diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeContinuousMinorArc.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeContinuousMinorArc.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac233ab397eec3fa76a0dd61d2b58c12c18865e6 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeContinuousMinorArc.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeContinuousEnergy +import OAI.NumberTheory.EgyptianFractions.ThreePrimeMinorArc + +namespace OAI +noncomputable section +open scoped BigOperators +open MeasureTheory + +namespace Problem337.ThreePrimeContinuousMinorArc + +/-- The actual prime logarithmic exponential sum, with positive phase. -/ +def primeExponentialSum (u : ℕ) (x : ℝ) : ℂ := + ThreePrimeContinuousEnergy.natPolynomial (Nat.primesLE u) + (fun p => (Real.log (p : ℝ) : ℂ)) x + +lemma primeExponentialSum_eq (u : ℕ) (x : ℝ) : + primeExponentialSum u x = + ∑ p ∈ (Finset.Icc 1 u).filter Nat.Prime, + (Real.log (p : ℝ) : ℂ) * + Complex.exp (2 * Real.pi * Complex.I * (p : ℂ) * (x : ℂ)) := by + rw [primeExponentialSum, ThreePrimeContinuousEnergy.natPolynomial, + Nat.primesLE_eq_filter_Icc_one] + +/-- Every real frequency gives a unit-modulus phase. -/ +lemma phase_norm (t x : ℝ) : + ‖Complex.exp (2 * Real.pi * Complex.I * (t : ℂ) * (x : ℂ))‖ = 1 := by + rw [Complex.norm_exp] + simp [Complex.mul_re, Complex.mul_im] + +/-- The unconditional amplitude estimate needed in major-arc error budgets. -/ +theorem primeExponentialSum_norm_le (u : ℕ) (x : ℝ) : + ‖primeExponentialSum u x‖ ≤ Real.log 4 * (u : ℝ) := by + apply ThreePrimeMinorArc.prime_sum_norm_le + intro p hp + exact (phase_norm p x).le + +/-- Exact energy of the prime exponential sum on one unit interval. -/ +theorem primeExponentialSum_parseval (u : ℕ) : + (∫ x : ℝ in 0..1, ‖primeExponentialSum u x‖ ^ 2) = + ∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) ^ 2 := by + simpa only [primeExponentialSum, Complex.norm_real, Real.norm_eq_abs, sq_abs] using + ThreePrimeContinuousEnergy.nat_polynomial_parseval_interval + (Nat.primesLE u) (fun p => (Real.log (p : ℝ) : ℂ)) + +/-- Continuous prime minor arcs with an arbitrary norm-bounded twist. +The prime supremum estimate remains an explicit analytic hypothesis. -/ +theorem prime_minor_cubic_bound (u : ℕ) (hu : 2 ≤ u) + (phase : ℝ → ℂ) (minor : Set ℝ) (hmeas : MeasurableSet minor) + (hsubset : minor ⊆ Set.Icc 0 1) (ε : ℝ) (hε : 0 ≤ ε) + (hminor : ∀ x ∈ minor, ‖primeExponentialSum u x‖ ≤ + ε * (u : ℝ) / Real.log (u : ℝ)) + (hphase : ∀ x ∈ minor, ‖phase x‖ ≤ 1) : + ‖∫ x in minor, primeExponentialSum u x ^ 3 * phase x‖ ≤ + ε * Real.log 4 * (u : ℝ) ^ 2 := by + have hu1 : 1 < (u : ℝ) := by exact_mod_cast (show 1 < u by omega) + have hlog : 0 < Real.log (u : ℝ) := Real.log_pos hu1 + have hB : 0 ≤ ε * (u : ℝ) / Real.log (u : ℝ) := by positivity + have h := ThreePrimeContinuousEnergy.nat_polynomial_interval_minor_cubic_bound + (Nat.primesLE u) (fun p => (Real.log (p : ℝ) : ℂ)) phase minor hmeas hsubset + (ε * (u : ℝ) / Real.log (u : ℝ)) hB hminor hphase + change ‖∫ x in minor, primeExponentialSum u x ^ 3 * phase x‖ ≤ _ at h + simp only [Complex.norm_real, Real.norm_eq_abs, sq_abs] at h + apply h.trans + calc + ε * (u : ℝ) / Real.log (u : ℝ) * + (∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) ^ 2) ≤ + ε * (u : ℝ) / Real.log (u : ℝ) * + (Real.log 4 * (u : ℝ) * Real.log (u : ℝ)) := + mul_le_mul_of_nonneg_left (ThreePrimeMinorArc.prime_log_squares_le u (by omega)) hB + _ = ε * Real.log 4 * (u : ℝ) ^ 2 := by field_simp + +/-- Conventional negative extraction frequency for the cubic prime count. -/ +theorem prime_minor_extraction_bound (u : ℕ) (hu : 2 ≤ u) + (minor : Set ℝ) (hmeas : MeasurableSet minor) + (hsubset : minor ⊆ Set.Icc 0 1) (ε : ℝ) (hε : 0 ≤ ε) + (hminor : ∀ x ∈ minor, ‖primeExponentialSum u x‖ ≤ + ε * (u : ℝ) / Real.log (u : ℝ)) : + ‖∫ x in minor, primeExponentialSum u x ^ 3 * + Complex.exp (2 * Real.pi * Complex.I * (-(u : ℂ)) * (x : ℂ))‖ ≤ + ε * Real.log 4 * (u : ℝ) ^ 2 := by + apply prime_minor_cubic_bound u hu _ minor hmeas hsubset ε hε hminor + intro x hx + simpa only [Complex.ofReal_neg, Complex.ofReal_natCast] using (phase_norm (-(u : ℝ)) x).le + +end Problem337.ThreePrimeContinuousMinorArc + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeCubicStability.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeCubicStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..c21e1c9944f1840748be0d7a35da3cc48b508bfd --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeCubicStability.lean @@ -0,0 +1,110 @@ +import Mathlib + +namespace OAI +noncomputable section +open MeasureTheory +open scoped ENNReal + +namespace Problem337.ThreePrimeCubicStability + +/-- Exact polynomial factorization gives a norm estimate without choosing +common upper bounds for the two arguments. -/ +theorem norm_cube_sub_cube_le (z w : ℂ) : + ‖z ^ 3 - w ^ 3‖ ≤ ‖z - w‖ * (‖z‖ ^ 2 + ‖z‖ * ‖w‖ + ‖w‖ ^ 2) := by + have hfactor : z ^ 3 - w ^ 3 = (z - w) * (z ^ 2 + z * w + w ^ 2) := by ring + rw [hfactor, norm_mul] + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + calc + ‖z ^ 2 + z * w + w ^ 2‖ ≤ ‖z ^ 2 + z * w‖ + ‖w ^ 2‖ := norm_add_le _ _ + _ ≤ (‖z ^ 2‖ + ‖z * w‖) + ‖w ^ 2‖ := + add_le_add (norm_add_le _ _) le_rfl + _ = _ := by simp only [norm_pow, norm_mul] + +/-- Asymmetric uniform error estimate for two cubic expressions. -/ +theorem norm_cube_sub_cube_le_of_bounds (z w : ℂ) {E M N : ℝ} + (hE : 0 ≤ E) (hM : 0 ≤ M) (_hN : 0 ≤ N) + (hdiff : ‖z - w‖ ≤ E) (hz : ‖z‖ ≤ M) (hw : ‖w‖ ≤ N) : + ‖z ^ 3 - w ^ 3‖ ≤ E * (M ^ 2 + M * N + N ^ 2) := by + apply (norm_cube_sub_cube_le z w).trans + apply mul_le_mul hdiff _ (by positivity) hE + exact add_le_add + (add_le_add (pow_le_pow_left₀ (norm_nonneg _) hz 2) + (mul_le_mul hz hw (norm_nonneg _) hM)) + (pow_le_pow_left₀ (norm_nonneg _) hw 2) + +/-- Cubic approximation error integrated over an arbitrary finite-measure set. +No measurability or integrability is silently assumed: the Bochner norm bound +is valid also when the displayed integral is defined by zero. -/ +theorem norm_cubic_error_integral_le {α : Type*} [MeasurableSpace α] + {μ : Measure α} {s : Set α} (hs : μ s < ∞) + (F G ψ : α → ℂ) {E M N : ℝ} + (hE : 0 ≤ E) (hM : 0 ≤ M) (hN : 0 ≤ N) + (hdiff : ∀ x ∈ s, ‖F x - G x‖ ≤ E) + (hF : ∀ x ∈ s, ‖F x‖ ≤ M) (hG : ∀ x ∈ s, ‖G x‖ ≤ N) + (hψ : ∀ x ∈ s, ‖ψ x‖ ≤ 1) : + ‖∫ x in s, (F x ^ 3 - G x ^ 3) * ψ x ∂μ‖ ≤ + E * (M ^ 2 + M * N + N ^ 2) * (μ s).toReal := by + apply norm_setIntegral_le_of_norm_le_const hs + intro x hx + rw [norm_mul] + calc + ‖F x ^ 3 - G x ^ 3‖ * ‖ψ x‖ ≤ + (E * (M ^ 2 + M * N + N ^ 2)) * 1 := + mul_le_mul (norm_cube_sub_cube_le_of_bounds (F x) (G x) hE hM hN + (hdiff x hx) (hF x hx) (hG x hx)) (hψ x hx) (norm_nonneg _) (by positivity) + _ = _ := mul_one _ + +/-- A common amplitude bound gives the standard `3 E M²` cubic error. -/ +theorem norm_cubic_error_integral_le_common {α : Type*} [MeasurableSpace α] + {μ : Measure α} {s : Set α} (hs : μ s < ∞) + (F G ψ : α → ℂ) {E M : ℝ} (hE : 0 ≤ E) (hM : 0 ≤ M) + (hdiff : ∀ x ∈ s, ‖F x - G x‖ ≤ E) + (hF : ∀ x ∈ s, ‖F x‖ ≤ M) (hG : ∀ x ∈ s, ‖G x‖ ≤ M) + (hψ : ∀ x ∈ s, ‖ψ x‖ ≤ 1) : + ‖∫ x in s, (F x ^ 3 - G x ^ 3) * ψ x ∂μ‖ ≤ + 3 * E * M ^ 2 * (μ s).toReal := by + convert norm_cubic_error_integral_le hs F G ψ hE hM hM hdiff hF hG hψ using 1 + ring + +/-- When the two cubic integrands are integrable, the error estimate controls +the difference of their integrals, as required by major-arc approximation. -/ +theorem norm_cubic_integral_sub_le {α : Type*} [MeasurableSpace α] + {μ : Measure α} {s : Set α} (hs : μ s < ∞) + (F G ψ : α → ℂ) {E M : ℝ} (hE : 0 ≤ E) (hM : 0 ≤ M) + (hFi : IntegrableOn (fun x => F x ^ 3 * ψ x) s μ) + (hGi : IntegrableOn (fun x => G x ^ 3 * ψ x) s μ) + (hdiff : ∀ x ∈ s, ‖F x - G x‖ ≤ E) + (hF : ∀ x ∈ s, ‖F x‖ ≤ M) (hG : ∀ x ∈ s, ‖G x‖ ≤ M) + (hψ : ∀ x ∈ s, ‖ψ x‖ ≤ 1) : + ‖(∫ x in s, F x ^ 3 * ψ x ∂μ) - (∫ x in s, G x ^ 3 * ψ x ∂μ)‖ ≤ + 3 * E * M ^ 2 * (μ s).toReal := by + rw [← integral_sub hFi hGi] + simpa only [sub_mul] using + norm_cubic_error_integral_le_common hs F G ψ hE hM hdiff hF hG hψ + +/-- Oriented-interval version of cubic stability, independent of endpoint order. -/ +theorem norm_cubic_interval_error_le (F G ψ : ℝ → ℂ) (a b : ℝ) + {E M : ℝ} (hE : 0 ≤ E) (hM : 0 ≤ M) + (hdiff : ∀ x ∈ Set.uIoc a b, ‖F x - G x‖ ≤ E) + (hF : ∀ x ∈ Set.uIoc a b, ‖F x‖ ≤ M) + (hG : ∀ x ∈ Set.uIoc a b, ‖G x‖ ≤ M) + (hψ : ∀ x ∈ Set.uIoc a b, ‖ψ x‖ ≤ 1) : + ‖∫ x in a..b, (F x ^ 3 - G x ^ 3) * ψ x‖ ≤ + 3 * E * M ^ 2 * |b - a| := by + apply intervalIntegral.norm_integral_le_of_norm_le_const + intro x hx + have hbound : ‖F x ^ 3 - G x ^ 3‖ ≤ 3 * E * M ^ 2 := by + convert norm_cube_sub_cube_le_of_bounds (F x) (G x) hE hM hM + (hdiff x hx) (hF x hx) (hG x hx) using 1 + ring + rw [norm_mul] + calc + _ ≤ (3 * E * M ^ 2) * 1 := + mul_le_mul hbound (hψ x hx) (norm_nonneg _) (by positivity) + _ = _ := mul_one _ + +end Problem337.ThreePrimeCubicStability + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeEulerProduct.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeEulerProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..9eaba93dffc35dce02082d24af50d45d1fc27494 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeEulerProduct.lean @@ -0,0 +1,93 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeSingularSeries + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337 + +/-- The standard ternary local Euler factor, extended by one at nonprimes. -/ +def ternaryEulerFactor (u p : ℕ) : ℝ := + if p.Prime then + if p ∣ u then 1 - 1 / ((p : ℝ) - 1) ^ 2 + else 1 + 1 / ((p : ℝ) - 1) ^ 3 + else 1 + +lemma ternaryEulerFactor_add_three (u n : ℕ) : + ternaryEulerFactor u (n + 3) = 1 + threePrimeOddPerturbation u n := by + have heq : ((n + 3 : ℕ) : ℝ) - 1 = (n : ℝ) + 2 := by push_cast; ring + unfold ternaryEulerFactor threePrimeOddPerturbation + rw [heq] + split_ifs <;> ring + +lemma ternaryEulerFactor_two (u : ℕ) : + ternaryEulerFactor u 2 = if Odd u then 2 else 0 := by + unfold ternaryEulerFactor + norm_num only [Nat.prime_two, ite_true, Nat.cast_ofNat] + by_cases h : 2 ∣ u + · have hn : ¬ Odd u := fun ho => + (Nat.not_even_iff_odd.mpr ho) (even_iff_two_dvd.mpr h) + norm_num [h, hn] + · have ho : Odd u := Nat.not_even_iff_odd.mp + (fun he => h (even_iff_two_dvd.mp he)) + norm_num [h, ho] + +lemma ternaryEulerFactor_prefix (u : ℕ) : + (∏ p ∈ Finset.range 3, ternaryEulerFactor u p) = if Odd u then 2 else 0 := by + simp only [Finset.prod_range_succ, Finset.prod_range_zero, one_mul] + have h0 : ternaryEulerFactor u 0 = 1 := by simp [ternaryEulerFactor, Nat.not_prime_zero] + have h1 : ternaryEulerFactor u 1 = 1 := by simp [ternaryEulerFactor] + rw [h0, h1, one_mul, one_mul, ternaryEulerFactor_two] + +lemma ternaryEulerFactor_tail_multipliable (u : ℕ) : + Multipliable (fun n : ℕ => ternaryEulerFactor u (n + 3)) := by + exact (threePrimeOddFactors_multipliable u).congr + (fun n => (ternaryEulerFactor_add_three u n).symm) + +lemma ternaryEulerFactor_multipliable (u : ℕ) : + Multipliable (ternaryEulerFactor u) := + (ternaryEulerFactor_tail_multipliable u).comp_nat_add + +/-- The shifted odd-prime definition is exactly the conventional Euler +product, including the vanishing local factor at two for even inputs. -/ +theorem threePrimeSingularSeries_eq_euler_tprod (u : ℕ) : + threePrimeSingularSeries u = ∏' p : ℕ, ternaryEulerFactor u p := by + calc + threePrimeSingularSeries u = (if Odd u then 2 else 0) * + ∏' n : ℕ, ternaryEulerFactor u (n + 3) := by + unfold threePrimeSingularSeries + congr 1 + exact tprod_congr (fun n => (ternaryEulerFactor_add_three u n).symm) + _ = (∏ p ∈ Finset.range 3, ternaryEulerFactor u p) * + ∏' n : ℕ, ternaryEulerFactor u (n + 3) := by rw [ternaryEulerFactor_prefix] + _ = ∏' p : ℕ, ternaryEulerFactor u p := + (ternaryEulerFactor_tail_multipliable u).prod_mul_tprod_nat_mul' + +/-- Removing the factors equal to one at nonprimes recovers the usual +prime-indexed singular series. This identity is valid for all natural inputs. -/ +theorem threePrimeSingularSeries_eq_prime_tprod (u : ℕ) : + threePrimeSingularSeries u = ∏' p : {p : ℕ // p.Prime}, + (if p.val ∣ u then 1 - 1 / ((p.val : ℝ) - 1) ^ 2 + else 1 + 1 / ((p.val : ℝ) - 1) ^ 3) := by + have hs : Function.mulSupport (ternaryEulerFactor u) ⊆ {p : ℕ | p.Prime} := by + intro p hp + by_contra hn + change ¬ p.Prime at hn + exact hp (by simp [ternaryEulerFactor, hn]) + rw [threePrimeSingularSeries_eq_euler_tprod, + ← tprod_subtype_eq_of_mulSupport_subset hs] + apply tprod_congr + intro p + have hp : Nat.Prime (p : ℕ) := p.property + simp only [ternaryEulerFactor, hp, ite_true] + +lemma threePrimeSingularSeries_eq_zero_of_even {u : ℕ} (hu : Even u) : + threePrimeSingularSeries u = 0 := by + have hn : ¬ Odd u := fun ho => Nat.not_even_iff_odd.mpr ho hu + simp [threePrimeSingularSeries, hn] + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeEulerTail.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeEulerTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ca3091502d8069cd70d3625d59b2c69c4666e3f --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeEulerTail.lean @@ -0,0 +1,176 @@ +import Mathlib + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.ThreePrimeEulerTail + +/-- A reciprocal-square tail is bounded by a telescoping reciprocal tail. +The statement is for arbitrary finite sets, hence also for sets of primes. -/ +theorem reciprocal_square_tail (P : Finset ℕ) (N : ℕ) (hN : 2 ≤ N) + (hP : ∀ p ∈ P, N < p) : + (∑ p ∈ P, 1 / ((p : ℝ) - 1) ^ 2) ≤ 1 / ((N : ℝ) - 1) := by + classical + by_cases hempty : P = ∅ + · subst P + simp only [Finset.sum_empty] + apply one_div_nonneg.mpr + have : (2 : ℝ) ≤ N := by exact_mod_cast hN + linarith + have hne : P.Nonempty := Finset.nonempty_iff_ne_empty.mpr hempty + let M := P.max' hne + have hNM : N < M := hP M (Finset.max'_mem P hne) + have hsub : P ⊆ Finset.Ico (N + 1) (M + 1) := by + intro p hp + exact Finset.mem_Ico.mpr ⟨by have := hP p hp; omega, + by have := Finset.le_max' P p hp; omega⟩ + have hpoint (p : ℕ) (hp : p ∈ Finset.Ico (N + 1) (M + 1)) : + 1 / ((p : ℝ) - 1) ^ 2 ≤ + 1 / ((p : ℝ) - 2) - 1 / (((p + 1 : ℕ) : ℝ) - 2) := by + have hp3 : 3 ≤ p := by have := (Finset.mem_Ico.mp hp).1; omega + have hpR : (3 : ℝ) ≤ p := by exact_mod_cast hp3 + have hp1 : 0 < (p : ℝ) - 1 := by linarith + have hp2 : 0 < (p : ℝ) - 2 := by linarith + push_cast + have heq : (p : ℝ) + 1 - 2 = (p : ℝ) - 1 := by ring + rw [heq] + field_simp + nlinarith + calc + _ ≤ ∑ p ∈ Finset.Ico (N + 1) (M + 1), 1 / ((p : ℝ) - 1) ^ 2 := + Finset.sum_le_sum_of_subset_of_nonneg hsub (by intros; positivity) + _ ≤ ∑ p ∈ Finset.Ico (N + 1) (M + 1), + (1 / ((p : ℝ) - 2) - 1 / (((p + 1 : ℕ) : ℝ) - 2)) := + Finset.sum_le_sum hpoint + _ = 1 / (((N + 1 : ℕ) : ℝ) - 2) - + 1 / (((M + 1 : ℕ) : ℝ) - 2) := by + have htel := Finset.sum_Ico_sub (fun p : ℕ => -(1 / ((p : ℝ) - 2))) + (show N + 1 ≤ M + 1 by omega) + simpa only [neg_sub_neg] using htel + _ ≤ 1 / ((N : ℝ) - 1) := by + have hM : (2 : ℝ) ≤ M := by exact_mod_cast (show 2 ≤ M by omega) + have hpos : 0 ≤ 1 / (((M + 1 : ℕ) : ℝ) - 2) := by + apply one_div_nonneg.mpr + push_cast + linarith + push_cast at * + have heq : (N : ℝ) + 1 - 2 = (N : ℝ) - 1 := by ring + rw [heq] + linarith + +/-- Uniform finite Euler-tail error from the standard local-factor defect bound. -/ +theorem product_tail_abs_sub_one (f : ℕ → ℝ) (P : Finset ℕ) + (N : ℕ) (hN : 2 ≤ N) (hP : ∀ p ∈ P, N < p) + (hf : ∀ p ∈ P, |f p - 1| ≤ 1 / ((p : ℝ) - 1) ^ 2) : + |(∏ p ∈ P, f p) - 1| ≤ 2 / ((N : ℝ) - 1) := by + have hsum : (∑ p ∈ P, |f p - 1|) ≤ 1 / ((N : ℝ) - 1) := + (Finset.sum_le_sum hf).trans (reciprocal_square_tail P N hN hP) + have hNreal : (2 : ℝ) ≤ N := by exact_mod_cast hN + have hden : 0 < (N : ℝ) - 1 := by linarith + have hsmall : |1 / ((N : ℝ) - 1)| ≤ 1 := by + rw [abs_of_nonneg (by positivity)] + exact (div_le_one hden).mpr (by linarith) + have hprod := P.norm_prod_one_add_sub_one_le (fun p => f p - 1) + simp only [add_sub_cancel, Real.norm_eq_abs] at hprod + calc + _ ≤ Real.exp (∑ p ∈ P, |f p - 1|) - 1 := hprod + _ ≤ Real.exp (1 / ((N : ℝ) - 1)) - 1 := sub_le_sub_right (Real.exp_le_exp.mpr hsum) 1 + _ ≤ |Real.exp (1 / ((N : ℝ) - 1)) - 1| := le_abs_self _ + _ ≤ 2 * |1 / ((N : ℝ) - 1)| := Real.abs_exp_sub_one_le hsmall + _ = 2 / ((N : ℝ) - 1) := by rw [abs_of_nonneg (by positivity)]; ring + +/-- The local-factor defect majorant gives absolute summability without imposing +any condition on the finitely many initial factors. -/ +theorem summable_abs_sub_one (f : ℕ → ℝ) + (hf : ∀ p : ℕ, 3 ≤ p → |f p - 1| ≤ 1 / ((p : ℝ) - 1) ^ 2) : + Summable (fun p => |f p - 1|) := by + have hseries : Summable (fun n : ℕ => 1 / (n : ℝ) ^ 2) := + Real.summable_one_div_nat_pow.mpr (by norm_num) + have hshift := (summable_nat_add_iff 2).mpr hseries + apply (summable_nat_add_iff 3).mp + apply hshift.of_nonneg_of_le (fun n => abs_nonneg _) + intro n + have h := hf (n + 3) (by omega) + convert h using 1 + push_cast + ring + +/-- Absolute summability of the local defects defines a genuine Euler product. -/ +theorem multipliable (f : ℕ → ℝ) + (hf : ∀ p : ℕ, 3 ≤ p → |f p - 1| ≤ 1 / ((p : ℝ) - 1) ^ 2) : + Multipliable f := by + have hsum : Summable (fun p => f p - 1) := by + apply Summable.of_norm + simpa only [Real.norm_eq_abs] using summable_abs_sub_one f hf + simpa only [add_sub_cancel] using Real.multipliable_one_add_of_summable hsum + +/-- A partial Euler product approximates its infinite product with an explicit +relative error. Only the universal local defect estimate is needed. -/ +theorem tprod_sub_partial_abs_le (f : ℕ → ℝ) + (hf : ∀ p : ℕ, 3 ≤ p → |f p - 1| ≤ 1 / ((p : ℝ) - 1) ^ 2) + (N : ℕ) (hN : 2 ≤ N) : + |(∏' p, f p) - ∏ p ∈ Finset.range (N + 1), f p| ≤ + |∏ p ∈ Finset.range (N + 1), f p| * (2 / ((N : ℝ) - 1)) := by + apply le_of_tendsto (((multipliable f hf).hasProd.tendsto_prod_nat.sub_const + (∏ p ∈ Finset.range (N + 1), f p)).abs) + filter_upwards [Filter.eventually_ge_atTop (N + 1)] with M hNM + rw [← Finset.prod_range_mul_prod_Ico f hNM] + have heq : (∏ p ∈ Finset.range (N + 1), f p) * + (∏ p ∈ Finset.Ico (N + 1) M, f p) - + (∏ p ∈ Finset.range (N + 1), f p) = + (∏ p ∈ Finset.range (N + 1), f p) * + ((∏ p ∈ Finset.Ico (N + 1) M, f p) - 1) := by ring + rw [heq, abs_mul] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + apply product_tail_abs_sub_one f _ N hN + · intro p hp + have := (Finset.mem_Ico.mp hp).1 + omega + · intro p hp + apply hf + have := (Finset.mem_Ico.mp hp).1 + omega + +/-- All partial products are bounded by three times their first three factors. +This estimate is uniform in any external parameter of the local factors. -/ +theorem partial_abs_le (f : ℕ → ℝ) + (hf : ∀ p : ℕ, 3 ≤ p → |f p - 1| ≤ 1 / ((p : ℝ) - 1) ^ 2) + (N : ℕ) (hN : 2 ≤ N) : + |∏ p ∈ Finset.range (N + 1), f p| ≤ + 3 * |∏ p ∈ Finset.range 3, f p| := by + rw [← Finset.prod_range_mul_prod_Ico f (show 3 ≤ N + 1 by omega), abs_mul] + have htail := product_tail_abs_sub_one f (Finset.Ico 3 (N + 1)) 2 (by omega) + (by intro p hp; have := (Finset.mem_Ico.mp hp).1; omega) + (by intro p hp; exact hf p (Finset.mem_Ico.mp hp).1) + norm_num only [Nat.cast_ofNat, sub_self, one_div, Nat.cast_one, sub_zero] at htail + have hbound : |∏ p ∈ Finset.Ico 3 (N + 1), f p| ≤ 3 := by + calc + _ = |((∏ p ∈ Finset.Ico 3 (N + 1), f p) - 1) + 1| := by ring_nf + _ ≤ |(∏ p ∈ Finset.Ico 3 (N + 1), f p) - 1| + |(1 : ℝ)| := abs_add_le _ _ + _ ≤ 3 := by norm_num at htail ⊢; linarith + nlinarith [abs_nonneg (∏ p ∈ Finset.range 3, f p)] + +/-- Uniform O(1/N) truncation error, stated with a bound for the only three +uncontrolled initial local factors. -/ +theorem tprod_sub_partial_abs_le_uniform (f : ℕ → ℝ) + (hf : ∀ p : ℕ, 3 ≤ p → |f p - 1| ≤ 1 / ((p : ℝ) - 1) ^ 2) + (B : ℝ) (hB : |∏ p ∈ Finset.range 3, f p| ≤ B) + (N : ℕ) (hN : 2 ≤ N) : + |(∏' p, f p) - ∏ p ∈ Finset.range (N + 1), f p| ≤ + 6 * B / ((N : ℝ) - 1) := by + have hNR : (2 : ℝ) ≤ N := by exact_mod_cast hN + have hden : 0 < (N : ℝ) - 1 := by linarith + calc + _ ≤ |∏ p ∈ Finset.range (N + 1), f p| * (2 / ((N : ℝ) - 1)) := + tprod_sub_partial_abs_le f hf N hN + _ ≤ (3 * B) * (2 / ((N : ℝ) - 1)) := by + apply mul_le_mul_of_nonneg_right _ (by positivity) + exact (partial_abs_le f hf N hN).trans (mul_le_mul_of_nonneg_left hB (by norm_num)) + _ = 6 * B / ((N : ℝ) - 1) := by ring + +end Problem337.ThreePrimeEulerTail + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourier.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourier.lean new file mode 100644 index 0000000000000000000000000000000000000000..5dae24658f573f0995b2e17e651fda569528e679 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourier.lean @@ -0,0 +1,203 @@ +import OAI.NumberTheory.EgyptianFractions.RationalSupplyReduction + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.ThreePrimeFourier + +/-- Exact Fourier extraction of a weighted ordered triple in a finite cyclic + group. No primality or analytic estimate is needed. -/ +theorem weighted_triple_character_identity {q : ℕ} [NeZero q] + {α : Type*} (s : Finset α) (f : α → ZMod q) (w : α → ℂ) + (u : ZMod q) : + (∑ r : ZMod q, (∑ a ∈ s, w a * ZMod.stdAddChar (f a * r)) ^ 3 * + ZMod.stdAddChar (-u * r)) = + (q : ℂ) * ∑ a ∈ s, ∑ b ∈ s, ∑ c ∈ s, + if f a + f b + f c = u then w a * w b * w c else 0 := by + classical + have hexpand (r : ZMod q) : + (∑ a ∈ s, w a * ZMod.stdAddChar (f a * r)) ^ 3 * + ZMod.stdAddChar (-u * r) = + ∑ a ∈ s, ∑ b ∈ s, ∑ c ∈ s, + (w a * w b * w c) * ZMod.stdAddChar ((f a + f b + f c - u) * r) := by + calc + _ = ((∑ a ∈ s, w a * ZMod.stdAddChar (f a * r)) * + (∑ b ∈ s, w b * ZMod.stdAddChar (f b * r)) * + (∑ c ∈ s, w c * ZMod.stdAddChar (f c * r))) * + ZMod.stdAddChar (-u * r) := by ring + _ = _ := by + simp only [Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + apply Finset.sum_congr rfl + intro c hc + rw [sub_mul, add_mul, add_mul, sub_eq_add_neg, + AddChar.map_add_eq_mul, AddChar.map_add_eq_mul, AddChar.map_add_eq_mul] + rw [neg_mul] + ring + simp_rw [hexpand] + rw [Finset.sum_comm] + calc + _ = ∑ a ∈ s, ∑ b ∈ s, ∑ c ∈ s, + ∑ r : ZMod q, + (w a * w b * w c) * ZMod.stdAddChar ((f a + f b + f c - u) * r) := by + apply Finset.sum_congr rfl + intro a ha + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b hb + rw [Finset.sum_comm] + _ = _ := by + simp_rw [← Finset.mul_sum, FiveProducts.character_sum, sub_eq_zero] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + apply Finset.sum_congr rfl + intro c hc + split_ifs <;> ring + +/-- Choosing the cyclic modulus above every possible sum removes all modular +aliasing. The resulting identity counts ordinary natural-number sums exactly. -/ +theorem weighted_natural_triple_character_identity {q : ℕ} [NeZero q] + (s : Finset ℕ) (w : ℕ → ℂ) (u : ℕ) + (hs : ∀ a ∈ s, a ≤ u) (hq : 3 * u < q) : + (∑ r : ZMod q, (∑ a ∈ s, w a * ZMod.stdAddChar ((a : ZMod q) * r)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod q) * r)) = + (q : ℂ) * ∑ a ∈ s, ∑ b ∈ s, ∑ c ∈ s, + if a + b + c = u then w a * w b * w c else 0 := by + classical + rw [weighted_triple_character_identity] + congr 1 + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + apply Finset.sum_congr rfl + intro c hc + have habc : a + b + c < q := by + have := hs a ha + have := hs b hb + have := hs c hc + omega + have hu : u < q := by omega + have heq : (a : ZMod q) + (b : ZMod q) + (c : ZMod q) = (u : ZMod q) ↔ + a + b + c = u := by + rw [← Nat.cast_add, ← Nat.cast_add, ZMod.natCast_eq_natCast_iff', + Nat.mod_eq_of_lt habc, Nat.mod_eq_of_lt hu] + simp only [heq] + +/-- Normalized inverse Fourier extraction for weighted ordinary triples. -/ +theorem weighted_natural_triple_fourier {q : ℕ} [NeZero q] + (s : Finset ℕ) (w : ℕ → ℂ) (u : ℕ) + (hs : ∀ a ∈ s, a ≤ u) (hq : 3 * u < q) : + (∑ a ∈ s, ∑ b ∈ s, ∑ c ∈ s, + if a + b + c = u then w a * w b * w c else 0) = + (∑ r : ZMod q, (∑ a ∈ s, w a * ZMod.stdAddChar ((a : ZMod q) * r)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod q) * r)) / (q : ℂ) := by + apply (eq_div_iff (NeZero.ne (q : ℂ))).2 + simpa only [mul_comm] using + (weighted_natural_triple_character_identity s w u hs hq).symm + +/-- The existing ordered-prime-triple finset is exactly the filtered cube + of the primes at most `u`. This identity also applies to arbitrary weights. -/ +theorem supply_prime_triple_sum_eq_nested (u : ℕ) (w : ℕ → ℂ) : + (∑ t ∈ supplyPrimeTriples u, w t.1 * w t.2.1 * w t.2.2) = + ∑ a ∈ (Finset.Icc 1 u).filter Nat.Prime, + ∑ b ∈ (Finset.Icc 1 u).filter Nat.Prime, + ∑ c ∈ (Finset.Icc 1 u).filter Nat.Prime, + if a + b + c = u then w a * w b * w c else 0 := by + classical + let s := (Finset.Icc 1 u).filter Nat.Prime + have hset : ((s ×ˢ (s ×ˢ s)).filter + (fun t : ℕ × ℕ × ℕ => t.1 + t.2.1 + t.2.2 = u)) = + supplyPrimeTriples u := by + ext t + simp only [s, supplyPrimeTriples, Finset.mem_filter, Finset.mem_product] + tauto + rw [← hset] + simp only [Finset.sum_filter, Finset.sum_product, s] + +/-- Exact extraction of the log-weighted prime count that occurs in the + three-prime lower bound. The modulus condition excludes all circular sums. -/ +theorem supply_prime_weighted_fourier {q : ℕ} [NeZero q] + (u : ℕ) (hq : 3 * u < q) : + (∑ t ∈ supplyPrimeTriples u, + (Real.log (t.1 : ℝ) : ℂ) * (Real.log (t.2.1 : ℝ) : ℂ) * + (Real.log (t.2.2 : ℝ) : ℂ)) = + (∑ r : ZMod q, + (∑ a ∈ (Finset.Icc 1 u).filter Nat.Prime, + (Real.log (a : ℝ) : ℂ) * ZMod.stdAddChar ((a : ZMod q) * r)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod q) * r)) / (q : ℂ) := by + rw [supply_prime_triple_sum_eq_nested u (fun a => (Real.log (a : ℝ) : ℂ))] + apply weighted_natural_triple_fourier _ _ _ _ hq + intro a ha + exact (Finset.mem_Icc.mp (Finset.mem_filter.mp ha).1).2 + +/-- Real-part version of the exact extraction formula. -/ +theorem supply_prime_weighted_fourier_re {q : ℕ} [NeZero q] + (u : ℕ) (hq : 3 * u < q) : + (∑ t ∈ supplyPrimeTriples u, + Real.log (t.1 : ℝ) * Real.log (t.2.1 : ℝ) * Real.log (t.2.2 : ℝ)) = + (∑ r : ZMod q, + (∑ a ∈ (Finset.Icc 1 u).filter Nat.Prime, + (Real.log (a : ℝ) : ℂ) * ZMod.stdAddChar ((a : ZMod q) * r)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod q) * r)).re / (q : ℝ) := by + have h := congrArg Complex.re (supply_prime_weighted_fourier u hq) + simpa only [Complex.re_sum, ← Complex.ofReal_mul, Complex.ofReal_re, + ← Complex.ofReal_natCast, Complex.div_ofReal_re] using h + +/-- Splitting frequencies into an arbitrary major set and its complement + gives the standard lower bound by the major real part minus the minor norm. -/ +theorem major_minor_real_lower_bound {α : Type*} [Fintype α] [DecidableEq α] + (s : Finset α) (F : α → ℂ) (Q : ℝ) (hQ : 0 < Q) : + ((∑ r ∈ s, F r).re - ‖∑ r ∈ sᶜ, F r‖) / Q ≤ + (∑ r, F r).re / Q := by + classical + apply div_le_div_of_nonneg_right _ hQ.le + rw [← Finset.sum_add_sum_compl s F, Complex.add_re] + have h := Complex.re_le_norm (-(∑ r ∈ sᶜ, F r)) + simp only [Complex.neg_re, norm_neg] at h + linarith + +/-- A lower major-frequency bound and an upper minor-frequency norm bound + imply a lower bound for the actual log-weighted ordered-prime-triple count. + The genuinely analytic estimates remain explicit hypotheses. -/ +theorem supply_prime_weighted_lower_of_major_minor {q : ℕ} [NeZero q] + (u : ℕ) (hq : 3 * u < q) (major : Finset (ZMod q)) + (A E : ℝ) + (hmajor : A * (q : ℝ) ≤ + (∑ r ∈ major, + (∑ a ∈ (Finset.Icc 1 u).filter Nat.Prime, + (Real.log (a : ℝ) : ℂ) * ZMod.stdAddChar ((a : ZMod q) * r)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod q) * r)).re) + (hminor : ‖∑ r ∈ majorᶜ, + (∑ a ∈ (Finset.Icc 1 u).filter Nat.Prime, + (Real.log (a : ℝ) : ℂ) * ZMod.stdAddChar ((a : ZMod q) * r)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod q) * r)‖ ≤ E * (q : ℝ)) : + A - E ≤ ∑ t ∈ supplyPrimeTriples u, + Real.log (t.1 : ℝ) * Real.log (t.2.1 : ℝ) * Real.log (t.2.2 : ℝ) := by + classical + have hqpos : (0 : ℝ) < q := by exact_mod_cast (Nat.pos_of_ne_zero (NeZero.ne q)) + rw [supply_prime_weighted_fourier_re u hq] + let F : ZMod q → ℂ := fun r => + (∑ a ∈ (Finset.Icc 1 u).filter Nat.Prime, + (Real.log (a : ℝ) : ℂ) * ZMod.stdAddChar ((a : ZMod q) * r)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod q) * r) + change A - E ≤ (∑ r, F r).re / (q : ℝ) + have hsplit := major_minor_real_lower_bound major F (q : ℝ) hqpos + refine le_trans ?_ hsplit + apply (le_div_iff₀ hqpos).2 + change A * (q : ℝ) ≤ (∑ r ∈ major, F r).re at hmajor + change ‖∑ r ∈ majorᶜ, F r‖ ≤ E * (q : ℝ) at hminor + nlinarith + +end Problem337.ThreePrimeFourier + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourierBundle.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourierBundle.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c83c1696f91d6b53ed5df3ee35e5a315a4bcc85 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourierBundle.lean @@ -0,0 +1,4 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeFourierReduction +import OAI.NumberTheory.EgyptianFractions.ThreePrimeContinuousMinorArc +import OAI.NumberTheory.EgyptianFractions.ThreePrimeIntegralCount +import OAI.NumberTheory.EgyptianFractions.ThreePrimeMangoldtIntegral \ No newline at end of file diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourierReduction.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourierReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c613e9d15db39fcb78969792475cf3f2fe3f4f7 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeFourierReduction.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeFourier +import OAI.NumberTheory.EgyptianFractions.ThreePrimeWeighted + +namespace OAI +noncomputable section +open scoped BigOperators +open Filter + +namespace Problem337.ThreePrimeFourier + +/-- The ordinary positive-sign prime exponential sum, at the zero-padded +cyclic modulus `3*u+1`. -/ +def primeFourierSum (u : ℕ) (r : ZMod (3 * u + 1)) : ℂ := + ∑ a ∈ (Finset.Icc 1 u).filter Nat.Prime, + (Real.log (a : ℝ) : ℂ) * ZMod.stdAddChar ((a : ZMod (3 * u + 1)) * r) + +/-- The cubic integrand extracting the ordered prime triples of sum `u`. -/ +def primeFourierIntegrand (u : ℕ) (r : ZMod (3 * u + 1)) : ℂ := + primeFourierSum u r ^ 3 * ZMod.stdAddChar (-(u : ZMod (3 * u + 1)) * r) + +/-- The canonical weighted count is exactly the real inverse Fourier sum. -/ +theorem weightedSupplyPrimeTriples_eq_fourier (u : ℕ) : + weightedSupplyPrimeTriples u = + (∑ r, primeFourierIntegrand u r).re / (3 * u + 1 : ℕ) := by + exact supply_prime_weighted_fourier_re u (by omega) + +/-- The remaining quantitative three-prime assertion follows from explicit +major-frequency main terms and minor-frequency errors for the actual prime +exponential sums. This theorem does not assert either analytic estimate. -/ +theorem quantitativeThreePrimeLowerBound_of_major_minor + (major : (u : ℕ) → Finset (ZMod (3 * u + 1))) + (c : ℝ) (hc : 0 < c) + (hmajor : ∀ᶠ u : ℕ in atTop, Odd u → + (2 * c * (u : ℝ) ^ 2) * (3 * u + 1 : ℕ) ≤ + (∑ r ∈ major u, primeFourierIntegrand u r).re) + (hminor : ∀ᶠ u : ℕ in atTop, Odd u → + ‖∑ r ∈ (major u)ᶜ, primeFourierIntegrand u r‖ ≤ + (c * (u : ℝ) ^ 2) * (3 * u + 1 : ℕ)) : + QuantitativeThreePrimeLowerBound := by + apply quantitativeThreePrimeLowerBound_of_weighted + refine ⟨c, hc, ?_⟩ + filter_upwards [hmajor, hminor] with u hma hmi + intro hu + have h := supply_prime_weighted_lower_of_major_minor u (by omega : 3 * u < 3 * u + 1) + (major u) (2 * c * (u : ℝ) ^ 2) (c * (u : ℝ) ^ 2) (hma hu) (hmi hu) + change 2 * c * (u : ℝ) ^ 2 - c * (u : ℝ) ^ 2 ≤ weightedSupplyPrimeTriples u at h + nlinarith + +end Problem337.ThreePrimeFourier + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeIntegralCount.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeIntegralCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cde46542af7746d81f5a6fae9abae04f4b27fcd --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeIntegralCount.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeContinuousFourier +import OAI.NumberTheory.EgyptianFractions.RationalSupplyReduction + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.ThreePrimeContinuousFourier + +/-- Positive prime frequencies up to the integer under representation. -/ +def primeFrequencies (u : ℕ) : Finset ℕ := (Finset.Icc 1 u).filter Nat.Prime + +/-- The unweighted positive-sign prime exponential sum. -/ +def primePhaseSum (u : ℕ) (x : ℝ) : ℂ := + ∑ p ∈ primeFrequencies u, phase (p : ℤ) x + +lemma prime_triples_eq_filter (u : ℕ) : + supplyPrimeTriples u = + ((primeFrequencies u) ×ˢ ((primeFrequencies u) ×ˢ (primeFrequencies u))).filter + (fun t => t.1 + t.2.1 + t.2.2 = u) := by + ext t + simp only [supplyPrimeTriples, primeFrequencies, Finset.mem_filter, Finset.mem_product] + tauto + +/-- The exact prime-triple count is a continuous cubic Fourier coefficient. +This does not estimate the integral or assert a prime-distribution result. -/ +theorem prime_triple_integral (u : ℕ) : + (∫ x in (0 : ℝ)..1, primePhaseSum u x ^ 3 * phase (-(u : ℤ)) x) = + ((supplyPrimeTriples u).card : ℂ) := by + classical + have h := weighted_triple_finset_integral (primeFrequencies u) + (fun p : ℕ => (p : ℤ)) (fun _ => (1 : ℂ)) (u : ℤ) + simp only [one_mul, mul_one] at h + change (∫ x in (0 : ℝ)..1, + (∑ p ∈ primeFrequencies u, phase (p : ℤ) x) ^ 3 * phase (-(u : ℤ)) x) = _ + rw [h, prime_triples_eq_filter] + simp only [Finset.card_eq_sum_ones, Nat.cast_sum, Finset.sum_filter, + Finset.sum_product] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + apply Finset.sum_congr rfl + intro c hc + have heq : ((a : ℤ) + (b : ℤ) + (c : ℤ) = (u : ℤ)) ↔ a + b + c = u := by omega + simp [heq] + +end Problem337.ThreePrimeContinuousFourier + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalDensity.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b92b7fd8b27958147a43330bee03c3bf6ccc29a --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalDensity.lean @@ -0,0 +1,319 @@ +import Mathlib + +namespace OAI +noncomputable section + +open scoped BigOperators + +namespace Problem337 + +/-- Nonzero residue classes modulo `p`. For prime `p`, these are exactly +its unit classes. -/ +def threePrimeNonzeroResidues (p : ℕ) [NeZero p] : Finset (ZMod p) := + Finset.univ.erase 0 + +/-- Two-coordinate parametrization of nonzero residue triples with sum `u`: +the third coordinate is `u - x - y`. -/ +def threePrimeLocalPairs (p : ℕ) [NeZero p] (u : ZMod p) : + Finset (ZMod p × ZMod p) := + (threePrimeNonzeroResidues p ×ˢ threePrimeNonzeroResidues p).filter + (fun t => t.1 + t.2 ≠ u) + +lemma mem_threePrimeLocalPairs {p : ℕ} [NeZero p] + (u x y : ZMod p) : + (x, y) ∈ threePrimeLocalPairs p u ↔ + x ≠ 0 ∧ y ≠ 0 ∧ u - x - y ≠ 0 := by + simp only [threePrimeLocalPairs, threePrimeNonzeroResidues, + Finset.mem_filter, Finset.mem_product, Finset.mem_erase, + Finset.mem_univ, and_true] + constructor + · rintro ⟨⟨hx, hy⟩, hsum⟩ + refine ⟨hx, hy, ?_⟩ + intro hz + apply hsum + linear_combination -hz + · rintro ⟨hx, hy, hz⟩ + refine ⟨⟨hx, hy⟩, ?_⟩ + intro hsum + apply hz + linear_combination -hsum + +lemma threePrimeLocalBadPairs_eq_image {p : ℕ} [NeZero p] (u : ZMod p) : + (threePrimeNonzeroResidues p ×ˢ threePrimeNonzeroResidues p).filter + (fun t => t.1 + t.2 = u) = + ((threePrimeNonzeroResidues p).erase u).image (fun x => (x, u - x)) := by + classical + ext t + rcases t with ⟨x, y⟩ + simp only [threePrimeNonzeroResidues, Finset.mem_filter, Finset.mem_product, + Finset.mem_erase, Finset.mem_univ, and_true, Finset.mem_image, Prod.mk.injEq] + constructor + · rintro ⟨⟨hx, hy⟩, hsum⟩ + refine ⟨x, ⟨?_, hx⟩, rfl, ?_⟩ + · intro hxu + apply hy + linear_combination hsum - hxu + · linear_combination -hsum + · rintro ⟨a, ⟨hau, ha⟩, hax, hay⟩ + subst a + refine ⟨⟨ha, ?_⟩, ?_⟩ + · intro hy + apply hau + linear_combination -hay - hy + · linear_combination -hay + +lemma threePrimeNonzeroResidues_card (p : ℕ) [NeZero p] : + (threePrimeNonzeroResidues p).card = p - 1 := by + simp [threePrimeNonzeroResidues] + +/-- Removing the forbidden third-coordinate-zero pairs leaves this exact +cardinality balance. This identity uses only the additive residue group. -/ +theorem threePrimeLocalPairs_card_balance (p : ℕ) [NeZero p] (u : ZMod p) : + (threePrimeLocalPairs p u).card + + ((threePrimeNonzeroResidues p).erase u).card = (p - 1) ^ 2 := by + classical + have hcard := Finset.card_filter_add_card_filter_not + (s := threePrimeNonzeroResidues p ×ˢ threePrimeNonzeroResidues p) + (p := fun t : ZMod p × ZMod p => t.1 + t.2 = u) + rw [threePrimeLocalBadPairs_eq_image] at hcard + have hinj : Function.Injective (fun x : ZMod p => (x, u - x)) := by + intro x y hxy + exact congrArg Prod.fst hxy + rw [Finset.card_image_of_injective _ hinj] at hcard + simpa [threePrimeLocalPairs, Finset.card_product, + threePrimeNonzeroResidues_card, pow_two, add_comm] using hcard + +/-- Exact count of the local nonzero solutions to a three-term sum. -/ +theorem threePrimeLocalPairs_card (p : ℕ) [NeZero p] (hp : 2 ≤ p) + (u : ZMod p) : + (threePrimeLocalPairs p u).card = + if u = 0 then (p - 1) * (p - 2) else (p - 1) * (p - 2) + 1 := by + classical + have hbalance := threePrimeLocalPairs_card_balance p u + have hdiff : p - 1 = (p - 2) + 1 := by omega + by_cases hu : u = 0 + · subst u + simp [threePrimeNonzeroResidues] at hbalance + simp only [ite_true, eq_self] + rw [hdiff] at hbalance ⊢ + nlinarith + · have hmem : u ∈ threePrimeNonzeroResidues p := by + simp [threePrimeNonzeroResidues, hu] + rw [Finset.card_erase_of_mem hmem, threePrimeNonzeroResidues_card] at hbalance + simp only [ite_eq_right hu] + rw [hdiff] at hbalance ⊢ + simp only [Nat.add_sub_cancel] at hbalance + nlinarith + +/-- Polynomial form of the local solution count. -/ +theorem threePrimeLocalPairs_card_real (p : ℕ) [NeZero p] (hp : 2 ≤ p) + (u : ZMod p) : + ((threePrimeLocalPairs p u).card : ℝ) = + (p : ℝ) ^ 2 - 3 * p + 3 - if u = 0 then 1 else 0 := by + rw [threePrimeLocalPairs_card p hp u] + split_ifs <;> push_cast [Nat.cast_sub (show 1 ≤ p by omega), Nat.cast_sub hp] <;> ring + +/-- The local density relative to the heuristic density of three unit classes. +The prime hypothesis is used when identifying this with a singular-series +factor; the finite expression is defined for every nonzero modulus. -/ +def threePrimeLocalFactor (p : ℕ) [NeZero p] (u : ZMod p) : ℝ := + (p : ℝ) * (threePrimeLocalPairs p u).card / ((p : ℝ) - 1) ^ 3 + +/-- The exact local factor of the ternary prime singular series. -/ +theorem threePrimeLocalFactor_eq (p : ℕ) [NeZero p] (hp : 2 ≤ p) + (u : ZMod p) : + threePrimeLocalFactor p u = + if u = 0 then 1 - 1 / ((p : ℝ) - 1) ^ 2 + else 1 + 1 / ((p : ℝ) - 1) ^ 3 := by + have hpR : (2 : ℝ) ≤ p := by exact_mod_cast hp + have hden : (p : ℝ) - 1 ≠ 0 := by linarith + rw [threePrimeLocalFactor, threePrimeLocalPairs_card_real p hp u] + split_ifs <;> field_simp <;> ring + +/-- The natural-number formulation distinguishes primes dividing the target. -/ +theorem threePrimeLocalFactor_natCast (p u : ℕ) [NeZero p] (hp : 2 ≤ p) : + threePrimeLocalFactor p (u : ZMod p) = + if p ∣ u then 1 - 1 / ((p : ℝ) - 1) ^ 2 + else 1 + 1 / ((p : ℝ) - 1) ^ 3 := by + rw [threePrimeLocalFactor_eq p hp] + simp only [ZMod.natCast_eq_zero_iff] + +/-- An odd target has the positive factor two at the prime two. -/ +theorem threePrimeLocalFactor_two (u : ℕ) (hu : Odd u) : + threePrimeLocalFactor 2 (u : ZMod 2) = 2 := by + rw [threePrimeLocalFactor_natCast 2 u (by omega)] + have hnot : ¬2 ∣ u := by + rw [← ZMod.natCast_eq_zero_iff] + exact ZMod.natCast_ne_zero_iff_odd.mpr hu + norm_num [hnot] + +/-- The literal ordered triples underlying the local density. -/ +def threePrimeLocalTriples (p : ℕ) [NeZero p] (u : ZMod p) : + Finset (ZMod p × ZMod p × ZMod p) := + Finset.univ.filter (fun t => + t.1 ≠ 0 ∧ t.2.1 ≠ 0 ∧ t.2.2 ≠ 0 ∧ t.1 + t.2.1 + t.2.2 = u) + +/-- The third residue is uniquely determined by the first two. -/ +theorem threePrimeLocalTriples_eq_image (p : ℕ) [NeZero p] (u : ZMod p) : + threePrimeLocalTriples p u = + (threePrimeLocalPairs p u).image (fun t => (t.1, t.2, u - t.1 - t.2)) := by + classical + ext t + rcases t with ⟨x, y, z⟩ + constructor + · intro ht + obtain ⟨hx, hy, hz, hsum⟩ := (Finset.mem_filter.mp ht).2 + have hthird : u - x - y = z := by linear_combination -hsum + refine Finset.mem_image.mpr ⟨(x, y), ?_, ?_⟩ + · exact (mem_threePrimeLocalPairs u x y).mpr ⟨hx, hy, by simpa [hthird] using hz⟩ + · simp [hthird] + · intro ht + obtain ⟨⟨a, b⟩, hab, h⟩ := Finset.mem_image.mp ht + obtain ⟨hx, hy, hz⟩ := (mem_threePrimeLocalPairs u a b).mp hab + rw [← h] + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _, hx, hy, hz, ?_⟩ + ring + +/-- The two-coordinate parametrization does not change the local count. -/ +theorem threePrimeLocalTriples_card (p : ℕ) [NeZero p] (u : ZMod p) : + (threePrimeLocalTriples p u).card = (threePrimeLocalPairs p u).card := by + rw [threePrimeLocalTriples_eq_image] + apply Finset.card_image_of_injective + intro a b h + apply Prod.ext + · exact congrArg (fun t : ZMod p × ZMod p × ZMod p => t.1) h + · exact congrArg (fun t : ZMod p × ZMod p × ZMod p => t.2.1) h + +/-- For a prime modulus, the nonzero residue condition is exactly the unit +condition used in the prime singular series. -/ +theorem mem_threePrimeLocalTriples_iff_units (p : ℕ) [Fact p.Prime] + (u : ZMod p) (t : ZMod p × ZMod p × ZMod p) : + t ∈ threePrimeLocalTriples p u ↔ + IsUnit t.1 ∧ IsUnit t.2.1 ∧ IsUnit t.2.2 ∧ t.1 + t.2.1 + t.2.2 = u := by + simp [threePrimeLocalTriples, isUnit_iff_ne_zero] + +/-- There is no local obstruction at a modulus of at least three when only +nonzero residue classes are required. -/ +theorem threePrimeLocalPairs_card_pos (p : ℕ) [NeZero p] (hp : 3 ≤ p) + (u : ZMod p) : 0 < (threePrimeLocalPairs p u).card := by + rw [threePrimeLocalPairs_card p (by omega) u] + have hp1 : 0 < p - 1 := by omega + have hp2 : 0 < p - 2 := by omega + split_ifs <;> positivity + +/-- In particular every odd-prime local density is strictly positive. -/ +theorem threePrimeLocalFactor_pos_of_three_le (p : ℕ) [NeZero p] + (hp : 3 ≤ p) (u : ZMod p) : 0 < threePrimeLocalFactor p u := by + have hpR : (3 : ℝ) ≤ p := by exact_mod_cast hp + have hcard : (0 : ℝ) < (threePrimeLocalPairs p u).card := by + exact_mod_cast threePrimeLocalPairs_card_pos p hp u + dsimp [threePrimeLocalFactor] + exact div_pos (mul_pos (by linarith) hcard) (pow_pos (by linarith) _) + +/-- The only nonzero-residue ternary-sum obstruction is zero modulo two. -/ +theorem threePrimeLocalTriples_nonempty_iff (p : ℕ) [NeZero p] + (hp : 2 ≤ p) (u : ZMod p) : + (threePrimeLocalTriples p u).Nonempty ↔ p ≠ 2 ∨ u ≠ 0 := by + rw [← Finset.card_pos, threePrimeLocalTriples_card] + by_cases hp2 : p = 2 + · subst p + rw [threePrimeLocalPairs_card 2 (by omega)] + by_cases hu : u = 0 <;> simp [hu] + · have hpos := threePrimeLocalPairs_card_pos p (by omega) u + simp [hp2, hpos] + +/-- Every prime local factor is positive for odd natural targets. -/ +theorem threePrimeLocalFactor_pos (p u : ℕ) [Fact p.Prime] (hu : Odd u) : + 0 < threePrimeLocalFactor p (u : ZMod p) := by + have hp := (Fact.out : p.Prime).two_le + by_cases hp2 : p = 2 + · subst p + rw [threePrimeLocalFactor_two u hu] + norm_num + · exact threePrimeLocalFactor_pos_of_three_le p (by omega) _ + +/-- Oddness is exactly the local-solubility condition for a sum of three unit +residue classes at every prime. This is only a local statement, not a theorem +that those residue classes lift simultaneously to three prime integers. -/ +theorem threePrimeLocalSolubility_iff_odd (u : ℕ) : + (∀ p : ℕ, p.Prime → ∃ x y z : ZMod p, + IsUnit x ∧ IsUnit y ∧ IsUnit z ∧ x + y + z = (u : ZMod p)) ↔ Odd u := by + constructor + · intro h + obtain ⟨x, y, z, hx, hy, hz, hsum⟩ := h 2 Nat.prime_two + have hmem : (x, y, z) ∈ threePrimeLocalTriples 2 (u : ZMod 2) := + (mem_threePrimeLocalTriples_iff_units 2 _ _).mpr ⟨hx, hy, hz, hsum⟩ + have hnonzero := (threePrimeLocalTriples_nonempty_iff 2 (by omega) _).mp ⟨_, hmem⟩ + exact ZMod.natCast_ne_zero_iff_odd.mp (hnonzero.resolve_left (by simp)) + · intro hu p hp + let : Fact p.Prime := ⟨hp⟩ + have hlocal : p ≠ 2 ∨ (u : ZMod p) ≠ 0 := by + by_cases hp2 : p = 2 + · right + subst p + exact ZMod.natCast_ne_zero_iff_odd.mpr hu + · exact Or.inl hp2 + obtain ⟨t, ht⟩ := (threePrimeLocalTriples_nonempty_iff p hp.two_le _).mpr hlocal + exact ⟨t.1, t.2.1, t.2.2, (mem_threePrimeLocalTriples_iff_units p _ _).mp ht⟩ + +private lemma sum_zmod_zero_other (p : ℕ) [NeZero p] (hp : 1 ≤ p) + (a b : ℝ) : + (∑ u : ZMod p, if u = 0 then a else b) = ((p : ℝ) - 1) * b + a := by + classical + rw [← Finset.sum_erase_add (s := (Finset.univ : Finset (ZMod p))) + (fun u => if u = 0 then a else b) (Finset.mem_univ 0)] + have heq : (∑ u ∈ (Finset.univ : Finset (ZMod p)).erase 0, + if u = 0 then a else b) = + ∑ _u ∈ (Finset.univ : Finset (ZMod p)).erase 0, b := by + apply Finset.sum_congr rfl + intro u hu + exact ite_eq_right (Finset.mem_erase.mp hu).1 + rw [heq] + simp [Nat.cast_sub hp] + +/-- The normalized local solution density has exact average one. -/ +theorem sum_threePrimeLocalFactor (p : ℕ) [NeZero p] (hp : 2 ≤ p) : + (∑ u : ZMod p, threePrimeLocalFactor p u) = (p : ℝ) := by + simp_rw [threePrimeLocalFactor_eq p hp] + rw [sum_zmod_zero_other p (by omega)] + have hpR : (2 : ℝ) ≤ p := by exact_mod_cast hp + have hden : (p : ℝ) - 1 ≠ 0 := by linarith + field_simp + ring + +/-- Exact local variance of the ternary density: after dividing by the number +of residues, it is `(p - 1)⁻⁵`. -/ +theorem sum_threePrimeLocalFactor_centered_sq (p : ℕ) [NeZero p] (hp : 2 ≤ p) : + (∑ u : ZMod p, (threePrimeLocalFactor p u - 1) ^ 2) = + (p : ℝ) / ((p : ℝ) - 1) ^ 5 := by + have hpR : (2 : ℝ) ≤ p := by exact_mod_cast hp + have hden : (p : ℝ) - 1 ≠ 0 := by linarith + have heq (u : ZMod p) : (threePrimeLocalFactor p u - 1) ^ 2 = + if u = 0 then 1 / ((p : ℝ) - 1) ^ 4 else 1 / ((p : ℝ) - 1) ^ 6 := by + rw [threePrimeLocalFactor_eq p hp] + split_ifs <;> field_simp <;> ring + simp_rw [heq] + rw [sum_zmod_zero_other p (by omega)] + field_simp + ring + +/-- The exact uncentered second moment, useful with the independent CRT +multiplicativity of local densities. -/ +theorem sum_threePrimeLocalFactor_sq (p : ℕ) [NeZero p] (hp : 2 ≤ p) : + (∑ u : ZMod p, (threePrimeLocalFactor p u) ^ 2) = + (p : ℝ) * (1 + 1 / ((p : ℝ) - 1) ^ 5) := by + have heq (u : ZMod p) : (threePrimeLocalFactor p u) ^ 2 = + (threePrimeLocalFactor p u - 1) ^ 2 + 2 * threePrimeLocalFactor p u - 1 := by + ring + simp_rw [heq] + rw [Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, + sum_threePrimeLocalFactor p hp, sum_threePrimeLocalFactor_centered_sq p hp] + simp only [Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul, mul_one] + ring + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalFactor.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalFactor.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad0b99ebe8579c7e0149b7f4f342c77113b6f07a --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalFactor.lean @@ -0,0 +1,105 @@ +import OAI.NumberTheory.EgyptianFractions.FiveProducts + +namespace OAI +noncomputable section + +open scoped BigOperators + +namespace Problem337.ThreePrimeLocalFactor + +/-- Orthogonality with the zero residue removed. -/ +theorem nonzero_character_sum {p : ℕ} [NeZero p] (t : ZMod p) : + (∑ a ∈ (Finset.univ : Finset (ZMod p)).erase 0, + ZMod.stdAddChar (t * a)) = + if t = 0 then (p : ℂ) - 1 else -1 := by + classical + have hsum := FiveProducts.character_sum t + have hsplit := Finset.sum_erase_add + (s := (Finset.univ : Finset (ZMod p))) + (fun a => ZMod.stdAddChar (t * a)) (Finset.mem_univ 0) + simp only [mul_zero, AddChar.map_zero_eq_one] at hsplit + rw [hsum] at hsplit + split_ifs at hsplit ⊢ <;> linear_combination hsplit + +/-- The prime-modulus Ramanujan sum, indexed by nonzero residues. -/ +def primeRamanujanSum (p : ℕ) [NeZero p] (u : ℕ) : ℂ := + ∑ a ∈ (Finset.univ : Finset (ZMod p)).erase 0, + ZMod.stdAddChar (-(u : ZMod p) * a) + +/-- Removing the zero frequency from character orthogonality gives the +prime Ramanujan sum. In fact this formula needs only a nonzero modulus. -/ +theorem primeRamanujanSum_eq (p : ℕ) [NeZero p] (u : ℕ) : + primeRamanujanSum p u = if p ∣ u then (p : ℂ) - 1 else -1 := by + simpa only [primeRamanujanSum, neg_eq_zero, ZMod.natCast_eq_zero_iff] using + nonzero_character_sum (-(u : ZMod p)) + +/-- The normalized cubic prime-frequency contribution to the ternary +singular series. -/ +def localFactor (p u : ℕ) [NeZero p] : ℂ := + 1 - primeRamanujanSum p u / ((p : ℂ) - 1) ^ 3 + +/-- The two familiar local factors follow exactly from finite character +orthogonality; this is not an asymptotic prime-counting assertion. -/ +theorem localFactor_eq (p u : ℕ) (hp : p.Prime) : + letI : NeZero p := ⟨hp.ne_zero⟩ + localFactor p u = + if p ∣ u then 1 - 1 / ((p : ℂ) - 1) ^ 2 + else 1 + 1 / ((p : ℂ) - 1) ^ 3 := by + let : NeZero p := ⟨hp.ne_zero⟩ + have hp1 : (p : ℂ) - 1 ≠ 0 := by + exact sub_ne_zero.mpr (by exact_mod_cast hp.ne_one) + rw [localFactor, primeRamanujanSum_eq] + split_ifs + · field_simp + · ring + +/-- The normalized cubic exponential-sum contribution of the nonzero +frequencies at a prime modulus. -/ +def cubicPrimeCoefficient (p u : ℕ) [NeZero p] : ℂ := + ∑ a ∈ (Finset.univ : Finset (ZMod p)).erase 0, + ((∑ b ∈ (Finset.univ : Finset (ZMod p)).erase 0, + ZMod.stdAddChar (a * b)) / ((p : ℂ) - 1)) ^ 3 * + ZMod.stdAddChar (-(u : ZMod p) * a) + +/-- The cubic coefficient is exactly the signed, normalized Ramanujan sum. +Thus the local Euler factor is the zero-frequency contribution plus the +actual nonzero-frequency cubic sum. -/ +theorem cubicPrimeCoefficient_eq (p u : ℕ) [NeZero p] : + cubicPrimeCoefficient p u = + -primeRamanujanSum p u / ((p : ℂ) - 1) ^ 3 := by + classical + unfold cubicPrimeCoefficient + calc + _ = ∑ a ∈ (Finset.univ : Finset (ZMod p)).erase 0, + (-1 / ((p : ℂ) - 1) ^ 3) * + ZMod.stdAddChar (-(u : ZMod p) * a) := by + apply Finset.sum_congr rfl + intro a ha + rw [nonzero_character_sum, ite_eq_right (Finset.mem_erase.mp ha).1, div_pow] + norm_num + _ = (-1 / ((p : ℂ) - 1) ^ 3) * primeRamanujanSum p u := by + rw [← Finset.mul_sum] + rfl + _ = _ := by ring + +theorem one_add_cubicPrimeCoefficient (p u : ℕ) [NeZero p] : + 1 + cubicPrimeCoefficient p u = localFactor p u := by + rw [cubicPrimeCoefficient_eq, localFactor] + ring + +/-- A real-valued statement of the local factor for direct use with real +Euler products. -/ +theorem one_add_cubicPrimeCoefficient_eq_real (p u : ℕ) (hp : p.Prime) : + letI : NeZero p := ⟨hp.ne_zero⟩ + 1 + cubicPrimeCoefficient p u = + ((if p ∣ u then 1 - 1 / ((p : ℝ) - 1) ^ 2 + else 1 + 1 / ((p : ℝ) - 1) ^ 3 : ℝ) : ℂ) := by + let : NeZero p := ⟨hp.ne_zero⟩ + rw [one_add_cubicPrimeCoefficient, localFactor_eq p u hp] + split_ifs <;> push_cast <;> rfl + +end Problem337.ThreePrimeLocalFactor + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalFourier.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalFourier.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c7da7fbf6828d374570dfdd2e67a9b968a6df7f --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalFourier.lean @@ -0,0 +1,43 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeLocalDensity +import OAI.NumberTheory.EgyptianFractions.ThreePrimeLocalFactor + +namespace OAI +noncomputable section + +namespace Problem337 + +/-- The normalized actual local solution count agrees with the zero frequency +plus the normalized cubic nonzero-frequency sum. -/ +theorem threePrimeLocalFactor_eq_cubic (p u : ℕ) [Fact p.Prime] : + (threePrimeLocalFactor p (u : ZMod p) : ℂ) = + 1 + ThreePrimeLocalFactor.cubicPrimeCoefficient p u := by + have hp := (Fact.out : p.Prime) + rw [threePrimeLocalFactor_natCast p u hp.two_le] + exact (ThreePrimeLocalFactor.one_add_cubicPrimeCoefficient_eq_real p u hp).symm + +/-- An unnormalized finite Fourier identity for literal local unit triples. +All normalizing constants are checked against the combinatorial count. -/ +theorem threePrimeLocalTriples_card_fourier (p u : ℕ) [Fact p.Prime] : + (p : ℂ) * (threePrimeLocalTriples p (u : ZMod p)).card = + ((p : ℂ) - 1) ^ 3 * + (1 + ThreePrimeLocalFactor.cubicPrimeCoefficient p u) := by + have hp := (Fact.out : p.Prime) + have hp1 : (p : ℂ) - 1 ≠ 0 := by + exact sub_ne_zero.mpr (by exact_mod_cast hp.ne_one) + rw [threePrimeLocalTriples_card, ← threePrimeLocalFactor_eq_cubic] + unfold threePrimeLocalFactor + push_cast + field_simp + +/-- The cubic prime-frequency contribution is real, as follows from its +independently counted local-density interpretation. -/ +theorem threePrimeCubicCoefficient_im (p u : ℕ) [Fact p.Prime] : + (ThreePrimeLocalFactor.cubicPrimeCoefficient p u).im = 0 := by + have h := congrArg Complex.im (threePrimeLocalFactor_eq_cubic p u) + simpa using h.symm + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalSeries.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee64165debf56f21e4f507085d3f0399ca6de552 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeLocalSeries.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeLocalDensity +import OAI.NumberTheory.EgyptianFractions.ThreePrimeSingularSeries + +namespace OAI +noncomputable section + +open scoped BigOperators + +namespace Problem337 + +/-- The normalized actual local unit-triple count at prime moduli, with one at +nonprime indices. The inactive branch makes this a total natural-indexed +function without imposing a finiteness instance on `ZMod 0`. -/ +def threePrimeArithmeticFactor (p u : ℕ) : ℝ := + if hp : p.Prime then + @threePrimeLocalFactor p ⟨hp.ne_zero⟩ (u : ZMod p) + else 1 + +lemma threePrimeArithmeticFactor_of_prime (p u : ℕ) (hp : p.Prime) : + threePrimeArithmeticFactor p u = + if p ∣ u then 1 - 1 / ((p : ℝ) - 1) ^ 2 + else 1 + 1 / ((p : ℝ) - 1) ^ 3 := by + let : NeZero p := ⟨hp.ne_zero⟩ + simpa only [threePrimeArithmeticFactor, dite_eq_left hp] using + threePrimeLocalFactor_natCast p u hp.two_le + +lemma threePrimeArithmeticFactor_of_not_prime (p u : ℕ) (hp : ¬p.Prime) : + threePrimeArithmeticFactor p u = 1 := by + simp only [threePrimeArithmeticFactor, dite_eq_right hp] + +/-- The analytically indexed odd-prime Euler factor is the normalized actual +count of its local unit solutions. -/ +theorem threePrimeOddFactor_eq_arithmeticFactor (u n : ℕ) : + 1 + threePrimeOddPerturbation u n = threePrimeArithmeticFactor (n + 3) u := by + by_cases hp : (n + 3).Prime + · rw [threePrimeArithmeticFactor_of_prime _ _ hp] + have hn : ((n + 3 : ℕ) : ℝ) - 1 = (n : ℝ) + 2 := by push_cast; ring + rw [hn] + simp only [threePrimeOddPerturbation, ite_eq_left hp] + split_ifs <;> ring + · simp [threePrimeOddPerturbation, hp, + threePrimeArithmeticFactor_of_not_prime _ _ hp] + +/-- The local unit-triple factor at two records precisely the parity obstruction. -/ +theorem threePrimeArithmeticFactor_two (u : ℕ) : + threePrimeArithmeticFactor 2 u = if Odd u then 2 else 0 := by + rw [threePrimeArithmeticFactor_of_prime 2 u Nat.prime_two] + have hdvd : 2 ∣ u ↔ ¬Odd u := by + rw [← ZMod.natCast_eq_zero_iff] + exact not_iff_not.mp (by simp only [not_not, ZMod.natCast_ne_zero_iff_odd]) + by_cases hu : Odd u <;> norm_num [hdvd, hu] + +/-- Exact interpretation of the singular series as the product of normalized +finite local unit-triple solution counts. -/ +theorem threePrimeSingularSeries_eq_localProduct (u : ℕ) : + threePrimeSingularSeries u = threePrimeArithmeticFactor 2 u * + ∏' n : ℕ, threePrimeArithmeticFactor (n + 3) u := by + rw [threePrimeSingularSeries, threePrimeArithmeticFactor_two] + simp_rw [threePrimeOddFactor_eq_arithmeticFactor] + +/-- The actual local-factor product converges, rather than merely being a +formal Euler-product notation. -/ +theorem threePrimeArithmeticFactors_multipliable (u : ℕ) : + Multipliable (fun n : ℕ => threePrimeArithmeticFactor (n + 3) u) := by + simpa only [threePrimeOddFactor_eq_arithmeticFactor] using + threePrimeOddFactors_multipliable u + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldt.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldt.lean new file mode 100644 index 0000000000000000000000000000000000000000..148d6c383c02969e625b5256a296b4b047eef26e --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldt.lean @@ -0,0 +1,249 @@ +import OAI.NumberTheory.EgyptianFractions.RationalSupplyReduction +import Mathlib.NumberTheory.Chebyshev + +namespace OAI +noncomputable section +open scoped BigOperators +open Filter Asymptotics + +namespace Problem337 + +/-- All positive ordered triples of fixed sum, without primality restrictions. -/ +def supplyIntegerTriples (u : ℕ) : Finset (ℕ × ℕ × ℕ) := + ((Finset.Icc 1 u) ×ˢ ((Finset.Icc 1 u) ×ˢ (Finset.Icc 1 u))).filter + (fun t => t.1 + t.2.1 + t.2.2 = u) + +/-- Logarithmic weight supported only on primes, unlike the von Mangoldt weight. -/ +def primeLogWeight (n : ℕ) : ℝ := if n.Prime then Real.log n else 0 + +/-- The weighted ternary convolution used in the analytic three-prime theorem. -/ +def mangoldtTripleSum (u : ℕ) : ℝ := + ∑ t ∈ supplyIntegerTriples u, + ArithmeticFunction.vonMangoldt t.1 * ArithmeticFunction.vonMangoldt t.2.1 * + ArithmeticFunction.vonMangoldt t.2.2 + +/-- The corresponding weighted sum over genuine prime triples. -/ +def primeTripleLogSum (u : ℕ) : ℝ := + ∑ t ∈ supplyPrimeTriples u, + Real.log (t.1 : ℝ) * Real.log (t.2.1 : ℝ) * Real.log (t.2.2 : ℝ) + +lemma primeLogWeight_nonneg (n : ℕ) : 0 ≤ primeLogWeight n := by + unfold primeLogWeight + split_ifs with hn + · exact Real.log_nonneg (by exact_mod_cast hn.one_le) + · exact le_rfl + +lemma primeLogWeight_le_vonMangoldt (n : ℕ) : + primeLogWeight n ≤ ArithmeticFunction.vonMangoldt n := by + unfold primeLogWeight + split_ifs with hn + · exact (ArithmeticFunction.vonMangoldt_apply_prime hn).ge + · exact ArithmeticFunction.vonMangoldt_nonneg + +lemma primeTripleLogSum_eq (u : ℕ) : + primeTripleLogSum u = ∑ t ∈ supplyIntegerTriples u, + primeLogWeight t.1 * primeLogWeight t.2.1 * primeLogWeight t.2.2 := by + classical + have hset : supplyPrimeTriples u = (supplyIntegerTriples u).filter + (fun t => t.1.Prime ∧ t.2.1.Prime ∧ t.2.2.Prime) := by + ext t + simp only [supplyPrimeTriples, supplyIntegerTriples, Finset.mem_filter] + tauto + unfold primeTripleLogSum + rw [hset, Finset.sum_filter] + apply Finset.sum_congr rfl + intro t ht + by_cases h1 : t.1.Prime <;> by_cases h2 : t.2.1.Prime <;> + by_cases h3 : t.2.2.Prime <;> simp [primeLogWeight, h1, h2, h3] + +/-- A weighted version of the fixed-coordinate counting bound. -/ +lemma fixed_sum_coordinate_sum_le + {α : Type*} [DecidableEq α] (T : Finset α) (U : Finset ℕ) + (x y z : α → ℕ) (u : ℕ) (f : ℕ → ℝ) + (hf : ∀ n ∈ U, 0 ≤ f n) + (hsum : ∀ t ∈ T, x t + y t + z t = u) + (hU : ∀ t ∈ T, x t ∈ U ∧ y t ∈ U) + (hinj : Function.Injective (fun t => (x t, y t, z t))) : + (∑ t ∈ T, f (x t)) ≤ (U.card : ℝ) * ∑ n ∈ U, f n := by + classical + have hi : Set.InjOn (fun t => (x t, y t)) (T : Set α) := by + intro a ha b hb hab + have hxy := Prod.mk.inj hab + have hz : z a = z b := by + have := hsum a ha + have := hsum b hb + omega + exact hinj (Prod.ext hxy.1 (Prod.ext hxy.2 hz)) + have hsub : T.image (fun t => (x t, y t)) ⊆ U ×ˢ U := by + intro q hq + obtain ⟨t, ht, rfl⟩ := Finset.mem_image.mp hq + exact Finset.mem_product.mpr (hU t ht) + calc + (∑ t ∈ T, f (x t)) = ∑ q ∈ T.image (fun t => (x t, y t)), f q.1 := by + rw [Finset.sum_image] + exact hi + _ ≤ ∑ q ∈ U ×ˢ U, f q.1 := by + apply Finset.sum_le_sum_of_subset_of_nonneg hsub + intro q hq _ + exact hf q.1 (Finset.mem_product.mp hq).1 + _ = (U.card : ℝ) * ∑ n ∈ U, f n := by + rw [Finset.sum_product] + simp only [Finset.sum_const, nsmul_eq_mul] + rw [← Finset.mul_sum] + +/-- Prime powers of exponent at least two carry exactly the difference of the +Chebyshev functions. -/ +lemma sum_primePowerLogWeight (u : ℕ) : + (∑ n ∈ Finset.Icc 1 u, + (ArithmeticFunction.vonMangoldt n - primeLogWeight n)) = + Chebyshev.psi u - Chebyshev.theta u := by + rw [Finset.sum_sub_distrib] + congr 1 + · simp only [Chebyshev.psi, Nat.floor_natCast] + congr 1 + · simp only [Chebyshev.theta, Nat.floor_natCast, Finset.sum_filter, + primeLogWeight] + congr 1 + +private lemma triple_product_difference_le + (a b c p q r L : ℝ) + (hp : 0 ≤ p) (hq : 0 ≤ q) (hr : 0 ≤ r) + (hpa : p ≤ a) (hqb : q ≤ b) (hrc : r ≤ c) + (ha : a ≤ L) (hb : b ≤ L) (hc : c ≤ L) : + a * b * c ≤ p * q * r + L ^ 2 * ((a - p) + (b - q) + (c - r)) := by + have hL : 0 ≤ L := hp.trans (hpa.trans ha) + have ha0 := hp.trans hpa + have hb0 := hq.trans hqb + have hc0 := hr.trans hrc + have hpL := hpa.trans ha + have hqL := hqb.trans hb + have h1 : (a - p) * b * c ≤ (a - p) * L * L := by gcongr + have h2 : p * (b - q) * c ≤ L * (b - q) * L := by gcongr + have h3 : p * q * (c - r) ≤ L * L * (c - r) := by gcongr + nlinarith + +lemma mangoldtTripleSum_le_primeTripleLogSum (u : ℕ) : + mangoldtTripleSum u ≤ primeTripleLogSum u + + 3 * (u : ℝ) * Real.log (u : ℝ) ^ 2 * + (Chebyshev.psi u - Chebyshev.theta u) := by + classical + let U := Finset.Icc 1 u + let T := supplyIntegerTriples u + let d : ℕ → ℝ := fun n => ArithmeticFunction.vonMangoldt n - primeLogWeight n + have hd (n : ℕ) : 0 ≤ d n := sub_nonneg.mpr (primeLogWeight_le_vonMangoldt n) + have hT (t : ℕ × ℕ × ℕ) (ht : t ∈ T) : + t.1 ∈ U ∧ t.2.1 ∈ U ∧ t.2.2 ∈ U := by + obtain ⟨ht, _⟩ := Finset.mem_filter.mp ht + exact (Finset.mem_product.mp ht).imp_right Finset.mem_product.mp + have hsum (t : ℕ × ℕ × ℕ) (ht : t ∈ T) : + t.1 + t.2.1 + t.2.2 = u := (Finset.mem_filter.mp ht).2 + have hweight (n : ℕ) (hn : n ∈ U) : + ArithmeticFunction.vonMangoldt n ≤ Real.log (u : ℝ) := by + apply ArithmeticFunction.vonMangoldt_le_log.trans + apply Real.log_le_log + · exact_mod_cast (Finset.mem_Icc.mp hn).1 + · exact_mod_cast (Finset.mem_Icc.mp hn).2 + have h1 := fixed_sum_coordinate_sum_le T U (fun t => t.1) + (fun t => t.2.1) (fun t => t.2.2) u d (fun n _ => hd n) + hsum (fun t ht => ⟨(hT t ht).1, (hT t ht).2.1⟩) + (by intro a b h; exact h) + have h2 := fixed_sum_coordinate_sum_le T U (fun t => t.2.1) + (fun t => t.1) (fun t => t.2.2) u d (fun n _ => hd n) + (by intro t ht; have := hsum t ht; omega) + (fun t ht => ⟨(hT t ht).2.1, (hT t ht).1⟩) + (by + intro a b h + have hc := Prod.mk.inj h + have hh := Prod.mk.inj hc.2 + exact Prod.ext hh.1 (Prod.ext hc.1 hh.2)) + have h3 := fixed_sum_coordinate_sum_le T U (fun t => t.2.2) + (fun t => t.1) (fun t => t.2.1) u d (fun n _ => hd n) + (by intro t ht; have := hsum t ht; omega) + (fun t ht => ⟨(hT t ht).2.2, (hT t ht).1⟩) + (by + intro a b h + have hc := Prod.mk.inj h + have hh := Prod.mk.inj hc.2 + exact Prod.ext hh.1 (Prod.ext hh.2 hc.1)) + have hUcard : U.card = u := by simp [U, Nat.card_Icc] + have hdSum : (∑ n ∈ U, d n) = Chebyshev.psi u - Chebyshev.theta u := + sum_primePowerLogWeight u + rw [hUcard, hdSum] at h1 h2 h3 + have hlocal : mangoldtTripleSum u ≤ primeTripleLogSum u + + Real.log (u : ℝ) ^ 2 * + ((∑ t ∈ T, d t.1) + (∑ t ∈ T, d t.2.1) + (∑ t ∈ T, d t.2.2)) := by + calc + mangoldtTripleSum u ≤ ∑ t ∈ T, + (primeLogWeight t.1 * primeLogWeight t.2.1 * primeLogWeight t.2.2 + + Real.log (u : ℝ) ^ 2 * (d t.1 + d t.2.1 + d t.2.2)) := by + apply Finset.sum_le_sum + intro t ht + have htU := hT t ht + exact triple_product_difference_le + (ArithmeticFunction.vonMangoldt t.1) (ArithmeticFunction.vonMangoldt t.2.1) + (ArithmeticFunction.vonMangoldt t.2.2) (primeLogWeight t.1) + (primeLogWeight t.2.1) (primeLogWeight t.2.2) (Real.log u) + (primeLogWeight_nonneg _) (primeLogWeight_nonneg _) (primeLogWeight_nonneg _) + (primeLogWeight_le_vonMangoldt _) (primeLogWeight_le_vonMangoldt _) + (primeLogWeight_le_vonMangoldt _) (hweight _ htU.1) + (hweight _ htU.2.1) (hweight _ htU.2.2) + _ = _ := by + rw [Finset.sum_add_distrib, ← Finset.mul_sum] + simp only [Finset.sum_add_distrib, primeTripleLogSum_eq, T] + have htotal := add_le_add (add_le_add h1 h2) h3 + have hm := mul_le_mul_of_nonneg_left htotal (sq_nonneg (Real.log (u : ℝ))) + nlinarith + +/-- The contribution from genuine higher prime powers is lower order than the +quadratic main term. This uses Mathlib's elementary `ψ - θ = O(sqrt x)` bound. -/ +theorem mangoldt_triple_error_isLittleO : + (fun x : ℝ => 3 * x * Real.log x ^ 2 * + (Chebyshev.psi x - Chebyshev.theta x)) =o[atTop] (fun x : ℝ => x ^ 2) := by + have hlog : (fun x : ℝ => Real.log x ^ 2) =o[atTop] + (fun x : ℝ => x ^ (1 / 2 : ℝ)) := by + simpa only [Real.rpow_two] using + isLittleO_log_rpow_rpow_atTop (2 : ℝ) (by norm_num : (0 : ℝ) < 1 / 2) + have hsmall := hlog.mul_isBigO Chebyshev.isBigO_psi_sub_theta_sqrt + have hscaled := hsmall.mul_isBigO (isBigO_refl (fun x : ℝ => x) atTop) + have hquadratic : + (fun x : ℝ => x * Real.log x ^ 2 * (Chebyshev.psi x - Chebyshev.theta x)) + =o[atTop] (fun x : ℝ => x ^ 2) := by + apply hscaled.congr' + · exact Eventually.of_forall (fun x => by simp only [Pi.sub_apply]; ring) + · filter_upwards [eventually_gt_atTop (0 : ℝ)] with x hx + rw [Real.sqrt_eq_rpow, ← Real.rpow_add hx] + norm_num + ring + simpa only [mul_assoc] using hquadratic.const_mul_left 3 + +/-- Explicit error absorption along the natural-number parameter. -/ +theorem eventually_mangoldt_triple_error_lt (ε : ℝ) (hε : 0 < ε) : + ∀ᶠ u : ℕ in atTop, + 3 * (u : ℝ) * Real.log (u : ℝ) ^ 2 * + (Chebyshev.psi u - Chebyshev.theta u) < ε * (u : ℝ) ^ 2 := by + have hsmall := mangoldt_triple_error_isLittleO.bound (show 0 < ε / 2 by positivity) + have hn := (tendsto_natCast_atTop_atTop (R := ℝ)).eventually hsmall + filter_upwards [hn, eventually_ge_atTop (1 : ℕ)] with u hu hu1 + rw [Real.norm_of_nonneg (sq_nonneg (u : ℝ))] at hu + have hu0 : (0 : ℝ) < u := by exact_mod_cast hu1 + exact (le_trans (le_abs_self _) hu).trans_lt (by nlinarith [sq_pos_of_pos hu0]) + +/-- An analytic quadratic lower bound for the von Mangoldt convolution implies +one for the prime-only weighted sum. No analytic lower bound is asserted here. -/ +theorem weighted_prime_lower_bound_of_mangoldt + (c : ℝ) (hc : 0 < c) + (hmain : ∀ᶠ u : ℕ in atTop, Odd u → c * (u : ℝ) ^ 2 ≤ mangoldtTripleSum u) : + ∀ᶠ u : ℕ in atTop, Odd u → + (c / 2) * (u : ℝ) ^ 2 ≤ primeTripleLogSum u := by + filter_upwards [hmain, eventually_mangoldt_triple_error_lt (c / 2) (by positivity)] + with u hu herr + intro hodd + have hupper := mangoldtTripleSum_le_primeTripleLogSum u + have hlower := hu hodd + linarith + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtAsymptotics.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtAsymptotics.lean new file mode 100644 index 0000000000000000000000000000000000000000..7ec6751703d6a1c7302197a76321560c5cde49fe --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtAsymptotics.lean @@ -0,0 +1,82 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeMangoldt + +namespace OAI +noncomputable section +open scoped BigOperators +open Filter Asymptotics + +namespace Problem337 + +/-- Removing higher prime powers can only reduce a nonnegative convolution. -/ +lemma primeTripleLogSum_le_mangoldtTripleSum (u : ℕ) : + primeTripleLogSum u ≤ mangoldtTripleSum u := by + rw [primeTripleLogSum_eq] + unfold mangoldtTripleSum + apply Finset.sum_le_sum + intro t ht + exact mul_le_mul + (mul_le_mul (primeLogWeight_le_vonMangoldt t.1) + (primeLogWeight_le_vonMangoldt t.2.1) + (primeLogWeight_nonneg t.2.1) ArithmeticFunction.vonMangoldt_nonneg) + (primeLogWeight_le_vonMangoldt t.2.2) (primeLogWeight_nonneg t.2.2) + (mul_nonneg ArithmeticFunction.vonMangoldt_nonneg ArithmeticFunction.vonMangoldt_nonneg) + +/-- Two-sided control of the actual convolution error, without an analytic hypothesis. -/ +theorem abs_mangoldtTripleSum_sub_primeTripleLogSum_le (u : ℕ) : + |mangoldtTripleSum u - primeTripleLogSum u| ≤ + 3 * (u : ℝ) * Real.log (u : ℝ) ^ 2 * + (Chebyshev.psi u - Chebyshev.theta u) := by + rw [abs_of_nonneg (sub_nonneg.mpr (primeTripleLogSum_le_mangoldtTripleSum u))] + linarith [mangoldtTripleSum_le_primeTripleLogSum u] + +/-- Higher prime powers do not affect the normalized quadratic main term. -/ +theorem mangoldtTripleSum_sub_primeTripleLogSum_isLittleO : + (fun u : ℕ => mangoldtTripleSum u - primeTripleLogSum u) =o[atTop] + (fun u : ℕ => (u : ℝ) ^ 2) := by + have hbound := mangoldt_triple_error_isLittleO.comp_tendsto + (tendsto_natCast_atTop_atTop (R := ℝ)) + apply IsLittleO.of_bound + intro c hc + filter_upwards [hbound.bound hc] with u hu + simp only [Function.comp_apply, Real.norm_eq_abs] at hu ⊢ + exact (abs_mangoldtTripleSum_sub_primeTripleLogSum_le u).trans + ((le_abs_self _).trans hu) + +/-- The normalized difference converges to zero along all natural integers. -/ +theorem tendsto_mangoldtTripleSum_sub_primeTripleLogSum_div_sq : + Tendsto (fun u : ℕ => + (mangoldtTripleSum u - primeTripleLogSum u) / (u : ℝ) ^ 2) + atTop (nhds 0) := + mangoldtTripleSum_sub_primeTripleLogSum_isLittleO.tendsto_div_nhds_zero + +/-- Any quadratic asymptotic, including a varying singular-series coefficient, +is equivalent for the Mangoldt and prime-only convolutions. This is only an +error-transfer theorem: neither asymptotic formula is asserted. -/ +theorem mangoldt_prime_quadratic_asymptotic_iff_filter + (l : Filter ℕ) (hl : l ≤ atTop) (σ : ℕ → ℝ) : + ((fun u : ℕ => mangoldtTripleSum u - σ u * (u : ℝ) ^ 2) =o[l] + (fun u : ℕ => (u : ℝ) ^ 2)) ↔ + ((fun u : ℕ => primeTripleLogSum u - σ u * (u : ℝ) ^ 2) =o[l] + (fun u : ℕ => (u : ℝ) ^ 2)) := by + constructor + · intro h + exact (h.sub (mangoldtTripleSum_sub_primeTripleLogSum_isLittleO.mono hl)).congr_left + (fun u => by ring) + · intro h + exact (h.add (mangoldtTripleSum_sub_primeTripleLogSum_isLittleO.mono hl)).congr_left + (fun u => by ring) + +/-- The same transfer without restricting the parameter (the filter version also +applies directly to the odd integers). -/ +theorem mangoldt_prime_quadratic_asymptotic_iff (σ : ℕ → ℝ) : + ((fun u : ℕ => mangoldtTripleSum u - σ u * (u : ℝ) ^ 2) =o[atTop] + (fun u : ℕ => (u : ℝ) ^ 2)) ↔ + ((fun u : ℕ => primeTripleLogSum u - σ u * (u : ℝ) ^ 2) =o[atTop] + (fun u : ℕ => (u : ℝ) ^ 2)) := + mangoldt_prime_quadratic_asymptotic_iff_filter atTop le_rfl σ + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtBridge.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..99d04e2052ac70c946ba4a6b2193f0ce0e52e8d9 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtBridge.lean @@ -0,0 +1,31 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeMangoldt +import OAI.NumberTheory.EgyptianFractions.ThreePrimeWeighted + +namespace OAI +noncomputable section +open Filter + +namespace Problem337 + +/-- The independently defined prime-weighted counts are identical. -/ +lemma primeTripleLogSum_eq_weightedSupplyPrimeTriples (u : ℕ) : + primeTripleLogSum u = weightedSupplyPrimeTriples u := rfl + +/-- The standard quadratic lower bound for the von Mangoldt convolution is +sufficient for the exact arithmetic hypothesis used in the Egyptian-fraction +construction. The genuinely analytic lower bound remains an explicit premise. -/ +theorem quantitativeThreePrimeLowerBound_of_mangoldt + (hmain : ∃ c : ℝ, 0 < c ∧ ∀ᶠ u : ℕ in atTop, Odd u → + c * (u : ℝ) ^ 2 ≤ mangoldtTripleSum u) : + QuantitativeThreePrimeLowerBound := by + obtain ⟨c, hc, hmain⟩ := hmain + apply quantitativeThreePrimeLowerBound_of_weighted + refine ⟨c / 2, by positivity, ?_⟩ + simpa only [primeTripleLogSum_eq_weightedSupplyPrimeTriples] using + weighted_prime_lower_bound_of_mangoldt c hc hmain + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtIntegral.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..691150fc175e71c60a3138021ffb1eb5d820c33e --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtIntegral.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeContinuousFourier +import OAI.NumberTheory.EgyptianFractions.ThreePrimeMangoldt + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.ThreePrimeContinuousFourier + +/-- The actual positive-frequency Mangoldt polynomial on the unit circle. -/ +def mangoldtPhaseSum (u : ℕ) (x : ℝ) : ℂ := + ∑ n ∈ Finset.Icc 1 u, (ArithmeticFunction.vonMangoldt n : ℂ) * phase (n : ℤ) x + +lemma mangoldtPhaseSum_exp (u : ℕ) (x : ℝ) : + mangoldtPhaseSum u x = ∑ n ∈ Finset.Icc 1 u, + (ArithmeticFunction.vonMangoldt n : ℂ) * + Complex.exp (2 * Real.pi * Complex.I * (n : ℂ) * x) := by + simp only [mangoldtPhaseSum, phase_exp, Int.cast_natCast] + +lemma mangoldtPhaseSum_continuous (u : ℕ) : Continuous (mangoldtPhaseSum u) := by + unfold mangoldtPhaseSum + exact continuous_finsetSum _ (fun n hn => continuous_const.mul (phase_continuous _)) + +/-- Exact continuous cubic extraction for the canonical positive-integer +Mangoldt convolution. In particular no prime-distribution estimate is used. -/ +theorem mangoldt_triple_integral (u : ℕ) : + (∫ x in (0 : ℝ)..1, mangoldtPhaseSum u x ^ 3 * phase (-(u : ℤ)) x) = + (mangoldtTripleSum u : ℂ) := by + classical + have h := weighted_triple_finset_integral (Finset.Icc 1 u) + (fun n : ℕ => (n : ℤ)) (fun n => (ArithmeticFunction.vonMangoldt n : ℂ)) (u : ℤ) + change (∫ x in (0 : ℝ)..1, + (∑ n ∈ Finset.Icc 1 u, (ArithmeticFunction.vonMangoldt n : ℂ) * + phase (n : ℤ) x) ^ 3 * phase (-(u : ℤ)) x) = _ + rw [h] + unfold mangoldtTripleSum supplyIntegerTriples + simp only [Finset.sum_filter, Finset.sum_product, Complex.ofReal_sum] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + apply Finset.sum_congr rfl + intro c hc + have heq : ((a : ℤ) + (b : ℤ) + (c : ℤ) = (u : ℤ)) ↔ a + b + c = u := by omega + by_cases hsum : a + b + c = u <;> simp [heq, hsum] + +/-- The integral is a genuine integrable complex expression, not an appeal to +the default value of the Bochner integral on a nonintegrable function. -/ +theorem mangoldt_cubic_intervalIntegrable (u : ℕ) (a b : ℝ) : + IntervalIntegrable + (fun x => mangoldtPhaseSum u x ^ 3 * phase (-(u : ℤ)) x) MeasureTheory.volume a b := by + exact ((mangoldtPhaseSum_continuous u).pow 3 |>.mul + (phase_continuous _)).intervalIntegrable _ _ + +/-- Taking real parts recovers exactly the real arithmetic convolution. -/ +theorem re_mangoldt_triple_integral (u : ℕ) : + (∫ x in (0 : ℝ)..1, mangoldtPhaseSum u x ^ 3 * phase (-(u : ℤ)) x).re = + mangoldtTripleSum u := by + rw [mangoldt_triple_integral] + rfl + +end Problem337.ThreePrimeContinuousFourier + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtPowerError.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtPowerError.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca084aed473bc43d4eaddb6df11addaef9ba5adf --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMangoldtPowerError.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeMangoldtAsymptotics + +namespace OAI +noncomputable section +open Filter Asymptotics + +namespace Problem337 + +/-- The elementary prime-power error is smaller than every power above `3/2`. -/ +theorem mangoldt_triple_error_isLittleO_rpow + (α : ℝ) (hα : 3 / 2 < α) : + (fun x : ℝ => 3 * x * Real.log x ^ 2 * + (Chebyshev.psi x - Chebyshev.theta x)) =o[atTop] + (fun x : ℝ => x ^ α) := by + have hlog : (fun x : ℝ => Real.log x ^ 2) =o[atTop] + (fun x : ℝ => x ^ (α - 3 / 2)) := by + simpa only [Real.rpow_two] using + isLittleO_log_rpow_rpow_atTop (2 : ℝ) (by linarith : 0 < α - 3 / 2) + have hsmall := hlog.mul_isBigO Chebyshev.isBigO_psi_sub_theta_sqrt + have hscaled := hsmall.mul_isBigO (isBigO_refl (fun x : ℝ => x) atTop) + have hfinal : + (fun x : ℝ => x * Real.log x ^ 2 * (Chebyshev.psi x - Chebyshev.theta x)) + =o[atTop] (fun x : ℝ => x ^ α) := by + apply hscaled.congr' + · exact Eventually.of_forall (fun x => by simp only [Pi.sub_apply]; ring) + · filter_upwards [eventually_gt_atTop (0 : ℝ)] with x hx + rw [Real.sqrt_eq_rpow] + calc + x ^ (α - 3 / 2) * x ^ (1 / 2 : ℝ) * x = + x ^ (α - 3 / 2) * x ^ (1 / 2 : ℝ) * x ^ (1 : ℝ) := by + rw [Real.rpow_one] + _ = x ^ α := by + rw [← Real.rpow_add hx, ← Real.rpow_add hx] + congr 1 + ring + simpa only [mul_assoc] using hfinal.const_mul_left 3 + +/-- Actual Mangoldt and prime-only convolutions differ by `o(u^α)` for `α>3/2`. -/ +theorem mangoldtTripleSum_sub_primeTripleLogSum_isLittleO_rpow + (α : ℝ) (hα : 3 / 2 < α) : + (fun u : ℕ => mangoldtTripleSum u - primeTripleLogSum u) =o[atTop] + (fun u : ℕ => (u : ℝ) ^ α) := by + have hbound := (mangoldt_triple_error_isLittleO_rpow α hα).comp_tendsto + (tendsto_natCast_atTop_atTop (R := ℝ)) + apply IsLittleO.of_bound + intro c hc + filter_upwards [hbound.bound hc] with u hu + simp only [Function.comp_apply, Real.norm_eq_abs] at hu ⊢ + exact (abs_mangoldtTripleSum_sub_primeTripleLogSum_le u).trans + ((le_abs_self _).trans hu) + +/-- A positive power lower bound for the Mangoldt convolution survives removing +higher prime powers at any exponent above `3/2`. The lower bound itself remains +an explicit analytic premise. -/ +theorem weighted_prime_power_lower_bound_of_mangoldt + (α : ℝ) (hα : 3 / 2 < α) (c : ℝ) (hc : 0 < c) + (hmain : ∀ᶠ u : ℕ in atTop, Odd u → c * (u : ℝ) ^ α ≤ mangoldtTripleSum u) : + ∀ᶠ u : ℕ in atTop, Odd u → + (c / 2) * (u : ℝ) ^ α ≤ primeTripleLogSum u := by + have herr := (mangoldtTripleSum_sub_primeTripleLogSum_isLittleO_rpow α hα).bound + (show 0 < c / 2 by positivity) + filter_upwards [hmain, herr] with u hu herr + intro hodd + rw [Real.norm_of_nonneg (Real.rpow_nonneg (Nat.cast_nonneg u) α), + Real.norm_eq_abs] at herr + have habs := le_abs_self (mangoldtTripleSum u - primeTripleLogSum u) + have hlower := hu hodd + linarith + +/-- Transfer of an arbitrary power-scale asymptotic to genuine prime triples, +including along the odd integers or any other subfilter tending to infinity. -/ +theorem mangoldt_prime_rpow_asymptotic_iff_filter + (α : ℝ) (hα : 3 / 2 < α) (l : Filter ℕ) (hl : l ≤ atTop) (σ : ℕ → ℝ) : + ((fun u : ℕ => mangoldtTripleSum u - σ u * (u : ℝ) ^ α) =o[l] + (fun u : ℕ => (u : ℝ) ^ α)) ↔ + ((fun u : ℕ => primeTripleLogSum u - σ u * (u : ℝ) ^ α) =o[l] + (fun u : ℕ => (u : ℝ) ^ α)) := by + have herr := (mangoldtTripleSum_sub_primeTripleLogSum_isLittleO_rpow α hα).mono hl + constructor + · intro h + exact (h.sub herr).congr_left (fun u => by ring) + · intro h + exact (h.add herr).congr_left (fun u => by ring) + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMinorArc.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMinorArc.lean new file mode 100644 index 0000000000000000000000000000000000000000..674ad12a1edf0dcbe5e2d053370fcb05130c36b9 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMinorArc.lean @@ -0,0 +1,188 @@ +import OAI.NumberTheory.EgyptianFractions.BilinearFourier +import OAI.NumberTheory.EgyptianFractions.ThreePrimeMinorEnergy + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.ThreePrimeMinorArc + +/-- The prime logarithmic polynomial has global size at most Chebyshev's +theta function, for arbitrary phases of norm at most one. -/ +theorem prime_sum_norm_le_theta (u : ℕ) (phase : ℕ → ℂ) + (hphase : ∀ p ∈ Nat.primesLE u, ‖phase p‖ ≤ 1) : + ‖∑ p ∈ Nat.primesLE u, (Real.log (p : ℝ) : ℂ) * phase p‖ ≤ + Chebyshev.theta (u : ℝ) := by + rw [Chebyshev.theta_eq_sum_primesLE_log] + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro p hp + have hlog : 0 ≤ Real.log (p : ℝ) := + Real.log_nonneg (by exact_mod_cast (Nat.mem_primesLE.mp hp).2.one_le) + rw [norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg hlog] + simpa using mul_le_mul_of_nonneg_left (hphase p hp) hlog + +/-- An unconditional linear global amplitude bound, with an explicit constant. -/ +theorem prime_sum_norm_le (u : ℕ) (phase : ℕ → ℂ) + (hphase : ∀ p ∈ Nat.primesLE u, ‖phase p‖ ≤ 1) : + ‖∑ p ∈ Nat.primesLE u, (Real.log (p : ℝ) : ℂ) * phase p‖ ≤ + Real.log 4 * (u : ℝ) := + (prime_sum_norm_le_theta u phase hphase).trans + (Chebyshev.theta_le_log4_mul_x (Nat.cast_nonneg u)) + +/-- The cubic contribution of any set of frequencies is controlled by a +uniform bound on that set and the full Fourier energy. The twist may be any +function of norm at most one. This is the elementary minor-arc reduction, +not an assertion of a prime exponential-sum estimate. -/ +theorem cubic_contribution_le_energy {q : ℕ} [NeZero q] + (w : ZMod q → ℂ) (minor : Finset (ZMod q)) + (twist : ZMod q → ℂ) (A : ℝ) (hA : 0 ≤ A) + (hbound : ∀ r ∈ minor, ‖residueFourier w r‖ ≤ A) + (htwist : ∀ r ∈ minor, ‖twist r‖ ≤ 1) : + ‖(∑ r ∈ minor, residueFourier w r ^ 3 * twist r) / (q : ℂ)‖ ≤ + A * ∑ n : ZMod q, ‖w n‖ ^ 2 := by + have htransform (r : ZMod q) : + residueFourier w r = ZMod.dft (fun n => w (-n)) r := by + rw [ZMod.dft_comp_neg] + simp only [residueFourier, ZMod.dft_apply, smul_eq_mul, mul_neg, neg_neg] + apply Finset.sum_congr rfl + intro n hn + rw [mul_comm n r, mul_comm] + have h := ThreePrimeMinorEnergy.minor_cubic_bound + (fun n => w (-n)) twist minor A hA (by + intro r hr + rw [← htransform] + exact hbound r hr) htwist + simp_rw [← htransform] at h + have henergy : (∑ n : ZMod q, ‖w (-n)‖ ^ 2) = + ∑ n : ZMod q, ‖w n‖ ^ 2 := + Equiv.sum_comp (Equiv.neg _) (fun n => ‖w n‖ ^ 2) + rw [henergy] at h + simpa only [div_eq_mul_inv, mul_comm] using h + +/-- The usual additive-character twist for the coefficient at `u`. -/ +theorem cubic_character_contribution_le_energy {q : ℕ} [NeZero q] + (w : ZMod q → ℂ) (minor : Finset (ZMod q)) (u : ZMod q) + (A : ℝ) (hA : 0 ≤ A) + (hbound : ∀ r ∈ minor, ‖residueFourier w r‖ ≤ A) : + ‖(∑ r ∈ minor, residueFourier w r ^ 3 * ZMod.stdAddChar (-(r * u))) / + (q : ℂ)‖ ≤ A * ∑ n : ZMod q, ‖w n‖ ^ 2 := by + apply cubic_contribution_le_energy w minor _ A hA hbound + intro r hr + simp [ZMod.stdAddChar_apply] + +/-- Prime logarithmic weights, zero padded in a cyclic group. -/ +def primeLogWeight {q : ℕ} [NeZero q] (u : ℕ) (n : ZMod q) : ℂ := + if n.val ∈ Nat.primesLE u then (Real.log (n.val : ℝ) : ℂ) else 0 + +/-- Zero padding preserves the exact prime-weight energy when `u < q`. -/ +theorem primeLogWeight_energy {q : ℕ} [NeZero q] (u : ℕ) (huq : u < q) : + (∑ n : ZMod q, ‖primeLogWeight u n‖ ^ 2) = + ∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) ^ 2 := by + classical + calc + (∑ n : ZMod q, ‖primeLogWeight u n‖ ^ 2) = + ∑ n ∈ Finset.univ.filter (fun n : ZMod q => n.val ∈ Nat.primesLE u), + Real.log (n.val : ℝ) ^ 2 := by + simp [primeLogWeight, Finset.sum_filter, apply_ite, Complex.norm_real, + Real.norm_eq_abs, sq_abs] + _ = ∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) ^ 2 := by + apply Finset.sum_bij (fun n _ => n.val) + · intro n hn + exact (Finset.mem_filter.mp hn).2 + · intro n hn n' hn' heq + exact ZMod.val_injective q heq + · intro p hp + have hpq : p < q := (Nat.mem_primesLE.mp hp).1.trans_lt huq + refine ⟨(p : ZMod q), ?_, ZMod.val_natCast_of_lt hpq⟩ + simp [ZMod.val_natCast_of_lt hpq, hp] + · intro n hn + rfl + +/-- The zero-padded transform is exactly the usual prime exponential sum. -/ +theorem residueFourier_primeLogWeight {q : ℕ} [NeZero q] + (u : ℕ) (huq : u < q) (r : ZMod q) : + residueFourier (primeLogWeight u) r = + ∑ p ∈ Nat.primesLE u, + (Real.log (p : ℝ) : ℂ) * ZMod.stdAddChar (r * (p : ZMod q)) := by + classical + calc + residueFourier (primeLogWeight u) r = + ∑ n ∈ Finset.univ.filter (fun n : ZMod q => n.val ∈ Nat.primesLE u), + (Real.log (n.val : ℝ) : ℂ) * ZMod.stdAddChar (r * n) := by + simp [residueFourier, primeLogWeight, Finset.sum_filter, ite_mul] + _ = ∑ p ∈ Nat.primesLE u, + (Real.log (p : ℝ) : ℂ) * ZMod.stdAddChar (r * (p : ZMod q)) := by + apply Finset.sum_bij (fun n _ => n.val) + · intro n hn + exact (Finset.mem_filter.mp hn).2 + · intro n hn n' hn' heq + exact ZMod.val_injective q heq + · intro p hp + have hpq : p < q := (Nat.mem_primesLE.mp hp).1.trans_lt huq + refine ⟨(p : ZMod q), ?_, ZMod.val_natCast_of_lt hpq⟩ + simp [ZMod.val_natCast_of_lt hpq, hp] + · intro n hn + simp only [ZMod.natCast_zmod_val] + +/-- A Chebyshev energy bound saves one logarithm compared with the trivial +bound obtained by counting all integers up to `u`. -/ +theorem prime_log_squares_le (u : ℕ) (hu : 1 ≤ u) : + (∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) ^ 2) ≤ + Real.log 4 * (u : ℝ) * Real.log (u : ℝ) := by + have hlogu : 0 ≤ Real.log (u : ℝ) := Real.log_nonneg (by exact_mod_cast hu) + calc + (∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) ^ 2) ≤ + ∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) * Real.log (u : ℝ) := by + apply Finset.sum_le_sum + intro p hp + obtain ⟨hpu, hprime⟩ := Nat.mem_primesLE.mp hp + have hp0 : (0 : ℝ) < p := by exact_mod_cast hprime.pos + have hplog : 0 ≤ Real.log (p : ℝ) := + Real.log_nonneg (by exact_mod_cast hprime.one_le) + have hlog : Real.log (p : ℝ) ≤ Real.log (u : ℝ) := + Real.log_le_log hp0 (by exact_mod_cast hpu) + simpa [pow_two] using mul_le_mul_of_nonneg_left hlog hplog + _ = Chebyshev.theta (u : ℝ) * Real.log (u : ℝ) := by + rw [Chebyshev.theta_eq_sum_primesLE_log, Finset.sum_mul] + _ ≤ Real.log 4 * (u : ℝ) * Real.log (u : ℝ) := + mul_le_mul_of_nonneg_right (Chebyshev.theta_le_log4_mul_x (Nat.cast_nonneg u)) hlogu + +/-- A minor-frequency supremum bound for the actual prime sum yields a +quadratic error with the Chebyshev constant made explicit. -/ +theorem prime_cubic_contribution_le {q : ℕ} [NeZero q] + (u : ℕ) (hu : 2 ≤ u) (huq : u < q) (minor : Finset (ZMod q)) + (ε : ℝ) (hε : 0 ≤ ε) + (hbound : ∀ r ∈ minor, + ‖∑ p ∈ Nat.primesLE u, + (Real.log (p : ℝ) : ℂ) * ZMod.stdAddChar (r * (p : ZMod q))‖ ≤ + ε * (u : ℝ) / Real.log (u : ℝ)) : + ‖(∑ r ∈ minor, (∑ p ∈ Nat.primesLE u, + (Real.log (p : ℝ) : ℂ) * ZMod.stdAddChar (r * (p : ZMod q))) ^ 3 * + ZMod.stdAddChar (-(r * (u : ZMod q)))) / (q : ℂ)‖ ≤ + ε * Real.log 4 * (u : ℝ) ^ 2 := by + have hu1 : 1 < (u : ℝ) := by exact_mod_cast (show 1 < u by omega) + have hlog : 0 < Real.log (u : ℝ) := Real.log_pos hu1 + have hA : 0 ≤ ε * (u : ℝ) / Real.log (u : ℝ) := by positivity + have h := cubic_character_contribution_le_energy (primeLogWeight u) minor + (u : ZMod q) (ε * (u : ℝ) / Real.log (u : ℝ)) hA (by + intro r hr + rw [residueFourier_primeLogWeight u huq] + exact hbound r hr) + simp_rw [residueFourier_primeLogWeight u huq] at h + rw [primeLogWeight_energy u huq] at h + apply h.trans + calc + ε * (u : ℝ) / Real.log (u : ℝ) * + (∑ p ∈ Nat.primesLE u, Real.log (p : ℝ) ^ 2) ≤ + ε * (u : ℝ) / Real.log (u : ℝ) * + (Real.log 4 * (u : ℝ) * Real.log (u : ℝ)) := + mul_le_mul_of_nonneg_left (prime_log_squares_le u (by omega)) hA + _ = ε * Real.log 4 * (u : ℝ) ^ 2 := by + field_simp + +end Problem337.ThreePrimeMinorArc + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMinorEnergy.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMinorEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab5af41bf9102201f75eade42a154df786408c58 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeMinorEnergy.lean @@ -0,0 +1,102 @@ +import Mathlib + +namespace OAI +noncomputable section +open scoped BigOperators ComplexConjugate + +namespace Problem337.ThreePrimeMinorEnergy + +variable {q : ℕ} [NeZero q] + +/-- Transposition for the unnormalized discrete Fourier transform. -/ +theorem sum_dft_mul (f g : ZMod q → ℂ) : + (∑ k, ZMod.dft f k * g k) = ∑ x, f x * ZMod.dft g x := by + simp only [ZMod.dft_apply, smul_eq_mul, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x hx + apply Finset.sum_congr rfl + intro k hk + rw [mul_comm k x] + ring + +/-- Complex conjugation reverses the Fourier frequency. -/ +theorem dft_conj (f : ZMod q → ℂ) (k : ZMod q) : + ZMod.dft (fun x => conj (f x)) k = conj (ZMod.dft f (-k)) := by + simp only [ZMod.dft_apply, smul_eq_mul, map_sum, map_mul, + ← AddChar.map_neg_eq_conj] + apply Finset.sum_congr rfl + intro x hx + congr 2 + ring + +/-- Exact Parseval identity, retaining the factor `q` for counting measure. -/ +theorem dft_parseval (f : ZMod q → ℂ) : + (∑ k, ‖ZMod.dft f k‖ ^ 2) = (q : ℝ) * ∑ x, ‖f x‖ ^ 2 := by + have h := sum_dft_mul f (fun k => conj (ZMod.dft f k)) + have hconj (x : ZMod q) : + ZMod.dft (fun k => conj (ZMod.dft f k)) x = (q : ℂ) * conj (f x) := by + rw [dft_conj] + simp only [ZMod.dft_dft, neg_neg, smul_eq_mul, map_mul, map_natCast] + simp only [hconj] at h + have h' : (∑ k, (‖ZMod.dft f k‖ ^ 2 : ℂ)) = + (q : ℂ) * ∑ x, (‖f x‖ ^ 2 : ℂ) := by + calc + (∑ k, (‖ZMod.dft f k‖ ^ 2 : ℂ)) = + ∑ k, ZMod.dft f k * conj (ZMod.dft f k) := by + apply Finset.sum_congr rfl + intro k hk + rw [Complex.mul_conj, Complex.normSq_eq_norm_sq, Complex.ofReal_pow] + _ = ∑ x, f x * ((q : ℂ) * conj (f x)) := h + _ = (q : ℂ) * ∑ x, (‖f x‖ ^ 2 : ℂ) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x hx + rw [← mul_assoc, mul_comm (f x) (q : ℂ), mul_assoc, + Complex.mul_conj, Complex.normSq_eq_norm_sq, Complex.ofReal_pow] + exact_mod_cast h' + +/-- The cubic contribution of any frequency set is controlled by its +supremum Fourier bound and the exact input energy. The phase may be any +function of modulus at most one, so either Fourier sign convention is allowed. -/ +theorem minor_cubic_bound (f phase : ZMod q → ℂ) (minor : Finset (ZMod q)) + (B : ℝ) (hB : 0 ≤ B) + (hminor : ∀ k ∈ minor, ‖ZMod.dft f k‖ ≤ B) + (hphase : ∀ k ∈ minor, ‖phase k‖ ≤ 1) : + ‖(q : ℂ)⁻¹ * ∑ k ∈ minor, ZMod.dft f k ^ 3 * phase k‖ ≤ + B * ∑ x, ‖f x‖ ^ 2 := by + have hq : (0 : ℝ) < q := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne q) + have hsum : ‖∑ k ∈ minor, ZMod.dft f k ^ 3 * phase k‖ ≤ + B * ((q : ℝ) * ∑ x, ‖f x‖ ^ 2) := by + calc + ‖∑ k ∈ minor, ZMod.dft f k ^ 3 * phase k‖ ≤ + ∑ k ∈ minor, ‖ZMod.dft f k ^ 3 * phase k‖ := norm_sum_le _ _ + _ ≤ ∑ k ∈ minor, B * ‖ZMod.dft f k‖ ^ 2 := by + apply Finset.sum_le_sum + intro k hk + rw [norm_mul, norm_pow] + calc + ‖ZMod.dft f k‖ ^ 3 * ‖phase k‖ ≤ ‖ZMod.dft f k‖ ^ 3 := by + simpa using mul_le_mul_of_nonneg_left (hphase k hk) (by positivity : + 0 ≤ ‖ZMod.dft f k‖ ^ 3) + _ ≤ B * ‖ZMod.dft f k‖ ^ 2 := by + nlinarith [mul_le_mul_of_nonneg_right (hminor k hk) + (sq_nonneg ‖ZMod.dft f k‖)] + _ = B * ∑ k ∈ minor, ‖ZMod.dft f k‖ ^ 2 := (Finset.mul_sum ..).symm + _ ≤ B * ∑ k, ‖ZMod.dft f k‖ ^ 2 := by + apply mul_le_mul_of_nonneg_left _ hB + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (by intros; positivity) + _ = B * ((q : ℝ) * ∑ x, ‖f x‖ ^ 2) := by rw [dft_parseval] + rw [norm_mul, norm_inv, Complex.norm_natCast] + calc + (q : ℝ)⁻¹ * ‖∑ k ∈ minor, ZMod.dft f k ^ 3 * phase k‖ ≤ + (q : ℝ)⁻¹ * (B * ((q : ℝ) * ∑ x, ‖f x‖ ^ 2)) := + mul_le_mul_of_nonneg_left hsum (inv_nonneg.mpr hq.le) + _ = B * ∑ x, ‖f x‖ ^ 2 := by field_simp + +end Problem337.ThreePrimeMinorEnergy + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimePartialSummation.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimePartialSummation.lean new file mode 100644 index 0000000000000000000000000000000000000000..f9fce501af3515b63a34f8c2c77e3c0be1ab7a15 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimePartialSummation.lean @@ -0,0 +1,108 @@ +import OAI.NumberTheory.EgyptianFractions.FirstDerivativeSum + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.ThreePrimeAnalysis + +/-- Finite Abel summation controlled by initial partial sums and total variation. -/ +theorem weighted_sum_norm_le_partial_sum_bound + (a b : ℕ → ℂ) (n : ℕ) (B : ℝ) + (hprefix : ∀ k ≤ n + 1, ‖∑ j ∈ Finset.range k, a j‖ ≤ B) : + ‖∑ j ∈ Finset.range (n + 1), b j * a j‖ ≤ + B * (‖b n‖ + ∑ j ∈ Finset.range n, ‖b (j + 1) - b j‖) := by + let A : ℕ → ℂ := fun k => ∑ j ∈ Finset.range k, a j + have hdiff (j : ℕ) : A (j + 1) - A j = a j := by + simp [A, Finset.sum_range_succ] + have hid := Problem337.weighted_difference_sum A b n + simp only [hdiff, A, Finset.range_zero, Finset.sum_empty, mul_zero, sub_zero] at hid + rw [hid] + calc + _ ≤ ‖b n * ∑ j ∈ Finset.range (n + 1), a j‖ + + ‖∑ j ∈ Finset.range n, (b (j + 1) - b j) * + ∑ i ∈ Finset.range (j + 1), a i‖ := norm_sub_le _ _ + _ ≤ ‖b n‖ * B + ∑ j ∈ Finset.range n, ‖b (j + 1) - b j‖ * B := by + apply add_le_add + · rw [norm_mul] + exact mul_le_mul_of_nonneg_left (hprefix (n + 1) le_rfl) (norm_nonneg _) + · apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro j hj + rw [norm_mul] + exact mul_le_mul_of_nonneg_left (hprefix (j + 1) (by + have := Finset.mem_range.mp hj + omega)) (norm_nonneg _) + _ = _ := by rw [← Finset.sum_mul]; ring + +/-- The unit exponential is one-Lipschitz in its real angle. -/ +theorem norm_exp_I_mul_sub_le (x y : ℝ) : + ‖Complex.exp (Complex.I * (x : ℂ)) - Complex.exp (Complex.I * (y : ℂ))‖ ≤ + |x - y| := by + have hid : Complex.exp (Complex.I * (x : ℂ)) - Complex.exp (Complex.I * (y : ℂ)) = + Complex.exp (Complex.I * (y : ℂ)) * + (Complex.exp (Complex.I * ((x - y : ℝ) : ℂ)) - 1) := by + rw [mul_sub, mul_one, ← Complex.exp_add] + congr 2 + push_cast + ring + rw [hid, norm_mul, Complex.norm_exp_I_mul_ofReal, one_mul] + simpa only [Real.norm_eq_abs] using + (Real.norm_exp_I_mul_ofReal_sub_one_le (x := x - y)) + +/-- Linear-phase Abel transfer, uniform in the initial angle and frequency. -/ +theorem linear_phase_sum_norm_le + (a : ℕ → ℂ) (N : ℕ) (B α t : ℝ) (hB : 0 ≤ B) + (hprefix : ∀ k ≤ N, ‖∑ j ∈ Finset.range k, a j‖ ≤ B) : + ‖∑ j ∈ Finset.range N, + Complex.exp (Complex.I * ((α + t * j : ℝ) : ℂ)) * a j‖ ≤ + B * (1 + |t| * N) := by + cases N with + | zero => simpa using hB + | succ n => + have h := weighted_sum_norm_le_partial_sum_bound a + (fun j => Complex.exp (Complex.I * ((α + t * j : ℝ) : ℂ))) n B hprefix + have hvariation : + (∑ j ∈ Finset.range n, + ‖Complex.exp (Complex.I * ((α + t * (j + 1 : ℕ) : ℝ) : ℂ)) - + Complex.exp (Complex.I * ((α + t * j : ℝ) : ℂ))‖) ≤ (n : ℝ) * |t| := by + calc + _ ≤ ∑ _j ∈ Finset.range n, |t| := by + apply Finset.sum_le_sum + intro j hj + have heq : α + t * (j + 1 : ℕ) - (α + t * j) = t := by + push_cast + ring + simpa only [heq] using norm_exp_I_mul_sub_le + (α + t * (j + 1 : ℕ)) (α + t * j) + _ = _ := by simp + rw [Complex.norm_exp_I_mul_ofReal] at h + apply h.trans + apply mul_le_mul_of_nonneg_left _ hB + have ht := abs_nonneg t + push_cast at hvariation ⊢ + nlinarith + +/-- The major-arc partial-summation error estimate, in turns rather than radians. +It is conditional only on the stated finite prefix discrepancy. -/ +theorem twisted_sum_sub_norm_le + (a b : ℕ → ℂ) (N : ℕ) (B β : ℝ) (hB : 0 ≤ B) + (hprefix : ∀ k ≤ N, + ‖(∑ j ∈ Finset.range k, a j) - ∑ j ∈ Finset.range k, b j‖ ≤ B) : + ‖(∑ j ∈ Finset.range N, + Complex.exp (Complex.I * ((2 * Real.pi * β * j : ℝ) : ℂ)) * a j) - + ∑ j ∈ Finset.range N, + Complex.exp (Complex.I * ((2 * Real.pi * β * j : ℝ) : ℂ)) * b j‖ ≤ + B * (1 + 2 * Real.pi * |β| * N) := by + have h := linear_phase_sum_norm_le (fun j => a j - b j) N B 0 + (2 * Real.pi * β) hB (by + intro k hk + simpa only [Finset.sum_sub_distrib] using hprefix k hk) + simpa only [zero_add, mul_sub, Finset.sum_sub_distrib, abs_mul, + abs_of_pos Real.pi_pos, abs_of_pos (show (0 : ℝ) < 2 by norm_num)] using h + +end Problem337.ThreePrimeAnalysis + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeSingularSeries.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeSingularSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..a049b507ebd5f00e7d0db60e54b72d9816dc4873 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeSingularSeries.lean @@ -0,0 +1,126 @@ +import OAI.NumberTheory.EgyptianFractions.RationalSupplyReduction + +namespace OAI +noncomputable section +open scoped BigOperators +open Filter + +namespace Problem337 + +/-- The odd-prime local perturbation in the ternary Goldbach singular series. +Index `n` corresponds to the integer `n + 3`; nonprimes contribute zero. -/ +def threePrimeOddPerturbation (u n : ℕ) : ℝ := + if (n + 3).Prime then + if n + 3 ∣ u then -(1 / ((n : ℝ) + 2) ^ 2) + else 1 / ((n : ℝ) + 2) ^ 3 + else 0 + +/-- The local factor at two, with all the odd-prime factors following it. -/ +def threePrimeSingularSeries (u : ℕ) : ℝ := + (if Odd u then 2 else 0) * + ∏' n : ℕ, (1 + threePrimeOddPerturbation u n) + +lemma threePrimeOddPerturbation_norm_le (u n : ℕ) : + ‖threePrimeOddPerturbation u n‖ ≤ 1 / ((n : ℝ) + 2) ^ 2 := by + have hx : 1 ≤ (n : ℝ) + 2 := by have := Nat.cast_nonneg (α := ℝ) n; linarith + have hx0 : 0 < (n : ℝ) + 2 := by positivity + unfold threePrimeOddPerturbation + split_ifs + · simp [Real.norm_eq_abs] + · rw [Real.norm_eq_abs, abs_of_nonneg (by positivity)] + apply div_le_div_of_nonneg_left zero_le_one (by positivity) + nlinarith [sq_nonneg ((n : ℝ) + 2)] + · simp only [norm_zero] + positivity + +lemma threePrimeOddPerturbation_summable (u : ℕ) : + Summable (threePrimeOddPerturbation u) := by + have hs : Summable (fun n : ℕ => 1 / ((n : ℝ) + 2) ^ 2) := by + simpa only [Nat.cast_add, Nat.cast_ofNat] using + (summable_nat_add_iff 2).mpr (Real.summable_one_div_nat_pow.mpr (by norm_num : 1 < 2)) + exact hs.of_norm_bounded (threePrimeOddPerturbation_norm_le u) + +lemma threePrimeOddFactors_multipliable (u : ℕ) : + Multipliable (fun n : ℕ => 1 + threePrimeOddPerturbation u n) := + Real.multipliable_one_add_of_summable (threePrimeOddPerturbation_summable u) + +/-- The telescoping product over all integers is a lower bound for the product +of the negative local factors over any subset of odd primes. -/ +lemma prod_one_sub_reciprocal_square (N : ℕ) : + (∏ n ∈ Finset.range N, (1 - 1 / ((n : ℝ) + 2) ^ 2)) = + ((N : ℝ) + 2) / (2 * ((N : ℝ) + 1)) := by + induction N with + | zero => norm_num + | succ N ih => + rw [Finset.prod_range_succ, ih] + push_cast + have h1 : (N : ℝ) + 1 ≠ 0 := by positivity + have h2 : (N : ℝ) + 2 ≠ 0 := by positivity + field_simp + ring + +lemma one_sub_reciprocal_square_nonneg (n : ℕ) : + 0 ≤ 1 - 1 / ((n : ℝ) + 2) ^ 2 := by + have hsq : 1 ≤ ((n : ℝ) + 2) ^ 2 := by nlinarith [Nat.cast_nonneg (α := ℝ) n] + have hdiv : 1 / ((n : ℝ) + 2) ^ 2 ≤ 1 := + (div_le_one (by positivity)).2 hsq + linarith + +lemma threePrimeOddFactor_lower (u n : ℕ) : + 1 - 1 / ((n : ℝ) + 2) ^ 2 ≤ 1 + threePrimeOddPerturbation u n := by + unfold threePrimeOddPerturbation + split_ifs <;> have h2 : 0 ≤ 1 / ((n : ℝ) + 2) ^ 2 := by positivity + all_goals have h3 : 0 ≤ 1 / ((n : ℝ) + 2) ^ 3 := by positivity + all_goals linarith + +lemma threePrimeOddFactors_prod_lower (u N : ℕ) : + (1 / 2 : ℝ) ≤ ∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n) := by + calc + (1 / 2 : ℝ) ≤ ((N : ℝ) + 2) / (2 * ((N : ℝ) + 1)) := by + apply (le_div_iff₀ (by positivity)).2 + linarith + _ = ∏ n ∈ Finset.range N, (1 - 1 / ((n : ℝ) + 2) ^ 2) := + (prod_one_sub_reciprocal_square N).symm + _ ≤ _ := Finset.prod_le_prod₀ + (fun n _ => one_sub_reciprocal_square_nonneg n) + (fun n _ => threePrimeOddFactor_lower u n) + +lemma threePrimeOddFactors_tprod_lower (u : ℕ) : + (1 / 2 : ℝ) ≤ ∏' n : ℕ, (1 + threePrimeOddPerturbation u n) := by + exact ge_of_tendsto' (threePrimeOddFactors_multipliable u).hasProd.tendsto_prod_nat + (threePrimeOddFactors_prod_lower u) + +/-- Uniform positivity does not require a prime number theorem: the all-integer +comparison product gives the explicit lower bound one for every odd input. -/ +theorem threePrimeSingularSeries_one_le {u : ℕ} (hu : Odd u) : + 1 ≤ threePrimeSingularSeries u := by + rw [threePrimeSingularSeries, ite_eq_left hu] + have h := threePrimeOddFactors_tprod_lower u + linarith + +/-- A uniform asymptotic error estimate for ordered prime triples suffices for +the precise quantitative number-theoretic interface used by the supply proof. +The asymptotic estimate remains a hypothesis; no Vinogradov theorem is asserted. -/ +theorem quantitativeThreePrimeLowerBound_of_singular_error + (A : ℝ) (hA : 0 < A) + (herror : ∀ ε : ℝ, 0 < ε → ∀ᶠ u : ℕ in atTop, Odd u → + |((supplyPrimeTriples u).card : ℝ) - A * threePrimeSingularSeries u * + ((u : ℝ) ^ 2 / Real.log (u : ℝ) ^ 3)| ≤ + ε * ((u : ℝ) ^ 2 / Real.log (u : ℝ) ^ 3)) : + QuantitativeThreePrimeLowerBound := by + refine ⟨A / 2, by positivity, ?_⟩ + filter_upwards [herror (A / 2) (by positivity), eventually_ge_atTop 2] with u hu hu2 + intro hodd + have hs := threePrimeSingularSeries_one_le hodd + have huR : 1 < (u : ℝ) := by exact_mod_cast (show 1 < u by omega) + have hscale : 0 ≤ (u : ℝ) ^ 2 / Real.log (u : ℝ) ^ 3 := by + exact div_nonneg (sq_nonneg _) (pow_nonneg (Real.log_pos huR).le _) + have hmain := mul_le_mul_of_nonneg_right hs (mul_nonneg hA.le hscale) + have hlow := (abs_le.mp (hu hodd)).1 + nlinarith + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeSingularTail.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeSingularTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a007b04ed61e619f98cb480587837145f36ce74 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeSingularTail.lean @@ -0,0 +1,174 @@ +import OAI.NumberTheory.EgyptianFractions.ThreePrimeEulerTail +import OAI.NumberTheory.EgyptianFractions.ThreePrimeSingularSeries + +namespace OAI +noncomputable section +open scoped BigOperators +open Filter + +namespace Problem337 + +private lemma shifted_reciprocal_square_tail (P : Finset ℕ) (N : ℕ) + (hP : ∀ n ∈ P, N ≤ n) : + (∑ n ∈ P, 1 / ((n : ℝ) + 2) ^ 2) ≤ 1 / ((N : ℝ) + 1) := by + have htail := ThreePrimeEulerTail.reciprocal_square_tail + (P.image (fun n => n + 3)) (N + 2) (by omega) (by + intro p hp + obtain ⟨n, hn, rfl⟩ := Finset.mem_image.mp hp + have := hP n hn + omega) + rw [Finset.sum_image (by intro a ha b hb hab; dsimp at hab; omega)] at htail + convert htail using 1 + · apply Finset.sum_congr rfl + intro n hn + push_cast + ring + · push_cast + ring + +/-- Every finite tail of the canonical ternary singular series has relative +error at most `2 / (N + 1)`, uniformly in the integer being represented. -/ +theorem threePrimeOddFactors_tail_abs_sub_one (u N : ℕ) (P : Finset ℕ) + (hP : ∀ n ∈ P, N ≤ n) : + |(∏ n ∈ P, (1 + threePrimeOddPerturbation u n)) - 1| ≤ + 2 / ((N : ℝ) + 1) := by + have hsum : (∑ n ∈ P, ‖threePrimeOddPerturbation u n‖) ≤ + 1 / ((N : ℝ) + 1) := + (Finset.sum_le_sum (fun n _ => threePrimeOddPerturbation_norm_le u n)).trans + (shifted_reciprocal_square_tail P N hP) + have hsmall : |1 / ((N : ℝ) + 1)| ≤ 1 := by + rw [abs_of_nonneg (by positivity)] + exact (div_le_one (by positivity)).mpr (by linarith [Nat.cast_nonneg (α := ℝ) N]) + have hprod := P.norm_prod_one_add_sub_one_le (threePrimeOddPerturbation u) + rw [Real.norm_eq_abs] at hprod + calc + _ ≤ Real.exp (∑ n ∈ P, ‖threePrimeOddPerturbation u n‖) - 1 := hprod + _ ≤ Real.exp (1 / ((N : ℝ) + 1)) - 1 := + sub_le_sub_right (Real.exp_le_exp.mpr hsum) 1 + _ ≤ |Real.exp (1 / ((N : ℝ) + 1)) - 1| := le_abs_self _ + _ ≤ 2 * |1 / ((N : ℝ) + 1)| := Real.abs_exp_sub_one_le hsmall + _ = 2 / ((N : ℝ) + 1) := by rw [abs_of_nonneg (by positivity)]; ring + +/-- Uniform boundedness of the finite odd-prime factors. -/ +theorem threePrimeOddFactors_partial_abs_le (u N : ℕ) : + |∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n)| ≤ 3 := by + have htail := threePrimeOddFactors_tail_abs_sub_one u 0 (Finset.range N) + (by intros; omega) + norm_num only [Nat.cast_zero, zero_add, div_one] at htail + calc + _ = |((∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n)) - 1) + 1| := by ring_nf + _ ≤ |(∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n)) - 1| + |(1 : ℝ)| := + abs_add_le _ _ + _ ≤ 3 := by norm_num at htail ⊢; linarith + +/-- The canonical infinite odd-prime product is uniformly approximated by its +first `N` factors at the explicit rate `6 / (N + 1)`. -/ +theorem threePrimeOddFactors_tprod_sub_partial (u N : ℕ) : + |(∏' n : ℕ, (1 + threePrimeOddPerturbation u n)) - + ∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n)| ≤ + 6 / ((N : ℝ) + 1) := by + apply le_of_tendsto (((threePrimeOddFactors_multipliable u).hasProd.tendsto_prod_nat.sub_const + (∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n))).abs) + filter_upwards [eventually_ge_atTop N] with M hNM + rw [← Finset.prod_range_mul_prod_Ico (fun n => 1 + threePrimeOddPerturbation u n) hNM] + have heq : (∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n)) * + (∏ n ∈ Finset.Ico N M, (1 + threePrimeOddPerturbation u n)) - + (∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n)) = + (∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n)) * + ((∏ n ∈ Finset.Ico N M, (1 + threePrimeOddPerturbation u n)) - 1) := by ring + rw [heq, abs_mul] + calc + _ ≤ 3 * (2 / ((N : ℝ) + 1)) := by + apply mul_le_mul (threePrimeOddFactors_partial_abs_le u N) + (threePrimeOddFactors_tail_abs_sub_one u N (Finset.Ico N M) + (by intro n hn; exact (Finset.mem_Ico.mp hn).1)) (abs_nonneg _) (by norm_num) + _ = 6 / ((N : ℝ) + 1) := by ring + +/-- The finite canonical singular product, including the factor at two. -/ +def threePrimeSingularPartial (u N : ℕ) : ℝ := + (if Odd u then 2 else 0) * + ∏ n ∈ Finset.range N, (1 + threePrimeOddPerturbation u n) + +/-- Uniform quantitative truncation of the actual defined singular series. -/ +theorem threePrimeSingularSeries_sub_partial (u N : ℕ) : + |threePrimeSingularSeries u - threePrimeSingularPartial u N| ≤ + 12 / ((N : ℝ) + 1) := by + unfold threePrimeSingularSeries threePrimeSingularPartial + rw [← mul_sub, abs_mul] + have hfactor : |(if Odd u then 2 else 0 : ℝ)| ≤ 2 := by split_ifs <;> norm_num + calc + _ ≤ 2 * (6 / ((N : ℝ) + 1)) := + mul_le_mul hfactor (threePrimeOddFactors_tprod_sub_partial u N) (abs_nonneg _) (by norm_num) + _ = 12 / ((N : ℝ) + 1) := by ring + +/-- Uniform convergence in the represented integer: the onset is independent +of `u`, including even inputs where the singular series vanishes. -/ +theorem threePrimeSingularPartial_tendstoUniformly : + TendstoUniformly (fun N u => threePrimeSingularPartial u N) + threePrimeSingularSeries atTop := by + apply Metric.tendstoUniformly_iff.mpr + intro ε hε + obtain ⟨N₀, hN₀⟩ := exists_nat_gt (12 / ε) + filter_upwards [eventually_ge_atTop N₀] with N hN + intro u + rw [Real.dist_eq] + apply (threePrimeSingularSeries_sub_partial u N).trans_lt + apply (div_lt_iff₀ (by positivity : (0 : ℝ) < N + 1)).mpr + have hNreal : (N₀ : ℝ) ≤ N := by exact_mod_cast hN + have hbound := (div_lt_iff₀ hε).mp hN₀ + nlinarith + +/-- A simultaneous absolute bound for all singular series, useful when +converting an additive asymptotic error into a relative error. -/ +theorem threePrimeSingularSeries_abs_le_six (u : ℕ) : + |threePrimeSingularSeries u| ≤ 6 := by + have hodd : |∏' n : ℕ, (1 + threePrimeOddPerturbation u n)| ≤ 3 := + le_of_tendsto' (threePrimeOddFactors_multipliable u).hasProd.tendsto_prod_nat.abs + (threePrimeOddFactors_partial_abs_le u) + unfold threePrimeSingularSeries + rw [abs_mul] + have hfactor : |(if Odd u then 2 else 0 : ℝ)| ≤ 2 := by split_ifs <;> norm_num + nlinarith [abs_nonneg (∏' n : ℕ, (1 + threePrimeOddPerturbation u n))] + +/-- A cutoff tending to infinity may depend on the represented integer or on +any other parameter; uniform truncation still makes the error tend to zero. -/ +theorem threePrimeSingularPartial_sub_tendsto_zero {α : Type*} {l : Filter α} + (u Q : α → ℕ) (hQ : Tendsto Q l atTop) : + Tendsto (fun x => threePrimeSingularSeries (u x) - + threePrimeSingularPartial (u x) (Q x)) l (nhds 0) := by + apply squeeze_zero_norm (fun x => by + simpa only [Real.norm_eq_abs] using threePrimeSingularSeries_sub_partial (u x) (Q x)) + apply tendsto_const_nhds.div_atTop + apply tendsto_atTop_mono (fun x => ?_) (tendsto_natCast_atTop_atTop.comp hQ) + exact le_add_of_nonneg_right zero_le_one + +/-- Truncating the singular series changes any weighted main term by little-o +of that same weight. No positivity or nonvanishing of the weight is needed. -/ +theorem threePrimeSingularPartial_weighted_isLittleO {α : Type*} {l : Filter α} + (u Q : α → ℕ) (hQ : Tendsto Q l atTop) (w : α → ℝ) : + (fun x => (threePrimeSingularSeries (u x) - + threePrimeSingularPartial (u x) (Q x)) * w x) =o[l] w := by + have hsmall : (fun x => threePrimeSingularSeries (u x) - + threePrimeSingularPartial (u x) (Q x)) =o[l] (fun _ => (1 : ℝ)) := + (Asymptotics.isLittleO_one_iff ℝ).mpr (threePrimeSingularPartial_sub_tendsto_zero u Q hQ) + simpa only [one_mul] using hsmall.mul_isBigO (Asymptotics.isBigO_refl w l) + +/-- An asymptotic formula with a growing finite singular product is equivalent +to the formula with the canonical infinite series. This supplies the uniform +Euler-tail transfer in a major-arc computation without asserting that formula. -/ +theorem threePrimeSingularPartial_asymptotic_iff {α : Type*} {l : Filter α} + (u Q : α → ℕ) (hQ : Tendsto Q l atTop) (a w : α → ℝ) : + ((fun x => a x - threePrimeSingularSeries (u x) * w x) =o[l] w) ↔ + ((fun x => a x - threePrimeSingularPartial (u x) (Q x) * w x) =o[l] w) := by + have htail := threePrimeSingularPartial_weighted_isLittleO u Q hQ w + constructor + · intro h + exact (h.add htail).congr_left (fun x => by ring) + · intro h + exact (h.sub htail).congr_left (fun x => by ring) + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeWeighted.lean b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeWeighted.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ab7e9584eb51e59ab903adae48c5c9cc1d9ef30 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/ThreePrimeWeighted.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.EgyptianFractions.RationalSupplyReduction + +namespace OAI +noncomputable section +open scoped BigOperators +open Filter + +namespace Problem337 + +/-- The logarithmically weighted ordered prime triple count, with exactly the +same triples as the rational-divisor supply reduction. -/ +def weightedSupplyPrimeTriples (u : ℕ) : ℝ := + ∑ t ∈ supplyPrimeTriples u, + Real.log (t.1 : ℝ) * Real.log (t.2.1 : ℝ) * Real.log (t.2.2 : ℝ) + +lemma weightedSupplyPrimeTriples_le (u : ℕ) : + weightedSupplyPrimeTriples u ≤ + (supplyPrimeTriples u).card * Real.log (u : ℝ) ^ 3 := by + unfold weightedSupplyPrimeTriples + calc + _ ≤ ∑ _t ∈ supplyPrimeTriples u, Real.log (u : ℝ) ^ 3 := by + apply Finset.sum_le_sum + intro t ht + obtain ⟨htmem, htprime⟩ := Finset.mem_filter.mp ht + obtain ⟨hp, hq, hr⟩ := Finset.mem_product.mp htmem |>.imp_right Finset.mem_product.mp + have hlog (p : ℕ) (hp : p ∈ Finset.Icc 1 u) : + 0 ≤ Real.log (p : ℝ) ∧ Real.log (p : ℝ) ≤ Real.log (u : ℝ) := by + obtain ⟨hp1, hpu⟩ := Finset.mem_Icc.mp hp + have hp1r : (1 : ℝ) ≤ p := by exact_mod_cast hp1 + exact ⟨Real.log_nonneg hp1r, + Real.log_le_log (lt_of_lt_of_le zero_lt_one hp1r) (by exact_mod_cast hpu)⟩ + obtain ⟨hp0, hpu⟩ := hlog t.1 hp + obtain ⟨hq0, hqu⟩ := hlog t.2.1 hq + obtain ⟨hr0, hru⟩ := hlog t.2.2 hr + have hu0 : 0 ≤ Real.log (u : ℝ) := hp0.trans hpu + calc + _ ≤ (Real.log (u : ℝ) * Real.log (u : ℝ)) * Real.log (u : ℝ) := + mul_le_mul (mul_le_mul hpu hqu hq0 hu0) hru hr0 (by positivity) + _ = _ := by ring + _ = _ := by simp + +/-- Positive quadratic logarithmically weighted count is enough for the +precise unweighted lower-bound interface already used by the solution. -/ +theorem quantitativeThreePrimeLowerBound_of_weighted + (hweighted : ∃ c : ℝ, 0 < c ∧ ∀ᶠ u : ℕ in atTop, Odd u → + c * (u : ℝ) ^ 2 ≤ weightedSupplyPrimeTriples u) : + QuantitativeThreePrimeLowerBound := by + obtain ⟨c, hc, hw⟩ := hweighted + refine ⟨c, hc, ?_⟩ + filter_upwards [hw, eventually_ge_atTop 2] with u hu hu2 + intro hodd + have hur : (1 : ℝ) < u := by exact_mod_cast (show 1 < u by omega) + have hlog : 0 < Real.log (u : ℝ) ^ 3 := pow_pos (Real.log_pos hur) 3 + have h := (hu hodd).trans (weightedSupplyPrimeTriples_le u) + rw [← mul_div_assoc] + exact (div_le_iff₀ hlog).2 h + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/TruncatedDivisors.lean b/lean/OAI/NumberTheory/EgyptianFractions/TruncatedDivisors.lean new file mode 100644 index 0000000000000000000000000000000000000000..87278d91ce887a01eefcbadb58bbf8ea4a0c946a --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/TruncatedDivisors.lean @@ -0,0 +1,128 @@ +import Mathlib + +namespace OAI +namespace Problem337.DivisorMoment + +/-- Positive divisors truncated at an integral threshold. -/ +def truncatedDivisors (X n : ℕ) : Finset ℕ := + n.divisors.filter (fun a => a ≤ X) + +@[simp] theorem mem_truncatedDivisors {X n a : ℕ} : + a ∈ truncatedDivisors X n ↔ a ∣ n ∧ n ≠ 0 ∧ a ≤ X := by + simp [truncatedDivisors, and_assoc] + +/-- The second component of the gcd splitting is a divisor of the quotient. +No coprimality of the chosen factor and the quotient is needed. -/ +theorem div_gcd_dvd_quotient {a d n : ℕ} (ha : a ∣ n) (hd : d ∣ n) : + a / Nat.gcd a d ∣ n / d := by + apply (Nat.dvd_div_iff_mul_dvd hd).2 + have hlcm : Nat.lcm a d = d * (a / Nat.gcd a d) := by + rw [Nat.lcm_eq_mul_div, Nat.mul_comm a d, + Nat.mul_div_assoc d (Nat.gcd_dvd_left a d)] + rw [← hlcm] + exact Nat.lcm_dvd ha hd + +/-- Divisor splitting is injective, because its components multiply to the input. -/ +theorem gcd_split_injective (d : ℕ) : + Function.Injective (fun a : ℕ => (Nat.gcd a d, a / Nat.gcd a d)) := by + intro a b hab + have h := congrArg (fun z : ℕ × ℕ => z.2 * z.1) hab + simpa only [Nat.div_mul_cancel (Nat.gcd_dvd_left a d), + Nat.div_mul_cancel (Nat.gcd_dvd_left b d)] using h + +/-- Truncated divisors of a product inject into a full divisor set and one +truncated divisor set. This is the prefix inequality in the divisor moment argument. -/ +theorem truncated_card_le_mul {X n d : ℕ} (hn : 0 < n) (hd : d ∣ n) : + (truncatedDivisors X n).card ≤ + d.divisors.card * (truncatedDivisors X (n / d)).card := by + have hdpos : 0 < d := Nat.pos_of_dvd_of_pos hd hn + have hquotpos : 0 < n / d := Nat.div_pos (Nat.le_of_dvd hn hd) hdpos + rw [← Finset.card_product] + apply Finset.card_le_card_of_injOn (fun a : ℕ => (Nat.gcd a d, a / Nat.gcd a d)) + · intro a ha + obtain ⟨han, _, haX⟩ := mem_truncatedDivisors.mp ha + apply Finset.mem_product.mpr + constructor + · exact Nat.mem_divisors.mpr ⟨Nat.gcd_dvd_right a d, hdpos.ne'⟩ + · exact mem_truncatedDivisors.mpr + ⟨div_gcd_dvd_quotient han hd, hquotpos.ne', + (Nat.div_le_self a (Nat.gcd a d)).trans haX⟩ + · exact (gcd_split_injective d).injOn + +/-- Multiples of a positive integer in a translated interval satisfy the +uniform counting estimate needed for short-interval divisor moments. -/ +theorem interval_multiples_card_le (N Y d : ℕ) (hd : 0 < d) : + ((Finset.Ioc N (N + Y)).filter (fun a => d ∣ a)).card ≤ Y / d + 1 := by + have hcard : ((Finset.Ioc N (N + Y)).filter (fun a => d ∣ a)).card ≤ + (Finset.Ioc (N / d) ((N + Y) / d)).card := by + apply Finset.card_le_card_of_injOn (fun a : ℕ => a / d) + · intro a ha + obtain ⟨haI, had⟩ := Finset.mem_filter.mp ha + obtain ⟨hNa, haNY⟩ := Finset.mem_Ioc.mp haI + apply Finset.mem_Ioc.mpr + constructor + · apply (Nat.div_lt_iff_lt_mul hd).mpr + simpa only [Nat.div_mul_cancel had] using hNa + · exact Nat.div_le_div_right haNY + · intro a ha b hb hab + have had := (Finset.mem_filter.mp ha).2 + have hbd := (Finset.mem_filter.mp hb).2 + have h := congrArg (fun q => q * d) hab + simpa only [Nat.div_mul_cancel had, Nat.div_mul_cancel hbd] using h + rw [Nat.card_Ioc, Nat.add_div hd] at hcard + split_ifs at hcard + · simpa only [Nat.add_assoc, Nat.add_sub_cancel_left] using hcard + · have h : ((Finset.Ioc N (N + Y)).filter (fun a => d ∣ a)).card ≤ Y / d := by + simpa only [Nat.add_zero, Nat.add_sub_cancel_left] using hcard + exact h.trans (Nat.le_succ _) + +theorem interval_multiples_card_le_real (N Y d : ℕ) (hd : 0 < d) : + (((Finset.Ioc N (N + Y)).filter (fun a => d ∣ a)).card : ℝ) ≤ + (Y : ℝ) / d + 1 := by + calc + _ ≤ ((Y / d + 1 : ℕ) : ℝ) := by + exact_mod_cast interval_multiples_card_le N Y d hd + _ = ((Y / d : ℕ) : ℝ) + 1 := by norm_cast + _ ≤ (Y : ℝ) / d + 1 := by + have hcast : ((Y / d : ℕ) : ℝ) ≤ (Y : ℝ) / d := Nat.cast_div_le + linarith + +theorem interval_multiples_card_le_twice (N Y d : ℕ) (hd : 0 < d) + (hdY : d ≤ Y) : + (((Finset.Ioc N (N + Y)).filter (fun a => d ∣ a)).card : ℝ) ≤ + 2 * (Y : ℝ) / d := by + have hdR : (0 : ℝ) < d := by exact_mod_cast hd + have hratio : (1 : ℝ) ≤ (Y : ℝ) / d := by + apply (le_div_iff₀ hdR).mpr + simpa only [one_mul] using (show (d : ℝ) ≤ Y by exact_mod_cast hdY) + calc + _ ≤ (Y : ℝ) / d + 1 := interval_multiples_card_le_real N Y d hd + _ ≤ 2 * ((Y : ℝ) / d) := by linarith + _ = 2 * (Y : ℝ) / d := by ring + +/-- Real lengths are implemented by their natural floor, without changing the +uniform interval bound. -/ +theorem interval_multiples_real_cutoff (N d : ℕ) (Y : ℝ) (hY : 0 ≤ Y) + (hd : 0 < d) : + (((Finset.Ioc N (N + ⌊Y⌋₊)).filter (fun a => d ∣ a)).card : ℝ) ≤ + Y / d + 1 := by + calc + _ ≤ (⌊Y⌋₊ : ℝ) / d + 1 := interval_multiples_card_le_real N ⌊Y⌋₊ d hd + _ ≤ Y / d + 1 := by + gcongr + exact Nat.floor_le hY + +theorem interval_multiples_real_cutoff_twice (N d : ℕ) (Y : ℝ) (hY : 0 ≤ Y) + (hd : 0 < d) (hdY : (d : ℝ) ≤ Y) : + (((Finset.Ioc N (N + ⌊Y⌋₊)).filter (fun a => d ∣ a)).card : ℝ) ≤ + 2 * Y / d := by + calc + _ ≤ 2 * (⌊Y⌋₊ : ℝ) / d := + interval_multiples_card_le_twice N ⌊Y⌋₊ d hd (Nat.le_floor hdY) + _ ≤ 2 * Y / d := by + gcongr + exact Nat.floor_le hY + +end Problem337.DivisorMoment + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/TypeIIBlockScalar.lean b/lean/OAI/NumberTheory/EgyptianFractions/TypeIIBlockScalar.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e4284a545f5ff5a84efd3c743bef5e778b4bf6b --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/TypeIIBlockScalar.lean @@ -0,0 +1,43 @@ +import Mathlib + +namespace OAI +namespace Problem337.TypeIIBlockScalar + +/-- The scalar aggregation for one dyadic Vaughan Type-II block. All analytic +information is explicit in the three elementary size bounds. -/ +theorem block_bound (X M T Q U V H : ℝ) + (hX : 0 ≤ X) (hM : 0 ≤ M) (hT : 0 ≤ T) + (hQ : 0 < Q) (hU : 0 < U) (hV : 0 < V) (hH : 1 ≤ H) + (hMT : M * T ≤ X) (hTU : T ≤ 2 * X / U) (hMV : M ≤ X / V) : + (2 * M * H ^ 3) * ((2 * T / Q + 1) * (2 * M + 4 * Q * H)) * + (T * H ^ 2) ≤ + 32 * X * H ^ 6 * (X / Q + X / U + X / V + Q) := by + have hH0 : 0 ≤ H := by linarith + have hXQ : 0 ≤ X / Q := div_nonneg hX hQ.le + have hXU : 0 ≤ X / U := div_nonneg hX hU.le + have hXV : 0 ≤ X / V := div_nonneg hX hV.le + have hMTQ : M * T / Q ≤ X / Q := div_le_div_of_nonneg_right hMT hQ.le + have hTH : T * H ≤ (2 * X / U) * H := mul_le_mul_of_nonneg_right hTU hH0 + have hQH : X / Q ≤ H * (X / Q) := by nlinarith [mul_le_mul_of_nonneg_right hH hXQ] + have hVH : X / V ≤ H * (X / V) := by nlinarith [mul_le_mul_of_nonneg_right hH hXV] + have hinner : (2 * T / Q + 1) * (2 * M + 4 * Q * H) ≤ + 16 * H * (X / Q + X / U + X / V + Q) := by + have heq : (2 * T / Q + 1) * (2 * M + 4 * Q * H) = + 4 * (M * T / Q) + 8 * T * H + 2 * M + 4 * Q * H := by + field_simp + ring + rw [heq] + have hTH' : T * H ≤ 2 * (X / U) * H := by convert hTH using 1; ring + nlinarith [mul_nonneg hH0 hXQ, mul_nonneg hH0 hXV, mul_nonneg hH0 hQ.le] + have hfactor : 2 * (M * T) * H ^ 5 ≤ 2 * X * H ^ 5 := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hMT (by norm_num)) (by positivity) + have hinner0 : 0 ≤ (2 * T / Q + 1) * (2 * M + 4 * Q * H) := by positivity + calc + _ = (2 * (M * T) * H ^ 5) * ((2 * T / Q + 1) * (2 * M + 4 * Q * H)) := by ring + _ ≤ (2 * X * H ^ 5) * (16 * H * (X / Q + X / U + X / V + Q)) := + mul_le_mul hfactor hinner hinner0 (by positivity) + _ = _ := by ring + +end Problem337.TypeIIBlockScalar + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/UniformDivisorMoment.lean b/lean/OAI/NumberTheory/EgyptianFractions/UniformDivisorMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..7cba3b99bdc1e994ab764f47f590f932f270dc2f --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/UniformDivisorMoment.lean @@ -0,0 +1,91 @@ +import OAI.NumberTheory.EgyptianFractions.SmallPrimeMoment +import OAI.NumberTheory.EgyptianFractions.IntermediateBandBudget +import OAI.NumberTheory.EgyptianFractions.LargeClassUniform +import OAI.NumberTheory.EgyptianFractions.DivisorClassAssembly + +namespace OAI +noncomputable section + +open Filter +open scoped BigOperators + +namespace Problem337.DivisorMoment + +attribute [local instance] Classical.propDecidable + +/-- The complete uniform shifted divisor moment, with the upper cutoff +parameterized exponentially. All three prime-factor classes are estimated +unconditionally; the threshold depends only on the fixed `D` and `r`. -/ +theorem eventually_uniform_divisor_moment_exp (D r : ℝ) + (hD : 1 ≤ D) (hr : 0 ≤ r) : + ∀ᶠ S : ℝ in atTop, ∀ v Y : ℝ, ∀ N : ℕ, + S / (2 * Real.log S) ≤ v → v ≤ D * S → + Real.exp (v / 2) ≤ Y → Y ≤ Real.exp v → + (N : ℝ) ≤ Real.exp (D * S) → + (∑ h ∈ Finset.Icc 1 ⌊Y⌋₊, + (truncatedDivisorCount (Real.exp v) (N + h) : ℝ) ^ r) ≤ + Y * Real.exp (S ^ (1 / 4 : ℝ)) := by + obtain ⟨C, hC, hlarge⟩ := eventually_large_class_moment_bound_exp D r hD hr + filter_upwards [hlarge, small_class_truncated_moment_bound D r hD hr, + eventually_intermediate_band_budget D r hD hr, + DivisorClasses.eventually_class_budget_assembly D r C hD hr hC.le] + with S hlarge hsmall hband hassemble + intro v Y N hvlo hvhi hYlo hYhi hN + have hYpos : 0 < Y := (Real.exp_pos (v / 2)).trans_le hYlo + have hsqrt : Real.sqrt (Real.exp v) = Real.exp (v / 2) := by + rw [Real.sqrt_eq_rpow, ← Real.exp_mul] + congr 1 + ring + apply hassemble v Y hvlo hvhi hYlo hYhi (Finset.Icc 1 ⌊Y⌋₊) + (fun h => N + h) (fun h => (truncatedDivisorCount (Real.exp v) (N + h) : ℝ) ^ r) + · intro h hh + positivity + · exact hlarge v Y N hvlo hvhi hYlo hYhi hN + · simpa only [Real.log_exp] using hsmall (Real.exp v) Y N + (by simpa only [Real.log_exp] using hvlo) + (by simpa only [Real.log_exp] using hvhi) + (by simpa only [hsqrt] using hYlo) hYhi hN + · intro j + by_cases hj : 4 * Real.log S * 2 ^ j ≤ v ^ (15 / 16 : ℝ) + · exact hband v Y N j hvlo hvhi hYlo hYhi hN hj + · have hempty : (Finset.Icc 1 ⌊Y⌋₊).filter + (fun h => DivisorClasses.BandClass (N + h) S v Y j) = ∅ := by + apply Finset.filter_eq_empty_iff.mpr + intro h hh hb + exact hj (DivisorClasses.band_scale_lt hb).le + simp only [hempty, Finset.sum_empty] + positivity + +/-- Uniform divisor moments with real cutoffs. The statement also covers a real +interval length through its floor. -/ +theorem eventually_uniform_divisor_moment (D r : ℝ) + (hD : 1 ≤ D) (hr : 0 ≤ r) : + ∀ᶠ S : ℝ in atTop, ∀ X Y : ℝ, ∀ N : ℕ, + S / (2 * Real.log S) ≤ Real.log X → Real.log X ≤ D * S → + Real.sqrt X ≤ Y → Y ≤ X → (N : ℝ) ≤ Real.exp (D * S) → + (∑ h ∈ Finset.Icc 1 ⌊Y⌋₊, + (truncatedDivisorCount X (N + h) : ℝ) ^ r) ≤ + Y * Real.exp (S ^ (1 / 4 : ℝ)) := by + filter_upwards [eventually_uniform_divisor_moment_exp D r hD hr, + eventually_ge_atTop (2 : ℝ)] with S hmoment hS + intro X Y N hvlo hvhi hYlo hYhi hN + have hSpos : 0 < S := by linarith + have hlogS : 0 < Real.log S := Real.log_pos (by linarith) + have hlogX : 0 < Real.log X := + (by positivity : 0 < S / (2 * Real.log S)).trans_le hvlo + have hXnonneg : 0 ≤ X := (Real.sqrt_nonneg X).trans (hYlo.trans hYhi) + have hX : 1 < X := (Real.log_pos_iff hXnonneg).mp hlogX + have hXpos : 0 < X := by linarith + have hsqrt : Real.exp (Real.log X / 2) = Real.sqrt X := by + rw [Real.sqrt_eq_rpow, Real.rpow_def_of_pos hXpos] + congr 1 + ring + simpa only [Real.exp_log hXpos] using hmoment (Real.log X) Y N hvlo hvhi + (by simpa only [hsqrt] using hYlo) + (by simpa only [Real.exp_log hXpos] using hYhi) hN + +end Problem337.DivisorMoment + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/UniformSecondMoment.lean b/lean/OAI/NumberTheory/EgyptianFractions/UniformSecondMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..8ba6882a85c823b58d00a218a0e601e4b2d23be4 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/UniformSecondMoment.lean @@ -0,0 +1,90 @@ +import OAI.NumberTheory.EgyptianFractions.SecondMomentAssembly +import OAI.NumberTheory.EgyptianFractions.FiniteExposureAverage + +namespace OAI +noncomputable section +open scoped BigOperators +namespace Problem337 + +theorem norm_expect_sq_eq_expect_pairs {I : Type*} [Fintype I] (z : I → ℂ) : + ‖𝔼 i, z i‖ ^ 2 = 𝔼 ij : I × I, (z ij.1 * star (z ij.2)).re := by + simp only [Fintype.expect_eq_sum_div_card, norm_div, norm_natCast] + rw [div_pow, norm_sum_sq_eq_sum_pair] + simp only [Fintype.card_prod, Nat.cast_mul, pow_two] + +theorem uniform_second_moment_identity {Ω I : Type*} [Fintype Ω] [Fintype I] + (z : Ω → I → ℂ) : + (𝔼 ω, ‖𝔼 i, z ω i‖ ^ 2) = + 𝔼 ij : I × I, (𝔼 ω, z ω ij.1 * star (z ω ij.2)).re := by + simp_rw [norm_expect_sq_eq_expect_pairs] + rw [Finset.expect_comm] + congr 1 + funext ij + exact (map_expect (Complex.reCLM.toLinearMap.restrictScalars ℚ≥0) (fun ω => z ω ij.1 * star (z ω ij.2)) Finset.univ).symm + +/-- Uniform finite-average version of the Hamming second-moment reduction. -/ +theorem uniform_boolean_second_moment_bound {Ω : Type*} [Fintype Ω] [Nonempty Ω] + (m : ℕ) (z : Ω → (Fin m → Bool) → ℂ) + (hz : ∀ ω i, ‖z ω i‖ ≤ 1) (δ : ℝ) (hδ : 0 ≤ δ) + (hgood : ∀ i j, (m : ℝ) / 4 ≤ (hammingDist i j : ℝ) → + ‖𝔼 ω, z ω i * star (z ω j)‖ ≤ δ) : + (𝔼 ω, ‖𝔼 i, z ω i‖ ^ 2) ≤ Real.exp (-(m : ℝ) / 16) + δ := by + classical + let E := Finset.univ.filter (fun ij : (Fin m → Bool) × (Fin m → Bool) => + (hammingDist ij.1 ij.2 : ℝ) < (m : ℝ) / 4) + have hall (i j : Fin m → Bool) : ‖𝔼 ω, z ω i * star (z ω j)‖ ≤ 1 := by + calc + _ ≤ 𝔼 ω, ‖z ω i * star (z ω j)‖ := RCLike.norm_expect_le (K := ℂ) + _ ≤ 𝔼 _ω : Ω, (1 : ℝ) := by + apply Finset.expect_le_expect + intro ω hω + rw [norm_mul, norm_star] + nlinarith [hz ω i, hz ω j, norm_nonneg (z ω i), norm_nonneg (z ω j)] + _ = 1 := Fintype.expect_const 1 + have hexc : (E.card : ℝ) ≤ (4 : ℝ) ^ m * Real.exp (-(m : ℝ) / 16) := + hamming_exception_count m + have hcard : (Fintype.card ((Fin m → Bool) × (Fin m → Bool)) : ℝ) = (4 : ℝ) ^ m := by + simp only [Fintype.card_prod, Fintype.card_fun, Fintype.card_bool, + Fintype.card_fin, Nat.cast_mul, Nat.cast_pow, Nat.cast_ofNat] + rw [← mul_pow] + norm_num + rw [uniform_second_moment_identity] + calc + (𝔼 ij : (Fin m → Bool) × (Fin m → Bool), + (𝔼 ω, z ω ij.1 * star (z ω ij.2)).re) ≤ + 𝔼 ij : (Fin m → Bool) × (Fin m → Bool), + ((if ij ∈ E then 1 else 0) + δ : ℝ) := by + apply Finset.expect_le_expect + intro ij hij + by_cases hb : ij ∈ E + · simp only [ite_eq_left hb] + exact (Complex.re_le_norm _).trans ((hall _ _).trans (by linarith)) + · simp only [ite_eq_right hb, zero_add] + apply (Complex.re_le_norm _).trans (hgood _ _ ?_) + simpa only [E, Finset.mem_filter, Finset.mem_univ, true_and, not_lt] using hb + _ = (E.card : ℝ) / (4 : ℝ) ^ m + δ := by + rw [Finset.expect_add_distrib, expect_finset_indicator, Fintype.expect_const, hcard] + _ ≤ Real.exp (-(m : ℝ) / 16) + δ := by + have hdiv : (E.card : ℝ) / (4 : ℝ) ^ m ≤ Real.exp (-(m : ℝ) / 16) := + (div_le_iff₀ (by positivity)).2 (by simpa only [mul_comm] using hexc) + linarith + +/-- Uniform-mean final random estimate, directly matching the second moment +of the sampled Boolean-product exponential average. -/ +theorem uniform_boolean_random_second_moment_bound {Ω : Type*} + [Fintype Ω] [Nonempty Ω] (m : ℕ) (V : ℝ) + (z : Ω → (Fin m → Bool) → ℂ) (hz : ∀ ω i, ‖z ω i‖ ≤ 1) + (hlarge : 50 ≤ min (m : ℝ) V) + (hgood : ∀ i j, (m : ℝ) / 4 ≤ (hammingDist i j : ℝ) → + ‖𝔼 ω, z ω i * star (z ω j)‖ ≤ Real.exp (-V / 20) + Real.exp (-V / 5)) : + (𝔼 ω, ‖𝔼 i, z ω i‖ ^ 2) ≤ Real.exp (-min (m : ℝ) V / 100) := by + have h := uniform_boolean_second_moment_bound m z hz + (Real.exp (-V / 20) + Real.exp (-V / 5)) (by positivity) hgood + exact h.trans (by simpa only [add_assoc] using + random_second_moment_absorption (m : ℝ) V hlarge) + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/UpperSlope.lean b/lean/OAI/NumberTheory/EgyptianFractions/UpperSlope.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9871b567fd323ccd815905473c6aefc12a94e25 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/UpperSlope.lean @@ -0,0 +1,94 @@ +import Mathlib + +namespace OAI +open Filter +open scoped Topology + +namespace Problem337 + +/-- A double logarithm estimate for the elementary denominator bound. -/ +theorem loglog_le_of_power_bound {k : ℕ} {x : ℝ} (hk : 2 ≤ k) + (hx : 2 ≤ x) (hbound : x ≤ 1 + (k : ℝ) ^ (2 ^ (k - 1))) : + Real.log (Real.log x) ≤ (k : ℝ) * Real.log 2 + Real.log (Real.log k) := by + have hkR : 2 ≤ (k : ℝ) := by exact_mod_cast hk + have hkpos : 0 < (k : ℝ) := by linarith + have hkone : 1 ≤ (k : ℝ) := by linarith + have hlogk : 0 < Real.log (k : ℝ) := Real.log_pos (by linarith) + have hp : 1 ≤ (2 : ℕ) ^ (k - 1) := Nat.one_le_pow _ _ (by decide) + have hpow : 2 ≤ (k : ℝ) ^ (2 ^ (k - 1)) := by + calc + 2 ≤ (k : ℝ) := hkR + _ = (k : ℝ) ^ 1 := by simp + _ ≤ (k : ℝ) ^ (2 ^ (k - 1)) := pow_le_pow_right₀ hkone hp + have hexp : (2 : ℕ) ^ (k - 1) * 2 = 2 ^ k := by + rw [← pow_succ, Nat.sub_add_cancel (by omega : 1 ≤ k)] + have hbound' : x ≤ (k : ℝ) ^ (2 ^ k) := by + calc + x ≤ 1 + (k : ℝ) ^ (2 ^ (k - 1)) := hbound + _ ≤ ((k : ℝ) ^ (2 ^ (k - 1))) ^ 2 := by nlinarith + _ = (k : ℝ) ^ (2 ^ k) := by rw [← pow_mul, hexp] + have hlog : Real.log x ≤ (2 : ℝ) ^ k * Real.log (k : ℝ) := by + simpa only [Real.log_pow, Nat.cast_pow, Nat.cast_ofNat] using + Real.log_le_log (by linarith : 0 < x) hbound' + have hlogx : 0 < Real.log x := Real.log_pos (by linarith) + calc + Real.log (Real.log x) ≤ Real.log ((2 : ℝ) ^ k * Real.log (k : ℝ)) := + Real.log_le_log hlogx hlog + _ = (k : ℝ) * Real.log 2 + Real.log (Real.log k) := by + rw [Real.log_mul (by positivity) (ne_of_gt hlogk), Real.log_pow] + +/-- The logarithmic error in the denominator upper bound is negligible. -/ +theorem tendsto_log_nat_div_nat : + Tendsto (fun k : ℕ => Real.log (k : ℝ) / (k : ℝ)) atTop (𝓝 0) := by + have h := Real.tendsto_pow_log_div_mul_add_atTop 1 0 1 one_ne_zero + simpa [Function.comp_def] using h.comp tendsto_natCast_atTop_atTop + +/-- The elementary power upper bound forces the sharp upper logarithmic slope. -/ +theorem power_bound_slope_limits (u : ℕ → ℝ) + (hu : ∀ᶠ k in atTop, 2 ≤ u k ∧ + u k ≤ 1 + (k : ℝ) ^ (2 ^ (k - 1))) : + 0 ≤ liminf (fun k => Real.log (Real.log (u k)) / (k : ℝ)) atTop ∧ + liminf (fun k => Real.log (Real.log (u k)) / (k : ℝ)) atTop ≤ + limsup (fun k => Real.log (Real.log (u k)) / (k : ℝ)) atTop ∧ + limsup (fun k => Real.log (Real.log (u k)) / (k : ℝ)) atTop ≤ Real.log 2 := by + let f : ℕ → ℝ := fun k => Real.log (Real.log (u k)) / (k : ℝ) + have hupp : f ≤ᶠ[atTop] (fun k : ℕ => Real.log 2 + Real.log (k : ℝ) / (k : ℝ)) := by + filter_upwards [hu, eventually_ge_atTop 2] with k hk hk2 + have hkR : 2 ≤ (k : ℝ) := by exact_mod_cast hk2 + have hkpos : 0 < (k : ℝ) := by linarith + have hlog : Real.log (Real.log (k : ℝ)) ≤ Real.log (k : ℝ) := by + apply Real.log_le_log (Real.log_pos (by linarith)) + linarith [Real.log_le_sub_one_of_pos hkpos] + have hmain := loglog_le_of_power_bound hk2 hk.1 hk.2 + calc + f k ≤ ((k : ℝ) * Real.log 2 + Real.log (k : ℝ)) / (k : ℝ) := by + apply div_le_div_of_nonneg_right _ hkpos.le + exact hmain.trans (add_le_add (le_refl _) hlog) + _ = Real.log 2 + Real.log (k : ℝ) / (k : ℝ) := by + field_simp + have hlo : (fun k : ℕ => Real.log (Real.log 2) / (k : ℝ)) ≤ᶠ[atTop] f := by + filter_upwards [hu, eventually_ge_atTop 2] with k hk hk2 + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg k) + exact Real.log_le_log (Real.log_pos (by norm_num)) + (Real.log_le_log (by norm_num) hk.1) + have htU : Tendsto (fun k : ℕ => Real.log 2 + Real.log (k : ℝ) / (k : ℝ)) + atTop (𝓝 (Real.log 2)) := by + simpa using tendsto_const_nhds.add tendsto_log_nat_div_nat + have htL : Tendsto (fun k : ℕ => Real.log (Real.log 2) / (k : ℝ)) + atTop (𝓝 0) := tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + have hfbU : atTop.IsBoundedUnder (· ≤ ·) f := htU.isBoundedUnder_le.mono_le hupp + have hfbL : atTop.IsBoundedUnder (· ≥ ·) f := htL.isBoundedUnder_ge.mono_ge hlo + change 0 ≤ liminf f atTop ∧ liminf f atTop ≤ limsup f atTop ∧ + limsup f atTop ≤ Real.log 2 + refine ⟨?_, liminf_le_limsup hfbU hfbL, ?_⟩ + · calc + 0 = liminf (fun k : ℕ => Real.log (Real.log 2) / (k : ℝ)) atTop := htL.liminf_eq.symm + _ ≤ liminf f atTop := liminf_le_liminf hlo htL.isBoundedUnder_ge hfbU.isCobounded_flip + · calc + limsup f atTop ≤ limsup (fun k : ℕ => Real.log 2 + Real.log (k : ℝ) / (k : ℝ)) atTop := + limsup_le_limsup hupp hfbL.isCobounded_flip htU.isBoundedUnder_le + _ = Real.log 2 := htU.limsup_eq + +end Problem337 + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VanDerCorput.lean b/lean/OAI/NumberTheory/EgyptianFractions/VanDerCorput.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffe4d05ec7a422b9968adc8909801b8a1a75d0f2 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VanDerCorput.lean @@ -0,0 +1,239 @@ +import OAI.NumberTheory.EgyptianFractions.FourierSecondMoment + +namespace OAI +open scoped BigOperators +open ComplexConjugate + +namespace Problem337 + +/-- Cauchy--Schwarz for the norm of a finite complex sum. -/ +theorem norm_sum_sq_le_card_mul_sum_norm_sq {α : Type*} + (U : Finset α) (f : α → ℂ) : + ‖∑ u ∈ U, f u‖ ^ 2 ≤ (U.card : ℝ) * ∑ u ∈ U, ‖f u‖ ^ 2 := by + have hn := norm_sum_le U f + have hs := Finset.sum_mul_sq_le_sq_mul_sq U (fun _ => (1 : ℝ)) (fun u => ‖f u‖) + simp only [one_mul, one_pow, Finset.sum_const, nsmul_eq_mul, mul_one] at hs + exact (pow_le_pow_left₀ (norm_nonneg _) hn 2).trans hs + +/-- Averaging equal column sums and bounding their pairwise correlations. +This is the finite algebraic core of van der Corput differencing. -/ +theorem averaged_columns_correlation_bound {α β : Type*} + (U : Finset α) (T : Finset β) (z : α → β → ℂ) + (S : ℂ) (D E : ℝ) + (hcol : ∀ t ∈ T, ∑ u ∈ U, z u t = S) + (hdiag : ∀ t ∈ T, ∑ u ∈ U, ‖z u t‖ ^ 2 ≤ D) + (hcorr : ∀ t ∈ T, ∀ s ∈ T, t ≠ s → + ‖∑ u ∈ U, z u t * conj (z u s)‖ ≤ E) : + (T.card : ℝ) ^ 2 * ‖S‖ ^ 2 ≤ + (U.card : ℝ) * ((T.card : ℝ) * D + + (T.card : ℝ) * (T.card - 1 : ℝ) * E) := by + classical + have havg : (∑ u ∈ U, ∑ t ∈ T, z u t) = (T.card : ℂ) * S := by + rw [Finset.sum_comm] + simp_rw [Finset.sum_congr rfl hcol] + simp + have hcs := norm_sum_sq_le_card_mul_sum_norm_sq U (fun u => ∑ t ∈ T, z u t) + rw [havg, norm_mul, Complex.norm_natCast, mul_pow] at hcs + apply hcs.trans + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + rw [finite_complex_second_moment_identity] + have hentry (t : β) (ht : t ∈ T) (s : β) (hs : s ∈ T) : + (∑ u ∈ U, z u t * conj (z u s)).re ≤ + E + if t = s then D - E else 0 := by + by_cases heq : t = s + · subst s + simp only [re_finset_sum, Complex.mul_conj, Complex.ofReal_re, + Complex.normSq_eq_norm_sq, ite_true, add_sub_cancel] + exact hdiag t ht + · simpa [heq] using (Complex.re_le_norm _).trans (hcorr t ht s hs heq) + calc + (∑ t ∈ T, ∑ s ∈ T, (∑ u ∈ U, z u t * conj (z u s)).re) ≤ + ∑ t ∈ T, ∑ s ∈ T, (E + if t = s then D - E else 0) := by + exact Finset.sum_le_sum (fun t ht => Finset.sum_le_sum (fun s hs => hentry t ht s hs)) + _ = (T.card : ℝ) * D + (T.card : ℝ) * (T.card - 1 : ℝ) * E := by + have hrow (t : β) (ht : t ∈ T) : + (∑ s ∈ T, (E + if t = s then D - E else 0)) = + (T.card : ℝ) * E + D - E := by + simp [Finset.sum_add_distrib, ht] + ring + simp_rw [Finset.sum_congr rfl hrow] + simp only [Finset.sum_const, nsmul_eq_mul] + ring + +/-- Translation does not change a finite sum once the summation interval + contains all translated points in its support. -/ +theorem sum_shift_supported {M : Type*} [AddCommMonoid M] + (a : ℤ → M) (N H : ℕ) (t : ℤ) (ht0 : 0 ≤ t) (htH : t ≤ H) + (hsupport : ∀ n : ℤ, n ∉ Finset.Icc (1 : ℤ) N → a n = 0) : + (∑ n ∈ Finset.Icc (1 - (H : ℤ)) N, a (n + t)) = + ∑ n ∈ Finset.Icc (1 : ℤ) N, a n := by + classical + apply Finset.sum_bij_ne_zero (fun n _ _ => n + t) + · intro n hn hne + by_contra hout + exact hne (hsupport (n + t) hout) + · intro n hn hn0 m hm hm0 heq + omega + · intro n hn hn0 + refine ⟨n - t, ?_, ?_, by omega⟩ + · simp only [Finset.mem_Icc] at hn ⊢ + omega + · simpa using hn0 + · intros + rfl + +/-- A concrete finite-support shift bound, before using `H ≤ N` to simplify + the two endpoint losses. Correlation assumptions are symmetric in the shift. -/ +theorem van_der_corput_interval_exact + (a : ℤ → ℂ) (N H : ℕ) (hH : 1 ≤ H) (E : ℝ) (hE : 0 ≤ E) + (hsupport : ∀ n : ℤ, n ∉ Finset.Icc (1 : ℤ) N → a n = 0) + (hnorm : ∀ n : ℤ, ‖a n‖ ≤ 1) + (hcorr : ∀ h : ℤ, -(H : ℤ) < h → h < H → h ≠ 0 → + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a (n + h) * conj (a n)‖ ≤ E) : + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a n‖ ^ 2 ≤ + ((N : ℝ) + H) * ((N : ℝ) / H + E) := by + classical + let U := Finset.Icc (1 - (H : ℤ)) (N : ℤ) + let T := Finset.range H + let z : ℤ → ℕ → ℂ := fun n t => a (n + t) + have hcardU : (U.card : ℝ) = (N : ℝ) + H := by + dsimp [U] + rw [Int.card_Icc] + have heq : (N : ℤ) + 1 - (1 - (H : ℤ)) = ((N + H : ℕ) : ℤ) := by omega + rw [heq] + norm_cast + have hcol (t : ℕ) (ht : t ∈ T) : + (∑ n ∈ U, z n t) = ∑ n ∈ Finset.Icc (1 : ℤ) N, a n := by + exact sum_shift_supported a N H t (by omega) (by have := Finset.mem_range.mp ht; omega) hsupport + have hdiag (t : ℕ) (ht : t ∈ T) : (∑ n ∈ U, ‖z n t‖ ^ 2) ≤ (N : ℝ) := by + have hs : ∀ n : ℤ, n ∉ Finset.Icc (1 : ℤ) N → ‖a n‖ ^ 2 = 0 := by + intro n hn + simp [hsupport n hn] + have heq := sum_shift_supported (fun n => ‖a n‖ ^ 2) N H t + (by omega) (by have := Finset.mem_range.mp ht; omega) hs + change (∑ n ∈ U, ‖a (n + t)‖ ^ 2) ≤ (N : ℝ) + rw [heq] + calc + (∑ n ∈ Finset.Icc (1 : ℤ) N, ‖a n‖ ^ 2) ≤ + ∑ _n ∈ Finset.Icc (1 : ℤ) N, (1 : ℝ) := by + exact Finset.sum_le_sum (fun n _ => by have := hnorm n; have := norm_nonneg (a n); nlinarith) + _ = (N : ℝ) := by simp [Int.card_Icc] + have hcorr' (t : ℕ) (ht : t ∈ T) (s : ℕ) (hs : s ∈ T) (hne : t ≠ s) : + ‖∑ n ∈ U, z n t * conj (z n s)‖ ≤ E := by + let b : ℤ → ℂ := fun n => a (n + ((t : ℤ) - s)) * conj (a n) + have hb : ∀ n : ℤ, n ∉ Finset.Icc (1 : ℤ) N → b n = 0 := by + intro n hn + simp [b, hsupport n hn] + have heq := sum_shift_supported b N H s (by omega) + (by have := Finset.mem_range.mp hs; omega) hb + have hz : (∑ n ∈ U, z n t * conj (z n s)) = ∑ n ∈ U, b (n + s) := by + apply Finset.sum_congr rfl + intro n hn + simp [z, b] + rw [hz, heq] + apply hcorr + · have := Finset.mem_range.mp ht + have := Finset.mem_range.mp hs + omega + · have := Finset.mem_range.mp ht + have := Finset.mem_range.mp hs + omega + · omega + have hraw := averaged_columns_correlation_bound U T z + (∑ n ∈ Finset.Icc (1 : ℤ) N, a n) N E hcol hdiag hcorr' + have hHR : (0 : ℝ) < H := by exact_mod_cast (show 0 < H by omega) + simp only [T, Finset.card_range, hcardU] at hraw + apply (mul_le_mul_iff_left₀ (sq_pos_of_pos hHR)).mp + have hweak : (H : ℝ)^2 * ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a n‖^2 ≤ + ((N : ℝ) + H) * ((H : ℝ) * N + (H : ℝ)^2 * E) := by + apply hraw.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + nlinarith + have heq : (((N : ℝ) + H) * ((N : ℝ) / H + E)) * (H : ℝ)^2 = + ((N : ℝ) + H) * ((H : ℝ) * N + (H : ℝ)^2 * E) := by + field_simp + rw [heq] + simpa [mul_comm] using hweak + +/-- Opposite shifts give conjugate autocorrelations, with zero extension + supplying the endpoint cancellation. -/ +theorem interval_correlation_neg (a : ℤ → ℂ) (N : ℕ) (h : ℤ) + (hsupport : ∀ n : ℤ, n ∉ Finset.Icc (1 : ℤ) N → a n = 0) : + (∑ n ∈ Finset.Icc (1 : ℤ) N, a (n + -h) * conj (a n)) = + conj (∑ n ∈ Finset.Icc (1 : ℤ) N, a (n + h) * conj (a n)) := by + classical + rw [map_sum] + apply Finset.sum_bij_ne_zero (fun n _ _ => n - h) + · intro n hn hn0 + by_contra hout + have hz := hsupport (n - h) hout + simp [sub_eq_add_neg] at hz + simp [hz] at hn0 + · intro n hn hn0 m hm hm0 heq + omega + · intro n hn hn0 + have hmem : n + h ∈ Finset.Icc (1 : ℤ) N := by + by_contra hout + have hz := hsupport (n + h) hout + simp [hz] at hn0 + refine ⟨n + h, hmem, ?_, by omega⟩ + simpa [map_mul, mul_comm] using hn0 + · intro n hn hn0 + simp [map_mul, sub_eq_add_neg, mul_comm] + +/-- The elementary van der Corput inequality for an interval-supported + sequence, in the positive-shift form required for iterated differencing. -/ +theorem van_der_corput_interval + (a : ℤ → ℂ) (N H : ℕ) (hH : 1 ≤ H) (hHN : H ≤ N) + (E : ℝ) (hE : 0 ≤ E) + (hsupport : ∀ n : ℤ, n ∉ Finset.Icc (1 : ℤ) N → a n = 0) + (hnorm : ∀ n : ℤ, ‖a n‖ ≤ 1) + (hcorr : ∀ h : ℤ, 0 < h → h < H → + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a (n + h) * conj (a n)‖ ≤ E) : + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a n‖ ^ 2 ≤ + 2 * (N : ℝ)^2 / H + 2 * (N : ℝ) * E := by + have hsym : ∀ h : ℤ, -(H : ℤ) < h → h < H → h ≠ 0 → + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a (n + h) * conj (a n)‖ ≤ E := by + intro h hl hu hn + by_cases hp : 0 < h + · exact hcorr h hp hu + · have hneg : 0 < -h := by omega + have hnegb : -h < (H : ℤ) := by omega + have heq := interval_correlation_neg a N (-h) hsupport + simp only [neg_neg] at heq + rw [heq, Complex.norm_conj] + exact hcorr (-h) hneg hnegb + have hraw := van_der_corput_interval_exact a N H hH E hE hsupport hnorm hsym + have hHR : (0 : ℝ) < H := by exact_mod_cast (show 0 < H by omega) + have hHNR : (H : ℝ) ≤ N := by exact_mod_cast hHN + calc + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a n‖ ^ 2 ≤ + ((N : ℝ) + H) * ((N : ℝ) / H + E) := hraw + _ ≤ (2 * (N : ℝ)) * ((N : ℝ) / H + E) := by + apply mul_le_mul_of_nonneg_right (by linarith) + positivity + _ = 2 * (N : ℝ)^2 / H + 2 * (N : ℝ) * E := by ring + +/-- Normalized van der Corput differencing, with an explicit absolute constant. -/ +theorem van_der_corput_interval_normalized + (a : ℤ → ℂ) (N H : ℕ) (hH : 1 ≤ H) (hHN : H ≤ N) + (E : ℝ) (hE : 0 ≤ E) + (hsupport : ∀ n : ℤ, n ∉ Finset.Icc (1 : ℤ) N → a n = 0) + (hnorm : ∀ n : ℤ, ‖a n‖ ≤ 1) + (hcorr : ∀ h : ℤ, 0 < h → h < H → + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a (n + h) * conj (a n)‖ ≤ E) : + ‖∑ n ∈ Finset.Icc (1 : ℤ) N, a n‖ ^ 2 / (N : ℝ)^2 ≤ + 2 / (H : ℝ) + 2 * E / N := by + have hNR : (0 : ℝ) < N := by exact_mod_cast (show 0 < N by omega) + have hHR : (0 : ℝ) < H := by exact_mod_cast (show 0 < H by omega) + apply (div_le_iff₀ (sq_pos_of_pos hNR)).mpr + have hraw := van_der_corput_interval a N H hH hHN E hE hsupport hnorm hcorr + have heq : (2 / (H : ℝ) + 2 * E / N) * (N : ℝ)^2 = + 2 * (N : ℝ)^2 / H + 2 * (N : ℝ) * E := by + field_simp + rw [heq] + exact hraw + +end Problem337 + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanBilinear.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanBilinear.lean new file mode 100644 index 0000000000000000000000000000000000000000..cb751ddd18caa1fd282c7d39c38044ab05262626 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanBilinear.lean @@ -0,0 +1,305 @@ +import Mathlib + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.VaughanBilinear + +/-- The exact correlation expansion of a weighted finite bilinear energy. +No distinctness or unit-modulus assumption on the phase is needed. -/ +theorem energy_identity {α β : Type*} (s : Finset α) (t : Finset β) + (b : β → ℂ) (z : α → β → ℂ) : + ((∑ m ∈ s, ‖∑ n ∈ t, b n * z m n‖ ^ 2 : ℝ) : ℂ) = + ∑ n ∈ t, ∑ k ∈ t, b n * (starRingEnd ℂ) (b k) * + ∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k) := by + classical + have hpoint (m : α) : + (‖∑ n ∈ t, b n * z m n‖ ^ 2 : ℂ) = + ∑ n ∈ t, ∑ k ∈ t, + b n * (starRingEnd ℂ) (b k) * + (z m n * (starRingEnd ℂ) (z m k)) := by + rw [← Complex.mul_conj'] + simp only [map_sum, map_mul, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro n hn + apply Finset.sum_congr rfl + intro k hk + ring + push_cast + simp_rw [hpoint] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro n hn + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k hk + rw [Finset.mul_sum] + +/-- Bounding a bilinear energy by absolute correlations retains the +arithmetic cancellation in the first variable. -/ +theorem energy_le_correlations {α β : Type*} (s : Finset α) (t : Finset β) + (b : β → ℂ) (z : α → β → ℂ) : + (∑ m ∈ s, ‖∑ n ∈ t, b n * z m n‖ ^ 2) ≤ + ∑ n ∈ t, ∑ k ∈ t, ‖b n‖ * ‖b k‖ * + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖ := by + have h := congrArg Complex.re (energy_identity s t b z) + simp only [Complex.ofReal_re, Complex.re_sum] at h + rw [h] + apply Finset.sum_le_sum + intro n hn + apply Finset.sum_le_sum + intro k hk + calc + _ ≤ ‖b n * (starRingEnd ℂ) (b k) * + ∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖ := Complex.re_le_norm _ + _ = _ := by simp only [norm_mul, Complex.norm_conj] + +/-- Finite Type-II Cauchy--Schwarz, with the full correlation sum explicit. +This is an unconditional algebraic bound, not a minor-arc hypothesis. -/ +theorem norm_bilinear_sq_le {α β : Type*} (s : Finset α) (t : Finset β) + (a : α → ℂ) (b : β → ℂ) (z : α → β → ℂ) : + ‖∑ m ∈ s, a m * ∑ n ∈ t, b n * z m n‖ ^ 2 ≤ + (∑ m ∈ s, ‖a m‖ ^ 2) * + (∑ n ∈ t, ∑ k ∈ t, ‖b n‖ * ‖b k‖ * + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) := by + calc + _ ≤ (∑ m ∈ s, ‖a m‖ * ‖∑ n ∈ t, b n * z m n‖) ^ 2 := by + apply pow_le_pow_left₀ (norm_nonneg _) + simpa only [norm_mul] using + norm_sum_le s (fun m => a m * ∑ n ∈ t, b n * z m n) + _ ≤ (∑ m ∈ s, ‖a m‖ ^ 2) * + ∑ m ∈ s, ‖∑ n ∈ t, b n * z m n‖ ^ 2 := + Finset.sum_mul_sq_le_sq_mul_sq s _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left (energy_le_correlations s t b z) + (Finset.sum_nonneg fun _ _ => sq_nonneg _) + +/-- For unit phases the diagonal correlation is exactly the number of rows. -/ +theorem diagonal_correlation {α β : Type*} (s : Finset α) + (z : α → β → ℂ) (n : β) (hz : ∀ m ∈ s, ‖z m n‖ = 1) : + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m n)‖ = (s.card : ℝ) := by + have h : (∑ m ∈ s, z m n * (starRingEnd ℂ) (z m n)) = (s.card : ℂ) := by + calc + _ = ∑ m ∈ s, (1 : ℂ) := by + apply Finset.sum_congr rfl + intro m hm + rw [Complex.mul_conj', hz m hm] + norm_num + _ = _ := by simp + rw [h, Complex.norm_natCast] + +/-- Exact diagonal/off-diagonal separation; erased indices do not count a +diagonal pair twice, including when either indexing set is empty. -/ +theorem correlation_sum_split {α β : Type*} [DecidableEq β] + (s : Finset α) (t : Finset β) (z : α → β → ℂ) + (hz : ∀ m ∈ s, ∀ n ∈ t, ‖z m n‖ = 1) : + (∑ n ∈ t, ∑ k ∈ t, ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) = + (s.card : ℝ) * t.card + + ∑ n ∈ t, ∑ k ∈ t.erase n, + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖ := by + have hpoint (n : β) (hn : n ∈ t) : + (∑ k ∈ t, ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) = + (s.card : ℝ) + ∑ k ∈ t.erase n, + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖ := by + rw [← Finset.sum_erase_add (s := t) + (fun k => ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) hn, + diagonal_correlation s z n (fun m hm => hz m hm n hn)] + ring + calc + _ = ∑ n ∈ t, ((s.card : ℝ) + ∑ k ∈ t.erase n, + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) := + Finset.sum_congr rfl hpoint + _ = _ := by rw [Finset.sum_add_distrib]; simp [mul_comm] + +/-- Bounded coefficient version of Type-II Cauchy--Schwarz. The diagonal +is evaluated exactly; only genuine off-diagonal correlations remain. -/ +theorem norm_bilinear_sq_le_offDiagonal {α β : Type*} [DecidableEq β] + (s : Finset α) (t : Finset β) (a : α → ℂ) (b : β → ℂ) + (z : α → β → ℂ) (B : ℝ) (hB : 0 ≤ B) + (hb : ∀ n ∈ t, ‖b n‖ ≤ B) + (hz : ∀ m ∈ s, ∀ n ∈ t, ‖z m n‖ = 1) : + ‖∑ m ∈ s, a m * ∑ n ∈ t, b n * z m n‖ ^ 2 ≤ + (∑ m ∈ s, ‖a m‖ ^ 2) * B ^ 2 * + ((s.card : ℝ) * t.card + ∑ n ∈ t, ∑ k ∈ t.erase n, + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) := by + have hbound : + (∑ n ∈ t, ∑ k ∈ t, ‖b n‖ * ‖b k‖ * + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) ≤ + B ^ 2 * ∑ n ∈ t, ∑ k ∈ t, + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖ := by + simp only [Finset.mul_sum] + apply Finset.sum_le_sum + intro n hn + apply Finset.sum_le_sum + intro k hk + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + simpa only [pow_two] using mul_le_mul (hb n hn) (hb k hk) (norm_nonneg _) hB + calc + _ ≤ _ := norm_bilinear_sq_le s t a b z + _ ≤ (∑ m ∈ s, ‖a m‖ ^ 2) * + (B ^ 2 * ∑ n ∈ t, ∑ k ∈ t, + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) := + mul_le_mul_of_nonneg_left hbound (Finset.sum_nonneg fun _ _ => sq_nonneg _) + _ = _ := by rw [correlation_sum_split s t z hz]; ring + +/-- The standard real additive phase, with the `2π` convention. -/ +def phase (x : ℝ) : ℂ := Real.fourierChar x + +@[simp] theorem norm_phase (x : ℝ) : ‖phase x‖ = 1 := Circle.norm_coe _ + +theorem phase_mul_conj (x y : ℝ) : + phase x * (starRingEnd ℂ) (phase y) = phase (x - y) := by + unfold phase + rw [Circle.starRingEnd_addChar, ← Circle.coe_mul, ← AddChar.map_add_eq_mul] + congr 2 + +theorem phase_nat_mul (x : ℝ) (n : ℕ) : phase (x * n) = phase x ^ n := by + unfold phase + rw [mul_comm, ← nsmul_eq_mul, AddChar.map_nsmul_eq_pow, Circle.coe_pow] + +/-- An exact geometric cancellation bound in a form valid even at resonance. -/ +theorem phase_sum_mul_bound (x : ℝ) (M : ℕ) : + ‖∑ m ∈ Finset.range M, phase (x * m)‖ * ‖1 - phase x‖ ≤ 2 := by + simp_rw [phase_nat_mul] + rw [← norm_mul, geom_sum_mul_neg] + calc + ‖1 - phase x ^ M‖ ≤ ‖(1 : ℂ)‖ + ‖phase x ^ M‖ := norm_sub_le _ _ + _ = 2 := by simp; norm_num + +/-- The usual geometric sum bound away from resonance. -/ +theorem phase_sum_le_min (x : ℝ) (M : ℕ) (hx : phase x ≠ 1) : + ‖∑ m ∈ Finset.range M, phase (x * m)‖ ≤ + min (M : ℝ) (2 / ‖1 - phase x‖) := by + apply le_min + · calc + _ ≤ ∑ m ∈ Finset.range M, ‖phase (x * m)‖ := norm_sum_le _ _ + _ = M := by simp + · have hpos : 0 < ‖1 - phase x‖ := norm_pos_iff.mpr (sub_ne_zero.mpr hx.symm) + exact (le_div_iff₀ hpos).mpr (phase_sum_mul_bound x M) + +/-- A total geometric majorant. Resonant frequencies use the trivial bound; +the definition never interprets division by zero as cancellation. -/ +def geometricBound (M : ℕ) (x : ℝ) : ℝ := + if phase x = 1 then M else min (M : ℝ) (2 / ‖1 - phase x‖) + +theorem phase_sum_le_geometricBound (x : ℝ) (M : ℕ) : + ‖∑ m ∈ Finset.range M, phase (x * m)‖ ≤ geometricBound M x := by + unfold geometricBound + split_ifs with hx + · simp_rw [phase_nat_mul, hx] + simp + · exact phase_sum_le_min x M hx + +/-- The finite Type-II estimate specialized to a real bilinear phase. All +remaining terms are explicit one-dimensional geometric sums, bounded without +any Diophantine approximation assumption. -/ +theorem real_phase_bilinear_sq_le (M : ℕ) (t : Finset ℕ) + (a b : ℕ → ℂ) (θ B : ℝ) (hB : 0 ≤ B) + (hb : ∀ n ∈ t, ‖b n‖ ≤ B) : + ‖∑ m ∈ Finset.range M, a m * ∑ n ∈ t, b n * phase (θ * m * n)‖ ^ 2 ≤ + (∑ m ∈ Finset.range M, ‖a m‖ ^ 2) * B ^ 2 * + ((M : ℝ) * t.card + ∑ n ∈ t, ∑ k ∈ t.erase n, + geometricBound M (θ * ((n : ℝ) - k))) := by + have hbase := norm_bilinear_sq_le_offDiagonal (Finset.range M) t a b + (fun m n => phase (θ * m * n)) B hB hb + (fun m hm n hn => norm_phase _) + simp only [Finset.card_range] at hbase + refine hbase.trans ?_ + apply mul_le_mul_of_nonneg_left _ + (mul_nonneg (Finset.sum_nonneg fun _ _ => sq_nonneg _) (sq_nonneg B)) + apply add_le_add_right + apply Finset.sum_le_sum + intro n hn + apply Finset.sum_le_sum + intro k hk + have hcorr : (∑ m ∈ Finset.range M, + phase (θ * m * n) * (starRingEnd ℂ) (phase (θ * m * k))) = + ∑ m ∈ Finset.range M, phase ((θ * ((n : ℝ) - k)) * m) := by + apply Finset.sum_congr rfl + intro m hm + rw [phase_mul_conj] + congr 1 + ring + rw [hcorr] + exact phase_sum_le_geometricBound _ M + +/-- A finite real Schur bound, proved by symmetrizing `2xy ≤ x²+y²`. +The coefficients need not be nonnegative. -/ +theorem symmetric_weighted_sum_le {β : Type*} (t : Finset β) + (f : β → ℝ) (K : β → β → ℝ) + (hK : ∀ n ∈ t, ∀ k ∈ t, 0 ≤ K n k) + (hsym : ∀ n ∈ t, ∀ k ∈ t, K n k = K k n) : + (∑ n ∈ t, ∑ k ∈ t, f n * f k * K n k) ≤ + ∑ n ∈ t, f n ^ 2 * ∑ k ∈ t, K n k := by + have hfirst : (∑ n ∈ t, ∑ k ∈ t, f n ^ 2 * K n k) = + ∑ n ∈ t, f n ^ 2 * ∑ k ∈ t, K n k := by + simp only [Finset.mul_sum] + have hsecond : (∑ n ∈ t, ∑ k ∈ t, f k ^ 2 * K n k) = + ∑ n ∈ t, f n ^ 2 * ∑ k ∈ t, K n k := by + rw [Finset.sum_comm] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro n hn + apply Finset.sum_congr rfl + intro k hk + rw [hsym k hk n hn] + calc + _ ≤ ∑ n ∈ t, ∑ k ∈ t, + (f n ^ 2 * K n k + f k ^ 2 * K n k) / 2 := by + apply Finset.sum_le_sum + intro n hn + apply Finset.sum_le_sum + intro k hk + nlinarith [mul_nonneg (sq_nonneg (f n - f k)) (hK n hn k hk)] + _ = ((∑ n ∈ t, ∑ k ∈ t, f n ^ 2 * K n k) + + (∑ n ∈ t, ∑ k ∈ t, f k ^ 2 * K n k)) / 2 := by + simp only [add_div, Finset.sum_div, Finset.sum_add_distrib] + _ = _ := by rw [hfirst, hsecond]; ring + +/-- Reversing a correlation conjugates it, hence preserves its norm. -/ +theorem correlation_norm_symm {α β : Type*} (s : Finset α) + (z : α → β → ℂ) (n k : β) : + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖ = + ‖∑ m ∈ s, z m k * (starRingEnd ℂ) (z m n)‖ := by + have hc : (∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)) = + (starRingEnd ℂ) (∑ m ∈ s, z m k * (starRingEnd ℂ) (z m n)) := by + simp only [map_sum, map_mul, starRingEnd_self_apply] + apply Finset.sum_congr rfl + intro m hm + ring + rw [hc, Complex.norm_conj] + +/-- Type-II energy bound using an absolute correlation row bound. Unlike the +bounded-coefficient version, this retains both coefficient squared sums and +therefore applies directly to divisor-coefficient second-moment estimates. -/ +theorem norm_bilinear_sq_le_energy {α β : Type*} (s : Finset α) (t : Finset β) + (a : α → ℂ) (b : β → ℂ) (z : α → β → ℂ) (C : ℝ) + (hrow : ∀ n ∈ t, + (∑ k ∈ t, ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) ≤ C) : + ‖∑ m ∈ s, a m * ∑ n ∈ t, b n * z m n‖ ^ 2 ≤ + (∑ m ∈ s, ‖a m‖ ^ 2) * C * (∑ n ∈ t, ‖b n‖ ^ 2) := by + have hweight := symmetric_weighted_sum_le t (fun n => ‖b n‖) + (fun n k => ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) + (fun _ _ _ _ => norm_nonneg _) + (fun n _ k _ => correlation_norm_symm s z n k) + have hbound : + (∑ n ∈ t, ∑ k ∈ t, ‖b n‖ * ‖b k‖ * + ‖∑ m ∈ s, z m n * (starRingEnd ℂ) (z m k)‖) ≤ + C * ∑ n ∈ t, ‖b n‖ ^ 2 := by + refine hweight.trans ?_ + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro n hn + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hrow n hn) (sq_nonneg ‖b n‖) + calc + _ ≤ _ := norm_bilinear_sq_le s t a b z + _ ≤ (∑ m ∈ s, ‖a m‖ ^ 2) * (C * ∑ n ∈ t, ‖b n‖ ^ 2) := + mul_le_mul_of_nonneg_left hbound (Finset.sum_nonneg fun _ _ => sq_nonneg _) + _ = _ := by ring + +end Problem337.VaughanBilinear + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanCutoff.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanCutoff.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e869aafb09fa5579b2aa013f05f254be1c5a801 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanCutoff.lean @@ -0,0 +1,192 @@ +import Mathlib + +namespace OAI +noncomputable section +open Filter + +namespace Problem337.Vaughan + +/-- The conventional balanced natural cutoff for Vaughan's identity. -/ +def optimizedCutoff (X : ℝ) : ℕ := ⌊X ^ (2 / 5 : ℝ)⌋₊ + +theorem optimizedCutoff_le (X : ℝ) (hX : 0 ≤ X) : + (optimizedCutoff X : ℝ) ≤ X ^ (2 / 5 : ℝ) := + Nat.floor_le (Real.rpow_nonneg hX _) + +theorem optimizedCutoff_lower (X : ℝ) (hX : 2 ≤ X ^ (2 / 5 : ℝ)) : + X ^ (2 / 5 : ℝ) / 2 ≤ (optimizedCutoff X : ℝ) := by + have hfloor := Nat.lt_floor_add_one (X ^ (2 / 5 : ℝ)) + unfold optimizedCutoff + linarith + +theorem optimizedCutoff_pos (X : ℝ) (hX : 2 ≤ X ^ (2 / 5 : ℝ)) : + 0 < optimizedCutoff X := by + have h : 2 ≤ optimizedCutoff X := Nat.le_floor hX + omega + +theorem optimizedCutoff_sq_le (X : ℝ) (hX : 0 ≤ X) : + (optimizedCutoff X : ℝ) ^ 2 ≤ X ^ (4 / 5 : ℝ) := by + have hpow : (X ^ (2 / 5 : ℝ)) ^ 2 = X ^ (4 / 5 : ℝ) := by + have h := Real.rpow_mul hX (2 / 5 : ℝ) (2 : ℝ) + norm_num at h + exact h.symm + rw [← hpow] + exact pow_le_pow_left₀ (Nat.cast_nonneg _) (optimizedCutoff_le X hX) 2 + +theorem optimizedCutoff_le_four_fifths (X : ℝ) (hX : 1 ≤ X) : + (optimizedCutoff X : ℝ) ≤ X ^ (4 / 5 : ℝ) := + (optimizedCutoff_le X (by linarith)).trans + (Real.rpow_le_rpow_of_exponent_le hX (by norm_num)) + +/-- The reciprocal square-root loss from a long-variable cutoff has precisely +the required four-fifths power, with a harmless explicit constant. -/ +theorem div_sqrt_optimizedCutoff_le (X : ℝ) (hX : 0 < X) + (hpow : 2 ≤ X ^ (2 / 5 : ℝ)) : + X / Real.sqrt (optimizedCutoff X : ℝ) ≤ 2 * X ^ (4 / 5 : ℝ) := by + have hsq : (X ^ (1 / 5 : ℝ)) ^ 2 = X ^ (2 / 5 : ℝ) := by + have h := Real.rpow_mul hX.le (1 / 5 : ℝ) (2 : ℝ) + norm_num at h + exact h.symm + have hcut := optimizedCutoff_lower X hpow + have hs : X ^ (1 / 5 : ℝ) / 2 ≤ Real.sqrt (optimizedCutoff X : ℝ) := by + apply (Real.le_sqrt (by positivity) (Nat.cast_nonneg _)).mpr + nlinarith [sq_nonneg (X ^ (1 / 5 : ℝ))] + have hpos : 0 < Real.sqrt (optimizedCutoff X : ℝ) := + Real.sqrt_pos.mpr (by exact_mod_cast optimizedCutoff_pos X hpow) + apply (div_le_iff₀ hpos).mpr + have hprod : X ^ (4 / 5 : ℝ) * X ^ (1 / 5 : ℝ) = X := by + rw [← Real.rpow_add hX] + norm_num + calc + X = X ^ (4 / 5 : ℝ) * X ^ (1 / 5 : ℝ) := hprod.symm + _ = (2 * X ^ (4 / 5 : ℝ)) * (X ^ (1 / 5 : ℝ) / 2) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hs (by positivity) + +/-- A concrete scalar optimization of the cutoff-dependent error terms. -/ +theorem optimizedCutoff_error_le (X : ℝ) (hX : 1 ≤ X) + (hpow : 2 ≤ X ^ (2 / 5 : ℝ)) : + (optimizedCutoff X : ℝ) + (optimizedCutoff X : ℝ) ^ 2 + + X / Real.sqrt (optimizedCutoff X : ℝ) ≤ 4 * X ^ (4 / 5 : ℝ) := by + have h1 := optimizedCutoff_le_four_fifths X hX + have h2 := optimizedCutoff_sq_le X (by linarith) + have h3 := div_sqrt_optimizedCutoff_le X (by linarith) hpow + linarith + +/-- The short initial segment is also absorbed by the four-fifths budget. -/ +theorem optimizedCutoff_log_le (X : ℝ) (hX : 1 ≤ X) + (hpow : 2 ≤ X ^ (2 / 5 : ℝ)) : + (optimizedCutoff X : ℝ) * Real.log (optimizedCutoff X : ℝ) ≤ + X ^ (4 / 5 : ℝ) * Real.log X := by + have hUX : (optimizedCutoff X : ℝ) ≤ X := by + calc + _ ≤ X ^ (2 / 5 : ℝ) := optimizedCutoff_le X (by linarith) + _ ≤ X ^ (1 : ℝ) := Real.rpow_le_rpow_of_exponent_le hX (by norm_num) + _ = X := Real.rpow_one X + have hlog : Real.log (optimizedCutoff X : ℝ) ≤ Real.log X := + Real.log_le_log (by exact_mod_cast optimizedCutoff_pos X hpow) hUX + have hlogX : 0 ≤ Real.log X := Real.log_nonneg hX + exact (mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg _)).trans + (mul_le_mul_of_nonneg_right (optimizedCutoff_le_four_fifths X hX) hlogX) + +/-- Scalar normalization to the usual three-term Vaughan envelope. The +Diophantine denominator only needs the ordinary range `1 ≤ q ≤ X`. -/ +theorem optimizedCutoff_standard_envelope (X q : ℝ) (hX : 1 ≤ X) + (hq : 1 ≤ q) (hqX : q ≤ X) (hpow : 2 ≤ X ^ (2 / 5 : ℝ)) : + X / q + ((optimizedCutoff X : ℝ) + (optimizedCutoff X : ℝ) ^ 2 + + X / Real.sqrt (optimizedCutoff X : ℝ)) + q ≤ + 4 * (X / Real.sqrt q + X ^ (4 / 5 : ℝ) + Real.sqrt (X * q)) := by + have hX0 : 0 ≤ X := by linarith + have hq0 : 0 ≤ q := by linarith + have hsqpos : 0 < Real.sqrt q := Real.sqrt_pos.mpr (by linarith) + have hsqq : Real.sqrt q ≤ q := Real.sqrt_le_self_iff.mpr (Or.inr hq) + have hdiv : X / q ≤ X / Real.sqrt q := + div_le_div_of_nonneg_left hX0 hsqpos hsqq + have hqsqrt : q ≤ Real.sqrt (X * q) := by + apply (Real.le_sqrt hq0 (mul_nonneg hX0 hq0)).mpr + nlinarith [mul_le_mul_of_nonneg_right hqX hq0] + have herr := optimizedCutoff_error_le X hX hpow + have hnonneg : 0 ≤ X / Real.sqrt q := div_nonneg hX0 hsqpos.le + nlinarith [Real.sqrt_nonneg (X * q)] + +/-- Optimization of the square-root expression arising from a Type II block. +Both long-variable cutoffs are the same balanced natural cutoff. -/ +theorem sqrt_optimizedCutoff_envelope_le (X q : ℝ) (hX : 1 ≤ X) + (hq : 0 < q) (hpow : 2 ≤ X ^ (2 / 5 : ℝ)) : + Real.sqrt (X * (X / q + X / (optimizedCutoff X : ℝ) + + X / (optimizedCutoff X : ℝ) + q)) ≤ + 3 * (X / Real.sqrt q + X ^ (4 / 5 : ℝ) + Real.sqrt (X * q)) := by + have hX0 : 0 ≤ X := by linarith + have hU0 : 0 < (optimizedCutoff X : ℝ) := by + exact_mod_cast optimizedCutoff_pos X hpow + have hA : 0 ≤ X / Real.sqrt q := by positivity + have hB : 0 ≤ X ^ (4 / 5 : ℝ) := by positivity + have hC : 0 ≤ Real.sqrt (X * q) := Real.sqrt_nonneg _ + have hqeq : X * (X / q) = (X / Real.sqrt q) ^ 2 := by + rw [div_pow, Real.sq_sqrt hq.le] + ring + have hUeq : X * (X / (optimizedCutoff X : ℝ)) = + (X / Real.sqrt (optimizedCutoff X : ℝ)) ^ 2 := by + rw [div_pow, Real.sq_sqrt hU0.le] + ring + have hUbound := pow_le_pow_left₀ (show 0 ≤ X / Real.sqrt (optimizedCutoff X : ℝ) by + positivity) (div_sqrt_optimizedCutoff_le X (by linarith) hpow) 2 + have hCeq := Real.sq_sqrt (mul_nonneg hX0 hq.le) + apply (Real.sqrt_le_left (by positivity)).mpr + rw [mul_add, mul_add, mul_add, hqeq, hUeq] + nlinarith [mul_nonneg hA hB, mul_nonneg hA hC, mul_nonneg hB hC, + sq_nonneg (X / Real.sqrt q), sq_nonneg (X ^ (4 / 5 : ℝ)), + sq_nonneg (Real.sqrt (X * q))] + +/-- The precise squared Type II block budget transfers to the standard +Vaughan envelope after choosing both cutoffs as `optimizedCutoff X`. -/ +theorem optimizedCutoff_squared_budget (X q C R : ℝ) (hX : 1 ≤ X) + (hq : 0 < q) (hC : 0 ≤ C) (hpow : 2 ≤ X ^ (2 / 5 : ℝ)) + (hbound : R ^ 2 ≤ C * X * (1 + Real.log (2 * X)) ^ 6 * + (X / q + X / (optimizedCutoff X : ℝ) + X / (optimizedCutoff X : ℝ) + q)) : + R ≤ 3 * Real.sqrt C * (1 + Real.log (2 * X)) ^ 3 * + (X / Real.sqrt q + X ^ (4 / 5 : ℝ) + Real.sqrt (X * q)) := by + let L : ℝ := 1 + Real.log (2 * X) + let E : ℝ := X / Real.sqrt q + X ^ (4 / 5 : ℝ) + Real.sqrt (X * q) + have hX0 : 0 ≤ X := by linarith + have hL : 0 ≤ L := by + have := Real.log_nonneg (show (1 : ℝ) ≤ 2 * X by linarith) + dsimp [L] + linarith + have hE : 0 ≤ E := by dsimp [E]; positivity + have hD : X * (X / q + X / (optimizedCutoff X : ℝ) + + X / (optimizedCutoff X : ℝ) + q) ≤ (3 * E) ^ 2 := + (Real.sqrt_le_left (by positivity)).mp (sqrt_optimizedCutoff_envelope_le X q hX hq hpow) + change R ≤ 3 * Real.sqrt C * L ^ 3 * E + apply le_of_sq_le_sq _ (by positivity) + calc + R ^ 2 ≤ C * X * L ^ 6 * + (X / q + X / (optimizedCutoff X : ℝ) + X / (optimizedCutoff X : ℝ) + q) := hbound + _ = (C * L ^ 6) * (X * + (X / q + X / (optimizedCutoff X : ℝ) + X / (optimizedCutoff X : ℝ) + q)) := by ring + _ ≤ (C * L ^ 6) * (3 * E) ^ 2 := mul_le_mul_of_nonneg_left hD (by positivity) + _ = (3 * Real.sqrt C * L ^ 3 * E) ^ 2 := by + have hs := Real.sq_sqrt hC + calc + _ = (3 * E) ^ 2 * L ^ 6 * (Real.sqrt C) ^ 2 := by rw [hs]; ring + _ = _ := by ring + +/-- All cutoff inequalities hold simultaneously beyond one real threshold. -/ +theorem eventually_optimizedCutoff_bounds : + ∀ᶠ X : ℝ in atTop, + 0 < optimizedCutoff X ∧ + X ^ (2 / 5 : ℝ) / 2 ≤ (optimizedCutoff X : ℝ) ∧ + (optimizedCutoff X : ℝ) ≤ X ^ (2 / 5 : ℝ) ∧ + (optimizedCutoff X : ℝ) ^ 2 ≤ X ^ (4 / 5 : ℝ) ∧ + X / Real.sqrt (optimizedCutoff X : ℝ) ≤ 2 * X ^ (4 / 5 : ℝ) := by + have hlarge := (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 2 / 5)).eventually + (eventually_ge_atTop (2 : ℝ)) + filter_upwards [hlarge, eventually_ge_atTop (1 : ℝ)] with X hpow hX + exact ⟨optimizedCutoff_pos X hpow, optimizedCutoff_lower X hpow, + optimizedCutoff_le X (by linarith), optimizedCutoff_sq_le X (by linarith), + div_sqrt_optimizedCutoff_le X (by linarith) hpow⟩ + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanDecomposition.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDecomposition.lean new file mode 100644 index 0000000000000000000000000000000000000000..93921bc13280bfab12819f171845d8d8e6a04fe2 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDecomposition.lean @@ -0,0 +1,105 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanTypeI + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius ArithmeticFunction.zeta + +namespace Problem337.Vaughan + +/-- Taking a short part restricts a finite weighted sum to the smaller interval. -/ +theorem weightedSum_shortPart (N V : ℕ) (w : ℕ → ℂ) (f : ArithmeticFunction ℝ) : + weightedSum (Finset.Ioc 0 N) w (shortPart V f) = + weightedSum (Finset.Ioc 0 (min V N)) w f := by + unfold weightedSum + calc + _ = ∑ n ∈ Finset.Ioc 0 (min V N), (shortPart V f n : ℂ) * w n := by + symm + apply Finset.sum_subset + · intro n hn + obtain ⟨hn0, hnVN⟩ := Finset.mem_Ioc.mp hn + exact Finset.mem_Ioc.mpr ⟨hn0, (le_min_iff.mp hnVN).2⟩ + · intro n hn hnot + have hV : ¬ n ≤ V := by + simp only [Finset.mem_Ioc] at hn hnot + omega + simp [hV] + _ = _ := by + apply Finset.sum_congr rfl + intro n hn + simp [(le_min_iff.mp (Finset.mem_Ioc.mp hn).2).1] + +/-- The initial von Mangoldt segment has the elementary `V log V` bound. -/ +theorem norm_short_vonMangoldt_sum_le (N V : ℕ) (w : ℕ → ℂ) + (hw : ∀ n ∈ Finset.Ioc 0 N, ‖w n‖ ≤ 1) : + ‖weightedSum (Finset.Ioc 0 N) w (shortPart V Λ)‖ ≤ + (V : ℝ) * Real.log V := by + rw [weightedSum_shortPart] + unfold weightedSum + calc + _ ≤ ∑ n ∈ Finset.Ioc 0 (min V N), ‖(Λ n : ℂ) * w n‖ := norm_sum_le _ _ + _ ≤ ∑ _n ∈ Finset.Ioc 0 (min V N), Real.log V := by + apply Finset.sum_le_sum + intro n hn + obtain ⟨hn0, hnVN⟩ := Finset.mem_Ioc.mp hn + obtain ⟨hnV, hnN⟩ := le_min_iff.mp hnVN + rw [norm_mul, Complex.norm_real, Real.norm_eq_abs, + abs_of_nonneg ArithmeticFunction.vonMangoldt_nonneg] + calc + Λ n * ‖w n‖ ≤ Λ n * 1 := mul_le_mul_of_nonneg_left + (hw n (Finset.mem_Ioc.mpr ⟨hn0, hnN⟩)) ArithmeticFunction.vonMangoldt_nonneg + _ ≤ Real.log n := by simpa using (ArithmeticFunction.vonMangoldt_le_log (n := n)) + _ ≤ Real.log V := Real.log_le_log (by exact_mod_cast hn0) (by exact_mod_cast hnV) + _ = (min V N : ℕ) * Real.log V := by simp + _ ≤ (V : ℝ) * Real.log V := mul_le_mul_of_nonneg_right + (by exact_mod_cast min_le_left V N) (Real.log_natCast_nonneg V) + +/-- The actual Type II term is a hyperbola with both short factors removed. -/ +theorem typeII_eq_hyperbola (N U V : ℕ) (w : ℕ → ℂ) : + weightedSum (Finset.Ioc 0 N) w (typeIICoefficient U * longPart V Λ) = + ∑ d ∈ (hyperbola N).filter (fun d => U < d.1 ∧ V < d.2), + (typeIICoefficient U d.1 : ℂ) * (Λ d.2 : ℂ) * w (d.1 * d.2) := by + unfold weightedSum + rw [← positive_interval N, sum_real_convolution_hyperbola, Finset.sum_filter] + apply Finset.sum_congr rfl + intro d hd + by_cases hU : U < d.1 + · by_cases hV : V < d.2 <;> simp [hU, hV] + · simp [hU, typeIICoefficient_eq_zero U d.1 (not_lt.mp hU)] + +/-- A fully finite Vaughan estimate. Only the displayed elementary inner-sum +envelopes are hypotheses; the remaining Type II sum is retained explicitly. -/ +theorem norm_vonMangoldt_sum_le (N U V : ℕ) (w : ℕ → ℂ) (B₁ B₂ : ℕ → ℝ) + (hw : ∀ n ∈ Finset.Ioc 0 N, ‖w n‖ ≤ 1) + (hfirst : ∀ a ∈ Finset.Ioc 0 (min U N), ∀ k ≤ N / a, + ‖∑ b ∈ Finset.Ioc 0 k, w (a * b)‖ ≤ B₁ a) + (hsecond : ∀ a ∈ Finset.Ioc 0 (min (U * V) N), + ‖∑ b ∈ Finset.Ioc 0 (N / a), w (a * b)‖ ≤ B₂ a) : + ‖weightedSum (Finset.Ioc 0 N) w Λ‖ ≤ + (V : ℝ) * Real.log V + + 2 * Real.log N * (∑ a ∈ Finset.Ioc 0 (min U N), B₁ a) + + Real.log N * (∑ a ∈ Finset.Ioc 0 (min (U * V) N), B₂ a) + + ‖∑ d ∈ (hyperbola N).filter (fun d => U < d.1 ∧ V < d.2), + (typeIICoefficient U d.1 : ℂ) * (Λ d.2 : ℂ) * w (d.1 * d.2)‖ := by + have h0 := norm_short_vonMangoldt_sum_le N V w hw + have h1 := first_typeI_bound w N U B₁ hfirst + have h2 := second_typeI_bound w N U V B₂ hsecond + rw [weighted_identity (Finset.Ioc 0 N) w U V] + calc + _ ≤ (‖weightedSum (Finset.Ioc 0 N) w (shortPart V Λ)‖ + + ‖weightedSum (Finset.Ioc 0 N) w + (shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log)‖) + + ‖weightedSum (Finset.Ioc 0 N) w (typeICoefficient U V * ζ)‖ + + ‖weightedSum (Finset.Ioc 0 N) w (typeIICoefficient U * longPart V Λ)‖ := by + apply (norm_add_le _ _).trans + apply add_le_add _ le_rfl + apply (norm_sub_le _ _).trans + exact add_le_add (norm_add_le _ _) le_rfl + _ ≤ _ := by + rw [typeII_eq_hyperbola] + exact add_le_add (add_le_add (add_le_add h0 h1) h2) le_rfl + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadic.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadic.lean new file mode 100644 index 0000000000000000000000000000000000000000..305abd507775114b0aba9afea5a68c1534e33d22 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadic.lean @@ -0,0 +1,152 @@ +import Mathlib + +namespace OAI +/-! +# Exact dyadic decomposition of a truncated hyperbola + +The long--long convolution is partitioned into genuine dyadic row intervals. +Each column interval is shortened to `N / 2^j`, retaining the exact `mn ≤ N` +cutoff. This is a finite reindexing, with no analytic cancellation hypothesis. +-/ + +noncomputable section +open scoped BigOperators +open Finset + +namespace Problem337.VaughanDyadic + +/-- Rows above the lower cutoff, inside one half-open power-of-two interval. -/ +def shell (U N j : ℕ) : Finset ℕ := + (Ioc U N).filter fun m => 2 ^ j ≤ m ∧ m < 2 ^ (j + 1) + +lemma mem_shell {U N j m : ℕ} : + m ∈ shell U N j ↔ U < m ∧ m ≤ N ∧ 2 ^ j ≤ m ∧ m < 2 ^ (j + 1) := by + simp only [shell, mem_filter, mem_Ioc] + tauto + +lemma shell_eq_log_fiber (U N j : ℕ) : + shell U N j = (Ioc U N).filter (fun m => Nat.log 2 m = j) := by + ext m + simp only [shell, mem_filter] + apply and_congr_right + intro hm + exact (Nat.log_eq_iff (Or.inr ⟨by decide, (lt_of_le_of_lt (Nat.zero_le U) + (mem_Ioc.mp hm).1).ne'⟩)).symm + +/-- The shell is a single consecutive interval, so its phase correlations remain geometric. -/ +lemma shell_eq_Icc (U N j : ℕ) : + shell U N j = Icc (max (U + 1) (2 ^ j)) (min N (2 ^ (j + 1) - 1)) := by + ext m + rw [mem_shell] + simp only [mem_Icc, max_le_iff, le_min_iff] + have hp : 0 < 2 ^ (j + 1) := by positivity + omega + +/-- Exact partition, valid also when the original interval is empty. -/ +theorem sum_eq_sum_shells {E : Type*} [AddCommMonoid E] + (U N : ℕ) (f : ℕ → E) : + (∑ m ∈ Ioc U N, f m) = + ∑ j ∈ range (Nat.log 2 N + 1), ∑ m ∈ shell U N j, f m := by + simp_rw [shell_eq_log_fiber] + apply (sum_fiberwise_of_maps_to ?_ f).symm + intro m hm + exact mem_range.mpr (Nat.lt_succ_of_le (Nat.log_mono_right (mem_Ioc.mp hm).2)) + +lemma inner_sum_eq_common_cutoff {E : Type*} [AddCommMonoid E] + (N U V j m : ℕ) (hm : m ∈ shell U N j) (f : ℕ → E) : + (∑ n ∈ Ioc V (N / m), f n) = + ∑ n ∈ Ioc V (N / 2 ^ j), if m * n ≤ N then f n else 0 := by + have hmem := mem_shell.mp hm + have hm0 : 0 < m := lt_of_le_of_lt (Nat.zero_le U) hmem.1 + have hpow : 0 < 2 ^ j := by positivity + have hdiv : N / m ≤ N / 2 ^ j := Nat.div_le_div_left hmem.2.2.1 hpow + have hsets : Ioc V (N / m) = + (Ioc V (N / 2 ^ j)).filter (fun n => m * n ≤ N) := by + ext n + simp only [mem_Ioc, mem_filter] + constructor + · rintro ⟨hV, hn⟩ + exact ⟨⟨hV, hn.trans hdiv⟩, + by simpa [Nat.mul_comm] using (Nat.le_div_iff_mul_le hm0).mp hn⟩ + · rintro ⟨⟨hV, _⟩, hn⟩ + exact ⟨hV, (Nat.le_div_iff_mul_le hm0).mpr (by simpa [Nat.mul_comm] using hn)⟩ + rw [hsets, sum_filter] + +/-- The actual dyadic block, not a rectangular surrogate without the cutoff. -/ +def block {E : Type*} [AddCommMonoid E] (N U V j : ℕ) (F : ℕ → ℕ → E) : E := + ∑ m ∈ shell U N j, ∑ n ∈ Ioc V (N / 2 ^ j), + if m * n ≤ N then F m n else 0 + +/-- Exact long--long hyperbola decomposition into common-column dyadic blocks. -/ +theorem sum_hyperbola_eq_sum_blocks {E : Type*} [AddCommMonoid E] + (N U V : ℕ) (F : ℕ → ℕ → E) : + (∑ m ∈ Ioc U N, ∑ n ∈ Ioc V (N / m), F m n) = + ∑ j ∈ range (Nat.log 2 N + 1), block N U V j F := by + rw [sum_eq_sum_shells] + apply sum_congr rfl + intro j hj + unfold block + apply sum_congr rfl + intro m hm + exact inner_sum_eq_common_cutoff N U V j m hm (F m) + +/-- Product-finset form of the same exact decomposition. -/ +theorem sum_filtered_product_eq_sum_blocks {E : Type*} [AddCommMonoid E] + (N U V : ℕ) (F : ℕ → ℕ → E) : + (∑ d ∈ (Ioc U N ×ˢ Ioc V N).filter (fun d => d.1 * d.2 ≤ N), F d.1 d.2) = + ∑ j ∈ range (Nat.log 2 N + 1), block N U V j F := by + rw [← sum_hyperbola_eq_sum_blocks, sum_filter, sum_product] + apply sum_congr rfl + intro m hm + have hm0 : 0 < m := lt_of_le_of_lt (Nat.zero_le U) (mem_Ioc.mp hm).1 + rw [← sum_filter] + have he : (Ioc V N).filter (fun n => m * n ≤ N) = Ioc V (N / m) := by + ext n + simp only [mem_filter, mem_Ioc] + constructor + · rintro ⟨⟨hV, _⟩, hmn⟩ + exact ⟨hV, (Nat.le_div_iff_mul_le hm0).mpr (by simpa [Nat.mul_comm] using hmn)⟩ + · rintro ⟨hV, hn⟩ + exact ⟨⟨hV, hn.trans (Nat.div_le_self N m)⟩, + by simpa [Nat.mul_comm] using (Nat.le_div_iff_mul_le hm0).mp hn⟩ + rw [he] + +/-- Triangle inequality with the actual dyadic block norms. -/ +theorem norm_hyperbola_le_sum_block_norms {E : Type*} [SeminormedAddCommGroup E] + (N U V : ℕ) (F : ℕ → ℕ → E) : + ‖∑ m ∈ Ioc U N, ∑ n ∈ Ioc V (N / m), F m n‖ ≤ + ∑ j ∈ range (Nat.log 2 N + 1), ‖block N U V j F‖ := by + rw [sum_hyperbola_eq_sum_blocks] + exact norm_sum_le _ _ + +/-- Any genuine uniform block estimate pays only the number of dyadic blocks. -/ +theorem norm_hyperbola_le_block_count {E : Type*} [SeminormedAddCommGroup E] + (N U V : ℕ) (F : ℕ → ℕ → E) (B : ℝ) + (hB : ∀ j < Nat.log 2 N + 1, ‖block N U V j F‖ ≤ B) : + ‖∑ m ∈ Ioc U N, ∑ n ∈ Ioc V (N / m), F m n‖ ≤ + (Nat.log 2 N + 1 : ℕ) * B := by + calc + _ ≤ ∑ j ∈ range (Nat.log 2 N + 1), ‖block N U V j F‖ := + norm_hyperbola_le_sum_block_norms N U V F + _ ≤ ∑ j ∈ range (Nat.log 2 N + 1), B := + sum_le_sum fun j hj => hB j (mem_range.mp hj) + _ = _ := by simp + +/-- Real-log normalization of the finite dyadic block count. -/ +theorem norm_hyperbola_le_log_budget {E : Type*} [SeminormedAddCommGroup E] + (N U V : ℕ) (F : ℕ → ℕ → E) (B : ℝ) (hB0 : 0 ≤ B) + (hB : ∀ j < Nat.log 2 N + 1, ‖block N U V j F‖ ≤ B) : + ‖∑ m ∈ Ioc U N, ∑ n ∈ Ioc V (N / m), F m n‖ ≤ + (1 + Real.log N / Real.log 2) * B := by + refine (norm_hyperbola_le_block_count N U V F B hB).trans ?_ + apply mul_le_mul_of_nonneg_right _ hB0 + have h := Real.natLog_le_logb N 2 + simp only [Real.logb, Nat.cast_ofNat] at h + push_cast + linarith + +end Problem337.VaughanDyadic + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicDecomposition.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicDecomposition.lean new file mode 100644 index 0000000000000000000000000000000000000000..7b0d23da76130ede69aadab66771184a4771b0d0 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicDecomposition.lean @@ -0,0 +1,96 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanDyadic +import OAI.NumberTheory.EgyptianFractions.VaughanDecomposition +import OAI.NumberTheory.EgyptianFractions.DivisorSquareMean + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius ArithmeticFunction.zeta +open Finset + +namespace Problem337.Vaughan + +lemma long_hyperbola_eq_filtered_product (N U V : ℕ) : + (hyperbola N).filter (fun d => U < d.1 ∧ V < d.2) = + (Ioc U N ×ˢ Ioc V N).filter (fun d => d.1 * d.2 ≤ N) := by + ext d + rcases d with ⟨a, b⟩ + simp only [mem_filter, mem_hyperbola, mem_product, mem_Ioc] + constructor + · rintro ⟨⟨ha, hb, hp⟩, hU, hV⟩ + exact ⟨⟨⟨hU, (Nat.le_mul_of_pos_right a hb).trans hp⟩, + ⟨hV, (Nat.le_mul_of_pos_left b ha).trans hp⟩⟩, hp⟩ + · rintro ⟨⟨⟨hU, ha⟩, ⟨hV, hb⟩⟩, hp⟩ + exact ⟨⟨by omega, by omega, hp⟩, hU, hV⟩ + +/-- The dyadic block with the actual arithmetic coefficients in Vaughan's identity. -/ +def typeIIBlock (N U V j : ℕ) (w : ℕ → ℂ) : ℂ := + VaughanDyadic.block N U V j + (fun m n => (typeIICoefficient U m : ℂ) * (Λ n : ℂ) * w (m * n)) + +/-- No arithmetic coefficient or hyperbolic cutoff is lost in dyadic decomposition. -/ +theorem typeII_eq_sum_dyadic_blocks (N U V : ℕ) (w : ℕ → ℂ) : + weightedSum (Ioc 0 N) w (typeIICoefficient U * longPart V Λ) = + ∑ j ∈ range (Nat.log 2 N + 1), typeIIBlock N U V j w := by + rw [typeII_eq_hyperbola, long_hyperbola_eq_filtered_product] + exact VaughanDyadic.sum_filtered_product_eq_sum_blocks (E := ℂ) N U V + (fun m n => (typeIICoefficient U m : ℂ) * (Λ n : ℂ) * w (m * n)) + +theorem norm_typeII_le_sum_dyadic_blocks (N U V : ℕ) (w : ℕ → ℂ) : + ‖weightedSum (Ioc 0 N) w (typeIICoefficient U * longPart V Λ)‖ ≤ + ∑ j ∈ range (Nat.log 2 N + 1), ‖typeIIBlock N U V j w‖ := by + rw [typeII_eq_sum_dyadic_blocks] + exact norm_sum_le _ _ + +/-- A genuine uniform block bound has only a logarithmic decomposition cost. -/ +theorem norm_typeII_le_dyadic_log_budget (N U V : ℕ) (w : ℕ → ℂ) + (B : ℝ) (hB0 : 0 ≤ B) + (hB : ∀ j < Nat.log 2 N + 1, ‖typeIIBlock N U V j w‖ ≤ B) : + ‖weightedSum (Ioc 0 N) w (typeIICoefficient U * longPart V Λ)‖ ≤ + (1 + Real.log N / Real.log 2) * B := by + let F : ℕ → ℕ → ℂ := + fun m n => (typeIICoefficient U m : ℂ) * (Λ n : ℂ) * w (m * n) + have he : weightedSum (Ioc 0 N) w (typeIICoefficient U * longPart V Λ) = + ∑ m ∈ Ioc U N, ∑ n ∈ Ioc V (N / m), F m n := by + rw [typeII_eq_sum_dyadic_blocks, VaughanDyadic.sum_hyperbola_eq_sum_blocks] + rfl + rw [he] + exact VaughanDyadic.norm_hyperbola_le_log_budget N U V F B hB0 hB + +/-- The complete finite Vaughan envelope, with its Type II term split into +actual dyadic blocks ready for interval correlation estimates. -/ +theorem norm_vonMangoldt_sum_le_dyadic (N U V : ℕ) (w : ℕ → ℂ) (B₁ B₂ : ℕ → ℝ) + (hw : ∀ n ∈ Ioc 0 N, ‖w n‖ ≤ 1) + (hfirst : ∀ a ∈ Ioc 0 (min U N), ∀ k ≤ N / a, + ‖∑ b ∈ Ioc 0 k, w (a * b)‖ ≤ B₁ a) + (hsecond : ∀ a ∈ Ioc 0 (min (U * V) N), + ‖∑ b ∈ Ioc 0 (N / a), w (a * b)‖ ≤ B₂ a) : + ‖weightedSum (Ioc 0 N) w Λ‖ ≤ + (V : ℝ) * Real.log V + + 2 * Real.log N * (∑ a ∈ Ioc 0 (min U N), B₁ a) + + Real.log N * (∑ a ∈ Ioc 0 (min (U * V) N), B₂ a) + + ∑ j ∈ range (Nat.log 2 N + 1), ‖typeIIBlock N U V j w‖ := by + have h := norm_vonMangoldt_sum_le N U V w B₁ B₂ hw hfirst hsecond + rw [← typeII_eq_hyperbola] at h + exact h.trans (add_le_add le_rfl (norm_typeII_le_sum_dyadic_blocks N U V w)) + +/-- Sharp unconditional row energy for the actual Type II coefficient in a dyadic shell. -/ +theorem typeII_shell_energy_le (N U j : ℕ) : + (∑ m ∈ VaughanDyadic.shell U N j, ‖(typeIICoefficient U m : ℂ)‖ ^ 2) ≤ + (2 ^ (j + 1) : ℕ) * (1 + Real.log (2 ^ (j + 1) : ℕ)) ^ 3 := by + have hT : VaughanDyadic.shell U N j ⊆ Ioc 0 (2 ^ (j + 1)) := by + intro m hm + have h := VaughanDyadic.mem_shell.mp hm + exact mem_Ioc.mpr ⟨lt_of_le_of_lt (Nat.zero_le U) h.1, h.2.2.2.le⟩ + have h := DivisorSquareMean.sum_norm_sq_le_log_of_subset + (fun m => (typeIICoefficient U m : ℂ)) (VaughanDyadic.shell U N j) + (2 ^ (j + 1)) 1 hT (by + intro m hm + simpa only [Complex.norm_real, Real.norm_eq_abs, one_mul] using + abs_typeIICoefficient_le_divisors_card U m) + simpa only [one_pow, one_mul] using h + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicEstimate.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicEstimate.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff7c204c1026d0c59b9a32d9e33e297e0a008204 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicEstimate.lean @@ -0,0 +1,96 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanDyadicDecomposition +import OAI.NumberTheory.EgyptianFractions.VaughanHyperbolicNearRational + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction +open Finset + +namespace Problem337.Vaughan + +lemma typeIIBlock_eq_bilinear (θ : ℝ) (N U V j : ℕ) : + typeIIBlock N U V j (fun k => VaughanBilinear.phase (θ * k)) = + ∑ m ∈ Icc (max (U + 1) (2 ^ j)) (min N (2 ^ (j + 1) - 1)), + (typeIICoefficient U m : ℂ) * + ∑ n ∈ Ioc V (N / 2 ^ j), (Λ n : ℂ) * + HyperbolaCorrelation.column θ N n m := by + unfold typeIIBlock VaughanDyadic.block + rw [VaughanDyadic.shell_eq_Icc] + apply sum_congr rfl + intro m hm + rw [mul_sum] + apply sum_congr rfl + intro n hn + unfold HyperbolaCorrelation.column + by_cases h : m * n ≤ N + · simp only [ite_eq_left h, HyperbolaCorrelation.phase_eq_vaughan] + rw [mul_assoc] + congr 2 + congr 1 + push_cast + ring + · simp [h] + +lemma dyadic_row_length_le (N U j : ℕ) : + min N (2 ^ (j + 1) - 1) + 1 - max (U + 1) (2 ^ j) ≤ 2 ^ j := by + have htop : min N (2 ^ (j + 1) - 1) ≤ 2 ^ (j + 1) - 1 := min_le_right _ _ + have hlow : 2 ^ j ≤ max (U + 1) (2 ^ j) := le_max_right _ _ + have hp : 0 < 2 ^ j := by positivity + rw [pow_succ] at htop + omega + +/-- The elementary bounded-weight column energy, used only as a normalization +inside the actual Type II block estimate. -/ +lemma mangoldt_column_energy_le (V T : ℕ) : + (∑ n ∈ Ioc V T, ‖(Λ n : ℂ)‖ ^ 2) ≤ (T : ℝ) * (Real.log T) ^ 2 := by + calc + _ ≤ ∑ n ∈ Ioc V T, (Real.log T) ^ 2 := by + apply sum_le_sum + intro n hn + have h := mem_Ioc.mp hn + have hn0 : 0 < n := lt_of_le_of_lt (Nat.zero_le V) h.1 + apply pow_le_pow_left₀ (norm_nonneg _) + rw [Complex.norm_real, Real.norm_eq_abs, + abs_of_nonneg ArithmeticFunction.vonMangoldt_nonneg] + exact ArithmeticFunction.vonMangoldt_le_log.trans + (Real.log_le_log (by exact_mod_cast hn0) (by exact_mod_cast h.2)) + _ = ((T - V : ℕ) : ℝ) * (Real.log T) ^ 2 := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast Nat.sub_le T V) (sq_nonneg _) + +/-- A genuine rational-approximation estimate for one actual Vaughan block. +All coefficient energies and correlations have been evaluated explicitly. -/ +theorem typeIIBlock_sq_le_raw + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N U V j : ℕ) : + ‖typeIIBlock N U V j (fun k => VaughanBilinear.phase (θ * k))‖ ^ 2 ≤ + ((2 ^ (j + 1) : ℕ) * (1 + Real.log (2 ^ (j + 1) : ℕ)) ^ 3) * + ((2 * ((N / 2 ^ j : ℕ) : ℝ) / q + 1) * + (2 * ((2 ^ j : ℕ) : ℝ) + 4 * (q : ℝ) * (1 + Real.log (2 * (q : ℝ))))) * + (((N / 2 ^ j : ℕ) : ℝ) * (Real.log (N / 2 ^ j : ℕ)) ^ 2) := by + have hlog : 0 ≤ 1 + Real.log (2 * (q : ℝ)) := by + have hq1 : (1 : ℝ) ≤ q := by exact_mod_cast hq + have h := Real.log_nonneg (show (1 : ℝ) ≤ 2 * q by linarith) + linarith + have h := VaughanBilinear.near_rational_hyperbolic_bilinear_sq_le θ a q hq hcop happrox + N (max (U + 1) (2 ^ j)) (min N (2 ^ (j + 1) - 1)) (V + 1) (N / 2 ^ j) + (Ioc V (N / 2 ^ j)) (by + intro n hn + have hn' := mem_Ioc.mp hn + exact mem_Ico.mpr ⟨by omega, by omega⟩) + (fun n hn => lt_of_le_of_lt (Nat.zero_le V) (mem_Ioc.mp hn).1) + (fun m => (typeIICoefficient U m : ℂ)) (fun n => (Λ n : ℂ)) + rw [← typeIIBlock_eq_bilinear, ← VaughanDyadic.shell_eq_Icc] at h + refine h.trans ?_ + have hA := typeII_shell_energy_le N U j + have hB := mangoldt_column_energy_le V (N / 2 ^ j) + have hlength : ((min N (2 ^ (j + 1) - 1) + 1 - max (U + 1) (2 ^ j) : ℕ) : ℝ) ≤ + ((2 ^ j : ℕ) : ℝ) := by exact_mod_cast dyadic_row_length_le N U j + gcongr + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicUniform.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicUniform.lean new file mode 100644 index 0000000000000000000000000000000000000000..7771af2ccae9f18e0d5c53c22a782e544fe216de --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanDyadicUniform.lean @@ -0,0 +1,127 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanDyadicEstimate +import OAI.NumberTheory.EgyptianFractions.TypeIIBlockScalar +import OAI.NumberTheory.EgyptianFractions.HyperbolaDyadicBridge + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction +open Finset + +namespace Problem337.Vaughan + +def typeIILogScale (N : ℕ) : ℝ := 1 + Real.log (2 * (N : ℝ)) + +lemma one_le_typeIILogScale (N : ℕ) : 1 ≤ typeIILogScale N := by + have h := Real.log_natCast_nonneg (2 * N) + simp only [Nat.cast_mul, Nat.cast_ofNat] at h + unfold typeIILogScale + linarith + +lemma log_nat_le_typeIILogScale (N T : ℕ) (hT : T ≤ N) : + Real.log T ≤ typeIILogScale N := by + by_cases h0 : T = 0 + · simp only [h0, Nat.cast_zero, Real.log_zero] + exact zero_le_one.trans (one_le_typeIILogScale N) + have ht : (0 : ℝ) < T := by exact_mod_cast Nat.pos_of_ne_zero h0 + have htn : (T : ℝ) ≤ 2 * (N : ℝ) := by + have h := (Nat.cast_le (α := ℝ)).mpr hT + nlinarith [Nat.cast_nonneg N (α := ℝ)] + have hlog := Real.log_le_log ht htn + unfold typeIILogScale + linarith + +/-- Uniform logarithmic normalization of the coefficient block estimate. -/ +theorem typeIIBlock_sq_le_normalized + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N U V j : ℕ) (hqN : q ≤ N) (hM : 2 ^ j ≤ N) : + ‖typeIIBlock N U V j (fun k => VaughanBilinear.phase (θ * k))‖ ^ 2 ≤ + (2 * ((2 ^ j : ℕ) : ℝ) * (typeIILogScale N) ^ 3) * + ((2 * ((N / 2 ^ j : ℕ) : ℝ) / q + 1) * + (2 * ((2 ^ j : ℕ) : ℝ) + 4 * (q : ℝ) * typeIILogScale N)) * + (((N / 2 ^ j : ℕ) : ℝ) * (typeIILogScale N) ^ 2) := by + have hH0 : 0 ≤ typeIILogScale N := zero_le_one.trans (one_le_typeIILogScale N) + have hqR : (0 : ℝ) < q := by exact_mod_cast hq + have hMR : (0 : ℝ) < ((2 ^ j : ℕ) : ℝ) := by positivity + have hqlog : 1 + Real.log (2 * (q : ℝ)) ≤ typeIILogScale N := by + unfold typeIILogScale + apply add_le_add le_rfl + exact Real.log_le_log (by positivity) (by exact_mod_cast Nat.mul_le_mul_left 2 hqN) + have hMlog : 1 + Real.log (2 ^ (j + 1) : ℕ) ≤ typeIILogScale N := by + unfold typeIILogScale + apply add_le_add le_rfl + apply Real.log_le_log (by positivity) + rw [pow_succ, Nat.cast_mul, Nat.cast_ofNat] + have hMRN : ((2 ^ j : ℕ) : ℝ) ≤ N := by exact_mod_cast hM + nlinarith + have hTlog := log_nat_le_typeIILogScale N (N / 2 ^ j) (Nat.div_le_self _ _) + have hraw := typeIIBlock_sq_le_raw θ a q hq hcop happrox N U V j + refine hraw.trans ?_ + have hqlog0 : 0 ≤ 1 + Real.log (2 * (q : ℝ)) := by + have h := Real.log_natCast_nonneg (2 * q) + simp only [Nat.cast_mul, Nat.cast_ofNat] at h + linarith + have hMlog0 : 0 ≤ 1 + Real.log (2 ^ (j + 1) : ℕ) := by + linarith [Real.log_natCast_nonneg (2 ^ (j + 1))] + have hTlog0 := Real.log_natCast_nonneg (N / 2 ^ j) + have he : ((2 ^ (j + 1) : ℕ) : ℝ) = 2 * ((2 ^ j : ℕ) : ℝ) := by + rw [pow_succ, Nat.cast_mul, Nat.cast_ofNat] + ring + rw [he] at hMlog hMlog0 ⊢ + gcongr + +/-- Uniform actual Type II block bound, with no cancellation or energy premise. -/ +theorem typeIIBlock_sq_le_uniform + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N U V j : ℕ) (hqN : q ≤ N) (hU : 0 < U) (hV : 0 < V) : + ‖typeIIBlock N U V j (fun k => VaughanBilinear.phase (θ * k))‖ ^ 2 ≤ + 32 * (N : ℝ) * (typeIILogScale N) ^ 6 * + ((N : ℝ) / q + (N : ℝ) / U + (N : ℝ) / V + q) := by + have hH : 0 ≤ typeIILogScale N := zero_le_one.trans (one_le_typeIILogScale N) + by_cases hb : typeIIBlock N U V j (fun k => VaughanBilinear.phase (θ * k)) = 0 + · rw [hb, norm_zero, zero_pow (by decide : 2 ≠ 0)] + positivity + have hs : (VaughanDyadic.shell U N j).Nonempty := by + by_contra he + have he' : VaughanDyadic.shell U N j = ∅ := not_nonempty_iff_eq_empty.mp he + apply hb + simp [typeIIBlock, VaughanDyadic.block, he'] + obtain ⟨m, hm⟩ := hs + have hm' := VaughanDyadic.mem_shell.mp hm + have hM : 2 ^ j ≤ N := hm'.2.2.1.trans hm'.2.1 + have hbase := VaughanDyadic.base_le_div_of_block_ne_zero N U V j + (fun m n => (typeIICoefficient U m : ℂ) * (Λ n : ℂ) * + VaughanBilinear.phase (θ * (m * n : ℕ))) hb + have hMT : (((2 ^ j : ℕ) : ℝ) * ((N / 2 ^ j : ℕ) : ℝ)) ≤ N := by + exact_mod_cast Nat.mul_div_le N (2 ^ j) + have hU2M : (U : ℝ) ≤ 2 * ((2 ^ j : ℕ) : ℝ) := by + have hnat : U ≤ 2 * 2 ^ j := by + have hu := hm'.1 + have hmhi := hm'.2.2.2 + rw [pow_succ] at hmhi + omega + exact_mod_cast hnat + have hTU : ((N / 2 ^ j : ℕ) : ℝ) ≤ 2 * (N : ℝ) / U := by + apply (le_div_iff₀ (by exact_mod_cast hU : (0 : ℝ) < U)).mpr + nlinarith [mul_le_mul_of_nonneg_left hU2M + (Nat.cast_nonneg (N / 2 ^ j) : (0 : ℝ) ≤ (N / 2 ^ j : ℕ))] + have hMV : ((2 ^ j : ℕ) : ℝ) ≤ (N : ℝ) / V := by + apply (le_div_iff₀ (by exact_mod_cast hV : (0 : ℝ) < V)).mpr + have hn : 2 ^ j * V ≤ N := + (Nat.mul_le_mul_left (2 ^ j) (Nat.le_succ V)).trans + ((Nat.le_div_iff_mul_le (Nat.succ_pos V)).mp hbase) + exact_mod_cast hn + exact (typeIIBlock_sq_le_normalized θ a q hq hcop happrox N U V j hqN hM).trans + (TypeIIBlockScalar.block_bound N (2 ^ j : ℕ) (N / 2 ^ j : ℕ) q U V (typeIILogScale N) + (Nat.cast_nonneg N) (by positivity) (Nat.cast_nonneg _) + (by exact_mod_cast hq) (by exact_mod_cast hU) (by exact_mod_cast hV) + (one_le_typeIILogScale N) hMT hTU hMV) + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanEstimate.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanEstimate.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd859108c1aebe0b7afe53491c1dd9c683cbfbc1 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanEstimate.lean @@ -0,0 +1,140 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanOptimized +import OAI.NumberTheory.EgyptianFractions.VaughanTypeINormalized + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius ArithmeticFunction.zeta + +namespace Problem337.Vaughan + +lemma realPhase_eq_bilinear_phase (x : ℝ) : + RealPhase.phase x = VaughanBilinear.phase x := + (VaughanBilinear.phase_eq_geometric_phase x).symm + +lemma optimized_typeI_scales (X q : ℝ) (hX : 1 ≤ X) (hq : 1 ≤ q) + (hqX : q ≤ X) (hpow : 2 ≤ X ^ (2 / 5 : ℝ)) : + X / q + (optimizedCutoff X : ℝ) + q ≤ 4 * approximationEnvelope X q ∧ + X / q + (optimizedCutoff X : ℝ) ^ 2 + q ≤ 4 * approximationEnvelope X q := by + have hs := optimizedCutoff_standard_envelope X q hX hq hqX hpow + have hdiv : 0 ≤ X / Real.sqrt (optimizedCutoff X : ℝ) := by positivity + change _ ≤ 4 * approximationEnvelope X q at hs + constructor <;> nlinarith [Nat.cast_nonneg (optimizedCutoff X) (α := ℝ), + sq_nonneg (optimizedCutoff X : ℝ)] + +/-- An explicit classical Vaughan estimate for the actual von Mangoldt +exponential sum. The only analytic input is a reduced rational approximation; +all Type I and Type II cancellation estimates have been proved above. -/ +theorem vonMangoldt_sum_bound + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N : ℕ) (hqN : q ≤ N) + (hpow : 2 ≤ (N : ℝ) ^ (2 / 5 : ℝ)) : + ‖weightedSum (Finset.Ioc 0 N) (fun k => VaughanBilinear.phase (θ * k)) Λ‖ ≤ + 200 * (typeIILogScale N) ^ 4 * approximationEnvelope N q := by + let U := optimizedCutoff (N : ℝ) + let w : ℕ → ℂ := fun k => VaughanBilinear.phase (θ * k) + let H := typeIILogScale N + let E := approximationEnvelope (N : ℝ) q + have hN : 1 ≤ N := hq.trans_le hqN + have hNr : (1 : ℝ) ≤ N := by exact_mod_cast hN + have hqr : (1 : ℝ) ≤ q := by exact_mod_cast hq + have hqNr : (q : ℝ) ≤ N := by exact_mod_cast hqN + have hH : 1 ≤ H := one_le_typeIILogScale N + have hH0 : 0 ≤ H := zero_le_one.trans hH + have hE : 0 ≤ E := approximationEnvelope_nonneg N q (Nat.cast_nonneg N) + have hH14 : H ≤ H ^ 4 := by + simpa using (pow_le_pow_right₀ hH (show 1 ≤ 4 by omega)) + have hH24 : H ^ 2 ≤ H ^ 4 := pow_le_pow_right₀ hH (by omega) + have hcost := optimized_typeI_scales N q hNr hqr hqNr hpow + have hfirst := VaughanHyperbolic.first_typeI_normalized_bound θ a q hq hcop happrox + N U hN hqN + have hsecond := VaughanHyperbolic.second_typeI_normalized_bound θ a q hq hcop happrox + N U U hN hqN + simp only [realPhase_eq_bilinear_phase] at hfirst hsecond + have h1 : ‖weightedSum (Finset.Ioc 0 N) w + (shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log)‖ ≤ 64 * H ^ 4 * E := by + calc + _ ≤ 16 * H ^ 2 * ((N : ℝ) / q + U + q) := hfirst + _ ≤ 16 * H ^ 2 * (4 * E) := mul_le_mul_of_nonneg_left hcost.1 (by positivity) + _ ≤ 64 * H ^ 4 * E := by nlinarith [mul_le_mul_of_nonneg_right hH24 hE] + have h2 : ‖weightedSum (Finset.Ioc 0 N) w (typeICoefficient U U * ζ)‖ ≤ + 32 * H ^ 4 * E := by + calc + _ ≤ 8 * H ^ 2 * ((N : ℝ) / q + (U : ℝ) ^ 2 + q) := by + simpa only [H, typeIILogScale, w, pow_two] using hsecond + _ ≤ 8 * H ^ 2 * (4 * E) := mul_le_mul_of_nonneg_left hcost.2 (by positivity) + _ ≤ 32 * H ^ 4 * E := by nlinarith [mul_le_mul_of_nonneg_right hH24 hE] + have h0 : ‖weightedSum (Finset.Ioc 0 N) w (shortPart U Λ)‖ ≤ H ^ 4 * E := by + have hlog : Real.log N ≤ H ^ 4 := (log_nat_le_typeIILogScale N N le_rfl).trans hH14 + have hpower : (N : ℝ) ^ (4 / 5 : ℝ) ≤ E := by + dsimp [E, approximationEnvelope] + have hd : 0 ≤ (N : ℝ) / Real.sqrt q := by positivity + linarith [Real.sqrt_nonneg ((N : ℝ) * q)] + calc + _ ≤ (U : ℝ) * Real.log U := norm_short_vonMangoldt_sum_le N U w (by + intro n hn + simp [w]) + _ ≤ (N : ℝ) ^ (4 / 5 : ℝ) * Real.log N := optimizedCutoff_log_le N hNr hpow + _ ≤ E * H ^ 4 := mul_le_mul hpower hlog (Real.log_natCast_nonneg N) hE + _ = _ := by ring + have hII : ‖weightedSum (Finset.Ioc 0 N) w (typeIICoefficient U * longPart U Λ)‖ ≤ + 54 * H ^ 4 * E := optimized_typeII_bound θ a q hq hcop happrox N hqN hpow + change ‖weightedSum (Finset.Ioc 0 N) w Λ‖ ≤ 200 * H ^ 4 * E + rw [weighted_identity (Finset.Ioc 0 N) w U U] + calc + _ ≤ (‖weightedSum (Finset.Ioc 0 N) w (shortPart U Λ)‖ + + ‖weightedSum (Finset.Ioc 0 N) w + (shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log)‖) + + ‖weightedSum (Finset.Ioc 0 N) w (typeICoefficient U U * ζ)‖ + + ‖weightedSum (Finset.Ioc 0 N) w (typeIICoefficient U * longPart U Λ)‖ := by + apply (norm_add_le _ _).trans + apply add_le_add _ le_rfl + apply (norm_sub_le _ _).trans + exact add_le_add (norm_add_le _ _) le_rfl + _ ≤ _ := by nlinarith [mul_nonneg (pow_nonneg hH0 4) hE] + +/-- The ordinary logarithmic form of the classical Vaughan estimate. -/ +theorem vonMangoldt_sum_log_bound + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N : ℕ) (hqN : q ≤ N) + (hpow : 2 ≤ (N : ℝ) ^ (2 / 5 : ℝ)) (hlog : 1 ≤ Real.log N) : + ‖weightedSum (Finset.Ioc 0 N) (fun k => VaughanBilinear.phase (θ * k)) Λ‖ ≤ + 16200 * (Real.log N) ^ 4 * approximationEnvelope N q := by + have hNr : (0 : ℝ) < N := by exact_mod_cast hq.trans_le hqN + have hH : typeIILogScale N ≤ 3 * Real.log N := by + unfold typeIILogScale + rw [Real.log_mul (by norm_num) hNr.ne'] + linarith [Real.log_two_lt_d9] + have hH0 : 0 ≤ typeIILogScale N := zero_le_one.trans (one_le_typeIILogScale N) + have hE := approximationEnvelope_nonneg N q (Nat.cast_nonneg N) + refine (vonMangoldt_sum_bound θ a q hq hcop happrox N hqN hpow).trans ?_ + calc + _ ≤ 200 * (3 * Real.log N) ^ 4 * approximationEnvelope N q := by gcongr + _ = _ := by ring + +open Filter in +/-- The estimate holds uniformly in every reduced approximation once the +summation length is large, with an absolute explicit constant. -/ +theorem eventually_vonMangoldt_sum_log_bound : + ∀ᶠ N : ℕ in atTop, ∀ (θ : ℝ) (a : ℤ) (q : ℕ), 0 < q → + IsCoprime a (q : ℤ) → |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2 → q ≤ N → + ‖weightedSum (Finset.Ioc 0 N) (fun k => VaughanBilinear.phase (θ * k)) Λ‖ ≤ + 16200 * (Real.log N) ^ 4 * approximationEnvelope N q := by + have hlog : ∀ᶠ N : ℕ in atTop, 1 ≤ Real.log (N : ℝ) := + (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).eventually + (eventually_ge_atTop (1 : ℝ)) + have hpow : ∀ᶠ N : ℕ in atTop, 2 ≤ (N : ℝ) ^ (2 / 5 : ℝ) := + ((tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 2 / 5)).comp + tendsto_natCast_atTop_atTop).eventually (eventually_ge_atTop (2 : ℝ)) + filter_upwards [hlog, hpow] with N hlog hpow + intro θ a q hq hcop happrox hqN + exact vonMangoldt_sum_log_bound θ a q hq hcop happrox N hqN hpow hlog + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanHyperbola.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanHyperbola.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6abb33b9340d681bcd3932de72504e0602881b3 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanHyperbola.lean @@ -0,0 +1,144 @@ +import Mathlib.NumberTheory.ArithmeticFunction.VonMangoldt +import Mathlib.Basic.Complex.Basic + +namespace OAI +/-! +# Finite hyperbola reindexing for Vaughan sums + +An exact finite change of variables from `n = a*b` to pairs of positive +integers below a hyperbola. The arbitrary weight version is suitable for +both rational additive characters and real-frequency exponential sums. +-/ + +noncomputable section +open scoped BigOperators + +namespace Problem337.Vaughan + +/-- Positive lattice points below the multiplicative hyperbola `a*b ≤ N`. -/ +def hyperbola (N : ℕ) : Finset (ℕ × ℕ) := + ((Finset.Icc 1 N).product (Finset.Icc 1 N)).filter (fun ab => ab.1 * ab.2 ≤ N) + +@[simp] lemma mem_hyperbola {N a b : ℕ} : + (a, b) ∈ hyperbola N ↔ 1 ≤ a ∧ 1 ≤ b ∧ a * b ≤ N := by + change ((a, b) ∈ ((Finset.Icc 1 N).product (Finset.Icc 1 N)).filter + (fun ab => ab.1 * ab.2 ≤ N)) ↔ _ + rw [Finset.mem_filter] + have hm : (a, b) ∈ (Finset.Icc 1 N).product (Finset.Icc 1 N) ↔ + a ∈ Finset.Icc 1 N ∧ b ∈ Finset.Icc 1 N := Finset.mem_product + rw [hm] + simp only [Finset.mem_Icc] + constructor + · rintro ⟨⟨⟨ha, _⟩, ⟨hb, _⟩⟩, hp⟩ + exact ⟨ha, hb, hp⟩ + · rintro ⟨ha, hb, hp⟩ + have haN : a ≤ N := (Nat.le_mul_of_pos_right a (by omega : 0 < b)).trans hp + have hbN : b ≤ N := (Nat.le_mul_of_pos_left b (by omega : 0 < a)).trans hp + exact ⟨⟨⟨ha, haN⟩, ⟨hb, hbN⟩⟩, hp⟩ + +/-- The divisor-antidiagonal fibers partition the positive hyperbola exactly. +The summand may also depend on the product index `n`. -/ +theorem sum_divisor_fibers {A : Type*} [AddCommMonoid A] + (N : ℕ) (F : ℕ → ℕ → ℕ → A) : + (∑ n ∈ Finset.Icc 1 N, ∑ ab ∈ n.divisorsAntidiagonal, F n ab.1 ab.2) = + ∑ ab ∈ hyperbola N, F (ab.1 * ab.2) ab.1 ab.2 := by + rw [Finset.sum_sigma'] + apply Finset.sum_nbij' + (fun x : Sigma (fun _n : ℕ => ℕ × ℕ) => x.2) + (fun ab : ℕ × ℕ => (⟨ab.1 * ab.2, ab⟩ : Sigma (fun _n : ℕ => ℕ × ℕ))) + · rintro ⟨n, a, b⟩ hx + obtain ⟨hn, hab⟩ := Finset.mem_sigma.mp hx + obtain ⟨hn1, hnN⟩ := Finset.mem_Icc.mp hn + obtain ⟨hprod, hn0⟩ := Nat.mem_divisorsAntidiagonal.mp hab + apply mem_hyperbola.mpr + change a * b = n at hprod + change n ≠ 0 at hn0 + have hab0 : a * b ≠ 0 := by rw [hprod]; exact hn0 + exact ⟨Nat.pos_of_ne_zero (left_ne_zero_of_mul hab0), + Nat.pos_of_ne_zero (right_ne_zero_of_mul hab0), by rw [hprod]; exact hnN⟩ + · rintro ⟨a, b⟩ hab + obtain ⟨ha, hb, hp⟩ := mem_hyperbola.mp hab + apply Finset.mem_sigma.mpr + constructor + · exact Finset.mem_Icc.mpr ⟨Nat.mul_pos ha hb, hp⟩ + · exact Nat.mem_divisorsAntidiagonal.mpr ⟨rfl, Nat.ne_of_gt (Nat.mul_pos ha hb)⟩ + · rintro ⟨n, a, b⟩ hx + have hprod := (Nat.mem_divisorsAntidiagonal.mp (Finset.mem_sigma.mp hx).2).1 + change (⟨a * b, (a, b)⟩ : Sigma (fun _n : ℕ => ℕ × ℕ)) = ⟨n, (a, b)⟩ + rw [hprod] + · intro ab hab + rfl + · rintro ⟨n, a, b⟩ hx + have hprod := (Nat.mem_divisorsAntidiagonal.mp (Finset.mem_sigma.mp hx).2).1 + change F n a b = F (a * b) a b + rw [hprod] + +/-- The hyperbola sum as ordinary nested integer intervals. The inner endpoint +is the natural-number quotient `N / a`; the outer interval excludes zero. -/ +theorem sum_hyperbola_eq_nested {A : Type*} [AddCommMonoid A] + (N : ℕ) (F : ℕ → ℕ → A) : + (∑ ab ∈ hyperbola N, F ab.1 ab.2) = + ∑ a ∈ Finset.Icc 1 N, ∑ b ∈ Finset.Icc 1 (N / a), F a b := by + rw [Finset.sum_sigma'] + apply Finset.sum_nbij' + (fun ab : ℕ × ℕ => (⟨ab.1, ab.2⟩ : Sigma (fun _a : ℕ => ℕ))) + (fun x : Sigma (fun _a : ℕ => ℕ) => (x.1, x.2)) + · rintro ⟨a, b⟩ hab + obtain ⟨ha, hb, hp⟩ := mem_hyperbola.mp hab + apply Finset.mem_sigma.mpr + constructor + · exact Finset.mem_Icc.mpr ⟨ha, + (Nat.le_mul_of_pos_right a (by omega : 0 < b)).trans hp⟩ + · apply Finset.mem_Icc.mpr + exact ⟨hb, (Nat.le_div_iff_mul_le (by omega : 0 < a)).mpr (by simpa [mul_comm] using hp)⟩ + · rintro ⟨a, b⟩ hx + obtain ⟨ha, hb⟩ := Finset.mem_sigma.mp hx + obtain ⟨ha1, haN⟩ := Finset.mem_Icc.mp ha + obtain ⟨hb1, hbN⟩ := Finset.mem_Icc.mp hb + change 1 ≤ a at ha1 + change 1 ≤ b at hb1 + change b ≤ N / a at hbN + apply mem_hyperbola.mpr + refine ⟨ha1, hb1, ?_⟩ + have hp := (Nat.le_div_iff_mul_le (by omega : 0 < a)).mp hbN + simpa [mul_comm] using hp + · intro ab hab + rfl + · intro x hx + rfl + · intro ab hab + rfl + +/-- Exact finite convolution reindexing with an arbitrary multiplicative +weight. No convergence or support hypotheses on the weight are needed. -/ +theorem sum_convolution_hyperbola {R : Type*} [Semiring R] + (N : ℕ) (f g : ArithmeticFunction R) (w : ℕ → R) : + (∑ n ∈ Finset.Icc 1 N, (f * g) n * w n) = + ∑ ab ∈ hyperbola N, (f ab.1 * g ab.2) * w (ab.1 * ab.2) := by + simp_rw [ArithmeticFunction.mul_apply, Finset.sum_mul] + exact sum_divisor_fibers N (fun n a b => (f a * g b) * w n) + +/-- Real arithmetic coefficients with complex weights, the combination used +for the von-Mangoldt exponential sum. -/ +theorem sum_real_convolution_hyperbola + (N : ℕ) (f g : ArithmeticFunction ℝ) (w : ℕ → ℂ) : + (∑ n ∈ Finset.Icc 1 N, ((f * g) n : ℂ) * w n) = + ∑ ab ∈ hyperbola N, ((f ab.1 * g ab.2 : ℝ) : ℂ) * w (ab.1 * ab.2) := by + simp_rw [ArithmeticFunction.mul_apply, Complex.ofReal_sum, Finset.sum_mul] + exact sum_divisor_fibers N (fun n a b => ((f a * g b : ℝ) : ℂ) * w n) + +/-- The traditional nested-interval form of the finite convolution identity. -/ +theorem sum_real_convolution_eq_nested + (N : ℕ) (f g : ArithmeticFunction ℝ) (w : ℕ → ℂ) : + (∑ n ∈ Finset.Icc 1 N, ((f * g) n : ℂ) * w n) = + ∑ a ∈ Finset.Icc 1 N, ∑ b ∈ Finset.Icc 1 (N / a), + ((f a * g b : ℝ) : ℂ) * w (a * b) := by + rw [sum_real_convolution_hyperbola] + exact sum_hyperbola_eq_nested (A := ℂ) N + (fun a b => ((f a * g b : ℝ) : ℂ) * w (a * b)) + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanHyperbolicNearRational.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanHyperbolicNearRational.lean new file mode 100644 index 0000000000000000000000000000000000000000..34a4f46eddfdcecabaac76a260c65eb3a86d4cb8 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanHyperbolicNearRational.lean @@ -0,0 +1,55 @@ +import OAI.NumberTheory.EgyptianFractions.HyperbolaTypeII +import OAI.NumberTheory.EgyptianFractions.VaughanNearRational + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.VaughanBilinear + +/-- A full Type-II estimate for the actual hyperbolic region `m*n ≤ X`. +The rational approximation is the only analytic input: support intersection, +geometric cancellation, harmonic spacing, and coefficient-energy estimates +are all supplied by checked lemmas. Empty row and column intervals are allowed. -/ +theorem near_rational_hyperbolic_bilinear_sq_le + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (X L U V N : ℕ) (t : Finset ℕ) + (ht : t ⊆ Finset.Ico V (V + N)) (hpos : ∀ n ∈ t, 0 < n) + (c b : ℕ → ℂ) : + ‖∑ m ∈ Finset.Icc L U, c m * ∑ n ∈ t, + b n * HyperbolaCorrelation.column θ X n m‖ ^ 2 ≤ + (∑ m ∈ Finset.Icc L U, ‖c m‖ ^ 2) * + ((2 * (N : ℝ) / q + 1) * + (2 * ((U + 1 - L : ℕ) : ℝ) + + 4 * (q : ℝ) * (1 + Real.log (2 * (q : ℝ))))) * + (∑ n ∈ t, ‖b n‖ ^ 2) := by + apply norm_bilinear_sq_le_energy + intro n hn + calc + _ ≤ ∑ k ∈ t, geometricBound (U + 1 - L) (θ * ((n : ℝ) - k)) := by + apply Finset.sum_le_sum + intro k hk + exact HyperbolaCorrelation.column_correlation_le θ X L U n k + ((hpos n hn).trans_le (le_max_left _ _)) + _ ≤ _ := by + simpa only [Int.cast_sub, Int.cast_natCast] using + (sum_geometricBound_difference_le θ a q hq hcop happrox + (U + 1 - L) t (fun k : ℕ => (k : ℤ)) (V : ℤ) N + (by + intro k hk + obtain ⟨hl, hu⟩ := Finset.mem_Ico.mp (ht hk) + apply Finset.mem_Ico.mpr + constructor <;> exact_mod_cast (by assumption)) + (by + intro i hi j hj hij + dsimp at hij + exact_mod_cast hij) + (n : ℤ)) + +end Problem337.VaughanBilinear + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanIdentity.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d5ef57f6ca241e52a2dc3a420638337b2a0a258 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanIdentity.lean @@ -0,0 +1,180 @@ +import Mathlib.NumberTheory.ArithmeticFunction.VonMangoldt + +namespace OAI +/-! +# Vaughan's identity with finite cutoffs + +This file supplies an unconditional algebraic input to the analytic three-prime +route. Multiplication of arithmetic functions below is Dirichlet convolution. +No estimate for exponential sums over primes is assumed or asserted here. +-/ + +noncomputable section + +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius + ArithmeticFunction.zeta + +namespace Problem337.Vaughan + +/-- The part of an arithmetic function supported on integers at most `U`. -/ +def shortPart {R : Type*} [Zero R] (U : ℕ) (f : ArithmeticFunction R) : + ArithmeticFunction R := + ⟨fun n => if n ≤ U then f n else 0, by simp⟩ + +/-- The complementary part, supported on integers strictly above `U`. -/ +def longPart {R : Type*} [Zero R] (U : ℕ) (f : ArithmeticFunction R) : + ArithmeticFunction R := + ⟨fun n => if U < n then f n else 0, by simp⟩ + +@[simp] lemma shortPart_apply {R : Type*} [Zero R] + (U : ℕ) (f : ArithmeticFunction R) (n : ℕ) : + shortPart U f n = if n ≤ U then f n else 0 := rfl + +@[simp] lemma longPart_apply {R : Type*} [Zero R] + (U : ℕ) (f : ArithmeticFunction R) (n : ℕ) : + longPart U f n = if U < n then f n else 0 := rfl + +lemma shortPart_add_longPart {R : Type*} [AddMonoid R] + (U : ℕ) (f : ArithmeticFunction R) : shortPart U f + longPart U f = f := by + ext n + by_cases hn : n ≤ U <;> simp [hn, Nat.not_lt.mpr, Nat.lt_of_not_ge] + +lemma longPart_eq_sub_shortPart {R : Type*} [AddCommGroup R] + (U : ℕ) (f : ArithmeticFunction R) : longPart U f = f - shortPart U f := by + have h := shortPart_add_longPart U f + exact eq_sub_iff_add_eq.mpr (by simpa only [add_comm] using h) + +/-- Vaughan's four-term identity, valid also at zero and for zero cutoffs. +The first convolution is Type I; the second has a coefficient supported on +`[1,U*V]`; the last is the long-long Type II convolution. -/ +theorem vonMangoldt_identity (U V : ℕ) : + ArithmeticFunction.vonMangoldt = + shortPart V ArithmeticFunction.vonMangoldt + + shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log - + (shortPart U (μ : ArithmeticFunction ℝ) * + shortPart V ArithmeticFunction.vonMangoldt) * (ζ : ArithmeticFunction ℝ) + + (longPart U (μ : ArithmeticFunction ℝ) * (ζ : ArithmeticFunction ℝ)) * + longPart V ArithmeticFunction.vonMangoldt := by + rw [longPart_eq_sub_shortPart, longPart_eq_sub_shortPart] + have hμ : (μ : ArithmeticFunction ℝ) * (ζ : ArithmeticFunction ℝ) = 1 := + ArithmeticFunction.coe_moebius_mul_coe_zeta + have hΛ : (ζ : ArithmeticFunction ℝ) * ArithmeticFunction.vonMangoldt = + ArithmeticFunction.log := ArithmeticFunction.zeta_mul_vonMangoldt + calc + ArithmeticFunction.vonMangoldt = + ((μ : ArithmeticFunction ℝ) * (ζ : ArithmeticFunction ℝ)) * + ArithmeticFunction.vonMangoldt := by rw [hμ, one_mul] + _ = _ := by + rw [← hΛ] + have hshort : ((μ : ArithmeticFunction ℝ) * (ζ : ArithmeticFunction ℝ)) * + shortPart V ArithmeticFunction.vonMangoldt = + shortPart V ArithmeticFunction.vonMangoldt := by rw [hμ, one_mul] + linear_combination hshort + +/-- A convolution of two short parts has the expected product support. -/ +lemma shortPart_mul_eq_zero_of_lt {R : Type*} [Semiring R] + (U V n : ℕ) (f g : ArithmeticFunction R) (hn : U * V < n) : + (shortPart U f * shortPart V g) n = 0 := by + rw [ArithmeticFunction.mul_apply] + apply Finset.sum_eq_zero + intro ab hab + have habn := (Nat.mem_divisorsAntidiagonal.mp hab).1 + by_cases ha : ab.1 ≤ U + · have hb : ¬ ab.2 ≤ V := by + intro hb + have hm := Nat.mul_le_mul ha hb + rw [habn] at hm + omega + simp [ha, hb] + · simp [ha] + +/-- Convolving a long part cannot create a smaller positive index. -/ +lemma longPart_mul_eq_zero_of_le {R : Type*} [Semiring R] + (U n : ℕ) (f g : ArithmeticFunction R) (hn : n ≤ U) : + (longPart U f * g) n = 0 := by + rw [ArithmeticFunction.mul_apply] + apply Finset.sum_eq_zero + intro ab hab + obtain ⟨hprod, hn0⟩ := Nat.mem_divisorsAntidiagonal.mp hab + have ha : ab.1 ≤ n := Nat.le_of_dvd (Nat.pos_of_ne_zero hn0) ⟨ab.2, hprod.symm⟩ + have hnot : ¬ U < ab.1 := by omega + simp [hnot] + +lemma abs_shortPart_le (U : ℕ) (f : ArithmeticFunction ℝ) (n : ℕ) : + |shortPart U f n| ≤ |f n| := by + by_cases hn : n ≤ U <;> simp [hn, abs_nonneg] + +lemma abs_longPart_le (U : ℕ) (f : ArithmeticFunction ℝ) (n : ℕ) : + |longPart U f n| ≤ |f n| := by + by_cases hn : U < n <;> simp [hn, abs_nonneg] + +lemma abs_real_moebius_le_one (n : ℕ) : + |(μ : ArithmeticFunction ℝ) n| ≤ 1 := by + change |((ArithmeticFunction.moebius n : ℤ) : ℝ)| ≤ 1 + exact_mod_cast (ArithmeticFunction.abs_moebius_le_one (n := n)) + +/-- The short convolution coefficient appearing in Type I sums. -/ +def typeICoefficient (U V : ℕ) : ArithmeticFunction ℝ := + shortPart U (μ : ArithmeticFunction ℝ) * shortPart V ArithmeticFunction.vonMangoldt + +/-- The coefficient appearing in the long-long Type II sum. -/ +def typeIICoefficient (U : ℕ) : ArithmeticFunction ℝ := + longPart U (μ : ArithmeticFunction ℝ) * (ζ : ArithmeticFunction ℝ) + +lemma typeICoefficient_eq_zero (U V n : ℕ) (hn : U * V < n) : + typeICoefficient U V n = 0 := shortPart_mul_eq_zero_of_lt U V n _ _ hn + +lemma typeIICoefficient_eq_zero (U n : ℕ) (hn : n ≤ U) : + typeIICoefficient U n = 0 := longPart_mul_eq_zero_of_le U n _ _ hn + +/-- The Type I coefficient costs only a logarithm, not a divisor function. -/ +lemma abs_typeICoefficient_le_log (U V n : ℕ) : + |typeICoefficient U V n| ≤ Real.log n := by + unfold typeICoefficient + rw [ArithmeticFunction.mul_apply] + calc + _ ≤ ∑ ab ∈ n.divisorsAntidiagonal, + |shortPart U (μ : ArithmeticFunction ℝ) ab.1 * + shortPart V ArithmeticFunction.vonMangoldt ab.2| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ ab ∈ n.divisorsAntidiagonal, ArithmeticFunction.vonMangoldt ab.2 := by + apply Finset.sum_le_sum + intro ab hab + rw [abs_mul] + have hμ := (abs_shortPart_le U (μ : ArithmeticFunction ℝ) ab.1).trans + (abs_real_moebius_le_one ab.1) + have hΛ := abs_shortPart_le V ArithmeticFunction.vonMangoldt ab.2 + rw [abs_of_nonneg ArithmeticFunction.vonMangoldt_nonneg] at hΛ + calc + _ ≤ 1 * ArithmeticFunction.vonMangoldt ab.2 := + mul_le_mul hμ hΛ (abs_nonneg _) zero_le_one + _ = _ := one_mul _ + _ = Real.log n := by + rw [Nat.sum_divisorsAntidiagonal' (fun _ b => ArithmeticFunction.vonMangoldt b)] + exact ArithmeticFunction.vonMangoldt_sum + +lemma typeIICoefficient_apply (U n : ℕ) : + typeIICoefficient U n = + ∑ d ∈ n.divisors.filter (U < ·), (μ : ArithmeticFunction ℝ) d := by + rw [typeIICoefficient, ArithmeticFunction.coe_mul_zeta_apply] + simp only [longPart_apply, Finset.sum_filter] + +/-- A uniform elementary coefficient bound for the Type II sum. -/ +lemma abs_typeIICoefficient_le_divisors_card (U n : ℕ) : + |typeIICoefficient U n| ≤ (n.divisors.card : ℝ) := by + rw [typeIICoefficient, ArithmeticFunction.coe_mul_zeta_apply] + calc + _ ≤ ∑ d ∈ n.divisors, |longPart U (μ : ArithmeticFunction ℝ) d| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _d ∈ n.divisors, (1 : ℝ) := by + apply Finset.sum_le_sum + intro d hd + exact (abs_longPart_le U (μ : ArithmeticFunction ℝ) d).trans + (abs_real_moebius_le_one d) + _ = _ := by simp + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanNearRational.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanNearRational.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5f3f54bff64b35437c1e75bfd0c7d4ec9dc80a3 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanNearRational.lean @@ -0,0 +1,269 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanBilinear +import OAI.NumberTheory.EgyptianFractions.GeometricCharacterBound +import OAI.NumberTheory.EgyptianFractions.RationalPhaseSpacing + +namespace OAI +noncomputable section +open scoped BigOperators + +namespace Problem337.VaughanBilinear + +theorem phase_int (n : ℤ) : phase n = 1 := by + rw [phase, Real.fourierChar_apply] + have he : (↑(2 * Real.pi * (n : ℝ)) : ℂ) * Complex.I = + (n : ℂ) * (2 * (Real.pi : ℂ) * Complex.I) := by + push_cast + ring + rw [he, Complex.exp_int_mul_two_pi_mul_I] + +theorem phase_fract (x : ℝ) : phase (Int.fract x) = phase x := by + rw [Int.fract, ← phase_mul_conj, phase_int] + simp + +theorem phase_eq_geometric_phase (x : ℝ) : + phase x = Complex.exp (Complex.I * (2 * Real.pi * x : ℝ)) := by + rw [phase, Real.fourierChar_apply] + congr 1 + ring + +/-- The usual truncated reciprocal-distance majorant for a real geometric +sum. Integer phases use the length cap, never a spurious zero reciprocal. -/ +theorem phase_sum_le_truncatedInv (x : ℝ) (M : ℕ) : + ‖∑ m ∈ Finset.range M, phase (x * m)‖ ≤ + RationalPhaseSpacing.truncatedInv M (RationalPhaseSpacing.intDistance x) := by + have hcap : ‖∑ m ∈ Finset.range M, phase (x * m)‖ ≤ (M : ℝ) := by + calc + _ ≤ ∑ m ∈ Finset.range M, ‖phase (x * m)‖ := norm_sum_le _ _ + _ = _ := by simp + by_cases hx : RationalPhaseSpacing.intDistance x = 0 + · simpa only [RationalPhaseSpacing.truncatedInv, ite_eq_left hx] using hcap + have hpos : 0 < RationalPhaseSpacing.intDistance x := + lt_of_le_of_ne (RationalPhaseSpacing.intDistance_nonneg x) (Ne.symm hx) + rw [RationalPhaseSpacing.truncatedInv, ite_eq_right hx] + refine le_min hcap ?_ + have hlow : RationalPhaseSpacing.intDistance x ≤ Int.fract x := min_le_left _ _ + have hhigh : Int.fract x ≤ 1 - RationalPhaseSpacing.intDistance x := by + have h := min_le_right (Int.fract x) (1 - Int.fract x) + change RationalPhaseSpacing.intDistance x ≤ 1 - Int.fract x at h + linarith + have hgeom := norm_geometric_phase_sum_le_middle hpos hlow hhigh M + have heq : (∑ m ∈ Finset.range M, phase (x * m)) = + ∑ m ∈ Finset.range M, + Complex.exp (Complex.I * (2 * Real.pi * Int.fract x : ℝ)) ^ m := by + apply Finset.sum_congr rfl + intro m hm + rw [phase_nat_mul, ← phase_fract x, phase_eq_geometric_phase] + rw [heq] + exact hgeom.trans (one_div_le_one_div_of_le hpos (by linarith)) + +/-- Rational approximation provides an actual Type-II correlation row bound +on every short block of integer columns, uniformly in the chosen row. -/ +theorem near_rational_correlation_row_le + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (M : ℕ) (t : Finset ℤ) + (hspan : ∀ n ∈ t, ∀ k ∈ t, 2 * |n - k| ≤ (q : ℤ)) (n : ℤ) : + (∑ k ∈ t, ‖∑ m ∈ Finset.range M, + phase (θ * m * n) * (starRingEnd ℂ) (phase (θ * m * k))‖) ≤ + 2 * (M : ℝ) + 4 * (q : ℝ) * (1 + Real.log (2 * (q : ℝ))) := by + classical + let A := t.image (fun k => n - k) + have hA : ∀ j ∈ A, ∀ l ∈ A, 2 * |j - l| ≤ (q : ℤ) := by + intro j hj l hl + obtain ⟨k, hk, rfl⟩ := Finset.mem_image.mp hj + obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hl + have heq : (n - k) - (n - i) = i - k := by omega + rw [heq] + exact hspan i hi k hk + have hsum := RationalPhaseSpacing.sum_truncatedInv_intDistance_le + θ a q hq hcop happrox A hA (M : ℝ) (Nat.cast_nonneg M) + have hcorr (k : ℤ) : (∑ m ∈ Finset.range M, + phase (θ * m * n) * (starRingEnd ℂ) (phase (θ * m * k))) = + ∑ m ∈ Finset.range M, phase ((θ * ((n - k : ℤ) : ℝ)) * m) := by + apply Finset.sum_congr rfl + intro m hm + rw [phase_mul_conj] + congr 1 + push_cast + ring + calc + _ ≤ ∑ k ∈ t, RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * ((n - k : ℤ) : ℝ))) := by + apply Finset.sum_le_sum + intro k hk + rw [hcorr] + exact phase_sum_le_truncatedInv _ M + _ = ∑ j ∈ A, RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * j)) := by + rw [Finset.sum_image] + intro k hk i hi heq + dsimp at heq + omega + _ ≤ _ := hsum + +/-- A proved near-rational Type-II estimate with both coefficient energies. +The only number-theoretic hypothesis is the stated reduced approximation; +all correlation/spacing/cancellation estimates are discharged. -/ +theorem near_rational_bilinear_sq_le + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (M : ℕ) (t : Finset ℤ) + (hspan : ∀ n ∈ t, ∀ k ∈ t, 2 * |n - k| ≤ (q : ℤ)) + (c : ℕ → ℂ) (b : ℤ → ℂ) : + ‖∑ m ∈ Finset.range M, c m * ∑ n ∈ t, b n * phase (θ * m * n)‖ ^ 2 ≤ + (∑ m ∈ Finset.range M, ‖c m‖ ^ 2) * + (2 * (M : ℝ) + 4 * (q : ℝ) * (1 + Real.log (2 * (q : ℝ)))) * + (∑ n ∈ t, ‖b n‖ ^ 2) := by + apply norm_bilinear_sq_le_energy + intro n hn + exact near_rational_correlation_row_le θ a q hq hcop happrox M t hspan n + +/-- Actual near-rational row cancellation on an arbitrary integer interval, +also valid for any subset of that interval. -/ +theorem near_rational_interval_correlation_row_le + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (M : ℕ) (t : Finset ℤ) (L : ℤ) (N : ℕ) + (ht : t ⊆ Finset.Ico L (L + N)) (n : ℤ) : + (∑ k ∈ t, ‖∑ m ∈ Finset.range M, + phase (θ * m * n) * (starRingEnd ℂ) (phase (θ * m * k))‖) ≤ + (2 * (N : ℝ) / q + 1) * + (2 * (M : ℝ) + 4 * (q : ℝ) * (1 + Real.log (2 * (q : ℝ)))) := by + classical + let A := t.image (fun k => n - k) + let L' : ℤ := n - L - N + 1 + have hA : A ⊆ Finset.Ico L' (L' + N) := by + intro j hj + obtain ⟨k, hk, rfl⟩ := Finset.mem_image.mp hj + have hk' := Finset.mem_Ico.mp (ht hk) + apply Finset.mem_Ico.mpr + dsimp [L'] + omega + calc + _ ≤ ∑ k ∈ t, RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * ((n - k : ℤ) : ℝ))) := by + apply Finset.sum_le_sum + intro k hk + have heq : (∑ m ∈ Finset.range M, + phase (θ * m * n) * (starRingEnd ℂ) (phase (θ * m * k))) = + ∑ m ∈ Finset.range M, phase ((θ * ((n - k : ℤ) : ℝ)) * m) := by + apply Finset.sum_congr rfl + intro m hm + rw [phase_mul_conj] + congr 1 + push_cast + ring + rw [heq] + exact phase_sum_le_truncatedInv _ M + _ = ∑ j ∈ A, RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * j)) := by + rw [Finset.sum_image] + intro k hk i hi heq + dsimp at heq + omega + _ ≤ ∑ j ∈ Finset.Ico L' (L' + N), RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * j)) := + Finset.sum_le_sum_of_subset_of_nonneg hA (fun _ _ _ => + RationalPhaseSpacing.truncatedInv_nonneg (Nat.cast_nonneg M) + (RationalPhaseSpacing.intDistance_nonneg _)) + _ ≤ _ := RationalPhaseSpacing.sum_truncatedInv_intDistance_interval_le + θ a q hq hcop happrox L' N M (Nat.cast_nonneg M) + +/-- Full rectangular Type-II estimate from a reduced rational approximation. +No spacing, correlation, or equidistribution estimate remains as a premise. -/ +theorem near_rational_interval_bilinear_sq_le + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (M : ℕ) (t : Finset ℤ) (L : ℤ) (N : ℕ) + (ht : t ⊆ Finset.Ico L (L + N)) (c : ℕ → ℂ) (b : ℤ → ℂ) : + ‖∑ m ∈ Finset.range M, c m * ∑ n ∈ t, b n * phase (θ * m * n)‖ ^ 2 ≤ + (∑ m ∈ Finset.range M, ‖c m‖ ^ 2) * + ((2 * (N : ℝ) / q + 1) * + (2 * (M : ℝ) + 4 * (q : ℝ) * (1 + Real.log (2 * (q : ℝ))))) * + (∑ n ∈ t, ‖b n‖ ^ 2) := by + apply norm_bilinear_sq_le_energy + intro n hn + exact near_rational_interval_correlation_row_le θ a q hq hcop happrox M t L N ht n + +/-- The explicit geometric majorant itself is bounded by the truncated +reciprocal distance. This also allows variable inner interval lengths. -/ +theorem geometricBound_le_truncatedInv (M : ℕ) (x : ℝ) : + geometricBound M x ≤ + RationalPhaseSpacing.truncatedInv M (RationalPhaseSpacing.intDistance x) := by + by_cases hd : RationalPhaseSpacing.intDistance x = 0 + · rw [RationalPhaseSpacing.truncatedInv, ite_eq_left hd] + unfold geometricBound + split_ifs + · exact le_rfl + · exact min_le_left _ _ + have hdpos : 0 < RationalPhaseSpacing.intDistance x := + lt_of_le_of_ne (RationalPhaseSpacing.intDistance_nonneg x) (Ne.symm hd) + have hlow : RationalPhaseSpacing.intDistance x ≤ Int.fract x := min_le_left _ _ + have hhigh : Int.fract x ≤ 1 - RationalPhaseSpacing.intDistance x := by + have h := min_le_right (Int.fract x) (1 - Int.fract x) + change RationalPhaseSpacing.intDistance x ≤ 1 - Int.fract x at h + linarith + have hs := sin_pi_mul_lower_on_middle hdpos hlow hhigh + have hchord : 2 * RationalPhaseSpacing.intDistance x ≤ ‖1 - phase x‖ := by + rw [norm_sub_rev, ← phase_fract x, phase_eq_geometric_phase, norm_exp_phase_sub_one] + have habs := le_abs_self (Real.sin (Real.pi * Int.fract x)) + nlinarith + have hnorm : 0 < ‖1 - phase x‖ := by linarith + have hx : phase x ≠ 1 := by + intro hx + simp [hx] at hnorm + rw [geometricBound, ite_eq_right hx, RationalPhaseSpacing.truncatedInv, ite_eq_right hd] + apply min_le_min_left + apply (div_le_div_iff₀ hnorm hdpos).mpr + simpa using hchord + +/-- A uniform harmonic row bound for indexed integer frequencies. The map +into the interval must be injective, but need not exhaust the interval. -/ +theorem sum_geometricBound_difference_le {β : Type*} + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (M : ℕ) (t : Finset β) (f : β → ℤ) (L : ℤ) (N : ℕ) + (hf : ∀ k ∈ t, f k ∈ Finset.Ico L (L + N)) + (hinj : Set.InjOn f t) (n : ℤ) : + (∑ k ∈ t, geometricBound M (θ * ((n - f k : ℤ) : ℝ))) ≤ + (2 * (N : ℝ) / q + 1) * + (2 * (M : ℝ) + 4 * (q : ℝ) * (1 + Real.log (2 * (q : ℝ)))) := by + classical + let A := t.image (fun k => n - f k) + let L' : ℤ := n - L - N + 1 + have hA : A ⊆ Finset.Ico L' (L' + N) := by + intro j hj + obtain ⟨k, hk, rfl⟩ := Finset.mem_image.mp hj + have hk' := Finset.mem_Ico.mp (hf k hk) + apply Finset.mem_Ico.mpr + dsimp [L'] + omega + calc + _ ≤ ∑ k ∈ t, RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * ((n - f k : ℤ) : ℝ))) := + Finset.sum_le_sum (fun k _ => geometricBound_le_truncatedInv M _) + _ = ∑ j ∈ A, RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * j)) := by + rw [Finset.sum_image] + intro k hk i hi heq + apply hinj hk hi + dsimp at heq + omega + _ ≤ ∑ j ∈ Finset.Ico L' (L' + N), RationalPhaseSpacing.truncatedInv M + (RationalPhaseSpacing.intDistance (θ * j)) := + Finset.sum_le_sum_of_subset_of_nonneg hA (fun _ _ _ => + RationalPhaseSpacing.truncatedInv_nonneg (Nat.cast_nonneg M) + (RationalPhaseSpacing.intDistance_nonneg _)) + _ ≤ _ := RationalPhaseSpacing.sum_truncatedInv_intDistance_interval_le + θ a q hq hcop happrox L' N M (Nat.cast_nonneg M) + +end Problem337.VaughanBilinear + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanOptimized.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanOptimized.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a16f4ee58214cc00adbbe988f1b8d39fc37c2a4 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanOptimized.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanDyadicUniform +import OAI.NumberTheory.EgyptianFractions.VaughanCutoff + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction + +namespace Problem337.Vaughan + +/-- The standard three-term envelope for a reduced rational approximation. -/ +def approximationEnvelope (X q : ℝ) : ℝ := + X / Real.sqrt q + X ^ (4 / 5 : ℝ) + Real.sqrt (X * q) + +lemma approximationEnvelope_nonneg (X q : ℝ) (hX : 0 ≤ X) : + 0 ≤ approximationEnvelope X q := by + unfold approximationEnvelope + positivity + +lemma dyadic_log_le_three_scale (N : ℕ) : + 1 + Real.log N / Real.log 2 ≤ 3 * typeIILogScale N := by + have hlog := Real.log_natCast_nonneg N + have htwo : (1 / 2 : ℝ) ≤ Real.log 2 := by linarith [Real.log_two_gt_d9] + have hdiv : Real.log N / Real.log 2 ≤ 2 * Real.log N := by + apply (div_le_iff₀ (by linarith : 0 < Real.log 2)).mpr + nlinarith [mul_le_mul_of_nonneg_right htwo hlog] + have hN := log_nat_le_typeIILogScale N N le_rfl + have hH := one_le_typeIILogScale N + linarith + +/-- Balanced cutoffs turn each actual Type II block into the standard envelope. -/ +theorem optimized_typeIIBlock_bound + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N j : ℕ) (hqN : q ≤ N) + (hpow : 2 ≤ (N : ℝ) ^ (2 / 5 : ℝ)) : + ‖typeIIBlock N (optimizedCutoff N) (optimizedCutoff N) j + (fun k => VaughanBilinear.phase (θ * k))‖ ≤ + 18 * (typeIILogScale N) ^ 3 * approximationEnvelope N q := by + have hN : (1 : ℝ) ≤ N := by exact_mod_cast hq.trans_le hqN + have hU := optimizedCutoff_pos N hpow + have hs := typeIIBlock_sq_le_uniform θ a q hq hcop happrox N + (optimizedCutoff N) (optimizedCutoff N) j hqN hU hU + have hb := optimizedCutoff_squared_budget N q 32 + ‖typeIIBlock N (optimizedCutoff N) (optimizedCutoff N) j + (fun k => VaughanBilinear.phase (θ * k))‖ + hN (by exact_mod_cast hq) (by norm_num) hpow hs + have hsqrt : Real.sqrt (32 : ℝ) ≤ 6 := + (Real.sqrt_le_left (by norm_num)).mpr (by norm_num) + change _ ≤ 3 * Real.sqrt 32 * (typeIILogScale N) ^ 3 * approximationEnvelope N q at hb + refine hb.trans ?_ + have hH : 0 ≤ typeIILogScale N := zero_le_one.trans (one_le_typeIILogScale N) + have hE := approximationEnvelope_nonneg N q (Nat.cast_nonneg N) + gcongr + norm_num at * + linarith + +/-- Summing the genuine dyadic blocks costs one further logarithm, not a +power of the summation length. All cancellation hypotheses are discharged. -/ +theorem optimized_typeII_bound + (θ : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |θ - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N : ℕ) (hqN : q ≤ N) + (hpow : 2 ≤ (N : ℝ) ^ (2 / 5 : ℝ)) : + ‖weightedSum (Finset.Ioc 0 N) (fun k => VaughanBilinear.phase (θ * k)) + (typeIICoefficient (optimizedCutoff N) * longPart (optimizedCutoff N) Λ)‖ ≤ + 54 * (typeIILogScale N) ^ 4 * approximationEnvelope N q := by + have hH : 0 ≤ typeIILogScale N := zero_le_one.trans (one_le_typeIILogScale N) + have hE := approximationEnvelope_nonneg N q (Nat.cast_nonneg N) + have hb := norm_typeII_le_dyadic_log_budget N (optimizedCutoff N) (optimizedCutoff N) + (fun k => VaughanBilinear.phase (θ * k)) + (18 * (typeIILogScale N) ^ 3 * approximationEnvelope N q) (by positivity) + (fun j _ => optimized_typeIIBlock_bound θ a q hq hcop happrox N j hqN hpow) + refine hb.trans ?_ + calc + _ ≤ (3 * typeIILogScale N) * + (18 * (typeIILogScale N) ^ 3 * approximationEnvelope N q) := + mul_le_mul_of_nonneg_right (dyadic_log_le_three_scale N) (by positivity) + _ = _ := by ring + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanRealTypeIHyperbolic.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanRealTypeIHyperbolic.lean new file mode 100644 index 0000000000000000000000000000000000000000..1df7636f672fa806e006fcae7f65fab9d9eb9ab3 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanRealTypeIHyperbolic.lean @@ -0,0 +1,112 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanTypeI +import OAI.NumberTheory.EgyptianFractions.RealTypeI + +namespace OAI +/-! +# Actual near-rational estimates for the two Vaughan Type I terms + +The prefix adapter uses the sharper canonical harmonic hyperbola bound +for its scalar aggregation. +The variable hyperbolic lengths are retained throughout. In particular the +right hand side has size `N / q + A + q`, up to logarithmic factors, rather +than the much larger fixed-cap estimate obtained by replacing every `N / d` +with `N`. +-/ + +noncomputable section +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius ArithmeticFunction.zeta + +namespace Problem337.VaughanHyperbolic + +open Vaughan + +open RationalPhaseSpacing + +/-- Every hyperbolic inner prefix has the required variable-cap envelope. +This includes the zero-frequency case and does not require a nonresonance +assumption. -/ +theorem norm_phase_Ioc_mul_le_variable (α : ℝ) (N d k : ℕ) (hk : k ≤ N / d) : + ‖∑ b ∈ Finset.Ioc 0 k, RealPhase.phase (α * (d * b : ℕ))‖ ≤ + truncatedInv ((N : ℝ) / d) (intDistance (α * d)) := by + have heq : (∑ b ∈ Finset.Ioc 0 k, RealPhase.phase (α * (d * b : ℕ))) = + ∑ j ∈ Finset.range k, RealPhase.phase ((α * d) * (1 + j) + 0) := by + rw [sum_Ioc_zero_eq_sum_range_succ] + apply Finset.sum_congr rfl + intro j hj + congr 1 + push_cast + ring + rw [heq] + exact (RealPhase.norm_sum_shift_phase_le_envelope (α * d) 0 1 k).trans + (RealTypeI.geometric_envelope_le_truncated_real (α * d) k ((N : ℝ) / d) + ((by exact_mod_cast hk : (k : ℝ) ≤ (N / d : ℕ)).trans Nat.cast_div_le)) + +/-- The positive-initial-interval convention used by Vaughan's identity. -/ +theorem sum_variable_reciprocal_Ioc_le + (α : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |α - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N A : ℕ) : + (∑ d ∈ Finset.Ioc 0 A, + truncatedInv ((N : ℝ) / d) (intDistance (α * d))) ≤ + RealTypeI.hyperbolicCost (N : ℝ) A q := by + have hcast : (∑ d ∈ Finset.Ioc 0 A, + truncatedInv ((N : ℝ) / d) (intDistance (α * d))) = + ∑ d ∈ Finset.Icc 1 (A : ℤ), + truncatedInv ((N : ℝ) / d) (intDistance (α * d)) := by + apply Finset.sum_nbij' (fun d : ℕ => (d : ℤ)) Int.toNat + · intro d hd + obtain ⟨hd0, hdA⟩ := Finset.mem_Ioc.mp hd + exact Finset.mem_Icc.mpr ⟨by exact_mod_cast hd0, by exact_mod_cast hdA⟩ + · intro d hd + obtain ⟨hd1, hdA⟩ := Finset.mem_Icc.mp hd + apply Finset.mem_Ioc.mpr + omega + · intro d hd + exact Int.toNat_natCast d + · intro d hd + exact Int.toNat_of_nonneg (by have := (Finset.mem_Icc.mp hd).1; omega) + · intro d hd + simp + rw [hcast] + exact sum_truncatedInv_hyperbolic_le α a q hq hcop happrox N (Nat.cast_nonneg N) A + +/-- The first actual Vaughan convolution, with its logarithmic inner weight, +is bounded using only a reduced rational approximation to the frequency. -/ +theorem first_typeI_real_phase_bound + (α : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |α - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N U : ℕ) : + ‖weightedSum (Finset.Ioc 0 N) (fun n => RealPhase.phase (α * n)) + (shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log)‖ ≤ + 2 * Real.log N * RealTypeI.hyperbolicCost (N : ℝ) (min U N) q := by + apply (first_typeI_bound (fun n => RealPhase.phase (α * n)) N U + (fun d => truncatedInv ((N : ℝ) / d) (intDistance (α * d))) + (fun d _ k hk => norm_phase_Ioc_mul_le_variable α N d k hk)).trans + exact mul_le_mul_of_nonneg_left + (sum_variable_reciprocal_Ioc_le α a q hq hcop happrox N (min U N)) + (by positivity) + +/-- The second actual Vaughan convolution has one logarithmic coefficient +factor and the same variable-length reciprocal budget. -/ +theorem second_typeI_real_phase_bound + (α : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |α - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N U V : ℕ) : + ‖weightedSum (Finset.Ioc 0 N) (fun n => RealPhase.phase (α * n)) + (typeICoefficient U V * ζ)‖ ≤ + Real.log N * RealTypeI.hyperbolicCost (N : ℝ) (min (U * V) N) q := by + apply (second_typeI_bound (fun n => RealPhase.phase (α * n)) N U V + (fun d => truncatedInv ((N : ℝ) / d) (intDistance (α * d))) + (fun d _ => norm_phase_Ioc_mul_le_variable α N d (N / d) le_rfl)).trans + exact mul_le_mul_of_nonneg_left + (sum_variable_reciprocal_Ioc_le α a q hq hcop happrox N (min (U * V) N)) + (Real.log_natCast_nonneg N) + +end Problem337.VaughanHyperbolic + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanTypeI.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanTypeI.lean new file mode 100644 index 0000000000000000000000000000000000000000..0666d110f2384843b19224795b04b683cb9fd50a --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanTypeI.lean @@ -0,0 +1,160 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanWeighted +import OAI.NumberTheory.EgyptianFractions.ThreePrimePartialSummation + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius ArithmeticFunction.zeta + +namespace Problem337.Vaughan + +/-- Indexing positive initial intervals by a zero-based range. -/ +lemma sum_Ioc_zero_eq_sum_range_succ {R : Type*} [AddCommMonoid R] + (f : ℕ → R) (N : ℕ) : + (∑ j ∈ Finset.Ioc 0 N, f j) = ∑ j ∈ Finset.range N, f (j + 1) := by + induction N with + | zero => simp + | succ N ih => + rw [Finset.sum_Ioc_succ_top (Nat.zero_le N), Finset.sum_range_succ, ih] + +/-- Adding a logarithmic weight costs at most twice the endpoint logarithm. +The prefix bound remains explicit; no cancellation estimate is assumed silently. -/ +theorem log_weighted_sum_norm_le (w : ℕ → ℂ) (N : ℕ) (B : ℝ) + (hprefix : ∀ k ≤ N, ‖∑ j ∈ Finset.Ioc 0 k, w j‖ ≤ B) : + ‖∑ j ∈ Finset.Ioc 0 N, (Real.log j : ℂ) * w j‖ ≤ + 2 * B * Real.log N := by + cases N with + | zero => simp + | succ n => + have hlog (j : ℕ) : 0 ≤ Real.log (j + 1 : ℕ) := + Real.log_nonneg (by exact_mod_cast Nat.succ_le_succ (Nat.zero_le j)) + have hmono (j : ℕ) : Real.log (j + 1 : ℕ) ≤ Real.log (j + 1 + 1 : ℕ) := by + apply Real.log_le_log + · positivity + · exact_mod_cast Nat.le_succ (j + 1) + have hvar : (∑ j ∈ Finset.range n, + ‖(Real.log (j + 1 + 1 : ℕ) : ℂ) - (Real.log (j + 1 : ℕ) : ℂ)‖) = + Real.log (n + 1 : ℕ) := by + calc + _ = ∑ j ∈ Finset.range n, + (Real.log (j + 1 + 1 : ℕ) - Real.log (j + 1 : ℕ)) := by + apply Finset.sum_congr rfl + intro j hj + rw [← Complex.ofReal_sub, Complex.norm_real, Real.norm_eq_abs, + abs_of_nonneg (sub_nonneg.mpr (hmono j))] + _ = _ := by + simpa using Finset.sum_range_sub (fun j => Real.log (j + 1 : ℕ)) n + have h := ThreePrimeAnalysis.weighted_sum_norm_le_partial_sum_bound + (fun j => w (j + 1)) (fun j => (Real.log (j + 1 : ℕ) : ℂ)) n B (by + intro k hk + simpa only [sum_Ioc_zero_eq_sum_range_succ] using hprefix k hk) + rw [hvar, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg (hlog n)] at h + rw [sum_Ioc_zero_eq_sum_range_succ] + convert h using 1 + ring + +/-- Type I logarithmic bilinear estimate for coefficients bounded by one. -/ +theorem norm_log_bilinear_sum_le (w : ℕ → ℂ) (N A : ℕ) (c B : ℕ → ℝ) + (hA : A ≤ N) + (hc : ∀ a ∈ Finset.Ioc 0 A, |c a| ≤ 1) + (hprefix : ∀ a ∈ Finset.Ioc 0 A, ∀ k ≤ N / a, + ‖∑ b ∈ Finset.Ioc 0 k, w (a * b)‖ ≤ B a) : + ‖∑ a ∈ Finset.Ioc 0 A, (c a : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), (Real.log b : ℂ) * w (a * b)‖ ≤ + 2 * Real.log N * ∑ a ∈ Finset.Ioc 0 A, B a := by + calc + _ ≤ ∑ a ∈ Finset.Ioc 0 A, + ‖(c a : ℂ) * ∑ b ∈ Finset.Ioc 0 (N / a), + (Real.log b : ℂ) * w (a * b)‖ := norm_sum_le _ _ + _ ≤ ∑ a ∈ Finset.Ioc 0 A, 2 * Real.log N * B a := by + apply Finset.sum_le_sum + intro a ha + obtain ⟨ha0, haA⟩ := Finset.mem_Ioc.mp ha + have haN := haA.trans hA + have hq : 1 ≤ N / a := (Nat.le_div_iff_mul_le ha0).mpr (by simpa using haN) + have hB : 0 ≤ B a := by simpa using hprefix a ha 0 (Nat.zero_le _) + have hlog : Real.log (N / a : ℕ) ≤ Real.log N := by + apply Real.log_le_log + · exact_mod_cast (Nat.zero_lt_of_lt hq) + · exact_mod_cast Nat.div_le_self N a + rw [norm_mul, Complex.norm_real, Real.norm_eq_abs] + calc + _ ≤ 1 * ‖∑ b ∈ Finset.Ioc 0 (N / a), + (Real.log b : ℂ) * w (a * b)‖ := + mul_le_mul_of_nonneg_right (hc a ha) (norm_nonneg _) + _ ≤ 2 * B a * Real.log (N / a : ℕ) := by + simpa using log_weighted_sum_norm_le (fun b => w (a * b)) (N / a) (B a) + (hprefix a ha) + _ ≤ 2 * Real.log N * B a := by + nlinarith [mul_le_mul_of_nonneg_left hlog (show 0 ≤ 2 * B a by positivity)] + _ = _ := by rw [Finset.mul_sum] + +/-- Type I bilinear estimate for coefficients with the logarithmic majorant. -/ +theorem norm_bilinear_sum_le_log (w : ℕ → ℂ) (N A : ℕ) (c B : ℕ → ℝ) + (hA : A ≤ N) + (hc : ∀ a ∈ Finset.Ioc 0 A, |c a| ≤ Real.log a) + (hinner : ∀ a ∈ Finset.Ioc 0 A, + ‖∑ b ∈ Finset.Ioc 0 (N / a), w (a * b)‖ ≤ B a) : + ‖∑ a ∈ Finset.Ioc 0 A, (c a : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), w (a * b)‖ ≤ + Real.log N * ∑ a ∈ Finset.Ioc 0 A, B a := by + calc + _ ≤ ∑ a ∈ Finset.Ioc 0 A, + ‖(c a : ℂ) * ∑ b ∈ Finset.Ioc 0 (N / a), w (a * b)‖ := norm_sum_le _ _ + _ ≤ ∑ a ∈ Finset.Ioc 0 A, Real.log N * B a := by + apply Finset.sum_le_sum + intro a ha + obtain ⟨ha0, haA⟩ := Finset.mem_Ioc.mp ha + have hB : 0 ≤ B a := (norm_nonneg _).trans (hinner a ha) + have hlog : Real.log a ≤ Real.log N := Real.log_le_log + (by exact_mod_cast ha0) (by exact_mod_cast haA.trans hA) + have hlogN : 0 ≤ Real.log N := (abs_nonneg _).trans ((hc a ha).trans hlog) + rw [norm_mul, Complex.norm_real, Real.norm_eq_abs] + exact mul_le_mul ((hc a ha).trans hlog) (hinner a ha) (norm_nonneg _) hlogN + _ = _ := by rw [Finset.mul_sum] + +/-- The first Vaughan Type I term in its finite bilinear form. -/ +theorem first_typeI_sum_bound (w : ℕ → ℂ) (N U : ℕ) (B : ℕ → ℝ) + (hprefix : ∀ a ∈ Finset.Ioc 0 (min U N), ∀ k ≤ N / a, + ‖∑ b ∈ Finset.Ioc 0 k, w (a * b)‖ ≤ B a) : + ‖∑ a ∈ Finset.Ioc 0 (min U N), ((μ a : ℝ) : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), (Real.log b : ℂ) * w (a * b)‖ ≤ + 2 * Real.log N * ∑ a ∈ Finset.Ioc 0 (min U N), B a := by + apply norm_log_bilinear_sum_le w N (min U N) (fun a => (μ a : ℝ)) B + (min_le_right _ _) _ hprefix + intro a ha + exact abs_real_moebius_le_one a + +/-- The second Vaughan Type I term in its finite bilinear form. -/ +theorem second_typeI_sum_bound (w : ℕ → ℂ) (N U V : ℕ) (B : ℕ → ℝ) + (hinner : ∀ a ∈ Finset.Ioc 0 (min (U * V) N), + ‖∑ b ∈ Finset.Ioc 0 (N / a), w (a * b)‖ ≤ B a) : + ‖∑ a ∈ Finset.Ioc 0 (min (U * V) N), (typeICoefficient U V a : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), w (a * b)‖ ≤ + Real.log N * ∑ a ∈ Finset.Ioc 0 (min (U * V) N), B a := by + exact norm_bilinear_sum_le_log w N (min (U * V) N) (typeICoefficient U V) B + (min_le_right _ _) (fun a _ => abs_typeICoefficient_le_log U V a) hinner + +/-- First Type I estimate directly for the actual Vaughan convolution. -/ +theorem first_typeI_bound (w : ℕ → ℂ) (N U : ℕ) (B : ℕ → ℝ) + (hprefix : ∀ a ∈ Finset.Ioc 0 (min U N), ∀ k ≤ N / a, + ‖∑ b ∈ Finset.Ioc 0 k, w (a * b)‖ ≤ B a) : + ‖weightedSum (Finset.Ioc 0 N) w + (shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log)‖ ≤ + 2 * Real.log N * ∑ a ∈ Finset.Ioc 0 (min U N), B a := by + rw [first_typeI_eq_sum] + exact first_typeI_sum_bound w N U B hprefix + +/-- Second Type I estimate directly for the actual Vaughan convolution. -/ +theorem second_typeI_bound (w : ℕ → ℂ) (N U V : ℕ) (B : ℕ → ℝ) + (hinner : ∀ a ∈ Finset.Ioc 0 (min (U * V) N), + ‖∑ b ∈ Finset.Ioc 0 (N / a), w (a * b)‖ ≤ B a) : + ‖weightedSum (Finset.Ioc 0 N) w (typeICoefficient U V * ζ)‖ ≤ + Real.log N * ∑ a ∈ Finset.Ioc 0 (min (U * V) N), B a := by + rw [second_typeI_eq_sum] + exact second_typeI_sum_bound w N U V B hinner + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanTypeINormalized.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanTypeINormalized.lean new file mode 100644 index 0000000000000000000000000000000000000000..20b8f93d1eefd89abd72c61eafb67bfbe65e8135 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanTypeINormalized.lean @@ -0,0 +1,102 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanRealTypeIHyperbolic + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius ArithmeticFunction.zeta + +namespace Problem337.VaughanHyperbolic + +/-- A common logarithmic majorant for both actual Type I costs. -/ +theorem hyperbolicCost_min_le (N A q : ℕ) (hN : 1 ≤ N) (hq : 0 < q) + (hqN : q ≤ N) : + RealTypeI.hyperbolicCost N (min A N) q ≤ + 8 * ((N : ℝ) / q + A + q) * (1 + Real.log (2 * (N : ℝ))) := by + have hNr : (1 : ℝ) ≤ N := by exact_mod_cast hN + have hqr : (1 : ℝ) ≤ q := by exact_mod_cast hq + have hqNr : (q : ℝ) ≤ N := by exact_mod_cast hqN + have hminA : ((min A N : ℕ) : ℝ) ≤ A := by exact_mod_cast min_le_left A N + have hminN : ((min A N : ℕ) : ℝ) ≤ N := by exact_mod_cast min_le_right A N + have hlogq : 0 ≤ 1 + Real.log (2 * (q : ℝ)) := by + have := Real.log_nonneg (show 1 ≤ 2 * (q : ℝ) by linarith) + linarith + have hH : 0 ≤ 1 + Real.log (2 * (N : ℝ)) := by + have := Real.log_nonneg (show 1 ≤ 2 * (N : ℝ) by linarith) + linarith + have hlogqN : 1 + Real.log (2 * (q : ℝ)) ≤ + 1 + Real.log (2 * (N : ℝ)) := by + gcongr + have hlogmin : 1 + Real.log (((min A N : ℕ) : ℝ) + 1) ≤ + 1 + Real.log (2 * (N : ℝ)) := by + exact add_le_add le_rfl (Real.log_le_log (by positivity) (by linarith)) + unfold RealTypeI.hyperbolicCost + calc + _ ≤ 8 * ((A : ℝ) + q) * (1 + Real.log (2 * (N : ℝ))) + + (4 * (N : ℝ) / q) * (1 + Real.log (2 * (N : ℝ))) := by + apply add_le_add + · exact mul_le_mul (by gcongr) hlogqN hlogq (by positivity) + · exact mul_le_mul_of_nonneg_left hlogmin (by positivity) + _ ≤ _ := by + have hd : 0 ≤ (N : ℝ) / q := by positivity + simp only [mul_div_assoc] + nlinarith [mul_nonneg hd hH] + +private lemma log_le_common (N : ℕ) (hN : 1 ≤ N) : + Real.log N ≤ 1 + Real.log (2 * (N : ℝ)) := by + have hNr : (1 : ℝ) ≤ N := by exact_mod_cast hN + have h := Real.log_le_log (show 0 < (N : ℝ) by linarith) + (show (N : ℝ) ≤ 2 * N by linarith) + linarith + +/-- Uniform Type I bound in the parameters of the optimized Vaughan cutoff. -/ +theorem first_typeI_normalized_bound + (α : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |α - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N U : ℕ) (hN : 1 ≤ N) (hqN : q ≤ N) : + ‖Vaughan.weightedSum (Finset.Ioc 0 N) (fun n => RealPhase.phase (α * n)) + (Vaughan.shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log)‖ ≤ + 16 * (1 + Real.log (2 * (N : ℝ))) ^ 2 * ((N : ℝ) / q + U + q) := by + have hH : 0 ≤ 1 + Real.log (2 * (N : ℝ)) := + (Real.log_natCast_nonneg N).trans (log_le_common N hN) + calc + _ ≤ 2 * Real.log N * RealTypeI.hyperbolicCost N (min U N) q := + first_typeI_real_phase_bound α a q hq hcop happrox N U + _ ≤ 2 * Real.log N * + (8 * ((N : ℝ) / q + U + q) * (1 + Real.log (2 * (N : ℝ)))) := + mul_le_mul_of_nonneg_left (hyperbolicCost_min_le N U q hN hq hqN) (by positivity) + _ ≤ _ := by + have h := mul_le_mul_of_nonneg_right (log_le_common N hN) + (show 0 ≤ 16 * ((N : ℝ) / q + U + q) * + (1 + Real.log (2 * (N : ℝ))) by positivity) + nlinarith + +/-- Uniform second Type I bound with the full product support retained. -/ +theorem second_typeI_normalized_bound + (α : ℝ) (a : ℤ) (q : ℕ) (hq : 0 < q) + (hcop : IsCoprime a (q : ℤ)) + (happrox : |α - (a : ℝ) / q| ≤ 1 / (q : ℝ) ^ 2) + (N U V : ℕ) (hN : 1 ≤ N) (hqN : q ≤ N) : + ‖Vaughan.weightedSum (Finset.Ioc 0 N) (fun n => RealPhase.phase (α * n)) + (Vaughan.typeICoefficient U V * ζ)‖ ≤ + 8 * (1 + Real.log (2 * (N : ℝ))) ^ 2 * ((N : ℝ) / q + U * V + q) := by + have hH : 0 ≤ 1 + Real.log (2 * (N : ℝ)) := + (Real.log_natCast_nonneg N).trans (log_le_common N hN) + calc + _ ≤ Real.log N * RealTypeI.hyperbolicCost N (min (U * V) N) q := + second_typeI_real_phase_bound α a q hq hcop happrox N U V + _ ≤ Real.log N * + (8 * ((N : ℝ) / q + (U * V : ℕ) + q) * (1 + Real.log (2 * (N : ℝ)))) := + mul_le_mul_of_nonneg_left (hyperbolicCost_min_le N (U * V) q hN hq hqN) + (Real.log_natCast_nonneg N) + _ ≤ _ := by + have h := mul_le_mul_of_nonneg_right (log_le_common N hN) + (show 0 ≤ 8 * ((N : ℝ) / q + U * V + q) * + (1 + Real.log (2 * (N : ℝ))) by positivity) + push_cast + nlinarith + +end Problem337.VaughanHyperbolic + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/VaughanWeighted.lean b/lean/OAI/NumberTheory/EgyptianFractions/VaughanWeighted.lean new file mode 100644 index 0000000000000000000000000000000000000000..a538dc05daf9edda86e495ef2ed3ebc6368610d2 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/VaughanWeighted.lean @@ -0,0 +1,108 @@ +import OAI.NumberTheory.EgyptianFractions.VaughanIdentity +import OAI.NumberTheory.EgyptianFractions.VaughanHyperbola +import Mathlib + +namespace OAI +noncomputable section +open scoped BigOperators ArithmeticFunction ArithmeticFunction.Moebius ArithmeticFunction.zeta + +namespace Problem337.Vaughan + +/-- Finite complex weighted sum of a real arithmetic function. -/ +def weightedSum (s : Finset ℕ) (w : ℕ → ℂ) (f : ArithmeticFunction ℝ) : ℂ := + ∑ n ∈ s, (f n : ℂ) * w n + +@[simp] theorem weightedSum_add (s : Finset ℕ) (w : ℕ → ℂ) + (f g : ArithmeticFunction ℝ) : + weightedSum s w (f + g) = weightedSum s w f + weightedSum s w g := by + simp [weightedSum, add_mul, Finset.sum_add_distrib] + +@[simp] theorem weightedSum_sub (s : Finset ℕ) (w : ℕ → ℂ) + (f g : ArithmeticFunction ℝ) : + weightedSum s w (f - g) = weightedSum s w f - weightedSum s w g := by + simp [sub_eq_add_neg, weightedSum, add_mul, Finset.sum_add_distrib] + +/-- Exact complex weighted Vaughan decomposition, using the canonical cutoff API. -/ +theorem weighted_identity (s : Finset ℕ) (w : ℕ → ℂ) (U V : ℕ) : + weightedSum s w Λ = weightedSum s w (shortPart V Λ) + + weightedSum s w (shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log) - + weightedSum s w (typeICoefficient U V * ζ) + + weightedSum s w (typeIICoefficient U * longPart V Λ) := by + have h := congrArg (weightedSum s w) (vonMangoldt_identity U V) + simpa only [weightedSum_add, weightedSum_sub, typeICoefficient, typeIICoefficient] using h + +/-- The Type II convolution is supported where both factors exceed the cutoffs. -/ +theorem typeII_apply (U V n : ℕ) : + (typeIICoefficient U * longPart V Λ) n = + ∑ d ∈ n.divisorsAntidiagonal.filter (fun d => U < d.1 ∧ V < d.2), + typeIICoefficient U d.1 * Λ d.2 := by + rw [ArithmeticFunction.mul_apply, Finset.sum_filter] + apply Finset.sum_congr rfl + intro d hd + by_cases hU : U < d.1 + · by_cases hV : V < d.2 <;> simp [hU, hV] + · simp [hU, typeIICoefficient_eq_zero U d.1 (not_lt.mp hU)] + +lemma positive_interval (N : ℕ) : Finset.Icc 1 N = Finset.Ioc 0 N := by + ext n + simp only [Finset.mem_Icc, Finset.mem_Ioc] + omega + +/-- A convolution sum with its outer coefficient factored out. -/ +theorem weightedSum_mul (N : ℕ) (w : ℕ → ℂ) (f g : ArithmeticFunction ℝ) : + weightedSum (Finset.Ioc 0 N) w (f * g) = + ∑ a ∈ Finset.Ioc 0 N, (f a : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), (g b : ℂ) * w (a * b) := by + simpa only [weightedSum, positive_interval, Finset.mul_sum, Complex.ofReal_mul, + mul_assoc] using sum_real_convolution_eq_nested N f g w + +/-- A compactly supported coefficient restricts the outer interval exactly. -/ +theorem weightedSum_mul_of_support (N A : ℕ) (w : ℕ → ℂ) + (f g : ArithmeticFunction ℝ) (hf : ∀ a, A < a → f a = 0) : + weightedSum (Finset.Ioc 0 N) w (f * g) = + ∑ a ∈ Finset.Ioc 0 (min A N), (f a : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), (g b : ℂ) * w (a * b) := by + rw [weightedSum_mul] + symm + apply Finset.sum_subset + · intro a ha + obtain ⟨ha0, haAN⟩ := Finset.mem_Ioc.mp ha + exact Finset.mem_Ioc.mpr ⟨ha0, (le_min_iff.mp haAN).2⟩ + · intro a ha hnot + have hA : A < a := by + simp only [Finset.mem_Ioc] at ha hnot + omega + simp [hf a hA] + +/-- Exact first Type I sum with its actual short cutoff. -/ +theorem first_typeI_eq_sum (N U : ℕ) (w : ℕ → ℂ) : + weightedSum (Finset.Ioc 0 N) w + (shortPart U (μ : ArithmeticFunction ℝ) * ArithmeticFunction.log) = + ∑ a ∈ Finset.Ioc 0 (min U N), ((μ a : ℝ) : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), (Real.log b : ℂ) * w (a * b) := by + rw [weightedSum_mul_of_support N U w _ _ (by + intro a ha + simp [not_le.mpr ha])] + apply Finset.sum_congr rfl + intro a ha + have haU := (le_min_iff.mp (Finset.mem_Ioc.mp ha).2).1 + simp [haU] + +/-- Exact second Type I sum, supported up to the product cutoff. -/ +theorem second_typeI_eq_sum (N U V : ℕ) (w : ℕ → ℂ) : + weightedSum (Finset.Ioc 0 N) w (typeICoefficient U V * ζ) = + ∑ a ∈ Finset.Ioc 0 (min (U * V) N), (typeICoefficient U V a : ℂ) * + ∑ b ∈ Finset.Ioc 0 (N / a), w (a * b) := by + rw [weightedSum_mul_of_support N (U * V) w _ _ (typeICoefficient_eq_zero U V)] + apply Finset.sum_congr rfl + intro a ha + congr 1 + apply Finset.sum_congr rfl + intro b hb + simp [ArithmeticFunction.zeta_apply_ne (Nat.ne_of_gt (Finset.mem_Ioc.mp hb).1)] + +end Problem337.Vaughan + +end + +end OAI diff --git a/lean/OAI/NumberTheory/EgyptianFractions/WeightedBinomial.lean b/lean/OAI/NumberTheory/EgyptianFractions/WeightedBinomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..c2b2d078d46d0c15ff60178f8eb941a89dd04fa6 --- /dev/null +++ b/lean/OAI/NumberTheory/EgyptianFractions/WeightedBinomial.lean @@ -0,0 +1,55 @@ +import Mathlib + +namespace OAI +noncomputable section +open scoped BigOperators +namespace Problem337 + +/-- A weighted binomial bound, allowing a real cutoff on subset size. -/ +theorem weighted_binomial_bound (L : ℕ) (t q : ℝ) (hq0 : 0 < q) (hq1 : q ≤ 1) : + (∑ j ∈ (Finset.range (L + 1)).filter (fun j : ℕ => (j : ℝ) ≤ t), + (Nat.choose L j : ℝ)) ≤ q ^ (-t) * (1 + q) ^ L := by + have hw : q ^ t * + (∑ j ∈ (Finset.range (L + 1)).filter (fun j : ℕ => (j : ℝ) ≤ t), + (Nat.choose L j : ℝ)) ≤ (1 + q) ^ L := by + rw [Finset.mul_sum] + calc + _ ≤ ∑ j ∈ (Finset.range (L + 1)).filter (fun j : ℕ => (j : ℝ) ≤ t), + q ^ j * (Nat.choose L j : ℝ) := by + apply Finset.sum_le_sum + intro j hj + apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) + simpa only [Real.rpow_natCast] using + Real.rpow_le_rpow_of_exponent_ge hq0 hq1 (Finset.mem_filter.mp hj).2 + _ ≤ ∑ j ∈ Finset.range (L + 1), q ^ j * (Nat.choose L j : ℝ) := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + intro j hj hnot + positivity + _ = (1 + q) ^ L := by + rw [show 1 + q = q + 1 by ring, add_pow] + simp + have hqt : 0 < q ^ t := Real.rpow_pos_of_pos hq0 t + have hdiv : + (∑ j ∈ (Finset.range (L + 1)).filter (fun j : ℕ => (j : ℝ) ≤ t), + (Nat.choose L j : ℝ)) ≤ (1 + q) ^ L / q ^ t := + (le_div_iff₀ hqt).2 (by simpa only [mul_comm] using hw) + simpa only [Real.rpow_neg hq0.le, div_eq_mul_inv, mul_comm] using hdiv + +/-- Exponential form of the weighted subset count used in divisor estimates. -/ +theorem weighted_binomial_exp_bound (L : ℕ) (t q : ℝ) (hq0 : 0 < q) (hq1 : q ≤ 1) : + (∑ j ∈ (Finset.range (L + 1)).filter (fun j : ℕ => (j : ℝ) ≤ t), + (Nat.choose L j : ℝ)) ≤ Real.exp (-t * Real.log q + (L : ℝ) * q) := by + apply (weighted_binomial_bound L t q hq0 hq1).trans + have hqadd : 0 < 1 + q := by positivity + rw [← Real.rpow_natCast (1 + q) L, + Real.rpow_def_of_pos hq0, Real.rpow_def_of_pos hqadd, ← Real.exp_add] + apply Real.exp_le_exp.mpr + have hlog : Real.log (1 + q) ≤ q := by + simpa using Real.log_le_sub_one_of_pos hqadd + nlinarith [mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg L : (0 : ℝ) ≤ L)] + +end Problem337 + +end + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/AccurateScales.lean b/lean/OAI/NumberTheory/GaussianMoat/AccurateScales.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a6731a0b6f1e628e3045f2909ae16aebff7aced --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/AccurateScales.lean @@ -0,0 +1,336 @@ +import OAI.NumberTheory.GaussianMoat.SieveCertificate + +namespace OAI + +namespace GaussianMoat + +section +open scoped BigOperators Classical + +noncomputable def bandConstant (D : ℝ) : ℝ := + 10000+100*|Real.log D|+100*|Real.log (max D ((latticeBall (4*D)).card:ℝ))| + +lemma bandConstant_pos (D : ℝ) : 0 bandLength g U i.val)++post) + N (bandSize s g U l) δ) := by + let V := bandScale g U l + have hV : 0 Real.exp (m:ℝ)*a) atTop atTop := + (Real.tendsto_exp_atTop.comp tendsto_natCast_atTop_atTop).atTop_mul_const ha + simpa only [mul_comm] using hh.eventually (eventually_ge_atTop C) + +lemma eventually_mul_le_double_exp {a : ℝ} (ha : 0 a*Real.exp m) atTop atTop := by + simpa only [Function.comp_apply] using Filter.Tendsto.const_mul_atTop ha + (Real.tendsto_exp_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ))) + filter_upwards [ht.eventually hh] with m hm + simpa only [pow_one,one_mul,←mul_assoc,div_mul_cancel₀ _ ha.ne'] using hm + +lemma eventually_accurate_small {ε : ℝ} (hε : 0<ε) : + ∀ᶠ m : ℕ in atTop, accurateGrid m≤ε := by + have hh := eventually_linear_le_square 0 (-Real.log ε) + filter_upwards [tendsto_natCast_atTop_atTop.eventually hh] with m hm + change 0*(m:ℝ)-Real.log ε≤(m:ℝ)^2 at hm + unfold accurateGrid + rw [←Real.exp_log hε] + apply Real.exp_le_exp.mpr + linarith only [hm] + +lemma dense_sieve_cap (s : SplitSieve) (hne : s.primes.Nonempty) {T δ U : ℝ} + (hT : 2≤T) + (hp : ∀ p∈s.primes, T≤(p:ℝ) ∧ (p:ℝ)≤2*T) + (hdense : δ*T/Real.log (2*T)≤ s.primes.card) + (hsize : 2*U≤δ*T) : ⌊U/s.meanLog⌋₊≤ s.primes.card := by + have hT0 : 0 + bandLength (accurateGrid m) (Real.exp (a*Real.exp m)) i.val)++post) + N (bandSize s (accurateGrid m) (Real.exp (a*Real.exp m)) (accurateIterations m)) + (91*accurateGrid m)) := by + have hlarge := eventually_mul_le_double_exp (a := a/2) (by positivity) + (bandConstant D*(B+1)) + have hgap := eventually_const_le_exp_mul (a := A-a) (by linarith only [haA]) (Real.log (2/δ)) + have htwo := eventually_const_le_exp_mul hA 2 + filter_upwards [eventually_accurate_scale ha 5,eventually_accurate_scale ha 1, + eventually_accurate_small (show (0:ℝ)<1/200 by norm_num),hlarge,hgap,htwo] + with m hm5 hm1 hsmall hlarge hgap htwo + intro s T pre post N hne hp hdense hT hThi hpost hN hlen + have he1 : 1≤Real.exp (m:ℝ) := Real.one_le_exp_iff.mpr (Nat.cast_nonneg _) + have hT0 : 0 (hpost n hn).trans (Real.exp_le_exp.mpr htail)) + (hN.trans (Real.exp_le_exp.mpr htail)) (hlen.trans (Real.exp_le_exp.mpr htail)) + (accurateIterations_error m) + +end + +open scoped BigOperators Classical + +lemma EntropyBand.size_cap {s : SplitSieve} {D δ : ℝ} {ns : List ℕ} {N b : ℕ} + (q : EntropyBand s D ns N b δ) (hmean : 0< s.meanLog) : b≤ s.primes.card := by + rw [q.size] + apply le_trans _ q.cap + apply Nat.floor_mono + apply div_le_div_of_nonneg_right _ hmean.le + have hh := bandScale_antitone q.positive.le (by linarith only [q.small]) q.scale.le (Nat.zero_le q.l) + simpa only [bandScale,pow_zero,one_mul] using hh + +lemma EntropyBand.size_lower {s : SplitSieve} {D δ : ℝ} {ns : List ℕ} {N b : ℕ} + (q : EntropyBand s D ns N b δ) (hmean : 0< s.meanLog) : + bandScale q.g q.U q.l/2≤(b:ℝ)*s.meanLog := by + have hV := bandScale_pos q.positive q.scale q.l + have hg5 : q.g^5≤1 := pow_le_one₀ q.positive.le (by linarith only [q.small]) + have hh := mul_le_mul_of_nonneg_right hg5 hV.le + have hlarge := q.large + have hVL : 2*s.meanLog≤bandScale q.g q.U q.l := by nlinarith only [hh,hlarge,hmean] + have hf := Nat.lt_floor_add_one (bandScale q.g q.U q.l/s.meanLog) + have hm := mul_lt_mul_of_pos_right hf hmean + rw [div_mul_cancel₀ _ hmean.ne',add_mul,one_mul] at hm + have ht : bandScale q.g q.U q.l/2≤(⌊bandScale q.g q.U q.l/s.meanLog⌋₊:ℝ)*s.meanLog := by + linarith only [hm,hVL] + simpa only [q.size,bandSize] using ht + +lemma EntropyBand.size_pos {s : SplitSieve} {D δ : ℝ} {ns : List ℕ} {N b : ℕ} + (q : EntropyBand s D ns N b δ) (hmean : 0< s.meanLog) : 0 X ω ∈ L (C ω) ∧ ((L (C ω)).card:ℝ) ≤ b) + a*(Real.log (Fintype.card α)-Real.log b)-Real.binEntropy a ≤ + Real.log (Fintype.card α)-p.cHf X C := by + dsimp only + have hh := p.short_list_deficit X C L + (fun ω => decide (X ω ∈ L (C ω) ∧ ((L (C ω)).card:ℝ) ≤ b)) hb + (fun ω _ he => of_decide_eq_true he) + have ha : (p.map (fun ω => decide (X ω ∈ L (C ω) ∧ ((L (C ω)).card:ℝ) ≤ b))) true = + p.prob (fun ω => X ω ∈ L (C ω) ∧ ((L (C ω)).card:ℝ) ≤ b) := by + simp only [map_mass,decide_eq_true_eq,prob] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> rfl + rw [ha] at hh + simpa only [condH,← Hf_eq_H,cHf] using hh + +lemma average_deficit_lower {ι : Type uIota} [Fintype ι] (w : FinLaw ι) + (a d : ι → ℝ) {a₀ v : ℝ} (ha : ∀ i, a i ∈ Set.Icc (0:ℝ) 1) + (ha₀ : 0 < a₀) (hav : a₀ ≤ ∑ i, w i*a i) + (hv : 2*(1-Real.log a₀) ≤ v) + (hdef : ∀ i, a i*v-Real.binEntropy (a i) ≤ d i) : + a₀*v/2 ≤ ∑ i, w i*d i := by + let A := ∑ i, w i*a i + have hA : 0 < A := lt_of_lt_of_le ha₀ hav + have hA1 : A ≤ 1 := by + have hh := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + mul_le_mul_of_nonneg_left (ha i).2 (w.nonneg i)) + simpa only [mul_one,w.sum_one] using hh + have ha₀1 : a₀ ≤ 1 := hav.trans hA1 + have hl : Real.log a₀ ≤ Real.log A := Real.log_le_log ha₀ hav + have hl0 : Real.log a₀ ≤ 0 := Real.log_nonpos ha₀.le ha₀1 + have hv0 : 0 ≤ v := by linarith only [hv,hl0] + have hh := w.binEntropy_sum_le a ha + have hp := binEntropy_le_log_inverse hA hA1 + have hdl := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + mul_le_mul_of_nonneg_left (hdef i) (w.nonneg i)) + rw [show (∑ i, w i*(a i*v-Real.binEntropy (a i))) = + A*v-∑ i, w i*Real.binEntropy (a i) by + simp only [mul_sub,Finset.sum_sub_distrib,← mul_assoc,← Finset.sum_mul,A]] at hdl + have hlog := mul_le_mul_of_nonneg_left hl hA.le + have hmult := mul_le_mul_of_nonneg_left hv hA.le + have ham := mul_le_mul_of_nonneg_right hav hv0 + change (∑ i, w i*Real.binEntropy (a i)) ≤ Real.binEntropy A at hh + nlinarith only [hdl,hh,hp,hlog,hmult,ham] + +theorem shared_coverage_deficit {Γ : Type uCapitalGamma} {G : Type uGroup} [Fintype Γ] [Fintype G] [AddCommGroup G] + (p : FinLaw Ω) (q : Ω → FinLaw Γ) (Y : Ω → G) (h : Γ → G) + (K : Finset G) (hK : K.Nonempty) (E : Ω → Finset G) (Bad : Ω → Prop) + {τ δ ε b : ℝ} {n : ℕ} (hn : 0 Y v.1+h v.2∈K) ≤ τ*K.card/(Fintype.card G:ℝ)) + (hq : ∀ ω, ¬ Bad ω → ∀ y ∉ E ω, (τ+4*δ)/(Fintype.card G:ℝ) ≤ (q ω).map h y) + (hE : ∀ ω, ¬ Bad ω → ((E ω).card:ℝ)/δ≤b) + (herr : (Fintype.card G:ℝ)*Real.exp (-(n:ℝ)*δ^2*K.card/(2*(Fintype.card G:ℝ)))≤ε) : + let P := p.joint (fun ω => (q ω).iid n) + let L := fun v : Fin n → Γ => coverageList K n τ δ (fun i => h (v i)) + let a := P.prob (fun v => Y v.1 ∈ L v.2 ∧ ((L v.2).card:ℝ)≤b) + δ/(τ+δ)-p.prob Bad-ε ≤ a ∧ + a*(Real.log (Fintype.card G)-Real.log b)-Real.binEntropy a ≤ + Real.log (Fintype.card G)-P.cHf (fun v => Y v.1) Prod.snd := by + dsimp only + constructor + · have htrue := p.true_coverageList_probability q Y h K hK hτ hδ hn hp + have hsize := p.coverageList_size_probability q h K hK E Bad hτ hτ1 hδ hδ1 hε n hq hE herr + have hi := (p.joint (fun ω => (q ω).iid n)).prob_inter_ge + (fun v => Y v.1 ∈ coverageList K n τ δ (fun i => h (v.2 i))) + (fun v => ((coverageList K n τ δ (fun i => h (v.2 i))).card:ℝ)≤b) + simp only [not_le] at hi + linarith only [htrue,hsize,hi] + · exact short_list_probability_deficit (p.joint (fun ω => (q ω).iid n)) + (fun v => Y v.1) Prod.snd + (fun v => coverageList K n τ δ (fun i => h (v i))) hb + +end FinLaw + +lemma perm_expect_apply {ι : Type uIota} [Fintype ι] [DecidableEq ι] (f : ι → ℝ) (i : ι) : + (𝔼 π : Equiv.Perm ι, f (π i)) = 𝔼 j, f j := by + let : Nonempty ι := ⟨i⟩ + calc + _ = 𝔼 j : ι, 𝔼 π : Equiv.Perm ι, f (π j) := by + rw [show (fun j : ι => 𝔼 π : Equiv.Perm ι, f (π j)) = + (fun _ => 𝔼 π : Equiv.Perm ι, f (π i)) by + funext j; exact perm_expect_exchange f j i] + simp only [Fintype.expect_const] + _ = 𝔼 π : Equiv.Perm ι, 𝔼 j : ι, f (π j) := Finset.expect_comm _ _ _ + _ = _ := by + have he (π : Equiv.Perm ι) : (𝔼 j, f (π j)) = 𝔼 j, f j := + Fintype.expect_equiv π _ _ (fun _ => rfl) + simp only [he,Fintype.expect_const] + +namespace FinLaw +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} [Fintype Ω] {k : ℕ} + +lemma Hf_sub_le_cHf (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.Hf X-p.Hf Y ≤ p.cHf X Y := by + have h := p.Hf_pair_ge_snd Y X + rw [p.Hf_pair_comm Y X] at h + exact sub_le_sub_right h _ + +lemma orderedEntropy_conditioning (p : FinLaw Ω) (X : Ω → Fin k → α) + (C : Ω → β) {b : ℕ} (hb : b ≤ k) : + p.orderedEntropy X b-p.Hf C ≤ + b*(𝔼 i : Fin k, p.cHf (fun ω => X ω i) C) := by + have hh (π : Equiv.Perm (Fin k)) : + p.Hf (prefixVar X π b)-p.Hf C ≤ + ∑ i : Fin b, p.cHf (fun ω => X ω (π ⟨i.val,lt_of_lt_of_le i.isLt hb⟩)) C := by + apply (p.Hf_sub_le_cHf _ C).trans + apply (p.cHf_le_of_determined _ + (fun ω (i : Fin b) => X ω (π ⟨i.val,lt_of_lt_of_le i.isLt hb⟩)) C ?_).trans + (p.cHf_fintype_subadd _ C) + intro ω ν hx _ + funext i + by_cases hi : i.val hh π) + have he (i : Fin b) : + (𝔼 π : Equiv.Perm (Fin k), p.cHf (fun ω => X ω (π ⟨i.val,lt_of_lt_of_le i.isLt hb⟩)) C) = + 𝔼 j : Fin k, p.cHf (fun ω => X ω j) C := + perm_expect_apply (fun j => p.cHf (fun ω => X ω j) C) _ + simpa only [orderedEntropy,Finset.expect_sub_distrib,Fintype.expect_const, + Finset.expect_sum_comm,he,Finset.sum_const,Finset.card_univ, + Fintype.card_fin,nsmul_eq_mul] using hav + +lemma signedEntropy_conditioning (p : FinLaw Ω) (X : (Fin k → Bool) → Ω → Fin k → α) + (C : Ω → β) {b : ℕ} (hb : b ≤ k) : + p.signedEntropy X b-p.Hf C ≤ + b*(𝔼 σ : Fin k → Bool, 𝔼 i : Fin k, p.cHf (fun ω => X σ ω i) C) := by + have h := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => + p.orderedEntropy_conditioning (X σ) C hb) + simpa only [signedEntropy,Finset.expect_sub_distrib,Fintype.expect_const, + Finset.mul_expect] using h + +end FinLaw + +theorem SplitSieve.coverage_conditioning {Ω : Type uOmega} {β : Type uBeta} [Fintype Ω] + (s : SplitSieve) (p : FinLaw Ω) (Y : Ω → GaussianInt) (C : Ω → β) + {b : ℕ} (hb : b ≤ s.primes.card) : + s.pointEntropy p Y b-p.Hf C ≤ + b*(𝔼 σ : Fin s.primes.card → Bool, 𝔼 i : Fin s.primes.card, + p.cHf (fun ω => s.residueVector σ (Y ω) i) C) := + p.signedEntropy_conditioning _ C hb + +namespace FinLaw + +section + +theorem backward_coverage_step {Ω : Type uOmega} {Γ : Type uCapitalGamma} {ι : Type uIota} [Fintype Ω] [Fintype Γ] [Fintype ι] + (G : ι → Type uGroup) [∀ i, Fintype (G i)] [∀ i, AddCommGroup (G i)] + (w : FinLaw ι) (p : FinLaw Ω) (q : Ω → FinLaw Γ) + (Y : (i : ι) → Ω → G i) (h : (i : ι) → Γ → G i) + (Bad₀ : ι → Prop) (Bad₁ : ι → Ω → Prop) + (K : (i : ι) → Finset (G i)) (E : (i : ι) → Ω → Finset (G i)) + (b : ι → ℝ) {τ δ ε η η' e v : ℝ} {n : ℕ} + (hn : 0 < n) (hτ : 0 ≤ τ) (hτ1 : τ ≤ 3/8) + (hδ : 0 < δ) (hδ1 : δ ≤ 1/64) (hε : 0 ≤ ε) (hη : 0 < η) + (hnext : ∑ i, w i*p.prob (Bad₁ i) ≤ η') + (hsmall : η'+ε ≤ η*δ/2) + (hscale : 2*(1-Real.log (η*δ/2)) ≤ v) + (hgap : e < η*δ*v/4) + (hdata : (∑ i, w i*(Real.log (Fintype.card (G i))- + (p.joint (fun ω => (q ω).iid n)).cHf (fun x => Y i x.1) Prod.snd)) ≤ e) + (hK : ∀ i, Bad₀ i → (K i).Nonempty) + (hb : ∀ i, Bad₀ i → 1 ≤ b i) + (hv : ∀ i, Bad₀ i → v ≤ Real.log (Fintype.card (G i))-Real.log (b i)) + (hp : ∀ i, Bad₀ i → (p.joint q).prob (fun x => Y i x.1+h i x.2 ∈ K i) ≤ + τ*(K i).card/(Fintype.card (G i):ℝ)) + (hq : ∀ i, Bad₀ i → ∀ ω, ¬Bad₁ i ω → ∀ y ∉ E i ω, + (τ+4*δ)/(Fintype.card (G i):ℝ) ≤ (q ω).map (h i) y) + (hE : ∀ i, Bad₀ i → ∀ ω, ¬Bad₁ i ω → ((E i ω).card:ℝ)/δ ≤ b i) + (herr : ∀ i, Bad₀ i → (Fintype.card (G i):ℝ)* + Real.exp (-(n:ℝ)*δ^2*(K i).card/(2*(Fintype.card (G i):ℝ))) ≤ ε) : + w.prob Bad₀ ≤ η := by + let P := p.joint (fun ω => (q ω).iid n) + let L := fun i (x : Fin n → Γ) => coverageList (K i) n τ δ (fun j => h i (x j)) + let a := fun i => if Bad₀ i then P.prob + (fun x => Y i x.1 ∈ L i x.2 ∧ ((L i x.2).card:ℝ) ≤ b i) else 0 + let d := fun i => Real.log (Fintype.card (G i))-P.cHf (fun x => Y i x.1) Prod.snd + have hd (i : ι) : 0 ≤ d i := by + exact sub_nonneg.mpr ((P.cHf_le_Hf _ _).trans (P.Hf_le_log_card_type _)) + have ha (i : ι) : a i ∈ Set.Icc (0:ℝ) 1 := by + dsimp only [a] + split_ifs + · exact ⟨P.prob_nonneg _,P.prob_le_one _⟩ + · norm_num + have hstep (i : ι) (hi : Bad₀ i) : + δ-p.prob (Bad₁ i)-ε ≤ a i ∧ a i*v-Real.binEntropy (a i) ≤ d i := by + have hh := shared_coverage_deficit p q (Y i) (h i) (K i) (hK i hi) (E i) (Bad₁ i) + hn hτ hτ1 hδ hδ1 hε (hb i hi) (hp i hi) (hq i hi) (hE i hi) (herr i hi) + dsimp only at hh + have hh' : δ/(τ+δ)-p.prob (Bad₁ i)-ε ≤ a i ∧ + a i*(Real.log (Fintype.card (G i))-Real.log (b i))-Real.binEntropy (a i) ≤ d i := by + simpa only [a,hi,ite_eq_left,P,L,d] using hh + constructor + · have htd : 0 < τ+δ := by linarith only [hτ,hδ] + have htd1 : τ+δ ≤ 1 := by linarith only [hτ1,hδ1] + have hfrac : δ ≤ δ/(τ+δ) := (le_div_iff₀ htd).mpr (by nlinarith only [htd1,hδ]) + linarith only [hh'.1,hfrac] + · have hm := mul_le_mul_of_nonneg_left (hv i hi) (ha i).1 + linarith only [hh'.2,hm] + have hl (i : ι) : δ*(if Bad₀ i then (1:ℝ) else 0)-p.prob (Bad₁ i)-ε ≤ a i := by + by_cases hi : Bad₀ i + · simpa only [hi,ite_true,mul_one] using (hstep i hi).1 + · simp only [hi,ite_false,mul_zero,a] + linarith only [p.prob_nonneg (Bad₁ i),hε] + have hdef (i : ι) : a i*v-Real.binEntropy (a i) ≤ d i := by + by_cases hi : Bad₀ i + · exact (hstep i hi).2 + · simpa only [a,hi,ite_false,Real.binEntropy_zero,zero_mul,sub_zero] using hd i + by_contra hc + have hθη : η < w.prob Bad₀ := lt_of_not_ge hc + have hlavg := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + mul_le_mul_of_nonneg_left (hl i) (w.nonneg i)) + have heq : (∑ i, w i*(δ*(if Bad₀ i then (1:ℝ) else 0)-p.prob (Bad₁ i)-ε)) = + δ*w.prob Bad₀-(∑ i, w i*p.prob (Bad₁ i))-ε := by + simp only [mul_sub,Finset.sum_sub_distrib,← Finset.sum_mul,w.sum_one,one_mul,prob, + Finset.mul_sum] + congr 2 + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> ring + rw [heq] at hlavg + have hav : η*δ/2 ≤ ∑ i, w i*a i := by + have hm := mul_le_mul_of_nonneg_left hθη.le hδ.le + linarith only [hlavg,hm,hnext,hsmall] + have hbnd := average_deficit_lower w a d ha (by positivity : 0 < η*δ/2) hav hscale hdef + change (∑ i, w i*d i) ≤ e at hdata + nlinarith only [hbnd,hdata,hgap] + +variable {Ω : Type uOmega} {G : Type uGroup} [Fintype Ω] [Fintype G] + +theorem low_mass_average {ι : Type uIota} [Fintype ι] + (G : ι → Type uGroup) [∀ i, Fintype (G i)] + (w : FinLaw ι) (p : (i : ι) → FinLaw (G i)) + (K : (i : ι) → Finset (G i)) (Bad : ι → Prop) {b e : ℝ} + (hb : 0 < b) + (hK : ∀ i, ∀ x ∈ K i, p i x ≤ (3/8:ℝ)/(Fintype.card (G i):ℝ)) + (hbad : ∀ i, Bad i → b ≤ ((K i).card:ℝ)/(8*(Fintype.card (G i):ℝ))) + (hdef : (∑ i, w i*(Real.log (Fintype.card (G i))-(p i).entropy)) ≤ e) : + w.prob Bad ≤ e/b := by + have h (i : ι) : b*(if Bad i then (1:ℝ) else 0) ≤ + Real.log (Fintype.card (G i))-(p i).entropy := by + by_cases hi : Bad i + · simp only [hi,ite_true,mul_one] + exact (hbad i hi).trans ((p i).low_mass_deficit (K i) (by + intro x hx + convert hK i x hx using 1; ring)) + · simp only [hi,ite_false,mul_zero] + exact sub_nonneg.mpr (p i).entropy_le_log_card + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + mul_le_mul_of_nonneg_left (h i) (w.nonneg i)) + have he : (∑ i, w i*(b*(if Bad i then (1:ℝ) else 0)))=b*w.prob Bad := by + rw [prob,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> ring + rw [he] at hs + apply (le_div_iff₀ hb).mpr + linarith only [hs,hdef] + +end + +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} [Fintype Ω] [Fintype α] [Fintype β] + +lemma uniform_map_perm [Nonempty Ω] (e : Equiv.Perm Ω) : (uniform Ω).map e = uniform Ω := by + ext x + rw [map_equiv_mass] + rfl + +lemma prob_uniform (E : Ω → Prop) [Nonempty Ω] : + (uniform Ω).prob E = ((Finset.univ.filter E).card:ℝ)/(Fintype.card Ω:ℝ) := by + simp only [prob,uniform_mass,div_eq_mul_inv] + rw [← Finset.sum_boole] + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + +lemma uniform_no_wrap (n a : ℕ) (ha : a ≤ n+1) : + (uniform (Fin (n+1))).prob (fun i => i.val+a i.val+a i.val i.val+a (k:ℝ)) hcard using 1 + congr 2 + ext i + simp + · simp + _ = _ := by + rw [Nat.cast_sub ha,Nat.cast_add,Nat.cast_one] + field_simp + +lemma joint_perm_second (p : FinLaw Ω) {Γ : Type uCapitalGamma} [Fintype Γ] [Nonempty Γ] + (e : Equiv.Perm Γ) : + (p.joint (fun _ => uniform Γ)).map (fun v => (v.1,e v.2)) = p.joint (fun _ => uniform Γ) := by + have h := joint_map_fiber p (fun _ => uniform Γ) (fun _ v => e v) + simpa only [uniform_map_perm] using h + +lemma smoothing_prob (p : FinLaw Ω) (t : Ω → ℕ) (n a : ℕ) (ha : a≤n) + (E : ℕ → Prop) : + (p.joint (fun _ => uniform (Fin (n+1)))).prob (fun v => E (t v.1+v.2.val)) ≤ + (p.joint (fun _ => uniform (Fin (n+1)))).prob (fun v => E (t v.1+v.2.val+a))+ + (a:ℝ)/(n+1) := by + let e : Equiv.Perm (Fin (n+1)) := Equiv.addRight ⟨a,by omega⟩ + let P := p.joint (fun _ => uniform (Fin (n+1))) + have hprob : P.prob (fun v => E (t v.1+(e v.2).val)) = + P.prob (fun v => E (t v.1+v.2.val)) := by + have hh := congrArg (fun Q : FinLaw (Ω × Fin (n+1)) => Q.prob + (fun v => E (t v.1+v.2.val))) (p.joint_perm_second e) + simpa only [prob_map] using hh + have hgood : P.prob (fun v => v.2.val+a E (t v.1+(e v.2).val) ∧ v.2.val+a E (t v.1+v.2.val+a)) := by + apply P.prob_mono + intro v hv + have he : (e v.2).val = v.2.val+a := by + change (v.2+(⟨a,by omega⟩ : Fin (n+1))).val = _ + exact Fin.val_add_eq_of_add_lt hv.2 + simpa only [he,Nat.add_assoc] using hv.1 + have hh := P.prob_inter_ge (fun v => E (t v.1+(e v.2).val)) (fun v => v.2.val+a v.2.val+a uniform (Fin (n+1)))).condH + (fun v => X (t v.1+v.2.val+a)) (fun v => C (t v.1+v.2.val+a)) ≤ + (p.joint (fun _ => uniform (Fin (n+1)))).condH + (fun v => X (t v.1+v.2.val)) (fun v => C (t v.1+v.2.val)) + + 2*Real.binEntropy ((a:ℝ)/(n+1))+ + ((a:ℝ)/(n+1))*(Real.log (Fintype.card α)+2*Real.log (Fintype.card β)) := by + let e : Equiv.Perm (Fin (n+1)) := Equiv.addRight ⟨a,by omega⟩ + let P := p.joint (fun _ => uniform (Fin (n+1))) + let good := fun v : Ω × Fin (n+1) => decide (v.2.val+a v.2.val+a rfl + rw [hh,prob_joint] + simp only [uniform_no_wrap n a (by omega), + ← Finset.sum_mul,p.sum_one,one_mul] + have he : P.condH (fun v => X (t v.1+(e v.2).val)) (fun v => C (t v.1+(e v.2).val)) = + P.condH (fun v => X (t v.1+v.2.val)) (fun v => C (t v.1+v.2.val)) := by + have hh := congrArg (fun Q : FinLaw (Ω × Fin (n+1)) => + Q.condH (fun v => X (t v.1+v.2.val)) (fun v => C (t v.1+v.2.val))) (p.joint_perm_second e) + simpa only [condH,H_map,Function.comp_def] using hh + have h := P.condH_sub_condH_of_agree + (fun v => X (t v.1+v.2.val+a)) (fun v => X (t v.1+(e v.2).val)) + (fun v => C (t v.1+v.2.val+a)) (fun v => C (t v.1+(e v.2).val)) good (by + intro v _ hv + have hlt : v.2.val+a residueCode f.val (z a)) (incrementWord z L) + (fun a (f : F) => residueCode f.val (z a)) / L := by + let Q := (TimeLaw.at 0).advance (commonSchedule z q.pre 0) + have hOld : Q.law.Hf (fun t (f : F) => residueCode f.val (z t.val))≤E := + (residue_finset_entropy Q.law (fun t => z t.val) F hf).trans hF + obtain ⟨σ,π,hh⟩ := schedule_batch_information s q.nonempty z hz ha q.pre q.rest hD q.large + q.mean hs q.prime_scale q.band q.u q.coverage (fun f : F => f.val) hOld + q.cap q.repetitions q.length q.floor q.gain q.exceptions q.short q.smooth_length + q.smooth_error q.list q.rate + let f := fun j => s.signedFactorAt (s.selectedIndex q.cap σ π j) + let G := F∪Finset.univ.image f + refine ⟨G,Finset.subset_union_left,?_,?_⟩ + · apply Finset.union_subset Finset.subset_union_left + intro g hg + obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hg + exact Finset.mem_union_right F (s.signed_mem_available _) + · rw [q.schedule] + unfold TimeLaw.info + rw [FinLaw.cIf_finset_union] + exact hh + +theorem greedy_finite_selection (A : ℕ → Finset GaussianInt) + (hA : ∀ j, A j⊆A (j+1)) (n : ℕ) + (R : ℕ → Finset GaussianInt → Finset GaussianInt → Prop) + (hstep : ∀ j≤n, ∀ F⊆A j, ∃ G, F⊆G ∧ G⊆A (j+1) ∧ R j F G) : + ∃ F : ℕ → Finset GaussianInt, + (∀ j, F j⊆A j) ∧ (∀ j, F j⊆F (j+1)) ∧ (∀ j≤n, R j (F j) (F (j+1))) := by + have step (j : ℕ) (F : {F : Finset GaussianInt // F⊆A j}) : + ∃ G : {G : Finset GaussianInt // G⊆A (j+1)}, F.val⊆G.val ∧ (j≤n → R j F.val G.val) := by + by_cases hj : j≤n + · obtain ⟨G,hFG,hG,hR⟩ := hstep j hj F.val F.property + exact ⟨⟨G,hG⟩,hFG,fun _ => hR⟩ + · exact ⟨⟨F.val,F.property.trans (hA j)⟩,Finset.Subset.refl _,fun h => (hj h).elim⟩ + let f (j : ℕ) (F : {F : Finset GaussianInt // F⊆A j}) := (step j F).choose + let F : (j : ℕ) → {F : Finset GaussianInt // F⊆A j} := + @Nat.rec (fun j => {F : Finset GaussianInt // F⊆A j}) ⟨∅,Finset.empty_subset _⟩ f + refine ⟨fun j => (F j).val,fun j => (F j).property,?_,?_⟩ + · intro j + exact (step j (F j)).choose_spec.1 + · intro j hj + exact (step j (F j)).choose_spec.2 hj + +noncomputable def precedingFactors (s : ℕ → SplitSieve) (j : ℕ) : Finset GaussianInt := + (Finset.range j).biUnion (fun i => (s i).availableFactors) + +lemma precedingFactors_mono (s : ℕ → SplitSieve) {i j : ℕ} (h : i≤j) : + precedingFactors s i⊆precedingFactors s j := +by + intro f hf + obtain ⟨k,hk,hf⟩ := Finset.mem_biUnion.mp hf + exact Finset.mem_biUnion.mpr ⟨k,(Finset.range_mono h) hk,hf⟩ + +lemma precedingFactors_succ (s : ℕ → SplitSieve) (j : ℕ) : + precedingFactors s (j+1)=precedingFactors s j∪(s j).availableFactors := by + simp only [precedingFactors,Finset.range_add_one,Finset.biUnion_insert,Finset.union_comm] + +lemma precedingFactors_ne_zero (s : ℕ → SplitSieve) {j : ℕ} {f : GaussianInt} + (h : f∈precedingFactors s j) : f≠0 := by + obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp h + exact (s i).available_ne_zero hi + +theorem certificate_no_walk {D ε : ℝ} (hD : 1≤D) (ns : List ℕ) (N n : ℕ) + (s : ℕ → SplitSieve) (L : ℕ → ℕ) (r : ℕ → ℝ) + (cert : ∀ j≤n, BatchCertificate D ns N (s j) (L j) + (residueWeight (precedingFactors s j)) (r j)) + (hdiv : ∀ j residueCode f.val (z a)) (incrementWord z (L j)) + (fun a (f : F) => residueCode f.val (z a)) / L j + obtain ⟨F,hFA,hFF,hR⟩ := greedy_finite_selection (precedingFactors s) + (fun j => precedingFactors_mono s (Nat.le_succ j)) n + (fun j F G => r j≤rate j F G) (by + intro j hj F hF + obtain ⟨G,hFG,hG,hI⟩ := (cert j hj).sound hD z hz (ha j hj) hs F + (fun f hf => precedingFactors_ne_zero s (hF hf)) (residueWeight_mono hF) + refine ⟨G,hFG,?_,hI⟩ + rw [precedingFactors_succ] + exact hG.trans (Finset.union_subset_union_left hF)) + have ht := schedule_information_telescope z hs ns N n F hFF + (fun j f hf => precedingFactors_ne_zero s (hFA j hf)) L + (fun j hj => (cert j hj).length) hdiv (fun j hj => (cert j hj).smooth_length) hε (by + intro j hj a ha + have hw := residueWeight_mono ((hFA (j+1)).trans (precedingFactors_mono s (j := n+1) (by omega))) + have hh := herr j hj a ha + have hx : 0≤(a:ℝ)/(N+1) := by positivity + change _+_ * (_+2*residueWeight (F (j+1)))≤ε + nlinarith only [hw,hh,hx]) + have hh := Finset.sum_le_sum (s := Finset.range (n+1)) (fun j hj => hR j (by simpa only [Finset.mem_range,Nat.lt_succ_iff] using hj)) + exact (not_lt_of_ge (hh.trans ht)) hexcess + +open scoped BigOperators Classical +open Filter + +theorem thin_bins (J : Finset ℕ) {K : ℕ} (hK : 0 j%K=a)).card ∧ + ∀ i∈J.filter (fun j => j%K=a), ∀ j∈J.filter (fun j => j%K=a), + i j%K) + (fun j _ => Finset.mem_range.mpr (Nat.mod_lt _ hK)) + (Finset.nonempty_range_iff.mpr hK.ne') hh + refine ⟨a,Finset.mem_range.mp ha,hc,?_⟩ + intro i hi j hj hij + have hi' := (Finset.mem_filter.mp hi).2 + have hj' := (Finset.mem_filter.mp hj).2 + have hd : i%K=j%K := hi'.trans hj'.symm + have hei := Nat.mod_add_div i K + have hej := Nat.mod_add_div j K + have hq : i/K j%K=a),?_,hsep,?_⟩ + · have hh := (div_le_div_of_nonneg_right hJ (Nat.cast_nonneg K)).trans hcard + simpa only [div_mul_eq_mul_div] using hh + · intro j hj + exact hp j (Finset.mem_filter.mp hj).1 + +lemma dyadicSieve_available_weight (j : ℕ) : + residueWeight (dyadicSieve j).availableFactors≤4*Real.log 4*(2:ℝ)^j := by + have hp : (∑ p∈PrimeLogMass.dyadicBatch j, Real.log (p:ℝ))≤Real.log 4*(2:ℝ)^(j+1) := + PrimeLogMass.prime_log_mass_le_theta _ (by positivity) (by + intro p hp + have h := (PrimeLogMass.mem_dyadicBatch j p).mp hp + exact ⟨h.2.2.1,by exact_mod_cast h.2.1.le⟩) + have hh := (dyadicSieve j).available_weight + change residueWeight (dyadicSieve j).availableFactors≤2*∑ p∈PrimeLogMass.dyadicBatch j, Real.log (p:ℝ) at hh + rw [pow_succ] at hp + nlinarith only [hh,hp] + +end + +open scoped BigOperators Classical + +lemma bandScale_add (g U : ℝ) (j k : ℕ) : + bandScale g U (j+k)=bandScale g (bandScale g U j) k := by + unfold bandScale + rw [pow_add] + ring + +lemma bandLength_add (g U : ℝ) (j k : ℕ) : + bandLength g U (j+k)=bandLength g (bandScale g U j) k := by + unfold bandLength + rw [bandScale_add] + +lemma bandList_split (g U : ℝ) (j l r : ℕ) : + List.ofFn (fun i : Fin (j+l+r) => bandLength g U i.val)= + List.ofFn (fun i : Fin j => bandLength g U i.val)++ + List.ofFn (fun i : Fin l => bandLength g (bandScale g U j) i.val)++ + List.ofFn (fun i : Fin r => bandLength g (bandScale g U (j+l)) i.val) := by + rw [List.ofFn_add,List.ofFn_add] + simp only [Fin.val_castLE,Fin.val_natAdd,bandLength_add] + +theorem band_first_crossing {g U V : ℝ} {m : ℕ} (hg : 0 simp + | cons n ns ih => + have hn := hns n (List.mem_cons_self ..) + have hi := ih (fun m hm => hns m (List.mem_cons_of_mem n hm)) + simp only [List.sum_cons,List.length_cons,Nat.cast_add,Nat.cast_one] + nlinarith only [hn,hi] + have he : 1≤Real.exp H := Real.one_le_exp_iff.mpr hH + have hc : 0≤(ns.length:ℝ)*Real.exp H := mul_nonneg (Nat.cast_nonneg _) (Real.exp_nonneg _) + have hN : 1≤(N:ℝ)+1 := by linarith only [(Nat.cast_nonneg N : (0:ℝ)≤N)] + have hle : ((ns.sum+N:ℕ)+1:ℝ)≤((ns.length:ℝ)+1)*Real.exp H*((N:ℝ)+1) := by + simp only [Nat.cast_add] + nlinarith only [hs,he,hc,hN,(Nat.cast_nonneg N : (0:ℝ)≤N)] + have hh := Real.log_le_log (show (0:ℝ)<((ns.sum+N:ℕ)+1) by positivity) hle + rw [Real.log_mul (by positivity) (by positivity),Real.log_mul (by positivity) (Real.exp_ne_zero _), + Real.log_exp] at hh + exact hh + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/BatchParameters.lean b/lean/OAI/NumberTheory/GaussianMoat/BatchParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..50f05d151ae82d2c9b9d06d83546fc55cf4481b8 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/BatchParameters.lean @@ -0,0 +1,281 @@ +import OAI.NumberTheory.GaussianMoat.WindowParameters + +namespace OAI + +namespace GaussianMoat +open scoped BigOperators Classical + +theorem one_step_coverage (s : SplitSieve) (D : ℝ) (N : ℕ) + (mid bot : List ℕ) (b q n : ℕ) (e ebase : ℝ) + (u : s.SignedIndex → ℝ) + (hm : EntropyBand s D mid 0 b e) + (hb : EntropyBand s D bot N q ebase) + (hb0 : 0 Real.exp (-100)/64*(s.signedPrime i:ℝ) + let C : s.SignedIndex → ℝ := fun i => Real.exp (-100)*(s.signedPrime i:ℝ) + have hc : 0 a*x) atTop atTop := tendsto_id.const_mul_atTop ha + filter_upwards [ht.eventually h] with X hX + simp only [one_mul,mul_pow] at hX + convert hX using 1; field_simp + +lemma eventually_mul_exp_le_exp {a b : ℝ} (hab : a nlinarith only [hh1,hh2] + +lemma batchWordLength_le_scale (j : ℕ) : (batchWordLength j:ℝ)≤(2:ℝ)^j := by + unfold batchWordLength + push_cast + apply pow_le_pow_right₀ (by norm_num : (1:ℝ)≤2) + omega + +theorem eventually_integer_batch_bounds {D : ℝ} (hD : 1≤D) : + ∀ᶠ X : ℝ in atTop, ∀ j : ℕ, + X≤j*Real.log 2 → j*Real.log 2≤21/20*X → + 0 Unit + | n + 1 => Bool × Cube n +instance cubeFintype : (n : ℕ) → Fintype (Cube n) + | 0 => inferInstanceAs (Fintype Unit) + | n + 1 => @instFintypeProd Bool (Cube n) inferInstance (cubeFintype n) +instance cubeDecidableEq : (n : ℕ) → DecidableEq (Cube n) + | 0 => inferInstanceAs (DecidableEq Unit) + | n + 1 => @instDecidableEqProd Bool (Cube n) inferInstance (cubeDecidableEq n) +def cubeDist : (n : ℕ) → Cube n → Cube n → ℕ + | 0, _, _ => 0 + | n + 1, (b,x), (c,y) => (if b = c then 0 else 1) + cubeDist n x y +@[simp] theorem cubeDist_self (n : ℕ) (x : Cube n) : cubeDist n x x = 0 := by + induction n with + | zero => rfl + | succ n ih => obtain ⟨b,x⟩ := x; simp [cubeDist, ih] +@[simp] theorem cubeDist_zero_iff (n : ℕ) (x y : Cube n) : cubeDist n x y = 0 ↔ x = y := by + induction n with + | zero => simp only [cubeDist] + | succ n ih => + obtain ⟨b,x⟩ := x + obtain ⟨c,y⟩ := y + by_cases h : b = c <;> simp [cubeDist, h, ih, Prod.mk.injEq] +theorem cubeDist_symm (n : ℕ) (x y : Cube n) : cubeDist n x y = cubeDist n y x := by + induction n with + | zero => rfl + | succ n ih => + obtain ⟨b,x⟩ := x + obtain ⟨c,y⟩ := y + simp [cubeDist, eq_comm (a := b) (b := c), ih x y] +theorem cubeDist_triangle (n : ℕ) (x y z : Cube n) : + cubeDist n x z ≤ cubeDist n x y + cubeDist n y z := by + induction n with + | zero => simp [cubeDist] + | succ n ih => + obtain ⟨b,x⟩ := x + obtain ⟨c,y⟩ := y + obtain ⟨d,z⟩ := z + have h := ih x y z + cases b <;> cases c <;> cases d <;> simp [cubeDist] <;> omega + +noncomputable def cubeSize {n : ℕ} (S : Cube n → Prop) : ℕ := by + classical + exact ∑ x, if S x then 1 else 0 +noncomputable def cubeBoundary {n : ℕ} (S : Cube n → Prop) : ℕ := by + classical + exact ∑ x, ∑ y, if S x ∧ ¬ S y ∧ cubeDist n x y = 1 then 1 else 0 +noncomputable def cubeCross {n : ℕ} (A B : Cube n → Prop) : ℕ := by + classical + exact ∑ x, if A x ∧ ¬ B x then 1 else 0 + +theorem cubeSize_succ {n : ℕ} (S : Cube (n+1) → Prop) : + cubeSize S = cubeSize (fun x => S (false,x)) + cubeSize (fun x => S (true,x)) := by + classical + simp only [cubeSize, Fintype.sum_prod_type, Fintype.sum_bool] + ac_rfl + +theorem cubeBoundary_succ {n : ℕ} (S : Cube (n+1) → Prop) : + cubeBoundary S = cubeBoundary (fun x => S (false,x)) + cubeBoundary (fun x => S (true,x)) + + cubeCross (fun x => S (false,x)) (fun x => S (true,x)) + + cubeCross (fun x => S (true,x)) (fun x => S (false,x)) := by + classical + simp only [cubeBoundary, cubeCross, Fintype.sum_prod_type, Fintype.sum_bool, cubeDist, + Bool.false_eq_true, Bool.true_eq_false, ↓reduceIte, zero_add, Nat.add_eq_left, + cubeDist_zero_iff, Finset.sum_add_distrib] + simp only [and_assoc, and_left_comm, and_comm, ite_and, Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte] + omega + +theorem cubeCross_card_le {n : ℕ} (A B : Cube n → Prop) : cubeSize A ≤ cubeSize B + cubeCross A B := by + classical + rw [cubeSize, cubeSize, cubeCross, ← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro x _ + by_cases ha : A x <;> by_cases hb : B x <;> simp [ha, hb] + +theorem cube_degree (n : ℕ) (x : Cube n) : (∑ y, if cubeDist n x y = 1 then 1 else 0) = n := by + classical + induction n with + | zero => simp [cubeDist] + | succ n ih => + obtain ⟨b,x⟩ := x + cases b <;> simp only [Fintype.sum_prod_type, Fintype.sum_bool, cubeDist, + Bool.false_eq_true, Bool.true_eq_false, ↓reduceIte, zero_add, Nat.add_eq_left, + cubeDist_zero_iff, Finset.sum_ite_eq, Finset.mem_univ, ↓reduceIte, ih] + omega + +theorem binEntropy_ge_two_mul {p : ℝ} (hp0 : 0 ≤ p) (hp2 : p ≤ 1/2) : + 2 * p * Real.log 2 ≤ Real.binEntropy p := by + have hc : ConcaveOn ℝ (Set.Icc 0 1) Real.binEntropy := Real.strictConcave_binEntropy.concaveOn + have h := hc.2 (show (0 : ℝ) ∈ Set.Icc 0 1 by norm_num) + (show (2 : ℝ)⁻¹ ∈ Set.Icc 0 1 by norm_num) + (show 0 ≤ 1 - 2*p by linarith) (show 0 ≤ 2*p by positivity) (by ring) + simpa only [smul_eq_mul, Real.binEntropy_zero, Real.binEntropy_two_inv, + mul_zero, zero_add, show 2*p*(2:ℝ)⁻¹ = p by ring] using h + +theorem entropy_merge_of_le {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) : + 2 * a * Real.log 2 ≤ (a+b)*Real.log (a+b) - a*Real.log a - b*Real.log b := by + by_cases ha0 : a = 0 + · simp [ha0] + have hap : 0 < a := lt_of_le_of_ne ha (Ne.symm ha0) + have hbp : 0 < b := hap.trans_le hab + have ht : 0 < a+b := by positivity + have hp0 : 0 ≤ a/(a+b) := by positivity + have hp2 : a/(a+b) ≤ 1/2 := (div_le_iff₀ ht).mpr (by linarith) + have h := mul_le_mul_of_nonneg_left (binEntropy_ge_two_mul hp0 hp2) ht.le + have heq : (a+b) * Real.binEntropy (a/(a+b)) = + (a+b)*Real.log (a+b) - a*Real.log a - b*Real.log b := by + have hsub : 1-a/(a+b) = b/(a+b) := by field_simp; ring + rw [Real.binEntropy, hsub, Real.log_inv, Real.log_inv, + Real.log_div hap.ne' ht.ne', Real.log_div hbp.ne' ht.ne'] + field_simp + ring + rw [heq] at h + have heq' : (a+b) * (2 * (a/(a+b)) * Real.log 2) = 2*a*Real.log 2 := by + field_simp + rwa [heq'] at h + +theorem entropy_merge {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : + 2 * min a b * Real.log 2 ≤ (a+b)*Real.log (a+b) - a*Real.log a - b*Real.log b := by + rcases le_total a b with hab | hba + · simpa [min_eq_left hab] using entropy_merge_of_le ha hab + · have h := entropy_merge_of_le hb hba + rw [min_eq_right hba] + convert h using 1 + rw [add_comm b a] + ring + +theorem cube_edge_isoperimetric (n : ℕ) (S : Cube n → Prop) : + (cubeSize S : ℝ) * ((n : ℝ) * Real.log 2 - Real.log (cubeSize S)) ≤ + (cubeBoundary S : ℝ) * Real.log 2 := by + classical + induction n with + | zero => + by_cases hs : S () <;> simp [cubeSize, cubeBoundary, cubeDist, hs] + | succ n ih => + have h0 := ih (fun x => S (false,x)) + have h1 := ih (fun x => S (true,x)) + have hac := cubeCross_card_le (fun x => S (false,x)) (fun x => S (true,x)) + have hbc := cubeCross_card_le (fun x => S (true,x)) (fun x => S (false,x)) + have hac' : (cubeSize (fun x => S (false,x)) : ℝ) ≤ + cubeSize (fun x => S (true,x)) + cubeCross (fun x => S (false,x)) (fun x => S (true,x)) := by + exact_mod_cast hac + have hbc' : (cubeSize (fun x => S (true,x)) : ℝ) ≤ + cubeSize (fun x => S (false,x)) + cubeCross (fun x => S (true,x)) (fun x => S (false,x)) := by + exact_mod_cast hbc + have he := entropy_merge (a := (cubeSize (fun x => S (false,x)) : ℝ)) + (b := (cubeSize (fun x => S (true,x)) : ℝ)) (by positivity) (by positivity) + have hl : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + rw [cubeSize_succ, cubeBoundary_succ] + push_cast + rcases le_total (cubeSize (fun x => S (false,x)) : ℝ) (cubeSize (fun x => S (true,x)) : ℝ) with hab | hba + · rw [min_eq_left hab] at he + have hn : (0 : ℝ) ≤ cubeCross (fun x => S (false,x)) (fun x => S (true,x)) := by positivity + nlinarith + · rw [min_eq_right hba] at he + have hn : (0 : ℝ) ≤ cubeCross (fun x => S (true,x)) (fun x => S (false,x)) := by positivity + nlinarith + +def cubeExpand {n : ℕ} (S : Cube n → Prop) (y : Cube n) : Prop := + S y ∨ ∃ x, S x ∧ cubeDist n x y = 1 + +def cubeExpandIter {n : ℕ} (S : Cube n → Prop) : ℕ → Cube n → Prop + | 0 => S + | h+1 => cubeExpand (cubeExpandIter S h) + +theorem cubeSize_mono {n : ℕ} {S T : Cube n → Prop} (h : ∀ x, S x → T x) : + cubeSize S ≤ cubeSize T := by + classical + apply Finset.sum_le_sum + intro x _ + by_cases hs : S x + · simp [hs, h x hs] + · simp [hs] + +theorem cube_card (n : ℕ) : Fintype.card (Cube n) = 2^n := by + induction n with + | zero => rfl + | succ n ih => + change Fintype.card (Bool × Cube n) = _ + rw [Fintype.card_prod, Fintype.card_bool, ih, pow_succ] + omega + +theorem cubeSize_le (n : ℕ) (S : Cube n → Prop) : cubeSize S ≤ 2^n := by + classical + calc + cubeSize S ≤ ∑ _ : Cube n, 1 := by + apply Finset.sum_le_sum + intro x _ + split_ifs <;> omega + _ = 2^n := by simp [cube_card] + +theorem cubeBoundary_expand_bound {n : ℕ} (S : Cube n → Prop) : + cubeBoundary S + n * cubeSize S ≤ n * cubeSize (cubeExpand S) := by + classical + have hdegree (y : Cube n) : + (∑ x, if S x ∧ ¬ S y ∧ cubeDist n x y = 1 then 1 else 0) ≤ + n * (if ¬S y ∧ (∃ x, S x ∧ cubeDist n x y = 1) then 1 else 0) := by + by_cases hy : ¬S y ∧ (∃ x, S x ∧ cubeDist n x y = 1) + · rw [ite_eq_left hy, mul_one] + calc + _ ≤ ∑ x, if cubeDist n y x = 1 then 1 else 0 := by + apply Finset.sum_le_sum + intro x _ + by_cases h : S x ∧ ¬ S y ∧ cubeDist n x y = 1 + · simp [h, cubeDist_symm n y x] + · simp [h] + _ = n := cube_degree n y + · simp only [hy, ↓reduceIte, mul_zero, Nat.le_zero] + apply Finset.sum_eq_zero + intro x _ + have hnot : ¬(S x ∧ ¬S y ∧ cubeDist n x y = 1) := by + rintro ⟨hs, hns, hd⟩ + exact hy ⟨hns,x,hs,hd⟩ + simp [hnot] + have hb := Finset.sum_le_sum (s := Finset.univ) (fun y _ => hdegree y) + rw [← Finset.mul_sum] at hb + have heq : cubeSize (cubeExpand S) = cubeSize S + + ∑ y, if ¬S y ∧ (∃ x, S x ∧ cubeDist n x y = 1) then 1 else 0 := by + rw [cubeSize, cubeSize, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro y _ + by_cases hs : S y <;> simp [cubeExpand, hs] + unfold cubeBoundary + rw [Finset.sum_comm, heq, Nat.mul_add] + omega + +theorem cubeExpandIter_witness {n h : ℕ} {S : Cube n → Prop} {x : Cube n} + (hx : cubeExpandIter S h x) : ∃ y, S y ∧ cubeDist n y x ≤ h := by + induction h generalizing x with + | zero => exact ⟨x,hx,by simp⟩ + | succ h ih => + rcases hx with hx | ⟨z,hz,hzx⟩ + · obtain ⟨y,hy,hyx⟩ := ih hx + exact ⟨y,hy,by omega⟩ + · obtain ⟨y,hy,hyz⟩ := ih hz + exact ⟨y,hy,by have ht := cubeDist_triangle n y z x; omega⟩ + +theorem cubeExpandIter_disjoint {n h : ℕ} {S T : Cube n → Prop} + (hsep : ∀ x, S x → ∀ y, T y → 2*h < cubeDist n x y) : + ∀ x, ¬(cubeExpandIter S h x ∧ cubeExpandIter T h x) := by + rintro x ⟨hs,ht⟩ + obtain ⟨y,hy,hyx⟩ := cubeExpandIter_witness hs + obtain ⟨z,hz,hzx⟩ := cubeExpandIter_witness ht + have h := hsep y hy z hz + have htri := cubeDist_triangle n y x z + rw [cubeDist_symm n x z] at htri + omega + +theorem cubeSize_sum_le {n : ℕ} {ι : Type uIota} [Fintype ι] (S : ι → Cube n → Prop) + (hd : ∀ i j, i ≠ j → ∀ x, ¬(S i x ∧ S j x)) : + ∑ i, cubeSize (S i) ≤ 2^n := by + classical + unfold cubeSize + rw [Finset.sum_comm] + calc + _ ≤ ∑ _ : Cube n, 1 := by + apply Finset.sum_le_sum + intro x _ + by_cases he : ∃ i, S i x + · obtain ⟨i,hi⟩ := he + rw [Finset.sum_eq_single i] + · simp [hi] + · intro j _ hji + have hnot : ¬S j x := fun hj => hd j i hji x ⟨hj,hi⟩ + simp [hnot] + · simp + · have hh : ∀ i, ¬S i x := by simpa only [not_exists] using he + simp [hh] + _ = 2^n := by simp [cube_card] + +theorem cube_growth {n : ℕ} (hn : 0 < n) (S : Cube n → Prop) {a E : ℝ} + (hE : 0 < E) (hlogE : Real.log E ≤ (n : ℝ) * Real.log 2 - a) + (hsize : (cubeSize S : ℝ) ≤ E) : + (1 + a / ((n : ℝ) * Real.log 2)) * cubeSize S ≤ cubeSize (cubeExpand S) := by + by_cases hz : cubeSize S = 0 + · simp [hz] + have hpos : (0 : ℝ) < cubeSize S := by exact_mod_cast Nat.pos_of_ne_zero hz + have hnpos : (0 : ℝ) < n := by exact_mod_cast hn + have hlogtwo : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hden : 0 < (n : ℝ) * Real.log 2 := mul_pos hnpos hlogtwo + have hl := ((Real.log_le_log_iff hpos hE).mpr hsize).trans hlogE + have hi := cube_edge_isoperimetric n S + have hb : (cubeBoundary S : ℝ) + n * cubeSize S ≤ n * cubeSize (cubeExpand S) := by + exact_mod_cast cubeBoundary_expand_bound S + apply (mul_le_mul_iff_left₀ hden).mp + field_simp at ⊢ + nlinarith [mul_le_mul_of_nonneg_left hl hpos.le, + mul_le_mul_of_nonneg_right hb hlogtwo.le] + +theorem cube_iter_growth {n : ℕ} (S : Cube n → Prop) {δ E : ℝ} (hδ : 0 ≤ δ) + (hgrow : ∀ T : Cube n → Prop, (cubeSize T : ℝ) ≤ E → + (1+δ)*cubeSize T ≤ cubeSize (cubeExpand T)) (h : ℕ) : + min E ((1+δ)^h * cubeSize S) ≤ cubeSize (cubeExpandIter S h) := by + induction h with + | zero => simpa only [pow_zero, one_mul, cubeExpandIter] using + (min_le_right E (cubeSize S : ℝ)) + | succ h ih => + have hmono : (cubeSize (cubeExpandIter S h) : ℝ) ≤ cubeSize (cubeExpandIter S (h+1)) := by + exact_mod_cast cubeSize_mono (S := cubeExpandIter S h) (T := cubeExpand (cubeExpandIter S h)) + (fun _ hx => Or.inl hx) + by_cases hlarge : E ≤ (cubeSize (cubeExpandIter S h) : ℝ) + · exact (min_le_left _ _).trans (hlarge.trans hmono) + · have hsmall : (cubeSize (cubeExpandIter S h) : ℝ) ≤ E := le_of_not_ge hlarge + have hpow : (1+δ)^h * cubeSize S ≤ E := by + by_contra hnot + rw [min_eq_left (le_of_not_ge hnot)] at ih + exact hlarge ih + rw [min_eq_right hpow] at ih + have hmul := mul_le_mul_of_nonneg_left ih (by linarith : 0 ≤ 1+δ) + have hg := hgrow (cubeExpandIter S h) hsmall + apply (min_le_right _ _).trans + simpa only [pow_succ, mul_assoc, mul_left_comm, cubeExpandIter] using hmul.trans hg + +theorem cube_separated_bound {n h : ℕ} (hn : 0 < n) {ι : Type uIota} [Fintype ι] + (S : ι → Cube n → Prop) {a E A : ℝ} (ha : 0 ≤ a) (hE : 0 < E) + (hlogE : Real.log E ≤ (n : ℝ) * Real.log 2 - a) + (hseed : ∀ i, A * cubeSize (S i) ≤ E) + (hfactor : A ≤ (1 + a / ((n : ℝ)*Real.log 2))^h) + (hsep : ∀ i j, i ≠ j → ∀ x, S i x → ∀ y, S j y → 2*h < cubeDist n x y) : + A * (∑ i, (cubeSize (S i) : ℝ)) ≤ (2 : ℝ)^n := by + have hδ : 0 ≤ a / ((n : ℝ)*Real.log 2) := by + apply div_nonneg ha + exact mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg (by norm_num)) + have hlarge (i : ι) : A * cubeSize (S i) ≤ cubeSize (cubeExpandIter (S i) h) := by + apply le_trans (le_min (hseed i) (mul_le_mul_of_nonneg_right hfactor (Nat.cast_nonneg _))) + exact cube_iter_growth (S i) hδ (fun T ht => cube_growth hn T hE hlogE ht) h + rw [Finset.mul_sum] + apply (Finset.sum_le_sum (fun i _ => hlarge i)).trans + have hd : ∀ i j, i ≠ j → ∀ x, ¬(cubeExpandIter (S i) h x ∧ cubeExpandIter (S j) h x) := by + intro i j hij + exact cubeExpandIter_disjoint (hsep i j hij) + exact_mod_cast cubeSize_sum_le (fun i => cubeExpandIter (S i) h) hd + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/CommonBlocks.lean b/lean/OAI/NumberTheory/GaussianMoat/CommonBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6055797497516d1a2edc6e97dd99b778cfee0b2 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/CommonBlocks.lean @@ -0,0 +1,202 @@ +import OAI.NumberTheory.GaussianMoat.Smoothing + +namespace OAI + +namespace GaussianMoat +open scoped BigOperators Classical +open Filter + +noncomputable def commonBlocks (a : ℝ) (m W : ℕ) (J : ℕ → Finset ℕ) : List ℕ := + windowBlocks a m J W++accurateBlock m (1/20) + +noncomputable def middleBlocks (a : ℝ) (m w : ℕ) (J : ℕ → Finset ℕ) : List ℕ := + accurateBlock m ((100:ℝ)^w/4)++windowBlocks a m J w + +lemma windowScale_tendsto (w : ℕ) : + Tendsto (fun m : ℕ => (100:ℝ)^w*Real.exp m) atTop atTop := + (Real.tendsto_exp_atTop.comp tendsto_natCast_atTop_atTop).const_mul_atTop (by positivity) + +lemma dyadic_prime_bounds (j : ℕ) : + ∀ p∈(dyadicSieve j).primes, (2:ℝ)^j≤(p:ℝ) ∧ (p:ℝ)≤2*(2:ℝ)^j := by + intro p hp + have hh := (PrimeLogMass.mem_dyadicBatch j p).mp hp + constructor + · exact_mod_cast hh.1 + · have hh' : p≤2^(j+1) := hh.2.1.le + rw [pow_succ] at hh' + exact_mod_cast (by simpa only [mul_comm] using hh' : p≤2*2^j) + +lemma dyadic_dense_nonempty {δ : ℝ} (hδ : 0<δ) {j : ℕ} + (hd : δ*(2:ℝ)^j/Real.log ((2:ℝ)^(j+1))≤(PrimeLogMass.dyadicBatch j).card) : + (dyadicSieve j).primes.Nonempty := by + apply Finset.card_pos.mp + have hp : 0<δ*(2:ℝ)^j/Real.log ((2:ℝ)^(j+1)) := by rw [Real.log_pow]; positivity + exact_mod_cast hp.trans_le hd + +lemma dyadic_mean_bounds {X : ℝ} (hX : 2≤X) {j : ℕ} + (hne : (dyadicSieve j).primes.Nonempty) + (hlo : X≤j*Real.log 2) (hhi : j*Real.log 2≤21/20*X) : + 1≤(dyadicSieve j).meanLog ∧ (dyadicSieve j).meanLog≤2*X := by + have hh := (dyadicSieve j).meanLog_bounds hne (by positivity) (dyadic_prime_bounds j) + rw [Real.log_mul (by norm_num) (by positivity),Real.log_pow] at hh + have hl2 := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + constructor <;> linarith only [hh.1,hh.2,hlo,hhi,hX,hl2] + +lemma commonBlocks_length {a : ℝ} {m W : ℕ} (J : ℕ → Finset ℕ) (hm : 2≤Real.exp m) + (hJ : ∀ w.trans (hl.trans (Real.exp_le_exp.mpr harg)) + have hNs : (windowSmoothing W m:ℝ)+1≤Real.exp ((20*(100:ℝ)^W+2)*((100:ℝ)^w*Real.exp m)) := + (windowSmoothing_bounds W m).2.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hX (by positivity))) + have hbLen : ((accurateBlock m (1/20)).length+2:ℝ)≤Real.exp ((100:ℝ)^w*Real.exp m) := by + have hh : (accurateBlock m (1/20)).length≤(commonBlocks a m W J).length := by simp [commonBlocks] + exact (add_le_add (by exact_mod_cast hh : ((accurateBlock m (1/20)).length:ℝ)≤(commonBlocks a m W J).length) (le_refl (2:ℝ))) |>.trans (hl.trans (Real.exp_le_exp.mpr hX)) + have hrLen : ((middleBlocks a m w J++accurateBlock m (1/20)).length+2:ℝ)≤Real.exp ((100:ℝ)^w*Real.exp m) := by + have hh := middleBlocks_length_le (a := a) (m := m) J hw + have hh' : (middleBlocks a m w J++accurateBlock m (1/20)).length≤(commonBlocks a m W J).length := by + simp only [commonBlocks,List.length_append]; omega + exact (add_le_add (by exact_mod_cast hh' : ((middleBlocks a m w J++accurateBlock m (1/20)).length:ℝ)≤(commonBlocks a m W J).length) (le_refl (2:ℝ))) |>.trans (hl.trans (Real.exp_le_exp.mpr hX)) + have hbOps : ∀ n∈accurateBlock m (1/20), (n:ℝ)≤Real.exp (Real.exp ((1/20)*((100:ℝ)^w*Real.exp m))) := by + apply accurateBlock_bound (accurateGrid_le_one m) + exact (mul_le_of_le_one_left (Real.exp_nonneg _) (accurateGrid_le_one m)).trans + (Real.exp_le_exp.mpr (by linarith only [hX])) + have hrOps : ∀ n∈middleBlocks a m w J++accurateBlock m (1/20), (n:ℝ)≤Real.exp (Real.exp ((1/4)*((100:ℝ)^w*Real.exp m))) := by + intro n hn + rcases List.mem_append.mp hn with hn|hn + · rcases List.mem_append.mp hn with hn|hn + · apply accurateBlock_bound (accurateGrid_le_one m) _ n hn + simpa only [div_mul_eq_mul_div,mul_assoc,one_mul] using + (mul_le_of_le_one_left (Real.exp_nonneg (((100:ℝ)^w/4)*Real.exp m)) (accurateGrid_le_one m)) + · exact (smaller_window_operations ha ha1 m w J (fun i hi => hJ i (hi.trans hw)) n hn).trans + (Real.exp_le_exp.mpr (Real.exp_le_exp.mpr (by nlinarith only [show 0≤(100:ℝ)^w*Real.exp m by positivity] : ((100:ℝ)^w/50)*Real.exp m≤(1/4)*((100:ℝ)^w*Real.exp m)))) + · exact (hbOps n hn).trans (Real.exp_le_exp.mpr (Real.exp_le_exp.mpr (by nlinarith only [show 0≤(100:ℝ)^w*Real.exp m by positivity] : (1/20)*((100:ℝ)^w*Real.exp m)≤(1/4)*((100:ℝ)^w*Real.exp m)))) + exact ⟨hl,hNsmall,hlw, + hbot _ _ (by have := windowSmoothing_pos W m; omega) hbLen hbOps hNs, + hrest _ _ (by have := windowSmoothing_pos W m; omega) hrLen hrOps hNs⟩ + +lemma floor_size_lower {s : SplitSieve} {g U X : ℝ} {l : ℕ} + (hX : 0 (hJ i hi k hk).2.1) + have hmid' := hmid (dyadicSieve j) ((2:ℝ)^j) [] (windowBlocks a m J w) 0 + hne hpj hdense hT hThi + (smaller_window_operations ha ha1 m w J (fun i hi k hk => (hJ i (hi.trans hw) k hk).2.1)) + (by simp only [Nat.cast_zero]; positivity) hlen + have hTwo : (2:ℝ)≤Real.exp (Real.exp ((1/100)*Real.exp m)) := by + have he : 1≤Real.exp ((1/100)*Real.exp (m:ℝ)) := Real.one_le_exp_iff.mpr (by positivity) + linarith only [Real.add_one_le_exp (Real.exp ((1/100)*Real.exp (m:ℝ))),he] + have hbot' := hbot (dyadicSieve j) ((2:ℝ)^j) [] [] (windowSmoothing W m) + hne hpj hdense + ((Real.exp_le_exp.mpr (by nlinarith only [hwp,Real.exp_pos (m:ℝ)] : 1*Real.exp m≤(100:ℝ)^w*Real.exp m)).trans hT) + hThi (by simp only [List.not_mem_nil,IsEmpty.forall_iff,implies_true]) hN + (by simpa only [List.length_nil,Nat.cast_zero,zero_add] using hTwo) + refine ⟨?_,?_,?_⟩ + · simpa only [List.nil_append,accurateBlock,middleBlocks] using hmid' + · simpa only [List.nil_append,List.append_nil,accurateBlock] using hbot' + · apply floor_size_lower (by linarith only [hX2]) (by linarith only [hm.1]) hm.2 + · simpa only [pow_zero,one_mul,div_div,show (4:ℝ)*2=8 by norm_num,div_mul_eq_mul_div] using hscale + · simpa only [mul_assoc,div_mul_eq_mul_div] using hlarge + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/ConditionalSampling.lean b/lean/OAI/NumberTheory/GaussianMoat/ConditionalSampling.lean new file mode 100644 index 0000000000000000000000000000000000000000..12bf2ab49eb42ba9ee4046ce5d65889b8b66540e --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/ConditionalSampling.lean @@ -0,0 +1,493 @@ +import OAI.NumberTheory.GaussianMoat.PrimeMass + +namespace OAI + +universe uOmega uAlpha uBeta uGamma uIota uDelta + +namespace GaussianMoat +open Filter Topology Finset + +namespace FinLaw +open scoped BigOperators +variable {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] {k : ℕ} + +theorem cHf_eq_of_fibers {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) + (X : Ω → α) (Y : Ω → β) (C : Ω → γ) + (h : ∀ ω ν, C ω = C ν → (X ω = X ν ↔ Y ω = Y ν)) : + p.cHf X C = p.cHf Y C := by + unfold cHf + congr 1 + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq] + constructor <;> intro hh + · exact ⟨(h ω ν hh.2).mp hh.1,hh.2⟩ + · exact ⟨(h ω ν hh.2).mpr hh.1,hh.2⟩ + +theorem cHf_le_of_determined {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) + (X : Ω → α) (Y : Ω → β) (C : Ω → γ) + (h : ∀ ω ν, Y ω = Y ν → C ω = C ν → X ω = X ν) : + p.cHf X C ≤ p.cHf Y C := by + apply sub_le_sub_right + apply p.Hf_le_of_determined + intro ω ν hh + rcases Prod.mk.inj hh with ⟨hy,hc⟩ + exact Prod.ext (h ω ν hy hc) hc + +theorem cHf_finset_subadd {ι : Type uIota} {β : Type uBeta} (p : FinLaw Ω) + (X : Ω → ι → α) (C : Ω → β) (S : Finset ι) : + p.cHf (fun ω (i : S) => X ω i) C ≤ ∑ i ∈ S, p.cHf (fun ω => X ω i) C := by + classical + induction S using Finset.induction_on with + | empty => + have he : p.cHf (fun ω (i : (∅:Finset ι)) => X ω i) C = p.cHf (fun _ => ()) C := by + apply p.cHf_eq_of_fibers + intro ω ν _ + simp only [iff_true] + funext i + exact False.elim (Finset.notMem_empty i.val i.property) + have hc : p.cHf (fun _ => ()) C = 0 := by + unfold cHf + have hh := p.Hf_eq_of_fibers (fun ω => ((),C ω)) C (fun _ _ => by simp) + rw [hh,sub_self] + simp [he,hc] + | @insert i S hi ih => + have he : p.cHf (fun ω (j : (insert i S : Finset ι)) => X ω j) C = + p.cHf (fun ω => (X ω i,fun j : S => X ω j)) C := by + apply p.cHf_eq_of_fibers + intro ω ν _ + constructor + · intro h + apply Prod.ext + · exact congrFun h ⟨i,Finset.mem_insert_self _ _⟩ + · funext j; exact congrFun h ⟨j,Finset.mem_insert_of_mem j.property⟩ + · intro h + funext j + rcases Finset.mem_insert.mp j.property with hj | hj + · simpa [hj] using congrArg Prod.fst h + · exact congrFun (congrArg Prod.snd h) ⟨j,hj⟩ + rw [he,Finset.sum_insert hi] + have hh := p.cHf_pair_subadd (fun ω => X ω i) (fun ω (j : S) => X ω j) C + linarith + +theorem cHf_fintype_subadd {ι : Type uIota} {β : Type uBeta} [Fintype ι] (p : FinLaw Ω) + (X : Ω → ι → α) (C : Ω → β) : + p.cHf X C ≤ ∑ i, p.cHf (fun ω => X ω i) C := by + have h := p.cHf_finset_subadd X C Finset.univ + have he : p.cHf (fun ω (i : (Finset.univ : Finset ι)) => X ω i) C = p.cHf X C := by + apply p.cHf_eq_of_fibers + intro ω ν _ + exact ⟨fun hh => funext (fun i => congrFun hh ⟨i,Finset.mem_univ i⟩), + fun hh => funext (fun i => congrFun hh i)⟩ + rwa [he] at h + +omit [Fintype Ω] in + +theorem prefixVar_swap (X : Ω → Fin k → α) (π : Equiv.Perm (Fin k)) (s : ℕ) + (i j : Fin k) (hi : s ≤ i.val) (hj : s ≤ j.val) : + prefixVar X (π*Equiv.swap i j) s = prefixVar X π s := by + classical + funext ω a + by_cases ha : a.val X ω (π i)) (C π)) = + 𝔼 π : Equiv.Perm (Fin k), p.cHf (fun ω => X ω (π j)) (C π) := by + classical + apply Fintype.expect_equiv (Equiv.mulRight (Equiv.swap i j)) + intro π + change p.cHf (fun ω => X ω (π i)) (C π) = + p.cHf (fun ω => X ω ((π*Equiv.swap i j) j)) (C (π*Equiv.swap i j)) + rw [hC] + simp only [Equiv.Perm.mul_apply,Equiv.swap_apply_right] + +theorem prefix_conditional_block {β : Type uBeta} (p : FinLaw Ω) + (X : Ω → Fin k → α) (π : Equiv.Perm (Fin k)) (C : Ω → β) + {b q : ℕ} (hbq : b ≤ q) (hq : q ≤ k) + (hC : ∀ ω ν, C ω = C ν → prefixVar X π b ω = prefixVar X π b ν) : + p.cHf (prefixVar X π q) C ≤ + ∑ j : Fin (q-b), p.cHf (fun ω => X ω (π ⟨b+j.val,by omega⟩)) C := by + let R := fun ω (j : Fin (q-b)) => X ω (π ⟨b+j.val,by omega⟩) + apply (p.cHf_le_of_determined (prefixVar X π q) R C ?_).trans + (p.cHf_fintype_subadd R C) + intro ω ν hR hcond + funext i + by_cases hi : i.val < b + · have h := congrFun (hC ω ν hcond) i + simpa [prefixVar,hi,show i.val X ω (π ⟨b,by omega⟩)) (C π)) := by + have h := Finset.expect_le_expect (s := Finset.univ) (fun π _ => + p.prefix_conditional_block X π (C π) hbq.le hq (hC π)) + rw [Finset.expect_sum_comm] at h + have he (j : Fin (q-b)) : + (𝔼 π : Equiv.Perm (Fin k), p.cHf (fun ω => X ω (π ⟨b+j.val,by omega⟩)) (C π)) = + 𝔼 π : Equiv.Perm (Fin k), p.cHf (fun ω => X ω (π ⟨b,by omega⟩)) (C π) := by + exact (p.ordered_remaining_exchange_cond X C ⟨b,by omega⟩ ⟨b+j.val,by omega⟩ + (fun π => hswap π _ (by change b ≤ b+j.val; omega))).symm + simpa only [he,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using h + +theorem ordered_enrichment_accounting {β : Type uBeta} {γ : Type uGamma} {δ : Type uDelta} (p : FinLaw Ω) + (X Y Z : Ω → Fin k → α) (d : Ω → Fin k → β) (H : Ω → γ) (E : Ω → δ) + {b q : ℕ} (hb : 0 < b) (hbq : b < q) (hq : q ≤ k) + (hd : ∀ i ω ν, X ω i = X ν i → Y ω i = Y ν i → d ω i = d ν i) + (hY : ∀ i ω ν, X ω i = X ν i → d ω i = d ν i → Y ω i = Y ν i) + (hH : ∀ i ω ν, H ω = H ν → d ω i = d ν i) + (hZ : ∀ i ω ν, X ω i = X ν i → E ω = E ν → Z ω i = Z ν i) : + (b : ℝ) * ((q-b : ℕ) * + (𝔼 π : Equiv.Perm (Fin k), p.cHf (fun ω => d ω (π ⟨b,by omega⟩)) + (fun ω => (prefixVar X π b ω,prefixVar Y π b ω))) + + p.orderedEntropy Z q-p.Hf H-p.Hf E) ≤ + (q : ℝ)*(p.orderedEntropy X b+p.orderedEntropy Y b) := by + let C := fun (π : Equiv.Perm (Fin k)) ω => + ((prefixVar X π b ω,prefixVar Y π b ω),H ω) + let A := 𝔼 π : Equiv.Perm (Fin k), + p.cHf (fun ω => X ω (π ⟨b,by omega⟩)) (C π) + let F := 𝔼 π : Equiv.Perm (Fin k), + p.cHf (fun ω => d ω (π ⟨b,by omega⟩)) + (fun ω => (prefixVar X π b ω,prefixVar Y π b ω)) + have hblock := p.ordered_prefix_conditional_bound X C hbq hq + (fun π ω ν hh => congrArg (fun c => c.1.1) hh) (by + intro π j hj + dsimp [C] + rw [prefixVar_swap X π b _ j (by exact le_rfl) hj, + prefixVar_swap Y π b _ j (by exact le_rfl) hj]) + have hlow (π : Equiv.Perm (Fin k)) : + p.Hf (prefixVar Z π q)-p.Hf E-p.Hf (prefixVar X π b)- + p.Hf (prefixVar Y π b)-p.Hf H ≤ p.cHf (prefixVar X π q) (C π) := by + have hz : p.Hf (prefixVar Z π q) ≤ p.Hf (prefixVar X π q)+p.Hf E := by + apply (p.Hf_le_of_determined (prefixVar Z π q) + (fun ω => (prefixVar X π q ω,E ω)) ?_).trans (p.Hf_pair_subadd _ _) + intro ω ν hh + funext i + by_cases hi : i.val (prefixVar X π b ω,prefixVar Y π b ω)) H + have h2 := p.Hf_pair_subadd (prefixVar X π b) (prefixVar Y π b) + dsimp [C] + linarith + have hx := p.Hf_pair_ge_snd (C π) (prefixVar X π q) + rw [p.Hf_pair_comm] at hx + unfold cHf + linarith + have hav := Finset.expect_le_expect (s := Finset.univ) (fun π _ => hlow π) + simp only [Finset.expect_sub_distrib,Fintype.expect_const] at hav + have hal : p.orderedEntropy Z q-p.Hf E-p.orderedEntropy X b- + p.orderedEntropy Y b-p.Hf H ≤ (q-b : ℕ)*A := hav.trans hblock + have hchain := Finset.expect_le_expect (s := Finset.univ) (fun π _ => + p.enrichment_chain (fun ω => X ω (π ⟨b,by omega⟩)) (fun ω => Y ω (π ⟨b,by omega⟩)) + (prefixVar X π b) (prefixVar Y π b) (fun ω => d ω (π ⟨b,by omega⟩)) H + (hd _) (hY _) (hH _)) + simp only [Finset.expect_sub_distrib,Finset.expect_add_distrib] at hchain + have hchain' : F ≤ (p.orderedEntropy X (b+1)-p.orderedEntropy X b)+ + (p.orderedEntropy Y (b+1)-p.orderedEntropy Y b)-A := by + rwa [p.orderedEntropy_step X (by omega),p.orderedEntropy_step Y (by omega)] + have hx := p.orderedEntropy_slope X hb (by omega) + have hy := p.orderedEntropy_slope Y hb (by omega) + have haux : A+F ≤ (p.orderedEntropy X b+p.orderedEntropy Y b)/b := by + rw [add_div] + linarith + have hbR : (0 : ℝ) f (π a)) + (Finset.mem_univ i) + dsimp [S] + linarith + have hid : (S.card : ℝ)*(𝔼 π : Equiv.Perm ι, f (π i)*f (π j)) = + -(𝔼 π : Equiv.Perm ι, f (π i)^2) := by + calc + _ = ∑ a ∈ S, (𝔼 π : Equiv.Perm ι, f (π i)*f (π a)) := by + rw [show (∑ a ∈ S, (𝔼 π : Equiv.Perm ι, f (π i)*f (π a))) = + ∑ _a ∈ S, (𝔼 π : Equiv.Perm ι, f (π i)*f (π j)) from + Finset.sum_congr rfl (fun a ha => hex a ha)] + simp [nsmul_eq_mul] + _ = 𝔼 π : Equiv.Perm ι, ∑ a ∈ S, f (π i)*f (π a) := + (Finset.expect_sum_comm _ _ _).symm + _ = -(𝔼 π : Equiv.Perm ι, f (π i)^2) := by + simp_rw [← Finset.mul_sum,hsum,mul_neg,← sq] + rw [Finset.expect_neg_distrib] + have hvar : 0 ≤ (𝔼 π : Equiv.Perm ι, f (π i)^2) := + Finset.expect_nonneg (fun _ _ => sq_nonneg _) + have hc : (0 : ℝ) < S.card := by exact_mod_cast hS.card_pos + nlinarith + +theorem perm_sample_second_moment {ι : Type uIota} [Fintype ι] [DecidableEq ι] (f : ι → ℝ) + (hf : ∑ i, f i = 0) (S : Finset ι) {M : ℝ} (hM : ∀ i, (f i)^2 ≤ M) : + (𝔼 π : Equiv.Perm ι, (∑ i ∈ S, f (π i))^2) ≤ S.card*M := by + classical + induction S using Finset.induction_on with + | empty => simp + | @insert i S hi ih => + have hsqr (π : Equiv.Perm ι) : (∑ j ∈ insert i S, f (π j))^2 = + (f (π i))^2+(∑ j ∈ S, f (π j))^2+2*(∑ j ∈ S, f (π i)*f (π j)) := by + rw [Finset.sum_insert hi,← Finset.mul_sum] + ring + simp_rw [hsqr,Finset.expect_add_distrib,← Finset.mul_expect,Finset.expect_sum_comm] + have hb : (𝔼 π : Equiv.Perm ι, f (π i)^2) ≤ M := + (Finset.expect_le_expect (s := Finset.univ) (fun π _ => hM (π i))).trans_eq + (Fintype.expect_const _) + have hc : (∑ j ∈ S, (𝔼 π : Equiv.Perm ι, f (π i)*f (π j))) ≤ 0 := by + apply Finset.sum_nonpos + intro j hj + exact perm_covariance_nonpos f hf (fun he => hi (he.symm ▸ hj)) + rw [Finset.card_insert_of_notMem hi,Nat.cast_add,Nat.cast_one] + nlinarith + +theorem expect_lower_tail_le {Ω : Type uOmega} [Fintype Ω] [Nonempty Ω] + (Z : Ω → ℝ) {a δ V : ℝ} (hδ : 0 < δ) + (hV : (𝔼 ω, (Z ω-a)^2) ≤ V) : + (𝔼 ω, if Z ω < a-δ then (1 : ℝ) else 0) ≤ V/δ^2 := by + classical + have he : ∀ ω, δ^2*(if Z ω < a-δ then (1 : ℝ) else 0) ≤ (Z ω-a)^2 := by + intro ω + split_ifs with hh + · nlinarith + · simpa using sq_nonneg (Z ω-a) + have h := Finset.expect_le_expect (s := Finset.univ) (fun ω _ => he ω) + rw [← Finset.mul_expect] at h + exact (le_div_iff₀ (sq_pos_of_pos hδ)).mpr (by nlinarith) + +theorem perm_sample_interval_tail {ι : Type uIota} [Fintype ι] [DecidableEq ι] [Nonempty ι] + (f : ι → ℝ) (S : Finset ι) {a M δ : ℝ} (hδ : 0 < δ) + (hf : ∀ i, a ≤ f i ∧ f i ≤ a+M) : + (𝔼 π : Equiv.Perm ι, + if (∑ i ∈ S, f (π i)) < S.card*(𝔼 i, f i)-δ then (1 : ℝ) else 0) ≤ + S.card*M^2/δ^2 := by + let μ := 𝔼 i, f i + have hlo : a ≤ μ := by + have h := Finset.expect_le_expect (s := Finset.univ) (fun i _ => (hf i).1) + simpa only [Fintype.expect_const] using h + have hhi : μ ≤ a+M := by + have h := Finset.expect_le_expect (s := Finset.univ) (fun i _ => (hf i).2) + simpa only [Fintype.expect_const] using h + have hsum : ∑ i, (f i-μ) = 0 := by + simp only [Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + rw [show (Fintype.card ι : ℝ)*μ = ∑ i, f i from Fintype.card_mul_expect f] + ring + have hsq (i : ι) : (f i-μ)^2 ≤ M^2 := by + have h := hf i + nlinarith + have hvar := perm_sample_second_moment (fun i => f i-μ) hsum S hsq + have hid (π : Equiv.Perm ι) : (∑ i ∈ S, (f (π i)-μ)) = + (∑ i ∈ S, f (π i))-S.card*μ := by + simp only [Finset.sum_sub_distrib,Finset.sum_const,nsmul_eq_mul] + simp_rw [hid] at hvar + exact expect_lower_tail_le _ hδ hvar + +namespace FinLaw +open scoped BigOperators +variable {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] {k : ℕ} + +noncomputable def uniform (Ω : Type uOmega) [Fintype Ω] [Nonempty Ω] : FinLaw Ω where + mass := fun _ => (Fintype.card Ω : ℝ)⁻¹ + nonneg := fun _ => inv_nonneg.mpr (Nat.cast_nonneg _) + sum_one := by + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + exact mul_inv_cancel₀ (by exact_mod_cast (Fintype.card_pos : 0 < Fintype.card Ω).ne') + +@[simp] theorem uniform_mass [Nonempty Ω] (ω : Ω) : + uniform Ω ω = (Fintype.card Ω : ℝ)⁻¹ := rfl + +theorem uniform_Hf_injective {β : Type uBeta} [Nonempty Ω] (X : Ω → β) + (hX : Function.Injective X) : (uniform Ω).Hf X = Real.log (Fintype.card Ω) := by + classical + have hN : (Fintype.card Ω : ℝ) ≠ 0 := by exact_mod_cast (Fintype.card_pos : 0 < Fintype.card Ω).ne' + unfold Hf + simp only [hX.eq_iff,uniform_mass,Finset.sum_ite_eq',Finset.mem_univ,ite_true, + Finset.sum_const,Finset.card_univ,nsmul_eq_mul,Real.log_inv] + rw [← mul_assoc,mul_inv_cancel₀ hN] + ring + +theorem Hf_le_log_card_type {β : Type uBeta} [Fintype β] (p : FinLaw Ω) (X : Ω → β) : + p.Hf X ≤ Real.log (Fintype.card β) := by + rw [p.Hf_eq_H] + exact (p.map X).entropy_le_log_card + +theorem Hf_le_log_card_set {β : Type uBeta} (p : FinLaw Ω) (X : Ω → β) + (S : Finset β) (hX : ∀ ω, X ω ∈ S) : p.Hf X ≤ Real.log S.card := by + classical + let Y := fun ω => (⟨X ω,hX ω⟩ : S) + have he : p.Hf X = p.Hf Y := by + apply p.Hf_eq_of_fibers + intro ω ν + exact ⟨fun h => Subtype.ext h, fun h => congrArg Subtype.val h⟩ + rw [he] + simpa using p.Hf_le_log_card_type Y + +theorem map_mix {ι : Type uIota} {β : Type uBeta} [Fintype ι] [Fintype β] + (p : FinLaw ι) (q : ι → FinLaw Ω) (X : Ω → β) : + (p.mix q).map X = p.mix (fun i => (q i).map X) := by + classical + ext b + simp only [map_mass,mix_mass,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + +theorem Hf_mix_ge {ι : Type uIota} {β : Type uBeta} [Fintype ι] + (p : FinLaw ι) (q : ι → FinLaw Ω) (X : Ω → β) : + (∑ i, p i*(q i).Hf X) ≤ (p.mix q).Hf X := by + classical + let Y := fun ω => (⟨X ω,⟨ω,rfl⟩⟩ : Set.range X) + let : Fintype (Set.range X) := Fintype.ofFinite _ + have he (r : FinLaw Ω) : r.Hf X = r.Hf Y := by + apply r.Hf_eq_of_fibers + intro ω ν + exact ⟨fun h => Subtype.ext h, fun h => congrArg Subtype.val h⟩ + simp_rw [he,Hf_eq_H] + change (∑ i, p i*((q i).map Y).entropy) ≤ ((p.mix q).map Y).entropy + rw [map_mix] + exact p.entropy_mix_ge _ + +theorem Hf_prefix_le (p : FinLaw Ω) (X : Ω → Fin k → α) (π : Equiv.Perm (Fin k)) + (s : ℕ) : p.Hf (prefixVar X π s) ≤ p.Hf X := by + exact p.Hf_le_of_determined _ _ (fun ω ν hh => + congrArg (fun y (i : Fin k) => if i.val < s then some (y (π i)) else none) hh) + +theorem Hf_fintype_subadd {ι : Type uIota} {β : Type uBeta} [Fintype ι] (p : FinLaw Ω) + (X : Ω → ι → β) : p.Hf X ≤ ∑ i, p.Hf (fun ω => X ω i) := by + classical + have he : p.Hf (fun ω (i : (Finset.univ : Finset ι)) => X ω i) = p.Hf X := by + apply p.Hf_eq_of_fibers + intro ω ν + constructor + · intro hh + funext i + exact congrFun hh ⟨i,Finset.mem_univ _⟩ + · intro hh + funext i + exact congrFun hh i + simpa only [he] using p.Hf_finset_subadd X Finset.univ + +theorem Hf_prefix_le_sum (p : FinLaw Ω) (X : Ω → Fin k → α) + (L : Fin k → ℝ) (hL : ∀ i, p.Hf (fun ω => X ω i) ≤ L i) + (π : Equiv.Perm (Fin k)) {s : ℕ} (hs : s ≤ k) : + p.Hf (prefixVar X π s) ≤ ∑ j : Fin s, L (π ⟨j.val,by omega⟩) := by + let Y := fun ω (j : Fin s) => X ω (π ⟨j.val,by omega⟩) + have he : p.Hf (prefixVar X π s) = p.Hf Y := by + apply p.Hf_eq_of_fibers + intro ω ν + constructor + · intro hh + funext j + have h := congrFun hh ⟨j.val,by omega⟩ + simpa [prefixVar,j.isLt,Y] using h + · intro hh + funext j + by_cases hj : j.val < s + · have h := congrFun hh ⟨j.val,hj⟩ + simpa [prefixVar,hj,Y] using congrArg some h + · simp [prefixVar,hj] + rw [he] + exact (p.Hf_fintype_subadd Y).trans (Finset.sum_le_sum (fun j _ => hL _)) + +theorem fresh_entropy_from_prefix {β : Type uBeta} (p : FinLaw Ω) + (X Y : Ω → Fin k → α) (d : Ω → Fin k → β) {b s : ℕ} + (hbs : b < s) (hs : s ≤ k) + (hd : ∀ i ω ν, X ω i = X ν i → Y ω i = Y ν i → d ω i = d ν i) : + p.orderedEntropy d s-p.orderedEntropy X b-p.orderedEntropy Y b ≤ + (s-b : ℕ)*(𝔼 π : Equiv.Perm (Fin k), + p.cHf (fun ω => d ω (π ⟨b,by omega⟩)) + (fun ω => (prefixVar X π b ω,prefixVar Y π b ω))) := by + let C := fun (π : Equiv.Perm (Fin k)) ω => (prefixVar X π b ω,prefixVar Y π b ω) + have hdet : ∀ π ω ν, C π ω=C π ν → prefixVar d π b ω=prefixVar d π b ν := by + intro π ω ν hh + funext i + by_cases hi : i.val < b + · have hx := congrFun (congrArg Prod.fst hh) i + have hy := congrFun (congrArg Prod.snd hh) i + simp only [C,prefixVar,hi,ite_eq_left,Option.some.injEq] at hx hy + simpa only [prefixVar,hi,ite_eq_left] using congrArg some (hd (π i) ω ν hx hy) + · simp [prefixVar,hi] + have hblock := p.ordered_prefix_conditional_bound d C hbs hs hdet (by + intro π j hj + dsimp [C] + rw [prefixVar_swap X π b _ j (by exact le_rfl) hj, + prefixVar_swap Y π b _ j (by exact le_rfl) hj]) + have hlow (π : Equiv.Perm (Fin k)) : p.Hf (prefixVar d π s)- + p.Hf (prefixVar X π b)-p.Hf (prefixVar Y π b) ≤ + p.cHf (prefixVar d π s) (C π) := by + have h1 := p.Hf_pair_subadd (prefixVar X π b) (prefixVar Y π b) + have h2 := p.Hf_pair_ge_snd (C π) (prefixVar d π s) + rw [p.Hf_pair_comm] at h2 + dsimp [C] at * + unfold cHf + linarith + have hav := Finset.expect_le_expect (s := Finset.univ) (fun π _ => hlow π) + simp only [Finset.expect_sub_distrib] at hav + exact hav.trans hblock + +end FinLaw + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/DenseBins.lean b/lean/OAI/NumberTheory/GaussianMoat/DenseBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8ec782b13353648a19974a7e8e1cf7d3d8724a1 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/DenseBins.lean @@ -0,0 +1,224 @@ +import OAI.NumberTheory.GaussianMoat.ConditionalSampling + +namespace OAI + +namespace GaussianMoat +open Filter Topology Finset +open scoped BigOperators + +namespace PrimeLogMass +open Filter Topology Finset +open ArithmeticFunction.vonMangoldt Complex +open scoped BigOperators + +def dyadicBatch (j : ℕ) : Finset ℕ := + (Finset.Ico (2^j) (2^(j+1))).filter (fun p => p.Prime ∧ p % 4 = 1) + +lemma mem_dyadicBatch (j p : ℕ) : p ∈ dyadicBatch j ↔ + 2^j ≤ p ∧ p < 2^(j+1) ∧ p.Prime ∧ p % 4 = 1 := by + simp only [dyadicBatch,Finset.mem_filter,Finset.mem_Ico] + tauto + +lemma logBin_mem (p : ℕ) (hp : p.Prime) (hm : p % 4 = 1) : + p ∈ dyadicBatch (Nat.log 2 p) := by + rw [mem_dyadicBatch] + exact ⟨Nat.pow_log_le_self 2 hp.ne_zero, + Nat.lt_pow_succ_log_self (by norm_num) p,hp,hm⟩ + +lemma prime_log_mass_le_theta (S : Finset ℕ) {U : ℝ} (hU : 0 ≤ U) + (hp : ∀ p ∈ S, p.Prime ∧ (p : ℝ) ≤ U) : + (∑ p ∈ S, Real.log p) ≤ Real.log 4*U := by + apply le_trans _ (Chebyshev.theta_le_log4_mul_x hU) + rw [Chebyshev.theta_eq_sum_primesLE] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro p hpS + rw [Nat.mem_primesLE] + exact ⟨(Nat.le_floor_iff hU).mpr (hp p hpS).2,(hp p hpS).1⟩ + · intro p hpS _ + exact Real.log_nonneg (by exact_mod_cast (Nat.mem_primesLE.mp hpS).2.one_le) + +noncomputable def dyadicMass (j : ℕ) : ℝ := + ∑ p ∈ dyadicBatch j, Real.log p/p + +lemma dyadicMass_nonneg (j : ℕ) : 0 ≤ dyadicMass j := by + apply Finset.sum_nonneg + intro p hp + exact div_nonneg (Real.log_nonneg (by exact_mod_cast (mem_dyadicBatch _ _ |>.mp hp).2.2.1.one_le)) + (Nat.cast_nonneg _) + +lemma dyadicMass_le (j : ℕ) : dyadicMass j ≤ 2*Real.log 4 := by + have hT : (0 : ℝ) < 2^j := pow_pos (by norm_num) _ + have hs : dyadicMass j ≤ (∑ p ∈ dyadicBatch j, Real.log p)/(2^j : ℝ) := by + rw [Finset.sum_div] + apply Finset.sum_le_sum + intro p hp + have h := (mem_dyadicBatch j p).mp hp + apply div_le_div_of_nonneg_left + · exact Real.log_nonneg (by exact_mod_cast h.2.2.1.one_le) + · exact hT + · exact_mod_cast h.1 + have ht := prime_log_mass_le_theta (dyadicBatch j) (U := (2 : ℝ)^(j+1)) + (by positivity) (by intro p hp; have h := (mem_dyadicBatch j p).mp hp + exact ⟨h.2.2.1,by exact_mod_cast h.2.1.le⟩) + apply hs.trans + apply (div_le_iff₀ hT).mpr + rw [pow_succ] at ht + nlinarith + +lemma dyadicMass_le_card (j : ℕ) : dyadicMass j ≤ + (dyadicBatch j).card * Real.log ((2 : ℝ)^(j+1)) / (2 : ℝ)^j := by + rw [dyadicMass] + have hT : (0 : ℝ) < 2^j := pow_pos (by norm_num) _ + have hp (p : ℕ) (hp : p ∈ dyadicBatch j) : + Real.log p/p ≤ Real.log ((2 : ℝ)^(j+1))/(2 : ℝ)^j := by + have h := (mem_dyadicBatch j p).mp hp + apply le_trans (div_le_div_of_nonneg_left + (Real.log_nonneg (by exact_mod_cast h.2.2.1.one_le)) hT (by exact_mod_cast h.1)) + apply div_le_div_of_nonneg_right _ hT.le + exact Real.log_le_log (by exact_mod_cast h.2.2.1.pos) (by exact_mod_cast h.2.1.le) + have hs := Finset.sum_le_sum (s := dyadicBatch j) hp + simpa [Finset.sum_const,nsmul_eq_mul,mul_div_assoc] using hs + +theorem many_dense_bins (J : Finset ℕ) {X c A : ℝ} (hc : 0 < c) + (hA : 0 < A) (hcard : (J.card : ℝ) ≤ A*X) + (hmass : c*X ≤ ∑ j ∈ J, dyadicMass j) : + c*X/(4*Real.log 4) ≤ + ((J.filter (fun j => c/(2*A) ≤ dyadicMass j)).card : ℝ) ∧ + ∀ j ∈ J.filter (fun j => c/(2*A) ≤ dyadicMass j), + c/(2*A)*(2 : ℝ)^j/Real.log ((2 : ℝ)^(j+1)) ≤ (dyadicBatch j).card := by + classical + let G := J.filter (fun j => c/(2*A) ≤ dyadicMass j) + have hlog : 0 < Real.log (4 : ℝ) := Real.log_pos (by norm_num) + have hδ : 0 < c/(2*A) := div_pos hc (by positivity) + have ht (j : ℕ) (hj : j ∈ J) : dyadicMass j ≤ + (if j ∈ G then 2*Real.log 4 else 0)+c/(2*A) := by + by_cases hg : j ∈ G + · simp only [hg,ite_eq_left] + linarith [dyadicMass_le j] + · rw [ite_eq_right hg,zero_add] + exact (not_le.mp (fun h => hg (Finset.mem_filter.mpr ⟨hj,h⟩))).le + have hs := Finset.sum_le_sum (s := J) ht + have he : (∑ j ∈ J, if j ∈ G then 2*Real.log 4 else 0) = G.card*(2*Real.log 4) := by + rw [← Finset.sum_filter] + have hG : J.filter (fun j => j ∈ G) = G := by + ext j + simp only [G,Finset.mem_filter] + tauto + rw [hG] + simp [nsmul_eq_mul] + rw [Finset.sum_add_distrib,he,Finset.sum_const,nsmul_eq_mul] at hs + have hsmall : (J.card : ℝ)*(c/(2*A)) ≤ c*X/2 := by + have h := mul_le_mul_of_nonneg_right hcard hδ.le + have he : A*X*(c/(2*A))=c*X/2 := by field_simp + rwa [he] at h + refine ⟨(div_le_iff₀ (by positivity)).mpr (by dsimp [G] at hs; nlinarith),?_⟩ + intro j hj + have hg := (Finset.mem_filter.mp hj).2 + have h := dyadicMass_le_card j + have hT : (0 : ℝ) < 2^j := pow_pos (by norm_num) _ + have hL : 0 < Real.log ((2 : ℝ)^(j+1)) := Real.log_pos (one_lt_pow₀ (by norm_num) (by omega)) + apply (div_le_iff₀ hL).mpr + have h' := (le_div_iff₀ hT).mp (hg.trans h) + exact h' + +noncomputable def splitWindow (X : ℝ) : Finset ℕ := + (windowIndices X).filter (fun p => p.Prime ∧ p % 4 = 1) + +noncomputable def windowBins (X : ℝ) : Finset ℕ := + (splitWindow X).image (Nat.log 2) + +lemma split_residue_mass (p : ℕ) (hp : p.Prime) : + residueClass (1 : ZMod 4) p = if p % 4 = 1 then Real.log p else 0 := by + have he : (p : ZMod 4) = 1 ↔ p % 4 = 1 := by + rw [show (1 : ZMod 4) = (1 : ℕ) from rfl,ZMod.natCast_eq_natCast_iff] + rfl + simp only [residueClass,Set.indicator_apply,Set.mem_ofPred_eq,he, + ArithmeticFunction.vonMangoldt_apply_prime hp] + +lemma window_mass_le_bins (X : ℝ) : + (∑ p ∈ (windowIndices X).filter Nat.Prime, residueClass (1 : ZMod 4) p/p) ≤ + ∑ j ∈ windowBins X, dyadicMass j := by + classical + have hres : (∑ p ∈ (windowIndices X).filter Nat.Prime, residueClass (1 : ZMod 4) p/p) = + ∑ p ∈ splitWindow X, Real.log p/p := by + rw [splitWindow,Finset.sum_filter,Finset.sum_filter] + apply Finset.sum_congr rfl + intro p _ + by_cases hp : p.Prime + · rw [ite_eq_left hp,split_residue_mass p hp] + by_cases hm : p % 4=1 <;> simp [hp,hm] + · simp [hp] + rw [hres,← Finset.sum_fiberwise_of_maps_to + (s := splitWindow X) (t := windowBins X) (g := Nat.log 2) + (fun p hp => Finset.mem_image.mpr ⟨p,hp,rfl⟩)] + apply Finset.sum_le_sum + intro j _ + dsimp [dyadicMass] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro p hp + rcases Finset.mem_filter.mp hp with ⟨hp,hj⟩ + obtain ⟨_,hpp,hpm⟩ := Finset.mem_filter.mp hp + rw [← hj] + exact logBin_mem p hpp hpm + · intro p hp _ + have hpp := ((mem_dyadicBatch j p).mp hp).2.2.1 + exact div_nonneg (Real.log_nonneg (by exact_mod_cast hpp.one_le)) (Nat.cast_nonneg p) + +lemma windowBin_bounds {X : ℝ} (hX : 1000 ≤ X) {j : ℕ} (hj : j ∈ windowBins X) : + X ≤ j*Real.log 2 ∧ j*Real.log 2 ≤ 21/20*X := by + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hj + obtain ⟨hpW,hpP,hpM⟩ := Finset.mem_filter.mp hp + have hw := (mem_windowIndices X p).mp hpW + have hp0 : (0 : ℝ) < p := by exact_mod_cast hpP.pos + have hlb := (Real.le_log_iff_exp_le hp0).mpr hw.1 + have hub := (Real.log_le_iff_le_exp hp0).mpr hw.2 + have hbin := (mem_dyadicBatch _ _).mp (logBin_mem p hpP hpM) + have hlow := Real.log_le_log (pow_pos (by norm_num : (0 : ℝ)<2) (Nat.log 2 p)) + (by exact_mod_cast hbin.1 : (2 : ℝ)^Nat.log 2 p ≤ p) + have hhigh := Real.log_lt_log hp0 + (by exact_mod_cast hbin.2.1 : (p : ℝ) < (2 : ℝ)^(Nat.log 2 p+1)) + rw [Real.log_pow] at hlow hhigh + simp only [Nat.cast_add,Nat.cast_one] at hhigh + constructor + · nlinarith [Real.log_two_lt_d9] + · nlinarith + +lemma windowBins_card {X : ℝ} (hX : 1000 ≤ X) : (windowBins X).card ≤ 3*X := by + classical + have hX0 : 0 ≤ X := by linarith + have hs : windowBins X ⊆ Finset.range (⌊2*X⌋₊+1) := by + intro j hj + have h := (windowBin_bounds hX hj).2 + have hlog := Real.log_two_gt_d9 + have hj0 : (0 : ℝ)≤j := Nat.cast_nonneg _ + have hjX : (j : ℝ)≤2*X := by nlinarith + rw [Finset.mem_range,Nat.lt_succ_iff,Nat.le_floor_iff (by positivity : (0 : ℝ)≤2*X)] + exact hjX + have hc : (windowBins X).card ≤ ⌊2*X⌋₊+1 := + (Finset.card_le_card hs).trans_eq (Finset.card_range _) + have hcR : ((windowBins X).card:ℝ) ≤ ⌊2*X⌋₊+1 := by exact_mod_cast hc + have hf := Nat.floor_le (show (0 : ℝ)≤2*X by positivity) + nlinarith + +theorem eventually_dense_split_bins : ∃ c δ : ℝ, 0 < c ∧ 0 < δ ∧ + ∀ᶠ X : ℝ in atTop, ∃ J : Finset ℕ, + c*X ≤ J.card ∧ + ∀ j ∈ J, X ≤ j*Real.log 2 ∧ j*Real.log 2 ≤ 21/20*X ∧ + δ*(2 : ℝ)^j/Real.log ((2 : ℝ)^(j+1)) ≤ (dyadicBatch j).card := by + obtain ⟨c,hc,he⟩ := eventually_prime_window_mass (show IsUnit (1 : ZMod 4) from isUnit_one) + refine ⟨c/(4*Real.log 4),c/6,div_pos hc (by positivity),div_pos hc (by norm_num),?_⟩ + filter_upwards [he,eventually_ge_atTop (1000 : ℝ)] with X hmass hX + let J := (windowBins X).filter (fun j => c/6 ≤ dyadicMass j) + have hh := many_dense_bins (windowBins X) hc (by norm_num : (0 : ℝ)<3) + (windowBins_card hX) (hmass.trans (window_mass_le_bins X)) + refine ⟨J,?_,?_⟩ + · simpa only [show (2 : ℝ)*3=6 by norm_num,div_mul_eq_mul_div] using hh.1 + · intro j hj + have hb := windowBin_bounds hX (Finset.mem_filter.mp hj).1 + have hd := hh.2 j (by simpa only [show (2 : ℝ)*3=6 by norm_num] using hj) + exact ⟨hb.1,hb.2,by simpa only [show (2 : ℝ)*3=6 by norm_num] using hd⟩ + +end PrimeLogMass +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/DifferenceSampling.lean b/lean/OAI/NumberTheory/GaussianMoat/DifferenceSampling.lean new file mode 100644 index 0000000000000000000000000000000000000000..a863f155182e2a81a5ef41835e8ad8a6ea51eb09 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/DifferenceSampling.lean @@ -0,0 +1,238 @@ +import OAI.NumberTheory.GaussianMoat.WalkGeometry + +namespace OAI + +namespace GaussianMoat + +noncomputable def walkSegment (z : ℕ → GaussianInt) (n : ℕ) : Finset GaussianInt := + (Finset.range (n+1)).image z + +noncomputable def differences (E : Finset GaussianInt) : Finset GaussianInt := + (E ×ˢ E).image (fun p => p.1-p.2) + +@[simp] theorem mem_walkSegment (z : ℕ → GaussianInt) (n : ℕ) (w : GaussianInt) : + w ∈ walkSegment z n ↔ ∃ i ≤ n, z i = w := by + simp [walkSegment,Finset.mem_image] + +@[simp] theorem mem_differences (E : Finset GaussianInt) (w : GaussianInt) : + w ∈ differences E ↔ ∃ a ∈ E, ∃ b ∈ E, a-b = w := by + simp [differences,Finset.mem_image,Prod.exists,and_assoc] + +theorem card_le_card_differences {E : Finset GaussianInt} (hE : E.Nonempty) : + E.card ≤ (differences E).card := by + classical + obtain ⟨a,ha⟩ := hE + have hs : E.image (fun b => b-a) ⊆ differences E := by + intro w hw + obtain ⟨b,hb,rfl⟩ := Finset.mem_image.mp hw + exact mem_differences E (b-a) |>.mpr ⟨b,hb,a,ha,rfl⟩ + have hi : Function.Injective (fun b : GaussianInt => b-a) := sub_left_injective + rw [← Finset.card_image_of_injective E hi] + exact Finset.card_le_card hs + +theorem walkSegment_dist_le (z : ℕ → GaussianInt) {n : ℕ} {D : ℝ} (hD : 0 ≤ D) + (hz : ∀ i < n, dist (z i:ℂ) (z (i+1):ℂ) ≤ D) {i j : ℕ} (hi : i ≤ n) (hj : j ≤ n) : + dist (z i:ℂ) (z j:ℂ) ≤ D*n := by + wlog hij : i ≤ j generalizing i j + · rw [dist_comm] + exact this hj hi (by omega) + have h := dist_le_Ico_sum_of_dist_le (f := fun k => (z k:ℂ)) hij + (d := fun _ => D) (fun {k} _ hk => hz k (lt_of_lt_of_le hk hj)) + simp only [Finset.sum_const,Nat.card_Ico,nsmul_eq_mul] at h + calc + dist (z i:ℂ) (z j:ℂ) ≤ (j-i:ℕ)*D := h + _ ≤ (n:ℝ)*D := mul_le_mul_of_nonneg_right (by exact_mod_cast (show j-i ≤ n by omega)) hD + _ = D*n := mul_comm _ _ + +def joinedPath (z : ℕ → GaussianInt) (t : ℕ) (i : ℕ) : GaussianInt := + z (Nat.dist t i)-z t + +@[simp] theorem joinedPath_zero (z : ℕ → GaussianInt) (t : ℕ) : joinedPath z t 0 = 0 := by + simp [joinedPath,Nat.dist] + +@[simp] theorem joinedPath_end (z : ℕ → GaussianInt) (t s : ℕ) : + joinedPath z t (t+s) = z s-z t := by simp [joinedPath,Nat.dist] + +theorem joinedPath_step (z : ℕ → GaussianInt) {n t s : ℕ} (ht : t ≤ n) (hs : s ≤ n) + {D : ℝ} (hz : ∀ i < n, dist (z i:ℂ) (z (i+1):ℂ) ≤ D) : + ∀ i < t+s, dist (joinedPath z t i:ℂ) (joinedPath z t (i+1):ℂ) ≤ D := by + intro i hi + simp only [joinedPath,map_sub,dist_sub_right] + by_cases hit : i < t + · have he : Nat.dist t i = Nat.dist t (i+1)+1 := by simp only [Nat.dist]; omega + rw [he,dist_comm] + exact hz _ (by simp only [Nat.dist]; omega) + · have he : Nat.dist t (i+1) = Nat.dist t i+1 := by simp only [Nat.dist]; omega + rw [he] + exact hz _ (by simp only [Nat.dist]; omega) + +theorem differences_card_of_triangle (z : ℕ → GaussianInt) {n t s u : ℕ} + (ht : t ≤ n) (hs : s ≤ n) (hu : u ≤ n) {D : ℝ} (hD : 0 ≤ D) + (hz : ∀ i < n, dist (z i:ℂ) (z (i+1):ℂ) ≤ D) + (hab : (z s-z t).re*(z u-z t).im-(z s-z t).im*(z u-z t).re ≠ 0) : + ((z s-z t).re*(z u-z t).im-(z s-z t).im*(z u-z t).re).natAbs ≤ + (differences (walkSegment z n)).card * (latticeBall (4*D)).card := by + have hts : 0 < t+s := by + by_contra hh + have ht0 : t=0 := by omega + have hs0 : s=0 := by omega + simp [ht0,hs0] at hab + have htu : 0 < t+u := by + by_contra hh + have ht0 : t=0 := by omega + have hu0 : u=0 := by omega + simp [ht0,hu0] at hab + apply lattice_path_difference_card (joinedPath z t) (joinedPath z t) hts htu + (z s-z t) (z u-z t) (joinedPath_zero z t) (joinedPath_zero z t) + (joinedPath_end z t s) (joinedPath_end z t u) hab hD + (joinedPath_step z ht hs hz) (joinedPath_step z ht hu hz) + intro i hi j hj + apply (mem_differences _ _).mpr + refine ⟨z (Nat.dist t i),(mem_walkSegment _ _ _).mpr ⟨_,?_,rfl⟩, + z (Nat.dist t j),(mem_walkSegment _ _ _).mpr ⟨_,?_,rfl⟩,?_⟩ + · simp only [Nat.dist]; omega + · simp only [Nat.dist]; omega + · simp only [joinedPath]; ring + +noncomputable def diameterRotation (a : ℂ) : ℂ := star a / (‖a‖:ℂ) + +theorem diameterRotation_norm {a : ℂ} (ha : a ≠ 0) : ‖diameterRotation a‖ = 1 := by + simp [diameterRotation,Complex.norm_real,norm_ne_zero_iff.mpr ha] + +theorem diameterRotation_mul (a : ℂ) : diameterRotation a*a = (‖a‖:ℂ) := by + by_cases ha : a=0 + · simp [ha,diameterRotation] + have hn : (‖a‖:ℂ) ≠ 0 := by exact_mod_cast norm_ne_zero_iff.mpr ha + have hm : star a*a = (‖a‖:ℂ)^2 := Complex.conj_mul' a + rw [diameterRotation,div_mul_eq_mul_div,hm] + field_simp + +theorem diameter_rectangle {a v : ℂ} (ha : a ≠ 0) (hv : ‖v‖ ≤ ‖a‖) + (hva : ‖v-a‖ ≤ ‖a‖) : + 0 ≤ (diameterRotation a*v).re ∧ (diameterRotation a*v).re ≤ ‖a‖ ∧ + |(diameterRotation a*v).im| ≤ ‖a‖ := by + let u := diameterRotation a*v + have hn : ‖u‖ ≤ ‖a‖ := by simpa [u,norm_mul,diameterRotation_norm ha] using hv + have hna : ‖u-(‖a‖:ℂ)‖ ≤ ‖a‖ := by + rw [← diameterRotation_mul a,← mul_sub] + simpa [norm_mul,diameterRotation_norm ha] using hva + have hr := Complex.abs_re_le_norm u + have hi := Complex.abs_im_le_norm u + have hra := Complex.abs_re_le_norm (u-(‖a‖:ℂ)) + simp only [Complex.sub_re,Complex.ofReal_re] at hra + have hl := (abs_le.mp (hra.trans hna)).1 + exact ⟨by dsimp [u] at *; linarith, (le_abs_self u.re).trans (hr.trans hn), hi.trans hn⟩ + +theorem diameter_height (a b : GaussianInt) : + |((a.re*b.im-a.im*b.re:ℤ):ℝ)| = + ‖(a:ℂ)‖*|(diameterRotation (a:ℂ)*(b:ℂ)).im| := by + by_cases ha : a=0 + · simp [ha,diameterRotation] + have hna : ‖(a:ℂ)‖ ≠ 0 := norm_ne_zero_iff.mpr (by simpa using ha) + have he : (diameterRotation (a:ℂ)*(b:ℂ)).im = + ((a.re:ℝ)*(b.im:ℝ)-(a.im:ℝ)*(b.re:ℝ))/‖(a:ℂ)‖ := by + simp only [diameterRotation,div_mul_eq_mul_div,Complex.div_ofReal_im, + Complex.mul_im,Complex.star_def,Complex.conj_re,Complex.conj_im, + ← GaussianInt.intCast_re,← GaussianInt.intCast_im] + ring + rw [he,abs_div,abs_of_nonneg (norm_nonneg (a:ℂ))] + push_cast + field_simp + +theorem walk_many_differences (z : ℕ → GaussianInt) {n : ℕ} (hn : 1 ≤ n) + (hinj : Function.Injective z) {D : ℝ} (hD : 1 ≤ D) + (hz : ∀ i < n, dist (z i:ℂ) (z (i+1):ℂ) ≤ D) : + ∃ (R W : ℝ) (e c : ℂ), 1 ≤ W ∧ W ≤ R ∧ ‖e‖ = 1 ∧ + (∀ p ∈ walkSegment z n, 0 ≤ (e*((p:ℂ)-c)).re ∧ + (e*((p:ℂ)-c)).re ≤ R ∧ |(e*((p:ℂ)-c)).im| ≤ W) ∧ + (n:ℝ) ≤ 18*(R*W) ∧ R*W ≤ D^2*(n:ℝ)^2 ∧ + R*W ≤ max D ((latticeBall (4*D)).card:ℝ)*(differences (walkSegment z n)).card := by + classical + let I := Finset.range (n+1) + have hI : I.Nonempty := ⟨0,by simp [I]⟩ + obtain ⟨⟨t,s⟩,hts,hmax⟩ := Finset.exists_max_image (I ×ˢ I) + (fun q => dist (z q.1:ℂ) (z q.2:ℂ)) (hI.product hI) + have ht : t ≤ n := by simpa [I] using (Finset.mem_product.mp hts).1 + have hs : s ≤ n := by simpa [I] using (Finset.mem_product.mp hts).2 + let a := z s-z t + let R := ‖(a:ℂ)‖ + have hdiam : ∀ i ≤ n, ∀ j ≤ n, dist (z i:ℂ) (z j:ℂ) ≤ R := by + intro i hi j hj + have h := hmax (i,j) (by simp [I,hi,hj]) + simpa [R,a,map_sub,← dist_eq_norm,dist_comm] using h + have hR : 1 ≤ R := (lattice_dist_ge_one (hinj.ne (by omega : 0 ≠ 1))).trans (hdiam 0 (by omega) 1 hn) + have ha : a ≠ 0 := by intro hh; simp [R,hh] at hR; linarith + have hac : (a:ℂ) ≠ 0 := by simpa using ha + let e := diameterRotation (a:ℂ) + let c := (z t:ℂ) + have he : ‖e‖ = 1 := diameterRotation_norm hac + have hr : ∀ i ≤ n, 0 ≤ (e*((z i:ℂ)-c)).re ∧ + (e*((z i:ℂ)-c)).re ≤ R ∧ |(e*((z i:ℂ)-c)).im| ≤ R := by + intro i hi + have hv : ‖(z i:ℂ)-c‖ ≤ ‖(a:ℂ)‖ := by simpa only [← dist_eq_norm] using hdiam i hi t ht + have hva : ‖((z i:ℂ)-c)-(a:ℂ)‖ ≤ ‖(a:ℂ)‖ := by + have hh : ((z i:ℂ)-c)-(a:ℂ) = (z i:ℂ)-(z s:ℂ) := by simp [a,c] + rw [hh,← dist_eq_norm] + exact hdiam i hi s hs + exact diameter_rectangle hac hv hva + obtain ⟨u,hu,humax⟩ := Finset.exists_max_image I + (fun i => |(e*((z i:ℂ)-c)).im|) hI + have hu' : u ≤ n := by simpa [I] using hu + let W := max 1 |(e*((z u:ℂ)-c)).im| + have hW : 1 ≤ W := le_max_left _ _ + have hWR : W ≤ R := max_le hR (hr u hu').2.2 + have hrect : ∀ p ∈ walkSegment z n, 0 ≤ (e*((p:ℂ)-c)).re ∧ + (e*((p:ℂ)-c)).re ≤ R ∧ |(e*((p:ℂ)-c)).im| ≤ W := by + intro p hp + obtain ⟨i,hi,rfl⟩ := (mem_walkSegment _ _ _).mp hp + exact ⟨(hr i hi).1,(hr i hi).2.1,(humax i (by simpa [I] using hi)).trans (le_max_right _ _)⟩ + have hcard : (walkSegment z n).card = n+1 := by + rw [walkSegment,Finset.card_image_of_injective _ hinj,Finset.card_range] + have hcount : (n:ℝ)+1 ≤ 18*R*W := by + have h := lattice_rectangle_card (walkSegment z n) he hR hW hrect + simpa only [hcard,Nat.cast_add,Nat.cast_one] using h + have hRD : R ≤ D*n := by + simpa only [R,a,map_sub,← dist_eq_norm] using walkSegment_dist_le z (by linarith) hz hs ht + have hAupper : R*W ≤ D^2*(n:ℝ)^2 := by + have hn0 : (0:ℝ) ≤ n := Nat.cast_nonneg _ + have hm := mul_le_mul hRD hRD (by linarith : 0 ≤ R) (by positivity : 0 ≤ D*n) + have hw := mul_le_mul_of_nonneg_left hWR (by linarith : 0 ≤ R) + nlinarith + refine ⟨R,W,e,c,hW,hWR,he,hrect,by nlinarith,hAupper,?_⟩ + have hdif := card_le_card_differences (E := walkSegment z n) + ⟨z 0,(mem_walkSegment _ _ _).mpr ⟨0,by omega,rfl⟩⟩ + have hcountdif : (n:ℝ)+1 ≤ ((differences (walkSegment z n)).card:ℝ) := by + rw [hcard] at hdif + exact_mod_cast hdif + by_cases hthin : |(e*((z u:ℂ)-c)).im| ≤ 1 + · have hWeq : W = 1 := max_eq_left hthin + rw [hWeq,mul_one] + have hdn : D*(n:ℝ) ≤ D*((differences (walkSegment z n)).card:ℝ) := + mul_le_mul_of_nonneg_left (by linarith) (by linarith) + exact (hRD.trans hdn).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) (by positivity)) + · have hWeq : W = |(e*((z u:ℂ)-c)).im| := max_eq_right (by linarith) + let b := z u-z t + have hdet : |((a.re*b.im-a.im*b.re:ℤ):ℝ)| = R*W := by + rw [diameter_height,hWeq] + simp only [R,e,b,map_sub,c] + have hab : a.re*b.im-a.im*b.re ≠ 0 := by + intro hh + rw [hh,Int.cast_zero,abs_zero] at hdet + have : 0 < R*W := mul_pos (by linarith) (by linarith) + linarith + have hcd := differences_card_of_triangle z ht hs hu' (by linarith) hz hab + have hcd' : |((a.re*b.im-a.im*b.re:ℤ):ℝ)| ≤ + ((differences (walkSegment z n)).card:ℝ)*((latticeBall (4*D)).card:ℝ) := by + have hh : ((a.re*b.im-a.im*b.re).natAbs:ℝ) ≤ + ((differences (walkSegment z n)).card:ℝ)*((latticeBall (4*D)).card:ℝ) := by + exact_mod_cast hcd + simpa only [Nat.cast_natAbs,Int.cast_abs] using hh + rw [hdet] at hcd' + calc + R*W ≤ ((differences (walkSegment z n)).card:ℝ)*((latticeBall (4*D)).card:ℝ) := hcd' + _ = ((latticeBall (4*D)).card:ℝ)*((differences (walkSegment z n)).card:ℝ) := mul_comm _ _ + _ ≤ _ := mul_le_mul_of_nonneg_right (le_max_right _ _) (by positivity) + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/DyadicSieve.lean b/lean/OAI/NumberTheory/GaussianMoat/DyadicSieve.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c6cf2d5ac258a3a31ce701e38bbc1118ac840d8 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/DyadicSieve.lean @@ -0,0 +1,126 @@ +import OAI.NumberTheory.GaussianMoat.InformationTelescope + +namespace OAI + +universe uOmega uIota uBeta + +namespace GaussianMoat +open scoped BigOperators Classical + +noncomputable def chosenSplitFactor (p : ℕ) : GaussianInt := + if h : p.Prime ∧ p%4=1 then (exists_split_factor h.1 h.2).choose else 0 + +lemma chosenSplitFactor_spec {p : ℕ} (hp : p.Prime) (hm : p%4=1) : + Irreducible (chosenSplitFactor p) ∧ (chosenSplitFactor p).norm=(p:ℤ) := by + rw [chosenSplitFactor,dite_eq_left ⟨hp,hm⟩] + exact (exists_split_factor hp hm).choose_spec + +noncomputable def splitSieveOf (S : Finset ℕ) + (hS : ∀ p∈S, p.Prime ∧ p%4=1) : SplitSieve where + primes := S + factor := chosenSplitFactor + prime_mem := fun p hp => (hS p hp).1 + mod_four := fun p hp => (hS p hp).2 + factor_irreducible := fun p hp => (chosenSplitFactor_spec (hS p hp).1 (hS p hp).2).1 + factor_norm := fun p hp => (chosenSplitFactor_spec (hS p hp).1 (hS p hp).2).2 + +noncomputable def dyadicSieve (j : ℕ) : SplitSieve := + splitSieveOf (PrimeLogMass.dyadicBatch j) (fun p hp => by + have h := (PrimeLogMass.mem_dyadicBatch j p).mp hp + exact ⟨h.2.2.1,h.2.2.2⟩) + +lemma gaussian_norm_log_nonneg (f : GaussianInt) : 0≤Real.log f.norm.natAbs := by + by_cases h : f.norm.natAbs=0 + · simp only [h,Nat.cast_zero,Real.log_zero,le_refl] + · exact Real.log_nonneg (by exact_mod_cast Nat.one_le_iff_ne_zero.mpr h) + +noncomputable def residueWeight (F : Finset GaussianInt) : ℝ := + ∑ f∈F, Real.log f.norm.natAbs + +lemma residueWeight_mono {F G : Finset GaussianInt} (h : F⊆G) : residueWeight F≤residueWeight G := + Finset.sum_le_sum_of_subset_of_nonneg h (fun f _ _ => gaussian_norm_log_nonneg f) + +lemma residueWeight_nonneg (F : Finset GaussianInt) : 0≤residueWeight F := + Finset.sum_nonneg (fun f _ => gaussian_norm_log_nonneg f) + +theorem residue_vector_entropy {Ω : Type uOmega} {ι : Type uIota} [Fintype Ω] [Fintype ι] + (p : FinLaw Ω) (z : Ω → GaussianInt) (f : ι → GaussianInt) (hf : ∀ i, f i≠0) : + p.Hf (fun ω i => residueCode (f i) (z ω))≤∑ i, Real.log (f i).norm.natAbs := by + let (i : ι) : Finite (GaussianInt ⧸ multiples (f i)) := finite_gaussianResidue (hf i) + let (i : ι) : Fintype (GaussianInt ⧸ multiples (f i)) := Fintype.ofFinite _ + rw [p.Hf_eq_of_fibers _ (fun ω i => gaussianResidue (f i) (z ω)) + (fun ω ν => residueCode_vector_fibers f (z ω) (z ν))] + have hh := p.Hf_le_log_card_type (fun ω i => gaussianResidue (f i) (z ω)) + rw [Fintype.card_pi,Nat.cast_prod,Real.log_prod] at hh + · convert hh using 1 + apply Finset.sum_congr rfl + intro i _ + rw [← Nat.card_eq_fintype_card,multiples_index (hf i)] + · intro i _ + exact_mod_cast Fintype.card_ne_zero + +lemma residue_finset_entropy {Ω : Type uOmega} [Fintype Ω] (p : FinLaw Ω) + (z : Ω → GaussianInt) (F : Finset GaussianInt) (hf : ∀ f∈F, f≠0) : + p.Hf (fun ω (f : F) => residueCode f.val (z ω))≤residueWeight F := by + have h := residue_vector_entropy p z (fun f : F => f.val) (fun f => hf f.val f.property) + exact h.trans_eq (Finset.sum_subtype F (fun _ => Iff.rfl) + (fun f : GaussianInt => Real.log f.norm.natAbs)).symm + +noncomputable def SplitSieve.availableFactors (s : SplitSieve) : Finset GaussianInt := + Finset.univ.image (fun i : s.primes × Bool => signedFactor (s.factor i.1.val) i.2) + +lemma SplitSieve.signed_mem_available (s : SplitSieve) (i : s.SignedIndex) : + s.signedFactorAt i∈s.availableFactors := by + exact Finset.mem_image.mpr ⟨(s.enumeration i.2,i.1 i.2),Finset.mem_univ _,rfl⟩ + +lemma SplitSieve.available_ne_zero (s : SplitSieve) {f : GaussianInt} (hf : f∈s.availableFactors) : + f≠0 := by + obtain ⟨⟨p,b⟩,_,rfl⟩ := Finset.mem_image.mp hf + intro h + have hn := (signedFactor_norm (s.factor p.val) b).trans (s.factor_norm p.val p.property) + rw [h] at hn + have hp := (s.prime_mem p.val p.property).ne_zero + apply hp + simpa only [Zsqrtd.norm_zero,Nat.cast_eq_zero] using hn.symm + +lemma SplitSieve.available_weight (s : SplitSieve) : + residueWeight s.availableFactors≤2*∑ p∈s.primes, Real.log (p:ℝ) := by + have hh := Finset.sum_image_le_of_nonneg (s := (Finset.univ : Finset (s.primes × Bool))) + (g := fun i : s.primes × Bool => signedFactor (s.factor i.1.val) i.2) + (f := fun f : GaussianInt => Real.log f.norm.natAbs) (fun f _ => gaussian_norm_log_nonneg f) + change residueWeight s.availableFactors≤_ at hh + apply hh.trans_eq + simp only [Fintype.sum_prod_type,signedFactor_norm] + simp only [s.factor_norm _ (Subtype.property _),Int.natAbs_natCast] + simp only [Fintype.sum_bool,Finset.sum_add_distrib] + rw [← Finset.sum_subtype s.primes (fun _ => Iff.rfl) (fun p : ℕ => Real.log (p:ℝ))] + ring + +lemma FinLaw.cIf_finset_union {Ω : Type uOmega} {ι : Type uIota} {β : Type uBeta} [Fintype Ω] [Fintype ι] + (p : FinLaw Ω) (z : Ω → GaussianInt) (Y : Ω → β) + (F : Finset GaussianInt) (f : ι → GaussianInt) : + p.cIf (fun ω (g : ↥(F∪Finset.univ.image f)) => residueCode g.val (z ω)) Y + (fun ω (g : F) => residueCode g.val (z ω))= + p.cIf (fun ω i => residueCode (f i) (z ω)) Y + (fun ω (g : F) => residueCode g.val (z ω)) := by + rw [p.cIf_comm,p.cIf_comm (fun ω i => residueCode (f i) (z ω))] + unfold FinLaw.cIf + congr 1 + apply p.cHf_congr_fibers + · intro ω ν; rfl + · intro ω ν + simp only [Prod.mk.injEq] + constructor + · rintro ⟨hO,hU⟩ + refine ⟨hO,funext fun i => ?_⟩ + exact congrFun hU ⟨f i,Finset.mem_union_right F (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩)⟩ + · rintro ⟨hO,hU⟩ + refine ⟨hO,funext fun g => ?_⟩ + rcases Finset.mem_union.mp g.property with hg|hg + · exact congrFun hO ⟨g.val,hg⟩ + · obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hg + simpa only [hi] using congrFun hU i + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/EntropyBand.lean b/lean/OAI/NumberTheory/GaussianMoat/EntropyBand.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e7746a3d1d59cec48cf7abbeb5d0613dd04a30f --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/EntropyBand.lean @@ -0,0 +1,292 @@ +import OAI.NumberTheory.GaussianMoat.SignedResidues + +namespace OAI + +universe uAlpha uOmega uBeta + +namespace GaussianMoat +open scoped BigOperators Classical + +noncomputable def ForwardKernel.displacementSymbol (K : ForwardKernel) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a : ℕ) : + Fin (K.bound+1) → latticeBall (D*K.bound) := fun i => + ⟨z (a+i.val)-z a,(mem_latticeBall _ _).mpr (by + simpa only [Nat.add_zero] using walk_pair_displacement z hD hs a K.bound i.val 0 + (by omega) (by omega))⟩ + +noncomputable def ForwardKernel.displacementLaw (K : ForwardKernel) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a : ℕ) : + FinLaw (latticeBall (D*K.bound)) := + (K.law a).map (K.displacementSymbol z hD hs a) + +lemma ForwardKernel.displacementLaw_observe (K : ForwardKernel) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a : ℕ) + {α : Type uAlpha} [Fintype α] (f : GaussianInt → α) : + (K.displacementLaw z hD hs a).map (fun d => f (d.val+z a))= + (K.law a).map (fun i => f (z (a+i.val))) := by + rw [displacementLaw,FinLaw.map_comp] + congr 1 + funext i + simp only [Function.comp_def,displacementSymbol,sub_add_cancel] + +theorem continuation_data_entropy {Ω : Type uOmega} [Fintype Ω] (p : FinLaw Ω) + (a : Ω → ℕ) (K : ForwardKernel) (z : ℕ → GaussianInt) {D : ℝ} + (hD : 1≤D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (hK : 1≤K.bound) (n : ℕ) : + (p.joint (fun ω => (K.displacementLaw z (by linarith only [hD]) hs (a ω)).iid n)).Hf + Prod.snd ≤ n*(Real.log 36+2*Real.log (D*K.bound)) := by + let q := fun ω => (K.displacementLaw z (by linarith only [hD]) hs (a ω)).iid n + have hh := (p.joint q).Hf_le_log_card_type Prod.snd + simp only [Fintype.card_fun,Fintype.card_fin,Fintype.card_coe,Nat.cast_pow,Real.log_pow] at hh + have hR : 1≤D*K.bound := one_le_mul_of_one_le_of_one_le hD (by exact_mod_cast hK) + have hc : (0:ℝ)<(latticeBall (D*K.bound)).card := by + exact_mod_cast Finset.card_pos.mpr ⟨0,by simpa using (show 0≤D*K.bound by positivity)⟩ + have hl := Real.log_le_log hc (latticeBall_card_le hR) + rw [Real.log_mul (by norm_num : (36:ℝ)≠0) + (pow_ne_zero _ (by linarith only [hR] : D*K.bound≠0)),Real.log_pow] at hl + exact hh.trans (mul_le_mul_of_nonneg_left hl (Nat.cast_nonneg _)) + +lemma continuation_pointEntropy {Ω : Type uOmega} [Fintype Ω] (s : SplitSieve) + (p : FinLaw Ω) (a : Ω → ℕ) (K : ForwardKernel) (z : ℕ → GaussianInt) {D : ℝ} + (hD : 0≤D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (n b : ℕ) : + s.pointEntropy (p.joint (fun ω => (K.displacementLaw z hD hs (a ω)).iid n)) + (fun v => z (a v.1)) b = s.pointEntropy p (fun ω => z (a ω)) b := by + let q : Ω → FinLaw (Fin n → latticeBall (D*K.bound)) := fun ω => + (K.displacementLaw z hD hs (a ω)).iid n + exact s.pointEntropy_joint_fst p q (fun ω => z (a ω)) b + +noncomputable def ForwardKernel.relativeResidueLaw (K : ForwardKernel) + (s : SplitSieve) (z : ℕ → GaussianInt) (a : ℕ) (i : s.SignedIndex) : FinLaw (s.Residue i) := + (K.law a).map (fun t => s.residue i (z (a+t.val)-z a)) + +lemma ForwardKernel.displacementLaw_residue (K : ForwardKernel) + (s : SplitSieve) (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a : ℕ) (i : s.SignedIndex) : + (K.displacementLaw z hD hs a).map (fun d => s.residue i d.val)= + K.relativeResidueLaw s z a i := by + rw [ForwardKernel.displacementLaw,FinLaw.map_comp] + rfl + +lemma ForwardKernel.then_relativeResidueLaw (K R : ForwardKernel) + (s : SplitSieve) (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a : ℕ) (i : s.SignedIndex) : + (K.then R).relativeResidueLaw s z a i = + ((K.law a).joint (fun t => R.displacementLaw z hD hs (a+t.val))).map + (fun v => s.residue i (z (a+v.1.val)-z a)+s.residue i v.2.val) := by + unfold relativeResidueLaw ForwardKernel.then + rw [FinLaw.map_comp,FinLaw.joint_observation_fun,FinLaw.joint_observation_fun] + congr 1 + funext t + rw [ForwardKernel.displacementLaw,FinLaw.map_comp] + congr 1 + funext u + change s.residue i (z (a+(t.val+u.val))-z a) = + s.residue i (z (a+t.val)-z a)+s.residue i (z (a+t.val+u.val)-z (a+t.val)) + unfold SplitSieve.residue + rw [← gaussianResidue_add] + congr 1 + rw [Nat.add_assoc] + abel + +lemma FinLaw.cHf_const_right {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} [Fintype Ω] + (p : FinLaw Ω) (X : Ω → α) (c : β) : p.cHf X (fun _ => c)=p.Hf X := by + unfold cHf + rw [p.Hf_const,sub_zero] + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq,and_true] + +lemma ForwardKernel.residue_deficit (K : ForwardKernel) + (s : SplitSieve) (hne : s.primes.Nonempty) (z : ℕ → GaussianInt) (a : ℕ) + {b : ℕ} (hb : 0 z (a+t.val)) b) : + letI := s.signedIndex_nonempty hne + (∑ i : s.SignedIndex, FinLaw.uniform _ i*(Real.log (Fintype.card (s.Residue i))- + (K.relativeResidueLaw s z a i).entropy))≤e*s.meanLog := by + let := s.signedIndex_nonempty hne + have hh := s.signed_coverage_deficit hne (K.law a) (fun t => z (a+t.val)) + (fun _ => ()) (z a) hb hbk hH (E := 0) (by rw [FinLaw.Hf_const]) + simp only [FinLaw.cHf_const_right,zero_div,add_zero] at hh + change (∑ i, FinLaw.uniform _ i*(Real.log (Fintype.card (s.Residue i))- + (K.law a).H (fun t => s.residue i (z (a+t.val)-z a))))≤_ + simpa only [FinLaw.Hf_eq_H] using hh + +theorem ForwardKernel.coverage_base (K : ForwardKernel) + (s : SplitSieve) (hne : s.primes.Nonempty) (z : ℕ → GaussianInt) (a : ℕ) + {b : ℕ} (hb : 0 z (a+t.val)) b) : + letI := s.signedIndex_nonempty hne + (FinLaw.uniform s.SignedIndex).prob (fun i => + u i≤((K.relativeResidueLaw s z a i).lowResidues τ).card) ≤e*s.meanLog/c := by + let := s.signedIndex_nonempty hne + apply FinLaw.lowResidues_base s.Residue (FinLaw.uniform _) (K.relativeResidueLaw s z a) u + hτ hc + · intro i + simpa only [s.residue_card] using hu i + · exact K.residue_deficit s hne z a hb hbk hH + +lemma ForwardKernel.coverage_data_deficit (K R : ForwardKernel) + (s : SplitSieve) (hne : s.primes.Nonempty) (z : ℕ → GaussianInt) {D : ℝ} + (hD : 1≤D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (hR : 1≤R.bound) + (a n : ℕ) {b : ℕ} (hb : 0 z (a+t.val)) b) : + letI := s.signedIndex_nonempty hne + (∑ i : s.SignedIndex, FinLaw.uniform _ i*(Real.log (Fintype.card (s.Residue i))- + ((K.law a).joint (fun t => (R.displacementLaw z (by linarith only [hD]) hs (a+t.val)).iid n)).cHf + (fun v => s.residue i (z (a+v.1.val)-z a)) Prod.snd)) ≤ + e*s.meanLog+n*(Real.log 36+2*Real.log (D*R.bound))/b := by + let := s.signedIndex_nonempty hne + let q := fun t : Fin (K.bound+1) => + (R.displacementLaw z (by linarith only [hD]) hs (a+t.val)).iid n + let P := (K.law a).joint q + have he : s.pointEntropy P (fun v => z (a+v.1.val)) b = + s.pointEntropy (K.law a) (fun t => z (a+t.val)) b := + s.pointEntropy_joint_fst (K.law a) q (fun t => z (a+t.val)) b + have hH' : (1-e)*(b:ℝ)*s.meanLog≤ s.pointEntropy P (fun v => z (a+v.1.val)) b := by + rw [he]; exact hH + exact s.signed_coverage_deficit hne P (fun v => z (a+v.1.val)) Prod.snd (z a) + hb hbk hH' (continuation_data_entropy (K.law a) (fun t => a+t.val) R z hD hs hR n) + +theorem ForwardKernel.coverage_backward (K R : ForwardKernel) + (s : SplitSieve) (hne : s.primes.Nonempty) (z : ℕ → GaussianInt) {D : ℝ} + (hD : 1≤D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (hR : 1≤R.bound) + (a : ℕ) (u u' c : s.SignedIndex → ℝ) {τ δ ε η η' e v : ℝ} {n b : ℕ} + (hn : 0 z (a+t.val)) b) + (hnext : ∀ t, letI := s.signedIndex_nonempty hne + (FinLaw.uniform s.SignedIndex).prob (fun i => u' i≤ + ((R.relativeResidueLaw s z t i).lowResidues (τ+4*δ)).card)≤η') + (hsmall : η'+ε≤η*δ/2) (hscale : 2*(1-Real.log (η*δ/2))≤v) + (hgap : e*s.meanLog+n*(Real.log 36+2*Real.log (D*R.bound))/b<η*δ*v/4) + (hc : ∀ i, 1≤c i) (hv : ∀ i, v≤Real.log (s.signedPrime i)-Real.log (c i)) + (hu' : ∀ i, u' i/δ≤c i) + (herr : ∀ i, (s.signedPrime i:ℝ)*Real.exp + (-(n:ℝ)*δ^2*u i/(2*(s.signedPrime i:ℝ)))≤ε) : + letI := s.signedIndex_nonempty hne + (FinLaw.uniform s.SignedIndex).prob (fun i => + u i≤(((K.then R).relativeResidueLaw s z a i).lowResidues τ).card)≤η := by + let := s.signedIndex_nonempty hne + let w := FinLaw.uniform s.SignedIndex + let q := fun t : Fin (K.bound+1) => R.displacementLaw z (by linarith only [hD]) hs (a+t.val) + have hnxt : (∑ i, w i*(K.law a).prob (fun t => u' i≤ + (((q t).map (fun d => s.residue i d.val)).lowResidues (τ+4*δ)).card))≤η' := by + simp only [q,ForwardKernel.displacementLaw_residue,FinLaw.prob,Finset.mul_sum] + rw [Finset.sum_comm] + have he : (∑ t, ∑ i, w i*(if u' i≤ + ((R.relativeResidueLaw s z (a+t.val) i).lowResidues (τ+4*δ)).card then K.law a t else 0)) = + ∑ t, K.law a t*w.prob (fun i => u' i≤ + ((R.relativeResidueLaw s z (a+t.val) i).lowResidues (τ+4*δ)).card) := by + unfold FinLaw.prob + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro t _ + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> ring + rw [he] + have hh := Finset.sum_le_sum (s := Finset.univ) (fun t _ => + mul_le_mul_of_nonneg_left (hnext (a+t.val)) ((K.law a).nonneg t)) + simpa only [← Finset.sum_mul,(K.law a).sum_one,one_mul] using hh + have hd := K.coverage_data_deficit R s hne z hD hs hR a n hb hbk hH + have hh := FinLaw.lowResidues_backward s.Residue w (K.law a) q + (fun i t => s.residue i (z (a+t.val)-z a)) (fun i d => s.residue i d.val) + u u' c hn hτ hτ1 hδ hδ1 hε hη hu hnxt hsmall hscale hgap hd hc + (by intro i; simpa only [s.residue_card] using hv i) hu' + (by intro i; simpa only [s.residue_card] using herr i) + have he (i : s.SignedIndex) := K.then_relativeResidueLaw R s z + (by linarith only [hD]) hs a i + simpa only [he] using hh + +structure EntropyBand (s : SplitSieve) (D : ℝ) (ns : List ℕ) (N b : ℕ) (δ : ℝ) where + pre : List ℕ + post : List ℕ + g : ℝ + U : ℝ + l : ℕ + e : ℝ + schedule : ns=pre++List.ofFn (fun i : Fin l => bandLength g U i.val)++post + size : b=bandSize s g U l + positive : 0 z (a+t.val)) b := by + rcases q with ⟨pre,post,g,U,l,e,heq,hb,hg,hg1,hU,hlog,hlarge,hsize,hdisp,hgeom,hcap,hcost,hδ⟩ + subst ns b + have hh := commonSchedule_subband_entropy s hne z hz pre post a N hD hT hs hpT + hg hg1 hL hU hlog hlarge hsize hdisp hgeom hcap hcost + have hn : 0≤(bandSize s g U l:ℝ)*s.meanLog := mul_nonneg (Nat.cast_nonneg _) (by linarith only [hL]) + nlinarith only [hh,hδ,hn] + +inductive CoverageDerivation (s : SplitSieve) (D : ℝ) (N : ℕ) : + List ℕ → ℝ → (s.SignedIndex → ℝ) → ℝ → Prop + | base (ns : List ℕ) (b : ℕ) (τ c e η : ℝ) (u : s.SignedIndex → ℝ) + (band : EntropyBand s D ns N b e) + (hb : 0 u i≤ + (((commonSchedule z ns N).relativeResidueLaw s z a i).lowResidues τ).card)≤η := by + let := s.signedIndex_nonempty hne + induction q with + | base ns b τ c e η u band hb hbk hτ hc hu hη => + intro a + exact ((commonSchedule z ns N).coverage_base s hne z a hb hbk u hτ hc hu + (band.sound hne z hz hD hT hs hpT hL a)).trans hη + | step ns rest b n τ δ ε η η' e v u u' c band next hR hn hb hbk hτ hτ1 hδ hδ1 + hε hη hu hsmall hscale hgap hc hv hu' herr ih => + intro a + rw [commonSchedule_append] + apply (commonSchedule z ns 0).coverage_backward (commonSchedule z rest N) s hne z + hD hs (by simpa only [commonSchedule_bound] using hR) a u u' c hn hb hbk hτ hτ1 hδ hδ1 hε hη hu + (band.sound hne z hz hD hT hs hpT hL a) ih hsmall hscale + · simpa only [commonSchedule_bound,Nat.cast_add] using hgap + · exact hc + · exact hv + · exact hu' + · exact herr + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/FiniteEntropy.lean b/lean/OAI/NumberTheory/GaussianMoat/FiniteEntropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..dc2480006a3e7f440e72a8c8557c3f0cb88f38a7 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/FiniteEntropy.lean @@ -0,0 +1,365 @@ +import OAI.NumberTheory.GaussianMoat.DifferenceSampling + +namespace OAI + +universe uOmega uAlpha uBeta uGamma uIota uDelta uEpsilon uZeta + +namespace GaussianMoat + +namespace FinLaw + +section + +variable {Ω : Type uOmega} [Fintype Ω] + +noncomputable def Hf {α : Type uAlpha} (p : FinLaw Ω) (X : Ω → α) : ℝ := by + classical + exact -∑ ω, p ω * Real.log (∑ ν, if X ν = X ω then p ν else 0) + +noncomputable def cHf {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : ℝ := + p.Hf (fun ω => (X ω,Y ω))-p.Hf Y + +theorem Hf_eq_H {α : Type uAlpha} [Fintype α] (p : FinLaw Ω) (X : Ω → α) : p.Hf X = p.H X := by + classical + rw [H_eq_sum] + simp only [Hf,map_mass] + +theorem Hf_eq_of_fibers {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) + (hf : ∀ ω ν, X ω = X ν ↔ Y ω = Y ν) : p.Hf X = p.Hf Y := by + classical + unfold Hf + congr 1 + apply Finset.sum_congr rfl + intro ω _ + congr 2 + apply Finset.sum_congr rfl + intro ν _ + rw [hf] + +noncomputable def outputRange {α : Type uAlpha} (X : Ω → α) : Finset α := by + classical + exact Finset.univ.image X + +noncomputable def outputCode {α : Type uAlpha} (X : Ω → α) (ω : Ω) : outputRange X := + ⟨X ω,by + classical + simp [outputRange]⟩ + +@[simp] theorem outputCode_eq_iff {α : Type uAlpha} (X : Ω → α) (ω ν : Ω) : + outputCode X ω = outputCode X ν ↔ X ω = X ν := Subtype.ext_iff + +theorem Hf_code {α : Type uAlpha} (p : FinLaw Ω) (X : Ω → α) : + p.Hf X = p.H (outputCode X) := by + rw [← Hf_eq_H] + exact p.Hf_eq_of_fibers _ _ (fun _ _ => (outputCode_eq_iff _ _ _).symm) + +theorem Hf_pair_code {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.Hf (fun ω => (X ω,Y ω)) = p.H (fun ω => (outputCode X ω,outputCode Y ω)) := by + rw [← Hf_eq_H] + apply p.Hf_eq_of_fibers + simp only [Prod.mk.injEq,outputCode_eq_iff,implies_true] + +theorem Hf_triple_code {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) + (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.Hf (fun ω => (X ω,(Y ω,Z ω))) = + p.H (fun ω => (outputCode X ω,(outputCode Y ω,outputCode Z ω))) := by + rw [← Hf_eq_H] + apply p.Hf_eq_of_fibers + simp only [Prod.mk.injEq,outputCode_eq_iff,implies_true] + +theorem Hf_nonneg {α : Type uAlpha} (p : FinLaw Ω) (X : Ω → α) : 0 ≤ p.Hf X := by + rw [Hf_code] + exact (p.map _).entropy_nonneg + +theorem Hf_le_log_card_sample {α : Type uAlpha} (p : FinLaw Ω) (X : Ω → α) : + p.Hf X ≤ Real.log (Fintype.card Ω) := by + rw [Hf_code] + refine (p.map _).entropy_le_log_card.trans ?_ + have hsel := Fintype.card_le_of_surjective (outputCode X) (fun ⟨x,hx⟩ => by + classical + obtain ⟨ω,_,hω⟩ := Finset.mem_image.mp hx + exact ⟨ω,Subtype.ext hω⟩) + exact Real.log_le_log (by exact_mod_cast Fintype.card_pos_iff.mpr (p.map (outputCode X)).nonempty) + (by exact_mod_cast hsel) + +theorem Hf_pair_comm {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.Hf (fun ω => (X ω,Y ω)) = p.Hf (fun ω => (Y ω,X ω)) := by + apply p.Hf_eq_of_fibers + simp only [Prod.mk.injEq,and_comm,implies_true] + +theorem Hf_pair_assoc {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.Hf (fun ω => (X ω,(Y ω,Z ω))) = p.Hf (fun ω => ((X ω,Y ω),Z ω)) := by + apply p.Hf_eq_of_fibers + simp only [Prod.mk.injEq,and_assoc,implies_true] + +theorem Hf_pair_ge_snd {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.Hf Y ≤ p.Hf (fun ω => (X ω,Y ω)) := by + rw [Hf_pair_code,Hf_code] + exact p.H_pair_ge_snd _ _ + +theorem Hf_pair_subadd {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.Hf (fun ω => (X ω,Y ω)) ≤ p.Hf X+p.Hf Y := by + rw [Hf_pair_code,Hf_code p X,Hf_code p Y] + exact p.H_pair_subadd _ _ + +theorem Hf_strong_subadd {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.Hf (fun ω => (X ω,(Y ω,Z ω)))+p.Hf Y ≤ + p.Hf (fun ω => (X ω,Y ω))+p.Hf (fun ω => (Y ω,Z ω)) := by + rw [Hf_triple_code,Hf_code p Y,Hf_pair_code p X Y,Hf_pair_code p Y Z] + exact p.H_strong_subadd _ _ _ + +theorem cHf_nonneg {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + 0 ≤ p.cHf X Y := sub_nonneg.mpr (p.Hf_pair_ge_snd X Y) + +theorem cHf_le_Hf {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.cHf X Y ≤ p.Hf X := by have := p.Hf_pair_subadd X Y; unfold cHf; linarith + +theorem cHf_mono {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.cHf X (fun ω => (Y ω,Z ω)) ≤ p.cHf X Y := by + have := p.Hf_strong_subadd X Y Z + unfold cHf + linarith + +theorem Hf_comp_le {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (f : α → β) : + p.Hf (f ∘ X) ≤ p.Hf X := by + have h := p.Hf_pair_ge_snd X (f ∘ X) + have he : p.Hf (fun ω => (X ω,(f ∘ X) ω)) = p.Hf X := + p.Hf_eq_of_fibers _ _ (fun _ _ => by + simp only [Prod.mk.injEq,Function.comp_def] + exact ⟨And.left,fun hh => ⟨hh,congrArg f hh⟩⟩) + rwa [he] at h + +theorem Hf_le_of_determined {α : Type uAlpha} {β : Type uBeta} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) + (h : ∀ ω ν, Y ω = Y ν → X ω = X ν) : p.Hf X ≤ p.Hf Y := by + have hh := p.Hf_pair_ge_snd Y X + have he : p.Hf (fun ω => (Y ω,X ω)) = p.Hf Y := + p.Hf_eq_of_fibers _ _ (fun ω ν => by + simp only [Prod.mk.injEq] + exact ⟨And.left,fun hh => ⟨hh,h ω ν hh⟩⟩) + rwa [he] at hh + +theorem Hf_const {α : Type uAlpha} (p : FinLaw Ω) (a : α) : p.Hf (fun _ => a) = 0 := by + classical + simp [Hf,p.sum_one] + +theorem Hf_finset_subadd {ι : Type uIota} {α : Type uAlpha} (p : FinLaw Ω) (X : Ω → ι → α) (S : Finset ι) : + p.Hf (fun ω (i : S) => X ω i) ≤ ∑ i ∈ S, p.Hf (fun ω => X ω i) := by + classical + induction S using Finset.induction_on with + | empty => + have he : p.Hf (fun ω (i : (∅:Finset ι)) => X ω i) = p.Hf (fun _ => ()) := by + apply p.Hf_eq_of_fibers + intro ω ν + simp only [iff_true] + funext i + exact False.elim (Finset.notMem_empty i.val i.property) + simp [he,p.Hf_const] + | @insert i S hi ih => + have he : p.Hf (fun ω (j : (insert i S : Finset ι)) => X ω j) = + p.Hf (fun ω => (X ω i,fun j : S => X ω j)) := by + apply p.Hf_eq_of_fibers + intro ω ν + constructor + · intro h + apply Prod.ext + · exact congrFun h ⟨i,Finset.mem_insert_self _ _⟩ + · funext j; exact congrFun h ⟨j,Finset.mem_insert_of_mem j.property⟩ + · intro h + funext j + rcases Finset.mem_insert.mp j.property with hj | hj + · simpa [hj] using congrArg Prod.fst h + · exact congrFun (congrArg Prod.snd h) ⟨j,hj⟩ + rw [he,Finset.sum_insert hi] + have hh := p.Hf_pair_subadd (fun ω => X ω i) (fun ω (j : S) => X ω j) + linarith + +end +open scoped BigOperators + +variable {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] {k : ℕ} + +def prefixVar (X : Ω → Fin k → α) (π : Equiv.Perm (Fin k)) (s : ℕ) (ω : Ω) (i : Fin k) : Option α := + if i.val < s then some (X ω (π i)) else none + +noncomputable def orderedEntropy (p : FinLaw Ω) (X : Ω → Fin k → α) (s : ℕ) : ℝ := + 𝔼 π : Equiv.Perm (Fin k), p.Hf (prefixVar X π s) + +omit [Fintype Ω] in +@[simp] theorem prefixVar_zero (X : Ω → Fin k → α) (π : Equiv.Perm (Fin k)) (ω : Ω) : + prefixVar X π 0 ω = fun _ => none := by funext i; simp [prefixVar] + +@[simp] theorem orderedEntropy_zero (p : FinLaw Ω) (X : Ω → Fin k → α) : + p.orderedEntropy X 0 = 0 := by + have h (π : Equiv.Perm (Fin k)) : prefixVar X π 0 = fun _ _ => none := by + funext ω i + simp [prefixVar] + simp [orderedEntropy,h,Finset.expect,p.Hf_const] + +theorem orderedEntropy_nonneg (p : FinLaw Ω) (X : Ω → Fin k → α) (s : ℕ) : + 0 ≤ p.orderedEntropy X s := Finset.expect_nonneg (fun _ _ => p.Hf_nonneg _) + +theorem prefixVar_chain (p : FinLaw Ω) (X : Ω → Fin k → α) (π : Equiv.Perm (Fin k)) + {s : ℕ} (hs : s < k) : + p.Hf (prefixVar X π (s+1)) = + p.Hf (fun ω => (X ω (π ⟨s,hs⟩),prefixVar X π s ω)) := by + apply p.Hf_eq_of_fibers + intro ω ν + constructor + · intro h + apply Prod.ext + · have hh := congrFun h ⟨s,hs⟩ + simpa [prefixVar] using hh + · funext i + by_cases hi : i.val < s + · have hh := congrFun h i + simpa [prefixVar,hi,show i.val X ω (π ⟨s,hs⟩)) (prefixVar X π s) := by + simp only [orderedEntropy,← Finset.expect_sub_distrib,cHf,p.prefixVar_chain X _ hs] + +theorem ordered_remaining_exchange (p : FinLaw Ω) (X : Ω → Fin k → α) (s : ℕ) + (i j : Fin k) (hi : s ≤ i.val) (hj : s ≤ j.val) : + (𝔼 π : Equiv.Perm (Fin k), p.cHf (fun ω => X ω (π i)) (prefixVar X π s)) = + 𝔼 π : Equiv.Perm (Fin k), p.cHf (fun ω => X ω (π j)) (prefixVar X π s) := by + classical + apply Fintype.expect_equiv (Equiv.mulRight (Equiv.swap i j)) + intro π + have hp : prefixVar X (π*Equiv.swap i j) s = prefixVar X π s := by + funext ω a + by_cases ha : a.val X ω (π i)) (prefixVar X π s) = + p.cHf (fun ω => X ω ((π * Equiv.swap i j) j)) (prefixVar X (π * Equiv.swap i j) s) + rw [hp] + simp only [Equiv.Perm.mul_apply,Equiv.swap_apply_right] + +theorem cHf_mono_of_refines {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) + (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) + (h : ∀ ω ν, Y ω = Y ν → Z ω = Z ν) : p.cHf X Y ≤ p.cHf X Z := by + have hc := p.cHf_mono X Z Y + have hy : p.Hf (fun ω => (Z ω,Y ω)) = p.Hf Y := by + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq] + exact ⟨And.right,fun hh => ⟨h ω ν hh,hh⟩⟩ + have hx : p.Hf (fun ω => (X ω,(Z ω,Y ω))) = p.Hf (fun ω => (X ω,Y ω)) := by + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq] + exact ⟨fun hh => ⟨hh.1,hh.2.2⟩,fun hh => ⟨hh.1,h ω ν hh.2,hh.2⟩⟩ + unfold cHf at hc ⊢ + rwa [hy,hx] at hc + +theorem orderedEntropy_concave (p : FinLaw Ω) (X : Ω → Fin k → α) {s : ℕ} (hs : s+1 < k) : + p.orderedEntropy X (s+2)-p.orderedEntropy X (s+1) ≤ + p.orderedEntropy X (s+1)-p.orderedEntropy X s := by + rw [p.orderedEntropy_step X hs,p.orderedEntropy_step X (by omega : s simp + | succ s ih => + have ih' := ih (by omega) + have hc := p.orderedEntropy_concave X hs + have hn : (0 : ℝ) ≤ s+1 := by positivity + have hm := mul_le_mul_of_nonneg_left hc hn + simp only [Nat.cast_add,Nat.cast_one] at * + nlinarith + exact (le_div_iff₀ (by exact_mod_cast hb)).mpr (by nlinarith [h b hbk]) + +noncomputable def signedEntropy (p : FinLaw Ω) (X : (Fin k → Bool) → Ω → Fin k → α) (s : ℕ) : ℝ := + 𝔼 σ : Fin k → Bool, p.orderedEntropy (X σ) s + +@[simp] theorem signedEntropy_zero (p : FinLaw Ω) (X : (Fin k → Bool) → Ω → Fin k → α) : + p.signedEntropy X 0 = 0 := by simp [signedEntropy,Finset.expect] + +theorem signedEntropy_slope (p : FinLaw Ω) (X : (Fin k → Bool) → Ω → Fin k → α) + {b : ℕ} (hb : 0 < b) (hbk : b < k) : + p.signedEntropy X (b+1)-p.signedEntropy X b ≤ p.signedEntropy X b / b := by + unfold signedEntropy + rw [← Finset.expect_sub_distrib,Finset.expect_div] + exact Finset.expect_le_expect (fun σ _ => p.orderedEntropy_slope (X σ) hb hbk) + +theorem cHf_chain {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.cHf (fun ω => (X ω,Y ω)) Z = p.cHf X Z + p.cHf Y (fun ω => (X ω,Z ω)) := by + unfold cHf + have he : p.Hf (fun ω => ((X ω,Y ω),Z ω)) = p.Hf (fun ω => (Y ω,(X ω,Z ω))) := by + apply p.Hf_eq_of_fibers + simp only [Prod.mk.injEq] + tauto + rw [he] + ring + +theorem cHf_pair_subadd {β : Type uBeta} {γ : Type uGamma} (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.cHf (fun ω => (X ω,Y ω)) Z ≤ p.cHf X Z + p.cHf Y Z := by + rw [p.cHf_chain] + apply add_le_add le_rfl + apply p.cHf_mono_of_refines + intro ω ν h + exact congrArg Prod.snd h + +theorem enrichment_chain {β : Type uBeta} {γ : Type uGamma} {δ : Type uDelta} {ε : Type uEpsilon} {ζ : Type uZeta} (p : FinLaw Ω) + (X : Ω → α) (Y : Ω → β) (Bx : Ω → γ) (By : Ω → δ) (h : Ω → ε) (H : Ω → ζ) + (hh : ∀ ω ν, X ω = X ν → Y ω = Y ν → h ω = h ν) + (hY : ∀ ω ν, X ω = X ν → h ω = h ν → Y ω = Y ν) + (hH : ∀ ω ν, H ω = H ν → h ω = h ν) : + p.cHf h (fun ω => (Bx ω,By ω)) ≤ p.cHf X Bx + p.cHf Y By - + p.cHf X (fun ω => ((Bx ω,By ω),H ω)) := by + let B := fun ω => (Bx ω,By ω) + have he : p.cHf (fun ω => (h ω,X ω)) B = p.cHf (fun ω => (X ω,Y ω)) B := by + unfold cHf + congr 1 + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq] + exact ⟨fun ha => ⟨⟨ha.1.2,hY ω ν ha.1.2 ha.1.1⟩,ha.2⟩, + fun ha => ⟨⟨hh ω ν ha.1.1 ha.1.2,ha.1.1⟩,ha.2⟩⟩ + have hx : p.cHf X B ≤ p.cHf X Bx := + p.cHf_mono_of_refines _ _ _ (fun _ _ he => congrArg Prod.fst he) + have hy : p.cHf Y B ≤ p.cHf Y By := + p.cHf_mono_of_refines _ _ _ (fun _ _ he => congrArg Prod.snd he) + have ht : p.cHf X (fun ω => (B ω,H ω)) ≤ p.cHf X (fun ω => (h ω,B ω)) := by + apply p.cHf_mono_of_refines + intro ω ν he + apply Prod.ext + · exact hH ω ν (congrArg Prod.snd he) + · exact congrArg Prod.fst he + have hc := p.cHf_chain h X B + have hs := p.cHf_pair_subadd X Y B + change p.cHf h B ≤ p.cHf X Bx + p.cHf Y By - p.cHf X (fun ω => (B ω,H ω)) + linarith + +end FinLaw + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/FiniteLaw.lean b/lean/OAI/NumberTheory/GaussianMoat/FiniteLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..1afa312b97e152deef51599b4feee1a4085ad63f --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/FiniteLaw.lean @@ -0,0 +1,583 @@ +import OAI.NumberTheory.GaussianMoat.SignedGeometry + +namespace OAI + +universe uAlpha uBeta uGamma uOmega uDelta + +namespace GaussianMoat +open MeasureTheory ProbabilityTheory +open scoped NNReal + +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +noncomputable def entropySum {α : Type uAlpha} [Fintype α] (p : α → ℝ) : ℝ := + ∑ a, Real.negMulLog (p a) + +theorem gibbs_point {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) (habs : q = 0 → p = 0) : + p - q ≤ p * (Real.log p - Real.log q) := by + by_cases hp0 : p = 0 + · simp [hp0, hq] + have hpp : 0 < p := lt_of_le_of_ne hp (Ne.symm hp0) + have hqp : 0 < q := lt_of_le_of_ne hq (Ne.symm (fun h => hp0 (habs h))) + have h := mul_le_mul_of_nonneg_left + (Real.self_sub_one_le_mul_log (div_nonneg hp hq)) hq + rw [Real.log_div hp0 hqp.ne'] at h + have h1 : q*(p/q-1) = p-q := by field_simp + have h2 : q*(p/q*(Real.log p-Real.log q)) = p*(Real.log p-Real.log q) := by field_simp + rwa [h1,h2] at h + +theorem gibbs_sum {α : Type uAlpha} [Fintype α] (p q : α → ℝ) + (hp : ∀ a, 0 ≤ p a) (hq : ∀ a, 0 ≤ q a) + (habs : ∀ a, q a = 0 → p a = 0) (hsum : ∑ a, p a = ∑ a, q a) : + 0 ≤ ∑ a, p a * (Real.log (p a) - Real.log (q a)) := by + have h := Finset.sum_le_sum (s := Finset.univ) (fun a _ => gibbs_point (hp a) (hq a) (habs a)) + simpa [Finset.sum_sub_distrib, hsum] using h + +theorem entropySum_subadd {α : Type uAlpha} {β : Type uBeta} [Fintype α] [Fintype β] + (p : α → β → ℝ) (hp : ∀ a b, 0 ≤ p a b) : + (∑ a, ∑ b, Real.negMulLog (p a b)) + Real.negMulLog (∑ a, ∑ b, p a b) ≤ + (∑ a, Real.negMulLog (∑ b, p a b)) + ∑ b, Real.negMulLog (∑ a, p a b) := by + classical + let r := fun a => ∑ b, p a b + let c := fun b => ∑ a, p a b + let m := ∑ a, r a + have hr : ∀ a, 0 ≤ r a := fun a => Finset.sum_nonneg (fun b _ => hp a b) + have hc : ∀ b, 0 ≤ c b := fun b => Finset.sum_nonneg (fun a _ => hp a b) + have hm : 0 ≤ m := Finset.sum_nonneg (fun a _ => hr a) + have hpr : ∀ a b, p a b ≤ r a := fun a b => + Finset.single_le_sum (fun b' _ => hp a b') (Finset.mem_univ b) + have hpc : ∀ a b, p a b ≤ c b := fun a b => + Finset.single_le_sum (fun a' _ => hp a' b) (Finset.mem_univ a) + have hrm : ∀ a, r a ≤ m := fun a => + Finset.single_le_sum (fun a' _ => hr a') (Finset.mem_univ a) + have hcm : ∑ b, c b = m := Finset.sum_comm + by_cases hm0 : m = 0 + · have hz : ∀ a b, p a b = 0 := fun a b => le_antisymm (by simpa [hm0] using (hpr a b).trans (hrm a)) (hp a b) + simp [hz] + have hmp : 0 < m := lt_of_le_of_ne hm (Ne.symm hm0) + let q := fun ab : α × β => r ab.1 * c ab.2 / m + have hq : ∀ ab, 0 ≤ q ab := fun ab => div_nonneg (mul_nonneg (hr _) (hc _)) hm + have habs : ∀ ab : α × β, q ab = 0 → p ab.1 ab.2 = 0 := by + intro ab hh + by_contra h + have hpp : 0 < p ab.1 ab.2 := lt_of_le_of_ne (hp _ _) (Ne.symm h) + have hrp : 0 < r ab.1 := hpp.trans_le (hpr _ _) + have hcp : 0 < c ab.2 := hpp.trans_le (hpc _ _) + exact (div_pos (mul_pos hrp hcp) hmp).ne' hh + have hqsum : ∑ ab, q ab = m := by + rw [Fintype.sum_prod_type] + change (∑ a, ∑ b, r a*c b/m) = m + have hi : ∀ a, (∑ b, r a*c b/m) = r a := by + intro a + calc + _ = (r a*(∑ b, c b))/m := by rw [Finset.mul_sum, Finset.sum_div] + _ = r a := by rw [hcm, mul_div_cancel_right₀ _ hm0] + simp_rw [hi] + rfl + have hg := gibbs_sum (fun ab : α × β => p ab.1 ab.2) q (fun _ => hp _ _) hq habs + (by rw [hqsum, Fintype.sum_prod_type]) + have ht : ∀ a b, p a b * (Real.log (p a b) - Real.log (q (a,b))) = + p a b*Real.log (p a b) - p a b*Real.log (r a) - p a b*Real.log (c b) + p a b*Real.log m := by + intro a b + by_cases hz : p a b = 0 + · simp [hz] + have hpp : 0 < p a b := lt_of_le_of_ne (hp _ _) (Ne.symm hz) + have hrp : 0 < r a := hpp.trans_le (hpr _ _) + have hcp : 0 < c b := hpp.trans_le (hpc _ _) + dsimp [q] + rw [Real.log_div (mul_pos hrp hcp).ne' hm0, Real.log_mul hrp.ne' hcp.ne'] + ring + have hrow : (∑ a, ∑ b, p a b * Real.log (r a)) = ∑ a, r a*Real.log (r a) := by + simp_rw [← Finset.sum_mul] + rfl + have hcol : (∑ a, ∑ b, p a b * Real.log (c b)) = ∑ b, c b*Real.log (c b) := by + rw [Finset.sum_comm] + simp_rw [← Finset.sum_mul] + rfl + have htot : (∑ a, ∑ b, p a b * Real.log m) = m*Real.log m := by + simp_rw [← Finset.sum_mul] + rfl + rw [Fintype.sum_prod_type] at hg + simp_rw [ht, Finset.sum_add_distrib, Finset.sum_sub_distrib] at hg + rw [hrow,hcol,htot] at hg + change (∑ a, ∑ b, Real.negMulLog (p a b)) + Real.negMulLog m ≤ + (∑ a, Real.negMulLog (r a)) + ∑ b, Real.negMulLog (c b) + simp only [Real.negMulLog, neg_mul, Finset.sum_neg_distrib] + linarith + +theorem negMulLog_sum_le {α : Type uAlpha} [Fintype α] (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) : + Real.negMulLog (∑ a, p a) ≤ ∑ a, Real.negMulLog (p a) := by + have ht : ∀ a, -p a * Real.log (∑ b, p b) ≤ Real.negMulLog (p a) := by + intro a + by_cases hz : p a = 0 + · simp [hz] + have hpos := lt_of_le_of_ne (hp a) (Ne.symm hz) + have hle : p a ≤ ∑ b, p b := Finset.single_le_sum (fun b _ => hp b) (Finset.mem_univ a) + have hh := mul_le_mul_of_nonneg_left (Real.log_le_log hpos hle) (hp a) + unfold Real.negMulLog + linarith + have hh := Finset.sum_le_sum (s := Finset.univ) (fun a _ => ht a) + simpa only [← Finset.sum_mul, Finset.sum_neg_distrib, Real.negMulLog] using hh + +structure FinLaw (α : Type uAlpha) [Fintype α] where + mass : α → ℝ + nonneg : ∀ a, 0 ≤ mass a + sum_one : ∑ a, mass a = 1 + +namespace FinLaw +variable {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} {Ω : Type uOmega} [Fintype α] [Fintype β] [Fintype γ] [Fintype Ω] + +instance : CoeFun (FinLaw α) (fun _ => α → ℝ) := ⟨mass⟩ + +@[ext] theorem ext {p q : FinLaw α} (h : ∀ a, p a = q a) : p = q := by + cases p; cases q; congr; exact funext h + +theorem le_one (p : FinLaw α) (a : α) : p a ≤ 1 := by + rw [← p.sum_one] + exact Finset.single_le_sum (fun x _ => p.nonneg x) (Finset.mem_univ a) + +theorem nonempty (p : FinLaw α) : Nonempty α := by + by_contra h + have : IsEmpty α := not_nonempty_iff.mp h + simpa using p.sum_one + +noncomputable def entropy (p : FinLaw α) : ℝ := entropySum p + +theorem entropy_nonneg (p : FinLaw α) : 0 ≤ p.entropy := + Finset.sum_nonneg (fun a _ => Real.negMulLog_nonneg (p.nonneg a) (p.le_one a)) + +theorem entropy_le_log_card (p : FinLaw α) : p.entropy ≤ Real.log (Fintype.card α) := by + have := p.nonempty + have hn : 0 < (Fintype.card α : ℝ) := by exact_mod_cast Fintype.card_pos + have h := gibbs_sum (fun a => p a) (fun _ => (Fintype.card α : ℝ)⁻¹) p.nonneg + (fun _ => by positivity) (fun _ h => False.elim ((inv_pos.mpr hn).ne' h)) (by simp [p.sum_one, hn.ne']) + have heq : (∑ a, p a * (Real.log (p a) - Real.log (Fintype.card α : ℝ)⁻¹)) = + -p.entropy + Real.log (Fintype.card α) := by + simp only [Real.log_inv, sub_neg_eq_add, mul_add, Finset.sum_add_distrib, + ← Finset.sum_mul, p.sum_one, one_mul, entropy, entropySum, Real.negMulLog] + rw [← Finset.sum_neg_distrib] + congr 1 + apply Finset.sum_congr rfl + intro a _ + ring + rw [heq] at h + linarith + +noncomputable def map (p : FinLaw α) (f : α → β) : FinLaw β := by + classical + exact { + mass := fun b => ∑ a, if f a = b then p a else 0 + nonneg := fun b => Finset.sum_nonneg (fun a _ => by split_ifs; exact p.nonneg a; exact le_rfl) + sum_one := by rw [Finset.sum_comm]; simpa using p.sum_one } + +@[simp] theorem map_mass (p : FinLaw α) (f : α → β) (b : β) : + p.map f b = ∑ a, if f a = b then p a else 0 := by + classical + rfl + +@[simp] theorem map_id (p : FinLaw α) : p.map id = p := by + classical + ext a + simp + +@[simp] theorem map_comp (p : FinLaw α) (f : α → β) (g : β → γ) : + (p.map f).map g = p.map (g ∘ f) := by + classical + ext c + simp only [map_mass] + have he (b : β) : (if g b = c then ∑ a, if f a = b then p a else 0 else 0) = + ∑ a, if f a = b ∧ g b = c then p a else 0 := by + by_cases h : g b = c <;> simp [h] + simp_rw [he] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + simp [ite_and] + +noncomputable def H (p : FinLaw Ω) (X : Ω → α) : ℝ := (p.map X).entropy + +noncomputable def condH (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : ℝ := + p.H (fun ω => (X ω,Y ω)) - p.H Y + +theorem H_eq_sum (p : FinLaw Ω) (X : Ω → α) : + p.H X = -∑ ω, p ω * Real.log (p.map X (X ω)) := by + classical + unfold H entropy entropySum + simp only [Real.negMulLog, neg_mul, Finset.sum_neg_distrib] + congr 1 + calc + _ = ∑ a, ∑ ω, (if X ω = a then p ω else 0) * Real.log (p.map X a) := by + apply Finset.sum_congr rfl + intro a _ + rw [map_mass, Finset.sum_mul] + _ = _ := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + simp [ite_mul] + +theorem H_eq_of_fibers (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) + (hf : ∀ ω ω', X ω = X ω' ↔ Y ω = Y ω') : p.H X = p.H Y := by + rw [H_eq_sum,H_eq_sum] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + have hh : p.map X (X ω) = p.map Y (Y ω) := by + simp only [map_mass] + apply Finset.sum_congr rfl + intro ω' _ + rw [hf] + rw [hh] + +theorem H_comp_injective (p : FinLaw Ω) (X : Ω → α) (f : α → β) + (hf : Function.Injective f) : p.H (f ∘ X) = p.H X := + p.H_eq_of_fibers _ _ (fun _ _ => hf.eq_iff) + +theorem H_pair_comm (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.H (fun ω => (X ω,Y ω)) = p.H (fun ω => (Y ω,X ω)) := by + apply p.H_eq_of_fibers + simp only [Prod.mk.injEq, and_comm, implies_true] + +theorem H_pair_assoc (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.H (fun ω => (X ω,(Y ω,Z ω))) = p.H (fun ω => ((X ω,Y ω),Z ω)) := by + apply p.H_eq_of_fibers + simp only [Prod.mk.injEq, and_assoc, implies_true] + +theorem H_pair_function (p : FinLaw Ω) (X : Ω → α) (f : α → β) : + p.H (fun ω => (X ω,f (X ω))) = p.H X := by + apply p.H_eq_of_fibers + intro ω ω' + simp only [Prod.mk.injEq] + exact ⟨And.left,fun h => ⟨h,congrArg f h⟩⟩ + +@[simp] theorem H_map (p : FinLaw Ω) (X : Ω → α) (f : α → β) : + (p.map X).H f = p.H (f ∘ X) := by simp [H] + +@[simp] theorem map_fst_mass (p : FinLaw (α × β)) (a : α) : + p.map Prod.fst a = ∑ b, p (a,b) := by + rw [map_mass,Fintype.sum_prod_type,Finset.sum_comm] + simp + +@[simp] theorem map_snd_mass (p : FinLaw (α × β)) (b : β) : + p.map Prod.snd b = ∑ a, p (a,b) := by + simp [map_mass,Fintype.sum_prod_type] + +theorem entropy_ge_snd (p : FinLaw (α × β)) : (p.map Prod.snd).entropy ≤ p.entropy := by + have h := Finset.sum_le_sum (s := Finset.univ) + (fun b _ => negMulLog_sum_le (fun a => p (a,b)) (fun _ => p.nonneg _)) + rw [Finset.sum_comm] at h + simpa only [entropy,entropySum,map_snd_mass,Fintype.sum_prod_type] using h + +theorem entropy_subadd (p : FinLaw (α × β)) : + p.entropy ≤ (p.map Prod.fst).entropy + (p.map Prod.snd).entropy := by + have h := entropySum_subadd (fun a b => p (a,b)) (fun _ _ => p.nonneg _) + have hs : (∑ a, ∑ b, p (a,b)) = 1 := by simpa only [Fintype.sum_prod_type] using p.sum_one + rw [hs,Real.negMulLog_one,add_zero] at h + simpa only [entropy,entropySum,map_fst_mass,map_snd_mass,Fintype.sum_prod_type] using h + +theorem H_pair_ge_snd (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.H Y ≤ p.H (fun ω => (X ω,Y ω)) := by + have h := (p.map (fun ω => (X ω,Y ω))).entropy_ge_snd + simpa only [map_comp,Function.comp_def,H] using h + +theorem H_pair_subadd (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.H (fun ω => (X ω,Y ω)) ≤ p.H X + p.H Y := by + have h := (p.map (fun ω => (X ω,Y ω))).entropy_subadd + simpa only [map_comp,Function.comp_def,H] using h + +theorem condH_nonneg (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : 0 ≤ p.condH X Y := + sub_nonneg.mpr (p.H_pair_ge_snd X Y) + +theorem condH_le_H (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : p.condH X Y ≤ p.H X := by + have h := p.H_pair_subadd X Y + unfold condH + linarith + +theorem H_le_condH_add (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.H X ≤ p.condH X Y + p.H Y := by + have h := p.H_pair_ge_snd Y X + rw [p.H_pair_comm Y X] at h + simpa only [condH,sub_add_cancel] using h + +theorem entropy_strong_subadd (p : FinLaw (α × (β × γ))) : + p.entropy + (p.map (fun x => x.2.1)).entropy ≤ + (p.map (fun x => (x.1,x.2.1))).entropy + (p.map Prod.snd).entropy := by + have h := Finset.sum_le_sum (s := Finset.univ) (fun b _ => + entropySum_subadd (fun a c => p (a,(b,c))) (fun _ _ => p.nonneg _)) + have hmid (b : β) : p.map (fun x => x.2.1) b = ∑ a, ∑ c, p (a,(b,c)) := by + simp only [map_mass,Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_comm] + simp + have hleft (a : α) (b : β) : p.map (fun x => (x.1,x.2.1)) (a,b) = ∑ c, p (a,(b,c)) := by + simp [map_mass,Fintype.sum_prod_type,Prod.mk.injEq,ite_and] + rw [Finset.sum_comm] + simp + have hfull : (∑ b, ∑ a, ∑ c, Real.negMulLog (p (a,(b,c)))) = p.entropy := by + rw [Finset.sum_comm] + simp only [entropy,entropySum,Fintype.sum_prod_type] + have hxy : (∑ b, ∑ a, Real.negMulLog (∑ c, p (a,(b,c)))) = + (p.map (fun x => (x.1,x.2.1))).entropy := by + rw [Finset.sum_comm] + simp only [entropy,entropySum,Fintype.sum_prod_type,hleft] + simp only [Finset.sum_add_distrib] at h + rw [hfull,hxy] at h + simpa only [entropy,entropySum,Fintype.sum_prod_type,hmid,map_snd_mass] using h + +theorem H_strong_subadd (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.H (fun ω => (X ω,(Y ω,Z ω))) + p.H Y ≤ + p.H (fun ω => (X ω,Y ω)) + p.H (fun ω => (Y ω,Z ω)) := by + have h := (p.map (fun ω => (X ω,(Y ω,Z ω)))).entropy_strong_subadd + simpa only [map_comp,Function.comp_def,H] using h + +theorem condH_mono (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.condH X (fun ω => (Y ω,Z ω)) ≤ p.condH X Y := by + have h := p.H_strong_subadd X Y Z + unfold condH + linarith + +noncomputable def mutualInfo (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : ℝ := + p.H X - p.condH X Y + +noncomputable def condMutualInfo {δ : Type uDelta} [Fintype δ] (p : FinLaw Ω) + (X : Ω → α) (Y : Ω → β) (Z : Ω → δ) : ℝ := + p.condH X Z - p.condH X (fun ω => (Y ω,Z ω)) + +theorem mutualInfo_nonneg (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + 0 ≤ p.mutualInfo X Y := sub_nonneg.mpr (p.condH_le_H X Y) + +theorem condH_pair_comm (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.condH X (fun ω => (Y ω,Z ω)) = p.condH X (fun ω => (Z ω,Y ω)) := by + unfold condH + congr 1 + · apply p.H_eq_of_fibers + simp only [Prod.mk.injEq,and_comm,implies_true] + · exact p.H_pair_comm Y Z + +theorem condMutualInfo_nonneg (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + 0 ≤ p.condMutualInfo X Y Z := by + unfold condMutualInfo + rw [condH_pair_comm] + exact sub_nonneg.mpr (p.condH_mono X Z Y) + +theorem entropySum_scale (p : α → ℝ) (c : ℝ) : + entropySum (fun a => c*p a) = c*entropySum p + (∑ a, p a)*Real.negMulLog c := by + simp only [entropySum, Real.negMulLog_mul, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.sum_mul] + ring + +theorem entropySum_le_mass_log_card (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) : + entropySum p ≤ (∑ a, p a)*Real.log (Fintype.card α) + Real.negMulLog (∑ a, p a) := by + let m := ∑ a, p a + have hm : 0 ≤ m := Finset.sum_nonneg (fun a _ => hp a) + by_cases hm0 : m = 0 + · have hz : ∀ a, p a = 0 := by + intro a + have hle : p a ≤ m := Finset.single_le_sum (fun b _ => hp b) (Finset.mem_univ a) + exact le_antisymm (by simpa [hm0] using hle) (hp a) + simp [entropySum,hz] + let q : FinLaw α := { + mass := fun a => p a/m + nonneg := fun a => div_nonneg (hp a) hm + sum_one := by rw [← Finset.sum_div]; exact div_self hm0 } + have h := mul_le_mul_of_nonneg_left q.entropy_le_log_card hm + have he : entropySum p = m*q.entropy + Real.negMulLog m := by + have hs : (fun a => m*q a) = p := by ext a; dsimp [q]; field_simp + rw [← hs, entropySum_scale, q.sum_one, one_mul] + rfl + rw [he] + exact add_le_add_left h _ + +theorem entropySum_le_mass_log_support (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) + (S : Finset α) (hs : ∀ a, a ∉ S → p a = 0) : + entropySum p ≤ (∑ a, p a)*Real.log S.card + Real.negMulLog (∑ a, p a) := by + classical + have he : entropySum p = entropySum (fun a : S => p a) := by + unfold entropySum + rw [← Finset.sum_subtype S (fun _ => Iff.rfl) (fun a => Real.negMulLog (p a))] + exact (Finset.sum_subset (Finset.subset_univ S) (fun a _ ha => by rw [hs a ha,Real.negMulLog_zero])).symm + have hm : (∑ a, p a) = ∑ a : S, p a := by + rw [← Finset.sum_subtype S (fun _ => Iff.rfl) p] + exact (Finset.sum_subset (Finset.subset_univ S) (fun a _ ha => hs a ha)).symm + rw [he,hm] + simpa using entropySum_le_mass_log_card (fun a : S => p a) (fun a => hp a) + +theorem condH_le_support (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) + (L : β → Finset α) (hs : ∀ ω, p ω ≠ 0 → X ω ∈ L (Y ω)) : + p.condH X Y ≤ ∑ b, p.map Y b * Real.log (L b).card := by + classical + let q := p.map (fun ω => (X ω,Y ω)) + have hzero : ∀ b a, a ∉ L b → q (a,b) = 0 := by + intro b a ha + change p.map (fun ω => (X ω,Y ω)) (a,b) = 0 + rw [map_mass] + apply Finset.sum_eq_zero + intro ω _ + split_ifs with he + · have he' := Prod.mk.inj he + by_contra hn + have hmem := hs ω hn + rw [he'.1,he'.2] at hmem + exact ha hmem + · rfl + have h := Finset.sum_le_sum (s := Finset.univ) (fun b _ => + entropySum_le_mass_log_support (fun a => q (a,b)) (fun a => q.nonneg _) (L b) (hzero b)) + have hm (b : β) : (∑ a, q (a,b)) = p.map Y b := by + rw [← map_snd_mass,map_comp] + rfl + simp_rw [hm] at h + rw [Finset.sum_add_distrib] at h + have hfull : (∑ b, entropySum (fun a => q (a,b))) = p.H (fun ω => (X ω,Y ω)) := by + unfold entropySum + rw [Finset.sum_comm] + simp only [H,entropy,entropySum,Fintype.sum_prod_type,q] + rw [hfull] at h + change p.condH X Y ≤ _ + unfold condH + have hh : (∑ b, Real.negMulLog (p.map Y b)) = p.H Y := rfl + rw [hh] at h + linarith + +noncomputable def mix (p : FinLaw Ω) (q : Ω → FinLaw α) : FinLaw α := { + mass := fun a => ∑ ω, p ω * q ω a + nonneg := fun a => Finset.sum_nonneg (fun ω _ => mul_nonneg (p.nonneg ω) ((q ω).nonneg a)) + sum_one := by rw [Finset.sum_comm]; simp_rw [← Finset.mul_sum, sum_one, mul_one]; exact p.sum_one } + +@[simp] theorem mix_mass (p : FinLaw Ω) (q : Ω → FinLaw α) (a : α) : + p.mix q a = ∑ ω, p ω * q ω a := rfl + +theorem entropy_mix_ge (p : FinLaw Ω) (q : Ω → FinLaw α) : + (∑ ω, p ω * (q ω).entropy) ≤ (p.mix q).entropy := by + have h := Finset.sum_le_sum (s := Finset.univ) (fun a _ => + Real.concaveOn_negMulLog.le_map_sum (fun ω _ => p.nonneg ω) p.sum_one + (fun ω _ => (q ω).nonneg a)) + change (∑ ω, p ω * ∑ a, Real.negMulLog (q ω a)) ≤ _ + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + simpa only [entropy,entropySum,mix_mass,smul_eq_mul] using h + +@[simp] theorem H_const (p : FinLaw Ω) (a : α) : p.H (fun _ => a) = 0 := by + rw [H_eq_sum] + simp [p.sum_one] + +theorem H_bool (p : FinLaw Ω) (E : Ω → Bool) : + p.H E = Real.binEntropy (p.map E true) := by + have hs := (p.map E).sum_one + simp only [Fintype.sum_bool] at hs + have hf : p.map E false = 1 - p.map E true := by linarith + simp only [H,entropy,entropySum,Fintype.sum_bool,hf, + Real.binEntropy_eq_negMulLog_add_negMulLog_one_sub] + +theorem condH_le_reveal (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → γ) : + p.condH X Y ≤ p.H Z + p.condH X (fun ω => (Y ω,Z ω)) := by + have h1 := p.H_pair_ge_snd Z (fun ω => (X ω,Y ω)) + have he : p.H (fun ω => (Z ω,(X ω,Y ω))) = p.H (fun ω => (X ω,(Y ω,Z ω))) := by + apply p.H_eq_of_fibers + simp only [Prod.mk.injEq] + tauto + rw [he] at h1 + have h2 := p.H_pair_subadd Y Z + unfold condH + linarith + +omit [Fintype α] in + +theorem log_card_le_real (S : Finset α) {b : ℝ} (hb : 1 ≤ b) (hs : (S.card : ℝ) ≤ b) : + Real.log S.card ≤ Real.log b := by + by_cases hz : S.card = 0 + · simpa [hz] using Real.log_nonneg hb + · exact Real.log_le_log (by exact_mod_cast Nat.pos_of_ne_zero hz) hs + +theorem short_list (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) + (L : β → Finset α) (E : Ω → Bool) {b : ℝ} (hb : 1 ≤ b) + (hs : ∀ ω, p ω ≠ 0 → E ω = true → X ω ∈ L (Y ω) ∧ ((L (Y ω)).card : ℝ) ≤ b) : + p.condH X Y ≤ Real.binEntropy (p.map E true) + + p.map E true * Real.log b + (1-p.map E true)*Real.log (Fintype.card α) := by + classical + let L' : β × Bool → Finset α := fun ye => + if ye.2 = true then if ((L ye.1).card : ℝ) ≤ b then L ye.1 else ∅ else Finset.univ + have hs' : ∀ ω, p ω ≠ 0 → X ω ∈ L' (Y ω,E ω) := by + intro ω hn + by_cases he : E ω = true + · have hh := hs ω hn he + simpa [L',he,hh.2] using hh.1 + · simp [L',he] + have hc := p.condH_le_support X (fun ω => (Y ω,E ω)) L' hs' + have hcard (y : β) (e : Bool) : + Real.log (L' (y,e)).card ≤ if e = true then Real.log b else Real.log (Fintype.card α) := by + cases e + · simp [L'] + · simp only [L',ite_true] + split_ifs with hh + · exact log_card_le_real _ hb hh + · simpa using Real.log_nonneg hb + have hh := Finset.sum_le_sum (s := Finset.univ) (fun ye _ => + mul_le_mul_of_nonneg_left (hcard ye.1 ye.2) ((p.map (fun ω => (Y ω,E ω))).nonneg ye)) + have hm (e : Bool) : (∑ y, p.map (fun ω => (Y ω,E ω)) (y,e)) = p.map E e := by + rw [← map_snd_mass,map_comp] + rfl + have hsum : (∑ ye : β × Bool, p.map (fun ω => (Y ω,E ω)) ye * + (if ye.2 = true then Real.log b else Real.log (Fintype.card α))) = + p.map E true*Real.log b + (1-p.map E true)*Real.log (Fintype.card α) := by + rw [Fintype.sum_prod_type,Finset.sum_comm,Fintype.sum_bool] + simp only [Bool.false_eq_true,ite_false,ite_true,← Finset.sum_mul,hm] + have htotal := (p.map E).sum_one + simp only [Fintype.sum_bool] at htotal + congr 2 + linarith + rw [hsum] at hh + have h := p.condH_le_reveal X Y E + rw [H_bool] at h + linarith + +theorem short_list_deficit (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) + (L : β → Finset α) (E : Ω → Bool) {b : ℝ} (hb : 1 ≤ b) + (hs : ∀ ω, p ω ≠ 0 → E ω = true → X ω ∈ L (Y ω) ∧ ((L (Y ω)).card : ℝ) ≤ b) : + p.map E true * (Real.log (Fintype.card α) - Real.log b) - Real.binEntropy (p.map E true) + ≤ Real.log (Fintype.card α) - p.condH X Y := by + have h := p.short_list X Y L E hb hs + nlinarith + +theorem low_mass_deficit (p : FinLaw α) (S : Finset α) + (hs : ∀ a ∈ S, p a ≤ 3 / (8 * (Fintype.card α : ℝ))) : + (S.card : ℝ) / (8 * (Fintype.card α : ℝ)) ≤ Real.log (Fintype.card α) - p.entropy := by + classical + have := p.nonempty + have hn : 0 < (Fintype.card α : ℝ) := by exact_mod_cast Fintype.card_pos + let u : ℝ := (Fintype.card α : ℝ)⁻¹ + have hu : 0 < u := inv_pos.mpr hn + let d := fun a => p a * (Real.log (p a) - Real.log u) - p a + u + have hd : ∀ a, 0 ≤ d a := by + intro a + have h := gibbs_point (p.nonneg a) hu.le (fun hz => False.elim (hu.ne' hz)) + dsimp [d] + linarith + have hlog2 : Real.log 2 ≤ 1 := by have h := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ) < 2); norm_num at h ⊢; exact h + have hlow : ∀ a ∈ S, u/8 ≤ d a := by + intro a ha + have h := gibbs_point (p.nonneg a) (show 0 ≤ u/2 by positivity) + (fun hz => False.elim ((div_pos hu (by norm_num : (0:ℝ)<2)).ne' hz)) + rw [Real.log_div hu.ne' (by norm_num : (2:ℝ) ≠ 0)] at h + have hlog := mul_le_mul_of_nonneg_left hlog2 (p.nonneg a) + have hpa : p a ≤ 3*u/8 := by simpa only [u,div_eq_mul_inv,mul_inv_rev,mul_assoc] using hs a ha + dsimp [d] + nlinarith + have hsum : (∑ a, d a) = Real.log (Fintype.card α) - p.entropy := by + simp only [d, mul_sub, Finset.sum_add_distrib, Finset.sum_sub_distrib, + ← Finset.sum_mul,p.sum_one,one_mul,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,u,Real.log_inv] + rw [mul_inv_cancel₀ hn.ne'] + simp only [entropy,entropySum,Real.negMulLog,neg_mul,Finset.sum_neg_distrib] + ring + have hh := Finset.sum_le_sum (s := S) hlow + have hsub := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ S) (fun a _ _ => hd a) + have hfinal := hh.trans hsub + rw [hsum] at hfinal + simpa only [Finset.sum_const,nsmul_eq_mul,u,div_eq_mul_inv,mul_inv_rev,mul_assoc] using hfinal + +end FinLaw + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/FreshEntropy.lean b/lean/OAI/NumberTheory/GaussianMoat/FreshEntropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..28dc8a7ff5140ba41fe01d8a54400ebd05af186d --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/FreshEntropy.lean @@ -0,0 +1,350 @@ +import OAI.NumberTheory.GaussianMoat.DenseBins + +namespace OAI + +universe uKappa uBeta uIota uOmega uXi uAlpha + +namespace GaussianMoat +open scoped BigOperators Classical + +theorem expect_restrict {κ : Type uKappa} {β : Type uBeta} [Fintype κ] [Fintype β] [Nonempty β] + (s : Finset κ) (F : (s → β) → ℝ) : + (𝔼 σ : κ → β, F (fun p => σ p)) = 𝔼 τ : s → β, F τ := by + classical + let e := Equiv.piEquivPiSubtypeProd (fun x => x ∈ s) (fun _ => β) + calc + _ = 𝔼 pair : (s → β) × ({x : κ // x ∉ s} → β), F pair.1 := by + exact Fintype.expect_equiv e _ _ (fun _ => rfl) + _ = _ := by + rw [← Finset.univ_product_univ,Finset.expect_product] + simp only [Fintype.expect_const] + +theorem expect_precomp_injective {ι : Type uIota} {κ : Type uKappa} {β : Type uBeta} [Fintype ι] [Fintype κ] + [Fintype β] [Nonempty β] (e : ι → κ) (he : Function.Injective e) + (F : (ι → β) → ℝ) : + (𝔼 σ : κ → β, F (σ ∘ e)) = 𝔼 τ : ι → β, F τ := by + classical + let s := Finset.univ.image e + let ee : ι ≃ s := Equiv.ofBijective (fun i => ⟨e i, Finset.mem_image.mpr + ⟨i,Finset.mem_univ _,rfl⟩⟩) ⟨fun i j h => he (congrArg Subtype.val h),by + rintro ⟨y,hy⟩ + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp hy + exact ⟨i,Subtype.ext hi⟩⟩ + calc + _ = 𝔼 τ : s → β, F (fun i => τ (ee i)) := expect_restrict s _ + _ = _ := by + exact Fintype.expect_equiv (Equiv.arrowCongr ee.symm (Equiv.refl β)) _ _ (fun _ => rfl) + +lemma signMeasure_real_eq_expect {ι : Type uIota} [Fintype ι] (S : Set (ι → Bool)) : + (signMeasure ι).real S = 𝔼 σ : ι → Bool, if σ ∈ S then (1 : ℝ) else 0 := by + rw [signMeasure_real_set] + simp [Finset.expect,NNRat.smul_def,div_eq_inv_mul] + +lemma expect_sign_restriction {ι : Type uIota} {κ : Type uKappa} [Fintype ι] [Fintype κ] + (e : ι → κ) (he : Function.Injective e) (S : Set (ι → Bool)) : + (𝔼 σ : κ → Bool, if σ ∘ e ∈ S then (1 : ℝ) else 0) = + (signMeasure ι).real S := by + exact (expect_precomp_injective e he (fun τ => if τ ∈ S then (1 : ℝ) else 0)).trans + (signMeasure_real_eq_expect S).symm + +lemma uniform_entropy_event_bound {Ω : Type uOmega} {Ξ : Type uXi} {α : Type uAlpha} [Fintype Ω] [Nonempty Ω] + [Fintype Ξ] [Nonempty Ξ] (X : Ξ → Ω → α) (bad : Ξ → Prop) + (hg : ∀ σ, ¬bad σ → Function.Injective (X σ)) : + (1-(𝔼 σ, if bad σ then (1 : ℝ) else 0))*Real.log (Fintype.card Ω) ≤ + 𝔼 σ, (FinLaw.uniform Ω).Hf (X σ) := by + have hp (σ : Ξ) : (1-(if bad σ then (1 : ℝ) else 0))*Real.log (Fintype.card Ω) ≤ + (FinLaw.uniform Ω).Hf (X σ) := by + by_cases hb : bad σ + · simpa [hb] using (FinLaw.uniform Ω).Hf_nonneg (X σ) + · simp only [hb,ite_false,sub_zero,one_mul] + rw [FinLaw.uniform_Hf_injective _ (hg σ hb)] + have h := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => hp σ) + simpa only [← Finset.expect_mul,Finset.expect_sub_distrib,Fintype.expect_const] using h + +abbrev SplitSieve.restrict (s : SplitSieve) (Q : Finset ℕ) (hQ : Q ⊆ s.primes) : SplitSieve where + primes := Q + factor := s.factor + prime_mem := fun p hp => s.prime_mem p (hQ hp) + mod_four := fun p hp => s.mod_four p (hQ hp) + factor_irreducible := fun p hp => s.factor_irreducible p (hQ hp) + factor_norm := fun p hp => s.factor_norm p (hQ hp) + +noncomputable def SplitSieve.enumeration (s : SplitSieve) : Fin s.primes.card ≃ s.primes := + s.primes.equivFin.symm + +noncomputable def prefixIndices (k r : ℕ) : Finset (Fin k) := + Finset.univ.filter (fun i => i.val < r) + +lemma mem_prefixIndices {k r : ℕ} (i : Fin k) : i ∈ prefixIndices k r ↔ i.val < r := by + simp [prefixIndices] + +lemma prefixIndices_card {k r : ℕ} (hr : r ≤ k) : (prefixIndices k r).card = r := by + have he : prefixIndices k r = (Finset.univ : Finset (Fin r)).image + (fun i => (⟨i.val,by omega⟩ : Fin k)) := by + ext i + simp only [mem_prefixIndices,Finset.mem_image,Finset.mem_univ,true_and] + exact ⟨fun hi => ⟨⟨i.val,hi⟩,rfl⟩,fun ⟨j,hj⟩ => by cases hj; exact j.isLt⟩ + have hinj : Function.Injective (fun i : Fin r => (⟨i.val,by omega⟩ : Fin k)) := + fun i j h => Fin.ext (congrArg (fun j : Fin k => j.val) h) + rw [he,Finset.card_image_of_injective _ hinj] + exact Finset.card_fin r + +noncomputable def SplitSieve.prefixSet (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) (r : ℕ) : Finset ℕ := + (prefixIndices s.primes.card r).image (fun i => (s.enumeration (π i)).val) + +lemma SplitSieve.prefixSet_subset (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) (r : ℕ) : s.prefixSet π r ⊆ s.primes := by + intro p hp + obtain ⟨i,_,rfl⟩ := Finset.mem_image.mp hp + exact (s.enumeration (π i)).property + +lemma SplitSieve.prefixSet_card (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) {r : ℕ} (hr : r ≤ s.primes.card) : + (s.prefixSet π r).card = r := by + have hinj : Function.Injective (fun i => (s.enumeration (π i)).val) := + Subtype.val_injective.comp (s.enumeration.injective.comp π.injective) + rw [SplitSieve.prefixSet,Finset.card_image_of_injective _ hinj] + exact prefixIndices_card hr + +noncomputable abbrev SplitSieve.prefixSieve (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) (r : ℕ) : SplitSieve := + s.restrict (s.prefixSet π r) (s.prefixSet_subset π r) + +noncomputable def SplitSieve.residueVector (s : SplitSieve) + (σ : Fin s.primes.card → Bool) (z : GaussianInt) (i : Fin s.primes.card) : ℕ := + residueCode (signedFactor (s.factor (s.enumeration i)) (σ i)) z + +noncomputable def SplitSieve.prefixIndex (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) (r : ℕ) (p : (s.prefixSet π r)) : Fin s.primes.card := + s.enumeration.symm ⟨p.val,s.prefixSet_subset π r p.property⟩ + +lemma SplitSieve.prefixIndex_injective (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) (r : ℕ) : Function.Injective (s.prefixIndex π r) := by + intro p q hpq + apply Subtype.ext + exact congrArg (fun y : s.primes => (y : ℕ)) (s.enumeration.symm.injective hpq) + +lemma SplitSieve.prefix_injective_of_no_bad (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) (r : ℕ) + (σ : Fin s.primes.card → Bool) (Δ : Finset GaussianInt) (Q : Set GaussianInt) + (hΔ : ∀ x ∈ Δ, ∀ y ∈ Δ, x-y ∈ Q) + (hb : ¬(s.prefixSieve π r).badSign Q (σ ∘ s.prefixIndex π r)) : + Function.Injective (fun x : Δ => FinLaw.prefixVar (fun x : Δ => s.residueVector σ x) π r x) := by + intro x y hxy + apply Subtype.ext + by_contra hne + apply hb + refine ⟨x-y,hΔ x x.property y y.property,sub_ne_zero.mpr hne,?_⟩ + apply (s.prefixSieve π r).prod_factors_dvd _ (fun _ h => h) + intro p hp + obtain ⟨i,hi,hp'⟩ := Finset.mem_image.mp hp + have hres := congrFun hxy i + have hiv := (mem_prefixIndices i).mp hi + simp only [FinLaw.prefixVar,hiv,ite_eq_left,Option.some.injEq] at hres + have hidx : s.prefixIndex π r ⟨p,hp⟩ = π i := by + apply s.enumeration.injective + apply Subtype.ext + simpa only [SplitSieve.prefixIndex,Equiv.apply_symm_apply] using hp'.symm + rw [SplitSieve.extendSigns_mem _ _ p hp] + change signedFactor (s.factor p) (σ (s.prefixIndex π r ⟨p,hp⟩)) ∣ _ + rw [hidx] + simpa only [SplitSieve.residueVector,hp'] using + (residueCode_eq _ _ _).mp hres + +theorem SplitSieve.prefix_entropy_rectangle (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) {r : ℕ} (hr : r ≤ s.primes.card) + (Δ : Finset GaussianInt) (hΔne : Δ.Nonempty) + {T R W d : ℝ} {e : ℂ} (he : ‖e‖=1) (hT : 5 ≤ T) + (hpT : ∀ p ∈ s.primes, T ≤ (p : ℝ) ∧ (p : ℝ) ≤ 2*T) + (hW : 1 ≤ W) (hWR : W ≤ R) (hd : 0 < d) (hd1 : d < 1/4) + (harea : R*W ≤ ((s.prefixSieve π r).period : ℝ)^(1-d)) + (hlarge : 1000 ≤ d^3*r) + (hΔ : ∀ x ∈ Δ, ∀ y ∈ Δ, x-y ∈ orientedRectangle e R W) : + let := hΔne.to_subtype + (1-Real.exp (-(d^3*r/5120)))*Real.log Δ.card ≤ + 𝔼 σ : Fin s.primes.card → Bool, + (FinLaw.uniform Δ).Hf (FinLaw.prefixVar (fun x : Δ => s.residueVector σ x) π r) := by + let := hΔne.to_subtype + let t := s.prefixSieve π r + let Q := orientedRectangle e R W + have hc : t.primes.card=r := s.prefixSet_card π hr + have hprob : (𝔼 σ : Fin s.primes.card → Bool, + if t.badSign Q (σ ∘ s.prefixIndex π r) then (1 : ℝ) else 0) ≤ + Real.exp (-(d^3*r/5120)) := by + calc + _ = (signMeasure t.primes).real {τ | t.badSign Q τ} := by + convert expect_sign_restriction (s.prefixIndex π r) (s.prefixIndex_injective π r) + {τ | t.badSign Q τ} using 1 + congr 1 + ext σ; simp + _ ≤ _ := by + have ht := t.signed_rectangle he hT (fun p hp => hpT p (s.prefixSet_subset π r hp)) + hW hWR hd hd1 harea (by rwa [hc]) + simpa only [hc] using ht + have hg := uniform_entropy_event_bound + (fun σ => FinLaw.prefixVar (fun x : Δ => s.residueVector σ x) π r) + (fun σ => t.badSign Q (σ ∘ s.prefixIndex π r)) + (fun σ hb => s.prefix_injective_of_no_bad π r σ Δ Q hΔ hb) + simp only [Fintype.card_coe] at hg + have hl : 0 ≤ Real.log (Δ.card : ℝ) := Real.log_nonneg (by exact_mod_cast hΔne.card_pos) + exact (mul_le_mul_of_nonneg_right (sub_le_sub_left hprob 1) hl).trans hg + +noncomputable def SplitSieve.meanLog (s : SplitSieve) : ℝ := + 𝔼 i : Fin s.primes.card, Real.log (s.enumeration i : ℕ) + +lemma SplitSieve.prefix_log_period (s : SplitSieve) + (π : Equiv.Perm (Fin s.primes.card)) (r : ℕ) : + Real.log ((s.prefixSieve π r).period : ℝ) = + ∑ i ∈ prefixIndices s.primes.card r, Real.log (s.enumeration (π i) : ℕ) := by + rw [SplitSieve.log_period] + rw [Finset.sum_coe_sort (s.prefixSieve π r).primes (fun p : ℕ => Real.log (p : ℝ))] + change (∑ p ∈ s.prefixSet π r, Real.log (p : ℝ)) = _ + unfold SplitSieve.prefixSet + exact Finset.sum_image (Subtype.val_injective.comp + (s.enumeration.injective.comp π.injective)).injOn + +lemma SplitSieve.prefix_product_tail (s : SplitSieve) (hk : 0 < s.primes.card) + {r : ℕ} (hr : r ≤ s.primes.card) {T δ : ℝ} (hT : 0 < T) (hδ : 0 < δ) + (hpT : ∀ p ∈ s.primes, T ≤ (p : ℝ) ∧ (p : ℝ) ≤ 2*T) : + (𝔼 π : Equiv.Perm (Fin s.primes.card), + if Real.log ((s.prefixSieve π r).period : ℝ) < r*s.meanLog-δ then (1 : ℝ) else 0) ≤ + r*(Real.log 2)^2/δ^2 := by + let : Nonempty (Fin s.primes.card) := ⟨⟨0,hk⟩⟩ + have hb (i : Fin s.primes.card) : Real.log T ≤ Real.log (s.enumeration i : ℕ) ∧ + Real.log (s.enumeration i : ℕ) ≤ Real.log T+Real.log 2 := by + have hh := hpT (s.enumeration i) (s.enumeration i).property + constructor + · exact Real.log_le_log hT hh.1 + · have h := Real.log_le_log (hT.trans_le hh.1) hh.2 + rwa [Real.log_mul (by norm_num : (2 : ℝ)≠0) hT.ne',add_comm] at h + have h := perm_sample_interval_tail (fun i => Real.log (s.enumeration i : ℕ)) + (prefixIndices s.primes.card r) hδ hb + convert h using 1 <;> + simp only [prefixIndices_card hr,SplitSieve.meanLog,← s.prefix_log_period] + congr 1 + +theorem SplitSieve.signed_prefix_entropy (s : SplitSieve) + {r : ℕ} (hr : r ≤ s.primes.card) (Δ : Finset GaussianInt) (hΔne : Δ.Nonempty) + {T R W d δ : ℝ} {e : ℂ} (he : ‖e‖=1) (hT : 5 ≤ T) + (hpT : ∀ p ∈ s.primes, T ≤ (p : ℝ) ∧ (p : ℝ) ≤ 2*T) + (hW : 1 ≤ W) (hWR : W ≤ R) (hd : 0 < d) (hd1 : d < 1/4) + (hδ : 0 < δ) (hgap : Real.log (R*W) ≤ (1-d)*(r*s.meanLog-δ)) + (hlarge : 1000 ≤ d^3*r) + (hΔ : ∀ x ∈ Δ, ∀ y ∈ Δ, x-y ∈ orientedRectangle e R W) : + let := hΔne.to_subtype + (1-r*(Real.log 2)^2/δ^2-Real.exp (-(d^3*r/5120)))*Real.log Δ.card ≤ + (FinLaw.uniform Δ).signedEntropy (fun σ x => s.residueVector σ x) r := by + let := hΔne.to_subtype + have hk : 0 < s.primes.card := by + by_contra hn + have hz : r=0 := by omega + simp only [hz,Nat.cast_zero,mul_zero] at hlarge + norm_num at hlarge + have hRW : 0 < R*W := mul_pos (by linarith) (by linarith) + have hlog : 0 ≤ Real.log (Δ.card : ℝ) := Real.log_nonneg (by exact_mod_cast hΔne.card_pos) + let ε := Real.exp (-(d^3*r/5120)) + let bad (π : Equiv.Perm (Fin s.primes.card)) := + Real.log ((s.prefixSieve π r).period : ℝ) < r*s.meanLog-δ + have hp (π : Equiv.Perm (Fin s.primes.card)) : + (1-(if bad π then (1 : ℝ) else 0)-ε)*Real.log Δ.card ≤ + 𝔼 σ : Fin s.primes.card → Bool, + (FinLaw.uniform Δ).Hf (FinLaw.prefixVar (fun x : Δ => s.residueVector σ x) π r) := by + by_cases hb : bad π + · have hn : 0 ≤ (𝔼 σ : Fin s.primes.card → Bool, + (FinLaw.uniform Δ).Hf (FinLaw.prefixVar (fun x : Δ => s.residueVector σ x) π r)) := + Finset.expect_nonneg (fun _ _ => (FinLaw.uniform Δ).Hf_nonneg _) + simp only [hb,ite_eq_left,sub_self,zero_sub] + exact (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (Real.exp_pos _).le) hlog).trans hn + · simp only [hb,ite_false,sub_zero] + apply s.prefix_entropy_rectangle π hr Δ hΔne he hT hpT hW hWR hd hd1 ?_ hlarge hΔ + have hP : 0 < ((s.prefixSieve π r).period : ℝ) := by + exact_mod_cast (s.prefixSieve π r).period_pos + apply (Real.log_le_log_iff hRW (Real.rpow_pos_of_pos hP _)).mp + rw [Real.log_rpow hP] + exact hgap.trans (mul_le_mul_of_nonneg_left (le_of_not_gt hb) (by linarith)) + have hav := Finset.expect_le_expect (s := Finset.univ) (fun π _ => hp π) + simp only [← Finset.expect_mul,Finset.expect_sub_distrib,Fintype.expect_const] at hav + have hb := s.prefix_product_tail hk hr (by linarith : (0 : ℝ) s.residueVector σ (Z ω) i) ≤ Real.log (s.enumeration i : ℕ) := by + let π := signedFactor (s.factor (s.enumeration i)) (σ i) + have hπ : π ≠ 0 := (signedFactor_irreducible + (s.factor_irreducible _ (s.enumeration i).property) _).ne_zero + obtain ⟨hfin,hcard⟩ := residueCode_range_card hπ + have h := P.Hf_le_log_card_set (fun ω => residueCode π (Z ω)) hfin.toFinset + (fun ω => hfin.mem_toFinset.mpr ⟨Z ω,rfl⟩) + rw [← Set.ncard_eq_toFinset_card (Set.range (residueCode π)) hfin,hcard] at h + have hn : π.norm.natAbs=(s.enumeration i : ℕ) := by + dsimp [π] + rw [signedFactor_norm,s.factor_norm _ (s.enumeration i).property,Int.natAbs_natCast] + rw [hn] at h + exact h + +lemma SplitSieve.residue_prefix_entropy_le {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (P : FinLaw Ω) (Z : Ω → GaussianInt) + (σ : Fin s.primes.card → Bool) {b : ℕ} (hb : b ≤ s.primes.card) + {U : ℝ} (hU : ∀ p ∈ s.primes, Real.log (p : ℝ) ≤ U) : + P.orderedEntropy (fun ω => s.residueVector σ (Z ω)) b ≤ b*U := by + have h (π : Equiv.Perm (Fin s.primes.card)) := P.Hf_prefix_le_sum + (fun ω => s.residueVector σ (Z ω)) (fun _ => U) + (fun i => (s.residueVector_entropy_le P Z σ i).trans + (hU _ (s.enumeration i).property)) π hb + have hh := Finset.expect_le_expect (s := Finset.univ) (fun π _ => h π) + simpa only [FinLaw.orderedEntropy,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + Fintype.expect_const] using hh + +theorem SplitSieve.actual_fresh_entropy (s : SplitSieve) + {b r : ℕ} (hbr : b < r) (hr : r ≤ s.primes.card) + (Δ : Finset GaussianInt) (hΔne : Δ.Nonempty) + (X Y : Δ → GaussianInt) (hXY : ∀ ω, X ω-Y ω=ω) + {T R W d δ : ℝ} {e : ℂ} (he : ‖e‖=1) (hT : 5 ≤ T) + (hpT : ∀ p ∈ s.primes, T ≤ (p : ℝ) ∧ (p : ℝ) ≤ 2*T) + (hW : 1 ≤ W) (hWR : W ≤ R) (hd : 0 < d) (hd1 : d < 1/4) + (hδ : 0 < δ) (hgap : Real.log (R*W) ≤ (1-d)*(r*s.meanLog-δ)) + (hlarge : 1000 ≤ d^3*r) + (hΔ : ∀ x ∈ Δ, ∀ y ∈ Δ, x-y ∈ orientedRectangle e R W) : + let := hΔne.to_subtype + (1-r*(Real.log 2)^2/δ^2-Real.exp (-(d^3*r/5120)))*Real.log Δ.card- + 2*b*Real.log (2*T) ≤ + (r-b : ℕ)*(𝔼 σ : Fin s.primes.card → Bool, + 𝔼 π : Equiv.Perm (Fin s.primes.card), + (FinLaw.uniform Δ).cHf (fun ω => s.residueVector σ ω (π ⟨b,by omega⟩)) + (fun ω => (FinLaw.prefixVar (fun x => s.residueVector σ (X x)) π b ω, + FinLaw.prefixVar (fun x => s.residueVector σ (Y x)) π b ω))) := by + let := hΔne.to_subtype + let P := FinLaw.uniform Δ + have hU (p : ℕ) (hp : p ∈ s.primes) : Real.log (p : ℝ) ≤ Real.log (2*T) := + Real.log_le_log (by have := (hpT p hp).1; linarith) (hpT p hp).2 + have hp (σ : Fin s.primes.card → Bool) := P.fresh_entropy_from_prefix + (fun ω => s.residueVector σ (X ω)) (fun ω => s.residueVector σ (Y ω)) + (fun ω => s.residueVector σ ω) hbr hr (by + intro i ω ν hx hy + change residueCode _ (ω : GaussianInt) = residueCode _ (ν : GaussianInt) + rw [← hXY ω,← hXY ν] + exact residueCode_sub hx hy) + have hX σ := s.residue_prefix_entropy_le P X σ (by omega : b ≤ s.primes.card) hU + have hY σ := s.residue_prefix_entropy_le P Y σ (by omega : b ≤ s.primes.card) hU + have hl (σ : Fin s.primes.card → Bool) : + P.orderedEntropy (fun ω => s.residueVector σ ω) r-2*b*Real.log (2*T) ≤ + (r-b : ℕ)*(𝔼 π : Equiv.Perm (Fin s.primes.card), + P.cHf (fun ω => s.residueVector σ ω (π ⟨b,by omega⟩)) + (fun ω => (FinLaw.prefixVar (fun x => s.residueVector σ (X x)) π b ω, + FinLaw.prefixVar (fun x => s.residueVector σ (Y x)) π b ω))) := by + linarith [hp σ,hX σ,hY σ] + have hh := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => hl σ) + simp only [Finset.expect_sub_distrib,Fintype.expect_const,← Finset.mul_expect] at hh + have hg := s.signed_prefix_entropy hr Δ hΔne he hT hpT hW hWR hd hd1 hδ hgap hlarge hΔ + exact (sub_le_sub_right hg _).trans hh + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/GroupCoverage.lean b/lean/OAI/NumberTheory/GaussianMoat/GroupCoverage.lean new file mode 100644 index 0000000000000000000000000000000000000000..44f1c59452279b8fc4d3c0d811363fbd44bfb3e9 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/GroupCoverage.lean @@ -0,0 +1,444 @@ +import OAI.NumberTheory.GaussianMoat.KernelComposition + +namespace OAI + +universe uGroup uOmega uAlpha uIota uBeta uCapitalGamma + +namespace GaussianMoat + +section +open scoped BigOperators Classical +variable {G : Type uGroup} [Fintype G] [AddGroup G] + +noncomputable def overlapCount (K E : Finset G) (x : G) : ℕ := + (E.filter (fun y => x+y ∈ K)).card + +lemma overlapCount_sum (K E : Finset G) : + (∑ x : G, overlapCount K E x) = K.card*E.card := by + simp only [overlapCount,Finset.card_filter] + rw [Finset.sum_comm] + have hh (y : G) : (∑ x : G, if x+y ∈ K then (1:ℕ) else 0) = K.card := by + calc + _ = ∑ x : G, if x ∈ K then (1:ℕ) else 0 := + Equiv.sum_comp (Equiv.addRight y) (fun x => if x ∈ K then (1:ℕ) else 0) + _ = K.card := by simp + simp only [hh,Finset.sum_const,smul_eq_mul] + ring + +noncomputable def overlapExceptions (K E : Finset G) (δ : ℝ) : Finset G := + Finset.univ.filter (fun x => δ*K.card < overlapCount K E x) + +lemma overlapExceptions_card (K E : Finset G) (hK : K.Nonempty) {δ : ℝ} (hδ : 0 < δ) : + ((overlapExceptions K E δ).card:ℝ) ≤ E.card/δ := by + have hKp : (0:ℝ) < K.card := by exact_mod_cast Finset.card_pos.mpr hK + have hs : ((overlapExceptions K E δ).card:ℝ)*(δ*K.card) ≤ + ∑ x : G, (overlapCount K E x:ℝ) := by + have h1 : ∑ x ∈ overlapExceptions K E δ, δ*K.card ≤ + ∑ x ∈ overlapExceptions K E δ, (overlapCount K E x:ℝ) := by + apply Finset.sum_le_sum + intro x hx + exact (Finset.mem_filter.mp hx).2.le + have h2 := Finset.sum_le_sum_of_subset_of_nonneg + (Finset.subset_univ (overlapExceptions K E δ)) + (fun x _ _ => (Nat.cast_nonneg (overlapCount K E x): (0:ℝ)≤_)) + simpa only [Finset.sum_const,nsmul_eq_mul] using h1.trans h2 + have he : (∑ x : G, (overlapCount K E x:ℝ)) = (K.card:ℝ)*E.card := by + exact_mod_cast overlapCount_sum K E + rw [he] at hs + apply (le_div_iff₀ hδ).mpr + nlinarith only [hs,hKp] + +lemma coverage_hit_lower (q : FinLaw G) (K E : Finset G) {τ δ : ℝ} + (hτ : 0 ≤ τ) (hτ1 : τ ≤ 3/8) (hδ : 0 < δ) (hδ1 : δ ≤ 1/64) + (hq : ∀ y ∉ E, (τ+4*δ)/(Fintype.card G:ℝ) ≤ q y) + {x : G} (hx : x ∉ overlapExceptions K E δ) : + (τ+2*δ)*(K.card:ℝ)/(Fintype.card G:ℝ) ≤ q.prob (fun y => x+y ∈ K) := by + have hne := q.nonempty + have hp : (0:ℝ) < Fintype.card G := by exact_mod_cast Fintype.card_pos + have hoc : (overlapCount K E x:ℝ) ≤ δ*K.card := by + simpa only [overlapExceptions,Finset.mem_filter,Finset.mem_univ,true_and,not_lt] using hx + let S := Finset.univ.filter (fun y : G => x+y ∈ K ∧ y ∉ E) + have hcount : (S.card:ℝ)+(overlapCount K E x:ℝ) = K.card := by + have ht : S.card+overlapCount K E x=K.card := by + have hbase : (Finset.univ.filter (fun y : G => x+y ∈ K)).card = K.card := by + simp only [Finset.card_filter] + calc + _ = ∑ y : G, if y ∈ K then (1:ℕ) else 0 := + Equiv.sum_comp (Equiv.addLeft x) (fun y => if y ∈ K then (1:ℕ) else 0) + _ = K.card := by simp + have hsplit := Finset.card_filter_add_card_filter_not + (s := Finset.univ.filter (fun y : G => x+y ∈ K)) (p := fun y => y ∈ E) + have hE : ((Finset.univ.filter (fun y : G => x+y ∈ K)).filter (fun y => y ∈ E)).card = + overlapCount K E x := by + unfold overlapCount + congr 1 + ext y + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + tauto + have hS : (Finset.univ.filter (fun y : G => x+y ∈ K)).filter (fun y => y ∉ E) = S := by + ext y + simp [S] + rw [hE,hS,hbase] at hsplit + omega + exact_mod_cast ht + have h1 : (S.card:ℝ)*((τ+4*δ)/(Fintype.card G:ℝ)) ≤ ∑ y ∈ S, q y := by + simpa only [Finset.sum_const,nsmul_eq_mul] using Finset.sum_le_sum (s := S) + (fun y hy => hq y (Finset.mem_filter.mp hy).2.2) + have h2 : (∑ y ∈ S, q y) ≤ q.prob (fun y => x+y ∈ K) := by + have he : q.prob (fun y => x+y ∈ K) = + ∑ y ∈ Finset.univ.filter (fun y : G => x+y ∈ K), q y := by + simp only [FinLaw.prob,Finset.sum_filter] + apply Finset.sum_congr rfl + intro y _ + by_cases hy : x+y ∈ K <;> simp only [hy,ite_true,ite_false] + rw [he] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro y hy + exact Finset.mem_filter.mpr ⟨Finset.mem_univ y,(Finset.mem_filter.mp hy).2.1⟩ + · intro y _ _ + exact q.nonneg y + have h3 : (τ+2*δ)*K.card ≤ S.card*(τ+4*δ) := by + have hc : (0:ℝ) ≤ K.card := Nat.cast_nonneg _ + have hd : τ+2*δ ≤ (1-δ)*(τ+4*δ) := by nlinarith only [hτ1,hδ1,hδ] + have hm := mul_le_mul_of_nonneg_right hd hc + have hs : (1-δ)*(K.card:ℝ) ≤ S.card := by linarith only [hcount,hoc] + have ht := mul_le_mul_of_nonneg_right hs (by positivity : (0:ℝ) ≤ τ+4*δ) + nlinarith only [hm,ht] + calc + _ ≤ (S.card:ℝ)*((τ+4*δ)/(Fintype.card G:ℝ)) := by + simpa only [mul_div_assoc] using (div_le_div_iff_of_pos_right hp).mpr h3 + _ ≤ _ := h1.trans h2 + +noncomputable def coverageList (K : Finset G) (n : ℕ) (τ δ : ℝ) (h : Fin n → G) : Finset G := + Finset.univ.filter (fun x => + (∑ i : Fin n, if x+h i ∈ K then (1:ℝ) else 0) ≤ + n*(τ+δ)*K.card/(Fintype.card G:ℝ)) + +theorem coverageList_tail (q : FinLaw G) (K E : Finset G) (hK : K.Nonempty) + {τ δ : ℝ} (hτ : 0 ≤ τ) (hτ1 : τ ≤ 3/8) (hδ : 0 < δ) (hδ1 : δ ≤ 1/64) + (hq : ∀ y ∉ E, (τ+4*δ)/(Fintype.card G:ℝ) ≤ q y) (n : ℕ) : + (q.iid n).prob (fun h => ¬ coverageList K n τ δ h ⊆ overlapExceptions K E δ) ≤ + (Fintype.card G:ℝ)*Real.exp (-(n:ℝ)*δ^2*K.card/(2*(Fintype.card G:ℝ))) := by + have hne := q.nonempty + have hp : (0:ℝ) < Fintype.card G := by exact_mod_cast Fintype.card_pos + have hKp : (0:ℝ) < K.card := by exact_mod_cast Finset.card_pos.mpr hK + let μ := (τ+2*δ)*(K.card:ℝ)/(Fintype.card G:ℝ) + let d := δ*(K.card:ℝ)/(Fintype.card G:ℝ) + have hμ : 0 < μ := by dsimp [μ]; positivity + have hd : 0 ≤ d := by dsimp [d]; positivity + have hx (x : G) : (q.iid n).prob (fun h => x ∈ coverageList K n τ δ h ∧ + x ∉ overlapExceptions K E δ) ≤ + Real.exp (-(n:ℝ)*δ^2*K.card/(2*(Fintype.card G:ℝ))) := by + by_cases he : x ∈ overlapExceptions K E δ + · simp only [he,not_true_eq_false,and_false,FinLaw.prob,ite_false,Finset.sum_const_zero] + exact (Real.exp_pos _).le + · have hh := q.iid_lower_tail (fun y => x+y ∈ K) n hμ hd + (coverage_hit_lower q K E hτ hτ1 hδ hδ1 hq he) + have hth : (n:ℝ)*(μ-d) = (n:ℝ)*(τ+δ)*K.card/(Fintype.card G:ℝ) := by + dsimp [μ,d] + ring + rw [hth] at hh + have hm : (q.iid n).prob (fun h => x ∈ coverageList K n τ δ h ∧ + x ∉ overlapExceptions K E δ) ≤ + (q.iid n).prob (fun h => + (∑ i : Fin n, if x+h i ∈ K then (1:ℝ) else 0) ≤ + n*(τ+δ)*K.card/(Fintype.card G:ℝ)) := by + apply FinLaw.prob_mono + intro h hh + exact (Finset.mem_filter.mp hh.1).2 + apply (hm.trans (by + convert! hh using 1 + congr 1 + funext v + congr 1 + apply Finset.sum_congr rfl + intro i _ + by_cases hi : x+v i ∈ K <;> simp only [hi,ite_true,ite_false])).trans + apply Real.exp_le_exp.mpr + have heq : d^2/μ = δ^2*(K.card:ℝ)/((τ+2*δ)*(Fintype.card G:ℝ)) := by + dsimp [d,μ] + field_simp + have ht : 0 < τ+2*δ := by positivity + have ht1 : τ+2*δ ≤ 1 := by linarith only [hτ1,hδ1] + have hratio : δ^2*(K.card:ℝ)/(Fintype.card G:ℝ) ≤ d^2/μ := by + rw [heq] + apply div_le_div_of_nonneg_left (by positivity) (mul_pos ht hp) + exact mul_le_of_le_one_left hp.le ht1 + have hmul := mul_le_mul_of_nonneg_left hratio (show (0:ℝ) ≤ n/2 by positivity) + calc + _ = -((n:ℝ)/2*(d^2/μ)) := by simp only [div_eq_mul_inv,mul_inv_rev]; ring + _ ≤ -((n:ℝ)/2*(δ^2*(K.card:ℝ)/(Fintype.card G:ℝ))) := neg_le_neg hmul + _ = _ := by ring + have hu := (q.iid n).prob_exists_le_sum (fun x h => x ∈ coverageList K n τ δ h ∧ + x ∉ overlapExceptions K E δ) + have hm : (q.iid n).prob (fun h => ¬ coverageList K n τ δ h ⊆ overlapExceptions K E δ) ≤ + (q.iid n).prob (fun h => ∃ x, x ∈ coverageList K n τ δ h ∧ x ∉ overlapExceptions K E δ) := by + apply FinLaw.prob_mono + intro h hh + by_contra hn + apply hh + intro x hx + by_contra he + exact hn ⟨x,hx,he⟩ + apply (hm.trans hu).trans + simpa only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] using + Finset.sum_le_sum (s := Finset.univ) (fun x _ => hx x) + +end + +namespace FinLaw + +section +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] [Fintype α] + +lemma prod_ite_forall {ι : Type uIota} [Fintype ι] (P : ι → Prop) (f : ι → ℝ) : + (∏ i, if P i then f i else 0) = if ∀ i, P i then ∏ i, f i else 0 := by + by_cases h : ∀ i, P i + · simp [h] + · rw [ite_eq_right h] + push Not at h + obtain ⟨i,hi⟩ := h + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +lemma iid_map (p : FinLaw Ω) (f : Ω → α) (n : ℕ) : + (p.iid n).map (fun x i => f (x i)) = (p.map f).iid n := by + ext y + simp only [map_mass,iid_mass] + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro x _ + rw [prod_ite_forall] + congr 1 + exact propext funext_iff + +lemma iid_prob_forall (p : FinLaw Ω) (E : Ω → Prop) (n : ℕ) : + (p.iid n).prob (fun x => ∀ i, E (x i)) = (p.prob E)^n := by + simp only [prob,iid_mass] + calc + _ = ∑ x : Fin n → Ω, ∏ i, if E (x i) then p (x i) else 0 := by + apply Finset.sum_congr rfl + intro x _ + have h := prod_ite_forall (fun i => E (x i)) (fun i => p (x i)) + by_cases hh : ∀ i, E (x i) <;> simpa only [hh,ite_true,ite_false] using h.symm + _ = _ := by + rw [← Fintype.prod_sum (fun (_ : Fin n) (ω : Ω) => if E ω then p ω else (0:ℝ))] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +lemma iid_prob_implies (p : FinLaw Ω) (E F : Ω → Prop) (n : ℕ) + (h : ∀ x, E x → ¬ F x) : + (p.iid n).prob (fun x => ∀ i, E (x i)) ≤ (1-p.prob F)^n := by + rw [← p.prob_compl F,← p.iid_prob_forall] + exact (p.iid n).prob_mono (fun x hx i => h _ (hx i)) + +lemma iid_survival_exp (p : FinLaw Ω) (E : Ω → Prop) (n : ℕ) {c : ℝ} + (hp : c ≤ 1-p.prob E) : + (p.iid n).prob (fun x => ∀ i, E (x i)) ≤ Real.exp (-(n:ℝ)*c) := by + have hbase : p.prob E ≤ Real.exp (-c) := by + have h := Real.add_one_le_exp (-c) + linarith only [hp,h] + rw [iid_prob_forall] + calc + _ ≤ (Real.exp (-c))^n := pow_le_pow_left₀ (p.prob_nonneg E) hbase n + _ = _ := by rw [← Real.exp_nat_mul]; congr 1; ring + +lemma expect_map (p : FinLaw Ω) (f : Ω → α) (g : α → ℝ) : + (∑ a, p.map f a*g a) = ∑ ω, p ω*g (f ω) := by + simp only [map_mass,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + simp only [ite_mul,zero_mul] + simp + +lemma joint_expect_snd (p : FinLaw Ω) (q : Ω → FinLaw α) (f : Ω → α → ℝ) : + (∑ v, p.joint q v*f v.1 v.2) = ∑ ω, p ω*(∑ a, q ω a*f ω a) := by + simp only [Fintype.sum_prod_type,joint_mass,Finset.mul_sum,mul_assoc] + +lemma prob_map_true (p : FinLaw Ω) (E : Ω → Prop) : + p.map (fun ω => decide (E ω)) true = p.prob E := by + simp only [map_mass,decide_eq_true_eq,prob] + +lemma prob_le_of_expect (p : FinLaw Ω) (f : Ω → ℝ) + (hf : ∀ ω, 0 ≤ f ω) {c t : ℝ} (ht : 0 < t) + (hc : (∑ ω, p ω*f ω) ≤ c) : + 1-c/t ≤ p.prob (fun ω => f ω ≤ t) := by + have h := (p.prob_le_expect_div f hf ht).trans ((div_le_div_iff_of_pos_right ht).mpr hc) + have he := p.prob_compl (fun ω => f ω ≤ t) + simp only [not_le] at he + linarith only [h,he] + +end + +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} [Fintype Ω] [Fintype α] [Fintype β] + +lemma H_sub_H_of_agree (p : FinLaw Ω) (X Y : Ω → α) (E : Ω → Bool) + (hE : ∀ ω, p ω ≠ 0 → E ω = true → X ω=Y ω) : + p.H X-p.H Y ≤ Real.binEntropy (p.map E true)+ + (1-p.map E true)*Real.log (Fintype.card α) := by + have h := p.short_list X Y (fun y => {y}) E (b := 1) le_rfl (by + intro ω hp he + simp only [Finset.mem_singleton,Finset.card_singleton,Nat.cast_one,le_refl,and_true] + exact hE ω hp he) + rw [Real.log_one,mul_zero,add_zero] at h + have hc := p.H_le_condH_add X Y + linarith only [h,hc] + +lemma condH_sub_condH_of_agree (p : FinLaw Ω) (X X' : Ω → α) (O O' : Ω → β) + (E : Ω → Bool) (hE : ∀ ω, p ω ≠ 0 → E ω=true → X ω=X' ω ∧ O ω=O' ω) : + p.condH X O-p.condH X' O' ≤ 2*Real.binEntropy (p.map E true)+ + (1-p.map E true)*(Real.log (Fintype.card α)+2*Real.log (Fintype.card β)) := by + have h1 := p.H_sub_H_of_agree (fun ω => (X ω,O ω)) (fun ω => (X' ω,O' ω)) E + (fun ω hp he => Prod.ext (hE ω hp he).1 (hE ω hp he).2) + have h2 := p.H_sub_H_of_agree O' O E (fun ω hp he => (hE ω hp he).2.symm) + have hn := p.nonempty + have ha : Nonempty α := ⟨X (Classical.arbitrary Ω)⟩ + have hb : Nonempty β := ⟨O (Classical.arbitrary Ω)⟩ + have hca : (Fintype.card α:ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + have hcb : (Fintype.card β:ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + rw [Fintype.card_prod,Nat.cast_mul,Real.log_mul hca hcb] at h1 + unfold condH + linarith only [h1,h2] + +lemma binEntropy_le_log_inverse {a : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) : + Real.binEntropy a ≤ a*(1-Real.log a) := by + have h : Real.negMulLog (1-a) ≤ a := by + by_cases hz : 1-a=0 + · simp only [hz,Real.negMulLog_zero] + exact ha.le + · have hp : 0 < 1-a := lt_of_le_of_ne (by linarith) (Ne.symm hz) + have hh := Real.log_le_sub_one_of_pos (inv_pos.mpr hp) + rw [Real.log_inv] at hh + have hm := mul_le_mul_of_nonneg_left hh hp.le + rw [mul_sub,mul_inv_cancel₀ hz,mul_one] at hm + unfold Real.negMulLog + nlinarith only [hm] + rw [Real.binEntropy_eq_negMulLog_add_negMulLog_one_sub] + dsimp only [Real.negMulLog] at h ⊢ + nlinarith only [h] + +lemma binEntropy_sum_le {ι : Type uIota} [Fintype ι] (w : FinLaw ι) (a : ι → ℝ) + (ha : ∀ i, a i ∈ Set.Icc (0:ℝ) 1) : + (∑ i, w i*Real.binEntropy (a i)) ≤ Real.binEntropy (∑ i, w i*a i) := by + exact Real.strictConcave_binEntropy.concaveOn.le_map_sum (fun i _ => w.nonneg i) w.sum_one (fun i _ => ha i) + +end FinLaw + +open scoped BigOperators Classical +namespace FinLaw +variable {Ω : Type uOmega} {Γ : Type uCapitalGamma} {G : Type uGroup} [Fintype Ω] [Fintype Γ] [Fintype G] [AddCommGroup G] + +omit [AddCommGroup G] in +lemma prob_mem_finset (p : FinLaw G) (K : Finset G) : + p.prob (fun x => x ∈ K) = ∑ x ∈ K, p x := by + unfold prob + calc + _ = ∑ x ∈ K, if x ∈ K then p x else 0 := by + symm + convert! Finset.sum_subset (Finset.subset_univ K) + (f := fun x => if x ∈ K then p x else (0:ℝ)) + (fun x _ hx => ite_eq_right hx) using 1 + apply Finset.sum_congr rfl + intro x _ + by_cases hx : x∈K <;> simp only [hx,ite_true,ite_false] + _ = _ := Finset.sum_congr rfl (fun x hx => ite_eq_left hx) + +lemma joint_prob_le_bad_add (p : FinLaw Ω) (q : Ω → FinLaw Γ) + (Bad : Ω → Prop) (E : Ω × Γ → Prop) {ε : ℝ} (hε : 0 ≤ ε) + (hg : ∀ ω, ¬ Bad ω → (q ω).prob (fun a => E (ω,a)) ≤ ε) : + (p.joint q).prob E ≤ p.prob Bad+ε := by + rw [prob_joint] + have h (ω : Ω) : (q ω).prob (fun a => E (ω,a)) ≤ (if Bad ω then 1 else 0)+ε := by + by_cases hb : Bad ω + · simpa only [hb,ite_true] using (q ω).prob_le_one (fun a => E (ω,a)) |>.trans (by linarith only [hε]) + · simpa only [hb,ite_false,zero_add] using hg ω hb + have hh := Finset.sum_le_sum (s := Finset.univ) (fun ω _ => + mul_le_mul_of_nonneg_left (h ω) (p.nonneg ω)) + convert! hh using 1 + simp only [mul_add,Finset.sum_add_distrib,← Finset.sum_mul,p.sum_one,one_mul,prob] + congr 1 + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + +omit [Fintype G] in + +lemma iid_true_hit_expect (p : FinLaw Ω) (q : Ω → FinLaw Γ) + (Y : Ω → G) (h : Γ → G) (K : Finset G) (n : ℕ) : + (∑ v, p.joint (fun ω => (q ω).iid n) v * + (∑ i : Fin n, if Y v.1+h (v.2 i) ∈ K then (1:ℝ) else 0)) = + n*(p.joint q).prob (fun v => Y v.1+h v.2 ∈ K) := by + rw [joint_expect_snd p (fun ω => (q ω).iid n) + (fun ω v => ∑ i : Fin n, if Y ω+h (v i) ∈ K then (1:ℝ) else 0)] + have he (i : Fin n) (ω : Ω) : + (∑ v, (q ω).iid n v*(if Y ω+h (v i) ∈ K then (1:ℝ) else 0)) = + (q ω).prob (fun a => Y ω+h a ∈ K) := by + rw [← expect_map ((q ω).iid n) (fun v => v i) (fun a => if Y ω+h a ∈ K then (1:ℝ) else 0), + iid_map_eval] + unfold prob + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp + have hh (ω : Ω) : + (∑ v, (q ω).iid n v*(∑ i : Fin n, if Y ω+h (v i) ∈ K then (1:ℝ) else 0)) = + n*(q ω).prob (fun a => Y ω+h a ∈ K) := by + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + simp only [he,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + simp only [hh,mul_left_comm (p _) (n:ℝ)] + rw [← Finset.mul_sum,prob_joint p q (fun v => Y v.1+h v.2∈K)] + +lemma true_coverageList_probability (p : FinLaw Ω) (q : Ω → FinLaw Γ) + (Y : Ω → G) (h : Γ → G) (K : Finset G) (hK : K.Nonempty) + {τ δ : ℝ} (hτ : 0 ≤ τ) (hδ : 0 < δ) {n : ℕ} (hn : 0 < n) + (hp : (p.joint q).prob (fun v => Y v.1+h v.2 ∈ K) ≤ + τ*K.card/(Fintype.card G:ℝ)) : + δ/(τ+δ) ≤ (p.joint (fun ω => (q ω).iid n)).prob + (fun v => Y v.1 ∈ coverageList K n τ δ (fun i => h (v.2 i))) := by + have hG : Nonempty G := ⟨Y (Classical.choice p.nonempty)⟩ + have hcard : (0:ℝ) < Fintype.card G := by exact_mod_cast Fintype.card_pos + have hkc : (0:ℝ) < K.card := by exact_mod_cast Finset.card_pos.mpr hK + have hnc : (0:ℝ) < n := by exact_mod_cast hn + have htd : 0 < τ+δ := by linarith + have hb : (∑ v, p.joint (fun ω => (q ω).iid n) v * + (∑ i : Fin n, if Y v.1+h (v.2 i) ∈ K then (1:ℝ) else 0)) ≤ + n*(τ*K.card/(Fintype.card G:ℝ)) := by + rw [iid_true_hit_expect] + exact mul_le_mul_of_nonneg_left hp hnc.le + have hh := (p.joint (fun ω => (q ω).iid n)).prob_le_of_expect + (fun v => ∑ i : Fin n, if Y v.1+h (v.2 i) ∈ K then (1:ℝ) else 0) + (fun _ => Finset.sum_nonneg (fun _ _ => by split_ifs <;> norm_num)) + (t := n*(τ+δ)*K.card/(Fintype.card G:ℝ)) (by positivity) hb + have he : 1-(n*(τ*K.card/(Fintype.card G:ℝ)))/(n*(τ+δ)*K.card/(Fintype.card G:ℝ)) = + δ/(τ+δ) := by field_simp; ring + rw [he] at hh + simpa only [coverageList,Finset.mem_filter,Finset.mem_univ,true_and] using hh + +lemma coverageList_size_probability (p : FinLaw Ω) (q : Ω → FinLaw Γ) + (h : Γ → G) (K : Finset G) (hK : K.Nonempty) (E : Ω → Finset G) + (Bad : Ω → Prop) {τ δ ε b : ℝ} + (hτ : 0 ≤ τ) (hτ1 : τ ≤ 3/8) (hδ : 0 < δ) (hδ1 : δ ≤ 1/64) + (hε : 0 ≤ ε) (n : ℕ) + (hq : ∀ ω, ¬ Bad ω → ∀ y ∉ E ω, + (τ+4*δ)/(Fintype.card G:ℝ) ≤ (q ω).map h y) + (hE : ∀ ω, ¬ Bad ω → ((E ω).card:ℝ)/δ ≤ b) + (herr : (Fintype.card G:ℝ)*Real.exp (-(n:ℝ)*δ^2*K.card/(2*(Fintype.card G:ℝ))) ≤ ε) : + (p.joint (fun ω => (q ω).iid n)).prob (fun v => + b < ((coverageList K n τ δ (fun i => h (v.2 i))).card:ℝ)) ≤ p.prob Bad+ε := by + apply joint_prob_le_bad_add p _ Bad _ hε + intro ω hg + have ha := (coverageList_tail ((q ω).map h) K (E ω) hK hτ hτ1 hδ hδ1 (hq ω hg) n).trans herr + rw [← iid_map,prob_map] at ha + apply (prob_mono _ ?_).trans ha + intro x hx hs + have hc := Finset.card_le_card hs + have hcR : ((coverageList K n τ δ (fun i => h (x i))).card:ℝ) ≤ + ((overlapExceptions K (E ω) δ).card:ℝ) := by exact_mod_cast hc + have hb := (overlapExceptions_card K (E ω) hK hδ).trans (hE ω hg) + linarith only [hx,hcR,hb] + +end FinLaw +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/Information.lean b/lean/OAI/NumberTheory/GaussianMoat/Information.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0982945a1174ec7d3534c8d2f998e13cc3d5bae --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/Information.lean @@ -0,0 +1,381 @@ +import OAI.NumberTheory.GaussianMoat.TimeLaw + +namespace OAI + +universe uOmega uAlpha uBeta uGamma uDelta uEpsilon uZeta uIota + +namespace GaussianMoat + +section +open scoped BigOperators Classical + +namespace FinLaw +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} [Fintype Ω] [Fintype α] [Fintype β] [Fintype γ] + +lemma mix_map_left (p : FinLaw Ω) (f : Ω → α) (q : α → FinLaw β) : + (p.map f).mix q = p.mix (fun ω => q (f ω)) := by + ext b + simp only [mix_mass,map_mass,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + simp only [ite_mul,zero_mul] + rw [Finset.sum_ite_eq] + simp + +lemma mix_assoc (p : FinLaw Ω) (q : Ω → FinLaw α) (r : α → FinLaw β) : + (p.mix q).mix r = p.mix (fun ω => (q ω).mix r) := by + ext b + simp only [mix_mass,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + apply Finset.sum_congr rfl + intro a _ + ring + +lemma joint_observation (p : FinLaw Ω) (q : Ω → FinLaw α) (F : Ω → α → β) : + (p.joint q).map (fun v => F v.1 v.2) = p.mix (fun ω => (q ω).map (F ω)) := by + have h := congrArg (fun r : FinLaw (Ω × β) => r.map Prod.snd) (joint_map_fiber p q F) + simpa only [map_comp,joint_map_snd,Function.comp_def] using h + +lemma joint_associate (p : FinLaw Ω) (q : Ω → FinLaw α) (r : Ω → α → FinLaw β) : + ((p.joint q).joint (fun v => r v.1 v.2)).map (fun v => (v.1.1,(v.1.2,v.2))) = + p.joint (fun ω => (q ω).joint (r ω)) := by + ext v + rcases v with ⟨ω,a,b⟩ + change ((p.joint q).joint (fun v => r v.1 v.2)).map (Equiv.prodAssoc Ω α β) (ω,a,b) = _ + rw [map_equiv_mass] + simp only [Equiv.prodAssoc_symm_apply,joint_mass,mul_assoc] + +end FinLaw + +structure ForwardKernel where + bound : ℕ + law : ℕ → FinLaw (Fin (bound+1)) + +noncomputable def addOffsets (n m : ℕ) : Fin (n+1) × Fin (m+1) → Fin (n+m+1) := + fun v => ⟨v.1.val+v.2.val,by omega⟩ + +noncomputable def ForwardKernel.then (K R : ForwardKernel) : ForwardKernel where + bound := K.bound+R.bound + law := fun a => ((K.law a).joint (fun i => R.law (a+i.val))).map + (addOffsets K.bound R.bound) + +noncomputable def differenceKernel (z : ℕ → GaussianInt) (n : ℕ) : ForwardKernel where + bound := n + law := fun a => ((FinLaw.uniform Bool).joint (fun _ => + differenceLaw (fun t => z (a+t)) n)).map (fun v => if v.1 then v.2.1 else v.2.2) + +noncomputable def smoothingKernel (n : ℕ) : ForwardKernel where + bound := n + law := fun _ => FinLaw.uniform (Fin (n+1)) + +noncomputable def commonSchedule (z : ℕ → GaussianInt) (ns : List ℕ) (N : ℕ) : ForwardKernel := + ns.foldr (fun n K => (differenceKernel z n).then K) (smoothingKernel N) + +@[simp] lemma commonSchedule_bound (z : ℕ → GaussianInt) (ns : List ℕ) (N : ℕ) : + (commonSchedule z ns N).bound = ns.sum+N := by + induction ns with + | nil => simp [commonSchedule,smoothingKernel] + | cons n ns ih => + change n+(commonSchedule z ns N).bound = _ + rw [ih,List.sum_cons,Nat.add_assoc] + +@[simp] lemma commonSchedule_cons (z : ℕ → GaussianInt) (n : ℕ) (ns : List ℕ) (N : ℕ) : + commonSchedule z (n::ns) N = (differenceKernel z n).then (commonSchedule z ns N) := rfl + +noncomputable def TimeLaw.advance (P : TimeLaw) (K : ForwardKernel) : TimeLaw where + last := P.last+K.bound + law := (P.law.joint (fun a => K.law a.val)).map (addOffsets P.last K.bound) + +lemma ForwardKernel.displacement_entropy (K : ForwardKernel) (a : ℕ) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 1 ≤ D) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) (hK : 1 ≤ K.bound) : + (K.law a).Hf (fun i => z (a+i.val)-z a) ≤ + Real.log 36+2*Real.log (D*K.bound) := by + apply displacement_entropy_le + · exact one_le_mul_of_one_le_of_one_le hD (by exact_mod_cast hK) + · intro i + simpa only [Nat.add_zero] using walk_pair_displacement z (by linarith only [hD]) hstep + a K.bound i.val 0 (by omega) (by omega) + +lemma TimeLaw.advance_displacement_entropy (P : TimeLaw) (K : ForwardKernel) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 1 ≤ D) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) (hK : 1 ≤ K.bound) : + (P.law.joint (fun a => K.law a.val)).Hf + (fun v => z (v.1.val+v.2.val)-z v.1.val) ≤ + Real.log 36+2*Real.log (D*K.bound) := by + apply displacement_entropy_le + · exact one_le_mul_of_one_le_of_one_le hD (by exact_mod_cast hK) + · intro v + simpa only [Nat.add_zero] using walk_pair_displacement z (by linarith only [hD]) hstep + v.1.val K.bound v.2.val 0 (by omega) (by omega) + +lemma entropy_step_deficit {b q : ℕ} {L F E E' g e C : ℝ} + (hq : 0 < q) (hL : 0 ≤ L) (hg : 0 ≤ g) (hg1 : g ≤ 1/100) + (hbq : (b:ℝ) ≤ g*q) (hF : (1-30*g)*L ≤ F) + (hE : (1-e)*(q:ℝ)*L ≤ E) (hC : C ≤ 8*g*q*L) + (hstep : (b:ℝ)*((q-b:ℕ)*F+E-C) ≤ 2*(q:ℝ)*E') : + (1-e/2-20*g)*(b:ℝ)*L ≤ E' := by + have hqr : (0:ℝ) < q := by exact_mod_cast hq + have hbqr : (b:ℝ) ≤ q := by nlinarith only [hbq,hg1,hqr] + have hbqnat : b ≤ q := by exact_mod_cast hbqr + rw [Nat.cast_sub hbqnat] at hstep + have hqbn : 0 ≤ (q:ℝ)-b := by linarith only [hbqr] + have hFb := mul_le_mul_of_nonneg_left hF hqbn + have hgl : 0 ≤ (1-30*g)*L := mul_nonneg (by linarith only [hg1]) hL + have hbL := mul_le_mul_of_nonneg_right hbq hgl + have hgg := mul_nonneg (mul_nonneg hg hg) (mul_nonneg hqr.le hL) + have hgql : 0 ≤ g*(q:ℝ)*L := by positivity + have hcore : (2-e-40*g)*(q:ℝ)*L ≤ ((q:ℝ)-b)*F+E-C := by + nlinarith only [hFb,hbL,hE,hC,hgg,hgql] + have hm := mul_le_mul_of_nonneg_left hcore (Nat.cast_nonneg b : (0:ℝ) ≤ b) + apply (mul_le_mul_iff_right₀ (mul_pos (by norm_num : (0:ℝ)<2) hqr)).mp + calc + _ = (b:ℝ)*((2-e-40*g)*(q:ℝ)*L) := by ring + _ ≤ (b:ℝ)*(((q:ℝ)-b)*F+E-C) := hm + _ ≤ _ := hstep + +theorem TimeLaw.step_deficit (P : TimeLaw) (s : SplitSieve) + (z : ℕ → GaussianInt) {D g e : ℝ} (hD : 1 ≤ D) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) {n b q : ℕ} + (hn : 1 ≤ n) (hb : 0 < b) (hbq : b < q) (hq : q ≤ s.primes.card) + (hg : 0 ≤ g) (hg1 : g ≤ 1/100) (hL : 0 ≤ s.meanLog) + (hratio : (b:ℝ) ≤ g*q) + (hfresh : ∀ a : Fin (P.last+1), (1-30*g)*s.meanLog ≤ s.freshCoordinate + (differenceLaw (fun t => z (a.val+t)) n) + (fun ij => z (a.val+ij.1.val)) (fun ij => z (a.val+ij.2.val)) b (by omega)) + (hE : (1-e)*(q:ℝ)*s.meanLog ≤ s.pointEntropy P.law (fun a => z a.val) q) + (hcost : 2*(Real.log 36+2*Real.log (D*n)) ≤ 8*g*q*s.meanLog) : + (1-e/2-20*g)*(b:ℝ)*s.meanLog ≤ + s.pointEntropy (P.step z n).law (fun a => z a.val) b := by + exact entropy_step_deficit (by omega) hL hg hg1 hratio le_rfl hE hcost + (P.step_enrichment s z hD hstep hn hb hbq hq hfresh) + +lemma deficit_iteration (l : ℕ) {g : ℝ} (hg : 0 ≤ g) (e : ℕ → ℝ) + (h0 : e 0 ≤ 1) (hnext : ∀ j < l, e (j+1) ≤ e j/2+20*g) : + e l ≤ (1/2:ℝ)^l+40*g := by + induction l with + | zero => simpa only [pow_zero] using h0.trans (le_add_of_nonneg_right (by positivity)) + | succ l ih => + have hi := ih (fun j hj => hnext j (by omega)) + have hn := hnext l (by omega) + rw [pow_succ] + linarith only [hi,hn] + +end + +section +namespace FinLaw +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} [Fintype Ω] [Fintype α] [Fintype β] [Fintype γ] + +lemma joint_observation_fun (p : FinLaw Ω) (q : Ω → FinLaw α) (F : Ω × α → β) : + (p.joint q).map F = p.mix (fun ω => (q ω).map (fun a => F (ω,a))) := by + exact joint_observation p q (fun ω a => F (ω,a)) + +lemma mix_comm (p : FinLaw Ω) (q : FinLaw α) (r : Ω → α → FinLaw β) : + p.mix (fun ω => q.mix (r ω)) = q.mix (fun a => p.mix (fun ω => r ω a)) := by + ext b + simp only [mix_mass,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro ω _ + ring + +end FinLaw +open scoped BigOperators Classical + +lemma TimeLaw.advance_difference (P : TimeLaw) (z : ℕ → GaussianInt) (n : ℕ) : + P.advance (differenceKernel z n) = P.step z n := by + unfold TimeLaw.advance TimeLaw.step differenceKernel + congr 1 + dsimp only + rw [FinLaw.joint_observation_fun] + conv_lhs => arg 2; ext a; rw [FinLaw.map_comp,FinLaw.joint_observation_fun] + rw [FinLaw.mix_comm,FinLaw.joint_observation_fun] + conv_rhs => arg 2; ext c; rw [FinLaw.joint_observation_fun] + apply congrArg + funext c + apply congrArg + funext a + apply congrArg + funext ij + apply Fin.ext + dsimp only [Function.comp_def,addOffsets,endpointTime] + split_ifs <;> rfl + +end + +namespace FinLaw +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} {δ : Type uDelta} {ε : Type uEpsilon} [Fintype Ω] + +noncomputable def cIf (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (O : Ω → γ) : ℝ := + p.cHf X O-p.cHf X (fun ω => (O ω,Y ω)) + +lemma cIf_nonneg (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (O : Ω → γ) : + 0 ≤ p.cIf X Y O := sub_nonneg.mpr (p.cHf_mono X O Y) + +lemma cIf_comm (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (O : Ω → γ) : + p.cIf X Y O = p.cIf Y X O := by + unfold cIf cHf + have he : p.Hf (fun ω => (X ω,(O ω,Y ω))) = + p.Hf (fun ω => (Y ω,(O ω,X ω))) := by + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq] + tauto + rw [he,p.Hf_pair_comm O Y,p.Hf_pair_comm O X] + ring + +lemma cIf_le_cHf (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (O : Ω → γ) : + p.cIf X Y O ≤ p.cHf X O := by + have h := p.cHf_nonneg X (fun ω => (O ω,Y ω)) + unfold cIf + linarith + +lemma cIf_le_Hf (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (O : Ω → γ) : + p.cIf X Y O ≤ p.Hf Y := by + rw [p.cIf_comm] + exact (p.cIf_le_cHf Y X O).trans (p.cHf_le_Hf Y O) + +lemma cIf_chain (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (Z : Ω → δ) (O : Ω → γ) : + p.cIf X (fun ω => (Y ω,Z ω)) O = + p.cIf X Y O+p.cIf X Z (fun ω => (O ω,Y ω)) := by + unfold cIf + have he : p.cHf X (fun ω => (O ω,(Y ω,Z ω))) = + p.cHf X (fun ω => ((O ω,Y ω),Z ω)) := by + unfold cHf + rw [p.Hf_pair_assoc O Y Z] + congr 1 + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq,and_assoc] + rw [he] + ring + +lemma cIf_conditioning_cost (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) + (O : Ω → γ) (S : Ω → δ) : + p.cIf X Y (fun ω => (O ω,S ω)) ≤ p.cIf X Y O+p.Hf S := by + have h1 := p.cHf_mono X O S + have h2 := p.cHf_mono S O Y + have h3 := p.cHf_le_Hf S O + have h4 := p.cHf_nonneg S (fun ω => (X ω,(O ω,Y ω))) + have h5 := p.cHf_chain X S (fun ω => (O ω,Y ω)) + have h6 := p.cHf_chain S X (fun ω => (O ω,Y ω)) + have he : p.cHf (fun ω => (X ω,S ω)) (fun ω => (O ω,Y ω)) = + p.cHf (fun ω => (S ω,X ω)) (fun ω => (O ω,Y ω)) := by + unfold cHf + congr 1 + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq] + tauto + have he' : p.cHf X (fun ω => ((O ω,S ω),Y ω)) = + p.cHf X (fun ω => (S ω,(O ω,Y ω))) := by + unfold cHf + congr 1 <;> apply p.Hf_eq_of_fibers <;> intro ω ν <;> + simp only [Prod.mk.injEq] <;> tauto + unfold cIf + rw [he'] + linarith only [h1,h2,h3,h4,h5,h6,he] + +theorem cIf_transport (p : FinLaw Ω) (X : Ω → α) (O : Ω → β) + (X' : Ω → γ) (O' : Ω → δ) (W : Ω → ε) {ζ : Type uZeta} (S : Ω → ζ) + (hO : ∀ ω ν, (O ω,S ω)=(O ν,S ν) ↔ (O' ω,S ω)=(O' ν,S ν)) + (hX : ∀ ω ν, (X ω,O ω,S ω)=(X ν,O ν,S ν) ↔ + (X' ω,O' ω,S ω)=(X' ν,O' ν,S ν)) : + p.cIf X (fun ω => (S ω,W ω)) O ≤ p.cIf X' W O'+2*p.Hf S := by + have he : p.cIf X W (fun ω => (O ω,S ω)) = + p.cIf X' W (fun ω => (O' ω,S ω)) := by + rw [p.cIf_comm X W,p.cIf_comm X' W] + unfold cIf cHf + congr 2 + · apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq,hO] + · exact p.Hf_eq_of_fibers _ _ hO + · apply p.Hf_eq_of_fibers + intro ω ν + have hh := hX ω ν + simp only [Prod.mk.injEq] at hh ⊢ + tauto + · apply p.Hf_eq_of_fibers + intro ω ν + have hh := hX ω ν + simp only [Prod.mk.injEq] at hh ⊢ + tauto + rw [p.cIf_chain X S W O,he] + have h1 := p.cIf_le_Hf X S O + have h2 := p.cIf_conditioning_cost X' W O' S + linarith + +lemma cHf_eq_conditionOn [Fintype β] (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.cHf X Y = ∑ a, p.map Y a*(p.conditionOn Y a).Hf X := by + let C := outputCode X + have hh := p.condH_eq_conditionOn C Y + have hx (r : FinLaw Ω) : r.Hf C = r.Hf X := by + apply r.Hf_eq_of_fibers + intro ω ν + exact outputCode_eq_iff X ω ν + have hpair : p.Hf (fun ω => (C ω,Y ω)) = p.Hf (fun ω => (X ω,Y ω)) := by + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq,C,outputCode_eq_iff] + simpa only [condH,← Hf_eq_H,hx,hpair,cHf] using hh + +end FinLaw + +open scoped BigOperators Classical + +theorem SplitSieve.pointEntropy_shift {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (p : FinLaw Ω) (X Y : Ω → GaussianInt) (b : ℕ) : + s.pointEntropy p X b ≤ s.pointEntropy p Y b+p.Hf (fun ω => Y ω-X ω) := by + have h (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) : + p.Hf (FinLaw.prefixVar (fun ω => s.residueVector σ (X ω)) π b) ≤ + p.Hf (FinLaw.prefixVar (fun ω => s.residueVector σ (Y ω)) π b)+ + p.Hf (fun ω => Y ω-X ω) := by + apply (p.Hf_le_of_determined _ (fun ω => + (FinLaw.prefixVar (fun ν => s.residueVector σ (Y ν)) π b ω,Y ω-X ω)) ?_).trans + (p.Hf_pair_subadd _ _) + intro ω ν hh + funext i + by_cases hi : i.val + Finset.expect_le_expect (s := Finset.univ) (fun π _ => h σ π)) + simpa only [SplitSieve.pointEntropy,FinLaw.signedEntropy,FinLaw.orderedEntropy, + Finset.expect_add_distrib,Fintype.expect_const] using hh + +lemma residue_observation_shift {Ω : Type uOmega} {ι : Type uIota} (f : ι → GaussianInt) + (X Y : Ω → GaussianInt) (ω ν : Ω) : + ((fun i => residueCode (f i) (X ω)),Y ω-X ω)= + ((fun i => residueCode (f i) (X ν)),Y ν-X ν) ↔ + ((fun i => residueCode (f i) (Y ω)),Y ω-X ω)= + ((fun i => residueCode (f i) (Y ν)),Y ν-X ν) := by + simp only [Prod.mk.injEq] + constructor + · rintro ⟨hx,hd⟩ + refine ⟨?_,hd⟩ + funext i + have h := residueCode_add (congrFun hx i) (congrArg (residueCode (f i)) hd) + simpa only [add_sub_cancel] using h + · rintro ⟨hy,hd⟩ + refine ⟨?_,hd⟩ + funext i + have h := residueCode_sub (congrFun hy i) (congrArg (residueCode (f i)) hd) + simpa only [sub_sub_cancel] using h + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/InformationTelescope.lean b/lean/OAI/NumberTheory/GaussianMoat/InformationTelescope.lean new file mode 100644 index 0000000000000000000000000000000000000000..8fdac298f262560c04c3e3b4bc3705027ea0fb21 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/InformationTelescope.lean @@ -0,0 +1,291 @@ +import OAI.NumberTheory.GaussianMoat.WalkPackage + +namespace OAI + +universe uOmega uKappa uIota uAlpha uBeta uGamma + +namespace GaussianMoat +open scoped BigOperators Classical + +theorem exists_batch_information {Ω : Type uOmega} {κ : Type uKappa} [Fintype Ω] + (s : SplitSieve) (hne : s.primes.Nonempty) (p : FinLaw Ω) (a : Ω → ℕ) + (g : κ → GaussianInt) (R : ForwardKernel) (z : ℕ → GaussianInt) + (hz : Function.Injective z) (ha : ∀ t, z t∈s.avoiding) + {b L N n : ℕ} (hb : b≤ s.primes.card) (hn : 0 z (a ω)) b) + (hO : p.Hf (fun ω i => residueCode (g i) (z (a ω)))≤E) + (hBad : (𝔼 i : s.SignedIndex, p.prob (fun ω => e i≤ + (((R.then (smoothingKernel N)).relativeResidueLaw s z (a ω) i).lowResidues τ).card))≤η) + (hnum : ∀ i, Real.log (4*e i+(s.signedPrime i:ℝ)*Real.exp + (-(n:ℝ)*(((L:ℝ)*(τ/(s.signedPrime i:ℝ))/2)/4))) ≤ + Real.log (s.signedPrime i)-A) + (hrate : (n:ℝ)*((L:ℝ)*r+2*(Real.log 36+2*Real.log (D*(R.bound+N)))) ≤ + (b:ℝ)*(A*(1-2*η)-δ*s.meanLog)-E) : + ∃ σ : Fin s.primes.card → Bool, ∃ π : Equiv.Perm (Fin s.primes.card), + r≤ (p.joint (fun ω => (R.then (smoothingKernel N)).law (a ω))).cIf + (fun v j => residueCode (s.signedFactorAt (s.selectedIndex hb σ π j)) + (z (a v.1+v.2.val))) + (fun v => incrementWord z L (a v.1+v.2.val)) + (fun v i => residueCode (g i) (z (a v.1+v.2.val))) / L := by + let K := R.then (smoothingKernel N) + let old := fun ω i => residueCode (g i) (z (a ω)) + let old' := FinLaw.outputCode old + have hOld : p.Hf old'≤E := by + apply le_trans (le_of_eq (p.Hf_eq_of_fibers old' old (fun ω ν => FinLaw.outputCode_eq_iff old ω ν))) hO + have hD0 : 0≤D := by linarith only [hD] + have hlower := averaged_batch_package_information s hne p a old' R z hz ha hb + hD0 hτ hA hs e he hshort hLN herr hH hOld hBad hnum + let Info := fun (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) => + (p.joint (fun ω => K.law (a ω))).cIf + (fun v j => residueCode (s.signedFactorAt (s.selectedIndex hb σ π j)) (z (a v.1+v.2.val))) + (fun v => incrementWord z L (a v.1+v.2.val)) + (fun v i => residueCode (g i) (z (a v.1+v.2.val))) + have hK : 1≤K.bound := by change 1≤R.bound+N; omega + have ht (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) : + (p.joint (fun ω => K.packageLaw z hD0 hs (a ω) L)).cIf + (fun v j => s.residue (s.selectedIndex hb σ π j) (z (a v.1))) Prod.snd + (fun v => old' v.1) ≤ Info σ π+2*(Real.log 36+2*Real.log (D*K.bound)) := by + have hc := (p.joint (fun ω => K.packageLaw z hD0 hs (a ω) L)).cIf_congr_fibers + (fun v j => s.residue (s.selectedIndex hb σ π j) (z (a v.1))) + (fun v j => residueCode (s.signedFactorAt (s.selectedIndex hb σ π j)) (z (a v.1))) + Prod.snd Prod.snd (fun v => old' v.1) (fun v => old v.1) + (fun v w => by + simp only [funext_iff,SplitSieve.residue,gaussianResidue_eq,residueCode_eq]) + (fun _ _ => Iff.rfl) (fun v w => FinLaw.outputCode_eq_iff old v.1 w.1) + rw [hc] + exact K.package_information_transport p a (fun j => s.signedFactorAt (s.selectedIndex hb σ π j)) + g z hD hs hK L + have hav := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => + Finset.expect_le_expect (s := Finset.univ) (fun π _ => ht σ π)) + simp only [Finset.expect_add_distrib,Fintype.expect_const] at hav + have hmul := mul_le_mul_of_nonneg_left hav (Nat.cast_nonneg n) + have hnR : 0<(n:ℝ) := by exact_mod_cast hn + have hrate' : (L:ℝ)*r≤𝔼 σ, 𝔼 π, Info σ π := by + have heK : (K.bound:ℝ)=R.bound+N := by simp only [K,ForwardKernel.then,smoothingKernel,Nat.cast_add] + conv at hmul => rhs; rw [heK] + have hh := hrate.trans (hlower.trans hmul) + apply (mul_le_mul_iff_right₀ hnR).mp + nlinarith only [hh] + obtain ⟨σ,_,hσ⟩ := Finset.exists_le_of_le_expect Finset.univ_nonempty hrate' + obtain ⟨π,_,hπ⟩ := Finset.exists_le_of_le_expect Finset.univ_nonempty hσ + refine ⟨σ,π,?_⟩ + exact (le_div_iff₀ (show (0:ℝ) simp + | succ n ih => + have hn := ih (fun j hj => hnext j (by omega)) + have hh := hnext n (by omega) + rw [Finset.sum_range_succ,Nat.cast_add,Nat.cast_one] + linarith only [hn,hh] + linarith only [h,hb] + +theorem word_entropy_rate_monotone {Ω : Type uOmega} {ι : Type uIota} [Fintype Ω] [Fintype ι] + (p : FinLaw Ω) (t : Ω → ℕ) (z : ℕ → GaussianInt) {D : ℝ} + (hz : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) + (f : ι → GaussianInt) (hf : ∀ i, f i≠0) {L K N : ℕ} + (hL : 0 FinLaw.uniform (Fin (N+1))) + P.cHf (fun v => incrementWord z K (t v.1+v.2.val)) + (fun v i => residueCode (f i) (z (t v.1+v.2.val))) / K ≤ + P.cHf (fun v => incrementWord z L (t v.1+v.2.val)) + (fun v i => residueCode (f i) (z (t v.1+v.2.val))) / L + ε := by + dsimp only + let P := p.joint (fun _ => FinLaw.uniform (Fin (N+1))) + let u := fun v : Ω × Fin (N+1) => t v.1+v.2.val + let Q := fun v i => residueCode (f i) (z (u v)) + let H := P.cHf (fun v => incrementWord z L (u v)) Q + obtain ⟨m,hm⟩ := hdiv + have hm' : K=m*L := by simpa [Nat.mul_comm] using hm + have hmp : 0 < m := by nlinarith only [hK,hm] + have hLp : (0:ℝ) incrementWord z L (u v+j.val*L)) + (fun v i => residueCode (f i) (z (u v+j.val*L)))) ≤ (m:ℝ)*(H+ε) := by + have hh (j : Fin m) : P.cHf (fun v => incrementWord z L (u v+j.val*L)) + (fun v i => residueCode (f i) (z (u v+j.val*L))) ≤ H+ε := by + have hj : j.val*L hh j) + simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using hh' + have htotal := hblock.trans hsum + have hd := div_le_div_of_nonneg_right htotal (show (0:ℝ)≤ m*L by positivity) + have he : (m:ℝ)*(H+ε)/((m:ℝ)*L)=(H+ε)/L := by field_simp + rw [he,add_div] at hd + have hel : ε/(L:ℝ)≤ε := div_le_self hε (by exact_mod_cast hL) + rw [hm',Nat.cast_mul] + change P.cHf (fun v => incrementWord z (m*L) (u v)) Q / ((m:ℝ)*L) ≤ H/L+ε + linarith only [hd,hel] + +lemma FinLaw.cIf_refinement {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} [Fintype Ω] + (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (O : Ω → γ) + (h : ∀ ω ν, X ω = X ν → O ω = O ν) : + p.cIf X Y O = p.cHf Y O - p.cHf Y X := by + rw [p.cIf_comm] + unfold FinLaw.cIf + congr 1 + apply p.cHf_congr_fibers Y Y (fun ω => (O ω,X ω)) X + · intro ω ν; rfl + · intro ω ν + simp only [Prod.mk.injEq] + exact ⟨And.right,fun hx => ⟨h ω ν hx,hx⟩⟩ + +theorem common_law_information_telescope {Ω : Type uOmega} [Fintype Ω] + (p : FinLaw Ω) (t : Ω → ℕ) (z : ℕ → GaussianInt) {D : ℝ} + (hz : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) + (F : ℕ → Finset GaussianInt) (hF : ∀ j, F j ⊆ F (j+1)) + (hf : ∀ j, ∀ f ∈ F j, f ≠ 0) (L : ℕ → ℕ) (n N : ℕ) + (hL : ∀ j ≤ n, 0 < L j) (hdiv : ∀ j < n, L j ∣ L (j+1)) + (hN : ∀ j ≤ n, L j ≤ N) {ε : ℝ} (hε : 0 ≤ ε) + (herr : ∀ j < n, ∀ a < L (j+1), + 2*Real.binEntropy ((a:ℝ)/(N+1)) + ((a:ℝ)/(N+1))* + ((L j:ℝ)*Real.log (latticeBall D).card + + 2*∑ f ∈ F (j+1), Real.log f.norm.natAbs) ≤ ε) : + let P := p.joint (fun _ => FinLaw.uniform (Fin (N+1))) + let u := fun v : Ω × Fin (N+1) => t v.1+v.2.val + (∑ j ∈ Finset.range (n+1), + P.cIf (fun v (f : F (j+1)) => residueCode f.val (z (u v))) + (fun v => incrementWord z (L j) (u v)) + (fun v (f : F j) => residueCode f.val (z (u v))) / L j) ≤ + Real.log (latticeBall D).card + n*ε := by + dsimp only + let P := p.joint (fun _ => FinLaw.uniform (Fin (N+1))) + let u := fun v : Ω × Fin (N+1) => t v.1+v.2.val + let Q := fun j => fun v (f : F j) => residueCode f.val (z (u v)) + let a := fun j => P.cHf (fun v => incrementWord z (L j) (u v)) (Q j) / L j + let b := fun j => P.cHf (fun v => incrementWord z (L j) (u v)) (Q (j+1)) / L j + have hnext (j : ℕ) (hj : j < n) : a (j+1) ≤ b j+ε := by + dsimp only [a,b,Q,u,P] + apply word_entropy_rate_monotone p t z hz (fun f : F (j+1) => f.val) + (fun f => hf _ _ f.property) (hL j (by omega)) (hL (j+1) (by omega)) + (hdiv j hj) (hN (j+1) (by omega)) hε + intro k hk + convert herr j hj k hk using 1 + rw [Finset.sum_coe_sort (F (j+1)) (fun f : GaussianInt => Real.log f.norm.natAbs)] + have hb : 0 ≤ b n := div_nonneg (P.cHf_nonneg _ _) (Nat.cast_nonneg _) + have hi (j : ℕ) : P.cIf (Q (j+1)) (fun v => incrementWord z (L j) (u v)) (Q j) / + L j = a j-b j := by + rw [P.cIf_refinement,sub_div] + intro v w hv + funext f + exact congrFun hv ⟨f.val,hF j f.property⟩ + have ht := finite_entropy_telescope n a b ε hnext hb + have ha : a 0 ≤ Real.log (latticeBall D).card := by + apply (div_le_iff₀ (show (0:ℝ) < L 0 by exact_mod_cast hL 0 (by omega))).mpr + have hh := (P.cHf_le_Hf (fun v => incrementWord z (L 0) (u v)) (Q 0)).trans + (boundedWord_entropy_le P u z hz (L 0)) + simpa only [mul_comm] using hh + change (∑ j ∈ Finset.range (n+1), P.cIf (Q (j+1)) + (fun v => incrementWord z (L j) (u v)) (Q j) / L j) ≤ _ + simp only [hi] + linarith only [ht,ha] + +noncomputable def TimeLaw.info {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} (P : TimeLaw) + (X : ℕ → α) (Y : ℕ → β) (O : ℕ → γ) : ℝ := + P.law.cIf (fun t => X t.val) (fun t => Y t.val) (fun t => O t.val) + +lemma TimeLaw.advance_info {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} (P : TimeLaw) (K : ForwardKernel) + (X : ℕ → α) (Y : ℕ → β) (O : ℕ → γ) : + (P.advance K).info X Y O=(P.law.joint (fun a => K.law a.val)).cIf + (fun v => X (v.1.val+v.2.val)) (fun v => Y (v.1.val+v.2.val)) + (fun v => O (v.1.val+v.2.val)) := by + unfold TimeLaw.info TimeLaw.advance + rw [FinLaw.cIf_map] + rfl + +lemma commonSchedule_smooth (z : ℕ → GaussianInt) (ns : List ℕ) (N : ℕ) : + commonSchedule z ns N=(commonSchedule z ns 0).then (smoothingKernel N) := by + simpa only [List.append_nil,commonSchedule,List.foldr_nil] using commonSchedule_append z ns [] N + +theorem schedule_information_telescope (z : ℕ → GaussianInt) {D : ℝ} + (hz : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (ns : List ℕ) (N n : ℕ) + (F : ℕ → Finset GaussianInt) (hF : ∀ j, F j⊆F (j+1)) + (hf : ∀ j, ∀ f∈F j, f≠0) (L : ℕ → ℕ) + (hL : ∀ j≤n, 0 residueCode f.val (z a)) (incrementWord z (L j)) + (fun a (f : F j) => residueCode f.val (z a)) / L j)≤ + Real.log (latticeBall D).card+n*ε := by + let Q := (TimeLaw.at 0).advance (commonSchedule z ns 0) + have h := common_law_information_telescope Q.law (fun t => t.val) z hz F hF hf L n N + hL hdiv hN hε herr + dsimp only + rw [commonSchedule_smooth,TimeLaw.advance_then] + simp only [TimeLaw.advance_info] + exact h + +theorem schedule_batch_information (s : SplitSieve) (hne : s.primes.Nonempty) + (z : ℕ → GaussianInt) (hz : Function.Injective z) (ha : ∀ t, z t∈s.avoiding) + (pre rest : List ℕ) {N b L n : ℕ} {D T τ A η δ E r : ℝ} + (hD : 1≤D) (hT : 5≤T) (hML : 1≤ s.meanLog) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) + (hpT : ∀ p∈s.primes, T≤(p:ℝ) ∧ (p:ℝ)≤2*T) + (band : EntropyBand s D pre 0 b δ) + (u : s.SignedIndex → ℝ) (coverage : CoverageDerivation s D N rest τ u η) + {κ : Type uKappa} (f : κ → GaussianInt) + (hOld : ((TimeLaw.at 0).advance (commonSchedule z pre 0)).law.Hf + (fun t i => residueCode (f i) (z t.val))≤E) + (hb : b≤ s.primes.card) (hn : 0 residueCode (s.signedFactorAt (s.selectedIndex hb σ π j)) (z a)) + (incrementWord z L) (fun a i => residueCode (f i) (z a)) / L := by + let P := (TimeLaw.at 0).advance (commonSchedule z pre 0) + let R := commonSchedule z rest 0 + have hH : (1-δ)*(b:ℝ)*s.meanLog≤ s.pointEntropy P.law (fun t => z t.val) b := by + rw [SplitSieve.pointEntropy_exact_start] + simpa only [Nat.zero_add] using band.sound hne z hz hD hT hs hpT hML 0 + have hc := coverage.sound hne z hz hD hT hs hpT hML + have hBad : (𝔼 i : s.SignedIndex, P.law.prob (fun ω => u i≤ + (((R.then (smoothingKernel N)).relativeResidueLaw s z ω.val i).lowResidues τ).card))≤η := by + let := s.signedIndex_nonempty hne + have hh := Finset.sum_le_sum (s := Finset.univ) (fun ω _ => + mul_le_mul_of_nonneg_left (hc ω.val) (P.law.nonneg ω)) + simp only [← Finset.sum_mul,P.law.sum_one,one_mul] at hh + rw [← commonSchedule_smooth] + unfold FinLaw.prob at hh ⊢ + rw [Finset.expect_eq_sum_div_card] + simp only [FinLaw.uniform,Finset.mul_sum,mul_ite,mul_zero] at hh + rw [Finset.sum_comm] at hh + convert hh using 1 + all_goals first | rfl | simp only [Finset.card_univ,div_eq_mul_inv,Finset.sum_mul,ite_mul,zero_mul] + obtain ⟨σ,π,hh⟩ := exists_batch_information s hne P.law (fun t => t.val) f R z hz ha + hb hn hL hD hτ hA hs u hu hshort hLN herr hH hOld hBad hnum + (by simpa only [R,commonSchedule_bound,Nat.add_zero] using hrate) + refine ⟨σ,π,?_⟩ + have heR : commonSchedule z rest N=R.then (smoothingKernel N) := commonSchedule_smooth z rest N + rw [commonSchedule_append,TimeLaw.advance_then,TimeLaw.advance_info,heR] + exact hh + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/KernelComposition.lean b/lean/OAI/NumberTheory/GaussianMoat/KernelComposition.lean new file mode 100644 index 0000000000000000000000000000000000000000..e87365e0be517d89982b283d8e6fa96bb9edc773 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/KernelComposition.lean @@ -0,0 +1,202 @@ +import OAI.NumberTheory.GaussianMoat.MultiscaleSchedule + +namespace OAI + +universe uOmega uAlpha uBeta + +namespace GaussianMoat +open scoped BigOperators Classical +namespace FinLaw +noncomputable def pure {Ω : Type uOmega} [Fintype Ω] (ω : Ω) : FinLaw Ω where + mass ν := if ν=ω then 1 else 0 + nonneg _ := by split_ifs <;> norm_num + sum_one := by simp + +lemma mix_pure {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] [Fintype α] (ω : Ω) (q : Ω → FinLaw α) : + (pure ω).mix q=q ω := by + ext a + simp [mix_mass,pure] + +lemma joint_pure_observation {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} [Fintype Ω] [Fintype α] [Fintype β] + (ω : Ω) (q : Ω → FinLaw α) (F : Ω × α → β) : + ((pure ω).joint q).map F=(q ω).map (fun a => F (ω,a)) := by + rw [joint_observation_fun,mix_pure] +end FinLaw + +noncomputable def TimeLaw.at (a : ℕ) : TimeLaw where + last := a + law := FinLaw.pure ⟨a,by omega⟩ + +lemma TimeLaw.at_advance (a : ℕ) (K : ForwardKernel) : + ((TimeLaw.at a).advance K).law= + (K.law a).map (fun t => (⟨a+t.val,by omega⟩ : Fin (a+K.bound+1))) := by + change ((FinLaw.pure (⟨a,by omega⟩ : Fin (a+1))).joint + (fun t => K.law t.val)).map (addOffsets a K.bound)=_ + rw [FinLaw.joint_pure_observation] + rfl + +lemma SplitSieve.pointEntropy_exact_start (s : SplitSieve) (K : ForwardKernel) + (z : ℕ → GaussianInt) (a b : ℕ) : + s.pointEntropy ((TimeLaw.at a).advance K).law (fun t => z t.val) b= + s.pointEntropy (K.law a) (fun t => z (a+t.val)) b := by + rw [TimeLaw.at_advance] + change s.pointEntropy ((K.law a).map + (fun t => (⟨a+t.val,by omega⟩ : Fin (a+K.bound+1)))) (fun t => z t.val) b = _ + rw [s.pointEntropy_map] + rfl + +theorem TimeLaw.advance_entropy_succ (P : TimeLaw) (K : ForwardKernel) (s : SplitSieve) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 1≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (b : ℕ) : + s.pointEntropy P.law (fun a => z a.val) b- + (Real.log 36+2*Real.log (D*(K.bound+1))) ≤ + s.pointEntropy (P.advance K).law (fun a => z a.val) b := by + let Q := P.law.joint (fun a => K.law a.val) + have hh := s.pointEntropy_shift Q (fun v => z v.1.val) + (fun v => z (v.1.val+v.2.val)) b + have hf := s.pointEntropy_joint_fst P.law (fun a => K.law a.val) (fun a => z a.val) b + change s.pointEntropy Q (fun v => z v.1.val) b=_ at hf + rw [hf] at hh + have he : s.pointEntropy (P.advance K).law (fun a => z a.val) b= + s.pointEntropy Q (fun v => z (v.1.val+v.2.val)) b := by + unfold TimeLaw.advance + rw [s.pointEntropy_map] + rfl + have hc : Q.Hf (fun v => z (v.1.val+v.2.val)-z v.1.val) ≤ + Real.log 36+2*Real.log (D*(K.bound+1)) := by + apply displacement_entropy_le + · exact one_le_mul_of_one_le_of_one_le hD (by exact_mod_cast Nat.le_add_left 1 K.bound) + · intro v + have hd := walk_pair_displacement z (by linarith only [hD]) hs + v.1.val (K.bound+1) v.2.val 0 (by omega) (by omega) + simpa only [Nat.add_zero,Nat.cast_add,Nat.cast_one] using hd + rw [he] + linarith only [hh,hc] + +theorem commonSchedule_subband_entropy (s : SplitSieve) (hne : s.primes.Nonempty) + (z : ℕ → GaussianInt) (hinj : Function.Injective z) + (pre post : List ℕ) (a N : ℕ) {D T U g e : ℝ} {l : ℕ} + (hD : 1≤D) (hT : 5≤T) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) + (hpT : ∀ p∈s.primes, T≤(p:ℝ) ∧ (p:ℝ)≤2*T) + (hg : 0 bandLength g U i.val)++post) N).law a) + (fun t => z (a+t.val)) (bandSize s g U l) := by + rw [← s.pointEntropy_exact_start] + rw [List.append_assoc,TimeLaw.advance_common_append,TimeLaw.advance_common_append, + TimeLaw.foldl_ofFn] + let P := pre.foldl (fun Q k => Q.step z k) (TimeLaw.at a) + have h1 := P.geometric_band_entropy s hne z hinj hD hT hs hpT hg hg1 hL hU + hlog hlarge hsize hdisp hgeom hcap + have h2 := (P.run z (bandLength g U) l).advance_entropy_succ + (commonSchedule z post N) s z hD hs (bandSize s g U l) + rw [commonSchedule_bound] at h2 + change _ ≤ s.pointEntropy ((P.run z (bandLength g U) l).advance (commonSchedule z post N)).law + (fun a => z a.val) (bandSize s g U l) + simp only [Nat.cast_add] at hcost h2 + nlinarith only [h1,h2,hcost] + +lemma ForwardKernel.ext_observe (K R : ForwardKernel) (hb : K.bound=R.bound) + (h : ∀ (a : ℕ) {α : Type} [Fintype α] (f : ℕ → α), + (K.law a).map (fun t => f (a+t.val))=(R.law a).map (fun t => f (a+t.val))) : K=R := by + cases K with | mk n p => + cases R with | mk m q => + dsimp only at hb + subst m + congr 1 + funext a + let f : ℕ → Fin (n+1) := fun t => ⟨min (t-a) n,by omega⟩ + have hh := h a f + have he : (fun t : Fin (n+1) => f (a+t.val))=id := by + funext t + apply Fin.ext + dsimp only [f,id_eq] + omega + simpa only [he,FinLaw.map_id] using hh + +lemma ForwardKernel.then_assoc (K R S : ForwardKernel) : + (K.then R).then S=K.then (R.then S) := by + apply ForwardKernel.ext_observe + · exact Nat.add_assoc _ _ _ + · intro a α _ f + rw [ForwardKernel.then_observe,ForwardKernel.then_observe] + have hl : ((K.then R).law a).mix + (fun t => (S.law (a+t.val)).map (fun u => f (a+t.val+u.val))) = + (K.law a).mix (fun t => (R.law (a+t.val)).mix + (fun u => (S.law (a+t.val+u.val)).map (fun v => f (a+t.val+u.val+v.val)))) := by + unfold ForwardKernel.then + rw [FinLaw.mix_map_left] + ext x + simp only [FinLaw.mix_mass,FinLaw.joint_mass,Fintype.sum_prod_type,Finset.mul_sum, + addOffsets,Nat.add_assoc,mul_assoc] + rw [hl] + congr 1 + funext t + exact (R.then_observe S (a+t.val) f).symm + +lemma FinLaw.map_pure {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] [Fintype α] + (ω : Ω) (f : Ω → α) : (FinLaw.pure ω).map f=FinLaw.pure (f ω) := by + ext a + simp only [FinLaw.map_mass,FinLaw.pure] + rw [Finset.sum_eq_single ω] + · simp only [ite_true,eq_comm] + · intro ν _ hν + simp [hν] + · simp + +lemma FinLaw.mix_pure_right {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] [Fintype α] + (p : FinLaw Ω) (f : Ω → α) : p.mix (fun ω => FinLaw.pure (f ω))=p.map f := by + ext a + simp only [FinLaw.mix_mass,FinLaw.pure,FinLaw.map_mass,mul_ite,mul_one,mul_zero] + apply Finset.sum_congr rfl + intro ω _ + simp only [eq_comm] + +lemma smoothingKernel_zero_law (a : ℕ) : + (smoothingKernel 0).law a=FinLaw.pure (0 : Fin 1) := by + change FinLaw.uniform (Fin 1)=FinLaw.pure (0 : Fin 1) + ext x + have hx : x=0 := Subsingleton.elim _ _ + simp [FinLaw.uniform,FinLaw.pure,hx] + +lemma ForwardKernel.then_zero (K : ForwardKernel) : K.then (smoothingKernel 0)=K := by + apply ForwardKernel.ext_observe + · exact Nat.add_zero _ + · intro a α _ f + rw [ForwardKernel.then_observe] + change (K.law a).mix (fun t => (FinLaw.uniform (Fin 1)).map + (fun u => f (a+t.val+u.val)))=_ + have hu : FinLaw.uniform (Fin 1)=FinLaw.pure (0 : Fin 1) := smoothingKernel_zero_law 0 + simp only [hu,FinLaw.map_pure,Fin.val_zero,Nat.add_zero] + exact FinLaw.mix_pure_right _ _ + +lemma ForwardKernel.zero_then (K : ForwardKernel) : (smoothingKernel 0).then K=K := by + apply ForwardKernel.ext_observe + · exact Nat.zero_add _ + · intro a α _ f + rw [ForwardKernel.then_observe] + change (FinLaw.uniform (Fin 1)).mix + (fun t => (K.law (a+t.val)).map (fun u => f (a+t.val+u.val)))=_ + have hu : FinLaw.uniform (Fin 1)=FinLaw.pure (0 : Fin 1) := smoothingKernel_zero_law 0 + rw [hu,FinLaw.mix_pure] + rfl + +lemma commonSchedule_append (z : ℕ → GaussianInt) (ns ms : List ℕ) (N : ℕ) : + commonSchedule z (ns++ms) N=(commonSchedule z ns 0).then (commonSchedule z ms N) := by + induction ns with + | nil => exact (ForwardKernel.zero_then _).symm + | cons n ns ih => + rw [List.cons_append,commonSchedule_cons,commonSchedule_cons,ih,ForwardKernel.then_assoc] + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/LatticeComponents.lean b/lean/OAI/NumberTheory/GaussianMoat/LatticeComponents.lean new file mode 100644 index 0000000000000000000000000000000000000000..b622abaff944f7103bfcc0c662a641643071f528 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/LatticeComponents.lean @@ -0,0 +1,557 @@ +import OAI.NumberTheory.GaussianMoat.Model + +namespace OAI + +namespace GaussianMoat + +def determinant (z w : GaussianInt) : ℤ := z.re * w.im - z.im * w.re + +theorem determinant_mul_left (a z w : GaussianInt) : + determinant (a * z) (a * w) = a.norm * determinant z w := by + simp only [determinant, Zsqrtd.re_mul, Zsqrtd.im_mul, Zsqrtd.norm] + ring + +theorem norm_dvd_determinant {a z w : GaussianInt} (hz : a ∣ z) (hw : a ∣ w) : + a.norm ∣ determinant z w := by + obtain ⟨u, rfl⟩ := hz + obtain ⟨v, rfl⟩ := hw + rw [determinant_mul_left] + exact dvd_mul_right _ _ + +theorem determinant_eq_zero_of_common_factor {a z w : GaussianInt} + (hz : a ∣ z) (hw : a ∣ w) (hsmall : |determinant z w| < a.norm) : + determinant z w = 0 := by + by_contra hne + have hpos : 0 < |determinant z w| := abs_pos.mpr hne + have hdiv : a.norm ∣ |determinant z w| := (dvd_abs _ _).mpr (norm_dvd_determinant hz hw) + have hle := Int.le_of_dvd hpos hdiv + omega + +structure SplitSieve where + primes : Finset ℕ + factor : ℕ → GaussianInt + prime_mem : ∀ p ∈ primes, Nat.Prime p + mod_four : ∀ p ∈ primes, p % 4 = 1 + factor_irreducible : ∀ p ∈ primes, Irreducible (factor p) + factor_norm : ∀ p ∈ primes, (factor p).norm = (p : ℤ) + +def SplitSieve.avoiding (s : SplitSieve) : Set GaussianInt := + {z | ∀ p ∈ s.primes, ¬s.factor p ∣ z ∧ ¬star (s.factor p) ∣ z} + +def FiniteSieveEndpoint : Prop := + ∀ D : ℝ, 1 ≤ D → ∃ s : SplitSieve, + ∀ z : ℕ → GaussianInt, (∀ t, z t ∈ s.avoiding) → Function.Injective z → + (∀ t, dist (z (t + 1) : ℂ) (z t : ℂ) ≤ D) → False + +theorem finite_box (N : ℤ) : + {z : GaussianInt | |z.re| ≤ N ∧ |z.im| ≤ N}.Finite := by + have hinj : Function.Injective (fun z : GaussianInt => (z.re, z.im)) := by + intro z w h + exact Zsqrtd.ext (congrArg Prod.fst h) (congrArg Prod.snd h) + have hf := (Set.finite_Icc (-N) N).prod (Set.finite_Icc (-N) N) + apply (hf.preimage hinj.injOn).subset + intro z hz + exact ⟨abs_le.mp hz.1, abs_le.mp hz.2⟩ + +theorem finite_norm_le (N : ℤ) : {z : GaussianInt | z.norm ≤ N}.Finite := by + apply (finite_box (|N| + 1)).subset + intro z hz + have heq : z.norm = z.re ^ 2 + z.im ^ 2 := by + simp only [Zsqrtd.norm] + ring + have hn : N ≤ |N| := le_abs_self N + have hn0 : 0 ≤ |N| := abs_nonneg N + have hx : z.re ^ 2 ≤ (|N| + 1)^2 := by + change z.norm ≤ N at hz + nlinarith [sq_nonneg z.im, sq_nonneg (|N| : ℤ)] + have hy : z.im ^ 2 ≤ (|N| + 1)^2 := by + change z.norm ≤ N at hz + nlinarith [sq_nonneg z.re, sq_nonneg (|N| : ℤ)] + exact ⟨abs_le_of_sq_le_sq hx (by omega), abs_le_of_sq_le_sq hy (by omega)⟩ + +theorem finite_irreducibles_divisible (a : GaussianInt) (ha : Irreducible a) : + {z : GaussianInt | Irreducible z ∧ a ∣ z}.Finite := by + apply (finite_norm_le a.norm).subset + intro z hz + exact (Zsqrtd.norm_eq_of_associated (by decide) (ha.associated_of_dvd hz.1 hz.2)).ge + +def SplitSieve.exceptions (s : SplitSieve) : Set GaussianInt := + {z | Irreducible z ∧ z ∉ s.avoiding} + +theorem SplitSieve.exceptions_finite (s : SplitSieve) : s.exceptions.Finite := by + have hfactor (p : ℕ) (hp : p ∈ s.primes) : + {z : GaussianInt | Irreducible z ∧ + (s.factor p ∣ z ∨ star (s.factor p) ∣ z)}.Finite := by + have hstar : Irreducible (star (s.factor p)) := + (MulEquiv.irreducible_iff (starRingAut : RingAut GaussianInt)).mpr + (s.factor_irreducible p hp) + simpa only [← Set.ofPred_or, and_or_left] using + (finite_irreducibles_divisible (s.factor p) (s.factor_irreducible p hp)).union + (finite_irreducibles_divisible (star (s.factor p)) hstar) + apply ((s.primes.finite_toSet).biUnion hfactor).subset + intro z hz + obtain ⟨hzprime, hzavoid⟩ := hz + simp only [SplitSieve.avoiding, Set.mem_ofPred_eq, not_forall, not_and, not_not] at hzavoid + obtain ⟨p, hp, hdiv⟩ := hzavoid + exact Set.mem_iUnion.mpr ⟨p, Set.mem_iUnion.mpr ⟨hp, ⟨hzprime, by tauto⟩⟩⟩ + +theorem SplitSieve.eventually_avoiding (s : SplitSieve) (z : ℕ → GaussianInt) + (hz : ∀ t, Irreducible (z t)) (hinj : Function.Injective z) : + ∃ N : ℕ, ∀ t, N ≤ t → z t ∈ s.avoiding := by + have hf : (z ⁻¹' s.exceptions).Finite := s.exceptions_finite.preimage hinj.injOn + obtain ⟨N, hN⟩ := hf.exists_le + refine ⟨N + 1, ?_⟩ + intro t ht + by_contra h + have ht' : t ∈ z ⁻¹' s.exceptions := ⟨hz t, h⟩ + have := hN t ht' + omega + +theorem main_of_finiteSieve (hsieve : FiniteSieveEndpoint) : MainEndpoint := by + intro D z hz hinj hstep + obtain ⟨s, hs⟩ := hsieve (max D 1) (le_max_right _ _) + obtain ⟨N, hN⟩ := s.eventually_avoiding z hz hinj + apply hs (fun t => z (N + t)) + · intro t + exact hN _ (Nat.le_add_right _ _) + · exact hinj.comp (fun _ _ h => Nat.add_left_cancel h) + · intro t + have hh : dist (z (N + (t + 1)) : ℂ) (z (N + t) : ℂ) ≤ D := by + simpa only [Nat.add_assoc] using hstep (N + t) + exact hh.trans (le_max_left _ _) + +theorem norm_square_complex (z : GaussianInt) : (z.norm : ℝ) = ‖(z : ℂ)‖ ^ 2 := by + rw [GaussianInt.intCast_real_norm, Complex.normSq_eq_norm_sq] + +theorem finite_dist_le (c : GaussianInt) (D : ℝ) : + {z : GaussianInt | dist (z : ℂ) (c : ℂ) ≤ D}.Finite := by + let N : ℤ := ⌈D + ‖(c : ℂ)‖⌉ + apply (finite_box N).subset + intro z hz + change dist (z : ℂ) (c : ℂ) ≤ D at hz + have htri : ‖(z : ℂ)‖ ≤ dist (z : ℂ) (c : ℂ) + ‖(c : ℂ)‖ := by + simpa only [sub_add_cancel, ← dist_eq_norm] using + norm_add_le ((z : ℂ) - (c : ℂ)) (c : ℂ) + have hnorm : ‖(z : ℂ)‖ ≤ (N : ℝ) := by + calc + ‖(z : ℂ)‖ ≤ dist (z : ℂ) (c : ℂ) + ‖(c : ℂ)‖ := htri + _ ≤ D + ‖(c : ℂ)‖ := add_le_add_left hz _ + _ ≤ (N : ℝ) := Int.le_ceil _ + constructor + · have h := (Complex.abs_re_le_norm (z : ℂ)).trans hnorm + rw [← GaussianInt.intCast_re, ← Int.cast_abs] at h + exact Int.cast_le.mp h + · have h := (Complex.abs_im_le_norm (z : ℂ)).trans hnorm + rw [← GaussianInt.intCast_im, ← Int.cast_abs] at h + exact Int.cast_le.mp h + +theorem norm_le_of_dvd {a z : GaussianInt} (hz : z ≠ 0) (h : a ∣ z) : + a.norm ≤ z.norm := by + obtain ⟨w, rfl⟩ := h + have hw : w ≠ 0 := by + intro h + apply hz + rw [h, mul_zero] + have hpos : 0 < w.norm := GaussianInt.norm_pos.mpr hw + rw [Zsqrtd.norm_mul] + nlinarith [GaussianInt.norm_nonneg a] + +theorem not_dvd_sub_of_dist_sq_lt {a z w : GaussianInt} (hzw : z ≠ w) + (hshort : dist (z : ℂ) (w : ℂ) ^ 2 < (a.norm : ℝ)) : ¬a ∣ z - w := by + intro hdiv + have hnorm := norm_le_of_dvd (sub_ne_zero.mpr hzw) hdiv + have hreal : (a.norm : ℝ) ≤ ((z - w).norm : ℝ) := by exact_mod_cast hnorm + rw [norm_square_complex (z - w), GaussianInt.toComplex_sub, ← dist_eq_norm] at hreal + exact (not_lt_of_ge hreal) hshort + +noncomputable def latticeGraph (A : Set GaussianInt) (D : ℝ) : SimpleGraph GaussianInt where + Adj z w := z ≠ w ∧ z ∈ A ∧ w ∈ A ∧ dist (z : ℂ) (w : ℂ) ≤ D + symm := by + constructor + intro z w h + exact ⟨h.1.symm, h.2.2.1, h.2.1, by simpa only [dist_comm] using h.2.2.2⟩ + loopless := by + constructor + intro z h + exact h.1 rfl + +theorem lattice_walk_mem {A : Set GaussianInt} {D : ℝ} {z w : GaussianInt} + (p : (latticeGraph A D).Walk z w) (hz : z ∈ A) (i : ℕ) : p.getVert i ∈ A := by + induction p generalizing i with + | nil => simpa using hz + | @cons u v w huv p ih => + cases i with + | zero => simpa using hz + | succ i => exact ih huv.2.2.1 i + +theorem lattice_walk_dist {A : Set GaussianInt} {D : ℝ} {z w : GaussianInt} + (p : (latticeGraph A D).Walk z w) : + dist (z : ℂ) (w : ℂ) ≤ (p.length : ℝ) * max D 0 := by + induction p with + | nil => simp + | @cons u v w huv p ih => + calc + dist (u : ℂ) (w : ℂ) ≤ dist (u : ℂ) (v : ℂ) + dist (v : ℂ) (w : ℂ) := + dist_triangle _ _ _ + _ ≤ D + (p.length : ℝ) * max D 0 := add_le_add huv.2.2.2 ih + _ ≤ ((p.cons huv).length : ℝ) * max D 0 := by + simp only [SimpleGraph.Walk.length_cons, Nat.cast_add, Nat.cast_one] + nlinarith [le_max_left D 0] + +@[ext] +structure LatticePrefix (A : Set GaussianInt) (D : ℝ) (root : GaussianInt) (n : ℕ) where + point : Fin (n + 1) → GaussianInt + mem : ∀ i, point i ∈ A + start : point 0 = root + injective : Function.Injective point + step : ∀ i j, j.val = i.val + 1 → dist (point j : ℂ) (point i : ℂ) ≤ D + +theorem LatticePrefix.dist_le {A : Set GaussianInt} {D : ℝ} {root : GaussianInt} + {n : ℕ} (p : LatticePrefix A D root n) (i : Fin (n + 1)) : + dist (p.point i : ℂ) (root : ℂ) ≤ (i.val : ℝ) * max D 0 := by + induction i using Fin.induction with + | zero => simp [p.start] + | succ i ih => + calc + dist (p.point i.succ : ℂ) (root : ℂ) ≤ + dist (p.point i.succ : ℂ) (p.point i.castSucc : ℂ) + + dist (p.point i.castSucc : ℂ) (root : ℂ) := dist_triangle _ _ _ + _ ≤ D + (i.val : ℝ) * max D 0 := add_le_add (p.step _ _ rfl) ih + _ ≤ (i.succ.val : ℝ) * max D 0 := by + simp only [Fin.val_succ, Nat.cast_add, Nat.cast_one] + nlinarith [le_max_left D 0] + +instance LatticePrefix.finite (A : Set GaussianInt) (D : ℝ) (root : GaussianInt) (n : ℕ) : + Finite (LatticePrefix A D root n) := by + let S : Set (Fin (n + 1) → GaussianInt) := + {f | ∀ i, dist (f i : ℂ) (root : ℂ) ≤ (n : ℝ) * max D 0} + have hS : S.Finite := Set.Finite.pi' (fun _ => finite_dist_le root ((n : ℝ) * max D 0)) + let := hS.to_subtype + let f : LatticePrefix A D root n → S := fun p => ⟨p.point, fun i => + (p.dist_le i).trans (mul_le_mul_of_nonneg_right + (by exact_mod_cast Nat.le_of_lt_succ i.isLt) (le_max_right D 0))⟩ + exact Finite.of_injective f (fun p q h => LatticePrefix.ext (congrArg Subtype.val h)) + +def LatticePrefix.restrict {A : Set GaussianInt} {D : ℝ} {root : GaussianInt} + {n m : ℕ} (h : n ≤ m) (p : LatticePrefix A D root m) : LatticePrefix A D root n where + point i := p.point (Fin.castLE (by omega) i) + mem i := p.mem _ + start := by simpa using p.start + injective := p.injective.comp (Fin.castLE_injective (by omega)) + step i j hij := p.step _ _ hij + +theorem infinite_component_has_walk {A : Set GaussianInt} {D : ℝ} {root : GaussianInt} + (hroot : root ∈ A) (hinfinite : {w | (latticeGraph A D).Reachable root w}.Infinite) : + ∃ z : ℕ → GaussianInt, (∀ n, z n ∈ A) ∧ Function.Injective z ∧ + ∀ n, dist (z (n + 1) : ℂ) (z n : ℂ) ≤ D := by + classical + have hne (n : ℕ) : Nonempty (LatticePrefix A D root n) := by + have hnot : ¬ {w | (latticeGraph A D).Reachable root w} ⊆ + {w | dist (w : ℂ) (root : ℂ) ≤ (n : ℝ) * max D 0} := by + intro h + exact hinfinite ((finite_dist_le root ((n : ℝ) * max D 0)).subset h) + obtain ⟨w, hw, hfar⟩ := Set.not_subset.mp hnot + apply hw.elim_path + intro path + let p := path.val + have hn : n ≤ p.length := by + by_contra hn + have hlen : (p.length : ℝ) ≤ (n : ℝ) := by exact_mod_cast (by omega : p.length ≤ n) + have hdist := (lattice_walk_dist p).trans + (mul_le_mul_of_nonneg_right hlen (le_max_right D 0)) + apply hfar + change dist (w : ℂ) (root : ℂ) ≤ (n : ℝ) * max D 0 + simpa only [dist_comm] using hdist + exact ⟨{ + point := fun i => p.getVert i.val + mem := fun i => lattice_walk_mem p hroot _ + start := p.getVert_zero + injective := fun i j h => Fin.ext (path.isPath.getVert_injOn + (show i.val ≤ p.length from (Nat.le_of_lt_succ i.isLt).trans hn) + (show j.val ≤ p.length from (Nat.le_of_lt_succ j.isLt).trans hn) h) + step := fun i j h => by + have hadj := p.adj_getVert_succ (i := i.val) (by omega) + simpa only [h, dist_comm] using hadj.2.2.2 + }⟩ + let (n : ℕ) : Nonempty (LatticePrefix A D root n) := hne n + obtain ⟨p, hp⟩ := exists_seq_forall_proj_of_forall_finite + (α := fun n => LatticePrefix A D root n) + (fun h => LatticePrefix.restrict h) + (by intro n a; apply LatticePrefix.ext; funext i; rfl) + (by intro i j k hij hjk a; apply LatticePrefix.ext; funext l; rfl) + (fun _ _ => Set.toFinite _) + let z : ℕ → GaussianInt := fun n => (p n).point (Fin.last n) + have hagree (n k : ℕ) (hnk : n ≤ k) : + (p k).point ⟨n, by omega⟩ = z n := by + simpa only [LatticePrefix.restrict, z, Fin.last, Fin.castLE] using + congrArg (fun a : LatticePrefix A D root n => a.point (Fin.last n)) (hp hnk) + refine ⟨z, fun n => (p n).mem _, ?_, ?_⟩ + · intro n m heq + have h := (hagree n (max n m) (le_max_left _ _)).trans + (heq.trans (hagree m (max n m) (le_max_right _ _)).symm) + exact congrArg Fin.val ((p (max n m)).injective h) + · intro n + have h := (p (n + 1)).step ⟨n, by omega⟩ (Fin.last (n + 1)) rfl + simpa only [hagree n (n + 1) (by omega)] using h + +theorem lattice_component_finite {A : Set GaussianInt} {D : ℝ} + (hno : ∀ z : ℕ → GaussianInt, (∀ n, z n ∈ A) → Function.Injective z → + (∀ n, dist (z (n + 1) : ℂ) (z n : ℂ) ≤ D) → False) + {root : GaussianInt} (hroot : root ∈ A) : + {w | (latticeGraph A D).Reachable root w}.Finite := by + by_contra h + obtain ⟨z, hz, hinj, hstep⟩ := infinite_component_has_walk hroot h + exact hno z hz hinj hstep + +def latticeTranslation {A : Set GaussianInt} {D : ℝ} (v : GaussianInt) + (hv : ∀ z ∈ A, z + v ∈ A) : + latticeGraph A D →g latticeGraph A D where + toFun z := z + v + map_rel' := by + intro z w h + refine ⟨fun he => h.1 (add_right_cancel he), hv z h.2.1, hv w h.2.2.1, ?_⟩ + simpa only [map_add, dist_add_right] using h.2.2.2 + +theorem eq_of_finite_component_period {A : Set GaussianInt} {D : ℝ} + {root x y v : GaussianInt} + (hfinite : {w | (latticeGraph A D).Reachable root w}.Finite) + (hx : (latticeGraph A D).Reachable root x) + (hy : (latticeGraph A D).Reachable root y) + (hv : ∀ z ∈ A, z + v ∈ A) (hxy : y = x + v) : x = y := by + classical + by_contra hne + have hv0 : v ≠ 0 := by intro h; apply hne; simpa [h] using hxy.symm + have hreach : (latticeGraph A D).Reachable x (x + v) := by + rw [← hxy] + exact hx.symm.trans hy + have hall (n : ℕ) : (latticeGraph A D).Reachable x (x + n • v) := by + induction n with + | zero => simp + | succ n ih => + have ht := ih.map (latticeTranslation v hv) + have hh := hreach.trans ht + change (latticeGraph A D).Reachable x ((x + n • v) + v) at hh + simpa only [succ_nsmul, add_assoc] using hh + have hinj : Function.Injective (fun n : ℕ => x + n • v) := by + intro n m h + have hh := add_left_cancel h + simp only [nsmul_eq_mul] at hh + exact Nat.cast_injective (mul_right_cancel₀ hv0 hh) + apply (Set.infinite_range_of_injective hinj) + exact hfinite.subset (by rintro _ ⟨n, rfl⟩; exact hx.trans (hall n)) + +def SplitSieve.period (s : SplitSieve) : ℕ := ∏ p ∈ s.primes, p + +theorem SplitSieve.period_pos (s : SplitSieve) : 0 < s.period := by + exact Finset.prod_pos (fun p hp => (s.prime_mem p hp).pos) + +theorem SplitSieve.factor_dvd_period (s : SplitSieve) {p : ℕ} (hp : p ∈ s.primes) : + s.factor p ∣ (s.period : GaussianInt) ∧ star (s.factor p) ∣ (s.period : GaussianInt) := by + have hn : (p : GaussianInt) = s.factor p * star (s.factor p) := by + rw [← Zsqrtd.norm_eq_mul_conj, s.factor_norm p hp] + simp + have hd : (p : GaussianInt) ∣ (s.period : GaussianInt) := by + have hh : p ∣ s.period := Finset.dvd_prod_of_mem (fun p : ℕ => p) hp + exact map_dvd (Nat.castRingHom GaussianInt) hh + constructor + · apply dvd_trans _ hd + rw [hn] + exact dvd_mul_right _ _ + · apply dvd_trans _ hd + rw [hn] + exact dvd_mul_left _ _ + +theorem SplitSieve.periodic (s : SplitSieve) (z v : GaussianInt) (hz : z ∈ s.avoiding) : + z + (s.period : GaussianInt) * v ∈ s.avoiding := by + intro p hp + have hd := s.factor_dvd_period hp + constructor + · intro h + apply (hz p hp).1 + have hh := dvd_sub h (dvd_mul_of_dvd_left hd.1 v) + simpa only [add_sub_cancel_right] using hh + · intro h + apply (hz p hp).2 + have hh := dvd_sub h (dvd_mul_of_dvd_left hd.2 v) + simpa only [add_sub_cancel_right] using hh + +def residue (Q : ℕ) (z : GaussianInt) : ZMod Q × ZMod Q := (z.re, z.im) + +theorem eq_add_period_of_residue_eq {Q : ℕ} {x y : GaussianInt} + (h : residue Q x = residue Q y) : + ∃ v : GaussianInt, y = x + (Q : GaussianInt) * v := by + have hx := (ZMod.intCast_eq_intCast_iff_dvd_sub x.re y.re Q).mp (congrArg Prod.fst h) + have hy := (ZMod.intCast_eq_intCast_iff_dvd_sub x.im y.im Q).mp (congrArg Prod.snd h) + obtain ⟨a, ha⟩ := hx + obtain ⟨b, hb⟩ := hy + refine ⟨⟨a, b⟩, ?_⟩ + ext <;> simp only [Zsqrtd.re_add, Zsqrtd.im_add, Zsqrtd.re_mul, Zsqrtd.im_mul, + Zsqrtd.re_natCast, Zsqrtd.im_natCast, zero_mul, mul_zero, add_zero] <;> omega + +theorem periodic_component_bound {A : Set GaussianInt} {D : ℝ} {Q : ℕ} (hQ : Q ≠ 0) + (hperiod : ∀ z ∈ A, ∀ v : GaussianInt, z + (Q : GaussianInt) * v ∈ A) + {root : GaussianInt} + (hfinite : {w | (latticeGraph A D).Reachable root w}.Finite) : + {w | (latticeGraph A D).Reachable root w}.ncard ≤ Q ^ 2 := by + classical + let : NeZero Q := ⟨hQ⟩ + let C := {w | (latticeGraph A D).Reachable root w} + have hinj : Set.InjOn (residue Q) C := by + intro x hx y hy heq + obtain ⟨v, hv⟩ := eq_add_period_of_residue_eq heq + exact eq_of_finite_component_period hfinite hx hy + (fun z hz => hperiod z hz v) hv + have hcard := Set.ncard_le_card ((residue Q) '' C) + rw [Set.InjOn.ncard_image hinj, Nat.card_prod, Nat.card_zmod, pow_two] at * + exact hcard + +def SplitSieve.boundary (s : SplitSieve) (D : ℝ) : Set GaussianInt := + {z | z ∈ s.avoiding ∧ ∃ e ∈ s.exceptions, dist (z : ℂ) (e : ℂ) ≤ D} + +theorem SplitSieve.boundary_finite (s : SplitSieve) (D : ℝ) : (s.boundary D).Finite := by + apply (s.exceptions_finite.biUnion (fun e _ => finite_dist_le e D)).subset + rintro z ⟨_, e, he, hd⟩ + exact Set.mem_iUnion.mpr ⟨e, Set.mem_iUnion.mpr ⟨he, hd⟩⟩ + +def SplitSieve.restored (s : SplitSieve) (D : ℝ) : Set GaussianInt := + s.exceptions ∪ ⋃ v ∈ s.boundary D, {w | (latticeGraph s.avoiding D).Reachable v w} + +theorem SplitSieve.restored_finite (s : SplitSieve) (D : ℝ) + (hf : ∀ r ∈ s.avoiding, {w | (latticeGraph s.avoiding D).Reachable r w}.Finite) : + (s.restored D).Finite := by + exact s.exceptions_finite.union ((s.boundary_finite D).biUnion (fun _ hv => hf _ hv.1)) + +theorem lattice_reachable_mem {A : Set GaussianInt} {D : ℝ} {r w : GaussianInt} + (hr : r ∈ A) (h : (latticeGraph A D).Reachable r w) : w ∈ A := by + apply h.elim + intro p + simpa only [p.getVert_length] using lattice_walk_mem p hr p.length + +theorem SplitSieve.restored_closed (s : SplitSieve) (D : ℝ) + {p q : PrimeVertex} (hp : p.val ∈ s.restored D) (hadj : (primeGraph D).Adj p q) : + q.val ∈ s.restored D := by + classical + by_cases hqa : q.val ∈ s.avoiding + · rcases hp with hpe | hp + · exact Or.inr (Set.mem_iUnion.mpr ⟨q.val, Set.mem_iUnion.mpr + ⟨⟨hqa, p.val, hpe, by simpa only [dist_comm] using hadj.2⟩, + SimpleGraph.Reachable.refl _⟩⟩) + · obtain ⟨v, hv⟩ := Set.mem_iUnion.mp hp + obtain ⟨hvb, hvp⟩ := Set.mem_iUnion.mp hv + have hpa := lattice_reachable_mem hvb.1 hvp + have hed : (latticeGraph s.avoiding D).Adj p.val q.val := + ⟨fun h => hadj.1 (Subtype.ext h), hpa, hqa, hadj.2⟩ + exact Or.inr (Set.mem_iUnion.mpr ⟨v, Set.mem_iUnion.mpr ⟨hvb, + hvp.trans hed.reachable⟩⟩) + · exact Or.inl ⟨q.property, hqa⟩ + +theorem prime_reachable_mem {D : ℝ} {T : Set GaussianInt} + (hclosed : ∀ p q : PrimeVertex, p.val ∈ T → (primeGraph D).Adj p q → q.val ∈ T) + {p q : PrimeVertex} (hp : p.val ∈ T) (h : (primeGraph D).Reachable p q) : q.val ∈ T := by + apply h.elim + intro w + clear h + induction w with + | nil => exact hp + | @cons a b c hab w ih => exact ih (hclosed a b hp hab) + +theorem lattice_component_eq_singleton {A : Set GaussianInt} {D : ℝ} {r : GaussianInt} + (hr : r ∉ A) : {w | (latticeGraph A D).Reachable r w} = {r} := by + ext w + constructor + · intro h + apply h.elim + intro p + cases p with + | nil => rfl + | cons hed p => exact (hr hed.2.1).elim + · intro h + rw [Set.mem_singleton_iff] at h + subst w + exact SimpleGraph.Reachable.refl _ + +theorem SplitSieve.component_subset (s : SplitSieve) (D : ℝ) (p : PrimeVertex) : + Subtype.val '' component D p ⊆ + {w | (latticeGraph s.avoiding D).Reachable p.val w} ∪ s.restored D := by + rintro _ ⟨q, hq, rfl⟩ + apply prime_reachable_mem (T := + {w | (latticeGraph s.avoiding D).Reachable p.val w} ∪ s.restored D) _ + (Or.inl (SimpleGraph.Reachable.refl _)) hq + intro a b ha hab + rcases ha with ha | ha + · by_cases hpa : p.val ∈ s.avoiding + · by_cases hba : b.val ∈ s.avoiding + · exact Or.inl (ha.trans (show (latticeGraph s.avoiding D).Adj a.val b.val from + ⟨fun hh => hab.1 (Subtype.ext hh), lattice_reachable_mem hpa ha, hba, hab.2⟩).reachable) + · exact Or.inr (Or.inl ⟨b.property, hba⟩) + · have hap : a.val = p.val := by + have hh : a.val ∈ {w | (latticeGraph s.avoiding D).Reachable p.val w} := ha + rw [lattice_component_eq_singleton hpa] at hh + exact hh + exact Or.inr (s.restored_closed D (Or.inl (by simpa only [hap] using + (show p.val ∈ s.exceptions from ⟨p.property, hpa⟩))) hab) + · exact Or.inr (s.restored_closed D ha hab) + +theorem prime_components_of_finiteSieve (hsieve : FiniteSieveEndpoint) (D : ℝ) : + ∃ B : ℕ, ∀ p : PrimeVertex, (component D p).Finite ∧ (component D p).ncard ≤ B := by + classical + obtain ⟨s, hs⟩ := hsieve (max D 1) (le_max_right _ _) + have hno : ∀ z : ℕ → GaussianInt, (∀ n, z n ∈ s.avoiding) → Function.Injective z → + (∀ n, dist (z (n + 1) : ℂ) (z n : ℂ) ≤ D) → False := by + intro z hz hinj hstep + exact hs z hz hinj (fun n => (hstep n).trans (le_max_left _ _)) + have hf (r : GaussianInt) : {w | (latticeGraph s.avoiding D).Reachable r w}.Finite := by + by_cases hr : r ∈ s.avoiding + · exact lattice_component_finite hno hr + · rw [lattice_component_eq_singleton hr] + exact Set.finite_singleton _ + have hK := s.restored_finite D (fun r _ => hf r) + refine ⟨s.period ^ 2 + (s.restored D).ncard, fun p => ?_⟩ + let C := {w | (latticeGraph s.avoiding D).Reachable p.val w} + have hC : C.ncard ≤ s.period ^ 2 := periodic_component_bound + (Nat.ne_of_gt s.period_pos) (fun z hz v => s.periodic z v hz) (hf p.val) + have hsubset := s.component_subset D p + have hfinimage := ((hf p.val).union hK).subset hsubset + have hfin : (component D p).Finite := by + apply (hfinimage.preimage Subtype.val_injective.injOn).subset + intro q hq + exact ⟨q, hq, rfl⟩ + refine ⟨hfin, ?_⟩ + have hle := (Set.ncard_le_ncard hsubset ((hf p.val).union hK)).trans + (Set.ncard_union_le C (s.restored D)) + rw [Set.InjOn.ncard_image Subtype.val_injective.injOn] at hle + exact hle.trans (Nat.add_le_add_right hC _) + +theorem finite_prime_walk_bound {D : ℝ} {B : ℕ} + (hB : ∀ p : PrimeVertex, (component D p).Finite ∧ (component D p).ncard ≤ B) + (n : ℕ) (z : Fin n → GaussianInt) (hz : ∀ i, Irreducible (z i)) + (hinj : Function.Injective z) + (hstep : ∀ i j : Fin n, j.val = i.val + 1 → dist (z j : ℂ) (z i : ℂ) ≤ D) : n ≤ B := by + classical + cases n with + | zero => exact Nat.zero_le _ + | succ n => + let f : Fin (n + 1) → PrimeVertex := fun i => ⟨z i, hz i⟩ + have hf : Function.Injective f := fun i j h => hinj (congrArg Subtype.val h) + have hreach (i : Fin (n + 1)) : (primeGraph D).Reachable (f 0) (f i) := by + induction i using Fin.induction with + | zero => exact SimpleGraph.Reachable.refl _ + | succ i ih => + apply ih.trans + apply SimpleGraph.Adj.reachable + exact ⟨fun h => (by have hh := congrArg Fin.val (hf h); simp at hh), + by simpa only [dist_comm] using hstep i.castSucc i.succ rfl⟩ + have hsubset : Set.range f ⊆ component D (f 0) := by + rintro _ ⟨i, rfl⟩ + exact hreach i + have hle := (Set.ncard_le_ncard hsubset (hB _).1).trans (hB _).2 + simpa only [Set.ncard_range_of_injective hf, Nat.card_fin] using hle + +theorem endpoints_of_finiteSieve (hsieve : FiniteSieveEndpoint) : MainEndpoint ∧ UniformEndpoint := by + refine ⟨main_of_finiteSieve hsieve, fun D => ?_⟩ + obtain ⟨B, hB⟩ := prime_components_of_finiteSieve hsieve D + exact ⟨B, hB, finite_prime_walk_bound hB⟩ + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/Main.lean b/lean/OAI/NumberTheory/GaussianMoat/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..73dd67edbe79d975971db5d996745e3905e15a5c --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/Main.lean @@ -0,0 +1,107 @@ +import OAI.NumberTheory.GaussianMoat.SieveSmoothing + +namespace OAI + +namespace GaussianMoat +open scoped BigOperators Classical +open Filter + +theorem exists_sieveCertificate (D : ℝ) (hD : 1≤D) : Nonempty (SieveCertificate D) := by + obtain ⟨a,δ,t,K,ha,ha1,haδ,ht,hK,hgap,hcost,hdensity⟩ := exists_separated_parameters + let c := topCoefficient a/4 + have hc : 0 Real.exp (m:ℝ)) atTop atTop := + Real.tendsto_exp_atTop.comp tendsto_natCast_atTop_atTop + obtain ⟨m,hbatch,hsmooth,hm⟩ := + (hbatch.and ((eventually_allBins_smoothing D W).and + (hexp.eventually (eventually_ge_atTop (max X0 (K*Real.log 2)))))).exists + have hmX : X0≤Real.exp (m:ℝ) := (le_max_left _ _).trans hm + have hmK : K*Real.log 2≤Real.exp (m:ℝ) := (le_max_right _ _).trans hm + have hbexists : ∀ w : ℕ, ∃ J : Finset ℕ, + t*((100:ℝ)^w*Real.exp m)≤J.card ∧ + (∀ i∈J, ∀ j∈J, i hsep w) + obtain ⟨hsmooth,htotal⟩ := hsmooth J (fun w hw j hj => (hJ w hw j hj).2) + refine ⟨{ + schedule := commonBlocks a m W J + smoothing := windowSmoothing W m + batches := binEnum U + last := U.card-1 + lengths := fun n => batchWordLength (binEnum U n) + rates := fun n => c/(10000000*Real.log ((2:ℝ)^(binEnum U n))) + error := Real.exp (-Real.exp m) + batch := ?_ + divides := ?_ + nonneg := (Real.exp_pos _).le + smooth := ?_ + excess := ?_ + }⟩ + · intro n hn + apply Classical.choice + have hn' : n hbounds w) (hsep w) _ hjw _) + have hh := precedingFactors_enum_cost U hK hn' hUsep + have hm := mul_le_mul_of_nonneg_right hcost (show (0:ℝ)≤2^(binEnum U n) by positivity) + exact hh.trans (by convert hm using 1; ring) + · intro n hn + exact batchWordLength_dvd (binEnum_strictMono U (Nat.lt_succ_self n) (by omega)).le + · intro n hn a ha' + rw [hUlast,precedingFactors_enum_all] + exact hsmooth _ (binEnum_mem U (by omega)) _ (binEnum_mem U (by omega)) a ha' + · rw [hUlast,binEnum_sum U (fun j => c/(10000000*Real.log ((2:ℝ)^j)))] + have hsum := allBins_rate J (Real.exp_pos (m:ℝ)) hc hJ (fun w _ => hdense w) + have hcost' : ((U.card-1:ℕ):ℝ)*Real.exp (-Real.exp m)≤1 := + (mul_le_mul_of_nonneg_right (by exact_mod_cast Nat.sub_le U.card 1 : ((U.card-1:ℕ):ℝ)≤U.card) + (Real.exp_nonneg _)).trans htotal + have hh := hWrate.trans_le hsum + linarith only [hcost',hh] + +theorem finiteSieveEndpoint_proved : FiniteSieveEndpoint := + finiteSieve_of_certificates exists_sieveCertificate + +theorem fullMain : MainEndpoint ∧ UniformEndpoint := + endpoints_of_finiteSieve finiteSieveEndpoint_proved + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/Model.lean b/lean/OAI/NumberTheory/GaussianMoat/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d6562d48218e51908c1aa1a155da51acc1caf45 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/Model.lean @@ -0,0 +1,38 @@ +import Mathlib + +namespace OAI + +namespace GaussianMoat + +abbrev PrimeVertex := {z : GaussianInt // Irreducible z} + +noncomputable def primeGraph (D : ℝ) : SimpleGraph PrimeVertex where + Adj p q := p ≠ q ∧ dist (p.val : ℂ) (q.val : ℂ) ≤ D + symm := by + constructor + intro p q h + exact ⟨h.1.symm, by simpa only [dist_comm] using h.2⟩ + loopless := by + constructor + intro p h + exact h.1 rfl + +def component (D : ℝ) (p : PrimeVertex) : Set PrimeVertex := + {q | (primeGraph D).Reachable p q} + +def MainEndpoint : Prop := + ∀ (D : ℝ) (z : ℕ → GaussianInt), + (∀ t, Irreducible (z t)) → Function.Injective z → + (∀ t, dist (z (t + 1) : ℂ) (z t : ℂ) ≤ D) → False + +def UniformEndpoint : Prop := + ∀ D : ℝ, ∃ B : ℕ, + (∀ p : PrimeVertex, (component D p).Finite ∧ (component D p).ncard ≤ B) ∧ + (∀ (n : ℕ) (z : Fin n → GaussianInt), + (∀ i, Irreducible (z i)) → Function.Injective z → + (∀ i j : Fin n, j.val = i.val + 1 → dist (z j : ℂ) (z i : ℂ) ≤ D) → + n ≤ B) + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/MultiscaleSchedule.lean b/lean/OAI/NumberTheory/GaussianMoat/MultiscaleSchedule.lean new file mode 100644 index 0000000000000000000000000000000000000000..268cd94a139ee4fd96a535ffda508f832d847457 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/MultiscaleSchedule.lean @@ -0,0 +1,423 @@ +import OAI.NumberTheory.GaussianMoat.Information + +namespace OAI + +universe uOmega uAlpha + +namespace GaussianMoat +open scoped BigOperators Classical + +structure EnrichmentMargins (s : SplitSieve) (D g : ℝ) (n b q : ℕ) : Prop where + length_pos : 1 ≤ n + output_pos : 0 < b + decreases : b < q + input_cap : q ≤ s.primes.card + ratio : (b:ℝ) ≤ g*q + log_pos : 0 < Real.log n-Real.log 18 + rounding : s.meanLog ≤ g*(Real.log n-Real.log 18) + large : 5120*s.meanLog ≤ g^4*(Real.log n-Real.log 18) + output_cost : (b:ℝ)*s.meanLog ≤ g*(Real.log n-Real.log 18) + lattice_cost : Real.log 16+Real.log (max D ((latticeBall (4*D)).card:ℝ)) ≤ + g*(Real.log n-Real.log 18) + geometry_cap : 2*(2*Real.log n+Real.log 16+2*Real.log D) ≤ s.primes.card*s.meanLog + displacement_cost : 2*(Real.log 36+2*Real.log (D*n)) ≤ 8*g*q*s.meanLog + +theorem TimeLaw.geometric_step_deficit (P : TimeLaw) (s : SplitSieve) + (hne : s.primes.Nonempty) (z : ℕ → GaussianInt) (hinj : Function.Injective z) + {D T g e : ℝ} (hD : 1 ≤ D) (hT : 5 ≤ T) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) + (hpT : ∀ p ∈ s.primes, T ≤ (p:ℝ) ∧ (p:ℝ) ≤ 2*T) + (hg : 0 < g) (hg1 : g ≤ 1/100) (hL : 1 ≤ s.meanLog) {n b q : ℕ} + (hm : EnrichmentMargins s D g n b q) + (hE : (1-e)*(q:ℝ)*s.meanLog ≤ s.pointEntropy P.law (fun a => z a.val) q) : + (1-e/2-20*g)*(b:ℝ)*s.meanLog ≤ + s.pointEntropy (P.step z n).law (fun a => z a.val) b := by + apply P.step_deficit s z hD hstep hm.length_pos hm.output_pos hm.decreases + hm.input_cap hg.le hg1 (by linarith only [hL]) hm.ratio ?_ hE hm.displacement_cost + intro a + obtain ⟨hb,hh⟩ := s.walk_fresh_lower hne (fun t => z (a.val+t)) hm.length_pos + (shifted_walk_injective z hinj a.val) hD hT + (fun t _ => by simpa only [Nat.add_assoc] using hstep (a.val+t)) hpT hg hg1 hL + hm.log_pos hm.rounding hm.large hm.output_cost hm.lattice_cost hm.geometry_cap + exact hh + +lemma SplitSieve.pointEntropy_nonneg {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (p : FinLaw Ω) (Z : Ω → GaussianInt) (b : ℕ) : + 0 ≤ s.pointEntropy p Z b := by + unfold pointEntropy FinLaw.signedEntropy + exact Finset.expect_nonneg (fun _ _ => p.orderedEntropy_nonneg _ _) + +noncomputable def TimeLaw.run (P : TimeLaw) (z : ℕ → GaussianInt) (n : ℕ → ℕ) : ℕ → TimeLaw + | 0 => P + | j+1 => (P.run z n j).step z (n j) + +@[simp] lemma TimeLaw.run_zero (P : TimeLaw) (z : ℕ → GaussianInt) (n : ℕ → ℕ) : + P.run z n 0=P := rfl +@[simp] lemma TimeLaw.run_succ (P : TimeLaw) (z : ℕ → GaussianInt) (n : ℕ → ℕ) (j : ℕ) : + P.run z n (j+1)=(P.run z n j).step z (n j) := rfl + +theorem TimeLaw.run_entropy (P : TimeLaw) (s : SplitSieve) (hne : s.primes.Nonempty) + (z : ℕ → GaussianInt) (hinj : Function.Injective z) {D T g : ℝ} + (hD : 1 ≤ D) (hT : 5 ≤ T) (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) + (hpT : ∀ p ∈ s.primes, T ≤ (p:ℝ) ∧ (p:ℝ) ≤ 2*T) + (hg : 0 < g) (hg1 : g ≤ 1/100) (hL : 1 ≤ s.meanLog) + (n q : ℕ → ℕ) (l : ℕ) (hm : ∀ j z a.val) (q l) := by + induction l with + | zero => + have hh := s.pointEntropy_nonneg P.law (fun a => z a.val) (q 0) + simp only [pow_zero,sub_self,zero_sub,TimeLaw.run_zero] + have hneg : -(40*g)*(q 0:ℝ)*s.meanLog ≤ 0 := by + apply mul_nonpos_of_nonpos_of_nonneg + · exact mul_nonpos_of_nonpos_of_nonneg (by linarith only [hg]) (Nat.cast_nonneg (q 0)) + · linarith only [hL] + exact hneg.trans hh + | succ l ih => + have hi := ih (fun j hj => hm j (by omega)) + have hh := (P.run z n l).geometric_step_deficit s hne z hinj hD hT hstep hpT + hg hg1 hL (hm l (by omega)) (e := (1/2:ℝ)^l+40*g) (by + convert hi using 1; ring) + rw [TimeLaw.run_succ] + convert hh using 1; ring + +theorem TimeLaw.advance_entropy (P : TimeLaw) (K : ForwardKernel) (s : SplitSieve) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 1 ≤ D) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) (hK : 1 ≤ K.bound) (b : ℕ) : + s.pointEntropy P.law (fun a => z a.val) b - + (Real.log 36+2*Real.log (D*K.bound)) ≤ + s.pointEntropy (P.advance K).law (fun a => z a.val) b := by + let Q := P.law.joint (fun a => K.law a.val) + have hh := s.pointEntropy_shift Q (fun v => z v.1.val) + (fun v => z (v.1.val+v.2.val)) b + have hfst := s.pointEntropy_joint_fst P.law (fun a => K.law a.val) (fun a => z a.val) b + change s.pointEntropy Q (fun v => z v.1.val) b = _ at hfst + rw [hfst] at hh + have he : s.pointEntropy (P.advance K).law (fun a => z a.val) b = + s.pointEntropy Q (fun v => z (v.1.val+v.2.val)) b := by + unfold TimeLaw.advance + rw [s.pointEntropy_map] + rfl + rw [he] + have hc := P.advance_displacement_entropy K z hD hstep hK + linarith only [hh,hc] + +theorem TimeLaw.run_future_entropy (P : TimeLaw) (K : ForwardKernel) (s : SplitSieve) + (hne : s.primes.Nonempty) (z : ℕ → GaussianInt) (hinj : Function.Injective z) + {D T g : ℝ} (hD : 1 ≤ D) (hT : 5 ≤ T) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) + (hpT : ∀ p ∈ s.primes, T ≤ (p:ℝ) ∧ (p:ℝ) ≤ 2*T) + (hg : 0 < g) (hg1 : g ≤ 1/100) (hL : 1 ≤ s.meanLog) + (n q : ℕ → ℕ) (l : ℕ) (hm : ∀ j z a.val) (q l) := by + have h1 := P.run_entropy s hne z hinj hD hT hstep hpT hg hg1 hL n q l hm + have h2 := (P.run z n l).advance_entropy K s z hD hstep hK (q l) + nlinarith only [h1,h2,hcost] + +noncomputable def TimeLaw.observe {α : Type uAlpha} [Fintype α] (P : TimeLaw) (f : ℕ → α) : FinLaw α := + P.law.map (fun t => f t.val) + +lemma TimeLaw.ext_observe (P Q : TimeLaw) (hl : P.last=Q.last) + (h : ∀ {α : Type} [Fintype α] (f : ℕ → α), P.observe f=Q.observe f) : P=Q := by + cases P with | mk n p => + cases Q with | mk m q => + dsimp only at hl + subst m + congr 1 + let f : ℕ → Fin (n+1) := fun t => ⟨min t n,by omega⟩ + have hh := h f + have he : (fun t : Fin (n+1) => f t.val)=id := by + funext t + apply Fin.ext + exact Nat.min_eq_left (by omega) + unfold observe at hh + simpa only [he,FinLaw.map_id] using hh + +lemma TimeLaw.observe_advance {α : Type uAlpha} [Fintype α] + (P : TimeLaw) (K : ForwardKernel) (f : ℕ → α) : + (P.advance K).observe f=P.law.mix (fun a => (K.law a.val).map (fun t => f (a.val+t.val))) := by + unfold observe advance + rw [FinLaw.map_comp,FinLaw.joint_observation_fun] + rfl + +lemma ForwardKernel.then_observe {α : Type uAlpha} [Fintype α] + (K R : ForwardKernel) (a : ℕ) (f : ℕ → α) : + ((K.then R).law a).map (fun t => f (a+t.val))= + (K.law a).mix (fun t => (R.law (a+t.val)).map (fun u => f (a+t.val+u.val))) := by + unfold ForwardKernel.then + rw [FinLaw.map_comp,FinLaw.joint_observation_fun] + congr 1 + funext t + congr 1 + funext u + simp only [Function.comp_def,addOffsets,Nat.add_assoc] + +lemma TimeLaw.advance_then (P : TimeLaw) (K R : ForwardKernel) : + P.advance (K.then R)=(P.advance K).advance R := by + apply TimeLaw.ext_observe + · exact (Nat.add_assoc _ _ _).symm + · intro α _ f + rw [TimeLaw.observe_advance,TimeLaw.observe_advance] + change P.law.mix _ = (((P.law.joint (fun a => K.law a.val)).map + (addOffsets P.last K.bound))).mix (fun a : Fin (P.last+K.bound+1) => + (R.law a.val).map (fun t => f (a.val+t.val))) + rw [FinLaw.mix_map_left] + have hj := FinLaw.joint_observation (P.law) (fun a => K.law a.val) + (fun a t => (a,t)) + clear hj + have hmix : ((P.law.joint (fun a => K.law a.val))).mix + (fun v => (R.law (v.1.val+v.2.val)).map (fun u => f (v.1.val+v.2.val+u.val))) = + P.law.mix (fun a => (K.law a.val).mix + (fun t => (R.law (a.val+t.val)).map (fun u => f (a.val+t.val+u.val)))) := by + ext x + simp only [FinLaw.mix_mass,FinLaw.joint_mass,Fintype.sum_prod_type,Finset.mul_sum,mul_assoc] + change P.law.mix _ = (P.law.joint (fun a => K.law a.val)).mix + (fun v => (R.law (v.1.val+v.2.val)).map (fun u => f (v.1.val+v.2.val+u.val))) + rw [hmix] + congr 1 + funext a + exact K.then_observe R a.val f + +lemma TimeLaw.advance_common_cons (P : TimeLaw) (z : ℕ → GaussianInt) + (n : ℕ) (ns : List ℕ) (N : ℕ) : + P.advance (commonSchedule z (n::ns) N)=(P.step z n).advance (commonSchedule z ns N) := by + rw [commonSchedule_cons,TimeLaw.advance_then,TimeLaw.advance_difference] + +lemma TimeLaw.advance_common_append (P : TimeLaw) (z : ℕ → GaussianInt) + (ns ms : List ℕ) (N : ℕ) : + P.advance (commonSchedule z (ns++ms) N)= + (ns.foldl (fun Q k => Q.step z k) P).advance (commonSchedule z ms N) := by + induction ns generalizing P with + | nil => rfl + | cons k ks hk => + rw [List.cons_append,TimeLaw.advance_common_cons,hk,List.foldl_cons] + +lemma TimeLaw.foldl_ofFn (P : TimeLaw) (z : ℕ → GaussianInt) + (n : ℕ → ℕ) (l : ℕ) : + (List.ofFn (fun i : Fin l => n i.val)).foldl (fun Q k => Q.step z k) P=P.run z n l := by + induction l with + | zero => rfl + | succ l hl => + rw [List.ofFn_succ_last,List.foldl_append,List.foldl_cons,List.foldl_nil] + simp only [Fin.val_castSucc,Fin.val_last] + rw [hl,TimeLaw.run_succ] + +lemma TimeLaw.run_common (P : TimeLaw) (z : ℕ → GaussianInt) + (n : ℕ → ℕ) (l N : ℕ) : + P.advance (commonSchedule z (List.ofFn (fun i : Fin l => n i.val)) N)= + (P.run z n l).advance (smoothingKernel N) := by + have h := P.advance_common_append z (List.ofFn (fun i : Fin l => n i.val)) [] N + simpa only [List.append_nil,TimeLaw.foldl_ofFn,commonSchedule,List.foldr_nil] using h + +lemma log_floor_exp {x : ℝ} (hx : 2 ≤ x) : + 1 ≤ ⌊Real.exp x⌋₊ ∧ x-1 ≤ Real.log (⌊Real.exp x⌋₊:ℝ) ∧ + Real.log (⌊Real.exp x⌋₊:ℝ) ≤ x := by + have he : 2 ≤ Real.exp x := by linarith only [Real.add_one_le_exp x,hx] + have hn : 1 ≤ ⌊Real.exp x⌋₊ := Nat.floor_pos.mpr (by linarith only [he]) + have hnp : (0:ℝ)<⌊Real.exp x⌋₊ := by exact_mod_cast hn + have hlow : Real.exp x/2 ≤ (⌊Real.exp x⌋₊:ℝ) := by + have h := Nat.lt_floor_add_one (Real.exp x) + linarith only [he,h] + have hlo := Real.log_le_log (div_pos (Real.exp_pos x) (by norm_num : (0:ℝ)<2)) hlow + rw [Real.log_div (Real.exp_ne_zero x) (by norm_num : (2:ℝ)≠0),Real.log_exp] at hlo + have hl2 : Real.log 2 ≤ 1 := by + have h := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith only [h] + have hhi := Real.log_le_log hnp (Nat.floor_le (Real.exp_nonneg x)) + rw [Real.log_exp] at hhi + exact ⟨hn,by linarith only [hlo,hl2],hhi⟩ + +theorem EnrichmentMargins.from_scale (s : SplitSieve) {D U g : ℝ} + (hD : 1 ≤ D) (hg : 0 < g) (hg1 : g ≤ 1/200) (hL : 1 ≤ s.meanLog) + (hU : 0 < U) + (hlog : 2*(1+Real.log 18) ≤ g*U) + (hlarge : 640*s.meanLog ≤ g^5*U) + (hsize : Real.log 16+Real.log (max D ((latticeBall (4*D)).card:ℝ)) ≤ g^2*U) + (hdisp : 4*Real.log D+2*Real.log 36 ≤ 4*g*U) + (hgeom : 2*Real.log 16+4*Real.log D ≤ U/4) + (hcap : ⌊U/s.meanLog⌋₊ ≤ s.primes.card) : + EnrichmentMargins s D (2*g) ⌊Real.exp (g*U)⌋₊ + ⌊g^2*U/s.meanLog⌋₊ ⌊U/s.meanLog⌋₊ := by + let L := s.meanLog + let n := ⌊Real.exp (g*U)⌋₊ + let q := ⌊U/L⌋₊ + let b := ⌊g^2*U/L⌋₊ + have hLp : 0 < L := by dsimp [L]; linarith only [hL] + have hg_le : g ≤ 1 := by linarith only [hg1] + have hg2 : g^2 ≤ 1 := pow_le_one₀ hg.le hg_le + have hg3 : g^3 ≤ 1 := pow_le_one₀ hg.le hg_le + have h52 : g^5*U ≤ g^2*U := by + have hpow : g^5=g^2*g^3 := by ring + rw [hpow] + nlinarith only [hg3,mul_nonneg (sq_nonneg g) hU.le] + have h2U : g^2*U ≤ U := by nlinarith only [hg2,hU] + have hLU : L ≤ U/2 := by + change 640*L ≤ g^5*U at hlarge + linarith only [hlarge,h52,h2U,hLp] + have hbL : L ≤ g^2*U := by + change 640*L ≤ g^5*U at hlarge + linarith only [hlarge,h52,hLp] + have he2 : 2 ≤ g*U := by + have hh := Real.log_nonneg (by norm_num : (1:ℝ)≤18) + linarith only [hh,hlog] + obtain ⟨hn,hnlo,hnhi⟩ := log_floor_exp he2 + have hnlo' : g*U/2 ≤ Real.log n-Real.log 18 := by + change g*U-1 ≤ Real.log n at hnlo + linarith only [hnlo,hlog] + have hu : 0 < Real.log n-Real.log 18 := + lt_of_lt_of_le (div_pos (mul_pos hg hU) (by norm_num)) hnlo' + have hqL : U-L ≤ (q:ℝ)*L := by + have hf := Nat.lt_floor_add_one (U/L) + have hm := mul_lt_mul_of_pos_right hf hLp + rw [div_mul_cancel₀ _ hLp.ne',add_mul,one_mul] at hm + linarith only [hm] + have hqU : U/2 ≤ (q:ℝ)*L := by linarith only [hqL,hLU] + have hqpos : 0 < q := by + have : (0:ℝ) z a.val) (bandSize s g U l) := by + have hm := geometric_band_margins s hD hg hg1 hL hU hlog hlarge hsize hdisp hgeom hcap + have hh := P.run_entropy s hne z hinj hD hT hs hpT (by positivity : 0<2*g) + (by linarith only [hg1] : 2*g≤1/100) hL (bandLength g U) (bandSize s g U) l hm + convert hh using 1; ring + +lemma commonSchedule_log_bound (z : ℕ → GaussianInt) (ns : List ℕ) (N : ℕ) {x : ℝ} + (hns : ∀ n∈ns, (n:ℝ)≤Real.exp x) (hN : (N:ℝ)≤Real.exp x) + (hlen : (ns.length+2:ℝ)≤Real.exp x) : + Real.log (1+(commonSchedule z ns N).bound:ℝ) ≤ 2*x := by + have hsum : (ns.sum:ℝ)≤(ns.length:ℝ)*Real.exp x := by + induction ns with + | nil => simp + | cons n ns ih => + have hn := hns n (by simp) + have ht := ih (fun k hk => hns k (by simp [hk])) + (by simp only [List.length_cons,Nat.cast_add,Nat.cast_one] at hlen; linarith only [hlen]) + simp only [List.sum_cons,List.length_cons,Nat.cast_add,Nat.cast_one] + nlinarith only [hn,ht] + have hx : (1:ℝ)≤Real.exp x := by + have hlen0 : (0:ℝ)≤ns.length := Nat.cast_nonneg _ + linarith only [hlen,hlen0] + have hall : (1+(commonSchedule z ns N).bound:ℝ)≤Real.exp (2*x) := by + rw [commonSchedule_bound,Nat.cast_add] + have hm := mul_le_mul_of_nonneg_right hlen (Real.exp_nonneg x) + rw [show 2*x=x+x by ring,Real.exp_add] + nlinarith only [hsum,hN,hm,hx] + have hlog := Real.log_le_log (by positivity : (0:ℝ)<1+(commonSchedule z ns N).bound) hall + simpa only [Real.log_exp] using hlog + +lemma suffix_entropy_cost {D g V L : ℝ} {q S : ℕ} + (hD : 1≤D) (hg : 0≤g) (hS : 1≤S) + (hq : V/2≤(q:ℝ)*L) (hlog : Real.log (1+(S:ℝ))≤2*g*V) + (hconst : Real.log 36+2*Real.log D≤g*V) : + Real.log 36+2*Real.log (D*S)≤10*g*q*L := by + have hSp : (0:ℝ) X i ω) C ≤ ∑ i, p.cHf (X i) C := by + let Y := fun ω i => (⟨i,X i ω⟩ : Σ i, G i) + have he : p.cHf (fun ω i => X i ω) C = p.cHf Y C := by + apply p.cHf_congr_fibers _ _ _ _ + · intro ω ν + constructor + · intro h; funext i; exact congrArg (Sigma.mk i) (congrFun h i) + · intro h; funext i; exact Sigma.mk.inj_iff.mp (congrFun h i) |>.2 |> eq_of_heq + · intro ω ν; rfl + rw [he] + apply (p.cHf_fintype_subadd Y C).trans + apply Finset.sum_le_sum + intro i _ + apply le_of_eq + apply p.cHf_congr_fibers _ _ _ _ + · intro ω ν + exact ⟨fun h => eq_of_heq (Sigma.mk.inj_iff.mp h).2,fun h => congrArg (Sigma.mk i) h⟩ + · intro ω ν; rfl + +lemma joint_passing_entropy {ι : Type uIota} {O : Type uOutput} {Γ : Type uCapitalGamma} [Fintype ι] [Fintype O] [Fintype Γ] + (G : ι → Type uGroup) [∀ i, Fintype (G i)] + (p : FinLaw (O × (∀ i, G i))) (q : O × (∀ i, G i) → FinLaw Γ) + (hit : (i : ι) → Γ → G i → Prop) (n : ℕ) + (htrue : ∀ a, p a≠0 → ∀ v, q a v≠0 → ∀ i, ¬ hit i v (a.2 i)) : + (p.joint (fun a => (q a).iid n)).cHf (fun v => v.1.2) + (fun v => (v.1.1,v.2)) ≤ + ∑ a, p a*(∑ i, ∑ v, (q a).iid n v*Real.log (passingList (hit i) n v).card) := by + let P := p.joint (fun a => (q a).iid n) + let C := fun v : (O × (∀ i, G i)) × (Fin n → Γ) => (v.1.1,v.2) + have hcoordinate (i : ι) : + P.cHf (fun v => v.1.2 i) C ≤ ∑ v, P v*Real.log (passingList (hit i) n v.2).card := by + have hh := P.conditional_passing_support (fun v => v.1.2 i) C + (fun c x => ∃ j, hit i (c.2 j) x) (by + intro v hv + have hm : p v.1≠0 ∧ (q v.1).iid n v.2≠0 := mul_ne_zero_iff.mp hv + have hx := (q v.1).passingList_true (hit i) (v.1.2 i) + (fun a ha => htrue v.1 hm.1 a ha i) n v.2 hm.2 + simpa only [passingList,Finset.mem_filter,Finset.mem_univ,true_and,not_exists] using hx) + have hh' : P.cHf (fun v => v.1.2 i) C ≤ + ∑ c, (P.map C) c * Real.log (passingList (hit i) n c.2).card := by + convert hh using 1 + apply Finset.sum_congr rfl + intro c _ + simp only [passingList,not_exists] + rw [expect_map] at hh' + exact hh' + have hs := P.cHf_dpi_subadd G (fun i v => v.1.2 i) C + apply hs.trans + apply (Finset.sum_le_sum (s := Finset.univ) (fun i _ => hcoordinate i)).trans + apply le_of_eq + rw [Finset.sum_comm] + simp only [Finset.mul_sum,← mul_assoc] + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_comm] + simp only [P,joint_mass] + +theorem passing_information_lower {ι : Type uIota} {O : Type uOutput} {Γ : Type uCapitalGamma} [Fintype ι] [Fintype O] [Fintype Γ] + (G : ι → Type uGroup) [∀ i, Fintype (G i)] + (p : FinLaw (O × (∀ i, G i))) (q : O × (∀ i, G i) → FinLaw Γ) + (hit : (i : ι) → Γ → G i → Prop) (n : ℕ) + (htrue : ∀ a, p a≠0 → ∀ v, q a v≠0 → ∀ i, ¬ hit i v (a.2 i)) + (Bad : ι → O × (∀ i, G i) → Prop) {A e η : ℝ} (hA : 0≤A) + (hH : (∑ i, Real.log (Fintype.card (G i)))-e ≤ p.cHf Prod.snd Prod.fst) + (hBad : (∑ i, p.prob (Bad i)) ≤ η) + (hlist : ∀ a, p a≠0 → ∀ i, + (∑ v, (q a).iid n v*Real.log (passingList (hit i) n v).card) ≤ + Real.log (Fintype.card (G i))-A*(if Bad i a then 0 else 1)) : + A*((Fintype.card ι:ℝ)-η)-e ≤ + (n:ℝ)*(p.joint q).cIf (fun v => v.1.2) Prod.snd (fun v => v.1.1) := by + let P := p.joint (fun a => (q a).iid n) + have hcond := joint_passing_entropy G p q hit n htrue + have hsum : (∑ a, p a*(∑ i, ∑ v, (q a).iid n v*Real.log (passingList (hit i) n v).card)) ≤ + (∑ i, Real.log (Fintype.card (G i)))-A*((Fintype.card ι:ℝ)-∑ i, p.prob (Bad i)) := by + calc + _ ≤ ∑ a, p a*(∑ i, (Real.log (Fintype.card (G i))-A*(if Bad i a then 0 else 1))) := by + apply Finset.sum_le_sum + intro a _ + by_cases ha : p a=0 + · simp only [ha,zero_mul,le_refl] + · exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ => hlist a ha i)) (p.nonneg a) + _ = _ := by + simp only [Finset.sum_sub_distrib,mul_sub, + ← Finset.sum_mul,p.sum_one,one_mul] + congr 1 + rw [mul_comm] + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + have hh (i : ι) : (∑ a, p a*(if Bad i a then (0:ℝ) else 1))=1-p.prob (Bad i) := by + rw [← p.prob_compl] + unfold prob + apply Finset.sum_congr rfl + intro a _ + by_cases hb : Bad i a <;> simp [hb] + have hh' (i : ι) : (∑ a, p a*(A*(if Bad i a then (0:ℝ) else 1)))= + A*(1-p.prob (Bad i)) := by + rw [← hh i,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + ring + simp only [hh',mul_sub,mul_one,Finset.sum_sub_distrib,Finset.sum_const, + Finset.card_univ,nsmul_eq_mul] + have hinit : P.cHf (fun v => v.1.2) (fun v => v.1.1)=p.cHf Prod.snd Prod.fst := by + have hh := P.cHf_map Prod.fst Prod.snd Prod.fst + rw [joint_map_fst] at hh + exact hh.symm + have hlow : A*((Fintype.card ι:ℝ)-η)-e ≤ + P.cIf (fun v => v.1.2) Prod.snd (fun v => v.1.1) := by + unfold cIf + rw [hinit] + have hm := mul_le_mul_of_nonneg_left hBad hA + change P.cHf (fun v => v.1.2) (fun v => (v.1.1,v.2)) ≤ _ at hcond + linarith only [hH,hcond,hsum,hm] + exact hlow.trans (conditional_iid_information p q n) + +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} {Γ : Type uCapitalGamma} [Fintype Ω] [Fintype α] [Fintype Γ] + +lemma conditionOn_support (p : FinLaw Ω) (C : Ω → α) (a : α) + (ha : p.map C a≠0) (ω : Ω) (hω : p.conditionOn C a ω≠0) : + p ω≠0 ∧ C ω=a := by + have hh := p.conditionOn_weight C a ω + have hn := mul_ne_zero ha hω + rw [hh] at hn + split_ifs at hn with hc + · exact ⟨hn,hc⟩ + · exact False.elim (hn rfl) + +lemma joint_conditionOn_mix (p : FinLaw Ω) (C : Ω → α) (q : Ω → FinLaw Γ) : + (p.map C).joint (fun a => (p.conditionOn C a).mix q)= + (p.joint q).map (fun v => (C v.1,v.2)) := by + ext ⟨a,v⟩ + rw [joint_mass,mix_mass,Finset.mul_sum] + conv_rhs => rw [map_mass,Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro ω _ + rw [← mul_assoc,conditionOn_weight] + simp only [joint_mass,Prod.mk.injEq] + by_cases hc : C ω=a + · simp only [hc,true_and,ite_true,Finset.sum_ite_eq',Finset.mem_univ] + · simp only [hc,false_and,ite_false,zero_mul,Finset.sum_const_zero] + +lemma mix_support (p : FinLaw Ω) (q : Ω → FinLaw Γ) (v : Γ) + (hv : p.mix q v≠0) : ∃ ω, p ω≠0 ∧ q ω v≠0 := by + rw [mix_mass] at hv + obtain ⟨ω,_,hω⟩ := Finset.exists_ne_zero_of_sum_ne_zero hv + exact ⟨ω,(mul_ne_zero_iff.mp hω)⟩ + +lemma expected_log_card_passingList_le {G : Type uGroup} [Fintype G] + (q : FinLaw Γ) (hit : Γ → G → Prop) (x : G) + (htrue : ∀ v, q v≠0 → ¬hit v x) (n : ℕ) : + (∑ v, q.iid n v*Real.log (passingList hit n v).card) ≤ Real.log (Fintype.card G) := by + have hh (v : Fin n → Γ) : q.iid n v*Real.log (passingList hit n v).card ≤ + q.iid n v*Real.log (Fintype.card G) := by + by_cases hv : q.iid n v=0 + · simp only [hv,zero_mul,le_refl] + · apply mul_le_mul_of_nonneg_left _ ((q.iid n).nonneg v) + apply Real.log_le_log + · exact_mod_cast Finset.card_pos.mpr ⟨x,q.passingList_true hit x htrue n v hv⟩ + · exact_mod_cast Finset.card_le_univ (passingList hit n v) + have hs := Finset.sum_le_sum (s := Finset.univ) (fun v _ => hh v) + simpa only [← Finset.sum_mul,(q.iid n).sum_one,one_mul] using hs + +lemma cIf_map {β : Type uBeta} {γ : Type uGamma} {δ : Type uDelta} (p : FinLaw Ω) (F : Ω → α) + (X : α → β) (Y : α → γ) (Z : α → δ) : + (p.map F).cIf X Y Z=p.cIf (X ∘ F) (Y ∘ F) (Z ∘ F) := by + unfold cIf + rw [cHf_map,cHf_map] + rfl + +theorem posterior_passing_information_lower {ι : Type uIota} {O : Type uOutput} [Fintype ι] [Fintype O] + (G : ι → Type uGroup) [∀ i, Fintype (G i)] + (p : FinLaw Ω) (old : Ω → O) (X : Ω → ∀ i, G i) (q : Ω → FinLaw Γ) + (hit : (i : ι) → Γ → G i → Prop) (Good : ι → Ω → Prop) + (E : (i : ι) → Ω → Finset (G i)) (e c : ι → ℝ) {A H η : ℝ} (n : ℕ) + (hA : 0≤A) (he : ∀ i, 0≤e i) (hc : ∀ i, 0≤c i) + (htrue : ∀ ω, p ω≠0 → ∀ v, q ω v≠0 → ∀ i, ¬hit i v (X ω i)) + (hE : ∀ i ω, Good i ω → ((E i ω).card:ℝ)≤e i) + (hhit : ∀ i ω, Good i ω → ∀ x∉E i ω, c i≤(q ω).prob (fun v => hit i v x)) + (hH : (∑ i, Real.log (Fintype.card (G i)))-H ≤ p.cHf X old) + (hBad : (∑ i, p.prob (fun ω => ¬Good i ω))≤η) + (hnum : ∀ i, Real.log (4*e i+(Fintype.card (G i):ℝ)*Real.exp (-(n:ℝ)*(c i/4))) ≤ + Real.log (Fintype.card (G i))-A) : + A*((Fintype.card ι:ℝ)-2*η)-H ≤ + (n:ℝ)*(p.joint q).cIf (fun v => X v.1) Prod.snd (fun v => old v.1) := by + let C := fun ω => (old ω,X ω) + let μ := p.map C + let Q := fun a => (p.conditionOn C a).mix q + let Bad := fun i a => (1/2:ℝ)<(p.conditionOn C a).prob (fun ω => ¬Good i ω) + have hsurv (a : O × (∀ i, G i)) (ha : μ a≠0) (v : Γ) (hv : Q a v≠0) (i : ι) : + ¬hit i v (a.2 i) := by + obtain ⟨ω,hω,hv⟩ := (p.conditionOn C a).mix_support q v hv + have hw := p.conditionOn_support C a ha ω hω + have hx : X ω=a.2 := congrArg Prod.snd hw.2 + rw [← hx] + exact htrue ω hw.1 v hv i + have hH' : (∑ i, Real.log (Fintype.card (G i)))-H ≤ μ.cHf Prod.snd Prod.fst := by + rw [cHf_map] + exact hH + have hBad' : (∑ i, μ.prob (Bad i))≤2*η := by + have hh := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + p.posterior_unfavorable C (fun ω => ¬Good i ω)) + simp only [← Finset.mul_sum] at hh + exact hh.trans (mul_le_mul_of_nonneg_left hBad (by norm_num)) + have hlist (a : O × (∀ i, G i)) (ha : μ a≠0) (i : ι) : + (∑ v, (Q a).iid n v*Real.log (passingList (hit i) n v).card) ≤ + Real.log (Fintype.card (G i))-A*(if Bad i a then 0 else 1) := by + by_cases hb : Bad i a + · rw [ite_eq_left hb,mul_zero,sub_zero] + exact (Q a).expected_log_card_passingList_le (hit i) (a.2 i) + (fun v hv => hsurv a ha v hv i) n + · rw [ite_eq_right hb,mul_one] + have hg : (1/2:ℝ)≤(p.conditionOn C a).prob (Good i) := by + have hh := (p.conditionOn C a).prob_compl (Good i) + dsimp only [Bad] at hb + push Not at hb + linarith only [hh,hb] + let F := Finset.univ.filter (fun x : G i => + (p.conditionOn C a).prob (fun ω => Good i ω ∧ x∉E i ω)<1/4) + have hf : (F.card:ℝ)≤4*e i := + (p.conditionOn C a).mixed_exception_card (Good i) (E i) (he i) (hE i) hg + have hm (x : G i) (hx : x∉F) : c i/4≤(Q a).prob (fun v => hit i v x) := by + apply (p.conditionOn C a).mixed_floor q (Good i) (E i) (hit i) (hc i) (hhit i) x + have hh : ¬(p.conditionOn C a).prob (fun ω => Good i ω ∧ x∉E i ω)<1/4 := by + simpa only [F,Finset.mem_filter,Finset.mem_univ,true_and] using hx + exact le_of_not_gt hh + have ht := (Q a).expected_log_card_passingList (hit i) (a.2 i) + (fun v hv => hsurv a ha v hv i) F hm n + have hpos : (0:ℝ)<(Fintype.card (G i):ℝ)*Real.exp (-(n:ℝ)*(c i/4)) := by + have hcard : 0 (C v.1,v.2)) := + p.joint_conditionOn_mix C q + rw [hdist,cIf_map] at hh + exact hh + +end FinLaw +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/PointEnrichment.lean b/lean/OAI/NumberTheory/GaussianMoat/PointEnrichment.lean new file mode 100644 index 0000000000000000000000000000000000000000..debcc81dab900f0d5e750fa80c9102e97656050e --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/PointEnrichment.lean @@ -0,0 +1,570 @@ +import OAI.NumberTheory.GaussianMoat.FreshEntropy + +namespace OAI + +universe uOmega uIota uKappa uAlpha uBeta uCapitalKappa + +namespace GaussianMoat + +section +open scoped BigOperators Classical + +theorem latticeBall_card_le {R : ℝ} (hR : 1 ≤ R) : + ((latticeBall R).card : ℝ) ≤ 36*R^2 := by + have h := lattice_rectangle_card (latticeBall R) (e := 1) (c := (-R : ℝ)) + (by simp) (R := 2*R) (by linarith) hR (by + intro z hz + have hn := (mem_latticeBall R z).mp hz + have hr := abs_le.mp ((Complex.abs_re_le_norm (z:ℂ)).trans hn) + have hi := (Complex.abs_im_le_norm (z:ℂ)).trans hn + simp only [one_mul,Complex.sub_re,Complex.ofReal_re,sub_neg_eq_add, + Complex.sub_im,Complex.ofReal_im,sub_zero] + exact ⟨by linarith,by linarith,hi⟩) + nlinarith + +theorem displacement_entropy_le {Ω : Type uOmega} [Fintype Ω] (P : FinLaw Ω) + (Z : Ω → GaussianInt) {R : ℝ} (hR : 1 ≤ R) (hZ : ∀ ω, ‖(Z ω:ℂ)‖ ≤ R) : + P.Hf Z ≤ Real.log 36+2*Real.log R := by + have h := P.Hf_le_log_card_set Z (latticeBall R) (fun ω => (mem_latticeBall R _).mpr (hZ ω)) + have hc : 0 < ((latticeBall R).card:ℝ) := by + exact_mod_cast Finset.card_pos.mpr ⟨0,by simpa using (show 0 ≤ R by linarith)⟩ + have hl := Real.log_le_log hc (latticeBall_card_le hR) + rw [Real.log_mul (by norm_num : (36:ℝ)≠0) (pow_ne_zero _ (by linarith : R≠0)), + Real.log_pow] at hl + exact h.trans hl + +theorem differences_rectangle (E : Finset GaussianInt) {e c : ℂ} {R W : ℝ} + (hE : ∀ p ∈ E, 0 ≤ (e*((p:ℂ)-c)).re ∧ + (e*((p:ℂ)-c)).re ≤ R ∧ |(e*((p:ℂ)-c)).im| ≤ W) : + ∀ x ∈ differences E, ∀ y ∈ differences E, + x-y ∈ orientedRectangle (star e) (4*R) (4*W) := by + intro x hx y hy + obtain ⟨a,ha,b,hb,rfl⟩ := (mem_differences E x).mp hx + obtain ⟨a',ha',b',hb',rfl⟩ := (mem_differences E y).mp hy + have h1 := hE a ha + have h2 := hE b hb + have h3 := hE a' ha' + have h4 := hE b' hb' + have heq : e*((a:ℂ)-(b:ℂ)-((a':ℂ)-(b':ℂ))) = + e*((a:ℂ)-c)-e*((b:ℂ)-c)-(e*((a':ℂ)-c)-e*((b':ℂ)-c)) := by ring + rw [orientedRectangle] + simp only [Set.mem_ofPred_eq,star_star,map_sub,heq,Complex.sub_re,Complex.sub_im] + obtain ⟨h1i,h1i'⟩ := abs_le.mp h1.2.2 + obtain ⟨h2i,h2i'⟩ := abs_le.mp h2.2.2 + obtain ⟨h3i,h3i'⟩ := abs_le.mp h3.2.2 + obtain ⟨h4i,h4i'⟩ := abs_le.mp h4.2.2 + refine ⟨abs_le.mpr ⟨?_,?_⟩,abs_le.mpr ⟨?_,?_⟩⟩ <;> linarith + +lemma difference_exists_pair (z : ℕ → GaussianInt) (n : ℕ) + (d : differences (walkSegment z n)) : + ∃ ij : Fin (n+1) × Fin (n+1), z ij.1.val-z ij.2.val=d := by + obtain ⟨a,ha,b,hb,hab⟩ := (mem_differences _ _).mp d.property + obtain ⟨i,hi,rfl⟩ := (mem_walkSegment _ _ _).mp ha + obtain ⟨j,hj,rfl⟩ := (mem_walkSegment _ _ _).mp hb + exact ⟨(⟨i,by omega⟩,⟨j,by omega⟩),hab⟩ + +noncomputable def differenceRepresentative (z : ℕ → GaussianInt) (n : ℕ) + (d : differences (walkSegment z n)) : Fin (n+1) × Fin (n+1) := + (difference_exists_pair z n d).choose + +lemma differenceRepresentative_spec (z : ℕ → GaussianInt) (n : ℕ) + (d : differences (walkSegment z n)) : + z (differenceRepresentative z n d).1.val-z (differenceRepresentative z n d).2.val=d := + (difference_exists_pair z n d).choose_spec + +lemma differenceRepresentative_injective (z : ℕ → GaussianInt) (n : ℕ) : + Function.Injective (differenceRepresentative z n) := by + intro d d' hh + apply Subtype.ext + rw [← differenceRepresentative_spec z n d,← differenceRepresentative_spec z n d',hh] + +lemma differences_walkSegment_nonempty (z : ℕ → GaussianInt) (n : ℕ) : + (differences (walkSegment z n)).Nonempty := by + refine ⟨0,(mem_differences _ _).mpr ⟨z 0,?_,z 0,?_,sub_self _⟩⟩ <;> + exact (mem_walkSegment _ _ _).mpr ⟨0,by omega,rfl⟩ + +end + +namespace FinLaw +open scoped BigOperators Classical +variable {ι : Type uIota} {Ω : Type uOmega} {κ : Type uKappa} {α : Type uAlpha} {β : Type uBeta} [Fintype ι] [Fintype Ω] [Fintype κ] + +noncomputable def joint (p : FinLaw ι) (q : ι → FinLaw Ω) : FinLaw (ι × Ω) where + mass := fun v => p v.1*q v.1 v.2 + nonneg := fun v => mul_nonneg (p.nonneg _) ((q _).nonneg _) + sum_one := by + simp only [Fintype.sum_prod_type,← Finset.mul_sum,FinLaw.sum_one,mul_one] + +@[simp] theorem joint_mass (p : FinLaw ι) (q : ι → FinLaw Ω) (i : ι) (ω : Ω) : + p.joint q (i,ω) = p i*q i ω := rfl + +@[simp] theorem joint_map_fst (p : FinLaw ι) (q : ι → FinLaw Ω) : + (p.joint q).map Prod.fst = p := by + ext i + simp only [map_mass,Fintype.sum_prod_type,joint_mass] + rw [Finset.sum_comm] + simp only [Finset.sum_ite_eq',Finset.mem_univ,ite_true,← Finset.mul_sum, + sum_one,mul_one] + +@[simp] theorem joint_map_snd (p : FinLaw ι) (q : ι → FinLaw Ω) : + (p.joint q).map Prod.snd = p.mix q := by + ext ω + simp [map_mass,Fintype.sum_prod_type,joint_mass,mix_mass] + +@[simp] theorem joint_map_second (p : FinLaw ι) (q : ι → FinLaw Ω) (f : Ω → κ) : + (p.joint q).map (fun v => (v.1,f v.2)) = p.joint (fun i => (q i).map f) := by + ext ⟨i,x⟩ + simp only [map_mass,Fintype.sum_prod_type,joint_mass,Prod.mk.injEq,ite_and] + rw [Finset.sum_comm] + simp only [Finset.sum_ite_eq',Finset.mem_univ,ite_true] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + +theorem entropy_joint (p : FinLaw ι) (q : ι → FinLaw Ω) : + (p.joint q).entropy = p.entropy+∑ i, p i*(q i).entropy := by + simp only [entropy,entropySum,Fintype.sum_prod_type,joint_mass,Real.negMulLog_mul, + Finset.sum_add_distrib,← Finset.mul_sum,← Finset.sum_mul,FinLaw.sum_one,one_mul] + +theorem Hf_map (p : FinLaw Ω) (f : Ω → κ) (X : κ → α) : + (p.map f).Hf X = p.Hf (X ∘ f) := by + rw [Hf_code,H,map_comp] + rw [← H,← Hf_eq_H] + apply p.Hf_eq_of_fibers + intro ω ν + exact outputCode_eq_iff X (f ω) (f ν) + +theorem cHf_map (p : FinLaw Ω) (f : Ω → κ) (X : κ → α) (Y : κ → β) : + (p.map f).cHf X Y = p.cHf (X ∘ f) (Y ∘ f) := by + simp only [cHf,Hf_map,Function.comp_def] + +theorem Hf_joint_pair (p : FinLaw ι) (q : ι → FinLaw Ω) (X : Ω → α) : + (p.joint q).Hf (fun v => (v.1,X v.2)) = p.entropy+∑ i, p i*(q i).Hf X := by + let C := outputCode X + have he (r : FinLaw Ω) : r.Hf X = r.Hf C := + r.Hf_eq_of_fibers X C (fun ω ν => (outputCode_eq_iff X ω ν).symm) + have he' : (p.joint q).Hf (fun v => (v.1,X v.2)) = + (p.joint q).Hf (fun v => (v.1,C v.2)) := by + apply Hf_eq_of_fibers + intro v w + simp only [Prod.mk.injEq,C,outputCode_eq_iff] + rw [he',Hf_eq_H,H,joint_map_second,entropy_joint] + simp_rw [he,Hf_eq_H,H] + +theorem cHf_mix_ge (p : FinLaw ι) (q : ι → FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + (∑ i, p i*(q i).cHf X Y) ≤ (p.mix q).cHf X Y := by + have hm := (p.joint q).cHf_mono (fun v => X v.2) (fun v => Y v.2) Prod.fst + have hid : (p.joint q).cHf (fun v => X v.2) (fun v => (Y v.2,v.1)) = + ∑ i, p i*(q i).cHf X Y := by + unfold cHf + have h1 : (p.joint q).Hf (fun v => (X v.2,(Y v.2,v.1))) = + (p.joint q).Hf (fun v => (v.1,(X v.2,Y v.2))) := by + apply Hf_eq_of_fibers + intro v w + simp only [Prod.mk.injEq] + tauto + rw [h1,Hf_joint_pair p q (fun ω => (X ω,Y ω)), + Hf_pair_comm (p.joint q) (fun v => Y v.2) Prod.fst, Hf_joint_pair] + simp only [mul_sub,Finset.sum_sub_distrib] + ring + rw [hid] at hm + have he := (p.joint q).cHf_map Prod.snd X Y + rw [joint_map_snd] at he + exact hm.trans_eq he.symm + +theorem joint_map_fiber (p : FinLaw ι) (q : ι → FinLaw Ω) (f : ι → Ω → κ) : + (p.joint q).map (fun v => (v.1,f v.1 v.2)) = p.joint (fun i => (q i).map (f i)) := by + ext ⟨i,x⟩ + simp only [map_mass,Fintype.sum_prod_type,joint_mass,Prod.mk.injEq,ite_and] + rw [Finset.sum_comm] + simp only [Finset.sum_ite_eq',Finset.mem_univ,ite_true] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + +theorem Hf_joint_pair_vary (p : FinLaw ι) (q : ι → FinLaw Ω) (X : ι → Ω → α) : + (p.joint q).Hf (fun v => (v.1,X v.1 v.2)) = + p.entropy+∑ i, p i*(q i).Hf (X i) := by + let C := outputCode (fun v : ι × Ω => X v.1 v.2) + have he (i : ι) : (q i).Hf (X i) = (q i).Hf (fun ω => C (i,ω)) := by + apply Hf_eq_of_fibers + intro ω ν + exact (outputCode_eq_iff (fun v : ι × Ω => X v.1 v.2) (i,ω) (i,ν)).symm + have he' : (p.joint q).Hf (fun v => (v.1,X v.1 v.2)) = + (p.joint q).Hf (fun v => (v.1,C v)) := by + apply Hf_eq_of_fibers + intro v w + simp only [Prod.mk.injEq,C,outputCode_eq_iff] + rw [he',Hf_eq_H,H,joint_map_fiber p q (fun i ω => C (i,ω)),entropy_joint] + simp_rw [he,Hf_eq_H,H] + +theorem cHf_joint_ge (p : FinLaw ι) (q : ι → FinLaw Ω) + (X : ι → Ω → α) (Y : ι → Ω → β) : + (∑ i, p i*(q i).cHf (X i) (Y i)) ≤ + (p.joint q).cHf (fun v => X v.1 v.2) (fun v => Y v.1 v.2) := by + have hm := (p.joint q).cHf_mono (fun v => X v.1 v.2) (fun v => Y v.1 v.2) Prod.fst + have hid : (p.joint q).cHf (fun v => X v.1 v.2) (fun v => (Y v.1 v.2,v.1)) = + ∑ i, p i*(q i).cHf (X i) (Y i) := by + unfold cHf + have h1 : (p.joint q).Hf (fun v => (X v.1 v.2,(Y v.1 v.2,v.1))) = + (p.joint q).Hf (fun v => (v.1,(X v.1 v.2,Y v.1 v.2))) := by + apply Hf_eq_of_fibers + intro v w + simp only [Prod.mk.injEq] + tauto + rw [h1,Hf_joint_pair_vary p q (fun i ω => (X i ω,Y i ω)), + Hf_pair_comm (p.joint q) (fun v => Y v.1 v.2) Prod.fst,Hf_joint_pair_vary] + simp only [mul_sub,Finset.sum_sub_distrib] + ring + rwa [hid] at hm + +theorem Hf_pair_const_right (p : FinLaw Ω) (X : Ω → α) (c : β) : + p.Hf (fun ω => (X ω,c)) = p.Hf X := by + apply Hf_eq_of_fibers + intro ω ν + simp + +theorem Hf_joint_ge (p : FinLaw ι) (q : ι → FinLaw Ω) (X : ι → Ω → α) : + (∑ i, p i*(q i).Hf (X i)) ≤ (p.joint q).Hf (fun v => X v.1 v.2) := by + have h := cHf_joint_ge p q X (fun _ _ => (0:ℕ)) + simpa only [cHf,Hf_const,sub_zero,Hf_pair_const_right] using h + +end FinLaw + +open scoped BigOperators Classical + +noncomputable def SplitSieve.pointEntropy {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (P : FinLaw Ω) (Z : Ω → GaussianInt) (b : ℕ) : ℝ := + P.signedEntropy (fun σ ω => s.residueVector σ (Z ω)) b + +noncomputable def SplitSieve.freshCoordinate {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (P : FinLaw Ω) (X Y : Ω → GaussianInt) + (b : ℕ) (hb : b < s.primes.card) : ℝ := + 𝔼 σ : Fin s.primes.card → Bool, 𝔼 π : Equiv.Perm (Fin s.primes.card), + P.cHf (fun ω => s.residueVector σ (X ω-Y ω) (π ⟨b,hb⟩)) + (fun ω => (FinLaw.prefixVar (fun x => s.residueVector σ (X x)) π b ω, + FinLaw.prefixVar (fun x => s.residueVector σ (Y x)) π b ω)) + +lemma SplitSieve.freshCoordinate_map {Ω : Type uOmega} {Κ : Type uCapitalKappa} [Fintype Ω] [Fintype Κ] + (s : SplitSieve) (p : FinLaw Ω) (f : Ω → Κ) (X Y : Κ → GaussianInt) + (b : ℕ) (hb : b < s.primes.card) : + s.freshCoordinate (p.map f) X Y b hb = s.freshCoordinate p (X ∘ f) (Y ∘ f) b hb := by + unfold SplitSieve.freshCoordinate + simp only [FinLaw.cHf_map,Function.comp_def] + rfl + +noncomputable def differenceLaw (z : ℕ → GaussianInt) (n : ℕ) : + FinLaw (Fin (n+1) × Fin (n+1)) := by + let := (differences_walkSegment_nonempty z n).to_subtype + exact (FinLaw.uniform (differences (walkSegment z n))).map (differenceRepresentative z n) + +theorem differenceLaw_fresh (s : SplitSieve) (z : ℕ → GaussianInt) (n : ℕ) + {b r : ℕ} (hbr : b < r) (hr : r ≤ s.primes.card) + {T R W d δ : ℝ} {e : ℂ} (he : ‖e‖=1) (hT : 5 ≤ T) + (hpT : ∀ p ∈ s.primes, T ≤ (p : ℝ) ∧ (p : ℝ) ≤ 2*T) + (hW : 1 ≤ W) (hWR : W ≤ R) (hd : 0 < d) (hd1 : d < 1/4) + (hδ : 0 < δ) (hgap : Real.log (R*W) ≤ (1-d)*(r*s.meanLog-δ)) + (hlarge : 1000 ≤ d^3*r) + (hΔ : ∀ x ∈ differences (walkSegment z n), ∀ y ∈ differences (walkSegment z n), + x-y ∈ orientedRectangle e R W) : + (1-r*(Real.log 2)^2/δ^2-Real.exp (-(d^3*r/5120)))* + Real.log (differences (walkSegment z n)).card-2*b*Real.log (2*T) ≤ + (r-b : ℕ)*s.freshCoordinate (differenceLaw z n) + (fun ij => z ij.1.val) (fun ij => z ij.2.val) b (by omega) := by + let Δ := differences (walkSegment z n) + let hne := differences_walkSegment_nonempty z n + let := hne.to_subtype + let X : Δ → GaussianInt := fun ω => z (differenceRepresentative z n ω).1.val + let Y : Δ → GaussianInt := fun ω => z (differenceRepresentative z n ω).2.val + have hXY : ∀ ω, X ω-Y ω=ω := differenceRepresentative_spec z n + have h := s.actual_fresh_entropy hbr hr Δ hne X Y hXY he hT hpT hW hWR hd hd1 hδ hgap hlarge hΔ + change _ ≤ (r-b : ℕ)*s.freshCoordinate + ((FinLaw.uniform Δ).map (differenceRepresentative z n)) + (fun ij => z ij.1.val) (fun ij => z ij.2.val) b (by omega) + rw [s.freshCoordinate_map] + change _ ≤ (r-b : ℕ)*s.freshCoordinate (FinLaw.uniform Δ) X Y b (by omega) + simpa only [SplitSieve.freshCoordinate,hXY] using h + +theorem SplitSieve.freshCoordinate_joint_ge {ι : Type uIota} {Ω : Type uOmega} [Fintype ι] [Fintype Ω] + (s : SplitSieve) (p : FinLaw ι) (q : ι → FinLaw Ω) + (X Y : ι → Ω → GaussianInt) {b : ℕ} (hb : b < s.primes.card) : + (∑ i, p i*s.freshCoordinate (q i) (X i) (Y i) b hb) ≤ + s.freshCoordinate (p.joint q) (fun v => X v.1 v.2) (fun v => Y v.1 v.2) b hb := by + have h := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => + Finset.expect_le_expect (s := Finset.univ) (fun π _ => + p.cHf_joint_ge q (fun i ω => s.residueVector σ (X i ω-Y i ω) (π ⟨b,hb⟩)) + (fun i ω => (FinLaw.prefixVar (fun x => s.residueVector σ (X i x)) π b ω, + FinLaw.prefixVar (fun x => s.residueVector σ (Y i x)) π b ω)))) + simpa only [SplitSieve.freshCoordinate,Finset.expect_sum_comm,Finset.mul_expect] using! h + +lemma pointEntropy_fair_endpoint {Ω : Type uOmega} [Fintype Ω] (s : SplitSieve) + (p : FinLaw Ω) (X Y : Ω → GaussianInt) (b : ℕ) : + s.pointEntropy p X b+s.pointEntropy p Y b ≤ + 2*s.pointEntropy ((FinLaw.uniform Bool).joint (fun _ => p)) + (fun v => if v.1 then X v.2 else Y v.2) b := by + have h := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => + Finset.expect_le_expect (s := Finset.univ) (fun π _ => + (FinLaw.uniform Bool).Hf_joint_ge (fun _ => p) + (fun c ω => FinLaw.prefixVar (fun x => s.residueVector σ (if c then X x else Y x)) π b ω))) + simp only [Fintype.sum_bool,FinLaw.uniform_mass,Fintype.card_bool,Nat.cast_ofNat, + Bool.false_eq_true,ite_false,ite_true,Finset.expect_add_distrib,← Finset.mul_expect] at h + change (2:ℝ)⁻¹*s.pointEntropy p X b+(2:ℝ)⁻¹*s.pointEntropy p Y b ≤ + s.pointEntropy ((FinLaw.uniform Bool).joint (fun _ => p)) + (fun v => if v.1 then X v.2 else Y v.2) b at h + linarith + +theorem SplitSieve.point_enrichment_accounting {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (p : FinLaw Ω) (X Y Z : Ω → GaussianInt) + {b q : ℕ} (hb : 0 < b) (hbq : b < q) (hq : q ≤ s.primes.card) : + (b : ℝ)*((q-b : ℕ)*s.freshCoordinate p X Y b (by omega)+ + s.pointEntropy p Z q-p.Hf (fun ω => X ω-Y ω)-p.Hf (fun ω => X ω-Z ω)) ≤ + (q : ℝ)*(s.pointEntropy p X b+s.pointEntropy p Y b) := by + have h (σ : Fin s.primes.card → Bool) := p.ordered_enrichment_accounting + (fun ω => s.residueVector σ (X ω)) (fun ω => s.residueVector σ (Y ω)) + (fun ω => s.residueVector σ (Z ω)) (fun ω => s.residueVector σ (X ω-Y ω)) + (fun ω => X ω-Y ω) (fun ω => X ω-Z ω) hb hbq hq + (by intro i ω ν hx hy; exact residueCode_sub hx hy) + (by + intro i ω ν hx hd + have h := residueCode_sub hx hd + simpa only [sub_sub_cancel,SplitSieve.residueVector] using h) + (by intro i ω ν hh; rw [hh]) + (by + intro i ω ν hx he + have h := residueCode_sub hx (congrArg (residueCode _) he) + simpa only [sub_sub_cancel,SplitSieve.residueVector] using h) + have hh := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => h σ) + simpa only [SplitSieve.pointEntropy,FinLaw.signedEntropy,SplitSieve.freshCoordinate, + Finset.expect_sub_distrib,Finset.expect_add_distrib,← Finset.mul_expect,Fintype.expect_const] using hh + +theorem SplitSieve.actual_enrichment {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (p : FinLaw Ω) (X Y Z : Ω → GaussianInt) + {b q : ℕ} (hb : 0 < b) (hbq : b < q) (hq : q ≤ s.primes.card) + {F R : ℝ} (hF : F ≤ s.freshCoordinate p X Y b (by omega)) + (hR : 1 ≤ R) (hXY : ∀ ω, ‖((X ω-Y ω:GaussianInt):ℂ)‖ ≤ R) + (hXZ : ∀ ω, ‖((X ω-Z ω:GaussianInt):ℂ)‖ ≤ R) : + (b : ℝ)*((q-b : ℕ)*F+s.pointEntropy p Z q-2*(Real.log 36+2*Real.log R)) ≤ + 2*(q : ℝ)*s.pointEntropy ((FinLaw.uniform Bool).joint (fun _ => p)) + (fun v => if v.1 then X v.2 else Y v.2) b := by + have hc := s.point_enrichment_accounting p X Y Z hb hbq hq + have h1 := displacement_entropy_le p (fun ω => X ω-Y ω) hR hXY + have h2 := displacement_entropy_le p (fun ω => X ω-Z ω) hR hXZ + have he := pointEntropy_fair_endpoint s p X Y b + have hm := mul_le_mul_of_nonneg_left he (Nat.cast_nonneg q) + have hf := mul_le_mul_of_nonneg_left hF (show (0:ℝ) ≤ (q-b:ℕ) by positivity) + have hsub : (q-b:ℕ)*F+s.pointEntropy p Z q-2*(Real.log 36+2*Real.log R) ≤ + (q-b:ℕ)*s.freshCoordinate p X Y b (by omega)+s.pointEntropy p Z q- + p.Hf (fun ω => X ω-Y ω)-p.Hf (fun ω => X ω-Z ω) := by linarith + have hmul := mul_le_mul_of_nonneg_left hsub (Nat.cast_nonneg b) + nlinarith + +open scoped BigOperators Classical + +lemma fresh_error_bounds {g L r : ℝ} (hg : 0 < g) (hg1 : g ≤ 1/100) + (hL : 1 ≤ L) (hr : 0 < r) (hlarge : 5120 ≤ g^4*r) : + r*(Real.log 2)^2/(2*g*r*L)^2 ≤ g ∧ Real.exp (-(g^3*r/5120)) ≤ g := by + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hlog1 : Real.log 2 ≤ 1 := by + have h := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hl2 : (Real.log 2)^2 ≤ 1 := by nlinarith + have hg4 : 0 < g^4 := pow_pos hg _ + have hg3 : 0 < g^3 := pow_pos hg _ + have hgL : 0 < 2*g*r*L := by positivity + have hgr : 1 ≤ g^3*r := by + have h : g^4*r = g*(g^3*r) := by ring + have hp : 0 ≤ g^3*r := mul_nonneg hg3.le hr.le + nlinarith + have hLL : 1 ≤ L^2 := by nlinarith + have hprod := mul_le_mul hgr hLL (by norm_num : (0:ℝ)≤1) (mul_nonneg hg3.le hr.le) + have hrr : 0 ≤ r*(4*(g^3*r*L^2)-1) := mul_nonneg hr.le (by nlinarith) + constructor + · apply (div_le_iff₀ (sq_pos_of_pos hgL)).mpr + have h := mul_le_mul_of_nonneg_left hl2 hr.le + nlinarith + · have hpow : 1/g ≤ g^3*r/5120 := by + apply (div_le_iff₀ hg).mpr + nlinarith + have hlogg : -(1/g) ≤ Real.log g := by + have h := Real.log_le_sub_one_of_pos (inv_pos.mpr hg) + rw [Real.log_inv] at h + simp only [one_div] at h ⊢ + linarith + exact (Real.exp_le_exp.mpr (by linarith : -(g^3*r/5120) ≤ Real.log g)).trans_eq + (Real.exp_log hg) + +lemma fresh_gap_bound {g a L r : ℝ} (hg : 0 < g) (hg1 : g ≤ 1/100) + (ha : 0 ≤ a) (hlow : (1+10*g)*a ≤ r*L) : + a ≤ (1-g)*(r*L-2*g*r*L) := by + have hfac : 0 ≤ (1-g)*(1-2*g) := mul_nonneg (by linarith) (by linarith) + have h := mul_le_mul_of_nonneg_left hlow hfac + have hn : 0 ≤ g*(7-30*g) := mul_nonneg hg.le (by linarith) + have he : 1 ≤ (1-g)*(1-2*g)*(1+10*g) := by + have hg3 : 0 ≤ g^3 := pow_nonneg hg.le _ + nlinarith + have ha' := mul_le_mul_of_nonneg_right he ha + nlinarith + +theorem SplitSieve.differenceLaw_fresh_lower (s : SplitSieve) + (z : ℕ → GaussianInt) (n : ℕ) {b r : ℕ} + (hbr : b < r) (hr : r ≤ s.primes.card) + {T R W g a : ℝ} {e : ℂ} (he : ‖e‖=1) (hT : 5 ≤ T) + (hpT : ∀ p ∈ s.primes, T ≤ (p : ℝ) ∧ (p : ℝ) ≤ 2*T) + (hW : 1 ≤ W) (hWR : W ≤ R) (hg : 0 < g) (hg1 : g ≤ 1/100) + (hmean : 1 ≤ s.meanLog) (ha : a = Real.log (R*W)) (ha0 : 0 ≤ a) + (hlow : (1+10*g)*a ≤ r*s.meanLog) (hhigh : r*s.meanLog ≤ (1+11*g)*a) + (hlarge : 5120 ≤ g^4*r) + (hsize : (1-g)*a ≤ Real.log (differences (walkSegment z n)).card) + (hcost : 2*b*Real.log (2*T) ≤ 8*g*a) + (hΔ : ∀ x ∈ differences (walkSegment z n), ∀ y ∈ differences (walkSegment z n), + x-y ∈ orientedRectangle e R W) : + (1-30*g)*s.meanLog ≤ s.freshCoordinate (differenceLaw z n) + (fun ij => z ij.1.val) (fun ij => z ij.2.val) b (by omega) := by + have hr0 : (0:ℝ) < r := by exact_mod_cast (show 0 < r by omega) + have hg14 : g < 1/4 := by linarith + have hδ : 0 < 2*g*r*s.meanLog := by positivity + have hgap : Real.log (R*W) ≤ (1-g)*(r*s.meanLog-2*g*r*s.meanLog) := by + rw [← ha] + exact fresh_gap_bound hg hg1 ha0 hlow + have hlarge' : 1000 ≤ g^3*(r:ℝ) := by + have hp : 0 ≤ g^3*(r:ℝ) := by positivity + have hid : g^4*(r:ℝ) = g*(g^3*r) := by ring + nlinarith + have herr := fresh_error_bounds hg hg1 hmean hr0 hlarge + have h := differenceLaw_fresh s z n hbr hr he hT hpT hW hWR hg hg14 hδ + hgap hlarge' hΔ + have hsize0 : 0 ≤ Real.log (differences (walkSegment z n)).card := by + have hh : 0 ≤ (1-g)*a := mul_nonneg (by linarith) ha0 + linarith + have he := mul_le_mul_of_nonneg_right (show 1-2*g ≤ + 1-(r:ℝ)*(Real.log 2)^2/(2*g*r*s.meanLog)^2- + Real.exp (-(g^3*r/5120)) by linarith [herr.1,herr.2]) hsize0 + have hs := mul_le_mul_of_nonneg_left hsize (show 0 ≤ 1-2*g by linarith) + have hnum : (1-11*g)*a ≤ (r-b:ℕ)*s.freshCoordinate (differenceLaw z n) + (fun ij => z ij.1.val) (fun ij => z ij.2.val) b (by omega) := by + have hx : 0 ≤ 2*g^2*a := by positivity + nlinarith + have hp0 : 0 ≤ 1-30*g := by linarith + have hh := mul_le_mul_of_nonneg_left hhigh hp0 + have hh2 : (1-30*g)*((1+11*g)*a) ≤ (1-11*g)*a := by + have h1 : 0 ≤ g*a := mul_nonneg hg.le ha0 + have h2 : 0 ≤ g^2*a := mul_nonneg (sq_nonneg _) ha0 + nlinarith + have hbrR : (r-b:ℕ) ≤ (r:ℝ) := by exact_mod_cast Nat.sub_le r b + have hb0 : (0:ℝ) < (r-b:ℕ) := by exact_mod_cast Nat.sub_pos_of_lt hbr + have hm := mul_le_mul_of_nonneg_right hbrR (mul_nonneg hp0 (by linarith : 0 ≤ s.meanLog)) + nlinarith + +lemma SplitSieve.meanLog_bounds (s : SplitSieve) (hne : s.primes.Nonempty) {T : ℝ} + (hT : 0 < T) (hpT : ∀ p ∈ s.primes, T ≤ (p:ℝ) ∧ (p:ℝ) ≤ 2*T) : + Real.log T ≤ s.meanLog ∧ s.meanLog ≤ Real.log (2*T) := by + have : Nonempty (Fin s.primes.card) := Fin.pos_iff_nonempty.mp (Finset.card_pos.mpr hne) + constructor + · have h := Finset.expect_le_expect (s := Finset.univ) (fun i _ => + Real.log_le_log hT (hpT _ (s.enumeration i).property).1) + simpa only [SplitSieve.meanLog,Fintype.expect_const] using h + · apply Finset.expect_le (Finset.univ_nonempty) + intro i _ + exact Real.log_le_log (lt_of_lt_of_le hT (hpT _ (s.enumeration i).property).1) + (hpT _ (s.enumeration i).property).2 + +theorem SplitSieve.walk_fresh_lower (s : SplitSieve) (hne : s.primes.Nonempty) + (z : ℕ → GaussianInt) {n : ℕ} (hn : 1 ≤ n) (hinj : Function.Injective z) + {D T g : ℝ} (hD : 1 ≤ D) (hT : 5 ≤ T) + (hz : ∀ i < n, dist (z i:ℂ) (z (i+1):ℂ) ≤ D) + (hpT : ∀ p ∈ s.primes, T ≤ (p:ℝ) ∧ (p:ℝ) ≤ 2*T) + (hg : 0 < g) (hg1 : g ≤ 1/100) (hL : 1 ≤ s.meanLog) + {b : ℕ} (hu : 0 < Real.log n-Real.log 18) + (hround : s.meanLog ≤ g*(Real.log n-Real.log 18)) + (hlarge : 5120*s.meanLog ≤ g^4*(Real.log n-Real.log 18)) + (hcost : (b:ℝ)*s.meanLog ≤ g*(Real.log n-Real.log 18)) + (hsize : Real.log 16+Real.log (max D ((latticeBall (4*D)).card:ℝ)) ≤ + g*(Real.log n-Real.log 18)) + (hcap : 2*(2*Real.log n+Real.log 16+2*Real.log D) ≤ s.primes.card*s.meanLog) : + ∃ hb : b < s.primes.card, + (1-30*g)*s.meanLog ≤ s.freshCoordinate (differenceLaw z n) + (fun ij => z ij.1.val) (fun ij => z ij.2.val) b hb := by + obtain ⟨R,W,e,c,hW,hWR,he,hrect,hnA,hAup,hAΔ⟩ := + walk_many_differences z hn hinj hD hz + have hRp : 0 < R := by linarith + have hWp : 0 < W := by linarith + have hA : 0 < R*W := mul_pos hRp hWp + have hnR : (0:ℝ) < n := by exact_mod_cast hn + have hLp : 0 < s.meanLog := by linarith + let a := Real.log (16*(R*W)) + let u := Real.log n-Real.log 18 + have hua : u ≤ a := by + have h := Real.log_le_log hnR hnA + rw [Real.log_mul (by norm_num : (18:ℝ)≠0) hA.ne'] at h + have hl16 : 0 ≤ Real.log 16 := Real.log_nonneg (by norm_num) + dsimp [u,a] + rw [Real.log_mul (by norm_num : (16:ℝ)≠0) hA.ne'] + linarith + have ha0 : 0 < a := lt_of_lt_of_le hu hua + have hav : a ≤ 2*Real.log n+Real.log 16+2*Real.log D := by + have h := Real.log_le_log hA hAup + rw [Real.log_mul (pow_ne_zero _ (by linarith : D≠0)) (pow_ne_zero _ hnR.ne'), + Real.log_pow,Real.log_pow] at h + dsimp [a] + rw [Real.log_mul (by norm_num : (16:ℝ)≠0) hA.ne'] + norm_num at h + linarith only [h] + let r := ⌈(1+10*g)*a/s.meanLog⌉₊ + have hlo : (1+10*g)*a ≤ (r:ℝ)*s.meanLog := by + exact (div_le_iff₀ hLp).mp (Nat.le_ceil _) + have hhi : (r:ℝ)*s.meanLog ≤ (1+11*g)*a := by + have hx : 0 ≤ (1+10*g)*a/s.meanLog := by positivity + have hc := Nat.ceil_lt_add_one hx + have hh := mul_lt_mul_of_pos_right hc hLp + have heq : ((1+10*g)*a/s.meanLog+1)*s.meanLog = (1+10*g)*a+s.meanLog := by + rw [add_mul,div_mul_cancel₀ _ hLp.ne',one_mul] + rw [heq] at hh + have hgu := mul_le_mul_of_nonneg_left hua hg.le + change (r:ℝ)*s.meanLog < (1+10*g)*a+s.meanLog at hh + nlinarith only [hh,hround,hgu] + have hr : r ≤ s.primes.card := by + suffices hh : (r:ℝ) ≤ s.primes.card by exact_mod_cast hh + have hh : (1+11*g)*a ≤ 2*a := by nlinarith only [hg1,ha0] + nlinarith only [hhi,hh,hav,hcap,hLp] + have hbr : b < r := by + suffices hh : (b:ℝ) < r by exact_mod_cast hh + have hgu := mul_le_mul_of_nonneg_left hua hg.le + nlinarith only [hcost,hgu,hlo,hg1,hLp,ha0] + have hlr : 5120 ≤ g^4*(r:ℝ) := by + have hg4 : 0 < g^4 := pow_pos hg _ + have h1 : u ≤ (r:ℝ)*s.meanLog := by nlinarith only [hlo,hua,hg,ha0] + have h2 := mul_le_mul_of_nonneg_left h1 hg4.le + nlinarith only [h2,hlarge,hLp] + have hC : 0 < max D ((latticeBall (4*D)).card:ℝ) := lt_of_lt_of_le (by linarith) (le_max_left _ _) + have hdc : (0:ℝ) < (differences (walkSegment z n)).card := by + exact_mod_cast Finset.card_pos.mpr (differences_walkSegment_nonempty z n) + have hsz : (1-g)*a ≤ Real.log (differences (walkSegment z n)).card := by + have h := Real.log_le_log hA hAΔ + rw [Real.log_mul hC.ne' hdc.ne'] at h + have hgu := mul_le_mul_of_nonneg_left hua hg.le + have haeq : a = Real.log 16+Real.log (R*W) := by + exact Real.log_mul (by norm_num) hA.ne' + nlinarith only [h,hgu,haeq,hsize] + have hlog2 : Real.log (2*T) ≤ 2*s.meanLog := by + have hm := s.meanLog_bounds hne (by linarith) hpT + have hlog2 : Real.log 2 ≤ 1 := by + have h := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + rw [Real.log_mul (by norm_num : (2:ℝ)≠0) (by linarith : T≠0)] + linarith only [hm.1,hlog2,hL] + have hbc : 2*(b:ℝ)*Real.log (2*T) ≤ 8*g*a := by + have h := mul_le_mul_of_nonneg_left hlog2 (by positivity : (0:ℝ)≤2*b) + have hgu := mul_le_mul_of_nonneg_left hua hg.le + have hga : 0 ≤ g*a := by positivity + nlinarith only [h,hgu,hcost,hga] + refine ⟨by omega,?_⟩ + apply s.differenceLaw_fresh_lower z n hbr hr (e := star e) (R := 4*R) (W := 4*W) + (by simpa using he) hT hpT (by linarith) (by linarith) hg hg1 hL + (a := a) (by dsimp [a]; congr 1; ring) ha0.le hlo hhi hlr hsz hbc + exact differences_rectangle (walkSegment z n) hrect + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/PosteriorSampling.lean b/lean/OAI/NumberTheory/GaussianMoat/PosteriorSampling.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d4c3b82c86394e0b05adc27d85de5cb671c75f8 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/PosteriorSampling.lean @@ -0,0 +1,349 @@ +import OAI.NumberTheory.GaussianMoat.BackwardCoverage + +namespace OAI + +universe uOmega uAlpha uCapitalGamma uGroup uIota uBeta uGamma + +namespace GaussianMoat + +namespace FinLaw +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} {Γ : Type uCapitalGamma} {G : Type uGroup} [Fintype Ω] [Fintype α] [Fintype Γ] [Fintype G] + +lemma prob_and_split (p : FinLaw Ω) (A B : Ω → Prop) : + p.prob (fun ω => A ω ∧ B ω)+p.prob (fun ω => A ω ∧ ¬B ω)=p.prob A := by + simp only [prob,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro ω _ + by_cases ha : A ω <;> by_cases hb : B ω <;> simp [ha,hb] + +lemma prob_mix (p : FinLaw Ω) (q : Ω → FinLaw Γ) (E : Γ → Prop) : + (p.mix q).prob E = ∑ ω, p ω*(q ω).prob E := by + rw [← joint_map_snd,prob_map,prob_joint] + +lemma posterior_unfavorable (p : FinLaw Ω) (C : Ω → α) (Bad : Ω → Prop) : + (p.map C).prob (fun a => (1/2:ℝ)<(p.conditionOn C a).prob Bad) ≤ 2*p.prob Bad := by + have h := (p.map C).prob_le_expect_div (fun a => (p.conditionOn C a).prob Bad) + (fun a => (p.conditionOn C a).prob_nonneg _) (by norm_num : (0:ℝ)<1/2) + rw [p.conditionOn_prob] at h + linarith only [h] + +lemma mixed_exception_card (p : FinLaw Ω) (Good : Ω → Prop) (E : Ω → Finset G) + {e : ℝ} (he : 0≤e) (hE : ∀ ω, Good ω → ((E ω).card:ℝ)≤e) + (hG : (1/2:ℝ)≤p.prob Good) : + ((Finset.univ.filter (fun x : G => + p.prob (fun ω => Good ω ∧ x∉E ω)<1/4)).card:ℝ) ≤ 4*e := by + let u := fun x => p.prob (fun ω => Good ω ∧ x∉E ω) + let f := fun x => p.prob (fun ω => Good ω ∧ x∈E ω) + let K := Finset.univ.filter (fun x : G => u x<1/4) + have hsum : (∑ x : G, f x) ≤ e := by + simp only [f,prob] + rw [Finset.sum_comm] + have hh (ω : Ω) : (∑ x : G, if Good ω ∧ x∈E ω then p ω else 0) ≤ p ω*e := by + by_cases hg : Good ω + · have hc : (∑ x : G, if Good ω ∧ x∈E ω then p ω else 0) = p ω*(E ω).card := by + simp only [hg,true_and] + calc + _ = ∑ x : G, p ω*(if x∈E ω then (1:ℝ) else 0) := by + apply Finset.sum_congr rfl + intro x _ + split_ifs <;> simp + _ = _ := by rw [← Finset.mul_sum]; simp + rw [hc] + exact mul_le_mul_of_nonneg_left (hE ω hg) (p.nonneg ω) + · simp only [hg,false_and,ite_false,Finset.sum_const_zero] + exact mul_nonneg (p.nonneg ω) he + have ht := Finset.sum_le_sum (s := Finset.univ) (fun ω _ => hh ω) + simp only [← Finset.sum_mul,p.sum_one,one_mul] at ht + convert ht using 1 + apply Finset.sum_congr rfl + intro ω _ + apply Finset.sum_congr rfl + intro x _ + split_ifs <;> rfl + have hk (x : G) (hx : x∈K) : (1/4:ℝ)≤f x := by + have h := p.prob_and_split Good (fun ω => x∈E ω) + have hu : u x<1/4 := (Finset.mem_filter.mp hx).2 + change f x+u x=p.prob Good at h + linarith only [hu,h,hG] + have hl : (K.card:ℝ)/4 ≤ ∑ x∈K, f x := by + have h := Finset.sum_le_sum (s := K) (fun x hx => hk x hx) + simpa only [Finset.sum_const,nsmul_eq_mul,div_eq_mul_inv,one_mul] using h + have hr : (∑ x∈K, f x) ≤ ∑ x:G, f x := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ K) + (fun x _ _ => p.prob_nonneg _) + change (K.card:ℝ)≤4*e + linarith only [hl,hr,hsum] + +omit [Fintype G] in +lemma mixed_floor (p : FinLaw Ω) (q : Ω → FinLaw Γ) (Good : Ω → Prop) + (E : Ω → Finset G) (hit : Γ → G → Prop) {τ : ℝ} (hτ : 0≤τ) + (hq : ∀ ω, Good ω → ∀ x∉E ω, τ≤(q ω).prob (fun v => hit v x)) + (x : G) (hx : (1/4:ℝ)≤p.prob (fun ω => Good ω ∧ x∉E ω)) : + τ/4 ≤ (p.mix q).prob (fun v => hit v x) := by + rw [prob_mix] + have h (ω : Ω) : τ*(if Good ω ∧ x∉E ω then (1:ℝ) else 0) ≤ (q ω).prob (fun v => hit v x) := by + by_cases hg : Good ω ∧ x∉E ω + · rw [ite_eq_left hg,mul_one] + exact hq ω hg.1 x hg.2 + · rw [ite_eq_right hg,mul_zero] + exact (q ω).prob_nonneg _ + have hh := Finset.sum_le_sum (s := Finset.univ) (fun ω _ => + mul_le_mul_of_nonneg_left (h ω) (p.nonneg ω)) + have he : (∑ ω, p ω*(τ*(if Good ω ∧ x∉E ω then (1:ℝ) else 0))) = + τ*p.prob (fun ω => Good ω ∧ x∉E ω) := by + rw [prob,Finset.mul_sum] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> ring + rw [he] at hh + have hm := mul_le_mul_of_nonneg_left hx hτ + linarith only [hh,hm] + +lemma prob_exists_eq_sum_disjoint {ι : Type uIota} [Fintype ι] + (p : FinLaw Ω) (E : ι → Ω → Prop) + (h : ∀ ω i j, E i ω → E j ω → i=j) : + p.prob (fun ω => ∃ i, E i ω) = ∑ i, p.prob (E i) := by + simp only [prob] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + by_cases he : ∃ i, E i ω + · obtain ⟨i,hi⟩ := he + rw [ite_eq_left ⟨i,hi⟩,Finset.sum_eq_single i] + · simp [hi] + · intro j _ hji + exact ite_eq_right (fun hj => hji (h ω j i hj hi)) + · simp + · simp only [ite_eq_right he] + symm + apply Finset.sum_eq_zero + intro i _ + exact ite_eq_right (fun hi => he ⟨i,hi⟩) + +end FinLaw + +section +namespace FinLaw +open scoped BigOperators Classical +variable {Ω : Type uOmega} {ι : Type uIota} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} [Fintype Ω] [Fintype ι] [Fintype α] [Fintype β] + +lemma Hf_id (p : FinLaw Ω) : p.Hf id = p.entropy := by rw [Hf_eq_H,H,map_id] + +lemma cHf_joint_fst (p : FinLaw ι) (q : ι → FinLaw Ω) (X : ι → Ω → γ) : + (p.joint q).cHf (fun v => X v.1 v.2) Prod.fst = ∑ i, p i*(q i).Hf (X i) := by + unfold cHf + rw [Hf_pair_comm,Hf_joint_pair_vary] + have h := (p.joint q).Hf_map Prod.fst id + rw [joint_map_fst,Hf_id] at h + change p.entropy = (p.joint q).Hf Prod.fst at h + rw [← h] + ring + +lemma joint_iid_eval (p : FinLaw ι) (q : ι → FinLaw Ω) (n : ℕ) (i : Fin n) : + (p.joint (fun a => (q a).iid n)).map (fun v => (v.1,v.2 i)) = p.joint q := by + calc + _ = p.joint (fun a => ((q a).iid n).map (fun x : Fin n → Ω => x i)) := + joint_map_second p (fun a => (q a).iid n) (fun x : Fin n → Ω => x i) + _ = _ := by simp only [iid_map_eval] + +theorem conditional_iid_information (p : FinLaw (α × β)) (q : α × β → FinLaw Ω) (n : ℕ) : + (p.joint (fun a => (q a).iid n)).cIf (fun v => v.1.2) Prod.snd (fun v => v.1.1) ≤ + (n:ℝ)*(p.joint q).cIf (fun v => v.1.2) Prod.snd (fun v => v.1.1) := by + let P := p.joint (fun a => (q a).iid n) + let Q := p.joint q + have hsub := P.cHf_fintype_subadd Prod.snd (fun v => v.1.1) + have hmarg (i : Fin n) : P.cHf (fun v => v.2 i) (fun v => v.1.1) = + Q.cHf Prod.snd (fun v => v.1.1) := by + have h := P.cHf_map (fun v => (v.1,v.2 i)) Prod.snd (fun v => v.1.1) + rw [joint_iid_eval] at h + exact h.symm + simp only [hmarg,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hsub + have hcond : P.cHf Prod.snd (fun v => (v.1.1,v.1.2)) = + (n:ℝ)*Q.cHf Prod.snd (fun v => (v.1.1,v.1.2)) := by + change P.cHf Prod.snd Prod.fst = (n:ℝ)*Q.cHf Prod.snd Prod.fst + rw [cHf_joint_fst p (fun a => (q a).iid n) (fun _ x => x), + cHf_joint_fst p q (fun _ x => x)] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + change p a*((q a).iid n).Hf id = (n:ℝ)*(p a*(q a).Hf id) + rw [Hf_id,Hf_id,entropy_iid] + ring + change P.cIf _ _ _ ≤ (n:ℝ)*Q.cIf _ _ _ + rw [P.cIf_comm,Q.cIf_comm] + unfold cIf + rw [hcond] + nlinarith only [hsub] + +end FinLaw + +open scoped BigOperators Classical +namespace FinLaw +variable {Ω : Type uOmega} {α : Type uAlpha} {Γ : Type uCapitalGamma} {G : Type uGroup} [Fintype Ω] [Fintype α] [Fintype Γ] [Fintype G] + +noncomputable def passingList (hit : Γ → G → Prop) (n : ℕ) (v : Fin n → Γ) : Finset G := + Finset.univ.filter (fun x => ∀ i, ¬ hit (v i) x) + +lemma expect_card_passingList (q : FinLaw Γ) (hit : Γ → G → Prop) + (E : Finset G) {c : ℝ} (hhit : ∀ x ∉ E, c≤q.prob (fun v => hit v x)) (n : ℕ) : + (∑ v, q.iid n v*((passingList hit n v).card:ℝ)) ≤ + (E.card:ℝ)+(Fintype.card G:ℝ)*Real.exp (-(n:ℝ)*c) := by + have hprob (x : G) (hx : x ∉ E) : + (q.iid n).prob (fun v => x∈passingList hit n v) ≤ Real.exp (-(n:ℝ)*c) := by + have hh := q.iid_survival_exp (fun v => ¬hit v x) n (c := c) (by + rw [q.prob_compl]; linarith only [hhit x hx]) + simpa only [passingList,Finset.mem_filter,Finset.mem_univ,true_and] using hh + have he : (∑ v, q.iid n v*((passingList hit n v).card:ℝ)) = + ∑ x : G, (q.iid n).prob (fun v => x∈passingList hit n v) := by + have hc (v : Fin n → Γ) : ((passingList hit n v).card:ℝ) = + ∑ x : G, if x∈passingList hit n v then (1:ℝ) else 0 := by simp + simp only [hc,Finset.mul_sum,prob] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro v _ + by_cases hx : x∈passingList hit n v <;> simp only [hx,ite_true,ite_false,mul_one,mul_zero] + rw [he] + have hh (x : G) : (q.iid n).prob (fun v => x∈passingList hit n v) ≤ + (if x∈E then (1:ℝ) else 0)+Real.exp (-(n:ℝ)*c) := by + by_cases hx : x∈E + · simp only [hx,ite_true] + exact ((q.iid n).prob_le_one _).trans (le_add_of_nonneg_right (Real.exp_nonneg _)) + · simp only [hx,ite_false,zero_add] + exact hprob x hx + have hs := Finset.sum_le_sum (s := Finset.univ) (fun x _ => hh x) + simpa only [Finset.sum_add_distrib,Finset.sum_boole,Finset.filter_mem_eq_inter, + Finset.univ_inter,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] using hs + +lemma passingList_true (q : FinLaw Γ) (hit : Γ → G → Prop) (x : G) + (h : ∀ v, q v≠0 → ¬hit v x) (n : ℕ) : + ∀ v, q.iid n v≠0 → x∈passingList hit n v := by + intro v hv + simp only [passingList,Finset.mem_filter,Finset.mem_univ,true_and] + intro i + apply h + intro hz + apply hv + change (∏ j : Fin n, q (v j)) = 0 + exact Finset.prod_eq_zero (Finset.mem_univ i) hz + +lemma expect_log_le_log_expect (p : FinLaw Ω) (f : Ω → ℝ) + (hf : ∀ ω, p ω≠0 → 0 if p ω=0 then (1:ℝ) else f ω + have hh := strictConcaveOn_log_Ioi.concaveOn.le_map_sum + (fun ω _ => p.nonneg ω) p.sum_one (fun ω _ => show 0 hit v y)) (n : ℕ) : + (∑ v, q.iid n v*Real.log (passingList hit n v).card) ≤ + Real.log ((E.card:ℝ)+(Fintype.card G:ℝ)*Real.exp (-(n:ℝ)*c)) := by + have hp (v : Fin n → Γ) (hv : q.iid n v≠0) : (0:ℝ)<(passingList hit n v).card := by + exact_mod_cast Finset.card_pos.mpr ⟨x,q.passingList_true hit x htrue n v hv⟩ + apply ((q.iid n).expect_log_le_log_expect (fun v => ((passingList hit n v).card:ℝ)) hp).trans + apply Real.log_le_log ?_ (q.expect_card_passingList hit E hhit n) + have hex : ∃ v, 0 < q.iid n v := by + by_contra hh + push Not at hh + have hz : ∀ v, q.iid n v=0 := fun v => le_antisymm (hh v) ((q.iid n).nonneg v) + have hs := (q.iid n).sum_one + simp only [hz,Finset.sum_const_zero] at hs + norm_num at hs + obtain ⟨v,hv⟩ := hex + exact Finset.sum_pos' (fun v _ => mul_nonneg ((q.iid n).nonneg v) (Nat.cast_nonneg _)) + ⟨v,Finset.mem_univ v,mul_pos hv (hp v hv.ne')⟩ + +lemma conditional_passing_support (p : FinLaw Ω) (X : Ω → G) (C : Ω → α) + (hit : α → G → Prop) (hs : ∀ ω, p ω≠0 → ¬hit (C ω) (X ω)) : + p.cHf X C ≤ ∑ a, p.map C a*Real.log ((Finset.univ.filter (fun x => ¬hit a x)).card) := by + have h := p.condH_le_support X C (fun a => Finset.univ.filter (fun x => ¬hit a x)) (by + intro ω hw + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact hs ω hw) + simpa only [condH,← Hf_eq_H,cHf] using h + +end FinLaw +end + +namespace FinLaw +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} [Fintype Ω] + +lemma cHf_prefix_step (p : FinLaw Ω) {n k : ℕ} (X : Ω → Fin n → α) + (C : Ω → β) (hk : k X ω ⟨k,hk⟩) (fun ω => (prefixVar X (Equiv.refl _) k ω,C ω)) := by + have he : p.cHf (prefixVar X (Equiv.refl _) (k+1)) C = + p.cHf (fun ω => (prefixVar X (Equiv.refl _) k ω,X ω ⟨k,hk⟩)) C := by + apply p.cHf_eq_of_fibers + intro ω ν _ + constructor + · intro h + refine Prod.ext ?_ ?_ + · funext i + by_cases hi : i.val X ω i) (S i) := by + have h (k : ℕ) (hk : k≤n) : p.cHf (prefixVar X (Equiv.refl _) k) C ≤ + ∑ i : Fin k, p.cHf (fun ω => X ω ⟨i.val,by omega⟩) (S ⟨i.val,by omega⟩) := by + induction k with + | zero => + have he : p.cHf (prefixVar X (Equiv.refl _) 0) C = 0 := by + unfold cHf + have hh : p.Hf (fun ω => (prefixVar X (Equiv.refl _) 0 ω,C ω)) = p.Hf C := by + apply p.Hf_eq_of_fibers + intro ω ν + simp only [prefixVar_zero,Prod.mk.injEq,true_and] + rw [hh,sub_self] + simp only [he,Finset.univ_eq_empty,Finset.sum_empty,le_refl] + | succ k ih => + rw [p.cHf_prefix_step X C (by omega),Fin.sum_univ_castSucc] + have hm := p.cHf_mono_of_refines (fun ω => X ω ⟨k,by omega⟩) + (fun ω => (prefixVar X (Equiv.refl _) k ω,C ω)) (S ⟨k,by omega⟩) + (fun ω ν hh => hS ⟨k,by omega⟩ ω ν (congrArg Prod.fst hh) (congrArg Prod.snd hh)) + exact add_le_add (ih (by omega)) hm + have he : p.cHf (prefixVar X (Equiv.refl _) n) C=p.cHf X C := by + apply p.cHf_eq_of_fibers + intro ω ν _ + constructor + · intro h + funext i + simpa [prefixVar,i.isLt] using congrFun h i + · intro h + funext i + simp only [prefixVar,i.isLt,ite_eq_left,Equiv.refl_apply] + exact congrArg some (congrFun h i) + simpa only [he] using h n le_rfl + +end FinLaw +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/PrimeMass.lean b/lean/OAI/NumberTheory/GaussianMoat/PrimeMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..924bf62a01e01d365dfa9dcb48b89843276a2edc --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/PrimeMass.lean @@ -0,0 +1,422 @@ +import OAI.NumberTheory.GaussianMoat.ResidueQuotient + +namespace OAI + +namespace GaussianMoat + +open Filter Topology Finset +namespace PrimeLogMass +open ArithmeticFunction.vonMangoldt Complex + +lemma residue_real_series {q : ℕ} [NeZero q] {a : ZMod q} (ha : IsUnit a) + {x : ℝ} (hx : 1 < x) : + ∑' n, residueClass a n / (n : ℝ) ^ x = + (LFunctionResidueClassAux a x).re + (q.totient : ℝ)⁻¹ / (x - 1) := by + refine ofReal_injective ?_ + simp only [ofReal_tsum, ofReal_div, ofReal_cpow (Nat.cast_nonneg _), ofReal_natCast, + ofReal_add, ofReal_inv, ofReal_sub, ofReal_one] + simp_rw [← LFunctionResidueClassAux_real ha hx, + eqOn_LFunctionResidueClassAux ha <| Set.mem_ofPred.mpr (ofReal_re x ▸ hx), sub_add_cancel, + LSeries, LSeries.term] + refine tsum_congr fun n ↦ ?_ + split_ifs with hn + · simp only [hn, residueClass_apply_zero, ofReal_zero, zero_div] + · rfl + +theorem residue_moment_limit {q : ℕ} [NeZero q] {a : ZMod q} (ha : IsUnit a) + {j : ℝ} (hj : 0 < j) : + Tendsto (fun X : ℝ => (∑' n, residueClass a n / (n : ℝ) ^ (1+j/X)) / X) + atTop (𝓝 ((q.totient : ℝ)⁻¹ / j)) := by + have hinv : Tendsto (fun X : ℝ => j/X) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop tendsto_id + have harg : Tendsto (fun X : ℝ => ((1+j/X : ℝ) : ℂ)) atTop (𝓝 1) := by + have hr : Tendsto (fun X : ℝ => 1+j/X) atTop (𝓝 1) := by + simpa using hinv.const_add 1 + simpa only [Function.comp_def,ofReal_one] using + Complex.continuous_ofReal.continuousAt.tendsto.comp hr + have hmem : ∀ᶠ X : ℝ in atTop, ((1+j/X : ℝ) : ℂ) ∈ {s : ℂ | 1 ≤ s.re} := by + filter_upwards [eventually_gt_atTop (0 : ℝ)] with X hX + change 1 ≤ 1+j/X + exact le_add_of_nonneg_right (div_nonneg hj.le hX.le) + have hc : Tendsto (fun X : ℝ => (LFunctionResidueClassAux a ((1+j/X : ℝ) : ℂ)).re) + atTop (𝓝 (LFunctionResidueClassAux a 1).re) := by + exact Complex.continuous_re.continuousAt.tendsto.comp + ((continuousOn_LFunctionResidueClassAux a 1 (by simp)).tendsto.comp + (tendsto_nhdsWithin_iff.mpr ⟨harg,hmem⟩)) + have hz := hc.div_atTop tendsto_id + have hl : Tendsto (fun X : ℝ => (LFunctionResidueClassAux a ((1+j/X : ℝ) : ℂ)).re / X + + (q.totient : ℝ)⁻¹ / j) atTop (𝓝 ((q.totient : ℝ)⁻¹ / j)) := by + simpa using hz.add_const ((q.totient : ℝ)⁻¹ / j) + apply hl.congr' + filter_upwards [eventually_gt_atTop (0 : ℝ)] with X hX + rw [residue_real_series ha (by linarith [div_pos hj hX] : 1 < 1+j/X)] + rw [add_div,add_sub_cancel_left,div_div,div_mul_cancel₀ _ hX.ne'] + +open intervalIntegral MeasureTheory + +noncomputable def betaMoment (m n : ℕ) : ℝ := ∫ x in (0 : ℝ)..1, x^m*(1-x)^n + +lemma betaMoment_pos (m n : ℕ) : 0 < betaMoment m n := by + apply intervalIntegral.intervalIntegral_pos_of_pos_on + · exact (by fun_prop : Continuous (fun x : ℝ => x^m*(1-x)^n)).intervalIntegrable _ _ + · intro x hx + exact mul_pos (pow_pos hx.1 _) (pow_pos (sub_pos.mpr hx.2) _) + · norm_num + +lemma betaMoment_succ (m n : ℕ) : + betaMoment (m+1) n = (m+1 : ℝ)/(m+n+2)*betaMoment m n := by + have hd (x : ℝ) : HasDerivAt (fun x : ℝ => x^(m+1)*(1-x)^(n+1)) + ((m+1 : ℝ)*x^m*(1-x)^(n+1) - (n+1 : ℝ)*x^(m+1)*(1-x)^n) x := by + have h1 : HasDerivAt (fun y : ℝ => y^(m+1)) ((m+1 : ℝ)*x^m) x := by + simpa only [Nat.add_sub_cancel,Nat.cast_add,Nat.cast_one] using hasDerivAt_pow (m+1) x + have h2 : HasDerivAt (fun y : ℝ => (1-y)^(n+1)) (-(n+1 : ℝ)*(1-x)^n) x := by + simpa only [Nat.add_sub_cancel, Nat.cast_add, Nat.cast_one, id_eq, sub_zero, zero_sub, + mul_neg_one, neg_mul] using! ((hasDerivAt_id x).const_sub 1).pow (n+1) + convert! h1.mul h2 using 1; ring + have hInt := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun x _ => hd x) + (by exact (by fun_prop : Continuous (fun x : ℝ => + (m+1 : ℝ)*x^m*(1-x)^(n+1)-(n+1 : ℝ)*x^(m+1)*(1-x)^n)).intervalIntegrable 0 1) + have hsplit : betaMoment m (n+1)+betaMoment (m+1) n = betaMoment m n := by + unfold betaMoment + rw [← intervalIntegral.integral_add] + · congr 1 + funext x + rw [pow_succ,pow_succ] + ring + · exact (by fun_prop : Continuous (fun x : ℝ => x^m*(1-x)^(n+1))).intervalIntegrable _ _ + · exact (by fun_prop : Continuous (fun x : ℝ => x^(m+1)*(1-x)^n)).intervalIntegrable _ _ + have hi (u v : ℕ) : IntervalIntegrable (fun x : ℝ => x^u*(1-x)^v) volume 0 1 := + (by fun_prop : Continuous _).intervalIntegrable _ _ + have hmul (c : ℝ) (u v : ℕ) : + (∫ x : ℝ in 0..1, c*x^u*(1-x)^v) = c*betaMoment u v := by + simp only [mul_assoc,intervalIntegral.integral_const_mul,betaMoment] + rw [intervalIntegral.integral_sub + (by simpa only [mul_assoc] using (hi m (n+1)).const_mul (m+1 : ℝ)) + (by simpa only [mul_assoc] using (hi (m+1) n).const_mul (n+1 : ℝ)), + hmul,hmul] at hInt + simp only [one_pow,sub_self,zero_pow (Nat.succ_ne_zero _),mul_zero,zero_mul,sub_zero] at hInt + have hn : (0 : ℝ) < m+n+2 := by positivity + rw [div_mul_eq_mul_div] + apply (eq_div_iff hn.ne').mpr + nlinarith + +noncomputable def windowPolynomialAux (m n : ℕ) : Polynomial ℝ := + Polynomial.X^m*(1-Polynomial.X)^n* + ((Polynomial.X-Polynomial.C (7/20))*(Polynomial.C (11/30)-Polynomial.X)) + +lemma windowPolynomialAux_eval (m n : ℕ) (y : ℝ) : + Polynomial.eval y (windowPolynomialAux m n) = y^m*(1-y)^n*((y-7/20)*(11/30-y)) := by + simp only [windowPolynomialAux,Polynomial.eval_mul,Polynomial.eval_pow, + Polynomial.eval_sub,Polynomial.eval_one,Polynomial.eval_X,Polynomial.eval_C] + +noncomputable def windowPolynomial : Polynomial ℝ := windowPolynomialAux 1431 2567 + +lemma windowPolynomial_eval (y : ℝ) : + Polynomial.eval y windowPolynomial = y^1431*(1-y)^2567*((y-7/20)*(11/30-y)) := + windowPolynomialAux_eval 1431 2567 y + +lemma windowPolynomial_nonpos {y : ℝ} (hy : y ∈ Set.Icc (0 : ℝ) 1) + (hout : y ≤ 7/20 ∨ 11/30 ≤ y) : Polynomial.eval y windowPolynomial ≤ 0 := by + rw [windowPolynomial_eval] + have hp : 0 ≤ y^1431*(1-y)^2567 := mul_nonneg (pow_nonneg hy.1 _) (pow_nonneg (sub_nonneg.mpr hy.2) _) + apply mul_nonpos_of_nonneg_of_nonpos hp + rcases hout with hl | hr + · exact mul_nonpos_of_nonpos_of_nonneg (by linarith only [hl]) (by linarith only [hl]) + · exact mul_nonpos_of_nonneg_of_nonpos (by linarith only [hr]) (by linarith only [hr]) + +lemma betaMoment_quadratic (m n : ℕ) (a b : ℝ) : + (∫ x : ℝ in 0..1, x^m*(1-x)^n*((x-a)*(b-x))) = + (a+b)*betaMoment (m+1) n-betaMoment (m+2) n-a*b*betaMoment m n := by + have he : (fun x : ℝ => x^m*(1-x)^n*((x-a)*(b-x))) = fun x => + (a+b)*(x^(m+1)*(1-x)^n)-(x^(m+2)*(1-x)^n)-a*b*(x^m*(1-x)^n) := by + funext x + simp only [pow_add,pow_one,pow_two] + ring + have hi (u v : ℕ) : IntervalIntegrable (fun x : ℝ => x^u*(1-x)^v) volume 0 1 := + (by fun_prop : Continuous _).intervalIntegrable _ _ + rw [he,intervalIntegral.integral_sub ((hi (m+1) n).const_mul _ |>.sub (hi (m+2) n)) + ((hi m n).const_mul _), + intervalIntegral.integral_sub ((hi (m+1) n).const_mul _) (hi (m+2) n), + intervalIntegral.integral_const_mul,intervalIntegral.integral_const_mul] + rfl + +lemma windowPolynomial_integral_pos : 0 < ∫ x : ℝ in 0..1, Polynomial.eval x windowPolynomial := by + simp only [windowPolynomial_eval] + rw [betaMoment_quadratic] + change 0 < (7/20+11/30)*betaMoment 1432 2567 - betaMoment 1433 2567 - + (7/20*(11/30))*betaMoment 1431 2567 + rw [betaMoment_succ 1432 2567, betaMoment_succ 1431 2567] + norm_num only [Nat.cast_ofNat] + have hp := betaMoment_pos 1431 2567 + nlinarith + +lemma polynomial_integral_coeff (P : Polynomial ℝ) : + (∫ x : ℝ in 0..1, P.eval x) = ∑ j ∈ P.support, P.coeff j / (j+1 : ℝ) := by + simp_rw [Polynomial.eval_eq_sum,Polynomial.sum_def] + rw [intervalIntegral.integral_finsetSum] + · simp only [intervalIntegral.integral_const_mul,integral_pow,one_pow, + zero_pow (Nat.succ_ne_zero _),sub_zero,mul_one_div] + · intro j _ + exact (by fun_prop : Continuous (fun x : ℝ => P.coeff j*x^j)).intervalIntegrable _ _ + +theorem residue_polynomial_moment_limit {q : ℕ} [NeZero q] {a : ZMod q} (ha : IsUnit a) + (P : Polynomial ℝ) : + Tendsto (fun X : ℝ => ∑ j ∈ P.support, P.coeff j * + ((∑' n, residueClass a n / (n : ℝ) ^ (1+(j+1 : ℝ)/X)) / X)) atTop + (𝓝 ((q.totient : ℝ)⁻¹ * (∫ x : ℝ in 0..1, P.eval x))) := by + have h (j : ℕ) := (residue_moment_limit ha (show (0 : ℝ) < j+1 by positivity)).const_mul (P.coeff j) + have hs := tendsto_finsetSum P.support (fun j _ => h j) + convert hs using 1 + congr 1 + rw [polynomial_integral_coeff,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + +lemma residue_summable {q : ℕ} [NeZero q] (a : ZMod q) {x : ℝ} (hx : 1 < x) : + Summable (fun n : ℕ => residueClass a n / (n : ℝ)^x) := + LSeries.summable_real_of_abscissaOfAbsConv_lt + ((abscissaOfAbsConv_residueClass_le_one a).trans_lt (by exact_mod_cast hx)) + +lemma laplace_power (n j : ℕ) (X : ℝ) (hn : n ≠ 0) : + (n : ℝ) ^ (-(j+1 : ℝ)/X) = + (Real.exp (-Real.log n / X))^(j+1) := by + rw [Real.rpow_def_of_pos (by exact_mod_cast Nat.pos_of_ne_zero hn), ← Real.exp_nat_mul] + congr 1 + push_cast + ring + +lemma laplace_term {q : ℕ} [NeZero q] (a : ZMod q) (n j : ℕ) (X : ℝ) : + residueClass a n / (n : ℝ)^(1+(j+1 : ℝ)/X) = + residueClass a n / n * (Real.exp (-Real.log n/X))^(j+1) := by + rcases n.eq_zero_or_pos with rfl | hn + · simp + · rw [Real.rpow_add (by exact_mod_cast hn),Real.rpow_one,div_mul_eq_div_div, + div_eq_mul_inv _ ((n : ℝ)^((j+1 : ℝ)/X)), ← Real.rpow_neg (by positivity), + show -((j+1 : ℝ)/X) = -(j+1 : ℝ)/X by ring,laplace_power n j X (by omega)] + +lemma polynomial_laplace_series {q : ℕ} [NeZero q] (a : ZMod q) + (P : Polynomial ℝ) {X : ℝ} (hX : 0 < X) : + (∑ j ∈ P.support, P.coeff j * + (∑' n, residueClass a n / (n : ℝ)^(1+(j+1 : ℝ)/X))) = + ∑' n, residueClass a n / n * Real.exp (-Real.log n/X) * + Polynomial.eval (Real.exp (-Real.log n/X)) P := by + have hs (j : ℕ) : Summable (fun n : ℕ => residueClass a n / + (n : ℝ)^(1+(j+1 : ℝ)/X)) := residue_summable a (by + have : 0 < (j+1 : ℝ)/X := div_pos (by positivity) hX + linarith) + simp_rw [← tsum_mul_left] + rw [← Summable.tsum_finsetSum (fun j _ => (hs j).mul_left (P.coeff j))] + apply tsum_congr + intro n + simp_rw [laplace_term,Polynomial.eval_eq_sum,Polynomial.sum_def,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + rw [pow_succ] + ring + +lemma polynomial_laplace_summable {q : ℕ} [NeZero q] (a : ZMod q) + (P : Polynomial ℝ) {X : ℝ} (hX : 0 < X) : + Summable (fun n : ℕ => residueClass a n / n * Real.exp (-Real.log n/X) * + Polynomial.eval (Real.exp (-Real.log n/X)) P) := by + have hs (j : ℕ) : Summable (fun n : ℕ => P.coeff j * (residueClass a n / + (n : ℝ)^(1+(j+1 : ℝ)/X))) := (residue_summable a (by + have : 0 < (j+1 : ℝ)/X := div_pos (by positivity) hX + linarith)).mul_left _ + apply (summable_sum (s := P.support) (fun j _ => hs j)).congr + intro n + simp_rw [laplace_term,Polynomial.eval_eq_sum,Polynomial.sum_def,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + rw [pow_succ] + ring + +lemma windowPolynomial_le_one {y : ℝ} (hy : y ∈ Set.Icc (0 : ℝ) 1) : + Polynomial.eval y windowPolynomial ≤ 1 := by + by_cases hl : y ≤ 7/20 + · exact (windowPolynomial_nonpos hy (.inl hl)).trans (by norm_num) + by_cases hr : 11/30 ≤ y + · exact (windowPolynomial_nonpos hy (.inr hr)).trans (by norm_num) + rw [windowPolynomial_eval] + have h1 : 0 ≤ y^1431 := pow_nonneg hy.1 _ + have h2 : 0 ≤ (1-y)^2567 := pow_nonneg (by linarith only [hy.2]) _ + have he : y^1431*(1-y)^2567 ≤ 1 := + (mul_le_of_le_one_left h2 (pow_le_one₀ hy.1 hy.2)).trans + (pow_le_one₀ (by linarith only [hy.2]) (by linarith only [hy.1])) + have hf : (y-7/20)*(11/30-y) ≤ 1 := + (mul_le_of_le_one_left (by linarith only [hr]) (by linarith only [hy.2])).trans + (by linarith only [hy.1]) + exact (mul_le_of_le_one_left + (mul_nonneg (by linarith only [hl]) (by linarith only [hr])) he).trans hf + +lemma exp_window_lower : Real.exp (-(10499/10000 : ℝ)) < 7/20 := by + have h := Real.quadratic_le_exp_of_nonneg (by norm_num : (0 : ℝ) ≤ 499/10000) + have he := Real.exp_one_gt_d9 + have hp : Real.exp (10499/10000 : ℝ) = Real.exp 1 * Real.exp (499/10000 : ℝ) := by + rw [← Real.exp_add] + norm_num + rw [Real.exp_neg,hp] + rw [inv_eq_one_div] + apply (div_lt_iff₀ (by positivity)).mpr + nlinarith + +lemma exp_window_upper : (11/30 : ℝ) < Real.exp (-(1001/1000 : ℝ)) := by + have h := Real.exp_bound_div_one_sub_of_interval (by norm_num : (0 : ℝ) ≤ 1/1000) + (by norm_num : (1/1000 : ℝ) < 1) + have hp : Real.exp (1001/1000 : ℝ) = Real.exp 1 * Real.exp (1/1000 : ℝ) := by + rw [← Real.exp_add] + norm_num + rw [Real.exp_neg,inv_eq_one_div] + apply (lt_div_iff₀ (Real.exp_pos _)).mpr + rw [hp] + have hm := mul_le_mul_of_nonneg_left h (Real.exp_pos 1).le + norm_num at hm + nlinarith [Real.exp_one_lt_d9] + +noncomputable def windowIndices (X : ℝ) : Finset ℕ := by + classical + exact (Finset.range (⌊Real.exp (10499/10000*X)⌋₊+1)).filter (fun n => Real.exp (1001/1000*X) ≤ n) + +lemma mem_windowIndices (X : ℝ) (n : ℕ) : + n ∈ windowIndices X ↔ Real.exp (1001/1000*X) ≤ n ∧ (n : ℝ) ≤ Real.exp (10499/10000*X) := by + simp only [windowIndices,Finset.mem_filter,Finset.mem_range,Nat.lt_succ_iff, + Nat.le_floor_iff (Real.exp_pos _).le,and_comm] + +lemma laplace_window_nonpos {X : ℝ} (hX : 0 < X) (n : ℕ) + (hn : n ≠ 0) (hout : n ∉ windowIndices X) : + Polynomial.eval (Real.exp (-Real.log n/X)) windowPolynomial ≤ 0 := by + have hnp : (0 : ℝ) < n := by exact_mod_cast Nat.pos_of_ne_zero hn + have hlog : 0 ≤ Real.log n := Real.log_nonneg (by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hn) + apply windowPolynomial_nonpos + · exact ⟨(Real.exp_pos _).le,Real.exp_le_one_iff.mpr (div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hlog) hX.le)⟩ + rw [mem_windowIndices,not_and_or] at hout + rcases hout with hl | hr + · right + have : Real.log n < 1001/1000*X := (Real.log_lt_iff_lt_exp hnp).mpr (lt_of_not_ge hl) + apply exp_window_upper.le.trans + apply Real.exp_le_exp.mpr + apply (le_div_iff₀ hX).mpr + linarith + · left + have : 10499/10000*X < Real.log n := (Real.lt_log_iff_exp_lt hnp).mpr (lt_of_not_ge hr) + apply le_trans _ exp_window_lower.le + apply Real.exp_le_exp.mpr + apply (div_le_iff₀ hX).mpr + linarith + +lemma window_mass_dominates {q : ℕ} [NeZero q] (a : ZMod q) {X : ℝ} (hX : 0 < X) : + (∑' n, residueClass a n / n * Real.exp (-Real.log n/X) * + Polynomial.eval (Real.exp (-Real.log n/X)) windowPolynomial) ≤ + ∑ n ∈ windowIndices X, residueClass a n / n := by + classical + let f := fun n : ℕ => if n ∈ windowIndices X then residueClass a n / n else 0 + have hf : Summable f := summable_of_ne_finset_zero (s := windowIndices X) (by + intro n hn + simp [f,hn]) + have ht : (∑' n, f n) = ∑ n ∈ windowIndices X, residueClass a n / n := by + rw [tsum_eq_sum (s := windowIndices X) (by intro n hn; simp [f,hn])] + apply Finset.sum_congr rfl + intro n hn + simp [f,hn] + rw [← ht] + apply Summable.tsum_le_tsum _ (polynomial_laplace_summable a windowPolynomial hX) hf + intro n + by_cases hn : n = 0 + · subst n + simp [f] + have hlog : 0 ≤ Real.log n := Real.log_nonneg (by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hn) + have hy : Real.exp (-Real.log n/X) ∈ Set.Icc (0 : ℝ) 1 := + ⟨(Real.exp_pos _).le,Real.exp_le_one_iff.mpr (div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hlog) hX.le)⟩ + have hw : 0 ≤ residueClass a n / n := div_nonneg (residueClass_nonneg a n) (Nat.cast_nonneg n) + by_cases hm : n ∈ windowIndices X + · simp only [f,ite_eq_left hm] + calc + _ ≤ residueClass a n / n * Real.exp (-Real.log n/X) := by + exact mul_le_of_le_one_right (mul_nonneg hw hy.1) (windowPolynomial_le_one hy) + _ ≤ _ := mul_le_of_le_one_right hw hy.2 + · simp only [f,ite_eq_right hm] + exact mul_nonpos_of_nonneg_of_nonpos (mul_nonneg hw hy.1) (laplace_window_nonpos hX n hn hm) + +theorem eventually_residue_window_mass {q : ℕ} [NeZero q] {a : ZMod q} (ha : IsUnit a) : + ∃ c : ℝ, 0 < c ∧ ∀ᶠ X : ℝ in atTop, + c*X ≤ ∑ n ∈ windowIndices X, residueClass a n / n := by + let c := (q.totient : ℝ)⁻¹ * (∫ x : ℝ in 0..1, Polynomial.eval x windowPolynomial) + have hc : 0 < c := mul_pos (inv_pos.mpr (by exact_mod_cast q.totient.pos_of_neZero)) + windowPolynomial_integral_pos + have hlim := residue_polynomial_moment_limit ha windowPolynomial + have he : ∀ᶠ X : ℝ in atTop, + c/2 < ∑ j ∈ windowPolynomial.support, windowPolynomial.coeff j * + ((∑' n, residueClass a n / (n : ℝ)^(1+(j+1 : ℝ)/X)) / X) := + hlim.eventually (eventually_gt_nhds (by dsimp [c]; linarith only [hc] : c/2 < c)) + refine ⟨c/2,half_pos hc,?_⟩ + filter_upwards [he,eventually_gt_atTop (0 : ℝ)] with X h hX + have hid := polynomial_laplace_series a windowPolynomial hX + have h' : c/2 < (∑' n, residueClass a n / n * Real.exp (-Real.log n/X) * + Polynomial.eval (Real.exp (-Real.log n/X)) windowPolynomial) / X := by + rw [← hid,Finset.sum_div] + simpa only [mul_div_assoc] using h + exact ((lt_div_iff₀ hX).mp h').le.trans (window_mass_dominates a hX) + +theorem eventually_prime_window_mass {q : ℕ} [NeZero q] {a : ZMod q} (ha : IsUnit a) : + ∃ c : ℝ, 0 < c ∧ ∀ᶠ X : ℝ in atTop, + c*X ≤ ∑ n ∈ (windowIndices X).filter Nat.Prime, residueClass a n / n := by + classical + obtain ⟨c,hc,he⟩ := eventually_residue_window_mass ha + let f : ℕ → ℝ := fun n => (if n.Prime then 0 else residueClass a n) / n + have hf : Summable f := summable_residueClass_non_primes_div a + have hn : ∀ n, 0 ≤ f n := by intro n; dsimp [f]; split_ifs <;> positivity [residueClass_nonneg a n] + refine ⟨c/2,half_pos hc,?_⟩ + filter_upwards [he,eventually_ge_atTop (2*(∑' n, f n)/c)] with X hX hK + have hb := hf.sum_le_tsum (windowIndices X) (fun n _ => hn n) + have hid : (∑ n ∈ windowIndices X, residueClass a n/n) = + (∑ n ∈ (windowIndices X).filter Nat.Prime, residueClass a n/n) + + ∑ n ∈ windowIndices X, f n := by + rw [Finset.sum_filter, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro n _ + dsimp [f] + split_ifs <;> simp + rw [hid] at hX + have hbig := (div_le_iff₀ hc).mp hK + nlinarith + +end PrimeLogMass + +theorem irreducible_of_prime_norm {π : GaussianInt} {p : ℕ} + (hp : p.Prime) (hn : π.norm = (p : ℤ)) : Irreducible π := by + have hnp : π.norm.natAbs = p := by rw [hn]; simp + constructor + · intro hu + have h := Zsqrtd.norm_eq_one_iff.mpr hu + rw [hnp] at h + exact hp.ne_one h + · intro a b hab + have he : a.norm.natAbs*b.norm.natAbs = p := by + rw [← Int.natAbs_mul,← Zsqrtd.norm_mul,← hab,hnp] + have hi : Irreducible p := (Nat.irreducible_iff_nat_prime p).mpr hp + rcases hi.isUnit_or_isUnit he.symm with ha | hb + · left + apply Zsqrtd.norm_eq_one_iff.mp + simpa only [Nat.isUnit_iff] using ha + · right + apply Zsqrtd.norm_eq_one_iff.mp + simpa only [Nat.isUnit_iff] using hb + +theorem exists_split_factor {p : ℕ} (hp : p.Prime) (hmod : p % 4 = 1) : + ∃ π : GaussianInt, Irreducible π ∧ π.norm = (p : ℤ) := by + let : Fact p.Prime := ⟨hp⟩ + have hnp : ¬ Irreducible (p : GaussianInt) := by + intro hi + have h := (GaussianInt.prime_iff_mod_four_eq_three_of_nat_prime p).mp hi.prime + omega + obtain ⟨a,b,hab⟩ := GaussianInt.sq_add_sq_of_nat_prime_of_not_irreducible p hnp + have hn : (⟨a,b⟩ : GaussianInt).norm = (p : ℤ) := by + simp only [Zsqrtd.norm] + norm_num only [Int.reduceNeg,neg_mul,sub_neg_eq_add] + have h : (a : ℤ)^2+(b : ℤ)^2 = (p : ℤ) := by exact_mod_cast hab + simpa only [pow_two,one_mul] using h + exact ⟨⟨a,b⟩,irreducible_of_prime_norm hp hn,hn⟩ + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/ResidueQuotient.lean b/lean/OAI/NumberTheory/GaussianMoat/ResidueQuotient.lean new file mode 100644 index 0000000000000000000000000000000000000000..98fd6033e3b94ed466dbfbcf87da5002902f98a8 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/ResidueQuotient.lean @@ -0,0 +1,82 @@ +import OAI.NumberTheory.GaussianMoat.FiniteEntropy + +namespace OAI + +namespace GaussianMoat + +noncomputable def multiples (π : GaussianInt) : Submodule ℤ GaussianInt := + (twoVectorMap π (π * ⟨0,1⟩)).range + +lemma twoVectorMap_mul_i (π z : GaussianInt) : + twoVectorMap π (π * ⟨0,1⟩) z = π*z := by + rw [twoVectorMap_apply] + ext <;> simp [zsmul_eq_mul,Zsqrtd.re_mul,Zsqrtd.im_mul] <;> ring + +lemma mem_multiples (π z : GaussianInt) : z ∈ multiples π ↔ π ∣ z := by + simp only [multiples, LinearMap.mem_range, twoVectorMap_mul_i] + exact ⟨fun ⟨a,ha⟩ => ⟨a,ha.symm⟩,fun ⟨a,ha⟩ => ⟨a,ha.symm⟩⟩ + +lemma multiples_index {π : GaussianInt} (hπ : π ≠ 0) : + Nat.card (GaussianInt ⧸ multiples π) = π.norm.natAbs := by + have he : π.re*(π*⟨0,1⟩).im-π.im*(π*⟨0,1⟩).re = π.norm := by + simp [Zsqrtd.re_mul,Zsqrtd.im_mul,Zsqrtd.norm] + have hn : π.norm ≠ 0 := (GaussianInt.norm_pos.mpr hπ).ne' + have h := twoVectorMap_quotient_card (a := π) (b := π*⟨0,1⟩) (he.trans_ne hn) + simpa only [multiples,he] using h + +noncomputable def gaussianResidue (π z : GaussianInt) : GaussianInt ⧸ multiples π := + Submodule.Quotient.mk z + +lemma gaussianResidue_eq (π z w : GaussianInt) : + gaussianResidue π z = gaussianResidue π w ↔ π ∣ z-w := by + rw [gaussianResidue,gaussianResidue,Submodule.Quotient.eq,mem_multiples] + +instance : Countable GaussianInt := latticeCoords.injective.countable + +instance (π : GaussianInt) : Countable (GaussianInt ⧸ multiples π) := + (Submodule.Quotient.mk_surjective (p := multiples π)).countable + +noncomputable def residueCode (π z : GaussianInt) : ℕ := by + let := Encodable.ofCountable (GaussianInt ⧸ multiples π) + exact Encodable.encode (gaussianResidue π z) + +lemma residueCode_eq (π z w : GaussianInt) : + residueCode π z = residueCode π w ↔ π ∣ z-w := by + let := Encodable.ofCountable (GaussianInt ⧸ multiples π) + change Encodable.encode (gaussianResidue π z) = Encodable.encode (gaussianResidue π w) ↔ _ + rw [Encodable.encode_inj,gaussianResidue_eq] + +lemma residueCode_sub {π x y x' y' : GaussianInt} + (hx : residueCode π x = residueCode π x') (hy : residueCode π y = residueCode π y') : + residueCode π (x-y) = residueCode π (x'-y') := by + rw [residueCode_eq] at * + convert dvd_sub hx hy using 1; ring + +lemma residueCode_add {π x y x' y' : GaussianInt} + (hx : residueCode π x = residueCode π x') (hy : residueCode π y = residueCode π y') : + residueCode π (x+y) = residueCode π (x'+y') := by + rw [residueCode_eq] at * + convert dvd_add hx hy using 1; ring + +lemma finite_gaussianResidue {π : GaussianInt} (hπ : π ≠ 0) : + Finite (GaussianInt ⧸ multiples π) := by + apply Nat.finite_of_card_ne_zero + rw [multiples_index hπ] + simpa only [Int.natAbs_ne_zero] using (GaussianInt.norm_pos.mpr hπ).ne' + +lemma residueCode_range_card {π : GaussianInt} (hπ : π ≠ 0) : + (Set.range (residueCode π)).Finite ∧ (Set.range (residueCode π)).ncard = π.norm.natAbs := by + let := finite_gaussianResidue hπ + let := Encodable.ofCountable (GaussianInt ⧸ multiples π) + have hs : Function.Surjective (gaussianResidue π) := Submodule.Quotient.mk_surjective _ + have hr : Set.range (residueCode π) = Set.range + (Encodable.encode : (GaussianInt ⧸ multiples π) → ℕ) := by + change Set.range (Encodable.encode ∘ gaussianResidue π) = _ + rw [Set.range_comp,hs.range_eq,Set.image_univ] + rw [hr] + refine ⟨Set.finite_range _,?_⟩ + rw [Set.ncard_range_of_injective Encodable.encode_injective,multiples_index hπ] + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/SeparatedParameters.lean b/lean/OAI/NumberTheory/GaussianMoat/SeparatedParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..1305c85f1d5fc3f401b1985d4d17753c70cb0e06 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/SeparatedParameters.lean @@ -0,0 +1,224 @@ +import OAI.NumberTheory.GaussianMoat.WindowBatch + +namespace OAI + +namespace GaussianMoat + +section +open scoped BigOperators Classical + +noncomputable def binEnum (J : Finset ℕ) (n : ℕ) : ℕ := + if h : n binEnum J n) + · intro n hn; exact binEnum_mem J (Finset.mem_range.mp hn) + · intro n hn k hk he + have hn' := Finset.mem_range.mp hn + have hk' := Finset.mem_range.mp hk + rcases lt_trichotomy n k with h|h|h + · exact (ne_of_lt (binEnum_strictMono J h hk') he).elim + · exact h + · exact (ne_of_lt (binEnum_strictMono J h hn') he.symm).elim + · intro j hj + obtain ⟨n,hn,he⟩ := binEnum_surj J hj + exact ⟨n,Finset.mem_range.mpr hn,he⟩ + · intro n hn; rfl + +lemma precedingFactors_enum_subset (J : Finset ℕ) {n : ℕ} (hn : n dyadicSieve (binEnum J k)) n⊆ + (J.filter (· (dyadicSieve j).availableFactors) := by + intro f hf + obtain ⟨k,hk,hf⟩ := Finset.mem_biUnion.mp hf + have hk' := Finset.mem_range.mp hk + apply Finset.mem_biUnion.mpr + exact ⟨binEnum J k,Finset.mem_filter.mpr ⟨binEnum_mem J (hk'.trans hn),binEnum_strictMono J hk' hn⟩,hf⟩ + +lemma precedingFactors_enum_cost (J : Finset ℕ) {K n : ℕ} (hK : 0 dyadicSieve (binEnum J k)) n)≤ + (4*Real.log 4/((2:ℝ)^K-1))*(2:ℝ)^(binEnum J n) := by + apply (residueWeight_mono (precedingFactors_enum_subset J hn)).trans + apply separated_factor_cost _ hK + · intro a ha b hb hab + exact hsep a (Finset.mem_filter.mp ha).1 b (Finset.mem_filter.mp hb).1 hab + · intro a ha + exact hsep a (Finset.mem_filter.mp ha).1 (binEnum J n) (binEnum_mem J hn) (Finset.mem_filter.mp ha).2 + +lemma precedingFactors_enum_all (J : Finset ℕ) : + precedingFactors (fun k => dyadicSieve (binEnum J k)) J.card= + J.biUnion (fun j => (dyadicSieve j).availableFactors) := by + ext f + constructor + · intro hf + obtain ⟨k,hk,hf⟩ := Finset.mem_biUnion.mp hf + exact Finset.mem_biUnion.mpr ⟨binEnum J k,binEnum_mem J (Finset.mem_range.mp hk),hf⟩ + · intro hf + obtain ⟨j,hj,hf⟩ := Finset.mem_biUnion.mp hf + obtain ⟨n,hn,he⟩ := binEnum_surj J hj + exact Finset.mem_biUnion.mpr ⟨n,Finset.mem_range.mpr hn,by simpa only [he] using hf⟩ + +open scoped BigOperators Classical +open Filter + +noncomputable def allBins (W : ℕ) (J : ℕ → Finset ℕ) : Finset ℕ := + (Finset.range W).biUnion J + +lemma bin_window_gap {X : ℝ} {K u v i j : ℕ} (hX : 0 hs w (Finset.mem_range.mp hw)) + simpa only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] using hh + +end + +open scoped BigOperators Classical +open Filter + +lemma exists_separated_parameters : ∃ a δ t : ℝ, ∃ K : ℕ, + 0.and hn).exists + have hlo := (le_max_left _ _).trans hpow + have hhi := (le_max_right _ _).trans hpow + have hgap : a≤(2:ℝ)^K*topCoefficient a := (div_le_iff₀ hv).mp hlo + have hden : 0<(2:ℝ)^K-1 := by + have := one_lt_pow₀ (by norm_num : (1:ℝ)<2) (by omega : K≠0) + linarith only [this] + have hcost : 4*Real.log 4/((2:ℝ)^K-1)≤(topCoefficient a/4)/10000 := by + have hh : 160000*Real.log 4≤((2:ℝ)^K-1)*topCoefficient a := by + apply (div_le_iff₀ hv).mp + linarith only [hhi] + apply (div_le_iff₀ hden).mpr + nlinarith only [hh] + refine ⟨a,δ,c/K,K,ha,ha1,haδ,div_pos hc (by exact_mod_cast hK),hK,hgap,hcost,?_⟩ + filter_upwards [he] with X hX + obtain ⟨J,hJ,hp⟩ := hX + obtain ⟨b,_,hcard,hsep⟩ := thin_bins J hK + refine ⟨J.filter (fun j => j%K=b),?_,hsep,?_⟩ + · have hh := (div_le_div_of_nonneg_right hJ (Nat.cast_nonneg K)).trans hcard + simpa only [div_mul_eq_mul_div] using hh + · intro j hj + exact hp j (Finset.mem_filter.mp hj).1 + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/SieveCertificate.lean b/lean/OAI/NumberTheory/GaussianMoat/SieveCertificate.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cef2204c0c942ef967dcd6b9c8621336d06bdcc --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/SieveCertificate.lean @@ -0,0 +1,117 @@ +import OAI.NumberTheory.GaussianMoat.BatchCertificate + +namespace OAI + +namespace GaussianMoat +open scoped BigOperators Classical + +structure SieveCertificate (D : ℝ) where + schedule : List ℕ + smoothing : ℕ + batches : ℕ → ℕ + last : ℕ + lengths : ℕ → ℕ + rates : ℕ → ℝ + error : ℝ + batch : ∀ j≤last, BatchCertificate D schedule smoothing (dyadicSieve (batches j)) (lengths j) + (residueWeight (precedingFactors (fun i => dyadicSieve (batches i)) j)) (rates j) + divides : ∀ j dyadicSieve (batches i)) (last+1)))≤error + excess : Real.log (latticeBall D).card+last*error<∑ j∈Finset.range (last+1), rates j + +noncomputable def SieveCertificate.primes {D : ℝ} (q : SieveCertificate D) : Finset ℕ := + (Finset.range (q.last+1)).biUnion (fun j => PrimeLogMass.dyadicBatch (q.batches j)) + +lemma SieveCertificate.primes_spec {D : ℝ} (q : SieveCertificate D) : + ∀ p∈q.primes, p.Prime ∧ p%4=1 := by + intro p hp + obtain ⟨j,_,hj⟩ := Finset.mem_biUnion.mp hp + exact (PrimeLogMass.mem_dyadicBatch _ _ |>.mp hj).2.2 + +noncomputable def SieveCertificate.sieve {D : ℝ} (q : SieveCertificate D) : SplitSieve := + splitSieveOf q.primes q.primes_spec + +lemma SieveCertificate.avoiding_batch {D : ℝ} (q : SieveCertificate D) + {z : GaussianInt} (hz : z∈q.sieve.avoiding) {j : ℕ} (hj : j≤q.last) : + z∈(dyadicSieve (q.batches j)).avoiding := by + intro p hp + exact hz p (Finset.mem_biUnion.mpr ⟨j,Finset.mem_range.mpr (by omega),hp⟩) + +theorem SieveCertificate.sound {D : ℝ} (q : SieveCertificate D) (hD : 1≤D) : + ∀ z : ℕ → GaussianInt, (∀ t, z t∈q.sieve.avoiding) → Function.Injective z → + (∀ t, dist (z (t+1):ℂ) (z t:ℂ)≤D) → False := by + intro z ha hz hs + exact certificate_no_walk hD q.schedule q.smoothing q.last + (fun j => dyadicSieve (q.batches j)) q.lengths q.rates q.batch q.divides + q.nonneg q.smooth q.excess z hz (fun _ hj t => q.avoiding_batch (ha t) hj) + (fun t => by simpa only [dist_comm] using hs t) + +theorem finiteSieve_of_certificates + (h : ∀ D : ℝ, 1≤D → Nonempty (SieveCertificate D)) : FiniteSieveEndpoint := by + intro D hD + obtain ⟨q⟩ := h D hD + exact ⟨q.sieve,q.sound hD⟩ + +theorem entropyBand_from_suffix (s : SplitSieve) (pre post : List ℕ) (N l : ℕ) + {D g U δ : ℝ} (hD : 1≤D) (hg : 0 bandLength g U i.val)++post) + N (bandSize s g U l) δ) := by + let V := bandScale g U l + have hV : 0 (0:GaussianInt)) post N hpost hN hlen + simp only [commonSchedule_bound,Nat.cast_add] at hshift + rw [show 1+((post.sum:ℝ)+N)=(post.sum:ℝ)+N+1 by ring] at hshift + have hcost : Real.log 36+2*Real.log (D*((post.sum+N:ℕ)+1))≤ + (10*g)*(bandSize s g U l:ℝ)*s.meanLog := by + rw [Real.log_mul (by linarith only [hD] : D≠0) (by positivity)] + simp only [Nat.cast_add] + have hc : Real.log 36+2*Real.log D≤g*V := hconst + have hm := mul_le_mul_of_nonneg_left hfloor (show 0≤10*g by positivity) + nlinarith only [hshift,hc,hm] + exact ⟨⟨pre,post,g,U,l,10*g,rfl,rfl,hg,hg1,hU,hlog,hlarge,hsize,hdisp,hgeom, + hcap,hcost,by linarith only [hδ]⟩⟩ + +lemma bandLength_le_exp_start {g U : ℝ} (hg : 0≤g) (hg1 : g≤1) (hU : 0≤U) (j : ℕ) : + (bandLength g U j:ℝ)≤Real.exp (g*U) := by + apply (Nat.floor_le (Real.exp_nonneg _)).trans + apply Real.exp_le_exp.mpr + have hh := bandScale_antitone hg hg1 hU (Nat.zero_le j) + simpa only [bandScale,pow_zero,one_mul] using mul_le_mul_of_nonneg_left hh hg + +lemma bandLength_le_exp_at {g U : ℝ} (hg : 0≤g) (hg1 : g≤1) (hU : 0≤U) + {i j : ℕ} (hij : i≤j) : + (bandLength g U j:ℝ)≤Real.exp (g*bandScale g U i) := by + exact (Nat.floor_le (Real.exp_nonneg _)).trans + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (bandScale_antitone hg hg1 hU hij) hg)) + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/SieveSmoothing.lean b/lean/OAI/NumberTheory/GaussianMoat/SieveSmoothing.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c05a44f9ef76e294ff0f13d82b386563ec9ef44 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/SieveSmoothing.lean @@ -0,0 +1,91 @@ +import OAI.NumberTheory.GaussianMoat.SeparatedParameters + +namespace OAI + +namespace GaussianMoat +open scoped BigOperators Classical +open Filter + +lemma allBins_scale_bound {m W : ℕ} (J : ℕ → Finset ℕ) + (hb : ∀ w (dyadicSieve j).availableFactors))≤ + Real.exp ((2*(100:ℝ)^W)*Real.exp m) := by + have hp := eventually_poly_le_exp_linear (4*Real.log 4*(3*(W:ℝ)*(100:ℝ)^W)) + (a := (19/20)*(100:ℝ)^W) (by positivity) 1 + have ht : Tendsto (fun m : ℕ => Real.exp (m:ℝ)) atTop atTop := + Real.tendsto_exp_atTop.comp tendsto_natCast_atTop_atTop + filter_upwards [ht.eventually hp,ht.eventually (eventually_ge_atTop (2:ℝ))] with m hp hm + intro J hJ + have he := fun (j : ℕ) (hj : j∈allBins W J) => allBins_scale_bound J hJ hj + have hcard := allBins_card_upper J hm hJ + have hs : (∑ j∈allBins W J, residueWeight (dyadicSieve j).availableFactors)≤ + (4*Real.log 4)*((allBins W J).card:ℝ)*Real.exp (21/20*(100:ℝ)^W*Real.exp m) := by + calc + _ ≤ ∑ _j∈allBins W J, (4*Real.log 4)*Real.exp (21/20*(100:ℝ)^W*Real.exp m) := by + apply Finset.sum_le_sum + intro j hj + exact (dyadicSieve_available_weight j).trans + (mul_le_mul_of_nonneg_left (he j hj) (by positivity)) + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul]; ring + have hcard' := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hcard (show 0≤4*Real.log 4 by positivity)) + (Real.exp_nonneg (21/20*(100:ℝ)^W*Real.exp m)) + have hh := mul_le_mul_of_nonneg_right hp (Real.exp_nonneg (21/20*(100:ℝ)^W*Real.exp m)) + rw [←Real.exp_add] at hh + simp only [pow_one] at hh + have heq : (19/20)*100^W*Real.exp (m:ℝ)+21/20*100^W*Real.exp m= + (2*(100:ℝ)^W)*Real.exp m := by ring + rw [heq] at hh + apply (residueWeight_biUnion_le _ _).trans (hs.trans (hcard'.trans _)) + convert hh using 1; ring + +theorem eventually_allBins_smoothing (D : ℝ) (W : ℕ) : + ∀ᶠ m : ℕ in atTop, ∀ J : ℕ → Finset ℕ, + (∀ w (dyadicSieve j).availableFactors)))≤ + Real.exp (-Real.exp m)) ∧ + ((allBins W J).card:ℝ)*Real.exp (-Real.exp m)≤1 := by + have hA : 1≤2*(100:ℝ)^W := by have := window_power_one W; linarith only [this] + have ht : Tendsto (fun m : ℕ => Real.exp (m:ℝ)) atTop atTop := + Real.tendsto_exp_atTop.comp tendsto_natCast_atTop_atTop + filter_upwards [eventually_allBins_weight W, + ht.eventually (eventually_smoothing_guard (H := Real.log (latticeBall D).card) hA), + ht.eventually (eventually_smoothing_total (3*(W:ℝ)*(100:ℝ)^W)), + ht.eventually (eventually_ge_atTop (2:ℝ))] with m hweight hsmooth htotal hm + intro J hJ + have hL (j : ℕ) (hj : j∈allBins W J) : + (batchWordLength j:ℝ)≤Real.exp ((2*(100:ℝ)^W)*Real.exp m) := by + apply (batchWordLength_le_scale j).trans ((allBins_scale_bound J hJ hj).trans _) + apply Real.exp_le_exp.mpr + have : 0≤(100:ℝ)^W*Real.exp m := by positivity + nlinarith only [this] + constructor + · intro i hi j hj a ha + apply hsmooth _ _ _ _ (Nat.cast_nonneg _) + ((show (a:ℝ)≤batchWordLength j by exact_mod_cast ha.le).trans (hL j hj)) + (Nat.cast_nonneg _) (hL i hi) (hweight J hJ) + convert (windowSmoothing_bounds W m).1 using 1 + congr 1 + ring + · exact (mul_le_mul_of_nonneg_right (allBins_card_upper J hm hJ) + (Real.exp_nonneg _)).trans htotal + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/SignConcentration.lean b/lean/OAI/NumberTheory/GaussianMoat/SignConcentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b6ec19889e975f74ee5e628f9bb85fd144e94c3 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/SignConcentration.lean @@ -0,0 +1,131 @@ +import OAI.NumberTheory.GaussianMoat.SignedArithmetic + +namespace OAI + +universe uIota + +namespace GaussianMoat + +open MeasureTheory ProbabilityTheory +open scoped NNReal +noncomputable def fairCoin : Measure Bool := (PMF.uniformOfFintype Bool).toMeasure +instance fairCoin_probability : IsProbabilityMeasure fairCoin := by + unfold fairCoin + infer_instance +noncomputable def signMeasure (ι : Type uIota) [Fintype ι] : Measure (ι → Bool) := + Measure.pi (fun _ => fairCoin) +instance signMeasure_probability (ι : Type uIota) [Fintype ι] : IsProbabilityMeasure (signMeasure ι) := by + unfold signMeasure + infer_instance + +theorem fairCoin_mean (f : Bool → ℝ) : ∫ b, f b ∂fairCoin = (f false + f true) / 2 := by + have hf : Integrable f fairCoin := Integrable.of_mem_Icc + (min (f false) (f true)) (max (f false) (f true)) (by fun_prop) (by + apply ae_of_all + intro b + cases b <;> simp) + rw [integral_fintype hf] + simp [fairCoin, measureReal_def, + PMF.uniformOfFintype_apply] + ring + +theorem sign_hoeffding {ι : Type uIota} [Fintype ι] (f : ι → Bool → ℝ) (w : ι → ℝ) + (hf : ∀ i b, f i b ∈ Set.Icc 0 (w i)) {ε : ℝ} (hε : 0 ≤ ε) : + (signMeasure ι).real {σ | ε + ∑ i, (f i false + f i true) / 2 ≤ ∑ i, f i (σ i)} + ≤ Real.exp (-ε ^ 2 / (2 * ∑ i, (((‖w i‖₊ / 2) ^ 2 : ℝ≥0) : ℝ))) := by + classical + let X : ι → (ι → Bool) → ℝ := fun i σ => f i (σ i) - (f i false + f i true) / 2 + have hsub (i : ι) : HasSubgaussianMGF (X i) ((‖w i‖₊ / 2) ^ 2) (signMeasure ι) := by + have h := hasSubgaussianMGF_of_mem_Icc (μ := fairCoin) (X := f i) + (by fun_prop) (ae_of_all _ (hf i)) + rw [fairCoin_mean] at h + simp only [sub_zero] at h + have he := (measurePreserving_eval (fun _ : ι => fairCoin) i).map_eq + rw [← he] at h + have heval : AEMeasurable (Function.eval i : (ι → Bool) → Bool) (signMeasure ι) := + (measurable_pi_apply i).aemeasurable + exact HasSubgaussianMGF.of_map heval h + have hind : iIndepFun X (signMeasure ι) := + iIndepFun_pi (X := fun i b => f i b - (f i false + f i true) / 2) (fun _ => by fun_prop) + have h := HasSubgaussianMGF.measure_sum_ge_le_of_iIndepFun hind + (s := Finset.univ) (fun i _ => hsub i) hε + simpa only [X, Finset.sum_sub_distrib, le_sub_iff_add_le, NNReal.coe_sum] using h + +open scoped Classical in + +noncomputable def SplitSieve.eligible (s : SplitSieve) (v : GaussianInt) : Finset ℕ := + s.primes.filter (fun p => s.factor p ∣ v ∨ star (s.factor p) ∣ v) + +noncomputable def SplitSieve.lineLog (s : SplitSieve) (v : GaussianInt) (p : ℕ) (b : Bool) : ℝ := by + classical + exact if signedFactor (s.factor p) b ∣ v then Real.log p else 0 + +theorem SplitSieve.eligible_log_bound (s : SplitSieve) {v : GaussianInt} (hv : v ≠ 0) : + ∑ p ∈ s.eligible v, Real.log (p : ℝ) ≤ Real.log (v.norm : ℝ) := by + classical + let σ : ℕ → Bool := fun p => decide (s.factor p ∣ v) + have hnorm := s.eligible_product_le_norm (s.eligible v) + (Finset.filter_subset _ _) σ hv (by + intro p hp + obtain ⟨_, hleft | hright⟩ := Finset.mem_filter.mp hp + · simp [σ, signedFactor, hleft] + · by_cases hd : s.factor p ∣ v + · simp [σ, signedFactor, hd] + · simpa [σ, signedFactor, hd] using hright) + have hnorm' : ∏ p ∈ s.eligible v, (p : ℝ) ≤ (v.norm : ℝ) := by + have h : ((∏ p ∈ s.eligible v, (p : ℤ)) : ℝ) ≤ (v.norm : ℝ) := by exact_mod_cast hnorm + push_cast at h + exact h + have hpos (p : ℕ) (hp : p ∈ s.eligible v) : 0 < (p : ℝ) := by + exact_mod_cast (s.prime_mem p (Finset.mem_filter.mp hp).1).pos + have hlog := Real.log_le_log (Finset.prod_pos hpos) hnorm' + rw [Real.log_prod (fun p hp => (hpos p hp).ne')] at hlog + exact hlog + +theorem SplitSieve.lineLog_mean (s : SplitSieve) {v : GaussianInt} + (hv : PrimitiveDirection v) (hv0 : v ≠ 0) : + ∑ p : s.primes, (s.lineLog v p false + s.lineLog v p true) / 2 ≤ + Real.log (v.norm : ℝ) / 2 := by + classical + have heq : ∑ p : s.primes, (s.lineLog v p false + s.lineLog v p true) = + ∑ p ∈ s.eligible v, Real.log (p : ℝ) := by + rw [Finset.sum_coe_sort s.primes (fun p => s.lineLog v p false + s.lineLog v p true), + SplitSieve.eligible, Finset.sum_filter] + apply Finset.sum_congr rfl + intro p hp + have hp2 : p ≠ 2 := by have hm := s.mod_four p hp; omega + have hnot := not_both_factors_dvd_primitive (s.prime_mem p hp) hp2 (s.factor_norm p hp) hv + by_cases h1 : s.factor p ∣ v <;> by_cases h2 : star (s.factor p) ∣ v + · exact False.elim (hnot ⟨h1,h2⟩) + all_goals simp [SplitSieve.lineLog, signedFactor, h1, h2] + rw [← Finset.sum_div, heq] + exact div_le_div_of_nonneg_right (s.eligible_log_bound hv0) (by norm_num) + +theorem SplitSieve.lineLog_tail (s : SplitSieve) {v : GaussianInt} + (hv : PrimitiveDirection v) (hv0 : v ≠ 0) {ε : ℝ} (hε : 0 ≤ ε) : + (signMeasure s.primes).real {σ | + Real.log (v.norm : ℝ) / 2 + ε ≤ ∑ p : s.primes, s.lineLog v p (σ p)} + ≤ Real.exp (-ε ^ 2 / (2 * ∑ p : s.primes, + (((‖Real.log (p : ℝ)‖₊ / 2) ^ 2 : ℝ≥0) : ℝ))) := by + classical + apply le_trans (measureReal_mono (s₂ := {σ | + ε + ∑ p : s.primes, (s.lineLog v p false + s.lineLog v p true) / 2 ≤ + ∑ p : s.primes, s.lineLog v p (σ p)}) ?_) + · apply sign_hoeffding (fun p : s.primes => s.lineLog v p) (fun p => Real.log (p : ℝ)) + · intro p b + have hp : 0 ≤ Real.log (p : ℝ) := Real.log_nonneg (by + exact_mod_cast (s.prime_mem p p.property).one_lt.le) + unfold SplitSieve.lineLog + split_ifs + · exact ⟨hp, le_rfl⟩ + · exact ⟨le_rfl, hp⟩ + · exact hε + · intro σ hσ + have hmean := s.lineLog_mean hv hv0 + change Real.log (v.norm : ℝ) / 2 + ε ≤ _ at hσ + change ε + _ ≤ _ + linarith + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/SignedArithmetic.lean b/lean/OAI/NumberTheory/GaussianMoat/SignedArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..28bd436974b52c6ab54a62d0e7cdb61fbc7d2c6a --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/SignedArithmetic.lean @@ -0,0 +1,192 @@ +import OAI.NumberTheory.GaussianMoat.LatticeComponents + +namespace OAI + +universe uIota + +namespace GaussianMoat + +def PrimitiveDirection (v : GaussianInt) : Prop := IsCoprime v.re v.im + +theorem int_multiple_of_determinant_zero {v w : GaussianInt} + (hv : PrimitiveDirection v) (hvw : determinant v w = 0) : + ∃ a : ℤ, w = (a : GaussianInt) * v := by + obtain ⟨r, s, hrs⟩ := hv + refine ⟨r * w.re + s * w.im, ?_⟩ + change v.re * w.im - v.im * w.re = 0 at hvw + ext <;> simp only [Zsqrtd.re_mul, Zsqrtd.im_mul, Zsqrtd.re_intCast, + Zsqrtd.im_intCast, zero_mul, mul_zero, add_zero] + · nlinarith [congrArg (fun x : ℤ => x * w.re) hrs, + congrArg (fun x : ℤ => s * x) hvw] + · nlinarith [congrArg (fun x : ℤ => x * w.im) hrs, + congrArg (fun x : ℤ => r * x) hvw] + +theorem exists_primitive_direction {w : GaussianInt} (hw : w ≠ 0) : + ∃ v : GaussianInt, PrimitiveDirection v ∧ v ≠ 0 ∧ + ∃ a : ℤ, a ≠ 0 ∧ w = (a : GaussianInt) * v := by + have hg := (Zsqrtd.gcd_pos_iff w).mpr hw + obtain ⟨v, hv, hcop⟩ := Zsqrtd.exists_coprime_of_gcd_pos hg + refine ⟨v, hcop, ?_, (Int.gcd w.re w.im : ℤ), by exact_mod_cast hg.ne', hv⟩ + intro h + apply hw + simp only [h, mul_zero] at hv + exact hv + +theorem norm_dvd_norm {a b : GaussianInt} (h : a ∣ b) : a.norm ∣ b.norm := by + obtain ⟨u, rfl⟩ := h + rw [Zsqrtd.norm_mul] + exact dvd_mul_right _ _ + +theorem factor_dvd_integer_iff {p : ℕ} {π : GaussianInt} (hp : Nat.Prime p) + (hπ : π.norm = (p : ℤ)) (a : ℤ) : π ∣ (a : GaussianInt) ↔ (p : ℤ) ∣ a := by + have hp' : Prime (p : ℤ) := Int.prime_iff_natAbs_prime.mpr (by simpa using hp) + constructor + · intro h + have hn := norm_dvd_norm h + rw [hπ, Zsqrtd.norm_intCast] at hn + exact (hp'.dvd_mul.mp hn).elim id id + · intro h + have hd : π ∣ (p : GaussianInt) := by + have he : (p : GaussianInt) = π * star π := by + rw [← Zsqrtd.norm_eq_mul_conj, hπ] + simp + rw [he] + exact dvd_mul_right _ _ + exact hd.trans (map_dvd (Int.castRingHom GaussianInt) h) + +theorem not_both_factors_dvd_primitive {p : ℕ} {π v : GaussianInt} + (hp : Nat.Prime p) (hpodd : p ≠ 2) (hπ : π.norm = (p : ℤ)) + (hv : PrimitiveDirection v) : ¬ (π ∣ v ∧ star π ∣ v) := by + rintro ⟨h1, h2⟩ + have hs : π ∣ star v := by + obtain ⟨u, hu⟩ := h2 + refine ⟨star u, ?_⟩ + simpa only [star_mul, star_star, mul_comm] using congrArg star hu + have hreal : π ∣ ((2 * v.re : ℤ) : GaussianInt) := by + have heq : ((2 * v.re : ℤ) : GaussianInt) = v + star v := by + ext <;> simp + ring + rw [heq] + exact dvd_add h1 hs + have himag : π ∣ ((2 * v.im : ℤ) : GaussianInt) := by + have heq : ((2 * v.im : ℤ) : GaussianInt) = + (⟨0, -1⟩ : GaussianInt) * (v - star v) := by + ext <;> simp [Zsqrtd.re_mul, Zsqrtd.im_mul] + ring + rw [heq] + exact dvd_mul_of_dvd_right (dvd_sub h1 hs) _ + have hp' : Prime (p : ℤ) := Int.prime_iff_natAbs_prime.mpr (by simpa using hp) + have hp2 : ¬ (p : ℤ) ∣ 2 := by + intro h + have hn : p ∣ 2 := by exact_mod_cast h + have hh := (Nat.dvd_prime Nat.prime_two).mp hn + exact hh.elim hp.ne_one hpodd + have hr : (p : ℤ) ∣ v.re := + (hp'.dvd_mul.mp ((factor_dvd_integer_iff hp hπ _).mp hreal)).resolve_left hp2 + have hi : (p : ℤ) ∣ v.im := + (hp'.dvd_mul.mp ((factor_dvd_integer_iff hp hπ _).mp himag)).resolve_left hp2 + exact hp'.not_isUnit (hv.isUnit_of_dvd' hr hi) + +def signedFactor (π : GaussianInt) (b : Bool) : GaussianInt := if b then π else star π + +theorem signedFactor_norm (π : GaussianInt) (b : Bool) : (signedFactor π b).norm = π.norm := by + cases b <;> simp [signedFactor, Zsqrtd.norm_conj] + +theorem signedFactor_irreducible {π : GaussianInt} (hπ : Irreducible π) (b : Bool) : + Irreducible (signedFactor π b) := by + cases b + · exact (MulEquiv.irreducible_iff (starRingAut : RingAut GaussianInt)).mpr hπ + · exact hπ + +theorem coprime_factors_of_norm_primes {p q : ℕ} {π ρ : GaussianInt} + (hp : Nat.Prime p) (hq : Nat.Prime q) (hpq : p ≠ q) + (hπ : π.norm = (p : ℤ)) (hρ : ρ.norm = (q : ℤ)) : IsCoprime π ρ := by + have hc : Nat.Coprime p q := (hp.coprime_iff_not_dvd).mpr (by + intro hd + have hh := (Nat.dvd_prime hq).mp hd + exact hh.elim hp.ne_one hpq) + have hcz : IsCoprime (p : ℤ) (q : ℤ) := by + apply Int.isCoprime_iff_gcd_eq_one.mpr + simpa using hc + have hcg := hcz.map (Int.castRingHom GaussianInt) + have hdπ : π ∣ (p : GaussianInt) := (factor_dvd_integer_iff hp hπ _).mpr (dvd_refl _) + have hdρ : ρ ∣ (q : GaussianInt) := (factor_dvd_integer_iff hq hρ _).mpr (dvd_refl _) + exact hcg.of_isCoprime_of_dvd_left hdπ |>.of_isCoprime_of_dvd_right hdρ + +theorem norm_finset_prod {ι : Type uIota} (s : Finset ι) (f : ι → GaussianInt) : + (∏ i ∈ s, f i).norm = ∏ i ∈ s, (f i).norm := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => simp [hi, Zsqrtd.norm_mul, ih] + +theorem SplitSieve.prod_factors_dvd (s : SplitSieve) (t : Finset ℕ) (ht : t ⊆ s.primes) + (σ : ℕ → Bool) {v : GaussianInt} + (hd : ∀ p ∈ t, signedFactor (s.factor p) (σ p) ∣ v) : + (∏ p ∈ t, signedFactor (s.factor p) (σ p)) ∣ v := by + apply Finset.prod_dvd_of_coprime _ hd + intro p hp q hq hpq + exact coprime_factors_of_norm_primes (s.prime_mem p (ht hp)) (s.prime_mem q (ht hq)) hpq + ((signedFactor_norm _ _).trans (s.factor_norm p (ht hp))) + ((signedFactor_norm _ _).trans (s.factor_norm q (ht hq))) + +theorem SplitSieve.eligible_product_le_norm (s : SplitSieve) (t : Finset ℕ) + (ht : t ⊆ s.primes) (σ : ℕ → Bool) {v : GaussianInt} (hv : v ≠ 0) + (hd : ∀ p ∈ t, signedFactor (s.factor p) (σ p) ∣ v) : + (∏ p ∈ t, (p : ℤ)) ≤ v.norm := by + have hle := norm_le_of_dvd hv (s.prod_factors_dvd t ht σ hd) + rw [norm_finset_prod] at hle + convert hle using 1 + apply Finset.prod_congr rfl + intro p hp + exact ((signedFactor_norm _ _).trans (s.factor_norm p (ht hp))).symm + +open scoped Classical in + +theorem SplitSieve.uneligible_product_dvd_coefficient (s : SplitSieve) + (t : Finset ℕ) (ht : t ⊆ s.primes) (σ : ℕ → Bool) (v : GaussianInt) (a : ℤ) + (hw : (∏ p ∈ t, signedFactor (s.factor p) (σ p)) ∣ (a : GaussianInt) * v) : + (∏ p ∈ t.filter (fun p => ¬ signedFactor (s.factor p) (σ p) ∣ v), (p : ℤ)) ∣ a := by + classical + apply Finset.prod_dvd_of_coprime + · intro p hp q hq hpq + have hp' := s.prime_mem p (ht (Finset.mem_filter.mp hp).1) + have hq' := s.prime_mem q (ht (Finset.mem_filter.mp hq).1) + apply Int.isCoprime_iff_gcd_eq_one.mpr + change Nat.Coprime p q + exact (hp'.coprime_iff_not_dvd).mpr (fun h => + ((Nat.dvd_prime hq').mp h).elim hp'.ne_one hpq) + · intro p hp + obtain ⟨hpt, hpv⟩ := Finset.mem_filter.mp hp + have hpp := ht hpt + have hd : signedFactor (s.factor p) (σ p) ∣ (a : GaussianInt) * v := + (Finset.dvd_prod_of_mem _ hpt).trans hw + have ha := ((signedFactor_irreducible (s.factor_irreducible p hpp) (σ p)).prime.dvd_mul.mp hd).resolve_right hpv + exact (factor_dvd_integer_iff (s.prime_mem p hpp) + ((signedFactor_norm _ _).trans (s.factor_norm p hpp)) a).mp ha + +open scoped Classical in + +theorem SplitSieve.line_witness_norm_lower (s : SplitSieve) + (t : Finset ℕ) (ht : t ⊆ s.primes) (σ : ℕ → Bool) + {v w : GaussianInt} (hv : PrimitiveDirection v) (hw : w ≠ 0) + (hline : determinant v w = 0) + (hdiv : (∏ p ∈ t, signedFactor (s.factor p) (σ p)) ∣ w) : + v.norm * (∏ p ∈ t.filter (fun p => ¬ signedFactor (s.factor p) (σ p) ∣ v), (p : ℤ)) ^ 2 + ≤ w.norm := by + classical + obtain ⟨a, rfl⟩ := int_multiple_of_determinant_zero hv hline + have ha : a ≠ 0 := by intro h; simp [h] at hw + have hd := s.uneligible_product_dvd_coefficient t ht σ v a hdiv + have habs : 0 < |a| := abs_pos.mpr ha + have hle := Int.le_of_dvd habs ((dvd_abs _ _).mpr hd) + have hprod : 0 ≤ ∏ p ∈ t.filter (fun p => ¬ signedFactor (s.factor p) (σ p) ∣ v), (p : ℤ) := + Finset.prod_nonneg (fun _ _ => Int.natCast_nonneg _) + have hs : (∏ p ∈ t.filter (fun p => ¬ signedFactor (s.factor p) (σ p) ∣ v), (p : ℤ)) ^ 2 ≤ a ^ 2 := by + nlinarith [sq_abs a] + rw [Zsqrtd.norm_mul, Zsqrtd.norm_intCast] + nlinarith [mul_le_mul_of_nonneg_left hs (GaussianInt.norm_nonneg v)] + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/SignedGeometry.lean b/lean/OAI/NumberTheory/GaussianMoat/SignedGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..00c9f9a2a8bcff280d94c6d1809bf8c6a8d1d2e2 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/SignedGeometry.lean @@ -0,0 +1,679 @@ +import OAI.NumberTheory.GaussianMoat.BooleanCube + +namespace OAI + +universe uIota + +namespace GaussianMoat +open MeasureTheory ProbabilityTheory +open scoped NNReal + +def cubeEquiv : (n : ℕ) → Cube n ≃ (Fin n → Bool) + | 0 => { + toFun := fun _ i => Fin.elim0 i + invFun := fun _ => () + left_inv := fun x => by cases x; rfl + right_inv := fun f => by funext i; exact Fin.elim0 i } + | n+1 => (Equiv.prodCongr (Equiv.refl Bool) (cubeEquiv n)).trans (Fin.consEquiv (fun _ => Bool)) + +noncomputable def cubeSignEquiv (ι : Type uIota) [Fintype ι] : Cube (Fintype.card ι) ≃ (ι → Bool) := + (cubeEquiv (Fintype.card ι)).trans + (Equiv.arrowCongr (Fintype.equivFin ι).symm (Equiv.refl Bool)) + +noncomputable def signDist {ι : Type uIota} [Fintype ι] (σ τ : ι → Bool) : ℕ := by + classical + exact ∑ i, if σ i = τ i then 0 else 1 + +theorem cubeEquiv_dist (n : ℕ) (x y : Cube n) : + signDist (cubeEquiv n x) (cubeEquiv n y) = cubeDist n x y := by + classical + induction n with + | zero => simp [signDist, cubeDist] + | succ n ih => + obtain ⟨b,x⟩ := x + obtain ⟨c,y⟩ := y + simp only [signDist, Fin.sum_univ_succ, cubeEquiv, Equiv.trans_apply, + Equiv.prodCongr_apply, Fin.consEquiv_apply, Fin.cons_zero, + Fin.cons_succ, cubeDist] + congr 1 + exact ih x y + +theorem cubeSignEquiv_dist (ι : Type uIota) [Fintype ι] (x y : Cube (Fintype.card ι)) : + signDist (cubeSignEquiv ι x) (cubeSignEquiv ι y) = cubeDist (Fintype.card ι) x y := by + classical + rw [← cubeEquiv_dist] + unfold signDist cubeSignEquiv + simp only [Equiv.trans_apply, Equiv.arrowCongr_apply, Equiv.symm_symm] + exact (Fintype.equivFin ι).sum_comp (fun i => if cubeEquiv (Fintype.card ι) x i = + cubeEquiv (Fintype.card ι) y i then (0 : ℕ) else 1) + +theorem signMeasure_real_singleton {ι : Type uIota} [Fintype ι] (σ : ι → Bool) : + (signMeasure ι).real {σ} = ((2 : ℝ)^Fintype.card ι)⁻¹ := by + simp [measureReal_def, signMeasure, Measure.pi_singleton, fairCoin, + PMF.uniformOfFintype_apply] + +open scoped Classical in + +theorem signMeasure_real_set {ι : Type uIota} [Fintype ι] (S : Set (ι → Bool)) : + (signMeasure ι).real S = (∑ σ, if σ ∈ S then (1 : ℝ) else 0) / + (2 : ℝ)^Fintype.card ι := by + classical + have he : S = (↑(Finset.univ.filter (· ∈ S)) : Set (ι → Bool)) := by ext; simp + conv_lhs => rw [he, ← sum_measureReal_singleton] + rw [Finset.sum_filter, Finset.sum_div] + apply Finset.sum_congr rfl + intro σ _ + by_cases hσ : σ ∈ S <;> simp [hσ, signMeasure_real_singleton] + +theorem cubeSignEquiv_measure {ι : Type uIota} [Fintype ι] (S : (ι → Bool) → Prop) : + (signMeasure ι).real {σ | S σ} = + (cubeSize (fun x => S (cubeSignEquiv ι x)) : ℝ) / (2 : ℝ)^Fintype.card ι := by + classical + rw [signMeasure_real_set] + congr 1 + simp only [Set.mem_ofPred_eq] + rw [← (cubeSignEquiv ι).sum_comp (fun σ => if S σ then (1 : ℝ) else 0)] + simp only [cubeSize, Nat.cast_sum, Nat.cast_ite, Nat.cast_one, Nat.cast_zero] + +noncomputable def SplitSieve.extendSigns (s : SplitSieve) (σ : s.primes → Bool) (p : ℕ) : Bool := by + classical + exact if hp : p ∈ s.primes then σ ⟨p,hp⟩ else false + +@[simp] theorem SplitSieve.extendSigns_mem (s : SplitSieve) (σ : s.primes → Bool) + (p : ℕ) (hp : p ∈ s.primes) : s.extendSigns σ p = σ ⟨p,hp⟩ := by + simp [SplitSieve.extendSigns, hp] + +noncomputable def SplitSieve.signedProduct (s : SplitSieve) (σ : s.primes → Bool) : GaussianInt := + ∏ p ∈ s.primes, signedFactor (s.factor p) (s.extendSigns σ p) + +theorem SplitSieve.line_witness_log_lower (s : SplitSieve) (σ : s.primes → Bool) + {v w : GaussianInt} (hv : PrimitiveDirection v) (hv0 : v ≠ 0) (hw : w ≠ 0) + (hline : determinant v w = 0) (hdiv : s.signedProduct σ ∣ w) + {B : ℝ} (hbound : (w.norm : ℝ) ≤ B) : + Real.log (v.norm : ℝ) / 2 + (∑ p : s.primes, Real.log (p : ℝ)) - Real.log B / 2 ≤ + ∑ p : s.primes, s.lineLog v p (σ p) := by + classical + let t := s.primes.filter (fun p => ¬signedFactor (s.factor p) (s.extendSigns σ p) ∣ v) + have hp (p : ℕ) (hp : p ∈ t) : 0 < (p : ℝ) := by + exact_mod_cast (s.prime_mem p (Finset.mem_filter.mp hp).1).pos + have hprod : 0 < ∏ p ∈ t, (p : ℝ) := Finset.prod_pos hp + have hvpos : 0 < (v.norm : ℝ) := by exact_mod_cast (GaussianInt.norm_pos.mpr hv0) + have hlo := s.line_witness_norm_lower s.primes (fun _ h => h) (s.extendSigns σ) hv hw hline hdiv + have hlow : (v.norm : ℝ) * (∏ p ∈ t, (p : ℝ))^2 ≤ B := by + apply le_trans ?_ hbound + have hc : ((v.norm * (∏ p ∈ t, (p : ℤ))^2 : ℤ) : ℝ) ≤ (w.norm : ℝ) := by exact_mod_cast hlo + push_cast at hc + exact hc + have hlog := Real.log_le_log (mul_pos hvpos (sq_pos_of_pos hprod)) hlow + rw [Real.log_mul hvpos.ne' (sq_pos_of_pos hprod).ne', Real.log_pow, + Real.log_prod (fun p hp' => (hp p hp').ne')] at hlog + have hsum : (∑ p ∈ t, Real.log (p : ℝ)) = + (∑ p : s.primes, Real.log (p : ℝ)) - ∑ p : s.primes, s.lineLog v p (σ p) := by + calc + _ = ∑ p ∈ s.primes, (Real.log (p : ℝ) - s.lineLog v p (s.extendSigns σ p)) := by + unfold t + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro p hp' + unfold SplitSieve.lineLog + split_ifs <;> simp_all + _ = _ := by + rw [← Finset.sum_coe_sort s.primes + (fun p => Real.log (p : ℝ) - s.lineLog v p (s.extendSigns σ p))] + simp [SplitSieve.extendSigns, Finset.sum_sub_distrib] + rw [hsum] at hlog + norm_num only [Nat.cast_ofNat] at hlog + linarith only [hlog] + +def SplitSieve.lineEvent (s : SplitSieve) (Q : Set GaussianInt) (v : GaussianInt) + (σ : s.primes → Bool) : Prop := + ∃ w ∈ Q, w ≠ 0 ∧ determinant v w = 0 ∧ s.signedProduct σ ∣ w + +theorem SplitSieve.line_event_tail (s : SplitSieve) {Q : Set GaussianInt} + {v : GaussianInt} (hv : PrimitiveDirection v) (hv0 : v ≠ 0) {B ε : ℝ} + (hQ : ∀ w ∈ Q, (w.norm : ℝ) ≤ B) (hε : 0 ≤ ε) + (hexcess : ε ≤ (∑ p : s.primes, Real.log (p : ℝ)) - Real.log B / 2) : + (signMeasure s.primes).real {σ | s.lineEvent Q v σ} ≤ + Real.exp (-ε^2 / (2 * ∑ p : s.primes, + (((‖Real.log (p : ℝ)‖₊ / 2)^2 : ℝ≥0) : ℝ))) := by + apply le_trans (measureReal_mono (s₂ := {σ | + Real.log (v.norm : ℝ) / 2 + ε ≤ ∑ p : s.primes, s.lineLog v p (σ p)}) ?_) + · exact s.lineLog_tail hv hv0 hε + · rintro σ ⟨w,hwQ,hw,hline,hd⟩ + have hl := s.line_witness_log_lower σ hv hv0 hw hline hd (hQ w hwQ) + change Real.log (v.norm : ℝ) / 2 + ε ≤ _ + linarith + +open scoped Classical in + +noncomputable def SplitSieve.commonProduct (s : SplitSieve) (σ τ : s.primes → Bool) : GaussianInt := + ∏ p ∈ s.primes.filter (fun p => s.extendSigns σ p = s.extendSigns τ p), + signedFactor (s.factor p) (s.extendSigns σ p) + +theorem SplitSieve.commonProduct_dvd_left (s : SplitSieve) (σ τ : s.primes → Bool) : + s.commonProduct σ τ ∣ s.signedProduct σ := by + classical + exact Finset.prod_dvd_prod_of_subset _ _ _ (Finset.filter_subset _ _) + +theorem SplitSieve.commonProduct_comm (s : SplitSieve) (σ τ : s.primes → Bool) : + s.commonProduct σ τ = s.commonProduct τ σ := by + classical + unfold SplitSieve.commonProduct + apply Finset.prod_congr + · ext p + simp only [Finset.mem_filter, eq_comm] + · intro p hp + rw [(Finset.mem_filter.mp hp).2] + +theorem SplitSieve.commonProduct_dvd_right (s : SplitSieve) (σ τ : s.primes → Bool) : + s.commonProduct σ τ ∣ s.signedProduct τ := by + rw [s.commonProduct_comm] + exact s.commonProduct_dvd_left τ σ + +open scoped Classical in +theorem SplitSieve.signDist_eq_card (s : SplitSieve) (σ τ : s.primes → Bool) : + signDist σ τ = (s.primes.filter (fun p => s.extendSigns σ p ≠ s.extendSigns τ p)).card := by + classical + rw [Finset.card_eq_sum_ones, Finset.sum_filter, ← Finset.sum_coe_sort s.primes + (fun p => if s.extendSigns σ p ≠ s.extendSigns τ p then 1 else 0)] + unfold signDist + apply Finset.sum_congr rfl + intro p _ + simp [SplitSieve.extendSigns] + +theorem SplitSieve.period_le_common_norm (s : SplitSieve) (σ τ : s.primes → Bool) + {U : ℝ} (hpU : ∀ p ∈ s.primes, (p : ℝ) ≤ U) : + (s.period : ℝ) ≤ ((s.commonProduct σ τ).norm : ℝ) * U^(signDist σ τ) := by + classical + let c := s.primes.filter (fun p => s.extendSigns σ p = s.extendSigns τ p) + let d := s.primes.filter (fun p => s.extendSigns σ p ≠ s.extendSigns τ p) + have hc : ((s.commonProduct σ τ).norm : ℝ) = ∏ p ∈ c, (p : ℝ) := by + unfold SplitSieve.commonProduct + rw [norm_finset_prod, Int.cast_prod] + apply Finset.prod_congr rfl + intro p hp + rw [signedFactor_norm, s.factor_norm p (Finset.mem_filter.mp hp).1] + exact_mod_cast (rfl : (p : ℝ) = p) + have hd : (∏ p ∈ d, (p : ℝ)) ≤ U^d.card := by + rw [← Finset.prod_const] + exact Finset.prod_le_prod₀ (fun p _ => Nat.cast_nonneg p) + (fun p hp => hpU p (Finset.mem_filter.mp hp).1) + have hp : (s.period : ℝ) = (∏ p ∈ c, (p : ℝ)) * (∏ p ∈ d, (p : ℝ)) := by + unfold SplitSieve.period + push_cast + exact (Finset.prod_filter_mul_prod_filter_not s.primes + (fun p => s.extendSigns σ p = s.extendSigns τ p) (fun p => (p : ℝ))).symm + rw [hp, hc, s.signDist_eq_card] + exact mul_le_mul_of_nonneg_left hd (Finset.prod_nonneg (fun p _ => Nat.cast_nonneg p)) + +theorem SplitSieve.near_witnesses_collinear (s : SplitSieve) (σ τ : s.primes → Bool) + {w w' : GaussianInt} (hw : s.signedProduct σ ∣ w) (hw' : s.signedProduct τ ∣ w') + {U B : ℝ} (hU : 0 < U) (hpU : ∀ p ∈ s.primes, (p : ℝ) ≤ U) + (hdet : (|determinant w w'| : ℝ) ≤ B) + (hsmall : B * U^(signDist σ τ) < (s.period : ℝ)) : determinant w w' = 0 := by + have hbound := lt_of_lt_of_le hsmall (s.period_le_common_norm σ τ hpU) + have hlt : B < ((s.commonProduct σ τ).norm : ℝ) := + (mul_lt_mul_iff_left₀ (pow_pos hU _)).mp (by simpa only [mul_comm] using hbound) + apply determinant_eq_zero_of_common_factor + ((s.commonProduct_dvd_left σ τ).trans hw) ((s.commonProduct_dvd_right σ τ).trans hw') + exact_mod_cast hdet.trans_lt hlt + +theorem determinant_zero_trans {u v w : GaussianInt} (hv : v ≠ 0) + (huv : determinant u v = 0) (hvw : determinant v w = 0) : + determinant u w = 0 := by + have hcoord : v.re ≠ 0 ∨ v.im ≠ 0 := by + contrapose! hv + ext <;> simp [hv.1, hv.2] + unfold determinant at * + rcases hcoord with hr | hi + · apply (mul_eq_zero.mp (show v.re * (u.re * w.im - u.im * w.re) = 0 by + nlinarith [congrArg (fun x : ℤ => x * w.re) huv, + congrArg (fun x : ℤ => u.re * x) hvw])).resolve_left hr + · apply (mul_eq_zero.mp (show v.im * (u.re * w.im - u.im * w.re) = 0 by + nlinarith [congrArg (fun x : ℤ => x * w.im) huv, + congrArg (fun x : ℤ => u.im * x) hvw])).resolve_left hi + +@[simp] theorem determinant_self (v : GaussianInt) : determinant v v = 0 := by + unfold determinant + ring + +theorem determinant_swap (u v : GaussianInt) : determinant u v = -determinant v u := by + unfold determinant + ring + +def witnessLine (v : GaussianInt) : Set GaussianInt := {w | determinant v w = 0} + +theorem witnessLine_eq {v w : GaussianInt} (hv : v ≠ 0) (hw : w ≠ 0) + (hvw : determinant v w = 0) : witnessLine v = witnessLine w := by + ext u + constructor + · intro hu + exact determinant_zero_trans hv (by rw [determinant_swap, hvw, neg_zero]) hu + · exact determinant_zero_trans hw hvw + +def SplitSieve.badSign (s : SplitSieve) (Q : Set GaussianInt) (σ : s.primes → Bool) : Prop := + ∃ w ∈ Q, w ≠ 0 ∧ s.signedProduct σ ∣ w + +noncomputable def SplitSieve.badWitness (s : SplitSieve) (Q : Set GaussianInt) + (σ : {σ : s.primes → Bool // s.badSign Q σ}) : GaussianInt := σ.property.choose + +theorem SplitSieve.badWitness_spec (s : SplitSieve) (Q : Set GaussianInt) + (σ : {σ : s.primes → Bool // s.badSign Q σ}) : + s.badWitness Q σ ∈ Q ∧ s.badWitness Q σ ≠ 0 ∧ s.signedProduct σ.val ∣ s.badWitness Q σ := + σ.property.choose_spec + +def SplitSieve.badLines (s : SplitSieve) (Q : Set GaussianInt) : Set (Set GaussianInt) := + Set.range (fun σ : {σ : s.primes → Bool // s.badSign Q σ} => witnessLine (s.badWitness Q σ)) + +instance SplitSieve.badLines_finite (s : SplitSieve) (Q : Set GaussianInt) : + Finite (s.badLines Q) := by + unfold SplitSieve.badLines + infer_instance + +theorem SplitSieve.badLine_primitive (s : SplitSieve) (Q : Set GaussianInt) + (L : s.badLines Q) : ∃ v : GaussianInt, PrimitiveDirection v ∧ v ≠ 0 ∧ witnessLine v = L.val := by + obtain ⟨σ, hσ⟩ := L.property + have hw := s.badWitness_spec Q σ + obtain ⟨v,hv,hv0,a,_hanz,ha⟩ := exists_primitive_direction hw.2.1 + refine ⟨v,hv,hv0, ?_⟩ + rw [← hσ] + apply witnessLine_eq hv0 hw.2.1 + rw [ha] + unfold determinant + simp only [Zsqrtd.re_mul, Zsqrtd.im_mul, Zsqrtd.re_intCast, Zsqrtd.im_intCast] + ring + +def SplitSieve.lineClass (s : SplitSieve) (Q : Set GaussianInt) (L : s.badLines Q) + (σ : s.primes → Bool) : Prop := + ∃ hσ : s.badSign Q σ, witnessLine (s.badWitness Q ⟨σ,hσ⟩) = L.val + +theorem SplitSieve.badSign_iff_class (s : SplitSieve) (Q : Set GaussianInt) (σ : s.primes → Bool) : + s.badSign Q σ ↔ ∃ L : s.badLines Q, s.lineClass Q L σ := by + constructor + · intro hσ + exact ⟨⟨witnessLine (s.badWitness Q ⟨σ,hσ⟩), ⟨⟨σ,hσ⟩,rfl⟩⟩, hσ, rfl⟩ + · rintro ⟨L,hσ,_⟩ + exact hσ + +theorem SplitSieve.lineClass_subset_event (s : SplitSieve) (Q : Set GaussianInt) + (L : s.badLines Q) {v : GaussianInt} (hvL : witnessLine v = L.val) : + {σ | s.lineClass Q L σ} ⊆ {σ | s.lineEvent Q v σ} := by + rintro σ ⟨hσ,hL⟩ + have hw := s.badWitness_spec Q ⟨σ,hσ⟩ + refine ⟨_,hw.1,hw.2.1,?_,hw.2.2⟩ + change s.badWitness Q ⟨σ,hσ⟩ ∈ witnessLine v + rw [hvL, ← hL] + exact determinant_self _ + +theorem SplitSieve.lineClasses_separated (s : SplitSieve) (Q : Set GaussianInt) + {U B : ℝ} (hU : 1 ≤ U) (hpU : ∀ p ∈ s.primes, (p : ℝ) ≤ U) + (hdet : ∀ w ∈ Q, ∀ w' ∈ Q, (|determinant w w'| : ℝ) ≤ B) + {h : ℕ} (hsmall : B * U^(2*h) < (s.period : ℝ)) (hB : 0 ≤ B) : + ∀ L L' : s.badLines Q, L ≠ L' → ∀ σ, s.lineClass Q L σ → + ∀ τ, s.lineClass Q L' τ → 2*h < signDist σ τ := by + intro L L' hLL σ ⟨hσ,hσL⟩ τ ⟨hτ,hτL⟩ + by_contra hn + have hd : signDist σ τ ≤ 2*h := le_of_not_gt hn + have hw := s.badWitness_spec Q ⟨σ,hσ⟩ + have hw' := s.badWitness_spec Q ⟨τ,hτ⟩ + have hsm : B * U^(signDist σ τ) < (s.period : ℝ) := + (mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hU hd) hB).trans_lt hsmall + have hcol := s.near_witnesses_collinear σ τ hw.2.2 hw'.2.2 (by linarith) hpU + (hdet _ hw.1 _ hw'.1) hsm + apply hLL + apply Subtype.ext + rw [← hσL, ← hτL] + exact witnessLine_eq hw.2.1 hw'.2.1 hcol + +theorem cubeSize_exists_le_sum {n : ℕ} {ι : Type uIota} [Fintype ι] + (S : ι → Cube n → Prop) : cubeSize (fun x => ∃ i, S i x) ≤ ∑ i, cubeSize (S i) := by + classical + unfold cubeSize + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro x _ + by_cases hx : ∃ i, S i x + · obtain ⟨i, hi⟩ := hx + rw [ite_eq_left ⟨i,hi⟩] + have h : (if S i x then 1 else 0) ≤ ∑ j : ι, if S j x then 1 else 0 := + Finset.single_le_sum (f := fun j => if S j x then (1 : ℕ) else 0) + (fun _ _ => Nat.zero_le _) (Finset.mem_univ i) + simpa only [ite_eq_left hi] using h + · simp only [ite_eq_right hx] + exact Nat.zero_le _ + +theorem SplitSieve.signed_region_bound (s : SplitSieve) (Q : Set GaussianInt) + (hr : 0 < s.primes.card) {U B N ε a E A : ℝ} {h : ℕ} + (hU : 1 ≤ U) (hpU : ∀ p ∈ s.primes, (p : ℝ) ≤ U) + (hB : 0 ≤ B) (hdet : ∀ w ∈ Q, ∀ w' ∈ Q, (|determinant w w'| : ℝ) ≤ B) + (hsmall : B * U^(2*h) < (s.period : ℝ)) + (hQ : ∀ w ∈ Q, (w.norm : ℝ) ≤ N) (hε : 0 ≤ ε) + (hexcess : ε ≤ (∑ p : s.primes, Real.log (p : ℝ)) - Real.log N / 2) + (ha : 0 ≤ a) (hE : 0 < E) (hA : 0 < A) + (hlogE : Real.log E ≤ (s.primes.card : ℝ) * Real.log 2 - a) + (hseed : A * Real.exp (-ε^2 / (2 * ∑ p : s.primes, + (((‖Real.log (p : ℝ)‖₊ / 2)^2 : ℝ≥0) : ℝ))) * (2 : ℝ)^s.primes.card ≤ E) + (hfactor : A ≤ (1 + a / ((s.primes.card : ℝ)*Real.log 2))^h) : + (signMeasure s.primes).real {σ | s.badSign Q σ} ≤ A⁻¹ := by + classical + let : Fintype (s.badLines Q) := Fintype.ofFinite _ + let S : s.badLines Q → Cube (Fintype.card s.primes) → Prop := + fun L x => s.lineClass Q L (cubeSignEquiv s.primes x) + have hcard : Fintype.card s.primes = s.primes.card := Fintype.card_coe _ + have hpow : 0 < (2 : ℝ)^Fintype.card s.primes := pow_pos (by norm_num) _ + have hseed' (L : s.badLines Q) : A * cubeSize (S L) ≤ E := by + obtain ⟨v,hv,hv0,hvL⟩ := s.badLine_primitive Q L + have hm := (measureReal_mono (s.lineClass_subset_event Q L hvL)).trans + (s.line_event_tail hv hv0 hQ hε hexcess) + rw [cubeSignEquiv_measure] at hm + have hc : (cubeSize (S L) : ℝ) ≤ Real.exp (-ε^2 / (2 * ∑ p : s.primes, + (((‖Real.log (p : ℝ)‖₊ / 2)^2 : ℝ≥0) : ℝ))) * (2 : ℝ)^Fintype.card s.primes := + (div_le_iff₀ hpow).mp hm + have hh := mul_le_mul_of_nonneg_left hc hA.le + exact hh.trans (by simpa only [hcard, mul_assoc] using hseed) + have hsep : ∀ L L' : s.badLines Q, L ≠ L' → ∀ x, S L x → ∀ y, S L' y → + 2*h < cubeDist (Fintype.card s.primes) x y := by + intro L L' hLL x hx y hy + have hh := s.lineClasses_separated Q hU hpU hdet hsmall hB L L' hLL + (cubeSignEquiv s.primes x) hx (cubeSignEquiv s.primes y) hy + simpa only [cubeSignEquiv_dist] using hh + have hpack := cube_separated_bound (n := Fintype.card s.primes) (h := h) + (by simpa only [hcard] using hr) S ha hE (by simpa only [hcard] using hlogE) + hseed' (by simpa only [hcard] using hfactor) hsep + have hunion : (cubeSize (fun x => s.badSign Q (cubeSignEquiv s.primes x)) : ℝ) ≤ + ∑ L, (cubeSize (S L) : ℝ) := by + have he : (fun x => s.badSign Q (cubeSignEquiv s.primes x)) = (fun x => ∃ L, S L x) := by + funext x + exact propext (s.badSign_iff_class Q _) + rw [he] + exact_mod_cast cubeSize_exists_le_sum S + rw [cubeSignEquiv_measure, div_le_iff₀ hpow] + have hh := (mul_le_mul_of_nonneg_left hunion hA.le).trans hpack + calc + _ ≤ (2 : ℝ)^Fintype.card s.primes / A := (le_div_iff₀ hA).mpr (by simpa only [mul_comm] using hh) + _ = _ := by rw [div_eq_mul_inv, mul_comm] + +theorem SplitSieve.signed_region_exp_bound (s : SplitSieve) (Q : Set GaussianInt) + (hr : 0 < s.primes.card) {U B N ε a b : ℝ} {h : ℕ} + (hU : 1 ≤ U) (hpU : ∀ p ∈ s.primes, (p : ℝ) ≤ U) + (hB : 0 ≤ B) (hdet : ∀ w ∈ Q, ∀ w' ∈ Q, (|determinant w w'| : ℝ) ≤ B) + (hsmall : B * U^(2*h) < (s.period : ℝ)) + (hQ : ∀ w ∈ Q, (w.norm : ℝ) ≤ N) (hε : 0 ≤ ε) + (hexcess : ε ≤ (∑ p : s.primes, Real.log (p : ℝ)) - Real.log N / 2) + (ha : 0 ≤ a) (hb : b ≤ a) + (htail : 2*a ≤ ε^2 / (2 * ∑ p : s.primes, + (((‖Real.log (p : ℝ)‖₊ / 2)^2 : ℝ≥0) : ℝ))) + (hgrowth : b ≤ (h : ℝ) * Real.log (1 + a / ((s.primes.card : ℝ)*Real.log 2))) : + (signMeasure s.primes).real {σ | s.badSign Q σ} ≤ Real.exp (-b) := by + have htwo : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hr' : 0 < (s.primes.card : ℝ) := by exact_mod_cast hr + have hbase : 0 < 1 + a / ((s.primes.card : ℝ)*Real.log 2) := by + have := div_nonneg ha (mul_pos hr' htwo).le + linarith + have hbexp : Real.exp b ≤ (1 + a / ((s.primes.card : ℝ)*Real.log 2))^h := by + rw [← Real.exp_log (pow_pos hbase h)] + apply Real.exp_le_exp.mpr + simpa only [Real.log_pow] using hgrowth + have hh := s.signed_region_bound Q hr hU hpU hB hdet hsmall hQ hε hexcess ha + (E := (2 : ℝ)^s.primes.card * Real.exp (-a)) + (A := Real.exp b) (h := h) (mul_pos (pow_pos (by norm_num) _) (Real.exp_pos _)) + (Real.exp_pos _) (by + rw [Real.log_mul (pow_pos (by norm_num : (0 : ℝ) < 2) _).ne' (Real.exp_pos _).ne', + Real.log_pow, Real.log_exp] + linarith) (by + rw [← Real.exp_add] + have he : b + -ε^2 / (2 * ∑ p : s.primes, + (((‖Real.log (p : ℝ)‖₊ / 2)^2 : ℝ≥0) : ℝ)) ≤ -a := by + rw [neg_div] + linarith + exact (mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr he) + (pow_nonneg (by norm_num) _)).trans_eq (mul_comm _ _)) hbexp + simpa only [Real.exp_neg] using hh + +def orientedRectangle (e : ℂ) (R W : ℝ) : Set GaussianInt := + {z | |(star e * (z : ℂ)).re| ≤ R ∧ |(star e * (z : ℂ)).im| ≤ W} + +theorem rectangle_norm_bound {e : ℂ} (he : ‖e‖ = 1) {R W : ℝ} + (hW : 0 ≤ W) (hWR : W ≤ R) {z : GaussianInt} (hz : z ∈ orientedRectangle e R W) : + (z.norm : ℝ) ≤ 2 * R^2 := by + have hnorm : ‖star e * (z : ℂ)‖ = ‖(z : ℂ)‖ := by + rw [norm_mul, norm_star, he, one_mul] + rw [norm_square_complex, ← hnorm, ← Complex.normSq_eq_norm_sq, Complex.normSq_apply] + have hx : (star e * (z : ℂ)).re ^ 2 ≤ R^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg ((star e * (z : ℂ)).re)) + (hW.trans hWR)).mpr hz.1 + have hy : (star e * (z : ℂ)).im ^ 2 ≤ W^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg ((star e * (z : ℂ)).im)) hW).mpr hz.2 + have hww := (sq_le_sq₀ hW (hW.trans hWR)).mpr hWR + nlinarith + +theorem determinant_rotated (e : ℂ) (he : ‖e‖ = 1) (z w : GaussianInt) : + (determinant z w : ℝ) = + (star e * (z : ℂ)).re * (star e * (w : ℂ)).im - + (star e * (z : ℂ)).im * (star e * (w : ℂ)).re := by + have hsq : e.re^2 + e.im^2 = 1 := by + have hh := Complex.normSq_eq_norm_sq e + rw [he] at hh + simpa [Complex.normSq_apply, pow_two] using hh + simp only [Complex.mul_re, Complex.mul_im, Complex.star_def, Complex.conj_re, Complex.conj_im, + ← GaussianInt.intCast_re, ← GaussianInt.intCast_im, determinant, Int.cast_sub, Int.cast_mul] + nlinarith [congrArg (fun x : ℝ => x * ((z.re : ℝ) * w.im - z.im * w.re)) hsq] + +theorem rectangle_determinant_bound {e : ℂ} (he : ‖e‖ = 1) {R W : ℝ} + (hR : 0 ≤ R) (hW : 0 ≤ W) {z w : GaussianInt} + (hz : z ∈ orientedRectangle e R W) (hw : w ∈ orientedRectangle e R W) : + (|determinant z w| : ℝ) ≤ 2*R*W := by + rw [determinant_rotated e he] + apply (abs_sub _ _).trans + rw [abs_mul, abs_mul] + have h1 := mul_le_mul hz.1 hw.2 (abs_nonneg _) hR + have h2 := mul_le_mul hz.2 hw.1 (abs_nonneg _) hW + nlinarith + +theorem rectangle_cube_growth {r : ℕ} {d : ℝ} (hd : 0 < d) (hd1 : d ≤ 1/4) + (hlarge : 1000 ≤ d^3 * r) : + let h := ⌊d * r / 10⌋₊ + d^3 * r / 5120 ≤ (h : ℝ) * Real.log (1 + (d^2 * r / 64) / ((r : ℝ) * Real.log 2)) := by + dsimp only + have hr : 0 < (r : ℝ) := by + by_contra h + have hr0 : (r : ℝ) = 0 := le_antisymm (le_of_not_gt h) (Nat.cast_nonneg _) + rw [hr0, mul_zero] at hlarge + norm_num at hlarge + have loglo : (1/2 : ℝ) ≤ Real.log 2 := by linarith [Real.log_two_gt_d9] + have loghi : Real.log 2 ≤ 1 := by linarith [Real.log_two_lt_d9] + have hlog : 0 < Real.log 2 := lt_of_lt_of_le (by norm_num) loglo + have hdle : d ≤ 1 := by linarith + have hsq : d^2 ≤ 1 := by nlinarith + have hdr : d^3 * r ≤ d * r := by + exact mul_le_mul_of_nonneg_right (by nlinarith [mul_nonneg hd.le (sub_nonneg.mpr hsq)]) hr.le + have hfloor : d * r / 20 ≤ (⌊d * r / 10⌋₊ : ℝ) := by + have hh := Nat.lt_floor_add_one (d * r / 10) + have hdrl : 1000 ≤ d * r := hlarge.trans hdr + linarith + have heq : (d^2 * r / 64) / ((r : ℝ) * Real.log 2) = d^2 / (64 * Real.log 2) := by + field_simp + let δ := d^2 / (64 * Real.log 2) + have hδ : 0 ≤ δ := div_nonneg (sq_nonneg _) (by positivity) + have hδ1 : δ ≤ 1 := by + apply (div_le_iff₀ (mul_pos (by norm_num) hlog)).mpr + nlinarith + have hδlo : d^2 / 64 ≤ δ := by + apply (le_div_iff₀ (mul_pos (by norm_num) hlog)).mpr + nlinarith [mul_nonneg (sq_nonneg d) (sub_nonneg.mpr loghi)] + have hlogδ : δ/2 ≤ Real.log (1+δ) := by + apply le_trans ?_ (Real.le_log_one_add_of_nonneg hδ) + apply (le_div_iff₀ (by linarith : 0 < δ+2)).mpr + nlinarith [mul_nonneg hδ (sub_nonneg.mpr hδ1)] + rw [heq] + change _ ≤ (⌊d * r / 10⌋₊ : ℝ) * Real.log (1+δ) + have hm := mul_le_mul hfloor hlogδ (by linarith) (Nat.cast_nonneg _) + have hm' : d^3 * r / 2560 ≤ (d*r/20) * (δ/2) := by + have := mul_le_mul_of_nonneg_left hδlo (by positivity : 0 ≤ d*r/40) + nlinarith + have hnon : 0 ≤ d^3 * r := by positivity + nlinarith + +theorem rectangle_linear_large {r d : ℝ} (hr : 0 ≤ r) (hd : 0 ≤ d) (hd1 : d ≤ 1) + (hlarge : 1000 ≤ d^3 * r) : 1000 ≤ d*r := by + have hs : d^2 ≤ 1 := by nlinarith + have hc : d^3 ≤ d := by nlinarith [mul_nonneg hd (sub_nonneg.mpr hs)] + exact hlarge.trans (mul_le_mul_of_nonneg_right hc hr) + +theorem rectangle_log_small {r : ℕ} {d t u l : ℝ} + (hd : 0 < d) (hd1 : d ≤ 1/4) (ht : 1/2 ≤ t) (hu : 0 ≤ u) (hutu : u ≤ 2*t) + (hl : (r : ℝ)*t ≤ l) (hlarge : 1000 ≤ d^3 * r) : + Real.log 2 + (1-d)*l + (2*⌊d*r/10⌋₊ : ℕ)*u < l := by + have hdr : 1000 ≤ d*r := rectangle_linear_large (Nat.cast_nonneg _) hd.le (by linarith) hlarge + have hf : (⌊d*r/10⌋₊ : ℝ) ≤ d*r/10 := Nat.floor_le (by positivity) + have hm : (2*⌊d*r/10⌋₊ : ℕ)*u ≤ (d*r/5)*(2*t) := by + push_cast + apply mul_le_mul (by linarith) hutu hu + positivity + have hdl := mul_le_mul_of_nonneg_left hl hd.le + have hdt : 500 ≤ d*r*t := by + have hh := mul_le_mul_of_nonneg_left ht (by positivity : 0 ≤ d*r) + nlinarith + have hlog : Real.log 2 ≤ 1 := by linarith [Real.log_two_lt_d9] + nlinarith + +theorem rectangle_log_excess {r : ℕ} {d t l : ℝ} (hd : 0 < d) (hd1 : d ≤ 1/4) + (ht : 1/2 ≤ t) (hl : (r : ℝ)*t ≤ l) (hlarge : 1000 ≤ d^3 * r) : + d*l/2 ≤ l - ((1-d)*l + Real.log 2/2) := by + have hdr : 1000 ≤ d*r := rectangle_linear_large (Nat.cast_nonneg _) hd.le (by linarith) hlarge + have h1 := mul_le_mul_of_nonneg_left hl hd.le + have h2 := mul_le_mul_of_nonneg_left ht (by positivity : 0 ≤ d*r) + have hlog : Real.log 2 ≤ 1 := by linarith [Real.log_two_lt_d9] + nlinarith + +theorem rectangle_hoeffding_exponent {r d t l V : ℝ} (hr : 0 < r) (hd : 0 ≤ d) + (ht : 0 < t) (hl : r*t ≤ l) (hV : 0 < V) (hVup : V ≤ r*t^2) : + 2*(d^2*r/64) ≤ (d*l/2)^2 / (2*V) := by + have hdl : 0 ≤ d*r*t/2 := by positivity + have hdl' : d*r*t/2 ≤ d*l/2 := by nlinarith [mul_le_mul_of_nonneg_left hl hd] + have hs : (d*r*t/2)^2 ≤ (d*l/2)^2 := (sq_le_sq₀ hdl (hdl.trans hdl')).mpr hdl' + have hden : 0 < 2*r*t^2 := by positivity + calc + 2*(d^2*r/64) ≤ d^2*r/8 := by nlinarith [mul_nonneg (sq_nonneg d) hr.le] + _ = (d*r*t/2)^2 / (2*r*t^2) := by field_simp; ring + _ ≤ (d*l/2)^2 / (2*r*t^2) := div_le_div_of_nonneg_right hs hden.le + _ ≤ (d*l/2)^2 / (2*V) := div_le_div_of_nonneg_left (sq_nonneg _) (by positivity) (by nlinarith) + +theorem SplitSieve.log_period (s : SplitSieve) : + Real.log (s.period : ℝ) = ∑ p : s.primes, Real.log (p : ℝ) := by + classical + unfold SplitSieve.period + push_cast + rw [Real.log_prod (fun p hp => by + exact_mod_cast (s.prime_mem p hp).ne_zero)] + exact (Finset.sum_coe_sort s.primes (fun p => Real.log (p : ℝ))).symm + +noncomputable def SplitSieve.logVariance (s : SplitSieve) : ℝ := + ∑ p : s.primes, (((‖Real.log (p : ℝ)‖₊ / 2)^2 : ℝ≥0) : ℝ) + +theorem SplitSieve.logVariance_pos (s : SplitSieve) (hr : 0 < s.primes.card) : + 0 < s.logVariance := by + classical + obtain ⟨p,hp⟩ := Finset.card_pos.mp hr + have hlog : 0 < Real.log (p : ℝ) := Real.log_pos (by exact_mod_cast (s.prime_mem p hp).one_lt) + apply Finset.sum_pos' (fun _ _ => by positivity) + refine ⟨⟨p,hp⟩, Finset.mem_univ _, ?_⟩ + simp only [NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, coe_nnnorm, Real.norm_eq_abs, + abs_of_pos hlog] + positivity + +theorem SplitSieve.logVariance_le (s : SplitSieve) {U : ℝ} + (hU : 1 ≤ U) (hpU : ∀ p ∈ s.primes, (p : ℝ) ≤ U) : + s.logVariance ≤ (s.primes.card : ℝ) * (Real.log U / 2)^2 := by + classical + calc + _ ≤ ∑ _p : s.primes, (Real.log U / 2)^2 := by + apply Finset.sum_le_sum + intro p _ + have hp : 0 < (p : ℝ) := by exact_mod_cast (s.prime_mem p p.property).pos + have hlog : 0 ≤ Real.log (p : ℝ) := Real.log_nonneg (by exact_mod_cast (s.prime_mem p p.property).one_le) + have hle := Real.log_le_log hp (hpU p p.property) + simp only [NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, coe_nnnorm, Real.norm_eq_abs, + abs_of_nonneg hlog] + exact (sq_le_sq₀ (by positivity) (div_nonneg (Real.log_nonneg hU) (by norm_num))).mpr (by linarith) + _ = _ := by simp [nsmul_eq_mul] + +theorem SplitSieve.signed_rectangle (s : SplitSieve) + {T R W d : ℝ} {e : ℂ} (he : ‖e‖ = 1) (hT : 5 ≤ T) + (hpT : ∀ p ∈ s.primes, T ≤ (p : ℝ) ∧ (p : ℝ) ≤ 2*T) + (hW : 1 ≤ W) (hWR : W ≤ R) (hd : 0 < d) (hd1 : d < 1/4) + (harea : R*W ≤ (s.period : ℝ)^(1-d)) (hlarge : 1000 ≤ d^3*s.primes.card) : + (signMeasure s.primes).real {σ | s.badSign (orientedRectangle e R W) σ} ≤ + Real.exp (-(d^3*s.primes.card/5120)) := by + have hr : 0 < s.primes.card := by + by_contra h + have hz : s.primes.card = 0 := Nat.eq_zero_of_not_pos h + rw [hz, Nat.cast_zero, mul_zero] at hlarge + norm_num at hlarge + have hr' : 0 < (s.primes.card : ℝ) := by exact_mod_cast hr + have hP : 0 < (s.period : ℝ) := by exact_mod_cast s.period_pos + have hTpos : 0 < T := by linarith + have hU : 1 ≤ 2*T := by linarith + have hUpos : 0 < 2*T := by linarith + have hWpos : 0 < W := by linarith + have hRpos : 0 < R := lt_of_lt_of_le hWpos hWR + have hRW : 0 < R*W := mul_pos hRpos hWpos + have hlogT : 1/2 ≤ Real.log T := by + have hlog2T := Real.log_le_log (by norm_num : (0 : ℝ) < 2) (by linarith : 2 ≤ T) + linarith [Real.log_two_gt_d9] + have hlogU : Real.log (2*T) ≤ 2*Real.log T := by + rw [Real.log_mul (by norm_num) hTpos.ne'] + have hh := Real.log_le_log (by norm_num : (0 : ℝ) < 2) (by linarith : 2 ≤ T) + linarith + have hlogP : (s.primes.card : ℝ)*Real.log T ≤ Real.log (s.period : ℝ) := by + rw [s.log_period] + calc + _ = ∑ _p : s.primes, Real.log T := by simp [nsmul_eq_mul] + _ ≤ _ := Finset.sum_le_sum (fun p _ => Real.log_le_log hTpos (hpT p p.property).1) + have hlogPpos : 0 < Real.log (s.period : ℝ) := + (mul_pos hr' (by linarith : 0 < Real.log T)).trans_le hlogP + have hRarea : R ≤ R*W := by nlinarith + have hlogR : Real.log R ≤ (1-d)*Real.log (s.period : ℝ) := by + have hh := Real.log_le_log hRpos (hRarea.trans harea) + simpa only [Real.log_rpow hP] using hh + have hlogB : Real.log (2*R*W) ≤ Real.log 2 + (1-d)*Real.log (s.period : ℝ) := by + have hh := Real.log_le_log hRW harea + rw [Real.log_rpow hP] at hh + have heq : 2*R*W = 2*(R*W) := by ring + rw [heq, Real.log_mul (by norm_num) hRW.ne'] + linarith + have hlogN : Real.log (2*R^2)/2 ≤ (1-d)*Real.log (s.period : ℝ) + Real.log 2/2 := by + rw [Real.log_mul (by norm_num) (pow_pos hRpos 2).ne', Real.log_pow] + norm_num only [Nat.cast_ofNat] + linarith + let h : ℕ := ⌊d*s.primes.card/10⌋₊ + have hsmall : (2*R*W) * (2*T)^(2*h) < (s.period : ℝ) := by + apply (Real.log_lt_log_iff (mul_pos (by positivity) (pow_pos hUpos _)) hP).mp + rw [Real.log_mul (by positivity : 2*R*W ≠ 0) (pow_pos hUpos _).ne', Real.log_pow] + have hh := rectangle_log_small hd hd1.le hlogT (Real.log_nonneg hU) hlogU hlogP hlarge + exact (add_le_add_left hlogB _).trans_lt hh + have hV := s.logVariance_pos hr + have hVup : s.logVariance ≤ (s.primes.card : ℝ)*(Real.log T)^2 := by + apply (s.logVariance_le hU (fun p hp => (hpT p hp).2)).trans + apply mul_le_mul_of_nonneg_left ?_ hr'.le + apply (sq_le_sq₀ (div_nonneg (Real.log_nonneg hU) (by norm_num)) (by linarith : 0 ≤ Real.log T)).mpr + linarith + apply s.signed_region_exp_bound (orientedRectangle e R W) hr hU + (fun p hp => (hpT p hp).2) (by positivity) (fun _ hw _ hw' => + rectangle_determinant_bound he hRpos.le hWpos.le hw hw') hsmall + (fun _ hz => rectangle_norm_bound he hWpos.le hWR hz) + (ε := d*Real.log (s.period : ℝ)/2) (a := d^2*s.primes.card/64) (h := h) + · positivity + · rw [← s.log_period] + have hh := rectangle_log_excess hd hd1.le hlogT hlogP hlarge + linarith + · positivity + · have hc : d^3 ≤ d^2 := by nlinarith [sq_nonneg d, mul_nonneg (sq_nonneg d) (by linarith : 0 ≤ 1-d)] + have hh := mul_le_mul_of_nonneg_right hc hr'.le + nlinarith [mul_nonneg (sq_nonneg d) hr'.le] + · exact rectangle_hoeffding_exponent hr' hd.le (by linarith) hlogP hV hVup + · exact rectangle_cube_growth hd hd1.le hlarge + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/SignedResidues.lean b/lean/OAI/NumberTheory/GaussianMoat/SignedResidues.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e60e34372caba6567fbb3b641a8bff14a10896c --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/SignedResidues.lean @@ -0,0 +1,216 @@ +import OAI.NumberTheory.GaussianMoat.WalkWords + +namespace OAI + +universe uIota uOmega uAlpha uGroup uGroupPrime uCapitalGamma + +namespace GaussianMoat +open scoped BigOperators Classical + +abbrev SplitSieve.SignedIndex (s : SplitSieve) := (Fin s.primes.card → Bool) × Fin s.primes.card + +noncomputable def SplitSieve.signedPrime (s : SplitSieve) (i : s.SignedIndex) : ℕ := + s.enumeration i.2 +noncomputable def SplitSieve.signedFactorAt (s : SplitSieve) (i : s.SignedIndex) : GaussianInt := + signedFactor (s.factor (s.signedPrime i)) (i.1 i.2) + +lemma SplitSieve.signedFactorAt_norm (s : SplitSieve) (i : s.SignedIndex) : + (s.signedFactorAt i).norm = (s.signedPrime i:ℤ) := by + rw [signedFactorAt,signedFactor_norm] + exact s.factor_norm _ (s.enumeration i.2).property + +lemma SplitSieve.signedFactorAt_ne_zero (s : SplitSieve) (i : s.SignedIndex) : + s.signedFactorAt i≠0 := by + intro h + have hn := s.signedFactorAt_norm i + rw [h] at hn + have hp := (s.prime_mem _ (s.enumeration i.2).property).ne_zero + apply hp + change s.signedPrime i = 0 + simpa only [Zsqrtd.norm_zero,Nat.cast_eq_zero] using hn.symm + +abbrev SplitSieve.Residue (s : SplitSieve) (i : s.SignedIndex) := + GaussianInt ⧸ multiples (s.signedFactorAt i) +noncomputable instance SplitSieve.residueFintype (s : SplitSieve) (i : s.SignedIndex) : + Fintype (s.Residue i) := by + let := finite_gaussianResidue (s.signedFactorAt_ne_zero i) + exact Fintype.ofFinite _ + +lemma SplitSieve.residue_card (s : SplitSieve) (i : s.SignedIndex) : + Fintype.card (s.Residue i)=s.signedPrime i := by + rw [← Nat.card_eq_fintype_card] + change Nat.card (GaussianInt ⧸ multiples (s.signedFactorAt i)) = _ + rw [multiples_index (s.signedFactorAt_ne_zero i),s.signedFactorAt_norm] + simp + +noncomputable def SplitSieve.residue (s : SplitSieve) (i : s.SignedIndex) : + GaussianInt → s.Residue i := gaussianResidue (s.signedFactorAt i) + +lemma SplitSieve.residue_fibers (s : SplitSieve) (i : s.SignedIndex) (z w : GaussianInt) : + s.residue i z=s.residue i w ↔ s.residueVector i.1 z i.2=s.residueVector i.1 w i.2 := by + change gaussianResidue _ z=gaussianResidue _ w ↔ residueCode _ z=residueCode _ w + rw [gaussianResidue_eq,residueCode_eq] + rfl + +lemma FinLaw.uniform_expect {ι : Type uIota} [Fintype ι] [Nonempty ι] (f : ι → ℝ) : + (∑ i, FinLaw.uniform ι i*f i)=𝔼 i, f i := by + rw [Fintype.expect_eq_sum_div_card] + simp only [FinLaw.uniform_mass,← Finset.mul_sum,div_eq_inv_mul] + +lemma SplitSieve.signedIndex_nonempty (s : SplitSieve) (hne : s.primes.Nonempty) : + Nonempty s.SignedIndex := by + have hk := hne.card_pos + exact ⟨(fun _ => true,⟨0,hk⟩)⟩ + +theorem SplitSieve.signed_coverage_deficit {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] + (s : SplitSieve) (hne : s.primes.Nonempty) (p : FinLaw Ω) + (Z : Ω → GaussianInt) (C : Ω → α) (a : GaussianInt) {b : ℕ} + (hb : 0 s.residue i (Z ω-a)) C)) ≤ e*s.meanLog+E/b := by + let := s.signedIndex_nonempty hne + have hc := s.coverage_conditioning p Z C hbk + have he (i : s.SignedIndex) : + p.cHf (fun ω => s.residue i (Z ω-a)) C = + p.cHf (fun ω => s.residueVector i.1 (Z ω) i.2) C := by + apply p.cHf_congr_fibers _ _ _ _ + · intro ω ν + change gaussianResidue _ (Z ω-a)=gaussianResidue _ (Z ν-a) ↔ _ + rw [gaussianResidue_sub,gaussianResidue_sub,sub_left_inj] + exact s.residue_fibers i _ _ + · intro ω ν; rfl + have hd : (∑ i : s.SignedIndex, FinLaw.uniform _ i* + (Real.log (Fintype.card (s.Residue i))-p.cHf (fun ω => s.residue i (Z ω-a)) C)) = + s.meanLog-(𝔼 σ : Fin s.primes.card → Bool, 𝔼 i : Fin s.primes.card, + p.cHf (fun ω => s.residueVector σ (Z ω) i) C) := by + rw [FinLaw.uniform_expect] + simp only [s.residue_card,he,Finset.expect_sub_distrib] + simp only [← Finset.univ_product_univ,Finset.expect_product] + simp only [signedPrime,meanLog,Fintype.expect_const] + rw [hd] + have hbp : (0:ℝ) s.residueVector σ (Z ω) i) C))*(b:ℝ) ≤ + (e*s.meanLog+E/b)*(b:ℝ) := by + rw [add_mul,div_mul_cancel₀ _ hbp.ne'] + nlinarith only [hc,hH,hC] + exact hgoal + +namespace FinLaw +variable {G : Type uGroup} [Fintype G] + +noncomputable def lowResidues (p : FinLaw G) (τ : ℝ) : Finset G := + Finset.univ.filter (fun x => p x<τ/(Fintype.card G:ℝ)) + +lemma not_mem_lowResidues (p : FinLaw G) (τ : ℝ) (x : G) : + x∉p.lowResidues τ ↔ τ/(Fintype.card G:ℝ)≤p x := by + simp only [lowResidues,Finset.mem_filter,Finset.mem_univ,true_and,not_lt] + +lemma lowResidues_prob (p : FinLaw G) (τ : ℝ) : + p.prob (fun x => x∈p.lowResidues τ) ≤ τ*(p.lowResidues τ).card/(Fintype.card G:ℝ) := by + have he : p.prob (fun x => x∈p.lowResidues τ)=∑ x∈p.lowResidues τ, p x := by + unfold prob + trans ∑ x, if x∈p.lowResidues τ then p.mass x else 0 + · apply Finset.sum_congr rfl + intro x _ + split_ifs <;> rfl + · rw [← Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter,Finset.univ_inter] + rw [he] + have hh := Finset.sum_le_sum (s := p.lowResidues τ) (fun x hx => + ((Finset.mem_filter.mp hx).2).le) + simp only [Finset.sum_const,nsmul_eq_mul] at hh + have heq : ((p.lowResidues τ).card:ℝ)*(τ/(Fintype.card G:ℝ)) = + τ*(p.lowResidues τ).card/(Fintype.card G:ℝ) := by ring + rw [heq] at hh + exact hh + +lemma lowResidues_equiv {G' : Type uGroupPrime} [Fintype G'] (p : FinLaw G) (e : G ≃ G') (τ : ℝ) : + ((p.map e).lowResidues τ).card=(p.lowResidues τ).card := by + have h : (p.map e).lowResidues τ=(p.lowResidues τ).image e := by + ext x + simp only [lowResidues,Finset.mem_filter,Finset.mem_univ,true_and, + Finset.mem_image,map_equiv_mass,Fintype.card_congr e] + constructor + · intro hx + exact ⟨e.symm x,hx,e.apply_symm_apply x⟩ + · rintro ⟨y,hy,rfl⟩ + simpa only [e.symm_apply_apply] using hy + rw [h,Finset.card_image_of_injective _ e.injective] + +theorem lowResidues_base {ι : Type uIota} [Fintype ι] + (G : ι → Type uGroup) [∀ i, Fintype (G i)] (w : FinLaw ι) + (p : (i : ι) → FinLaw (G i)) (u : ι → ℝ) {τ b e : ℝ} + (hτ : τ≤3/8) (hb : 0 u i≤((p i).lowResidues τ).card) ≤ e/b := by + apply low_mass_average G w p (fun i => (p i).lowResidues τ) _ hb + · intro i x hx + exact ((Finset.mem_filter.mp hx).2).le.trans + (div_le_div_of_nonneg_right hτ (Nat.cast_nonneg _)) + · intro i hi + have hne := (p i).nonempty + have hp : (0:ℝ) u' i≤ + (((q ω).map (h i)).lowResidues (τ+4*δ)).card) ≤ η') + (hsmall : η'+ε≤η*δ/2) (hscale : 2*(1-Real.log (η*δ/2))≤v) + (hgap : e<η*δ*v/4) + (hdata : (∑ i, w i*(Real.log (Fintype.card (G i))- + (p.joint (fun ω => (q ω).iid n)).cHf (fun x => Y i x.1) Prod.snd))≤e) + (hb : ∀ i, 1≤b i) + (hv : ∀ i, v≤Real.log (Fintype.card (G i))-Real.log (b i)) + (hu' : ∀ i, u' i/δ≤b i) + (herr : ∀ i, (Fintype.card (G i):ℝ)* + Real.exp (-(n:ℝ)*δ^2*u i/(2*(Fintype.card (G i):ℝ)))≤ε) : + w.prob (fun i => u i≤(((p.joint q).map (fun x => Y i x.1+h i x.2)).lowResidues τ).card) ≤ η := by + let P := fun i => (p.joint q).map (fun x => Y i x.1+h i x.2) + let K := fun i => (P i).lowResidues τ + let B₀ := fun i => u i≤(K i).card + let B₁ := fun i ω => u' i≤(((q ω).map (h i)).lowResidues (τ+4*δ)).card + let E := fun i ω => (((q ω).map (h i)).lowResidues (τ+4*δ)) + apply backward_coverage_step G w p q Y h B₀ B₁ K E b hn hτ hτ1 hδ hδ1 + hε hη hnext hsmall hscale hgap hdata + · intro i hi + apply Finset.card_pos.mp + have hh : (0:ℝ)<(K i).card := (hu i).trans_le hi + exact_mod_cast hh + · intro i _; exact hb i + · intro i _; exact hv i + · intro i _ + have hh := (P i).lowResidues_prob τ + rw [prob_map] at hh + exact hh + · intro i _ ω _ x hx + exact (((q ω).map (h i)).not_mem_lowResidues _ x).mp hx + · intro i _ ω hω + have hh : ((E i ω).card:ℝ) simp [windowBlocks] + | succ W ih => + have hi := ih (fun w hw => hJ w (by omega)) + rw [windowBlocks_succ,List.length_append,List.length_append] + simp only [topBlocks_length,Nat.cast_add,Nat.cast_mul,topIterations,Nat.cast_ofNat, + accurateBlock,List.length_ofFn,accurateIterations,Nat.cast_pow] + have hh := hJ W (by omega) + have hW : (W:ℝ)+1=(W+1:ℕ) := by push_cast; rfl + push_cast + nlinarith only [hi,hh] + +lemma windowBlocks_length_bound_of_bins {a : ℝ} {m W : ℕ} + (J : ℕ → Finset ℕ) (hm : 2≤Real.exp m) + (hJ : ∀ w (s.signedPrime i:ℝ)*Real.exp (-X/200)) (1/100) := by + exact one_step_coverage s D N mid bot b q (coverageRepetitions X) e e _ hm hb + (hm.size_pos hmean) (hm.size_cap hmean) (hb.size_pos hmean) (hb.size_cap hmean) + hN (coverageRepetitions_pos X) + (fun i => (Real.exp_le_exp.mpr hX).trans (hp i).1) + (fun i => mul_pos ((Real.exp_pos X).trans_le (hp i).1) (Real.exp_pos _)) hbase + (by linarith only [hmid,hcost]) hhazard + +lemma binEntropy_small_exp {t Y : ℝ} (ht : 0≤t) (hY : 1≤Y) + (htY : t≤Real.exp (-Y)) : + Real.binEntropy t≤(Y+1)*Real.exp (-Y) := by + have heY : 2≤Real.exp Y := by linarith only [Real.add_one_le_exp Y,hY] + have hu : Real.exp (-Y)≤(1/2:ℝ) := by + rw [Real.exp_neg] + exact inv_le_of_inv_le₀ (by norm_num) (by simpa using heY) + have hm := Real.binEntropy_strictMonoOn.monotoneOn + (show t∈Set.Icc 0 (2:ℝ)⁻¹ by norm_num; exact ⟨ht,htY.trans hu⟩) + (show Real.exp (-Y)∈Set.Icc 0 (2:ℝ)⁻¹ by norm_num; exact ⟨(Real.exp_pos _).le,hu⟩) htY + have hn := Real.negMulLog_le_one_sub_self (show 0≤1-Real.exp (-Y) by linarith only [hu]) + simp only [Real.binEntropy_eq_negMulLog_add_negMulLog_one_sub, + Real.negMulLog,Real.log_exp] at hm ⊢ + have hh : -(1-Real.exp (-Y))*Real.log (1-Real.exp (-Y))≤Real.exp (-Y) := by + simpa only [Real.negMulLog,sub_sub_cancel] using hn + nlinarith only [hm,hh] + +lemma exp_ratio_bound {a N X A : ℝ} (ha : a≤Real.exp (A*X)) + (hN : Real.exp (10*A*X)≤N) : + a/(N+1)≤Real.exp (-9*A*X) := by + have hNp : 0 ⟨v.2.1.val+(if v.1 then v.2.2.1.val else v.2.2.2.val),by + split_ifs <;> omega⟩ + +noncomputable def TimeLaw.step (P : TimeLaw) (z : ℕ → GaussianInt) (n : ℕ) : TimeLaw where + last := P.last+n + law := ((FinLaw.uniform Bool).joint (fun _ => P.law.joint (fun a => + differenceLaw (fun t => z (a.val+t)) n))).map (endpointTime P.last n) + +lemma SplitSieve.pointEntropy_map {Ω : Type uOmega} {Κ : Type uCapitalKappa} [Fintype Ω] [Fintype Κ] + (s : SplitSieve) (p : FinLaw Ω) (f : Ω → Κ) (Z : Κ → GaussianInt) (b : ℕ) : + s.pointEntropy (p.map f) Z b = s.pointEntropy p (Z ∘ f) b := by + unfold pointEntropy FinLaw.signedEntropy FinLaw.orderedEntropy + simp only [FinLaw.Hf_map] + rfl + +lemma SplitSieve.pointEntropy_joint_fst {Ω : Type uOmega} {Κ : Type uCapitalKappa} [Fintype Ω] [Fintype Κ] + (s : SplitSieve) (p : FinLaw Ω) (q : Ω → FinLaw Κ) (Z : Ω → GaussianInt) (b : ℕ) : + s.pointEntropy (p.joint q) (fun v => Z v.1) b = s.pointEntropy p Z b := by + have h := s.pointEntropy_map (p.joint q) Prod.fst Z b + rw [FinLaw.joint_map_fst] at h + exact h.symm + +lemma shifted_walk_injective (z : ℕ → GaussianInt) (hz : Function.Injective z) (a : ℕ) : + Function.Injective (fun t => z (a+t)) := by intro i j h; have := hz h; omega + +lemma walk_pair_displacement (z : ℕ → GaussianInt) {D : ℝ} (hD : 0 ≤ D) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) (a n i j : ℕ) + (hi : i ≤ n) (hj : j ≤ n) : + ‖((z (a+i)-z (a+j):GaussianInt):ℂ)‖ ≤ D*n := by + have h := walkSegment_dist_le (fun t => z (a+t)) hD + (fun t _ => by simpa only [Nat.add_assoc] using hstep (a+t)) hi hj + simpa only [dist_eq_norm,map_sub] using h + +theorem TimeLaw.step_enrichment (P : TimeLaw) (s : SplitSieve) + (z : ℕ → GaussianInt) {D F : ℝ} (hD : 1 ≤ D) + (hstep : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) {n b q : ℕ} + (hn : 1 ≤ n) (hb : 0 < b) (hbq : b < q) (hq : q ≤ s.primes.card) + (hF : ∀ a : Fin (P.last+1), F ≤ s.freshCoordinate + (differenceLaw (fun t => z (a.val+t)) n) + (fun ij => z (a.val+ij.1.val)) (fun ij => z (a.val+ij.2.val)) b (by omega)) : + (b:ℝ)*((q-b:ℕ)*F+s.pointEntropy P.law (fun a => z a.val) q- + 2*(Real.log 36+2*Real.log (D*n))) ≤ + 2*(q:ℝ)*s.pointEntropy (P.step z n).law (fun a => z a.val) b := by + let K := P.law.joint (fun a => differenceLaw (fun t => z (a.val+t)) n) + let X := fun v : Fin (P.last+1) × (Fin (n+1) × Fin (n+1)) => z (v.1.val+v.2.1.val) + let Y := fun v : Fin (P.last+1) × (Fin (n+1) × Fin (n+1)) => z (v.1.val+v.2.2.val) + let Z := fun v : Fin (P.last+1) × (Fin (n+1) × Fin (n+1)) => z v.1.val + have hF' : F ≤ s.freshCoordinate K X Y b (by omega) := by + have hh := s.freshCoordinate_joint_ge P.law + (fun a => differenceLaw (fun t => z (a.val+t)) n) + (fun a ij => z (a.val+ij.1.val)) (fun a ij => z (a.val+ij.2.val)) (by omega : b < s.primes.card) + apply le_trans _ hh + have hsum := Finset.sum_le_sum (s := Finset.univ) (fun a _ => + mul_le_mul_of_nonneg_left (hF a) (P.law.nonneg a)) + simpa only [← Finset.sum_mul,P.law.sum_one,one_mul] using hsum + have hDn : 1 ≤ D*n := one_le_mul_of_one_le_of_one_le hD (by exact_mod_cast hn) + have h := s.actual_enrichment K X Y Z hb hbq hq hF' hDn + (fun v => walk_pair_displacement z (by linarith) hstep _ _ _ _ (by omega) (by omega)) + (fun v => by + change ‖((z (v.1.val+v.2.1.val)-z v.1.val:GaussianInt):ℂ)‖ ≤ D*n + simpa only [Nat.add_zero] using + walk_pair_displacement z (by linarith) hstep v.1.val n v.2.1.val 0 (by omega) (by omega)) + have hZ := s.pointEntropy_joint_fst P.law + (fun a => differenceLaw (fun t => z (a.val+t)) n) (fun a => z a.val) q + rw [hZ] at h + have hout : s.pointEntropy (P.step z n).law (fun a => z a.val) b = + s.pointEntropy ((FinLaw.uniform Bool).joint (fun _ => K)) + (fun v => if v.1 then X v.2 else Y v.2) b := by + change s.pointEntropy (((FinLaw.uniform Bool).joint (fun _ => K)).map + (endpointTime P.last n)) (fun a => z a.val) b = _ + rw [s.pointEntropy_map] + apply congrArg (fun F => s.pointEntropy ((FinLaw.uniform Bool).joint (fun _ => K)) F b) + funext v + simp only [Function.comp_def,endpointTime,X,Y] + split_ifs <;> rfl + rw [hout] + exact h + +end + +namespace FinLaw + +section +open scoped BigOperators Classical +variable {Ω : Type uOmega} [Fintype Ω] + +noncomputable def prob (p : FinLaw Ω) (E : Ω → Prop) : ℝ := ∑ ω, if E ω then p ω else 0 + +lemma prob_nonneg (p : FinLaw Ω) (E : Ω → Prop) : 0 ≤ p.prob E := by + exact Finset.sum_nonneg (fun ω _ => by split_ifs <;> simp [p.nonneg ω]) + +lemma prob_le_one (p : FinLaw Ω) (E : Ω → Prop) : p.prob E ≤ 1 := by + rw [← p.sum_one] + exact Finset.sum_le_sum (fun ω _ => by split_ifs <;> simp [p.nonneg ω]) + +lemma prob_mono (p : FinLaw Ω) {E F : Ω → Prop} (h : ∀ ω, E ω → F ω) : + p.prob E ≤ p.prob F := by + apply Finset.sum_le_sum + intro ω _ + by_cases he : E ω + · simp [he,h ω he] + · by_cases hf : F ω <;> simp [he,hf,p.nonneg ω] + +noncomputable def iid (p : FinLaw Ω) (n : ℕ) : FinLaw (Fin n → Ω) where + mass := fun x => ∏ i, p (x i) + nonneg := fun x => Finset.prod_nonneg (fun i _ => p.nonneg _) + sum_one := by + rw [← Fintype.prod_sum] + simp only [p.sum_one,Finset.prod_const_one] + +@[simp] lemma iid_mass (p : FinLaw Ω) (n : ℕ) (x : Fin n → Ω) : + p.iid n x = ∏ i, p (x i) := rfl + +lemma iid_product (p : FinLaw Ω) (n : ℕ) (f : Ω → ℝ) : + (∑ x : Fin n → Ω, p.iid n x * ∏ i, f (x i)) = (∑ ω, p ω*f ω)^n := by + simp only [iid_mass,← Finset.prod_mul_distrib] + exact (Fintype.sum_pow (fun ω => p ω*f ω) n).symm + +lemma exp_neg_le_quadratic {t : ℝ} (ht : 0 ≤ t) : Real.exp (-t) ≤ 1-t+t^2/2 := by + have hm : Monotone (fun x : ℝ => 1-x+x^2/2-Real.exp (-x)) := by + apply monotone_of_hasDerivAt_nonneg (f' := fun x => -1+x+Real.exp (-x)) + · intro x + convert! (((hasDerivAt_const x (1:ℝ)).sub (hasDerivAt_id x)).add + (((hasDerivAt_id x).pow 2).div_const 2)).sub + (((hasDerivAt_id x).neg).exp) using 1 + simp only [Pi.neg_apply,id_eq] + ring + · intro x + have h := Real.add_one_le_exp (-x) + change 0 ≤ -1+x+Real.exp (-x) + linarith + have h := hm ht + simpa using h + +lemma prob_le_exp_moment (p : FinLaw Ω) (S : Ω → ℝ) {t a : ℝ} (ht : 0 ≤ t) : + p.prob (fun ω => S ω ≤ a) ≤ Real.exp (t*a) * ∑ ω, p ω*Real.exp (-t*S ω) := by + have h (ω : Ω) : (if S ω ≤ a then p ω else 0) ≤ + Real.exp (t*a)*(p ω*Real.exp (-t*S ω)) := by + by_cases hh : S ω ≤ a + · rw [ite_eq_left hh] + have he : 1 ≤ Real.exp (t*a+-t*S ω) := Real.one_le_exp_iff.mpr (by nlinarith) + calc + p ω = p ω*1 := by ring + _ ≤ p ω*Real.exp (t*a+-t*S ω) := mul_le_mul_of_nonneg_left he (p.nonneg ω) + _ = Real.exp (t*a)*(p ω*Real.exp (-t*S ω)) := by rw [Real.exp_add]; ring + · rw [ite_eq_right hh] + exact mul_nonneg (Real.exp_pos _).le (mul_nonneg (p.nonneg ω) (Real.exp_pos _).le) + simpa only [prob,Finset.mul_sum] using Finset.sum_le_sum (s := Finset.univ) (fun ω _ => h ω) + +lemma bernoulli_moment (p : FinLaw Ω) (E : Ω → Prop) (t : ℝ) : + (∑ ω, p ω*Real.exp (-t*(if E ω then 1 else 0))) = + 1+p.prob E*(Real.exp (-t)-1) := by + have he (ω : Ω) : p ω*Real.exp (-t*(if E ω then 1 else 0)) = + p ω+(if E ω then p ω else 0)*(Real.exp (-t)-1) := by + split_ifs <;> simp only [mul_one,mul_zero,Real.exp_zero,zero_mul,add_zero] + ring + simp only [he,Finset.sum_add_distrib,← Finset.sum_mul,p.sum_one,prob] + +theorem iid_lower_tail (p : FinLaw Ω) (E : Ω → Prop) (n : ℕ) + {μ δ : ℝ} (hμ : 0 < μ) (hδ : 0 ≤ δ) (hp : μ ≤ p.prob E) : + (p.iid n).prob (fun x => (∑ i : Fin n, if E (x i) then (1:ℝ) else 0) ≤ n*(μ-δ)) ≤ + Real.exp (- (n:ℝ)*δ^2/(2*μ)) := by + let t := δ/μ + have ht : 0 ≤ t := div_nonneg hδ hμ.le + have hm := prob_le_exp_moment (p.iid n) + (fun x => ∑ i : Fin n, if E (x i) then (1:ℝ) else 0) ht (a := n*(μ-δ)) + have hfactor : (∑ x : Fin n → Ω, p.iid n x * + Real.exp (-t*∑ i : Fin n, if E (x i) then 1 else 0)) = + (1+p.prob E*(Real.exp (-t)-1))^n := by + simp_rw [Finset.mul_sum,Real.exp_sum] + rw [iid_product p n (fun ω => Real.exp (-t*(if E ω then 1 else 0))),bernoulli_moment] + rw [hfactor] at hm + have hbase0 : 0 ≤ 1+p.prob E*(Real.exp (-t)-1) := by + rw [← bernoulli_moment] + exact Finset.sum_nonneg (fun ω _ => mul_nonneg (p.nonneg ω) (Real.exp_pos _).le) + have hbase : 1+p.prob E*(Real.exp (-t)-1) ≤ Real.exp (μ*(Real.exp (-t)-1)) := by + have hn : Real.exp (-t)-1 ≤ 0 := by + have h := Real.exp_le_one_iff.mpr (neg_nonpos.mpr ht) + linarith + have h1 := mul_le_mul_of_nonpos_right hp hn + have h2 := Real.add_one_le_exp (μ*(Real.exp (-t)-1)) + linarith + have hpw := pow_le_pow_left₀ hbase0 hbase n + have hmul := mul_le_mul_of_nonneg_left hpw (Real.exp_pos (t*(n*(μ-δ)))).le + apply hm.trans (hmul.trans ?_) + rw [← Real.exp_nat_mul,← Real.exp_add] + apply Real.exp_le_exp.mpr + have he := exp_neg_le_quadratic ht + have h := mul_le_mul_of_nonneg_left he (mul_nonneg (Nat.cast_nonneg n) hμ.le) + have hid : t*((n:ℝ)*(μ-δ))+(n:ℝ)*μ*(-t+t^2/2) = -(n:ℝ)*δ^2/(2*μ) := by + dsimp [t] + field_simp + ring + rw [← hid] + nlinarith + +end + +section +open scoped BigOperators Classical +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} [Fintype Ω] [Fintype α] [Fintype β] [Fintype γ] + +lemma le_map_apply (p : FinLaw Ω) (X : Ω → α) (ω : Ω) : p ω ≤ p.map X (X ω) := by + have h := Finset.single_le_sum (s := Finset.univ) + (f := fun ν => if X ν=X ω then p ν else 0) + (fun ν _ => by split_ifs <;> simp [p.nonneg ν]) (Finset.mem_univ ω) + simpa only [ite_true,map_mass] using h + +noncomputable def conditionOn (p : FinLaw Ω) (X : Ω → α) (a : α) : FinLaw Ω := + if h : p.map X a = 0 then p else { + mass := fun ω => if X ω=a then p ω/(p.map X a) else 0 + nonneg := fun ω => by split_ifs; exact div_nonneg (p.nonneg ω) ((p.map X).nonneg a); rfl + sum_one := by + have he : (∑ ω, if X ω=a then p ω/(p.map X a) else 0) = + (∑ ω, if X ω=a then p ω else 0)/(p.map X a) := by + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro ω _ + split_ifs <;> simp + rw [he,← map_mass,div_self h] } + +lemma conditionOn_weight (p : FinLaw Ω) (X : Ω → α) (a : α) (ω : Ω) : + p.map X a * p.conditionOn X a ω = if X ω=a then p ω else 0 := by + by_cases hz : p.map X a=0 + · rw [hz,zero_mul] + split_ifs with hh + · have h := p.le_map_apply X ω + rw [hh,hz] at h + exact (le_antisymm h (p.nonneg ω)).symm + · rfl + · unfold conditionOn + rw [dite_eq_right hz] + change p.map X a * (if X ω=a then p ω/(p.map X a) else 0) = _ + by_cases hx : X ω=a + · rw [ite_eq_left hx,ite_eq_left hx] + exact mul_div_cancel₀ _ hz + · rw [ite_eq_right hx,ite_eq_right hx,mul_zero] + +lemma disintegration (p : FinLaw Ω) (X : Ω → α) : + (p.map X).joint (p.conditionOn X) = p.map (fun ω => (X ω,ω)) := by + ext ⟨a,ω⟩ + rw [joint_mass,conditionOn_weight,map_mass] + simp only [Prod.mk.injEq] + rw [Finset.sum_eq_single ω] + · simp + · intro ν _ hn + simp [hn] + · simp + +lemma conditionOn_mixture (p : FinLaw Ω) (X : Ω → α) : + (p.map X).mix (p.conditionOn X) = p := by + rw [← joint_map_snd,disintegration,map_comp] + exact p.map_id + +lemma conditionOn_observation (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) : + p.H (fun ω => (X ω,Y ω)) = p.H X+∑ a, p.map X a*(p.conditionOn X a).H Y := by + have h := (p.map X).Hf_joint_pair (p.conditionOn X) Y + rw [disintegration,Hf_map] at h + simpa only [Hf_eq_H,H,Function.comp_def] using h + +lemma condH_eq_conditionOn (p : FinLaw Ω) (Y : Ω → β) (X : Ω → α) : + p.condH Y X = ∑ a, p.map X a*(p.conditionOn X a).H Y := by + unfold condH + rw [p.H_pair_comm Y X,p.conditionOn_observation X Y] + ring + +lemma prob_map (p : FinLaw Ω) (f : Ω → α) (E : α → Prop) : + (p.map f).prob E = p.prob (fun ω => E (f ω)) := by + simp only [prob,map_mass] + have h (a : α) : (if E a then ∑ ω, if f ω=a then p ω else 0 else 0) = + ∑ ω, if f ω=a then (if E a then p ω else 0) else 0 := by + by_cases he : E a <;> simp [he] + simp_rw [h] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro ω _ + simp + +lemma prob_joint (p : FinLaw Ω) (q : Ω → FinLaw α) (E : Ω × α → Prop) : + (p.joint q).prob E = ∑ ω, p ω*(q ω).prob (fun a => E (ω,a)) := by + simp only [prob,Fintype.sum_prod_type,joint_mass,Finset.mul_sum] + apply Finset.sum_congr rfl + intro ω _ + apply Finset.sum_congr rfl + intro a _ + split_ifs <;> simp + +lemma conditionOn_prob (p : FinLaw Ω) (X : Ω → α) (E : Ω → Prop) : + (∑ a, p.map X a*(p.conditionOn X a).prob E) = p.prob E := by + rw [← prob_joint (p.map X) (p.conditionOn X) (fun v => E v.2),disintegration,prob_map] + +lemma prob_le_expect_div (p : FinLaw Ω) (f : Ω → ℝ) (hf : ∀ ω, 0 ≤ f ω) + {a : ℝ} (ha : 0 < a) : + p.prob (fun ω => a < f ω) ≤ (∑ ω, p ω*f ω)/a := by + apply (le_div_iff₀ ha).mpr + rw [prob,Finset.sum_mul] + apply Finset.sum_le_sum + intro ω _ + by_cases hh : a < f ω + · simp only [ite_eq_left hh] + exact mul_le_mul_of_nonneg_left hh.le (p.nonneg ω) + · simp only [ite_eq_right hh,zero_mul] + exact mul_nonneg (p.nonneg ω) (hf ω) + +lemma prob_compl (p : FinLaw Ω) (E : Ω → Prop) : + p.prob (fun ω => ¬ E ω) = 1-p.prob E := by + have h : p.prob (fun ω => ¬ E ω)+p.prob E = 1 := by + rw [prob,prob,← Finset.sum_add_distrib,← p.sum_one] + apply Finset.sum_congr rfl + intro ω _ + by_cases he : E ω <;> simp [he] + linarith + +lemma prob_inter_ge (p : FinLaw Ω) (E F : Ω → Prop) : + p.prob E-p.prob (fun ω => ¬ F ω) ≤ p.prob (fun ω => E ω ∧ F ω) := by + rw [prob,prob,prob,← Finset.sum_sub_distrib] + apply Finset.sum_le_sum + intro ω _ + by_cases he : E ω <;> by_cases hf : F ω <;> simp [he,hf,p.nonneg ω] + +lemma prob_exists_le_sum {ι : Type uIota} [Fintype ι] (p : FinLaw Ω) (E : ι → Ω → Prop) : + p.prob (fun ω => ∃ i, E i ω) ≤ ∑ i, p.prob (E i) := by + simp only [prob] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro ω _ + by_cases hh : ∃ i, E i ω + · obtain ⟨i,hi⟩ := hh + rw [ite_eq_left ⟨i,hi⟩] + have h := Finset.single_le_sum (s := Finset.univ) + (f := fun i => if E i ω then p ω else 0) + (fun j _ => by split_ifs <;> simp [p.nonneg ω]) (Finset.mem_univ i) + simpa only [ite_eq_left hi] using h + · simp only [ite_eq_right hh] + exact Finset.sum_nonneg (fun i _ => by split_ifs <;> simp [p.nonneg ω]) + +end + +open scoped BigOperators Classical +variable {Ω : Type uOmega} {Κ : Type uCapitalKappa} {ι : Type uIota} {α : Type uAlpha} {β : Type uBeta} [Fintype Ω] [Fintype Κ] [Fintype ι] + +lemma map_equiv_mass (p : FinLaw Ω) (e : Ω ≃ Κ) (x : Κ) : + p.map e x = p (e.symm x) := by + rw [map_mass,Finset.sum_eq_single (e.symm x)] + · simp + · intro ω _ hn + have hh : e ω ≠ x := by intro h; exact hn (e.injective (by simpa using h)) + simp [hh] + · simp + +lemma entropy_map_equiv (p : FinLaw Ω) (e : Ω ≃ Κ) : + (p.map e).entropy = p.entropy := by + simp only [entropy,entropySum,map_equiv_mass] + exact e.symm.sum_comp (fun ω => Real.negMulLog (p ω)) + +lemma iid_succ (p : FinLaw Ω) (n : ℕ) : + p.iid (n+1) = (p.joint (fun _ => p.iid n)).map + (Fin.consEquiv (fun _ : Fin (n+1) => Ω)) := by + ext x + rw [map_equiv_mass] + change (∏ i : Fin (n+1), p (x i)) = p (x 0)*(∏ i : Fin n, p (x i.succ)) + exact Fin.prod_univ_succ _ + +lemma entropy_iid (p : FinLaw Ω) (n : ℕ) : + (p.iid n).entropy = n*p.entropy := by + induction n with + | zero => + have he : p.iid 0 = uniform (Fin 0 → Ω) := by ext x; simp [uniform_mass] + rw [he] + simp [entropy,entropySum,uniform_mass] + | succ n ih => + rw [iid_succ,entropy_map_equiv,entropy_joint] + simp only [ih,← Finset.sum_mul,p.sum_one,one_mul,Nat.cast_add,Nat.cast_one] + ring + +lemma iid_split (p : FinLaw Ω) (n : ℕ) (i : Fin n) : + p.iid n = (p.joint (fun _ => + ({ mass := fun x : (j : {j : Fin n // j ≠ i}) → Ω => ∏ j, p (x j) + nonneg := fun x => Finset.prod_nonneg (fun j _ => p.nonneg _) + sum_one := by rw [← Fintype.prod_sum]; simp only [p.sum_one,Finset.prod_const_one] } : + FinLaw ((j : {j : Fin n // j ≠ i}) → Ω)))).map + (Equiv.piSplitAt i (fun _ : Fin n => Ω)).symm := by + ext x + rw [map_equiv_mass] + change (∏ j : Fin n, p (x j)) = p (x i)*(∏ j : {j : Fin n // j ≠ i}, p (x j)) + rw [← Fintype.prod_subtype_mul_prod_subtype (p := fun j : Fin n => j=i)] + have he : (∏ j : {j : Fin n // j=i}, p (x j)) = p (x i) := by + have hsub := Finset.prod_subtype (F := inferInstance) (p := fun j : Fin n => j=i) ({i} : Finset (Fin n)) (by simp) (fun j => p (x j)) + simpa using hsub.symm + convert! congrArg (fun v => v*(∏ j : {j : Fin n // j ≠ i}, p (x j))) he using 1 + congr 1 + congr 1 + ext j + simp only [Finset.mem_univ] + +lemma iid_map_eval (p : FinLaw Ω) (n : ℕ) (i : Fin n) : + (p.iid n).map (fun x => x i) = p := by + rw [iid_split p n i,map_comp] + have he : ((fun x : Fin n → Ω => x i) ∘ (Equiv.piSplitAt i (fun _ : Fin n => Ω)).symm) = Prod.fst := by + funext x + simp [Equiv.piSplitAt] + rw [he,joint_map_fst] + +end FinLaw +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/WalkGeometry.lean b/lean/OAI/NumberTheory/GaussianMoat/WalkGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..b1df34ba15f15d426b257a076248774703d2c27c --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/WalkGeometry.lean @@ -0,0 +1,589 @@ +import OAI.NumberTheory.GaussianMoat.FiniteLaw + +namespace OAI + +namespace GaussianMoat + +section +open scoped BigOperators + +def colorEdge (a b : Fin 3) : ℤ := + if a = 0 ∧ b = 1 then 1 else if a = 1 ∧ b = 0 then -1 else 0 + +def Tricolored (a b c : Fin 3) : Prop := a ≠ b ∧ b ≠ c ∧ a ≠ c + +theorem colorEdge_add {a b c : Fin 3} (h : ¬ Tricolored a b c) : + colorEdge a b + colorEdge b c = colorEdge a c := by + unfold Tricolored at h + revert a b c + decide + +theorem colorEdge_zero_left (a b : Fin 3) (ha : a ≠ 0) (hb : b ≠ 0) : + colorEdge a b = 0 := by simp [colorEdge,ha,hb] + +theorem colorEdge_zero_one (a b : Fin 3) (ha : a ≠ 1) (hb : b ≠ 1) : + colorEdge a b = 0 := by simp [colorEdge,ha,hb] + +theorem colorEdge_binary (a b : Fin 3) (ha : a ≠ 2) (hb : b ≠ 2) : + colorEdge a b = (b.val : ℤ) - a.val := by + revert a b + decide + +theorem discrete_rectangle_sperner (c : ℕ → ℕ → Fin 3) (m n : ℕ) + (hbottom : ∀ i ≤ m, c i 0 = 0) + (htop : ∀ i ≤ m, c i n ≠ 0) + (hleft : ∀ j ≤ n, c 0 j ≠ 2) + (hright : ∀ j ≤ n, c m j ≠ 1) : + ∃ i < m, ∃ j < n, + Tricolored (c i j) (c (i+1) j) (c (i+1) (j+1)) ∨ + Tricolored (c i j) (c i (j+1)) (c (i+1) (j+1)) := by + by_contra h + have hcell (i j : ℕ) (hi : i < m) (hj : j < n) : + colorEdge (c i j) (c (i+1) j) - colorEdge (c i (j+1)) (c (i+1) (j+1)) = + colorEdge (c i j) (c i (j+1)) - colorEdge (c (i+1) j) (c (i+1) (j+1)) := by + have h1 : ¬ Tricolored (c i j) (c (i+1) j) (c (i+1) (j+1)) := + fun hh => h ⟨i,hi,j,hj,Or.inl hh⟩ + have h2 : ¬ Tricolored (c i j) (c i (j+1)) (c (i+1) (j+1)) := + fun hh => h ⟨i,hi,j,hj,Or.inr hh⟩ + have he1 := colorEdge_add h1 + have he2 := colorEdge_add h2 + omega + have hsum := Finset.sum_congr (s₁ := Finset.range n) rfl (fun j hj => + Finset.sum_congr (s₁ := Finset.range m) rfl (fun i hi => + hcell i j (Finset.mem_range.mp hi) (Finset.mem_range.mp hj))) + have hl : (∑ j ∈ Finset.range n, ∑ i ∈ Finset.range m, + (colorEdge (c i j) (c (i+1) j) - colorEdge (c i (j+1)) (c (i+1) (j+1)))) = 0 := by + rw [Finset.sum_comm] + apply Finset.sum_eq_zero + intro i hi + rw [Finset.sum_range_sub'] + rw [hbottom i (Nat.le_of_lt (Finset.mem_range.mp hi)), + hbottom (i+1) (Finset.mem_range.mp hi)] + rw [colorEdge_zero_left _ _ (htop i (Nat.le_of_lt (Finset.mem_range.mp hi))) + (htop (i+1) (Finset.mem_range.mp hi))] + rfl + have hr : (∑ j ∈ Finset.range n, ∑ i ∈ Finset.range m, + (colorEdge (c i j) (c i (j+1)) - colorEdge (c (i+1) j) (c (i+1) (j+1)))) = 1 := by + have he (j : ℕ) (hj : j ∈ Finset.range n) : + (∑ i ∈ Finset.range m, (colorEdge (c i j) (c i (j+1)) - + colorEdge (c (i+1) j) (c (i+1) (j+1)))) = ((c 0 (j+1)).val : ℤ) - (c 0 j).val := by + rw [Finset.sum_range_sub'] + rw [colorEdge_zero_one _ _ (hright j (Nat.le_of_lt (Finset.mem_range.mp hj))) + (hright (j+1) (Finset.mem_range.mp hj)),sub_zero, + colorEdge_binary _ _ (hleft j (Nat.le_of_lt (Finset.mem_range.mp hj))) + (hleft (j+1) (Finset.mem_range.mp hj))] + rw [Finset.sum_congr rfl he,Finset.sum_range_sub (fun j => ((c 0 j).val : ℤ))] + have hend : c 0 n = 1 := by + have h0 := htop 0 (Nat.zero_le m) + have h2 := hleft n le_rfl + have hone : ∀ x : Fin 3, x ≠ 0 → x ≠ 2 → x = 1 := by decide + exact hone _ h0 h2 + rw [hend,hbottom 0 (Nat.zero_le m)] + norm_num + rw [hl,hr] at hsum + omega + +noncomputable def pointColor (z : ℂ) : Fin 3 := if z.im < 0 then 0 else if z.re < 0 then 1 else 2 + +theorem pointColor_zero {z : ℂ} (h : pointColor z = 0) : z.im < 0 := by + unfold pointColor at h + split_ifs at h with hi hr + · exact hi + · exact False.elim ((by decide : (1 : Fin 3) ≠ 0) h) + · exact False.elim ((by decide : (2 : Fin 3) ≠ 0) h) + +theorem pointColor_one {z : ℂ} (h : pointColor z = 1) : z.re < 0 ∧ 0 ≤ z.im := by + unfold pointColor at h + split_ifs at h with hi hr + · exact False.elim ((by decide : (0 : Fin 3) ≠ 1) h) + · exact ⟨hr,le_of_not_gt hi⟩ + · exact False.elim ((by decide : (2 : Fin 3) ≠ 1) h) + +theorem pointColor_two {z : ℂ} (h : pointColor z = 2) : 0 ≤ z.re ∧ 0 ≤ z.im := by + unfold pointColor at h + split_ifs at h with hi hr + · exact False.elim ((by decide : (0 : Fin 3) ≠ 2) h) + · exact False.elim ((by decide : (1 : Fin 3) ≠ 2) h) + · exact ⟨le_of_not_gt hr,le_of_not_gt hi⟩ + +theorem tricolored_covers {a b c : Fin 3} (h : Tricolored a b c) (q : Fin 3) : + q = a ∨ q = b ∨ q = c := by + unfold Tricolored at h + revert a b c q + decide + +theorem tricolored_norm_bound {x y z : ℂ} {r : ℝ} (hr : 0 ≤ r) + (hxy : dist x y ≤ r) (hxz : dist x z ≤ r) + (hc : Tricolored (pointColor x) (pointColor y) (pointColor z)) : ‖x‖ ≤ 2*r := by + have he (q : Fin 3) : ∃ w : ℂ, pointColor w = q ∧ dist x w ≤ r := by + rcases tricolored_covers hc q with h | h | h + · exact ⟨x,h.symm,by simpa using hr⟩ + · exact ⟨y,h.symm,hxy⟩ + · exact ⟨z,h.symm,hxz⟩ + obtain ⟨w0,h0,hd0⟩ := he 0 + obtain ⟨w1,h1,hd1⟩ := he 1 + obtain ⟨w2,h2,hd2⟩ := he 2 + have hc0 := pointColor_zero h0 + have hc1 := pointColor_one h1 + have hc2 := pointColor_two h2 + have hRe (w : ℂ) (hd : dist x w ≤ r) : -r ≤ x.re-w.re ∧ x.re-w.re ≤ r := by + apply abs_le.mp + have hh : |x.re-w.re| ≤ dist x w := by simpa only [Complex.sub_re,dist_eq_norm] using Complex.abs_re_le_norm (x-w) + exact hh.trans hd + have hIm (w : ℂ) (hd : dist x w ≤ r) : -r ≤ x.im-w.im ∧ x.im-w.im ≤ r := by + apply abs_le.mp + have hh : |x.im-w.im| ≤ dist x w := by simpa only [Complex.sub_im,dist_eq_norm] using Complex.abs_im_le_norm (x-w) + exact hh.trans hd + have hR1 := hRe w1 hd1 + have hR2 := hRe w2 hd2 + have hI0 := hIm w0 hd0 + have hI1 := hIm w1 hd1 + have hrx : |x.re| ≤ r := abs_le.mpr ⟨by linarith,by linarith⟩ + have hix : |x.im| ≤ r := abs_le.mpr ⟨by linarith,by linarith⟩ + have h := Complex.norm_le_abs_re_add_abs_im x + linarith + +theorem discrete_rectangle_approx_zero (f : ℕ → ℕ → ℂ) (m n : ℕ) {D : ℝ} (hD : 0 ≤ D) + (hhor : ∀ i < m, ∀ j ≤ n, dist (f i j) (f (i+1) j) ≤ D) + (hver : ∀ i ≤ m, ∀ j < n, dist (f i j) (f i (j+1)) ≤ D) + (hbottom : ∀ i ≤ m, (f i 0).im < 0) + (htop : ∀ i ≤ m, 0 ≤ (f i n).im) + (hleft : ∀ j ≤ n, (f 0 j).re < 0) + (hright : ∀ j ≤ n, 0 ≤ (f m j).re) : + ∃ i ≤ m, ∃ j ≤ n, ‖f i j‖ ≤ 4*D := by + have hb : ∀ i ≤ m, pointColor (f i 0) = 0 := by + intro i hi + simp [pointColor,hbottom i hi] + have ht : ∀ i ≤ m, pointColor (f i n) ≠ 0 := by + intro i hi hh + exact (not_lt_of_ge (htop i hi)) (pointColor_zero hh) + have hl : ∀ j ≤ n, pointColor (f 0 j) ≠ 2 := by + intro j hj hh + exact (not_le_of_gt (hleft j hj)) (pointColor_two hh).1 + have hr : ∀ j ≤ n, pointColor (f m j) ≠ 1 := by + intro j hj hh + exact (not_lt_of_ge (hright j hj)) (pointColor_one hh).1 + obtain ⟨i,hi,j,hj,hc⟩ := discrete_rectangle_sperner (fun i j => pointColor (f i j)) m n hb ht hl hr + refine ⟨i,hi.le,j,hj.le,?_⟩ + have hdiag : dist (f i j) (f (i+1) (j+1)) ≤ 2*D := by + have h := dist_triangle (f i j) (f (i+1) j) (f (i+1) (j+1)) + have h1 := hhor i hi j hj.le + have h2 := hver (i+1) hi j hj + linarith + rcases hc with hc | hc + · have hh := tricolored_norm_bound (show 0 ≤ 2*D by positivity) + ((hhor i hi j hj.le).trans (by linarith : D ≤ 2*D)) hdiag hc + linarith + · have hh := tricolored_norm_bound (show 0 ≤ 2*D by positivity) + ((hver i hi.le j hj).trans (by linarith : D ≤ 2*D)) hdiag hc + linarith + +noncomputable def repeatPath (v : ℕ → ℂ) (n : ℕ) (a : ℂ) (t : ℕ) : ℂ := + v (t % n) + ((t / n : ℕ) : ℂ) * a + +@[simp] theorem repeatPath_zero (v : ℕ → ℂ) (n : ℕ) (a : ℂ) : + repeatPath v n a 0 = v 0 := by simp [repeatPath] + +@[simp] theorem repeatPath_multiple (v : ℕ → ℂ) {n : ℕ} (hn : 0 < n) (a : ℂ) (k : ℕ) : + repeatPath v n a (k*n) = v 0 + (k : ℂ)*a := by simp [repeatPath,hn.ne'] + +theorem repeatPath_step (v : ℕ → ℂ) {n : ℕ} (hn : 0 < n) (a : ℂ) + (hv0 : v 0 = 0) (hvn : v n = a) {D : ℝ} + (hstep : ∀ i < n, dist (v i) (v (i+1)) ≤ D) (t : ℕ) : + dist (repeatPath v n a t) (repeatPath v n a (t+1)) ≤ D := by + have hr := Nat.mod_lt t hn + have hdiv := Nat.mod_add_div t n + by_cases hh : t % n + 1 = n + · have ht : t+1 = (t/n+1)*n := by nlinarith + rw [ht,repeatPath_multiple v hn] + have he : repeatPath v n a t = v (t%n) + ((t/n:ℕ):ℂ)*a := rfl + rw [he,hv0,zero_add,Nat.cast_add,Nat.cast_one,add_mul,one_mul,add_comm (((t/n:ℕ):ℂ)*a) a] + rw [dist_add_right] + simpa [hh,hvn] using hstep (t%n) hr + · have hr' : t%n+1 < n := by omega + have ht : t+1 = t%n+1+(t/n)*n := by nlinarith + have hmod : (t+1)%n = t%n+1 := by rw [ht,Nat.add_mul_mod_self_right,Nat.mod_eq_of_lt hr'] + have hquo : (t+1)/n = t/n := by rw [ht,Nat.add_mul_div_right _ _ hn,Nat.div_eq_of_lt hr',zero_add] + simp only [repeatPath,hmod,hquo,dist_add_right] + exact hstep (t%n) hr + +theorem discrete_rectangle_approx_zero_rev (f : ℕ → ℕ → ℂ) (m n : ℕ) {D : ℝ} (hD : 0 ≤ D) + (hhor : ∀ i < m, ∀ j ≤ n, dist (f i j) (f (i+1) j) ≤ D) + (hver : ∀ i ≤ m, ∀ j < n, dist (f i j) (f i (j+1)) ≤ D) + (hbottom : ∀ i ≤ m, 0 < (f i 0).im) + (htop : ∀ i ≤ m, (f i n).im ≤ 0) + (hleft : ∀ j ≤ n, (f 0 j).re < 0) + (hright : ∀ j ≤ n, 0 ≤ (f m j).re) : + ∃ i ≤ m, ∃ j ≤ n, ‖f i j‖ ≤ 4*D := by + have hh : ∀ i < m, ∀ j ≤ n, dist (star (f i j)) (star (f (i+1) j)) ≤ D := by + intro i hi j hj + simpa only [dist_star_star] using hhor i hi j hj + have hv : ∀ i ≤ m, ∀ j < n, dist (star (f i j)) (star (f i (j+1))) ≤ D := by + intro i hi j hj + simpa only [dist_star_star] using hver i hi j hj + have hb : ∀ i ≤ m, (star (f i 0)).im < 0 := by + intro i hi + simpa only [Complex.star_def,Complex.conj_im,neg_lt_zero] using hbottom i hi + have ht : ∀ i ≤ m, 0 ≤ (star (f i n)).im := by + intro i hi + simpa only [Complex.star_def,Complex.conj_im,neg_nonneg] using htop i hi + obtain ⟨i,hi,j,hj,hz⟩ := discrete_rectangle_approx_zero (fun i j => star (f i j)) m n + hD hh hv hb ht (by simpa only [Complex.star_def,Complex.conj_re] using hleft) + (by simpa only [Complex.star_def,Complex.conj_re] using hright) + exact ⟨i,hi,j,hj,by simpa only [norm_star] using hz⟩ + +theorem path_difference_cover (v u : ℕ → ℂ) {n m : ℕ} (hn : 0 < n) (hm : 0 < m) + (a b : ℂ) (hv0 : v 0 = 0) (hu0 : u 0 = 0) (hvn : v n = a) (hum : u m = b) + (ha : 0 < a.re) (hai : a.im = 0) (hb : 0 < b.im) {D : ℝ} (hD : 0 ≤ D) + (hv : ∀ i < n, dist (v i) (v (i+1)) ≤ D) + (hu : ∀ j < m, dist (u j) (u (j+1)) ≤ D) (w : ℂ) : + ∃ i < n, ∃ j < m, ∃ s t : ℤ, + ‖v i-u j+(s:ℂ)*a+(t:ℂ)*b-w‖ ≤ 4*D := by + let H : ℝ := (∑ i ∈ Finset.range n, ‖v i‖) + (∑ j ∈ Finset.range m, ‖u j‖) + ‖w‖ + have hH : 0 ≤ H := by dsimp [H]; positivity + have hvb (i : ℕ) : ‖v (i%n)‖ ≤ ∑ k ∈ Finset.range n, ‖v k‖ := + Finset.single_le_sum (fun k _ => norm_nonneg (v k)) (Finset.mem_range.mpr (Nat.mod_lt i hn)) + have hub (j : ℕ) : ‖u (j%m)‖ ≤ ∑ k ∈ Finset.range m, ‖u k‖ := + Finset.single_le_sum (fun k _ => norm_nonneg (u k)) (Finset.mem_range.mpr (Nat.mod_lt j hm)) + have herr (i j : ℕ) : ‖v (i%n)-u (j%m)-w‖ ≤ H := by + have h1 := norm_sub_le (v (i%n)) (u (j%m)) + have h2 := norm_sub_le (v (i%n)-u (j%m)) w + dsimp [H] + linarith [hvb i,hub j] + have hrerr (i j : ℕ) : -H ≤ (v (i%n)-u (j%m)-w).re ∧ + (v (i%n)-u (j%m)-w).re ≤ H := + abs_le.mp ((Complex.abs_re_le_norm _).trans (herr i j)) + have hierr (i j : ℕ) : -H ≤ (v (i%n)-u (j%m)-w).im ∧ + (v (i%n)-u (j%m)-w).im ≤ H := + abs_le.mp ((Complex.abs_im_le_norm _).trans (herr i j)) + obtain ⟨N,hN⟩ := exists_nat_gt (H/b.im) + have hN' : H < (N:ℝ)*b.im := (div_lt_iff₀ hb).mp hN + obtain ⟨M,hM⟩ := exists_nat_gt ((H+(N:ℝ)*|b.re|)/a.re) + have hM' : H+(N:ℝ)*|b.re| < (M:ℝ)*a.re := (div_lt_iff₀ ha).mp hM + let f (i j : ℕ) : ℂ := repeatPath v n a i-repeatPath u m b j-(M:ℂ)*a+(N:ℂ)*b-w + have hf (i j : ℕ) : f i j = v (i%n)-u (j%m)-w + + (((i/n:ℕ):ℂ)-(M:ℂ))*a + ((N:ℂ)-((j/m:ℕ):ℂ))*b := by + dsimp [f,repeatPath] + ring + have hfr (i j : ℕ) : (f i j).re = (v (i%n)-u (j%m)-w).re + + (((i/n:ℕ):ℝ)-(M:ℝ))*a.re + ((N:ℝ)-((j/m:ℕ):ℝ))*b.re := by + rw [hf] + simp + have hfi (i j : ℕ) : (f i j).im = (v (i%n)-u (j%m)-w).im + + ((N:ℝ)-((j/m:ℕ):ℝ))*b.im := by + rw [hf] + simp [hai] + have hhor (i : ℕ) (_ : i < 2*M*n) (j : ℕ) (_ : j ≤ 2*N*m) : + dist (f i j) (f (i+1) j) ≤ D := by + simpa only [f,dist_sub_right,dist_add_right] using repeatPath_step v hn a hv0 hvn hv i + have hver (i : ℕ) (_ : i ≤ 2*M*n) (j : ℕ) (_ : j < 2*N*m) : + dist (f i j) (f i (j+1)) ≤ D := by + simpa only [f,dist_sub_right,dist_add_right,dist_sub_left] using repeatPath_step u hm b hu0 hum hu j + have hbottom (i : ℕ) (_ : i ≤ 2*M*n) : 0 < (f i 0).im := by + rw [hfi] + simpa only [Nat.zero_div,Nat.cast_zero,sub_zero] using (show + 0 < (v (i%n)-u (0%m)-w).im+(N:ℝ)*b.im by linarith [(hierr i 0).1]) + have htop (i : ℕ) (_ : i ≤ 2*M*n) : (f i (2*N*m)).im ≤ 0 := by + rw [hfi,Nat.mul_div_cancel _ hm,Nat.cast_mul,Nat.cast_ofNat] + linarith [(hierr i (2*N*m)).2] + have hcoef (j : ℕ) (hj : j ≤ 2*N*m) : + |(N:ℝ)-((j/m:ℕ):ℝ)| ≤ N := by + have hq : j/m ≤ 2*N := (Nat.div_le_div_right hj).trans_eq (Nat.mul_div_cancel _ hm) + have hqr : ((j/m:ℕ):ℝ) ≤ 2*(N:ℝ) := by exact_mod_cast hq + exact abs_le.mpr ⟨by linarith,by linarith [Nat.cast_nonneg (α := ℝ) (j/m)]⟩ + have hprod (j : ℕ) (hj : j ≤ 2*N*m) : + -(N:ℝ)*|b.re| ≤ ((N:ℝ)-((j/m:ℕ):ℝ))*b.re ∧ + ((N:ℝ)-((j/m:ℕ):ℝ))*b.re ≤ (N:ℝ)*|b.re| := by + have hh : |((N:ℝ)-((j/m:ℕ):ℝ))*b.re| ≤ (N:ℝ)*|b.re| := by + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (hcoef j hj) (abs_nonneg _) + simpa only [neg_mul] using abs_le.mp hh + have hleft (j : ℕ) (hj : j ≤ 2*N*m) : (f 0 j).re < 0 := by + rw [hfr] + simp only [Nat.zero_div,Nat.cast_zero,zero_sub] + nlinarith [(hrerr 0 j).2,(hprod j hj).2] + have hright (j : ℕ) (hj : j ≤ 2*N*m) : 0 ≤ (f (2*M*n) j).re := by + rw [hfr,Nat.mul_div_cancel _ hn,Nat.cast_mul,Nat.cast_ofNat] + nlinarith [(hrerr (2*M*n) j).1,(hprod j hj).1] + obtain ⟨i,_,j,_,hz⟩ := discrete_rectangle_approx_zero_rev f (2*M*n) (2*N*m) + hD hhor hver hbottom htop hleft hright + refine ⟨i%n,Nat.mod_lt i hn,j%m,Nat.mod_lt j hm,((i/n:ℕ):ℤ)-(M:ℤ),(N:ℤ)-((j/m:ℕ):ℤ),?_⟩ + convert hz using 1 + rw [hf] + simp only [Int.cast_sub,Int.cast_natCast] + congr 1 + ring + +theorem path_difference_cover_horizontal (v u : ℕ → ℂ) {n m : ℕ} (hn : 0 < n) (hm : 0 < m) + (a b : ℂ) (hv0 : v 0 = 0) (hu0 : u 0 = 0) (hvn : v n = a) (hum : u m = b) + (ha : 0 < a.re) (hai : a.im = 0) (hb : b.im ≠ 0) {D : ℝ} (hD : 0 ≤ D) + (hv : ∀ i < n, dist (v i) (v (i+1)) ≤ D) + (hu : ∀ j < m, dist (u j) (u (j+1)) ≤ D) (w : ℂ) : + ∃ i < n, ∃ j < m, ∃ s t : ℤ, + ‖v i-u j+(s:ℂ)*a+(t:ℂ)*b-w‖ ≤ 4*D := by + rcases hb.lt_or_gt with hb | hb + · have hzv : (fun i => star (v i)) 0 = 0 := by simp [hv0] + have hzu : (fun i => star (u i)) 0 = 0 := by simp [hu0] + have hva : (fun i => star (v i)) n = star a := by simp only [hvn] + have hub : (fun i => star (u i)) m = star b := by simp only [hum] + have hbr : 0 < (star b).im := by simpa using hb + have hv' : ∀ i < n, dist (star (v i)) (star (v (i+1))) ≤ D := by simpa using hv + have hu' : ∀ j < m, dist (star (u j)) (star (u (j+1))) ≤ D := by simpa using hu + obtain ⟨i,hi,j,hj,s,t,hh⟩ := path_difference_cover (fun i => star (v i)) + (fun j => star (u j)) hn hm (star a) (star b) hzv hzu hva hub + (by simpa using ha) (by simpa using hai) hbr hD hv' hu' (star w) + refine ⟨i,hi,j,hj,s,t,?_⟩ + have he : ‖star (v i-u j+(s:ℂ)*a+(t:ℂ)*b-w)‖ ≤ 4*D := by + simpa only [star_sub,star_add,star_mul,star_intCast,mul_comm] using hh + simpa only [norm_star] using he + · exact path_difference_cover v u hn hm a b hv0 hu0 hvn hum ha hai hb hD hv hu w + +theorem path_difference_cover_general (v u : ℕ → ℂ) {n m : ℕ} (hn : 0 < n) (hm : 0 < m) + (a b : ℂ) (hv0 : v 0 = 0) (hu0 : u 0 = 0) (hvn : v n = a) (hum : u m = b) + (ha : a ≠ 0) (hb : (b/a).im ≠ 0) {D : ℝ} (hD : 0 ≤ D) + (hv : ∀ i < n, dist (v i) (v (i+1)) ≤ D) + (hu : ∀ j < m, dist (u j) (u (j+1)) ≤ D) (w : ℂ) : + ∃ i < n, ∃ j < m, ∃ s t : ℤ, + ‖v i-u j+(s:ℂ)*a+(t:ℂ)*b-w‖ ≤ 4*D := by + have hna : 0 < ‖a‖ := norm_pos_iff.mpr ha + have hv' : ∀ i < n, dist (v i/a) (v (i+1)/a) ≤ D/‖a‖ := by + intro i hi + simp only [dist_eq_norm,← sub_div,norm_div] + exact div_le_div_of_nonneg_right (by simpa only [dist_eq_norm] using hv i hi) hna.le + have hu' : ∀ j < m, dist (u j/a) (u (j+1)/a) ≤ D/‖a‖ := by + intro j hj + simp only [dist_eq_norm,← sub_div,norm_div] + exact div_le_div_of_nonneg_right (by simpa only [dist_eq_norm] using hu j hj) hna.le + obtain ⟨i,hi,j,hj,s,t,hh⟩ := path_difference_cover_horizontal (fun i => v i/a) + (fun j => u j/a) hn hm 1 (b/a) (by simp [hv0]) (by simp [hu0]) + (by simp [hvn,ha]) (by simp [hum]) (by norm_num) (by simp) hb + (by positivity : 0 ≤ D/‖a‖) hv' hu' (w/a) + refine ⟨i,hi,j,hj,s,t,?_⟩ + have he : v i/a-u j/a+(s:ℂ)*1+(t:ℂ)*(b/a)-w/a = + (v i-u j+(s:ℂ)*a+(t:ℂ)*b-w)/a := by field_simp + rw [he,norm_div] at hh + have hh' := (div_le_iff₀ hna).mp hh + calc + _ ≤ 4 * (D/‖a‖) * ‖a‖ := hh' + _ = 4*D := by field_simp + +end + +def latticeCoords : GaussianInt ≃ₗ[ℤ] (Fin 2 → ℤ) where + toFun z := ![z.re,z.im] + invFun v := ⟨v 0,v 1⟩ + left_inv z := by ext <;> rfl + right_inv v := by ext i; fin_cases i <;> rfl + map_add' z w := by ext i; fin_cases i <;> rfl + map_smul' c z := by + ext i + fin_cases i <;> simp [zsmul_eq_mul] + +noncomputable def latticeBasis : Module.Basis (Fin 2) ℤ GaussianInt := + (Pi.basisFun ℤ (Fin 2)).map latticeCoords.symm + +noncomputable instance : Module.Free ℤ GaussianInt := Module.Free.of_basis latticeBasis +instance : Module.Finite ℤ GaussianInt := Module.Finite.of_basis latticeBasis + +noncomputable def twoVectorMap (a b : GaussianInt) : GaussianInt →ₗ[ℤ] GaussianInt := + Matrix.toLin latticeBasis latticeBasis !![a.re,b.re; a.im,b.im] + +@[simp] theorem twoVectorMap_apply (a b z : GaussianInt) : + twoVectorMap a b z = z.re • a + z.im • b := by + apply latticeCoords.injective + change latticeBasis.repr (twoVectorMap a b z) = latticeCoords (z.re • a+z.im • b) + rw [twoVectorMap,Matrix.toLin_apply] + simp only [map_sum,map_smul,Module.Basis.repr_self] + ext i + fin_cases i <;> simp [latticeCoords,latticeBasis,zsmul_eq_mul,Fin.sum_univ_two,Pi.basisFun_repr,Matrix.vecHead,Matrix.vecTail] <;> ring + +@[simp] theorem twoVectorMap_det (a b : GaussianInt) : + LinearMap.det (twoVectorMap a b) = a.re*b.im-a.im*b.re := by + rw [← LinearMap.det_toMatrix latticeBasis,twoVectorMap,LinearMap.toMatrix_toLin] + simp [Matrix.det_fin_two,mul_comm] + +theorem twoVectorMap_injective {a b : GaussianInt} (h : a.re*b.im-a.im*b.re ≠ 0) : + Function.Injective (twoVectorMap a b) := by + intro z w hzw + have h1 := congrArg Zsqrtd.re hzw + have h2 := congrArg Zsqrtd.im hzw + simp only [twoVectorMap_apply,zsmul_eq_mul,Zsqrtd.re_add,Zsqrtd.im_add, + Zsqrtd.re_smul,Zsqrtd.im_smul] at h1 h2 + have hr : (a.re*b.im-a.im*b.re)*(z.re-w.re) = 0 := by linear_combination b.im*h1-b.re*h2 + have hi : (a.re*b.im-a.im*b.re)*(z.im-w.im) = 0 := by linear_combination a.re*h2-a.im*h1 + ext + · exact sub_eq_zero.mp ((mul_eq_zero.mp hr).resolve_left h) + · exact sub_eq_zero.mp ((mul_eq_zero.mp hi).resolve_left h) + +theorem twoVectorMap_quotient_card {a b : GaussianInt} (h : a.re*b.im-a.im*b.re ≠ 0) : + Nat.card (GaussianInt ⧸ (twoVectorMap a b).range) = (a.re*b.im-a.im*b.re).natAbs := by + have hh := Submodule.natAbs_det_equiv (twoVectorMap a b).range + (LinearEquiv.ofInjective (twoVectorMap a b) (twoVectorMap_injective h)) + have he : (twoVectorMap a b).range.subtype ∘ₗ + AddMonoidHom.toIntLinearMap ((LinearEquiv.ofInjective (twoVectorMap a b) + (twoVectorMap_injective h)) : GaussianInt →+ (twoVectorMap a b).range) = twoVectorMap a b := by + ext z <;> rfl + rw [he,twoVectorMap_det] at hh + exact hh.symm + +noncomputable def latticeBall (D : ℝ) : Finset GaussianInt := + (finite_dist_le 0 D).toFinset + +@[simp] theorem mem_latticeBall (D : ℝ) (z : GaussianInt) : + z ∈ latticeBall D ↔ ‖(z:ℂ)‖ ≤ D := by simp [latticeBall] + +theorem complex_div_im_ne_zero {a b : GaussianInt} (h : a.re*b.im-a.im*b.re ≠ 0) : + ((b:ℂ)/(a:ℂ)).im ≠ 0 := by + have ha : a ≠ 0 := by intro hh; simp [hh] at h + have hac : (a:ℂ) ≠ 0 := by simpa using ha + have hn : Complex.normSq (a:ℂ) ≠ 0 := (Complex.normSq_pos.mpr hac).ne' + rw [Complex.div_im,← sub_div] + intro hh + have hh' := (div_eq_zero_iff.mp hh).resolve_right hn + have hz : (a.re:ℝ)*(b.im:ℝ)-(a.im:ℝ)*(b.re:ℝ) = 0 := by + simpa only [← GaussianInt.intCast_re,← GaussianInt.intCast_im,mul_comm] using hh' + apply h + exact_mod_cast hz + +theorem lattice_path_difference_cover (v u : ℕ → GaussianInt) {n m : ℕ} + (hn : 0 < n) (hm : 0 < m) (a b : GaussianInt) + (hv0 : v 0 = 0) (hu0 : u 0 = 0) (hvn : v n = a) (hum : u m = b) + (hab : a.re*b.im-a.im*b.re ≠ 0) {D : ℝ} (hD : 0 ≤ D) + (hv : ∀ i < n, dist (v i:ℂ) (v (i+1):ℂ) ≤ D) + (hu : ∀ j < m, dist (u j:ℂ) (u (j+1):ℂ) ≤ D) (w : GaussianInt) : + ∃ i < n, ∃ j < m, ∃ s t : ℤ, + ‖((v i-u j+(s:GaussianInt)*a+(t:GaussianInt)*b-w:GaussianInt):ℂ)‖ ≤ 4*D := by + have ha : a ≠ 0 := by intro hh; simp [hh] at hab + obtain ⟨i,hi,j,hj,s,t,hh⟩ := path_difference_cover_general + (fun i => (v i:ℂ)) (fun j => (u j:ℂ)) hn hm (a:ℂ) (b:ℂ) + (by simp [hv0]) (by simp [hu0]) (by simp [hvn]) (by simp [hum]) + (by simpa using ha) (complex_div_im_ne_zero hab) hD hv hu (w:ℂ) + exact ⟨i,hi,j,hj,s,t,by simpa using hh⟩ + +theorem lattice_path_difference_card (v u : ℕ → GaussianInt) {n m : ℕ} + (hn : 0 < n) (hm : 0 < m) (a b : GaussianInt) + (hv0 : v 0 = 0) (hu0 : u 0 = 0) (hvn : v n = a) (hum : u m = b) + (hab : a.re*b.im-a.im*b.re ≠ 0) {D : ℝ} (hD : 0 ≤ D) + (hv : ∀ i < n, dist (v i:ℂ) (v (i+1):ℂ) ≤ D) + (hu : ∀ j < m, dist (u j:ℂ) (u (j+1):ℂ) ≤ D) + (E : Finset GaussianInt) (hE : ∀ i < n, ∀ j < m, v i-u j ∈ E) : + (a.re*b.im-a.im*b.re).natAbs ≤ E.card*(latticeBall (4*D)).card := by + classical + let Q := (twoVectorMap a b).range + have hcard : Nat.card (GaussianInt ⧸ Q) = (a.re*b.im-a.im*b.re).natAbs := + twoVectorMap_quotient_card hab + have : Finite (GaussianInt ⧸ Q) := Nat.finite_of_card_ne_zero (by rw [hcard]; simpa using hab) + let : Fintype (GaussianInt ⧸ Q) := Fintype.ofFinite _ + let F : E × (latticeBall (4*D)) → GaussianInt ⧸ Q := + fun x => Q.mkQ (x.1.val+x.2.val) + have hf : Function.Surjective F := by + intro q + obtain ⟨w,rfl⟩ := Q.mkQ_surjective q + obtain ⟨i,hi,j,hj,s,t,hh⟩ := lattice_path_difference_cover v u hn hm a b hv0 hu0 hvn hum hab hD hv hu w + let r : GaussianInt := -(v i-u j+(s:GaussianInt)*a+(t:GaussianInt)*b-w) + have hr : r ∈ latticeBall (4*D) := by + rw [mem_latticeBall] + dsimp only [r] + rw [map_neg,norm_neg] + exact hh + refine ⟨(⟨v i-u j,hE i hi j hj⟩,⟨r,hr⟩),?_⟩ + apply (Submodule.Quotient.eq Q).mpr + change (v i-u j)+r-w ∈ (twoVectorMap a b).range + refine ⟨⟨-s,-t⟩,?_⟩ + rw [twoVectorMap_apply] + change (-s) • a + (-t) • b = _ + simp only [zsmul_eq_mul,Int.cast_neg] + dsimp [r] + ring + have hh := Fintype.card_le_of_surjective F hf + have hQ : Fintype.card (GaussianInt ⧸ Q) = (a.re*b.im-a.im*b.re).natAbs := by + rw [← Nat.card_eq_fintype_card,hcard] + simpa only [Fintype.card_prod,Fintype.card_coe,hQ] using hh + +theorem lattice_norm_ge_one {z : GaussianInt} (hz : z ≠ 0) : 1 ≤ ‖(z:ℂ)‖ := by + have hi : 1 ≤ z.norm := by have := GaussianInt.norm_pos.mpr hz; omega + have hr : (1:ℝ) ≤ (z.norm:ℝ) := by exact_mod_cast hi + rw [GaussianInt.intCast_real_norm,Complex.normSq_eq_norm_sq] at hr + nlinarith [norm_nonneg (z:ℂ)] + +theorem lattice_dist_ge_one {z w : GaussianInt} (h : z ≠ w) : + 1 ≤ dist (z:ℂ) (w:ℂ) := by + simpa only [map_sub,dist_eq_norm] using lattice_norm_ge_one (sub_ne_zero.mpr h) + +noncomputable def latticePixel (e c : ℂ) (z : GaussianInt) : ℤ × ℤ := + (⌊2*(e*((z:ℂ)-c)).re⌋,⌊2*(e*((z:ℂ)-c)).im⌋) + +theorem abs_sub_lt_half_of_pixel_eq {x y : ℝ} (h : ⌊2*x⌋ = ⌊2*y⌋) : |x-y| < 1/2 := by + have h1 := Int.floor_le (2*x) + have h2 := Int.lt_floor_add_one (2*x) + have h3 := Int.floor_le (2*y) + have h4 := Int.lt_floor_add_one (2*y) + rw [h] at h1 h2 + exact abs_lt.mpr ⟨by linarith,by linarith⟩ + +theorem latticePixel_injective {e : ℂ} (he : ‖e‖ = 1) (c : ℂ) : + Function.Injective (latticePixel e c) := by + intro z w h + have hr := abs_sub_lt_half_of_pixel_eq (congrArg Prod.fst h) + have hi := abs_sub_lt_half_of_pixel_eq (congrArg Prod.snd h) + have hn : ‖e*((z:ℂ)-c)-e*((w:ℂ)-c)‖ < 1 := by + have hh := Complex.norm_le_abs_re_add_abs_im (e*((z:ℂ)-c)-e*((w:ℂ)-c)) + simp only [Complex.sub_re,Complex.sub_im] at hh + change |(e*((z:ℂ)-c)).re-(e*((w:ℂ)-c)).re| < 1/2 at hr + change |(e*((z:ℂ)-c)).im-(e*((w:ℂ)-c)).im| < 1/2 at hi + linarith + have heq : e*((z:ℂ)-c)-e*((w:ℂ)-c) = e*((z:ℂ)-(w:ℂ)) := by ring + rw [heq,norm_mul,he,one_mul] at hn + by_contra hne + exact (not_lt_of_ge (lattice_dist_ge_one hne)) (by simpa only [dist_eq_norm] using hn) + +theorem lattice_rectangle_card (E : Finset GaussianInt) {e c : ℂ} (he : ‖e‖ = 1) + {R W : ℝ} (hR : 1 ≤ R) (hW : 1 ≤ W) + (hE : ∀ z ∈ E, 0 ≤ (e*((z:ℂ)-c)).re ∧ (e*((z:ℂ)-c)).re ≤ R ∧ + |(e*((z:ℂ)-c)).im| ≤ W) : + (E.card:ℝ) ≤ 18*R*W := by + classical + let B : Finset (ℤ × ℤ) := Finset.Icc 0 ⌊2*R⌋ ×ˢ Finset.Icc ⌊-2*W⌋ ⌊2*W⌋ + have hb : E.image (latticePixel e c) ⊆ B := by + intro x hx + obtain ⟨z,hz,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨hz0,hzR,hzW⟩ := hE z hz + have hzw := abs_le.mp hzW + simp only [B,Finset.mem_product,Finset.mem_Icc,latticePixel] + refine ⟨⟨?_,Int.floor_mono (by linarith)⟩, + ⟨Int.floor_mono (by linarith),Int.floor_mono (by linarith)⟩⟩ + exact Int.floor_nonneg.mpr (by linarith) + have hcard : E.card ≤ B.card := by + rw [← Finset.card_image_iff.mpr (latticePixel_injective he c).injOn] + exact Finset.card_le_card hb + have hR0 : (0:ℤ) ≤ ⌊2*R⌋+1 := by + have hh : (0:ℤ) ≤ ⌊2*R⌋ := Int.floor_nonneg.mpr (by linarith) + omega + have hW0 : ⌊-2*W⌋ ≤ ⌊2*W⌋+1 := by + have hh : ⌊-2*W⌋ ≤ ⌊2*W⌋ := Int.floor_mono (by linarith) + omega + have hcr : ((Finset.Icc (0:ℤ) ⌊2*R⌋).card:ℝ) = (⌊2*R⌋:ℝ)+1 := by + have h := Int.card_Icc_of_le 0 ⌊2*R⌋ hR0 + simp only [sub_zero] at h + exact_mod_cast h + have hcw : ((Finset.Icc ⌊-2*W⌋ ⌊2*W⌋).card:ℝ) = (⌊2*W⌋:ℝ)+1-(⌊-2*W⌋:ℝ) := by + exact_mod_cast Int.card_Icc_of_le ⌊-2*W⌋ ⌊2*W⌋ hW0 + have hrb : ((Finset.Icc (0:ℤ) ⌊2*R⌋).card:ℝ) ≤ 3*R := by + rw [hcr] + linarith [Int.floor_le (2*R)] + have hwb : ((Finset.Icc ⌊-2*W⌋ ⌊2*W⌋).card:ℝ) ≤ 6*W := by + rw [hcw] + linarith [Int.floor_le (2*W),Int.lt_floor_add_one (-2*W)] + have hh : (E.card:ℝ) ≤ ((Finset.Icc (0:ℤ) ⌊2*R⌋).card:ℝ)* + ((Finset.Icc ⌊-2*W⌋ ⌊2*W⌋).card:ℝ) := by + dsimp only [B] at hcard + rw [Finset.card_product] at hcard + exact_mod_cast hcard + calc + (E.card:ℝ) ≤ _ := hh + _ ≤ (3*R)*(6*W) := mul_le_mul hrb hwb (Nat.cast_nonneg _) (by linarith) + _ = 18*R*W := by ring + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/WalkPackage.lean b/lean/OAI/NumberTheory/GaussianMoat/WalkPackage.lean new file mode 100644 index 0000000000000000000000000000000000000000..050d24bbbba5471994ba6b257b4c8320d59ead4d --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/WalkPackage.lean @@ -0,0 +1,365 @@ +import OAI.NumberTheory.GaussianMoat.PassingInformation + +namespace OAI + +universe uOmega uAlpha uOutput uIota uAlphaPrime uBeta uBetaPrime uGamma uGammaPrime uCapitalGamma uCapitalGammaPrime uKappa + +namespace GaussianMoat +open scoped BigOperators Classical + +abbrev WalkPackage (D : ℝ) (B L : ℕ) := latticeBall (D*B) × (Fin L → latticeBall D) + +noncomputable def ForwardKernel.packageSymbol (K : ForwardKernel) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a L : ℕ) (u : Fin (K.bound+1)) : + WalkPackage D K.bound L := + (K.displacementSymbol z hD hs a u,boundedWord z hs L (a+u.val)) + +noncomputable def ForwardKernel.packageLaw (K : ForwardKernel) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a L : ℕ) : + FinLaw (WalkPackage D K.bound L) := + (K.law a).map (K.packageSymbol z hD hs a L) + +noncomputable def WalkPackage.prefix {D : ℝ} {B L : ℕ} + (v : WalkPackage D B L) (l : Fin L) : GaussianInt := + v.1.val+∑ j : Fin l.val, (v.2 ⟨j.val,lt_trans j.isLt l.isLt⟩).val + +lemma ForwardKernel.packageSymbol_prefix (K : ForwardKernel) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 0≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a L : ℕ) (u : Fin (K.bound+1)) (l : Fin L) : + (K.packageSymbol z hD hs a L u).prefix l=z (a+u.val+l.val)-z a := by + change z (a+u.val)-z a+(∑ j : Fin l.val, incrementWord z l.val (a+u.val) j)=_ + rw [incrementWord_sum] + abel + +noncomputable def WalkPackage.Hits {D : ℝ} {B L : ℕ} + (π : GaussianInt) (v : WalkPackage D B L) (x : GaussianInt ⧸ multiples π) : Prop := + ∃ l : Fin L, gaussianResidue π (v.prefix l) = -x + +lemma ForwardKernel.package_true_survives (K : ForwardKernel) + (π : GaussianInt) (z : ℕ → GaussianInt) (havoid : ∀ t, ¬π∣z t) + {D : ℝ} (hD : 0≤D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (a L : ℕ) : + ∀ v, K.packageLaw z hD hs a L v≠0 → ¬WalkPackage.Hits π v (gaussianResidue π (z a)) := by + intro v hv + rw [packageLaw,FinLaw.map_mass] at hv + obtain ⟨u,_,hu⟩ := Finset.exists_ne_zero_of_sum_ne_zero hv + have he : K.packageSymbol z hD hs a L u=v := by + by_contra he + simp only [ite_eq_right he,ne_self_iff_false] at hu + rw [← he] + simpa only [WalkPackage.Hits,K.packageSymbol_prefix] using true_residue_no_hit π z havoid a (a+u.val) L + +lemma FinLaw.mass_map_eq_prob {Ω : Type uOmega} {α : Type uAlpha} [Fintype Ω] [Fintype α] + (p : FinLaw Ω) (f : Ω → α) (x : α) : p.map f x=p.prob (fun ω => f ω=x) := rfl + +theorem ForwardKernel.smoothed_package_floor (R : ForwardKernel) + (π : GaussianInt) (z : ℕ → GaussianInt) (hz : Function.Injective z) + {D τ : ℝ} (hD : 0≤D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) + {L N : ℕ} (hshort : (D*L)^2<(π.norm:ℝ)) (hLN : L≤N) + (herr : (L:ℝ)/(N+1)≤τ/2) (a : ℕ) (x : GaussianInt ⧸ multiples π) + (hfloor : τ≤((R.then (smoothingKernel N)).law a).prob + (fun u => gaussianResidue π (z (a+u.val)-z a) = -x)) : + (L:ℝ)*τ/2≤((R.then (smoothingKernel N)).packageLaw z hD hs a L).prob + (fun v => WalkPackage.Hits π v x) := by + have hf : τ≤((R.law a).joint (fun _ => FinLaw.uniform (Fin (N+1)))).prob + (fun v => gaussianResidue π (z (a+v.1.val+v.2.val)-z a) = -x) := by + change τ≤(((R.law a).joint (fun _ => FinLaw.uniform (Fin (N+1)))).map (addOffsets R.bound N)).prob + (fun (u : Fin (R.bound+N+1)) => gaussianResidue π (z (a+u.val)-z a) = -x) at hfloor + rw [FinLaw.prob_map] at hfloor + simpa only [addOffsets,Nat.add_assoc] using hfloor + have hh := smoothed_package_hit_lower (R.law a) π z hz hD hs hshort hLN herr a + (fun u => a+u.val) (-x) hf + rw [packageLaw,FinLaw.prob_map] + simp only [WalkPackage.Hits,packageSymbol_prefix] + change _≤(((R.law a).joint (fun _ => FinLaw.uniform (Fin (N+1)))).map (addOffsets R.bound N)).prob + (fun (u : Fin (R.bound+N+1)) => ∃ l : Fin L, gaussianResidue π (z (a+u.val+l.val)-z a) = -x) + rw [FinLaw.prob_map] + simpa only [addOffsets,Nat.add_assoc] using hh + +noncomputable def ForwardKernel.passingException (K : ForwardKernel) + (s : SplitSieve) (z : ℕ → GaussianInt) (a : ℕ) (i : s.SignedIndex) (τ : ℝ) : + Finset (s.Residue i) := ((K.relativeResidueLaw s z a i).lowResidues τ).image Neg.neg + +lemma ForwardKernel.passingException_card (K : ForwardKernel) + (s : SplitSieve) (z : ℕ → GaussianInt) (a : ℕ) (i : s.SignedIndex) (τ : ℝ) : + (K.passingException s z a i τ).card=((K.relativeResidueLaw s z a i).lowResidues τ).card := by + apply Finset.card_image_of_injective + exact neg_injective + +lemma ForwardKernel.not_mem_passingException (K : ForwardKernel) + (s : SplitSieve) (z : ℕ → GaussianInt) (a : ℕ) (i : s.SignedIndex) (τ : ℝ) (x : s.Residue i) + (hx : x∉K.passingException s z a i τ) : + τ/(s.signedPrime i:ℝ)≤(K.relativeResidueLaw s z a i) (-x) := by + have hh : -x∉(K.relativeResidueLaw s z a i).lowResidues τ := by + intro h + exact hx (Finset.mem_image.mpr ⟨-x,h,neg_neg x⟩) + have he := (K.relativeResidueLaw s z a i).not_mem_lowResidues τ (-x) |>.mp hh + simpa only [s.residue_card] using he + +lemma SplitSieve.avoids_signed (s : SplitSieve) (z : GaussianInt) + (h : z∈s.avoiding) (i : s.SignedIndex) : ¬s.signedFactorAt i∣z := by + have hh := h (s.signedPrime i) (s.enumeration i.2).property + rcases i with ⟨σ,i⟩ + change ¬signedFactor _ (σ i)∣z + cases he : σ i <;> simp only [signedFactor] <;> tauto + +theorem smoothed_batch_package_information {Ω : Type uOmega} {O : Type uOutput} {ι : Type uIota} + [Fintype Ω] [Fintype O] [Fintype ι] + (s : SplitSieve) (p : FinLaw Ω) (a : Ω → ℕ) (old : Ω → O) + (I : ι → s.SignedIndex) (R : ForwardKernel) + (z : ℕ → GaussianInt) (hz : Function.Injective z) + (ha : ∀ t, z t∈s.avoiding) {D τ A H η : ℝ} {L N n : ℕ} + (hD : 0≤D) (hτ : 0≤τ) (hA : 0≤A) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) + (e : ι → ℝ) (he : ∀ i, 0≤e i) + (hshort : ∀ i, (D*L)^2<(s.signedPrime (I i):ℝ)) (hLN : L≤N) + (herr : ∀ i, (L:ℝ)/(N+1)≤(τ/(s.signedPrime (I i):ℝ))/2) + (hH : (∑ i, Real.log (s.signedPrime (I i)))-H ≤ + p.cHf (fun ω i => s.residue (I i) (z (a ω))) old) + (hBad : (∑ i, p.prob (fun ω => e i≤ + (((R.then (smoothingKernel N)).relativeResidueLaw s z (a ω) (I i)).lowResidues τ).card))≤η) + (hnum : ∀ i, Real.log (4*e i+(s.signedPrime (I i):ℝ)*Real.exp + (-(n:ℝ)*(((L:ℝ)*(τ/(s.signedPrime (I i):ℝ))/2)/4))) ≤ + Real.log (s.signedPrime (I i))-A) : + A*((Fintype.card ι:ℝ)-2*η)-H ≤ (n:ℝ)* + (p.joint (fun ω => (R.then (smoothingKernel N)).packageLaw z hD hs (a ω) L)).cIf + (fun v i => s.residue (I i) (z (a v.1))) Prod.snd (fun v => old v.1) := by + let K := R.then (smoothingKernel N) + let q := fun ω => K.packageLaw z hD hs (a ω) L + let Good := fun i ω => + (((K.relativeResidueLaw s z (a ω) (I i)).lowResidues τ).card:ℝ) s.Residue (I i)) p old + (fun ω i => s.residue (I i) (z (a ω))) q (fun i => WalkPackage.Hits (s.signedFactorAt (I i))) + Good (fun i ω => K.passingException s z (a ω) (I i) τ) e + (fun i => (L:ℝ)*(τ/(s.signedPrime (I i):ℝ))/2) n hA he + · intro i + positivity + · intro ω _ v hv i + exact K.package_true_survives (s.signedFactorAt (I i)) z + (fun t => s.avoids_signed (z t) (ha t) (I i)) hD hs (a ω) L v hv + · intro i ω hg + rw [ForwardKernel.passingException_card] + exact hg.le + · intro i ω _ x hx + apply R.smoothed_package_floor (s.signedFactorAt (I i)) z hz hD hs + (by simpa only [s.signedFactorAt_norm,Int.cast_natCast] using hshort i) hLN (herr i) (a ω) x + have hh := K.not_mem_passingException s z (a ω) (I i) τ x hx + simpa only [ForwardKernel.relativeResidueLaw,FinLaw.mass_map_eq_prob,SplitSieve.residue] using hh + · simpa only [s.residue_card] using hH + · simpa only [Good,not_lt] using hBad + · simpa only [s.residue_card] using hnum + +namespace FinLaw +lemma cIf_congr_fibers {Ω : Type uOmega} {α : Type uAlpha} {α' : Type uAlphaPrime} {β : Type uBeta} {β' : Type uBetaPrime} {γ : Type uGamma} {γ' : Type uGammaPrime} [Fintype Ω] + (p : FinLaw Ω) (X : Ω → α) (X' : Ω → α') + (Y : Ω → β) (Y' : Ω → β') (O : Ω → γ) (O' : Ω → γ') + (hX : ∀ ω ν, X ω=X ν ↔ X' ω=X' ν) + (hY : ∀ ω ν, Y ω=Y ν ↔ Y' ω=Y' ν) + (hO : ∀ ω ν, O ω=O ν ↔ O' ω=O' ν) : + p.cIf X Y O=p.cIf X' Y' O' := by + unfold cIf + rw [p.cHf_congr_fibers X X' O O' hX hO] + congr 1 + apply p.cHf_congr_fibers _ _ _ _ hX + intro ω ν + simp only [Prod.mk.injEq,hO,hY] + +lemma joint_map_cIf {Ω : Type uOmega} {Γ : Type uCapitalGamma} {Γ' : Type uCapitalGammaPrime} {α : Type uAlpha} {β : Type uBeta} [Fintype Ω] [Fintype Γ] [Fintype Γ'] + (p : FinLaw Ω) (q : Ω → FinLaw Γ) (f : Ω → Γ → Γ') (X : Ω → α) (O : Ω → β) : + (p.joint (fun ω => (q ω).map (f ω))).cIf (fun v => X v.1) Prod.snd (fun v => O v.1)= + (p.joint q).cIf (fun v => X v.1) (fun v => f v.1 v.2) (fun v => O v.1) := by + rw [← joint_map_fiber,cIf_map] + rfl +end FinLaw + +theorem ForwardKernel.package_information_transport {Ω : Type uOmega} {ι : Type uIota} {κ : Type uKappa} [Fintype Ω] + (K : ForwardKernel) (p : FinLaw Ω) (a : Ω → ℕ) (f : ι → GaussianInt) (g : κ → GaussianInt) + (z : ℕ → GaussianInt) {D : ℝ} (hD : 1≤D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (hK : 1≤K.bound) (L : ℕ) : + (p.joint (fun ω => K.packageLaw z (by linarith only [hD]) hs (a ω) L)).cIf + (fun v i => residueCode (f i) (z (a v.1))) Prod.snd + (fun v i => residueCode (g i) (z (a v.1))) ≤ + (p.joint (fun ω => K.law (a ω))).cIf + (fun v i => residueCode (f i) (z (a v.1+v.2.val))) + (fun v => incrementWord z L (a v.1+v.2.val)) + (fun v i => residueCode (g i) (z (a v.1+v.2.val)))+ + 2*(Real.log 36+2*Real.log (D*K.bound)) := by + let P := p.joint (fun ω => K.law (a ω)) + let X := fun v : Ω × Fin (K.bound+1) => z (a v.1) + let Y := fun v : Ω × Fin (K.bound+1) => z (a v.1+v.2.val) + let S := fun v => Y v-X v + let W := fun v : Ω × Fin (K.bound+1) => incrementWord z L (a v.1+v.2.val) + have hemap := FinLaw.joint_map_cIf p (fun ω => K.law (a ω)) + (fun ω => K.packageSymbol z (by linarith only [hD]) hs (a ω) L) + (fun ω i => residueCode (f i) (z (a ω))) (fun ω i => residueCode (g i) (z (a ω))) + change (p.joint (fun ω => K.packageLaw z (by linarith only [hD]) hs (a ω) L)).cIf _ _ _=_ at hemap + rw [hemap] + have he := P.cIf_congr_fibers + (fun v i => residueCode (f i) (X v)) (fun v i => residueCode (f i) (X v)) + (fun v => K.packageSymbol z (by linarith only [hD]) hs (a v.1) L v.2) + (fun v => (S v,W v)) + (fun v i => residueCode (g i) (X v)) (fun v i => residueCode (g i) (X v)) + (fun _ _ => Iff.rfl) (fun v w => by + simp only [ForwardKernel.packageSymbol,Prod.mk.injEq,Subtype.mk.injEq, + ForwardKernel.displacementSymbol,boundedWord_fibers] + rfl) (fun _ _ => Iff.rfl) + change P.cIf _ _ _≤_ + rw [he] + have ht := P.cIf_transport (fun v i => residueCode (f i) (X v)) + (fun v i => residueCode (g i) (X v)) (fun v i => residueCode (f i) (Y v)) + (fun v i => residueCode (g i) (Y v)) W S + (residue_observation_shift g X Y) (by + intro v w + have hf := residue_observation_shift f X Y v w + have hg := residue_observation_shift g X Y v w + simp only [Prod.mk.injEq,S] at hf hg ⊢ + tauto) + have hc : P.Hf S≤Real.log 36+2*Real.log (D*K.bound) := by + apply displacement_entropy_le + · exact one_le_mul_of_one_le_of_one_le hD (by exact_mod_cast hK) + · intro v + simpa only [S,X,Y,Nat.add_zero] using walk_pair_displacement z (by linarith only [hD]) hs + (a v.1) K.bound v.2.val 0 (by omega) (by omega) + exact ht.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left hc (show (0:ℝ)≤2 by norm_num))) + +lemma perm_expect_uniform {ι : Type uIota} [Fintype ι] [DecidableEq ι] [Nonempty ι] + (f : ι → ℝ) (i : ι) : + (𝔼 π : Equiv.Perm ι, f (π i))=𝔼 j, f j := by + have hf (π : Equiv.Perm ι) : (𝔼 j, f (π j))=𝔼 j, f j := by + rw [Fintype.expect_eq_sum_div_card,Fintype.expect_eq_sum_div_card,Equiv.sum_comp π] + calc + _ = 𝔼 j : ι, 𝔼 π : Equiv.Perm ι, f (π j) := by + simp_rw [← perm_expect_exchange f i] + rw [Fintype.expect_const] + _ = 𝔼 π : Equiv.Perm ι, 𝔼 j, f (π j) := Finset.expect_comm _ _ _ + _ = _ := by simp_rw [hf]; rw [Fintype.expect_const] + +noncomputable def SplitSieve.selectedIndex (s : SplitSieve) {b : ℕ} (hb : b≤ s.primes.card) + (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) (j : Fin b) : + s.SignedIndex := (σ,π ⟨j.val,lt_of_lt_of_le j.isLt hb⟩) + +lemma SplitSieve.selected_sum_average (s : SplitSieve) (hne : s.primes.Nonempty) + {b : ℕ} (hb : b≤ s.primes.card) (f : s.SignedIndex → ℝ) : + (𝔼 σ : Fin s.primes.card → Bool, 𝔼 π : Equiv.Perm (Fin s.primes.card), + ∑ j : Fin b, f (s.selectedIndex hb σ π j)) = + (b:ℝ)*(𝔼 i : s.SignedIndex, f i) := by + have : Nonempty (Fin s.primes.card) := ⟨⟨0,hne.card_pos⟩⟩ + have hf (σ : Fin s.primes.card → Bool) (j : Fin b) : + (𝔼 π : Equiv.Perm (Fin s.primes.card),f (s.selectedIndex hb σ π j))= + 𝔼 i : Fin s.primes.card, f (σ,i) := by + exact perm_expect_uniform (fun i => f (σ,i)) ⟨j.val,lt_of_lt_of_le j.isLt hb⟩ + simp only [Finset.expect_sum_comm,hf,Finset.sum_const,Finset.card_univ, + Fintype.card_fin,nsmul_eq_mul,← Finset.mul_expect,← Finset.univ_product_univ,Finset.expect_product] + +lemma selected_prefix_fibers {Ω : Type uOmega} {α : Type uAlpha} {k b : ℕ} (hb : b≤k) + (X : Ω → Fin k → α) (π : Equiv.Perm (Fin k)) (ω ν : Ω) : + (fun j : Fin b => X ω (π ⟨j.val,lt_of_lt_of_le j.isLt hb⟩))= + (fun j : Fin b => X ν (π ⟨j.val,lt_of_lt_of_le j.isLt hb⟩)) ↔ + FinLaw.prefixVar X π b ω=FinLaw.prefixVar X π b ν := by + constructor + · intro h + funext i + by_cases hi : i.val s.residue (s.selectedIndex hb σ π j) (Z ω))= + (fun j => s.residue (s.selectedIndex hb σ π j) (Z ν)) ↔ + FinLaw.prefixVar (fun v => s.residueVector σ (Z v)) π b ω= + FinLaw.prefixVar (fun v => s.residueVector σ (Z v)) π b ν := by + rw [funext_iff] + simp only [s.residue_fibers] + change (∀ j : Fin b, s.residueVector σ (Z ω) (π ⟨j.val,_⟩)= + s.residueVector σ (Z ν) (π ⟨j.val,_⟩)) ↔ _ + rw [← funext_iff] + exact selected_prefix_fibers hb (fun v => s.residueVector σ (Z v)) π ω ν + +lemma SplitSieve.selected_entropy_average {Ω : Type uOmega} [Fintype Ω] + (s : SplitSieve) (p : FinLaw Ω) (Z : Ω → GaussianInt) + {b : ℕ} (hb : b≤ s.primes.card) : + (𝔼 σ : Fin s.primes.card → Bool, 𝔼 π : Equiv.Perm (Fin s.primes.card), + p.Hf (fun ω j => s.residue (s.selectedIndex hb σ π j) (Z ω)))= + s.pointEntropy p Z b := by + have h (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) := + p.Hf_eq_of_fibers _ _ (s.selected_residue_fibers hb σ π Z) + simp only [h,SplitSieve.pointEntropy,FinLaw.signedEntropy,FinLaw.orderedEntropy] + +lemma SplitSieve.selected_log_average (s : SplitSieve) (hne : s.primes.Nonempty) + {b : ℕ} (hb : b≤ s.primes.card) : + (𝔼 σ : Fin s.primes.card → Bool, 𝔼 π : Equiv.Perm (Fin s.primes.card), + ∑ j : Fin b, Real.log (s.signedPrime (s.selectedIndex hb σ π j))) = + (b:ℝ)*s.meanLog := by + rw [s.selected_sum_average hne hb (fun i => Real.log (s.signedPrime i))] + simp only [← Finset.univ_product_univ,Finset.expect_product, + SplitSieve.signedPrime,Fintype.expect_const,SplitSieve.meanLog] + +theorem averaged_batch_package_information {Ω : Type uOmega} {O : Type uOutput} [Fintype Ω] [Fintype O] + (s : SplitSieve) (hne : s.primes.Nonempty) (p : FinLaw Ω) (a : Ω → ℕ) + (old : Ω → O) (R : ForwardKernel) (z : ℕ → GaussianInt) + (hz : Function.Injective z) (ha : ∀ t, z t∈s.avoiding) + {b L N n : ℕ} (hb : b≤ s.primes.card) {D τ A η δ E : ℝ} + (hD : 0≤D) (hτ : 0≤τ) (hA : 0≤A) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) + (e : s.SignedIndex → ℝ) (he : ∀ i, 0≤e i) + (hshort : ∀ i, (D*L)^2<(s.signedPrime i:ℝ)) (hLN : L≤N) + (herr : ∀ i, (L:ℝ)/(N+1)≤(τ/(s.signedPrime i:ℝ))/2) + (hH : (1-δ)*(b:ℝ)*s.meanLog≤ s.pointEntropy p (fun ω => z (a ω)) b) + (hO : p.Hf old≤E) + (hBad : (𝔼 i : s.SignedIndex, p.prob (fun ω => e i≤ + (((R.then (smoothingKernel N)).relativeResidueLaw s z (a ω) i).lowResidues τ).card))≤η) + (hnum : ∀ i, Real.log (4*e i+(s.signedPrime i:ℝ)*Real.exp + (-(n:ℝ)*(((L:ℝ)*(τ/(s.signedPrime i:ℝ))/2)/4))) ≤ + Real.log (s.signedPrime i)-A) : + (b:ℝ)*(A*(1-2*η)-δ*s.meanLog)-E ≤ (n:ℝ)* + (𝔼 σ : Fin s.primes.card → Bool, 𝔼 π : Equiv.Perm (Fin s.primes.card), + (p.joint (fun ω => (R.then (smoothingKernel N)).packageLaw z hD hs (a ω) L)).cIf + (fun v j => s.residue (s.selectedIndex hb σ π j) (z (a v.1))) + Prod.snd (fun v => old v.1)) := by + let X := fun (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) + (ω : Ω) (j : Fin b) => s.residue (s.selectedIndex hb σ π j) (z (a ω)) + let Bad := fun i => p.prob (fun ω => e i≤ + (((R.then (smoothingKernel N)).relativeResidueLaw s z (a ω) i).lowResidues τ).card) + have hi (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) := + smoothed_batch_package_information s p a old (s.selectedIndex hb σ π) R z hz ha + hD hτ hA hs (fun j => e (s.selectedIndex hb σ π j)) + (fun j => he _) (fun j => hshort _) hLN (fun j => herr _) + (H := (∑ j, Real.log (s.signedPrime (s.selectedIndex hb σ π j)))-p.cHf (X σ π) old) + (by dsimp only [X]; linarith) + (η := ∑ j, Bad (s.selectedIndex hb σ π j)) le_rfl (fun j => hnum _) + have hav := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => + Finset.expect_le_expect (s := Finset.univ) (fun π _ => hi σ π)) + simp only [Fintype.card_fin,Finset.expect_sub_distrib,← Finset.mul_expect,Fintype.expect_const, + Finset.expect_sum_comm] at hav + have hx (σ : Fin s.primes.card → Bool) (π : Equiv.Perm (Fin s.primes.card)) : + p.Hf (X σ π)-E≤p.cHf (X σ π) old := by + have h := p.Hf_pair_ge_snd old (X σ π) + rw [p.Hf_pair_comm] at h + unfold FinLaw.cHf + linarith only [h,hO] + have hxa := Finset.expect_le_expect (s := Finset.univ) (fun σ _ => + Finset.expect_le_expect (s := Finset.univ) (fun π _ => hx σ π)) + simp only [Finset.expect_sub_distrib,Fintype.expect_const] at hxa + have hxe := s.selected_entropy_average p (fun ω => z (a ω)) hb + change (𝔼 σ, 𝔼 π, p.Hf (X σ π))=_ at hxe + rw [hxe] at hxa + have hlog := s.selected_log_average hne hb + have hbad := s.selected_sum_average hne hb Bad + have hbR : 0≤(b:ℝ) := Nat.cast_nonneg _ + have hbadle : (b:ℝ)*(𝔼 i, Bad i)≤b*η := mul_le_mul_of_nonneg_left hBad hbR + simp only [Finset.expect_sum_comm] at hlog hbad + rw [hlog,hbad] at hav + have hprod := mul_le_mul_of_nonneg_left hbadle hA + nlinarith only [hav,hxa,hH,hprod] + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/WalkWords.lean b/lean/OAI/NumberTheory/GaussianMoat/WalkWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef80836338f44cdeba6ef113746820f1febfd042 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/WalkWords.lean @@ -0,0 +1,239 @@ +import OAI.NumberTheory.GaussianMoat.PosteriorSampling + +namespace OAI + +universe uIota uOmega uAlpha uBeta uGamma uDelta + +namespace GaussianMoat +open scoped BigOperators Classical + +noncomputable def incrementWord (z : ℕ → GaussianInt) (L t : ℕ) : Fin L → GaussianInt := + fun i => z (t+i.val+1)-z (t+i.val) + +lemma incrementWord_sum (z : ℕ → GaussianInt) (L t : ℕ) : + ∑ i, incrementWord z L t i=z (t+L)-z t := by + simp only [incrementWord] + rw [Fin.sum_univ_eq_sum_range (fun i => z (t+i+1)-z (t+i))] + simpa only [Nat.add_assoc,Nat.add_zero] using + Finset.sum_range_sub (fun i => z (t+i)) L + +lemma block_displacement (z : ℕ → GaussianInt) (L k t u : ℕ) + (h : ∀ j simp + | succ k ih => + have hh := ih (fun j hj => h j (by omega)) + have hk := congrArg (fun w : Fin L → GaussianInt => ∑ i, w i) (h k (by omega)) + rw [incrementWord_sum,incrementWord_sum] at hk + have ht : t+k*L+L=t+(k+1)*L := by ring + have hu : u+k*L+L=u+(k+1)*L := by ring + rw [ht,hu] at hk + linear_combination hh+hk + +lemma residue_block_update {ι : Type uIota} (f : ι → GaussianInt) (z : ℕ → GaussianInt) + (L k t u : ℕ) + (hQ : (fun i => residueCode (f i) (z t))=(fun i => residueCode (f i) (z u))) + (hW : ∀ j residueCode (f i) (z (t+k*L)))= + (fun i => residueCode (f i) (z (u+k*L))) := by + have hd := block_displacement z L k t u hW + funext i + have hh := residueCode_add (congrFun hQ i) (congrArg (residueCode (f i)) hd) + simpa only [add_sub_cancel] using hh + +theorem incrementWord_blocks_entropy {Ω : Type uOmega} {ι : Type uIota} [Fintype Ω] + (p : FinLaw Ω) (t : Ω → ℕ) (z : ℕ → GaussianInt) (f : ι → GaussianInt) + (L n : ℕ) (hL : 0 incrementWord z (n*L) (t ω)) + (fun ω i => residueCode (f i) (z (t ω))) ≤ + ∑ j : Fin n, p.cHf (fun ω => incrementWord z L (t ω+j.val*L)) + (fun ω i => residueCode (f i) (z (t ω+j.val*L))) := by + let W := fun ω (j : Fin n) => incrementWord z L (t ω+j.val*L) + let Q := fun ω i => residueCode (f i) (z (t ω)) + have hvec : p.cHf (fun ω => incrementWord z (n*L) (t ω)) Q ≤ p.cHf W Q := by + apply p.cHf_le_of_determined + intro ω ν h _ + funext i + let j : Fin n := ⟨i.val/L,(Nat.div_lt_iff_lt_mul hL).mpr i.isLt⟩ + let a : Fin L := ⟨i.val%L,Nat.mod_lt _ hL⟩ + have hh := congrFun (congrFun h j) a + have he : j.val*L+a.val=i.val := by + dsimp only [j,a] + simpa only [Nat.mul_comm] using Nat.div_add_mod i.val L + simpa only [W,incrementWord,Nat.add_assoc,he] using hh + apply hvec.trans + apply p.cHf_blocks_le W Q + intro j ω ν hW hQ + apply residue_block_update f z L j.val (t ω) (t ν) hQ + intro k hk + have hh := congrFun hW ⟨k,lt_trans hk j.isLt⟩ + simpa only [FinLaw.prefixVar,Equiv.refl_apply,hk,ite_eq_left,Option.some.injEq,W] using hh + +noncomputable def boundedWord (z : ℕ → GaussianInt) {D : ℝ} + (hz : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (L t : ℕ) : Fin L → latticeBall D := + fun i => ⟨incrementWord z L t i,by + rw [mem_latticeBall] + simpa only [incrementWord,map_sub,← dist_eq_norm,dist_comm] using hz (t+i.val)⟩ + +lemma boundedWord_fibers (z : ℕ → GaussianInt) {D : ℝ} + (hz : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (L t u : ℕ) : + boundedWord z hz L t=boundedWord z hz L u ↔ incrementWord z L t=incrementWord z L u := by + constructor + · intro h + funext i + exact congrArg Subtype.val (congrFun h i) + · intro h + funext i + exact Subtype.ext (congrFun h i) + +lemma boundedWord_entropy_le {Ω : Type uOmega} [Fintype Ω] (p : FinLaw Ω) (t : Ω → ℕ) + (z : ℕ → GaussianInt) {D : ℝ} (hz : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) (L : ℕ) : + p.Hf (fun ω => incrementWord z L (t ω)) ≤ (L:ℝ)*Real.log (latticeBall D).card := by + have he : p.Hf (fun ω => incrementWord z L (t ω))=p.Hf (fun ω => boundedWord z hz L (t ω)) := by + apply p.Hf_eq_of_fibers + intro ω ν + exact (boundedWord_fibers z hz L (t ω) (t ν)).symm + rw [he] + have h := p.Hf_le_log_card_type (fun ω => boundedWord z hz L (t ω)) + simpa only [Fintype.card_fun,Fintype.card_fin,Fintype.card_coe,Nat.cast_pow,Real.log_pow] using h + +@[simp] lemma gaussianResidue_add (π z w : GaussianInt) : + gaussianResidue π (z+w)=gaussianResidue π z+gaussianResidue π w := rfl +@[simp] lemma gaussianResidue_sub (π z w : GaussianInt) : + gaussianResidue π (z-w)=gaussianResidue π z-gaussianResidue π w := rfl +@[simp] lemma gaussianResidue_zero (π : GaussianInt) : gaussianResidue π 0=0 := rfl + +lemma short_residue_hits_disjoint (π : GaussianInt) (z : ℕ → GaussianInt) + (hz : Function.Injective z) {D : ℝ} (hD : 0 ≤ D) + (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) {L : ℕ} + (hshort : (D*L)^2 < (π.norm:ℝ)) (a t : ℕ) + (x : GaussianInt ⧸ multiples π) (i j : Fin L) + (hi : gaussianResidue π (z (t+i.val)-z a)=x) + (hj : gaussianResidue π (z (t+j.val)-z a)=x) : i=j := by + by_contra hij + have hneq : z (t+i.val)≠z (t+j.val) := by + intro he + have ht := hz he + apply hij + apply Fin.ext + omega + have hh := walk_pair_displacement z hD hs t L i.val j.val (by omega) (by omega) + rw [GaussianInt.toComplex_sub,← dist_eq_norm] at hh + have hd : dist (z (t+i.val):ℂ) (z (t+j.val):ℂ)^2 < (π.norm:ℝ) := by + exact (sq_le_sq₀ dist_nonneg (mul_nonneg hD (Nat.cast_nonneg L))).mpr hh |>.trans_lt hshort + have hres : gaussianResidue π (z (t+i.val))=gaussianResidue π (z (t+j.val)) := by + simpa only [gaussianResidue_sub,sub_left_inj] using hi.trans hj.symm + exact not_dvd_sub_of_dist_sq_lt hneq hd ((gaussianResidue_eq _ _ _).mp hres) + +lemma short_residue_hit_prob {Ω : Type uOmega} [Fintype Ω] (p : FinLaw Ω) + (π : GaussianInt) (z : ℕ → GaussianInt) (hz : Function.Injective z) + {D : ℝ} (hD : 0 ≤ D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) + {L : ℕ} (hshort : (D*L)^2 < (π.norm:ℝ)) (a : ℕ) (t : Ω → ℕ) + (x : GaussianInt ⧸ multiples π) : + p.prob (fun ω => ∃ i : Fin L, gaussianResidue π (z (t ω+i.val)-z a)=x) = + ∑ i : Fin L, p.prob (fun ω => gaussianResidue π (z (t ω+i.val)-z a)=x) := by + apply p.prob_exists_eq_sum_disjoint + intro ω i j hi hj + exact short_residue_hits_disjoint π z hz hD hs hshort a (t ω) x i j hi hj + +theorem smoothed_package_hit_lower {Ω : Type uOmega} [Fintype Ω] (p : FinLaw Ω) + (π : GaussianInt) (z : ℕ → GaussianInt) (hz : Function.Injective z) + {D c : ℝ} (hD : 0 ≤ D) (hs : ∀ t, dist (z t:ℂ) (z (t+1):ℂ) ≤ D) + {L N : ℕ} (hshort : (D*L)^2 < (π.norm:ℝ)) (hLN : L ≤ N) + (herr : (L:ℝ)/(N+1) ≤ c/2) (a : ℕ) (t : Ω → ℕ) + (x : GaussianInt ⧸ multiples π) + (hfloor : c ≤ (p.joint (fun _ => FinLaw.uniform (Fin (N+1)))).prob + (fun v => gaussianResidue π (z (t v.1+v.2.val)-z a)=x)) : + (L:ℝ)*c/2 ≤ (p.joint (fun _ => FinLaw.uniform (Fin (N+1)))).prob + (fun v => ∃ i : Fin L, gaussianResidue π (z (t v.1+v.2.val+i.val)-z a)=x) := by + rw [short_residue_hit_prob _ π z hz hD hs hshort a] + have hh (i : Fin L) : c/2 ≤ + (p.joint (fun _ => FinLaw.uniform (Fin (N+1)))).prob + (fun v => gaussianResidue π (z (t v.1+v.2.val+i.val)-z a)=x) := by + have hp := p.smoothing_prob t N i.val (by omega) + (fun b => gaussianResidue π (z b-z a)=x) + have he : (i.val:ℝ)/(N+1) ≤ c/2 := by + apply le_trans _ herr + exact div_le_div_of_nonneg_right (by exact_mod_cast i.isLt.le) (by positivity) + linarith only [hp,hfloor,he] + have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hh i) + simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_div_assoc] using h + +lemma true_residue_no_hit (π : GaussianInt) (z : ℕ → GaussianInt) + (havoid : ∀ t, ¬π ∣ z t) (a t L : ℕ) : + ¬∃ i : Fin L, gaussianResidue π (z (t+i.val)-z a) = -gaussianResidue π (z a) := by + rintro ⟨i,hi⟩ + have hh : gaussianResidue π (z (t+i.val))=gaussianResidue π 0 := by + rw [gaussianResidue_sub] at hi + rw [gaussianResidue_zero] + exact sub_eq_neg_self.mp hi + have hd := (gaussianResidue_eq _ _ _).mp hh + simp only [sub_zero] at hd + exact havoid _ hd + +namespace FinLaw +variable {Ω : Type uOmega} {α : Type uAlpha} {β : Type uBeta} {γ : Type uGamma} {δ : Type uDelta} [Fintype Ω] + +lemma cHf_congr_fibers (p : FinLaw Ω) (X : Ω → α) (Y : Ω → β) (C : Ω → γ) (D : Ω → δ) + (hX : ∀ ω ν, X ω=X ν ↔ Y ω=Y ν) (hC : ∀ ω ν, C ω=C ν ↔ D ω=D ν) : + p.cHf X C=p.cHf Y D := by + unfold cHf + rw [p.Hf_eq_of_fibers C D hC] + congr 1 + apply p.Hf_eq_of_fibers + intro ω ν + simp only [Prod.mk.injEq,hX,hC] + +end FinLaw + +lemma residueCode_vector_fibers {ι : Type uIota} (f : ι → GaussianInt) (x y : GaussianInt) : + (fun i => residueCode (f i) x)=(fun i => residueCode (f i) y) ↔ + (fun i => gaussianResidue (f i) x)=(fun i => gaussianResidue (f i) y) := by + simp only [funext_iff,residueCode_eq,gaussianResidue_eq] + +theorem word_residue_smoothing {Ω : Type uOmega} {ι : Type uIota} [Fintype Ω] [Fintype ι] + (p : FinLaw Ω) (t : Ω → ℕ) (z : ℕ → GaussianInt) {D : ℝ} + (hz : ∀ t, dist (z t:ℂ) (z (t+1):ℂ)≤D) + (f : ι → GaussianInt) (hf : ∀ i, f i≠0) (L N a : ℕ) (ha : a≤N) : + let P := p.joint (fun _ => FinLaw.uniform (Fin (N+1))) + P.cHf (fun v => incrementWord z L (t v.1+v.2.val+a)) + (fun v i => residueCode (f i) (z (t v.1+v.2.val+a))) ≤ + P.cHf (fun v => incrementWord z L (t v.1+v.2.val)) + (fun v i => residueCode (f i) (z (t v.1+v.2.val)))+ + 2*Real.binEntropy ((a:ℝ)/(N+1))+ + ((a:ℝ)/(N+1))*((L:ℝ)*Real.log (latticeBall D).card+ + 2*∑ i, Real.log (f i).norm.natAbs) := by + let (i : ι) : Finite (GaussianInt ⧸ multiples (f i)) := finite_gaussianResidue (hf i) + let (i : ι) : Fintype (GaussianInt ⧸ multiples (f i)) := Fintype.ofFinite _ + dsimp only + let P := p.joint (fun _ => FinLaw.uniform (Fin (N+1))) + have he (u : Ω × Fin (N+1) → ℕ) : + P.cHf (fun v => incrementWord z L (u v)) (fun v i => residueCode (f i) (z (u v))) = + P.condH (fun v => boundedWord z hz L (u v)) (fun v i => gaussianResidue (f i) (z (u v))) := by + rw [show P.condH (fun v => boundedWord z hz L (u v)) + (fun v i => gaussianResidue (f i) (z (u v))) = + P.cHf (fun v => boundedWord z hz L (u v)) + (fun v i => gaussianResidue (f i) (z (u v))) by + simp only [FinLaw.condH,FinLaw.cHf,FinLaw.Hf_eq_H]] + apply P.cHf_congr_fibers + · intro v w; exact (boundedWord_fibers z hz L (u v) (u w)).symm + · intro v w; exact residueCode_vector_fibers f _ _ + have h := p.smoothing_condH t N a ha (boundedWord z hz L) + (fun t i => gaussianResidue (f i) (z t)) + have hc : Real.log (Fintype.card ((i : ι) → GaussianInt ⧸ multiples (f i))) = + ∑ i, Real.log (f i).norm.natAbs := by + rw [Fintype.card_pi,Nat.cast_prod,Real.log_prod] + · apply Finset.sum_congr rfl + intro i _ + rw [← Nat.card_eq_fintype_card,multiples_index (hf i)] + · intro i _ + exact_mod_cast Fintype.card_ne_zero + change P.cHf _ _ ≤ P.cHf _ _+_+_ + rw [he,he] + simpa only [Fintype.card_fun,Fintype.card_fin,Fintype.card_coe,Nat.cast_pow, + Real.log_pow,hc] using h + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/WindowBatch.lean b/lean/OAI/NumberTheory/GaussianMoat/WindowBatch.lean new file mode 100644 index 0000000000000000000000000000000000000000..318ec6aa60aa15b1ea51cfe67656afbca9c8e7d4 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/WindowBatch.lean @@ -0,0 +1,148 @@ +import OAI.NumberTheory.GaussianMoat.CommonBlocks + +namespace OAI + +namespace GaussianMoat +open scoped BigOperators Classical +open Filter + +lemma eventually_length_smoothing : + ∀ᶠ X : ℝ in atTop, ∀ p L N : ℝ, + 0

Disjoint (subbin R theta N i) (subbin R theta N j)) := by + intro i j hij + apply Finset.disjoint_left.mpr + intro p hpi hpj + have hp := subbin_subset hR ht i.isLt hpi + obtain ⟨k, _, hk⟩ := unique_prime_subbin hR ht hN hp + exact hij ((hk i hpi).trans (hk j hpj).symm) + +theorem finite_partition {R theta : ℝ} {N : ℕ} (hR : 0 < R) + (ht : 0 < theta) (hN : 0 < N) : + (Finset.univ : Finset (Fin N)).biUnion (fun i => subbin R theta N i) = primeBin R theta := by + classical + ext p + simp only [Finset.mem_biUnion, Finset.mem_univ, true_and] + constructor + · rintro ⟨i, hi⟩ + exact subbin_subset hR ht i.isLt hi + · intro hp + exact (unique_prime_subbin hR ht hN hp).exists + +theorem sum_partition {R theta : ℝ} {N : ℕ} {B : Type*} [AddCommMonoid B] + (hR : 0 < R) (ht : 0 < theta) (hN : 0 < N) (reward : ℕ → B) : + (∑ p ∈ primeBin R theta, reward p) = + ∑ i : Fin N, ∑ p ∈ subbin R theta N i, reward p := by + classical + rw [← finite_partition hR ht hN] + exact Finset.sum_biUnion (fun i _ j _ hij => subbins_pairwise_disjoint hR ht hN hij) + +theorem card_partition {R theta : ℝ} {N : ℕ} (hR : 0 < R) + (ht : 0 < theta) (hN : 0 < N) : + (primeBin R theta).card = ∑ i : Fin N, (subbin R theta N i).card := by + classical + simpa only [Finset.sum_const, smul_eq_mul, mul_one, Nat.cast_id] using + sum_partition hR ht hN (fun _ : ℕ => (1 : ℕ)) + +theorem actual_prime_common_geometry {R theta w Cs : ℝ} {i p : ℕ} + (hR : 0 < R) (ht : 0 < theta) (ht1 : theta ≤ 1) (hw : 1 < w) + (hCs : 0 ≤ Cs) (hi : i < count w Cs) (hp : p ∈ subbin R theta (count w Cs) i) : + left R theta (count w Cs) i ≤ (p : ℝ) ∧ + (p : ℝ) ≤ right R theta (count w Cs) i ∧ + right R theta (count w Cs) i ≤ + (1 + w ^ (-2 * Cs - 10)) * left R theta (count w Cs) i := by + have hm := (mem_subbin hR ht (count_bounds hw hCs).1).mp hp + exact ⟨hm.2.1.le, hm.2.2, (local_common_interval_geometry hR ht ht1 hw hCs hi).2.2.1⟩ + +end ErdosTagSubbins + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/ConditionalPrimeBins.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/ConditionalPrimeBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e116a10054877ba9c863957ea88ee612b5aae9d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/ConditionalPrimeBins.lean @@ -0,0 +1,188 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.RetainedIntervalUpper + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.PrimeCompletedIntervalUpper + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeHistories PrimeKilledChain +open RetainedIntervalUpper + +variable {w ell S : ℝ} {start : Node} + +def closedLiveBin (a b : ℝ) : Set (ChainState w ell S start) := + fun z => match z with + | none => False + | some h => a ≤ h.node.ratio ∧ h.node.ratio ≤ b + +theorem mem_closedLiveBin_some (h : History w ell S start) (a b : ℝ) : + some h ∈ closedLiveBin a b ↔ a ≤ h.node.ratio ∧ h.node.ratio ≤ b := Iff.rfl + +theorem not_mem_closedLiveBin_none (a b : ℝ) : + (none : ChainState w ell S start) ∉ closedLiveBin a b := by + change ¬False + exact not_false + +theorem chain_closedBin_formula (h : History w ell S start) (a b : ℝ) : + chain w ell S start (some h) (closedLiveBin a b) = + ∑ p ∈ nodeChildren w ell S h.node, + if a ≤ childRatio w h.node.gap p ∧ childRatio w h.node.gap p ≤ b + then childProbability w ell S start h p else 0 := by + classical + simp only [chain_some,completedLaw,Measure.add_apply,liveLaw,Measure.finsetSum_apply, + Measure.smul_apply,smul_eq_mul,Measure.dirac_apply,Set.indicator,mem_closedLiveBin_some, + not_mem_closedLiveBin_none,History.append_node,step,Pi.one_apply,mul_ite,mul_one,mul_zero,ite_false,add_zero] + exact Finset.sum_attach _ (fun p : ℕ => + if a ≤ childRatio w h.node.gap p ∧ childRatio w h.node.gap p ≤ b + then childProbability w ell S start h p else 0) + +theorem chain_interval_le_tilt (h : History w ell S start) (hs : Valid h.node.side h.node.ratio) (a b : ℝ) : + chain w ell S start (some h) (closedLiveBin a b) ≤ + ENNReal.ofReal (retainedIntervalTilt w ell S h.node.side h.node.ratio h.node.gap h.node.cutoff h.node.closed a b) := by + classical + rw [chain_closedBin_formula,← Finset.sum_filter] + change (∑ p ∈ retainedInterval w ell S h.node.side h.node.ratio h.node.gap h.node.cutoff h.node.closed a b, + childProbability w ell S start h p) ≤ _ + unfold retainedIntervalTilt + rw [ENNReal.ofReal_sum_of_nonneg + (s := retainedInterval w ell S h.node.side h.node.ratio h.node.gap h.node.cutoff h.node.closed a b) + (f := fun p => primeTilt w h.node.gap h.node.side h.node.ratio p) + (fun p hp => primeTilt_nonneg hs (Finset.mem_filter.mp hp).1)] + apply Finset.sum_le_sum + intro p hp + apply ENNReal.ofReal_le_ofReal + exact div_le_self (primeTilt_nonneg hs (Finset.mem_filter.mp hp).1) (by linarith [epsilon_pos w]) + +theorem prime_completed_interval_upper : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → + ∀ h : History w ell S start, ∀ a b : ℝ, 0 < a → a ≤ b → b-a ≤ 1 → + chain w ell S start (some h) (closedLiveBin a b) ≤ + ENNReal.ofReal (C*(1+S)^2*((b-a)+Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)))) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hbound⟩ := retained_short_interval_upper + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw ell S start hell hr hs hsS h a b ha hab hwidth + have hv := terminal_valid hs h.admissible + have hg := terminal_gap_positive (show 0 ≤ ell by linarith) hr hs h.admissible + have hS := terminal_ratio_le hsS h.admissible + exact (chain_interval_le_tilt h hv a b).trans (ENNReal.ofReal_le_ofReal + (hbound w hw ell S h.node.side h.node.ratio h.node.gap h.node.cutoff a b h.node.closed + hell hg hv hS ha hab hwidth)) + +end NumberTheoryLean.PrimeCompletedIntervalUpper + + + +namespace NumberTheoryLean.ConditionalPrimeBins + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeTiltBounds PrimeTiltMonotone +open PrimeCumulativeBound PrimeRatioBins RetainedIntervalUpper PrimeCompletedIntervalUpper +open PrimeHistories PrimeKilledChain DerivativeWeights WeightFutureIntegrals + +theorem multiplier_valid_antitone {i : Side} {s a t : ℝ} (hs : Valid i s) + (ha : Valid i.flip a) (ht : Valid i.flip t) (hat : a ≤ t) : + multiplier i s t ≤ multiplier i s a := by + have ha0 := valid_pos ha + have ht0 := valid_pos ht + have hphi := TwoStepDensityBounds.weight_antitone ha ht hat + have hq : (t+1)/t ≤ (a+1)/a := by + rw [add_div,div_self ht0.ne',add_div,div_self ha0.ne'] + exact add_le_add_right (one_div_le_one_div_of_le ha0 hat) 1 + have hqt : 0 ≤ (t+1)/t := by positivity + have hqa : 0 ≤ (a+1)/a := by positivity + have hsq : ((t+1)/t)^2 ≤ ((a+1)/a)^2 := by nlinarith + unfold multiplier + apply div_le_div_of_nonneg_right _ (weight_pos hs).le + exact mul_le_mul hsq hphi (weight_pos ht).le (sq_nonneg _) + +theorem retained_tilt_le_multiplier {w ell S s r cap a b : ℝ} {i : Side} {closed : Bool} + (hw : 1 < w) (hs : Valid i s) (ha : Valid i.flip a) (hab : a ≤ b) : + retainedIntervalTilt w ell S i s r cap closed a b ≤ multiplier i s a*closedMass w r a b := by + classical + let A := retainedInterval w ell S i s r cap closed a b + have hraw : (∑ p ∈ A,(p:ℝ)⁻¹) ≤ closedMass w r a b := + Finset.sum_le_sum_of_subset_of_nonneg (retained_subset_closed hw (valid_pos ha) hab) + (fun p _ _ => inv_nonneg.mpr (Nat.cast_nonneg p)) + calc + _ ≤ multiplier i s a*(∑ p ∈ A,(p:ℝ)⁻¹) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + rcases Finset.mem_filter.mp hp with ⟨hchild,hat,_⟩ + have hm := multiplier_valid_antitone hs ha (child_valid hs hchild) hat + rw [primeTilt_eq_multiplier,mul_comm (multiplier i s a)] + exact mul_le_mul_of_nonneg_left hm (inv_nonneg.mpr (Nat.cast_nonneg p)) + _ ≤ _ := mul_le_mul_of_nonneg_left hraw (multiplier_pos hs ha).le + +theorem retained_conditional_bin : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ i : Side, ∀ s r cap a h : ℝ, ∀ closed : Bool, + 1 ≤ ell → 0 < r → Valid i s → Valid i.flip a → 0 < h → h ≤ 1 → + retainedIntervalTilt w ell S i s r cap closed a (a+h) ≤ + (1+C*(a+1)*Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))/h)* + h*W a*(weight i.flip a/weight i s) := by + classical + obtain ⟨c,C,w₀,hc,hC,hw₀,herror⟩ := closed_prime_error + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw ell S i s r cap a h closed hell hr hs ha hh hh1 + have ha0 := valid_pos ha + have hma := (multiplier_pos hs ha).le + let A := retainedInterval w ell S i s r cap closed a (a+h) + let e := Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)) + by_cases hne : A.Nonempty + · have hlow := short_interval_lower_exponent hell hs ha0 (by linarith : a ≤ a+h) + (by linarith : a+h-a ≤ 1) hne + have herr := herror w hw r a (a+h) hr ha0 (by linarith) hlow + have hlog := (bin_log_width_bounds ha0 (show a ≤ a+h by linarith)).2 + have hraw : closedMass w r a (a+h) ≤ h/(a+1)+C*e := by + rw [add_sub_cancel_left] at hlog + linarith [(abs_le.mp herr).2] + calc + _ ≤ multiplier i s a*closedMass w r a (a+h) := retained_tilt_le_multiplier (hw₀.trans_le hw) hs ha (by linarith) + _ ≤ multiplier i s a*(h/(a+1)+C*e) := mul_le_mul_of_nonneg_left hraw hma + _ = _ := by + unfold multiplier W + dsimp only [e] + field_simp [hh.ne',ha0.ne',(weight_pos hs).ne'] + · have hempty : A = ∅ := Finset.not_nonempty_iff_eq_empty.mp hne + change (∑ p ∈ A,_) ≤ _ + rw [hempty,Finset.sum_empty] + have hW := (W_pos ha0).le + have hratio := (div_pos (weight_pos ha) (weight_pos hs)).le + positivity + +variable {w ell S : ℝ} {start : Node} + +theorem actual_conditional_bin : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → + ∀ g : History w ell S start, ∀ a h : ℝ, Valid g.node.side.flip a → 0 < h → h ≤ 1 → + chain w ell S start (some g) (ActualPrimeBins.liveBin a (a+h)) ≤ + ENNReal.ofReal ((1+C*(a+1)*Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))/h)* + h*W a*(weight g.node.side.flip a/weight g.node.side g.node.ratio)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hbound⟩ := retained_conditional_bin + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw ell S start hell hr hs g a h ha hh hh1 + have hv := terminal_valid hs g.admissible + have hg := terminal_gap_positive (show 0 ≤ ell by linarith) hr hs g.admissible + have hsubset : ActualPrimeBins.liveBin a (a+h) ⊆ (closedLiveBin (w:=w) (ell:=ell) (S:=S) (start:=start) a (a+h)) := by + intro p hp + cases p with + | none => exact False.elim hp + | some p => exact ⟨hp.1,hp.2.le⟩ + exact (measure_mono hsubset).trans ((chain_interval_le_tilt g hv a (a+h)).trans + (ENNReal.ofReal_le_ofReal (hbound w hw ell S g.node.side g.node.ratio g.node.gap g.node.cutoff a h g.node.closed + hell hg hv ha hh hh1))) + +end NumberTheoryLean.ConditionalPrimeBins + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/CrossingPrimeBin.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/CrossingPrimeBin.lean new file mode 100644 index 0000000000000000000000000000000000000000..2a14db916d7aa06a66366f4e9fd272bd685e5e6e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/CrossingPrimeBin.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RepeatedWordData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CrossingPrimeBin +open FinitePathGeometry PrimeHistories PrimeTiltGeometry RepeatedWordData CandidateTerminalGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open IsolatedBinGeometry MarkedPrefixTools +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def isolatedAlpha (theta T : ℝ) : ℝ := theta/(10*(T+1)) + +theorem isolated_alpha_bounds {theta T : ℝ} (htheta : 0 < theta) (hT : 1 ≤ T) : + 0 < isolatedAlpha theta T ∧ isolatedAlpha theta T ≤ theta := by + unfold isolatedAlpha + refine ⟨div_pos htheta (by linarith),?_⟩ + exact div_le_self htheta.le (by linarith) + +theorem crossing_exponent_room {theta T B r s x h : ℝ} (htheta : 0 < theta) (hT : 1 ≤ T) + (hB : 0 < B) (hx : 0 < x) (hs : (1:ℝ)/2 ≤ s) (hsT : s ≤ T) + (he : r=s*x) (hlo : theta*B/3 < r) (hhi : r ≤ theta*B) + (hh : h ≤ isolatedAlpha theta T*B) : + isolatedAlpha theta T*B+h ≤ x ∧ x+h ≤ (4*theta)*B := by + have ha := isolated_alpha_bounds htheta hT + have hA : 0 ≤ isolatedAlpha theta T*B := mul_nonneg ha.1.le hB.le + have hEq : 10*(isolatedAlpha theta T*B)*(T+1)=theta*B := by + unfold isolatedAlpha + field_simp [show T+1 ≠ 0 by linarith] + have hlo' : 2*(isolatedAlpha theta T*B) ≤ x := by + by_contra! hn + have hm := mul_lt_mul_of_pos_right hn (by linarith : 0 < T) + have hr : r ≤ x*T := by rw [he]; nlinarith + nlinarith + have hhi' : x ≤ 2*(theta*B) := by rw [he] at hhi; nlinarith + have hAB : isolatedAlpha theta T*B ≤ theta*B := mul_le_mul_of_nonneg_right ha.2 hB.le + exact ⟨by linarith,by nlinarith⟩ + +theorem actual_crossing_bin {w top xi ell S theta T B : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hell : 1 ≤ ell) + (htheta : 0 < theta) (hT : 1 ≤ T) (hB : 0 < B) (z : Node) + (hs : Valid z.side z.ratio) (hcap : w^z.cutoff=top) + (h : History w ell S z) (hne : h.primes ≠ []) + (hlo : theta*B/3 < h.node.gap) (hhi : h.node.gap ≤ theta*B) (hbound : h.node.ratio ≤ T) + (hwidth : xi/Real.log w ≤ isolatedAlpha theta T*B) : + isolatedBin w top xi B (isolatedAlpha theta T) (4*theta) + (label (zero_lt_one.trans hw) htop hxi (h.primes.getLastD 0)) := by + have hx := history_nonempty_cutoff_gt hw h hne + have hx0 : 0 < h.node.cutoff := by linarith + have hvalid : Valid h.node.side h.node.ratio := terminal_valid hs h.admissible + have hslo : (1:ℝ)/2 ≤ h.node.ratio := by + cases he : h.node.side <;> rw [he] at hvalid <;> dsimp [Valid] at hvalid <;> linarith + have hratio := terminal_ratio_div_cutoff w z h.primes hne hx0.ne' + change h.node.ratio=h.node.gap/h.node.cutoff at hratio + have hgap : h.node.gap=h.node.ratio*h.node.cutoff := ((eq_div_iff hx0.ne').mp hratio).symm + have hroom := crossing_exponent_room htheta hT hB hx0 hslo hbound hgap hlo hhi hwidth + have hl : h.primes.getLastD 0 ∈ h.primes := history_last_mem h hne + have hsrc := ActualRepeatedBinStep.history_source_primes hw htop hell hcap h _ hl + have hcut : h.node.cutoff=primeExponent w (h.primes.getLastD 0) := terminal_lastD w z h.primes hne + apply whole_bin_of_exponent_band hw htop hxi hsrc + · rw [← hcut]; exact hroom.1 + · rw [← hcut]; exact hroom.2 +end NumberTheoryLean.CrossingPrimeBin + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/DirichletZeroFree.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/DirichletZeroFree.lean new file mode 100644 index 0000000000000000000000000000000000000000..a16c6f2ef53c2f4bdb9455e040ab340897f88eda --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/DirichletZeroFree.lean @@ -0,0 +1,56 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PrimitiveTransfer + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz + +lemma modulusHeight_mono {m q : ℕ} [NeZero m] [NeZero q] (hmq : m ≤ q) (t : ℝ) : + modulusHeight m t ≤ modulusHeight q t := by + have h : Real.log (m:ℝ) ≤ Real.log (q:ℝ) := + Real.log_le_log (by exact_mod_cast NeZero.pos m) (by exact_mod_cast hmq) + unfold modulusHeight + linarith + +theorem exists_nonprincipal_zero_free_region : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi ≠ 1 → ∀ s : ℂ, 1-c/(modulusHeight q s.im)^2 ≤ s.re → + DirichletCharacter.LFunction chi s ≠ 0 := by + obtain ⟨cp,hcp,hprimitive⟩ := exists_primitive_zero_free_region + let c : ℝ := min cp (1/4) + have hc : 0 < c := lt_min hcp (by norm_num) + have hcc : c ≤ cp := min_le_left _ _ + have hc4 : c ≤ 1/4 := min_le_right _ _ + refine ⟨c,hc,?_⟩ + intro q _ chi hchi s hs + let _ : NeZero chi.conductor := ⟨chi.conductor_ne_zero⟩ + have hH := modulusHeight_ge_one q s.im + have hHsq : 1 ≤ (modulusHeight q s.im)^2 := by nlinarith + have hfrac : c/(modulusHeight q s.im)^2 ≤ c := by + apply (div_le_iff₀ (by positivity : 0 < (modulusHeight q s.im)^2)).mpr + nlinarith + have hrep : 0 < s.re := by linarith + apply (LFunction_primitive_ne_zero_iff chi hchi hrep).mpr + have hcond : chi.conductor ≤ q := Nat.le_of_dvd (NeZero.pos q) chi.conductor_dvd_level + have hHm := modulusHeight_ge_one chi.conductor s.im + have hmono := modulusHeight_mono hcond s.im + have hpow : (modulusHeight chi.conductor s.im)^2 ≤ (modulusHeight q s.im)^2 := by nlinarith + have hfrac' : c/(modulusHeight q s.im)^2 ≤ cp/(modulusHeight chi.conductor s.im)^2 := by + calc + _ ≤ cp/(modulusHeight q s.im)^2 := div_le_div_of_nonneg_right hcc (sq_nonneg _) + _ ≤ _ := div_le_div_of_nonneg_left hcp.le (by positivity) hpow + apply hprimitive chi.conductor (conductor_ge_three chi hchi) chi.primitiveCharacter + chi.primitiveCharacter_isPrimitive (primitiveCharacter_ne_one chi hchi) s + linarith + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/DirichletZeroPenalty.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/DirichletZeroPenalty.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba6a96e3a5ad81c766ac2777309b4a52f5184c5d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/DirichletZeroPenalty.lean @@ -0,0 +1,351 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.LocalZeroLogDerivative + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz + +noncomputable def dirichletCenter (t : ℝ) : ℂ := 3 + (t : ℂ) * Complex.I +noncomputable def dirichletDiskPoint (t : ℝ) (w : ℂ) : ℂ := dirichletCenter t + (5/2 : ℂ)*w +noncomputable def normalizedDirichlet {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (t : ℝ) (w : ℂ) : ℂ := + DirichletCharacter.LFunction chi (dirichletDiskPoint t w) / + DirichletCharacter.LFunction chi (dirichletCenter t) +noncomputable def dirichletDiskEnvelope (q : ℕ) (t : ℝ) : ℝ := + 4 * absoluteZetaTwo * (|t|+6) * (q : ℝ)^(1/2:ℝ) + +@[simp] theorem dirichletCenter_re (t : ℝ) : (dirichletCenter t).re = 3 := by + simp [dirichletCenter] +@[simp] theorem dirichletDiskPoint_re (t : ℝ) (w : ℂ) : + (dirichletDiskPoint t w).re = 3 + (5/2:ℝ)*w.re := by + simp [dirichletDiskPoint] + +theorem dirichletDiskPoint_half_strip (t : ℝ) {w : ℂ} (hw : ‖w‖ ≤ 1) : + 1/2 ≤ (dirichletDiskPoint t w).re := by + have h := (abs_le.mp ((Complex.abs_re_le_norm w).trans hw)).1 + rw [dirichletDiskPoint_re] + linarith + +theorem dirichletDiskPoint_norm (t : ℝ) {w : ℂ} (hw : ‖w‖ ≤ 1) : + ‖dirichletDiskPoint t w‖ ≤ |t|+6 := by + have hc : ‖dirichletCenter t‖ ≤ 3+|t| := by + simpa [dirichletCenter, norm_mul] using + (norm_add_le (3 : ℂ) ((t : ℂ)*Complex.I)) + have h := norm_add_le (dirichletCenter t) ((5/2 : ℂ)*w) + have hn : ‖(5/2:ℂ)*w‖ = (5/2:ℝ)*‖w‖ := by rw [norm_mul]; norm_num + rw [hn] at h + change ‖dirichletDiskPoint t w‖ ≤ _ at h + linarith + +theorem normalizedDirichlet_zero {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (t : ℝ) : normalizedDirichlet chi t 0 = 1 := by + unfold normalizedDirichlet dirichletDiskPoint + simp only [mul_zero, add_zero] + exact div_self (LFunction_ne_zero_right chi (by simp)) + +theorem normalizedDirichlet_analytic {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) (t : ℝ) (w : ℂ) : + AnalyticAt ℂ (normalizedDirichlet chi t) w := by + have hL := DirichletCharacter.differentiable_LFunction hchi + have hd : Differentiable ℂ (normalizedDirichlet chi t) := by + unfold normalizedDirichlet dirichletDiskPoint + fun_prop + exact hd.analyticAt w + +theorem normalizedDirichlet_bound {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) (t : ℝ) {w : ℂ} (hw : ‖w‖ ≤ 1) : + ‖normalizedDirichlet chi t w‖ ≤ dirichletDiskEnvelope q t := by + have hu := norm_LFunction_half_strip chi hchi (dirichletDiskPoint_half_strip t hw) + have hi := norm_inv_LFunction_le_absoluteZetaTwo chi (s := dirichletCenter t) (by norm_num) + have hZ : 0 ≤ absoluteZetaTwo := zero_le_one.trans one_le_absoluteZetaTwo + unfold normalizedDirichlet + rw [div_eq_mul_inv, norm_mul] + calc + _ ≤ (4 * ‖dirichletDiskPoint t w‖ * (q : ℝ)^(1/2:ℝ)) * absoluteZetaTwo := + mul_le_mul hu hi (norm_nonneg _) (by positivity) + _ ≤ (4 * (|t|+6) * (q : ℝ)^(1/2:ℝ)) * absoluteZetaTwo := by + gcongr + exact dirichletDiskPoint_norm t hw + _ = dirichletDiskEnvelope q t := by unfold dirichletDiskEnvelope; ring + +theorem dirichletDiskEnvelope_gt_one (q : ℕ) [NeZero q] (t : ℝ) : + 1 < dirichletDiskEnvelope q t := by + have hq : (1 : ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hp : (1 : ℝ) ≤ (q : ℝ)^(1/2:ℝ) := Real.one_le_rpow hq (by norm_num) + have hZ := one_le_absoluteZetaTwo + have ht := abs_nonneg t + unfold dirichletDiskEnvelope + have h1 : 24 ≤ 4 * absoluteZetaTwo * (|t|+6) := by nlinarith + have h2 := mul_le_mul_of_nonneg_left hp (by positivity : 0 ≤ 4 * absoluteZetaTwo * (|t|+6)) + nlinarith + +theorem normalizedDirichlet_zero_re_lt {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) (t : ℝ) {w : ℂ} + (hw : normalizedDirichlet chi t w = 0) : w.re < -4/5 := by + have hn := LFunction_ne_zero_right chi (s := dirichletCenter t) (by simp) + have hz : DirichletCharacter.LFunction chi (dirichletDiskPoint t w) = 0 := + (div_eq_zero_iff.mp hw).resolve_right hn + by_contra! h + have hr : 1 ≤ (dirichletDiskPoint t w).re := by rw [dirichletDiskPoint_re]; linarith + exact DirichletCharacter.LFunction_ne_zero_of_one_le_re chi (Or.inl hchi) hr hz + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +theorem log_dirichletDiskEnvelope_bound (q : ℕ) [NeZero q] (t : ℝ) : + Real.log (dirichletDiskEnvelope q t) ≤ + (Real.log (4 * absoluteZetaTwo)+1) * (Real.log (q : ℝ)+Real.log (|t|+6)) := by + have hZ := one_le_absoluteZetaTwo + have hZp : 0 < 4 * absoluteZetaTwo := by linarith + have ht := abs_nonneg t + have htp : 0 < |t|+6 := by linarith + have hq : (1 : ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hqp : (0 : ℝ) < q := by linarith + have hlogq := Real.log_nonneg hq + have hlogZ : 0 ≤ Real.log (4 * absoluteZetaTwo) := Real.log_nonneg (by linarith) + have hlogt : 1 ≤ Real.log (|t|+6) := + ((Real.lt_log_iff_exp_lt htp).mpr (Real.exp_one_lt_three.trans (by linarith))).le + have heq : Real.log (dirichletDiskEnvelope q t) = + Real.log (4 * absoluteZetaTwo)+Real.log (|t|+6)+(1/2)*Real.log (q : ℝ) := by + unfold dirichletDiskEnvelope + rw [Real.log_mul (mul_pos hZp htp).ne' (Real.rpow_pos_of_pos hqp _).ne', + Real.log_mul hZp.ne' htp.ne', Real.log_rpow hqp] + rw [heq] + nlinarith [mul_nonneg hlogZ hlogq, mul_le_mul_of_nonneg_left hlogt hlogZ] + +theorem normalizedDirichlet_log_derivative {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) (t : ℝ) (w : ℂ) + (hw : DirichletCharacter.LFunction chi (dirichletDiskPoint t w) ≠ 0) : + deriv (normalizedDirichlet chi t) w / normalizedDirichlet chi t w = + (5/2:ℂ) * (deriv (DirichletCharacter.LFunction chi) (dirichletDiskPoint t w) / + DirichletCharacter.LFunction chi (dirichletDiskPoint t w)) := by + have hn := LFunction_ne_zero_right chi (s := dirichletCenter t) (by simp) + have hp : HasDerivAt (dirichletDiskPoint t) (5/2:ℂ) w := by + simpa only [dirichletDiskPoint, id_eq, mul_one] using! (((hasDerivAt_id w).const_mul (5/2:ℂ)).const_add (dirichletCenter t)) + have hd := (((DirichletCharacter.differentiable_LFunction hchi).differentiableAt.hasDerivAt).comp w hp).div_const + (DirichletCharacter.LFunction chi (dirichletCenter t)) + change HasDerivAt (normalizedDirichlet chi t) + ((deriv (DirichletCharacter.LFunction chi) (dirichletDiskPoint t w) * (5/2:ℂ)) / + DirichletCharacter.LFunction chi (dirichletCenter t)) w at hd + rw [hd.deriv] + unfold normalizedDirichlet + field_simp + +theorem uniform_dirichlet_local_log_derivative : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi ≠ 1 → ∀ t : ℝ, ∃ S : Finset ℂ, + (∀ rho, rho ∈ S ↔ ‖rho‖ ≤ 19/20 ∧ + DirichletCharacter.LFunction chi (dirichletDiskPoint t rho) = 0) ∧ + (∀ rho ∈ S, rho.re < -4/5) ∧ + ∀ w : ℂ, ‖w‖ ≤ 17/20 → + DirichletCharacter.LFunction chi (dirichletDiskPoint t w) ≠ 0 → + ‖(5/2:ℂ) * (deriv (DirichletCharacter.LFunction chi) (dirichletDiskPoint t w) / + DirichletCharacter.LFunction chi (dirichletDiskPoint t w)) - + ∑ rho ∈ S, (analyticOrderAt (normalizedDirichlet chi t) rho).toNat / (w-rho)‖ ≤ + C * (Real.log (q : ℝ)+Real.log (|t|+6)) := by + classical + obtain ⟨C, hC, hlocal⟩ := exists_local_zero_log_derivative_constant + have hZ := one_le_absoluteZetaTwo + have hlogZ : 0 ≤ Real.log (4 * absoluteZetaTwo) := Real.log_nonneg (by linarith) + refine ⟨C * (Real.log (4 * absoluteZetaTwo)+1), mul_pos hC (by linarith), ?_⟩ + intro q _ chi hchi t + have hn := LFunction_ne_zero_right chi (s := dirichletCenter t) (by simp) + obtain ⟨S, hS, hb⟩ := hlocal (dirichletDiskEnvelope q t) (dirichletDiskEnvelope_gt_one q t) + (normalizedDirichlet chi t) (fun w _ => normalizedDirichlet_analytic chi hchi t w) + (normalizedDirichlet_zero chi t) (fun w hw => normalizedDirichlet_bound chi hchi t + (by simpa only [Metric.mem_closedBall, dist_zero_right] using hw)) + have hzeros (rho : ℂ) : normalizedDirichlet chi t rho = 0 ↔ + DirichletCharacter.LFunction chi (dirichletDiskPoint t rho) = 0 := by + unfold normalizedDirichlet + exact div_eq_zero_iff.trans (or_iff_left hn) + refine ⟨S, fun rho => (hS rho).trans (and_congr_right fun _ => hzeros rho), ?_, ?_⟩ + · intro rho hr + exact normalizedDirichlet_zero_re_lt chi hchi t ((hS rho).mp hr).2 + · intro w hw hne + have h := hb w hw (fun hz => hne ((hzeros w).mp hz)) + rw [normalizedDirichlet_log_derivative chi hchi t w hne] at h + apply h.trans + calc + _ ≤ C * ((Real.log (4 * absoluteZetaTwo)+1) * (Real.log (q : ℝ)+Real.log (|t|+6))) := + mul_le_mul_of_nonneg_left (log_dirichletDiskEnvelope_bound q t) hC.le + _ = _ := by ring + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +@[simp] theorem dirichletDiskPoint_ofReal (sigma t : ℝ) : + dirichletDiskPoint t ((2/5*(sigma-3):ℝ):ℂ) = (sigma:ℂ)+(t:ℂ)*Complex.I := by + unfold dirichletDiskPoint dirichletCenter + push_cast + ring + +lemma real_zero_term_nonneg {w rho : ℂ} (m : ℕ) + (h : rho.re ≤ w.re) : 0 ≤ (((m : ℂ) / (w-rho)).re) := by + rw [Complex.div_re] + simp only [Complex.natCast_re, Complex.natCast_im, zero_mul, zero_div, add_zero, + Complex.sub_re] + exact div_nonneg (mul_nonneg (Nat.cast_nonneg _) (sub_nonneg.mpr h)) (Complex.normSq_nonneg _) + +theorem uniform_neg_real_log_derivative : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi ≠ 1 → ∀ sigma t : ℝ, 1 < sigma → sigma ≤ 2 → + (-deriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I) / + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I)).re ≤ + C * (Real.log (q:ℝ)+Real.log (|t|+6)) := by + classical + obtain ⟨C, hC, hlocal⟩ := uniform_dirichlet_local_log_derivative + refine ⟨C, hC, ?_⟩ + intro q _ chi hchi sigma t hs hs2 + obtain ⟨S, _, hSre, hb⟩ := hlocal q chi hchi t + let w : ℂ := ((2/5*(sigma-3):ℝ):ℂ) + have hw : ‖w‖ ≤ 17/20 := by + change ‖((2/5*(sigma-3):ℝ):ℂ)‖ ≤ _ + rw [Complex.norm_real, Real.norm_eq_abs] + exact abs_le.mpr ⟨by linarith, by linarith⟩ + have hwre : -4/5 < w.re := by + dsimp only [w] + simp only [Complex.ofReal_re] + linarith + have hnonzero : DirichletCharacter.LFunction chi (dirichletDiskPoint t w) ≠ 0 := by + rw [dirichletDiskPoint_ofReal] + exact LFunction_ne_zero_right chi (by simpa using hs) + have h := hb w hw hnonzero + have hsum : 0 ≤ (∑ rho ∈ S, (analyticOrderAt (normalizedDirichlet chi t) rho).toNat / (w-rho) : ℂ).re := by + rw [Complex.re_sum] + exact Finset.sum_nonneg (fun rho hr => real_zero_term_nonneg _ ((hSre rho hr).le.trans hwre.le)) + have herror := (Complex.re_le_norm (-( + (5/2:ℂ) * (deriv (DirichletCharacter.LFunction chi) (dirichletDiskPoint t w) / + DirichletCharacter.LFunction chi (dirichletDiskPoint t w)) - + ∑ rho ∈ S, (analyticOrderAt (normalizedDirichlet chi t) rho).toNat / (w-rho)))).trans + (by simpa only [norm_neg] using h) + have hscale (a : ℂ) : ((5/2:ℂ)*a).re = (5/2:ℝ)*a.re := by + norm_num [Complex.mul_re] + rw [Complex.neg_re, Complex.sub_re, hscale] at herror + have hq : (1:ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hpos : 0 ≤ C * (Real.log (q:ℝ)+Real.log (|t|+6)) := + mul_nonneg hC.le (add_nonneg (Real.log_nonneg hq) (Real.log_nonneg (by have := abs_nonneg t; linarith))) + rw [show (sigma:ℂ)+(t:ℂ)*Complex.I = dirichletDiskPoint t w from (dirichletDiskPoint_ofReal sigma t).symm] + rw [neg_div, Complex.neg_re] + nlinarith + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +lemma normalizedDirichlet_zero_order_pos {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) (t : ℝ) {rho : ℂ} + (hr : ‖rho‖ ≤ 19/20) (hz : normalizedDirichlet chi t rho = 0) : + 1 ≤ (analyticOrderAt (normalizedDirichlet chi t) rho).toNat := by + have hf : ∀ w ∈ Metric.closedBall (0:ℂ) 1, AnalyticAt ℂ (normalizedDirichlet chi t) w := + fun w _ => normalizedDirichlet_analytic chi hchi t w + have hfne : normalizedDirichlet chi t 0 ≠ 0 := by rw [normalizedDirichlet_zero]; norm_num + have hmem : rho ∈ _root_.Erdos970.zerosetKfR (19/20) (by norm_num) (normalizedDirichlet chi t) := + ⟨by simpa only [Metric.mem_closedBall, dist_zero_right] using hr, hz⟩ + have ht := _root_.Erdos970.lem_m_rho_is_nat (39/40) (19/20) (by norm_num) (by norm_num) + (normalizedDirichlet chi t) hf hfne (by norm_num) rho hmem + have hge := _root_.Erdos970.lem_m_rho_ge_1 (39/40) (19/20) (by norm_num) (by norm_num) + (normalizedDirichlet chi t) hf hfne (by norm_num) rho hmem + simpa using ENat.toNat_le_toNat hge ht + +theorem uniform_zero_penalty : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi ≠ 1 → ∀ sigma beta t : ℝ, + 1 < sigma → sigma ≤ 2 → 3/4 ≤ beta → beta < 1 → + DirichletCharacter.LFunction chi ((beta:ℂ)+(t:ℂ)*Complex.I) = 0 → + (-deriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I) / + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I)).re ≤ + C * (Real.log (q:ℝ)+Real.log (|t|+6)) - 1/(sigma-beta) := by + classical + obtain ⟨C, hC, hlocal⟩ := uniform_dirichlet_local_log_derivative + refine ⟨C, hC, ?_⟩ + intro q _ chi hchi sigma beta t hs hs2 hb34 hb1 hzero + obtain ⟨S, hS, hSre, hbound⟩ := hlocal q chi hchi t + let w : ℂ := ((2/5*(sigma-3):ℝ):ℂ) + let rho0 : ℂ := ((2/5*(beta-3):ℝ):ℂ) + have hw : ‖w‖ ≤ 17/20 := by + change ‖((2/5*(sigma-3):ℝ):ℂ)‖ ≤ _ + rw [Complex.norm_real, Real.norm_eq_abs] + exact abs_le.mpr ⟨by linarith, by linarith⟩ + have hr : ‖rho0‖ ≤ 19/20 := by + change ‖((2/5*(beta-3):ℝ):ℂ)‖ ≤ _ + rw [Complex.norm_real, Real.norm_eq_abs] + exact abs_le.mpr ⟨by linarith, by linarith⟩ + have hwre : -4/5 < w.re := by + dsimp only [w] + simp only [Complex.ofReal_re] + linarith + have hrL : DirichletCharacter.LFunction chi (dirichletDiskPoint t rho0) = 0 := by + rw [dirichletDiskPoint_ofReal] + exact hzero + have hrmem : rho0 ∈ S := (hS rho0).mpr ⟨hr, hrL⟩ + have hrNorm : normalizedDirichlet chi t rho0 = 0 := by + unfold normalizedDirichlet + rw [hrL, zero_div] + have hm := normalizedDirichlet_zero_order_pos chi hchi t hr hrNorm + have hden : 0 < sigma-beta := by linarith + have hsub : w-rho0 = ((2/5*(sigma-beta):ℝ):ℂ) := by + dsimp only [w, rho0] + push_cast + ring + have hterm : (5/2:ℝ)/(sigma-beta) ≤ + (((analyticOrderAt (normalizedDirichlet chi t) rho0).toNat:ℂ)/(w-rho0)).re := by + rw [hsub] + rw [show ((analyticOrderAt (normalizedDirichlet chi t) rho0).toNat:ℂ) = + (((analyticOrderAt (normalizedDirichlet chi t) rho0).toNat:ℝ):ℂ) by simp] + rw [← Complex.ofReal_div, Complex.ofReal_re] + calc + _ = 1/(2/5*(sigma-beta)) := by field_simp + _ ≤ _ := div_le_div_of_nonneg_right (by exact_mod_cast hm) (by positivity) + have hsum : (5/2:ℝ)/(sigma-beta) ≤ + (∑ rho ∈ S, (analyticOrderAt (normalizedDirichlet chi t) rho).toNat / (w-rho):ℂ).re := by + rw [Complex.re_sum] + apply hterm.trans + exact Finset.single_le_sum (fun rho hr => real_zero_term_nonneg (analyticOrderAt (normalizedDirichlet chi t) rho).toNat ((hSre rho hr).le.trans hwre.le)) hrmem + have hn : DirichletCharacter.LFunction chi (dirichletDiskPoint t w) ≠ 0 := by + rw [dirichletDiskPoint_ofReal] + exact LFunction_ne_zero_right chi (by simpa using hs) + have h := hbound w hw hn + have herror := (Complex.re_le_norm (-( + (5/2:ℂ) * (deriv (DirichletCharacter.LFunction chi) (dirichletDiskPoint t w) / + DirichletCharacter.LFunction chi (dirichletDiskPoint t w)) - + ∑ rho ∈ S, (analyticOrderAt (normalizedDirichlet chi t) rho).toNat / (w-rho)))).trans + (by simpa only [norm_neg] using h) + have hscale (a:ℂ) : ((5/2:ℂ)*a).re = (5/2:ℝ)*a.re := by norm_num [Complex.mul_re] + rw [Complex.neg_re, Complex.sub_re, hscale] at herror + have hq : (1:ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hpos : 0 ≤ C*(Real.log (q:ℝ)+Real.log (|t|+6)) := + mul_nonneg hC.le (add_nonneg (Real.log_nonneg hq) (Real.log_nonneg (by have := abs_nonneg t; linarith))) + rw [show (sigma:ℂ)+(t:ℂ)*Complex.I = dirichletDiskPoint t w from (dirichletDiskPoint_ofReal sigma t).symm, + neg_div, Complex.neg_re] + rw [div_eq_mul_inv] at hsum + rw [one_div] + nlinarith only [herror, hsum, hpos] + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/FrozenPrimeGroup.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/FrozenPrimeGroup.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e1864ae405510bc93965df54dd61161cdaf3871 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/FrozenPrimeGroup.lean @@ -0,0 +1,70 @@ +import OAI.NumberTheory.Jacobsthal.Paths.MovingStopMargins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.FrozenPrimeGroup +open _root_.Finset _root_.Erdos970.Finset FiniteFirstTag ActualSourceTags ActualBinOwners +open ErdosInversePrimeBin ErdosInverseAlignment ErdosPrimeInputs.PrimePrefixMass +open StoppedVertexHistory +attribute [local instance] Classical.propDecidable + +noncomputable def frozenGroup (R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) (pre tail : List ℕ) : + Finset (List ℕ) := ((primeBin R xi).filter (aligns a q)).image (fun p => pre++p::tail) + +theorem replacement_injective (pre tail : List ℕ) : Function.Injective (fun p : ℕ => pre++p::tail) := by + intro p q hpq + exact (List.cons.inj (List.append_cancel_left hpq)).1 + +theorem mem_frozenGroup (R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) (pre tail ps : List ℕ) : + ps ∈ frozenGroup R xi a q pre tail ↔ + ∃ p ∈ primeBin R xi,aligns a q p ∧ ps=pre++p::tail := by + constructor + · intro h + obtain ⟨p,hp,he⟩ := Finset.mem_image.mp h + obtain ⟨hb,ha⟩ := Finset.mem_filter.mp hp + exact ⟨p,hb,ha,he.symm⟩ + · rintro ⟨p,hp,ha,rfl⟩ + exact Finset.mem_image.mpr ⟨p,Finset.mem_filter.mpr ⟨hp,ha⟩,rfl⟩ + +theorem frozenGroup_card (R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) (pre tail : List ℕ) : + (frozenGroup R xi a q pre tail).card=((primeBin R xi).filter (aligns a q)).card := by + exact Finset.card_image_of_injective _ (replacement_injective pre tail) + +theorem frozenGroup_original_mass (R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) (pre tail : List ℕ) : + (∑ ps ∈ frozenGroup R xi a q pre tail,prefixWeight ps)= + ((pre.prod*tail.prod:ℕ):ℝ)⁻¹ * ∑ p ∈ (primeBin R xi).filter (aligns a q),(p:ℝ)⁻¹ := by + rw [frozenGroup,Finset.sum_image,Finset.mul_sum] + · apply Finset.sum_congr rfl + intro p _hp + rw [prefixWeight_product,TagBelowStopWindow.replacement_product,Nat.cast_mul,mul_inv_rev] + · intro p _ q _ hpq + exact replacement_injective pre tail hpq + +theorem frozenGroup_owner_card (Y w Cs eta R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) (pre tail : List ℕ) + (hY : 0 ≤ Y) (hw : 1 < w) (ho : owner Y w Cs eta R xi a = some q) : + (1-eta)*((primeBin R xi).card:ℝ) ≤ (frozenGroup R xi a q pre tail).card := by + rw [frozenGroup_card] + exact (actual_owner_witness hY hw a ho).2 + +theorem frozenGroup_product_sum (R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) (pre tail : List ℕ) + (F : ℕ → ℝ) : + (∑ ps ∈ frozenGroup R xi a q pre tail,F ps.prod)= + ∑ p ∈ (primeBin R xi).filter (aligns a q),F (p*(pre.prod*tail.prod)) := by + rw [frozenGroup,Finset.sum_image] + · apply Finset.sum_congr rfl + intro p _hp + rw [TagBelowStopWindow.replacement_product] + · intro p _ q _ hpq + exact replacement_injective pre tail hpq +end NumberTheoryLean.FrozenPrimeGroup + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/FullHistoryPrimeOccupation.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/FullHistoryPrimeOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..92d289d85d436c8d92c7e3be01f24f7a28ec452b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/FullHistoryPrimeOccupation.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.SourceSelectedCompactOccupation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.FullHistoryPrimeOccupation + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling PersistentFailureFlag +open FiniteHistoryTransport ActualCoupledHistories SourceSelectedCompactOccupation +open PrimeCompactWeights PrimeFamilyOccupation ErdosPrimeInputs.PrimePrefixMass + +variable {w ell S B : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem prime_coordinate (mesh : ℝ) (N k : ℕ) (hk : k ≤ N) : + (sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N).map + (fun h => (h ⟨k,by simpa using hk⟩).1.1) = pathLaw w ell S start k := by + calc + _ = ((sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N).map + (fun h => h ⟨k,by simpa using hk⟩)).map (fun q => q.1.1) := by + exact (Measure.map_map + (f := fun h : Hist (FlagState (JointState w ell S start)) N => h ⟨k,Finset.mem_Iic.mpr hk⟩) + (g := fun q : FlagState (JointState w ell S start) => q.1.1) + (by fun_prop) (by fun_prop)).symm + _ = _ := by rw [sourceHistoryLaw_coordinate hw hell hS0 hS hr hs hsS mesh N k hk, + FlaggedSourceStart.sourceLaw_prime] + +noncomputable def fullListReward (w B : ℝ) {ell S : ℝ} (start : Node) + (F : List ℕ → ℝ) (N : ℕ) (h : Hist (FlagState (JointState w ell S start)) N) : ℝ≥0∞ := + ∑ j : Fin N, ENNReal.ofReal + (scaledWeight w B start (h ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩).1.1 * + listReward F (h ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩).1.1) + +theorem fullListReward_measurable (F : List ℕ → ℝ) (N : ℕ) : + Measurable (fullListReward w B (ell:=ell) (S:=S) start F N) := by + unfold fullListReward + apply Finset.measurable_sum + intro j _ + exact (measurable_of_countable (fun z : ChainState w ell S start => + ENNReal.ofReal (scaledWeight w B start z*listReward F z))).comp + ((measurable_fst.comp measurable_fst).comp (measurable_pi_apply _)) + +theorem fullListReward_integral (mesh : ℝ) (N : ℕ) (F : List ℕ → ℝ) : + (∫⁻ h,fullListReward w B start F N h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N) = + ∑ n ∈ range N, ∫⁻ z,ENNReal.ofReal (scaledWeight w B start z*listReward F z) + ∂pathLaw w ell S start n := by + unfold fullListReward + rw [lintegral_finsetSum] + · rw [← Fin.sum_univ_eq_sum_range] + apply Finset.sum_congr rfl + intro j _ + have hm : Measurable (fun z : ChainState w ell S start => + ENNReal.ofReal (scaledWeight w B start z*listReward F z)) := measurable_of_countable _ + rw [← prime_coordinate hw hell hS0 hS hr hs hsS mesh N j j.isLt.le, + lintegral_map hm (by exact (measurable_fst.comp measurable_fst).comp (measurable_pi_apply _))] + · intro j _ + exact (measurable_of_countable (fun z : ChainState w ell S start => + ENNReal.ofReal (scaledWeight w B start z*listReward F z))).comp + ((measurable_fst.comp measurable_fst).comp (measurable_pi_apply _)) + +theorem finite_family_full_history (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) + (mesh : ℝ) (F : List ℕ → ℝ) (hF : ∀ ps,allowed w ell S start ps → 0 ≤ F ps) : + (∫⁻ h,fullListReward w B start F (LowStateHorizon.sourceHorizon S B) h + ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh (LowStateHorizon.sourceHorizon S B)) = + ENNReal.ofReal (B^2*(∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps)) := by + rw [fullListReward_integral] + exact finite_nonnegative_original_occupation hw hell hS0 hS hr hs hsS hB hsize F hF + +end NumberTheoryLean.FullHistoryPrimeOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/FullPrimeEventFibres.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/FullPrimeEventFibres.lean new file mode 100644 index 0000000000000000000000000000000000000000..04a68d32653ebfba922951e8c80be8b835b8251b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/FullPrimeEventFibres.lean @@ -0,0 +1,91 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceBlockFibreBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosLargeHeightBlocks ErdosInversePrimeBin +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def actualBlockIndex (R theta : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 0 < R) (htheta : 0 < theta) (p : goodPrimes (primeBin R theta) H) : + Fin (blockCount C0 R theta H) := + Classical.choose (unique_original_prime_block C0 R theta H p.val hR htheta + (Finset.mem_filter.mp p.property).1).exists + +theorem actualBlockIndex_mem (R theta : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 0 < R) (htheta : 0 < theta) (p : goodPrimes (primeBin R theta) H) : + p.val ∈ blockPrimes C0 R theta H (actualBlockIndex R theta H C0 hR htheta p) := + Classical.choose_spec (unique_original_prime_block C0 R theta H p.val hR htheta + (Finset.mem_filter.mp p.property).1).exists + +theorem actualBlockIndex_eq_iff (R theta : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 0 < R) (htheta : 0 < theta) (p : goodPrimes (primeBin R theta) H) + (i : Fin (blockCount C0 R theta H)) : + actualBlockIndex R theta H C0 hR htheta p = i ↔ p.val ∈ blockPrimes C0 R theta H i := by + constructor + · intro he + rw [← he] + exact actualBlockIndex_mem R theta H C0 hR htheta p + · intro hi + exact (unique_original_prime_block C0 R theta H p.val hR htheta + (Finset.mem_filter.mp p.property).1).unique (actualBlockIndex_mem R theta H C0 hR htheta p) hi + +noncomputable def indexedFullPrimeEvent (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (E : ErdosLargePatternLaw.FullPattern w H → Prop) : Finset (goodPrimes P H) := + Finset.univ.filter (fun p => E (actualFullPattern P w H C0 hw hP hlarge p)) + +noncomputable def fullPrimeEvent (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (E : ErdosLargePatternLaw.FullPattern w H → Prop) : Finset ℕ := + (indexedFullPrimeEvent P w H C0 hw hP hlarge E).image Subtype.val + +theorem fullPrimeEvent_card (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (E : ErdosLargePatternLaw.FullPattern w H → Prop) : + (fullPrimeEvent P w H C0 hw hP hlarge E).card = (indexedFullPrimeEvent P w H C0 hw hP hlarge E).card := + Finset.card_image_of_injective _ Subtype.val_injective + +theorem fullPrimeEvent_card_fibres (R theta w : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 0 < R) (htheta : 0 < theta) (hw : 0 ≤ w) + (hP : ∀ p ∈ primeBin R theta,p.Prime) (hlarge : ∀ p ∈ primeBin R theta,w < (p : ℝ)) + (E : ErdosLargePatternLaw.FullPattern w H → Prop) : + (fullPrimeEvent (primeBin R theta) w H C0 hw hP hlarge E).card = + ∑ i : Fin (blockCount C0 R theta H),∑ v ∈ Finset.univ.filter E, + (blockPatternPrimes R theta w H C0 hw hP hlarge i v).card := by + let f (p : goodPrimes (primeBin R theta) H) := + (actualBlockIndex R theta H C0 hR htheta p,actualFullPattern (primeBin R theta) w H C0 hw hP hlarge p) + let S : Finset (Fin (blockCount C0 R theta H) × ErdosLargePatternLaw.FullPattern w H) := + Finset.univ.product (Finset.univ.filter E) + have hmaps : (indexedFullPrimeEvent (primeBin R theta) w H C0 hw hP hlarge E : Set _).MapsTo f (S : Set _) := by + intro p hp + exact Finset.mem_product.mpr ⟨Finset.mem_univ _,Finset.mem_filter.mpr + ⟨Finset.mem_univ _,(Finset.mem_filter.mp hp).2⟩⟩ + rw [fullPrimeEvent_card,Finset.card_eq_sum_card_fiberwise hmaps] + simp only [S,Finset.product_eq_sprod,Finset.sum_product] + apply Finset.sum_congr rfl + intro i _hi + apply Finset.sum_congr rfl + intro v hv + congr 1 + ext p + simp only [indexedFullPrimeEvent,blockPatternPrimes,Finset.mem_filter,Finset.mem_univ,true_and,f,Prod.mk.injEq, + actualBlockIndex_eq_iff] + constructor + · exact fun h => h.2 + · intro h + exact ⟨h.2.symm ▸ (Finset.mem_filter.mp hv).2,h⟩ + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/GuardedHardPrimeSets.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/GuardedHardPrimeSets.lean new file mode 100644 index 0000000000000000000000000000000000000000..96c592221030bc6b5117c35d6a731a5302079523 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/GuardedHardPrimeSets.lean @@ -0,0 +1,494 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FullEndpointData +import OAI.NumberTheory.Jacobsthal.Estimates.FullPatternSurvivors +import OAI.NumberTheory.Jacobsthal.Estimates.SourceFullPatternDomination +import OAI.NumberTheory.Jacobsthal.Probability.FullPatternVariance +import OAI.NumberTheory.Jacobsthal.Probability.StableModelMoments + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosVarianceWeighted +open ErdosInverseCells +attribute [local instance] Classical.propDecidable + +theorem subset_card_of_fraction (A P : Finset ℕ) (hAP : A ⊆ P) (rho : ℝ) + (hfrac : (A.card : ℝ)/(P.card : ℝ) ≤ rho) : (A.card : ℝ) ≤ rho*(P.card : ℝ) := by + by_cases hP : P.card = 0 + · have hP0 := Finset.card_eq_zero.mp hP + have hA0 : A = ∅ := Finset.eq_empty_iff_forall_notMem.mpr (fun a ha => by simpa [hP0] using hAP ha) + simp only [hA0,Finset.card_empty,Nat.cast_zero,hP,mul_zero,le_refl] + · have hPC : (0 : ℝ) < P.card := by exact_mod_cast Nat.pos_of_ne_zero hP + exact (div_le_iff₀ hPC).mp hfrac + +theorem harmonic_transfer (A P : Finset ℕ) (hAP : A ⊆ P) (R theta rho : ℝ) + (hR : 0 < R) (htheta : 0 ≤ theta) (hrho : 0 ≤ rho) + (hbin : ∀ p ∈ P,R < (p : ℝ) ∧ (p : ℝ) ≤ (1+theta)*R) + (hcard : (A.card : ℝ) ≤ rho*(P.card : ℝ)) : + harmonicMass A ≤ rho*(1+theta)*harmonicMass P := by + have htop : 0 < (1+theta)*R := by positivity + have hupper : harmonicMass A ≤ (A.card : ℝ)/R := by + calc + _ ≤ ∑ _p ∈ A,R⁻¹ := by + apply Finset.sum_le_sum + intro p hp + have h := (hbin p (hAP hp)).1 + exact (inv_le_inv₀ (hR.trans h) hR).mpr h.le + _ = _ := by rw [Finset.sum_const,nsmul_eq_mul];ring + have hlower : (P.card : ℝ)/((1+theta)*R) ≤ harmonicMass P := by + calc + _ = ∑ _p ∈ P,((1+theta)*R)⁻¹ := by rw [Finset.sum_const,nsmul_eq_mul];ring + _ ≤ _ := by + apply Finset.sum_le_sum + intro p hp + have h := hbin p hp + exact (inv_le_inv₀ htop (hR.trans h.1)).mpr h.2 + calc + _ ≤ (A.card : ℝ)/R := hupper + _ ≤ (rho*(P.card : ℝ))/R := div_le_div_of_nonneg_right hcard hR.le + _ = rho*(1+theta)*((P.card : ℝ)/((1+theta)*R)) := by field_simp + _ ≤ _ := mul_le_mul_of_nonneg_left hlower (by positivity) + +theorem harmonic_transfer_two (A P : Finset ℕ) (hAP : A ⊆ P) (R theta rho : ℝ) + (hR : 0 < R) (htheta : 0 ≤ theta) (htheta1 : theta ≤ 1) (hrho : 0 ≤ rho) + (hbin : ∀ p ∈ P,R < (p : ℝ) ∧ (p : ℝ) ≤ (1+theta)*R) + (hcard : (A.card : ℝ) ≤ rho*(P.card : ℝ)) : + harmonicMass A ≤ 2*rho*harmonicMass P := by + have hh := harmonic_transfer A P hAP R theta rho hR htheta hrho hbin hcard + have hc := harmonicMass_nonneg P + have hmul := mul_le_mul_of_nonneg_left (show 1+theta ≤ 2 by linarith) (mul_nonneg hrho hc) + nlinarith + +end ErdosVarianceWeighted + + +section + +open _root_.Filter +namespace ErdosVarianceUniformMoments +open NumberTheoryLean ErdosVarianceMoments ErdosVarianceSmallModel ErdosRandomVariance +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def modelBadEvent (J : ℕ) (w : ℝ) (H qA : ℕ) (C0 : ℤ) + (beta delta : ∀ t : ℕ,ZMod t) (eta : ℝ) (v : ModelPoint w H) : Prop := + eta*((J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ + |indicatorSum (Finset.range J) (modelIndicator w H C0 qA beta delta) v- + (J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊| + +theorem uniform_model_chebyshev (a eta tau : ℝ) (ha : 0 < a) (heta : 0 < eta) (htau : 0 < tau) : + ∃ Cs : ℝ,0 < Cs ∧ ∀ xi : ℝ,0 < xi → ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ + ∀ (R : ℝ),0 < R → ∀ (H qA : ℕ),0 < H → ∀ (C0 : ℤ),Int.gcd C0 (H : ℤ) = 1 → + ∀ (beta delta : ∀ t : ℕ,ZMod t), + (∀ t ∈ coprimePrimes w H,qA.Coprime t) → + xi*w^Cs ≤ modelLength R xi (H : ℝ) (C0 : ℝ) → + ∀ J : ℕ,w^a ≤ (J : ℝ) → + modelMass R xi w H C0 (modelBadEvent J w H qA C0 beta delta eta) ≤ tau := by + let zeta := min 1 (tau*eta^2/8) + have hzeta : 0 < zeta := lt_min zero_lt_one (by positivity) + have hzeta1 : zeta ≤ 1 := min_le_left _ _ + let eps := tau*eta^2/2 + have heps : 0 < eps := by dsimp [eps];positivity + obtain ⟨Cs,hCs,huniform⟩ := uniform_joint_model_relative zeta hzeta + refine ⟨Cs,hCs,?_⟩ + intro xi hxi + filter_upwards [huniform xi hxi,stable_source_chebyshev a eps ha heps] with w hw hstable + refine ⟨hw.1,?_⟩ + intro R hR H qA hH C0 hC0 beta delta hqA hscale J hJ + have hmom := model_moment_bounds R xi w H qA C0 beta delta zeta + (hw.2 R hR H qA hH C0 hC0 beta delta hqA hscale) + have hh := hstable.2 J hJ (ModelPoint w H) (modelUniverse R xi w H C0) + (fun _ => atomWeight R xi w H C0) (modelIndicator w H C0 qA beta delta) zeta eta + (fun _ _ => (atomWeight_pos R xi w H C0 hR hxi.le hH).le) hzeta.le hzeta1 heta + (fun j _ v _ => modelIndicator_binary w H C0 qA beta delta j v) + hmom.1 (fun j _ => hmom.2.1 j) (fun j _ => hmom.2.2.1 j) + (fun i _ j _ _ => hmom.2.2.2 i j) + have hV : sieveProduct (variancePrimes w) = SmallSieveFinite.smallEuler ⌊w⌋₊ := by + rw [variancePrimes_eq_cutoff,actual_sieveProduct] + rw [hV] at hh + have hbudget : (eps+4*zeta)/eta^2 ≤ tau := by + apply (div_le_iff₀ (sq_pos_of_pos heta)).mpr + have hz : zeta ≤ tau*eta^2/8 := min_le_right _ _ + dsimp [eps] + linarith + exact hh.trans hbudget + +end ErdosVarianceUniformMoments + +end + + +namespace ErdosVarianceSmallPrime +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceEffective ErdosVarianceCommon + ErdosVarianceMoments ErdosVarianceUniformMoments ErdosInverseCells ErdosRandomVariance +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem common_deviation_mem_primeEvent (P : Finset ℕ) (J : ℕ) (w : ℝ) + (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hPLarge : ∀ p ∈ P,w < (p : ℝ)) + (hQLarge : ∀ t ∈ qf.primeFactors,w < (t : ℝ)) (p : ℕ) [NeZero p] + (hpGood : p ∈ goodPrimes P (effectiveModulus a r qf)) (eta : ℝ) + (hdev : eta*((J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ + |((commonSurvivors J w a r qf p (Finset.mem_filter.mp hpGood).2).card : ℝ)- + (J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊|) : + p ∈ actualPrimeEvent P w (effectiveModulus a r qf) (effectiveIntercept a r qf) hw hP hPLarge + (modelBadEvent J w (effectiveModulus a r qf) (alignedCofactor (fun t => (a t : ℤ)) r qf) + (effectiveIntercept a r qf) (actualDivisorTarget a qf) (actualCoprimeTarget a r) eta) := by + apply Finset.mem_image.mpr + refine ⟨⟨p,hpGood⟩,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,rfl⟩ + change eta*((J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ + |(∑ j ∈ Finset.range J,actualModelIndicator w a r qf j + (primePoint P w (effectiveModulus a r qf) (effectiveIntercept a r qf) hw hP hPLarge ⟨p,hpGood⟩))- + (J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊| + rw [← common_card_eq_model_sum P J w a r qf hq hw hP hPLarge hQLarge p hpGood] + exact hdev + +end ErdosVarianceSmallPrime + + + +namespace ErdosVarianceSmallPrime +open NumberTheoryLean ErdosInverseCounts ErdosInverseAlignment ErdosVarianceCommon +attribute [local instance] Classical.propDecidable + +noncomputable def badAligningPrimes (P : Finset ℕ) (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) + (r : ℚ) (qf : ℕ) (eps : ℝ) : Finset ℕ := + P.filter (fun p => aligns (fun t => (a t : ℤ)) r p ∧ + eps < |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a (p*qf) : ℝ)/ + referenceCount Y w p qf-1|) + +theorem mem_badAligningPrimes (P : Finset ℕ) (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) + (r : ℚ) (qf : ℕ) (eps : ℝ) (p : ℕ) : + p ∈ badAligningPrimes P Y w a r qf eps ↔ p ∈ P ∧ + aligns (fun t => (a t : ℤ)) r p ∧ + eps < |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a (p*qf) : ℝ)/ + referenceCount Y w p qf-1| := Finset.mem_filter + +end ErdosVarianceSmallPrime + + + +namespace ErdosVarianceLargePrime +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceEffective ErdosVarianceCommon + ErdosVarianceMoments ErdosVarianceLargeMap +attribute [local instance] Classical.propDecidable + +noncomputable def fullPatternBadEvent (J : ℕ) (w : ℝ) (H qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (eta : ℝ) (v : ErdosLargePatternLaw.FullPattern w H) : Prop := + eta*((J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ + |(ErdosLargePatternLaw.survivorCount w H qA J beta delta v : ℝ)- + (J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊| + +theorem common_deviation_mem_full_event (P : Finset ℕ) (J : ℕ) (w : ℝ) + (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hPLarge : ∀ p ∈ P,w < (p : ℝ)) + (hQLarge : ∀ t ∈ qf.primeFactors,w < (t : ℝ)) (p : ℕ) [NeZero p] + (hpGood : p ∈ goodPrimes P (effectiveModulus a r qf)) (eta : ℝ) + (hdev : eta*((J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ + |((commonSurvivors J w a r qf p (Finset.mem_filter.mp hpGood).2).card : ℝ)- + (J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊|) : + p ∈ fullPrimeEvent P w (effectiveModulus a r qf) (effectiveIntercept a r qf) hw hP hPLarge + (fullPatternBadEvent J w (effectiveModulus a r qf) (alignedCofactor (fun t => (a t : ℤ)) r qf) + (actualDivisorTarget a qf) (actualCoprimeTarget a r) eta) := by + apply Finset.mem_image.mpr + refine ⟨⟨p,hpGood⟩,Finset.mem_filter.mpr ⟨Finset.mem_univ _,?_⟩,rfl⟩ + change eta*((J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ + |(ErdosLargePatternLaw.survivorCount w (effectiveModulus a r qf) + (alignedCofactor (fun t => (a t : ℤ)) r qf) J (actualDivisorTarget a qf) (actualCoprimeTarget a r) + (actualFullPattern P w (effectiveModulus a r qf) (effectiveIntercept a r qf) hw hP hPLarge ⟨p,hpGood⟩) : ℝ)- + (J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊| + rw [full_count_eq_common P J w a r qf hq hw hP hPLarge hQLarge p hpGood] + exact hdev + +end ErdosVarianceLargePrime + + +section + +open _root_.Filter +namespace ErdosVarianceSmallPrime +open NumberTheoryLean ErdosInverseBoxHeight ErdosInversePrimeBin ErdosInverseEuler + ErdosVarianceSmallModel ErdosVarianceEffective ErdosVarianceCommon ErdosVarianceMoments + ErdosVarianceUniformMoments ErdosInverseAlignment +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_small_H_bad_prime_fraction (alpha aStar eps sigma : ℝ) + (halpha : 0 < alpha) (ha : 0 < aStar) (heps : 0 < eps) (hsigma : 0 < sigma) : + ∃ Cs : ℝ,0 < Cs ∧ ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,0 < xi → xi ≤ xi0 → ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ),Squarefree qf → + z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + (∀ t ∈ qf.primeFactors,sourceW z < (t : ℝ)) → + (∀ p ∈ primeBin R theta,qf.Coprime p ∧ + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z)) → + (effectiveModulus a r qf : ℝ) ≤ R^((4 : ℝ)/5) → + effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ (sourceZ z)^12 → + (sourceW z)^Cs ≤ effectiveSize a r qf R → + ((badAligningPrimes (primeBin R theta) (sourceY z) (sourceW z) a r qf eps).card : ℝ)/ + ((primeBin R theta).card : ℝ) ≤ sigma := by + obtain ⟨C,hC,hdom⟩ := source_effective_point_domination alpha halpha + obtain ⟨Cs,hCs,hmodel⟩ := uniform_model_chebyshev (5*aStar/8) (eps/2) (sigma/C) + (by positivity) (by positivity) (div_pos hsigma hC) + obtain ⟨xi0,hxi0,hxi01,hcommon⟩ := source_actual_bad_to_common aStar eps ha heps + refine ⟨Cs,hCs,xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + have hxi1 := hxib.trans hxi01 + filter_upwards [hdom xi hxi hxi1,hcommon xi hxi hxib, + sourceW_tendsto_atTop.eventually (hmodel xi hxi),eventually_gt_atTop (0 : ℝ)] + with z hzdom hzcommon hzmodel hz0 + intro R theta a r qf hq hRlo hthetal hthetau hQLarge hgeometry hHsmall hratio hhard + have hR : 0 < R := (Real.rpow_pos_of_pos hz0 alpha).trans_le hRlo + have htheta : 0 ≤ theta := (by positivity : (0 : ℝ) ≤ xi/4).trans hthetal + let P := primeBin R theta + let H := effectiveModulus a r qf + let C0 := effectiveIntercept a r qf + let qA := alignedCofactor (fun t => (a t : ℤ)) r qf + let beta := actualDivisorTarget a qf + let delta := actualCoprimeTarget a r + let J := commonLength (sourceY z) qf R xi + let E := modelBadEvent J (sourceW z) H qA C0 beta delta (eps/2) + obtain ⟨hw,hP,hPLarge,hdomE⟩ := hzdom R theta a r qf hq hRlo hthetal hthetau hHsmall hratio + have hHp : 0 < H := effectiveModulus_pos a r qf + have hC0 : Int.gcd C0 (H : ℤ) = 1 := effective_coordinates_gcd a r qf hq + have hqA : ∀ t ∈ coprimePrimes (sourceW z) H,qA.Coprime t := by + intro t ht + have hc := LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1 + have htw := (Nat.le_floor_iff hw).mp hc.2 + exact aligned_coefficient_coprime_small a r qf hq (sourceW z) hQLarge t hc.1 htw + have hY : xi*(sourceW z)^Cs ≤ modelLength R xi (H : ℝ) (C0 : ℝ) := by + exact (mul_le_mul_of_nonneg_left hhard hxi.le).trans + (modelLength_bounds R xi (H : ℝ) (C0 : ℝ) hR hxi.le hxi1 (by exact_mod_cast hHp)).2 + have hmap (p : ℕ) (hp : p ∈ badAligningPrimes P (sourceY z) (sourceW z) a r qf eps) : + (sourceW z)^(5*aStar/8) ≤ (J : ℝ) ∧ + p ∈ actualPrimeEvent P (sourceW z) H C0 hw hP hPLarge E := by + obtain ⟨hpP,halign,hbad⟩ := (mem_badAligningPrimes P (sourceY z) (sourceW z) a r qf eps p).mp hp + have hprime := hP p hpP + let : NeZero p := ⟨hprime.ne_zero⟩ + have hqp := (hgeometry p hpP).1 + have hgood : p ∈ goodPrimes P H := Finset.mem_filter.mpr + ⟨hpP,aligned_isolated_coprime_effective a r qf hq p hprime hqp halign⟩ + have hbin := (mem_primeBin hR.le htheta p).mp hpP + have hpu : (p : ℝ) ≤ (1+xi)*R := hbin.2.2.trans (by nlinarith) + have hh := hzcommon a r qf hq p hprime hqp (Finset.mem_filter.mp hgood).2 R hR + hbin.2.1 hpu (hPLarge p hpP) hQLarge (hgeometry p hpP).2 halign hbad + refine ⟨hh.1,?_⟩ + exact common_deviation_mem_primeEvent P J (sourceW z) a r qf hq hw hP hPLarge hQLarge p hgood + (eps/2) hh.2.le + by_cases hempty : badAligningPrimes P (sourceY z) (sourceW z) a r qf eps = ∅ + · change ((badAligningPrimes P (sourceY z) (sourceW z) a r qf eps).card : ℝ)/(P.card : ℝ) ≤ sigma + rw [hempty,Finset.card_empty,Nat.cast_zero,zero_div] + exact hsigma.le + obtain ⟨p,hp⟩ := Finset.nonempty_iff_ne_empty.mpr hempty + have hJ := (hmap p hp).1 + have hmass : modelMass R xi (sourceW z) H C0 E ≤ sigma/C := + hzmodel.2 R hR H qA hHp C0 hC0 beta delta hqA hY J hJ + have hsub : badAligningPrimes P (sourceY z) (sourceW z) a r qf eps ⊆ + actualPrimeEvent P (sourceW z) H C0 hw hP hPLarge E := fun p hp => (hmap p hp).2 + have hcard : ((badAligningPrimes P (sourceY z) (sourceW z) a r qf eps).card : ℝ) ≤ + (actualPrimeEvent P (sourceW z) H C0 hw hP hPLarge E).card := by + exact_mod_cast Finset.card_le_card hsub + have hh := (div_le_div_of_nonneg_right hcard (Nat.cast_nonneg P.card)).trans + ((hdomE E).trans (mul_le_mul_of_nonneg_left hmass hC.le)) + have hc : C*(sigma/C) = sigma := by field_simp + exact hh.trans_eq hc + +end ErdosVarianceSmallPrime + +end + +section + +open _root_.Filter +namespace ErdosVarianceLargePrime +open NumberTheoryLean ErdosInverseBoxHeight ErdosInversePrimeBin ErdosInverseEuler + ErdosVarianceSmallModel ErdosVarianceEffective ErdosVarianceCommon ErdosVarianceMoments + ErdosVarianceLargeMap ErdosVarianceSmallPrime ErdosInverseAlignment +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_large_H_bad_prime_fraction (alpha aStar eps sigma : ℝ) + (halpha : 0 < alpha) (ha : 0 < aStar) (heps : 0 < eps) (hsigma : 0 < sigma) : + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ ∀ xi : ℝ,0 < xi → xi ≤ xi0 → ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ),Squarefree qf → + z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + (∀ t ∈ qf.primeFactors,sourceW z < (t : ℝ)) → + (∀ p ∈ primeBin R theta,qf.Coprime p ∧ + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z)) → + R^((4 : ℝ)/5) ≤ (effectiveModulus a r qf : ℝ) → + (effectiveModulus a r qf : ℝ) ≤ R*(sourceZ z)^11 → + effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ (sourceZ z)^12 → + ((badAligningPrimes (primeBin R theta) (sourceY z) (sourceW z) a r qf eps).card : ℝ)/ + ((primeBin R theta).card : ℝ) ≤ sigma := by + obtain ⟨C,hC,hdom⟩ := source_full_pattern_domination alpha halpha + have hmodel := ErdosLargePatternLaw.uniform_pattern_chebyshev (5*aStar/8) (eps/2) (sigma/(2*C)) + (by positivity) (by positivity) (by positivity) + obtain ⟨xi0,hxi0,hxi01,hcommon⟩ := source_actual_bad_to_common aStar eps ha heps + refine ⟨xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + have hxi1 := hxib.trans hxi01 + filter_upwards [hdom xi hxi hxi1 (sigma/2) (by positivity),hcommon xi hxi hxib, + sourceW_tendsto_atTop.eventually hmodel] with z hzdom hzcommon hzmodel + intro R theta a r qf hq hRlo hthetal hthetau hQLarge hgeometry hHlarge hHupper hratio + have hR1 : 1 < R := (Real.one_lt_rpow hzdom.1 halpha).trans_le hRlo + have hR : 0 < R := by linarith + have htheta : 0 ≤ theta := (by positivity : (0 : ℝ) ≤ xi/4).trans hthetal + let P := primeBin R theta + let H := effectiveModulus a r qf + let C0 := effectiveIntercept a r qf + let qA := alignedCofactor (fun t => (a t : ℤ)) r qf + let beta := actualDivisorTarget a qf + let delta := actualCoprimeTarget a r + let J := commonLength (sourceY z) qf R xi + let E := fullPatternBadEvent J (sourceW z) H qA beta delta (eps/2) + have hH1 : (1 : ℝ) < H := (Real.one_lt_rpow hR1 (by norm_num : (0 : ℝ) < 4/5)).trans_le hHlarge + have hH2 : 2 ≤ H := by + have hh : 1 < H := by exact_mod_cast hH1 + omega + have hC0 : Int.gcd C0 (H : ℤ) = 1 := effective_coordinates_gcd a r qf hq + obtain ⟨hw,hP,hPLarge,hdomE⟩ := hzdom.2 R theta hRlo hthetal hthetau H C0 hH2 hC0 hHlarge hHupper hratio + have hqA : ∀ t ∈ coprimePrimes (sourceW z) H,qA.Coprime t := by + intro t ht + have hc := LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1 + exact aligned_coefficient_coprime_small a r qf hq (sourceW z) hQLarge t hc.1 ((Nat.le_floor_iff hw).mp hc.2) + have hmap (p : ℕ) (hp : p ∈ badAligningPrimes P (sourceY z) (sourceW z) a r qf eps) : + (sourceW z)^(5*aStar/8) ≤ (J : ℝ) ∧ p ∈ fullPrimeEvent P (sourceW z) H C0 hw hP hPLarge E := by + obtain ⟨hpP,halign,hbad⟩ := (mem_badAligningPrimes P (sourceY z) (sourceW z) a r qf eps p).mp hp + have hprime := hP p hpP + let : NeZero p := ⟨hprime.ne_zero⟩ + have hqp := (hgeometry p hpP).1 + have hgood : p ∈ goodPrimes P H := Finset.mem_filter.mpr + ⟨hpP,aligned_isolated_coprime_effective a r qf hq p hprime hqp halign⟩ + have hbin := (mem_primeBin hR.le htheta p).mp hpP + have hpu : (p : ℝ) ≤ (1+xi)*R := hbin.2.2.trans (by nlinarith) + have hh := hzcommon a r qf hq p hprime hqp (Finset.mem_filter.mp hgood).2 R hR + hbin.2.1 hpu (hPLarge p hpP) hQLarge (hgeometry p hpP).2 halign hbad + exact ⟨hh.1,common_deviation_mem_full_event P J (sourceW z) a r qf hq hw hP hPLarge hQLarge p hgood + (eps/2) hh.2.le⟩ + by_cases hempty : badAligningPrimes P (sourceY z) (sourceW z) a r qf eps = ∅ + · change ((badAligningPrimes P (sourceY z) (sourceW z) a r qf eps).card : ℝ)/(P.card : ℝ) ≤ sigma + rw [hempty,Finset.card_empty,Nat.cast_zero,zero_div] + exact hsigma.le + obtain ⟨p,hp⟩ := Finset.nonempty_iff_ne_empty.mpr hempty + have hJ := (hmap p hp).1 + have hmass : patternEventWeight (sourceW z) H E ≤ sigma/(2*C) := + hzmodel.2 H qA beta delta hqA J hJ + have hsub : badAligningPrimes P (sourceY z) (sourceW z) a r qf eps ⊆ + fullPrimeEvent P (sourceW z) H C0 hw hP hPLarge E := fun p hp => (hmap p hp).2 + have hcard : ((badAligningPrimes P (sourceY z) (sourceW z) a r qf eps).card : ℝ) ≤ + (fullPrimeEvent P (sourceW z) H C0 hw hP hPLarge E).card := by exact_mod_cast Finset.card_le_card hsub + have hh := (div_le_div_of_nonneg_right hcard (Nat.cast_nonneg P.card)).trans + ((hdomE E).trans (add_le_add (mul_le_mul_of_nonneg_left hmass hC.le) le_rfl)) + have hc : C*(sigma/(2*C))+sigma/2 = sigma := by field_simp;ring + exact hh.trans_eq hc + +end ErdosVarianceLargePrime + +end + +section + +open _root_.Filter +namespace ErdosVarianceLargePrime +open NumberTheoryLean ErdosInverseBoxHeight ErdosInversePrimeBin ErdosInverseEuler + ErdosVarianceEffective ErdosVarianceSmallPrime +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_hard_bad_prime_fraction (alpha aStar eps sigma Cmin : ℝ) + (halpha : 0 < alpha) (ha : 0 < aStar) (heps : 0 < eps) (hsigma : 0 < sigma) : + ∃ Cs : ℝ,0 < Cs ∧ Cmin ≤ Cs ∧ ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,0 < xi → xi ≤ xi0 → ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ),Squarefree qf → + z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + (∀ t ∈ qf.primeFactors,sourceW z < (t : ℝ)) → + (∀ p ∈ primeBin R theta,qf.Coprime p ∧ + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z)) → + (effectiveModulus a r qf : ℝ) ≤ R*(sourceZ z)^11 → + effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ (sourceZ z)^12 → + (sourceW z)^Cs ≤ effectiveSize a r qf R → + ((badAligningPrimes (primeBin R theta) (sourceY z) (sourceW z) a r qf eps).card : ℝ)/ + ((primeBin R theta).card : ℝ) ≤ sigma := by + obtain ⟨Cs0,hCs0,xiS,hxiS,hxiS1,hsmall⟩ := source_small_H_bad_prime_fraction alpha aStar eps sigma halpha ha heps hsigma + obtain ⟨xiL,hxiL,hxiL1,hlarge⟩ := source_large_H_bad_prime_fraction alpha aStar eps sigma halpha ha heps hsigma + let Cs := max Cs0 (max 1 Cmin) + have hCs : 0 < Cs := hCs0.trans_le (le_max_left _ _) + have hCmin : Cmin ≤ Cs := (le_max_right 1 Cmin).trans (le_max_right _ _) + refine ⟨Cs,hCs,hCmin,min xiS xiL,lt_min hxiS hxiL,(min_le_left _ _).trans hxiS1,?_⟩ + intro xi hxi hxib + have hxS := hxib.trans (min_le_left xiS xiL) + have hxL := hxib.trans (min_le_right xiS xiL) + filter_upwards [hsmall xi hxi hxS,hlarge xi hxi hxL,sourceW_tendsto_atTop.eventually_ge_atTop 1] + with z hzsmall hzlarge hW + intro R theta a r qf hq hRlo hthetal hthetau hQLarge hgeometry hHupper hratio hhard + by_cases hcase : (effectiveModulus a r qf : ℝ) ≤ R^((4 : ℝ)/5) + · have hhard0 : (sourceW z)^Cs0 ≤ effectiveSize a r qf R := + (Real.rpow_le_rpow_of_exponent_le hW (le_max_left Cs0 (max 1 Cmin))).trans hhard + exact hzsmall R theta a r qf hq hRlo hthetal hthetau hQLarge hgeometry hcase hratio hhard0 + · exact hzlarge R theta a r qf hq hRlo hthetal hthetau hQLarge hgeometry + (le_of_lt (lt_of_not_ge hcase)) hHupper hratio + +end ErdosVarianceLargePrime + +end + + +namespace ErdosVarianceWeighted +open NumberTheoryLean ErdosInverseBoxHeight ErdosInversePrimeBin ErdosVarianceEffective ErdosVarianceSmallPrime +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +def hardCandidate (z R : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (Cs : ℝ) : Prop := + (effectiveModulus a r qf : ℝ) ≤ R*(sourceZ z)^11 ∧ + effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ (sourceZ z)^12 ∧ + (sourceW z)^Cs ≤ effectiveSize a r qf R + +noncomputable def guardedHardPrimes (z R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (Cs eps : ℝ) : Finset ℕ := + if hardCandidate z R a r qf Cs then + badAligningPrimes (primeBin R theta) (sourceY z) (sourceW z) a r qf eps else ∅ + +noncomputable def rawHardPrimeUnion (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) (qf : ℕ) (Cs eps : ℝ) : Finset ℕ := + Q.biUnion (fun r => guardedHardPrimes z R theta a r qf Cs eps) + +theorem guardedHardPrimes_subset (z R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (Cs eps : ℝ) : + guardedHardPrimes z R theta a r qf Cs eps ⊆ primeBin R theta := by + unfold guardedHardPrimes + split_ifs + · exact Finset.filter_subset _ _ + · exact Finset.empty_subset _ + +theorem rawHardPrimeUnion_subset (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) (qf : ℕ) (Cs eps : ℝ) : + rawHardPrimeUnion Q z R theta a qf Cs eps ⊆ primeBin R theta := by + exact Finset.biUnion_subset.mpr (fun r _ => guardedHardPrimes_subset z R theta a r qf Cs eps) + +theorem mem_rawHardPrimeUnion (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) (qf : ℕ) (Cs eps : ℝ) (p : ℕ) : + p ∈ rawHardPrimeUnion Q z R theta a qf Cs eps ↔ ∃ r ∈ Q, + hardCandidate z R a r qf Cs ∧ + p ∈ badAligningPrimes (primeBin R theta) (sourceY z) (sourceW z) a r qf eps := by + simp only [rawHardPrimeUnion,Finset.mem_biUnion] + apply exists_congr + intro r + apply and_congr_right + intro _hr + by_cases h : hardCandidate z R a r qf Cs <;> simp [guardedHardPrimes,h] + +theorem rawHardPrimeUnion_card (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) (qf : ℕ) (Cs eps sigma : ℝ) + (h : ∀ r ∈ Q,((guardedHardPrimes z R theta a r qf Cs eps).card : ℝ) ≤ + sigma*((primeBin R theta).card : ℝ)) : + ((rawHardPrimeUnion Q z R theta a qf Cs eps).card : ℝ) ≤ + sigma*(Q.card : ℝ)*((primeBin R theta).card : ℝ) := by + have hc := Finset.card_biUnion_le (s := Q) (t := fun r => guardedHardPrimes z R theta a r qf Cs eps) + calc + _ ≤ ∑ r ∈ Q,((guardedHardPrimes z R theta a r qf Cs eps).card : ℝ) := by exact_mod_cast hc + _ ≤ ∑ _r ∈ Q,sigma*((primeBin R theta).card : ℝ) := Finset.sum_le_sum h + _ = _ := by rw [Finset.sum_const,nsmul_eq_mul];ring + +end ErdosVarianceWeighted + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/HighPrimeRemoval.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/HighPrimeRemoval.lean new file mode 100644 index 0000000000000000000000000000000000000000..03b786412806f875cd22f0f9f84bebaec4c803ce --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/HighPrimeRemoval.lean @@ -0,0 +1,1242 @@ +import Mathlib.Data.Finset.Sort +import Mathlib.NumberTheory.AbelSummation +import Mathlib.NumberTheory.Chebyshev +import PrimeNumberTheoremAnd.Erdos970.MertensClassical +import StrongPNT.Erdos970.PNT5_Strong +import OAI.NumberTheory.Jacobsthal.Primes.PrimeBinCounting + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosPrimeInputs.StrongChebyshev + +open _root_.Filter Asymptotics +open scoped Topology + +noncomputable def errorScale (c x : ℝ) : ℝ := + x * Real.exp (-c * Real.sqrt (Real.log x)) + +theorem errorScale_nonneg (c : ℝ) {x : ℝ} (hx : 0 ≤ x) : 0 ≤ errorScale c x := by + exact mul_nonneg hx (Real.exp_pos _).le + +theorem psi_eq_original {x : ℝ} (hx : 0 ≤ x) : Chebyshev.psi x = _root_.Erdos970.ChebyshevPsi x := by + rw [Chebyshev.psi_eq_sum_Icc, _root_.Erdos970.ChebyshevPsi, Nat.floor_add_one hx, + Nat.range_succ_eq_Icc_zero] + +theorem sqrt_le_errorScale {c : ℝ} (hc : 0 < c) : + ∀ᶠ x : ℝ in atTop, Real.sqrt x ≤ errorScale c x := by + filter_upwards [eventually_ge_atTop (1 : ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop ((2 * c) ^ 2))] with x hx hlog + have hx0 : 0 < x := lt_of_lt_of_le zero_lt_one hx + have hl0 : 0 ≤ Real.log x := Real.log_nonneg hx + have hy0 := Real.sqrt_nonneg (Real.log x) + have hy2 := Real.sq_sqrt hl0 + have hy : 2 * c ≤ Real.sqrt (Real.log x) := by nlinarith + have hmul := mul_nonneg hy0 (sub_nonneg.mpr hy) + have hlin : Real.log x * (1 / 2) ≤ Real.log x - c * Real.sqrt (Real.log x) := by + nlinarith + calc + Real.sqrt x = Real.exp (Real.log x * (1 / 2)) := by + rw [Real.sqrt_eq_rpow, Real.rpow_def_of_pos hx0] + _ ≤ Real.exp (Real.log x - c * Real.sqrt (Real.log x)) := Real.exp_le_exp.mpr hlin + _ = errorScale c x := by + rw [Real.exp_sub, Real.exp_log hx0, errorScale, neg_mul, Real.exp_neg] + ring + +theorem sqrt_isBigO_errorScale {c : ℝ} (hc : 0 < c) : + Real.sqrt =O[atTop] errorScale c := by + apply IsBigO.of_bound 1 + filter_upwards [sqrt_le_errorScale hc, eventually_ge_atTop (0 : ℝ)] with x hb hx + simpa only [Real.norm_eq_abs, abs_of_nonneg (Real.sqrt_nonneg x), + abs_of_nonneg (errorScale_nonneg c hx), one_mul] using hb + +theorem psi_strong : ∃ c : ℝ, 0 < c ∧ + (fun x : ℝ => Chebyshev.psi x - x) =O[atTop] errorScale c := by + obtain ⟨c, hc, h⟩ := _root_.Erdos970.Strong_PNT + refine ⟨c, hc, h.congr' ?_ ?_⟩ + · filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx + simp only [Pi.sub_apply, id_eq, psi_eq_original hx] + · filter_upwards [] with x + simp only [errorScale, Real.sqrt_eq_rpow] + +theorem theta_strong : ∃ c : ℝ, 0 < c ∧ + (fun x : ℝ => Chebyshev.theta x - x) =O[atTop] errorScale c := by + obtain ⟨c, hc, hpsi⟩ := psi_strong + have hdiff := Chebyshev.isBigO_psi_sub_theta_sqrt.trans (sqrt_isBigO_errorScale hc) + refine ⟨c, hc, (hpsi.sub hdiff).congr_left ?_⟩ + intro x + simp only [Pi.sub_apply] + ring + +end ErdosPrimeInputs.StrongChebyshev + + + +namespace ErdosPrimeInputs.PrimeAbel + +open _root_.Set _root_.Finset _root_.MeasureTheory +open scoped Topology + +noncomputable def primeLogWeight (n : ℕ) : ℝ := if n.Prime then Real.log n else 0 +noncomputable def reciprocalPrimes (a b : ℝ) : ℝ := + ∑ n ∈ (Finset.Ioc ⌊a⌋₊ ⌊b⌋₊).filter Nat.Prime, (n : ℝ)⁻¹ +noncomputable def invLogWeight (t : ℝ) : ℝ := 1 / (t * Real.log t) +noncomputable def errorKernel (t : ℝ) : ℝ := (Real.log t + 1) / (t ^ 2 * Real.log t ^ 2) + +theorem prefix_primeLogWeight (x : ℝ) : + ∑ n ∈ Finset.Icc 0 ⌊x⌋₊, primeLogWeight n = Chebyshev.theta x := by + rw [Chebyshev.theta_eq_sum_Icc, Finset.sum_filter] + rfl + +theorem reciprocal_eq_weighted (a b : ℝ) : + reciprocalPrimes a b = ∑ n ∈ Finset.Ioc ⌊a⌋₊ ⌊b⌋₊, invLogWeight n * primeLogWeight n := by + rw [reciprocalPrimes, Finset.sum_filter] + apply Finset.sum_congr rfl + intro n hn + by_cases hp : n.Prime + · have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast hp.ne_zero + have hnl : Real.log (n : ℝ) ≠ 0 := ne_of_gt (Real.log_pos (by exact_mod_cast hp.one_lt)) + simp only [primeLogWeight, hp, ite_true, invLogWeight] + field_simp + · simp [primeLogWeight, hp] + +theorem hasDerivAt_invLogWeight {t : ℝ} (ht : 1 < t) : + HasDerivAt invLogWeight (-errorKernel t) t := by + have ht0 : t ≠ 0 := ne_of_gt (lt_trans zero_lt_one ht) + have hl0 : Real.log t ≠ 0 := ne_of_gt (Real.log_pos ht) + convert! ((hasDerivAt_id t).mul (Real.hasDerivAt_log ht0)).inv (mul_ne_zero ht0 hl0) using 1 + · ext x + simp [invLogWeight, one_div] + · dsimp [errorKernel] + field_simp + +theorem deriv_invLogWeight {t : ℝ} (ht : 1 < t) : deriv invLogWeight t = -errorKernel t := + (hasDerivAt_invLogWeight ht).deriv + +theorem invLogWeight_continuousOn {a b : ℝ} (ha : 1 < a) : + ContinuousOn invLogWeight (Set.Icc a b) := by + intro t ht + exact (hasDerivAt_invLogWeight (lt_of_lt_of_le ha ht.1)).continuousAt.continuousWithinAt + +theorem deriv_invLogWeight_continuousOn {a b : ℝ} (ha : 1 < a) : + ContinuousOn (deriv invLogWeight) (Set.Icc a b) := by + have hc : ContinuousOn (fun t => -errorKernel t) (Set.Icc a b) := by + intro t ht + have ht1 : 1 < t := lt_of_lt_of_le ha ht.1 + have ht0 : t ≠ 0 := ne_of_gt (lt_trans zero_lt_one ht1) + have hl0 : Real.log t ≠ 0 := ne_of_gt (Real.log_pos ht1) + apply ContinuousAt.continuousWithinAt + unfold errorKernel + fun_prop (disch := simp [ht0, hl0]) + apply hc.congr + intro t ht + exact deriv_invLogWeight (lt_of_lt_of_le ha ht.1) + +theorem abel_theta {a b : ℝ} (ha : 1 < a) (hab : a ≤ b) : + reciprocalPrimes a b = invLogWeight b * Chebyshev.theta b - invLogWeight a * Chebyshev.theta a - + ∫ t in Set.Ioc a b, deriv invLogWeight t * Chebyshev.theta t := by + rw [reciprocal_eq_weighted] + have h := sum_mul_eq_sub_sub_integral_mul primeLogWeight (le_of_lt (lt_trans zero_lt_one ha)) hab + (fun t ht => (hasDerivAt_invLogWeight (lt_of_lt_of_le ha ht.1)).differentiableAt) + (deriv_invLogWeight_continuousOn ha).integrableOn_Icc + simpa only [prefix_primeLogWeight] using h + +theorem error_identity {a b : ℝ} (ha : 1 < a) (hab : a ≤ b) : + reciprocalPrimes a b - (∫ t in Set.Ioc a b, invLogWeight t) = + invLogWeight b * (Chebyshev.theta b - b) - invLogWeight a * (Chebyshev.theta a - a) - + ∫ t in Set.Ioc a b, deriv invLogWeight t * (Chebyshev.theta t - t) := by + have hf : IntegrableOn invLogWeight (Set.Ioc a b) := + (invLogWeight_continuousOn ha).integrableOn_Icc.mono_set Set.Ioc_subset_Icc_self + have hfd : ContinuousOn (deriv invLogWeight) (Set.Icc a b) := deriv_invLogWeight_continuousOn ha + have hlin : IntegrableOn (fun t => deriv invLogWeight t * t) (Set.Ioc a b) := + (hfd.mul continuousOn_id).integrableOn_Icc.mono_set Set.Ioc_subset_Icc_self + have htheta : IntegrableOn (fun t => deriv invLogWeight t * Chebyshev.theta t) (Set.Ioc a b) := by + have h := integrableOn_mul_sum_Icc primeLogWeight (m := 0) + (le_of_lt (lt_trans zero_lt_one ha)) hfd.integrableOn_Icc + simp only [prefix_primeLogWeight] at h + exact h.mono_set Set.Ioc_subset_Icc_self + have hmain : (∫ t in Set.Ioc a b, deriv invLogWeight t * t) + + (∫ t in Set.Ioc a b, invLogWeight t) = invLogWeight b * b - invLogWeight a * a := by + rw [← integral_add hlin hf, ← intervalIntegral.integral_of_le hab] + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + · intro t ht + rw [Set.uIcc_of_le hab] at ht + rw [deriv_invLogWeight (lt_of_lt_of_le ha ht.1)] + simpa only [one_mul, mul_one] using! + ((hasDerivAt_invLogWeight (lt_of_lt_of_le ha ht.1)).mul (hasDerivAt_id t)) + · exact (intervalIntegrable_iff_integrableOn_Ioc_of_le hab).mpr (hlin.add hf) + have hrem : (∫ t in Set.Ioc a b, deriv invLogWeight t * (Chebyshev.theta t - t)) = + (∫ t in Set.Ioc a b, deriv invLogWeight t * Chebyshev.theta t) - + (∫ t in Set.Ioc a b, deriv invLogWeight t * t) := by + simp_rw [mul_sub] + exact integral_sub htheta hlin + have hAbel := abel_theta ha hab + linear_combination hAbel - hmain + hrem + +theorem hasDerivAt_loglog {t : ℝ} (ht : 1 < t) : + HasDerivAt (fun x => Real.log (Real.log x)) (invLogWeight t) t := by + have ht0 : t ≠ 0 := ne_of_gt (lt_trans zero_lt_one ht) + have hl0 : Real.log t ≠ 0 := ne_of_gt (Real.log_pos ht) + convert! (Real.hasDerivAt_log hl0).comp t (Real.hasDerivAt_log ht0) using 1 + simp [invLogWeight, one_div, mul_inv_rev, mul_comm] + +theorem integral_invLogWeight {a b : ℝ} (ha : 1 < a) (hab : a ≤ b) : + (∫ t in Set.Ioc a b, invLogWeight t) = Real.log (Real.log b) - Real.log (Real.log a) := by + rw [← intervalIntegral.integral_of_le hab] + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + · intro t ht + rw [Set.uIcc_of_le hab] at ht + exact hasDerivAt_loglog (lt_of_lt_of_le ha ht.1) + · exact (intervalIntegrable_iff_integrableOn_Ioc_of_le hab).mpr + ((invLogWeight_continuousOn ha).integrableOn_Icc.mono_set Set.Ioc_subset_Icc_self) + +end ErdosPrimeInputs.PrimeAbel + + + +namespace ErdosPrimeInputs.PrimeEndpoints + +open _root_.Finset +open PrimeAbel + +noncomputable def intervalGuard (leftClosed rightClosed : Bool) (a b t : ℝ) : Prop := + (if leftClosed then a ≤ t else a < t) ∧ (if rightClosed then t ≤ b else t < b) + +noncomputable def intervalSum (leftClosed rightClosed : Bool) (a b : ℝ) : ℝ := by + classical + exact ∑ n ∈ Nat.primesLE ⌊b⌋₊, + if intervalGuard leftClosed rightClosed a b (n : ℝ) then (n : ℝ)⁻¹ else 0 + +lemma reciprocal_eq_core {a b : ℝ} (ha : 0 ≤ a) (_hab : a ≤ b) : + reciprocalPrimes a b = ∑ n ∈ Nat.primesLE ⌊b⌋₊, if a < (n : ℝ) then (n : ℝ)⁻¹ else 0 := by + rw [reciprocalPrimes, ← Finset.sum_filter] + congr 1 + ext n + simp only [Finset.mem_filter, Finset.mem_Ioc, Nat.mem_primesLE] + rw [Nat.floor_lt ha] + tauto + +lemma selection_difference_bound (p q : Prop) [Decidable p] [Decidable q] {w : ℝ} (hw : 0 ≤ w) : + |(if p then w else 0) - (if q then w else 0)| ≤ w := by + by_cases hp : p <;> by_cases hq : q <;> simp [hp, hq, abs_of_nonneg hw, hw] + +lemma fiber_sum_le (s : Finset ℕ) (x : ℝ) {w : ℝ} (hw : 0 ≤ w) : + (∑ n ∈ s, if (n : ℝ) = x then w else 0) ≤ w := by + rw [← Finset.sum_filter] + simp only [Finset.sum_const, nsmul_eq_mul] + have hc : (s.filter (fun n : ℕ => (n : ℝ) = x)).card ≤ 1 := by + apply Finset.card_le_one.mpr + intro n hn m hm + have h := (Finset.mem_filter.mp hn).2.trans (Finset.mem_filter.mp hm).2.symm + exact_mod_cast h + have hr : ((s.filter (fun n : ℕ => (n : ℝ) = x)).card : ℝ) ≤ 1 := by exact_mod_cast hc + simpa only [one_mul] using mul_le_mul_of_nonneg_right hr hw + +theorem endpoint_difference {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) + (lc rc : Bool) : |intervalSum lc rc a b - reciprocalPrimes a b| ≤ 2 / a := by + classical + have hw : 0 ≤ a⁻¹ := inv_nonneg.mpr ha.le + rw [intervalSum, reciprocal_eq_core ha.le hab, ← Finset.sum_sub_distrib] + calc + _ ≤ ∑ n ∈ Nat.primesLE ⌊b⌋₊, + |(if intervalGuard lc rc a b (n : ℝ) then (n : ℝ)⁻¹ else 0) - + (if a < (n : ℝ) then (n : ℝ)⁻¹ else 0)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ n ∈ Nat.primesLE ⌊b⌋₊, + ((if (n : ℝ) = a then a⁻¹ else 0) + (if (n : ℝ) = b then a⁻¹ else 0)) := by + apply Finset.sum_le_sum + intro n hn + have hp : n.Prime := (Nat.mem_primesLE.mp hn).2 + have hn0 : 0 < (n : ℝ) := by exact_mod_cast hp.pos + have hnw : 0 ≤ (n : ℝ)⁻¹ := inv_nonneg.mpr hn0.le + have hnb : (n : ℝ) ≤ b := (Nat.le_floor_iff (le_trans ha.le hab)).mp (Nat.mem_primesLE.mp hn).1 + by_cases hna : (n : ℝ) = a + · have hd := selection_difference_bound (intervalGuard lc rc a b (n : ℝ)) (a < (n : ℝ)) hnw + calc + _ ≤ (n : ℝ)⁻¹ := hd + _ ≤ _ := by rw [hna]; split_ifs <;> simp_all + · by_cases hneqb : (n : ℝ) = b + · calc + _ ≤ (n : ℝ)⁻¹ := selection_difference_bound _ _ hnw + _ ≤ a⁻¹ := by rw [hneqb]; exact inv_anti₀ ha hab + _ = _ := by rw [ite_eq_right hna, ite_eq_left hneqb, zero_add] + · have hguard : intervalGuard lc rc a b (n : ℝ) ↔ a < (n : ℝ) := by + have hne : a ≠ (n : ℝ) := Ne.symm hna + cases lc <;> cases rc <;> simp_all [intervalGuard, le_iff_lt_or_eq] + simp [hguard, hna, hneqb] + _ ≤ a⁻¹ + a⁻¹ := by + rw [Finset.sum_add_distrib] + exact add_le_add (fiber_sum_le _ _ hw) (fiber_sum_le _ _ hw) + _ = 2 / a := by ring + +end ErdosPrimeInputs.PrimeEndpoints + + + +namespace ErdosPrimeInputs.PrimeErrorDecay + +open _root_.Set _root_.MeasureTheory _root_.Filter Asymptotics +open scoped Topology +open StrongChebyshev PrimeAbel + +noncomputable def decay (c t : ℝ) : ℝ := Real.exp (-c * Real.sqrt (Real.log t)) +noncomputable def tailKernel (c t : ℝ) : ℝ := decay c t / (t * Real.sqrt (Real.log t)) + +lemma decay_pos (c t : ℝ) : 0 < decay c t := Real.exp_pos _ + +lemma decay_antitone {c a b : ℝ} (hc : 0 ≤ c) (ha : 0 < a) (hab : a ≤ b) : + decay c b ≤ decay c a := by + apply Real.exp_le_exp.mpr + have h := Real.sqrt_le_sqrt (Real.log_le_log ha hab) + nlinarith + +lemma hasDerivAt_decay {c t : ℝ} (ht : 1 < t) : + HasDerivAt (decay c) (-(c / 2) * tailKernel c t) t := by + have ht0 : t ≠ 0 := ne_of_gt (lt_trans zero_lt_one ht) + have hl0 : Real.log t ≠ 0 := ne_of_gt (Real.log_pos ht) + have hs0 : Real.sqrt (Real.log t) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (Real.log_pos ht)) + have h := (((Real.hasDerivAt_sqrt hl0).comp t (Real.hasDerivAt_log ht0)).const_mul (-c)).exp + convert! h using 1 + dsimp [tailKernel, decay] + field_simp + +lemma tailKernel_continuousOn {c a b : ℝ} (ha : 1 < a) : + ContinuousOn (tailKernel c) (Set.Icc a b) := by + intro t ht + have ht1 := lt_of_lt_of_le ha ht.1 + have ht0 : t ≠ 0 := ne_of_gt (lt_trans zero_lt_one ht1) + have hs0 : Real.sqrt (Real.log t) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (Real.log_pos ht1)) + apply ContinuousAt.continuousWithinAt + unfold tailKernel decay + fun_prop (disch := simp [ht0, hs0]) + +lemma hasDerivAt_tailPrimitive {c t : ℝ} (hc : 0 < c) (ht : 1 < t) : + HasDerivAt (fun t => -(2 / c) * decay c t) (tailKernel c t) t := by + convert! (hasDerivAt_decay ht).const_mul (-(2 / c)) using 1 + field_simp + +lemma tailIntegral {c a b : ℝ} (hc : 0 < c) (ha : 1 < a) (hab : a ≤ b) : + (∫ t in Set.Ioc a b, tailKernel c t) = (2 / c) * (decay c a - decay c b) := by + have h : (∫ t in a..b, tailKernel c t) = -(2 / c) * decay c b - (-(2 / c) * decay c a) := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + · intro t ht + rw [Set.uIcc_of_le hab] at ht + exact hasDerivAt_tailPrimitive hc (lt_of_lt_of_le ha ht.1) + · exact (intervalIntegrable_iff_integrableOn_Ioc_of_le hab).mpr + ((tailKernel_continuousOn ha).integrableOn_Icc.mono_set Set.Ioc_subset_Icc_self) + rw [intervalIntegral.integral_of_le hab] at h + rw [h] + ring + +lemma tailIntegral_le {c a b : ℝ} (hc : 0 < c) (ha : 1 < a) (hab : a ≤ b) : + (∫ t in Set.Ioc a b, tailKernel c t) ≤ (2 / c) * decay c a := by + rw [tailIntegral hc ha hab] + exact mul_le_mul_of_nonneg_left (sub_le_self _ (decay_pos c b).le) (by positivity) + +lemma kernel_comparison {t : ℝ} (ht : 1 < t) (hl : 1 ≤ Real.log t) : + errorKernel t * t ≤ 2 / (t * Real.sqrt (Real.log t)) := by + have ht0 : 0 < t := lt_trans zero_lt_one ht + have hl0 : 0 < Real.log t := lt_of_lt_of_le zero_lt_one hl + have hs0 : 0 < Real.sqrt (Real.log t) := Real.sqrt_pos.mpr hl0 + have hsle : Real.sqrt (Real.log t) ≤ Real.log t := by + have hs2 := Real.sq_sqrt hl0.le + have hs := Real.sqrt_nonneg (Real.log t) + nlinarith + calc + errorKernel t * t = (Real.log t + 1) / (t * Real.log t ^ 2) := by + unfold errorKernel + field_simp + _ ≤ (2 * Real.log t) / (t * Real.log t ^ 2) := + div_le_div_of_nonneg_right (by linarith) (by positivity) + _ = 2 / (t * Real.log t) := by field_simp + _ ≤ _ := div_le_div_of_nonneg_left (by norm_num) (mul_pos ht0 hs0) + (mul_le_mul_of_nonneg_left hsle ht0.le) + +lemma endpoint_error_bound {c C t : ℝ} (hC : 0 ≤ C) (ht : 1 < t) (hl : 1 ≤ Real.log t) + (hθ : |Chebyshev.theta t - t| ≤ C * errorScale c t) : + |invLogWeight t * (Chebyshev.theta t - t)| ≤ C * decay c t := by + have ht0 : 0 < t := lt_trans zero_lt_one ht + have hl0 : 0 < Real.log t := lt_of_lt_of_le zero_lt_one hl + rw [abs_mul, abs_of_nonneg (show 0 ≤ invLogWeight t by unfold invLogWeight; positivity)] + calc + _ ≤ invLogWeight t * (C * errorScale c t) := + mul_le_mul_of_nonneg_left hθ (by unfold invLogWeight; positivity) + _ = C * decay c t / Real.log t := by unfold invLogWeight errorScale decay; field_simp + _ ≤ C * decay c t := div_le_self (mul_nonneg hC (decay_pos c t).le) hl + +lemma integral_error_bound {c C a b : ℝ} (hc : 0 < c) (hC : 0 ≤ C) + (ha : 1 < a) (hla : 1 ≤ Real.log a) (hab : a ≤ b) + (hθ : ∀ t ∈ Set.Icc a b, |Chebyshev.theta t - t| ≤ C * errorScale c t) : + |∫ t in Set.Ioc a b, deriv invLogWeight t * (Chebyshev.theta t - t)| ≤ + (4 * C / c) * decay c a := by + have hi : IntegrableOn (fun t => (2 * C) * tailKernel c t) (Set.Ioc a b) := + ((tailKernel_continuousOn ha).integrableOn_Icc.mono_set Set.Ioc_subset_Icc_self).const_mul _ + have hb : ∀ t ∈ Set.Ioc a b, + ‖deriv invLogWeight t * (Chebyshev.theta t - t)‖ ≤ (2 * C) * tailKernel c t := by + intro t ht + have ht1 : 1 < t := lt_trans ha ht.1 + have ht0 : 0 < t := lt_trans zero_lt_one ht1 + have hlt : 1 ≤ Real.log t := le_trans hla (Real.log_le_log (lt_trans zero_lt_one ha) ht.1.le) + have hk0 : 0 ≤ errorKernel t := by unfold errorKernel; positivity + rw [deriv_invLogWeight ht1, Real.norm_eq_abs, abs_mul, abs_neg, abs_of_nonneg hk0] + calc + _ ≤ errorKernel t * (C * errorScale c t) := mul_le_mul_of_nonneg_left (hθ t ⟨ht.1.le, ht.2⟩) hk0 + _ = (errorKernel t * t) * (C * decay c t) := by unfold errorScale decay; ring + _ ≤ (2 / (t * Real.sqrt (Real.log t))) * (C * decay c t) := + mul_le_mul_of_nonneg_right (kernel_comparison ht1 hlt) (mul_nonneg hC (decay_pos c t).le) + _ = _ := by unfold tailKernel; ring + have hint := norm_integral_le_of_norm_le hi (ae_restrict_of_forall_mem measurableSet_Ioc hb) + rw [integral_const_mul] at hint + calc + _ ≤ (2 * C) * ∫ t in Set.Ioc a b, tailKernel c t := hint + _ ≤ (2 * C) * ((2 / c) * decay c a) := + mul_le_mul_of_nonneg_left (tailIntegral_le hc ha hab) (by positivity) + _ = _ := by ring + +theorem uniform_prime_interval_error : ∃ c C a₀ : ℝ, 0 < c ∧ 0 < C ∧ + 1 < a₀ ∧ 1 ≤ Real.log a₀ ∧ + ∀ a b : ℝ, a₀ ≤ a → a ≤ b → + |reciprocalPrimes a b - (Real.log (Real.log b) - Real.log (Real.log a))| ≤ C * decay c a := by + obtain ⟨c, hc, hstrong⟩ := theta_strong + obtain ⟨K, hK, hbound⟩ := hstrong.exists_pos + obtain ⟨x₀, hx₀⟩ := eventually_atTop.mp hbound.bound + let a₀ := max x₀ (Real.exp 1) + have ha₀ : 1 < a₀ := by + have he : 1 < Real.exp 1 := by linarith [Real.exp_one_gt_two] + exact lt_of_lt_of_le he (le_max_right x₀ (Real.exp 1)) + have hlog₀ : 1 ≤ Real.log a₀ := by + have h := Real.log_le_log (Real.exp_pos 1) (le_max_right x₀ (Real.exp 1)) + simpa only [Real.log_exp] using h + refine ⟨c, 2 * K + 4 * K / c, a₀, hc, by positivity, ha₀, hlog₀, ?_⟩ + intro a b haa hab + have ha : 1 < a := lt_of_lt_of_le ha₀ haa + have hb : 1 < b := lt_of_lt_of_le ha hab + have hla : 1 ≤ Real.log a := le_trans hlog₀ (Real.log_le_log (lt_trans zero_lt_one ha₀) haa) + have hlb : 1 ≤ Real.log b := le_trans hla (Real.log_le_log (lt_trans zero_lt_one ha) hab) + have hθ : ∀ t, a₀ ≤ t → |Chebyshev.theta t - t| ≤ K * errorScale c t := by + intro t ht + have ht0 : 0 ≤ t := le_of_lt (lt_of_lt_of_le (lt_trans zero_lt_one ha₀) ht) + have h := hx₀ t (le_trans (le_max_left _ _) ht) + simpa only [Real.norm_eq_abs, abs_of_nonneg (errorScale_nonneg c ht0)] using h + rw [← integral_invLogWeight ha hab, error_identity ha hab] + calc + _ ≤ |invLogWeight b * (Chebyshev.theta b - b)| + |invLogWeight a * (Chebyshev.theta a - a)| + + |∫ t in Set.Ioc a b, deriv invLogWeight t * (Chebyshev.theta t - t)| := + (abs_sub _ _).trans (add_le_add (abs_sub _ _) le_rfl) + _ ≤ K * decay c a + K * decay c a + (4 * K / c) * decay c a := by + apply add_le_add + · apply add_le_add + · exact (endpoint_error_bound hK.le hb hlb (hθ b (le_trans haa hab))).trans + (mul_le_mul_of_nonneg_left (decay_antitone hc.le (lt_trans zero_lt_one ha) hab) hK.le) + · exact endpoint_error_bound hK.le ha hla (hθ a haa) + · exact integral_error_bound hc hK.le ha hla hab (fun t ht => hθ t (le_trans haa ht.1)) + _ = _ := by ring + +end ErdosPrimeInputs.PrimeErrorDecay + + + +namespace ErdosPrimeInputs.HarmonicPrimeMeasure + +open _root_.Filter Asymptotics +open scoped Topology +open StrongChebyshev PrimeAbel PrimeEndpoints PrimeErrorDecay + +lemma reciprocal_le_decay {c : ℝ} (hc : 0 < c) : + ∀ᶠ a : ℝ in atTop, a⁻¹ ≤ decay c a := by + filter_upwards [sqrt_le_errorScale hc, eventually_ge_atTop (1 : ℝ)] with a hs ha + have ha0 : 0 < a := lt_of_lt_of_le zero_lt_one ha + have h := le_trans (Real.one_le_sqrt.mpr ha) hs + rw [inv_eq_one_div] + apply (div_le_iff₀ ha0).mpr + simpa only [errorScale, decay, mul_comm] using h + +theorem uniform_all_endpoints : ∃ c C a₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < a₀ ∧ + ∀ a b : ℝ, a₀ ≤ a → a ≤ b → ∀ lc rc : Bool, + |intervalSum lc rc a b - (Real.log (Real.log b) - Real.log (Real.log a))| ≤ C * decay c a := by + obtain ⟨c, C, a₀, hc, hC, ha₀, hlog₀, h⟩ := uniform_prime_interval_error + obtain ⟨A, hA⟩ := eventually_atTop.mp (reciprocal_le_decay hc) + refine ⟨c, C + 2, max a₀ A, hc, by positivity, lt_of_lt_of_le ha₀ (le_max_left _ _), ?_⟩ + intro a b haa hab lc rc + have ha : 1 < a := lt_of_lt_of_le ha₀ (le_trans (le_max_left _ _) haa) + have herr := h a b (le_trans (le_max_left _ _) haa) hab + have hend := endpoint_difference (lt_trans zero_lt_one ha) hab lc rc + have hinv := hA a (le_trans (le_max_right _ _) haa) + calc + _ ≤ |intervalSum lc rc a b - reciprocalPrimes a b| + + |reciprocalPrimes a b - (Real.log (Real.log b) - Real.log (Real.log a))| := abs_sub_le _ _ _ + _ ≤ 2 / a + C * decay c a := add_le_add hend herr + _ ≤ 2 * decay c a + C * decay c a := add_le_add (by simpa only [div_eq_mul_inv] using mul_le_mul_of_nonneg_left hinv (by norm_num : (0 : ℝ) ≤ 2)) le_rfl + _ = _ := by ring + +noncomputable def primeExponent (w : ℝ) (p : ℕ) : ℝ := Real.log p / Real.log w + +noncomputable def harmonicMass (w : ℝ) (lc rc : Bool) (u v : ℝ) : ℝ := by + classical + exact ∑ p ∈ Nat.primesLE ⌊w ^ v⌋₊, + if intervalGuard lc rc u v (primeExponent w p) then (p : ℝ)⁻¹ else 0 + +lemma exponent_le_iff {w p t : ℝ} (hw : 1 < w) (hp : 0 < p) : + Real.log p / Real.log w ≤ t ↔ p ≤ w ^ t := by + rw [div_le_iff₀ (Real.log_pos hw), ← Real.log_rpow (lt_trans zero_lt_one hw) t, + Real.log_le_log_iff hp (Real.rpow_pos_of_pos (lt_trans zero_lt_one hw) t)] + +lemma exponent_lt_iff {w p t : ℝ} (hw : 1 < w) (hp : 0 < p) : + Real.log p / Real.log w < t ↔ p < w ^ t := by + rw [div_lt_iff₀ (Real.log_pos hw), ← Real.log_rpow (lt_trans zero_lt_one hw) t, + Real.log_lt_log_iff hp (Real.rpow_pos_of_pos (lt_trans zero_lt_one hw) t)] + +lemma le_exponent_iff {w p t : ℝ} (hw : 1 < w) (hp : 0 < p) : + t ≤ Real.log p / Real.log w ↔ w ^ t ≤ p := by + rw [le_div_iff₀ (Real.log_pos hw), ← Real.log_rpow (lt_trans zero_lt_one hw) t, + Real.log_le_log_iff (Real.rpow_pos_of_pos (lt_trans zero_lt_one hw) t) hp] + +lemma lt_exponent_iff {w p t : ℝ} (hw : 1 < w) (hp : 0 < p) : + t < Real.log p / Real.log w ↔ w ^ t < p := by + rw [lt_div_iff₀ (Real.log_pos hw), ← Real.log_rpow (lt_trans zero_lt_one hw) t, + Real.log_lt_log_iff (Real.rpow_pos_of_pos (lt_trans zero_lt_one hw) t) hp] + +lemma harmonicMass_eq_intervalSum {w : ℝ} (hw : 1 < w) (lc rc : Bool) (u v : ℝ) : + harmonicMass w lc rc u v = intervalSum lc rc (w ^ u) (w ^ v) := by + classical + unfold harmonicMass intervalSum + apply Finset.sum_congr rfl + intro p hp + have hp0 : 0 < (p : ℝ) := by exact_mod_cast (Nat.mem_primesLE.mp hp).2.pos + have hg : intervalGuard lc rc u v (primeExponent w p) ↔ + intervalGuard lc rc (w ^ u) (w ^ v) (p : ℝ) := by + cases lc <;> cases rc <;> + simp only [intervalGuard, primeExponent, Bool.false_eq_true, ite_true, ite_false, + exponent_le_iff hw hp0, exponent_lt_iff hw hp0, le_exponent_iff hw hp0, lt_exponent_iff hw hp0] + simp only [hg] + +theorem harmonic_prime_measure : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ u v : ℝ, 1 / 2 ≤ u → u ≤ v → ∀ lc rc : Bool, + |harmonicMass w lc rc u v - (Real.log v - Real.log u)| ≤ + C * Real.exp (-c * Real.sqrt (u * Real.log w)) := by + obtain ⟨c, C, a₀, hc, hC, ha₀, h⟩ := uniform_all_endpoints + refine ⟨c, C, max 2 (a₀ ^ 2), hc, hC, lt_of_lt_of_le (by norm_num) (le_max_left _ _), ?_⟩ + intro w hw u v hu huv lc rc + have hw1 : 1 < w := lt_of_lt_of_le (by norm_num : (1 : ℝ) < 2) (le_trans (le_max_left _ _) hw) + have hw0 : 0 < w := lt_trans zero_lt_one hw1 + have hu0 : 0 < u := lt_of_lt_of_le (by norm_num : (0 : ℝ) < 1 / 2) hu + have hv0 : 0 < v := lt_of_lt_of_le hu0 huv + have hlogw : 0 < Real.log w := Real.log_pos hw1 + have hsqrt : a₀ ≤ Real.sqrt w := by + have hs2 := Real.sq_sqrt hw0.le + have hs0 := Real.sqrt_nonneg w + have haw : a₀ ^ 2 ≤ w := le_trans (le_max_right _ _) hw + nlinarith + have hau : a₀ ≤ w ^ u := le_trans hsqrt (by + rw [Real.sqrt_eq_rpow] + exact Real.rpow_le_rpow_of_exponent_le hw1.le hu) + have huvpow : w ^ u ≤ w ^ v := Real.rpow_le_rpow_of_exponent_le hw1.le huv + have hmain : Real.log (Real.log (w ^ v)) - Real.log (Real.log (w ^ u)) = + Real.log v - Real.log u := by + rw [Real.log_rpow hw0, Real.log_rpow hw0, + Real.log_mul (ne_of_gt hv0) (ne_of_gt hlogw), Real.log_mul (ne_of_gt hu0) (ne_of_gt hlogw)] + ring + have hp := h (w ^ u) (w ^ v) hau huvpow lc rc + rw [hmain] at hp + rw [harmonicMass_eq_intervalSum hw1] + simpa only [decay, Real.log_rpow hw0] using hp + +end ErdosPrimeInputs.HarmonicPrimeMeasure + + + +namespace ErdosPrimeInputs.MertensStrong + +open _root_.Filter Asymptotics _root_.Finset +open scoped Topology +open PrimeAbel PrimeErrorDecay + +lemma second_error_difference {a b : ℝ} (hab : a ≤ b) : + _root_.Erdos970.Mertens.E₂p b - _root_.Erdos970.Mertens.E₂p a = + reciprocalPrimes a b - (Real.log (Real.log b) - Real.log (Real.log a)) := by + have h := Finset.sum_Ioc_consecutive + (fun p : ℕ => if p.Prime then (p : ℝ)⁻¹ else 0) (Nat.zero_le ⌊a⌋₊) (Nat.floor_mono hab) + unfold _root_.Erdos970.Mertens.E₂p reciprocalPrimes + simp only [Finset.sum_filter, one_div] at * + linarith + +theorem second_error_strong : ∃ c C a₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < a₀ ∧ + ∀ a : ℝ, a₀ ≤ a → |_root_.Erdos970.Mertens.E₂p a| ≤ C * decay c a := by + obtain ⟨c,C,a₀,hc,hC,ha₀,_,h⟩ := uniform_prime_interval_error + refine ⟨c,C,a₀,hc,hC,ha₀,?_⟩ + intro a ha + have ht : Tendsto _root_.Erdos970.Mertens.E₂p atTop (𝓝 0) := (isLittleO_one_iff ℝ).mp _root_.Erdos970.Mertens.E₂p.bound' + have hb : |0 - _root_.Erdos970.Mertens.E₂p a| ≤ C * decay c a := by + apply le_of_tendsto (ht.sub_const (_root_.Erdos970.Mertens.E₂p a)).abs + filter_upwards [eventually_ge_atTop a] with b hab + rw [second_error_difference hab] + exact h a b ha hab + simpa only [zero_sub, abs_neg] using hb + +lemma reciprocal_le_decay {c x : ℝ} (hc : c ≤ 1) (hx : 0 < x) (hlog : 1 ≤ Real.log x) : + 1 / x ≤ decay c x := by + have hs := Real.sqrt_nonneg (Real.log x) + have hs2 := Real.sq_sqrt (show 0 ≤ Real.log x by linarith) + have hsmall : Real.sqrt (Real.log x) ≤ Real.log x := by nlinarith + have hexp : -Real.log x ≤ -c * Real.sqrt (Real.log x) := by nlinarith + calc + 1 / x = Real.exp (-Real.log x) := by rw [Real.exp_neg, Real.exp_log hx, one_div] + _ ≤ decay c x := Real.exp_le_exp.mpr hexp + +lemma third_error_identity (x : ℝ) : + _root_.Erdos970.Mertens.E₃ x = + (∑ n ∈ Ioc 0 ⌊x⌋₊, _root_.Erdos970.Mertens.M_eq_summand n - 0) - (_root_.Erdos970.Mertens.M - _root_.Erdos970.Mertens.γ) - _root_.Erdos970.Mertens.E₂p x := by + unfold _root_.Erdos970.Mertens.E₃ _root_.Erdos970.Mertens.E₂p + have h (n : ℕ) : _root_.Erdos970.Mertens.M_eq_summand n = + (if n.Prime then Real.log (1 - 1 / n) else 0) + (if n.Prime then (1 : ℝ) / n else 0) := by + unfold _root_.Erdos970.Mertens.M_eq_summand + split_ifs <;> ring + simp_rw [sub_zero, h] + rw [sum_filter, sum_filter, sum_add_distrib, _root_.Erdos970.Mertens.γ.eq_eulerMascheroni] + ring + +theorem third_error_strong : ∃ c C a₀ : ℝ, 0 < c ∧ 0 < C ∧ 2 ≤ a₀ ∧ + ∀ x : ℝ, a₀ ≤ x → |_root_.Erdos970.Mertens.E₃ x| ≤ C * decay c x := by + obtain ⟨c,C,a₀,hc,hC,ha₀,h⟩ := second_error_strong + let c' := min c 1 + let x₀ := max a₀ (Real.exp 1) + have hc' : 0 < c' := lt_min hc zero_lt_one + have hx₀ : 2 ≤ x₀ := (le_of_lt Real.exp_one_gt_two).trans (le_max_right _ _) + refine ⟨c',C+4,x₀,hc',by positivity,hx₀,?_⟩ + intro x hx + have hx2 : 2 ≤ x := hx₀.trans hx + have hx0 : 0 < x := by linarith + have hlog : 1 ≤ Real.log x := by + have h' := Real.log_le_log (Real.exp_pos 1) ((le_max_right a₀ (Real.exp 1)).trans hx) + simpa only [Real.log_exp] using h' + have hd : decay c x ≤ decay c' x := by + apply Real.exp_le_exp.mpr + have := min_le_left c (1:ℝ) + have := Real.sqrt_nonneg (Real.log x) + dsimp [c'] + nlinarith + rw [third_error_identity] + simp only [sub_zero] + calc + _ ≤ |(∑ n ∈ Ioc 0 ⌊x⌋₊, _root_.Erdos970.Mertens.M_eq_summand n) - (_root_.Erdos970.Mertens.M - _root_.Erdos970.Mertens.γ)| + |_root_.Erdos970.Mertens.E₂p x| := abs_sub _ _ + _ ≤ 4 / x + C * decay c x := add_le_add (_root_.Erdos970.Mertens.sum_M_eq_summand_le' hx2) (h x ((le_max_left _ _).trans hx)) + _ ≤ 4 * decay c' x + C * decay c' x := by + apply add_le_add + · have hrec := reciprocal_le_decay (min_le_right c 1) hx0 hlog + calc + 4 / x = 4 * (1/x) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hrec (by norm_num) + · exact mul_le_mul_of_nonneg_left hd hC.le + _ = (C+4) * decay c' x := by ring + +noncomputable def primeProduct (x : ℝ) : ℝ := + ∏ p ∈ Ioc 0 ⌊x⌋₊ with p.Prime, (1 - (1:ℝ) / p) + +theorem prime_product_strong : ∃ c C x₀ : ℝ, 0 < c ∧ 0 < C ∧ 2 ≤ x₀ ∧ + ∀ x : ℝ, x₀ ≤ x → + |primeProduct x / (Real.exp (-Real.eulerMascheroniConstant) / Real.log x) - 1| ≤ + C * Real.exp (-c * Real.sqrt (Real.log x)) := by + obtain ⟨c,C,a₀,hc,hC,ha₀,h⟩ := third_error_strong + have ht : Tendsto _root_.Erdos970.Mertens.E₃ atTop (𝓝 0) := (isLittleO_one_iff ℝ).mp _root_.Erdos970.Mertens.E₃.bound' + have hs : ∀ᶠ x : ℝ in atTop, |_root_.Erdos970.Mertens.E₃ x| < 1 := + ht.abs.eventually (gt_mem_nhds (show |(0:ℝ)| < 1 by norm_num)) + obtain ⟨x₁,hx₁⟩ := eventually_atTop.mp hs + refine ⟨c,2*C,max a₀ x₁,hc,by positivity,ha₀.trans (le_max_left _ _),?_⟩ + intro x hx + have hxa := (le_max_left a₀ x₁).trans hx + have hxx := (le_max_right a₀ x₁).trans hx + have hx2 : 2 ≤ x := ha₀.trans hxa + have hx1 : 1 < x := by linarith + have hl : Real.log x ≠ 0 := ne_of_gt (Real.log_pos hx1) + have he : primeProduct x / (Real.exp (-Real.eulerMascheroniConstant) / Real.log x) = + Real.exp (_root_.Erdos970.Mertens.E₃ x) := by + rw [primeProduct, _root_.Erdos970.Mertens.prod_one_minus_div_prime_eq hx1] + field_simp + rw [he] + calc + _ ≤ 2 * |_root_.Erdos970.Mertens.E₃ x| := Real.abs_exp_sub_one_le (hx₁ x hxx).le + _ ≤ 2 * (C * decay c x) := mul_le_mul_of_nonneg_left (h x hxa) (by norm_num) + _ = _ := by unfold decay; ring + +end ErdosPrimeInputs.MertensStrong + + + +namespace ErdosInversePrimeBin +open _root_.Filter Asymptotics +open scoped Topology +open ErdosPrimeInputs.StrongChebyshev ErdosPrimeInputs.PrimeErrorDecay + +theorem prime_bin_theta_error : ∃ c C R₀ : ℝ,0 < c ∧ 0 < C ∧ 2 ≤ R₀ ∧ + ∀ R : ℝ,R₀ ≤ R → ∀ xi : ℝ,0 ≤ xi → xi ≤ 1 → + |Chebyshev.theta ((1+xi)*R)-Chebyshev.theta R-xi*R| ≤ 3*C*R*decay c R := by + obtain ⟨c,hc,hstrong⟩ := theta_strong + obtain ⟨C,hC,hbig⟩ := hstrong.exists_pos + obtain ⟨A,hA⟩ := eventually_atTop.mp hbig.bound + refine ⟨c,C,max A 2,hc,hC,le_max_right _ _,?_⟩ + intro R hR xi hxi hxi1 + have hR2 : 2 ≤ R := (le_max_right _ _).trans hR + have hR0 : 0 < R := by linarith + have hRA : A ≤ R := (le_max_left _ _).trans hR + have hbR : R ≤ (1+xi)*R := by nlinarith + have hb2 : (1+xi)*R ≤ 2*R := by nlinarith + have htheta (x : ℝ) (hx : A ≤ x) (hx0 : 0 ≤ x) : + |Chebyshev.theta x-x| ≤ C*(x*decay c x) := by + have h := hA x hx + simp only [Real.norm_eq_abs] at h + rw [abs_of_nonneg (errorScale_nonneg c hx0)] at h + exact h + have hr := htheta R hRA hR0.le + have hb : |Chebyshev.theta ((1+xi)*R)-(1+xi)*R| ≤ 2*C*R*decay c R := by + calc + _ ≤ C*(((1+xi)*R)*decay c ((1+xi)*R)) := htheta _ (hRA.trans hbR) (hR0.le.trans hbR) + _ ≤ C*((2*R)*decay c R) := mul_le_mul_of_nonneg_left + (mul_le_mul hb2 (decay_antitone hc.le hR0 hbR) (decay_pos _ _).le (by positivity)) hC.le + _ = _ := by ring + have he : Chebyshev.theta ((1+xi)*R)-Chebyshev.theta R-xi*R = + (Chebyshev.theta ((1+xi)*R)-(1+xi)*R)-(Chebyshev.theta R-R) := by ring + rw [he] + exact (abs_sub _ _).trans (by nlinarith only [hb,hr]) + +theorem decay_tendsto_zero {c : ℝ} (hc : 0 < c) : Tendsto (decay c) atTop (𝓝 0) := by + have h := Real.tendsto_exp_neg_atTop_nhds_zero.comp + (Tendsto.const_mul_atTop hc (Real.tendsto_sqrt_atTop.comp Real.tendsto_log_atTop)) + convert h using 1 + funext x + simp only [Function.comp_apply,decay,neg_mul] + +theorem uniform_bin_theta_error {eta : ℝ} (heta : 0 < eta) : + ∀ᶠ R : ℝ in atTop,2 ≤ R ∧ ∀ xi : ℝ,eta ≤ xi → xi ≤ 1 → + |Chebyshev.theta ((1+xi)*R)-Chebyshev.theta R-xi*R| ≤ xi*R/2 := by + obtain ⟨c,C,R₀,hc,hC,hR₀,hbound⟩ := prime_bin_theta_error + have hdec : Tendsto (fun R : ℝ => 3*C*decay c R) atTop (𝓝 0) := by + simpa only [mul_zero] using (decay_tendsto_zero hc).const_mul (3*C) + filter_upwards [eventually_ge_atTop R₀, + hdec.eventually (eventually_le_nhds (show 0 < eta/2 by positivity))] with R hR hd + have hR2 := hR₀.trans hR + refine ⟨hR2,?_⟩ + intro xi hxi hxi1 + have hxi0 : 0 ≤ xi := heta.le.trans hxi + have he := hbound R hR xi hxi0 hxi1 + have hm := mul_le_mul_of_nonneg_right hd (show 0 ≤ R by linarith) + have hwidth := mul_le_mul_of_nonneg_right hxi (show 0 ≤ R by linarith) + exact he.trans (by nlinarith only [hm,hwidth]) + +end ErdosInversePrimeBin + + + +namespace ErdosPrimeInputs.PrimePrefixMass + +open _root_.Finset +open StrongChebyshev PrimeAbel PrimeEndpoints PrimeErrorDecay HarmonicPrimeMeasure + +noncomputable def primesBetween (a b : ℝ) : Finset ℕ := + (Nat.primesLE ⌊b⌋₊).filter (fun p => a < (p : ℝ)) + +def decreasingPrefixes (s : Finset ℕ) : Finset (List ℕ) := + s.powerset.image (fun t => t.sort (· ≥ ·)) + +noncomputable def prefixWeight (l : List ℕ) : ℝ := (l.map (fun p : ℕ => (p : ℝ)⁻¹)).prod + +lemma mem_decreasingPrefixes {s : Finset ℕ} {l : List ℕ} : + l ∈ decreasingPrefixes s ↔ l.Pairwise (· > ·) ∧ ∀ p ∈ l, p ∈ s := by + constructor + · intro hl + obtain ⟨t, ht, rfl⟩ := Finset.mem_image.mp hl + refine ⟨t.sortedGT_sort.pairwise, ?_⟩ + intro p hp + apply (Finset.mem_powerset.mp ht) + simpa using hp + · rintro ⟨hp, hs⟩ + have hn : l.Nodup := hp.imp (fun h => ne_of_gt h) + have hge : l.Pairwise (· ≥ ·) := hp.imp (fun h => le_of_lt h) + apply Finset.mem_image.mpr + refine ⟨l.toFinset, Finset.mem_powerset.mpr ?_, (List.toFinset_sort (· ≥ ·) hn).mpr hge⟩ + intro p hp + exact hs p (List.mem_toFinset.mp hp) + +lemma prefixWeight_sort (s : Finset ℕ) : + prefixWeight (s.sort (· ≥ ·)) = ∏ p ∈ s, (p : ℝ)⁻¹ := by + have h := List.prod_toFinset (fun p : ℕ => (p : ℝ)⁻¹) (s.sort_nodup (· ≥ ·)) + simpa only [Finset.sort_toFinset, prefixWeight] using h.symm + +lemma sum_prefixWeights (s : Finset ℕ) : + (∑ l ∈ decreasingPrefixes s, prefixWeight l) = ∏ p ∈ s, (1 + (p : ℝ)⁻¹) := by + rw [decreasingPrefixes, Finset.sum_image] + · simp_rw [prefixWeight_sort] + exact (Finset.prod_one_add s).symm + · intro t ht u hu h + have h' := congrArg List.toFinset h + simpa only [Finset.sort_toFinset] using h' + +lemma prefix_mass_le_exp (s : Finset ℕ) : + (∑ l ∈ decreasingPrefixes s, prefixWeight l) ≤ Real.exp (∑ p ∈ s, (p : ℝ)⁻¹) := by + rw [sum_prefixWeights, Real.exp_sum] + apply Finset.prod_le_prod₀ + · intro p hp + positivity + · intro p hp + simpa only [add_comm] using Real.add_one_le_exp (p : ℝ)⁻¹ + +lemma sum_primesBetween {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) : + (∑ p ∈ primesBetween a b, (p : ℝ)⁻¹) = reciprocalPrimes a b := by + rw [primesBetween, Finset.sum_filter] + exact (reciprocal_eq_core ha hab).symm + +lemma interval_open_closed {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) : + intervalSum false true a b = reciprocalPrimes a b := by + classical + rw [intervalSum, reciprocal_eq_core ha hab] + apply Finset.sum_congr rfl + intro p hp + have hpb : (p : ℝ) ≤ b := (Nat.le_floor_iff (le_trans ha hab)).mp (Nat.mem_primesLE.mp hp).1 + simp [intervalGuard, hpb] + +theorem total_prime_prefix_mass : ∃ M w₀ : ℝ, 0 < M ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell B : ℝ, 1 ≤ ell → ell ≤ B → + (∑ l ∈ decreasingPrefixes (primesBetween (w ^ ell) (w ^ B)), prefixWeight l) ≤ M * B / ell := by + obtain ⟨c, C, w₀, hc, hC, hw₀, h⟩ := harmonic_prime_measure + refine ⟨Real.exp C, w₀, Real.exp_pos C, hw₀, ?_⟩ + intro w hw ell B hell hB + have hw1 := lt_of_lt_of_le hw₀ hw + have hwpos : 0 < w := lt_trans zero_lt_one hw1 + have hellpos : 0 < ell := lt_of_lt_of_le zero_lt_one hell + have hBpos : 0 < B := lt_of_lt_of_le hellpos hB + have hab : w ^ ell ≤ w ^ B := Real.rpow_le_rpow_of_exponent_le hw1.le hB + have ha : 0 ≤ w ^ ell := (Real.rpow_pos_of_pos hwpos ell).le + have hh := h w hw ell B (by linarith) hB false true + rw [harmonicMass_eq_intervalSum hw1, interval_open_closed ha hab] at hh + have hexp : Real.exp (-c * Real.sqrt (ell * Real.log w)) ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc.le) (Real.sqrt_nonneg _)) + have hs : reciprocalPrimes (w ^ ell) (w ^ B) ≤ Real.log B - Real.log ell + C := by + have hu := (abs_le.mp hh).2 + have he := mul_le_mul_of_nonneg_left hexp hC.le + linarith + calc + _ ≤ Real.exp (∑ p ∈ primesBetween (w ^ ell) (w ^ B), (p : ℝ)⁻¹) := prefix_mass_le_exp _ + _ ≤ Real.exp (Real.log B - Real.log ell + C) := by + apply Real.exp_le_exp.mpr + simpa only [sum_primesBetween ha hab] using hs + _ = Real.exp C * B / ell := by + rw [Real.exp_add, Real.exp_sub, Real.exp_log hBpos, Real.exp_log hellpos] + ring + +end ErdosPrimeInputs.PrimePrefixMass + + + +namespace ErdosPrimeInputs.PrimePrefixTail + +open _root_.Finset +open PrimePrefixMass + +noncomputable def longPrefixMass (s : Finset ℕ) (m : ℕ) : ℝ := + ∑ l ∈ (decreasingPrefixes s).filter (fun l => m ≤ l.length), prefixWeight l + +lemma prefixWeight_nonneg (l : List ℕ) : 0 ≤ prefixWeight l := by + unfold prefixWeight + apply List.prod_nonneg + intro x hx + obtain ⟨p, hp, rfl⟩ := List.mem_map.mp hx + positivity + +lemma tilted_weight (l : List ℕ) : + ((l.map (fun p : ℕ => 2 * (p : ℝ)⁻¹)).prod) = (2 : ℝ) ^ l.length * prefixWeight l := by + induction l with + | nil => simp [prefixWeight] + | cons p l ih => simp only [List.map_cons, List.prod_cons, List.length_cons, pow_succ, prefixWeight] at ih ⊢; rw [ih]; ring + +lemma sum_sorted_products (s : Finset ℕ) (f : ℕ → ℝ) : + (∑ l ∈ decreasingPrefixes s, (l.map f).prod) = ∏ p ∈ s, (1 + f p) := by + rw [decreasingPrefixes, Finset.sum_image] + · have hp (t : Finset ℕ) : ((t.sort (· ≥ ·)).map f).prod = ∏ p ∈ t, f p := by + simpa only [Finset.sort_toFinset] using (List.prod_toFinset f (t.sort_nodup (· ≥ ·))).symm + simp_rw [hp] + exact (Finset.prod_one_add s).symm + · intro t ht u hu h + simpa only [Finset.sort_toFinset] using congrArg List.toFinset h + +lemma sum_tilted_weights (s : Finset ℕ) : + (∑ l ∈ decreasingPrefixes s, (2 : ℝ) ^ l.length * prefixWeight l) = + ∏ p ∈ s, (1 + 2 * (p : ℝ)⁻¹) := by + simp_rw [← tilted_weight] + exact sum_sorted_products s _ + +theorem longPrefixMass_le (s : Finset ℕ) (m : ℕ) : + longPrefixMass s m ≤ Real.exp (2 * ∑ p ∈ s, (p : ℝ)⁻¹) / (2 : ℝ) ^ m := by + apply (le_div_iff₀ (pow_pos (by norm_num : (0 : ℝ) < 2) m)).mpr + rw [mul_comm, longPrefixMass, Finset.mul_sum] + calc + _ ≤ ∑ l ∈ (decreasingPrefixes s).filter (fun l => m ≤ l.length), + (2 : ℝ) ^ l.length * prefixWeight l := by + apply Finset.sum_le_sum + intro l hl + exact mul_le_mul_of_nonneg_right + (pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) (Finset.mem_filter.mp hl).2) (prefixWeight_nonneg l) + _ ≤ ∑ l ∈ decreasingPrefixes s, (2 : ℝ) ^ l.length * prefixWeight l := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + intro l hl hnot + exact mul_nonneg (pow_nonneg (by norm_num) _) (prefixWeight_nonneg l) + _ = ∏ p ∈ s, (1 + 2 * (p : ℝ)⁻¹) := sum_tilted_weights s + _ ≤ ∏ p ∈ s, Real.exp (2 * (p : ℝ)⁻¹) := by + apply Finset.prod_le_prod₀ + · intro p hp + positivity + · intro p hp + simpa only [add_comm] using Real.add_one_le_exp (2 * (p : ℝ)⁻¹) + _ = _ := by rw [← Real.exp_sum, ← Finset.mul_sum] + +end ErdosPrimeInputs.PrimePrefixTail + + + +namespace ErdosPrimeInputs.LongPrimePaths + +open _root_.Filter Asymptotics +open scoped Topology +open PrimeAbel PrimeEndpoints PrimeErrorDecay HarmonicPrimeMeasure PrimePrefixMass PrimePrefixTail + +lemma fixed_tilt_tail (C A : ℝ) : ∀ᶠ B : ℝ in atTop, ∀ m : ℕ, + (Real.log B) ^ 2 / 2 ≤ m → + Real.exp (2 * (Real.log B + C)) / (2 : ℝ) ^ m ≤ B ^ (-A) := by + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + filter_upwards [eventually_gt_atTop (1 : ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (max 1 (2 * (A + 2 + 2 * |C|) / Real.log 2)))] with B hB hL + intro m hm + have hb0 : 0 < B := lt_trans zero_lt_one hB + have hl1 : 1 ≤ Real.log B := le_trans (le_max_left _ _) hL + have hl0 : 0 ≤ Real.log B := le_trans zero_le_one hl1 + have ht : 2 * (A + 2 + 2 * |C|) ≤ Real.log B * Real.log 2 := + (div_le_iff₀ hlog2).mp (le_trans (le_max_right _ _) hL) + have ht' := mul_le_mul_of_nonneg_right ht hl0 + have hm' := mul_le_mul_of_nonneg_right hm hlog2.le + have hC' := mul_le_mul_of_nonneg_left hl1 (abs_nonneg C) + have he : 2 * (Real.log B + C) - (m : ℝ) * Real.log 2 ≤ Real.log B * (-A) := by + nlinarith [le_abs_self C] + have hpow : (2 : ℝ) ^ m = Real.exp ((m : ℝ) * Real.log 2) := by + rw [Real.exp_nat_mul, Real.exp_log (by norm_num : (0 : ℝ) < 2)] + rw [hpow, ← Real.exp_sub, Real.rpow_def_of_pos hb0] + exact Real.exp_le_exp.mpr he + +theorem long_prime_paths_superpolynomial : ∃ w₀ : ℝ, 1 < w₀ ∧ + ∀ A : ℝ, ∀ᶠ B : ℝ in atTop, ∀ w : ℝ, w₀ ≤ w → ∀ ell : ℝ, + 1 ≤ ell → ell ≤ B → ∀ m : ℕ, (Real.log B) ^ 2 / 2 ≤ m → + longPrefixMass (primesBetween (w ^ ell) (w ^ B)) m ≤ B ^ (-A) := by + obtain ⟨c, C, w₀, hc, hC, hw₀, h⟩ := harmonic_prime_measure + refine ⟨w₀, hw₀, ?_⟩ + intro A + filter_upwards [fixed_tilt_tail C A] with B htail + intro w hw ell hell hB m hm + have hw1 := lt_of_lt_of_le hw₀ hw + have hwpos : 0 < w := lt_trans zero_lt_one hw1 + have hab : w ^ ell ≤ w ^ B := Real.rpow_le_rpow_of_exponent_le hw1.le hB + have ha : 0 ≤ w ^ ell := (Real.rpow_pos_of_pos hwpos ell).le + have hh := h w hw ell B (by linarith) hB false true + rw [harmonicMass_eq_intervalSum hw1, interval_open_closed ha hab] at hh + have hexp : Real.exp (-c * Real.sqrt (ell * Real.log w)) ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc.le) (Real.sqrt_nonneg _)) + have hsum : (∑ p ∈ primesBetween (w ^ ell) (w ^ B), (p : ℝ)⁻¹) ≤ Real.log B + C := by + rw [sum_primesBetween ha hab] + have hu := (abs_le.mp hh).2 + have he := mul_le_mul_of_nonneg_left hexp hC.le + have hl := Real.log_nonneg hell + linarith + calc + _ ≤ Real.exp (2 * ∑ p ∈ primesBetween (w ^ ell) (w ^ B), (p : ℝ)⁻¹) / (2 : ℝ) ^ m := longPrefixMass_le _ _ + _ ≤ Real.exp (2 * (Real.log B + C)) / (2 : ℝ) ^ m := + div_le_div_of_nonneg_right (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hsum (by norm_num))) (by positivity) + _ ≤ _ := htail m hm + +end ErdosPrimeInputs.LongPrimePaths + + + +namespace ErdosPrimeInputs.HighPrimeGeometry + +open _root_.Finset +open HarmonicPrimeMeasure PrimePrefixMass + +noncomputable def remainingGap (r₀ w : ℝ) (l : List ℕ) : ℝ := + r₀ - (l.map (primeExponent w)).sum + +def cutoff (x : ℕ → ℝ) : ℝ → List ℕ → ℝ + | B, [] => B + | _, p :: ps => cutoff x (x p) ps + +noncomputable def primeCutoff (w B : ℝ) (l : List ℕ) : ℝ := cutoff (primeExponent w) B l + +lemma cutoff_append (x : ℕ → ℝ) (B : ℝ) (pre suf : List ℕ) : + cutoff x B (pre ++ suf) = cutoff x (cutoff x B pre) suf := by + induction pre generalizing B with + | nil => rfl + | cons p pre ih => exact ih (x p) + +lemma cutoff_eq_lastD (x : ℕ → ℝ) (B : ℝ) (l : List ℕ) : + cutoff x B l = (l.map x).getLastD B := by + induction l generalizing B with + | nil => rfl + | cons p l ih => + cases l with + | nil => rfl + | cons q l => simpa [cutoff, List.getLastD] using ih (x p) + +lemma remainingGap_append (r₀ w : ℝ) (pre suf : List ℕ) : + remainingGap r₀ w (pre ++ suf) = remainingGap (remainingGap r₀ w pre) w suf := by + simp only [remainingGap, List.map_append, List.sum_append] + ring + +lemma exponent_monotone {w : ℝ} (hw : 1 < w) : Monotone (primeExponent w) := by + intro p q hpq + have hlogw : 0 ≤ Real.log w := (Real.log_pos hw).le + by_cases hp : p = 0 + · subst p + simp only [primeExponent, Nat.cast_zero, Real.log_zero, zero_div] + exact div_nonneg (Real.log_natCast_nonneg q) hlogw + · have hp0 : 0 < (p : ℝ) := by exact_mod_cast Nat.pos_of_ne_zero hp + exact div_le_div_of_nonneg_right (Real.log_le_log hp0 (by exact_mod_cast hpq)) hlogw + +lemma cutoff_lower (x : ℕ → ℝ) {ell B : ℝ} (hB : ell ≤ B) (l : List ℕ) + (hl : ∀ p ∈ l, ell ≤ x p) : ell ≤ cutoff x B l := by + induction l generalizing B with + | nil => exact hB + | cons p l ih => + exact ih (hl p (by simp)) (fun q hq => hl q (by simp [hq])) + +lemma suffix_le_cutoff (x : ℕ → ℝ) (hx : Monotone x) (B : ℝ) (pre suf : List ℕ) + (hdec : (pre ++ suf).Pairwise (· > ·)) + (hB : ∀ p ∈ pre ++ suf, x p ≤ B) : + ∀ p ∈ suf, x p ≤ cutoff x B pre := by + induction pre generalizing B with + | nil => exact hB + | cons q pre ih => + have hp := List.pairwise_cons.mp hdec + apply ih (x q) hp.2 + intro p hmem + exact hx (le_of_lt (hp.1 p hmem)) + +lemma sum_exponents_le (x : ℕ → ℝ) (l : List ℕ) (b : ℝ) + (hl : ∀ p ∈ l, x p ≤ b) : (l.map x).sum ≤ (l.length : ℝ) * b := by + induction l with + | nil => simp + | cons p l ih => + have hp := hl p (by simp) + have ht := ih (fun q hq => hl q (by simp [hq])) + simp only [List.map_cons, List.sum_cons, List.length_cons, Nat.cast_add, Nat.cast_one] + nlinarith + +lemma prime_exponent_bounds {w ell B : ℝ} (hw : 1 < w) {p : ℕ} + (hp : p ∈ primesBetween (w ^ ell) (w ^ B)) : + ell < primeExponent w p ∧ primeExponent w p ≤ B := by + obtain ⟨hp, hlow⟩ := Finset.mem_filter.mp hp + have hp0 : 0 < (p : ℝ) := by exact_mod_cast (Nat.mem_primesLE.mp hp).2.pos + have hhigh : (p : ℝ) ≤ w ^ B := + (Nat.le_floor_iff (Real.rpow_pos_of_pos (lt_trans zero_lt_one hw) B).le).mp (Nat.mem_primesLE.mp hp).1 + exact ⟨(lt_exponent_iff hw hp0).mpr hlow, (exponent_le_iff hw hp0).mpr hhigh⟩ + +noncomputable def hasHighState (r₀ w B S : ℝ) (l : List ℕ) : Prop := + ∃ pre suf : List ℕ, l = pre ++ suf ∧ + S < remainingGap r₀ w pre / primeCutoff w B pre + +theorem high_short_gap {r₀ w B ell S : ℝ} (hw : 1 < w) (hell : 0 < ell) + (hellB : ell ≤ B) (hS : 0 ≤ S) {l : List ℕ} + (hl : l ∈ decreasingPrefixes (primesBetween (w ^ ell) (w ^ B))) + (hhigh : hasHighState r₀ w B S l) (hshort : (l.length : ℝ) < S / 2) : + S * ell / 2 < remainingGap r₀ w l := by + obtain ⟨pre, suf, rfl, hh⟩ := hhigh + obtain ⟨hdec, hmem⟩ := mem_decreasingPrefixes.mp hl + have hB : ∀ p ∈ pre ++ suf, primeExponent w p ≤ B := fun p hp => + (prime_exponent_bounds hw (hmem p hp)).2 + have hlow : ∀ p ∈ pre, ell ≤ primeExponent w p := fun p hp => + (prime_exponent_bounds hw (hmem p (List.mem_append_left _ hp))).1.le + have hb : ell ≤ primeCutoff w B pre := cutoff_lower (primeExponent w) hellB pre hlow + have hb0 : 0 < primeCutoff w B pre := lt_of_lt_of_le hell hb + have hcut := suffix_le_cutoff (primeExponent w) (exponent_monotone hw) B pre suf hdec hB + have hsum := sum_exponents_le (primeExponent w) suf (primeCutoff w B pre) hcut + have hlen : (suf.length : ℝ) ≤ (List.length (pre ++ suf) : ℝ) := by + simp only [List.length_append, Nat.cast_add] + linarith [Nat.cast_nonneg (α := ℝ) pre.length] + have hmul := mul_le_mul_of_nonneg_right hlen hb0.le + have hshortmul := mul_lt_mul_of_pos_right hshort hb0 + have hbase := mul_le_mul_of_nonneg_left hb hS + have hh := (lt_div_iff₀ hb0).mp hh + rw [remainingGap_append] + unfold remainingGap + change S * primeCutoff w B pre < r₀ - (pre.map (primeExponent w)).sum at hh + nlinarith + +theorem high_small_gap_long {r₀ w B ell S K : ℝ} (hw : 1 < w) (hell : 0 < ell) + (hellB : ell ≤ B) (hS : 0 ≤ S) (hK : K ≤ S * ell / 2) {l : List ℕ} + (hl : l ∈ decreasingPrefixes (primesBetween (w ^ ell) (w ^ B))) + (hhigh : hasHighState r₀ w B S l) (hgap : remainingGap r₀ w l ≤ K) : + S / 2 ≤ (l.length : ℝ) := by + by_contra h + have hs := high_short_gap hw hell hellB hS hl hhigh (lt_of_not_ge h) + linarith + +end ErdosPrimeInputs.HighPrimeGeometry + + + +namespace ErdosPrimeInputs.HighPrimeMass + +open _root_.Finset +open PrimePrefixMass PrimePrefixTail HighPrimeGeometry + +noncomputable def lowGapHighMass (r₀ w B ell S K : ℝ) : ℝ := by + classical + exact ∑ l ∈ (decreasingPrefixes (primesBetween (w ^ ell) (w ^ B))).filter + (fun l => remainingGap r₀ w l ≤ K ∧ hasHighState r₀ w B S l), prefixWeight l + +noncomputable def rewardedHighMass (r₀ w B ell S c : ℝ) : ℝ := by + classical + exact ∑ l ∈ (decreasingPrefixes (primesBetween (w ^ ell) (w ^ B))).filter + (fun l => hasHighState r₀ w B S l ∧ 0 ≤ remainingGap r₀ w l), + prefixWeight l * Real.exp (-c * remainingGap r₀ w l) + +theorem lowGapHighMass_le_long {r₀ w B ell S K : ℝ} (hw : 1 < w) (hell : 0 < ell) + (hellB : ell ≤ B) (hS : 0 ≤ S) (hK : K ≤ S * ell / 2) : + lowGapHighMass r₀ w B ell S K ≤ + longPrefixMass (primesBetween (w ^ ell) (w ^ B)) ⌈S / 2⌉₊ := by + classical + unfold lowGapHighMass longPrefixMass + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro l hl + obtain ⟨hl, hgap, hhigh⟩ := Finset.mem_filter.mp hl + exact Finset.mem_filter.mpr ⟨hl, Nat.ceil_le.mpr + (high_small_gap_long hw hell hellB hS hK hl hhigh hgap)⟩ + · intro l hl hnot + exact prefixWeight_nonneg l + +theorem rewardedHighMass_le {r₀ w B ell S c : ℝ} (hw : 1 < w) (hell : 0 < ell) + (hellB : ell ≤ B) (hS : 0 ≤ S) (hc : 0 < c) : + rewardedHighMass r₀ w B ell S c ≤ + longPrefixMass (primesBetween (w ^ ell) (w ^ B)) ⌈S / 2⌉₊ + + (∑ l ∈ decreasingPrefixes (primesBetween (w ^ ell) (w ^ B)), prefixWeight l) * + Real.exp (-c * (S * ell / 2)) := by + classical + simp only [rewardedHighMass, longPrefixMass, Finset.sum_filter] + rw [Finset.sum_mul, ← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro l hl + have hwgt := prefixWeight_nonneg l + have he := (Real.exp_pos (-c * (S * ell / 2))).le + by_cases hcond : hasHighState r₀ w B S l ∧ 0 ≤ remainingGap r₀ w l + · rw [ite_eq_left hcond] + by_cases hlong : ⌈S / 2⌉₊ ≤ l.length + · rw [ite_eq_left hlong] + have hexp : Real.exp (-c * remainingGap r₀ w l) ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc.le) hcond.2) + have hmul := mul_le_mul_of_nonneg_left hexp hwgt + have hn := mul_nonneg hwgt he + linarith + · rw [ite_eq_right hlong, zero_add] + have hshort : (l.length : ℝ) < S / 2 := Nat.lt_ceil.mp (lt_of_not_ge hlong) + have hgap := high_short_gap hw hell hellB hS hl hcond.1 hshort + apply mul_le_mul_of_nonneg_left _ hwgt + apply Real.exp_le_exp.mpr + nlinarith + · rw [ite_eq_right hcond] + apply add_nonneg + · split_ifs <;> positivity + · exact mul_nonneg hwgt he + +end ErdosPrimeInputs.HighPrimeMass + + + +namespace ErdosPrimeInputs.HighPrimeRemoval + +open _root_.Filter Asymptotics +open scoped Topology +open PrimePrefixMass PrimePrefixTail LongPrimePaths HighPrimeGeometry HighPrimeMass + +lemma lowGapHighMass_nonneg (r₀ w B ell S K : ℝ) : 0 ≤ lowGapHighMass r₀ w B ell S K := by + classical + unfold lowGapHighMass + exact Finset.sum_nonneg (fun l _ => prefixWeight_nonneg l) + +lemma rewardedHighMass_nonneg (r₀ w B ell S c : ℝ) : 0 ≤ rewardedHighMass r₀ w B ell S c := by + classical + unfold rewardedHighMass + exact Finset.sum_nonneg (fun l _ => mul_nonneg (prefixWeight_nonneg l) (Real.exp_pos _).le) + +lemma large_gap_saving {c : ℝ} (hc : 0 < c) (A : ℝ) : ∀ᶠ B : ℝ in atTop, + B * Real.exp (-c * ((Real.log B) ^ 2 / 2)) ≤ B ^ (-A) := by + filter_upwards [eventually_gt_atTop (1 : ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (max 1 (2 * (A + 1) / c)))] with B hB hL + have hb0 : 0 < B := lt_trans zero_lt_one hB + have hl0 : 0 ≤ Real.log B := le_trans zero_le_one (le_trans (le_max_left _ _) hL) + have ht : 2 * (A + 1) ≤ Real.log B * c := + (div_le_iff₀ hc).mp (le_trans (le_max_right _ _) hL) + have hm := mul_le_mul_of_nonneg_right ht hl0 + have he : Real.log B + (-c * ((Real.log B) ^ 2 / 2)) ≤ Real.log B * (-A) := by nlinarith + calc + _ = Real.exp (Real.log B + (-c * ((Real.log B) ^ 2 / 2))) := by + rw [Real.exp_add, Real.exp_log hb0] + _ ≤ Real.exp (Real.log B * (-A)) := Real.exp_le_exp.mpr he + _ = _ := (Real.rpow_def_of_pos hb0 (-A)).symm + +theorem low_gap_high_removal : ∃ w₀ : ℝ, 1 < w₀ ∧ + ∀ K : ℝ, 0 < K → ∀ A : ℝ, ∀ᶠ B : ℝ in atTop, + ∀ w : ℝ, w₀ ≤ w → ∀ ell : ℝ, 1 ≤ ell → ell ≤ B → ∀ r₀ : ℝ, + lowGapHighMass r₀ w B ell ((Real.log B) ^ 2) K ≤ B ^ (-A) := by + obtain ⟨w₀, hw₀, htail⟩ := long_prime_paths_superpolynomial + refine ⟨w₀, hw₀, ?_⟩ + intro K hK A + filter_upwards [htail A, + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (2 * K + 1))] with B hB hlog + intro w hw ell hell hellB r₀ + have hw1 : 1 < w := lt_of_lt_of_le hw₀ hw + have hell0 : 0 < ell := lt_of_lt_of_le zero_lt_one hell + have hsmall : K ≤ (Real.log B) ^ 2 / 2 := by nlinarith + have hprod := mul_le_mul_of_nonneg_left hell (sq_nonneg (Real.log B)) + have hsmall' : K ≤ (Real.log B) ^ 2 * ell / 2 := by nlinarith + exact (lowGapHighMass_le_long hw1 hell0 hellB (sq_nonneg _) hsmall').trans + (hB w hw ell hell hellB _ (Nat.le_ceil _)) + +theorem rewarded_high_removal : ∃ M w₀ : ℝ, 0 < M ∧ 1 < w₀ ∧ + ∀ c : ℝ, 0 < c → ∀ A : ℝ, ∀ᶠ B : ℝ in atTop, + ∀ w : ℝ, w₀ ≤ w → ∀ ell : ℝ, 1 ≤ ell → ell ≤ B → ∀ r₀ : ℝ, + rewardedHighMass r₀ w B ell ((Real.log B) ^ 2) c ≤ M * B ^ (-A) := by + obtain ⟨M, wMass, hM, hwMass, hmass⟩ := total_prime_prefix_mass + obtain ⟨wTail, hwTail, htail⟩ := long_prime_paths_superpolynomial + refine ⟨1 + M, max wMass wTail, by positivity, lt_of_lt_of_le hwMass (le_max_left _ _), ?_⟩ + intro c hc A + filter_upwards [htail A, large_gap_saving hc A] with B htailB hrewardB + intro w hw ell hell hellB r₀ + have hwM : wMass ≤ w := le_trans (le_max_left _ _) hw + have hwT : wTail ≤ w := le_trans (le_max_right _ _) hw + have hw1 : 1 < w := lt_of_lt_of_le hwMass hwM + have hell0 : 0 < ell := lt_of_lt_of_le zero_lt_one hell + have hB0 : 0 < B := lt_of_lt_of_le hell0 hellB + have hmassB : (∑ l ∈ decreasingPrefixes (primesBetween (w ^ ell) (w ^ B)), prefixWeight l) ≤ M * B := + (hmass w hwM ell B hell hellB).trans (div_le_self (mul_nonneg hM.le hB0.le) hell) + have hE : Real.exp (-c * ((Real.log B) ^ 2 * ell / 2)) ≤ + Real.exp (-c * ((Real.log B) ^ 2 / 2)) := by + have hp := mul_le_mul_of_nonneg_left hell (sq_nonneg (Real.log B)) + apply Real.exp_le_exp.mpr + nlinarith + calc + _ ≤ longPrefixMass (primesBetween (w ^ ell) (w ^ B)) ⌈(Real.log B) ^ 2 / 2⌉₊ + + (∑ l ∈ decreasingPrefixes (primesBetween (w ^ ell) (w ^ B)), prefixWeight l) * + Real.exp (-c * ((Real.log B) ^ 2 * ell / 2)) := + rewardedHighMass_le hw1 hell0 hellB (sq_nonneg _) hc + _ ≤ B ^ (-A) + (M * B) * Real.exp (-c * ((Real.log B) ^ 2 / 2)) := by + apply add_le_add + · exact htailB w hwT ell hell hellB _ (Nat.le_ceil _) + · exact mul_le_mul hmassB hE (Real.exp_pos _).le (mul_nonneg hM.le hB0.le) + _ ≤ B ^ (-A) + M * B ^ (-A) := by + apply add_le_add le_rfl + rw [mul_assoc] + exact mul_le_mul_of_nonneg_left hrewardB hM.le + _ = (1 + M) * B ^ (-A) := by ring + +end ErdosPrimeInputs.HighPrimeRemoval + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/IgnoredDenominatorPrimes.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/IgnoredDenominatorPrimes.lean new file mode 100644 index 0000000000000000000000000000000000000000..c28ed6820f72ff8ff252f2f302f8b98edd258ef9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/IgnoredDenominatorPrimes.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualUnalignedIncidence +import OAI.NumberTheory.Jacobsthal.Partitions.BoxInflation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosSourceCollision +open ErdosInversePrimeBin ErdosLineCollision ErdosRichLine ErdosInverseBoxHeight + +noncomputable def ignoredPrimes (P : Finset ℕ) (d : ℕ) : Finset ℕ := by + classical + exact P.filter (fun p => p ∣ d) + +theorem ignoredPrimes_card_le (P : Finset ℕ) (d : ℕ) (hd : 0 < d) + (hP : ∀ p ∈ P,Nat.Prime p) (z alpha : ℝ) (hz : 1 < z) (ha : 0 < alpha) + (hlarge : ∀ p ∈ P,z^alpha ≤ (p : ℝ)) (hheight : (d : ℝ) ≤ z) : + ((ignoredPrimes P d).card : ℝ) ≤ 1/alpha := by + have he : ignoredPrimes P d = dividingPrimes P (d : ℤ) := by + classical + ext p + simp only [ignoredPrimes,dividingPrimes,Finset.mem_filter,Int.natCast_dvd_natCast] + rw [he] + apply dividingPrimes_card_bound P (d : ℤ) (by exact_mod_cast hd.ne') hP z alpha 1 hz ha hlarge + simpa only [Int.cast_natCast,abs_of_nonneg (show (0 : ℝ) ≤ d from Nat.cast_nonneg d),Real.rpow_one] using hheight + +theorem source_denominator_le_z {z R Z d : ℝ} (hz : 1 < z) (_hR : 0 ≤ R) (hZ : 0 ≤ Z) + (hRz : R ≤ z^((1 : ℝ)/100)) (hZz : Z ≤ z^((1 : ℝ)/100)) (hd : d ≤ R*Z^10) : d ≤ z := by + have hz0 : 0 < z := by linarith + have hZ10 : Z^10 ≤ z^((10 : ℝ)/100) := by + calc + _ ≤ (z^((1 : ℝ)/100))^10 := by gcongr + _ = _ := by rw [← Real.rpow_mul_natCast hz0.le];norm_num + calc + d ≤ R*Z^10 := hd + _ ≤ z^((1 : ℝ)/100)*z^((10 : ℝ)/100) := by gcongr + _ = z^((11 : ℝ)/100) := by rw [← Real.rpow_add hz0];norm_num + _ ≤ z := by + have hh := Real.rpow_le_rpow_of_exponent_le hz.le (by norm_num : (11 : ℝ)/100 ≤ 1) + simpa only [Real.rpow_one] using hh + +end ErdosSourceCollision + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/IntervalPrimesDefinition.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/IntervalPrimesDefinition.lean new file mode 100644 index 0000000000000000000000000000000000000000..2cd227bb9bca4853bb7afbb0add7214e362e16fe --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/IntervalPrimesDefinition.lean @@ -0,0 +1,33 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open Finset + +noncomputable def intervalPrimes (x H : ℝ) (q : ℕ) (r : ℤ) : Finset ℕ := + (range (⌊max (x+H) 0⌋₊+1)).filter (fun p => + p.Prime ∧ x < (p:ℝ) ∧ (p:ℝ) ≤ x+H ∧ Int.ModEq (q:ℤ) (p:ℤ) r) + +theorem mem_intervalPrimes (x H : ℝ) (q : ℕ) (r : ℤ) (p : ℕ) : + p ∈ intervalPrimes x H q r ↔ + p.Prime ∧ x < (p:ℝ) ∧ (p:ℝ) ≤ x+H ∧ Int.ModEq (q:ℤ) (p:ℤ) r := by + constructor + · intro h + exact (mem_filter.mp h).2 + · intro h + apply mem_filter.mpr + refine ⟨mem_range.mpr (Nat.lt_succ_of_le ?_),h⟩ + exact (Nat.le_floor_iff (le_max_right _ _)).mpr (h.2.2.1.trans (le_max_left _ _)) + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/IsolatedRealPrimeRange.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/IsolatedRealPrimeRange.lean new file mode 100644 index 0000000000000000000000000000000000000000..be43c38c02891290cc50f462af01fe6918287c26 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/IsolatedRealPrimeRange.lean @@ -0,0 +1,37 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CrossingBandGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.IsolatedRealPrimeRange +open LogarithmicBinScale LogarithmicBinEndpoints PrimeBinRepresentatives IsolatedBinGeometry + +theorem isolated_real_range {w top xi B alpha beta : ℝ} (hw : 1 < w) (htop : w < top) + (hxi : 0 < xi) (hpower : w^B=top) {b : Fin (binCount w top xi)} + (hb : isolatedBin w top xi B alpha beta b) : + top^alpha ≤ lower w top xi b ∧ upper w top xi b ≤ top^beta := by + have hw0 : 0 < w := zero_lt_one.trans hw + have htop0 : 0 < top := hw0.trans htop + have hlow : 0 < lower w top xi b := endpoint_pos hw0 _ + have hupp : 0 < upper w top xi b := hlow.trans (bin_source_bounds hw0 htop hxi b).2.1 + have hlog : Real.log top=B*Real.log w := by rw [← hpower,Real.log_rpow hw0] + have hlo : alpha*B*Real.log w ≤ Real.log (lower w top xi b) := + (le_div_iff₀ (Real.log_pos hw)).mp hb.1 + have hhi : Real.log (upper w top xi b) ≤ beta*B*Real.log w := + (div_le_iff₀ (Real.log_pos hw)).mp hb.2 + constructor + · apply (Real.log_le_log_iff (Real.rpow_pos_of_pos htop0 alpha) hlow).mp + rw [Real.log_rpow htop0,hlog] + nlinarith + · apply (Real.log_le_log_iff hupp (Real.rpow_pos_of_pos htop0 beta)).mp + rw [Real.log_rpow htop0,hlog] + nlinarith +end NumberTheoryLean.IsolatedRealPrimeRange + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/KloostermanPrimeBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/KloostermanPrimeBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..c53870dc299fb4ec56d6fee65a27eb10333ca3ce --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/KloostermanPrimeBound.lean @@ -0,0 +1,85 @@ +import OAI.NumberTheory.Jacobsthal.Probability.KloostermanFourthMoment + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators ComplexConjugate + +namespace ErdosKloosterman + +attribute [local instance] Classical.decEq + +variable {F : Type*} [Field F] [Fintype F] + +private theorem fourth_product_eq_norm (z : ℂ) : + z*z*conj z*conj z = ((‖z‖^4 : ℝ) : ℂ) := by + calc + _ = (z * conj z)^2 := by ring + _ = _ := by + rw [Complex.mul_conj, Complex.normSq_eq_norm_sq, ← Complex.ofReal_pow] + congr 1 + ring + +theorem fourth_norm_identity (ψ : AddChar F ℂ) (hψ : ψ.IsPrimitive) : + (∑ a : F, ∑ b : F, ‖sum ψ a b‖^4) = + (Fintype.card F : ℝ)^2 * (pairCollisions F).card := by + have h := fourth_moment_identity ψ hψ + simp_rw [fourth_product_eq_norm] at h + exact_mod_cast h + +private theorem unit_orbit_bound (ψ : AddChar F ℂ) (a b : F) (ha : a ≠ 0) : + (Fintype.card Fˣ : ℝ) * ‖sum ψ a b‖^4 ≤ + ∑ x : F × F, ‖sum ψ x.1 x.2‖^4 := by + let f : Fˣ → F × F := fun c => (a * (c : F), b * (↑c⁻¹ : F)) + have hf : Function.Injective f := by + intro c d h + apply Units.ext + exact mul_left_cancel₀ ha (congrArg Prod.fst h) + have heq : (∑ x ∈ Finset.univ.image f, ‖sum ψ x.1 x.2‖^4) = + (Fintype.card Fˣ : ℝ) * ‖sum ψ a b‖^4 := by + rw [Finset.sum_image] + · simp only [f, sum_unit_scale, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + · exact fun c _ d _ h => hf h + rw [← heq] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun _ _ _ => by positivity) + +theorem fourth_norm_le (ψ : AddChar F ℂ) (hψ : ψ.IsPrimitive) + (a b : F) (hab : a ≠ 0 ∨ b ≠ 0) : + ‖sum ψ a b‖^4 ≤ 3 * (Fintype.card F : ℝ)^3 := by + have left (a b : F) (ha : a ≠ 0) : + ‖sum ψ a b‖^4 ≤ 3 * (Fintype.card F : ℝ)^3 := by + have horbit := unit_orbit_bound ψ a b ha + rw [Fintype.sum_prod_type, fourth_norm_identity ψ hψ] at horbit + have hc : ((pairCollisions F).card : ℝ) ≤ 3 * (Fintype.card Fˣ : ℝ)^2 := by + exact_mod_cast pairCollisions_card_le F + have hu : (0 : ℝ) < Fintype.card Fˣ := by exact_mod_cast Fintype.card_pos + have hf : (Fintype.card Fˣ : ℝ) ≤ (Fintype.card F : ℝ) := by + exact_mod_cast Fintype.card_le_of_injective (fun x : Fˣ => (x : F)) Units.val_injective + have hbound : (Fintype.card Fˣ : ℝ) * ‖sum ψ a b‖^4 ≤ + (Fintype.card Fˣ : ℝ) * (3 * (Fintype.card F : ℝ)^2 * Fintype.card Fˣ) := by + calc + _ ≤ (Fintype.card F : ℝ)^2 * (pairCollisions F).card := horbit + _ ≤ (Fintype.card F : ℝ)^2 * (3 * (Fintype.card Fˣ : ℝ)^2) := + mul_le_mul_of_nonneg_left hc (sq_nonneg _) + _ = _ := by ring + have hcancel := (mul_le_mul_iff_right₀ hu).mp hbound + calc + _ ≤ 3 * (Fintype.card F : ℝ)^2 * Fintype.card Fˣ := hcancel + _ ≤ 3 * (Fintype.card F : ℝ)^2 * Fintype.card F := + mul_le_mul_of_nonneg_left hf (by positivity) + _ = _ := by ring + rcases hab with ha | hb + · exact left a b ha + · rw [sum_swap] + exact left b a hb + +end ErdosKloosterman + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/LargePrimeDeletion.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/LargePrimeDeletion.lean new file mode 100644 index 0000000000000000000000000000000000000000..f488a065a1a017bfcc81015f4af67628346d7103 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/LargePrimeDeletion.lean @@ -0,0 +1,272 @@ +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Mathlib.Data.Int.CardIntervalMod +import Mathlib.Data.Nat.Prime.Int +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.Ring +import OAI.NumberTheory.Jacobsthal.Conclusions.Targets +import OAI.NumberTheory.Jacobsthal.Sieve.AlignedPrimeCongruence + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.LargePrimeDeletion + +open scoped BigOperators + +def cutoffPrimes (z : ℕ) : Finset ℕ := + (Finset.range (z + 1)).filter Nat.Prime + +@[simp] theorem mem_cutoffPrimes {p z : ℕ} : + p ∈ cutoffPrimes z ↔ p.Prime ∧ p ≤ z := by + simp only [cutoffPrimes, Finset.mem_filter, Finset.mem_range, Nat.lt_succ_iff, and_comm] + +def largePrimeFactors (n z : ℕ) : Finset ℕ := + n.primeFactors.filter fun p => z < p + +@[simp] theorem mem_largePrimeFactors {n z p : ℕ} : + p ∈ largePrimeFactors n z ↔ p ∈ n.primeFactors ∧ z < p := by + simp [largePrimeFactors] + +noncomputable def deletionCell (C : Finset ℕ) (a : ℤ) (q : ℕ) : Finset ℕ := by + classical + exact C.filter fun i => (q : ℤ) ∣ a + i + +@[simp] theorem mem_deletionCell {C : Finset ℕ} {a : ℤ} {q i : ℕ} : + i ∈ deletionCell C a q ↔ i ∈ C ∧ (q : ℤ) ∣ a + i := by + classical + simp [deletionCell] + +def divisibilityResidue (a : ℤ) (q : ℕ) : ℕ := ((-a) % q).toNat + +theorem divisibility_iff_modEq (a : ℤ) {q : ℕ} (hq : 0 < q) (i : ℕ) : + (q : ℤ) ∣ a + i ↔ Nat.ModEq q i (divisibilityResidue a q) := by + have hqz : (0 : ℤ) < q := by exact_mod_cast hq + have hr : ((divisibilityResidue a q : ℕ) : ℤ) = (-a) % q := by + exact Int.toNat_of_nonneg (Int.emod_nonneg _ (ne_of_gt hqz)) + rw [← Int.natCast_modEq_iff, hr, Int.ModEq, Int.emod_emod, ← Int.ModEq, + Int.modEq_iff_dvd] + have heq : -a - (i : ℤ) = -(a + i) := by ring + rw [heq, Int.dvd_neg] + +theorem card_deletionCell_range (Y : ℕ) (a : ℤ) {q : ℕ} (hq : 0 < q) : + (deletionCell (Finset.range Y) a q).card = + Y / q + if divisibilityResidue a q % q < Y % q then 1 else 0 := by + classical + unfold deletionCell + simp_rw [divisibility_iff_modEq a hq] + rw [← Nat.count_eq_card_filter_range] + exact Nat.count_modEq_card Y hq (divisibilityResidue a q) + +theorem card_deletionCell_le_div_add_one {Y : ℕ} (a : ℤ) + (C : Finset ℕ) (hC : C ⊆ Finset.range Y) {q : ℕ} (hq : 0 < q) : + (deletionCell C a q).card ≤ Y / q + 1 := by + classical + have hsub : deletionCell C a q ⊆ deletionCell (Finset.range Y) a q := by + intro i hi + obtain ⟨hiC, hdiv⟩ := mem_deletionCell.mp hi + exact mem_deletionCell.mpr ⟨hC hiC, hdiv⟩ + have hcount := Finset.card_le_card hsub + rw [card_deletionCell_range Y a hq] at hcount + split_ifs at hcount <;> omega + +theorem card_deletionCell_le_real_div_add_one {Y : ℕ} (a : ℤ) + (C : Finset ℕ) (hC : C ⊆ Finset.range Y) {q : ℕ} (hq : 0 < q) : + ((deletionCell C a q).card : ℝ) ≤ (Y : ℝ) / q + 1 := by + calc + ((deletionCell C a q).card : ℝ) ≤ ((Y / q + 1 : ℕ) : ℝ) := by + exact_mod_cast card_deletionCell_le_div_add_one a C hC hq + _ ≤ (Y : ℝ) / q + 1 := by + push_cast + exact add_le_add (show ((Y / q : ℕ) : ℝ) ≤ (Y : ℝ) / q from Nat.cast_div_le) le_rfl + +noncomputable def cutoffSurvivors (Y z : ℕ) (residue : ℕ → ℕ) : Finset ℕ := + SievePartition.survivors (Finset.range Y) (cutoffPrimes z) + (SievePartition.residueBad residue) + +@[simp] theorem mem_cutoffSurvivors {Y z i : ℕ} {residue : ℕ → ℕ} : + i ∈ cutoffSurvivors Y z residue ↔ + i < Y ∧ ∀ p, p.Prime → p ≤ z → i % p ≠ residue p % p := by + classical + simp only [cutoffSurvivors, SievePartition.mem_survivors, Finset.mem_range, + mem_cutoffPrimes, SievePartition.residueBad] + tauto + +def CompatibleSmallResidues (n z : ℕ) (a : ℤ) (residue : ℕ → ℕ) : Prop := + ∀ p ∈ n.primeFactors, p ≤ z → residue p % p = divisibilityResidue a p % p + +theorem divisibilityResidues_compatible (n z : ℕ) (a : ℤ) : + CompatibleSmallResidues n z a (divisibilityResidue a) := by + intro p _ _ + rfl + +theorem cutoffSurvivors_avoid_small {Y n z : ℕ} {a : ℤ} {residue : ℕ → ℕ} + (hcompat : CompatibleSmallResidues n z a residue) : + ∀ i ∈ cutoffSurvivors Y z residue, ∀ p ∈ n.primeFactors, + p ≤ z → ¬ (p : ℤ) ∣ a + i := by + intro i hi p hp hpz hdiv + have hprime := (Nat.mem_primeFactors.mp hp).1 + have hres := (divisibility_iff_modEq a hprime.pos i).mp hdiv + have hav := (mem_cutoffSurvivors.mp hi).2 p hprime hpz + apply hav + rw [hcompat p hp hpz] + exact hres + +noncomputable def coprimeOffsets (Y n : ℕ) (a : ℤ) : Finset ℕ := by + classical + exact (Finset.range Y).filter fun i => (a + i).natAbs.Coprime n + +@[simp] theorem mem_coprimeOffsets {Y n i : ℕ} {a : ℤ} : + i ∈ coprimeOffsets Y n a ↔ i < Y ∧ (a + i).natAbs.Coprime n := by + classical + simp [coprimeOffsets] + +theorem coprime_iff_avoid_primeFactors {n : ℕ} (hn : 0 < n) (x : ℤ) : + x.natAbs.Coprime n ↔ ∀ p ∈ n.primeFactors, ¬ (p : ℤ) ∣ x := by + constructor + · intro hc p hp hpx + obtain ⟨hprime, hpn, _⟩ := Nat.mem_primeFactors.mp hp + have hpx' : p ∣ x.natAbs := Int.natCast_dvd.mp hpx + exact hprime.not_dvd_one (by simpa only [hc.gcd_eq_one] using Nat.dvd_gcd hpx' hpn) + · intro hav + apply Nat.coprime_of_dvd + intro p hp hpx hpn + exact hav p (Nat.mem_primeFactors.mpr ⟨hp, hpn, ne_of_gt hn⟩) + (Int.natCast_dvd.mpr hpx) + +theorem candidate_subset_coprime_union_deletions + {Y n z : ℕ} (hn : 0 < n) (a : ℤ) (C : Finset ℕ) + (hC : C ⊆ Finset.range Y) + (hsmall : ∀ i ∈ C, ∀ p ∈ n.primeFactors, p ≤ z → ¬ (p : ℤ) ∣ a + i) : + C ⊆ coprimeOffsets Y n a ∪ + (largePrimeFactors n z).biUnion (deletionCell C a) := by + classical + intro i hi + by_cases hcop : (a + i).natAbs.Coprime n + · exact Finset.mem_union_left _ (mem_coprimeOffsets.mpr + ⟨Finset.mem_range.mp (hC hi), hcop⟩) + · have hbad : ∃ p ∈ n.primeFactors, (p : ℤ) ∣ a + i := by + by_contra h + apply hcop + rw [coprime_iff_avoid_primeFactors hn] + intro p hp hpi + exact h ⟨p, hp, hpi⟩ + obtain ⟨p, hp, hpi⟩ := hbad + have hlarge : z < p := lt_of_not_ge (fun hpz => hsmall i hi p hp hpz hpi) + exact Finset.mem_union_right _ (Finset.mem_biUnion.mpr + ⟨p, mem_largePrimeFactors.mpr ⟨hp, hlarge⟩, mem_deletionCell.mpr ⟨hi, hpi⟩⟩) + +theorem card_le_coprime_add_large_deletions + {Y n z : ℕ} (hn : 0 < n) (a : ℤ) (C : Finset ℕ) + (hC : C ⊆ Finset.range Y) + (hsmall : ∀ i ∈ C, ∀ p ∈ n.primeFactors, p ≤ z → ¬ (p : ℤ) ∣ a + i) : + C.card ≤ (coprimeOffsets Y n a).card + + ∑ q ∈ largePrimeFactors n z, (deletionCell C a q).card := by + classical + calc + C.card ≤ (coprimeOffsets Y n a ∪ + (largePrimeFactors n z).biUnion (deletionCell C a)).card := + Finset.card_le_card (candidate_subset_coprime_union_deletions hn a C hC hsmall) + _ ≤ (coprimeOffsets Y n a).card + + ((largePrimeFactors n z).biUnion (deletionCell C a)).card := Finset.card_union_le _ _ + _ ≤ (coprimeOffsets Y n a).card + + ∑ q ∈ largePrimeFactors n z, (deletionCell C a q).card := + Nat.add_le_add_left Finset.card_biUnion_le _ + +theorem exists_coprime_of_survivor_budget + {Y n z k : ℕ} (hn : 0 < n) (hcard : n.primeFactors.card ≤ k) + (a : ℤ) (C : Finset ℕ) (hC : C ⊆ Finset.range Y) + (hsmall : ∀ i ∈ C, ∀ p ∈ n.primeFactors, p ≤ z → ¬ (p : ℤ) ∣ a + i) + {R : ℝ} (hR : 0 ≤ R) + (hupper : ∀ q ∈ largePrimeFactors n z, ((deletionCell C a q).card : ℝ) ≤ R) + (hbudget : (k : ℝ) * R < C.card) : + ∃ i : ℕ, i < Y ∧ (a + i).natAbs.Coprime n := by + classical + have hlargecard : (largePrimeFactors n z).card ≤ k := + (Finset.card_filter_le _ _).trans hcard + have hsum : (∑ q ∈ largePrimeFactors n z, ((deletionCell C a q).card : ℝ)) ≤ + (k : ℝ) * R := by + calc + _ ≤ ∑ _q ∈ largePrimeFactors n z, R := Finset.sum_le_sum hupper + _ = ((largePrimeFactors n z).card : ℝ) * R := by simp + _ ≤ (k : ℝ) * R := mul_le_mul_of_nonneg_right (by exact_mod_cast hlargecard) hR + have hcountR : (C.card : ℝ) ≤ ((coprimeOffsets Y n a).card : ℝ) + + ∑ q ∈ largePrimeFactors n z, ((deletionCell C a q).card : ℝ) := by + exact_mod_cast card_le_coprime_add_large_deletions hn a C hC hsmall + have hpos : 0 < (coprimeOffsets Y n a).card := by + have hposR : (0 : ℝ) < (coprimeOffsets Y n a).card := by linarith + exact_mod_cast hposR + obtain ⟨i, hi⟩ := Finset.card_pos.mp hpos + exact ⟨i, mem_coprimeOffsets.mp hi⟩ + +theorem large_deletionCell_le_cutoff {Y z : ℕ} (a : ℤ) + (C : Finset ℕ) (hC : C ⊆ Finset.range Y) {q : ℕ} (hqz : z < q) : + ((deletionCell C a q).card : ℝ) ≤ (Y : ℝ) / (z + 1) + 1 := by + have hq : 0 < q := lt_of_le_of_lt (Nat.zero_le z) hqz + have hzq : (z : ℝ) + 1 ≤ q := by exact_mod_cast Nat.succ_le_of_lt hqz + have hz : (0 : ℝ) < (z : ℝ) + 1 := by positivity + calc + ((deletionCell C a q).card : ℝ) ≤ (Y : ℝ) / q + 1 := + card_deletionCell_le_real_div_add_one a C hC hq + _ ≤ (Y : ℝ) / (z + 1) + 1 := by + exact add_le_add (div_le_div_of_nonneg_left (Nat.cast_nonneg Y) hz hzq) le_rfl + +theorem sum_large_deletions_le_elementary {Y n z k : ℕ} + (hcard : n.primeFactors.card ≤ k) (a : ℤ) + (C : Finset ℕ) (hC : C ⊆ Finset.range Y) : + (∑ q ∈ largePrimeFactors n z, ((deletionCell C a q).card : ℝ)) ≤ + (k : ℝ) * ((Y : ℝ) / (z + 1) + 1) := by + have hlargecard : (largePrimeFactors n z).card ≤ k := + (Finset.card_filter_le _ _).trans hcard + calc + _ ≤ ∑ _q ∈ largePrimeFactors n z, ((Y : ℝ) / (z + 1) + 1) := by + apply Finset.sum_le_sum + intro q hq + exact large_deletionCell_le_cutoff a C hC (mem_largePrimeFactors.mp hq).2 + _ = ((largePrimeFactors n z).card : ℝ) * ((Y : ℝ) / (z + 1) + 1) := by simp [mul_add] + _ ≤ (k : ℝ) * ((Y : ℝ) / (z + 1) + 1) := by + apply mul_le_mul_of_nonneg_right (by exact_mod_cast hlargecard) + positivity + +theorem exists_coprime_of_cutoff_estimates + {Y n z k : ℕ} (hn : 0 < n) (hcard : n.primeFactors.card ≤ k) + (a : ℤ) (residue : ℕ → ℕ) + (hcompat : CompatibleSmallResidues n z a residue) + {S R : ℝ} (hR : 0 ≤ R) + (hlower : S ≤ (cutoffSurvivors Y z residue).card) + (hupper : ∀ q ∈ largePrimeFactors n z, + ((deletionCell (cutoffSurvivors Y z residue) a q).card : ℝ) ≤ R) + (hbudget : (k : ℝ) * R < S) : + ∃ i : ℕ, i < Y ∧ (a + i).natAbs.Coprime n := by + apply exists_coprime_of_survivor_budget hn hcard a (cutoffSurvivors Y z residue) + · intro i hi + exact Finset.mem_range.mpr (mem_cutoffSurvivors.mp hi).1 + · exact cutoffSurvivors_avoid_small hcompat + · exact hR + · exact hupper + · exact hbudget.trans_le hlower + +theorem isJacobsthalBound_of_cutoff_estimates + (Y z k : ℕ) {S R : ℝ} (hR : 0 ≤ R) + (hlower : ∀ residue : ℕ → ℕ, S ≤ (cutoffSurvivors Y z residue).card) + (hupper : ∀ (residue : ℕ → ℕ) (a : ℤ) (q : ℕ), q.Prime → z < q → + ((deletionCell (cutoffSurvivors Y z residue) a q).card : ℝ) ≤ R) + (hbudget : (k : ℝ) * R < S) : + Targets.IsJacobsthalBound k Y := by + intro n hn hcard a + apply exists_coprime_of_cutoff_estimates hn hcard a (divisibilityResidue a) + (divisibilityResidues_compatible n z a) hR (hlower _) + · intro q hq + obtain ⟨hqn, hqz⟩ := mem_largePrimeFactors.mp hq + exact hupper _ a q (Nat.mem_primeFactors.mp hqn).1 hqz + · exact hbudget + +end NumberTheoryLean.LargePrimeDeletion + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/LatePrimeRatio.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/LatePrimeRatio.lean new file mode 100644 index 0000000000000000000000000000000000000000..1daaa003a12406d4120e66b363c94e31b12c8f7a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/LatePrimeRatio.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RepeatedWordData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.LatePrimeRatio +open FinitePathGeometry PrimeHistories PrimeTiltGeometry RepeatedWordData + +attribute [local instance] Classical.propDecidable + +theorem child_ratio_min {w ell S : ℝ} (z : Node) {p : ℕ} (hp : p ∈ nodeChildren w ell S z) : + minRatio z.side z.ratio ≤ (step w z p).ratio := (Finset.mem_filter.mp hp).2.2.2.1 + +theorem two_step_ratio_one {w ell S : ℝ} (z : Node) {p q : ℕ} + (hp : p ∈ nodeChildren w ell S z) (hq : q ∈ nodeChildren w ell S (step w z p)) : + 1 ≤ (step w (step w z p) q).ratio := by + have h1 := child_ratio_min z hp + have h2 := child_ratio_min (step w z p) hq + cases hi : z.side with + | even => + have hside : (step w z p).side=.odd := by simp [step,hi,Side.flip] + rw [hside] at h2 + exact (by norm_num : (1:ℝ)≤2).trans ((le_max_left _ _).trans h2) + | odd => + rw [hi] at h1 + have hfirst : 2 ≤ (step w z p).ratio := (le_max_left _ _).trans h1 + have hside : (step w z p).side=.even := by simp [step,hi,Side.flip] + rw [hside] at h2 + change (step w z p).ratio-1 ≤ (step w (step w z p) q).ratio at h2 + linarith + +theorem allowed_late_ratio_one {w ell S : ℝ} (z : Node) (ps : List ℕ) + (hp : allowed w ell S z ps) (hlen : 2 ≤ ps.length) : 1 ≤ (terminal w z ps).ratio := by + induction ps generalizing z with + | nil => simp at hlen + | cons p ps ih => + obtain ⟨hhead,hrest⟩ := (allowed_cons w ell S z p ps).mp hp + cases ps with + | nil => simp at hlen + | cons q qs => + cases qs with + | nil => + have hq := ((allowed_cons w ell S (step w z p) q []).mp hrest).1 + exact two_step_ratio_one z hhead hq + | cons r rs => exact ih (step w z p) hrest (by simp) + +theorem allowed_late_gap_cutoff {w ell S : ℝ} (hw : 1 < w) (hell : 1 ≤ ell) + (z : Node) (ps : List ℕ) (hp : allowed w ell S z ps) (hlen : 2 ≤ ps.length) : + (terminal w z ps).cutoff ≤ (terminal w z ps).gap := by + have hne : ps ≠ [] := by intro he; simp [he] at hlen + let h : History w ell S z := ⟨ps,hp⟩ + have hx := history_nonempty_cutoff_gt hw h hne + have hx0 : 0 < (terminal w z ps).cutoff := by change ell < (terminal w z ps).cutoff at hx; linarith + have hr := allowed_late_ratio_one z ps hp hlen + have he := CandidateTerminalGeometry.terminal_ratio_div_cutoff w z ps hne hx0.ne' + rw [he] at hr + exact (one_le_div hx0).mp hr +end NumberTheoryLean.LatePrimeRatio + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/LiteralUniformPrimeTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/LiteralUniformPrimeTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..03579fab0ce03416a6a737c3b32e64ad061679c3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/LiteralUniformPrimeTail.lean @@ -0,0 +1,237 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CorrectedCompactTransfer +import OAI.NumberTheory.Jacobsthal.Estimates.ScaledOriginalTail +import OAI.NumberTheory.Jacobsthal.Partitions.CompactSelectedPartition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PrimeFamilyOccupation +open _root_.Filter _root_.Finset +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +theorem removed_signed_reward_bound {w ell S c : ℝ} (hw : 1 < w) + {start : Node} (hsS : start.ratio ≤ S) (F : List ℕ → ℝ) + (hF : ∀ ps ∈ uncappedPrefixes w ell start, + |F ps| ≤ Real.exp (-c*(terminal w start ps).gap)) : + |(∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps) - + (∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps)| ≤ + uncappedRewardedHighMass w ell start S c := by + classical + have hp := uncapped_sum_partition (ell := ell) hw hsS (fun ps => prefixWeight ps*F ps) + have he : (∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps) - + (∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps) = + ∑ ps ∈ (uncappedPrefixes w ell start).filter (actualHasHigh w S start),prefixWeight ps*F ps := by + linarith only [hp] + rw [he] + calc + _ ≤ ∑ ps ∈ (uncappedPrefixes w ell start).filter (actualHasHigh w S start), + |prefixWeight ps*F ps| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ _ := by + apply Finset.sum_le_sum + intro ps hps + rw [abs_mul,abs_of_nonneg (prefixWeight_nonneg ps)] + exact mul_le_mul_of_nonneg_left (hF ps (Finset.mem_filter.mp hps).1) (prefixWeight_nonneg ps) + +theorem removed_signed_reward_every_power : + ∃ M w₀ : ℝ,0 < M ∧ 1 < w₀ ∧ ∀ c : ℝ,0 < c → ∀ A : ℝ,∀ᶠ B : ℝ in atTop, + ∀ w : ℝ,w₀ ≤ w → ∀ ell : ℝ,1 ≤ ell → ell ≤ B → ∀ start : Node, + start.cutoff = B → 0 < start.gap → Valid start.side start.ratio → Consistent start → + start.ratio ≤ (Real.log B)^2 → ∀ F : List ℕ → ℝ, + (∀ ps ∈ uncappedPrefixes w ell start,|F ps| ≤ Real.exp (-c*(terminal w start ps).gap)) → + |(∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps) - + (∑ ps ∈ retainedPrefixes w ell ((Real.log B)^2) start,prefixWeight ps*F ps)| ≤ M*B^(-A) := by + obtain ⟨M,w₀,hM,hw₀,hbound⟩ := uncapped_rewarded_high_removal + refine ⟨M,w₀,hM,hw₀,?_⟩ + intro c hc A + filter_upwards [hbound c hc A] with B hB + intro w hw ell hell hellB start hcut hr hs hcons hsS F hF + exact (removed_signed_reward_bound (hw₀.trans_le hw) hsS F hF).trans + (hB w hw ell hell hellB start hcut hr hs hcons) + +end NumberTheoryLean.PrimeFamilyOccupation + +end + +section + +namespace NumberTheoryLean.LiteralPrimeOccupation + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeFamilyOccupation +open PrimeCompactWeights CompactInverseTest CompactNormalizationCorrection ScaledOriginalTail DerivativeWeights +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def nodeReward (H : Side → ℝ×ℝ → ℝ) (w : ℝ) (start : Node) (ps : List ℕ) : ℝ := + H (terminal w start ps).side ((terminal w start ps).gap,(terminal w start ps).ratio) + +noncomputable def familyValue (H : Side → ℝ×ℝ → ℝ) (w ell S : ℝ) (start : Node) : ℝ := + (start.gap^2/weight start.side start.ratio)* + (∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*nodeReward H w start ps) + +noncomputable def sourceFactor (B : ℝ) (start : Node) : ℝ := + B^2*weight start.side start.ratio/start.gap^2 + +theorem signed_weight_test_identity {w ell S B : ℝ} {start : Node} + (hs : Valid start.side start.ratio) (H : Side → ℝ×ℝ → ℝ) (z : ChainState w ell S start) : + scaledWeight w B start z*listReward (nodeReward H w start) z = + sourceFactor B start*correctedTest (inverseTest H) z := by + cases z with + | none => simp [scaledWeight,listReward,correctedTest] + | some h => + have hv : Valid h.node.side h.node.ratio := terminal_valid hs h.admissible + change scaledWeight w B start (some h)*H h.node.side (h.node.gap,h.node.ratio) = + sourceFactor B start*((1+epsilon w)^h.primes.length*inverseTest H h.node.side (h.node.gap,h.node.ratio)) + rw [inverseTest_eq hv] + unfold scaledWeight sourceFactor + ring + +theorem literal_corrected_occupation {w ell S B : ℝ} {start : Node} + (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) + (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) (H : Side → ℝ×ℝ → ℝ) : + familyValue H w ell S start = correctedExpectation (inverseTest H) w ell S start (LowStateHorizon.sourceHorizon S B) := by + have he := finite_signed_original_occupation hw hell hS0 hS hr hs hsS hB hsize (nodeReward H w start) + simp_rw [signed_weight_test_identity hs H,integral_const_mul] at he + rw [← Finset.mul_sum] at he + have hf : 0 < sourceFactor B start := by unfold sourceFactor; have hp := weight_pos hs; positivity + apply mul_left_cancel₀ hf.ne' + calc + _ = B^2*(∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*nodeReward H w start ps) := by + unfold sourceFactor familyValue + field_simp [(weight_pos hs).ne',hr.ne'] + _ = _ := he.symm + +noncomputable def tailListReward (c K w : ℝ) (start : Node) (ps : List ℕ) : ℝ := + if K < (terminal w start ps).gap then Real.exp (-c*(terminal w start ps).gap) else 0 + +theorem tailListReward_nonneg (c K w : ℝ) (start : Node) (ps : List ℕ) : 0 ≤ tailListReward c K w start ps := by + unfold tailListReward + split_ifs <;> positivity + +theorem tail_weight_test_identity {w ell S B : ℝ} {start : Node} (c K : ℝ) (z : ChainState w ell S start) : + ENNReal.ofReal (scaledWeight w B start z*listReward (tailListReward c K w start) z) = scaledTail c K w B start z := by + cases z with + | none => simp [scaledWeight,listReward,scaledTail] + | some h => + change ENNReal.ofReal (scaledWeight w B start (some h)*(if K < h.node.gap then Real.exp (-c*h.node.gap) else 0)) = _ + change ENNReal.ofReal (scaledWeight w B start (some h)*(if K < h.node.gap then Real.exp (-c*h.node.gap) else 0)) = + if K < h.node.gap then ENNReal.ofReal (scaledWeight w B start (some h)*Real.exp (-c*h.node.gap)) else 0 + by_cases hh : K < h.node.gap + · rw [ite_eq_left hh,ite_eq_left hh] + · rw [ite_eq_right hh,ite_eq_right hh,mul_zero,ENNReal.ofReal_zero] + +theorem literal_scaled_tail {w ell S B : ℝ} {start : Node} + (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) + (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) (c K : ℝ) : + ENNReal.ofReal (B^2*(∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*tailListReward c K w start ps)) = + ∑ n ∈ range (LowStateHorizon.sourceHorizon S B),∫⁻ z,scaledTail c K w B start z ∂pathLaw w ell S start n := by + have he := finite_nonnegative_original_occupation hw hell hS0 hS hr hs hsS hB hsize + (tailListReward c K w start) (fun ps _ => tailListReward_nonneg c K w start ps) + simp_rw [tail_weight_test_identity c K] at he + exact he.symm + +end NumberTheoryLean.LiteralPrimeOccupation + +end + +section + +namespace NumberTheoryLean.LiteralUniformPrimeTail + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualPrimeHigh PrimeFamilyOccupation LiteralPrimeOccupation ScaledOriginalTail +open UniformBudgetRate LowStateHorizon ErdosPrimeInputs.PrimePrefixMass + +theorem tailListReward_envelope (c K w : ℝ) (start : Node) (ps : List ℕ) : + |tailListReward c K w start ps| ≤ Real.exp (-c*(terminal w start ps).gap) := by + unfold tailListReward + split_ifs + · rw [abs_of_pos (Real.exp_pos _)] + · rw [abs_zero]; exact (Real.exp_pos _).le + +theorem actual_uniform_original_prime_tail (d c ε : ℝ) (hd : 0 < d) (hc : 0 < c) (hε : 0 < ε) : + ∃ M₀ : ℕ,∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ + ∀ M : ℕ,M₀ ≤ M → ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + ∀ ell : ℝ,1 ≤ ell → ell ≤ B → Real.log B ≤ d*Real.log w → + ∀ start : Node,start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + B^2*(∑ ps ∈ uncappedPrefixes w ell start, + prefixWeight ps*tailListReward c (3*((M:ℝ)+1)) w start ps) ≤ ε := by + obtain ⟨M₀,BL,wL,hBL,hwL,hlow⟩ := actual_uniform_scaled_tail d c (ε/2) hd hc (by linarith) + obtain ⟨Crem,wH,hCrem,hwH,hremove⟩ := removed_signed_reward_every_power + obtain ⟨BH,hBH⟩ := eventually_atTop.mp (hremove c hc 3) + obtain ⟨wScale,hwScale⟩ := eventually_atTop.mp + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + let B₀ := max BL (max BH (max (Real.exp 2) (2*Crem/ε))) + let w₀ := max wL (max wH (max normalizationThreshold wScale)) + refine ⟨M₀,B₀,w₀,hBL.trans_le (le_max_left _ _),hwL.trans_le (le_max_left _ _),?_⟩ + intro M hM B w hB hw ell hell hellB hcomp start hi h199 h23 hcons hcut + have hBL' : BL ≤ B := (le_max_left _ _).trans hB + have hBH' : BH ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hB + have hBexp : Real.exp 2 ≤ B := + (le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) (le_max_right _ _)).trans hB + have hBlarge : 2*Crem/ε ≤ B := + (le_trans (le_trans (le_max_right _ _) (le_max_right _ _)) (le_max_right _ _)).trans hB + have hBpos : 0 < B := hBL.trans_le hBL' + have hlogB : 2 ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hBexp + have hwL' : wL ≤ w := (le_max_left _ _).trans hw + have hwH' : wH ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hnorm : normalizationThreshold ≤ w := + (le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) (le_max_right _ _)).trans hw + have hwScale' : wScale ≤ w := + (le_trans (le_trans (le_max_right _ _) (le_max_right _ _)) (le_max_right _ _)).trans hw + have hscale := source_scale_bound (hwScale w hwScale') hlogB hcomp + let S := (Real.log B)^2 + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hsS : start.ratio ≤ S := by linarith + have he : B*start.ratio = start.gap := by + have hh : start.cutoff = start.gap/start.ratio := hcons + rw [hcut] at hh + exact (eq_div_iff (valid_pos hs).ne').mp hh + have hr : 0 < start.gap := by rw [← he]; exact mul_pos hBpos (valid_pos hs) + have hsize : start.gap ≤ (23/10:ℝ)*B := by nlinarith + let F := tailListReward c (3*((M:ℝ)+1)) w start + have hretained : B^2*(∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps) ≤ ε/2 := by + apply (ENNReal.ofReal_le_ofReal_iff (by linarith : 0 ≤ ε/2)).mp + rw [literal_scaled_tail hnorm hell hS0 hscale.1 hr hs hsS hBpos hsize] + exact hlow M hM B w hBL' hwL' ell hell hellB hcomp start hi h199 h23 hcons hcut + have hremoved := hBH B hBH' w hwH' ell hell hellB start hcut hr hs hcons hsS F + (fun ps _ => tailListReward_envelope c (3*((M:ℝ)+1)) w start ps) + have hremovedScaled : B^2*(Crem*B^(-(3:ℝ))) ≤ ε/2 := by + have heq : B^2*(Crem*B^(-(3:ℝ))) = Crem/B := by + rw [Real.rpow_neg hBpos.le,Real.rpow_ofNat] + field_simp + rw [heq] + apply (div_le_iff₀ hBpos).mpr + have hh := (div_le_iff₀ hε).mp hBlarge + nlinarith + have hdiff := mul_le_mul_of_nonneg_left hremoved (sq_nonneg B) + have htriangle : B^2*(∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps) ≤ + B^2*(∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps)+ + B^2*|(∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps)- + (∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps)| := by + have hh := mul_le_mul_of_nonneg_left (le_abs_self + ((∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps)- + (∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps))) (sq_nonneg B) + nlinarith + linarith + +end NumberTheoryLean.LiteralUniformPrimeTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/LogarithmicPrimeLength.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/LogarithmicPrimeLength.lean new file mode 100644 index 0000000000000000000000000000000000000000..af7b03d413b2f10a6158216b5282e0ca6e6dc77a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/LogarithmicPrimeLength.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Primes.HighPrimeRemoval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.LogarithmicPrimeLength +open _root_.Filter +open ErdosPrimeInputs PrimeAbel PrimeEndpoints PrimeErrorDecay HarmonicPrimeMeasure PrimePrefixMass PrimePrefixTail + +theorem fixed_log_length_tilt (C A L : ℝ) (hL : A+3 ≤ L*Real.log 2) : + ∀ᶠ B : ℝ in atTop,∀ m : ℕ,L*Real.log B ≤ m → + Real.exp (2*(Real.log B+C))/(2:ℝ)^m ≤ B^(-A) := by + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + filter_upwards [eventually_gt_atTop (1:ℝ), + Real.tendsto_log_atTop.eventually_ge_atTop (max 1 (2*|C|))] with B hB hlog + intro m hm + have hBp : 0 < B := zero_lt_one.trans hB + have hlog0 : 0 ≤ Real.log B := by linarith [le_max_left (1:ℝ) (2*|C|)] + have hC : 2*C ≤ Real.log B := by linarith [le_max_right (1:ℝ) (2*|C|),le_abs_self C] + have hm' := mul_le_mul_of_nonneg_right hm hlog2.le + have hL' := mul_le_mul_of_nonneg_right hL hlog0 + have he : 2*(Real.log B+C)-(m:ℝ)*Real.log 2 ≤ Real.log B*(-A) := by nlinarith + have hpow : (2:ℝ)^m=Real.exp ((m:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul,Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [hpow,← Real.exp_sub,Real.rpow_def_of_pos hBp] + exact Real.exp_le_exp.mpr he + +theorem logarithmic_prime_length_tail : ∃ w₀ : ℝ,1 < w₀ ∧ ∀ A : ℝ,∃ L : ℝ,1 ≤ L ∧ + ∀ᶠ B : ℝ in atTop,∀ w : ℝ,w₀ ≤ w → ∀ m : ℕ,L*Real.log B ≤ m → + longPrefixMass (primesBetween w (w^B)) m ≤ B^(-A) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hPrime⟩ := harmonic_prime_measure + refine ⟨w₀,hw₀,?_⟩ + intro A + let L := (|A|+4)/Real.log 2 + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hlog2up : Real.log 2 ≤ 1 := by + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hL : 1 ≤ L := (le_div_iff₀ hlog2).mpr (by linarith [abs_nonneg A]) + have hcoef : A+3 ≤ L*Real.log 2 := by + dsimp [L] + rw [div_mul_cancel₀ _ hlog2.ne'] + linarith [le_abs_self A] + refine ⟨L,hL,?_⟩ + filter_upwards [fixed_log_length_tilt C A L hcoef,eventually_ge_atTop (1:ℝ)] with B hTail hB + intro w hw m hm + have hw1 := hw₀.trans_le hw + have hw0 : 0 < w := zero_lt_one.trans hw1 + have hab : w ≤ w^B := by + simpa only [Real.rpow_one] using Real.rpow_le_rpow_of_exponent_le hw1.le hB + have hh := hPrime w hw 1 B (by norm_num) hB false true + rw [harmonicMass_eq_intervalSum hw1,Real.rpow_one,interval_open_closed hw0.le hab] at hh + have hexp : Real.exp (-c*Real.sqrt (1*Real.log w)) ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc.le) (Real.sqrt_nonneg _)) + have hsum : (∑ p ∈ primesBetween w (w^B),(p:ℝ)⁻¹) ≤ Real.log B+C := by + rw [sum_primesBetween hw0.le hab] + have hu := (abs_le.mp hh).2 + simp only [Real.log_one,sub_zero] at hu + linarith [mul_le_mul_of_nonneg_left hexp hC.le] + calc + _ ≤ Real.exp (2*∑ p ∈ primesBetween w (w^B),(p:ℝ)⁻¹)/(2:ℝ)^m := longPrefixMass_le _ _ + _ ≤ Real.exp (2*(Real.log B+C))/(2:ℝ)^m := + div_le_div_of_nonneg_right (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hsum (by norm_num))) (by positivity) + _ ≤ _ := hTail m hm +end NumberTheoryLean.LogarithmicPrimeLength + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/OddPrimeRoots.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/OddPrimeRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..9c2c68c9fcb9a393fb406d816c06bde7efccfa76 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/OddPrimeRoots.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.StationaryFibres + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman.PrimePower + +attribute [local instance] Classical.decEq + +def primeReduction (p s : ℕ) (hs : 0 < s) : ZMod (p^s) →+* ZMod p := + ZMod.castHom (dvd_pow_self p (by omega)) (ZMod p) + +theorem isUnit_iff_primeReduction_ne_zero (p s : ℕ) [Fact p.Prime] (hs : 0 < s) + (x : ZMod (p^s)) : IsUnit x ↔ primeReduction p s hs x ≠ 0 := by + have hx : primeReduction p s hs x = (x.val : ZMod p) := by + rw [primeReduction, ZMod.castHom_apply, ZMod.cast_eq_val] + rw [hx, ne_eq, ZMod.natCast_eq_zero_iff] + nth_rw 1 [← x.natCast_zmod_val] + exact ZMod.isUnit_natCast_iff_not_dvd_pow (Fact.out : p.Prime) hs + +theorem eq_or_neg_of_sq_eq_odd (p s : ℕ) [Fact p.Prime] (hs : 0 < s) (hp2 : p ≠ 2) + (x y : ZMod (p^s)) (hy : IsUnit y) (hxy : x^2 = y^2) : x = y ∨ x = -y := by + let f := primeReduction p s hs + have hyf : f y ≠ 0 := (isUnit_iff_primeReduction_ne_zero p s hs y).mp hy + have htwo : (2 : ZMod p) ≠ 0 := by + intro h + have hd : p ∣ 2 := (ZMod.natCast_eq_zero_iff 2 p).mp h + rcases (Nat.dvd_prime Nat.prime_two).mp hd with hp1 | hp2' + · exact (Fact.out : p.Prime).ne_one hp1 + · exact hp2 hp2' + have hfactor : (x-y)*(x+y) = 0 := by linear_combination hxy + have hunits : IsUnit (x-y) ∨ IsUnit (x+y) := by + rw [isUnit_iff_primeReduction_ne_zero p s hs, + isUnit_iff_primeReduction_ne_zero p s hs] + change f (x-y) ≠ 0 ∨ f (x+y) ≠ 0 + by_cases hm : f (x-y) = 0 + · right + have he : f x = f y := sub_eq_zero.mp (by simpa only [map_sub] using hm) + rw [map_add, he, ← two_mul] + exact mul_ne_zero htwo hyf + · exact Or.inl hm + rcases hunits with hm | hp + · right + exact eq_neg_of_add_eq_zero_left ((hm.mul_right_eq_zero).mp hfactor) + · left + exact sub_eq_zero.mp ((hp.mul_left_eq_zero).mp hfactor) + +theorem quadraticUnitRoots_card_le_two (p s : ℕ) [Fact p.Prime] (hs : 0 < s) + (hp2 : p ≠ 2) (a b : ZMod (p^s)) (ha : IsUnit a) : + (quadraticUnitRoots (p^s) a b).card ≤ 2 := by + by_cases hempty : (quadraticUnitRoots (p^s) a b).Nonempty + · obtain ⟨y, hy⟩ := hempty + obtain ⟨hyunit, hyeq⟩ := (Finset.mem_filter.mp hy).2 + have hsubset : quadraticUnitRoots (p^s) a b ⊆ {y,-y} := by + intro x hx + obtain ⟨_, hxeq⟩ := (Finset.mem_filter.mp hx).2 + have hsq : x^2 = y^2 := by + rcases ha with ⟨u, rfl⟩ + have h := congrArg (fun z : ZMod (p^s) => (↑u⁻¹ : ZMod (p^s)) * z) + (hxeq.trans hyeq.symm) + simpa only [Units.inv_mul_cancel_left] using h + rcases eq_or_neg_of_sq_eq_odd p s hs hp2 x y hyunit hsq with he | he + · exact Finset.mem_insert.mpr (Or.inl he) + · exact Finset.mem_insert.mpr (Or.inr (Finset.mem_singleton.mpr he)) + exact (Finset.card_le_card hsubset).trans (by simpa using Finset.card_insert_le y ({-y} : Finset (ZMod (p^s)))) + · rw [Finset.not_nonempty_iff_eq_empty.mp hempty] + simp + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/OriginalPrimeBlocks.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/OriginalPrimeBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..fa8ec6ebd71a799a9c6beb6ad5583716df51456e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/OriginalPrimeBlocks.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CommonSliceGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosLargeHeightBlocks + + +noncomputable def blockPrimes (C0 : ℤ) (R xi : ℝ) (H i : ℕ) : Finset ℕ := + ErdosTagSubbins.subbin R xi (blockCount C0 R xi H) i + +theorem mem_blockPrimes (C0 : ℤ) (R xi : ℝ) (H i p : ℕ) + (hR : 0 < R) (hxi : 0 < xi) : + p ∈ blockPrimes C0 R xi H i ↔ p.Prime ∧ + blockLeft C0 R xi H i < (p : ℝ) ∧ (p : ℝ) ≤ blockRight C0 R xi H i := + ErdosTagSubbins.mem_subbin hR hxi (blockCount_pos C0 R xi H) + +theorem block_partition (C0 : ℤ) (R xi : ℝ) (H : ℕ) (hR : 0 < R) (hxi : 0 < xi) : + (Finset.univ : Finset (Fin (blockCount C0 R xi H))).biUnion + (fun i => blockPrimes C0 R xi H i) = ErdosInversePrimeBin.primeBin R xi := + ErdosTagSubbins.finite_partition hR hxi (blockCount_pos C0 R xi H) + +theorem block_pairwise_disjoint (C0 : ℤ) (R xi : ℝ) (H : ℕ) (hR : 0 < R) (hxi : 0 < xi) : + Pairwise (fun i j : Fin (blockCount C0 R xi H) => + Disjoint (blockPrimes C0 R xi H i) (blockPrimes C0 R xi H j)) := + ErdosTagSubbins.subbins_pairwise_disjoint hR hxi (blockCount_pos C0 R xi H) + +theorem unique_original_prime_block (C0 : ℤ) (R xi : ℝ) (H p : ℕ) + (hR : 0 < R) (hxi : 0 < xi) (hp : p ∈ ErdosInversePrimeBin.primeBin R xi) : + ∃! i : Fin (blockCount C0 R xi H), p ∈ blockPrimes C0 R xi H i := + ErdosTagSubbins.unique_prime_subbin hR hxi (blockCount_pos C0 R xi H) hp + +theorem original_prime_sum {B : Type*} [AddCommMonoid B] + (C0 : ℤ) (R xi : ℝ) (H : ℕ) (hR : 0 < R) (hxi : 0 < xi) (f : ℕ → B) : + (∑ p ∈ ErdosInversePrimeBin.primeBin R xi, f p) = + ∑ i : Fin (blockCount C0 R xi H), ∑ p ∈ blockPrimes C0 R xi H i, f p := + ErdosTagSubbins.sum_partition hR hxi (blockCount_pos C0 R xi H) f + +theorem block_width_sum (C0 : ℤ) (R xi : ℝ) (H : ℕ) : + (∑ i : Fin (blockCount C0 R xi H), + (blockRight C0 R xi H i-blockLeft C0 R xi H i)) = xi*R := by + simp only [blockRight,blockLeft,ErdosTagSubbins.right_sub_left,Finset.sum_const, + Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + rw [ErdosTagSubbins.total_step (blockCount_pos C0 R xi H)] + ring + +theorem last_block_endpoint (C0 : ℤ) (R xi : ℝ) (H : ℕ) : + blockRight C0 R xi H (blockCount C0 R xi H-1) = (1+xi)*R := by + have hn : 1 ≤ blockCount C0 R xi H := blockCount_pos C0 R xi H + rw [blockRight,ErdosTagSubbins.right,Nat.sub_add_cancel hn, + ErdosTagSubbins.total_step (blockCount_pos C0 R xi H)] + ring + +theorem final_upper_endpoint_included (C0 : ℤ) (R xi : ℝ) (H p : ℕ) + (hR : 0 < R) (hxi : 0 < xi) (hp : p.Prime) (he : (p : ℝ)=(1+xi)*R) : + p ∈ blockPrimes C0 R xi H (blockCount C0 R xi H-1) := by + apply ErdosTagSubbins.upper_endpoint_included hR hxi (blockCount_pos C0 R xi H) hp + exact he.trans (last_block_endpoint C0 R xi H).symm + +end ErdosLargeHeightBlocks + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PaperMissingPrimeWindow.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PaperMissingPrimeWindow.lean new file mode 100644 index 0000000000000000000000000000000000000000..dba968bd93783cd33ca1e2a10e3597ae1d2c51f1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PaperMissingPrimeWindow.lean @@ -0,0 +1,291 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalSourceScale +import OAI.NumberTheory.Jacobsthal.Probability.MarkedOccurrenceProbability +import OAI.NumberTheory.Jacobsthal.Probability.UncappedCompactEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.MovingPrimeWindowProbability + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualCoupledHistories FlaggedSourceStart FiniteHistoryTransport PriorPrimeWindow +open CompactPrefixOccurrence MarkedOccurrenceProbability MarkedSourceSmallness ExponentialMesh +open SourceSelectedCompactOccupation SourceCouplingRate +open Erdos970Dependency.MarkedVisits + +theorem source_missing_window_probability : ∃ κ₀ : ℝ, 0 < κ₀ ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∀ R d eps : ℝ, 0 < d → 0 < eps → + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → ∃ w₀ : ℝ, 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ, ∀ start : Node, ∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → w ≤ start.gap → + let S := (Real.log B)^2 + let N := LowStateHorizon.sourceHorizon S B + ∀ E : Set (List ℕ), + (∀ p : History w ell S start,p.primes ∈ E → p.node.gap ≤ R ∧ + ¬hasPrimeWindow w (K*(Real.log w)^2) (rho*K*(Real.log w)^2) start p.primes) → + fullSourceLaw w ell S start hs (mesh κ w) N {h | occurs E N h} ≤ ENNReal.ofReal eps := by + obtain ⟨κ₀,hκ₀,hCouple⟩ := source_coupling_rate + refine ⟨κ₀,hκ₀,?_⟩ + intro κ hκ hκle R d eps hd heps + obtain ⟨WC,hWC,hC⟩ := hCouple κ hκ hκle d hd + obtain ⟨rho,hrho,hMoving⟩ := moving_canonical_missing_visit (show 0 < eps/2 by positivity) + refine ⟨rho,hrho,?_⟩ + intro K hK + have hA : 0 ≤ 5*d^3 := by positivity + have hEvents := (hMoving K hK).and ((mark_mesh_smallness hA hκ).and + ((moving_compact_gap_small ((11/10)*R) hK).and + (((log_power_exp_tendsto 1 0 (show 0 < κ/2 by positivity)).eventually + (eventually_le_nhds (show 0 < eps/2 by positivity))).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2)))))) + obtain ⟨W,hW⟩ := eventually_atTop.mp hEvents + refine ⟨max WC (max normalizationThreshold W),hWC.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hB hlogB hcomp hi h199 h23 hc hcut hgap + dsimp only + intro E hE + have hwC : WC ≤ w := (le_max_left _ _).trans hw + have hnorm : normalizationThreshold ≤ w := + (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hwe := hW w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw) + have hw3 : 3 ≤ w := hwe.1.1 + have hr : 0 < start.gap := (by linarith : 0 < w).trans_le hgap + have hscale := UniformBudgetRate.source_scale_bound hwe.2.2.2.2 hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have he : start.gap = B*start.ratio := by + have hh : start.cutoff = start.gap/start.ratio := hc + rw [hcut] at hh + exact ((eq_div_iff (valid_pos hs).ne').mp hh).symm + have hsize : start.gap ≤ (23/10:ℝ)*B := by rw [he]; nlinarith + have hf := (hC w hwC ell B start hs hell hB hlogB hcomp hr h23 hc hsize).1 + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) le_rfl |>.1 + have hfailSmall : Real.exp (-(κ/2)*Real.sqrt (Real.log w)) ≤ eps/2 := by + simpa only [pow_zero,mul_one,one_mul] using hwe.2.2.2.1 + have hf' : sourceLaw hnorm hell hS0 hscale.1 hr hs hsS (mesh κ w) + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) PersistentFailureFlag.failed ≤ ENNReal.ofReal (eps/2) := + hf.trans (ENNReal.ofReal_le_ofReal hfailSmall) + let s : TransitionKernels.EvenState := ⟨start.ratio,by simpa only [hi,Valid] using hs⟩ + have htyped : typedState start.side start.ratio hs = Sum.inl s := by + have aux : ∀ (i : Side) (t : ℝ) (ht : Valid i t) (hi : i = .even), + typedState i t ht = Sum.inl (⟨t,by simpa only [hi,Valid] using ht⟩ : TransitionKernels.EvenState) := by + intro i t ht hi + subst i + rfl + exact aux start.side start.ratio hs hi + have hcanon := hwe.1.2 start.gap hgap s h199 h23 + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) + have hb₀ : 0 < K*(Real.log w)^2 := by + have hL : 0 < Real.log w := Real.log_pos (by linarith) + positivity + have hb₁ : 0 < rho*K*(Real.log w)^2 := by + have : 0 < rho := by linarith + have hL : 0 < Real.log w := Real.log_pos (by linarith) + positivity + have hProb := missing_occurrence_probability hnorm hell hS0 hscale.1 hr hs hsS hc + hb₀ hb₁ hwe.2.2.1 (mesh_pos κ w) hwe.2.1.1 _ (hwe.2.1.2 _ hscale.2) E hE + rw [htyped] at hProb + calc + _ ≤ _ := hProb + _ ≤ ENNReal.ofReal (eps/2)+ENNReal.ofReal (eps/2) := add_le_add hf' hcanon + _ = _ := by rw [← ENNReal.ofReal_add (by positivity : 0 ≤ eps/2) (by positivity : 0 ≤ eps/2)]; congr 1; ring + +end NumberTheoryLean.MovingPrimeWindowProbability + +end + +section + +namespace NumberTheoryLean.WeightedMissingPrimeWindow + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership ActualPrimeHigh +open PriorPrimeWindow MovingPrimeWindowProbability UncappedCompactEvent +open SourceSelectedCompactOccupation CompactPrefixOccurrence +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +attribute [local instance] Classical.propDecidable + +theorem weighted_missing_prime_window : ∃ κ₀ : ℝ, 0 < κ₀ ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∀ R d eps : ℝ, 3 ≤ R → 0 < d → 0 < eps → + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → ∃ B₀ w₀ : ℝ, 0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ ell : ℝ, ∀ start : Node, + ∀ _hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → Real.log B ≤ d*Real.log w → + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → w ≤ start.gap → + ∀ E : Set (List ℕ), + (∀ ps ∈ uncappedPrefixes w ell start, ps ∈ E → (terminal w start ps).gap ≤ R ∧ + ¬hasPrimeWindow w (K*(Real.log w)^2) (rho*K*(Real.log w)^2) start ps) → + B^2*(∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ eps := by + obtain ⟨κ₀,hκ₀,hProb⟩ := source_missing_window_probability + refine ⟨κ₀,hκ₀,?_⟩ + intro κ hκ hκle R d eps hR hd heps + obtain ⟨C,WC,hC,hWC,hCompact⟩ := uncapped_compact_event R hR d hd + let delta := eps/(2*C) + have hdelt : 0 < delta := by dsimp [delta]; positivity + obtain ⟨rho,hrho,hMoving⟩ := hProb κ hκ hκle R d delta hd hdelt + refine ⟨rho,hrho,?_⟩ + intro K hK + obtain ⟨WP,hWP,hP⟩ := hMoving K hK + obtain ⟨BC,hBC,hCbound⟩ := hCompact (3:ℝ) + refine ⟨max BC (max (Real.exp 2) (2/eps)),max WC WP, + hBC.trans_le (le_max_left _ _),hWC.trans_le (le_max_left _ _),?_⟩ + intro B w hBB hw ell start hs hell hellB hcomp hi h199 h23 hc hcut hgap E hE + have hB : 0 < B := hBC.trans_le ((le_max_left _ _).trans hBB) + have heB : Real.exp 2 ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hBB + have hlogB : 2 ≤ Real.log B := (Real.le_log_iff_exp_le hB).mpr heB + have hwC : WC ≤ w := (le_max_left _ _).trans hw + have hwP : WP ≤ w := (le_max_right _ _).trans hw + have hw1 : 1 < w := hWC.trans_le hwC + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hHist : ∀ p : History w ell ((Real.log B)^2) start,p.primes ∈ E → p.node.gap ≤ R ∧ + ¬hasPrimeWindow w (K*(Real.log w)^2) (rho*K*(Real.log w)^2) start p.primes := by + intro p hp + have hUn : p.primes ∈ uncappedPrefixes w ell start := + (mem_uncappedPrefixes hw1 start p.primes).mpr + ((uncapped_iff_exists_ceiling w ell start p.primes).mpr ⟨(Real.log B)^2,hsS,p.admissible⟩) + exact hE p.primes hUn hp + have hProbability := hP w hwP ell B start hs hell hB hlogB hcomp hi h199 h23 hc hcut hgap E hHist + have hpReal := ENNReal.toReal_mono ENNReal.ofReal_ne_top hProbability + rw [ENNReal.toReal_ofReal hdelt.le] at hpReal + have hMass := hCbound B w ((le_max_left _ _).trans hBB) hwC ell start hs hell hellB hcomp + hi h199 h23 hc hcut (ExponentialMesh.mesh κ w) E (fun ps hp hsel => (hE ps hp hsel).1) + have hMass' : (∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ + (C/B^2)*delta+B^(-(3:ℝ)) := + hMass.trans (add_le_add (mul_le_mul_of_nonneg_left hpReal (by positivity)) le_rfl) + have hlarge : 2/eps ≤ B := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hBB + have hinv : 1/B ≤ eps/2 := by + have hh := (div_le_iff₀ heps).mp hlarge + apply (div_le_iff₀ hB).mpr + nlinarith + have hCD : C*delta = eps/2 := by dsimp [delta]; field_simp [hC.ne'] + have hpow : B^(-(3:ℝ)) = (B^3)⁻¹ := by rw [Real.rpow_neg hB.le,Real.rpow_ofNat] + calc + _ ≤ B^2*((C/B^2)*delta+B^(-(3:ℝ))) := mul_le_mul_of_nonneg_left hMass' (sq_nonneg B) + _ = C*delta+1/B := by rw [hpow]; field_simp [hB.ne'] + _ ≤ eps := by rw [hCD]; linarith + +end NumberTheoryLean.WeightedMissingPrimeWindow + +end + +section + +namespace NumberTheoryLean.MissingWindowPrimeMass + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh PriorPrimeWindow +open ErdosPrimeInputs.PrimePrefixMass WeightedMissingPrimeWindow + +noncomputable def missingWindowPrefixes (w ell R b₀ b₁ : ℝ) (start : Node) : Finset (List ℕ) := by + classical + exact (uncappedPrefixes w ell start).filter fun ps => + (terminal w start ps).gap ≤ R ∧ ¬hasPrimeWindow w b₀ b₁ start ps + +theorem moving_missing_prefix_mass (R d eps : ℝ) (hR : 3 ≤ R) (hd : 0 < d) (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → ∃ B₀ w₀ : ℝ, 0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ ell : ℝ, ∀ start : Node, + ∀ _hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → Real.log B ≤ d*Real.log w → + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → w ≤ start.gap → + B^2*(∑ ps ∈ missingWindowPrefixes w ell R (K*(Real.log w)^2) + (rho*K*(Real.log w)^2) start,prefixWeight ps) ≤ eps := by + classical + obtain ⟨κ₀,hκ₀,hbound⟩ := weighted_missing_prime_window + obtain ⟨rho,hrho,hK⟩ := hbound κ₀ hκ₀ le_rfl R d eps hR hd heps + refine ⟨rho,hrho,?_⟩ + intro K hKpos + obtain ⟨B₀,w₀,hB₀,hw₀,h⟩ := hK K hKpos + refine ⟨B₀,w₀,hB₀,hw₀,?_⟩ + intro B w hB hw ell start hs hell hellB hcomp hi h199 h23 hc hcut hgap + let E : Set (List ℕ) := {ps | (terminal w start ps).gap ≤ R ∧ + ¬hasPrimeWindow w (K*(Real.log w)^2) (rho*K*(Real.log w)^2) start ps} + have hh := h B w hB hw ell start hs hell hellB hcomp hi h199 h23 hc hcut hgap E + (fun _ _ hmem => hmem) + have hset : missingWindowPrefixes w ell R (K*(Real.log w)^2) (rho*K*(Real.log w)^2) start = + (uncappedPrefixes w ell start).filter (fun ps => ps ∈ E) := by + ext ps + simp only [missingWindowPrefixes,Finset.mem_filter,E,Set.mem_ofPred_eq] + rw [hset] + convert! hh using 1 + congr 1 + apply Finset.sum_congr + · ext ps + simp only [Finset.mem_filter] + · intro ps _ + rfl + +end NumberTheoryLean.MissingWindowPrimeMass + +end + +section + +namespace NumberTheoryLean.PaperMissingPrimeWindow + +open _root_.Set _root_.Filter _root_.Finset +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open JacobsthalSourceScale MissingWindowPrimeMass ErdosPrimeInputs.PrimePrefixMass + +theorem sourceW_le_sourceB_eventually : ∀ᶠ L : ℝ in atTop,sourceW L ≤ sourceB L := by + filter_upwards [sourceW_bounds_eventually,eventually_gt_atTop (1:ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with L hW hL hlog + have hLp : 0 < L := by linarith + have hlogW : 0 < Real.log (sourceW L) := Real.log_pos hW.1 + have hd : Real.log (sourceW L) ≤ (Real.log L)^2 := by + have hh := Real.log_le_log (by linarith [hW.1] : 0 < sourceW L) hW.2.2 + nlinarith + exact div_le_div_of_nonneg_left hLp.le hlogW hd + +theorem paper_missing_prime_window_mass (R eps : ℝ) (hR : 3 ≤ R) (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → ∃ L₀ : ℝ, 0 < L₀ ∧ + ∀ L : ℝ,L₀ ≤ L → ∀ ell : ℝ,1 ≤ ell → ell ≤ 2 → ∀ start : Node, + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = sourceB L → + (sourceB L)^2*(∑ ps ∈ missingWindowPrefixes (sourceW L) ell R + (K*(Real.log (sourceW L))^2) (rho*K*(Real.log (sourceW L))^2) start,prefixWeight ps) ≤ eps := by + obtain ⟨rho,hrho,hK⟩ := moving_missing_prefix_mass R 2 eps hR (by norm_num) heps + refine ⟨rho,hrho,?_⟩ + intro K hKpos + obtain ⟨B₀,w₀,_hB₀,_hw₀,h⟩ := hK K hKpos + have he : ∀ᶠ L : ℝ in atTop,∀ ell : ℝ,1 ≤ ell → ell ≤ 2 → ∀ start : Node, + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = sourceB L → + (sourceB L)^2*(∑ ps ∈ missingWindowPrefixes (sourceW L) ell R + (K*(Real.log (sourceW L))^2) (rho*K*(Real.log (sourceW L))^2) start,prefixWeight ps) ≤ eps := by + filter_upwards [source_scale_eventually,sourceW_le_sourceB_eventually, + sourceB_tendsto.eventually (eventually_ge_atTop (max B₀ 2)), + sourceW_tendsto.eventually (eventually_ge_atTop w₀)] with L hscale hWB hB hw + intro ell hell hell2 start hi h199 h23 hc hcut + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have heq : start.gap = sourceB L*start.ratio := by + have hh : start.cutoff = start.gap/start.ratio := hc + rw [hcut] at hh + exact ((eq_div_iff (valid_pos hs).ne').mp hh).symm + have hgap : sourceW L ≤ start.gap := by + have hBg : sourceB L ≤ start.gap := by rw [heq]; nlinarith [hscale.2.1] + exact hWB.trans hBg + exact h (sourceB L) (sourceW L) ((le_max_left _ _).trans hB) hw ell start hs hell + (hell2.trans ((le_max_right _ _).trans hB)) hscale.2.2.2.2 hi h199 h23 hc hcut hgap + obtain ⟨L₁,hL₁⟩ := eventually_atTop.mp he + refine ⟨max 1 L₁,by have hh := le_max_left (1:ℝ) L₁; linarith,?_⟩ + intro L hL + exact hL₁ L ((le_max_right _ _).trans hL) + +end NumberTheoryLean.PaperMissingPrimeWindow + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinCounting.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinCounting.lean new file mode 100644 index 0000000000000000000000000000000000000000..f22347d4f71b313d21d3b4f2c00f5a7f693d1dce --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinCounting.lean @@ -0,0 +1,62 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosInversePrimeBin + +noncomputable def primeBin (R xi : ℝ) : Finset ℕ := + Nat.primesLE ⌊(1+xi)*R⌋₊ \ Nat.primesLE ⌊R⌋₊ + +theorem mem_primeBin {R xi : ℝ} (hR : 0 ≤ R) (hxi : 0 ≤ xi) (p : ℕ) : + p ∈ primeBin R xi ↔ p.Prime ∧ R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R := by + have hb : 0 ≤ (1+xi)*R := by positivity + constructor + · intro hp + obtain ⟨hpB,hpR⟩ := Finset.mem_sdiff.mp hp + obtain ⟨hup,hprime⟩ := Nat.mem_primesLE.mp hpB + refine ⟨hprime,?_,(Nat.le_floor_iff hb).mp hup⟩ + by_contra! hlow + exact hpR (Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff hR).mpr hlow,hprime⟩) + · rintro ⟨hprime,hlo,hhi⟩ + apply Finset.mem_sdiff.mpr + refine ⟨Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff hb).mpr hhi,hprime⟩,?_⟩ + intro hpR + exact (not_le_of_gt hlo) ((Nat.le_floor_iff hR).mp (Nat.mem_primesLE.mp hpR).1) + +theorem primeBin_log_sum {R xi : ℝ} (hR : 0 ≤ R) (hxi : 0 ≤ xi) : + (∑ p ∈ primeBin R xi,Real.log p) = Chebyshev.theta ((1+xi)*R)-Chebyshev.theta R := by + have hsub : Nat.primesLE ⌊R⌋₊ ⊆ Nat.primesLE ⌊(1+xi)*R⌋₊ := by + intro p hp + obtain ⟨hle,hprime⟩ := Nat.mem_primesLE.mp hp + exact Nat.mem_primesLE.mpr ⟨hle.trans (Nat.floor_mono (by nlinarith)),hprime⟩ + rw [Chebyshev.theta_eq_sum_primesLE,Chebyshev.theta_eq_sum_primesLE] + simpa only [primeBin] using (Finset.sum_sdiff_eq_sub (f := fun p : ℕ => Real.log p) hsub) + +theorem primeBin_log_sum_upper {R xi : ℝ} (hR : 2 ≤ R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) : + (∑ p ∈ primeBin R xi,Real.log p) ≤ (primeBin R xi).card*(2*Real.log R) := by + have hR0 : 0 < R := by linarith + have hupper : (1+xi)*R ≤ R^2 := by nlinarith + have hb0 : 0 < (1+xi)*R := by positivity + have hlog : Real.log ((1+xi)*R) ≤ 2*Real.log R := by + have h := Real.log_le_log hb0 hupper + simpa only [Real.log_pow,Nat.cast_ofNat] using h + calc + _ ≤ ∑ _p ∈ primeBin R xi,2*Real.log R := by + apply Finset.sum_le_sum + intro p hp + obtain ⟨hprime,_,hhi⟩ := (mem_primeBin hR0.le hxi p).mp hp + exact (Real.log_le_log (by exact_mod_cast hprime.pos) hhi).trans hlog + _ = _ := by simp + +end ErdosInversePrimeBin + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinRationalList.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinRationalList.lean new file mode 100644 index 0000000000000000000000000000000000000000..309532935e8743c3af808d0bf44d2f83d5ae3d4b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinRationalList.lean @@ -0,0 +1,254 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualCollisionBound +import OAI.NumberTheory.Jacobsthal.Primes.HighPrimeRemoval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open scoped BigOperators +namespace ErdosInversePrimeBin +open _root_.Filter +open scoped Topology + +theorem primeBin_log_sum_lower {R xi : ℝ} (hR : 0 < R) (hxi : 0 ≤ xi) : + (primeBin R xi).card*Real.log R ≤ ∑ p ∈ primeBin R xi,Real.log p := by + calc + _ = ∑ _p ∈ primeBin R xi,Real.log R := by simp + _ ≤ _ := by + apply Finset.sum_le_sum + intro p hp + exact Real.log_le_log hR ((mem_primeBin hR.le hxi p).mp hp).2.1.le + +theorem uniform_prime_bin_count {eta : ℝ} (heta : 0 < eta) : + ∀ᶠ R : ℝ in atTop,2 ≤ R ∧ ∀ xi : ℝ,eta ≤ xi → xi ≤ 1 → + xi*R/(4*Real.log R) ≤ (primeBin R xi).card ∧ + (primeBin R xi).card ≤ 2*xi*R/Real.log R := by + filter_upwards [uniform_bin_theta_error heta] with R hR + refine ⟨hR.1,?_⟩ + intro xi hxi hxi1 + have hxi0 := heta.le.trans hxi + have hR0 : 0 < R := by linarith [hR.1] + have hlog : 0 < Real.log R := Real.log_pos (by linarith [hR.1]) + have he := hR.2 xi hxi hxi1 + rw [← primeBin_log_sum hR0.le hxi0] at he + have hlow := (abs_le.mp he).1 + have hhigh := (abs_le.mp he).2 + have hcountupper := primeBin_log_sum_upper hR.1 hxi0 hxi1 + have hcountlower := primeBin_log_sum_lower hR0 hxi0 + constructor + · apply (div_le_iff₀ (show 0 < 4*Real.log R by positivity)).mpr + nlinarith only [hlow,hcountupper] + · apply (le_div_iff₀ hlog).mpr + have hprod := mul_nonneg hxi0 hR0.le + nlinarith only [hhigh,hcountlower,hprod] + +theorem log_le_two_sqrt {R : ℝ} (hR : 0 < R) : Real.log R ≤ 2*Real.sqrt R := by + have h := Real.log_le_sub_one_of_pos (Real.sqrt_pos.mpr hR) + have he : Real.log R = 2*Real.log (Real.sqrt R) := by + rw [← Real.sq_sqrt hR.le,Real.log_pow] + norm_num + rw [he] + linarith + +theorem bin_scale_sqrt_lower {R xi eta : ℝ} (hR : 2 ≤ R) (heta : 0 < eta) (hxi : eta ≤ xi) : + eta*Real.sqrt R/8 ≤ xi*R/(4*Real.log R) := by + have hR0 : 0 < R := by linarith + have hlog : 0 < Real.log R := Real.log_pos (by linarith) + apply (div_le_div_iff₀ (by norm_num : (0 : ℝ) < 8) (show 0 < 4*Real.log R by positivity)).mpr + have hlogbound := mul_le_mul_of_nonneg_left (log_le_two_sqrt hR0) + (show 0 ≤ eta*Real.sqrt R by positivity) + have hRxi := mul_le_mul_of_nonneg_right hxi hR0.le + have hs := Real.sq_sqrt hR0.le + have he : eta*Real.sqrt R*(2*Real.sqrt R) = 2*eta*R := by + calc + _ = 2*eta*(Real.sqrt R)^2 := by ring + _ = _ := by rw [hs] + rw [he] at hlogbound + nlinarith only [hlogbound,hRxi] + +end ErdosInversePrimeBin + +end + +section + +namespace ErdosInversePrimeBin +open _root_.Filter +open scoped Topology + +theorem uniform_prime_bin_many {eta : ℝ} (heta : 0 < eta) (N : ℕ) : + ∀ᶠ R : ℝ in atTop,2 ≤ R ∧ ∀ xi : ℝ,eta ≤ xi → xi ≤ 1 → N ≤ (primeBin R xi).card := by + filter_upwards [uniform_prime_bin_count heta, + eventually_ge_atTop ((8*(N : ℝ)/eta)^2)] with R hR hsize + have hR0 : 0 < R := by linarith [hR.1] + have hs : 8*(N : ℝ)/eta ≤ Real.sqrt R := + (Real.le_sqrt (by positivity) hR0.le).mpr hsize + have hn : (N : ℝ) ≤ eta*Real.sqrt R/8 := by + have h := (div_le_iff₀ heta).mp hs + apply (le_div_iff₀ (by norm_num : (0 : ℝ) < 8)).mpr + nlinarith only [h] + refine ⟨hR.1,?_⟩ + intro xi hxi hxi1 + have h := hn.trans ((bin_scale_sqrt_lower hR.1 heta hxi).trans (hR.2 xi hxi hxi1).1) + exact_mod_cast h + +end ErdosInversePrimeBin + +end + +section + +namespace ErdosInverseCells +open ErdosInversePrimeBin + +theorem prime_bin_weight_spread (R theta xi : ℝ) (hR : 0 < R) (htheta : 0 ≤ theta) + (hxi : 0 ≤ xi) (hthetaXi : theta ≤ xi) : + ∀ p ∈ primeBin R theta,∀ r ∈ primeBin R theta,(p : ℝ)⁻¹ ≤ (1+xi)*(r : ℝ)⁻¹ := by + intro p hp r hr + have hpm := (mem_primeBin hR.le htheta p).mp hp + have hrm := (mem_primeBin hR.le htheta r).mp hr + have hp0 : (0 : ℝ) < p := hR.trans hpm.2.1 + have hr0 : (0 : ℝ) < r := hR.trans hrm.2.1 + have htop : (r : ℝ) ≤ (1+xi)*(p : ℝ) := by + calc + _ ≤ (1+theta)*R := hrm.2.2 + _ ≤ (1+xi)*R := mul_le_mul_of_nonneg_right (by linarith) hR.le + _ ≤ (1+xi)*(p : ℝ) := mul_le_mul_of_nonneg_left hpm.2.1.le (by linarith) + have hh : (1 : ℝ)/(p : ℝ) ≤ (1+xi)/(r : ℝ) := + (div_le_div_iff₀ hp0 hr0).mpr (by simpa only [one_mul] using htop) + simpa only [one_div,div_eq_mul_inv,one_mul] using hh + +end ErdosInverseCells + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourcePolynomial +open ErdosInversePrimeBin + +theorem prime_bin_log_upper {R xi : ℝ} (hR : 2 ≤ R) (hxi0 : 0 ≤ xi) (hxi1 : xi ≤ 1) + (p : primeBin R xi) : Real.log (p.val : ℝ) ≤ 2*Real.log R := by + have hR0 : 0 < R := by linarith + have hp := (mem_primeBin hR0.le hxi0 p.val).mp p.property + have hp2 : (p.val : ℝ) ≤ 2*R := hp.2.2.trans + (mul_le_mul_of_nonneg_right (by linarith : 1+xi ≤ 2) hR0.le) + have hsq : 2*R ≤ R^2 := by + simpa only [pow_two] using mul_le_mul_of_nonneg_right hR hR0.le + have h := Real.log_le_log (hR0.trans hp.2.1) (hp2.trans hsq) + simpa only [Real.log_pow,Nat.cast_ofNat] using h + +theorem prime_bin_slope_cost_bound {R xi L : ℝ} (hR : 2 ≤ R) (hxi0 : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hL : 0 < L) (T : primeBin R xi → Finset ℤ) + (hcount : ((primeBin R xi).card : ℝ) ≤ 2*R/Real.log R) + (hthin : (∑ p : primeBin R xi, ((T p).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/L^6) : + (∑ p : primeBin R xi, ((T p).card : ℝ)*Real.log (p.val : ℝ)) ≤ 4*R^2/L^6 := by + have hR0 : 0 < R := by linarith + have hlog : 0 < Real.log R := Real.log_pos (by linarith) + calc + _ ≤ ∑ p : primeBin R xi, ((T p).card : ℝ)*(2*Real.log R) := + Finset.sum_le_sum (fun p _ => mul_le_mul_of_nonneg_left (prime_bin_log_upper hR hxi0 hxi1 p) (Nat.cast_nonneg _)) + _ = (∑ p : primeBin R xi, ((T p).card : ℝ))*(2*Real.log R) := by rw [Finset.sum_mul] + _ ≤ (((primeBin R xi).card : ℝ)*R/L^6)*(2*Real.log R) := + mul_le_mul_of_nonneg_right hthin (by positivity) + _ ≤ ((2*R/Real.log R)*R/L^6)*(2*Real.log R) := by gcongr + _ = 4*R^2/L^6 := by field_simp; ring + +theorem rich_prime_log_lower {R xi eta c : ℝ} (hR : 2 ≤ R) (heta : 0 < eta) + (hxi : eta ≤ xi) (hc : 0 ≤ c) + (hcount : xi*R/(4*Real.log R) ≤ ((primeBin R xi).card : ℝ)) + (I : Finset ℕ) (hIP : I ⊆ primeBin R xi) + (hrich : c*((primeBin R xi).card : ℝ) ≤ (I.card : ℝ)) : + c*eta*R/4 ≤ ∑ p ∈ I, Real.log (p : ℝ) := by + have hR0 : 0 < R := by linarith + have hlog : 0 < Real.log R := Real.log_pos (by linarith) + have hxi0 : 0 ≤ xi := heta.le.trans hxi + have hsum : (I.card : ℝ)*Real.log R ≤ ∑ p ∈ I, Real.log (p : ℝ) := by + calc + _ = ∑ _p ∈ I, Real.log R := by simp + _ ≤ _ := Finset.sum_le_sum (fun p hp => + Real.log_le_log hR0 ((mem_primeBin hR0.le hxi0 p).mp (hIP hp)).2.1.le) + calc + c*eta*R/4 ≤ c*xi*R/4 := by gcongr + _ = c*(xi*R/(4*Real.log R))*Real.log R := by field_simp + _ ≤ c*((primeBin R xi).card : ℝ)*Real.log R := by gcongr + _ ≤ (I.card : ℝ)*Real.log R := mul_le_mul_of_nonneg_right hrich hlog.le + _ ≤ _ := hsum + +theorem uniform_prime_bin_budgets {eta : ℝ} (heta : 0 < eta) : + ∀ᶠ R : ℝ in atTop, 2 ≤ R ∧ ∀ xi : ℝ, eta ≤ xi → xi ≤ 1 → + (∀ L : ℝ, 0 < L → ∀ T : primeBin R xi → Finset ℤ, + (∑ p : primeBin R xi, ((T p).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/L^6 → + (∑ p : primeBin R xi, ((T p).card : ℝ)*Real.log (p.val : ℝ)) ≤ 4*R^2/L^6) ∧ + (∀ c : ℝ, 0 ≤ c → ∀ I : Finset ℕ, I ⊆ primeBin R xi → + c*((primeBin R xi).card : ℝ) ≤ (I.card : ℝ) → c*eta*R/4 ≤ ∑ p ∈ I, Real.log (p : ℝ)) := by + filter_upwards [uniform_prime_bin_count heta] with R hR + refine ⟨hR.1,?_⟩ + intro xi hxi hxi1 + have hxi0 := heta.le.trans hxi + have hlog : 0 < Real.log R := Real.log_pos (by linarith [hR.1]) + have hR0 : 0 < R := by linarith [hR.1] + have hbounds := hR.2 xi hxi hxi1 + have hupper : ((primeBin R xi).card : ℝ) ≤ 2*R/Real.log R := by + apply hbounds.2.trans + gcongr + linarith + exact ⟨fun L hL T hthin => prime_bin_slope_cost_bound hR.1 hxi0 hxi1 hL T hupper hthin, + fun c hc I hIP hrich => rich_prime_log_lower hR.1 heta hxi hc hbounds.1 I hIP hrich⟩ + +end ErdosSourcePolynomial + +end + +section + +namespace ErdosInversePrimeBin +open _root_.Filter ErdosInverseAlignment +open scoped Topology + +theorem uniform_source_prime_bin_list {eta α C c : ℝ} + (heta : 0 < eta) (hα : 0 < α) (hC : 0 ≤ C) (hc : 0 < c) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R xi Sq Z : ℝ,∀ a : ℕ → ℤ, + z^α ≤ R → eta ≤ xi → xi ≤ 1 → 0 ≤ Sq → 2*Sq*R^2*Z^20 ≤ z^C → + (sourceRationalList (primeBin R xi) a Sq R Z c).card ≤ ⌈2/c^2⌉₊ := by + let N : ℕ := ⌈max 1 (2*(C/α)/c^2)⌉₊ + have hN : max 1 (2*(C/α)/c^2) ≤ (N : ℝ) := Nat.le_ceil _ + obtain ⟨R₀,hR₀⟩ := eventually_atTop.mp (uniform_prime_bin_many heta N) + filter_upwards [eventually_gt_atTop (1 : ℝ), + (tendsto_rpow_atTop hα).eventually (eventually_ge_atTop R₀)] with z hz hlarge + refine ⟨hz,?_⟩ + intro R xi Sq Z a hR hxi hxi1 hSq hheight + have hbin := hR₀ R (hlarge.trans hR) + have hR0 : 0 ≤ R := by linarith [hbin.1] + have hxi0 : 0 ≤ xi := heta.le.trans hxi + have hmany : N ≤ (primeBin R xi).card := hbin.2 xi hxi hxi1 + have hmanyR : (N : ℝ) ≤ ((primeBin R xi).card : ℝ) := by exact_mod_cast hmany + have hPpos : 0 < (primeBin R xi).card := by + have hN1 : (1 : ℝ) ≤ N := (le_max_left _ _).trans hN + have hpositive : (0 : ℝ) < (primeBin R xi).card := by linarith only [hN1,hmanyR] + exact_mod_cast hpositive + have henough : 2*(C/α) ≤ c^2*((primeBin R xi).card : ℝ) := by + have hneed : 2*(C/α)/c^2 ≤ ((primeBin R xi).card : ℝ) := + (le_max_right _ _).trans (hN.trans hmanyR) + simpa only [mul_comm] using (div_le_iff₀ (sq_pos_of_pos hc)).mp hneed + apply source_rational_list_bound (primeBin R xi) a hSq hR0 hz hα hC hc + · intro p hp + exact ((mem_primeBin hR0 hxi0 p).mp hp).1 + · intro p hp + exact hR.trans ((mem_primeBin hR0 hxi0 p).mp hp).2.1.le + · exact hheight + · exact hPpos + · exact henough + +end ErdosInversePrimeBin + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinRepresentatives.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinRepresentatives.lean new file mode 100644 index 0000000000000000000000000000000000000000..16c85a9c90f2996b883b2492f497bc89f22cffaf --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeBinRepresentatives.lean @@ -0,0 +1,84 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RepresentativeAdmission + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PrimeBinRepresentatives + +open _root_.Erdos970.Finset +open ErdosInversePrimeBin ErdosPrimeInputs.HarmonicPrimeMeasure +open PrimeHistories RepresentativeAdmission + +noncomputable def leftExponent (w R : ℝ) : ℝ := Real.log R/Real.log w +noncomputable def rightExponent (w R xi : ℝ) : ℝ := Real.log ((1+xi)*R)/Real.log w + +theorem bin_exponent_bounds {w R xi : ℝ} (hw : 1 < w) (hR : 0 < R) (hxi : 0 ≤ xi) + {p : ℕ} (hp : p ∈ primeBin R xi) : + leftExponent w R < primeExponent w p ∧ primeExponent w p ≤ rightExponent w R xi := by + obtain ⟨hprime,hlo,hhi⟩ := (mem_primeBin hR.le hxi p).mp hp + have hp0 : (0:ℝ) < p := by exact_mod_cast hprime.pos + exact ⟨div_lt_div_of_pos_right (Real.log_lt_log hR hlo) (Real.log_pos hw), + div_le_div_of_nonneg_right (Real.log_le_log hp0 hhi) (Real.log_pos hw).le⟩ + +theorem bin_exponent_width {w R xi : ℝ} (hR : 0 < R) (hxi : 0 ≤ xi) : + rightExponent w R xi-leftExponent w R = Real.log (1+xi)/Real.log w := by + rw [rightExponent,leftExponent,Real.log_mul (by positivity : (1+xi:ℝ) ≠ 0) hR.ne'] + ring + +theorem representative_error {w R xi : ℝ} (hw : 1 < w) (hR : 0 < R) (hxi : 0 ≤ xi) + {p : ℕ} (hp : p ∈ primeBin R xi) : + 0 ≤ rightExponent w R xi-primeExponent w p ∧ + rightExponent w R xi-primeExponent w p ≤ xi/Real.log w := by + have h := bin_exponent_bounds hw hR hxi hp + have hlog : Real.log (1+xi) ≤ xi := by + have hh := Real.log_le_sub_one_of_pos (by positivity : 0 < 1+xi) + linarith + refine ⟨sub_nonneg.mpr h.2,?_⟩ + calc + _ ≤ rightExponent w R xi-leftExponent w R := by linarith [h.1] + _ = Real.log (1+xi)/Real.log w := bin_exponent_width hR hxi + _ ≤ _ := div_le_div_of_nonneg_right hlog (Real.log_pos hw).le + +theorem finite_gap_movement (w : ℝ) (rep : ℕ → ℝ) (z : Node) (ps : List ℕ) {h : ℝ} + (hrep : ∀ p ∈ ps,0 ≤ rep p-primeExponent w p ∧ rep p-primeExponent w p ≤ h) : + 0 ≤ (terminal w z ps).gap-representativeGap rep z.gap ps ∧ + (terminal w z ps).gap-representativeGap rep z.gap ps ≤ (ps.length:ℝ)*h := by + have hs : 0 ≤ (ps.map rep).sum-(ps.map (primeExponent w)).sum ∧ + (ps.map rep).sum-(ps.map (primeExponent w)).sum ≤ (ps.length:ℝ)*h := by + induction ps with + | nil => simp + | cons p ps ih => + have hp := hrep p (by simp) + have ht := ih (fun q hq => hrep q (by simp [hq])) + simp only [List.map_cons,List.sum_cons,List.length_cons,Nat.cast_add,Nat.cast_one] + constructor <;> linarith + rw [terminal_gap_sum,representativeGap] + constructor <;> linarith + +theorem source_movement_bound {w B Clen xi : ℝ} (hw : 1 < w) (hC : 0 ≤ Clen) (hxi : 0 ≤ xi) + (hcomp : Real.log B ≤ 2*Real.log w) (rep : ℕ → ℝ) (z : Node) (ps : List ℕ) + (hlen : (ps.length:ℝ) ≤ Clen*Real.log B) + (hrep : ∀ p ∈ ps,0 ≤ rep p-primeExponent w p ∧ rep p-primeExponent w p ≤ xi/Real.log w) : + 0 ≤ (terminal w z ps).gap-representativeGap rep z.gap ps ∧ + (terminal w z ps).gap-representativeGap rep z.gap ps ≤ 2*Clen*xi := by + have hm := finite_gap_movement w rep z ps hrep + have hlog := Real.log_pos hw + refine ⟨hm.1,hm.2.trans ?_⟩ + calc + _ ≤ (Clen*Real.log B)*(xi/Real.log w) := + mul_le_mul_of_nonneg_right hlen (div_nonneg hxi hlog.le) + _ ≤ (Clen*(2*Real.log w))*(xi/Real.log w) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hcomp hC) (div_nonneg hxi hlog.le) + _ = _ := by field_simp [hlog.ne'] + +end NumberTheoryLean.PrimeBinRepresentatives + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeChoiceCoordinateMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeChoiceCoordinateMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..026ca02490c13696a15250d7a6a9274adad98af8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeChoiceCoordinateMass.lean @@ -0,0 +1,241 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualFirstTagExistence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.PrimeBinAlignmentMass +open ErdosInversePrimeBin + + +noncomputable def mass (P : Finset ℕ) : ℝ := ∑ p ∈ P,(p:ℝ)⁻¹ + +theorem mass_nonnegative (P : Finset ℕ) : 0 ≤ mass P := + Finset.sum_nonneg (fun p _ => inv_nonneg.mpr (Nat.cast_nonneg p)) + +theorem subset_mass_bounds {R xi : ℝ} (hR : 0 < R) (hxi : 0 ≤ xi) (P : Finset ℕ) + (hP : P ⊆ primeBin R xi) : + (P.card:ℝ)/((1+xi)*R) ≤ mass P ∧ mass P ≤ (P.card:ℝ)/R := by + have hden : 0 < (1+xi)*R := by positivity + constructor + · calc + _ = ∑ _p ∈ P,((1+xi)*R)⁻¹ := by simp [div_eq_mul_inv] + _ ≤ _ := Finset.sum_le_sum (fun p hp => by + obtain ⟨hpp,_hlo,hhi⟩ := (mem_primeBin hR.le hxi p).mp (hP hp) + simpa only [one_div] using (one_div_le_one_div_of_le (by exact_mod_cast hpp.pos : (0:ℝ) by + obtain ⟨_hpp,hlo,_hhi⟩ := (mem_primeBin hR.le hxi p).mp (hP hp) + simpa only [one_div] using (one_div_le_one_div_of_le hR hlo.le)) + _ = _ := by simp [div_eq_mul_inv] + +theorem non_nearfull_mass {R xi eta : ℝ} (hR : 0 < R) (hxi : 0 ≤ xi) (heta : 0 ≤ eta) + (A : Finset ℕ) (hA : A ⊆ primeBin R xi) + (hcard : (A.card:ℝ) ≤ (1-eta)*((primeBin R xi).card:ℝ)) : + mass A ≤ (1-eta/(1+xi))*mass (primeBin R xi) := by + let P := primeBin R xi + let C := P \ A + have hden : 0 < (1+xi)*R := by positivity + have hcardC : eta*(P.card:ℝ) ≤ (C.card:ℝ) := by + have hh := Finset.card_sdiff_add_card_eq_card hA + have hhr : (C.card:ℝ)+(A.card:ℝ)=(P.card:ℝ) := by exact_mod_cast hh + change (A.card:ℝ) ≤ (1-eta)*(P.card:ℝ) at hcard + nlinarith + have hPmass := (subset_mass_bounds hR hxi P (fun _ h => h)).2 + have hCmass := (subset_mass_bounds hR hxi C Finset.sdiff_subset).1 + have hsum : mass C=mass P-mass A := Finset.sum_sdiff_eq_sub hA + have hbound : eta/(1+xi)*mass P ≤ mass C := by + calc + _ ≤ eta/(1+xi)*((P.card:ℝ)/R) := + mul_le_mul_of_nonneg_left hPmass (div_nonneg heta (by positivity)) + _ = (eta*(P.card:ℝ))/((1+xi)*R) := by + field_simp [hR.ne',(by positivity : (1+xi:ℝ) ≠ 0)] + _ ≤ (C.card:ℝ)/((1+xi)*R) := div_le_div_of_nonneg_right hcardC hden.le + _ ≤ _ := hCmass + rw [hsum] at hbound + linarith +end NumberTheoryLean.PrimeBinAlignmentMass + + + +namespace NumberTheoryLean.PrimeChoiceBoxMass +open PrimeBinAlignmentMass ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +noncomputable def choices {m : ℕ} (P : Fin m → Finset ℕ) : Finset (Fin m → ℕ) := Fintype.piFinset P +noncomputable def weight {m : ℕ} (f : Fin m → ℕ) : ℝ := ∏ i,(f i:ℝ)⁻¹ +noncomputable def boxMass {m : ℕ} (P : Fin m → Finset ℕ) : ℝ := ∑ f ∈ choices P,weight f + +theorem boxMass_factorizes {m : ℕ} (P : Fin m → Finset ℕ) : boxMass P=∏ i,mass (P i) := by + exact (Finset.prod_univ_sum P (fun _ p => (p:ℝ)⁻¹)).symm + +noncomputable def alignedChoices {m : ℕ} (P : Fin m → Finset ℕ) (S : Finset (Fin m)) + (a : ℕ → ℤ) (q : ℚ) : Finset (Fin m → ℕ) := + (choices P).filter (fun f => ∀ i ∈ S,aligns a q (f i)) + +theorem alignedChoices_eq {m : ℕ} (P : Fin m → Finset ℕ) (S : Finset (Fin m)) + (a : ℕ → ℤ) (q : ℚ) : + alignedChoices P S a q=choices (fun i => if i ∈ S then (P i).filter (aligns a q) else P i) := by + ext f + simp only [alignedChoices,choices,Finset.mem_filter,Fintype.mem_piFinset] + constructor + · rintro ⟨hp,ha⟩ i + by_cases hi : i ∈ S + · simpa only [ite_eq_left hi,Finset.mem_filter] using And.intro (hp i) (ha i hi) + · simpa only [ite_eq_right hi] using hp i + · intro h + constructor + · intro i + by_cases hi : i ∈ S + · have hh := h i; rw [ite_eq_left hi] at hh; exact (Finset.mem_filter.mp hh).1 + · have hh := h i; rwa [ite_eq_right hi] at hh + · intro i hi + have hh := h i + rw [ite_eq_left hi] at hh + exact (Finset.mem_filter.mp hh).2 + +theorem no_nearfull_box_mass {m : ℕ} (R : Fin m → ℝ) (xi eta : ℝ) + (hR : ∀ i,0 < R i) (hxi : 0 ≤ xi) (heta0 : 0 ≤ eta) (heta1 : eta ≤ 1) + (S : Finset (Fin m)) (a : ℕ → ℤ) (q : ℚ) + (hd : ∀ i ∈ S,(((primeBin (R i) xi).filter (aligns a q)).card:ℝ) ≤ + (1-eta)*((primeBin (R i) xi).card:ℝ)) : + (∑ f ∈ alignedChoices (fun i => primeBin (R i) xi) S a q,weight f) ≤ + (1-eta/(1+xi))^S.card*boxMass (fun i => primeBin (R i) xi) := by + let c : ℝ := 1-eta/(1+xi) + have hc : 0 ≤ c := by + have hd : 0 < 1+xi := by linarith + have hh : eta/(1+xi) ≤ 1 := (div_le_one hd).mpr (by linarith) + dsimp [c]; linarith + rw [alignedChoices_eq] + change boxMass (fun i => if i ∈ S then (primeBin (R i) xi).filter (aligns a q) else primeBin (R i) xi) ≤ _ + rw [boxMass_factorizes,boxMass_factorizes] + calc + _ ≤ ∏ i : Fin m,(if i ∈ S then c else 1)*mass (primeBin (R i) xi) := by + apply Finset.prod_le_prod₀ + · intro i _ + exact mass_nonnegative _ + · intro i _ + by_cases hi : i ∈ S + · simp only [ite_eq_left hi] + exact non_nearfull_mass (hR i) hxi heta0 _ (Finset.filter_subset _ _) (hd i hi) + · simp only [ite_eq_right hi,one_mul,le_refl] + _ = c^S.card*∏ i : Fin m,mass (primeBin (R i) xi) := by + rw [Finset.prod_mul_distrib,Finset.prod_ite_mem_eq] + simp + _ = _ := rfl +end NumberTheoryLean.PrimeChoiceBoxMass + + + +namespace NumberTheoryLean.PrimeChoiceAlignmentDecay +open PrimeChoiceBoxMass PrimeBinAlignmentMass ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem boxMass_nonnegative {m : ℕ} (P : Fin m → Finset ℕ) : 0 ≤ boxMass P := by + rw [boxMass_factorizes] + exact Finset.prod_nonneg (fun i _ => mass_nonnegative (P i)) + +theorem search_power_bound {w c eta xi : ℝ} (hw : 1 < w) (_hc : 0 < c) + (heta0 : 0 < eta) (heta1 : eta ≤ 1) (hxi0 : 0 ≤ xi) (hxi1 : xi ≤ 1) + (n : ℕ) (hcount : c*Real.log w ≤ (n:ℝ)) : + (1-eta/(1+xi))^n ≤ w^(-(c*eta/2)) := by + have hden : 0 < 1+xi := by linarith + have hquot : eta/(1+xi) ≤ 1 := (div_le_one hden).mpr (by linarith) + have hbase : 0 ≤ 1-eta/(1+xi) := by linarith + have hq : eta/2 ≤ eta/(1+xi) := div_le_div_of_nonneg_left heta0.le hden (by linarith) + have hsmall : 1-eta/(1+xi) ≤ Real.exp (-(eta/2)) := + (sub_le_sub_left hq 1).trans (Real.one_sub_le_exp_neg (eta/2)) + have hpow := pow_le_pow_left₀ hbase hsmall n + apply hpow.trans + rw [← Real.exp_nat_mul,Real.rpow_def_of_pos (zero_lt_one.trans hw)] + apply Real.exp_le_exp.mpr + nlinarith + +theorem no_nearfull_power_mass {m : ℕ} (R : Fin m → ℝ) (w c eta xi : ℝ) + (hR : ∀ i,0 < R i) (hw : 1 < w) (hc : 0 < c) (heta0 : 0 < eta) + (heta1 : eta ≤ 1) (hxi0 : 0 ≤ xi) (hxi1 : xi ≤ 1) + (S : Finset (Fin m)) (hcount : c*Real.log w ≤ (S.card:ℝ)) (a : ℕ → ℤ) (q : ℚ) + (hd : ∀ i ∈ S,(((primeBin (R i) xi).filter (aligns a q)).card:ℝ) ≤ + (1-eta)*((primeBin (R i) xi).card:ℝ)) : + (∑ f ∈ alignedChoices (fun i => primeBin (R i) xi) S a q,weight f) ≤ + w^(-(c*eta/2))*boxMass (fun i => primeBin (R i) xi) := by + exact (no_nearfull_box_mass R xi eta hR hxi0 heta0.le heta1 S a q hd).trans + (mul_le_mul_of_nonneg_right (search_power_bound hw hc heta0 heta1 hxi0 hxi1 S.card hcount) + (boxMass_nonnegative _)) +end NumberTheoryLean.PrimeChoiceAlignmentDecay + + + +namespace NumberTheoryLean.PrimeChoiceCoordinateMass +open PrimeChoiceBoxMass PrimeBinAlignmentMass + +attribute [local instance] Classical.propDecidable + +noncomputable def coordinateEvent {m : ℕ} (P : Fin m → Finset ℕ) (i : Fin m) (A : Finset ℕ) : + Finset (Fin m → ℕ) := (choices P).filter (fun f => f i ∈ A) +noncomputable def someCoordinateEvent {m : ℕ} (P : Fin m → Finset ℕ) (S : Finset (Fin m)) + (A : Fin m → Finset ℕ) : Finset (Fin m → ℕ) := + (choices P).filter (fun f => ∃ i ∈ S,f i ∈ A i) + +theorem weight_nonnegative {m : ℕ} (f : Fin m → ℕ) : 0 ≤ weight f := + Finset.prod_nonneg (fun i _ => inv_nonneg.mpr (Nat.cast_nonneg (f i))) + +theorem coordinate_mass_eq {m : ℕ} (P : Fin m → Finset ℕ) (i : Fin m) (A : Finset ℕ) + (hA : A ⊆ P i) : + (∑ f ∈ coordinateEvent P i A,weight f)=mass A * ∏ j ∈ Finset.univ.erase i,mass (P j) := by + have he : coordinateEvent P i A=choices (Function.update P i A) := + (Fintype.piFinset_update_eq_filter_piFinset_mem P i hA).symm + rw [he] + change boxMass (Function.update P i A)=_ + rw [boxMass_factorizes,← Finset.mul_prod_erase Finset.univ + (fun j => mass (Function.update P i A j)) (Finset.mem_univ i),Function.update_self] + congr 1 + apply Finset.prod_congr rfl + intro j hj + rw [Function.update_of_ne (Finset.mem_erase.mp hj).1] + +theorem coordinate_mass_bound {m : ℕ} (P : Fin m → Finset ℕ) (i : Fin m) (A : Finset ℕ) + (hA : A ⊆ P i) (delta : ℝ) (hm : mass A ≤ delta*mass (P i)) : + (∑ f ∈ coordinateEvent P i A,weight f) ≤ delta*boxMass P := by + rw [coordinate_mass_eq P i A hA,boxMass_factorizes, + ← Finset.mul_prod_erase Finset.univ (fun j => mass (P j)) (Finset.mem_univ i)] + have hh := mul_le_mul_of_nonneg_right hm (Finset.prod_nonneg (s := Finset.univ.erase i) (fun j _ => mass_nonnegative (P j))) + simpa only [mul_assoc] using hh + +theorem union_mass_le_sum {m : ℕ} (P : Fin m → Finset ℕ) (S : Finset (Fin m)) + (A : Fin m → Finset ℕ) : + (∑ f ∈ someCoordinateEvent P S A,weight f) ≤ + ∑ i ∈ S,∑ f ∈ coordinateEvent P i (A i),weight f := by + simp only [someCoordinateEvent,coordinateEvent,Finset.sum_filter] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro f _hf + by_cases he : ∃ i ∈ S,f i ∈ A i + · rw [ite_eq_left he] + obtain ⟨i,hi,hAi⟩ := he + have hh := Finset.single_le_sum (s := S) + (f := fun j => if f j ∈ A j then weight f else 0) + (fun j _ => by split_ifs; exact weight_nonnegative f; rfl) hi + simpa only [ite_eq_left hAi] using hh + · rw [ite_eq_right he] + exact Finset.sum_nonneg (fun i _ => by split_ifs; exact weight_nonnegative f; rfl) + +theorem some_coordinate_mass_bound {m : ℕ} (P : Fin m → Finset ℕ) (S : Finset (Fin m)) + (A : Fin m → Finset ℕ) (hA : ∀ i ∈ S,A i ⊆ P i) (delta : ℝ) + (hm : ∀ i ∈ S,mass (A i) ≤ delta*mass (P i)) : + (∑ f ∈ someCoordinateEvent P S A,weight f) ≤ (S.card:ℝ)*delta*boxMass P := by + apply (union_mass_le_sum P S A).trans + calc + _ ≤ ∑ _i ∈ S,delta*boxMass P := Finset.sum_le_sum + (fun i hi => coordinate_mass_bound P i (A i) (hA i hi) delta (hm i hi)) + _ = _ := by simp [mul_assoc] +end NumberTheoryLean.PrimeChoiceCoordinateMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeCompactWeights.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeCompactWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..10f60390744ac82f7af8fce741612e3f4d9a4326 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeCompactWeights.lean @@ -0,0 +1,817 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CompletedParentInterval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.WeightedPrimeBins + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeTiltGeometry PrimeTiltBounds PrimeTiltMonotone +open PrimeRatioBins ContinuousRatioBins + +noncomputable def weightedPrimeBin (w r : ℝ) (i : Side) (s a b : ℝ) : ℝ := + ∑ p ∈ ratioBin w r a b, primeTilt w r i s p + +theorem weightedPrimeBin_sandwich {w r s a b : ℝ} {i : Side} (hs : Valid i s) + (hma : minRatio i s ≤ a) (hab : a ≤ b) : + multiplier i s b * ratioBinMass w r a b ≤ weightedPrimeBin w r i s a b ∧ + weightedPrimeBin w r i s a b ≤ multiplier i s a * ratioBinMass w r a b := by + classical + have hlo : ∀ p ∈ ratioBin w r a b, multiplier i s b ≤ multiplier i s (childRatio w r p) := by + intro p hp + have ht := (Finset.mem_filter.mp hp).2 + exact multiplier_antitone hs (Set.mem_Ici.mpr (hma.trans ht.1)) + (Set.mem_Ici.mpr (hma.trans hab)) ht.2.le + have hup : ∀ p ∈ ratioBin w r a b, multiplier i s (childRatio w r p) ≤ multiplier i s a := by + intro p hp + have ht := (Finset.mem_filter.mp hp).2 + exact multiplier_antitone hs (Set.mem_Ici.mpr hma) (Set.mem_Ici.mpr (hma.trans ht.1)) ht.1 + constructor + · rw [ratioBinMass, Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + rw [primeTilt_eq_multiplier, mul_comm (multiplier i s b)] + exact mul_le_mul_of_nonneg_left (hlo p hp) (inv_nonneg.mpr (Nat.cast_nonneg p)) + · rw [ratioBinMass, Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + rw [primeTilt_eq_multiplier, mul_comm (multiplier i s a)] + exact mul_le_mul_of_nonneg_left (hup p hp) (inv_nonneg.mpr (Nat.cast_nonneg p)) + +theorem sandwich_difference {ma mb R H D C E : ℝ} (hma : 0 ≤ ma) (hmb : 0 ≤ mb) + (hm : mb ≤ ma) (hE : 0 ≤ E) (hraw : |R-H| ≤ E) + (hD : mb*R ≤ D ∧ D ≤ ma*R) (hC : mb*H ≤ C ∧ C ≤ ma*H) : + |D-C| ≤ ma*E + (ma-mb)*H := by + rw [abs_le] + constructor + · have h := mul_le_mul_of_nonneg_left (show H-R ≤ E by linarith [(abs_le.mp hraw).1]) hmb + have h' := mul_le_mul_of_nonneg_right hm hE + nlinarith [hD.1,hC.2] + · have h := mul_le_mul_of_nonneg_left (abs_le.mp hraw).2 hma + nlinarith [hD.2,hC.1] + +theorem sub_le_mul_log_sub {a b : ℝ} (ha : 0 < a) (hb : 0 < b) : + a-b ≤ a*(Real.log a-Real.log b) := by + have h := Real.log_le_sub_one_of_pos (div_pos hb ha) + rw [Real.log_div hb.ne' ha.ne'] at h + have hm := mul_le_mul_of_nonneg_left h ha.le + have he : a*(b/a-1) = b-a := by field_simp + rw [he] at hm + nlinarith + +theorem multiplier_drop : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, 3 ≤ S → + ∀ i : Side, ∀ s a b : ℝ, Valid i s → minRatio i s ≤ a → a ≤ b → b ≤ S → + multiplier i s a-multiplier i s b ≤ multiplier i s a*(C*(1+S)^3*(b-a)) := by + obtain ⟨C,hC,hbound⟩ := multiplier_log_lipschitz + refine ⟨C,hC,?_⟩ + intro S hS i s a b hs hma hab hbS + have ha := valid_next hs hma + have hb := valid_next hs (hma.trans hab) + have h := hbound S hS i s a b hs ha hb (hab.trans hbS) hbS + rw [abs_sub_comm a b, abs_of_nonneg (sub_nonneg.mpr hab)] at h + exact (sub_le_mul_log_sub (multiplier_pos hs ha) (multiplier_pos hs hb)).trans + (mul_le_mul_of_nonneg_left ((le_abs_self _).trans h) (multiplier_pos hs ha).le) + +theorem weighted_bin_error : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ r : ℝ, 0 < r → ∀ i : Side, ∀ s a b : ℝ, + Valid i s → minRatio i s ≤ a → a ≤ b → 1/2 ≤ r/(b+1) → + |weightedPrimeBin w r i s a b-continuousBin i s a b| ≤ + multiplier i s a * (C*Real.exp (-c*Real.sqrt ((1/2 : ℝ)*Real.log w))) + + (multiplier i s a-multiplier i s b)*(Real.log (b+1)-Real.log (a+1)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hraw⟩ := prime_ratio_bin_error + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw r hr i s a b hs hma hab hlow + have ha := (minRatio_pos hs).trans_le hma + apply sandwich_difference (multiplier_pos hs (valid_next hs hma)).le + (multiplier_pos hs (valid_next hs (hma.trans hab))).le + (multiplier_antitone hs (Set.mem_Ici.mpr hma) (Set.mem_Ici.mpr (hma.trans hab)) hab) + (by positivity) (hraw w hw r a b hr ha hab hlow) + (weightedPrimeBin_sandwich hs hma hab) (continuousBin_sandwich hs hma hab) + +theorem weighted_bin_polynomial_error : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ r S : ℝ, 0 < r → 3 ≤ S → ∀ i : Side, ∀ s a b : ℝ, + Valid i s → s ≤ S → minRatio i s ≤ a → a ≤ b → b ≤ S → 1/2 ≤ r/(b+1) → + |weightedPrimeBin w r i s a b-continuousBin i s a b| ≤ + C*(1+S)^5*((b-a)^2+Real.exp (-c*Real.sqrt ((1/2 : ℝ)*Real.log w))) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,herr⟩ := weighted_bin_error + obtain ⟨D,hD,henv⟩ := multiplier_envelope + obtain ⟨L,hL,hdrop⟩ := multiplier_drop + let M := D*C+D*L + have hM : 0 < M := by dsimp [M]; positivity + refine ⟨c,M,w₀,hc,hM,hw₀,?_⟩ + intro w hw r S hr hS i s a b hs hsS hma hab hbS hlow + let P := 1+S + let e := Real.exp (-c*Real.sqrt ((1/2 : ℝ)*Real.log w)) + let H := Real.log (b+1)-Real.log (a+1) + let delta := multiplier i s a-multiplier i s b + have hP : 1 ≤ P := by dsimp [P]; linarith + have hP0 : 0 ≤ P := by linarith + have he : 0 ≤ e := (Real.exp_pos _).le + have hh : 0 ≤ b-a := sub_nonneg.mpr hab + have ha := (minRatio_pos hs).trans_le hma + have hH0 : 0 ≤ H := sub_nonneg.mpr (Real.log_le_log (by linarith) (by linarith)) + have hH : H ≤ b-a := ((bin_log_width_bounds ha hab).2).trans (div_le_self hh (by linarith)) + have hd0 : 0 ≤ delta := sub_nonneg.mpr + (multiplier_antitone hs (Set.mem_Ici.mpr hma) (Set.mem_Ici.mpr (hma.trans hab)) hab) + have hm := henv S i s a hs hsS hma + have hd : delta ≤ D*L*P^5*(b-a) := by + calc + _ ≤ multiplier i s a*(L*P^3*(b-a)) := hdrop S hS i s a b hs hma hab hbS + _ ≤ (D*P^2)*(L*P^3*(b-a)) := mul_le_mul_of_nonneg_right hm (by positivity) + _ = _ := by ring + have hp25 : P^2 ≤ P^5 := by + have h := mul_le_mul_of_nonneg_left (one_le_pow₀ hP : (1 : ℝ) ≤ P^3) (sq_nonneg P) + nlinarith + have hfirst : multiplier i s a*(C*e) ≤ D*C*P^5*e := by + calc + _ ≤ (D*P^2)*(C*e) := mul_le_mul_of_nonneg_right hm (mul_nonneg hC.le he) + _ = (D*C*e)*P^2 := by ring + _ ≤ (D*C*e)*P^5 := mul_le_mul_of_nonneg_left hp25 (by positivity) + _ = _ := by ring + have hsecond : delta*H ≤ D*L*P^5*(b-a)^2 := by + calc + _ ≤ (D*L*P^5*(b-a))*H := mul_le_mul_of_nonneg_right hd hH0 + _ ≤ (D*L*P^5*(b-a))*(b-a) := mul_le_mul_of_nonneg_left hH (by positivity) + _ = _ := by ring + have hDC : D*C ≤ M := le_add_of_nonneg_right (mul_nonneg hD.le hL.le) + have hDL : D*L ≤ M := le_add_of_nonneg_left (mul_nonneg hD.le hC.le) + calc + _ ≤ multiplier i s a*(C*e)+delta*H := herr w hw r hr i s a b hs hma hab hlow + _ ≤ D*C*P^5*e + D*L*P^5*(b-a)^2 := add_le_add hfirst hsecond + _ ≤ M*P^5*e + M*P^5*(b-a)^2 := add_le_add + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hDC (pow_nonneg hP0 _)) he) + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hDL (pow_nonneg hP0 _)) (sq_nonneg _)) + _ = _ := by dsimp [P,e]; ring + +end NumberTheoryLean.WeightedPrimeBins + +end + +section + +namespace NumberTheoryLean.NormalizedPrimeBins + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeTiltGeometry PrimeRatioBins PrimeTiltBounds +open WeightedPrimeBins ContinuousRatioBins PrimeKilledChain + +theorem division_error {D C e : ℝ} (hC : 0 ≤ C) (he : 0 ≤ e) : + |D/(1+e)-C| ≤ |D-C|+e*C := by + let A := |D-C| + have hA : 0 ≤ A := abs_nonneg _ + have hlo : C-A ≤ D := by dsimp [A]; linarith [neg_abs_le (D-C)] + have hup : D ≤ C+A := by dsimp [A]; linarith [le_abs_self (D-C)] + have hZ : 0 < 1+e := by linarith + have hu : D/(1+e) ≤ C+A := (div_le_iff₀ hZ).mpr (by + nlinarith [mul_nonneg (add_nonneg hC hA) he]) + have hl : C-A-e*C ≤ D/(1+e) := (le_div_iff₀ hZ).mpr (by + nlinarith [mul_nonneg hA he, mul_nonneg hC (sq_nonneg e)]) + rw [abs_le] + constructor <;> dsimp [A] at hu hl <;> nlinarith [mul_nonneg he hC] + +noncomputable def normalizedPrimeBin (w r : ℝ) (i : Side) (s a b : ℝ) : ℝ := + ∑ p ∈ ratioBin w r a b, primeTilt w r i s p/(1+epsilon w) + +theorem normalizedPrimeBin_eq (w r : ℝ) (i : Side) (s a b : ℝ) : + normalizedPrimeBin w r i s a b = weightedPrimeBin w r i s a b/(1+epsilon w) := by + exact (Finset.sum_div _ _ _).symm + +theorem normalized_bin_error : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ r S : ℝ, 0 < r → 3 ≤ S → ∀ i : Side, ∀ s a b : ℝ, + Valid i s → s ≤ S → minRatio i s ≤ a → a ≤ b → b ≤ S → 1/2 ≤ r/(b+1) → + |normalizedPrimeBin w r i s a b-continuousBin i s a b| ≤ + C*(1+S)^5*((b-a)^2+Real.exp (-c*Real.sqrt ((1/2 : ℝ)*Real.log w))) + + epsilon w*continuousBin i s a b := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hbound⟩ := weighted_bin_polynomial_error + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw r S hr hS i s a b hs hsS hma hab hbS hlow + rw [normalizedPrimeBin_eq] + exact (division_error (show 0 ≤ continuousBin i s a b from ENNReal.toReal_nonneg) (epsilon_pos w).le).trans + (add_le_add (hbound w hw r S hr hS i s a b hs hsS hma hab hbS hlow) le_rfl) + +end NumberTheoryLean.NormalizedPrimeBins + +end + +section + +namespace NumberTheoryLean.PrimeBinMembership + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeTiltGeometry PrimeTiltPrefixes PrimeHistories +open PrimeRatioBins NormalizedPrimeBins PrimeKilledChain +open ErdosPrimeInputs.HarmonicPrimeMeasure + +def Consistent (z : Node) : Prop := z.cutoff = z.gap/z.ratio + +theorem step_consistent {w ell S : ℝ} {z : Node} {p : ℕ} (hell : 0 ≤ ell) + (hr : 0 < z.gap) (hs : Valid z.side z.ratio) (hp : p ∈ nodeChildren w ell S z) : + Consistent (step w z p) := by + have hx := child_exponent_positive hell hp + have ht := valid_pos (child_valid hs hp) + change primeExponent w p = (z.gap-primeExponent w p)/childRatio w z.gap p + rw [← nextGap_childRatio hr hx ht, nextGap_div_ratio ht, nextExponent_childRatio hr hx] + +theorem terminal_consistent {w ell S : ℝ} {z : Node} {ps : List ℕ} (hell : 0 ≤ ell) + (hr : 0 < z.gap) (hs : Valid z.side z.ratio) (hz : Consistent z) (hp : allowed w ell S z ps) : + Consistent (terminal w z ps) := by + induction ps generalizing z with + | nil => exact hz + | cons p ps ih => + rcases (allowed_cons w ell S z p ps).mp hp with ⟨hc,ht⟩ + exact ih (child_gap_positive hell hr hs hc) (child_valid hs hc) (step_consistent hell hr hs hc) ht + +theorem history_consistent {w ell S : ℝ} {start : Node} (hell : 0 ≤ ell) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hc : Consistent start) + (h : History w ell S start) : Consistent h.node := + terminal_consistent hell hr hs hc h.admissible + +theorem children_full_bin {w ell S s r cap a b : ℝ} {i : Side} (hw : 1 < w) + (hell : 0 < ell) (_hr : 0 < r) (hs : Valid i s) (hcap : cap = r/s) + (hma : minRatio i s < a) (hab : a ≤ b) (hbS : b ≤ S) (harr : b ≤ r/ell-1) (closed : Bool) : + (children w ell S i s r cap closed).filter (fun p => a ≤ childRatio w r p ∧ childRatio w r p < b) = + ratioBin w r a b := by + classical + have ha : 0 < a := (PrimeTiltMonotone.minRatio_pos hs).trans hma + have hb : 0 < b := ha.trans_le hab + have hs0 := valid_pos hs + ext p + constructor + · intro hp + rcases Finset.mem_filter.mp hp with ⟨hchild,hbin⟩ + have hprime := ((mem_children_iff hw i closed p).mp hchild).1 + have hxp := PrimeRatioBins.primeExponent_pos hw hprime + have hinterval := (ratio_interval_iff (r := r) ha hab hxp).mp hbin + have hp0 : (0 : ℝ) < p := by exact_mod_cast hprime.pos + have hreal : (p : ℝ) ≤ w^(r/(a+1)) := (exponent_le_iff hw hp0).mp hinterval.2 + apply Finset.mem_filter.mpr + exact ⟨Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) _).le).mpr hreal,hprime⟩,hbin⟩ + · intro hp + rcases Finset.mem_filter.mp hp with ⟨hpprime,hbin⟩ + have hprime := (Nat.mem_primesLE.mp hpprime).2 + have hxp := PrimeRatioBins.primeExponent_pos hw hprime + have hinterval := (ratio_interval_iff (r := r) ha hab hxp).mp hbin + have hlow : ell ≤ r/(b+1) := by + apply (le_div_iff₀ (by linarith : 0 < b+1)).mpr + have h := (le_div_iff₀ hell).mp (show b+1 ≤ r/ell by linarith) + nlinarith + have hbelow : primeExponent w p < cap := by + rw [hcap] + apply (lt_div_iff₀ hs0).mpr + have hrat : s < r/primeExponent w p := by + have hmin := minRatio_ge_sub_one i s + have hlo : a ≤ r/primeExponent w p-1 := hbin.1 + linarith + have h := (lt_div_iff₀ hxp).mp hrat + nlinarith + have hguard : capGuard closed cap (primeExponent w p) := by + cases closed with + | false => exact hbelow + | true => exact hbelow.le + apply Finset.mem_filter.mpr + refine ⟨(mem_children_iff hw i closed p).mpr ⟨hprime,hlow.trans_lt hinterval.1,hguard,?_,?_⟩,hbin⟩ + · exact hma.le.trans hbin.1 + · exact hbin.2.le.trans hbS + +theorem normalized_children_full_bin {w ell S s r cap a b : ℝ} {i : Side} (hw : 1 < w) + (hell : 0 < ell) (hr : 0 < r) (hs : Valid i s) (hcap : cap = r/s) + (hma : minRatio i s < a) (hab : a ≤ b) (hbS : b ≤ S) (harr : b ≤ r/ell-1) (closed : Bool) : + (∑ p ∈ children w ell S i s r cap closed, + if a ≤ childRatio w r p ∧ childRatio w r p < b then primeTilt w r i s p/(1+epsilon w) else 0) = + normalizedPrimeBin w r i s a b := by + classical + rw [← Finset.sum_filter, children_full_bin hw hell hr hs hcap hma hab hbS harr closed] + rfl + +end NumberTheoryLean.PrimeBinMembership + +end + +section + +namespace NumberTheoryLean.ActualPrimeBins + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeTiltBounds PrimeHistories PrimeKilledChain +open PrimeBinMembership NormalizedPrimeBins PrimeRatioBins + +variable {w ell S : ℝ} {start : Node} + +def liveBin (a b : ℝ) : Set (ChainState w ell S start) := + fun z => match z with + | none => False + | some h => a ≤ h.node.ratio ∧ h.node.ratio < b + +theorem mem_liveBin_some (h : History w ell S start) (a b : ℝ) : + some h ∈ liveBin a b ↔ a ≤ h.node.ratio ∧ h.node.ratio < b := Iff.rfl + +theorem not_mem_liveBin_none (a b : ℝ) : + (none : ChainState w ell S start) ∉ liveBin a b := by + change ¬False + exact not_false + +theorem liveBin_measurable (a b : ℝ) : MeasurableSet (liveBin (w := w) (ell := ell) (S := S) (start := start) a b) := trivial + +theorem chain_live_bin_formula (h : History w ell S start) (a b : ℝ) : + chain w ell S start (some h) (liveBin a b) = + ∑ p ∈ nodeChildren w ell S h.node, + if a ≤ childRatio w h.node.gap p ∧ childRatio w h.node.gap p < b then childProbability w ell S start h p else 0 := by + classical + simp only [chain_some, completedLaw, Measure.add_apply, liveLaw, Measure.finsetSum_apply, + Measure.smul_apply, smul_eq_mul, Measure.dirac_apply, Set.indicator, mem_liveBin_some, not_mem_liveBin_none, History.append_node, step, + Pi.one_apply, mul_ite, mul_one, mul_zero, ite_false, add_zero] + exact Finset.sum_attach _ (fun p : ℕ => + if a ≤ childRatio w h.node.gap p ∧ childRatio w h.node.gap p < b then childProbability w ell S start h p else 0) + +theorem chain_full_bin (h : History w ell S start) {a b : ℝ} (hw : 1 < w) + (hell : 0 < ell) (hr : 0 < h.node.gap) (hs : Valid h.node.side h.node.ratio) (hc : Consistent h.node) + (hma : minRatio h.node.side h.node.ratio < a) (hab : a ≤ b) (hbS : b ≤ S) + (harr : b ≤ h.node.gap/ell-1) : + chain w ell S start (some h) (liveBin a b) = + ENNReal.ofReal (normalizedPrimeBin w h.node.gap h.node.side h.node.ratio a b) := by + classical + rw [chain_live_bin_formula] + have hnonneg : ∀ p ∈ nodeChildren w ell S h.node, + 0 ≤ if a ≤ childRatio w h.node.gap p ∧ childRatio w h.node.gap p < b + then primeTilt w h.node.gap h.node.side h.node.ratio p/(1+epsilon w) else 0 := by + intro p hp + split_ifs + · exact div_nonneg (primeTilt_nonneg (w := w) (r := h.node.gap) (i := h.node.side) (s := h.node.ratio) hs hp) (normalizer_pos w).le + · exact le_rfl + calc + _ = ENNReal.ofReal (∑ p ∈ nodeChildren w ell S h.node, + if a ≤ childRatio w h.node.gap p ∧ childRatio w h.node.gap p < b + then primeTilt w h.node.gap h.node.side h.node.ratio p/(1+epsilon w) else 0) := by + rw [ENNReal.ofReal_sum_of_nonneg hnonneg] + apply Finset.sum_congr rfl + intro p hp + split_ifs <;> simp only [childProbability, ENNReal.ofReal_zero] + _ = _ := congrArg ENNReal.ofReal (normalized_children_full_bin hw hell hr hs hc hma hab hbS harr h.node.closed) + +theorem chain_full_bin_real (h : History w ell S start) {a b : ℝ} (hw : 1 < w) + (hell : 0 < ell) (hr : 0 < h.node.gap) (hs : Valid h.node.side h.node.ratio) (hc : Consistent h.node) + (hma : minRatio h.node.side h.node.ratio < a) (hab : a ≤ b) (hbS : b ≤ S) + (harr : b ≤ h.node.gap/ell-1) : + (chain w ell S start (some h) (liveBin a b)).toReal = + normalizedPrimeBin w h.node.gap h.node.side h.node.ratio a b := by + rw [chain_full_bin h hw hell hr hs hc hma hab hbS harr] + apply ENNReal.toReal_ofReal + unfold normalizedPrimeBin + apply Finset.sum_nonneg + intro p hp + have ht := (Finset.mem_filter.mp hp).2 + rw [primeTilt_eq_multiplier] + exact div_nonneg (mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg p)) + (multiplier_pos hs (valid_next hs (hma.le.trans ht.1))).le) (normalizer_pos w).le + +end NumberTheoryLean.ActualPrimeBins + +end + +section + +namespace NumberTheoryLean.ActualPrimeHigh +open FinitePathGeometry PrimeTiltGeometry PrimeTiltPrefixes PrimeHistories PrimeBinMembership +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass +open ErdosPrimeInputs.HighPrimeGeometry + +theorem allowed_prime_bounds {w ell U : ℝ} (hw : 1 < w) {z : Node} {ps : List ℕ} + (hpath : allowed w ell U z ps) : ∀ p ∈ ps, + p.Prime ∧ ell < primeExponent w p ∧ capGuard z.closed z.cutoff (primeExponent w p) := by + induction ps generalizing z with + | nil => simp + | cons p ps ih => + obtain ⟨hc,ht⟩ := (allowed_cons w ell U z p ps).mp hpath + have hdata := (mem_children_iff hw z.side z.closed p).mp hc + intro q hq + rcases List.mem_cons.mp hq with rfl | hq + · exact ⟨hdata.1,hdata.2.1,hdata.2.2.1⟩ + · have htail := ih ht q hq + have hqp : primeExponent w q < primeExponent w p := htail.2.2 + refine ⟨htail.1,htail.2.1,?_⟩ + have hpcap := hdata.2.2.1 + cases he : z.closed <;> simp only [capGuard,he,Bool.false_eq_true,ite_false,ite_true] at hpcap ⊢ + · exact hqp.trans hpcap + · exact hqp.le.trans hpcap + +theorem allowed_decreasing {w ell U : ℝ} (hw : 1 < w) {z : Node} {ps : List ℕ} + (hpath : allowed w ell U z ps) : ps.Pairwise (· > ·) := by + induction ps generalizing z with + | nil => simp + | cons p ps ih => + obtain ⟨hc,ht⟩ := (allowed_cons w ell U z p ps).mp hpath + refine List.pairwise_cons.mpr ⟨?_,ih ht⟩ + intro q hq + have hqp : primeExponent w q < primeExponent w p := (allowed_prime_bounds hw ht q hq).2.2 + exact lt_of_not_ge (fun hpq => (not_lt_of_ge (exponent_monotone hw hpq)) hqp) + +theorem allowed_mem_decreasing {w ell U : ℝ} (hw : 1 < w) {z : Node} {ps : List ℕ} + (hpath : allowed w ell U z ps) : + ps ∈ decreasingPrefixes (primesBetween (w^ell) (w^z.cutoff)) := by + apply mem_decreasingPrefixes.mpr + refine ⟨allowed_decreasing hw hpath,?_⟩ + intro p hp + obtain ⟨hprime,hlo,hcap⟩ := allowed_prime_bounds hw hpath p hp + have hp0 : (0 : ℝ) < p := by exact_mod_cast hprime.pos + have hup : primeExponent w p ≤ z.cutoff := by + cases he : z.closed <;> simp only [capGuard,he,Bool.false_eq_true,ite_false,ite_true] at hcap + · exact hcap.le + · exact hcap + have hlow : w^ell < (p : ℝ) := (lt_exponent_iff hw hp0).mp hlo + have hhigh : (p : ℝ) ≤ w^z.cutoff := (exponent_le_iff hw hp0).mp hup + apply Finset.mem_filter.mpr + refine ⟨Nat.mem_primesLE.mpr ⟨?_,hprime⟩,hlow⟩ + exact (Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) _).le).mpr hhigh + +theorem terminal_gap_remaining (w : ℝ) (z : Node) (ps : List ℕ) : + (terminal w z ps).gap = remainingGap z.gap w ps := by + induction ps generalizing z with + | nil => simp [remainingGap] + | cons p ps ih => + rw [terminal_cons,ih] + simp only [remainingGap,step,List.map_cons,List.sum_cons] + ring + +theorem terminal_cutoff (w : ℝ) (z : Node) (ps : List ℕ) : + (terminal w z ps).cutoff = primeCutoff w z.cutoff ps := by + induction ps generalizing z with + | nil => rfl + | cons p ps ih => exact ih (step w z p) + +theorem terminal_ratio_remaining {w ell U : ℝ} {z : Node} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) + (hz : Consistent z) (hp : allowed w ell U z ps) : + (terminal w z ps).ratio = remainingGap z.gap w ps / primeCutoff w z.cutoff ps := by + have hc := terminal_consistent hell hr hs hz hp + have hg := terminal_gap_positive hell hr hs hp + have hv := valid_pos (terminal_valid hs hp) + rw [← terminal_gap_remaining w z ps,← terminal_cutoff w z ps] + change (terminal w z ps).cutoff = (terminal w z ps).gap/(terminal w z ps).ratio at hc + rw [hc] + field_simp + +noncomputable def actualHasHigh (w T : ℝ) (z : Node) (ps : List ℕ) : Prop := + ∃ pre suf : List ℕ, ps = pre ++ suf ∧ T < (terminal w z pre).ratio + +theorem actual_has_high_iff {w ell U T : ℝ} {z : Node} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) + (hz : Consistent z) (hp : allowed w ell U z ps) : + actualHasHigh w T z ps ↔ hasHighState z.gap w z.cutoff T ps := by + constructor <;> rintro ⟨pre,suf,he,hh⟩ + · have hpre : allowed w ell U z pre := (allowed_append w ell U z pre suf).mp (he ▸ hp) |>.1 + rw [terminal_ratio_remaining hell hr hs hz hpre] at hh + exact ⟨pre,suf,he,hh⟩ + · have hpre : allowed w ell U z pre := (allowed_append w ell U z pre suf).mp (he ▸ hp) |>.1 + rw [← terminal_ratio_remaining hell hr hs hz hpre] at hh + exact ⟨pre,suf,he,hh⟩ + +end NumberTheoryLean.ActualPrimeHigh + +end + +section + +namespace NumberTheoryLean.ActualPrimeHigh +open FinitePathGeometry PrimeTiltGeometry PrimeTiltPrefixes PrimeHistories PrimeBinMembership +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass +open ErdosPrimeInputs.HighPrimeGeometry + +noncomputable def uncappedChildren (w ell : ℝ) (z : Node) : Finset ℕ := by + classical + exact (Nat.primesLE ⌊w^z.cutoff⌋₊).filter (fun p => ell < primeExponent w p ∧ + capGuard z.closed z.cutoff (primeExponent w p) ∧ + minRatio z.side z.ratio ≤ childRatio w z.gap p) + +noncomputable def uncappedAllowed (w ell : ℝ) : Node → List ℕ → Prop + | _, [] => True + | z, p::ps => p ∈ uncappedChildren w ell z ∧ uncappedAllowed w ell (step w z p) ps + +theorem allowed_mono {w ell U V : ℝ} (hUV : U ≤ V) {z : Node} {ps : List ℕ} + (hp : allowed w ell U z ps) : allowed w ell V z ps := by + classical + induction ps generalizing z with + | nil => trivial + | cons p ps ih => + obtain ⟨hc,ht⟩ := (allowed_cons w ell U z p ps).mp hp + obtain ⟨hprime,hlo,hcap,hmin,hmax⟩ := Finset.mem_filter.mp hc + apply (allowed_cons w ell V z p ps).mpr + exact ⟨Finset.mem_filter.mpr ⟨hprime,hlo,hcap,hmin,hmax.trans hUV⟩,ih ht⟩ + +theorem uncapped_iff_exists_ceiling (w ell : ℝ) (z : Node) (ps : List ℕ) : + uncappedAllowed w ell z ps ↔ ∃ U : ℝ, z.ratio ≤ U ∧ allowed w ell U z ps := by + classical + induction ps generalizing z with + | nil => exact ⟨fun _ => ⟨z.ratio,le_rfl,trivial⟩,fun _ => trivial⟩ + | cons p ps ih => + constructor + · rintro ⟨hc,ht⟩ + obtain ⟨U,hchildU,hrest⟩ := (ih (step w z p)).mp ht + let V := max U z.ratio + refine ⟨V,le_max_right _ _,?_⟩ + obtain ⟨hprime,hlo,hcap,hmin⟩ := Finset.mem_filter.mp hc + apply (allowed_cons w ell V z p ps).mpr + refine ⟨Finset.mem_filter.mpr ⟨hprime,hlo,hcap,hmin,?_⟩, + allowed_mono (le_max_left _ _) hrest⟩ + exact hchildU.trans (le_max_left _ _) + · rintro ⟨U,_hstart,hpath⟩ + obtain ⟨hc,ht⟩ := (allowed_cons w ell U z p ps).mp hpath + obtain ⟨hprime,hlo,hcap,hmin,hmax⟩ := Finset.mem_filter.mp hc + refine ⟨Finset.mem_filter.mpr ⟨hprime,hlo,hcap,hmin⟩,?_⟩ + exact (ih (step w z p)).mpr ⟨U,hmax,ht⟩ + +theorem uncapped_mem_decreasing {w ell : ℝ} (hw : 1 < w) {z : Node} {ps : List ℕ} + (hp : uncappedAllowed w ell z ps) : + ps ∈ decreasingPrefixes (primesBetween (w^ell) (w^z.cutoff)) := by + obtain ⟨U,_,hU⟩ := (uncapped_iff_exists_ceiling w ell z ps).mp hp + exact allowed_mem_decreasing hw hU + +noncomputable def uncappedPrefixes (w ell : ℝ) (z : Node) : Finset (List ℕ) := by + classical + exact (decreasingPrefixes (primesBetween (w^ell) (w^z.cutoff))).filter (uncappedAllowed w ell z) + +theorem mem_uncappedPrefixes {w ell : ℝ} (hw : 1 < w) (z : Node) (ps : List ℕ) : + ps ∈ uncappedPrefixes w ell z ↔ uncappedAllowed w ell z ps := by + classical + exact ⟨fun h => (Finset.mem_filter.mp h).2, + fun h => Finset.mem_filter.mpr ⟨uncapped_mem_decreasing hw h,h⟩⟩ + +theorem uncapped_gap_positive {w ell : ℝ} {z : Node} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) + (hp : uncappedAllowed w ell z ps) : 0 < (terminal w z ps).gap := by + obtain ⟨U,_,hU⟩ := (uncapped_iff_exists_ceiling w ell z ps).mp hp + exact terminal_gap_positive hell hr hs hU + +theorem uncapped_has_high_iff {w ell T : ℝ} {z : Node} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) (hz : Consistent z) + (hp : uncappedAllowed w ell z ps) : + actualHasHigh w T z ps ↔ hasHighState z.gap w z.cutoff T ps := by + obtain ⟨U,_,hU⟩ := (uncapped_iff_exists_ceiling w ell z ps).mp hp + exact actual_has_high_iff hell hr hs hz hU + +end NumberTheoryLean.ActualPrimeHigh + +end + +section + +open scoped BigOperators +namespace NumberTheoryLean.ActualPrimeHigh +attribute [local instance] Classical.propDecidable +open FinitePathGeometry PrimeHistories PrimeBinMembership +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail ErdosPrimeInputs.HighPrimeGeometry + +noncomputable def uncappedLowGapHighMass (w ell : ℝ) (z : Node) (T K : ℝ) : ℝ := by + classical + exact ∑ ps ∈ (uncappedPrefixes w ell z).filter + (fun ps => (terminal w z ps).gap ≤ K ∧ actualHasHigh w T z ps), prefixWeight ps + +noncomputable def uncappedRewardedHighMass (w ell : ℝ) (z : Node) (T c : ℝ) : ℝ := by + classical + exact ∑ ps ∈ (uncappedPrefixes w ell z).filter (actualHasHigh w T z), + prefixWeight ps * Real.exp (-c*(terminal w z ps).gap) + +theorem uncapped_reward_filter {w ell T : ℝ} (hw : 1 < w) {z : Node} + (hell : 0 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) : + (uncappedPrefixes w ell z).filter (actualHasHigh w T z) = + (uncappedPrefixes w ell z).filter + (fun ps => actualHasHigh w T z ps ∧ 0 ≤ (terminal w z ps).gap) := by + classical + ext ps + simp only [Finset.mem_filter] + constructor + · rintro ⟨hp,hh⟩ + exact ⟨hp,hh,(uncapped_gap_positive hell hr hs ((mem_uncappedPrefixes hw z ps).mp hp)).le⟩ + · rintro ⟨hp,hh,_⟩ + exact ⟨hp,hh⟩ + +theorem uncapped_low_mass_le {w ell : ℝ} (_hw : 1 < w) {z : Node} + (hell : 0 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) + (hz : Consistent z) (T K : ℝ) : + uncappedLowGapHighMass w ell z T K ≤ + ErdosPrimeInputs.HighPrimeMass.lowGapHighMass z.gap w z.cutoff ell T K := by + classical + unfold uncappedLowGapHighMass ErdosPrimeInputs.HighPrimeMass.lowGapHighMass + simp only [terminal_gap_remaining] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro ps hp + obtain ⟨hfamily,hgap,hhigh⟩ := Finset.mem_filter.mp hp + obtain ⟨hdec,hactual⟩ := Finset.mem_filter.mp hfamily + exact Finset.mem_filter.mpr ⟨hdec,hgap, + (uncapped_has_high_iff hell hr hs hz hactual).mp hhigh⟩ + · intro ps _ _ + exact prefixWeight_nonneg ps + +theorem uncapped_rewarded_mass_le {w ell : ℝ} (_hw : 1 < w) {z : Node} + (hell : 0 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) + (hz : Consistent z) (T c : ℝ) : + uncappedRewardedHighMass w ell z T c ≤ + ErdosPrimeInputs.HighPrimeMass.rewardedHighMass z.gap w z.cutoff ell T c := by + classical + unfold uncappedRewardedHighMass ErdosPrimeInputs.HighPrimeMass.rewardedHighMass + simp only [terminal_gap_remaining] + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro ps hp + obtain ⟨hfamily,hhigh⟩ := Finset.mem_filter.mp hp + obtain ⟨hdec,hactual⟩ := Finset.mem_filter.mp hfamily + have hgap := (uncapped_gap_positive hell hr hs hactual).le + rw [terminal_gap_remaining] at hgap + exact Finset.mem_filter.mpr ⟨hdec, + (uncapped_has_high_iff hell hr hs hz hactual).mp hhigh,hgap⟩ + · intro ps _ _ + exact mul_nonneg (prefixWeight_nonneg ps) (Real.exp_pos _).le + +end NumberTheoryLean.ActualPrimeHigh + +end + +section + +namespace NumberTheoryLean.PrimeFamilyOccupation +open FinitePathGeometry PrimeHistories PrimeKilledChain +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass +open ActualPrimeHigh + +noncomputable def retainedPrefixes (w ell S : ℝ) (start : Node) : Finset (List ℕ) := by + classical + exact (uncappedPrefixes w ell start).filter (allowed w ell S start) + +theorem mem_retainedPrefixes {w ell S : ℝ} (hw : 1 < w) (start : Node) (ps : List ℕ) : + ps ∈ retainedPrefixes w ell S start ↔ allowed w ell S start ps := by + classical + constructor + · intro h + exact (Finset.mem_filter.mp h).2 + · intro h + apply Finset.mem_filter.mpr + refine ⟨(mem_uncappedPrefixes hw start ps).mpr ?_,h⟩ + apply (uncapped_iff_exists_ceiling w ell start ps).mpr + exact ⟨max S start.ratio,le_max_right _ _,allowed_mono (le_max_left _ _) h⟩ + +noncomputable def retainedHistoryEquiv {w ell S : ℝ} (hw : 1 < w) (start : Node) : + {ps // ps ∈ retainedPrefixes w ell S start} ≃ History w ell S start where + toFun ps := ⟨ps.val,(mem_retainedPrefixes hw start ps.val).mp ps.property⟩ + invFun h := ⟨h.primes,(mem_retainedPrefixes hw start h.primes).mpr h.admissible⟩ + left_inv ps := by cases ps; rfl + right_inv h := by cases h; rfl + +noncomputable abbrev historyFintype {w ell S : ℝ} (hw : 1 < w) (start : Node) : + Fintype (History w ell S start) := + Fintype.ofEquiv {ps // ps ∈ retainedPrefixes w ell S start} (retainedHistoryEquiv hw start) + +theorem sum_histories {w ell S : ℝ} (hw : 1 < w) (start : Node) (F : List ℕ → ℝ) : + letI := historyFintype (ell := ell) (S := S) hw start + (∑ h : History w ell S start,F h.primes) = + ∑ ps ∈ retainedPrefixes w ell S start,F ps := by + classical + let := historyFintype (ell := ell) (S := S) hw start + calc + _ = ∑ ps : {ps // ps ∈ retainedPrefixes w ell S start},F ps.val := + (Equiv.sum_comp (retainedHistoryEquiv hw start) (fun h => F h.primes)).symm + _ = _ := Finset.sum_attach _ F + +theorem retained_history_horizon {w ell S B : ℝ} (hw : 1 < w) + (hell : 1 ≤ ell) (hS0 : 0 ≤ S) {start : Node} + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (hB : 0 < B) (hsize : start.gap ≤ (23/10 : ℝ)*B) + {ps : List ℕ} (hps : ps ∈ retainedPrefixes w ell S start) : + ps.length < LowStateHorizon.sourceHorizon S B := by + exact PrimeHistoryHorizon.history_length_lt hell hS0 hr hs hB hsize + ⟨ps,(mem_retainedPrefixes hw start ps).mp hps⟩ + +end NumberTheoryLean.PrimeFamilyOccupation + +end + +section + +namespace NumberTheoryLean.PrimeCompactWeights + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeCompactVisits +open PrimeCorrectionFactor PrimeBinMembership PrimeTiltGeometry DerivativeWeights + +noncomputable def inverseBound (K : ℝ) : ℝ := max (1/weight .even K) (1/weight .odd K) + +theorem valid_compact_end {K : ℝ} (hK : 3 ≤ K) (i : Side) : Valid i K := by + cases i <;> change _ ≤ K <;> linarith + +theorem inverseBound_pos {K : ℝ} (hK : 3 ≤ K) : 0 < inverseBound K := + (one_div_pos.mpr (weight_pos (valid_compact_end hK .even))).trans_le (le_max_left _ _) + +theorem compact_inverse_weight {K s : ℝ} {i : Side} (hK : 3 ≤ K) (hs : Valid i s) (hsK : s ≤ K) : + 1/weight i s ≤ inverseBound K := by + have hpos := weight_pos (valid_compact_end hK i) + have hmono := TwoStepDensityBounds.weight_antitone hs (valid_compact_end hK i) hsK + have h := one_div_le_one_div_of_le hpos hmono + cases i with + | even => exact h.trans (le_max_left _ _) + | odd => exact h.trans (le_max_right _ _) + +theorem terminal_cutoff_lower {w ell S : ℝ} {start : Node} {ps : List ℕ} + (hc : ell ≤ start.cutoff) (hp : allowed w ell S start ps) : ell ≤ (terminal w start ps).cutoff := by + classical + induction ps generalizing start with + | nil => exact hc + | cons p ps ih => + obtain ⟨hchild,htail⟩ := (allowed_cons w ell S start p ps).mp hp + have hlo : ell < ErdosPrimeInputs.HarmonicPrimeMeasure.primeExponent w p := + (Finset.mem_filter.mp hchild).2.1 + exact ih hlo.le htail + +theorem history_ratio_le_gap {w ell S : ℝ} {start : Node} + (hell : 1 ≤ ell) (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (hc : Consistent start) (hcut : ell ≤ start.cutoff) (h : History w ell S start) : + h.node.ratio ≤ h.node.gap := by + have hv : 0 < h.node.ratio := valid_pos (terminal_valid hs h.admissible) + have hn : Consistent h.node := history_consistent (by linarith) hr hs hc h + have hlow : ell ≤ h.node.cutoff := terminal_cutoff_lower hcut h.admissible + change h.node.cutoff = h.node.gap/h.node.ratio at hn + have he := (eq_div_iff hv.ne').mp hn + nlinarith + +noncomputable def compactConstant (K : ℝ) : ℝ := + 2*K^2*weight .even (199/100)*inverseBound K + +theorem compactConstant_pos {K : ℝ} (hK : 3 ≤ K) : 0 < compactConstant K := by + have hφ : 0 < weight .even (199/100) := weight_pos (by norm_num [Valid]) + have hI := inverseBound_pos hK + unfold compactConstant + positivity + +noncomputable def scaledWeight (w B : ℝ) {ell S : ℝ} (start : Node) : ChainState w ell S start → ℝ + | none => 0 + | some h => B^2*(1+epsilon w)^h.primes.length*(h.node.gap/start.gap)^2* + (weight start.side start.ratio/weight h.node.side h.node.ratio) + +theorem scaledWeight_nonneg {w B ell S : ℝ} {start : Node} + (hs : Valid start.side start.ratio) (z : ChainState w ell S start) : 0 ≤ scaledWeight w B start z := by + cases z with + | none => exact le_rfl + | some h => + have hφ := (weight_pos hs).le + have hφ' := (weight_pos (terminal_valid hs h.admissible)).le + have he := (normalizer_pos w).le + unfold scaledWeight + positivity + +theorem scaled_compact_bound {d w ell B K : ℝ} {start : Node} + (hK : 3 ≤ K) (hB : 0 < B) (hell : 1 ≤ ell) (hellB : ell ≤ B) + (hlogB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) + (hbudget : correctionBudget d w ≤ 1) + (hi : start.side = .even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hc : Consistent start) (hcut : start.cutoff = B) + (h : History w ell ((Real.log B)^2) start) (hgK : h.node.gap ≤ K) : + scaledWeight w B start (some h) ≤ compactConstant K := by + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hs0 := valid_pos hs + have he : start.gap = B*start.ratio := by + have hh : start.cutoff = start.gap/start.ratio := hc + rw [hcut] at hh + exact ((eq_div_iff hs0.ne').mp hh).symm + have hr : 0 < start.gap := by rw [he]; positivity + have hBr : B ≤ start.gap := by rw [he]; nlinarith + have hsize : start.gap ≤ (23/10:ℝ)*B := by rw [he]; nlinarith + have hrat : h.node.ratio ≤ K := (history_ratio_le_gap hell hr hs hc (by rwa [hcut]) h).trans hgK + have hgv : Valid h.node.side h.node.ratio := terminal_valid hs h.admissible + have hgp : 0 < h.node.gap := terminal_gap_positive (by linarith) hr hs h.admissible + have hinv := compact_inverse_weight hK hgv hrat + have hinit : weight start.side start.ratio ≤ weight .even (199/100) := by + rw [hi] + exact TwoStepDensityBounds.weight_antitone (by norm_num [Valid]) (hi ▸ hs) h199 + have hcorr : (1+epsilon w)^h.primes.length ≤ 2 := by + have hh := (history_correction hlogB hcomp hell hr hs hB hsize h).2 + linarith + have hgap : B^2*(h.node.gap/start.gap)^2 ≤ K^2 := by + have hratio : B/start.gap ≤ 1 := (div_le_one hr).mpr hBr + have hpos : 0 ≤ B/start.gap := div_nonneg hB.le hr.le + have heq : B^2*(h.node.gap/start.gap)^2 = (B/start.gap)^2*h.node.gap^2 := by ring + rw [heq] + have h1 : (B/start.gap)^2 ≤ 1 := by nlinarith + have h2 : h.node.gap^2 ≤ K^2 := by nlinarith + nlinarith [sq_nonneg (B/start.gap),mul_nonneg (sub_nonneg.mpr h1) (sq_nonneg h.node.gap)] + have hC : 0 ≤ (1+epsilon w)^h.primes.length := pow_nonneg (normalizer_pos w).le _ + have hI : 0 ≤ inverseBound K := (inverseBound_pos hK).le + have hφ : 0 ≤ weight .even (199/100) := (weight_pos (by norm_num [Valid])).le + have hpφ : 0 ≤ weight start.side start.ratio := (weight_pos hs).le + have hφg : 0 < weight h.node.side h.node.ratio := weight_pos hgv + calc + _ = ((1+epsilon w)^h.primes.length*(B^2*(h.node.gap/start.gap)^2))* + (weight start.side start.ratio*(1/weight h.node.side h.node.ratio)) := by unfold scaledWeight; ring + _ ≤ (2*K^2)*(weight .even (199/100)*inverseBound K) := by + exact mul_le_mul (mul_le_mul hcorr hgap (by positivity) (by norm_num)) + (mul_le_mul hinit hinv (by positivity) hφ) (by positivity) (by positivity) + _ = _ := by unfold compactConstant; ring + +end NumberTheoryLean.PrimeCompactWeights + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeCountAbel.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeCountAbel.lean new file mode 100644 index 0000000000000000000000000000000000000000..7752e93b4d6b0fc381f4c0fd199015a9610c1e02 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeCountAbel.lean @@ -0,0 +1,179 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import PrimeNumberTheoremAnd.Erdos970.Consequences +import OAI.NumberTheory.Jacobsthal.Primes.HighPrimeRemoval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosPrimeInputs.PrimeCountingPrimitive + +open _root_.Set _root_.Filter _root_.MeasureTheory _root_.Asymptotics +open _root_.Erdos970.Set _root_.Erdos970.Filter _root_.Erdos970.MeasureTheory _root_.Erdos970.Asymptotics +open scoped Topology +open PrimeErrorDecay StrongChebyshev + +noncomputable def scale (c x : ℝ) : ℝ := x * decay c x / Real.log x +noncomputable def kernel (c x : ℝ) : ℝ := decay c x / Real.log x ^ 2 +noncomputable def slope (c x : ℝ) : ℝ := decay c x / Real.log x * + (1 - 1 / Real.log x - c / (2 * Real.sqrt (Real.log x))) + +lemma scale_nonneg {c x : ℝ} (hx : 1 ≤ x) : 0 ≤ scale c x := + div_nonneg (mul_nonneg (by linarith) (decay_pos c x).le) (Real.log_nonneg hx) + +lemma hasDerivAt_scale {c x : ℝ} (hx : 1 < x) : + HasDerivAt (scale c) (slope c x) x := by + have hx0 : x ≠ 0 := ne_of_gt (by linarith) + have hl0 : Real.log x ≠ 0 := ne_of_gt (Real.log_pos hx) + have hs0 : Real.sqrt (Real.log x) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (Real.log_pos hx)) + convert! ((hasDerivAt_id x).mul (hasDerivAt_decay hx)).div (Real.hasDerivAt_log hx0) hl0 using 1 + simp only [slope, tailKernel, id_eq, Pi.mul_apply] + field_simp + ring + +lemma kernel_le_slope {c x : ℝ} (hc : 0 ≤ c) + (hx : 1 < x) (hl : 4 ≤ Real.log x) (hc2 : 4*c^2 ≤ Real.log x) : + kernel c x ≤ slope c x := by + have hl0 := Real.log_pos hx + have hs := Real.sqrt_nonneg (Real.log x) + have hs0 := Real.sqrt_pos.mpr hl0 + have hs2 := Real.sq_sqrt hl0.le + have hcS : 2*c ≤ Real.sqrt (Real.log x) := by nlinarith + have hi : 1 / Real.log x ≤ 1/4 := (div_le_iff₀ hl0).mpr (by linarith) + have hj : c / (2 * Real.sqrt (Real.log x)) ≤ 1/4 := + (div_le_iff₀ (by positivity)).mpr (by nlinarith) + have h : 1 / Real.log x ≤ 1 - 1 / Real.log x - c / (2 * Real.sqrt (Real.log x)) := by linarith + calc + kernel c x = (decay c x / Real.log x) * (1 / Real.log x) := by unfold kernel; ring + _ ≤ slope c x := mul_le_mul_of_nonneg_left h (div_nonneg (decay_pos c x).le hl0.le) + +lemma continuousOn_kernel {c a b : ℝ} (ha : 1 < a) : + ContinuousOn (kernel c) (Icc a b) := by + intro t ht + have ht0 : t ≠ 0 := ne_of_gt (by linarith [ht.1]) + have hlt0 : Real.log t ≠ 0 := ne_of_gt (Real.log_pos (by linarith [ht.1])) + apply ContinuousAt.continuousWithinAt + unfold kernel decay + fun_prop (disch := simp [hlt0]) + +lemma continuousOn_slope {c a b : ℝ} (ha : 1 < a) : + ContinuousOn (slope c) (Icc a b) := by + intro t ht + have ht1 : 1 < t := lt_of_lt_of_le ha ht.1 + have ht0 : t ≠ 0 := ne_of_gt (by linarith) + have hlt0 : Real.log t ≠ 0 := ne_of_gt (Real.log_pos ht1) + have hst0 : Real.sqrt (Real.log t) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (Real.log_pos ht1)) + apply ContinuousAt.continuousWithinAt + unfold slope decay + fun_prop (disch := simp [hst0]) + +theorem integral_kernel_le {c a b : ℝ} (hc : 0 ≤ c) (ha : 1 < a) + (hl : 4 ≤ Real.log a) (hc2 : 4*c^2 ≤ Real.log a) (hab : a ≤ b) : + (∫ t in a..b, kernel c t) ≤ scale c b := by + have hi : IntervalIntegrable (kernel c) volume a b := (continuousOn_kernel (c:=c) (b:=b) ha).intervalIntegrable_of_Icc hab + have hj : IntervalIntegrable (slope c) volume a b := (continuousOn_slope (c:=c) (b:=b) ha).intervalIntegrable_of_Icc hab + have hle : (∫ t in a..b, kernel c t) ≤ ∫ t in a..b, slope c t := by + apply intervalIntegral.integral_mono_on hab hi hj + intro t ht + have hlog := Real.log_le_log (show 0 < a by linarith) ht.1 + exact kernel_le_slope hc (lt_of_lt_of_le ha ht.1) (hl.trans hlog) (hc2.trans hlog) + have hfund : (∫ t in a..b, slope c t) = scale c b - scale c a := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + · intro t ht + rw [uIcc_of_le hab] at ht + exact hasDerivAt_scale (lt_of_lt_of_le ha ht.1) + · exact hj + exact hle.trans (hfund.trans_le (sub_le_self _ (scale_nonneg ha.le))) + +theorem eventually_one_le_scale {c : ℝ} (hc : 0 < c) : + ∀ᶠ x : ℝ in atTop, 1 ≤ scale c x := by + have hlog := (isLittleO_log_rpow_atTop (show (0:ℝ)<1/2 by norm_num)).bound (show (0:ℝ)<1 by norm_num) + filter_upwards [sqrt_le_errorScale hc, hlog, eventually_gt_atTop (1:ℝ)] with x hs hl hx + have hl0 := Real.log_pos hx + have hx0 : 0 < x := by linarith + have hslog : Real.log x ≤ Real.sqrt x := by + simpa only [Real.norm_eq_abs, one_mul, Real.sqrt_eq_rpow, abs_of_pos hl0, + abs_of_nonneg (Real.rpow_nonneg hx0.le _)] using hl + change 1 ≤ x * decay c x / Real.log x + apply (le_div_iff₀ hl0).mpr + simp only [one_mul] + exact hslog.trans hs + +end ErdosPrimeInputs.PrimeCountingPrimitive + +end + +section + +namespace ErdosPrimeInputs.PrimeCountAbel + +open _root_.Set _root_.Filter _root_.MeasureTheory +open _root_.Erdos970.Set _root_.Erdos970.Filter _root_.Erdos970.MeasureTheory +open scoped Topology + +noncomputable def logarithmicIntegral (x : ℝ) : ℝ := ∫ t in 2..x, 1 / Real.log t +noncomputable def primeError (x : ℝ) : ℝ := (Nat.primeCounting ⌊x⌋₊ : ℝ) - logarithmicIntegral x +noncomputable def endpoint (x : ℝ) : ℝ := (Chebyshev.theta x - x) / Real.log x +noncomputable def thetaKernel (t : ℝ) : ℝ := Chebyshev.theta t / (t * Real.log t ^ 2) +noncomputable def mainKernel (t : ℝ) : ℝ := 1 / Real.log t ^ 2 +noncomputable def errorKernel (t : ℝ) : ℝ := thetaKernel t - mainKernel t + +lemma mainKernel_continuous {a b : ℝ} (ha : 2 ≤ a) : ContinuousOn mainKernel (Icc a b) := by + intro t ht + have ht1 : 1 < t := by linarith [ht.1] + have ht0 : t ≠ 0 := ne_of_gt (by linarith) + have hlt0 : Real.log t ≠ 0 := ne_of_gt (Real.log_pos ht1) + apply ContinuousAt.continuousWithinAt + unfold mainKernel + fun_prop (disch := simp [hlt0]) + +lemma mainKernel_integrable {a b : ℝ} (ha : 2 ≤ a) (hab : a ≤ b) : + IntervalIntegrable mainKernel volume a b := + (mainKernel_continuous ha).intervalIntegrable_of_Icc hab + +lemma thetaKernel_integrable {a b : ℝ} (ha : 2 ≤ a) (hab : a ≤ b) : + IntervalIntegrable thetaKernel volume a b := by + apply (intervalIntegrable_iff_integrableOn_Icc_of_le hab).mpr + exact (Chebyshev.integrableOn_theta_div_id_mul_log_sq b).mono_set (fun t ht => ⟨ha.trans ht.1,ht.2⟩) + +lemma errorKernel_integrable {a b : ℝ} (ha : 2 ≤ a) (hab : a ≤ b) : + IntervalIntegrable errorKernel volume a b := + (thetaKernel_integrable ha hab).sub (mainKernel_integrable ha hab) + +lemma errorKernel_eq {t : ℝ} (ht : 0 < t) : + errorKernel t = (Chebyshev.theta t - t) / (t * Real.log t ^ 2) := by + unfold errorKernel thetaKernel mainKernel + field_simp + +theorem primeError_eq {x : ℝ} (hx : 2 ≤ x) : + primeError x = 2 / Real.log 2 + endpoint x + ∫ t in 2..x, errorKernel t := by + have hli := _root_.Erdos970.integral_log_inv 2 x (by norm_num) hx + have herr : (∫ t in 2..x, errorKernel t) = + (∫ t in 2..x, thetaKernel t) - (∫ t in 2..x, mainKernel t) := + intervalIntegral.integral_sub (thetaKernel_integrable (by norm_num) hx) + (mainKernel_integrable (by norm_num) hx) + unfold primeError logarithmicIntegral endpoint + rw [Chebyshev.primeCounting_eq_theta_div_log_add_integral hx, herr] + simp only [one_div] + rw [hli] + unfold thetaKernel mainKernel + simp only [one_div] + ring + +theorem primeError_increment {a x : ℝ} (ha : 2 ≤ a) (hax : a ≤ x) : + primeError x = primeError a - endpoint a + endpoint x + ∫ t in a..x, errorKernel t := by + have hs := intervalIntegral.integral_add_adjacent_intervals + (errorKernel_integrable (by norm_num) ha) (errorKernel_integrable ha hax) + rw [primeError_eq (ha.trans hax), primeError_eq ha] + linarith + +end ErdosPrimeInputs.PrimeCountAbel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeDensityBlocks.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeDensityBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c494d694ed2f013432d764a0caabdc2075d2591 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeDensityBlocks.lean @@ -0,0 +1,317 @@ +import Mathlib.Data.Nat.Log +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.DisjointBlockExpansion +import OAI.NumberTheory.Jacobsthal.Estimates.SquarefreeHarmonic + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.PrimeDensityBlocks + +open scoped BigOperators + +def dyadicPrimes (n : ℕ) : Finset ℕ := (Finset.Ico n (2 * n)).filter Nat.Prime + +@[simp] theorem mem_dyadicPrimes {n p : ℕ} : + p ∈ dyadicPrimes n ↔ n ≤ p ∧ p < 2 * n ∧ p.Prime := by + simp only [dyadicPrimes, Finset.mem_filter, Finset.mem_Ico] + tauto + +theorem dyadicPrimes_subset_survivors (n : ℕ) : + dyadicPrimes n ⊆ {n} ∪ + (LargePrimeDeletion.cutoffSurvivors n n (LargePrimeDeletion.divisibilityResidue (n : ℤ))).image + (fun i => n + i) := by + intro p hp + obtain ⟨hnp, hp2n, hprime⟩ := mem_dyadicPrimes.mp hp + by_cases heq : p = n + · exact Finset.mem_union_left _ (by simp [heq]) + · have hnp' : n < p := lt_of_le_of_ne hnp (Ne.symm heq) + apply Finset.mem_union_right + apply Finset.mem_image.mpr + refine ⟨p - n, ?_, Nat.add_sub_of_le hnp⟩ + apply LargePrimeDeletion.mem_cutoffSurvivors.mpr + refine ⟨by omega, ?_⟩ + intro q hq hqn hbad + have hdiv := (LargePrimeDeletion.divisibility_iff_modEq (n : ℤ) hq.pos (p - n)).mpr hbad + have hdivN : q ∣ p := by + have hnEq : (n : ℤ) + (p - n : ℕ) = p := by exact_mod_cast Nat.add_sub_of_le hnp + rw [hnEq] at hdiv + exact Int.natCast_dvd_natCast.mp hdiv + have hqp : q = p := (Nat.prime_dvd_prime_iff_eq hq hprime).mp hdivN + omega + +theorem dyadicPrimes_card_le (n : ℕ) : + ((dyadicPrimes n).card : ℝ) ≤ 1 + 255 * (1 + (n : ℝ) / Real.log n) := by + let C := LargePrimeDeletion.cutoffSurvivors n n (LargePrimeDeletion.divisibilityResidue (n : ℤ)) + have hcard : (dyadicPrimes n).card ≤ 1 + C.card := by + calc + _ ≤ ({n} ∪ C.image (fun i => n + i)).card := Finset.card_le_card (dyadicPrimes_subset_survivors n) + _ ≤ ({n} : Finset ℕ).card + (C.image (fun i => n + i)).card := Finset.card_union_le _ _ + _ ≤ 1 + C.card := by simpa using Nat.add_le_add_left (Finset.card_image_le) 1 + have hcardR : ((dyadicPrimes n).card : ℝ) ≤ 1 + (C.card : ℝ) := by exact_mod_cast hcard + exact hcardR.trans (add_le_add le_rfl + (SquarefreeHarmonic.cutoffSurvivors_le_uniform_log n n _ le_rfl)) + +theorem self_le_two_pow (k : ℕ) : k ≤ 2 ^ k := by + induction k with + | zero => simp + | succ k ih => + have hpos : 1 ≤ 2 ^ k := Nat.one_le_pow _ _ (by norm_num) + rw [pow_succ] + omega + +theorem dyadic_density_sum_le (k : ℕ) (hk : 1 ≤ k) (g : ℕ → ℝ) + (hg : ∀ p ∈ dyadicPrimes (2 ^ k), g p ≤ 2 / p) : + (∑ p ∈ dyadicPrimes (2 ^ k), g p) ≤ 1532 / (k : ℝ) := by + let n : ℕ := 2 ^ k + have hnpos : (0 : ℝ) < n := by dsimp [n]; positivity + have hkpos : (0 : ℝ) < k := by exact_mod_cast hk + have hkn : (k : ℝ) ≤ n := by exact_mod_cast self_le_two_pow k + have hlog2 : (1 / 2 : ℝ) ≤ Real.log 2 := by + have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 2) + norm_num at h + exact h + have hlogeq : Real.log (n : ℝ) = (k : ℝ) * Real.log 2 := by + simp only [n, Nat.cast_pow, Nat.cast_ofNat, Real.log_pow] + have hloglower : (k : ℝ) / 2 ≤ Real.log (n : ℝ) := by + rw [hlogeq] + nlinarith [mul_nonneg hkpos.le (sub_nonneg.mpr hlog2)] + have hlogpos : 0 < Real.log (n : ℝ) := by linarith + have hsum : (∑ p ∈ dyadicPrimes n, g p) ≤ ((dyadicPrimes n).card : ℝ) * (2 / n) := by + calc + _ ≤ ∑ _p ∈ dyadicPrimes n, (2 / n : ℝ) := by + apply Finset.sum_le_sum + intro p hp + apply (hg p hp).trans + exact div_le_div_of_nonneg_left (by norm_num) hnpos + (by exact_mod_cast (mem_dyadicPrimes.mp hp).1) + _ = _ := by simp + have hcount := dyadicPrimes_card_le n + have hfirst : (512 : ℝ) / n ≤ 512 / (k : ℝ) := + div_le_div_of_nonneg_left (by norm_num) hkpos hkn + have hsecond : (510 : ℝ) / Real.log (n : ℝ) ≤ 1020 / (k : ℝ) := by + apply (div_le_div_iff₀ hlogpos hkpos).mpr + nlinarith + calc + (∑ p ∈ dyadicPrimes (2 ^ k), g p) ≤ ((dyadicPrimes n).card : ℝ) * (2 / n) := hsum + _ ≤ (1 + 255 * (1 + (n : ℝ) / Real.log n)) * (2 / n) := + mul_le_mul_of_nonneg_right hcount (by positivity) + _ = (512 : ℝ) / n + 510 / Real.log (n : ℝ) := by field_simp; ring + _ ≤ 512 / (k : ℝ) + 1020 / (k : ℝ) := add_le_add hfirst hsecond + _ = _ := by ring + +def geometricPrimes (j : ℕ) : Finset ℕ := + (Finset.Ico (2 ^ (2 ^ j)) (2 ^ (2 ^ (j + 1)))).filter Nat.Prime + +@[simp] theorem mem_geometricPrimes {j p : ℕ} : + p ∈ geometricPrimes j ↔ 2 ^ (2 ^ j) ≤ p ∧ p < 2 ^ (2 ^ (j + 1)) ∧ p.Prime := by + simp only [geometricPrimes, Finset.mem_filter, Finset.mem_Ico] + tauto + +theorem dyadicPrimes_disjoint {k l : ℕ} (hkl : k ≠ l) : + Disjoint (dyadicPrimes (2 ^ k)) (dyadicPrimes (2 ^ l)) := by + apply Finset.disjoint_left.mpr + intro p hp hk + obtain ⟨hkp, hpk, _⟩ := mem_dyadicPrimes.mp hp + obtain ⟨hlp, hpl, _⟩ := mem_dyadicPrimes.mp hk + rcases lt_or_gt_of_ne hkl with hlt | hlt + · have hpow : 2 ^ (k + 1) ≤ 2 ^ l := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt) + rw [pow_succ, Nat.mul_comm] at hpow + omega + · have hpow : 2 ^ (l + 1) ≤ 2 ^ k := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt) + rw [pow_succ, Nat.mul_comm] at hpow + omega + +theorem geometricPrimes_eq_dyadic_union (j : ℕ) : + geometricPrimes j = (Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1))).biUnion + (fun k => dyadicPrimes (2 ^ k)) := by + ext p + constructor + · intro hp + obtain ⟨hlo, hhi, hprime⟩ := mem_geometricPrimes.mp hp + let k := Nat.log 2 p + have hklo : 2 ^ j ≤ k := Nat.le_log_of_pow_le (by norm_num) hlo + have hkhi : k < 2 ^ (j + 1) := Nat.log_lt_of_lt_pow hprime.ne_zero hhi + apply Finset.mem_biUnion.mpr + refine ⟨k, Finset.mem_Ico.mpr ⟨hklo, hkhi⟩, ?_⟩ + apply mem_dyadicPrimes.mpr + refine ⟨Nat.pow_log_le_self 2 hprime.ne_zero, ?_, hprime⟩ + have h := Nat.lt_pow_succ_log_self (by norm_num : 1 < 2) p + simpa only [pow_succ, Nat.mul_comm] using h + · intro hp + obtain ⟨k, hk, hpk⟩ := Finset.mem_biUnion.mp hp + obtain ⟨hklo, hkhi⟩ := Finset.mem_Ico.mp hk + obtain ⟨hkp, hpk, hprime⟩ := mem_dyadicPrimes.mp hpk + apply mem_geometricPrimes.mpr + refine ⟨(Nat.pow_le_pow_right (by norm_num) hklo).trans hkp, ?_, hprime⟩ + have hpow : 2 ^ (k + 1) ≤ 2 ^ (2 ^ (j + 1)) := + Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hkhi) + rw [pow_succ, Nat.mul_comm] at hpow + exact hpk.trans_le hpow + +theorem geometric_reciprocal_sum_le (j : ℕ) : + (∑ p ∈ geometricPrimes j, (2 : ℝ) / p) ≤ 1532 := by + rw [geometricPrimes_eq_dyadic_union] + rw [Finset.sum_biUnion (fun k _ l _ hkl => dyadicPrimes_disjoint hkl)] + have hKpos : (0 : ℝ) < (2 ^ j : ℕ) := by positivity + calc + _ ≤ ∑ k ∈ Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1)), (1532 : ℝ) / (k : ℝ) := by + apply Finset.sum_le_sum + intro k hk + have hk1 : 1 ≤ k := (Nat.one_le_pow _ _ (by norm_num)).trans (Finset.mem_Ico.mp hk).1 + exact dyadic_density_sum_le k hk1 (fun p => (2 : ℝ) / p) (fun _ _ => le_rfl) + _ ≤ ∑ _k ∈ Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1)), (1532 : ℝ) / (2 ^ j : ℕ) := by + apply Finset.sum_le_sum + intro k hk + exact div_le_div_of_nonneg_left (by norm_num) hKpos + (by exact_mod_cast (Finset.mem_Ico.mp hk).1) + _ = 1532 := by + have hcard : (Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1))).card = 2 ^ j := by + rw [Nat.card_Ico, pow_succ] + omega + simp only [Finset.sum_const, hcard, nsmul_eq_mul] + field_simp + +theorem subset_geometric_density_sum_le (j : ℕ) (Q : Finset ℕ) (hQ : Q ⊆ geometricPrimes j) + (g : ℕ → ℝ) (hg : ∀ p ∈ Q, g p ≤ 2 / p) : (∑ p ∈ Q, g p) ≤ 1532 := by + calc + _ ≤ ∑ p ∈ Q, (2 : ℝ) / p := Finset.sum_le_sum hg + _ ≤ ∑ p ∈ geometricPrimes j, (2 : ℝ) / p := + Finset.sum_le_sum_of_subset_of_nonneg hQ (fun _ _ _ => by positivity) + _ ≤ _ := geometric_reciprocal_sum_le j + +def lastBlock (V : ℕ) : ℕ := Nat.log 2 (Nat.log 2 V) + +def blockIndices (V : ℕ) : Finset ℕ := Finset.range (lastBlock V + 1) + +def primeBlock (P : Finset ℕ) (j : ℕ) : Finset ℕ := P ∩ geometricPrimes j + +theorem geometricPrimes_disjoint {i j : ℕ} (hij : i ≠ j) : + Disjoint (geometricPrimes i) (geometricPrimes j) := by + apply Finset.disjoint_left.mpr + intro p hp hq + obtain ⟨hil, hiu, _⟩ := mem_geometricPrimes.mp hp + obtain ⟨hjl, hju, _⟩ := mem_geometricPrimes.mp hq + rcases lt_or_gt_of_ne hij with hlt | hlt + · have hexp : 2 ^ (i + 1) ≤ 2 ^ j := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt) + have hpowers := Nat.pow_le_pow_right (by norm_num : 1 ≤ 2) hexp + omega + · have hexp : 2 ^ (j + 1) ≤ 2 ^ i := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt) + have hpowers := Nat.pow_le_pow_right (by norm_num : 1 ≤ 2) hexp + omega + +theorem primeBlock_pairwise (V : ℕ) (P : Finset ℕ) : + (blockIndices V : Set ℕ).Pairwise fun i j => Disjoint (primeBlock P i) (primeBlock P j) := by + intro i _ j _ hij + exact (geometricPrimes_disjoint hij).mono Finset.inter_subset_right Finset.inter_subset_right + +theorem primeBlock_union (V : ℕ) (P : Finset ℕ) + (hprime : ∀ p ∈ P, p.Prime) (hV : ∀ p ∈ P, p ≤ V) : + (blockIndices V).biUnion (primeBlock P) = P := by + ext p + constructor + · intro hp + obtain ⟨j, _, hpj⟩ := Finset.mem_biUnion.mp hp + exact (Finset.mem_inter.mp hpj).1 + · intro hp + have hpp := hprime p hp + let k := Nat.log 2 p + let j := Nat.log 2 k + have hk1 : 1 ≤ k := Nat.le_log_of_pow_le (by norm_num) (by simpa using hpp.two_le) + have hk0 : k ≠ 0 := by omega + have hjlast : j ≤ lastBlock V := Nat.log_mono_right (Nat.log_mono_right (hV p hp)) + have hlo : 2 ^ (2 ^ j) ≤ p := + (Nat.pow_le_pow_right (by norm_num) (Nat.pow_log_le_self 2 hk0)).trans + (Nat.pow_log_le_self 2 hpp.ne_zero) + have hhi : p < 2 ^ (2 ^ (j + 1)) := by + have hkj : k < 2 ^ (j + 1) := Nat.lt_pow_succ_log_self (by norm_num) k + have hpk : p < 2 ^ (k + 1) := Nat.lt_pow_succ_log_self (by norm_num) p + exact hpk.trans_le (Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hkj)) + exact Finset.mem_biUnion.mpr ⟨j, Finset.mem_range.mpr (Nat.lt_succ_of_le hjlast), + Finset.mem_inter.mpr ⟨hp, mem_geometricPrimes.mpr ⟨hlo, hhi, hpp⟩⟩⟩ + +theorem primeBlock_density_sum_le (P : Finset ℕ) (j : ℕ) (g : ℕ → ℝ) + (hdim : ∀ p ∈ P, g p ≤ 2 / p) : (∑ p ∈ primeBlock P j, g p) ≤ 1532 := + subset_geometric_density_sum_le j _ Finset.inter_subset_right g + (fun p hp => hdim p (Finset.mem_inter.mp hp).1) + +def reverseOrder (m J j : ℕ) : ℕ := m + (J - j) + +def supportCost (m J : ℕ) : ℕ := + ∑ j ∈ Finset.range (J + 1), 2 ^ (j + 1) * (2 * reverseOrder m J j + 1) + +theorem supportCost_succ (m J : ℕ) : + supportCost m (J + 1) = supportCost (m + 1) J + 2 ^ (J + 2) * (2 * m + 1) := by + unfold supportCost + rw [Finset.sum_range_succ] + have hsum : (∑ j ∈ Finset.range (J + 1), 2 ^ (j + 1) * (2 * reverseOrder m (J + 1) j + 1)) = + ∑ j ∈ Finset.range (J + 1), 2 ^ (j + 1) * (2 * reverseOrder (m + 1) J j + 1) := by + apply Finset.sum_congr rfl + intro j hj + have hjJ : j ≤ J := Nat.le_of_lt_succ (Finset.mem_range.mp hj) + have horder : reverseOrder m (J + 1) j = reverseOrder (m + 1) J j := by + unfold reverseOrder + omega + rw [horder] + rw [hsum] + simp only [reverseOrder, Nat.sub_self, Nat.add_zero] + +theorem supportCost_le (m J : ℕ) : supportCost m J ≤ (8 * m + 12) * 2 ^ J := by + induction J generalizing m with + | zero => simp [supportCost, reverseOrder]; omega + | succ J ih => + rw [supportCost_succ] + calc + _ ≤ (8 * (m + 1) + 12) * 2 ^ J + 2 ^ (J + 2) * (2 * m + 1) := + Nat.add_le_add_right (ih (m + 1)) _ + _ = (8 * m + 12) * 2 ^ (J + 1) := by simp only [pow_add]; norm_num; ring + +theorem supportCost_le_twelve (m J : ℕ) : supportCost m J ≤ 12 * (m + 1) * 2 ^ J := by + apply (supportCost_le m J).trans + exact Nat.mul_le_mul_right (2 ^ J) (by omega) + +theorem lastBlock_lower_le (V : ℕ) (hV : 2 ≤ V) : 2 ^ (2 ^ lastBlock V) ≤ V := by + have hlog1 : 1 ≤ Nat.log 2 V := Nat.le_log_of_pow_le (by norm_num) (by simpa using hV) + have hlog0 : Nat.log 2 V ≠ 0 := by omega + have hinner : 2 ^ lastBlock V ≤ Nat.log 2 V := Nat.pow_log_le_self 2 hlog0 + exact (Nat.pow_le_pow_right (by norm_num) hinner).trans (Nat.pow_log_le_self 2 (by omega)) + +theorem supportHeight_product_le (V m : ℕ) (hV : 2 ≤ V) : + (∏ j ∈ blockIndices V, (2 ^ (2 ^ (j + 1))) ^ (2 * reverseOrder m (lastBlock V) j + 1)) ≤ + V ^ (12 * (m + 1)) := by + simp only [← pow_mul] + rw [Finset.prod_pow_eq_pow_sum] + change 2 ^ supportCost m (lastBlock V) ≤ _ + calc + _ ≤ 2 ^ (12 * (m + 1) * 2 ^ lastBlock V) := + Nat.pow_le_pow_right (by norm_num) (supportCost_le_twelve m (lastBlock V)) + _ = (2 ^ (2 ^ lastBlock V)) ^ (12 * (m + 1)) := by rw [← pow_mul, Nat.mul_comm] + _ ≤ _ := Nat.pow_le_pow_left (lastBlock_lower_le V hV) _ + +noncomputable def actualLowerCoefficient (V m : ℕ) (P : Finset ℕ) (T : Finset ℕ) : ℝ := + DisjointBlockExpansion.lowerCoefficient (blockIndices V) (primeBlock P) + (reverseOrder m (lastBlock V)) T + +theorem actualLowerCoefficient_support (V m : ℕ) (P : Finset ℕ) (hV : 2 ≤ V) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ V) + {T : Finset ℕ} (hT : T ⊆ P) (hc : actualLowerCoefficient V m P T ≠ 0) : + Squarefree (∏ p ∈ T, p) ∧ (∏ p ∈ T, p) ≤ V ^ (12 * (m + 1)) := by + have hTu : T ⊆ (blockIndices V).biUnion (primeBlock P) := by + simpa only [primeBlock_union V P hprime hsize] using hT + have hbound := DisjointBlockExpansion.lowerCoefficient_prime_support (blockIndices V) (primeBlock P) + (primeBlock_pairwise V P) (reverseOrder m (lastBlock V)) (fun j => 2 ^ (2 ^ (j + 1))) + (fun j _ => Nat.one_le_pow _ _ (by norm_num)) + (fun j _ p hp => hprime p (Finset.mem_inter.mp hp).1) + (fun j _ p hp => (mem_geometricPrimes.mp (Finset.mem_inter.mp hp).2).2.1.le) hTu hc + exact ⟨hbound.1, hbound.2.trans (supportHeight_product_le V m hV)⟩ + +end NumberTheoryLean.PrimeDensityBlocks + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeEventCounting.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeEventCounting.lean new file mode 100644 index 0000000000000000000000000000000000000000..36fe4a3df581ec058d02327ac3dac8e709247a38 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeEventCounting.lean @@ -0,0 +1,249 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.SmallModelMeasure +import OAI.NumberTheory.Jacobsthal.Estimates.ActualPatternClass +import OAI.NumberTheory.Jacobsthal.Partitions.ActualCoordinateBlocks +import OAI.NumberTheory.Jacobsthal.Sieve.PrimeFibreBrunBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceSmallModel +open ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_residue_fibre_bound (alpha : ℝ) (ha : 0 < alpha) : + ∃ C : ℝ,0 < C ∧ ∀ xi : ℝ,0 < xi → xi ≤ 1 → + ∀ᶠ z : ℝ in atTop,1 < z ∧ + ∀ (P : Finset ℕ) (R H C0 : ℝ) (m : ℤ) (M : ℕ) (b : ℤ), + z^alpha ≤ R → 0 < H → 0 < M → H ≤ R^((4 : ℝ)/5) → + (M : ℝ) ≤ H*(smallModulus (sourceW z) : ℝ) → + totalScale R H C0/H ≤ (sourceZ z)^12 → + (∀ p ∈ P,p.Prime ∧ R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) → + ((residueFibre P H C0 m M b).card : ℝ) ≤ + C*primeWidth R xi H C0/((M.totient : ℝ)*Real.log R) := by + obtain ⟨C,B,hC,hB,hBrun⟩ := residue_fibre_prime_bound + refine ⟨50*C,by positivity,?_⟩ + intro xi hxi hxi1 + have hgrowth := tendsto_rpow_atTop (by positivity : 0 < alpha/10) + filter_upwards [source_prime_width_lower alpha xi ha hxi hxi1,source_small_modulus_R alpha ha, + hgrowth.eventually_ge_atTop B] with z hWidth hMod hzB + refine ⟨hWidth.1,?_⟩ + intro P R H C0 m M b hRlo hH hM hHsmall hMbound hRatio hP + have hz0 : 0 < z := by linarith [hWidth.1] + have hR1 : 1 < R := (Real.one_lt_rpow hWidth.1 ha).trans_le hRlo + have hR : 0 < R := by linarith + have hlogR : 0 < Real.log R := Real.log_pos hR1 + have hMp : (0 : ℝ) < M := by exact_mod_cast hM + have hphi : (0 : ℝ) < M.totient := by exact_mod_cast Nat.totient_pos.mpr hM + have hX := primeWidth_pos R xi H C0 hR hxi hH + have hX19 := hWidth.2 R H C0 hRlo hH hRatio + have hM17 : (M : ℝ) ≤ R^((17 : ℝ)/20) := by + calc + _ ≤ H*(smallModulus (sourceW z) : ℝ) := hMbound + _ ≤ R^((4 : ℝ)/5)*R^((1 : ℝ)/20) := + mul_le_mul hHsmall (hMod.2 R hRlo) (Nat.cast_nonneg _) (Real.rpow_nonneg hR.le _) + _ = _ := by rw [← Real.rpow_add hR];norm_num + have hLength : R^((1 : ℝ)/10) ≤ 5*primeWidth R xi H C0/(M : ℝ) := by + apply (le_div_iff₀ hMp).mpr + calc + _ ≤ R^((1 : ℝ)/10)*R^((17 : ℝ)/20) := + mul_le_mul_of_nonneg_left hM17 (Real.rpow_nonneg hR.le _) + _ = R^((19 : ℝ)/20) := by rw [← Real.rpow_add hR];norm_num + _ ≤ primeWidth R xi H C0 := hX19 + _ ≤ _ := by linarith + have hB_R : B ≤ R^((1 : ℝ)/10) := by + apply le_trans hzB + have hh := Real.rpow_le_rpow (Real.rpow_nonneg hz0.le alpha) hRlo (by norm_num : (0 : ℝ) ≤ 1/10) + simpa only [← Real.rpow_mul hz0.le,show alpha*((1 : ℝ)/10) = alpha/10 by ring] using hh + have hLog : (1/10 : ℝ)*Real.log R ≤ Real.log (5*primeWidth R xi H C0/(M : ℝ)) := by + have hh := Real.log_le_log (Real.rpow_pos_of_pos hR (1/10)) hLength + simpa only [Real.log_rpow hR] using hh + calc + _ ≤ C*(5*primeWidth R xi H C0)/ + ((M.totient : ℝ)*Real.log (5*primeWidth R xi H C0/(M : ℝ))) := + hBrun P R xi H C0 m M b hR hxi hxi1 hH hM (hB_R.trans hLength) hP + _ ≤ C*(5*primeWidth R xi H C0)/((M.totient : ℝ)*((1/10 : ℝ)*Real.log R)) := + div_le_div_of_nonneg_left (by positivity) (by positivity) + (mul_le_mul_of_nonneg_left hLog hphi.le) + _ = _ := by field_simp;norm_num + +end ErdosVarianceSmallModel + +end + +section + +namespace ErdosVarianceSmallModel +open ErdosVarianceEffective +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def goodPrimes (P : Finset ℕ) (H : ℕ) : Finset ℕ := P.filter (fun p => H.Coprime p) + +noncomputable def primeM (P : Finset ℕ) (H : ℕ) (C0 : ℤ) (hP : ∀ p ∈ P,p.Prime) + (p : goodPrimes P H) : ℤ := by + letI : NeZero p.val := ⟨(hP _ (Finset.mem_filter.mp p.property).1).ne_zero⟩ + exact intervalM0 p.val H (Finset.mem_filter.mp p.property).2 C0 + +noncomputable def primeK (P : Finset ℕ) (H : ℕ) (C0 : ℤ) (hP : ∀ p ∈ P,p.Prime) + (p : goodPrimes P H) : ℕ := by + letI : NeZero p.val := ⟨(hP _ (Finset.mem_filter.mp p.property).1).ne_zero⟩ + exact intervalK p.val H (Finset.mem_filter.mp p.property).2 C0 + +noncomputable def primePoint (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) : ModelPoint w H := + ⟨primeM P H C0 hP p, + ZMod.unitOfCoprime p.val (prime_coprime_small_pattern w hw H p.val + (hP _ (Finset.mem_filter.mp p.property).1) (hlarge _ (Finset.mem_filter.mp p.property).1)), + (primeK P H C0 hP p : ZMod (divisorModulus w H))⟩ + +theorem primeMK_identity (P : Finset ℕ) (H : ℕ) (C0 : ℤ) (hP : ∀ p ∈ P,p.Prime) + (p : goodPrimes P H) : + (p.val : ℤ)*primeM P H C0 hP p = C0+(H : ℤ)*(primeK P H C0 hP p : ℤ) := by + let : NeZero p.val := ⟨(hP _ (Finset.mem_filter.mp p.property).1).ne_zero⟩ + exact intervalM0_identity p.val H (Finset.mem_filter.mp p.property).2 C0 + +theorem primeM_bounds (P : Finset ℕ) (H : ℕ) (C0 : ℤ) (hP : ∀ p ∈ P,p.Prime) (hH : 0 < H) + (p : goodPrimes P H) : + (C0 : ℝ)/(p.val : ℝ) ≤ (primeM P H C0 hP p : ℝ) ∧ + (primeM P H C0 hP p : ℝ) < (C0 : ℝ)/(p.val : ℝ)+(H : ℝ) := by + let : NeZero p.val := ⟨(hP _ (Finset.mem_filter.mp p.property).1).ne_zero⟩ + exact intervalM0_bounds p.val H (Finset.mem_filter.mp p.property).2 C0 hH + +theorem primeM_coprime (P : Finset ℕ) (H : ℕ) (C0 : ℤ) (hP : ∀ p ∈ P,p.Prime) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (p : goodPrimes P H) : + (primeM P H C0 hP p).natAbs.Coprime H := by + apply Nat.coprime_of_dvd + intro t ht htm htH + have htm' : (t : ℤ) ∣ primeM P H C0 hP p := Int.natCast_dvd.mpr htm + have htH' : (t : ℤ) ∣ (H : ℤ) := by exact_mod_cast htH + have hsub := dvd_sub (dvd_mul_of_dvd_right htm' (p.val : ℤ)) + (dvd_mul_of_dvd_left htH' (primeK P H C0 hP p : ℤ)) + rw [primeMK_identity,add_sub_cancel_right] at hsub + have hdiv := Nat.dvd_gcd (Int.natCast_dvd.mp hsub) htH + have hg : Nat.gcd C0.natAbs H = 1 := by simpa only [Int.gcd_def,Int.natAbs_natCast] using hC0 + rw [hg] at hdiv + exact ht.not_dvd_one hdiv + +theorem primePoint_mem_model (P : Finset ℕ) (R xi w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (hR : 0 < R) (hxi : 0 ≤ xi) (hH : 0 < H) (hC0 : Int.gcd C0 (H : ℤ) = 1) + (hbin : ∀ p ∈ P,R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) (p : goodPrimes P H) : + primePoint P w H C0 hw hP hlarge p ∈ modelUniverse R xi w H C0 := by + have hpP := (Finset.mem_filter.mp p.property).1 + have hm := moving_interval_enclosure R xi (H : ℝ) (C0 : ℝ) (p.val : ℝ) + (primeM P H C0 hP p) hR hxi (hbin _ hpP).1 (hbin _ hpP).2 (primeM_bounds P H C0 hP hH p) + apply (mem_modelUniverse R xi w H C0 _).mpr + exact ⟨hm.1,hm.2,primeM_coprime P H C0 hP hC0 p⟩ + +end ErdosVarianceSmallModel + +end + +section + +namespace ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def primeFibre (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (v : ModelPoint w H) : Finset (goodPrimes P H) := + Finset.univ.filter (fun p => primePoint P w H C0 hw hP hlarge p = v) + +theorem primeFibre_image_subset (P : Finset ℕ) (w : ℝ) (H : ℕ) [NeZero H] (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (v : ModelPoint w H) (hm : v.1.natAbs.Coprime H) : + (primeFibre P w H C0 hw hP hlarge v).image Subtype.val ⊆ + residueFibre P (H : ℝ) (C0 : ℝ) v.1 (H*divisorModulus w H*coprimeModulus w H) + (patternClass w H C0 hC0 v.1 hm v.2 : ℤ) := by + intro q hq + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hq + have he := (Finset.mem_filter.mp hp).2 + have hpm : primeM P H C0 hP p = v.1 := congrArg Prod.fst he + have hp1 : (p.val : ZMod (coprimeModulus w H)) = (v.2.1 : ZMod (coprimeModulus w H)) := by + simpa only [primePoint,ZMod.coe_unitOfCoprime] using + congrArg (fun z : ModelPoint w H => (z.2.1 : ZMod (coprimeModulus w H))) he + have hk0 : (primeK P H C0 hP p : ZMod (divisorModulus w H)) = v.2.2 := + congrArg (fun z : ModelPoint w H => z.2.2) he + have hEquation : (p.val : ℤ)*v.1 = C0+(H : ℤ)*(primeK P H C0 hP p : ℤ) := by + rw [← hpm] + exact primeMK_identity P H C0 hP p + have hbounds := primeM_bounds P H C0 hP (Nat.pos_of_ne_zero (NeZero.ne H)) p + rw [hpm] at hbounds + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp p.property).1,hbounds⟩,?_⟩ + exact actual_pattern_class w H C0 hC0 v.1 hm v.2 p.val (primeK P H C0 hP p) hEquation hp1 hk0 + +theorem primeFibre_card_le_residue (P : Finset ℕ) (w : ℝ) (H : ℕ) [NeZero H] (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (v : ModelPoint w H) (hm : v.1.natAbs.Coprime H) : + (primeFibre P w H C0 hw hP hlarge v).card ≤ + (residueFibre P (H : ℝ) (C0 : ℝ) v.1 (H*divisorModulus w H*coprimeModulus w H) + (patternClass w H C0 hC0 v.1 hm v.2 : ℤ)).card := by + calc + _ = ((primeFibre P w H C0 hw hP hlarge v).image Subtype.val).card := + (Finset.card_image_of_injective _ Subtype.val_injective).symm + _ ≤ _ := Finset.card_le_card (primeFibre_image_subset P w H C0 hw hP hlarge hC0 v hm) + +end ErdosVarianceSmallModel + +end + +section + +namespace ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def indexedPrimeEvent (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (E : ModelPoint w H → Prop) : Finset (goodPrimes P H) := + Finset.univ.filter (fun p => E (primePoint P w H C0 hw hP hlarge p)) + +noncomputable def actualPrimeEvent (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (E : ModelPoint w H → Prop) : Finset ℕ := + (indexedPrimeEvent P w H C0 hw hP hlarge E).image Subtype.val + +theorem actualPrimeEvent_card (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (E : ModelPoint w H → Prop) : + (actualPrimeEvent P w H C0 hw hP hlarge E).card = (indexedPrimeEvent P w H C0 hw hP hlarge E).card := + Finset.card_image_of_injective _ Subtype.val_injective + +theorem actualPrimeEvent_card_fibres (P : Finset ℕ) (R xi w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (hR : 0 < R) (hxi : 0 ≤ xi) (hH : 0 < H) (hC0 : Int.gcd C0 (H : ℤ) = 1) + (hbin : ∀ p ∈ P,R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) (E : ModelPoint w H → Prop) : + (actualPrimeEvent P w H C0 hw hP hlarge E).card = + ∑ v ∈ (modelUniverse R xi w H C0).filter E,(primeFibre P w H C0 hw hP hlarge v).card := by + rw [actualPrimeEvent_card] + have hmaps : (indexedPrimeEvent P w H C0 hw hP hlarge E : Set (goodPrimes P H)).MapsTo + (primePoint P w H C0 hw hP hlarge) ((modelUniverse R xi w H C0).filter E) := by + intro p hp + exact Finset.mem_filter.mpr ⟨primePoint_mem_model P R xi w H C0 hw hP hlarge hR hxi hH hC0 hbin p, + (Finset.mem_filter.mp hp).2⟩ + rw [Finset.card_eq_sum_card_fiberwise hmaps] + apply Finset.sum_congr rfl + intro v hv + congr 1 + ext p + simp only [indexedPrimeEvent,primeFibre,Finset.mem_filter,Finset.mem_univ,true_and] + constructor + · exact fun hh => hh.2 + · intro he + exact ⟨he.symm ▸ (Finset.mem_filter.mp hv).2,he⟩ + +end ErdosVarianceSmallModel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeExceptionalMean.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeExceptionalMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..970270dede67176fe40d7635a4389e16f0cb464e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeExceptionalMean.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ExceptionalResidues + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseSpectrum +attribute [local instance] Classical.decEq + +theorem exceptional_fraction_sum_bound (P : Finset ℕ) (hP : ∀ p ∈ P,Nat.Prime p) + (Q J : ℕ) (M : ℤ) (S : Finset ℤ) (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) + (hQ : ∀ p ∈ P,p ≤ Q) (T : ℝ) (hT : 0 < T) : + (∑ p ∈ P,((exceptionalResidues p S T).card : ℝ)/(p : ℝ)) ≤ + (4+8*Real.pi^2)*((J : ℝ)+(Q : ℝ)^2)*(S.card : ℝ)/T^2 := by + calc + _ ≤ ∑ p ∈ P,((p : ℝ)*integerResidueVariance p S)/T^2 := + Finset.sum_le_sum (fun p hp => exceptional_fraction_le_variance p (hP p hp).pos S T hT) + _ = (∑ p ∈ P,(p : ℝ)*integerResidueVariance p S)/T^2 := (Finset.sum_div _ _ _).symm + _ ≤ _ := div_le_div_of_nonneg_right (prime_variance_large_sieve P hP Q J M S hS hQ) (sq_nonneg _) + +theorem exceptional_fraction_average_bound (P : Finset ℕ) (hP : ∀ p ∈ P,Nat.Prime p) + (hn : 0 < P.card) (Q J : ℕ) (M : ℤ) (S : Finset ℤ) (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) + (hQ : ∀ p ∈ P,p ≤ Q) (T : ℝ) (hT : 0 < T) : + (∑ p ∈ P,((exceptionalResidues p S T).card : ℝ)/(p : ℝ))/(P.card : ℝ) ≤ + (4+8*Real.pi^2)*((J : ℝ)+(Q : ℝ)^2)*(S.card : ℝ)/((P.card : ℝ)*T^2) := by + have hnR : (0 : ℝ) < P.card := by exact_mod_cast hn + calc + _ ≤ ((4+8*Real.pi^2)*((J : ℝ)+(Q : ℝ)^2)*(S.card : ℝ)/T^2)/(P.card : ℝ) := + div_le_div_of_nonneg_right (exceptional_fraction_sum_bound P hP Q J M S hS hQ T hT) hnR.le + _ = _ := by ring + +theorem exceptional_average_of_survivor_upper (P : Finset ℕ) (hP : ∀ p ∈ P,Nat.Prime p) + (hn : 0 < P.card) (Q J : ℕ) (hJ : 0 < J) (M : ℤ) (S : Finset ℤ) + (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) (hQ : ∀ p ∈ P,p ≤ Q) + (delta V0 C : ℝ) (hd : 0 < delta) (hV : 0 < V0) + (hm : (S.card : ℝ) ≤ C*(J : ℝ)*V0) : + (∑ p ∈ P,((exceptionalResidues p S (delta*(J : ℝ)*V0)).card : ℝ)/(p : ℝ))/(P.card : ℝ) ≤ + (4+8*Real.pi^2)*C*((J : ℝ)+(Q : ℝ)^2)/((P.card : ℝ)*delta^2*(J : ℝ)*V0) := by + have hnR : (0 : ℝ) < P.card := by exact_mod_cast hn + have hJR : (0 : ℝ) < J := by exact_mod_cast hJ + have hT : 0 < delta*(J : ℝ)*V0 := mul_pos (mul_pos hd hJR) hV + calc + _ ≤ (4+8*Real.pi^2)*((J : ℝ)+(Q : ℝ)^2)*(S.card : ℝ)/ + ((P.card : ℝ)*(delta*(J : ℝ)*V0)^2) := exceptional_fraction_average_bound P hP hn Q J M S hS hQ _ hT + _ ≤ (4+8*Real.pi^2)*((J : ℝ)+(Q : ℝ)^2)*(C*(J : ℝ)*V0)/ + ((P.card : ℝ)*(delta*(J : ℝ)*V0)^2) := by + gcongr + _ = _ := by field_simp + +end ErdosInverseSpectrum + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeFibreInterval.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeFibreInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ffb83b11115183f33fb3a81733a1b63f9f81364 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeFibreInterval.lean @@ -0,0 +1,104 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReciprocalEnvelope + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosVarianceSmallModel + +theorem bin_diameter (R xi p q : ℝ) (hp : R < p ∧ p ≤ (1+xi)*R) + (hq : R < q ∧ q ≤ (1+xi)*R) : |p-q| ≤ xi*R := by + rw [abs_le] + constructor <;> nlinarith + +theorem reciprocal_difference_abs (C0 p q : ℝ) (hp : 0 < p) (hq : 0 < q) : + |C0/p-C0/q| = |C0| * |p-q| / (p*q) := by + have he : C0/p-C0/q = (-C0)*(p-q)/(p*q) := by field_simp;ring + rw [he,abs_div,abs_mul,abs_neg,abs_of_pos (mul_pos hp hq)] + +theorem fixed_m_reciprocal_diameter (R xi H C0 p q m : ℝ) + (hR : 0 < R) (hxi1 : xi ≤ 1) (hH : 0 < H) (hC : C0 ≠ 0) + (hp : R < p ∧ p ≤ (1+xi)*R) (hq : R < q ∧ q ≤ (1+xi)*R) + (hmp : C0/p ≤ m ∧ m < C0/p+H) (hmq : C0/q ≤ m ∧ m < C0/q+H) : + |p-q| ≤ 4*R^2*H/|C0| := by + have hpp : 0 < p := hR.trans hp.1 + have hqp : 0 < q := hR.trans hq.1 + have hdiff : |C0/p-C0/q| ≤ H := by rw [abs_le];constructor <;> linarith + rw [reciprocal_difference_abs C0 p q hpp hqp] at hdiff + have hh := (div_le_iff₀ (mul_pos hpp hqp)).mp hdiff + have hp2 : p ≤ 2*R := by nlinarith + have hq2 : q ≤ 2*R := by nlinarith + have hpq : p*q ≤ 4*R^2 := by nlinarith [mul_le_mul hp2 hq2 hqp.le (by positivity : 0 ≤ 2*R)] + have hm := mul_le_mul_of_nonneg_left hpq hH.le + apply (le_div_iff₀ (abs_pos.mpr hC)).mpr + nlinarith + +theorem fixed_m_prime_diameter (R xi H C0 p q m : ℝ) + (hR : 0 < R) (_hxi : 0 < xi) (hxi1 : xi ≤ 1) (hH : 0 < H) + (hp : R < p ∧ p ≤ (1+xi)*R) (hq : R < q ∧ q ≤ (1+xi)*R) + (hmp : C0/p ≤ m ∧ m < C0/p+H) (hmq : C0/q ≤ m ∧ m < C0/q+H) : + |p-q| ≤ 4*primeWidth R xi H C0 := by + have hbin := bin_diameter R xi p q hp hq + have hscale : |p-q| ≤ 4*R*H/totalScale R H C0 := by + rcases le_total H (interceptScale R C0) with h | h + · have hC : C0 ≠ 0 := by + intro he + rw [he,interceptScale,abs_zero,zero_div] at h + linarith + rw [totalScale,max_eq_right h] + calc + _ ≤ 4*R^2*H/|C0| := fixed_m_reciprocal_diameter R xi H C0 p q m hR hxi1 hH hC hp hq hmp hmq + _ = _ := by dsimp [interceptScale];field_simp + · rw [totalScale,max_eq_left h,mul_div_cancel_right₀ _ hH.ne'] + nlinarith + rcases le_total (xi*R) (R*H/totalScale R H C0) with h | h + · rw [primeWidth,min_eq_left h] + nlinarith + · rw [primeWidth,min_eq_right h] + simpa only [mul_div_assoc,mul_assoc] using hscale + +end ErdosVarianceSmallModel + +end + +section + +namespace ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable + +noncomputable def geometricFibre (P : Finset ℕ) (H C0 : ℝ) (m : ℤ) : Finset ℕ := + P.filter (fun p => C0/(p : ℝ) ≤ (m : ℝ) ∧ (m : ℝ) < C0/(p : ℝ)+H) + +theorem geometric_fibre_interval (P : Finset ℕ) (R xi H C0 : ℝ) (m : ℤ) + (hR : 0 < R) (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hH : 0 < H) + (hP : ∀ p ∈ P,R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) : + ∃ x : ℝ,∀ p ∈ geometricFibre P H C0 m, + x < (p : ℝ) ∧ (p : ℝ) ≤ x+5*primeWidth R xi H C0 := by + classical + by_cases hne : (geometricFibre P H C0 m).Nonempty + · let p0 := (geometricFibre P H C0 m).min' hne + have hp0 : p0 ∈ geometricFibre P H C0 m := Finset.min'_mem _ hne + have hp0P := (Finset.mem_filter.mp hp0).1 + have hX := primeWidth_pos R xi H C0 hR hxi hH + refine ⟨(p0 : ℝ)-primeWidth R xi H C0,?_⟩ + intro p hp + have hpP := (Finset.mem_filter.mp hp).1 + have hmin : p0 ≤ p := Finset.min'_le _ p hp + have hminR : (p0 : ℝ) ≤ p := by exact_mod_cast hmin + have hd := fixed_m_prime_diameter R xi H C0 p p0 m hR hxi hxi1 hH + (hP p hpP) (hP p0 hp0P) (Finset.mem_filter.mp hp).2 (Finset.mem_filter.mp hp0).2 + have hupper := (abs_le.mp hd).2 + constructor <;> linarith + · refine ⟨0,?_⟩ + intro p hp + exact False.elim (hne ⟨p,hp⟩) + +end ErdosVarianceSmallModel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeGridGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeGridGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..bb1866c5d4509dc028973f4db0007cff43836ee9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeGridGeometry.lean @@ -0,0 +1,1337 @@ +import Mathlib.Analysis.SpecialFunctions.Integrals.Basic +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import Mathlib.Probability.Kernel.Composition.Comp +import OAI.NumberTheory.Jacobsthal.Estimates.FiniteMonotoneComparison +import OAI.NumberTheory.Jacobsthal.Estimates.LowStateHorizon +import OAI.NumberTheory.Jacobsthal.Primes.PrimeRatioBins +import OAI.NumberTheory.Jacobsthal.Sieve.AdmittedExponentMarginal + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.PrimeTiltMonotone + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltBounds DerivativeWeights TransitionKernels +open HarmonicExponentMeasure + +theorem multiplier_measurable (i : Side) (s : ℝ) : Measurable (multiplier i s) := by + have hw : Measurable (weight i.flip) := by + cases i with + | even => exact phiOdd_continuous.measurable + | odd => exact phiEven_measurable + exact ((((measurable_id.add_const 1).div measurable_id).pow_const 2).mul hw).div_const (weight i s) + +theorem minRatio_pos {i : Side} {s : ℝ} (hs : Valid i s) : 0 < minRatio i s := + valid_pos (valid_next hs le_rfl) + +theorem multiplier_antitone {i : Side} {s : ℝ} (hs : Valid i s) : + AntitoneOn (multiplier i s) (Ici (minRatio i s)) := by + intro u hu v hv huv + have hu0 := valid_pos (valid_next hs hu) + have hv0 := valid_pos (valid_next hs hv) + have hphi : weight i.flip v ≤ weight i.flip u := by + cases i with + | even => exact phiOdd_antitone huv + | odd => + have h2 : 2 ≤ minRatio .odd s := le_max_left _ _ + apply phiEven_strictAntiOn.antitoneOn + · change 1 < u + change minRatio .odd s ≤ u at hu + linarith + · change 1 < v + change minRatio .odd s ≤ v at hv + linarith + · exact huv + have hq : (v+1)/v ≤ (u+1)/u := by + have h := one_div_le_one_div_of_le hu0 huv + have heU : (u+1)/u = 1+1/u := by field_simp + have heV : (v+1)/v = 1+1/v := by field_simp + rw [heU,heV] + linarith + have hqU : 0 ≤ (u+1)/u := (div_pos (by linarith) hu0).le + have hqV : 0 ≤ (v+1)/v := (div_pos (by linarith) hv0).le + have hsq : ((v+1)/v)^2 ≤ ((u+1)/u)^2 := by nlinarith + unfold multiplier + apply div_le_div_of_nonneg_right _ (weight_pos hs).le + exact mul_le_mul hsq hphi (weight_pos (valid_next hs hv)).le (sq_nonneg _) + +theorem ratioMeasure_ae_above (a : ℝ) : ∀ᵐ t ∂ratioMeasure a, a ≤ t := + (withDensity_absolutelyContinuous _ _).ae_le (ae_restrict_mem measurableSet_Ici) + +theorem multiplier_nonnegative_ae {i : Side} {s : ℝ} (hs : Valid i s) : + 0 ≤ᵐ[ratioMeasure (minRatio i s)] multiplier i s := + (ratioMeasure_ae_above _).mono (fun _ ht => (multiplier_pos hs (valid_next hs ht)).le) + +theorem weighted_ratio_density_eq {i : Side} {s : ℝ} (hs : Valid i s) (t : ℝ) : + (Ici (minRatio i s)).indicator (fun t => ENNReal.ofReal (1/(t+1)) * ENNReal.ofReal (multiplier i s t)) t = + ENNReal.ofReal (transitionDensity i s t) := by + classical + by_cases ht : minRatio i s ≤ t + · have ht0 := valid_pos (valid_next hs ht) + rw [indicator_of_mem (show t ∈ Ici (minRatio i s) from ht), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ 1/(t+1)), transitionDensity, tailDensity, + indicator_of_mem (show t ∈ Ici (minRatio i s) from ht)] + congr 1 + unfold multiplier W + field_simp + · rw [indicator_of_notMem (show t ∉ Ici (minRatio i s) from ht), transitionDensity, tailDensity, + indicator_of_notMem (show t ∉ Ici (minRatio i s) from ht), ENNReal.ofReal_zero] + +theorem transitionDensity_mass {i : Side} {s : ℝ} (hs : Valid i s) : + (∫⁻ t : ℝ, ENNReal.ofReal (transitionDensity i s t)) = 1 := by + cases i with + | even => + let x : EvenState := ⟨s,hs⟩ + have h := evenKernel_apply x univ + simp only [setLIntegral_univ, measure_univ] at h + exact h.symm + | odd => + let x : OddState := ⟨s,hs⟩ + have h := oddKernel_apply x univ + simp only [setLIntegral_univ, measure_univ] at h + exact h.symm + +theorem multiplier_ratio_integral {i : Side} {s : ℝ} (hs : Valid i s) : + (∫⁻ t, ENNReal.ofReal (multiplier i s t) ∂ratioMeasure (minRatio i s)) = 1 := by + rw [ratioMeasure, lintegral_withDensity_eq_lintegral_mul _ (f := fun t : ℝ => ENNReal.ofReal (1/(t+1))) + (g := fun t : ℝ => ENNReal.ofReal (multiplier i s t)) (by fun_prop) + (ENNReal.measurable_ofReal.comp (multiplier_measurable i s)), ← lintegral_indicator measurableSet_Ici] + calc + _ = ∫⁻ t : ℝ, ENNReal.ofReal (transitionDensity i s t) := lintegral_congr (fun t => weighted_ratio_density_eq hs t) + _ = 1 := transitionDensity_mass hs + +end NumberTheoryLean.PrimeTiltMonotone + + + +namespace NumberTheoryLean.PrimeRatioMeasure + +open _root_.Set _root_.Finset _root_.MeasureTheory +open _root_.Erdos970.Set _root_.Erdos970.Finset _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeTiltBounds PrimeTiltMonotone +open PrimeRatioBins HarmonicExponentMeasure + +noncomputable def primeAtoms (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) : Finset ℝ := by + classical + exact (children w ell S i s r cap closed).image (childRatio w r) + +noncomputable def finitePrimeMeasure (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) : Measure ℝ := + ∑ p ∈ children w ell S i s r cap closed, ENNReal.ofReal (p : ℝ)⁻¹ • Measure.dirac (childRatio w r p) + +theorem finitePrimeMeasure_apply (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) + {B : Set ℝ} [DecidablePred (fun x => x ∈ B)] (hB : MeasurableSet B) : + finitePrimeMeasure w ell S i s r cap closed B = + ∑ p ∈ children w ell S i s r cap closed, if childRatio w r p ∈ B then ENNReal.ofReal (p : ℝ)⁻¹ else 0 := by + classical + simp only [finitePrimeMeasure, Measure.finsetSum_apply, Measure.smul_apply, smul_eq_mul, + Measure.dirac_apply' _ hB, Set.indicator, Pi.one_apply, mul_ite, mul_one, mul_zero] + +theorem finitePrimeMeasure_support (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) : + ∀ᵐ t ∂finitePrimeMeasure w ell S i s r cap closed, t ∈ primeAtoms w ell S i s r cap closed := by + classical + apply ae_iff.mpr + change finitePrimeMeasure w ell S i s r cap closed ((↑(primeAtoms w ell S i s r cap closed) : Set ℝ)ᶜ) = 0 + rw [finitePrimeMeasure_apply _ _ _ _ _ _ _ _ (Finset.finite_toSet _).measurableSet.compl] + apply Finset.sum_eq_zero + intro p hp + have hm : childRatio w r p ∈ primeAtoms w ell S i s r cap closed := Finset.mem_image.mpr ⟨p,hp,rfl⟩ + simp only [Set.mem_compl_iff, Finset.mem_coe, hm, not_true_eq_false, ite_false] + +theorem primeAtoms_above (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) : + ∀ t ∈ primeAtoms w ell S i s r cap closed, minRatio i s ≤ t := by + classical + intro t ht + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp ht + exact (Finset.mem_filter.mp hp).2.2.2.1 + +theorem finitePrimeMeasure_Icc (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) (x : ℝ) : + finitePrimeMeasure w ell S i s r cap closed (Icc (minRatio i s) x) = + ENNReal.ofReal (∑ p ∈ children w ell S i s r cap closed, + if childRatio w r p ≤ x then (p : ℝ)⁻¹ else 0) := by + classical + rw [finitePrimeMeasure_apply _ _ _ _ _ _ _ _ measurableSet_Icc, + ENNReal.ofReal_sum_of_nonneg (fun p _ => by split_ifs <;> positivity)] + apply Finset.sum_congr rfl + intro p hp + have ha : minRatio i s ≤ childRatio w r p := (Finset.mem_filter.mp hp).2.2.2.1 + by_cases hx : childRatio w r p ≤ x <;> simp [Set.mem_Icc,ha,hx] + +theorem finitePrimeMeasure_tilt (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) (hs : Valid i s) : + (∫⁻ t, ENNReal.ofReal (multiplier i s t) ∂finitePrimeMeasure w ell S i s r cap closed) = + ENNReal.ofReal (∑ p ∈ children w ell S i s r cap closed, primeTilt w r i s p) := by + rw [finitePrimeMeasure, lintegral_finsetSum_measure] + simp_rw [lintegral_smul_measure, lintegral_dirac' _ (f := fun t => ENNReal.ofReal (multiplier i s t)) + (ENNReal.measurable_ofReal.comp (multiplier_measurable i s))] + simp only [smul_eq_mul] + rw [ENNReal.ofReal_sum_of_nonneg (fun p hp => primeTilt_nonneg hs hp)] + apply Finset.sum_congr rfl + intro p hp + rw [primeTilt_eq_multiplier, ENNReal.ofReal_mul (inv_nonneg.mpr (Nat.cast_nonneg p))] + +theorem ratioMeasure_Icc {a x : ℝ} (ha : 0 < a) (hax : a ≤ x) : + ratioMeasure a (Icc a x) = ENNReal.ofReal (Real.log (x+1)-Real.log (a+1)) := by + rw [ratioMeasure, withDensity_apply _ measurableSet_Icc, Measure.restrict_restrict measurableSet_Icc, + Set.inter_eq_left.mpr (show Icc a x ⊆ Ici a from fun _ ht => ht.1)] + have hi : IntegrableOn (fun t : ℝ => 1/(t+1)) (Icc a x) := by + apply ContinuousOn.integrableOn_Icc + apply continuousOn_const.div (continuousOn_id.add continuousOn_const) + intro t ht + change t+1 ≠ 0 + linarith [ht.1] + have hn : ∀ᵐ t ∂volume.restrict (Icc a x), 0 ≤ 1/(t+1) := by + apply ae_restrict_of_forall_mem measurableSet_Icc + intro t ht + exact (one_div_pos.mpr (by linarith [ht.1] : 0 < t+1)).le + rw [← ofReal_integral_eq_lintegral_ofReal hi hn, integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le hax, + intervalIntegral.integral_comp_add_right (f := fun t : ℝ => 1/t) 1, + integral_one_div_of_pos (by linarith : 0 < a+1) (by linarith : 0 < x+1), + Real.log_div (by linarith : x+1 ≠ 0) (by linarith : a+1 ≠ 0)] + +end NumberTheoryLean.PrimeRatioMeasure + + + +namespace NumberTheoryLean.PrimeCumulativeBound + +open _root_.Set _root_.Finset _root_.MeasureTheory +open _root_.Erdos970.Set _root_.Erdos970.Finset _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeTiltMonotone PrimeRatioBins +open PrimeRatioMeasure HarmonicExponentMeasure +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimeEndpoints + +noncomputable def closedBin (w r a b : ℝ) : Finset ℕ := by + classical + exact (Nat.primesLE ⌊w^(r/(a+1))⌋₊).filter (fun p => a ≤ childRatio w r p ∧ childRatio w r p ≤ b) + +noncomputable def closedMass (w r a b : ℝ) : ℝ := ∑ p ∈ closedBin w r a b, (p : ℝ)⁻¹ + +theorem closed_interval_iff {r a b x : ℝ} (ha : 0 < a) (hab : a ≤ b) (hx : 0 < x) : + (a ≤ r/x-1 ∧ r/x-1 ≤ b) ↔ r/(b+1) ≤ x ∧ x ≤ r/(a+1) := by + have ha1 : 0 < a+1 := by linarith + have hb1 : 0 < b+1 := by linarith + constructor + · rintro ⟨hlo,hhi⟩ + constructor + · apply (div_le_iff₀ hb1).mpr + have h := (div_le_iff₀ hx).mp (show r/x ≤ b+1 by linarith) + nlinarith + · apply (le_div_iff₀ ha1).mpr + have h := (le_div_iff₀ hx).mp (show a+1 ≤ r/x by linarith) + nlinarith + · rintro ⟨hlo,hhi⟩ + constructor + · have h := (le_div_iff₀ ha1).mp hhi + have hh : a+1 ≤ r/x := (le_div_iff₀ hx).mpr (by nlinarith) + linarith + · have h := (div_le_iff₀ hb1).mp hlo + have hh : r/x ≤ b+1 := (div_le_iff₀ hx).mpr (by nlinarith) + linarith + +theorem closedMass_eq_harmonic {w r a b : ℝ} (hw : 1 < w) (ha : 0 < a) (hab : a ≤ b) : + closedMass w r a b = harmonicMass w true true (r/(b+1)) (r/(a+1)) := by + classical + unfold closedMass closedBin harmonicMass + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro p hp + have h := closed_interval_iff (r := r) ha hab (PrimeRatioBins.primeExponent_pos hw (Nat.mem_primesLE.mp hp).2) + simp only [childRatio, intervalGuard, ite_true, h] + +theorem cumulative_subset_closed {w ell S s r cap b : ℝ} (hw : 1 < w) {i : Side} (hs : Valid i s) (closed : Bool) : + (children w ell S i s r cap closed).filter (fun p => childRatio w r p ≤ b) ⊆ + closedBin w r (minRatio i s) b := by + classical + intro p hp + rcases Finset.mem_filter.mp hp with ⟨hchild,hb⟩ + have hprime := (Nat.mem_primesLE.mp (Finset.mem_filter.mp hchild).1).2 + have ha : minRatio i s ≤ childRatio w r p := (Finset.mem_filter.mp hchild).2.2.2.1 + have hab : minRatio i s ≤ b := ha.trans hb + have hinterval := (closed_interval_iff (r := r) (minRatio_pos hs) hab (PrimeRatioBins.primeExponent_pos hw hprime)).mp ⟨ha,hb⟩ + apply Finset.mem_filter.mpr + refine ⟨Nat.mem_primesLE.mpr ⟨?_,hprime⟩,ha,hb⟩ + have hp0 : (0 : ℝ) < p := by exact_mod_cast hprime.pos + have hreal : (p : ℝ) ≤ w^(r/(minRatio i s+1)) := (exponent_le_iff hw hp0).mp hinterval.2 + exact (Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) _).le).mpr hreal + +theorem cumulative_sum_le_closed {w ell S s r cap b : ℝ} (hw : 1 < w) {i : Side} (hs : Valid i s) (closed : Bool) : + (∑ p ∈ children w ell S i s r cap closed, if childRatio w r p ≤ b then (p : ℝ)⁻¹ else 0) ≤ + closedMass w r (minRatio i s) b := by + classical + rw [← Finset.sum_filter] + exact Finset.sum_le_sum_of_subset_of_nonneg (cumulative_subset_closed hw hs closed) + (fun p _ _ => inv_nonneg.mpr (Nat.cast_nonneg p)) + +theorem actual_cumulative_error : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ i : Side, ∀ s r cap : ℝ, ∀ closed : Bool, + 1 ≤ ell → 0 < r → Valid i s → ∀ x ∈ primeAtoms w ell S i s r cap closed, + finitePrimeMeasure w ell S i s r cap closed (Icc (minRatio i s) x) ≤ + ratioMeasure (minRatio i s) (Icc (minRatio i s) x) + + ENNReal.ofReal (C * Real.exp (-c * Real.sqrt ((1/2 : ℝ) * Real.log w))) := by + classical + obtain ⟨c,C,w₀,hc,hC,hw₀,hbound⟩ := harmonic_prime_measure + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw ell S i s r cap closed hell hr hs x hx + have hw1 := hw₀.trans_le hw + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hx + let x := childRatio w r p + have ha := minRatio_pos hs + have hax : minRatio i s ≤ x := (Finset.mem_filter.mp hp).2.2.2.1 + have hxp : r/(x+1) = primeExponent w p := nextExponent_childRatio hr (child_exponent_positive (by linarith) hp) + have hlow : (1/2 : ℝ) ≤ r/(x+1) := by + rw [hxp] + have h := (Finset.mem_filter.mp hp).2.1 + linarith + have hend : r/(x+1) ≤ r/(minRatio i s+1) := + div_le_div_of_nonneg_left hr.le (by linarith : 0 < minRatio i s+1) (by linarith) + have hprime := hbound w hw (r/(x+1)) (r/(minRatio i s+1)) hlow hend true true + rw [← closedMass_eq_harmonic hw1 ha hax, bin_log_width hr ha hax] at hprime + have hE : C * Real.exp (-c * Real.sqrt ((r/(x+1))*Real.log w)) ≤ + C * Real.exp (-c * Real.sqrt ((1/2 : ℝ)*Real.log w)) := by + apply mul_le_mul_of_nonneg_left _ hC.le + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonpos_left (Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_right hlow (Real.log_pos hw1).le)) (by linarith) + have hraw : (∑ q ∈ children w ell S i s r cap closed, if childRatio w r q ≤ x then (q : ℝ)⁻¹ else 0) ≤ + (Real.log (x+1)-Real.log (minRatio i s+1)) + C * Real.exp (-c * Real.sqrt ((1/2 : ℝ)*Real.log w)) := by + have h := cumulative_sum_le_closed (ell := ell) (S := S) (r := r) (cap := cap) (b := x) hw1 hs closed + have hh := (abs_le.mp hprime).2 + linarith + change finitePrimeMeasure w ell S i s r cap closed (Icc (minRatio i s) x) ≤ _ + rw [finitePrimeMeasure_Icc, ratioMeasure_Icc ha hax] + have hmain : 0 ≤ Real.log (x+1)-Real.log (minRatio i s+1) := + sub_nonneg.mpr (Real.log_le_log (by linarith) (by linarith)) + rw [← ENNReal.ofReal_add hmain (by positivity)] + exact ENNReal.ofReal_le_ofReal hraw + +end NumberTheoryLean.PrimeCumulativeBound + + + +namespace NumberTheoryLean.PrimeRowMass + +open _root_.Set _root_.Finset _root_.MeasureTheory +open _root_.Erdos970.Set _root_.Erdos970.Finset _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeTiltBounds PrimeTiltMonotone +open PrimeRatioMeasure PrimeCumulativeBound HarmonicExponentMeasure FiniteMonotoneComparison + +theorem retained_row_mass : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ i : Side, ∀ s r cap : ℝ, ∀ closed : Bool, + 1 ≤ ell → 0 < r → Valid i s → s ≤ S → + (∑ p ∈ children w ell S i s r cap closed, primeTilt w r i s p) ≤ + 1 + C*(1+S)^2 * Real.exp (-c * Real.sqrt ((1/2 : ℝ)*Real.log w)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hcdf⟩ := actual_cumulative_error + obtain ⟨D,hD,henv⟩ := multiplier_envelope + refine ⟨c,C*D,w₀,hc,mul_pos hC hD,hw₀,?_⟩ + intro w hw ell S i s r cap closed hell hr hs hsS + let μ := finitePrimeMeasure w ell S i s r cap closed + let ν := ratioMeasure (minRatio i s) + let A := primeAtoms w ell S i s r cap closed + let E := C * Real.exp (-c * Real.sqrt ((1/2 : ℝ)*Real.log w)) + have hE : 0 ≤ E := by dsimp [E]; positivity + have hloc : ∀ t ∈ A, minRatio i s ≤ t := primeAtoms_above w ell S i s r cap closed + have hcomp := finite_monotone_integral_le μ ν A (multiplier i s) (minRatio i s) + (multiplier i s (minRatio i s)) (ENNReal.ofReal E) (multiplier_measurable i s) + (finitePrimeMeasure_support w ell S i s r cap closed) hloc + (fun t ht => (multiplier_pos hs (valid_next hs (hloc t ht))).le) + (multiplier_nonnegative_ae hs) (multiplier_antitone hs) + (fun t ht => multiplier_antitone hs (a := minRatio i s) (b := t) + (Set.mem_Ici.mpr le_rfl) (Set.mem_Ici.mpr (hloc t ht)) (hloc t ht)) + (hcdf w hw ell S i s r cap closed hell hr hs) + rw [finitePrimeMeasure_tilt w ell S i s r cap closed hs, multiplier_ratio_integral hs] at hcomp + have hM := henv S i s (minRatio i s) hs hsS le_rfl + have hn : 0 ≤ 1 + (C*D)*(1+S)^2 * Real.exp (-c*Real.sqrt ((1/2 : ℝ)*Real.log w)) := by positivity + apply (ENNReal.ofReal_le_ofReal_iff hn).mp + calc + _ ≤ 1 + ENNReal.ofReal E * ENNReal.ofReal (multiplier i s (minRatio i s)) := hcomp + _ ≤ 1 + ENNReal.ofReal E * ENNReal.ofReal (D*(1+S)^2) := + add_le_add le_rfl (mul_le_mul le_rfl (ENNReal.ofReal_le_ofReal hM) zero_le zero_le) + _ = _ := by + rw [← ENNReal.ofReal_mul hE] + have hprod : 0 ≤ E*(D*(1+S)^2) := by positivity + rw [show (1 : ℝ≥0∞) = ENNReal.ofReal (1 : ℝ) by norm_num, ← ENNReal.ofReal_add (by norm_num) hprod] + congr 1 + dsimp [E] + ring + +end NumberTheoryLean.PrimeRowMass + + + +namespace NumberTheoryLean.PrimeRowNormalization + +open _root_.Filter _root_.Set _root_.Finset +open _root_.Erdos970.Filter _root_.Erdos970.Set _root_.Erdos970.Finset +open scoped Topology +open FinitePathGeometry PrimeTiltGeometry PrimeRowMass + + theorem polynomial_absorption {c C : ℝ} (hc : 0 < c) (hC : 0 < C) : ∀ᶠ w : ℝ in atTop, + ∀ S : ℝ, 0 ≤ S → S ≤ (Real.log w)^3 → + C*(1+S)^2 * Real.exp (-c*Real.sqrt ((1/2 : ℝ)*Real.log w)) ≤ + Real.exp (-(c/4)*Real.sqrt (Real.log w)) := by + have hd : 0 < c/4 := by positivity + have ht : Tendsto (fun x : ℝ => 4*C*x^12 * Real.exp (-(c/4)*x)) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (12 : ℝ) (c/4) hd).const_mul (4*C) + simpa only [Real.rpow_ofNat, mul_zero, mul_assoc] using h + have hcomp := ht.comp (Real.tendsto_sqrt_atTop.comp Real.tendsto_log_atTop) + filter_upwards [hcomp.eventually (eventually_lt_nhds (by norm_num : (0 : ℝ) < 1)), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1 : ℝ))] with w hsmall hlog + intro S hS0 hS + let L := Real.log w + let Y := Real.sqrt L + have hL : 1 ≤ L := hlog + have hL0 : 0 ≤ L := by linarith + have hY0 : 0 ≤ Y := Real.sqrt_nonneg _ + have hY2 : Y^2 = L := Real.sq_sqrt hL0 + have hY12 : Y^12 = L^6 := by + calc + _ = (Y^2)^6 := by ring + _ = _ := by rw [hY2] + have hL3 : 1 ≤ L^3 := one_le_pow₀ hL + have hlin : 1+S ≤ 2*L^3 := by change S ≤ L^3 at hS; linarith + have hpoly : (1+S)^2 ≤ 4*Y^12 := by + calc + _ ≤ (2*L^3)^2 := pow_le_pow_left₀ (by linarith) hlin 2 + _ = _ := by rw [hY12]; ring + have hhalf : Y/2 ≤ Real.sqrt ((1/2 : ℝ)*L) := by + apply (sq_le_sq₀ (by positivity : 0 ≤ Y/2) (Real.sqrt_nonneg _)).mp + rw [Real.sq_sqrt (by positivity : 0 ≤ (1/2 : ℝ)*L)] + nlinarith [hY2] + have he : Real.exp (-c*Real.sqrt ((1/2 : ℝ)*L)) ≤ Real.exp (-(c/2)*Y) := by + apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left hhalf hc.le] + have hsml : 4*C*Y^12*Real.exp (-(c/4)*Y) ≤ 1 := hsmall.le + calc + _ ≤ (4*C*Y^12) * Real.exp (-(c/2)*Y) := + mul_le_mul (by nlinarith [mul_le_mul_of_nonneg_left hpoly hC.le]) he (Real.exp_pos _).le (by positivity) + _ = (4*C*Y^12*Real.exp (-(c/4)*Y)) * Real.exp (-(c/4)*Y) := by + rw [show -(c/2)*Y = -(c/4)*Y + -(c/4)*Y by ring, Real.exp_add] + ring + _ ≤ 1 * Real.exp (-(c/4)*Y) := mul_le_mul_of_nonneg_right hsml (Real.exp_pos _).le + _ = _ := one_mul _ + +theorem retained_row_mass_one_add : ∃ c w₀ : ℝ, 0 < c ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, 0 ≤ S → S ≤ (Real.log w)^3 → + ∀ i : Side, ∀ s r cap : ℝ, ∀ closed : Bool, 1 ≤ ell → 0 < r → Valid i s → s ≤ S → + (∑ p ∈ children w ell S i s r cap closed, primeTilt w r i s p) ≤ + 1 + Real.exp (-c * Real.sqrt (Real.log w)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hrow⟩ := retained_row_mass + obtain ⟨w₁,hw₁⟩ := (eventually_atTop.1 (polynomial_absorption hc hC)) + refine ⟨c/4,max w₀ w₁,by positivity,hw₀.trans_le (le_max_left _ _),?_⟩ + intro w hw ell S hS0 hS i s r cap closed hell hr hs hsS + exact (hrow w ((le_max_left _ _).trans hw) ell S i s r cap closed hell hr hs hsS).trans + (add_le_add le_rfl (hw₁ w ((le_max_right _ _).trans hw) S hS0 hS)) + +end NumberTheoryLean.PrimeRowNormalization + + + +namespace NumberTheoryLean.PrimeKilledChain + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.Finset _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeHistories PrimeRowNormalization + +noncomputable def normalizationRate : ℝ := Classical.choose retained_row_mass_one_add +noncomputable def normalizationThreshold : ℝ := Classical.choose (Classical.choose_spec retained_row_mass_one_add) + + theorem normalizationRate_pos : 0 < normalizationRate := + (Classical.choose_spec (Classical.choose_spec retained_row_mass_one_add)).1 + +theorem normalizationThreshold_gt_one : 1 < normalizationThreshold := + (Classical.choose_spec (Classical.choose_spec retained_row_mass_one_add)).2.1 + +noncomputable def epsilon (w : ℝ) : ℝ := Real.exp (-normalizationRate * Real.sqrt (Real.log w)) + +theorem epsilon_pos (w : ℝ) : 0 < epsilon w := Real.exp_pos _ +theorem normalizer_pos (w : ℝ) : 0 < 1+epsilon w := by linarith [epsilon_pos w] + +theorem actual_row_bound {w ell S : ℝ} (hw : normalizationThreshold ≤ w) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) + (z : Node) (hell : 1 ≤ ell) (hr : 0 < z.gap) (hs : Valid z.side z.ratio) (hsS : z.ratio ≤ S) : + (∑ p ∈ nodeChildren w ell S z, primeTilt w z.gap z.side z.ratio p) ≤ 1+epsilon w := by + exact (Classical.choose_spec (Classical.choose_spec retained_row_mass_one_add)).2.2 + w hw ell S hS0 hS z.side z.ratio z.gap z.cutoff z.closed hell hr hs hsS + +variable (w ell S : ℝ) (start : Node) +abbrev ChainState := Option (History w ell S start) + +instance : MeasurableSpace (ChainState w ell S start) := ⊤ +instance : MeasurableSingletonClass (ChainState w ell S start) := ⟨fun _ => trivial⟩ + +noncomputable def childProbability (h : History w ell S start) (p : ℕ) : ℝ≥0∞ := + ENNReal.ofReal (primeTilt w h.node.gap h.node.side h.node.ratio p / (1+epsilon w)) + +noncomputable def liveMass (h : History w ell S start) : ℝ≥0∞ := + ∑ p ∈ nodeChildren w ell S h.node, childProbability w ell S start h p + +noncomputable def liveLaw (h : History w ell S start) : Measure (ChainState w ell S start) := + ∑ p ∈ (nodeChildren w ell S h.node).attach, + childProbability w ell S start h p.1 • Measure.dirac (some (h.append p.1 p.2)) + +theorem liveLaw_univ (h : History w ell S start) : liveLaw w ell S start h univ = liveMass w ell S start h := by + simp only [liveLaw, Measure.finsetSum_apply, Measure.smul_apply, smul_eq_mul, measure_univ, mul_one, + Finset.sum_attach, liveMass] + +noncomputable def completedLaw (h : History w ell S start) : Measure (ChainState w ell S start) := + liveLaw w ell S start h + (1-liveMass w ell S start h) • Measure.dirac none + +noncomputable def chain : Kernel (ChainState w ell S start) (ChainState w ell S start) where + toFun z := match z with + | none => Measure.dirac none + | some h => completedLaw w ell S start h + measurable' := measurable_of_countable _ + +@[simp] theorem chain_none : chain w ell S start none = Measure.dirac none := rfl +@[simp] theorem chain_some (h : History w ell S start) : chain w ell S start (some h) = completedLaw w ell S start h := rfl + +variable {w ell S : ℝ} {start : Node} + +theorem liveMass_le_one (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) : + liveMass w ell S start h ≤ 1 := by + have hnvalid := terminal_valid hs h.admissible + have hngap := terminal_gap_positive (by linarith : 0 ≤ ell) hr hs h.admissible + have hnS := terminal_ratio_le hsS h.admissible + have hrow := actual_row_bound hw hS0 hS h.node hell hngap hnvalid hnS + have hZ := normalizer_pos w + unfold liveMass childProbability + have hnonneg : ∀ p ∈ nodeChildren w ell S h.node, + 0 ≤ primeTilt w h.node.gap h.node.side h.node.ratio p / (1+epsilon w) := by + intro p hp + exact div_nonneg (primeTilt_nonneg (w := w) (r := h.node.gap) (i := h.node.side) (s := h.node.ratio) hnvalid hp) hZ.le + rw [← ENNReal.ofReal_sum_of_nonneg (s := nodeChildren w ell S h.node) + (f := fun p => primeTilt w h.node.gap h.node.side h.node.ratio p / (1+epsilon w)) hnonneg, ← Finset.sum_div] + have hreal : (∑ p ∈ nodeChildren w ell S h.node, primeTilt w h.node.gap h.node.side h.node.ratio p) / + (1+epsilon w) ≤ 1 := (div_le_iff₀ hZ).mpr (by simpa only [one_mul] using hrow) + simpa only [ENNReal.ofReal_one] using ENNReal.ofReal_le_ofReal hreal + +theorem chain_isMarkov (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) : + IsMarkovKernel (chain w ell S start) := by + constructor + intro z + constructor + cases z with + | none => simp only [chain_none, measure_univ] + | some h => + rw [chain_some, completedLaw, Measure.add_apply, liveLaw_univ, Measure.smul_apply] + simp only [measure_univ, smul_eq_mul, mul_one] + exact add_tsub_cancel_of_le (liveMass_le_one hw hell hS0 hS hr hs hsS h) + +instance chain_pow_markov [IsMarkovKernel (chain w ell S start)] (n : ℕ) : + IsMarkovKernel ((chain w ell S start)^n) := by + induction n with + | zero => change IsMarkovKernel (Kernel.id : Kernel (ChainState w ell S start) (ChainState w ell S start)); infer_instance + | succ n ih => + let := ih + have hp : (chain w ell S start)^(n+1) = (chain w ell S start) ∘ₖ ((chain w ell S start)^n) := pow_succ' _ _ + rw [hp] + infer_instance + +noncomputable def pathLaw (w ell S : ℝ) (start : Node) (n : ℕ) : Measure (ChainState w ell S start) := + ((chain w ell S start)^n) (some History.empty) + +theorem pathLaw_isProbability (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) (n : ℕ) : + IsProbabilityMeasure (pathLaw w ell S start n) := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + unfold pathLaw + infer_instance + +end NumberTheoryLean.PrimeKilledChain + + + +namespace NumberTheoryLean.PrimeChainProbabilities + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.Finset _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeTiltPrefixes PrimeHistories PrimeKilledChain + +variable {w ell S : ℝ} {start : Node} + +theorem history_append_eq_iff (h k : History w ell S start) (p q : ℕ) + (hp : p ∈ nodeChildren w ell S h.node) (hq : q ∈ nodeChildren w ell S k.node) : + h.append p hp = k.append q hq ↔ h = k ∧ p = q := by + constructor + · intro heq + have hl := congrArg History.primes heq + have hh := List.append_singleton_inj.mp hl + exact ⟨History.ext hh.1,hh.2⟩ + · rintro ⟨rfl,rfl⟩ + exact History.ext rfl + +theorem liveLaw_at_append (g h : History w ell S start) (p : ℕ) + (hp : p ∈ nodeChildren w ell S h.node) : + liveLaw w ell S start g {some (h.append p hp)} = + ({h} : Set (History w ell S start)).indicator (fun _ => childProbability w ell S start h p) g := by + classical + simp only [liveLaw, Measure.finsetSum_apply, Measure.smul_apply, smul_eq_mul, Measure.dirac_apply, + Set.indicator, Set.mem_singleton_iff, Pi.one_apply, Option.some.injEq, history_append_eq_iff, + mul_ite, mul_one, mul_zero] + by_cases hgh : g = h + · subst g + simp only [true_and, ite_true] + calc + _ = ∑ q ∈ nodeChildren w ell S h.node, if q = p then childProbability w ell S start h q else 0 := + Finset.sum_attach _ (fun q : ℕ => if q = p then childProbability w ell S start h q else 0) + _ = _ := by simp [hp] + · simp [hgh] + +theorem chain_at_append (h : History w ell S start) (p : ℕ) + (hp : p ∈ nodeChildren w ell S h.node) (z : ChainState w ell S start) : + chain w ell S start z {some (h.append p hp)} = + ({some h} : Set (ChainState w ell S start)).indicator (fun _ => childProbability w ell S start h p) z := by + classical + cases z with + | none => simp [chain_none, Set.indicator] + | some g => + rw [chain_some, completedLaw, Measure.add_apply, liveLaw_at_append, Measure.smul_apply] + simp [Set.indicator] + +theorem pathLaw_append (n : ℕ) (h : History w ell S start) (p : ℕ) + (hp : p ∈ nodeChildren w ell S h.node) : + pathLaw w ell S start (n+1) {some (h.append p hp)} = + childProbability w ell S start h p * pathLaw w ell S start n {some h} := by + unfold pathLaw + have hpow : (chain w ell S start)^(n+1) = (chain w ell S start) ∘ₖ ((chain w ell S start)^n) := pow_succ' _ _ + rw [hpow, Kernel.comp_apply' _ _ _ (measurableSet_singleton _)] + calc + _ = ∫⁻ z, ({some h} : Set (ChainState w ell S start)).indicator + (fun _ => childProbability w ell S start h p) z ∂((chain w ell S start)^n) (some History.empty) := + lintegral_congr (fun z => chain_at_append h p hp z) + _ = _ := by rw [lintegral_indicator (measurableSet_singleton _), lintegral_const, Measure.restrict_apply_univ] + +noncomputable def nodeProduct (e w : ℝ) (z : Node) (ps : List ℕ) : ℝ := + normalizedTiltProduct e w z.side z.ratio z.gap ps + +theorem nodeProduct_append (e w : ℝ) (z : Node) (ps qs : List ℕ) : + nodeProduct e w z (ps++qs) = nodeProduct e w z ps * nodeProduct e w (terminal w z ps) qs := by + induction ps generalizing z with + | nil => simp [nodeProduct, normalizedTiltProduct, terminal] + | cons p ps ih => + change (primeTilt w z.gap z.side z.ratio p / (1+e)) * nodeProduct e w (step w z p) (ps++qs) = + ((primeTilt w z.gap z.side z.ratio p / (1+e)) * nodeProduct e w (step w z p) ps) * + nodeProduct e w (terminal w (step w z p) ps) qs + rw [ih, mul_assoc] + +theorem nodeProduct_nonnegative {e : ℝ} (he : 0 ≤ e) {z : Node} {ps : List ℕ} + (hs : Valid z.side z.ratio) (hp : allowed w ell S z ps) : 0 ≤ nodeProduct e w z ps := by + induction ps generalizing z with + | nil => exact zero_le_one + | cons p ps ih => + rcases (allowed_cons w ell S z p ps).mp hp with ⟨hchild,hrest⟩ + change 0 ≤ (primeTilt w z.gap z.side z.ratio p / (1+e)) * nodeProduct e w (step w z p) ps + exact mul_nonneg (div_nonneg (primeTilt_nonneg hs hchild) (by linarith)) (ih (child_valid hs hchild) hrest) + +theorem pathLaw_singleton_weight (hs : Valid start.side start.ratio) (h : History w ell S start) : + pathLaw w ell S start h.primes.length {some h} = ENNReal.ofReal (nodeProduct (epsilon w) w start h.primes) := by + classical + have main : ∀ ps : List ℕ, ∀ h : History w ell S start, h.primes = ps → + pathLaw w ell S start ps.length {some h} = ENNReal.ofReal (nodeProduct (epsilon w) w start ps) := by + intro ps + induction ps using List.reverseRecOn with + | nil => + intro h heq + have hh : h = History.empty := History.ext heq + subst h + change Measure.dirac (some (History.empty : History w ell S start)) {some History.empty} = ENNReal.ofReal (1 : ℝ) + simp + | append_singleton ps p ih => + intro h heq + have hall : allowed w ell S start (ps++[p]) := heq ▸ h.admissible + obtain ⟨hpre,hlast⟩ := (allowed_append w ell S start ps [p]).mp hall + let g : History w ell S start := ⟨ps,hpre⟩ + have hp : p ∈ nodeChildren w ell S g.node := (allowed_cons w ell S g.node p []).mp hlast |>.1 + have hh : h = g.append p hp := History.ext heq + rw [hh, List.length_append, List.length_singleton, pathLaw_append, ih g rfl, nodeProduct_append] + have hgn : Valid g.node.side g.node.ratio := terminal_valid hs g.admissible + have hn : 0 ≤ primeTilt w g.node.gap g.node.side g.node.ratio p / (1+epsilon w) := + div_nonneg (primeTilt_nonneg (w := w) (r := g.node.gap) (i := g.node.side) (s := g.node.ratio) hgn hp) (normalizer_pos w).le + change ENNReal.ofReal (primeTilt w g.node.gap g.node.side g.node.ratio p / (1+epsilon w)) * + ENNReal.ofReal (nodeProduct (epsilon w) w start ps) = + ENNReal.ofReal (nodeProduct (epsilon w) w start ps * + (primeTilt w g.node.gap g.node.side g.node.ratio p / (1+epsilon w) * 1)) + rw [← ENNReal.ofReal_mul hn] + congr 1 + ring + exact main h.primes h rfl + +theorem source_prime_weight_identity (hell : 0 ≤ ell) (hr : 0 < start.gap) + (hs : Valid start.side start.ratio) (h : History w ell S start) : + ErdosPrimeInputs.PrimePrefixMass.prefixWeight h.primes = + (pathLaw w ell S start h.primes.length {some h}).toReal * (1+epsilon w)^h.primes.length * + (h.node.gap/start.gap)^2 * (weight start.side start.ratio / weight h.node.side h.node.ratio) := by + rw [pathLaw_singleton_weight hs h, ENNReal.toReal_ofReal (nodeProduct_nonnegative (epsilon_pos w).le hs h.admissible)] + have hweight := normalized_prime_prefix_weight_identity (epsilon_pos w).le hell hr hs h.admissible + simpa only [nodeProduct, History.node, terminal_gap_eq, terminal_side_eq, terminal_ratio_eq] using hweight + +theorem normalized_source_prime_weight (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) : + IsProbabilityMeasure (pathLaw w ell S start h.primes.length) ∧ + ErdosPrimeInputs.PrimePrefixMass.prefixWeight h.primes = + (pathLaw w ell S start h.primes.length {some h}).toReal * (1+epsilon w)^h.primes.length * + (h.node.gap/start.gap)^2 * (weight start.side start.ratio / weight h.node.side h.node.ratio) := by + exact ⟨pathLaw_isProbability hw hell hS0 hS hr hs hsS h.primes.length, + source_prime_weight_identity (by linarith) hr hs h⟩ + +end NumberTheoryLean.PrimeChainProbabilities + + + +namespace NumberTheoryLean.PrimeCompactVisits + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.Finset _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeTiltGeometry + +variable {w ell S : ℝ} {start : Node} + +noncomputable def potential (K : ℝ) : ChainState w ell S start → ℝ + | none => 0 + | some h => min h.node.gap K + 1 + +noncomputable def visit (K : ℝ) : ChainState w ell S start → ℝ + | none => 0 + | some h => if h.node.gap ≤ K then 1 else 0 + +theorem visit_nonneg (K : ℝ) (z : ChainState w ell S start) : 0 ≤ visit K z := by + cases z with + | none => exact le_rfl + | some h => simp only [visit]; split_ifs <;> norm_num + +theorem potential_nonneg {K : ℝ} (hK : 0 ≤ K) (hell : 0 ≤ ell) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (z : ChainState w ell S start) : + 0 ≤ potential K z := by + cases z with + | none => exact le_rfl + | some h => + have hg : 0 < h.node.gap := terminal_gap_positive hell hr hs h.admissible + exact add_nonneg (le_min hg.le hK) zero_le_one + +theorem potential_le {K : ℝ} (hK : 0 ≤ K) (z : ChainState w ell S start) : + potential K z ≤ K+1 := by + cases z with + | none => change (0:ℝ) ≤ K+1; linarith + | some h => exact add_le_add_left (min_le_right _ _) 1 + +theorem visit_le_potential {K : ℝ} (hK : 0 ≤ K) (hell : 0 ≤ ell) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (z : ChainState w ell S start) : + visit K z ≤ potential K z := by + cases z with + | none => exact le_rfl + | some h => + have hg : 0 < h.node.gap := terminal_gap_positive hell hr hs h.admissible + simp only [visit,potential] + split_ifs with hle + · rw [min_eq_left hle]; linarith + · exact add_nonneg (le_min hg.le hK) zero_le_one + +theorem child_potential_drift {K : ℝ} (hell : 1 ≤ ell) + (h : History w ell S start) (p : ℕ) (hp : p ∈ nodeChildren w ell S h.node) : + visit K (some h) + potential K (some (h.append p hp)) ≤ potential K (some h) := by + classical + have he : ell < ErdosPrimeInputs.HarmonicPrimeMeasure.primeExponent w p := + (Finset.mem_filter.mp hp).2.1 + simp only [visit,potential,History.append_node,step] + split_ifs with hle + · rw [min_eq_left hle] + have hm := min_le_left (h.node.gap-ErdosPrimeInputs.HarmonicPrimeMeasure.primeExponent w p) K + linarith + · rw [min_eq_right (le_of_not_ge hle)] + have hm := min_le_right (h.node.gap-ErdosPrimeInputs.HarmonicPrimeMeasure.primeExponent w p) K + linarith + +variable (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) + +include hell hr hs in + +theorem actual_row_drift_ae {K : ℝ} (hK : 0 ≤ K) (z : ChainState w ell S start) : + ∀ᵐ y ∂chain w ell S start z, visit K z + potential K y ≤ potential K z := by + classical + cases z with + | none => + rw [chain_none] + exact (ae_dirac_iff (by trivial)).mpr (by simp [visit,potential]) + | some h => + have hdead : visit K (some h) + potential K (none : ChainState w ell S start) ≤ potential K (some h) := by + simpa only [potential,add_zero] using visit_le_potential hK (by linarith : 0 ≤ ell) hr hs (some h) + have hchild := child_potential_drift (K := K) hell h + apply ae_iff.mpr + simp [chain_some,completedLaw,liveLaw,hdead,hchild] + +include hw hell hS0 hS hr hs hsS + +theorem actual_row_drift {K : ℝ} (hK : 0 ≤ K) (z : ChainState w ell S start) : + ENNReal.ofReal (visit K z) + (∫⁻ y, ENNReal.ofReal (potential K y) ∂chain w ell S start z) ≤ + ENNReal.ofReal (potential K z) := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + have hp := actual_row_drift_ae hell hr hs hK z + have hnon := potential_nonneg (w := w) (S := S) hK (by linarith : 0 ≤ ell) hr hs + calc + _ = ∫⁻ y, ENNReal.ofReal (visit K z) + ENNReal.ofReal (potential K y) ∂chain w ell S start z := by + rw [lintegral_add_left measurable_const,lintegral_const,measure_univ,mul_one] + _ ≤ ∫⁻ _y, ENNReal.ofReal (potential K z) ∂chain w ell S start z := by + apply lintegral_mono_ae + filter_upwards [hp] with y hy + rw [← ENNReal.ofReal_add (visit_nonneg K z) (hnon y)] + exact ENNReal.ofReal_le_ofReal hy + _ = _ := by rw [lintegral_const,measure_univ,mul_one] + +theorem finite_compact_potential {K : ℝ} (hK : 0 ≤ K) (N : ℕ) : + (∑ n ∈ range N, ∫⁻ z, ENNReal.ofReal (visit K z) ∂pathLaw w ell S start n) + + (∫⁻ z, ENNReal.ofReal (potential K z) ∂pathLaw w ell S start N) ≤ + ENNReal.ofReal (potential K (some (History.empty : History w ell S start))) := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + have hV : Measurable (fun z : ChainState w ell S start => ENNReal.ofReal (potential K z)) := measurable_of_countable _ + have hv : Measurable (fun z : ChainState w ell S start => ENNReal.ofReal (visit K z)) := measurable_of_countable _ + induction N with + | zero => + simp only [sum_range_zero,zero_add,pathLaw,pow_zero] + change (∫⁻ z, ENNReal.ofReal (potential K z) ∂Measure.dirac (some History.empty)) ≤ _ + rw [lintegral_dirac' _ hV] + | succ N ih => + have hnext : (∫⁻ z, ENNReal.ofReal (potential K z) ∂pathLaw w ell S start (N+1)) = + ∫⁻ z, ∫⁻ y, ENNReal.ofReal (potential K y) ∂chain w ell S start z ∂pathLaw w ell S start N := by + unfold pathLaw + have hp : (chain w ell S start)^(N+1) = (chain w ell S start) ∘ₖ ((chain w ell S start)^N) := pow_succ' _ _ + rw [hp,Kernel.lintegral_comp _ _ _ hV] + rw [sum_range_succ,hnext,add_assoc] + apply le_trans (add_le_add_right ?_ _) ih + rw [← lintegral_add_left hv] + exact lintegral_mono (actual_row_drift hw hell hS0 hS hr hs hsS hK) + +theorem finite_compact_visits {K : ℝ} (hK : 0 ≤ K) (N : ℕ) : + (∑ n ∈ range N, ∫⁻ z, ENNReal.ofReal (visit K z) ∂pathLaw w ell S start n) ≤ + ENNReal.ofReal (K+1) := by + exact (le_add_right le_rfl).trans ((finite_compact_potential hw hell hS0 hS hr hs hsS hK N).trans + (ENNReal.ofReal_le_ofReal (potential_le hK _))) + +end NumberTheoryLean.PrimeCompactVisits + + + +namespace NumberTheoryLean.PrimeHistoryHorizon + +open _root_.Set _root_.Finset +open _root_.Erdos970.Set _root_.Erdos970.Finset +open FinitePathGeometry PrimeTiltGeometry PrimeTiltPrefixes PrimeHistories +open LowStateHorizon ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem valid_ratio_lower {i : Side} {t : ℝ} (ht : Valid i t) : (19/20 : ℝ) ≤ t := by + cases i <;> dsimp [Valid] at ht <;> linarith + +theorem prime_cost_lower {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hs : Valid i s) (hpath : PrimeAdmissible w ell S i s r cap closed ps) : + (ps.length : ℝ)/(S+1) ≤ pathCost (primeRatios w r ps) := by + classical + induction ps generalizing i s r cap closed with + | nil => simp [primeRatios,pathCost] + | cons p ps ih => + rcases hpath with ⟨hp,hrest⟩ + have ht := valid_pos (child_valid hs hp) + have htS : childRatio w r p ≤ S := (Finset.mem_filter.mp hp).2.2.2.2 + have hc : 1/(S+1) ≤ cost (childRatio w r p) := + (one_div_le_one_div_of_le (by linarith : 0 < childRatio w r p+1) (by linarith)).trans + (cost_ge_inv_add_one ht) + have hih := ih (child_valid hs hp) hrest + simp only [List.length_cons, Nat.cast_add, Nat.cast_one, add_div, primeRatios, pathCost] + linarith + +theorem prime_gap_cost {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < r) (hs : Valid i s) + (hpath : PrimeAdmissible w ell S i s r cap closed ps) : + primeFinalGap w r ps = r * Real.exp (-pathCost (primeRatios w r ps)) := by + rw [primeFinalGap_eq hell hr hs hpath, finalGap_eq_cost hs (ratios_admissible hpath)] + +theorem prime_final_gap_lower {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hell : 0 < ell) (hr : 0 < r) (hs : Valid i s) + (hpath : PrimeAdmissible w ell S i s r cap closed ps) (hne : ps ≠ []) : + (19/20 : ℝ)*ell < primeFinalGap w r ps := by + classical + induction ps generalizing i s r cap closed with + | nil => exact False.elim (hne rfl) + | cons p ps ih => + rcases hpath with ⟨hp,hrest⟩ + cases ps with + | nil => + have hx : ell < primeExponent w p := (Finset.mem_filter.mp hp).2.1 + have hx0 : 0 < primeExponent w p := hell.trans hx + have ht := valid_ratio_lower (child_valid hs hp) + have heq : r-primeExponent w p = childRatio w r p * primeExponent w p := by + unfold childRatio + field_simp + change (19/20 : ℝ)*ell < r-primeExponent w p + calc + _ < (19/20 : ℝ)*primeExponent w p := mul_lt_mul_of_pos_left hx (by norm_num) + _ ≤ childRatio w r p * primeExponent w p := mul_le_mul_of_nonneg_right ht hx0.le + _ = _ := heq.symm + | cons q qs => + exact ih (child_gap_positive hell.le hr hs hp) (child_valid hs hp) hrest (by simp) + +theorem prime_source_horizon {w ell S s r cap B : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hell : 1 ≤ ell) (hS : 0 ≤ S) (hr : 0 < r) (hs : Valid i s) + (hpath : PrimeAdmissible w ell S i s r cap closed ps) (hB : 0 < B) (hsize : r ≤ (23/10 : ℝ)*B) : + ps.length < sourceHorizon S B := by + by_cases hne : ps = [] + · subst ps + unfold sourceHorizon + simp + · have hell0 : 0 < ell := by linarith + have hgap := prime_final_gap_lower hell0 hr hs hpath hne + have hl := Real.log_lt_log (mul_pos (by norm_num : (0 : ℝ) < 19/20) hell0) hgap + rw [prime_gap_cost hell0.le hr hs hpath, + Real.log_mul hr.ne' (Real.exp_pos _).ne', Real.log_exp] at hl + have hc := prime_cost_lower hs hpath + have hlogR := Real.log_le_log hr hsize + rw [Real.log_mul (by norm_num : (23/10 : ℝ) ≠ 0) hB.ne'] at hlogR + have hlog23 : Real.log (23/10 : ℝ) ≤ 13/10 := by + have h := Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 23/10) + norm_num at h + exact h + have hlog19 : (-1/19 : ℝ) ≤ Real.log (19/20 : ℝ) := by + have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 19/20) + norm_num at h + linarith + have hlogell : Real.log (19/20 : ℝ) ≤ Real.log ((19/20 : ℝ)*ell) := + Real.log_le_log (by norm_num) (by nlinarith) + have hn : (ps.length : ℝ)/(S+1) < Real.log B+2 := by linarith + have hmul := (div_lt_iff₀ (by linarith : 0 < S+1)).mp hn + have hceil := Nat.le_ceil ((S+1)*(Real.log B+2)) + have hreal : (ps.length : ℝ) < (sourceHorizon S B : ℝ) := by + unfold sourceHorizon + push_cast + nlinarith + exact_mod_cast hreal + +theorem history_length_lt {w ell S B : ℝ} {start : Node} + (hell : 1 ≤ ell) (hS : 0 ≤ S) (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (hB : 0 < B) (hsize : start.gap ≤ (23/10 : ℝ)*B) (h : History w ell S start) : + h.primes.length < sourceHorizon S B := + prime_source_horizon hell hS hr hs h.admissible hB hsize + +end NumberTheoryLean.PrimeHistoryHorizon + + + +namespace NumberTheoryLean.PrimeChainHorizon + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeHistoryHorizon LowStateHorizon + +variable {w ell S : ℝ} {start : Node} + +def stage (n : ℕ) : ChainState w ell S start → Prop + | none => True + | some h => h.primes.length = n + +theorem stage_measurable (n : ℕ) : MeasurableSet {z : ChainState w ell S start | stage n z} := trivial + +theorem next_stage (n : ℕ) (z : ChainState w ell S start) (hz : stage n z) : + ∀ᵐ y ∂chain w ell S start z, stage (n+1) y := by + classical + cases z with + | none => + rw [chain_none] + exact (ae_dirac_iff (stage_measurable (n+1))).mpr trivial + | some h => + have hlen : h.primes.length = n := hz + apply ae_iff.mpr + simp [chain_some, completedLaw, liveLaw, stage, History.append_primes, hlen] + +theorem pathLaw_stage (n : ℕ) : ∀ᵐ z ∂pathLaw w ell S start n, stage n z := by + induction n with + | zero => + change ∀ᵐ z ∂Measure.dirac (some (History.empty : History w ell S start)), stage 0 z + exact (ae_dirac_iff (stage_measurable 0)).mpr rfl + | succ n ih => + have hp : (chain w ell S start)^(n+1) = (chain w ell S start) ∘ₖ ((chain w ell S start)^n) := pow_succ' _ _ + change ∀ᵐ z ∂((chain w ell S start)^(n+1)) (some History.empty), stage (n+1) z + rw [hp] + apply Kernel.ae_comp_of_ae_ae (stage_measurable (n+1)) + filter_upwards [ih] with z hz + exact next_stage n z hz + +theorem pathLaw_eq_cemetery {B : ℝ} (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) + (hB : 0 < B) (hsize : start.gap ≤ (23/10 : ℝ)*B) (n : ℕ) (hn : sourceHorizon S B ≤ n) : + pathLaw w ell S start n = Measure.dirac none := by + let := pathLaw_isProbability hw hell hS0 hS hr hs hsS n + have hnone : ∀ᵐ z ∂pathLaw w ell S start n, z = none := by + filter_upwards [pathLaw_stage n] with z hz + cases z with + | none => rfl + | some h => + have hlen := history_length_lt hell hS0 hr hs hB hsize h + change h.primes.length = n at hz + omega + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_dirac' _ hf] + calc + _ = ∫⁻ _z, f none ∂pathLaw w ell S start n := lintegral_congr_ae (hnone.mono (fun z hz => congrArg f hz)) + _ = _ := by rw [lintegral_const, measure_univ, mul_one] + +end NumberTheoryLean.PrimeChainHorizon + + + +namespace NumberTheoryLean.PrimeCorrectionFactor + +open _root_.Filter _root_.Set +open _root_.Erdos970.Filter _root_.Erdos970.Set +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeHistoryHorizon PrimeKilledChain LowStateHorizon + +noncomputable def correctionBudget (d w : ℝ) : ℝ := + Real.exp (5*d^3*(Real.log w)^3*epsilon w)-1 + +theorem correctionBudget_tendsto_zero (d : ℝ) : Tendsto (correctionBudget d) atTop (𝓝 0) := by + have ht : Tendsto (fun x : ℝ => 5*d^3*x^6*Real.exp (-normalizationRate*x)) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (6 : ℝ) normalizationRate normalizationRate_pos).const_mul (5*d^3) + simpa only [Real.rpow_ofNat, mul_assoc, mul_zero] using h + have hi : Tendsto (fun w : ℝ => 5*d^3*(Real.log w)^3*epsilon w) atTop (𝓝 0) := by + apply Tendsto.congr' _ (ht.comp (Real.tendsto_sqrt_atTop.comp Real.tendsto_log_atTop)) + filter_upwards [Real.tendsto_log_atTop.eventually (eventually_ge_atTop (0 : ℝ))] with w hw + have hp : (Real.sqrt (Real.log w))^6 = (Real.log w)^3 := by + calc + _ = ((Real.sqrt (Real.log w))^2)^3 := by ring + _ = _ := by rw [Real.sq_sqrt hw] + simp only [Function.comp_apply, epsilon, hp] + have h := ((Real.continuous_exp.tendsto (0 : ℝ)).comp hi).sub_const 1 + change Tendsto (fun w : ℝ => Real.exp (5*d^3*(Real.log w)^3*epsilon w)-1) atTop (𝓝 0) + simpa only [Function.comp_apply, Real.exp_zero, sub_self] using h + +theorem correction_le_budget {d w B : ℝ} (hB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) (n : ℕ) + (hn : n ≤ sourceHorizon ((Real.log B)^2) B) : + 0 ≤ (1+epsilon w)^n-1 ∧ (1+epsilon w)^n-1 ≤ correctionBudget d w := by + have hpow1 : 1 ≤ (1+epsilon w)^n := one_le_pow₀ (by linarith [epsilon_pos w]) + have hN := source_horizon_log_cube hB + have hnR : (n : ℝ) ≤ (sourceHorizon ((Real.log B)^2) B : ℝ) := by exact_mod_cast hn + have hcube : (Real.log B)^3 ≤ (d*Real.log w)^3 := pow_le_pow_left₀ (by linarith) hcomp 3 + have hnum : (n : ℝ) ≤ 5*d^3*(Real.log w)^3 := by nlinarith [hN,hnR] + have hbase : 1+epsilon w ≤ Real.exp (epsilon w) := by + simpa only [add_comm] using Real.add_one_le_exp (epsilon w) + have hp : (1+epsilon w)^n ≤ (Real.exp (epsilon w))^n := pow_le_pow_left₀ (by linarith [epsilon_pos w]) hbase n + rw [← Real.exp_nat_mul] at hp + have he : Real.exp ((n : ℝ)*epsilon w) ≤ Real.exp (5*d^3*(Real.log w)^3*epsilon w) := + Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hnum (epsilon_pos w).le) + exact ⟨sub_nonneg.mpr hpow1, sub_le_sub_right (hp.trans he) 1⟩ + +theorem history_correction {d w ell B : ℝ} {start : Node} + (hlogB : 2 ≤ Real.log B) + (hcomp : Real.log B ≤ d*Real.log w) (hell : 1 ≤ ell) (hr : 0 < start.gap) + (hs : Valid start.side start.ratio) (hB : 0 < B) (hsize : start.gap ≤ (23/10 : ℝ)*B) + (h : History w ell ((Real.log B)^2) start) : + 0 ≤ (1+epsilon w)^h.primes.length-1 ∧ + (1+epsilon w)^h.primes.length-1 ≤ correctionBudget d w := + correction_le_budget hlogB hcomp h.primes.length + (history_length_lt hell (sq_nonneg _) hr hs hB hsize h).le + +end NumberTheoryLean.PrimeCorrectionFactor + + + +namespace NumberTheoryLean.PrimeSideSupport + +open _root_.Set _root_.MeasureTheory +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open FinitePathGeometry PrimeTiltGeometry PrimeHistories PrimeKilledChain PrimeChainHorizon + +def sideAfter (i : Side) : ℕ → Side + | 0 => i + | n+1 => (sideAfter i n).flip + +theorem sideAfter_flip (i : Side) (n : ℕ) : sideAfter i.flip n = (sideAfter i n).flip := by + induction n with + | zero => rfl + | succ n ih => simp only [sideAfter,ih] + +theorem sideAfter_even (n : ℕ) : sideAfter .even (2*n) = .even := by + induction n with + | zero => rfl + | succ n ih => + rw [show 2*(n+1)=2*n+1+1 by omega,sideAfter,sideAfter,ih] + rfl + +theorem sideAfter_odd (n : ℕ) : sideAfter .even (2*n+1) = .odd := by + rw [sideAfter,sideAfter_even] + rfl + +theorem terminal_side_after (w : ℝ) (z : Node) (ps : List ℕ) : + (terminal w z ps).side = sideAfter z.side ps.length := by + induction ps generalizing z with + | nil => rfl + | cons p ps ih => + rw [terminal_cons,ih,List.length_cons,sideAfter] + exact sideAfter_flip z.side ps.length + +def regularLower : Side → ℝ | .even => 2 | .odd => 1 +noncomputable def weakLower : Side → ℝ | .even => 2 | .odd => 98/100 + +def Regular (z : Node) : Prop := regularLower z.side ≤ z.ratio +def WeakRegular (z : Node) : Prop := weakLower z.side ≤ z.ratio + +theorem regular_step {w ell S : ℝ} {z : Node} (hz : Regular z) {p : ℕ} + (hp : p ∈ nodeChildren w ell S z) : Regular (step w z p) := by + classical + have hlo := (Finset.mem_filter.mp hp).2.2.2.1 + cases hi : z.side with + | even => + change regularLower z.side ≤ z.ratio at hz + rw [hi,regularLower] at hz + change minRatio z.side z.ratio ≤ childRatio w z.gap p at hlo + rw [hi,minRatio] at hlo + change regularLower z.side.flip ≤ childRatio w z.gap p + rw [hi,Side.flip,regularLower] + linarith + | odd => + change minRatio z.side z.ratio ≤ childRatio w z.gap p at hlo + rw [hi,minRatio] at hlo + change regularLower z.side.flip ≤ childRatio w z.gap p + rw [hi,Side.flip,regularLower] + exact (le_max_left _ _).trans hlo + +theorem two_step_regular {w ell S : ℝ} {z : Node} {p q : ℕ} + (hp : p ∈ nodeChildren w ell S z) (hq : q ∈ nodeChildren w ell S (step w z p)) : + Regular (step w (step w z p) q) := by + classical + have hlo := (Finset.mem_filter.mp hp).2.2.2.1 + have hlo' := (Finset.mem_filter.mp hq).2.2.2.1 + change minRatio z.side.flip (childRatio w z.gap p) ≤ childRatio w (step w z p).gap q at hlo' + change regularLower z.side.flip.flip ≤ childRatio w (step w z p).gap q + cases hi : z.side with + | even => + rw [Side.flip,Side.flip,regularLower] + rw [hi,Side.flip,minRatio] at hlo' + exact (le_max_left _ _).trans hlo' + | odd => + rw [Side.flip,Side.flip,regularLower] + change minRatio z.side z.ratio ≤ childRatio w z.gap p at hlo + rw [hi,minRatio] at hlo + rw [hi,Side.flip,minRatio] at hlo' + linarith [le_max_left (2:ℝ) (z.ratio-1)] + +theorem terminal_regular_of_regular {w ell S : ℝ} {z : Node} {ps : List ℕ} + (hz : Regular z) (hp : allowed w ell S z ps) : Regular (terminal w z ps) := by + induction ps generalizing z with + | nil => exact hz + | cons p ps ih => + rcases (allowed_cons w ell S z p ps).mp hp with ⟨hchild,hpath⟩ + exact ih (regular_step hz hchild) hpath + +theorem terminal_regular {w ell S : ℝ} {z : Node} {ps : List ℕ} + (hp : allowed w ell S z ps) (hlen : 2 ≤ ps.length) : Regular (terminal w z ps) := by + cases ps with + | nil => simp at hlen + | cons p ps => + cases ps with + | nil => simp at hlen + | cons q qs => + rcases (allowed_cons w ell S z p (q::qs)).mp hp with ⟨hp,hrest⟩ + rcases (allowed_cons w ell S (step w z p) q qs).mp hrest with ⟨hq,hrest⟩ + change Regular (terminal w (step w (step w z p) q) qs) + exact terminal_regular_of_regular (two_step_regular hp hq) hrest + +theorem weak_step {w ell S : ℝ} {z : Node} (hz : Valid z.side z.ratio) {p : ℕ} + (hp : p ∈ nodeChildren w ell S z) : WeakRegular (step w z p) := by + classical + have hlo := (Finset.mem_filter.mp hp).2.2.2.1 + change minRatio z.side z.ratio ≤ childRatio w z.gap p at hlo + change weakLower z.side.flip ≤ childRatio w z.gap p + cases hi : z.side with + | even => + rw [hi,Valid] at hz + rw [hi,minRatio] at hlo + rw [Side.flip,weakLower] + linarith + | odd => + rw [hi,minRatio] at hlo + rw [Side.flip,weakLower] + exact (le_max_left _ _).trans hlo + +theorem terminal_weak {w ell S : ℝ} {z : Node} {ps : List ℕ} + (hz : Valid z.side z.ratio) (hp : allowed w ell S z ps) (hne : ps ≠ []) : + WeakRegular (terminal w z ps) := by + induction ps generalizing z with + | nil => exact False.elim (hne rfl) + | cons p ps ih => + rcases (allowed_cons w ell S z p ps).mp hp with ⟨hchild,hpath⟩ + cases ps with + | nil => exact weak_step hz hchild + | cons q qs => exact ih (child_valid hz hchild) hpath (by simp) + +theorem pathLaw_regular {w ell S : ℝ} {start : Node} (n : ℕ) (hn : 2 ≤ n) : + ∀ᵐ p ∂pathLaw w ell S start n, match p with + | none => True + | some h => Regular h.node := by + filter_upwards [pathLaw_stage (w:=w) (ell:=ell) (S:=S) (start:=start) n] with p hp + cases p with + | none => trivial + | some h => + have heq : h.primes.length = n := hp + exact terminal_regular h.admissible (by omega) + +theorem pathLaw_weak {w ell S : ℝ} {start : Node} (hs : Valid start.side start.ratio) + (n : ℕ) (hn : 1 ≤ n) : + ∀ᵐ p ∂pathLaw w ell S start n, match p with + | none => True + | some h => WeakRegular h.node := by + filter_upwards [pathLaw_stage (w:=w) (ell:=ell) (S:=S) (start:=start) n] with p hp + cases p with + | none => trivial + | some h => + have heq : h.primes.length = n := hp + apply terminal_weak hs h.admissible + intro he + simp [he] at heq + omega + +theorem pathLaw_side {w ell S : ℝ} {start : Node} (hi : start.side = .even) (n : ℕ) : + ∀ᵐ p ∂pathLaw w ell S start n, match p with + | none => True + | some h => h.node.side = sideAfter .even n := by + filter_upwards [pathLaw_stage (w:=w) (ell:=ell) (S:=S) (start:=start) n] with p hp + cases p with + | none => trivial + | some h => + have heq : h.primes.length = n := hp + change (terminal w start h.primes).side = _ + rw [terminal_side_after,heq,hi] + +end NumberTheoryLean.PrimeSideSupport + + + +namespace NumberTheoryLean.PrimeGridGeometry + +open _root_.Set _root_.Erdos970.Set +open FinitePathGeometry PrimeHistories PrimeSideSupport + +noncomputable def width (m : ℕ) : ℝ := 1/(m:ℝ) +noncomputable def point (m j : ℕ) : ℝ := (j:ℝ)/(m:ℝ) + +theorem width_nonneg (m : ℕ) : 0 ≤ width m := by unfold width; positivity + +theorem width_pos {m : ℕ} (hm : 1 ≤ m) : 0 < width m := by + apply one_div_pos.mpr + exact_mod_cast (show 0 < m by omega) + +theorem point_succ (m j : ℕ) : point m (j+1) = point m j+width m := by + simp only [point,width,Nat.cast_add,Nat.cast_one,add_div] + +theorem point_nonneg (m j : ℕ) : 0 ≤ point m j := div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + +theorem threshold_le_point {m : ℕ} (hm : 1 ≤ m) (k j : ℕ) : + (k:ℝ) ≤ point m j ↔ k*m ≤ j := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + rw [point,le_div_iff₀ hm0] + exact_mod_cast Iff.rfl + +theorem index_from_upper {m j k : ℕ} {t : ℝ} (hm : 1 ≤ m) + (hkt : (k:ℝ) ≤ t) (ht : t < point m (j+1)) : k*m ≤ j := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hdiv : (k:ℝ) < ((j+1:ℕ):ℝ)/(m:ℝ) := hkt.trans_lt ht + have hmul := (lt_div_iff₀ hm0).mp hdiv + have hn : k*m < j+1 := by exact_mod_cast hmul + omega + +theorem finite_grid_cover {m J : ℕ} {t : ℝ} (hm : 1 ≤ m) (ht : 0 ≤ t) + (hJ : t < point m (J+1)) : ∃ j ≤ J, t ∈ Ico (point m j) (point m (j+1)) := by + let j := ⌊t*(m:ℝ)⌋₊ + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have htm : 0 ≤ t*(m:ℝ) := mul_nonneg ht hm0.le + have hlo := Nat.floor_le htm + have hhi := Nat.lt_floor_add_one (t*(m:ℝ)) + have hbound : (j:ℝ) < ((J+1:ℕ):ℝ) := by + have h := (lt_div_iff₀ hm0).mp hJ + exact hlo.trans_lt h + have hj : j ≤ J := by + have hnat : j < J+1 := by exact_mod_cast hbound + omega + refine ⟨j,hj,?_⟩ + constructor + · exact (div_le_iff₀ hm0).mpr hlo + · apply (lt_div_iff₀ hm0).mpr + simpa only [Nat.cast_add,Nat.cast_one] using hhi + +theorem incoming_grid_end {m : ℕ} (hmN : 1 ≤ m) (j : ℕ) : + point m (j+m+2) = point m j+1+2*width m := by + have hm : (m:ℝ) ≠ 0 := by exact_mod_cast (show m ≠ 0 by omega) + unfold point width + push_cast + field_simp + +def lowerIndex (m : ℕ) : Side → ℕ | .even => 2*m | .odd => m + +theorem regular_bin_domain {m j : ℕ} {z : Node} (hm : 1 ≤ m) (hz : Regular z) + (hbin : z.ratio ∈ Ico (point m j) (point m (j+1))) : + lowerIndex m z.side ≤ j ∧ Valid z.side (point m j) := by + cases hi : z.side with + | even => + change regularLower z.side ≤ z.ratio at hz + rw [hi,regularLower] at hz + have hj := index_from_upper hm (k:=2) hz hbin.2 + have ht : (2:ℝ) ≤ point m j := by simpa only [Nat.cast_ofNat] using (threshold_le_point hm 2 j).mpr hj + rw [lowerIndex,Valid] + exact ⟨hj,by linarith⟩ + | odd => + change regularLower z.side ≤ z.ratio at hz + rw [hi,regularLower] at hz + have hj := index_from_upper hm (k:=1) (by simpa only [Nat.cast_one] using hz) hbin.2 + have ht : (1:ℝ) ≤ point m j := by simpa only [Nat.cast_one] using (threshold_le_point hm 1 j).mpr hj + rw [lowerIndex,Valid] + exact ⟨by simpa using hj,by linarith⟩ + +theorem weak_bin_domain {m j : ℕ} {z : Node} (hm : 1 ≤ m) (hsmall : width m ≤ 1/100) + (hz : WeakRegular z) (hbin : z.ratio ∈ Ico (point m j) (point m (j+1))) : + Valid z.side (point m j) := by + cases hi : z.side with + | even => + change weakLower z.side ≤ z.ratio at hz + rw [hi,weakLower] at hz + have hj := index_from_upper hm (k:=2) hz hbin.2 + have ht : (2:ℝ) ≤ point m j := by simpa only [Nat.cast_ofNat] using (threshold_le_point hm 2 j).mpr hj + rw [Valid] + linarith + | odd => + change weakLower z.side ≤ z.ratio at hz + rw [hi,weakLower] at hz + have ht := hbin.2 + rw [point_succ] at ht + rw [Valid] + linarith + +theorem child_bin_domain {w ell S : ℝ} {m j p : ℕ} {z : Node} + (hm : 1 ≤ m) (hsmall : width m ≤ 1/100) (hz : Valid z.side z.ratio) + (hp : p ∈ nodeChildren w ell S z) + (hbin : (step w z p).ratio ∈ Ico (point m j) (point m (j+1))) : + Valid z.side.flip (point m j) := + weak_bin_domain hm hsmall (weak_step hz hp) hbin + +end NumberTheoryLean.PrimeGridGeometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeHistoryCompactCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeHistoryCompactCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..a578a5bb9dccf1a18d43db5eacf3d625fc7fd784 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeHistoryCompactCount.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalCoupledHistories + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PrimeHistoryCompactCount + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeCompactVisits +open FiniteHistoryTransport ActualCoupledHistories ActualProcessCoupling PersistentFailureFlag + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +include hw hell hS0 hS hr hs hsS + +theorem pathwise_compact_potential {R : ℝ} (hR : 0 ≤ R) (N : ℕ) : + ∀ᵐ h ∂pathKernel (chain w ell S start) N (fun _ => some History.empty), + pathSum (visit R) N h + potential R (last N h) ≤ + potential R (some (History.empty : History w ell S start)) := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + have hv : Measurable (visit (w:=w) (ell:=ell) (S:=S) (start:=start) R) := measurable_of_countable _ + have hp : Measurable (potential (w:=w) (ell:=ell) (S:=S) (start:=start) R) := measurable_of_countable _ + induction N with + | zero => + change ∀ᵐ h ∂Measure.dirac (fun _ => some History.empty), _ + apply (ae_dirac_iff ((measurableSet_le + ((pathSum_measurable hv 0).add (hp.comp (last_measurable 0))) measurable_const))).mpr + simp [pathSum,last] + | succ N ih => + apply ae_pathKernel_succ _ N _ (measurableSet_le + ((pathSum_measurable hv (N+1)).add (hp.comp (last_measurable (N+1)))) measurable_const) + filter_upwards [ih] with h hh + filter_upwards [actual_row_drift_ae hell hr hs hR (last N h)] with y hy + change pathSum (visit R) (N+1) (FiniteHistoryTransport.extend N h y) + + potential R (last (N+1) (FiniteHistoryTransport.extend N h y)) ≤ _ + rw [pathSum_extend,extend_last] + linarith + +theorem pathwise_compact_count {R : ℝ} (hR : 0 ≤ R) (N : ℕ) : + ∀ᵐ h ∂pathKernel (chain w ell S start) N (fun _ => some History.empty), + pathSum (visit R) N h ≤ R+1 := by + filter_upwards [pathwise_compact_potential hw hell hS0 hS hr hs hsS hR N] with h hh + have hp := potential_nonneg hR (by linarith : 0 ≤ ell) hr hs (last N h) + have hinit := potential_le (w:=w) (ell:=ell) (S:=S) (start:=start) hR (some History.empty) + linarith + +theorem sourceHistory_compact_count {R : ℝ} (hR : 0 ≤ R) (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + pathSum (visit R) N (mapHist (fun q => q.1.1) N h) ≤ R+1 := by + have hP : MeasurableSet {h : Hist (ChainState w ell S start) N | + pathSum (visit R) N h ≤ R+1} := + measurableSet_le (pathSum_measurable (measurable_of_countable _) N) measurable_const + have hh : ∀ᵐ h ∂(sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N).map + (mapHist (fun q => q.1.1) N), pathSum (visit R) N h ≤ R+1 := by + rw [sourceHistoryLaw_prime] + exact pathwise_compact_count hw hell hS0 hS hr hs hsS hR N + exact (ae_map_iff (mapHist_measurable (by exact measurable_fst.comp measurable_fst) N).aemeasurable hP).mp hh + +end NumberTheoryLean.PrimeHistoryCompactCount + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeHitRepresentative.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeHitRepresentative.lean new file mode 100644 index 0000000000000000000000000000000000000000..d428d19a14a043ea4dcebee535f1f57fb1c32889 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeHitRepresentative.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PositiveProgression + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseHits + +theorem modEq_prime_product_iff (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) (n b : ℕ) : + Nat.ModEq (∏ p ∈ P,p) n b ↔ ∀ p ∈ P,Nat.ModEq p n b := by + classical + revert hP + induction P using Finset.induction_on with + | empty => intro _;simp [Nat.modEq_one] + | @insert p P hp ih => + intro hP + have hprime := hP p (Finset.mem_insert_self _ _) + have hrest : ∀ q ∈ P,q.Prime := fun q hq => hP q (Finset.mem_insert_of_mem hq) + have hco : p.Coprime (∏ q ∈ P,q) := by + apply Nat.Coprime.prod_right + intro q hq + exact (Nat.coprime_primes hprime (hrest q hq)).mpr (by intro heq;exact hp (heq ▸ hq)) + rw [Finset.prod_insert hp,← Nat.modEq_and_modEq_iff_modEq_mul hco,ih hrest] + simp only [Finset.forall_mem_insert] + +theorem exists_prime_hit_representative (q : ℕ) (hq : Squarefree q) (a : ℕ → ℕ) : + ∃ b : ℕ,1 ≤ b ∧ b ≤ q ∧ ∀ n : ℕ, + (∀ p ∈ q.primeFactors,n%p = a p%p) ↔ Nat.ModEq q n b := by + classical + have hq0 : 0 < q := Nat.pos_of_ne_zero hq.ne_zero + have hnz : ∀ p ∈ q.primeFactors,(id p : ℕ) ≠ 0 := + fun p hp => (Nat.prime_of_mem_primeFactors hp).ne_zero + have hpair : Set.Pairwise (q.primeFactors : Set ℕ) (fun p r => Nat.Coprime (id p) (id r)) := by + intro p hp r hr hpr + exact (Nat.coprime_primes (Nat.prime_of_mem_primeFactors hp) + (Nat.prime_of_mem_primeFactors hr)).mpr hpr + let c := Nat.chineseRemainderOfFinset a id q.primeFactors hnz hpair + have hcq : c.val < q := by + have hh := Nat.chineseRemainderOfFinset_lt_prod a id hnz hpair + simpa only [id_eq,Nat.prod_primeFactors_of_squarefree hq] using hh + have hbp : ∃ b : ℕ,1 ≤ b ∧ b ≤ q ∧ ∀ p ∈ q.primeFactors,Nat.ModEq p b (a p) := by + by_cases hc : c.val = 0 + · refine ⟨q,hq0,le_rfl,?_⟩ + intro p hp + have hd : p ∣ q := Nat.dvd_of_mem_primeFactors hp + have ht := c.property p hp + change Nat.ModEq p c.val (a p) at ht + rw [hc] at ht + exact hd.modEq_zero_nat.trans ht + · exact ⟨c.val,by omega,hcq.le,c.property⟩ + obtain ⟨b,hb1,hbq,hbp⟩ := hbp + refine ⟨b,hb1,hbq,?_⟩ + intro n + have hprod := modEq_prime_product_iff q.primeFactors (fun p hp => Nat.prime_of_mem_primeFactors hp) n b + rw [Nat.prod_primeFactors_of_squarefree hq] at hprod + rw [hprod] + constructor + · intro hn p hp + exact (show Nat.ModEq p n (a p) from hn p hp).trans (hbp p hp).symm + · intro hn p hp + exact (hn p hp).trans (hbp p hp) + +noncomputable def primeHitRepresentative (q : ℕ) (hq : Squarefree q) (a : ℕ → ℕ) : ℕ := + (exists_prime_hit_representative q hq a).choose + +theorem primeHitRepresentative_spec (q : ℕ) (hq : Squarefree q) (a : ℕ → ℕ) : + 1 ≤ primeHitRepresentative q hq a ∧ primeHitRepresentative q hq a ≤ q ∧ + ∀ n : ℕ,(∀ p ∈ q.primeFactors,n%p = a p%p) ↔ Nat.ModEq q n (primeHitRepresentative q hq a) := + (exists_prime_hit_representative q hq a).choose_spec + +end ErdosInverseHits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeIntervalFlags.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeIntervalFlags.lean new file mode 100644 index 0000000000000000000000000000000000000000..1499bf8da0d9b4f0292bd93287aaa5caf97dc0ea --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeIntervalFlags.lean @@ -0,0 +1,369 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.LargeModulusSiegelWalfisz + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Finset _root_.MeasureTheory +open scoped Topology +open ErdosPrimeInputs.PrimeCountAbel (logarithmicIntegral) + +lemma intervalPrimes_eq_sdiff {u v : ℝ} (hu : 0 ≤ u) (q : ℕ) (r : ℤ) : + intervalPrimes u (v-u) q r = intervalPrimes 0 v q r \ intervalPrimes 0 u q r := by + ext p + simp only [mem_sdiff,mem_intervalPrimes,zero_add,add_sub_cancel] + constructor + · rintro ⟨hp,hlo,hhi,hm⟩ + refine ⟨⟨hp,by linarith,hhi,hm⟩,?_⟩ + rintro ⟨_,_,hpu,_⟩ + linarith + · rintro ⟨⟨hp,h0,hhi,hm⟩,hnot⟩ + refine ⟨hp,?_,hhi,hm⟩ + by_contra h + exact hnot ⟨hp,h0,le_of_not_gt h,hm⟩ + +lemma intervalPrimes_count_sub {u v : ℝ} (hu : 0 ≤ u) (huv : u ≤ v) (q : ℕ) (r : ℤ) : + ((intervalPrimes u (v-u) q r).card:ℝ) = + ((intervalPrimes 0 v q r).card:ℝ)-((intervalPrimes 0 u q r).card:ℝ) := by + have hs : intervalPrimes 0 u q r ⊆ intervalPrimes 0 v q r := by + intro p hp + obtain ⟨hpr,h0,hpu,hm⟩ := (mem_intervalPrimes _ _ _ _ _).mp hp + exact (mem_intervalPrimes _ _ _ _ _).mpr ⟨hpr,h0,by linarith,hm⟩ + rw [intervalPrimes_eq_sdiff hu,card_sdiff_of_subset hs,Nat.cast_sub (card_le_card hs)] + +lemma inv_log_intervalIntegrable {u v : ℝ} (hu : 2 ≤ u) (huv : u ≤ v) : + IntervalIntegrable (fun t:ℝ => 1/Real.log t) volume u v := by + apply ContinuousOn.intervalIntegrable_of_Icc huv + intro t ht + have ht0 : t ≠ 0 := by linarith [ht.1] + have hl0 : Real.log t ≠ 0 := (Real.log_pos (by linarith [ht.1])).ne' + exact ContinuousAt.continuousWithinAt (by fun_prop) + +lemma logarithmicIntegral_sub {u v : ℝ} (hu : 2 ≤ u) (huv : u ≤ v) : + logarithmicIntegral v-logarithmicIntegral u = ∫ t in u..v, 1/Real.log t := by + have h := intervalIntegral.integral_add_adjacent_intervals + (inv_log_intervalIntegrable (by norm_num) hu) (inv_log_intervalIntegrable hu huv) + unfold logarithmicIntegral + linarith + +lemma logarithmicIntegral_sub_lower {u v : ℝ} (hu : 2 ≤ u) (huv : u ≤ v) : + (v-u)/Real.log v ≤ logarithmicIntegral v-logarithmicIntegral u := by + have hv1 : 1 < v := by linarith + rw [logarithmicIntegral_sub hu huv] + calc + _ = ∫ _t in u..v, 1/Real.log v := by simp; ring + _ ≤ _ := intervalIntegral.integral_mono_on huv (by simp) + (inv_log_intervalIntegrable hu huv) (fun t ht => by + have ht1 : 1 < t := by linarith [ht.1] + have hl : Real.log t ≤ Real.log v := Real.log_le_log (by linarith) ht.2 + exact one_div_le_one_div_of_le (Real.log_pos ht1) hl) + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology +open ErdosPrimeInputs.PrimeCountAbel (logarithmicIntegral) + +lemma ordinary_prime_count_exponential : + ∃ c C X₀ : ℝ, 0 < c ∧ 0 < C ∧ 3 ≤ X₀ ∧ ∀ X : ℝ, X₀ ≤ X → + |((intervalPrimes 0 X 1 0).card:ℝ)-logarithmicIntegral X| ≤ + C*X*Real.exp (-c*cubeHeight X) := by + obtain ⟨c,C,X0,hc,hC,hX0,h⟩ := large_modulus_siegel_walfisz + refine ⟨c,C,X0,hc,hC,hX0,?_⟩ + intro X hX + have hx1 : 1 < X := by linarith + have hq : (1:ℝ) ≤ Real.exp (c*cubeHeight X) := + Real.one_le_exp_iff.mpr (mul_nonneg hc.le (cubeHeight_pos hx1).le) + have he := h X hX 1 0 (by norm_num) (by norm_num) (by simpa only [Nat.cast_one,cubeHeight] using! hq) + simpa only [Nat.totient_one,Nat.cast_one,div_one,cubeHeight] using! he + +lemma prime_interval_lower_of_errors {c C u v : ℝ} (hc : 0 ≤ c) (hC : 0 ≤ C) + (hu : 2 ≤ u) (huv : u ≤ v) + (heU : |((intervalPrimes 0 u 1 0).card:ℝ)-logarithmicIntegral u| ≤ C*u*Real.exp (-c*cubeHeight u)) + (heV : |((intervalPrimes 0 v 1 0).card:ℝ)-logarithmicIntegral v| ≤ C*v*Real.exp (-c*cubeHeight v)) : + (v-u)/Real.log v-2*C*v*Real.exp (-c*cubeHeight u) ≤ + ((intervalPrimes u (v-u) 1 0).card:ℝ) := by + have hu0 : 0 ≤ u := by linarith + have hv0 : 0 ≤ v := hu0.trans huv + have hh := cubeHeight_mono (by linarith : 1 Real.exp (K*(Real.log w)^3)) atTop atTop := + Real.tendsto_exp_atTop.comp + (Filter.Tendsto.const_mul_atTop hK ((tendsto_pow_atTop (by decide : (3:ℕ)≠0)).comp Real.tendsto_log_atTop)) + +lemma cubeHeight_lower_of_exp_cube {R w u : ℝ} (hR : 0 < R) (hw : 1 < w) (hu : 1 ≤ u) + (hbound : Real.exp (R^3*(Real.log w)^3) ≤ u) : + R*Real.log w ≤ cubeHeight u := by + have hlogw : 0 < Real.log w := Real.log_pos hw + have hlog : R^3*(Real.log w)^3 ≤ Real.log u := by + have h := Real.log_le_log (Real.exp_pos _) hbound + simpa only [Real.log_exp] using h + apply (pow_le_pow_iff_left₀ (mul_nonneg hR.le hlogw.le) + (Real.rpow_nonneg (Real.log_nonneg hu) _) (by decide : (3:ℕ)≠0)).mp + change (R*Real.log w)^3 ≤ (cubeHeight u)^3 + rw [cubeHeight_pow_three hu,mul_pow] + exact hlog + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma moving_prime_interval_error_budget {c C D R L eps w u v : ℝ} + (hc : 0 < c) (hC : 0 ≤ C) (hR : 0 < R) (heps : 0 < eps) + (hRate : c*R=D+3) (hw : 3 ≤ w) (hu : 2 ≤ u) (huv : u ≤ v) + (hlo : Real.exp (R^3*(Real.log w)^3) ≤ u) + (hhi : v ≤ Real.exp (L*(Real.log w)^3)) + (hlen : v/w^D ≤ v-u) + (hpoly : 2*C*L*(Real.log w)^3 ≤ eps*w^3) : + 2*C*v*Real.exp (-c*cubeHeight u) ≤ eps*(v-u)/Real.log v := by + have hw0 : 0 < w := by linarith + have hu0 : 0 < u := by linarith + have hv0 : 0 < v := hu0.trans_le huv + have hlogv : 0 < Real.log v := Real.log_pos (by linarith) + have hh := cubeHeight_lower_of_exp_cube hR (by linarith) (by linarith) hlo + have hrate : (D+3)*Real.log w ≤ c*cubeHeight u := by + have he := mul_le_mul_of_nonneg_left hh hc.le + rw [← mul_assoc,hRate] at he + exact he + have hlogupper : Real.log v ≤ L*(Real.log w)^3 := by + have he := Real.log_le_log hv0 hhi + simpa only [Real.log_exp] using he + let W : ℝ := w^D + let Z : ℝ := w^3 + let decay : ℝ := Real.exp (-c*cubeHeight u) + have hW : 0 < W := Real.rpow_pos_of_pos hw0 _ + have hZ : 0 < Z := pow_pos hw0 _ + have hdecay : 0 < decay := Real.exp_pos _ + have hpower : W*Z = Real.exp ((D+3)*Real.log w) := by + dsimp [W,Z] + rw [← Real.rpow_natCast w 3,← Real.rpow_add hw0,Real.rpow_def_of_pos hw0] + congr 1 + push_cast + ring + have hcancel : decay*W*Z ≤ 1 := by + rw [mul_assoc,hpower] + dsimp [decay] + rw [← Real.exp_add] + exact Real.exp_le_one_iff.mpr (by linarith) + have hlen' : v ≤ (v-u)*W := (div_le_iff₀ hW).mp hlen + have hbound : ((2*C*v*decay)*Real.log v)*W ≤ (eps*(v-u))*W := by + calc + _ = (2*C*Real.log v)*(v*decay*W) := by ring + _ ≤ (2*C*(L*(Real.log w)^3))*(v*decay*W) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hlogupper (by positivity)) (by positivity) + _ = (2*C*L*(Real.log w)^3)*(v*decay*W) := by ring + _ ≤ (eps*Z)*(v*decay*W) := mul_le_mul_of_nonneg_right hpoly (by positivity) + _ = (eps*v)*(decay*W*Z) := by ring + _ ≤ eps*v := by simpa only [mul_one] using mul_le_mul_of_nonneg_left hcancel (by positivity : 0≤eps*v) + _ ≤ eps*((v-u)*W) := mul_le_mul_of_nonneg_left hlen' heps.le + _ = _ := by ring + apply (le_div_iff₀ hlogv).mpr + exact le_of_mul_le_mul_right hbound hW + +lemma eventually_interval_polynomial_budget {C L eps : ℝ} (heps : 0 < eps) : + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ 2*C*L*(Real.log w)^3 ≤ eps*w^3 := by + filter_upwards [eventually_ge_atTop (3:ℝ), + Real.tendsto_log_atTop.eventually + (eventually_polynomial_le_exp (2*C*L/eps) 3 (by norm_num : (0:ℝ)<1))] + with w hw hp + have hw0 : 0 < w := by linarith + have hfirst : 2*C*L*(Real.log w)^3 ≤ eps*w := by + have he := mul_le_mul_of_nonneg_right hp.2 heps.le + rw [one_mul,Real.exp_log hw0] at he + calc + _ = ((2*C*L/eps)*(Real.log w)^3)*eps := by field_simp + _ ≤ w*eps := he + _ = _ := mul_comm _ _ + have hw3 : w ≤ w^3 := by nlinarith [sq_nonneg (w-1)] + exact ⟨hw,hfirst.trans (mul_le_mul_of_nonneg_left hw3 heps.le)⟩ + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +theorem moving_prime_interval_lower (D : ℝ) (hD : 0 < D) : + ∃ K : ℝ, 0 < K ∧ ∀ L : ℝ, 0 < L → ∀ eps : ℝ, 0 < eps → + ∃ w₀ : ℝ, 3 ≤ w₀ ∧ ∀ w : ℝ, w₀ ≤ w → ∀ u v : ℝ, u ≤ v → + Real.exp (K*(Real.log w)^3) ≤ u → v ≤ Real.exp (L*(Real.log w)^3) → + v/w^D ≤ v-u → + (1-eps)*(v-u)/Real.log v ≤ ((intervalPrimes u (v-u) 1 0).card:ℝ) := by + obtain ⟨c,C,X0,hc,hC,hX0,hcount⟩ := ordinary_prime_count_exponential + let R : ℝ := (D+3)/c + let K : ℝ := R^3 + have hR : 0 < R := by dsimp [R]; positivity + have hK : 0 < K := pow_pos hR _ + have hRate : c*R=D+3 := by dsimp [R]; field_simp + refine ⟨K,hK,?_⟩ + intro L _hL eps heps + have hev : ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ u v : ℝ, u ≤ v → + Real.exp (K*(Real.log w)^3) ≤ u → v ≤ Real.exp (L*(Real.log w)^3) → + v/w^D ≤ v-u → + (1-eps)*(v-u)/Real.log v ≤ ((intervalPrimes u (v-u) 1 0).card:ℝ) := by + filter_upwards [eventually_interval_polynomial_budget (C:=C) (L:=L) heps, + (exponential_log_cube_tendsto hK).eventually (eventually_ge_atTop X0)] + with w hpoly hlarge + refine ⟨hpoly.1,?_⟩ + intro u v huv hlo hhi hlen + have hXu : X0 ≤ u := hlarge.trans hlo + have hXv : X0 ≤ v := hXu.trans huv + have hu2 : 2 ≤ u := by linarith + have herr := moving_prime_interval_error_budget hc hC.le hR heps hRate hpoly.1 hu2 huv hlo hhi hlen hpoly.2 + have hlower := prime_interval_lower_of_errors hc.le hC.le hu2 huv (hcount u hXu) (hcount v hXv) + calc + _ = (v-u)/Real.log v-eps*(v-u)/Real.log v := by ring + _ ≤ (v-u)/Real.log v-2*C*v*Real.exp (-c*cubeHeight u) := sub_le_sub_left herr _ + _ ≤ _ := hlower + obtain ⟨b,hb⟩ := eventually_atTop.mp hev + refine ⟨max 3 b,le_max_left _ _,?_⟩ + intro w hw u v huv hlo hhi hlen + exact (hb w ((le_max_right _ _).trans hw)).2 u v huv hlo hhi hlen + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Finset +open scoped Topology + +noncomputable def primeIntervalFlags (includeLower includeUpper : Bool) (u v : ℝ) : Finset ℕ := + (range (⌊max v 0⌋₊+1)).filter (fun p:ℕ => p.Prime ∧ + (if includeLower then u ≤ (p:ℝ) else u < (p:ℝ)) ∧ + (if includeUpper then (p:ℝ) ≤ v else (p:ℝ) < v)) + +lemma mem_primeIntervalFlags (includeLower includeUpper : Bool) (u v : ℝ) (p : ℕ) : + p ∈ primeIntervalFlags includeLower includeUpper u v ↔ p.Prime ∧ + (if includeLower then u ≤ (p:ℝ) else u < (p:ℝ)) ∧ + (if includeUpper then (p:ℝ) ≤ v else (p:ℝ) < v) := by + constructor + · intro hp + exact (mem_filter.mp hp).2 + · intro hp + have hv : (p:ℝ) ≤ v := by + cases includeUpper + · exact (show (p:ℝ) heq he.symm) + · have hv : (p:ℝ) ≤ v := by + cases includeUpper + · exact (show (p:ℝ) 0 + | some h => ENNReal.ofReal (1/weight h.node.side h.node.ratio) + +noncomputable def inverseBin (w ell S : ℝ) (start : Node) (m n j : ℕ) : ℝ≥0∞ := + ∫⁻ z in bin m j,inverseWeight z ∂pathLaw w ell S start n + +theorem actual_inverse_bin_local : ∃ L : ℝ,0 < L ∧ + ∀ w ell S : ℝ,3 ≤ S → ∀ start : Node, + Valid start.side start.ratio → start.side = .even → start.ratio ≤ S → + ∀ m n j : ℕ,Valid (sideAfter .even n) (point m j) → + inverseBin w ell S start m n j ≤ + ENNReal.ofReal (Real.exp (L*(1+S)^3*width m)/weight (sideAfter .even n) (point m j))* + mass w ell S start m n j := by + obtain ⟨L,hL,hlocal⟩ := weight_local_ratio + refine ⟨L,hL,?_⟩ + intro w ell S hS start hs hi hsS m n j hj + let c := Real.exp (L*(1+S)^3*width m)/weight (sideAfter .even n) (point m j) + have hpoint : ∀ᵐ z ∂(pathLaw w ell S start n).restrict (bin m j),inverseWeight z ≤ ENNReal.ofReal c := by + filter_upwards [ae_restrict_of_ae (pathLaw_side hi n),ae_restrict_mem (bin_measurable m j)] with z hz hbin + cases z with + | none => exact False.elim hbin + | some h => + have hcell := (mem_bin h m j).mp hbin + have hgv : Valid h.node.side h.node.ratio := terminal_valid hs h.admissible + have hgS : h.node.ratio ≤ S := terminal_ratio_le hsS h.admissible + have hj' : Valid h.node.side (point m j) := by rwa [hz] + have hlast : h.node.ratio ≤ point m j+width m := by + rw [point_succ] at hcell + exact hcell.2.le + have hr := hlocal S hS h.node.side (point m j) h.node.ratio (width m) hj' hgv hgS hcell.1 hlast + have hratio : 1/weight h.node.side h.node.ratio ≤ + Real.exp (L*(1+S)^3*width m)/weight h.node.side (point m j) := by + have heq : 1/weight h.node.side h.node.ratio = + (weight h.node.side (point m j)/weight h.node.side h.node.ratio)/weight h.node.side (point m j) := by + field_simp [(weight_pos hj').ne'] + rw [heq] + exact div_le_div_of_nonneg_right hr (weight_pos hj').le + change ENNReal.ofReal (1/weight h.node.side h.node.ratio) ≤ _ + apply ENNReal.ofReal_le_ofReal + simpa only [c,hz] using hratio + calc + _ ≤ ∫⁻ _z in bin m j,ENNReal.ofReal c ∂pathLaw w ell S start n := lintegral_mono_ae hpoint + _ = _ := by rw [setLIntegral_const]; rfl + +theorem cancel_inverse_bin {C E F : ℝ} {m n j : ℕ} + (hE : 0 ≤ E) + (hj : Valid (sideAfter .even n) (point m j)) + (hlocal : inverseBin w ell S start m n j ≤ + ENNReal.ofReal (E/weight (sideAfter .even n) (point m j))*mass w ell S start m n j) + (hmass : mass w ell S start m n j ≤ + ENNReal.ofReal (C*width m*weight (sideAfter .even n) (point m j)*F)) : + inverseBin w ell S start m n j ≤ ENNReal.ofReal (E*C*width m*F) := by + have hφ := weight_pos hj + have hw := width_nonneg m + refine hlocal.trans ((mul_le_mul_of_nonneg_left hmass zero_le).trans ?_) + rw [← ENNReal.ofReal_mul (div_nonneg hE hφ.le)] + apply le_of_eq + congr 1 + field_simp + +theorem profile_le_nineteen {m : ℕ} {i : Side} {t : ℝ} + (hm : width m ≤ 1) (ht : regularLower i ≤ t) : profile m i t ≤ 19 := by + cases i with + | even => norm_num [profile] + | odd => + have ht1 : 1 ≤ t := ht + have hW := W_le_six (by linarith : (1:ℝ)/2 ≤ t) + have hW0 := (WeightFutureIntegrals.W_pos (by linarith : 0 < t)).le + have hw := width_nonneg m + have hh : width m*W t ≤ 6 := + (mul_le_mul hm hW hW0 zero_le_one).trans_eq (one_mul 6) + have hinv : 0 ≤ 1/t^2 := by positivity + change 1-1/t^2+3*width m*W t ≤ 19 + nlinarith + +end NumberTheoryLean.PrimeInverseBins + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeLaw.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0d4faa5409c92db9c52dc93915613e084bdc0be --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeLaw.lean @@ -0,0 +1,195 @@ +import Mathlib.Analysis.Normed.Ring.InfiniteSum +import Mathlib.Analysis.SpecialFunctions.Log.Basic +import Mathlib.Analysis.SpecificLimits.Basic +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace EulerPrimeLaw + +noncomputable def incrementProbability (p : ℝ) : ℝ := 1 / (p - 1) ^ 2 +noncomputable def geometricMass (p : ℝ) (j : ℕ) : ℝ := (1 - 1 / p) * (1 / p) ^ j +noncomputable def bernoulliMass (p : ℝ) (b : Bool) : ℝ := + if b then incrementProbability p else 1 - incrementProbability p +noncomputable def eulerMass (p : ℝ) : ℕ → ℝ + | 0 => (p - 2) / (p - 1) + | j + 1 => (1 / p) ^ (j + 1) + +abbrev Sample := Bool × ℕ +noncomputable def jointMass (p : ℝ) (s : Sample) : ℝ := + bernoulliMass p s.1 * geometricMass p s.2 +def lowerExponent (s : Sample) : ℕ := s.2 +def upperExponent (s : Sample) : ℕ := s.2 + if s.1 then 1 else 0 + +variable {p : ℝ} (hp : 2 ≤ p) +include hp + +lemma reciprocal_nonneg : 0 ≤ 1 / p := by positivity +lemma reciprocal_lt_one : 1 / p < 1 := (div_lt_one (by linarith)).2 (by linarith) +omit hp in +lemma incrementProbability_nonneg : 0 ≤ incrementProbability p := by + unfold incrementProbability + positivity +lemma incrementProbability_le_one : incrementProbability p ≤ 1 := by + have h : 1 ≤ (p - 1) ^ 2 := by nlinarith + exact (div_le_one (by positivity : 0 < (p - 1) ^ 2)).2 h + +lemma geometricMass_nonneg (j : ℕ) : 0 ≤ geometricMass p j := + mul_nonneg (sub_nonneg.mpr (reciprocal_lt_one hp).le) + (pow_nonneg (reciprocal_nonneg hp) j) +lemma bernoulliMass_nonneg (b : Bool) : 0 ≤ bernoulliMass p b := by + cases b <;> simp only [bernoulliMass, Bool.false_eq_true, ↓reduceIte] + · exact sub_nonneg.mpr (incrementProbability_le_one hp) + · exact incrementProbability_nonneg (p := p) +lemma jointMass_nonneg (s : Sample) : 0 ≤ jointMass p s := + mul_nonneg (bernoulliMass_nonneg hp s.1) (geometricMass_nonneg hp s.2) +lemma eulerMass_nonneg (j : ℕ) : 0 ≤ eulerMass p j := by + cases j with + | zero => exact div_nonneg (by linarith) (by linarith) + | succ j => exact pow_nonneg (reciprocal_nonneg hp) _ + +theorem geometricMass_hasSum : HasSum (geometricMass p) 1 := by + have h := (hasSum_geometric_of_lt_one (reciprocal_nonneg hp) + (reciprocal_lt_one hp)).mul_left (1 - 1 / p) + change HasSum (fun j : ℕ => (1 - 1 / p) * (1 / p) ^ j) 1 + convert! h using 1 + exact (mul_inv_cancel₀ (ne_of_gt (sub_pos.mpr (reciprocal_lt_one hp)))).symm + +omit hp in +lemma bernoulliMass_hasSum : HasSum (bernoulliMass p) 1 := by + convert hasSum_fintype (bernoulliMass p) using 1 + simp [bernoulliMass] + +lemma jointMass_summable : Summable (jointMass p) := + (bernoulliMass_hasSum (p := p)).summable.mul_of_nonneg + (geometricMass_hasSum hp).summable (bernoulliMass_nonneg hp) (geometricMass_nonneg hp) + +theorem jointMass_hasSum : HasSum (jointMass p) 1 := by + apply (jointMass_summable hp).hasSum_iff.mpr + rw [(jointMass_summable hp).tsum_prod] + simp only [jointMass, tsum_mul_left, (geometricMass_hasSum hp).tsum_eq, mul_one] + exact (bernoulliMass_hasSum (p := p)).tsum_eq + +lemma event_summable (A : Sample → Prop) [DecidablePred A] : + Summable (fun s => if A s then jointMass p s else 0) := by + apply (jointMass_summable hp).of_nonneg_of_le + · intro s; split_ifs <;> simp_all only [le_refl, jointMass_nonneg hp] + · intro s; split_ifs <;> simp_all only [le_refl, jointMass_nonneg hp] + +theorem lowerExponent_marginal (j : ℕ) : + (∑' s : Sample, if lowerExponent s = j then jointMass p s else 0) = + geometricMass p j := by + rw [(event_summable hp (fun s => lowerExponent s = j)).tsum_prod] + simp only [lowerExponent, jointMass, tsum_ite_eq, tsum_fintype, Fintype.sum_bool, + bernoulliMass, Bool.false_eq_true, ↓reduceIte] + ring + +lemma zero_convolution : bernoulliMass p false * geometricMass p 0 = eulerMass p 0 := by + have hp0 : p ≠ 0 := by linarith + have hp1 : p - 1 ≠ 0 := by linarith + simp only [bernoulliMass, Bool.false_eq_true, ↓reduceIte, incrementProbability, + geometricMass, pow_zero, mul_one, eulerMass] + field_simp + ring + +lemma succ_convolution (j : ℕ) : + bernoulliMass p false * geometricMass p (j + 1) + + bernoulliMass p true * geometricMass p j = eulerMass p (j + 1) := by + have hp0 : p ≠ 0 := by linarith + have hp1 : p - 1 ≠ 0 := by linarith + simp only [bernoulliMass, Bool.false_eq_true, ↓reduceIte, incrementProbability, + geometricMass, eulerMass, pow_succ] + field_simp + ring + +theorem upperExponent_marginal (j : ℕ) : + (∑' s : Sample, if upperExponent s = j then jointMass p s else 0) = eulerMass p j := by + rw [(event_summable hp (fun s => upperExponent s = j)).tsum_prod] + simp only [tsum_fintype, Fintype.sum_bool, upperExponent, jointMass, Bool.false_eq_true, ↓reduceIte, + Nat.add_zero] + cases j with + | zero => + simp only [Nat.add_eq_zero_iff, one_ne_zero, and_false, ↓reduceIte, + tsum_zero, zero_add, tsum_ite_eq] + exact zero_convolution hp + | succ j => + simp only [Nat.add_left_inj, tsum_ite_eq] + simpa only [add_comm] using succ_convolution hp j + +theorem eulerMass_hasSum : HasSum (eulerMass p) 1 := by + have ht : HasSum (fun j : ℕ => eulerMass p (j + 1)) + ((1 - 1 / p)⁻¹ * (1 / p)) := by + simpa only [eulerMass, pow_succ] using + (hasSum_geometric_of_lt_one (reciprocal_nonneg hp) + (reciprocal_lt_one hp)).mul_right (1 / p) + have h := (hasSum_nat_add_iff 1).mp ht + convert! h using 1 + have hp0 : p ≠ 0 := by linarith + have hp1 : p - 1 ≠ 0 := by linarith + simp only [Finset.sum_range_one, eulerMass] + field_simp + ring + +theorem bernoulli_marginal (b : Bool) : + (∑' s : Sample, if s.1 = b then jointMass p s else 0) = bernoulliMass p b := by + rw [(event_summable hp (fun s => s.1 = b)).tsum_prod] + have hi (a : Bool) : + (∑' j : ℕ, if a = b then jointMass p (a, j) else 0) = + if a = b then bernoulliMass p a else 0 := by + split_ifs with h + · simp only [jointMass, tsum_mul_left, (geometricMass_hasSum hp).tsum_eq, mul_one] + · simp only [tsum_zero] + simp only [hi, tsum_ite_eq] + +omit hp in + +lemma weighted_log_excess (s : Sample) : + jointMass p s * ((upperExponent s - lowerExponent s : ℕ) : ℝ) * Real.log p = + (bernoulliMass p s.1 * (if s.1 then Real.log p else 0)) * geometricMass p s.2 := by + rcases s with ⟨b, j⟩ + cases b <;> simp [jointMass, upperExponent, lowerExponent, mul_comm, mul_assoc] + +lemma log_excess_summable : Summable (fun s : Sample => + jointMass p s * ((upperExponent s - lowerExponent s : ℕ) : ℝ) * Real.log p) := by + have hb : ∀ b : Bool, 0 ≤ bernoulliMass p b * (if b then Real.log p else 0) := by + intro b + apply mul_nonneg (bernoulliMass_nonneg hp b) + split_ifs + · exact Real.log_nonneg (by linarith) + · rfl + have h := (hasSum_fintype (fun b : Bool => + bernoulliMass p b * (if b then Real.log p else 0))).summable.mul_of_nonneg + (geometricMass_hasSum hp).summable hb (geometricMass_nonneg hp) + exact h.congr (fun s => (weighted_log_excess s).symm) + +theorem expected_log_excess : + (∑' s : Sample, jointMass p s * + ((upperExponent s - lowerExponent s : ℕ) : ℝ) * Real.log p) = + Real.log p / (p - 1) ^ 2 := by + rw [(log_excess_summable hp).tsum_prod] + simp only [weighted_log_excess, tsum_mul_left, (geometricMass_hasSum hp).tsum_eq, + mul_one, tsum_fintype, Fintype.sum_bool, bernoulliMass, Bool.false_eq_true, + ↓reduceIte, mul_zero, add_zero, incrementProbability] + ring + +omit hp in + +theorem lowerExponent_le_upperExponent (s : Sample) : lowerExponent s ≤ upperExponent s := by + exact Nat.le_add_right _ _ + +omit hp in + +theorem at_two : eulerMass 2 0 = 0 ∧ bernoulliMass 2 false = 0 ∧ bernoulliMass 2 true = 1 := by + norm_num [eulerMass, bernoulliMass, incrementProbability] + +end EulerPrimeLaw + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeMarginalInduction.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeMarginalInduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..078712d354b61889954d762ad2618296af9ad597 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeMarginalInduction.lean @@ -0,0 +1,104 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.MarginalTransport +import OAI.NumberTheory.Jacobsthal.Partitions.SourceParentBin + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + + +namespace NumberTheoryLean.PrimeMarginalInduction + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeSideSupport PrimeGridGeometry PrimeGridKernel +open PrimeMarginalRecursion MarginalProfiles MarginalTransport SourceParentBin ExponentialMesh DerivativeWeights + +theorem finite_marginal_profiles : ∃ κ₀ L : ℝ, 0 < κ₀ ∧ 0 < L ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∃ w₀ : ℝ, 1 < w₀ ∧ ∀ w : ℝ, w₀ ≤ w → + ∀ ell S : ℝ, 3 ≤ S → S ≤ (Real.log w)^3 → ∀ start : Node, + 1 ≤ ell → 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + ∀ m : ℕ, 1 ≤ m → width m = mesh κ w → width m ≤ 1/100 → + (∀ n,IsProbabilityMeasure (pathLaw w ell S start n)) ∧ + (∀ j,Valid .odd (point m j) → mass w ell S start m 1 j ≤ + ENNReal.ofReal (initialConstant*MarginalGrowth.factor L κ w S*width m*W (point m j)*weight .odd (point m j))) ∧ + (∀ n,2 ≤ n → ∀ j,lowerIndex m (sideAfter .even n) ≤ j → mass w ell S start m n j ≤ + ENNReal.ofReal ((24*initialConstant)*(MarginalGrowth.factor L κ w S)^n*width m* + weight (sideAfter .even n) (point m j)*profile m (sideAfter .even n) (point m j))) := by + obtain ⟨κ₀,L,hκ₀,hL,hcovered⟩ := covered_recursion + refine ⟨κ₀,L,hκ₀,hL,?_⟩ + intro κ hκ hκle + obtain ⟨wR,hwR,hrec⟩ := hcovered κ hκ hκle + refine ⟨max wR normalizationThreshold,hwR.trans_le (le_max_left _ _),?_⟩ + intro w hw ell S hS3 hS start hell hr hi h199 h23 m hm hmesh hsmall + have hwR' := (le_max_left _ _).trans hw + have hnorm := (le_max_right _ _).trans hw + have hs : Valid start.side start.ratio := by rw [hi,Valid]; linarith + have hsS : start.ratio ≤ S := by linarith + have hC0 := initialConstant_pos.le + have hg := (MarginalGrowth.factor_pos L κ w S).le + have hwidth := width_nonneg m + refine ⟨fun n => pathLaw_isProbability hnorm hell (by linarith) hS hr hs hsS n,?_⟩ + have hfirst : ∀ j,Valid .odd (point m j) → mass w ell S start m 1 j ≤ + ENNReal.ofReal (initialConstant*MarginalGrowth.factor L κ w S*width m*W (point m j)*weight .odd (point m j)) := by + intro j hjV + by_cases hjS : point m j ≤ S + · have hbase := hrec w hwR' ell S hS3 hS start hell hr hs hsS m 0 j hm hmesh .even {index m start} + hjV hjS (source_coverage hm hsmall hi h199 j) + rw [Finset.sum_singleton,source_grid_mass hm (by linarith : 0 ≤ start.ratio),mul_one] at hbase + have hInv := source_inverse_weight hm hsmall start h199 h23 + have hkV := source_left_valid hm hsmall start h199 + have hWt := (WeightFutureIntegrals.W_pos (valid_pos hjV)).le + have hφ := (weight_pos hjV).le + have hFactor : 0 ≤ width m*W (point m j)*weight .odd (point m j) := by positivity + refine hbase.trans (ENNReal.ofReal_le_ofReal ?_) + calc + _ = (rowFactor L κ w S*(width m*W (point m j)*weight .odd (point m j)))* + (1/weight .even (point m (index m start))) := by unfold entry rowFactor; simp only [Side.flip]; ring + _ ≤ (MarginalGrowth.factor L κ w S*(width m*W (point m j)*weight .odd (point m j)))*initialConstant := + mul_le_mul (mul_le_mul_of_nonneg_right (row_le_factor L κ w S) hFactor) hInv + (one_div_nonneg.mpr (weight_pos hkV).le) (by positivity) + _ = _ := by ring + · rw [mass_zero_above hsS (lt_of_not_ge hjS) 1] + exact zero_le + have hsecond : ∀ j,2*m ≤ j → mass w ell S start m 2 j ≤ + ENNReal.ofReal ((24*initialConstant)*(MarginalGrowth.factor L κ w S)^2*width m*weight .even (point m j)) := by + intro j hj + by_cases hjS : point m j ≤ S + · have hjV : Valid .even (point m j) := index_valid hm .even hj + have hcover := weak_coverage (w:=w) (ell:=ell) (S:=S) hs hi hm hsmall 1 (by omega) j + have hbase := hrec w hwR' ell S hS3 hS start hell hr hs hsS m 1 j hm hmesh .odd (weakIndices m j .odd) + hjV hjS (by simpa only [sideAfter,Side.flip] using hcover) + exact hbase.trans (first_to_second L κ w S initialConstant hm j hj (fun k => mass w ell S start m 1 k) hC0 hfirst) + · rw [mass_zero_above hsS (lt_of_not_ge hjS) 2] + exact zero_le + refine ⟨hfirst,?_⟩ + intro n hn + induction n, hn using Nat.le_induction with + | base => + intro j hj + have hj' : 2*m ≤ j := hj + simpa only [sideAfter,Side.flip,profile,mul_one] using hsecond j hj' + | succ n hn ih => + intro j hj + by_cases hjS : point m j ≤ S + · let i := sideAfter .even n + have hj' : lowerIndex m i.flip ≤ j := hj + have hjV := index_valid hm i.flip hj' + have hbase := hrec w hwR' ell S hS3 hS start hell hr hs hsS m n j hm hmesh i + (Finset.Icc (lowerIndex m i) (j+m+1)) hjV hjS (regular_coverage hs hi hm n hn j) + have hnext := profile_step L κ w S (24*initialConstant) hm hmesh n j i + (fun k => mass w ell S start m n k) (by positivity) hj' (fun k hk => ih k hk) + exact hbase.trans hnext + · rw [mass_zero_above hsS (lt_of_not_ge hjS) (n+1)] + exact zero_le + +end NumberTheoryLean.PrimeMarginalInduction + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeMarginalRecursion.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeMarginalRecursion.lean new file mode 100644 index 0000000000000000000000000000000000000000..165ac3be88f5d5e3482db56f611698aea2b2e7be --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeMarginalRecursion.lean @@ -0,0 +1,234 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.FiniteBinIntegral +import OAI.NumberTheory.Jacobsthal.Partitions.GridWeightComparison + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PrimeGridKernel + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeHistories PrimeKilledChain PrimeSideSupport PrimeGridGeometry + +variable {w ell S : ℝ} {start : Node} + +noncomputable def bin (m j : ℕ) : Set (ChainState w ell S start) := + ActualPrimeBins.liveBin (point m j) (point m (j+1)) + +theorem mem_bin (g : History w ell S start) (m j : ℕ) : + some g ∈ bin m j ↔ g.node.ratio ∈ Ico (point m j) (point m (j+1)) := Iff.rfl + +theorem bin_measurable (m j : ℕ) : MeasurableSet (bin (w:=w) (ell:=ell) (S:=S) (start:=start) m j) := trivial + +theorem row_none (m j : ℕ) : chain w ell S start none (bin m j) = 0 := by + rw [chain_none,Measure.dirac_apply' _ (bin_measurable m j), + indicator_of_notMem (show (none:ChainState w ell S start) ∉ bin m j from ActualPrimeBins.not_mem_liveBin_none _ _)] + +theorem row_zero_of_large_parent (g : History w ell S start) (m j : ℕ) + (hlarge : point m j+width m+1 ≤ g.node.ratio) : + chain w ell S start (some g) (bin m j) = 0 := by + classical + rw [bin,point_succ,ActualPrimeBins.chain_live_bin_formula] + apply Finset.sum_eq_zero + intro p hp + have hlo := (Finset.mem_filter.mp hp).2.2.2.1 + have hmin := minRatio_ge_sub_one g.node.side g.node.ratio + have hnot : ¬(point m j ≤ childRatio w g.node.gap p ∧ childRatio w g.node.gap p < point m j+width m) := by + rintro ⟨_,ht⟩ + linarith + rw [ite_eq_right hnot] + +theorem row_zero_above_grid (g : History w ell S start) {m : ℕ} (hm : 1 ≤ m) (j : ℕ) + (hlarge : point m (j+m+2) ≤ g.node.ratio) : + chain w ell S start (some g) (bin m j) = 0 := by + apply row_zero_of_large_parent + rw [incoming_grid_end hm j] at hlarge + linarith [width_nonneg m] + +noncomputable def weakIndices (m j : ℕ) (i : Side) : Finset ℕ := by + classical + exact (Finset.Icc 0 (j+m+1)).filter (fun k => Valid i (point m k)) + +theorem weak_parent_cover (g : History w ell S start) {m : ℕ} (hm : 1 ≤ m) + (hsmall : width m ≤ 1/100) (j : ℕ) (hv : Valid g.node.side g.node.ratio) (hg : WeakRegular g.node) + (hupper : g.node.ratio < point m (j+m+2)) : + ∃ k ∈ weakIndices m j g.node.side, some g ∈ bin m k := by + classical + obtain ⟨k,hk,hbin⟩ := finite_grid_cover (J:=j+m+1) hm (valid_pos hv).le (by simpa only [Nat.add_assoc] using hupper) + exact ⟨k,Finset.mem_filter.mpr ⟨Finset.mem_Icc.mpr ⟨Nat.zero_le _,hk⟩,weak_bin_domain hm hsmall hg hbin⟩,hbin⟩ + +theorem regular_parent_cover (g : History w ell S start) {m : ℕ} (hm : 1 ≤ m) + (j : ℕ) (hv : Valid g.node.side g.node.ratio) (hg : Regular g.node) + (hupper : g.node.ratio < point m (j+m+2)) : + ∃ k ∈ Finset.Icc (lowerIndex m g.node.side) (j+m+1), + some g ∈ bin m k ∧ Valid g.node.side (point m k) := by + obtain ⟨k,hk,hbin⟩ := finite_grid_cover (J:=j+m+1) hm (valid_pos hv).le (by simpa only [Nat.add_assoc] using hupper) + have hdom := regular_bin_domain hm hg hbin + exact ⟨k,Finset.mem_Icc.mpr ⟨hdom.1,hk⟩,hbin,hdom.2⟩ + +noncomputable def mass (w ell S : ℝ) (start : Node) (m n j : ℕ) : ℝ≥0∞ := + pathLaw w ell S start n (bin m j) + +theorem mass_step (m n j : ℕ) : + mass w ell S start m (n+1) j = + ∫⁻ p,chain w ell S start p (bin m j) ∂pathLaw w ell S start n := by + have hp : (chain w ell S start)^(n+1) = (chain w ell S start) ∘ₖ ((chain w ell S start)^n) := pow_succ' _ _ + change ((chain w ell S start)^(n+1)) (some History.empty) (bin m j) = _ + rw [hp] + exact Kernel.comp_apply' _ _ _ (bin_measurable m j) + +end NumberTheoryLean.PrimeGridKernel + +end + +section + + +namespace NumberTheoryLean.PrimeMarginalRecursion + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeSideSupport +open PrimeGridGeometry PrimeGridKernel GridWeightComparison ExponentialMesh FiniteBinIntegral +open DerivativeWeights + +noncomputable def entry (L κ w S : ℝ) (m : ℕ) (i : Side) (j k : ℕ) : ℝ := + (1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)))*Real.exp (L*(1+S)^3*mesh κ w)* + width m*W (point m j)*(weight i.flip (point m j)/weight i (point m k)) + +def coveredParents {w ell S : ℝ} {start : Node} (m j : ℕ) (i : Side) (I : Finset ℕ) : + ChainState w ell S start → Prop + | none => True + | some g => g.node.side = i ∧ (g.node.ratio < point m (j+m+2) → + ∃ k ∈ I, some g ∈ bin m k ∧ Valid i (point m k)) + +theorem weak_coverage {w ell S : ℝ} {start : Node} (hs : Valid start.side start.ratio) + (hi : start.side = .even) {m : ℕ} (hm : 1 ≤ m) (hsmall : width m ≤ 1/100) + (n : ℕ) (hn : 1 ≤ n) (j : ℕ) : + ∀ᵐ p ∂pathLaw w ell S start n, coveredParents m j (sideAfter .even n) (weakIndices m j (sideAfter .even n)) p := by + filter_upwards [pathLaw_side (w:=w) (ell:=ell) (S:=S) hi n,pathLaw_weak (w:=w) (ell:=ell) (S:=S) hs n hn] with p hside hweak + cases p with + | none => trivial + | some g => + refine ⟨hside,?_⟩ + intro htop + have hgv : Valid g.node.side g.node.ratio := terminal_valid hs g.admissible + obtain ⟨k,hk,hbin⟩ := weak_parent_cover g hm hsmall j hgv hweak htop + have hkV := weak_bin_domain hm hsmall hweak ((mem_bin g m k).mp hbin) + exact ⟨k,by simpa only [hside] using hk,hbin,by simpa only [hside] using hkV⟩ + +theorem regular_coverage {w ell S : ℝ} {start : Node} (hs : Valid start.side start.ratio) + (hi : start.side = .even) {m : ℕ} (hm : 1 ≤ m) (n : ℕ) (hn : 2 ≤ n) (j : ℕ) : + ∀ᵐ p ∂pathLaw w ell S start n, coveredParents m j (sideAfter .even n) + (Finset.Icc (lowerIndex m (sideAfter .even n)) (j+m+1)) p := by + filter_upwards [pathLaw_side (w:=w) (ell:=ell) (S:=S) hi n,pathLaw_regular (w:=w) (ell:=ell) (S:=S) (start:=start) n hn] with p hside hreg + cases p with + | none => trivial + | some g => + refine ⟨hside,?_⟩ + intro htop + have hgv : Valid g.node.side g.node.ratio := terminal_valid hs g.admissible + obtain ⟨k,hk,hbin,hkV⟩ := regular_parent_cover g hm j hgv hreg htop + exact ⟨k,by simpa only [hside] using hk,hbin,by simpa only [hside] using hkV⟩ + +theorem covered_recursion : ∃ κ₀ L : ℝ, 0 < κ₀ ∧ 0 < L ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∃ w₀ : ℝ, 1 < w₀ ∧ ∀ w : ℝ, w₀ ≤ w → + ∀ ell S : ℝ, 3 ≤ S → S ≤ (Real.log w)^3 → ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → + ∀ m n j : ℕ, 1 ≤ m → width m = mesh κ w → ∀ i : Side, ∀ I : Finset ℕ, + Valid i.flip (point m j) → point m j ≤ S → + (∀ᵐ p ∂pathLaw w ell S start n, coveredParents m j i I p) → + mass w ell S start m (n+1) j ≤ + ∑ k ∈ I,ENNReal.ofReal (entry L κ w S m i j k)*mass w ell S start m n k := by + obtain ⟨κ₀,L,hκ₀,hL,hparent⟩ := actual_parent_bin_upper + refine ⟨κ₀,L,hκ₀,hL,?_⟩ + intro κ hκ hκle + obtain ⟨w₀,hw₀,hrow⟩ := hparent κ hκ hκle + refine ⟨w₀,hw₀,?_⟩ + intro w hw ell S hS3 hS start hell hr hs hsS m n j hm hmesh i I hjV hjS hcover + classical + have hEnvelope : ∀ᵐ p ∂pathLaw w ell S start n, + chain w ell S start p (bin m j) ≤ + ∑ k ∈ I,ENNReal.ofReal (entry L κ w S m i j k)*((bin m k).indicator (fun _ => (1:ℝ≥0∞)) p) := by + filter_upwards [hcover] with p hp + cases p with + | none => rw [row_none]; exact zero_le + | some g => + by_cases hhigh : point m (j+m+2) ≤ g.node.ratio + · rw [row_zero_above_grid g hm j hhigh] + exact zero_le + · obtain ⟨k,hk,hbin,hkV⟩ := hp.2 (lt_of_not_ge hhigh) + have hgu : Valid g.node.side (point m k) := by rwa [hp.1] + have hga : Valid g.node.side.flip (point m j) := by rwa [hp.1] + have hgn : g.node.ratio ≤ S := terminal_ratio_le hsS g.admissible + have hgBin := (mem_bin g m k).mp hbin + have hgb : g.node.ratio ≤ point m k+mesh κ w := by + rw [point_succ,hmesh] at hgBin + exact hgBin.2.le + have hb := hrow w hw ell S hS3 hS start hell hr hs g (point m k) (point m j) + hgu hga hgn hjS hgBin.1 hgb + have hentry : chain w ell S start (some g) (bin m j) ≤ ENNReal.ofReal (entry L κ w S m i j k) := by + simpa only [bin,point_succ,hmesh,entry,hp.1] using hb + calc + _ ≤ ENNReal.ofReal (entry L κ w S m i j k) := hentry + _ = ENNReal.ofReal (entry L κ w S m i j k)*((bin m k).indicator (fun _ => (1:ℝ≥0∞)) (some g)) := by + rw [indicator_of_mem hbin,mul_one] + _ ≤ _ := Finset.single_le_sum (s:=I) (a:=k) + (f:=fun l => ENNReal.ofReal (entry L κ w S m i j l)*((bin m l).indicator (fun _ => (1:ℝ≥0∞)) (some g))) + (fun _ _ => zero_le) hk + rw [mass_step] + calc + _ ≤ ∫⁻ p,∑ k ∈ I,ENNReal.ofReal (entry L κ w S m i j k)*((bin m k).indicator (fun _ => (1:ℝ≥0∞)) p) + ∂pathLaw w ell S start n := lintegral_mono_ae hEnvelope + _ = _ := integrate_bin_envelope (pathLaw w ell S start n) I (bin m) + (fun k _ => bin_measurable m k) (entry L κ w S m i j) + +theorem weak_recursion : ∃ κ₀ L : ℝ, 0 < κ₀ ∧ 0 < L ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∃ w₀ : ℝ, 1 < w₀ ∧ ∀ w : ℝ, w₀ ≤ w → + ∀ ell S : ℝ, 3 ≤ S → S ≤ (Real.log w)^3 → ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → start.side = .even → + ∀ m n j : ℕ, 1 ≤ m → width m = mesh κ w → width m ≤ 1/100 → 1 ≤ n → + Valid (sideAfter .even n).flip (point m j) → point m j ≤ S → + mass w ell S start m (n+1) j ≤ + ∑ k ∈ weakIndices m j (sideAfter .even n), + ENNReal.ofReal (entry L κ w S m (sideAfter .even n) j k)*mass w ell S start m n k := by + obtain ⟨κ₀,L,hκ₀,hL,hrec⟩ := covered_recursion + refine ⟨κ₀,L,hκ₀,hL,?_⟩ + intro κ hκ hκle + obtain ⟨w₀,hw₀,hrec⟩ := hrec κ hκ hκle + refine ⟨w₀,hw₀,?_⟩ + intro w hw ell S hS3 hS start hell hr hs hsS hi m n j hm hmesh hsmall hn hjV hjS + apply hrec w hw ell S hS3 hS start hell hr hs hsS m n j hm hmesh (sideAfter .even n) + (weakIndices m j (sideAfter .even n)) hjV hjS + exact weak_coverage hs hi hm hsmall n hn j + +theorem regular_recursion : ∃ κ₀ L : ℝ, 0 < κ₀ ∧ 0 < L ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∃ w₀ : ℝ, 1 < w₀ ∧ ∀ w : ℝ, w₀ ≤ w → + ∀ ell S : ℝ, 3 ≤ S → S ≤ (Real.log w)^3 → ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → start.side = .even → + ∀ m n j : ℕ, 1 ≤ m → width m = mesh κ w → 2 ≤ n → + Valid (sideAfter .even n).flip (point m j) → point m j ≤ S → + mass w ell S start m (n+1) j ≤ + ∑ k ∈ Finset.Icc (lowerIndex m (sideAfter .even n)) (j+m+1), + ENNReal.ofReal (entry L κ w S m (sideAfter .even n) j k)*mass w ell S start m n k := by + obtain ⟨κ₀,L,hκ₀,hL,hrec⟩ := covered_recursion + refine ⟨κ₀,L,hκ₀,hL,?_⟩ + intro κ hκ hκle + obtain ⟨w₀,hw₀,hrec⟩ := hrec κ hκ hκle + refine ⟨w₀,hw₀,?_⟩ + intro w hw ell S hS3 hS start hell hr hs hsS hi m n j hm hmesh hn hjV hjS + apply hrec w hw ell S hS3 hS start hell hr hs hsS m n j hm hmesh (sideAfter .even n) + (Finset.Icc (lowerIndex m (sideAfter .even n)) (j+m+1)) hjV hjS + exact regular_coverage hs hi hm n hn j + +end NumberTheoryLean.PrimeMarginalRecursion + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeOccupationDensity.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeOccupationDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..df5a2ff88489e6a3084e6118907f1c8748d840ff --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeOccupationDensity.lean @@ -0,0 +1,150 @@ +import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap +import OAI.NumberTheory.Jacobsthal.Analysis.LiteralCompactRemoval +import OAI.NumberTheory.Jacobsthal.Renewal.RetainedOccupationLimit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.OriginalPrimeOccupationLimit + +open _root_.Set _root_.Filter +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership +open LiteralPrimeOccupation LiteralCompactRemoval RetainedOccupationLimit +open CompactLogOccupationTest NormalizedOccupationLimit + +theorem original_prime_continuous_occupation_limit {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 1 ≤ ell) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) + (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |uncappedFamilyValue H w ell start-invariantAverage (arrivalTest ell H)| ≤ ε := by + obtain ⟨BP,wP,hBP,hwP,hretained⟩ := retained_original_occupation_limit hH hcompact ha hb hell hsupport d (ε/2) hd (by linarith) + obtain ⟨C,wH,hC,hwH,hremove⟩ := source_compact_family_removal hH hcompact + (K:=b) (fun i r s h => hsupport i r s (Or.inr h)) + obtain ⟨BH,hBH⟩ := eventually_atTop.mp hremove + let B₀ := max BP (max BH (max ell (2*C/ε))) + refine ⟨B₀,max wP wH,hBP.trans_le (le_max_left _ _),hwP.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBP' : BP ≤ B := (le_max_left _ _).trans hB + have hBH' : BH ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hB + have hellB : ell ≤ B := + (le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) (le_max_right _ _)).trans hB + have hlarge : 2*C/ε ≤ B := + (le_trans (le_trans (le_max_right _ _) (le_max_right _ _)) (le_max_right _ _)).trans hB + have hBpos : 0 < B := hBP.trans_le hBP' + have hsmall : C/B ≤ ε/2 := by + apply (div_le_iff₀ hBpos).mpr + have hh := (div_le_iff₀ hε).mp hlarge + nlinarith + have hrem := hBH B hBH' w ((le_max_right _ _).trans hw) ell hell hellB start hi h199 h23 hcons hcut + have hret := hretained B w hBP' ((le_max_left _ _).trans hw) hcomp start hi h199 h23 hcons hcut + have htri := abs_sub_le (uncappedFamilyValue H w ell start) (familyValue H w ell ((Real.log B)^2) start) + (invariantAverage (arrivalTest ell H)) + linarith + +theorem literal_original_prime_occupation {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 1 ≤ ell) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) + (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |(start.gap^2/FinitePathGeometry.weight start.side start.ratio)* + (∑ ps ∈ ActualPrimeHigh.uncappedPrefixes w ell start, + ErdosPrimeInputs.PrimePrefixMass.prefixWeight ps* + H (terminal w start ps).side ((terminal w start ps).gap,(terminal w start ps).ratio))- + invariantAverage (arrivalTest ell H)| ≤ ε := by + simpa only [uncappedFamilyValue,nodeReward] using + original_prime_continuous_occupation_limit hH hcompact ha hb hell hsupport d ε hd hε + +end NumberTheoryLean.OriginalPrimeOccupationLimit + +end + +section + +namespace NumberTheoryLean.PrimeOccupationDensity + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures InvariantInverseWeights OccupationBoundaries +open Erdos970Dependency.StateKernelInvariance Erdos970Dependency.InvariantCostBound + +noncomputable def baseMeasure : Measure (ℝ×State) := (volume : Measure ℝ).prod stateMeasure + +noncomputable def density (ell : ℝ) (x : ℝ×State) : ℝ := + if stateRatio x.2 < Real.exp x.1/ell then (Real.exp x.1)^2/(stateWeight x.2*costMass) else 0 + +theorem density_nonneg (ell : ℝ) (x : ℝ×State) : 0 ≤ density ell x := by + unfold density + split_ifs + · exact div_nonneg (sq_nonneg _) (mul_pos (stateWeight_pos _) costMass_pos).le + · exact le_rfl + +theorem density_measurable (ell : ℝ) : Measurable (density ell) := by + have he := Real.measurable_exp.comp (measurable_fst : Measurable (Prod.fst : ℝ×State → ℝ)) + have hs := stateRatio_measurable.comp (measurable_snd : Measurable (Prod.snd : ℝ×State → State)) + exact Measurable.ite (measurableSet_lt hs (he.div_const ell)) + ((he.pow_const 2).div ((stateWeight_measurable.comp measurable_snd).mul_const costMass)) measurable_const + +noncomputable def limitingMeasure (ell : ℝ) : Measure (ℝ×State) := + baseMeasure.withDensity (fun x => ENNReal.ofReal (density ell x)) + +theorem limiting_absolutelyContinuous (ell : ℝ) : limitingMeasure ell ≪ baseMeasure := + withDensity_absolutelyContinuous _ _ + +theorem invariant_ratio_null {B : Set ℝ} (hB : MeasurableSet B) (hnull : volume B=0) : + stateMeasure (stateRatio ⁻¹' B)=0 := by + rw [← state_invariance,Measure.bind_apply (stateRatio_measurable hB) stateKernel.aemeasurable] + simp_rw [stateKernel_ratio_null _ hB hnull] + exact lintegral_zero + +theorem invariant_ratio_level_null (t : ℝ) : stateMeasure {s | stateRatio s=t}=0 := by + exact invariant_ratio_null (measurableSet_singleton t) (measure_singleton t) + +theorem exponential_level_null (r : ℝ) : (volume : Measure ℝ) {u | Real.exp u=r}=0 := by + have hs : ({u : ℝ | Real.exp u=r}:Set ℝ).Subsingleton := by + intro u hu v hv + exact Real.exp_injective (hu.trans hv.symm) + exact hs.countable.measure_zero volume + +theorem gap_boundary_null (ell r : ℝ) : limitingMeasure ell {x | Real.exp x.1=r}=0 := by + apply limiting_absolutelyContinuous ell + have he : {x : ℝ×State | Real.exp x.1=r} = {u : ℝ | Real.exp u=r} ×ˢ (univ : Set State) := by + ext x + simp + rw [baseMeasure,he,Measure.prod_prod,exponential_level_null,zero_mul] + +theorem ratio_boundary_null (ell t : ℝ) : limitingMeasure ell {x | stateRatio x.2=t}=0 := by + apply limiting_absolutelyContinuous ell + have he : {x : ℝ×State | stateRatio x.2=t} = (univ : Set ℝ) ×ˢ {s : State | stateRatio s=t} := by + ext x + simp + rw [baseMeasure,he,Measure.prod_prod,invariant_ratio_level_null,mul_zero] + +noncomputable def rectangleBoundary (a b c d : ℝ) : Set (ℝ×State) := + {x | Real.exp x.1=a} ∪ {x | Real.exp x.1=b} ∪ {x | stateRatio x.2=c} ∪ {x | stateRatio x.2=d} + +theorem rectangle_boundary_null (ell a b c d : ℝ) : limitingMeasure ell (rectangleBoundary a b c d)=0 := by + unfold rectangleBoundary + exact measure_union_null (measure_union_null (measure_union_null (gap_boundary_null ell a) + (gap_boundary_null ell b)) (ratio_boundary_null ell c)) (ratio_boundary_null ell d) + +end NumberTheoryLean.PrimeOccupationDensity + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePartitionCounts.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePartitionCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ad2a7c04e05a9208419adae2f77945714a9c761 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePartitionCounts.lean @@ -0,0 +1,60 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.NonstructuredCounts + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseStructured +open ErdosSourceCollision ErdosLineCollision ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem prime_sum_partition_le {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (a : ℕ → ℤ) (f : ℕ → ℝ) (hf : ∀ p ∈ P,0 ≤ f p) : + (∑ p ∈ P,f p) ≤ (∑ p ∈ unalignedPrimes P a r,f p)+(∑ p ∈ ignoredPrimes P l.denominator,f p)+ + ∑ p ∈ P.filter (aligns a r.rational),f p := by + calc + _ ≤ ∑ p ∈ P,((if ¬p ∣ l.denominator ∧ ¬aligns a r.rational p then f p else 0)+ + (if p ∣ l.denominator then f p else 0)+(if aligns a r.rational p then f p else 0)) := by + apply Finset.sum_le_sum + intro p hp + by_cases hd : p ∣ l.denominator <;> by_cases ha : aligns a r.rational p <;> + simp [hd,ha] + linarith [hf p hp] + _ = _ := by simp only [unalignedPrimes,ignoredPrimes,Finset.sum_filter,Finset.sum_add_distrib] + +theorem many_aligners_of_richness {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (c eps : ℝ) (hN : 0 < X.card) + (hrich : c*(P.card : ℝ)*(X.card : ℝ) ≤ ∑ p ∈ P,((incidentPoints X (a p) p (T p)).card : ℝ)) + (hbad : (∑ p ∈ unalignedPrimes P a r,((incidentPoints X (a p) p (T p)).card : ℝ))+ + (∑ p ∈ ignoredPrimes P l.denominator,((incidentPoints X (a p) p (T p)).card : ℝ)) ≤ + eps*(P.card : ℝ)*(X.card : ℝ)) : + (c-eps)*(P.card : ℝ) ≤ ((P.filter (aligns a r.rational)).card : ℝ) := by + have hp := prime_sum_partition_le r P a + (fun p => ((incidentPoints X (a p) p (T p)).card : ℝ)) (fun _ _ => Nat.cast_nonneg _) + have ha := total_incidence_le_product (P.filter (aligns a r.rational)) X a T + have hNp : (0 : ℝ) < X.card := by exact_mod_cast hN + have hh : ((c-eps)*(P.card : ℝ))*(X.card : ℝ) ≤ + ((P.filter (aligns a r.rational)).card : ℝ)*(X.card : ℝ) := by linarith + exact le_of_mul_le_mul_right hh hNp + +theorem intercept_mem_fixed_list {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (a : ℕ → ℤ) (S R Z cp : ℝ) (hS : 0 ≤ S) (hR : 0 ≤ R) + (hden : (l.denominator : ℝ) ≤ R*Z^10) (hnum : |(l.intercept : ℝ)| ≤ S*R*Z^10) + (halign : cp*(P.card : ℝ) ≤ ((P.filter (aligns a r.rational)).card : ℝ)) : + r.rational ∈ sourceRationalList P a S R Z cp := by + have hh := r.height_transfer (R*Z^10) (S*R*Z^10) hden hnum + apply (mem_sourceRationalList P a hS hR r.rational).mpr + refine ⟨?_,hh.1,halign⟩ + simpa only [Nat.cast_natAbs,Int.cast_abs] using hh.2 + +end ErdosInverseStructured + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..45d282574742ea32db6cc19b9745b4f87b401b6b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerBound.lean @@ -0,0 +1,144 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.CommonFrequencyLift +import OAI.NumberTheory.Jacobsthal.Sieve.KloostermanPrimeExponent + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman.PrimePower + +noncomputable def envelope (p a : ℕ) (h k : ℤ) : ℝ := + ((a+1 : ℕ) : ℝ)^2 * ((p^a : ℕ) : ℝ)^((3 : ℝ)/4) * + ((Nat.gcd (p^a) (Int.gcd h k) : ℕ) : ℝ)^((1 : ℝ)/4) + +theorem envelope_ge_primitive (p a : ℕ) [Fact p.Prime] (ha : 0 < a) (h k : ℤ) : + 4 * ((p^a : ℕ) : ℝ)^((3 : ℝ)/4) ≤ envelope p a h k := by + have hg : 0 < Nat.gcd (p^a) (Int.gcd h k) := + Nat.gcd_pos_of_pos_left _ (pow_pos (Fact.out : p.Prime).pos a) + have hg1 : (1 : ℝ) ≤ ((Nat.gcd (p^a) (Int.gcd h k) : ℕ) : ℝ) := by + exact_mod_cast (Nat.succ_le_iff.mpr hg) + have hgp := Real.one_le_rpow hg1 (by norm_num : (0 : ℝ) ≤ 1/4) + have ha2 : (2 : ℝ) ≤ ((a+1 : ℕ) : ℝ) := by exact_mod_cast (by omega : 2 ≤ a+1) + have hc : (4 : ℝ) ≤ ((a+1 : ℕ) : ℝ)^2 := by nlinarith + unfold envelope + calc + _ ≤ ((a+1 : ℕ) : ℝ)^2 * ((p^a : ℕ) : ℝ)^((3 : ℝ)/4) := + mul_le_mul_of_nonneg_right hc (by positivity) + _ ≤ _ := le_mul_of_one_le_right (by positivity) hgp + +theorem quarter_scale (p Q g : ℝ) (hp : 0 < p) (hQ : 0 ≤ Q) (hg : 0 ≤ g) : + p * (Q^((3 : ℝ)/4) * g^((1 : ℝ)/4)) = + (p*Q)^((3 : ℝ)/4) * (p*g)^((1 : ℝ)/4) := by + rw [Real.mul_rpow hp.le hQ, Real.mul_rpow hp.le hg] + have he : p^((3 : ℝ)/4) * p^((1 : ℝ)/4) = p := by + rw [← Real.rpow_add hp] + norm_num + calc + _ = (p^((3 : ℝ)/4) * p^((1 : ℝ)/4)) * + (Q^((3 : ℝ)/4) * g^((1 : ℝ)/4)) := by rw [he] + _ = _ := by ring + +theorem envelope_scale (p a : ℕ) [Fact p.Prime] (h k : ℤ) : + (p : ℝ) * envelope p a h k ≤ envelope p (a+1) ((p : ℤ)*h) ((p : ℤ)*k) := by + have hp : (0 : ℝ) < p := by exact_mod_cast (Fact.out : p.Prime).pos + have hc : ((a+1 : ℕ) : ℝ)^2 ≤ ((a+1+1 : ℕ) : ℝ)^2 := by + push_cast + nlinarith [show (0 : ℝ) ≤ a from Nat.cast_nonneg a] + unfold envelope + rw [common_frequency_gcd, pow_succ' p a, Nat.cast_mul, Nat.cast_mul] + calc + _ = ((a+1 : ℕ) : ℝ)^2 * ((p : ℝ) * + (((p^a : ℕ) : ℝ)^((3 : ℝ)/4) * + ((Nat.gcd (p^a) (Int.gcd h k) : ℕ) : ℝ)^((1 : ℝ)/4))) := by ring + _ = _ := by rw [quarter_scale _ _ _ hp (by positivity) (by positivity)] + _ ≤ _ := mul_le_mul_of_nonneg_right hc (by positivity) + _ = _ := by ring + +end ErdosKloosterman.PrimePower + +end + +section + +namespace ErdosKloosterman.PrimePower + +private theorem prime_zero_envelope (p : ℕ) [Fact p.Prime] (h k : ℤ) + (hh : (h : ZMod p) = 0) (hk : (k : ZMod p) = 0) : + envelope p 1 h k = 4 * (p : ℝ) := by + have hd : p ∣ Int.gcd h k := Int.dvd_gcd + ((ZMod.intCast_zmod_eq_zero_iff_dvd h p).mp hh) + ((ZMod.intCast_zmod_eq_zero_iff_dvd k p).mp hk) + have hg := Nat.gcd_eq_left_iff_dvd.mpr hd + unfold envelope + rw [pow_one, hg] + have hp : (0 : ℝ) < p := by exact_mod_cast (Fact.out : p.Prime).pos + calc + _ = 4 * ((p : ℝ)^((3 : ℝ)/4) * (p : ℝ)^((1 : ℝ)/4)) := by norm_num; ring + _ = _ := by rw [← Real.rpow_add hp]; norm_num + +theorem prime_envelope_bound (p : ℕ) [Fact p.Prime] (h k : ℤ) : + ‖standardSum p h k‖ ≤ envelope p 1 h k := by + have primitive (hab : (h : ZMod p) ≠ 0 ∨ (k : ZMod p) ≠ 0) : + ‖standardSum p h k‖ ≤ envelope p 1 h k := by + calc + _ ≤ 2 * (p : ℝ)^((3 : ℝ)/4) := standardSum_prime_bound p h k hab + _ ≤ 4 * (p : ℝ)^((3 : ℝ)/4) := by + nlinarith [Real.rpow_nonneg (Nat.cast_nonneg p) ((3 : ℝ)/4)] + _ ≤ _ := by simpa only [pow_one] using envelope_ge_primitive p 1 (by decide) h k + by_cases hh : (h : ZMod p) = 0 + · by_cases hk : (k : ZMod p) = 0 + · have he : standardSum p h k = (Fintype.card (ZMod p)ˣ : ℂ) := by + simp only [standardSum, hh, hk, sum_zero_zero, ← Nat.card_eq_fintype_card] + have hc : (Fintype.card (ZMod p)ˣ : ℝ) ≤ p := by + have hc := Fintype.card_le_of_injective (fun u : (ZMod p)ˣ => (u : ZMod p)) + Units.val_injective + simpa only [ZMod.card] using (show (Fintype.card (ZMod p)ˣ : ℝ) ≤ + Fintype.card (ZMod p) by exact_mod_cast hc) + rw [he] + calc + _ = (Fintype.card (ZMod p)ˣ : ℝ) := by simp + _ ≤ p := hc + _ ≤ envelope p 1 h k := by + rw [prime_zero_envelope p h k hh hk] + nlinarith [show (0 : ℝ) ≤ p from Nat.cast_nonneg p] + · exact primitive (Or.inr hk) + · exact primitive (Or.inl hh) + +theorem prime_power_envelope_bound (p : ℕ) [Fact p.Prime] : + ∀ a : ℕ, 0 < a → ∀ h k : ℤ, ‖standardSum (p^a) h k‖ ≤ envelope p a h k := by + intro a + induction a with + | zero => intro ha; omega + | succ a ih => + intro ha h k + by_cases haz : a = 0 + · subst a + simpa only [Nat.zero_add, pow_one] using prime_envelope_bound p h k + have ha0 : 0 < a := by omega + by_cases hprimitive : (h : ZMod p) ≠ 0 ∨ (k : ZMod p) ≠ 0 + · exact (primitive_three_quarter_bound p (a+1) (by omega) h k hprimitive).trans + (envelope_ge_primitive p (a+1) (by omega) h k) + push Not at hprimitive + obtain ⟨hh, hk⟩ := hprimitive + obtain ⟨h', rfl⟩ := (ZMod.intCast_zmod_eq_zero_iff_dvd h p).mp hh + obtain ⟨k', rfl⟩ := (ZMod.intCast_zmod_eq_zero_iff_dvd k p).mp hk + rw [common_frequency_lift p a ha0, norm_mul] + have hn : ‖(p : ℂ)‖ = (p : ℝ) := by simp + rw [hn] + exact (mul_le_mul_of_nonneg_left (ih ha0 h' k') (Nat.cast_nonneg p)).trans + (envelope_scale p a h' k') + +theorem standardSum_prime_power_bound (p a : ℕ) [Fact p.Prime] (ha : 1 ≤ a) (h k : ℤ) : + ‖standardSum (p^a) h k‖ ≤ ((a+1 : ℕ) : ℝ)^2 * ((p^a : ℕ) : ℝ)^((3 : ℝ)/4) * + ((Nat.gcd (p^a) (Int.gcd h k) : ℕ) : ℝ)^((1 : ℝ)/4) := + prime_power_envelope_bound p a ha h k + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerGrowth.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerGrowth.lean new file mode 100644 index 0000000000000000000000000000000000000000..148dd6b5a4e001d1a62f2958ca90379fe469883a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerGrowth.lean @@ -0,0 +1,61 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosDivisorBounds + +theorem local_power_bound {eps : ℝ} (heps : 0 < eps) : + ∃ B : ℝ, 1 ≤ B ∧ ∀ p : ℕ, 2 ≤ p → ∀ k : ℕ, + (k : ℝ) + 1 ≤ B * ((p : ℝ)^eps)^k := by + let a : ℝ := (2 : ℝ)^eps - 1 + have ha : 0 < a := sub_pos.mpr (Real.one_lt_rpow (by norm_num) heps) + let B : ℝ := 1 + a⁻¹ + have hB : 1 ≤ B := by + dsimp [B] + exact le_add_of_nonneg_right (inv_nonneg.mpr ha.le) + have hBa : B*a = a+1 := by dsimp [B]; field_simp + refine ⟨B,hB,?_⟩ + intro p hp k + have hk : (0 : ℝ) ≤ k := Nat.cast_nonneg k + have hlin : (k : ℝ)+1 ≤ B*(1+(k : ℝ)*a) := by + have hm := mul_le_mul_of_nonneg_right (show 1 ≤ B*a by rw [hBa]; linarith) hk + nlinarith + have hbern := one_add_mul_le_pow (a:=a) (by linarith : -2 ≤ a) k + have heq : 1+a = (2 : ℝ)^eps := by dsimp [a]; ring + have hpp : (2 : ℝ)^eps ≤ (p : ℝ)^eps := + Real.rpow_le_rpow (by norm_num) (by exact_mod_cast hp) heps.le + calc + _ ≤ B*(1+(k : ℝ)*a) := hlin + _ ≤ B*(1+a)^k := mul_le_mul_of_nonneg_left hbern (by linarith) + _ = B*((2 : ℝ)^eps)^k := by rw [heq] + _ ≤ _ := mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (by positivity) hpp k) (by linarith) + +theorem large_prime_power_bound {eps : ℝ} (heps : 0 < eps) : + ∃ P : ℕ, ∀ p : ℕ, P ≤ p → ∀ k : ℕ, + (k : ℝ)+1 ≤ ((p : ℝ)^eps)^k := by + obtain ⟨P,hP⟩ := exists_nat_ge ((2 : ℝ)^(1/eps)) + refine ⟨P,?_⟩ + intro p hp k + have hpp : (2 : ℝ)^(1/eps) ≤ (p : ℝ) := hP.trans (by exact_mod_cast hp) + have hr := Real.rpow_le_rpow (by positivity : 0 ≤ (2 : ℝ)^(1/eps)) hpp heps.le + have he : ((2 : ℝ)^(1/eps))^eps = 2 := by + rw [← Real.rpow_mul (by norm_num : (0 : ℝ) ≤ 2)] + field_simp + norm_num + rw [he] at hr + have hb := one_add_mul_le_pow (a:=(1 : ℝ)) (by norm_num) k + have hlin : (k : ℝ)+1 ≤ (2 : ℝ)^k := by simpa only [mul_one, one_add_one_eq_two, add_comm] using hb + exact hlin.trans (pow_le_pow_left₀ (by norm_num) hr k) + +end ErdosDivisorBounds + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerStationarity.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerStationarity.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5aa3d2853890210ffd021a056635151b6df55bc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimePowerStationarity.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.StationaryPhase + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosKloosterman.PrimePower + +theorem stationary_iff_quadratic {R : Type*} [CommRing R] (q a b : R) (u : Rˣ) : + q * (a - b * (↑u⁻¹ : R)^2) = 0 ↔ q * (a * (u : R)^2 - b) = 0 := by + have he : q * (a - b * (↑u⁻¹ : R)^2) * (u : R)^2 = + q * (a * (u : R)^2 - b) := by + calc + _ = q * a * (u : R)^2 - q * b * ((↑u⁻¹ : R) * u)^2 := by ring + _ = _ := by simp; ring + rw [← he] + change _ ↔ _ * ((u^2 : Rˣ) : R) = 0 + exact (Units.mul_left_eq_zero (u^2)).symm + +theorem mul_annihilator_iff (n d : ℕ) [NeZero (n*d)] (hn : 0 < n) (x : ZMod (n*d)) : + (n : ZMod (n*d)) * x = 0 ↔ (x.val : ZMod d) = 0 := by + nth_rw 1 [← x.natCast_zmod_val] + rw [← Nat.cast_mul, ZMod.natCast_eq_zero_iff, ZMod.natCast_eq_zero_iff] + exact Nat.mul_dvd_mul_iff_left hn + +theorem power_shift_square_zero (p r s : ℕ) (hsr : s ≤ r) : + ((p^r : ℕ) : ZMod (p^(r+s)))^2 = 0 := by + rw [← Nat.cast_pow, ZMod.natCast_eq_zero_iff, ← pow_mul] + exact pow_dvd_pow p (by omega) + +theorem standard_stationary_identity (p r s : ℕ) [NeZero (p^(r+s))] (hsr : s ≤ r) + (h k : ℤ) : + standardSum (p^(r+s)) h k = + ∑ u ∈ stationaryUnits ((p^r : ℕ) : ZMod (p^(r+s))) (h : ZMod (p^(r+s))) k, + ZMod.stdAddChar ((h : ZMod (p^(r+s))) * (u : ZMod (p^(r+s))) + + (k : ZMod (p^(r+s))) * (↑u⁻¹ : ZMod (p^(r+s)))) := by + exact stationary_phase_identity (R := ZMod (p^(r+s))) + (ZMod.stdAddChar (N := p^(r+s))) (ZMod.isPrimitive_stdAddChar (p^(r+s))) + (h : ZMod (p^(r+s))) (k : ZMod (p^(r+s))) ((p^r : ℕ) : ZMod (p^(r+s))) (power_shift_square_zero p r s hsr) + +theorem standard_norm_le_stationary_card (p r s : ℕ) [NeZero (p^(r+s))] (hsr : s ≤ r) + (h k : ℤ) : + ‖standardSum (p^(r+s)) h k‖ ≤ + (stationaryUnits ((p^r : ℕ) : ZMod (p^(r+s))) (h : ZMod (p^(r+s))) k).card := by + exact norm_sum_le_stationary_card (R := ZMod (p^(r+s))) + (ZMod.stdAddChar (N := p^(r+s))) (ZMod.isPrimitive_stdAddChar (p^(r+s))) + (h : ZMod (p^(r+s))) (k : ZMod (p^(r+s))) ((p^r : ℕ) : ZMod (p^(r+s))) (power_shift_square_zero p r s hsr) + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductLifting.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductLifting.lean new file mode 100644 index 0000000000000000000000000000000000000000..bba26ada1255e6d16095d12506c9030fe5170bd2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductLifting.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LineSubstitution + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +theorem lineSub_eval {R : Type*} [CommRing R] (φ : ℤ →+* R) (a s z : R) + (Q : MvPolynomial (Fin 2) ℤ) : + (lineSub φ a s Q).eval z = MvPolynomial.eval₂Hom φ ![z,a-s*z] Q := by + have he : (Polynomial.evalRingHom z).comp (lineSub φ a s) = + MvPolynomial.eval₂Hom φ ![z,a-s*z] := by + apply MvPolynomial.ringHom_ext + · intro c + simp [lineSub] + · intro i + fin_cases i <;> simp [lineSub] + exact congrArg (fun f : MvPolynomial (Fin 2) ℤ →+* R => f Q) he + +theorem eval_integer_cast {R : Type*} [CommRing R] (Q : MvPolynomial (Fin 2) ℤ) (x y : ℤ) : + MvPolynomial.eval₂Hom (Int.castRingHom R) ![(x : R),(y : R)] Q = + (MvPolynomial.eval ![x,y] Q : R) := by + have he : (Int.castRingHom R) ∘ (![x,y] : Fin 2 → ℤ) = ![(x : R),(y : R)] := by + funext i + fin_cases i <;> rfl + have h := MvPolynomial.eval₂_comp (Int.castRingHom R) ![x,y] Q + rw [he] at h + exact h.symm + +theorem divides_of_line_incidence (p : ℕ) (Q : MvPolynomial (Fin 2) ℤ) (a s : ZMod p) + (x y : ℤ) (hline : lineSub (Int.castRingHom (ZMod p)) a s Q = 0) + (hinc : (y : ZMod p) = a-s*(x : ZMod p)) : (p : ℤ) ∣ MvPolynomial.eval ![x,y] Q := by + apply (ZMod.intCast_zmod_eq_zero_iff_dvd _ p).mp + rw [← eval_integer_cast,hinc,← lineSub_eval,hline,Polynomial.eval_zero] + +theorem zero_of_prime_product_large (n : ℤ) (I : Finset ℕ) + (hprime : ∀ p ∈ I, Nat.Prime p) (hdiv : ∀ p ∈ I, (p : ℤ) ∣ n) + (hlarge : |(n : ℝ)| < ((∏ p ∈ I, p : ℕ) : ℝ)) : n = 0 := by + by_contra hn + have hd : (∏ p ∈ I, p) ∣ n.natAbs := + Finset.prod_primes_dvd n.natAbs (fun p hp => (hprime p hp).prime) + (fun p hp => Int.natCast_dvd.mp (hdiv p hp)) + have hle : (∏ p ∈ I, p) ≤ n.natAbs := Nat.le_of_dvd (Int.natAbs_pos.mpr hn) hd + have habs : (n.natAbs : ℝ) = |(n : ℝ)| := by rw [Nat.cast_natAbs,Int.cast_abs] + have hleR : ((∏ p ∈ I, p : ℕ) : ℝ) ≤ |(n : ℝ)| := by + rw [← habs] + exact_mod_cast hle + exact (not_lt_of_ge hleR) hlarge + +theorem value_zero_of_incident_prime_product (Q : MvPolynomial (Fin 2) ℤ) (D H : ℕ) + (hD : Q.totalDegree ≤ D) (hH : ∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) + (S : ℝ) (x y : ℤ) (hx : 0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) (hy : 0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) + (I : Finset ℕ) (hprime : ∀ p ∈ I, Nat.Prime p) + (a s : ∀ p : I, ZMod p.val) + (hline : ∀ p : I, lineSub (Int.castRingHom (ZMod p.val)) (a p) (s p) Q = 0) + (hinc : ∀ p : I, (y : ZMod p.val) = a p-s p*(x : ZMod p.val)) + (hlarge : ((D+2).choose 2 : ℝ)*(H : ℝ)*(max 1 S)^D < ((∏ p ∈ I, p : ℕ) : ℝ)) : + MvPolynomial.eval ![x,y] Q = 0 := by + apply zero_of_prime_product_large _ I hprime + · intro p hp + exact divides_of_line_incidence p Q (a ⟨p,hp⟩) (s ⟨p,hp⟩) x y (hline ⟨p,hp⟩) (hinc ⟨p,hp⟩) + · exact (polynomial_value_bound Q D H hD hH S x y hx hy).trans_lt hlarge + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductLogCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductLogCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..5eeff7deba60544b3e017c2ee7ed84dcd453348e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductLogCoordinates.lean @@ -0,0 +1,57 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RepresentativeAdmission + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.PrimeProductLogCoordinates +open FinitePathGeometry PrimeHistories RepresentativeAdmission +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem log_nat_product (ps : List ℕ) (hp : ∀ p ∈ ps,0 < p) : + Real.log (ps.prod:ℝ)=(ps.map (fun p : ℕ => Real.log (p:ℝ))).sum := by + rw [Nat.cast_list_prod] + have hh := Real.log_list_prod (l := ps.map (fun p : ℕ => (p:ℝ))) (by + intro x hx + obtain ⟨p,hp',rfl⟩ := List.mem_map.mp hx + exact_mod_cast (hp p hp').ne') + simpa only [List.map_map,Function.comp_def] using hh + +theorem exponent_sum_log_product (w : ℝ) (ps : List ℕ) (hp : ∀ p ∈ ps,0 < p) : + (ps.map (primeExponent w)).sum=Real.log (ps.prod:ℝ)/Real.log w := by + rw [log_nat_product ps hp] + induction ps with + | nil => simp + | cons p ps ih => + simp only [List.map_cons,List.sum_cons,add_div,primeExponent] + rw [ih (fun q hq => hp q (by simp [hq]))] + +theorem terminal_gap_log_quotient {w a : ℝ} (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (ps : List ℕ) (hp : ∀ p ∈ ps,0 < p) : + (terminal w z ps).gap=Real.log ((Y:ℝ)/(ps.prod:ℝ))/Real.log w-a+2 := by + have hprodNat : 0 < ps.prod := List.prod_pos hp + have hprod : 0 < (ps.prod:ℝ) := by exact_mod_cast hprodNat + have hYr : 0 < (Y:ℝ) := by exact_mod_cast hY + rw [terminal_gap_sum,exponent_sum_log_product w ps hp,hroot,Real.log_div hYr.ne' hprod.ne'] + ring + +theorem source_length_exponent_identity {w a : ℝ} (hw : 1 < w) (Y P : ℕ) + (hY : 0 < Y) (hP : 1 < P) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (ps : List ℕ) (hp : ∀ p ∈ ps,0 < p) : + Real.log ((Y:ℝ)/(ps.prod:ℝ))/Real.log (P:ℝ)= + (terminal w z ps).gap/primeExponent w P+(a-2)/primeExponent w P := by + have hlogw : 0 < Real.log w := Real.log_pos hw + have hlogP : 0 < Real.log (P:ℝ) := Real.log_pos (by exact_mod_cast hP) + rw [terminal_gap_log_quotient Y hY z hroot ps hp,primeExponent] + field_simp [hlogw.ne',hlogP.ne'] + ring +end NumberTheoryLean.PrimeProductLogCoordinates + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductOmissions.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductOmissions.lean new file mode 100644 index 0000000000000000000000000000000000000000..30da38ec0afaaa0f924038da176b6992618b47e4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeProductOmissions.lean @@ -0,0 +1,105 @@ +import Mathlib.Data.Nat.Totient +import OAI.NumberTheory.Jacobsthal.Primes.HighPrimeRemoval +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueCountDifference + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosPrimeInputs.PrimeProductOmissions + +open _root_.Finset +open NumberTheoryLean.LargePrimeDeletion SubsetPrimeSieve MertensStrong + +noncomputable def reducedPrimes (z q : ℕ) : Finset ℕ := cutoffPrimes z \ q.primeFactors + +lemma factor_bounds {p : ℕ} (hp : p.Prime) : + 0 < 1 - (p : ℝ)⁻¹ ∧ 1 - (p : ℝ)⁻¹ ≤ 1 := by + have hp1 : (1:ℝ) < p := by exact_mod_cast hp.one_lt + exact ⟨sub_pos.mpr (inv_lt_one_of_one_lt₀ hp1), sub_le_self _ (inv_nonneg.mpr (Nat.cast_nonneg _))⟩ + +lemma totient_euler (q : ℕ) : (q.totient : ℝ) = (q : ℝ) * euler q.primeFactors := by + unfold euler + have h := congrArg (fun r : ℚ => (r : ℝ)) (Nat.totient_eq_mul_prod_factors q) + push_cast at h + exact h + +theorem euler_omissions_le (P : Finset ℕ) (q : ℕ) (hq : 0 < q) + (hP : ∀ p ∈ P, p.Prime) : euler (P \ q.primeFactors) ≤ euler P * q / q.totient := by + have hQ : ∀ p ∈ q.primeFactors, p.Prime := fun p hp => Nat.prime_of_mem_primeFactors hp + have hsmall : euler q.primeFactors ≤ euler (P ∩ q.primeFactors) := by + apply prod_le_prod_of_subset_of_le_one₀ inter_subset_right + · intro p hp + exact (factor_bounds (hQ p hp)).1.le + · intro p hp _ + exact (factor_bounds (hQ p hp)).2 + have hdiff : P \ (P ∩ q.primeFactors) = P \ q.primeFactors := by + ext p + simp + have hprod : euler (P \ q.primeFactors) * euler (P ∩ q.primeFactors) = euler P := by + unfold euler + rw [← hdiff] + exact prod_sdiff inter_subset_left + have he : euler (P \ q.primeFactors) * euler q.primeFactors ≤ euler P := + (mul_le_mul_of_nonneg_left hsmall + (euler_pos (fun p hp => hP p (mem_sdiff.mp hp).1)).le).trans_eq hprod + have hqR : 0 < (q:ℝ) := by exact_mod_cast hq + have htR : 0 < (q.totient:ℝ) := by exact_mod_cast Nat.totient_pos.mpr hq + apply (le_div_iff₀ htR).mpr + rw [totient_euler q] + nlinarith [mul_le_mul_of_nonneg_right he hqR.le] + +lemma cutoff_euler_eq (x : ℝ) : euler (cutoffPrimes ⌊x⌋₊) = primeProduct x := by + have hs : cutoffPrimes ⌊x⌋₊ = (Ioc 0 ⌊x⌋₊).filter Nat.Prime := by + ext p + simp only [mem_cutoffPrimes,mem_filter,mem_Ioc] + constructor + · rintro ⟨hp,hle⟩ + exact ⟨⟨hp.pos,hle⟩,hp⟩ + · rintro ⟨⟨_,hle⟩,hp⟩ + exact ⟨hp,hle⟩ + unfold euler primeProduct + rw [hs] + simp only [one_div] + +theorem prime_product_upper : ∃ C x₀ : ℝ, 0 < C ∧ 2 ≤ x₀ ∧ + ∀ x : ℝ, x₀ ≤ x → primeProduct x ≤ C / Real.log x := by + obtain ⟨c,K,x₀,hc,hK,hx₀,h⟩ := prime_product_strong + refine ⟨(K+1)*Real.exp (-Real.eulerMascheroniConstant),x₀,by positivity,hx₀,?_⟩ + intro x hx + have hx1 : 1 < x := by linarith [hx₀.trans hx] + have hl := Real.log_pos hx1 + have hd : Real.exp (-c * Real.sqrt (Real.log x)) ≤ 1 := Real.exp_le_one_iff.mpr (by + have := Real.sqrt_nonneg (Real.log x) + nlinarith) + have hh := (abs_le.mp (h x hx)).2 + have hu : primeProduct x / (Real.exp (-Real.eulerMascheroniConstant) / Real.log x) ≤ K+1 := by + nlinarith [mul_le_mul_of_nonneg_left hd hK.le] + have hmul := (div_le_iff₀ (div_pos (Real.exp_pos _) hl)).mp hu + simpa only [mul_div_assoc] using hmul + +theorem reduced_product_upper : ∃ C x₀ : ℝ, 0 < C ∧ 2 ≤ x₀ ∧ + ∀ x : ℝ, x₀ ≤ x → ∀ q : ℕ, 0 < q → + euler (reducedPrimes ⌊x⌋₊ q) ≤ C * ((q : ℝ) / q.totient) / Real.log x := by + obtain ⟨C,x₀,hC,hx₀,h⟩ := prime_product_upper + refine ⟨C,x₀,hC,hx₀,?_⟩ + intro x hx q hq + have ht0 : 0 ≤ (q.totient : ℝ) := Nat.cast_nonneg _ + calc + _ ≤ euler (cutoffPrimes ⌊x⌋₊) * q / q.totient := + euler_omissions_le _ q hq (fun p hp => (mem_cutoffPrimes.mp hp).1) + _ = primeProduct x * q / q.totient := by rw [cutoff_euler_eq] + _ ≤ (C / Real.log x) * q / q.totient := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_right (h x hx) (Nat.cast_nonneg _)) ht0 + _ = _ := by ring + +end ErdosPrimeInputs.PrimeProductOmissions + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeRatioBins.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeRatioBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad03101d41237732f4949992a166c4efded48c5b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeRatioBins.lean @@ -0,0 +1,569 @@ +import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated +import OAI.NumberTheory.Jacobsthal.Estimates.InverseWeightGrowth +import OAI.NumberTheory.Jacobsthal.Primes.HighPrimeRemoval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PrimeTiltGeometry + +open _root_.Erdos970.Set _root_.Erdos970.Finset +open FinitePathGeometry ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def childRatio (w r : ℝ) (p : ℕ) : ℝ := r / primeExponent w p - 1 + +noncomputable def capGuard (closed : Bool) (cap x : ℝ) : Prop := + if closed then x ≤ cap else x < cap + +noncomputable def children (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) : Finset ℕ := by + classical + exact (Nat.primesLE ⌊w^cap⌋₊).filter (fun p => ell < primeExponent w p ∧ + capGuard closed cap (primeExponent w p) ∧ minRatio i s ≤ childRatio w r p ∧ childRatio w r p ≤ S) + +theorem mem_children_iff {w ell S s r cap : ℝ} (hw : 1 < w) (i : Side) (closed : Bool) (p : ℕ) : + p ∈ children w ell S i s r cap closed ↔ p.Prime ∧ ell < primeExponent w p ∧ + capGuard closed cap (primeExponent w p) ∧ minRatio i s ≤ childRatio w r p ∧ childRatio w r p ≤ S := by + classical + unfold children + simp only [Finset.mem_filter, Nat.mem_primesLE] + constructor + · rintro ⟨⟨_,hp⟩,hx,hcap,ht,hS⟩ + exact ⟨hp,hx,hcap,ht,hS⟩ + · rintro ⟨hp,hx,hcap,ht,hS⟩ + refine ⟨⟨?_,hp⟩,hx,hcap,ht,hS⟩ + have hc : primeExponent w p ≤ cap := by + cases closed with + | false => exact (show primeExponent w p < cap from hcap).le + | true => exact hcap + have hp0 : (0 : ℝ) < p := by exact_mod_cast hp.pos + have hreal : (p : ℝ) ≤ w^cap := (exponent_le_iff hw hp0).mp hc + exact (Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) cap).le).mpr hreal + +theorem child_valid {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {p : ℕ} + (hs : Valid i s) (hp : p ∈ children w ell S i s r cap closed) : Valid i.flip (childRatio w r p) := by + classical + have ht := (Finset.mem_filter.mp hp).2.2.2.1 + exact valid_next hs ht + +theorem child_exponent_positive {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {p : ℕ} + (hell : 0 ≤ ell) (hp : p ∈ children w ell S i s r cap closed) : 0 < primeExponent w p := by + classical + exact lt_of_le_of_lt hell (Finset.mem_filter.mp hp).2.1 + +theorem nextExponent_childRatio {w r : ℝ} {p : ℕ} (hr : 0 < r) (hp : 0 < primeExponent w p) : + nextExponent r (childRatio w r p) = primeExponent w p := by + unfold nextExponent childRatio + simp only [sub_add_cancel] + field_simp + +theorem nextGap_childRatio {w r : ℝ} {p : ℕ} (hr : 0 < r) (hp : 0 < primeExponent w p) + (ht : 0 < childRatio w r p) : nextGap r (childRatio w r p) = r - primeExponent w p := by + have h := gap_exponent_conservation (r := r) ht + rw [nextExponent_childRatio hr hp] at h + linarith + +theorem child_gap_positive {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {p : ℕ} + (hell : 0 ≤ ell) (hr : 0 < r) (hs : Valid i s) (hp : p ∈ children w ell S i s r cap closed) : + 0 < r - primeExponent w p := by + have ht := valid_pos (child_valid hs hp) + rw [← nextGap_childRatio hr (child_exponent_positive hell hp) ht] + exact nextGap_pos hr ht + +noncomputable def primeTilt (w r : ℝ) (i : Side) (s : ℝ) (p : ℕ) : ℝ := + (p : ℝ)⁻¹ * ((childRatio w r p + 1) / childRatio w r p)^2 * + weight i.flip (childRatio w r p) / weight i s + +theorem primeTilt_nonneg {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {p : ℕ} + (hs : Valid i s) (hp : p ∈ children w ell S i s r cap closed) : 0 ≤ primeTilt w r i s p := by + unfold primeTilt + exact div_nonneg (mul_nonneg (mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg p)) (sq_nonneg _)) + (weight_pos (child_valid hs hp)).le) (weight_pos hs).le + +theorem prime_tilt_step_identity {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {p : ℕ} + (hell : 0 ≤ ell) (hr : 0 < r) (hs : Valid i s) (hp : p ∈ children w ell S i s r cap closed) : + (p : ℝ)⁻¹ = primeTilt w r i s p * ((r - primeExponent w p)/r)^2 * + (weight i s / weight i.flip (childRatio w r p)) := by + have ht := valid_pos (child_valid hs hp) + have hw := weight_pos hs + have hw' := weight_pos (child_valid hs hp) + rw [← nextGap_childRatio hr (child_exponent_positive hell hp) ht] + unfold primeTilt nextGap + field_simp [hr.ne', ht.ne', hw.ne', hw'.ne'] + +end NumberTheoryLean.PrimeTiltGeometry + +end + +section + +namespace NumberTheoryLean.PrimeTiltPrefixes + +open _root_.Erdos970.Set _root_.Erdos970.Finset +open FinitePathGeometry PrimeTiltGeometry ErdosPrimeInputs.HarmonicPrimeMeasure +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def PrimeAdmissible (w ell S : ℝ) : Side → ℝ → ℝ → ℝ → Bool → List ℕ → Prop + | _, _, _, _, _, [] => True + | i, s, r, cap, closed, p::ps => p ∈ children w ell S i s r cap closed ∧ + PrimeAdmissible w ell S i.flip (childRatio w r p) (r-primeExponent w p) (primeExponent w p) false ps + +noncomputable def primeRatios (w : ℝ) : ℝ → List ℕ → List ℝ + | _, [] => [] + | r, p::ps => childRatio w r p :: primeRatios w (r-primeExponent w p) ps + +noncomputable def primeFinalGap (w : ℝ) : ℝ → List ℕ → ℝ + | r, [] => r + | r, p::ps => primeFinalGap w (r-primeExponent w p) ps + +noncomputable def tiltProduct (w : ℝ) : Side → ℝ → ℝ → List ℕ → ℝ + | _, _, _, [] => 1 + | i, s, r, p::ps => primeTilt w r i s p * tiltProduct w i.flip (childRatio w r p) (r-primeExponent w p) ps + +noncomputable def normalizedTiltProduct (e w : ℝ) : Side → ℝ → ℝ → List ℕ → ℝ + | _, _, _, [] => 1 + | i, s, r, p::ps => (primeTilt w r i s p / (1+e)) * + normalizedTiltProduct e w i.flip (childRatio w r p) (r-primeExponent w p) ps + +theorem ratios_admissible {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hpath : PrimeAdmissible w ell S i s r cap closed ps) : Admissible i s (primeRatios w r ps) := by + classical + induction ps generalizing i s r cap closed with + | nil => trivial + | cons p ps ih => + rcases hpath with ⟨hp,hps⟩ + exact ⟨(Finset.mem_filter.mp hp).2.2.2.1, ih hps⟩ + +theorem primeFinalGap_eq {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < r) (hs : Valid i s) + (hpath : PrimeAdmissible w ell S i s r cap closed ps) : + primeFinalGap w r ps = finalGap r (primeRatios w r ps) := by + induction ps generalizing i s r cap closed with + | nil => rfl + | cons p ps ih => + rcases hpath with ⟨hp,hps⟩ + simp only [primeFinalGap, primeRatios, finalGap] + rw [nextGap_childRatio hr (child_exponent_positive hell hp) (valid_pos (child_valid hs hp))] + exact ih (child_gap_positive hell hr hs hp) (child_valid hs hp) hps + +theorem primeFinalGap_pos {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < r) (hs : Valid i s) + (hpath : PrimeAdmissible w ell S i s r cap closed ps) : 0 < primeFinalGap w r ps := by + induction ps generalizing i s r cap closed with + | nil => exact hr + | cons p ps ih => + rcases hpath with ⟨hp,hps⟩ + exact ih (child_gap_positive hell hr hs hp) (child_valid hs hp) hps + +theorem prime_prefix_weight_identity {w ell S s r cap : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (hell : 0 ≤ ell) (hr : 0 < r) (hs : Valid i s) + (hpath : PrimeAdmissible w ell S i s r cap closed ps) : + prefixWeight ps = tiltProduct w i s r ps * (primeFinalGap w r ps / r)^2 * + (weight i s / weight (finalSide i (primeRatios w r ps)) (finalRatio s (primeRatios w r ps))) := by + induction ps generalizing i s r cap closed with + | nil => + simp only [prefixWeight, List.map_nil, List.prod_nil, tiltProduct, primeFinalGap, primeRatios, finalSide, finalRatio] + rw [div_self hr.ne', div_self (weight_pos hs).ne'] + norm_num + | cons p ps ih => + rcases hpath with ⟨hp,hps⟩ + have hr' := child_gap_positive hell hr hs hp + have hs' := child_valid hs hp + have hi := ih hr' hs' hps + have hf := weight_pos (valid_final hs' (ratios_admissible hps)) + have hstep := prime_tilt_step_identity hell hr hs hp + simp only [prefixWeight, List.map_cons, List.prod_cons] at ⊢ + change (p : ℝ)⁻¹ * prefixWeight ps = _ + rw [hi, hstep] + simp only [tiltProduct, primeFinalGap, primeRatios, finalSide, finalRatio] + field_simp [hr.ne', hr'.ne', (weight_pos hs').ne', hf.ne'] + +theorem normalized_product_correction {e : ℝ} (he : 0 ≤ e) (w : ℝ) (i : Side) (s r : ℝ) (ps : List ℕ) : + normalizedTiltProduct e w i s r ps * (1+e)^ps.length = tiltProduct w i s r ps := by + induction ps generalizing i s r with + | nil => simp [normalizedTiltProduct, tiltProduct] + | cons p ps ih => + simp only [normalizedTiltProduct, tiltProduct, List.length_cons, pow_succ] + rw [show (primeTilt w r i s p / (1+e)) * normalizedTiltProduct e w i.flip (childRatio w r p) (r-primeExponent w p) ps * + ((1+e)^ps.length * (1+e)) = primeTilt w r i s p * + (normalizedTiltProduct e w i.flip (childRatio w r p) (r-primeExponent w p) ps * (1+e)^ps.length) by + field_simp [show 1+e ≠ 0 by linarith]] + rw [ih] + +theorem normalized_prime_prefix_weight_identity {w ell S s r cap e : ℝ} {i : Side} {closed : Bool} {ps : List ℕ} + (he : 0 ≤ e) (hell : 0 ≤ ell) (hr : 0 < r) (hs : Valid i s) + (hpath : PrimeAdmissible w ell S i s r cap closed ps) : + prefixWeight ps = normalizedTiltProduct e w i s r ps * (1+e)^ps.length * (primeFinalGap w r ps / r)^2 * + (weight i s / weight (finalSide i (primeRatios w r ps)) (finalRatio s (primeRatios w r ps))) := by + rw [normalized_product_correction he] + exact prime_prefix_weight_identity hell hr hs hpath + +end NumberTheoryLean.PrimeTiltPrefixes + +end + +section + +namespace NumberTheoryLean.PrimeTiltBounds + +open _root_.Erdos970.Set +open FinitePathGeometry PrimeTiltGeometry WeightGlobalBounds DerivativeWeights + +noncomputable def multiplier (i : Side) (s t : ℝ) : ℝ := + ((t+1)/t)^2 * weight i.flip t / weight i s + +theorem primeTilt_eq_multiplier (w r : ℝ) (i : Side) (s : ℝ) (p : ℕ) : + primeTilt w r i s p = (p : ℝ)⁻¹ * multiplier i s (childRatio w r p) := by + unfold primeTilt multiplier + ring + +theorem multiplier_pos {i : Side} {s t : ℝ} (hs : Valid i s) (ht : Valid i.flip t) : + 0 < multiplier i s t := by + have ht0 := valid_pos ht + exact div_pos (mul_pos (sq_pos_of_pos (div_pos (by linarith) ht0)) (weight_pos ht)) (weight_pos hs) + +theorem valid_ge_half {i : Side} {t : ℝ} (ht : Valid i t) : (1/2 : ℝ) ≤ t := by + cases i <;> dsimp [Valid] at ht <;> linarith + +theorem multiplier_envelope : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, ∀ i : Side, ∀ s t : ℝ, + Valid i s → s ≤ S → minRatio i s ≤ t → multiplier i s t ≤ C * (1+S)^2 := by + obtain ⟨C,hC,he,ho⟩ := weights_global_ratio_bound + refine ⟨9*C, by positivity, ?_⟩ + intro S i s t hs hsS hst + have ht := valid_next hs hst + have ht0 := valid_pos ht + have hhalf := valid_ge_half ht + have hrat : weight i.flip t / weight i s ≤ C * (1+s)^2 := by + cases i with + | even => + have hm : phiOdd t ≤ phiOdd (s-1) := phiOdd_antitone hst + exact (div_le_div_of_nonneg_right hm (weight_pos hs).le).trans (he s hs) + | odd => + change max 2 (s-1) ≤ t at hst + have hm2 : 2 ≤ max 2 (s-1) := le_max_left _ _ + have hm : phiEven t ≤ phiEven (max 2 (s-1)) := + phiEven_strictAntiOn.antitoneOn (by change 1 < max 2 (s-1); linarith) + (by change 1 < t; linarith) hst + exact (div_le_div_of_nonneg_right hm (weight_pos hs).le).trans (ho s hs) + have hq : (t+1)/t ≤ 3 := (div_le_iff₀ ht0).mpr (by linarith) + have hq0 : 0 ≤ (t+1)/t := (div_pos (by linarith) ht0).le + have hsq : ((t+1)/t)^2 ≤ 9 := by nlinarith + have hs0 := valid_pos hs + calc + _ = ((t+1)/t)^2 * (weight i.flip t / weight i s) := by unfold multiplier; ring + _ ≤ 9 * (C * (1+s)^2) := mul_le_mul hsq hrat (div_pos (weight_pos ht) (weight_pos hs)).le (by norm_num) + _ ≤ (9*C) * (1+S)^2 := by + have hp : (1+s)^2 ≤ (1+S)^2 := by nlinarith + nlinarith [mul_le_mul_of_nonneg_left hp (show 0 ≤ 9*C by positivity)] + +theorem log_lipschitz_half {u v : ℝ} (hu : (1/2 : ℝ) ≤ u) (hv : (1/2 : ℝ) ≤ v) : + |Real.log u - Real.log v| ≤ 2 * |u-v| := by + have ordered : ∀ a b : ℝ, (1/2 : ℝ) ≤ a → a ≤ b → + |Real.log b - Real.log a| ≤ 2*(b-a) := by + intro a b ha hab + apply interval_abs_bound hab + · exact Real.continuousOn_log.mono (by intro t ht; exact ne_of_gt (by linarith [ht.1] : 0 < t)) + · intro t ht + exact Real.hasDerivAt_log (by linarith [ht.1] : t ≠ 0) + · intro t ht + have ht0 : 0 < t := by linarith [ht.1] + rw [abs_of_nonneg (inv_nonneg.mpr ht0.le)] + exact (inv_le_comm₀ ht0 (by norm_num : (0 : ℝ) < 2)).mpr (by linarith [ht.1]) + rcases le_total u v with huv | hvu + · rw [abs_sub_comm (Real.log u), abs_sub_comm u, abs_of_nonneg (sub_nonneg.mpr huv)] + exact ordered u v hu huv + · rw [abs_of_nonneg (sub_nonneg.mpr hvu)] + exact ordered v u hv hvu + +theorem log_multiplier {i : Side} {s t : ℝ} (hs : Valid i s) (ht : Valid i.flip t) : + Real.log (multiplier i s t) = 2*(Real.log (t+1)-Real.log t) + Real.log (weight i.flip t) - Real.log (weight i s) := by + have ht0 := valid_pos ht + have hq : (t+1)/t ≠ 0 := (div_pos (by linarith) ht0).ne' + unfold multiplier + rw [Real.log_div (mul_ne_zero (pow_ne_zero _ hq) (weight_pos ht).ne') (weight_pos hs).ne', + Real.log_mul (pow_ne_zero _ hq) (weight_pos ht).ne', Real.log_pow, + Real.log_div (by linarith : t+1 ≠ 0) ht0.ne'] + norm_num + +theorem multiplier_log_lipschitz : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, 3 ≤ S → + ∀ i : Side, ∀ s u v : ℝ, Valid i s → Valid i.flip u → Valid i.flip v → u ≤ S → v ≤ S → + |Real.log (multiplier i s u) - Real.log (multiplier i s v)| ≤ C * (1+S)^3 * |u-v| := by + obtain ⟨C,hC,hbound⟩ := weights_log_lipschitz + refine ⟨C+8, by linarith, ?_⟩ + intro S hS i s u v hs hu hv huS hvS + have hw : |Real.log (weight i.flip u) - Real.log (weight i.flip v)| ≤ C*(1+S)^3*|u-v| := by + cases i with + | even => exact (hbound S hS).2 u v hu hv huS hvS + | odd => exact (hbound S hS).1 u v hu hv huS hvS + have hbase := log_lipschitz_half (valid_ge_half hu) (valid_ge_half hv) + have hshift : |Real.log (u+1)-Real.log (v+1)| ≤ 2*|u-v| := by + have h := log_lipschitz_half (u := u+1) (v := v+1) + (by linarith [valid_ge_half hu]) (by linarith [valid_ge_half hv]) + simpa only [add_sub_add_right_eq_sub] using h + have hp : (1 : ℝ) ≤ (1+S)^3 := one_le_pow₀ (by linarith : (1 : ℝ) ≤ 1+S) + rw [log_multiplier hs hu, log_multiplier hs hv] + calc + _ = |2*(Real.log (u+1)-Real.log (v+1)) - 2*(Real.log u-Real.log v) + + (Real.log (weight i.flip u)-Real.log (weight i.flip v))| := by congr 1; ring + _ ≤ 2*|Real.log (u+1)-Real.log (v+1)| + 2*|Real.log u-Real.log v| + + |Real.log (weight i.flip u)-Real.log (weight i.flip v)| := by + rw [abs_le] + constructor <;> nlinarith [ + le_abs_self (Real.log (u+1)-Real.log (v+1)), neg_abs_le (Real.log (u+1)-Real.log (v+1)), + le_abs_self (Real.log u-Real.log v), neg_abs_le (Real.log u-Real.log v), + le_abs_self (Real.log (weight i.flip u)-Real.log (weight i.flip v)), + neg_abs_le (Real.log (weight i.flip u)-Real.log (weight i.flip v))] + _ ≤ (C+8)*(1+S)^3*|u-v| := by + have hmul := mul_le_mul_of_nonneg_right hp (show 0 ≤ 8*|u-v| by positivity) + nlinarith + +theorem multiplier_relative_bound : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, 3 ≤ S → + ∀ i : Side, ∀ s u v : ℝ, Valid i s → Valid i.flip u → Valid i.flip v → u ≤ S → v ≤ S → + multiplier i s u ≤ Real.exp (C*(1+S)^3*|u-v|) * multiplier i s v := by + obtain ⟨C,hC,hbound⟩ := multiplier_log_lipschitz + refine ⟨C,hC,?_⟩ + intro S hS i s u v hs hu hv huS hvS + have h := (abs_le.mp (hbound S hS i s u v hs hu hv huS hvS)).2 + have hl : Real.log (multiplier i s u) ≤ C*(1+S)^3*|u-v| + Real.log (multiplier i s v) := by linarith + have he := Real.exp_le_exp.mpr hl + rwa [Real.exp_add, Real.exp_log (multiplier_pos hs hu), Real.exp_log (multiplier_pos hs hv)] at he + +end NumberTheoryLean.PrimeTiltBounds + +end + +section + +namespace NumberTheoryLean.PrimeHistories + +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open FinitePathGeometry PrimeTiltGeometry PrimeTiltPrefixes +open ErdosPrimeInputs.HarmonicPrimeMeasure + +structure Node where + side : Side + ratio : ℝ + gap : ℝ + cutoff : ℝ + closed : Bool + +noncomputable def nodeChildren (w ell S : ℝ) (z : Node) : Finset ℕ := + children w ell S z.side z.ratio z.gap z.cutoff z.closed + +noncomputable def step (w : ℝ) (z : Node) (p : ℕ) : Node where + side := z.side.flip + ratio := childRatio w z.gap p + gap := z.gap - primeExponent w p + cutoff := primeExponent w p + closed := false + +noncomputable def terminal (w : ℝ) (z : Node) (ps : List ℕ) : Node := ps.foldl (step w) z + +noncomputable def allowed (w ell S : ℝ) (z : Node) (ps : List ℕ) : Prop := + PrimeAdmissible w ell S z.side z.ratio z.gap z.cutoff z.closed ps + +@[simp] theorem terminal_nil (w : ℝ) (z : Node) : terminal w z [] = z := rfl +@[simp] theorem terminal_cons (w : ℝ) (z : Node) (p : ℕ) (ps : List ℕ) : + terminal w z (p::ps) = terminal w (step w z p) ps := rfl + +theorem terminal_append (w : ℝ) (z : Node) (ps qs : List ℕ) : + terminal w z (ps++qs) = terminal w (terminal w z ps) qs := by + exact List.foldl_append + +theorem allowed_nil (w ell S : ℝ) (z : Node) : allowed w ell S z [] := trivial + +theorem allowed_cons (w ell S : ℝ) (z : Node) (p : ℕ) (ps : List ℕ) : + allowed w ell S z (p::ps) ↔ p ∈ nodeChildren w ell S z ∧ allowed w ell S (step w z p) ps := Iff.rfl + +theorem allowed_append (w ell S : ℝ) (z : Node) (ps qs : List ℕ) : + allowed w ell S z (ps++qs) ↔ allowed w ell S z ps ∧ allowed w ell S (terminal w z ps) qs := by + induction ps generalizing z with + | nil => simp only [List.nil_append, terminal_nil, iff_true_intro (allowed_nil w ell S z), true_and] + | cons p ps ih => + rw [List.cons_append, allowed_cons, ih, allowed_cons, terminal_cons] + tauto + +theorem terminal_valid {w ell S : ℝ} {z : Node} {ps : List ℕ} (hs : Valid z.side z.ratio) + (hp : allowed w ell S z ps) : Valid (terminal w z ps).side (terminal w z ps).ratio := by + induction ps generalizing z with + | nil => exact hs + | cons p ps ih => + rcases (allowed_cons w ell S z p ps).mp hp with ⟨hchild,hpath⟩ + exact ih (child_valid hs hchild) hpath + +theorem terminal_gap_positive {w ell S : ℝ} {z : Node} {ps : List ℕ} (hell : 0 ≤ ell) + (hr : 0 < z.gap) (hs : Valid z.side z.ratio) (hp : allowed w ell S z ps) : + 0 < (terminal w z ps).gap := by + induction ps generalizing z with + | nil => exact hr + | cons p ps ih => + rcases (allowed_cons w ell S z p ps).mp hp with ⟨hchild,hpath⟩ + exact ih (child_gap_positive hell hr hs hchild) (child_valid hs hchild) hpath + +theorem terminal_ratio_le {w ell S : ℝ} {z : Node} {ps : List ℕ} (hs : z.ratio ≤ S) + (hp : allowed w ell S z ps) : (terminal w z ps).ratio ≤ S := by + classical + induction ps generalizing z with + | nil => exact hs + | cons p ps ih => + rcases (allowed_cons w ell S z p ps).mp hp with ⟨hchild,hpath⟩ + exact ih (Finset.mem_filter.mp hchild).2.2.2.2 hpath + +theorem terminal_gap_eq (w : ℝ) (z : Node) (ps : List ℕ) : + (terminal w z ps).gap = primeFinalGap w z.gap ps := by + induction ps generalizing z with + | nil => rfl + | cons p ps ih => simpa only [terminal_cons, primeFinalGap, step] using ih (step w z p) + +theorem terminal_ratio_eq (w : ℝ) (z : Node) (ps : List ℕ) : + (terminal w z ps).ratio = finalRatio z.ratio (primeRatios w z.gap ps) := by + induction ps generalizing z with + | nil => rfl + | cons p ps ih => simpa only [terminal_cons, primeRatios, finalRatio, step] using ih (step w z p) + +theorem terminal_side_eq (w : ℝ) (z : Node) (ps : List ℕ) : + (terminal w z ps).side = finalSide z.side (primeRatios w z.gap ps) := by + induction ps generalizing z with + | nil => rfl + | cons p ps ih => simpa only [terminal_cons, primeRatios, finalSide, step] using ih (step w z p) + +structure History (w ell S : ℝ) (start : Node) where + primes : List ℕ + admissible : allowed w ell S start primes + +namespace History + +variable {w ell S : ℝ} {start : Node} + +@[ext] theorem ext {h k : History w ell S start} (heq : h.primes = k.primes) : h = k := by + cases h + cases k + cases heq + rfl + +instance : Countable (History w ell S start) := (show Function.Injective (History.primes : History w ell S start → List ℕ) from fun _ _ h => ext h).countable +instance : MeasurableSpace (History w ell S start) := ⊤ +instance : MeasurableSingletonClass (History w ell S start) := ⟨fun _ => trivial⟩ + +def empty : History w ell S start := ⟨[],allowed_nil w ell S start⟩ +noncomputable def node (h : History w ell S start) : Node := terminal w start h.primes + +noncomputable def append (h : History w ell S start) (p : ℕ) (hp : p ∈ nodeChildren w ell S h.node) : History w ell S start where + primes := h.primes ++ [p] + admissible := (allowed_append w ell S start h.primes [p]).mpr ⟨h.admissible, + (allowed_cons w ell S h.node p []).mpr ⟨hp,allowed_nil w ell S _⟩⟩ + +@[simp] theorem append_primes (h : History w ell S start) (p : ℕ) (hp : p ∈ nodeChildren w ell S h.node) : + (h.append p hp).primes = h.primes ++ [p] := rfl + +theorem append_node (h : History w ell S start) (p : ℕ) (hp : p ∈ nodeChildren w ell S h.node) : + (h.append p hp).node = step w h.node p := by + change terminal w start (h.primes ++ [p]) = _ + rw [terminal_append, terminal_cons, terminal_nil] + rfl + +end History +end NumberTheoryLean.PrimeHistories + +end + +section + +namespace NumberTheoryLean.PrimeRatioBins + +open _root_.Erdos970.Finset _root_.Erdos970.Set +open FinitePathGeometry PrimeTiltGeometry PrimeTiltBounds +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimeEndpoints + +noncomputable def ratioBin (w r a b : ℝ) : Finset ℕ := by + classical + exact (Nat.primesLE ⌊w ^ (r/(a+1))⌋₊).filter + (fun p => a ≤ childRatio w r p ∧ childRatio w r p < b) + +noncomputable def ratioBinMass (w r a b : ℝ) : ℝ := + ∑ p ∈ ratioBin w r a b, (p : ℝ)⁻¹ + +theorem ratio_interval_iff {r a b x : ℝ} (ha : 0 < a) (hab : a ≤ b) (hx : 0 < x) : + (a ≤ r/x-1 ∧ r/x-1 < b) ↔ r/(b+1) < x ∧ x ≤ r/(a+1) := by + have ha1 : 0 < a+1 := by linarith + have hb1 : 0 < b+1 := by linarith + constructor + · rintro ⟨hlo,hhi⟩ + constructor + · apply (div_lt_iff₀ hb1).mpr + have h := (div_lt_iff₀ hx).mp (show r/x < b+1 by linarith) + nlinarith + · apply (le_div_iff₀ ha1).mpr + have h := (le_div_iff₀ hx).mp (show a+1 ≤ r/x by linarith) + nlinarith + · rintro ⟨hlo,hhi⟩ + constructor + · have h := (le_div_iff₀ ha1).mp hhi + have hh : a+1 ≤ r/x := (le_div_iff₀ hx).mpr (by nlinarith) + linarith + · have h := (div_lt_iff₀ hb1).mp hlo + have hh : r/x < b+1 := (div_lt_iff₀ hx).mpr (by nlinarith) + linarith + +theorem primeExponent_pos {w : ℝ} (hw : 1 < w) {p : ℕ} (hp : p.Prime) : 0 < primeExponent w p := by + apply div_pos + · apply Real.log_pos + exact_mod_cast hp.one_lt + · exact Real.log_pos hw + +theorem ratioBinMass_eq_harmonic {w r a b : ℝ} (hw : 1 < w) (ha : 0 < a) (hab : a ≤ b) : + ratioBinMass w r a b = harmonicMass w false true (r/(b+1)) (r/(a+1)) := by + classical + unfold ratioBinMass ratioBin harmonicMass + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro p hp + have heq := ratio_interval_iff (r := r) ha hab (primeExponent_pos hw (Nat.mem_primesLE.mp hp).2) + simp only [childRatio, intervalGuard, Bool.false_eq_true, ite_false, ite_true, heq] + +theorem bin_log_width {r a b : ℝ} (hr : 0 < r) (ha : 0 < a) (hab : a ≤ b) : + Real.log (r/(a+1)) - Real.log (r/(b+1)) = Real.log (b+1)-Real.log (a+1) := by + rw [Real.log_div hr.ne' (by linarith : a+1 ≠ 0), Real.log_div hr.ne' (by linarith : b+1 ≠ 0)] + ring + +theorem bin_log_width_bounds {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) : + (b-a)/(b+1) ≤ Real.log (b+1)-Real.log (a+1) ∧ + Real.log (b+1)-Real.log (a+1) ≤ (b-a)/(a+1) := by + have ha1 : 0 < a+1 := by linarith + have hb1 : 0 < b+1 := by linarith + have hq := div_pos hb1 ha1 + have hl := Real.one_sub_inv_le_log_of_pos hq + have hu := Real.log_le_sub_one_of_pos hq + rw [Real.log_div hb1.ne' ha1.ne'] at hl hu + have heL : 1-((b+1)/(a+1))⁻¹ = (b-a)/(b+1) := by field_simp; ring + have heU : (b+1)/(a+1)-1 = (b-a)/(a+1) := by field_simp; ring + rw [heL] at hl + rw [heU] at hu + exact ⟨hl,hu⟩ + +theorem prime_ratio_bin_error : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ r a b : ℝ, 0 < r → 0 < a → a ≤ b → 1/2 ≤ r/(b+1) → + |ratioBinMass w r a b - (Real.log (b+1)-Real.log (a+1))| ≤ + C * Real.exp (-c * Real.sqrt ((1/2 : ℝ) * Real.log w)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hbound⟩ := harmonic_prime_measure + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw r a b hr ha hab hlow + have hw1 := hw₀.trans_le hw + have hend : r/(b+1) ≤ r/(a+1) := div_le_div_of_nonneg_left hr.le (by linarith : 0 < a+1) (by linarith) + have h := hbound w hw (r/(b+1)) (r/(a+1)) hlow hend false true + rw [← ratioBinMass_eq_harmonic hw1 ha hab, bin_log_width hr ha hab] at h + apply h.trans + apply mul_le_mul_of_nonneg_left _ hC.le + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonpos_left (Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_right hlow (Real.log_pos hw1).le)) (by linarith) + +end NumberTheoryLean.PrimeRatioBins + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeRationalList.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeRationalList.lean new file mode 100644 index 0000000000000000000000000000000000000000..288d654feeda25024adf74fcd241911f7b14a98a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeRationalList.lean @@ -0,0 +1,88 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FactorDividesAbscissa + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem common_prime_product_dvd (P : Finset ℕ) (a : ℕ → ℤ) {q r : ℚ} + (hqr : q ≠ r) (hP : ∀ p ∈ P,p.Prime) : + (∏ p ∈ commonAligners P a q r,p) ∣ (determinant q r).natAbs := by + have hn := Int.natAbs_ne_zero.mpr (determinant_ne_zero hqr) + have hsub : commonAligners P a q r ⊆ (determinant q r).natAbs.primeFactors := by + intro p hp + obtain ⟨hpP,hq,hr⟩ := Finset.mem_filter.mp hp + exact Nat.mem_primeFactors.mpr ⟨hP p hpP,Int.natCast_dvd.mp (common_alignment_dvd a q r p hq hr),hn⟩ + exact (Finset.prod_dvd_prod_of_subset _ _ id hsub).trans (Nat.prod_primeFactors_dvd _) + +theorem common_primes_power_height_bound (P : Finset ℕ) (a : ℕ → ℤ) {q r : ℚ} + (hqr : q ≠ r) (hP : ∀ p ∈ P,p.Prime) {z α C : ℝ} + (hz : 1 < z) (hα : 0 < α) (hlarge : ∀ p ∈ P,z^α ≤ (p : ℝ)) + (hheight : ((determinant q r).natAbs : ℝ) ≤ z^C) : + ((commonAligners P a q r).card : ℝ) ≤ C/α := by + have hprod : (∏ p ∈ commonAligners P a q r,p) ≤ (determinant q r).natAbs := + Nat.le_of_dvd (Nat.pos_of_ne_zero (Int.natAbs_ne_zero.mpr (determinant_ne_zero hqr))) + (common_prime_product_dvd P a hqr hP) + have hpow : z^(α*((commonAligners P a q r).card : ℝ)) ≤ z^C := by + calc + _ = ∏ _p ∈ commonAligners P a q r,z^α := by + rw [Finset.prod_const,Real.rpow_mul_natCast (by linarith : 0 ≤ z)] + _ ≤ ∏ p ∈ commonAligners P a q r,(p : ℝ) := + Finset.prod_le_prod₀ (fun _ _ => Real.rpow_nonneg (by linarith) _) + (fun p hp => hlarge p (Finset.mem_filter.mp hp).1) + _ = ((∏ p ∈ commonAligners P a q r,p : ℕ) : ℝ) := by simp + _ ≤ ((determinant q r).natAbs : ℝ) := by exact_mod_cast hprod + _ ≤ _ := hheight + have h := (Real.rpow_le_rpow_left_iff hz).mp hpow + apply (le_div_iff₀ hα).mpr + nlinarith only [h] + +end ErdosInverseAlignment + +end + +section + +namespace ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem prime_rational_list_bound (P : Finset ℕ) (a : ℕ → ℤ) (HA HD : ℕ) + {z α C c : ℝ} (hz : 1 < z) (hα : 0 < α) (hC : 0 ≤ C) (hc : 0 < c) + (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,z^α ≤ (p : ℝ)) + (hheight : ((2*HA*HD : ℕ) : ℝ) ≤ z^C) (hPpos : 0 < P.card) + (henough : 2*(C/α) ≤ c^2*(P.card : ℝ)) : + ((rationalList P a HA HD c).card : ℝ) ≤ 2/c^2 := by + apply ErdosInverseIncidence.dense_incidence_card_bound + (rationalList P a HA HD c) P (fun q p => aligns a q p) hc (div_nonneg hC hα.le) hPpos + · intro q hq + exact (mem_rationalList P a HA HD c q).mp hq |>.2.2 + · intro q hq r hr hqr + obtain ⟨hqa,hqd,_⟩ := (mem_rationalList P a HA HD c q).mp hq + obtain ⟨hra,hrd,_⟩ := (mem_rationalList P a HA HD c r).mp hr + apply common_primes_power_height_bound P a hqr hP hz hα hlarge + exact (show ((determinant q r).natAbs : ℝ) ≤ ((2*HA*HD : ℕ) : ℝ) by + exact_mod_cast determinant_height q r HA HD hqa hra hqd hrd).trans hheight + · exact henough + +theorem prime_rational_list_card_le_ceil (P : Finset ℕ) (a : ℕ → ℤ) (HA HD : ℕ) + {z α C c : ℝ} (hz : 1 < z) (hα : 0 < α) (hC : 0 ≤ C) (hc : 0 < c) + (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,z^α ≤ (p : ℝ)) + (hheight : ((2*HA*HD : ℕ) : ℝ) ≤ z^C) (hPpos : 0 < P.card) + (henough : 2*(C/α) ≤ c^2*(P.card : ℝ)) : + (rationalList P a HA HD c).card ≤ ⌈2/c^2⌉₊ := by + have h := (prime_rational_list_bound P a HA HD hz hα hC hc hP hlarge hheight hPpos henough).trans + (Nat.le_ceil (2/c^2)) + exact_mod_cast h + +end ErdosInverseAlignment + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeTailSplit.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeTailSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..8181b97e1cdee02a991f8f3767b28dc7782e8a26 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeTailSplit.lean @@ -0,0 +1,171 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.GrowingFarTail +import OAI.NumberTheory.Jacobsthal.Partitions.SuccessfulTailTransport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.InitialPrimeTail + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain DerivativeWeights +open PrimeExponentialTail ExponentialMeshTail SuccessfulTailTransport + +noncomputable def initialConstant : ℝ := 8/weight .even (23/10) + +theorem initialConstant_pos : 0 < initialConstant := + div_pos (by norm_num) (weight_pos (by norm_num [Valid])) + +noncomputable def initialBudget (c B : ℝ) : ℝ := (initialConstant/c^2)*Real.exp (-(c/2)*B) + +theorem initialBudget_tendsto_zero {c : ℝ} (hc : 0 < c) : Tendsto (initialBudget c) atTop (𝓝 0) := by + have h := tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (0:ℝ) (c/2) (by linarith : 0 < c/2) + have h' := h.const_mul (initialConstant/c^2) + change Tendsto (fun B : ℝ => (initialConstant/c^2)*Real.exp (-(c/2)*B)) atTop (𝓝 0) + simpa only [Real.rpow_zero,one_mul,mul_zero] using h' + +theorem initial_tail_integral (w ell S c K : ℝ) (start : Node) : + (∫⁻ z,tailReward c K z ∂pathLaw w ell S start 0) = + tailReward c K (some (History.empty : History w ell S start)) := by + change (∫⁻ z,tailReward c K z ∂Measure.dirac (some History.empty)) = _ + rw [lintegral_dirac' _ (measurable_of_countable _)] + +theorem clean_initial_integral (w ell S c K mesh : ℝ) (start : Node) (hs : Valid start.side start.ratio) : + (∫⁻ z,cleanReward c K z ∂CouplingData.sourceLaw w ell S start hs mesh 0) = + tailReward c K (some (History.empty : History w ell S start)) := by + change (∫⁻ z,cleanReward c K z ∂Measure.dirac (FlaggedSourceStart.sourceJoint w ell S start hs,false)) = _ + rw [lintegral_dirac' _ (cleanReward_measurable c K)] + rfl + +theorem source_initial_tail {w ell S B c K : ℝ} {start : Node} + (hc : 0 < c) (hB : 0 < B) (hsize : B ≤ start.gap) + (hi : start.side = .even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) : + tailReward c K (some (History.empty : History w ell S start)) ≤ ENNReal.ofReal (initialBudget c B) := by + have hr : 0 < start.gap := hB.trans_le hsize + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hφ := weight_pos hs + have hφend : 0 < weight .even (23/10) := weight_pos (by norm_num [Valid]) + have hmono : weight .even (23/10) ≤ weight start.side start.ratio := by + rw [hi] + exact TwoStepDensityBounds.weight_antitone (by change 198/100 ≤ start.ratio; linarith) (by norm_num [Valid]) h23 + have hinv := one_div_le_one_div_of_le hφend hmono + have hraw := quadratic_exp_majorant hc hr.le + have hexp : Real.exp (-c*start.gap/2) ≤ Real.exp (-(c/2)*B) := Real.exp_le_exp.mpr (by nlinarith) + have hbound : start.gap^2*Real.exp (-c*start.gap)/weight start.side start.ratio ≤ initialBudget c B := by + calc + _ = (start.gap^2*Real.exp (-c*start.gap))*(1/weight start.side start.ratio) := by ring + _ ≤ ((8/c^2)*Real.exp (-c*start.gap/2))*(1/weight .even (23/10)) := + mul_le_mul hraw hinv (by positivity) (by positivity) + _ ≤ ((8/c^2)*Real.exp (-(c/2)*B))*(1/weight .even (23/10)) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hexp (by positivity)) (by positivity) + _ = _ := by unfold initialBudget initialConstant; ring + change (if K < start.gap then ENNReal.ofReal _ else 0) ≤ _ + split_ifs + · exact ENNReal.ofReal_le_ofReal hbound + · exact zero_le + +end NumberTheoryLean.InitialPrimeTail + +end + +section + + +namespace NumberTheoryLean.PrimeTailSplit + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling +open PersistentFailureFlag FlaggedOccupationBound PrimeExponentialTail +open SuccessfulTailTransport ModerateFailedReward InitialPrimeTail + +variable {w ell S : ℝ} {start : Node} + +theorem tail_split_pointwise (c K T : ℝ) (q : FlagState (JointState w ell S start)) : + tailReward c K q.1.1 ≤ cleanReward c K q+ + selected (fun p : JointState w ell S start => moderateReward c T p.1) q+tailReward c T q.1.1 := by + rcases q with ⟨⟨p,y⟩,b⟩ + cases b with + | false => + simp only [cleanReward,selected_false,add_zero] + exact le_add_of_nonneg_right zero_le + | true => + simp only [cleanReward,Bool.true_eq_false,ite_false,selected_true,zero_add] + cases p with + | none => simp [tailReward,moderateReward] + | some h => + by_cases hK : K < h.node.gap + · rw [tailReward,ite_eq_left hK] + by_cases hT : h.node.gap ≤ T + · simp only [moderateReward,PrimeCompactVisits.visit,ite_eq_left hT,ENNReal.ofReal_one,mul_one] + exact le_add_of_nonneg_right zero_le + · rw [tailReward,ite_eq_left (lt_of_not_ge hT)] + exact le_add_of_nonneg_left zero_le + · rw [tailReward,ite_eq_right hK] + exact zero_le + +theorem finite_le_initial_plus_successors (a : ℕ → ℝ≥0∞) (N : ℕ) : + (∑ n ∈ range N,a n) ≤ a 0+∑ n ∈ range N,a (n+1) := by + calc + _ ≤ ∑ n ∈ range (N+1),a n := by rw [Finset.sum_range_succ]; exact le_add_of_nonneg_right zero_le + _ = _ := by rw [Finset.sum_range_succ']; exact add_comm _ _ + +private theorem add_tail_bounds {a b c x y p q : ℝ≥0∞} + (ha : a ≤ x + p) (hc : c ≤ y + q) : a + b + c ≤ x + y + p + b + q := by + calc + _ ≤ (x + p) + b + (y + q) := add_le_add (add_le_add ha (le_refl b)) hc + _ = _ := by ac_rfl + +variable (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) + +include hw hell hS0 hS hr hsS in + +theorem actual_finite_tail_split (c K T mesh : ℝ) (N : ℕ) : + (∑ n ∈ range N,∫⁻ z,tailReward c K z ∂pathLaw w ell S start n) ≤ + tailReward c K (some (History.empty : History w ell S start))+ + tailReward c T (some (History.empty : History w ell S start))+ + (∑ n ∈ range N,∫⁻ q,cleanReward c K q ∂CouplingData.sourceLaw w ell S start hs mesh (n+1))+ + (∑ n ∈ range N,∫⁻ q,selected (fun p : JointState w ell S start => moderateReward c T p.1) q + ∂CouplingData.sourceLaw w ell S start hs mesh n)+ + (∑ n ∈ range N,∫⁻ z,tailReward c T z ∂pathLaw w ell S start (n+1)) := by + have htail (R : ℝ) : Measurable (tailReward (w:=w) (ell:=ell) (S:=S) (start:=start) c R) := measurable_of_countable _ + have hmod : Measurable (fun p : JointState w ell S start => moderateReward c T p.1) := + (measurable_of_countable (moderateReward c T)).comp measurable_fst + have hone : ∀ n : ℕ,(∫⁻ z,tailReward c K z ∂pathLaw w ell S start n) ≤ + (∫⁻ q,cleanReward c K q ∂CouplingData.sourceLaw w ell S start hs mesh n)+ + (∫⁻ q,selected (fun p : JointState w ell S start => moderateReward c T p.1) q + ∂CouplingData.sourceLaw w ell S start hs mesh n)+ + (∫⁻ z,tailReward c T z ∂pathLaw w ell S start n) := by + intro n + have he := CouplingData.source_prime hw hell hS0 hS hr hs hsS mesh n + rw [← he,lintegral_map (g:=fun q : FlagState (JointState w ell S start) => q.1.1) + (htail K) (measurable_fst.comp measurable_fst)] + have h := lintegral_mono (μ:=CouplingData.sourceLaw w ell S start hs mesh n) (tail_split_pointwise c K T) + rw [lintegral_add_left (f:=fun q : FlagState (JointState w ell S start) => cleanReward c K q+selected (fun p : JointState w ell S start => moderateReward c T p.1) q) + ((cleanReward_measurable c K).add (selected_measurable hmod)), + lintegral_add_left (cleanReward_measurable c K)] at h + rw [← lintegral_map (g:=fun q : FlagState (JointState w ell S start) => q.1.1) + (htail T) (measurable_fst.comp measurable_fst),he] at h + rw [he] + exact h + have hclean := finite_le_initial_plus_successors + (fun n => ∫⁻ q,cleanReward c K q ∂CouplingData.sourceLaw w ell S start hs mesh n) N + rw [clean_initial_integral] at hclean + have hfar := finite_le_initial_plus_successors (fun n => ∫⁻ z,tailReward c T z ∂pathLaw w ell S start n) N + rw [initial_tail_integral] at hfar + have hsum := Finset.sum_le_sum (s:=range N) (fun n _ => hone n) + rw [Finset.sum_add_distrib,Finset.sum_add_distrib] at hsum + exact hsum.trans (add_tail_bounds hclean hfar) + +end NumberTheoryLean.PrimeTailSplit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeWordArithmetic.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeWordArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..9020295677ad52525072a849b0fea708b9e95046 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrimeWordArithmetic.lean @@ -0,0 +1,174 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.HypotheticalSubbinLower +import OAI.NumberTheory.Jacobsthal.Sieve.LastPrimeModulusCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedArithmetic +open ErdosStoppedTagSieve Erdos970Dependency.SiegelWalfisz + ErdosInverseCounts ErdosInverseAlignment ErdosHypotheticalTag + ErdosPrimeInputs.MertensStrong NumberTheoryLean + +attribute [local instance] Classical.propDecidable + +noncomputable def primeHypothetical (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q p : ℕ) : ℝ := + if hp : p.Prime then + (modulusCount Y small (@hypotheticalClass a r p ⟨hp.ne_zero⟩) (p*q) : ℝ) + else 0 + +theorem primeHypothetical_on_prime (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q p : ℕ) (hp : p.Prime) : + primeHypothetical Y small a r q p = + (modulusCount Y small (@hypotheticalClass a r p ⟨hp.ne_zero⟩) (p*q) : ℝ) := by + simp only [primeHypothetical,dite_eq_left hp] + +theorem primeHypothetical_row (Y : ℕ) (small T : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q : ℕ) (hT : ∀ p ∈ T,p.Prime) (p : T) : + primeHypothetical Y small a r q p.val=hypotheticalRowCount Y small T a r q hT p := by + exact primeHypothetical_on_prime Y small a r q p.val (hT p.val p.property) + +theorem primeHypothetical_sum (Y : ℕ) (small T : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q : ℕ) (hT : ∀ p ∈ T,p.Prime) : + (∑ p ∈ T,primeHypothetical Y small a r q p)= + ∑ p : T,hypotheticalRowCount Y small T a r q hT p := by + rw [← Finset.sum_coe_sort T] + exact Finset.sum_congr rfl (fun p _ => primeHypothetical_row Y small T a r q hT p) + +theorem primeHypothetical_agrees (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q p : ℕ) (hp : p.Prime) (ha : aligns (fun t => (a t : ℤ)) r p) : + primeHypothetical Y small a r q p=(modulusCount Y small a (p*q) : ℝ) := by + rw [primeHypothetical_on_prime Y small a r q p hp] + let : NeZero p := ⟨hp.ne_zero⟩ + rw [hypothetical_count_agrees Y small a r (p*q) p hp ha] + +theorem strict_smallPrimeSet_nat (P : ℕ) : + smallPrimeSet (P : ℝ)=LargePrimeDeletion.cutoffPrimes (P-1) := by + ext t + rw [mem_smallPrimeSet,LargePrimeDeletion.mem_cutoffPrimes] + constructor + · rintro ⟨ht,hlt⟩ + have hlt' : t < P := by exact_mod_cast hlt + exact ⟨ht,by omega⟩ + · rintro ⟨ht,hle⟩ + have hlt : t < P := by have := ht.two_le;omega + exact ⟨ht,by exact_mod_cast hlt⟩ + +theorem primeHypothetical_uniform_upper : + ∃ C eta0 : ℝ,0 < C ∧ 0 < eta0 ∧ eta0 ≤ 1/4 ∧ 2*C*eta0 ≤ 1/20 ∧ + ∃ P0 : ℕ,2 ≤ P0 ∧ ∀ P : ℕ,P.Prime → P0 ≤ P → + ∀ Y q p : ℕ,∀ r : ℚ,∀ a : ℕ → ℕ, + 0 < Y → p.Prime → Squarefree (p*q) → + (∀ t ∈ (p*q).primeFactors,P ≤ t) → (P : ℝ)^2 ≤ (Y : ℝ)/(p*q : ℕ) → + primeHypothetical Y (smallPrimeSet (P : ℝ)) a r q p ≤ + C*((Y : ℝ)/(p*q : ℕ))*primeProduct (P : ℝ) := by + obtain ⟨C,hC,P0,hP0,hUpper⟩ := original_individual_upper_closed + refine ⟨C,min (1/4) (1/(40*C)),hC,lt_min (by norm_num) (by positivity), + min_le_left _ _,?_,P0,hP0,?_⟩ + · have hh := mul_le_mul_of_nonneg_left (min_le_right (1/4 : ℝ) (1/(40*C))) + (show 0 ≤ 2*C by positivity) + have he : 2*C*(1/(40*C))=(1/20 : ℝ) := by field_simp;ring + exact hh.trans_eq he + · intro P hPrime hP Y q p r a hY hp hsf hlarge hJ + rw [primeHypothetical_on_prime Y _ a r q p hp,strict_smallPrimeSet_nat] + exact hUpper P hPrime hP Y (p*q) _ hY hsf hlarge hJ + +end ErdosStoppedArithmetic + + + +namespace ErdosStoppedArithmetic +open ErdosInverseCounts ErdosInverseAlignment ErdosStoppedTagSieve + NumberTheoryLean.LastPrimeModulusCount + + +theorem prime_word_product (ps : List ℕ) (hd : ps.Pairwise (· > ·)) + (hprime : ∀ p ∈ ps,p.Prime) : + 0 < ps.prod ∧ Squarefree ps.prod ∧ ps.prod.primeFactors=ps.toFinset := by + have hn : ps.Nodup := hd.imp (fun h => ne_of_gt h) + have hpos : 0 < ps.prod := List.prod_pos (fun p hp => (hprime p hp).pos) + have he : (∏ p ∈ ps.toFinset,p)=ps.prod := by + simpa only [List.map_id'] using List.prod_toFinset (fun p : ℕ => p) hn + have hprimeF : ∀ p ∈ ps.toFinset,p.Prime := fun p hp => hprime p (List.mem_toFinset.mp hp) + have hsq : Squarefree (∏ p ∈ ps.toFinset,p) := by + apply Finset.squarefree_prod_of_pairwise_isCoprime + · intro p hp q hq hpq + simp only [← Nat.coprime_iff_isRelPrime] + exact (Nat.coprime_primes (hprimeF p hp) (hprimeF q hq)).mpr hpq + · exact fun p hp => (hprimeF p hp).squarefree + refine ⟨hpos,by rwa [he] at hsq,?_⟩ + rw [← he] + exact primeFactors_product ps.toFinset hprimeF + +theorem last_prime_mem (ps : List ℕ) (hne : ps≠[]) : ps.getLastD 0 ∈ ps := by + rw [← List.dropLast_append_getLast hne,List.getLastD_concat] + simp + +theorem fixed_tail_arithmetic (pre tail : List ℕ) (p : ℕ) (htail : tail ≠ []) + (hd : (pre++p::tail).Pairwise (· > ·)) + (hprime : ∀ t ∈ pre++p::tail,t.Prime) (a : ℕ → ℤ) (r : ℚ) + (hAlign : ∀ t ∈ pre++tail,aligns a r t) : + (tail.getLastD 0).Prime ∧ 0 < pre.prod*tail.prod ∧ + Squarefree (p*(pre.prod*tail.prod)) ∧ + (∀ t ∈ (p*(pre.prod*tail.prod)).primeFactors,tail.getLastD 0 ≤ t) ∧ + p ∉ smallPrimeSet (tail.getLastD 0 : ℝ) ∧ + (∀ t ∈ smallPrimeSet (tail.getLastD 0 : ℝ),(pre.prod*tail.prod).Coprime t) ∧ + ∀ t ∈ (p*(pre.prod*tail.prod)).primeFactors,t ≠ p → aligns a r t := by + have hLastTail := last_prime_mem tail htail + have hLast : (tail.getLastD 0).Prime := hprime _ + (List.mem_append.mpr (Or.inr (List.mem_cons.mpr (Or.inr hLastTail)))) + have hprod := prime_word_product (pre++p::tail) hd hprime + have he : (pre++p::tail).prod=p*(pre.prod*tail.prod) := by + simp only [List.prod_append,List.prod_cons];ring + rw [he] at hprod + have hqpos : 0 < pre.prod*tail.prod := by + by_contra hn + have hz : pre.prod*tail.prod=0 := by omega + have hh := hprod.1 + rw [hz,mul_zero] at hh + omega + have hlastWord : (pre++p::tail).getLastD 0=tail.getLastD 0 := by + rw [← List.dropLast_append_getLast htail] + rw [← List.cons_append,← List.append_assoc] + simp only [List.getLastD_concat] + have hlow : ∀ t ∈ (p*(pre.prod*tail.prod)).primeFactors,tail.getLastD 0 ≤ t := by + have hh := (below_all_last (pre++p::tail) (by simp) hd (tail.getLastD 0-1)).mpr + (by rw [hlastWord];exact Nat.sub_lt hLast.pos (by norm_num)) + intro t ht + rw [hprod.2.2] at ht + have h := hh t (List.mem_toFinset.mp ht) + omega + have hPp : tail.getLastD 0 < p := + (List.pairwise_cons.mp (List.pairwise_append.mp hd).2.1).1 _ hLastTail + refine ⟨hLast,hqpos,hprod.2.1,hlow,?_,?_,?_⟩ + · intro hp + have hh := ((mem_smallPrimeSet _ p).mp hp).2 + have hpp : (tail.getLastD 0 : ℝ) < p := by exact_mod_cast hPp + linarith + · intro t ht + obtain ⟨htPrime,htP⟩ := (mem_smallPrimeSet _ t).mp ht + apply Nat.Coprime.symm + apply htPrime.coprime_iff_not_dvd.mpr + intro htq + have htd : t ∣ p*(pre.prod*tail.prod) := dvd_mul_of_dvd_right htq p + have htf : t ∈ (p*(pre.prod*tail.prod)).primeFactors := + Nat.mem_primeFactors.mpr ⟨htPrime,htd,hprod.1.ne'⟩ + have h := hlow t htf + have htP' : t < tail.getLastD 0 := by exact_mod_cast htP + omega + · intro t ht hne + rw [hprod.2.2] at ht + have hm := List.mem_toFinset.mp ht + apply hAlign t + simp only [List.mem_append,List.mem_cons] at hm ⊢ + tauto + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/PrincipalPrimePowers.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrincipalPrimePowers.lean new file mode 100644 index 0000000000000000000000000000000000000000..72450b1958772a930ff56ea607400d809ebfa84e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/PrincipalPrimePowers.lean @@ -0,0 +1,110 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.SharpCharacterLogPower + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +noncomputable def principalDifference (q : ℕ) [NeZero q] (n : ℕ) : ℂ := + (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)- + (ArithmeticFunction.vonMangoldt n:ℂ) + +lemma principalDifference_norm_le (q : ℕ) [NeZero q] (n : ℕ) : + ‖principalDifference q n‖ ≤ ArithmeticFunction.vonMangoldt n := by + unfold principalDifference + by_cases hu : IsUnit (n:ZMod q) + · rw [MulChar.one_apply hu,one_mul,sub_self,norm_zero] + exact ArithmeticFunction.vonMangoldt_nonneg + · rw [MulChar.map_nonunit _ hu,zero_mul,zero_sub,norm_neg,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (ArithmeticFunction.vonMangoldt_nonneg (n := n))] + +lemma excluded_primePower_dvd_power (q : ℕ) [NeZero q] {N n : ℕ} + (hn : n ≤ N) (hLambda : ArithmeticFunction.vonMangoldt n ≠ 0) + (hu : ¬IsUnit (n:ZMod q)) : n ∣ q^(Nat.log 2 N) := by + obtain ⟨p,k,hp,hk,he⟩ := (isPrimePow_nat_iff n).mp + (ArithmeticFunction.vonMangoldt_ne_zero_iff.mp hLambda) + have hpq : p ∣ q := by + by_contra h + apply hu + rw [← he,Nat.cast_pow] + exact ((ZMod.isUnit_prime_iff_not_dvd hp).mpr h).pow k + have h2 : 2^k ≤ n := by rw [← he]; gcongr; exact hp.two_le + have hkN : k ≤ Nat.log 2 N := Nat.le_log_of_pow_le (by decide) (h2.trans hn) + rw [← he] + exact (pow_dvd_pow p hkN).trans (pow_dvd_pow_of_dvd hpq _) + +lemma principalDifference_eq_zero_of_not_dvd (q : ℕ) [NeZero q] {N n : ℕ} + (hn : n ≤ N) (hnd : ¬n ∣ q^(Nat.log 2 N)) : principalDifference q n = 0 := by + by_cases hl : ArithmeticFunction.vonMangoldt n = 0 + · simp only [principalDifference,hl,Complex.ofReal_zero,mul_zero,sub_self] + · by_cases hu : IsUnit (n:ZMod q) + · simp only [principalDifference,MulChar.one_apply hu,one_mul,sub_self] + · exact (hnd (excluded_primePower_dvd_power q hn hl hu)).elim + +theorem norm_principal_sharp_difference (q : ℕ) [NeZero q] (X : ℝ) : + ‖sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ + (Nat.log 2 ⌊X⌋₊:ℝ)*Real.log (q:ℝ) := by + let K : ℕ := Nat.log 2 ⌊X⌋₊ + let N := Finset.range (⌊X⌋₊+1) + let D := (q^K).divisors + let S := N ∩ D + have hqpow : q^K ≠ 0 := pow_ne_zero _ (NeZero.ne q) + have hsub : S ⊆ N := Finset.inter_subset_left + have hsum : (∑ n ∈ S, principalDifference q n) = ∑ n ∈ N, principalDifference q n := by + apply Finset.sum_subset hsub + intro n hn hnS + have hn' : n ≤ ⌊X⌋₊ := by simpa only [N,Finset.mem_range,Nat.lt_add_one_iff] using hn + apply principalDifference_eq_zero_of_not_dvd q hn' + intro hd + apply hnS + exact Finset.mem_inter.mpr ⟨hn,Nat.mem_divisors.mpr ⟨hd,hqpow⟩⟩ + unfold sharpSum + rw [← Finset.sum_sub_distrib] + change ‖∑ n ∈ N, principalDifference q n‖ ≤ (K:ℝ)*Real.log (q:ℝ) + rw [← hsum] + calc + _ ≤ ∑ n ∈ S, ‖principalDifference q n‖ := norm_sum_le _ _ + _ ≤ ∑ n ∈ S, ArithmeticFunction.vonMangoldt n := Finset.sum_le_sum (fun n _ => principalDifference_norm_le q n) + _ ≤ ∑ n ∈ D, ArithmeticFunction.vonMangoldt n := + Finset.sum_le_sum_of_subset_of_nonneg Finset.inter_subset_right (fun n _ _ => ArithmeticFunction.vonMangoldt_nonneg) + _ = Real.log ((q^K:ℕ):ℝ) := ArithmeticFunction.vonMangoldt_sum + _ = _ := by rw [Nat.cast_pow,Real.log_pow] + +lemma natLog_floor_le_realLog {X : ℝ} (hX : 1 ≤ X) : + (Nat.log 2 ⌊X⌋₊:ℝ) ≤ Real.log X/Real.log 2 := by + have hfloor : ⌊X⌋₊ ≠ 0 := by + intro hz + have h := Nat.lt_floor_add_one X + rw [hz] at h + norm_num at h + linarith + have hNat := Nat.pow_log_le_self 2 hfloor + have hp : (2:ℝ)^(Nat.log 2 ⌊X⌋₊) ≤ X := + (show (2:ℝ)^(Nat.log 2 ⌊X⌋₊) ≤ (⌊X⌋₊:ℝ) by exact_mod_cast hNat).trans + (Nat.floor_le (by linarith)) + have hlog := Real.log_le_log (by positivity : (0:ℝ) < 2^(Nat.log 2 ⌊X⌋₊)) hp + rw [Real.log_pow] at hlog + exact (le_div_iff₀ (Real.log_pos (by norm_num : (1:ℝ) < 2))).mpr hlog + +theorem norm_principal_sharp_difference_real (q : ℕ) [NeZero q] {X : ℝ} (hX : 1 ≤ X) : + ‖sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ + (Real.log X/Real.log 2)*Real.log (q:ℝ) := by + apply (norm_principal_sharp_difference q X).trans + exact mul_le_mul_of_nonneg_right (natLog_floor_le_realLog hX) + (Real.log_nonneg (by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q))) + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/ProgressionPrimeUpper.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/ProgressionPrimeUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd72b61f752e60cc99fee292cebf3d7697337bad --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/ProgressionPrimeUpper.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.SieveScale + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosPrimeInputs.ProgressionPrimeUpper + +open _root_.Finset +open NumberTheoryLean.LargePrimeDeletion +open SubsetPrimeSieve PrimeProductOmissions AffinePrimeSieve SieveScale + +lemma reduced_coprime {z q p : ℕ} (hq : 0 < q) (hp : p ∈ reducedPrimes z q) : q.Coprime p := by + obtain ⟨hpz,hpq⟩ := mem_sdiff.mp hp + have hprime := (mem_cutoffPrimes.mp hpz).1 + apply (hprime.coprime_iff_not_dvd.mpr ?_).symm + intro hd + exact hpq (Nat.mem_primeFactors.mpr ⟨hprime,hd,Nat.ne_of_gt hq⟩) + +lemma modulus_factor_ge_one {q : ℕ} (hq : 0 < q) : 1 ≤ (q:ℝ)/q.totient := by + have ht : (0:ℝ) < q.totient := by exact_mod_cast Nat.totient_pos.mpr hq + apply (le_div_iff₀ ht).mpr + simpa only [one_mul] using (show (q.totient:ℝ) ≤ q by exact_mod_cast Nat.totient_le q) + +theorem progression_prime_upper : ∃ C J₀ : ℝ, 0 < C ∧ 1 < J₀ ∧ + ∀ (N : ℕ) (a : ℤ) (q : ℕ) (J : ℝ), J₀ ≤ J → 0 < q → |(N:ℝ)-J| ≤ 1 → + ((primeIndices N a q).card:ℝ) ≤ C * J * ((q:ℝ)/q.totient) / Real.log J := by + obtain ⟨K,u₀,hK,hu₀,hEuler⟩ := reduced_product_upper + obtain ⟨J₀,hJ₀,hcut⟩ := cutoff_eventually_ge u₀ + have hα := exponent_pos + refine ⟨2*K/exponent+6,J₀,by positivity,hJ₀,?_⟩ + intro N a q J hJ hq hNJ + have hJ1 : 1 < J := hJ₀.trans_le hJ + have hJ0 : 0 < J := by linarith + have hlog := Real.log_pos hJ1 + let u := cutoff J + have huBase : u₀ ≤ u := hcut J hJ + have hu2 : 2 ≤ u := hu₀.trans huBase + have hu0 : 0 ≤ u := by linarith + let P := reducedPrimes ⌊u⌋₊ q + let R : ℝ := (q:ℝ)/q.totient + have hR : 1 ≤ R := modulus_factor_ge_one hq + have hP : ∀ p ∈ P, p.Prime := fun p hp => (mem_cutoffPrimes.mp (mem_sdiff.mp hp).1).1 + have hsize : ∀ p ∈ P, (p:ℝ) ≤ u := by + intro p hp + have hh := (mem_cutoffPrimes.mp (mem_sdiff.mp hp).1).2 + exact (show (p:ℝ) ≤ (⌊u⌋₊:ℝ) by exact_mod_cast hh).trans (Nat.floor_le hu0) + have hcop : ∀ p ∈ P, q.Coprime p := fun p hp => reduced_coprime hq hp + have hEpos := (euler_pos hP).le + have hsieve := affine_sieve_error N a q u level J P hu2 (by norm_num [level]) hJ0.le hNJ hP hsize hcop + have hpow : u ^ level = Real.sqrt J := cutoff_power hJ0.le + rw [hpow] at hsieve + have hexp : Real.exp (-level/96) ≤ 1 := Real.exp_le_one_iff.mpr (by norm_num [level]) + have hsurv : ((survivors N a q P).card:ℝ) ≤ 2*J*euler P + 2*Real.sqrt J := by + have hh := (abs_le.mp hsieve).2 + have hm := mul_le_mul_of_nonneg_left hexp (mul_nonneg hJ0.le hEpos) + nlinarith + have hcount : ((primeIndices N a q).card:ℝ) ≤ 2*J*euler P + 3*Real.sqrt J := by + have hh := prime_count_le_sifted_add N a q u P hq hu0 hP hsize + have hu := cutoff_le_sqrt hJ1.le + change u ≤ Real.sqrt J at hu + linarith + have hEuler' : euler P ≤ K*R/Real.log u := hEuler u huBase q hq + have hmain : 2*J*euler P ≤ (2*K/exponent)*J*R/Real.log J := by + calc + _ ≤ 2*J*(K*R/Real.log u) := mul_le_mul_of_nonneg_left hEuler' (by positivity) + _ = _ := by + change 2*J*(K*R/Real.log (cutoff J)) = _ + rw [log_cutoff hJ0] + field_simp + have hsqrt : Real.sqrt J ≤ 2*J*R/Real.log J := by + calc + _ ≤ 2*J/Real.log J := sqrt_le_log_scale hJ1 + _ = (2*J/Real.log J)*1 := by ring + _ ≤ (2*J/Real.log J)*R := mul_le_mul_of_nonneg_left hR (by positivity) + _ = _ := by ring + have herr : 3*Real.sqrt J ≤ 6*J*R/Real.log J := by + calc + _ ≤ 3*(2*J*R/Real.log J) := mul_le_mul_of_nonneg_left hsqrt (by norm_num) + _ = _ := by ring + calc + _ ≤ 2*J*euler P + 3*Real.sqrt J := hcount + _ ≤ (2*K/exponent)*J*R/Real.log J + 6*J*R/Real.log J := add_le_add hmain herr + _ = _ := by ring + +end ErdosPrimeInputs.ProgressionPrimeUpper + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/ReferenceSourcePrimeSets.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/ReferenceSourcePrimeSets.lean new file mode 100644 index 0000000000000000000000000000000000000000..81a4ba96341f6b0d81acb0e339a35d93bbbef62d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/ReferenceSourcePrimeSets.lean @@ -0,0 +1,265 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceCutoffRecurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceMertens + +open _root_.Filter Asymptotics +open scoped Topology +open ReferenceProductsBasics ErdosPrimeInputs.MertensStrong + +noncomputable def normalization (w : ℝ) : ℝ := + Real.exp (-Real.eulerMascheroniConstant)/(Real.log w*primeProduct w) + +noncomputable def referenceProduct (w b : ℝ) (closed : Bool) : ℝ := + availableProduct w (w^b) closed + +theorem normalization_pos {w : ℝ} (hw : 1 < w) : 0 < normalization w := + div_pos (Real.exp_pos _) (mul_pos (Real.log_pos hw) (actual_primeProduct_pos w)) + +theorem normalization_eq_exp {w : ℝ} (hw : 1 < w) : + normalization w=Real.exp (-_root_.Erdos970.Mertens.E₃ w) := by + unfold normalization primeProduct + rw [_root_.Erdos970.Mertens.prod_one_minus_div_prime_eq hw,Real.exp_neg] + field_simp [ne_of_gt (Real.log_pos hw)] + rw [← Real.exp_add,add_neg_cancel,Real.exp_zero] + +theorem normalization_tendsto_one : Tendsto normalization atTop (𝓝 1) := by + have h := (isLittleO_one_iff ℝ).mp _root_.Erdos970.Mertens.E₃.bound' + have hl : Tendsto (fun w => Real.exp (-_root_.Erdos970.Mertens.E₃ w)) atTop (𝓝 1) := by + convert! Real.continuous_exp.continuousAt.tendsto.comp h.neg using 1 + norm_num + apply hl.congr' + filter_upwards [eventually_gt_atTop (1:ℝ)] with w hw + exact (normalization_eq_exp hw).symm + +theorem closed_normalized_identity {w b : ℝ} (hw : 1 < w) (hb : 1 ≤ b) : + referenceProduct w b true/(normalization w/b)= + primeProduct (w^b)/(Real.exp (-Real.eulerMascheroniConstant)/Real.log (w^b)) := by + have hw0 : 0 < w := by linarith + have hb0 : 0 < b := by linarith + have hwb : w ≤ w^b := by + simpa only [Real.rpow_one] using Real.rpow_le_rpow_of_exponent_le hw.le hb + rw [referenceProduct,closed_product_ratio hw0.le hwb,normalization,Real.log_rpow hw0] + field_simp [ne_of_gt (actual_primeProduct_pos w),ne_of_gt (Real.log_pos hw),ne_of_gt hb0] + +theorem exp_error_mono_rate {c₁ c₂ t : ℝ} (hc : c₂ ≤ c₁) : + Real.exp (-c₁*Real.sqrt t) ≤ Real.exp (-c₂*Real.sqrt t) := + Real.exp_le_exp.mpr (by nlinarith [Real.sqrt_nonneg t]) + +theorem reference_product_strong : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ b : ℝ,2 ≤ b → ∀ closed : Bool, + |referenceProduct w b closed/(normalization w/b)-1| ≤ + C*Real.exp (-c*Real.sqrt (b*Real.log w)) := by + obtain ⟨c,C,x₀,hc,hC,hx₀,hprod⟩ := prime_product_strong + let c' := min c 1 + let W := max x₀ (Real.exp 1) + have hc' : 0 < c' := lt_min hc zero_lt_one + refine ⟨c',3*C+2,W,hc',by positivity, + (by have hh := le_max_left x₀ (Real.exp 1); dsimp [W]; linarith),?_⟩ + intro w hw b hb closed + have hwX : x₀ ≤ w := (le_max_left _ _).trans hw + have hwE : Real.exp 1 ≤ w := (le_max_right _ _).trans hw + have hw1 : 1 < w := by linarith [hx₀.trans hwX] + have hw0 : 0 < w := by linarith + have hb1 : 1 ≤ b := by linarith + have hb0 : 0 < b := by linarith + have hxw : w ≤ w^b := by simpa only [Real.rpow_one] using Real.rpow_le_rpow_of_exponent_le hw1.le hb1 + have hx2 : 2 ≤ w^b := (hx₀.trans hwX).trans hxw + have hx0 : 0 < w^b := Real.rpow_pos_of_pos hw0 b + have hlog : 1 ≤ Real.log (w^b) := by + have hh := Real.log_le_log (Real.exp_pos 1) (hwE.trans hxw) + simpa only [Real.log_exp] using hh + let E := Real.exp (-c'*Real.sqrt (b*Real.log w)) + have hEpos : 0 < E := Real.exp_pos _ + have hE1 : E ≤ 1 := Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc'.le) (Real.sqrt_nonneg _)) + have hclosed : |referenceProduct w b true/(normalization w/b)-1| ≤ C*E := by + rw [closed_normalized_identity hw1 hb1] + have h := hprod (w^b) (hwX.trans hxw) + have hm := exp_error_mono_rate (t:=Real.log (w^b)) (min_le_left c 1) + rw [Real.log_rpow hw0] at h hm ⊢ + exact h.trans (mul_le_mul_of_nonneg_left hm hC.le) + cases closed with + | true => exact hclosed.trans (mul_le_mul_of_nonneg_right (by linarith : C ≤ 3*C+2) hEpos.le) + | false => + let D := normalization w/b + let q := referenceProduct w b true/D + let k := referenceProduct w b false/referenceProduct w b true + have hD : 0 < D := div_pos (normalization_pos hw1) hb0 + have hP : 0 < referenceProduct w b true := availableProduct_pos _ _ _ + have hq0 : 0 < q := div_pos hP hD + have hq : q ≤ C+1 := by + have hh := (abs_le.mp hclosed).2 + have hh' := mul_le_mul_of_nonneg_left hE1 hC.le + dsimp only [q,D] + linarith + have hk : |k-1| ≤ 2/(w^b) := endpoint_relative_bound hx2 + have hrec : 1/(w^b) ≤ E := by + have h := ErdosPrimeInputs.MertensStrong.reciprocal_le_decay (min_le_right c 1) hx0 hlog + simpa only [E,ErdosPrimeInputs.PrimeErrorDecay.decay,Real.log_rpow hw0] using h + have heq : referenceProduct w b false/D=k*q := by + dsimp only [k,q] + field_simp + change |referenceProduct w b false/D-1| ≤ (3*C+2)*E + rw [heq] + calc + _ = |(k-1)*q+(q-1)| := by congr 1; ring + _ ≤ |(k-1)*q|+|q-1| := abs_add_le _ _ + _ = |k-1| *q+|q-1| := by rw [abs_mul,abs_of_pos hq0] + _ ≤ (2/(w^b))*(C+1)+C*E := + add_le_add (mul_le_mul hk hq hq0.le (by positivity)) hclosed + _ ≤ 2*E*(C+1)+C*E := by + apply add_le_add_left + apply mul_le_mul_of_nonneg_right _ (by linarith : 0 ≤ C+1) + simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hrec (by norm_num : (0:ℝ) ≤ 2) + _ = _ := by ring + +end NumberTheoryLean.ReferenceMertens + +end + +section + +namespace NumberTheoryLean.ReferenceSourcePrimeSets + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry PrimeTiltGeometry ReferenceAdmission ReferencePruning ReferenceProductsBasics +open ReferenceMertens ReferenceCutoffRecurrence +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass + +noncomputable def sourcePrimes (w b : ℝ) (closed : Bool) : Finset ℕ := availablePrimes w (w^b) closed +noncomputable def highPrimes (w b : ℝ) (closed : Bool) : Finset ℕ := + (sourcePrimes w b closed).filter (fun p => w^(2:ℝ)<(p:ℝ)) + +theorem availablePrimes_membership {a x : ℝ} (hx : 0 ≤ x) (closed : Bool) (p : ℕ) : + p ∈ availablePrimes a x closed ↔ p.Prime ∧ a<(p:ℝ) ∧ (if closed then (p:ℝ) ≤ x else (p:ℝ) exact (exponent_lt_iff hw hp0).mpr hhi + | true => exact (exponent_le_iff hw hp0).mpr hhi + · rintro ⟨hp,hlo,hhi⟩ + have hp0 : 0 < (p:ℝ) := by exact_mod_cast hp.pos + refine ⟨hp,?_,?_⟩ + · simpa only [Real.rpow_one] using (lt_exponent_iff hw hp0).mp hlo + · cases closed with + | false => exact (exponent_lt_iff hw hp0).mp hhi + | true => exact (exponent_le_iff hw hp0).mp hhi + +theorem highPrimes_membership {w : ℝ} (hw : 1 < w) (b : ℝ) (closed : Bool) (p : ℕ) : + p ∈ highPrimes w b closed ↔ p.Prime ∧ 2 exact hle.trans_lt hb + | true => exact hle.trans hb.le + +theorem sourcePrimes_partition {w b : ℝ} (hw : 1 < w) (hb : 2 < b) (closed : Bool) : + sourcePrimes w b closed=highPrimes w b closed ∪ boundaryPrimes w := by + ext p + constructor + · intro hp + by_cases hhi : w^(2:ℝ)<(p:ℝ) + · exact Finset.mem_union.mpr (Or.inl (Finset.mem_filter.mpr ⟨hp,hhi⟩)) + · have hpm := (sourcePrimes_membership hw b closed p).mp hp + apply Finset.mem_union.mpr + right + rw [← sourcePrimes_boundary] + apply (sourcePrimes_membership hw 2 true p).mpr + refine ⟨hpm.1,hpm.2.1,?_⟩ + exact (exponent_le_iff hw (by exact_mod_cast hpm.1.pos)).mpr (le_of_not_gt hhi) + · intro hp + rcases Finset.mem_union.mp hp with hp | hp + · exact (Finset.mem_filter.mp hp).1 + · exact boundary_subset_source hw hb closed hp + +theorem highPrimes_above_boundary {w b : ℝ} (hw : 1 < w) (closed : Bool) : + Above (highPrimes w b closed) (boundaryPrimes w) := by + intro p hp q hq + have hpHi := (Finset.mem_filter.mp hp).2 + have hqB := boundary_prime_exponent_upper hw hq + have hqP : q.Prime := (Nat.mem_primesLE.mp (Finset.mem_filter.mp hq).1).2 + have hqLe := (exponent_le_iff hw (by exact_mod_cast hqP.pos)).mp hqB + exact_mod_cast hqLe.trans_lt hpHi + +theorem rpow_primeExponent {w : ℝ} (hw : 1 < w) {p : ℕ} (hp : p.Prime) : + w^primeExponent w p=(p:ℝ) := by + have hw0 : 0 < w := by linarith + rw [Real.rpow_def_of_pos hw0] + have he : Real.log w*primeExponent w p=Real.log p := by + unfold primeExponent + field_simp [ne_of_gt (Real.log_pos hw)] + rw [he,Real.exp_log (by exact_mod_cast hp.pos)] + +theorem sourcePrimes_at_selected {w b : ℝ} (hw : 1 < w) (closed : Bool) {p : ℕ} + (hp : p ∈ sourcePrimes w b closed) : + sourcePrimes w (primeExponent w p) false=(sourcePrimes w b closed).filter (fun q => q exact hpM.2.2.le + | true => exact hpM.2.2 + ext q + rw [sourcePrimes_membership hw,Finset.mem_filter,sourcePrimes_membership hw] + constructor + · rintro ⟨hq,hqLo,hqCap⟩ + have hqCap' : primeExponent w q < primeExponent w p := hqCap + have hqP : q

exact hqCap'.trans_le hpCap + | true => exact hqCap'.le.trans hpCap + · rintro ⟨⟨hq,hqLo,_hqCap⟩,hqp⟩ + refine ⟨hq,hqLo,?_⟩ + apply (exponent_lt_iff hw (by exact_mod_cast hq.pos)).mpr + rw [rpow_primeExponent hw hpM.1] + exact_mod_cast hqp + +end NumberTheoryLean.ReferenceSourcePrimeSets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/RieszMellinKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/RieszMellinKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e5f7d5efa914ee9844c650273d2fc0a216077c5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/RieszMellinKernel.lean @@ -0,0 +1,227 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LocalZeroMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz + +lemma modulusHeight_diskPoint_le (q : ℕ) [NeZero q] (t : ℝ) {rho : ℂ} + (hr : ‖rho‖ ≤ 19/20) : + modulusHeight q (dirichletDiskPoint t rho).im ≤ 2*modulusHeight q t := by + have hri : |rho.im| ≤ 19/20 := (Complex.abs_im_le_norm rho).trans hr + have hi : (dirichletDiskPoint t rho).im = t+(5/2:ℝ)*rho.im := by + simp [dirichletDiskPoint,dirichletCenter] + have hdis : |(dirichletDiskPoint t rho).im| ≤ |t|+3 := by + rw [hi] + have h := abs_add_le t ((5/2:ℝ)*rho.im) + rw [abs_mul,abs_of_pos (by norm_num : (0:ℝ) < 5/2)] at h + linarith + have ht := abs_nonneg t + have hq : (1:ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hlq := Real.log_nonneg hq + have hl2 : Real.log 2 ≤ Real.log (|t|+6) := Real.log_le_log (by norm_num) (by linarith) + have hl : Real.log (|(dirichletDiskPoint t rho).im|+6) ≤ Real.log (2*(|t|+6)) := + Real.log_le_log (by positivity) (by linarith) + rw [Real.log_mul (by norm_num : (2:ℝ) ≠ 0) (by positivity : |t|+6 ≠ 0)] at hl + unfold modulusHeight + linarith + +theorem exists_uniform_zero_separation : + ∃ a : ℝ, 0 < a ∧ a ≤ 1/100 ∧ ∀ (q : ℕ) [NeZero q] + (chi : DirichletCharacter ℂ q), chi ≠ 1 → ∀ sigma t : ℝ, + 1-a/(modulusHeight q t)^2 ≤ sigma → + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I) ≠ 0 ∧ + ∀ rho : ℂ, ‖rho‖ ≤ 19/20 → + DirichletCharacter.LFunction chi (dirichletDiskPoint t rho) = 0 → + a/(modulusHeight q t)^2 ≤ ‖((2/5*(sigma-3):ℝ):ℂ)-rho‖ := by + obtain ⟨c,hc,hregion⟩ := exists_nonprincipal_zero_free_region + let a : ℝ := min (c/16) (1/100) + have ha : 0 < a := lt_min (by positivity) (by norm_num) + have hac : a ≤ c/16 := min_le_left _ _ + have ha100 : a ≤ 1/100 := min_le_right _ _ + refine ⟨a,ha,ha100,?_⟩ + intro q _ chi hchi sigma t hs + have hH := modulusHeight_ge_one q t + have hHp : 0 < modulusHeight q t := by linarith + have hHsq : 0 < (modulusHeight q t)^2 := by positivity + constructor + · apply hregion q chi hchi ((sigma:ℂ)+(t:ℂ)*Complex.I) + simp only [show ((sigma:ℂ)+(t:ℂ)*Complex.I).re = sigma by simp, + show ((sigma:ℂ)+(t:ℂ)*Complex.I).im = t by simp] + have hdiv := div_le_div_of_nonneg_right (show a ≤ c by linarith) hHsq.le + linarith + · intro rho hr hz + have hZ := modulusHeight_ge_one q (dirichletDiskPoint t rho).im + have hZp : 0 < modulusHeight q (dirichletDiskPoint t rho).im := by linarith + have hheight := modulusHeight_diskPoint_le q t hr + have hpow : (modulusHeight q (dirichletDiskPoint t rho).im)^2 ≤ + 4*(modulusHeight q t)^2 := by nlinarith + have hdrop : c/(4*(modulusHeight q t)^2) ≤ + c/(modulusHeight q (dirichletDiskPoint t rho).im)^2 := + div_le_div_of_nonneg_left hc.le (by positivity) hpow + have hzeroRe : (dirichletDiskPoint t rho).re < + 1-c/(modulusHeight q (dirichletDiskPoint t rho).im)^2 := by + by_contra! h + exact hregion q chi hchi (dirichletDiskPoint t rho) h hz + have ha4 : 4*(a/(modulusHeight q t)^2) ≤ c/(4*(modulusHeight q t)^2) := by + have h := div_le_div_of_nonneg_right (show 4*a ≤ c/4 by linarith) hHsq.le + convert h using 1 <;> ring + have hdiff : (5/2:ℝ)*((((2/5*(sigma-3):ℝ):ℂ)).re-rho.re) = + sigma-(dirichletDiskPoint t rho).re := by + rw [Complex.ofReal_re,dirichletDiskPoint_re] + ring + have har : 0 ≤ a/(modulusHeight q t)^2 := div_nonneg ha.le hHsq.le + have hsep : a/(modulusHeight q t)^2 ≤ (((2/5*(sigma-3):ℝ):ℂ)).re-rho.re := by + nlinarith only [hs,hzeroRe,hdrop,ha4,hdiff,har] + have hn := Complex.re_le_norm (((2/5*(sigma-3):ℝ):ℂ)-rho) + simp only [Complex.sub_re] at hn + exact hsep.trans hn + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +theorem exists_uniform_nonprincipal_strip_bound : + ∃ a : ℝ, 0 < a ∧ a ≤ 1/100 ∧ ∃ C : ℝ, 0 < C ∧ + ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), chi ≠ 1 → + ∀ sigma t : ℝ, 1-a/(modulusHeight q t)^2 ≤ sigma → sigma ≤ 2 → + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I) ≠ 0 ∧ + ‖deriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I) / + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ + C*(modulusHeight q t)^3 := by + classical + obtain ⟨a,ha,ha100,hsep⟩ := exists_uniform_zero_separation + obtain ⟨C0,hC0,hlocal⟩ := uniform_local_zero_estimates + refine ⟨a,ha,ha100,C0+C0/a,by positivity,?_⟩ + intro q _ chi hchi sigma t hs hs2 + obtain ⟨hne,hseparate⟩ := hsep q chi hchi sigma t hs + refine ⟨hne,?_⟩ + obtain ⟨S,hS,hmass,hbound⟩ := hlocal q chi hchi t + let H : ℝ := modulusHeight q t + have hH : 1 ≤ H := modulusHeight_ge_one q t + have hHp : 0 < H := by linarith + have hHsq : 1 ≤ H^2 := by nlinarith + have hH2 : 0 < H^2 := by positivity + have hr : 0 < a/H^2 := by positivity + have hfrac : a/H^2 ≤ a := by + apply (div_le_iff₀ hH2).mpr + simpa only [mul_one] using mul_le_mul_of_nonneg_left hHsq ha.le + let w : ℂ := ((2/5*(sigma-3):ℝ):ℂ) + have hw : ‖w‖ ≤ 17/20 := by + change ‖((2/5*(sigma-3):ℝ):ℂ)‖ ≤ _ + rw [Complex.norm_real,Real.norm_eq_abs] + change 1-a/H^2 ≤ sigma at hs + exact abs_le.mpr ⟨by linarith,by linarith⟩ + have hwne : DirichletCharacter.LFunction chi (dirichletDiskPoint t w) ≠ 0 := by + rw [dirichletDiskPoint_ofReal] + exact hne + let D : ℂ := deriv (DirichletCharacter.LFunction chi) (dirichletDiskPoint t w) / + DirichletCharacter.LFunction chi (dirichletDiskPoint t w) + let Z : ℂ := ∑ rho ∈ S, (analyticOrderAt (normalizedDirichlet chi t) rho).toNat/(w-rho) + have hterm (rho : ℂ) (hrho : rho ∈ S) : + ‖((analyticOrderAt (normalizedDirichlet chi t) rho).toNat:ℂ)/(w-rho)‖ ≤ + ((analyticOrderAt (normalizedDirichlet chi t) rho).toNat:ℝ)/(a/H^2) := by + rw [norm_div,Complex.norm_natCast] + apply div_le_div_of_nonneg_left (Nat.cast_nonneg _) hr + exact hseparate rho ((hS rho).mp hrho).1 ((hS rho).mp hrho).2 + have hZ : ‖Z‖ ≤ (C0/a)*H^3 := by + calc + _ ≤ ∑ rho ∈ S, ‖((analyticOrderAt (normalizedDirichlet chi t) rho).toNat:ℂ)/(w-rho)‖ := + norm_sum_le _ _ + _ ≤ ∑ rho ∈ S, ((analyticOrderAt (normalizedDirichlet chi t) rho).toNat:ℝ)/(a/H^2) := + Finset.sum_le_sum hterm + _ = (∑ rho ∈ S, ((analyticOrderAt (normalizedDirichlet chi t) rho).toNat:ℝ))/(a/H^2) := by + simp only [Finset.sum_div] + _ ≤ (C0*H)/(a/H^2) := div_le_div_of_nonneg_right hmass hr.le + _ = _ := by field_simp + have hb := hbound w hw hwne + change ‖(5/2:ℂ)*D-Z‖ ≤ C0*H at hb + have ht := norm_add_le ((5/2:ℂ)*D-Z) Z + rw [sub_add_cancel] at ht + have hscale : ‖(5/2:ℂ)*D‖ = (5/2:ℝ)*‖D‖ := by rw [norm_mul]; norm_num + rw [hscale] at ht + have hh2 : H ≤ H^2 := by nlinarith + have hh3 := mul_le_mul_of_nonneg_left hh2 hHp.le + have hcube : H ≤ H^3 := by nlinarith only [hh2,hh3] + have hsmall := mul_le_mul_of_nonneg_left hcube hC0.le + rw [show (sigma:ℂ)+(t:ℂ)*Complex.I = dirichletDiskPoint t w from (dirichletDiskPoint_ofReal sigma t).symm] + change ‖D‖ ≤ (C0+C0/a)*H^3 + nlinarith only [ht,hb,hZ,hsmall,norm_nonneg D] + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Set _root_.Filter +open scoped Topology +attribute [local instance] Classical.propDecidable + +noncomputable def rieszWeight (x : ℝ) : ℝ := max (1-x) 0 +noncomputable def rieszProfile (x : ℝ) : ℂ := + (Ioc (0:ℝ) 1).indicator (fun _ => (1:ℂ)) x - + (Ioc (0:ℝ) 1).indicator (fun t => (t:ℂ)) x +noncomputable def rieszKernel (s : ℂ) : ℂ := 1/(s*(s+1)) + +lemma rieszProfile_eq_weight {x : ℝ} (hx : 0 < x) : rieszProfile x = (rieszWeight x:ℂ) := by + by_cases hx1 : x ≤ 1 + · have hm : x ∈ Ioc (0:ℝ) 1 := ⟨hx,hx1⟩ + simp [rieszProfile,hm,rieszWeight,max_eq_left (sub_nonneg.mpr hx1)] + · have hm : x ∉ Ioc (0:ℝ) 1 := fun h => hx1 h.2 + have hx1' : 1 ≤ x := le_of_lt (lt_of_not_ge hx1) + simp [rieszProfile,hm,rieszWeight,max_eq_right (sub_nonpos.mpr hx1')] + +lemma continuous_rieszWeight : Continuous rieszWeight := by unfold rieszWeight; fun_prop + +lemma continuousAt_rieszProfile {x : ℝ} (hx : 0 < x) : ContinuousAt rieszProfile x := by + have he : rieszProfile =ᶠ[𝓝 x] (fun t => (rieszWeight t:ℂ)) := by + filter_upwards [isOpen_Ioi.mem_nhds hx] with y hy + exact rieszProfile_eq_weight hy + exact (continuousAt_congr he).mpr (Complex.continuous_ofReal.comp continuous_rieszWeight).continuousAt + +theorem hasMellin_rieszProfile {s : ℂ} (hs : 0 < s.re) : + HasMellin rieszProfile s (rieszKernel s) := by + have h0 := hasMellin_one_Ioc hs + have h1 := hasMellin_cpow_Ioc (1:ℂ) (s := s) (by simp only [Complex.one_re]; linarith) + have h1' : HasMellin ((Ioc (0:ℝ) 1).indicator (fun t => (t:ℂ))) s (1/(s+1)) := by + simpa only [Complex.cpow_one] using h1 + have h := hasMellin_sub h0.1 h1'.1 + rw [h0.2,h1'.2] at h + change HasMellin rieszProfile s (1/s-1/(s+1)) at h + have hs0 : s ≠ 0 := by intro hz; simp [hz] at hs + have hs1 : s+1 ≠ 0 := by + intro hz + have he := congrArg Complex.re hz + simp only [Complex.add_re,Complex.one_re,Complex.zero_re] at he + linarith + have he : 1/s-1/(s+1) = rieszKernel s := by + unfold rieszKernel + field_simp + ring + rwa [he] at h + +lemma rieszWeight_nonneg (x : ℝ) : 0 ≤ rieszWeight x := le_max_right _ _ +lemma rieszWeight_le_one {x : ℝ} (hx : 0 ≤ x) : rieszWeight x ≤ 1 := by + unfold rieszWeight + exact max_le (by linarith) zero_le_one +lemma rieszWeight_eq_zero {x : ℝ} (hx : 1 ≤ x) : rieszWeight x = 0 := + max_eq_right (sub_nonpos.mpr hx) + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/SmallEffectivePrimeSplit.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/SmallEffectivePrimeSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..3ff44a1804d183f5a4a335453417637fb08d3486 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/SmallEffectivePrimeSplit.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.EffectiveAvoidance + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosPrimitiveIntercept + +theorem full_cofactor_coprime_small (qf : ℕ) (hq : Squarefree qf) (w : ℝ) + (hlarge : ∀ u ∈ qf.primeFactors,w < (u : ℝ)) (t : ℕ) (ht : t.Prime) (htw : (t : ℝ) ≤ w) : + qf.Coprime t := by + apply Nat.Coprime.symm + apply ht.coprime_iff_not_dvd.mpr + intro hdiv + have hh := hlarge t (Nat.mem_primeFactors.mpr ⟨ht,hdiv,hq.ne_zero⟩) + linarith + +theorem small_dvd_effectiveModulus_iff (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) (w : ℝ) + (hlarge : ∀ u ∈ qf.primeFactors,w < (u : ℝ)) (t : ℕ) (ht : t.Prime) (htw : (t : ℝ) ≤ w) : + t ∣ effectiveModulus a r qf ↔ t ∣ r.den := by + rw [effectiveModulus,ht.dvd_mul] + have htq : ¬t ∣ qf := ht.coprime_iff_not_dvd.mp (full_cofactor_coprime_small qf hq w hlarge t ht htw).symm + have hbad : ¬t ∣ badPrimeProduct (fun u => (a u : ℤ)) r qf := by + intro hd + apply htq + rw [← alignedCofactor_mul_bad (fun u => (a u : ℤ)) r qf hq] + exact dvd_mul_of_dvd_right hd _ + simp only [hbad,or_false] + +theorem small_effective_avoidance (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) (w : ℝ) + (hlarge : ∀ u ∈ qf.primeFactors,w < (u : ℝ)) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) + (t : ℕ) (ht : t.Prime) (htw : (t : ℝ) ≤ w) (j : ℤ) : + (t ∣ effectiveModulus a r qf → + ((effectiveInteger a r qf p hHp j : ZMod t) ≠ (a t : ZMod t) ↔ + (intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ZMod t)+ + (p : ZMod t)*(j : ZMod t) ≠ + ((a t : ZMod t)-(ErdosInverseCells.cofactorHit qf a : ZMod t))* + (↑((ZMod.unitOfCoprime qf (full_cofactor_coprime_small qf hq w hlarge t ht htw))⁻¹) : ZMod t))) ∧ + (¬t ∣ effectiveModulus a r qf → + ((effectiveInteger a r qf p hHp j : ZMod t) ≠ (a t : ZMod t) ↔ + (p : ZMod t)*(alignedCofactor (fun u => (a u : ℤ)) r qf : ZMod t)* + ((intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ZMod t)+ + (effectiveModulus a r qf : ZMod t)*(j : ZMod t)) ≠ + (r.den : ZMod t)*(a t : ZMod t)-(r.num : ZMod t))) := by + constructor + · intro _htH + exact effective_avoidance_unit a r qf p hHp t (full_cofactor_coprime_small qf hq w hlarge t ht htw) j + · intro htH + exact effective_avoidance_not_dvd a r qf hq p hHp t ht htH j + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/SourcePrimeProductData.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/SourcePrimeProductData.lean new file mode 100644 index 0000000000000000000000000000000000000000..376e7ccc40e06de79734253878465ee1380b8c96 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/SourcePrimeProductData.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FullBoxPrefixLower + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SourcePrimeProductData +open FinitePathGeometry PrimeHistories ReferenceAdmission LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +theorem source_word_product_data {w top : ℝ} (hw : 1 < w) (htop : w < top) (ps : List ℕ) + (hd : ps.Pairwise (· > ·)) (hp : ∀ p∈ps,p ∈ sourcePrimeSet w top) : + 0 < ps.prod ∧ Squarefree ps.prod ∧ ∀ p∈ps.prod.primeFactors,w<(p:ℝ) := by + have hn : ps.Nodup := hd.imp (fun h => ne_of_gt h) + have hprime : ∀ p∈ps,p.Prime := fun p h => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hp p h)).1 + have hpos : 0 < ps.prod := List.prod_pos (fun p h => (hprime p h).pos) + have he : (∏ p∈ps.toFinset,p)=ps.prod := by simpa using List.prod_toFinset (fun p : ℕ => p) hn + have hprimeF : ∀ p∈ps.toFinset,p.Prime := fun p h => hprime p (List.mem_toFinset.mp h) + have hsq : Squarefree (∏ p∈ps.toFinset,p) := by + apply Finset.squarefree_prod_of_pairwise_isCoprime + · intro p hpp q hqq hpq + simp only [← Nat.coprime_iff_isRelPrime] + exact (Nat.coprime_primes (hprimeF p hpp) (hprimeF q hqq)).mpr hpq + · intro p hpp + exact (hprimeF p hpp).squarefree + have hfac : ps.prod.primeFactors=ps.toFinset := by + rw [← he] + exact ErdosInverseCounts.primeFactors_product ps.toFinset hprimeF + refine ⟨hpos,by rwa [he] at hsq,?_⟩ + intro p hpf + rw [hfac] at hpf + exact ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hp p (List.mem_toFinset.mp hpf))).2.1 + +theorem reference_word_product_data {w top : ℝ} (hw : 1 < w) (htop : w < top) (i : Side) (r : ℝ) (ps : List ℕ) + (hp : ps ∈ referencePrefixes w (sourcePrimeSet w top) i r) : + 0 < ps.prod ∧ Squarefree ps.prod ∧ ∀ p∈ps.prod.primeFactors,w<(p:ℝ) := by + classical + have hh := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hp).1 + exact source_word_product_data hw htop ps hh.1 hh.2 +end NumberTheoryLean.SourcePrimeProductData + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/SourcePrimeSampleBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/SourcePrimeSampleBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..9385909933a70db8e4abd215d3a12ebd2c8def94 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/SourcePrimeSampleBound.lean @@ -0,0 +1,77 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceEdgeClasses + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq + +theorem prime_sample_coprime (U : Finset ℕ) (hU : ∀ u ∈ U,Nat.Prime u) (h : ℕ) (sample : Fin h ↪ U) : + Pairwise (fun i j => Nat.Coprime (sample i).val (sample j).val) := by + intro i j hij + apply (Nat.coprime_primes (hU _ (sample i).property) (hU _ (sample j).property)).mpr + intro he + exact hij (sample.injective (Subtype.ext he)) + +theorem small_prime_product_pos (small : Finset ℕ) (hsmall : ∀ p ∈ small,Nat.Prime p) : + 0 < ∏ p ∈ small,p := Finset.prod_pos (fun p hp => (hsmall p hp).pos) + +theorem small_product_coprime_sample (small U : Finset ℕ) + (hsmall : ∀ p ∈ small,Nat.Prime p) (hU : ∀ u ∈ U,Nat.Prime u) + (hdisj : Disjoint small U) (h : ℕ) (sample : Fin h ↪ U) (i : Fin h) : + Nat.Coprime (∏ p ∈ small,p) (sample i).val := by + apply Nat.coprime_prod_left_iff.mpr + intro p hp + apply (Nat.coprime_primes (hsmall p hp) (hU _ (sample i).property)).mpr + intro he + exact (Finset.disjoint_left.mp hdisj hp) (he.symm ▸ (sample i).property) + +theorem sourceTestedSlopes_card_upper {ι : Type*} [Fintype ι] (p q0 M0 : ℕ) [NeZero M0] (u : ι → ℕ) + (hp : ∀ i,Nat.Coprime p (u i)) (hq : ∀ i,Nat.Coprime q0 (u i)) (a : ℕ → ℤ) (b0 : ℤ) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) + (hU : ∀ i,0 < u i) (h0 : ∀ i,Nat.Coprime M0 (u i)) + (hu : Pairwise (fun i j => Nat.Coprime (u i) (u j))) : + ((sourceTestedSlopes p q0 M0 u hp hq a b0 E).card : ℝ) ≤ + (p : ℝ)/(M0 : ℝ)*(∑ v : ZMod M0,∏ i,((E v i).card : ℝ)/(u i : ℝ))+ + (M0 : ℝ)*((∏ i,u i : ℕ) : ℝ) := by + rw [sourceTestedSlopes_eq_sampledSlopes] + exact sampledSlopes_card_upper p M0 u _ _ E hU h0 hu + +theorem distinct_prime_sample_slope_bound (U : Finset ℕ) (hU : ∀ u ∈ U,Nat.Prime u) + (h : ℕ) (sample : Fin h ↪ U) (p q0 M0 : ℕ) [NeZero M0] + (hp : ∀ u ∈ U,Nat.Coprime p u) (hq : ∀ u ∈ U,Nat.Coprime q0 u) + (h0 : ∀ u ∈ U,Nat.Coprime M0 u) (a : ℕ → ℤ) (b0 : ℤ) + (E : ZMod M0 → ∀ i : Fin h,Finset (ZMod (sample i).val)) : + ((sourceTestedSlopes p q0 M0 (fun i => (sample i).val) + (fun i => hp _ (sample i).property) (fun i => hq _ (sample i).property) a b0 E).card : ℝ) ≤ + (p : ℝ)/(M0 : ℝ)*(∑ v : ZMod M0,∏ i : Fin h,((E v i).card : ℝ)/((sample i).val : ℝ))+ + (M0 : ℝ)*((∏ i : Fin h,(sample i).val : ℕ) : ℝ) := by + exact sourceTestedSlopes_card_upper p q0 M0 _ _ _ a b0 E + (fun i => (hU _ (sample i).property).pos) (fun i => h0 _ (sample i).property) + (prime_sample_coprime U hU h sample) + +theorem mem_sourceTestedSlopes_of_same_cell {ι : Type*} [Fintype ι] + (p q q0 M0 : ℕ) (u : ι → ℕ) (hp : ∀ i,Nat.Coprime p (u i)) + (hq : ∀ i,Nat.Coprime q (u i)) (hq0 : ∀ i,Nat.Coprime q0 (u i)) + (a : ℕ → ℤ) (b b0 s : ℤ) (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) + (hs : s ∈ Finset.Ico (0 : ℤ) (p : ℤ)) + (hqq : ∀ i,(q : ZMod (u i)) = (q0 : ZMod (u i))) + (hbb : ∀ i,(b : ZMod (u i)) = (b0 : ZMod (u i))) + (hE : ∀ i,sourceEdgeResidue p q (u i) (hp i) (hq i) (a (u i)) b s ∈ E (s : ZMod M0) i) : + s ∈ sourceTestedSlopes p q0 M0 u hp hq0 a b0 E := by + apply Finset.mem_filter.mpr + refine ⟨hs,?_⟩ + intro i + rw [← sourceEdgeResidue_of_same_cell p q q0 (u i) (hp i) (hq i) (hq0 i) (a (u i)) b b0 s (hqq i) (hbb i)] + exact hE i + +end ErdosInverseCRT + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/SourceRawPrimeMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/SourceRawPrimeMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a1208adf9c04b398509a15b4f42efde898add25 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/SourceRawPrimeMass.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceGuardedHardCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosVarianceWeighted +open NumberTheoryLean ErdosInverseBoxHeight ErdosInversePrimeBin ErdosVarianceEffective ErdosInverseCells +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_raw_hard_prime_mass (alpha aStar eps tau Cmin : ℝ) (F : ℕ) + (halpha : 0 < alpha) (ha : 0 < aStar) (heps : 0 < eps) (htau : 0 < tau) : + ∃ Cs : ℝ,0 < Cs ∧ Cmin ≤ Cs ∧ ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,0 < xi → xi ≤ xi0 → ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ) (a : ℕ → ℕ) (qf : ℕ),Squarefree qf → + z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + (∀ t ∈ qf.primeFactors,sourceW z < (t : ℝ)) → + (∀ p ∈ primeBin R theta,qf.Coprime p ∧ + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z)) → + ∀ Q : Finset ℚ,Q.card ≤ F → + harmonicMass (rawHardPrimeUnion Q z R theta a qf Cs eps) ≤ tau*harmonicMass (primeBin R theta) := by + let sigma := tau/(2*((F : ℝ)+1)) + have hsigma : 0 < sigma := by dsimp [sigma];positivity + obtain ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,hcount⟩ := + source_guarded_hard_count alpha aStar eps sigma Cmin halpha ha heps hsigma + refine ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + filter_upwards [hcount xi hxi hxib,eventually_gt_atTop (1 : ℝ)] with z hz hz1 + intro R theta a qf hq hRlo hthetal hthetau hQLarge hgeometry Q hQ + have hR : 0 < R := (Real.rpow_pos_of_pos (by linarith : 0 < z) alpha).trans_le hRlo + have htheta : 0 ≤ theta := (by positivity : (0 : ℝ) ≤ xi/4).trans hthetal + have htheta1 : theta ≤ 1 := hthetau.trans (hxib.trans hxi01) + have hcard := rawHardPrimeUnion_card Q z R theta a qf Cs eps sigma + (fun r _ => hz R theta a qf hq hRlo hthetal hthetau hQLarge hgeometry r) + have hm := harmonic_transfer_two (rawHardPrimeUnion Q z R theta a qf Cs eps) (primeBin R theta) + (rawHardPrimeUnion_subset Q z R theta a qf Cs eps) R theta (sigma*(Q.card : ℝ)) hR htheta htheta1 + (by positivity) (fun p hp => ((mem_primeBin hR.le htheta p).mp hp).2) hcard + have hbudget : 2*(sigma*(Q.card : ℝ)) ≤ tau := by + have hQr : (Q.card : ℝ) ≤ (F : ℝ)+1 := by + have hh : (Q.card : ℝ) ≤ F := by exact_mod_cast hQ + linarith + have hh := mul_le_mul_of_nonneg_left hQr (show 0 ≤ 2*sigma by positivity) + have he : (2*sigma)*((F : ℝ)+1) = tau := by dsimp [sigma];field_simp + nlinarith + exact hm.trans (mul_le_mul_of_nonneg_right hbudget (harmonicMass_nonneg _)) + +end ErdosVarianceWeighted + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/StableSourceChebyshev.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/StableSourceChebyshev.lean new file mode 100644 index 0000000000000000000000000000000000000000..bb249ef86100f34ce9c5e2e8fce911e709b8ab35 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/StableSourceChebyshev.lean @@ -0,0 +1,43 @@ +import OAI.NumberTheory.Jacobsthal.Probability.StableSourceVariance + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +open _root_.Filter +namespace ErdosRandomVariance + +universe u + +theorem stable_source_chebyshev (delta eps : ℝ) (hdelta : 0 < delta) (heps : 0 < eps) : + ∀ᶠ W : ℝ in atTop, 1 < W ∧ ∀ (J : ℕ), W^delta ≤ (J : ℝ) → + ∀ (α : Type u) (C : Finset α) (w : α → ℝ) (I : ℕ → α → ℝ) (zeta eta : ℝ), + (∀ x ∈ C, 0 ≤ w x) → 0 ≤ zeta → zeta ≤ 1 → 0 < eta → + (∀ j ∈ Finset.range J, ∀ x ∈ C, I j x = 0 ∨ I j x = 1) → + (∑ x ∈ C, w x) ≤ 1+zeta → + (∀ j ∈ Finset.range J, (1-zeta)*sieveProduct (variancePrimes W) ≤ weightedMoment C w (I j)) → + (∀ j ∈ Finset.range J, weightedMoment C w (I j) ≤ (1+zeta)*sieveProduct (variancePrimes W)) → + (∀ i ∈ Finset.range J, ∀ j ∈ Finset.range J, i ≠ j → + weightedMoment C w (fun x => I i x*I j x) ≤ (1+zeta)*pairKernel (variancePrimes W) i j) → + (∑ x ∈ C with eta*((J : ℝ)*sieveProduct (variancePrimes W)) ≤ + |indicatorSum (Finset.range J) I x-(J : ℝ)*sieveProduct (variancePrimes W)|, w x) ≤ + (eps+4*zeta)/eta^2 := by + classical + filter_upwards [stable_source_variance delta eps hdelta heps] with W hW + refine ⟨hW.1,?_⟩ + intro J hJ α C w I zeta eta hw hzeta hzeta1 heta hI hMass hLower hUpper hPair + have hJpos : (0 : ℝ) < J := lt_of_lt_of_le + (Real.rpow_pos_of_pos (show 0 < W by linarith [hW.1]) delta) hJ + have hM := mul_pos hJpos (sieveProduct_pos _ (variancePrimes_prime W)) + exact weighted_relative_chebyshev C w (indicatorSum (Finset.range J) I) + ((J : ℝ)*sieveProduct (variancePrimes W)) eta (eps+4*zeta) hw hM heta + (hW.2 J hJ α C w I zeta hzeta hzeta1 hI hMass hLower hUpper hPair) + +end ErdosRandomVariance + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/StoppedReferencePrimes.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/StoppedReferencePrimes.lean new file mode 100644 index 0000000000000000000000000000000000000000..f463ef79f5b37ae0345fbab0cfdfcb762c154ce6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/StoppedReferencePrimes.lean @@ -0,0 +1,102 @@ +import OAI.NumberTheory.Jacobsthal.Paths.MovingStopMargins +import OAI.NumberTheory.Jacobsthal.Paths.StoppedReferenceFinite + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosStoppedReferenceUpper +open NumberTheoryLean FinitePathGeometry PrimeHistories ReferencePruning ReferenceAdmission +open ReferenceProductsBasics ReferenceSourcePrimeSets LogarithmicBinPartition +open StoppedCountVertex StoppedVertexHistory StoppedCountAdapters StoppedTraceSets +open ErdosPrimeInputs.PrimePrefixMass + +theorem below_all_iff_last (ps : List ℕ) (hne : ps ≠ []) (hdec : ps.Pairwise (· > ·)) (q : ℕ) : + (∀ p ∈ ps,q rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [he] + constructor + · intro h + exact h _ (List.getLast_mem hne) + · intro h p hp + have hdec' : (ps.dropLast++[ps.getLast hne]).Pairwise (· > ·) := by + rwa [List.dropLast_append_getLast] + rw [← List.dropLast_append_getLast hne] at hp + rcases List.mem_append.mp hp with hp | hp + · exact h.trans ((List.pairwise_append.mp hdec').2.2 p hp _ (by simp)) + · have heq := List.mem_singleton.mp hp + simpa only [heq] using h + +theorem suffix_source_primes {w top : ℝ} (hw : 0 < w) (htop : w < top) + (ps : List ℕ) (hne : ps ≠ []) (hdec : ps.Pairwise (· > ·)) + (hsource : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) : + suffixPrimes (sourcePrimeSet w top) ps=availablePrimes w (ps.getLastD 0:ℝ) false := by + classical + have hlast : ps.getLastD 0 ∈ ps := by + have he : ps.getLastD 0=ps.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hne + have hlastP := (mem_sourcePrimeSet hw htop _).mp (hsource _ hlast) + have hp0 : 0 ≤ (ps.getLastD 0:ℝ) := Nat.cast_nonneg _ + ext q + rw [suffixPrimes,Finset.mem_filter,mem_sourcePrimeSet hw htop, + availablePrimes_membership hp0] + simp only [Bool.false_eq_true,ite_false] + rw [below_all_iff_last ps hne hdec q] + constructor + · rintro ⟨⟨hq,hwq,_⟩,hql⟩ + exact ⟨hq,hwq,by exact_mod_cast hql⟩ + · rintro ⟨hq,hwq,hql⟩ + exact ⟨⟨hq,hwq,hql.le.trans hlastP.2.2⟩,by exact_mod_cast hql⟩ + +theorem after_source_primes {w top : ℝ} (hw : 0 < w) (htop : w < top) + (v : Vertex) (hv : v.available=sourcePrimeSet w top) + (ps : List ℕ) (hne : ps ≠ []) (hdec : ps.Pairwise (· > ·)) + (hsource : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) : + (after w v ps).available=availablePrimes w (ps.getLastD 0:ℝ) false := by + rw [after_available,hv] + exact suffix_source_primes hw htop ps hne hdec hsource + +theorem after_original_scale (w : ℝ) (Y : ℕ) (z : Node) (P : Finset ℕ) (ps : List ℕ) : + (after w (rootVertex z ∅ P ((Y:ℝ)*ErdosPrimeInputs.MertensStrong.primeProduct w)) ps).scale= + ((Y:ℝ)/(ps.prod:ℝ))*ErdosPrimeInputs.MertensStrong.primeProduct w := by + rw [after_scale_product] + change ((Y:ℝ)*ErdosPrimeInputs.MertensStrong.primeProduct w)/(ps.prod:ℝ)=_ + ring + +theorem actual_stopped_vertex_data {n : ℕ} (Y : ℕ) + (w top Cs eta Clen B xi b₀ b₁ : ℝ) (hw : 0 < w) (htop : w < top) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) + (ps : List ℕ) + (hp : ps ∈ stopped w (SourceStopPredicate.stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) + (sourcePrimeSet w top).card + (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*ErdosPrimeInputs.MertensStrong.primeProduct w))) : + (terminal w z ps).side=.even ∧ ps ≠ [] ∧ ps.Pairwise (· > ·) ∧ + (after w (rootVertex z ∅ (sourcePrimeSet w top) + ((Y:ℝ)*ErdosPrimeInputs.MertensStrong.primeProduct w)) ps).available= + availablePrimes w (ps.getLastD 0:ℝ) false := by + classical + have hf := ActualSourceStopBinding.actual_source_stops_first Y w Cs eta Clen B xi b₀ b₁ + ((Y:ℝ)*ErdosPrimeInputs.MertensStrong.primeProduct w) lower width label a z (sourcePrimeSet w top) hp + have ht := StoppedTraceAdmission.trace_reference_member w + (SourceStopPredicate.stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) + (sourcePrimeSet w top).card + (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*ErdosPrimeInputs.MertensStrong.primeProduct w)) (Or.inr hp) + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp ht).1 + refine ⟨hf.1,hf.2.1.1,hd.1,?_⟩ + exact after_source_primes hw htop _ rfl ps hf.2.1.1 hd.1 hd.2 + +end ErdosStoppedReferenceUpper + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/SubsetPrimeBoxMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/SubsetPrimeBoxMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f4392c26e162f4bd0173aa5851647df33baadcd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/SubsetPrimeBoxMass.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SingletonSubsetMass +import OAI.NumberTheory.Jacobsthal.Paths.WrongOwnerBoxMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SubsetPrimeBoxMass +open _root_.Filter FiniteWeightedChoiceBox SingletonSubsetMass PrimeBinAlignmentMass +open WrongOwnerSearchTail WrongOwnerBinMass ActualBinOwners ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem no_nearfull_subset_mass {n : ℕ} (R : Fin n → ℝ) (xi eta : ℝ) (mult : Fin n → ℕ) + (hR : ∀ i,0 < R i) (hxi : 0 ≤ xi) (heta : 0 ≤ eta) (S : Finset (Fin n)) + (hsingle : ∀ i ∈ S,mult i=1) (a : ℕ → ℤ) (q : ℚ) + (hd : ∀ i ∈ S,(((primeBin (R i) xi).filter (aligns a q)).card:ℝ) ≤ + (1-eta)*((primeBin (R i) xi).card:ℝ)) : + (∑ f ∈ restrictedPoints (fun i => (primeBin (R i) xi).powersetCard (mult i)) S + (fun _ s => ∀ p ∈ s,aligns a q p),pointWeight (fun _ => subsetWeight) f) ≤ + (1-eta/(1+xi))^S.card*boxMass (fun i => (primeBin (R i) xi).powersetCard (mult i)) + (fun _ => subsetWeight) := by + apply restriction_mass_bound + · intro i s + exact subsetWeight_nonnegative s + · intro i hi + rw [hsingle i hi,singleton_total_mass] + have he := singleton_all_mass (primeBin (R i) xi) (aligns a q) + calc + _ = mass ((primeBin (R i) xi).filter (aligns a q)) := by + convert! he using 1 + exact Finset.sum_congr (by ext s; simp only [Finset.mem_filter]) (fun _ _ => rfl) + _ ≤ _ := non_nearfull_mass (hR i) hxi heta _ (Finset.filter_subset _ _) (hd i hi) + +theorem no_nearfull_subset_power {n : ℕ} (R : Fin n → ℝ) (w c xi eta : ℝ) (mult : Fin n → ℕ) + (hR : ∀ i,0 < R i) (hw : 1 < w) (hc : 0 < c) (hxi0 : 0 ≤ xi) (hxi1 : xi ≤ 1) + (heta0 : 0 < eta) (heta1 : eta ≤ 1) (S : Finset (Fin n)) + (hsingle : ∀ i ∈ S,mult i=1) (hcount : c*Real.log w ≤ (S.card:ℝ)) (a : ℕ → ℤ) (q : ℚ) + (hd : ∀ i ∈ S,(((primeBin (R i) xi).filter (aligns a q)).card:ℝ) ≤ + (1-eta)*((primeBin (R i) xi).card:ℝ)) : + (∑ f ∈ restrictedPoints (fun i => (primeBin (R i) xi).powersetCard (mult i)) S + (fun _ s => ∀ p ∈ s,aligns a q p),pointWeight (fun _ => subsetWeight) f) ≤ + w^(-(c*eta/2))*boxMass (fun i => (primeBin (R i) xi).powersetCard (mult i)) + (fun _ => subsetWeight) := by + have hmass : 0 ≤ boxMass (fun i => (primeBin (R i) xi).powersetCard (mult i)) (fun _ => subsetWeight) := by + exact Finset.sum_nonneg (fun f _ => weight_nonnegative _ (fun _ => subsetWeight_nonnegative) f) + exact (no_nearfull_subset_mass R xi eta mult hR hxi0 heta0.le S hsingle a q hd).trans + (mul_le_mul_of_nonneg_right (PrimeChoiceAlignmentDecay.search_power_bound hw hc heta0 heta1 hxi0 hxi1 S.card hcount) hmass) + +theorem wrong_owner_subset_mass {Cs theta A : ℝ} (hCs : 0 ≤ Cs) (htheta : 0 < theta) (hA : 0 < A) : + ∀ᶠ w : ℝ in atTop,∀ Y xi eta : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → theta ≤ xi → xi ≤ 1 → + ∀ (n : ℕ) (R : Fin n → ℝ) (mult : Fin n → ℕ) (S : Finset (Fin n)), + (∀ i ∈ S,mult i=1) → (∀ i ∈ S,w^(w^((1/4:ℝ))) ≤ R i) → + ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + (∑ f ∈ (points (fun i => (primeBin (R i) xi).powersetCard (mult i))).filter + (fun f => ∃ i ∈ S,∃ p ∈ f i,p ∈ wrongOwnerPrimes Y w Cs eta (R i) xi a q), + pointWeight (fun _ => subsetWeight) f) ≤ + (S.card:ℝ)*w^(-A)*boxMass (fun i => (primeBin (R i) xi).powersetCard (mult i)) + (fun _ => subsetWeight) := by + filter_upwards [actual_wrong_search_mass hCs htheta hA] with w hw + intro Y xi eta hY hYup hxi hxi1 n R mult S hsingle hsearch a q hq + have hh := union_mass_bound (fun i => (primeBin (R i) xi).powersetCard (mult i)) + (fun _ => subsetWeight) (fun _ s => subsetWeight_nonnegative s) S + (fun i s => ∃ p ∈ s,p ∈ wrongOwnerPrimes Y w Cs eta (R i) xi a q) (w^(-A)) (by + intro i hi + rw [hsingle i hi,singleton_total_mass] + have he := singleton_some_mass (primeBin (R i) xi) (wrongOwnerPrimes Y w Cs eta (R i) xi a q) + (Finset.filter_subset _ _) + calc + _ = mass (wrongOwnerPrimes Y w Cs eta (R i) xi a q) := by + convert! he using 1 + exact Finset.sum_congr (by ext s; simp only [Finset.mem_filter]) (fun _ _ => rfl) + _ ≤ _ := hw Y (R i) xi eta hY hYup (hsearch i hi) hxi hxi1 a q hq) + convert! hh using 1 + exact Finset.sum_congr (by ext f; simp only [Finset.mem_filter]) (fun _ _ => rfl) +end NumberTheoryLean.SubsetPrimeBoxMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/TagPrimePartition.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/TagPrimePartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..42e1e2d05723664c7cb5df31d63dc44a0c746a33 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/TagPrimePartition.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Paths.TagCutoffSeparation +import OAI.NumberTheory.Jacobsthal.Sieve.TagCRTPeriodicity + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedTagSieve +open scoped BigOperators +open Erdos970Dependency.SiegelWalfisz +attribute [local instance] Classical.propDecidable + +lemma mem_AP_canonical (R V : ℝ) (M a p : ℕ) (ha : a p%Q∈A ∧ ∀ t∈T,(p:ZMod t)=rho t) + +theorem intersectionPrimes_eq_biUnion (R V : ℝ) (Q : ℕ) (hQ : 0 < Q) (T A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) + (hA : ∀ a∈A,a intervalPrimes R V (Q*(∏ t∈T,t)) (a:ℤ)) := by + ext p + rw [intersectionPrimes,Finset.mem_filter,Finset.mem_biUnion] + have hM : 0 < Q*(∏ t∈T,t) := Nat.mul_pos hQ (Finset.prod_pos (fun t ht => (hT t ht).pos)) + constructor + · rintro ⟨hp,h⟩ + refine ⟨p%(Q*(∏ t∈T,t)),(mod_mem_intersectionResidues Q hQ T A rho hT hQT hA p).mpr h,?_⟩ + exact (mem_AP_canonical R V _ _ p (Nat.mod_lt p hM)).mpr ⟨hp,rfl⟩ + · rintro ⟨a,ha,hp⟩ + have har := ((mem_intersectionResidues Q hQ T A rho hT hQT hA a).mp ha).1 + obtain ⟨hp,he⟩ := (mem_AP_canonical R V _ a p har).mp hp + refine ⟨hp,(mod_mem_intersectionResidues Q hQ T A rho hT hQT hA p).mp ?_⟩ + rw [he] + exact ha + +lemma intersection_AP_disjoint (R V : ℝ) (Q : ℕ) (hQ : 0 < Q) (T A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) + (hA : ∀ a∈A,a + Disjoint (intervalPrimes R V (Q*(∏ t∈T,t)) (a:ℤ)) + (intervalPrimes R V (Q*(∏ t∈T,t)) (b:ℤ))) := by + intro a ha b hb hab + apply Finset.disjoint_left.mpr + intro p hpa hpb + have har := ((mem_intersectionResidues Q hQ T A rho hT hQT hA a).mp ha).1 + have hbr := ((mem_intersectionResidues Q hQ T A rho hT hQT hA b).mp hb).1 + exact hab (((mem_AP_canonical R V _ a p har).mp hpa).2.symm.trans + ((mem_AP_canonical R V _ b p hbr).mp hpb).2) + +theorem intersectionPrimes_card (R V : ℝ) (Q : ℕ) (hQ : 0 < Q) (T A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) + (hA : ∀ a∈A,a t) ht + have hz : (radical D:ZMod t)=0 := (ZMod.natCast_eq_zero_iff _ _).mpr htr + rw [hn] + push_cast + simp [hz] + +theorem mem_actualClasses_mod_iff (D : ℕ) (hD : 0 < D) (A B : ℤ) (a : ℕ → ℤ) (p : ℕ) : + p%(D*radical D)∈actualClasses D A B a ↔ + (D:ℤ)∣A+B*p ∧ ∀ t∈D.primeFactors,(actualN D A B p:ZMod t)≠a t := by + have hQ : 0 < D*radical D := Nat.mul_pos hD (radical_pos D) + simp only [actualClasses,Finset.mem_filter,Finset.mem_range,Nat.mod_lt p hQ,true_and, + integral_mod_lift_iff] + apply and_congr_right + intro _h + constructor <;> intro h t ht + · simpa only [actualN_mod_lift D hD A B p t ht] using h t ht + · simpa only [actualN_mod_lift D hD A B p t ht] using h t ht + +end ErdosStoppedTagSieve + + + +namespace ErdosStoppedTagSieve +open ErdosUnitLifts +attribute [local instance] Classical.propDecidable + +noncomputable def smallPrimeSet (P : ℝ) : Finset ℕ := + (Nat.primesLE ⌊P⌋₊).filter (fun t => (t:ℝ) ¬t∣D ∧ (D:ZMod t)*(residue t)-A≠0) +noncomputable def restrictedPrimes (P : ℝ) (D : ℕ) (A : ℤ) (residue : ℕ → ℤ) (d0 : ℕ) : Finset ℕ := + (unalignedPrimes P D A residue).filter (fun t => ¬t∣d0) +noncomputable def forbiddenClass (D : ℕ) (A B : ℤ) (residue : ℕ → ℤ) (t : ℕ) : ZMod t := + (B:ZMod t)⁻¹*((D:ZMod t)*(residue t)-A) + +lemma coefficient_cast_zero {t d0 : ℕ} {B : ℤ} + (hprofile : t∣B.natAbs ↔ t∣d0) (ht : t∣d0) : (B:ZMod t)=0 := + (ZMod.intCast_zmod_eq_zero_iff_dvd B t).mpr (Int.natCast_dvd.mpr (hprofile.mpr ht)) + +lemma coefficient_unit_of_not_dvd {t d0 : ℕ} (ht : t.Prime) (B : ℤ) + (hprofile : t∣B.natAbs ↔ t∣d0) (hnot : ¬t∣d0) : IsUnit (B:ZMod t) := + intCast_isUnit_of_natAbs_coprime t B + ((ht.coprime_iff_not_dvd.mpr (fun hd => hnot (hprofile.mp hd))).symm) + +theorem signed_coefficient_profile (P : ℝ) (q d0 ell : ℕ) (m : ℤ) + (hq : ∀ t∈smallPrimeSet P,q.Coprime t) (hell : ell.Prime) (hellP : P<(ell:ℝ)) + (hm : m.natAbs=d0*ell) : + ∀ t∈smallPrimeSet P,t∣((q:ℤ)*m).natAbs ↔ t∣d0 := by + intro t ht + obtain ⟨htp,htP⟩ := (mem_smallPrimeSet P t).mp ht + have htq : ¬t∣q := htp.coprime_iff_not_dvd.mp (hq t ht).symm + have hte : ¬t∣ell := by + intro hd + rcases hell.eq_one_or_self_of_dvd t hd with he | he + · exact htp.ne_one he + · have her : (t:ℝ)=ell := by exact_mod_cast he + linarith + simp only [Int.natAbs_mul,Int.natAbs_natCast,hm,htp.dvd_mul,htq,hte,false_or,or_false] + +theorem denominator_coefficient_coprime (P : ℝ) (D : ℕ) (hD : 0 < D) (hDP : (D:ℝ) Disjoint (P i) (P j))) + (i j : Fin n) (hij : i ≠ j) (hi : m i=1) (hj : m j=1) (G : ℕ → ℕ → ℕ → ℝ) : + (∑ f ∈ selections P m,(selectionProduct f:ℝ)⁻¹* + G (pickedPrime f i) (pickedPrime f j) (selectionProduct (eraseTwoSelection f i j)))= + ∑ p ∈ P i,∑ u ∈ P j,∑ q ∈ cofactorChoices P (eraseTwo m i j), + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹)*G p u q := by + rw [two_singleton_weighted_sum P m i j hij hi hj] + rw [← two_prime_cofactor_sum P m hP hd i j G] + apply Finset.sum_congr rfl + intro p _hp + apply Finset.sum_congr rfl + intro u _hu + apply Finset.sum_congr rfl + intro f hf + have hm := (mem_selections P _ f).mp hf + have hei : f i=∅ := Finset.card_eq_zero.mp ((hm i).2.trans (eraseTwo_zero m i j).1) + have hej : f j=∅ := Finset.card_eq_zero.mp ((hm j).2.trans (eraseTwo_zero m i j).2) + rw [(picked_fillTwo f i j hij p u).1,(picked_fillTwo f i j hij p u).2,erase_filled_two f i j hei hej p u] +end NumberTheoryLean.TwoPrimeObservableSum + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/TwoPrimeRoots.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/TwoPrimeRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..234cfe8b45b17160e6e8342b72e753807687df4d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/TwoPrimeRoots.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.TwoPowerDivisibility + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman.PrimePower + +attribute [local instance] Classical.decEq + +theorem two_sq_eq_reduction (s : ℕ) (x y : ZMod (2 * 2^s)) (hy : IsUnit y) + (hxy : x^2 = y^2) : + reduction 2 (2^s) x = reduction 2 (2^s) y ∨ + reduction 2 (2^s) x = -reduction 2 (2^s) y := by + have hycast : IsUnit (y.val : ZMod (2*2^s)) := by + simpa only [ZMod.natCast_zmod_val] using hy + have hcop : y.val.Coprime 2 := + Nat.Coprime.of_dvd_right (dvd_mul_right 2 (2^s)) + ((ZMod.isUnit_iff_coprime y.val (2*2^s)).mp hycast) + have hyodd : ¬(2 : ℤ) ∣ (y.val : ℤ) := by + exact_mod_cast (Nat.prime_two.coprime_iff_not_dvd.mp hcop.symm) + have hdiv : (2 : ℤ)^(s+1) ∣ (x.val : ℤ)^2-(y.val : ℤ)^2 := by + have hz : (((x.val : ℤ)^2-(y.val : ℤ)^2 : ℤ) : ZMod (2*2^s)) = 0 := by + push_cast + rw [ZMod.natCast_zmod_val, ZMod.natCast_zmod_val] + exact sub_eq_zero.mpr hxy + have h := (ZMod.intCast_zmod_eq_zero_iff_dvd _ (2*2^s)).mp hz + simpa only [Nat.cast_mul, Nat.cast_ofNat, Nat.cast_pow, pow_succ'] using h + rcases two_power_square_congruence s (x.val : ℤ) (y.val : ℤ) hyodd hdiv with hm | hp + · left + have hz := (ZMod.intCast_zmod_eq_zero_iff_dvd + ((x.val : ℤ)-(y.val : ℤ)) (2^s)).mpr (by exact_mod_cast hm) + push_cast at hz + rw [reduction_apply_val, reduction_apply_val] + exact sub_eq_zero.mp hz + · right + have hz := (ZMod.intCast_zmod_eq_zero_iff_dvd + ((x.val : ℤ)+(y.val : ℤ)) (2^s)).mpr (by exact_mod_cast hp) + push_cast at hz + rw [reduction_apply_val, reduction_apply_val] + exact eq_neg_of_add_eq_zero_left hz + +theorem quadraticUnitRoots_card_le_four_twice (s : ℕ) (a b : ZMod (2*2^s)) + (ha : IsUnit a) : (quadraticUnitRoots (2*2^s) a b).card ≤ 4 := by + by_cases hempty : (quadraticUnitRoots (2*2^s) a b).Nonempty + · obtain ⟨y, hy⟩ := hempty + obtain ⟨hyunit, hyeq⟩ := (Finset.mem_filter.mp hy).2 + let S : Finset (ZMod (2^s)) := {reduction 2 (2^s) y, -reduction 2 (2^s) y} + have hsubset : quadraticUnitRoots (2*2^s) a b ⊆ + Finset.univ.filter (fun x => reduction 2 (2^s) x ∈ S) := by + intro x hx + obtain ⟨_, hxeq⟩ := (Finset.mem_filter.mp hx).2 + have hsq : x^2 = y^2 := by + rcases ha with ⟨u, rfl⟩ + have h := congrArg (fun z : ZMod (2*2^s) => (↑u⁻¹ : ZMod (2*2^s)) * z) + (hxeq.trans hyeq.symm) + simpa only [Units.inv_mul_cancel_left] using h + have hc := two_sq_eq_reduction s x y hyunit hsq + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, by simpa only [S, Finset.mem_insert, + Finset.mem_singleton] using hc⟩ + have hScard : S.card ≤ 2 := by + simpa only [Finset.card_singleton] using + Finset.card_insert_le (reduction 2 (2^s) y) ({-reduction 2 (2^s) y} : Finset _) + calc + _ ≤ (Finset.univ.filter (fun x => reduction 2 (2^s) x ∈ S)).card := + Finset.card_le_card hsubset + _ = S.card * 2 := reduction_preimage_card 2 (2^s) S + _ ≤ 4 := by omega + · rw [Finset.not_nonempty_iff_eq_empty.mp hempty] + simp + +theorem quadraticUnitRoots_card_le_four (s : ℕ) (hs : 0 < s) (a b : ZMod (2^s)) + (ha : IsUnit a) : (quadraticUnitRoots (2^s) a b).card ≤ 4 := by + obtain ⟨t, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : s ≠ 0) + have transport (n : ℕ) (hn : n = 2*2^t) [NeZero n] + (a b : ZMod n) (ha : IsUnit a) : (quadraticUnitRoots n a b).card ≤ 4 := by + subst n + exact quadraticUnitRoots_card_le_four_twice t a b ha + exact transport (2^t.succ) Nat.pow_succ' a b ha + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/UniformDirichletBasepoint.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/UniformDirichletBasepoint.lean new file mode 100644 index 0000000000000000000000000000000000000000..c85d3478444d4d22e1278be3fef74f3f30aa41da --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/UniformDirichletBasepoint.lean @@ -0,0 +1,190 @@ +import StrongPNT.Erdos970.PNT5_Strong +import OAI.NumberTheory.Jacobsthal.Siegel.Main + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.MeasureTheory _root_.Set _root_.Finset _root_.Complex +open scoped Topology +namespace Erdos970Dependency.SiegelWalfisz +open WeightedTorusJets + +theorem norm_LFunction_modulus_height {eta : ℝ} (heta : 0 < eta) (heta_half : eta ≤ 1 / 2) + {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) + {s : ℂ} (hre : 1 - eta ≤ s.re) : + ‖DirichletCharacter.LFunction chi s‖ ≤ (1 / eta + 2) * ‖s‖ * (q : ℝ) ^ eta := by + have hs : 0 < s.re := by linarith + have hq1 : (1 : ℝ) ≤ q := by + exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hint := integrableOn_min_mul_rpow (Nat.cast_nonneg q) + (by linarith : -s.re - 1 < -1) + have hI : ‖∫ t : ℝ in Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, chi (k : ZMod q)) * (t : ℂ) ^ (-(s + 1))‖ ≤ + ∫ t : ℝ in Ioi 1, min t (q : ℝ) * t ^ (-s.re - 1) := by + apply norm_integral_le_of_norm_le hint + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + have ht0 : 0 < t := lt_trans zero_lt_one ht + rw [norm_mul, Complex.norm_cpow_eq_rpow_re_of_pos ht0] + have he : (-(s + 1)).re = -s.re - 1 := by simp; ring + rw [he] + exact mul_le_mul_of_nonneg_right (norm_sum_character_Icc_le_min chi hchi ht0.le) + (Real.rpow_nonneg ht0.le _) + have hbound := hI.trans (integral_min_mul_rpow_le hq1 heta heta_half hre) + rw [LFunction_eq_partial_sum_integral_of_re_pos chi hchi hs, norm_mul] + calc + ‖s‖ * _ ≤ ‖s‖ * ((q : ℝ) ^ eta * (1 / eta + 2)) := + mul_le_mul_of_nonneg_left hbound (norm_nonneg s) + _ = _ := by ring + +theorem norm_LFunction_height_envelope {eta : ℝ} (heta : 0 < eta) (heta_half : eta ≤ 1 / 2) + {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) + {s : ℂ} (hre : 1 - eta ≤ s.re) {H : ℝ} (hH : ‖s‖ ≤ H) : + ‖DirichletCharacter.LFunction chi s‖ ≤ (1 / eta + 2) * H * (q : ℝ) ^ eta := by + apply (norm_LFunction_modulus_height heta heta_half chi hchi hre).trans + exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hH (by positivity)) (Real.rpow_nonneg (Nat.cast_nonneg q) eta) + +theorem norm_LFunction_half_strip {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + (hchi : chi ≠ 1) {s : ℂ} (hs : 1 / 2 ≤ s.re) : + ‖DirichletCharacter.LFunction chi s‖ ≤ 4 * ‖s‖ * (q : ℝ) ^ (1 / 2 : ℝ) := by + have h := norm_LFunction_modulus_height (eta := (1 / 2 : ℝ)) (s := s) + (by norm_num) (by norm_num) chi hchi (by linarith) + norm_num at h + exact h + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +open _root_.Complex +namespace Erdos970Dependency.SiegelWalfisz + +theorem LFunction_ne_zero_right {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + {s : ℂ} (hs : 1 < s.re) : DirichletCharacter.LFunction chi s ≠ 0 := by + rw [DirichletCharacter.LFunction_eq_LSeries chi hs] + exact DirichletCharacter.LSeries_ne_zero_of_one_lt_re chi hs + +theorem uniform_log_derivative_right : + ∃ C : ℝ, 0 ≤ C ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q) (s : ℂ), + 1 < s.re → ‖deriv (DirichletCharacter.LFunction chi) s / DirichletCharacter.LFunction chi s‖ ≤ + (s.re - 1)⁻¹ + C := by + obtain ⟨C, hC, hbound⟩ := _root_.Erdos970.strongPnt_triv_bound_zeta + refine ⟨C, hC, ?_⟩ + intro q _ chi s hs + have hz := hbound s.re 0 hs + simp only [Complex.ofReal_zero, zero_mul, add_zero] at hz + exact (WeightedTorusJets.norm_logDeriv_LFunction_le_neg_logDeriv_zeta chi hs).trans + ((Complex.re_le_norm _).trans hz) + +noncomputable def perronPoint (v t : ℝ) : ℂ := + ((1 + (Real.log v)⁻¹ : ℝ) : ℂ) + (t : ℂ) * Complex.I + +@[simp] theorem perronPoint_re (v t : ℝ) : (perronPoint v t).re = 1 + (Real.log v)⁻¹ := by + simp [perronPoint] + +theorem perronPoint_re_gt_one {v : ℝ} (hv : 1 < v) (t : ℝ) : 1 < (perronPoint v t).re := by + rw [perronPoint_re] + have h := inv_pos.mpr (Real.log_pos hv) + linarith + +theorem LFunction_ne_zero_perron_line {v : ℝ} (hv : 1 < v) {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (t : ℝ) : + DirichletCharacter.LFunction chi (perronPoint v t) ≠ 0 := + LFunction_ne_zero_right chi (perronPoint_re_gt_one hv t) + +theorem uniform_log_derivative_perron_line : + ∃ C : ℝ, 0 ≤ C ∧ ∀ (v : ℝ), 1 < v → ∀ (q : ℕ) [NeZero q] + (chi : DirichletCharacter ℂ q) (t : ℝ), + ‖deriv (DirichletCharacter.LFunction chi) (perronPoint v t) / + DirichletCharacter.LFunction chi (perronPoint v t)‖ ≤ Real.log v + C := by + obtain ⟨C, hC, hbound⟩ := uniform_log_derivative_right + refine ⟨C, hC, ?_⟩ + intro v hv q _ chi t + have h := hbound q chi (perronPoint v t) (perronPoint_re_gt_one hv t) + simpa only [perronPoint_re, add_sub_cancel_left, inv_inv] using h + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +noncomputable def absoluteZetaTwo : ℝ := ∑' n : ℕ, ‖LSeries.term (fun _ => 1) (2 : ℂ) n‖ + +lemma absoluteZetaTwo_summable : + Summable (fun n : ℕ => ‖LSeries.term (fun _ => 1) (2 : ℂ) n‖) := by + apply Summable.norm + exact LSeriesSummable_of_bounded_of_one_lt_re (m := 1) (by intro n hn; simp) (by norm_num) + +lemma one_le_absoluteZetaTwo : 1 ≤ absoluteZetaTwo := by + have h := absoluteZetaTwo_summable.le_tsum 1 (fun n _ => norm_nonneg (LSeries.term (fun _ => 1) (2 : ℂ) n)) + simpa [LSeries.term, absoluteZetaTwo] using h + +lemma norm_LSeries_le_absoluteZetaTwo (f : ℕ → ℂ) (hf : ∀ n, ‖f n‖ ≤ 1) + {s : ℂ} (hs : 2 ≤ s.re) : ‖LSeries f s‖ ≤ absoluteZetaTwo := by + have hsum : LSeriesSummable f s := + LSeriesSummable_of_bounded_of_one_lt_re (fun n _ => hf n) (by linarith) + apply (norm_tsum_le_tsum_norm hsum.norm).trans + apply Summable.tsum_le_tsum _ hsum.norm absoluteZetaTwo_summable + intro n + exact (LSeries.norm_term_le s (show ‖f n‖ ≤ ‖(1 : ℂ)‖ by simpa using hf n)).trans + (LSeries.norm_term_le_of_re_le_re (fun _ => (1 : ℂ)) (by simpa using hs) n) + +lemma norm_LFunction_le_absoluteZetaTwo {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) {s : ℂ} (hs : 2 ≤ s.re) : + ‖DirichletCharacter.LFunction chi s‖ ≤ absoluteZetaTwo := by + rw [DirichletCharacter.LFunction_eq_LSeries chi (by linarith)] + exact norm_LSeries_le_absoluteZetaTwo _ (fun n => chi.norm_le_one n) hs + +lemma norm_inv_LFunction_le_absoluteZetaTwo {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) {s : ℂ} (hs : 2 ≤ s.re) : + ‖(DirichletCharacter.LFunction chi s)⁻¹‖ ≤ absoluteZetaTwo := by + let f : ℕ → ℂ := fun n => chi n * (ArithmeticFunction.moebius n : ℂ) + have hf (n : ℕ) : ‖f n‖ ≤ 1 := by + have hm : ‖(ArithmeticFunction.moebius n : ℂ)‖ ≤ 1 := by + rw [Complex.norm_intCast, ← Int.cast_abs] + exact_mod_cast (show |ArithmeticFunction.moebius n| ≤ 1 from ArithmeticFunction.abs_moebius_le_one) + change ‖chi n * (ArithmeticFunction.moebius n : ℂ)‖ ≤ 1 + rw [norm_mul] + exact (mul_le_mul_of_nonneg_right (chi.norm_le_one n) (norm_nonneg _)).trans (by simpa using hm) + have hs1 : 1 < s.re := by linarith + have hp : DirichletCharacter.LFunction chi s * LSeries f s = 1 := by + rw [DirichletCharacter.LFunction_eq_LSeries chi hs1] + exact DirichletCharacter.LSeries.mul_mu_eq_one chi hs1 + have hn := LFunction_ne_zero_right chi hs1 + have hinv : (DirichletCharacter.LFunction chi s)⁻¹ = LSeries f s := by + apply mul_left_cancel₀ hn + rw [mul_inv_cancel₀ hn, hp] + rw [hinv] + exact norm_LSeries_le_absoluteZetaTwo f hf hs + +theorem uniform_basepoint_bounds : + ∃ B : ℝ, 0 < B ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q) (s : ℂ), + 2 ≤ s.re → B⁻¹ ≤ ‖DirichletCharacter.LFunction chi s‖ ∧ + ‖DirichletCharacter.LFunction chi s‖ ≤ B := by + have hB : 0 < absoluteZetaTwo := lt_of_lt_of_le zero_lt_one one_le_absoluteZetaTwo + refine ⟨absoluteZetaTwo, hB, ?_⟩ + intro q _ chi s hs + refine ⟨?_, norm_LFunction_le_absoluteZetaTwo chi hs⟩ + have hn := norm_pos_iff.mpr (LFunction_ne_zero_right chi (by linarith : 1 < s.re)) + have h := mul_le_mul_of_nonneg_right (norm_inv_LFunction_le_absoluteZetaTwo chi hs) hn.le + rw [norm_inv, inv_mul_cancel₀ hn.ne'] at h + rw [← one_div] + exact (div_le_iff₀ hB).mpr (by nlinarith) + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/WeightedChebyshev.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/WeightedChebyshev.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f351f4a704c641e4b6cd29a7e5b2b114f3861c9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/WeightedChebyshev.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Probability.StableFiniteVariance + +namespace OAI + +namespace Erdos970 + + +namespace ErdosRandomVariance + +theorem weighted_chebyshev {α : Type*} (C : Finset α) (w f : α → ℝ) + (M a B : ℝ) (hw : ∀ x ∈ C, 0 ≤ w x) (ha : 0 < a) + (hBound : weightedMoment C w (fun x => (f x-M)^2) ≤ B) : + (∑ x ∈ C with a ≤ |f x-M|, w x) ≤ B/a^2 := by + classical + have hlocal (x : α) (hx : x ∈ C.filter (fun x => a ≤ |f x-M|)) : + a^2*w x ≤ w x*(f x-M)^2 := by + obtain ⟨hxC,hxE⟩ := Finset.mem_filter.mp hx + have hsq : a^2 ≤ (f x-M)^2 := by + nlinarith [sq_abs (f x-M),abs_nonneg (f x-M)] + nlinarith [mul_le_mul_of_nonneg_right hsq (hw x hxC)] + have hs : a^2*(∑ x ∈ C with a ≤ |f x-M|, w x) ≤ B := by + calc + _ = ∑ x ∈ C with a ≤ |f x-M|, a^2*w x := Finset.mul_sum .. + _ ≤ ∑ x ∈ C with a ≤ |f x-M|, w x*(f x-M)^2 := Finset.sum_le_sum hlocal + _ ≤ ∑ x ∈ C, w x*(f x-M)^2 := by + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun x hx _ => mul_nonneg (hw x hx) (sq_nonneg _)) + _ ≤ B := hBound + apply (le_div_iff₀ (sq_pos_of_pos ha)).mpr + nlinarith [hs] + +theorem weighted_relative_chebyshev {α : Type*} (C : Finset α) (w f : α → ℝ) + (M eta beta : ℝ) (hw : ∀ x ∈ C, 0 ≤ w x) (hM : 0 < M) (heta : 0 < eta) + (hBound : weightedMoment C w (fun x => (f x-M)^2) ≤ beta*M^2) : + (∑ x ∈ C with eta*M ≤ |f x-M|, w x) ≤ beta/eta^2 := by + classical + have h := weighted_chebyshev C w f M (eta*M) (beta*M^2) hw (mul_pos heta hM) hBound + have he : beta*M^2/(eta*M)^2 = beta/eta^2 := by + field_simp [hM.ne',heta.ne'] + rwa [he] at h + +end ErdosRandomVariance + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/WeightedPrimeMultiplePairs.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/WeightedPrimeMultiplePairs.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f044953d52521380499242fffa863a7eefe4a39 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/WeightedPrimeMultiplePairs.lean @@ -0,0 +1,620 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UniformLower +import OAI.NumberTheory.Jacobsthal.Partitions.SignedIntervalGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Finset +open scoped Topology + +noncomputable def primeMultiplesIn (d : ℕ) (P x y : ℝ) : Finset ℤ := by + classical + exact (Icc (⌈x⌉:ℤ) (⌊y⌋:ℤ)).filter (fun m:ℤ => x < (m:ℝ) ∧ (m:ℝ) < y ∧ + ∃ ell : ℕ, ell.Prime ∧ P < (ell:ℝ) ∧ (m=(d:ℤ)*ell ∨ m= -((d:ℤ)*ell))) + +lemma mem_primeMultiplesIn (d : ℕ) (P x y : ℝ) (m : ℤ) : + m ∈ primeMultiplesIn d P x y ↔ x < (m:ℝ) ∧ (m:ℝ) < y ∧ + ∃ ell : ℕ, ell.Prime ∧ P < (ell:ℝ) ∧ (m=(d:ℤ)*ell ∨ m= -((d:ℤ)*ell)) := by + classical + constructor + · intro hm + exact (mem_filter.mp hm).2 + · intro hm + apply mem_filter.mpr + exact ⟨mem_Icc.mpr ⟨Int.ceil_le.mpr hm.1.le,Int.le_floor.mpr hm.2.1.le⟩,hm⟩ + +lemma prime_multiple_pos_injective {d : ℕ} (hd : 0 < d) : + Function.Injective (fun ell:ℕ => (d:ℤ)*(ell:ℤ)) := by + intro a b hab + have hd0 : (d:ℤ) ≠ 0 := by exact_mod_cast hd.ne' + have he := mul_left_cancel₀ hd0 hab + exact_mod_cast he + +lemma prime_multiple_neg_injective {d : ℕ} (hd : 0 < d) : + Function.Injective (fun ell:ℕ => -((d:ℤ)*(ell:ℤ))) := by + intro a b hab + exact prime_multiple_pos_injective hd (neg_injective hab) + +lemma signed_prime_sets_card_le {d : ℕ} (hd : 0 < d) {P x y : ℝ} (A B : Finset ℕ) + (hA : ∀ ell ∈ A, ell.Prime ∧ P < (ell:ℝ) ∧ x < (d:ℝ)*ell ∧ (d:ℝ)*ell < y) + (hB : ∀ ell ∈ B, ell.Prime ∧ P < (ell:ℝ) ∧ x < -((d:ℝ)*ell) ∧ -((d:ℝ)*ell) < y) : + A.card+B.card ≤ (primeMultiplesIn d P x y).card := by + classical + let pos : ℕ → ℤ := fun ell => (d:ℤ)*ell + let neg : ℕ → ℤ := fun ell => -((d:ℤ)*ell) + have hsub : A.image pos ∪ B.image neg ⊆ primeMultiplesIn d P x y := by + intro m hm + rcases mem_union.mp hm with hm|hm + · obtain ⟨ell,he,rfl⟩ := mem_image.mp hm + obtain ⟨hp,hP,hlo,hhi⟩ := hA ell he + apply (mem_primeMultiplesIn _ _ _ _ _).mpr + refine ⟨?_,?_,ell,hp,hP,Or.inl rfl⟩ + · simpa [pos] using hlo + · simpa [pos] using hhi + · obtain ⟨ell,he,rfl⟩ := mem_image.mp hm + obtain ⟨hp,hP,hlo,hhi⟩ := hB ell he + apply (mem_primeMultiplesIn _ _ _ _ _).mpr + refine ⟨?_,?_,ell,hp,hP,Or.inr rfl⟩ + · simpa [neg] using hlo + · simpa [neg] using hhi + have hdisj : Disjoint (A.image pos) (B.image neg) := by + apply disjoint_left.mpr + intro m hmA hmB + obtain ⟨a,ha,ham⟩ := mem_image.mp hmA + obtain ⟨b,hb,hbm⟩ := mem_image.mp hmB + have hdZ : (0:ℤ) < d := by exact_mod_cast hd + have hapos : 0 < pos a := mul_pos hdZ (by exact_mod_cast (hA a ha).1.pos) + have hbpos : 0 < (d:ℤ)*(b:ℤ) := mul_pos hdZ (by exact_mod_cast (hB b hb).1.pos) + have he : pos a = -((d:ℤ)*(b:ℤ)) := ham.trans hbm.symm + linarith + have he := card_le_card hsub + rw [card_union_of_disjoint hdisj,card_image_of_injective _ (prime_multiple_pos_injective hd), + card_image_of_injective _ (prime_multiple_neg_injective hd)] at he + exact he + +end Erdos970Dependency.SiegelWalfisz + + + +namespace ErdosStoppedArithmetic +open Erdos970Dependency.SiegelWalfisz +attribute [local instance] Classical.propDecidable + +theorem large_prime_factor_unique (d e p q : ℕ) (he : 0 < e) (hp : p.Prime) (hq : q.Prime) + (hep : e < p) (heq : d*p=e*q) : d=e ∧ p=q := by + have hpd : p ∣ e*q := heq ▸ Nat.dvd_mul_left p d + have hpeq : p=q := by + rcases hp.dvd_mul.mp hpd with hpe | hpq + · have hh := Nat.le_of_dvd he hpe + omega + · rcases (Nat.dvd_prime hq).mp hpq with h | h + · exact (hp.ne_one h).elim + · exact h + refine ⟨?_,hpeq⟩ + rw [hpeq] at heq + exact mul_right_cancel₀ hq.ne_zero heq + +theorem prime_multiple_natAbs (d : ℕ) (P x y : ℝ) (m : ℤ) + (hm : m ∈ primeMultiplesIn d P x y) : + ∃ p : ℕ,p.Prime ∧ P < (p : ℝ) ∧ m.natAbs=d*p := by + obtain ⟨_hx,_hy,p,hp,hP,hpos|hneg⟩ := (mem_primeMultiplesIn d P x y m).mp hm + · exact ⟨p,hp,hP,by rw [hpos,Int.natAbs_mul,Int.natAbs_natCast,Int.natAbs_natCast]⟩ + · exact ⟨p,hp,hP,by rw [hneg,Int.natAbs_neg,Int.natAbs_mul,Int.natAbs_natCast,Int.natAbs_natCast]⟩ + +theorem prime_multiple_factors_disjoint (P x y : ℝ) (d e : ℕ) (he : 0 < e) + (heP : (e : ℝ) ≤ P) (hne : d ≠ e) : + Disjoint (primeMultiplesIn d P x y) (primeMultiplesIn e P x y) := by + apply Finset.disjoint_left.mpr + intro m hmd hme + obtain ⟨p,hp,hP,hd⟩ := prime_multiple_natAbs d P x y m hmd + obtain ⟨q,hq,_hQ,heq⟩ := prime_multiple_natAbs e P x y m hme + have hep : e < p := by exact_mod_cast heP.trans_lt hP + exact hne (large_prime_factor_unique d e p q he hp hq hep (hd.symm.trans heq)).1 + +end ErdosStoppedArithmetic + + + +namespace Erdos970Dependency.SiegelWalfisz + +lemma prime_multiple_d_le_P {P d : ℝ} (hP : 1 ≤ P) (hd : d ≤ P^(19/20:ℝ)) : d ≤ P := by + calc + _ ≤ P^(19/20:ℝ) := hd + _ ≤ P^(1:ℝ) := Real.rpow_le_rpow_of_exponent_le hP (by norm_num) + _ = P := Real.rpow_one P + +lemma prime_multiple_P_sq_le {P s : ℝ} (hP : 1 ≤ P) (hs : 2 ≤ s) : P^2 ≤ P^s := by + calc + _ = P^(2:ℝ) := (Real.rpow_natCast P 2).symm + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le hP hs + +lemma prime_multiple_interval_height {Cs w P s x y : ℝ} (hP : 0 < P) + (hheight : 2*w^(Cs+2) ≤ P^(1/50:ℝ)) + (hxy : max |x| |y| ≤ 2*w^(Cs+2)*P^s) : max |x| |y| ≤ P^(s+1/50) := by + calc + _ ≤ 2*w^(Cs+2)*P^s := hxy + _ ≤ P^(1/50:ℝ)*P^s := mul_le_mul_of_nonneg_right hheight (Real.rpow_pos_of_pos hP _).le + _ = _ := by rw [← Real.rpow_add hP]; congr 1; ring + +lemma prime_multiple_piece_bounds {Cs w P s H d a b : ℝ} + (hCs : 0 ≤ Cs) (hw : 4 ≤ w) (hP : 3 ≤ P) (hs : 203/100 ≤ s) + (hd1 : 1 ≤ d) (hd : d ≤ P^(19/20:ℝ)) + (hH : P^s/2 ≤ H) (hheight : 2*w^(Cs+2) ≤ P^(1/50:ℝ)) + (ha : H/w ≤ a) (hlen : H/w ≤ b-a) (hb : b ≤ 2*w^(Cs+2)*P^s) : + P ≤ a/d ∧ a/d ≤ b/d ∧ b/d ≤ P^(s+1/50) ∧ + (b/d)/w^(Cs+4) ≤ b/d-a/d ∧ Real.log (b/d) ≤ (s+1/50)*Real.log P := by + have hw0 : 0 < w := by linarith + have hP0 : 0 < P := by linarith + have hP1 : 1 ≤ P := by linarith + have hd0 : 0 < d := by linarith + have hPs : 0 < P^s := Real.rpow_pos_of_pos hP0 _ + have hH0 : 0 < H := by linarith + have ht0 : 0 < H/w := div_pos hH0 hw0 + have ha0 : 0 < a := ht0.trans_le ha + have hlen0 : 0 < b-a := ht0.trans_le hlen + have hb0 : 0 < b := by linarith + have hwp : 0 < w^(Cs+2) := Real.rpow_pos_of_pos hw0 _ + have hW : 0 < w^(Cs+4) := Real.rpow_pos_of_pos hw0 _ + have hwle : w ≤ w^(Cs+2) := by + calc + _ = w^(1:ℝ) := (Real.rpow_one w).symm + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le (by linarith) (by linarith) + have h2w : 2*w ≤ P^(1/20:ℝ) := by + calc + _ ≤ 2*w^(Cs+2) := mul_le_mul_of_nonneg_left hwle (by norm_num) + _ ≤ P^(1/50:ℝ) := hheight + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le hP1 (by norm_num) + have h2wd : 2*w*d ≤ P := by + calc + _ ≤ P^(1/20:ℝ)*P^(19/20:ℝ) := mul_le_mul h2w hd hd0.le (by positivity) + _ = P := by rw [← Real.rpow_add hP0]; norm_num + have hP2 : P^2 ≤ P^s := prime_multiple_P_sq_le hP1 (by linarith) + have hPd : P*d ≤ H/w := by + apply (le_div_iff₀ hw0).mpr + calc + _ = (P/2)*(2*w*d) := by ring + _ ≤ (P/2)*P := mul_le_mul_of_nonneg_left h2wd (by positivity) + _ = P^2/2 := by ring + _ ≤ P^s/2 := div_le_div_of_nonneg_right hP2 (by norm_num) + _ ≤ H := hH + have hlo : P ≤ a/d := (le_div_iff₀ hd0).mpr (hPd.trans ha) + have hab : a/d ≤ b/d := div_le_div_of_nonneg_right (by linarith) hd0.le + have hhi : b/d ≤ P^(s+1/50) := by + calc + _ ≤ b := div_le_self hb0.le hd1 + _ ≤ 2*w^(Cs+2)*P^s := hb + _ ≤ P^(1/50:ℝ)*P^s := mul_le_mul_of_nonneg_right hheight hPs.le + _ = _ := by rw [← Real.rpow_add hP0]; congr 1; ring + have hHlen : H ≤ w*(b-a) := by + have he := (div_le_iff₀ hw0).mp hlen + simpa only [mul_comm] using he + have hpower : w^(Cs+4) = w^(Cs+2)*w^2 := by + rw [← Real.rpow_natCast w 2,← Real.rpow_add hw0] + congr 1 + ring + have hwidth : b ≤ w^(Cs+4)*(b-a) := by + calc + _ ≤ 2*w^(Cs+2)*P^s := hb + _ ≤ 2*w^(Cs+2)*(2*H) := mul_le_mul_of_nonneg_left (by linarith : P^s≤2*H) (by positivity) + _ = 4*w^(Cs+2)*H := by ring + _ ≤ 4*w^(Cs+2)*(w*(b-a)) := mul_le_mul_of_nonneg_left hHlen (by positivity) + _ = (4*w)*(w^(Cs+2)*(b-a)) := by ring + _ ≤ w^2*(w^(Cs+2)*(b-a)) := mul_le_mul_of_nonneg_right (by nlinarith : 4*w≤w^2) (by positivity) + _ = _ := by rw [hpower]; ring + have hrel : (b/d)/w^(Cs+4) ≤ b/d-a/d := by + apply (div_le_iff₀ hW).mpr + calc + _ ≤ (w^(Cs+4)*(b-a))/d := div_le_div_of_nonneg_right hwidth hd0.le + _ = _ := by ring + have hlog := Real.log_le_log (hP0.trans_le (hlo.trans hab)) hhi + rw [Real.log_rpow hP0] at hlog + exact ⟨hlo,hab,hhi,hrel,hlog⟩ + +end Erdos970Dependency.SiegelWalfisz + + + +namespace ErdosStoppedArithmetic +open Erdos970Dependency.SiegelWalfisz +attribute [local instance] Classical.propDecidable + +noncomputable def admissiblePairs (T : Finset ℕ) (M : Finset ℤ) (good : ℕ → ℤ → Prop) : + Finset (ℕ × ℤ) := (T.product M).filter (fun pm => good pm.1 pm.2) + +theorem admissible_pair_card_rows (T : Finset ℕ) (M : Finset ℤ) (good : ℕ → ℤ → Prop) : + (admissiblePairs T M good).card = ∑ p ∈ T,(M.filter (good p)).card := by + simp only [admissiblePairs,Finset.card_filter,Finset.product_eq_sprod,Finset.sum_product] + +theorem admissible_pair_card_columns (T : Finset ℕ) (M : Finset ℤ) (good : ℕ → ℤ → Prop) : + (admissiblePairs T M good).card = ∑ m ∈ M,(T.filter (fun p => good p m)).card := by + rw [admissible_pair_card_rows] + simp only [Finset.card_filter] + exact Finset.sum_comm + +theorem prime_multiple_pair_sum (P x y : ℝ) (D T : Finset ℕ) (good : ℕ → ℤ → Prop) + (hD : ∀ d ∈ D,0 < d ∧ (d : ℝ) ≤ P) : + (admissiblePairs T (D.biUnion (fun d => primeMultiplesIn d P x y)) good).card = + ∑ d ∈ D,∑ m ∈ primeMultiplesIn d P x y,(T.filter (fun p => good p m)).card := by + rw [admissible_pair_card_columns] + apply Finset.sum_biUnion + intro d hd e he hne + exact prime_multiple_factors_disjoint P x y d e (hD e he).1 (hD e he).2 hne + +theorem prime_multiple_pair_lower (P x y A B : ℝ) (D T : Finset ℕ) + (good : ℕ → ℤ → Prop) (W : ℕ → ℝ) + (hD : ∀ d ∈ D,0 < d ∧ (d : ℝ) ≤ P) (hB : 0 ≤ B) + (hW : ∀ d ∈ D,0 ≤ W d) + (hM : ∀ d ∈ D,A/(d : ℝ) ≤ ((primeMultiplesIn d P x y).card : ℝ)) + (hTag : ∀ d ∈ D,∀ m ∈ primeMultiplesIn d P x y, + B*W d ≤ ((T.filter (fun p => good p m)).card : ℝ)) : + A*B*(∑ d ∈ D,W d/(d : ℝ)) ≤ + ((admissiblePairs T (D.biUnion (fun d => primeMultiplesIn d P x y)) good).card : ℝ) := by + rw [prime_multiple_pair_sum P x y D T good hD,Nat.cast_sum] + have hEach (d : ℕ) (hd : d ∈ D) : + A*B*(W d/(d : ℝ)) ≤ + ((∑ m ∈ primeMultiplesIn d P x y,(T.filter (fun p => good p m)).card : ℕ) : ℝ) := by + rw [Nat.cast_sum] + calc + _ = (A/(d : ℝ))*(B*W d) := by ring + _ ≤ ((primeMultiplesIn d P x y).card : ℝ)*(B*W d) := + mul_le_mul_of_nonneg_right (hM d hd) (mul_nonneg hB (hW d hd)) + _ = ∑ _m ∈ primeMultiplesIn d P x y,B*W d := by rw [Finset.sum_const,nsmul_eq_mul] + _ ≤ _ := Finset.sum_le_sum (fun m hm => hTag d hd m hm) + rw [Finset.mul_sum] + exact Finset.sum_le_sum hEach + +end ErdosStoppedArithmetic + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma prime_multiple_height_eventually {Cs K : ℝ} (_hCs : 0 ≤ Cs) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop, 4 ≤ w ∧ ∀ P : ℝ, + Real.exp (K*(Real.log w)^3) ≤ P → 3 ≤ P ∧ 2*w^(Cs+2) ≤ P^(1/50:ℝ) := by + let a : ℝ := K/50 + let B : ℝ := Real.log 2+Cs+2 + have ha : 0 < a := by dsimp [a]; positivity + filter_upwards [eventually_ge_atTop (4:ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (max 1 (B/a))), + (exponential_log_cube_tendsto hK).eventually (eventually_ge_atTop (3:ℝ))] + with w hw hh hlarge + refine ⟨hw,?_⟩ + intro P hP + have hP3 : 3 ≤ P := hlarge.trans hP + have hP0 : 0 < P := by linarith + have hw0 : 0 < w := by linarith + let h := Real.log w + have hh1 : 1 ≤ h := (le_max_left _ _).trans hh + have hhb : B/a ≤ h := (le_max_right _ _).trans hh + have hB : B ≤ a*h := by + have he := (div_le_iff₀ ha).mp hhb + simpa only [mul_comm] using he + have hhsq : h ≤ h^2 := by nlinarith + have hBsq : B ≤ a*h^2 := hB.trans (mul_le_mul_of_nonneg_left hhsq ha.le) + have hBcube := mul_le_mul_of_nonneg_right hBsq (show 0 ≤ h by linarith) + have hlog2 : Real.log 2 ≤ Real.log 2*h := by + simpa only [mul_one] using mul_le_mul_of_nonneg_left hh1 (Real.log_pos (by norm_num : (1:ℝ)<2)).le + have hlin : Real.log 2+(Cs+2)*h ≤ a*h^3 := by dsimp [B] at hBcube; nlinarith + have hlogP : K*h^3 ≤ Real.log P := by + have he := Real.log_le_log (Real.exp_pos _) hP + simpa only [Real.log_exp] using he + have he : Real.log 2+(Cs+2)*h ≤ Real.log P*(1/50) := by + dsimp [a] at hlin + nlinarith + refine ⟨hP3,?_⟩ + calc + _ = Real.exp (Real.log 2+(Cs+2)*h) := by + rw [Real.exp_add,Real.exp_log (by norm_num : (0:ℝ)<2),Real.rpow_def_of_pos hw0] + congr 1 + congr 1 + ring + _ ≤ Real.exp (Real.log P*(1/50)) := Real.exp_le_exp.mpr he + _ = _ := (Real.rpow_def_of_pos hP0 _).symm + +lemma prime_multiple_endpoint_loss {eps : ℝ} (heps : 0 < eps) : + ∀ᶠ P : ℝ in atTop, 3 ≤ P ∧ ∀ s d H : ℝ, + 203/100 ≤ s → s ≤ 219/100 → 1 ≤ d → d ≤ P^(19/20:ℝ) → P^s/2 ≤ H → + 2 ≤ (eps/2)*H/(d*(s+1/50)*Real.log P) := by + filter_upwards [eventually_ge_atTop (3:ℝ), + Real.tendsto_log_atTop.eventually (eventually_polynomial_le_exp (24/eps) 1 (by norm_num : (0:ℝ)<1))] + with P hP hp + refine ⟨hP,?_⟩ + intro s d H hs hsUpper hd1 hd hH + have hP0 : 0 < P := by linarith + have hP1 : 1 ≤ P := by linarith + have hd0 : 0 < d := by linarith + have hs0 : 0 < s+1/50 := by linarith + have hlog : 0 < Real.log P := Real.log_pos (by linarith) + have h24 : 24*Real.log P ≤ eps*P := by + have he := mul_le_mul_of_nonneg_right hp.2 heps.le + rw [one_mul,pow_one,Real.exp_log hP0] at he + calc + _ = ((24/eps)*Real.log P)*eps := by field_simp + _ ≤ P*eps := he + _ = _ := mul_comm _ _ + have hdP := prime_multiple_d_le_P hP1 hd + have hP2 := prime_multiple_P_sq_le hP1 (show 2 ≤ s by linarith) + have hden : d*(s+1/50)*Real.log P ≤ 3*P*Real.log P := by + have hm := mul_le_mul hdP (show s+1/50≤3 by linarith) hs0.le hP0.le + have hn := mul_le_mul_of_nonneg_right hm hlog.le + nlinarith only [hn] + have hm := mul_le_mul_of_nonneg_right h24 (show 0≤P/4 by positivity) + have hl := mul_le_mul_of_nonneg_left (show P^2≤2*H by linarith) (show 0≤eps/4 by positivity) + apply (le_div_iff₀ (by positivity : 0 + (prime_multiple_piece_bounds hCs hwHeight.1 hP3 hs hd1 hdSmall hH hheight (le_max_right _ _) hret hy).1) + have hB := retained_negative_data (P:=P) (x:=x) (y:=y) (t:=t) hd (fun hret => + (prime_multiple_piece_bounds hCs hwHeight.1 hP3 hs hd1 hdSmall hH hheight (le_max_right _ _) hret hnx).1) + have hcard : (A.card:ℝ)+(B.card:ℝ) ≤ ((primeMultiplesIn d P x y).card:ℝ) := by + exact_mod_cast signed_prime_sets_card_le hd A B hA hB + let len : ℝ := retainedLength (max x t) y t+retainedLength (max (-y) t) (-x) t + have hsum : (1-delta)*len/((d:ℝ)*Den)-2 ≤ ((primeMultiplesIn d P x y).card:ℝ) := by + calc + _ = ((1-delta)*retainedLength (max x t) y t/((d:ℝ)*Den)-1)+ + ((1-delta)*retainedLength (max (-y) t) (-x) t/((d:ℝ)*Den)-1) := by dsimp [len]; ring + _ ≤ (A.card:ℝ)+(B.card:ℝ) := add_le_add hpCount hnCount + _ ≤ _ := hcard + have htrim : 4*t ≤ delta*H := by + have hweps := (div_le_iff₀ heps).mp hwBudget + have hfrac : 4/w ≤ delta := (div_le_iff₀ hw0).mpr (by dsimp [delta]; nlinarith) + calc + _ = (4/w)*H := by dsimp [t]; ring + _ ≤ _ := mul_le_mul_of_nonneg_right hfrac hH0.le + have hretained := signed_retained_length (show x ≤ y by dsimp [H] at hH0; linarith) ht0.le + change H-4*t ≤ len at hretained + have hLoss := (hP0 P (hwP.trans hPlower)).2 s (d:ℝ) H hs hsUpper hd1 hdSmall hH + have hLoss' : 2 ≤ (eps/2)*H/((d:ℝ)*Den) := by simpa only [Den,mul_assoc] using hLoss + simpa only [H, Den, mul_assoc] using + retained_count_lower (show delta = eps / 4 from rfl) hdelta1 hH0.le hden + htrim hretained hsum hLoss' + obtain ⟨b,hb⟩ := eventually_atTop.mp hev + refine ⟨max 4 b,le_max_left _ _,?_⟩ + intro w hw P s x y d hPlower hPupper hs hsUpper hH hMax hd hdSmall + exact (hb w ((le_max_right _ _).trans hw)).2 P s x y d hPlower hPupper hs hsUpper hH hMax hd hdSmall + +end Erdos970Dependency.SiegelWalfisz + + + +open _root_.Filter +namespace ErdosStoppedArithmetic +open Erdos970Dependency.SiegelWalfisz Erdos970.EulerWeightedLower +attribute [local instance] Classical.propDecidable + +theorem supported_small_factor_bounds (P : ℝ) (hP : 1 < P) (E : Finset ℕ) (d : ℕ) + (hd : d ∈ supportedIntegers E ⌊P^(95/100 : ℝ)⌋₊) : + 0 < d ∧ (d : ℝ) ≤ P^(19/20 : ℝ) ∧ (d : ℝ) ≤ P := by + have hi := Finset.mem_Icc.mp (Finset.mem_filter.mp hd).1 + have hh : (d : ℝ) ≤ P^(95/100 : ℝ) := (Nat.le_floor_iff (Real.rpow_nonneg (by linarith) _)).mp hi.2 + have hexp : (95/100 : ℝ)=(19/20 : ℝ) := by norm_num + refine ⟨hi.1,by simpa only [hexp] using hh,?_⟩ + exact hh.trans (Real.rpow_le_self_of_one_le hP.le (by norm_num)) + +theorem paper_weight_nonneg (E : Finset ℕ) (hE : ∀ p ∈ E,p.Prime) (d : ℕ) : + 0 ≤ paperWeight E d := by + unfold paperWeight + apply Finset.prod_nonneg + intro p hp + have hpr := hE p (Finset.mem_filter.mp hp).1 + have hp2 : (2 : ℝ) ≤ p := by exact_mod_cast hpr.two_le + have hden : 0 < (p : ℝ)-1 := by linarith + have hrec : 1/((p : ℝ)-1) ≤ 1 := (div_le_one hden).mpr (by linarith) + exact sub_nonneg.mpr hrec + +theorem moving_weighted_pair_lower (Cs : ℝ) (hCs : 0 ≤ Cs) : + ∃ K : ℝ,0 < K ∧ ∀ rho : ℝ,1 < rho → ∀ eps : ℝ,0 < eps → eps < 1 → + ∃ w0 : ℝ,4 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → ∀ P s x y : ℝ, + Real.exp (K*(Real.log w)^3) ≤ P → P ≤ Real.exp (rho*K*(Real.log w)^3) → + 203/100 ≤ s → s ≤ 219/100 → P^s/2 ≤ y-x → max |x| |y| ≤ 2*w^(Cs+2)*P^s → + ∀ (E T : Finset ℕ) (good : ℕ → ℤ → Prop) (B : ℝ),E ⊆ primesThrough P → 0 ≤ B → + (∀ d ∈ supportedIntegers E ⌊P^(95/100 : ℝ)⌋₊,∀ m ∈ primeMultiplesIn d P x y, + B*paperWeight E d ≤ ((T.filter (fun p => good p m)).card : ℝ)) → + ((1-eps)*(y-x)/((s+1/50)*Real.log P))*B* + (Real.exp (-Real.eulerMascheroniConstant)*(94/100-eps)) ≤ + ((admissiblePairs T ((supportedIntegers E ⌊P^(95/100 : ℝ)⌋₊).biUnion + (fun d => primeMultiplesIn d P x y)) good).card : ℝ) := by + obtain ⟨K,hK,hPrime⟩ := moving_signed_prime_multiple_lower Cs hCs + refine ⟨K,hK,?_⟩ + intro rho hrho eps heps heps1 + obtain ⟨wS,hwS,hS⟩ := hPrime rho hrho eps heps heps1 + obtain ⟨P0,hP0⟩ := eventually_atTop.mp (weightedSmallSum_eventually_uniform heps) + obtain ⟨wG,hwG⟩ := eventually_atTop.mp + ((exponential_log_cube_tendsto hK).eventually_ge_atTop (max 2 P0)) + refine ⟨max wS wG,hwS.trans (le_max_left _ _),?_⟩ + intro w hw P s x y hPlower hPupper hs hsupper hLength hHeight E T good B hE hB hTag + have hLarge : max 2 P0 ≤ P := (hwG w ((le_max_right _ _).trans hw)).trans hPlower + have hP2 : 2 ≤ P := (le_max_left _ _).trans hLarge + have hP : 1 < P := by linarith + have hPpos : 0 < P := by linarith + have hlog : 0 < Real.log P := Real.log_pos hP + have hspos : 0 < s+1/50 := by linarith + have hLengthPos : 0 < y-x := (by positivity : (0 : ℝ) < P^s/2).trans_le hLength + let A := (1-eps)*(y-x)/((s+1/50)*Real.log P) + have hA : 0 ≤ A := by dsimp [A];positivity + let D := supportedIntegers E ⌊P^(95/100 : ℝ)⌋₊ + have hD (d : ℕ) (hd : d ∈ D) := supported_small_factor_bounds P hP E d hd + have hpr (p : ℕ) (hp : p ∈ E) : p.Prime := primesThrough_prime (hE hp) + have hM (d : ℕ) (hd : d ∈ D) : A/(d : ℝ) ≤ ((primeMultiplesIn d P x y).card : ℝ) := by + have hh := hS w ((le_max_left _ _).trans hw) P s x y d hPlower hPupper hs hsupper + hLength hHeight (hD d hd).1 (hD d hd).2.1 + have he : A/(d : ℝ)=(1-eps)*(y-x)/((d : ℝ)*(s+1/50)*Real.log P) := by + dsimp [A] + simp only [div_eq_mul_inv,mul_inv_rev] + ring + exact he.trans_le hh + have hPairs := prime_multiple_pair_lower P x y A B D T good (paperWeight E) + (fun d hd => ⟨(hD d hd).1,(hD d hd).2.2⟩) hB (fun d _ => paper_weight_nonneg E hpr d) hM hTag + have hWeighted := hP0 P ((le_max_right _ _).trans hLarge) E hE + change A*B*(Real.exp (-Real.eulerMascheroniConstant)*(94/100-eps)) ≤ _ + have hh := mul_le_mul_of_nonneg_left hWeighted (mul_nonneg hA hB) + exact hh.trans hPairs + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/ZetaPoleBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/ZetaPoleBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..e28cadaeda8a9de71c55a931c6d26591e09c7f51 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/ZetaPoleBounds.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.PrincipalEulerCorrection + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Set _root_.Complex + +noncomputable abbrev regularZeta := DirichletCharacter.LFunctionTrivChar₁ 1 + +lemma neg_logDeriv_zeta_pole_split {s : ℂ} (hs : 1 < s.re) : + -logDeriv riemannZeta s = -logDeriv regularZeta s + 1/(s-1) := by + have hs1 : s ≠ 1 := by intro h; simp [h] at hs + have hz := riemannZeta_ne_zero_of_one_le_re hs.le + simp only [logDeriv_apply, regularZeta] + rw [DirichletCharacter.deriv_LFunctionTrivChar₁_apply_of_ne_one 1 hs1] + simp only [DirichletCharacter.LFunctionTrivChar₁, Function.update_of_ne hs1, + DirichletCharacter.LFunctionTrivChar, DirichletCharacter.LFunction_modOne_eq] + field_simp + ring + +theorem exists_regular_zeta_compact_bound : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, 1 ≤ s.re → s.re ≤ 2 → |s.im| ≤ 6 → + ‖logDeriv regularZeta s‖ ≤ C := by + let K : Set ℂ := Icc (1:ℝ) 2 ×ℂ Icc (-6:ℝ) 6 + have hK : IsCompact K := isCompact_Icc.reProdIm isCompact_Icc + have hc : ContinuousOn (fun s => -deriv regularZeta s / regularZeta s) K := by + apply (DirichletCharacter.continuousOn_neg_logDeriv_LFunctionTrivChar₁ 1).mono + intro s hs + right + have hr : 1 ≤ s.re := ((Complex.mem_reProdIm.mp hs).1).1 + simpa only [DirichletCharacter.LFunctionTrivChar, DirichletCharacter.LFunction_modOne_eq] using + riemannZeta_ne_zero_of_one_le_re hr + obtain ⟨C, hC⟩ := hK.exists_bound_of_continuousOn hc + refine ⟨max 1 C, lt_of_lt_of_le zero_lt_one (le_max_left _ _), ?_⟩ + intro s hs hs2 ht + have hm : s ∈ K := ⟨⟨hs,hs2⟩,abs_le.mp ht⟩ + have h := (hC s hm).trans (le_max_right (1:ℝ) C) + simpa only [logDeriv_apply, neg_div, norm_neg] using h + +theorem exists_zeta_small_height_real_bound : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, 1 < s.re → s.re ≤ 2 → |s.im| ≤ 6 → + (-logDeriv riemannZeta s).re ≤ C+(1/(s-1)).re := by + obtain ⟨C,hC,hbound⟩ := exists_regular_zeta_compact_bound + refine ⟨C,hC,?_⟩ + intro s hs hs2 ht + rw [neg_logDeriv_zeta_pole_split hs, Complex.add_re] + have h := (Complex.re_le_norm (-logDeriv regularZeta s)).trans + (by simpa only [norm_neg] using hbound s hs.le hs2 ht) + linarith + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualCouplingError.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualCouplingError.lean new file mode 100644 index 0000000000000000000000000000000000000000..9bbba8439d3b98393b53c3353557a559f6bfad0e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualCouplingError.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.AllLabelDiscrepancy + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualCouplingError + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open MeshRatioLabels ActualSupportIntervals ActualProcessCoupling +open PrimeBinMembership RegeneratingInverseBands AllLabelDiscrepancy + +theorem actual_one_step_failure : ∃ c₁ c₂ C₁ C₂ C₃ D w₀ : ℝ, + 0 < c₁ ∧ 0 < c₂ ∧ 0 < C₁ ∧ 0 < C₂ ∧ 0 < C₃ ∧ 0 < D ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, ∀ h : History w ell S start, + ∀ v : ℝ, ∀ z : CostState, ∀ mesh : ℝ, + ∀ (hnorm : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS3 : 3 ≤ S) (hS : S ≤ (Real.log w)^3) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S), Consistent start → + stateRatio z.1 ≤ S → h.node.side = stateSide z.1 → 0 < mesh → + let Ld := minRatio h.node.side h.node.ratio + let Lc := minRatio (stateSide z.1) (stateRatio z.1) + let Ud := upperSupport S ell h.node.gap + let Uc := upperSupport S ell (gapValue v z) + |Ld-Lc|+mesh ≤ 1 → |Ud-Uc|+mesh ≤ 1 → + jointKernel hnorm hell (show 0 ≤ S from (by linarith)) hS hr hs hsS v mesh (some h,.inl z) + {q | primeLabel w ell S mesh start q.1 ≠ continuousLabel S mesh q.2} ≤ + ENNReal.ofReal (2*((S/mesh+2)*(C₁*(1+S)^5*(mesh^2+Real.exp (-c₁*Real.sqrt ((1/2:ℝ)*Real.log w))))+ + epsilon w+(Real.exp (D*(1+S)^3*|h.node.ratio-stateRatio z.1|)-1)+ + C₂*(1+S)^2*(|Ld-Lc|+|Ud-Uc|+2*mesh+2*Real.exp (-c₂*Real.sqrt ((1/2:ℝ)*Real.log w)))+ + C₃*(1+S)^2*(|Ld-Lc|+|Ud-Uc|+2*mesh))) := by + obtain ⟨c₁,c₂,C₁,C₂,C₃,D,w₀,hc₁,hc₂,hC₁,hC₂,hC₃,hD,hw₀,hbound⟩ := all_label_discrepancy + refine ⟨c₁,c₂,C₁,C₂,C₃,D,w₀,hc₁,hc₂,hC₁,hC₂,hC₃,hD,hw₀,?_⟩ + intro w hw ell S start h v z mesh hnorm hell hS3 hS hr hs hsS hcons hzS hside hm + dsimp only + intro hL hU + exact (jointKernel_mismatch_bound hnorm hell (by linarith) hS hr hs hsS v mesh (some h) (.inl z)).trans + (ENNReal.ofReal_le_ofReal (hbound w hw ell S start h v z mesh hnorm hell hS3 hS hr hs hsS hcons hzS hside hm hL hU)) + +end NumberTheoryLean.ActualCouplingError + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualCouplingUpdates.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualCouplingUpdates.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6da54f3b5174f8fcf780c0a5aed5f9ccf93b6db --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualCouplingUpdates.lean @@ -0,0 +1,949 @@ +import Mathlib.Algebra.Order.BigOperators.Group.Finset +import Mathlib.Basic.Real.Basic +import Mathlib.Probability.Kernel.Composition.Comp +import Mathlib.Probability.Kernel.Composition.MapComap +import Mathlib.Probability.Kernel.Composition.Prod +import Mathlib.Probability.Kernel.WithDensity +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Partitions.CompletedParentInterval +import OAI.NumberTheory.Jacobsthal.Partitions.CrossingBandGeometry +import OAI.NumberTheory.Jacobsthal.Partitions.MeshBoundaryGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Finset +open scoped BigOperators +namespace Erdos970Dependency.MaximalCoupling + +variable {ι : Type*} [Fintype ι] +attribute [local instance] Classical.propDecidable + +noncomputable def common (a b : ι → ℝ) (i : ι) : ℝ := min (a i) (b i) +noncomputable def residual (a b : ι → ℝ) : ℝ := 1 - ∑ i, common a b i +noncomputable def leftRemainder (a b : ι → ℝ) (i : ι) : ℝ := a i - common a b i +noncomputable def rightRemainder (a b : ι → ℝ) (i : ι) : ℝ := b i - common a b i + +noncomputable def matrix (a b : ι → ℝ) (i j : ι) : ℝ := + (if i = j then common a b i else 0) + + if residual a b = 0 then 0 else leftRemainder a b i * rightRemainder a b j / residual a b + +omit [Fintype ι] in +theorem common_nonneg {a b : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (hb : ∀ i, 0 ≤ b i) (i : ι) : + 0 ≤ common a b i := le_min (ha i) (hb i) + +omit [Fintype ι] in +theorem leftRemainder_nonneg (a b : ι → ℝ) (i : ι) : 0 ≤ leftRemainder a b i := + sub_nonneg.mpr (min_le_left _ _) +omit [Fintype ι] in +theorem rightRemainder_nonneg (a b : ι → ℝ) (i : ι) : 0 ≤ rightRemainder a b i := + sub_nonneg.mpr (min_le_right _ _) + +theorem sum_leftRemainder {a b : ι → ℝ} (ha : ∑ i, a i = 1) : + ∑ i, leftRemainder a b i = residual a b := by simp only [leftRemainder, sum_sub_distrib, ha, residual] +theorem sum_rightRemainder {a b : ι → ℝ} (hb : ∑ i, b i = 1) : + ∑ i, rightRemainder a b i = residual a b := by simp only [rightRemainder, sum_sub_distrib, hb, residual] + +theorem residual_nonneg {a b : ι → ℝ} (ha : ∑ i, a i = 1) : 0 ≤ residual a b := by + rw [← sum_leftRemainder ha] + exact sum_nonneg (fun i _ => leftRemainder_nonneg a b i) + +theorem leftRemainder_zero {a b : ι → ℝ} (ha : ∑ i, a i = 1) (hr : residual a b = 0) (i : ι) : + leftRemainder a b i = 0 := by + have h := single_le_sum (fun j _ => leftRemainder_nonneg a b j) (mem_univ i) + rw [sum_leftRemainder ha, hr] at h + exact le_antisymm h (leftRemainder_nonneg a b i) +theorem rightRemainder_zero {a b : ι → ℝ} (hb : ∑ i, b i = 1) (hr : residual a b = 0) (i : ι) : + rightRemainder a b i = 0 := by + have h := single_le_sum (fun j _ => rightRemainder_nonneg a b j) (mem_univ i) + rw [sum_rightRemainder hb, hr] at h + exact le_antisymm h (rightRemainder_nonneg a b i) + +omit [Fintype ι] in + +theorem remainder_product_self (a b : ι → ℝ) (i : ι) : + leftRemainder a b i * rightRemainder a b i = 0 := by + rcases le_total (a i) (b i) with h | h + · simp [leftRemainder, rightRemainder, common, min_eq_left h] + · simp [leftRemainder, rightRemainder, common, min_eq_right h] + +theorem matrix_nonneg {a b : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (hb : ∀ i, 0 ≤ b i) + (hsa : ∑ i, a i = 1) (i j : ι) : 0 ≤ matrix a b i j := by + unfold matrix + apply add_nonneg + · split_ifs <;> first | exact common_nonneg ha hb i | exact le_rfl + · split_ifs + · exact le_rfl + · exact div_nonneg (mul_nonneg (leftRemainder_nonneg a b i) (rightRemainder_nonneg a b j)) (residual_nonneg hsa) + +theorem row_sum {a b : ι → ℝ} (ha : ∑ i, a i = 1) (hb : ∑ i, b i = 1) (i : ι) : + ∑ j, matrix a b i j = a i := by + classical + by_cases hr : residual a b = 0 + · have hz := leftRemainder_zero ha hr i + simp only [matrix, ite_eq_left hr, add_zero] + simp only [sum_ite_eq, mem_univ, ite_true] + unfold leftRemainder at hz + linarith + · simp only [matrix, ite_eq_right hr, sum_add_distrib] + rw [sum_ite_eq] + simp only [mem_univ, ite_true] + rw [← sum_div, ← mul_sum, sum_rightRemainder hb] + rw [mul_div_cancel_right₀ _ hr] + unfold leftRemainder + ring + +theorem column_sum {a b : ι → ℝ} (ha : ∑ i, a i = 1) (hb : ∑ i, b i = 1) (j : ι) : + ∑ i, matrix a b i j = b j := by + classical + by_cases hr : residual a b = 0 + · have hz := rightRemainder_zero hb hr j + simp only [matrix, ite_eq_left hr, add_zero] + simp only [sum_ite_eq', mem_univ, ite_true] + unfold rightRemainder at hz + linarith + · simp only [matrix, ite_eq_right hr, sum_add_distrib] + rw [sum_ite_eq'] + simp only [mem_univ, ite_true] + rw [← sum_div, ← sum_mul, sum_leftRemainder ha] + rw [mul_div_cancel_left₀ _ hr] + unfold rightRemainder + ring + +theorem matrix_diagonal (a b : ι → ℝ) (i : ι) : matrix a b i i = common a b i := by + simp [matrix, remainder_product_self] + +theorem total_mass {a b : ι → ℝ} (ha : ∑ i, a i = 1) (hb : ∑ i, b i = 1) : + ∑ i, ∑ j, matrix a b i j = 1 := by simp_rw [row_sum ha hb]; exact ha + +theorem mismatch_mass {a b : ι → ℝ} (ha : ∑ i, a i = 1) (hb : ∑ i, b i = 1) : + (∑ i, ∑ j, if i ≠ j then matrix a b i j else 0) = residual a b := by + classical + have hi (i : ι) : (∑ j, if i ≠ j then matrix a b i j else 0) + matrix a b i i = a i := by + have h := sum_filter_add_sum_filter_not (univ : Finset ι) (fun j => i ≠ j) (fun j => matrix a b i j) + simp only [sum_filter, not_not, sum_ite_eq, mem_univ, ite_true, row_sum ha hb] at h + exact h + have hsum := congrArg (fun f : ι → ℝ => ∑ i, f i) (funext hi) + simp only [sum_add_distrib, matrix_diagonal, ha] at hsum + unfold residual + linarith + +theorem exists_coupling {a b : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (hb : ∀ i, 0 ≤ b i) + (hsa : ∑ i, a i = 1) (hsb : ∑ i, b i = 1) : + ∃ p : ι → ι → ℝ, (∀ i j, 0 ≤ p i j) ∧ (∀ i, ∑ j, p i j = a i) ∧ + (∀ j, ∑ i, p i j = b j) ∧ + (∑ i, ∑ j, if i ≠ j then p i j else 0) = 1 - ∑ i, min (a i) (b i) := by + exact ⟨matrix a b, matrix_nonneg ha hb hsa, row_sum hsa hsb, column_sum hsa hsb, + mismatch_mass hsa hsb⟩ + +end Erdos970Dependency.MaximalCoupling + +end + +section + +namespace NumberTheoryLean.KernelBinConditioning + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {α β ι : Type*} [MeasurableSpace α] [MeasurableSpace β] + +noncomputable def conditional (K : Kernel α β) {B : Set β} (hB : MeasurableSet B) (default : β) : Kernel α β where + toFun x := if K x B = 0 then Measure.dirac default else (K x B)⁻¹ • (K x).restrict B + measurable' := by + classical + have hm := K.measurable_coe hB + have hscaled : Measurable (fun x => (K x B)⁻¹ • (K x).restrict B) := by + apply Measure.measurable_of_measurable_coe + intro A hA + simp only [Measure.smul_apply, smul_eq_mul, Measure.restrict_apply hA] + exact hm.inv.mul (K.measurable_coe (hA.inter hB)) + exact Measurable.ite (measurableSet_eq_fun hm measurable_const) measurable_const hscaled + +theorem conditional_apply (K : Kernel α β) {B : Set β} (hB : MeasurableSet B) (default : β) (x : α) : + conditional K hB default x = if K x B = 0 then Measure.dirac default else (K x B)⁻¹ • (K x).restrict B := rfl + +instance conditional_isMarkov (K : Kernel α β) [IsMarkovKernel K] {B : Set β} + (hB : MeasurableSet B) (default : β) : IsMarkovKernel (conditional K hB default) := by + constructor + intro x + constructor + classical + rw [conditional_apply] + by_cases hx : K x B = 0 + · rw [ite_eq_left hx] + exact measure_univ + · rw [ite_eq_right hx, Measure.smul_apply, smul_eq_mul, Measure.restrict_apply_univ] + exact ENNReal.inv_mul_cancel hx (measure_ne_top _ _) + +theorem weighted_conditional (K : Kernel α β) [IsMarkovKernel K] {B : Set β} + (hB : MeasurableSet B) (default : β) (x : α) : + (K x B) • conditional K hB default x = (K x).restrict B := by + classical + rw [conditional_apply] + by_cases hx : K x B = 0 + · rw [ite_eq_left hx, hx, zero_smul] + exact (Measure.restrict_eq_zero.mpr hx).symm + · rw [ite_eq_right hx, smul_smul, ENNReal.mul_inv_cancel hx (measure_ne_top _ _), one_smul] + +variable [MeasurableSpace ι] [MeasurableSingletonClass ι] + +noncomputable def labelMass (K : Kernel α β) (label : β → ι) (x : α) (i : ι) : ℝ := + (K x (label ⁻¹' {i})).toReal + +theorem labelMass_measurable (K : Kernel α β) {label : β → ι} (hl : Measurable label) (i : ι) : + Measurable (fun x => labelMass K label x i) := + ENNReal.measurable_toReal.comp (K.measurable_coe (hl (measurableSet_singleton i))) + +omit [MeasurableSpace ι] [MeasurableSingletonClass ι] in +theorem labelMass_nonneg (K : Kernel α β) (label : β → ι) (x : α) (i : ι) : + 0 ≤ labelMass K label x i := ENNReal.toReal_nonneg + +theorem conditional_map_label (K : Kernel α β) [IsMarkovKernel K] {label : β → ι} + (hl : Measurable label) (default : β) (x : α) (i : ι) (hi : K x (label ⁻¹' {i}) ≠ 0) : + (conditional K (hl (measurableSet_singleton i)) default x).map label = Measure.dirac i := by + have hAE : ∀ᵐ y ∂conditional K (hl (measurableSet_singleton i)) default x, label y = i := by + rw [conditional_apply, ite_eq_right hi] + apply Measure.ae_smul_measure + simpa only [Set.mem_preimage, Set.mem_singleton_iff] using + ae_restrict_mem (hl (measurableSet_singleton i)) (μ := K x) + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf hl, lintegral_dirac' _ hf] + calc + _ = ∫⁻ _y, f i ∂conditional K (hl (measurableSet_singleton i)) default x := + lintegral_congr_ae (hAE.mono (fun y hy => congrArg f hy)) + _ = _ := by rw [lintegral_const, measure_univ, mul_one] + +variable [Fintype ι] + +theorem labelMass_sum (K : Kernel α β) [IsMarkovKernel K] {label : β → ι} + (hl : Measurable label) (x : α) : ∑ i, labelMass K label x i = 1 := by + have h := sum_measure_preimage_singleton (μ := K x) (Finset.univ : Finset ι) + (fun i _ => hl (measurableSet_singleton i)) + simp only [Finset.coe_univ, Set.preimage_univ, measure_univ] at h + have hr := congrArg ENNReal.toReal h + rw [ENNReal.toReal_sum (fun _ _ => measure_ne_top _ _), ENNReal.toReal_one] at hr + exact hr + +theorem conditional_mixture (K : Kernel α β) [IsMarkovKernel K] {label : β → ι} + (hl : Measurable label) (default : β) (x : α) : + (∑ i, (K x (label ⁻¹' {i})) • conditional K (hl (measurableSet_singleton i)) default x) = K x := by + simp_rw [weighted_conditional] + apply Measure.ext + intro B hB + rw [Measure.finsetSum_apply] + simp_rw [Measure.restrict_apply hB] + have h := sum_measure_preimage_singleton (μ := (K x).restrict B) (Finset.univ : Finset ι) + (fun i _ => hl (measurableSet_singleton i)) + simp only [Finset.coe_univ, Set.preimage_univ, Measure.restrict_apply_univ] at h + have heq : ∀ i : ι, (K x).restrict B (label ⁻¹' {i}) = K x (B ∩ label ⁻¹' {i}) := by + intro i + rw [Measure.restrict_apply (hl (measurableSet_singleton i)), Set.inter_comm] + simp_rw [heq] at h + exact h + +end NumberTheoryLean.KernelBinConditioning + +end + +section + +namespace NumberTheoryLean.KernelCouplingWeights + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open KernelBinConditioning Erdos970Dependency.MaximalCoupling +attribute [local instance] Classical.propDecidable + +variable {α β γ ι : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] +variable [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + +noncomputable def weight (K : Kernel α β) (L : Kernel α γ) (f : β → ι) (g : γ → ι) + (x : α) (i j : ι) : ℝ := matrix (labelMass K f x) (labelMass L g x) i j + +noncomputable def errorMass (K : Kernel α β) (L : Kernel α γ) (f : β → ι) (g : γ → ι) (x : α) : ℝ := + residual (labelMass K f x) (labelMass L g x) + +theorem weight_measurable (K : Kernel α β) (L : Kernel α γ) {f : β → ι} {g : γ → ι} + (hf : Measurable f) (hg : Measurable g) (i j : ι) : Measurable (fun x => weight K L f g x i j) := by + classical + have ha := labelMass_measurable K hf + have hb := labelMass_measurable L hg + have hc (i : ι) : Measurable (fun x => common (labelMass K f x) (labelMass L g x) i) := (ha i).min (hb i) + have hr : Measurable (fun x => residual (labelMass K f x) (labelMass L g x)) := + measurable_const.sub (Finset.measurable_sum univ (fun i _ => hc i)) + have hl : Measurable (fun x => leftRemainder (labelMass K f x) (labelMass L g x) i) := (ha i).sub (hc i) + have hh : Measurable (fun x => rightRemainder (labelMass K f x) (labelMass L g x) j) := (hb j).sub (hc j) + have hd : Measurable (fun x => if i = j then common (labelMass K f x) (labelMass L g x) i else 0) := by + by_cases hij : i = j + · simpa only [ite_eq_left hij] using hc i + · simp only [ite_eq_right hij] + exact measurable_const + exact hd.add (Measurable.ite (measurableSet_eq_fun hr measurable_const) measurable_const ((hl.mul hh).div hr)) + +theorem weight_joint_measurable (K : Kernel α β) (L : Kernel α γ) {f : β → ι} {g : γ → ι} + (hf : Measurable f) (hg : Measurable g) (i j : ι) : + Measurable (Function.uncurry (fun (x : α) (_ : β × γ) => ENNReal.ofReal (weight K L f g x i j))) := + (ENNReal.measurable_ofReal.comp (weight_measurable K L hf hg i j)).comp measurable_fst + +variable (K : Kernel α β) (L : Kernel α γ) [IsMarkovKernel K] [IsMarkovKernel L] +variable {f : β → ι} {g : γ → ι} (hf : Measurable f) (hg : Measurable g) +include hf hg + +omit hg [IsMarkovKernel L] in +theorem weight_nonnegative (x : α) (i j : ι) : 0 ≤ weight K L f g x i j := + matrix_nonneg (labelMass_nonneg K f x) (labelMass_nonneg L g x) (labelMass_sum K hf x) i j + +theorem weight_row (x : α) (i : ι) : ∑ j, weight K L f g x i j = labelMass K f x i := + row_sum (labelMass_sum K hf x) (labelMass_sum L hg x) i + +theorem weight_column (x : α) (j : ι) : ∑ i, weight K L f g x i j = labelMass L g x j := + column_sum (labelMass_sum K hf x) (labelMass_sum L hg x) j + +theorem weight_total (x : α) : ∑ i, ∑ j, weight K L f g x i j = 1 := + total_mass (labelMass_sum K hf x) (labelMass_sum L hg x) + +theorem weight_row_ofReal (x : α) (i : ι) : + ∑ j, ENNReal.ofReal (weight K L f g x i j) = K x (f ⁻¹' {i}) := by + rw [← ENNReal.ofReal_sum_of_nonneg (fun j _ => weight_nonnegative K L (g := g) hf x i j), weight_row K L hf hg] + exact ENNReal.ofReal_toReal (measure_ne_top _ _) + +theorem weight_column_ofReal (x : α) (j : ι) : + ∑ i, ENNReal.ofReal (weight K L f g x i j) = L x (g ⁻¹' {j}) := by + rw [← ENNReal.ofReal_sum_of_nonneg (fun i _ => weight_nonnegative K L (g := g) hf x i j), weight_column K L hf hg] + exact ENNReal.ofReal_toReal (measure_ne_top _ _) + +theorem weight_total_ofReal (x : α) : ∑ i, ∑ j, ENNReal.ofReal (weight K L f g x i j) = 1 := by + simp_rw [weight_row_ofReal K L hf hg] + have h := sum_measure_preimage_singleton (μ := K x) (Finset.univ : Finset ι) + (fun i _ => hf (measurableSet_singleton i)) + simpa only [Finset.coe_univ, Set.preimage_univ, measure_univ] using h + +theorem weight_le_left (x : α) (i j : ι) : weight K L f g x i j ≤ labelMass K f x i := by + have h := single_le_sum (fun j _ => weight_nonnegative K L (g := g) hf x i j) (Finset.mem_univ j) + rwa [weight_row K L hf hg] at h + +theorem weight_le_right (x : α) (i j : ι) : weight K L f g x i j ≤ labelMass L g x j := by + have h := single_le_sum (fun i _ => weight_nonnegative K L (g := g) hf x i j) (Finset.mem_univ i) + rwa [weight_column K L hf hg] at h + +theorem weight_zero_left (x : α) (i j : ι) (hi : K x (f ⁻¹' {i}) = 0) : weight K L f g x i j = 0 := by + apply le_antisymm _ (weight_nonnegative K L (g := g) hf x i j) + have h := weight_le_left K L hf hg x i j + simpa only [labelMass, hi, ENNReal.toReal_zero] using h + +theorem weight_zero_right (x : α) (i j : ι) (hj : L x (g ⁻¹' {j}) = 0) : weight K L f g x i j = 0 := by + apply le_antisymm _ (weight_nonnegative K L (g := g) hf x i j) + have h := weight_le_right K L hf hg x i j + simpa only [labelMass, hj, ENNReal.toReal_zero] using h + +theorem weight_mismatch (x : α) : + (∑ i, ∑ j, if i ≠ j then weight K L f g x i j else 0) = errorMass K L f g x := by + exact mismatch_mass (labelMass_sum K hf x) (labelMass_sum L hg x) + +end NumberTheoryLean.KernelCouplingWeights + +end + +section + +namespace NumberTheoryLean.KernelCouplingLift + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open KernelBinConditioning KernelCouplingWeights + +variable {α β γ ι : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] +variable [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] +variable (K : Kernel α β) (L : Kernel α γ) [IsMarkovKernel K] [IsMarkovKernel L] +variable {f : β → ι} {g : γ → ι} (hf : Measurable f) (hg : Measurable g) (dβ : β) (dγ : γ) + +noncomputable def component (i j : ι) : Kernel α (β × γ) := + ((conditional K (hf (measurableSet_singleton i)) dβ).prod + (conditional L (hg (measurableSet_singleton j)) dγ)).withDensity + (fun x _ => ENNReal.ofReal (weight K L f g x i j)) + +instance component_isSFinite (i j : ι) : IsSFiniteKernel (component K L hf hg dβ dγ i j) := by + unfold component + apply Kernel.IsSFiniteKernel.withDensity + intro x y + exact ENNReal.ofReal_ne_top + +theorem component_apply (i j : ι) (x : α) : + component K L hf hg dβ dγ i j x = ENNReal.ofReal (weight K L f g x i j) • + (conditional K (hf (measurableSet_singleton i)) dβ x).prod + (conditional L (hg (measurableSet_singleton j)) dγ x) := by + rw [component, Kernel.withDensity_apply _ (weight_joint_measurable K L hf hg i j) x, + Kernel.prod_apply, withDensity_const] + +noncomputable def coupled : Kernel α (β × γ) := + Kernel.sum (fun p : ι × ι => component K L hf hg dβ dγ p.1 p.2) + +instance coupled_isSFinite : IsSFiniteKernel (coupled K L hf hg dβ dγ) := by + unfold coupled + infer_instance + +theorem coupled_apply_set (x : α) {B : Set (β × γ)} (hB : MeasurableSet B) : + coupled K L hf hg dβ dγ x B = ∑ i, ∑ j, ENNReal.ofReal (weight K L f g x i j) * + ((conditional K (hf (measurableSet_singleton i)) dβ x).prod + (conditional L (hg (measurableSet_singleton j)) dγ x)) B := by + rw [coupled, Kernel.sum_apply' _ _ hB, tsum_fintype, Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro i hi + apply Finset.sum_congr rfl + intro j hj + rw [component_apply, Measure.smul_apply, smul_eq_mul] + +instance coupled_isMarkov : IsMarkovKernel (coupled K L hf hg dβ dγ) := by + constructor + intro x + constructor + rw [coupled_apply_set K L hf hg dβ dγ x MeasurableSet.univ] + simp only [measure_univ, mul_one] + exact weight_total_ofReal K L hf hg x + +theorem coupled_map_fst (x : α) : + (coupled K L hf hg dβ dγ x).map Prod.fst = K x := by + apply Measure.ext + intro B hB + rw [Measure.map_apply measurable_fst hB, coupled_apply_set K L hf hg dβ dγ x (measurable_fst hB)] + have hpre : (Prod.fst ⁻¹' B : Set (β × γ)) = B ×ˢ univ := by ext p; simp + rw [hpre] + simp only [Measure.prod_prod, measure_univ, mul_one] + simp_rw [← Finset.sum_mul, weight_row_ofReal K L hf hg] + have h := congrArg (fun μ : Measure β => μ B) (conditional_mixture K hf dβ x) + simpa only [Measure.finsetSum_apply, Measure.smul_apply, smul_eq_mul] using h + +theorem coupled_map_snd (x : α) : + (coupled K L hf hg dβ dγ x).map Prod.snd = L x := by + apply Measure.ext + intro B hB + rw [Measure.map_apply measurable_snd hB, coupled_apply_set K L hf hg dβ dγ x (measurable_snd hB)] + have hpre : (Prod.snd ⁻¹' B : Set (β × γ)) = univ ×ˢ B := by ext p; simp + rw [hpre] + simp only [Measure.prod_prod, measure_univ, one_mul] + rw [Finset.sum_comm] + simp_rw [← Finset.sum_mul, weight_column_ofReal K L hf hg] + have h := congrArg (fun μ : Measure γ => μ B) (conditional_mixture L hg dγ x) + simpa only [Measure.finsetSum_apply, Measure.smul_apply, smul_eq_mul] using h + +end NumberTheoryLean.KernelCouplingLift + +end + +section + +namespace NumberTheoryLean.KernelCouplingLabels + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open KernelBinConditioning KernelCouplingWeights KernelCouplingLift +open Erdos970Dependency.MaximalCoupling + +variable {α β γ ι : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] +variable [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] +variable (K : Kernel α β) (L : Kernel α γ) [IsMarkovKernel K] [IsMarkovKernel L] +variable {f : β → ι} {g : γ → ι} (hf : Measurable f) (hg : Measurable g) (dβ : β) (dγ : γ) +include hf hg + +theorem component_labels (i j : ι) (x : α) : + (component K L hf hg dβ dγ i j x).map (Prod.map f g) = + ENNReal.ofReal (weight K L f g x i j) • Measure.dirac (i,j) := by + by_cases hi : K x (f ⁻¹' {i}) = 0 + · simp only [component_apply, weight_zero_left K L hf hg x i j hi, ENNReal.ofReal_zero, zero_smul, Measure.map_zero] + · by_cases hj : L x (g ⁻¹' {j}) = 0 + · simp only [component_apply, weight_zero_right K L hf hg x i j hj, ENNReal.ofReal_zero, zero_smul, Measure.map_zero] + · rw [component_apply, Measure.map_smul _ (hf.prodMap hg).aemeasurable, ← Measure.map_prod_map _ _ hf hg, + conditional_map_label K hf dβ x i hi, conditional_map_label L hg dγ x j hj, + Measure.dirac_prod_dirac] + +theorem coupled_labels (x : α) : + (coupled K L hf hg dβ dγ x).map (Prod.map f g) = + Measure.sum (fun p : ι × ι => ENNReal.ofReal (weight K L f g x p.1 p.2) • Measure.dirac p) := by + rw [coupled, Kernel.sum_apply, Measure.map_sum (hf.prodMap hg).aemeasurable] + apply congrArg Measure.sum + funext p + exact component_labels K L hf hg dβ dγ p.1 p.2 x + +theorem coupled_mismatch (x : α) : + coupled K L hf hg dβ dγ x {p : β × γ | f p.1 ≠ g p.2} = + ENNReal.ofReal (errorMass K L f g x) := by + classical + let D : Set (ι × ι) := {p | p.1 ≠ p.2} + have hD : MeasurableSet D := (Set.to_countable D).measurableSet + change coupled K L hf hg dβ dγ x ((Prod.map f g) ⁻¹' D) = _ + rw [← Measure.map_apply (hf.prodMap hg) hD, coupled_labels, Measure.sum_apply _ hD, + tsum_fintype, Fintype.sum_prod_type] + simp only [Measure.smul_apply, smul_eq_mul, Measure.dirac_apply' _ hD, Set.indicator, + D, Set.mem_ofPred_eq, Pi.one_apply, mul_ite, mul_one, mul_zero] + have hn (i j : ι) : 0 ≤ if i ≠ j then weight K L f g x i j else 0 := by + split_ifs + · exact weight_nonnegative K L (g := g) hf x i j + · exact le_rfl + have he : (∑ i, ∑ j, if i ≠ j then ENNReal.ofReal (weight K L f g x i j) else 0) = + ENNReal.ofReal (∑ i, ∑ j, if i ≠ j then weight K L f g x i j else 0) := by + rw [ENNReal.ofReal_sum_of_nonneg (fun i _ => Finset.sum_nonneg (fun j _ => hn i j))] + apply Finset.sum_congr rfl + intro i hi + rw [ENNReal.ofReal_sum_of_nonneg (fun j _ => hn i j)] + apply Finset.sum_congr rfl + intro j hj + split_ifs <;> simp only [ENNReal.ofReal_zero] + rw [he, weight_mismatch K L hf hg] + +omit hg [IsMarkovKernel L] in +theorem errorMass_le_l1 (x : α) : errorMass K L f g x ≤ + ∑ i, |labelMass K f x i-labelMass L g x i| := by + rw [errorMass, ← sum_leftRemainder (labelMass_sum K hf x)] + apply Finset.sum_le_sum + intro i hi + unfold leftRemainder common + rcases le_total (labelMass K f x i) (labelMass L g x i) with hab | hba + · rw [min_eq_left hab, sub_self] + exact abs_nonneg _ + · rw [min_eq_right hba] + exact le_abs_self _ + +theorem coupled_mismatch_le_l1 (x : α) : + coupled K L hf hg dβ dγ x {p : β × γ | f p.1 ≠ g p.2} ≤ + ENNReal.ofReal (∑ i, |labelMass K f x i-labelMass L g x i|) := by + rw [coupled_mismatch] + exact ENNReal.ofReal_le_ofReal (errorMass_le_l1 K L (g := g) hf x) + +end NumberTheoryLean.KernelCouplingLabels + +end + +section + +namespace NumberTheoryLean.ActualProcessCoupling + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ContinuousKilledBins MeshRatioLabels KernelCouplingLift KernelCouplingLabels KernelBinConditioning + +abbrev JointState (w ell S : ℝ) (start : Node) := + ChainState w ell S start × CemeteryKernel.Space CostState + +noncomputable def primeLabel (w ell S mesh : ℝ) (start : Node) : ChainState w ell S start → Label S mesh + | none => cemeteryLabel S mesh + | some h => ratioLabel S mesh h.node.ratio + +noncomputable def continuousLabel (S mesh : ℝ) : CemeteryKernel.Space CostState → Label S mesh := + Sum.elim (fun z => ratioLabel S mesh (stateRatio z.1)) (fun _ => cemeteryLabel S mesh) + +theorem primeLabel_measurable (w ell S mesh : ℝ) (start : Node) : Measurable (primeLabel w ell S mesh start) := + measurable_of_countable _ + +theorem continuousLabel_measurable (S mesh : ℝ) : Measurable (continuousLabel S mesh) := + ((ratioLabel_measurable S mesh).comp (stateRatio_measurable.comp measurable_fst)).sumElim measurable_const + +noncomputable def primeParent (w ell S : ℝ) (start : Node) : Kernel (JointState w ell S start) (ChainState w ell S start) := + (chain w ell S start).comap Prod.fst measurable_fst + +noncomputable def continuousParent (w ell S : ℝ) (start : Node) (v : ℝ) : + Kernel (JointState w ell S start) (CemeteryKernel.Space CostState) := + (continuousChain v ell S).comap Prod.snd measurable_snd + +instance primeParent_isMarkov (w ell S : ℝ) (start : Node) [IsMarkovKernel (chain w ell S start)] : + IsMarkovKernel (primeParent w ell S start) := by unfold primeParent; infer_instance + +instance continuousParent_isMarkov (w ell S : ℝ) (start : Node) (v : ℝ) : + IsMarkovKernel (continuousParent w ell S start v) := by unfold continuousParent; infer_instance + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) +variable (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +noncomputable def jointKernel + (_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) + (v mesh : ℝ) : Kernel (JointState w ell S start) (JointState w ell S start) := by + letI := chain_isMarkov _hw _hell _hS0 _hS _hr _hs _hsS + exact coupled (primeParent w ell S start) (continuousParent w ell S start v) + (primeLabel_measurable w ell S mesh start) (continuousLabel_measurable S mesh) + none CemeteryKernel.dead + +instance jointKernel_isMarkov (v mesh : ℝ) : IsMarkovKernel (jointKernel hw hell hS0 hS hr hs hsS v mesh) := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + unfold jointKernel + infer_instance + +theorem jointKernel_left (v mesh : ℝ) (p : ChainState w ell S start) (z : CemeteryKernel.Space CostState) : + (jointKernel hw hell hS0 hS hr hs hsS v mesh (p,z)).map Prod.fst = chain w ell S start p := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + exact coupled_map_fst (primeParent w ell S start) (continuousParent w ell S start v) + (primeLabel_measurable w ell S mesh start) (continuousLabel_measurable S mesh) + none CemeteryKernel.dead (p,z) + +theorem jointKernel_right (v mesh : ℝ) (p : ChainState w ell S start) (z : CemeteryKernel.Space CostState) : + (jointKernel hw hell hS0 hS hr hs hsS v mesh (p,z)).map Prod.snd = continuousChain v ell S z := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + exact coupled_map_snd (primeParent w ell S start) (continuousParent w ell S start v) + (primeLabel_measurable w ell S mesh start) (continuousLabel_measurable S mesh) + none CemeteryKernel.dead (p,z) + +theorem jointKernel_mismatch_bound (v mesh : ℝ) (p : ChainState w ell S start) (z : CemeteryKernel.Space CostState) : + jointKernel hw hell hS0 hS hr hs hsS v mesh (p,z) + {q | primeLabel w ell S mesh start q.1 ≠ continuousLabel S mesh q.2} ≤ + ENNReal.ofReal (∑ i : Label S mesh, + |(chain w ell S start p ((primeLabel w ell S mesh start) ⁻¹' {i})).toReal - + (continuousChain v ell S z ((continuousLabel S mesh) ⁻¹' {i})).toReal|) := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + exact coupled_mismatch_le_l1 (primeParent w ell S start) (continuousParent w ell S start v) + (primeLabel_measurable w ell S mesh start) (continuousLabel_measurable S mesh) + none CemeteryKernel.dead (p,z) + +end NumberTheoryLean.ActualProcessCoupling + +end + +section + +namespace NumberTheoryLean.ActualCouplingSupport + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ContinuousKilledBins MeshRatioLabels ActualProcessCoupling LowStateHorizon + +variable {w ell S : ℝ} {start : Node} + +def continuousSupported (S : ℝ) : CemeteryKernel.Space CostState → Prop + | .inl z => stateRatio z.1 ≤ S + | .inr _ => True + +def badRatio (S : ℝ) : Set CostState := {z | ¬stateRatio z.1 ≤ S} + +theorem badRatio_measurable (S : ℝ) : MeasurableSet (badRatio S) := + (measurableSet_le (stateRatio_measurable.comp measurable_fst) measurable_const).compl + +theorem unsupported_eq (S : ℝ) : + {q : CemeteryKernel.Space CostState | ¬continuousSupported S q} = Sum.inl '' badRatio S := by + ext q + cases q <;> simp [continuousSupported,badRatio] + +theorem continuousSupported_measurable (S : ℝ) : MeasurableSet {q | continuousSupported S q} := by + have h : MeasurableSet {q : CemeteryKernel.Space CostState | ¬continuousSupported S q} := by + rw [unsupported_eq] + exact (badRatio_measurable S).inl_image + simpa only [Set.compl_ofPred, not_not] using h.compl + +theorem continuous_supported (v ell S : ℝ) (q : CemeteryKernel.Space CostState) : + ∀ᵐ y ∂continuousChain v ell S q, continuousSupported S y := by + apply ae_iff.mpr + rw [unsupported_eq] + cases q with + | inl z => + rw [continuousChain, CemeteryKernel.complete_live_mass _ _ (badRatio_measurable S), + lowKernel, Kernel.restrict_apply, Measure.restrict_apply (badRatio_measurable S)] + have he : badRatio S ∩ lowDomain v ell S = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro y hy + exact hy.1 hy.2.2 + rw [he,measure_empty] + | inr u => + cases u + change Measure.dirac (CemeteryKernel.dead : CemeteryKernel.Space CostState) (Sum.inl '' badRatio S) = 0 + rw [Measure.dirac_apply' _ (badRatio_measurable S).inl_image, indicator_of_notMem (by simp [CemeteryKernel.dead])] + +def matchedOutcome (mesh : ℝ) : JointState w ell S start → Prop + | (none,.inr _) => True + | (some h,.inl z) => |h.node.ratio-stateRatio z.1| < mesh + | _ => False + +theorem labels_match_outcomes {mesh : ℝ} (hm : 0 < mesh) + (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + (p : ChainState w ell S start) (z : CemeteryKernel.Space CostState) + (hSup : continuousSupported S z) (hlabel : primeLabel w ell S mesh start p = continuousLabel S mesh z) : + matchedOutcome mesh (p,z) := by + cases p with + | none => + cases z with + | inl z => + change cemeteryLabel S mesh = ratioLabel S mesh (stateRatio z.1) at hlabel + exact False.elim (ratioLabel_ne_cemetery hm hSup hlabel.symm) + | inr u => trivial + | some h => + have hpos := valid_pos (terminal_valid hs h.admissible) + have hbound := terminal_ratio_le hsS h.admissible + cases z with + | inl z => + change ratioLabel S mesh h.node.ratio = ratioLabel S mesh (stateRatio z.1) at hlabel + exact matching_ratios_close hm hpos.le (OccupationBoundaries.stateRatio_pos z.1).le hbound hSup hlabel + | inr u => + change ratioLabel S mesh h.node.ratio = cemeteryLabel S mesh at hlabel + exact False.elim (ratioLabel_ne_cemetery hm hbound hlabel) + +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) +variable (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem joint_continuous_supported (v mesh : ℝ) (p : ChainState w ell S start) (z : CemeteryKernel.Space CostState) : + ∀ᵐ q ∂jointKernel hw hell hS0 hS hr hs hsS v mesh (p,z), continuousSupported S q.2 := by + have h : ∀ᵐ q ∂(jointKernel hw hell hS0 hS hr hs hsS v mesh (p,z)).map Prod.snd, continuousSupported S q := by + rw [jointKernel_right hw hell hS0 hS hr hs hsS] + exact continuous_supported v ell S z + exact (ae_map_iff measurable_snd.aemeasurable (continuousSupported_measurable S)).mp h + +theorem joint_matching_control (v : ℝ) {mesh : ℝ} (hm : 0 < mesh) + (p : ChainState w ell S start) (z : CemeteryKernel.Space CostState) : + ∀ᵐ q ∂jointKernel hw hell hS0 hS hr hs hsS v mesh (p,z), + primeLabel w ell S mesh start q.1 = continuousLabel S mesh q.2 → matchedOutcome mesh q := by + filter_upwards [joint_continuous_supported hw hell hS0 hS hr hs hsS v mesh p z] with q hq + intro heq + exact labels_match_outcomes hm hs hsS q.1 q.2 hq heq + +end NumberTheoryLean.ActualCouplingSupport + +end + +section + +namespace NumberTheoryLean.ActualCouplingFinite + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ContinuousKilledBins PrimeChainHorizon LowStateHorizon + +section Generic +variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] +variable (K : Kernel α α) (L : Kernel β β) +variable {f : α → β} (hf : Measurable f) + +include hf + +theorem map_power_of_step (hstep : ∀ x, (K x).map f = L (f x)) (n : ℕ) (x : α) : + ((K^n) x).map f = (L^n) (f x) := by + let P : Kernel α β := Kernel.deterministic f hf + have hinter : P ∘ₖ K = L ∘ₖ P := by + rw [show P = Kernel.deterministic f hf from rfl, Kernel.deterministic_comp_eq_map, + Kernel.comp_deterministic_eq_comap] + ext x : 1 + rw [Kernel.map_apply _ hf,Kernel.comap_apply] + exact hstep x + have hpow : ∀ n, P ∘ₖ (K^n) = (L^n) ∘ₖ P := by + intro n + induction n with + | zero => + change P ∘ₖ (Kernel.id : Kernel α α) = Kernel.id ∘ₖ P + rw [Kernel.comp_id,Kernel.id_comp] + | succ n ih => + have hp : K^(n+1) = (K^n) ∘ₖ K := pow_succ _ _ + have hq : L^(n+1) = (L^n) ∘ₖ L := pow_succ _ _ + rw [hp,hq,← Kernel.comp_assoc,ih,Kernel.comp_assoc,hinter,← Kernel.comp_assoc] + have h := hpow n + rw [show P = Kernel.deterministic f hf from rfl,Kernel.deterministic_comp_eq_map, + Kernel.comp_deterministic_eq_comap] at h + have hx := congrArg (fun M : Kernel α β => M x) h + rwa [Kernel.map_apply _ hf,Kernel.comap_apply] at hx +end Generic + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) +variable (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +instance jointKernel_pow_markov (v mesh : ℝ) (n : ℕ) : + IsMarkovKernel ((jointKernel hw hell hS0 hS hr hs hsS v mesh)^n) := by + induction n with + | zero => change IsMarkovKernel (Kernel.id : Kernel (JointState w ell S start) (JointState w ell S start)); infer_instance + | succ n ih => + let := ih + have hp : (jointKernel hw hell hS0 hS hr hs hsS v mesh)^(n+1) = + (jointKernel hw hell hS0 hS hr hs hsS v mesh) ∘ₖ ((jointKernel hw hell hS0 hS hr hs hsS v mesh)^n) := pow_succ' _ _ + rw [hp] + infer_instance + +theorem joint_power_left (v mesh : ℝ) (n : ℕ) (q : JointState w ell S start) : + (((jointKernel hw hell hS0 hS hr hs hsS v mesh)^n) q).map Prod.fst = + ((chain w ell S start)^n) q.1 := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + exact map_power_of_step _ _ measurable_fst + (fun x => jointKernel_left hw hell hS0 hS hr hs hsS v mesh x.1 x.2) n q + +theorem joint_power_right (v mesh : ℝ) (n : ℕ) (q : JointState w ell S start) : + (((jointKernel hw hell hS0 hS hr hs hsS v mesh)^n) q).map Prod.snd = + ((continuousChain v ell S)^n) q.2 := + map_power_of_step _ _ measurable_snd + (fun x => jointKernel_right hw hell hS0 hS hr hs hsS v mesh x.1 x.2) n q + +noncomputable def jointPathLaw (v mesh : ℝ) (z : CostState) (n : ℕ) : Measure (JointState w ell S start) := + ((jointKernel hw hell hS0 hS hr hs hsS v mesh)^n) (some History.empty,.inl z) + +instance jointPathLaw_probability (v mesh : ℝ) (z : CostState) (n : ℕ) : + IsProbabilityMeasure (jointPathLaw hw hell hS0 hS hr hs hsS v mesh z n) := by + unfold jointPathLaw + infer_instance + +theorem jointPathLaw_prime (v mesh : ℝ) (z : CostState) (n : ℕ) : + (jointPathLaw hw hell hS0 hS hr hs hsS v mesh z n).map Prod.fst = pathLaw w ell S start n := + joint_power_left hw hell hS0 hS hr hs hsS v mesh n (some History.empty,.inl z) + +theorem jointPathLaw_continuous (v mesh : ℝ) (z : CostState) (n : ℕ) : + (jointPathLaw hw hell hS0 hS hr hs hsS v mesh z n).map Prod.snd = + ((continuousChain v ell S)^n) (.inl z) := + joint_power_right hw hell hS0 hS hr hs hsS v mesh n (some History.empty,.inl z) + +theorem jointPathLaw_stage (v mesh : ℝ) (z : CostState) (n : ℕ) : + ∀ᵐ q ∂jointPathLaw hw hell hS0 hS hr hs hsS v mesh z n, stage n q.1 := by + have h : ∀ᵐ p ∂(jointPathLaw hw hell hS0 hS hr hs hsS v mesh z n).map Prod.fst, stage n p := by + rw [jointPathLaw_prime hw hell hS0 hS hr hs hsS] + exact pathLaw_stage n + exact (ae_map_iff measurable_fst.aemeasurable (stage_measurable n)).mp h + +theorem jointPathLaw_prime_exit {B : ℝ} (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) + (v mesh : ℝ) (z : CostState) (n : ℕ) (hn : sourceHorizon S B ≤ n) : + ∀ᵐ q ∂jointPathLaw hw hell hS0 hS hr hs hsS v mesh z n, q.1 = none := by + have h : ∀ᵐ p ∂(jointPathLaw hw hell hS0 hS hr hs hsS v mesh z n).map Prod.fst, p = none := by + rw [jointPathLaw_prime hw hell hS0 hS hr hs hsS, + pathLaw_eq_cemetery hw hell hS0 hS hr hs hsS hB hsize n hn] + exact (ae_dirac_iff (measurableSet_singleton _)).mpr rfl + exact (ae_map_iff measurable_fst.aemeasurable (measurableSet_singleton _)).mp h + +end NumberTheoryLean.ActualCouplingFinite + +end + +section + +namespace NumberTheoryLean.ActualCouplingUpdates + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualCouplingSupport ContinuousKilledBins +open LowStateHorizon NearbyParentGeometry ArrivalKernelGeometry RegeneratingInverseBands +open PrimeTiltGeometry PrimeHistoryHorizon KernelDensityBridge PairedCostGrouping + +variable {w ell S : ℝ} {start : Node} + +def liftPredicate {α : Type*} (P : α → Prop) : CemeteryKernel.Space α → Prop := + Sum.elim P (fun _ => True) + +theorem liftPredicate_measurable {α : Type*} [MeasurableSpace α] {P : α → Prop} + (hP : MeasurableSet {x | P x}) : MeasurableSet {x | liftPredicate P x} := by + exact measurableSet_sum_iff.mpr ⟨hP,MeasurableSet.univ⟩ + +theorem complete_ae {α : Type*} [MeasurableSpace α] (K : Kernel α α) (x : α) + {P : α → Prop} (hP : MeasurableSet {y | P y}) (h : ∀ᵐ y ∂K x, P y) : + ∀ᵐ y ∂CemeteryKernel.complete K (.inl x), liftPredicate P y := by + rw [CemeteryKernel.complete_live,CemeteryKernel.liveRow_apply,ae_add_measure_iff] + constructor + · exact (ae_map_iff measurable_inl.aemeasurable (liftPredicate_measurable hP)).mpr h + · apply Measure.ae_smul_measure _ _ + exact (ae_dirac_iff (liftPredicate_measurable hP)).mpr trivial + +def primeFollows (h : History w ell S start) : ChainState w ell S start → Prop + | none => True + | some k => ∃ p, ∃ hp : p ∈ nodeChildren w ell S h.node, k = h.append p hp + +theorem prime_follows (h : History w ell S start) : + ∀ᵐ k ∂chain w ell S start (some h), primeFollows h k := by + classical + apply ae_iff.mpr + simp [chain_some,completedLaw,liveLaw,primeFollows] + intro p hp + exact Or.inr ⟨p,hp,rfl⟩ + +theorem side_set_measurable (i : Side) : MeasurableSet {s : State | stateSide s = i} := by + cases i <;> apply measurableSet_sum_iff.mpr <;> simp [stateSide] + +theorem stateKernel_side (s : State) : + ∀ᵐ t ∂stateKernel s, stateSide t = (stateSide s).flip := by + cases s with + | inl s => + change ∀ᵐ t ∂evenBranch s, stateSide t = Side.odd + rw [evenBranch,Kernel.map_apply _ measurable_inr] + exact (ae_map_iff measurable_inr.aemeasurable (side_set_measurable .odd)).mpr + (Filter.Eventually.of_forall (fun _ => rfl)) + | inr s => + change ∀ᵐ t ∂oddBranch s, stateSide t = Side.even + rw [oddBranch,Kernel.map_apply _ measurable_inl] + exact (ae_map_iff measurable_inl.aemeasurable (side_set_measurable .even)).mpr + (Filter.Eventually.of_forall (fun _ => rfl)) + +def continuousFollows (z y : CostState) : Prop := + y.2 = z.2+cost (stateRatio y.1) ∧ stateSide y.1 = (stateSide z.1).flip + +theorem continuousFollows_measurable (z : CostState) : MeasurableSet {y | continuousFollows z y} := + (measurableSet_eq_fun measurable_snd + (measurable_const.add (cost_measurable.comp (stateRatio_measurable.comp measurable_fst)))).inter + (measurable_fst (side_set_measurable (stateSide z.1).flip)) + +theorem costKernel_follows (z : CostState) : ∀ᵐ y ∂costKernel z, continuousFollows z y := by + have hm : Measurable (fun s : State => (s,z.2+cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + rw [costKernel_eq_map] + apply (ae_map_iff hm.aemeasurable (continuousFollows_measurable z)).mpr + filter_upwards [stateKernel_side z.1] with y hy + exact ⟨rfl,hy⟩ + +theorem continuous_follows (v ell S : ℝ) (z : CostState) : + ∀ᵐ y ∂continuousChain v ell S (.inl z), liftPredicate (continuousFollows z) y := by + apply complete_ae _ _ (continuousFollows_measurable z) + exact ae_restrict_of_ae (costKernel_follows z) + +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) +variable (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem joint_follows (v mesh : ℝ) (h : History w ell S start) (z : CostState) : + ∀ᵐ q ∂jointKernel hw hell hS0 hS hr hs hsS v mesh (some h,.inl z), + primeFollows h q.1 ∧ liftPredicate (continuousFollows z) q.2 := by + have hL : ∀ᵐ p ∂(jointKernel hw hell hS0 hS hr hs hsS v mesh (some h,.inl z)).map Prod.fst, + primeFollows h p := by + rw [jointKernel_left hw hell hS0 hS hr hs hsS] + exact prime_follows h + have hR : ∀ᵐ y ∂(jointKernel hw hell hS0 hS hr hs hsS v mesh (some h,.inl z)).map Prod.snd, + liftPredicate (continuousFollows z) y := by + rw [jointKernel_right hw hell hS0 hS hr hs hsS] + exact continuous_follows v ell S z + exact ((ae_map_iff measurable_fst.aemeasurable (show MeasurableSet {p | primeFollows h p} from trivial)).mp hL).and + ((ae_map_iff measurable_snd.aemeasurable (liftPredicate_measurable (continuousFollows_measurable z))).mp hR) + +include hell hr hs + +theorem prime_step_gap (h : History w ell S start) (p : ℕ) (hp : p ∈ nodeChildren w ell S h.node) : + (h.append p hp).node.gap = nextGap h.node.gap (h.append p hp).node.ratio := by + have hrg := terminal_gap_positive (show 0 ≤ ell by linarith) hr hs h.admissible + have hvalid := terminal_valid hs h.admissible + rw [History.append_node] + exact (nextGap_childRatio hrg (child_exponent_positive (show 0 ≤ ell by linarith) hp) + (valid_pos (child_valid hvalid hp))).symm + +theorem matched_live_update {v mesh d : ℝ} (h k : History w ell S start) (z y : CostState) + (hfollow : primeFollows h (some k)) (hcont : continuousFollows z y) + (hside : h.node.side = stateSide z.1) + (hgap : |Real.log h.node.gap-Real.log (gapValue v z)| ≤ d) + (hmatch : |k.node.ratio-stateRatio y.1| ≤ mesh) : + k.node.side = stateSide y.1 ∧ + |Real.log k.node.gap-Real.log (gapValue v y)| ≤ d+4*mesh := by + obtain ⟨p,hp,rfl⟩ := hfollow + have hrg := terminal_gap_positive (show 0 ≤ ell by linarith) hr hs h.admissible + have hnext := terminal_valid hs (h.append p hp).admissible + constructor + · rw [History.append_node] + change h.node.side.flip = stateSide y.1 + rw [hcont.2,hside] + · have hy : y = (y.1,z.2+cost (stateRatio y.1)) := Prod.ext rfl hcont.1 + have hygap : gapValue v y = nextGap (gapValue v z) (stateRatio y.1) := by + calc + _ = gapValue v (y.1,z.2+cost (stateRatio y.1)) := congrArg (gapValue v) hy + _ = _ := gapValue_update v z y.1 + rw [prime_step_gap hell hr hs, hygap] + exact log_gap_step hrg (Real.exp_pos _) (PrimeTiltBounds.valid_ge_half hnext) + (CostPrefixTransport.stateRatio_ge_half y.1) hgap hmatch + +end NumberTheoryLean.ActualCouplingUpdates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualUnlistedEvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualUnlistedEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff3c2ca84818118ac0c70c5d61dab438e1fc1c2c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/ActualUnlistedEvent.lean @@ -0,0 +1,44 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UnlistedLocalMass +import OAI.NumberTheory.Jacobsthal.Partitions.SourceRawBoxFactory + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualUnlistedEvent +open ErdosCofactorChoices ErdosSubsetWord ErdosVarianceEligible +open EligibleBoxLists ExpandedCompactPartition FilteredBoxWordMass UnlistedLocalMass +open LogarithmicBinScale +attribute [local instance] Classical.propDecidable + +theorem selected_unlisted_le_unwitnessed_mass {w top xi Cs C B K L alpha beta eps : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℕ) + (M : Finset (Fin (binCount w top xi) → ℕ)) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (m : Fin (binCount w top xi) → ℕ) (hm : m∈M) + (a : ℕ → ℕ) (z : PrimeHistories.Node) (F : Finset (List ℕ)) : + selectedWordMass (globalBins w top xi) m + (unlistedGeometric hw htop hxi Cs C B K L alpha beta a z (eligibleLists Y w Cs M Q) + (CountErrorClassification.badCompactWords w K eps Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a + (SmallSieveFinite.smallEuler ⌊w⌋₊) z F)) ≤ + ∑ f∈(selections (globalBins w top xi) m).filter + (unwitnessedSelection hw htop hxi Y Cs C B K L alpha beta eps a z (Q m)), + (selectionProduct f:ℝ)⁻¹ := by + simp only [selectedWordMass,Finset.sum_filter] + apply Finset.sum_le_sum + intro f hf + split_ifs with hU hActual hActual + · exact le_rfl + · apply False.elim + apply hActual + exact EligibleListWord.unlisted_compact_selected_data hw htop hxi Y M Q m hm f hf a z F hU + · exact inv_nonneg.mpr (Nat.cast_nonneg _) + · exact le_rfl +end NumberTheoryLean.ActualUnlistedEvent + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/ArrivalKernelGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/ArrivalKernelGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..97d9803bc3225df636fc4d5b09a9044bfe6c3791 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/ArrivalKernelGeometry.lean @@ -0,0 +1,629 @@ +import Mathlib.Probability.Kernel.Composition.Comp +import Mathlib.Probability.Kernel.WithDensity +import OAI.NumberTheory.Jacobsthal.Estimates.EvenInverseBands + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.KernelWeightTransform + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {α : Type*} [MeasurableSpace α] + +structure PositiveWeight (α : Type*) [MeasurableSpace α] where + value : α → ℝ≥0∞ + measurable_value : Measurable value + ne_zero : ∀ a, value a ≠ 0 + ne_top : ∀ a, value a ≠ ∞ + +instance : CoeFun (PositiveWeight α) (fun _ => α → ℝ≥0∞) := ⟨PositiveWeight.value⟩ + +theorem ratio_measurable (w : PositiveWeight α) : + Measurable (Function.uncurry (fun a b => w b / w a)) := + (w.measurable_value.comp measurable_snd).div (w.measurable_value.comp measurable_fst) + +theorem ratio_ne_top (w : PositiveWeight α) (a b : α) : w b / w a ≠ ∞ := + ENNReal.div_ne_top (w.ne_top b) (w.ne_zero a) + +theorem ratio_cocycle (w : PositiveWeight α) (a b c : α) : + (w b / w a) * (w c / w b) = w c / w a := by + simp only [div_eq_mul_inv] + calc + _ = (w b * (w b)⁻¹) * (w c * (w a)⁻¹) := by ring + _ = _ := by rw [ENNReal.mul_inv_cancel (w.ne_zero b) (w.ne_top b), one_mul] + +noncomputable def conjugate (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) : Kernel α α := + K.withDensity (fun a b => w b / w a) + +instance conjugate_isSFiniteKernel (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) : + IsSFiniteKernel (conjugate K w) := Kernel.IsSFiniteKernel.withDensity K (ratio_ne_top w) + +instance kernelPower_isSFiniteKernel (K : Kernel α α) [IsSFiniteKernel K] (n : ℕ) : + IsSFiniteKernel (K ^ n) := by + induction n with + | zero => change IsSFiniteKernel (Kernel.id : Kernel α α); infer_instance + | succ n ih => + have hp : K ^ (n + 1) = K ∘ₖ (K ^ n) := pow_succ' _ _ + rw [hp] + infer_instance + +theorem conjugate_apply (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) (a : α) : + conjugate K w a = (K a).withDensity (fun b => w b / w a) := + Kernel.withDensity_apply K (ratio_measurable w) a + +theorem conjugate_lintegral (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) (a : α) + {F : α → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ b, F b ∂conjugate K w a) = ∫⁻ b, (w b / w a) * F b ∂K a := + Kernel.lintegral_withDensity K (ratio_measurable w) a hF + +theorem conjugate_id (w : PositiveWeight α) : conjugate (Kernel.id : Kernel α α) w = Kernel.id := by + ext a : 1 + apply Measure.ext_of_lintegral + intro F hF + rw [conjugate_lintegral _ w a hF, + Kernel.lintegral_id' (f := fun b => (w b / w a) * F b) ((w.measurable_value.div measurable_const).mul hF), + ENNReal.div_self (w.ne_zero a) (w.ne_top a), one_mul, Kernel.lintegral_id' hF] + +theorem conjugate_comp (L K : Kernel α α) [IsSFiniteKernel L] [IsSFiniteKernel K] + (w : PositiveWeight α) : + (conjugate L w) ∘ₖ (conjugate K w) = conjugate (L ∘ₖ K) w := by + ext a : 1 + apply Measure.ext_of_lintegral + intro F hF + have hInner : Measurable (fun b => ∫⁻ c, F c ∂conjugate L w b) := hF.lintegral_kernel + have hWeighted : Measurable (fun c => (w c / w a) * F c) := + (w.measurable_value.div measurable_const).mul hF + rw [Kernel.lintegral_comp _ _ _ hF, + conjugate_lintegral K w a (F := fun b => ∫⁻ c, F c ∂conjugate L w b) hInner, + conjugate_lintegral (L ∘ₖ K) w a hF, + Kernel.lintegral_comp L K a hWeighted] + apply lintegral_congr + intro b + rw [conjugate_lintegral L w b hF, + ← lintegral_const_mul' _ _ (ratio_ne_top w a b)] + apply lintegral_congr + intro c + rw [← mul_assoc, ratio_cocycle] + +theorem conjugate_congr (L K : Kernel α α) [IsSFiniteKernel L] [IsSFiniteKernel K] + (h : L = K) (w : PositiveWeight α) : conjugate L w = conjugate K w := by + subst K + rfl + +theorem conjugate_pow (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) (n : ℕ) : + (conjugate K w) ^ n = conjugate (K ^ n) w := by + induction n with + | zero => + change (Kernel.id : Kernel α α) = conjugate Kernel.id w + exact (conjugate_id w).symm + | succ n ih => + have hp : (conjugate K w) ^ (n + 1) = (conjugate K w) ∘ₖ ((conjugate K w) ^ n) := pow_succ' _ _ + have hq : K ^ (n + 1) = K ∘ₖ (K ^ n) := pow_succ' _ _ + rw [hp, ih, conjugate_comp] + exact conjugate_congr (K ∘ₖ (K ^ n)) (K ^ (n + 1)) hq.symm w + +theorem conjugate_pow_lintegral (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) + (n : ℕ) (a : α) {F : α → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ b, F b ∂((conjugate K w) ^ n) a) = + (w a)⁻¹ * ∫⁻ b, w b * F b ∂(K ^ n) a := by + rw [conjugate_pow, conjugate_lintegral _ w a hF] + calc + _ = ∫⁻ b, (w a)⁻¹ * (w b * F b) ∂(K ^ n) a := by + apply lintegral_congr + intro b + rw [div_eq_mul_inv] + ring + _ = _ := lintegral_const_mul' _ _ (ENNReal.inv_ne_top.mpr (w.ne_zero a)) + +theorem conjugate_prefix_sum (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) : + Kernel.sum (fun n : ℕ => (conjugate K w) ^ n) = + conjugate (Kernel.sum (fun n : ℕ => K ^ n)) w := by + calc + _ = Kernel.sum (fun n : ℕ => conjugate (K ^ n) w) := by + apply congrArg Kernel.sum + funext n + exact conjugate_pow K w n + _ = _ := (Kernel.withDensity_kernel_sum (fun n : ℕ => K ^ n) (fun _ => inferInstance) + (fun a b => w b / w a)).symm + +end NumberTheoryLean.KernelWeightTransform + +end + +section + +namespace NumberTheoryLean.KernelExitBarrier + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open KernelWeightTransform + +variable {α β γ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] + +theorem restrict_inner_comp (K : Kernel α β) (L : Kernel γ α) {A : Set α} (hA : MeasurableSet A) + (hzero : ∀ a ∉ A, K a = 0) : K ∘ₖ (L.restrict hA) = K ∘ₖ L := by + classical + ext z B hB + rw [Kernel.comp_apply' _ _ _ hB, Kernel.comp_apply' _ _ _ hB, Kernel.restrict_apply, + ← lintegral_indicator hA] + apply lintegral_congr + intro a + by_cases ha : a ∈ A + · rw [indicator_of_mem ha] + · rw [indicator_of_notMem ha, hzero a ha] + simp + +theorem restricted_pow_eq (K : Kernel α α) {A : Set α} (hA : MeasurableSet A) + (hNoReturn : ∀ a ∉ A, K a A = 0) (n : ℕ) : + (K.restrict hA) ^ (n + 1) = (K ^ (n + 1)).restrict hA := by + have hz : ∀ a ∉ A, K.restrict hA a = 0 := by + intro a ha + rw [Kernel.restrict_apply] + exact Measure.restrict_eq_zero.mpr (hNoReturn a ha) + induction n with + | zero => simp + | succ n ih => + have hL : (K.restrict hA) ^ (n + 1 + 1) = (K.restrict hA) ∘ₖ ((K.restrict hA) ^ (n + 1)) := pow_succ' _ _ + have hR : K ^ (n + 1 + 1) = K ∘ₖ (K ^ (n + 1)) := pow_succ' _ _ + rw [hL, ih, restrict_inner_comp (K.restrict hA) (K ^ (n + 1)) hA hz, + Kernel.comp_restrict hA, hR] + +theorem restricted_future_sum (K : Kernel α α) {A : Set α} (hA : MeasurableSet A) + (hNoReturn : ∀ a ∉ A, K a A = 0) : + Kernel.sum (fun n : ℕ => (K.restrict hA) ^ (n + 1)) = + (Kernel.sum (fun n : ℕ => K ^ (n + 1))).restrict hA := by + ext z B hB + rw [Kernel.sum_apply' _ _ hB, Kernel.restrict_apply' _ _ _ hB, + Kernel.sum_apply' _ _ (hB.inter hA)] + apply tsum_congr + intro n + rw [restricted_pow_eq K hA hNoReturn, Kernel.restrict_apply' _ _ _ hB] + +theorem conjugate_restrict (K : Kernel α α) [IsSFiniteKernel K] (w : PositiveWeight α) + {A : Set α} (hA : MeasurableSet A) : + (conjugate K w).restrict hA = conjugate (K.restrict hA) w := by + ext a : 1 + rw [Kernel.restrict_apply, conjugate_apply K w a, conjugate_apply (K.restrict hA) w a, + Kernel.restrict_apply, MeasureTheory.restrict_withDensity hA] + +end NumberTheoryLean.KernelExitBarrier + +end + +section + +namespace NumberTheoryLean.KernelMappedDomination + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open KernelWeightTransform + +variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + +theorem mapped_pow_lintegral_le (K : Kernel α α) (L : Kernel β β) + [IsSFiniteKernel K] [IsSFiniteKernel L] (P : α → β) (hP : Measurable P) + (hrow : ∀ x, (K x).map P ≤ L (P x)) : + ∀ n : ℕ, ∀ x : α, ∀ f : β → ℝ≥0∞, Measurable f → + (∫⁻ y, f (P y) ∂(K^n) x) ≤ ∫⁻ y, f y ∂(L^n) (P x) := by + intro n + induction n with + | zero => + intro x f hf + change (∫⁻ y, f (P y) ∂Measure.dirac x) ≤ ∫⁻ y, f y ∂Measure.dirac (P x) + rw [lintegral_dirac' _ (f := fun y => f (P y)) (hf.comp hP), lintegral_dirac' _ hf] + | succ n ih => + intro x f hf + have hp : K^(n+1) = (K^n) ∘ₖ K := pow_succ _ _ + have hq : L^(n+1) = (L^n) ∘ₖ L := pow_succ _ _ + rw [hp, hq, + Kernel.lintegral_comp _ _ _ (g := fun y => f (P y)) (hf.comp hP), + Kernel.lintegral_comp _ _ _ hf] + have hF : Measurable (fun y => ∫⁻ t, f t ∂(L^n) y) := hf.lintegral_kernel + calc + _ ≤ ∫⁻ y, ∫⁻ t, f t ∂(L^n) (P y) ∂K x := lintegral_mono (fun y => ih y f hf) + _ = ∫⁻ y, ∫⁻ t, f t ∂(L^n) y ∂(K x).map P := + (lintegral_map (f := fun y => ∫⁻ t, f t ∂(L^n) y) hF hP).symm + _ ≤ _ := lintegral_mono' (hrow x) le_rfl + +theorem mapped_pow_le (K : Kernel α α) (L : Kernel β β) + [IsSFiniteKernel K] [IsSFiniteKernel L] (P : α → β) (hP : Measurable P) + (hrow : ∀ x, (K x).map P ≤ L (P x)) (n : ℕ) (x : α) : + ((K^n) x).map P ≤ (L^n) (P x) := by + apply Measure.le_iff.mpr + intro A hA + have hf : Measurable (A.indicator (fun _ : β => (1 : ℝ≥0∞))) := measurable_const.indicator hA + have h := mapped_pow_lintegral_le K L P hP hrow n x _ hf + rw [← lintegral_map (f := A.indicator (fun _ : β => (1 : ℝ≥0∞))) hf hP] at h + simpa only [lintegral_indicator hA, lintegral_const, one_mul, Measure.restrict_apply_univ] using h + +theorem mapped_prefix_sum_le (K : Kernel α α) (L : Kernel β β) + [IsSFiniteKernel K] [IsSFiniteKernel L] (P : α → β) (hP : Measurable P) + (hrow : ∀ x, (K x).map P ≤ L (P x)) (x : α) + {f : β → ℝ≥0∞} (hf : Measurable f) : + (∑' n : ℕ, ∫⁻ y, f (P y) ∂(K^n) x) ≤ + ∑' n : ℕ, ∫⁻ y, f y ∂(L^n) (P x) := + ENNReal.tsum_le_tsum (fun n => mapped_pow_lintegral_le K L P hP hrow n x f hf) + +theorem mapped_pow_lintegral_eq (K : Kernel α α) (L : Kernel β β) + [IsSFiniteKernel K] [IsSFiniteKernel L] (P : α → β) (hP : Measurable P) + (hrow : ∀ x, (K x).map P = L (P x)) : + ∀ n : ℕ, ∀ x : α, ∀ f : β → ℝ≥0∞, Measurable f → + (∫⁻ y, f (P y) ∂(K^n) x) = ∫⁻ y, f y ∂(L^n) (P x) := by + intro n + induction n with + | zero => + intro x f hf + change (∫⁻ y, f (P y) ∂Measure.dirac x) = ∫⁻ y, f y ∂Measure.dirac (P x) + rw [lintegral_dirac' _ (f := fun y => f (P y)) (hf.comp hP), lintegral_dirac' _ hf] + | succ n ih => + intro x f hf + have hp : K^(n+1) = (K^n) ∘ₖ K := pow_succ _ _ + have hq : L^(n+1) = (L^n) ∘ₖ L := pow_succ _ _ + rw [hp, hq, Kernel.lintegral_comp _ _ _ (g := fun y => f (P y)) (hf.comp hP), + Kernel.lintegral_comp _ _ _ hf] + have hF : Measurable (fun y => ∫⁻ t, f t ∂(L^n) y) := hf.lintegral_kernel + calc + _ = ∫⁻ y, ∫⁻ t, f t ∂(L^n) (P y) ∂K x := lintegral_congr (fun y => ih y f hf) + _ = ∫⁻ y, ∫⁻ t, f t ∂(L^n) y ∂(K x).map P := + (lintegral_map (f := fun y => ∫⁻ t, f t ∂(L^n) y) hF hP).symm + _ = _ := by rw [hrow x] + +theorem mapped_pow_eq (K : Kernel α α) (L : Kernel β β) + [IsSFiniteKernel K] [IsSFiniteKernel L] (P : α → β) (hP : Measurable P) + (hrow : ∀ x, (K x).map P = L (P x)) (n : ℕ) (x : α) : + ((K^n) x).map P = (L^n) (P x) := by + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf hP] + exact mapped_pow_lintegral_eq K L P hP hrow n x f hf + +end NumberTheoryLean.KernelMappedDomination + +end + +section + +namespace NumberTheoryLean.HarmonicWeightKernel + +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open DerivativeWeights WeightFutureIntegrals TransitionKernels FinitePathGeometry +open FinitePathMeasures OccupationBoundaries InvariantInverseWeights +open KernelWeightTransform CostPrefixTransport OccupationDecomposition + +noncomputable def harmonicWeight : PositiveWeight CostState where + value z := ENNReal.ofReal (Real.exp (-2 * z.2) / stateWeight z.1) + measurable_value := ENNReal.measurable_ofReal.comp + ((Real.measurable_exp.comp (measurable_const.mul measurable_snd)).div + (stateWeight_measurable.comp measurable_fst)) + ne_zero z := (ENNReal.ofReal_pos.mpr (div_pos (Real.exp_pos _) (stateWeight_pos z.1))).ne' + ne_top _ := ENNReal.ofReal_ne_top + +noncomputable def harmonicKernel : Kernel CostState CostState := conjugate costKernel harmonicWeight + +instance harmonicKernel_isSFiniteKernel : IsSFiniteKernel harmonicKernel := by unfold harmonicKernel; infer_instance + +theorem exp_neg_two_cost {t : ℝ} (ht : 0 < t) : + Real.exp (-2 * cost t) = (t / (t + 1)) ^ 2 := by + have h : Real.exp (-cost t) = t / (t + 1) := by + simpa only [nextGap, one_mul] using (nextGap_eq_cost (r := 1) ht).symm + calc + _ = Real.exp (-cost t + -cost t) := congrArg Real.exp (by ring) + _ = Real.exp (-cost t) * Real.exp (-cost t) := Real.exp_add _ _ + _ = _ := by rw [h, pow_two] + +theorem transition_weight_ratio (z : CostState) (s : State) : + harmonicWeight (s, z.2 + cost (stateRatio s)) / harmonicWeight z = + ENNReal.ofReal ((stateRatio s / (stateRatio s + 1)) ^ 2 * + (stateWeight z.1 / stateWeight s)) := by + have hz : 0 < Real.exp (-2 * z.2) / stateWeight z.1 := div_pos (Real.exp_pos _) (stateWeight_pos z.1) + change ENNReal.ofReal (Real.exp (-2 * (z.2 + cost (stateRatio s))) / stateWeight s) / + ENNReal.ofReal (Real.exp (-2 * z.2) / stateWeight z.1) = _ + rw [← ENNReal.ofReal_div_of_pos hz] + congr 1 + rw [show -2 * (z.2 + cost (stateRatio s)) = (-2 * z.2) + (-2 * cost (stateRatio s)) by ring, + Real.exp_add, exp_neg_two_cost (stateRatio_pos s)] + field_simp [(stateWeight_pos z.1).ne', (stateWeight_pos s).ne', (Real.exp_pos (-2 * z.2)).ne'] + +noncomputable def correction (i : Side) (s t : ℝ) : ℝ := + (t / (t + 1)) ^ 2 * (weight i s / weight i.flip t) + +theorem weight_measurable (i : Side) : Measurable (weight i) := by + cases i + · exact phiEven_measurable + · exact phiOdd_continuous.measurable + +theorem correction_measurable (i : Side) (s : ℝ) : Measurable (correction i s) := + ((measurable_id.div (measurable_id.add measurable_const)).pow_const 2).mul + (measurable_const.div (weight_measurable i.flip)) + +noncomputable def harmonicRatioDensity (i : Side) (s : ℝ) : ℝ → ℝ≥0∞ := + (Ici (minRatio i s)).indicator (fun t => ENNReal.ofReal (1 / (t + 1))) + +theorem harmonicRatioDensity_measurable (i : Side) (s : ℝ) : Measurable (harmonicRatioDensity i s) := + (ENNReal.measurable_ofReal.comp (measurable_const.div (measurable_id.add measurable_const))).indicator measurableSet_Ici + +theorem corrected_density_eq {i : Side} {s : ℝ} (hs : Valid i s) (t : ℝ) : + ENNReal.ofReal (transitionDensity i s t) * ENNReal.ofReal (correction i s t) = + harmonicRatioDensity i s t := by + by_cases ht : minRatio i s ≤ t + · have hv := valid_next hs ht + have hp : 0 ≤ transitionDensity i s t := by + unfold transitionDensity tailDensity + rw [indicator_of_mem (show t ∈ Ici (minRatio i s) from ht)] + exact div_nonneg (mul_nonneg (W_pos (valid_pos hv)).le (weight_pos hv).le) (weight_pos hs).le + rw [← ENNReal.ofReal_mul hp, harmonicRatioDensity, + indicator_of_mem (show t ∈ Ici (minRatio i s) from ht)] + congr 1 + have he := step_weight_identity (r := 1) hs ht (by norm_num) + simpa only [correction, nextGap, one_mul, div_one, mul_assoc] using he.symm + · rw [transitionDensity, tailDensity, indicator_of_notMem (show t ∉ Ici (minRatio i s) from ht), + ENNReal.ofReal_zero, zero_mul, harmonicRatioDensity, + indicator_of_notMem (show t ∉ Ici (minRatio i s) from ht)] + +theorem initial_weight_inv (s : State) : (harmonicWeight (s, 0))⁻¹ = ENNReal.ofReal (stateWeight s) := by + change (ENNReal.ofReal (Real.exp (-2 * (0 : ℝ)) / stateWeight s))⁻¹ = _ + rw [mul_zero, Real.exp_zero, ENNReal.ofReal_div_of_pos (stateWeight_pos s), ENNReal.ofReal_one, one_div, inv_inv] + +theorem harmonic_prefix_lintegral (n : ℕ) (s : State) {F : CostState → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ z, F z ∂(harmonicKernel ^ n) (s, 0)) = ENNReal.ofReal (stateWeight s) * + ∫⁻ z, ENNReal.ofReal (Real.exp (-2 * z.2) / stateWeight z.1) * F z ∂(costKernel ^ n) (s, 0) := by + rw [harmonicKernel, conjugate_pow_lintegral costKernel harmonicWeight n (s, 0) hF, initial_weight_inv] + rfl + +noncomputable def harmonicOccupation : Kernel CostState CostState := Kernel.sum (fun n : ℕ => harmonicKernel ^ n) + +instance harmonicOccupation_isSFiniteKernel : IsSFiniteKernel harmonicOccupation := by + unfold harmonicOccupation + infer_instance + +theorem inclusiveOccupation_eq_prefix_sum : inclusiveOccupation = Kernel.sum (fun n : ℕ => costKernel ^ n) := by + ext z B hB + rw [inclusiveOccupation, _root_.add_apply, Measure.add_apply, fullOccupation, + Kernel.sum_apply' _ _ hB, Kernel.sum_apply' _ _ hB] + exact (tsum_eq_zero_add' (f := fun n : ℕ => (costKernel ^ n) z B) ENNReal.summable).symm + +theorem harmonicOccupation_transform : harmonicOccupation = conjugate inclusiveOccupation harmonicWeight := by + rw [harmonicOccupation, harmonicKernel, conjugate_prefix_sum] + exact conjugate_congr _ _ inclusiveOccupation_eq_prefix_sum.symm harmonicWeight + +end NumberTheoryLean.HarmonicWeightKernel + +end + +section + +namespace NumberTheoryLean.HarmonicKernelDensities + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostGrouping +open KernelDensityBridge InvariantInverseWeights KernelWeightTransform HarmonicWeightKernel +open Erdos970Dependency.OrdinaryKernelInvariance Erdos970Dependency.StateKernelInvariance + +theorem harmonic_even_typed (s : EvenState) (T : ℝ) {H : CostState → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y ∂harmonicKernel (.inl s, T)) = + ∫⁻ t : OddState, ENNReal.ofReal (correction .even s.1 t.1) * H (.inr t, T + cost t.1) ∂evenToOdd s := by + have hm : Measurable (fun y : CostState => (harmonicWeight y / harmonicWeight (.inl s, T)) * H y) := + (harmonicWeight.measurable_value.div measurable_const).mul hH + rw [harmonicKernel, conjugate_lintegral costKernel harmonicWeight (.inl s, T) hH, + costKernel_even_lintegral s T (H := fun y : CostState => (harmonicWeight y / harmonicWeight (.inl s, T)) * H y) hm] + apply lintegral_congr + intro t + have hr : harmonicWeight (.inr t, T + cost t.1) / harmonicWeight (.inl s, T) = + ENNReal.ofReal (correction .even s.1 t.1) := by + simpa only [stateRatio, stateWeight, weight, Side.flip, correction, Sum.elim_inl, Sum.elim_inr] using + transition_weight_ratio (.inl s, T) (.inr t) + exact congrArg (fun c : ℝ≥0∞ => c * H (.inr t, T + cost t.1)) hr + +theorem harmonic_odd_typed (s : OddState) (T : ℝ) {H : CostState → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y ∂harmonicKernel (.inr s, T)) = + ∫⁻ t : EvenState, ENNReal.ofReal (correction .odd s.1 t.1) * H (.inl t, T + cost t.1) ∂oddToEven s := by + have hm : Measurable (fun y : CostState => (harmonicWeight y / harmonicWeight (.inr s, T)) * H y) := + (harmonicWeight.measurable_value.div measurable_const).mul hH + rw [harmonicKernel, conjugate_lintegral costKernel harmonicWeight (.inr s, T) hH, + costKernel_odd_lintegral s T (H := fun y : CostState => (harmonicWeight y / harmonicWeight (.inr s, T)) * H y) hm] + apply lintegral_congr + intro t + have hr : harmonicWeight (.inl t, T + cost t.1) / harmonicWeight (.inr s, T) = + ENNReal.ofReal (correction .odd s.1 t.1) := by + simpa only [stateRatio, stateWeight, weight, Side.flip, correction, Sum.elim_inl, Sum.elim_inr] using + transition_weight_ratio (.inr s, T) (.inl t) + exact congrArg (fun c : ℝ≥0∞ => c * H (.inl t, T + cost t.1)) hr + +noncomputable def evenUpdateReal (T t : ℝ) : CostState := (.inr (oddLift t), T + cost t) +noncomputable def oddUpdateReal (T t : ℝ) : CostState := (.inl (evenLift t), T + cost t) + +theorem evenUpdateReal_measurable (T : ℝ) : Measurable (evenUpdateReal T) := + (measurable_inr.comp oddLift_measurable).prodMk (measurable_const.add cost_measurable) + +theorem oddUpdateReal_measurable (T : ℝ) : Measurable (oddUpdateReal T) := + (measurable_inl.comp evenLift_measurable).prodMk (measurable_const.add cost_measurable) + +theorem harmonic_even_joint_lintegral (s : EvenState) (T : ℝ) {H : CostState → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y ∂harmonicKernel (.inl s, T)) = + ∫⁻ t : ℝ, harmonicRatioDensity .even s.1 t * H (evenUpdateReal T t) := by + let G : ℝ → ℝ≥0∞ := fun t => ENNReal.ofReal (correction .even s.1 t) * H (evenUpdateReal T t) + have hG : Measurable G := (ENNReal.measurable_ofReal.comp (correction_measurable .even s.1)).mul + (hH.comp (evenUpdateReal_measurable T)) + rw [harmonic_even_typed s T hH] + calc + _ = ∫⁻ t : OddState, G t.1 ∂evenToOdd s := by + apply lintegral_congr + intro t + simp only [G, evenUpdateReal, oddLift_ratio] + _ = ∫⁻ t : ℝ, G t ∂evenKernel s := evenToOdd_lintegral_ratio s hG + _ = ∫⁻ t : ℝ, ENNReal.ofReal (transitionDensity .even s.1 t) * G t := evenKernel_lintegral_density s hG + _ = _ := by + apply lintegral_congr + intro t + dsimp [G] + rw [← mul_assoc, corrected_density_eq (i := .even) (s := s.1) s.2 t] + +theorem harmonic_odd_joint_lintegral (s : OddState) (T : ℝ) {H : CostState → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y ∂harmonicKernel (.inr s, T)) = + ∫⁻ t : ℝ, harmonicRatioDensity .odd s.1 t * H (oddUpdateReal T t) := by + let G : ℝ → ℝ≥0∞ := fun t => ENNReal.ofReal (correction .odd s.1 t) * H (oddUpdateReal T t) + have hG : Measurable G := (ENNReal.measurable_ofReal.comp (correction_measurable .odd s.1)).mul + (hH.comp (oddUpdateReal_measurable T)) + rw [harmonic_odd_typed s T hH] + calc + _ = ∫⁻ t : EvenState, G t.1 ∂oddToEven s := by + apply lintegral_congr + intro t + simp only [G, oddUpdateReal, evenLift_ratio] + _ = ∫⁻ t : ℝ, G t ∂oddKernel s := oddToEven_lintegral_ratio s hG + _ = ∫⁻ t : ℝ, ENNReal.ofReal (transitionDensity .odd s.1 t) * G t := oddKernel_lintegral_density s hG + _ = _ := by + apply lintegral_congr + intro t + dsimp [G] + rw [← mul_assoc, corrected_density_eq (i := .odd) (s := s.1) s.2 t] + +theorem harmonic_even_measure (s : EvenState) (T : ℝ) : + harmonicKernel (.inl s, T) = + (volume.withDensity (harmonicRatioDensity .even s.1)).map (evenUpdateReal T) := by + apply Measure.ext_of_lintegral + intro H hH + rw [harmonic_even_joint_lintegral s T hH, + lintegral_map hH (evenUpdateReal_measurable T), + lintegral_withDensity_eq_lintegral_mul volume (f := harmonicRatioDensity .even s.1) + (g := fun t => H (evenUpdateReal T t)) (harmonicRatioDensity_measurable .even s.1) + (hH.comp (evenUpdateReal_measurable T))] + rfl + +theorem harmonic_odd_measure (s : OddState) (T : ℝ) : + harmonicKernel (.inr s, T) = + (volume.withDensity (harmonicRatioDensity .odd s.1)).map (oddUpdateReal T) := by + apply Measure.ext_of_lintegral + intro H hH + rw [harmonic_odd_joint_lintegral s T hH, + lintegral_map hH (oddUpdateReal_measurable T), + lintegral_withDensity_eq_lintegral_mul volume (f := harmonicRatioDensity .odd s.1) + (g := fun t => H (oddUpdateReal T t)) (harmonicRatioDensity_measurable .odd s.1) + (hH.comp (oddUpdateReal_measurable T))] + rfl + +end NumberTheoryLean.HarmonicKernelDensities + +end + +section + +namespace NumberTheoryLean.ArrivalKernelGeometry + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostGrouping +open OccupationBoundaries RegeneratingInverseBands KernelDensityBridge +open HarmonicWeightKernel KernelWeightTransform + +noncomputable def currentExponent (v : ℝ) (z : CostState) : ℝ := gapValue v z / stateRatio z.1 + +theorem gapValue_measurable (v : ℝ) : Measurable (gapValue v) := + Real.measurable_exp.comp (measurable_const.sub measurable_snd) + +theorem currentExponent_measurable (v : ℝ) : Measurable (currentExponent v) := + (gapValue_measurable v).div (stateRatio_measurable.comp measurable_fst) + +theorem currentExponent_pos (v : ℝ) (z : CostState) : 0 < currentExponent v z := + div_pos (Real.exp_pos _) (stateRatio_pos z.1) + +def arrivalSet (v ell : ℝ) : Set CostState := {z | ell < currentExponent v z} + +theorem arrivalSet_measurable (v ell : ℝ) : MeasurableSet (arrivalSet v ell) := + measurableSet_lt measurable_const (currentExponent_measurable v) + +theorem arrivalSet_eq_cutoff (v : ℝ) {ell : ℝ} (hell : 0 < ell) : + arrivalSet v ell = {z | stateRatio z.1 < gapValue v z / ell} := by + ext z + change ell < gapValue v z / stateRatio z.1 ↔ stateRatio z.1 < gapValue v z / ell + rw [lt_div_iff₀ (stateRatio_pos z.1), lt_div_iff₀ hell, mul_comm ell (stateRatio z.1)] + +theorem gapValue_update (v : ℝ) (z : CostState) (s : State) : + gapValue v (s, z.2 + cost (stateRatio s)) = nextGap (gapValue v z) (stateRatio s) := by + rw [nextGap_eq_cost (stateRatio_pos s)] + change Real.exp (v - (z.2 + cost (stateRatio s))) = Real.exp (v - z.2) * Real.exp (-cost (stateRatio s)) + rw [show v - (z.2 + cost (stateRatio s)) = (v - z.2) + (-cost (stateRatio s)) by ring, Real.exp_add] + +theorem currentExponent_update (v : ℝ) (z : CostState) (s : State) : + currentExponent v (s, z.2 + cost (stateRatio s)) = nextExponent (gapValue v z) (stateRatio s) := by + change gapValue v (s, z.2 + cost (stateRatio s)) / stateRatio s = _ + rw [gapValue_update, nextGap_div_ratio (stateRatio_pos s)] + +theorem stateKernel_ae_minRatio (s : State) : + ∀ᵐ t ∂stateKernel s, minRatio (stateSide s) (stateRatio s) ≤ stateRatio t := by + cases s with + | inl s => + change ∀ᵐ t ∂stateKernel (.inl s), s.1 - 1 ≤ stateRatio t + have h : ∀ᵐ u ∂(stateKernel (.inl s)).map stateRatio, s.1 - 1 ≤ u := by + rw [stateKernel_even_ratio] + exact evenKernel_ae_support s + exact (ae_map_iff stateRatio_measurable.aemeasurable measurableSet_Ici).mp h + | inr s => + change ∀ᵐ t ∂stateKernel (.inr s), max 2 (s.1 - 1) ≤ stateRatio t + have h : ∀ᵐ u ∂(stateKernel (.inr s)).map stateRatio, max 2 (s.1 - 1) ≤ u := by + rw [stateKernel_odd_ratio] + exact oddKernel_ae_support s + exact (ae_map_iff stateRatio_measurable.aemeasurable measurableSet_Ici).mp h + +theorem costKernel_gap_flow (v : ℝ) (z : CostState) : + ∀ᵐ y ∂costKernel z, gapValue v z = gapValue v y + currentExponent v y := by + have hm : Measurable (fun s : State => (s, z.2 + cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + have hp : MeasurableSet {y : CostState | gapValue v z = gapValue v y + currentExponent v y} := + measurableSet_eq_fun measurable_const ((gapValue_measurable v).add (currentExponent_measurable v)) + rw [costKernel_eq_map] + apply (ae_map_iff hm.aemeasurable hp).mpr + apply Eventually.of_forall + intro s + rw [gapValue_update, currentExponent_update] + exact (gap_exponent_conservation (stateRatio_pos s)).symm + +theorem costKernel_exponent_nonincreasing (v : ℝ) (z : CostState) : + ∀ᵐ y ∂costKernel z, currentExponent v y ≤ currentExponent v z := by + have hm : Measurable (fun s : State => (s, z.2 + cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + have hp : MeasurableSet {y : CostState | currentExponent v y ≤ currentExponent v z} := + measurableSet_le (currentExponent_measurable v) measurable_const + rw [costKernel_eq_map] + apply (ae_map_iff hm.aemeasurable hp).mpr + filter_upwards [stateKernel_ae_minRatio z.1] with s hs + rw [currentExponent_update] + exact exponent_le_cutoff (stateRatio_valid z.1) hs (Real.exp_pos _) + +theorem harmonicKernel_absolutelyContinuous (z : CostState) : harmonicKernel z ≪ costKernel z := + Kernel.withDensity_absolutelyContinuous (fun a b => harmonicWeight b / harmonicWeight a) z + +theorem harmonicKernel_gap_flow (v : ℝ) (z : CostState) : + ∀ᵐ y ∂harmonicKernel z, gapValue v z = gapValue v y + currentExponent v y := + (harmonicKernel_absolutelyContinuous z).ae_le (costKernel_gap_flow v z) + +theorem harmonicKernel_exponent_nonincreasing (v : ℝ) (z : CostState) : + ∀ᵐ y ∂harmonicKernel z, currentExponent v y ≤ currentExponent v z := + (harmonicKernel_absolutelyContinuous z).ae_le (costKernel_exponent_nonincreasing v z) + +theorem costKernel_no_reentry (v ell : ℝ) (z : CostState) (hz : z ∉ arrivalSet v ell) : + costKernel z (arrivalSet v ell) = 0 := by + have hZ : currentExponent v z ≤ ell := le_of_not_gt hz + have h : ∀ᵐ y ∂costKernel z, y ∉ arrivalSet v ell := by + filter_upwards [costKernel_exponent_nonincreasing v z] with y hy + exact not_lt_of_ge (le_trans hy hZ) + simpa only [ae_iff, not_not, Set.ofPred_mem_eq] using h + +theorem harmonicKernel_no_reentry (v ell : ℝ) (z : CostState) (hz : z ∉ arrivalSet v ell) : + harmonicKernel z (arrivalSet v ell) = 0 := + harmonicKernel_absolutelyContinuous z (costKernel_no_reentry v ell z hz) + +end NumberTheoryLean.ArrivalKernelGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/CanonicalPairHitEvents.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/CanonicalPairHitEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..42ee8e50aa2dd2d5f92ee75e37cdbcf475bd36f5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/CanonicalPairHitEvents.lean @@ -0,0 +1,139 @@ +import OAI.NumberTheory.Jacobsthal.Paths.CanonicalWordPrefix + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping + +theorem rawWord_first_prefix_law (w : List Bool) : ∀ a b (past : RawHistory a) (z : OddCost), + rawLast a past=embedOdd z → + (rawMarkedWordKernel a (w++[b]) past).map (wordFirstPrefix a w b)=canonicalWordFirstPrefix a w b past := by + induction w with + | nil => + intro a b past z hz + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (wordFirstPrefix_measurable a [] b)] + change (∫⁻ t : RawCycleWordTrace a [b].length, F (wordFirstPrefix a [] b t) + ∂rawMarkedWordKernel a [b] past)=_ + rw [rawMarkedWord_cons_lintegral a b [] past (F := fun t => F (wordFirstPrefix a [] b t)) + (hF.comp (wordFirstPrefix_measurable a [] b))] + change (∫⁻ r : RawReturnTrace a, ∫⁻ _t, F (@Sigma.mk ℕ RawHistory (a+1) (rawReturnFirstPrefix a r)) + ∂Measure.dirac r.2 ∂rawBranchReturnKernel a b past)=_ + simp only [lintegral_const,measure_univ,mul_one] + have hG : Measurable (fun h : RawHistory (a+1) => F (@Sigma.mk ℕ RawHistory (a+1) h)) := + hF.comp (measurableSigmaMk (a+1)) + rw [← lintegral_map (g := rawReturnFirstPrefix a) hG (rawReturnFirstPrefix_measurable a), + rawBranchReturn_first_prefix a b past z hz,canonicalWordFirstPrefix, + Kernel.map_apply _ (measurableSigmaMk (a+1)),lintegral_map hF (measurableSigmaMk (a+1)),Kernel.restrict_apply] + | cons c w ih => + intro a b past z hz + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (wordFirstPrefix_measurable a (c::w) b)] + change (∫⁻ t : RawCycleWordTrace a (c::(w++[b])).length, F (wordFirstPrefix a (c::w) b t) + ∂rawMarkedWordKernel a (c::(w++[b])) past)=_ + rw [rawMarkedWord_cons_lintegral a c (w++[b]) past (F := fun t => F (wordFirstPrefix a (c::w) b t)) + (hF.comp (wordFirstPrefix_measurable a (c::w) b)),canonicalWordFirstPrefix, + Kernel.lintegral_comp _ _ _ hF] + apply lintegral_congr_ae + filter_upwards [rawBranchReturn_endpoint_supported a c past] with r hr + change (∫⁻ t, F (wordFirstPrefix (a+2*(r.1+1)) w b t) + ∂rawMarkedWordKernel (a+2*(r.1+1)) (w++[b]) r.2)= + ∫⁻ q, F q ∂canonicalWordFirstPrefix (a+2*(r.1+1)) w b r.2 + rw [← lintegral_map (g := wordFirstPrefix (a+2*(r.1+1)) w b) hF (wordFirstPrefix_measurable _ w b), + ih _ b r.2 (decodeReturnedOdd (rawReturnSignature a r).2.2) hr] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels + +noncomputable def pairHitTest (a k b : ℕ) (hab : a+2*k+1 ≤ b) (v H : ℝ) : Set (RawHistory b) := + {h | h ⟨a+2*k,Finset.mem_Iic.mpr (by omega)⟩ ∈ regenerationSet ∧ + firstArrivalMark (h ⟨a+2*k+1,Finset.mem_Iic.mpr hab⟩)=true ∧ + (h ⟨a+2*k,Finset.mem_Iic.mpr (by omega)⟩).2 ∈ Icc v (v+H)} + +lemma pairHitTest_measurable (a k b : ℕ) (hab : a+2*k+1 ≤ b) (v H : ℝ) : + MeasurableSet (pairHitTest a k b hab v H) := + (regenerationSet_measurable.preimage (measurable_pi_apply _)).inter + (((firstArrivalMark_measurable.comp (measurable_pi_apply _)) (measurableSet_singleton true)).inter + (measurableSet_Icc.preimage (measurable_snd.comp (measurable_pi_apply _)))) + +lemma pairHitTest_prefix {a k b c : ℕ} (hab : a+2*k+1 ≤ b) (hbc : b ≤ c) (v H : ℝ) : + rawPrefix hbc ⁻¹' pairHitTest a k b hab v H=pairHitTest a k c (hab.trans hbc) v H := rfl + +noncomputable def noPairHits (a m b : ℕ) (hab : a+2*m ≤ b) (v H : ℝ) : Set (RawHistory b) := + {h | ∀ k : Fin m, h ∉ pairHitTest a k.1 b (by have hk:=k.2; omega) v H} + +lemma noPairHits_measurable (a m b : ℕ) (hab : a+2*m ≤ b) (v H : ℝ) : + MeasurableSet (noPairHits a m b hab v H) := by + unfold noPairHits + simp only [ofPred_forall] + apply MeasurableSet.iInter + intro k + exact (pairHitTest_measurable a k.1 b (by have hk:=k.2; omega) v H).compl + +lemma noPairHits_prefix {a m b c : ℕ} (hab : a+2*m ≤ b) (hbc : b ≤ c) (v H : ℝ) : + rawPrefix hbc ⁻¹' noPairHits a m b hab v H=noPairHits a m c (hab.trans hbc) v H := rfl + +lemma noPairHits_zero (a b : ℕ) (hab : a+2*0 ≤ b) (v H : ℝ) : + noPairHits a 0 b hab v H=univ := by + ext h + simp [noPairHits] + +lemma noPairHits_succ (a n b : ℕ) (hab : a+2*(n+1) ≤ b) (v H : ℝ) : + noPairHits a (n+1) b hab v H = + noPairHits a n b (by omega) v H ∩ (pairHitTest a n b (by omega) v H)ᶜ := by + ext h + change (∀ k : Fin (n+1), h ∉ pairHitTest a k.1 b _ v H) ↔ + (∀ k : Fin n, h ∉ pairHitTest a k.1 b _ v H) ∧ h ∉ pairHitTest a n b _ v H + constructor + · intro hh + exact ⟨fun k => hh k.castSucc,hh (Fin.last n)⟩ + · rintro ⟨hh,hn⟩ k + by_cases hk : k.1 < n + · exact hh ⟨k.1,hk⟩ + · have he : k.1=n := by have := k.2; omega + have hkLast : k=Fin.last n := Fin.ext he + subst k + exact hn + +noncomputable def firstPairHitEvent (a n b : ℕ) (hab : a+2*n+1 ≤ b) (v H : ℝ) : Set (RawHistory b) := + noPairHits a n b (by omega) v H ∩ pairHitTest a n b hab v H + +lemma firstPairHitEvent_measurable (a n b : ℕ) (hab : a+2*n+1 ≤ b) (v H : ℝ) : + MeasurableSet (firstPairHitEvent a n b hab v H) := + (noPairHits_measurable a n b (by omega) v H).inter (pairHitTest_measurable a n b hab v H) + +lemma firstPairHitEvent_prefix {a n b c : ℕ} (hab : a+2*n+1 ≤ b) (hbc : b ≤ c) (v H : ℝ) : + rawPrefix hbc ⁻¹' firstPairHitEvent a n b hab v H=firstPairHitEvent a n c (hab.trans hbc) v H := rfl + +lemma firstPairHitEvent_disjoint {a n m b : ℕ} (hn : a+2*n+1 ≤ b) (hm : a+2*m+1 ≤ b) + (hnm : n ≠ m) (v H : ℝ) : Disjoint (firstPairHitEvent a n b hn v H) (firstPairHitEvent a m b hm v H) := by + apply disjoint_left.mpr + intro h hN hM + obtain hlt | hgt := lt_or_gt_of_ne hnm + · exact (hM.1 ⟨n,hlt⟩) hN.2 + · exact (hN.1 ⟨m,hgt⟩) hM.2 + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/CanonicalPairVisitLaw.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/CanonicalPairVisitLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..49c7e3e97c12a10cbdc3310e18a45b75197f96fa --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/CanonicalPairVisitLaw.lean @@ -0,0 +1,84 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ConsecutivePowerProjection + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.KernelPotential + +noncomputable def canonicalPairVisitKernel (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) FiniteRawHistory := + Kernel.sum (fun n : ℕ => (pairStoppedHistory a n v H).map (@Sigma.mk ℕ RawHistory (a+2*n+1))) + +instance canonicalPairVisitKernel_isSFiniteKernel (a : ℕ) (v H : ℝ) : IsSFiniteKernel (canonicalPairVisitKernel a v H) := by + unfold canonicalPairVisitKernel + infer_instance + +theorem canonicalPairVisit_endpoint (a : ℕ) (v H : ℝ) (past : RawHistory a) : + (canonicalPairVisitKernel a v H past).map finiteRawLast=consecutiveMarkedHit v H (rawLast a past) := by + rw [canonicalPairVisitKernel,Kernel.sum_apply,Measure.map_sum finiteRawLast_measurable.aemeasurable, + consecutiveMarkedHit,potential,Kernel.sum_apply] + apply congrArg Measure.sum + funext n + rw [Kernel.map_apply _ (measurableSigmaMk (a+2*n+1)), + Measure.map_map finiteRawLast_measurable (measurableSigmaMk (a+2*n+1))] + exact pairStoppedHistory_projection a n v H past + +lemma canonicalPairVisit_mass (a : ℕ) (v H : ℝ) (past : RawHistory a) : + canonicalPairVisitKernel a v H past univ=consecutiveMarkedHit v H (rawLast a past) univ := by + have he := congrArg (fun μ : Measure CostState => μ univ) (canonicalPairVisit_endpoint a v H past) + rw [Measure.map_apply finiteRawLast_measurable MeasurableSet.univ,preimage_univ] at he + exact he + +lemma canonicalPairVisit_mass_le_one (a : ℕ) (v H : ℝ) (past : RawHistory a) : + canonicalPairVisitKernel a v H past univ ≤ 1 := by + rw [canonicalPairVisit_mass] + exact consecutiveMarkedHit_mass_le_one v H _ + +instance canonicalPairVisitKernel_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (canonicalPairVisitKernel a v H) := + ⟨⟨1,by simp,canonicalPairVisit_mass_le_one a v H⟩⟩ + +noncomputable def extendFinitePrefix (N : ℕ) : Kernel FiniteRawHistory (RawHistory N) where + toFun q := if q.1 ≤ N then rawExtension q.1 N q.2 else 0 + measurable' := by + apply measurable_sigma_family + intro n + by_cases hn : n ≤ N + · simpa only [hn,ite_true] using (rawExtension n N).measurable + · simp only [hn,ite_false] + exact measurable_const + +instance extendFinitePrefix_isFiniteKernel (N : ℕ) : IsFiniteKernel (extendFinitePrefix N) := by + refine ⟨⟨1,by simp,?_⟩⟩ + intro q + change (if q.1 ≤ N then rawExtension q.1 N q.2 else 0) univ ≤ 1 + split_ifs <;> simp + +lemma extendFinitePrefix_comp_map {α : Type*} [MeasurableSpace α] (N n : ℕ) + (K : Kernel α (RawHistory n)) [IsSFiniteKernel K] : + extendFinitePrefix N ∘ₖ K.map (@Sigma.mk ℕ RawHistory n)= + if n ≤ N then rawExtension n N ∘ₖ K else 0 := by + ext x S hS + rw [Kernel.comp_apply' _ _ _ hS,Kernel.map_apply _ (measurableSigmaMk n), + lintegral_map ((extendFinitePrefix N).measurable_coe hS) (measurableSigmaMk n)] + by_cases hn : n ≤ N + · rw [ite_eq_left hn,Kernel.comp_apply' _ _ _ hS] + apply lintegral_congr + intro h + change (if n ≤ N then rawExtension n N h else 0) S=rawExtension n N h S + rw [ite_eq_left hn] + · rw [ite_eq_right hn] + change (∫⁻ h, (if n ≤ N then rawExtension n N h else 0) S ∂K x)=0 + simp [hn] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/CemeteryHistoryLaw.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/CemeteryHistoryLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c233e87f08f1d4e9e3f33e13d0d6b967df36e76 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/CemeteryHistoryLaw.lean @@ -0,0 +1,407 @@ +import Mathlib.Probability.Kernel.Composition.Comp +import Mathlib.Probability.Kernel.Composition.MapComap +import Mathlib.Probability.Kernel.WithDensity +import OAI.NumberTheory.Jacobsthal.Paths.FiniteHistorySupport + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.CemeteryKernel + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {α : Type*} [MeasurableSpace α] + +abbrev Space (α : Type*) := α ⊕ Unit + +def dead : Space α := Sum.inr () + +noncomputable def cemeteryPart (K : Kernel α α) : Kernel α (Space α) := + (Kernel.const α (Measure.dirac dead)).withDensity (fun x _ => 1-K x univ) + +theorem cemeteryPart_measurable (K : Kernel α α) : + Measurable (Function.uncurry (fun (x : α) (_ : Space α) => 1-K x univ)) := + measurable_const.sub ((K.measurable_coe MeasurableSet.univ).comp measurable_fst) + +theorem cemeteryPart_apply (K : Kernel α α) (x : α) : + cemeteryPart K x = (1-K x univ) • Measure.dirac dead := by + rw [cemeteryPart, Kernel.withDensity_apply _ (cemeteryPart_measurable K) x, Kernel.const_apply, withDensity_const] + +noncomputable def liveRow (K : Kernel α α) : Kernel α (Space α) := K.map Sum.inl + cemeteryPart K + +theorem liveRow_apply (K : Kernel α α) (x : α) : + liveRow K x = (K x).map Sum.inl + (1-K x univ) • Measure.dirac dead := by + rw [liveRow, _root_.add_apply, Kernel.map_apply _ measurable_inl, cemeteryPart_apply] + +noncomputable def complete (K : Kernel α α) : Kernel (Space α) (Space α) where + toFun := Sum.elim (liveRow K) (fun _ => Measure.dirac dead) + measurable' := (liveRow K).measurable.sumElim measurable_const + +@[simp] theorem complete_live (K : Kernel α α) (x : α) : complete K (.inl x) = liveRow K x := rfl +@[simp] theorem complete_dead (K : Kernel α α) : complete K dead = Measure.dirac dead := rfl + +theorem complete_isMarkov (K : Kernel α α) (hK : ∀ x, K x univ ≤ 1) : IsMarkovKernel (complete K) := by + constructor + intro z + constructor + cases z with + | inl x => + rw [complete_live, liveRow_apply, Measure.add_apply, Measure.map_apply measurable_inl MeasurableSet.univ, + Set.preimage_univ, Measure.smul_apply] + simp only [measure_univ, smul_eq_mul, mul_one] + exact add_tsub_cancel_of_le (hK x) + | inr u => + cases u + change Measure.dirac (dead : Space α) univ = 1 + exact measure_univ + +theorem complete_live_mass (K : Kernel α α) (x : α) {B : Set α} (hB : MeasurableSet B) : + complete K (.inl x) (Sum.inl '' B) = K x B := by + rw [complete_live, liveRow_apply, Measure.add_apply, + Measure.map_apply measurable_inl hB.inl_image, Measure.smul_apply] + have hpre : Sum.inl ⁻¹' (Sum.inl '' B : Set (Space α)) = B := Set.preimage_image_eq _ Sum.inl_injective + rw [hpre] + have hd : Measure.dirac (dead : Space α) (Sum.inl '' B) = 0 := by + rw [Measure.dirac_apply' _ hB.inl_image, indicator_of_notMem (by simp [dead])] + rw [hd, smul_zero, add_zero] + +end NumberTheoryLean.CemeteryKernel + +end + +section + +namespace NumberTheoryLean.CemeteryPowers + +open MeasureTheory ProbabilityTheory +open scoped ENNReal +open CemeteryKernel + +variable {α : Type*} [MeasurableSpace α] + +noncomputable def liftReward (F : α → ℝ≥0∞) : Space α → ℝ≥0∞ := Sum.elim F (fun _ => 0) + +theorem liftReward_measurable {F : α → ℝ≥0∞} (hF : Measurable F) : Measurable (liftReward F) := + hF.sumElim measurable_const + +theorem row_lift (K : Kernel α α) {F : α → ℝ≥0∞} (hF : Measurable F) (q : Space α) : + (∫⁻ y,liftReward F y ∂complete K q) = liftReward (fun z => ∫⁻ y,F y ∂K z) q := by + cases q with + | inl z => + rw [complete_live,liveRow_apply,lintegral_add_measure, + lintegral_map (liftReward_measurable hF) measurable_inl, + lintegral_smul_measure,lintegral_dirac' _ (liftReward_measurable hF)] + simp only [liftReward,Sum.elim_inl,dead,Sum.elim_inr,smul_eq_mul,mul_zero,add_zero] + | inr u => + cases u + change (∫⁻ y,liftReward F y ∂Measure.dirac dead) = 0 + rw [lintegral_dirac' _ (liftReward_measurable hF)] + rfl + +theorem power_lift (K : Kernel α α) {F : α → ℝ≥0∞} (hF : Measurable F) (n : ℕ) (q : Space α) : + (∫⁻ y,liftReward F y ∂((complete K)^n) q) = liftReward (fun z => ∫⁻ y,F y ∂(K^n) z) q := by + induction n generalizing q with + | zero => + change (∫⁻ y,liftReward F y ∂Measure.dirac q) = _ + rw [lintegral_dirac' _ (liftReward_measurable hF)] + cases q with + | inl z => + change F z = ∫⁻ y,F y ∂Measure.dirac z + rw [lintegral_dirac' _ hF] + | inr u => rfl + | succ n ih => + have hp : (complete K)^(n+1) = ((complete K)^n) ∘ₖ complete K := pow_succ _ _ + have hl : K^(n+1) = (K^n) ∘ₖ K := pow_succ _ _ + rw [hp,Kernel.lintegral_comp _ _ _ (liftReward_measurable hF)] + calc + _ = ∫⁻ y,liftReward (fun z => ∫⁻ a,F a ∂(K^n) z) y ∂complete K q := lintegral_congr ih + _ = liftReward (fun y => ∫⁻ z,∫⁻ a,F a ∂(K^n) z ∂K y) q := row_lift K hF.lintegral_kernel q + _ = _ := by + cases q with + | inl z => + change _ = ∫⁻ y,F y ∂(K^(n+1)) z + rw [hl,Kernel.lintegral_comp _ _ _ hF] + rfl + | inr u => rfl + +end NumberTheoryLean.CemeteryPowers + +end + +section + +namespace NumberTheoryLean.CemeteryHistoryMap + +open Set MeasureTheory ProbabilityTheory Preorder +open scoped ENNReal +open FiniteHistoryTransport CemeteryKernel + +variable {X : Type*} [MeasurableSpace X] + +def live (z : Space X) : Prop := Sum.elim (fun _ => True) (fun _ => False) z + +theorem live_measurable : MeasurableSet {z : Space X | live z} := + measurableSet_sum_iff.mpr ⟨MeasurableSet.univ,MeasurableSet.empty⟩ + +noncomputable def killStep (E : Set X) (z : Space X) (x : X) : Space X := by + classical + exact if live z ∧ x ∈ E then Sum.inl x else dead + +theorem killStep_measurable {E : Set X} (hE : MeasurableSet E) : + Measurable (fun p : Space X × X => killStep E p.1 p.2) := by + classical + exact Measurable.ite ((measurable_fst live_measurable).inter (measurable_snd hE)) + (measurable_inl.comp measurable_snd) measurable_const + +omit [MeasurableSpace X] in +theorem killStep_eq_or_dead (E : Set X) (z : Space X) (x : X) : + killStep E z x = Sum.inl x ∨ killStep E z x = dead := by + classical + unfold killStep + split_ifs <;> simp + +theorem extend_restrict (n : ℕ) (h : Hist X n) (x : X) : + frestrictLe₂ (π := fun _ => X) n.le_succ (extend n h x) = h := by + ext k + simp [frestrictLe₂, FiniteHistoryTransport.extend, IicProdIoc_def, + show (k:ℕ) ≤ n from Finset.mem_Iic.mp k.2] + +noncomputable def killHist (E : Set X) : (n : ℕ) → Hist X n → Hist (Space X) n + | 0,h => mapHist (fun x : X => (Sum.inl x : Space X)) 0 h + | n+1,h => + let past := killHist E n (frestrictLe₂ (π := fun _ => X) n.le_succ h) + extend n past (killStep E (last n past) (last (n+1) h)) + +theorem killHist_measurable {E : Set X} (hE : MeasurableSet E) (n : ℕ) : + Measurable (killHist E n) := by + induction n with + | zero => exact mapHist_measurable (measurable_inl (α := X) (β := Unit)) 0 + | succ n ih => + have hp := ih.comp (measurable_frestrictLe₂ (X := fun _ => X) n.le_succ) + exact (extend_measurable n).comp (hp.prodMk ((killStep_measurable hE).comp + (((last_measurable n).comp hp).prodMk (last_measurable (n+1))))) + +theorem killHist_extend (E : Set X) (n : ℕ) (h : Hist X n) (x : X) : + killHist E (n+1) (extend n h x) = + extend n (killHist E n h) (killStep E (last n (killHist E n h)) x) := by + simp only [killHist, extend_restrict, extend_last] + +theorem killHist_last (E : Set X) (n : ℕ) (h : Hist X n) : + last n (killHist E n h) = Sum.inl (last n h) ∨ last n (killHist E n h) = dead := by + cases n with + | zero => exact Or.inl rfl + | succ n => + simp only [killHist, extend_last] + exact killStep_eq_or_dead _ _ _ + +end NumberTheoryLean.CemeteryHistoryMap + +end + +section + +namespace NumberTheoryLean.CemeteryHistoryMap + +open Set MeasureTheory ProbabilityTheory Preorder +open FiniteHistoryTransport CemeteryKernel + +attribute [local instance] Classical.propDecidable + +variable {X : Type*} [MeasurableSpace X] + +def aliveThrough (E : Set X) (n : ℕ) (h : Hist X n) : Prop := + ∀ j : Finset.Iic n, 0 < (j:ℕ) → h j ∈ E + +omit [MeasurableSpace X] in +theorem aliveThrough_succ (E : Set X) (n : ℕ) (h : Hist X (n+1)) : + aliveThrough E (n+1) h ↔ + aliveThrough E n (frestrictLe₂ (π := fun _ => X) n.le_succ h) ∧ last (n+1) h ∈ E := by + constructor + · intro ha + refine ⟨?_,ha ⟨n+1,by simp⟩ (Nat.succ_pos n)⟩ + intro j hj + exact ha ⟨j,by have := Finset.mem_Iic.mp j.2; simp; omega⟩ hj + · rintro ⟨ha,hx⟩ ⟨j,hj⟩ hpos + have hj' := Finset.mem_Iic.mp hj + by_cases hle : j ≤ n + · exact ha ⟨j,by simpa using hle⟩ hpos + · have heq : j = n+1 := by omega + subst j + exact hx + +theorem killHist_restrict (E : Set X) (n k : ℕ) (hk : k ≤ n) (h : Hist X n) : + frestrictLe₂ (π := fun _ => Space X) hk (killHist E n h) = + killHist E k (frestrictLe₂ (π := fun _ => X) hk h) := by + induction n generalizing k with + | zero => + have : k = 0 := by omega + subst k + rfl + | succ n ih => + by_cases hkn : k ≤ n + · calc + _ = frestrictLe₂ (π := fun _ => Space X) hkn + (frestrictLe₂ (π := fun _ => Space X) n.le_succ (killHist E (n+1) h)) := rfl + _ = frestrictLe₂ (π := fun _ => Space X) hkn + (killHist E n (frestrictLe₂ (π := fun _ => X) n.le_succ h)) := by + rw [killHist,extend_restrict] + _ = _ := ih k hkn _ + · have heq : k = n+1 := by omega + subst k + rfl + +theorem killHist_last_exact (E : Set X) (n : ℕ) (h : Hist X n) : + last n (killHist E n h) = if aliveThrough E n h then Sum.inl (last n h) else dead := by + classical + induction n with + | zero => + have ha : aliveThrough E 0 h := by + intro j hj + have := Finset.mem_Iic.mp j.2 + omega + simp only [ite_eq_left ha] + rfl + | succ n ih => + rw [killHist,extend_last,ih] + simp only [aliveThrough_succ] + by_cases hp : aliveThrough E n (frestrictLe₂ (π := fun _ => X) n.le_succ h) <;> + by_cases hx : last (n+1) h ∈ E <;> simp [hp,hx,killStep,live,dead] + +theorem killHist_coordinate (E : Set X) (n k : ℕ) (hk : k ≤ n) (h : Hist X n) : + (killHist E n h) ⟨k,by simpa using hk⟩ = + if aliveThrough E k (frestrictLe₂ (π := fun _ => X) hk h) + then Sum.inl (h ⟨k,by simpa using hk⟩) else dead := by + classical + have heq := congrArg (last k) (killHist_restrict E n k hk h) + rw [killHist_last_exact] at heq + exact heq + +end NumberTheoryLean.CemeteryHistoryMap + +end + +section + +namespace NumberTheoryLean.CemeteryHistoryMap + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open CemeteryKernel FiniteHistoryTransport + +variable {X : Type*} [MeasurableSpace X] +variable (K : Kernel X X) [IsMarkovKernel K] {E : Set X} (hE : MeasurableSet E) + +theorem killStep_live_map (x : X) : + (K x).map (killStep E (Sum.inl x)) = complete (K.restrict hE) (Sum.inl x) := by + classical + have hf : Measurable (killStep E (Sum.inl x)) := + (killStep_measurable hE).comp measurable_prodMk_left + have hA : ((K x).restrict E).map (killStep E (Sum.inl x)) = ((K x).restrict E).map Sum.inl := by + apply Measure.map_congr + filter_upwards [ae_restrict_mem hE] with y hy + simp [killStep,live,hy] + have hB : ((K x).restrict Eᶜ).map (killStep E (Sum.inl x)) = + ((K x).restrict Eᶜ).map (fun _ => (dead : Space X)) := by + apply Measure.map_congr + filter_upwards [ae_restrict_mem hE.compl] with y hy + change y ∉ E at hy + simp [killStep,live,hy] + calc + _ = (((K x).restrict E)+((K x).restrict Eᶜ)).map (killStep E (Sum.inl x)) := by + rw [Measure.restrict_add_restrict_compl hE] + _ = ((K x).restrict E).map Sum.inl + (1-K x E) • Measure.dirac dead := by + rw [Measure.map_add _ _ hf, hA, hB, Measure.map_const, Measure.restrict_apply_univ, + measure_compl hE (measure_ne_top _ _), measure_univ] + _ = _ := by + rw [complete_live,liveRow_apply,Kernel.restrict_apply,Measure.restrict_apply_univ] + +theorem killStep_dead_map (x : X) : + (K x).map (killStep E dead) = complete (K.restrict hE) dead := by + classical + have hf : killStep E (dead : Space X) = fun _ => dead := by + funext y + simp [killStep,live,dead] + rw [hf,Measure.map_const,measure_univ,one_smul,complete_dead] + +theorem killHist_step_map (n : ℕ) (h : Hist X n) : + (K (last n h)).map (killStep E (last n (killHist E n h))) = + complete (K.restrict hE) (last n (killHist E n h)) := by + rcases killHist_last E n h with hl | hd + · rw [hl] + exact killStep_live_map K hE _ + · rw [hd] + exact killStep_dead_map K hE _ + +instance restricted_complete_markov : IsMarkovKernel (complete (K.restrict hE)) := by + apply complete_isMarkov + intro x + rw [Kernel.restrict_apply,Measure.restrict_apply_univ] + exact (measure_mono (subset_univ E)).trans_eq (measure_univ (μ := K x)) + +end NumberTheoryLean.CemeteryHistoryMap + +end + +section + +namespace NumberTheoryLean.CemeteryHistoryMap + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open CemeteryKernel FiniteHistoryTransport + +variable {X : Type*} [MeasurableSpace X] +variable (K : Kernel X X) [IsMarkovKernel K] {E : Set X} (hE : MeasurableSet E) + +theorem lintegral_killHist (n : ℕ) (h₀ : Hist X 0) + {F : Hist (Space X) n → ℝ≥0∞} (hF : Measurable F) : + ∫⁻ h, F (killHist E n h) ∂pathKernel K n h₀ = + ∫⁻ h, F h ∂pathKernel (complete (K.restrict hE)) n (mapHist Sum.inl 0 h₀) := by + induction n with + | zero => + simp only [pathKernel,Kernel.partialTraj_self,Kernel.id_apply] + rw [lintegral_dirac' _ (by exact hF.comp (killHist_measurable hE 0)),lintegral_dirac' _ hF] + rfl + | succ n ih => + rw [lintegral_pathKernel_succ K n h₀ (by exact hF.comp (killHist_measurable hE (n+1))), + lintegral_pathKernel_succ (complete (K.restrict hE)) n (mapHist Sum.inl 0 h₀) hF] + have hG : Measurable (fun h : Hist (Space X) n => + ∫⁻ y, F (FiniteHistoryTransport.extend n h y) ∂complete (K.restrict hE) (last n h)) := by + have hm : Measurable (Function.uncurry (fun h : Hist (Space X) n => fun y : Space X => + F (FiniteHistoryTransport.extend n h y))) := hF.comp (extend_measurable n) + simpa only [pastKernel,Kernel.comap_apply] using + (hm.lintegral_kernel_prod_right (κ := pastKernel (complete (K.restrict hE)) n)) + calc + _ = ∫⁻ h, ∫⁻ y, F (FiniteHistoryTransport.extend n (killHist E n h) y) + ∂complete (K.restrict hE) (last n (killHist E n h)) ∂pathKernel K n h₀ := by + apply lintegral_congr + intro h + simp only [killHist_extend] + rw [← killHist_step_map K hE n h,lintegral_map] + · exact hF.comp ((extend_measurable n).comp measurable_prodMk_left) + · exact (killStep_measurable hE).comp measurable_prodMk_left + _ = _ := ih hG + +theorem pathMeasure_killHist (n : ℕ) (h₀ : Hist X 0) : + (pathKernel K n h₀).map (killHist E n) = + pathKernel (complete (K.restrict hE)) n (mapHist Sum.inl 0 h₀) := by + have hk : (pathKernel K n).map (killHist E n) = + (pathKernel (complete (K.restrict hE)) n).comap (mapHist Sum.inl 0) + (mapHist_measurable measurable_inl 0) := by + apply Kernel.ext_fun + intro h F hF + rw [Kernel.lintegral_map _ (killHist_measurable hE n) _ hF,Kernel.comap_apply] + exact lintegral_killHist K hE n h hF + rw [← Kernel.map_apply _ (killHist_measurable hE n),hk,Kernel.comap_apply] + +end NumberTheoryLean.CemeteryHistoryMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/CompletedMarkEvents.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/CompletedMarkEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..177b0df137a87d003c226162a727051a2af7535b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/CompletedMarkEvents.lean @@ -0,0 +1,138 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualThresholdArrival + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.CanonicalMarkSlack + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open FinitePathMeasures FinitePathGeometry ArrivalKernelGeometry RegeneratingInverseBands +open CanonicalCostCoordinates Erdos970Dependency.MarkedVisits + +theorem firstArrivalMark_bounds (z : CostState) (hz : firstArrivalMark z = true) : + stateSide z.1 = .even ∧ 209/100 ≤ stateRatio z.1 ∧ stateRatio z.1 ≤ 213/100 := by + rcases z with ⟨s,T⟩ + cases s with + | inl s => + have h := (sourceMark_true s).mp hz + exact ⟨rfl,h.1,h.2⟩ + | inr s => exact Bool.noConfusion hz + +theorem pair_hit_slack {r b₀ b₁ : ℝ} (hr : 0 < r) (hb₀ : 0 < b₀) (hb₁ : 0 < b₁) + (a k N : ℕ) (hk : a+2*k+1 ≤ N) (h : RawHistory N) + (htime : (h ⟨a+2*k+1,Finset.mem_Iic.mpr hk⟩).2 = + (h ⟨a+2*k,Finset.mem_Iic.mpr (by omega)⟩).2 + + cost (stateRatio (h ⟨a+2*k+1,Finset.mem_Iic.mpr hk⟩).1)) + (hHit : h ∈ pairHitTest a k N hk (Real.log (r/b₁)) (Real.log (b₁/(10*b₀)))) : + let z := h ⟨a+2*k+1,Finset.mem_Iic.mpr hk⟩ + stateSide z.1 = .even ∧ 209/100 ≤ stateRatio z.1 ∧ stateRatio z.1 ≤ 213/100 ∧ + 10*b₀/(313/100) ≤ currentExponent (Real.log r) z ∧ + currentExponent (Real.log r) z ≤ b₁/(309/100) ∧ 6*b₀ < gapValue (Real.log r) z := by + dsimp only + let pre := h ⟨a+2*k,Finset.mem_Iic.mpr (show a+2*k ≤ N by omega)⟩ + let z := h ⟨a+2*k+1,Finset.mem_Iic.mpr hk⟩ + have hmark := firstArrivalMark_bounds z hHit.2.1 + have hwindow := (marked_cost_window hr hb₀ hb₁ pre.2).mpr hHit.2.2 + have hslack := marked_draw_slack hb₀ hwindow.1 hwindow.2 hmark.2.1 hmark.2.2 + have hz : z = (z.1,pre.2+cost (stateRatio z.1)) := Prod.ext rfl htime + have he : currentExponent (Real.log r) z = nextExponent (gapAt r pre.2) (stateRatio z.1) := by + calc + _ = currentExponent (Real.log r) (z.1,pre.2+cost (stateRatio z.1)) := congrArg _ hz + _ = nextExponent (gapValue (Real.log r) pre) (stateRatio z.1) := currentExponent_update _ pre z.1 + _ = _ := by rw [gapValue_log_eq_gapAt hr] + have hg : gapValue (Real.log r) z = nextGap (gapAt r pre.2) (stateRatio z.1) := by + calc + _ = gapValue (Real.log r) (z.1,pre.2+cost (stateRatio z.1)) := congrArg _ hz + _ = nextGap (gapValue (Real.log r) pre) (stateRatio z.1) := gapValue_update _ pre z.1 + _ = _ := by rw [gapValue_log_eq_gapAt hr] + exact ⟨hmark.1,hmark.2.1,hmark.2.2,he ▸ hslack.1,he ▸ hslack.2.1,hg ▸ hslack.2.2.2.2.1⟩ + +theorem canonical_all_marks_slack {r b₀ b₁ : ℝ} (hr : 0 < r) (hb₀ : 0 < b₀) (hb₁ : 0 < b₁) + (s : State) (N : ℕ) : + ∀ᵐ h ∂finitePathMeasure s N, ∀ a k : ℕ, ∀ hk : a+2*k+1 ≤ N, + h ∈ pairHitTest a k N hk (Real.log (r/b₁)) (Real.log (b₁/(10*b₀))) → + let z := h ⟨a+2*k+1,Finset.mem_Iic.mpr hk⟩ + stateSide z.1 = .even ∧ 209/100 ≤ stateRatio z.1 ∧ stateRatio z.1 ≤ 213/100 ∧ + 10*b₀/(313/100) ≤ currentExponent (Real.log r) z ∧ + currentExponent (Real.log r) z ≤ b₁/(309/100) ∧ 6*b₀ < gapValue (Real.log r) z := by + have hall : ∀ᵐ h ∂finitePathMeasure s N, ∀ j : Fin N, + (h ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩).2 = + (h ⟨j.1,Finset.mem_Iic.mpr j.isLt.le⟩).2 + + cost (stateRatio (h ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩).1) := by + apply ae_all_iff.mpr + intro j + exact raw_cost_coordinate (Nat.zero_le _) j.isLt (fun _ => (s,0)) + filter_upwards [hall] with h hh + intro a k hk hHit + exact pair_hit_slack hr hb₀ hb₁ a k N hk h + (hh ⟨a+2*k,by omega⟩) hHit + +end NumberTheoryLean.CanonicalMarkSlack + +end + +section + +namespace NumberTheoryLean.CompletedMarkEvents + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures FiniteHistoryTransport CemeteryKernel +open ArrivalKernelGeometry RegeneratingInverseBands ActualCouplingUpdates + +def strongMark (v b₀ b₁ : ℝ) (z : CostState) : Prop := + stateSide z.1 = .even ∧ 209/100 ≤ stateRatio z.1 ∧ stateRatio z.1 ≤ 213/100 ∧ + 10*b₀/(313/100) ≤ currentExponent v z ∧ currentExponent v z ≤ b₁/(309/100) + +theorem strongMark_measurable (v b₀ b₁ : ℝ) : MeasurableSet {z | strongMark v b₀ b₁ z} := + (measurable_fst (side_set_measurable .even)).inter + ((measurableSet_le measurable_const (stateRatio_measurable.comp measurable_fst)).inter + ((measurableSet_le (stateRatio_measurable.comp measurable_fst) measurable_const).inter + ((measurableSet_le measurable_const (currentExponent_measurable v)).inter + (measurableSet_le (currentExponent_measurable v) measurable_const)))) + +def markedPoint (v b₀ b₁ : ℝ) : Space CostState → Prop := + Sum.elim (strongMark v b₀ b₁) (fun _ => False) + +def compactPoint (v R : ℝ) : Space CostState → Prop := + Sum.elim (fun z => gapValue v z ≤ R) (fun _ => False) + +theorem markedPoint_measurable (v b₀ b₁ : ℝ) : MeasurableSet {z | markedPoint v b₀ b₁ z} := + measurableSet_sum_iff.mpr ⟨strongMark_measurable _ _ _,MeasurableSet.empty⟩ + +theorem compactPoint_measurable (v R : ℝ) : MeasurableSet {z | compactPoint v R z} := + measurableSet_sum_iff.mpr ⟨measurableSet_le (gapValue_measurable v) measurable_const,MeasurableSet.empty⟩ + +def noStrongBefore (v b₀ b₁ : ℝ) (N k : ℕ) (h : Hist (Space CostState) N) : Prop := + ∀ i : Finset.Iic N,i.1 ≤ k → ¬markedPoint v b₀ b₁ (h i) + +theorem noStrongBefore_measurable (v b₀ b₁ : ℝ) (N k : ℕ) : + MeasurableSet {h | noStrongBefore v b₀ b₁ N k h} := by + simp only [noStrongBefore,Set.ofPred_forall] + apply MeasurableSet.iInter + intro i + apply MeasurableSet.iInter + intro _hi + exact ((measurable_pi_apply i) (markedPoint_measurable v b₀ b₁)).compl + +def badCompactPath (v R b₀ b₁ : ℝ) (N : ℕ) : Set (Hist (Space CostState) N) := + {h | ∃ j : Finset.Iic N,compactPoint v R (h j) ∧ noStrongBefore v b₀ b₁ N j.1 h} + +theorem badCompactPath_measurable (v R b₀ b₁ : ℝ) (N : ℕ) : + MeasurableSet (badCompactPath v R b₀ b₁ N) := by + simp only [badCompactPath,Set.ofPred_exists] + apply MeasurableSet.iUnion + intro j + exact ((measurable_pi_apply j) (compactPoint_measurable v R)).inter + (noStrongBefore_measurable v b₀ b₁ N j.1) + +end NumberTheoryLean.CompletedMarkEvents + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/CouplingEvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/CouplingEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..fd4cb2d8b37ee3e8de32f039a2f68b0e6c1bf925 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/CouplingEvent.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.IntegerLaw + +namespace OAI + +namespace Erdos970 + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +noncomputable def lowerInteger (E : Finset ℕ) (s : Outcomes E) : ℕ := + integerProduct E (fun p => lowerExponent (s p)) +noncomputable def upperInteger (E : Finset ℕ) (s : Outcomes E) : ℕ := + integerProduct E (fun p => upperExponent (s p)) + +variable (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) +include hE + +lemma log_integerProduct (k : E → ℕ) : + Real.log (integerProduct E k : ℝ) = ∑ p : E, (k p : ℝ) * Real.log (p : ℝ) := by + rw [integerProduct, Nat.cast_prod] + rw [Real.log_prod] + · simp only [Nat.cast_pow, Real.log_pow] + · intro p _; exact_mod_cast pow_ne_zero (k p) (hE p p.property).ne_zero + +theorem upper_log_eq_lower_add_excess (s : Outcomes E) : + Real.log (upperInteger E s : ℝ) = Real.log (lowerInteger E s : ℝ) + excessLog E s := by + rw [upperInteger, lowerInteger, log_integerProduct E hE, log_integerProduct E hE] + unfold excessLog + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _ + rw [Nat.cast_sub (lowerExponent_le_upperExponent (s p))] + ring + +theorem source_cutoff_implication {P : ℝ} (hP : 1 < P) (s : Outcomes E) + (hl : (lowerInteger E s : ℝ) ≤ P ^ (94 / 100 : ℝ)) + (hz : excessLog E s ≤ (1 / 100 : ℝ) * Real.log P) : + (upperInteger E s : ℝ) ≤ P ^ (95 / 100 : ℝ) := by + have hu : 0 < (upperInteger E s : ℝ) := by + exact_mod_cast integerProduct_pos E hE (fun p => upperExponent (s p)) + have hl0 : 0 < (lowerInteger E s : ℝ) := by + exact_mod_cast integerProduct_pos E hE (fun p => lowerExponent (s p)) + apply (Real.log_le_log_iff hu (Real.rpow_pos_of_pos (by linarith) _)).mp + rw [upper_log_eq_lower_add_excess E hE] + have hh := Real.log_le_log hl0 hl + rw [Real.log_rpow (by linarith : 0 < P)] at hh ⊢ + linarith + +theorem small_product_coupling_lower {P : ℝ} (hP : 1 < P) : + eventMass E (fun s => (lowerInteger E s : ℝ) ≤ P ^ (94 / 100 : ℝ)) - + 100 * uniformMomentBound / Real.log P ≤ + eventMass E (fun s => (upperInteger E s : ℝ) ≤ P ^ (95 / 100 : ℝ)) := by + have htwo : ∀ p ∈ E, 2 ≤ p := fun p hp => (hE p hp).two_le + let L : Outcomes E → Prop := fun s => (lowerInteger E s : ℝ) ≤ P ^ (94 / 100 : ℝ) + let U : Outcomes E → Prop := fun s => (upperInteger E s : ℝ) ≤ P ^ (95 / 100 : ℝ) + let B : Outcomes E → Prop := fun s => (1 / 100 : ℝ) * Real.log P < excessLog E s + have hi : eventMass E L ≤ eventMass E U + eventMass E B := by + rw [eventMass, eventMass, eventMass, ← Summable.tsum_add + (product_event_summable E htwo U) (product_event_summable E htwo B)] + apply Summable.tsum_le_tsum _ (product_event_summable E htwo L) + ((product_event_summable E htwo U).add (product_event_summable E htwo B)) + intro s + have hw := productMass_nonneg E htwo s + by_cases hl : L s + · by_cases hz : B s + · simp only [ite_eq_left hl, ite_eq_left hz]; split_ifs <;> linarith + · have hu : U s := source_cutoff_implication E hE hP s hl (le_of_not_gt hz) + simp only [ite_eq_left hl, ite_eq_left hu, ite_eq_right hz, add_zero, le_refl] + · simp only [ite_eq_right hl]; split_ifs <;> linarith + have ht := excess_tail_le E htwo (show 0 < (1 / 100 : ℝ) * Real.log P by + exact mul_pos (by norm_num) (Real.log_pos hP)) + have he : uniformMomentBound / ((1 / 100 : ℝ) * Real.log P) = + 100 * uniformMomentBound / Real.log P := by ring + rw [he] at ht + change eventMass E L - _ ≤ eventMass E U + change eventMass E B ≤ _ at ht + linarith + +end EulerWeightedLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/CouplingLabelEvents.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/CouplingLabelEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a7bbfd0d89df88fbbc0adfab7ccab0be3b0257e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/CouplingLabelEvents.lean @@ -0,0 +1,210 @@ +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 diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/EvenThresholdEvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/EvenThresholdEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..80e46243eb1287af721584081b243ca3f4a81301 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/EvenThresholdEvent.lean @@ -0,0 +1,139 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.EvenThresholdVolume + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosEvenThreshold +open Set MeasureTheory NumberTheoryLean +open FinitePathGeometry DerivativeWeights TransitionKernels FinitePathMeasures KernelDensityBridge + +noncomputable def stripDensityBound : ℝ := (5/4:ℝ)*phiEven 2/phiOdd 5 +noncomputable def stripConstant : ℝ := 20*stripDensityBound + +theorem stripDensityBound_pos : 0 < stripDensityBound := by + have he := phiEven_pos (by norm_num : (1:ℝ)<2) + have ho := phiOdd_pos 5 + unfold stripDensityBound + positivity + +theorem stripConstant_pos : 0 < stripConstant := by + unfold stripConstant + exact mul_pos (by norm_num) stripDensityBound_pos + +theorem oddDensity_compact_bound (s : OddState) {t : ℝ} (ht2 : 2 ≤ t) (ht4 : t ≤ 4) : + oddDensity s t ≤ stripDensityBound := by + change (if max 2 (s.1-1) ≤ t then W t*phiEven t/phiOdd s.1 else 0) ≤ _ + by_cases hsupp : max 2 (s.1-1) ≤ t + · rw [ite_eq_left hsupp] + have hs5 : s.1 ≤ 5 := by linarith [le_max_right (2:ℝ) (s.1-1)] + have ht0 : 0 < t := by linarith + have hW : W t ≤ (5:ℝ)/4 := by + unfold W + apply (div_le_div_iff₀ (sq_pos_of_pos ht0) (by norm_num : (0:ℝ)<4)).mpr + nlinarith + have hphi : phiEven t ≤ phiEven 2 := + phiEven_strictAntiOn.antitoneOn (by norm_num) (by change 1 < t; linarith : t ∈ Ioi (1:ℝ)) ht2 + have hden : phiOdd 5 ≤ phiOdd s.1 := phiOdd_antitone hs5 + have hepos : 0 < phiEven 2 := phiEven_pos (by norm_num) + have htpos : 0 < phiEven t := phiEven_pos (by linarith) + have hnum := mul_le_mul hW hphi htpos.le (by norm_num : (0:ℝ)≤5/4) + calc + _ ≤ ((5:ℝ)/4*phiEven 2)/phiOdd s.1 := div_le_div_of_nonneg_right hnum (phiOdd_pos _).le + _ ≤ ((5:ℝ)/4*phiEven 2)/phiOdd 5 := + div_le_div_of_nonneg_left (by positivity) (phiOdd_pos 5) hden + _ = _ := rfl + · rw [ite_eq_right hsupp] + exact stripDensityBound_pos.le + +theorem oddKernel_strip_bound (s : OddState) {R d : ℝ} + (hR : 0 < R) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) : + oddKernel s (thresholdStrip R d) ≤ ENNReal.ofReal (stripConstant*d/R) := by + rw [oddKernel_apply] + calc + _ ≤ ∫⁻ _t in thresholdStrip R d,ENNReal.ofReal stripDensityBound := by + apply setLIntegral_mono measurable_const + intro t ht + have h4 := (strip_parameters hd1 ht).2 + exact ENNReal.ofReal_le_ofReal (oddDensity_compact_bound s ht.1 h4) + _ = ENNReal.ofReal stripDensityBound*volume (thresholdStrip R d) := by simp + _ ≤ ENNReal.ofReal stripDensityBound*ENNReal.ofReal (20*d/R) := + mul_le_mul_right (thresholdStrip_volume hR hd0 hd1) _ + _ = ENNReal.ofReal (stripConstant*d/R) := by + rw [← ENNReal.ofReal_mul stripDensityBound_pos.le] + congr 1 + unfold stripConstant + ring + +theorem oddToEven_strip_bound (s : OddState) {R d : ℝ} + (hR : 0 < R) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) : + oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' thresholdStrip R d) ≤ + ENNReal.ofReal (stripConstant*d/R) := by + have hh := oddKernel_strip_bound s hR hd0 hd1 + rw [← oddToEven_map_ratio s,Measure.map_apply measurable_subtype_coe (thresholdStrip_measurable R d)] at hh + exact hh + +theorem exists_uniform_strip_bound : ∃ C : ℝ,0 < C ∧ ∀ R d : ℝ,0 < R → 0 ≤ d → d ≤ 1 → + ∀ s : OddState,oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' thresholdStrip R d) ≤ + ENNReal.ofReal (C*d/R) := + ⟨stripConstant,stripConstant_pos,fun _ _ hR hd0 hd1 s => oddToEven_strip_bound s hR hd0 hd1⟩ + +end ErdosEvenThreshold + +end + +section + +namespace ErdosEvenThreshold +open Set MeasureTheory NumberTheoryLean +open FinitePathGeometry TransitionKernels FinitePathMeasures + +noncomputable def nearThreshold (R d : ℝ) : Set ℝ := + {t | 1 < nextExponent R t ∧ 0 ≤ thresholdSlack R t ∧ thresholdSlack R t ≤ d} + +theorem thresholdStrip_eq_near (R d : ℝ) : thresholdStrip R d=nearThreshold R d := by + ext t + constructor + · intro ht + exact ht.2 + · rintro ⟨hx,hlo,hhi⟩ + have hm := gap_eq_exponent_mul R t + have hlow := le_max_left (2*nextExponent R t) (nextExponent R t+2) + have ht2 : 2 ≤ t := by + have hh : nextExponent R t*2 ≤ nextExponent R t*t := by + unfold thresholdSlack at hlo + nlinarith + exact le_of_mul_le_mul_left hh (by linarith : 0 < nextExponent R t) + exact ⟨ht2,hx,hlo,hhi⟩ + +theorem nearThreshold_measurable (R d : ℝ) : MeasurableSet (nearThreshold R d) := by + rw [← thresholdStrip_eq_near] + exact thresholdStrip_measurable R d + +theorem conditional_even_near_threshold (s : OddState) {R d : ℝ} + (hR : 0 < R) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) : + oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' nearThreshold R d) ≤ + ENNReal.ofReal (stripConstant*d/R) := by + rw [← thresholdStrip_eq_near] + exact oddToEven_strip_bound s hR hd0 hd1 + +theorem conditional_even_near_threshold_real (s : OddState) {R d : ℝ} + (hR : 0 < R) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) : + (oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' nearThreshold R d)).toReal ≤ stripConstant*d/R := by + have hh := ENNReal.toReal_mono ENNReal.ofReal_ne_top (conditional_even_near_threshold s hR hd0 hd1) + have hnon : 0 ≤ stripConstant*d/R := div_nonneg (mul_nonneg stripConstant_pos.le hd0) hR.le + simpa only [ENNReal.toReal_ofReal hnon] using hh + +theorem exists_conditional_even_bound : ∃ C : ℝ,0 < C ∧ ∀ R d : ℝ,0 < R → 0 ≤ d → d ≤ 1 → + ∀ s : OddState,(oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' nearThreshold R d)).toReal ≤ C*d/R := + ⟨stripConstant,stripConstant_pos,fun _ _ hR hd0 hd1 s => conditional_even_near_threshold_real s hR hd0 hd1⟩ + +end ErdosEvenThreshold + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/FallingFactorialProbability.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/FallingFactorialProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..171ff003abbb50951d4ca3cc8a9dbda41dfc4643 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/FallingFactorialProbability.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FiniteSampleSpace + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseSampling +attribute [local instance] Classical.decEq + +theorem sample_length_le (n h : ℕ) (beta : ℝ) (hb : 0 < beta) (hb1 : beta ≤ 1) + (hsize : 4*(h : ℝ)/beta ≤ (n : ℝ)) : h ≤ n := by + have hh := (div_le_iff₀ hb).mp hsize + have hbmul := mul_le_mul_of_nonneg_right hb1 (Nat.cast_nonneg n : (0 : ℝ) ≤ n) + have hr : (h : ℝ) ≤ n := by nlinarith [show (0 : ℝ) ≤ h from Nat.cast_nonneg h] + exact_mod_cast hr + +theorem falling_ratio_lower (n m h : ℕ) (beta : ℝ) (hb : 0 < beta) (hb1 : beta ≤ 1) + (hgood : (beta/2)*(n : ℝ) ≤ (m : ℝ)) + (hsize : 4*(h : ℝ)/beta ≤ (n : ℝ)) : + (beta/4)^h ≤ (m.descFactorial h : ℝ)/(n.descFactorial h : ℝ) := by + have hhn := sample_length_le n h beta hb hb1 hsize + have hpay := (div_le_iff₀ hb).mp hsize + have hhm : h ≤ m := by + have hh : (h : ℝ) ≤ m := by nlinarith [show (0 : ℝ) ≤ h from Nat.cast_nonneg h] + exact_mod_cast hh + have hnum : ((beta/4)*(n : ℝ))^h ≤ (m.descFactorial h : ℝ) := by + rw [Nat.descFactorial_eq_prod_range,Nat.cast_prod] + calc + _ = ∏ _i ∈ Finset.range h,(beta/4)*(n : ℝ) := by simp + _ ≤ ∏ i ∈ Finset.range h,((m-i : ℕ) : ℝ) := by + apply Finset.prod_le_prod₀ (fun _ _ => by positivity) + intro i hi + have hih : i < h := Finset.mem_range.mp hi + have him : i ≤ m := by omega + rw [Nat.cast_sub him] + have hiR : (i : ℝ) ≤ h := by exact_mod_cast hih.le + nlinarith + have hden : (n.descFactorial h : ℝ) ≤ (n : ℝ)^h := by + exact_mod_cast Nat.descFactorial_le_pow n h + have hdenpos : (0 : ℝ) < n.descFactorial h := by exact_mod_cast Nat.descFactorial_pos.mpr hhn + apply (le_div_iff₀ hdenpos).mpr + calc + _ ≤ (beta/4)^h*(n : ℝ)^h := mul_le_mul_of_nonneg_left hden (by positivity) + _ = ((beta/4)*(n : ℝ))^h := by rw [mul_pow] + _ ≤ _ := hnum + +theorem sampleFrequency_lower {α : Type*} (U W : Finset α) (hWU : W ⊆ U) (h : ℕ) + (beta : ℝ) (hb : 0 < beta) (hb1 : beta ≤ 1) + (hgood : (beta/2)*(U.card : ℝ) ≤ (W.card : ℝ)) + (hsize : 4*(h : ℝ)/beta ≤ (U.card : ℝ)) : + (beta/4)^h ≤ sampleFrequency U W h := by + rw [sampleFrequency_eq U W hWU h] + exact falling_ratio_lower U.card W.card h beta hb hb1 hgood hsize + +theorem sample_nonempty_of_length {α : Type*} (U : Finset α) (h : ℕ) (hh : h ≤ U.card) : + Nonempty (Sample U h) := by + apply Fintype.card_pos_iff.mp + rw [sample_card] + exact Nat.descFactorial_pos.mpr hh + +end ErdosInverseSampling + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/FiniteHistoryPairLaw.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/FiniteHistoryPairLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c557a410d07f3018ef326bb510e40ae5047a4e7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/FiniteHistoryPairLaw.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FiniteHistorySupport + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.FiniteHistoryPairLaw +open Set MeasureTheory ProbabilityTheory Preorder +open scoped ENNReal +open FiniteHistoryTransport FiniteHistoryOccurrence +variable {X : Type*} [MeasurableSpace X] + +def adjacentPair (N : ℕ) (h : Hist X N) (j : Fin N) : X×X := + (atIndex N h j.castSucc,atIndex N h j.succ) + +theorem adjacentPair_measurable (N : ℕ) (j : Fin N) : Measurable (fun h : Hist X N => adjacentPair N h j) := + (measurable_pi_apply _).prodMk (measurable_pi_apply _) + +theorem lintegral_adjacent_pair (K : Kernel X X) [IsMarkovKernel K] + (N : ℕ) (h₀ : Hist X 0) (j : Fin N) {F : X×X → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ h,F (adjacentPair N h j) ∂pathKernel K N h₀)= + ∫⁻ x,∫⁻ y,F (x,y) ∂K x ∂(K^j.1) (last 0 h₀) := by + have hk : j.1+1 ≤ N := by have := j.isLt; omega + let G : Hist X (j.1+1) → ℝ≥0∞ := + fun h => F (h ⟨j.1,Finset.mem_Iic.mpr (by omega)⟩,last (j.1+1) h) + have hG : Measurable G := hF.comp ((measurable_pi_apply _).prodMk (last_measurable _)) + have hprefix : (pathKernel K N h₀).map (frestrictLe₂ (π := fun _ => X) hk)=pathKernel K (j.1+1) h₀ := + Kernel.partialTraj_map_frestrictLe₂_apply (X := fun _ => X) (κ := pastKernel K) h₀ hk + change (∫⁻ h,G (frestrictLe₂ (π := fun _ => X) hk h) ∂pathKernel K N h₀)=_ + rw [← lintegral_map hG (measurable_frestrictLe₂ hk),hprefix,lintegral_pathKernel_succ K j.1 h₀ hG] + calc + _ = ∫⁻ h,∫⁻ y,F (last j.1 h,y) ∂K (last j.1 h) ∂pathKernel K j.1 h₀ := by + apply lintegral_congr + intro h + apply lintegral_congr + intro y + change F ((extend j.1 h y) ⟨j.1,Finset.mem_Iic.mpr (by omega)⟩, + last (j.1+1) (extend j.1 h y))=F (last j.1 h,y) + rw [extend_last,extend_previous j.1 h y ⟨j.1,by simp⟩] + rfl + _ = _ := by + have hcur : Measurable (Function.uncurry (fun x : X => fun y : X => F (x,y))) := hF + exact lintegral_endpoint K j.1 h₀ (hcur.lintegral_kernel_prod_right (κ := K)) + +noncomputable def pairProbability (K : Kernel X X) (E : Set (X×X)) (x : X) : ℝ≥0∞ := + K x ((Prod.mk x) ⁻¹' E) + +theorem pairProbability_integral (K : Kernel X X) {E : Set (X×X)} (hE : MeasurableSet E) (x : X) : + (∫⁻ y,E.indicator (fun _ => (1:ℝ≥0∞)) (x,y) ∂K x)=pairProbability K E x := by + change (∫⁻ y,((Prod.mk x) ⁻¹' E).indicator 1 y ∂K x)=_ + exact lintegral_indicator_one (measurable_prodMk_left hE) + +theorem pairProbability_measurable (K : Kernel X X) [IsSFiniteKernel K] + {E : Set (X×X)} (hE : MeasurableSet E) : Measurable (pairProbability K E) := by + have hF : Measurable (E.indicator (fun _ => (1:ℝ≥0∞))) := measurable_const.indicator hE + have hcur : Measurable (Function.uncurry (fun x : X => fun y : X => E.indicator (fun _ => (1:ℝ≥0∞)) (x,y))) := hF + have hh := hcur.lintegral_kernel_prod_right (κ := K) + simpa only [pairProbability_integral K hE] using hh + +theorem adjacent_pair_probability (K : Kernel X X) [IsMarkovKernel K] + {E : Set (X×X)} (hE : MeasurableSet E) (N : ℕ) (h₀ : Hist X 0) (j : Fin N) : + pathKernel K N h₀ ((fun h => adjacentPair N h j) ⁻¹' E)= + ∫⁻ h,pairProbability K E (atIndex N h j.castSucc) ∂pathKernel K N h₀ := by + have hF : Measurable (E.indicator (fun _ => (1:ℝ≥0∞))) := measurable_const.indicator hE + have hc : Measurable (fun h : Hist X N => atIndex N h j.castSucc) := measurable_pi_apply _ + have hp := atIndex_law K N h₀ j.castSucc + simp only [Fin.val_castSucc] at hp + calc + _ = ∫⁻ h,E.indicator (fun _ => (1:ℝ≥0∞)) (adjacentPair N h j) ∂pathKernel K N h₀ := + (lintegral_indicator_one ((adjacentPair_measurable N j) hE)).symm + _ = ∫⁻ x,∫⁻ y,E.indicator (fun _ => (1:ℝ≥0∞)) (x,y) ∂K x ∂(K^j.1) (last 0 h₀) := + lintegral_adjacent_pair K N h₀ j hF + _ = ∫⁻ x,pairProbability K E x ∂(K^j.1) (last 0 h₀) := by simp_rw [pairProbability_integral K hE] + _ = _ := by rw [← hp,lintegral_map (pairProbability_measurable K hE) hc] +end NumberTheoryLean.FiniteHistoryPairLaw + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/FiniteKernelResolvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/FiniteKernelResolvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef09d156c6af7512371cbbb753ba921e258e95f6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/FiniteKernelResolvent.lean @@ -0,0 +1,80 @@ +import Mathlib.MeasureTheory.Integral.Lebesgue.DominatedConvergence +import Mathlib.Probability.Kernel.Composition.MeasureComp +import Mathlib.Tactic +import Mathlib.Topology.Algebra.InfiniteSum.ENNReal + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped ENNReal ProbabilityTheory Topology BigOperators +namespace Erdos970Dependency.FiniteKernelResolvent +variable {X : Type*} [MeasurableSpace X] + +theorem fixed_point_finite (Q : Kernel X X) (mu alpha : Measure X) + (hfix : mu = alpha + Q ∘ₘ mu) (N : ℕ) : + mu = (∑ j ∈ Finset.range N, (Q ^ j) ∘ₘ alpha) + (Q ^ N) ∘ₘ mu := by + induction N with + | zero => + simp only [Finset.range_zero, Finset.sum_empty, pow_zero, zero_add] + change mu = Kernel.id ∘ₘ mu + exact Measure.id_comp.symm + | succ N ih => + have hlast : (Q ^ N) ∘ₘ mu = (Q ^ N) ∘ₘ alpha + (Q ^ (N + 1)) ∘ₘ mu := by + calc + (Q ^ N) ∘ₘ mu = (Q ^ N) ∘ₘ (alpha + Q ∘ₘ mu) := congrArg (fun nu ↦ (Q ^ N) ∘ₘ nu) hfix + _ = (Q ^ N) ∘ₘ alpha + ((Q ^ N) ∘ₖ Q) ∘ₘ mu := by rw [Measure.comp_add, Measure.comp_assoc] + _ = _ := by rw [pow_succ]; rfl + rw [Finset.sum_range_succ, add_assoc, ← hlast] + exact ih + +theorem residual_mass_tendsto_zero (Q : Kernel X X) (mu : Measure X) [IsFiniteMeasure mu] + (hsub : ∀ n s, (Q ^ n) s univ ≤ 1) + (htail : ∀ s, Tendsto (fun n : ℕ ↦ (Q ^ n) s univ) atTop (𝓝 0)) : + Tendsto (fun n : ℕ ↦ ((Q ^ n) ∘ₘ mu) univ) atTop (𝓝 0) := by + have h := tendsto_lintegral_of_dominated_convergence (μ := mu) + (F := fun n s ↦ (Q ^ n) s univ) (f := fun _ ↦ 0) (fun _ ↦ 1) + (fun n ↦ (Q ^ n).measurable_coe MeasurableSet.univ) + (fun n ↦ Eventually.of_forall (hsub n)) + (by simp) (Eventually.of_forall htail) + have heq (n : ℕ) : ((Q ^ n) ∘ₘ mu) univ = ∫⁻ s, (Q ^ n) s univ ∂mu := + Measure.bind_apply MeasurableSet.univ (Q ^ n).aemeasurable + simp_rw [heq] + simpa only [lintegral_zero] using h + +theorem residual_set_tendsto_zero (Q : Kernel X X) (mu : Measure X) [IsFiniteMeasure mu] + (hsub : ∀ n s, (Q ^ n) s univ ≤ 1) + (htail : ∀ s, Tendsto (fun n : ℕ ↦ (Q ^ n) s univ) atTop (𝓝 0)) (B : Set X) : + Tendsto (fun n : ℕ ↦ ((Q ^ n) ∘ₘ mu) B) atTop (𝓝 0) := by + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds + (residual_mass_tendsto_zero Q mu hsub htail) (Eventually.of_forall (fun _ ↦ zero_le)) + (Eventually.of_forall (fun _ ↦ measure_mono (subset_univ B))) + +theorem fixed_point_resolvent (Q : Kernel X X) (mu alpha : Measure X) [IsFiniteMeasure mu] + (hfix : mu = alpha + Q ∘ₘ mu) (hsub : ∀ n s, (Q ^ n) s univ ≤ 1) + (htail : ∀ s, Tendsto (fun n : ℕ ↦ (Q ^ n) s univ) atTop (𝓝 0)) : + mu = Measure.sum (fun n : ℕ ↦ (Q ^ n) ∘ₘ alpha) := by + ext B hB + rw [Measure.sum_apply _ hB] + have hfinite (N : ℕ) : mu B = + (∑ j ∈ Finset.range N, ((Q ^ j) ∘ₘ alpha) B) + ((Q ^ N) ∘ₘ mu) B := by + have h := congrArg (fun nu : Measure X ↦ nu B) (fixed_point_finite Q mu alpha hfix N) + simpa only [Measure.add_apply, Measure.finsetSum_apply] using h + have hlim := (ENNReal.tendsto_nat_tsum (fun n : ℕ ↦ ((Q ^ n) ∘ₘ alpha) B)).add + (residual_set_tendsto_zero Q mu hsub htail B) + simp only [add_zero] at hlim + have hlim' : Tendsto (fun _ : ℕ ↦ mu B) atTop + (𝓝 (∑' n : ℕ, ((Q ^ n) ∘ₘ alpha) B)) := + hlim.congr' (Eventually.of_forall (fun N ↦ (hfinite N).symm)) + exact tendsto_nhds_unique tendsto_const_nhds hlim' + +end Erdos970Dependency.FiniteKernelResolvent + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/FirstHitKernels.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/FirstHitKernels.lean new file mode 100644 index 0000000000000000000000000000000000000000..d15476a1ec46522ba52f617a1bd874a62137070b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/FirstHitKernels.lean @@ -0,0 +1,586 @@ +import Mathlib.Probability.Kernel.Composition.CompProd +import OAI.NumberTheory.Jacobsthal.Analysis.WeightIntegrals +import OAI.NumberTheory.Jacobsthal.Sieve.CompactExponentialMoments + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.KernelDensityBridge + +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open DerivativeWeights TransitionKernels FinitePathGeometry FinitePathMeasures + +theorem evenToOdd_map_ratio (s : EvenState) : + (evenToOdd s).map (Subtype.val : OddState → ℝ) = evenKernel s := by + calc + _ = (evenKernel s).restrict (Ici (95 / 100 : ℝ)) := by + change ((evenKernel s).comap (Subtype.val : OddState → ℝ)).map Subtype.val = _ + exact map_comap_subtype_coe (μ := evenKernel s) (s := Ici (95 / 100 : ℝ)) measurableSet_Ici + _ = _ := Measure.restrict_eq_self_of_ae_mem (evenKernel_ae_odd_domain s) + +theorem oddToEven_map_ratio (s : OddState) : + (oddToEven s).map (Subtype.val : EvenState → ℝ) = oddKernel s := by + calc + _ = (oddKernel s).restrict (Ici (198 / 100 : ℝ)) := by + change ((oddKernel s).comap (Subtype.val : EvenState → ℝ)).map Subtype.val = _ + exact map_comap_subtype_coe (μ := oddKernel s) (s := Ici (198 / 100 : ℝ)) measurableSet_Ici + _ = _ := Measure.restrict_eq_self_of_ae_mem (oddKernel_ae_even_domain s) + +theorem stateKernel_even_ratio (s : EvenState) : + (stateKernel (.inl s)).map stateRatio = evenKernel s := by + change (evenBranch s).map stateRatio = _ + rw [evenBranch, Kernel.map_apply _ measurable_inr, + Measure.map_map stateRatio_measurable measurable_inr] + exact evenToOdd_map_ratio s + +theorem stateKernel_odd_ratio (s : OddState) : + (stateKernel (.inr s)).map stateRatio = oddKernel s := by + change (oddBranch s).map stateRatio = _ + rw [oddBranch, Kernel.map_apply _ measurable_inl, + Measure.map_map stateRatio_measurable measurable_inl] + exact oddToEven_map_ratio s + +theorem evenToOdd_lintegral_ratio (s : EvenState) {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ t : OddState, H t.1 ∂evenToOdd s) = ∫⁻ t, H t ∂evenKernel s := by + rw [← evenToOdd_map_ratio, lintegral_map hH measurable_subtype_coe] + +theorem oddToEven_lintegral_ratio (s : OddState) {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ t : EvenState, H t.1 ∂oddToEven s) = ∫⁻ t, H t ∂oddKernel s := by + rw [← oddToEven_map_ratio, lintegral_map hH measurable_subtype_coe] + +theorem evenKernel_lintegral_density (s : EvenState) {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ t, H t ∂evenKernel s) = + ∫⁻ t, ENNReal.ofReal (transitionDensity .even s.1 t) * H t := by + exact Kernel.lintegral_withDensity (Kernel.const EvenState volume) + (f := fun s t => ENNReal.ofReal (evenDensity s t)) + (ENNReal.measurable_ofReal.comp evenDensity_measurable) s hH + +theorem oddKernel_lintegral_density (s : OddState) {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ t, H t ∂oddKernel s) = + ∫⁻ t, ENNReal.ofReal (transitionDensity .odd s.1 t) * H t := by + exact Kernel.lintegral_withDensity (Kernel.const OddState volume) + (f := fun s t => ENNReal.ofReal (oddDensity s t)) + (ENNReal.measurable_ofReal.comp oddDensity_measurable) s hH + +theorem transitionDensity_joint_measurable (i : Side) : + Measurable (Function.uncurry (transitionDensity i)) := by + cases i with + | even => + change Measurable (fun x : ℝ × ℝ => + if x.1 - 1 ≤ x.2 then W x.2 * phiOdd x.2 / phiEven x.1 else 0) + apply Measurable.ite (measurableSet_le (measurable_fst.sub measurable_const) measurable_snd) + · exact ((W_measurable.comp measurable_snd).mul + (phiOdd_continuous.measurable.comp measurable_snd)).div (phiEven_measurable.comp measurable_fst) + · exact measurable_const + | odd => + change Measurable (fun x : ℝ × ℝ => + if max 2 (x.1 - 1) ≤ x.2 then W x.2 * phiEven x.2 / phiOdd x.1 else 0) + apply Measurable.ite (measurableSet_le + (measurable_const.max (measurable_fst.sub measurable_const)) measurable_snd) + · exact ((W_measurable.comp measurable_snd).mul + (phiEven_measurable.comp measurable_snd)).div (phiOdd_continuous.measurable.comp measurable_fst) + · exact measurable_const + +noncomputable def evenTwoStep : Kernel EvenState (ℝ × ℝ) := + (evenToOdd ⊗ₖ oddToEven.prodMkLeft EvenState).map (fun x : OddState × EvenState => (x.1.1, x.2.1)) + +noncomputable def oddTwoStep : Kernel OddState (ℝ × ℝ) := + (oddToEven ⊗ₖ evenToOdd.prodMkLeft OddState).map (fun x : EvenState × OddState => (x.1.1, x.2.1)) + +instance evenTwoStep_isMarkovKernel : IsMarkovKernel evenTwoStep := + Kernel.IsMarkovKernel.map _ ((measurable_subtype_coe.comp measurable_fst).prodMk + (measurable_subtype_coe.comp measurable_snd)) + +instance oddTwoStep_isMarkovKernel : IsMarkovKernel oddTwoStep := + Kernel.IsMarkovKernel.map _ ((measurable_subtype_coe.comp measurable_fst).prodMk + (measurable_subtype_coe.comp measurable_snd)) + +theorem evenTwoStep_lintegral (s : EvenState) {H : ℝ × ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ x, H x ∂evenTwoStep s) = ∫⁻ t, ∫⁻ u, + ENNReal.ofReal (transitionDensity .even s.1 t) * + ENNReal.ofReal (transitionDensity .odd t u) * H (t, u) := by + have hm : Measurable (fun x : OddState × EvenState => (x.1.1, x.2.1)) := + (measurable_subtype_coe.comp measurable_fst).prodMk (measurable_subtype_coe.comp measurable_snd) + rw [evenTwoStep, Kernel.lintegral_map _ hm _ hH] + rw [Kernel.lintegral_compProd evenToOdd (oddToEven.prodMkLeft EvenState) s + (f := fun x : OddState × EvenState => H (x.1.1, x.2.1)) (hH.comp hm)] + change (∫⁻ t : OddState, ∫⁻ u : EvenState, H (t.1, u.1) ∂oddToEven t ∂evenToOdd s) = _ + have hinner : ∀ t : OddState, (∫⁻ u : EvenState, H (t.1, u.1) ∂oddToEven t) = + ∫⁻ u, ENNReal.ofReal (transitionDensity .odd t.1 u) * H (t.1, u) := by + intro t + rw [oddToEven_lintegral_ratio t (H := fun u : ℝ => H (t.1, u)) (hH.comp measurable_prodMk_left), + oddKernel_lintegral_density t (H := fun u : ℝ => H (t.1, u)) (hH.comp measurable_prodMk_left)] + simp_rw [hinner] + have hJ : Measurable (fun t : ℝ => ∫⁻ u, + ENNReal.ofReal (transitionDensity .odd t u) * H (t, u)) := + ((ENNReal.measurable_ofReal.comp (transitionDensity_joint_measurable .odd)).mul hH).lintegral_prod_right + rw [evenToOdd_lintegral_ratio s hJ, evenKernel_lintegral_density s hJ] + apply lintegral_congr + intro t + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro u + ring + +theorem oddTwoStep_lintegral (s : OddState) {H : ℝ × ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ x, H x ∂oddTwoStep s) = ∫⁻ t, ∫⁻ u, + ENNReal.ofReal (transitionDensity .odd s.1 t) * + ENNReal.ofReal (transitionDensity .even t u) * H (t, u) := by + have hm : Measurable (fun x : EvenState × OddState => (x.1.1, x.2.1)) := + (measurable_subtype_coe.comp measurable_fst).prodMk (measurable_subtype_coe.comp measurable_snd) + rw [oddTwoStep, Kernel.lintegral_map _ hm _ hH] + rw [Kernel.lintegral_compProd oddToEven (evenToOdd.prodMkLeft OddState) s + (f := fun x : EvenState × OddState => H (x.1.1, x.2.1)) (hH.comp hm)] + change (∫⁻ t : EvenState, ∫⁻ u : OddState, H (t.1, u.1) ∂evenToOdd t ∂oddToEven s) = _ + have hinner : ∀ t : EvenState, (∫⁻ u : OddState, H (t.1, u.1) ∂evenToOdd t) = + ∫⁻ u, ENNReal.ofReal (transitionDensity .even t.1 u) * H (t.1, u) := by + intro t + rw [evenToOdd_lintegral_ratio t (H := fun u : ℝ => H (t.1, u)) (hH.comp measurable_prodMk_left), + evenKernel_lintegral_density t (H := fun u : ℝ => H (t.1, u)) (hH.comp measurable_prodMk_left)] + simp_rw [hinner] + have hJ : Measurable (fun t : ℝ => ∫⁻ u, + ENNReal.ofReal (transitionDensity .even t u) * H (t, u)) := + ((ENNReal.measurable_ofReal.comp (transitionDensity_joint_measurable .even)).mul hH).lintegral_prod_right + rw [oddToEven_lintegral_ratio s hJ, oddKernel_lintegral_density s hJ] + apply lintegral_congr + intro t + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro u + ring + +noncomputable def jointDensity (i : Side) (s : ℝ) (x : ℝ × ℝ) : ℝ≥0∞ := + ENNReal.ofReal (transitionDensity i s x.1) * ENNReal.ofReal (transitionDensity i.flip x.1 x.2) + +theorem jointDensity_measurable (i : Side) (s : ℝ) : Measurable (jointDensity i s) := by + exact (ENNReal.measurable_ofReal.comp ((transitionDensity_joint_measurable i).comp + (measurable_const.prodMk measurable_fst))).mul + (ENNReal.measurable_ofReal.comp (transitionDensity_joint_measurable i.flip)) + +theorem evenTwoStep_eq_withDensity (s : EvenState) : + evenTwoStep s = ((volume : Measure ℝ).prod volume).withDensity (jointDensity .even s.1) := by + apply Measure.ext_of_lintegral + intro H hH + rw [evenTwoStep_lintegral s hH, + lintegral_withDensity_eq_lintegral_mul _ (jointDensity_measurable .even s.1) hH] + have hp := lintegral_prod (μ := (volume : Measure ℝ)) (ν := (volume : Measure ℝ)) + (fun x => jointDensity .even s.1 x * H x) ((jointDensity_measurable .even s.1).mul hH).aemeasurable + exact hp.symm + +theorem oddTwoStep_eq_withDensity (s : OddState) : + oddTwoStep s = ((volume : Measure ℝ).prod volume).withDensity (jointDensity .odd s.1) := by + apply Measure.ext_of_lintegral + intro H hH + rw [oddTwoStep_lintegral s hH, + lintegral_withDensity_eq_lintegral_mul _ (jointDensity_measurable .odd s.1) hH] + have hp := lintegral_prod (μ := (volume : Measure ℝ)) (ν := (volume : Measure ℝ)) + (fun x => jointDensity .odd s.1 x * H x) ((jointDensity_measurable .odd s.1).mul hH).aemeasurable + exact hp.symm + +end NumberTheoryLean.KernelDensityBridge + +end + +section + +namespace NumberTheoryLean.JointMinorization + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open DerivativeWeights TransitionKernels FinitePathGeometry FinitePathMeasures +open KernelDensityBridge TwoStepDensityBounds + +def rectangle (L : ℝ) : Set (ℝ × ℝ) := Icc L (L + 1) ×ˢ Icc (L + 1) (L + 2) + +theorem rectangle_measurable (L : ℝ) : MeasurableSet (rectangle L) := + measurableSet_Icc.prod measurableSet_Icc + +noncomputable def rectangleLaw (L : ℝ) : Measure (ℝ × ℝ) := + ((volume : Measure ℝ).prod volume).restrict (rectangle L) + +instance rectangleLaw_isProbabilityMeasure (L : ℝ) : IsProbabilityMeasure (rectangleLaw L) := by + constructor + rw [rectangleLaw, Measure.restrict_apply MeasurableSet.univ, univ_inter, + rectangle, Measure.prod_prod, Real.volume_Icc, Real.volume_Icc] + rw [show L + 1 - L = 1 by ring, show L + 2 - (L + 1) = 1 by ring] + norm_num + +theorem transitionDensity_nonneg {i : Side} {s : ℝ} (hs : Valid i s) (t : ℝ) : + 0 ≤ transitionDensity i s t := by + cases i with + | even => exact evenDensity_nonneg ⟨s, hs⟩ t + | odd => exact oddDensity_nonneg ⟨s, hs⟩ t + +theorem rectangle_minorization {i : Side} {s L : ℝ} (hL : 3 ≤ L) + (hs : Valid i s) (hsL : s ≤ L) : + ENNReal.ofReal (minorizationSize L) • rectangleLaw L ≤ + ((volume : Measure ℝ).prod volume).withDensity (jointDensity i s) := by + rw [rectangleLaw, ← withDensity_const, + ← withDensity_indicator (rectangle_measurable L)] + apply withDensity_mono + apply Eventually.of_forall + intro x + by_cases hx : x ∈ rectangle L + · rw [indicator_of_mem hx] + change ENNReal.ofReal (minorizationSize L) ≤ + ENNReal.ofReal (transitionDensity i s x.1) * ENNReal.ofReal (transitionDensity i.flip x.1 x.2) + rw [← ENNReal.ofReal_mul (transitionDensity_nonneg hs x.1)] + exact ENNReal.ofReal_le_ofReal (le_trans (minorizationSize_le_rectangle i L) + (rectangle_density_lower hL hs hsL hx.1 hx.2)) + · rw [indicator_of_notMem hx] + exact zero_le + +theorem evenTwoStep_rectangle_minorization {L : ℝ} (hL : 3 ≤ L) + (s : EvenState) (hs : s.1 ≤ L) : + ENNReal.ofReal (minorizationSize L) • rectangleLaw L ≤ evenTwoStep s := by + rw [evenTwoStep_eq_withDensity] + exact rectangle_minorization hL s.2 hs + +theorem oddTwoStep_rectangle_minorization {L : ℝ} (hL : 3 ≤ L) + (s : OddState) (hs : s.1 ≤ L) : + ENNReal.ofReal (minorizationSize L) • rectangleLaw L ≤ oddTwoStep s := by + rw [oddTwoStep_eq_withDensity] + exact rectangle_minorization hL s.2 hs + +noncomputable def pairCost (T : ℝ) (x : ℝ × ℝ) : ℝ × ℝ := + (x.2, T + cost x.1 + cost x.2) + +theorem pairCost_measurable (T : ℝ) : Measurable (pairCost T) := + measurable_snd.prodMk ((measurable_const.add (cost_measurable.comp measurable_fst)).add + (cost_measurable.comp measurable_snd)) + +noncomputable def minorizingLaw (L T : ℝ) : Measure (ℝ × ℝ) := (rectangleLaw L).map (pairCost T) + +instance minorizingLaw_isProbabilityMeasure (L T : ℝ) : IsProbabilityMeasure (minorizingLaw L T) := + (Measure.isProbabilityMeasure_map_iff (μ := rectangleLaw L) + (pairCost_measurable T).aemeasurable).mpr inferInstance + +noncomputable def evenJointKernel (T : ℝ) : Kernel EvenState (ℝ × ℝ) := evenTwoStep.map (pairCost T) +noncomputable def oddJointKernel (T : ℝ) : Kernel OddState (ℝ × ℝ) := oddTwoStep.map (pairCost T) + +instance evenJointKernel_isMarkovKernel (T : ℝ) : IsMarkovKernel (evenJointKernel T) := + Kernel.IsMarkovKernel.map _ (pairCost_measurable T) + +instance oddJointKernel_isMarkovKernel (T : ℝ) : IsMarkovKernel (oddJointKernel T) := + Kernel.IsMarkovKernel.map _ (pairCost_measurable T) + +theorem even_joint_minorization {L : ℝ} (hL : 3 ≤ L) (s : EvenState) (hs : s.1 ≤ L) (T : ℝ) : + ENNReal.ofReal (minorizationSize L) • minorizingLaw L T ≤ evenJointKernel T s := by + rw [evenJointKernel, Kernel.map_apply _ (pairCost_measurable T)] + have h := Measure.map_mono (evenTwoStep_rectangle_minorization hL s hs) (pairCost_measurable T) + rw [Measure.map_smul _ (pairCost_measurable T).aemeasurable] at h + exact h + +theorem odd_joint_minorization {L : ℝ} (hL : 3 ≤ L) (s : OddState) (hs : s.1 ≤ L) (T : ℝ) : + ENNReal.ofReal (minorizationSize L) • minorizingLaw L T ≤ oddJointKernel T s := by + rw [oddJointKernel, Kernel.map_apply _ (pairCost_measurable T)] + have h := Measure.map_mono (oddTwoStep_rectangle_minorization hL s hs) (pairCost_measurable T) + rw [Measure.map_smul _ (pairCost_measurable T).aemeasurable] at h + exact h + +theorem compact_joint_minorization (S : ℝ) : ∃ L ε : ℝ, 3 ≤ L ∧ S ≤ L ∧ 0 < ε ∧ ε ≤ 1 ∧ + (∀ T : ℝ, IsProbabilityMeasure (minorizingLaw L T)) ∧ + (∀ T : ℝ, ∀ s : EvenState, s.1 ≤ S → ENNReal.ofReal ε • minorizingLaw L T ≤ evenJointKernel T s) ∧ + (∀ T : ℝ, ∀ s : OddState, s.1 ≤ S → ENNReal.ofReal ε • minorizingLaw L T ≤ oddJointKernel T s) := by + refine ⟨max 3 S, minorizationSize (max 3 S), le_max_left _ _, le_max_right _ _, + minorizationSize_pos (le_max_left _ _), minorizationSize_le_one _, ?_, ?_, ?_⟩ + · intro T + infer_instance + · intro T s hs + exact even_joint_minorization (le_max_left _ _) s (le_trans hs (le_max_right _ _)) T + · intro T s hs + exact odd_joint_minorization (le_max_left _ _) s (le_trans hs (le_max_right _ _)) T + +end NumberTheoryLean.JointMinorization + +end + +section + +namespace NumberTheoryLean.GoodPairTransitions + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open BuchstabBridge DerivativeWeights WeightFutureIntegrals TransitionKernels +open FinitePathGeometry FinitePathMeasures KernelDensityBridge TwoStepDensityBounds JointMinorization + +def goodPair (s : ℝ) : Set (ℝ × ℝ) := + {x | x.1 ∈ Icc (max 2 (s - 1)) (max 2 (s - 1) + 1 / 4) ∧ + x.2 ∈ Icc (x.1 - 1) (x.1 - 3 / 4)} + +theorem goodPair_measurable (s : ℝ) : MeasurableSet (goodPair s) := by + exact ((measurableSet_le measurable_const measurable_fst).inter + (measurableSet_le measurable_fst measurable_const)).inter + ((measurableSet_le (measurable_fst.sub measurable_const) measurable_snd).inter + (measurableSet_le measurable_snd (measurable_fst.sub measurable_const))) + +theorem goodPair_volume (s : ℝ) : ((volume : Measure ℝ).prod volume) (goodPair s) = ENNReal.ofReal (1 / 16 : ℝ) := by + rw [Measure.prod_apply (goodPair_measurable s)] + have heq : ∀ t : ℝ, volume (Prod.mk t ⁻¹' goodPair s) = + (Icc (max 2 (s - 1)) (max 2 (s - 1) + 1 / 4)).indicator + (fun _ => ENNReal.ofReal (1 / 4 : ℝ)) t := by + intro t + by_cases ht : t ∈ Icc (max 2 (s - 1)) (max 2 (s - 1) + 1 / 4) + · have hp : Prod.mk t ⁻¹' goodPair s = Icc (t - 1) (t - 3 / 4) := by + ext u + simp only [mem_preimage, goodPair, mem_ofPred_eq, ht, true_and] + rw [hp, Real.volume_Icc, indicator_of_mem ht] + congr 1 + ring + · have hp : Prod.mk t ⁻¹' goodPair s = ∅ := by + ext u + simp only [mem_preimage, goodPair, mem_ofPred_eq, ht, false_and, mem_empty_iff_false] + rw [hp, measure_empty, indicator_of_notMem ht] + rw [lintegral_congr heq, lintegral_indicator measurableSet_Icc, setLIntegral_const, Real.volume_Icc] + rw [show max 2 (s - 1) + 1 / 4 - max 2 (s - 1) = (1 : ℝ) / 4 by ring] + rw [← ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≤ 1 / 4)] + congr 1 + norm_num + +theorem goodPair_bounds {s M t u : ℝ} (hM : 4 ≤ M) (hs : s ≤ M) (hg : (t, u) ∈ goodPair s) : + 2 ≤ t ∧ 1 ≤ u ∧ t ≤ M ∧ u ≤ M := by + have ht2 : 2 ≤ t := le_trans (le_max_left _ _) hg.1.1 + have ha : max 2 (s - 1) ≤ M - 1 := max_le (by linarith) (by linarith) + exact ⟨ht2, by linarith [hg.2.1], by linarith [hg.1.2], by linarith [hg.1.2, hg.2.2]⟩ + +theorem goodPair_terminal {s t u : ℝ} (hg : (t, u) ∈ goodPair s) : + u ≤ max (3 / 2) (s - 3 / 2) := by + by_cases hs : s ≤ 3 + · have ha : max 2 (s - 1) = 2 := max_eq_left (by linarith) + have ht := hg.1.2 + rw [ha] at ht + exact le_trans (show u ≤ 3 / 2 by linarith [hg.2.2]) (le_max_left _ _) + · have ha : max 2 (s - 1) = s - 1 := max_eq_right (by linarith) + have ht := hg.1.2 + rw [ha] at ht + exact le_trans (show u ≤ s - 3 / 2 by linarith [hg.2.2]) (le_max_right _ _) + +theorem phiOdd_le_A (s : ℝ) : phiOdd s ≤ sieveA := by + by_cases hs : s ≤ 3 + · exact le_of_eq (phiOdd_initial hs) + · have h := phiOdd_antitone (show 3 ≤ s by linarith) + rwa [phiOdd_initial (s := 3) le_rfl] at h + +noncomputable def goodPairDensityLower (M : ℝ) : ℝ := (1 / M) ^ 2 * (phiOdd M / sieveA) + +theorem goodPairDensityLower_pos {M : ℝ} (hM : 4 ≤ M) : 0 < goodPairDensityLower M := by + unfold goodPairDensityLower + exact mul_pos (sq_pos_of_pos (one_div_pos.mpr (by linarith))) (div_pos (phiOdd_pos M) sieveA_pos) + +theorem goodPair_density_lower {M : ℝ} (hM : 4 ≤ M) (s : OddState) (hs : s.1 ≤ M) + {t u : ℝ} (hg : (t, u) ∈ goodPair s.1) : + goodPairDensityLower M ≤ transitionDensity .odd s.1 t * transitionDensity .even t u := by + obtain ⟨ht2, hu1, htM, huM⟩ := goodPair_bounds hM hs hg + have ht0 : 0 < t := by linarith + have hu0 : 0 < u := by linarith + have heq := two_step_density_eq (i := .odd) s.2 hg.1.1 hg.2.1 + change transitionDensity .odd s.1 t * transitionDensity .even t u = + (W t * W u) * (phiOdd u / phiOdd s.1) at heq + rw [heq] + have hW : (1 / M) ^ 2 ≤ W t * W u := by + simpa only [pow_two] using mul_le_mul (W_lower ht0 htM) (W_lower hu0 huM) + (one_div_nonneg.mpr (by linarith)) (W_pos ht0).le + have hr : phiOdd M / sieveA ≤ phiOdd u / phiOdd s.1 := by + calc + _ ≤ phiOdd M / phiOdd s.1 := div_le_div_of_nonneg_left (phiOdd_pos M).le (phiOdd_pos s.1) (phiOdd_le_A s.1) + _ ≤ _ := div_le_div_of_nonneg_right (phiOdd_antitone huM) (phiOdd_pos s.1).le + exact mul_le_mul hW hr (div_pos (phiOdd_pos M) sieveA_pos).le (mul_pos (W_pos ht0) (W_pos hu0)).le + +theorem goodPair_measure_lower {M : ℝ} (hM : 4 ≤ M) (s : OddState) (hs : s.1 ≤ M) : + ENNReal.ofReal (goodPairDensityLower M / 16) ≤ oddTwoStep s (goodPair s.1) := by + have hdom : ENNReal.ofReal (goodPairDensityLower M) • + ((volume : Measure ℝ).prod volume).restrict (goodPair s.1) ≤ oddTwoStep s := by + rw [oddTwoStep_eq_withDensity, ← withDensity_const, + ← withDensity_indicator (goodPair_measurable s.1)] + apply withDensity_mono + apply Eventually.of_forall + intro x + by_cases hx : x ∈ goodPair s.1 + · rw [indicator_of_mem hx] + change ENNReal.ofReal (goodPairDensityLower M) ≤ + ENNReal.ofReal (transitionDensity .odd s.1 x.1) * ENNReal.ofReal (transitionDensity .even x.1 x.2) + rw [← ENNReal.ofReal_mul (transitionDensity_nonneg (i := .odd) s.2 x.1)] + exact ENNReal.ofReal_le_ofReal (goodPair_density_lower hM s hs hx) + · rw [indicator_of_notMem hx] + exact zero_le + have h := hdom (goodPair s.1) + rw [Measure.smul_apply, Measure.restrict_apply (goodPair_measurable s.1), inter_self, + goodPair_volume, smul_eq_mul, ← ENNReal.ofReal_mul (goodPairDensityLower_pos hM).le] at h + convert! h using 1 + congr 1 + ring + +noncomputable def goodPairProbability (M : ℝ) : ℝ := min (1 / 2) (goodPairDensityLower M / 16) + +theorem goodPairProbability_pos {M : ℝ} (hM : 4 ≤ M) : 0 < goodPairProbability M := + lt_min (by norm_num) (div_pos (goodPairDensityLower_pos hM) (by norm_num)) + +theorem goodPairProbability_le_one (M : ℝ) : goodPairProbability M ≤ 1 := + le_trans (min_le_left _ _) (by norm_num) + +theorem odd_terminal_progress {M : ℝ} (hM : 4 ≤ M) (s : OddState) (hs : s.1 ≤ M) : + ENNReal.ofReal (goodPairProbability M) ≤ + oddTwoStep s {x : ℝ × ℝ | x.2 ≤ max (3 / 2) (s.1 - 3 / 2)} := by + calc + _ ≤ ENNReal.ofReal (goodPairDensityLower M / 16) := ENNReal.ofReal_le_ofReal (min_le_right _ _) + _ ≤ oddTwoStep s (goodPair s.1) := goodPair_measure_lower hM s hs + _ ≤ _ := measure_mono (fun x hx => goodPair_terminal hx) + +end NumberTheoryLean.GoodPairTransitions + +end + +section + +namespace NumberTheoryLean.FirstHitKernels + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open FinitePathMeasures + +def regenerationStateSet : Set State := + fun z => Sum.elim (fun _ : TransitionKernels.EvenState => False) + (fun s : TransitionKernels.OddState => s.1 ≤ 3) z + +theorem regenerationStateSet_measurable : MeasurableSet regenerationStateSet := by + apply measurableSet_sum_iff.mpr + constructor + · exact MeasurableSet.empty + · exact measurableSet_le measurable_subtype_coe measurable_const + +def regenerationSet : Set CostState := Prod.fst ⁻¹' regenerationStateSet + +theorem regenerationSet_measurable : MeasurableSet regenerationSet := + regenerationStateSet_measurable.preimage measurable_fst + +@[simp] theorem regeneration_even (s : TransitionKernels.EvenState) (T : ℝ) : + (.inl s, T) ∉ regenerationSet := by change ¬False; exact not_false + +@[simp] theorem regeneration_odd (s : TransitionKernels.OddState) (T : ℝ) : + (.inr s, T) ∈ regenerationSet ↔ s.1 ≤ 3 := Iff.rfl + +noncomputable def killed : Kernel CostState CostState := costKernel.restrict regenerationSet_measurable.compl +noncomputable def captured : Kernel CostState CostState := costKernel.restrict regenerationSet_measurable + +instance killed_isFiniteKernel : IsFiniteKernel killed := by unfold killed; infer_instance +instance captured_isFiniteKernel : IsFiniteKernel captured := by unfold captured; infer_instance + +instance killed_pow_isFiniteKernel (n : ℕ) : IsFiniteKernel (killed ^ n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel CostState CostState); infer_instance + | succ n ih => + rw [pow_succ'] + change IsFiniteKernel (killed ∘ₖ (killed ^ n)) + infer_instance + +theorem captured_add_killed : captured + killed = costKernel := by + ext z : 1 + change (costKernel z).restrict regenerationSet + (costKernel z).restrict regenerationSetᶜ = costKernel z + exact Measure.restrict_add_restrict_compl regenerationSet_measurable + +noncomputable def firstHit (n : ℕ) : Kernel CostState CostState := captured ∘ₖ (killed ^ n) + +instance firstHit_isFiniteKernel (n : ℕ) : IsFiniteKernel (firstHit n) := by + unfold firstHit + infer_instance + +noncomputable def firstHitLaw : Kernel CostState CostState := Kernel.sum firstHit + +instance firstHitLaw_isSFiniteKernel : IsSFiniteKernel firstHitLaw := by + unfold firstHitLaw + infer_instance + +theorem firstHit_mass_step (n : ℕ) (z : CostState) : + firstHit n z univ + (killed ^ (n + 1)) z univ = (killed ^ n) z univ := by + have hp : killed ^ (n + 1) = killed ∘ₖ (killed ^ n) := pow_succ' killed n + calc + _ = ((captured + killed) ∘ₖ (killed ^ n)) z univ := by + rw [Kernel.comp_add_left, add_apply, Measure.add_apply, hp] + rfl + _ = (costKernel ∘ₖ (killed ^ n)) z univ := by rw [captured_add_killed] + _ = _ := by rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ]; simp + +theorem firstHit_finite_mass (n : ℕ) (z : CostState) : + (killed ^ n) z univ + ∑ k ∈ Finset.range n, firstHit k z univ = 1 := by + induction n with + | zero => + simp only [Finset.range_zero, Finset.sum_empty, add_zero, pow_zero] + change (Measure.dirac z) univ = 1 + simp + | succ n ih => + rw [Finset.sum_range_succ] + calc + _ = (∑ k ∈ Finset.range n, firstHit k z univ) + + (firstHit n z univ + (killed ^ (n + 1)) z univ) := by ac_rfl + _ = (∑ k ∈ Finset.range n, firstHit k z univ) + (killed ^ n) z univ := by rw [firstHit_mass_step] + _ = 1 := by simpa only [add_comm] using ih + +theorem survival_mass_le_one (n : ℕ) (z : CostState) : (killed ^ n) z univ ≤ 1 := by + calc + _ ≤ (killed ^ n) z univ + ∑ k ∈ Finset.range n, firstHit k z univ := le_add_of_nonneg_right zero_le + _ = 1 := firstHit_finite_mass n z + +theorem firstHit_partial_mass_le_one (n : ℕ) (z : CostState) : + (∑ k ∈ Finset.range n, firstHit k z univ) ≤ 1 := by + calc + _ ≤ (killed ^ n) z univ + ∑ k ∈ Finset.range n, firstHit k z univ := le_add_of_nonneg_left zero_le + _ = 1 := firstHit_finite_mass n z + +theorem survival_mass_antitone (z : CostState) : Antitone (fun n => (killed ^ n) z univ) := by + apply antitone_nat_of_succ_le + intro n + calc + _ ≤ firstHit n z univ + (killed ^ (n + 1)) z univ := le_add_of_nonneg_left zero_le + _ = _ := firstHit_mass_step n z + +theorem firstHitLaw_mass_le_one (z : CostState) : firstHitLaw z univ ≤ 1 := by + rw [firstHitLaw, Kernel.sum_apply' _ _ MeasurableSet.univ, ENNReal.tsum_eq_iSup_nat] + exact iSup_le (fun n => firstHit_partial_mass_le_one n z) + +instance firstHitLaw_isFiniteKernel : IsFiniteKernel firstHitLaw := + ⟨1, by norm_num, fun z => firstHitLaw_mass_le_one z⟩ + +theorem firstHitLaw_probability_of_survival_vanishes (z : CostState) + (hz : Tendsto (fun n => (killed ^ n) z univ) atTop (𝓝 0)) : + IsProbabilityMeasure (firstHitLaw z) := by + constructor + rw [firstHitLaw, Kernel.sum_apply' _ _ MeasurableSet.univ] + have hs := hz.add (ENNReal.tendsto_nat_tsum (fun n => firstHit n z univ)) + simp only [zero_add, firstHit_finite_mass] at hs + exact tendsto_nhds_unique hs tendsto_const_nhds + +theorem captured_off_regeneration (z : CostState) : captured z regenerationSetᶜ = 0 := by + rw [captured, Kernel.restrict_apply' _ _ _ regenerationSet_measurable.compl, + compl_inter_self, measure_empty] + +theorem firstHit_off_regeneration (n : ℕ) (z : CostState) : firstHit n z regenerationSetᶜ = 0 := by + rw [firstHit, Kernel.comp_apply' _ _ _ regenerationSet_measurable.compl] + simp only [captured_off_regeneration, lintegral_zero] + +theorem firstHitLaw_off_regeneration (z : CostState) : firstHitLaw z regenerationSetᶜ = 0 := by + rw [firstHitLaw, Kernel.sum_apply' _ _ regenerationSet_measurable.compl] + simp only [firstHit_off_regeneration, tsum_zero] + +theorem costKernel_increases_cost (z : CostState) : + costKernel z {y : CostState | y.2 ≤ z.2} = 0 := by + rw [costKernel_apply z (measurableSet_le measurable_snd measurable_const)] + have he : {s : State | ((s, z.2 + FinitePathGeometry.cost (stateRatio s)) : CostState).2 ≤ z.2} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro s hs + have hp := FinitePathGeometry.cost_pos (FinitePathGeometry.valid_pos (stateRatio_valid s)) + change z.2 + FinitePathGeometry.cost (stateRatio s) ≤ z.2 at hs + linarith + change (stateKernel z.1) {s : State | z.2 + FinitePathGeometry.cost (stateRatio s) ≤ z.2} = 0 + rw [he, measure_empty] + +end NumberTheoryLean.FirstHitKernels + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/FullBoxVarianceGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/FullBoxVarianceGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..8198e2186ef916e0c1901ffe47836d4a88f8f063 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/FullBoxVarianceGeometry.lean @@ -0,0 +1,49 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.FullBoxTotalLength + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceWeighted +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport SafeSubsetBoxGeometry + ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection LogarithmicBinScale + +theorem product_le_Y_of_length (w a : ℝ) (hw : 1 < w) (ha : 0 ≤ a) (Y d : ℕ) + (hY : 0 < Y) (hd : 0 < d) (hlen : a ≤ Real.log ((Y : ℝ)/(d : ℝ))/Real.log w) : d ≤ Y := by + have hdR : (0 : ℝ) < d := by exact_mod_cast hd + have hYR : (0 : ℝ) < Y := by exact_mod_cast hY + have hh : w^a ≤ (Y : ℝ)/(d : ℝ) := (Real.le_logb_iff_rpow_le hw (div_pos hYR hdR)).mp hlen + have hratio : 1 ≤ (Y : ℝ)/(d : ℝ) := (Real.one_le_rpow hw.le ha).trans hh + have hreal := (le_div_iff₀ hdR).mp hratio + have hdle : (d : ℝ) ≤ Y := by simpa only [one_mul] using hreal + exact_mod_cast hdle + +theorem full_box_variance_fibres {w top xi B C K a : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) (ha0 : 0 ≤ a) + (hcomp : Real.log B ≤ 2*Real.log w) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap = Real.log (Y : ℝ)/Real.log w-a+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed = true) (hcap : w^z.cutoff = top) + (m : Fin (binCount w top xi) → ℕ) (hanchor : SafeAnchor hw htop hxi C B K z m) + (i : Fin (binCount w top xi)) (hi : m i = 1) : + ∀ f ∈ selections (globalBins w top xi) (eraseMultiplicity m i),Squarefree (selectionProduct f) ∧ + (∀ t ∈ (selectionProduct f).primeFactors,w < (t : ℝ)) ∧ + (∀ p ∈ globalBins w top xi i,(selectionProduct f).Coprime p ∧ + 3*a/4 ≤ Real.log ((Y : ℝ)/((p : ℝ)*selectionProduct f))/Real.log w) := by + intro f hf + have harith := erased_cofactor_arithmetic hw htop hxi m i f hf + have hlen := erased_cofactor_all_lengths hw htop hxi hC hcomp Y hY z hroot hs hz hg hclosed hcap m hanchor i hi f hf + refine ⟨harith.1,harith.2.1,?_⟩ + intro p hp + exact ⟨harith.2.2 p hp,(by linarith : 3*a/4 ≤ a).trans (hlen p hp)⟩ + +end ErdosVarianceWeighted + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/FullPatternVariance.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/FullPatternVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..46ce1ab1538fcf0705b5e95201c55e6384290546 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/FullPatternVariance.lean @@ -0,0 +1,188 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ConditionalPatternCounts +import OAI.NumberTheory.Jacobsthal.Primes.StableSourceChebyshev + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosLargePatternLaw +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceMoments + +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem four_coordinate_count {A B C D : Type*} [Fintype A] [Fintype B] [Fintype C] [Fintype D] + (P : A → B → Prop) (Q : C → D → Prop) (n m : ℕ) + (hP : ∀ a,(Finset.univ.filter (P a)).card=n) + (hQ : ∀ c,(Finset.univ.filter (Q c)).card=m) : + (Finset.univ.filter (fun v : A × B × C × D => P v.1 v.2.1 ∧ Q v.2.2.1 v.2.2.2)).card = + Fintype.card A*n*Fintype.card C*m := by + have hi (a : A) (b : B) (c : C) (d : D) : + (if P a b ∧ Q c d then 1 else 0 : ℕ)=(if P a b then 1 else 0)*(if Q c d then 1 else 0) := by + by_cases hp : P a b <;> by_cases hq : Q c d <;> simp [hp,hq] + have hp (a : A) : (∑ b : B,if P a b then 1 else 0)=n := by + simpa only [Finset.card_filter] using hP a + have hq (c : C) : (∑ d : D,if Q c d then 1 else 0)=m := by + simpa only [Finset.card_filter] using hQ c + have hd (a : A) (b : B) (c : C) : + (∑ d : D,(if P a b then 1 else 0)*(if Q c d then 1 else 0)) = + (if P a b then 1 else 0)*m := by + calc + _ = (if P a b then 1 else 0)*(∑ d : D,if Q c d then 1 else 0) := + (Finset.mul_sum _ _ _).symm + _ = _ := by rw [hq] + simp only [Finset.card_filter,Fintype.sum_prod_type,hi] + simp_rw [hd] + simp only [Finset.sum_const,Finset.card_univ,smul_eq_mul] + have hb (a : A) : (∑ b : B,Fintype.card C*((if P a b then 1 else 0)*m)) = + Fintype.card C*(n*m) := by + calc + _ = Fintype.card C*(∑ b : B,(if P a b then 1 else 0)*m) := (Finset.mul_sum _ _ _).symm + _ = Fintype.card C*((∑ b : B,if P a b then 1 else 0)*m) := + congrArg (fun x => Fintype.card C*x) (Finset.sum_mul _ _ _).symm + _ = _ := by rw [hp] + simp_rw [hb] + simp only [Finset.sum_const,Finset.card_univ,smul_eq_mul] + ring + +theorem joint_condition_card (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) : + (Finset.univ.filter (jointCondition w H qA beta delta S)).card = + (divisorModulus w H).totient*(∏ t ∈ divisorPrimes w H,(t-(positionResidues S t).card))* + (coprimeModulus w H).totient*(∏ t ∈ coprimePrimes w H,(t-(positionResidues S t).card)) := by + have he : Finset.univ.filter (jointCondition w H qA beta delta S) = + Finset.univ.filter (fun v : FullPattern w H => + divisorCondition w H beta S v.1 v.2.1 ∧ coprimeCondition w H qA delta S v.2.2.1 v.2.2.2) := by + apply Finset.filter_congr + rintro ⟨p0,k0,p1,m1⟩ _ + exact joint_condition_split w H qA beta delta S p0 k0 p1 m1 + rw [he,four_coordinate_count _ _ _ _ + (divisor_condition_card w H beta S) (fun p1 => coprime_condition_card w H qA delta S p1 hqA)] + simp only [ZMod.card_units_eq_totient] + +theorem joint_density_split (w : ℝ) (H : ℕ) (S : Finset ℕ) : + jointDensity (divisorPrimes w H) S*jointDensity (coprimePrimes w H) S = + jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S := by + unfold jointDensity divisorPrimes coprimePrimes + exact Finset.prod_filter_mul_prod_filter_not _ _ _ + +theorem joint_expectation (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) : + expectation w H (fun v => if jointCondition w H qA beta delta S v then 1 else 0) = + jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S := by + have h0 : ∀ t ∈ divisorPrimes w H,t.Prime := fun t ht => + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1 + have h1 : ∀ t ∈ coprimePrimes w H,t.Prime := fun t ht => + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1 + have hc : (∑ v : FullPattern w H,if jointCondition w H qA beta delta S v then (1 : ℝ) else 0) = + ((Finset.univ.filter (jointCondition w H qA beta delta S)).card : ℝ) := by + simp only [Finset.card_filter,Nat.cast_sum,Nat.cast_ite,Nat.cast_one,Nat.cast_zero] + have hT0 : (divisorModulus w H : ℝ) ≠ 0 := by exact_mod_cast (divisorModulus_pos w H).ne' + have hT1 : (coprimeModulus w H : ℝ) ≠ 0 := by exact_mod_cast (coprimeModulus_pos w H).ne' + have hP0 : ((divisorModulus w H).totient : ℝ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (divisorModulus_pos w H)).ne' + have hP1 : ((coprimeModulus w H).totient : ℝ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (coprimeModulus_pos w H)).ne' + rw [expectation,← Finset.mul_sum,hc,joint_condition_card w H qA beta delta S hqA] + simp only [Nat.cast_mul] + rw [product_allowed_eq_density _ S h0,product_allowed_eq_density _ S h1] + change weight w H*(((divisorModulus w H).totient : ℝ)* + ((divisorModulus w H : ℝ)*jointDensity (divisorPrimes w H) S)* + ((coprimeModulus w H).totient : ℝ)* + ((coprimeModulus w H : ℝ)*jointDensity (coprimePrimes w H) S)) = _ + rw [← joint_density_split w H S] + unfold weight + field_simp + +end ErdosLargePatternLaw + + + +open _root_.Filter +namespace ErdosLargePatternLaw +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceMoments ErdosRandomVariance + +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem single_expectation (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) (j : ℕ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) : + expectation w H (indicator w H qA beta delta j) = + sieveProduct (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) := by + have h := joint_expectation w H qA beta delta {j} hqA + have he : (fun v => if jointCondition w H qA beta delta {j} v then (1 : ℝ) else 0) = + indicator w H qA beta delta j := by + funext v + simp only [jointCondition,Finset.mem_singleton,forall_eq,indicator] + rw [he,jointDensity_singleton] at h + exact h + +theorem pair_expectation (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) (i j : ℕ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) : + expectation w H (fun v => indicator w H qA beta delta i v*indicator w H qA beta delta j v) = + pairKernel (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) i j := by + have h := joint_expectation w H qA beta delta {i,j} hqA + have he : (fun v => indicator w H qA beta delta i v*indicator w H qA beta delta j v) = + (fun v => if jointCondition w H qA beta delta {i,j} v then 1 else 0) := by + funext v + simp only [jointCondition,Finset.forall_mem_insert,Finset.mem_singleton,forall_eq,indicator] + by_cases hi : survives w H qA beta delta i v <;> + by_cases hj : survives w H qA beta delta j v <;> simp [hi,hj] + rw [he,h,jointDensity_pair] + +theorem count_variance (w : ℝ) (H qA J : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) : + expectation w H (fun v => ((survivorCount w H qA J beta delta v : ℝ)- + (J : ℝ)*sieveProduct (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊))^2) ≤ + (J : ℝ)*sieveProduct (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) := by + have hs (j : ℕ) := single_expectation w H qA beta delta j hqA + have hp (i j : ℕ) := pair_expectation w H qA beta delta i j hqA + have hh := stable_prime_variance (Finset.univ : Finset (FullPattern w H)) (fun _ => weight w H) + J (indicator w H qA beta delta) (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) + (fun p hp => (LargePrimeDeletion.mem_cutoffPrimes.mp hp).1) 0 (le_refl _) + (fun j _ v _ => indicator_binary w H qA beta delta j v) + (by simpa only [add_zero] using (weight_sum w H).le) + (fun j _ => by simpa only [sub_zero,one_mul,expectation,weightedMoment] using (hs j).ge) + (fun j _ => by simpa only [add_zero,one_mul,expectation,weightedMoment] using (hs j).le) + (fun i _ j _ _ => by simpa only [add_zero,one_mul,expectation,weightedMoment] using (hp i j).le) + simpa only [mul_zero,zero_mul,one_mul,add_zero,indicatorSum,← count_eq_indicator_sum,expectation,weightedMoment] using hh + +theorem uniform_pattern_chebyshev (a eta tau : ℝ) (ha : 0 < a) (heta : 0 < eta) (htau : 0 < tau) : + ∀ᶠ w : ℝ in atTop,1 < w ∧ ∀ (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t), + (∀ t ∈ coprimePrimes w H,qA.Coprime t) → ∀ J : ℕ,w^a ≤ (J : ℝ) → + (∑ v : FullPattern w H with eta*((J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ + |(survivorCount w H qA J beta delta v : ℝ)-(J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊|, + weight w H) ≤ tau := by + have heps : 0 < tau*eta^2 := mul_pos htau (sq_pos_of_pos heta) + filter_upwards [stable_source_chebyshev a (tau*eta^2) ha heps] with w hw + refine ⟨hw.1,?_⟩ + intro H qA beta delta hqA J hJ + have hcut : variancePrimes w=LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ := by + ext p + simp only [variancePrimes,LargePrimeDeletion.mem_cutoffPrimes,Finset.mem_filter,Finset.mem_Ioc] + exact ⟨fun h => ⟨h.2,h.1.2⟩,fun h => ⟨⟨h.1.pos,h.2⟩,h.1⟩⟩ + have hs (j : ℕ) := single_expectation w H qA beta delta j hqA + have hp (i j : ℕ) := pair_expectation w H qA beta delta i j hqA + have hh := hw.2 J hJ (FullPattern w H) Finset.univ (fun _ => weight w H) + (indicator w H qA beta delta) 0 eta (fun _ _ => (weight_positive w H).le) + (le_refl _) zero_le_one heta (fun j _ v _ => indicator_binary w H qA beta delta j v) + (by simpa only [add_zero] using (weight_sum w H).le) + (fun j _ => by simpa only [sub_zero,one_mul,hcut,expectation,weightedMoment] using (hs j).ge) + (fun j _ => by simpa only [add_zero,one_mul,hcut,expectation,weightedMoment] using (hs j).le) + (fun i _ j _ _ => by simpa only [add_zero,one_mul,hcut,expectation,weightedMoment] using (hp i j).le) + have hV : sieveProduct (variancePrimes w)=SmallSieveFinite.smallEuler ⌊w⌋₊ := by + rw [hcut] + simp only [sieveProduct,SmallSieveFinite.smallEuler,one_div] + have hb : (tau*eta^2+4*0)/eta^2=tau := by + field_simp [heta.ne'] + ring + simpa only [hV,hb,indicatorSum,← count_eq_indicator_sum] using hh + +end ErdosLargePatternLaw + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/GenuineMarkedVisit.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/GenuineMarkedVisit.lean new file mode 100644 index 0000000000000000000000000000000000000000..878fc650f86a6a138487620e5ccc5ae9d592111a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/GenuineMarkedVisit.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.RawCompactPlacement + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels +open NumberTheoryLean.FirstHitKernels + +noncomputable def genuineMarkedVisitEvent (a : ℕ) (v H : ℝ) : Set (RawEvenMarkedHitTrace a) := + {z | rawEvenHitAnchor a z ∈ regenerationSet ∧ z ∈ evenHitIncreasing a ∧ + z ∈ rawEvenPhysicalHitEvent a v H} + +lemma genuineMarkedVisitEvent_measurable (a : ℕ) (v H : ℝ) : MeasurableSet (genuineMarkedVisitEvent a v H) := + (regenerationSet_measurable.preimage (rawEvenHitAnchor_measurable a)).inter + ((evenHitIncreasing_measurable a).inter (rawEvenPhysicalHitEvent_measurable a v H)) + +lemma rawEvenHit_ae_genuine (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a v H h, z ∈ genuineMarkedVisitEvent a v H := by + filter_upwards [rawEvenHit_anchor_regenerates a v H h,rawEvenHit_increasing a v H h, + rawEvenHit_ae_physical a v H h] with z hz0 hz1 hz2 + exact ⟨hz0,hz1,hz2⟩ + +theorem genuineMarkedVisit_mass (a : ℕ) (v H : ℝ) (h : RawHistory a) : + rawEvenMarkedHitKernel a v H h (genuineMarkedVisitEvent a v H)=rawEvenMarkedHitKernel a v H h univ := + (ae_mem_iff_measure_eq (genuineMarkedVisitEvent_measurable a v H).nullMeasurableSet).mp + (rawEvenHit_ae_genuine a v H h) + +theorem genuineMarkedVisit_exponential (S : ℝ) : ∃ eta C eta0 B : ℝ, + 0 < eta ∧ 0 < C ∧ 0 < eta0 ∧ 0 ≤ B ∧ ∀ (a : ℕ) (h : RawHistory a) (s : EvenState), + rawLast a h=(Sum.inl s,0) → s.1 ≤ S → ∀ v H : ℝ, 0 ≤ H → + 1-rawEvenMarkedHitKernel a v H h (genuineMarkedVisitEvent a v H) ≤ + ENNReal.ofReal (C*Real.exp (-eta*H)+B*Real.exp (-eta0*v)) := by + obtain ⟨eta,C,eta0,B,heta,hC,heta0,hB,h⟩ := rawEvenMarkedHit_exponential S + refine ⟨eta,C,eta0,B,heta,hC,heta0,hB,?_⟩ + intro a past s hs hS v H hH + rw [genuineMarkedVisit_mass] + exact h a past s hs hS v H hH + +theorem moving_genuine_marked_visit {eps : ℝ} (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → ∀ (a : ℕ) (h : RawHistory a) (s : EvenState), + rawLast a h=(Sum.inl s,0) → 199/100 ≤ s.1 → s.1 ≤ 23/10 → + 1-rawEvenMarkedHitKernel a (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) h + (genuineMarkedVisitEvent a (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10))) ≤ + ENNReal.ofReal eps := by + obtain ⟨rho,hrho,hMoving⟩ := moving_raw_even_marked_hit heps + refine ⟨rho,hrho,?_⟩ + intro K hK + filter_upwards [hMoving K hK] with w hw + refine ⟨hw.1,?_⟩ + intro r hr a h s hs hs0 hs1 + rw [genuineMarkedVisit_mass] + exact hw.2 r hr a h s hs hs0 hs1 + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/GeometricCostLaws.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/GeometricCostLaws.lean new file mode 100644 index 0000000000000000000000000000000000000000..610e333108b97c7365d0ad142d9bc678245dcc02 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/GeometricCostLaws.lean @@ -0,0 +1,115 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UnmarkedTransform + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open AbsorptionCutoff.Renewal + +noncomputable def costTransform (μ : Measure ℝ) (eta : ℝ) : ℝ≥0∞ := + ∫⁻ G, ENNReal.ofReal (Real.exp (eta*G)) ∂μ + +lemma costTransform_zero (μ : Measure ℝ) : costTransform μ 0 = μ univ := by simp [costTransform] + +lemma costTransform_conv (μ ν : Measure ℝ) [SFinite ν] (eta : ℝ) : + costTransform (μ ∗ ν) eta = costTransform μ eta*costTransform ν eta := by + have hm : Measurable (fun G : ℝ => ENNReal.ofReal (Real.exp (eta*G))) := by fun_prop + rw [costTransform,Measure.lintegral_conv hm] + have hi (x : ℝ) : (∫⁻ y, ENNReal.ofReal (Real.exp (eta*(x+y))) ∂ν) = + ENNReal.ofReal (Real.exp (eta*x))*costTransform ν eta := by + simp_rw [mul_add,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le] + exact lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + simp_rw [hi] + exact lintegral_mul_const _ hm + +lemma conv_mass (μ ν : Measure ℝ) [SFinite ν] : (μ ∗ ν) univ = μ univ*ν univ := by + simpa only [costTransform_zero] using costTransform_conv μ ν 0 + +lemma convPow_costTransform (μ : Measure ℝ) [SFinite μ] (eta : ℝ) (n : ℕ) : + costTransform (convPow μ n) eta = (costTransform μ eta)^n := by + induction n with + | zero => simp [convPow_zero,costTransform] + | succ n ih => rw [convPow_succ,costTransform_conv,ih,pow_succ] + +lemma renewal_costTransform (μ : Measure ℝ) [SFinite μ] (eta : ℝ) : + costTransform (renewalMeasure μ) eta = (1-costTransform μ eta)⁻¹ := by + rw [costTransform,renewalMeasure,lintegral_sum_measure] + change (∑' n, costTransform (convPow μ n) eta) = _ + simp_rw [convPow_costTransform] + exact ENNReal.tsum_geometric _ + +noncomputable def unmarkedPotential : Measure ℝ := renewalMeasure unmarkedCostLaw + +lemma unmarkedPotential_mass : unmarkedPotential univ = markProbability⁻¹ := by + have he := renewal_costTransform unmarkedCostLaw 0 + rw [costTransform_zero,costTransform_zero,unmarkedCostLaw_mass, + ENNReal.sub_sub_cancel (by simp : (1:ℝ≥0∞) ≠ ∞) markProbability_lt_one.le] at he + exact he + +instance unmarkedPotential_isFiniteMeasure : IsFiniteMeasure unmarkedPotential := by + constructor + rw [unmarkedPotential_mass] + exact lt_top_iff_ne_top.mpr (ENNReal.inv_ne_top.mpr markProbability_pos.ne') + +noncomputable def geometricMarkedCostLaw : Measure ℝ := markedCostLaw ∗ unmarkedPotential + +instance geometricMarkedCostLaw_isProbabilityMeasure : IsProbabilityMeasure geometricMarkedCostLaw := by + constructor + rw [geometricMarkedCostLaw,conv_mass,markedCostLaw_mass,unmarkedPotential_mass] + exact ENNReal.mul_inv_cancel markProbability_pos.ne' (lt_trans markProbability_lt_one (by simp)).ne + +lemma geometricMarked_costTransform (eta : ℝ) : + costTransform geometricMarkedCostLaw eta = + costTransform markedCostLaw eta*(1-costTransform unmarkedCostLaw eta)⁻¹ := by + rw [geometricMarkedCostLaw,costTransform_conv,unmarkedPotential,renewal_costTransform] + +lemma geometricMarked_exponential_moment : ∃ eta : ℝ, 0 < eta ∧ + costTransform geometricMarkedCostLaw eta < ∞ := by + obtain ⟨eta,heta,hU,hM⟩ := exists_subcritical_unmarked_transform + refine ⟨eta,heta,?_⟩ + rw [geometricMarked_costTransform] + have hsub : (1:ℝ≥0∞)-costTransform unmarkedCostLaw eta ≠ 0 := + (tsub_pos_iff_lt.mpr hU).ne' + exact ENNReal.mul_lt_top hM (lt_top_iff_ne_top.mpr (ENNReal.inv_ne_top.mpr hsub)) + +lemma conv_ae_lower {μ ν : Measure ℝ} [SFinite μ] [SFinite ν] {a b : ℝ} + (hμ : ∀ᵐ x ∂μ, a ≤ x) (hν : ∀ᵐ y ∂ν, b ≤ y) : + ∀ᵐ z ∂(μ ∗ ν), a+b ≤ z := by + rw [Measure.conv] + apply (ae_map_iff measurable_add.aemeasurable measurableSet_Ici).mpr + apply (Measure.ae_prod_iff_ae_ae (measurableSet_le measurable_const measurable_add)).mpr + filter_upwards [hμ] with x hx + filter_upwards [hν] with y hy + linarith + +lemma convPow_ae_nonneg (μ : Measure ℝ) [SFinite μ] (hμ : ∀ᵐ x ∂μ, 0 ≤ x) (n : ℕ) : + ∀ᵐ x ∂convPow μ n, 0 ≤ x := by + induction n with + | zero => simp [convPow_zero] + | succ n ih => + rw [convPow_succ] + simpa only [zero_add] using conv_ae_lower ih hμ + +lemma unmarkedPotential_ae_nonneg : ∀ᵐ G ∂unmarkedPotential, 0 ≤ G := by + rw [unmarkedPotential,renewalMeasure,Measure.ae_sum_iff] + intro n + apply convPow_ae_nonneg + filter_upwards [source_unmarked_cost_lower] with G hG + exact positive_cost_of_lower hG + +lemma geometricMarked_cost_lower : ∀ᵐ G ∂geometricMarkedCostLaw, Real.log (4/3) ≤ G := by + rw [geometricMarkedCostLaw] + simpa only [add_zero] using conv_ae_lower source_marked_cost_lower unmarkedPotential_ae_nonneg + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/HarmonicPrefixKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/HarmonicPrefixKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..3ce666ceef75bd5d47229c4b3fffdf1f28fb1e82 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/HarmonicPrefixKernel.lean @@ -0,0 +1,175 @@ +import Mathlib.MeasureTheory.Measure.Lebesgue.Basic +import Mathlib.Probability.Kernel.Composition.Comp +import Mathlib.Probability.Kernel.WithDensity +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosPrimeInputs.WeightedKernelMass + +open Set Finset MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {α : Type*} [MeasurableSpace α] + +noncomputable def mass (K : Kernel α α) (n : ℕ) (x : α) : ℝ≥0∞ := (K^n) x univ + +@[simp] theorem mass_zero (K : Kernel α α) (x : α) : mass K 0 x = 1 := by + change (Measure.dirac x) univ = 1 + simp + +lemma mass_succ (K : Kernel α α) (n : ℕ) (x : α) : + mass K (n+1) x = ∫⁻ y, mass K n y ∂K x := by + unfold mass + rw [pow_succ] + exact Kernel.comp_apply' _ _ _ MeasurableSet.univ + +lemma mass_measurable (K : Kernel α α) (n : ℕ) : Measurable (mass K n) := + (K^n).measurable_coe MeasurableSet.univ + +theorem weighted_sum_succ (K : Kernel α α) (c : ℝ≥0∞) (N : ℕ) (x : α) : + (∑ n ∈ range (N+1), c^n * mass K n x) = + 1 + c * ∫⁻ y, (∑ n ∈ range N, c^n * mass K n y) ∂K x := by + rw [lintegral_finsetSum (range N) (f := fun n y => c^n * mass K n y) (fun n _ => measurable_const.mul (mass_measurable K n)),mul_sum] + simp_rw [lintegral_const_mul _ (mass_measurable K _),← mass_succ] + rw [Finset.sum_range_succ'] + simp only [pow_zero,mass_zero,one_mul] + rw [add_comm] + congr 1 + apply sum_congr rfl + intro n hn + rw [pow_succ] + ring + +theorem weighted_finite_bound (K : Kernel α α) (c : ℝ≥0∞) (V : α → ℝ≥0∞) + (hV : ∀ x, 1 + c * (∫⁻ y, V y ∂K x) ≤ V x) : + ∀ N : ℕ, ∀ x : α, (∑ n ∈ range N, c^n * mass K n x) ≤ V x := by + intro N + induction N with + | zero => intro x; simp + | succ N ih => + intro x + rw [weighted_sum_succ] + exact (add_le_add le_rfl (mul_le_mul le_rfl (lintegral_mono (fun y => ih y)) zero_le zero_le)).trans (hV x) + +theorem weighted_total_bound (K : Kernel α α) (c : ℝ≥0∞) (V : α → ℝ≥0∞) + (hV : ∀ x, 1 + c * (∫⁻ y, V y ∂K x) ≤ V x) (x : α) : + (∑' n : ℕ, c^n * mass K n x) ≤ V x := by + exact ENNReal.tsum_le_of_sum_range_le (fun N => weighted_finite_bound K c V hV N x) + +end ErdosPrimeInputs.WeightedKernelMass + +end + +section + +namespace ErdosPrimeInputs.HarmonicPrefixKernel + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open WeightedKernelMass + +noncomputable def density (ell B t : ℝ) : ℝ≥0∞ := + if ell simp + +theorem kernel_lintegral (ell B : ℝ) {f : ℝ → ℝ≥0∞} (hf : Measurable f) : + (∫⁻ t, f t ∂kernel ell B) = ∫⁻ t in Ioc ell B, ENNReal.ofReal (t⁻¹)*f t := by + rw [kernel,Kernel.lintegral_withDensity _ (density_measurable ell) B hf,Kernel.const_apply] + have heq : (fun t => density ell B t * f t) = (Ioc ell B).indicator (fun t => ENNReal.ofReal (t⁻¹)*f t) := by + funext t + simp only [density,Set.indicator,mem_Ioc,ite_mul,zero_mul] + rw [heq,lintegral_indicator measurableSet_Ioc] + +theorem kernel_eq_restrict (ell B : ℝ) : kernel ell B = + (volume.restrict (Ioc ell B)).withDensity (fun t : ℝ => ENNReal.ofReal (t⁻¹)) := by + apply Measure.ext_of_lintegral + intro f hf + rw [kernel_lintegral ell B hf] + have hm : Measurable (fun t : ℝ => ENNReal.ofReal (t⁻¹)) := ENNReal.measurable_ofReal.comp measurable_inv + exact (lintegral_withDensity_eq_lintegral_mul _ hm hf).symm + +lemma kernel_eq_zero {ell B : ℝ} (hB : B≤ell) : kernel ell B = 0 := by + rw [kernel_eq_restrict,Ioc_eq_empty_of_le hB] + simp + +noncomputable def bound (ell B : ℝ) : ℝ := max 1 (B/ell) +noncomputable def boundE (ell B : ℝ) : ℝ≥0∞ := ENNReal.ofReal (bound ell B) + +lemma bound_measurable (ell : ℝ) : Measurable (bound ell) := + measurable_const.max (measurable_id.div_const ell) + +lemma boundE_measurable (ell : ℝ) : Measurable (boundE ell) := + ENNReal.measurable_ofReal.comp (bound_measurable ell) + +lemma bound_on {ell B : ℝ} (hell : 0 by simpa only [one_mul] using (schur_one hell x).le) B + simpa only [one_pow,one_mul,boundE,bound_on hell hB] using h + +end ErdosPrimeInputs.HarmonicPrefixKernel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/HighPrefixKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/HighPrefixKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b8bbec2546d90fbbb3a24440a0faf567bd3fbe4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/HighPrefixKernel.lean @@ -0,0 +1,104 @@ +import Mathlib.Probability.Kernel.Composition.Prod +import OAI.NumberTheory.Jacobsthal.Paths.HighPrefixState + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosPrimeInputs.HighPrefixKernel + +open Set Filter MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +open WeightedKernelMass HarmonicPrefixKernel HarmonicPrefixTilt HarmonicLongPrefixes HighPrefixState + +noncomputable def kernel (ell S : ℝ) : Kernel State State := + ((Kernel.id : Kernel State State).prod + ((HarmonicPrefixKernel.kernel ell).comap (fun z : State => z.1) measurable_fst)).map + (Function.uncurry (update S)) + +instance kernel_isSFinite (ell S : ℝ) : IsSFiniteKernel (kernel ell S) := by + unfold kernel + infer_instance + +lemma update_at_measurable (S : ℝ) (z : State) : Measurable (update S z) := + (update_measurable S).of_uncurry_left + +theorem kernel_eq_map (ell S : ℝ) (z : State) : + kernel ell S z = (HarmonicPrefixKernel.kernel ell z.1).map (update S z) := by + apply Measure.ext_of_lintegral + intro f hf + rw [kernel,Kernel.map_apply _ (update_measurable S),lintegral_map hf (update_measurable S)] + have hg : Measurable (fun p : State × ℝ => f (update S p.1 p.2)) := hf.comp (update_measurable S) + calc + _ = ∫⁻ t, f (update S z t) ∂HarmonicPrefixKernel.kernel ell z.1 := + Kernel.lintegral_id_prod (f := fun p : State × ℝ => f (update S p.1 p.2)) hg _ z + _ = _ := (lintegral_map hf (update_at_measurable S z)).symm + +lemma harmonic_ae_interval (ell B : ℝ) : + ∀ᵐ t ∂HarmonicPrefixKernel.kernel ell B, t ∈ Ioc ell B := by + rw [HarmonicPrefixKernel.kernel_eq_restrict, + ae_withDensity_iff (by fun_prop : Measurable (fun t : ℝ => ENNReal.ofReal (t⁻¹)))] + filter_upwards [self_mem_ae_restrict measurableSet_Ioc] with t ht + intro _ + exact ht + +theorem ae_update (ell S : ℝ) (z : State) {P : State → Prop} + (hP : MeasurableSet {w | P w}) (h : ∀ t ∈ Ioc ell z.1, P (update S z t)) : + ∀ᵐ w ∂kernel ell S z, P w := by + rw [kernel_eq_map] + apply (ae_map_iff (update_at_measurable S z).aemeasurable hP).mpr + exact (harmonic_ae_interval ell z.1).mono (fun t ht => h t ht) + +lemma state_schur_one {ell : ℝ} (hell : 0 boundE ell w.1) := (boundE_measurable ell).comp measurable_fst + rw [lintegral_map (f := fun w : State => boundE ell w.1) hf (update_at_measurable S z)] + exact schur_one hell z.1 + +lemma state_schur_two {ell : ℝ} (hell : 0 squareBoundE ell w.1) := (squareBoundE_measurable ell).comp measurable_fst + rw [lintegral_map (f := fun w : State => squareBoundE ell w.1) hf (update_at_measurable S z)] + exact schur_two hell z.1 + +theorem total_mass {ell B : ℝ} (hell : 0 boundE ell z.1) + (fun z => by simpa only [one_mul] using (state_schur_one hell S z).le) (initial S B R) + simpa only [one_pow,one_mul,initial,boundE,bound_on hell hB] using h + +theorem weighted_mass {ell B : ℝ} (hell : 0 squareBoundE ell z.1) + (fun z => (state_schur_two hell S z).le) (initial S B R) + simpa only [initial,squareBoundE,bound_on hell hB] using h + +theorem ae_invariant {ell B : ℝ} (hell : 0 + intro _ + change ∀ᵐ z ∂Measure.dirac (initial S B R), Invariant ell S 0 z + exact (ae_dirac_iff (invariant_measurable ell S 0)).mpr (initial_invariant hell hB) + | succ n ih => + intro hn + have hn' : (n:ℝ)≤S := by push_cast at hn; linarith + rw [pow_succ'] + apply Kernel.ae_comp_of_ae_ae (invariant_measurable ell S (n+1)) + filter_upwards [ih hn'] with z hz + exact ae_update ell S z (invariant_measurable ell S (n+1)) + (fun t ht => update_invariant hell n z t hz ht hn') + +end ErdosPrimeInputs.HighPrefixKernel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/HorizontalBoundaryMarks.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/HorizontalBoundaryMarks.lean new file mode 100644 index 0000000000000000000000000000000000000000..b24558a566100ebeb610e558a10695c2d55e8031 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/HorizontalBoundaryMarks.lean @@ -0,0 +1,56 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.RealAlgebraicFibers + +namespace OAI + +namespace Erdos970 + +section + +open Set +namespace ErdosAlgebraicCurve +open ErdosCriticalGeometry ErdosImplicitCurvature ErdosDivisibleInflection + +theorem horizontalLine_ne_zero (z : ℂ) : affineLine 0 z ≠ 0 := by + intro hz + have h := congrArg (MvPolynomial.eval ![(0 : ℂ),z+1]) hz + simp [affineLine] at h + +theorem nonlinear_not_dvd_horizontal (Q : MV ℂ) (hdeg : 1 < Q.totalDegree) (z : ℂ) : + ¬Q ∣ affineLine 0 z := by + intro hdiv + have hd := MvPolynomial.totalDegree_le_of_dvd_of_isDomain hdiv (horizontalLine_ne_zero z) + exact (not_le_of_gt hdeg) (hd.trans (affineLine_degree_le 0 z)) + +def boundaryAbscissae (Q : MV ℝ) (y : ℝ) : Set ℝ := {x | peval Q x y = 0} + +theorem boundary_abscissae_bound (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) (y : ℝ) : + (boundaryAbscissae Q y).Finite ∧ (boundaryAbscissae Q y).ncard ≤ 2*Q.totalDegree := by + have hd : 1 < (complexify Q).totalDegree := by rwa [complexify_totalDegree] + obtain ⟨hfin,hcard⟩ := irreducible_abscissa_bound (complexify Q) (affineLine 0 (y : ℂ)) hQ hd + (nonlinear_not_dvd_horizontal _ hd y) + have hpre := finite_real_preimage (intersectionAbscissae (complexify Q) (affineLine 0 (y : ℂ))) hfin + have hsub : boundaryAbscissae Q y ⊆ + Complex.ofReal ⁻¹' intersectionAbscissae (complexify Q) (affineLine 0 (y : ℂ)) := by + intro x hx + refine ⟨((x : ℂ),(y : ℂ)),⟨?_,?_⟩,rfl⟩ + · rw [complexify_eval,← peval_eq_eval_pair] + change peval Q x y = 0 at hx + rw [hx,Complex.ofReal_zero] + · simp [affineLine] + refine ⟨hpre.1.subset hsub,?_⟩ + calc + _ ≤ (Complex.ofReal ⁻¹' intersectionAbscissae (complexify Q) (affineLine 0 (y : ℂ))).ncard := + ncard_le_ncard hsub hpre.1 + _ ≤ _ := hpre.2 + _ ≤ _ := hcard + _ ≤ 2*(complexify Q).totalDegree*1 := Nat.mul_le_mul_left _ (affineLine_degree_le 0 y) + _ = 2*Q.totalDegree := by rw [mul_one,complexify_totalDegree] + +end ErdosAlgebraicCurve + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/JointMarkedWord.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/JointMarkedWord.lean new file mode 100644 index 0000000000000000000000000000000000000000..1651d5e948cbffde128522fce69140ed7bb76617 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/JointMarkedWord.lean @@ -0,0 +1,75 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawWordBridgeInputs + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping + +noncomputable def sourceWordReward (w : List Bool) + (F : CycleInputSignature × CycleWordSignature w.length → ℝ≥0∞) (c : CycleInputSignature) : ℝ≥0∞ := + ∫⁻ s, F (c,s) ∂sourceMarkedWordKernel w (decodeReturnedOdd c.2.2.2) + +lemma sourceWordReward_measurable (w : List Bool) + {F : CycleInputSignature × CycleWordSignature w.length → ℝ≥0∞} (hF : Measurable F) : + Measurable (sourceWordReward w F) := by + let K : Kernel CycleInputSignature (CycleWordSignature w.length) := + (sourceMarkedWordKernel w).comap (fun c : CycleInputSignature => decodeReturnedOdd c.2.2.2) + (decodeReturnedOdd_measurable.comp (measurable_snd.comp (measurable_snd.comp measurable_snd))) + change Measurable (fun c : CycleInputSignature => ∫⁻ s, F (c,s) ∂K c) + exact hF.lintegral_kernel_prod_right' + +theorem rawMarkedWord_signature (w : List Bool) : ∀ (a : ℕ) (h : RawHistory a) (z : OddCost), + rawLast a h=embedOdd z → + (rawMarkedWordKernel a w h).map (rawCycleWordSignature a w.length) = sourceMarkedWordKernel w z := by + induction w with + | nil => + intro a h z hz + change (Measure.dirac h).map (rawLast a) = Measure.dirac (embedOdd z) + rw [Measure.map_dirac' (rawLast_measurable a),hz] + | cons b w ih => + intro a h z hz + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (rawCycleWordSignature_measurable _ a), + rawMarkedWord_cons_lintegral a b w h + (F := fun t => F (rawCycleWordSignature a (b::w).length t)) + (hF.comp (rawCycleWordSignature_measurable _ a)),sourceMarkedWord_cons_lintegral b w z hF] + have hInner : (fun r : RawReturnTrace a => ∫⁻ t, + F (rawReturnInputSignature a r,rawCycleWordSignature (a+2*(r.1+1)) w.length t) + ∂rawMarkedWordKernel (a+2*(r.1+1)) w r.2) =ᵐ[rawBranchReturnKernel a b h] + fun r => sourceWordReward w F (rawReturnInputSignature a r) := by + filter_upwards [rawBranchReturn_endpoint_supported a b h] with r hr + rcases r with ⟨n,y⟩ + change (∫⁻ t, F (rawReturnInputSignature a ⟨n,y⟩,rawCycleWordSignature (a+2*(n+1)) w.length t) + ∂rawMarkedWordKernel (a+2*(n+1)) w y) = _ + have hi := ih (a+2*(n+1)) y (decodeReturnedOdd (rawReturnSignature a ⟨n,y⟩).2.2) hr + have hG : Measurable (fun s : CycleWordSignature w.length => F (rawReturnInputSignature a ⟨n,y⟩,s)) := + hF.comp measurable_prodMk_left + rw [← lintegral_map (g := rawCycleWordSignature (a+2*(n+1)) w.length) + (f := fun s : CycleWordSignature w.length => F (rawReturnInputSignature a ⟨n,y⟩,s)) + hG (rawCycleWordSignature_measurable _ _),hi] + rfl + change (∫⁻ r : RawReturnTrace a, ∫⁻ t, + F (rawReturnInputSignature a r,rawCycleWordSignature (a+2*(r.1+1)) w.length t) + ∂rawMarkedWordKernel (a+2*(r.1+1)) w r.2 ∂rawBranchReturnKernel a b h) = _ + rw [lintegral_congr_ae hInner, + ← lintegral_map (g := rawReturnInputSignature a) (sourceWordReward_measurable w hF) + (rawReturnInputSignature_measurable a),rawBranchReturn_input_signature a b h z hz, + lintegral_map (g := sourceCycleInputSignature z) (sourceWordReward_measurable w hF) + (sourceCycleInputSignature_measurable.comp measurable_prodMk_left)] + rfl + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/KloostermanFourthMoment.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/KloostermanFourthMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..6019366335508b13c0568fd64ffa21fac328e6e2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/KloostermanFourthMoment.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PairCollisionCount + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators ComplexConjugate + +namespace ErdosKloosterman + +attribute [local instance] Classical.decEq + +variable {F : Type*} [Field F] [Fintype F] + +private theorem fourth_expand (ψ : AddChar F ℂ) (a b : F) : + sum ψ a b * sum ψ a b * conj (sum ψ a b) * conj (sum ψ a b) = + ∑ x : (Fˣ × Fˣ) × (Fˣ × Fˣ), ψ + (a * ((x.2.1 : F) + x.2.2 - x.1.1 - x.1.2) + + b * ((↑x.2.1⁻¹ : F) + ↑x.2.2⁻¹ - ↑x.1.1⁻¹ - ↑x.1.2⁻¹)) := by + simp only [sum, map_sum, Finset.sum_mul, Finset.mul_sum, Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro u _ + apply Finset.sum_congr rfl + intro v _ + apply Finset.sum_congr rfl + intro z _ + apply Finset.sum_congr rfl + intro w _ + rw [← AddChar.map_neg_eq_conj, ← AddChar.map_neg_eq_conj, + ← AddChar.map_add_eq_mul, ← AddChar.map_add_eq_mul, ← AddChar.map_add_eq_mul] + congr 1 + ring + +private theorem two_frequency_orthogonality (ψ : AddChar F ℂ) + (hψ : ψ.IsPrimitive) (x y : F) : + (∑ a : F, ∑ b : F, ψ (a*x + b*y)) = + if x = 0 ∧ y = 0 then (Fintype.card F : ℂ)^2 else 0 := by + simp_rw [AddChar.map_add_eq_mul, ← Finset.mul_sum, + AddChar.sum_mulShift _ hψ, ← Finset.sum_mul, AddChar.sum_mulShift _ hψ] + split_ifs <;> simp_all [pow_two] + +theorem fourth_moment_identity (ψ : AddChar F ℂ) (hψ : ψ.IsPrimitive) : + (∑ a : F, ∑ b : F, + sum ψ a b * sum ψ a b * conj (sum ψ a b) * conj (sum ψ a b)) = + (Fintype.card F : ℂ)^2 * (pairCollisions F).card := by + simp_rw [fourth_expand] + conv_lhs => + arg 2 + ext a + rw [Finset.sum_comm] + rw [Finset.sum_comm] + simp_rw [two_frequency_orthogonality ψ hψ] + have heq (x : (Fˣ × Fˣ) × (Fˣ × Fˣ)) : + ((x.2.1 : F) + x.2.2 - x.1.1 - x.1.2 = 0 ∧ + (↑x.2.1⁻¹ : F) + ↑x.2.2⁻¹ - ↑x.1.1⁻¹ - ↑x.1.2⁻¹ = 0) ↔ + ((x.1.1 : F) + x.1.2 = x.2.1 + x.2.2 ∧ + (↑x.1.1⁻¹ : F) + ↑x.1.2⁻¹ = ↑x.2.1⁻¹ + ↑x.2.2⁻¹) := by + simp only [sub_sub, sub_eq_zero, eq_comm] + simp_rw [heq] + rw [← Finset.sum_filter] + simp only [pairCollisions, Finset.sum_const, nsmul_eq_mul] + ring + +end ErdosKloosterman + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedBeginningKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedBeginningKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f8d44b46072f89b060e0b8dccb02422a7e4f30c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedBeginningKernel.lean @@ -0,0 +1,130 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.MarkedRenewalComparison + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw + +noncomputable def rawBeginningKernel : Kernel OddCost OddCost := + Kernel.sum (fun n : ℕ => (cycleBranchKernel false ^ n) ∘ₖ cycleBranchKernel true) + +instance rawBeginningKernel_isSFiniteKernel : IsSFiniteKernel rawBeginningKernel := by + unfold rawBeginningKernel + infer_instance + +lemma rawBeginning_ae_regeneration (z : OddCost) : ∀ᵐ y ∂rawBeginningKernel z, y ∈ returnSet := by + rw [rawBeginningKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + exact branch_word_ae_regeneration true false n z + +lemma rawBeginning_project_actual (z : OddCost) (hz : z ∈ returnSet) : + (rawBeginningKernel z).map (fun y => y.2-z.2) = actualSpacingLaw z := by + rw [rawBeginningKernel,Kernel.sum_apply, + Measure.map_sum (f := fun y : OddCost => y.2-z.2) (measurable_snd.sub measurable_const).aemeasurable,actualSpacingLaw] + apply congrArg Measure.sum + funext n + rw [actualSpacingTerm_eq n z hz,branch_word_cost_law true false n z hz, + branchCostLaw_true,branchCostLaw_false] + +lemma rawBeginning_cost_law (z : OddCost) (hz : z ∈ returnSet) : + (rawBeginningKernel z).map (fun y => y.2-z.2) = markedSpacingLaw := by + rw [rawBeginning_project_actual z hz,actualSpacingLaw_eq z hz,markedSpacingLaw_eq] + +lemma rawBeginning_mass (z : OddCost) (hz : z ∈ returnSet) : rawBeginningKernel z univ = 1 := by + have he := congrArg (fun μ : Measure ℝ => μ univ) (rawBeginning_cost_law z hz) + rw [Measure.map_apply (f := fun y : OddCost => y.2-z.2) + (measurable_snd.sub measurable_const) MeasurableSet.univ,preimage_univ] at he + exact he.trans measure_univ + +abbrev RegCost := {z : OddCost // z ∈ returnSet} + +noncomputable def beginningDomainKernel : Kernel RegCost OddCost := + rawBeginningKernel.comap Subtype.val measurable_subtype_coe + +instance beginningDomainKernel_isMarkovKernel : IsMarkovKernel beginningDomainKernel := by + constructor + intro z + constructor + rw [beginningDomainKernel,Kernel.comap_apply] + exact rawBeginning_mass z.1 z.2 + +noncomputable def markedBeginningKernel : Kernel RegCost RegCost := + beginningDomainKernel.comapRight (MeasurableEmbedding.subtype_coe returnSet_measurable) + +instance markedBeginningKernel_isMarkovKernel : IsMarkovKernel markedBeginningKernel := by + apply Kernel.IsMarkovKernel.comapRight + intro z + have hae : ∀ᵐ y ∂beginningDomainKernel z, y ∈ returnSet := by + rw [beginningDomainKernel,Kernel.comap_apply] + exact rawBeginning_ae_regeneration z.1 + have he := (ae_mem_iff_measure_eq (μ := beginningDomainKernel z) + returnSet_measurable.nullMeasurableSet).mp hae + rw [measure_univ] at he + convert! he using 1 + congr 1 + ext y + simp + +lemma markedBeginning_map_state (z : RegCost) : + (markedBeginningKernel z).map (Subtype.val : RegCost → OddCost) = rawBeginningKernel z.1 := by + calc + _ = (rawBeginningKernel z.1).restrict returnSet := by + change (((rawBeginningKernel z.1).comap (Subtype.val : RegCost → OddCost)).map Subtype.val) = _ + exact map_comap_subtype_coe (μ := rawBeginningKernel z.1) returnSet_measurable + _ = _ := Measure.restrict_eq_self_of_ae_mem (rawBeginning_ae_regeneration z.1) + +def beginningCost (z : RegCost) : ℝ := z.1.2 + +lemma beginningCost_measurable : Measurable beginningCost := + measurable_snd.comp measurable_subtype_coe + +lemma markedBeginning_increment_law (z : RegCost) : + (markedBeginningKernel z).map (fun y => beginningCost y-beginningCost z) = markedSpacingLaw := by + calc + _ = ((markedBeginningKernel z).map (Subtype.val : RegCost → OddCost)).map (fun y => y.2-z.1.2) := + (Measure.map_map (measurable_snd.sub measurable_const) measurable_subtype_coe).symm + _ = (rawBeginningKernel z.1).map (fun y => y.2-z.1.2) := by rw [markedBeginning_map_state] + _ = _ := rawBeginning_cost_law z.1 z.2 + +noncomputable def markedClockKernel : Kernel ℝ ℝ := + (Kernel.id ×ₖ Kernel.const ℝ markedSpacingLaw).map (fun x : ℝ × ℝ => x.1+x.2) + +instance markedClockKernel_isMarkovKernel : IsMarkovKernel markedClockKernel := + Kernel.IsMarkovKernel.map _ measurable_add + +lemma markedClockKernel_apply (x : ℝ) : markedClockKernel x = markedSpacingLaw.map (fun G => x+G) := by + ext B hB + rw [markedClockKernel,Kernel.map_apply' _ measurable_add _ hB, + Kernel.prod_apply' _ _ _ (measurable_add hB),Kernel.id_apply,lintegral_dirac'] + · rw [Measure.map_apply (f := fun G : ℝ => x+G) (measurable_const.add measurable_id) hB] + rfl + · exact measurable_measure_prodMk_left (measurable_add hB) + +lemma markedBeginning_cost_kernel_link : + markedBeginningKernel.map beginningCost = markedClockKernel.comap beginningCost beginningCost_measurable := by + ext z : 1 + rw [Kernel.map_apply _ beginningCost_measurable,Kernel.comap_apply,markedClockKernel_apply] + calc + _ = ((markedBeginningKernel z).map (fun y => beginningCost y-beginningCost z)).map + (fun G => beginningCost z+G) := by + rw [Measure.map_map (f := fun y : RegCost => beginningCost y-beginningCost z) + (g := fun G : ℝ => beginningCost z+G) (measurable_const.add measurable_id) + (beginningCost_measurable.sub measurable_const)] + congr 1 + funext y + simp [Function.comp_apply] + _ = _ := by rw [markedBeginning_increment_law] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedCostHitReduction.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedCostHitReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab9ebb7f1427641b3c7621ec75afd75cb2fed59b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedCostHitReduction.lean @@ -0,0 +1,457 @@ +import Mathlib.Data.List.OfFn +import OAI.NumberTheory.Jacobsthal.Paths.WindowHitWords + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess + +noncomputable def allowedCycleInputs (b : Bool) (v H : ℝ) : Set OddCost := + Prod.snd ⁻¹' allowedCycleCosts b v H + +lemma allowedCycleInputs_measurable (b : Bool) (v H : ℝ) : MeasurableSet (allowedCycleInputs b v H) := + (allowedCycleCosts_measurable b v H).preimage measurable_snd + +noncomputable def permittedCycleBranch (b : Bool) (v H : ℝ) : Kernel OddCost OddCost := + cycleBranchKernel b ∘ₖ stateFilter (allowedCycleInputs_measurable b v H) + +instance permittedCycleBranch_isFiniteKernel (b : Bool) (v H : ℝ) : IsFiniteKernel (permittedCycleBranch b v H) := by + unfold permittedCycleBranch + infer_instance + +lemma permittedCycleBranch_false (v H : ℝ) : permittedCycleBranch false v H=cycleBranchKernel false := by + ext z : 1 + rw [permittedCycleBranch,stateFilter_input] + simp [allowedCycleInputs,allowedCycleCosts] + +lemma permittedCycleBranch_true (v H : ℝ) : + permittedCycleBranch true v H=cycleBranchKernel true ∘ₖ stateFilter (ordinaryCostWindow_measurable v H).compl := rfl + +lemma permittedCycleBranch_sum (v H : ℝ) : (∑ b : Bool, permittedCycleBranch b v H)=ordinaryWindowContinue v H := by + rw [Fintype.sum_bool,permittedCycleBranch_false,permittedCycleBranch_true,ordinaryWindowContinue,add_comm] + +noncomputable def sourceHitWordKernel : List Bool → ℝ → ℝ → Kernel OddCost OddCost + | [], v, H => ordinaryWindowCapture v H + | b::w, v, H => sourceHitWordKernel w v H ∘ₖ permittedCycleBranch b v H + +instance sourceHitWordKernel_isFiniteKernel (w : List Bool) (v H : ℝ) : IsFiniteKernel (sourceHitWordKernel w v H) := by + induction w with + | nil => change IsFiniteKernel (ordinaryWindowCapture v H); infer_instance + | cons b w ih => rw [sourceHitWordKernel]; infer_instance + +lemma sourceHitWordKernel_mass (w : List Bool) (v H : ℝ) : ∀ z, + sourceHitWordMass w v H z=sourceHitWordKernel w v H z univ := by + induction w with + | nil => intro z; exact sourceHitWordMass_nil v H z + | cons b w ih => + intro z + rw [sourceHitWordMass_cons,sourceHitWordKernel,permittedCycleBranch,← Kernel.comp_assoc,stateFilter_input] + change (if z.2 ∈ allowedCycleCosts b v H then ∫⁻ y, sourceHitWordMass w v H y ∂cycleBranchKernel b z else 0) = + (if z.2 ∈ allowedCycleCosts b v H then (sourceHitWordKernel w v H ∘ₖ cycleBranchKernel b) z else 0) univ + by_cases hz : z.2 ∈ allowedCycleCosts b v H + · rw [ite_eq_left hz,ite_eq_left hz,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + exact lintegral_congr ih + · simp [hz] + +lemma kernel_comp_finset_sum_left {ι α β γ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] + (s : Finset ι) (K : ι → Kernel α β) (D : Kernel γ α) : + (∑ i ∈ s, K i) ∘ₖ D = ∑ i ∈ s, K i ∘ₖ D := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => simp only [Finset.sum_insert hi,Kernel.comp_add_left,ih] + +lemma kernel_comp_finset_sum_right {ι α β γ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] + (s : Finset ι) (K : Kernel β γ) (D : ι → Kernel α β) : + K ∘ₖ (∑ i ∈ s, D i) = ∑ i ∈ s, K ∘ₖ D i := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => simp only [Finset.sum_insert hi,Kernel.comp_add_right,ih] + +theorem sourceHitWordKernel_sum_length (v H : ℝ) (n : ℕ) : + (∑ f : Fin n → Bool, sourceHitWordKernel (List.ofFn f) v H) = + ordinaryWindowCapture v H ∘ₖ ((ordinaryWindowContinue v H)^n) := by + induction n with + | zero => + simp [List.ofFn_zero,sourceHitWordKernel] + exact (Kernel.comp_id _).symm + | succ n ih => + rw [← (Fin.consEquiv (fun _ : Fin (n+1) => Bool)).sum_comp + (fun f => sourceHitWordKernel (List.ofFn f) v H)] + simp only [Fintype.sum_prod_type] + change (∑ b : Bool, ∑ f : Fin n → Bool, sourceHitWordKernel (List.ofFn (Fin.cons b f)) v H) = _ + simp_rw [List.ofFn_cons,sourceHitWordKernel] + simp_rw [← kernel_comp_finset_sum_left,ih] + rw [← kernel_comp_finset_sum_right,permittedCycleBranch_sum,pow_succ] + exact Kernel.comp_assoc _ _ _ + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.PairedCostGrouping +open NumberTheoryLean.KernelPotential + +abbrev RawMarkedHitTrace (a : ℕ) := + Σ n : ℕ, Σ f : Fin n → Bool, RawCycleWordTrace a (List.ofFn f++[true]).length + +def packRawMarkedHitTrace (a n : ℕ) (f : Fin n → Bool) + (t : RawCycleWordTrace a (List.ofFn f++[true]).length) : RawMarkedHitTrace a := + @Sigma.mk ℕ (fun m => Σ g : Fin m → Bool, RawCycleWordTrace a (List.ofFn g++[true]).length) n + (@Sigma.mk (Fin n → Bool) (fun g => RawCycleWordTrace a (List.ofFn g++[true]).length) f t) + +lemma packRawMarkedHitTrace_measurable (a n : ℕ) (f : Fin n → Bool) : + Measurable (packRawMarkedHitTrace a n f) := + (measurableSigmaMk (X := fun m : ℕ => Σ g : Fin m → Bool, RawCycleWordTrace a (List.ofFn g++[true]).length) n).comp + (measurableSigmaMk (X := fun g : Fin n → Bool => RawCycleWordTrace a (List.ofFn g++[true]).length) f) + +noncomputable def rawMarkedFirstHitKernel (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawMarkedHitTrace a) := + Kernel.sum (fun n : ℕ => Kernel.sum (fun f : Fin n → Bool => + (rawHitWordKernel a (List.ofFn f) v H).map (packRawMarkedHitTrace a n f))) + +instance rawMarkedFirstHitKernel_isSFiniteKernel (a : ℕ) (v H : ℝ) : IsSFiniteKernel (rawMarkedFirstHitKernel a v H) := by + unfold rawMarkedFirstHitKernel + infer_instance + +theorem rawMarkedFirstHit_mass (a : ℕ) (v H : ℝ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + rawMarkedFirstHitKernel a v H h univ=ordinaryMarkedHit v H z univ := by + rw [rawMarkedFirstHitKernel,Kernel.sum_apply' _ _ MeasurableSet.univ, + ordinaryMarkedHit,potential,Kernel.sum_apply' _ _ MeasurableSet.univ] + apply tsum_congr + intro n + rw [Kernel.sum_apply' _ _ MeasurableSet.univ] + calc + _ = ∑' f : Fin n → Bool, sourceHitWordKernel (List.ofFn f) v H z univ := by + apply tsum_congr + intro f + rw [Kernel.map_apply' _ (packRawMarkedHitTrace_measurable a n f) _ MeasurableSet.univ, + preimage_univ,rawHitWord_mass a (List.ofFn f) v H h z hz,sourceHitWordKernel_mass] + _ = (∑ f : Fin n → Bool, sourceHitWordKernel (List.ofFn f) v H) z univ := by + rw [tsum_fintype,Kernel.finsetSum_apply'] + _ = _ := by rw [sourceHitWordKernel_sum_length] + +noncomputable def rawMarkedHitEvent (a : ℕ) (v H : ℝ) : Set (RawMarkedHitTrace a) := + {r | rawCycleWordSignature a (List.ofFn r.2.1++[true]).length r.2.2 ∈ hitWordEvent (List.ofFn r.2.1) v H} + +lemma rawMarkedHitEvent_measurable (a : ℕ) (v H : ℝ) : MeasurableSet (rawMarkedHitEvent a v H) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + apply MeasurableSpace.measurableSet_iInf.mpr + intro f + exact (hitWordEvent_measurable (List.ofFn f) v H).preimage (rawCycleWordSignature_measurable _ a) + +theorem rawMarkedFirstHit_ae_event (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ r ∂rawMarkedFirstHitKernel a v H h, r ∈ rawMarkedHitEvent a v H := by + rw [rawMarkedFirstHitKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.sum_apply,Measure.ae_sum_iff] + intro f + rw [Kernel.map_apply _ (packRawMarkedHitTrace_measurable a n f)] + apply (ae_map_iff (packRawMarkedHitTrace_measurable a n f).aemeasurable (rawMarkedHitEvent_measurable a v H)).mpr + rw [rawHitWordKernel,Kernel.restrict_apply] + exact ae_restrict_mem ((hitWordEvent_measurable (List.ofFn f) v H).preimage (rawCycleWordSignature_measurable _ a)) + +noncomputable def rawRegMarkedFirstHitKernel (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawMarkedHitTrace a) := + rawMarkedFirstHitKernel a v H ∘ₖ stateFilter (lastRegeneration_measurable a) + +lemma rawRegMarkedFirstHit_mass_le_one (a : ℕ) (v H : ℝ) (h : RawHistory a) : + rawRegMarkedFirstHitKernel a v H h univ ≤ 1 := by + rw [rawRegMarkedFirstHitKernel,stateFilter_input] + by_cases hReg : h ∈ lastRegeneration a + · rw [ite_eq_left hReg] + let z := decodeReturnedOdd (rawLast a h) + have hz : rawLast a h=embedOdd z := (embed_decodeReturnedOdd_of_regeneration _ hReg).symm + rw [rawMarkedFirstHit_mass a v H h z hz] + exact ordinaryMarkedHit_mass_le_one v H z + · simp [hReg] + +instance rawRegMarkedFirstHitKernel_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (rawRegMarkedFirstHitKernel a v H) := + ⟨⟨1,by simp,rawRegMarkedFirstHit_mass_le_one a v H⟩⟩ + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.KernelPotential + +variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + +lemma kernel_power_sfinite (K : Kernel α α) [IsSFiniteKernel K] (n : ℕ) : IsSFiniteKernel (K^n) := by + induction n with + | zero => change IsSFiniteKernel (Kernel.id : Kernel α α); infer_instance + | succ n ih => rw [pow_succ']; change IsSFiniteKernel (K ∘ₖ (K^n)); infer_instance + +lemma kernel_power_support (K : Kernel α α) [IsSFiniteKernel K] {S : Set α} (hS : MeasurableSet S) + (hK : ∀ x, ∀ᵐ y ∂K x, y ∈ S) (n : ℕ) (x : α) (hx : x ∈ S) : + ∀ᵐ y ∂(K^n) x, y ∈ S := by + have (m : ℕ) : IsSFiniteKernel (K^m) := kernel_power_sfinite K m + cases n with + | zero => change ∀ᵐ y ∂Measure.dirac x, y ∈ S; exact (ae_dirac_iff hS).mpr hx + | succ n => + rw [pow_succ'] + change ∀ᵐ y ∂(K ∘ₖ (K^n)) x, y ∈ S + exact Kernel.ae_comp_of_ae_ae hS (Eventually.of_forall hK) + +lemma supported_projection_power (K : Kernel α α) (L : Kernel β β) [IsSFiniteKernel K] [IsSFiniteKernel L] + {S : Set α} (_hS : MeasurableSet S) (hSupp : ∀ x, ∀ᵐ y ∂K x, y ∈ S) + {f : α → β} (hf : Measurable f) (hKL : ∀ x ∈ S, (K x).map f=L (f x)) + (n : ℕ) (x : α) (hx : x ∈ S) : ((K^n) x).map f=(L^n) (f x) := by + have (m : ℕ) : IsSFiniteKernel (K^m) := kernel_power_sfinite K m + have (m : ℕ) : IsSFiniteKernel (L^m) := kernel_power_sfinite L m + induction n generalizing x with + | zero => change (Measure.dirac x).map f=Measure.dirac (f x); exact Measure.map_dirac' hf x + | succ n ih => + apply Measure.ext_of_lintegral + intro F hF + have hp : K^(n+1)=(K^n) ∘ₖ K := pow_succ _ _ + have hq : L^(n+1)=(L^n) ∘ₖ L := pow_succ _ _ + rw [lintegral_map hF hf,hp,hq,Kernel.lintegral_comp _ _ _ (g := fun z => F (f z)) (hF.comp hf), + Kernel.lintegral_comp _ _ _ hF] + have he : (fun y => ∫⁻ z, F (f z) ∂(K^n) y) =ᵐ[K x] fun y => ∫⁻ z, F z ∂(L^n) (f y) := by + filter_upwards [hSupp x] with y hy + rw [← lintegral_map (g := f) hF hf,ih y hy] + rw [lintegral_congr_ae he] + have hJ : Measurable (fun y : β => ∫⁻ z, F z ∂(L^n) y) := hF.lintegral_kernel + rw [← lintegral_map (g := f) hJ hf,hKL x hx] + +lemma supported_projection_potential (K B : Kernel α α) (L C : Kernel β β) + [IsSFiniteKernel K] [IsSFiniteKernel B] [IsSFiniteKernel L] [IsSFiniteKernel C] + {S : Set α} (hS : MeasurableSet S) (hSupp : ∀ x, ∀ᵐ y ∂K x, y ∈ S) + {f : α → β} (hf : Measurable f) (hKL : ∀ x ∈ S, (K x).map f=L (f x)) + (hBC : ∀ x ∈ S, (B x).map f=C (f x)) (x : α) (hx : x ∈ S) : + (potential B K x).map f=potential C L (f x) := by + have (m : ℕ) : IsSFiniteKernel (K^m) := kernel_power_sfinite K m + have (m : ℕ) : IsSFiniteKernel (L^m) := kernel_power_sfinite L m + rw [potential,Kernel.sum_apply,Measure.map_sum (f := f) hf.aemeasurable,potential,Kernel.sum_apply] + apply congrArg Measure.sum + funext n + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF hf,Kernel.lintegral_comp _ _ _ (g := fun z => F (f z)) (hF.comp hf), + Kernel.lintegral_comp _ _ _ hF] + have he : (fun y => ∫⁻ z, F (f z) ∂B y) =ᵐ[(K^n) x] fun y => ∫⁻ z, F z ∂C (f y) := by + filter_upwards [kernel_power_support K hS hSupp n x hx] with y hy + rw [← lintegral_map (g := f) hF hf,hBC y hy] + rw [lintegral_congr_ae he] + have hJ : Measurable (fun y : β => ∫⁻ z, F z ∂C y) := hF.lintegral_kernel + rw [← lintegral_map (g := f) hJ hf,supported_projection_power K L hS hSupp hf hKL n x hx] + +noncomputable def kernelScale (p : ℝ≥0∞) (B : Kernel α β) [IsSFiniteKernel B] : Kernel α β := + B.withDensity (fun _ _ => p) + +lemma kernelScale_apply (p : ℝ≥0∞) (B : Kernel α β) [IsSFiniteKernel B] (x : α) : + kernelScale p B x=p • B x := by + rw [kernelScale,Kernel.withDensity_apply _ (f := fun _ _ => p) measurable_const,withDensity_const] + +lemma kernelScale_isSFinite (p : ℝ≥0∞) (hp : p ≠ ∞) (B : Kernel α β) [IsSFiniteKernel B] : + IsSFiniteKernel (kernelScale p B) := Kernel.IsSFiniteKernel.withDensity B (fun _ _ => hp) + +lemma potential_scale_base (p : ℝ≥0∞) (hp : p ≠ ∞) (B : Kernel α β) (K : Kernel α α) + [IsSFiniteKernel B] [IsSFiniteKernel K] (x : α) : + potential (kernelScale p B) K x=p • potential B K x := by + have : IsSFiniteKernel (kernelScale p B) := kernelScale_isSFinite p hp B + have (n : ℕ) : IsSFiniteKernel (K^n) := kernel_power_sfinite K n + ext S hS + rw [potential,Kernel.sum_apply' _ _ hS,Measure.smul_apply,smul_eq_mul, + potential,Kernel.sum_apply' _ _ hS,← ENNReal.tsum_mul_left] + apply tsum_congr + intro n + rw [Kernel.comp_apply' _ _ _ hS,Kernel.comp_apply' _ _ _ hS] + simp_rw [kernelScale_apply,Measure.smul_apply,smul_eq_mul] + exact lintegral_const_mul' _ _ hp + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.KernelPotential + +noncomputable def costWindowFilter (v H : ℝ) : Kernel ℝ ℝ := + stateFilter (S := Icc v (v+H)) measurableSet_Icc + +noncomputable def costOutsideFilter (v H : ℝ) : Kernel ℝ ℝ := + stateFilter (S := (Icc v (v+H))ᶜ) measurableSet_Icc.compl + +instance costWindowFilter_isFiniteKernel (v H : ℝ) : IsFiniteKernel (costWindowFilter v H) := by + unfold costWindowFilter + infer_instance +instance costOutsideFilter_isFiniteKernel (v H : ℝ) : IsFiniteKernel (costOutsideFilter v H) := by + unfold costOutsideFilter + infer_instance + +noncomputable def costMarkedLoop (v H : ℝ) : Kernel ℝ ℝ := markedClockKernel ∘ₖ costOutsideFilter v H +instance costMarkedLoop_isFiniteKernel (v H : ℝ) : IsFiniteKernel (costMarkedLoop v H) := by + unfold costMarkedLoop + infer_instance + +noncomputable def costCurrentHit (v H : ℝ) : Kernel ℝ ℝ := + potential (costWindowFilter v H) (costMarkedLoop v H) +instance costCurrentHit_isSFiniteKernel (v H : ℝ) : IsSFiniteKernel (costCurrentHit v H) := by + unfold costCurrentHit + infer_instance + +instance costWindow_stopping_isMarkov (v H : ℝ) : IsMarkovKernel (costWindowFilter v H+costMarkedLoop v H) := by + unfold costWindowFilter costMarkedLoop costOutsideFilter + infer_instance + +lemma costCurrentHit_mass_le_one (v H T : ℝ) : costCurrentHit v H T univ ≤ 1 := + capturePotential_mass_le_one _ _ T + +noncomputable def ordinaryMarkedLoop (v H : ℝ) : Kernel OddCost OddCost := + rawBeginningKernel ∘ₖ stateFilter (ordinaryCostWindow_measurable v H).compl +instance ordinaryMarkedLoop_isSFiniteKernel (v H : ℝ) : IsSFiniteKernel (ordinaryMarkedLoop v H) := by + unfold ordinaryMarkedLoop + infer_instance + +lemma rawBeginning_total_cost (z : OddCost) (hz : z ∈ returnSet) : + (rawBeginningKernel z).map Prod.snd=markedClockKernel z.2 := by + rw [markedClockKernel_apply] + calc + _ = ((rawBeginningKernel z).map (fun y => y.2-z.2)).map (fun G : ℝ => z.2+G) := by + rw [Measure.map_map (g := fun G : ℝ => z.2+G) (f := fun y : OddCost => y.2-z.2) + (measurable_const.add measurable_id) (measurable_snd.sub measurable_const)] + congr 1 + funext y + simp only [Function.comp_def,add_sub_cancel] + _ = _ := by rw [rawBeginning_cost_law z hz] + +lemma ordinaryMarkedLoop_support (v H : ℝ) (z : OddCost) : + ∀ᵐ y ∂ordinaryMarkedLoop v H z, y ∈ returnSet := by + rw [ordinaryMarkedLoop,stateFilter_input] + split_ifs + · exact rawBeginning_ae_regeneration z + · simp + +lemma ordinaryMarkedLoop_cost (v H : ℝ) (z : OddCost) (hz : z ∈ returnSet) : + (ordinaryMarkedLoop v H z).map Prod.snd=costMarkedLoop v H z.2 := by + rw [ordinaryMarkedLoop,costMarkedLoop,costOutsideFilter,stateFilter_input,stateFilter_input] + by_cases h : z.2 ∈ Icc v (v+H) + · rw [ite_eq_right (show z ∉ (ordinaryCostWindow v H)ᶜ from fun hn => hn h), + ite_eq_right (show z.2 ∉ (Icc v (v+H))ᶜ from fun hn => hn h),Measure.map_zero] + · rw [ite_eq_left (show z ∈ (ordinaryCostWindow v H)ᶜ from h), + ite_eq_left (show z.2 ∈ (Icc v (v+H))ᶜ from h)] + exact rawBeginning_total_cost z hz + +lemma cost_filter_projection (v H : ℝ) (z : OddCost) : + (stateFilter (ordinaryCostWindow_measurable v H) z).map Prod.snd=costWindowFilter v H z.2 := by + rw [stateFilter,costWindowFilter,stateFilter,Kernel.restrict_apply,Kernel.restrict_apply,Kernel.id_apply,Kernel.id_apply] + change ((Measure.dirac z).restrict (Prod.snd ⁻¹' Icc v (v+H))).map Prod.snd = + (Measure.dirac z.2).restrict (Icc v (v+H)) + rw [← Measure.restrict_map measurable_snd measurableSet_Icc,Measure.map_dirac' measurable_snd] + +lemma ordinaryWindowCapture_on_regeneration (v H : ℝ) (z : OddCost) (hz : z ∈ returnSet) : + ordinaryWindowCapture v H z=markProbability • stateFilter (ordinaryCostWindow_measurable v H) z := by + have hp : nextMarkWeight z=markProbability := cycleBranch_true_mass z hz + rw [ordinaryWindowCapture,Kernel.restrict_apply,markInputWeightKernel_apply,hp,Measure.restrict_smul] + rfl + +lemma ordinaryWindowCapture_cost (v H : ℝ) (z : OddCost) (hz : z ∈ returnSet) : + (ordinaryWindowCapture v H z).map Prod.snd=kernelScale markProbability (costWindowFilter v H) z.2 := by + rw [ordinaryWindowCapture_on_regeneration v H z hz,Measure.map_smul _ measurable_snd.aemeasurable,cost_filter_projection,kernelScale_apply] + +theorem ordinaryMarkedPotential_cost (v H : ℝ) (z : OddCost) (hz : z ∈ returnSet) : + (potential (ordinaryWindowCapture v H) (ordinaryMarkedLoop v H) z).map Prod.snd = + markProbability • costCurrentHit v H z.2 := by + have : IsSFiniteKernel (kernelScale markProbability (costWindowFilter v H)) := + kernelScale_isSFinite markProbability markProbability_ne_top _ + rw [supported_projection_potential (ordinaryMarkedLoop v H) (ordinaryWindowCapture v H) + (costMarkedLoop v H) (kernelScale markProbability (costWindowFilter v H)) + returnSet_measurable (ordinaryMarkedLoop_support v H) measurable_snd + (ordinaryMarkedLoop_cost v H) (ordinaryWindowCapture_cost v H) z hz, + potential_scale_base markProbability markProbability_ne_top] + rfl + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.InitialRegeneration NumberTheoryLean.TransitionKernels +open NumberTheoryLean.KernelPotential + +lemma unmarkedStar_support (z : OddCost) (hz : z ∈ returnSet) : + ∀ᵐ y ∂unmarkedStar z, y ∈ returnSet := by + rw [unmarkedStar,potential,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.id_comp] + exact cycleBranch_pow_ae_regeneration false n z hz + +lemma ordinaryMarkedPotential_mass (v H : ℝ) (z : OddCost) (hz : z ∈ returnSet) : + potential (ordinaryWindowCapture v H) (ordinaryMarkedLoop v H) z univ = + markProbability*costCurrentHit v H z.2 univ := by + have he := congrArg (fun μ : Measure ℝ => μ univ) (ordinaryMarkedPotential_cost v H z hz) + rw [Measure.map_apply measurable_snd MeasurableSet.univ,preimage_univ,Measure.smul_apply,smul_eq_mul] at he + exact he + +theorem ordinaryMarkedHit_first_mark_reduction (v H : ℝ) (z : OddCost) (hz : z ∈ returnSet) : + ordinaryMarkedHit v H z univ = + ∫⁻ y, costCurrentHit v H y.2 univ ∂rawFirstMarkedBeginning z := by + have hQ : Measurable (fun y : OddCost => costCurrentHit v H y.2 univ) := + ((costCurrentHit v H).measurable_coe MeasurableSet.univ).comp measurable_snd + rw [ordinaryMarkedHit_denested,Kernel.comp_apply' _ _ _ MeasurableSet.univ, + rawFirstMarkedBeginning,Kernel.withDensity_apply _ (f := fun _ y : OddCost => nextMarkWeight y) + (nextMarkWeight_measurable.comp measurable_snd), + lintegral_withDensity_eq_lintegral_mul _ nextMarkWeight_measurable hQ] + change (∫⁻ y, potential (ordinaryWindowCapture v H) (ordinaryMarkedLoop v H) y univ ∂unmarkedStar z) = + ∫⁻ y, nextMarkWeight y*costCurrentHit v H y.2 univ ∂unmarkedStar z + apply lintegral_congr_ae + filter_upwards [unmarkedStar_support z hz] with y hy + rw [ordinaryMarkedPotential_mass v H y hy] + have hp : nextMarkWeight y=markProbability := cycleBranch_true_mass y hy + rw [hp] + +noncomputable def ordinaryInitialHitMass (s : EvenState) (v H : ℝ) : ℝ≥0∞ := + ∫⁻ z, ordinaryMarkedHit v H z univ ∂delayedRegeneration s + +lemma ordinaryInitialHitMass_le_one (s : EvenState) (v H : ℝ) : ordinaryInitialHitMass s v H ≤ 1 := by + calc + _ ≤ ∫⁻ _z, (1:ℝ≥0∞) ∂delayedRegeneration s := lintegral_mono (ordinaryMarkedHit_mass_le_one v H) + _ = 1 := by simp + +theorem ordinaryInitialHit_cost_law (s : EvenState) (v H : ℝ) : + ordinaryInitialHitMass s v H = ∫⁻ T, costCurrentHit v H T univ ∂initialMarkedCostLaw s := by + have hQ : Measurable (fun y : OddCost => costCurrentHit v H y.2 univ) := + ((costCurrentHit v H).measurable_coe MeasurableSet.univ).comp measurable_snd + rw [ordinaryInitialHitMass,initialMarkedCostLaw, + lintegral_map ((costCurrentHit v H).measurable_coe MeasurableSet.univ) measurable_snd, + initialMarkedBeginning,Kernel.lintegral_comp _ _ _ hQ] + apply lintegral_congr_ae + filter_upwards [delayedRegeneration_ae_regeneration s] with z hz + exact ordinaryMarkedHit_first_mark_reduction v H z hz + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedCostSublaws.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedCostSublaws.lean new file mode 100644 index 0000000000000000000000000000000000000000..84adaed1a3cbc346f8e5a125936882b246a6ae61 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedCostSublaws.lean @@ -0,0 +1,98 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.MarkedCycleCompletion + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.RegenerationTails NumberTheoryLean.CycleCostLower +open NumberTheoryLean.CycleCostMoments + +noncomputable def sourceCycleLaw : Measure MarkedOddCost := completedMarkedKernel (regenerationState,0) + +instance sourceCycleLaw_isProbabilityMeasure : IsProbabilityMeasure sourceCycleLaw := by + unfold sourceCycleLaw + infer_instance + +def sourceMarkSet : Set MarkedOddCost := {z | z.1=true} + +lemma sourceMarkSet_measurable : MeasurableSet sourceMarkSet := + measurable_fst (measurableSet_singleton true) + +def sourceCostProjection (z : MarkedOddCost) : ℝ := z.2.2 + +lemma sourceCostProjection_measurable : Measurable sourceCostProjection := + measurable_snd.comp measurable_snd + +lemma sourceCycle_cost_projection : sourceCycleLaw.map sourceCostProjection = cycleCostLaw := by + rw [cycleCostLaw,← completedMarked_forget (regenerationState,0), + Measure.map_map measurable_snd measurable_snd] + rfl + +lemma sourceCycle_mark_mass : sourceCycleLaw sourceMarkSet = markProbability := + completedMarked_mark_mass regenerationState (by norm_num [regenerationState]) 0 + +noncomputable def markedCostLaw : Measure ℝ := + (sourceCycleLaw.restrict sourceMarkSet).map sourceCostProjection + +noncomputable def unmarkedCostLaw : Measure ℝ := + (sourceCycleLaw.restrict sourceMarkSetᶜ).map sourceCostProjection + +instance markedCostLaw_isFiniteMeasure : IsFiniteMeasure markedCostLaw := by + unfold markedCostLaw + infer_instance + +instance unmarkedCostLaw_isFiniteMeasure : IsFiniteMeasure unmarkedCostLaw := by + unfold unmarkedCostLaw + infer_instance + +lemma markedCostLaw_add_unmarked : markedCostLaw+unmarkedCostLaw = cycleCostLaw := by + calc + _ = (sourceCycleLaw.restrict sourceMarkSet+sourceCycleLaw.restrict sourceMarkSetᶜ).map sourceCostProjection := + (Measure.map_add _ _ sourceCostProjection_measurable).symm + _ = sourceCycleLaw.map sourceCostProjection := by rw [Measure.restrict_add_restrict_compl sourceMarkSet_measurable] + _ = _ := sourceCycle_cost_projection + +lemma markedCostLaw_mass : markedCostLaw univ = markProbability := by + rw [markedCostLaw,Measure.map_apply sourceCostProjection_measurable MeasurableSet.univ, + preimage_univ,Measure.restrict_apply MeasurableSet.univ,univ_inter] + exact sourceCycle_mark_mass + +lemma unmarkedCostLaw_mass : unmarkedCostLaw univ = 1-markProbability := by + rw [unmarkedCostLaw,Measure.map_apply sourceCostProjection_measurable MeasurableSet.univ, + preimage_univ,Measure.restrict_apply MeasurableSet.univ,univ_inter, + measure_compl sourceMarkSet_measurable (measure_ne_top _ _),measure_univ,sourceCycle_mark_mass] + +lemma markedCostLaw_le : markedCostLaw ≤ cycleCostLaw := by + rw [← markedCostLaw_add_unmarked] + exact Measure.le_add_right le_rfl + +lemma unmarkedCostLaw_le : unmarkedCostLaw ≤ cycleCostLaw := by + rw [← markedCostLaw_add_unmarked] + exact Measure.le_add_left le_rfl + +lemma source_marked_cost_lower : ∀ᵐ G ∂markedCostLaw, Real.log (4/3) ≤ G := + (ae_mono markedCostLaw_le) cycleCostLaw_lower + +lemma source_unmarked_cost_lower : ∀ᵐ G ∂unmarkedCostLaw, Real.log (4/3) ≤ G := + (ae_mono unmarkedCostLaw_le) cycleCostLaw_lower + +lemma source_marked_exponential_moments : ∃ eta : ℝ, 0 < eta ∧ + (∫⁻ G, ENNReal.ofReal (Real.exp (eta*G)) ∂markedCostLaw) < ∞ ∧ + (∫⁻ G, ENNReal.ofReal (Real.exp (eta*G)) ∂unmarkedCostLaw) < ∞ := by + obtain ⟨eta,heta,hfin⟩ := cycle_cost_exponential_moment + exact ⟨eta,heta,(lintegral_mono' markedCostLaw_le le_rfl).trans_lt hfin, + (lintegral_mono' unmarkedCostLaw_le le_rfl).trans_lt hfin⟩ + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedOccurrenceProbability.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedOccurrenceProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..6505914b5c4ee30098a4343fe2038754dab5cade --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedOccurrenceProbability.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CanonicalBadCompact +import OAI.NumberTheory.Jacobsthal.Analysis.SourceBadCompactOccurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.MarkedOccurrenceProbability + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualCoupledHistories ActualSuccessfulHistories ActualProcessCoupling FlaggedSourceStart +open FiniteHistoryTransport PriorPrimeWindow CompactPrefixOccurrence CompletedMarkEvents +open SourceBadCompactOccurrence CanonicalBadCompact ContinuousKilledBins PersistentFailureFlag +open Erdos970Dependency.MarkedVisits + +variable {w ell S R b₀ b₁ : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem missing_occurrence_probability (hc : Consistent start) + (hb₀ : 0 < b₀) (hb₁ : 0 < b₁) (hR : (11/10)*R < 6*b₀) + {mesh : ℝ} (hm : 0 < mesh) (hmesh : mesh ≤ 1/100) (N : ℕ) + (herror : 4*(N:ℝ)*mesh ≤ Real.log (11/10)) (E : Set (List ℕ)) + (hE : ∀ p : History w ell S start,p.primes ∈ E → + p.node.gap ≤ R ∧ ¬hasPrimeWindow w b₀ b₁ start p.primes) : + sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N {h | occurs E N h} ≤ + sourceLaw hw hell hS0 hS hr hs hsS mesh N failed + + finitePathMeasure (typedState start.side start.ratio hs) N + (closedNoHitEvent 1 N start.gap b₀ b₁ 1) := by + let μ := sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N + let F : Set (Hist (FlagState (JointState w ell S start)) N) := {h | (last N h).2 = true} + let C : Set (Hist (FlagState (JointState w ell S start)) N) := + mapHist (fun q => q.1.2) N ⁻¹' badCompactPath (Real.log start.gap) ((11/10)*R) b₀ b₁ N + have hF : μ F = sourceLaw hw hell hS0 hS hr hs hsS mesh N failed := + sourceHistory_failure_probability hw hell hS0 hS hr hs hsS mesh N + have hC : μ C ≤ finitePathMeasure (typedState start.side start.ratio hs) N + (closedNoHitEvent 1 N start.gap b₀ b₁ 1) := by + dsimp [μ,C] + rw [← Measure.map_apply + (by exact mapHist_measurable (by exact measurable_snd.comp measurable_fst) N) + (badCompactPath_measurable _ _ _ _ _),sourceHistoryLaw_continuous] + exact completed_bad_compact_mass hr hb₀ hb₁ hR ell S (typedState start.side start.ratio hs) N + calc + _ ≤ μ (F ∪ C) := measure_mono_ae + (missing_occurrence_inclusion hw hell hS0 hS hr hs hsS hc hb₀ hm hmesh N herror E hE) + _ ≤ μ F + μ C := measure_union_le F C + _ ≤ _ := by rw [hF]; exact add_le_add le_rfl hC + +end NumberTheoryLean.MarkedOccurrenceProbability + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedReturnKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedReturnKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..05e739f5dd34838362260097190ceb1302803ae4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedReturnKernel.lean @@ -0,0 +1,222 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.MarkedCycleWords + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open AbsorptionCutoff.Renewal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.RegenerationTails + +noncomputable def nextMarkWeight (z : OddCost) : ℝ≥0∞ := cycleBranchKernel true z univ + +lemma nextMarkWeight_measurable : Measurable nextMarkWeight := + (cycleBranchKernel true).measurable_coe MeasurableSet.univ + +lemma markProbability_ne_top : markProbability ≠ ∞ := + (lt_trans markProbability_lt_one (by simp)).ne + +noncomputable def actualWaitingTerm (n : ℕ) (z : OddCost) : Measure ℝ := + (((cycleBranchKernel false ^ n) z).withDensity nextMarkWeight).map (fun y => y.2-z.2) + +noncomputable def actualSpacingTerm (n : ℕ) (z : OddCost) : Measure ℝ := + markProbability⁻¹ • + ((((cycleBranchKernel false ^ n) ∘ₖ cycleBranchKernel true) z).withDensity nextMarkWeight).map + (fun y => y.2-z.2) + +lemma actualWaitingTerm_eq (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + actualWaitingTerm n z = markProbability • convPow unmarkedCostLaw n := by + have hw : nextMarkWeight =ᵐ[(cycleBranchKernel false ^ n) z] fun _ => markProbability := by + filter_upwards [cycleBranch_pow_ae_regeneration false n z hz] with y hy + exact cycleBranch_true_mass y hy + have hmap : Measurable (fun y : OddCost => y.2-z.2) := measurable_snd.sub measurable_const + rw [actualWaitingTerm,withDensity_congr_ae hw,withDensity_const,Measure.map_smul _ hmap.aemeasurable, + branch_cumulative_cost_law false n z hz,branchCostLaw_false] + +lemma actualSpacingTerm_eq (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + actualSpacingTerm n z = markedCostLaw ∗ convPow unmarkedCostLaw n := by + have hw : nextMarkWeight =ᵐ[((cycleBranchKernel false ^ n) ∘ₖ cycleBranchKernel true) z] + fun _ => markProbability := by + filter_upwards [branch_word_ae_regeneration true false n z] with y hy + exact cycleBranch_true_mass y hy + have hmap : Measurable (fun y : OddCost => y.2-z.2) := measurable_snd.sub measurable_const + rw [actualSpacingTerm,withDensity_congr_ae hw,withDensity_const,Measure.map_smul _ hmap.aemeasurable,smul_smul, + ENNReal.inv_mul_cancel markProbability_pos.ne' markProbability_ne_top,one_smul, + branch_word_cost_law true false n z hz,branchCostLaw_true,branchCostLaw_false] + +noncomputable def actualWaitingLaw (z : OddCost) : Measure ℝ := Measure.sum (fun n => actualWaitingTerm n z) +noncomputable def actualSpacingLaw (z : OddCost) : Measure ℝ := Measure.sum (fun n => actualSpacingTerm n z) + +lemma conv_sum_right (μ : Measure ℝ) (ν : ℕ → Measure ℝ) [∀ n, SFinite (ν n)] : + μ ∗ Measure.sum ν = Measure.sum (fun n => μ ∗ ν n) := by + unfold Measure.conv + rw [Measure.prod_sum_right,Measure.map_sum measurable_add.aemeasurable] + +lemma actualWaitingLaw_eq (z : OddCost) (hz : z ∈ returnSet) : + actualWaitingLaw z = markProbability • unmarkedPotential := by + ext B hB + rw [actualWaitingLaw,Measure.sum_apply _ hB] + simp_rw [actualWaitingTerm_eq _ z hz,Measure.smul_apply,smul_eq_mul] + rw [unmarkedPotential,renewalMeasure,Measure.sum_apply _ hB,ENNReal.tsum_mul_left] + +lemma actualSpacingLaw_eq (z : OddCost) (hz : z ∈ returnSet) : + actualSpacingLaw z = geometricMarkedCostLaw := by + rw [actualSpacingLaw,geometricMarkedCostLaw,unmarkedPotential,renewalMeasure,conv_sum_right] + apply congrArg Measure.sum + funext n + exact actualSpacingTerm_eq n z hz + +lemma actualWaitingLaw_mass (z : OddCost) (hz : z ∈ returnSet) : actualWaitingLaw z univ = 1 := by + rw [actualWaitingLaw_eq z hz,Measure.smul_apply,smul_eq_mul,unmarkedPotential_mass] + exact ENNReal.mul_inv_cancel markProbability_pos.ne' markProbability_ne_top + +lemma actualSpacingLaw_mass (z : OddCost) (hz : z ∈ returnSet) : actualSpacingLaw z univ = 1 := by + rw [actualSpacingLaw_eq z hz] + exact measure_univ + +noncomputable def firstMarkWaitingLaw : Measure ℝ := actualWaitingLaw (regenerationState,0) +noncomputable def markedSpacingLaw : Measure ℝ := actualSpacingLaw (regenerationState,0) + +instance firstMarkWaitingLaw_isProbabilityMeasure : IsProbabilityMeasure firstMarkWaitingLaw := + ⟨actualWaitingLaw_mass _ (by norm_num [returnSet,NumberTheoryLean.PairedHitting.pairedRegeneration,regenerationState])⟩ + +instance markedSpacingLaw_isProbabilityMeasure : IsProbabilityMeasure markedSpacingLaw := + ⟨actualSpacingLaw_mass _ (by norm_num [returnSet,NumberTheoryLean.PairedHitting.pairedRegeneration,regenerationState])⟩ + +lemma markedSpacingLaw_eq : markedSpacingLaw = geometricMarkedCostLaw := + actualSpacingLaw_eq _ (by norm_num [returnSet,NumberTheoryLean.PairedHitting.pairedRegeneration,regenerationState]) + +lemma markedSpacing_exponential_moment : ∃ eta : ℝ, 0 < eta ∧ costTransform markedSpacingLaw eta < ∞ := by + rw [markedSpacingLaw_eq] + exact geometricMarked_exponential_moment + +lemma markedSpacing_cost_lower : ∀ᵐ G ∂markedSpacingLaw, Real.log (4/3) ≤ G := by + rw [markedSpacingLaw_eq] + exact geometricMarked_cost_lower + +lemma firstMarkWaiting_costTransform (eta : ℝ) : costTransform firstMarkWaitingLaw eta = + markProbability*(1-costTransform unmarkedCostLaw eta)⁻¹ := by + rw [firstMarkWaitingLaw,actualWaitingLaw_eq _ (by norm_num [returnSet,NumberTheoryLean.PairedHitting.pairedRegeneration,regenerationState])] + unfold costTransform + rw [lintegral_smul_measure] + change markProbability*costTransform unmarkedPotential eta = _ + rw [unmarkedPotential,renewal_costTransform] + rfl + +lemma marked_waiting_common_exponential_moment : ∃ eta : ℝ, 0 < eta ∧ + costTransform firstMarkWaitingLaw eta < ∞ ∧ costTransform markedSpacingLaw eta < ∞ := by + obtain ⟨eta,heta,hU,hM⟩ := exists_subcritical_unmarked_transform + have hi : (1-costTransform unmarkedCostLaw eta)⁻¹ < ∞ := + lt_top_iff_ne_top.mpr (ENNReal.inv_ne_top.mpr (tsub_pos_iff_lt.mpr hU).ne') + refine ⟨eta,heta,?_,?_⟩ + · rw [firstMarkWaiting_costTransform] + exact ENNReal.mul_lt_top (lt_top_iff_ne_top.mpr markProbability_ne_top) hi + · rw [markedSpacingLaw_eq,geometricMarked_costTransform] + exact ENNReal.mul_lt_top hM hi + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open AbsorptionCutoff.Renewal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.KernelPotential + +lemma capture_word_cost_lintegral (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y.2 ∂(cycleBranchKernel true ∘ₖ (cycleBranchKernel false ^ n)) z) = + ∫⁻ G, H (z.2+G) ∂(convPow unmarkedCostLaw n ∗ markedCostLaw) := by + rw [Kernel.lintegral_comp _ _ _ (g := fun y : OddCost => H y.2) (hH.comp measurable_snd)] + let F : ℝ → ℝ≥0∞ := fun t => ∫⁻ G, H (t+G) ∂markedCostLaw + have hF : Measurable F := (hH.comp measurable_add).lintegral_prod_right' + calc + _ = ∫⁻ y, F y.2 ∂(cycleBranchKernel false ^ n) z := by + apply lintegral_congr_ae + filter_upwards [cycleBranch_pow_ae_regeneration false n z hz] with y hy + rw [cycleBranch_cost_lintegral true y hy hH,branchCostLaw_true] + _ = ∫⁻ S, F (z.2+S) ∂convPow unmarkedCostLaw n := by + rw [branch_cumulative_cost_lintegral false n z hz hF,branchCostLaw_false] + _ = _ := by + rw [Measure.lintegral_conv (f := fun G : ℝ => H (z.2+G)) (hH.comp (measurable_const.add measurable_id))] + apply lintegral_congr + intro S + apply lintegral_congr + intro G + congr 1 + ring + +noncomputable def markedReturnKernel : Kernel OddCost OddCost := + potential (cycleBranchKernel true) (cycleBranchKernel false) + +instance markedReturnKernel_isSFiniteKernel : IsSFiniteKernel markedReturnKernel := by + unfold markedReturnKernel + infer_instance + +lemma markedReturn_cost_law (z : OddCost) (hz : z ∈ returnSet) : + (markedReturnKernel z).map (fun y => y.2-z.2) = markedSpacingLaw := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map (g := fun y : OddCost => y.2-z.2) hH (measurable_snd.sub measurable_const), + markedReturnKernel,potential,Kernel.sum_apply,lintegral_sum_measure, + markedSpacingLaw_eq,geometricMarkedCostLaw,unmarkedPotential,renewalMeasure,conv_sum_right, + lintegral_sum_measure] + apply tsum_congr + intro n + have he := capture_word_cost_lintegral n z hz (H := fun G => H (G-z.2)) + (hH.comp (measurable_id.sub measurable_const)) + rw [Measure.conv_comm] at he + simpa only [add_sub_cancel_left] using he + +lemma markedReturn_mass_of_regeneration (z : OddCost) (hz : z ∈ returnSet) : + markedReturnKernel z univ = 1 := by + have he := congrArg (fun μ : Measure ℝ => μ univ) (markedReturn_cost_law z hz) + rw [Measure.map_apply (f := fun y : OddCost => y.2-z.2) (measurable_snd.sub measurable_const) MeasurableSet.univ,preimage_univ] at he + exact he.trans measure_univ + +lemma markedReturn_unfold : markedReturnKernel = cycleBranchKernel true+ + markedReturnKernel ∘ₖ cycleBranchKernel false := potential_unfold _ _ + +instance markedReturnKernel_isMarkovKernel : IsMarkovKernel markedReturnKernel := by + constructor + intro z + constructor + rw [markedReturn_unfold,add_apply,Measure.add_apply,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + have hi : (∫⁻ y, markedReturnKernel y univ ∂cycleBranchKernel false z) = cycleBranchKernel false z univ := by + calc + _ = ∫⁻ _y, (1:ℝ≥0∞) ∂cycleBranchKernel false z := by + apply lintegral_congr_ae + filter_upwards [cycleBranch_ae_regeneration false z] with y hy + exact markedReturn_mass_of_regeneration y hy + _ = _ := lintegral_one + rw [hi] + have he := congrArg (fun K : Kernel OddCost OddCost => K z univ) cycleBranch_sum + simpa only [add_apply,Measure.add_apply,measure_univ] using he + +lemma markedReturn_ae_regeneration (z : OddCost) : ∀ᵐ y ∂markedReturnKernel z, y ∈ returnSet := by + rw [markedReturnKernel,potential,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + exact Kernel.ae_comp_of_ae_ae returnSet_measurable + (Eventually.of_forall (cycleBranch_ae_regeneration true)) + +lemma markedReturn_increment_integral (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H (y.2-z.2) ∂markedReturnKernel z) = ∫⁻ G, H G ∂markedSpacingLaw := by + rw [← markedReturn_cost_law z hz,lintegral_map (g := fun y : OddCost => y.2-z.2) hH (measurable_snd.sub measurable_const)] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedStripTotal.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedStripTotal.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0a184cc5c23c22d0ded9c97758ee4f60575a87e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedStripTotal.lean @@ -0,0 +1,177 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RegularStripBound +import OAI.NumberTheory.Jacobsthal.Estimates.SortedRealGaps + +namespace OAI + +namespace Erdos970 + +section + +open Set +namespace ErdosMarkedStrips +open ErdosImplicitCurvature ErdosLocalFiberGraphs ErdosRegularStrip ErdosConvexGraph +attribute [local instance] Classical.propDecidable + +noncomputable def polynomialSquarePoints (Q : Bivariate) (S : ℝ) : Finset (ℤ × ℤ) := + ((Finset.Icc (0 : ℤ) ⌊S⌋).product (Finset.Icc (0 : ℤ) ⌊S⌋)).filter + (fun p => peval Q p.1 p.2 = 0) + +theorem mem_polynomialSquarePoints (Q : Bivariate) (S : ℝ) (p : ℤ × ℤ) : + p ∈ polynomialSquarePoints Q S ↔ InSquare S p ∧ peval Q p.1 p.2 = 0 := by + simp only [polynomialSquarePoints,InSquare,Finset.mem_filter,Finset.product_eq_sprod, + Finset.mem_product,Finset.mem_Icc,Int.le_floor,Int.cast_nonneg_iff] + +noncomputable def markedFiberPoints (Q : Bivariate) (t S : ℝ) : Finset (ℤ × ℤ) := + (polynomialSquarePoints Q S).filter (fun p => (p.1 : ℝ) = t) + +theorem mem_markedFiberPoints (Q : Bivariate) (t S : ℝ) (p : ℤ × ℤ) : + p ∈ markedFiberPoints Q t S ↔ p ∈ polynomialSquarePoints Q S ∧ (p.1 : ℝ) = t := by + simp only [markedFiberPoints,Finset.mem_filter] + +theorem markedFiber_card_le (Q : Bivariate) (t S : ℝ) + (hp : verticalPolynomial Q t ≠ 0) : (markedFiberPoints Q t S).card ≤ Q.totalDegree := by + classical + obtain ⟨z,hz⟩ : ∃ z : ℝ, peval Q t z ≠ 0 := by + by_contra! h + apply hp + apply Polynomial.funext + intro z + rw [verticalPolynomial_eval,h z,Polynomial.eval_zero] + have hfin := boundedFiber_finite Q t 0 S z hz + have hmap : ∀ p ∈ (markedFiberPoints Q t S : Set (ℤ × ℤ)), + (p.2 : ℝ) ∈ boundedFiber Q t 0 S := by + intro p hp + have hm := (mem_markedFiberPoints Q t S p).mp hp + have hs := (mem_polynomialSquarePoints Q S p).mp hm.1 + refine ⟨hs.1.2,?_⟩ + simpa only [hm.2] using hs.2 + have hinj : InjOn (fun p : ℤ × ℤ => (p.2 : ℝ)) (markedFiberPoints Q t S : Set (ℤ × ℤ)) := by + intro p hp q hq hpq + have hp1 := ((mem_markedFiberPoints Q t S p).mp hp).2 + have hq1 := ((mem_markedFiberPoints Q t S q).mp hq).2 + apply Prod.ext + · exact_mod_cast hp1.trans hq1.symm + · change (p.2 : ℝ) = (q.2 : ℝ) at hpq + exact_mod_cast hpq + have hc := ncard_le_ncard_of_injOn (fun p : ℤ × ℤ => (p.2 : ℝ)) hmap hinj hfin + simp only [ncard_coe_finset] at hc + exact hc.trans (boundedFiber_card_le_degree Q t 0 S z hz) + +theorem square_points_partition (Q : Bivariate) (S : ℝ) (E : Finset ℝ) + (h0 : 0 ∈ E) (hS : S ∈ E) : + polynomialSquarePoints Q S = + E.biUnion (fun t => markedFiberPoints Q t S) ∪ + Finset.univ.biUnion (fun i : Fin (E.card-1) => + polynomialStripPoints Q (gapLeft E i) (gapRight E i) S) := by + classical + ext p + constructor + · intro hp + have hs := (mem_polynomialSquarePoints Q S p).mp hp + by_cases hm : (p.1 : ℝ) ∈ E + · apply Finset.mem_union_left + exact Finset.mem_biUnion.mpr ⟨p.1,hm,(mem_markedFiberPoints Q p.1 S p).mpr ⟨hp,rfl⟩⟩ + · obtain ⟨i,hi⟩ := exists_gap_of_not_mem E h0 hS hs.1.1 hm + apply Finset.mem_union_right + exact Finset.mem_biUnion.mpr ⟨i,Finset.mem_univ i, + (mem_polynomialStripPoints Q _ _ S p).mpr ⟨hs.1,hi,hs.2⟩⟩ + · intro hp + rcases Finset.mem_union.mp hp with hp | hp + · obtain ⟨t,_,ht⟩ := Finset.mem_biUnion.mp hp + exact ((mem_markedFiberPoints Q t S p).mp ht).1 + · obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp hp + have hs := (mem_polynomialStripPoints Q _ _ S p).mp hi + exact (mem_polynomialSquarePoints Q S p).mpr ⟨hs.1,hs.2.2⟩ + +end ErdosMarkedStrips + +end + +section + +open Set +namespace ErdosMarkedStrips +open ErdosImplicitCurvature ErdosLocalFiberGraphs ErdosRegularStrip ErdosConvexGraph + +def RegularOff (Q : Bivariate) (S : ℝ) (E : Finset ℝ) : Prop := + ∀ t ∉ E, (peval Q t 0 ≠ 0 ∧ peval Q t S ≠ 0) ∧ + ∀ y ∈ Icc 0 S, peval Q t y = 0 → + peval (partialX Q) t y ≠ 0 ∧ peval (partialY Q) t y ≠ 0 ∧ + peval (inflectionPolynomial Q) t y ≠ 0 + +theorem marked_square_lattice_bound (Q : Bivariate) (S : ℝ) (E : Finset ℝ) + (hS : 0 ≤ S) (h0 : 0 ∈ E) (hSE : S ∈ E) + (hfiber : ∀ t ∈ E, verticalPolynomial Q t ≠ 0) (hregular : RegularOff Q S E) : + ((polynomialSquarePoints Q S).card : ℝ) ≤ + 13*(E.card : ℝ)*(Q.totalDegree : ℝ)*(1+S^((2 : ℝ)/3)) := by + classical + let B := 1+S^((2 : ℝ)/3) + have hB : 1 ≤ B := by + dsimp [B] + exact le_add_of_nonneg_right (Real.rpow_nonneg hS _) + have hB0 : 0 ≤ B := le_trans zero_le_one hB + have hstrip (i : Fin (E.card-1)) : + ((polynomialStripPoints Q (gapLeft E i) (gapRight E i) S).card : ℝ) ≤ + 12*(Q.totalDegree : ℝ)*B := by + apply regular_strip_lattice_bound Q _ _ S hS + · exact fun t ht => (hregular t (no_mark_in_gap E i ht)).1 + · exact fun t ht => (hregular t (no_mark_in_gap E i ht)).2 + have hcount : (polynomialSquarePoints Q S).card ≤ + (∑ t ∈ E, (markedFiberPoints Q t S).card) + + ∑ i : Fin (E.card-1), (polynomialStripPoints Q (gapLeft E i) (gapRight E i) S).card := by + rw [square_points_partition Q S E h0 hSE] + exact (Finset.card_union_le _ _).trans + (Nat.add_le_add Finset.card_biUnion_le Finset.card_biUnion_le) + have hm : (∑ t ∈ E, ((markedFiberPoints Q t S).card : ℝ)) ≤ + (E.card : ℝ)*(Q.totalDegree : ℝ) := by + calc + _ ≤ ∑ _t ∈ E, (Q.totalDegree : ℝ) := Finset.sum_le_sum (fun t ht => by + exact_mod_cast markedFiber_card_le Q t S (hfiber t ht)) + _ = _ := by simp + have hg : (∑ i : Fin (E.card-1), + ((polynomialStripPoints Q (gapLeft E i) (gapRight E i) S).card : ℝ)) ≤ + (E.card : ℝ)*(12*(Q.totalDegree : ℝ)*B) := by + calc + _ ≤ ∑ _i : Fin (E.card-1), 12*(Q.totalDegree : ℝ)*B := + Finset.sum_le_sum (fun i _ => hstrip i) + _ = ((E.card-1 : ℕ) : ℝ)*(12*(Q.totalDegree : ℝ)*B) := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast Nat.sub_le E.card 1) (by positivity) + have hc : ((polynomialSquarePoints Q S).card : ℝ) ≤ + (∑ t ∈ E, ((markedFiberPoints Q t S).card : ℝ)) + + ∑ i : Fin (E.card-1), ((polynomialStripPoints Q (gapLeft E i) (gapRight E i) S).card : ℝ) := by + exact_mod_cast hcount + calc + ((polynomialSquarePoints Q S).card : ℝ) ≤ + (E.card : ℝ)*(Q.totalDegree : ℝ) + (E.card : ℝ)*(12*(Q.totalDegree : ℝ)*B) := + hc.trans (add_le_add hm hg) + _ ≤ (E.card : ℝ)*(Q.totalDegree : ℝ)*B + (E.card : ℝ)*(12*(Q.totalDegree : ℝ)*B) := by + have hscale : (E.card : ℝ)*(Q.totalDegree : ℝ) ≤ + (E.card : ℝ)*(Q.totalDegree : ℝ)*B := by + calc + _ = (E.card : ℝ)*(Q.totalDegree : ℝ)*1 := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hB (by positivity) + exact add_le_add hscale le_rfl + _ = 13*(E.card : ℝ)*(Q.totalDegree : ℝ)*(1+S^((2 : ℝ)/3)) := by dsimp [B]; ring + +theorem marked_square_cubic_bound (Q : Bivariate) (S : ℝ) (E : Finset ℝ) (C : ℕ) + (hS : 0 ≤ S) (h0 : 0 ∈ E) (hSE : S ∈ E) + (hfiber : ∀ t ∈ E, verticalPolynomial Q t ≠ 0) (hregular : RegularOff Q S E) + (hcard : E.card ≤ C*Q.totalDegree^2) : + ((polynomialSquarePoints Q S).card : ℝ) ≤ + 13*(C : ℝ)*(Q.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3)) := by + calc + ((polynomialSquarePoints Q S).card : ℝ) ≤ + 13*(E.card : ℝ)*(Q.totalDegree : ℝ)*(1+S^((2 : ℝ)/3)) := + marked_square_lattice_bound Q S E hS h0 hSE hfiber hregular + _ ≤ 13*((C : ℝ)*(Q.totalDegree : ℝ)^2)*(Q.totalDegree : ℝ)*(1+S^((2 : ℝ)/3)) := by + gcongr + exact_mod_cast hcard + _ = _ := by ring + +end ErdosMarkedStrips + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedVisitGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedVisitGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..951aa1f913bf10c8d75dd1e199ccfe94a4638792 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MarkedVisitGeometry.lean @@ -0,0 +1,485 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PairedBlockContraction + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.PairedCostProcess + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures KernelDensityBridge +open JointMinorization RegenerationTails PairedHitting + +abbrev OddCost := OddState × ℝ + +noncomputable def pairedDraws : Kernel OddState (EvenState × OddState) := + oddToEven ⊗ₖ evenToOdd.prodMkLeft OddState + +instance pairedDraws_isMarkovKernel : IsMarkovKernel pairedDraws := by unfold pairedDraws; infer_instance + +noncomputable def pairUpdate (x : OddCost × (EvenState × OddState)) : OddCost := + (x.2.2, x.1.2 + cost x.2.1.1 + cost x.2.2.1) + +theorem pairUpdate_measurable : Measurable pairUpdate := + (measurable_snd.comp measurable_snd).prodMk + (((measurable_snd.comp measurable_fst).add + (cost_measurable.comp (measurable_subtype_coe.comp (measurable_fst.comp measurable_snd)))).add + (cost_measurable.comp (measurable_subtype_coe.comp (measurable_snd.comp measurable_snd)))) + +noncomputable def pairedCostKernel : Kernel OddCost OddCost := + (Kernel.id ×ₖ pairedDraws.prodMkRight ℝ).map pairUpdate + +instance pairedCostKernel_isMarkovKernel : IsMarkovKernel pairedCostKernel := + Kernel.IsMarkovKernel.map _ pairUpdate_measurable + +theorem pairedCostKernel_apply (z : OddCost) {B : Set OddCost} (hB : MeasurableSet B) : + pairedCostKernel z B = pairedDraws z.1 {x | (x.2, z.2 + cost x.1.1 + cost x.2.1) ∈ B} := by + rw [pairedCostKernel, Kernel.map_apply' _ pairUpdate_measurable _ hB, + Kernel.prod_apply' _ _ _ (pairUpdate_measurable hB), Kernel.id_apply, lintegral_dirac'] + · rfl + · exact measurable_measure_prodMk_left (pairUpdate_measurable hB) + +theorem pairedCost_map_state (z : OddCost) : (pairedCostKernel z).map Prod.fst = pairedOdd z.1 := by + ext B hB + rw [Measure.map_apply measurable_fst hB, pairedCostKernel_apply _ (measurable_fst hB), + pairedOdd, Kernel.comp_eq_snd_compProd, Kernel.snd_apply' _ _ hB] + rfl + +theorem pairedCost_map_ratio_cost (z : OddCost) : + (pairedCostKernel z).map (fun x => (x.1.1, x.2)) = oddJointKernel z.2 z.1 := by + have hm : Measurable (fun x : OddCost => (x.1.1, x.2)) := + (measurable_subtype_coe.comp measurable_fst).prodMk measurable_snd + have hp : Measurable (fun x : EvenState × OddState => (x.1.1, x.2.1)) := + (measurable_subtype_coe.comp measurable_fst).prodMk (measurable_subtype_coe.comp measurable_snd) + ext B hB + rw [Measure.map_apply hm hB, pairedCostKernel_apply _ (hm hB), + oddJointKernel, Kernel.map_apply _ (pairCost_measurable z.2), + Measure.map_apply (pairCost_measurable z.2) hB, oddTwoStep, Kernel.map_apply _ hp, + Measure.map_apply hp ((pairCost_measurable z.2) hB)] + rfl + +theorem pairedDraws_regeneration (s : OddState) (hs : s.1 ≤ 3) : + pairedDraws s = pairedDraws regenerationState := by + have hf : oddToEven s = oddToEven regenerationState := by + rw [oddToEven, Kernel.comapRight_apply, Kernel.comapRight_apply, oddKernel_regeneration s hs] + ext B hB + rw [pairedDraws, Kernel.compProd_apply hB, Kernel.compProd_apply hB] + change (∫⁻ t : EvenState, evenToOdd t (Prod.mk t ⁻¹' B) ∂oddToEven s) = + ∫⁻ t : EvenState, evenToOdd t (Prod.mk t ⁻¹' B) ∂oddToEven regenerationState + rw [hf] + +theorem pairedCost_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + pairedCostKernel (s, T) = pairedCostKernel (regenerationState, T) := by + ext B hB + rw [pairedCostKernel_apply _ hB, pairedCostKernel_apply _ hB] + exact congrArg (fun μ : Measure (EvenState × OddState) => + μ {x | (x.2, T + cost x.1.1 + cost x.2.1) ∈ B}) (pairedDraws_regeneration s hs) + +def shiftCost (T : ℝ) (z : OddCost) : OddCost := (z.1, z.2 + T) + +theorem shiftCost_measurable (T : ℝ) : Measurable (shiftCost T) := + measurable_fst.prodMk (measurable_snd.add measurable_const) + +theorem pairedCost_translation (s : OddState) (T a : ℝ) : + (pairedCostKernel (s, T)).map (shiftCost a) = pairedCostKernel (s, T + a) := by + ext B hB + rw [Measure.map_apply (shiftCost_measurable a) hB, + pairedCostKernel_apply _ ((shiftCost_measurable a) hB), pairedCostKernel_apply _ hB] + congr 1 + ext x + change (x.2, (T + cost x.1.1 + cost x.2.1) + a) ∈ B ↔ + (x.2, (T + a) + cost x.1.1 + cost x.2.1) ∈ B + have heq : (T + cost x.1.1 + cost x.2.1) + a = (T + a) + cost x.1.1 + cost x.2.1 := by ring + rw [heq] + +end NumberTheoryLean.PairedCostProcess + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.RegenerationTails + +noncomputable def sourceMark (t : EvenState) : Bool := if (209/100:ℝ) ≤ t.1 ∧ t.1 ≤ 213/100 then true else false + +lemma sourceMark_measurable : Measurable sourceMark := by + unfold sourceMark + exact Measurable.ite (measurableSet_Icc.preimage measurable_subtype_coe) measurable_const measurable_const + +abbrev MarkedOddCost := Bool × OddCost + +noncomputable def markedPairUpdate (x : OddCost × (EvenState × OddState)) : MarkedOddCost := + (sourceMark x.2.1,pairUpdate x) + +lemma markedPairUpdate_measurable : Measurable markedPairUpdate := + (sourceMark_measurable.comp (measurable_fst.comp measurable_snd)).prodMk pairUpdate_measurable + +noncomputable def markedPairKernel : Kernel OddCost MarkedOddCost := + (Kernel.id ×ₖ pairedDraws.prodMkRight ℝ).map markedPairUpdate + +instance markedPairKernel_isMarkovKernel : IsMarkovKernel markedPairKernel := + Kernel.IsMarkovKernel.map _ markedPairUpdate_measurable + +lemma markedPairKernel_apply (z : OddCost) {B : Set MarkedOddCost} (hB : MeasurableSet B) : + markedPairKernel z B = pairedDraws z.1 + {x | (sourceMark x.1,(x.2,z.2+cost x.1.1+cost x.2.1)) ∈ B} := by + rw [markedPairKernel,Kernel.map_apply' _ markedPairUpdate_measurable _ hB, + Kernel.prod_apply' _ _ _ (markedPairUpdate_measurable hB),Kernel.id_apply,lintegral_dirac'] + · rfl + · exact measurable_measure_prodMk_left (markedPairUpdate_measurable hB) + +lemma markedPair_forget (z : OddCost) : (markedPairKernel z).map Prod.snd = pairedCostKernel z := by + ext B hB + rw [Measure.map_apply measurable_snd hB,markedPairKernel_apply _ (measurable_snd hB), + pairedCostKernel_apply _ hB] + rfl + +lemma markedPair_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + markedPairKernel (s,T) = markedPairKernel (regenerationState,T) := by + ext B hB + rw [markedPairKernel_apply _ hB,markedPairKernel_apply _ hB,pairedDraws_regeneration s hs] + +def markedShift (a : ℝ) (z : MarkedOddCost) : MarkedOddCost := (z.1,shiftCost a z.2) + +lemma markedShift_measurable (a : ℝ) : Measurable (markedShift a) := + measurable_fst.prodMk ((shiftCost_measurable a).comp measurable_snd) + +lemma markedPair_translation (s : OddState) (T a : ℝ) : + (markedPairKernel (s,T)).map (markedShift a) = markedPairKernel (s,T+a) := by + ext B hB + rw [Measure.map_apply (markedShift_measurable a) hB, + markedPairKernel_apply _ ((markedShift_measurable a) hB),markedPairKernel_apply _ hB] + congr 1 + ext x + change (sourceMark x.1,(x.2,(T+cost x.1.1+cost x.2.1)+a)) ∈ B ↔ + (sourceMark x.1,(x.2,(T+a)+cost x.1.1+cost x.2.1)) ∈ B + rw [show (T+cost x.1.1+cost x.2.1)+a=(T+a)+cost x.1.1+cost x.2.1 by ring] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace NumberTheoryLean.CostReturnLaw + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open TransitionKernels PairedHitting PairedBlockContraction PairedCostProcess + +def returnSet : Set OddCost := Prod.fst ⁻¹' pairedRegeneration + +theorem returnSet_measurable : MeasurableSet returnSet := + pairedRegeneration_measurable.preimage measurable_fst + +noncomputable def costKilled : Kernel OddCost OddCost := pairedCostKernel.restrict returnSet_measurable.compl +noncomputable def costCaptured : Kernel OddCost OddCost := pairedCostKernel.restrict returnSet_measurable + +instance costKilled_isFiniteKernel : IsFiniteKernel costKilled := by unfold costKilled; infer_instance +instance costCaptured_isFiniteKernel : IsFiniteKernel costCaptured := by unfold costCaptured; infer_instance + +instance costKilled_pow_isFiniteKernel (n : ℕ) : IsFiniteKernel (costKilled ^ n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel OddCost OddCost); infer_instance + | succ n ih => + rw [pow_succ'] + change IsFiniteKernel (costKilled ∘ₖ (costKilled ^ n)) + infer_instance + +theorem costKilled_map_state (z : OddCost) : (costKilled z).map Prod.fst = pairedKilled z.1 := by + rw [costKilled, Kernel.restrict_apply] + change ((pairedCostKernel z).restrict (Prod.fst ⁻¹' pairedRegeneration)ᶜ).map Prod.fst = _ + rw [← preimage_compl, ← Measure.restrict_map measurable_fst pairedRegeneration_measurable.compl, + pairedCost_map_state] + rfl + +theorem costKilled_pow_map_state (n : ℕ) (z : OddCost) : + ((costKilled ^ n) z).map Prod.fst = (pairedKilled ^ n) z.1 := by + induction n generalizing z with + | zero => + change (Measure.dirac z).map Prod.fst = Measure.dirac z.1 + exact Measure.map_dirac' measurable_fst z + | succ n ih => + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH measurable_fst] + have hp : costKilled ^ (n + 1) = (costKilled ^ n) ∘ₖ costKilled := pow_succ costKilled n + have hq : pairedKilled ^ (n + 1) = (pairedKilled ^ n) ∘ₖ pairedKilled := pow_succ pairedKilled n + rw [hp, hq, Kernel.lintegral_comp _ _ _ (g := fun z : OddCost => H z.1) (hH.comp measurable_fst), + Kernel.lintegral_comp _ _ _ hH] + have hi : ∀ y : OddCost, (∫⁻ w : OddCost, H w.1 ∂(costKilled ^ n) y) = + ∫⁻ t, H t ∂(pairedKilled ^ n) y.1 := by + intro y + rw [← ih y, lintegral_map hH measurable_fst] + simp_rw [hi] + have hJ : Measurable (fun t : OddState => ∫⁻ u, H u ∂(pairedKilled ^ n) t) := hH.lintegral_kernel + rw [← costKilled_map_state z, lintegral_map hJ measurable_fst] + +theorem costKilled_mass (n : ℕ) (z : OddCost) : + (costKilled ^ n) z univ = (pairedKilled ^ n) z.1 univ := by + have h := congrArg (fun μ : Measure OddState => μ univ) (costKilled_pow_map_state n z) + rwa [Measure.map_apply measurable_fst MeasurableSet.univ, preimage_univ] at h + +theorem cost_survival_tendsto_zero (z : OddCost) : + Tendsto (fun n => (costKilled ^ n) z univ) atTop (𝓝 0) := by + apply (paired_survival_tendsto_zero z.1).congr + intro n + exact (costKilled_mass n z).symm + +noncomputable def firstReturn (n : ℕ) : Kernel OddCost OddCost := costCaptured ∘ₖ (costKilled ^ n) + +instance firstReturn_isFiniteKernel (n : ℕ) : IsFiniteKernel (firstReturn n) := by unfold firstReturn; infer_instance + +noncomputable def returnLaw : Kernel OddCost OddCost := Kernel.sum firstReturn + +theorem costCaptured_add_costKilled : costCaptured + costKilled = pairedCostKernel := by + ext z : 1 + change (pairedCostKernel z).restrict returnSet + (pairedCostKernel z).restrict returnSetᶜ = pairedCostKernel z + exact Measure.restrict_add_restrict_compl returnSet_measurable + +theorem return_mass_step (n : ℕ) (z : OddCost) : + firstReturn n z univ + (costKilled ^ (n + 1)) z univ = (costKilled ^ n) z univ := by + have hp : costKilled ^ (n + 1) = costKilled ∘ₖ (costKilled ^ n) := pow_succ' costKilled n + calc + _ = ((costCaptured + costKilled) ∘ₖ (costKilled ^ n)) z univ := by + rw [Kernel.comp_add_left, add_apply, Measure.add_apply, hp] + rfl + _ = (pairedCostKernel ∘ₖ (costKilled ^ n)) z univ := by rw [costCaptured_add_costKilled] + _ = _ := by rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ]; simp + +theorem return_finite_mass (n : ℕ) (z : OddCost) : + (costKilled ^ n) z univ + ∑ k ∈ Finset.range n, firstReturn k z univ = 1 := by + induction n with + | zero => + change (Measure.dirac z) univ + 0 = 1 + simp + | succ n ih => + rw [Finset.sum_range_succ] + calc + _ = (∑ k ∈ Finset.range n, firstReturn k z univ) + + (firstReturn n z univ + (costKilled ^ (n + 1)) z univ) := by ac_rfl + _ = (∑ k ∈ Finset.range n, firstReturn k z univ) + (costKilled ^ n) z univ := by rw [return_mass_step] + _ = 1 := by simpa only [add_comm] using ih + +instance returnLaw_isMarkovKernel : IsMarkovKernel returnLaw := by + constructor + intro z + constructor + rw [returnLaw, Kernel.sum_apply' _ _ MeasurableSet.univ] + have h := (cost_survival_tendsto_zero z).add (ENNReal.tendsto_nat_tsum (fun n => firstReturn n z univ)) + simp only [zero_add, return_finite_mass] at h + exact tendsto_nhds_unique h tendsto_const_nhds + +theorem costCaptured_off_returnSet (z : OddCost) : costCaptured z returnSetᶜ = 0 := by + rw [costCaptured, Kernel.restrict_apply' _ _ _ returnSet_measurable.compl, compl_inter_self, measure_empty] + +theorem firstReturn_off_returnSet (n : ℕ) (z : OddCost) : firstReturn n z returnSetᶜ = 0 := by + rw [firstReturn, Kernel.comp_apply' _ _ _ returnSet_measurable.compl] + simp only [costCaptured_off_returnSet, lintegral_zero] + +theorem returnLaw_off_returnSet (z : OddCost) : returnLaw z returnSetᶜ = 0 := by + rw [returnLaw, Kernel.sum_apply' _ _ returnSet_measurable.compl] + simp only [firstReturn_off_returnSet, tsum_zero] + +noncomputable def cycleCostLaw : Measure ℝ := (returnLaw (RegenerationTails.regenerationState, 0)).map Prod.snd + +instance cycleCostLaw_isProbabilityMeasure : IsProbabilityMeasure cycleCostLaw := + (Measure.isProbabilityMeasure_map_iff (μ := returnLaw (RegenerationTails.regenerationState, 0)) + measurable_snd.aemeasurable).mpr inferInstance + +end NumberTheoryLean.CostReturnLaw + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.RegenerationTails +open NumberTheoryLean.DerivativeWeights NumberTheoryLean.WeightFutureIntegrals +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.KernelDensityBridge + +lemma regeneration_density_eq {t : ℝ} (ht : 2 ≤ t) : + oddDensity regenerationState t = W t*phiEven t/phiOdd 1 := by + simp [oddDensity,tailDensity,regenerationState,ht] + +lemma regeneration_interval_positive {a b : ℝ} (ha : 2 ≤ a) (hab : a < b) : + 0 < oddKernel regenerationState (Icc a b) := by + have hp : ∀ t ∈ Icc a b, 0 < oddDensity regenerationState t := by + intro t ht + rw [regeneration_density_eq (ha.trans ht.1)] + exact div_pos (mul_pos (W_pos (by linarith [ht.1])) (phiEven_pos (by linarith [ht.1]))) (phiOdd_pos 1) + have hf : ContinuousOn (fun t => W t*phiEven t/phiOdd 1) (Icc a b) := by + intro t ht + have ht0 : t ≠ 0 := by linarith [ht.1] + have ht2 : t^2 ≠ 0 := pow_ne_zero 2 ht0 + have hW : ContinuousAt W t := by unfold W; fun_prop + exact ((hW.mul (phiEven_continuousAt (by linarith [ht.1]))).div_const _).continuousWithinAt + have hc : ContinuousOn (oddDensity regenerationState) (Icc a b) := hf.congr + (fun t ht => regeneration_density_eq (ha.trans ht.1)) + have hi := intervalIntegral.integral_pos hab hc (fun t ht => (hp t ⟨ht.1.le,ht.2⟩).le) + ⟨a,⟨le_rfl,hab.le⟩,hp a ⟨le_rfl,hab.le⟩⟩ + rw [oddKernel_apply,← ofReal_integral_eq_lintegral_ofReal + (oddDensity_integrable regenerationState).integrableOn + (Filter.Eventually.of_forall (oddDensity_nonneg regenerationState))] + apply ENNReal.ofReal_pos.mpr + rw [integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le hab.le] + exact hi + +noncomputable def markProbability : ℝ≥0∞ := + oddKernel regenerationState (Icc (209/100:ℝ) (213/100)) + +lemma markProbability_pos : 0 < markProbability := + regeneration_interval_positive (by norm_num) (by norm_num) + +lemma markProbability_lt_one : markProbability < 1 := by + let J := Icc (5/2:ℝ) (13/5) + have hJ : 0 < oddKernel regenerationState J := regeneration_interval_positive (by norm_num) (by norm_num) + have hdisj : Disjoint (Icc (209/100:ℝ) (213/100)) J := by + apply Set.disjoint_left.mpr + intro t ht hj + dsimp [J] at hj + linarith [ht.2,hj.1] + have hsum : markProbability+oddKernel regenerationState J ≤ 1 := by + rw [markProbability,← measure_union hdisj measurableSet_Icc] + exact prob_le_one + exact (ENNReal.lt_add_right (measure_ne_top _ _) hJ.ne').trans_le hsum + +lemma sourceMark_true (t : EvenState) : sourceMark t = true ↔ t.1 ∈ Icc (209/100:ℝ) (213/100) := by + simp [sourceMark] + +lemma markedPair_mark_mass (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + markedPairKernel (s,T) {z | z.1=true} = markProbability := by + have hm : MeasurableSet {z : MarkedOddCost | z.1=true} := measurable_fst (measurableSet_singleton true) + rw [markedPair_regeneration s hs T,markedPairKernel_apply _ hm] + have he : {x : EvenState × OddState | sourceMark x.1=true} = + Prod.fst ⁻¹' {t : EvenState | t.1 ∈ Icc (209/100:ℝ) (213/100)} := by + ext x + exact sourceMark_true x.1 + change pairedDraws regenerationState {x : EvenState × OddState | sourceMark x.1=true} = _ + rw [he] + let E : Set EvenState := {t | t.1 ∈ Icc (209/100:ℝ) (213/100)} + have hE : MeasurableSet E := measurable_subtype_coe measurableSet_Icc + have hfst : pairedDraws.fst regenerationState E = + pairedDraws regenerationState {p | p.1 ∈ E} := Kernel.fst_apply' _ _ hE + change pairedDraws regenerationState {p | p.1 ∈ E} = _ + rw [← hfst,pairedDraws,Kernel.fst_compProd] + have hmap := oddToEven_map_ratio regenerationState + have hmeasure := congrArg (fun μ : Measure ℝ => μ (Icc (209/100:ℝ) (213/100))) hmap + rw [Measure.map_apply measurable_subtype_coe measurableSet_Icc] at hmeasure + exact hmeasure + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set +open scoped Topology +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathGeometry + +noncomputable def gapAt (r T : ℝ) : ℝ := r*Real.exp (-T) + +lemma gapAt_pathCost {i : Side} {s r : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) : gapAt r (pathCost ts) = finalGap r ts := + (finalGap_eq_cost hs ht).symm + +lemma nextExponent_scale (a r t : ℝ) : nextExponent (a*r) t = a*nextExponent r t := by + unfold nextExponent + ring + +lemma nextGap_scale (a r t : ℝ) : nextGap (a*r) t = a*nextGap r t := by + unfold nextGap + ring + +lemma marked_draw_slack {b0 b1 r t : ℝ} (hb0 : 0 < b0) + (hr0 : 10*b0 ≤ r) (hr1 : r ≤ b1) (ht0 : 209/100 ≤ t) (ht1 : t ≤ 213/100) : + 10*b0/(313/100) ≤ nextExponent r t ∧ nextExponent r t ≤ b1/(309/100) ∧ + 2*b0 ≤ nextExponent r t ∧ nextExponent r t ≤ b1/2 ∧ + 6*b0 < nextGap r t ∧ nextGap r t/nextExponent r t=t := by + have hr : 0 < r := by linarith + have ht : 0 < t := by linarith + have htp : 0 < t+1 := by linarith + have hlow : 10*b0/(313/100) ≤ nextExponent r t := by + unfold nextExponent + exact div_le_div₀ (by positivity) hr0 htp (by linarith) + have hhi : nextExponent r t ≤ b1/(309/100) := by + unfold nextExponent + exact div_le_div₀ (hr.le.trans hr1) hr1 (by norm_num) (by linarith) + have hlo2 : 2*b0 ≤ nextExponent r t := by + apply (le_div_iff₀ htp).mpr + nlinarith + have hhi2 : nextExponent r t ≤ b1/2 := by + unfold nextExponent + exact div_le_div₀ (hr.le.trans hr1) hr1 (by norm_num) (by linarith) + have hgap : 6*b0 < nextGap r t := by + unfold nextGap + apply (lt_div_iff₀ htp).mpr + have hm := mul_le_mul_of_nonneg_right hr0 ht.le + nlinarith + exact ⟨hlow,hhi,hlo2,hhi2,hgap,nextRatio_identity hr ht⟩ + +lemma gapAt_le_iff {r B : ℝ} (hr : 0 < r) (hB : 0 < B) (T : ℝ) : + gapAt r T ≤ B ↔ Real.log (r/B) ≤ T := by + rw [gapAt,Real.exp_neg,← div_eq_mul_inv,div_le_iff₀ (Real.exp_pos T), + Real.log_le_iff_le_exp (div_pos hr hB),div_le_iff₀ hB] + simp only [mul_comm] + +lemma le_gapAt_iff {r A : ℝ} (hr : 0 < r) (hA : 0 < A) (T : ℝ) : + A ≤ gapAt r T ↔ T ≤ Real.log (r/A) := by + rw [gapAt,Real.exp_neg,← div_eq_mul_inv,le_div_iff₀ (Real.exp_pos T), + Real.le_log_iff_exp_le (div_pos hr hA),le_div_iff₀ hA] + simp only [mul_comm] + +lemma marked_cost_window {r b0 b1 : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) (T : ℝ) : + 10*b0 ≤ gapAt r T ∧ gapAt r T ≤ b1 ↔ + Real.log (r/b1) ≤ T ∧ T ≤ Real.log (r/b1)+Real.log (b1/(10*b0)) := by + have he : Real.log (r/(10*b0)) = Real.log (r/b1)+Real.log (b1/(10*b0)) := by + rw [Real.log_div hr.ne' (by positivity),Real.log_div hr.ne' hb1.ne', + Real.log_div hb1.ne' (by positivity)] + ring + rw [le_gapAt_iff hr (by positivity),gapAt_le_iff hr hb1,he,and_comm] + +lemma proportional_window_width {rho b0 : ℝ} (hrho : 0 < rho) (hb0 : 0 < b0) : + Real.log ((rho*b0)/(10*b0)) = Real.log (rho/10) := by + congr 1 + field_simp + +lemma moving_window_cost_threshold {K rho : ℝ} (hK : 0 < K) (hrho : 0 < rho) (M : ℝ) : + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → + M ≤ Real.log (r/(rho*K*(Real.log w)^2)) := by + have ht : Tendsto (fun w:ℝ => (Real.log w)^2/w) atTop (𝓝 0) := by + simpa only [one_mul,add_zero] using Real.tendsto_pow_log_div_mul_add_atTop (1:ℝ) 0 2 one_ne_zero + have hl : Tendsto (fun w:ℝ => (Real.exp M*rho*K)*((Real.log w)^2/w)) atTop (𝓝 0) := by + simpa only [mul_zero] using ht.const_mul (Real.exp M*rho*K) + filter_upwards [eventually_ge_atTop (3:ℝ),hl.eventually (gt_mem_nhds (show (0:ℝ)<1 by norm_num))] + with w hw hs + refine ⟨hw,?_⟩ + intro r hr + have hw0 : 0 < w := by linarith + have hr0 : 0 < r := hw0.trans_le hr + have hlog : 0 < Real.log w := Real.log_pos (by linarith) + have hden : 0 < rho*K*(Real.log w)^2 := by positivity + apply (Real.le_log_iff_exp_le (div_pos hr0 hden)).mpr + apply (le_div_iff₀ hden).mpr + have he := (div_le_iff₀ hw0).mp (show (Real.exp M*rho*K*(Real.log w)^2)/w ≤ 1 by simpa only [mul_div_assoc] using hs.le) + nlinarith + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MomentIndicators.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MomentIndicators.lean new file mode 100644 index 0000000000000000000000000000000000000000..67f1c9422d1aaa2bd9e0c5cea8d0563fe36407ad --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MomentIndicators.lean @@ -0,0 +1,139 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.JointModelDensity +import OAI.NumberTheory.Jacobsthal.Primes.StableSourceChebyshev + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosVarianceMoments +open NumberTheoryLean ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem finite_joint_moment_estimate (R xi w : ℝ) (hR : 0 < R) (hxi : 0 ≤ xi) (hw : 2 ≤ w) + (s : ℝ) (hs : 480024 ≤ s) (H qA : ℕ) (hH : 0 < H) (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (beta delta : ∀ t : ℕ,ZMod t) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) (S : Finset ℕ) (hS : S.card ≤ 2) : + |modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S)- + jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S| ≤ + jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S*Real.exp (-s/96)+ + 4*(H.divisors.card : ℝ)*(H : ℝ)/ + (modelLength R xi (H : ℝ) (C0 : ℝ)*(H.totient : ℝ))*(w^s)^2 := by + let b := modelLeft R xi (C0 : ℝ) + let c := modelRight R xi (H : ℝ) (C0 : ℝ) + let Y := modelLength R xi (H : ℝ) (C0 : ℝ) + let X := Y*((H.totient : ℝ)/(H : ℝ)) + let K0 := jointDensity (divisorPrimes w H) S + let K1 := jointDensity (coprimePrimes w H) S + let a0 := atomWeight R xi w H C0*(divisorModulus w H : ℝ) + let N : ℝ := (coprimeModulus w H).totient + let err := 4*(H.divisors.card : ℝ)*(w^s)^2 + let B := X*K1*Real.exp (-s/96)+err + let f (p : (ZMod (coprimeModulus w H))ˣ) : ℝ := + (coprimePositionSurvivors w H qA delta S p b c).card + have hHR : (0 : ℝ) < H := by exact_mod_cast hH + have hY : 0 < Y := by dsimp [Y,modelLength,interceptScale];positivity + have hX : 0 < X := mul_pos hY (div_pos (by exact_mod_cast Nat.totient_pos.mpr hH) hHR) + have hbc : c-b = Y := by dsimp [c,b,modelRight,Y];ring + have hK0 := jointDensity_nonneg (divisorPrimes w H) S + (fun t ht => (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1) + have hK01 := jointDensity_le_one (divisorPrimes w H) S + (fun t ht => (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1) + have ha0 : 0 < a0 := mul_pos (atomWeight_pos R xi w H C0 hR hxi hH) + (by exact_mod_cast divisorModulus_pos w H) + have hnorm : a0*N*X = 1 := model_normalization_identity R xi w H C0 hR hxi hH + have hpoint (p : (ZMod (coprimeModulus w H))ˣ) : |f p-X*K1| ≤ B := by + by_cases hz : K1 = 0 + · have he := zero_coprimePositionSurvivors w H qA delta S p hqA hz b c + simp only [f,he,Finset.card_empty,Nat.cast_zero,hz,mul_zero,sub_zero,abs_zero,B,zero_mul,zero_add] + dsimp [err] + positivity + · have hh := coprimePositionSurvivors_estimate w hw s hs H qA hH delta S hS p hqA b c + (by linarith) hz + rw [hbc] at hh + exact hh + have hsum : |(∑ p,f p)-N*(X*K1)| ≤ N*B := by + have hconst : (∑ _p : (ZMod (coprimeModulus w H))ˣ,X*K1) = N*(X*K1) := by + simp only [Finset.sum_const,Finset.card_univ,ZMod.card_units_eq_totient,nsmul_eq_mul,N] + rw [← hconst,← Finset.sum_sub_distrib] + calc + _ ≤ ∑ p,|f p-X*K1| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _p : (ZMod (coprimeModulus w H))ˣ,B := Finset.sum_le_sum (fun p _ => hpoint p) + _ = N*B := by simp only [Finset.sum_const,Finset.card_univ,ZMod.card_units_eq_totient,nsmul_eq_mul,N] + have hmass : modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S) = a0*K0*(∑ p,f p) := by + rw [joint_model_mass R xi w H qA C0 beta delta S hC0] + dsimp [a0,K0,f,b,c] + ring + have hbase : a0*K0*(N*(X*K1)) = K0*K1 := by + calc + _ = (a0*N*X)*(K0*K1) := by ring + _ = _ := by rw [hnorm,one_mul] + have htotal := jointDensity_split w H S + change K0*K1 = _ at htotal + rw [← htotal,hmass,← hbase,← mul_sub,abs_mul,abs_of_nonneg (mul_nonneg ha0.le hK0)] + have hm := mul_le_mul_of_nonneg_left hsum (mul_nonneg ha0.le hK0) + have hscalar : a0*N = 1/X := (eq_div_iff hX.ne').mpr hnorm + have he : a0*K0*(N*B) = K0*K1*Real.exp (-s/96)+K0*err/X := by + dsimp [B] + calc + _ = (a0*N*X)*(K0*K1*Real.exp (-s/96))+(a0*N)*(K0*err) := by ring + _ = _ := by rw [hnorm,hscalar];ring + have her : 0 ≤ err := by dsimp [err];positivity + have hlast : K0*err/X ≤ err/X := div_le_div_of_nonneg_right + (by simpa only [one_mul] using mul_le_mul_of_nonneg_right hK01 her) hX.le + have hright : err/X = 4*(H.divisors.card : ℝ)*(H : ℝ)/ + (modelLength R xi (H : ℝ) (C0 : ℝ)*(H.totient : ℝ))*(w^s)^2 := by + dsimp [err,X,Y] + field_simp + rw [hbase] + exact hm.trans (he ▸ add_le_add le_rfl (hlast.trans_eq hright)) + +end ErdosVarianceMoments + + + +namespace ErdosVarianceUniformMoments +open NumberTheoryLean ErdosVarianceMoments ErdosVarianceSmallModel ErdosRandomVariance +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem weighted_joint_eq_mass (R xi w : ℝ) (H qA : ℕ) (C0 : ℤ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) : + weightedMoment (modelUniverse R xi w H C0) (fun _ => atomWeight R xi w H C0) + (jointIndicator w H C0 qA beta delta S) = + modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S) := by + unfold weightedMoment modelMass + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro v _hv + unfold jointIndicator + split_ifs <;> simp + +theorem weighted_single_eq_mass (R xi w : ℝ) (H qA : ℕ) (C0 : ℤ) + (beta delta : ∀ t : ℕ,ZMod t) (j : ℕ) : + weightedMoment (modelUniverse R xi w H C0) (fun _ => atomWeight R xi w H C0) + (modelIndicator w H C0 qA beta delta j) = + modelMass R xi w H C0 (jointCondition w H C0 qA beta delta {j}) := by + rw [← weighted_joint_eq_mass] + congr 1 + funext v + exact (jointIndicator_singleton w H C0 qA beta delta j v).symm + +theorem weighted_pair_eq_mass (R xi w : ℝ) (H qA : ℕ) (C0 : ℤ) + (beta delta : ∀ t : ℕ,ZMod t) (i j : ℕ) : + weightedMoment (modelUniverse R xi w H C0) (fun _ => atomWeight R xi w H C0) + (fun v => modelIndicator w H C0 qA beta delta i v*modelIndicator w H C0 qA beta delta j v) = + modelMass R xi w H C0 (jointCondition w H C0 qA beta delta {i,j}) := by + rw [← weighted_joint_eq_mass] + congr 1 + funext v + exact (jointIndicator_pair w H C0 qA beta delta i j v).symm + +end ErdosVarianceUniformMoments + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/MovingMarkedWindow.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/MovingMarkedWindow.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e8d9003310a956959b6b318e8ca5051f247e646 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/MovingMarkedWindow.lean @@ -0,0 +1,383 @@ +import Mathlib.Probability.Kernel.WithDensity +import OAI.NumberTheory.Jacobsthal.Partitions.BeginningWindowTransport + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.InitialRegeneration NumberTheoryLean.TransitionKernels +open NumberTheoryLean.KernelPotential +open AbsorptionCutoff.Renewal + +noncomputable def rawFirstMarkedBeginning : Kernel OddCost OddCost := + (potential Kernel.id (cycleBranchKernel false)).withDensity (fun _ y => nextMarkWeight y) + +lemma nextMarkWeight_ne_top (z : OddCost) : nextMarkWeight z ≠ ∞ := + measure_ne_top (cycleBranchKernel true z) univ + +instance rawFirstMarkedBeginning_isSFiniteKernel : IsSFiniteKernel rawFirstMarkedBeginning := by + unfold rawFirstMarkedBeginning + exact Kernel.IsSFiniteKernel.withDensity _ (fun _ y => nextMarkWeight_ne_top y) + +lemma rawFirstMarkedBeginning_apply (z : OddCost) : + rawFirstMarkedBeginning z = + Measure.sum (fun n : ℕ => ((cycleBranchKernel false ^ n) z).withDensity nextMarkWeight) := by + rw [rawFirstMarkedBeginning,Kernel.withDensity_apply _ (f := fun _ y : OddCost => nextMarkWeight y) (nextMarkWeight_measurable.comp measurable_snd), + potential,Kernel.sum_apply] + simp only [Kernel.id_comp] + exact withDensity_sum _ _ + +lemma rawFirstMarkedBeginning_increment (z : OddCost) (hz : z ∈ returnSet) : + (rawFirstMarkedBeginning z).map (fun y => y.2-z.2) = firstMarkWaitingLaw := by + rw [rawFirstMarkedBeginning_apply, + Measure.map_sum (f := fun y : OddCost => y.2-z.2) (measurable_snd.sub measurable_const).aemeasurable] + change actualWaitingLaw z = firstMarkWaitingLaw + rw [actualWaitingLaw_eq z hz,firstMarkWaitingLaw,actualWaitingLaw_eq] + norm_num [returnSet,NumberTheoryLean.PairedHitting.pairedRegeneration,NumberTheoryLean.RegenerationTails.regenerationState] + +lemma rawFirstMarkedBeginning_mass (z : OddCost) (hz : z ∈ returnSet) : + rawFirstMarkedBeginning z univ = 1 := by + have he := congrArg (fun μ : Measure ℝ => μ univ) (rawFirstMarkedBeginning_increment z hz) + rw [Measure.map_apply (f := fun y : OddCost => y.2-z.2) (measurable_snd.sub measurable_const) MeasurableSet.univ,preimage_univ] at he + exact he.trans measure_univ + +lemma rawFirstMarkedBeginning_ae_regeneration (z : OddCost) (hz : z ∈ returnSet) : + ∀ᵐ y ∂rawFirstMarkedBeginning z, y ∈ returnSet := by + rw [rawFirstMarkedBeginning_apply,Measure.ae_sum_iff] + intro n + exact (withDensity_absolutelyContinuous _ _).ae_le (cycleBranch_pow_ae_regeneration false n z hz) + +lemma rawFirstMarkedBeginning_cost_integral (z : OddCost) (hz : z ∈ returnSet) + {F : ℝ → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F y.2 ∂rawFirstMarkedBeginning z) = ∫⁻ G, F (z.2+G) ∂firstMarkWaitingLaw := by + rw [← rawFirstMarkedBeginning_increment z hz, + lintegral_map (g := fun y : OddCost => y.2-z.2) (f := fun G : ℝ => F (z.2+G)) + (hF.comp (measurable_const.add measurable_id)) (measurable_snd.sub measurable_const)] + apply lintegral_congr + intro y + congr 1 + ring + +noncomputable def initialMarkedBeginning : Kernel EvenState OddCost := + rawFirstMarkedBeginning ∘ₖ delayedRegeneration + +instance initialMarkedBeginning_isMarkovKernel : IsMarkovKernel initialMarkedBeginning := by + constructor + intro s + constructor + rw [initialMarkedBeginning,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + have he : (fun z => rawFirstMarkedBeginning z univ) =ᵐ[delayedRegeneration s] fun _ => 1 := by + filter_upwards [delayedRegeneration_ae_regeneration s] with z hz + exact rawFirstMarkedBeginning_mass z hz + rw [lintegral_congr_ae he] + simp + +lemma initialMarkedBeginning_ae_regeneration (s : EvenState) : + ∀ᵐ z ∂initialMarkedBeginning s, z ∈ returnSet := by + rw [initialMarkedBeginning] + apply Kernel.ae_comp_of_ae_ae returnSet_measurable + filter_upwards [delayedRegeneration_ae_regeneration s] with z hz + exact rawFirstMarkedBeginning_ae_regeneration z hz + +noncomputable def initialMarkedCostLaw (s : EvenState) : Measure ℝ := + (initialMarkedBeginning s).map Prod.snd + +instance initialMarkedCostLaw_isProbabilityMeasure (s : EvenState) : IsProbabilityMeasure (initialMarkedCostLaw s) := + (Measure.isProbabilityMeasure_map_iff measurable_snd.aemeasurable).mpr inferInstance + +lemma initialMarkedCostLaw_eq (s : EvenState) : + initialMarkedCostLaw s = delayedCostLaw s ∗ firstMarkWaitingLaw := by + apply Measure.ext_of_lintegral + intro F hF + rw [initialMarkedCostLaw,lintegral_map hF measurable_snd,initialMarkedBeginning, + Kernel.lintegral_comp _ _ _ (g := fun z : OddCost => F z.2) (hF.comp measurable_snd), + Measure.lintegral_conv hF,delayedCostLaw, + lintegral_map (g := Prod.snd) (f := fun x : ℝ => ∫⁻ y, F (x+y) ∂firstMarkWaitingLaw) + ((hF.comp measurable_add).lintegral_prod_right') measurable_snd] + apply lintegral_congr_ae + filter_upwards [delayedRegeneration_ae_regeneration s] with z hz + exact rawFirstMarkedBeginning_cost_integral z hz hF + +lemma firstMarkWaiting_nonneg : ∀ᵐ G ∂firstMarkWaitingLaw, 0 ≤ G := by + rw [firstMarkWaitingLaw,actualWaitingLaw_eq _ (by norm_num [returnSet, + NumberTheoryLean.PairedHitting.pairedRegeneration,NumberTheoryLean.RegenerationTails.regenerationState])] + exact Measure.ae_smul_measure unmarkedPotential_ae_nonneg _ + +lemma initialMarkedCost_nonneg (s : EvenState) : ∀ᵐ D ∂initialMarkedCostLaw s, 0 ≤ D := by + rw [initialMarkedCostLaw_eq] + have hd : ∀ᵐ T ∂delayedCostLaw s, 0 ≤ T := by + rw [delayedCostLaw] + exact (ae_map_iff measurable_snd.aemeasurable measurableSet_Ici).mpr (delayedRegeneration_cost_nonneg s) + simpa only [zero_add] using conv_ae_lower hd firstMarkWaiting_nonneg + +lemma costTransform_mono {μ : Measure ℝ} (hμ : ∀ᵐ G ∂μ, 0 ≤ G) {a b : ℝ} (hab : a ≤ b) : + costTransform μ a ≤ costTransform μ b := by + apply lintegral_mono_ae + filter_upwards [hμ] with G hG + exact ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hab hG)) + +theorem initialMarkedCost_uniform_exponential (S : ℝ) : ∃ eta B : ℝ, 0 < eta ∧ 0 ≤ B ∧ + ∀ s : EvenState, s.1 ≤ S → costTransform (initialMarkedCostLaw s) eta ≤ ENNReal.ofReal B := by + obtain ⟨a,A,ha,hA,hDelay⟩ := delayedCostLaw_uniform_exponential S + obtain ⟨b,hb,hWait,_⟩ := marked_waiting_common_exponential_moment + let eta := min a b + have heta : 0 < eta := lt_min ha hb + have hW : costTransform firstMarkWaitingLaw eta < ∞ := + (costTransform_mono firstMarkWaiting_nonneg (min_le_right a b)).trans_lt hWait + let W : ℝ := (costTransform firstMarkWaitingLaw eta).toReal + have hWreal : costTransform firstMarkWaitingLaw eta = ENNReal.ofReal W := + (ENNReal.ofReal_toReal hW.ne).symm + refine ⟨eta,A*W,heta,mul_nonneg hA ENNReal.toReal_nonneg,?_⟩ + intro s hs + have hd : ∀ᵐ T ∂delayedCostLaw s, 0 ≤ T := by + rw [delayedCostLaw] + exact (ae_map_iff measurable_snd.aemeasurable measurableSet_Ici).mpr (delayedRegeneration_cost_nonneg s) + rw [initialMarkedCostLaw_eq,costTransform_conv,hWreal,ENNReal.ofReal_mul hA] + exact mul_le_mul_left ((costTransform_mono hd (min_le_left a b)).trans (hDelay s hs)) _ + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.TransitionKernels NumberTheoryLean.KernelPotential + +noncomputable def initialBeginningReg : Kernel EvenState RegCost := + initialMarkedBeginning.comapRight (MeasurableEmbedding.subtype_coe returnSet_measurable) + +instance initialBeginningReg_isMarkovKernel : IsMarkovKernel initialBeginningReg := by + apply Kernel.IsMarkovKernel.comapRight + intro s + have he := (ae_mem_iff_measure_eq (μ := initialMarkedBeginning s) + returnSet_measurable.nullMeasurableSet).mp (initialMarkedBeginning_ae_regeneration s) + rw [measure_univ] at he + convert! he using 1 + congr 1 + ext y + simp + +lemma initialBeginningReg_map_state (s : EvenState) : + (initialBeginningReg s).map (Subtype.val : RegCost → OddCost) = initialMarkedBeginning s := by + calc + _ = (initialMarkedBeginning s).restrict returnSet := by + change (((initialMarkedBeginning s).comap (Subtype.val : RegCost → OddCost)).map Subtype.val) = _ + exact map_comap_subtype_coe (μ := initialMarkedBeginning s) returnSet_measurable + _ = _ := Measure.restrict_eq_self_of_ae_mem (initialMarkedBeginning_ae_regeneration s) + +lemma initialBeginningReg_cost_law (s : EvenState) : + (initialBeginningReg s).map beginningCost = initialMarkedCostLaw s := by + rw [initialMarkedCostLaw,← initialBeginningReg_map_state s, + Measure.map_map measurable_snd measurable_subtype_coe] + rfl + +lemma beginningBelow_shift (t v : ℝ) : beginningBelow t (v-t) = beginningBelow 0 v := by + unfold beginningBelow + congr 1 + ext z + simp only [mem_preimage,mem_Iio,relativeBeginningCost,sub_zero] + constructor <;> intro h <;> linarith + +lemma beginningOver_shift (t v H : ℝ) : beginningOver t (v-t) H = beginningOver 0 v H := by + unfold beginningOver + congr 1 + ext z + simp only [mem_preimage,mem_Ioi,relativeBeginningCost,sub_zero] + constructor <;> intro h <;> linarith + +lemma beginningWindow_shift (t v H : ℝ) : beginningWindow t (v-t) H = beginningWindow 0 v H := by + unfold beginningWindow + congr 1 + ext z + simp only [mem_preimage,mem_Icc,relativeBeginningCost,sub_zero] + constructor <;> rintro ⟨h1,h2⟩ <;> constructor <;> linarith + +lemma absoluteBeginningOvershoot_eq (z : RegCost) (v H : ℝ) : + (potential (beginningOver 0 v H) (beginningBelow 0 v)) z univ = + beginningOvershoot z (v-beginningCost z) H := by + rw [beginningOvershoot,beginningOver_shift,beginningBelow_shift] + +lemma absoluteBeginningWindowHit_eq (z : RegCost) (v H : ℝ) : + (potential (beginningWindow 0 v H) (beginningBelow 0 v)) z univ = + beginningWindowHit z (v-beginningCost z) H := by + rw [beginningWindowHit,beginningWindow_shift,beginningBelow_shift] + +noncomputable def markedWindowSuccess (v H : ℝ) (z : RegCost) : ℝ≥0∞ := + if beginningCost z < v then (potential (beginningWindow 0 v H) (beginningBelow 0 v)) z univ + else if beginningCost z ≤ v+H then 1 else 0 + +noncomputable def markedWindowFailure (v H : ℝ) (z : RegCost) : ℝ≥0∞ := + if beginningCost z < v then (potential (beginningOver 0 v H) (beginningBelow 0 v)) z univ + else if beginningCost z ≤ v+H then 0 else 1 + +lemma markedWindowSuccess_measurable (v H : ℝ) : Measurable (markedWindowSuccess v H) := by + unfold markedWindowSuccess + exact Measurable.ite (measurableSet_lt beginningCost_measurable measurable_const) + ((potential _ _).measurable_coe MeasurableSet.univ) + (Measurable.ite (measurableSet_le beginningCost_measurable measurable_const) measurable_const measurable_const) + +lemma markedWindowFailure_measurable (v H : ℝ) : Measurable (markedWindowFailure v H) := by + unfold markedWindowFailure + exact Measurable.ite (measurableSet_lt beginningCost_measurable measurable_const) + ((potential _ _).measurable_coe MeasurableSet.univ) + (Measurable.ite (measurableSet_le beginningCost_measurable measurable_const) measurable_const measurable_const) + +lemma markedWindow_partition (z : RegCost) (v H : ℝ) (hH : 0 ≤ H) : + markedWindowSuccess v H z+markedWindowFailure v H z = 1 := by + unfold markedWindowSuccess markedWindowFailure + by_cases hz : beginningCost z < v + · rw [ite_eq_left hz,ite_eq_left hz,absoluteBeginningOvershoot_eq,absoluteBeginningWindowHit_eq] + exact beginningWindow_partition z (by linarith) hH + · rw [ite_eq_right hz,ite_eq_right hz] + split_ifs <;> simp + +noncomputable def initialMarkedWindowSuccess (s : EvenState) (v H : ℝ) : ℝ≥0∞ := + ∫⁻ z, markedWindowSuccess v H z ∂initialBeginningReg s + +noncomputable def initialMarkedWindowFailure (s : EvenState) (v H : ℝ) : ℝ≥0∞ := + ∫⁻ z, markedWindowFailure v H z ∂initialBeginningReg s + +lemma initialMarkedWindow_partition (s : EvenState) (v H : ℝ) (hH : 0 ≤ H) : + initialMarkedWindowSuccess s v H+initialMarkedWindowFailure s v H = 1 := by + rw [initialMarkedWindowSuccess,initialMarkedWindowFailure, + ← lintegral_add_left (markedWindowSuccess_measurable v H)] + simp only [markedWindow_partition _ v H hH,lintegral_const,measure_univ,mul_one] + +lemma cost_tail_le_transform (μ : Measure ℝ) {eta : ℝ} (heta : 0 ≤ eta) (v : ℝ) : + μ (Ici v) ≤ ENNReal.ofReal (Real.exp (-eta*v))*costTransform μ eta := by + calc + _ = ∫⁻ G, (Ici v).indicator (fun _ => (1:ℝ≥0∞)) G ∂μ := by + rw [lintegral_indicator measurableSet_Ici]; simp + _ ≤ ∫⁻ G, ENNReal.ofReal (Real.exp (-eta*v))*ENNReal.ofReal (Real.exp (eta*G)) ∂μ := by + apply lintegral_mono + intro G + by_cases hG : G ∈ Ici v + · rw [indicator_of_mem hG] + change (1:ℝ≥0∞) ≤ ENNReal.ofReal (Real.exp (-eta*v))*ENNReal.ofReal (Real.exp (eta*G)) + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le,← Real.exp_add] + have he : (1:ℝ) ≤ Real.exp (-eta*v+eta*G) := Real.one_le_exp_iff.mpr (by change v≤G at hG; nlinarith) + simpa only [ENNReal.ofReal_one] using ENNReal.ofReal_le_ofReal he + · rw [indicator_of_notMem hG]; exact zero_le + _ = _ := lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + +lemma initialMarkedWindowFailure_le (s : EvenState) (v H R : ℝ) + (hTail : ∀ z : RegCost, ∀ u : ℝ, 0 < u → beginningOvershoot z u H ≤ ENNReal.ofReal R) : + initialMarkedWindowFailure s v H ≤ ENNReal.ofReal R+initialMarkedCostLaw s (Ici v) := by + have hp (z : RegCost) : markedWindowFailure v H z ≤ ENNReal.ofReal R+ + (beginningCost ⁻¹' Ici v).indicator (fun _ => (1:ℝ≥0∞)) z := by + by_cases hz : beginningCost z < v + · rw [markedWindowFailure,ite_eq_left hz,absoluteBeginningOvershoot_eq, + indicator_of_notMem (show z ∉ beginningCost ⁻¹' Ici v from not_le_of_gt hz),add_zero] + exact hTail z _ (by linarith) + · rw [indicator_of_mem (show z ∈ beginningCost ⁻¹' Ici v from le_of_not_gt hz), + markedWindowFailure,ite_eq_right hz] + split_ifs + · exact zero_le + · exact le_add_left le_rfl + calc + _ ≤ ∫⁻ z, ENNReal.ofReal R+(beginningCost ⁻¹' Ici v).indicator (fun _ => (1:ℝ≥0∞)) z ∂initialBeginningReg s := + lintegral_mono hp + _ = ENNReal.ofReal R+initialBeginningReg s (beginningCost ⁻¹' Ici v) := by + rw [lintegral_add_left measurable_const,lintegral_const,measure_univ,mul_one, + lintegral_indicator (beginningCost_measurable measurableSet_Ici)] + simp + _ = _ := by + rw [← initialBeginningReg_cost_law s,Measure.map_apply beginningCost_measurable measurableSet_Ici] + +theorem initialMarkedWindow_exponential (S : ℝ) : ∃ eta C eta0 B : ℝ, + 0 < eta ∧ 0 < C ∧ 0 < eta0 ∧ 0 ≤ B ∧ ∀ s : EvenState, s.1 ≤ S → ∀ v H : ℝ, + 0 ≤ H → initialMarkedWindowFailure s v H ≤ + ENNReal.ofReal (C*Real.exp (-eta*H)+B*Real.exp (-eta0*v)) := by + obtain ⟨eta,C,heta,hC,hTail⟩ := beginningWindow_exponential + obtain ⟨eta0,B,heta0,hB,hDelay⟩ := initialMarkedCost_uniform_exponential S + refine ⟨eta,C,eta0,B,heta,hC,heta0,hB,?_⟩ + intro s hs v H hH + calc + _ ≤ ENNReal.ofReal (C*Real.exp (-eta*H))+initialMarkedCostLaw s (Ici v) := + initialMarkedWindowFailure_le s v H _ (fun z u hu => (hTail z u H hu hH).1) + _ ≤ ENNReal.ofReal (C*Real.exp (-eta*H))+ + ENNReal.ofReal (Real.exp (-eta0*v))*costTransform (initialMarkedCostLaw s) eta0 := + add_le_add le_rfl (cost_tail_le_transform _ heta0.le v) + _ ≤ ENNReal.ofReal (C*Real.exp (-eta*H))+ENNReal.ofReal (Real.exp (-eta0*v))*ENNReal.ofReal B := + add_le_add le_rfl (mul_le_mul_right (hDelay s hs) _) + _ = _ := by rw [← ENNReal.ofReal_mul (Real.exp_pos _).le,mul_comm (Real.exp (-eta0*v)), + ← ENNReal.ofReal_add (mul_nonneg hC.le (Real.exp_pos _).le) (mul_nonneg hB (Real.exp_pos _).le)] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels + +lemma exponential_decay_tendsto {eta : ℝ} (heta : 0 < eta) (C : ℝ) : + Tendsto (fun H : ℝ => C*Real.exp (-eta*H)) atTop (𝓝 0) := by + have he : Tendsto (fun H : ℝ => Real.exp (-eta*H)) atTop (𝓝 0) := by + simpa only [Function.comp_def,id_eq,neg_mul] using + Real.tendsto_exp_neg_atTop_nhds_zero.comp (Tendsto.const_mul_atTop heta tendsto_id) + simpa only [mul_zero] using he.const_mul C + +theorem moving_marked_window_capture {eps : ℝ} (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → + initialMarkedWindowFailure s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) ≤ + ENNReal.ofReal eps ∧ + 1-ENNReal.ofReal eps ≤ + initialMarkedWindowSuccess s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) := by + obtain ⟨eta,C,eta0,B,heta,_hC,heta0,_hB,hBound⟩ := initialMarkedWindow_exponential (23/10) + have hHalf : 0 < eps/2 := by positivity + obtain ⟨H,hH,hSmall⟩ := ((eventually_gt_atTop (0:ℝ)).and + ((tendsto_order.mp (exponential_decay_tendsto heta C)).2 (eps/2) hHalf)).exists + obtain ⟨V,hV⟩ := eventually_atTop.mp + ((tendsto_order.mp (exponential_decay_tendsto heta0 B)).2 (eps/2) hHalf) + let rho : ℝ := 10*Real.exp H + have hrho : 10 < rho := by + have he := Real.one_lt_exp_iff.mpr hH + dsimp [rho] + linarith + have hWidth : Real.log (rho/10) = H := by + dsimp [rho] + rw [mul_div_cancel_left₀ _ (by norm_num : (10:ℝ) ≠ 0),Real.log_exp] + refine ⟨rho,hrho,?_⟩ + intro K hK + filter_upwards [moving_window_cost_threshold hK (by linarith : 0 < rho) V] with w hw + refine ⟨hw.1,?_⟩ + intro r hr s _hs0 hs1 + have hFailure : initialMarkedWindowFailure s + (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) ≤ ENNReal.ofReal eps := by + rw [hWidth] + apply (hBound s hs1 _ H hH.le).trans + apply ENNReal.ofReal_le_ofReal + have htail := hV _ (hw.2 r hr) + linarith + refine ⟨hFailure,?_⟩ + apply tsub_le_iff_right.mpr + have hp := initialMarkedWindow_partition s (Real.log (r/(rho*K*(Real.log w)^2))) + (Real.log (rho/10)) (by rw [hWidth]; exact hH.le) + calc + 1 = initialMarkedWindowSuccess s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10))+ + initialMarkedWindowFailure s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) := hp.symm + _ ≤ _ := add_le_add le_rfl hFailure + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/OrderedAffineMoment.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/OrderedAffineMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..59ecf9db963d1752d7475547a8e7b58f1dea1dda --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/OrderedAffineMoment.lean @@ -0,0 +1,153 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ScalarFreeGate + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission + +noncomputable def orderedFirstMoment : ℕ → ℝ → ℝ + | 0,_ => 0 + | n+1,b => ∫ x in (1:ℝ)..baseCutoff b, + (x*orderedMass n x+orderedFirstMoment n x)/(max 1 x) + +theorem orderedFirstMoment_continuous (n : ℕ) : Continuous (orderedFirstMoment n) := by + induction n with + | zero => exact continuous_const + | succ n ih => + have hc : Continuous (fun x : ℝ => (x*orderedMass n x+orderedFirstMoment n x)/(max 1 x)) := + ((continuous_id.mul (orderedMass_continuous n)).add ih).div + (continuous_const.max continuous_id) (fun x => ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _))) + exact (intervalIntegral.differentiable_integral_of_continuous hc).continuous.comp + (continuous_const.max (continuous_const.min continuous_id)) + +theorem first_moment_primitive (n : ℕ) {x : ℝ} (hx : 0 < x) : + HasDerivAt (fun x : ℝ => (x-1)*((Real.log x)^(n+1)/((n+1).factorial:ℝ))) + ((Real.log x)^(n+1)/((n+1).factorial:ℝ)+(x-1)*((Real.log x)^n/(n.factorial:ℝ))/x) x := by + have hh := ((hasDerivAt_id x).sub_const 1).mul (log_power_primitive n hx) + convert! hh using 1 + simp only [id_eq,one_mul] + ring + +theorem orderedFirstMoment_eq (n : ℕ) {b : ℝ} (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + orderedFirstMoment (n+1) b=(b-1)*((Real.log b)^n/(n.factorial:ℝ)) := by + induction n generalizing b with + | zero => + rw [orderedFirstMoment,baseCutoff_on hb1 hb2] + have he : (∫ x in (1:ℝ)..b,(x*orderedMass 0 x+orderedFirstMoment 0 x)/(max 1 x))= + ∫ _x in (1:ℝ)..b,(1:ℝ) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hb1] at hx + have hx0 : x ≠ 0 := by linarith [hx.1] + simp [orderedMass,orderedFirstMoment,max_eq_right hx.1,hx0] + rw [he] + simp + | succ n ih => + rw [orderedFirstMoment,baseCutoff_on hb1 hb2] + have he : (∫ x in (1:ℝ)..b,(x*orderedMass (n+1) x+orderedFirstMoment (n+1) x)/(max 1 x))= + ∫ x in (1:ℝ)..b,((Real.log x)^(n+1)/((n+1).factorial:ℝ)+(x-1)*((Real.log x)^n/(n.factorial:ℝ))/x) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hb1] at hx + have hx0 : x ≠ 0 := by linarith [hx.1] + dsimp only + rw [orderedMass_eq (n+1) hx.1 (hx.2.trans hb2),ih hx.1 (hx.2.trans hb2),max_eq_right hx.1] + field_simp + rw [he] + have hn : (n.factorial:ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + have hn1 : ((n+1).factorial:ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero (n+1) + have hc : ContinuousOn (fun x : ℝ => (Real.log x)^(n+1)/((n+1).factorial:ℝ)+(x-1)*((Real.log x)^n/(n.factorial:ℝ))/x) + (uIcc 1 b) := by + rw [uIcc_of_le hb1] + intro x hx + have hx0 : x ≠ 0 := by linarith [hx.1] + apply ContinuousAt.continuousWithinAt + fun_prop (disch := simp_all) + have hd : ∀ x ∈ uIcc (1:ℝ) b, HasDerivAt + (fun x : ℝ => (x-1)*((Real.log x)^(n+1)/((n+1).factorial:ℝ))) + ((Real.log x)^(n+1)/((n+1).factorial:ℝ)+(x-1)*((Real.log x)^n/(n.factorial:ℝ))/x) x := by + intro x hx + rw [uIcc_of_le hb1] at hx + exact first_moment_primitive n (by linarith [hx.1]) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd (hc.intervalIntegrable (μ := volume))] + simp + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission + +noncomputable def orderedAffine (m : ℝ) (n : ℕ) (S b : ℝ) : ℝ := + (3*S/m-2)*orderedMass n b+(3/m)*orderedFirstMoment n b + +theorem orderedAffine_continuous (m : ℝ) (n : ℕ) : + Continuous (fun p : ℝ×ℝ => orderedAffine m n p.1 p.2) := by + have hM : Continuous (fun p : ℝ×ℝ => orderedMass n p.2) := (orderedMass_continuous n).comp continuous_snd + have hF : Continuous (fun p : ℝ×ℝ => orderedFirstMoment n p.2) := (orderedFirstMoment_continuous n).comp continuous_snd + exact (((continuous_const.mul continuous_fst).div_const m).sub continuous_const |>.mul hM).add + (continuous_const.mul hF) + +theorem orderedAffine_shift_continuous (m : ℝ) (n : ℕ) (S : ℝ) : + Continuous (fun x : ℝ => orderedAffine m n (S+x) x) := by + have hp : Continuous (fun x : ℝ => (S+x,x)) := by fun_prop + exact (orderedAffine_continuous m n).comp hp + +theorem orderedAffine_shift_div_continuous (m : ℝ) (n : ℕ) (S : ℝ) : + Continuous (fun x : ℝ => orderedAffine m n (S+x) x/(max 1 x)) := + (orderedAffine_shift_continuous m n S).div (continuous_const.max continuous_id) + (fun x => ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _))) + +theorem orderedAffine_zero (m S b : ℝ) : orderedAffine m 0 S b=3*S/m-2 := by + simp [orderedAffine,orderedMass,orderedFirstMoment] + +theorem orderedAffine_succ (m : ℝ) (n : ℕ) (S b : ℝ) : + orderedAffine m (n+1) S b= + ∫ x : ℝ in 1..baseCutoff b,orderedAffine m n (S+x) x/(max 1 x) := by + have hd : ∀ x : ℝ,max 1 x ≠ 0 := fun x => ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _)) + have hM : Continuous (fun x : ℝ => orderedMass n x/(max 1 x)) := + (orderedMass_continuous n).div (continuous_const.max continuous_id) hd + have hF : Continuous (fun x : ℝ => (x*orderedMass n x+orderedFirstMoment n x)/(max 1 x)) := + ((continuous_id.mul (orderedMass_continuous n)).add (orderedFirstMoment_continuous n)).div + (continuous_const.max continuous_id) hd + change (3*S/m-2)*(∫ x : ℝ in 1..baseCutoff b,orderedMass n x/(max 1 x))+ + (3/m)*(∫ x : ℝ in 1..baseCutoff b,(x*orderedMass n x+orderedFirstMoment n x)/(max 1 x))=_ + rw [← intervalIntegral.integral_const_mul,← intervalIntegral.integral_const_mul, + ← intervalIntegral.integral_add + ((hM.const_mul (3*S/m-2)).intervalIntegrable (μ := volume) 1 _) + ((hF.const_mul (3/m)).intervalIntegrable (μ := volume) 1 _)] + apply intervalIntegral.integral_congr + intro x _ + dsimp only [orderedAffine] + ring + +theorem orderedAffine_at_two (n : ℕ) : + orderedAffine ((n+1:ℕ):ℝ) (n+1) 0 2= + (3/Real.log 2-2)*(Real.log 2)^(n+1)/((n+1).factorial:ℝ) := by + rw [orderedAffine,orderedMass_eq (n+1) (by norm_num) le_rfl, + orderedFirstMoment_eq n (by norm_num) le_rfl] + norm_num only [mul_zero,zero_div,zero_sub,sub_self,sub_zero,show (2:ℝ)-1=1 by norm_num,one_mul] + rw [Nat.factorial_succ,pow_succ,Nat.cast_mul] + have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity + have hf : (n.factorial:ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + have hl : Real.log 2 ≠ 0 := (Real.log_pos (by norm_num : (1:ℝ)<2)).ne' + field_simp + ring + +end ErdosOmissionTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/OrderedWindowKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/OrderedWindowKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..b49ed1b2ea5f8e3a915e8877de78b5804496543a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/OrderedWindowKernel.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.TerminalForceIntegral + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission ErdosContinuousBoundary + +noncomputable def windowKernel (S a u c : ℝ) : ℝ := + ((S+a+u+2*c)^3-(S+2*a)^3)/(12*(max 1 a)*(max 1 u)*(max 1 c)^2) +noncomputable def windowMiddle (S a u : ℝ) : ℝ := + ∫ c : ℝ in 1..baseCutoff u,windowKernel S a u c +noncomputable def windowOuter (S a : ℝ) : ℝ := + ∫ u : ℝ in 1..baseCutoff a,windowMiddle S a u +noncomputable def windowMass (S b : ℝ) : ℝ := + ∫ a : ℝ in 1..baseCutoff b,windowOuter S a + +theorem windowKernel_continuous (S : ℝ) : + Continuous (fun q : (ℝ×ℝ)×ℝ => windowKernel S q.1.1 q.1.2 q.2) := by + have hn : Continuous (fun q : (ℝ×ℝ)×ℝ => (S+q.1.1+q.1.2+2*q.2)^3-(S+2*q.1.1)^3) := by fun_prop + have hd : Continuous (fun q : (ℝ×ℝ)×ℝ => 12*(max 1 q.1.1)*(max 1 q.1.2)*(max 1 q.2)^2) := by fun_prop + apply hn.div hd + intro q + have h1 : 0 < max (1:ℝ) q.1.1 := (by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _) + have h2 : 0 < max (1:ℝ) q.1.2 := (by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _) + have h3 : 0 < max (1:ℝ) q.2 := (by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _) + positivity + +theorem windowMiddle_continuous (S : ℝ) : Continuous (fun p : ℝ×ℝ => windowMiddle S p.1 p.2) := by + exact continuous_variable_upper_integral (fun p c => windowKernel S p.1 p.2 c) + (windowKernel_continuous S) (fun p => baseCutoff p.2) + (continuous_const.max (continuous_const.min continuous_snd)) + +theorem windowOuter_continuous (S : ℝ) : Continuous (windowOuter S) := by + have hp : Continuous (fun q : (ℝ×ℝ)×ℝ => (q.1.1,q.2)) := by fun_prop + have hF : Continuous (fun q : (ℝ×ℝ)×ℝ => windowMiddle S q.1.1 q.2) := + (windowMiddle_continuous S).comp hp + have hcap : Continuous (fun p : ℝ×ℝ => baseCutoff p.1) := + continuous_const.max (continuous_const.min continuous_fst) + have hh : Continuous (fun p : ℝ×ℝ => ∫ u : ℝ in 1..baseCutoff p.1,windowMiddle S p.1 u) := + continuous_variable_upper_integral (fun p u => windowMiddle S p.1 u) hF (fun p => baseCutoff p.1) hcap + have hmap : Continuous (fun a : ℝ => (a,(0:ℝ))) := by fun_prop + change Continuous (fun a : ℝ => ∫ u : ℝ in 1..baseCutoff a,windowMiddle S a u) + simpa only [Function.comp_def] using! hh.comp hmap + +theorem windowKernel_literal {S a u c : ℝ} (ha : 1 ≤ a) (hu : 1 ≤ u) (hc : 1 ≤ c) : + windowKernel S a u c=lastWindowCoefficient S a u c/(a*u*c) := by + rw [windowKernel,max_eq_right ha,max_eq_right hu,max_eq_right hc,lastWindowCoefficient] + ring + +theorem scalarTailMass_zero_eq_windowMass {S b : ℝ} (hS : 0 ≤ S) (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + scalarTailMass 0 S b=windowMass S b := by + rw [scalarTailMass_zero_triple hS hb1 hb2,windowMass,baseCutoff_on hb1 hb2] + apply intervalIntegral.integral_congr + intro a ha + rw [uIcc_of_le hb1] at ha + dsimp only + rw [windowOuter,baseCutoff_on ha.1 (ha.2.trans hb2)] + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le ha.1] at hu + dsimp only + rw [windowMiddle,baseCutoff_on hu.1 (hu.2.trans (ha.2.trans hb2))] + apply intervalIntegral.integral_congr + intro c hc + rw [uIcc_of_le hu.1] at hc + exact (windowKernel_literal ha.1 hu.1 hc.1).symm + +end ErdosOmissionTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/OrdinaryMarkedWindow.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/OrdinaryMarkedWindow.lean new file mode 100644 index 0000000000000000000000000000000000000000..3dcd3554794a54cab02bdc3649286e2e0ec46e0d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/OrdinaryMarkedWindow.lean @@ -0,0 +1,270 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.RawInitialDelay + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.KernelPotential + +variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + +lemma potential_factor_right (B : Kernel α β) (U : Kernel α α) : + potential B U = B ∘ₖ potential Kernel.id U := by + simpa only [Kernel.comp_id] using potential_comp_left (Kernel.id : Kernel α α) B U + +lemma kernel_middle_power (S H : Kernel α α) (n : ℕ) : + S ∘ₖ ((H ∘ₖ S)^n) = ((S ∘ₖ H)^n) ∘ₖ S := (mul_pow_mul S H n).symm + +lemma potential_exchange (B : Kernel α β) (S H : Kernel α α) : + potential (B ∘ₖ S) (H ∘ₖ S) = (potential B (S ∘ₖ H)) ∘ₖ S := by + rw [potential,potential,Kernel.comp_sum_left] + apply congrArg Kernel.sum + funext n + rw [Kernel.comp_assoc,kernel_middle_power,← Kernel.comp_assoc] + +theorem potential_denesting (B : Kernel α β) (U H : Kernel α α) : + potential B (U+H) = + (potential B ((potential Kernel.id U) ∘ₖ H)) ∘ₖ potential Kernel.id U := by + rw [first_capture_decomposition,potential_factor_right B U,potential_factor_right H U,potential_exchange] + +lemma compose_mono_right_general {K L : Kernel α α} (hKL : K ≤ L) (B : Kernel α β) : + B ∘ₖ K ≤ B ∘ₖ L := by + intro x + apply Measure.le_iff.mpr + intro S hS + rw [Kernel.comp_apply' _ _ _ hS,Kernel.comp_apply' _ _ _ hS] + exact lintegral_mono' (hKL x) le_rfl + +lemma potential_mono_step_general {K L : Kernel α α} (hKL : K ≤ L) (B : Kernel α β) : + potential B K ≤ potential B L := by + apply potential_le_of_super B K (potential B L) + calc + _ ≤ B+(potential B L) ∘ₖ L := fun x => add_le_add le_rfl ((compose_mono_right_general hKL _) x) + _ = _ := (potential_unfold B L).symm + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.KernelPotential + +variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + +noncomputable def stateFilter {S : Set α} (hS : MeasurableSet S) : Kernel α α := Kernel.id.restrict hS + +instance stateFilter_isFiniteKernel {S : Set α} (hS : MeasurableSet S) : IsFiniteKernel (stateFilter hS) := by + unfold stateFilter + infer_instance + +lemma stateFilter_apply {S : Set α} (hS : MeasurableSet S) (x : α) : + stateFilter hS x = if x ∈ S then Measure.dirac x else 0 := by + classical + rw [stateFilter,Kernel.restrict_apply,Kernel.id_apply,restrict_dirac' hS] + +lemma stateFilter_mass {S : Set α} (hS : MeasurableSet S) (x : α) : + stateFilter hS x univ = if x ∈ S then 1 else 0 := by + classical + rw [stateFilter_apply] + split_ifs <;> simp + +lemma stateFilter_output (K : Kernel α β) {S : Set β} (hS : MeasurableSet S) : + stateFilter hS ∘ₖ K = K.restrict hS := by + rw [stateFilter,Kernel.comp_restrict,Kernel.id_comp] + +lemma stateFilter_input (K : Kernel α β) {S : Set α} (hS : MeasurableSet S) (x : α) : + (K ∘ₖ stateFilter hS) x = if x ∈ S then K x else 0 := by + classical + by_cases hx : x ∈ S + · rw [ite_eq_left hx] + ext B hB + rw [Kernel.comp_apply' _ _ _ hB,stateFilter_apply,ite_eq_left hx,lintegral_dirac' x (K.measurable_coe hB)] + · rw [ite_eq_right hx] + ext B hB + rw [Kernel.comp_apply' _ _ _ hB,stateFilter_apply,ite_eq_right hx,lintegral_zero_measure] + rfl + +lemma stateFilter_mono {S T : Set α} (hS : MeasurableSet S) (hT : MeasurableSet T) (hST : S ⊆ T) : + stateFilter hS ≤ stateFilter hT := by + classical + intro x + by_cases hx : x ∈ S + · rw [stateFilter_apply,stateFilter_apply,ite_eq_left hx,ite_eq_left (hST hx)] + · rw [stateFilter_apply,ite_eq_right hx] + exact Measure.zero_le _ + +instance stateFilter_stopping_isMarkov (R : Kernel α α) [IsMarkovKernel R] + {S : Set α} (hS : MeasurableSet S) : IsMarkovKernel (stateFilter hS+R ∘ₖ stateFilter hS.compl) := by + classical + constructor + intro x + constructor + rw [_root_.add_apply,Measure.add_apply,stateFilter_mass,stateFilter_input] + by_cases hx : x ∈ S <;> simp [hx] + +lemma capturePotential_mass_le_one (B H : Kernel α α) [IsFiniteKernel B] [IsFiniteKernel H] + [IsMarkovKernel (B+H)] (x : α) : potential B H x univ ≤ 1 := by + have (n : ℕ) : IsFiniteKernel (H^n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel α α); infer_instance + | succ n ih => rw [pow_succ']; change IsFiniteKernel (H ∘ₖ (H^n)); infer_instance + have hs (n : ℕ) : (B ∘ₖ (H^n)) x univ+(H^(n+1)) x univ=(H^n) x univ := by + have hp : H^(n+1)=H ∘ₖ (H^n) := pow_succ' _ _ + calc + _ = ((B+H) ∘ₖ (H^n)) x univ := by rw [Kernel.comp_add_left,_root_.add_apply,Measure.add_apply,hp] + _ = _ := by + rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ] + simp only [measure_univ,lintegral_const,one_mul] + have hf (n : ℕ) : (H^n) x univ+∑ k ∈ Finset.range n, (B ∘ₖ (H^k)) x univ=1 := by + induction n with + | zero => change (Measure.dirac x) univ+0=1; simp + | succ n ih => + rw [Finset.sum_range_succ] + calc + _ = (∑ k ∈ Finset.range n, (B ∘ₖ (H^k)) x univ)+ + ((B ∘ₖ (H^n)) x univ+(H^(n+1)) x univ) := by ac_rfl + _ = _ := by rw [hs]; simpa only [add_comm] using ih + rw [potential,Kernel.sum_apply' _ _ MeasurableSet.univ,ENNReal.tsum_eq_iSup_nat] + apply iSup_le + intro n + calc + _ ≤ (H^n) x univ+∑ k ∈ Finset.range n, (B ∘ₖ (H^k)) x univ := le_add_left le_rfl + _ = 1 := hf n + +lemma currentHit_outside (R : Kernel α α) {S : Set α} (hS : MeasurableSet S) (x : α) (hx : x ∉ S) : + potential (stateFilter hS) (R ∘ₖ stateFilter hS.compl) x = + (potential (stateFilter hS) (R ∘ₖ stateFilter hS.compl) ∘ₖ R) x := by + classical + conv_lhs => + rw [potential_unfold,_root_.add_apply,stateFilter_apply,ite_eq_right hx, + ← Kernel.comp_assoc,stateFilter_input,ite_eq_left (show x ∈ Sᶜ from hx),zero_add] + +lemma currentHit_inside (R : Kernel α α) {S : Set α} (hS : MeasurableSet S) (x : α) (hx : x ∈ S) : + 1 ≤ potential (stateFilter hS) (R ∘ₖ stateFilter hS.compl) x univ := by + rw [potential_unfold,_root_.add_apply,Measure.add_apply,stateFilter_mass,ite_eq_left hx] + exact le_add_right le_rfl + +theorem restricted_crossing_le_current_hit (R : Kernel α α) {S T : Set α} + (hS : MeasurableSet S) (hT : MeasurableSet T) (hTS : T ⊆ Sᶜ) (x : α) (hx : x ∈ T) : + potential (R.restrict hS) (R.restrict hT) x univ ≤ + potential (stateFilter hS) (R ∘ₖ stateFilter hS.compl) x univ := by + rw [← stateFilter_output R hS,← stateFilter_output R hT,potential_exchange] + have hK : R ∘ₖ stateFilter hT ≤ R ∘ₖ stateFilter hS.compl := + compose_mono_right_general (stateFilter_mono hT hS.compl hTS) R + have hP := potential_mono_step_general hK (stateFilter hS) + have he := currentHit_outside R hS x (hTS hx) + exact ((compose_mono_left hP R) x univ).trans_eq (congrArg (fun μ : Measure α => μ univ) he.symm) + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.KernelPotential + +lemma cycleBranch_mass_partition (z : OddCost) : + cycleBranchKernel true z univ+cycleBranchKernel false z univ=1 := by + rw [← Measure.add_apply,← _root_.add_apply,cycleBranch_sum] + exact measure_univ + +lemma nextMarkWeight_le_one (z : OddCost) : nextMarkWeight z ≤ 1 := by + change cycleBranchKernel true z univ ≤ 1 + calc + _ ≤ cycleBranchKernel true z univ+cycleBranchKernel false z univ := le_add_right le_rfl + _ = 1 := cycleBranch_mass_partition z + +noncomputable def markInputWeightKernel : Kernel OddCost OddCost := + Kernel.id.withDensity (fun _ z => nextMarkWeight z) + +instance markInputWeightKernel_isFiniteKernel : IsFiniteKernel markInputWeightKernel := by + apply Kernel.isFiniteKernel_withDensity_of_bounded _ (B := 1) (by simp) + exact fun _ z => nextMarkWeight_le_one z + +lemma markInputWeightKernel_apply (z : OddCost) : + markInputWeightKernel z=nextMarkWeight z • Measure.dirac z := by + rw [markInputWeightKernel,Kernel.withDensity_apply _ (f := fun _ z : OddCost => nextMarkWeight z) + (nextMarkWeight_measurable.comp measurable_snd),Kernel.id_apply,dirac_withDensity' nextMarkWeight_measurable] + +noncomputable def ordinaryCostWindow (v H : ℝ) : Set OddCost := Prod.snd ⁻¹' Icc v (v+H) + +lemma ordinaryCostWindow_measurable (v H : ℝ) : MeasurableSet (ordinaryCostWindow v H) := + measurableSet_Icc.preimage measurable_snd + +noncomputable def ordinaryWindowCapture (v H : ℝ) : Kernel OddCost OddCost := + markInputWeightKernel.restrict (ordinaryCostWindow_measurable v H) + +noncomputable def ordinaryWindowContinue (v H : ℝ) : Kernel OddCost OddCost := + cycleBranchKernel false+cycleBranchKernel true ∘ₖ stateFilter (ordinaryCostWindow_measurable v H).compl + +instance ordinaryWindowCapture_isFiniteKernel (v H : ℝ) : IsFiniteKernel (ordinaryWindowCapture v H) := by + unfold ordinaryWindowCapture + infer_instance + +instance ordinaryWindowContinue_isFiniteKernel (v H : ℝ) : IsFiniteKernel (ordinaryWindowContinue v H) := by + unfold ordinaryWindowContinue + infer_instance + +lemma ordinaryWindowCapture_mass (v H : ℝ) (z : OddCost) : + ordinaryWindowCapture v H z univ = if z ∈ ordinaryCostWindow v H then nextMarkWeight z else 0 := by + rw [ordinaryWindowCapture,Kernel.restrict_apply' _ _ _ MeasurableSet.univ,univ_inter, + markInputWeightKernel_apply,Measure.smul_apply,smul_eq_mul, + Measure.dirac_apply' z (ordinaryCostWindow_measurable v H)] + split_ifs <;> simp_all + +instance ordinaryWindow_stop_isMarkov (v H : ℝ) : + IsMarkovKernel (ordinaryWindowCapture v H+ordinaryWindowContinue v H) := by + constructor + intro z + constructor + rw [_root_.add_apply,Measure.add_apply,ordinaryWindowCapture_mass,ordinaryWindowContinue, + _root_.add_apply,Measure.add_apply,stateFilter_input] + by_cases hz : z ∈ ordinaryCostWindow v H + · simp only [hz,ite_true,mem_compl_iff,not_true_eq_false,ite_false,Measure.coe_zero,Pi.zero_apply,add_zero] + exact cycleBranch_mass_partition z + · simp only [hz,ite_false,mem_compl_iff,not_false_eq_true,ite_true,zero_add] + simpa only [nextMarkWeight,add_comm] using cycleBranch_mass_partition z + +noncomputable def ordinaryMarkedHit (v H : ℝ) : Kernel OddCost OddCost := + potential (ordinaryWindowCapture v H) (ordinaryWindowContinue v H) + +lemma ordinaryMarkedHit_mass_le_one (v H : ℝ) (z : OddCost) : ordinaryMarkedHit v H z univ ≤ 1 := + capturePotential_mass_le_one _ _ z + +noncomputable def unmarkedStar : Kernel OddCost OddCost := potential Kernel.id (cycleBranchKernel false) + +instance unmarkedStar_isSFiniteKernel : IsSFiniteKernel unmarkedStar := by unfold unmarkedStar; infer_instance + +lemma rawBeginning_unmarkedStar : rawBeginningKernel = unmarkedStar ∘ₖ cycleBranchKernel true := by + rw [unmarkedStar,potential,Kernel.comp_sum_left,rawBeginningKernel] + apply congrArg Kernel.sum + funext n + rw [Kernel.id_comp] + +theorem ordinaryMarkedHit_denested (v H : ℝ) : + ordinaryMarkedHit v H = + (potential (ordinaryWindowCapture v H) + (rawBeginningKernel ∘ₖ stateFilter (ordinaryCostWindow_measurable v H).compl)) ∘ₖ unmarkedStar := by + rw [ordinaryMarkedHit,ordinaryWindowContinue,rawBeginning_unmarkedStar,Kernel.comp_assoc] + exact potential_denesting _ _ _ + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/PairedDrift.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/PairedDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..fc691729330542c26aa52384c03cfadf2f30c6d7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/PairedDrift.lean @@ -0,0 +1,139 @@ +import OAI.NumberTheory.Jacobsthal.Paths.PairedHitting + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.PairedDrift + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathMeasures KernelDensityBridge +open RegenerationDrift CompactExponentialMoments PairedHitting + +noncomputable def V (s : OddState) : ℝ := Real.exp s.1 + +theorem V_pos (s : OddState) : 0 < V s := Real.exp_pos _ +theorem V_one_le (s : OddState) : 1 ≤ V s := Real.one_le_exp_iff.mpr (by linarith [s.2]) +theorem V_measurable : Measurable V := Real.measurable_exp.comp measurable_subtype_coe + +theorem paired_drift : ∃ a C : ℝ, 0 < a ∧ a < 1 ∧ 0 < C ∧ ∀ s : OddState, + (∫⁻ t, ENNReal.ofReal (V t) ∂pairedOdd s) ≤ ENNReal.ofReal a * ENNReal.ofReal (V s) + ENNReal.ofReal C := by + obtain ⟨C, hC, he, ho⟩ := kernel_global_drift + have hκ := driftFactor_pos + have hκ1 := driftFactor_lt_one + have he' : ∀ s : EvenState, (∫⁻ t : OddState, ENNReal.ofReal (Real.exp t.1) ∂evenToOdd s) ≤ + ENNReal.ofReal driftFactor * ENNReal.ofReal (Real.exp s.1) + ENNReal.ofReal C := by + intro s + rw [evenToOdd_lintegral_ratio s (H := fun x : ℝ => ENNReal.ofReal (Real.exp x)) (ENNReal.measurable_ofReal.comp Real.measurable_exp)] + have h := ENNReal.ofReal_le_ofReal (he s).2 + rw [ofReal_integral_eq_lintegral_ofReal (he s).1 (Eventually.of_forall (fun t => (Real.exp_pos t).le)), + ENNReal.ofReal_add (mul_pos hκ (Real.exp_pos _)).le hC.le, ENNReal.ofReal_mul hκ.le] at h + exact h + have ho' : ∀ s : OddState, (∫⁻ t : EvenState, ENNReal.ofReal (Real.exp t.1) ∂oddToEven s) ≤ + ENNReal.ofReal driftFactor * ENNReal.ofReal (Real.exp s.1) + ENNReal.ofReal C := by + intro s + rw [oddToEven_lintegral_ratio s (H := fun x : ℝ => ENNReal.ofReal (Real.exp x)) (ENNReal.measurable_ofReal.comp Real.measurable_exp)] + have h := ENNReal.ofReal_le_ofReal (ho s).2 + rw [ofReal_integral_eq_lintegral_ofReal (ho s).1 (Eventually.of_forall (fun t => (Real.exp_pos t).le)), + ENNReal.ofReal_add (mul_pos hκ (Real.exp_pos _)).le hC.le, ENNReal.ofReal_mul hκ.le] at h + exact h + refine ⟨driftFactor ^ 2, (1 + driftFactor) * C, sq_pos_of_pos hκ, by nlinarith, + mul_pos (by linarith) hC, ?_⟩ + intro s + rw [pairedOdd, Kernel.lintegral_comp evenToOdd oddToEven s (g := fun t : OddState => ENNReal.ofReal (V t)) (ENNReal.measurable_ofReal.comp V_measurable)] + change (∫⁻ t : EvenState, ∫⁻ u : OddState, ENNReal.ofReal (Real.exp u.1) ∂evenToOdd t ∂oddToEven s) ≤ _ + have hEV : Measurable (fun t : EvenState => ENNReal.ofReal (Real.exp t.1)) := + ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp measurable_subtype_coe) + calc + _ ≤ ∫⁻ t : EvenState, ENNReal.ofReal driftFactor * ENNReal.ofReal (Real.exp t.1) + ENNReal.ofReal C ∂oddToEven s := + lintegral_mono he' + _ = ENNReal.ofReal driftFactor * (∫⁻ t : EvenState, ENNReal.ofReal (Real.exp t.1) ∂oddToEven s) + ENNReal.ofReal C := by + rw [lintegral_add_left (f := fun t : EvenState => ENNReal.ofReal driftFactor * ENNReal.ofReal (Real.exp t.1)) (measurable_const.mul hEV) (fun _ => ENNReal.ofReal C), lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + simp + _ ≤ ENNReal.ofReal driftFactor * (ENNReal.ofReal driftFactor * ENNReal.ofReal (Real.exp s.1) + ENNReal.ofReal C) + ENNReal.ofReal C := + add_le_add (mul_le_mul le_rfl (ho' s) zero_le zero_le) le_rfl + _ = _ := by + rw [ENNReal.ofReal_pow hκ.le, ENNReal.ofReal_mul (by linarith : 0 ≤ 1 + driftFactor), + ENNReal.ofReal_add zero_le_one hκ.le, ENNReal.ofReal_one] + dsimp [V] + ring + +theorem pairedKilled_drift : ∃ a C : ℝ, 0 < a ∧ a < 1 ∧ 0 < C ∧ ∀ s : OddState, + (∫⁻ t, ENNReal.ofReal (V t) ∂pairedKilled s) ≤ ENNReal.ofReal a * ENNReal.ofReal (V s) + ENNReal.ofReal C := by + obtain ⟨a, C, ha, ha1, hC, hb⟩ := paired_drift + refine ⟨a, C, ha, ha1, hC, ?_⟩ + intro s + rw [pairedKilled, Kernel.lintegral_restrict] + exact le_trans (setLIntegral_le_lintegral _ _) (hb s) + +theorem pairedKilled_iterated_drift : ∃ a B : ℝ, 0 < a ∧ a < 1 ∧ 0 < B ∧ + ∀ n : ℕ, ∀ s : OddState, + (∫⁻ t, ENNReal.ofReal (V t) ∂(pairedKilled ^ n) s) ≤ + ENNReal.ofReal (a ^ n * V s + B) := by + obtain ⟨a, C, ha, ha1, hC, hOne⟩ := pairedKilled_drift + let B := C / (1 - a) + have hB : 0 < B := div_pos hC (by linarith) + have hBE : a * B + C = B := by dsimp [B]; field_simp [show 1 - a ≠ 0 by linarith]; ring + have hEE : ENNReal.ofReal a * ENNReal.ofReal B + ENNReal.ofReal C = ENNReal.ofReal B := by + rw [← ENNReal.ofReal_mul ha.le, ← ENNReal.ofReal_add (mul_pos ha hB).le hC.le, hBE] + have hV : Measurable (fun s : OddState => ENNReal.ofReal (V s)) := ENNReal.measurable_ofReal.comp V_measurable + have hIter : ∀ n : ℕ, ∀ s : OddState, + (∫⁻ t, ENNReal.ofReal (V t) ∂(pairedKilled ^ n) s) ≤ + (ENNReal.ofReal a) ^ n * ENNReal.ofReal (V s) + ENNReal.ofReal B := by + intro n + induction n with + | zero => + intro s + change (∫⁻ t, ENNReal.ofReal (V t) ∂Measure.dirac s) ≤ _ + rw [lintegral_dirac' s hV] + simp only [pow_zero, one_mul] + exact le_add_of_nonneg_right zero_le + | succ n ih => + intro s + have hp : pairedKilled ^ (n + 1) = pairedKilled ∘ₖ (pairedKilled ^ n) := pow_succ' pairedKilled n + rw [hp, Kernel.lintegral_comp _ _ _ hV] + calc + _ ≤ ∫⁻ t, ENNReal.ofReal a * ENNReal.ofReal (V t) + ENNReal.ofReal C ∂(pairedKilled ^ n) s := + lintegral_mono hOne + _ = ENNReal.ofReal a * (∫⁻ t, ENNReal.ofReal (V t) ∂(pairedKilled ^ n) s) + + ENNReal.ofReal C * (pairedKilled ^ n) s univ := by + rw [lintegral_add_left (f := fun t : OddState => ENNReal.ofReal a * ENNReal.ofReal (V t)) (measurable_const.mul hV) (fun _ => ENNReal.ofReal C), lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + lintegral_const] + _ ≤ ENNReal.ofReal a * ((ENNReal.ofReal a) ^ n * ENNReal.ofReal (V s) + ENNReal.ofReal B) + ENNReal.ofReal C := by + apply add_le_add + · exact mul_le_mul le_rfl (ih s) zero_le zero_le + · simpa only [mul_one] using mul_le_mul (le_refl (ENNReal.ofReal C)) (paired_survival_le_one n s) zero_le zero_le + _ = _ := by rw [mul_add, add_assoc, hEE, pow_succ]; ring + refine ⟨a, B, ha, ha1, hB, ?_⟩ + intro n s + rw [ENNReal.ofReal_add (mul_nonneg (pow_nonneg ha.le _) (V_pos s).le) hB.le, + ENNReal.ofReal_mul (pow_nonneg ha.le _), ENNReal.ofReal_pow ha.le] + exact hIter n s + +theorem block_drift_algebra {a B p v e mass : ℝ} (ha : a ≤ 1 / 4) (hB : 0 ≤ B) + (hp : 0 < p) (hp1 : p ≤ 1) (hv : 0 ≤ v) (he : e ≤ a * v + B) (hm : mass ≤ 1) + (hcase : mass ≤ 1 - p ∨ 8 * B ≤ v) : + e + (2 * B / p) * mass ≤ (1 - p / 2) * (v + 2 * B / p) := by + let D := 2 * B / p + have hD : 0 ≤ D := div_nonneg (by linarith) hp.le + have hpD : p * D = 2 * B := by dsimp [D]; field_simp + have hav : a * v ≤ v / 4 := by nlinarith [mul_le_mul_of_nonneg_right ha hv] + have hrv : v / 2 ≤ (1 - p / 2) * v := by + nlinarith [mul_le_mul_of_nonneg_right (show (1 : ℝ) / 2 ≤ 1 - p / 2 by linarith) hv] + change e + D * mass ≤ (1 - p / 2) * (v + D) + rcases hcase with hsmall | hlarge + · have hmD := mul_le_mul_of_nonneg_left hsmall hD + nlinarith + · have hmD := mul_le_mul_of_nonneg_left hm hD + nlinarith + +end NumberTheoryLean.PairedDrift + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/PaperSubsetTagEvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/PaperSubsetTagEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..9dc862219397d3ee99f52ab98c76006b225b1cf5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/PaperSubsetTagEvent.lean @@ -0,0 +1,110 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FiniteBoxWordMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosSubsetWord +open ErdosCofactorChoices ErdosTagEvent +open NumberTheoryLean ActualSourceTags ActualBinOwners FiniteFirstTag WrongOwnerBinMass +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem subset_bad_tag_inclusion {Y w top Cs eta xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (a : ℕ → ℤ) (q : ℚ) (hf : f ∈ selections (globalBins w top xi) mult) + (howner : ∀ b ∈ occupiedSearch w top xi mult, + nearFull eta (lower w top xi b) (width w top xi b) a q → + owner Y w Cs eta (lower w top xi b) (width w top xi b) a=some q) + (halign : ∀ b ∈ occupiedSearch w top xi mult,∀ p ∈ f b,aligns a q p) + (hbad : ¬∃ t,sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (descendingWord f)=some t ∧ t.rational=q) : + (∀ b ∈ occupiedSearch w top xi mult,¬nearFull eta (lower w top xi b) (width w top xi b) a q) ∨ + ∃ b ∈ occupiedSearch w top xi mult,∃ p ∈ f b, + p ∈ wrongOwnerPrimes Y w Cs eta (lower w top xi b) (width w top xi b) a q := by + have hmem := (mem_selections _ mult f).mp hf + by_cases hn : ∀ b ∈ occupiedSearch w top xi mult, + ¬nearFull eta (lower w top xi b) (width w top xi b) a q + · exact Or.inl hn + · push Not at hn + obtain ⟨b,hb,hnear⟩ := hn + have hpos : 0 < (f b).card := by rw [(hmem b).2]; exact (Finset.mem_filter.mp hb).2.2 + obtain ⟨p,hp⟩ := Finset.card_pos.mp hpos + have hl := selected_prime_label hw htop hxi mult f hf b hp + have ho := howner b hb hnear + have hs := (Finset.mem_filter.mp hb).2.1 + have hbin := (hmem b).1 hp + have hc : tagCandidate Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a p=some (b,q) := by + have hh := candidate_of_witness Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a p q + (by rw [hl]; exact hbin) (by rw [hl]; exact hs) (by rw [hl]; exact ho) (halign b hb p hp) + simpa only [hl] using hh + obtain ⟨t,ht⟩ := sourceTag_exists_of_candidate Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (descendingWord f) ((mem_descendingWord f p).mpr ⟨b,hp⟩) hc + have hne : t.rational ≠ q := fun he => hbad ⟨t,ht,he⟩ + obtain ⟨pre,p',tail,heq,_hindex,_hbin,hp',hsearch,hor,har,_hbefore⟩ := + sourceTag_witness Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (descendingWord f) ht + have hin : p' ∈ descendingWord f := by rw [heq]; simp + obtain ⟨b',hin⟩ := (mem_descendingWord f p').mp hin + have hl' := selected_prime_label hw htop hxi mult f hf b' hin + rw [hl'] at hsearch hor hp' + have hbpos : 0 < mult b' := by + rw [← (hmem b').2] + exact Finset.card_pos.mpr ⟨p',hin⟩ + have hb' : b' ∈ occupiedSearch w top xi mult := Finset.mem_filter.mpr ⟨Finset.mem_univ _,hsearch,hbpos⟩ + exact Or.inr ⟨b',hb',p',hin,Finset.mem_filter.mpr ⟨hp',halign b' hb' p' hin,t.rational,hor,hne,har⟩⟩ + +end ErdosSubsetWord + + + +namespace ErdosSubsetWord +open _root_.Filter ErdosCofactorChoices ErdosTagEvent +open NumberTheoryLean ActualSourceTags ActualBinOwners FiniteFirstTag WrongOwnerBinMass +open JacobsthalSourceScale PaperBinOwners +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem source_globalBins (top xi : ℝ) : + globalBins (sourceW (Real.log top)) top xi=actualBins top xi := rfl + +theorem paper_subset_bad_tag_inclusion {Cs eta xi : ℝ} (hCs : 0 ≤ Cs) (heta : eta < 1/2) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ (Y : ℕ),Y ≤ ⌊top^2/(Real.log top)^2⌋₊ → + ∀ (mult : Fin (binCount (sourceW (Real.log top)) top xi) → ℕ) + (f : Fin (binCount (sourceW (Real.log top)) top xi) → Finset ℕ) (a : ℕ → ℤ) (q : ℚ), + eligible Y (sourceW (Real.log top)) Cs q → f ∈ selections (actualBins top xi) mult → + (∀ b ∈ occupiedSearch (sourceW (Real.log top)) top xi mult,∀ p ∈ f b,aligns a q p) → + (¬∃ t,sourceTag Y (sourceW (Real.log top)) Cs eta + (lower (sourceW (Real.log top)) top xi) (width (sourceW (Real.log top)) top xi) + (label (zero_lt_one.trans hw) htop hxi) a (descendingWord f)=some t ∧ t.rational=q) → + (∀ b ∈ occupiedSearch (sourceW (Real.log top)) top xi mult, + ¬nearFull eta (lower (sourceW (Real.log top)) top xi b) + (width (sourceW (Real.log top)) top xi b) a q) ∨ + ∃ b ∈ occupiedSearch (sourceW (Real.log top)) top xi mult,∃ p ∈ f b, + p ∈ wrongOwnerPrimes Y (sourceW (Real.log top)) Cs eta + (lower (sourceW (Real.log top)) top xi b) (width (sourceW (Real.log top)) top xi b) a q := by + filter_upwards [paper_bin_span hxi hxi1,paper_owner_identifies hCs heta hxi hxi1] with top hspan hidentify + have hw : 1 < sourceW (Real.log top) := by linarith [hspan.1] + refine ⟨hw,hspan.2.1,?_⟩ + intro Y hY mult f a q he hf halign hbad + apply subset_bad_tag_inclusion hw hspan.2.1 hxi mult f a q hf _ halign hbad + intro b hb hnear + exact hidentify Y hY b (Finset.mem_filter.mp hb).2.1 a q he hnear + +end ErdosSubsetWord + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/PaperTagEventInclusion.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/PaperTagEventInclusion.lean new file mode 100644 index 0000000000000000000000000000000000000000..32827a88c7a767e41c5dc49aa59c310395bc50c9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/PaperTagEventInclusion.lean @@ -0,0 +1,124 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ActualPatternCoordinates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosTagEvent +open NumberTheoryLean ActualSourceTags ActualBinOwners FiniteFirstTag +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open PrimeChoiceBoxMass WrongOwnerBinMass ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem pattern_bad_tag_inclusion {m : ℕ} {Y w top Cs eta xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (pattern : Fin m → Fin (binCount w top xi)) (f : Fin m → ℕ) (a : ℕ → ℤ) (q : ℚ) + (hf : f ∈ choices (patternBins w top xi pattern)) + (howner : ∀ i ∈ searchPositions w top xi pattern, + nearFull eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a q → + owner Y w Cs eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a=some q) + (halign : ∀ i ∈ searchPositions w top xi pattern,aligns a q (f i)) + (hbad : ¬∃ t,sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (List.ofFn f)=some t ∧ t.rational=q) : + (∀ i ∈ searchPositions w top xi pattern, + ¬nearFull eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a q) ∨ + ∃ i ∈ searchPositions w top xi pattern,f i ∈ + wrongOwnerPrimes Y w Cs eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a q := by + by_cases hnone : ∀ i ∈ searchPositions w top xi pattern, + ¬nearFull eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a q + · exact Or.inl hnone + · push Not at hnone + obtain ⟨i,hi,hnear⟩ := hnone + have ho := howner i hi hnear + have hl := actual_choice_label hw htop hxi pattern f hf i + have hp := actual_choice_coordinate pattern f hf i + have hs := (Finset.mem_filter.mp hi).2 + have hc : tagCandidate Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (f i)=some (pattern i,q) := by + have hh := candidate_of_witness Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (f i) q + (by rw [hl]; exact hp) (by rw [hl]; exact hs) (by rw [hl]; exact ho) (halign i hi) + simpa only [hl] using hh + obtain ⟨t,ht⟩ := sourceTag_exists_of_candidate Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (List.ofFn f) (List.mem_ofFn.mpr ⟨i,rfl⟩) hc + have hne : t.rational ≠ q := fun he => hbad ⟨t,ht,he⟩ + obtain ⟨j,hj,_hbin,hor,har⟩ := first_tag_coordinate hw htop hxi pattern f a hf t ht + refine Or.inr ⟨j,hj,?_⟩ + exact Finset.mem_filter.mpr ⟨actual_choice_coordinate pattern f hf j, + halign j hj,t.rational,hor,hne,har⟩ + +theorem nonnearfull_card_lt (eta R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) + (hn : ¬nearFull eta R xi a q) : + (((primeBin R xi).filter (aligns a q)).card:ℝ) < (1-eta)*((primeBin R xi).card:ℝ) := + lt_of_not_ge hn + +end ErdosTagEvent + + + +namespace ErdosTagEvent +open _root_.Filter NumberTheoryLean ActualSourceTags ActualBinOwners FiniteFirstTag +open JacobsthalSourceScale PaperBinOwners +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open PrimeChoiceBoxMass WrongOwnerBinMass ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem paper_bad_tag_inclusion {Cs eta xi : ℝ} (hCs : 0 ≤ Cs) (heta : eta < 1/2) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ (Y : ℕ),Y ≤ ⌊top^2/(Real.log top)^2⌋₊ → ∀ (m : ℕ) + (pattern : Fin m → Fin (binCount (sourceW (Real.log top)) top xi)) (f : Fin m → ℕ) + (a : ℕ → ℤ) (q : ℚ),eligible Y (sourceW (Real.log top)) Cs q → + f ∈ choices (patternBins (sourceW (Real.log top)) top xi pattern) → + (∀ i ∈ searchPositions (sourceW (Real.log top)) top xi pattern,aligns a q (f i)) → + (¬∃ t,sourceTag Y (sourceW (Real.log top)) Cs eta + (lower (sourceW (Real.log top)) top xi) (width (sourceW (Real.log top)) top xi) + (label (zero_lt_one.trans hw) htop hxi) a (List.ofFn f)=some t ∧ t.rational=q) → + (∀ i ∈ searchPositions (sourceW (Real.log top)) top xi pattern, + ¬nearFull eta (lower (sourceW (Real.log top)) top xi (pattern i)) + (width (sourceW (Real.log top)) top xi (pattern i)) a q) ∨ + ∃ i ∈ searchPositions (sourceW (Real.log top)) top xi pattern,f i ∈ + wrongOwnerPrimes Y (sourceW (Real.log top)) Cs eta + (lower (sourceW (Real.log top)) top xi (pattern i)) + (width (sourceW (Real.log top)) top xi (pattern i)) a q := by + filter_upwards [paper_bin_span hxi hxi1,paper_owner_identifies hCs heta hxi hxi1] with top hspan hidentify + have hw : 1 < sourceW (Real.log top) := by linarith [hspan.1] + refine ⟨hw,hspan.2.1,?_⟩ + intro Y hY m pattern f a q he hf halign hbad + apply pattern_bad_tag_inclusion hw hspan.2.1 hxi pattern f a q hf _ halign hbad + intro i hi hnear + exact hidentify Y hY (pattern i) (Finset.mem_filter.mp hi).2 a q he hnear + +theorem bad_aligned_subset_wrong {m : ℕ} {Y w top Cs eta xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (pattern : Fin m → Fin (binCount w top xi)) (a : ℕ → ℤ) (q : ℚ) + (howner : ∀ i ∈ searchPositions w top xi pattern, + nearFull eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a q → + owner Y w Cs eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a=some q) + (hnear : ∃ i ∈ searchPositions w top xi pattern, + nearFull eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a q) : + ((alignedChoices (patternBins w top xi pattern) (searchPositions w top xi pattern) a q).filter + (fun f => ¬∃ t,sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (List.ofFn f)=some t ∧ t.rational=q)) ⊆ + (choices (patternBins w top xi pattern)).filter (fun f => + ∃ i ∈ searchPositions w top xi pattern,f i ∈ + wrongOwnerPrimes Y w Cs eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a q) := by + intro f hf + obtain ⟨hfa,hbad⟩ := Finset.mem_filter.mp hf + obtain ⟨hchoice,halign⟩ := Finset.mem_filter.mp hfa + have h := pattern_bad_tag_inclusion hw htop hxi pattern f a q hchoice howner halign hbad + rcases h with hnone | hwrong + · obtain ⟨i,hi,hnear⟩ := hnear + exact False.elim (hnone i hi hnear) + · exact Finset.mem_filter.mpr ⟨hchoice,hwrong⟩ + +end ErdosTagEvent + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/PhysicalMarkedRecord.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/PhysicalMarkedRecord.lean new file mode 100644 index 0000000000000000000000000000000000000000..e0157f7c928368cfdf9007aeb18ae702d8702080 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/PhysicalMarkedRecord.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.LastCycleRecord + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels + +noncomputable def recordFirst (c : CycleInputSignature) : CostState := c.2.2.1 +lemma recordFirst_measurable : Measurable recordFirst := + measurable_fst.comp (measurable_snd.comp measurable_snd) + +noncomputable def physicalMarkedRecord : Set CycleInputSignature := + {c | firstArrivalMark (recordFirst c)=true ∧ + (recordFirst c).2=c.1+cost (stateRatio (recordFirst c).1)} + +lemma physicalMarkedRecord_measurable : MeasurableSet physicalMarkedRecord := + ((firstArrivalMark_measurable.comp recordFirst_measurable) (measurableSet_singleton true)).inter + (measurableSet_eq_fun (measurable_snd.comp recordFirst_measurable) + (measurable_fst.add (cost_measurable.comp (stateRatio_measurable.comp + (measurable_fst.comp recordFirst_measurable))))) + +lemma source_record_physical (z : OddCost) (y : SourceCycleWitness) (hy : sourceMark y.1=true) : + sourceCycleInputSignature z y ∈ physicalMarkedRecord := by + exact ⟨hy,rfl⟩ + +lemma physicalMarkedRecord_witness {c : CycleInputSignature} (hc : c ∈ physicalMarkedRecord) : + ∃ t : EvenState, 209/100 ≤ t.1 ∧ t.1 ≤ 213/100 ∧ + recordFirst c=(Sum.inl t,c.1+cost t.1) := by + rcases hc with ⟨hm,hc⟩ + cases he : (recordFirst c).1 with + | inl t => + have ht : sourceMark t=true := by simpa only [firstArrivalMark,he,Sum.elim_inl] using hm + have hb : 209/100 ≤ t.1 ∧ t.1 ≤ 213/100 := by simpa [sourceMark] using ht + refine ⟨t,hb.1,hb.2,Prod.ext he ?_⟩ + simpa only [he,stateRatio,Sum.elim_inl] using hc + | inr t => simp [firstArrivalMark,he] at hm + +lemma sourceRecord_ae_physical (z : OddCost) : + ∀ᵐ c ∂sourceRecordKernel true z, c ∈ physicalMarkedRecord := by + rw [sourceRecordKernel_apply] + apply (ae_map_iff (sourceCycleInputSignature_measurable.comp measurable_prodMk_left).aemeasurable + physicalMarkedRecord_measurable).mpr + rw [sourceBranchWitnessKernel,Kernel.restrict_apply] + filter_upwards [ae_restrict_mem ((sourceMark_measurable.comp measurable_fst) (measurableSet_singleton true))] with y hy + exact source_record_physical z y hy + +lemma sourceLastRecord_ae_physical (w : List Bool) (z : OddCost) : + ∀ᵐ s ∂sourceMarkedWordKernel (w++[true]) z, lastCycleRecord w true s ∈ physicalMarkedRecord := by + apply (ae_map_iff (lastCycleRecord_measurable w true).aemeasurable physicalMarkedRecord_measurable).mp + rw [sourceLastRecord_law] + exact Kernel.ae_comp_of_ae_ae physicalMarkedRecord_measurable (Eventually.of_forall sourceRecord_ae_physical) + +lemma hitWordEvent_last_cost (w : List Bool) (v H : ℝ) : + ∀ s ∈ hitWordEvent w v H, (lastCycleRecord w true s).1 ∈ Icc v (v+H) := by + induction w with + | nil => intro s hs; exact hs + | cons b w ih => intro s hs; exact ih s.2 hs.2 + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/PreciseIncidenceMoment.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/PreciseIncidenceMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..b443eb03fac3caec910b91cb38dfcb1fc62e6e04 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/PreciseIncidenceMoment.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FactorDividesAbscissa + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosLineCollision +open ErdosInverseIncidence +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem precise_multiplicity_square_upper {α β : Type*} (A : Finset α) (Q : Finset β) + (R : α → β → Prop) (K : ℝ) (hK : 0 ≤ K) + (hpair : ∀ a ∈ A, ∀ b ∈ A, a ≠ b → + ((Q.filter (fun p => R a p ∧ R b p)).card : ℝ) ≤ K) : + (∑ p ∈ Q,(multiplicity A R p)^2) ≤ + (∑ p ∈ Q,multiplicity A R p)+K*(A.card : ℝ)^2 := by + rw [multiplicity_square_sum,multiplicity_sum] + calc + _ ≤ ∑ a ∈ A,∑ b ∈ A,((if b=a then (degree Q R a : ℝ) else 0)+K) := by + apply Finset.sum_le_sum + intro a ha + apply Finset.sum_le_sum + intro b hb + by_cases hab : b=a + · subst b + simp only [and_self,degree] + exact le_add_of_nonneg_right hK + · rw [ite_eq_right hab,zero_add] + exact hpair a ha b hb (Ne.symm hab) + _ = _ := by + simp only [Finset.sum_add_distrib,Finset.sum_ite_eq',Finset.sum_const,nsmul_eq_mul] + have he : (∑ a ∈ A,if a ∈ A then (degree Q R a : ℝ) else 0) = + ∑ a ∈ A,(degree Q R a : ℝ) := by simp + rw [he] + ring + +theorem precise_incidence_cauchy {α β : Type*} (A : Finset α) (Q : Finset β) + (R : α → β → Prop) (K B : ℝ) (hK : 0 ≤ K) (hB : 0 ≤ B) + (hQ : (Q.card : ℝ) ≤ B) + (hpair : ∀ a ∈ A, ∀ b ∈ A, a ≠ b → + ((Q.filter (fun p => R a p ∧ R b p)).card : ℝ) ≤ K) : + (∑ p ∈ Q,multiplicity A R p)^2 ≤ + B*(K*(A.card : ℝ)^2+∑ p ∈ Q,multiplicity A R p) := by + have hcs : (∑ p ∈ Q,multiplicity A R p)^2 ≤ (Q.card : ℝ)*(∑ p ∈ Q,(multiplicity A R p)^2) := by + simpa only [one_mul,one_pow,Finset.sum_const,nsmul_eq_mul,mul_one] using + Finset.sum_mul_sq_le_sq_mul_sq Q (fun _ => (1 : ℝ)) (multiplicity A R) + have hup := precise_multiplicity_square_upper A Q R K hK hpair + calc + _ ≤ (Q.card : ℝ)*(∑ p ∈ Q,(multiplicity A R p)^2) := hcs + _ ≤ B*(∑ p ∈ Q,(multiplicity A R p)^2) := mul_le_mul_of_nonneg_right hQ + (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + _ ≤ B*((∑ p ∈ Q,multiplicity A R p)+K*(A.card : ℝ)^2) := mul_le_mul_of_nonneg_left hup hB + _ = _ := by ring + +end ErdosLineCollision + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RawEvenMarkedHit.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawEvenMarkedHit.lean new file mode 100644 index 0000000000000000000000000000000000000000..7656fe86e59bab47e1de3be62c21f29a3673b239 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawEvenMarkedHit.lean @@ -0,0 +1,94 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RawInitialPacking + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.TransitionKernels + +abbrev RawEvenMarkedHitTrace (a : ℕ) := + Σ k : ℕ, RawHistory ((a+1)+2*k) × RawMarkedHitTrace ((a+1)+2*k) + +noncomputable def rawEvenHitContinuation (a : ℕ) (v H : ℝ) : Kernel (RawInitialPackedTrace a) (RawEvenMarkedHitTrace a) := + sigmaFamilyKernel (fun k : ℕ => + (Kernel.id : Kernel (RawHistory ((a+1)+2*k)) (RawHistory ((a+1)+2*k))) ×ₖ + rawRegMarkedFirstHitKernel ((a+1)+2*k) v H) + +instance rawEvenHitContinuation_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (rawEvenHitContinuation a v H) := by + apply sigmaFamilyKernel_isFinite_of_bound _ (B := 1) (by simp) + intro k y + rw [Kernel.id_prod_apply' _ _ MeasurableSet.univ,preimage_univ] + exact rawRegMarkedFirstHit_mass_le_one _ v H y + +noncomputable def rawEvenMarkedHitKernel (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawEvenMarkedHitTrace a) := + rawEvenHitContinuation a v H ∘ₖ packedInitialKernel a + +instance rawEvenMarkedHitKernel_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (rawEvenMarkedHitKernel a v H) := by + unfold rawEvenMarkedHitKernel + infer_instance + +theorem rawEvenMarkedHit_mass (a : ℕ) (v H : ℝ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + rawEvenMarkedHitKernel a v H h univ=ordinaryInitialHitMass s v H := by + let G : CostState → ℝ≥0∞ := fun c => ordinaryMarkedHit v H (decodeReturnedOdd c) univ + have hG : Measurable G := ((ordinaryMarkedHit v H).measurable_coe MeasurableSet.univ).comp decodeReturnedOdd_measurable + have he : (fun r => rawEvenHitContinuation a v H r univ) =ᵐ[packedInitialKernel a h] + fun r => G (packedInitialEndpoint a r) := by + filter_upwards [packedInitial_ae_regeneration a h s hs] with r hr + rcases r with ⟨k,y⟩ + rw [rawEvenHitContinuation,sigmaFamilyKernel_mass,Kernel.id_prod_apply' _ _ MeasurableSet.univ,preimage_univ, + rawRegMarkedFirstHitKernel,stateFilter_input, + ite_eq_left (show y ∈ lastRegeneration ((a+1)+2*k) from hr)] + let z := decodeReturnedOdd (rawLast ((a+1)+2*k) y) + have hz : rawLast ((a+1)+2*k) y=embedOdd z := (embed_decodeReturnedOdd_of_regeneration _ hr).symm + rw [rawMarkedFirstHit_mass _ v H y z hz] + rfl + rw [rawEvenMarkedHitKernel,Kernel.comp_apply' _ _ _ MeasurableSet.univ,lintegral_congr_ae he, + ← lintegral_map (g := packedInitialEndpoint a) hG (packedInitialEndpoint_measurable a), + packedInitial_endpoint_law a h s hs,lintegral_map hG embedOdd_measurable] + rfl + +lemma rawEvenMarkedHit_mass_le_one (a : ℕ) (v H : ℝ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : rawEvenMarkedHitKernel a v H h univ ≤ 1 := by + rw [rawEvenMarkedHit_mass a v H h s hs] + exact ordinaryInitialHitMass_le_one s v H + +theorem rawEvenMarkedHit_exponential (S : ℝ) : ∃ eta C eta0 B : ℝ, + 0 < eta ∧ 0 < C ∧ 0 < eta0 ∧ 0 ≤ B ∧ ∀ (a : ℕ) (h : RawHistory a) (s : EvenState), + rawLast a h=(Sum.inl s,0) → s.1 ≤ S → ∀ v H : ℝ, 0 ≤ H → + 1-rawEvenMarkedHitKernel a v H h univ ≤ + ENNReal.ofReal (C*Real.exp (-eta*H)+B*Real.exp (-eta0*v)) := by + obtain ⟨eta,C,eta0,B,heta,hC,heta0,hB,hBound⟩ := ordinaryInitialHit_exponential S + refine ⟨eta,C,eta0,B,heta,hC,heta0,hB,?_⟩ + intro a h s hs hS v H hH + rw [rawEvenMarkedHit_mass a v H h s hs] + exact hBound s hS v H hH + +theorem moving_raw_even_marked_hit {eps : ℝ} (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → ∀ (a : ℕ) (h : RawHistory a) (s : EvenState), + rawLast a h=(Sum.inl s,0) → 199/100 ≤ s.1 → s.1 ≤ 23/10 → + 1-rawEvenMarkedHitKernel a (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) h univ ≤ + ENNReal.ofReal eps := by + obtain ⟨rho,hrho,hMoving⟩ := moving_ordinary_marked_hit heps + refine ⟨rho,hrho,?_⟩ + intro K hK + filter_upwards [hMoving K hK] with w hw + refine ⟨hw.1,?_⟩ + intro r hr a h s hs hs0 hs1 + rw [rawEvenMarkedHit_mass a _ _ h s hs] + exact hw.2 r hr s hs0 hs1 + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RawFirstPrefixLaw.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawFirstPrefixLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..e8c453b5fd642de91b660be4fff3f707dd7c684b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawFirstPrefixLaw.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Paths.OneStepHistoryReconstruction + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping + +local instance : MeasurableSingletonClass State := by + constructor + intro x + cases x with + | inl e => simpa only [image_singleton] using ((measurableSet_singleton e).inl_image : MeasurableSet (Sum.inl '' {e} : Set State)) + | inr o => simpa only [image_singleton] using ((measurableSet_singleton o).inr_image : MeasurableSet (Sum.inr '' {o} : Set State)) + +def rawReturnFirstPrefix (a : ℕ) (r : RawReturnTrace a) : RawHistory (a+1) := + rawPrefix (show a+1 ≤ a+2*(r.1+1) by omega) r.2 + +lemma rawReturnFirstPrefix_measurable (a : ℕ) : Measurable (rawReturnFirstPrefix a) := by + apply measurable_sigma_family + intro n + exact rawPrefix_measurable (show a+1 ≤ a+2*(n+1) by omega) + +lemma rawReturnFirstPrefix_retains (a : ℕ) (past : RawHistory a) : + ∀ᵐ h ∂(rawReturnTraceKernel a past).map (rawReturnFirstPrefix a), + rawPrefix (show a ≤ a+1 by omega) h=past := by + have hm : MeasurableSet {h : RawHistory (a+1) | rawPrefix (show a ≤ a+1 by omega) h=past} := + (rawPrefix_measurable (show a ≤ a+1 by omega)) (measurableSet_singleton past) + apply (ae_map_iff (rawReturnFirstPrefix_measurable a).aemeasurable hm).mpr + rw [rawReturnTraceKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable a n)] + apply (ae_map_iff (rawReturnTrace_mk_measurable a n).aemeasurable + (hm.preimage (rawReturnFirstPrefix_measurable a))).mpr + exact firstReturnHistory_retains_past a n past + +theorem rawReturn_first_prefix (a : ℕ) (past : RawHistory a) (z : OddCost) + (hz : rawLast a past=embedOdd z) : + (rawReturnTraceKernel a past).map (rawReturnFirstPrefix a)=rawExtension a (a+1) past := by + apply oneStep_measure_eq_of_last a past + ((rawReturnTraceKernel a past).map (rawReturnFirstPrefix a)) (rawExtension a (a+1) past) + (rawReturnFirstPrefix_retains a past) (rawExtension_retains_prefix (by omega) past) + rw [Measure.map_map (rawLast_measurable (a+1)) (rawReturnFirstPrefix_measurable a),rawExtension_last_step] + exact rawReturn_first_arrival a past z hz + +noncomputable def firstPrefixMarkEvent (a : ℕ) (b : Bool) : Set (RawHistory (a+1)) := + {h | firstArrivalMark (rawLast (a+1) h)=b} + +lemma firstPrefixMarkEvent_measurable (a : ℕ) (b : Bool) : MeasurableSet (firstPrefixMarkEvent a b) := + (firstArrivalMark_measurable.comp (rawLast_measurable (a+1))) (measurableSet_singleton b) + +theorem rawBranchReturn_first_prefix (a : ℕ) (b : Bool) (past : RawHistory a) (z : OddCost) + (hz : rawLast a past=embedOdd z) : + (rawBranchReturnKernel a b past).map (rawReturnFirstPrefix a)= + (rawExtension a (a+1) past).restrict (firstPrefixMarkEvent a b) := by + rw [rawBranchReturnKernel,Kernel.restrict_apply] + change ((rawReturnTraceKernel a past).restrict ((rawReturnFirstPrefix a) ⁻¹' firstPrefixMarkEvent a b)).map + (rawReturnFirstPrefix a)=_ + rw [← Measure.restrict_map (rawReturnFirstPrefix_measurable a) (firstPrefixMarkEvent_measurable a b), + rawReturn_first_prefix a past z hz] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RawMarkedVisitGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawMarkedVisitGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf0cf3e4f615c11811e333747a3354694ac85bbf --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawMarkedVisitGeometry.lean @@ -0,0 +1,158 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawPhysicalHit + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels + +noncomputable def lastRawCycle : (a : ℕ) → (w : List Bool) → (b : Bool) → + RawCycleWordTrace a (w++[b]).length → Σ t : ℕ, RawReturnTrace t + | a, [], _b, r => ⟨a,packRawReturnTrace a r.1 r.2.1⟩ + | a, _c::w, b, r => lastRawCycle (a+2*(r.1+1)) w b r.2.2 + +lemma lastRawCycle_measurable (w : List Bool) : ∀ a b, Measurable (lastRawCycle a w b) := by + induction w with + | nil => + intro a b + apply measurable_sigma_family + intro n + exact (measurableSigmaMk a).comp ((rawReturnTrace_mk_measurable a n).comp measurable_fst) + | cons c w ih => + intro a b + apply measurable_sigma_family + intro n + exact (ih (a+2*(n+1)) b).comp measurable_snd + +lemma lastRawCycle_anchor_ge (w : List Bool) : ∀ a b r, a ≤ (lastRawCycle a w b r).1 := by + induction w with + | nil => intro a b r; exact le_rfl + | cons c w ih => + intro a b r + exact (by omega : a ≤ a+2*(r.1+1)).trans (ih _ b r.2.2) + +lemma lastRawCycle_record (w : List Bool) : ∀ a b r, + lastCycleRecord w b (rawCycleWordSignature a (w++[b]).length r)= + rawReturnInputSignature (lastRawCycle a w b r).1 (lastRawCycle a w b r).2 := by + induction w with + | nil => intro a b r; rfl + | cons c w ih => intro a b r; exact ih _ b r.2.2 + +noncomputable def rawEvenFinalCycle (a : ℕ) (r : RawEvenMarkedHitTrace a) : Σ t : ℕ, RawReturnTrace t := + let e := (a+1)+2*r.1 + let t := r.2.2 + lastRawCycle e (List.ofFn t.2.1) true t.2.2 + +lemma rawEvenFinalCycle_measurable (a : ℕ) : Measurable (rawEvenFinalCycle a) := by + apply measurable_sigma_family + intro k + have hm : Measurable (fun t : RawMarkedHitTrace ((a+1)+2*k) => + lastRawCycle ((a+1)+2*k) (List.ofFn t.2.1) true t.2.2) := by + apply measurable_sigma_family + intro n + apply measurable_sigma_family + intro f + exact lastRawCycle_measurable (List.ofFn f) _ true + exact hm.comp measurable_snd + +lemma rawEvenFinalCycle_anchor_gt (a : ℕ) (r : RawEvenMarkedHitTrace a) : + a < (rawEvenFinalCycle a r).1 := by + have h := lastRawCycle_anchor_ge (List.ofFn r.2.2.2.1) ((a+1)+2*r.1) true r.2.2.2.2 + exact lt_of_lt_of_le (by omega : a < (a+1)+2*r.1) h + +lemma rawEvenFinalCycle_record (a : ℕ) (r : RawEvenMarkedHitTrace a) : + rawEvenHitRecord a r=rawReturnInputSignature (rawEvenFinalCycle a r).1 (rawEvenFinalCycle a r).2 := + lastRawCycle_record (List.ofFn r.2.2.2.1) ((a+1)+2*r.1) true r.2.2.2.2 + +theorem rawEvenHit_actual_visit (a : ℕ) (v H : ℝ) (h0 : RawHistory a) : + ∀ᵐ r ∂rawEvenMarkedHitKernel a v H h0, + ∃ (t n : ℕ) (h : RawHistory (t+2*(n+1))) (tau : EvenState), + rawEvenFinalCycle a r=⟨t,⟨n,h⟩⟩ ∧ a < t ∧ + 209/100 ≤ tau.1 ∧ tau.1 ≤ 213/100 ∧ + h ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩= + (Sum.inl tau,(h ⟨t,Finset.mem_Iic.mpr (by omega)⟩).2+cost tau.1) ∧ + (h ⟨t,Finset.mem_Iic.mpr (by omega)⟩).2 ∈ Icc v (v+H) := by + filter_upwards [rawEvenHit_ae_physical a v H h0] with r hr + obtain ⟨tau,ht0,ht1,hFirst⟩ := physicalMarkedRecord_witness hr.1 + have hRecord := rawEvenFinalCycle_record a r + have hAnchor := rawEvenFinalCycle_anchor_gt a r + rcases he : rawEvenFinalCycle a r with ⟨t,n,h⟩ + rw [he] at hRecord hAnchor + refine ⟨t,n,h,tau,rfl,hAnchor,ht0,ht1,?_,?_⟩ + · rw [hRecord] at hFirst + exact hFirst + · have hw := hr.2 + rw [hRecord] at hw + exact hw + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels + +lemma gapAt_add_cost (r T t : ℝ) (ht : 0 < t) : + gapAt r (T+cost t)=nextGap (gapAt r T) t := by + rw [nextGap_eq_cost ht] + unfold gapAt + rw [neg_add,Real.exp_add] + ring + +theorem physical_record_slack {r b0 b1 : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + {c : CycleInputSignature} (hc : c ∈ physicalMarkedRecord) + (hW : c.1 ∈ Icc (Real.log (r/b1)) (Real.log (r/b1)+Real.log (b1/(10*b0)))) : + ∃ tau : EvenState, 209/100 ≤ tau.1 ∧ tau.1 ≤ 213/100 ∧ + recordFirst c=(Sum.inl tau,c.1+cost tau.1) ∧ + 10*b0 ≤ gapAt r c.1 ∧ gapAt r c.1 ≤ b1 ∧ + 10*b0/(313/100) ≤ nextExponent (gapAt r c.1) tau.1 ∧ + nextExponent (gapAt r c.1) tau.1 ≤ b1/(309/100) ∧ + 2*b0 ≤ nextExponent (gapAt r c.1) tau.1 ∧ + nextExponent (gapAt r c.1) tau.1 ≤ b1/2 ∧ + 6*b0 < gapAt r (recordFirst c).2 ∧ + gapAt r (recordFirst c).2 / nextExponent (gapAt r c.1) tau.1=tau.1 := by + obtain ⟨tau,ht0,ht1,hF⟩ := physicalMarkedRecord_witness hc + have hg := (marked_cost_window hr hb0 hb1 c.1).mpr hW + have hs := marked_draw_slack hb0 hg.1 hg.2 ht0 ht1 + refine ⟨tau,ht0,ht1,hF,hg.1,hg.2,hs.1,hs.2.1,hs.2.2.1,hs.2.2.2.1,?_,?_⟩ + · rw [hF,gapAt_add_cost r c.1 tau.1 (by linarith)] + exact hs.2.2.2.2.1 + · rw [hF,gapAt_add_cost r c.1 tau.1 (by linarith)] + exact hs.2.2.2.2.2 + +theorem rawEvenHit_ae_geometric {r b0 b1 : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + (a : ℕ) (h : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a (Real.log (r/b1)) (Real.log (b1/(10*b0))) h, + ∃ tau : EvenState, 209/100 ≤ tau.1 ∧ tau.1 ≤ 213/100 ∧ + recordFirst (rawEvenHitRecord a z)=(Sum.inl tau,(rawEvenHitRecord a z).1+cost tau.1) ∧ + 10*b0 ≤ gapAt r (rawEvenHitRecord a z).1 ∧ gapAt r (rawEvenHitRecord a z).1 ≤ b1 ∧ + 10*b0/(313/100) ≤ nextExponent (gapAt r (rawEvenHitRecord a z).1) tau.1 ∧ + nextExponent (gapAt r (rawEvenHitRecord a z).1) tau.1 ≤ b1/(309/100) ∧ + 2*b0 ≤ nextExponent (gapAt r (rawEvenHitRecord a z).1) tau.1 ∧ + nextExponent (gapAt r (rawEvenHitRecord a z).1) tau.1 ≤ b1/2 ∧ + 6*b0 < gapAt r (recordFirst (rawEvenHitRecord a z)).2 ∧ + gapAt r (recordFirst (rawEvenHitRecord a z)).2 / + nextExponent (gapAt r (rawEvenHitRecord a z).1) tau.1=tau.1 := by + filter_upwards [rawEvenHit_ae_physical a (Real.log (r/b1)) (Real.log (b1/(10*b0))) h] with z hz + exact physical_record_slack hr hb0 hb1 hz.1 hz.2 + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RawMarkedWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawMarkedWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d45fec941cce8ca2697d00b2657ef2cdaacef25 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RawMarkedWords.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawWordSpaces + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal + +noncomputable def rawMarkedWordKernel : (a : ℕ) → (w : List Bool) → + Kernel (RawHistory a) (RawCycleWordTrace a w.length) + | _a, [] => Kernel.id + | a, b::w => + (sigmaFamilyKernel (fun n : ℕ => + (Kernel.id : Kernel (RawHistory (a+2*(n+1))) (RawHistory (a+2*(n+1)))) ×ₖ + rawMarkedWordKernel (a+2*(n+1)) w)) ∘ₖ rawBranchReturnKernel a b + +lemma rawMarkedWord_bound_and_finite (w : List Bool) : ∀ a : ℕ, + IsFiniteKernel (rawMarkedWordKernel a w) ∧ ∀ h, rawMarkedWordKernel a w h univ ≤ 1 := by + induction w with + | nil => + intro a + constructor + · change IsFiniteKernel (Kernel.id : Kernel (RawHistory a) (RawHistory a)); infer_instance + · intro h + change (Measure.dirac h) univ ≤ 1 + simp + | cons b w ih => + intro a + let (c : ℕ) : IsFiniteKernel (rawMarkedWordKernel c w) := (ih c).1 + let C : (n : ℕ) → Kernel (RawHistory (a+2*(n+1))) + (RawHistory (a+2*(n+1)) × RawCycleWordTrace (a+2*(n+1)) w.length) := + fun n => Kernel.id ×ₖ rawMarkedWordKernel (a+2*(n+1)) w + have hC (n : ℕ) (y : RawHistory (a+2*(n+1))) : C n y univ ≤ 1 := by + dsimp [C] + rw [Kernel.id_prod_apply' _ _ MeasurableSet.univ,preimage_univ] + exact (ih (a+2*(n+1))).2 y + have : IsFiniteKernel (sigmaFamilyKernel C) := + sigmaFamilyKernel_isFinite_of_bound C (by simp : (1:ℝ≥0∞) < ∞) hC + have hS (r : RawReturnTrace a) : sigmaFamilyKernel C r univ ≤ 1 := by + rcases r with ⟨n,y⟩ + rw [sigmaFamilyKernel_mass] + exact hC n y + constructor + · change IsFiniteKernel ((sigmaFamilyKernel C) ∘ₖ rawBranchReturnKernel a b) + infer_instance + · intro h + change ((sigmaFamilyKernel C) ∘ₖ rawBranchReturnKernel a b) h univ ≤ 1 + rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ] + calc + _ ≤ ∫⁻ _r, (1:ℝ≥0∞) ∂rawBranchReturnKernel a b h := lintegral_mono hS + _ = rawBranchReturnKernel a b h univ := by simp + _ ≤ 1 := rawBranchReturn_mass_le_one a b h + +instance rawMarkedWordKernel_isFiniteKernel (a : ℕ) (w : List Bool) : IsFiniteKernel (rawMarkedWordKernel a w) := + (rawMarkedWord_bound_and_finite w a).1 + +theorem rawMarkedWord_mass_le_one (a : ℕ) (w : List Bool) (h : RawHistory a) : + rawMarkedWordKernel a w h univ ≤ 1 := (rawMarkedWord_bound_and_finite w a).2 h + +lemma rawMarkedWord_cons_lintegral (a : ℕ) (b : Bool) (w : List Bool) (h : RawHistory a) + {F : RawCycleWordTrace a (b::w).length → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ t, F t ∂rawMarkedWordKernel a (b::w) h) = + ∫⁻ r : RawReturnTrace a, ∫⁻ t, + F (@Sigma.mk ℕ (fun n => RawHistory (a+2*(n+1)) × RawCycleWordTrace (a+2*(n+1)) w.length) + r.1 (r.2,t)) ∂rawMarkedWordKernel (a+2*(r.1+1)) w r.2 ∂rawBranchReturnKernel a b h := by + rw [rawMarkedWordKernel,Kernel.lintegral_comp _ _ _ hF] + apply lintegral_congr + rintro ⟨n,y⟩ + calc + _ = ∫⁻ p : RawHistory (a+2*(n+1)) × RawCycleWordTrace (a+2*(n+1)) w.length, + F (@Sigma.mk ℕ (fun j => RawHistory (a+2*(j+1)) × RawCycleWordTrace (a+2*(j+1)) w.length) n p) + ∂((Kernel.id : Kernel (RawHistory (a+2*(n+1))) (RawHistory (a+2*(n+1)))) ×ₖ + rawMarkedWordKernel (a+2*(n+1)) w) y := + sigmaFamilyKernel_lintegral (fun j : ℕ => + (Kernel.id : Kernel (RawHistory (a+2*(j+1))) (RawHistory (a+2*(j+1)))) ×ₖ + rawMarkedWordKernel (a+2*(j+1)) w) n y hF + _ = _ := Kernel.lintegral_id_prod (hF.comp (measurableSigmaMk n)) (rawMarkedWordKernel (a+2*(n+1)) w) y + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RealExceptionalMarks.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RealExceptionalMarks.lean new file mode 100644 index 0000000000000000000000000000000000000000..977f5c8c4307033a6f7079641af3408659bef5b2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RealExceptionalMarks.lean @@ -0,0 +1,97 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.RealAlgebraicFibers + +namespace OAI + +namespace Erdos970 + +section + +open Set +namespace ErdosAlgebraicCurve +open ErdosCriticalGeometry ErdosImplicitCurvature ErdosDivisibleInflection + +def realExceptionalAbscissae (Q : MV ℝ) : Set ℝ := + Complex.ofReal ⁻¹' exceptionalAbscissae (complexify Q) + +theorem mem_realExceptionalAbscissae (Q : MV ℝ) (x y : ℝ) (hzero : peval Q x y = 0) + (hbad : peval (partialX Q) x y = 0 ∨ peval (partialY Q) x y = 0 ∨ + peval (inflectionPolynomial Q) x y = 0) : x ∈ realExceptionalAbscissae Q := by + have hc : complexPoint (x,y) ∈ exceptionalPoints (complexify Q) := by + rcases hbad with hx | hy | hi + · apply Or.inl + apply (real_critical_iff Q (x,y)).mpr + change MvPolynomial.eval ![x,y] Q = 0 ∧ + (MvPolynomial.eval ![x,y] (MvPolynomial.pderiv 0 Q) = 0 ∨ + MvPolynomial.eval ![x,y] (MvPolynomial.pderiv 1 Q) = 0) + simpa only [← peval_eq_eval_pair,partialX,partialY] using And.intro hzero (Or.inl hx) + · apply Or.inl + apply (real_critical_iff Q (x,y)).mpr + change MvPolynomial.eval ![x,y] Q = 0 ∧ + (MvPolynomial.eval ![x,y] (MvPolynomial.pderiv 0 Q) = 0 ∨ + MvPolynomial.eval ![x,y] (MvPolynomial.pderiv 1 Q) = 0) + simpa only [← peval_eq_eval_pair,partialX,partialY] using And.intro hzero (Or.inr hy) + · apply Or.inr + change MvPolynomial.eval ![(x : ℂ),(y : ℂ)] (complexify Q) = 0 ∧ + MvPolynomial.eval ![(x : ℂ),(y : ℂ)] (inflection (complexify Q)) = 0 + constructor + · rw [complexify_eval,← peval_eq_eval_pair,hzero,Complex.ofReal_zero] + · rw [← complexify_inflection,complexify_eval,← peval_eq_eval_pair,hi,Complex.ofReal_zero] + exact ⟨complexPoint (x,y),hc,rfl⟩ + +theorem divisible_critical_marks (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) (hdiv : complexify Q ∣ inflection (complexify Q)) : + ∃ B : Finset ℝ, B.card ≤ 4*Q.totalDegree^2 ∧ ∀ x ∉ B, ∀ y : ℝ, peval Q x y ≠ 0 := by + classical + obtain ⟨hf,hc⟩ := real_critical_abscissae_bound Q hQ hdeg + refine ⟨hf.toFinset,?_,?_⟩ + · rwa [← ncard_eq_toFinset_card _ hf] + · intro x hx y hzero + apply hx + apply hf.mem_toFinset.mpr + refine ⟨(x,y),?_,rfl⟩ + have hgrad := divisible_inflection_gradient_zero Q hQ hdeg hdiv x y hzero + change MvPolynomial.eval ![x,y] Q = 0 ∧ + (MvPolynomial.eval ![x,y] (MvPolynomial.pderiv 0 Q) = 0 ∨ + MvPolynomial.eval ![x,y] (MvPolynomial.pderiv 1 Q) = 0) + simpa only [← peval_eq_eval_pair,partialX,partialY] using And.intro hzero (Or.inl hgrad.1) + +theorem nondivisible_exceptional_marks (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) (hnd : ¬complexify Q ∣ inflection (complexify Q)) : + ∃ B : Finset ℝ, B.card ≤ 10*Q.totalDegree^2 ∧ + ∀ x ∉ B, ∀ y : ℝ, peval Q x y = 0 → + peval (partialX Q) x y ≠ 0 ∧ peval (partialY Q) x y ≠ 0 ∧ + peval (inflectionPolynomial Q) x y ≠ 0 := by + classical + have hd : 1 < (complexify Q).totalDegree := by rwa [complexify_totalDegree] + obtain ⟨hc,hcard⟩ := exceptional_abscissae_bound (complexify Q) hQ hd hnd + obtain ⟨hf,hpre⟩ := finite_real_preimage (exceptionalAbscissae (complexify Q)) hc + change (realExceptionalAbscissae Q).Finite at hf + refine ⟨hf.toFinset,?_,?_⟩ + · rw [← ncard_eq_toFinset_card _ hf] + exact hpre.trans (by simpa only [complexify_totalDegree] using hcard) + · intro x hx y hz + have hn : x ∉ realExceptionalAbscissae Q := fun h => hx (hf.mem_toFinset.mpr h) + refine ⟨?_,?_,?_⟩ + · exact fun h => hn (mem_realExceptionalAbscissae Q x y hz (Or.inl h)) + · exact fun h => hn (mem_realExceptionalAbscissae Q x y hz (Or.inr (Or.inl h))) + · exact fun h => hn (mem_realExceptionalAbscissae Q x y hz (Or.inr (Or.inr h))) + +theorem exists_bad_abscissae (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) : + ∃ B : Finset ℝ, B.card ≤ 10*Q.totalDegree^2 ∧ + ∀ x ∉ B, ∀ y : ℝ, peval Q x y = 0 → + peval (partialX Q) x y ≠ 0 ∧ peval (partialY Q) x y ≠ 0 ∧ + peval (inflectionPolynomial Q) x y ≠ 0 := by + by_cases hdiv : complexify Q ∣ inflection (complexify Q) + · obtain ⟨B,hB,hzero⟩ := divisible_critical_marks Q hQ hdeg hdiv + exact ⟨B,hB.trans (Nat.mul_le_mul_right _ (by omega)), + fun x hx y hy => (hzero x hx y hy).elim⟩ + · exact nondivisible_exceptional_marks Q hQ hdeg hdiv + +end ErdosAlgebraicCurve + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RegularStoppedEvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RegularStoppedEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..6dab15f8b80846e3d753ae965e1d9d878a7dc200 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RegularStoppedEvent.lean @@ -0,0 +1,76 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualRegularAdmission +import OAI.NumberTheory.Jacobsthal.Paths.FullWordHighAlignment + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RegularStoppedEvent +open FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate ActualWordSelection ActualRegularBoxes +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ActualRegularAdmission ActualPrefixClearance RegularBadTagWords SourceMarkedStopping +open StoppedTraceSets StoppedCountAdapters PriorPrimeWindow MissingWindowPrimeMass +open StrongReferenceTransport StrongSourceFamilies ActualPrimeHigh ReferenceAdmission +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +noncomputable def hasSourceStop {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) : Prop := + ∃ pre tail : List ℕ,ps=pre++tail ∧ pre ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) 1) + +noncomputable def uncapturedTest {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : Node) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (ps : List ℕ) : Prop := + (∃ q ∈ Q (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps), + ∀ p ∈ ps,Cs < primeExponent w p → aligns (sourceClass a) q p) ∧ + ¬hasSourceStop hw htop hxi Y Cs eta Clen B b₀ b₁ a z ps + +noncomputable def uncapturedRegular {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B K b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : Node) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) : Finset (List ℕ) := + (regularWords hw htop hxi Clen B K z).filter (uncapturedTest hw htop hxi Y Cs eta Clen B b₀ b₁ a z Q) + +theorem uncaptured_subset_exceptions {w top xi Cs eta Clen B K b₀ b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) (hmesh : 2*(xi/Real.log w) ≤ 6*(2*Clen*xi)) + (hb₀ : 0 < b₀) (hCs : Cs < 2*b₀) (hsearch : b₁ < w^((1/4:ℝ))) + (hh : xi/Real.log w ≤ b₀) (hsmall : 2*Clen*xi+(206/100)*(xi/Real.log w) ≤ (4/100)*b₀) + (Y : ℕ) (a : ℕ → ℕ) (z : Node) (hs : Valid z.side z.ratio) (hz : Consistent z) + (hg : StrongState z) (hclosed : z.closed=true) (hcap : w^z.cutoff=top) (hroot : b₁/2 < z.cutoff) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) : + uncapturedRegular hw htop hxi Y Cs eta Clen B K b₀ b₁ a z Q ⊆ + regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen B K z Q (sourceClass a) ∪ + missingWindowPrefixes w 1 K b₀ b₁ z := by + intro ps hp + obtain ⟨hr,⟨q,hq,ha⟩,hnotstop⟩ := Finset.mem_filter.mp hp + have href := regular_word_reference hw htop hxi hC hcomp hmesh z ps hr + by_cases hwin : hasPrimeWindow w b₀ b₁ z ps + · by_cases hcorrect : ∃ t,ActualSourceTags.sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) ps=some t ∧ t.rational=q + · obtain ⟨t,ht,htq⟩ := hcorrect + obtain ⟨pre,tail,heq,hwin⟩ := hwin + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hr).1 + have hreg := (Finset.mem_filter.mp hr).2 + have hsafe := clearance_supplies_safety hw htop hxi hC hcomp hmesh z ps hd.2 hreg.1 hreg.2.1 + have hcount := regular_tag_singleton hw htop hxi z ps hr (sourceClass a) t ht + have halign : ∀ p ∈ ps,Cs < primeExponent w p → aligns (sourceClass a) t.rational p := by + simpa only [htq] using ha + exact False.elim (hnotstop (marked_prefix_forces_actual_stop Y hw htop hxi hC hcomp hb₀ hCs hsearch hh hsmall + a ∅ 1 z ps pre tail heq hs hz hg hclosed hcap hroot href hreg.1 hsafe t ht hcount halign hwin)) + · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨hr,q,hq,ha,hcorrect⟩) + · have hu := (source_reference_transport hw htop z hs hz hg hclosed hcap ps href).1 + exact Finset.mem_union_right _ (Finset.mem_filter.mpr ⟨hu,(Finset.mem_filter.mp hr).2.2.2.1,hwin⟩) + +end NumberTheoryLean.RegularStoppedEvent + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedPairEvents.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedPairEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..4781557da9d8cda42c8b35051f3774442865aa78 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedPairEvents.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FinitePairOccurrence +import OAI.NumberTheory.Jacobsthal.Estimates.RepeatedStepRowBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedPairEvents +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling ActualFlagInvariant PersistentFailureFlag +open RepeatedStepRowBound + +variable {w ell S : ℝ} {start : Node} + +def primeRepeatPair {n : ℕ} (lab : ℕ → Fin n) (X U : ℝ) (G : Set (ChainState w ell S start)) : + ChainState w ell S start × ChainState w ell S start → Prop + | (some h,some k) => h.primes ≠ [] ∧ h.node.ratio ≤ U ∧ some h ∈ G ∧ + lab (h.primes.getLastD 0)=lab (k.primes.getLastD 0) ∧ X ≤ k.node.cutoff + | _ => False + +noncomputable def goodRepeatPair {n : ℕ} (lab : ℕ → Fin n) (X U : ℝ) (G : Set (ChainState w ell S start)) + (v mesh : ℝ) (N : ℕ) : Set (FlagState (JointState w ell S start) × FlagState (JointState w ell S start)) := + {xy | GoodAt v mesh N xy.1.1 ∧ GoodAt v mesh N xy.2.1 ∧ primeRepeatPair lab X U G (xy.1.1.1,xy.2.1.1)} + +theorem goodRepeatPair_measurable {n : ℕ} (lab : ℕ → Fin n) (X U : ℝ) (G : Set (ChainState w ell S start)) + (v mesh : ℝ) (N : ℕ) : MeasurableSet (goodRepeatPair lab X U G v mesh N) := by + have hp : MeasurableSet {pq : ChainState w ell S start × ChainState w ell S start | primeRepeatPair lab X U G pq} := + (Set.to_countable _).measurableSet + have hm : Measurable (fun xy : FlagState (JointState w ell S start) × FlagState (JointState w ell S start) => + (xy.1.1.1,xy.2.1.1)) := by fun_prop + exact ((measurable_fst.comp measurable_fst) (GoodAt_measurable v mesh N)).inter + (((measurable_fst.comp measurable_snd) (GoodAt_measurable v mesh N)).inter (hm hp)) + +theorem primeRepeatPair_left {n : ℕ} (lab : ℕ → Fin n) {X U : ℝ} {G : Set (ChainState w ell S start)} + {p q : ChainState w ell S start} (hp : primeRepeatPair lab X U G (p,q)) : + ∃ h : History w ell S start,p=some h ∧ h.primes ≠ [] ∧ h.node.ratio ≤ U ∧ p ∈ G := by + cases p with + | none => exact False.elim hp + | some h => + cases q with + | none => exact False.elim hp + | some k => exact ⟨h,rfl,hp.1,hp.2.1,hp.2.2.1⟩ + +theorem primeRepeatPair_next {n : ℕ} (lab : ℕ → Fin n) {X U : ℝ} {G : Set (ChainState w ell S start)} + (h : History w ell S start) (y : FlagState (JointState w ell S start)) + (hp : primeRepeatPair lab X U G (some h,y.1.1)) : nextRepeat lab X h y := by + cases hy : y.1.1 with + | none => rw [hy] at hp; exact False.elim hp + | some k => + rw [hy] at hp + unfold nextRepeat + rw [hy] + exact hp.2.2.2 + +theorem goodAt_enlarge {v mesh : ℝ} (hm : 0 ≤ mesh) {n N : ℕ} (hn : n ≤ N) + (q : JointState w ell S start) (hq : GoodAt v mesh n q) : GoodAt v mesh N q := by + rcases q with ⟨p,y⟩ + cases p with + | none => cases y <;> exact hq + | some p => + cases y with + | inr u => exact False.elim hq + | inl y => + refine ⟨hq.1,hq.2.1,hq.2.2.1,hq.2.2.2.trans ?_⟩ + have hnR : (n:ℝ) ≤ N := by exact_mod_cast hn + nlinarith [mul_le_mul_of_nonneg_right hnR hm] +end NumberTheoryLean.RepeatedPairEvents + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedPairProbability.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedPairProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..800a10348d8a49dcb99eaf40d5cbad6a5f430a94 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedPairProbability.lean @@ -0,0 +1,126 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RepeatedPairRow + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedPairProbability +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain ActualProcessCoupling +open ActualCoupledHistories ActualFlagInvariant ActualSuccessfulHistories PersistentFailureFlag +open RepeatedStepRowBound RepeatedPairEvents RepeatedPairRow +open FiniteHistoryTransport FiniteHistoryOccurrence FiniteHistoryPairLaw FinitePairOccurrence +open PrimeCompactVisits PrimeHistoryCompactCount +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels + +attribute [local instance] Classical.propDecidable +variable {w ell S : ℝ} {start : Node} + +noncomputable def rawRepeatPair {n : ℕ} (lab : ℕ → Fin n) (X U : ℝ) (G : Set (ChainState w ell S start)) : + Set (FlagState (JointState w ell S start) × FlagState (JointState w ell S start)) := + {xy | primeRepeatPair lab X U G (xy.1.1.1,xy.2.1.1)} + +theorem rawRepeatPair_measurable {n : ℕ} (lab : ℕ → Fin n) (X U : ℝ) (G : Set (ChainState w ell S start)) : + MeasurableSet (rawRepeatPair lab X U G) := by + have hm : Measurable (fun xy : FlagState (JointState w ell S start) × FlagState (JointState w ell S start) => + (xy.1.1.1,xy.2.1.1)) := by fun_prop + have hp : MeasurableSet {pq : ChainState w ell S start × ChainState w ell S start | primeRepeatPair lab X U G pq} := + (Set.to_countable _).measurableSet + exact hm hp + +noncomputable def compactParentGate (L : ℝ) : Set (ChainState w ell S start) := + {p | match p with | none => False | some h => h.node.gap ≤ L} + +theorem compact_gate_visit (L : ℝ) (p : ChainState w ell S start) : + (if p ∈ compactParentGate L then (1:ℝ) else 0)=visit L p := by + cases p with + | none => simp [compactParentGate,visit] + | some h => rfl + +variable (hwn : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem raw_repeat_good_on_success {n : ℕ} (lab : ℕ → Fin n) (X U : ℝ) (G : Set (ChainState w ell S start)) + {mesh : ℝ} (hm : 0 < mesh) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N, + (last N h).2=false → h ∈ pairOccurrence (rawRepeatPair lab X U G) N → + h ∈ pairOccurrence (goodRepeatPair lab X U G (Real.log start.gap) mesh N) N := by + filter_upwards [sourceHistory_success_good hwn hell hS0 hS hr hs hsS hm N] with h hh + intro hf hraw + obtain ⟨j,hj⟩ := Set.mem_iUnion.mp hraw + apply Set.mem_iUnion.mpr + refine ⟨j,?_,?_,hj⟩ + · exact goodAt_enlarge hm.le j.isLt.le _ (hh hf ⟨j.1,Finset.mem_Iic.mpr j.isLt.le⟩) + · exact goodAt_enlarge hm.le (show j.1+1 ≤ N by have := j.isLt; omega) _ + (hh hf ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩) + +theorem raw_repeat_probability_le_good {n : ℕ} (lab : ℕ → Fin n) (X U : ℝ) (G : Set (ChainState w ell S start)) + {mesh : ℝ} (hm : 0 < mesh) (N : ℕ) : + sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N (pairOccurrence (rawRepeatPair lab X U G) N) ≤ + FlaggedSourceStart.sourceLaw hwn hell hS0 hS hr hs hsS mesh N failed+ + sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N + (pairOccurrence (goodRepeatPair lab X U G (Real.log start.gap) mesh N) N) := by + have hsub : ∀ᵐ h ∂sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N, + h ∈ pairOccurrence (rawRepeatPair lab X U G) N → h ∈ {h | (last N h).2=true} ∪ + pairOccurrence (goodRepeatPair lab X U G (Real.log start.gap) mesh N) N := by + filter_upwards [raw_repeat_good_on_success hwn hell hS0 hS hr hs hsS lab X U G hm N] with h hh + intro hp + cases hf : (last N h).2 with + | false => exact Or.inr (hh hf hp) + | true => exact Or.inl hf + calc + _ ≤ sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N ({h | (last N h).2=true} ∪ + pairOccurrence (goodRepeatPair lab X U G (Real.log start.gap) mesh N) N) := measure_mono_ae hsub + _ ≤ _ := by + rw [← sourceHistory_failure_probability hwn hell hS0 hS hr hs hsS mesh N] + exact measure_union_le _ _ + +theorem good_repeat_probability_uniform {top xi U X mesh : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hU : 0 ≤ U) (hX : 0 < X) + (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hcap : w^start.cutoff=top) + (N : ℕ) (G : Set (ChainState w ell S start)) : + sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N + (pairOccurrence (goodRepeatPair (label (zero_lt_one.trans hw) htop hxi) X U G (Real.log start.gap) mesh N) N) ≤ + ENNReal.ofReal ((N:ℝ)*repeatBudget U X xi w mesh) := by + exact pair_occurrence_of_uniform_row _ (goodRepeatPair_measurable _ _ _ _ _ _ _) N _ + (repeatBudget_nonneg hU hX hxi.le hw hm.le) + (repeated_pair_row_uniform hwn hell hS0 hS hr hs hsS hw htop hxi hU hX hm hmesh hcap N G) + +theorem good_repeat_probability_compact {top xi L mesh : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hL : 0 ≤ L) + (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hcap : w^start.cutoff=top) (N : ℕ) : + sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N + (pairOccurrence (goodRepeatPair (label (zero_lt_one.trans hw) htop hxi) 1 L (compactParentGate L) + (Real.log start.gap) mesh N) N) ≤ ENNReal.ofReal (repeatBudget L 1 xi w mesh*(L+1)) := by + let A := repeatBudget L 1 xi w mesh + have hA : 0 ≤ A := repeatBudget_nonneg hL (by norm_num) hxi.le hw hm.le + apply pair_occurrence_of_budget _ (goodRepeatPair_measurable _ _ _ _ _ _ _) N _ + (fun x : FlagState (JointState w ell S start) => A*visit L x.1.1) + (fun x => mul_nonneg hA (visit_nonneg L _)) (A*(L+1)) + · intro x + have hh := repeated_pair_row_gated hwn hell hS0 hS hr hs hsS hw htop hxi hL (show (0:ℝ)<1 by norm_num) hm hmesh hcap N + (compactParentGate L) x + simpa only [compact_gate_visit] using hh + · filter_upwards [sourceHistory_compact_count hwn hell hS0 hS hr hs hsS hL mesh N] with h hh + rw [← Finset.mul_sum] + exact mul_le_mul_of_nonneg_left hh hA + +theorem raw_repeat_probability_compact {top xi L mesh : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hL : 0 ≤ L) + (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hcap : w^start.cutoff=top) (N : ℕ) : + sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N + (pairOccurrence (rawRepeatPair (label (zero_lt_one.trans hw) htop hxi) 1 L (compactParentGate L)) N) ≤ + FlaggedSourceStart.sourceLaw hwn hell hS0 hS hr hs hsS mesh N failed+ + ENNReal.ofReal (repeatBudget L 1 xi w mesh*(L+1)) := + (raw_repeat_probability_le_good hwn hell hS0 hS hr hs hsS _ 1 L (compactParentGate L) hm N).trans + (add_le_add le_rfl (good_repeat_probability_compact hwn hell hS0 hS hr hs hsS hw htop hxi hL hm hmesh hcap N)) +end NumberTheoryLean.RepeatedPairProbability + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedWordEvents.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedWordEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..bdcdd93225e0d7f7b1a3dc793f9322139bb56548 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RepeatedWordEvents.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SortedLabelRepetition +import OAI.NumberTheory.Jacobsthal.Paths.RepeatedWordData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedWordEvents +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualPrimeHigh ActualProcessCoupling +open FiniteHistoryTransport FiniteHistoryOccurrence FiniteHistoryPairLaw FinitePairOccurrence +open ActualCoupledHistories RepeatedPairProbability RepeatedPairEvents RepeatedWordData +open SortedLabelRepetition AdjacentPrimeRecovery ActualRepeatedBinStep ActualSourceTags +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels + + +noncomputable def searchRepeatedWord {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (ps : List ℕ) : Prop := ∃ b : Fin (binCount w top xi),searchBin w (lower w top xi b) ∧ + 2 ≤ (ps.map (label (zero_lt_one.trans hw) htop hxi)).count b + +def compactAdjacentWord {n : ℕ} (w : ℝ) (lab : ℕ → Fin n) (L : ℝ) (start : Node) (ps : List ℕ) : Prop := + ∃ pre p q tail,ps=pre++p::q::tail ∧ lab p=lab q ∧ (terminal w start (pre++[p])).gap ≤ L + +variable {w ell S : ℝ} {start : Node} +variable (hwn : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem search_word_pair_occurs {top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hcap : w^start.cutoff=top) (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N, + ∀ j : Finset.Iic N,∀ p : History w ell S start,(h j).1.1=some p → searchRepeatedWord hw htop hxi p.primes → + h ∈ pairOccurrence (rawRepeatPair (label (zero_lt_one.trans hw) htop hxi) (w^((1/4:ℝ))) S Set.univ) N := by + filter_upwards [sourceHistory_recovers_adjacent hwn hell hS0 hS hr hs hsS mesh N] with h hh + intro j p hp hrep + obtain ⟨b,hsearch,hcount⟩ := hrep + have hd := allowed_decreasing hw p.admissible + have hsrc := history_source_primes hw htop hell hcap p + obtain ⟨pre,a,c,tail,hword,ha,hc⟩ := source_repeated_label_adjacent hw htop hxi p.primes hd hsrc b hcount + obtain ⟨k,q,r,hq,hr,hqw,hrw⟩ := hh j p hp pre a c tail hword + apply Set.mem_iUnion.mpr + refine ⟨k,?_⟩ + change primeRepeatPair _ _ _ _ ((atIndex N h k.castSucc).1.1,(atIndex N h k.succ).1.1) + rw [hq,hr] + apply adjacent_search_pair_data hw htop hell hxi hsS hcap pre a c q r hqw hrw (ha.trans hc.symm) + rwa [hc] + +theorem compact_word_pair_occurs {n : ℕ} (lab : ℕ → Fin n) (hw : 1 < w) (L mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N, + ∀ j : Finset.Iic N,∀ p : History w ell S start,(h j).1.1=some p → compactAdjacentWord w lab L start p.primes → + h ∈ pairOccurrence (rawRepeatPair lab 1 L (compactParentGate L)) N := by + filter_upwards [sourceHistory_recovers_adjacent hwn hell hS0 hS hr hs hsS mesh N] with h hh + intro j p hp hrep + obtain ⟨pre,a,c,tail,hword,hlab,hgap⟩ := hrep + obtain ⟨k,q,r,hq,hr',hqw,hrw⟩ := hh j p hp pre a c tail hword + apply Set.mem_iUnion.mpr + refine ⟨k,?_⟩ + change primeRepeatPair _ _ _ _ ((atIndex N h k.castSucc).1.1,(atIndex N h k.succ).1.1) + rw [hq,hr'] + exact adjacent_compact_pair_data lab hw hell hr hs L pre a c q r hqw hrw hlab hgap +end NumberTheoryLean.RepeatedWordEvents + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RetainedCompactEvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RetainedCompactEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..c104c447a897aeacc8969d6742953e24406b9aa2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RetainedCompactEvent.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.Jacobsthal.Paths.NearPrefixOccurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.RetainedCompactEvent + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling PersistentFailureFlag +open PrimeBinMembership +open ActualCoupledHistories SourceSelectedCompactOccupation FullHistoryPrimeOccupation +open FullPathCompactSelection CompactPrefixOccurrence PrimeFamilyOccupation +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem retained_compact_event (R : ℝ) (hR : 3 ≤ R) (d : ℝ) (hd : 0 < d) : + ∃ C w₀ : ℝ, 0 < C ∧ 1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ, + ∀ start : Node, ∀ hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := LowStateHorizon.sourceHorizon S B + ∀ mesh : ℝ, ∀ E : Set (List ℕ), + (∀ ps ∈ retainedPrefixes w ell S start, ps ∈ E → (terminal w start ps).gap ≤ R) → + ENNReal.ofReal (B^2*(∑ ps ∈ (retainedPrefixes w ell S start).filter (· ∈ E),prefixWeight ps)) ≤ + ENNReal.ofReal C * fullSourceLaw w ell S start hs mesh N {h | occurs E N h} := by + obtain ⟨C,W,hC,hW,hsel⟩ := source_selected_compact R hR d hd + obtain ⟨W₁,hW₁⟩ := eventually_atTop.mp + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + refine ⟨C,max W (max normalizationThreshold W₁),hC,hW.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hellB hB hlogB hcomp hi h199 h23 hc hcut + dsimp only + intro mesh E hcompact + have hwW : W ≤ w := (le_max_left _ _).trans hw + have hnorm : normalizationThreshold ≤ w := + (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hlogw : d^2 ≤ Real.log w := hW₁ w + ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw) + have hscale := UniformBudgetRate.source_scale_bound hlogw hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have he : start.gap = B*start.ratio := by + have hh : start.cutoff = start.gap/start.ratio := hc + rw [hcut] at hh + exact ((eq_div_iff (valid_pos hs).ne').mp hh).symm + have hr : 0 < start.gap := by rw [he]; exact mul_pos hB (valid_pos hs) + have hsize : start.gap ≤ (23/10:ℝ)*B := by rw [he]; nlinarith + have hw1 : 1 < w := normalizationThreshold_gt_one.trans_le hnorm + have hnode : ∀ h : History w ell ((Real.log B)^2) start,h.primes ∈ E → h.node.gap ≤ R := by + intro h hh + exact hcompact h.primes ((mem_retainedPrefixes hw1 start h.primes).mpr h.admissible) hh + have hsum : (∑ ps ∈ retainedPrefixes w ell ((Real.log B)^2) start,prefixWeight ps*listSelection E ps) = + ∑ ps ∈ (retainedPrefixes w ell ((Real.log B)^2) start).filter (· ∈ E),prefixWeight ps := by + simp [Finset.sum_filter,listSelection,mul_ite] + rw [← hsum,← finite_family_full_history hnorm hell hS0 hscale.1 hr hs hsS hB hsize + mesh (listSelection E) (fun ps _ => listSelection_nonneg E ps)] + calc + _ ≤ ∫⁻ h,{h | occurs E (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) h}.indicator + (fullCompactReward R w B start (LowStateHorizon.sourceHorizon ((Real.log B)^2) B)) h + ∂sourceHistoryLaw hnorm hell hS0 hscale.1 hr hs hsS mesh + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) := + lintegral_mono (full_selected_le_occurrence E hnode _) + _ ≤ _ := by + have hh := hsel w hwW ell B start hs hell hellB hB hlogB hcomp hi h199 h23 hc hcut + mesh (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) _ (occurs_measurable E _) + exact hh + +end NumberTheoryLean.RetainedCompactEvent + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/RieszKernelBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/RieszKernelBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..ecca678ab457f6e246ce925116e627a3a29ec4bc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/RieszKernelBounds.lean @@ -0,0 +1,90 @@ +import OAI.NumberTheory.Jacobsthal.Primes.RieszMellinKernel + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory _root_.Filter +open scoped Topology + +lemma rieszKernel_norm_bound {sigma : ℝ} (hs : 1/2 ≤ sigma) (t : ℝ) : + ‖rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ 4/(1+t^2) := by + let z : ℂ := (sigma:ℂ)+(t:ℂ)*Complex.I + have hr : z.re = sigma := by simp [z] + have hi : z.im = t := by simp [z] + have h0 : ‖z‖^2 = sigma^2+t^2 := by + rw [Complex.sq_norm,Complex.normSq_apply,hr,hi] + ring + have h1 : ‖z+1‖^2 = (sigma+1)^2+t^2 := by + rw [Complex.sq_norm,Complex.normSq_apply] + simp only [Complex.add_re,Complex.add_im,Complex.one_re,Complex.one_im,add_zero,hr,hi] + ring + have hle : ‖z‖ ≤ ‖z+1‖ := by nlinarith [norm_nonneg z,norm_nonneg (z+1)] + have hp := mul_le_mul_of_nonneg_left hle (norm_nonneg z) + have hsig : (1/4:ℝ) ≤ sigma^2 := by nlinarith [sq_nonneg (sigma-1/2)] + have hden : (1+t^2)/4 ≤ ‖z‖*‖z+1‖ := by nlinarith only [h0,hp,hsig,sq_nonneg t] + have hdp : 0 < ‖z‖*‖z+1‖ := by nlinarith only [hden,sq_nonneg t] + change ‖1/(z*(z+1))‖ ≤ _ + rw [norm_div,norm_one,norm_mul] + apply (div_le_div_iff₀ hdp (by positivity : 0 < 1+t^2)).mpr + nlinarith only [hden] + +lemma rieszMajorant_integrable : Integrable (fun t:ℝ => 4/(1+t^2)) := by + simpa only [div_eq_mul_inv] using integrable_inv_one_add_sq.const_mul (4:ℝ) + +lemma continuous_rieszKernel_line {sigma : ℝ} (hs : 1/2 ≤ sigma) : + Continuous (fun t:ℝ => rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + unfold rieszKernel + apply continuous_const.div (by fun_prop) + intro t + apply mul_ne_zero + · intro hz + have h := congrArg Complex.re hz + simp at h + linarith + · intro hz + have h := congrArg Complex.re hz + simp at h + linarith + +lemma integrable_rieszKernel_line {sigma : ℝ} (hs : 1/2 ≤ sigma) : + Integrable (fun t:ℝ => rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + apply rieszMajorant_integrable.mono' (continuous_rieszKernel_line hs).aestronglyMeasurable + exact Filter.Eventually.of_forall (rieszKernel_norm_bound hs) + +lemma integral_norm_rieszKernel_line_le {sigma : ℝ} (hs : 1/2 ≤ sigma) : + (∫ t:ℝ, ‖rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)‖) ≤ 4*Real.pi := by + calc + _ ≤ ∫ t:ℝ, 4/(1+t^2) := integral_mono (integrable_rieszKernel_line hs).norm + rieszMajorant_integrable (rieszKernel_norm_bound hs) + _ = _ := by simp only [div_eq_mul_inv,integral_const_mul,integral_univ_inv_one_add_sq] + +theorem riesz_mellin_inversion {sigma x : ℝ} (hs : 1/2 ≤ sigma) (hx : 0 < x) : + mellinInv sigma rieszKernel x = (rieszWeight x:ℂ) := by + have hsp : 0 < sigma := by linarith + have he (t:ℝ) : mellin rieszProfile ((sigma:ℂ)+(t:ℂ)*Complex.I) = + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I) := + (hasMellin_rieszProfile (by simpa using hsp)).2 + have hvi : Complex.VerticalIntegrable (mellin rieszProfile) sigma := by + apply (integrable_rieszKernel_line hs).congr + exact Filter.Eventually.of_forall (fun t => (he t).symm) + have h := mellinInv_mellin_eq sigma rieszProfile hx (hasMellin_rieszProfile (by simpa using hsp)).1 + hvi (continuousAt_rieszProfile hx) + rw [rieszProfile_eq_weight hx] at h + rw [← h] + unfold mellinInv + congr 1 + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun t => by dsimp only; rw [he t]) + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SecondLossKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SecondLossKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..7751abc8994562503db4df1ebcae018923a85b75 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SecondLossKernel.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ScalarTailRecurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry + +theorem omissionForce_le_one (i : Side) (r b : ℝ) : omissionForce i r b ≤ 1 := by + cases i with + | even => norm_num [omissionForce] + | odd => + have hc : (upperCutoff .odd r b)⁻¹ ≤ (1:ℝ) := + (inv_le_one₀ ((by norm_num : (0:ℝ)<1).trans_le (upperCutoff_bounds .odd r b).1)).mpr + (upperCutoff_bounds .odd r b).1 + have hb : 0 ≤ survivorBaseline b := inv_nonneg.mpr (zero_le_one.trans (baseCutoff_bounds b).1) + change (upperCutoff .odd r b)⁻¹-survivorBaseline b ≤ 1 + linarith + +noncomputable def secondKernel (p : ℝ×ℝ) : ℝ := + (2*(p.1^2-1)/(max 1 p.2))*omissionForce .odd (2*p.1+2-p.2) p.2 + +theorem secondKernel_continuous : Continuous secondKernel := by + have hf : Continuous (fun p : ℝ×ℝ => omissionForce .odd (2*p.1+2-p.2) p.2) := + (omissionForce_continuous .odd).comp + (((continuous_const.mul continuous_fst).add continuous_const |>.sub continuous_snd).prodMk continuous_snd) + have hp : Continuous (fun p : ℝ×ℝ => 2*(p.1^2-1)/(max 1 p.2)) := + (continuous_const.mul ((continuous_fst.pow 2).sub continuous_const)).div + (continuous_const.max continuous_snd) (fun p => ne_of_gt + ((by norm_num : (0:ℝ)<1).trans_le (le_max_left 1 p.2))) + exact hp.mul hf + +theorem secondKernel_bound {y x : ℝ} (hy : y ∈ Icc (1:ℝ) 3) (hx : x ∈ Icc (1:ℝ) 2) : + |secondKernel (y,x)| ≤ 16 := by + have hx0 : 0 < x := by linarith [hx.1] + have hpoly : 0 ≤ y^2-1 := by nlinarith [hy.1] + have hpoly8 : y^2-1 ≤ 8 := by nlinarith [hy.1,hy.2] + have hp0 : 0 ≤ 2*(y^2-1)/x := div_nonneg (mul_nonneg (by norm_num) hpoly) hx0.le + have hp16 : 2*(y^2-1)/x ≤ 16 := by + apply (div_le_iff₀ hx0).mpr + nlinarith [hx.1] + unfold secondKernel + dsimp only + rw [max_eq_right hx.1,abs_of_nonneg (mul_nonneg hp0 (omissionForce_nonnegative .odd _ _))] + calc + _ ≤ (2*(y^2-1)/x)*1 := mul_le_mul_of_nonneg_left (omissionForce_le_one .odd _ _) hp0 + _ ≤ 16 := by simpa only [mul_one] using hp16 + +theorem second_density_kernel (y : ℝ) : + omissionDensity 1 .even y=∫ x : ℝ in 1..2,secondKernel (y,x) := by + change 2*(y^2-1)*(∫ x : ℝ in 1..upperCutoff .even (2*y+2) 2, + omissionForce .odd (2*y+2-x) x/(max 1 x))=_ + have hc : upperCutoff .even (2*y+2) 2=2 := by norm_num [upperCutoff] + rw [hc,← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro x _hx + dsimp only [secondKernel] + ring + +end ErdosOmissionBindings + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SigmaFamilyKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SigmaFamilyKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0dfcfe514d234e57eb9f937d3a08accd22450b4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SigmaFamilyKernel.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RawReturnBound + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal + +lemma measurable_sigma_family {ι : Type*} {X : ι → Type*} [∀ i, MeasurableSpace (X i)] + {Z : Type*} [MeasurableSpace Z] {f : (Σ i, X i) → Z} + (hf : ∀ i, Measurable (fun x => f (@Sigma.mk ι X i x))) : Measurable f := by + intro S hS + apply MeasurableSpace.measurableSet_iInf.mpr + intro i + exact hf i hS + +noncomputable def sigmaFamilyKernel {ι : Type*} {X Y : ι → Type*} + [∀ i, MeasurableSpace (X i)] [∀ i, MeasurableSpace (Y i)] + (K : ∀ i, Kernel (X i) (Y i)) : Kernel (Σ i, X i) (Σ i, Y i) where + toFun z := (K z.1 z.2).map (@Sigma.mk ι Y z.1) + measurable' := by + apply measurable_sigma_family + intro i + have hm := ((K i).map (@Sigma.mk ι Y i)).measurable + have he : (fun x : X i => ((K i).map (@Sigma.mk ι Y i)) x) = + (fun x : X i => (K i x).map (@Sigma.mk ι Y i)) := by + funext x + exact Kernel.map_apply _ (measurableSigmaMk i) x + change Measurable (fun x : X i => ((K i).map (@Sigma.mk ι Y i)) x) at hm + rw [he] at hm + exact hm + +lemma sigmaFamilyKernel_apply {ι : Type*} {X Y : ι → Type*} + [∀ i, MeasurableSpace (X i)] [∀ i, MeasurableSpace (Y i)] + (K : ∀ i, Kernel (X i) (Y i)) (i : ι) (x : X i) : + sigmaFamilyKernel K (@Sigma.mk ι X i x) = (K i x).map (@Sigma.mk ι Y i) := rfl + +lemma sigmaFamilyKernel_mass {ι : Type*} {X Y : ι → Type*} + [∀ i, MeasurableSpace (X i)] [∀ i, MeasurableSpace (Y i)] + (K : ∀ i, Kernel (X i) (Y i)) (i : ι) (x : X i) : + sigmaFamilyKernel K (@Sigma.mk ι X i x) univ=K i x univ := by + rw [sigmaFamilyKernel_apply,Measure.map_apply (measurableSigmaMk i) MeasurableSet.univ,preimage_univ] + +lemma sigmaFamilyKernel_lintegral {ι : Type*} {X Y : ι → Type*} + [∀ i, MeasurableSpace (X i)] [∀ i, MeasurableSpace (Y i)] + (K : ∀ i, Kernel (X i) (Y i)) (i : ι) (x : X i) + {F : (Σ j, Y j) → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ z, F z ∂sigmaFamilyKernel K (@Sigma.mk ι X i x)) = + ∫⁻ y, F (@Sigma.mk ι Y i y) ∂K i x := by + rw [sigmaFamilyKernel_apply,lintegral_map hF (measurableSigmaMk i)] + +lemma sigmaFamilyKernel_isFinite_of_bound {ι : Type*} {X Y : ι → Type*} + [∀ i, MeasurableSpace (X i)] [∀ i, MeasurableSpace (Y i)] + (K : ∀ i, Kernel (X i) (Y i)) {B : ℝ≥0∞} (hB : B < ∞) + (hK : ∀ i x, K i x univ ≤ B) : IsFiniteKernel (sigmaFamilyKernel K) := by + refine ⟨⟨B,hB,?_⟩⟩ + rintro ⟨i,x⟩ + rw [sigmaFamilyKernel_mass] + exact hK i x + +instance sigmaFamilyKernel_isMarkov {ι : Type*} {X Y : ι → Type*} + [∀ i, MeasurableSpace (X i)] [∀ i, MeasurableSpace (Y i)] + (K : ∀ i, Kernel (X i) (Y i)) [∀ i, IsMarkovKernel (K i)] : IsMarkovKernel (sigmaFamilyKernel K) := by + constructor + rintro ⟨i,x⟩ + constructor + rw [sigmaFamilyKernel_mass,measure_univ] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SingletonEventMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SingletonEventMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c970a5bd30b8471f3b3de028df7aa186153b8da --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SingletonEventMass.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.HarmonicConditioning +import OAI.NumberTheory.Jacobsthal.Partitions.TwoSingletonBins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceWeighted +open NumberTheoryLean ErdosCofactorChoices SingletonBinSelection SingletonBinSum CanonicalSubsetBox ErdosInverseCells +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem singleton_event_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (hi : m i = 1) + (E : (Fin n → Finset ℕ) → Prop) : + (∑ f ∈ (selections P m).filter E,(selectionProduct f : ℝ)⁻¹) = + ∑ f ∈ selections P (eraseMultiplicity m i),(selectionProduct f : ℝ)⁻¹* + harmonicMass ((P i).filter (fun p => E (fillSelection f i p))) := by + have he := singleton_weighted_sum P m i hi (fun f => if E f then (1 : ℝ) else 0) + have hl : (∑ f ∈ (selections P m).filter E,(selectionProduct f : ℝ)⁻¹) = + ∑ f ∈ selections P m,(selectionProduct f : ℝ)⁻¹*(if E f then (1 : ℝ) else 0) := by + simp only [Finset.sum_filter,mul_ite,mul_one,mul_zero] + rw [hl,he,Finset.sum_comm] + apply Finset.sum_congr rfl + intro f _hf + rw [harmonicMass,Finset.sum_filter,Finset.mul_sum] + apply Finset.sum_congr rfl + intro p _hp + split_ifs <;> ring + +theorem singleton_total_mass {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (hi : m i = 1) : + selectionMass P m = harmonicMass (P i)*selectionMass P (eraseMultiplicity m i) := by + have he := singleton_event_sum P m i hi (fun _ => True) + simp only [Finset.filter_true] at he + change selectionMass P m = _ at he + rw [he,← Finset.sum_mul] + change selectionMass P (eraseMultiplicity m i)*harmonicMass (P i) = _ + ring + +theorem singleton_event_mass_bound {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (hi : m i = 1) + (E : (Fin n → Finset ℕ) → Prop) (rho : ℝ) + (h : ∀ f ∈ selections P (eraseMultiplicity m i), + harmonicMass ((P i).filter (fun p => E (fillSelection f i p))) ≤ rho*harmonicMass (P i)) : + (∑ f ∈ (selections P m).filter E,(selectionProduct f : ℝ)⁻¹) ≤ rho*selectionMass P m := by + rw [singleton_event_sum P m i hi E] + calc + _ ≤ ∑ f ∈ selections P (eraseMultiplicity m i),(selectionProduct f : ℝ)⁻¹*(rho*harmonicMass (P i)) := by + apply Finset.sum_le_sum + intro f hf + exact mul_le_mul_of_nonneg_left (h f hf) (inv_nonneg.mpr (Nat.cast_nonneg _)) + _ = rho*selectionMass P m := by + rw [← Finset.sum_mul,singleton_total_mass P m i hi] + change selectionMass P (eraseMultiplicity m i)*(rho*harmonicMass (P i)) = _ + ring + +end ErdosVarianceWeighted + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceCompactCoupling.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceCompactCoupling.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f3b952b20945492dbc2e6aa1b60b47fb4526602 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceCompactCoupling.lean @@ -0,0 +1,412 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CompactTestMeasurable + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ActualFiniteCoupling + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualFlagInvariant PersistentFailureFlag FailureFlagBounds +open FlaggedSourceStart UniformFailureBudget PrimeBinMembership LowStateHorizon PrimeChainHorizon + +theorem actual_finite_failure : ∃ c₁ c₂ C₁ C₂ C₃ D w₀ : ℝ, + 0 < c₁ ∧ 0 < c₂ ∧ 0 < C₁ ∧ 0 < C₂ ∧ 0 < C₃ ∧ 0 < D ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, ∀ mesh : ℝ, ∀ N : ℕ, + ∀ (hnorm : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS3 : 3 ≤ S) (hS : S ≤ (Real.log w)^3) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S), + Consistent start → 0 < mesh → 2*mesh ≤ 1 → upperDisplacement S mesh N+mesh ≤ 1 → + ∀ n ≤ N, + sourceLaw hnorm hell (show 0 ≤ S from by linarith) hS hr hs hsS mesh n failed ≤ + (n:ℝ≥0∞)*ENNReal.ofReal (stepBudget c₁ c₂ C₁ C₂ C₃ D w S mesh N) := by + obtain ⟨c₁,c₂,C₁,C₂,C₃,D,w₀,hc₁,hc₂,hC₁,hC₂,hC₃,hD,hw₀,hrow⟩ := uniform_actual_bad_row + refine ⟨c₁,c₂,C₁,C₂,C₃,D,w₀,hc₁,hc₂,hC₁,hC₂,hC₃,hD,hw₀,?_⟩ + intro w hw ell S start mesh N hnorm hell hS3 hS hr hs hsS hcons hm hmesh hupper n hn + exact failure_probability_le + (jointKernel hnorm hell (by linarith) hS hr hs hsS (Real.log start.gap) mesh) + (mismatch_measurable mesh) (GoodAt (Real.log start.gap) mesh) + (GoodAt_measurable (Real.log start.gap) mesh) + (actual_good_step hnorm hell (by linarith) hS hr hs hsS (Real.log start.gap) hm) + (sourceJoint w ell S start hs) (source_good hs hsS hm.le) + (ENNReal.ofReal (stepBudget c₁ c₂ C₁ C₂ C₃ D w S mesh N)) N + (fun m hm' q hq => hrow w hw ell S start (Real.log start.gap) mesh N hnorm hell hS3 hS hr hs hsS + hcons hm hmesh hupper m hm'.le q hq) n hn + +variable {w ell S B : ℝ} {start : Node} + +theorem source_success_exits (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) + (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) {mesh : ℝ} (hm : 0 < mesh) + (n : ℕ) (hn : sourceHorizon S B ≤ n) : + ∀ᵐ q ∂sourceLaw hw hell hS0 hS hr hs hsS mesh n, + q.2 = false → q.1 = (none,CemeteryKernel.dead) := by + have hP : ∀ᵐ p ∂(sourceLaw hw hell hS0 hS hr hs hsS mesh n).map (fun q => q.1.1), p = none := by + rw [sourceLaw_prime,pathLaw_eq_cemetery hw hell hS0 hS hr hs hsS hB hsize n hn] + exact (ae_dirac_iff (measurableSet_singleton _)).mpr rfl + have hp := (ae_map_iff (measurable_fst.comp measurable_fst).aemeasurable (measurableSet_singleton _)).mp hP + filter_upwards [hp,sourceLaw_good hw hell hS0 hS hr hs hsS hm n] with q hq hgood + intro hflag + have hg := hgood hflag + rcases q with ⟨⟨p,z⟩,b⟩ + change p = none at hq + subst p + cases z with + | inl z => exact False.elim hg + | inr u => cases u; rfl + +end NumberTheoryLean.ActualFiniteCoupling + +end + +section + +namespace NumberTheoryLean.CouplingData + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualFlagInvariant KernelCouplingLift PersistentFailureFlag + +noncomputable def joint (w ell S : ℝ) (start : Node) (v mesh : ℝ) : + Kernel (JointState w ell S start) (JointState w ell S start) := + coupled (primeParent w ell S start) (continuousParent w ell S start v) + (primeLabel_measurable w ell S mesh start) (continuousLabel_measurable S mesh) + none CemeteryKernel.dead + +noncomputable def sourceLaw (w ell S : ℝ) (start : Node) (hs : Valid start.side start.ratio) + (mesh : ℝ) (n : ℕ) : Measure (FlagState (JointState w ell S start)) := + law (joint w ell S start (Real.log start.gap) mesh) (mismatch_measurable mesh) + (FlaggedSourceStart.sourceJoint w ell S start hs) n + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) +variable (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem joint_eq (v mesh : ℝ) : + jointKernel hw hell hS0 hS hr hs hsS v mesh = joint w ell S start v mesh := rfl + +theorem sourceLaw_eq (mesh : ℝ) (n : ℕ) : + FlaggedSourceStart.sourceLaw hw hell hS0 hS hr hs hsS mesh n = sourceLaw w ell S start hs mesh n := rfl + +include hw hell hS0 hS hr hsS in + +theorem source_probability (mesh : ℝ) (n : ℕ) : IsProbabilityMeasure (sourceLaw w ell S start hs mesh n) := by + rw [← sourceLaw_eq hw hell hS0 hS hr hs hsS] + infer_instance + +include hw hell hS0 hS hr hsS in + +theorem source_prime (mesh : ℝ) (n : ℕ) : + (sourceLaw w ell S start hs mesh n).map (fun q => q.1.1) = pathLaw w ell S start n := by + rw [← sourceLaw_eq hw hell hS0 hS hr hs hsS] + exact FlaggedSourceStart.sourceLaw_prime hw hell hS0 hS hr hs hsS mesh n + +end NumberTheoryLean.CouplingData + +end + +section + +namespace NumberTheoryLean.SourceCouplingRate + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualFiniteCoupling UniformFailureBudget UniformBudgetRate ActualFlagInvariant +open PersistentFailureFlag LowStateHorizon ExponentialMesh + +theorem source_coupling_rate : ∃ κ₀ : ℝ, 0 < κ₀ ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∀ d : ℝ, 0 < d → ∃ w₀ : ℝ, 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell B : ℝ, ∀ start : Node, ∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.gap ≤ (23/10:ℝ)*B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + (∀ n ≤ N, + CouplingData.sourceLaw w ell S start hs (mesh κ w) n failed ≤ + ENNReal.ofReal (Real.exp (-(κ/2)*Real.sqrt (Real.log w))) ∧ + ∀ᵐ q ∂CouplingData.sourceLaw w ell S start hs (mesh κ w) n, + q.2 = false → GoodAt (Real.log start.gap) (mesh κ w) n q.1) ∧ + (∀ᵐ q ∂CouplingData.sourceLaw w ell S start hs (mesh κ w) N, + q.2 = false → q.1 = (none,CemeteryKernel.dead)) := by + obtain ⟨c₁,c₂,C₁,C₂,C₃,D,wF,hc₁,hc₂,hC₁,hC₂,hC₃,hD,hwF,hfinite⟩ := actual_finite_failure + let κ₀ := min (c₁/4) (min (c₂/2) normalizationRate) + have hκ₀ : 0 < κ₀ := lt_min (by positivity) (lt_min (by positivity) normalizationRate_pos) + refine ⟨κ₀,hκ₀,?_⟩ + intro κ hκ hκle d hd + have hκ₁ : 4*κ ≤ c₁ := by + have h : κ ≤ c₁/4 := hκle.trans (min_le_left _ _) + linarith + have hκ₂ : 2*κ ≤ c₂ := by + have h : κ ≤ c₂/2 := (hκle.trans (min_le_right _ _)).trans (min_le_left _ _) + linarith + have hκr : κ ≤ normalizationRate := (hκle.trans (min_le_right _ _)).trans (min_le_right _ _) + let A := 5*d^3 + have hA : 0 ≤ A := by dsimp [A]; positivity + have hevent := (uniform_budget_rate hC₁.le hC₂.le hC₃.le hD.le hA hκ hκ₁ hκ₂ hκr).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + obtain ⟨W,hW⟩ := eventually_atTop.mp hevent + let w₀ := max wF (max normalizationThreshold W) + refine ⟨w₀,hwF.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hB hlogB hcomp hr hs23 hcons hsize + dsimp only + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hwF' : wF ≤ w := (le_max_left _ _).trans hw + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hwW : W ≤ w := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hw + have hwe := hW w hwW + have hscale := source_scale_bound hwe.2 hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hS : S ≤ (Real.log w)^3 := hscale.1 + have hsS : start.ratio ≤ S := by linarith + have hN : (N:ℝ) ≤ A*(Real.log w)^3 := hscale.2 + have hrate := hwe.1 S hS0 hS N hN + have hm : 0 < mesh κ w := mesh_pos κ w + constructor + · intro n hn + constructor + · have hf := hfinite w hwF' ell S start (mesh κ w) N hnorm hell hS3 hS hr hs hsS hcons + hm hrate.1 hrate.2.1 n hn + calc + _ ≤ (n:ℝ≥0∞)*ENNReal.ofReal (stepBudget c₁ c₂ C₁ C₂ C₃ D w S (mesh κ w) N) := hf + _ ≤ (N:ℝ≥0∞)*ENNReal.ofReal (stepBudget c₁ c₂ C₁ C₂ C₃ D w S (mesh κ w) N) := + mul_le_mul_of_nonneg_right (by exact_mod_cast hn) zero_le + _ = ENNReal.ofReal ((N:ℝ)*stepBudget c₁ c₂ C₁ C₂ C₃ D w S (mesh κ w) N) := by + rw [ENNReal.ofReal_mul (Nat.cast_nonneg N),ENNReal.ofReal_natCast] + _ ≤ _ := ENNReal.ofReal_le_ofReal hrate.2.2 + · exact FlaggedSourceStart.sourceLaw_good hnorm hell hS0 hS hr hs hsS hm n + · exact source_success_exits hnorm hell hS0 hS hr hs hsS hB hsize hm N le_rfl + +end NumberTheoryLean.SourceCouplingRate + +end + +section + +namespace NumberTheoryLean.MarkedSourceSmallness + +open _root_.Filter +open scoped Topology +open ExponentialMesh + +theorem mark_mesh_smallness {A κ : ℝ} (hA : 0 ≤ A) (hκ : 0 < κ) : + ∀ᶠ w : ℝ in atTop, mesh κ w ≤ 1/100 ∧ ∀ N : ℕ, + (N:ℝ) ≤ A*(Real.log w)^3 → 4*(N:ℝ)*mesh κ w ≤ Real.log (11/10) := by + have hlog : 0 < Real.log (11/10:ℝ) := Real.log_pos (by norm_num) + filter_upwards [ + (log_power_exp_tendsto 1 0 hκ).eventually (eventually_le_nhds (by norm_num : (0:ℝ) < 1/100)), + (log_power_exp_tendsto (4*A) 3 hκ).eventually (eventually_le_nhds hlog), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (0:ℝ))] with w hm hN hL + refine ⟨(mesh_upper κ w).trans (by simpa using hm),?_⟩ + intro N hbound + calc + _ ≤ (4*(A*(Real.log w)^3))*Real.exp (-κ*Real.sqrt (Real.log w)) := + mul_le_mul (by nlinarith) (mesh_upper κ w) (mesh_pos κ w).le (by positivity) + _ = (4*A)*(Real.log w)^3*Real.exp (-κ*Real.sqrt (Real.log w)) := by ring + _ ≤ _ := hN + +theorem moving_compact_gap_small (R : ℝ) {K : ℝ} (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop, R < 6*(K*(Real.log w)^2) := by + filter_upwards [Real.tendsto_log_atTop.eventually + (eventually_ge_atTop (max (1:ℝ) (1+R/(6*K))))] with w hw + have hL : 1 ≤ Real.log w := (le_max_left _ _).trans hw + have hR : 1+R/(6*K) ≤ Real.log w := (le_max_right _ _).trans hw + have hm := mul_le_mul_of_nonneg_left hR (show 0 ≤ 6*K by positivity) + have he : 6*K*(1+R/(6*K)) = 6*K+R := by field_simp [hK.ne'] + rw [he] at hm + have hSq : Real.log w ≤ (Real.log w)^2 := by nlinarith + have hs := mul_le_mul_of_nonneg_left hSq (show 0 ≤ 6*K by positivity) + nlinarith + +end NumberTheoryLean.MarkedSourceSmallness + +end + +section + +namespace NumberTheoryLean.CompactCouplingError + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualFlagInvariant PersistentFailureFlag +open CompactTestGeometry CompactTestMeasurable PrimeCompactVisits + +variable {w ell S : ℝ} {start : Node} + +noncomputable def difference (v : ℝ) (F : Side → ℝ×ℝ → ℝ) + (q : FlagState (JointState w ell S start)) : ℝ≥0∞ := + ENNReal.ofReal |primeTest F q.1.1-continuousTest v F q.1.2| + +theorem difference_measurable (v : ℝ) (F : Side → ℝ×ℝ → ℝ) (hF : ∀ i,Measurable (F i)) : + Measurable (difference (w:=w) (ell:=ell) (S:=S) (start:=start) v F) := + ENNReal.measurable_ofReal.comp (((primeTest_measurable F).comp (measurable_fst.comp measurable_fst)).sub + ((continuousTest_measurable v F hF).comp (measurable_snd.comp measurable_fst))).abs + +theorem actual_finite_compact_error (F : Side → ℝ×ℝ → ℝ) + (hF : ∀ i,UniformContinuous (F i)) {K η A : ℝ} (hK : 0 ≤ K) (hη : 0 < η) (hA : 0 ≤ A) + (hbound : ∀ i x,|F i x| ≤ A) (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → F i (r,s)=0) : + ∃ δ : ℝ,0 < δ ∧ ∀ w ell S : ℝ,∀ start : Node, + ∀ _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, + ∀ mesh : ℝ,0 < mesh → mesh ≤ δ → ∀ N : ℕ, + 4*(N:ℝ)*mesh ≤ 1 → 3*K*(Real.exp (4*(N:ℝ)*mesh)-1) ≤ δ → + (∑ n ∈ range N,∫⁻ q,difference (Real.log start.gap) F q ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal (η*(3*K+1))+ENNReal.ofReal (2*A)*(∑ n ∈ range N,CouplingData.sourceLaw w ell S start hs mesh n failed) := by + obtain ⟨δ,hδ,hcompare⟩ := actual_compact_test_comparison F hF hK hη hsupport + refine ⟨δ,hδ,?_⟩ + intro w ell S start hw hell hS0 hS hr hs hsS mesh hm hmδ N hclock hgap + have hpoint : ∀ n < N,∀ᵐ q ∂CouplingData.sourceLaw w ell S start hs mesh n, + difference (Real.log start.gap) F q ≤ ENNReal.ofReal η*ENNReal.ofReal (visit (3*K) q.1.1)+ + ENNReal.ofReal (2*A)*failed.indicator (fun _ => (1:ℝ≥0∞)) q := by + intro n hn + have hgood := FlaggedSourceStart.sourceLaw_good hw hell hS0 hS hr hs hsS hm n + rw [CouplingData.sourceLaw_eq hw hell hS0 hS hr hs hsS] at hgood + filter_upwards [hgood] with q hq + by_cases hb : q.2 = false + · have hnum : 4*(n:ℝ)*mesh ≤ 4*(N:ℝ)*mesh := by + have hnR : (n:ℝ) ≤ (N:ℝ) := by exact_mod_cast hn.le + nlinarith + have hgapn : 3*K*(Real.exp (4*(n:ℝ)*mesh)-1) ≤ δ := by + exact (mul_le_mul_of_nonneg_left (sub_le_sub_right (Real.exp_le_exp.mpr hnum) 1) (by positivity)).trans hgap + have hc := hcompare w ell S start (by linarith : 0 ≤ ell) hr hs (Real.log start.gap) mesh n hmδ + (hnum.trans hclock) hgapn q.1 (hq hb) + rw [indicator_of_notMem (show q ∉ (failed:Set (FlagState (JointState w ell S start))) by change ¬q.2=true; simp [hb]),mul_zero,add_zero] + rw [← ENNReal.ofReal_mul hη.le] + exact ENNReal.ofReal_le_ofReal hc + · have hbtrue : q.2 = true := by cases he : q.2 <;> simp_all + rw [indicator_of_mem (show q ∈ (failed:Set (FlagState (JointState w ell S start))) from hbtrue),mul_one] + exact (ENNReal.ofReal_le_ofReal (test_difference_bound hA hbound (Real.log start.gap) q.1.1 q.1.2)).trans + (le_add_of_nonneg_left zero_le) + have hone : ∀ n < N,(∫⁻ q,difference (Real.log start.gap) F q ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal η*(∫⁻ z,ENNReal.ofReal (visit (3*K) z) ∂pathLaw w ell S start n)+ + ENNReal.ofReal (2*A)*CouplingData.sourceLaw w ell S start hs mesh n failed := by + intro n hn + have he := CouplingData.source_prime hw hell hS0 hS hr hs hsS mesh n + calc + _ ≤ ∫⁻ q,ENNReal.ofReal η*ENNReal.ofReal (visit (3*K) q.1.1)+ + ENNReal.ofReal (2*A)*failed.indicator (fun _ => (1:ℝ≥0∞)) q ∂CouplingData.sourceLaw w ell S start hs mesh n := + lintegral_mono_ae (hpoint n hn) + _ = _ := by + rw [lintegral_add_left (f:=fun q : FlagState (JointState w ell S start) => ENNReal.ofReal η*ENNReal.ofReal (visit (3*K) q.1.1)) + (measurable_const.mul ((measurable_of_countable (fun z : ChainState w ell S start => ENNReal.ofReal (visit (3*K) z))).comp (measurable_fst.comp measurable_fst))), + lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + lintegral_indicator failed_measurable,setLIntegral_const,one_mul,← he, + lintegral_map (g:=fun q : FlagState (JointState w ell S start) => q.1.1) + (measurable_of_countable (fun z : ChainState w ell S start => ENNReal.ofReal (visit (3*K) z))) + (measurable_fst.comp measurable_fst)] + have hsum := Finset.sum_le_sum (s:=range N) (fun n hn => hone n (Finset.mem_range.mp hn)) + rw [Finset.sum_add_distrib,← Finset.mul_sum,← Finset.mul_sum] at hsum + refine hsum.trans (add_le_add_left ?_ _) + have hvisit := finite_compact_visits hw hell hS0 hS hr hs hsS (K:=3*K) (by positivity) N + have h := mul_le_mul_of_nonneg_left hvisit (show 0 ≤ ENNReal.ofReal η from zero_le) + rw [← ENNReal.ofReal_mul hη.le] at h + exact h + +end NumberTheoryLean.CompactCouplingError + +end + +section + +namespace NumberTheoryLean.SourceCompactCoupling + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open CompactTestGeometry CompactCouplingError ExponentialMesh SourceMarginalRate +open SourceCouplingRate HorizonMeshSmallness UniformBudgetRate LowStateHorizon PersistentFailureFlag + +theorem source_compact_coupling (F : Side → ℝ×ℝ → ℝ) (hF : ∀ i,UniformContinuous (F i)) + {K A : ℝ} (hK : 0 ≤ K) (hA : 0 ≤ A) (hbound : ∀ i x,|F i x| ≤ A) + (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → F i (r,s)=0) : + ∃ κ₀ : ℝ,0 < κ₀ ∧ ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ d ε : ℝ,0 < d → 0 < ε → + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.gap ≤ (23/10:ℝ)*B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + (∑ n ∈ range N,∫⁻ q,difference (Real.log start.gap) F q + ∂CouplingData.sourceLaw w ell S start hs (mesh κ w) n) ≤ ENNReal.ofReal ε := by + obtain ⟨κ₀,hκ₀,hrate⟩ := source_coupling_rate + refine ⟨κ₀,hκ₀,?_⟩ + intro κ hκ hκle d ε hd hε + let η := ε/(2*(3*K+1)) + have hη : 0 < η := by dsimp [η]; positivity + obtain ⟨δ,hδ,hfinite⟩ := actual_finite_compact_error F hF hK hη hA hbound hsupport + obtain ⟨wP,hwP,hrate⟩ := hrate κ hκ hκle d hd + let H := 5*d^3 + have hH : 0 ≤ H := by dsimp [H]; positivity + have hevent := (horizon_mesh_smallness (D:=0) hH (by norm_num) hκ).and + ((mesh_eventually_small hκ hδ).and + (((log_power_exp_tendsto (2*A*H) 3 (show 0 < κ/2 by linarith)).eventually + (eventually_le_nhds (show 0 < ε/2 by linarith))).and + (((log_power_exp_tendsto (36*K*H) 3 hκ).eventually (eventually_le_nhds hδ)).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2)))))) + obtain ⟨wAux,hwAux⟩ := eventually_atTop.mp hevent + refine ⟨max wP (max normalizationThreshold wAux),hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hB hlogB hcomp hr h23 hcons hsize + dsimp only + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hwe := hwAux w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw) + have hscale := source_scale_bound hwe.2.2.2.2 hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hN : (N:ℝ) ≤ H*(Real.log w)^3 := hscale.2 + have hnum := hwe.1 S hS0 hscale.1 N hN + have hm := mesh_pos κ w + have hgap : 3*K*(Real.exp (4*(N:ℝ)*mesh κ w)-1) ≤ δ := by + have he := exp_increment (show 0 ≤ 4*(N:ℝ)*mesh κ w by positivity) hnum.2.1 + have hlog : 0 ≤ Real.log w := (sq_nonneg d).trans hwe.2.2.2.2 + have hmul : (N:ℝ)*mesh κ w ≤ (H*(Real.log w)^3)*Real.exp (-κ*Real.sqrt (Real.log w)) := + mul_le_mul hN (mesh_upper κ w) hm.le (by positivity) + calc + _ ≤ 36*K*((N:ℝ)*mesh κ w) := by nlinarith [mul_le_mul_of_nonneg_left he (show 0 ≤ 3*K by positivity)] + _ ≤ (36*K*H)*(Real.log w)^3*Real.exp (-κ*Real.sqrt (Real.log w)) := by + have hh := mul_le_mul_of_nonneg_left hmul (show 0 ≤ 36*K by positivity) + simpa only [mul_assoc] using hh + _ ≤ _ := hwe.2.2.2.1 + have herror := hfinite w ell S start hnorm hell hS0 hscale.1 hr hs hsS (mesh κ w) hm hwe.2.1 N hnum.2.1 hgap + have hfail := (hrate w ((le_max_left _ _).trans hw) ell B start hs hell hB hlogB hcomp hr h23 hcons hsize).1 + have hsumfail : (∑ n ∈ range N,CouplingData.sourceLaw w ell S start hs (mesh κ w) n failed) ≤ + (N:ℝ≥0∞)*ENNReal.ofReal (Real.exp (-(κ/2)*Real.sqrt (Real.log w))) := by + calc + _ ≤ ∑ _n ∈ range N,ENNReal.ofReal (Real.exp (-(κ/2)*Real.sqrt (Real.log w))) := by + apply Finset.sum_le_sum + intro n hn + exact (hfail n (show n ≤ N from (Finset.mem_range.mp hn).le)).1 + _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] + have hfailSmall : ENNReal.ofReal (2*A)*(∑ n ∈ range N,CouplingData.sourceLaw w ell S start hs (mesh κ w) n failed) ≤ + ENNReal.ofReal (ε/2) := by + refine (mul_le_mul_of_nonneg_left hsumfail zero_le).trans ?_ + rw [← ENNReal.ofReal_natCast,← ENNReal.ofReal_mul (Nat.cast_nonneg _), + ← ENNReal.ofReal_mul (show 0 ≤ 2*A by positivity)] + apply ENNReal.ofReal_le_ofReal + have hn := mul_le_mul_of_nonneg_left hN (show 0 ≤ 2*A by positivity) + have he := mul_le_mul_of_nonneg_right hn (Real.exp_pos (-(κ/2)*Real.sqrt (Real.log w))).le + have hlim := hwe.2.2.1 + nlinarith + have hηeq : η*(3*K+1)=ε/2 := by dsimp [η]; field_simp + rw [hηeq] at herror + refine herror.trans ((add_le_add_right hfailSmall _).trans ?_) + rw [← ENNReal.ofReal_add (show 0 ≤ ε/2 by positivity) (show 0 ≤ ε/2 by positivity)] + exact le_of_eq (congrArg ENNReal.ofReal (by ring : ε/2+ε/2=ε)) + +end NumberTheoryLean.SourceCompactCoupling + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceFullEventCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceFullEventCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..f907620e160eb4f68b144baa334b6364f1045378 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceFullEventCount.lean @@ -0,0 +1,140 @@ +import OAI.NumberTheory.Jacobsthal.Primes.FullPrimeEventFibres + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosVarianceLargeMap +open ErdosVarianceSmallModel ErdosVarianceLargeCount +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def patternEventWeight (w : ℝ) (H : ℕ) (E : ErdosLargePatternLaw.FullPattern w H → Prop) : ℝ := + ∑ _v ∈ Finset.univ.filter E,ErdosLargePatternLaw.weight w H + +theorem full_pattern_card_numeric (w : ℝ) (H : ℕ) : + Fintype.card (ErdosLargePatternLaw.FullPattern w H) = patternCard (divisorModulus w H) (coprimeModulus w H) := by + rw [ErdosLargePatternLaw.pattern_card,patternCard] + ring + +theorem full_pattern_weight_numeric (w : ℝ) (H : ℕ) : + ErdosLargePatternLaw.weight w H = 1/(patternCard (divisorModulus w H) (coprimeModulus w H) : ℝ) := by + unfold ErdosLargePatternLaw.weight patternCard + push_cast + congr 1 + ring + +theorem patternEventWeight_card (w : ℝ) (H : ℕ) (E : ErdosLargePatternLaw.FullPattern w H → Prop) : + patternEventWeight w H E = ((Finset.univ.filter E).card : ℝ)/ + (patternCard (divisorModulus w H) (coprimeModulus w H) : ℝ) := by + rw [patternEventWeight,Finset.sum_const,nsmul_eq_mul,full_pattern_weight_numeric] + ring + +theorem patternEventWeight_nonneg (w : ℝ) (H : ℕ) (E : ErdosLargePatternLaw.FullPattern w H → Prop) : + 0 ≤ patternEventWeight w H E := Finset.sum_nonneg (fun _ _ => (ErdosLargePatternLaw.weight_positive w H).le) + +end ErdosVarianceLargeMap + + + +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceLargeCount ErdosLargeHeightBlocks ErdosInversePrimeBin +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem full_event_count_bound (R theta w C err : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 0 < R) (htheta : 0 < theta) (herr : 0 ≤ err) (hw : 0 ≤ w) + (hP : ∀ p ∈ primeBin R theta,p.Prime) (hlarge : ∀ p ∈ primeBin R theta,w < (p : ℝ)) + (hbound : ∀ (i : Fin (blockCount C0 R theta H)) (v : ErdosLargePatternLaw.FullPattern w H), + ((blockPatternPrimes R theta w H C0 hw hP hlarge i v).card : ℝ) ≤ + C*(blockRight C0 R theta H i-blockLeft C0 R theta H i)/ + ((patternCard (divisorModulus w H) (coprimeModulus w H) : ℝ)*Real.log R)+err) + (E : ErdosLargePatternLaw.FullPattern w H → Prop) : + ((fullPrimeEvent (primeBin R theta) w H C0 hw hP hlarge E).card : ℝ) ≤ + C*theta*R/Real.log R*patternEventWeight w H E+ + (blockCount C0 R theta H : ℝ)*(patternCard (divisorModulus w H) (coprimeModulus w H) : ℝ)*err := by + let B := Finset.univ.filter E + let M : ℝ := patternCard (divisorModulus w H) (coprimeModulus w H) + let n : ℝ := blockCount C0 R theta H + have hinner : (∑ i : Fin (blockCount C0 R theta H), + (C*(blockRight C0 R theta H i-blockLeft C0 R theta H i)/(M*Real.log R)+err)) = + C*(theta*R)/(M*Real.log R)+n*err := by + rw [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + congr 1 + calc + _ = (C/(M*Real.log R))*∑ i : Fin (blockCount C0 R theta H), + (blockRight C0 R theta H i-blockLeft C0 R theta H i) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _hi + ring + _ = _ := by rw [block_width_sum];ring + have hsum : ((fullPrimeEvent (primeBin R theta) w H C0 hw hP hlarge E).card : ℝ) ≤ + (B.card : ℝ)*(C*(theta*R)/(M*Real.log R)+n*err) := by + rw [fullPrimeEvent_card_fibres R theta w H C0 hR htheta hw hP hlarge E,Nat.cast_sum] + simp_rw [Nat.cast_sum] + calc + _ ≤ ∑ i : Fin (blockCount C0 R theta H),∑ _v ∈ B, + (C*(blockRight C0 R theta H i-blockLeft C0 R theta H i)/(M*Real.log R)+err) := by + apply Finset.sum_le_sum + intro i _hi + exact Finset.sum_le_sum (fun v _hv => hbound i v) + _ = _ := by + rw [Finset.sum_comm] + simp only [hinner,Finset.sum_const,nsmul_eq_mul] + have hB : (B.card : ℝ) ≤ M := by + have hh := Finset.card_le_univ B + rw [full_pattern_card_numeric] at hh + dsimp [M] + exact_mod_cast hh + have hevent : patternEventWeight w H E = (B.card : ℝ)/M := patternEventWeight_card w H E + have herror : (B.card : ℝ)*(n*err) ≤ M*(n*err) := mul_le_mul_of_nonneg_right hB (by dsimp [n];positivity) + have he : (B.card : ℝ)*(C*(theta*R)/(M*Real.log R)+n*err) = + C*theta*R/Real.log R*patternEventWeight w H E+(B.card : ℝ)*(n*err) := by + rw [hevent] + ring + have hright : C*theta*R/Real.log R*patternEventWeight w H E+(B.card : ℝ)*(n*err) ≤ + C*theta*R/Real.log R*patternEventWeight w H E+n*M*err := by nlinarith + exact hsum.trans (he.trans_le hright) + +end ErdosVarianceLargeMap + + + +open _root_.Filter +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceLargeCount ErdosLargeHeightBlocks + ErdosInversePrimeBin ErdosInverseBoxHeight +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_full_event_count (alpha : ℝ) (halpha : 0 < alpha) : + ∃ C : ℝ,0 < C ∧ ∀ᶠ z : ℝ in atTop,1 < z ∧ + ∀ (R theta : ℝ),z^alpha ≤ R → 0 < theta → theta ≤ 1 → + ∀ (H : ℕ) (C0 : ℤ),2 ≤ H → Int.gcd C0 (H : ℤ) = 1 → + R^((4 : ℝ)/5) ≤ (H : ℝ) → (H : ℝ) ≤ R*(sourceZ z)^11 → + ∀ (hw : 0 ≤ sourceW z) (hP : ∀ p ∈ primeBin R theta,p.Prime) + (hlarge : ∀ p ∈ primeBin R theta,sourceW z < (p : ℝ)) + (E : ErdosLargePatternLaw.FullPattern (sourceW z) H → Prop), + ((fullPrimeEvent (primeBin R theta) (sourceW z) H C0 hw hP hlarge E).card : ℝ) ≤ + C*theta*R/Real.log R*patternEventWeight (sourceW z) H E+ + (blockCount C0 R theta H : ℝ)* + (patternCard (divisorModulus (sourceW z) H) (coprimeModulus (sourceW z) H) : ℝ)*R^((9 : ℝ)/10) := by + obtain ⟨C,hC,hbound⟩ := source_block_fibre_bound alpha halpha + refine ⟨C,hC,?_⟩ + filter_upwards [hbound] with z hz + refine ⟨hz.1,?_⟩ + intro R theta hRlo htheta htheta1 H C0 hH hC0 hHlo hHhi hw hP hlarge E + have hR : 0 < R := (Real.rpow_pos_of_pos (by linarith [hz.1]) alpha).trans_le hRlo + exact full_event_count_bound R theta (sourceW z) C (R^((9 : ℝ)/10)) H C0 hR htheta + (Real.rpow_nonneg hR.le _) hw hP hlarge + (hz.2 R theta hRlo htheta htheta1 H C0 hH hC0 hHlo hHhi hw hP hlarge) E + +end ErdosVarianceLargeMap + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceIsolatedProbability.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceIsolatedProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..7cd8785c2a5d2ea084a5df7588088a75d566c93e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceIsolatedProbability.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalCrossingTail +import OAI.NumberTheory.Jacobsthal.Estimates.NonisolatedSelectedOccurrence +import OAI.NumberTheory.Jacobsthal.Partitions.CrossingMeshRate + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SourceIsolatedProbability +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualCoupledHistories FlaggedSourceStart SourceSelectedCompactOccupation SourceCouplingRate +open NonisolatedSelectedOccurrence NonisolatedWordOccurrence GoodCrossingVisit CrossingPrimeBin +open CanonicalCrossingTail CrossingMeshRate ExponentialMesh LowStateHorizon SourceSuccessfulTail + + +theorem source_nonisolated_probability (D theta eps : ℝ) (hD : 0 < D) + (htheta : 0 < theta) (htheta1 : theta ≤ 1/2) (heps : 0 < eps) : + ∃ κ alpha B₀ w₀ : ℝ,0 < κ ∧ 0 < alpha ∧ alpha ≤ theta ∧ 0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ hw : 1 < w,∀ top : ℝ,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → ∀ ell : ℝ,∀ start : Node, + ∀ hs : Valid start.side start.ratio,1 ≤ ell → Real.log B ≤ D*Real.log w → + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → Consistent start → start.cutoff=B → + w^start.cutoff=top → ∀ E : Set (List ℕ), + (∀ p : History w ell ((Real.log B)^2) start,p.primes ∈ E → p.node.gap ≤ theta*B ∧ + noIsolatedWord hw htop hxi B alpha (4*theta) p.primes) → + fullSourceLaw w ell ((Real.log B)^2) start hs (mesh κ w) (sourceHorizon ((Real.log B)^2) B) + {h | CompactPrefixOccurrence.occurs E _ h} ≤ ENNReal.ofReal eps := by + obtain ⟨κ,hκ,hCouple⟩ := source_coupling_rate + obtain ⟨WC,hWC,hC⟩ := hCouple κ hκ le_rfl D hD + obtain ⟨T,hT,hTail⟩ := canonical_crossing_tail (eps/2) (by positivity) + let alpha := isolatedAlpha theta (T+1) + have ha : 0 < alpha ∧ alpha ≤ theta := isolated_alpha_bounds htheta (by linarith) + have hEvents := (crossing_mesh_control (show 0 ≤ 5*D^3 by positivity) hκ).and + (((log_power_exp_tendsto 1 0 (show 0 < κ/2 by positivity)).eventually + (eventually_le_nhds (show 0 < eps/2 by positivity))).and + (Real.tendsto_log_atTop.eventually_ge_atTop (max 1 (D^2)))) + obtain ⟨W,hW⟩ := eventually_atTop.mp hEvents + refine ⟨κ,alpha,max (Real.exp 2) (1/alpha),max WC (max normalizationThreshold W), + hκ,ha.1,ha.2,(Real.exp_pos _).trans_le (le_max_left _ _),hWC.trans_le (le_max_left _ _),?_⟩ + intro B w hB₀ hw₀ hw top htop xi hxi hxi1 ell start hs hell hcomp hi h199 h23 hc hcut hcap E hE + have hB : 0 < B := (Real.exp_pos _).trans_le ((le_max_left _ _).trans hB₀) + have hlogB : 2 ≤ Real.log B := (Real.le_log_iff_exp_le hB).mpr ((le_max_left _ _).trans hB₀) + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw₀ + have he := hW w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw₀) + have hlogw : 1 ≤ Real.log w := (le_max_left _ _).trans he.2.2 + have hscale := UniformBudgetRate.source_scale_bound ((le_max_right _ _).trans he.2.2) hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hrnode := SourceNodeCoordinates.source_node_bounds hB start hi h199 h23 hc hcut + let N := sourceHorizon ((Real.log B)^2) B + have hwidth : xi/Real.log w ≤ alpha*B := by + have hlen : 1/alpha ≤ B := (le_max_right _ _).trans hB₀ + have hmul : 1 ≤ alpha*B := by have hh := (div_le_iff₀ ha.1).mp hlen; nlinarith + exact (div_le_self hxi.le hlogw).trans (hxi1.trans hmul) + have hOcc := selected_nonisolated_probability hnorm hell hS0 hscale.1 hrnode.2.1 hs hsS + hw htop hxi hB htheta htheta1 (by linarith : 1 ≤ T) h199 hc hcut hcap + (mesh_pos κ w) (mesh_le_one hκ.le w) N (he.1 N hscale.2) hwidth E hE + have hf := (hC w ((le_max_left _ _).trans hw₀) ell B start hs hell hB hlogB hcomp hrnode.2.1 h23 hc hrnode.2.2.2).1 N le_rfl |>.1 + have hfail : Real.exp (-(κ/2)*Real.sqrt (Real.log w)) ≤ eps/2 := by + simpa only [pow_zero,mul_one,one_mul] using he.2.1 + have hf' := hf.trans (ENNReal.ofReal_le_ofReal hfail) + obtain ⟨s,hsv,hcost⟩ := even_source_cost_state hs hi + have htyped : typedState start.side start.ratio hs=Sum.inl s := congrArg Prod.fst hcost + have ht := hTail (Real.log start.gap) (theta*B) s (by rwa [hsv]) (by rwa [hsv]) N + rw [← htyped] at ht + have hh := hOcc.trans (add_le_add hf' ht) + rw [← ENNReal.ofReal_add (by positivity : 0 ≤ eps/2) (by positivity : 0 ≤ eps/2)] at hh + simpa only [add_halves] using hh +end NumberTheoryLean.SourceIsolatedProbability + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceMarkedStopping.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceMarkedStopping.lean new file mode 100644 index 0000000000000000000000000000000000000000..028d261baf6c31001da3008cff75eaa8f6541fbb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceMarkedStopping.lean @@ -0,0 +1,274 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.StrongSourceFamilies +import OAI.NumberTheory.Jacobsthal.Paths.MovingStopMargins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.MarkedPrefixTools +open FinitePathGeometry PrimeHistories FiniteFirstTag ActualSourceTags PrimeBinRepresentatives +open ErdosPrimeInputs.HarmonicPrimeMeasure + +private theorem tagFrom_none (n : ℕ) (F : ℕ → Option (Fin n × ℚ)) (k : ℕ) (ps : List ℕ) + (h : ∀ p ∈ ps,F p=none) : firstTagFrom F k ps=none := by + induction ps generalizing k with + | nil => rfl + | cons p ps ih => + rw [firstTagFrom,h p (by simp)] + exact ih (k+1) (fun q hq => h q (by simp [hq])) + +theorem tagFrom_append_none (n : ℕ) (F : ℕ → Option (Fin n × ℚ)) (k : ℕ) (pre tail : List ℕ) + (h : ∀ p ∈ tail,F p=none) : firstTagFrom F k (pre++tail)=firstTagFrom F k pre := by + induction pre generalizing k with + | nil => exact tagFrom_none n F k tail h + | cons p pre ih => + simp only [List.cons_append,firstTagFrom] + cases hp : F p with + | none => exact ih (k+1) + | some bq => rfl + +theorem terminal_cutoff_last (w : ℝ) (z : Node) (ps : List ℕ) (hne : ps ≠ []) : + (terminal w z ps).cutoff=primeExponent w (ps.getLast hne) := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + rw [terminal_append] + rfl + +theorem terminal_lastD (w : ℝ) (z : Node) (ps : List ℕ) (hne : ps ≠ []) : + (terminal w z ps).cutoff=primeExponent w (ps.getLastD 0) := by + have hh := terminal_cutoff_last w z ps hne + have he : ps.getLastD 0=ps.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rwa [he] + +theorem prefix_exponent_lower {w : ℝ} (hw : 1 < w) (z : Node) (pre : List ℕ) (hne : pre ≠ []) + (hD : pre.Pairwise (· > ·)) (hp : ∀ p ∈ pre,p.Prime) : + ∀ p ∈ pre,(terminal w z pre).cutoff ≤ primeExponent w p := by + let last := pre.getLast hne + have hlast : last ∈ pre := List.getLast_mem hne + have he : pre.dropLast++[last]=pre := List.dropLast_append_getLast hne + have hdc : (pre.dropLast++[last]).Pairwise (· > ·) := by rwa [he] + intro p hpre + have hlp : last ≤ p := by + have hm : p ∈ pre.dropLast++[last] := by rwa [he] + rcases List.mem_append.mp hm with hm | hm + · exact ((List.pairwise_append.mp hdc).2.2 p hm last (by simp)).le + · have hh : p=last := Finset.mem_singleton.mp (by simpa using hm) + exact hh.symm.le + rw [terminal_cutoff_last w z pre hne] + exact div_le_div_of_nonneg_right (Real.log_le_log (by exact_mod_cast (hp last hlast).pos) + (by exact_mod_cast hlp)) (Real.log_pos hw).le + +theorem suffix_exponent_upper {w : ℝ} (hw : 1 < w) (z : Node) (pre tail : List ℕ) (hne : pre ≠ []) + (hD : (pre++tail).Pairwise (· > ·)) (hp : ∀ p ∈ pre++tail,p.Prime) : + ∀ p ∈ tail,primeExponent w p < (terminal w z pre).cutoff := by + intro p hpt + have hl := List.getLast_mem hne + have hlt : p < pre.getLast hne := (List.pairwise_append.mp hD).2.2 _ hl p hpt + rw [terminal_cutoff_last w z pre hne] + exact div_lt_div_of_pos_right (Real.log_lt_log (by exact_mod_cast (hp p (by simp [hpt])).pos) + (by exact_mod_cast hlt)) (Real.log_pos hw) + +theorem no_candidate_below_search {n : ℕ} (Y w Cs eta : ℝ) (hw : 1 < w) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℤ) + (hlo : ∀ b,0 < lower b) (hwidth : ∀ b,0 ≤ width b) (p : ℕ) + (hx : primeExponent w p < w^((1/4:ℝ))) : tagCandidate Y w Cs eta lower width label a p=none := by + cases ht : tagCandidate Y w Cs eta lower width label a p with + | none => rfl + | some bq => + rcases bq with ⟨b,q⟩ + have hh := candidate_witness Y w Cs eta lower width label a p ht + have hlow := (bin_exponent_bounds hw (hlo _) (hwidth _) hh.2.1).1 + have hs := hh.2.2.1 + change w^((1/4:ℝ)) ≤ leftExponent w (lower (label p)) at hs + exact False.elim ((not_lt_of_ge hs) (hlow.trans hx)) + +theorem sourceTag_prefix_eq {n : ℕ} (Y w Cs eta : ℝ) (hw : 1 < w) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℤ) + (hlo : ∀ b,0 < lower b) (hwidth : ∀ b,0 ≤ width b) (pre tail : List ℕ) + (htail : ∀ p ∈ tail,primeExponent w p < w^((1/4:ℝ))) : + sourceTag Y w Cs eta lower width label a (pre++tail)=sourceTag Y w Cs eta lower width label a pre := by + exact tagFrom_append_none n _ 0 pre tail (fun p hp => + no_candidate_below_search Y w Cs eta hw lower width label a hlo hwidth p (htail p hp)) +end NumberTheoryLean.MarkedPrefixTools + +end + +section + +namespace NumberTheoryLean.MarkedPrefixCandidate +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open StrongReferenceTransport StrongSourceFamilies SourceStopPredicate RepresentativeAdmission RepresentativeStopGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open ActualSourceTags FiniteFirstTag MarkedPrefixTools SuccessfulMarkedCoordinates +open ReferenceAdmission ReferencePruning +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem marked_prefix_candidate (Y : ℕ) {w top Cs eta Clen B xi b₀ b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) (hb₀ : 0 < b₀) (hCs : Cs < 2*b₀) + (hsearch : b₁ < w^((1/4:ℝ))) (hh : xi/Real.log w ≤ b₀) + (hsmall : 2*Clen*xi+(206/100)*(xi/Real.log w) ≤ (4/100)*b₀) + (a : ℕ → ℕ) (z : Node) (ps pre tail : List ℕ) (heq : ps=pre++tail) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) (hroot : b₁/2 < z.cutoff) + (href : ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap) + (hlen : (ps.length:ℝ) ≤ Clen*Real.log B) + (hsafe : representativeSafe w (representative w (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi)) z (2*Clen*xi) ps) + (t : Tag (binCount w top xi)) + (htag : sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) ps=some t) + (hcount : (ps.map (label (zero_lt_one.trans hw) htop hxi)).count t.bin=1) + (halign : ∀ p ∈ ps,Cs < primeExponent w p → aligns (sourceClass a) t.rational p) + (hwin : primeWindow b₀ b₁ (terminal w z pre)) : + (terminal w z pre).side=.even ∧ + stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z pre := by + let lab := label (zero_lt_one.trans hw) htop hxi + let rep := representative w (lower w top xi) (width w top xi) lab + have hne : pre ≠ [] := by + intro hn + have hh := hwin.2.2.2.2.1 + rw [hn,terminal_nil] at hh + linarith + have hsub : ∀ p ∈ pre,p ∈ ps := by + intro p hp + rw [heq] + exact List.mem_append.mpr (Or.inl hp) + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp href).1 + have hdFull : (pre++tail).Pairwise (· > ·) := by simpa only [← heq] using hd.1 + have hdPre := (List.pairwise_append.mp hdFull).1 + have hsource : ∀ p ∈ ps,p ∈ sourcePrimeSet w top := hd.2 + have hsourcePre : ∀ p ∈ pre,p ∈ sourcePrimeSet w top := fun p hp => hsource p (hsub p hp) + have hprimes : ∀ p ∈ pre++tail,p.Prime := by + intro p hp + exact ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hsource p (by rwa [heq]))).1 + have hprimesPre : ∀ p ∈ pre,p.Prime := fun p hp => hprimes p (by simp [hp]) + have hlenPre : (pre.length:ℝ) ≤ Clen*Real.log B := by + have hh : pre.length ≤ ps.length := by rw [heq,List.length_append]; omega + exact (by exact_mod_cast hh : (pre.length:ℝ) ≤ ps.length).trans hlen + have hb₁ : 0 < b₁ := by linarith [hwin.2.2.2.1,hwin.2.2.2.2.1] + have htailSmall : ∀ p ∈ tail,primeExponent w p < w^((1/4:ℝ)) := by + intro p hp + have hh := suffix_exponent_upper hw z pre tail hne hdFull hprimes p hp + linarith [hwin.2.2.2.2.1] + have htEq := sourceTag_prefix_eq Y w Cs eta hw (lower w top xi) (width w top xi) lab (sourceClass a) + (fun b => endpoint_pos (zero_lt_one.trans hw) _) (fun b => (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le) + pre tail htailSmall + have htagPre : sourceTag Y w Cs eta (lower w top xi) (width w top xi) lab (sourceClass a) pre=some t := by + apply htEq.symm.trans + simpa only [← heq] using htag + have hcountPre : (pre.map lab).count t.bin=1 := by + obtain ⟨u,p,v,hpre,_hidx,hbin,_hp,_hs,_ho,_ha,_hn⟩ := + sourceTag_witness Y w Cs eta (lower w top xi) (width w top xi) lab (sourceClass a) pre htagPre + have hp : p ∈ pre := by rw [hpre]; simp + have hm : t.bin ∈ pre.map lab := List.mem_map.mpr ⟨p,hp,hbin.symm⟩ + have hc := List.count_pos_iff.mpr hm + change (ps.map lab).count t.bin=1 at hcount + rw [heq,List.map_append,List.count_append] at hcount + omega + have halignPre : ∀ p ∈ pre,aligns (sourceClass a) t.rational p := by + intro p hp + have hh := prefix_exponent_lower hw z pre hne hdPre hprimesPre p hp + exact halign p (hsub p hp) (by linarith [hwin.2.2.2.1]) + have hsafePre : representativeSafe w rep z (2*Clen*xi) pre := by + intro qs hqs hneq heven + have hpre : pre <+: ps := ⟨tail,heq.symm⟩ + have hall := (List.mem_inits _ _).mp hqs |>.trans hpre + exact hsafe qs ((List.mem_inits _ _).mpr hall) hneq heven + have hrefPre : pre ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap := by + apply Finset.mem_filter.mpr + have hdecfull : pre ++ tail ∈ decreasingPrefixes (sourcePrimeSet w top) := by + simpa only [← heq] using (Finset.mem_filter.mp href).1 + refine ⟨decreasing_prefix_mem (pre := pre) (suf := tail) hdecfull,?_⟩ + exact ((admitted_append w z.gap z.side pre tail).mp (by simpa only [← heq] using (Finset.mem_filter.mp href).2)).1 + have htr := source_reference_transport hw htop z hs hz hg hclosed hcap pre hrefPre + obtain ⟨U,_hU,hU⟩ := (uncapped_iff_exists_ceiling w 1 z pre).mp ((mem_uncappedPrefixes hw z pre).mp htr.1) + have hr0 : 0 < z.gap := by linarith [hg.1] + have hn := terminal_consistent (by norm_num : (0:ℝ)≤1) hr0 hs hz hU + have hxpos : 0 < (terminal w z pre).cutoff := by linarith [hwin.2.2.2.1] + have hspos : 0 < (terminal w z pre).ratio := by linarith [hwin.2.1] + have hratio : (terminal w z pre).gap/(terminal w z pre).cutoff=(terminal w z pre).ratio := by + apply (div_eq_iff hxpos.ne').mpr + have hh := (eq_div_iff hspos.ne').mp hn + nlinarith + have hlast : pre.getLastD 0 ∈ pre := by + have hh : pre.getLastD 0=pre.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [hh] + exact List.getLast_mem hne + have hxerr := source_representative_error hw htop hxi (hsourcePre _ hlast) + change 0 ≤ rep (pre.getLastD 0)-primeExponent w (pre.getLastD 0) ∧ + rep (pre.getLastD 0)-primeExponent w (pre.getLastD 0) ≤ xi/Real.log w at hxerr + rw [← terminal_lastD w z pre hne] at hxerr + have hm := source_prefix_movement hw htop hxi hC hcomp z pre hsourcePre hlenPre + change 0 ≤ (terminal w z pre).gap-representativeGap rep z.gap pre ∧ + (terminal w z pre).gap-representativeGap rep z.gap pre ≤ 2*Clen*xi at hm + have hwindow : representativeWindow rep z b₀ b₁ pre := by + exact actual_mark_to_representative_window + (r := (terminal w z pre).gap) (rrep := representativeGap rep z.gap pre) + (x := (terminal w z pre).cutoff) (xrep := rep (pre.getLastD 0)) + (Delta := 2*Clen*xi) (h := xi/Real.log w) hb₀ hwin.2.2.2.1 hwin.2.2.2.2.1 + (by linarith [hxerr.1]) (by linarith [hxerr.2]) (by linarith [hm.1]) (by linarith [hm.2]) + (by rw [hratio]; exact hwin.2.1) (by rw [hratio]; exact hwin.2.2.1) hh hsmall + exact ⟨hwin.1,hne,hlenPre,source_list_boxed (zero_lt_one.trans hw) htop hxi pre hsourcePre, + hsafePre,hwindow,t,htagPre,hcountPre,halignPre⟩ +end NumberTheoryLean.MarkedPrefixCandidate + +end + +section + +namespace NumberTheoryLean.SourceMarkedStopping +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open StrongReferenceTransport StrongSourceFamilies SourceStopPredicate RepresentativeAdmission RepresentativeStopGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open ActualSourceTags FiniteFirstTag MarkedPrefixTools SuccessfulMarkedCoordinates +open ReferenceAdmission ReferencePruning +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass ErdosInverseAlignment +open MarkedPrefixCandidate StoppedPrefixExistence StoppedCountAdapters StoppedVertexHistory +open StoppedEvaluation StoppedTraceSets +attribute [local instance] Classical.propDecidable + +theorem marked_prefix_forces_actual_stop (Y : ℕ) {w top Cs eta Clen B xi b₀ b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) (hb₀ : 0 < b₀) (hCs : Cs < 2*b₀) + (hsearch : b₁ < w^((1/4:ℝ))) (hh : xi/Real.log w ≤ b₀) + (hsmall : 2*Clen*xi+(206/100)*(xi/Real.log w) ≤ (4/100)*b₀) + (a : ℕ → ℕ) (H : Finset ℕ) (mu : ℝ) (z : Node) (ps pre tail : List ℕ) (heq : ps=pre++tail) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) (hroot : b₁/2 < z.cutoff) + (href : ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap) + (hlen : (ps.length:ℝ) ≤ Clen*Real.log B) + (hsafe : representativeSafe w (representative w (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi)) z (2*Clen*xi) ps) + (t : Tag (binCount w top xi)) + (htag : sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) ps=some t) + (hcount : (ps.map (label (zero_lt_one.trans hw) htop hxi)).count t.bin=1) + (halign : ∀ p ∈ ps,Cs < primeExponent w p → aligns (sourceClass a) t.rational p) + (hwin : primeWindow b₀ b₁ (terminal w z pre)) : + ∃ first rest : List ℕ,ps=first++rest ∧ first ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z H (sourcePrimeSet w top) mu) := by + have hc := marked_prefix_candidate Y hw htop hxi hC hcomp hb₀ hCs hsearch hh hsmall + a z ps pre tail heq hs hz hg hclosed hcap hroot href hlen hsafe t htag hcount halign hwin + apply reference_candidate_forces_stop w _ (rootVertex z H (sourcePrimeSet w top) mu) ps href + refine ⟨pre,tail,heq,?_⟩ + unfold lowerStop + rw [after_node,after_past] + simpa only [rootVertex,List.nil_append] using hc +end NumberTheoryLean.SourceMarkedStopping + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceMarkedWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceMarkedWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..c3bfec2402d4e366e1e9f35e6f9a6b2e4ed9c962 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceMarkedWords.lean @@ -0,0 +1,90 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawWordSpaces + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FinitePathGeometry + +noncomputable def sourceCycleInputSignature (z : OddCost) (w : SourceCycleWitness) : CycleInputSignature := + (z.2,sourceReturnSignature z w) + +lemma sourceCycleInputSignature_measurable : + Measurable (fun p : OddCost × SourceCycleWitness => sourceCycleInputSignature p.1 p.2) := by + have hEven : Measurable (fun p : OddCost × SourceCycleWitness => p.2.1) := measurable_fst.comp measurable_snd + have hOld : Measurable (fun p : OddCost × SourceCycleWitness => p.1.2) := measurable_snd.comp measurable_fst + have hDur : Measurable (fun p : OddCost × SourceCycleWitness => p.2.2.1) := + measurable_fst.comp (measurable_snd.comp measurable_snd) + have hRet : Measurable (fun p : OddCost × SourceCycleWitness => p.2.2.2) := + measurable_snd.comp (measurable_snd.comp measurable_snd) + exact hOld.prodMk (hDur.prodMk (((measurable_inl.comp hEven).prodMk + (hOld.add (cost_measurable.comp (measurable_subtype_coe.comp hEven)))).prodMk + (embedOdd_measurable.comp hRet))) + +noncomputable def sourceWordUpdate (k : ℕ) (p : OddCost × (SourceCycleWitness × CycleWordSignature k)) : + CycleWordSignature (k+1) := (sourceCycleInputSignature p.1 p.2.1,p.2.2) + +lemma sourceWordUpdate_measurable (k : ℕ) : Measurable (sourceWordUpdate k) := + (sourceCycleInputSignature_measurable.comp + (measurable_fst.prodMk (measurable_fst.comp measurable_snd))).prodMk + (measurable_snd.comp measurable_snd) + +def sourceContinuationInput (p : OddCost × SourceCycleWitness) : OddCost := p.2.2.2 + +lemma sourceContinuationInput_measurable : Measurable sourceContinuationInput := + measurable_snd.comp (measurable_snd.comp measurable_snd) + +noncomputable def sourceMarkedWordKernel : (w : List Bool) → Kernel OddCost (CycleWordSignature w.length) + | [] => Kernel.deterministic embedOdd embedOdd_measurable + | b::w => + (Kernel.id ×ₖ (sourceBranchWitnessKernel b ⊗ₖ + (sourceMarkedWordKernel w).comap sourceContinuationInput sourceContinuationInput_measurable)).map + (sourceWordUpdate w.length) + +instance sourceMarkedWordKernel_isFiniteKernel (w : List Bool) : IsFiniteKernel (sourceMarkedWordKernel w) := by + induction w with + | nil => change IsFiniteKernel (Kernel.deterministic embedOdd embedOdd_measurable); infer_instance + | cons b w ih => rw [sourceMarkedWordKernel]; infer_instance + +lemma sourceMarkedWord_cons_lintegral (b : Bool) (w : List Bool) (z : OddCost) + {F : CycleWordSignature (b::w).length → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ s, F s ∂sourceMarkedWordKernel (b::w) z) = + ∫⁻ y : SourceCycleWitness, ∫⁻ s, + F (sourceCycleInputSignature z y,s) ∂sourceMarkedWordKernel w y.2.2 ∂sourceBranchWitnessKernel b z := by + rw [sourceMarkedWordKernel,Kernel.map_apply _ (sourceWordUpdate_measurable _), + lintegral_map hF (sourceWordUpdate_measurable _),Kernel.lintegral_id_prod (f := fun p : OddCost × (SourceCycleWitness × CycleWordSignature w.length) => F (sourceWordUpdate w.length p)) (hF.comp (sourceWordUpdate_measurable _)), + Kernel.lintegral_compProd _ _ _ + (f := fun p : SourceCycleWitness × CycleWordSignature w.length => F (sourceWordUpdate w.length (z,p))) + ((hF.comp (sourceWordUpdate_measurable _)).comp measurable_prodMk_left)] + rfl + +lemma sourceBranchWitness_mass_le_one (b : Bool) (z : OddCost) : sourceBranchWitnessKernel b z univ ≤ 1 := by + rw [sourceBranchWitnessKernel,Kernel.restrict_apply] + exact (Measure.restrict_le_self univ).trans_eq measure_univ + +lemma sourceMarkedWord_mass_le_one (w : List Bool) : ∀ z, sourceMarkedWordKernel w z univ ≤ 1 := by + induction w with + | nil => intro z; change (Measure.dirac (embedOdd z)) univ ≤ 1; simp + | cons b w ih => + intro z + have he := sourceMarkedWord_cons_lintegral b w z (F := fun _ => (1:ℝ≥0∞)) measurable_const + simp only [lintegral_const,one_mul] at he + rw [he] + calc + _ ≤ ∫⁻ _y, (1:ℝ≥0∞) ∂sourceBranchWitnessKernel b z := lintegral_mono (fun y => ih y.2.2) + _ = sourceBranchWitnessKernel b z univ := by simp + _ ≤ 1 := sourceBranchWitness_mass_le_one b z + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceThresholdCoupling.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceThresholdCoupling.lean new file mode 100644 index 0000000000000000000000000000000000000000..c22314ae2fcf5443302435ddd9f1a0a2e57d536f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceThresholdCoupling.lean @@ -0,0 +1,214 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.TwoSidedThresholdOccurrence +import OAI.NumberTheory.Jacobsthal.Estimates.TwoSidedThresholdStability + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReconstructedParentCoupling +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeBinMembership +open RepresentativeStopGeometry NearbyParentGeometry ActualFlagInvariant +open TwoSidedThresholdStability TwoSidedThresholdArrival TwoSidedThresholdGeometry +open ArrivalKernelGeometry RegeneratingInverseBands ErdosEvenThreshold + +def primeNearThreshold (d : ℝ) (z : Node) : Prop := + z.side=.even ∧ 1 < z.cutoff ∧ 0 ≤ z.gap-sourceHeight z.cutoff ∧ z.gap-sourceHeight z.cutoff ≤ d + +theorem node_parent_reconstruction (z : Node) (hc : Consistent z) (hs : 0 < z.ratio) : + nextExponent (z.gap+z.cutoff) z.ratio=z.cutoff ∧ nextGap (z.gap+z.cutoff) z.ratio=z.gap := by + have he : z.cutoff=z.gap/z.ratio := hc + constructor + · rw [he] + unfold nextExponent + field_simp [hs.ne',show z.ratio+1 ≠ 0 by positivity] + · rw [he] + unfold nextGap + field_simp [hs.ne',show z.ratio+1 ≠ 0 by positivity] + +theorem node_near_reconstruction {d : ℝ} (z : Node) (hc : Consistent z) (hs : 0 < z.ratio) + (hn : primeNearThreshold d z) : z.ratio ∈ nearThreshold (z.gap+z.cutoff) d := by + have hg := node_parent_reconstruction z hc hs + change 1 < nextExponent (z.gap+z.cutoff) z.ratio ∧ + 0 ≤ thresholdSlack (z.gap+z.cutoff) z.ratio ∧ thresholdSlack (z.gap+z.cutoff) z.ratio ≤ d + rw [thresholdSlack,hg.1,hg.2] + exact hn.2 + +theorem log_reconstructed_parent {r t : ℝ} (hr : 0 < r) (ht : 0 < t) : + Real.log (r+r/t)=Real.log r+cost t := by + have he : r+r/t=r*(1+1/t) := by ring + rw [he,Real.log_mul hr.ne' (show 1+1/t ≠ 0 by positivity)] + rfl + +theorem reconstructed_log_stability {r q t u D h : ℝ} (hr : 0 < r) (hq : 0 < q) + (ht : (1/2:ℝ) ≤ t) (hu : (1/2:ℝ) ≤ u) + (hgap : |Real.log r-Real.log q| ≤ D) (hratio : |t-u| ≤ h) : + |Real.log (r+r/t)-Real.log (q+q/u)| ≤ D+4*h := by + rw [log_reconstructed_parent hr (by linarith),log_reconstructed_parent hq (by linarith)] + have he : (Real.log r+cost t)-(Real.log q+cost u)= + (Real.log r-Real.log q)+(cost t-cost u) := by ring + rw [he] + have hc := cost_stability ht hu + exact (abs_add_le _ _).trans (by linarith) + +theorem good_prime_near_thick {w ell S v mesh d : ℝ} {start : Node} + (hell : 0 ≤ ell) (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hc : Consistent start) + (n : ℕ) (h : History w ell S start) (y : CostState) + (hgood : GoodAt v mesh n (some h,Sum.inl y)) + (hy2 : 2 ≤ stateRatio y.1) (hmesh : mesh ≤ 1) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) + (hexp : Real.exp (4*((n:ℝ)+1)*mesh) ≤ 4/3) (hne : primeNearThreshold d h.node) : + y ∈ thickArrival v d (3*mesh+3*(Real.exp (4*((n:ℝ)+1)*mesh)-1)) := by + have hcons := history_consistent hell hr hs hc h + have hvalid := terminal_valid hs h.admissible + have hpos : 0 < h.node.gap := terminal_gap_positive hell hr hs h.admissible + have hratio : 0 < h.node.ratio := valid_pos hvalid + have hnear := node_near_reconstruction h.node hcons hratio hne + have htwo : 2 ≤ h.node.ratio := ((thresholdStrip_eq_near _ _).symm ▸ hnear : + h.node.ratio ∈ thresholdStrip (h.node.gap+h.node.cutoff) d).1 + have he : h.node.cutoff=h.node.gap/h.node.ratio := hcons + have hg := reconstructed_log_stability (r := h.node.gap) (q := gapValue v y) + (t := h.node.ratio) (u := stateRatio y.1) hpos (Real.exp_pos _) (by linarith) (by linarith) + hgood.2.2.2 hgood.2.2.1 + have hpg : |Real.log (h.node.gap+h.node.cutoff)-Real.log (reconstructedParent v y)| ≤ + 4*((n:ℝ)+1)*mesh := by + rw [he] + change |Real.log (h.node.gap+h.node.gap/h.node.ratio)- + Real.log (gapValue v y+gapValue v y/stateRatio y.1)| ≤ _ + convert hg using 1 + ring + have hQ : 0 < reconstructedParent v y := add_pos (Real.exp_pos _) (currentExponent_pos v y) + have hh := coupled_near_to_thick hQ hy2 hd0 hd1 hnear hgood.2.2.1 hmesh hpg hexp + have hi : stateSide y.1=.even := hgood.2.1.symm.trans hne.1 + refine ⟨hi,hh.1,?_⟩ + simpa only [add_assoc] using hh.2 +end NumberTheoryLean.ReconstructedParentCoupling + +end + +section + +namespace NumberTheoryLean.SourceThresholdCoupling +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open FiniteHistoryTransport FiniteHistoryOccurrence ActualProcessCoupling ActualCoupledHistories +open ActualSuccessfulHistories ActualFlagInvariant PersistentFailureFlag +open ReconstructedParentCoupling CoupledEvenArrivalSupport CompletedArrivalOccurrence +open TwoSidedThresholdArrival TwoSidedThresholdKernel TwoSidedThresholdOccurrence +open CanonicalGapExposure RegeneratingInverseBands +attribute [local instance] Classical.propDecidable + +variable {w ell S : ℝ} {start : Node} + +def nearPrimeNode (d : ℝ) : ChainState w ell S start → Prop + | none => False + | some h => primeNearThreshold d h.node + +def primeThresholdOccurs (d : ℝ) (N : ℕ) (h : Hist (FlagState (JointState w ell S start)) N) : Prop := + ∃ j : Fin N,nearPrimeNode d (h ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩).1.1 + +theorem primeThresholdOccurs_measurable (d : ℝ) (N : ℕ) : + MeasurableSet {h : Hist (FlagState (JointState w ell S start)) N | primeThresholdOccurs d N h} := by + simp only [primeThresholdOccurs,Set.ofPred_exists] + apply MeasurableSet.iUnion + intro j + have hm : Measurable (fun h : Hist (FlagState (JointState w ell S start)) N => + (h ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩).1.1) := by fun_prop + exact hm (show MeasurableSet {z : ChainState w ell S start | nearPrimeNode d z} from by trivial) + +noncomputable def thresholdPerturbation (mesh : ℝ) (N : ℕ) : ℝ := + 3*mesh+3*(Real.exp (4*((N:ℝ)+1)*mesh)-1) + +theorem thresholdPerturbation_nonneg {mesh : ℝ} (hm : 0 ≤ mesh) (N : ℕ) : + 0 ≤ thresholdPerturbation mesh N := by + have he : 1 ≤ Real.exp (4*((N:ℝ)+1)*mesh) := Real.one_le_exp_iff.mpr (by positivity) + unfold thresholdPerturbation + linarith + +theorem thickArrival_mono {v d e f : ℝ} (hef : e ≤ f) : thickArrival v d e ⊆ thickArrival v d f := by + intro y hy + exact ⟨hy.1,hy.2.1,hy.2.2.1,hy.2.2.2.1,hy.2.2.2.2.trans (add_le_add le_rfl hef)⟩ + +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistory_threshold_transfer (hc : Consistent start) + {mesh d : ℝ} (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) + (N : ℕ) (hexp : Real.exp (4*((N:ℝ)+1)*mesh) ≤ 4/3) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + (last N h).2=false → primeThresholdOccurs d N h → + completedOccurrence (thickArrival (Real.log start.gap) d (thresholdPerturbation mesh N)) N + (mapHist (fun q => q.1.2) N h) := by + filter_upwards [sourceHistory_success_good hw hell hS0 hS hr hs hsS hm N, + sourceHistory_even_arrivals hw hell hS0 hS hr hs hsS mesh N] with h hgood hsupport + intro hf hbad + obtain ⟨j,hj⟩ := hbad + let k : Finset.Iic N := ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩ + have hg := hgood hf k + change GoodAt (Real.log start.gap) mesh (j.1+1) ((h k).1.1,(h k).1.2) at hg + change nearPrimeNode d ((h k).1.1) at hj + cases hp : (h k).1.1 with + | none => rw [hp] at hj; exact False.elim hj + | some p => + rw [hp] at hg hj + cases hy : (h k).1.2 with + | inr u => rw [hy] at hg; exact False.elim hg + | inl y => + rw [hy] at hg + have hi : stateSide y.1=.even := hg.2.1.symm.trans hj.1 + have hy2 := hsupport j y hy hi + have hn : (j.1+1:ℕ) ≤ N := by have := j.isLt; omega + have hnr : ((j.1+1:ℕ):ℝ) ≤ N := by exact_mod_cast hn + have harg : 4*((((j.1+1:ℕ):ℝ))+1)*mesh ≤ 4*((N:ℝ)+1)*mesh := by nlinarith + have hnear := good_prime_near_thick (by linarith : 0 ≤ ell) hr hs hc (j.1+1) p y hg hy2 hmesh hd0 hd1 + ((Real.exp_le_exp.mpr harg).trans hexp) hj + have herr : 3*mesh+3*(Real.exp (4*((((j.1+1:ℕ):ℝ))+1)*mesh)-1) ≤ thresholdPerturbation mesh N := by + unfold thresholdPerturbation + linarith [Real.exp_le_exp.mpr harg] + refine ⟨j,?_⟩ + change liveMember _ ((h k).1.2) + rw [hy] + exact thickArrival_mono herr hnear + +theorem source_threshold_probability (hc : Consistent start) + {mesh d : ℝ} (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) + (N : ℕ) (hexp : Real.exp (4*((N:ℝ)+1)*mesh) ≤ 4/3) : + sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N {h | primeThresholdOccurs d N h} ≤ + FlaggedSourceStart.sourceLaw hw hell hS0 hS hr hs hsS mesh N failed + + ENNReal.ofReal (thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*thresholdPerturbation mesh N)) := by + let A : Set (Hist (CemeteryKernel.Space CostState) N) := + {h | completedOccurrence (thickArrival (Real.log start.gap) d (thresholdPerturbation mesh N)) N h} + have hA : MeasurableSet A := completedOccurrence_measurable (thickArrival_measurable _ _ _) N + have hsub : ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + h ∈ {h | primeThresholdOccurs d N h} → h ∈ {h | (last N h).2=true} ∪ + (mapHist (fun q => q.1.2) N) ⁻¹' A := by + filter_upwards [sourceHistory_threshold_transfer hw hell hS0 hS hr hs hsS hc hm hmesh hd0 hd1 N hexp] with h hh + intro hp + cases hf : (last N h).2 with + | false => exact Or.inr (hh hf hp) + | true => exact Or.inl hf + have hraw := canonical_thick_occurrence_bound (Real.log start.gap) hd0 (thresholdPerturbation_nonneg hm.le N) + (FlaggedSourceStart.typedState start.side start.ratio hs) N + have hrawEN : finitePathMeasure (FlaggedSourceStart.typedState start.side start.ratio hs) N + (thickOccurrence (Real.log start.gap) d (thresholdPerturbation mesh N) N) ≤ + ENNReal.ofReal (thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*thresholdPerturbation mesh N)) := by + rw [← ENNReal.ofReal_toReal (measure_ne_top _ _)] + exact ENNReal.ofReal_le_ofReal hraw + calc + _ ≤ sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N + ({h | (last N h).2=true} ∪ (mapHist (fun q => q.1.2) N) ⁻¹' A) := measure_mono_ae hsub + _ ≤ sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N {h | (last N h).2=true}+ + sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N ((mapHist (fun q => q.1.2) N) ⁻¹' A) := measure_union_le _ _ + _ ≤ _ := by + rw [sourceHistory_failure_probability hw hell hS0 hS hr hs hsS mesh N] + exact add_le_add le_rfl ((source_completed_occurrence_le hw hell hS0 hS hr hs hsS mesh N + (thickArrival_measurable _ _ _)).trans hrawEN) +end NumberTheoryLean.SourceThresholdCoupling + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceTransitionSupport.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceTransitionSupport.lean new file mode 100644 index 0000000000000000000000000000000000000000..0015f07d587ceb5e65902aaea585a8b112249bcc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SourceTransitionSupport.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalCoupledHistories + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SourceTransitionSupport +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualCoupledHistories ActualFlagInvariant PersistentFailureFlag +open ActualCouplingUpdates ActualSupportIntervals ContinuousKilledBins LowStateHorizon + + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceTransition_left (mesh : ℝ) (x : FlagState (JointState w ell S start)) : + (sourceTransition hw hell hS0 hS hr hs hsS mesh x).map (fun y => y.1.1)=chain w ell S start x.1.1 := by + calc + _ = ((sourceTransition hw hell hS0 hS hr hs hsS mesh x).map Prod.fst).map Prod.fst := + (Measure.map_map measurable_fst measurable_fst).symm + _ = _ := by + rw [sourceTransition,marked_map] + exact jointKernel_left hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh x.1.1 x.1.2 + +theorem sourceTransition_right (mesh : ℝ) (x : FlagState (JointState w ell S start)) : + (sourceTransition hw hell hS0 hS hr hs hsS mesh x).map (fun y => y.1.2)= + continuousChain (Real.log start.gap) ell S x.1.2 := by + calc + _ = ((sourceTransition hw hell hS0 hS hr hs hsS mesh x).map Prod.fst).map Prod.snd := + (Measure.map_map measurable_snd measurable_fst).symm + _ = _ := by + rw [sourceTransition,marked_map] + exact jointKernel_right hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh x.1.1 x.1.2 + +theorem sourceTransition_live_support (mesh : ℝ) (h : History w ell S start) (z : CostState) (flag : Bool) : + ∀ᵐ y ∂sourceTransition hw hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag), + primeFollows h y.1.1 ∧ liftPredicate + (fun q : CostState => minRatio (stateSide z.1) (stateRatio z.1) ≤ stateRatio q.1) y.1.2 := by + have hp : ∀ᵐ y ∂sourceTransition hw hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag),primeFollows h y.1.1 := by + have hh : ∀ᵐ y ∂(sourceTransition hw hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag)).map + (fun y => y.1.1),primeFollows h y := by + rw [sourceTransition_left hw hell hS0 hS hr hs hsS] + exact prime_follows h + exact (ae_map_iff (measurable_fst.comp measurable_fst).aemeasurable (show MeasurableSet {y | primeFollows h y} from trivial)).mp hh + have hP : MeasurableSet {q : CostState | minRatio (stateSide z.1) (stateRatio z.1) ≤ stateRatio q.1} := + measurableSet_le measurable_const (stateRatio_measurable.comp measurable_fst) + have hq : ∀ᵐ y ∂sourceTransition hw hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag), + liftPredicate (fun q : CostState => minRatio (stateSide z.1) (stateRatio z.1) ≤ stateRatio q.1) y.1.2 := by + have hh : ∀ᵐ y ∂(sourceTransition hw hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag)).map + (fun y => y.1.2),liftPredicate (fun q : CostState => minRatio (stateSide z.1) (stateRatio z.1) ≤ stateRatio q.1) y := by + rw [sourceTransition_right hw hell hS0 hS hr hs hsS] + apply complete_ae _ z hP + rw [lowKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (costKernel_lower_support z) + exact (ae_map_iff (measurable_snd.comp measurable_fst).aemeasurable (liftPredicate_measurable hP)).mp hh + exact hp.and hq +end NumberTheoryLean.SourceTransitionSupport + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/StableFiniteVariance.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/StableFiniteVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f741f8195807d0012b79a7240b3b4a9a9dd3e0f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/StableFiniteVariance.lean @@ -0,0 +1,98 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRandomVariance +open scoped BigOperators + +noncomputable def weightedMoment {α : Type*} (C : Finset α) (w f : α → ℝ) : ℝ := + ∑ x ∈ C, w x * f x + +noncomputable def indicatorSum {ι α : Type*} (J : Finset ι) (I : ι → α → ℝ) (x : α) : ℝ := + ∑ j ∈ J, I j x + +theorem moment_sum {ι α : Type*} (C : Finset α) (w : α → ℝ) + (J : Finset ι) (f : ι → α → ℝ) : + weightedMoment C w (fun x => ∑ j ∈ J, f j x) = ∑ j ∈ J, weightedMoment C w (f j) := by + unfold weightedMoment + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + +theorem moment_indicator_square {ι α : Type*} (C : Finset α) (w : α → ℝ) + (J : Finset ι) (I : ι → α → ℝ) : + weightedMoment C w (fun x => (indicatorSum J I x)^2) = + ∑ i ∈ J, ∑ j ∈ J, weightedMoment C w (fun x => I i x * I j x) := by + have he (x : α) : (indicatorSum J I x)^2 = ∑ i ∈ J, ∑ j ∈ J, I i x * I j x := by + rw [indicatorSum, pow_two, Finset.sum_mul_sum] + simp only [he, moment_sum] + +theorem centered_moment_identity {α : Type*} (C : Finset α) (w f : α → ℝ) (M : ℝ) : + weightedMoment C w (fun x => (f x-M)^2) = + weightedMoment C w (fun x => (f x)^2) - 2*M*weightedMoment C w f + + M^2*(∑ x ∈ C, w x) := by + unfold weightedMoment + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro x _ + ring + +theorem stable_finite_variance {ι α : Type*} (C : Finset α) (w : α → ℝ) + (J : Finset ι) (I : ι → α → ℝ) (K : ι → ι → ℝ) (V zeta : ℝ) + (hV : 0 ≤ V) (hzeta : 0 ≤ zeta) + (hI : ∀ j ∈ J, ∀ x ∈ C, I j x = 0 ∨ I j x = 1) + (hMass : (∑ x ∈ C, w x) ≤ 1+zeta) + (hLower : ∀ j ∈ J, (1-zeta)*V ≤ weightedMoment C w (I j)) + (hUpper : ∀ j ∈ J, weightedMoment C w (I j) ≤ (1+zeta)*V) + (hPair : ∀ i ∈ J, ∀ j ∈ J, i ≠ j → + weightedMoment C w (fun x => I i x*I j x) ≤ (1+zeta)*K i j) + (hDiag : ∀ j ∈ J, K j j = V) + (hModel : (∑ i ∈ J, ∑ j ∈ J, K i j) ≤ ((J.card : ℝ)*V)^2+(J.card : ℝ)*V) : + weightedMoment C w (fun x => (indicatorSum J I x-(J.card : ℝ)*V)^2) ≤ + (1+zeta)*((J.card : ℝ)*V)+4*zeta*((J.card : ℝ)*V)^2 := by + classical + let M := (J.card : ℝ)*V + have hM : 0 ≤ M := mul_nonneg (Nat.cast_nonneg _) hV + have hMean : (1-zeta)*M ≤ weightedMoment C w (indicatorSum J I) := by + change (1-zeta)*M ≤ weightedMoment C w (fun x => ∑ j ∈ J, I j x) + rw [moment_sum] + have h := Finset.sum_le_sum (fun j hj => hLower j hj) + simp only [Finset.sum_const, nsmul_eq_mul] at h + dsimp only [M] + nlinarith [h] + have hAll : ∀ i ∈ J, ∀ j ∈ J, + weightedMoment C w (fun x => I i x*I j x) ≤ (1+zeta)*K i j := by + intro i hi j hj + by_cases hij : i = j + · subst j + have he : weightedMoment C w (fun x => I i x*I i x) = weightedMoment C w (I i) := by + unfold weightedMoment + apply Finset.sum_congr rfl + intro x hx + rcases hI i hi x hx with h | h <;> simp [h] + rw [he, hDiag i hi] + exact hUpper i hi + · exact hPair i hi j hj hij + have hSecond : weightedMoment C w (fun x => (indicatorSum J I x)^2) ≤ (1+zeta)*(M^2+M) := by + rw [moment_indicator_square] + calc + _ ≤ ∑ i ∈ J, ∑ j ∈ J, (1+zeta)*K i j := + Finset.sum_le_sum (fun i hi => Finset.sum_le_sum (fun j hj => hAll i hi j hj)) + _ = (1+zeta)*(∑ i ∈ J, ∑ j ∈ J, K i j) := by simp only [Finset.mul_sum] + _ ≤ _ := mul_le_mul_of_nonneg_left hModel (by linarith) + have hMeanScaled := mul_le_mul_of_nonneg_left hMean (show 0 ≤ 2*M by positivity) + have hMassScaled := mul_le_mul_of_nonneg_left hMass (sq_nonneg M) + change weightedMoment C w (fun x => (indicatorSum J I x-M)^2) ≤ (1+zeta)*M+4*zeta*M^2 + rw [centered_moment_identity] + nlinarith [hSecond, hMeanScaled, hMassScaled] + +end ErdosRandomVariance + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/StableModelMoments.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/StableModelMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..4bc421404de4a9700289a0aa40fcab41e8453113 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/StableModelMoments.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UniformJointModel + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceUniformMoments +open NumberTheoryLean ErdosVarianceMoments ErdosVarianceSmallModel ErdosRandomVariance ErdosInverseEuler +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem variancePrimes_eq_cutoff (w : ℝ) : + variancePrimes w = LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ := + (cutoffPrimes_eq_filtered_Ioc _).symm + +theorem model_moment_bounds (R xi w : ℝ) (H qA : ℕ) (C0 : ℤ) + (beta delta : ∀ t : ℕ,ZMod t) (zeta : ℝ) + (hrel : ∀ S : Finset ℕ,S.card ≤ 2 → + |modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S)- + jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S| ≤ + zeta*jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S) : + (∑ _v ∈ modelUniverse R xi w H C0,atomWeight R xi w H C0) ≤ 1+zeta ∧ + (∀ j : ℕ,(1-zeta)*sieveProduct (variancePrimes w) ≤ + weightedMoment (modelUniverse R xi w H C0) (fun _ => atomWeight R xi w H C0) + (modelIndicator w H C0 qA beta delta j)) ∧ + (∀ j : ℕ,weightedMoment (modelUniverse R xi w H C0) (fun _ => atomWeight R xi w H C0) + (modelIndicator w H C0 qA beta delta j) ≤ (1+zeta)*sieveProduct (variancePrimes w)) ∧ + (∀ i j : ℕ,weightedMoment (modelUniverse R xi w H C0) (fun _ => atomWeight R xi w H C0) + (fun v => modelIndicator w H C0 qA beta delta i v*modelIndicator w H C0 qA beta delta j v) ≤ + (1+zeta)*pairKernel (variancePrimes w) i j) := by + have hmass := hrel ∅ (by simp) + have he : jointCondition w H C0 qA beta delta ∅ = (fun _ => True) := by + funext v + exact propext (by simp [jointCondition]) + rw [he] at hmass + have hkempty : jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) ∅ = 1 := by + simp [jointDensity,positionDensity,positionResidues] + simp only [hkempty,mul_one,modelMass,Finset.filter_true] at hmass + have hsingle (j : ℕ) := hrel {j} (by simp) + have hsingle' (j : ℕ) : + |weightedMoment (modelUniverse R xi w H C0) (fun _ => atomWeight R xi w H C0) + (modelIndicator w H C0 qA beta delta j)-sieveProduct (variancePrimes w)| ≤ + zeta*sieveProduct (variancePrimes w) := by + simpa only [weighted_single_eq_mass,variancePrimes_eq_cutoff,jointDensity_singleton] using hsingle j + refine ⟨by linarith [(abs_le.mp hmass).2],?_,?_,?_⟩ + · intro j + nlinarith [(abs_le.mp (hsingle' j)).1] + · intro j + nlinarith [(abs_le.mp (hsingle' j)).2] + · intro i j + have hcard : ({i,j} : Finset ℕ).card ≤ 2 := by + calc + _ ≤ ({j} : Finset ℕ).card+1 := Finset.card_insert_le i _ + _ = 2 := by simp + have hh := hrel {i,j} hcard + rw [jointDensity_pair,← weighted_pair_eq_mass] at hh + rw [variancePrimes_eq_cutoff] + nlinarith [(abs_le.mp hh).2] + +end ErdosVarianceUniformMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/StableSourceVariance.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/StableSourceVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..d1f95b40e8bf3f2a8aa08a0807252ff42ecc8828 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/StableSourceVariance.lean @@ -0,0 +1,124 @@ +import PrimeNumberTheoremAnd.Erdos970.MertensClassical +import OAI.NumberTheory.Jacobsthal.Analysis.PairDensityExpansion +import OAI.NumberTheory.Jacobsthal.Primes.WeightedChebyshev + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosRandomVariance + +noncomputable def variancePrimes (w : ℝ) : Finset ℕ := (Finset.Ioc 0 ⌊w⌋₊).filter Nat.Prime + +theorem variancePrimes_prime (w : ℝ) (p : ℕ) (hp : p ∈ variancePrimes w) : p.Prime := + (Finset.mem_filter.mp hp).2 + +theorem sieveProduct_pos (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) : 0 < sieveProduct P := by + apply Finset.prod_pos + intro p hp + have h := hP p hp + apply sub_pos.mpr + exact (div_lt_one (show (0 : ℝ) < p by exact_mod_cast h.pos)).mpr + (by exact_mod_cast h.one_lt) + +theorem variance_product_limit : + Tendsto (fun w : ℝ => Real.log w*sieveProduct (variancePrimes w)) atTop + (𝓝 (Real.exp (-Real.eulerMascheroniConstant))) := by + have he3 : Tendsto _root_.Erdos970.Mertens.E₃ atTop (𝓝 (0 : ℝ)) := + (Asymptotics.isLittleO_one_iff ℝ).mp _root_.Erdos970.Mertens.E₃.bound' + have h := he3.rexp.const_mul (Real.exp (-Real.eulerMascheroniConstant)) + simp only [Real.exp_zero,mul_one] at h + apply h.congr' + filter_upwards [eventually_gt_atTop (1 : ℝ)] with w hw + rw [sieveProduct,variancePrimes,_root_.Erdos970.Mertens.prod_one_minus_div_prime_eq hw] + field_simp [ne_of_gt (Real.log_pos hw)] + +theorem source_mean_large (delta K : ℝ) (hdelta : 0 < delta) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop, 1 < w ∧ ∀ J : ℕ, w^delta ≤ (J : ℝ) → + K ≤ (J : ℝ)*sieveProduct (variancePrimes w) := by + let c := Real.exp (-Real.eulerMascheroniConstant)/2 + have hc : 0 < c := by dsimp [c]; positivity + have hlt : c < Real.exp (-Real.eulerMascheroniConstant) := by + dsimp [c]; nlinarith [Real.exp_pos (-Real.eulerMascheroniConstant)] + have hlow := variance_product_limit.eventually (lt_mem_nhds hlt) + have hsmall := (isLittleO_log_rpow_rpow_atTop (1 : ℝ) hdelta).bound (div_pos hc hK) + filter_upwards [hlow,hsmall,eventually_gt_atTop (1 : ℝ)] with w hwc hlog hw + refine ⟨hw,?_⟩ + intro J hJ + have hw0 : 0 < w := by linarith + have hL : 0 < Real.log w := Real.log_pos hw + have hlog' : Real.log w ≤ (c/K)*w^delta := by + simpa only [Real.rpow_one,Real.norm_eq_abs,abs_of_pos hL, + abs_of_nonneg (Real.rpow_nonneg hw0.le delta)] using hlog + have hV : 0 < sieveProduct (variancePrimes w) := sieveProduct_pos _ (variancePrimes_prime w) + have hm := mul_le_mul_of_nonneg_right hlog' hV.le + have hbase : c/(c/K) ≤ w^delta*sieveProduct (variancePrimes w) := by + apply (div_le_iff₀ (div_pos hc hK)).mpr + nlinarith [hwc,hm] + have he : c/(c/K)=K := by field_simp [hc.ne',hK.ne'] + rw [he] at hbase + exact hbase.trans (mul_le_mul_of_nonneg_right hJ hV.le) + +end ErdosRandomVariance + +end + + +open _root_.Filter +namespace ErdosRandomVariance + +universe u + +theorem stable_prime_variance {α : Type*} (C : Finset α) (w : α → ℝ) + (J : ℕ) (I : ℕ → α → ℝ) (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) + (zeta : ℝ) (hzeta : 0 ≤ zeta) + (hI : ∀ j ∈ Finset.range J, ∀ x ∈ C, I j x = 0 ∨ I j x = 1) + (hMass : (∑ x ∈ C, w x) ≤ 1+zeta) + (hLower : ∀ j ∈ Finset.range J, (1-zeta)*sieveProduct P ≤ weightedMoment C w (I j)) + (hUpper : ∀ j ∈ Finset.range J, weightedMoment C w (I j) ≤ (1+zeta)*sieveProduct P) + (hPair : ∀ i ∈ Finset.range J, ∀ j ∈ Finset.range J, i ≠ j → + weightedMoment C w (fun x => I i x*I j x) ≤ (1+zeta)*pairKernel P i j) : + weightedMoment C w (fun x => (indicatorSum (Finset.range J) I x-(J : ℝ)*sieveProduct P)^2) ≤ + (1+zeta)*((J : ℝ)*sieveProduct P)+4*zeta*((J : ℝ)*sieveProduct P)^2 := by + simpa only [Finset.card_range] using stable_finite_variance C w (Finset.range J) I + (pairKernel P) (sieveProduct P) zeta (sieveProduct_pos P hP).le hzeta hI hMass hLower hUpper + hPair (fun j _ => pairKernel_diagonal P j) + (by simpa only [Finset.card_range] using pairKernel_interval_sum P hP J) + +theorem stable_source_variance (delta eps : ℝ) (hdelta : 0 < delta) (heps : 0 < eps) : + ∀ᶠ W : ℝ in atTop, 1 < W ∧ ∀ (J : ℕ), W^delta ≤ (J : ℝ) → + ∀ (α : Type u) (C : Finset α) (w : α → ℝ) (I : ℕ → α → ℝ) (zeta : ℝ), + 0 ≤ zeta → zeta ≤ 1 → + (∀ j ∈ Finset.range J, ∀ x ∈ C, I j x = 0 ∨ I j x = 1) → + (∑ x ∈ C, w x) ≤ 1+zeta → + (∀ j ∈ Finset.range J, (1-zeta)*sieveProduct (variancePrimes W) ≤ weightedMoment C w (I j)) → + (∀ j ∈ Finset.range J, weightedMoment C w (I j) ≤ (1+zeta)*sieveProduct (variancePrimes W)) → + (∀ i ∈ Finset.range J, ∀ j ∈ Finset.range J, i ≠ j → + weightedMoment C w (fun x => I i x*I j x) ≤ (1+zeta)*pairKernel (variancePrimes W) i j) → + weightedMoment C w + (fun x => (indicatorSum (Finset.range J) I x-(J : ℝ)*sieveProduct (variancePrimes W))^2) ≤ + (eps+4*zeta)*((J : ℝ)*sieveProduct (variancePrimes W))^2 := by + filter_upwards [source_mean_large delta (2/eps) hdelta (div_pos (by norm_num) heps)] with W hW + refine ⟨hW.1,?_⟩ + intro J hJ α C w I zeta hzeta hzeta1 hI hMass hLower hUpper hPair + let M := (J : ℝ)*sieveProduct (variancePrimes W) + have hM : 2/eps ≤ M := hW.2 J hJ + have hM0 : 0 ≤ M := mul_nonneg (Nat.cast_nonneg _) (sieveProduct_pos _ (variancePrimes_prime W)).le + have h2 : 2 ≤ eps*M := by nlinarith [(div_le_iff₀ heps).mp hM] + have hmain := stable_prime_variance C w J I (variancePrimes W) (variancePrimes_prime W) + zeta hzeta hI hMass hLower hUpper hPair + change weightedMoment C w (fun x => (indicatorSum (Finset.range J) I x-M)^2) ≤ (eps+4*zeta)*M^2 + change weightedMoment C w (fun x => (indicatorSum (Finset.range J) I x-M)^2) ≤ (1+zeta)*M+4*zeta*M^2 at hmain + nlinarith [mul_le_mul_of_nonneg_right h2 hM0,mul_le_mul_of_nonneg_right hzeta1 hM0] + +end ErdosRandomVariance + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/StandardDeficitMoments.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/StandardDeficitMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..9e18b0608ad165b857b4cc0664a693ffa2aa0070 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/StandardDeficitMoments.lean @@ -0,0 +1,94 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.DickmanMoments + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory +namespace Erdos970Dependency.StandardBoundary +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.BuchstabBridge +open NumberTheoryLean.NormalizedDeficits NumberTheoryLean.DeficitFutureIntegrals +open NumberTheoryLean.Dickman + +theorem lower_deficit_total : + IntegrableOn lowerDeficit (Ioi 0) ∧ (∫ t in Ioi 0,lowerDeficit t)=sieveA-1 := by + have h := upper_future_integral (s := 1) le_rfl + norm_num only [sub_self,one_mul] at h + refine ⟨h.1,?_⟩ + rw [← h.2] + simp only [upperDeficit,F_initial sieveA (by norm_num : (0:ℝ)<1) (by norm_num : (1:ℝ)≤3),div_one] + +theorem lower_deficit_shift_tail : + IntegrableOn (fun y : ℝ => lowerDeficit (y+1)) (Ioi 1) ∧ + (∫ y in Ioi 1,lowerDeficit (y+1))=sieveA-3 := by + have ht := lower_deficit_total.1.mono_set (Ioi_subset_Ioi (by norm_num : (0:ℝ)≤2)) + have hs := halfline_shift 1 1 lowerDeficit + norm_num only [one_add_one_eq_two] at hs + refine ⟨hs.2.mp ht,?_⟩ + rw [← hs.1] + have hu : (∫ t : ℝ in 0..2,lowerDeficit t)=2 := by + calc + _ = ∫ _t : ℝ in 0..2,(1:ℝ) := by + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le (by norm_num : (0:ℝ)≤2)] at ht + simp only [lowerDeficit,f_initial sieveA ht.2,sub_zero] + _ = _ := by norm_num + have hsplit := intervalIntegral.integral_Ioi_sub_Ioi lower_deficit_total.1 (by norm_num : (0:ℝ)≤2) + rw [hu,lower_deficit_total.2] at hsplit + linarith + +theorem shifted_deficit_moments_integrable : + IntegrableOn (fun y : ℝ => y^2*lowerDeficit (y+1)) (Ioi 0) ∧ + IntegrableOn (fun y : ℝ => y^2*upperDeficit (y+1)) (Ioi 0) := by + have bound (b : ℝ → ℝ) (hb : ∀ y, 0 < y → 0 ≤ b (y+1) ∧ b (y+1) ≤ sieveA*rho y/(y+1)) + (hc : ContinuousOn (fun y : ℝ => b (y+1)) (Ioi 0)) : + IntegrableOn (fun y : ℝ => y^2*b (y+1)) (Ioi 0) := by + apply (rho_quadratic_quotient.1.const_mul sieveA).mono' + (((continuous_id.pow 2).continuousOn.mul hc).aestronglyMeasurable measurableSet_Ioi) + filter_upwards [ae_restrict_mem measurableSet_Ioi] with y hy + have hy0 : 0 < y := hy + change ‖y^2*b (y+1)‖ ≤ sieveA*(y^2*rho y/(y+1)) + rw [Real.norm_eq_abs,abs_of_nonneg (mul_nonneg (sq_nonneg y) (hb y hy0).1)] + calc + _ ≤ y^2*(sieveA*rho y/(y+1)) := mul_le_mul_of_nonneg_left (hb y hy0).2 (sq_nonneg y) + _ = _ := by ring + have hbound (y : ℝ) (hy : 0 < y) : + (0 ≤ lowerDeficit (y+1) ∧ lowerDeficit (y+1) ≤ sieveA*rho y/(y+1)) ∧ + (0 ≤ upperDeficit (y+1) ∧ upperDeficit (y+1) ≤ sieveA*rho y/(y+1)) := by + have hy1 : 1 ≤ y+1 := by linarith + have hp := deficits_pos hy1 + have he := deficit_sum (y+1) + rw [gap_eq_rho hy1,add_sub_cancel_right] at he + exact ⟨⟨hp.1.le,by linarith⟩,⟨hp.2.le,by linarith⟩⟩ + constructor + · exact bound lowerDeficit (fun y hy => (hbound y hy).1) + (lowerDeficit_continuous.comp (continuous_id.add continuous_const)).continuousOn + · apply bound upperDeficit (fun y hy => (hbound y hy).2) + apply upperDeficit_continuousOn.comp (continuous_id.add continuous_const).continuousOn + intro y hy + change 1 ≤ y+1 + change 0 < y at hy + linarith + +theorem shifted_deficit_moment_sum : + (∫ y in Ioi 0,y^2*lowerDeficit (y+1))+ + (∫ y in Ioi 0,y^2*upperDeficit (y+1))=sieveA := by + rw [← integral_add shifted_deficit_moments_integrable.1 shifted_deficit_moments_integrable.2] + have heq : EqOn (fun y : ℝ => y^2*lowerDeficit (y+1)+y^2*upperDeficit (y+1)) + (fun y => sieveA*(y^2*rho y/(y+1))) (Ioi 0) := by + intro y hy + dsimp only + rw [← mul_add,deficit_sum,gap_eq_rho (by change 0 < y at hy; linarith : 1 ≤ y+1),add_sub_cancel_right] + ring + rw [setIntegral_congr_fun measurableSet_Ioi heq,integral_const_mul,rho_quadratic_quotient.2,mul_one] + +end Erdos970Dependency.StandardBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/StateKernelInvariance.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/StateKernelInvariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..d54b510343596a7404851cb0385ad9e1498f915e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/StateKernelInvariance.lean @@ -0,0 +1,176 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.DensityConservation + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.OrdinaryKernelInvariance +open NumberTheoryLean NumberTheoryLean.DerivativeWeights NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels NumberTheoryLean.KernelDensityBridge +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantFiniteness +open Erdos970Dependency.IncomingDensityIdentities Erdos970Dependency.DensityConservation + +noncomputable def evenLift (s : ℝ) : EvenState := ⟨max (198 / 100) s, le_max_left _ _⟩ +noncomputable def oddLift (s : ℝ) : OddState := ⟨max (95 / 100) s, le_max_left _ _⟩ + +theorem evenLift_measurable : Measurable evenLift := + (measurable_const.max measurable_id).subtype_mk + +theorem oddLift_measurable : Measurable oddLift := + (measurable_const.max measurable_id).subtype_mk + +noncomputable def evenRealKernel : Kernel ℝ ℝ := evenKernel.comap evenLift evenLift_measurable +noncomputable def oddRealKernel : Kernel ℝ ℝ := oddKernel.comap oddLift oddLift_measurable + +instance evenRealKernel_isMarkovKernel : IsMarkovKernel evenRealKernel := by unfold evenRealKernel; infer_instance +instance oddRealKernel_isMarkovKernel : IsMarkovKernel oddRealKernel := by unfold oddRealKernel; infer_instance + +theorem even_lifted_product (s t : ℝ) : + InvariantDensities.evenDensity s * transitionDensity .even (evenLift s).1 t = incomingEven t s := by + by_cases hs : 2 ≤ s + · have heq : (evenLift s).1 = s := max_eq_right (by linarith) + rw [heq] + rfl + · rw [incomingEven, InvariantDensities.evenDensity, + indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs), zero_mul, zero_mul] + +theorem odd_lifted_product (s t : ℝ) : + InvariantDensities.oddDensity s * transitionDensity .odd (oddLift s).1 t = incomingOdd t s := by + by_cases hs : 1 ≤ s + · have heq : (oddLift s).1 = s := max_eq_right (by linarith) + rw [heq] + rfl + · rw [incomingOdd, InvariantDensities.oddDensity, + indicator_of_notMem (show s ∉ Ici (1 : ℝ) from hs), zero_mul, zero_mul] + +theorem even_ratio_invariance : evenRealKernel ∘ₘ evenMeasure = oddMeasure := by + apply kernel_density_conservation evenRealKernel InvariantDensities.evenDensity + InvariantDensities.oddDensity (fun s t ↦ transitionDensity .even (evenLift s).1 t) + InvariantDensities.evenDensity_measurable InvariantDensities.evenDensity_nonneg + · exact (InvariantDensities.evenDensity_measurable.comp measurable_fst).mul + ((transitionDensity_joint_measurable .even).comp + (((measurable_subtype_coe.comp evenLift_measurable).comp measurable_fst).prodMk measurable_snd)) + · intro s B _ + exact evenKernel_apply (evenLift s) B + · intro t + rw [show (fun s ↦ InvariantDensities.evenDensity s * transitionDensity .even (evenLift s).1 t) = + incomingEven t from funext (fun s ↦ even_lifted_product s t)] + exact incomingEven_integrable t + · intro s t + exact mul_nonneg (InvariantDensities.evenDensity_nonneg s) + (TransitionKernels.evenDensity_nonneg (evenLift s) t) + · intro t + simp_rw [even_lifted_product] + exact incomingEven_integral t + +theorem odd_ratio_invariance : oddRealKernel ∘ₘ oddMeasure = evenMeasure := by + apply kernel_density_conservation oddRealKernel InvariantDensities.oddDensity + InvariantDensities.evenDensity (fun s t ↦ transitionDensity .odd (oddLift s).1 t) + InvariantDensities.oddDensity_measurable InvariantDensities.oddDensity_nonneg + · exact (InvariantDensities.oddDensity_measurable.comp measurable_fst).mul + ((transitionDensity_joint_measurable .odd).comp + (((measurable_subtype_coe.comp oddLift_measurable).comp measurable_fst).prodMk measurable_snd)) + · intro s B _ + exact oddKernel_apply (oddLift s) B + · intro t + rw [show (fun s ↦ InvariantDensities.oddDensity s * transitionDensity .odd (oddLift s).1 t) = + incomingOdd t from funext (fun s ↦ odd_lifted_product s t)] + exact incomingOdd_integrable t + · intro s t + exact mul_nonneg (InvariantDensities.oddDensity_nonneg s) + (TransitionKernels.oddDensity_nonneg (oddLift s) t) + · intro t + simp_rw [odd_lifted_product] + exact incomingOdd_integral t + +end Erdos970Dependency.OrdinaryKernelInvariance + +end + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.StateKernelInvariance +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathMeasures NumberTheoryLean.KernelDensityBridge +open Erdos970Dependency.InvariantFiniteness Erdos970Dependency.OrdinaryKernelInvariance + +theorem comp_map_input {α β γ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] + (K : Kernel β γ) (mu : Measure α) (f : α → β) (hf : Measurable f) : + K ∘ₘ mu.map f = K.comap f hf ∘ₘ mu := by + ext B hB + rw [Measure.bind_apply hB K.aemeasurable, lintegral_map (K.measurable_coe hB) hf, + Measure.bind_apply hB (K.comap f hf).aemeasurable] + rfl + +theorem oddLift_ratio (s : OddState) : oddLift s.1 = s := by + apply Subtype.ext + exact max_eq_right s.2 + +theorem evenLift_ratio (s : EvenState) : evenLift s.1 = s := by + apply Subtype.ext + exact max_eq_right s.2 + +theorem evenKernel_map_lift (s : EvenState) : (evenKernel s).map oddLift = evenToOdd s := by + rw [← evenToOdd_map_ratio s, Measure.map_map oddLift_measurable measurable_subtype_coe] + rw [show oddLift ∘ (Subtype.val : OddState → ℝ) = id from funext oddLift_ratio, Measure.map_id] + +theorem oddKernel_map_lift (s : OddState) : (oddKernel s).map evenLift = oddToEven s := by + rw [← oddToEven_map_ratio s, Measure.map_map evenLift_measurable measurable_subtype_coe] + rw [show evenLift ∘ (Subtype.val : EvenState → ℝ) = id from funext evenLift_ratio, Measure.map_id] + +noncomputable def evenStateMeasure : Measure EvenState := evenMeasure.map evenLift +noncomputable def oddStateMeasure : Measure OddState := oddMeasure.map oddLift + +instance evenStateMeasure_isFiniteMeasure : IsFiniteMeasure evenStateMeasure := by unfold evenStateMeasure; infer_instance +instance oddStateMeasure_isFiniteMeasure : IsFiniteMeasure oddStateMeasure := by unfold oddStateMeasure; infer_instance + +theorem even_state_invariance : evenToOdd ∘ₘ evenStateMeasure = oddStateMeasure := by + have h := congrArg (fun mu : Measure ℝ ↦ mu.map oddLift) even_ratio_invariance + rw [Measure.map_comp _ _ oddLift_measurable] at h + have hK : evenRealKernel.map oddLift = evenToOdd.comap evenLift evenLift_measurable := by + ext s B hB + rw [Kernel.map_apply _ oddLift_measurable] + change (evenKernel (evenLift s)).map oddLift B = evenToOdd (evenLift s) B + rw [evenKernel_map_lift] + rw [hK, ← comp_map_input] at h + exact h + +theorem odd_state_invariance : oddToEven ∘ₘ oddStateMeasure = evenStateMeasure := by + have h := congrArg (fun mu : Measure ℝ ↦ mu.map evenLift) odd_ratio_invariance + rw [Measure.map_comp _ _ evenLift_measurable] at h + have hK : oddRealKernel.map evenLift = oddToEven.comap oddLift oddLift_measurable := by + ext s B hB + rw [Kernel.map_apply _ evenLift_measurable] + change (oddKernel (oddLift s)).map evenLift B = oddToEven (oddLift s) B + rw [oddKernel_map_lift] + rw [hK, ← comp_map_input] at h + exact h + +noncomputable def stateMeasure : Measure State := + evenStateMeasure.map Sum.inl + oddStateMeasure.map Sum.inr + +instance stateMeasure_isFiniteMeasure : IsFiniteMeasure stateMeasure := by unfold stateMeasure; infer_instance + +theorem state_invariance : stateKernel ∘ₘ stateMeasure = stateMeasure := by + have he : stateKernel ∘ₘ evenStateMeasure.map Sum.inl = oddStateMeasure.map Sum.inr := by + rw [comp_map_input _ _ _ measurable_inl] + change evenBranch ∘ₘ evenStateMeasure = _ + rw [evenBranch, ← Measure.map_comp _ _ measurable_inr, even_state_invariance] + have ho : stateKernel ∘ₘ oddStateMeasure.map Sum.inr = evenStateMeasure.map Sum.inl := by + rw [comp_map_input _ _ _ measurable_inr] + change oddBranch ∘ₘ oddStateMeasure = _ + rw [oddBranch, ← Measure.map_comp _ _ measurable_inl, odd_state_invariance] + rw [stateMeasure, Measure.comp_add, he, ho, add_comm] + +end Erdos970Dependency.StateKernelInvariance + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SubMarkovFlagPowers.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SubMarkovFlagPowers.lean new file mode 100644 index 0000000000000000000000000000000000000000..a48e1903deb36214081be0720ee9dcdfb7828f76 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SubMarkovFlagPowers.lean @@ -0,0 +1,121 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.FlaggedOccupationBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SubMarkovFlagPowers + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open PersistentFailureFlag FlaggedOccupationBound ActualCouplingFinite + +variable {α : Type*} [MeasurableSpace α] + +instance marked_sfinite (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) : IsSFiniteKernel (marked K hBad) := by + unfold marked + infer_instance + +theorem marked_eq_map_sfinite (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (z : FlagState α) : + marked K hBad z = (K z.1).map (fun y => (y,z.2 || badBit Bad y)) := by + apply Measure.ext_of_lintegral + intro F hF + rw [marked,Kernel.map_apply _ (update_measurable hBad),lintegral_map hF (update_measurable hBad)] + calc + _ = ∫⁻ y,F (y,z.2 || badBit Bad y) ∂K z.1 := + Kernel.lintegral_id_prod (f:=fun p : FlagState α × α => F (update Bad p)) + (hF.comp (update_measurable hBad)) _ z + _ = _ := (lintegral_map hF (row_update_measurable hBad z.2)).symm + +theorem marked_map_sfinite (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (z : FlagState α) : + (marked K hBad z).map Prod.fst = K z.1 := by + rw [marked_eq_map_sfinite K hBad z,Measure.map_map (f:=fun y => (y,z.2 || badBit Bad y)) + (g:=Prod.fst) measurable_fst (row_update_measurable hBad z.2)] + exact Measure.map_id + +noncomputable def goodSelect (F : α → ℝ≥0∞) : FlagState α → ℝ≥0∞ := failedᶜ.indicator (fun z => F z.1) + +theorem goodSelect_measurable {F : α → ℝ≥0∞} (hF : Measurable F) : Measurable (goodSelect F) := + (hF.comp measurable_fst).indicator failed_measurable.compl + +noncomputable def goodKernel (K : Kernel α α) {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) : Kernel α α := K.restrict hBad.compl + +instance goodKernel_sfinite (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) : IsSFiniteKernel (goodKernel K hBad) := by + unfold goodKernel + infer_instance + +theorem good_row_lift (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) {F : α → ℝ≥0∞} (hF : Measurable F) (q : FlagState α) : + (∫⁻ y,goodSelect F y ∂marked K hBad q) = + goodSelect (fun x => ∫⁻ y,F y ∂goodKernel K hBad x) q := by + classical + rw [marked_eq_map_sfinite K hBad q,lintegral_map (goodSelect_measurable hF) (row_update_measurable hBad q.2)] + rcases q with ⟨x,b⟩ + cases b with + | true => simp [goodSelect,failed] + | false => + simp only [goodSelect,failed,mem_compl_iff,mem_ofPred_eq,Bool.false_eq_true,not_false_eq_true, + indicator_of_mem,Bool.false_or] + rw [goodKernel,Kernel.restrict_apply,← lintegral_indicator hBad.compl] + apply lintegral_congr + intro y + by_cases hy : Bad y <;> simp [badBit,hy] + +theorem good_power_lift (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) {F : α → ℝ≥0∞} (hF : Measurable F) + (n : ℕ) (q : FlagState α) : + (∫⁻ y,goodSelect F y ∂((marked K hBad)^n) q) = + goodSelect (fun x => ∫⁻ y,F y ∂((goodKernel K hBad)^n) x) q := by + induction n generalizing q with + | zero => + change (∫⁻ y,goodSelect F y ∂Measure.dirac q) = _ + rw [lintegral_dirac' _ (goodSelect_measurable hF)] + have he : (fun x => ∫⁻ y,F y ∂((goodKernel K hBad)^0) x) = F := by + funext x + change (∫⁻ y,F y ∂Measure.dirac x) = F x + rw [lintegral_dirac' _ hF] + rw [he] + | succ n ih => + have hp : (marked K hBad)^(n+1) = ((marked K hBad)^n) ∘ₖ marked K hBad := pow_succ _ _ + have hg : (goodKernel K hBad)^(n+1) = ((goodKernel K hBad)^n) ∘ₖ goodKernel K hBad := pow_succ _ _ + rw [hp,Kernel.lintegral_comp _ _ _ (goodSelect_measurable hF)] + calc + _ = ∫⁻ y,goodSelect (fun x => ∫⁻ a,F a ∂((goodKernel K hBad)^n) x) y ∂marked K hBad q := lintegral_congr ih + _ = goodSelect (fun x => ∫⁻ y,∫⁻ a,F a ∂((goodKernel K hBad)^n) y ∂goodKernel K hBad x) q := + good_row_lift K hBad hF.lintegral_kernel q + _ = _ := by + have he : (fun x => ∫⁻ y,∫⁻ a,F a ∂((goodKernel K hBad)^n) y ∂goodKernel K hBad x) = + (fun x => ∫⁻ a,F a ∂((goodKernel K hBad)^(n+1)) x) := by + funext x + rw [hg,Kernel.lintegral_comp _ _ _ hF] + rw [he] + +theorem finite_integral_partition (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) {F : α → ℝ≥0∞} (hF : Measurable F) (n : ℕ) (x : α) : + (∫⁻ y,F y ∂(K^n) x) = (∫⁻ y,F y ∂((goodKernel K hBad)^n) x)+ + (∫⁻ y,selected F y ∂((marked K hBad)^n) (x,false)) := by + classical + have hmap := map_power_of_step (marked K hBad) K measurable_fst (marked_map_sfinite K hBad) n (x,false) + rw [← hmap,lintegral_map hF measurable_fst] + have he : (fun y : FlagState α => F y.1) = fun y => goodSelect F y+selected F y := by + funext y + rcases y with ⟨z,b⟩ + cases b <;> simp [goodSelect,selected,failed] + rw [he,lintegral_add_left (goodSelect_measurable hF),good_power_lift K hBad hF] + simp [goodSelect,failed] + +end NumberTheoryLean.SubMarkovFlagPowers + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/SuccessfulMarkedCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/SuccessfulMarkedCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..25c7b922a0654fc4f699c99977e3f59e02a99072 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/SuccessfulMarkedCoordinates.lean @@ -0,0 +1,127 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalCoupledHistories + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.MarkedWindowCouplingGeometry + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeBinMembership +open ActualFlagInvariant NearbyParentGeometry RegeneratingInverseBands ArrivalKernelGeometry + +theorem window_stability {b₀ b₁ rp rc sp tc x : ℝ} (hb₀ : 0 < b₀) + (ht₀ : 209/100 ≤ tc) (ht₁ : tc ≤ 213/100) + (hx₀ : 10*b₀/(313/100) ≤ x) (hx₁ : x ≤ b₁/(309/100)) + (hcurve : rc = x*tc) (hpq : rp ≤ (11/10)*rc) (hqp : rc ≤ (11/10)*rp) + (hnear : |sp-tc| ≤ 1/100) : + 208/100 ≤ sp ∧ sp ≤ 214/100 ∧ 2*b₀ ≤ rp/sp ∧ rp/sp ≤ b₁/2 ∧ 6*b₀ < rp := by + have hs₀ : 208/100 ≤ sp := by linarith [(abs_le.mp hnear).1] + have hs₁ : sp ≤ 214/100 := by linarith [(abs_le.mp hnear).2] + have hsp : 0 < sp := by linarith + have hx0 : 0 < x := (div_pos (by positivity) (by norm_num : 0 < (313/100:ℝ))).trans_le hx₀ + have hl : 10*b₀ ≤ x*(313/100) := (div_le_iff₀ (by norm_num : 0 < (313/100:ℝ))).mp hx₀ + have hu : x*(309/100) ≤ b₁ := (le_div_iff₀ (by norm_num : 0 < (309/100:ℝ))).mp hx₁ + have hb₁ : 0 < b₁ := by nlinarith + have hrc₀ : (209/100)*x ≤ rc := by nlinarith [mul_nonneg hx0.le (sub_nonneg.mpr ht₀)] + have hrc₁ : rc ≤ (213/100)*x := by nlinarith [mul_nonneg hx0.le (sub_nonneg.mpr ht₁)] + have hgap : 6*b₀ < rp := by nlinarith + refine ⟨hs₀,hs₁,?_,?_,hgap⟩ + · apply (le_div_iff₀ hsp).mpr + nlinarith [mul_nonneg hb₀.le (sub_nonneg.mpr hs₁)] + · apply (div_le_iff₀ hsp).mpr + nlinarith [mul_nonneg hb₁.le (sub_nonneg.mpr hs₀)] + +theorem actual_marked_window {w ell S v mesh b₀ b₁ : ℝ} {start : Node} + {n : ℕ} (h : History w ell S start) (z : CostState) + (hb₀ : 0 < b₀) + (hpositive : 0 < h.node.gap) (hconsistent : Consistent h.node) + (hgood : GoodAt v mesh n (some h,Sum.inl z)) + (heven : stateSide z.1 = .even) + (ht₀ : 209/100 ≤ stateRatio z.1) (ht₁ : stateRatio z.1 ≤ 213/100) + (hx₀ : 10*b₀/(313/100) ≤ currentExponent v z) + (hx₁ : currentExponent v z ≤ b₁/(309/100)) + (hmesh : mesh ≤ 1/100) (herror : 4*(n:ℝ)*mesh ≤ Real.log (11/10)) : + h.node.side = .even ∧ 208/100 ≤ h.node.ratio ∧ h.node.ratio ≤ 214/100 ∧ + 2*b₀ ≤ h.node.cutoff ∧ h.node.cutoff ≤ b₁/2 ∧ 6*b₀ < h.node.gap := by + change liveGood v mesh n h z at hgood + have hrel := log_gap_relative hpositive (Real.exp_pos _) hgood.2.2.2 + have he : Real.exp (4*(n:ℝ)*mesh) ≤ (11/10:ℝ) := by + rw [← Real.exp_log (by norm_num : 0 < (11/10:ℝ))] + exact Real.exp_le_exp.mpr herror + have hpq : h.node.gap ≤ (11/10)*gapValue v z := + hrel.1.trans (mul_le_mul_of_nonneg_right he (Real.exp_pos _).le) + have hqp : gapValue v z ≤ (11/10)*h.node.gap := + hrel.2.trans (mul_le_mul_of_nonneg_right he hpositive.le) + have hcurve : gapValue v z = currentExponent v z*stateRatio z.1 := by + unfold currentExponent + exact (div_mul_cancel₀ _ (OccupationBoundaries.stateRatio_pos z.1).ne').symm + have hg := window_stability hb₀ ht₀ ht₁ hx₀ hx₁ hcurve hpq hqp (hgood.2.2.1.trans hmesh) + refine ⟨hgood.2.1.trans heven,hg.1,hg.2.1,?_,?_,hg.2.2.2.2⟩ + · rw [hconsistent] + exact hg.2.2.1 + · rw [hconsistent] + exact hg.2.2.2.1 + +end NumberTheoryLean.MarkedWindowCouplingGeometry + +end + +section + +namespace NumberTheoryLean.SuccessfulMarkedCoordinates + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualProcessCoupling ActualFlagInvariant ActualCoupledHistories ActualSuccessfulHistories +open FiniteHistoryTransport MarkedWindowCouplingGeometry ArrivalKernelGeometry + +def primeWindow (b₀ b₁ : ℝ) (z : Node) : Prop := + z.side = .even ∧ 208/100 ≤ z.ratio ∧ z.ratio ≤ 214/100 ∧ + 2*b₀ ≤ z.cutoff ∧ z.cutoff ≤ b₁/2 ∧ 6*b₀ < z.gap + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistory_transports_marked_window (hc : Consistent start) + {mesh : ℝ} (hm : 0 < mesh) (hmesh : mesh ≤ 1/100) (N : ℕ) + (herror : 4*(N:ℝ)*mesh ≤ Real.log (11/10)) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + (last N h).2 = false → ∀ j : Finset.Iic N, ∀ z : CostState, + (h j).1.2 = Sum.inl z → ∀ b₀ b₁ : ℝ, 0 < b₀ → + stateSide z.1 = .even → 209/100 ≤ stateRatio z.1 → stateRatio z.1 ≤ 213/100 → + 10*b₀/(313/100) ≤ currentExponent (Real.log start.gap) z → + currentExponent (Real.log start.gap) z ≤ b₁/(309/100) → + ∃ p : History w ell S start, (h j).1.1 = some p ∧ primeWindow b₀ b₁ p.node := by + filter_upwards [sourceHistory_success_good hw hell hS0 hS hr hs hsS hm N] with h hh + intro hflag j z hz b₀ b₁ hb₀ heven ht₀ ht₁ hx₀ hx₁ + have hg := hh hflag j + have he : 4*(j.1:ℝ)*mesh ≤ Real.log (11/10) := by + have hj : (j.1:ℝ) ≤ N := by exact_mod_cast Finset.mem_Iic.mp j.2 + exact (by nlinarith : 4*(j.1:ℝ)*mesh ≤ 4*(N:ℝ)*mesh).trans herror + have hg' : GoodAt (Real.log start.gap) mesh j.1 ((h j).1.1,Sum.inl z) := by + simpa only [← hz] using hg + cases hp : (h j).1.1 with + | none => + rw [hp] at hg' + exact False.elim hg' + | some p => + rw [hp] at hg' + refine ⟨p,rfl,?_⟩ + exact actual_marked_window p z hb₀ + (terminal_gap_positive (by linarith : 0 ≤ ell) hr hs p.admissible) + (PrimeBinMembership.history_consistent (by linarith : 0 ≤ ell) hr hs hc p) + hg' heven ht₀ ht₁ hx₀ hx₁ hmesh he + +end NumberTheoryLean.SuccessfulMarkedCoordinates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/ThirdInnerKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/ThirdInnerKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..954379f8a49f5c1348b2f014fa0135fe75178664 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/ThirdInnerKernel.lean @@ -0,0 +1,247 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SecondLossIntegration + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosBoundaryLoss + +theorem lossTwo_measurable : Measurable (fun p : ℝ×ℝ => loss2Kernel p.2 p.1) := by + unfold loss2Kernel + fun_prop + +theorem lossTwo_bound {x t : ℝ} (hx : x ∈ Icc (1:ℝ) 2) (ht : t ∈ Icc (1:ℝ) 2) : + |loss2Kernel t x| ≤ 16 := by + have hx0 : 0 < x := by linarith [hx.1] + have ht0 : 0 < t := by linarith [ht.1] + have he : loss2Kernel t x=((x+2*t-2)^2*(x+2*t+4))/(12*x*t^2) := by + unfold loss2Kernel + field_simp + ring + have hs : 0 ≤ x+2*t-2 ∧ x+2*t-2 ≤ 4 := by constructor <;> linarith [hx.1,hx.2,ht.1,ht.2] + have hs2 : (x+2*t-2)^2 ≤ 16 := by nlinarith + have hs4 : 0 ≤ x+2*t+4 ∧ x+2*t+4 ≤ 10 := by constructor <;> linarith [hx.1,hx.2,ht.1,ht.2] + have hnum : (x+2*t-2)^2*(x+2*t+4) ≤ 160 := by + have h := mul_le_mul hs2 hs4.2 hs4.1 (by norm_num : (0:ℝ)≤16) + norm_num at h + exact h + have ht2 : 1 ≤ t^2 := by nlinarith [ht.1] + have hden : 12 ≤ 12*x*t^2 := by + have h := mul_le_mul hx.1 ht2 (by norm_num : (0:ℝ)≤1) hx0.le + nlinarith + have hden0 : 0 < 12*x*t^2 := by positivity + rw [he,abs_of_nonneg (div_nonneg (mul_nonneg (sq_nonneg _) hs4.1) hden0.le)] + apply (div_le_iff₀ hden0).mpr + nlinarith + +theorem actual_second_loss_eq_L2 : omissionLossTerm 1=L2 := by + rw [second_loss_ordered_integral] + have h := ordered_triangle_swap lossTwo_measurable (by norm_num : (0:ℝ)≤16) + (fun _ hx _ ht => lossTwo_bound hx ht) + exact h + +end ErdosOmissionBindings + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosBoundaryLoss + +theorem lossThree_bound {x u t : ℝ} (hx : x ∈ Icc (1:ℝ) 2) + (hu : u ∈ Icc (1:ℝ) 2) (ht : t ∈ Icc (1:ℝ) 2) : |loss3Kernel t u x| ≤ 64 := by + have hx0 : 0 < x := by linarith [hx.1] + have hu0 : 0 < u := by linarith [hu.1] + have ht0 : 0 < t := by linarith [ht.1] + have hs0 : 0 ≤ x+u+2*t := by positivity + have hs8 : x+u+2*t ≤ 8 := by linarith [hx.2,hu.2,ht.2] + have hsx : 2*x ≤ x+u+2*t := by linarith [hx.2,hu.1,ht.1] + have hp := pow_le_pow_left₀ (by positivity : (0:ℝ)≤2*x) hsx 3 + have hnum0 : 0 ≤ (x+u+2*t)^3-8*x^3 := by nlinarith + have hp8 := pow_le_pow_left₀ hs0 hs8 3 + have hnum : (x+u+2*t)^3-8*x^3 ≤ 512 := by nlinarith [pow_nonneg hx0.le 3] + have ht2 : 1 ≤ t^2 := by nlinarith [ht.1] + have hxu : (1:ℝ) ≤ x*u := by simpa only [one_mul] using mul_le_mul hx.1 hu.1 (by norm_num : (0:ℝ)≤1) hx0.le + have hprod : (1:ℝ) ≤ x*u*t^2 := by + simpa only [one_mul] using mul_le_mul hxu ht2 (by norm_num : (0:ℝ)≤1) (mul_pos hx0 hu0).le + have hden : 12 ≤ 12*x*u*t^2 := by nlinarith + have hden0 : 0 < 12*x*u*t^2 := by positivity + rw [loss3Kernel,abs_of_nonneg (div_nonneg hnum0 hden0.le)] + apply (div_le_iff₀ hden0).mpr + nlinarith + +noncomputable def clampedThird (x u t : ℝ) : ℝ := + loss3Kernel (baseCutoff t) (baseCutoff u) (baseCutoff x) + +theorem clampedThird_eq {x u t : ℝ} (hx : x ∈ Icc (1:ℝ) 2) + (hu : u ∈ Icc (1:ℝ) 2) (ht : t ∈ Icc (1:ℝ) 2) : + clampedThird x u t=loss3Kernel t u x := by + simp only [clampedThird,baseCutoff_on hx.1 hx.2,baseCutoff_on hu.1 hu.2,baseCutoff_on ht.1 ht.2] + +theorem clampedThird_bound (x u t : ℝ) : |clampedThird x u t| ≤ 64 := + lossThree_bound (baseCutoff_bounds x) (baseCutoff_bounds u) (baseCutoff_bounds t) + +theorem clampedThird_continuous : + Continuous (fun p : ℝ×ℝ×ℝ => clampedThird p.1 p.2.1 p.2.2) := by + have hn : Continuous (fun p : ℝ×ℝ×ℝ => + (baseCutoff p.1+baseCutoff p.2.1+2*baseCutoff p.2.2)^3-8*(baseCutoff p.1)^3) := by + unfold baseCutoff + fun_prop + have hd : Continuous (fun p : ℝ×ℝ×ℝ => + 12*baseCutoff p.1*baseCutoff p.2.1*(baseCutoff p.2.2)^2) := by + unfold baseCutoff + fun_prop + have hp (a : ℝ) : 0 < baseCutoff a := zero_lt_one.trans_le (baseCutoff_bounds a).1 + exact hn.div hd (fun p => ne_of_gt + (mul_pos (mul_pos (mul_pos (by norm_num) (hp p.1)) (hp p.2.1)) (sq_pos_of_pos (hp p.2.2)))) + +theorem baseCutoff_continuous : Continuous baseCutoff := by unfold baseCutoff; fun_prop + +end ErdosOmissionBindings + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceAdmission + +theorem odd_gate_indicator (H : Profile) (y : ℝ) : + gate H .odd (2*y+2) 2= + ∫ x : ℝ in 1..2,if x≤y then H .even (2*y+2-x) x/(max 1 x) else 0 := by + classical + have heq : Ioc (1:ℝ) (upperCutoff .odd (2*y+2) 2)=Ioc (1:ℝ) 2 ∩ Iic y := by + ext x + have hc := mem_upperCutoff .odd (2*y+2) 2 x + constructor + · intro hx + obtain ⟨hx1,hx2,_hxb,ha⟩ := hc.mp hx + rw [strong_gate_below_two hx2] at ha + refine ⟨⟨hx1,hx2⟩,?_⟩ + change x≤y + linarith + · rintro ⟨⟨hx1,hx2⟩,hxy⟩ + apply hc.mpr + refine ⟨hx1,hx2,hx2,?_⟩ + rw [strong_gate_below_two hx2] + change x≤y at hxy + linarith + rw [gate,intervalIntegral.integral_of_le (upperCutoff_bounds .odd (2*y+2) 2).1, + intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤2)] + change (∫ x in Ioc (1:ℝ) (upperCutoff .odd (2*y+2) 2),H .even (2*y+2-x) x/(max 1 x))= + ∫ x in Ioc (1:ℝ) 2,(Iic y).indicator (fun x => H .even (2*y+2-x) x/(max 1 x)) x + rw [setIntegral_indicator measurableSet_Iic,heq] + +theorem gate_force_bounds (i : Side) (r b : ℝ) : + 0 ≤ gate omissionForce i r b ∧ gate omissionForce i r b ≤ 1 := by + have hnon := gate_nonnegative omissionForce_nonnegative i r b + refine ⟨hnon,?_⟩ + have hb (x : ℝ) : |omissionForce i.flip (r-x) x/(max 1 x)| ≤ 1 := by + have hd : 0 < max (1:ℝ) x := (by norm_num : (0:ℝ)<1).trans_le (le_max_left 1 x) + rw [abs_div,abs_of_pos hd,abs_of_nonneg (omissionForce_nonnegative _ _ _)] + exact (div_le_one hd).mpr ((omissionForce_le_one _ _ _).trans (le_max_left 1 x)) + have h := intervalIntegral.norm_integral_le_of_norm_le_const (a:=1) (b:=upperCutoff i r b) + (C:=1) (f:=fun x => omissionForce i.flip (r-x) x/(max 1 x)) + (fun x _ => by simpa only [Real.norm_eq_abs] using hb x) + have hc := upperCutoff_bounds i r b + rw [Real.norm_eq_abs,one_mul,abs_of_nonneg (by linarith : 0 ≤ upperCutoff i r b-1)] at h + change |gate omissionForce i r b| ≤ upperCutoff i r b-1 at h + rw [abs_of_nonneg hnon] at h + linarith + +noncomputable def thirdKernel (p : ℝ×ℝ) : ℝ := + if p.2≤p.1 then (2*p.1^2/(max 1 p.2))*gate omissionForce .even (2*p.1+2-p.2) p.2 else 0 + +theorem thirdKernel_measurable : Measurable thirdKernel := by + have hg := gate_continuous omissionForce_continuous .even + have hc : Continuous (fun p : ℝ×ℝ => gate omissionForce .even (2*p.1+2-p.2) p.2) := + hg.comp (((continuous_const.mul continuous_fst).add continuous_const |>.sub continuous_snd).prodMk continuous_snd) + have hp : Measurable (fun p : ℝ×ℝ => 2*p.1^2/(max 1 p.2)) := by fun_prop + exact Measurable.ite (measurableSet_le measurable_snd measurable_fst) (hp.mul hc.measurable) measurable_const + +theorem thirdKernel_bound {y x : ℝ} (hy : y ∈ Icc (0:ℝ) 4) (hx : x ∈ Icc (1:ℝ) 2) : + |thirdKernel (y,x)| ≤ 32 := by + have hx0 : 0 < x := by linarith [hx.1] + unfold thirdKernel + dsimp only + split_ifs + · rw [max_eq_right hx.1] + have hp0 : 0 ≤ 2*y^2/x := by positivity + have hp32 : 2*y^2/x ≤ 32 := by + apply (div_le_iff₀ hx0).mpr + nlinarith [hy.1,hy.2,hx.1] + rw [abs_of_nonneg (mul_nonneg hp0 (gate_force_bounds _ _ _).1)] + exact (mul_le_mul_of_nonneg_left (gate_force_bounds _ _ _).2 hp0).trans (by simpa only [mul_one] using hp32) + · norm_num + +theorem third_density_kernel (y : ℝ) : + omissionDensity 2 .odd y=∫ x : ℝ in 1..2,thirdKernel (y,x) := by + change 2*y^2*gate (gate omissionForce) .odd (2*y+2) 2=_ + rw [odd_gate_indicator,← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro x _hx + dsimp only [thirdKernel] + split_ifs <;> ring + +end ErdosOmissionBindings + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry + +noncomputable def thirdInnerKernel (x : ℝ) (p : ℝ×ℝ) : ℝ := + (p.1^2/(max 1 p.2))*omissionForce .odd (2*p.1+2-x-p.2) p.2 + +theorem thirdInnerKernel_continuous (x : ℝ) : Continuous (thirdInnerKernel x) := by + have hf : Continuous (fun p : ℝ×ℝ => omissionForce .odd (2*p.1+2-x-p.2) p.2) := + (omissionForce_continuous .odd).comp + ((((continuous_const.mul continuous_fst).add continuous_const |>.sub continuous_const).sub continuous_snd).prodMk continuous_snd) + have hp : Continuous (fun p : ℝ×ℝ => p.1^2/(max 1 p.2)) := + (continuous_fst.pow 2).div (continuous_const.max continuous_snd) (fun p => ne_of_gt + ((by norm_num : (0:ℝ)<1).trans_le (le_max_left 1 p.2))) + exact hp.mul hf + +theorem thirdInnerKernel_bound {x y u : ℝ} (hx : x ∈ Icc (1:ℝ) 2) + (hy : y ∈ Icc x 4) (hu : u ∈ Icc (1:ℝ) x) : |thirdInnerKernel x (y,u)| ≤ 16 := by + have hu0 : 0 < u := by linarith [hu.1] + have hy0 : 0 ≤ y := by linarith [hx.1,hy.1] + have hp0 : 0 ≤ y^2/u := div_nonneg (sq_nonneg _) hu0.le + have hp16 : y^2/u ≤ 16 := by + apply (div_le_iff₀ hu0).mpr + nlinarith [hy.2,hu.1] + unfold thirdInnerKernel + dsimp only + rw [max_eq_right hu.1,abs_of_nonneg (mul_nonneg hp0 (omissionForce_nonnegative _ _ _))] + exact (mul_le_mul_of_nonneg_left (omissionForce_le_one _ _ _) hp0).trans (by simpa only [mul_one] using hp16) + +theorem third_even_gate (y : ℝ) {x : ℝ} (hx : x ∈ Icc (1:ℝ) 2) : + y^2*gate omissionForce .even (2*y+2-x) x= + ∫ u : ℝ in 1..x,thirdInnerKernel x (y,u) := by + have hc : upperCutoff .even (2*y+2-x) x=x := baseCutoff_on hx.1 hx.2 + rw [gate,hc,← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro u _hu + dsimp only [thirdInnerKernel,Side.flip] + ring + +end ErdosOmissionBindings + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/TransitionKernels.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/TransitionKernels.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cde8fc12dd978ff26f3218da950ed1f3a8bfaa0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/TransitionKernels.lean @@ -0,0 +1,198 @@ +import Mathlib.Probability.Kernel.WithDensity +import OAI.NumberTheory.Jacobsthal.Analysis.WeightFutureIntegrals + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.TransitionKernels + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open LinearSieveFunctions BuchstabBridge NormalizedDeficits +open DerivativeWeights WeightFutureIntegrals + +abbrev EvenState := {s : ℝ // 198 / 100 ≤ s} +abbrev OddState := {s : ℝ // 95 / 100 ≤ s} + +noncomputable def tailDensity (left mass : ℝ) (B : ℝ → ℝ) : ℝ → ℝ := + (Ici left).indicator (fun t => B t / mass) + +theorem tailDensity_nonneg {left mass : ℝ} {B : ℝ → ℝ} (hm : 0 < mass) + (hB : ∀ t, left ≤ t → 0 ≤ B t) (t : ℝ) : 0 ≤ tailDensity left mass B t := by + unfold tailDensity + by_cases ht : left ≤ t + · rw [indicator_of_mem (show t ∈ Ici left from ht)] + exact div_nonneg (hB t ht) hm.le + · rw [indicator_of_notMem (show t ∉ Ici left from ht)] + +theorem tailDensity_integrable {left mass : ℝ} {B : ℝ → ℝ} + (hB : IntegrableOn B (Ioi left)) : Integrable (tailDensity left mass B) := by + unfold tailDensity + apply (integrable_indicator_iff measurableSet_Ici).mpr + exact (Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi hB).div_const mass + +theorem tailDensity_integral {left mass : ℝ} {B : ℝ → ℝ} (hm : 0 < mass) + (hB : mass = ∫ t in Ioi left, B t) : ∫ t, tailDensity left mass B t = 1 := by + unfold tailDensity + rw [integral_indicator measurableSet_Ici, integral_div, integral_Ici_eq_integral_Ioi, ← hB] + exact div_self (ne_of_gt hm) + +theorem phiEven_measurable : Measurable phiEven := by + have hF : Measurable (F sieveA) := by + unfold F + exact (measurable_const.mul + (((plus_continuous.comp (continuous_id.sub continuous_const)).add + (Dickman.rho_continuous.comp (continuous_id.sub continuous_const))).measurable)).div + (measurable_const.mul measurable_id) + unfold phiEven + apply Measurable.ite measurableSet_Iic + · unfold evenInitial + exact measurable_const.mul ((measurable_id.div (measurable_id.sub measurable_const)).sub + (Real.measurable_log.comp (measurable_id.sub measurable_const))) + · exact measurable_id.mul (lowerDeficit_continuous.measurable.add + ((hF.sub measurable_const).comp (measurable_id.sub measurable_const))) + +theorem W_measurable : Measurable W := by + unfold W + exact (measurable_id.add measurable_const).div (measurable_id.pow_const 2) + +noncomputable def evenDensity (s : EvenState) : ℝ → ℝ := + tailDensity (s.1 - 1) (phiEven s.1) (fun t => W t * phiOdd t) + +noncomputable def oddDensity (s : OddState) : ℝ → ℝ := + tailDensity (max 2 (s.1 - 1)) (phiOdd s.1) (fun t => W t * phiEven t) + +theorem evenDensity_measurable : Measurable (Function.uncurry evenDensity) := by + change Measurable (fun x : EvenState × ℝ => + if x.1.1 - 1 ≤ x.2 then W x.2 * phiOdd x.2 / phiEven x.1.1 else 0) + apply Measurable.ite + (measurableSet_le ((measurable_subtype_coe.comp measurable_fst).sub measurable_const) measurable_snd) + · exact ((W_measurable.comp measurable_snd).mul + (phiOdd_continuous.measurable.comp measurable_snd)).div + (phiEven_measurable.comp (measurable_subtype_coe.comp measurable_fst)) + · exact measurable_const + +theorem oddDensity_measurable : Measurable (Function.uncurry oddDensity) := by + change Measurable (fun x : OddState × ℝ => + if max 2 (x.1.1 - 1) ≤ x.2 then W x.2 * phiEven x.2 / phiOdd x.1.1 else 0) + apply Measurable.ite + (measurableSet_le (measurable_const.max + ((measurable_subtype_coe.comp measurable_fst).sub measurable_const)) measurable_snd) + · exact ((W_measurable.comp measurable_snd).mul + (phiEven_measurable.comp measurable_snd)).div + (phiOdd_continuous.measurable.comp (measurable_subtype_coe.comp measurable_fst)) + · exact measurable_const + +theorem evenDensity_nonneg (s : EvenState) (t : ℝ) : 0 ≤ evenDensity s t := by + have hs : 1 < s.1 := by linarith [s.2] + apply tailDensity_nonneg (phiEven_pos hs) ?_ t + intro u hu + exact (mul_pos (W_pos (by linarith)) (phiOdd_pos u)).le + +theorem oddDensity_nonneg (s : OddState) (t : ℝ) : 0 ≤ oddDensity s t := by + apply tailDensity_nonneg (phiOdd_pos s.1) ?_ t + intro u hu + have hu1 : 1 < u := by linarith [le_max_left (2 : ℝ) (s.1 - 1)] + exact (mul_pos (W_pos (by linarith)) (phiEven_pos hu1)).le + +theorem evenDensity_integrable (s : EvenState) : Integrable (evenDensity s) := + tailDensity_integrable (phiEven_future_integral (s := s.1) (by linarith [s.2])).1 + +theorem oddDensity_integrable (s : OddState) : Integrable (oddDensity s) := + tailDensity_integrable (phiOdd_future_integral s.1).1 + +theorem evenDensity_integral (s : EvenState) : ∫ t, evenDensity s t = 1 := + tailDensity_integral (phiEven_pos (by linarith [s.2])) + (phiEven_future_integral (s := s.1) (by linarith [s.2])).2 + +theorem oddDensity_integral (s : OddState) : ∫ t, oddDensity s t = 1 := + tailDensity_integral (phiOdd_pos s.1) (phiOdd_future_integral s.1).2 + +noncomputable def evenKernel : Kernel EvenState ℝ := + (Kernel.const EvenState volume).withDensity (fun s t => ENNReal.ofReal (evenDensity s t)) + +noncomputable def oddKernel : Kernel OddState ℝ := + (Kernel.const OddState volume).withDensity (fun s t => ENNReal.ofReal (oddDensity s t)) + +theorem evenKernel_apply (s : EvenState) (B : Set ℝ) : + evenKernel s B = ∫⁻ t in B, ENNReal.ofReal (evenDensity s t) := by + exact Kernel.withDensity_apply' (Kernel.const EvenState volume) + (f := fun s t => ENNReal.ofReal (evenDensity s t)) + (ENNReal.measurable_ofReal.comp evenDensity_measurable) s B + +theorem oddKernel_apply (s : OddState) (B : Set ℝ) : + oddKernel s B = ∫⁻ t in B, ENNReal.ofReal (oddDensity s t) := by + exact Kernel.withDensity_apply' (Kernel.const OddState volume) + (f := fun s t => ENNReal.ofReal (oddDensity s t)) + (ENNReal.measurable_ofReal.comp oddDensity_measurable) s B + +instance evenKernel_isMarkovKernel : IsMarkovKernel evenKernel := by + constructor + intro s + constructor + rw [evenKernel_apply, setLIntegral_univ, + ← ofReal_integral_eq_lintegral_ofReal (evenDensity_integrable s) + (Eventually.of_forall (evenDensity_nonneg s)), evenDensity_integral] + norm_num + +instance oddKernel_isMarkovKernel : IsMarkovKernel oddKernel := by + constructor + intro s + constructor + rw [oddKernel_apply, setLIntegral_univ, + ← ofReal_integral_eq_lintegral_ofReal (oddDensity_integrable s) + (Eventually.of_forall (oddDensity_nonneg s)), oddDensity_integral] + norm_num + +theorem evenKernel_below_support (s : EvenState) : evenKernel s (Iio (s.1 - 1)) = 0 := by + rw [evenKernel_apply] + apply setLIntegral_eq_zero measurableSet_Iio + intro t ht + have hn : t ∉ Ici (s.1 - 1) := by + change ¬s.1 - 1 ≤ t + change t < s.1 - 1 at ht + exact not_le_of_gt ht + simp only [evenDensity, tailDensity, indicator_of_notMem hn, ENNReal.ofReal_zero, Pi.zero_apply] + +theorem oddKernel_below_support (s : OddState) : oddKernel s (Iio (max 2 (s.1 - 1))) = 0 := by + rw [oddKernel_apply] + apply setLIntegral_eq_zero measurableSet_Iio + intro t ht + have hn : t ∉ Ici (max 2 (s.1 - 1)) := by + change ¬max 2 (s.1 - 1) ≤ t + change t < max 2 (s.1 - 1) at ht + exact not_le_of_gt ht + simp only [oddDensity, tailDensity, indicator_of_notMem hn, ENNReal.ofReal_zero, Pi.zero_apply] + +theorem evenKernel_ae_support (s : EvenState) : ∀ᵐ t ∂evenKernel s, s.1 - 1 ≤ t := by + apply ae_iff.mpr + convert! evenKernel_below_support s using 1 + congr 1 + ext t + simp only [mem_ofPred_eq, mem_Iio, not_le] + +theorem oddKernel_ae_support (s : OddState) : ∀ᵐ t ∂oddKernel s, max 2 (s.1 - 1) ≤ t := by + apply ae_iff.mpr + convert! oddKernel_below_support s using 1 + congr 1 + ext t + simp only [mem_ofPred_eq, mem_Iio, not_le] + +theorem evenKernel_ae_odd_domain (s : EvenState) : ∀ᵐ t ∂evenKernel s, 95 / 100 ≤ t := by + filter_upwards [evenKernel_ae_support s] with t ht + linarith [s.2] + +theorem oddKernel_ae_even_domain (s : OddState) : ∀ᵐ t ∂oddKernel s, 198 / 100 ≤ t := by + filter_upwards [oddKernel_ae_support s] with t ht + linarith [le_max_left (2 : ℝ) (s.1 - 1)] + +end NumberTheoryLean.TransitionKernels + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/TwoSidedThresholdKernel.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/TwoSidedThresholdKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..62fa7fd81d5e5567eba07de8b4b235f532186be4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/TwoSidedThresholdKernel.lean @@ -0,0 +1,92 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.TwoSidedThresholdGeometry +import OAI.NumberTheory.Jacobsthal.Paths.ActualThresholdArrival + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.TwoSidedThresholdKernel +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures TransitionKernels KernelDensityBridge DerivativeWeights +open TwoSidedThresholdGeometry ErdosEvenThreshold CanonicalGapExposure RegeneratingInverseBands +attribute [local instance] Classical.propDecidable + +noncomputable def thickDensityBound : ℝ := (3/2:ℝ)*phiEven 2/phiOdd 6 +noncomputable def thickConstant : ℝ := 42*thickDensityBound + +theorem thickDensityBound_pos : 0 < thickDensityBound := by + have he := phiEven_pos (by norm_num : (1:ℝ)<2) + have ho := phiOdd_pos 6 + unfold thickDensityBound + positivity + +theorem thickConstant_pos : 0 < thickConstant := by + unfold thickConstant + exact mul_pos (by norm_num) thickDensityBound_pos + +theorem oddDensity_thick_bound (s : OddState) {t : ℝ} (ht2 : 2 ≤ t) (ht5 : t ≤ 5) : + oddDensity s t ≤ thickDensityBound := by + change (if max 2 (s.1-1) ≤ t then W t*phiEven t/phiOdd s.1 else 0) ≤ _ + by_cases hsup : max 2 (s.1-1) ≤ t + · rw [ite_eq_left hsup] + have hs6 : s.1 ≤ 6 := by linarith [le_max_right (2:ℝ) (s.1-1)] + have ht0 : 0 < t := by linarith + have hW : W t ≤ (3:ℝ)/2 := by + unfold W + apply (div_le_div_iff₀ (sq_pos_of_pos ht0) (by norm_num : (0:ℝ)<2)).mpr + nlinarith + have hphi := phiEven_strictAntiOn.antitoneOn (by norm_num : (2:ℝ) ∈ Ioi 1) + (by change 1 < t; linarith : t ∈ Ioi (1:ℝ)) ht2 + have hden := phiOdd_antitone hs6 + have hnum := mul_le_mul hW hphi (phiEven_pos (by linarith : 1 < t)).le (by norm_num : (0:ℝ)≤3/2) + calc + _ ≤ ((3:ℝ)/2*phiEven 2)/phiOdd s.1 := div_le_div_of_nonneg_right hnum (phiOdd_pos _).le + _ ≤ ((3:ℝ)/2*phiEven 2)/phiOdd 6 := + div_le_div_of_nonneg_left (mul_nonneg (by norm_num) (phiEven_pos (by norm_num)).le) (phiOdd_pos 6) hden + _ = _ := rfl + · rw [ite_eq_right hsup] + exact thickDensityBound_pos.le + +theorem oddKernel_thick_bound (s : OddState) {R delta : ℝ} (hR : 3 ≤ R) (hd : 0 ≤ delta) : + oddKernel s (thickStrip R delta) ≤ ENNReal.ofReal (thickConstant*delta) := by + rw [oddKernel_apply] + calc + _ ≤ ∫⁻ _t in thickStrip R delta,ENNReal.ofReal thickDensityBound := by + apply setLIntegral_mono measurable_const + intro t ht + exact ENNReal.ofReal_le_ofReal (oddDensity_thick_bound s ht.1 ht.2.1) + _ = ENNReal.ofReal thickDensityBound*volume (thickStrip R delta) := by simp + _ ≤ ENNReal.ofReal thickDensityBound*ENNReal.ofReal (42*delta) := + mul_le_mul_right (thickStrip_volume hR hd) _ + _ = _ := by + rw [← ENNReal.ofReal_mul thickDensityBound_pos.le] + congr 1 + unfold thickConstant + ring + +theorem oddToEven_thick_bound (s : OddState) {R delta : ℝ} (hR : 3 ≤ R) (hd : 0 ≤ delta) : + oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' thickStrip R delta) ≤ ENNReal.ofReal (thickConstant*delta) := by + have hh := oddKernel_thick_bound s hR hd + rw [← oddToEven_map_ratio s,Measure.map_apply measurable_subtype_coe (thickStrip_measurable R delta)] at hh + exact hh + +theorem oddToEven_thick_zero_high_parent (s : OddState) {R delta : ℝ} (hs : 6 < s.1) : + oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' thickStrip R delta)=0 := by + have he : oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' thickStrip R delta)=oddKernel s (thickStrip R delta) := by + rw [← oddToEven_map_ratio s,Measure.map_apply measurable_subtype_coe (thickStrip_measurable R delta)] + rw [he,oddKernel_apply] + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [ae_restrict_mem (thickStrip_measurable R delta)] with t ht + have hn : ¬max 2 (s.1-1) ≤ t := by linarith [le_max_right (2:ℝ) (s.1-1),ht.2.1] + have hz : oddDensity s t=0 := ite_eq_right hn + simp only [hz,ENNReal.ofReal_zero,Pi.zero_apply] +end NumberTheoryLean.TwoSidedThresholdKernel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/UncappedCompactEvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/UncappedCompactEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..5cd0f6c82d0d3327dd3da4b543250668c36018ec --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/UncappedCompactEvent.lean @@ -0,0 +1,100 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CompactSelectedPartition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.UncappedCompactEvent + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling PersistentFailureFlag +open PrimeBinMembership +open ActualCoupledHistories SourceSelectedCompactOccupation FullHistoryPrimeOccupation +open CompactPrefixOccurrence PrimeFamilyOccupation ActualPrimeHigh CompactSelectedPartition +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail RetainedCompactEvent + +attribute [local instance] Classical.propDecidable + +theorem uncapped_compact_event (R : ℝ) (hR : 3 ≤ R) (d : ℝ) (hd : 0 < d) : + ∃ C w₀ : ℝ, 0 < C ∧ 1 < w₀ ∧ ∀ A : ℝ, ∃ B₀ : ℝ, 0 < B₀ ∧ + ∀ B w : ℝ, B₀ ≤ B → w₀ ≤ w → ∀ ell : ℝ, ∀ start : Node, + ∀ hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → Real.log B ≤ d*Real.log w → + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := LowStateHorizon.sourceHorizon S B + ∀ mesh : ℝ, ∀ E : Set (List ℕ), + (∀ ps ∈ uncappedPrefixes w ell start, ps ∈ E → (terminal w start ps).gap ≤ R) → + (∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ + (C/B^2) * (fullSourceLaw w ell S start hs mesh N {h | occurs E N h}).toReal + B^(-A) := by + obtain ⟨C,W,hC,hW,hret⟩ := retained_compact_event R hR d hd + obtain ⟨WH,hWH,hhigh⟩ := uncapped_low_gap_high_removal + let w₀ := max W (max WH (max normalizationThreshold (Real.exp (d^2)))) + refine ⟨C,w₀,hC,hW.trans_le (le_max_left _ _),?_⟩ + intro A + obtain ⟨BH,hBH⟩ := eventually_atTop.mp (hhigh R (by linarith) A) + refine ⟨max (Real.exp 2) BH,(Real.exp_pos 2).trans_le (le_max_left _ _),?_⟩ + intro B w hB₀ hw ell start hs hell hellB hcomp hi h199 h23 hc hcut + dsimp only + intro mesh E hcompact + have heB : Real.exp 2 ≤ B := (le_max_left _ _).trans hB₀ + have hB : 0 < B := (Real.exp_pos 2).trans_le heB + have hlogB : 2 ≤ Real.log B := (Real.le_log_iff_exp_le hB).mpr heB + have hwW : W ≤ w := (le_max_left _ _).trans hw + have hwH : WH ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hnorm : normalizationThreshold ≤ w := + (le_trans (le_max_left _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hw + have hexp : Real.exp (d^2) ≤ w := + (le_trans (le_max_right _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hw + have hw1 : 1 < w := normalizationThreshold_gt_one.trans_le hnorm + have hlogw : d^2 ≤ Real.log w := (Real.le_log_iff_exp_le (by linarith : 0 < w)).mpr hexp + have hscale := UniformBudgetRate.source_scale_bound hlogw hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have he : start.gap = B*start.ratio := by + have hh : start.cutoff = start.gap/start.ratio := hc + rw [hcut] at hh + exact ((eq_div_iff (valid_pos hs).ne').mp hh).symm + have hr : 0 < start.gap := by rw [he]; exact mul_pos hB (valid_pos hs) + have hcompactRet : ∀ ps ∈ retainedPrefixes w ell ((Real.log B)^2) start, + ps ∈ E → (terminal w start ps).gap ≤ R := by + intro ps hp hE + rw [retained_eq_nonhigh hw1 hsS] at hp + exact hcompact ps (Finset.mem_filter.mp hp).1 hE + have hretain := hret w hwW ell B start hs hell hellB hB hlogB hcomp hi h199 h23 hc hcut + mesh E hcompactRet + let μ := fullSourceLaw w ell ((Real.log B)^2) start hs mesh + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) + let U : Set (FiniteHistoryTransport.Hist + (FlagState (JointState w ell ((Real.log B)^2) start)) + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B)) := + {h | occurs E (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) h} + have : IsProbabilityMeasure μ := by + dsimp [μ] + rw [fullSourceLaw_eq hnorm hell hS0 hscale.1 hr hs hsS] + infer_instance + have hm : 0 ≤ ∑ ps ∈ (retainedPrefixes w ell ((Real.log B)^2) start).filter (· ∈ E),prefixWeight ps := + Finset.sum_nonneg (fun ps _ => prefixWeight_nonneg ps) + have hreal := ENNReal.toReal_mono (ENNReal.mul_ne_top ENNReal.ofReal_ne_top (measure_ne_top μ U)) hretain + rw [ENNReal.toReal_ofReal (mul_nonneg (sq_nonneg B) hm),ENNReal.toReal_mul, + ENNReal.toReal_ofReal hC.le] at hreal + have hretReal : (∑ ps ∈ (retainedPrefixes w ell ((Real.log B)^2) start).filter (· ∈ E),prefixWeight ps) ≤ + (C/B^2)*(μ U).toReal := by + calc + _ ≤ (C*(μ U).toReal)/B^2 := (le_div_iff₀ (sq_pos_of_pos hB)).mpr (by nlinarith only [hreal]) + _ = _ := by ring + have hhighB := hBH B ((le_max_right _ _).trans hB₀) w hwH ell hell hellB start hcut hr hs hc + exact (selected_uncapped_le hw1 hsS E hcompact).trans (add_le_add hretReal hhighB) + +end NumberTheoryLean.UncappedCompactEvent + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Probability/UniformMoment.lean b/lean/OAI/NumberTheory/Jacobsthal/Probability/UniformMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..88267195e134e459b0001b9310c3d8acd457cdb3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Probability/UniformMoment.lean @@ -0,0 +1,78 @@ +import Mathlib.Analysis.PSeries +import OAI.NumberTheory.Jacobsthal.Primes.PrimeLaw + +namespace OAI + +namespace Erdos970 + +section + +namespace EulerPrimeLaw + +theorem log_excess_le_rpow {p : ℝ} (hp : 2 ≤ p) : + Real.log p / (p - 1) ^ 2 ≤ 8 * p ^ (-3 / 2 : ℝ) := by + have hp0 : 0 < p := by linarith + have hlog : Real.log p ≤ 2 * p ^ (1 / 2 : ℝ) := by + convert Real.log_le_rpow_div hp0.le (by norm_num : (0 : ℝ) < 1 / 2) using 1 + ring + have hden : p ^ 2 / 4 ≤ (p - 1) ^ 2 := by nlinarith [sq_nonneg (p - 2)] + calc + Real.log p / (p - 1) ^ 2 ≤ (2 * p ^ (1 / 2 : ℝ)) / (p - 1) ^ 2 := + div_le_div_of_nonneg_right hlog (sq_nonneg _) + _ ≤ (2 * p ^ (1 / 2 : ℝ)) / (p ^ 2 / 4) := + div_le_div_of_nonneg_left (by positivity) (by positivity) hden + _ = 8 * p ^ (-3 / 2 : ℝ) := by + rw [show (-3 / 2 : ℝ) = 1 / 2 - 2 by norm_num, Real.rpow_sub hp0, Real.rpow_two] + ring + +noncomputable def integerLogMoment (n : ℕ) : ℝ := Real.log (n : ℝ) / ((n : ℝ) - 1) ^ 2 + +lemma integerLogMoment_nonneg (n : ℕ) : 0 ≤ integerLogMoment n := by + cases n with + | zero => simp [integerLogMoment] + | succ n => + apply div_nonneg _ (sq_nonneg _) + exact Real.log_nonneg (by exact_mod_cast Nat.succ_le_succ (Nat.zero_le n)) + +lemma integerLogMoment_le (n : ℕ) : integerLogMoment n ≤ 8 * (n : ℝ) ^ (-3 / 2 : ℝ) := by + rcases Nat.lt_or_ge n 2 with h | h + · interval_cases n <;> norm_num [integerLogMoment] + · exact log_excess_le_rpow (by exact_mod_cast h) + +theorem integerLogMoment_summable : Summable integerLogMoment := by + have hs : Summable (fun n : ℕ => (n : ℝ) ^ (-3 / 2 : ℝ)) := by + apply Real.summable_nat_rpow.mpr + norm_num + exact (hs.mul_left 8).of_nonneg_of_le integerLogMoment_nonneg integerLogMoment_le + +noncomputable def uniformMomentBound : ℝ := 1 + ∑' n : ℕ, integerLogMoment n + +theorem uniformMomentBound_pos : 0 < uniformMomentBound := by + have h : 0 ≤ ∑' n : ℕ, integerLogMoment n := tsum_nonneg integerLogMoment_nonneg + unfold uniformMomentBound + linarith + +theorem finite_log_moment_le (E : Finset ℕ) : + (∑ p ∈ E, Real.log (p : ℝ) / ((p : ℝ) - 1) ^ 2) ≤ uniformMomentBound := by + have h := integerLogMoment_summable.sum_le_tsum E (fun n _ => integerLogMoment_nonneg n) + change (∑ p ∈ E, integerLogMoment p) ≤ 1 + ∑' n : ℕ, integerLogMoment n + linarith + +theorem finite_expected_log_excess_le (E : Finset ℕ) (hE : ∀ p ∈ E, 2 ≤ p) : + (∑ p ∈ E, ∑' s : Sample, jointMass (p : ℝ) s * + ((upperExponent s - lowerExponent s : ℕ) : ℝ) * Real.log (p : ℝ)) ≤ + uniformMomentBound := by + calc + _ = ∑ p ∈ E, Real.log (p : ℝ) / ((p : ℝ) - 1) ^ 2 := by + apply Finset.sum_congr rfl + intro p hp + exact expected_log_excess (by exact_mod_cast hE p hp) + _ ≤ uniformMomentBound := finite_log_moment_le E + +end EulerPrimeLaw + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/ClockTailReward.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/ClockTailReward.lean new file mode 100644 index 0000000000000000000000000000000000000000..53655ff2804c74925cc567d0ddfa4ad53e4eb227 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/ClockTailReward.lean @@ -0,0 +1,254 @@ +import OAI.NumberTheory.Jacobsthal.Probability.MarkedBeginningKernel + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open AbsorptionCutoff.Renewal +open NumberTheoryLean.KernelPotential + +instance markedClock_pow_isMarkovKernel (n : ℕ) : IsMarkovKernel (markedClockKernel ^ n) := by + induction n with + | zero => change IsMarkovKernel (Kernel.id : Kernel ℝ ℝ); infer_instance + | succ n ih => + rw [pow_succ'] + change IsMarkovKernel (markedClockKernel ∘ₖ (markedClockKernel ^ n)) + infer_instance + +lemma markedClock_cumulative_lintegral (n : ℕ) (x : ℝ) {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y ∂(markedClockKernel ^ n) x) = ∫⁻ G, H (x+G) ∂convPow markedSpacingLaw n := by + induction n generalizing x with + | zero => + change (∫⁻ y, H y ∂Measure.dirac x) = _ + rw [lintegral_dirac' x hH,convPow_zero, + lintegral_dirac' 0 (f := fun G : ℝ => H (x+G)) (hH.comp (measurable_const.add measurable_id)),add_zero] + | succ n ih => + have hp : markedClockKernel ^ (n+1) = (markedClockKernel ^ n) ∘ₖ markedClockKernel := pow_succ _ _ + rw [hp,Kernel.lintegral_comp _ _ _ hH] + simp_rw [ih] + have hF : Measurable (fun y : ℝ => ∫⁻ G, H (y+G) ∂convPow markedSpacingLaw n) := + (hH.comp measurable_add).lintegral_prod_right' + rw [markedClockKernel_apply,lintegral_map (g := fun G : ℝ => x+G) hF (measurable_const.add measurable_id), + convPow_succ',Measure.lintegral_conv (f := fun G : ℝ => H (x+G)) + (hH.comp (measurable_const.add measurable_id))] + apply lintegral_congr + intro t + apply lintegral_congr + intro G + congr 1 + ring + +lemma markedClock_cumulative_law (n : ℕ) (x : ℝ) : + (markedClockKernel ^ n) x = (convPow markedSpacingLaw n).map (fun G => x+G) := by + apply Measure.ext_of_lintegral + intro H hH + rw [markedClock_cumulative_lintegral n x hH, + lintegral_map (g := fun G : ℝ => x+G) hH (measurable_const.add measurable_id)] + +lemma markedClock_zero_law (n : ℕ) : (markedClockKernel ^ n) 0 = convPow markedSpacingLaw n := by + rw [markedClock_cumulative_law] + simp only [zero_add] + exact Measure.map_id + +lemma markedClock_renewal : + (potential (Kernel.id : Kernel ℝ ℝ) markedClockKernel) 0 = renewalMeasure markedSpacingLaw := by + rw [potential,Kernel.sum_apply,renewalMeasure] + apply congrArg Measure.sum + funext n + rw [Kernel.id_comp,markedClock_zero_law] + +lemma markedClock_increment_lower (x : ℝ) : + ∀ᵐ y ∂markedClockKernel x, x+Real.log (4/3) ≤ y := by + rw [markedClockKernel_apply] + apply (ae_map_iff (measurable_const.add measurable_id).aemeasurable measurableSet_Ici).mpr + filter_upwards [markedSpacing_cost_lower] with G hG + change x+Real.log (4/3) ≤ x+G + linarith + +lemma markedClock_minimum_pos : (0:ℝ) < Real.log (4/3) := Real.log_pos (by norm_num) + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open AbsorptionCutoff.Renewal +open NumberTheoryLean.KernelPotential + +noncomputable def clockBelow (v : ℝ) : Kernel ℝ ℝ := markedClockKernel.restrict (s := Iio v) measurableSet_Iio +noncomputable def clockOver (v H : ℝ) : Kernel ℝ ℝ := markedClockKernel.restrict (s := Ioi (v+H)) measurableSet_Ioi + +instance clockBelow_isFiniteKernel (v : ℝ) : IsFiniteKernel (clockBelow v) := by unfold clockBelow; infer_instance +instance clockOver_isFiniteKernel (v H : ℝ) : IsFiniteKernel (clockOver v H) := by unfold clockOver; infer_instance + +instance clockBelow_pow_isFiniteKernel (v : ℝ) (n : ℕ) : IsFiniteKernel (clockBelow v ^ n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel ℝ ℝ); infer_instance + | succ n ih => rw [pow_succ']; change IsFiniteKernel (clockBelow v ∘ₖ (clockBelow v ^ n)); infer_instance + +noncomputable def clockOverReward (v H : ℝ) : Kernel ℝ ℝ := by + classical + exact Kernel.piecewise (s := Iio v) measurableSet_Iio (clockOver v H) 0 + +instance clockOverReward_isFiniteKernel (v H : ℝ) : IsFiniteKernel (clockOverReward v H) := by + classical + unfold clockOverReward + infer_instance + +noncomputable def clockOvershoot (v H : ℝ) : ℝ≥0∞ := (potential (clockOver v H) (clockBelow v)) 0 univ + +lemma clockBelow_le (v : ℝ) : clockBelow v ≤ markedClockKernel := by + intro x + rw [clockBelow,Kernel.restrict_apply] + exact Measure.restrict_le_self + +lemma clockBelow_ae_lt (v x : ℝ) : ∀ᵐ y ∂clockBelow v x, y < v := by + rw [clockBelow,Kernel.restrict_apply] + exact ae_restrict_mem measurableSet_Iio + +lemma clockBelow_pow_ae_lt {v : ℝ} (hv : 0 < v) (n : ℕ) : ∀ᵐ y ∂(clockBelow v ^ n) 0, y < v := by + cases n with + | zero => change ∀ᵐ y ∂Measure.dirac (0:ℝ), y < v; exact (ae_dirac_iff measurableSet_Iio).mpr hv + | succ n => + rw [pow_succ'] + change ∀ᵐ y ∂(clockBelow v ∘ₖ (clockBelow v ^ n)) 0, y < v + exact Kernel.ae_comp_of_ae_ae measurableSet_Iio (Eventually.of_forall (clockBelow_ae_lt v)) + +lemma clockOver_mass (v H x : ℝ) : clockOver v H x univ = markedSpacingLaw (Ioi (v+H-x)) := by + rw [clockOver,Kernel.restrict_apply,Measure.restrict_apply MeasurableSet.univ,univ_inter, + markedClockKernel_apply,Measure.map_apply (f := fun G : ℝ => x+G) + (measurable_const.add measurable_id) measurableSet_Ioi] + congr 1 + ext G + simp only [mem_preimage,mem_Ioi] + constructor <;> intro h <;> linarith + +lemma clockOverReward_mass (v H x : ℝ) : clockOverReward v H x univ = + if x < v then markedSpacingLaw (Ioi (v+H-x)) else 0 := by + classical + rw [clockOverReward,Kernel.piecewise_apply] + by_cases hx : x < v <;> simp [hx,clockOver_mass] + +lemma clock_compose_mono_right {K L : Kernel ℝ ℝ} (h : K ≤ L) (B : Kernel ℝ ℝ) : + B ∘ₖ K ≤ B ∘ₖ L := by + intro x + apply Measure.le_iff.mpr + intro S hS + rw [Kernel.comp_apply' _ _ _ hS,Kernel.comp_apply' _ _ _ hS] + exact lintegral_mono' (h x) le_rfl + +lemma clock_potential_mono_step {K L : Kernel ℝ ℝ} (h : K ≤ L) (B : Kernel ℝ ℝ) : + potential B K ≤ potential B L := by + apply potential_le_of_super B K (potential B L) + calc + _ ≤ B+(potential B L) ∘ₖ L := fun x => add_le_add le_rfl ((clock_compose_mono_right h _) x) + _ = _ := (potential_unfold B L).symm + +lemma clockOvershoot_guarded {v : ℝ} (hv : 0 < v) (H : ℝ) : + (potential (clockOver v H) (clockBelow v)) 0 = + (potential (clockOverReward v H) (clockBelow v)) 0 := by + classical + ext B hB + unfold potential + rw [Kernel.sum_apply' _ _ hB,Kernel.sum_apply' _ _ hB] + apply tsum_congr + intro n + rw [Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB] + apply lintegral_congr_ae + filter_upwards [clockBelow_pow_ae_lt hv n] with x hx + rw [clockOverReward,Kernel.piecewise_apply,ite_eq_left (show x ∈ Iio v from hx)] + +lemma clockReward_potential_integral (v H : ℝ) : + (potential (clockOverReward v H) markedClockKernel) 0 univ = + ∫⁻ x, clockOverReward v H x univ ∂renewalMeasure markedSpacingLaw := by + rw [potential,Kernel.sum_apply' _ _ MeasurableSet.univ,renewalMeasure,lintegral_sum_measure] + apply tsum_congr + intro n + rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ,markedClock_zero_law] + +lemma clockOvershoot_le_reward {v : ℝ} (hv : 0 < v) (H : ℝ) : + clockOvershoot v H ≤ ∫⁻ x, clockOverReward v H x univ ∂renewalMeasure markedSpacingLaw := by + rw [clockOvershoot,clockOvershoot_guarded hv H] + exact ((clock_potential_mono_step (clockBelow_le v) (clockOverReward v H)) 0 univ).trans_eq + (clockReward_potential_integral v H) + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open AbsorptionCutoff.Renewal + +noncomputable def clockTailPiece (v H : ℝ) (j : ℕ) : ℝ → ℝ≥0∞ := + (Icc (v-(j:ℝ)-1) (v-j)).indicator (fun _ => markedSpacingLaw (Ioi (H+j))) + +lemma clockTailPiece_measurable (v H : ℝ) (j : ℕ) : Measurable (clockTailPiece v H j) := + measurable_const.indicator measurableSet_Icc + +lemma clockReward_le_tail_pieces (v H x : ℝ) : + clockOverReward v H x univ ≤ ∑' j : ℕ, clockTailPiece v H j x := by + classical + rw [clockOverReward_mass] + by_cases hx : x < v + · rw [ite_eq_left hx] + let j : ℕ := ⌊v-x⌋₊ + have hjlo : (j:ℝ) ≤ v-x := Nat.floor_le (by linarith) + have hjhi : v-x < (j:ℝ)+1 := Nat.lt_floor_add_one _ + have hmem : x ∈ Icc (v-(j:ℝ)-1) (v-j) := ⟨by linarith,by linarith⟩ + calc + _ ≤ markedSpacingLaw (Ioi (H+j)) := measure_mono (fun t ht => by + change H+(j:ℝ) < t + change v+H-x < t at ht + linarith) + _ = clockTailPiece v H j x := by rw [clockTailPiece,indicator_of_mem hmem] + _ ≤ _ := ENNReal.le_tsum (f := fun k : ℕ => clockTailPiece v H k x) j + · rw [ite_eq_right hx] + exact zero_le + +lemma clockTailPiece_integral (v H : ℝ) (j : ℕ) : + (∫⁻ x, clockTailPiece v H j x ∂renewalMeasure markedSpacingLaw) = + markedSpacingLaw (Ioi (H+j))*renewalMeasure markedSpacingLaw (Icc (v-(j:ℝ)-1) (v-j)) := by + rw [clockTailPiece,lintegral_indicator measurableSet_Icc] + simp [lintegral_const] + +theorem clock_renewal_reward_tail_bound : ∃ C : ℝ, 0 < C ∧ ∀ v H : ℝ, + (∫⁻ x, clockOverReward v H x univ ∂renewalMeasure markedSpacingLaw) ≤ + ENNReal.ofReal C*(∑' j : ℕ, markedSpacingLaw (Ioi (H+j))) := by + obtain ⟨C,hC,hcell⟩ := marked_renewal_cell_bound 1 + refine ⟨C,hC,?_⟩ + intro v H + calc + _ ≤ ∫⁻ x, ∑' j : ℕ, clockTailPiece v H j x ∂renewalMeasure markedSpacingLaw := + lintegral_mono (clockReward_le_tail_pieces v H) + _ = ∑' j : ℕ, ∫⁻ x, clockTailPiece v H j x ∂renewalMeasure markedSpacingLaw := + lintegral_tsum (fun j => (clockTailPiece_measurable v H j).aemeasurable) + _ ≤ ∑' j : ℕ, ENNReal.ofReal C*markedSpacingLaw (Ioi (H+j)) := by + apply ENNReal.tsum_le_tsum + intro j + rw [clockTailPiece_integral] + have he := hcell (v-(j:ℝ)-1) + rw [show v-(j:ℝ)-1+1=v-j by ring] at he + have hm := mul_le_mul_right he (markedSpacingLaw (Ioi (H+j))) + simpa only [mul_comm] using hm + _ = _ := ENNReal.tsum_mul_left + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/ClockWindowPassage.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/ClockWindowPassage.lean new file mode 100644 index 0000000000000000000000000000000000000000..3681aae9f5b3b6d6d99a37c27ba6edfaab6896be --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/ClockWindowPassage.lean @@ -0,0 +1,144 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ClockExponentialTail + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.KernelPotential + +noncomputable def clockAtOrAbove (v : ℝ) : Kernel ℝ ℝ := + markedClockKernel.restrict (s := Ici v) measurableSet_Ici + +instance clockAtOrAbove_isFiniteKernel (v : ℝ) : IsFiniteKernel (clockAtOrAbove v) := by + unfold clockAtOrAbove; infer_instance + +lemma clockAtOrAbove_add_below (v : ℝ) : clockAtOrAbove v + clockBelow v = markedClockKernel := by + ext x : 1 + change (markedClockKernel x).restrict (Ici v) + (markedClockKernel x).restrict (Iio v) = _ + simpa only [compl_Ici] using Measure.restrict_add_restrict_compl (μ := markedClockKernel x) measurableSet_Ici + +lemma clockBelow_increment_lower (v x : ℝ) : + ∀ᵐ y ∂clockBelow v x, x+Real.log (4/3) ≤ y := by + rw [clockBelow,Kernel.restrict_apply] + exact ae_restrict_of_ae (markedClock_increment_lower x) + +lemma clockBelow_pow_lower (v x : ℝ) (n : ℕ) : + ∀ᵐ y ∂(clockBelow v ^ n) x, x+(n:ℝ)*Real.log (4/3) ≤ y := by + induction n with + | zero => + simp only [pow_zero,Nat.cast_zero,zero_mul,add_zero] + exact (ae_dirac_iff measurableSet_Ici).mpr le_rfl + | succ n ih => + rw [pow_succ'] + change ∀ᵐ y ∂(clockBelow v ∘ₖ (clockBelow v ^ n)) x, _ ≤ y + apply Kernel.ae_comp_of_ae_ae measurableSet_Ici + filter_upwards [ih] with y hy + filter_upwards [clockBelow_increment_lower v y] with z hz + push_cast + nlinarith + +lemma clockBelow_mass_eq_zero {v : ℝ} (hv : 0 < v) {n : ℕ} + (hn : v ≤ (n:ℝ)*Real.log (4/3)) : (clockBelow v ^ n) 0 univ = 0 := by + have hfalse : ∀ᵐ y ∂(clockBelow v ^ n) 0, False := by + filter_upwards [clockBelow_pow_lower v 0 n,clockBelow_pow_ae_lt hv n] with y hy hvy + linarith + simpa only [ae_iff,not_false_eq_true,ofPred_true] using hfalse + +lemma clockBelow_survival_tendsto_zero {v : ℝ} (hv : 0 < v) : + Tendsto (fun n : ℕ => (clockBelow v ^ n) 0 univ) atTop (𝓝 0) := by + obtain ⟨N,hN⟩ := exists_nat_gt (v/Real.log (4/3)) + have hNc : v ≤ (N:ℝ)*Real.log (4/3) := + (div_lt_iff₀ markedClock_minimum_pos).mp hN |>.le + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop N] with n hn + exact (clockBelow_mass_eq_zero hv (hNc.trans (mul_le_mul_of_nonneg_right + (by exact_mod_cast hn) markedClock_minimum_pos.le))).symm + +lemma clockExit_mass_step (v : ℝ) (n : ℕ) : + (clockAtOrAbove v ∘ₖ (clockBelow v ^ n)) 0 univ + + (clockBelow v ^ (n+1)) 0 univ = (clockBelow v ^ n) 0 univ := by + have hp : clockBelow v ^ (n+1) = clockBelow v ∘ₖ (clockBelow v ^ n) := pow_succ' _ _ + calc + _ = ((clockAtOrAbove v+clockBelow v) ∘ₖ (clockBelow v ^ n)) 0 univ := by + rw [Kernel.comp_add_left,_root_.add_apply,Measure.add_apply,hp] + _ = (markedClockKernel ∘ₖ (clockBelow v ^ n)) 0 univ := by rw [clockAtOrAbove_add_below] + _ = _ := by rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ]; simp + +lemma clockExit_finite_mass (v : ℝ) (n : ℕ) : + (clockBelow v ^ n) 0 univ + + ∑ k ∈ Finset.range n, (clockAtOrAbove v ∘ₖ (clockBelow v ^ k)) 0 univ = 1 := by + induction n with + | zero => change (Measure.dirac (0:ℝ)) univ + 0 = 1; simp + | succ n ih => + rw [Finset.sum_range_succ] + calc + _ = (∑ k ∈ Finset.range n, (clockAtOrAbove v ∘ₖ (clockBelow v ^ k)) 0 univ)+ + ((clockAtOrAbove v ∘ₖ (clockBelow v ^ n)) 0 univ+(clockBelow v ^ (n+1)) 0 univ) := by ac_rfl + _ = _ := by rw [clockExit_mass_step]; simpa only [add_comm] using ih + +lemma clockExit_mass_one {v : ℝ} (hv : 0 < v) : + (potential (clockAtOrAbove v) (clockBelow v)) 0 univ = 1 := by + rw [potential,Kernel.sum_apply' _ _ MeasurableSet.univ] + have h := (clockBelow_survival_tendsto_zero hv).add (ENNReal.tendsto_nat_tsum + (fun n => (clockAtOrAbove v ∘ₖ (clockBelow v ^ n)) 0 univ)) + simp only [zero_add,clockExit_finite_mass] at h + exact tendsto_nhds_unique h tendsto_const_nhds + +noncomputable def clockWindow (v H : ℝ) : Kernel ℝ ℝ := + markedClockKernel.restrict (s := Icc v (v+H)) measurableSet_Icc + +instance clockWindow_isFiniteKernel (v H : ℝ) : IsFiniteKernel (clockWindow v H) := by + unfold clockWindow; infer_instance + +noncomputable def clockWindowHit (v H : ℝ) : ℝ≥0∞ := + (potential (clockWindow v H) (clockBelow v)) 0 univ + +lemma clockWindow_add_over {v H : ℝ} (hH : 0 ≤ H) : + clockWindow v H+clockOver v H = clockAtOrAbove v := by + ext x : 1 + change (markedClockKernel x).restrict (Icc v (v+H))+ + (markedClockKernel x).restrict (Ioi (v+H)) = (markedClockKernel x).restrict (Ici v) + have hd : Disjoint (Icc v (v+H)) (Ioi (v+H)) := by + rw [disjoint_left] + intro y hy hz + exact (not_lt_of_ge hy.2) hz + rw [← Measure.restrict_union hd measurableSet_Ioi] + congr 1 + ext y + simp only [mem_union,mem_Icc,mem_Ioi,mem_Ici] + constructor + · rintro (h|h) <;> linarith + · intro h + by_cases hy : y ≤ v+H + · exact Or.inl ⟨h,hy⟩ + · exact Or.inr (lt_of_not_ge hy) + +theorem clockWindowHit_add_overshoot {v H : ℝ} (hv : 0 < v) (hH : 0 ≤ H) : + clockWindowHit v H+clockOvershoot v H = 1 := by + rw [clockWindowHit,clockOvershoot,← Measure.add_apply,← _root_.add_apply, + ← potential_add,clockWindow_add_over hH] + exact clockExit_mass_one hv + +theorem clockWindowHit_exponential : ∃ eta C : ℝ, 0 < eta ∧ 0 < C ∧ ∀ v H : ℝ, + 0 < v → 0 ≤ H → 1-ENNReal.ofReal (C*Real.exp (-eta*H)) ≤ clockWindowHit v H := by + obtain ⟨eta,C,heta,hC,hTail⟩ := clockOvershoot_exponential + refine ⟨eta,C,heta,hC,?_⟩ + intro v H hv hH + have he : clockWindowHit v H+clockOvershoot v H = 1 := clockWindowHit_add_overshoot hv hH + have hb : 1 ≤ clockWindowHit v H+ENNReal.ofReal (C*Real.exp (-eta*H)) := by + rw [← he] + exact add_le_add le_rfl (hTail v H hv hH) + exact tsub_le_iff_right.mpr hb + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/CompletedCycleFirstArrival.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/CompletedCycleFirstArrival.lean new file mode 100644 index 0000000000000000000000000000000000000000..1bdb13e2ca90727a470743ccbac8dad1d9b9a23d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/CompletedCycleFirstArrival.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FiniteVisitMass + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels NumberTheoryLean.CycleOccupation + +lemma witnessContinuation_first_lintegral (z : FirstPairWitness) {F : EvenState → ℝ≥0∞} + (hF : Measurable F) : (∫⁻ w, F w.1 ∂witnessContinuation z)=F z.1 := by + rw [witnessContinuation,Kernel.map_apply _ continueWitnessUpdate_measurable, + lintegral_map (f := fun w : SourceCycleWitness => F w.1) (g := continueWitnessUpdate) (hF.comp measurable_fst) continueWitnessUpdate_measurable, + Kernel.lintegral_id_prod (f := fun x : FirstPairWitness × (ℕ × OddCost) => F (continueWitnessUpdate x).1) + ((hF.comp measurable_fst).comp continueWitnessUpdate_measurable)] + change (∫⁻ _w, F z.1 ∂durationHitOrReturn z.2)=F z.1 + simp + +lemma sourceCycleWitness_first_lintegral (z : OddCost) {F : CostState → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ w, F (sourceReturnSignature z w).2.1 ∂sourceCycleWitnessKernel z)= + ∫⁻ y, F y ∂costKernel (embedOdd z) := by + have hG : Measurable (fun t : EvenState => F (Sum.inl t,z.2+cost t.1)) := + hF.comp (measurable_inl.prodMk (measurable_const.add (cost_measurable.comp measurable_subtype_coe))) + rw [sourceCycleWitnessKernel,Kernel.lintegral_comp _ _ _ + (g := fun w : SourceCycleWitness => F (sourceReturnSignature z w).2.1) + (hF.comp ((measurable_fst.comp measurable_snd).comp (sourceReturnSignature_measurable z)))] + change (∫⁻ y : FirstPairWitness, ∫⁻ w, (fun t : EvenState => F (Sum.inl t,z.2+cost t.1)) w.1 + ∂witnessContinuation y ∂pairWitnessKernel z)=_ + simp_rw [witnessContinuation_first_lintegral _ hG] + rw [pairWitness_lintegral z (F := fun y : FirstPairWitness => F (Sum.inl y.1,z.2+cost y.1.1)) + (hG.comp measurable_fst)] + simp only [lintegral_const,measure_univ,mul_one] + exact (costKernel_odd_lintegral z.1 z.2 hF).symm + +theorem sourceCycleWitness_first_arrival (z : OddCost) : + (sourceCycleWitnessKernel z).map (fun w => (sourceReturnSignature z w).2.1)=costKernel (embedOdd z) := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map (g := fun w : SourceCycleWitness => (sourceReturnSignature z w).2.1) hF ((measurable_fst.comp measurable_snd).comp (sourceReturnSignature_measurable z))] + exact sourceCycleWitness_first_lintegral z hF + +theorem rawReturn_first_arrival (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (rawReturnTraceKernel a h).map (fun r => (rawReturnSignature a r).2.1)=costKernel (rawLast a h) := by + have he := congrArg (fun μ : Measure ReturnSignature => μ.map (fun s => s.2.1)) + (rawReturnTrace_signature a h z hz) + rw [Measure.map_map (g := fun s : ReturnSignature => s.2.1) + (measurable_fst.comp measurable_snd) (rawReturnSignature_measurable a), + Measure.map_map (g := fun s : ReturnSignature => s.2.1) + (measurable_fst.comp measurable_snd) (sourceReturnSignature_measurable z)] at he + rw [hz] + exact he.trans (sourceCycleWitness_first_arrival z) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/ContinuousCompletedOccupation.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/ContinuousCompletedOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..c03939b162cf4b77f81fb4a9b7431ecce558525f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/ContinuousCompletedOccupation.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CompletedParentInterval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + + +namespace NumberTheoryLean.ContinuousCompletedOccupation + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.Finset _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathMeasures ContinuousKilledBins LowStateHorizon CemeteryKernel +open PairedCostGrouping OccupationDecomposition CostPrefixTransport + +noncomputable abbrev liftReward := @CemeteryPowers.liftReward CostState + +theorem liftReward_measurable {F : CostState → ℝ≥0∞} (hF : Measurable F) : Measurable (liftReward F) := + CemeteryPowers.liftReward_measurable hF + +theorem completed_power_lift (v ell S : ℝ) {F : CostState → ℝ≥0∞} (hF : Measurable F) + (n : ℕ) (q : Space CostState) : + (∫⁻ y,liftReward F y ∂((continuousChain v ell S)^n) q) = + liftReward (fun z => ∫⁻ y,F y ∂((lowKernel costKernel v ell S)^n) z) q := + CemeteryPowers.power_lift (lowKernel costKernel v ell S) hF n q + +theorem low_power_integral_le (v ell S : ℝ) {F : CostState → ℝ≥0∞} (hF : Measurable F) + (n : ℕ) (z : CostState) : + (∫⁻ y,F y ∂((lowKernel costKernel v ell S)^n) z) ≤ ∫⁻ y,F y ∂(costKernel^n) z := by + induction n generalizing z with + | zero => exact le_rfl + | succ n ih => + have hp : (lowKernel costKernel v ell S)^(n+1) = + ((lowKernel costKernel v ell S)^n) ∘ₖ lowKernel costKernel v ell S := pow_succ _ _ + have hq : costKernel^(n+1) = (costKernel^n) ∘ₖ costKernel := pow_succ _ _ + rw [hp,hq,Kernel.lintegral_comp _ _ _ hF,Kernel.lintegral_comp _ _ _ hF] + calc + _ ≤ ∫⁻ y,∫⁻ a,F a ∂(costKernel^n) y ∂lowKernel costKernel v ell S z := lintegral_mono ih + _ ≤ _ := by + rw [lowKernel,Kernel.restrict_apply] + exact setLIntegral_le_lintegral _ _ + +theorem inclusive_integral_eq_tsum {F : CostState → ℝ≥0∞} (hF : Measurable F) (z : CostState) : + (∫⁻ y,F y ∂inclusiveOccupation z) = ∑' n : ℕ,∫⁻ y,F y ∂(costKernel^n) z := by + rw [inclusiveOccupation,_root_.add_apply,lintegral_add_measure,Kernel.id_apply, + lintegral_dirac' _ hF,fullOccupation,Kernel.sum_apply,lintegral_sum_measure] + conv_rhs => rw [tsum_eq_zero_add' ENNReal.summable] + congr 1 + change F z = ∫⁻ y,F y ∂Measure.dirac z + rw [lintegral_dirac' _ hF] + +theorem completed_finite_occupation_le (v ell S : ℝ) {F : CostState → ℝ≥0∞} (hF : Measurable F) + (N : ℕ) (z : CostState) : + (∑ n ∈ range N,∫⁻ y,liftReward F y ∂((continuousChain v ell S)^n) (.inl z)) ≤ + ∫⁻ y,F y ∂inclusiveOccupation z := by + rw [inclusive_integral_eq_tsum hF z] + calc + _ ≤ ∑ n ∈ range N,∫⁻ y,F y ∂(costKernel^n) z := by + apply Finset.sum_le_sum + intro n _hn + rw [completed_power_lift v ell S hF] + exact low_power_integral_le v ell S hF n z + _ ≤ _ := ENNReal.sum_le_tsum (range N) + +end NumberTheoryLean.ContinuousCompletedOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/DickmanFiniteDecay.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/DickmanFiniteDecay.lean new file mode 100644 index 0000000000000000000000000000000000000000..3314ba91c75597f30566fb994a61ee2243a79905 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/DickmanFiniteDecay.lean @@ -0,0 +1,696 @@ +import Mathlib.Analysis.Calculus.Deriv.MeanValue +import Mathlib.Analysis.Calculus.MeanValue +import Mathlib.Analysis.Complex.ExponentialBounds +import Mathlib.Analysis.SpecialFunctions.Exp +import Mathlib.Analysis.SpecialFunctions.Integrals.Basic +import Mathlib.Analysis.SpecialFunctions.Log.Basic +import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.DelayConstruction + +open MeasureTheory Filter +open scoped Topology + +noncomputable def kernel (f : ℝ → ℝ) (t : ℝ) : ℝ := f (t - 1) / max 1 t + +theorem kernel_continuous {f : ℝ → ℝ} (hf : Continuous f) : Continuous (kernel f) := by + apply Continuous.div (hf.comp (continuous_id.sub continuous_const)) (continuous_const.max continuous_id) + intro t + change max (1 : ℝ) t ≠ 0 + have h := le_max_left (1 : ℝ) t + linarith + +noncomputable def stepApprox (σ : ℝ) : ℕ → ℝ → ℝ + | 0 => fun _ => 1 + | n + 1 => fun u => 1 + σ * ∫ t in (1 : ℝ)..max 1 u, kernel (stepApprox σ n) t + +theorem stepApprox_continuous (σ : ℝ) (n : ℕ) : Continuous (stepApprox σ n) := by + induction n with + | zero => exact continuous_const + | succ n ih => + have hk := kernel_continuous ih + have hInt : Continuous (fun u : ℝ => ∫ t in (1 : ℝ)..u, kernel (stepApprox σ n) t) := + (intervalIntegral.differentiable_integral_of_continuous hk).continuous + exact continuous_const.add (continuous_const.mul (hInt.comp (continuous_const.max continuous_id))) + +theorem stepApprox_initial (σ : ℝ) (n : ℕ) {u : ℝ} (hu : u ≤ 1) : stepApprox σ n u = 1 := by + cases n <;> simp [stepApprox, max_eq_left hu] + +theorem stepApprox_succ_stable (σ : ℝ) (n : ℕ) {u : ℝ} (hu : u ≤ (n : ℝ) + 1) : + stepApprox σ (n + 1) u = stepApprox σ n u := by + induction n generalizing u with + | zero => simp only [Nat.cast_zero, zero_add] at hu; simp [stepApprox, max_eq_left hu] + | succ n ih => + change 1 + σ * (∫ t in (1 : ℝ)..max 1 u, kernel (stepApprox σ (n + 1)) t) = + 1 + σ * (∫ t in (1 : ℝ)..max 1 u, kernel (stepApprox σ n) t) + apply congrArg (fun I : ℝ => 1 + σ * I) + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le (le_max_left (1 : ℝ) u)] at ht + have hmax : max 1 u ≤ (n : ℝ) + 2 := by + apply max_le + · have hn0 := Nat.cast_nonneg (α := ℝ) n + linarith + · push_cast at hu + linarith + have htbound : t - 1 ≤ (n : ℝ) + 1 := by linarith [ht.2] + unfold kernel + rw [ih htbound] + +theorem stepApprox_stable (σ : ℝ) {n m : ℕ} (hnm : n ≤ m) {u : ℝ} + (hu : u ≤ (n : ℝ) + 1) : stepApprox σ m u = stepApprox σ n u := by + induction m, hnm using Nat.le_induction with + | base => rfl + | succ m hm ih => + rw [stepApprox_succ_stable σ m, ih] + have hcast : (n : ℝ) ≤ m := by exact_mod_cast hm + linarith + +noncomputable def delay (σ u : ℝ) : ℝ := stepApprox σ ⌈u⌉₊ u + +theorem delay_eq_stepApprox (σ : ℝ) (n : ℕ) {u : ℝ} (hu : u ≤ (n : ℝ) + 1) : + delay σ u = stepApprox σ n u := by + unfold delay + have hceil : u ≤ (⌈u⌉₊ : ℝ) + 1 := by have h := Nat.le_ceil u; linarith + rcases le_total n ⌈u⌉₊ with h | h + · exact stepApprox_stable σ h hu + · exact (stepApprox_stable σ h hceil).symm + +theorem delay_continuous (σ : ℝ) : Continuous (delay σ) := by + apply continuous_iff_continuousAt.mpr + intro u + let n := ⌈u⌉₊ + 1 + have hu : u < (n : ℝ) + 1 := by have h := Nat.le_ceil u; dsimp [n]; push_cast; linarith + have heq : delay σ =ᶠ[𝓝 u] stepApprox σ n := by + filter_upwards [Iio_mem_nhds hu] with x hx + exact delay_eq_stepApprox σ n hx.le + exact (continuousAt_congr heq).mpr (stepApprox_continuous σ n).continuousAt + +theorem delay_initial (σ : ℝ) {u : ℝ} (hu : u ≤ 1) : delay σ u = 1 := by + rw [delay_eq_stepApprox σ 0 (by simpa using hu)] + rfl + +theorem delay_integral (σ u : ℝ) : + delay σ u = 1 + σ * ∫ t in (1 : ℝ)..max 1 u, kernel (delay σ) t := by + let n := ⌈u⌉₊ + have hu : u ≤ (n : ℝ) := Nat.le_ceil u + rw [delay_eq_stepApprox σ (n + 1) (by push_cast; linarith)] + change 1 + σ * (∫ t in (1 : ℝ)..max 1 u, kernel (stepApprox σ n) t) = _ + apply congrArg (fun I : ℝ => 1 + σ * I) + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le (le_max_left (1 : ℝ) u)] at ht + have hmax : max 1 u ≤ (n : ℝ) + 1 := max_le (by have hn0 := Nat.cast_nonneg (α := ℝ) n; linarith) (by linarith) + have htbound : t - 1 ≤ (n : ℝ) + 1 := by linarith [ht.2] + unfold kernel + rw [delay_eq_stepApprox σ n htbound] + +theorem delay_integral_of_one_le (σ : ℝ) {u : ℝ} (hu : 1 ≤ u) : + delay σ u = 1 + σ * ∫ t in (1 : ℝ)..u, delay σ (t - 1) / t := by + rw [delay_integral σ u, max_eq_right hu] + apply congrArg (fun I : ℝ => 1 + σ * I) + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le hu] at ht + simp only [kernel, max_eq_right ht.1] + +theorem delay_hasDerivAt (σ : ℝ) {u : ℝ} (hu : 1 < u) : + HasDerivAt (delay σ) (σ * delay σ (u - 1) / u) u := by + have hk := kernel_continuous (delay_continuous σ) + have hInt := intervalIntegral.integral_hasDerivAt_right (hk.intervalIntegrable 1 u) + hk.aestronglyMeasurable.stronglyMeasurableAtFilter hk.continuousAt + have hPrim := (hInt.const_mul σ).const_add 1 + have heq : delay σ =ᶠ[𝓝 u] (fun x => 1 + σ * ∫ t in (1 : ℝ)..x, kernel (delay σ) t) := by + filter_upwards [Ioi_mem_nhds hu] with x hx + rw [delay_integral σ x, max_eq_right hx.le] + have hD := hPrim.congr_of_eventuallyEq heq + simpa only [kernel, max_eq_right hu.le, mul_div_assoc] using hD + +end NumberTheoryLean.DelayConstruction + +end + +section + +namespace NumberTheoryLean.DelayUniqueness + +theorem shifted_unique_upto (σ : ℝ) (F G : ℝ → ℝ) + (hFinit : ∀ u : ℝ, 1 ≤ u → u ≤ 2 → F u = 1) + (hGinit : ∀ u : ℝ, 1 ≤ u → u ≤ 2 → G u = 1) + (hFrec : ∀ u : ℝ, 2 < u → F u = 1 + σ * ∫ t in (1 : ℝ)..u - 1, F t / t) + (hGrec : ∀ u : ℝ, 2 < u → G u = 1 + σ * ∫ t in (1 : ℝ)..u - 1, G t / t) + (n : ℕ) : ∀ u : ℝ, 1 ≤ u → u ≤ (n : ℝ) + 2 → F u = G u := by + induction n with + | zero => + intro u hu1 hu2 + have hu : u ≤ 2 := by simpa only [Nat.cast_zero, zero_add] using hu2 + rw [hFinit u hu1 hu, hGinit u hu1 hu] + | succ n ih => + intro u hu1 hun + by_cases hu2 : u ≤ 2 + · rw [hFinit u hu1 hu2, hGinit u hu1 hu2] + · have hu : 2 < u := lt_of_not_ge hu2 + rw [hFrec u hu, hGrec u hu] + apply congrArg (fun I : ℝ => 1 + σ * I) + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le (by linarith : (1 : ℝ) ≤ u - 1)] at ht + change F t / t = G t / t + rw [ih t ht.1 (by push_cast at hun; linarith [ht.2])] + +theorem shifted_unique (σ : ℝ) (F G : ℝ → ℝ) + (hFinit : ∀ u : ℝ, 1 ≤ u → u ≤ 2 → F u = 1) + (hGinit : ∀ u : ℝ, 1 ≤ u → u ≤ 2 → G u = 1) + (hFrec : ∀ u : ℝ, 2 < u → F u = 1 + σ * ∫ t in (1 : ℝ)..u - 1, F t / t) + (hGrec : ∀ u : ℝ, 2 < u → G u = 1 + σ * ∫ t in (1 : ℝ)..u - 1, G t / t) + {u : ℝ} (hu : 1 ≤ u) : F u = G u := by + apply shifted_unique_upto σ F G hFinit hGinit hFrec hGrec ⌈u⌉₊ u hu + have h := Nat.le_ceil u + linarith + +end NumberTheoryLean.DelayUniqueness + +end + +section + +namespace NumberTheoryLean.Dickman + +open MeasureTheory Filter +open scoped Topology + +noncomputable def rho : ℝ → ℝ := DelayConstruction.delay (-1) + +theorem rho_continuous : Continuous rho := DelayConstruction.delay_continuous (-1) + +theorem rho_initial {u : ℝ} (hu : u ≤ 1) : rho u = 1 := DelayConstruction.delay_initial (-1) hu + +theorem rho_hasDerivAt {u : ℝ} (hu : 1 < u) : + HasDerivAt rho (-rho (u - 1) / u) u := by + simpa only [rho, neg_one_mul] using DelayConstruction.delay_hasDerivAt (-1) hu + +theorem rho_delay_equation {u : ℝ} (hu : 1 < u) : u * deriv rho u = -rho (u - 1) := by + rw [(rho_hasDerivAt hu).deriv] + field_simp + +theorem rho_integral {u : ℝ} (hu : 1 ≤ u) : + rho u = 1 - ∫ t in (1 : ℝ)..u, rho (t - 1) / t := by + simpa only [rho, neg_one_mul, sub_eq_add_neg] using DelayConstruction.delay_integral_of_one_le (-1) hu + +theorem rho_first_interval {u : ℝ} (hu1 : 1 ≤ u) (hu2 : u ≤ 2) : rho u = 1 - Real.log u := by + rw [rho_integral hu1] + have hInt : (∫ t in (1 : ℝ)..u, rho (t - 1) / t) = ∫ t in (1 : ℝ)..u, 1 / t := by + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le hu1] at ht + change rho (t - 1) / t = 1 / t + rw [rho_initial (by linarith [ht.2])] + rw [hInt, integral_one_div_of_pos (by norm_num) (by linarith), div_one] + +noncomputable def primitive (u : ℝ) : ℝ := ∫ t in (0 : ℝ)..u, rho t + +theorem primitive_continuous : Continuous primitive := + (intervalIntegral.differentiable_integral_of_continuous rho_continuous).continuous + +theorem primitive_hasDerivAt (u : ℝ) : HasDerivAt primitive (rho u) u := + intervalIntegral.integral_hasDerivAt_right (rho_continuous.intervalIntegrable 0 u) + rho_continuous.aestronglyMeasurable.stronglyMeasurableAtFilter rho_continuous.continuousAt + +noncomputable def identityDifference (u : ℝ) : ℝ := u * rho u - (primitive u - primitive (u - 1)) + +theorem identityDifference_continuous : Continuous identityDifference := + (continuous_id.mul rho_continuous).sub (primitive_continuous.sub + (primitive_continuous.comp (continuous_id.sub continuous_const))) + +theorem identityDifference_hasDerivAt {u : ℝ} (hu : 1 < u) : + HasDerivAt identityDifference 0 u := by + have hProd := (hasDerivAt_id u).mul (rho_hasDerivAt hu) + have hShift := (primitive_hasDerivAt (u - 1)).comp u ((hasDerivAt_id u).sub_const 1) + have hDiff := hProd.sub ((primitive_hasDerivAt u).sub hShift) + have hvalue : (1 * rho u + id u * (-rho (u - 1) / u) - (rho u - rho (u - 1) * 1)) = 0 := by + dsimp only [id_eq] + field_simp + ring + rw [hvalue] at hDiff + convert! hDiff using 1 + +theorem identityDifference_one : identityDifference 1 = 0 := by + have hp1 : primitive 1 = 1 := by + unfold primitive + calc + (∫ t in (0 : ℝ)..1, rho t) = ∫ _t in (0 : ℝ)..1, (1 : ℝ) := by + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le (by norm_num : (0 : ℝ) ≤ 1)] at ht + exact rho_initial ht.2 + _ = 1 := by simp + have hp0 : primitive 0 = 0 := by simp [primitive] + simp only [identityDifference, rho_initial (le_refl 1), one_mul, sub_self, hp1, hp0, sub_zero] + +theorem rho_unit_integral {u : ℝ} (hu : 1 ≤ u) : + u * rho u = ∫ t in u - 1..u, rho t := by + have hzero : identityDifference u = 0 := by + have hFTC := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hu + identityDifference_continuous.continuousOn + (fun x hx => identityDifference_hasDerivAt hx.1) + (intervalIntegrable_const : IntervalIntegrable (fun _ : ℝ => (0 : ℝ)) volume 1 u) + simpa only [intervalIntegral.integral_zero, identityDifference_one, sub_zero] using hFTC.symm + have hInt := intervalIntegral.integral_add_adjacent_intervals + (rho_continuous.intervalIntegrable (μ := volume) 0 (u - 1)) (rho_continuous.intervalIntegrable (μ := volume) (u - 1) u) + change primitive (u - 1) + (∫ t in u - 1..u, rho t) = primitive u at hInt + unfold identityDifference at hzero + linarith + +theorem rho_antitone_segment (b : ℝ) + (hprev : ∀ t : ℝ, 0 ≤ t → t ≤ b - 1 → 0 ≤ rho t) : AntitoneOn rho (Set.Icc 1 b) := by + apply antitoneOn_of_deriv_nonpos (convex_Icc 1 b) rho_continuous.continuousOn + · intro x hx + rw [interior_Icc] at hx + exact (rho_hasDerivAt hx.1).differentiableAt.differentiableWithinAt + · intro x hx + rw [interior_Icc] at hx + rw [(rho_hasDerivAt hx.1).deriv] + exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (hprev (x - 1) (by linarith [hx.1]) + (by linarith [hx.2]))) (by linarith [hx.1]) + +theorem rho_nonneg_upto (n : ℕ) : ∀ u : ℝ, 0 ≤ u → u ≤ (n : ℝ) + 1 → 0 ≤ rho u := by + induction n with + | zero => + intro u _ hu + rw [rho_initial (by simpa only [Nat.cast_zero, zero_add] using hu)] + norm_num + | succ n ih => + intro u hu0 hu + have hub : u ≤ (n : ℝ) + 2 := by push_cast at hu; linarith + have hmono : AntitoneOn rho (Set.Icc 1 ((n : ℝ) + 2)) := + rho_antitone_segment _ (fun t ht0 htb => ih t ht0 (by linarith)) + by_cases hu1 : u ≤ 1 + · rw [rho_initial hu1]; norm_num + · have hu1' : 1 < u := lt_of_not_ge hu1 + have hpoint : ∀ t ∈ Set.Icc (u - 1) u, rho u ≤ rho t := by + intro t ht + by_cases ht1 : 1 ≤ t + · exact hmono ⟨ht1, ht.2.trans hub⟩ ⟨hu1'.le, hub⟩ ht.2 + · rw [rho_initial (le_of_not_ge ht1)] + have h := hmono ⟨le_rfl, by linarith⟩ ⟨hu1'.le, hub⟩ hu1'.le + simpa only [rho_initial (le_refl 1)] using h + have hint := intervalIntegral.integral_mono_on (by linarith : u - 1 ≤ u) + (intervalIntegrable_const : IntervalIntegrable (fun _ : ℝ => rho u) volume (u - 1) u) + (rho_continuous.intervalIntegrable (μ := volume) (u - 1) u) hpoint + have hconst : (∫ _t in u - 1..u, rho u) = rho u := by simp + rw [hconst, ← rho_unit_integral hu1'.le] at hint + have hprod : 0 ≤ (u - 1) * rho u := by nlinarith + exact nonneg_of_mul_nonneg_right hprod (by linarith) + +theorem rho_nonneg (u : ℝ) : 0 ≤ rho u := by + by_cases hu : u ≤ 1 + · rw [rho_initial hu]; norm_num + · apply rho_nonneg_upto ⌈u⌉₊ u (by linarith) + have h := Nat.le_ceil u + linarith + +theorem rho_antitone : Antitone rho := by + intro x y hxy + by_cases hy : y ≤ 1 + · rw [rho_initial hy, rho_initial (hxy.trans hy)] + · have hy1 : 1 < y := lt_of_not_ge hy + have hmono := rho_antitone_segment y (fun t _ _ => rho_nonneg t) + by_cases hx : x ≤ 1 + · rw [rho_initial hx] + have h := hmono ⟨le_rfl, hy1.le⟩ ⟨hy1.le, le_rfl⟩ hy1.le + simpa only [rho_initial (le_refl 1)] using h + · exact hmono ⟨le_of_not_ge hx, hxy⟩ ⟨hy1.le, le_rfl⟩ hxy + +theorem rho_half_step {u : ℝ} (hu : 1 ≤ u) : rho (u - 1 / 2) ≤ 2 * u * rho u := by + have hconst := intervalIntegral.integral_mono_on (by linarith : u - 1 ≤ u - 1 / 2) + (intervalIntegrable_const : IntervalIntegrable (fun _ : ℝ => rho (u - 1 / 2)) volume (u - 1) (u - 1 / 2)) + (rho_continuous.intervalIntegrable (μ := volume) (u - 1) (u - 1 / 2)) + (fun t ht => rho_antitone ht.2) + have hvalue : (∫ _t in u - 1..u - 1 / 2, rho (u - 1 / 2)) = (1 / 2 : ℝ) * rho (u - 1 / 2) := by + rw [intervalIntegral.integral_const] + simp only [smul_eq_mul] + ring + rw [hvalue] at hconst + have hsub := intervalIntegral.integral_mono_interval (μ := volume) + (a := u - 1) (b := u - 1 / 2) (c := u - 1) (d := u) + le_rfl (by linarith) (by linarith) + (Filter.Eventually.of_forall (fun t => rho_nonneg t)) + (rho_continuous.intervalIntegrable (μ := volume) (u - 1) u) + rw [← rho_unit_integral hu] at hsub + nlinarith + +theorem rho_lower_comparison {u : ℝ} (hu : 2 ≤ u) : rho (u - 1) ≤ 4 * u ^ 2 * rho u := by + have h1 := rho_half_step (u := u) (by linarith) + have h2 := rho_half_step (u := u - 1 / 2) (by linarith) + have harg : u - 1 / 2 - 1 / 2 = u - 1 := by ring + rw [harg] at h2 + calc + rho (u - 1) ≤ 2 * (u - 1 / 2) * rho (u - 1 / 2) := h2 + _ ≤ 2 * (u - 1 / 2) * (2 * u * rho u) := + mul_le_mul_of_nonneg_left h1 (by linarith) + _ = (4 * u * (u - 1 / 2)) * rho u := by ring + _ ≤ 4 * u ^ 2 * rho u := mul_le_mul_of_nonneg_right (by nlinarith) (rho_nonneg u) + +theorem rho_pos_initial {u : ℝ} (hu : u ≤ 2) : 0 < rho u := by + by_cases hu1 : u ≤ 1 + · rw [rho_initial hu1]; norm_num + · have hu1' : 1 < u := lt_of_not_ge hu1 + rw [rho_first_interval hu1'.le hu] + have hlog2 : Real.log 2 < 1 := by + have h := Real.log_lt_log (by norm_num : (0 : ℝ) < 2) Real.exp_one_gt_two + simpa only [Real.log_exp] using h + have hlogu := Real.log_le_log (show 0 < u by linarith) hu + linarith + +theorem rho_pos_upto (n : ℕ) : ∀ u : ℝ, u ≤ (n : ℝ) + 2 → 0 < rho u := by + induction n with + | zero => intro u hu; exact rho_pos_initial (by simpa only [Nat.cast_zero, zero_add] using hu) + | succ n ih => + intro u hu + by_cases hu2 : u ≤ 2 + · exact rho_pos_initial hu2 + · have hu2' : 2 < u := lt_of_not_ge hu2 + have hprev : 0 < rho (u - 1) := ih (u - 1) (by push_cast at hu; linarith) + have hbound := rho_lower_comparison hu2'.le + by_contra hnot + have hnonpos : rho u ≤ 0 := le_of_not_gt hnot + have hprod := mul_nonpos_of_nonneg_of_nonpos (show 0 ≤ 4 * u ^ 2 by positivity) hnonpos + linarith + +theorem rho_pos (u : ℝ) : 0 < rho u := by + apply rho_pos_upto ⌈u⌉₊ u + have h := Nat.le_ceil u + linarith + +theorem rho_upper_comparison {u : ℝ} (hu : 1 ≤ u) : u * rho u ≤ rho (u - 1) := by + have hInt := intervalIntegral.integral_mono_on (by linarith : u - 1 ≤ u) + (rho_continuous.intervalIntegrable (μ := volume) (u - 1) u) + (intervalIntegrable_const : IntervalIntegrable (fun _ : ℝ => rho (u - 1)) volume (u - 1) u) + (fun t ht => rho_antitone ht.1) + have hconst : (∫ _t in u - 1..u, rho (u - 1)) = rho (u - 1) := by simp + rw [hconst, ← rho_unit_integral hu] at hInt + exact hInt + +theorem rho_ratio_bounds {u : ℝ} (hu : 2 ≤ u) : + 1 / (4 * u ^ 2) ≤ rho u / rho (u - 1) ∧ rho u / rho (u - 1) ≤ 1 / u := by + have hprev : 0 < rho (u - 1) := rho_pos _ + have hu0 : 0 < u := by linarith + constructor + · apply (div_le_div_iff₀ (show 0 < 4 * u ^ 2 by positivity) hprev).mpr + have h := rho_lower_comparison hu + nlinarith + · apply (div_le_div_iff₀ hprev hu0).mpr + have h := rho_upper_comparison (u := u) (by linarith) + nlinarith + +end NumberTheoryLean.Dickman + +end + +section + +namespace NumberTheoryLean.DickmanDecay + +open MeasureTheory Filter +open scoped Topology +open Dickman + +noncomputable def hazard (u : ℝ) : ℝ := rho (u - 1) / (u * rho u) + +theorem hazard_eq_neg_deriv {u : ℝ} (hu : 1 < u) : hazard u = -deriv rho u / rho u := by + rw [(rho_hasDerivAt hu).deriv] + unfold hazard + field_simp + +theorem hazard_ge_one {u : ℝ} (hu : 2 ≤ u) : 1 ≤ hazard u := by + unfold hazard + apply (le_div_iff₀ (mul_pos (show 0 < u by linarith) (rho_pos u))).mpr + simpa only [one_mul] using rho_upper_comparison (u := u) (by linarith) + +theorem deriv_le_of_hazard {u rate : ℝ} (hu : 1 < u) (hrate : rate ≤ hazard u) : + deriv rho u ≤ -rate * rho u := by + rw [hazard_eq_neg_deriv hu] at hrate + have h := (le_div_iff₀ (rho_pos u)).mp hrate + linarith + +theorem rho_exponential_comparison (T rate a b : ℝ) (hT : 2 ≤ T) + (htail : ∀ t : ℝ, T ≤ t → rate ≤ hazard t) (ha : T ≤ a) (hab : a ≤ b) : + rho b ≤ rho a * Real.exp (-rate * (b - a)) := by + let H : ℝ → ℝ := fun t => Real.exp (rate * t) * rho t + have hCont : Continuous H := + (Real.continuous_exp.comp (continuous_const.mul continuous_id)).mul rho_continuous + have hDeriv : ∀ t ∈ Set.Ioo a b, + HasDerivAt H (Real.exp (rate * t) * (deriv rho t + rate * rho t)) t := by + intro t ht + have ht1 : 1 < t := by linarith [ht.1] + have hExp := ((hasDerivAt_id t).const_mul rate).exp + have hRho := (rho_hasDerivAt ht1).differentiableAt.hasDerivAt + have hProd := hExp.mul hRho + convert! hProd using 1 + simp only [id_eq, mul_one] + ring + have hMono : AntitoneOn H (Set.Icc a b) := by + apply antitoneOn_of_deriv_nonpos (convex_Icc a b) hCont.continuousOn + · intro t ht + rw [interior_Icc] at ht + exact (hDeriv t ht).differentiableAt.differentiableWithinAt + · intro t ht + rw [interior_Icc] at ht + rw [(hDeriv t ht).deriv] + apply mul_nonpos_of_nonneg_of_nonpos (Real.exp_pos _).le + have hd := deriv_le_of_hazard (u := t) (rate := rate) (by linarith [ht.1]) (htail t (by linarith [ht.1])) + linarith + have hHb : H b ≤ H a := hMono ⟨le_rfl, hab⟩ ⟨hab, le_rfl⟩ hab + have hQ : rho b ≤ Real.exp (rate * a) * rho a / Real.exp (rate * b) := by + apply (le_div_iff₀ (Real.exp_pos _)).mpr + dsimp [H] at hHb + nlinarith + calc + rho b ≤ Real.exp (rate * a) * rho a / Real.exp (rate * b) := hQ + _ = rho a * (Real.exp (rate * a) / Real.exp (rate * b)) := by ring + _ = rho a * Real.exp (-rate * (b - a)) := by rw [← Real.exp_sub]; congr 1; congr 1; ring + +theorem unit_exponential_integral (rate u : ℝ) (hrate : rate ≠ 0) : + (∫ t in u - 1..u, Real.exp (-rate * (t - (u - 1)))) = (1 - Real.exp (-rate)) / rate := by + rw [intervalIntegral.integral_comp_sub_right (fun t : ℝ => Real.exp (-rate * t)) (u - 1)] + simp only [sub_self, sub_sub_cancel] + rw [intervalIntegral.integral_comp_mul_left Real.exp (neg_ne_zero.mpr hrate), integral_exp] + simp only [mul_zero, mul_one, Real.exp_zero, smul_eq_mul] + field_simp + ring + +theorem hazard_bootstrap (T rate u : ℝ) (hT : 2 ≤ T) (hrate : 0 < rate) + (htail : ∀ t : ℝ, T ≤ t → rate ≤ hazard t) (hu : T + 1 ≤ u) : + rate / (1 - Real.exp (-rate)) ≤ hazard u := by + have hu1 : 1 ≤ u := by linarith + have hcomp : ∀ t ∈ Set.Icc (u - 1) u, + rho t ≤ rho (u - 1) * Real.exp (-rate * (t - (u - 1))) := by + intro t ht + exact rho_exponential_comparison T rate (u - 1) t hT htail (by linarith) ht.1 + have hCont : Continuous (fun t : ℝ => rho (u - 1) * Real.exp (-rate * (t - (u - 1)))) := by fun_prop + have hInt := intervalIntegral.integral_mono_on (by linarith : u - 1 ≤ u) + (rho_continuous.intervalIntegrable (μ := volume) (u - 1) u) + (hCont.intervalIntegrable (μ := volume) (u - 1) u) hcomp + rw [← rho_unit_integral hu1, intervalIntegral.integral_const_mul, + unit_exponential_integral rate u (ne_of_gt hrate)] at hInt + have he : 0 < 1 - Real.exp (-rate) := sub_pos.mpr (Real.exp_lt_one_iff.mpr (by linarith)) + unfold hazard + apply (div_le_div_iff₀ he (mul_pos (show 0 < u by linarith) (rho_pos u))).mpr + rw [← mul_div_assoc] at hInt + have hmul := (le_div_iff₀ hrate).mp hInt + nlinarith + +theorem bootstrap_uniform_gain (L rate : ℝ) (hrate1 : 1 ≤ rate) (hrateL : rate ≤ L) : + rate + Real.exp (-L) ≤ rate / (1 - Real.exp (-rate)) := by + have hrate0 : 0 < rate := by linarith + have he0 : 0 < Real.exp (-rate) := Real.exp_pos _ + have hd0 : 0 < Real.exp (-L) := Real.exp_pos _ + have hle : Real.exp (-L) ≤ Real.exp (-rate) := Real.exp_le_exp.mpr (by linarith) + have hden : 0 < 1 - Real.exp (-rate) := sub_pos.mpr (Real.exp_lt_one_iff.mpr (by linarith)) + apply (le_div_iff₀ hden).mpr + nlinarith [mul_nonneg (show 0 ≤ rate - 1 by linarith) he0.le, mul_nonneg hd0.le he0.le] + +theorem hazard_step_bound (L : ℝ) (hL : 1 ≤ L) (n : ℕ) : + ∀ u : ℝ, (n : ℝ) + 2 ≤ u → + min L (1 + (n : ℝ) * Real.exp (-L)) ≤ hazard u := by + induction n with + | zero => + intro u hu + simp only [Nat.cast_zero, zero_mul, add_zero, min_eq_right hL] + exact hazard_ge_one (by simpa only [Nat.cast_zero, zero_add] using hu) + | succ n ih => + intro u hu + let d := Real.exp (-L) + let rate := min L (1 + (n : ℝ) * d) + have hd : 0 < d := Real.exp_pos _ + have hr1 : 1 ≤ rate := le_min hL (by have hn := Nat.cast_nonneg (α := ℝ) n; nlinarith) + have hrL : rate ≤ L := min_le_left _ _ + have htail : ∀ t : ℝ, (n : ℝ) + 2 ≤ t → rate ≤ hazard t := fun t ht => ih t ht + have hboost := hazard_bootstrap ((n : ℝ) + 2) rate u + (by have hn := Nat.cast_nonneg (α := ℝ) n; linarith) (by linarith) htail + (by push_cast at hu; linarith) + have hgain := bootstrap_uniform_gain L rate hr1 hrL + have hstep : min L (1 + ((n + 1 : ℕ) : ℝ) * d) ≤ rate + d := by + by_cases hcase : L ≤ 1 + (n : ℝ) * d + · have hr : rate = L := min_eq_left hcase + rw [hr] + exact (min_le_left _ _).trans (by linarith) + · have hr : rate = 1 + (n : ℝ) * d := min_eq_right (le_of_not_ge hcase) + rw [hr] + have hm := min_le_right L (1 + ((n + 1 : ℕ) : ℝ) * d) + push_cast at hm ⊢ + linarith + exact hstep.trans (hgain.trans hboost) + +theorem exists_hazard_tail (rate : ℝ) : + ∃ T : ℝ, 2 ≤ T ∧ ∀ u : ℝ, T ≤ u → rate ≤ hazard u := by + let L := max 1 rate + let d := Real.exp (-L) + have hL : 1 ≤ L := le_max_left _ _ + have hd : 0 < d := Real.exp_pos _ + obtain ⟨n, hn⟩ := exists_nat_ge ((L - 1) / d) + have hreach : L ≤ 1 + (n : ℝ) * d := by + have h := (div_le_iff₀ hd).mp hn + linarith + refine ⟨(n : ℝ) + 2, by have h := Nat.cast_nonneg (α := ℝ) n; linarith, ?_⟩ + intro u hu + have h := hazard_step_bound L hL n u hu + rw [min_eq_left hreach] at h + exact (le_max_right 1 rate).trans h + +theorem negative_logDeriv_tail (rate : ℝ) : + ∃ T : ℝ, 2 ≤ T ∧ ∀ u : ℝ, T ≤ u → rate ≤ -deriv rho u / rho u := by + obtain ⟨T, hT, htail⟩ := exists_hazard_tail rate + refine ⟨T, hT, ?_⟩ + intro u hu + rw [← hazard_eq_neg_deriv (by linarith : 1 < u)] + exact htail u hu + +theorem hazard_tendsto_atTop : Tendsto hazard atTop atTop := by + apply tendsto_atTop.mpr + intro rate + obtain ⟨T, _, htail⟩ := exists_hazard_tail rate + exact eventually_atTop.mpr ⟨T, htail⟩ + +theorem rho_exponential_majorant (rate : ℝ) : + ∃ C : ℝ, 0 < C ∧ ∃ T : ℝ, 2 ≤ T ∧ ∀ u : ℝ, T ≤ u → + rho u ≤ C * Real.exp (-rate * u) := by + obtain ⟨T, hT, htail⟩ := exists_hazard_tail rate + refine ⟨rho T * Real.exp (rate * T), mul_pos (rho_pos T) (Real.exp_pos _), T, hT, ?_⟩ + intro u hu + have h := rho_exponential_comparison T rate T u hT htail le_rfl hu + have heq : Real.exp (-rate * (u - T)) = Real.exp (rate * T) * Real.exp (-rate * u) := by + rw [← Real.exp_add] + congr 1 + ring + rw [heq] at h + simpa only [mul_assoc] using h + +theorem rho_faster_than_exponential (rate : ℝ) : + Tendsto (fun u : ℝ => Real.exp (rate * u) * rho u) atTop (𝓝 0) := by + obtain ⟨C, hC, T, _, hbound⟩ := rho_exponential_majorant (rate + 1) + have hUpper : (fun u : ℝ => Real.exp (rate * u) * rho u) ≤ᶠ[atTop] + (fun u => C * Real.exp (-u)) := by + apply eventually_atTop.mpr + refine ⟨T, ?_⟩ + intro u hu + have h := mul_le_mul_of_nonneg_left (hbound u hu) (Real.exp_pos (rate * u)).le + have heq : Real.exp (rate * u) * (C * Real.exp (-(rate + 1) * u)) = C * Real.exp (-u) := by + calc + _ = C * (Real.exp (rate * u) * Real.exp (-(rate + 1) * u)) := by ring + _ = _ := by rw [← Real.exp_add]; congr 1; congr 1; ring + rw [heq] at h + exact h + have hLower : (0 : ℝ → ℝ) ≤ᶠ[atTop] (fun u : ℝ => Real.exp (rate * u) * rho u) := + Filter.Eventually.of_forall (fun u => mul_nonneg (Real.exp_pos _).le (rho_nonneg u)) + have hLimit : Tendsto (fun u : ℝ => C * Real.exp (-u)) atTop (𝓝 0) := by + simpa only [mul_zero] using Real.tendsto_exp_neg_atTop_nhds_zero.const_mul C + exact squeeze_zero' hLower hUpper hLimit + +theorem rho_tendsto_zero : Tendsto rho atTop (𝓝 0) := by + simpa only [zero_mul, Real.exp_zero, one_mul] using rho_faster_than_exponential 0 + +end NumberTheoryLean.DickmanDecay + +end + +section + +namespace NumberTheoryLean.DickmanFiniteDecay + +open Dickman + +theorem rho_le_one (u : ℝ) : rho u ≤ 1 := by + by_cases hu : u ≤ 1 + · rw [rho_initial hu] + · have h := rho_antitone (le_of_lt (lt_of_not_ge hu)) + simpa only [rho_initial (le_refl (1:ℝ))] using h + +theorem rho_step_power {t u : ℝ} (ht : 1 ≤ t) (htu : t ≤ u) (n : ℕ) : + t^n*rho (u+(n:ℝ)) ≤ rho u := by + induction n with + | zero => simp + | succ n ih => + have hn : 0 ≤ (n:ℝ) := Nat.cast_nonneg n + have hh := rho_upper_comparison (u := u+(n:ℝ)+1) (by linarith) + have hs : t*rho (u+(n:ℝ)+1) ≤ rho (u+(n:ℝ)) := by + have hm := mul_le_mul_of_nonneg_right (show t ≤ u+(n:ℝ)+1 by linarith) + (rho_nonneg (u+(n:ℝ)+1)) + simp only [add_sub_cancel_right] at hh + exact hm.trans hh + have hmul := mul_le_mul_of_nonneg_left hs (pow_nonneg (by linarith : 0 ≤ t) n) + push_cast + rw [pow_succ] + simpa only [add_assoc,mul_assoc] using hmul.trans ih + +theorem rho_half_power {u : ℝ} (hu : 2 ≤ u) : + rho u ≤ 1/(u/2)^⌊u/2⌋₊ := by + have hu0 : 0 < u := by linarith + have hf := Nat.floor_le (by linarith : 0 ≤ u/2) + have hh := rho_step_power (t := u/2) (u := u-(⌊u/2⌋₊:ℝ)) + (by linarith) (by linarith) ⌊u/2⌋₊ + simp only [sub_add_cancel] at hh + apply (le_div_iff₀ (pow_pos (by linarith : 0 < u/2) _)).mpr + rw [mul_comm] + exact hh.trans (rho_le_one _) + +theorem rho_log_decay {u : ℝ} (hu : 8 ≤ u) : + rho u ≤ Real.exp (-(1/16:ℝ)*u*Real.log (u+2)) := by + have hu0 : 0 < u := by linarith + have ht0 : 0 < u/2 := by linarith + have hn : u/4 ≤ (⌊u/2⌋₊:ℝ) := by + have hf := Nat.lt_floor_add_one (u/2) + linarith + have hl0 : 0 ≤ Real.log u := Real.log_nonneg (by linarith) + have hlh : Real.log u/2 ≤ Real.log (u/2) := by + have hm := Real.log_le_log hu0 (show u ≤ (u/2)^2 by nlinarith) + rw [Real.log_pow] at hm + norm_num only [Nat.cast_ofNat] at hm + linarith + have hl2 : Real.log (u+2) ≤ 2*Real.log u := by + have hm := Real.log_le_log (show 0 < u+2 by linarith) (show u+2 ≤ u^2 by nlinarith) + simpa only [Real.log_pow,Nat.cast_ofNat] using hm + have hpow : (1/16:ℝ)*u*Real.log (u+2) ≤ (⌊u/2⌋₊:ℝ)*Real.log (u/2) := by + have hm := mul_le_mul hn hlh (by linarith : 0 ≤ Real.log u/2) (Nat.cast_nonneg ⌊u/2⌋₊) + nlinarith [mul_le_mul_of_nonneg_left hl2 hu0.le] + calc + _ ≤ 1/(u/2)^⌊u/2⌋₊ := rho_half_power (by linarith) + _ = Real.exp (-(⌊u/2⌋₊:ℝ)*Real.log (u/2)) := by + rw [neg_mul,Real.exp_neg,Real.exp_nat_mul,Real.exp_log ht0] + exact one_div _ + _ ≤ _ := Real.exp_le_exp.mpr (by nlinarith) + +end NumberTheoryLean.DickmanFiniteDecay + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/DickmanMoments.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/DickmanMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d8fc45a17a9a06b5d15656bb6d138b7a8a1fe6c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/DickmanMoments.lean @@ -0,0 +1,182 @@ +import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral +import Mathlib.MeasureTheory.Function.JacobianOneDim +import OAI.NumberTheory.Jacobsthal.Analysis.WeightFutureIntegrals + +namespace OAI + +namespace Erdos970 + +section + +open Set Filter MeasureTheory +open scoped Topology +namespace Erdos970Dependency.StandardBoundary +open NumberTheoryLean.Dickman NumberTheoryLean.DickmanDecay + +theorem rho_exp_bound {x : ℝ} (hx : 0 ≤ x) : rho x ≤ Real.exp 2 * Real.exp (-x) := by + have hle (y : ℝ) (hy : 0 ≤ y) : rho y ≤ 1 := by + simpa only [rho_initial (by norm_num : (0:ℝ) ≤ 1)] using rho_antitone hy + by_cases h2 : 2 ≤ x + · have h := rho_exponential_comparison 2 1 2 x le_rfl + (fun t ht => hazard_ge_one ht) le_rfl h2 + have h' := mul_le_mul_of_nonneg_right (hle 2 (by norm_num)) (Real.exp_pos (-(1:ℝ)*(x-2))).le + have he : Real.exp (-(1:ℝ)*(x-2)) = Real.exp 2 * Real.exp (-x) := by + rw [← Real.exp_add]; congr 1; ring + simpa only [one_mul, he] using h.trans h' + · apply (hle x hx).trans + rw [← Real.exp_add] + exact Real.one_le_exp (by linarith) + +theorem rho_moment_integrable (n : ℕ) : + IntegrableOn (fun x : ℝ => x^n*rho x) (Ioi 0) := by + have hg : IntegrableOn (fun x : ℝ => x^n*Real.exp (-x)) (Ioi 0) := by + have h := integrableOn_rpow_mul_exp_neg_mul_rpow (s := (n:ℝ)) (p := 1) + (by have hn := Nat.cast_nonneg (α := ℝ) n; linarith) (by norm_num) (by norm_num : (0:ℝ)<1) + simpa only [Real.rpow_natCast,Real.rpow_one,neg_one_mul] using! h + apply (hg.const_mul (Real.exp 2)).mono' + (((continuous_id.pow n).mul rho_continuous).aestronglyMeasurable.restrict) + filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx + have hx0 : 0 ≤ x := le_of_lt hx + change ‖x^n*rho x‖ ≤ Real.exp 2*(x^n*Real.exp (-x)) + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (pow_nonneg hx0 n),abs_of_nonneg (rho_nonneg x)] + calc + _ ≤ x^n*(Real.exp 2*Real.exp (-x)) := mul_le_mul_of_nonneg_left (rho_exp_bound hx0) (pow_nonneg hx0 n) + _ = Real.exp 2*(x^n*Real.exp (-x)) := by ring + +theorem rho_moment_tendsto_zero (n : ℕ) : + Tendsto (fun x : ℝ => x^n*rho x) atTop (𝓝 0) := by + have hl := (Real.tendsto_pow_mul_exp_neg_atTop_nhds_zero n).const_mul (Real.exp 2) + simp only [mul_zero] at hl + apply squeeze_zero' ?_ ?_ hl + · filter_upwards [eventually_ge_atTop (0:ℝ)] with x hx + exact mul_nonneg (pow_nonneg hx n) (rho_nonneg x) + · filter_upwards [eventually_ge_atTop (0:ℝ)] with x hx + calc + _ ≤ x^n*(Real.exp 2*Real.exp (-x)) := mul_le_mul_of_nonneg_left (rho_exp_bound hx) (pow_nonneg hx n) + _ = Real.exp 2*(x^n*Real.exp (-x)) := by ring + +theorem halfline_shift (a b : ℝ) (g : ℝ → ℝ) : + ((∫ x in Ioi (a+b),g x) = ∫ x in Ioi a,g (x+b)) ∧ + (IntegrableOn g (Ioi (a+b)) ↔ IntegrableOn (fun x => g (x+b)) (Ioi a)) := by + have hd : ∀ x ∈ Ioi a, HasDerivWithinAt (fun y : ℝ => y+b) 1 (Ioi a) x := + fun x _ => ((hasDerivAt_id x).add_const b).hasDerivWithinAt + have hinj : InjOn (fun y : ℝ => y+b) (Ioi a) := fun x _ y _ h => by linarith + have him : (fun y : ℝ => y+b) '' Ioi a = Ioi (a+b) := by + ext x + constructor + · rintro ⟨y,hy,rfl⟩; change a < y at hy; change a+b < y+b; linarith + · intro hx; refine ⟨x-b,?_,by ring⟩; change a+b < x at hx; change a < x-b; linarith + constructor + · have h := integral_image_eq_integral_abs_deriv_smul measurableSet_Ioi hd hinj g + simpa only [him,abs_one,one_smul] using h + · have h := integrableOn_image_iff_integrableOn_abs_deriv_smul measurableSet_Ioi hd hinj g + simpa only [him,abs_one,one_smul] using h + +end Erdos970Dependency.StandardBoundary + +end + +section + +open Set Filter MeasureTheory +open scoped Topology +namespace Erdos970Dependency.StandardBoundary +open NumberTheoryLean.Dickman NumberTheoryLean.DickmanDecay + +theorem rho_quotient_integral : + IntegrableOn (fun y : ℝ => rho y/(y+1)) (Ioi 0) ∧ + (∫ y in Ioi 0,rho y/(y+1)) = 1 := by + have hc : Continuous (fun y : ℝ => rho (y+1)) := rho_continuous.comp (continuous_id.add continuous_const) + have hd : ∀ y ∈ Ioi (0:ℝ), HasDerivAt (fun x : ℝ => rho (x+1)) (-(rho y/(y+1))) y := by + intro y hy + have hh := (rho_hasDerivAt (u := y+1) (by change 0 < y at hy; linarith)).comp y ((hasDerivAt_id y).add_const 1) + simpa only [add_sub_cancel_right,mul_one,neg_div] using! hh + have hn : ∀ y ∈ Ioi (0:ℝ), -(rho y/(y+1)) ≤ 0 := by + intro y hy + exact neg_nonpos.mpr (div_nonneg (rho_nonneg y) (by change 0 < y at hy; linarith)) + have hl : Tendsto (fun x : ℝ => rho (x+1)) atTop (𝓝 0) := + rho_tendsto_zero.comp (tendsto_atTop_add_const_right atTop 1 tendsto_id) + have hi := integrableOn_Ioi_deriv_of_nonpos hc.continuousWithinAt hd hn hl + have he := integral_Ioi_of_hasDerivAt_of_nonpos hc.continuousWithinAt hd hn hl + refine ⟨integrable_neg_iff.mp hi,?_⟩ + simp only [integral_neg,zero_add,rho_initial le_rfl,zero_sub] at he + linarith + +theorem rho_first_moment : + (∫ y in Ioi 0,y*rho y) = ∫ y in Ioi 0,rho y := by + have h0 : IntegrableOn rho (Ioi 0) := by simpa only [pow_zero,one_mul] using rho_moment_integrable 0 + have h1 : IntegrableOn (fun y : ℝ => y*rho y) (Ioi 0) := by simpa only [pow_one] using rho_moment_integrable 1 + have h1tail := h1.mono_set (Ioi_subset_Ioi (by norm_num : (0:ℝ) ≤ 1)) + have hadd : IntegrableOn (fun y : ℝ => (y+1)*rho y) (Ioi 0) := by + apply (h1.add h0).congr_fun _ measurableSet_Ioi + intro y _ + change y*rho y+rho y = (y+1)*rho y + ring + have hshift := halfline_shift 1 (-1) (fun y : ℝ => (y+1)*rho y) + simp only [← sub_eq_add_neg,sub_add_cancel,sub_self] at hshift + have hst : IntegrableOn (fun y : ℝ => y*rho (y-1)) (Ioi 1) := by + exact hshift.2.mp hadd + have hseq : (∫ y in Ioi 1,y*rho (y-1)) = + (∫ y in Ioi 0,y*rho y)+(∫ y in Ioi 0,rho y) := by + have hp (y : ℝ) : (y+1)*rho y = y*rho y+rho y := by ring + simpa only [hp,integral_add h1 h0] using hshift.1.symm + have hder : ∀ y ∈ Ioi (1:ℝ), HasDerivAt (fun x : ℝ => x^2*rho x) + (2*y*rho y-y*rho (y-1)) y := by + intro y hy + have hd := ((hasDerivAt_id y).pow 2).mul (rho_hasDerivAt hy) + change HasDerivAt (fun x : ℝ => x^2*rho x) (2*y^1*1*rho y+y^2*(-rho (y-1)/y)) y at hd + convert! hd using 1 + have hy0 : y ≠ 0 := by change 1 < y at hy; linarith + field_simp + ring + have hint : IntegrableOn (fun y : ℝ => 2*y*rho y-y*rho (y-1)) (Ioi 1) := by + have hh : IntegrableOn (fun y : ℝ => 2*(y*rho y)-y*rho (y-1)) (Ioi 1) := + (h1tail.const_mul 2).sub hst + apply hh.congr_fun _ measurableSet_Ioi + intro y _ + dsimp only + ring + have hcont : Continuous (fun x : ℝ => x^2*rho x) := (continuous_id.pow 2).mul rho_continuous + have he := integral_Ioi_of_hasDerivAt_of_tendsto + hcont.continuousWithinAt hder hint (rho_moment_tendsto_zero 2) + have hp (y : ℝ) : 2*y*rho y-y*rho (y-1)=2*(y*rho y)-y*rho (y-1) := by ring + simp only [hp,integral_sub (h1tail.const_mul 2) hst,integral_const_mul, + one_pow,rho_initial le_rfl,one_mul,zero_sub,hseq] at he + have hunit : (∫ y : ℝ in 0..1,y*rho y) = (1:ℝ)/2 := by + calc + _ = ∫ y : ℝ in 0..1,y := by + apply intervalIntegral.integral_congr + intro y hy + rw [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] at hy + change y*rho y = y + rw [rho_initial hy.2,mul_one] + _ = _ := by norm_num + have hsplit := intervalIntegral.integral_Ioi_sub_Ioi h1 (by norm_num : (0:ℝ) ≤ 1) + rw [hunit] at hsplit + linarith + +theorem rho_quadratic_quotient : + IntegrableOn (fun y : ℝ => y^2*rho y/(y+1)) (Ioi 0) ∧ + (∫ y in Ioi 0,y^2*rho y/(y+1)) = 1 := by + have h0 : IntegrableOn rho (Ioi 0) := by simpa only [pow_zero,one_mul] using rho_moment_integrable 0 + have h1 : IntegrableOn (fun y : ℝ => y*rho y) (Ioi 0) := by simpa only [pow_one] using rho_moment_integrable 1 + have heq : EqOn (fun y : ℝ => y^2*rho y/(y+1)) + (fun y => y*rho y-rho y+rho y/(y+1)) (Ioi 0) := by + intro y hy + have hn : y+1 ≠ 0 := by change 0 < y at hy; linarith + field_simp + ring + refine ⟨((h1.sub h0).add rho_quotient_integral.1).congr_fun (fun y hy => (heq hy).symm) measurableSet_Ioi,?_⟩ + have hs : IntegrableOn (fun y : ℝ => y*rho y-rho y) (Ioi 0) := h1.sub h0 + rw [setIntegral_congr_fun measurableSet_Ioi heq, + integral_add hs rho_quotient_integral.1,integral_sub h1 h0, + rho_first_moment,rho_quotient_integral.2] + ring + +end Erdos970Dependency.StandardBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/FiniteAdmittedOccupation.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/FiniteAdmittedOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..906bcaaa943aabe002d6636de740c5f025e6aba7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/FiniteAdmittedOccupation.lean @@ -0,0 +1,187 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SignedCompletedPowers +import OAI.NumberTheory.Jacobsthal.Partitions.ContinuousHighPartition +import OAI.NumberTheory.Jacobsthal.Paths.FlagMeasurePartition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.OriginalHarmonicOccupation + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures AdmittedHarmonicPaths ArrivalKernelGeometry +open KernelExitBarrier KernelWeightTransform HarmonicWeightKernel +open InvariantInverseWeights CostPrefixTransport RegeneratingInverseBands + +noncomputable def occupation (K : Kernel CostState CostState) : Kernel CostState CostState := + Kernel.sum (fun n : ℕ => K^n) + +instance occupation_isSFinite (K : Kernel CostState CostState) [IsSFiniteKernel K] : + IsSFiniteKernel (occupation K) := by unfold occupation; infer_instance + +theorem restricted_occupation_at (K : Kernel CostState CostState) {A : Set CostState} + (hA : MeasurableSet A) (hNo : ∀ z ∉ A, K z A = 0) (z : CostState) (hz : z ∈ A) : + occupation (K.restrict hA) z = (occupation K z).restrict A := by + classical + have hpow : ∀ n : ℕ, ((K.restrict hA)^n) z = ((K^n) z).restrict A := by + intro n + cases n with + | zero => + change Measure.dirac z = (Measure.dirac z).restrict A + rw [restrict_dirac' hA, ite_eq_left hz] + | succ n => rw [restricted_pow_eq K hA hNo]; rfl + apply Measure.ext + intro B hB + simp only [occupation] + rw [Kernel.sum_apply' _ _ hB, Measure.restrict_apply hB, + Kernel.sum_apply' _ _ (hB.inter hA)] + apply tsum_congr + intro n + rw [hpow, Measure.restrict_apply hB] + +theorem admitted_occupation_transform (v ell : ℝ) : + occupation (admittedHarmonic v ell) = conjugate (occupation (admittedTilted v ell)) harmonicWeight := by + rw [occupation, admitted_weight_transform, conjugate_prefix_sum] + rfl + +noncomputable def gapSquaredWeight (v : ℝ) (z : CostState) : ℝ≥0∞ := + ENNReal.ofReal ((gapValue v z)^2 / stateWeight z.1) + +theorem gapSquaredWeight_measurable (v : ℝ) : Measurable (gapSquaredWeight v) := + ENNReal.measurable_ofReal.comp (((gapValue_measurable v).pow_const 2).div + (stateWeight_measurable.comp measurable_fst)) + +theorem scaled_harmonic_weight (v : ℝ) (z : CostState) : + ENNReal.ofReal ((Real.exp v)^2) * harmonicWeight z = gapSquaredWeight v z := by + change ENNReal.ofReal ((Real.exp v)^2) * ENNReal.ofReal (Real.exp (-2*z.2) / stateWeight z.1) = _ + rw [← ENNReal.ofReal_mul (sq_nonneg _)] + congr 1 + change (Real.exp v)^2 * (Real.exp (-2*z.2) / stateWeight z.1) = (Real.exp (v-z.2))^2 / stateWeight z.1 + rw [← mul_div_assoc] + congr 1 + rw [pow_two, ← Real.exp_add, ← Real.exp_add, pow_two, ← Real.exp_add] + congr 1 + ring + +theorem scaled_ratio (v : ℝ) (s : State) (z : CostState) : + ENNReal.ofReal ((Real.exp v)^2 / stateWeight s) * (harmonicWeight z / harmonicWeight (s,0)) = + gapSquaredWeight v z := by + rw [div_eq_mul_inv (harmonicWeight z) (harmonicWeight (s,0)), initial_weight_inv] + calc + _ = (ENNReal.ofReal ((Real.exp v)^2 / stateWeight s) * ENNReal.ofReal (stateWeight s)) * harmonicWeight z := by ring + _ = ENNReal.ofReal ((Real.exp v)^2) * harmonicWeight z := by + rw [← ENNReal.ofReal_mul (div_nonneg (sq_nonneg _) (stateWeight_pos s).le), + div_mul_cancel₀ _ (stateWeight_pos s).ne'] + _ = _ := scaled_harmonic_weight v z + +theorem scaled_occupation (v ell : ℝ) (s : State) {F : CostState → ℝ≥0∞} (hF : Measurable F) : + ENNReal.ofReal ((Real.exp v)^2 / stateWeight s) * + (∫⁻ z, F z ∂occupation (admittedHarmonic v ell) (s,0)) = + ∫⁻ z, gapSquaredWeight v z * F z ∂occupation (admittedTilted v ell) (s,0) := by + rw [admitted_occupation_transform, conjugate_lintegral _ harmonicWeight (s,0) hF] + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro z + rw [← mul_assoc, scaled_ratio] + +theorem admitted_tilted_occupation (v ell : ℝ) (z : CostState) (hz : z ∈ arrivalSet v ell) : + occupation (admittedTilted v ell) z = (inclusiveOccupation z).restrict (arrivalSet v ell) := by + simpa only [occupation, admittedTilted, ← inclusiveOccupation_eq_prefix_sum] using + restricted_occupation_at costKernel (arrivalSet_measurable v ell) (costKernel_no_reentry v ell) z hz + +theorem scaled_occupation_arrival (v ell : ℝ) (s : State) (hs : (s,0) ∈ arrivalSet v ell) + {F : CostState → ℝ≥0∞} (hF : Measurable F) : + ENNReal.ofReal ((Real.exp v)^2 / stateWeight s) * + (∫⁻ z, F z ∂occupation (admittedHarmonic v ell) (s,0)) = + ∫⁻ z in arrivalSet v ell, gapSquaredWeight v z * F z ∂inclusiveOccupation (s,0) := by + rw [scaled_occupation v ell s hF, admitted_tilted_occupation v ell (s,0) hs] + +end NumberTheoryLean.OriginalHarmonicOccupation + +end + +section + +namespace NumberTheoryLean.FiniteAdmittedOccupation + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures LowStateHorizon AdmittedHarmonicPaths ArrivalKernelGeometry +open OriginalHarmonicOccupation SignedCompletedPowers CompactTestMeasurable +open ContinuousHighPartition SubMarkovFlagPowers FlagMeasurePartition FlaggedOccupationBound + +theorem occupation_eq_finite (K : Kernel CostState CostState) (z : CostState) (N : ℕ) + (hzero : ∀ n,N ≤ n → (K^n) z = 0) : occupation K z = ∑ n ∈ range N,(K^n) z := by + apply Measure.ext + intro B hB + rw [occupation,Kernel.sum_apply' _ _ hB,Measure.finsetSum_apply] + apply tsum_eq_sum + intro n hn + have hN : N ≤ n := by + have hh : ¬n < N := by simpa only [Finset.mem_range] using hn + omega + rw [hzero n hN] + simp + +theorem occupation_integral_eq_finite (K : Kernel CostState CostState) [IsFiniteKernel K] + (z : CostState) (N : ℕ) (hzero : ∀ n,N ≤ n → (K^n) z = 0) + {F : CostState → ℝ} (hF : Measurable F) {A : ℝ} (hbound : ∀ y,|F y| ≤ A) : + (∫ y,F y ∂occupation K z) = ∑ n ∈ range N,∫ y,F y ∂(K^n) z := by + rw [occupation_eq_finite K z N hzero] + apply integral_finsetSum_measure + intro n _hn + let := finite_kernel_power K n + exact bounded_integrable hF hbound + +theorem admitted_low_signed_error (v ell S B : ℝ) (hell : 1 ≤ ell) (hS : 0 < S) (hB : 0 < B) + (s : State) (hs : stateRatio s ≤ S) + (hgap : RegeneratingInverseBands.gapValue v (s,0) ≤ (23/10:ℝ)*B) + {F : CostState → ℝ} (hF : Measurable F) {A : ℝ} (hbound : ∀ y,|F y| ≤ A) : + ENNReal.ofReal |(∫ y,F y ∂occupation (admittedTilted v ell) (s,0))- + (∫ y,F y ∂occupation (lowKernel costKernel v ell S) (s,0))| ≤ + ∑' n : ℕ,∫⁻ y,selected (fun a => ENNReal.ofReal |F a|) y + ∂((tiltedFlagged v ell S)^n) (FlaggedHarmonicPaths.initial S (s,0)) := by + let M := ⌈RegeneratingInverseBands.gapValue v (s,0)/ell⌉₊ + let N := sourceHorizon S B + let T := max M N + have hfullzero : ∀ n,T ≤ n → ((admittedTilted v ell)^n) (s,0) = 0 := by + intro n hn + exact admitted_tilted_finite_height v (by linarith) (s,0) n ((le_max_left _ _).trans hn) + have hlowzero : ∀ n,T ≤ n → ((lowKernel costKernel v ell S)^n) (s,0) = 0 := by + intro n hn + exact tilted_source_horizon v ell S B hell hS hB (s,0) hgap n ((le_max_right _ _).trans hn) + let : IsFiniteKernel (lowKernel costKernel v ell S) := by unfold lowKernel; infer_instance + rw [occupation_integral_eq_finite _ _ T hfullzero hF hbound, + occupation_integral_eq_finite _ _ T hlowzero hF hbound] + have hI : ∀ n ∈ range T,Integrable F (((admittedTilted v ell)^n) (s,0)) := by + intro n _hn + let := finite_kernel_power (admittedTilted v ell) n + exact bounded_integrable hF hbound + have h := signed_finite_difference (admittedTilted v ell) (high_measurable S) T (s,0) hF hI + have he : goodKernel (admittedTilted v ell) (high_measurable S) = lowKernel costKernel v ell S := + good_admitted_eq_low costKernel v ell S + rw [he] at h + have hinit : FlaggedHarmonicPaths.initial S (s,0) = ((s,0),false) := by + simp only [FlaggedHarmonicPaths.initial,ite_eq_right (not_lt.mpr hs)] + rw [hinit] + exact h.trans (ENNReal.sum_le_tsum (range T)) + +theorem low_occupation_integral_eq_source_sum (v ell S B : ℝ) (hell : 1 ≤ ell) (hS : 0 < S) (hB : 0 < B) + (z : CostState) (hgap : RegeneratingInverseBands.gapValue v z ≤ (23/10:ℝ)*B) + {F : CostState → ℝ} (hF : Measurable F) {A : ℝ} (hbound : ∀ y,|F y| ≤ A) : + (∫ y,F y ∂occupation (lowKernel costKernel v ell S) z) = + ∑ n ∈ range (sourceHorizon S B),∫ y,F y ∂((lowKernel costKernel v ell S)^n) z := by + let : IsFiniteKernel (lowKernel costKernel v ell S) := by unfold lowKernel; infer_instance + exact occupation_integral_eq_finite _ _ _ (tilted_source_horizon v ell S B hell hS hB z hgap) hF hbound + +end NumberTheoryLean.FiniteAdmittedOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/FlaggedOccupationBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/FlaggedOccupationBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..d77b1536f4bb8a6ef0f4630edd5bf618ac3add65 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/FlaggedOccupationBound.lean @@ -0,0 +1,129 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FlaggedSourceStart + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.FlaggedOccupationBound + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open PersistentFailureFlag + +variable {α : Type*} [MeasurableSpace α] + +noncomputable def selected (f : α → ℝ≥0∞) : FlagState α → ℝ≥0∞ := + failed.indicator (fun z => f z.1) + +theorem selected_measurable {f : α → ℝ≥0∞} (hf : Measurable f) : Measurable (selected f) := + (hf.comp measurable_fst).indicator failed_measurable + +omit [MeasurableSpace α] in +@[simp] theorem selected_false (f : α → ℝ≥0∞) (x : α) : selected f (x,false) = 0 := by + simp [selected,failed] + +omit [MeasurableSpace α] in +@[simp] theorem selected_true (f : α → ℝ≥0∞) (x : α) : selected f (x,true) = f x := by + simp [selected,failed] + +theorem selected_integral_le {f : α → ℝ≥0∞} {C : ℝ≥0∞} (hC : C ≠ ∞) + (hf : ∀ x,f x ≤ C) (μ : Measure (FlagState α)) : + (∫⁻ z,selected f z ∂μ) ≤ C*μ failed := by + calc + _ ≤ ∫⁻ z,C*failed.indicator (fun _ => (1:ℝ≥0∞)) z ∂μ := by + apply lintegral_mono + rintro ⟨x,b⟩ + cases b <;> simp [selected,failed,hf x] + _ = _ := by + rw [lintegral_const_mul' _ _ hC,lintegral_indicator failed_measurable,setLIntegral_const,one_mul] + +theorem selected_true_integral (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) {f : α → ℝ≥0∞} (hf : Measurable f) (x : α) : + (∫⁻ z,selected f z ∂marked K hBad (x,true)) = ∫⁻ y,f y ∂K x := by + rw [marked_eq_map K hBad (x,true),lintegral_map (selected_measurable hf) + (row_update_measurable hBad true)] + simp only [Bool.true_or,selected_true] + +theorem selected_row (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) {q V : α → ℝ≥0∞} (hV : Measurable V) + {C : ℝ≥0∞} (hC : C ≠ ∞) (hbound : ∀ x,V x ≤ C) + (hdrift : ∀ x,q x+(∫⁻ y,V y ∂K x) ≤ V x) (z : FlagState α) : + selected q z+(∫⁻ y,selected V y ∂marked K hBad z)+ + C*failed.indicator (fun _ => (1:ℝ≥0∞)) z ≤ + selected V z+C*marked K hBad z failed := by + rcases z with ⟨x,b⟩ + cases b with + | false => + simpa [selected,failed] using selected_integral_le hC hbound (marked K hBad (x,false)) + | true => + rw [selected_true,selected_true,selected_true_integral K hBad hV,marked_failed_true] + simpa [failed] using add_le_add_left (hdrift x) C + +theorem law_selected_step (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) {q V : α → ℝ≥0∞} (hq : Measurable q) (hV : Measurable V) + {C : ℝ≥0∞} (hC : C ≠ ∞) (hbound : ∀ x,V x ≤ C) + (hdrift : ∀ x,q x+(∫⁻ y,V y ∂K x) ≤ V x) (x : α) (n : ℕ) : + (∫⁻ z,selected q z ∂law K hBad x n)+ + (∫⁻ z,selected V z ∂law K hBad x (n+1))+C*law K hBad x n failed ≤ + (∫⁻ z,selected V z ∂law K hBad x n)+C*law K hBad x (n+1) failed := by + have hp : (marked K hBad)^(n+1) = marked K hBad ∘ₖ ((marked K hBad)^n) := pow_succ' _ _ + have hnext : (∫⁻ z,selected V z ∂law K hBad x (n+1)) = + ∫⁻ z,∫⁻ y,selected V y ∂marked K hBad z ∂law K hBad x n := by + unfold law + rw [hp,Kernel.lintegral_comp _ _ _ (selected_measurable hV)] + have hfail : law K hBad x (n+1) failed = ∫⁻ z,marked K hBad z failed ∂law K hBad x n := by + unfold law + rw [hp,Kernel.comp_apply' _ _ _ failed_measurable] + have hi := lintegral_mono (μ := law K hBad x n) (selected_row K hBad hV hC hbound hdrift) + have hinner : Measurable (fun z => ∫⁻ y,selected V y ∂marked K hBad z) := (selected_measurable hV).lintegral_kernel + rw [lintegral_add_left (f := fun z => selected q z+(∫⁻ y,selected V y ∂marked K hBad z)) + ((selected_measurable hq).add hinner), + lintegral_add_left (selected_measurable hq), + lintegral_add_left (selected_measurable hV), + lintegral_const_mul' _ _ hC,lintegral_const_mul' _ _ hC, + lintegral_indicator failed_measurable,setLIntegral_const,one_mul] at hi + rw [← hnext,← hfail] at hi + exact hi + +theorem finite_selected_occupation (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) {q V : α → ℝ≥0∞} (hq : Measurable q) (hV : Measurable V) + {C : ℝ≥0∞} (hC : C ≠ ∞) (hbound : ∀ x,V x ≤ C) + (hdrift : ∀ x,q x+(∫⁻ y,V y ∂K x) ≤ V x) (x : α) (N : ℕ) : + (∑ n ∈ range N, ∫⁻ z,selected q z ∂law K hBad x n) ≤ C*law K hBad x N failed := by + have hstrong : ∀ N : ℕ, + (∑ n ∈ range N, ∫⁻ z,selected q z ∂law K hBad x n)+ + (∫⁻ z,selected V z ∂law K hBad x N) ≤ C*law K hBad x N failed := by + intro N + induction N with + | zero => + simp only [sum_range_zero,zero_add,law,pow_zero] + change (∫⁻ z,selected V z ∂Measure.dirac (x,false)) ≤ C*Measure.dirac (x,false) failed + rw [lintegral_dirac' _ (selected_measurable hV),selected_false] + exact zero_le + | succ N ih => + rw [sum_range_succ,add_assoc] + have hd : C*law K hBad x N failed ≠ ∞ := ENNReal.mul_ne_top hC (measure_ne_top _ _) + apply (ENNReal.add_le_add_iff_right hd).mp + calc + _ = (∑ n ∈ range N, ∫⁻ z,selected q z ∂law K hBad x n)+ + ((∫⁻ z,selected q z ∂law K hBad x N)+ + (∫⁻ z,selected V z ∂law K hBad x (N+1))+C*law K hBad x N failed) := by ac_rfl + _ ≤ (∑ n ∈ range N, ∫⁻ z,selected q z ∂law K hBad x n)+ + ((∫⁻ z,selected V z ∂law K hBad x N)+C*law K hBad x (N+1) failed) := + add_le_add_right (law_selected_step K hBad hq hV hC hbound hdrift x N) _ + _ ≤ C*law K hBad x N failed+C*law K hBad x (N+1) failed := by + rw [← add_assoc] + exact add_le_add_left ih _ + _ = _ := add_comm _ _ + exact (le_add_right le_rfl).trans (hstrong N) + +end NumberTheoryLean.FlaggedOccupationBound + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/FullOccupationRatioTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/FullOccupationRatioTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..b10c3a3fb149974bc804b3a8221f5cbfea784b70 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/FullOccupationRatioTail.lean @@ -0,0 +1,59 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FirstVisitRatioTail + +namespace OAI + +namespace Erdos970 + + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +namespace ErdosHighRatioBandTail +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels +open NumberTheoryLean.OccupationDecomposition NumberTheoryLean.InitialOccupation +open NumberTheoryLean.CostPrefixTransport NumberTheoryLean.EvenBandBounds +open Erdos970Dependency.StateKernelInvariance + +theorem full_band_tail_bound (h : ℝ) : ∃ C : ℝ≥0∞, C < ∞ ∧ ∃ U : ℝ, 4 ≤ U ∧ + ∀ T : ℝ, U ≤ T → ∀ v : ℝ, ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → + fullOccupation (.inl s,0) (highBand T v h) ≤ + ENNReal.ofReal (Real.exp (-2*(T-(U-1)))) + C*stateMeasure (highStates T) := by + obtain ⟨C,hC,hlater⟩ := later_band_tail_bound h + obtain ⟨U,hU,hfirst⟩ := first_band_tail_bound + refine ⟨C,hC,U,hU,?_⟩ + intro T hT v s hsL hsU + rw [fullOccupation_first_and_later] + change costKernel (.inl s,0) (highBand T v h) + + prefixOccupation 2 (.inl s,0) (highBand T v h) ≤ _ + exact add_le_add (hfirst T hT v h s hsU) (hlater T v s hsL hsU) + +theorem uniform_full_occupation_tail (h eps : ℝ) (heps : 0 < eps) : + ∀ᶠ T : ℝ in atTop, ∀ v : ℝ, ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → + fullOccupation (.inl s,0) (highBand T v h) ≤ ENNReal.ofReal eps := by + obtain ⟨C,hC,U,_hU,hb⟩ := full_band_tail_bound h + have hct : Tendsto (fun T : ℝ => C*stateMeasure (highStates T)) atTop (𝓝 0) := by + simpa only [mul_zero] using ENNReal.Tendsto.const_mul stateMeasure_tail_tendsto (Or.inr hC.ne) + have ht : Tendsto (fun T : ℝ => ENNReal.ofReal (Real.exp (-2*(T-(U-1)))) + + C*stateMeasure (highStates T)) atTop (𝓝 0) := by + simpa only [add_zero] using (exponential_tail_tendsto U).add hct + have hsmall := ht.eventually (gt_mem_nhds (ENNReal.ofReal_pos.mpr heps)) + filter_upwards [hsmall,eventually_ge_atTop U] with T hT hU + intro v s hsL hsU + exact (hb T hU v s hsL hsU).trans hT.le + +theorem exists_full_occupation_threshold (h eps : ℝ) (heps : 0 < eps) : + ∃ T₀ : ℝ, 3 ≤ T₀ ∧ ∀ T : ℝ, T₀ ≤ T → ∀ v : ℝ, ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → + fullOccupation (.inl s,0) (highBand T v h) ≤ ENNReal.ofReal eps := by + obtain ⟨T₀,hT₀⟩ := eventually_atTop.mp (uniform_full_occupation_tail h eps heps) + refine ⟨max T₀ 3,le_max_right _ _,?_⟩ + intro T hT + exact hT₀ T ((le_max_left _ _).trans hT) + +end ErdosHighRatioBandTail + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/KernelPotential.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/KernelPotential.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b62d7334b2a40a642741145f17d72d54091e184 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/KernelPotential.lean @@ -0,0 +1,139 @@ +import Mathlib.Probability.Kernel.Composition.Comp + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.KernelPotential + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {α β γ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] + +noncomputable def potential (B : Kernel α β) (K : Kernel α α) : Kernel α β := + Kernel.sum (fun n : ℕ => B ∘ₖ (K ^ n)) + +instance potential_isSFiniteKernel (B : Kernel α β) (K : Kernel α α) + [IsSFiniteKernel B] [IsSFiniteKernel K] : IsSFiniteKernel (potential B K) := by + have hp : ∀ n : ℕ, IsSFiniteKernel (K ^ n) := by + intro n + induction n with + | zero => change IsSFiniteKernel (Kernel.id : Kernel α α); infer_instance + | succ n ih => + rw [pow_succ] + change IsSFiniteKernel ((K ^ n) ∘ₖ K) + infer_instance + unfold potential + infer_instance + +theorem compose_mono_left {B C : Kernel α β} (h : B ≤ C) (K : Kernel γ α) : + B ∘ₖ K ≤ C ∘ₖ K := by + intro a + apply Measure.le_iff.mpr + intro s hs + rw [Kernel.comp_apply' _ _ _ hs, Kernel.comp_apply' _ _ _ hs] + exact lintegral_mono (fun x => h x s) + +theorem compose_finset_sum_left (I : Finset ℕ) (B : ℕ → Kernel α β) (K : Kernel γ α) : + (∑ n ∈ I, B n) ∘ₖ K = ∑ n ∈ I, B n ∘ₖ K := by + classical + induction I using Finset.induction_on with + | empty => simp + | @insert n I hn ih => simp only [Finset.sum_insert hn, Kernel.comp_add_left, ih] + +theorem power_comp_succ (B : Kernel α β) (K : Kernel α α) (n : ℕ) : + B ∘ₖ (K ^ (n + 1)) = (B ∘ₖ (K ^ n)) ∘ₖ K := by + rw [pow_succ] + exact (Kernel.comp_assoc B (K ^ n) K).symm + +theorem potential_unfold (B : Kernel α β) (K : Kernel α α) : + potential B K = B + (potential B K) ∘ₖ K := by + unfold potential + rw [Kernel.comp_sum_left] + ext a s hs + rw [Kernel.sum_apply' _ _ hs, add_apply, Measure.add_apply, Kernel.sum_apply' _ _ hs, + tsum_eq_zero_add' ENNReal.summable] + have hz : B ∘ₖ (K ^ 0) = B := Kernel.comp_id B + simp only [hz, power_comp_succ] + +theorem potential_le_of_super (B : Kernel α β) (K : Kernel α α) (S : Kernel α β) + (hS : B + S ∘ₖ K ≤ S) : potential B K ≤ S := by + have hfin : ∀ n : ℕ, (∑ j ∈ Finset.range n, B ∘ₖ (K ^ j)) ≤ S := by + intro n + induction n with + | zero => simp only [Finset.range_zero, Finset.sum_empty]; exact bot_le + | succ n ih => + rw [Finset.sum_range_succ'] + have hz : B ∘ₖ (K ^ 0) = B := Kernel.comp_id B + simp only [hz, power_comp_succ] + rw [← compose_finset_sum_left] + calc + _ = B + (∑ j ∈ Finset.range n, B ∘ₖ (K ^ j)) ∘ₖ K := add_comm _ _ + _ ≤ B + S ∘ₖ K := fun a => add_le_add le_rfl ((compose_mono_left ih K) a) + _ ≤ S := hS + intro a + apply Measure.le_iff.mpr + intro s hs + rw [potential, Kernel.sum_apply' _ _ hs, ENNReal.tsum_eq_iSup_nat] + apply iSup_le + intro n + have h := hfin n a s + rwa [Kernel.finsetSum_apply'] at h + +theorem potential_add (B C : Kernel α β) (K : Kernel α α) : + potential (B + C) K = potential B K + potential C K := by + unfold potential + simp_rw [Kernel.comp_add_left] + exact Kernel.sum_add _ _ + +theorem potential_comp_left (B : Kernel α β) (C : Kernel β γ) (K : Kernel α α) : + potential (C ∘ₖ B) K = C ∘ₖ (potential B K) := by + unfold potential + rw [Kernel.comp_sum_right] + congr 1 + funext n + exact Kernel.comp_assoc C B (K ^ n) + +theorem first_capture_decomposition (B : Kernel α β) (Q H : Kernel α α) : + potential B (Q + H) = potential (potential B Q) (potential H Q) := by + let P := potential B (Q + H) + let O := potential B Q + let R := potential H Q + let S := potential O R + have hP : P = B + P ∘ₖ (Q + H) := potential_unfold B (Q + H) + have hO : O = B + O ∘ₖ Q := potential_unfold B Q + have hR : R = H + R ∘ₖ Q := potential_unfold H Q + have hS : S = O + S ∘ₖ R := potential_unfold O R + have hSeq : B + S ∘ₖ (Q + H) = S := by + calc + _ = B + S ∘ₖ Q + S ∘ₖ H := by rw [Kernel.comp_add_right]; abel + _ = B + (O + S ∘ₖ R) ∘ₖ Q + S ∘ₖ H := by rw [← hS] + _ = (B + O ∘ₖ Q) + S ∘ₖ (H + R ∘ₖ Q) := by + rw [Kernel.comp_add_left, Kernel.comp_add_right, ← Kernel.comp_assoc] + abel + _ = O + S ∘ₖ R := by rw [← hO, ← hR] + _ = S := hS.symm + have hPS : P ≤ S := potential_le_of_super B (Q + H) S hSeq.le + have hPsuper : (B + P ∘ₖ H) + P ∘ₖ Q ≤ P := by + have heq : (B + P ∘ₖ H) + P ∘ₖ Q = P := by + calc + _ = B + P ∘ₖ (Q + H) := by rw [Kernel.comp_add_right]; abel + _ = P := hP.symm + exact heq.le + have hOR : O + P ∘ₖ R ≤ P := by + have h := potential_le_of_super (B + P ∘ₖ H) Q P hPsuper + rw [potential_add, potential_comp_left] at h + exact h + have hSP : S ≤ P := potential_le_of_super O R P hOR + exact le_antisymm hPS hSP + +end NumberTheoryLean.KernelPotential + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/LaplaceODE.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/LaplaceODE.lean new file mode 100644 index 0000000000000000000000000000000000000000..f614f0b7fc96b172207087b58519b94452b02fea --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/LaplaceODE.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialIntegral + +namespace OAI + +namespace Erdos970 + +section + +open Real Set MeasureTheory Filter Topology + +namespace ErdosAverageCertificates + +noncomputable section + +theorem laplace_ode_solution + {F : ℝ → ℝ} + (hF : DifferentiableOn ℝ F (Set.Ioi 0)) + (hpos : ∀ s : ℝ, 0 < s → 0 < 1 + F s) + (hode : ∀ s : ℝ, 0 < s → + s * deriv F s + Real.exp (-s) * (1 + F s) = 0) + (hinfty : Tendsto F atTop (nhds 0)) : + ∀ s : ℝ, 0 < s → + 1 + F s = Real.exp + (∫ t in Set.Ioi s, Real.exp (-t) / t) := by + intro s hs + have hlogDeriv : ∀ x ∈ Set.Ici s, + HasDerivAt (fun y : ℝ ↦ Real.log (1 + F y)) + (-Real.exp (-x) / x) x := by + intro x hx + have hx0 : 0 < x := lt_of_lt_of_le hs hx + have hFx : DifferentiableAt ℝ F x := + hF.differentiableAt (Ioi_mem_nhds hx0) + have hinner : HasDerivAt (fun y : ℝ ↦ 1 + F y) (deriv F x) x := + hFx.hasDerivAt.const_add 1 + have hlog := (Real.hasDerivAt_log (hpos x hx0).ne').comp x hinner + have hxne : x ≠ 0 := hx0.ne' + have hHne : 1 + F x ≠ 0 := (hpos x hx0).ne' + have hratio : (1 + F x)⁻¹ * deriv F x = -Real.exp (-x) / x := by + rw [inv_mul_eq_div] + field_simp [hxne, hHne] + nlinarith [hode x hx0] + exact hlog.congr_deriv hratio + have hlogLim : Tendsto (fun x : ℝ ↦ Real.log (1 + F x)) + atTop (nhds 0) := by + have hinner : Tendsto (fun x : ℝ ↦ 1 + F x) atTop (nhds 1) := by + simpa using (tendsto_const_nhds.add hinfty) + change Tendsto (Real.log ∘ fun x : ℝ ↦ 1 + F x) atTop (nhds 0) + simpa only [Real.log_one] using + (Real.continuousAt_log one_ne_zero).tendsto.comp hinner + have hneg : ∀ x ∈ Set.Ioi s, -Real.exp (-x) / x ≤ 0 := by + intro x hx + have hx0 : 0 < x := hs.trans hx + exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (Real.exp_pos _).le) hx0.le + have hint := MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonpos' + hlogDeriv hneg hlogLim + have hlogEq : Real.log (1 + F s) = + ∫ t in Set.Ioi s, Real.exp (-t) / t := by + have hrewrite : (fun x : ℝ ↦ -Real.exp (-x) / x) = + fun x : ℝ ↦ -(Real.exp (-x) / x) := by + funext x + ring + rw [hrewrite, integral_neg] at hint + linarith + rw [← hlogEq, Real.exp_log (hpos s hs)] + +end + +end ErdosAverageCertificates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/LastCycleRecord.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/LastCycleRecord.lean new file mode 100644 index 0000000000000000000000000000000000000000..7b7a6c70673de79042bdec6e4cf4d287f55edd74 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/LastCycleRecord.lean @@ -0,0 +1,97 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RawEvenMarkedHit + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels + +noncomputable def lastCycleRecord : (w : List Bool) → (b : Bool) → + CycleWordSignature (w++[b]).length → CycleInputSignature + | [], _b, s => s.1 + | _c::w, b, s => lastCycleRecord w b s.2 + +lemma lastCycleRecord_measurable (w : List Bool) : ∀ b, Measurable (lastCycleRecord w b) := by + induction w with + | nil => intro b; exact measurable_fst + | cons c w ih => intro b; exact (ih b).comp measurable_snd + +lemma lastCycleRecord_cost (w : List Bool) (b : Bool) (s : CycleWordSignature (w++[b]).length) : + (lastCycleRecord w b s).1=lookaheadInputCost w b s := by + induction w with + | nil => rfl + | cons c w ih => exact ih s.2 + +noncomputable def sourceRecordKernel (b : Bool) : Kernel OddCost CycleInputSignature := + (Kernel.id ×ₖ sourceBranchWitnessKernel b).map (fun p => sourceCycleInputSignature p.1 p.2) + +instance sourceRecordKernel_isFiniteKernel (b : Bool) : IsFiniteKernel (sourceRecordKernel b) := by + unfold sourceRecordKernel + infer_instance + +lemma sourceRecordKernel_apply (b : Bool) (z : OddCost) : + sourceRecordKernel b z=(sourceBranchWitnessKernel b z).map (sourceCycleInputSignature z) := by + ext S hS + rw [sourceRecordKernel,Kernel.map_apply' _ sourceCycleInputSignature_measurable _ hS, + Kernel.id_prod_apply' _ _ (sourceCycleInputSignature_measurable hS), + Measure.map_apply (f := sourceCycleInputSignature z) (sourceCycleInputSignature_measurable.comp measurable_prodMk_left) hS] + rfl + +lemma sourceRecordKernel_lintegral (b : Bool) (z : OddCost) {F : CycleInputSignature → ℝ≥0∞} + (hF : Measurable F) : (∫⁻ s, F s ∂sourceRecordKernel b z) = + ∫⁻ y, F (sourceCycleInputSignature z y) ∂sourceBranchWitnessKernel b z := by + rw [sourceRecordKernel_apply,lintegral_map (g := sourceCycleInputSignature z) hF + (sourceCycleInputSignature_measurable.comp measurable_prodMk_left)] + +lemma sourceLastRecord_lintegral (w : List Bool) (b : Bool) + {F : CycleInputSignature → ℝ≥0∞} (hF : Measurable F) : ∀ z, + (∫⁻ s, F (lastCycleRecord w b s) ∂sourceMarkedWordKernel (w++[b]) z) = + ∫⁻ y, ∫⁻ t, F t ∂sourceRecordKernel b y ∂branchWordKernel w z := by + have hG : Measurable (fun y : OddCost => ∫⁻ t, F t ∂sourceRecordKernel b y) := hF.lintegral_kernel + induction w with + | nil => + intro z + change (∫⁻ s : CycleWordSignature [b].length, F (lastCycleRecord [] b s) ∂sourceMarkedWordKernel [b] z) = _ + rw [sourceMarkedWord_cons_lintegral b [] z + (F := fun s => F (lastCycleRecord [] b s)) (hF.comp (lastCycleRecord_measurable [] b))] + change (∫⁻ y : SourceCycleWitness, ∫⁻ _s, F (sourceCycleInputSignature z y) + ∂Measure.dirac (embedOdd y.2.2) ∂sourceBranchWitnessKernel b z) = + ∫⁻ y, ∫⁻ t, F t ∂sourceRecordKernel b y ∂Measure.dirac z + simp only [lintegral_const,measure_univ,mul_one] + rw [lintegral_dirac' z hG,sourceRecordKernel_lintegral b z hF] + | cons c w ih => + intro z + change (∫⁻ s : CycleWordSignature (c::(w++[b])).length, + F (lastCycleRecord (c::w) b s) ∂sourceMarkedWordKernel (c::(w++[b])) z) = _ + rw [sourceMarkedWord_cons_lintegral c (w++[b]) z + (F := fun s => F (lastCycleRecord (c::w) b s)) (hF.comp (lastCycleRecord_measurable (c::w) b))] + change (∫⁻ y : SourceCycleWitness, ∫⁻ s, F (lastCycleRecord w b s) + ∂sourceMarkedWordKernel (w++[b]) y.2.2 ∂sourceBranchWitnessKernel c z) = _ + simp_rw [ih] + have hJ : Measurable (fun y : OddCost => ∫⁻ t, ∫⁻ u, F u ∂sourceRecordKernel b t ∂branchWordKernel w y) := + hG.lintegral_kernel + rw [← lintegral_map (g := fun y : SourceCycleWitness => y.2.2) hJ (measurable_snd.comp measurable_snd), + sourceBranchWitness_endpoint,branchWordKernel,Kernel.lintegral_comp _ _ _ hG] + +theorem sourceLastRecord_law (w : List Bool) (b : Bool) (z : OddCost) : + (sourceMarkedWordKernel (w++[b]) z).map (lastCycleRecord w b)= + (sourceRecordKernel b ∘ₖ branchWordKernel w) z := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (lastCycleRecord_measurable w b),Kernel.lintegral_comp _ _ _ hF] + exact sourceLastRecord_lintegral w b hF z + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedCycleCompletion.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedCycleCompletion.lean new file mode 100644 index 0000000000000000000000000000000000000000..b79dedbdd72c0cce9335dd596b42257752a8157f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedCycleCompletion.lean @@ -0,0 +1,128 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReturnCompletionAlgebra + +namespace OAI + +namespace Erdos970 + + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.CycleRegeneration +open NumberTheoryLean.InitialRegeneration NumberTheoryLean.RegenerationTails +open NumberTheoryLean.CycleCostLower NumberTheoryLean.FinitePathGeometry + +noncomputable def continueMarkUpdate (x : MarkedOddCost × OddCost) : MarkedOddCost := (x.1.1,x.2) + +lemma continueMarkUpdate_measurable : Measurable continueMarkUpdate := + (measurable_fst.comp measurable_fst).prodMk measurable_snd + +noncomputable def markContinuation : Kernel MarkedOddCost MarkedOddCost := + (Kernel.id ×ₖ hitOrReturn.prodMkLeft Bool).map continueMarkUpdate + +instance markContinuation_isMarkovKernel : IsMarkovKernel markContinuation := + Kernel.IsMarkovKernel.map _ continueMarkUpdate_measurable + +lemma markContinuation_apply (z : MarkedOddCost) {B : Set MarkedOddCost} (hB : MeasurableSet B) : + markContinuation z B = hitOrReturn z.2 {y | (z.1,y) ∈ B} := by + rw [markContinuation,Kernel.map_apply' _ continueMarkUpdate_measurable _ hB, + Kernel.prod_apply' _ _ _ (continueMarkUpdate_measurable hB),Kernel.id_apply,lintegral_dirac'] + · rfl + · exact measurable_measure_prodMk_left (continueMarkUpdate_measurable hB) + +lemma markContinuation_forget (z : MarkedOddCost) : + (markContinuation z).map Prod.snd = hitOrReturn z.2 := by + ext B hB + rw [Measure.map_apply measurable_snd hB,markContinuation_apply _ (measurable_snd hB)] + rfl + +noncomputable def completedMarkedKernel : Kernel OddCost MarkedOddCost := + markContinuation ∘ₖ markedPairKernel + +instance completedMarkedKernel_isMarkovKernel : IsMarkovKernel completedMarkedKernel := by + unfold completedMarkedKernel + infer_instance + +lemma completedMarked_forget (z : OddCost) : + (completedMarkedKernel z).map Prod.snd = returnLaw z := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF measurable_snd,completedMarkedKernel, + Kernel.lintegral_comp _ _ _ (g := fun y : MarkedOddCost => F y.2) (hF.comp measurable_snd)] + have he (y : MarkedOddCost) : (∫⁻ t, F t.2 ∂markContinuation y) = ∫⁻ t, F t ∂hitOrReturn y.2 := by + rw [← markContinuation_forget y,lintegral_map hF measurable_snd] + simp_rw [he] + have hJ : Measurable (fun y : OddCost => ∫⁻ t, F t ∂hitOrReturn y) := hF.lintegral_kernel + calc + _ = ∫⁻ y : OddCost, ∫⁻ t, F t ∂hitOrReturn y ∂pairedCostKernel z := by + rw [← markedPair_forget z,lintegral_map hJ measurable_snd] + _ = _ := by rw [← complete_first_pair,Kernel.lintegral_comp _ _ _ hF] + +lemma completedMarked_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + completedMarkedKernel (s,T) = completedMarkedKernel (regenerationState,T) := by + ext B hB + rw [completedMarkedKernel,Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB, + markedPair_regeneration s hs T] + +lemma markContinuation_preserves_mark (z : MarkedOddCost) : + markContinuation z {y | y.1=true} = if z.1=true then 1 else 0 := by + have hB : MeasurableSet {y : MarkedOddCost | y.1=true} := measurable_fst (measurableSet_singleton true) + rw [markContinuation_apply _ hB] + by_cases hz : z.1=true <;> simp [hz] + +lemma completedMarked_mark_eq (z : OddCost) : + completedMarkedKernel z {y | y.1=true} = markedPairKernel z {y | y.1=true} := by + let B : Set MarkedOddCost := {y | y.1=true} + have hB : MeasurableSet B := measurable_fst (measurableSet_singleton true) + rw [completedMarkedKernel,Kernel.comp_apply' _ _ _ hB] + calc + _ = ∫⁻ y, B.indicator (fun _ => (1:ℝ≥0∞)) y ∂markedPairKernel z := by + apply lintegral_congr + intro y + rw [markContinuation_preserves_mark] + simp [B,Set.indicator_apply] + _ = ∫⁻ _y in B, (1:ℝ≥0∞) ∂markedPairKernel z := lintegral_indicator hB _ + _ = _ := by simp [B] + +lemma completedMarked_mark_mass (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + completedMarkedKernel (s,T) {y | y.1=true} = markProbability := by + rw [completedMarked_mark_eq,markedPair_mark_mass s hs T] + +lemma completedMarked_cost_lower (z : OddCost) : + ∀ᵐ y ∂completedMarkedKernel z, z.2+cost 3 ≤ y.2.2 := by + have he := returnLaw_cost_lower z + rw [← completedMarked_forget z] at he + exact (ae_map_iff measurable_snd.aemeasurable (measurableSet_le measurable_const measurable_snd)).mp he + +lemma markContinuation_translation (z : MarkedOddCost) (a : ℝ) : + (markContinuation z).map (markedShift a) = markContinuation (markedShift a z) := by + ext B hB + rw [Measure.map_apply (markedShift_measurable a) hB, + markContinuation_apply _ ((markedShift_measurable a) hB),markContinuation_apply _ hB] + change hitOrReturn z.2 {y | (z.1,shiftCost a y) ∈ B} = + hitOrReturn (shiftCost a z.2) {y | (z.1,y) ∈ B} + have hD : MeasurableSet {y : OddCost | (z.1,y) ∈ B} := + (measurable_const.prodMk measurable_id) hB + rw [← hitOrReturn_translation z.2 a,Measure.map_apply (shiftCost_measurable a) hD] + rfl + +lemma completedMarked_translation (s : OddState) (T a : ℝ) : + (completedMarkedKernel (s,T)).map (markedShift a) = completedMarkedKernel (s,T+a) := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (markedShift_measurable a),completedMarkedKernel, + Kernel.lintegral_comp _ _ _ (g := fun y : MarkedOddCost => F (markedShift a y)) (hF.comp (markedShift_measurable a)),Kernel.lintegral_comp _ _ _ hF] + have he (z : MarkedOddCost) : (∫⁻ y, F (markedShift a y) ∂markContinuation z) = + ∫⁻ y, F y ∂markContinuation (markedShift a z) := by + rw [← markContinuation_translation z a,lintegral_map hF (markedShift_measurable a)] + simp_rw [he] + have hJ : Measurable (fun z : MarkedOddCost => ∫⁻ y, F y ∂markContinuation z) := hF.lintegral_kernel + rw [← markedPair_translation s T a,lintegral_map hJ (markedShift_measurable a)] + +end Erdos970Dependency.MarkedVisits + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedCycleWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedCycleWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..9cda38e039cec4579cd405db916ea3488e7d00a3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedCycleWords.lean @@ -0,0 +1,219 @@ +import OAI.NumberTheory.Jacobsthal.Probability.GeometricCostLaws + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw + +noncomputable def cycleBranchKernel (b : Bool) : Kernel OddCost OddCost := + (completedMarkedKernel.restrict (measurable_fst (measurableSet_singleton b))).map Prod.snd + +instance cycleBranchKernel_isFiniteKernel (b : Bool) : IsFiniteKernel (cycleBranchKernel b) := by + unfold cycleBranchKernel + infer_instance + +instance cycleBranch_pow_isFiniteKernel (b : Bool) (n : ℕ) : IsFiniteKernel (cycleBranchKernel b ^ n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel OddCost OddCost); infer_instance + | succ n ih => + rw [pow_succ'] + change IsFiniteKernel (cycleBranchKernel b ∘ₖ (cycleBranchKernel b ^ n)) + infer_instance + +noncomputable def branchCostLaw (b : Bool) : Measure ℝ := + (sourceCycleLaw.restrict {z | z.1=b}).map sourceCostProjection + +lemma branchCostLaw_true : branchCostLaw true = markedCostLaw := rfl + +lemma false_mark_set : {z : MarkedOddCost | z.1=false} = sourceMarkSetᶜ := by + ext z + cases z.1 <;> simp [sourceMarkSet] + +lemma branchCostLaw_false : branchCostLaw false = unmarkedCostLaw := by + rw [branchCostLaw,false_mark_set] + rfl + +instance branchCostLaw_isFiniteMeasure (b : Bool) : IsFiniteMeasure (branchCostLaw b) := by + unfold branchCostLaw + infer_instance + +lemma cycleBranch_sum : cycleBranchKernel true+cycleBranchKernel false = returnLaw := by + ext z : 1 + rw [add_apply] + unfold cycleBranchKernel + rw [Kernel.map_apply _ measurable_snd,Kernel.map_apply _ measurable_snd, + Kernel.restrict_apply,Kernel.restrict_apply] + change ((completedMarkedKernel z).restrict {y | y.1=true}).map Prod.snd + + ((completedMarkedKernel z).restrict {y | y.1=false}).map Prod.snd = returnLaw z + rw [false_mark_set] + change ((completedMarkedKernel z).restrict sourceMarkSet).map Prod.snd + + ((completedMarkedKernel z).restrict sourceMarkSetᶜ).map Prod.snd = returnLaw z + rw [← Measure.map_add _ _ measurable_snd,Measure.restrict_add_restrict_compl sourceMarkSet_measurable, + completedMarked_forget] + +lemma cycleBranch_ae_regeneration (b : Bool) (z : OddCost) : + ∀ᵐ y ∂cycleBranchKernel b z, y ∈ returnSet := by + rw [cycleBranchKernel,Kernel.map_apply _ measurable_snd,Kernel.restrict_apply] + apply (ae_map_iff measurable_snd.aemeasurable returnSet_measurable).mpr + exact ae_restrict_of_ae (completedMarked_ae_regeneration z) + +lemma cycleBranch_increment_integral (b : Bool) (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H (y.2-z.2) ∂cycleBranchKernel b z) = ∫⁻ G, H G ∂branchCostLaw b := by + let F : Bool × ℝ → ℝ≥0∞ := fun x => if x.1=b then H x.2 else 0 + have hF : Measurable F := Measurable.ite (measurable_fst (measurableSet_singleton b)) + (hH.comp measurable_snd) measurable_const + have hB : MeasurableSet {y : MarkedOddCost | y.1=b} := measurable_fst (measurableSet_singleton b) + have hleft : (∫⁻ y, H (y.2-z.2) ∂cycleBranchKernel b z) = + ∫⁻ y, F (y.1,y.2.2-z.2) ∂completedMarkedKernel z := by + rw [cycleBranchKernel,Kernel.map_apply _ measurable_snd,Kernel.restrict_apply, + lintegral_map (f := fun y : OddCost => H (y.2-z.2)) (hH.comp (measurable_snd.sub measurable_const)) measurable_snd] + change (∫⁻ y in {a : MarkedOddCost | a.1=b}, H (y.2.2-z.2) ∂completedMarkedKernel z) = _ + rw [← lintegral_indicator hB] + apply lintegral_congr + intro y + simp [F,Set.indicator_apply] + have hright : (∫⁻ G, H G ∂branchCostLaw b) = ∫⁻ u, F u ∂jointMarkCostLaw := by + rw [branchCostLaw,lintegral_map hH sourceCostProjection_measurable, + ← lintegral_indicator hB,jointMarkCostLaw,lintegral_map hF markCostProjection_measurable] + apply lintegral_congr + intro y + simp [F,sourceCostProjection,markCostProjection,Set.indicator_apply] + rw [hleft,hright,marked_cycle_increment_integral z hz hF] + +lemma cycleBranch_cost_lintegral (b : Bool) (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y.2 ∂cycleBranchKernel b z) = ∫⁻ G, H (z.2+G) ∂branchCostLaw b := by + have he := cycleBranch_increment_integral b z hz + (H := fun G => H (z.2+G)) (hH.comp (measurable_const.add measurable_id)) + simpa [add_sub_assoc] using he + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open AbsorptionCutoff.Renewal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw + +lemma cycleBranch_mass (b : Bool) (z : OddCost) (hz : z ∈ returnSet) : + cycleBranchKernel b z univ = branchCostLaw b univ := by + simpa only [lintegral_one] using cycleBranch_increment_integral b z hz (H := fun _ => 1) measurable_const + +lemma cycleBranch_true_mass (z : OddCost) (hz : z ∈ returnSet) : + cycleBranchKernel true z univ = markProbability := by + rw [cycleBranch_mass true z hz,branchCostLaw_true,markedCostLaw_mass] + +lemma cycleBranch_pow_ae_regeneration (b : Bool) (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + ∀ᵐ y ∂(cycleBranchKernel b ^ n) z, y ∈ returnSet := by + cases n with + | zero => + change ∀ᵐ y ∂Measure.dirac z, y ∈ returnSet + exact (ae_dirac_iff returnSet_measurable).mpr hz + | succ n => + rw [pow_succ'] + change ∀ᵐ y ∂(cycleBranchKernel b ∘ₖ (cycleBranchKernel b ^ n)) z, y ∈ returnSet + exact Kernel.ae_comp_of_ae_ae returnSet_measurable (Eventually.of_forall (cycleBranch_ae_regeneration b)) + +lemma branch_cumulative_cost_lintegral (b : Bool) (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y.2 ∂(cycleBranchKernel b ^ n) z) = + ∫⁻ G, H (z.2+G) ∂convPow (branchCostLaw b) n := by + induction n generalizing z with + | zero => + change (∫⁻ y, H y.2 ∂Measure.dirac z) = _ + rw [lintegral_dirac' z (f := fun y : OddCost => H y.2) (hH.comp measurable_snd),convPow_zero, + lintegral_dirac' 0 (f := fun G : ℝ => H (z.2+G)) (hH.comp (measurable_const.add measurable_id)),add_zero] + | succ n ih => + have hp : cycleBranchKernel b ^ (n+1) = (cycleBranchKernel b ^ n) ∘ₖ cycleBranchKernel b := pow_succ _ _ + rw [hp,Kernel.lintegral_comp _ _ _ (g := fun y : OddCost => H y.2) (hH.comp measurable_snd)] + let F : ℝ → ℝ≥0∞ := fun t => ∫⁻ G, H (z.2+t+G) ∂convPow (branchCostLaw b) n + have hF : Measurable F := (hH.comp ((measurable_const.add measurable_fst).add measurable_snd)).lintegral_prod_right' + calc + _ = ∫⁻ y, F (y.2-z.2) ∂cycleBranchKernel b z := by + apply lintegral_congr_ae + filter_upwards [cycleBranch_ae_regeneration b z] with y hy + rw [ih y hy] + apply lintegral_congr + intro G + congr 1 + ring + _ = ∫⁻ t, F t ∂branchCostLaw b := cycleBranch_increment_integral b z hz hF + _ = _ := by + rw [convPow_succ',Measure.lintegral_conv (f := fun G : ℝ => H (z.2+G)) + (hH.comp (measurable_const.add measurable_id))] + apply lintegral_congr + intro t + apply lintegral_congr + intro G + congr 1 + ring + +lemma branch_cumulative_cost_law (b : Bool) (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + ((cycleBranchKernel b ^ n) z).map (fun y => y.2-z.2) = convPow (branchCostLaw b) n := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map (g := fun y : OddCost => y.2-z.2) hH (measurable_snd.sub measurable_const), + branch_cumulative_cost_lintegral b n z hz (H := fun G => H (G-z.2)) + (hH.comp (measurable_id.sub measurable_const))] + simp only [add_sub_cancel_left] + +lemma branch_word_ae_regeneration (first rest : Bool) (n : ℕ) (z : OddCost) : + ∀ᵐ y ∂((cycleBranchKernel rest ^ n) ∘ₖ cycleBranchKernel first) z, y ∈ returnSet := by + apply Kernel.ae_comp_of_ae_ae returnSet_measurable + filter_upwards [cycleBranch_ae_regeneration first z] with y hy + exact cycleBranch_pow_ae_regeneration rest n y hy + +lemma branch_word_cost_lintegral (first rest : Bool) (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y.2 ∂((cycleBranchKernel rest ^ n) ∘ₖ cycleBranchKernel first) z) = + ∫⁻ G, H (z.2+G) ∂(branchCostLaw first ∗ convPow (branchCostLaw rest) n) := by + rw [Kernel.lintegral_comp _ _ _ (g := fun y : OddCost => H y.2) (hH.comp measurable_snd)] + let F : ℝ → ℝ≥0∞ := fun t => ∫⁻ G, H (z.2+t+G) ∂convPow (branchCostLaw rest) n + have hF : Measurable F := (hH.comp ((measurable_const.add measurable_fst).add measurable_snd)).lintegral_prod_right' + calc + _ = ∫⁻ y, F (y.2-z.2) ∂cycleBranchKernel first z := by + apply lintegral_congr_ae + filter_upwards [cycleBranch_ae_regeneration first z] with y hy + rw [branch_cumulative_cost_lintegral rest n y hy hH] + apply lintegral_congr + intro G + congr 1 + ring + _ = ∫⁻ t, F t ∂branchCostLaw first := cycleBranch_increment_integral first z hz hF + _ = _ := by + rw [Measure.lintegral_conv (f := fun G : ℝ => H (z.2+G)) (hH.comp (measurable_const.add measurable_id))] + apply lintegral_congr + intro t + apply lintegral_congr + intro G + congr 1 + ring + +lemma branch_word_cost_law (first rest : Bool) (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + (((cycleBranchKernel rest ^ n) ∘ₖ cycleBranchKernel first) z).map (fun y => y.2-z.2) = + branchCostLaw first ∗ convPow (branchCostLaw rest) n := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map (g := fun y : OddCost => y.2-z.2) hH (measurable_snd.sub measurable_const), + branch_word_cost_lintegral first rest n z hz (H := fun G => H (G-z.2)) + (hH.comp (measurable_id.sub measurable_const))] + simp only [add_sub_cancel_left] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedRenewalComparison.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedRenewalComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f4bf097bf81fdfa6bb43f9eae4b192cb50751dd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/MarkedRenewalComparison.lean @@ -0,0 +1,129 @@ +import OAI.NumberTheory.Jacobsthal.Probability.MarkedReturnKernel + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open AbsorptionCutoff.Renewal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.RegenerationTails NumberTheoryLean.KernelPotential +open NumberTheoryLean.CycleConvolutionLaw NumberTheoryLean.CycleRenewalInputs + +instance markedReturn_pow_isMarkovKernel (n : ℕ) : IsMarkovKernel (markedReturnKernel ^ n) := by + induction n with + | zero => change IsMarkovKernel (Kernel.id : Kernel OddCost OddCost); infer_instance + | succ n ih => + rw [pow_succ'] + change IsMarkovKernel (markedReturnKernel ∘ₖ (markedReturnKernel ^ n)) + infer_instance + +lemma markedReturn_cumulative_cost_lintegral (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y.2 ∂(markedReturnKernel ^ n) z) = ∫⁻ G, H (z.2+G) ∂convPow markedSpacingLaw n := by + induction n generalizing z with + | zero => + change (∫⁻ y, H y.2 ∂Measure.dirac z) = _ + rw [lintegral_dirac' z (f := fun y : OddCost => H y.2) (hH.comp measurable_snd),convPow_zero, + lintegral_dirac' 0 (f := fun G : ℝ => H (z.2+G)) (hH.comp (measurable_const.add measurable_id)),add_zero] + | succ n ih => + have hp : markedReturnKernel ^ (n+1) = (markedReturnKernel ^ n) ∘ₖ markedReturnKernel := pow_succ _ _ + rw [hp,Kernel.lintegral_comp _ _ _ (g := fun y : OddCost => H y.2) (hH.comp measurable_snd)] + let F : ℝ → ℝ≥0∞ := fun t => ∫⁻ G, H (z.2+t+G) ∂convPow markedSpacingLaw n + have hF : Measurable F := (hH.comp ((measurable_const.add measurable_fst).add measurable_snd)).lintegral_prod_right' + calc + _ = ∫⁻ y, F (y.2-z.2) ∂markedReturnKernel z := by + apply lintegral_congr_ae + filter_upwards [markedReturn_ae_regeneration z] with y hy + rw [ih y hy] + apply lintegral_congr + intro G + congr 1 + ring + _ = ∫⁻ t, F t ∂markedSpacingLaw := markedReturn_increment_integral z hz hF + _ = _ := by + rw [convPow_succ',Measure.lintegral_conv (f := fun G : ℝ => H (z.2+G)) + (hH.comp (measurable_const.add measurable_id))] + apply lintegral_congr + intro t + apply lintegral_congr + intro G + congr 1 + ring + +lemma markedReturn_cumulative_cost_law (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + ((markedReturnKernel ^ n) z).map (fun y => y.2-z.2) = convPow markedSpacingLaw n := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map (g := fun y : OddCost => y.2-z.2) hH (measurable_snd.sub measurable_const), + markedReturn_cumulative_cost_lintegral n z hz (H := fun G => H (G-z.2)) + (hH.comp (measurable_id.sub measurable_const))] + simp only [add_sub_cancel_left] + +lemma potential_mono_base {B C : Kernel OddCost OddCost} (h : B ≤ C) (K : Kernel OddCost OddCost) : + potential B K ≤ potential C K := by + apply potential_le_of_super B K (potential C K) + calc + _ ≤ C+(potential C K) ∘ₖ K := fun z => add_le_add (h z) le_rfl + _ = _ := (potential_unfold C K).symm + +lemma markedReturn_potential_le_full : + potential (Kernel.id : Kernel OddCost OddCost) markedReturnKernel ≤ potential Kernel.id returnLaw := by + have hsum : cycleBranchKernel false+cycleBranchKernel true=returnLaw := by + rw [add_comm] + exact cycleBranch_sum + have he : potential (Kernel.id : Kernel OddCost OddCost) returnLaw = + potential (potential Kernel.id (cycleBranchKernel false)) markedReturnKernel := by + rw [← hsum] + exact first_capture_decomposition _ _ _ + have hId : (Kernel.id : Kernel OddCost OddCost) ≤ potential Kernel.id (cycleBranchKernel false) := by + rw [potential_unfold] + intro z + exact Measure.le_add_right le_rfl + exact (potential_mono_base hId markedReturnKernel).trans_eq he.symm + +lemma markedReturn_renewal_projection : + ((potential (Kernel.id : Kernel OddCost OddCost) markedReturnKernel) (regenerationState,0)).map Prod.snd = + renewalMeasure markedSpacingLaw := by + rw [potential,Kernel.sum_apply,Measure.map_sum measurable_snd.aemeasurable,renewalMeasure] + apply congrArg Measure.sum + funext n + rw [Kernel.id_comp] + have he := markedReturn_cumulative_cost_law n (regenerationState,0) + (by norm_num [returnSet,NumberTheoryLean.PairedHitting.pairedRegeneration,regenerationState]) + simpa only [sub_zero] using he + +lemma fullReturn_renewal_projection : + ((potential (Kernel.id : Kernel OddCost OddCost) returnLaw) (regenerationState,0)).map Prod.snd = + renewalMeasure cycleCostLaw := by + rw [← actualArrival_sum_eq_renewal,potential,Kernel.sum_apply,Measure.map_sum measurable_snd.aemeasurable] + apply congrArg Measure.sum + funext n + rw [Kernel.id_comp] + rfl + +lemma marked_renewal_le_full : renewalMeasure markedSpacingLaw ≤ renewalMeasure cycleCostLaw := by + rw [← markedReturn_renewal_projection,← fullReturn_renewal_projection] + apply Measure.le_iff.mpr + intro B hB + rw [Measure.map_apply measurable_snd hB,Measure.map_apply measurable_snd hB] + exact markedReturn_potential_le_full (regenerationState,0) _ + +theorem marked_renewal_cell_bound (ell : ℝ) : ∃ C : ℝ, 0 < C ∧ ∀ y : ℝ, + renewalMeasure markedSpacingLaw (Icc y (y+ell)) ≤ ENNReal.ofReal C := by + obtain ⟨C,hC⟩ := cycle_renewal_cell_bound ell + refine ⟨max C 1,lt_of_lt_of_le zero_lt_one (le_max_right _ _),?_⟩ + intro y + exact (marked_renewal_le_full _).trans ((hC y).trans (ENNReal.ofReal_le_ofReal (le_max_left _ _))) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/NonnegativeOriginalOccupation.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/NonnegativeOriginalOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..df519758506024918dd54dfd08f06d285bf1945b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/NonnegativeOriginalOccupation.lean @@ -0,0 +1,244 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualFlaggedCompact + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceCompactOccupation + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open PrimeCompactVisits PrimeCompactWeights PrimeCorrectionFactor +open FlaggedOccupationBound PersistentFailureFlag ActualProcessCoupling ActualFlaggedCompact + +variable {w ell S B : ℝ} {start : Node} + +noncomputable def compactReward (K w B : ℝ) {ell S : ℝ} (start : Node) + (z : ChainState w ell S start) : ℝ≥0∞ := + ENNReal.ofReal (scaledWeight w B start z*visit K z) + +theorem literal_scaled_weight (hell : 0 ≤ ell) (hr : 0 < start.gap) + (hs : Valid start.side start.ratio) (h : History w ell S start) : + B^2*ErdosPrimeInputs.PrimePrefixMass.prefixWeight h.primes = + (pathLaw w ell S start h.primes.length {some h}).toReal*scaledWeight w B start (some h) := by + rw [PrimeChainProbabilities.source_prime_weight_identity hell hr hs h] + unfold scaledWeight + ring + +theorem compact_reward_envelope {K D : ℝ} + (hbound : ∀ h : History w ell S start,h.node.gap ≤ K → scaledWeight w B start (some h) ≤ D) + (z : ChainState w ell S start) : + compactReward K w B start z ≤ ENNReal.ofReal D*ENNReal.ofReal (visit K z) := by + cases z with + | none => simp [compactReward,visit] + | some h => + by_cases hh : h.node.gap ≤ K + · simpa only [compactReward,visit,ite_eq_left hh,mul_one,ENNReal.ofReal_one] + using ENNReal.ofReal_le_ofReal (hbound h hh) + · simp [compactReward,visit,hh] + +theorem finite_reward_envelope {K D : ℝ} + (hbound : ∀ h : History w ell S start,h.node.gap ≤ K → scaledWeight w B start (some h) ≤ D) + (N : ℕ) : + (∑ n ∈ range N, ∫⁻ z,compactReward K w B start z ∂pathLaw w ell S start n) ≤ + ENNReal.ofReal D*(∑ n ∈ range N, ∫⁻ z,ENNReal.ofReal (visit K z) ∂pathLaw w ell S start n) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro n _hn + calc + _ ≤ ∫⁻ z,ENNReal.ofReal D*ENNReal.ofReal (visit K z) ∂pathLaw w ell S start n := + lintegral_mono (compact_reward_envelope hbound) + _ = _ := lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + +theorem finite_selected_reward_envelope {K D mesh : ℝ} (hs : Valid start.side start.ratio) + (hbound : ∀ h : History w ell S start,h.node.gap ≤ K → scaledWeight w B start (some h) ≤ D) + (N : ℕ) : + (∑ n ∈ range N, ∫⁻ z,selected (fun q : JointState w ell S start => compactReward K w B start q.1) z + ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal D*(∑ n ∈ range N, ∫⁻ z,selected (compactVisit K) z + ∂CouplingData.sourceLaw w ell S start hs mesh n) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro n _hn + calc + _ ≤ ∫⁻ z,ENNReal.ofReal D*selected (compactVisit K) z ∂CouplingData.sourceLaw w ell S start hs mesh n := by + apply lintegral_mono + rintro ⟨q,b⟩ + cases b with + | false => simp only [selected_false,mul_zero,le_refl] + | true => simpa only [selected_true,compactVisit] using compact_reward_envelope hbound q.1 + _ = _ := lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + +theorem source_compact_occupation (K : ℝ) (hK : 3 ≤ K) (d : ℝ) (_hd : 0 < d) : + ∃ C w₀ : ℝ, 0 < C ∧ 1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ, + ∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + (∀ N : ℕ,(∑ n ∈ range N, ∫⁻ z,compactReward K w B start z ∂pathLaw w ell S start n) ≤ ENNReal.ofReal C) ∧ + (∀ mesh : ℝ,∀ N : ℕ, + (∑ n ∈ range N, ∫⁻ z,selected (fun q : JointState w ell S start => compactReward K w B start q.1) z + ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal C*CouplingData.sourceLaw w ell S start hs mesh N failed) := by + have hDK := compactConstant_pos hK + have hevent := ((correctionBudget_tendsto_zero d).eventually (eventually_le_nhds (by norm_num : (0:ℝ) < 1))).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + obtain ⟨W,hW⟩ := eventually_atTop.mp hevent + refine ⟨compactConstant K*(K+1),max normalizationThreshold W,by positivity, + normalizationThreshold_gt_one.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hellB hB hlogB hcomp hi h199 h23 hc hcut + dsimp only + have hnorm : normalizationThreshold ≤ w := (le_max_left _ _).trans hw + have hwe := hW w ((le_max_right _ _).trans hw) + have hscale := UniformBudgetRate.source_scale_bound hwe.2 hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hS3 : 3 ≤ (Real.log B)^2 := by nlinarith + have hsS : start.ratio ≤ (Real.log B)^2 := by linarith + have he : start.gap = B*start.ratio := by + have hh : start.cutoff = start.gap/start.ratio := hc + rw [hcut] at hh + exact ((eq_div_iff (valid_pos hs).ne').mp hh).symm + have hr : 0 < start.gap := by rw [he]; exact mul_pos hB (valid_pos hs) + have hbound := scaled_compact_bound hK hB hell hellB hlogB hcomp hwe.1 hi h199 h23 hc hcut + have hprod : ENNReal.ofReal (compactConstant K)*ENNReal.ofReal (K+1) = + ENNReal.ofReal (compactConstant K*(K+1)) := (ENNReal.ofReal_mul hDK.le).symm + constructor + · intro N + refine (finite_reward_envelope hbound N).trans ?_ + calc + _ ≤ ENNReal.ofReal (compactConstant K)*ENNReal.ofReal (K+1) := + mul_le_mul_of_nonneg_left (finite_compact_visits hnorm hell hS0 hscale.1 hr hs hsS (K := K) (by linarith) N) zero_le + _ = _ := hprod + · intro mesh N + refine (finite_selected_reward_envelope hs hbound N).trans ?_ + calc + _ ≤ ENNReal.ofReal (compactConstant K)*(ENNReal.ofReal (K+1)* + CouplingData.sourceLaw w ell ((Real.log B)^2) start hs mesh N failed) := + mul_le_mul_of_nonneg_left (actual_flagged_compact_visits hnorm hell hS0 hscale.1 hr hs hsS (K := K) (by linarith) mesh N) zero_le + _ = _ := by rw [← mul_assoc,hprod] + +end NumberTheoryLean.SourceCompactOccupation + +end + +section + +namespace NumberTheoryLean.PrimeFamilyOccupation +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeChainHorizon +open PrimeCompactWeights SourceCompactOccupation +open ErdosPrimeInputs.PrimePrefixMass + +variable {w ell S B : ℝ} {start : Node} + +theorem singleton_off_stage (n : ℕ) (h : History w ell S start) (hne : h.primes.length ≠ n) : + pathLaw w ell S start n {some h} = 0 := by + have hsub : ({some h} : Set (ChainState w ell S start)) ⊆ {z | ¬stage n z} := by + intro z hz + have he : z = some h := hz + subst z + exact hne + exact measure_mono_null hsub (ae_iff.mp (pathLaw_stage n)) + +noncomputable def listReward (F : List ℕ → ℝ) : ChainState w ell S start → ℝ + | none => 0 + | some h => F h.primes + +theorem singleton_scaled_reward (hell : 0 ≤ ell) (hr : 0 < start.gap) + (hs : Valid start.side start.ratio) (n : ℕ) (h : History w ell S start) + (F : List ℕ → ℝ) : + (pathLaw w ell S start n).real {some h} * + (scaledWeight w B start (some h)*F h.primes) = + if n = h.primes.length then B^2*prefixWeight h.primes*F h.primes else 0 := by + classical + by_cases hn : n = h.primes.length + · rw [ite_eq_left hn,hn,measureReal_def] + rw [← mul_assoc,← literal_scaled_weight hell hr hs h] + · rw [ite_eq_right hn,measureReal_def,singleton_off_stage n h (Ne.symm hn)] + simp + +theorem finite_signed_original_occupation (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) + (hB : 0 < B) (hsize : start.gap ≤ (23/10 : ℝ)*B) (F : List ℕ → ℝ) : + (∑ n ∈ range (LowStateHorizon.sourceHorizon S B), + ∫ z,scaledWeight w B start z*listReward F z ∂pathLaw w ell S start n) = + B^2*(∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps) := by + classical + have hw1 : 1 < w := normalizationThreshold_gt_one.trans_le hw + let := historyFintype (ell := ell) (S := S) hw1 start + have hterm (n : ℕ) : + (∫ z,scaledWeight w B start z*listReward F z ∂pathLaw w ell S start n) = + ∑ h : History w ell S start, + if n = h.primes.length then B^2*prefixWeight h.primes*F h.primes else 0 := by + let := pathLaw_isProbability hw hell hS0 hS hr hs hsS n + rw [integral_fintype Integrable.of_finite,Fintype.sum_option] + simp only [scaledWeight,listReward,mul_zero,smul_zero,zero_add] + apply Finset.sum_congr rfl + intro h _hh + exact singleton_scaled_reward (by linarith) hr hs n h F + simp_rw [hterm] + rw [Finset.sum_comm] + have hlen (h : History w ell S start) : h.primes.length ∈ range (LowStateHorizon.sourceHorizon S B) := + mem_range.mpr (PrimeHistoryHorizon.history_length_lt hell hS0 hr hs hB hsize h) + simp only [Finset.sum_ite_eq',hlen,ite_true] + simp_rw [mul_assoc] + rw [← Finset.mul_sum] + congr 1 + simpa only [mul_assoc] using sum_histories hw1 start (fun ps => prefixWeight ps*F ps) + +end NumberTheoryLean.PrimeFamilyOccupation + +end + +section + +namespace NumberTheoryLean.PrimeFamilyOccupation +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeCompactWeights +open ErdosPrimeInputs.PrimePrefixMass + +variable {w ell S B : ℝ} {start : Node} + +theorem listReward_nonneg (F : List ℕ → ℝ) + (hF : ∀ ps,allowed w ell S start ps → 0 ≤ F ps) (z : ChainState w ell S start) : + 0 ≤ listReward F z := by + cases z with + | none => exact le_rfl + | some h => exact hF h.primes h.admissible + +theorem finite_nonnegative_original_occupation (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) + (hB : 0 < B) (hsize : start.gap ≤ (23/10 : ℝ)*B) (F : List ℕ → ℝ) + (hF : ∀ ps,allowed w ell S start ps → 0 ≤ F ps) : + (∑ n ∈ range (LowStateHorizon.sourceHorizon S B), + ∫⁻ z,ENNReal.ofReal (scaledWeight w B start z*listReward F z) ∂pathLaw w ell S start n) = + ENNReal.ofReal (B^2*(∑ ps ∈ retainedPrefixes w ell S start,prefixWeight ps*F ps)) := by + classical + have hw1 : 1 < w := normalizationThreshold_gt_one.trans_le hw + let := historyFintype (ell := ell) (S := S) hw1 start + have hnon (z : ChainState w ell S start) : 0 ≤ scaledWeight w B start z*listReward F z := + mul_nonneg (scaledWeight_nonneg hs z) (listReward_nonneg F hF z) + rw [← finite_signed_original_occupation hw hell hS0 hS hr hs hsS hB hsize F] + rw [ENNReal.ofReal_sum_of_nonneg (fun n _ => integral_nonneg hnon)] + apply Finset.sum_congr rfl + intro n _hn + let := pathLaw_isProbability hw hell hS0 hS hr hs hsS n + exact (ofReal_integral_eq_lintegral_ofReal Integrable.of_finite + (Filter.Eventually.of_forall hnon)).symm + +end NumberTheoryLean.PrimeFamilyOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/OccupationAge.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/OccupationAge.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a2776b4dc006e33118cb8f6dec8a50e4de59814 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/OccupationAge.lean @@ -0,0 +1,1122 @@ +import AbsorptionCutoff.Supercritical.RenewalApprox +import Mathlib.MeasureTheory.Function.L2Space +import Mathlib.Probability.Kernel.Composition.CompMap +import Mathlib.Probability.Moments.IntegrableExpMul +import OAI.NumberTheory.Jacobsthal.Estimates.MinorizingCostRegularity +import OAI.NumberTheory.Jacobsthal.Estimates.PairedCostGrouping +import OAI.NumberTheory.Jacobsthal.Renewal.RegenerativeOddOccupation + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.CycleCostAtomless + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures KernelDensityBridge +open PairedCostProcess CostReturnLaw MinorizingCostRegularity + +theorem positive_second_cost_level_null (T y : ℝ) : + ((volume : Measure ℝ).prod volume) {x : ℝ × ℝ | 0 < x.2 ∧ T + cost x.1 + cost x.2 = y} = 0 := by + have hA : MeasurableSet {x : ℝ × ℝ | 0 < x.2 ∧ T + cost x.1 + cost x.2 = y} := + (measurableSet_lt measurable_const measurable_snd).inter + (measurableSet_eq_fun ((measurable_const.add (cost_measurable.comp measurable_fst)).add + (cost_measurable.comp measurable_snd)) measurable_const) + rw [Measure.prod_apply hA] + apply lintegral_eq_zero_of_ae_eq_zero + apply Eventually.of_forall + intro t + apply Set.Subsingleton.measure_zero + intro u hu v hv + have hu0 : 0 < u := hu.1 + have hv0 : 0 < v := hv.1 + have huEq : T + cost t + cost u = y := hu.2 + have hvEq : T + cost t + cost v = y := hv.2 + exact cost_strictAntiOn.injOn hu0 hv0 (by linarith) + +theorem oddTwoStep_second_positive (s : OddState) : ∀ᵐ x ∂oddTwoStep s, 0 < x.2 := by + have hm : Measurable (fun x : EvenState × OddState => (x.1.1, x.2.1)) := + (measurable_subtype_coe.comp measurable_fst).prodMk (measurable_subtype_coe.comp measurable_snd) + rw [oddTwoStep, Kernel.map_apply _ hm] + apply (ae_map_iff hm.aemeasurable (measurableSet_lt measurable_const measurable_snd)).mpr + exact Eventually.of_forall (fun x => by change 0 < x.2.1; linarith [x.2.2]) + +theorem oddTwoStep_cost_level (s : OddState) (T y : ℝ) : + oddTwoStep s {x : ℝ × ℝ | T + cost x.1 + cost x.2 = y} = 0 := by + have heq : {x : ℝ × ℝ | T + cost x.1 + cost x.2 = y} =ᵐ[oddTwoStep s] + {x : ℝ × ℝ | 0 < x.2 ∧ T + cost x.1 + cost x.2 = y} := by + filter_upwards [oddTwoStep_second_positive s] with x hx + exact propext ⟨fun h => ⟨hx, h⟩, fun h => h.2⟩ + rw [measure_congr heq, oddTwoStep_eq_withDensity] + exact withDensity_absolutelyContinuous _ _ (positive_second_cost_level_null T y) + +theorem pairedCost_cost_level (z : OddCost) (y : ℝ) : + pairedCostKernel z {w : OddCost | w.2 = y} = 0 := by + have hm : Measurable (fun x : EvenState × OddState => (x.1.1, x.2.1)) := + (measurable_subtype_coe.comp measurable_fst).prodMk (measurable_subtype_coe.comp measurable_snd) + have hB : MeasurableSet {x : ℝ × ℝ | z.2 + cost x.1 + cost x.2 = y} := + measurableSet_eq_fun ((measurable_const.add (cost_measurable.comp measurable_fst)).add + (cost_measurable.comp measurable_snd)) measurable_const + have h := oddTwoStep_cost_level z.1 z.2 y + rw [oddTwoStep, Kernel.map_apply _ hm, Measure.map_apply hm hB] at h + rw [pairedCostKernel_apply z (measurableSet_eq_fun measurable_snd measurable_const)] + exact h + +theorem captured_cost_level (z : OddCost) (y : ℝ) : costCaptured z {w : OddCost | w.2 = y} = 0 := by + rw [costCaptured, Kernel.restrict_apply' _ _ _ (measurableSet_eq_fun measurable_snd measurable_const)] + exact measure_mono_null inter_subset_left (pairedCost_cost_level z y) + +theorem firstReturn_cost_level (n : ℕ) (z : OddCost) (y : ℝ) : + firstReturn n z {w : OddCost | w.2 = y} = 0 := by + rw [firstReturn, Kernel.comp_apply' _ _ _ (measurableSet_eq_fun measurable_snd measurable_const)] + simp only [captured_cost_level, lintegral_zero] + +theorem returnLaw_cost_level (z : OddCost) (y : ℝ) : returnLaw z {w : OddCost | w.2 = y} = 0 := by + rw [returnLaw, Kernel.sum_apply' _ _ (measurableSet_eq_fun measurable_snd measurable_const)] + simp only [firstReturn_cost_level, tsum_zero] + +instance cycleCostLaw_nullSingletonClass : NullSingletonClass cycleCostLaw := by + constructor + intro y + rw [cycleCostLaw, Measure.map_apply measurable_snd (measurableSet_singleton y)] + exact returnLaw_cost_level (RegenerationTails.regenerationState, 0) y + +theorem cycleCostLaw_countable_null {C : Set ℝ} (hC : C.Countable) : cycleCostLaw C = 0 := + hC.measure_zero _ + +theorem cycleCostLaw_lattice_null (a r : ℝ) : + cycleCostLaw {x : ℝ | ∃ k : ℤ, x = a + k * r} = 0 := by + apply cycleCostLaw_countable_null + apply (countable_range (fun k : ℤ => a + k * r)).mono + intro x hx + obtain ⟨k, hk⟩ := hx + exact ⟨k, hk.symm⟩ + +end NumberTheoryLean.CycleCostAtomless + +end + +section + +namespace NumberTheoryLean.CycleCostLower + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostProcess CostReturnLaw +open MinorizingCostRegularity + +theorem pairedCost_cost_monotone (z : OddCost) : ∀ᵐ y ∂pairedCostKernel z, z.2 ≤ y.2 := by + apply ae_iff.mpr + simp only [not_le] + change pairedCostKernel z {y : OddCost | y.2 < z.2} = 0 + rw [pairedCostKernel_apply z (measurableSet_lt measurable_snd measurable_const)] + have he : {x : EvenState × OddState | (x.2, z.2 + cost x.1.1 + cost x.2.1) ∈ {y : OddCost | y.2 < z.2}} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro x hx + have h1 : 0 < cost x.1.1 := cost_pos (by linarith [x.1.2]) + have h2 : 0 < cost x.2.1 := cost_pos (by linarith [x.2.2]) + change z.2 + cost x.1.1 + cost x.2.1 < z.2 at hx + linarith + rw [he, measure_empty] + +theorem costKilled_cost_monotone (z : OddCost) : ∀ᵐ y ∂costKilled z, z.2 ≤ y.2 := + ae_restrict_of_ae (pairedCost_cost_monotone z) + +theorem costKilled_pow_cost_monotone (n : ℕ) (z : OddCost) : + ∀ᵐ y ∂(costKilled ^ n) z, z.2 ≤ y.2 := by + induction n generalizing z with + | zero => + change ∀ᵐ y ∂Measure.dirac z, z.2 ≤ y.2 + exact (ae_dirac_iff (measurableSet_le measurable_const measurable_snd)).mpr le_rfl + | succ n ih => + have hp : costKilled ^ (n + 1) = costKilled ∘ₖ (costKilled ^ n) := pow_succ' costKilled n + rw [hp] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_const measurable_snd) + filter_upwards [ih z] with y hy + filter_upwards [costKilled_cost_monotone y] with w hw + exact le_trans hy hw + +theorem captured_cost_lower (z : OddCost) : + ∀ᵐ y ∂costCaptured z, z.2 + cost 3 ≤ y.2 := by + apply ae_iff.mpr + simp only [not_le] + change costCaptured z {y : OddCost | y.2 < z.2 + cost 3} = 0 + have hB : MeasurableSet {y : OddCost | y.2 < z.2 + cost 3} := + measurableSet_lt measurable_snd measurable_const + rw [costCaptured, Kernel.restrict_apply' _ _ _ hB, + pairedCostKernel_apply z (hB.inter returnSet_measurable)] + have he : {x : EvenState × OddState | (x.2, z.2 + cost x.1.1 + cost x.2.1) ∈ + ({y : OddCost | y.2 < z.2 + cost 3} ∩ returnSet)} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro x hx + have hu : x.2.1 ≤ 3 := hx.2 + have hcost : cost 3 ≤ cost x.2.1 := cost_strictAntiOn.antitoneOn + (by change 0 < x.2.1; linarith [x.2.2]) (by norm_num) hu + have hfirst : 0 < cost x.1.1 := cost_pos (by linarith [x.1.2]) + have hbad : z.2 + cost x.1.1 + cost x.2.1 < z.2 + cost 3 := hx.1 + linarith + rw [he, measure_empty] + +theorem firstReturn_cost_lower (n : ℕ) (z : OddCost) : + ∀ᵐ y ∂firstReturn n z, z.2 + cost 3 ≤ y.2 := by + rw [firstReturn] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_const measurable_snd) + filter_upwards [costKilled_pow_cost_monotone n z] with y hy + filter_upwards [captured_cost_lower y] with w hw + linarith + +theorem returnLaw_cost_lower (z : OddCost) : ∀ᵐ y ∂returnLaw z, z.2 + cost 3 ≤ y.2 := by + rw [returnLaw, Kernel.sum_apply, Measure.ae_sum_iff] + exact fun n => firstReturn_cost_lower n z + +theorem cost_three : cost 3 = Real.log (4 / 3) := by + unfold cost + congr 1 + norm_num + +theorem cycleCostLaw_lower : ∀ᵐ G ∂cycleCostLaw, Real.log (4 / 3) ≤ G := by + change ∀ᵐ G ∂(returnLaw (RegenerationTails.regenerationState, 0)).map Prod.snd, Real.log (4 / 3) ≤ G + apply (ae_map_iff measurable_snd.aemeasurable measurableSet_Ici).mpr + have h := returnLaw_cost_lower (RegenerationTails.regenerationState, 0) + simpa only [zero_add, cost_three] using h + +theorem cycleCostLaw_positive : ∀ᵐ G ∂cycleCostLaw, 0 < G := by + filter_upwards [cycleCostLaw_lower] with G hG + exact lt_of_lt_of_le (by rw [← cost_three]; exact cost_pos (by norm_num)) hG + +end NumberTheoryLean.CycleCostLower + +end + +section + +namespace NumberTheoryLean.CycleRegeneration + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels PairedCostProcess CostReturnLaw RegenerationTails + +theorem costKilled_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + costKilled (s, T) = costKilled (regenerationState, T) := by + rw [costKilled, Kernel.restrict_apply, Kernel.restrict_apply, pairedCost_regeneration s hs T] + +theorem costCaptured_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + costCaptured (s, T) = costCaptured (regenerationState, T) := by + rw [costCaptured, Kernel.restrict_apply, Kernel.restrict_apply, pairedCost_regeneration s hs T] + +theorem firstReturn_regeneration (n : ℕ) (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + firstReturn n (s, T) = firstReturn n (regenerationState, T) := by + cases n with + | zero => + change (costCaptured ∘ₖ (Kernel.id : Kernel OddCost OddCost)) (s, T) = + (costCaptured ∘ₖ (Kernel.id : Kernel OddCost OddCost)) (regenerationState, T) + rw [Kernel.comp_id] + exact costCaptured_regeneration s hs T + | succ n => + have hp : costKilled ^ (n + 1) = (costKilled ^ n) ∘ₖ costKilled := pow_succ costKilled n + have hq : (costKilled ^ (n + 1)) (s, T) = (costKilled ^ (n + 1)) (regenerationState, T) := by + rw [hp, Kernel.comp_apply, Kernel.comp_apply, costKilled_regeneration s hs T] + rw [firstReturn, Kernel.comp_apply, Kernel.comp_apply, hq] + +theorem returnLaw_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + returnLaw (s, T) = returnLaw (regenerationState, T) := by + ext B hB + rw [returnLaw, Kernel.sum_apply' _ _ hB, Kernel.sum_apply' _ _ hB] + apply tsum_congr + intro n + rw [firstReturn_regeneration n s hs T] + +theorem costKilled_translation (z : OddCost) (a : ℝ) : + (costKilled z).map (shiftCost a) = costKilled (shiftCost a z) := by + rw [costKilled, Kernel.restrict_apply, Kernel.restrict_apply] + calc + _ = ((pairedCostKernel z).map (shiftCost a)).restrict returnSetᶜ := + (Measure.restrict_map (shiftCost_measurable a) returnSet_measurable.compl).symm + _ = _ := by rw [pairedCost_translation]; rfl + +theorem costCaptured_translation (z : OddCost) (a : ℝ) : + (costCaptured z).map (shiftCost a) = costCaptured (shiftCost a z) := by + rw [costCaptured, Kernel.restrict_apply, Kernel.restrict_apply] + calc + _ = ((pairedCostKernel z).map (shiftCost a)).restrict returnSet := + (Measure.restrict_map (shiftCost_measurable a) returnSet_measurable).symm + _ = _ := by rw [pairedCost_translation]; rfl + +noncomputable def shiftKernel (a : ℝ) : Kernel OddCost OddCost := + Kernel.deterministic (shiftCost a) (shiftCost_measurable a) + +theorem shift_commutes_killed (a : ℝ) : Commute (shiftKernel a) costKilled := by + change shiftKernel a ∘ₖ costKilled = costKilled ∘ₖ shiftKernel a + rw [shiftKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.map_apply _ (shiftCost_measurable a), Kernel.comap_apply] + exact costKilled_translation z a + +theorem shift_commutes_captured (a : ℝ) : Commute (shiftKernel a) costCaptured := by + change shiftKernel a ∘ₖ costCaptured = costCaptured ∘ₖ shiftKernel a + rw [shiftKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.map_apply _ (shiftCost_measurable a), Kernel.comap_apply] + exact costCaptured_translation z a + +theorem shift_commutes_firstReturn (a : ℝ) (n : ℕ) : Commute (shiftKernel a) (firstReturn n) := + (shift_commutes_captured a).mul_right ((shift_commutes_killed a).pow_right n) + +theorem shift_commutes_returnLaw (a : ℝ) : Commute (shiftKernel a) returnLaw := by + change shiftKernel a ∘ₖ returnLaw = returnLaw ∘ₖ shiftKernel a + rw [returnLaw, Kernel.comp_sum_right, Kernel.comp_sum_left] + apply congrArg Kernel.sum + funext n + exact (shift_commutes_firstReturn a n).eq + +theorem returnLaw_translation (z : OddCost) (a : ℝ) : + (returnLaw z).map (shiftCost a) = returnLaw (shiftCost a z) := by + have h := (shift_commutes_returnLaw a).eq + change shiftKernel a ∘ₖ returnLaw = returnLaw ∘ₖ shiftKernel a at h + rw [shiftKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] at h + have hz := congrArg (fun K : Kernel OddCost OddCost => K z) h + rwa [Kernel.map_apply _ (shiftCost_measurable a), Kernel.comap_apply] at hz + +noncomputable def cycleJointLaw : Measure OddCost := returnLaw (regenerationState, 0) + +instance cycleJointLaw_isProbabilityMeasure : IsProbabilityMeasure cycleJointLaw := by + unfold cycleJointLaw + infer_instance + +theorem return_increment_law (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + (returnLaw (s, T)).map (shiftCost (-T)) = cycleJointLaw := by + rw [returnLaw_regeneration s hs T] + have ht := returnLaw_translation (regenerationState, 0) T + have hz : shiftCost T (regenerationState, 0) = (regenerationState, T) := by simp [shiftCost] + rw [hz] at ht + rw [← ht, Measure.map_map (shiftCost_measurable (-T)) (shiftCost_measurable T)] + have heq : shiftCost (-T) ∘ shiftCost T = id := by + funext z + ext <;> simp [shiftCost, Function.comp_apply, add_assoc] + rw [heq, Measure.map_id] + rfl + +theorem returnLaw_ae_regeneration (z : OddCost) : ∀ᵐ y ∂returnLaw z, y ∈ returnSet := by + apply ae_iff.mpr + exact returnLaw_off_returnSet z + +theorem cycle_increment_integral (z : OddCost) (hz : z ∈ returnSet) + {F : ℝ → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F (y.2 - z.2) ∂returnLaw z) = ∫⁻ G, F G ∂cycleCostLaw := by + have h := congrArg (fun μ : Measure OddCost => ∫⁻ y, F y.2 ∂μ) (return_increment_law z.1 hz z.2) + rw [lintegral_map (f := fun y : OddCost => F y.2) (hF.comp measurable_snd) (shiftCost_measurable (-z.2))] at h + rw [cycleCostLaw, lintegral_map hF measurable_snd] + simpa only [shiftCost, sub_eq_add_neg, cycleJointLaw] using h + +noncomputable def cycleProductExpectation : List (ℝ → ℝ≥0∞) → OddCost → ℝ≥0∞ + | [], _ => 1 + | F :: Fs, z => ∫⁻ y, F (y.2 - z.2) * cycleProductExpectation Fs y ∂returnLaw z + +theorem finite_cycle_cost_factorization (Fs : List (ℝ → ℝ≥0∞)) + (hFs : ∀ F ∈ Fs, Measurable F) (z : OddCost) (hz : z ∈ returnSet) : + cycleProductExpectation Fs z = (Fs.map (fun F => ∫⁻ G, F G ∂cycleCostLaw)).prod := by + induction Fs generalizing z with + | nil => rfl + | cons F Fs ih => + have hF : Measurable F := hFs F (by simp) + have hrest : ∀ G ∈ Fs, Measurable G := fun G hG => hFs G (by simp [hG]) + change (∫⁻ y, F (y.2 - z.2) * cycleProductExpectation Fs y ∂returnLaw z) = + (∫⁻ G, F G ∂cycleCostLaw) * (Fs.map (fun F => ∫⁻ G, F G ∂cycleCostLaw)).prod + calc + _ = ∫⁻ y, F (y.2 - z.2) * (Fs.map (fun F => ∫⁻ G, F G ∂cycleCostLaw)).prod ∂returnLaw z := by + apply lintegral_congr_ae + filter_upwards [returnLaw_ae_regeneration z] with y hy + rw [ih hrest y hy] + _ = (∫⁻ y, F (y.2 - z.2) ∂returnLaw z) * (Fs.map (fun F => ∫⁻ G, F G ∂cycleCostLaw)).prod := + lintegral_mul_const _ (hF.comp (measurable_snd.sub measurable_const)) + _ = _ := by rw [cycle_increment_integral z hz hF] + +end NumberTheoryLean.CycleRegeneration + +end + +section + +namespace NumberTheoryLean.MarkedCycleLaw + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open PairedCostProcess CostReturnLaw CycleRegeneration + +abbrev MarkedReturn := ℕ × OddCost + +def markReturn (n : ℕ) (z : OddCost) : MarkedReturn := (2 * (n + 1), z) + +theorem markReturn_measurable (n : ℕ) : Measurable (markReturn n) := + measurable_const.prodMk measurable_id + +noncomputable def firstMarkedReturn (n : ℕ) : Kernel OddCost MarkedReturn := + (firstReturn n).map (markReturn n) + +instance firstMarkedReturn_isFiniteKernel (n : ℕ) : IsFiniteKernel (firstMarkedReturn n) := by + unfold firstMarkedReturn + infer_instance + +noncomputable def markedReturnLaw : Kernel OddCost MarkedReturn := Kernel.sum firstMarkedReturn + +instance markedReturnLaw_isMarkovKernel : IsMarkovKernel markedReturnLaw := by + constructor + intro z + constructor + rw [markedReturnLaw, Kernel.sum_apply' _ _ MeasurableSet.univ] + have heq : ∀ n, firstMarkedReturn n z univ = firstReturn n z univ := by + intro n + rw [firstMarkedReturn, Kernel.map_apply' _ (markReturn_measurable n) _ MeasurableSet.univ, preimage_univ] + simp_rw [heq] + rw [← Kernel.sum_apply' firstReturn z MeasurableSet.univ] + change returnLaw z univ = 1 + exact measure_univ + +theorem markedReturnLaw_forget (z : OddCost) : (markedReturnLaw z).map Prod.snd = returnLaw z := by + ext B hB + rw [Measure.map_apply measurable_snd hB, markedReturnLaw, + Kernel.sum_apply' _ _ (measurable_snd hB), returnLaw, Kernel.sum_apply' _ _ hB] + apply tsum_congr + intro n + rw [firstMarkedReturn, Kernel.map_apply' _ (markReturn_measurable n) _ (measurable_snd hB)] + rfl + +theorem markedReturnLaw_duration_ge_two (z : OddCost) : ∀ᵐ x ∂markedReturnLaw z, 2 ≤ x.1 := by + rw [markedReturnLaw, Kernel.sum_apply, Measure.ae_sum_iff] + intro n + rw [firstMarkedReturn, Kernel.map_apply _ (markReturn_measurable n)] + apply (ae_map_iff (markReturn_measurable n).aemeasurable + (measurableSet_le measurable_const measurable_fst)).mpr + exact Eventually.of_forall (fun _ => by change 2 ≤ 2 * (n + 1); omega) + +theorem markedReturnLaw_ae_regeneration (z : OddCost) : + ∀ᵐ x ∂markedReturnLaw z, x.2 ∈ returnSet := by + apply (ae_map_iff measurable_snd.aemeasurable returnSet_measurable).mp + rw [markedReturnLaw_forget] + exact returnLaw_ae_regeneration z + +noncomputable def markedCycleLaw : Measure MarkedReturn := + markedReturnLaw (RegenerationTails.regenerationState, 0) + +instance markedCycleLaw_isProbabilityMeasure : IsProbabilityMeasure markedCycleLaw := by + unfold markedCycleLaw + infer_instance + +noncomputable def durationLaw : Measure ℕ := markedCycleLaw.map Prod.fst + +instance durationLaw_isProbabilityMeasure : IsProbabilityMeasure durationLaw := + (Measure.isProbabilityMeasure_map_iff (μ := markedCycleLaw) + measurable_fst.aemeasurable).mpr inferInstance + +theorem durationLaw_ge_two : ∀ᵐ n ∂durationLaw, 2 ≤ n := by + apply (ae_map_iff measurable_fst.aemeasurable measurableSet_Ici).mpr + exact markedReturnLaw_duration_ge_two _ + +theorem durationLaw_positive : ∀ᵐ n ∂durationLaw, 0 < n := by + filter_upwards [durationLaw_ge_two] with n hn + omega + +theorem markedCycleLaw_cost_projection : + markedCycleLaw.map (fun x => x.2.2) = cycleCostLaw := by + have h := markedReturnLaw_forget (RegenerationTails.regenerationState, 0) + change markedCycleLaw.map Prod.snd = returnLaw (RegenerationTails.regenerationState, 0) at h + rw [cycleCostLaw, ← h, Measure.map_map measurable_snd measurable_snd] + rfl + +theorem durationLaw_lintegral (H : ℕ → ℝ≥0∞) : + (∫⁻ n, H n ∂durationLaw) = ∑' n : ℕ, + H (2 * (n + 1)) * firstReturn n (RegenerationTails.regenerationState, 0) univ := by + have hH : Measurable H := measurable_of_countable H + rw [durationLaw, lintegral_map hH measurable_fst, markedCycleLaw, + markedReturnLaw, Kernel.sum_apply, lintegral_sum_measure] + apply tsum_congr + intro n + rw [firstMarkedReturn, Kernel.map_apply _ (markReturn_measurable n), + lintegral_map (f := fun x : MarkedReturn => H x.1) (hH.comp measurable_fst) (markReturn_measurable n)] + change (∫⁻ _z, H (2 * (n + 1)) ∂firstReturn n (RegenerationTails.regenerationState, 0)) = _ + rw [lintegral_const] + +end NumberTheoryLean.MarkedCycleLaw + +end + +section + +namespace NumberTheoryLean.CycleDurationMoments + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open TransitionKernels PairedHitting PairedDrift PairedBlockContraction PairedCostProcess +open CostReturnLaw MarkedCycleLaw + +noncomputable def durationFrom (z : OddCost) : Measure ℕ := (markedReturnLaw z).map Prod.fst + +instance durationFrom_isProbabilityMeasure (z : OddCost) : IsProbabilityMeasure (durationFrom z) := + (Measure.isProbabilityMeasure_map_iff (μ := markedReturnLaw z) + measurable_fst.aemeasurable).mpr inferInstance + +theorem durationFrom_lintegral (z : OddCost) (H : ℕ → ℝ≥0∞) : + (∫⁻ n, H n ∂durationFrom z) = ∑' n : ℕ, H (2 * (n + 1)) * firstReturn n z univ := by + have hH : Measurable H := measurable_of_countable H + rw [durationFrom, lintegral_map hH measurable_fst, markedReturnLaw, Kernel.sum_apply, lintegral_sum_measure] + apply tsum_congr + intro n + rw [firstMarkedReturn, Kernel.map_apply _ (markReturn_measurable n), + lintegral_map (f := fun x : MarkedReturn => H x.1) (hH.comp measurable_fst) (markReturn_measurable n)] + change (∫⁻ _y, H (2 * (n + 1)) ∂firstReturn n z) = _ + rw [lintegral_const] + +theorem firstReturn_geometric : ∃ m : ℕ, 0 < m ∧ ∃ ρ D : ℝ, 0 < ρ ∧ ρ < 1 ∧ 0 < D ∧ + ∀ n : ℕ, ∀ z : OddCost, firstReturn n z univ ≤ ENNReal.ofReal (ρ ^ (n / m) * (V z.1 + D)) := by + obtain ⟨m, hm, ρ, D, hρ, hρ1, hD, hb⟩ := paired_survival_geometric + refine ⟨m, hm, ρ, D, hρ, hρ1, hD, ?_⟩ + intro n z + calc + _ ≤ firstReturn n z univ + (costKilled ^ (n + 1)) z univ := le_add_of_nonneg_right zero_le + _ = (costKilled ^ n) z univ := return_mass_step n z + _ = (pairedKilled ^ n) z.1 univ := costKilled_mass n z + _ ≤ (pairedKilled ^ (m * (n / m))) z.1 univ := paired_survival_antitone z.1 (Nat.mul_div_le n m) + _ ≤ _ := hb (n / m) z.1 + +theorem weighted_geometric_bound {m : ℕ} (hm : 0 < m) {ρ θ : ℝ} + (hρ : 0 < ρ) (hθ : 0 < θ) (hrel : 4 * (m : ℝ) * θ = -Real.log ρ) (n : ℕ) : + Real.exp (θ * (2 * ((n : ℝ) + 1))) * ρ ^ (n / m) ≤ + Real.exp (-Real.log ρ + 2 * θ) * (Real.exp (-2 * θ)) ^ n := by + have hlog : Real.log ρ = -4 * (m : ℝ) * θ := by linarith + have hmod : ((n % m : ℕ) : ℝ) < (m : ℝ) := by exact_mod_cast Nat.mod_lt n hm + have hdiv : (n : ℝ) = (m : ℝ) * ((n / m : ℕ) : ℝ) + ((n % m : ℕ) : ℝ) := by + have h : ((n % m : ℕ) : ℝ) + (m : ℝ) * ((n / m : ℕ) : ℝ) = (n : ℝ) := by + exact_mod_cast Nat.mod_add_div n m + linarith + have he : θ * (2 * ((n : ℝ) + 1)) + ((n / m : ℕ) : ℝ) * Real.log ρ ≤ + (-Real.log ρ + 2 * θ) + (n : ℝ) * (-2 * θ) := by + rw [hlog, hdiv] + nlinarith [mul_nonneg hθ.le (sub_nonneg.mpr hmod.le)] + calc + _ = Real.exp (θ * (2 * ((n : ℝ) + 1)) + ((n / m : ℕ) : ℝ) * Real.log ρ) := by + rw [Real.exp_add, Real.exp_nat_mul, Real.exp_log hρ] + _ ≤ Real.exp ((-Real.log ρ + 2 * θ) + (n : ℝ) * (-2 * θ)) := Real.exp_le_exp.mpr he + _ = _ := by rw [Real.exp_add, Real.exp_nat_mul] + +theorem return_duration_exponential_moment : ∃ θ : ℝ, 0 < θ ∧ ∀ z : OddCost, + (∫⁻ n, ENNReal.ofReal (Real.exp (θ * (n : ℝ))) ∂durationFrom z) < ∞ := by + obtain ⟨m, hm, ρ, D, hρ, hρ1, hD, hb⟩ := firstReturn_geometric + let θ := -Real.log ρ / (4 * (m : ℝ)) + have hmR : 0 < (m : ℝ) := by exact_mod_cast hm + have hθ : 0 < θ := div_pos (neg_pos.mpr (Real.log_neg hρ hρ1)) (by positivity) + have hrel : 4 * (m : ℝ) * θ = -Real.log ρ := by dsimp [θ]; field_simp + refine ⟨θ, hθ, ?_⟩ + intro z + let A := Real.exp (-Real.log ρ + 2 * θ) * (V z.1 + D) + let r := Real.exp (-2 * θ) + have hr0 : 0 ≤ r := (Real.exp_pos _).le + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by linarith) + have hsum : Summable (fun n : ℕ => A * r ^ n) := (summable_geometric_of_lt_one hr0 hr1).mul_left A + rw [durationFrom_lintegral] + apply lt_of_le_of_lt (ENNReal.tsum_le_tsum ?_) hsum.tsum_ofReal_lt_top + intro n + have hW : 0 < V z.1 + D := add_pos (V_pos z.1) hD + have hn := weighted_geometric_bound hm hρ hθ hrel n + simp only [Nat.cast_mul, Nat.cast_ofNat, Nat.cast_add, Nat.cast_one] + calc + _ ≤ ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * + ENNReal.ofReal (ρ ^ (n / m) * (V z.1 + D)) := mul_le_mul le_rfl (hb n z) zero_le zero_le + _ = ENNReal.ofReal ((Real.exp (θ * (2 * ((n : ℝ) + 1)))) * ρ ^ (n / m) * (V z.1 + D)) := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le] + congr 1 + ring + _ ≤ ENNReal.ofReal (A * r ^ n) := ENNReal.ofReal_le_ofReal (by + dsimp [A, r] + nlinarith [mul_le_mul_of_nonneg_right hn hW.le]) + +theorem return_duration_exponential_integrable : ∃ θ : ℝ, 0 < θ ∧ ∀ z : OddCost, + Integrable (fun n : ℕ => Real.exp (θ * (n : ℝ))) (durationFrom z) := by + obtain ⟨θ, hθ, hb⟩ := return_duration_exponential_moment + refine ⟨θ, hθ, ?_⟩ + intro z + refine ⟨(measurable_of_countable _).aestronglyMeasurable, ?_⟩ + exact (hasFiniteIntegral_iff_ofReal (Eventually.of_forall (fun n : ℕ => (Real.exp_pos (θ * (n : ℝ))).le))).mpr (hb z) + +theorem cycle_duration_exponential_integrable : ∃ θ : ℝ, 0 < θ ∧ + Integrable (fun n : ℕ => Real.exp (θ * (n : ℝ))) durationLaw := by + obtain ⟨θ, hθ, hb⟩ := return_duration_exponential_integrable + exact ⟨θ, hθ, hb (RegenerationTails.regenerationState, 0)⟩ + +end NumberTheoryLean.CycleDurationMoments + +end + +section + +namespace NumberTheoryLean.CycleCostMoments + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostProcess CostReturnLaw +open MarkedCycleLaw CycleDurationMoments + +theorem draw_cost_le_log_three {s : ℝ} (hs : 1 / 2 ≤ s) : cost s ≤ Real.log 3 := by + have hs0 : 0 < s := by linarith + have hi : 1 / s ≤ 2 := (div_le_iff₀ hs0).mpr (by linarith) + unfold cost + exact Real.log_le_log (by positivity) (by linarith) + +theorem pairedCost_cost_upper (z : OddCost) : + ∀ᵐ y ∂pairedCostKernel z, y.2 ≤ z.2 + 2 * Real.log 3 := by + apply ae_iff.mpr + simp only [not_le] + change pairedCostKernel z {y : OddCost | z.2 + 2 * Real.log 3 < y.2} = 0 + rw [pairedCostKernel_apply z (measurableSet_lt measurable_const measurable_snd)] + have he : {x : EvenState × OddState | (x.2, z.2 + cost x.1.1 + cost x.2.1) ∈ + {y : OddCost | z.2 + 2 * Real.log 3 < y.2}} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro x hx + have h1 := draw_cost_le_log_three (s := x.1.1) (by linarith [x.1.2]) + have h2 := draw_cost_le_log_three (s := x.2.1) (by linarith [x.2.2]) + change z.2 + 2 * Real.log 3 < z.2 + cost x.1.1 + cost x.2.1 at hx + linarith + rw [he, measure_empty] + +theorem costKilled_cost_upper (z : OddCost) : + ∀ᵐ y ∂costKilled z, y.2 ≤ z.2 + 2 * Real.log 3 := ae_restrict_of_ae (pairedCost_cost_upper z) + +theorem costKilled_pow_cost_upper (n : ℕ) (z : OddCost) : + ∀ᵐ y ∂(costKilled ^ n) z, y.2 ≤ z.2 + 2 * (n : ℝ) * Real.log 3 := by + induction n generalizing z with + | zero => + simp only [Nat.cast_zero, mul_zero, zero_mul, add_zero] + change ∀ᵐ y ∂Measure.dirac z, y.2 ≤ z.2 + exact (ae_dirac_iff (measurableSet_le measurable_snd measurable_const)).mpr le_rfl + | succ n ih => + have hp : costKilled ^ (n + 1) = costKilled ∘ₖ (costKilled ^ n) := pow_succ' costKilled n + rw [hp] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_snd measurable_const) + filter_upwards [ih z] with y hy + filter_upwards [costKilled_cost_upper y] with w hw + push_cast + nlinarith + +theorem captured_cost_upper (z : OddCost) : + ∀ᵐ y ∂costCaptured z, y.2 ≤ z.2 + 2 * Real.log 3 := ae_restrict_of_ae (pairedCost_cost_upper z) + +theorem firstReturn_cost_upper (n : ℕ) (z : OddCost) : + ∀ᵐ y ∂firstReturn n z, y.2 ≤ z.2 + 2 * ((n + 1 : ℕ) : ℝ) * Real.log 3 := by + rw [firstReturn] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_snd measurable_const) + filter_upwards [costKilled_pow_cost_upper n z] with y hy + filter_upwards [captured_cost_upper y] with w hw + push_cast + nlinarith + +theorem markedReturn_cost_upper (z : OddCost) : + ∀ᵐ x ∂markedReturnLaw z, x.2.2 ≤ z.2 + (x.1 : ℝ) * Real.log 3 := by + rw [markedReturnLaw, Kernel.sum_apply, Measure.ae_sum_iff] + intro n + rw [firstMarkedReturn, Kernel.map_apply _ (markReturn_measurable n)] + have hm : Measurable (fun x : MarkedReturn => z.2 + (x.1 : ℝ) * Real.log 3) := + measurable_const.add (((measurable_of_countable (fun n : ℕ => (n : ℝ))).comp measurable_fst).mul measurable_const) + apply (ae_map_iff (markReturn_measurable n).aemeasurable + (measurableSet_le (measurable_snd.comp measurable_snd) hm)).mpr + filter_upwards [firstReturn_cost_upper n z] with x hx + change x.2 ≤ z.2 + ((2 * (n + 1) : ℕ) : ℝ) * Real.log 3 + simpa only [Nat.cast_mul, Nat.cast_ofNat] using hx + +theorem markedCycle_cost_upper : ∀ᵐ x ∂markedCycleLaw, x.2.2 ≤ (x.1 : ℝ) * Real.log 3 := by + have h := markedReturn_cost_upper (RegenerationTails.regenerationState, 0) + convert! h using 1 + simp + +theorem cycle_cost_exponential_moment : ∃ η : ℝ, 0 < η ∧ + (∫⁻ G, ENNReal.ofReal (Real.exp (η * G)) ∂cycleCostLaw) < ∞ := by + obtain ⟨θ, hθ, hb⟩ := return_duration_exponential_moment + have hL : 0 < Real.log 3 := Real.log_pos (by norm_num) + let η := θ / Real.log 3 + have hη : 0 < η := div_pos hθ hL + refine ⟨η, hη, ?_⟩ + rw [← markedCycleLaw_cost_projection, + lintegral_map (g := fun x : MarkedReturn => x.2.2) (f := fun G : ℝ => ENNReal.ofReal (Real.exp (η * G))) + (ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp (measurable_const.mul measurable_id))) + (measurable_snd.comp measurable_snd)] + have hbound : (∫⁻ x : MarkedReturn, ENNReal.ofReal (Real.exp (η * x.2.2)) ∂markedCycleLaw) ≤ + ∫⁻ x : MarkedReturn, ENNReal.ofReal (Real.exp (θ * (x.1 : ℝ))) ∂markedCycleLaw := by + apply lintegral_mono_ae + filter_upwards [markedCycle_cost_upper] with x hx + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + have heq : η * ((x.1 : ℝ) * Real.log 3) = θ * (x.1 : ℝ) := by dsimp [η]; field_simp [ne_of_gt hL] + nlinarith [mul_le_mul_of_nonneg_left hx hη.le] + apply lt_of_le_of_lt hbound + have h := hb (RegenerationTails.regenerationState, 0) + rw [durationFrom, lintegral_map (measurable_of_countable (fun n : ℕ => ENNReal.ofReal (Real.exp (θ * (n : ℝ))))) measurable_fst] at h + exact h + +theorem cycle_cost_exponential_integrable : ∃ η : ℝ, 0 < η ∧ + Integrable (fun G : ℝ => Real.exp (η * G)) cycleCostLaw := by + obtain ⟨η, hη, hb⟩ := cycle_cost_exponential_moment + refine ⟨η, hη, ⟨(Real.continuous_exp.comp (continuous_const.mul continuous_id)).aestronglyMeasurable, ?_⟩⟩ + exact (hasFiniteIntegral_iff_ofReal (Eventually.of_forall (fun G : ℝ => (Real.exp_pos (η * G)).le))).mpr hb + +end NumberTheoryLean.CycleCostMoments + +end + +section + +namespace NumberTheoryLean.CycleOccupation + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostProcess PairedCostGrouping +open CostReturnLaw CycleCostLower CycleCostMoments + +noncomputable def pairSampling : Kernel OddCost (OddCost × (EvenState × OddState)) := + Kernel.id ×ₖ pairedDraws.prodMkRight ℝ + +instance pairSampling_isMarkovKernel : IsMarkovKernel pairSampling := by unfold pairSampling; infer_instance + +noncomputable def evenVisitMap (x : OddCost × (EvenState × OddState)) : CostState := + (.inl x.2.1, x.1.2 + cost x.2.1.1) + +noncomputable def oddVisitMap (x : OddCost × (EvenState × OddState)) : CostState := + (.inr x.2.2, x.1.2 + cost x.2.1.1 + cost x.2.2.1) + +theorem evenVisitMap_measurable : Measurable evenVisitMap := + (measurable_inl.comp (measurable_fst.comp measurable_snd)).prodMk + ((measurable_snd.comp measurable_fst).add + (cost_measurable.comp (measurable_subtype_coe.comp (measurable_fst.comp measurable_snd)))) + +theorem oddVisitMap_measurable : Measurable oddVisitMap := + (measurable_inr.comp (measurable_snd.comp measurable_snd)).prodMk + (((measurable_snd.comp measurable_fst).add + (cost_measurable.comp (measurable_subtype_coe.comp (measurable_fst.comp measurable_snd)))).add + (cost_measurable.comp (measurable_subtype_coe.comp (measurable_snd.comp measurable_snd)))) + +noncomputable def evenVisit : Kernel OddCost CostState := pairSampling.map evenVisitMap +noncomputable def oddVisit : Kernel OddCost CostState := pairSampling.map oddVisitMap + +instance evenVisit_isMarkovKernel : IsMarkovKernel evenVisit := Kernel.IsMarkovKernel.map _ evenVisitMap_measurable +instance oddVisit_isMarkovKernel : IsMarkovKernel oddVisit := Kernel.IsMarkovKernel.map _ oddVisitMap_measurable + +theorem sampling_map_measure {α : Type*} [MeasurableSpace α] + (f : OddCost × (EvenState × OddState) → α) (hf : Measurable f) (z : OddCost) : + (pairSampling.map f) z = (pairedDraws z.1).map (fun x => f (z, x)) := by + ext B hB + rw [Kernel.map_apply' _ hf _ hB, pairSampling, + Kernel.prod_apply' _ _ _ (hf hB), Kernel.id_apply, lintegral_dirac'] + · rw [Measure.map_apply (f := fun x : EvenState × OddState => f (z, x)) (hf.comp measurable_prodMk_left) hB] + rfl + · exact measurable_measure_prodMk_left (hf hB) + +theorem evenVisit_eq_full_step (z : OddCost) : evenVisit z = costKernel (embedOdd z) := by + apply Measure.ext_of_lintegral + intro H hH + rw [evenVisit, sampling_map_measure _ evenVisitMap_measurable, + lintegral_map (g := fun x : EvenState × OddState => evenVisitMap (z, x)) hH + (evenVisitMap_measurable.comp measurable_prodMk_left), pairedDraws, + Kernel.lintegral_compProd _ _ _ (f := fun x : EvenState × OddState => H (evenVisitMap (z, x))) + (hH.comp (evenVisitMap_measurable.comp measurable_prodMk_left))] + change (∫⁻ t : EvenState, ∫⁻ _u : OddState, H (.inl t, z.2 + cost t.1) ∂evenToOdd t ∂oddToEven z.1) = _ + simp only [lintegral_const, measure_univ, mul_one] + exact (costKernel_odd_lintegral z.1 z.2 hH).symm + +theorem oddVisit_eq_paired (z : OddCost) : oddVisit z = (pairedCostKernel z).map embedOdd := by + have h : oddVisit = pairedCostKernel.map embedOdd := by + rw [oddVisit, pairedCostKernel, ← Kernel.map_comp_right _ pairUpdate_measurable embedOdd_measurable] + rfl + rw [h, Kernel.map_apply _ embedOdd_measurable] + +noncomputable def pairVisits : Kernel OddCost CostState := evenVisit + oddVisit + +instance pairVisits_isFiniteKernel : IsFiniteKernel pairVisits := by unfold pairVisits; infer_instance + +theorem pairVisits_full_steps (z : OddCost) : + pairVisits z = costKernel (embedOdd z) + (costKernel ^ 2) (embedOdd z) := by + rw [pairVisits, add_apply, evenVisit_eq_full_step, oddVisit_eq_paired, pairedCost_full_grouping] + +theorem pairVisits_mass (z : OddCost) : pairVisits z univ = 2 := by + rw [pairVisits, add_apply, Measure.add_apply] + simp only [measure_univ] + norm_num + +theorem evenVisit_age_bounds (z : OddCost) : + ∀ᵐ y ∂evenVisit z, z.2 ≤ y.2 ∧ y.2 ≤ z.2 + 2 * Real.log 3 := by + rw [evenVisit, sampling_map_measure _ evenVisitMap_measurable] + apply (ae_map_iff (evenVisitMap_measurable.comp measurable_prodMk_left).aemeasurable + ((measurableSet_le measurable_const measurable_snd).inter (measurableSet_le measurable_snd measurable_const))).mpr + apply Eventually.of_forall + intro x + have hp : 0 < cost x.1.1 := cost_pos (by linarith [x.1.2]) + have hu := draw_cost_le_log_three (s := x.1.1) (by linarith [x.1.2]) + have hL : 0 < Real.log 3 := Real.log_pos (by norm_num) + change z.2 ≤ z.2 + cost x.1.1 ∧ z.2 + cost x.1.1 ≤ z.2 + 2 * Real.log 3 + constructor <;> linarith + +theorem oddVisit_age_bounds (z : OddCost) : + ∀ᵐ y ∂oddVisit z, z.2 ≤ y.2 ∧ y.2 ≤ z.2 + 2 * Real.log 3 := by + rw [oddVisit, sampling_map_measure _ oddVisitMap_measurable] + apply (ae_map_iff (oddVisitMap_measurable.comp measurable_prodMk_left).aemeasurable + ((measurableSet_le measurable_const measurable_snd).inter (measurableSet_le measurable_snd measurable_const))).mpr + apply Eventually.of_forall + intro x + have hp : 0 < cost x.1.1 := cost_pos (by linarith [x.1.2]) + have hq : 0 < cost x.2.1 := cost_pos (by linarith [x.2.2]) + have hu := draw_cost_le_log_three (s := x.1.1) (by linarith [x.1.2]) + have hv := draw_cost_le_log_three (s := x.2.1) (by linarith [x.2.2]) + change z.2 ≤ z.2 + cost x.1.1 + cost x.2.1 ∧ + z.2 + cost x.1.1 + cost x.2.1 ≤ z.2 + 2 * Real.log 3 + constructor <;> linarith + +theorem pairVisits_age_bounds (z : OddCost) : + ∀ᵐ y ∂pairVisits z, z.2 ≤ y.2 ∧ y.2 ≤ z.2 + 2 * Real.log 3 := by + rw [pairVisits, add_apply, ae_add_measure_iff] + exact ⟨evenVisit_age_bounds z, oddVisit_age_bounds z⟩ + +noncomputable def visitBlock (n : ℕ) : Kernel OddCost CostState := pairVisits ∘ₖ (costKilled ^ n) + +instance visitBlock_isFiniteKernel (n : ℕ) : IsFiniteKernel (visitBlock n) := by unfold visitBlock; infer_instance + +theorem visitBlock_mass (n : ℕ) (z : OddCost) : visitBlock n z univ = 2 * (costKilled ^ n) z univ := by + rw [visitBlock, Kernel.comp_apply' _ _ _ MeasurableSet.univ] + simp only [pairVisits_mass, lintegral_const] + +theorem visitBlock_age_bounds (n : ℕ) (z : OddCost) : + ∀ᵐ y ∂visitBlock n z, z.2 ≤ y.2 ∧ y.2 ≤ z.2 + 2 * ((n + 1 : ℕ) : ℝ) * Real.log 3 := by + rw [visitBlock] + apply Kernel.ae_comp_of_ae_ae + ((measurableSet_le measurable_const measurable_snd).inter (measurableSet_le measurable_snd measurable_const)) + filter_upwards [costKilled_pow_cost_monotone n z, costKilled_pow_cost_upper n z] with w hwL hwU + filter_upwards [pairVisits_age_bounds w] with y hy + constructor + · exact le_trans hwL hy.1 + · calc + y.2 ≤ w.2 + 2 * Real.log 3 := hy.2 + _ ≤ (z.2 + 2 * (n : ℝ) * Real.log 3) + 2 * Real.log 3 := add_le_add hwU le_rfl + _ = _ := by push_cast; ring + +noncomputable def occupationKernel : Kernel OddCost CostState := Kernel.sum visitBlock + +instance occupationKernel_isSFiniteKernel : IsSFiniteKernel occupationKernel := by unfold occupationKernel; infer_instance + +noncomputable def occupationMeasure : Measure CostState := occupationKernel (RegenerationTails.regenerationState, 0) + +theorem occupation_age_nonneg : ∀ᵐ y ∂occupationMeasure, 0 ≤ y.2 := by + rw [occupationMeasure, occupationKernel, Kernel.sum_apply, Measure.ae_sum_iff] + intro n + exact (visitBlock_age_bounds n (RegenerationTails.regenerationState, 0)).mono (fun _ h => h.1) + +theorem occupationFrom_exponential_moment : ∃ η : ℝ, 0 < η ∧ ∀ z : OddCost, + (∫⁻ y, ENNReal.ofReal (Real.exp (η * (y.2 - z.2))) ∂occupationKernel z) < ∞ := by + obtain ⟨m, hm, ρ, D, hρ, hρ1, hD, hb⟩ := PairedBlockContraction.paired_survival_geometric + let θ := -Real.log ρ / (4 * (m : ℝ)) + have hmR : 0 < (m : ℝ) := by exact_mod_cast hm + have hθ : 0 < θ := div_pos (neg_pos.mpr (Real.log_neg hρ hρ1)) (by positivity) + have hrel : 4 * (m : ℝ) * θ = -Real.log ρ := by dsimp [θ]; field_simp + have hL : 0 < Real.log 3 := Real.log_pos (by norm_num) + let η := θ / Real.log 3 + have hη : 0 < η := div_pos hθ hL + refine ⟨η, hη, ?_⟩ + intro z + let A := 2 * Real.exp (-Real.log ρ + 2 * θ) * (PairedDrift.V z.1 + D) + let r := Real.exp (-2 * θ) + have hr0 : 0 ≤ r := (Real.exp_pos _).le + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by linarith) + have hsum : Summable (fun n : ℕ => A * r ^ n) := (summable_geometric_of_lt_one hr0 hr1).mul_left A + rw [occupationKernel, Kernel.sum_apply, lintegral_sum_measure] + apply lt_of_le_of_lt (ENNReal.tsum_le_tsum ?_) hsum.tsum_ofReal_lt_top + intro n + have hW : 0 < PairedDrift.V z.1 + D := add_pos (PairedDrift.V_pos z.1) hD + have hn := CycleDurationMoments.weighted_geometric_bound hm hρ hθ hrel n + have hsurv : (costKilled ^ n) z univ ≤ ENNReal.ofReal (ρ ^ (n / m) * (PairedDrift.V z.1 + D)) := by + rw [costKilled_mass] + exact le_trans (PairedHitting.paired_survival_antitone z.1 (Nat.mul_div_le n m)) (hb (n / m) z.1) + calc + _ ≤ ∫⁻ _y, ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) ∂visitBlock n z := by + apply lintegral_mono_ae + filter_upwards [visitBlock_age_bounds n z] with y hy + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + calc + η * (y.2 - z.2) ≤ η * (2 * ((n + 1 : ℕ) : ℝ) * Real.log 3) := + mul_le_mul_of_nonneg_left (by linarith [hy.2]) hη.le + _ = θ * (2 * ((n : ℝ) + 1)) := by dsimp [η]; push_cast; field_simp + _ = ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * + (2 * (costKilled ^ n) z univ) := by rw [lintegral_const, visitBlock_mass] + _ ≤ ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * + (2 * ENNReal.ofReal (ρ ^ (n / m) * (PairedDrift.V z.1 + D))) := + mul_le_mul le_rfl (mul_le_mul le_rfl hsurv zero_le zero_le) zero_le zero_le + _ = ENNReal.ofReal (2 * (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * ρ ^ (n / m) * (PairedDrift.V z.1 + D)) := by + rw [show (2 : ℝ≥0∞) = ENNReal.ofReal (2 : ℝ) by norm_num, + ← ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≤ 2), + ← ENNReal.ofReal_mul (Real.exp_pos _).le] + congr 1 + ring + _ ≤ ENNReal.ofReal (A * r ^ n) := ENNReal.ofReal_le_ofReal (by + dsimp [A, r] + nlinarith [mul_le_mul_of_nonneg_right hn hW.le]) + +theorem occupation_exponential_moment : ∃ η : ℝ, 0 < η ∧ + (∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂occupationMeasure) < ∞ := by + obtain ⟨η, hη, hb⟩ := occupationFrom_exponential_moment + exact ⟨η, hη, by simpa only [occupationMeasure, sub_zero] using hb (RegenerationTails.regenerationState, 0)⟩ + +instance occupationMeasure_isFiniteMeasure : IsFiniteMeasure occupationMeasure := by + obtain ⟨η, hη, hb⟩ := occupation_exponential_moment + constructor + apply lt_of_le_of_lt (show occupationMeasure univ ≤ ∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂occupationMeasure from ?_) hb + calc + _ = ∫⁻ _y, (1 : ℝ≥0∞) ∂occupationMeasure := by simp + _ ≤ _ := by + apply lintegral_mono_ae + filter_upwards [occupation_age_nonneg] with y hy + exact ENNReal.one_le_ofReal.mpr (Real.one_le_exp (mul_nonneg hη.le hy)) + +theorem occupation_exponential_integrable : ∃ η : ℝ, 0 < η ∧ + Integrable (fun y : CostState => Real.exp (η * y.2)) occupationMeasure := by + obtain ⟨η, hη, hb⟩ := occupation_exponential_moment + refine ⟨η, hη, (Real.measurable_exp.comp (measurable_const.mul measurable_snd)).aestronglyMeasurable, ?_⟩ + exact (hasFiniteIntegral_iff_ofReal (Eventually.of_forall + (fun y : CostState => (Real.exp_pos (η * y.2)).le))).mpr hb + +end NumberTheoryLean.CycleOccupation + +end + +section + +namespace NumberTheoryLean.CycleRenewalInputs + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open CostReturnLaw CycleCostLower CycleCostMoments CycleCostAtomless +open AbsorptionCutoff.Renewal + +theorem cycle_negative_exponential_integrable {η : ℝ} (hη : 0 ≤ η) : + Integrable (fun G : ℝ => Real.exp (-η * G)) cycleCostLaw := by + refine (integrable_const (1 : ℝ)).mono' + ((Real.continuous_exp.comp (continuous_const.mul continuous_id)).aestronglyMeasurable) ?_ + filter_upwards [cycleCostLaw_positive] with G hG + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_one_iff.mpr (by nlinarith) + +theorem cycle_all_moments (n : ℕ) : Integrable (fun G : ℝ => G ^ n) cycleCostLaw := by + obtain ⟨η, hη, hp⟩ := cycle_cost_exponential_integrable + have hn := cycle_negative_exponential_integrable hη.le + simpa only [id_eq] using integrable_pow_of_integrable_exp_mul (μ := cycleCostLaw) + (X := id) (ne_of_gt hη) hp hn n + +theorem cycle_integrable_id : Integrable id cycleCostLaw := by + convert! cycle_all_moments 1 using 1 + simp + rfl + +theorem cycle_memLp_two : MemLp id 2 cycleCostLaw := by + apply (memLp_two_iff_integrable_sq measurable_id.aestronglyMeasurable).mpr + exact cycle_all_moments 2 + +theorem cycle_mean_lower : Real.log (4 / 3) ≤ ∫ G : ℝ, G ∂cycleCostLaw := by + have h := integral_mono_ae (integrable_const (Real.log (4 / 3))) cycle_integrable_id cycleCostLaw_lower + simpa using h + +theorem cycle_mean_pos : 0 < ∫ G : ℝ, G ∂cycleCostLaw := + lt_of_lt_of_le (Real.log_pos (by norm_num)) cycle_mean_lower + +theorem cycle_nonlattice : Nonlattice cycleCostLaw := by + intro a r + rw [cycleCostLaw_lattice_null] + norm_num + +theorem cycle_expTransform_le : expTransform 1 cycleCostLaw ≤ ENNReal.ofReal (3 / 4 : ℝ) := by + unfold expTransform + simp only [one_mul] + have heq : Real.exp (-Real.log (4 / 3)) = (3 : ℝ) / 4 := by + rw [Real.exp_neg, Real.exp_log (by norm_num : (0 : ℝ) < 4 / 3)] + norm_num + calc + _ ≤ ∫⁻ _G : ℝ, ENNReal.ofReal (Real.exp (-Real.log (4 / 3))) ∂cycleCostLaw := by + apply lintegral_mono_ae + filter_upwards [cycleCostLaw_lower] with G hG + exact ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr (by linarith)) + _ = _ := by rw [lintegral_const, measure_univ, mul_one, heq] + +theorem cycle_expTransform_lt_one : expTransform 1 cycleCostLaw < 1 := + lt_of_le_of_lt cycle_expTransform_le (by norm_num) + +theorem cycle_key_renewal {H : ℝ → ℝ} (hH : Continuous H) + (hDRI : driNorm (fun x => ‖H x‖ₑ) ≠ ∞) : + Tendsto (fun y : ℝ => ∑' n : ℕ, ∫ s, H (y - s) ∂convPow cycleCostLaw n) + atTop (𝓝 ((∫ x : ℝ, H x) / (∫ G : ℝ, G ∂cycleCostLaw))) := + tendsto_tsum_integral_comp_sub_of_driNorm_real cycle_nonlattice cycle_memLp_two cycle_mean_pos + (θ := 1) (by norm_num) cycle_expTransform_lt_one hH hDRI + +theorem cycle_renewal_cell_bound (ell : ℝ) : ∃ C : ℝ, ∀ y : ℝ, + renewalMeasure cycleCostLaw (Icc y (y + ell)) ≤ ENNReal.ofReal C := + exists_bound_renewalMeasure_Icc_of_expTransform cycle_nonlattice cycle_memLp_two cycle_mean_pos + (θ := 1) (by norm_num) cycle_expTransform_lt_one ell + +end NumberTheoryLean.CycleRenewalInputs + +end + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.ActualCycleOccupation +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathGeometry NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.PairedHitting NumberTheoryLean.PairedCostProcess NumberTheoryLean.PairedCostGrouping +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.CycleOccupation NumberTheoryLean.KernelPotential +open Erdos970Dependency.InvariantDensities Erdos970Dependency.StateKernelInvariance +open Erdos970Dependency.RegenerativeOddOccupation + +theorem costKernel_map_state (z : CostState) : (costKernel z).map Prod.fst = stateKernel z.1 := by + have hm : Measurable (fun s : State ↦ (s, z.2 + cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + rw [costKernel_eq_map, Measure.map_map measurable_fst hm] + change (stateKernel z.1).map id = stateKernel z.1 + exact Measure.map_id + +theorem evenVisit_map_state (z : OddCost) : + (evenVisit z).map Prod.fst = (oddToEven z.1).map Sum.inl := by + rw [evenVisit_eq_full_step, costKernel_map_state] + change oddBranch z.1 = _ + exact Kernel.map_apply _ measurable_inl _ + +theorem oddVisit_map_state (z : OddCost) : + (oddVisit z).map Prod.fst = (pairedOdd z.1).map Sum.inr := by + rw [oddVisit_eq_paired, Measure.map_map measurable_fst embedOdd_measurable, + ← pairedCost_map_state z, Measure.map_map measurable_inr measurable_fst] + rfl + +theorem pairVisits_map_state (z : OddCost) : (pairVisits z).map Prod.fst = ratioVisits z.1 := by + rw [pairVisits, add_apply, Measure.map_add _ _ measurable_fst, evenVisit_map_state, oddVisit_map_state] + simp only [ratioVisits, add_apply, Kernel.map_apply _ measurable_inl, Kernel.map_apply _ measurable_inr] + +theorem visitBlock_map_state (n : ℕ) (z : OddCost) : + (visitBlock n z).map Prod.fst = (ratioVisits ∘ₖ (pairedKilled ^ n)) z.1 := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH measurable_fst, visitBlock, + Kernel.lintegral_comp _ _ _ (g := fun y : CostState ↦ H y.1) (hH.comp measurable_fst), + Kernel.lintegral_comp _ _ _ hH] + have hi (w : OddCost) : (∫⁻ y : CostState, H y.1 ∂pairVisits w) = + ∫⁻ s : State, H s ∂ratioVisits w.1 := by + rw [← pairVisits_map_state w, lintegral_map hH measurable_fst] + simp_rw [hi] + have hJ : Measurable (fun s : OddState ↦ ∫⁻ t : State, H t ∂ratioVisits s) := hH.lintegral_kernel + rw [← costKilled_pow_map_state n z, lintegral_map hJ measurable_fst] + +theorem occupation_map_ratioOccupation : occupationMeasure.map Prod.fst = ratioOccupation := by + rw [occupationMeasure, occupationKernel, Kernel.sum_apply, Measure.map_sum measurable_fst.aemeasurable] + simp_rw [visitBlock_map_state] + rw [ratioOccupation, potential, Kernel.sum_apply] + +theorem occupation_map_stateMeasure : + occupationMeasure.map Prod.fst = (ENNReal.ofReal beta)⁻¹ • stateMeasure := by + rw [occupation_map_ratioOccupation, ratioOccupation_eq] + +theorem lintegral_state_occupation {Q : State → ℝ≥0∞} (hQ : Measurable Q) : + (∫⁻ y : CostState, Q y.1 ∂occupationMeasure) = + (ENNReal.ofReal beta)⁻¹ * ∫⁻ s : State, Q s ∂stateMeasure := by + rw [← lintegral_map hQ measurable_fst, occupation_map_stateMeasure, lintegral_smul_measure, smul_eq_mul] + +theorem integrable_state_occupation_iff {Q : State → ℝ} (hQ : Measurable Q) : + Integrable Q stateMeasure ↔ Integrable (fun y : CostState ↦ Q y.1) occupationMeasure := by + have h := integrable_map_measure (μ := occupationMeasure) (f := Prod.fst) (g := Q) + hQ.aestronglyMeasurable measurable_fst.aemeasurable + rw [occupation_map_stateMeasure, integrable_inv_smul_measure + (ne_of_gt (ENNReal.ofReal_pos.mpr beta_pos)) ENNReal.ofReal_ne_top] at h + simpa only [Function.comp_def] using h + +theorem integral_state_occupation {Q : State → ℝ} (hQ : Measurable Q) + (hI : Integrable (fun y : CostState ↦ Q y.1) occupationMeasure) : + Integrable Q stateMeasure ∧ + (∫ y : CostState, Q y.1 ∂occupationMeasure) = (1 / beta) * ∫ s : State, Q s ∂stateMeasure := by + refine ⟨(integrable_state_occupation_iff hQ).mpr hI, ?_⟩ + rw [← integral_map measurable_fst.aemeasurable hQ.aestronglyMeasurable, + occupation_map_stateMeasure, integral_smul_measure, ENNReal.toReal_inv, + ENNReal.toReal_ofReal beta_pos.le, smul_eq_mul, one_div] + +end Erdos970Dependency.ActualCycleOccupation + +end + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped ENNReal ProbabilityTheory Topology +namespace Erdos970Dependency.OccupationAge +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess NumberTheoryLean.PairedCostGrouping +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.CycleOccupation NumberTheoryLean.RegenerationTails + +theorem oddAge_measurable : Measurable (fun y : OddCost ↦ ENNReal.ofReal y.2) := + ENNReal.measurable_ofReal.comp measurable_snd + +theorem stateAge_measurable : Measurable (fun y : CostState ↦ ENNReal.ofReal y.2) := + ENNReal.measurable_ofReal.comp measurable_snd + +theorem occupation_age_integrable : Integrable (fun y : CostState ↦ y.2) occupationMeasure := by + obtain ⟨eta, heta, hI⟩ := occupation_exponential_integrable + apply (hI.const_mul (1 / eta)).mono' measurable_snd.aestronglyMeasurable + filter_upwards [occupation_age_nonneg] with y hy + rw [Real.norm_of_nonneg hy] + have h := Real.add_one_le_exp (eta * y.2) + calc + y.2 = (1 / eta) * (eta * y.2) := by field_simp + _ ≤ (1 / eta) * Real.exp (eta * y.2) := mul_le_mul_of_nonneg_left (by linarith) (by positivity) + +noncomputable def blockAge (n : ℕ) : ℝ≥0∞ := + ∫⁻ y : CostState, ENNReal.ofReal y.2 ∂visitBlock n (regenerationState, 0) + +noncomputable def residualAge (n : ℕ) : ℝ≥0∞ := + ∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂(costKilled ^ n) (regenerationState, 0) + +theorem blockAge_sum_finite : (∑' n : ℕ, blockAge n) < ∞ := by + have heq : (∑' n : ℕ, blockAge n) = ∫⁻ y : CostState, ENNReal.ofReal y.2 ∂occupationMeasure := by + rw [occupationMeasure, occupationKernel, Kernel.sum_apply, lintegral_sum_measure] + rfl + rw [heq, ← ofReal_integral_eq_lintegral_ofReal occupation_age_integrable occupation_age_nonneg] + exact ENNReal.ofReal_lt_top + +theorem blockAge_tendsto_zero : Tendsto blockAge atTop (𝓝 0) := + ENNReal.tendsto_atTop_zero_of_tsum_ne_top (ne_of_lt blockAge_sum_finite) + +theorem killed_age_le_pair (z : OddCost) : + (∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂costKilled z) ≤ + ∫⁻ y : CostState, ENNReal.ofReal y.2 ∂pairVisits z := by + calc + _ ≤ ∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂pairedCostKernel z := + lintegral_mono' Measure.restrict_le_self le_rfl + _ = ∫⁻ y : CostState, ENNReal.ofReal y.2 ∂oddVisit z := by + rw [oddVisit_eq_paired, lintegral_map stateAge_measurable embedOdd_measurable] + rfl + _ ≤ _ := lintegral_mono' (by + rw [pairVisits, add_apply] + apply Measure.le_iff.mpr + intro B _ + rw [Measure.add_apply] + exact le_add_left le_rfl) le_rfl + +theorem residualAge_succ_le (n : ℕ) : residualAge (n + 1) ≤ blockAge n := by + have hp : costKilled ^ (n + 1) = costKilled ∘ₖ (costKilled ^ n) := pow_succ' costKilled n + rw [residualAge, hp, + Kernel.lintegral_comp _ _ _ oddAge_measurable, + blockAge, visitBlock, + Kernel.lintegral_comp _ _ _ stateAge_measurable] + exact lintegral_mono killed_age_le_pair + +theorem residualAge_tendsto_zero : Tendsto residualAge atTop (𝓝 0) := by + have hshift : Tendsto (fun n : ℕ ↦ residualAge (n + 1)) atTop (𝓝 0) := + tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds blockAge_tendsto_zero + (Eventually.of_forall (fun _ ↦ zero_le)) (Eventually.of_forall residualAge_succ_le) + exact (tendsto_add_atTop_iff_nat 1).mp hshift + +end Erdos970Dependency.OccupationAge + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/OccupationDensityIntegral.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/OccupationDensityIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..af37643a2e20816705c674826c63564d09d433dd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/OccupationDensityIntegral.lean @@ -0,0 +1,107 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeOccupationDensity + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.OccupationDensityIntegral + +open _root_.Set _root_.MeasureTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures InvariantInverseWeights +open CompactInverseTest CompactLogOccupationTest PrimeOccupationDensity +open CycleResponse AdmissibleCycleTests NormalizedOccupationLimit OccupationConstant +open Erdos970Dependency.StateKernelInvariance Erdos970Dependency.InvariantCostBound + +noncomputable def rawTest (H : Side → ℝ×ℝ → ℝ) (x : ℝ×State) : ℝ := + H (stateSide x.2) (Real.exp x.1,stateRatio x.2) + +theorem density_mul_raw (ell : ℝ) (H : Side → ℝ×ℝ → ℝ) (x : ℝ×State) : + density ell x*rawTest H x = arrivalTest ell H x/costMass := by + classical + by_cases h : stateRatio x.2 < Real.exp x.1/ell + · change (if stateRatio x.2 < Real.exp x.1/ell then (Real.exp x.1)^2/(stateWeight x.2*costMass) else 0)*rawTest H x = + (if stateRatio x.2 < Real.exp x.1/ell then logTest H x else 0)/costMass + rw [ite_eq_left h,ite_eq_left h] + unfold logTest + rw [inverseTest_eq (stateRatio_valid x.2),← SuccessfulRewardComparison.stateWeight_eq] + unfold rawTest + ring + · simp [density,arrivalTest,AdmissibleCycleTests.mask,h] + +theorem compactBound_product_integrable {F : Test} (hF : Measurable F) (hB : HasCompactBound F) : + Integrable F baseMeasure := by + obtain ⟨C,M,hC,hM,hbound,hsupport⟩ := hB + let A : Set (ℝ×State) := Icc (-M) M ×ˢ univ + have hA : MeasurableSet A := measurableSet_Icc.prod MeasurableSet.univ + have hfin : baseMeasure A < ∞ := by + rw [baseMeasure,Measure.prod_prod,Real.volume_Icc] + exact ENNReal.mul_lt_top ENNReal.ofReal_lt_top (measure_lt_top stateMeasure univ) + let : IsFiniteMeasure (baseMeasure.restrict A) := ⟨by rw [Measure.restrict_apply_univ]; exact hfin⟩ + have hdom : Integrable (A.indicator (fun _ => C)) baseMeasure := + (integrable_indicator_iff hA).mpr (integrable_const C) + apply hdom.mono' hF.aestronglyMeasurable + apply Filter.Eventually.of_forall + intro x + by_cases hx : x ∈ A + · rw [indicator_of_mem hx] + exact hbound x + · have hlarge : M < |x.1| := by + apply lt_of_not_ge + intro hh + exact hx ⟨abs_le.mp hh,Set.mem_univ _⟩ + rw [hsupport x hlarge, norm_zero,indicator_of_notMem hx] + +theorem rawTest_integrable {H : Side → ℝ×ℝ → ℝ} (ell : ℝ) + (hF : Measurable (arrivalTest ell H)) (hB : HasCompactBound (arrivalTest ell H)) : + Integrable (rawTest H) (limitingMeasure ell) := by + have hI := compactBound_product_integrable hF hB + have hD : Measurable (fun x => ENNReal.ofReal (density ell x)) := ENNReal.measurable_ofReal.comp (density_measurable ell) + have htop : ∀ᵐ x ∂baseMeasure,ENNReal.ofReal (density ell x) < ∞ := + Filter.Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top) + apply (integrable_withDensity_iff_integrable_smul' hD htop).mpr + have he : (fun x => (ENNReal.ofReal (density ell x)).toReal • rawTest H x) = + (fun x => arrivalTest ell H x/costMass) := by + funext x + rw [ENNReal.toReal_ofReal (density_nonneg ell x),smul_eq_mul,density_mul_raw] + rw [he] + exact hI.div_const costMass + +theorem limiting_integral_eq_invariant {H : Side → ℝ×ℝ → ℝ} (ell : ℝ) + (hF : Measurable (arrivalTest ell H)) (hB : HasCompactBound (arrivalTest ell H)) : + (∫ x,rawTest H x ∂limitingMeasure ell) = invariantAverage (arrivalTest ell H) := by + have hI := compactBound_product_integrable hF hB + have hD : Measurable (fun x => ENNReal.ofReal (density ell x)) := ENNReal.measurable_ofReal.comp (density_measurable ell) + have htop : ∀ᵐ x ∂baseMeasure,ENNReal.ofReal (density ell x) < ∞ := + Filter.Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top) + rw [limitingMeasure,integral_withDensity_eq_integral_toReal_smul hD htop] + have he : (fun x => (ENNReal.ofReal (density ell x)).toReal • rawTest H x) = + (fun x => arrivalTest ell H x/costMass) := by + funext x + rw [ENNReal.toReal_ofReal (density_nonneg ell x),smul_eq_mul,density_mul_raw] + rw [he,integral_div] + have hfubini := integral_prod_symm (arrivalTest ell H) hI + change (∫ x,arrivalTest ell H x ∂baseMeasure)/costMass = _ + rw [baseMeasure,hfubini] + rfl + +theorem continuous_test_density {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 0 < ell) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) : + Integrable (rawTest H) (limitingMeasure ell) ∧ + (∫ x,rawTest H x ∂limitingMeasure ell) = invariantAverage (arrivalTest ell H) := by + have htest := arrivalTest_admissible hH hcompact ha hb hell hsupport + exact ⟨rawTest_integrable ell htest.measurable htest.compactBound, + limiting_integral_eq_invariant ell htest.measurable htest.compactBound⟩ + +end NumberTheoryLean.OccupationDensityIntegral + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/OddPairCycleGrouping.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/OddPairCycleGrouping.lean new file mode 100644 index 0000000000000000000000000000000000000000..94a8a9956ca0916c8c13cdff4cbde935504f2b54 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/OddPairCycleGrouping.lean @@ -0,0 +1,60 @@ +import OAI.NumberTheory.Jacobsthal.Paths.PairBranchFullProjection + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.InitialRegeneration +open NumberTheoryLean.KernelPotential + +noncomputable def pairWindowContinue (v H : ℝ) : Kernel OddCost OddCost := + pairBranchKernel false+pairBranchKernel true ∘ₖ stateFilter (ordinaryCostWindow_measurable v H).compl + +instance pairWindowContinue_isFiniteKernel (v H : ℝ) : IsFiniteKernel (pairWindowContinue v H) := by + unfold pairWindowContinue + infer_instance + +lemma pairWindowContinue_complete (v H : ℝ) : + hitOrReturn ∘ₖ pairWindowContinue v H=ordinaryWindowContinue v H := by + rw [pairWindowContinue,Kernel.comp_add_right,← Kernel.comp_assoc, + ← cycleBranch_completion false,← cycleBranch_completion true] + rfl + +noncomputable def oddConsecutiveCapture (v H : ℝ) : Kernel OddCost OddCost := + ordinaryWindowCapture v H ∘ₖ regenerationInput + +noncomputable def oddConsecutiveContinue (v H : ℝ) : Kernel OddCost OddCost := + pairedCostKernel ∘ₖ nonregenerationInput+pairWindowContinue v H ∘ₖ regenerationInput + +instance oddConsecutiveCapture_isFiniteKernel (v H : ℝ) : IsFiniteKernel (oddConsecutiveCapture v H) := by + unfold oddConsecutiveCapture + infer_instance + +instance oddConsecutiveContinue_isFiniteKernel (v H : ℝ) : IsFiniteKernel (oddConsecutiveContinue v H) := by + unfold oddConsecutiveContinue + infer_instance + +noncomputable def oddConsecutiveHit (v H : ℝ) : Kernel OddCost OddCost := + potential (oddConsecutiveCapture v H) (oddConsecutiveContinue v H) + +theorem oddConsecutiveHit_eq_cycles (v H : ℝ) : + oddConsecutiveHit v H=ordinaryMarkedHit v H ∘ₖ hitOrReturn := by + rw [oddConsecutiveHit,oddConsecutiveContinue,first_capture_decomposition, + oddConsecutiveCapture, + potential_comp_left regenerationInput (ordinaryWindowCapture v H) (pairedCostKernel ∘ₖ nonregenerationInput), + potential_comp_left regenerationInput (pairWindowContinue v H) (pairedCostKernel ∘ₖ nonregenerationInput), + ← hitOrReturn_eq_input_potential,potential_exchange,pairWindowContinue_complete] + rfl + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/RawHitRegeneration.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RawHitRegeneration.lean new file mode 100644 index 0000000000000000000000000000000000000000..c200e5c1445a466ba03f844e2dec388935b16fbc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RawHitRegeneration.lean @@ -0,0 +1,161 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RawMarkedVisitGeometry + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FirstHitKernels + +lemma rawMarkedWord_cons_ae (a : ℕ) (b : Bool) (w : List Bool) (h : RawHistory a) + {P : Set (RawCycleWordTrace a (b::w).length)} (hP : MeasurableSet P) + (hA : ∀ᵐ r : RawReturnTrace a ∂rawBranchReturnKernel a b h, + ∀ᵐ t ∂rawMarkedWordKernel (a+2*(r.1+1)) w r.2, + (@Sigma.mk ℕ (fun n => RawHistory (a+2*(n+1)) × RawCycleWordTrace (a+2*(n+1)) w.length) + r.1 (r.2,t)) ∈ P) : + ∀ᵐ t ∂rawMarkedWordKernel a (b::w) h, t ∈ P := by + rw [rawMarkedWordKernel] + apply Kernel.ae_comp_of_ae_ae hP + filter_upwards [hA] with r hr + rcases r with ⟨n,y⟩ + rw [sigmaFamilyKernel_apply] + apply (ae_map_iff (measurableSigmaMk n).aemeasurable hP).mpr + have he : ((Kernel.id : Kernel (RawHistory (a+2*(n+1))) (RawHistory (a+2*(n+1)))) ×ₖ + rawMarkedWordKernel (a+2*(n+1)) w) y = + (rawMarkedWordKernel (a+2*(n+1)) w y).map (Prod.mk y) := by + ext S hS + rw [Kernel.id_prod_apply' _ _ hS,Measure.map_apply measurable_prodMk_left hS] + rw [he] + exact (ae_map_iff measurable_prodMk_left.aemeasurable (hP.preimage (measurableSigmaMk n))).mpr hr + +noncomputable def rawReturnAnchor (a : ℕ) (r : RawReturnTrace a) : CostState := + r.2 ⟨a,Finset.mem_Iic.mpr (by omega)⟩ + +lemma rawReturnAnchor_measurable (a : ℕ) : Measurable (rawReturnAnchor a) := by + apply measurable_sigma_family + intro n + change Measurable (fun h : RawHistory (a+2*(n+1)) => h ⟨a,Finset.mem_Iic.mpr (by omega)⟩) + exact measurable_pi_apply _ + +lemma rawBranchReturn_anchor_regenerates (a : ℕ) (b : Bool) (h : RawHistory a) + (hr : rawLast a h ∈ regenerationSet) : + ∀ᵐ r ∂rawBranchReturnKernel a b h, rawReturnAnchor a r ∈ regenerationSet := by + rw [rawBranchReturnKernel,Kernel.restrict_apply] + apply ae_restrict_of_ae + rw [rawReturnTraceKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable a n)] + apply (ae_map_iff (rawReturnTrace_mk_measurable a n).aemeasurable + (regenerationSet_measurable.preimage (rawReturnAnchor_measurable a))).mpr + filter_upwards [firstReturnHistory_retains_past a n h] with y hy + have he := congrFun hy (⟨a,by simp⟩ : Finset.Iic a) + change y ⟨a,_⟩=rawLast a h at he + change y ⟨a,_⟩ ∈ regenerationSet + rw [he] + exact hr + +noncomputable def selectedCycleAnchor (r : Σ t : ℕ, RawReturnTrace t) : CostState := + rawReturnAnchor r.1 r.2 + +lemma selectedCycleAnchor_measurable : Measurable selectedCycleAnchor := by + apply measurable_sigma_family + intro t + exact rawReturnAnchor_measurable t + +lemma lastRawCycle_anchor_regenerates (w : List Bool) : ∀ a b h, + rawLast a h ∈ regenerationSet → + ∀ᵐ r ∂rawMarkedWordKernel a (w++[b]) h, selectedCycleAnchor (lastRawCycle a w b r) ∈ regenerationSet := by + induction w with + | nil => + intro a b h hr + apply rawMarkedWord_cons_ae a b [] h + (regenerationSet_measurable.preimage (selectedCycleAnchor_measurable.comp (lastRawCycle_measurable [] a b))) + filter_upwards [rawBranchReturn_anchor_regenerates a b h hr] with r hR + exact Eventually.of_forall (fun _ => hR) + | cons c w ih => + intro a b h _hr + apply rawMarkedWord_cons_ae a c (w++[b]) h + (regenerationSet_measurable.preimage (selectedCycleAnchor_measurable.comp (lastRawCycle_measurable (c::w) a b))) + filter_upwards [rawBranchReturn_ae_regeneration a c h] with r hR + exact ih _ b r.2 hR + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FirstHitKernels + +noncomputable def rawHitAnchor (a : ℕ) (r : RawMarkedHitTrace a) : CostState := + selectedCycleAnchor (lastRawCycle a (List.ofFn r.2.1) true r.2.2) + +lemma rawHitAnchor_measurable (a : ℕ) : Measurable (rawHitAnchor a) := by + apply measurable_sigma_family + intro n + apply measurable_sigma_family + intro f + exact selectedCycleAnchor_measurable.comp (lastRawCycle_measurable (List.ofFn f) a true) + +lemma rawFirstHit_anchor_regenerates (a : ℕ) (v H : ℝ) (h : RawHistory a) + (hr : rawLast a h ∈ regenerationSet) : + ∀ᵐ r ∂rawMarkedFirstHitKernel a v H h, rawHitAnchor a r ∈ regenerationSet := by + rw [rawMarkedFirstHitKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.sum_apply,Measure.ae_sum_iff] + intro f + rw [Kernel.map_apply _ (packRawMarkedHitTrace_measurable a n f)] + apply (ae_map_iff (packRawMarkedHitTrace_measurable a n f).aemeasurable + (regenerationSet_measurable.preimage (rawHitAnchor_measurable a))).mpr + rw [rawHitWordKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (lastRawCycle_anchor_regenerates (List.ofFn f) a true h hr) + +lemma rawRegFirstHit_anchor_regenerates (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ r ∂rawRegMarkedFirstHitKernel a v H h, rawHitAnchor a r ∈ regenerationSet := by + rw [rawRegMarkedFirstHitKernel,stateFilter_input] + by_cases hr : h ∈ lastRegeneration a + · rw [ite_eq_left hr] + exact rawFirstHit_anchor_regenerates a v H h hr + · simp [hr] + +noncomputable def rawEvenHitAnchor (a : ℕ) (r : RawEvenMarkedHitTrace a) : CostState := + selectedCycleAnchor (rawEvenFinalCycle a r) + +lemma rawEvenHitAnchor_measurable (a : ℕ) : Measurable (rawEvenHitAnchor a) := + selectedCycleAnchor_measurable.comp (rawEvenFinalCycle_measurable a) + +theorem rawEvenHit_anchor_regenerates (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ r ∂rawEvenMarkedHitKernel a v H h, rawEvenHitAnchor a r ∈ regenerationSet := by + have hP : MeasurableSet {r | rawEvenHitAnchor a r ∈ regenerationSet} := + regenerationSet_measurable.preimage (rawEvenHitAnchor_measurable a) + rw [rawEvenMarkedHitKernel] + apply Kernel.ae_comp_of_ae_ae hP + apply Eventually.of_forall + rintro ⟨k,y⟩ + rw [rawEvenHitContinuation,sigmaFamilyKernel_apply] + apply (ae_map_iff (measurableSigmaMk k).aemeasurable hP).mpr + have he : ((Kernel.id : Kernel (RawHistory ((a+1)+2*k)) (RawHistory ((a+1)+2*k))) ×ₖ + rawRegMarkedFirstHitKernel ((a+1)+2*k) v H) y = + (rawRegMarkedFirstHitKernel ((a+1)+2*k) v H y).map (Prod.mk y) := by + ext S hS + rw [Kernel.id_prod_apply' _ _ hS,Measure.map_apply measurable_prodMk_left hS] + rw [he] + exact (ae_map_iff measurable_prodMk_left.aemeasurable (hP.preimage (measurableSigmaMk k))).mpr + (rawRegFirstHit_anchor_regenerates _ v H y) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/RawInitialDelay.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RawInitialDelay.lean new file mode 100644 index 0000000000000000000000000000000000000000..785e0ed37d2f4d4b17746218336eb5892c60f797 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RawInitialDelay.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RawInitialEven + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.InitialOddDraw +open NumberTheoryLean.InitialRegeneration NumberTheoryLean.FirstHitKernels +open NumberTheoryLean.TransitionKernels + +lemma initialOddReturnJoint_endpoint (s : EvenState) : + (initialOddReturnJoint s).map Prod.snd=delayedRegeneration s := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF measurable_snd,initialOddReturnJoint, + Kernel.lintegral_compProd _ _ _ (f := fun p : OddCost × OddCost => F p.2) (hF.comp measurable_snd), + delayedRegeneration,Kernel.lintegral_comp _ _ _ hF] + rfl + +noncomputable def rawInitialEndpointState (a : ℕ) (r : RawInitialEvenTrace a) : CostState := + (rawContinuationSignature (a+1) r).2 + +lemma rawInitialEndpointState_measurable (a : ℕ) : Measurable (rawInitialEndpointState a) := + measurable_snd.comp (rawContinuationSignature_measurable (a+1)) + +lemma rawInitialEven_endpoint (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + (rawInitialEvenKernel a h).map (rawInitialEndpointState a)=(delayedRegeneration s).map embedOdd := by + have he := congrArg (fun μ : Measure (CostState × CostState) => μ.map Prod.snd) + (rawInitialEven_joint_signature a h s hs) + rw [Measure.map_map measurable_snd (rawContinuationSignature_measurable _), + Measure.map_map measurable_snd embedOddPair_measurable] at he + rw [← initialOddReturnJoint_endpoint s, + Measure.map_map embedOdd_measurable measurable_snd] + exact he + +noncomputable def rawInitialEvenCostLaw (a : ℕ) (h : RawHistory a) : Measure ℝ := + (rawInitialEvenKernel a h).map (fun r => (rawInitialEndpointState a r).2) + +theorem rawInitialEven_cost_law (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : rawInitialEvenCostLaw a h=delayedCostLaw s := by + calc + _ = ((rawInitialEvenKernel a h).map (rawInitialEndpointState a)).map Prod.snd := + (Measure.map_map measurable_snd (rawInitialEndpointState_measurable a)).symm + _ = ((delayedRegeneration s).map embedOdd).map Prod.snd := by rw [rawInitialEven_endpoint a h s hs] + _ = _ := by + rw [Measure.map_map measurable_snd embedOdd_measurable] + rfl + +theorem rawInitialEven_endpoint_regenerates (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + ∀ᵐ r ∂rawInitialEvenKernel a h, rawInitialEndpointState a r ∈ regenerationSet := by + apply (ae_map_iff (rawInitialEndpointState_measurable a).aemeasurable regenerationSet_measurable).mp + rw [rawInitialEven_endpoint a h s hs] + apply (ae_map_iff embedOdd_measurable.aemeasurable regenerationSet_measurable).mpr + exact delayedRegeneration_ae_regeneration s + +theorem rawInitialEven_uniform_exponential (S : ℝ) : ∃ eta B : ℝ, 0 < eta ∧ 0 ≤ B ∧ + ∀ (a : ℕ) (h : RawHistory a) (s : EvenState), rawLast a h=(Sum.inl s,0) → s.1 ≤ S → + costTransform (rawInitialEvenCostLaw a h) eta ≤ ENNReal.ofReal B := by + obtain ⟨eta,B,heta,hB,hMoment⟩ := delayedCostLaw_uniform_exponential S + refine ⟨eta,B,heta,hB,?_⟩ + intro a h s hs hS + rw [rawInitialEven_cost_law a h s hs] + exact hMoment s hS + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationBandBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationBandBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f9718335d7fb09c848212bf746ce1cac18d4f7d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationBandBounds.lean @@ -0,0 +1,879 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.InitialOddDraw +import OAI.NumberTheory.Jacobsthal.Estimates.OnePairCost + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped ENNReal ProbabilityTheory Topology BigOperators +namespace Erdos970Dependency.CycleMeanCost +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.CycleCostLower NumberTheoryLean.CycleOccupation +open NumberTheoryLean.RegenerationTails +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantCostBound +open Erdos970Dependency.RawStateCost Erdos970Dependency.OccupationAge Erdos970Dependency.OnePairCost + +noncomputable def capturedAge (n : ℕ) : ℝ≥0∞ := + ∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂firstReturn n (regenerationState, 0) + +noncomputable def blockIncrement (n : ℕ) : ℝ≥0∞ := + ∫⁻ y : CostState, ENNReal.ofReal (stateCost y.1) ∂visitBlock n (regenerationState, 0) + +theorem residualAge_zero : residualAge 0 = 0 := by + change (∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂Measure.dirac (regenerationState, 0)) = 0 + rw [lintegral_dirac' _ oddAge_measurable] + norm_num + +theorem age_balance (n : ℕ) : capturedAge n + residualAge (n + 1) = residualAge n + blockIncrement n := by + have hp : costKilled ^ (n + 1) = costKilled ∘ₖ (costKilled ^ n) := pow_succ' costKilled n + simp only [capturedAge, residualAge, blockIncrement, firstReturn, visitBlock] + rw [hp, Kernel.lintegral_comp _ _ _ oddAge_measurable, + Kernel.lintegral_comp _ _ _ oddAge_measurable, + Kernel.lintegral_comp _ _ _ increment_test_measurable] + have hC : Measurable (fun z : OddCost ↦ ∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂costCaptured z) := + oddAge_measurable.lintegral_kernel + rw [← lintegral_add_left hC, ← lintegral_add_left oddAge_measurable] + apply lintegral_congr_ae + filter_upwards [costKilled_pow_cost_monotone n (regenerationState, 0)] with z hz + exact captured_killed_age_balance z hz + +theorem finite_cost_balance (N : ℕ) : + (∑ n ∈ Finset.range N, capturedAge n) + residualAge N = ∑ n ∈ Finset.range N, blockIncrement n := by + induction N with + | zero => simp [residualAge_zero] + | succ N ih => + calc + _ = ((∑ n ∈ Finset.range N, capturedAge n) + capturedAge N) + residualAge (N + 1) := by + rw [Finset.sum_range_succ] + _ = ((∑ n ∈ Finset.range N, capturedAge n) + residualAge N) + blockIncrement N := by + rw [add_assoc, age_balance, ← add_assoc] + _ = (∑ n ∈ Finset.range N, blockIncrement n) + blockIncrement N := by rw [ih] + _ = _ := (Finset.sum_range_succ _ _).symm + +theorem capturedAge_sum : (∑' n : ℕ, capturedAge n) = + ∫⁻ G : ℝ, ENNReal.ofReal G ∂cycleCostLaw := by + rw [cycleCostLaw, lintegral_map ENNReal.measurable_ofReal measurable_snd, + returnLaw, Kernel.sum_apply, lintegral_sum_measure] + rfl + +theorem blockIncrement_sum : (∑' n : ℕ, blockIncrement n) = + ∫⁻ y : CostState, ENNReal.ofReal (stateCost y.1) ∂occupationMeasure := by + rw [occupationMeasure, occupationKernel, Kernel.sum_apply, lintegral_sum_measure] + rfl + +theorem cycle_cost_lintegral_eq_increments : + (∫⁻ G : ℝ, ENNReal.ofReal G ∂cycleCostLaw) = + ∫⁻ y : CostState, ENNReal.ofReal (stateCost y.1) ∂occupationMeasure := by + have hleft : Tendsto (fun N : ℕ ↦ (∑ n ∈ Finset.range N, capturedAge n) + residualAge N) + atTop (𝓝 (∑' n : ℕ, capturedAge n)) := by + simpa only [add_zero] using (ENNReal.tendsto_nat_tsum capturedAge).add residualAge_tendsto_zero + have hleft' : Tendsto (fun N : ℕ ↦ ∑ n ∈ Finset.range N, blockIncrement n) + atTop (𝓝 (∑' n : ℕ, capturedAge n)) := + hleft.congr' (Eventually.of_forall finite_cost_balance) + have h := tendsto_nhds_unique hleft' (ENNReal.tendsto_nat_tsum blockIncrement) + rw [capturedAge_sum, blockIncrement_sum] at h + exact h + +theorem cycle_cost_integrable : Integrable (fun G : ℝ ↦ G) cycleCostLaw := by + have hc : ∀ᵐ G ∂cycleCostLaw, 0 ≤ G := cycleCostLaw_positive.mono (fun _ h ↦ h.le) + have ho : ∀ᵐ y : CostState ∂occupationMeasure, 0 ≤ stateCost y.1 := + Eventually.of_forall (fun y ↦ (stateCost_bounds y.1).1.le) + refine ⟨measurable_id.aestronglyMeasurable, (hasFiniteIntegral_iff_ofReal hc).mpr ?_⟩ + rw [cycle_cost_lintegral_eq_increments, + ← ofReal_integral_eq_lintegral_ofReal occupation_increment_integrable ho] + exact ENNReal.ofReal_lt_top + +theorem cycle_mean_eq : (∫ G : ℝ, G ∂cycleCostLaw) = costMass / beta := by + have hc : ∀ᵐ G ∂cycleCostLaw, 0 ≤ G := cycleCostLaw_positive.mono (fun _ h ↦ h.le) + have ho : ∀ᵐ y : CostState ∂occupationMeasure, 0 ≤ stateCost y.1 := + Eventually.of_forall (fun y ↦ (stateCost_bounds y.1).1.le) + have h := cycle_cost_lintegral_eq_increments + rw [← ofReal_integral_eq_lintegral_ofReal cycle_cost_integrable hc, + ← ofReal_integral_eq_lintegral_ofReal occupation_increment_integrable ho] at h + have hr := congrArg ENNReal.toReal h + rw [ENNReal.toReal_ofReal (integral_nonneg_of_ae hc), + ENNReal.toReal_ofReal (integral_nonneg_of_ae ho)] at hr + exact hr.trans occupation_increment_integral + +end Erdos970Dependency.CycleMeanCost + +end + +section + +namespace NumberTheoryLean.InitialRegeneration + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostProcess +open CostReturnLaw CycleRegeneration CycleCostLower PairedDrift +open UniformCycleMoments InitialOddDraw + +noncomputable def hitOrReturn : Kernel OddCost OddCost := by + classical + exact Kernel.piecewise returnSet_measurable Kernel.id returnLaw + +instance hitOrReturn_isMarkovKernel : IsMarkovKernel hitOrReturn := by unfold hitOrReturn; infer_instance + +theorem hitOrReturn_ae_regeneration (z : OddCost) : ∀ᵐ w ∂hitOrReturn z, w ∈ returnSet := by + classical + rw [hitOrReturn, Kernel.piecewise_apply] + split_ifs with hz + · rw [Kernel.id_apply] + exact (ae_dirac_iff returnSet_measurable).mpr hz + · exact returnLaw_ae_regeneration z + +theorem hitOrReturn_cost_monotone (z : OddCost) : ∀ᵐ w ∂hitOrReturn z, z.2 ≤ w.2 := by + classical + rw [hitOrReturn, Kernel.piecewise_apply] + split_ifs + · rw [Kernel.id_apply] + exact (ae_dirac_iff (measurableSet_le measurable_const measurable_snd)).mpr le_rfl + · filter_upwards [returnLaw_cost_lower z] with w hw + have hc : 0 < cost (3 : ℝ) := cost_pos (by norm_num) + linarith + +noncomputable def delayedRegeneration : Kernel EvenState OddCost := hitOrReturn ∘ₖ firstOdd + +instance delayedRegeneration_isMarkovKernel : IsMarkovKernel delayedRegeneration := by + unfold delayedRegeneration + infer_instance + +theorem delayedRegeneration_ae_regeneration (s : EvenState) : + ∀ᵐ z ∂delayedRegeneration s, z ∈ returnSet := by + rw [delayedRegeneration] + exact Kernel.ae_comp_of_ae_ae returnSet_measurable (Eventually.of_forall hitOrReturn_ae_regeneration) + +theorem delayedRegeneration_cost_nonneg (s : EvenState) : + ∀ᵐ z ∂delayedRegeneration s, 0 ≤ z.2 := by + rw [delayedRegeneration] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_const measurable_snd) + filter_upwards [firstOdd_cost_bounds s] with z hz + filter_upwards [hitOrReturn_cost_monotone z] with w hw + exact le_trans hz.1 hw + +theorem exponential_total_eq {α : Type*} [MeasurableSpace α] + (μ : Measure (α × ℝ)) (η T : ℝ) : + (∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂μ) = + ENNReal.ofReal (Real.exp (η * T)) * + (∫⁻ y, ENNReal.ofReal (Real.exp (η * (y.2 - T))) ∂μ) := by + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro y + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add] + congr 2 + ring + +theorem delayedRegeneration_uniform_exponential (S : ℝ) : + ∃ η B : ℝ, 0 < η ∧ 0 ≤ B ∧ ∀ s : EvenState, s.1 ≤ S → + (∫⁻ z, ENNReal.ofReal (Real.exp (η * z.2)) ∂delayedRegeneration s) ≤ ENNReal.ofReal B := by + classical + obtain ⟨η, C, D, hη, hC, hD, hb⟩ := return_increment_uniform_exponential + have hpoint : ∀ z : OddCost, + (∫⁻ w, ENNReal.ofReal (Real.exp (η * w.2)) ∂hitOrReturn z) ≤ + ENNReal.ofReal (C + 1) * ENNReal.ofReal (Real.exp (η * z.2) * (V z.1 + (D + 1))) := by + intro z + rw [hitOrReturn, Kernel.piecewise_apply] + split_ifs + · rw [Kernel.id_apply, lintegral_dirac' z (f := fun w : OddCost => ENNReal.ofReal (Real.exp (η * w.2))) + (ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp (measurable_const.mul measurable_snd))), + ← ENNReal.ofReal_mul (by linarith : 0 ≤ C + 1)] + apply ENNReal.ofReal_le_ofReal + have hV : 1 ≤ V z.1 := V_one_le z.1 + have hw : 1 ≤ (C + 1) * (V z.1 + (D + 1)) := by nlinarith [mul_nonneg hC (by linarith : 0 ≤ V z.1 + (D + 1))] + nlinarith [mul_le_mul_of_nonneg_left hw (Real.exp_pos (η * z.2)).le] + · rw [exponential_total_eq _ η z.2] + calc + _ ≤ ENNReal.ofReal (Real.exp (η * z.2)) * ENNReal.ofReal (C * (V z.1 + D)) := + mul_le_mul le_rfl (hb z) zero_le zero_le + _ ≤ _ := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, + ← ENNReal.ofReal_mul (by linarith : 0 ≤ C + 1)] + apply ENNReal.ofReal_le_ofReal + have hV : 0 ≤ V z.1 := (V_pos z.1).le + have hw : C * (V z.1 + D) ≤ (C + 1) * (V z.1 + (D + 1)) := by nlinarith + nlinarith [mul_le_mul_of_nonneg_left hw (Real.exp_pos (η * z.2)).le] + obtain ⟨B, hB, hfirst⟩ := firstOdd_weighted_exponential S η (D + 1) hη.le (by linarith) + refine ⟨η, (C + 1) * B, hη, mul_nonneg (by linarith) hB, ?_⟩ + intro s hs + rw [delayedRegeneration, Kernel.lintegral_comp _ _ _ + (g := fun z : OddCost => ENNReal.ofReal (Real.exp (η * z.2))) + (ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp (measurable_const.mul measurable_snd)))] + calc + _ ≤ ∫⁻ z, ENNReal.ofReal (C + 1) * ENNReal.ofReal (Real.exp (η * z.2) * (V z.1 + (D + 1))) ∂firstOdd s := + lintegral_mono hpoint + _ = ENNReal.ofReal (C + 1) * + (∫⁻ z, ENNReal.ofReal (Real.exp (η * z.2) * (V z.1 + (D + 1))) ∂firstOdd s) := + lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + _ ≤ ENNReal.ofReal (C + 1) * ENNReal.ofReal B := mul_le_mul le_rfl (hfirst s hs) zero_le zero_le + _ = _ := (ENNReal.ofReal_mul (by linarith : 0 ≤ C + 1)).symm + +noncomputable def delayedCostLaw (s : EvenState) : Measure ℝ := (delayedRegeneration s).map Prod.snd + +instance delayedCostLaw_isProbabilityMeasure (s : EvenState) : IsProbabilityMeasure (delayedCostLaw s) := + (Measure.isProbabilityMeasure_map_iff (μ := delayedRegeneration s) + measurable_snd.aemeasurable).mpr inferInstance + +theorem delayedCostLaw_uniform_exponential (S : ℝ) : ∃ η B : ℝ, 0 < η ∧ 0 ≤ B ∧ + ∀ s : EvenState, s.1 ≤ S → + (∫⁻ T, ENNReal.ofReal (Real.exp (η * T)) ∂delayedCostLaw s) ≤ ENNReal.ofReal B := by + obtain ⟨η, B, hη, hB, hb⟩ := delayedRegeneration_uniform_exponential S + refine ⟨η, B, hη, hB, ?_⟩ + intro s hs + rw [delayedCostLaw, lintegral_map (f := fun T : ℝ => ENNReal.ofReal (Real.exp (η * T))) (ENNReal.measurable_ofReal.comp + (Real.measurable_exp.comp (measurable_const.mul measurable_id))) measurable_snd] + exact hb s hs + +end NumberTheoryLean.InitialRegeneration + +end + +section + +namespace NumberTheoryLean.InitialOccupation + +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathMeasures PairedCostProcess PairedCostGrouping +open CostReturnLaw CycleOccupation OccupationDecomposition KernelPotential +open InitialOddDraw InitialRegeneration + +noncomputable def beforeRegeneration : Kernel OddCost CostState := by + classical + exact Kernel.piecewise returnSet_measurable 0 occupationKernel + +instance beforeRegeneration_isSFiniteKernel : IsSFiniteKernel beforeRegeneration := by + unfold beforeRegeneration + infer_instance + +noncomputable def initialOccupation : Kernel EvenState CostState := + firstOdd.map embedOdd + beforeRegeneration ∘ₖ firstOdd + +instance initialOccupation_isSFiniteKernel : IsSFiniteKernel initialOccupation := by + unfold initialOccupation + infer_instance + +theorem pairedOccupation_unfold_cycles : + pairedOccupation = occupationKernel + pairedOccupation ∘ₖ returnLaw := by + have hEq : pairedOccupation = potential occupationKernel returnLaw := pairedOccupation_cycle_decomposition + calc + _ = potential occupationKernel returnLaw := hEq + _ = occupationKernel + (potential occupationKernel returnLaw) ∘ₖ returnLaw := potential_unfold _ _ + _ = _ := by rw [← hEq] + +theorem pairedOccupation_first_hit_split : + pairedOccupation = beforeRegeneration + pairedOccupation ∘ₖ hitOrReturn := by + classical + ext z B hB + rw [add_apply, Measure.add_apply, beforeRegeneration, Kernel.piecewise_apply, + Kernel.comp_apply' _ _ _ hB, hitOrReturn, Kernel.piecewise_apply] + by_cases hz : z ∈ returnSet + · simp only [hz, ite_eq_left, zero_apply, Kernel.id_apply] + rw [lintegral_dirac' z (pairedOccupation.measurable_coe hB)] + simp + · simp only [hz] + have h := congrArg (fun K : Kernel OddCost CostState => K z B) pairedOccupation_unfold_cycles + rwa [add_apply, Measure.add_apply, Kernel.comp_apply' _ _ _ hB] at h + +noncomputable def evenEmbeddingKernel : Kernel EvenState CostState := + Kernel.deterministic (fun s : EvenState => (.inl s, 0)) (measurable_inl.prodMk measurable_const) + +theorem firstOdd_intertwines : + oddEmbeddingKernel ∘ₖ firstOdd = costKernel ∘ₖ evenEmbeddingKernel := by + rw [oddEmbeddingKernel, evenEmbeddingKernel, Kernel.deterministic_comp_eq_map, + Kernel.comp_deterministic_eq_comap] + ext s : 1 + rw [Kernel.map_apply _ embedOdd_measurable, Kernel.comap_apply] + exact firstOdd_full_draw s + +theorem fullOccupation_eq_potential : fullOccupation = potential costKernel costKernel := by + unfold fullOccupation potential + apply congrArg Kernel.sum + funext n + exact pow_succ' costKernel n + +theorem fullOccupation_unfold : fullOccupation = costKernel + fullOccupation ∘ₖ costKernel := by + rw [fullOccupation_eq_potential] + exact potential_unfold _ _ + +theorem fullOccupation_odd_kernel : fullOccupation ∘ₖ oddEmbeddingKernel = pairedOccupation := by + rw [oddEmbeddingKernel, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.comap_apply] + exact (pairedOccupation_eq_full z).symm + +theorem fullOccupation_even_first_draw : + fullOccupation ∘ₖ evenEmbeddingKernel = firstOdd.map embedOdd + pairedOccupation ∘ₖ firstOdd := by + have hfull := congrArg (fun K : Kernel CostState CostState => K ∘ₖ evenEmbeddingKernel) fullOccupation_unfold + rw [Kernel.comp_add_left, Kernel.comp_assoc, ← firstOdd_intertwines, + ← Kernel.comp_assoc, fullOccupation_odd_kernel] at hfull + have hfirst : oddEmbeddingKernel ∘ₖ firstOdd = firstOdd.map embedOdd := by + rw [oddEmbeddingKernel, Kernel.deterministic_comp_eq_map] + rwa [hfirst] at hfull + +theorem initial_occupation_decomposition : + fullOccupation ∘ₖ evenEmbeddingKernel = initialOccupation + pairedOccupation ∘ₖ delayedRegeneration := by + rw [fullOccupation_even_first_draw] + have h := congrArg (fun K : Kernel OddCost CostState => K ∘ₖ firstOdd) pairedOccupation_first_hit_split + rw [Kernel.comp_add_left, Kernel.comp_assoc] at h + rw [h, ← add_assoc] + rfl + +theorem initial_occupation_decomposition_apply (s : EvenState) : + fullOccupation (.inl s, 0) = initialOccupation s + (pairedOccupation ∘ₖ delayedRegeneration) s := by + have h := congrArg (fun K : Kernel EvenState CostState => K s) initial_occupation_decomposition + rw [evenEmbeddingKernel, Kernel.comp_deterministic_eq_comap, Kernel.comap_apply, add_apply] at h + exact h + +end NumberTheoryLean.InitialOccupation + +end + +section + +namespace NumberTheoryLean.FullOccupationCovariance + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open TransitionKernels FinitePathMeasures PairedCostProcess PairedCostGrouping +open RegenerationTails CostReturnLaw CycleResponse AdmissibleCycleTests +open OccupationDecomposition OccupationRegeneration SignedCycleOccupation InitialOccupation + +instance fullOccupation_isSFiniteKernel : IsSFiniteKernel fullOccupation := by + rw [fullOccupation_eq_potential] + infer_instance + +theorem shifts_commute_fullOccupation (a : ℝ) : + shiftFullKernel a ∘ₖ fullOccupation = fullOccupation ∘ₖ shiftFullKernel a := by + rw [fullOccupation, Kernel.comp_sum_right, Kernel.comp_sum_left] + apply congrArg Kernel.sum + funext n + exact ((shiftFull_commutes a).pow_right (n + 1)).eq + +theorem fullOccupation_translation (z : CostState) (a : ℝ) : + (fullOccupation z).map (shiftFullCost a) = fullOccupation (shiftFullCost a z) := by + have h := shifts_commute_fullOccupation a + rw [shiftFullKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] at h + have hz := congrArg (fun K : Kernel CostState CostState => K z) h + rwa [Kernel.map_apply _ (shiftFullCost_measurable a), Kernel.comap_apply] at hz + +theorem fullOccupation_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + fullOccupation (embedOdd (s, T)) = fullOccupation (embedOdd (regenerationState, T)) := by + have hk : costKernel (embedOdd (s, T)) = costKernel (embedOdd (regenerationState, T)) := + costKernel_regeneration s hs T + ext B hB + rw [fullOccupation, Kernel.sum_apply' _ _ hB, Kernel.sum_apply' _ _ hB] + apply tsum_congr + intro n + have hp : costKernel ^ (n + 1) = (costKernel ^ n) ∘ₖ costKernel := pow_succ _ _ + rw [hp, Kernel.comp_apply, Kernel.comp_apply, hk] + +theorem fullOccupation_regeneration_law (z : OddCost) (hz : z ∈ returnSet) : + fullOccupation (embedOdd z) = + (fullOccupation (embedOdd (regenerationState, 0))).map (shiftFullCost z.2) := by + rw [fullOccupation_regeneration z.1 hz z.2, fullOccupation_translation] + have heq : shiftFullCost z.2 (embedOdd (regenerationState, 0)) = embedOdd (regenerationState, z.2) := by + simp [shiftFullCost, embedOdd] + rw [heq] + +noncomputable def fullResponse (F : Test) (v : ℝ) : ℝ := + ∫ y : CostState, F (v - y.2, y.1) ∂fullOccupation (embedOdd (regenerationState, 0)) + +theorem fullResponse_measurable {F : Test} (hF : Measurable F) : Measurable (fullResponse F) := by + exact ((hF.comp ((measurable_fst.sub (measurable_snd.comp measurable_snd)).prodMk + (measurable_fst.comp measurable_snd))).stronglyMeasurable.integral_prod_right').measurable + +theorem fullResponse_uniform_bound {F : Test} (hF : Measurable F) (hB : HasCompactBound F) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ v, ‖fullResponse F v‖ ≤ C := + fullOccupation_test_uniform_bound hF hB + +theorem fullResponse_limit {F : Test} (hF : Admissible F) : + Tendsto (fullResponse F) atTop (𝓝 ((∫ u : ℝ, response F u) / (∫ G : ℝ, G ∂cycleCostLaw))) := + fullOccupation_regeneration_limit hF + +theorem fullOccupation_regeneration_integral (z : OddCost) (hz : z ∈ returnSet) + {F : Test} (hF : Measurable F) (v : ℝ) : + (∫ y : CostState, F (v - y.2, y.1) ∂pairedOccupation z) = fullResponse F (v - z.2) := by + rw [pairedOccupation_eq_full, fullOccupation_regeneration_law z hz, + integral_map (shiftFullCost_measurable z.2).aemeasurable (shiftedTest_measurable hF v).aestronglyMeasurable] + apply integral_congr_ae + apply Eventually.of_forall + intro y + change F (v - (y.2 + z.2), y.1) = F ((v - z.2) - y.2, y.1) + rw [show v - (y.2 + z.2) = (v - z.2) - y.2 by ring] + +theorem fullOccupation_regeneration_integrable (z : OddCost) (hz : z ∈ returnSet) + {F : Test} (hF : Measurable F) (hB : HasCompactBound F) (v : ℝ) : + Integrable (fun y : CostState => F (v - y.2, y.1)) (pairedOccupation z) := by + rw [pairedOccupation_eq_full, fullOccupation_regeneration_law z hz] + apply (integrable_map_measure (shiftedTest_measurable hF v).aestronglyMeasurable + (shiftFullCost_measurable z.2).aemeasurable).mpr + have h := fullOccupation_test_integrable hF hB (v - z.2) + convert! h using 1 + funext y + change F (v - (y.2 + z.2), y.1) = F ((v - z.2) - y.2, y.1) + rw [show v - (y.2 + z.2) = (v - z.2) - y.2 by ring] + +end NumberTheoryLean.FullOccupationCovariance + +end + +section + +namespace NumberTheoryLean.InitialOccupationMoments + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open TransitionKernels FinitePathMeasures PairedCostProcess PairedCostGrouping +open CostReturnLaw CycleOccupation CycleResponse AdmissibleCycleTests PairedDrift +open InitialOddDraw InitialRegeneration InitialOccupation UniformCycleMoments + +theorem occupation_cost_monotone (z : OddCost) : ∀ᵐ y ∂occupationKernel z, z.2 ≤ y.2 := by + rw [occupationKernel, Kernel.sum_apply, Measure.ae_sum_iff] + intro n + exact (visitBlock_age_bounds n z).mono (fun _ hy => hy.1) + +theorem beforeRegeneration_cost_monotone (z : OddCost) : ∀ᵐ y ∂beforeRegeneration z, z.2 ≤ y.2 := by + classical + rw [beforeRegeneration, Kernel.piecewise_apply] + split_ifs + · simp + · exact occupation_cost_monotone z + +theorem initialOccupation_cost_nonneg (s : EvenState) : ∀ᵐ y ∂initialOccupation s, 0 ≤ y.2 := by + rw [initialOccupation, add_apply, ae_add_measure_iff] + constructor + · rw [Kernel.map_apply _ embedOdd_measurable] + apply (ae_map_iff embedOdd_measurable.aemeasurable (measurableSet_le measurable_const measurable_snd)).mpr + exact (firstOdd_cost_bounds s).mono (fun _ h => h.1) + · apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_const measurable_snd) + filter_upwards [firstOdd_cost_bounds s] with z hz + filter_upwards [beforeRegeneration_cost_monotone z] with y hy + exact le_trans hz.1 hy + +theorem initialOccupation_uniform_exponential (S : ℝ) : ∃ η B : ℝ, + 0 < η ∧ 0 ≤ B ∧ ∀ s : EvenState, s.1 ≤ S → + (∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂initialOccupation s) ≤ ENNReal.ofReal B := by + classical + obtain ⟨η, C, D, hη, hC, hD, hb⟩ := occupation_increment_uniform_exponential + have hpoint : ∀ z : OddCost, + ENNReal.ofReal (Real.exp (η * z.2)) + + (∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂beforeRegeneration z) ≤ + ENNReal.ofReal (C + 1) * ENNReal.ofReal (Real.exp (η * z.2) * (V z.1 + (D + 1))) := by + intro z + have he : (∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂beforeRegeneration z) ≤ + ENNReal.ofReal (Real.exp (η * z.2)) * ENNReal.ofReal (C * (V z.1 + D)) := by + rw [beforeRegeneration, Kernel.piecewise_apply] + split_ifs + · simp + · rw [exponential_total_eq _ η z.2] + exact mul_le_mul le_rfl (hb z) zero_le zero_le + calc + _ ≤ ENNReal.ofReal (Real.exp (η * z.2)) + + ENNReal.ofReal (Real.exp (η * z.2)) * ENNReal.ofReal (C * (V z.1 + D)) := add_le_add le_rfl he + _ ≤ _ := by + have hV := V_one_le z.1 + have hterm : 0 ≤ C * (V z.1 + D) := mul_nonneg hC (by linarith) + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, + ← ENNReal.ofReal_add (Real.exp_pos _).le (mul_nonneg (Real.exp_pos _).le hterm), + ← ENNReal.ofReal_mul (by linarith : 0 ≤ C + 1)] + apply ENNReal.ofReal_le_ofReal + have hw : 1 + C * (V z.1 + D) ≤ (C + 1) * (V z.1 + (D + 1)) := by nlinarith + nlinarith [mul_le_mul_of_nonneg_left hw (Real.exp_pos (η * z.2)).le] + obtain ⟨B, hB, hfirst⟩ := firstOdd_weighted_exponential S η (D + 1) hη.le (by linarith) + refine ⟨η, (C + 1) * B, hη, mul_nonneg (by linarith) hB, ?_⟩ + intro s hs + have hExp : Measurable (fun y : CostState => ENNReal.ofReal (Real.exp (η * y.2))) := + ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp (measurable_const.mul measurable_snd)) + rw [initialOccupation, add_apply, lintegral_add_measure, + Kernel.map_apply _ embedOdd_measurable, lintegral_map hExp embedOdd_measurable, + Kernel.lintegral_comp _ _ _ hExp] + change (∫⁻ z, ENNReal.ofReal (Real.exp (η * z.2)) ∂firstOdd s) + + (∫⁻ z, ∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂beforeRegeneration z ∂firstOdd s) ≤ _ + rw [← lintegral_add_left (f := fun z : OddCost => ENNReal.ofReal (Real.exp (η * z.2))) + (ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp (measurable_const.mul measurable_snd)))] + calc + _ ≤ ∫⁻ z, ENNReal.ofReal (C + 1) * ENNReal.ofReal (Real.exp (η * z.2) * (V z.1 + (D + 1))) ∂firstOdd s := + lintegral_mono hpoint + _ = ENNReal.ofReal (C + 1) * + (∫⁻ z, ENNReal.ofReal (Real.exp (η * z.2) * (V z.1 + (D + 1))) ∂firstOdd s) := + lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + _ ≤ ENNReal.ofReal (C + 1) * ENNReal.ofReal B := mul_le_mul le_rfl (hfirst s hs) zero_le zero_le + _ = _ := (ENNReal.ofReal_mul (by linarith : 0 ≤ C + 1)).symm + +instance initialOccupation_isFiniteMeasure (s : EvenState) : IsFiniteMeasure (initialOccupation s) := by + obtain ⟨η, B, hη, hB, hb⟩ := initialOccupation_uniform_exponential s.1 + constructor + apply lt_of_le_of_lt (show initialOccupation s univ ≤ ∫⁻ y, ENNReal.ofReal (Real.exp (η * y.2)) ∂initialOccupation s from ?_) + (lt_of_le_of_lt (hb s le_rfl) ENNReal.ofReal_lt_top) + calc + _ = ∫⁻ _y, (1 : ℝ≥0∞) ∂initialOccupation s := by simp + _ ≤ _ := by + apply lintegral_mono_ae + filter_upwards [initialOccupation_cost_nonneg s] with y hy + exact ENNReal.one_le_ofReal.mpr (Real.one_le_exp (mul_nonneg hη.le hy)) + +theorem initialOccupation_test_decay {F : Test} (_hF : Measurable F) (hB : HasCompactBound F) (S : ℝ) : + ∃ η B : ℝ, 0 < η ∧ 0 ≤ B ∧ ∀ s : EvenState, s.1 ≤ S → ∀ v : ℝ, + ‖∫ y : CostState, F (v - y.2, y.1) ∂initialOccupation s‖ ≤ B * Real.exp (-η * v) := by + obtain ⟨C, M, hC, hM, hbF, hsF⟩ := hB + obtain ⟨η, B, hη, hB, hb⟩ := initialOccupation_uniform_exponential S + refine ⟨η, C * B * Real.exp (η * M), hη, by positivity, ?_⟩ + intro s hs v + have hEi : Integrable (fun y : CostState => Real.exp (η * y.2)) (initialOccupation s) := by + refine ⟨(Real.measurable_exp.comp (measurable_const.mul measurable_snd)).aestronglyMeasurable, ?_⟩ + exact (hasFiniteIntegral_iff_ofReal (Eventually.of_forall fun y : CostState => (Real.exp_pos (η * y.2)).le)).mpr + (lt_of_le_of_lt (hb s hs) ENNReal.ofReal_lt_top) + have hEB : (∫ y : CostState, Real.exp (η * y.2) ∂initialOccupation s) ≤ B := by + apply (ENNReal.ofReal_le_ofReal_iff hB).mp + rw [ofReal_integral_eq_lintegral_ofReal hEi (Eventually.of_forall fun y => (Real.exp_pos _).le)] + exact hb s hs + have hpoint : ∀ y : CostState, ‖F (v - y.2, y.1)‖ ≤ + C * Real.exp (-η * (v - M)) * Real.exp (η * y.2) := by + intro y + by_cases hy : M < |v - y.2| + · rw [hsF _ hy, norm_zero] + positivity + · have hlow : v - M ≤ y.2 := by have h := (abs_le.mp (le_of_not_gt hy)).2; linarith + have hExp : 1 ≤ Real.exp (-η * (v - M)) * Real.exp (η * y.2) := by + rw [← Real.exp_add] + apply Real.one_le_exp + nlinarith + exact le_trans (hbF _) (by nlinarith [mul_le_mul_of_nonneg_left hExp hC]) + calc + _ ≤ ∫ y : CostState, C * Real.exp (-η * (v - M)) * Real.exp (η * y.2) ∂initialOccupation s := + norm_integral_le_of_norm_le (hEi.const_mul _) (Eventually.of_forall hpoint) + _ = C * Real.exp (-η * (v - M)) * (∫ y : CostState, Real.exp (η * y.2) ∂initialOccupation s) := integral_const_mul _ _ + _ ≤ C * Real.exp (-η * (v - M)) * B := mul_le_mul_of_nonneg_left hEB (by positivity) + _ = _ := by + rw [show -η * (v - M) = η * M + -η * v by ring, Real.exp_add] + ring + +end NumberTheoryLean.InitialOccupationMoments + +end + +section + +namespace NumberTheoryLean.UniformDelayedLimit + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open TransitionKernels CostReturnLaw CycleResponse AdmissibleCycleTests +open InitialRegeneration FullOccupationCovariance + +theorem exponential_integrable_of_bound {μ : Measure ℝ} {η B : ℝ} (hB : 0 ≤ B) + (hb : (∫⁻ T, ENNReal.ofReal (Real.exp (η * T)) ∂μ) ≤ ENNReal.ofReal B) : + Integrable (fun T : ℝ => Real.exp (η * T)) μ ∧ (∫ T, Real.exp (η * T) ∂μ) ≤ B := by + have hi : Integrable (fun T : ℝ => Real.exp (η * T)) μ := by + refine ⟨(Real.measurable_exp.comp (measurable_const.mul measurable_id)).aestronglyMeasurable, ?_⟩ + exact (hasFiniteIntegral_iff_ofReal (Eventually.of_forall fun T : ℝ => (Real.exp_pos (η * T)).le)).mpr + (lt_of_le_of_lt hb ENNReal.ofReal_lt_top) + refine ⟨hi, (ENNReal.ofReal_le_ofReal_iff hB).mp ?_⟩ + rwa [ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall fun T => (Real.exp_pos _).le)] + +theorem uniform_shift_limit {ι : Type*} (μ : ι → Measure ℝ) + [∀ i, IsProbabilityMeasure (μ i)] (I : Set ι) {η B K L : ℝ} + (hη : 0 < η) (hB : 0 ≤ B) (hK : 0 ≤ K) + (hmoment : ∀ i ∈ I, (∫⁻ T, ENNReal.ofReal (Real.exp (η * T)) ∂μ i) ≤ ENNReal.ofReal B) + {R : ℝ → ℝ} (hR : Measurable R) (hbound : ∀ u, ‖R u‖ ≤ K) + (hlim : Tendsto R atTop (𝓝 L)) : + ∀ ε : ℝ, 0 < ε → ∃ V : ℝ, ∀ v : ℝ, V ≤ v → ∀ i ∈ I, + ‖(∫ T, R (v - T) ∂μ i) - L‖ < ε := by + intro ε hε + let D := K + ‖L‖ + 1 + have hD : 0 < D := by dsimp [D]; positivity + have hExp : Tendsto (fun M : ℝ => Real.exp (-η * M)) atTop (𝓝 0) := by + simpa only [Function.comp_def, id_eq, neg_mul] using + Real.tendsto_exp_neg_atTop_nhds_zero.comp (Tendsto.const_mul_atTop hη tendsto_id) + have hTail : Tendsto (fun M : ℝ => (D * B) * Real.exp (-η * M)) atTop (𝓝 0) := by + simpa only [mul_zero] using hExp.const_mul (D * B) + obtain ⟨M, hM⟩ := ((tendsto_order.mp hTail).2 (ε / 2) (by positivity)).exists + have hNorm : Tendsto (fun u : ℝ => ‖R u - L‖) atTop (𝓝 0) := by + simpa only [sub_self, norm_zero] using (hlim.sub_const L).norm + obtain ⟨U, hU⟩ := eventually_atTop.mp ((tendsto_order.mp hNorm).2 (ε / 2) (by positivity)) + refine ⟨U + M, ?_⟩ + intro v hv i hi + obtain ⟨hEi, hEB⟩ := exponential_integrable_of_bound hB (hmoment i hi) + have hRi : Integrable (fun T : ℝ => R (v - T)) (μ i) := + ⟨(hR.comp (measurable_const.sub measurable_id)).aestronglyMeasurable, + HasFiniteIntegral.of_bounded (Eventually.of_forall fun T => hbound _)⟩ + have hpoint : ∀ T : ℝ, ‖R (v - T) - L‖ ≤ ε / 2 + D * Real.exp (-η * M) * Real.exp (η * T) := by + intro T + by_cases hT : T ≤ M + · have hx := (hU (v - T) (by linarith)).le + exact le_trans hx (le_add_of_nonneg_right (by positivity)) + · have hd : ‖R (v - T) - L‖ ≤ D := by + have hh := norm_sub_le (R (v - T)) L + have hbR := hbound (v - T) + calc + _ ≤ ‖R (v - T)‖ + ‖L‖ := hh + _ ≤ K + ‖L‖ := add_le_add hbR le_rfl + _ ≤ D := by unfold D; linarith + have he : 1 ≤ Real.exp (-η * M) * Real.exp (η * T) := by + rw [← Real.exp_add] + apply Real.one_le_exp + have hT' : M < T := lt_of_not_ge hT + nlinarith + have hd' : D ≤ D * Real.exp (-η * M) * Real.exp (η * T) := by + nlinarith [mul_le_mul_of_nonneg_left he hD.le] + exact le_trans hd (le_trans hd' (by linarith)) + calc + _ = ‖∫ T, (R (v - T) - L) ∂μ i‖ := by rw [integral_sub hRi (integrable_const L)]; simp + _ ≤ ∫ T, (ε / 2 + D * Real.exp (-η * M) * Real.exp (η * T)) ∂μ i := + norm_integral_le_of_norm_le ((integrable_const (ε / 2)).add (hEi.const_mul _)) (Eventually.of_forall hpoint) + _ = ε / 2 + D * Real.exp (-η * M) * (∫ T, Real.exp (η * T) ∂μ i) := by + rw [integral_add (integrable_const _) (hEi.const_mul _), integral_const_mul] + simp + _ ≤ ε / 2 + D * Real.exp (-η * M) * B := + add_le_add le_rfl (mul_le_mul_of_nonneg_left hEB (by positivity)) + _ < ε := by nlinarith [hM] + +theorem actual_delayed_response_limit {F : Test} (hF : Admissible F) (S : ℝ) : + ∀ ε : ℝ, 0 < ε → ∃ V : ℝ, ∀ v : ℝ, V ≤ v → ∀ s : EvenState, s.1 ≤ S → + ‖(∫ T, fullResponse F (v - T) ∂delayedCostLaw s) - + ((∫ u : ℝ, response F u) / (∫ G : ℝ, G ∂cycleCostLaw))‖ < ε := by + obtain ⟨η, B, hη, hB, hb⟩ := delayedCostLaw_uniform_exponential S + obtain ⟨K, hK, hbound⟩ := fullResponse_uniform_bound hF.measurable hF.compactBound + exact uniform_shift_limit delayedCostLaw {s : EvenState | s.1 ≤ S} hη hB hK + (fun s hs => hb s hs) (fullResponse_measurable hF.measurable) hbound (fullResponse_limit hF) + +end NumberTheoryLean.UniformDelayedLimit + +end + +section + +namespace NumberTheoryLean.EvenStartOccupation + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open TransitionKernels FinitePathMeasures PairedCostProcess PairedCostGrouping +open CostReturnLaw CycleResponse AdmissibleCycleTests OccupationDecomposition +open InitialRegeneration InitialOccupation InitialOccupationMoments +open FullOccupationCovariance UniformDelayedLimit + +theorem compactBound_norm {F : Test} (hB : HasCompactBound F) : HasCompactBound (fun x => ‖F x‖) := by + obtain ⟨C, M, hC, hM, hb, hs⟩ := hB + refine ⟨C, M, hC, hM, ?_, ?_⟩ + · intro x + simpa only [norm_norm] using hb x + · intro x hx + change ‖F x‖ = 0 + rw [hs x hx, norm_zero] + +theorem initial_test_integrable {F : Test} (hF : Measurable F) (hB : HasCompactBound F) + (s : EvenState) (v : ℝ) : + Integrable (fun y : CostState => F (v - y.2, y.1)) (initialOccupation s) := by + obtain ⟨C, M, hC, hM, hb, hs⟩ := hB + exact ⟨(shiftedTest_measurable hF v).aestronglyMeasurable, + HasFiniteIntegral.of_bounded (Eventually.of_forall fun _ => hb _)⟩ + +theorem future_after_delay_integrable {F : Test} (hF : Measurable F) (hB : HasCompactBound F) + (s : EvenState) (v : ℝ) : + Integrable (fun y : CostState => F (v - y.2, y.1)) ((pairedOccupation ∘ₖ delayedRegeneration) s) := by + have hm : AEStronglyMeasurable (fun y : CostState => F (v - y.2, y.1)) + ((pairedOccupation ∘ₖ delayedRegeneration) s) := (shiftedTest_measurable hF v).aestronglyMeasurable + apply (integrable_comp_iff hm).mpr + constructor + · filter_upwards [delayedRegeneration_ae_regeneration s] with z hz + exact fullOccupation_regeneration_integrable z hz hF hB v + · obtain ⟨K, hK, hb⟩ := fullResponse_uniform_bound hF.norm (compactBound_norm hB) + refine ⟨hm.norm.integral_kernel_comp, HasFiniteIntegral.of_bounded (C := K) ?_⟩ + filter_upwards [delayedRegeneration_ae_regeneration s] with z hz + rw [fullOccupation_regeneration_integral z hz (F := fun x => ‖F x‖) hF.norm v] + exact hb (v - z.2) + +theorem even_full_test_integrable {F : Test} (hF : Measurable F) (hB : HasCompactBound F) + (s : EvenState) (v : ℝ) : + Integrable (fun y : CostState => F (v - y.2, y.1)) (fullOccupation (.inl s, 0)) := by + rw [initial_occupation_decomposition_apply] + exact (initial_test_integrable hF hB s v).add_measure (future_after_delay_integrable hF hB s v) + +theorem even_full_signed_decomposition {F : Test} (hF : Measurable F) (hB : HasCompactBound F) + (s : EvenState) (v : ℝ) : + (∫ y : CostState, F (v - y.2, y.1) ∂fullOccupation (.inl s, 0)) = + (∫ y : CostState, F (v - y.2, y.1) ∂initialOccupation s) + + ∫ T, fullResponse F (v - T) ∂delayedCostLaw s := by + rw [initial_occupation_decomposition_apply, + integral_add_measure (initial_test_integrable hF hB s v) (future_after_delay_integrable hF hB s v), + Kernel.integral_comp (future_after_delay_integrable hF hB s v), delayedCostLaw, + integral_map (f := fun T : ℝ => fullResponse F (v - T)) measurable_snd.aemeasurable + ((fullResponse_measurable hF).comp (measurable_const.sub measurable_id)).aestronglyMeasurable] + congr 1 + apply integral_congr_ae + filter_upwards [delayedRegeneration_ae_regeneration s] with z hz + exact fullOccupation_regeneration_integral z hz hF v + +noncomputable def evenResponse (F : Test) (s : EvenState) (v : ℝ) : ℝ := + F (v, .inl s) + ∫ y : CostState, F (v - y.2, y.1) ∂fullOccupation (.inl s, 0) + +theorem uniform_even_occupation_limit {F : Test} (hF : Admissible F) (S : ℝ) : + ∀ ε : ℝ, 0 < ε → ∃ V : ℝ, ∀ v : ℝ, V ≤ v → ∀ s : EvenState, s.1 ≤ S → + ‖evenResponse F s v - ((∫ u : ℝ, response F u) / (∫ G : ℝ, G ∂cycleCostLaw))‖ < ε := by + obtain ⟨C, M, hC, hM, hb, hsupp⟩ := hF.compactBound + obtain ⟨η, B, hη, hB, hinit⟩ := initialOccupation_test_decay hF.measurable hF.compactBound S + have hExp : Tendsto (fun v : ℝ => B * Real.exp (-η * v)) atTop (𝓝 0) := by + have h := Real.tendsto_exp_neg_atTop_nhds_zero.comp (Tendsto.const_mul_atTop hη tendsto_id) + simpa only [Function.comp_def, id_eq, neg_mul, mul_zero] using h.const_mul B + intro ε hε + obtain ⟨V₁, hV₁⟩ := eventually_atTop.mp ((tendsto_order.mp hExp).2 (ε / 2) (by positivity)) + obtain ⟨V₂, hV₂⟩ := actual_delayed_response_limit hF S (ε / 2) (by positivity) + refine ⟨max (max V₁ V₂) (M + 1), ?_⟩ + intro v hv s hs + have hv₁ : V₁ ≤ v := le_trans (le_trans (le_max_left _ _) (le_max_left _ _)) hv + have hv₂ : V₂ ≤ v := le_trans (le_trans (le_max_right _ _) (le_max_left _ _)) hv + have hvM : M + 1 ≤ v := le_trans (le_max_right _ _) hv + have hz : F (v, .inl s) = 0 := hsupp _ (by change M < |v|; linarith [le_abs_self v]) + rw [evenResponse, hz, zero_add, even_full_signed_decomposition hF.measurable hF.compactBound] + let L := (∫ u : ℝ, response F u) / (∫ G : ℝ, G ∂cycleCostLaw) + have ha : ‖∫ y : CostState, F (v - y.2, y.1) ∂initialOccupation s‖ < ε / 2 := + lt_of_le_of_lt (hinit s hs v) (hV₁ v hv₁) + have hd := hV₂ v hv₂ s hs + have heq : (∫ y : CostState, F (v - y.2, y.1) ∂initialOccupation s) + + (∫ T, fullResponse F (v - T) ∂delayedCostLaw s) - L = + (∫ y : CostState, F (v - y.2, y.1) ∂initialOccupation s) + + ((∫ T, fullResponse F (v - T) ∂delayedCostLaw s) - L) := by ring + change ‖_ + _ - L‖ < ε + rw [heq] + exact lt_of_le_of_lt (norm_add_le _ _) (by linarith) + +theorem source_start_occupation_limit {F : Test} (hF : Admissible F) : + ∀ ε : ℝ, 0 < ε → ∃ V : ℝ, ∀ v : ℝ, V ≤ v → ∀ s : EvenState, + (199 / 100 : ℝ) ≤ s.1 → s.1 ≤ 23 / 10 → + ‖evenResponse F s v - ((∫ u : ℝ, response F u) / (∫ G : ℝ, G ∂cycleCostLaw))‖ < ε := by + intro ε hε + obtain ⟨V, hV⟩ := uniform_even_occupation_limit hF (23 / 10) ε hε + exact ⟨V, fun v hv s _ hs => hV v hv s hs⟩ + +end NumberTheoryLean.EvenStartOccupation + +end + +section + +namespace NumberTheoryLean.NormalizedOccupationLimit + +open Filter Set MeasureTheory +open scoped Topology +open FinitePathMeasures CycleResponse AdmissibleCycleTests OccupationConstant +open EvenStartOccupation FullOccupationCovariance +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantCostBound +open Erdos970Dependency.StateKernelInvariance Erdos970Dependency.CycleMeanCost + +noncomputable def invariantAverage (F : Test) : ℝ := + (∫ s : State, integratedStateTest F s ∂stateMeasure) / costMass + +theorem occupation_constant_eq {F : Test} (hF : Measurable F) (hB : HasCompactBound F) : + ((∫ v : ℝ, response F v) / (∫ G : ℝ, G ∂CostReturnLaw.cycleCostLaw)) = invariantAverage F := by + rw [(response_integral_eq_invariant hF hB).2, cycle_mean_eq, invariantAverage] + field_simp [beta_pos.ne', costMass_pos.ne'] + +theorem normalized_regeneration_occupation_limit {F : Test} (hF : Admissible F) : + Tendsto (fullResponse F) atTop (𝓝 (invariantAverage F)) := by + have h := fullResponse_limit hF + rwa [occupation_constant_eq hF.measurable hF.compactBound] at h + +theorem normalized_uniform_even_occupation_limit {F : Test} (hF : Admissible F) (S : ℝ) : + ∀ ε : ℝ, 0 < ε → ∃ V : ℝ, ∀ v : ℝ, V ≤ v → ∀ s : TransitionKernels.EvenState, s.1 ≤ S → + ‖evenResponse F s v - invariantAverage F‖ < ε := by + have h := uniform_even_occupation_limit hF S + rwa [occupation_constant_eq hF.measurable hF.compactBound] at h + +theorem source_compact_occupation_limit {F : Test} (hF : Admissible F) : + ∀ ε : ℝ, 0 < ε → ∃ V : ℝ, ∀ v : ℝ, V ≤ v → ∀ s : TransitionKernels.EvenState, + (199 / 100 : ℝ) ≤ s.1 → s.1 ≤ 23 / 10 → + ‖evenResponse F s v - invariantAverage F‖ < ε := by + have h := source_start_occupation_limit hF + rwa [occupation_constant_eq hF.measurable hF.compactBound] at h + +end NumberTheoryLean.NormalizedOccupationLimit + +end + +section + +namespace NumberTheoryLean.RegenerationBandBounds + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures PairedCostGrouping RegenerationTails CostReturnLaw +open CycleOccupation CycleConvolutionLaw OccupationDecomposition OccupationRegeneration +open AbsorptionCutoff.Renewal +open Erdos970Dependency.InvariantDensities Erdos970Dependency.StateKernelInvariance +open Erdos970Dependency.ActualCycleOccupation + +instance cycleRenewal_sFinite : SFinite (renewalMeasure cycleCostLaw) := by + unfold renewalMeasure + infer_instance + +noncomputable def stateBandReward (Q : State → ℝ≥0∞) (v h : ℝ) : CostState → ℝ≥0∞ := + (Prod.snd ⁻¹' Icc v (v + h)).indicator (fun y => Q y.1) + +theorem sub_mem_band_iff (v T h : ℝ) : v - T ∈ Icc (-h) 0 ↔ T ∈ Icc v (v + h) := by + simp only [mem_Icc] + constructor <;> rintro ⟨h₁, h₂⟩ <;> constructor <;> linarith + +theorem regeneration_band_identity {Q : State → ℝ≥0∞} (hQ : Measurable Q) (v h : ℝ) : + (∫⁻ y, stateBandReward Q v h y ∂fullOccupation (embedOdd (regenerationState, 0))) = + ∫⁻ y : CostState, Q y.1 * renewalMeasure cycleCostLaw (Icc (v - y.2) (v + h - y.2)) ∂occupationMeasure := by + classical + let F : ℝ × State → ℝ≥0∞ := (Prod.fst ⁻¹' Icc (-h) 0).indicator (fun x => Q x.2) + have hF : Measurable F := (hQ.comp measurable_snd).indicator (measurable_fst measurableSet_Icc) + have heq : stateBandReward Q v h = fun y : CostState => F (v - y.2, y.1) := by + funext y + simp only [stateBandReward, F, indicator_apply, mem_preimage, sub_mem_band_iff] + rw [heq, fullOccupation_positive_convolution hF, ← lintegral_sum_measure, actualArrival_sum_eq_renewal] + change (∫⁻ T : ℝ, ∫⁻ y : CostState, F (v - T - y.2, y.1) ∂occupationMeasure ∂renewalMeasure cycleCostLaw) = _ + have hjoint : Measurable (Function.uncurry (fun T : ℝ => fun y : CostState => F (v - T - y.2, y.1))) := + hF.comp (((measurable_const.sub measurable_fst).sub (measurable_snd.comp measurable_snd)).prodMk + (measurable_fst.comp measurable_snd)) + rw [lintegral_lintegral_swap hjoint.aemeasurable] + apply lintegral_congr + intro y + have hinner : (fun T : ℝ => F (v - T - y.2, y.1)) = + (Icc (v - y.2) (v + h - y.2)).indicator (fun _ : ℝ => Q y.1) := by + funext T + have hiff : v - T - y.2 ∈ Icc (-h) 0 ↔ T ∈ Icc (v - y.2) (v + h - y.2) := by + simp only [mem_Icc] + constructor <;> rintro ⟨h₁, h₂⟩ <;> constructor <;> linarith + simp only [F, indicator_apply, mem_preimage] + simp only [hiff] + rw [hinner, lintegral_indicator measurableSet_Icc, lintegral_const] + simp + +theorem regeneration_uniform_band (h : ℝ) : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ Q : State → ℝ≥0∞, Measurable Q → ∀ v : ℝ, + (∫⁻ y, stateBandReward Q v h y ∂fullOccupation (embedOdd (regenerationState, 0))) ≤ + C * ∫⁻ s : State, Q s ∂stateMeasure := by + obtain ⟨B, hB⟩ := CycleRenewalInputs.cycle_renewal_cell_bound h + let C := ENNReal.ofReal B * (ENNReal.ofReal beta)⁻¹ + have hβ : ENNReal.ofReal beta ≠ 0 := (ENNReal.ofReal_pos.mpr beta_pos).ne' + have hC : C < ∞ := lt_top_iff_ne_top.mpr (ENNReal.mul_ne_top ENNReal.ofReal_ne_top (ENNReal.inv_ne_top.mpr hβ)) + refine ⟨C, hC, ?_⟩ + intro Q hQ v + rw [regeneration_band_identity hQ v h] + calc + _ ≤ ∫⁻ y : CostState, Q y.1 * ENNReal.ofReal B ∂occupationMeasure := by + apply lintegral_mono + intro y + apply mul_le_mul le_rfl _ zero_le zero_le + have hb := hB (v - y.2) + rwa [show (v - y.2) + h = v + h - y.2 by ring] at hb + _ = (∫⁻ y : CostState, Q y.1 ∂occupationMeasure) * ENNReal.ofReal B := + lintegral_mul_const' _ _ ENNReal.ofReal_ne_top + _ = C * ∫⁻ s : State, Q s ∂stateMeasure := by + rw [lintegral_state_occupation hQ] + dsimp [C] + ring + +end NumberTheoryLean.RegenerationBandBounds + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationDrift.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6f3428032322daf5f8463ce6783cb905d60b510 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationDrift.lean @@ -0,0 +1,268 @@ +import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals +import Mathlib.MeasureTheory.Integral.Layercake +import OAI.NumberTheory.Jacobsthal.Estimates.InverseWeightGrowth + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.RegenerationTails + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open BuchstabBridge DerivativeWeights WeightFutureIntegrals WeightTailBounds +open TransitionKernels FinitePathMeasures + +theorem tailDensity_setIntegral {left right mass : ℝ} {B : ℝ → ℝ} (h : left ≤ right) : + (∫ t in Ici right, tailDensity left mass B t) = (∫ t in Ici right, B t) / mass := by + calc + _ = ∫ t in Ici right, B t / mass := by + apply setIntegral_congr_fun measurableSet_Ici + intro t ht + exact indicator_of_mem (show t ∈ Ici left from le_trans h ht) _ + _ = _ := integral_div mass B + +theorem evenKernel_tail (s : EvenState) {h : ℝ} (hh : 0 ≤ h) : + evenKernel s (Ici (s.1 - 1 + h)) = ENNReal.ofReal (phiEven (s.1 + h) / phiEven s.1) := by + rw [evenKernel_apply, ← ofReal_integral_eq_lintegral_ofReal + (evenDensity_integrable s).integrableOn (Eventually.of_forall (evenDensity_nonneg s))] + congr 1 + change (∫ t in Ici (s.1 - 1 + h), tailDensity (s.1 - 1) (phiEven s.1) (fun t => W t * phiOdd t) t) = _ + rw [tailDensity_setIntegral (by linarith), integral_Ici_eq_integral_Ioi] + have hf := (phiEven_future_integral (s := s.1 + h) (by linarith [s.2])).2 + rw [show s.1 + h - 1 = s.1 - 1 + h by ring] at hf + rw [← hf] + +theorem oddKernel_tail (s : OddState) (hs : 3 ≤ s.1) {h : ℝ} (hh : 0 ≤ h) : + oddKernel s (Ici (s.1 - 1 + h)) = ENNReal.ofReal (phiOdd (s.1 + h) / phiOdd s.1) := by + rw [oddKernel_apply, ← ofReal_integral_eq_lintegral_ofReal + (oddDensity_integrable s).integrableOn (Eventually.of_forall (oddDensity_nonneg s))] + congr 1 + change (∫ t in Ici (s.1 - 1 + h), tailDensity (max 2 (s.1 - 1)) (phiOdd s.1) + (fun t => W t * phiEven t) t) = _ + rw [tailDensity_setIntegral (by apply max_le <;> linarith), integral_Ici_eq_integral_Ioi] + have hf := (phiOdd_future_integral (s.1 + h)).2 + rw [max_eq_right (show 2 ≤ s.1 + h - 1 by linarith), + show s.1 + h - 1 = s.1 - 1 + h by ring] at hf + rw [← hf] + +theorem exponential_comparison {P : ℝ → ℝ} {U rate a b : ℝ} + (hp : ∀ t, U ≤ t → 0 < P t) + (hd : ∀ t, U ≤ t → DifferentiableAt ℝ P t) + (hl : ∀ t, U ≤ t → rate ≤ -deriv P t / P t) + (ha : U ≤ a) (hab : a ≤ b) : P b ≤ P a * Real.exp (-rate * (b - a)) := by + let H : ℝ → ℝ := fun t => Real.exp (rate * t) * P t + have hder : ∀ t, U ≤ t → HasDerivAt H + (Real.exp (rate * t) * (deriv P t + rate * P t)) t := by + intro t ht + have h := (((hasDerivAt_id t).const_mul rate).exp).mul (hd t ht).hasDerivAt + convert! h using 1 + simp only [id_eq, mul_one] + ring + have hm : AntitoneOn H (Icc a b) := by + apply antitoneOn_of_deriv_nonpos (convex_Icc _ _) + · intro t ht + exact (hder t (by linarith [ht.1])).continuousAt.continuousWithinAt + · intro t ht + rw [interior_Icc] at ht + exact (hder t (by linarith [ht.1])).differentiableAt.differentiableWithinAt + · intro t ht + rw [interior_Icc] at ht + have htU : U ≤ t := by linarith [ht.1] + rw [(hder t htU).deriv] + apply mul_nonpos_of_nonneg_of_nonpos (Real.exp_pos _).le + have h := (le_div_iff₀ (hp t htU)).mp (hl t htU) + linarith + have h := hm ⟨le_rfl, hab⟩ ⟨hab, le_rfl⟩ hab + have hq : P b ≤ Real.exp (rate * a) * P a / Real.exp (rate * b) := by + apply (le_div_iff₀ (Real.exp_pos _)).mpr + simpa only [H, mul_comm] using h + calc + P b ≤ Real.exp (rate * a) * P a / Real.exp (rate * b) := hq + _ = P a * (Real.exp (rate * a) / Real.exp (rate * b)) := by ring + _ = _ := by rw [← Real.exp_sub]; congr 1; congr 1; ring + +theorem kernel_exponential_tails (rate : ℝ) : ∃ U : ℝ, 4 ≤ U ∧ + (∀ s : EvenState, U ≤ s.1 → ∀ h : ℝ, 0 ≤ h → + evenKernel s (Ici (s.1 - 1 + h)) ≤ ENNReal.ofReal (Real.exp (-rate * h))) ∧ + (∀ s : OddState, U ≤ s.1 → ∀ h : ℝ, 0 ≤ h → + oddKernel s (Ici (s.1 - 1 + h)) ≤ ENNReal.ofReal (Real.exp (-rate * h))) := by + obtain ⟨U, hU, hb⟩ := weights_logDeriv_growth rate + refine ⟨U, hU, ?_, ?_⟩ + · intro s hs h hh + rw [evenKernel_tail s hh] + apply ENNReal.ofReal_le_ofReal + apply (div_le_iff₀ (phiEven_pos (by linarith))).mpr + have he := exponential_comparison (P := phiEven) + (fun t ht => phiEven_pos (by linarith)) + (fun t ht => (phiEven_hasDerivAt (by linarith)).differentiableAt) + (fun t ht => (hb t ht).1) hs (show s.1 ≤ s.1 + h by linarith) + simpa only [add_sub_cancel_left, mul_comm] using he + · intro s hs h hh + rw [oddKernel_tail s (by linarith) hh] + apply ENNReal.ofReal_le_ofReal + apply (div_le_iff₀ (phiOdd_pos s.1)).mpr + have ho := exponential_comparison (P := phiOdd) (fun t _ => phiOdd_pos t) + (fun t ht => (phiOdd_hasDerivAt (by linarith)).differentiableAt) + (fun t ht => (hb t ht).2) hs (show s.1 ≤ s.1 + h by linarith) + simpa only [add_sub_cancel_left, mul_comm] using ho + +def regenerationState : OddState := ⟨1, by norm_num⟩ + +theorem oddKernel_regeneration (s : OddState) (hs : s.1 ≤ 3) : + oddKernel s = oddKernel regenerationState := by + ext B hB + rw [oddKernel_apply, oddKernel_apply] + congr 1 + ext t + congr 1 + unfold oddDensity + rw [max_eq_left (show s.1 - 1 ≤ 2 by linarith), phiOdd_initial hs] + norm_num [regenerationState, phiOdd, tailDensity] + +theorem stateKernel_regeneration (s : OddState) (hs : s.1 ≤ 3) : + stateKernel (.inr s) = stateKernel (.inr regenerationState) := by + change oddBranch s = oddBranch regenerationState + rw [oddBranch, Kernel.map_apply _ measurable_inl, Kernel.map_apply _ measurable_inl, + oddToEven, Kernel.comapRight_apply, Kernel.comapRight_apply, oddKernel_regeneration s hs] + +theorem costKernel_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + costKernel (.inr s, T) = costKernel (.inr regenerationState, T) := by + ext B hB + rw [costKernel_apply _ hB, costKernel_apply _ hB] + exact congrArg (fun μ : Measure State => μ {t | (t, T + FinitePathGeometry.cost (stateRatio t)) ∈ B}) + (stateKernel_regeneration s hs) + +end NumberTheoryLean.RegenerationTails + +end + +section + +namespace NumberTheoryLean.RegenerationDrift + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open TransitionKernels RegenerationTails + +theorem exponential_moment_of_tail (μ : Measure ℝ) [IsProbabilityMeasure μ] (m : ℝ) + (hsupport : ∀ᵐ x ∂μ, m ≤ x) + (htail : ∀ h : ℝ, 0 ≤ h → μ (Ici (m + h)) ≤ ENNReal.ofReal (Real.exp (-2 * h))) : + (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂μ) ≤ ENNReal.ofReal (2 * Real.exp m) := by + have hnn : 0 ≤ᵐ[μ] (fun x : ℝ => x - m) := by + filter_upwards [hsupport] with x hx + exact sub_nonneg.mpr hx + have hlc := lintegral_comp_eq_lintegral_meas_le_mul (f := fun x : ℝ => x - m) + (g := Real.exp) μ hnn (measurable_id.sub measurable_const).aemeasurable + (fun t _ => Real.continuous_exp.intervalIntegrable 0 t) + (Eventually.of_forall (fun t => (Real.exp_pos t).le)) + simp only [integral_exp, Real.exp_zero] at hlc + have hsmall : (∫⁻ x, ENNReal.ofReal (Real.exp (x - m) - 1) ∂μ) ≤ 1 := by + rw [hlc] + calc + _ ≤ ∫⁻ h in Ioi (0 : ℝ), ENNReal.ofReal (Real.exp (-h)) := by + apply lintegral_mono_ae + filter_upwards [self_mem_ae_restrict measurableSet_Ioi] with h hh + have hset : {x : ℝ | h ≤ x - m} = Ici (m + h) := by ext x; simp only [mem_ofPred_eq, mem_Ici]; constructor <;> intro hx <;> linarith + rw [hset] + calc + _ ≤ ENNReal.ofReal (Real.exp (-2 * h)) * ENNReal.ofReal (Real.exp h) := + mul_le_mul (htail h hh.le) le_rfl zero_le zero_le + _ = _ := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add] + congr 2 + ring + _ = 1 := by + rw [← ofReal_integral_eq_lintegral_ofReal (integrableOn_exp_neg_Ioi 0) + (Eventually.of_forall (fun h => (Real.exp_pos (-h)).le)), integral_exp_neg_Ioi_zero] + norm_num + have hshiftMeas : Measurable (fun x : ℝ => ENNReal.ofReal (Real.exp (x - m) - 1)) := + ENNReal.measurable_ofReal.comp ((Real.measurable_exp.comp (measurable_id.sub measurable_const)).sub measurable_const) + have heq : (fun x : ℝ => ENNReal.ofReal (Real.exp (x - m))) =ᵐ[μ] + (fun x => ENNReal.ofReal (Real.exp (x - m) - 1) + 1) := by + filter_upwards [hsupport] with x hx + have he : 1 ≤ Real.exp (x - m) := Real.one_le_exp_iff.mpr (sub_nonneg.mpr hx) + rw [← ENNReal.ofReal_one, ← ENNReal.ofReal_add (sub_nonneg.mpr he) zero_le_one] + congr 1 + ring + have hshift : (∫⁻ x, ENNReal.ofReal (Real.exp (x - m)) ∂μ) ≤ 2 := by + rw [lintegral_congr_ae heq, lintegral_add_left hshiftMeas] + simp only [lintegral_const, measure_univ, mul_one] + calc + _ ≤ 1 + 1 := add_le_add hsmall le_rfl + _ = 2 := by norm_num + have hscale : ∀ x : ℝ, ENNReal.ofReal (Real.exp x) = + ENNReal.ofReal (Real.exp m) * ENNReal.ofReal (Real.exp (x - m)) := by + intro x + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add] + congr 2 + ring + rw [lintegral_congr hscale, lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + calc + _ ≤ ENNReal.ofReal (Real.exp m) * 2 := mul_le_mul le_rfl hshift zero_le zero_le + _ = _ := by rw [ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≤ 2)]; norm_num; ring + +theorem exponential_integrable_of_tail (μ : Measure ℝ) [IsProbabilityMeasure μ] (m : ℝ) + (hsupport : ∀ᵐ x ∂μ, m ≤ x) + (htail : ∀ h : ℝ, 0 ≤ h → μ (Ici (m + h)) ≤ ENNReal.ofReal (Real.exp (-2 * h))) : + Integrable Real.exp μ := by + refine ⟨Real.continuous_exp.aestronglyMeasurable, ?_⟩ + apply (hasFiniteIntegral_iff_ofReal (Eventually.of_forall (fun x => (Real.exp_pos x).le))).mpr + exact lt_of_le_of_lt (exponential_moment_of_tail μ m hsupport htail) ENNReal.ofReal_lt_top + +noncomputable def driftFactor : ℝ := 2 / Real.exp 1 + +theorem driftFactor_pos : 0 < driftFactor := by unfold driftFactor; positivity +theorem driftFactor_lt_one : driftFactor < 1 := by + unfold driftFactor + exact (div_lt_one (Real.exp_pos 1)).mpr Real.exp_one_gt_two + +theorem drift_scale (s : ℝ) : 2 * Real.exp (s - 1) = driftFactor * Real.exp s := by + unfold driftFactor + rw [Real.exp_sub] + ring + +theorem kernel_exponential_drift : ∃ U : ℝ, 4 ≤ U ∧ + (∀ s : EvenState, U ≤ s.1 → Integrable Real.exp (evenKernel s) ∧ + (∫⁻ t, ENNReal.ofReal (Real.exp t) ∂evenKernel s) ≤ ENNReal.ofReal (driftFactor * Real.exp s.1)) ∧ + (∀ s : OddState, U ≤ s.1 → Integrable Real.exp (oddKernel s) ∧ + (∫⁻ t, ENNReal.ofReal (Real.exp t) ∂oddKernel s) ≤ ENNReal.ofReal (driftFactor * Real.exp s.1)) := by + obtain ⟨U, hU, he, ho⟩ := kernel_exponential_tails 2 + refine ⟨U, hU, ?_, ?_⟩ + · intro s hs + refine ⟨exponential_integrable_of_tail _ (s.1 - 1) (evenKernel_ae_support s) (he s hs), ?_⟩ + simpa only [drift_scale] using exponential_moment_of_tail _ (s.1 - 1) (evenKernel_ae_support s) (he s hs) + · intro s hs + have hsupport : ∀ᵐ t ∂oddKernel s, s.1 - 1 ≤ t := by + filter_upwards [oddKernel_ae_support s] with t ht + exact le_trans (le_max_right _ _) ht + refine ⟨exponential_integrable_of_tail _ (s.1 - 1) hsupport (ho s hs), ?_⟩ + simpa only [drift_scale] using exponential_moment_of_tail _ (s.1 - 1) hsupport (ho s hs) + +theorem kernel_drift_expectation : ∃ U : ℝ, 4 ≤ U ∧ + (∀ s : EvenState, U ≤ s.1 → Integrable Real.exp (evenKernel s) ∧ + (∫ t, Real.exp t ∂evenKernel s) ≤ driftFactor * Real.exp s.1) ∧ + (∀ s : OddState, U ≤ s.1 → Integrable Real.exp (oddKernel s) ∧ + (∫ t, Real.exp t ∂oddKernel s) ≤ driftFactor * Real.exp s.1) := by + obtain ⟨U, hU, he, ho⟩ := kernel_exponential_drift + refine ⟨U, hU, ?_, ?_⟩ + · intro s hs + obtain ⟨hi, hb⟩ := he s hs + refine ⟨hi, (ENNReal.ofReal_le_ofReal_iff (mul_pos driftFactor_pos (Real.exp_pos _)).le).mp ?_⟩ + rw [ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall (fun t => (Real.exp_pos t).le))] + exact hb + · intro s hs + obtain ⟨hi, hb⟩ := ho s hs + refine ⟨hi, (ENNReal.ofReal_le_ofReal_iff (mul_pos driftFactor_pos (Real.exp_pos _)).le).mp ?_⟩ + rw [ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall (fun t => (Real.exp_pos t).le))] + exact hb + +end NumberTheoryLean.RegenerationDrift + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationInputPotential.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationInputPotential.lean new file mode 100644 index 0000000000000000000000000000000000000000..c6f96c4b1792e9df6164ebc4f62e991f931b4482 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerationInputPotential.lean @@ -0,0 +1,55 @@ +import OAI.NumberTheory.Jacobsthal.Paths.CanonicalPairVisitCompletion + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.InitialRegeneration NumberTheoryLean.KernelPotential + +noncomputable def regenerationInput : Kernel OddCost OddCost := stateFilter returnSet_measurable +noncomputable def nonregenerationInput : Kernel OddCost OddCost := stateFilter returnSet_measurable.compl + +instance regenerationInput_isFiniteKernel : IsFiniteKernel regenerationInput := by unfold regenerationInput; infer_instance +instance nonregenerationInput_isFiniteKernel : IsFiniteKernel nonregenerationInput := by unfold nonregenerationInput; infer_instance + +lemma regenerationInput_after_pair : regenerationInput ∘ₖ pairedCostKernel=costCaptured := by + rw [regenerationInput,stateFilter_output] + rfl + +lemma nonregenerationInput_after_pair : nonregenerationInput ∘ₖ pairedCostKernel=costKilled := by + rw [nonregenerationInput,stateFilter_output] + rfl + +lemma returnLaw_potential : returnLaw=potential costCaptured costKilled := rfl + +lemma hitOrReturn_input_split : hitOrReturn=regenerationInput+returnLaw ∘ₖ nonregenerationInput := by + ext z S hS + rw [hitOrReturn,Kernel.piecewise_apply,_root_.add_apply,Measure.add_apply, + regenerationInput,stateFilter_apply,nonregenerationInput,stateFilter_input] + by_cases hz : z ∈ returnSet + · simp only [hz,ite_true,mem_compl_iff,not_true_eq_false,ite_false,Measure.coe_zero,Pi.zero_apply,add_zero] + rfl + · simp only [hz,ite_false,mem_compl_iff,not_false_eq_true,ite_true,Measure.coe_zero,Pi.zero_apply,zero_add] + +theorem hitOrReturn_eq_input_potential : + hitOrReturn=potential regenerationInput (pairedCostKernel ∘ₖ nonregenerationInput) := by + have hR : returnLaw= + (potential regenerationInput (pairedCostKernel ∘ₖ nonregenerationInput)) ∘ₖ pairedCostKernel := by + rw [returnLaw_potential,← regenerationInput_after_pair,← nonregenerationInput_after_pair] + exact potential_exchange regenerationInput pairedCostKernel nonregenerationInput + rw [potential_unfold,← Kernel.comp_assoc,← hR] + exact hitOrReturn_input_split + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerativeOddOccupation.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerativeOddOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..528ab562684643deebfd0221a4e0af6082380259 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RegenerativeOddOccupation.lean @@ -0,0 +1,144 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PairedBlockContraction +import OAI.NumberTheory.Jacobsthal.Estimates.RegenerativeResolvent +import OAI.NumberTheory.Jacobsthal.Probability.StateKernelInvariance + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.RegenerationMass +open NumberTheoryLean.TransitionKernels NumberTheoryLean.PairedHitting +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantFiniteness +open Erdos970Dependency.OrdinaryKernelInvariance Erdos970Dependency.StateKernelInvariance + +theorem oddMeasure_below_one : oddMeasure (Iio (1 : ℝ)) = 0 := by + rw [oddMeasure, withDensity_apply _ measurableSet_Iio] + apply setLIntegral_eq_zero measurableSet_Iio + intro s hs + change ENNReal.ofReal (InvariantDensities.oddDensity s) = 0 + unfold InvariantDensities.oddDensity + rw [indicator_of_notMem (show s ∉ Ici (1 : ℝ) by change s < 1 at hs; change ¬1 ≤ s; linarith), ENNReal.ofReal_zero] + +theorem oddMeasure_regeneration_interval : oddMeasure (Icc (1 : ℝ) 3) = ENNReal.ofReal beta := by + rw [oddMeasure, withDensity_apply _ measurableSet_Icc, + ← ofReal_integral_eq_lintegral_ofReal InvariantFiniteness.oddDensity_integrable.integrableOn + (Filter.Eventually.of_forall InvariantDensities.oddDensity_nonneg)] + congr 1 + rw [integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le (by norm_num : (1 : ℝ) ≤ 3)] + rfl + +theorem oddMeasure_Iic_three : oddMeasure (Iic (3 : ℝ)) = ENNReal.ofReal beta := by + rw [← Iio_union_Icc_eq_Iic (by norm_num : (1 : ℝ) ≤ 3)] + rw [measure_union (by + apply Set.disjoint_left.mpr + intro s hs hcc + exact (not_le_of_gt hs) hcc.1) measurableSet_Icc, + oddMeasure_below_one, oddMeasure_regeneration_interval, zero_add] + +theorem oddStateMeasure_regeneration : oddStateMeasure pairedRegeneration = ENNReal.ofReal beta := by + rw [oddStateMeasure, Measure.map_apply oddLift_measurable pairedRegeneration_measurable] + have hpre : oddLift ⁻¹' pairedRegeneration = Iic (3 : ℝ) := by + ext s + change max (95 / 100 : ℝ) s ≤ 3 ↔ s ≤ 3 + rw [max_le_iff] + norm_num + rw [hpre, oddMeasure_Iic_three] + +theorem oddStateMeasure_mass_pos : 0 < oddStateMeasure univ := by + have hpos : 0 < oddStateMeasure pairedRegeneration := by + rw [oddStateMeasure_regeneration] + exact ENNReal.ofReal_pos.mpr beta_pos + exact hpos.trans_le (measure_mono (subset_univ _)) + +theorem stateMeasure_mass_pos : 0 < stateMeasure univ := by + rw [stateMeasure, Measure.add_apply, + Measure.map_apply measurable_inl MeasurableSet.univ, + Measure.map_apply measurable_inr MeasurableSet.univ] + simp only [preimage_univ] + exact lt_of_lt_of_le oddStateMeasure_mass_pos (le_add_left le_rfl) + +theorem stateMeasure_ne_zero : stateMeasure ≠ 0 := by + intro h + have hp := stateMeasure_mass_pos + rw [h, Measure.coe_zero, Pi.zero_apply] at hp + exact (lt_irrefl (0 : ℝ≥0∞)) hp + +end Erdos970Dependency.RegenerationMass + +end + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped ENNReal ProbabilityTheory Topology +namespace Erdos970Dependency.RegenerativeOddOccupation +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.PairedHitting NumberTheoryLean.PairedBlockContraction +open NumberTheoryLean.RegenerationTails NumberTheoryLean.KernelPotential +open Erdos970Dependency.InvariantDensities Erdos970Dependency.StateKernelInvariance +open Erdos970Dependency.RegenerationMass Erdos970Dependency.RegenerativeResolvent + +theorem paired_invariance : pairedOdd ∘ₘ oddStateMeasure = oddStateMeasure := by + rw [pairedOdd, ← Measure.comp_assoc, odd_state_invariance, even_state_invariance] + +theorem odd_draw_common {s : OddState} (hs : s ∈ pairedRegeneration) : + oddToEven s = oddToEven regenerationState := by + rw [oddToEven, Kernel.comapRight_apply, Kernel.comapRight_apply, + oddKernel_regeneration s hs] + +theorem paired_common {s : OddState} (hs : s ∈ pairedRegeneration) : + pairedOdd s = pairedOdd regenerationState := by + rw [pairedOdd, Kernel.comp_apply, Kernel.comp_apply, odd_draw_common hs] + +theorem killed_common {s : OddState} (hs : s ∈ pairedRegeneration) : + pairedKilled s = pairedKilled regenerationState := by + rw [pairedKilled, Kernel.restrict_apply, Kernel.restrict_apply, paired_common hs] + +theorem odd_source_equation : oddStateMeasure = oddStateMeasure.restrict pairedRegeneration + + pairedKilled ∘ₘ oddStateMeasure := by + rw [pairedKilled, restrict_kernel_comp, paired_invariance] + exact (Measure.restrict_add_restrict_compl pairedRegeneration_measurable).symm + +noncomputable def ratioVisits : Kernel OddState State := + oddToEven.map Sum.inl + pairedOdd.map Sum.inr + +instance ratioVisits_isFiniteKernel : IsFiniteKernel ratioVisits := by unfold ratioVisits; infer_instance + +theorem ratioVisits_common {s : OddState} (hs : s ∈ pairedRegeneration) : + ratioVisits s = ratioVisits regenerationState := by + simp only [ratioVisits, add_apply, Kernel.map_apply _ measurable_inl, Kernel.map_apply _ measurable_inr] + rw [odd_draw_common hs, paired_common hs] + +theorem ratioVisits_invariant_mass : ratioVisits ∘ₘ oddStateMeasure = stateMeasure := by + rw [ratioVisits, Measure.add_comp, ← Measure.map_comp _ _ measurable_inl, + ← Measure.map_comp _ _ measurable_inr, odd_state_invariance, paired_invariance] + rfl + +noncomputable def ratioOccupation : Measure State := + potential ratioVisits pairedKilled regenerationState + +theorem stateMeasure_eq_occupation : stateMeasure = ENNReal.ofReal beta • ratioOccupation := by + have h := post_resolvent ratioVisits pairedKilled oddStateMeasure pairedRegeneration + pairedRegeneration_measurable regenerationState odd_source_equation + paired_survival_le_one paired_survival_tendsto_zero + (fun _ hs ↦ ratioVisits_common hs) (fun _ hs ↦ killed_common hs) + rw [ratioVisits_invariant_mass, oddStateMeasure_regeneration] at h + exact h + +theorem ratioOccupation_eq : ratioOccupation = (ENNReal.ofReal beta)⁻¹ • stateMeasure := by + have h := congrArg (fun mu : Measure State ↦ (ENNReal.ofReal beta)⁻¹ • mu) stateMeasure_eq_occupation + rw [smul_smul, ENNReal.inv_mul_cancel (ne_of_gt (ENNReal.ofReal_pos.mpr beta_pos)) + ENNReal.ofReal_ne_top, one_smul] at h + exact h.symm + +end Erdos970Dependency.RegenerativeOddOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/RetainedOccupationLimit.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RetainedOccupationLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..b1b06e37332ca40de4aa26284ae023885b44c551 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/RetainedOccupationLimit.lean @@ -0,0 +1,296 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceNodeCoordinates +import OAI.NumberTheory.Jacobsthal.Primes.LiteralUniformPrimeTail + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.CompactLogOccupationTest + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped ENNReal Topology +open FinitePathGeometry FinitePathMeasures TransitionKernels CompactInverseTest +open CompactTestGeometry CompactTestMeasurable ActualCouplingUpdates +open CycleResponse AdmissibleCycleTests ArrivalKernelGeometry RegeneratingInverseBands +open NormalizedOccupationLimit EvenStartOccupation + +noncomputable def logTest (H : Side → ℝ×ℝ → ℝ) (x : ℝ×State) : ℝ := + inverseTest H (stateSide x.2) (Real.exp x.1,stateRatio x.2) + +theorem logTest_measurable {H : Side → ℝ×ℝ → ℝ} (hH : ∀ i,Continuous (H i)) : Measurable (logTest H) := by + have hcoord : Measurable (fun x : ℝ×State => (Real.exp x.1,stateRatio x.2)) := + (Real.measurable_exp.comp measurable_fst).prodMk (stateRatio_measurable.comp measurable_snd) + have hside : MeasurableSet {x : ℝ×State | stateSide x.2 = .even} := + measurable_snd (side_set_measurable .even) + have heq : logTest H = (fun x => if stateSide x.2 = .even then inverseTest H .even (Real.exp x.1,stateRatio x.2) + else inverseTest H .odd (Real.exp x.1,stateRatio x.2)) := by + funext x + rcases x with ⟨u,s⟩ + cases s <;> rfl + rw [heq] + exact Measurable.ite hside ((inverseTest_continuous hH .even).measurable.comp hcoord) + ((inverseTest_continuous hH .odd).measurable.comp hcoord) + +theorem logTest_continuous_shift {H : Side → ℝ×ℝ → ℝ} (hH : ∀ i,Continuous (H i)) (s : State) : + Continuous (fun u => logTest H (u,s)) := by + change Continuous (fun u : ℝ => inverseTest H (stateSide s) (Real.exp u,stateRatio s)) + exact (inverseTest_continuous hH (stateSide s)).comp (Real.continuous_exp.prodMk continuous_const) + +theorem logTest_compact_bound {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b : ℝ} (ha : 0 < a) (hb : 0 < b) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) : HasCompactBound (logTest H) := by + obtain ⟨A,hA,hbound⟩ := inverseTest_bounded hH hcompact + let M := |Real.log a|+|Real.log b|+1 + have hM : 0 ≤ M := by dsimp [M]; positivity + refine ⟨A,M,hA,hM,?_,?_⟩ + · intro x + simpa only [logTest,Real.norm_eq_abs] using hbound (stateSide x.2) (Real.exp x.1,stateRatio x.2) + · rintro ⟨u,s⟩ hu + have hcase : u < Real.log a ∨ Real.log b < u := by + by_contra hn + push Not at hn + have hlo := neg_abs_le (Real.log a) + have hup := le_abs_self (Real.log b) + have hle : |u| ≤ M := abs_le.mpr ⟨by dsimp [M]; linarith [abs_nonneg (Real.log b)],by dsimp [M]; linarith [abs_nonneg (Real.log a)]⟩ + exact (not_lt_of_ge hle) hu + have hzero : H (stateSide s) (Real.exp u,stateRatio s) = 0 := by + apply hsupport + rcases hcase with h | h + · exact Or.inl (by simpa only [Real.exp_log ha] using Real.exp_lt_exp.mpr h) + · exact Or.inr (by simpa only [Real.exp_log hb] using Real.exp_lt_exp.mpr h) + simp [logTest,inverseTest,hzero] + +theorem logTest_admissible {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b : ℝ} (ha : 0 < a) (hb : 0 < b) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) : Admissible (logTest H) := + Admissible.base (logTest_measurable hH) (logTest_continuous_shift hH) + (logTest_compact_bound hH hcompact ha hb hsupport) + +noncomputable def arrivalTest (ell : ℝ) (H : Side → ℝ×ℝ → ℝ) : Test := + AdmissibleCycleTests.mask {x | stateRatio x.2 < Real.exp x.1/ell} (logTest H) + +theorem arrivalTest_admissible {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 0 < ell) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) : Admissible (arrivalTest ell H) := + (logTest_admissible hH hcompact ha hb hsupport).arrival ell hell + +theorem logTest_shift_eq (H : Side → ℝ×ℝ → ℝ) (v : ℝ) (z : CostState) : + logTest H (v-z.2,z.1) = continuousTest v (inverseTest H) (.inl z) := rfl + +theorem arrivalTest_shift_eq (H : Side → ℝ×ℝ → ℝ) (v : ℝ) {ell : ℝ} (hell : 0 < ell) (z : CostState) : + arrivalTest ell H (v-z.2,z.1) = + (arrivalSet v ell).indicator (fun y => continuousTest v (inverseTest H) (.inl y)) z := by + classical + rw [arrivalSet_eq_cutoff v hell] + rfl + +theorem source_inverse_log_limit {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 0 < ell) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) : + ∀ ε : ℝ,0 < ε → ∃ V : ℝ,∀ v : ℝ,V ≤ v → ∀ s : EvenState, + (199/100:ℝ) ≤ s.1 → s.1 ≤ 23/10 → + ‖evenResponse (arrivalTest ell H) s v-invariantAverage (arrivalTest ell H)‖ < ε := + source_compact_occupation_limit (arrivalTest_admissible hH hcompact ha hb hell hsupport) + +end NumberTheoryLean.CompactLogOccupationTest + +end + +section + +namespace NumberTheoryLean.ContinuousOccupationIdentification + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures TransitionKernels CompactInverseTest CompactLogOccupationTest +open CycleResponse AdmissibleCycleTests EvenStartOccupation OriginalHarmonicOccupation +open CostPrefixTransport OccupationDecomposition ContinuousCompactHighError +open CompactTestGeometry CompactTestMeasurable FiniteAdmittedOccupation SignedCompletedPowers +open AdmittedHarmonicPaths ArrivalKernelGeometry LowStateHorizon SignedCompactTransfer + +theorem evenResponse_eq_inclusive {F : Test} (hF : Measurable F) (hB : HasCompactBound F) + (s : EvenState) (v : ℝ) : + evenResponse F s v = ∫ y : CostState,F (v-y.2,y.1) ∂inclusiveOccupation (.inl s,0) := by + have hm := shiftedTest_measurable hF v + obtain ⟨C,M,hC,hM,hbound,hsupp⟩ := hB + have hi : Integrable (fun y : CostState => F (v-y.2,y.1)) (Measure.dirac (.inl s,0)) := + bounded_integrable hm (fun y => by simpa only [Real.norm_eq_abs] using hbound (v-y.2,y.1)) + have hf := even_full_test_integrable hF ⟨C,M,hC,hM,hbound,hsupp⟩ s v + rw [inclusiveOccupation,_root_.add_apply,Kernel.id_apply,integral_add_measure hi hf, + integral_dirac' _ _ hm.stronglyMeasurable] + simp only [sub_zero,evenResponse] + +theorem full_admitted_eq_response {H : FinitePathGeometry.Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 0 < ell) + (hsupport : ∀ i : FinitePathGeometry.Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) + (s : EvenState) (v : ℝ) (hstart : (.inl s,0) ∈ arrivalSet v ell) : + (∫ z,inverseReward v H z ∂occupation (admittedTilted v ell) (.inl s,0)) = + evenResponse (arrivalTest ell H) s v := by + have htest := arrivalTest_admissible hH hcompact ha hb hell hsupport + rw [admitted_tilted_occupation v ell (.inl s,0) hstart,← integral_indicator (arrivalSet_measurable v ell)] + have he : (fun y : CostState => arrivalTest ell H (v-y.2,y.1)) = + (arrivalSet v ell).indicator (inverseReward v H) := by + funext y + exact arrivalTest_shift_eq H v hell y + rw [← he] + exact (evenResponse_eq_inclusive htest.measurable htest.compactBound s v).symm + +theorem low_occupation_eq_expectation {H : FinitePathGeometry.Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + (v ell S B : ℝ) (hell : 1 ≤ ell) (hS : 0 < S) (hB : 0 < B) + (z : CostState) (hgap : RegeneratingInverseBands.gapValue v z ≤ (23/10:ℝ)*B) : + (∫ y,inverseReward v H y ∂occupation (lowKernel costKernel v ell S) z) = + continuousExpectation (inverseTest H) v ell S z (sourceHorizon S B) := by + obtain ⟨A,hA,hbound⟩ := inverseTest_bounded hH hcompact + have hG : ∀ y : CostState,|inverseReward v H y| ≤ A := fun y => hbound _ _ + have hm := inverseReward_measurable v hH + rw [low_occupation_integral_eq_source_sum v ell S B hell hS hB z hgap hm hG] + apply Finset.sum_congr rfl + intro n _hn + have he : liftReal (inverseReward v H) = continuousTest v (inverseTest H) := by + funext y + cases y <;> rfl + rw [← he] + exact (continuous_signed_power v ell S n z hm hA hG).symm + +end NumberTheoryLean.ContinuousOccupationIdentification + +end + +section + +namespace NumberTheoryLean.ContinuousLowOccupationLimit + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology +open FinitePathGeometry FinitePathMeasures TransitionKernels CompactInverseTest +open CompactLogOccupationTest SourceLowRemoval ContinuousOccupationIdentification +open ContinuousCompactHighError RegeneratingInverseBands ArrivalKernelGeometry +open OriginalHarmonicOccupation AdmittedHarmonicPaths LowStateHorizon +open SignedCompactTransfer NormalizedOccupationLimit EvenStartOccupation + +theorem source_continuous_low_limit {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 1 ≤ ell) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) : + ∀ ε : ℝ,0 < ε → ∃ B₀ : ℝ,0 < B₀ ∧ ∀ B : ℝ,B₀ ≤ B → ∀ v : ℝ,∀ s : EvenState, + (199/100:ℝ) ≤ s.1 → s.1 ≤ 23/10 → currentExponent v (.inl s,0)=B → + |continuousExpectation (inverseTest H) v ell ((Real.log B)^2) (.inl s,0) + (sourceHorizon ((Real.log B)^2) B)-invariantAverage (arrivalTest ell H)| ≤ ε := by + intro ε hε + obtain ⟨C,hC,hremove⟩ := source_low_removal hH hcompact (K:=b) (fun i r s h => hsupport i r s (Or.inr h)) + obtain ⟨BR,hBR⟩ := eventually_atTop.mp hremove + obtain ⟨V,hV⟩ := source_inverse_log_limit hH hcompact ha hb (show 0 < ell by linarith) hsupport (ε/2) (by linarith) + let B₀ := max BR (max (Real.exp 2) (max (ell+1) (max (Real.exp V) (2*C/ε)))) + have hExpB₀ : Real.exp 2 ≤ B₀ := (le_max_left _ _).trans (le_max_right _ _) + refine ⟨B₀,(Real.exp_pos 2).trans_le hExpB₀,?_⟩ + intro B hB v s hsL hsU hcut + have hBR' : BR ≤ B := (le_max_left _ _).trans hB + have hBexp : Real.exp 2 ≤ B := hExpB₀.trans hB + have hBell : ell+1 ≤ B := + (le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) (le_max_right _ _)).trans hB + have hBV : Real.exp V ≤ B := + (le_trans (le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) (le_max_right _ _)) (le_max_right _ _)).trans hB + have hBC : 2*C/ε ≤ B := + (le_trans (le_trans (le_trans (le_max_right _ _) (le_max_right _ _)) (le_max_right _ _)) (le_max_right _ _)).trans hB + have hBp : 0 < B := (Real.exp_pos 2).trans_le hBexp + have hlogB : 2 ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hBexp + have hS : 0 < (Real.log B)^2 := by nlinarith + have hstart : (.inl s,0) ∈ arrivalSet v ell := by change ell < currentExponent v (.inl s,0); rw [hcut]; linarith + have hv : V ≤ v := by + have he : Real.exp v = B*s.1 := by + change Real.exp (v-0)/s.1=B at hcut + rw [sub_zero] at hcut + exact (div_eq_iff (show s.1 ≠ 0 by linarith [s.2])).mp hcut + apply Real.exp_le_exp.mp + rw [he] + have hBmul : B ≤ B*s.1 := by nlinarith + exact hBV.trans hBmul + have hfull := full_admitted_eq_response hH hcompact ha hb (show 0 < ell by linarith) hsupport s v hstart + have hscale := source_scale_upper hBp s hsU hcut + have hlow := low_occupation_eq_expectation hH hcompact v ell ((Real.log B)^2) B hell hS hBp (.inl s,0) hscale.2 + have hrem := hBR B hBR' v ell s hsL hsU hell (by linarith) hcut + rw [hfull,hlow] at hrem + have hsmall : C/B ≤ ε/2 := by + apply (div_le_iff₀ hBp).mpr + have hh := (div_le_iff₀ hε).mp hBC + nlinarith + have hlimit := hV v hv s hsL hsU + rw [Real.norm_eq_abs] at hlimit + have htri := abs_sub_le + (continuousExpectation (inverseTest H) v ell ((Real.log B)^2) (.inl s,0) (sourceHorizon ((Real.log B)^2) B)) + (evenResponse (arrivalTest ell H) s v) (invariantAverage (arrivalTest ell H)) + rw [abs_sub_comm _ (evenResponse (arrivalTest ell H) s v)] at htri + linarith + +end NumberTheoryLean.ContinuousLowOccupationLimit + +end + +section + +namespace NumberTheoryLean.RetainedOccupationLimit + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open LiteralPrimeOccupation SourceNodeCoordinates CompactInverseTest +open CorrectedCompactTransfer ContinuousLowOccupationLimit CompactLogOccupationTest +open SourceSuccessfulTail SignedCompactTransfer NormalizedOccupationLimit LowStateHorizon UniformBudgetRate + +theorem retained_original_occupation_limit {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {a b ell : ℝ} (ha : 0 < a) (hb : 0 < b) (hell : 1 ≤ ell) + (hsupport : ∀ i : Side,∀ r s : ℝ,r < a ∨ b < r → H i (r,s)=0) + (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |familyValue H w ell ((Real.log B)^2) start-invariantAverage (arrivalTest ell H)| ≤ ε := by + obtain ⟨BC,hBC,hcontinuous⟩ := source_continuous_low_limit hH hcompact ha hb hell hsupport (ε/2) (by linarith) + obtain ⟨wP,hwP,hprime⟩ := source_inverse_compact_transfer H hH hcompact hb.le + (fun i r s h => hsupport i r s (Or.inr h)) d (ε/2) hd (by linarith) + obtain ⟨wScale,hwScale⟩ := eventually_atTop.mp + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + refine ⟨max BC (Real.exp 2),max wP (max normalizationThreshold wScale), + hBC.trans_le (le_max_left _ _),hwP.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBC' : BC ≤ B := (le_max_left _ _).trans hB + have hBpos : 0 < B := hBC.trans_le hBC' + have hBexp : Real.exp 2 ≤ B := (le_max_right _ _).trans hB + have hlogB : 2 ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hBexp + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hscale := source_scale_bound + (hwScale w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw)) hlogB hcomp + obtain ⟨hs,hr,_,hsize⟩ := source_node_bounds hBpos start hi h199 h23 hcons hcut + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + obtain ⟨s,hsv,hcost⟩ := even_source_cost_state hs hi + have hcurrent := source_currentExponent hr hs hcons + rw [hcost,hcut] at hcurrent + have hc := hcontinuous B hBC' (Real.log start.gap) s + (by simpa only [hsv] using h199) (by simpa only [hsv] using h23) hcurrent + have hp := hprime w ((le_max_left _ _).trans hw) ell B start hs hell hBpos hlogB hcomp hr h23 hcons hsize + have hidentity := literal_corrected_occupation hnorm hell (sq_nonneg (Real.log B)) hscale.1 hr hs hsS hBpos hsize H + dsimp only at hp + rw [← hidentity,hcost] at hp + have htri := abs_sub_le (familyValue H w ell ((Real.log B)^2) start) + (continuousExpectation (inverseTest H) (Real.log start.gap) ell ((Real.log B)^2) (.inl s,0) + (sourceHorizon ((Real.log B)^2) B)) (invariantAverage (arrivalTest ell H)) + linarith + +end NumberTheoryLean.RetainedOccupationLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/SourceCycleDuration.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/SourceCycleDuration.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c04af17adcd108c4a4d3f58ca620fd4d9a006ed --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/SourceCycleDuration.lean @@ -0,0 +1,259 @@ +import OAI.NumberTheory.Jacobsthal.Probability.MovingMarkedWindow + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.InitialRegeneration +open NumberTheoryLean.MarkedCycleLaw + +noncomputable def durationHitOrReturn : Kernel OddCost (ℕ × OddCost) := by + classical + exact Kernel.piecewise returnSet_measurable + (Kernel.deterministic (fun z => (0,z)) (measurable_const.prodMk measurable_id)) markedReturnLaw + +instance durationHitOrReturn_isMarkovKernel : IsMarkovKernel durationHitOrReturn := by + unfold durationHitOrReturn + infer_instance + +lemma durationHitOrReturn_forget (z : OddCost) : + (durationHitOrReturn z).map Prod.snd = hitOrReturn z := by + classical + rw [durationHitOrReturn,Kernel.piecewise_apply,hitOrReturn,Kernel.piecewise_apply] + split_ifs + · rw [Kernel.deterministic_apply,Measure.map_dirac' measurable_snd] + rfl + · exact markedReturnLaw_forget z + +abbrev FirstPairWitness := EvenState × OddCost +abbrev SourceCycleWitness := EvenState × (ℕ × OddCost) + +noncomputable def pairWitnessUpdate (x : OddCost × (EvenState × OddState)) : FirstPairWitness := + (x.2.1,pairUpdate x) + +lemma pairWitnessUpdate_measurable : Measurable pairWitnessUpdate := + (measurable_fst.comp measurable_snd).prodMk pairUpdate_measurable + +noncomputable def pairWitnessKernel : Kernel OddCost FirstPairWitness := + (Kernel.id ×ₖ pairedDraws.prodMkRight ℝ).map pairWitnessUpdate + +instance pairWitnessKernel_isMarkovKernel : IsMarkovKernel pairWitnessKernel := + Kernel.IsMarkovKernel.map _ pairWitnessUpdate_measurable + +noncomputable def firstPairProjection (z : FirstPairWitness) : MarkedOddCost := (sourceMark z.1,z.2) + +lemma firstPairProjection_measurable : Measurable firstPairProjection := + (sourceMark_measurable.comp measurable_fst).prodMk measurable_snd + +lemma pairWitness_projection (z : OddCost) : + (pairWitnessKernel z).map firstPairProjection = markedPairKernel z := by + rw [pairWitnessKernel,Kernel.map_apply _ pairWitnessUpdate_measurable, + Measure.map_map firstPairProjection_measurable pairWitnessUpdate_measurable, + markedPairKernel,Kernel.map_apply _ markedPairUpdate_measurable] + rfl + +noncomputable def continueWitnessUpdate (x : FirstPairWitness × (ℕ × OddCost)) : SourceCycleWitness := + (x.1.1,(2+x.2.1,x.2.2)) + +lemma continueWitnessUpdate_measurable : Measurable continueWitnessUpdate := + (measurable_fst.comp measurable_fst).prodMk + ((measurable_const.add (measurable_fst.comp measurable_snd)).prodMk (measurable_snd.comp measurable_snd)) + +noncomputable def witnessContinuation : Kernel FirstPairWitness SourceCycleWitness := + (Kernel.id ×ₖ durationHitOrReturn.prodMkLeft EvenState).map continueWitnessUpdate + +instance witnessContinuation_isMarkovKernel : IsMarkovKernel witnessContinuation := + Kernel.IsMarkovKernel.map _ continueWitnessUpdate_measurable + +lemma witnessContinuation_apply (z : FirstPairWitness) {B : Set SourceCycleWitness} (hB : MeasurableSet B) : + witnessContinuation z B = durationHitOrReturn z.2 {d | (z.1,(2+d.1,d.2)) ∈ B} := by + rw [witnessContinuation,Kernel.map_apply' _ continueWitnessUpdate_measurable _ hB, + Kernel.prod_apply' _ _ _ (continueWitnessUpdate_measurable hB),Kernel.id_apply,lintegral_dirac'] + · rfl + · exact measurable_measure_prodMk_left (continueWitnessUpdate_measurable hB) + +noncomputable def sourceWitnessProjection (x : SourceCycleWitness) : MarkedOddCost := + (sourceMark x.1,x.2.2) + +lemma sourceWitnessProjection_measurable : Measurable sourceWitnessProjection := + (sourceMark_measurable.comp measurable_fst).prodMk (measurable_snd.comp measurable_snd) + +lemma witnessContinuation_projection (z : FirstPairWitness) : + (witnessContinuation z).map sourceWitnessProjection = markContinuation (firstPairProjection z) := by + ext B hB + rw [Measure.map_apply sourceWitnessProjection_measurable hB, + witnessContinuation_apply _ (sourceWitnessProjection_measurable hB),markContinuation_apply _ hB] + have he := congrArg (fun μ : Measure OddCost => μ {y | (sourceMark z.1,y) ∈ B}) + (durationHitOrReturn_forget z.2) + have hm : MeasurableSet {y : OddCost | (sourceMark z.1,y) ∈ B} := + (measurable_const.prodMk measurable_id) hB + rw [Measure.map_apply measurable_snd hm] at he + exact he + +noncomputable def sourceCycleWitnessKernel : Kernel OddCost SourceCycleWitness := + witnessContinuation ∘ₖ pairWitnessKernel + +instance sourceCycleWitnessKernel_isMarkovKernel : IsMarkovKernel sourceCycleWitnessKernel := by + unfold sourceCycleWitnessKernel + infer_instance + +lemma sourceCycleWitness_projection (z : OddCost) : + (sourceCycleWitnessKernel z).map sourceWitnessProjection = completedMarkedKernel z := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF sourceWitnessProjection_measurable,sourceCycleWitnessKernel, + Kernel.lintegral_comp _ _ _ (g := fun x : SourceCycleWitness => F (sourceWitnessProjection x)) + (hF.comp sourceWitnessProjection_measurable)] + have he (x : FirstPairWitness) : (∫⁻ y, F (sourceWitnessProjection y) ∂witnessContinuation x) = + ∫⁻ y, F y ∂markContinuation (firstPairProjection x) := by + rw [← witnessContinuation_projection x,lintegral_map hF sourceWitnessProjection_measurable] + simp_rw [he] + have hJ : Measurable (fun z : MarkedOddCost => ∫⁻ y, F y ∂markContinuation z) := hF.lintegral_kernel + rw [← lintegral_map (g := firstPairProjection) hJ firstPairProjection_measurable, + pairWitness_projection,completedMarkedKernel,Kernel.lintegral_comp _ _ _ hF] + +lemma sourceCycleWitness_duration_ge_two (z : OddCost) : + ∀ᵐ x ∂sourceCycleWitnessKernel z, 2 ≤ x.2.1 := by + rw [sourceCycleWitnessKernel] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_const (measurable_fst.comp measurable_snd)) + apply Eventually.of_forall + intro y + rw [witnessContinuation,Kernel.map_apply _ continueWitnessUpdate_measurable] + apply (ae_map_iff continueWitnessUpdate_measurable.aemeasurable + (measurableSet_le measurable_const (measurable_fst.comp measurable_snd))).mpr + exact Eventually.of_forall (fun x => by change 2 ≤ 2+x.2.1; omega) + +lemma sourceWitness_mark_iff (x : SourceCycleWitness) : + (sourceWitnessProjection x).1 = true ↔ (209/100:ℝ) ≤ x.1.1 ∧ x.1.1 ≤ 213/100 := by + simp [sourceWitnessProjection,sourceMark] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.InitialRegeneration NumberTheoryLean.MarkedCycleLaw + +noncomputable def addPairDuration (z : ℕ × OddCost) : ℕ × OddCost := (2+z.1,z.2) + +lemma addPairDuration_measurable : Measurable addPairDuration := + (measurable_const.add measurable_fst).prodMk measurable_snd + +lemma durationHit_comp_captured : durationHitOrReturn ∘ₖ costCaptured = + costCaptured.map (fun z => (0,z)) := by + classical + let D : Kernel OddCost (ℕ × OddCost) := Kernel.deterministic (fun z => ((0:ℕ),z)) + (measurable_const.prodMk measurable_id) + have hk : durationHitOrReturn ∘ₖ costCaptured = D ∘ₖ costCaptured := by + ext z B hB + rw [Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB] + apply lintegral_congr_ae + have hae : ∀ᵐ y ∂costCaptured z, y ∈ returnSet := by + rw [costCaptured,Kernel.restrict_apply] + exact ae_restrict_mem returnSet_measurable + filter_upwards [hae] with y hy + rw [durationHitOrReturn,Kernel.piecewise_apply,ite_eq_left hy] + rw [hk] + exact Kernel.deterministic_comp_eq_map _ _ + +lemma durationHit_comp_killed : durationHitOrReturn ∘ₖ costKilled = markedReturnLaw ∘ₖ costKilled := by + classical + ext z B hB + rw [Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB] + apply lintegral_congr_ae + have hae : ∀ᵐ y ∂costKilled z, y ∉ returnSet := by + rw [costKilled,Kernel.restrict_apply] + exact ae_restrict_mem returnSet_measurable.compl + filter_upwards [hae] with y hy + rw [durationHitOrReturn,Kernel.piecewise_apply,ite_eq_right hy] + +lemma firstMarkedReturn_succ (n : ℕ) : + firstMarkedReturn (n+1) = ((firstMarkedReturn n) ∘ₖ costKilled).map addPairDuration := by + unfold firstMarkedReturn + rw [← Kernel.map_comp,← Kernel.map_comp_right _ (markReturn_measurable n) addPairDuration_measurable, + firstReturn_succ_comp] + congr 1 + funext z + simp only [Function.comp_def,addPairDuration,markReturn,Prod.mk.injEq,and_true] + omega + +lemma markedReturnLaw_first_step_duration : + markedReturnLaw = firstMarkedReturn 0+(markedReturnLaw ∘ₖ costKilled).map addPairDuration := by + ext z B hB + rw [markedReturnLaw,Kernel.sum_apply' _ _ hB,_root_.add_apply,Measure.add_apply, + Kernel.map_apply' _ addPairDuration_measurable _ hB,Kernel.comp_sum_left, + Kernel.sum_apply' _ _ (addPairDuration_measurable hB),tsum_eq_zero_add' ENNReal.summable] + congr 1 + apply tsum_congr + intro n + rw [firstMarkedReturn_succ,Kernel.map_apply' _ addPairDuration_measurable _ hB] + +lemma duration_forced_first_pair : + (durationHitOrReturn ∘ₖ pairedCostKernel).map addPairDuration = markedReturnLaw := by + rw [← costCaptured_add_costKilled,Kernel.comp_add_right,durationHit_comp_captured,durationHit_comp_killed] + conv_rhs => rw [markedReturnLaw_first_step_duration] + ext z B hB + rw [Kernel.map_apply' _ addPairDuration_measurable _ hB,_root_.add_apply,Measure.add_apply, + _root_.add_apply,Measure.add_apply, + Kernel.map_apply' _ addPairDuration_measurable _ hB] + congr 1 + rw [Kernel.map_apply' _ (f := fun z : OddCost => ((0:ℕ),z)) (measurable_const.prodMk measurable_id) _ (addPairDuration_measurable hB), + firstMarkedReturn,Kernel.map_apply' _ (markReturn_measurable 0) _ hB] + change costCaptured z ((fun y => (0,y)) ⁻¹' addPairDuration ⁻¹' B) = + firstReturn 0 z (markReturn 0 ⁻¹' B) + have hz : firstReturn 0 = costCaptured := Kernel.comp_id _ + rw [hz] + rfl + +lemma pairWitness_forget (z : OddCost) : (pairWitnessKernel z).map Prod.snd = pairedCostKernel z := by + rw [pairWitnessKernel,Kernel.map_apply _ pairWitnessUpdate_measurable, + Measure.map_map measurable_snd pairWitnessUpdate_measurable, + pairedCostKernel,Kernel.map_apply _ pairUpdate_measurable] + rfl + +lemma witnessContinuation_duration (z : FirstPairWitness) : + (witnessContinuation z).map Prod.snd = (durationHitOrReturn z.2).map addPairDuration := by + ext B hB + rw [Measure.map_apply measurable_snd hB,witnessContinuation_apply _ (measurable_snd hB), + Measure.map_apply addPairDuration_measurable hB] + rfl + +theorem sourceCycleWitness_duration_law (z : OddCost) : + (sourceCycleWitnessKernel z).map Prod.snd = markedReturnLaw z := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF measurable_snd,sourceCycleWitnessKernel, + Kernel.lintegral_comp _ _ _ (g := fun x : SourceCycleWitness => F x.2) (hF.comp measurable_snd)] + have he (x : FirstPairWitness) : (∫⁻ y, F y.2 ∂witnessContinuation x) = + ∫⁻ y, F (addPairDuration y) ∂durationHitOrReturn x.2 := by + rw [← lintegral_map (g := Prod.snd) hF measurable_snd,witnessContinuation_duration, + lintegral_map hF addPairDuration_measurable] + simp_rw [he] + have hJ : Measurable (fun z : OddCost => ∫⁻ y, F (addPairDuration y) ∂durationHitOrReturn z) := + (hF.comp addPairDuration_measurable).lintegral_kernel + rw [← lintegral_map (g := Prod.snd) hJ measurable_snd,pairWitness_forget, + ← Kernel.lintegral_comp _ _ _ (g := fun y : ℕ × OddCost => F (addPairDuration y)) + (hF.comp addPairDuration_measurable), + ← lintegral_map (g := addPairDuration) hF addPairDuration_measurable] + have hd := congrArg (fun K : Kernel OddCost (ℕ × OddCost) => K z) duration_forced_first_pair + rw [Kernel.map_apply _ addPairDuration_measurable] at hd + rw [hd] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/SourceSelectedCompactOccupation.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/SourceSelectedCompactOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..14ee8c74cc0c147f98b7584d68e3ac79f3daad6e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/SourceSelectedCompactOccupation.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FullPathCompactSelection + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceSelectedCompactOccupation + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling PersistentFailureFlag +open FiniteHistoryTransport ActualCoupledHistories FullPathCompactSelection +open PrimeCompactWeights PrimeCorrectionFactor PrimeBinMembership + +noncomputable def fullSourceLaw (w ell S : ℝ) (start : Node) + (hs : Valid start.side start.ratio) (mesh : ℝ) (N : ℕ) : + Measure (Hist (FlagState (JointState w ell S start)) N) := + pathKernel (marked (CouplingData.joint w ell S start (Real.log start.gap) mesh) + (ActualFlagInvariant.mismatch_measurable mesh)) N + (fun _ => (FlaggedSourceStart.sourceJoint w ell S start hs,false)) + +theorem fullSourceLaw_eq {w ell S : ℝ} {start : Node} + (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) (mesh : ℝ) (N : ℕ) : + fullSourceLaw w ell S start hs mesh N = sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N := rfl + +theorem source_selected_compact (R : ℝ) (hR : 3 ≤ R) (d : ℝ) (_hd : 0 < d) : + ∃ C w₀ : ℝ, 0 < C ∧ 1 < w₀ ∧ ∀ w : ℝ, w₀ ≤ w → ∀ ell B : ℝ, + ∀ start : Node, ∀ hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + ∀ mesh : ℝ, ∀ N : ℕ, ∀ A : Set (Hist (FlagState (JointState w ell S start)) N), + MeasurableSet A → + (∫⁻ h, A.indicator (fullCompactReward R w B start N) h + ∂fullSourceLaw w ell S start hs mesh N) ≤ + ENNReal.ofReal C * fullSourceLaw w ell S start hs mesh N A := by + have hD := compactConstant_pos hR + have hevent := ((correctionBudget_tendsto_zero d).eventually + (eventually_le_nhds (by norm_num : (0:ℝ) < 1))).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + obtain ⟨W,hW⟩ := eventually_atTop.mp hevent + refine ⟨compactConstant R*(R+1),max normalizationThreshold W,by positivity, + normalizationThreshold_gt_one.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hellB hB hlogB hcomp hi h199 h23 hc hcut + dsimp only + intro mesh N A hA + have hnorm : normalizationThreshold ≤ w := (le_max_left _ _).trans hw + have hwe := hW w ((le_max_right _ _).trans hw) + have hscale := UniformBudgetRate.source_scale_bound hwe.2 hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have he : start.gap = B*start.ratio := by + have hh : start.cutoff = start.gap/start.ratio := hc + rw [hcut] at hh + exact ((eq_div_iff (valid_pos hs).ne').mp hh).symm + have hr : 0 < start.gap := by rw [he]; exact mul_pos hB (valid_pos hs) + have hbound := scaled_compact_bound hR hB hell hellB hlogB hcomp hwe.1 hi h199 h23 hc hcut + rw [fullSourceLaw_eq hnorm hell hS0 hscale.1 hr hs hsS] + exact selected_compact_history_bound hnorm hell hS0 hscale.1 hr hs hsS + (by linarith) hD.le hbound mesh N hA + +end NumberTheoryLean.SourceSelectedCompactOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/UniformCycleMoments.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/UniformCycleMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..821662c1307df42f40e480ea1203bdaaea76aa93 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/UniformCycleMoments.lean @@ -0,0 +1,1112 @@ +import Mathlib.MeasureTheory.Group.Integral +import Mathlib.MeasureTheory.Group.Prod +import Mathlib.MeasureTheory.Integral.Bochner.SumMeasure +import Mathlib.Probability.Kernel.Composition.IntegralCompProd +import Mathlib.Probability.Moments.IntegrableExpMul +import OAI.NumberTheory.Jacobsthal.Renewal.OccupationAge + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.OccupationBoundaries + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures KernelDensityBridge +open PairedCostProcess CostReturnLaw CycleOccupation MinorizingCostRegularity + + theorem stateRatio_pos (s : State) : 0 < stateRatio s := by + cases s with + | inl s => change 0 < s.1; linarith [s.2] + | inr s => change 0 < s.1; linarith [s.2] + +theorem stateKernel_ratio_null (s : State) {B : Set ℝ} (hB : MeasurableSet B) + (hnull : volume B = 0) : stateKernel s (stateRatio ⁻¹' B) = 0 := by + rw [← Measure.map_apply stateRatio_measurable hB] + cases s with + | inl s => rw [stateKernel_even_ratio, evenKernel_apply, Measure.restrict_eq_zero.mpr hnull, lintegral_zero_measure] + | inr s => rw [stateKernel_odd_ratio, oddKernel_apply, Measure.restrict_eq_zero.mpr hnull, lintegral_zero_measure] + +theorem costKernel_level_null (h : ℝ → ℝ) (hh : Measurable h) + (hinj : Set.InjOn (fun t => cost t + h t) (Ioi 0)) (z : CostState) (c : ℝ) : + costKernel z {y | y.2 + h (stateRatio y.1) = c} = 0 := by + have hA : MeasurableSet {t : ℝ | 0 < t ∧ z.2 + cost t + h t = c} := + measurableSet_Ioi.inter (measurableSet_eq_fun ((measurable_const.add cost_measurable).add hh) measurable_const) + have hnull : volume {t : ℝ | 0 < t ∧ z.2 + cost t + h t = c} = 0 := by + apply Set.Subsingleton.measure_zero + intro t ht u hu + exact hinj ht.1 hu.1 (by linarith [ht.2, hu.2]) + have hB : MeasurableSet {y : CostState | y.2 + h (stateRatio y.1) = c} := + measurableSet_eq_fun (measurable_snd.add (hh.comp (stateRatio_measurable.comp measurable_fst))) measurable_const + rw [costKernel_apply z hB] + convert! stateKernel_ratio_null z.1 hA hnull using 2 + ext s + simp only [mem_ofPred_eq, mem_preimage, stateRatio_pos s, true_and] + +theorem occupation_null_of_transition_null {B : Set CostState} (hB : MeasurableSet B) + (hnull : ∀ z : CostState, costKernel z B = 0) : occupationMeasure B = 0 := by + have hp : ∀ z : OddCost, pairVisits z B = 0 := by + intro z + rw [pairVisits_full_steps, Measure.add_apply, hnull] + have heq : costKernel ^ 2 = costKernel ∘ₖ costKernel := by rw [pow_two]; rfl + rw [heq, Kernel.comp_apply' _ _ _ hB] + simp only [hnull, lintegral_zero, add_zero] + rw [occupationMeasure, occupationKernel, Kernel.sum_apply' _ _ hB] + have hv : ∀ n, visitBlock n (RegenerationTails.regenerationState, 0) B = 0 := by + intro n + rw [visitBlock, Kernel.comp_apply' _ _ _ hB] + simp only [hp, lintegral_zero] + simp only [hv, tsum_zero] + +theorem occupation_level_null (h : ℝ → ℝ) (hh : Measurable h) + (hinj : Set.InjOn (fun t => cost t + h t) (Ioi 0)) (c : ℝ) : + occupationMeasure {y | y.2 + h (stateRatio y.1) = c} = 0 := by + apply occupation_null_of_transition_null + (measurableSet_eq_fun (measurable_snd.add (hh.comp (stateRatio_measurable.comp measurable_fst))) measurable_const) + exact fun z => costKernel_level_null h hh hinj z c + +theorem occupation_age_level_null (c : ℝ) : occupationMeasure {y | y.2 = c} = 0 := by + have hinj : Set.InjOn (fun t => cost t + (0 : ℝ)) (Ioi 0) := by + simpa only [add_zero] using cost_strictAntiOn.injOn + simpa only [add_zero] using occupation_level_null (fun _ => 0) measurable_const hinj c + +theorem cost_add_log {t : ℝ} (ht : 0 < t) : cost t + Real.log t = Real.log (t + 1) := by + rw [cost, ← Real.log_mul (by positivity : (1 + 1 / t : ℝ) ≠ 0) ht.ne'] + congr 1 + field_simp + +theorem occupation_age_log_ratio_level_null (c : ℝ) : + occupationMeasure {y | y.2 + Real.log (stateRatio y.1) = c} = 0 := by + apply occupation_level_null _ Real.measurable_log + intro t ht u hu htu + change 0 < t at ht + change 0 < u at hu + change cost t + Real.log t = cost u + Real.log u at htu + rw [cost_add_log ht, cost_add_log hu] at htu + have : t + 1 = u + 1 := (Real.log_injOn_pos (by change 0 < t + 1; linarith) (by change 0 < u + 1; linarith) htu) + linarith + +theorem occupation_arrival_boundary_null {ell : ℝ} (hell : 0 < ell) (v : ℝ) : + occupationMeasure {y | stateRatio y.1 = Real.exp (v - y.2) / ell} = 0 := by + apply measure_mono_null (t := {y | y.2 + Real.log (stateRatio y.1) = v - Real.log ell}) + · intro y hy + have hs := stateRatio_pos y.1 + have h := congrArg Real.log ((eq_div_iff hell.ne').mp hy) + rw [Real.log_mul hs.ne' hell.ne', Real.log_exp] at h + change y.2 + Real.log (stateRatio y.1) = v - Real.log ell + linarith + · exact occupation_age_log_ratio_level_null _ + +end NumberTheoryLean.OccupationBoundaries + + + +namespace NumberTheoryLean.CycleConvolutionLaw + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open PairedCostProcess CostReturnLaw CycleRegeneration CycleRenewalInputs +open AbsorptionCutoff.Renewal + +instance returnLaw_pow_isMarkovKernel (n : ℕ) : IsMarkovKernel (returnLaw ^ n) := by + induction n with + | zero => change IsMarkovKernel (Kernel.id : Kernel OddCost OddCost); infer_instance + | succ n ih => + rw [pow_succ'] + change IsMarkovKernel (returnLaw ∘ₖ (returnLaw ^ n)) + infer_instance + +theorem cumulative_cost_lintegral (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) + {H : ℝ → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y.2 ∂(returnLaw ^ n) z) = ∫⁻ G, H (z.2 + G) ∂convPow cycleCostLaw n := by + induction n generalizing z with + | zero => + change (∫⁻ y, H y.2 ∂Measure.dirac z) = _ + rw [lintegral_dirac' z (f := fun y : OddCost => H y.2) (hH.comp measurable_snd), convPow_zero, + lintegral_dirac' 0 (f := fun G : ℝ => H (z.2 + G)) (hH.comp (measurable_const.add measurable_id)), add_zero] + | succ n ih => + have hp : returnLaw ^ (n + 1) = (returnLaw ^ n) ∘ₖ returnLaw := pow_succ returnLaw n + rw [hp, Kernel.lintegral_comp _ _ _ (g := fun y : OddCost => H y.2) (hH.comp measurable_snd)] + let F : ℝ → ℝ≥0∞ := fun t => ∫⁻ G, H (z.2 + t + G) ∂convPow cycleCostLaw n + have hF : Measurable F := (hH.comp ((measurable_const.add measurable_fst).add measurable_snd)).lintegral_prod_right' + calc + _ = ∫⁻ y, F (y.2 - z.2) ∂returnLaw z := by + apply lintegral_congr_ae + filter_upwards [returnLaw_ae_regeneration z] with y hy + rw [ih y hy] + apply lintegral_congr + intro G + congr 1 + ring + _ = ∫⁻ t, F t ∂cycleCostLaw := cycle_increment_integral z hz hF + _ = _ := by + rw [convPow_succ', Measure.lintegral_conv (f := fun G : ℝ => H (z.2 + G)) + (hH.comp (measurable_const.add measurable_id))] + apply lintegral_congr + intro t + apply lintegral_congr + intro G + congr 1 + ring + +theorem cumulative_cost_law (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + ((returnLaw ^ n) z).map (fun y => y.2 - z.2) = convPow cycleCostLaw n := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map (g := fun y : OddCost => y.2 - z.2) hH (measurable_snd.sub measurable_const), + cumulative_cost_lintegral n z hz (H := fun G : ℝ => H (G - z.2)) + (hH.comp (measurable_id.sub measurable_const))] + apply lintegral_congr + intro G + rw [add_sub_cancel_left] + +noncomputable def actualArrivalLaw (n : ℕ) : Measure ℝ := + ((returnLaw ^ n) (RegenerationTails.regenerationState, 0)).map Prod.snd + +theorem actualArrivalLaw_eq_convPow (n : ℕ) : actualArrivalLaw n = convPow cycleCostLaw n := by + have hz : (RegenerationTails.regenerationState, (0 : ℝ)) ∈ returnSet := by + change (1 : ℝ) ≤ 3 + norm_num + have h := cumulative_cost_law n (RegenerationTails.regenerationState, 0) hz + simp only [sub_zero] at h + convert! h using 1 + +theorem actualArrival_sum_eq_renewal : Measure.sum actualArrivalLaw = renewalMeasure cycleCostLaw := by + unfold renewalMeasure + apply congrArg Measure.sum + funext n + exact actualArrivalLaw_eq_convPow n + +theorem actual_cycle_key_renewal {H : ℝ → ℝ} (hH : Continuous H) + (hDRI : driNorm (fun x => ‖H x‖ₑ) ≠ ∞) : + Tendsto (fun y : ℝ => ∑' n : ℕ, ∫ s, H (y - s) ∂actualArrivalLaw n) + atTop (𝓝 ((∫ x : ℝ, H x) / (∫ G : ℝ, G ∂cycleCostLaw))) := by + simp_rw [actualArrivalLaw_eq_convPow] + exact cycle_key_renewal hH hDRI + +end NumberTheoryLean.CycleConvolutionLaw + + + +namespace NumberTheoryLean.CycleResponse + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathMeasures CycleOccupation +open AbsorptionCutoff.Renewal + +abbrev Test := ℝ × State → ℝ + +noncomputable def response (F : Test) (v : ℝ) : ℝ := + ∫ y : CostState, F (v - y.2, y.1) ∂occupationMeasure + +theorem shiftedTest_measurable {F : Test} (hF : Measurable F) (v : ℝ) : + Measurable (fun y : CostState => F (v - y.2, y.1)) := + hF.comp ((measurable_const.sub measurable_snd).prodMk measurable_fst) + +theorem shiftedTest_integrable {F : Test} (hF : Measurable F) {C : ℝ} + (hbound : ∀ x, ‖F x‖ ≤ C) (v : ℝ) : + Integrable (fun y : CostState => F (v - y.2, y.1)) occupationMeasure := + ⟨(shiftedTest_measurable hF v).aestronglyMeasurable, + HasFiniteIntegral.of_bounded (Eventually.of_forall fun _ => hbound _)⟩ + +theorem response_bound {F : Test} {C : ℝ} (hbound : ∀ x, ‖F x‖ ≤ C) (v : ℝ) : + ‖response F v‖ ≤ C * occupationMeasure.real univ := + norm_integral_le_of_norm_le_const (Eventually.of_forall fun _ => hbound _) + +theorem response_zero_left {F : Test} {a v : ℝ} + (hsupp : ∀ x, x.1 < a → F x = 0) (hv : v < a) : response F v = 0 := by + apply integral_eq_zero_of_ae + filter_upwards [occupation_age_nonneg] with y hy + exact hsupp _ (by linarith) + +theorem occupation_age_all_moments (n : ℕ) : + Integrable (fun y : CostState => y.2 ^ n) occupationMeasure := by + obtain ⟨η, hη, hp⟩ := occupation_exponential_integrable + have hn : Integrable (fun y : CostState => Real.exp (-η * y.2)) occupationMeasure := by + refine (integrable_const (1 : ℝ)).mono' + (Real.measurable_exp.comp (measurable_const.mul measurable_snd)).aestronglyMeasurable ?_ + filter_upwards [occupation_age_nonneg] with y hy + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_one_iff.mpr (by nlinarith) + exact integrable_pow_of_integrable_exp_mul (X := Prod.snd) hη.ne' hp hn n + +theorem response_continuous_of_ae {F : Test} (hF : Measurable F) {C : ℝ} + (hbound : ∀ x, ‖F x‖ ≤ C) + (hcont : ∀ v, ∀ᵐ y ∂occupationMeasure, ContinuousAt (fun u => F (u - y.2, y.1)) v) : + Continuous (response F) := by + apply continuous_iff_continuousAt.mpr + intro v + exact tendsto_integral_filter_of_dominated_convergence (fun _ => C) + (Eventually.of_forall fun u => (shiftedTest_measurable hF u).aestronglyMeasurable) + (Eventually.of_forall fun u => Eventually.of_forall fun y => hbound _) + (integrable_const C) (hcont v) + +theorem response_reciprocal_square_bound {F : Test} {C M : ℝ} + (hC : 0 ≤ C) (hM : 0 ≤ M) (hbound : ∀ x, ‖F x‖ ≤ C) + (hsupp : ∀ x, M < |x.1| → F x = 0) : + ∃ K : ℝ, 0 ≤ K ∧ ∀ v : ℝ, ‖response F v‖ ≤ K * (1 + v ^ 2)⁻¹ := by + let Q : CostState → ℝ := fun y => C * (1 + 2 * y.2 ^ 2 + 2 * M ^ 2) + have hQi : Integrable Q occupationMeasure := + (((integrable_const (1 : ℝ)).add ((occupation_age_all_moments 2).const_mul 2)).add + (integrable_const (2 * M ^ 2))).const_mul C + have hQpos : ∀ y, 0 ≤ Q y := fun y => mul_nonneg hC (by positivity) + refine ⟨∫ y, Q y ∂occupationMeasure, integral_nonneg hQpos, ?_⟩ + intro v + have he : (1 + v ^ 2) * ‖response F v‖ ≤ ∫ y, Q y ∂occupationMeasure := by + have hh : ∀ y : CostState, ‖(1 + v ^ 2) * F (v - y.2, y.1)‖ ≤ Q y := by + intro y + by_cases hy : M < |v - y.2| + · rw [hsupp _ hy, mul_zero, norm_zero] + exact hQpos y + · have hu : |v - y.2| ≤ M := le_of_not_gt hy + have hu2 : (v - y.2) ^ 2 ≤ M ^ 2 := by + nlinarith [sq_le_sq₀ (abs_nonneg (v - y.2)) hM |>.mpr hu, sq_abs (v - y.2)] + have hv2 : v ^ 2 ≤ 2 * y.2 ^ 2 + 2 * M ^ 2 := by nlinarith [sq_nonneg (v - 2 * y.2)] + rw [norm_mul, Real.norm_eq_abs, abs_of_pos (by positivity : 0 < 1 + v ^ 2)] + exact le_trans (mul_le_mul_of_nonneg_left (hbound _) (by positivity)) + (by dsimp [Q]; nlinarith [mul_le_mul_of_nonneg_right hv2 hC]) + have hi := norm_integral_le_of_norm_le hQi (Eventually.of_forall hh) + rw [integral_const_mul, norm_mul, Real.norm_eq_abs, + abs_of_pos (by positivity : 0 < 1 + v ^ 2)] at hi + exact hi + rw [← div_eq_mul_inv] + exact (le_div_iff₀ (by positivity : 0 < 1 + v ^ 2)).mpr (by linarith) + +theorem driNorm_le_of_reciprocal_square {H : ℝ → ℝ} {K : ℝ} (hK : 0 ≤ K) + (hbound : ∀ v, ‖H v‖ ≤ K * (1 + v ^ 2)⁻¹) : driNorm (fun v => ‖H v‖ₑ) < ∞ := by + let p : ℝ → ℝ≥0∞ := fun v => ENNReal.ofReal ((1 + v ^ 2)⁻¹) + have hcell : ∀ k : ℤ, cellSup (fun v => ‖H v‖ₑ) k ≤ ENNReal.ofReal K * cellSup p k := by + intro k + apply iSup₂_le + intro v hv + calc + _ = ENNReal.ofReal ‖H v‖ := (ofReal_norm _).symm + _ ≤ ENNReal.ofReal (K * (1 + v ^ 2)⁻¹) := ENNReal.ofReal_le_ofReal (hbound v) + _ = ENNReal.ofReal K * p v := ENNReal.ofReal_mul hK + _ ≤ _ := mul_le_mul le_rfl (le_cellSup hv) zero_le zero_le + calc + _ ≤ ∑' k : ℤ, ENNReal.ofReal K * cellSup p k := ENNReal.tsum_le_tsum hcell + _ = ENNReal.ofReal K * driNorm p := by rw [ENNReal.tsum_mul_left]; rfl + _ < ∞ := ENNReal.mul_lt_top ENNReal.ofReal_lt_top (lt_top_iff_ne_top.mpr driNorm_ofReal_inv_one_add_sq_ne_top) + +theorem response_driNorm {F : Test} {C M : ℝ} + (hC : 0 ≤ C) (hM : 0 ≤ M) (hbound : ∀ x, ‖F x‖ ≤ C) + (hsupp : ∀ x, M < |x.1| → F x = 0) : driNorm (fun v => ‖response F v‖ₑ) ≠ ∞ := by + obtain ⟨K, hK, hb⟩ := response_reciprocal_square_bound hC hM hbound hsupp + exact (driNorm_le_of_reciprocal_square hK hb).ne + +end NumberTheoryLean.CycleResponse + + + +namespace NumberTheoryLean.AdmissibleCycleTests + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathMeasures CycleOccupation OccupationBoundaries CycleResponse + +noncomputable def mask (B : Set (ℝ × State)) (F : Test) : Test := B.indicator F + +def HasCompactBound (F : Test) : Prop := ∃ C M : ℝ, 0 ≤ C ∧ 0 ≤ M ∧ + (∀ x, ‖F x‖ ≤ C) ∧ (∀ x, M < |x.1| → F x = 0) + +def ShiftContinuous (F : Test) : Prop := + ∀ v : ℝ, ∀ᵐ y ∂occupationMeasure, ContinuousAt (fun u => F (u - y.2, y.1)) v + +theorem HasCompactBound.mask {F : Test} (hF : HasCompactBound F) (B : Set (ℝ × State)) : + HasCompactBound (mask B F) := by + classical + obtain ⟨C, M, hC, hM, hb, hs⟩ := hF + refine ⟨C, M, hC, hM, ?_, ?_⟩ + · intro x + by_cases hx : x ∈ B + · simpa [AdmissibleCycleTests.mask, hx] using hb x + · simpa [AdmissibleCycleTests.mask, hx] using hC + · intro x hx + by_cases h : x ∈ B <;> simp [AdmissibleCycleTests.mask, h, hs x hx] + +theorem HasCompactBound.add {F G : Test} (hF : HasCompactBound F) (hG : HasCompactBound G) : + HasCompactBound (fun x => F x + G x) := by + obtain ⟨C, M, hC, hM, hb, hs⟩ := hF + obtain ⟨D, N, hD, hN, hb', hs'⟩ := hG + refine ⟨C + D, max M N, add_nonneg hC hD, le_trans hM (le_max_left _ _), ?_, ?_⟩ + · intro x + exact le_trans (norm_add_le _ _) (add_le_add (hb x) (hb' x)) + · intro x hx + change F x + G x = 0 + rw [hs x (lt_of_le_of_lt (le_max_left _ _) hx), hs' x (lt_of_le_of_lt (le_max_right _ _) hx), add_zero] + +theorem HasCompactBound.scale {F : Test} (hF : HasCompactBound F) (c : ℝ) : + HasCompactBound (fun x => c * F x) := by + obtain ⟨C, M, hC, hM, hb, hs⟩ := hF + refine ⟨‖c‖ * C, M, mul_nonneg (norm_nonneg _) hC, hM, ?_, ?_⟩ + · intro x + rw [norm_mul] + exact mul_le_mul_of_nonneg_left (hb x) (norm_nonneg _) + · intro x hx + change c * F x = 0 + rw [hs x hx, mul_zero] + +theorem continuousAt_cut_lt {f q r : ℝ → ℝ} {v : ℝ} + (hf : ContinuousAt f v) (hq : Continuous q) (hr : Continuous r) (hne : q v ≠ r v) : + ContinuousAt (fun u => if q u < r u then f u else 0) v := by + obtain h | h := lt_or_gt_of_ne hne + · apply hf.congr + filter_upwards [(isOpen_lt hq hr).mem_nhds h] with u hu + simp [hu] + · apply (continuousAt_const : ContinuousAt (fun _ : ℝ => (0 : ℝ)) v).congr + filter_upwards [(isOpen_lt hr hq).mem_nhds h] with u hu + simp [not_lt_of_ge hu.le] + +theorem continuousAt_cut_le {f q r : ℝ → ℝ} {v : ℝ} + (hf : ContinuousAt f v) (hq : Continuous q) (hr : Continuous r) (hne : q v ≠ r v) : + ContinuousAt (fun u => if q u ≤ r u then f u else 0) v := by + obtain h | h := lt_or_gt_of_ne hne + · apply hf.congr + filter_upwards [(isOpen_lt hq hr).mem_nhds h] with u hu + simp [hu.le] + · apply (continuousAt_const : ContinuousAt (fun _ : ℝ => (0 : ℝ)) v).congr + filter_upwards [(isOpen_lt hr hq).mem_nhds h] with u hu + simp [not_le_of_gt hu] + +theorem ShiftContinuous.upper {F : Test} (hF : ShiftContinuous F) (a : ℝ) : + ShiftContinuous (mask {x | x.1 ≤ a} F) := by + intro v + have hn : ∀ᵐ y ∂occupationMeasure, y.2 ≠ v - a := by + simpa only [ae_iff, not_not] using occupation_age_level_null (v - a) + filter_upwards [hF v, hn] with y hy hn + have hne : v - y.2 ≠ a := by intro h; apply hn; linarith + exact continuousAt_cut_le hy (continuous_id.sub continuous_const) continuous_const hne + +theorem ShiftContinuous.upperOpen {F : Test} (hF : ShiftContinuous F) (a : ℝ) : + ShiftContinuous (mask {x | x.1 < a} F) := by + intro v + have hn : ∀ᵐ y ∂occupationMeasure, y.2 ≠ v - a := by + simpa only [ae_iff, not_not] using occupation_age_level_null (v - a) + filter_upwards [hF v, hn] with y hy hn + have hne : v - y.2 ≠ a := by intro h; apply hn; linarith + exact continuousAt_cut_lt hy (continuous_id.sub continuous_const) continuous_const hne + +theorem ShiftContinuous.state {F : Test} (hF : ShiftContinuous F) (B : Set State) : + ShiftContinuous (mask (Prod.snd ⁻¹' B) F) := by + classical + intro v + filter_upwards [hF v] with y hy + by_cases h : y.1 ∈ B + · have heq : (fun u => mask (Prod.snd ⁻¹' B) F (u - y.2, y.1)) = fun u => F (u - y.2, y.1) := by + funext u + simp [AdmissibleCycleTests.mask, h] + rw [heq] + exact hy + · have heq : (fun u => mask (Prod.snd ⁻¹' B) F (u - y.2, y.1)) = fun _ => 0 := by + funext u + simp [AdmissibleCycleTests.mask, h] + rw [heq] + exact continuousAt_const + +theorem ShiftContinuous.arrival {F : Test} (hF : ShiftContinuous F) {ell : ℝ} (hell : 0 < ell) : + ShiftContinuous (mask {x | stateRatio x.2 < Real.exp x.1 / ell} F) := by + intro v + have hn : ∀ᵐ y ∂occupationMeasure, stateRatio y.1 ≠ Real.exp (v - y.2) / ell := by + simpa only [ae_iff, not_not] using occupation_arrival_boundary_null hell v + filter_upwards [hF v, hn] with y hy hn + change ContinuousAt (fun u => if stateRatio y.1 < Real.exp (u - y.2) / ell then F (u - y.2, y.1) else 0) v + exact continuousAt_cut_lt hy continuous_const + ((Real.continuous_exp.comp (continuous_id.sub continuous_const)).div_const ell) hn + +inductive Admissible : Test → Prop + | base {F : Test} (hF : Measurable F) (hc : ∀ s : State, Continuous (fun u => F (u, s))) + (hb : HasCompactBound F) : Admissible F + | upper {F : Test} (hF : Admissible F) (a : ℝ) : Admissible (mask {x | x.1 ≤ a} F) + | upperOpen {F : Test} (hF : Admissible F) (a : ℝ) : Admissible (mask {x | x.1 < a} F) + | state {F : Test} (hF : Admissible F) (B : Set State) (hB : MeasurableSet B) : + Admissible (mask (Prod.snd ⁻¹' B) F) + | arrival {F : Test} (hF : Admissible F) (ell : ℝ) (hell : 0 < ell) : + Admissible (mask {x | stateRatio x.2 < Real.exp x.1 / ell} F) + | add {F G : Test} (hF : Admissible F) (hG : Admissible G) : Admissible (fun x => F x + G x) + | scale {F : Test} (hF : Admissible F) (c : ℝ) : Admissible (fun x => c * F x) + +theorem Admissible.lower {F : Test} (hF : Admissible F) (a : ℝ) : + Admissible (mask {x | a ≤ x.1} F) := by + classical + convert hF.add ((hF.upperOpen a).scale (-1)) using 1 + funext x + by_cases h : x.1 < a + · simp [mask, h, not_le_of_gt h] + · simp [mask, h, le_of_not_gt h] + +theorem Admissible.lowerOpen {F : Test} (hF : Admissible F) (a : ℝ) : + Admissible (mask {x | a < x.1} F) := by + classical + convert hF.add ((hF.upper a).scale (-1)) using 1 + funext x + by_cases h : x.1 ≤ a + · simp [mask, h, not_lt_of_ge h] + · simp [mask, h, lt_of_not_ge h] + +theorem Admissible.intervalIcc {F : Test} (hF : Admissible F) (a b : ℝ) : + Admissible (mask {x | x.1 ∈ Icc a b} F) := by + classical + convert (hF.lower a).upper b using 1 + funext x + by_cases ha : a ≤ x.1 <;> by_cases hb : x.1 ≤ b <;> simp [mask, ha, hb] + +theorem Admissible.intervalIco {F : Test} (hF : Admissible F) (a b : ℝ) : + Admissible (mask {x | x.1 ∈ Ico a b} F) := by + classical + convert (hF.lower a).upperOpen b using 1 + funext x + by_cases ha : a ≤ x.1 <;> by_cases hb : x.1 < b <;> simp [mask, ha, hb] + +theorem Admissible.intervalIoc {F : Test} (hF : Admissible F) (a b : ℝ) : + Admissible (mask {x | x.1 ∈ Ioc a b} F) := by + classical + convert (hF.lowerOpen a).upper b using 1 + funext x + by_cases ha : a < x.1 <;> by_cases hb : x.1 ≤ b <;> simp [mask, ha, hb] + +theorem Admissible.intervalIoo {F : Test} (hF : Admissible F) (a b : ℝ) : + Admissible (mask {x | x.1 ∈ Ioo a b} F) := by + classical + convert (hF.lowerOpen a).upperOpen b using 1 + funext x + by_cases ha : a < x.1 <;> by_cases hb : x.1 < b <;> simp [mask, ha, hb] + +theorem Admissible.measurable {F : Test} (hF : Admissible F) : Measurable F := by + induction hF with + | base hf _ _ => exact hf + | upper _ a ih => exact ih.indicator (measurableSet_le measurable_fst measurable_const) + | upperOpen _ a ih => exact ih.indicator (measurableSet_lt measurable_fst measurable_const) + | state _ B hB ih => exact ih.indicator (measurable_snd hB) + | arrival _ ell _ ih => + exact ih.indicator (measurableSet_lt (stateRatio_measurable.comp measurable_snd) + ((Real.measurable_exp.comp measurable_fst).div_const ell)) + | add _ _ ihF ihG => exact ihF.add ihG + | scale _ c ih => exact measurable_const.mul ih + +theorem Admissible.compactBound {F : Test} (hF : Admissible F) : HasCompactBound F := by + induction hF with + | base _ _ hb => exact hb + | upper _ _ ih => exact ih.mask _ + | upperOpen _ _ ih => exact ih.mask _ + | state _ _ _ ih => exact ih.mask _ + | arrival _ _ _ ih => exact ih.mask _ + | add _ _ ihF ihG => exact ihF.add ihG + | scale _ c ih => exact ih.scale c + +theorem Admissible.shiftContinuous {F : Test} (hF : Admissible F) : ShiftContinuous F := by + induction hF with + | base _ hc _ => + intro v + exact Eventually.of_forall fun y => ((hc y.1).comp (continuous_id.sub continuous_const)).continuousAt + | upper _ a ih => exact ih.upper a + | upperOpen _ a ih => exact ih.upperOpen a + | state _ B _ ih => exact ih.state B + | arrival _ _ hell ih => exact ih.arrival hell + | add _ _ ihF ihG => + intro v + filter_upwards [ihF v, ihG v] with y hyF hyG + exact hyF.add hyG + | scale _ c ih => + intro v + filter_upwards [ih v] with y hy + exact continuousAt_const.mul hy + +theorem Admissible.response_continuous {F : Test} (hF : Admissible F) : Continuous (response F) := by + obtain ⟨C, M, hC, hM, hb, hs⟩ := hF.compactBound + exact response_continuous_of_ae hF.measurable hb hF.shiftContinuous + +theorem Admissible.response_driNorm {F : Test} (hF : Admissible F) : + AbsorptionCutoff.Renewal.driNorm (fun v => ‖response F v‖ₑ) ≠ ∞ := by + obtain ⟨C, M, hC, hM, hb, hs⟩ := hF.compactBound + exact CycleResponse.response_driNorm hC hM hb hs + +theorem admissible_cycle_response_renewal {F : Test} (hF : Admissible F) : + Tendsto (fun v : ℝ => ∑' n : ℕ, ∫ s, response F (v - s) ∂CycleConvolutionLaw.actualArrivalLaw n) + atTop (𝓝 ((∫ u : ℝ, response F u) / (∫ G : ℝ, G ∂CostReturnLaw.cycleCostLaw))) := + CycleConvolutionLaw.actual_cycle_key_renewal hF.response_continuous hF.response_driNorm + +end NumberTheoryLean.AdmissibleCycleTests + + + +namespace NumberTheoryLean.OccupationDecomposition + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathMeasures PairedCostProcess PairedCostGrouping +open CostReturnLaw CycleOccupation KernelPotential + +noncomputable def pairedOccupation : Kernel OddCost CostState := potential pairVisits pairedCostKernel + +instance pairedOccupation_isSFiniteKernel : IsSFiniteKernel pairedOccupation := by + unfold pairedOccupation + infer_instance + +theorem returnLaw_eq_potential : returnLaw = potential costCaptured costKilled := rfl + +theorem occupationKernel_eq_potential : occupationKernel = potential pairVisits costKilled := rfl + +theorem pairedOccupation_cycle_decomposition : + pairedOccupation = Kernel.sum (fun n : ℕ => occupationKernel ∘ₖ (returnLaw ^ n)) := by + have hsplit : pairedCostKernel = costKilled + costCaptured := by + rw [add_comm, costCaptured_add_costKilled] + rw [pairedOccupation, hsplit, first_capture_decomposition, + ← occupationKernel_eq_potential, ← returnLaw_eq_potential] + rfl + +noncomputable def oddEmbeddingKernel : Kernel OddCost CostState := + Kernel.deterministic embedOdd embedOdd_measurable + +theorem oddEmbedding_intertwines : + oddEmbeddingKernel ∘ₖ pairedCostKernel = (costKernel ^ 2) ∘ₖ oddEmbeddingKernel := by + rw [oddEmbeddingKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.map_apply _ embedOdd_measurable, Kernel.comap_apply] + exact pairedCost_full_grouping z + +theorem oddEmbedding_intertwines_pow (n : ℕ) : + oddEmbeddingKernel ∘ₖ (pairedCostKernel ^ n) = (costKernel ^ (2 * n)) ∘ₖ oddEmbeddingKernel := by + induction n with + | zero => + have h0 : pairedCostKernel ^ 0 = (Kernel.id : Kernel OddCost OddCost) := rfl + have h1 : costKernel ^ (2 * 0) = (Kernel.id : Kernel CostState CostState) := rfl + rw [h0, h1, Kernel.comp_id, Kernel.id_comp] + | succ n ih => + have hp : pairedCostKernel ^ (n + 1) = (pairedCostKernel ^ n) ∘ₖ pairedCostKernel := pow_succ _ _ + rw [hp, ← Kernel.comp_assoc, ih, Kernel.comp_assoc, oddEmbedding_intertwines, + ← Kernel.comp_assoc, ← Kernel.pow_add] + congr 2 + +theorem pairedCost_pow_full_grouping (n : ℕ) (z : OddCost) : + ((pairedCostKernel ^ n) z).map embedOdd = (costKernel ^ (2 * n)) (embedOdd z) := by + have h := oddEmbedding_intertwines_pow n + rw [oddEmbeddingKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] at h + have hz := congrArg (fun K : Kernel OddCost CostState => K z) h + rwa [Kernel.map_apply _ embedOdd_measurable, Kernel.comap_apply] at hz + +theorem pairVisits_as_full_kernel : + pairVisits = (costKernel + costKernel ^ 2) ∘ₖ oddEmbeddingKernel := by + rw [oddEmbeddingKernel, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.comap_apply, add_apply] + exact pairVisits_full_steps z + +theorem pairedVisits_full_grouping (n : ℕ) (z : OddCost) : + (pairVisits ∘ₖ (pairedCostKernel ^ n)) z = + (costKernel ^ (2 * n + 1)) (embedOdd z) + (costKernel ^ (2 * n + 2)) (embedOdd z) := by + have heq : pairVisits ∘ₖ (pairedCostKernel ^ n) = + (costKernel ^ (2 * n + 1) + costKernel ^ (2 * n + 2)) ∘ₖ oddEmbeddingKernel := by + rw [pairVisits_as_full_kernel, Kernel.comp_assoc, oddEmbedding_intertwines_pow, + ← Kernel.comp_assoc, Kernel.comp_add_left] + have h1 : costKernel ∘ₖ (costKernel ^ (2 * n)) = costKernel ^ (2 * n + 1) := by + exact (pow_succ' costKernel (2 * n)).symm + have h2 : (costKernel ^ 2) ∘ₖ (costKernel ^ (2 * n)) = costKernel ^ (2 * n + 2) := by + rw [← Kernel.pow_add] + congr 1 + omega + rw [h1, h2] + rw [heq, oddEmbeddingKernel, Kernel.comp_deterministic_eq_comap, Kernel.comap_apply, add_apply] + +noncomputable def fullOccupation : Kernel CostState CostState := + Kernel.sum (fun n : ℕ => costKernel ^ (n + 1)) + +theorem pairedOccupation_eq_full (z : OddCost) : pairedOccupation z = fullOccupation (embedOdd z) := by + ext B hB + rw [pairedOccupation, potential, Kernel.sum_apply' _ _ hB, fullOccupation, Kernel.sum_apply' _ _ hB] + simp_rw [pairedVisits_full_grouping, Measure.add_apply] + rw [ENNReal.tsum_add] + simpa only [Nat.add_assoc, show (1 : ℕ) + 1 = 2 by rfl] using + (tsum_even_add_odd (f := fun n : ℕ => (costKernel ^ (n + 1)) (embedOdd z) B) + ENNReal.summable ENNReal.summable) + +theorem fullOccupation_cycle_decomposition (z : OddCost) : + fullOccupation (embedOdd z) = + Measure.sum (fun n : ℕ => (occupationKernel ∘ₖ (returnLaw ^ n)) z) := by + rw [← pairedOccupation_eq_full, pairedOccupation_cycle_decomposition, Kernel.sum_apply] + +theorem fullOccupation_cycle_lintegral (z : OddCost) {F : CostState → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F y ∂fullOccupation (embedOdd z)) = + ∑' n : ℕ, ∫⁻ w, ∫⁻ y, F y ∂occupationKernel w ∂(returnLaw ^ n) z := by + rw [fullOccupation_cycle_decomposition, lintegral_sum_measure] + apply tsum_congr + intro n + exact Kernel.lintegral_comp _ _ _ hF + +end NumberTheoryLean.OccupationDecomposition + + + +namespace NumberTheoryLean.OccupationRegeneration + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostProcess PairedCostGrouping +open RegenerationTails CostReturnLaw CycleRegeneration CycleOccupation +open OccupationDecomposition CycleResponse CycleConvolutionLaw + +def shiftFullCost (a : ℝ) (z : CostState) : CostState := (z.1, z.2 + a) + +theorem shiftFullCost_measurable (a : ℝ) : Measurable (shiftFullCost a) := + measurable_fst.prodMk (measurable_snd.add measurable_const) + +theorem costKernel_translation (z : CostState) (a : ℝ) : + (costKernel z).map (shiftFullCost a) = costKernel (shiftFullCost a z) := by + ext B hB + rw [Measure.map_apply (shiftFullCost_measurable a) hB, + costKernel_apply _ ((shiftFullCost_measurable a) hB), costKernel_apply _ hB] + congr 1 + ext s + change (s, (z.2 + cost (stateRatio s)) + a) ∈ B ↔ + (s, (z.2 + a) + cost (stateRatio s)) ∈ B + rw [show z.2 + cost (stateRatio s) + a = z.2 + a + cost (stateRatio s) by ring] + +noncomputable def shiftFullKernel (a : ℝ) : Kernel CostState CostState := + Kernel.deterministic (shiftFullCost a) (shiftFullCost_measurable a) + +theorem shiftFull_commutes (a : ℝ) : Commute (shiftFullKernel a) costKernel := by + change shiftFullKernel a ∘ₖ costKernel = costKernel ∘ₖ shiftFullKernel a + rw [shiftFullKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.map_apply _ (shiftFullCost_measurable a), Kernel.comap_apply] + exact costKernel_translation z a + +theorem costKernel_pow_translation (n : ℕ) (z : CostState) (a : ℝ) : + ((costKernel ^ n) z).map (shiftFullCost a) = (costKernel ^ n) (shiftFullCost a z) := by + have h := ((shiftFull_commutes a).pow_right n).eq + change shiftFullKernel a ∘ₖ (costKernel ^ n) = (costKernel ^ n) ∘ₖ shiftFullKernel a at h + rw [shiftFullKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] at h + have hz := congrArg (fun K : Kernel CostState CostState => K z) h + rwa [Kernel.map_apply _ (shiftFullCost_measurable a), Kernel.comap_apply] at hz + +theorem pairVisits_translation (z : OddCost) (a : ℝ) : + (pairVisits z).map (shiftFullCost a) = pairVisits (shiftCost a z) := by + rw [pairVisits_full_steps, Measure.map_add _ _ (shiftFullCost_measurable a), + costKernel_translation, costKernel_pow_translation, pairVisits_full_steps] + rfl + +theorem shifts_intertwine_pairVisits (a : ℝ) : + shiftFullKernel a ∘ₖ pairVisits = pairVisits ∘ₖ shiftKernel a := by + rw [shiftFullKernel, shiftKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.map_apply _ (shiftFullCost_measurable a), Kernel.comap_apply] + exact pairVisits_translation z a + +theorem shifts_intertwine_occupation (a : ℝ) : + shiftFullKernel a ∘ₖ occupationKernel = occupationKernel ∘ₖ shiftKernel a := by + rw [occupationKernel, Kernel.comp_sum_right, Kernel.comp_sum_left] + apply congrArg Kernel.sum + funext n + have hQ := ((shift_commutes_killed a).pow_right n).eq + change shiftKernel a ∘ₖ (costKilled ^ n) = (costKilled ^ n) ∘ₖ shiftKernel a at hQ + change shiftFullKernel a ∘ₖ (pairVisits ∘ₖ (costKilled ^ n)) = + (pairVisits ∘ₖ (costKilled ^ n)) ∘ₖ shiftKernel a + rw [← Kernel.comp_assoc, shifts_intertwine_pairVisits, Kernel.comp_assoc, hQ, ← Kernel.comp_assoc] + +theorem occupation_translation (z : OddCost) (a : ℝ) : + (occupationKernel z).map (shiftFullCost a) = occupationKernel (shiftCost a z) := by + have h := shifts_intertwine_occupation a + rw [shiftFullKernel, shiftKernel, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] at h + have hz := congrArg (fun K : Kernel OddCost CostState => K z) h + rwa [Kernel.map_apply _ (shiftFullCost_measurable a), Kernel.comap_apply] at hz + +theorem pairVisits_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + pairVisits (s, T) = pairVisits (regenerationState, T) := by + rw [pairVisits_full_steps, pairVisits_full_steps] + have hfirst : costKernel (embedOdd (s, T)) = costKernel (embedOdd (regenerationState, T)) := + costKernel_regeneration s hs T + have hpow : costKernel ^ 2 = costKernel ∘ₖ costKernel := by rw [pow_two]; rfl + rw [hfirst, hpow, Kernel.comp_apply, Kernel.comp_apply, hfirst] + +theorem visitBlock_regeneration (n : ℕ) (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + visitBlock n (s, T) = visitBlock n (regenerationState, T) := by + cases n with + | zero => + change (pairVisits ∘ₖ (Kernel.id : Kernel OddCost OddCost)) (s, T) = + (pairVisits ∘ₖ (Kernel.id : Kernel OddCost OddCost)) (regenerationState, T) + rw [Kernel.comp_id] + exact pairVisits_regeneration s hs T + | succ n => + have hp : costKilled ^ (n + 1) = (costKilled ^ n) ∘ₖ costKilled := pow_succ _ _ + have hq : (costKilled ^ (n + 1)) (s, T) = (costKilled ^ (n + 1)) (regenerationState, T) := by + rw [hp, Kernel.comp_apply, Kernel.comp_apply, costKilled_regeneration s hs T] + rw [visitBlock, Kernel.comp_apply, Kernel.comp_apply, hq] + +theorem occupation_regeneration (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + occupationKernel (s, T) = occupationKernel (regenerationState, T) := by + ext B hB + rw [occupationKernel, Kernel.sum_apply' _ _ hB, Kernel.sum_apply' _ _ hB] + apply tsum_congr + intro n + rw [visitBlock_regeneration n s hs T] + +theorem occupation_regeneration_law (z : OddCost) (hz : z ∈ returnSet) : + occupationKernel z = occupationMeasure.map (shiftFullCost z.2) := by + rw [occupation_regeneration z.1 hz z.2, occupationMeasure, occupation_translation] + have heq : shiftCost z.2 (regenerationState, 0) = (regenerationState, z.2) := by simp [shiftCost] + rw [heq] + +noncomputable def positiveResponse (F : ℝ × State → ℝ≥0∞) (v : ℝ) : ℝ≥0∞ := + ∫⁻ y : CostState, F (v - y.2, y.1) ∂occupationMeasure + +theorem positiveResponse_measurable {F : ℝ × State → ℝ≥0∞} (hF : Measurable F) : + Measurable (positiveResponse F) := by + exact (hF.comp ((measurable_fst.sub (measurable_snd.comp measurable_snd)).prodMk + (measurable_fst.comp measurable_snd))).lintegral_prod_right' + +theorem occupation_response_lintegral (z : OddCost) (hz : z ∈ returnSet) + {F : ℝ × State → ℝ≥0∞} (hF : Measurable F) (v : ℝ) : + (∫⁻ y : CostState, F (v - y.2, y.1) ∂occupationKernel z) = positiveResponse F (v - z.2) := by + rw [occupation_regeneration_law z hz, lintegral_map + (f := fun y : CostState => F (v - y.2, y.1)) + (hF.comp ((measurable_const.sub measurable_snd).prodMk measurable_fst)) (shiftFullCost_measurable z.2)] + apply lintegral_congr + intro y + congr 1 + dsimp [shiftFullCost] + ext <;> simp only + ring + +theorem occupation_response_integral (z : OddCost) (hz : z ∈ returnSet) + {F : Test} (hF : Measurable F) (v : ℝ) : + (∫ y : CostState, F (v - y.2, y.1) ∂occupationKernel z) = response F (v - z.2) := by + rw [occupation_regeneration_law z hz, integral_map (shiftFullCost_measurable z.2).aemeasurable + (shiftedTest_measurable hF v).aestronglyMeasurable] + apply integral_congr_ae + apply Eventually.of_forall + intro y + change F (v - (y.2 + z.2), y.1) = F ((v - z.2) - y.2, y.1) + rw [show v - (y.2 + z.2) = (v - z.2) - y.2 by ring] + +theorem returnLaw_pow_ae_regeneration (n : ℕ) (z : OddCost) (hz : z ∈ returnSet) : + ∀ᵐ w ∂(returnLaw ^ n) z, w ∈ returnSet := by + cases n with + | zero => + change ∀ᵐ w ∂Measure.dirac z, w ∈ returnSet + exact (ae_dirac_iff returnSet_measurable).mpr hz + | succ n => + have hp : returnLaw ^ (n + 1) = returnLaw ∘ₖ (returnLaw ^ n) := pow_succ' _ _ + rw [hp] + exact Kernel.ae_comp_of_ae_ae returnSet_measurable + (Eventually.of_forall fun w => returnLaw_ae_regeneration w) + +theorem fullOccupation_positive_convolution {F : ℝ × State → ℝ≥0∞} + (hF : Measurable F) (v : ℝ) : + (∫⁻ y : CostState, F (v - y.2, y.1) ∂fullOccupation (embedOdd (regenerationState, 0))) = + ∑' n : ℕ, ∫⁻ s, positiveResponse F (v - s) ∂actualArrivalLaw n := by + have hz : (regenerationState, (0 : ℝ)) ∈ returnSet := by change (1 : ℝ) ≤ 3; norm_num + rw [fullOccupation_cycle_lintegral _ (F := fun y : CostState => F (v - y.2, y.1)) (hF.comp ((measurable_const.sub measurable_snd).prodMk measurable_fst))] + apply tsum_congr + intro n + rw [actualArrivalLaw, lintegral_map (f := fun s : ℝ => positiveResponse F (v - s)) + ((positiveResponse_measurable hF).comp (measurable_const.sub measurable_id)) measurable_snd] + apply lintegral_congr_ae + filter_upwards [returnLaw_pow_ae_regeneration n (regenerationState, 0) hz] with w hw + exact occupation_response_lintegral w hw hF v + +end NumberTheoryLean.OccupationRegeneration + + + +namespace NumberTheoryLean.SignedCycleOccupation + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open FinitePathMeasures PairedCostProcess PairedCostGrouping RegenerationTails +open CostReturnLaw CycleOccupation CycleResponse CycleConvolutionLaw +open AdmissibleCycleTests OccupationDecomposition OccupationRegeneration +open AbsorptionCutoff.Renewal + +theorem positiveResponse_norm_eq {F : Test} (hF : Measurable F) {C : ℝ} + (hbound : ∀ x, ‖F x‖ ≤ C) (v : ℝ) : + positiveResponse (fun x => ‖F x‖ₑ) v = ‖response (fun x => ‖F x‖) v‖ₑ := by + have hi : Integrable (fun y : CostState => ‖F (v - y.2, y.1)‖) occupationMeasure := + (shiftedTest_integrable hF hbound v).norm + have hp : 0 ≤ response (fun x => ‖F x‖) v := integral_nonneg (fun y => norm_nonneg _) + rw [← ofReal_norm, Real.norm_eq_abs, abs_of_nonneg hp] + have h := ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall fun y => norm_nonneg _) + simpa only [positiveResponse, response, ofReal_norm] using h.symm + +theorem positiveResponse_norm_driNorm {F : Test} (hF : Measurable F) (hB : HasCompactBound F) : + driNorm (positiveResponse (fun x => ‖F x‖ₑ)) ≠ ∞ := by + obtain ⟨C, M, hC, hM, hb, hs⟩ := hB + have heq : positiveResponse (fun x => ‖F x‖ₑ) = fun v => ‖response (fun x => ‖F x‖) v‖ₑ := + funext (positiveResponse_norm_eq hF hb) + rw [heq] + apply response_driNorm hC hM + · intro x + simpa only [norm_norm] using hb x + · intro x hx + rw [hs x hx, norm_zero] + +theorem fullOccupation_norm_lintegral_bound {F : Test} (hF : Measurable F) + (hB : HasCompactBound F) : ∃ C : ℝ≥0∞, C < ∞ ∧ ∀ v : ℝ, + (∫⁻ y : CostState, ‖F (v - y.2, y.1)‖ₑ ∂fullOccupation (embedOdd (regenerationState, 0))) ≤ C := by + obtain ⟨D, hD⟩ := CycleRenewalInputs.cycle_renewal_cell_bound 1 + let H := positiveResponse (fun x => ‖F x‖ₑ) + have hH : driNorm H ≠ ∞ := positiveResponse_norm_driNorm hF hB + refine ⟨ENNReal.ofReal D * driNorm H, ENNReal.mul_lt_top ENNReal.ofReal_lt_top (lt_top_iff_ne_top.mpr hH), ?_⟩ + intro v + rw [fullOccupation_positive_convolution hF.enorm] + simp_rw [actualArrivalLaw_eq_convPow] + exact tsum_lintegral_comp_sub_le hD H v + +theorem fullOccupation_test_integrable {F : Test} (hF : Measurable F) + (hB : HasCompactBound F) (v : ℝ) : + Integrable (fun y : CostState => F (v - y.2, y.1)) + (fullOccupation (embedOdd (regenerationState, 0))) := by + obtain ⟨C, hC, hb⟩ := fullOccupation_norm_lintegral_bound hF hB + exact ⟨(shiftedTest_measurable hF v).aestronglyMeasurable, lt_of_le_of_lt (hb v) hC⟩ + +theorem fullOccupation_test_uniform_bound {F : Test} (hF : Measurable F) + (hB : HasCompactBound F) : ∃ C : ℝ, 0 ≤ C ∧ ∀ v : ℝ, + ‖∫ y : CostState, F (v - y.2, y.1) ∂fullOccupation (embedOdd (regenerationState, 0))‖ ≤ C := by + obtain ⟨C, hC, hb⟩ := fullOccupation_norm_lintegral_bound hF hB + refine ⟨C.toReal, ENNReal.toReal_nonneg, ?_⟩ + intro v + calc + _ ≤ (∫⁻ y : CostState, ‖F (v - y.2, y.1)‖ₑ ∂fullOccupation (embedOdd (regenerationState, 0))).toReal := + by simpa only [ofReal_norm] using (norm_integral_le_lintegral_norm + (μ := fullOccupation (embedOdd (regenerationState, 0))) (fun y : CostState => F (v - y.2, y.1))) + _ ≤ C.toReal := ENNReal.toReal_mono hC.ne (hb v) + +theorem fullOccupation_signed_convolution {F : Test} (hF : Admissible F) (v : ℝ) : + (∫ y : CostState, F (v - y.2, y.1) ∂fullOccupation (embedOdd (regenerationState, 0))) = + ∑' n : ℕ, ∫ s, response F (v - s) ∂actualArrivalLaw n := by + have hz : (regenerationState, (0 : ℝ)) ∈ returnSet := by change (1 : ℝ) ≤ 3; norm_num + have hI := fullOccupation_test_integrable hF.measurable hF.compactBound v + rw [fullOccupation_cycle_decomposition] at hI ⊢ + rw [integral_sum_measure hI] + apply tsum_congr + intro n + have hn := (integrable_sum_measure_iff.mp hI).1 n + rw [Kernel.integral_comp hn, actualArrivalLaw, integral_map (f := fun s : ℝ => response F (v - s)) measurable_snd.aemeasurable + ((hF.response_continuous.comp (continuous_const.sub continuous_id)).aestronglyMeasurable)] + apply integral_congr_ae + filter_upwards [returnLaw_pow_ae_regeneration n (regenerationState, 0) hz] with w hw + exact occupation_response_integral w hw hF.measurable v + +theorem fullOccupation_regeneration_limit {F : Test} (hF : Admissible F) : + Tendsto (fun v : ℝ => ∫ y : CostState, F (v - y.2, y.1) + ∂fullOccupation (embedOdd (regenerationState, 0))) atTop + (𝓝 ((∫ u : ℝ, response F u) / (∫ G : ℝ, G ∂cycleCostLaw))) := by + simpa only [fullOccupation_signed_convolution hF] using admissible_cycle_response_renewal hF + +end NumberTheoryLean.SignedCycleOccupation + + + +namespace NumberTheoryLean.CycleResponseFubini + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures CycleOccupation CycleResponse AdmissibleCycleTests + +noncomputable def ageShear (x : CostState × ℝ) : CostState × ℝ := (x.1, x.2 - x.1.2) + +theorem ageShear_measurable : Measurable ageShear := + measurable_fst.prodMk (measurable_snd.sub (measurable_snd.comp measurable_fst)) + +theorem ageShear_measurePreserving : MeasurePreserving ageShear + (occupationMeasure.prod volume) (occupationMeasure.prod volume) := by + apply MeasurePreserving.skew_product (g := fun y : CostState => fun u : ℝ => u - y.2) (MeasurePreserving.id occupationMeasure) + (measurable_snd.sub (measurable_snd.comp measurable_fst)) + apply Eventually.of_forall + intro y + simpa only [sub_eq_add_neg] using map_add_right_eq_self (volume : Measure ℝ) (-y.2) + +theorem unshifted_test_product_integrable {F : Test} (hF : Measurable F) + (hB : HasCompactBound F) : + Integrable (fun x : CostState × ℝ => F (x.2, x.1.1)) (occupationMeasure.prod volume) := by + classical + obtain ⟨C, M, hC, hM, hb, hs⟩ := hB + have hi : Integrable ((Icc (-M) M).indicator (fun _ : ℝ => (1 : ℝ))) volume := + (integrable_indicator_iff measurableSet_Icc).mpr (integrableOn_const isCompact_Icc.measure_ne_top) + have hprod := (integrable_const C : Integrable (fun _ : CostState => C) occupationMeasure).mul_prod hi + refine hprod.mono' (hF.comp (measurable_snd.prodMk (measurable_fst.comp measurable_fst))).aestronglyMeasurable ?_ + apply Eventually.of_forall + intro x + by_cases hx : x.2 ∈ Icc (-M) M + · simpa only [indicator_of_mem hx, mul_one] using hb (x.2, x.1.1) + · have habs : M < |x.2| := by + apply lt_of_not_ge + intro hu + exact hx (abs_le.mp hu) + rw [hs (x.2, x.1.1) habs, norm_zero, indicator_of_notMem hx, mul_zero] + +theorem shifted_test_product_integrable {F : Test} (hF : Measurable F) + (hB : HasCompactBound F) : + Integrable (fun x : CostState × ℝ => F (x.2 - x.1.2, x.1.1)) (occupationMeasure.prod volume) := by + exact ageShear_measurePreserving.integrable_comp_of_integrable (unshifted_test_product_integrable hF hB) + +theorem response_integrable {F : Test} (hF : Measurable F) (hB : HasCompactBound F) : + Integrable (response F) volume := by + exact (shifted_test_product_integrable hF hB).integral_prod_right + +theorem integrated_test_occupation_integrable {F : Test} (hF : Measurable F) + (hB : HasCompactBound F) : + Integrable (fun y : CostState => ∫ u : ℝ, F (u, y.1)) occupationMeasure := + (unshifted_test_product_integrable hF hB).integral_prod_left + +theorem integral_response_eq_occupation {F : Test} (hF : Measurable F) + (hB : HasCompactBound F) : + (∫ v : ℝ, response F v) = ∫ y : CostState, (∫ u : ℝ, F (u, y.1)) ∂occupationMeasure := by + calc + _ = ∫ y : CostState, (∫ u : ℝ, F (u - y.2, y.1)) ∂occupationMeasure := + (integral_integral_swap (shifted_test_product_integrable hF hB)).symm + _ = _ := by + apply integral_congr_ae + apply Eventually.of_forall + intro y + exact integral_sub_right_eq_self (fun u : ℝ => F (u, y.1)) y.2 + +end NumberTheoryLean.CycleResponseFubini + + + +namespace NumberTheoryLean.OccupationConstant + +open Set MeasureTheory +open FinitePathMeasures CycleResponse CycleResponseFubini AdmissibleCycleTests +open Erdos970Dependency.InvariantDensities Erdos970Dependency.StateKernelInvariance +open Erdos970Dependency.ActualCycleOccupation + +noncomputable def integratedStateTest (F : Test) (s : State) : ℝ := ∫ u : ℝ, F (u, s) + +theorem integratedStateTest_measurable {F : Test} (hF : Measurable F) : + Measurable (integratedStateTest F) := hF.stronglyMeasurable.integral_prod_left'.measurable + +theorem response_integral_eq_invariant {F : Test} (hF : Measurable F) (hB : HasCompactBound F) : + Integrable (integratedStateTest F) stateMeasure ∧ + (∫ v : ℝ, response F v) = (1 / beta) * ∫ s : State, integratedStateTest F s ∂stateMeasure := by + obtain ⟨hI, hEq⟩ := integral_state_occupation (integratedStateTest_measurable hF) + (integrated_test_occupation_integrable hF hB) + refine ⟨hI, ?_⟩ + rw [integral_response_eq_occupation hF hB] + exact hEq + +end NumberTheoryLean.OccupationConstant + + + +namespace NumberTheoryLean.UniformCycleMoments + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open PairedCostProcess CostReturnLaw CycleCostMoments CycleDurationMoments +open PairedDrift PairedHitting PairedBlockContraction CycleOccupation + +theorem geometric_exponential_budget {m : ℕ} (hm : 0 < m) {ρ : ℝ} + (hρ : 0 < ρ) (hρ1 : ρ < 1) : ∃ θ C : ℝ, 0 < θ ∧ 0 ≤ C ∧ ∀ W : ℝ, 0 ≤ W → + (∑' n : ℕ, ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * + ENNReal.ofReal (ρ ^ (n / m) * W)) ≤ ENNReal.ofReal (C * W) := by + let θ := -Real.log ρ / (4 * (m : ℝ)) + have hmR : 0 < (m : ℝ) := by exact_mod_cast hm + have hθ : 0 < θ := div_pos (neg_pos.mpr (Real.log_neg hρ hρ1)) (by positivity) + have hrel : 4 * (m : ℝ) * θ = -Real.log ρ := by dsimp [θ]; field_simp + let A := Real.exp (-Real.log ρ + 2 * θ) + let r := Real.exp (-2 * θ) + have hA : 0 ≤ A := (Real.exp_pos _).le + have hr : 0 ≤ r := (Real.exp_pos _).le + have hr1 : r < 1 := Real.exp_lt_one_iff.mpr (by linarith) + have hsum : Summable (fun n : ℕ => A * r ^ n) := (summable_geometric_of_lt_one hr hr1).mul_left A + let C := ∑' n : ℕ, A * r ^ n + have hC : 0 ≤ C := tsum_nonneg (fun n => mul_nonneg hA (pow_nonneg hr n)) + refine ⟨θ, C, hθ, hC, ?_⟩ + intro W hW + calc + _ ≤ ∑' n : ℕ, ENNReal.ofReal (A * r ^ n) * ENNReal.ofReal W := by + apply ENNReal.tsum_le_tsum + intro n + have h := weighted_geometric_bound hm hρ hθ hrel n + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← ENNReal.ofReal_mul (mul_nonneg hA (pow_nonneg hr n))] + apply ENNReal.ofReal_le_ofReal + dsimp [A, r] + nlinarith [mul_le_mul_of_nonneg_right h hW] + _ = (∑' n : ℕ, ENNReal.ofReal (A * r ^ n)) * ENNReal.ofReal W := ENNReal.tsum_mul_right + _ = ENNReal.ofReal C * ENNReal.ofReal W := by + rw [← ENNReal.ofReal_tsum_of_nonneg (fun n => mul_nonneg hA (pow_nonneg hr n)) hsum] + _ = _ := (ENNReal.ofReal_mul hC).symm + +theorem return_increment_uniform_exponential : ∃ η C D : ℝ, + 0 < η ∧ 0 ≤ C ∧ 0 < D ∧ ∀ z : OddCost, + (∫⁻ y, ENNReal.ofReal (Real.exp (η * (y.2 - z.2))) ∂returnLaw z) ≤ + ENNReal.ofReal (C * (V z.1 + D)) := by + obtain ⟨m, hm, ρ, D, hρ, hρ1, hD, hb⟩ := firstReturn_geometric + obtain ⟨θ, C, hθ, hC, hbudget⟩ := geometric_exponential_budget hm hρ hρ1 + let η := θ / Real.log 3 + have hL : 0 < Real.log 3 := Real.log_pos (by norm_num) + have hη : 0 < η := div_pos hθ hL + refine ⟨η, C, D, hη, hC, hD, ?_⟩ + intro z + rw [returnLaw, Kernel.sum_apply, lintegral_sum_measure] + apply le_trans (ENNReal.tsum_le_tsum ?_) (hbudget (V z.1 + D) (add_nonneg (V_pos z.1).le hD.le)) + intro n + calc + _ ≤ ∫⁻ _y, ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) ∂firstReturn n z := by + apply lintegral_mono_ae + filter_upwards [firstReturn_cost_upper n z] with y hy + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + calc + η * (y.2 - z.2) ≤ η * (2 * ((n + 1 : ℕ) : ℝ) * Real.log 3) := + mul_le_mul_of_nonneg_left (by linarith) hη.le + _ = _ := by dsimp [η]; push_cast; field_simp + _ = ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * firstReturn n z univ := lintegral_const _ + _ ≤ _ := mul_le_mul le_rfl (hb n z) zero_le zero_le + +theorem occupation_increment_uniform_exponential : ∃ η C D : ℝ, + 0 < η ∧ 0 ≤ C ∧ 0 < D ∧ ∀ z : OddCost, + (∫⁻ y, ENNReal.ofReal (Real.exp (η * (y.2 - z.2))) ∂occupationKernel z) ≤ + ENNReal.ofReal (C * (V z.1 + D)) := by + obtain ⟨m, hm, ρ, D, hρ, hρ1, hD, hb⟩ := paired_survival_geometric + obtain ⟨θ, C, hθ, hC, hbudget⟩ := geometric_exponential_budget hm hρ hρ1 + let η := θ / Real.log 3 + have hL : 0 < Real.log 3 := Real.log_pos (by norm_num) + have hη : 0 < η := div_pos hθ hL + refine ⟨η, 2 * C, D, hη, mul_nonneg (by norm_num) hC, hD, ?_⟩ + intro z + have hW : 0 ≤ V z.1 + D := add_nonneg (V_pos z.1).le hD.le + rw [occupationKernel, Kernel.sum_apply, lintegral_sum_measure] + calc + _ ≤ ∑' n : ℕ, 2 * (ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * + ENNReal.ofReal (ρ ^ (n / m) * (V z.1 + D))) := by + apply ENNReal.tsum_le_tsum + intro n + have hsurv : (costKilled ^ n) z univ ≤ ENNReal.ofReal (ρ ^ (n / m) * (V z.1 + D)) := by + rw [costKilled_mass] + exact le_trans (paired_survival_antitone z.1 (Nat.mul_div_le n m)) (hb (n / m) z.1) + calc + _ ≤ ∫⁻ _y, ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) ∂visitBlock n z := by + apply lintegral_mono_ae + filter_upwards [visitBlock_age_bounds n z] with y hy + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + calc + η * (y.2 - z.2) ≤ η * (2 * ((n + 1 : ℕ) : ℝ) * Real.log 3) := + mul_le_mul_of_nonneg_left (by linarith [hy.2]) hη.le + _ = _ := by dsimp [η]; push_cast; field_simp + _ = ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * (2 * (costKilled ^ n) z univ) := by + rw [lintegral_const, visitBlock_mass] + _ ≤ ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * + (2 * ENNReal.ofReal (ρ ^ (n / m) * (V z.1 + D))) := + mul_le_mul le_rfl (mul_le_mul le_rfl hsurv zero_le zero_le) zero_le zero_le + _ = _ := by ring + _ = 2 * ∑' n : ℕ, ENNReal.ofReal (Real.exp (θ * (2 * ((n : ℝ) + 1)))) * + ENNReal.ofReal (ρ ^ (n / m) * (V z.1 + D)) := ENNReal.tsum_mul_left + _ ≤ 2 * ENNReal.ofReal (C * (V z.1 + D)) := mul_le_mul le_rfl (hbudget _ hW) zero_le zero_le + _ = _ := by + rw [show (2 : ℝ≥0∞) = ENNReal.ofReal (2 : ℝ) by norm_num, + ← ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≤ 2)] + congr 1 + ring + +end NumberTheoryLean.UniformCycleMoments + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Renewal/WeightDickmanComparison.lean b/lean/OAI/NumberTheory/Jacobsthal/Renewal/WeightDickmanComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..660176488011530a8888fdb5ba2b64b3e42c24b4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Renewal/WeightDickmanComparison.lean @@ -0,0 +1,82 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.WeightFutureIntegrals + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.WeightDickmanComparison + +open Filter Set +open scoped Topology +open LinearSieveFunctions BuchstabBridge NormalizedDeficits +open DerivativeWeights WeightFutureIntegrals + +theorem deficits_le_gap {s : ℝ} (hs : 1 ≤ s) : + lowerDeficit s ≤ gap s ∧ upperDeficit s ≤ gap s := by + have h := deficit_sum s + obtain ⟨ha, hc⟩ := deficits_pos hs + constructor <;> linarith + +theorem weights_dickman_bounds : ∃ c C : ℝ, 0 < c ∧ 0 < C ∧ + ∀ s : ℝ, 2 ≤ s → + (c * Dickman.rho (s - 2) ≤ phiEven s ∧ phiEven s ≤ C * Dickman.rho (s - 2)) ∧ + (c * Dickman.rho (s - 2) ≤ phiOdd s ∧ phiOdd s ≤ C * Dickman.rho (s - 2)) := by + obtain ⟨δ, hδ, _, hcomp⟩ := deficits_uniform_comparison + refine ⟨δ * sieveA, 3 * sieveA, mul_pos hδ sieveA_pos, + mul_pos (by norm_num) sieveA_pos, ?_⟩ + intro s hs + have hs1 : 1 ≤ s := by linarith + have hp1 : 1 ≤ s - 1 := by linarith + have hs0 : 0 < s := by linarith + have hg : 0 < gap (s - 1) := gap_pos hp1 + have hgprev : (s - 1) * gap (s - 1) = sieveA * Dickman.rho (s - 2) := by + rw [gap_eq_rho hp1, show s - 1 - 1 = s - 2 by ring] + field_simp + have hgcur : s * gap s = sieveA * Dickman.rho (s - 1) := by + rw [gap_eq_rho hs1] + field_simp + have hlow : (δ * sieveA) * Dickman.rho (s - 2) ≤ s * (δ * gap (s - 1)) := by + calc + _ = δ * ((s - 1) * gap (s - 1)) := by rw [hgprev]; ring + _ = (s - 1) * (δ * gap (s - 1)) := by ring + _ ≤ s * (δ * gap (s - 1)) := mul_le_mul_of_nonneg_right (by linarith) (mul_pos hδ hg).le + have hlowE : s * (δ * gap (s - 1)) ≤ phiEven s := by + rw [phiEven_eq_deficits hs] + apply mul_le_mul_of_nonneg_left _ hs0.le + have hc := (hcomp (s - 1) hp1).2.2.1 + have ha := (deficits_pos hs1).1 + linarith + have hlowO : s * (δ * gap (s - 1)) ≤ phiOdd s := by + rw [phiOdd_eq_deficits hs1] + apply mul_le_mul_of_nonneg_left _ hs0.le + have ha := (hcomp (s - 1) hp1).1 + have hc := (deficits_pos hs1).2 + linarith + have huppE : phiEven s ≤ s * (gap s + gap (s - 1)) := by + rw [phiEven_eq_deficits hs] + exact mul_le_mul_of_nonneg_left + (add_le_add (deficits_le_gap hs1).1 (deficits_le_gap hp1).2) hs0.le + have huppO : phiOdd s ≤ s * (gap s + gap (s - 1)) := by + rw [phiOdd_eq_deficits hs1] + exact mul_le_mul_of_nonneg_left + (add_le_add (deficits_le_gap hs1).2 (deficits_le_gap hp1).1) hs0.le + have hupp : s * (gap s + gap (s - 1)) ≤ (3 * sieveA) * Dickman.rho (s - 2) := by + have h1 : sieveA * Dickman.rho (s - 1) ≤ sieveA * Dickman.rho (s - 2) := + mul_le_mul_of_nonneg_left (Dickman.rho_antitone (by linarith)) sieveA_pos.le + have h2 : s * gap (s - 1) ≤ 2 * ((s - 1) * gap (s - 1)) := by + nlinarith [mul_le_mul_of_nonneg_right (show s ≤ 2 * (s - 1) by linarith) hg.le] + rw [hgprev] at h2 + rw [mul_add, hgcur] + nlinarith + exact ⟨⟨le_trans hlow hlowE, le_trans huppE hupp⟩, + ⟨le_trans hlow hlowO, le_trans huppO hupp⟩⟩ + +end NumberTheoryLean.WeightDickmanComparison + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/AffineProjChartPolynomialEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AffineProjChartPolynomialEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5ae0f042183a5f1c1b860f02debe0b7e7a4a6ba --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AffineProjChartPolynomialEquiv.lean @@ -0,0 +1,98 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.GenericNormalization +import OAI.NumberTheory.Jacobsthal.Siegel.Homogenize + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial HomogeneousLocalization + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem conePolynomialMap_of_isHomogeneous {K σ : Type*} [CommRing K] + {f : MvPolynomial (Option σ) K} {n : ℕ} (hf : f.IsHomogeneous n) : + conePolynomialMap f = Polynomial.C (coneDehomogenize f) * Polynomial.X ^ n := by + have hv : (fun o : Option σ => Polynomial.C (o.elim (1 : MvPolynomial σ K) X) * + Polynomial.X) = (fun o : Option σ => o.elim Polynomial.X + (fun i => Polynomial.C (X i) * Polynomial.X)) := by + funext o + cases o <;> simp + have hc : algebraMap K (Polynomial (MvPolynomial σ K)) = + Polynomial.C.comp (algebraMap K (MvPolynomial σ K)) := by + apply RingHom.ext + intro r + exact Polynomial.algebraMap_apply (A := MvPolynomial σ K) r + rw [conePolynomialMap, aeval_def, hc, ← hv, + homogeneous_eval₂_mul hf, ← MvPolynomial.hom_eval₂] + rfl + +theorem coneAwayEquiv_affineProjChartMap {K σ : Type*} [CommRing K] + (z : affineProjChart K σ) : + coneAwayEquiv (algebraMap (affineProjChart K σ) + (Localization.Away (X (none : Option σ) : MvPolynomial (Option σ) K)) z) = + algebraMap (Polynomial (MvPolynomial σ K)) + (Localization.Away (Polynomial.X : Polynomial (MvPolynomial σ K))) + (Polynomial.C (affineProjChartMap (k := K) (fun i : σ => (X i : MvPolynomial σ K)) z)) := by + obtain ⟨n, a, ha, rfl⟩ := Away.mk_surjective (homogeneousSubmodule (Option σ) K) + (isHomogeneous_X K (none : Option σ)) z + let S := MvPolynomial (Option σ) K + let U := Localization.Away (X (none : Option σ) : S) + let A := MvPolynomial σ K + let V := Localization.Away (Polynomial.X : Polynomial A) + let e : U ≃ₐ[K] V := coneAwayEquiv + let den : Submonoid.powers (X (none : Option σ) : S) := ⟨X none ^ n, ⟨n, rfl⟩⟩ + have ha' : a.IsHomogeneous n := by + simpa only [smul_eq_mul, mul_one, mem_homogeneousSubmodule] using ha + have hunit : IsUnit (algebraMap (Polynomial A) V (Polynomial.X ^ n)) := by + simpa only [map_pow] using + (IsLocalization.Away.algebraMap_isUnit (S := V) (Polynomial.X : Polynomial A)).pow n + have hscale : e (algebraMap S U (den : S)) = + algebraMap (Polynomial A) V (Polynomial.X ^ n) := by + change coneAwayEquiv (algebraMap S U (X none ^ n)) = _ + rw [coneAwayEquiv_algebraMap, map_pow, conePolynomialMap_X_none] + have hraw : (Localization.mk a den : U) * algebraMap S U den = algebraMap S U a := by + rw [Localization.mk_eq_mk', IsLocalization.mk'_spec] + have heval : (coneDehomogenize : S →ₐ[K] A) = affineProjEval (k := K) + (fun i : σ => (X i : A)) := by + simp only [coneDehomogenize, affineProjEval, ← Option.elim'_eq_elim] + rw [affineProjChartMap_mk] + change e (Localization.mk a den) = algebraMap (Polynomial A) V + (Polynomial.C (affineProjEval (k := K) (fun i : σ => (X i : A)) a)) + apply hunit.mul_right_cancel + calc + _ = e (Localization.mk a den) * e (algebraMap S U den) := by rw [hscale] + _ = e ((Localization.mk a den : U) * algebraMap S U den) := (map_mul e _ _).symm + _ = e (algebraMap S U a) := congrArg e hraw + _ = algebraMap (Polynomial A) V (conePolynomialMap a) := coneAwayEquiv_algebraMap a + _ = _ := by rw [conePolynomialMap_of_isHomogeneous ha', map_mul, heval] + +theorem affineProjChartMap_polynomial_injective {K σ : Type*} [CommRing K] : + Function.Injective (affineProjChartMap (k := K) (fun i : σ => (X i : MvPolynomial σ K))) := by + intro a b hab + apply HomogeneousLocalization.val_injective + apply coneAwayEquiv.injective + change coneAwayEquiv (algebraMap (affineProjChart K σ) _ a) = + coneAwayEquiv (algebraMap (affineProjChart K σ) _ b) + rw [coneAwayEquiv_affineProjChartMap, coneAwayEquiv_affineProjChartMap, hab] + +noncomputable def affineProjChartPolynomialEquiv {K σ : Type*} [CommRing K] : + affineProjChart K σ ≃+* MvPolynomial σ K := + RingEquiv.ofBijective (affineProjChartMap (k := K) (fun i : σ => (X i : MvPolynomial σ K))) + ⟨affineProjChartMap_polynomial_injective, + affineProjChartMap_surjective _ (by + intro q + exact ⟨q, aeval_X_left_apply q⟩)⟩ + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/AffineZeroScheme.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AffineZeroScheme.lean new file mode 100644 index 0000000000000000000000000000000000000000..2bf5f14bf17e281f9f5602fcbc0b5aac0621c5b4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AffineZeroScheme.lean @@ -0,0 +1,482 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeProjectivePoint +import OAI.NumberTheory.Jacobsthal.Siegel.LaurentEvalOne + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem irrelevant_eq_ker_constantCoeff {K σ : Type*} [CommSemiring K] : + (HomogeneousIdeal.irrelevant (homogeneousSubmodule σ K)).toIdeal = + RingHom.ker (constantCoeff : MvPolynomial σ K →+* K) := by + ext p + rw [HomogeneousIdeal.mem_iff, HomogeneousIdeal.mem_irrelevant_iff, + GradedRing.proj_apply] + change (decomposition.decompose' p 0 : MvPolynomial σ K) = 0 ↔ constantCoeff p = 0 + rw [decomposition.decompose'_apply] + rw [homogeneousComponent_zero, constantCoeff_eq, C_eq_zero] + +theorem homogeneous_ideal_le_irrelevant {K σ : Type*} [Field K] + (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) (hproper : I ≠ ⊤) : + I ≤ (HomogeneousIdeal.irrelevant (homogeneousSubmodule σ K)).toIdeal := by + rw [irrelevant_eq_ker_constantCoeff] + intro p hp + change constantCoeff p = 0 + by_contra hn + have hC := homogeneousComponent_mem_of_mem hI hp 0 + rw [homogeneousComponent_zero] at hC + exact hproper (I.eq_top_of_isUnit_mem hC ((isUnit_iff_ne_zero.mpr hn).map C)) + +theorem irrelevant_isMaximal {K σ : Type*} [Field K] : + (HomogeneousIdeal.irrelevant (homogeneousSubmodule σ K)).toIdeal.IsMaximal := by + rw [irrelevant_eq_ker_constantCoeff] + exact RingHom.ker_isMaximal_of_surjective constantCoeff + (fun a => ⟨C a, constantCoeff_C σ a⟩) + +theorem projectiveSpectrum_lt_irrelevant {K σ : Type*} [Field K] + (x : ProjectiveSpectrum (homogeneousSubmodule σ K)) : + x.asHomogeneousIdeal.toIdeal < + (HomogeneousIdeal.irrelevant (homogeneousSubmodule σ K)).toIdeal := by + refine lt_of_le_not_ge + (homogeneous_ideal_le_irrelevant x.asHomogeneousIdeal.toIdeal + x.asHomogeneousIdeal.isHomogeneous x.isPrime.ne_top) ?_ + exact x.not_irrelevant_le + +end WeightedTorusJets.Geometry + + +namespace WeightedTorusJets.Geometry + +theorem topologicalKrullDim_le_closure_image {X Y : Type*} + [TopologicalSpace X] [TopologicalSpace Y] {f : X → Y} + (hf : Topology.IsInducing f) (Z : Set X) : + topologicalKrullDim Z ≤ topologicalKrullDim (closure (f '' Z)) := by + have hmem (x : Z) : f x ∈ closure (f '' Z) := + subset_closure ⟨x, x.property, rfl⟩ + exact ((hf.comp Topology.IsInducing.subtypeVal).codRestrict hmem).topologicalKrullDim_le + + + + +open _root_.AlgebraicGeometry MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra + +universe uClosure + +theorem coneProjective_zeroLocus_dimension + {K σ : Type uClosure} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + topologicalKrullDim (ProjectiveSpectrum.zeroLocus + (homogeneousSubmodule (Option σ) K) (coneIdeal p : Set (MvPolynomial (Option σ) K))) = + ringKrullDim (MvPolynomial σ K ⧸ p) := by + obtain ⟨d, hd, _⟩ := finiteType_dimension_trdeg (K := K) + (A := MvPolynomial σ K ⧸ p) + apply le_antisymm + · rw [hd] + let m := (HomogeneousIdeal.irrelevant (homogeneousSubmodule (Option σ) K)).toIdeal + let : m.IsMaximal := irrelevant_isMaximal + apply projective_zeroLocus_dim_le_of_cone_dim _ (coneIdeal p) m + projectiveSpectrum_lt_irrelevant d + rw [coneIdeal_quotient_ringKrullDim, hd] + · let : IsImmersion (affineIntoProj (k := K) (fun i : σ => X i)) := + affineIntoProj_isImmersion _ (fun f => ⟨f, aeval_X_left_apply f⟩) + have h : topologicalKrullDim (PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K))) ≤ + topologicalKrullDim (closure ((fun x : PrimeSpectrum (MvPolynomial σ K) => + ((affineIntoProj (k := K) (fun i : σ => X i)) x : + ProjectiveSpectrum (homogeneousSubmodule (Option σ) K))) '' + PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K)))) := + topologicalKrullDim_le_closure_image + (affineIntoProj (k := K) (fun i : σ => X i)).isEmbedding.isInducing + (PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K))) + rw [zeroLocus_topologicalKrullDim] at h + exact h.trans_eq (congrArg + (fun Z : Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K)) => + topologicalKrullDim Z) (closure_affineIntoProj_zeroLocus p)) + +theorem affineIntoProj_closure_dimension + {K σ : Type uClosure} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + topologicalKrullDim (closure ((affineIntoProj (k := K) (fun i : σ => X i)) '' + PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K)))) = + topologicalKrullDim (PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K))) := by + rw [closure_affineIntoProj_zeroLocus] + change topologicalKrullDim (ProjectiveSpectrum.zeroLocus + (homogeneousSubmodule (Option σ) K) (coneIdeal p : Set (MvPolynomial (Option σ) K))) = + topologicalKrullDim (PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K))) + rw [coneProjective_zeroLocus_dimension, zeroLocus_topologicalKrullDim] + +end WeightedTorusJets.Geometry + + +namespace WeightedTorusJets.Geometry + +open _root_.AlgebraicGeometry MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra + +universe uClosureCodim + +theorem affineIntoProj_closure_height_add_dimension + {K σ : Type uClosureCodim} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + (p.height : WithBot ℕ∞) + + topologicalKrullDim (closure ((affineIntoProj (k := K) (fun i : σ => X i)) '' + PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K)))) = Nat.card σ := by + calc + _ = (p.height : WithBot ℕ∞) + + topologicalKrullDim (PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K))) := + congrArg (fun d : WithBot ℕ∞ => (p.height : WithBot ℕ∞) + d) + (affineIntoProj_closure_dimension p) + _ = Nat.card σ := by + rw [zeroLocus_topologicalKrullDim, + prime_height_add_quotient_dim_eq_of_finiteType (K := K)] + simp + +end WeightedTorusJets.Geometry + + +namespace WeightedTorusJets.Geometry + +open _root_.AlgebraicGeometry + +theorem projective_component_of_isMinimalPrime + {A σ : Type*} [CommRing A] [SetLike σ A] [AddSubgroupClass σ A] + (𝒜 : ℕ → σ) [GradedRing 𝒜] (I : Ideal A) + (q : ProjectiveSpectrum 𝒜) (hq : I.IsMinimalPrime q.asHomogeneousIdeal.toIdeal) : + Maximal (fun V : Set (ProjectiveSpectrum 𝒜) => IsIrreducible V ∧ + V ⊆ ProjectiveSpectrum.zeroLocus 𝒜 (I : Set A)) + (closure ({q} : Set (ProjectiveSpectrum 𝒜))) := by + let : QuasiSober (ProjectiveSpectrum 𝒜) := inferInstanceAs (QuasiSober (Proj 𝒜)) + refine ⟨⟨isGenericPoint_closure.isIrreducible, ?_⟩, ?_⟩ + · exact closure_minimal (Set.singleton_subset_iff.mpr hq.le) + (ProjectiveSpectrum.isClosed_zeroLocus 𝒜 (I : Set A)) + · intro V hV hqV + let y := hV.1.genericPoint + have hy : IsGenericPoint y (closure V) := hV.1.isGenericPoint_genericPoint_closure + have hIy : I ≤ y.asHomogeneousIdeal.toIdeal := + closure_minimal hV.2 (ProjectiveSpectrum.isClosed_zeroLocus 𝒜 (I : Set A)) hy.mem + have hyq : y.asHomogeneousIdeal.toIdeal ≤ q.asHomogeneousIdeal.toIdeal := by + apply (ProjectiveSpectrum.le_iff_mem_closure 𝒜 y q).mpr + rw [hy.def] + exact subset_closure (hqV (subset_closure (Set.mem_singleton q))) + have hqy := hq.2 ⟨y.isPrime, hIy⟩ hyq + have heq : y = q := le_antisymm hyq hqy + rw [← heq, hy.def] + exact subset_closure + +end WeightedTorusJets.Geometry + + +namespace WeightedTorusJets.Geometry + +open _root_.AlgebraicGeometry MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem coneProjective_isComponent_of_local_radical + {ι K σ : Type*} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) + (hf : ((Ideal.span (Set.range f)).map + (algebraMap (MvPolynomial σ K) (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Maximal (fun V : Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K)) => + IsIrreducible V ∧ V ⊆ ProjectiveSpectrum.zeroLocus + (homogeneousSubmodule (Option σ) K) (paddedHomogenizedIdeal f n)) + (ProjectiveSpectrum.zeroLocus (homogeneousSubmodule (Option σ) K) (coneIdeal p)) := by + have h := projective_component_of_isMinimalPrime (homogeneousSubmodule (Option σ) K) + (paddedHomogenizedIdeal f n) (coneProjectivePoint p) + (coneIdeal_mem_minimalPrimes_padded p f n hf) + rwa [closure_coneProjectivePoint] at h + +universe uPaddedComponent + +theorem affineIntoProj_closure_isComponent_of_local_radical + {ι : Type*} {K σ : Type uPaddedComponent} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) + (hf : ((Ideal.span (Set.range f)).map + (algebraMap (MvPolynomial σ K) (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Maximal (fun V : Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K)) => + IsIrreducible V ∧ V ⊆ ProjectiveSpectrum.zeroLocus + (homogeneousSubmodule (Option σ) K) (paddedHomogenizedIdeal f n)) + (closure ((affineIntoProj (k := K) (fun i : σ => X i)) '' + PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K)))) := by + exact (congrArg + (fun Z : Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K)) => + Maximal (fun V => IsIrreducible V ∧ V ⊆ ProjectiveSpectrum.zeroLocus + (homogeneousSubmodule (Option σ) K) (paddedHomogenizedIdeal f n)) Z) + (closure_affineIntoProj_zeroLocus p)).mpr + (coneProjective_isComponent_of_local_radical p f n hf) + +end WeightedTorusJets.Geometry + +end + +namespace WeightedTorusJets.Geometry + +attribute [local instance] spec_stalk_isLocalRing + +theorem spec_stalk_cotangent_eq_localization {R : Type*} [CommRing R] + (q : PrimeSpectrum R) [IsRegularLocalRing (Localization.AtPrime q.asIdeal)] : + Module.finrank (IsLocalRing.ResidueField + ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk q)) + (IsLocalRing.CotangentSpace ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk q)) = + Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal)) := by + have : IsRegularLocalRing ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk q) := + IsRegularLocalRing.of_ringEquiv (AlgebraicGeometry.StructureSheaf.stalkIso R q).toRingEquiv + have hs := ((IsRegularLocalRing.iff_finrank_cotangentSpace + ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk q)).mp inferInstance) + have hl := ((IsRegularLocalRing.iff_finrank_cotangentSpace + (Localization.AtPrime q.asIdeal)).mp inferInstance) + exact_mod_cast hs.trans + ((AlgebraicGeometry.StructureSheaf.stalkIso R q).toRingEquiv.ringKrullDim.symm.trans hl.symm) + +theorem torus_stalk_cotangent_eq_codimension {K : Type*} [Field K] (n : ℕ) + (q : PrimeSpectrum (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))) : + Module.finrank (IsLocalRing.ResidueField + ((AlgebraicGeometry.Spec.structureSheaf (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))).presheaf.stalk q)) + (IsLocalRing.CotangentSpace + ((AlgebraicGeometry.Spec.structureSheaf (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))).presheaf.stalk q)) = + n - ((ringKrullDim (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)) ⧸ q.asIdeal)).unbotD 0).toNat := by + have : IsRegularLocalRing (Localization.AtPrime q.asIdeal) := + regular_localization_component (Submonoid.powers + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) q.asIdeal + rw [spec_stalk_cotangent_eq_localization, torus_component_cotangent_eq_codimension] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +attribute [local instance] spec_stalk_isLocalRing + +theorem torus_generic_stalk_cotangent_eq_codimension {K : Type*} [Field K] (n : ℕ) + (q : PrimeSpectrum (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))) + (V : Set (PrimeSpectrum (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))))) + (hV : IsGenericPoint q V) : + Module.finrank (IsLocalRing.ResidueField + ((AlgebraicGeometry.Spec.structureSheaf (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))).presheaf.stalk q)) + (IsLocalRing.CotangentSpace + ((AlgebraicGeometry.Spec.structureSheaf (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))).presheaf.stalk q)) = + n - ((topologicalKrullDim V).unbotD 0).toNat := by + rw [generic_component_topologicalKrullDim q V hV] + exact torus_stalk_cotangent_eq_codimension n q + +end WeightedTorusJets.Geometry + +open CategoryTheory _root_.AlgebraicGeometry + +namespace WeightedTorusJets.Geometry + +noncomputable def affineZeroScheme {R : Type*} [CommRing R] (I : Ideal R) : Scheme := + Spec (CommRingCat.of (R ⧸ I)) + +noncomputable def affineZeroSchemeι {R : Type*} [CommRing R] (I : Ideal R) : + affineZeroScheme I ⟶ Spec (CommRingCat.of R) := + Spec.map (CommRingCat.ofHom (Ideal.Quotient.mk I)) + +theorem affineZeroScheme_isClosedImmersion {R : Type*} [CommRing R] (I : Ideal R) : + IsClosedImmersion (affineZeroSchemeι I) := + IsClosedImmersion.spec_of_surjective _ Ideal.Quotient.mk_surjective + +noncomputable def quotientLocalizationEquiv {R : Type*} [CommRing R] + (I : Ideal R) (q : PrimeSpectrum (R ⧸ I)) : + Localization.AtPrime q.asIdeal ≃ₐ[R ⧸ I] + (Localization.AtPrime (q.asIdeal.comap (Ideal.Quotient.mk I)) ⧸ + I.map (algebraMap R (Localization.AtPrime (q.asIdeal.comap (Ideal.Quotient.mk I))))) := by + have : IsLocalization q.asIdeal.primeCompl + (Localization.AtPrime (q.asIdeal.comap (Ideal.Quotient.mk I)) ⧸ + I.map (algebraMap R (Localization.AtPrime (q.asIdeal.comap (Ideal.Quotient.mk I))))) := by + rw [← Ideal.map_primeCompl_comap_of_surjective (Ideal.Quotient.mk I) + Ideal.Quotient.mk_surjective q.asIdeal] + exact IsLocalization.of_surjective _ _ + (Ideal.Quotient.mk I) Ideal.Quotient.mk_surjective + (Ideal.Quotient.mk _) Ideal.Quotient.mk_surjective rfl (by simp) + exact IsLocalization.algEquiv q.asIdeal.primeCompl _ _ + +noncomputable def affineZeroSchemeStalkEquiv {R : Type*} [CommRing R] + (I : Ideal R) (q : PrimeSpectrum (R ⧸ I)) : + (affineZeroScheme I).presheaf.stalk q ≃+* + (Localization.AtPrime (q.asIdeal.comap (Ideal.Quotient.mk I)) ⧸ + I.map (algebraMap R (Localization.AtPrime (q.asIdeal.comap (Ideal.Quotient.mk I))))) := + (StructureSheaf.stalkIso (R ⧸ I) q).symm.toRingEquiv.trans + (quotientLocalizationEquiv I q).toRingEquiv + +theorem affineZeroScheme_range {R : Type*} [CommRing R] (I : Ideal R) : + Set.range (affineZeroSchemeι I) = PrimeSpectrum.zeroLocus (R := R) I := by + change Set.range (PrimeSpectrum.comap (Ideal.Quotient.mk I)) = _ + simpa only [Ideal.mk_ker] using + range_comap_of_surjective (R ⧸ I) (Ideal.Quotient.mk I) + Ideal.Quotient.mk_surjective + +noncomputable def affineZeroSchemePoint {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + PrimeSpectrum (R ⧸ I) := + I.primeSpectrumQuotientOrderIsoZeroLocus.symm ⟨p, hp⟩ + +theorem affineZeroSchemePoint_comap {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + (affineZeroSchemePoint I p hp).asIdeal.comap (Ideal.Quotient.mk I) = p.asIdeal := + congrArg (fun q : PrimeSpectrum.zeroLocus (R := R) I => q.1.asIdeal) + (I.primeSpectrumQuotientOrderIsoZeroLocus.apply_symm_apply ⟨p, hp⟩) + +theorem affineZeroSchemePoint_image {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + affineZeroSchemeι I (affineZeroSchemePoint I p hp) = p := + PrimeSpectrum.ext (affineZeroSchemePoint_comap I p hp) + +noncomputable def affineZeroSchemeStalkEquivAt {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + (affineZeroScheme I).presheaf.stalk (affineZeroSchemePoint I p hp) ≃+* + (Localization.AtPrime p.asIdeal ⧸ I.map (algebraMap R (Localization.AtPrime p.asIdeal))) := by + have e := affineZeroSchemeStalkEquiv I (affineZeroSchemePoint I p hp) + change _ ≃+* (Localization.AtPrime + (PrimeSpectrum.comap (Ideal.Quotient.mk I) (affineZeroSchemePoint I p hp)).asIdeal ⧸ + I.map (algebraMap R (Localization.AtPrime + (PrimeSpectrum.comap (Ideal.Quotient.mk I) (affineZeroSchemePoint I p hp)).asIdeal))) at e + have h : PrimeSpectrum.comap (Ideal.Quotient.mk I) (affineZeroSchemePoint I p hp) = p := + PrimeSpectrum.ext (affineZeroSchemePoint_comap I p hp) + rw [h] at e + exact e + +theorem ringEquiv_self_length {R S : Type*} [CommRing R] [CommRing S] + (e : R ≃+* S) : Module.length R R = Module.length S S := by + let : Algebra R S := e.toRingHom.toAlgebra + exact (LinearEquiv.ofBijective (Algebra.linearMap R S) e.bijective).length_eq.trans + (Module.length_eq_of_surjective (M := S) e.surjective) + +theorem affineZeroSchemeStalk_length {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + Module.length ((affineZeroScheme I).presheaf.stalk (affineZeroSchemePoint I p hp)) + ((affineZeroScheme I).presheaf.stalk (affineZeroSchemePoint I p hp)) = + Module.length (Localization.AtPrime p.asIdeal) + (Localization.AtPrime p.asIdeal ⧸ I.map (algebraMap R (Localization.AtPrime p.asIdeal))) := + (ringEquiv_self_length (affineZeroSchemeStalkEquivAt I p hp)).trans + (Module.length_eq_of_surjective (M := Localization.AtPrime p.asIdeal ⧸ + I.map (algebraMap R (Localization.AtPrime p.asIdeal))) + Ideal.Quotient.mk_surjective).symm + + + +noncomputable def affineZeroSchemeInclusion {R : Type*} [CommRing R] + (I J : Ideal R) (hIJ : I ≤ J) : affineZeroScheme J ⟶ affineZeroScheme I := + Spec.map (CommRingCat.ofHom (Ideal.Quotient.factor hIJ)) + +theorem affineZeroSchemeInclusion_isClosedImmersion {R : Type*} [CommRing R] + (I J : Ideal R) (hIJ : I ≤ J) : IsClosedImmersion (affineZeroSchemeInclusion I J hIJ) := + IsClosedImmersion.spec_of_surjective _ (Ideal.Quotient.factor_surjective hIJ) + +theorem affineZeroSchemeInclusion_comp_ι {R : Type*} [CommRing R] + (I J : Ideal R) (hIJ : I ≤ J) : + affineZeroSchemeInclusion I J hIJ ≫ affineZeroSchemeι I = affineZeroSchemeι J := by + unfold affineZeroSchemeInclusion affineZeroSchemeι affineZeroScheme + rw [← Spec.map_comp] + congr 1 + +theorem affineZeroSchemeInclusion_comp {R : Type*} [CommRing R] + (I J L : Ideal R) (hIJ : I ≤ J) (hJL : J ≤ L) : + affineZeroSchemeInclusion J L hJL ≫ affineZeroSchemeInclusion I J hIJ = + affineZeroSchemeInclusion I L (hIJ.trans hJL) := by + unfold affineZeroSchemeInclusion affineZeroScheme + rw [← Spec.map_comp] + congr 1 + exact CommRingCat.hom_ext (Ideal.Quotient.factor_comp hIJ hJL) + + + +theorem affineZeroSchemePoint_isMinimalPrime {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I.IsMinimalPrime p.asIdeal) : + (⊥ : Ideal (R ⧸ I)).IsMinimalPrime (affineZeroSchemePoint I p hp.le).asIdeal := by + change _ ∈ minimalPrimes (R ⧸ I) + rw [← (Ideal.comap_injective_of_surjective (Ideal.Quotient.mk I) + Ideal.Quotient.mk_surjective).mem_set_image, + ← Ideal.minimalPrimes_eq_comap, affineZeroSchemePoint_comap] + exact hp + +theorem affineZeroSchemePoint_isGenericPoint_component {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I.IsMinimalPrime p.asIdeal) : + ∃ V : Set (affineZeroScheme I), + IsGenericPoint (affineZeroSchemePoint I p hp.le) V ∧ Maximal IsIrreducible V := by + let q := affineZeroSchemePoint I p hp.le + refine ⟨PrimeSpectrum.zeroLocus (q.asIdeal : Set (R ⧸ I)), + prime_genericPoint_zeroLocus q, ?_⟩ + have h := zeroLocus_maximal_of_isMinimalPrime (⊥ : Ideal (R ⧸ I)) q + (affineZeroSchemePoint_isMinimalPrime I p hp) + change Maximal (fun V : Set (PrimeSpectrum (R ⧸ I)) => IsIrreducible V) _ + simpa only [PrimeSpectrum.zeroLocus_bot, Set.subset_univ, and_true] using h + +theorem affineZeroSchemePoint_zeroLocus_image {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + affineZeroSchemeι I '' + PrimeSpectrum.zeroLocus ((affineZeroSchemePoint I p hp).asIdeal : Set (R ⧸ I)) = + PrimeSpectrum.zeroLocus (p.asIdeal : Set R) := by + change PrimeSpectrum.comap (Ideal.Quotient.mk I) '' _ = _ + rw [image_comap_zeroLocus_eq_zeroLocus_comap (R ⧸ I) (Ideal.Quotient.mk I) + Ideal.Quotient.mk_surjective, affineZeroSchemePoint_comap] + + + + +variable {K : Type*} [Field K] + +local notation "Poly" => MvPolynomial (Fin 4) K +local notation "Torus" => Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : Poly)) + +noncomputable def torusJetZeroScheme (c : Fin 3 → Fin 4 → K) (F : Poly) + (t : Fin 3 → ℕ) (b : ℕ) : Scheme := + affineZeroScheme (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b) + +theorem torusJetZeroScheme_isClosedImmersion (c : Fin 3 → Fin 4 → K) (F : Poly) + (t : Fin 3 → ℕ) (b : ℕ) : + IsClosedImmersion (affineZeroSchemeι + (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b)) := + affineZeroScheme_isClosedImmersion _ + +noncomputable def torusJetZeroSchemeStalkEquiv (c : Fin 3 → Fin 4 → K) (F : Poly) + (t : Fin 3 → ℕ) (b : ℕ) (q : PrimeSpectrum Torus) + (hq : rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b ≤ q.asIdeal) : + (torusJetZeroScheme c F t b).presheaf.stalk + (affineZeroSchemePoint + (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b) q hq) ≃+* + (Localization.AtPrime q.asIdeal ⧸ + (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b).map + (algebraMap Torus (Localization.AtPrime q.asIdeal))) := + affineZeroSchemeStalkEquivAt _ q hq + +theorem torusJetZeroSchemeStalk_length (c : Fin 3 → Fin 4 → K) (F : Poly) + (t : Fin 3 → ℕ) (b : ℕ) (q : PrimeSpectrum Torus) + (hq : rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b ≤ q.asIdeal) : + let Z := torusJetZeroScheme c F t b + let η := affineZeroSchemePoint + (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b) q hq + Module.length (Z.presheaf.stalk η) (Z.presheaf.stalk η) = + Module.length (Localization.AtPrime q.asIdeal) + (Localization.AtPrime q.asIdeal ⧸ + (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b).map + (algebraMap Torus (Localization.AtPrime q.asIdeal))) := + affineZeroSchemeStalk_length _ q hq + +end WeightedTorusJets.Geometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/AlgebraMapMemSpanImage.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AlgebraMapMemSpanImage.lean new file mode 100644 index 0000000000000000000000000000000000000000..f540c049448546c6444cc64ddd6d2322caed7604 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AlgebraMapMemSpanImage.lean @@ -0,0 +1,52 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.FinrankSpanAlgebraMapImage + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open Module Submodule +namespace WeightedTorusJets.Geometry + +theorem algebraMap_mem_span_image_iff {K L n : Type*} [Field K] [Field L] + [Algebra K L] [Fintype n] (s : Set (n → K)) (v : n → K) : + (algebraMap K L ∘ v) ∈ span L ((fun w : n → K => algebraMap K L ∘ w) '' s) ↔ + v ∈ span K s := by + let φ := Pi.algebraMap n K L + constructor + · intro hv + have hd : finrank K (span K s) = finrank K (span K (insert v s)) := by + rw [← finrank_span_algebraMap_image (L := L) s, + ← finrank_span_algebraMap_image (L := L) (insert v s), Set.image_insert_eq, + Submodule.span_insert_eq_span hv] + have heq := Submodule.eq_of_le_of_finrank_eq + (Submodule.span_mono (Set.subset_insert v s)) hd + rw [heq] + exact Submodule.subset_span (Set.mem_insert v s) + · intro hv + exact Submodule.span_subset_span K L (φ '' s) + (Submodule.apply_mem_span_image_of_mem_span φ hv) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +theorem greedyPivots_algebraMap {K L n : Type*} [Field K] [Field L] + [Algebra K L] [Fintype n] (v : ℕ → n → K) (T : ℕ) : + greedyPivots L (fun i => algebraMap K L ∘ v i) T = greedyPivots K v T := by + ext i + rw [mem_greedyPivots_iff, mem_greedyPivots_iff] + have h := Geometry.algebraMap_mem_span_image_iff (L := L) + (v '' (Finset.range i : Set ℕ)) (v i) + simpa only [Set.image_image, Function.comp_def] using and_congr_right (fun _ => not_congr h) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ArithFrobIntegerGlobalCongruence.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ArithFrobIntegerGlobalCongruence.lean new file mode 100644 index 0000000000000000000000000000000000000000..4674239ab1b27b9ea19849ca2f04ce9273b2e5d8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ArithFrobIntegerGlobalCongruence.lean @@ -0,0 +1,56 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped NumberField + +namespace WeightedTorusJets + +theorem isArithFrobAt_of_integer_global_congruence + {K : Type*} [Field K] [NumberField K] + (p : ℕ) (σ : K ≃ₐ[ℚ] K) + (h : ∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) + (Q : Ideal (𝓞 K)) [Q.LiesOver (Ideal.span {(p : ℤ)})] : + IsArithFrobAt ℤ σ Q := by + intro x + change σ • x - x ^ Nat.card (ℤ ⧸ Q.under ℤ) ∈ Q + rw [← Q.over_def (Ideal.span {(p : ℤ)}), Int.card_ideal_quot] + have hp : (p : 𝓞 K) ∈ Q := by + have hle := Ideal.map_le_iff_le_comap.mpr + (show Ideal.span {(p : ℤ)} ≤ Q.under ℤ from (Q.over_def _).le) + apply hle + rw [Ideal.map_span, Set.image_singleton, map_natCast] + exact Ideal.subset_span (by simp) + simpa only [neg_sub] using Q.neg_mem (Q.mem_of_dvd (h x) hp) + +theorem exists_source_frobenius_of_global_choice + {K : Type*} [Field K] [NumberField K] + (p : ℕ) (σ τ : K ≃ₐ[ℚ] K) + (h : (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - (σ * τ) • x)) : + ∃ φ : K ≃ₐ[ℚ] K, (φ = σ ∨ φ = σ * τ) ∧ + (∀ (Q : Ideal (𝓞 K)) (_ : Q.IsPrime), + Q.LiesOver (Ideal.span {(p : ℤ)}) → IsArithFrobAt ℤ φ Q) ∧ + ∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - φ • x := by + rcases h with h | h + · refine ⟨σ, Or.inl rfl, ?_, h⟩ + intro Q _ hQ + let : Q.LiesOver (Ideal.span {(p : ℤ)}) := hQ + exact isArithFrobAt_of_integer_global_congruence p σ h Q + · refine ⟨σ * τ, Or.inr rfl, ?_, h⟩ + intro Q _ hQ + let : Q.LiesOver (Ideal.span {(p : ℤ)}) := hQ + exact isArithFrobAt_of_integer_global_congruence p (σ * τ) h Q + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/AuxiliarySqrtPairCharacterField.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AuxiliarySqrtPairCharacterField.lean new file mode 100644 index 0000000000000000000000000000000000000000..0363a0673b59ebd4fe4dcbcdb1e109cf53f6387e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/AuxiliarySqrtPairCharacterField.lean @@ -0,0 +1,117 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.SqrtPairFrobeniusDirections +import OAI.NumberTheory.Jacobsthal.Siegel.SumLogDivFilterDvdTwoMul + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +open scoped BigOperators + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem exists_auxiliary_sqrt_pair_with_characterField (q : ℕ) [NeZero q] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {8 * q} ℚ L] + [NeZero (8 * q)] [IsAbelianGalois ℚ L] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + (hne : χ ≠ 1) (hq8 : q ≠ 8) : + ∃ (d : ℤ) (a b : L), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : L) ∧ b ^ 2 = 2 ∧ + IsIntegral ℤ a ∧ IsIntegral ℤ b ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + IntermediateField.adjoin ℚ {a} ≠ IntermediateField.adjoin ℚ {b} ∧ + ∀ (p : ℕ), p.Prime → ¬ p ∣ 2 * q → + ∀ (P : Ideal (𝓞 L)), P.under ℤ = Ideal.span {(p : ℤ)} → + ∀ (σ : Gal(L/ℚ)), IsArithFrobAt ℤ σ P → χ p = -1 → σ a = -a := by + have hqm : q ∣ 8 * q := dvd_mul_left q 8 + have h8m : 8 ∣ 8 * q := dvd_mul_right 8 q + let K := cyclotomicDivisorField q (8 * q) L + let : IsCyclotomicExtension {q} ℚ K := + cyclotomicDivisorField_isCyclotomicExtension q (8 * q) L hqm + let : IsAbelianGalois ℚ K := IsCyclotomicExtension.isAbelianGalois {q} ℚ K + obtain ⟨d, aK, hd, hbound, hddiv, hdns, haK, _, hadjK, hsign⟩ := + exists_squarefree_generator_frobenius_sign q (8 * q) K L hqm χ hχ hprim hne + let a : L := algebraMap K L aK + have ha : a ^ 2 = (d : L) := by + change (algebraMap K L aK) ^ 2 = _ + rw [← map_pow, haK, map_intCast] + let ζ : L := zeta (8 * q) ℚ L ^ ((8 * q) / 8) + have hζ : IsPrimitiveRoot ζ 8 := + (zeta_spec (8 * q) ℚ L).pow (NeZero.pos (8 * q)) (Nat.div_mul_cancel h8m).symm + let b := ζ - ζ ^ 3 + have hb : b ^ 2 = 2 := primitive_eighth_root_difference_sq hζ + have hadj : IntermediateField.adjoin ℚ {a} = + characterField (8 * q) L ℂ (DirichletCharacter.changeLevel hqm χ) := by + rw [characterField_changeLevel q K ℂ L hqm χ hχ, ← hadjK, + IntermediateField.adjoin_map, Set.image_singleton] + rfl + have hneq : IntermediateField.adjoin ℚ {a} ≠ IntermediateField.adjoin ℚ {b} := by + intro heq + apply hq8 + exact primitive_level_eq_eight_of_lifted_sqrt_two_field hqm h8m χ hprim hχ b hb + (hadj.symm.trans heq) + refine ⟨d, a, b, hd, hbound, hddiv, hdns, ha, hb, ?_, ?_, hadj, hneq, ?_⟩ + · apply IsIntegral.of_pow (by decide : 0 < 2) + rw [ha] + exact isIntegral_algebraMap + · apply IsIntegral.of_pow (by decide : 0 < 2) + rw [hb] + exact isIntegral_natCast 2 + · intro p hp hpn P hP σ hσ hχp + have hc : p.Coprime (2 * q) := hp.coprime_iff_not_dvd.mpr hpn + have h2 := (Nat.coprime_mul_iff_right.mp hc).1 + have hq := (Nat.coprime_mul_iff_right.mp hc).2 + have h8 : p.Coprime 8 := by simpa using h2.pow_right 3 + exact hsign p hp (h8.mul_right hq) P hP σ hσ hχp + +end WeightedTorusJets + +open scoped Pointwise + + + +open scoped NumberField + + + +open scoped NumberField + + + + + + + + + + + + + + + +open scoped NumberField + + + + + + + + + + + + + + + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticArithmeticFull.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticArithmeticFull.lean new file mode 100644 index 0000000000000000000000000000000000000000..c94181021d95ac934d1e0befe0891c1cdd8f19ed --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticArithmeticFull.lean @@ -0,0 +1,468 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.AuxiliarySqrtPairCharacterField +import OAI.NumberTheory.Jacobsthal.Siegel.SqrtTwoField + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension + + + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + + + +open NumberField + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField + +theorem source_biquadratic_arithmetic_full (q : ℕ) [NeZero q] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {8 * q} ℚ L] + [NeZero (8 * q)] [IsAbelianGalois ℚ L] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) (hq8 : q ≠ 8) : + ∃ (d : ℤ) (a b : L), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : L) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ (p : ℕ), p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x)) := by + have hquad := real_character_isQuadratic χ hreal + obtain ⟨d, a, b, hd, hbound, hddiv, hdns, ha, hb, _, _, hadj, hfields, hsign⟩ := + exists_auxiliary_sqrt_pair_with_characterField q L χ hquad hprim hne hq8 + have haRat : a ^ 2 = algebraMap ℚ L (d : ℚ) := by simpa using ha + have hbRat : b ^ 2 = algebraMap ℚ L (2 : ℚ) := by simpa using hb + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let v := sqrtPairBasis a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields + have hv (i : Fin 4) : v i = ![1, a', b', a' * b'] i := by + apply Subtype.ext + change (sqrtPairBasis a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields i : L) = _ + rw [coe_sqrtPairBasis_apply] + fin_cases i <;> rfl + have ha' : a' ^ 2 = (d : B) := by apply Subtype.ext; exact ha + have hb' : b' ^ 2 = (2 : B) := by apply Subtype.ext; exact hb + have hint := biquadratic_monomials_integral a' b' d 2 ha' (by simpa using hb') + obtain ⟨σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hdesc⟩ := + sqrtPair_frobenius_directions a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields + obtain ⟨hformula, hfund, _⟩ := quadraticAdjoin_discriminant a d ha hd hdns + refine ⟨d, a, b, hd, hbound, hddiv, hdns, ha, hb, hadj, ?_, hfund, hformula, v, hv, ?_, ?_, + σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + · rw [hadj] + exact characterField_changeLevel_discr_natAbs (dvd_mul_left q 8) χ hquad hprim hne + · intro i + rw [hv] + fin_cases i + · exact hint.1 + · exact hint.2.1 + · exact hint.2.2.1 + · exact hint.2.2.2 + · exact finrank_adjoin_pair_sqrt a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields + · intro p hp hpn hχp + let : Fact p.Prime := ⟨hp⟩ + let : NeZero (8 * q) := ⟨Nat.mul_ne_zero (by decide) (NeZero.ne q)⟩ + have hc : p.Coprime (2 * q) := hp.coprime_iff_not_dvd.mpr hpn + have h2 := (Nat.coprime_mul_iff_right.mp hc).1 + have hq := (Nat.coprime_mul_iff_right.mp hc).2 + have h8 : p.Coprime 8 := by simpa using h2.pow_right 3 + have hpm : ¬ p ∣ 8 * q := hp.coprime_iff_not_dvd.mp (h8.mul_right hq) + obtain ⟨φ, hfrob, hglobal⟩ := exists_cyclotomic_frobenius_congruence (8 * q) L p hpm + obtain ⟨P, hP, hover⟩ := Ideal.exists_maximal_ideal_liesOver_of_isIntegral + (S := 𝓞 L) (Ideal.span {(p : ℤ)}) + exact hdesc p φ (hsign p hp hpn P hover.over.symm φ (hfrob P inferInstance hover) hχp) hglobal + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_biquadratic_arithmetic_canonical_full (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) (hq8 : q ≠ 8) : + let L := CyclotomicField (8 * q) ℚ + ∃ (d : ℤ) (a b : L), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : L) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ (p : ℕ), p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x)) := by + exact source_biquadratic_arithmetic_full q (CyclotomicField (8 * q) ℚ) + χ hreal hprim hne hq8 + + + +open IsCyclotomicExtension IsCyclotomicExtension.Rat + + + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + + + +open NumberField + + + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem exists_lower_triangular_replacement + {K ι : Type*} [CommRing K] [Fintype ι] [DecidableEq ι] [LinearOrder ι] + (A B : Matrix ι ι K) + (hspan : ∀ i, B i - A i ∈ Submodule.span K (A '' {j | j < i})) : + ∃ L : Matrix ι ι K, L.IsLowerTriangular ∧ (∀ i, L i i = 1) ∧ B = L * A := by + classical + have hcoeff (i : ι) : ∃ c : ι → K, + ∑ j ∈ Finset.univ.filter (fun j => j < i), c j • A j = B i - A i := by + apply (Submodule.mem_span_image_finset_iff_exists_fun' K).mp + simpa using hspan i + choose c hc using hcoeff + refine ⟨Matrix.of (fun i j => + (if j < i then c i j else 0) + (if i = j then 1 else 0)), + ?_, ?_, ?_⟩ + · intro i j hij + change i < j at hij + simp [not_lt_of_ge hij.le, hij.ne] + · intro i + simp + · apply Matrix.ext + intro i k + have hi := congrFun (hc i) k + simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.sub_apply] at hi + simpa only [Matrix.mul_apply, Matrix.of_apply, add_mul, Finset.sum_add_distrib, + ite_mul, zero_mul, one_mul, Finset.sum_ite_eq, Finset.mem_univ, ite_true, + Finset.sum_filter] using (eq_sub_iff_add_eq.mp hi).symm + +theorem determinant_dvd_of_earlier_row_replacement + {R K ι : Type*} [CommRing R] [CommRing K] [Fintype ι] [DecidableEq ι] + [LinearOrder ι] (f : R →+* K) (hf : Function.Injective f) + (A B : Matrix ι ι R) + (hspan : ∀ i, f.mapMatrix B i - f.mapMatrix A i ∈ + Submodule.span K (f.mapMatrix A '' {j | j < i})) + (p : R) (e : ι → ℕ) (hdiv : ∀ i j, p ^ e i ∣ B i j) : + p ^ (∑ i, e i) ∣ A.det := by + classical + obtain ⟨L, hL, hdiag, hreplace⟩ := + exists_lower_triangular_replacement (f.mapMatrix A) (f.mapMatrix B) hspan + have hdet : B.det = A.det := hf <| by + rw [f.map_det, f.map_det, hreplace, Matrix.det_mul, + Matrix.det_of_isLowerTriangular L hL] + simp [hdiag] + choose C hC using hdiv + have hB : B = Matrix.of (fun i j => p ^ e i * (Matrix.of C) i j) := by + ext i j + exact hC i j + rw [← hdet, hB, Matrix.det_mul_column (fun i => p ^ e i) (Matrix.of C), + Finset.prod_pow_eq_pow_sum] + exact dvd_mul_right _ _ + +theorem replacement_row_expansion {K ι : Type*} [CommRing K] + (x y z : ι → K) (p k r b c : ℕ) : + x ^ r * (x ^ p - y) ^ k * y ^ b * z ^ c = + ∑ m ∈ Finset.range (k + 1), + (((-1) ^ m * (k.choose m : K)) • + (x ^ (p * (k - m) + r) * y ^ (b + m) * z ^ c)) := by + rw [sub_eq_add_neg, add_comm (x ^ p), add_pow] + simp only [Finset.mul_sum, Finset.sum_mul] + apply Finset.sum_congr rfl + intro m hm + ext i + simp only [Pi.smul_apply, smul_eq_mul, Pi.mul_apply, Pi.pow_apply, Pi.neg_apply, + Pi.natCast_apply, pow_add, pow_mul] + rw [neg_pow] + ring + +theorem replacement_row_sub_mem {K ι : Type*} [CommRing K] + (x y z : ι → K) (W : Submodule K (ι → K)) (H p k r b c : ℕ) (hp : H < p) + (hspan : ∀ a b' c', a + H * b' + H * c' < p * k + r + H * b + H * c → + x ^ a * y ^ b' * z ^ c' ∈ W) : + x ^ r * (x ^ p - y) ^ k * y ^ b * z ^ c - + x ^ (p * k + r) * y ^ b * z ^ c ∈ W := by + rw [replacement_row_expansion, Finset.sum_range_succ'] + simp only [pow_zero, Nat.choose_zero_right, Nat.cast_one, mul_one, one_smul, + Nat.sub_zero, Nat.add_zero, add_sub_cancel_right] + apply W.sum_mem + intro m hm + apply W.smul_mem + apply hspan + have hmle : m + 1 ≤ k := Nat.succ_le_of_lt (Finset.mem_range.mp hm) + have hprod : H * (m + 1) < p * (m + 1) := + Nat.mul_lt_mul_of_pos_right hp (Nat.succ_pos m) + have hdecomp : p * k = p * (k - (m + 1)) + p * (m + 1) := by + rw [← Nat.mul_add, Nat.sub_add_cancel hmle] + simp only [Nat.mul_add, Nat.mul_one] at hprod hdecomp ⊢ + omega + +theorem weighted_interpolation_determinant_dvd + {R K ι : Type*} [CommRing R] [CommRing K] [Fintype ι] [DecidableEq ι] + [LinearOrder ι] (f : R →+* K) (hf : Function.Injective f) + (x y z : ι → R) (a b c : ι → ℕ) (A : Matrix ι ι R) + (hA : ∀ i n, A i n = x n ^ a i * y n ^ b i * z n ^ c i) + (H p : ℕ) (hp : H < p) + (hspan : ∀ i a' b' c', a' + H * b' + H * c' < a i + H * b i + H * c i → + (f ∘ x) ^ a' * (f ∘ y) ^ b' * (f ∘ z) ^ c' ∈ + Submodule.span K (f.mapMatrix A '' {j | j < i})) + (hFrob : ∀ n, (p : R) ∣ x n ^ p - y n) : + (p : R) ^ (∑ i, a i / p) ∣ A.det := by + classical + let B : Matrix ι ι R := Matrix.of fun i n => + x n ^ (a i % p) * (x n ^ p - y n) ^ (a i / p) * y n ^ b i * z n ^ c i + apply determinant_dvd_of_earlier_row_replacement f hf A B + · intro i + have h := replacement_row_sub_mem (f ∘ x) (f ∘ y) (f ∘ z) + (Submodule.span K (f.mapMatrix A '' {j | j < i})) + H p (a i / p) (a i % p) (b i) (c i) hp (by + intro a' b' c' hw + apply hspan i a' b' c' + simpa only [Nat.div_add_mod] using hw) + have heq : f.mapMatrix B i - f.mapMatrix A i = + (f ∘ x) ^ (a i % p) * ((f ∘ x) ^ p - f ∘ y) ^ (a i / p) * + (f ∘ y) ^ b i * (f ∘ z) ^ c i - + (f ∘ x) ^ a i * (f ∘ y) ^ b i * (f ∘ z) ^ c i := by + ext n + simp [B, hA, map_mul, map_pow, map_sub] + rw [heq] + simpa only [Nat.div_add_mod] using h + · intro i n + exact (((pow_dvd_pow_of_dvd (hFrob n) (a i / p)).mul_left + (x n ^ (a i % p))).mul_right (y n ^ b i)).mul_right (z n ^ c i) + +theorem weighted_interpolation_determinant_dvd_of_frobenius_choice + {R K ι : Type*} [CommRing R] [CommRing K] [Fintype ι] [DecidableEq ι] + [LinearOrder ι] (f : R →+* K) (hf : Function.Injective f) + (x y z : ι → R) (a b c : ι → ℕ) (A : Matrix ι ι R) + (hA : ∀ i n, A i n = x n ^ a i * y n ^ b i * z n ^ c i) + (H p : ℕ) (hp : H < p) + (hspan : ∀ i a' b' c', a' + H * b' + H * c' < a i + H * b i + H * c i → + (f ∘ x) ^ a' * (f ∘ y) ^ b' * (f ∘ z) ^ c' ∈ + Submodule.span K (f.mapMatrix A '' {j | j < i})) + (hFrob : (∀ n, (p : R) ∣ x n ^ p - y n) ∨ + (∀ n, (p : R) ∣ x n ^ p - z n)) : + (p : R) ^ (∑ i, a i / p) ∣ A.det := by + rcases hFrob with hFrob | hFrob + · exact weighted_interpolation_determinant_dvd f hf x y z a b c A hA H p hp + hspan hFrob + · apply weighted_interpolation_determinant_dvd f hf x z y a c b A + (fun i n => by rw [hA]; ring) H p hp _ hFrob + intro i a' c' b' hw + have h := hspan i a' b' c' (by omega) + convert h using 1 + ring + +open NumberField + +theorem galois_derivative_determinant_mem_prime_power + {K ι : Type*} [Field K] [Fintype ι] [DecidableEq ι] + [LinearOrder ι] (θ : ι → 𝓞 K) (ν₂ ν₃ : K →+* K) (a b c : ι → ℕ) + (H p : ℕ) (hp : H < p) + (hspan : ∀ i a' b' c', a' + H * b' + H * c' < a i + H * b i + H * c i → + (fun n => (θ n : K) ^ a' * ν₂ (θ n) ^ b' * ν₃ (θ n) ^ c') ∈ + Submodule.span K ((fun i n => + (θ n : K) ^ a i * ν₂ (θ n) ^ b i * ν₃ (θ n) ^ c i) '' {j | j < i})) + (hFrob : (∀ n, Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (θ n ^ p) = + Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (RingOfIntegers.mapRingHom ν₂ (θ n))) ∨ + (∀ n, Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (θ n ^ p) = + Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (RingOfIntegers.mapRingHom ν₃ (θ n)))) : + (Matrix.of (fun i n => θ n ^ a i * (RingOfIntegers.mapRingHom ν₂ (θ n)) ^ b i * + (RingOfIntegers.mapRingHom ν₃ (θ n)) ^ c i)).det ∈ + (Ideal.span {(p : 𝓞 K)}) ^ (∑ i, a i / p) := by + rw [Ideal.span_singleton_pow, Ideal.mem_span_singleton] + apply weighted_interpolation_determinant_dvd_of_frobenius_choice (algebraMap (𝓞 K) K) + RingOfIntegers.coe_injective θ + ((RingOfIntegers.mapRingHom ν₂) ∘ θ) ((RingOfIntegers.mapRingHom ν₃) ∘ θ) + a b c _ (fun _ _ => rfl) H p hp + · intro i a' b' c' hw + convert hspan i a' b' c' hw using 1 + · apply congrArg (Submodule.span K) + apply congrArg (fun f : ι → ι → K => f '' {j | j < i}) + ext j n + change algebraMap (𝓞 K) K (_ * _ * _) = _ + simp + · funext n + rfl + · rcases hFrob with hFrob | hFrob + · exact Or.inl fun n => Ideal.mem_span_singleton.mp + ((Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mp (hFrob n)) + · exact Or.inr fun n => Ideal.mem_span_singleton.mp + ((Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mp (hFrob n)) + +theorem integral_jet_matrix_lift {K : Type*} [Field K] + (σ τ : K →+* K) {a b : K} {d : ℤ} {m : ℕ} + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (n : Fin m → Fin 4 → ℕ) (α : Fin m → Fin 3 → ℕ) : + let θ := fun j => ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i + let A := Matrix.of fun i j => θ j ^ α i 0 * σ (θ j) ^ α i 1 * + (σ.comp τ) (θ j) ^ α i 2 + ∃ θ₀ : Fin m → 𝓞 K, + (∀ j, (θ₀ j : K) = θ j) ∧ + let A₀ := Matrix.of fun i j => θ₀ j ^ α i 0 * + NumberField.RingOfIntegers.mapRingHom σ (θ₀ j) ^ α i 1 * + NumberField.RingOfIntegers.mapRingHom (σ.comp τ) (θ₀ j) ^ α i 2 + A₀.map (algebraMap (𝓞 K) K) = A ∧ + (A₀.det : K) = A.det ∧ (A.det ≠ 0 → A₀.det ≠ 0) := by + let θ := fun j => ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i + obtain ⟨h1, hai, hbi, hab⟩ := + biquadratic_monomials_integral a b d 2 ha (by simpa using hb) + have hθ (j : Fin m) : IsIntegral ℤ (θ j) := by + apply IsIntegral.sum + intro i _ + apply (isIntegral_natCast _).mul + fin_cases i <;> assumption + let θ₀ : Fin m → 𝓞 K := fun j => ⟨θ j, hθ j⟩ + refine ⟨θ₀, fun _ => rfl, ?_⟩ + dsimp only + have hmap : + (Matrix.of fun i j => θ₀ j ^ α i 0 * + NumberField.RingOfIntegers.mapRingHom σ (θ₀ j) ^ α i 1 * + NumberField.RingOfIntegers.mapRingHom (σ.comp τ) (θ₀ j) ^ α i 2).map + (algebraMap (𝓞 K) K) = + Matrix.of fun i j => θ j ^ α i 0 * σ (θ j) ^ α i 1 * + (σ.comp τ) (θ j) ^ α i 2 := by + ext i j + change algebraMap (𝓞 K) K (_ * _ * _) = _ + simp only [map_mul, map_pow] + rfl + refine ⟨hmap, ?_⟩ + have hdet := congrArg Matrix.det hmap + rw [← RingHom.mapMatrix_apply, ← RingHom.map_det] at hdet + exact ⟨hdet, fun h => NumberField.RingOfIntegers.coe_ne_zero_iff.mp (hdet.symm ▸ h)⟩ + +theorem exists_integral_jet_determinant_divisible + {K : Type*} [Field K] + (σ τ : K →+* K) {a b : K} {d : ℤ} {m : ℕ} + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (n : Fin m → Fin 4 → ℕ) (α : Fin m → Fin 3 → ℕ) (H : ℕ) : + let θ := fun j => ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i + let A := Matrix.of fun i j => θ j ^ α i 0 * σ (θ j) ^ α i 1 * + (σ.comp τ) (θ j) ^ α i 2 + (∀ i a' b' c', a' + H * b' + H * c' < α i 0 + H * α i 1 + H * α i 2 → + (fun j => θ j ^ a' * σ (θ j) ^ b' * (σ.comp τ) (θ j) ^ c') ∈ + Submodule.span K (A '' {j | j < i})) → + A.det ≠ 0 → + ∃ Δ : 𝓞 K, (Δ : K) = A.det ∧ Δ ≠ 0 ∧ + ∀ p : ℕ, H < p → + ((∀ t : 𝓞 K, Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (t ^ p) = + Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (RingOfIntegers.mapRingHom σ t)) ∨ + (∀ t : 𝓞 K, Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (t ^ p) = + Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) + (RingOfIntegers.mapRingHom (σ.comp τ) t))) → + Δ ∈ (Ideal.span {(p : 𝓞 K)}) ^ (∑ i, α i 0 / p) := by + dsimp only + intro hspan hnonzero + obtain ⟨θ₀, hθ₀, _hmap, hdet, hne⟩ := integral_jet_matrix_lift σ τ ha hb n α + refine ⟨_, hdet, hne hnonzero, ?_⟩ + intro p hp hFrob + apply galois_derivative_determinant_mem_prime_power θ₀ σ (σ.comp τ) + (fun i => α i 0) (fun i => α i 1) (fun i => α i 2) H p hp + · intro i a' b' c' hw + convert hspan i a' b' c' hw using 1 + · apply congrArg (Submodule.span K) + apply congrArg (fun f : Fin m → Fin m → K => f '' {j | j < i}) + ext k j + simp only [Matrix.of_apply, hθ₀] + · funext j + simp only [hθ₀] + · rcases hFrob with hFrob | hFrob + · exact Or.inl fun j => hFrob (θ₀ j) + · exact Or.inr fun j => hFrob (θ₀ j) + +end WeightedTorusJets + +open scoped NumberField + +namespace WeightedTorusJets + +theorem frobenius_action_choice_iff_mapRingHom + {K : Type*} [Field K] [NumberField K] (σ τ : K ≃ₐ[ℚ] K) (p : ℕ) : + ((∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - (σ * τ) • x)) ↔ + ((∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - + NumberField.RingOfIntegers.mapRingHom σ.toRingHom x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - + NumberField.RingOfIntegers.mapRingHom (σ.toRingHom.comp τ.toRingHom) x)) := by + rfl + +theorem frobenius_action_choice_quotient + {K : Type*} [Field K] [NumberField K] (σ τ : K ≃ₐ[ℚ] K) (p : ℕ) + (hFrob : (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - (σ * τ) • x)) : + ((∀ x : 𝓞 K, Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (x ^ p) = + Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) + (NumberField.RingOfIntegers.mapRingHom σ.toRingHom x)) ∨ + (∀ x : 𝓞 K, Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) (x ^ p) = + Ideal.Quotient.mk (Ideal.span {(p : 𝓞 K)}) + (NumberField.RingOfIntegers.mapRingHom (σ.toRingHom.comp τ.toRingHom) x))) := by + rcases (frobenius_action_choice_iff_mapRingHom σ τ p).mp hFrob with h | h + · exact Or.inl fun x => (Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mpr + (Ideal.mem_span_singleton.mpr (h x)) + · exact Or.inr fun x => (Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mpr + (Ideal.mem_span_singleton.mpr (h x)) + +end WeightedTorusJets + +open scoped BigOperators + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticBasis.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticBasis.lean new file mode 100644 index 0000000000000000000000000000000000000000..05f54d9e6fc1ccf5568613f804b1f0577b5530e2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticBasis.lean @@ -0,0 +1,505 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped Pointwise +namespace WeightedTorusJets + +theorem finrank_sup_quadratic {F E : Type*} [Field F] [Field E] [Algebra F E] + (K L : IntermediateField F E) (hK : Module.finrank F K = 2) + (hL : Module.finrank F L = 2) (hne : K ≠ L) : + Module.finrank F ↥(K ⊔ L) = 4 := by + have : FiniteDimensional F K := Module.finite_of_finrank_eq_succ hK + have : FiniteDimensional F L := Module.finite_of_finrank_eq_succ hL + have hle : Module.finrank F ↥(K ⊔ L) ≤ 4 := by + simpa [hK, hL] using K.finrank_sup_le L + have hdiv : 2 ∣ Module.finrank F ↥(K ⊔ L) := by + simpa [hK] using IntermediateField.finrank_dvd_of_le_right + (show K ≤ K ⊔ L from le_sup_left) + have hlt : 2 < Module.finrank F ↥(K ⊔ L) := by + by_contra hc + have hKeq : K = K ⊔ L := IntermediateField.eq_of_le_of_finrank_le le_sup_left + (by omega) + have hLK : L ≤ K := hKeq.symm ▸ le_sup_right + have hLK_eq : L = K := IntermediateField.eq_of_le_of_finrank_le hLK (by omega) + exact hne hLK_eq.symm + omega + +theorem biquadratic_monomials_integral {E : Type*} [CommRing E] [Algebra ℤ E] + (a b : E) (d e : ℤ) (ha : a ^ 2 = d) (hb : b ^ 2 = e) : + IsIntegral ℤ (1 : E) ∧ IsIntegral ℤ a ∧ IsIntegral ℤ b ∧ IsIntegral ℤ (a * b) := by + have hai : IsIntegral ℤ a := IsIntegral.of_pow (by decide : 0 < 2) + (ha ▸ isIntegral_intCast d) + have hbi : IsIntegral ℤ b := IsIntegral.of_pow (by decide : 0 < 2) + (hb ▸ isIntegral_intCast e) + exact ⟨isIntegral_one, hai, hbi, hai.mul hbi⟩ + +theorem span_pair_sqrt {F E : Type*} [Field F] [Field E] [Algebra F E] + (a : E) (d : F) (ha : a ^ 2 = algebraMap F E d) : + Submodule.span F ({1, a} : Set E) = (Algebra.adjoin F {a}).toSubmodule := by + have heval : Polynomial.aeval a (Polynomial.X ^ 2 - Polynomial.C d) = 0 := by + simpa using sub_eq_zero.mpr ha + have h := Submodule.span_range_natDegree_eq_adjoin + (Polynomial.monic_X_pow_sub_C d (by decide : 2 ≠ 0)) heval + simpa [Finset.range_add_one, Set.pair_comm] using h + +theorem span_biquadratic_monomials {F E : Type*} [Field F] [Field E] [Algebra F E] + (a b : E) (d e : F) (ha : a ^ 2 = algebraMap F E d) + (hb : b ^ 2 = algebraMap F E e) : + Submodule.span F (Set.range ![1, a, b, a * b]) = + (Algebra.adjoin F ({a, b} : Set E)).toSubmodule := by + have hsets : ({1, a} : Set E) * ({1, b} : Set E) = Set.range ![1, a, b, a * b] := by + ext x + simp only [Set.mem_mul, Matrix.range_cons, Matrix.range_empty, Set.mem_union, Set.mem_insert_iff, + Set.mem_singleton_iff, Set.mem_empty_iff_false, or_false] + aesop + rw [← hsets, ← Submodule.span_mul_span, span_pair_sqrt a d ha, + span_pair_sqrt b e hb, ← Algebra.adjoin_union_coe_submodule] + simp [Set.pair_comm] + +noncomputable def biquadraticBasis {F E : Type*} [Field F] [Field E] [Algebra F E] + (a b : E) (d e : F) (ha : a ^ 2 = algebraMap F E d) + (hb : b ^ 2 = algebraMap F E e) + (hgen : Algebra.adjoin F ({a, b} : Set E) = ⊤) + (hdim : Module.finrank F E = 4) : Module.Basis (Fin 4) F E := + have : Module.Finite F E := Module.finite_of_finrank_eq_succ hdim + basisOfTopLeSpanOfCardEqFinrank ![1, a, b, a * b] + (by rw [span_biquadratic_monomials a b d e ha hb, hgen]; rfl) + (by simpa using hdim.symm) + +@[simp] +theorem biquadraticBasis_apply {F E : Type*} [Field F] [Field E] [Algebra F E] + (a b : E) (d e : F) (ha : a ^ 2 = algebraMap F E d) + (hb : b ^ 2 = algebraMap F E e) + (hgen : Algebra.adjoin F ({a, b} : Set E) = ⊤) + (hdim : Module.finrank F E = 4) (i : Fin 4) : + biquadraticBasis a b d e ha hb hgen hdim i = ![1, a, b, a * b] i := by + simp [biquadraticBasis] + +theorem finrank_adjoin_sqrt {F E : Type*} [Field F] [Field E] [Algebra F E] + (a : E) (d : F) (ha : a ^ 2 = algebraMap F E d) (hd : ¬ IsSquare d) : + Module.finrank F (IntermediateField.adjoin F {a}) = 2 := by + have hai : IsIntegral F a := IsIntegral.of_pow (by decide : 0 < 2) + (ha ▸ isIntegral_algebraMap) + have : FiniteDimensional F (IntermediateField.adjoin F {a}) := + IntermediateField.adjoin.finiteDimensional hai + have hpos := Module.finrank_pos (R := F) (M := IntermediateField.adjoin F {a}) + have hne : Module.finrank F (IntermediateField.adjoin F {a}) ≠ 1 := by + intro hone + have hamem := IntermediateField.finrank_adjoin_simple_eq_one_iff.mp hone + obtain ⟨r, hr⟩ := (IntermediateField.mem_bot).mp hamem + apply hd + refine ⟨r, ?_⟩ + apply (algebraMap F E).injective + simpa [map_mul, hr, sq] using ha.symm + have hle : Module.finrank F (IntermediateField.adjoin F {a}) ≤ 2 := by + rw [← IntermediateField.finrank_eq_finrank_subalgebra, + IntermediateField.adjoin_simple_toSubalgebra_of_isAlgebraic hai.isAlgebraic] + change Module.finrank F (Algebra.adjoin F {a}).toSubmodule ≤ 2 + rw [← span_pair_sqrt a d ha] + have h := finrank_range_le_card (R := F) ![(1 : E), a] + change Module.finrank F (Submodule.span F (Set.range ![(1 : E), a])) ≤ 2 at h + rwa [Matrix.range_cons_cons_empty] at h + omega + +theorem adjoin_pair_generators {F E : Type*} [Field F] [Field E] [Algebra F E] + (a b : E) (d e : F) (ha : a ^ 2 = algebraMap F E d) + (hb : b ^ 2 = algebraMap F E e) : + let K := IntermediateField.adjoin F ({a, b} : Set E) + let a' : K := ⟨a, IntermediateField.subset_adjoin F _ (by simp)⟩ + let b' : K := ⟨b, IntermediateField.subset_adjoin F _ (by simp)⟩ + Algebra.adjoin F ({a', b'} : Set K) = ⊤ := by + dsimp only + let K := IntermediateField.adjoin F ({a, b} : Set E) + let a' : K := ⟨a, IntermediateField.subset_adjoin F _ (by simp)⟩ + let b' : K := ⟨b, IntermediateField.subset_adjoin F _ (by simp)⟩ + have hai : IsIntegral F a' := IsIntegral.of_pow (by decide : 0 < 2) + (by have h : a' ^ 2 = algebraMap F K d := Subtype.ext ha + rw [h]; exact isIntegral_algebraMap) + have hbi : IsIntegral F b' := IsIntegral.of_pow (by decide : 0 < 2) + (by have h : b' ^ 2 = algebraMap F K e := Subtype.ext hb + rw [h]; exact isIntegral_algebraMap) + apply Algebra.adjoin_eq_top_of_intermediateField + (by intro x hx; rcases hx with rfl | rfl + · exact hai.isAlgebraic + · exact hbi.isAlgebraic) + apply IntermediateField.map_injective K.val + simp only [IntermediateField.adjoin_map, Set.image_pair, IntermediateField.val_mk] + ext x + simp [IntermediateField.mem_map, K] + +theorem finrank_adjoin_pair_sqrt {F E : Type*} [Field F] [Field E] [Algebra F E] + (a b : E) (d e : F) (ha : a ^ 2 = algebraMap F E d) + (hb : b ^ 2 = algebraMap F E e) (hd : ¬ IsSquare d) (he : ¬ IsSquare e) + (hne : IntermediateField.adjoin F {a} ≠ IntermediateField.adjoin F {b}) : + Module.finrank F (IntermediateField.adjoin F ({a, b} : Set E)) = 4 := by + rw [← Set.singleton_union, IntermediateField.adjoin_union] + exact finrank_sup_quadratic _ _ (finrank_adjoin_sqrt a d ha hd) + (finrank_adjoin_sqrt b e hb he) hne + +noncomputable def sqrtPairBasis {F E : Type*} [Field F] [Field E] [Algebra F E] + (a b : E) (d e : F) (ha : a ^ 2 = algebraMap F E d) + (hb : b ^ 2 = algebraMap F E e) (hd : ¬ IsSquare d) (he : ¬ IsSquare e) + (hne : IntermediateField.adjoin F {a} ≠ IntermediateField.adjoin F {b}) : + Module.Basis (Fin 4) F (IntermediateField.adjoin F ({a, b} : Set E)) := + let a' := (⟨a, IntermediateField.subset_adjoin F _ (by simp)⟩ : + IntermediateField.adjoin F ({a, b} : Set E)) + let b' := (⟨b, IntermediateField.subset_adjoin F _ (by simp)⟩ : + IntermediateField.adjoin F ({a, b} : Set E)) + biquadraticBasis a' b' d e (Subtype.ext ha) (Subtype.ext hb) + (adjoin_pair_generators a b d e ha hb) + (finrank_adjoin_pair_sqrt a b d e ha hb hd he hne) + +@[simp] +theorem coe_sqrtPairBasis_apply {F E : Type*} [Field F] [Field E] [Algebra F E] + (a b : E) (d e : F) (ha : a ^ 2 = algebraMap F E d) + (hb : b ^ 2 = algebraMap F E e) (hd : ¬ IsSquare d) (he : ¬ IsSquare e) + (hne : IntermediateField.adjoin F {a} ≠ IntermediateField.adjoin F {b}) (i : Fin 4) : + (sqrtPairBasis a b d e ha hb hd he hne i : E) = ![1, a, b, a * b] i := by + fin_cases i <;> simp [sqrtPairBasis] + + + +open Module + +variable {K : Type*} [Field K] [Algebra ℚ K] + +noncomputable def biquadraticLinearMap (v : Basis (Fin 4) ℚ K) (a' b' : K) : K →ₗ[ℚ] K := + v.constr ℚ ![1, a', b', a' * b'] + +lemma biquadraticLinearMap_basis (v : Basis (Fin 4) ℚ K) (a' b' : K) (i : Fin 4) : + biquadraticLinearMap v a' b' (v i) = ![1, a', b', a' * b'] i := + v.constr_basis ℚ _ i + +lemma biquadraticLinearMap_mul (v : Basis (Fin 4) ℚ K) (a b a' b' : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) + (ha' : a' * a' = algebraMap ℚ K d) (hb' : b' * b' = algebraMap ℚ K e) : + ∀ x y, biquadraticLinearMap v a' b' (x * y) = + biquadraticLinearMap v a' b' x * biquadraticLinearMap v a' b' y := by + let f := biquadraticLinearMap v a' b' + have hf (i : Fin 4) : f (![1, a, b, a * b] i) = ![1, a', b', a' * b'] i := by + rw [← hv i] + exact biquadraticLinearMap_basis v a' b' i + have hf1 : f 1 = 1 := hf 0 + have hfa : f a = a' := hf 1 + have hfb : f b = b' := hf 2 + have hfab : f (a * b) = a' * b' := hf 3 + have hfc (c : ℚ) (x : K) : f ((algebraMap ℚ K c) * x) = (algebraMap ℚ K c) * f x := by + simpa only [Algebra.smul_def] using f.map_smul c x + have hfq (c : ℚ) : f (algebraMap ℚ K c) = algebraMap ℚ K c := by simpa [hf1] using hfc c 1 + have h1 : a * (a * b) = (algebraMap ℚ K d) * b := by rw [← mul_assoc, ha] + have h2 : b * (a * b) = (algebraMap ℚ K e) * a := by rw [mul_left_comm, hb, mul_comm] + have h3 : (a * b) * (a * b) = (algebraMap ℚ K (d * e)) := by + rw [mul_mul_mul_comm, ha, hb, map_mul] + have h1' : a' * (a' * b') = (algebraMap ℚ K d) * b' := by rw [← mul_assoc, ha'] + have h2' : b' * (a' * b') = (algebraMap ℚ K e) * a' := by rw [mul_left_comm, hb', mul_comm] + have h3' : (a' * b') * (a' * b') = (algebraMap ℚ K (d * e)) := by + rw [mul_mul_mul_comm, ha', hb', map_mul] + apply (LinearMap.map_mul_iff f).mpr + apply v.ext + intro i + apply v.ext + intro j + change f (v i * v j) = f (v i) * f (v j) + rw [hv i, hv j] + fin_cases i <;> fin_cases j <;> simp_all + all_goals simp_all [mul_comm] + +noncomputable def biquadraticSignEquiv (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) + (s t : Bool) : K ≃ₐ[ℚ] K := by + let a' := if s then -a else a + let b' := if t then -b else b + let f := biquadraticLinearMap v a' b' + have hf (i : Fin 4) : f (![1, a, b, a * b] i) = ![1, a', b', a' * b'] i := by + rw [← hv i] + exact biquadraticLinearMap_basis v a' b' i + have hf1 : f 1 = 1 := hf 0 + have hfa : f a = a' := hf 1 + have hfb : f b = b' := hf 2 + have hfab : f (a * b) = a' * b' := hf 3 + have hcomp : f.comp f = LinearMap.id := by + apply v.ext + intro i + change f (f (v i)) = v i + rw [hv i] + cases s <;> cases t <;> fin_cases i <;> simp_all [a', b'] + have hinv : Function.Involutive f := fun x => LinearMap.congr_fun hcomp x + refine AlgEquiv.ofLinearEquiv (LinearEquiv.ofInvolutive f hinv) hf1 ?_ + apply biquadraticLinearMap_mul v a b a' b' d e hv ha hb + · cases s <;> simpa [a'] using ha + · cases t <;> simpa [b'] using hb + +lemma biquadraticSignEquiv_basis (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) + (s t : Bool) (i : Fin 4) : + biquadraticSignEquiv v a b d e hv ha hb s t (v i) = + ![1, if s then -a else a, if t then -b else b, + (if s then -a else a) * (if t then -b else b)] i := + biquadraticLinearMap_basis v _ _ i + +lemma biquadratic_algEquiv_ext (v : Basis (Fin 4) ℚ K) (a b : K) + (hv : ∀ i, v i = ![1, a, b, a * b] i) (f g : K ≃ₐ[ℚ] K) + (ha : f a = g a) (hb : f b = g b) : f = g := by + apply AlgEquiv.toLinearMap_injective + apply v.ext + intro i + change f (v i) = g (v i) + rw [hv i] + fin_cases i <;> simp_all + +lemma quadratic_algEquiv_dichotomy (a : K) (d : ℚ) + (ha : a * a = algebraMap ℚ K d) (f : K ≃ₐ[ℚ] K) : + f a = a ∨ f a = -a := by + apply sq_eq_sq_iff_eq_or_eq_neg.mp + simpa only [pow_two, ← map_mul, ha] using f.commutes d + +lemma biquadratic_automorphism_eq_sign (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) + (f : K ≃ₐ[ℚ] K) : + ∃ s t : Bool, f = biquadraticSignEquiv v a b d e hv ha hb s t := by + have hs (s t : Bool) (i : Fin 4) := biquadraticSignEquiv_basis v a b d e hv ha hb s t i + simp_rw [hv] at hs + rcases quadratic_algEquiv_dichotomy a d ha f with hfa | hfa <;> + rcases quadratic_algEquiv_dichotomy b e hb f with hfb | hfb + · refine ⟨false, false, biquadratic_algEquiv_ext v a b hv f _ ?_ ?_⟩ + · exact hfa.trans (hs false false 1).symm + · exact hfb.trans (hs false false 2).symm + · refine ⟨false, true, biquadratic_algEquiv_ext v a b hv f _ ?_ ?_⟩ + · exact hfa.trans (hs false true 1).symm + · exact hfb.trans (hs false true 2).symm + · refine ⟨true, false, biquadratic_algEquiv_ext v a b hv f _ ?_ ?_⟩ + · exact hfa.trans (hs true false 1).symm + · exact hfb.trans (hs true false 2).symm + · refine ⟨true, true, biquadratic_algEquiv_ext v a b hv f _ ?_ ?_⟩ + · exact hfa.trans (hs true true 1).symm + · exact hfb.trans (hs true true 2).symm + +lemma biquadraticSignEquiv_injective (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) : + Function.Injective (fun st : Bool × Bool => + biquadraticSignEquiv v a b d e hv ha hb st.1 st.2) := by + let : CharZero K := algebraRat.charZero K + have ha0 : a ≠ 0 := by simpa [hv] using v.ne_zero 1 + have hb0 : b ≠ 0 := by simpa [hv] using v.ne_zero 2 + have hana : a ≠ -a := fun h => ha0 (CharZero.eq_neg_self_iff.mp h) + have hbna : b ≠ -b := fun h => hb0 (CharZero.eq_neg_self_iff.mp h) + have hs (s t : Bool) (i : Fin 4) := biquadraticSignEquiv_basis v a b d e hv ha hb s t i + simp_rw [hv] at hs + intro st st' h + have hA := congrArg (fun f : K ≃ₐ[ℚ] K => f a) h + have hB := congrArg (fun f : K ≃ₐ[ℚ] K => f b) h + have hsA (s t : Bool) : biquadraticSignEquiv v a b d e hv ha hb s t a = + if s then -a else a := hs s t 1 + have hsB (s t : Bool) : biquadraticSignEquiv v a b d e hv ha hb s t b = + if t then -b else b := hs s t 2 + simp only [hsA] at hA + simp only [hsB] at hB + clear hs hsA hsB h + rcases st with ⟨s, t⟩ + rcases st' with ⟨s', t'⟩ + cases s <;> cases s' <;> cases t <;> cases t' <;> simp_all + +lemma biquadratic_card_automorphisms (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) : + Nat.card (K ≃ₐ[ℚ] K) = 4 := by + let f := fun st : Bool × Bool => biquadraticSignEquiv v a b d e hv ha hb st.1 st.2 + have hf : Function.Bijective f := by + refine ⟨biquadraticSignEquiv_injective v a b d e hv ha hb, ?_⟩ + intro g + obtain ⟨s, t, h⟩ := biquadratic_automorphism_eq_sign v a b d e hv ha hb g + exact ⟨⟨s, t⟩, h.symm⟩ + simpa using (Nat.card_congr (Equiv.ofBijective f hf)).symm + +lemma biquadratic_isGalois (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) : + IsGalois ℚ K := by + let : FiniteDimensional ℚ K := Module.Finite.of_basis v + apply IsGalois.of_card_aut_eq_finrank + rw [biquadratic_card_automorphisms v a b d e hv ha hb, Module.finrank_eq_card_basis v] + rfl + +lemma biquadraticSignEquiv_mul (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) + (s t s' t' : Bool) : + biquadraticSignEquiv v a b d e hv ha hb s t * + biquadraticSignEquiv v a b d e hv ha hb s' t' = + biquadraticSignEquiv v a b d e hv ha hb (s.xor s') (t.xor t') := by + have hs (s t : Bool) (i : Fin 4) := biquadraticSignEquiv_basis v a b d e hv ha hb s t i + simp_rw [hv] at hs + have hsA (s t : Bool) : biquadraticSignEquiv v a b d e hv ha hb s t a = + if s then -a else a := hs s t 1 + have hsB (s t : Bool) : biquadraticSignEquiv v a b d e hv ha hb s t b = + if t then -b else b := hs s t 2 + apply biquadratic_algEquiv_ext v a b hv + · cases s <;> cases s' <;> simp [AlgEquiv.mul_apply, hsA] + · cases t <;> cases t' <;> simp [AlgEquiv.mul_apply, hsB] + +lemma biquadratic_automorphisms_commute (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) + (f g : K ≃ₐ[ℚ] K) : Commute f g := by + obtain ⟨s, t, rfl⟩ := biquadratic_automorphism_eq_sign v a b d e hv ha hb f + obtain ⟨s', t', rfl⟩ := biquadratic_automorphism_eq_sign v a b d e hv ha hb g + change _ = _ + simp only [biquadraticSignEquiv_mul, Bool.xor_comm] + +lemma biquadraticSignEquiv_identity (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) : + biquadraticSignEquiv v a b d e hv ha hb false false = 1 := by + have hs (i : Fin 4) := biquadraticSignEquiv_basis v a b d e hv ha hb false false i + simp_rw [hv] at hs + apply biquadratic_algEquiv_ext v a b hv + · exact hs 1 + · exact hs 2 + +lemma biquadratic_four_automorphisms (v : Basis (Fin 4) ℚ K) (a b : K) (d e : ℚ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ K e) + (f : K ≃ₐ[ℚ] K) : + let σ := biquadraticSignEquiv v a b d e hv ha hb true false + let τ := biquadraticSignEquiv v a b d e hv ha hb false true + f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ := by + dsimp + obtain ⟨s, t, rfl⟩ := biquadratic_automorphism_eq_sign v a b d e hv ha hb f + cases s <;> cases t <;> + simp [biquadraticSignEquiv_mul, biquadraticSignEquiv_identity] + +end WeightedTorusJets +namespace WeightedTorusJets + +lemma sqrtPair_isGalois {L : Type*} [Field L] [CharZero L] + (a b : L) (d e : ℚ) (ha : a ^ 2 = algebraMap ℚ L d) + (hb : b ^ 2 = algebraMap ℚ L e) (hd : ¬ IsSquare d) (he : ¬ IsSquare e) + (hne : IntermediateField.adjoin ℚ {a} ≠ IntermediateField.adjoin ℚ {b}) : + IsGalois ℚ (IntermediateField.adjoin ℚ ({a, b} : Set L)) := by + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let v := sqrtPairBasis a b d e ha hb hd he hne + have hv (i : Fin 4) : v i = ![1, a', b', a' * b'] i := by + apply Subtype.ext + change (sqrtPairBasis a b d e ha hb hd he hne i : L) = _ + rw [coe_sqrtPairBasis_apply] + fin_cases i <;> rfl + have ha' : a' * a' = algebraMap ℚ B d := by + apply Subtype.ext + simpa [a', pow_two] using ha + have hb' : b' * b' = algebraMap ℚ B e := by + apply Subtype.ext + simpa [b', pow_two] using hb + exact biquadratic_isGalois v a' b' d e hv ha' hb' + +lemma sqrtPair_four_automorphisms {L : Type*} [Field L] [CharZero L] + (a b : L) (d e : ℚ) (ha : a ^ 2 = algebraMap ℚ L d) + (hb : b ^ 2 = algebraMap ℚ L e) (hd : ¬ IsSquare d) (he : ¬ IsSquare e) + (hne : IntermediateField.adjoin ℚ {a} ≠ IntermediateField.adjoin ℚ {b}) : + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) := by + dsimp + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let v := sqrtPairBasis a b d e ha hb hd he hne + have hv (i : Fin 4) : v i = ![1, a', b', a' * b'] i := by + apply Subtype.ext + change (sqrtPairBasis a b d e ha hb hd he hne i : L) = _ + rw [coe_sqrtPairBasis_apply] + fin_cases i <;> rfl + have ha' : a' * a' = algebraMap ℚ B d := by + apply Subtype.ext + simpa [a', pow_two] using ha + have hb' : b' * b' = algebraMap ℚ B e := by + apply Subtype.ext + simpa [b', pow_two] using hb + let σ := biquadraticSignEquiv v a' b' d e hv ha' hb' true false + let τ := biquadraticSignEquiv v a' b' d e hv ha' hb' false true + have hs (s t : Bool) (i : Fin 4) := + biquadraticSignEquiv_basis v a' b' d e hv ha' hb' s t i + simp_rw [hv] at hs + refine ⟨σ, τ, hs true false 1, hs true false 2, hs false true 1, + hs false true 2, biquadratic_card_automorphisms v a' b' d e hv ha' hb', ?_, ?_⟩ + · exact biquadratic_four_automorphisms v a' b' d e hv ha' hb' + · exact biquadratic_automorphisms_commute v a' b' d e hv ha' hb' + +end WeightedTorusJets + +open scoped NumberField + +namespace WeightedTorusJets + +theorem ringOfIntegers_map_dvd_iff + {K L : Type*} [Field K] [Field L] [NumberField K] [NumberField L] + (f : K →ₐ[ℚ] L) (a b : 𝓞 K) : + NumberField.RingOfIntegers.mapRingHom f.toRingHom a ∣ + NumberField.RingOfIntegers.mapRingHom f.toRingHom b ↔ a ∣ b := by + let F := NumberField.RingOfIntegers.mapRingHom f.toRingHom + have hF : Function.Injective F := by + intro x y h + apply NumberField.RingOfIntegers.ext + apply f.injective + exact congrArg (fun z : 𝓞 L ↦ (z : L)) h + refine ⟨fun h ↦ ?_, fun h ↦ map_dvd F h⟩ + change F a ∣ F b at h + by_cases ha : a = 0 + · subst a + rw [map_zero, zero_dvd_iff] at h + have hb : b = 0 := hF (h.trans (map_zero F).symm) + simp [hb] + · have haK : (a : K) ≠ 0 := fun h ↦ ha (NumberField.RingOfIntegers.ext h) + have haL : f (a : K) ≠ 0 := fun h ↦ haK (f.injective (h.trans (map_zero f).symm)) + obtain ⟨c, hc⟩ := h + have hquot : f ((b : K) / (a : K)) = (c : L) := by + rw [map_div₀, div_eq_iff haL] + simpa [F, map_mul, mul_comm] using congrArg (fun z : 𝓞 L ↦ (z : L)) hc + have hint : IsIntegral ℤ ((b : K) / (a : K)) := by + apply (isIntegral_algHom_iff (f.restrictScalars ℤ) f.injective).mp + change IsIntegral ℤ (f ((b : K) / (a : K))) + rw [hquot] + exact c.2 + refine ⟨⟨(b : K) / (a : K), hint⟩, ?_⟩ + apply NumberField.RingOfIntegers.ext + change (b : K) = (a : K) * ((b : K) / (a : K)) + rw [mul_comm, div_mul_cancel₀ _ haK] + +theorem frobenius_congruence_descends + {K L : Type*} [Field K] [Field L] [NumberField K] [NumberField L] + (f : K →ₐ[ℚ] L) (σ : K ≃ₐ[ℚ] K) (τ : L ≃ₐ[ℚ] L) + (hcomm : ∀ x : K, f (σ x) = τ (f x)) (p : ℕ) + (hfrob : ∀ y : 𝓞 L, (p : 𝓞 L) ∣ y ^ p - τ • y) (x : 𝓞 K) : + (p : 𝓞 K) ∣ x ^ p - σ • x := by + let F := NumberField.RingOfIntegers.mapRingHom f.toRingHom + have hmap : F (σ • x) = τ • F x := by + apply NumberField.RingOfIntegers.ext + exact hcomm (x : K) + apply (ringOfIntegers_map_dvd_iff f (p : 𝓞 K) (x ^ p - σ • x)).mp + change F (p : 𝓞 K) ∣ F (x ^ p - σ • x) + simpa only [map_natCast, map_sub, map_pow, hmap] using hfrob (F x) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticBasisGroupTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticBasisGroupTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..998069b9bddda61a6f6b8cafaccad92c4f0ded75 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticBasisGroupTransport.lean @@ -0,0 +1,753 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.BiquadraticGoodPrimeUnramifiedSameWitnessEquiv +import OAI.NumberTheory.Jacobsthal.Siegel.BiquadraticThetaMap +import OAI.NumberTheory.Jacobsthal.Siegel.CharacterGlobalGreedyDeterminantMasterBounds +import OAI.NumberTheory.Jacobsthal.Siegel.FrobeniusRetainedCharacterField +import OAI.NumberTheory.Jacobsthal.Siegel.GreedyPivotsRingEquiv +import OAI.NumberTheory.Jacobsthal.Siegel.QuadraticEigencharacterAutCongr + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +end + +section +open scoped NumberField + +namespace WeightedTorusJets + +theorem biquadratic_basis_group_transport {B K : Type*} + [Field B] [Field K] [NumberField B] [NumberField K] + (eB : B ≃ₐ[ℚ] K) (v : Module.Basis (Fin 4) ℚ B) (a b : B) + (hv : ∀ i, v i = ![1, a, b, a * b] i) (hint : ∀ i, IsIntegral ℤ (v i)) + (hdegree : Module.finrank ℚ B = 4) (σ τ : B ≃ₐ[ℚ] B) + (hσa : σ a = -a) (hσb : σ b = b) (hτa : τ a = a) (hτb : τ b = -b) + (hcard : Nat.card (B ≃ₐ[ℚ] B) = 4) + (hall : ∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) + (hcomm : ∀ f g : B ≃ₐ[ℚ] B, Commute f g) : + let A := eB a + let bK := eB b + let w := v.map eB.toLinearEquiv + (∀ i, w i = ![1, A, bK, A * bK] i) ∧ + (∀ i, IsIntegral ℤ (w i)) ∧ Module.finrank ℚ K = 4 ∧ IsGalois ℚ K ∧ + (AlgEquiv.autCongr eB σ A = -A ∧ AlgEquiv.autCongr eB σ bK = bK ∧ + AlgEquiv.autCongr eB τ A = A ∧ AlgEquiv.autCongr eB τ bK = -bK) ∧ + Nat.card (K ≃ₐ[ℚ] K) = 4 ∧ + (∀ f : K ≃ₐ[ℚ] K, f = 1 ∨ f = AlgEquiv.autCongr eB σ ∨ + f = AlgEquiv.autCongr eB τ ∨ f = AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) ∧ + (∀ f g : K ≃ₐ[ℚ] K, Commute f g) := by + have hw (i : Fin 4) : v.map eB.toLinearEquiv i = ![1, eB a, eB b, eB a * eB b] i := by + rw [Module.Basis.map_apply, hv] + fin_cases i <;> simp + have hwDegree : Module.finrank ℚ K = 4 := eB.toLinearEquiv.finrank_eq.symm.trans hdegree + obtain ⟨hcardK, hallK, hcommK⟩ := transported_four_automorphisms eB σ τ hcard hall hcomm + exact ⟨hw, fun i => map_isIntegral_int eB.toRingHom (hint i), hwDegree, + IsGalois.of_card_aut_eq_finrank ℚ K (hcardK.trans hwDegree.symm), + transported_sign_actions eB a b σ τ hσa hσb hτa hτb, hcardK, hallK, hcommK⟩ + + +theorem biquadratic_directions_eq_of_galois_coordinates + {K : Type*} [Field K] [CharZero K] (a b : K) (φ : K →+* ℂ) + (σ τ : K ≃ₐ[ℚ] K) (hσa : σ a = -a) (hσb : σ b = b) + (hτa : τ a = a) (hτb : τ b = -b) {a₀ b₀ : ℂ} + (hφa : φ a = a₀) (hφb : φ b = b₀) (D : Fin 3 → Fin 4 → ℂ) + (hD : ∀ j i, D j i = + φ ((![![1, a, b, a * b], (fun i => σ (![1, a, b, a * b] i)), + (fun i => (σ * τ) (![1, a, b, a * b] i))] : Fin 3 → Fin 4 → K) j i)) : + ∀ j, D j = biquadraticDirections a₀ b₀ j := by + intro j + funext i + rw [hD] + fin_cases j <;> fin_cases i <;> + simp [biquadraticDirections, AlgEquiv.mul_apply, hσa, hσb, hτa, hτb, hφa, hφb] + + + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_master_principal_opaque_prefix (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + ∃ (B : IntermediateField ℚ (CyclotomicField (8 * q) ℚ)) + (principalK : IntermediateField ℚ ℂ), + B = IntermediateField.adjoin ℚ {a, b} ∧ + principalK = IntermediateField.adjoin ℚ {Complex.sqrt (d : ℂ), (Real.sqrt 2 : ℂ)} ∧ + ∃ a' b' : B, (a' : CyclotomicField (8 * q) ℚ) = a ∧ + (b' : CyclotomicField (8 * q) ℚ) = b ∧ a' ^ 2 = (d : B) ∧ b' ^ 2 = 2 ∧ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∃ eB : B ≃ₐ[ℚ] principalK, + (eB a' : ℂ) = Complex.sqrt (d : ℂ) ∧ + (eB b' : ℂ) = (Real.sqrt 2 : ℂ) ∧ + ∃ hPrincipal : NumberField principalK, letI := hPrincipal + (∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x))) ∧ + (∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → + Algebra.IsUnramifiedIn (𝓞 principalK) (Ideal.span {(p : ℤ)})) ∧ + ∀ N H : ℕ, 0 < H → H ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ : Fin (N ^ 4) → B := fun j => + ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let R : (Fin 3 → ℕ) → Fin (N ^ 4) → B := fun β j => + θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2 + ∀ order : ℕ ≃ (Fin 3 → ℕ), + Monotone (fun i => order i 0 + H * order i 1 + H * order i 2) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ order) + (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + (∀ i, α i = order (g i)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ Δ ≠ 0 ∧ + ((1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p)) := by + classical + obtain ⟨_C, _hC, _hC4, _CH, hmaster⟩ := + source_character_global_greedy_determinant_master_bounds + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hsource⟩ := + hmaster q χ hreal hprim hne hfield + clear hmaster + let L := CyclotomicField (8 * q) ℚ + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + have ha' : a' ^ 2 = (d : B) := by apply Subtype.ext; exact ha + have hb' : b' ^ 2 = 2 := by apply Subtype.ext; exact hb + let principalK := IntermediateField.adjoin ℚ + ({Complex.sqrt (d : ℂ), (Real.sqrt 2 : ℂ)} : Set ℂ) + obtain ⟨eB, heBa, heBb⟩ := exists_principal_root_field_equiv + (K := B) v a' b' d hv ha' hb' σ τ hσa hσb hτa hτb + have hPrincipal : NumberField principalK := + NumberField.of_ringEquiv B principalK eB.toRingEquiv + let : NumberField principalK := hPrincipal + have hfrob := source_frobenius_of_retained_character_field q L χ hreal + a b hchar hdegree σ τ hτa hcard hall + have hunram (p : ℕ) (hp : p.Prime) (hgood : ¬ p ∣ 2 * q) : + Algebra.IsUnramifiedIn (𝓞 principalK) (Ideal.span {(p : ℤ)}) := + source_biquadratic_good_prime_unramified_same_witness_equiv q p a b eB hp hgood + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + B, principalK, rfl, rfl, a', b', rfl, rfl, ha', hb', + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, + eB, heBa, heBb, hPrincipal, hfrob, hunram, ?_⟩ + intro N H hH hHN n + dsimp only + intro order horder + obtain ⟨g, α, hg, hα, _hrange, _hmono, _hweight, _hstable, Δ, hΔ, hΔne, + harch, hdiv, _hraw, _hfinite, _hlarge⟩ := hsource N H hH hHN n order horder + exact ⟨g, α, hg, hα, Δ, hΔ, hΔne, harch, hdiv⟩ + +theorem source_principal_character_field_transport (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) + (d : ℤ) (a : CyclotomicField (8 * q) ℚ) + (hchar : IntermediateField.adjoin ℚ {a} = + characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)) + (hdisc : (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q) + (hfund : Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a}))) + (hformula : NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d)) + (B : IntermediateField ℚ (CyclotomicField (8 * q) ℚ)) + (K : IntermediateField ℚ ℂ) (aB : B) + (hcoeA : (aB : CyclotomicField (8 * q) ℚ) = a) + (eB : B ≃ₐ[ℚ] K) (heBa : (eB aB : ℂ) = Complex.sqrt (d : ℂ)) : + ∃ (Kχ : IntermediateField ℚ ℂ) (νL : CyclotomicField (8 * q) ℚ →ₐ[ℚ] ℂ), + Kχ = IntermediateField.adjoin ℚ {Complex.sqrt (d : ℂ)} ∧ + (∀ x : B, νL x = (eB x : ℂ)) ∧ + (characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)).map νL = Kχ ∧ + ∃ eχ : IntermediateField.adjoin ℚ ({a} : Set (CyclotomicField (8 * q) ℚ)) ≃ₐ[ℚ] Kχ, + (∀ x, (eχ x : ℂ) = νL x) ∧ + ∃ hKχ : NumberField Kχ, letI := hKχ + NumberField.discr Kχ = (if d % 4 = 1 then d else 4 * d) ∧ + NumberField.discr Kχ = + integerCharacter χ (real_character_isQuadratic χ hreal) (-1) * (q : ℤ) ∧ + Int.IsFundamentalDiscr (NumberField.discr Kχ) ∧ + (NumberField.discr Kχ).natAbs = q ∧ + Kχ ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} := by + classical + let L := CyclotomicField (8 * q) ℚ + let Kχ := IntermediateField.adjoin ℚ ({Complex.sqrt (d : ℂ)} : Set ℂ) + let νB : B →ₐ[ℚ] ℂ := K.val.comp eB.toAlgHom + obtain ⟨νL, hνL⟩ := IsAlgClosed.surjective_domRestrict_of_isAlgebraic + (K := ℚ) (L := B) (M := ℂ) (E := L) νB + have hνLa : νL a = Complex.sqrt (d : ℂ) := + (congrArg νL hcoeA).symm.trans ((AlgHom.congr_fun hνL aB).trans heBa) + have hχmap : (characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)).map νL = Kχ := by + rw [← hchar, IntermediateField.adjoin_map, Set.image_singleton, hνLa] + have hKχne : Kχ ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} := by + rw [← hχmap] + exact (sourceSqrtTwoField_exclusion_map_iff q L _ νL).2 hfield + let Qχ := IntermediateField.adjoin ℚ ({a} : Set L) + have hQχmap : Qχ.map νL = Kχ := by + simpa only [Qχ, hchar] using hχmap + let eχ : Qχ ≃ₐ[ℚ] Kχ := (Qχ.equivMap νL).trans (IntermediateField.equivOfEq hQχmap) + let hKχ : NumberField Kχ := NumberField.of_ringEquiv Qχ Kχ eχ.toRingEquiv + let : NumberField Kχ := hKχ + have hdiscrTransport : NumberField.discr Kχ = NumberField.discr Qχ := + (NumberField.discr_eq_discr_of_algEquiv Qχ eχ).symm + have hdiscrKχ : NumberField.discr Kχ = (if d % 4 = 1 then d else 4 * d) := + hdiscrTransport.trans hformula + have hfundKχ : Int.IsFundamentalDiscr (NumberField.discr Kχ) := + hdiscrTransport.symm ▸ hfund + have habsKχ : (NumberField.discr Kχ).natAbs = q := + (congrArg Int.natAbs hdiscrTransport).trans hdisc + have hquad := real_character_isQuadratic χ hreal + have hsignKχ : NumberField.discr Kχ = integerCharacter χ hquad (-1) * (q : ℤ) := by + rw [hdiscrTransport] + change NumberField.discr (IntermediateField.adjoin ℚ {a}) = _ + rw [hchar] + exact characterField_changeLevel_discr_eq_signed_conductor + (dvd_mul_left q 8) χ hquad hprim hne + have hνB (x : B) : νL x = (eB x : ℂ) := AlgHom.congr_fun hνL x + have heχ (x : Qχ) : (eχ x : ℂ) = νL x := rfl + exact ⟨Kχ, νL, rfl, hνB, hχmap, eχ, heχ, hKχ, + hdiscrKχ, hsignKχ, hfundKχ, habsKχ, hKχne⟩ + +theorem source_principal_determinant_suffix + {B principalK : Type*} [Field B] [Field principalK] + [Algebra ℚ B] [Algebra ℚ principalK] + (q : ℕ) (χ : DirichletCharacter ℂ q) (d : ℤ) + (a' b' : B) (A bK : principalK) (σ τ : B ≃ₐ[ℚ] B) + (eB : B ≃ₐ[ℚ] principalK) (heA : eB a' = A) (heB : eB b' = bK) + (ha' : a' ^ 2 = (d : B)) (hb' : b' ^ 2 = 2) + (hdreal : |(d : ℝ)| ≤ q) (hq : 1 ≤ q) + (hsource : + ∀ N H : ℕ, 0 < H → H ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ : Fin (N ^ 4) → B := fun j => + ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let R : (Fin 3 → ℕ) → Fin (N ^ 4) → B := fun β j => + θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2 + ∀ order : ℕ ≃ (Fin 3 → ℕ), + Monotone (fun i => order i 0 + H * order i 1 + H * order i 2) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ order) + (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + (∀ i, α i = order (g i)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ Δ ≠ 0 ∧ + ((1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p))) : + ∀ N H : ℕ, 0 < H → H ≤ N → ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let θK := fun j => ∑ i : Fin 4, ((n j i : ℕ) : principalK) * ![1, A, bK, A * bK] i + let R := fun β : Fin 3 → ℕ => fun j => + θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2 + let RK := fun β : Fin 3 → ℕ => fun j => + θK j ^ β 0 * (AlgEquiv.autCongr eB σ) (θK j) ^ β 1 * + (AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) (θK j) ^ β 2 + ∀ order : ℕ ≃ (Fin 3 → ℕ), + Monotone (fun i => order i 0 + H * order i 1 + H * order i 2) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)) (Δ : 𝓞 B), + Set.range g = (greedyPivots B (R ∘ order) (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + Set.range g = (greedyPivots principalK (RK ∘ order) (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + (∀ T : ℕ, greedyPivots principalK (RK ∘ order) T = greedyPivots B (R ∘ order) T) ∧ + (∀ i, α i = order (g i)) ∧ + (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + let ΔK := NumberField.RingOfIntegers.mapRingEquiv eB.toRingEquiv Δ + (∀ j, eB (θ j) = θK j) ∧ (∀ β j, eB (R β j) = RK β j) ∧ + (ΔK : principalK) = eB (Δ : B) ∧ + (ΔK : principalK) = Matrix.det (fun i j => RK (α i) j) ∧ ΔK ≠ 0 ∧ + Algebra.norm ℚ (ΔK : principalK) = Algebra.norm ℚ (Δ : B) ∧ + Algebra.norm ℤ ΔK = Algebra.norm ℤ Δ ∧ + (∀ p r : ℕ, + ((p : 𝓞 principalK) ^ r ∣ ΔK ↔ (p : 𝓞 B) ^ r ∣ Δ) ∧ + (ΔK ∈ (Ideal.span {(p : 𝓞 principalK)}) ^ r ↔ Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ r)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + ΔK ∈ (Ideal.span {(p : 𝓞 principalK)}) ^ (∑ i, α i 0 / p)) ∧ + (∀ νK : principalK →+* ℂ, ∀ j, ‖νK (θK j)‖ ≤ 8 * N * Real.sqrt q) ∧ + (∀ νK : principalK →+* ℂ, ∀ β j, + ‖νK (RK β j)‖ ≤ (8 * N * Real.sqrt q) ^ (β 0 + β 1 + β 2)) ∧ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (ΔK : principalK) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + classical + intro N H hH hHN n + dsimp only + intro order horder + obtain ⟨g, α, hg, hα, Δ, hΔ, hΔne, harch, hdiv⟩ := hsource N H hH hHN n order horder + clear hsource + let θ : Fin (N ^ 4) → B := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let θK : Fin (N ^ 4) → principalK := fun j => ∑ i : Fin 4, ((n j i : ℕ) : principalK) * ![1, A, bK, A * bK] i + let R : (Fin 3 → ℕ) → Fin (N ^ 4) → B := fun β j => + θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2 + let RK : (Fin 3 → ℕ) → Fin (N ^ 4) → principalK := fun β j => + θK j ^ β 0 * (AlgEquiv.autCongr eB σ) (θK j) ^ β 1 * + (AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) (θK j) ^ β 2 + let ΔK : NumberField.RingOfIntegers principalK := + NumberField.RingOfIntegers.mapRingEquiv eB.toRingEquiv Δ + have htransport := + source_existing_integral_jet_witness_transport + (K := B) (L := principalK) (ι := Fin (N ^ 4)) eB σ τ a' b' A bK heA heB + (fun j i => (n j i : ℕ)) θ (fun _ => rfl) α Δ hΔ hΔne + obtain ⟨hθe, hrow, hdetK, hneK, hnormQ, hnormZ, hprimepowers⟩ := htransport + change ∀ j, eB (θ j) = θK j at hθe + change ∀ β j, eB (R β j) = RK β j at hrow + change Algebra.norm ℚ (ΔK : principalK) = Algebra.norm ℚ (Δ : B) at hnormQ + have hgreedyAll (T : ℕ) : + greedyPivots principalK (RK ∘ order) T = + greedyPivots B (R ∘ order) T := + source_greedy_indices_transport eB.toRingEquiv R RK hrow order T + have hgK : Set.range g = + (greedyPivots principalK (RK ∘ order) (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) := + hg.trans (congrArg (fun s : Finset ℕ => (s : Set ℕ)) + (hgreedyAll (weightedJetIndices H (N ^ 4 - 1)).card).symm) + have htheta_bound (νK : principalK →+* ℂ) (j : Fin (N ^ 4)) : + ‖νK (θK j)‖ ≤ 8 * N * Real.sqrt q := by + rw [← hθe j] + exact norm_embedding_basis_sum_le (νK.comp eB.toRingHom) ha' hb' hdreal hq + (fun i => (n j i : ℕ)) (fun i => (n j i).isLt) + have hrow_bound (νK : principalK →+* ℂ) (β : Fin 3 → ℕ) (j : Fin (N ^ 4)) : + ‖νK (RK β j)‖ ≤ (8 * N * Real.sqrt q) ^ (β 0 + β 1 + β 2) := by + rw [← hrow β j] + exact norm_embedding_derivative_entry_le (νK.comp eB.toRingHom) + σ.toRingHom τ.toRingHom ha' hb' hdreal hq + (fun i => (n j i : ℕ)) (fun i => (n j i).isLt) β + have harchK : + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (ΔK : principalK) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + rw [hnormQ] + exact harch + refine ⟨g, α, Δ, hg, hgK, hgreedyAll, hα, hΔ, hθe, hrow, rfl, hdetK, hneK, hnormQ, + hnormZ, hprimepowers, ?_, htheta_bound, hrow_bound, harchK⟩ + intro p hp hHp hpq hχp + exact (hprimepowers p (∑ i, α i 0 / p)).2.mpr (hdiv p hp hHp hpq hχp) + +theorem source_principal_existing_data_completion (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) + (d : ℤ) (a : CyclotomicField (8 * q) ℚ) + (hbound : d.natAbs ≤ q) (hns : ¬ IsSquare (d : ℚ)) + (hchar : IntermediateField.adjoin ℚ {a} = characterField (8 * q) + (CyclotomicField (8 * q) ℚ) ℂ (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)) + (hdisc : (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q) + (hfund : Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a}))) + (hformula : NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d)) + (B : IntermediateField ℚ (CyclotomicField (8 * q) ℚ)) + (principalK : IntermediateField ℚ ℂ) (a' b' : B) + (hcoeA : (a' : CyclotomicField (8 * q) ℚ) = a) + (ha' : a' ^ 2 = (d : B)) (hb' : b' ^ 2 = 2) + (v : Module.Basis (Fin 4) ℚ B) (hv : ∀ i, v i = ![1, a', b', a' * b'] i) + (hint : ∀ i, IsIntegral ℤ (v i)) (hdegree : Module.finrank ℚ B = 4) + (σ τ : B ≃ₐ[ℚ] B) (hσa : σ a' = -a') (hσb : σ b' = b') + (hτa : τ a' = a') (hτb : τ b' = -b') (hcard : Nat.card (B ≃ₐ[ℚ] B) = 4) + (hall : ∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) + (hcomm : ∀ f g : B ≃ₐ[ℚ] B, Commute f g) + (eB : B ≃ₐ[ℚ] principalK) (heBa : (eB a' : ℂ) = Complex.sqrt (d : ℂ)) + (heBb : (eB b' : ℂ) = (Real.sqrt 2 : ℂ)) (hPrincipal : NumberField principalK) + (hfrob : ∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x))) + (hunram : ∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → + Algebra.IsUnramifiedIn (𝓞 principalK) (Ideal.span {(p : ℤ)})) + (hsource : ∀ N H : ℕ, 0 < H → H ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ : Fin (N ^ 4) → B := fun j => + ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let R : (Fin 3 → ℕ) → Fin (N ^ 4) → B := fun β j => + θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2 + ∀ order : ℕ ≃ (Fin 3 → ℕ), + Monotone (fun i => order i 0 + H * order i 1 + H * order i 2) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ order) + (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + (∀ i, α i = order (g i)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ Δ ≠ 0 ∧ + ((1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p))) : + letI := hPrincipal + let A := eB a' + let bK := eB b' + let w := v.map eB.toLinearEquiv + let φB := principalK.val.toRingHom.comp eB.toRingHom + (∀ i, w i = ![1, A, bK, A * bK] i) ∧ (∀ i, IsIntegral ℤ (w i)) ∧ + Module.finrank ℚ principalK = 4 ∧ IsGalois ℚ principalK ∧ + (AlgEquiv.autCongr eB σ A = -A ∧ AlgEquiv.autCongr eB σ bK = bK ∧ + AlgEquiv.autCongr eB τ A = A ∧ AlgEquiv.autCongr eB τ bK = -bK) ∧ + Nat.card (principalK ≃ₐ[ℚ] principalK) = 4 ∧ + (∀ f : principalK ≃ₐ[ℚ] principalK, f = 1 ∨ f = AlgEquiv.autCongr eB σ ∨ + f = AlgEquiv.autCongr eB τ ∨ f = AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) ∧ + (∀ f g : principalK ≃ₐ[ℚ] principalK, Commute f g) ∧ + ∃ (Kχ : IntermediateField ℚ ℂ) (νL : CyclotomicField (8 * q) ℚ →ₐ[ℚ] ℂ), + Kχ = IntermediateField.adjoin ℚ {Complex.sqrt (d : ℂ)} ∧ + (∀ x : B, νL x = (eB x : ℂ)) ∧ + (characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)).map νL = Kχ ∧ + ∃ eχ : IntermediateField.adjoin ℚ ({a} : Set (CyclotomicField (8 * q) ℚ)) ≃ₐ[ℚ] Kχ, + (∀ x, (eχ x : ℂ) = νL x) ∧ + ∃ hKχ : NumberField Kχ, letI := hKχ + NumberField.discr Kχ = (if d % 4 = 1 then d else 4 * d) ∧ + NumberField.discr Kχ = + integerCharacter χ (real_character_isQuadratic χ hreal) (-1) * (q : ℤ) ∧ + Int.IsFundamentalDiscr (NumberField.discr Kχ) ∧ + (NumberField.discr Kχ).natAbs = q ∧ + Kχ ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} ∧ + biquadraticCoefficients (φB a') (φB b') = + ![1, 1 / Complex.sqrt (d : ℂ), -(1 / (Real.sqrt 2 : ℂ)), + -(1 / (Complex.sqrt (d : ℂ) * (Real.sqrt 2 : ℂ)))] ∧ + LinearIndependent ℚ + (![1, 1 / Complex.sqrt (d : ℂ), -(1 / (Real.sqrt 2 : ℂ)), + -(1 / (Complex.sqrt (d : ℂ) * (Real.sqrt 2 : ℂ)))] : Fin 4 → ℂ) ∧ + ∃ D : Module.Basis (Fin 3) ℂ + (LinearMap.ker (biquadraticForm (Complex.sqrt (d : ℂ)) (Real.sqrt 2 : ℂ))), + (∀ j i, (D j : Fin 4 → ℂ) i = + φB ((![![1, a', b', a' * b'], (fun i => σ (![1, a', b', a' * b'] i)), + (fun i => (σ * τ) (![1, a', b', a' * b'] i))] : Fin 3 → Fin 4 → B) j i)) ∧ + (∀ j, (D j : Fin 4 → ℂ) = + biquadraticDirections (Complex.sqrt (d : ℂ)) (Real.sqrt 2 : ℂ) j) ∧ + (∀ (N : ℕ) (n : Fin (N ^ 4) ≃ (Fin 4 → Fin N)) (s : Set (Fin 3 → ℕ)), + Module.finrank ℂ (Submodule.span ℂ + ((fun β : Fin 3 → ℕ => fun j => MvPolynomial.eval (fun _ => 1) + (Geometry.invariantJet (fun k i => (D k : Fin 4 → ℂ) i) β + (MvPolynomial.monomial + (Finsupp.equivFunOnFinite.symm (fun i => (n j i : ℕ))) 1))) '' s)) = + Module.finrank B (Submodule.span B + ((fun β : Fin 3 → ℕ => fun j => + (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i) ^ β 0 * + σ (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i) ^ β 1 * + (σ * τ) (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i) ^ + β 2) '' s))) ∧ + ∃ (hA : A * A = algebraMap ℚ principalK (d : ℚ)) (hA0 : A ≠ 0), + let ξ := quadraticEigencharacter A (d : ℚ) hA hA0 + (∀ f, f A = ξ f * A) ∧ (∀ f, ξ f = 1 ∨ ξ f = -1) ∧ + ξ (AlgEquiv.autCongr eB σ) = -1 ∧ ξ (AlgEquiv.autCongr eB τ) = 1 ∧ + ξ (AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) = -1 ∧ + (∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → + Algebra.IsUnramifiedIn (𝓞 principalK) (Ideal.span {(p : ℤ)})) ∧ + (∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ∃ φ : B ≃ₐ[ℚ] B, (φ = σ ∨ φ = σ * τ) ∧ + (∀ (P : Ideal (𝓞 principalK)) (_ : P.IsPrime), P.LiesOver (Ideal.span {(p : ℤ)}) → + IsArithFrobAt ℤ (AlgEquiv.autCongr eB φ) P) ∧ + (ξ (AlgEquiv.autCongr eB φ) : ℂ) = χ p ∧ + ∀ x : 𝓞 principalK, (p : 𝓞 principalK) ∣ x ^ p - AlgEquiv.autCongr eB φ • x) ∧ + ∀ N H : ℕ, 0 < H → H ≤ N → ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let θK := fun j => ∑ i : Fin 4, ((n j i : ℕ) : principalK) * ![1, A, bK, A * bK] i + let R := fun β : Fin 3 → ℕ => fun j => + θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2 + let RK := fun β : Fin 3 → ℕ => fun j => + θK j ^ β 0 * (AlgEquiv.autCongr eB σ) (θK j) ^ β 1 * + (AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) (θK j) ^ β 2 + ∀ order : ℕ ≃ (Fin 3 → ℕ), + Monotone (fun i => order i 0 + H * order i 1 + H * order i 2) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)) (Δ : 𝓞 B), + Set.range g = (greedyPivots B (R ∘ order) (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + Set.range g = (greedyPivots principalK (RK ∘ order) (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + (∀ T : ℕ, greedyPivots principalK (RK ∘ order) T = greedyPivots B (R ∘ order) T) ∧ + (∀ i, α i = order (g i)) ∧ + (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + let ΔK := NumberField.RingOfIntegers.mapRingEquiv eB.toRingEquiv Δ + (∀ j, eB (θ j) = θK j) ∧ (∀ β j, eB (R β j) = RK β j) ∧ + (ΔK : principalK) = eB (Δ : B) ∧ + (ΔK : principalK) = Matrix.det (fun i j => RK (α i) j) ∧ ΔK ≠ 0 ∧ + Algebra.norm ℚ (ΔK : principalK) = Algebra.norm ℚ (Δ : B) ∧ + Algebra.norm ℤ ΔK = Algebra.norm ℤ Δ ∧ + (∀ p r : ℕ, + ((p : 𝓞 principalK) ^ r ∣ ΔK ↔ (p : 𝓞 B) ^ r ∣ Δ) ∧ + (ΔK ∈ (Ideal.span {(p : 𝓞 principalK)}) ^ r ↔ Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ r)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + ΔK ∈ (Ideal.span {(p : 𝓞 principalK)}) ^ (∑ i, α i 0 / p)) ∧ + (∀ νK : principalK →+* ℂ, ∀ j, ‖νK (θK j)‖ ≤ 8 * N * Real.sqrt q) ∧ + (∀ νK : principalK →+* ℂ, ∀ β j, + ‖νK (RK β j)‖ ≤ (8 * N * Real.sqrt q) ^ (β 0 + β 1 + β 2)) ∧ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (ΔK : principalK) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + classical + let L := CyclotomicField (8 * q) ℚ + let : NumberField principalK := hPrincipal + let A : principalK := eB a' + let bK : principalK := eB b' + have heA : eB a' = A := rfl + have heB : eB b' = bK := rfl + let φB : B →+* ℂ := principalK.val.toRingHom.comp eB.toRingHom + have hφa : φB a' = Complex.sqrt (d : ℂ) := heBa + have hφb : φB b' = (Real.sqrt 2 : ℂ) := heBb + let w := v.map eB.toLinearEquiv + have hbasis := + biquadratic_basis_group_transport eB v a' b' hv hint hdegree + σ τ hσa hσb hτa hτb hcard hall hcomm + have hw := hbasis.1 + have hwIntegral := hbasis.2.1 + have hwDegree := hbasis.2.2.1 + have hGaloisK := hbasis.2.2.2.1 + have hsignK := hbasis.2.2.2.2.1 + have hcardK := hbasis.2.2.2.2.2.1 + have hallK := hbasis.2.2.2.2.2.2.1 + have hcommK := hbasis.2.2.2.2.2.2.2 + have hclassified := + source_principal_character_field_transport q χ hreal hprim hne hfield + d a hchar hdisc hfund hformula B principalK a' hcoeA eB heBa + let Kχ := hclassified.choose + let νL := hclassified.choose_spec.choose + have hfielddata := hclassified.choose_spec.choose_spec + have hKχeq := hfielddata.1 + have hνB := hfielddata.2.1 + have hχmap := hfielddata.2.2.1 + let eχ := hfielddata.2.2.2.choose + have heχ := hfielddata.2.2.2.choose_spec.1 + let hKχ := hfielddata.2.2.2.choose_spec.2.choose + have hclass := hfielddata.2.2.2.choose_spec.2.choose_spec + let : NumberField Kχ := hKχ + have hdiscrKχ := hclass.1 + have hsignKχ := hclass.2.1 + have hfundKχ := hclass.2.2.1 + have habsKχ := hclass.2.2.2.1 + have hKχne := hclass.2.2.2.2 + have hcoeff : biquadraticCoefficients (φB a') (φB b') = + ![1, 1 / Complex.sqrt (d : ℂ), -(1 / (Real.sqrt 2 : ℂ)), + -(1 / (Complex.sqrt (d : ℂ) * (Real.sqrt 2 : ℂ)))] := by + simp only [hφa, hφb, biquadraticCoefficients, one_div] + have hsame := source_same_witness_hyperplane a' b' φB v hv σ τ hσa hσb hτa hτb + rw [hφa, hφb] at hsame + have hc := hsame.1 + let D := hsame.2.choose + have hD := hsame.2.choose_spec + have hprincipalCoefficients : LinearIndependent ℚ + (![1, 1 / Complex.sqrt (d : ℂ), -(1 / (Real.sqrt 2 : ℂ)), + -(1 / (Complex.sqrt (d : ℂ) * (Real.sqrt 2 : ℂ)))] : Fin 4 → ℂ) := by + simpa only [biquadraticCoefficients, one_div] using hc + have hprincipalDirections : ∀ j, (D j : Fin 4 → ℂ) = + biquadraticDirections (Complex.sqrt (d : ℂ)) (Real.sqrt 2 : ℂ) j := + biquadratic_directions_eq_of_galois_coordinates a' b' φB σ τ + hσa hσb hτa hτb hφa hφb (fun j => (D j : Fin 4 → ℂ)) hD + have hdimension (N : ℕ) (n : Fin (N ^ 4) ≃ (Fin 4 → Fin N)) + (s : Set (Fin 3 → ℕ)) : + Module.finrank ℂ (Submodule.span ℂ + ((fun β : Fin 3 → ℕ => fun j => MvPolynomial.eval (fun _ => 1) + (Geometry.invariantJet (fun k i => (D k : Fin 4 → ℂ) i) β + (MvPolynomial.monomial + (Finsupp.equivFunOnFinite.symm (fun i => (n j i : ℕ))) 1))) '' s)) = + Module.finrank B (Submodule.span B + ((fun β : Fin 3 → ℕ => fun j => + (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i) ^ β 0 * + σ (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i) ^ β 1 * + (σ * τ) (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i) ^ + β 2) '' s)) := by + have hD' := funext fun k => funext fun i => hD k i + rw [hD'] + exact Geometry.finrank_span_source_jet_rows_eq φB ![1, a', b', a' * b'] + σ.toRingHom τ.toRingHom (fun j i => (n j i : ℕ)) s + have haRat : a' ^ 2 = algebraMap ℚ B (d : ℚ) := by simpa using ha' + have hA : A * A = algebraMap ℚ principalK (d : ℚ) := by + calc + A * A = eB (a' * a') := (map_mul eB a' a').symm + _ = eB (algebraMap ℚ B (d : ℚ)) := + congrArg eB (by simpa [pow_two] using haRat) + _ = algebraMap ℚ principalK (d : ℚ) := eB.commutes (d : ℚ) + obtain ⟨hA0, heigen⟩ := + source_quadratic_group_character_principal_transport eB a' A (d : ℚ) + haRat hA hns heA σ τ hσa hτa principalK.val q χ hfrob + have hξ := heigen.1 + have hrange := heigen.2.1 + have hξσ := heigen.2.2.1 + have hξτ := heigen.2.2.2.1 + have hξστ := heigen.2.2.2.2.1 + have hprimes := heigen.2.2.2.2.2 + have hdreal : |(d : ℝ)| ≤ q := by + simpa only [Nat.cast_natAbs, Int.cast_abs] using + (show (d.natAbs : ℝ) ≤ q from Nat.cast_le.mpr hbound) + have hq : 1 ≤ q := Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hdeterminants := source_principal_determinant_suffix q χ d a' b' A bK σ τ + eB heA heB ha' hb' hdreal hq hsource + refine ⟨hw, hwIntegral, hwDegree, hGaloisK, + hsignK, hcardK, hallK, hcommK, Kχ, νL, hKχeq, hνB, hχmap, + eχ, heχ, hKχ, hdiscrKχ, hsignKχ, hfundKχ, habsKχ, hKχne, + hcoeff, hprincipalCoefficients, D, hD, hprincipalDirections, hdimension, + hA, hA0, hξ, hrange, hξσ, hξτ, hξστ, hunram, hprimes, hdeterminants⟩ + +theorem source_master_principal_same_data (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + ∃ (d : ℤ) (a b : CyclotomicField (8 * q) ℚ), + Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ ¬ IsSquare (d : ℚ) ∧ + a ^ 2 = (d : CyclotomicField (8 * q) ℚ) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + ∃ (B : IntermediateField ℚ (CyclotomicField (8 * q) ℚ)) + (K : IntermediateField ℚ ℂ), + B = IntermediateField.adjoin ℚ {a, b} ∧ + K = IntermediateField.adjoin ℚ {Complex.sqrt (d : ℂ), (Real.sqrt 2 : ℂ)} ∧ + ∃ aB bB : B, (aB : CyclotomicField (8 * q) ℚ) = a ∧ + (bB : CyclotomicField (8 * q) ℚ) = b ∧ + ∃ (v : Module.Basis (Fin 4) ℚ B) (σ τ : B ≃ₐ[ℚ] B), + (∀ i, v i = ![1, aB, bB, aB * bB] i) ∧ (∀ i, IsIntegral ℤ (v i)) ∧ + Module.finrank ℚ B = 4 ∧ + σ aB = -aB ∧ σ bB = bB ∧ τ aB = aB ∧ τ bB = -bB ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∃ eB : B ≃ₐ[ℚ] K, (eB aB : ℂ) = Complex.sqrt (d : ℂ) ∧ + (eB bB : ℂ) = (Real.sqrt 2 : ℂ) ∧ + ∃ hK : NumberField K, letI := hK + let A := eB aB + let bK := eB bB + let w := v.map eB.toLinearEquiv + let φB := K.val.toRingHom.comp eB.toRingHom + (∀ i, w i = ![1, A, bK, A * bK] i) ∧ (∀ i, IsIntegral ℤ (w i)) ∧ + Module.finrank ℚ K = 4 ∧ IsGalois ℚ K ∧ + (AlgEquiv.autCongr eB σ A = -A ∧ AlgEquiv.autCongr eB σ bK = bK ∧ + AlgEquiv.autCongr eB τ A = A ∧ AlgEquiv.autCongr eB τ bK = -bK) ∧ + Nat.card (K ≃ₐ[ℚ] K) = 4 ∧ + (∀ f : K ≃ₐ[ℚ] K, f = 1 ∨ f = AlgEquiv.autCongr eB σ ∨ + f = AlgEquiv.autCongr eB τ ∨ f = AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) ∧ + (∀ f g : K ≃ₐ[ℚ] K, Commute f g) ∧ + ∃ (Kχ : IntermediateField ℚ ℂ) (νL : CyclotomicField (8 * q) ℚ →ₐ[ℚ] ℂ), + Kχ = IntermediateField.adjoin ℚ {Complex.sqrt (d : ℂ)} ∧ + (∀ x : B, νL x = (eB x : ℂ)) ∧ + (characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)).map νL = Kχ ∧ + ∃ eχ : IntermediateField.adjoin ℚ ({a} : Set (CyclotomicField (8 * q) ℚ)) ≃ₐ[ℚ] Kχ, + (∀ x, (eχ x : ℂ) = νL x) ∧ + ∃ hKχ : NumberField Kχ, letI := hKχ + NumberField.discr Kχ = (if d % 4 = 1 then d else 4 * d) ∧ + NumberField.discr Kχ = + integerCharacter χ (real_character_isQuadratic χ hreal) (-1) * (q : ℤ) ∧ + Int.IsFundamentalDiscr (NumberField.discr Kχ) ∧ + (NumberField.discr Kχ).natAbs = q ∧ + Kχ ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} ∧ + biquadraticCoefficients (φB aB) (φB bB) = + ![1, 1 / Complex.sqrt (d : ℂ), -(1 / (Real.sqrt 2 : ℂ)), + -(1 / (Complex.sqrt (d : ℂ) * (Real.sqrt 2 : ℂ)))] ∧ + LinearIndependent ℚ + (![1, 1 / Complex.sqrt (d : ℂ), -(1 / (Real.sqrt 2 : ℂ)), + -(1 / (Complex.sqrt (d : ℂ) * (Real.sqrt 2 : ℂ)))] : Fin 4 → ℂ) ∧ + ∃ D : Module.Basis (Fin 3) ℂ + (LinearMap.ker (biquadraticForm (Complex.sqrt (d : ℂ)) (Real.sqrt 2 : ℂ))), + (∀ j i, (D j : Fin 4 → ℂ) i = + φB ((![![1, aB, bB, aB * bB], (fun i => σ (![1, aB, bB, aB * bB] i)), + (fun i => (σ * τ) (![1, aB, bB, aB * bB] i))] : Fin 3 → Fin 4 → B) j i)) ∧ + (∀ j, (D j : Fin 4 → ℂ) = + biquadraticDirections (Complex.sqrt (d : ℂ)) (Real.sqrt 2 : ℂ) j) ∧ + (∀ (N : ℕ) (n : Fin (N ^ 4) ≃ (Fin 4 → Fin N)) (s : Set (Fin 3 → ℕ)), + Module.finrank ℂ (Submodule.span ℂ + ((fun β : Fin 3 → ℕ => fun j => MvPolynomial.eval (fun _ => 1) + (Geometry.invariantJet (fun k i => (D k : Fin 4 → ℂ) i) β + (MvPolynomial.monomial + (Finsupp.equivFunOnFinite.symm (fun i => (n j i : ℕ))) 1))) '' s)) = + Module.finrank B (Submodule.span B + ((fun β : Fin 3 → ℕ => fun j => + (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, aB, bB, aB * bB] i) ^ β 0 * + σ (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, aB, bB, aB * bB] i) ^ β 1 * + (σ * τ) (∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, aB, bB, aB * bB] i) ^ + β 2) '' s))) ∧ + ∃ (hA : A * A = algebraMap ℚ K (d : ℚ)) (hA0 : A ≠ 0), + let ξ := quadraticEigencharacter A (d : ℚ) hA hA0 + (∀ f, f A = ξ f * A) ∧ (∀ f, ξ f = 1 ∨ ξ f = -1) ∧ + ξ (AlgEquiv.autCongr eB σ) = -1 ∧ ξ (AlgEquiv.autCongr eB τ) = 1 ∧ + ξ (AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) = -1 ∧ + (∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → + Algebra.IsUnramifiedIn (𝓞 K) (Ideal.span {(p : ℤ)})) ∧ + (∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ∃ φ : B ≃ₐ[ℚ] B, (φ = σ ∨ φ = σ * τ) ∧ + (∀ (P : Ideal (𝓞 K)) (_ : P.IsPrime), P.LiesOver (Ideal.span {(p : ℤ)}) → + IsArithFrobAt ℤ (AlgEquiv.autCongr eB φ) P) ∧ + (ξ (AlgEquiv.autCongr eB φ) : ℂ) = χ p ∧ + ∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - AlgEquiv.autCongr eB φ • x) ∧ + ∀ N H : ℕ, 0 < H → H ≤ N → ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, aB, bB, aB * bB] i + let θK := fun j => ∑ i : Fin 4, ((n j i : ℕ) : K) * ![1, A, bK, A * bK] i + let R := fun β : Fin 3 → ℕ => fun j => + θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2 + let RK := fun β : Fin 3 → ℕ => fun j => + θK j ^ β 0 * (AlgEquiv.autCongr eB σ) (θK j) ^ β 1 * + (AlgEquiv.autCongr eB σ * AlgEquiv.autCongr eB τ) (θK j) ^ β 2 + ∀ order : ℕ ≃ (Fin 3 → ℕ), + Monotone (fun i => order i 0 + H * order i 1 + H * order i 2) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)) (Δ : 𝓞 B), + Set.range g = (greedyPivots B (R ∘ order) (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + Set.range g = (greedyPivots K (RK ∘ order) (weightedJetIndices H (N ^ 4 - 1)).card : Set ℕ) ∧ + (∀ T : ℕ, greedyPivots K (RK ∘ order) T = greedyPivots B (R ∘ order) T) ∧ + (∀ i, α i = order (g i)) ∧ + (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + let ΔK := NumberField.RingOfIntegers.mapRingEquiv eB.toRingEquiv Δ + (∀ j, eB (θ j) = θK j) ∧ (∀ β j, eB (R β j) = RK β j) ∧ + (ΔK : K) = eB (Δ : B) ∧ + (ΔK : K) = Matrix.det (fun i j => RK (α i) j) ∧ ΔK ≠ 0 ∧ + Algebra.norm ℚ (ΔK : K) = Algebra.norm ℚ (Δ : B) ∧ + Algebra.norm ℤ ΔK = Algebra.norm ℤ Δ ∧ + (∀ p r : ℕ, + ((p : 𝓞 K) ^ r ∣ ΔK ↔ (p : 𝓞 B) ^ r ∣ Δ) ∧ + (ΔK ∈ (Ideal.span {(p : 𝓞 K)}) ^ r ↔ Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ r)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + ΔK ∈ (Ideal.span {(p : 𝓞 K)}) ^ (∑ i, α i 0 / p)) ∧ + (∀ νK : K →+* ℂ, ∀ j, ‖νK (θK j)‖ ≤ 8 * N * Real.sqrt q) ∧ + (∀ νK : K →+* ℂ, ∀ β j, + ‖νK (RK β j)‖ ≤ (8 * N * Real.sqrt q) ^ (β 0 + β 1 + β 2)) ∧ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (ΔK : K) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + classical + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + B, principalK, hB, hK, a', b', hcoeA, hcoeB, ha', hb', + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, + eB, heBa, heBb, hPrincipal, hfrob, hunram, hsource⟩ := + source_master_principal_opaque_prefix q χ hreal hprim hne hfield + let : NumberField principalK := hPrincipal + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, + B, principalK, hB, hK, a', b', hcoeA, hcoeB, v, σ, τ, + hv, hint, hdegree, hσa, hσb, hτa, hτb, hcard, hall, hcomm, + eB, heBa, heBb, hPrincipal, ?_⟩ + exact source_principal_existing_data_completion q χ hreal hprim hne hfield + d a hbound hns hchar hdisc hfund hformula B principalK a' b' hcoeA ha' hb' + v hv hint hdegree σ τ hσa hσb hτa hτb hcard hall hcomm + eB heBa heBb hPrincipal hfrob hunram hsource + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticGoodPrimeUnramified.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticGoodPrimeUnramified.lean new file mode 100644 index 0000000000000000000000000000000000000000..15349829aa57197f82b25d8f4007993e474e5bf9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticGoodPrimeUnramified.lean @@ -0,0 +1,36 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.QuadraticAdjoinBasis + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField + +theorem source_biquadratic_good_prime_unramified (q p : ℕ) [NeZero q] + (a b : CyclotomicField (8 * q) ℚ) (hp : p.Prime) (hgood : ¬ p ∣ 2 * q) : + Algebra.IsUnramifiedIn + (𝓞 (IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)))) + (Ideal.span {(p : ℤ)}) := by + have : Fact p.Prime := ⟨hp⟩ + have hp8 : p ∣ 8 ↔ p ∣ 2 := by + rw [show (8 : ℕ) = 2 ^ 3 by norm_num, hp.prime.dvd_pow_iff_dvd (by decide : 3 ≠ 0)] + have hpn : ¬ p ∣ 8 * q := by simpa only [hp.dvd_mul, hp8] using hgood + exact isUnramifiedIn_of_numberField_extension (L := CyclotomicField (8 * q) ℚ) _ + (cyclotomic_isUnramifiedIn (8 * q) (CyclotomicField (8 * q) ℚ) p hpn) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticGoodPrimeUnramifiedSameWitnessEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticGoodPrimeUnramifiedSameWitnessEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..934687b31eea61a175673db509fbbffaafe5f53b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticGoodPrimeUnramifiedSameWitnessEquiv.lean @@ -0,0 +1,35 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.BiquadraticGoodPrimeUnramified + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped NumberField +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField + +theorem source_biquadratic_good_prime_unramified_same_witness_equiv + (q p : ℕ) [NeZero q] (a b : CyclotomicField (8 * q) ℚ) + {K : Type*} [Field K] [NumberField K] + (e : IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) ≃ₐ[ℚ] K) + (hp : p.Prime) (hgood : ¬ p ∣ 2 * q) : + Algebra.IsUnramifiedIn (𝓞 K) (Ideal.span {(p : ℤ)}) := by + let := e.symm.toRingHom.toAlgebra + exact isUnramifiedIn_of_numberField_extension _ + (source_biquadratic_good_prime_unramified q p a b hp hgood) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticThetaMap.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticThetaMap.lean new file mode 100644 index 0000000000000000000000000000000000000000..73ce6194f5cecc00dab0c656c6a5384be85ad26d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/BiquadraticThetaMap.lean @@ -0,0 +1,111 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.IntegralDeterminantTransport +import OAI.NumberTheory.Jacobsthal.Siegel.JetRowAutCongr + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open scoped NumberField + +namespace WeightedTorusJets + +theorem biquadratic_theta_map + {K L : Type*} [CommRing K] [CommRing L] + (e : K →+* L) (a b : K) (n : Fin 4 → ℕ) : + e (∑ i : Fin 4, (n i : K) * ![1, a, b, a * b] i) = + ∑ i : Fin 4, (n i : L) * ![1, e a, e b, e a * e b] i := by + simp [Fin.sum_univ_succ] + +theorem source_existing_jet_witness_transport + {K L ι : Type*} [Field K] [Field L] [Algebra ℚ K] [Algebra ℚ L] + [Fintype ι] [DecidableEq ι] + (e : K ≃ₐ[ℚ] L) (σ τ : K ≃ₐ[ℚ] K) + (a b : K) (A B : L) (hea : e a = A) (heb : e b = B) + (n : ι → Fin 4 → ℕ) (θ : ι → K) + (hθ : ∀ j, θ j = ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i) + (α : ι → Fin 3 → ℕ) (Δ : K) + (hΔ : Δ = Matrix.det (Matrix.of fun i j => + θ j ^ α i 0 * σ (θ j) ^ α i 1 * (σ * τ) (θ j) ^ α i 2)) + (hΔne : Δ ≠ 0) : + let θL := fun j => ∑ i : Fin 4, (n j i : L) * ![1, A, B, A * B] i + (∀ j, e (θ j) = θL j) ∧ + (∀ (β : Fin 3 → ℕ) j, + e (θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2) = + θL j ^ β 0 * (AlgEquiv.autCongr e σ) (θL j) ^ β 1 * + (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) (θL j) ^ β 2) ∧ + e Δ = Matrix.det (Matrix.of fun i j => + θL j ^ α i 0 * (AlgEquiv.autCongr e σ) (θL j) ^ α i 1 * + (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) (θL j) ^ α i 2) ∧ + e Δ ≠ 0 := by + let θL := fun j => ∑ i : Fin 4, (n j i : L) * ![1, A, B, A * B] i + have hθe (j : ι) : e (θ j) = θL j := by + rw [hθ] + calc + e (∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i) = + ∑ i : Fin 4, (n j i : L) * ![1, e a, e b, e a * e b] i := + biquadratic_theta_map e.toRingHom a b (n j) + _ = θL j := by rw [hea, heb] + have hrow (β : Fin 3 → ℕ) (j : ι) : + e (θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2) = + θL j ^ β 0 * (AlgEquiv.autCongr e σ) (θL j) ^ β 1 * + (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) (θL j) ^ β 2 := by + rw [← hθe] + exact source_jet_row_autCongr e σ τ (θ j) β + refine ⟨hθe, hrow, ?_, (map_ne_zero e).mpr hΔne⟩ + rw [hΔ] + change e.toRingHom (Matrix.det (Matrix.of _)) = _ + rw [RingHom.map_det] + congr 1 + ext i j + exact hrow (α i) j + +theorem source_existing_integral_jet_witness_transport + {K L ι : Type*} [Field K] [Field L] [Algebra ℚ K] [Algebra ℚ L] + [Fintype ι] [DecidableEq ι] + (e : K ≃ₐ[ℚ] L) (σ τ : K ≃ₐ[ℚ] K) + (a b : K) (A B : L) (hea : e a = A) (heb : e b = B) + (n : ι → Fin 4 → ℕ) (θ : ι → K) + (hθ : ∀ j, θ j = ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i) + (α : ι → Fin 3 → ℕ) (Δ : 𝓞 K) + (hΔ : (Δ : K) = Matrix.det (Matrix.of fun i j => + θ j ^ α i 0 * σ (θ j) ^ α i 1 * (σ * τ) (θ j) ^ α i 2)) + (hΔne : Δ ≠ 0) : + let θL := fun j => ∑ i : Fin 4, (n j i : L) * ![1, A, B, A * B] i + let ΔL := NumberField.RingOfIntegers.mapRingEquiv e.toRingEquiv Δ + (∀ j, e (θ j) = θL j) ∧ + (∀ (β : Fin 3 → ℕ) j, + e (θ j ^ β 0 * σ (θ j) ^ β 1 * (σ * τ) (θ j) ^ β 2) = + θL j ^ β 0 * (AlgEquiv.autCongr e σ) (θL j) ^ β 1 * + (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) (θL j) ^ β 2) ∧ + (ΔL : L) = Matrix.det (Matrix.of fun i j => + θL j ^ α i 0 * (AlgEquiv.autCongr e σ) (θL j) ^ α i 1 * + (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) (θL j) ^ α i 2) ∧ + ΔL ≠ 0 ∧ + Algebra.norm ℚ (ΔL : L) = Algebra.norm ℚ (Δ : K) ∧ + Algebra.norm ℤ ΔL = Algebra.norm ℤ Δ ∧ + ∀ p r : ℕ, + ((p : 𝓞 L) ^ r ∣ ΔL ↔ (p : 𝓞 K) ^ r ∣ Δ) ∧ + (ΔL ∈ (Ideal.span {(p : 𝓞 L)}) ^ r ↔ + Δ ∈ (Ideal.span {(p : 𝓞 K)}) ^ r) := by + have hΔK : (Δ : K) ≠ 0 := by + intro h + apply hΔne + apply Subtype.ext + exact h + obtain ⟨hθe, hrow, hdet, _⟩ := source_existing_jet_witness_transport + e σ τ a b A B hea heb n θ hθ α (Δ : K) hΔ hΔK + obtain ⟨hcoe, hne, hnormQ, hnormZ, hdiv⟩ := integral_determinant_transport e Δ + exact ⟨hθe, hrow, hcoe.trans hdet, hne.mpr hΔne, hnormQ, hnormZ, hdiv⟩ + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/CharacterGlobalGreedyDeterminantFullLocalBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CharacterGlobalGreedyDeterminantFullLocalBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..63d4e961a2fe1bf4f9b58417f6aaa08b757abedc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CharacterGlobalGreedyDeterminantFullLocalBounds.lean @@ -0,0 +1,133 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.NormSqReal + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped BigOperators +open scoped BigOperators +open Module +open scoped BigOperators +open scoped BigOperators +open Module +open scoped BigOperators +open InnerProductSpace +open _root_.Erdos970.Finset +open scoped BigOperators NumberField +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_character_global_greedy_determinant_full_local_bounds : + ∃ C : ℝ, 0 < C ∧ Real.log 4 ≤ C ∧ ∃ CH : ℕ → ℝ, + ∀ (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)), + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ N H : ℕ, 0 < H → H ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * + ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + ∀ e : ℕ ≃ (Fin 3 → ℕ), Monotone (fun i => w (e i)) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ e) s.card : Set ℕ) ∧ + (∀ i, α i = e (g i)) ∧ + Set.range α = ((greedyPivots B (R ∘ e) s.card).image e : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ N ^ 4 - 1) ∧ + (∀ t : ℕ, s.card ≤ t → + Set.range g = (greedyPivots B (R ∘ e) t : Set ℕ)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + Δ ≠ 0 ∧ + ((1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p)) ∧ + (∀ U : ℝ, 0 ≤ U → + let P := (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ χ p = -1) + let E := fun p => ∑ i, α i 0 / p + let S₁ := ∑ i, (α i 0 : ℝ) + (∑ p ∈ P, (E p : ℝ) * Real.log p ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)|) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - + (N : ℝ) ^ 4 * (∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p) ≤ + ∑ p ∈ P, (E p : ℝ) * Real.log p) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - + Real.log 4 * (N : ℝ) ^ 4 * U ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)|) ) ∧ + ∀ β : ℝ, 0 < β → β < 1 → + DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ U : ℝ, 0 ≤ U → + (∑ i, (α i 0 : ℝ)) * + (Real.log U - C * Real.log q - + C * ((1 - β) * Real.log q) * (Real.log U) ^ 2 / Real.log q - CH H) - + C * (N : ℝ) ^ 4 * U ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| := by + classical + obtain ⟨C, hC, hC4, hfinite⟩ := source_given_determinant_finite_lower_of_real_zero + choose CH hCH using hfinite + refine ⟨C, hC, hC4, CH, ?_⟩ + intro q _ χ hreal hprim hne hfield + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hsource⟩ := + source_character_global_greedy_determinant_local_bounds q χ hreal hprim hne hfield + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro N H hH hHN n + dsimp only + intro e he + obtain ⟨g, α, hg, hα, hrange, hmono, hweight, hstable, Δ, hΔ, hneΔ, + harch, hdiv, hraw⟩ := hsource N H hH hHN n e he + refine ⟨g, α, hg, hα, hrange, hmono, hweight, hstable, Δ, hΔ, hneΔ, + harch, hdiv, hraw, ?_⟩ + intro β hβ0 hβ1 hzero U hU + simpa only [Nat.cast_pow] using hCH H q χ hprim hne hreal β hβ0 hβ1 hzero + _ hdegree (N ^ 4) Δ hneΔ α hdiv U hU + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/CharacterGlobalGreedyDeterminantMasterBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CharacterGlobalGreedyDeterminantMasterBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..88251af4a1e892efff4aea326203c25cf1a5a58a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CharacterGlobalGreedyDeterminantMasterBounds.lean @@ -0,0 +1,171 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.CharacterGlobalGreedyDeterminantFullLocalBounds +import OAI.NumberTheory.Jacobsthal.Siegel.GlobalRectanglePivotBounds +import OAI.NumberTheory.Jacobsthal.Siegel.InvariantJetLinearMap +import OAI.NumberTheory.Jacobsthal.Siegel.NormalizedMasterBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_character_global_greedy_determinant_master_bounds : + ∃ C : ℝ, 0 < C ∧ Real.log 4 ≤ C ∧ ∃ CH : ℕ → ℝ, + ∀ (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)), + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ N H : ℕ, 0 < H → H ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * + ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + ∀ e : ℕ ≃ (Fin 3 → ℕ), Monotone (fun i => w (e i)) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ e) s.card : Set ℕ) ∧ + (∀ i, α i = e (g i)) ∧ + Set.range α = ((greedyPivots B (R ∘ e) s.card).image e : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ N ^ 4 - 1) ∧ + (∀ t : ℕ, s.card ≤ t → + Set.range g = (greedyPivots B (R ∘ e) t : Set ℕ)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + Δ ≠ 0 ∧ + ((1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p)) ∧ + (∀ U : ℝ, 0 ≤ U → + let P := (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ χ p = -1) + let E := fun p => ∑ i, α i 0 / p + let S₁ := ∑ i, (α i 0 : ℝ) + (∑ p ∈ P, (E p : ℝ) * Real.log p ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)|) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - + (N : ℝ) ^ 4 * (∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p) ≤ + ∑ p ∈ P, (E p : ℝ) * Real.log p) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - + Real.log 4 * (N : ℝ) ^ 4 * U ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)|) ) ∧ + (∀ β : ℝ, 0 < β → β < 1 → + DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ U : ℝ, 0 ≤ U → + (∑ i, (α i 0 : ℝ)) * + (Real.log U - C * Real.log q - + C * ((1 - β) * Real.log q) * (Real.log U) ^ 2 / Real.log q - CH H) - + C * (N : ℝ) ^ 4 * U ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| ) ∧ + (18818 ≤ N → + let P := (greedyPivots B (R ∘ e) s.card).image e + let S₁ := ∑ a ∈ P, (a 0 : ℝ) + let S₂ := ∑ a ∈ P, ((a 1 : ℝ) + a 2) + let M := (N : ℝ) ^ 4 + let U := (N : ℝ) ^ (4 / 3 : ℝ) + M * (H : ℝ) ^ (2 / 3 : ℝ) * U / (4 * 97 ^ 2) ≤ S₁ ∧ + S₂ ≤ 192 * M * (H : ℝ) ^ (-(1 / 3 : ℝ)) * U ∧ + 0 < S₁ ∧ + ∀ β : ℝ, 0 < β → β < 1 → + DirichletCharacter.LFunction χ (β : ℂ) = 0 → + 1 ≤ 3 / 4 * (1 + S₂ / S₁) + + (C + 1 / 2 * (1 + S₂ / S₁)) * (Real.log q / Real.log U) + + C * ((1 - β) * Real.log q) * (Real.log U / Real.log q) + + (CH H + (1 + S₂ / S₁) * Real.log 8) / Real.log U + + (C * M * U + 1 / 2 * M * Real.log M) / (S₁ * Real.log U)) := by + classical + obtain ⟨C, hC, hC4, CH, hlocal⟩ := + source_character_global_greedy_determinant_full_local_bounds + refine ⟨C, hC, hC4, CH, ?_⟩ + intro q _ χ hreal hprim hne hfield + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hsource⟩ := + hlocal q χ hreal hprim hne hfield + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro N H hH hHN n + dsimp only + intro e he + obtain ⟨g, α, hg, hα, hrange, hmono, hweight, hstable, Δ, hΔ, hneΔ, + harch, hdiv, hraw, hfinite⟩ := hsource N H hH hHN n e he + refine ⟨g, α, hg, hα, hrange, hmono, hweight, hstable, Δ, hΔ, hneΔ, + harch, hdiv, hraw, hfinite, ?_⟩ + intro hN + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let R := fun a : Fin 3 → ℕ => fun j => + θ j ^ a 0 * σ (θ j) ^ a 1 * (σ * τ) (θ j) ^ a 2 + let P := (greedyPivots B (R ∘ e) (weightedJetIndices H (N ^ 4 - 1)).card).image e + let U := (N : ℝ) ^ (4 / 3 : ℝ) + have hninj : Function.Injective (fun j i => (n j i : ℕ)) := by + intro j k h + apply n.injective + funext i + exact Fin.ext (congrFun h i) + have hspan := actual_biquadratic_rectangle_span a' b' v hv σ τ + hσa hσb hτa hτb H N hH hHN (fun j i => (n j i : ℕ)) hninj + (fun j i => (n j i).isLt) + have hpivots := global_source_rectangle_pivot_bounds H N hH hHN hN R e he α hrange hspan + have hNpos : (0 : ℝ) < N := by exact_mod_cast hH.trans_le hHN + have hHpos : (0 : ℝ) < H := by exact_mod_cast hH + have hS₁ : 0 < ∑ a ∈ P, (a 0 : ℝ) := lt_of_lt_of_le (by positivity) hpivots.1 + refine ⟨hpivots.1, hpivots.2, hS₁, ?_⟩ + intro β hβ0 hβ1 hzero + have hUone : 1 < U := by + exact Real.one_lt_rpow (by exact_mod_cast (show 1 < N by omega)) (by norm_num) + have hS₁eq := sum_embedding_eq_sum_finset_of_range α P hrange (fun a => (a 0 : ℝ)) + have hS₂eq := sum_embedding_eq_sum_finset_of_range α P hrange (fun a => ((a 1 : ℝ) + a 2)) + have hlower := hfinite β hβ0 hβ1 hzero U (le_of_lt (zero_lt_one.trans hUone)) + rw [hS₁eq, hS₂eq] at harch + rw [hS₁eq] at hlower + have hlogN : Real.log (N : ℝ) = 3 / 4 * Real.log U := by + dsimp only [U] + rw [Real.log_rpow hNpos] + ring + have hq : 1 < (q : ℝ) := by + exact_mod_cast (show 1 < q from lt_of_lt_of_le (by decide) (three_le_level_of_nonprincipal χ hne)) + exact FinalComparison.normalized_master_bound hS₁ (Real.log_pos hUone) + (Real.log_pos hq) hlogN harch hlower + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ClosureSpecMapZeroLocus.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ClosureSpecMapZeroLocus.lean new file mode 100644 index 0000000000000000000000000000000000000000..078c4e7aaf981d787a192162e1bb5036bdd9099d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ClosureSpecMapZeroLocus.lean @@ -0,0 +1,100 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeProjectivePoint + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +noncomputable section +open scoped BigOperators + + + +namespace WeightedTorusJets.Geometry + +open scoped BigOperators + +variable (K ι : Type*) [CommRing K] + +local notation "P" => MvPolynomial ι K +local notation "G" => ι →₀ ℤ +local notation "A" => AddMonoidAlgebra K G + +end WeightedTorusJets.Geometry + + + +namespace WeightedTorusJets.Geometry + +open CategoryTheory _root_.AlgebraicGeometry MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra + +universe uTorusChart + +theorem closure_specMap_zeroLocus + {A B : Type uTorusChart} [CommRing A] [CommRing B] + (f : A →+* B) (q : Ideal B) [q.IsPrime] : + closure ((Spec.map (CommRingCat.ofHom f)) '' PrimeSpectrum.zeroLocus (q : Set B)) = + PrimeSpectrum.zeroLocus (q.comap f : Set A) := by + rw [← PrimeSpectrum.closure_singleton (⟨q, inferInstance⟩ : PrimeSpectrum B)] + change closure (PrimeSpectrum.comap f '' closure ({⟨q, inferInstance⟩} : Set (PrimeSpectrum B))) = _ + refine (closure_image_closure (PrimeSpectrum.continuous_comap f)).trans ?_ + rw [Set.image_singleton] + exact PrimeSpectrum.closure_singleton _ + +theorem affineIntoProj_specMap_point + {K σ A : Type uTorusChart} [CommRing K] [CommRing A] + (f : MvPolynomial σ K →+* A) (q : Ideal A) [q.IsPrime] : + (Spec.map (CommRingCat.ofHom f) ≫ affineIntoProj (k := K) (fun i : σ => X i)) + ⟨q, inferInstance⟩ = coneProjectivePoint (q.comap f) := by + exact affineIntoProj_polynomial_point (q.comap f) + +theorem closure_affineIntoProj_specMap_zeroLocus + {K σ A : Type uTorusChart} [CommRing K] [CommRing A] + (f : MvPolynomial σ K →+* A) (q : Ideal A) [q.IsPrime] : + closure ((Spec.map (CommRingCat.ofHom f) ≫ affineIntoProj (k := K) (fun i : σ => X i)) '' + PrimeSpectrum.zeroLocus (q : Set A)) = + ProjectiveSpectrum.zeroLocus (homogeneousSubmodule (Option σ) K) (coneIdeal (q.comap f)) := by + rw [← PrimeSpectrum.closure_singleton (⟨q, inferInstance⟩ : PrimeSpectrum A)] + have hc : Continuous (fun x : PrimeSpectrum A => + ((Spec.map (CommRingCat.ofHom f) ≫ affineIntoProj (k := K) (fun i : σ => X i)) x : + ProjectiveSpectrum (homogeneousSubmodule (Option σ) K))) := + (Spec.map (CommRingCat.ofHom f) ≫ affineIntoProj (k := K) (fun i : σ => X i)).continuous + refine (closure_image_closure hc).trans ?_ + rw [Set.image_singleton] + exact (congrArg (fun x : ProjectiveSpectrum (homogeneousSubmodule (Option σ) K) => + closure ({x} : Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K)))) + (affineIntoProj_specMap_point f q)).trans (closure_coneProjectivePoint (q.comap f)) + +theorem closure_torusLocalization_intoProj_zeroLocus + {K : Type} [CommRing K] + (q : Ideal (Localization.Away (∏ i : Fin 4, (X i : MvPolynomial (Fin 4) K)))) [q.IsPrime] : + let f := algebraMap (MvPolynomial (Fin 4) K) + (Localization.Away (∏ i : Fin 4, (X i : MvPolynomial (Fin 4) K))) + closure ((Spec.map (CommRingCat.ofHom f) ≫ affineIntoProj (k := K) (fun i : Fin 4 => X i)) '' + PrimeSpectrum.zeroLocus (q : Set _)) = + ProjectiveSpectrum.zeroLocus (homogeneousSubmodule (Option (Fin 4)) K) + (coneIdeal (q.comap f)) := + closure_affineIntoProj_specMap_zeroLocus _ q + +theorem closure_laurentTorus_intoProj_zeroLocus + {K : Type} [CommRing K] + (q : Ideal (AddMonoidAlgebra K (Fin 4 →₀ ℤ))) [q.IsPrime] : + let f := (polynomialToLaurent K (Fin 4)).toRingHom + closure ((Spec.map (CommRingCat.ofHom f) ≫ affineIntoProj (k := K) (fun i : Fin 4 => X i)) '' + PrimeSpectrum.zeroLocus (q : Set _)) = + ProjectiveSpectrum.zeroLocus (homogeneousSubmodule (Option (Fin 4)) K) + (coneIdeal (q.comap f)) := + closure_affineIntoProj_specMap_zeroLocus _ q + +end WeightedTorusJets.Geometry + + +end + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoeffPolynomialEvalMul.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoeffPolynomialEvalMul.lean new file mode 100644 index 0000000000000000000000000000000000000000..6eed2b9aef2ec7c629086c9178f10f3f1440d106 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoeffPolynomialEvalMul.lean @@ -0,0 +1,58 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.Homogenize + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommSemiring K] + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem coeff_polynomial_eval₂_mul + {S : Type*} [CommSemiring S] (c : K →+* S) (x : σ → S) + (p : MvPolynomial σ K) (n : ℕ) : + ((p.eval₂ (Polynomial.C.comp c) + (fun i => Polynomial.C (x i) * Polynomial.X)).coeff n) = + (homogeneousComponent n p).eval₂ c x := by + classical + have hh (i : ℕ) : (homogeneousComponent i p).eval₂ (Polynomial.C.comp c) + (fun j => Polynomial.C (x j) * Polynomial.X) = + Polynomial.C ((homogeneousComponent i p).eval₂ c x) * Polynomial.X ^ i := by + rw [homogeneous_eval₂_mul (homogeneousComponent_isHomogeneous i p), + ← MvPolynomial.hom_eval₂] + conv_lhs => rw [← sum_homogeneousComponent p] + simp only [eval₂_sum, Polynomial.finsetSum_coeff, hh, Polynomial.coeff_C_mul_X_pow] + by_cases hn : n < p.totalDegree + 1 + · simp [hn] + · have hdegree : p.totalDegree < n := by omega + simp [hn, homogeneousComponent_eq_zero n p hdegree] + +theorem polynomial_eval₂_homogeneousComponent + {S : Type*} [CommSemiring S] (c : K →+* S) (x : σ → S) + (p : MvPolynomial σ K) (n : ℕ) : + (homogeneousComponent n p).eval₂ (Polynomial.C.comp c) + (fun i => Polynomial.C (x i) * Polynomial.X) = + Polynomial.C ((p.eval₂ (Polynomial.C.comp c) + (fun i => Polynomial.C (x i) * Polynomial.X)).coeff n) * Polynomial.X ^ n := by + rw [homogeneous_eval₂_mul (homogeneousComponent_isHomogeneous n p), + ← MvPolynomial.hom_eval₂, coeff_polynomial_eval₂_mul] + +end WeightedTorusJets.Geometry + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoefficientSubspaceEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoefficientSubspaceEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d36066fb388bfa35d28d26ee8187afd6ad3ea8a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoefficientSubspaceEquiv.lean @@ -0,0 +1,524 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.HilbertSeries + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +open scoped BigOperators +namespace WeightedTorusJets + +variable {K A M ι : Type*} [Field K] [CommRing A] [Algebra K A] + [AddCommGroup M] [Module K M] [Module A M] [IsScalarTower K A M] [Fintype ι] + +noncomputable def coefficientSubspaceEquiv (C : Submodule K A) (P : Submodule K M) + (v : ι → M) (hv : LinearIndependent A v) + (hmem : ∀ c : ι → C, ∑ i, (c i : A) • v i ∈ P) + (hrep : ∀ y ∈ P, ∃ c : ι → C, ∑ i, (c i : A) • v i = y) : + (ι → C) ≃ₗ[K] P := by + let f : (ι → C) →ₗ[K] M := + ((Fintype.linearCombination A v).restrictScalars K).comp + (LinearMap.pi fun i => C.subtype.comp (LinearMap.proj i)) + refine LinearEquiv.ofBijective (f.codRestrict P hmem) ⟨?_, ?_⟩ + · intro c d hcd + have heq : ∑ i, (c i : A) • v i = ∑ i, (d i : A) • v i := + congrArg Subtype.val hcd + funext i + exact Subtype.ext (hv.eq_coords_of_eq heq i) + · intro y + obtain ⟨c, hc⟩ := hrep y y.property + exact ⟨c, Subtype.ext hc⟩ + +@[simp] +theorem coefficientSubspaceEquiv_apply (C : Submodule K A) (P : Submodule K M) + (v : ι → M) (hv : LinearIndependent A v) + (hmem : ∀ c : ι → C, ∑ i, (c i : A) • v i ∈ P) + (hrep : ∀ y ∈ P, ∃ c : ι → C, ∑ i, (c i : A) • v i = y) (c : ι → C) : + (coefficientSubspaceEquiv C P v hv hmem hrep c : M) = ∑ i, (c i : A) • v i := + rfl + +theorem finrank_coefficient_subspace (C : Submodule K A) (P : Submodule K M) + (v : ι → M) (hv : LinearIndependent A v) + (hmem : ∀ c : ι → C, ∑ i, (c i : A) • v i ∈ P) + (hrep : ∀ y ∈ P, ∃ c : ι → C, ∑ i, (c i : A) • v i = y) : + Module.finrank K P = Fintype.card ι * Module.finrank K C := by + rw [← (coefficientSubspaceEquiv C P v hv hmem hrep).finrank_eq] + simp [Module.finrank] + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem finrank_homogeneous_span {K A M : Type*} [Field K] [CommRing A] + [Algebra K A] [AddCommGroup M] [Module K M] [Module A M] [IsScalarTower K A M] + (𝒜 : ℕ → Submodule K A) [GradedAlgebra 𝒜] + (ℳ : ℕ → Submodule K M) [DirectSum.Decomposition ℳ] [SetLike.GradedSMul 𝒜 ℳ] + {r D n : ℕ} (v : Fin r → M) (hv : ∀ i, v i ∈ ℳ D) + (hlin : LinearIndependent A v) (hn : D ≤ n) : + Module.finrank K ↥(ℳ n ⊓ (Submodule.span A (Set.range v)).restrictScalars K) = + r * Module.finrank K (𝒜 (n - D)) := by + simpa only [Fintype.card_fin] using finrank_coefficient_subspace (𝒜 (n - D)) + (ℳ n ⊓ (Submodule.span A (Set.range v)).restrictScalars K) v hlin + (homogeneous_coefficients_sum_mem 𝒜 ℳ v hv hn) + (fun y hy => exists_homogeneous_coefficients 𝒜 ℳ v hv hn y hy.1 hy.2) + +end WeightedTorusJets + +open scoped BigOperators DirectSum + +namespace WeightedTorusJets.Geometry + +theorem exists_finset_homogeneous_span_eq_top + {A K M : Type*} [CommRing A] [Field K] [AddCommGroup M] + [Module A M] [Module K M] [Module.Finite A M] + (𝓜 : ℕ → Submodule K M) [DirectSum.Decomposition 𝓜] : + ∃ s : Finset M, Submodule.span A (s : Set M) = ⊤ ∧ + ∀ x ∈ s, ∃ n, x ∈ 𝓜 n := by + classical + obtain ⟨s, hs⟩ := Module.Finite.fg_top (R := A) (M := M) + let t := s.biUnion fun x => (DirectSum.decompose 𝓜 x).support.image + fun n => (DirectSum.decompose 𝓜 x n : M) + refine ⟨t, ?_, ?_⟩ + · apply top_unique + rw [← hs] + apply Submodule.span_le.mpr + intro x hx + rw [← DirectSum.sum_support_decompose 𝓜 x] + apply Submodule.sum_mem + intro n hn + apply Submodule.subset_span + exact Finset.mem_biUnion.mpr ⟨x, hx, Finset.mem_image.mpr ⟨n, hn, rfl⟩⟩ + · intro x hx + obtain ⟨y, _, hy⟩ := Finset.mem_biUnion.mp hx + obtain ⟨n, _, rfl⟩ := Finset.mem_image.mp hy + exact ⟨n, (DirectSum.decompose 𝓜 y n).property⟩ + +theorem exists_homogeneous_generic_basis + {A K M F N : Type*} [CommRing A] [Field K] [Field F] + [AddCommGroup M] [AddCommGroup N] [Module A M] [Module K M] + [Algebra A F] [IsFractionRing A F] [Module A N] [Module F N] + [IsScalarTower A F N] [Module.Finite A M] + (𝓜 : ℕ → Submodule K M) [DirectSum.Decomposition 𝓜] + (f : M →ₗ[A] N) [IsLocalizedModule (nonZeroDivisors A) f] : + ∃ v : Fin (Module.finrank F N) → M, + ∃ b : Module.Basis (Fin (Module.finrank F N)) F N, + (∀ i, f (v i) = b i) ∧ + (∀ i, ∃ n, v i ∈ 𝓜 n) ∧ LinearIndependent A v := by + classical + have : Module.Finite F N := + Module.Finite.of_isLocalizedModule (nonZeroDivisors A) (Rₚ := F) f + have : FaithfulSMul A F := + (faithfulSMul_iff_algebraMap_injective A F).mpr (IsFractionRing.injective A F) + obtain ⟨s, hs, hhom⟩ := exists_finset_homogeneous_span_eq_top (A := A) 𝓜 + have hspan : Submodule.span F (f '' (s : Set M)) = ⊤ := + span_eq_top_of_isLocalizedModule F (nonZeroDivisors A) f hs + let ι := (linearIndepOn_empty F (id : N → N)).extend + (Set.empty_subset (f '' (s : Set M))) + let b₀ : Module.Basis ι F N := Module.Basis.ofSpan hspan.ge + let := Module.Finite.finite_basis b₀ + let := Fintype.ofFinite ι + let e := Fintype.equivFinOfCardEq (Module.finrank_eq_card_basis b₀).symm + let b := b₀.reindex e + have hpre (i : Fin (Module.finrank F N)) : ∃ x ∈ s, f x = b i := by + apply Module.Basis.ofSpan_subset hspan.ge + refine ⟨e.symm i, ?_⟩ + exact (Module.Basis.reindex_apply b₀ e i).symm + choose v hv hvf using hpre + refine ⟨v, b, hvf, fun i => hhom _ (hv i), ?_⟩ + have hcomp : f ∘ v = b := funext hvf + apply LinearIndependent.of_comp f + rw [hcomp] + exact b.linearIndependent.restrict_scalars' A + +theorem fraction_finrank_eq_pos + (B A K L : Type*) [CommRing B] [IsDomain B] [CommRing A] [IsDomain A] + [Field K] [Field L] [Algebra B A] [Algebra B K] [Algebra A L] [Algebra B L] + [Module K L] [IsScalarTower B K L] [IsScalarTower B A L] + [IsFractionRing B K] [IsFractionRing A L] + [Module.Finite B A] [Module.IsTorsionFree B A] : + Module.finrank K L = Module.finrank B A ∧ 0 < Module.finrank K L := by + have heq := IsFractionRing.finrank_eq B K A L + exact ⟨heq, heq.symm ▸ Module.finrank_pos (R := B) (M := A)⟩ + +theorem finrank_quotient_span_eq_zero_of_full_rank + {A M : Type*} [CommRing A] [IsDomain A] [AddCommGroup M] [Module A M] + [Module.Finite A M] {n : ℕ} {v : Fin n → M} + (hv : LinearIndependent A v) (hn : n = Module.finrank A M) : + Module.finrank A (M ⧸ Submodule.span A (Set.range v)) = 0 := by + have h := (Submodule.span A (Set.range v)).finrank_quotient_add_finrank + rw [finrank_span_eq_card hv, Fintype.card_fin] at h + omega + +theorem generic_fiber_finrank_eq + {A M F N : Type*} [CommRing A] [Field F] + [AddCommGroup M] [AddCommGroup N] [Module A M] + [Algebra A F] [IsFractionRing A F] [Module A N] [Module F N] + [IsScalarTower A F N] (f : M →ₗ[A] N) + [IsLocalizedModule (nonZeroDivisors A) f] : + Module.finrank F N = Module.finrank A M := + (IsLocalization.finrank_eq F (nonZeroDivisors A) le_rfl).trans + (IsLocalizedModule.finrank_eq (nonZeroDivisors A) f le_rfl) + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +theorem exists_common_degree_independent + {K A M ι : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [AddCommGroup M] [Module K M] [Module A M] [Fintype ι] + (𝓐 : ℕ → Submodule K A) [GradedAlgebra 𝓐] + (𝓜 : ℕ → Submodule K M) + [SetLike.GradedSMul 𝓐 𝓜] + {a : A} (ha0 : a ≠ 0) (ha1 : a ∈ 𝓐 1) + {v : ι → M} (hv : LinearIndependent A v) + (hhom : ∀ i, ∃ n, v i ∈ 𝓜 n) : + ∃ D : ℕ, ∃ w : ι → M, LinearIndependent A w ∧ ∀ i, w i ∈ 𝓜 D := by + classical + choose e he using hhom + let D := Finset.univ.sup e + let w := fun i => a ^ (D - e i) • v i + refine ⟨D, w, ?_, ?_⟩ + · apply Fintype.linearIndependent_iff.mpr + intro c hc i + have hc' : ∑ j, (c j * a ^ (D - e j)) • v j = 0 := by + simpa only [mul_smul] using hc + exact (mul_eq_zero.mp (Fintype.linearIndependent_iff.mp hv _ hc' i)).resolve_right + (pow_ne_zero _ ha0) + · intro i + have hei : e i ≤ D := Finset.le_sup (Finset.mem_univ i) + have ha : a ^ (D - e i) ∈ 𝓐 (D - e i) := by + simpa using SetLike.pow_mem_graded (D - e i) ha1 + have hw := SetLike.GradedSMul.smul_mem ha (he i) + simpa only [vadd_eq_add, Nat.sub_add_cancel hei] using hw + + + +variable {K A M : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [AddCommGroup M] [Module K M] [Module A M] [IsScalarTower K A M] + [Module.IsTorsionFree A M] + (𝓐 : ℕ → Submodule K A) (𝓜 : ℕ → Submodule K M) + [SetLike.GradedSMul 𝓐 𝓜] + +theorem finrank_gradedPiece_le_shifted_submodule + (N : Submodule A M) {b : A} {E : ℕ} (hb0 : b ≠ 0) (hb : b ∈ 𝓐 E) + (hN : ∀ m : M, b • m ∈ N) (n : ℕ) + [Module.Finite K (𝓜 (E + n))] : + Module.finrank K (𝓜 n) ≤ + Module.finrank K ↥((𝓜 (E + n)) ⊓ N.restrictScalars K) := by + have hle : (𝓜 (E + n)) ⊓ N.restrictScalars K ≤ 𝓜 (E + n) := inf_le_left + have : Module.Finite K ↥((𝓜 (E + n)) ⊓ N.restrictScalars K) := + Module.Finite.of_injective (Submodule.inclusion hle) (Submodule.inclusion_injective hle) + let f : 𝓜 n →ₗ[K] ↥((𝓜 (E + n)) ⊓ N.restrictScalars K) := + { toFun m := ⟨b • (m : M), + ⟨by + change b • (m : M) ∈ 𝓜 (E + n) + exact SetLike.GradedSMul.smul_mem hb m.property, + hN m⟩⟩ + map_add' m m' := by ext; exact smul_add b (m : M) m' + map_smul' c m := by ext; exact smul_comm b c (m : M) } + apply LinearMap.finrank_le_finrank_of_injective (f := f) + intro x y h + apply Subtype.ext + exact smul_right_injective M hb0 (congrArg Subtype.val h) + +omit [IsDomain A] [Module.IsTorsionFree A M] in + +theorem finrank_gradedSubmodule_le + (N : Submodule A M) (n : ℕ) [Module.Finite K (𝓜 n)] : + Module.finrank K ↥((𝓜 n) ⊓ N.restrictScalars K) ≤ Module.finrank K (𝓜 n) := + Submodule.finrank_mono inf_le_left + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem exists_hilbert_finrank_sandwich + {K A M : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [AddCommGroup M] [Module K M] [Module A M] [IsScalarTower K A M] + [Module.Finite A M] [Module.IsTorsionFree A M] + (𝓐 : ℕ → Submodule K A) [GradedAlgebra 𝓐] + (𝓜 : ℕ → Submodule K M) [DirectSum.Decomposition 𝓜] + [SetLike.GradedSMul 𝓐 𝓜] [∀ n, Module.Finite K (𝓜 n)] + {a : A} (ha0 : a ≠ 0) (ha1 : a ∈ 𝓐 1) + (d : ℕ) (hdim : ∀ n, Module.finrank K (𝓐 n) = (n + d).choose d) : + ∃ D E : ℕ, ∀ n, D ≤ n → + Module.finrank A M * ((n - D + d).choose d) ≤ Module.finrank K (𝓜 n) ∧ + Module.finrank K (𝓜 n) ≤ + Module.finrank A M * ((n + E - D + d).choose d) := by + classical + let f := LocalizedModule.mkLinearMap (nonZeroDivisors A) M + obtain ⟨v, _, _, hhom, hv⟩ := exists_homogeneous_generic_basis + (F := FractionRing A) 𝓜 f + have hr := generic_fiber_finrank_eq (F := FractionRing A) f + obtain ⟨D, w, hw, hwD⟩ := exists_common_degree_independent 𝓐 𝓜 ha0 ha1 hv hhom + let N := Submodule.span A (Set.range w) + have hN : N.IsHomogeneous 𝓜 := by + apply WeightedTorusJets.homogeneous_submodule_span 𝓐 𝓜 + rintro x ⟨i, rfl⟩ + exact ⟨D, hwD i⟩ + have hzero : Module.finrank A (M ⧸ N) = 0 := + finrank_quotient_span_eq_zero_of_full_rank hw hr + have hrank : Module.rank A (M ⧸ N) = 0 := by + rw [← Module.finrank_eq_rank, hzero, Nat.cast_zero] + obtain ⟨b, hb0, ⟨E, hbE⟩, hbN⟩ := + WeightedTorusJets.exists_homogeneous_annihilator_of_rank_zero 𝓐 𝓜 N hN hrank + refine ⟨D, E, fun n hn => ⟨?_, ?_⟩⟩ + · have h := finrank_gradedSubmodule_le 𝓜 N n + change Module.finrank K ↥(𝓜 n ⊓ (Submodule.span A (Set.range w)).restrictScalars K) ≤ _ at h + rw [WeightedTorusJets.finrank_homogeneous_span 𝓐 𝓜 w hwD hw hn, hr, hdim] at h + exact h + · have h := finrank_gradedPiece_le_shifted_submodule 𝓐 𝓜 N hb0 hbE hbN n + change _ ≤ Module.finrank K + ↥(𝓜 (E + n) ⊓ (Submodule.span A (Set.range w)).restrictScalars K) at h + rw [WeightedTorusJets.finrank_homogeneous_span 𝓐 𝓜 w hwD hw (by omega), hr, hdim] at h + simpa only [Nat.add_comm E n] using h + +end WeightedTorusJets.Geometry + +end + +section +namespace WeightedTorusJets.Geometry + +open Filter _root_.Polynomial + +theorem leadingCoeff_nonneg_of_eventually_nat_eval_nonneg (P : Polynomial ℚ) + (hpos : ∀ᶠ n : ℕ in atTop, 0 ≤ P.eval (n : ℚ)) : 0 ≤ P.leadingCoeff := by + by_cases hP : P = 0 + · simp [hP] + · exact (leadingCoeff_pos_of_eventually_nat_eval_nonneg P hP hpos).le + +theorem natDegree_leadingCoeff_eq_of_eventually_nat_eval_sandwich + (P L U : Polynomial ℚ) (d : ℕ) + (hL : L.natDegree = d) (hU : U.natDegree = d) + (hLU : L.leadingCoeff = U.leadingCoeff) (hpos : 0 < L.leadingCoeff) + (hlo : ∀ᶠ n : ℕ in atTop, L.eval (n : ℚ) ≤ P.eval (n : ℚ)) + (hhi : ∀ᶠ n : ℕ in atTop, P.eval (n : ℚ) ≤ U.eval (n : ℚ)) : + P.natDegree = d ∧ P.leadingCoeff = L.leadingCoeff := by + have hlo' : ∀ᶠ n : ℕ in atTop, 0 ≤ (P - L).eval (n : ℚ) := by + filter_upwards [hlo] with n hn + simpa only [eval_sub] using sub_nonneg.mpr hn + have hhi' : ∀ᶠ n : ℕ in atTop, 0 ≤ (U - P).eval (n : ℚ) := by + filter_upwards [hhi] with n hn + simpa only [eval_sub] using sub_nonneg.mpr hn + have hcPL := leadingCoeff_nonneg_of_eventually_nat_eval_nonneg (P - L) hlo' + have hcUP := leadingCoeff_nonneg_of_eventually_nat_eval_nonneg (U - P) hhi' + have hLne : L ≠ 0 := leadingCoeff_ne_zero.mp hpos.ne' + have hUne : U ≠ 0 := leadingCoeff_ne_zero.mp (hLU ▸ hpos.ne') + have hdegreeLU : L.degree = U.degree := by + rw [degree_eq_natDegree hLne, degree_eq_natDegree hUne, hL, hU] + have hdegLP : L.degree ≤ P.degree := by + by_contra h + rw [leadingCoeff_sub_of_degree_lt' (lt_of_not_ge h)] at hcPL + linarith + have hdegPU : P.degree ≤ U.degree := by + by_contra h + have hUP : U.degree < P.degree := lt_of_not_ge h + have hLP : L.degree < P.degree := hdegreeLU ▸ hUP + rw [leadingCoeff_sub_of_degree_lt hLP] at hcPL + rw [leadingCoeff_sub_of_degree_lt' hUP] at hcUP + have hPne : P ≠ 0 := ne_zero_of_degree_gt hUP + exact (leadingCoeff_ne_zero.mpr hPne) (by linarith) + have hdeg : P.degree = L.degree := le_antisymm (hdegPU.trans_eq hdegreeLU.symm) hdegLP + have hnat : P.natDegree = d := (natDegree_eq_natDegree hdeg).trans hL + refine ⟨hnat, ?_⟩ + have coeff_nonneg (Q : Polynomial ℚ) (hQ : Q.natDegree ≤ d) + (hQpos : ∀ᶠ n : ℕ in atTop, 0 ≤ Q.eval (n : ℚ)) : 0 ≤ Q.coeff d := by + rcases hQ.eq_or_lt with h | h + · rw [← h, coeff_natDegree] + exact leadingCoeff_nonneg_of_eventually_nat_eval_nonneg Q hQpos + · rw [coeff_eq_zero_of_natDegree_lt h] + have hsub₁ : (P - L).natDegree ≤ d := by + simpa only [hnat, hL, max_self] using natDegree_sub_le P L + have hsub₂ : (U - P).natDegree ≤ d := by + simpa only [hnat, hU, max_self] using natDegree_sub_le U P + have hcoeff₁ := coeff_nonneg (P - L) hsub₁ hlo' + have hcoeff₂ := coeff_nonneg (U - P) hsub₂ hhi' + have hcoeffP : P.coeff d = P.leadingCoeff := by rw [← hnat, coeff_natDegree] + have hcoeffL : L.coeff d = L.leadingCoeff := by rw [← hL, coeff_natDegree] + have hcoeffU : U.coeff d = U.leadingCoeff := by rw [← hU, coeff_natDegree] + rw [coeff_sub, hcoeffP, hcoeffL] at hcoeff₁ + rw [coeff_sub, hcoeffU, hcoeffP, ← hLU] at hcoeff₂ + linarith + +theorem natDegree_leadingCoeff_eq_of_eventually_binomial_sandwich + (P : Polynomial ℚ) (d D E r : ℕ) (hr : 0 < r) + (hlo : ∀ᶠ n : ℕ in atTop, + (r : ℚ) * ((n - D + d).choose d : ℚ) ≤ P.eval (n : ℚ)) + (hhi : ∀ᶠ n : ℕ in atTop, + P.eval (n : ℚ) ≤ (r : ℚ) * ((n + E - D + d).choose d : ℚ)) : + P.natDegree = d ∧ P.leadingCoeff = (r : ℚ) / (d.factorial : ℚ) := by + let L : Polynomial ℚ := (r : ℚ) • preHilbertPoly ℚ d D + let U : Polynomial ℚ := (r : ℚ) • + (preHilbertPoly ℚ d D).comp (Polynomial.X + Polynomial.C (E : ℚ)) + have hr0 : (r : ℚ) ≠ 0 := by exact_mod_cast hr.ne' + have hL : L.natDegree = d := by + dsimp [L] + rw [natDegree_smul _ hr0, natDegree_preHilbertPoly] + have hU : U.natDegree = d := by + dsimp [U] + rw [natDegree_smul _ hr0, natDegree_comp, natDegree_preHilbertPoly, + natDegree_add_C, natDegree_X, mul_one] + have hcL : L.leadingCoeff = (r : ℚ) / (d.factorial : ℚ) := by + rw [leadingCoeff, hL] + change ((r : ℚ) • preHilbertPoly ℚ d D).coeff d = _ + rw [coeff_smul, coeff_preHilbertPoly_self] + rfl + have hcU : U.leadingCoeff = (r : ℚ) / (d.factorial : ℚ) := by + have hcompdeg : ((preHilbertPoly ℚ d D).comp (X + C (E : ℚ))).natDegree = d := by + rw [natDegree_comp, natDegree_preHilbertPoly, natDegree_add_C, natDegree_X, mul_one] + have hcompcoeff : ((preHilbertPoly ℚ d D).comp (X + C (E : ℚ))).coeff d = + ((preHilbertPoly ℚ d D).comp (X + C (E : ℚ))).leadingCoeff := by + calc + _ = ((preHilbertPoly ℚ d D).comp (X + C (E : ℚ))).coeff + ((preHilbertPoly ℚ d D).comp (X + C (E : ℚ))).natDegree := + congrArg ((preHilbertPoly ℚ d D).comp (X + C (E : ℚ))).coeff hcompdeg.symm + _ = _ := coeff_natDegree + rw [leadingCoeff, hU] + change ((r : ℚ) • (preHilbertPoly ℚ d D).comp (X + C (E : ℚ))).coeff d = _ + rw [coeff_smul, hcompcoeff, + leadingCoeff_comp (by rw [natDegree_add_C, natDegree_X]; decide), + leadingCoeff_preHilbertPoly, leadingCoeff_X_add_C, one_pow, mul_one] + rfl + have hLpos : 0 < L.leadingCoeff := by rw [hcL]; positivity + have hL_eval : ∀ᶠ n : ℕ in atTop, L.eval (n : ℚ) ≤ P.eval (n : ℚ) := by + filter_upwards [hlo, eventually_ge_atTop D] with n hn hDn + have hind : n + d - D = n - D + d := by omega + simpa only [L, eval_smul, smul_eq_mul, + preHilbertPoly_eq_choose_add_sub ℚ d (by omega : D ≤ n + d), hind] using hn + have hU_eval : ∀ᶠ n : ℕ in atTop, P.eval (n : ℚ) ≤ U.eval (n : ℚ) := by + filter_upwards [hhi, eventually_ge_atTop D] with n hn hDn + have hind : n + E + d - D = n + E - D + d := by omega + simpa only [U, eval_smul, smul_eq_mul, eval_comp, eval_add, eval_X, eval_C, + ← Nat.cast_add, + preHilbertPoly_eq_choose_add_sub ℚ d (by omega : D ≤ n + E + d), hind] using hn + obtain ⟨hdeg, hlc⟩ := natDegree_leadingCoeff_eq_of_eventually_nat_eval_sandwich + P L U d hL hU (hcL.trans hcU.symm) hLpos hL_eval hU_eval + exact ⟨hdeg, hlc.trans hcL⟩ + +end WeightedTorusJets.Geometry +end + +section +namespace WeightedTorusJets.Geometry + +open Filter + +theorem hilbertPolynomial_degree_coefficient_eq_rank + {K A M : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [AddCommGroup M] [Module K M] [Module A M] [IsScalarTower K A M] + [Module.Finite A M] [Module.IsTorsionFree A M] [Nontrivial M] + (𝓐 : ℕ → Submodule K A) [GradedAlgebra 𝓐] + (𝓜 : ℕ → Submodule K M) [DirectSum.Decomposition 𝓜] + [SetLike.GradedSMul 𝓐 𝓜] [∀ n, Module.Finite K (𝓜 n)] + {a : A} (ha0 : a ≠ 0) (ha1 : a ∈ 𝓐 1) + (d : ℕ) (hdim : ∀ n, Module.finrank K (𝓐 n) = (n + d).choose d) + (P : Polynomial ℚ) + (hP : ∀ᶠ n : ℕ in atTop, (Module.finrank K (𝓜 n) : ℚ) = P.eval (n : ℚ)) : + P.natDegree = d ∧ (d.factorial : ℚ) * P.leadingCoeff = (Module.finrank A M : ℚ) := by + obtain ⟨D, E, hDE⟩ := exists_hilbert_finrank_sandwich 𝓐 𝓜 ha0 ha1 d hdim + have hlo : ∀ᶠ n : ℕ in atTop, + (Module.finrank A M : ℚ) * ((n - D + d).choose d : ℚ) ≤ P.eval (n : ℚ) := by + filter_upwards [hP, eventually_ge_atTop D] with n hPn hn + rw [← hPn] + exact_mod_cast (hDE n hn).1 + have hhi : ∀ᶠ n : ℕ in atTop, + P.eval (n : ℚ) ≤ (Module.finrank A M : ℚ) * ((n + E - D + d).choose d : ℚ) := by + filter_upwards [hP, eventually_ge_atTop D] with n hPn hn + rw [← hPn] + exact_mod_cast (hDE n hn).2 + obtain ⟨hdeg, hlc⟩ := natDegree_leadingCoeff_eq_of_eventually_binomial_sandwich + P d D E (Module.finrank A M) (Module.finrank_pos (R := A) (M := M)) hlo hhi + refine ⟨hdeg, ?_⟩ + rw [hlc] + field_simp + +end WeightedTorusJets.Geometry +end + +section + +open scoped BigOperators DirectSum + +namespace WeightedTorusJets.Geometry + +variable {K M : Type*} [Field K] [AddCommGroup M] [Module K M] + (𝓜 : ℕ → Submodule K M) [DirectSum.Decomposition 𝓜] + (N : Submodule K M) + +theorem graded_quotient_coeLinearMap_injective (hN : N.IsHomogeneous 𝓜) : + Function.Injective + (DirectSum.coeLinearMap (fun n => (𝓜 n).map N.mkQ)) := by + classical + let 𝓠 := fun n => (𝓜 n).map N.mkQ + change Function.Injective (DirectSum.coeLinearMap 𝓠) + suffices hk : ∀ x : ⨁ i, 𝓠 i, DirectSum.coeLinearMap 𝓠 x = 0 → x = 0 by + intro x y hxy + exact sub_eq_zero.mp (hk (x - y) (by simp only [map_sub, hxy, sub_self])) + intro x hx + have hxsum : (∑ i ∈ x.support, (x i : M ⧸ N)) = 0 := by + simpa only [DirectSum.coeLinearMap_eq_dfinsuppSum, DFinsupp.sum] using hx + have hlift (i : ℕ) : ∃ m : M, m ∈ 𝓜 i ∧ N.mkQ m = (x i : M ⧸ N) := + (x i).property + choose m hm hmx using hlift + have hsum : (∑ i ∈ x.support, m i) ∈ N := by + apply (Submodule.Quotient.mk_eq_zero N).mp + change N.mkQ (∑ i ∈ x.support, m i) = 0 + rw [map_sum] + simpa only [hmx] using hxsum + apply DFinsupp.ext + intro i + by_cases hi : i ∈ x.support + · apply Subtype.ext + change (x i : M ⧸ N) = 0 + rw [← hmx i] + apply (Submodule.Quotient.mk_eq_zero N).mpr + have hmem := hN i hsum + have heq : (DirectSum.decompose 𝓜 (∑ j ∈ x.support, m j) i : M) = m i := by + rw [DirectSum.decompose_sum] + rw [DirectSum.sum_apply, AddSubmonoidClass.coe_finsetSum] + rw [Finset.sum_eq_single i] + · exact DirectSum.decompose_of_mem_same 𝓜 (hm i) + · intro j _ hji + exact DirectSum.decompose_of_mem_ne 𝓜 (hm j) hji + · exact fun hnot => (hnot hi).elim + rwa [heq] at hmem + · simpa only [DFinsupp.zero_apply] using DFinsupp.notMem_support_iff.mp hi + +theorem graded_quotient_coeLinearMap_surjective : + Function.Surjective + (DirectSum.coeLinearMap (fun n => (𝓜 n).map N.mkQ)) := by + classical + rw [← LinearMap.range_eq_top, DirectSum.range_coeLinearMap] + apply top_unique + intro x _ + obtain ⟨m, rfl⟩ := N.mkQ_surjective x + rw [← DirectSum.sum_support_decompose 𝓜 m, map_sum] + apply Submodule.sum_mem + intro n _ + apply le_iSup (fun n => (𝓜 n).map N.mkQ) n + exact Submodule.mem_map_of_mem (DirectSum.decompose 𝓜 m n).property + +@[instance_reducible] +noncomputable def gradedQuotientDecomposition (hN : N.IsHomogeneous 𝓜) : + DirectSum.Decomposition (fun n => (𝓜 n).map N.mkQ) := + (show DirectSum.IsInternal (fun n => (𝓜 n).map N.mkQ) from + ⟨graded_quotient_coeLinearMap_injective 𝓜 N hN, + graded_quotient_coeLinearMap_surjective 𝓜 N⟩).chooseDecomposition + +end WeightedTorusJets.Geometry + +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/CompletedLAnalyticOrderNeTop.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CompletedLAnalyticOrderNeTop.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c63ce37c897d2d489d7f5c73d9189b9f9e8ce26 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CompletedLAnalyticOrderNeTop.lean @@ -0,0 +1,294 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.E +import OAI.NumberTheory.Jacobsthal.Siegel.RealLogDerivConductorCompletedLDivisorTsum + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +open scoped BigOperators Topology + +section + +open Filter Set MeasureTheory +open scoped Topology + + + + +open Filter Set Asymptotics + + + + +namespace WeightedTorusJets + +open _root_.Complex _root_.Erdos970.Complex DirichletCharacter + +variable {q : ℕ} [NeZero q] + +theorem completedL_analyticOrderAt_ne_top (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) (s : ℂ) : analyticOrderAt (completedLFunction χ) s ≠ ⊤ := by + rw [ne_eq, AnalyticOnNhd.analyticOrderAt_eq_top_iff_eq_zero s + (differentiable_completedLFunction hχ).analyticAt] + intro hzero + have hnonzero := completedL_ne_zero_of_one_le_re χ hχ (s := 1) (by simp) + exact hnonzero (congrFun hzero 1) + +theorem completedL_analyticOrderNatAt_pos_iff (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) (s : ℂ) : + 0 < analyticOrderNatAt (completedLFunction χ) s ↔ completedLFunction χ s = 0 := by + rw [Nat.pos_iff_ne_zero, analyticOrderNatAt, ne_eq, ENat.toNat_eq_zero, + not_or, and_iff_left (completedL_analyticOrderAt_ne_top χ hχ s)] + exact ((differentiable_completedLFunction hχ).analyticAt s).analyticOrderAt_ne_zero + +theorem finite_completedL_zeros_on_compact (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) {K : Set ℂ} (hK : IsCompact K) : + {s ∈ K | completedLFunction χ s = 0}.Finite := by + have ha : AnalyticOnNhd ℂ (completedLFunction χ) Set.univ := + fun z _ => (differentiable_completedLFunction hχ).analyticAt z + have hz := ha.preimage_zero_mem_codiscrete + (completedL_ne_zero_of_one_le_re χ hχ (s := 1) (by simp)) + have hk := hK.finite_sdiff_of_mem_codiscreteWithin + ((Filter.codiscreteWithin_mono (Set.subset_univ K)) hz) + convert hk using 1 + ext s + simp + + + + + + +open _root_.Complex _root_.Erdos970.Complex DirichletCharacter + + +variable {q : ℕ} [NeZero q] {χ : DirichletCharacter ℂ q} + +local notation "ZeroIndices" => Σ z : ℂ, Fin (analyticOrderNatAt (conductorCompletedL χ) z) + + +end WeightedTorusJets + +namespace RealCharacterAnalysis + +open _root_.Complex _root_.Erdos970.Complex _root_.Erdos970.Complex.Hadamard + +theorem divisorCanonicalProduct_eq_tprod_analytic {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (h0 : f 0 ≠ 0) (m : ℕ) (s : ℂ) : + divisorCanonicalProduct m f Set.univ s = + ∏' p : Σ z : ℂ, Fin (analyticOrderNatAt f z), weierstrassFactor m (s / p.1) := by + simpa only [divisorCanonicalProduct, divisorIndexEquivAnalytic_val] using + (divisorIndexEquivAnalytic hf h0).tprod_eq (fun p => weierstrassFactor m (s / p.1)) + +end RealCharacterAnalysis +namespace WeightedTorusJets + +open _root_.Complex _root_.Erdos970.Complex DirichletCharacter _root_.Erdos970.Complex.Hadamard RealCharacterAnalysis + + +variable {q : ℕ} [NeZero q] {χ : DirichletCharacter ℂ q} + +local notation "DivisorIndices" => divisorZeroIndex₀ (conductorCompletedL χ) Set.univ + + +end WeightedTorusJets + + + +end +section + +open scoped Classical + +namespace WeightedTorusJets + +theorem gammaFactor_real_parity_argument {q : ℕ} + (χ : DirichletCharacter ℂ q) (s : ℝ) : + χ.gammaFactor (s : ℂ) = + Complex.Gammaℝ ((s + (1 - (χ (-1)).re) / 2 : ℝ) : ℂ) := by + rw [character_parity_parameter_real] + by_cases h : χ.Even <;> simp [DirichletCharacter.gammaFactor, h] + +end WeightedTorusJets + +end +section + +open Filter Set +open scoped Topology + +namespace WeightedTorusJets + +theorem exists_upper_bound_zeta_logDeriv_log : + ∃ C : ℝ, 0 < C ∧ ∀ X : ℝ, 3 ≤ X → + (-logDeriv riemannZeta ((1 + 1 / Real.log X : ℝ) : ℂ)).re ≤ Real.log X + C := by + obtain ⟨C, hC, hbound⟩ := exists_upper_bound_zeta_logDeriv_re + refine ⟨C, hC, ?_⟩ + intro X hX + have hlog : 1 < Real.log X := (Real.lt_log_iff_exp_lt (by linarith)).mpr + (Real.exp_one_lt_three.trans_le hX) + have hpos : 0 < 1 / Real.log X := one_div_pos.mpr (by linarith) + have hle : 1 / Real.log X ≤ 1 := by + simpa using one_div_le_one_div_of_le (by norm_num : (0 : ℝ) < 1) hlog.le + simpa using hbound (1 + 1 / Real.log X) (by linarith) (by linarith) + +end WeightedTorusJets +end + +open _root_.Complex _root_.Erdos970.Complex Filter +open scoped Topology ComplexConjugate + +namespace RealCharacterAnalysis + +theorem quadratic_prime_values {q p : ℕ} (χ : DirichletCharacter ℂ q) + (hχ : χ.IsQuadratic) (hp : p.Prime) (hpq : ¬ p ∣ q) : + χ (p : ZMod q) = 1 ∨ χ (p : ZMod q) = -1 := by + rcases hχ (p : ZMod q) with h | h + · exact (hpq ((apply_prime_eq_zero_iff χ hp).mp h)).elim + · exact h + +theorem deriv_lFunction_conj {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (s : ℂ) : + deriv (DirichletCharacter.LFunction χ⁻¹) (conj s) = + conj (deriv (DirichletCharacter.LFunction χ) s) := by + have heq : DirichletCharacter.LFunction χ⁻¹ = + conj ∘ DirichletCharacter.LFunction χ ∘ conj := by + funext z + simpa using lFunction_conj χ hχ (conj z) + rw [heq, deriv_conj_conj] + simp + +theorem deriv_lFunction_real {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + (hr : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + (deriv (DirichletCharacter.LFunction χ) (s : ℂ)).im = 0 := by + apply Complex.conj_eq_iff_im.mp + rw [← deriv_lFunction_conj χ hχ, Complex.conj_ofReal, + ((real_values_iff_quadratic χ).mp hr).inv] + +theorem logarithmic_derivative_real {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + (hr : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + (deriv (DirichletCharacter.LFunction χ) (s : ℂ) / + DirichletCharacter.LFunction χ (s : ℂ)).im = 0 := by + simp [Complex.div_im, deriv_lFunction_real χ hχ hr, lFunction_real χ hχ hr] + +theorem quadratic_nonprincipal_has_negative_value {q : ℕ} + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (hr : χ.IsQuadratic) : + ∃ a : (ZMod q)ˣ, χ a = -1 := by + obtain ⟨a, ha⟩ := MulChar.ne_one_iff.mp hχ + refine ⟨a, ?_⟩ + rcases hr a with h | h | h + · exact ((MulChar.apply_ne_zero_iff.mpr a.isUnit) h).elim + · exact (ha h).elim + · exact h + +theorem gammaR_conj (s : ℂ) : Gammaℝ (conj s) = conj (Gammaℝ s) := by + have hp : (Real.pi : ℂ) ^ conj (-s / 2) = conj ((Real.pi : ℂ) ^ (-s / 2)) := by + simpa using Complex.cpow_conj (Real.pi : ℂ) (-s / 2) + (by simp [Complex.arg_ofReal_of_nonneg Real.pi_pos.le, Real.pi_ne_zero.symm]) + simpa only [Gammaℝ_def, map_mul, map_div₀, map_neg, map_ofNat] using congrArg₂ (fun a b : ℂ => a * b) hp + (Complex.Gamma_conj (s / 2)) + +theorem gammaFactor_inv_conj {q : ℕ} + (χ : DirichletCharacter ℂ q) (s : ℂ) : + DirichletCharacter.gammaFactor χ⁻¹ (conj s) = + conj (DirichletCharacter.gammaFactor χ s) := by + have hpar : χ⁻¹.Even ↔ χ.Even := by + rw [← MulChar.star_eq_inv] + change conj (χ (-1)) = 1 ↔ χ (-1) = 1 + constructor + · intro h + apply (starRingEnd ℂ).injective + simpa only [map_one] using h + · intro h + simp only [h, map_one] + classical + by_cases he : χ.Even + · rw [DirichletCharacter.gammaFactor, DirichletCharacter.gammaFactor, + ite_eq_left he, ite_eq_left (hpar.mpr he)] + exact gammaR_conj s + · rw [DirichletCharacter.gammaFactor, DirichletCharacter.gammaFactor, + ite_eq_right he, ite_eq_right (fun h => he (hpar.mp h))] + simpa only [map_add, map_one] using gammaR_conj (s + 1) + +theorem completed_lFunction_conj {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (s : ℂ) : + DirichletCharacter.completedLFunction χ⁻¹ (conj s) = + conj (DirichletCharacter.completedLFunction χ s) := by + have hi : χ⁻¹ ≠ 1 := inv_ne_one.mpr hχ + have hf := DirichletCharacter.differentiable_completedLFunction hi + have hg : Differentiable ℂ + (conj ∘ DirichletCharacter.completedLFunction χ ∘ conj) := by + intro z + simpa using + (DirichletCharacter.differentiable_completedLFunction hχ (conj z)).conj_conj + have heq : DirichletCharacter.completedLFunction χ⁻¹ = + conj ∘ DirichletCharacter.completedLFunction χ ∘ conj := by + apply (hf.differentiableOn.analyticOnNhd isOpen_univ).eq_of_eventuallyEq + (hg.differentiableOn.analyticOnNhd isOpen_univ) + have hn : {z : ℂ | 0 < z.re} ∈ nhds (1 : ℂ) := + (isOpen_lt continuous_const continuous_re).mem_nhds (by norm_num) + filter_upwards [hn] with z hz + have hz0 : z ≠ 0 := by rintro rfl; simp at hz + have hgamma : DirichletCharacter.gammaFactor χ⁻¹ z ≠ 0 := by + rcases χ⁻¹.even_or_odd with heven | hodd + · rw [heven.gammaFactor_def] + exact Gammaℝ_ne_zero_of_re_pos hz + · rw [hodd.gammaFactor_def] + apply Gammaℝ_ne_zero_of_re_pos + simp only [add_re, one_re] + linarith + have h := lFunction_conj χ hχ (conj z) + simp only [Complex.conj_conj] at h + rw [DirichletCharacter.LFunction_eq_completed_div_gammaFactor χ⁻¹ z (.inl hz0), + DirichletCharacter.LFunction_eq_completed_div_gammaFactor χ (conj z) + (.inl (by simpa using hz0)), map_div₀, + ← gammaFactor_inv_conj, Complex.conj_conj] at h + exact (div_left_inj' hgamma).mp h + simpa using congrFun heq (conj s) + +theorem completed_lFunction_real {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + (hr : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + (DirichletCharacter.completedLFunction χ (s : ℂ)).im = 0 := by + apply Complex.conj_eq_iff_im.mp + rw [← completed_lFunction_conj χ hχ, Complex.conj_ofReal, + ((real_values_iff_quadratic χ).mp hr).inv] + +theorem deriv_completed_lFunction_conj {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (s : ℂ) : + deriv (DirichletCharacter.completedLFunction χ⁻¹) (conj s) = + conj (deriv (DirichletCharacter.completedLFunction χ) s) := by + have heq : DirichletCharacter.completedLFunction χ⁻¹ = + conj ∘ DirichletCharacter.completedLFunction χ ∘ conj := by + funext z + simpa using completed_lFunction_conj χ hχ (conj z) + rw [heq, deriv_conj_conj] + simp + +theorem deriv_completed_lFunction_real {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + (hr : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + (deriv (DirichletCharacter.completedLFunction χ) (s : ℂ)).im = 0 := by + apply Complex.conj_eq_iff_im.mp + rw [← deriv_completed_lFunction_conj χ hχ, Complex.conj_ofReal, + ((real_values_iff_quadratic χ).mp hr).inv] + +theorem logDeriv_completed_lFunction_real {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + (hr : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + (logDeriv (DirichletCharacter.completedLFunction χ) (s : ℂ)).im = 0 := by + simp [logDeriv, Complex.div_im, deriv_completed_lFunction_real χ hχ hr, + completed_lFunction_real χ hχ hr] + +end RealCharacterAnalysis + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConductorCompletedL.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConductorCompletedL.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ce0837a6b00d903389f9a0d3148b9e741dd1c93 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConductorCompletedL.lean @@ -0,0 +1,548 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.MellinConvergentTopIndicator + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section AnalyticAssemblyScope +open scoped BigOperators Topology +section +open Filter Set MeasureTheory +open scoped Topology +open Filter Set Asymptotics +namespace WeightedTorusJets + +open _root_.Complex _root_.Erdos970.Complex DirichletCharacter + +variable {q : ℕ} [NeZero q] + +noncomputable def conductorCompletedL (χ : DirichletCharacter ℂ q) (s : ℂ) : ℂ := + (q : ℂ) ^ (s / 2) * completedLFunction χ s + +omit [NeZero q] in +theorem gammaFactor_ne_zero_of_re_pos (χ : DirichletCharacter ℂ q) {s : ℂ} + (hs : 0 < s.re) : gammaFactor χ s ≠ 0 := by + rcases χ.even_or_odd with heven | hodd + · rw [heven.gammaFactor_def] + exact Gammaℝ_ne_zero_of_re_pos hs + · rw [hodd.gammaFactor_def] + apply Gammaℝ_ne_zero_of_re_pos + simp only [add_re, one_re] + linarith + +theorem completedL_eq_mul_gammaFactor (χ : DirichletCharacter ℂ q) {s : ℂ} + (hs : 0 < s.re) : + completedLFunction χ s = LFunction χ s * gammaFactor χ s := by + have hs0 : s ≠ 0 := by rintro rfl; simp at hs + rw [LFunction_eq_completed_div_gammaFactor χ s (.inl hs0)] + exact (div_mul_cancel₀ _ (gammaFactor_ne_zero_of_re_pos χ hs)).symm + +theorem completedL_ne_zero_of_one_le_re (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) {s : ℂ} (hs : 1 ≤ s.re) : completedLFunction χ s ≠ 0 := by + have hs0 : 0 < s.re := lt_of_lt_of_le zero_lt_one hs + rw [completedL_eq_mul_gammaFactor χ hs0] + exact mul_ne_zero (LFunction_ne_zero_of_one_le_re χ (.inl hχ) hs) + (gammaFactor_ne_zero_of_re_pos χ hs0) + +theorem conductorCompletedL_zero_iff (χ : DirichletCharacter ℂ q) (s : ℂ) : + conductorCompletedL χ s = 0 ↔ completedLFunction χ s = 0 := by + simp [conductorCompletedL, Nat.cast_ne_zero.mpr (NeZero.ne q)] + +theorem differentiable_conductorCompletedL (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) : + Differentiable ℂ (conductorCompletedL χ) := by + apply Differentiable.mul + · exact (differentiable_id.div_const (2 : ℂ)).const_cpow + (Or.inl (Nat.cast_ne_zero.mpr (NeZero.ne q))) + · exact differentiable_completedLFunction hχ + +theorem conductorCompletedL_one_sub (χ : DirichletCharacter ℂ q) + (hχ : χ.IsPrimitive) (s : ℂ) : + conductorCompletedL χ (1 - s) = rootNumber χ * conductorCompletedL χ⁻¹ s := by + rw [conductorCompletedL, hχ.completedLFunction_one_sub, conductorCompletedL] + have hq : (q : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne q) + calc + (q : ℂ) ^ ((1 - s) / 2) * + ((q : ℂ) ^ (s - 1 / 2) * rootNumber χ * completedLFunction χ⁻¹ s) = + ((q : ℂ) ^ ((1 - s) / 2) * (q : ℂ) ^ (s - 1 / 2)) * + (rootNumber χ * completedLFunction χ⁻¹ s) := by ring + _ = (q : ℂ) ^ (s / 2) * (rootNumber χ * completedLFunction χ⁻¹ s) := by + rw [← Complex.cpow_add _ _ hq] + congr 2 + ring + _ = rootNumber χ * ((q : ℂ) ^ (s / 2) * completedLFunction χ⁻¹ s) := by ring + +theorem completedL_zero_re_mem_Ioo (χ : DirichletCharacter ℂ q) + (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) {ρ : ℂ} + (hρ : completedLFunction χ ρ = 0) : ρ.re ∈ Set.Ioo (0 : ℝ) 1 := by + have hinv : χ⁻¹.IsPrimitive := by + simpa only [DirichletCharacter.IsPrimitive, conductor_inv] using hχ + have hinv1 : χ⁻¹ ≠ 1 := inv_ne_one.mpr hχ1 + constructor + · by_contra! hn + have hz : completedLFunction χ⁻¹ (1 - ρ) = 0 := by + rw [hinv.completedLFunction_one_sub, inv_inv, hρ, mul_zero] + exact completedL_ne_zero_of_one_le_re χ⁻¹ hinv1 (by simp only [sub_re, one_re]; linarith) hz + · by_contra! hn + exact completedL_ne_zero_of_one_le_re χ hχ1 hn hρ + +theorem conductorCompletedL_logDeriv (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + {s : ℂ} (hs : completedLFunction χ s ≠ 0) : + logDeriv (conductorCompletedL χ) s = + Complex.log (q : ℂ) / 2 + logDeriv (completedLFunction χ) s := by + have hq : (q : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne q) + have hpow : (q : ℂ) ^ (s / 2) ≠ 0 := Complex.cpow_ne_zero_iff.mpr (.inl hq) + have hd : HasDerivAt (fun z : ℂ => (q : ℂ) ^ (z / 2)) + ((q : ℂ) ^ (s / 2) * Complex.log (q : ℂ) * (1 / 2)) s := by + simpa only [id_eq] using + ((hasDerivAt_id s).div_const (2 : ℂ)).const_cpow (.inl hq) + have hl : logDeriv (fun z : ℂ => (q : ℂ) ^ (z / 2)) s = + Complex.log (q : ℂ) / 2 := by + rw [logDeriv_apply, hd.deriv] + field_simp + exact (logDeriv_fun_mul s hpow hs hd.differentiableAt + (differentiable_completedLFunction hχ s)).trans (congrArg (· + _) hl) + +theorem completedL_eq_poleFree (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (s : ℂ) : + completedLFunction χ s = ZMod.completedLFunction₀ χ s := by + have hq : q ≠ 1 := hχ ∘ level_one' _ + simp [completedLFunction, ZMod.completedLFunction_eq, χ.map_zero' hq, + χ.sum_eq_zero_of_ne_one hχ] + +theorem conductorCompletedL_eq_hurwitzSum (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) (s : ℂ) : + conductorCompletedL χ s = (q : ℂ) ^ (-s / 2) * + ((∑ j : ZMod q, χ j * HurwitzZeta.completedHurwitzZetaEven₀ (ZMod.toAddCircle j) s) + + ∑ j : ZMod q, χ j * HurwitzZeta.completedHurwitzZetaOdd (ZMod.toAddCircle j) s) := by + rw [conductorCompletedL, completedL_eq_poleFree χ hχ, ZMod.completedLFunction₀] + have hq : (q : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne q) + calc + _ = ((q : ℂ) ^ (s / 2) * (q : ℂ) ^ (-s)) * + ((∑ j : ZMod q, χ j * HurwitzZeta.completedHurwitzZetaEven₀ (ZMod.toAddCircle j) s) + + ∑ j : ZMod q, χ j * HurwitzZeta.completedHurwitzZetaOdd (ZMod.toAddCircle j) s) := by ring + _ = _ := by + rw [← Complex.cpow_add _ _ hq] + congr 2 + ring + +theorem norm_conductor_power_le (s : ℂ) : + ‖(q : ℂ) ^ (-s / 2)‖ ≤ Real.exp (Real.log (q : ℝ) * ‖s‖ / 2) := by + have hq : 0 < (q : ℝ) := Nat.cast_pos.mpr (NeZero.pos q) + have hq1 : 1 ≤ (q : ℝ) := by exact_mod_cast (NeZero.pos q) + change ‖((q : ℝ) : ℂ) ^ (-s / 2)‖ ≤ _ + rw [Complex.norm_cpow_eq_rpow_re_of_pos hq, Real.rpow_def_of_pos hq] + apply Real.exp_le_exp.mpr + simp only [Complex.div_ofNat_re, neg_re] + have hreal : -s.re ≤ ‖s‖ := (neg_le_abs s.re).trans (Complex.abs_re_le_norm s) + have := mul_le_mul_of_nonneg_left hreal (Real.log_nonneg hq1) + nlinarith + +theorem norm_conductorCompletedL_le_hurwitzSum (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) (s : ℂ) : + ‖conductorCompletedL χ s‖ ≤ Real.exp (Real.log (q : ℝ) * ‖s‖ / 2) * + ((∑ j : ZMod q, ‖HurwitzZeta.completedHurwitzZetaEven₀ (ZMod.toAddCircle j) s‖) + + ∑ j : ZMod q, ‖HurwitzZeta.completedHurwitzZetaOdd (ZMod.toAddCircle j) s‖) := by + have hsum : ∀ f : ZMod q → ℂ, ‖∑ j, χ j * f j‖ ≤ ∑ j, ‖f j‖ := by + intro f + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro j _ + rw [norm_mul] + exact mul_le_of_le_one_left (norm_nonneg _) (χ.norm_le_one j) + rw [conductorCompletedL_eq_hurwitzSum χ hχ s, norm_mul] + apply mul_le_mul (norm_conductor_power_le s) + ((norm_add_le _ _).trans (add_le_add (hsum _) (hsum _))) (norm_nonneg _) + (Real.exp_nonneg _) + +omit [NeZero q] in +theorem finite_uniform_exp_bound {ι : Type*} [Finite ι] (f : ι → ℂ → ℂ) + (r : ℂ → ℝ) (hr : ∀ z, 0 ≤ r z) + (hf : ∀ i, ∃ C > 0, ∀ z, ‖f i z‖ ≤ Real.exp (C * r z)) : + ∃ C > 0, ∀ i z, ‖f i z‖ ≤ Real.exp (C * r z) := by + choose c _ hc using hf + obtain ⟨B, hB⟩ := (Set.finite_range c).bddAbove + refine ⟨max B 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), fun i z => ?_⟩ + exact (hc i z).trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right + ((hB (Set.mem_range_self i)).trans (le_max_left _ _)) (hr z))) + +theorem conductorCompletedL_growth_of_hurwitz (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) + (he : ∀ j : ZMod q, ∃ C > 0, ∀ s : ℂ, + ‖HurwitzZeta.completedHurwitzZetaEven₀ (ZMod.toAddCircle j) s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ))) + (ho : ∀ j : ZMod q, ∃ C > 0, ∀ s : ℂ, + ‖HurwitzZeta.completedHurwitzZetaOdd (ZMod.toAddCircle j) s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ))) : + ∃ C > 0, ∀ s : ℂ, ‖conductorCompletedL χ s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := by + classical + let r : ℂ → ℝ := fun s => (1 + ‖s‖) ^ (3 / 2 : ℝ) + have hr : ∀ s, 0 ≤ r s := fun s => Real.rpow_nonneg (by positivity) _ + obtain ⟨E, hE, he⟩ := finite_uniform_exp_bound _ r hr he + obtain ⟨O, hO, ho⟩ := finite_uniform_exp_bound _ r hr ho + let B := max E O + have hB : 0 < B := lt_of_lt_of_le hE (le_max_left _ _) + have hq0 : 0 < (q : ℝ) := Nat.cast_pos.mpr (NeZero.pos q) + have hq1 : 1 ≤ (q : ℝ) := by exact_mod_cast (NeZero.pos q) + have hlog : 0 ≤ Real.log (q : ℝ) := Real.log_nonneg hq1 + refine ⟨Real.log (q : ℝ) / 2 + B + 2 * q, by positivity, fun s => ?_⟩ + have hr1 : 1 ≤ r s := Real.one_le_rpow (by simp) (by norm_num) + have hrs : ‖s‖ ≤ r s := (by linarith : ‖s‖ ≤ 1 + ‖s‖).trans + (Real.self_le_rpow_of_one_le (by simp) (by norm_num)) + have he' : ∀ j : ZMod q, + ‖HurwitzZeta.completedHurwitzZetaEven₀ (ZMod.toAddCircle j) s‖ ≤ + Real.exp (B * r s) := fun j => (he j s).trans + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right (le_max_left _ _) (hr s))) + have ho' : ∀ j : ZMod q, + ‖HurwitzZeta.completedHurwitzZetaOdd (ZMod.toAddCircle j) s‖ ≤ + Real.exp (B * r s) := fun j => (ho j s).trans + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right (le_max_right _ _) (hr s))) + have hsum : + ((∑ j : ZMod q, ‖HurwitzZeta.completedHurwitzZetaEven₀ (ZMod.toAddCircle j) s‖) + + ∑ j : ZMod q, ‖HurwitzZeta.completedHurwitzZetaOdd (ZMod.toAddCircle j) s‖) ≤ + (2 * q) * Real.exp (B * r s) := by + have h1 := Finset.sum_le_sum (fun j (_ : j ∈ (Finset.univ : Finset (ZMod q))) => he' j) + have h2 := Finset.sum_le_sum (fun j (_ : j ∈ (Finset.univ : Finset (ZMod q))) => ho' j) + simpa [Finset.sum_const, ZMod.card, nsmul_eq_mul, two_mul, add_mul] using add_le_add h1 h2 + have hcard : (2 * q : ℝ) ≤ Real.exp ((2 * q : ℝ) * r s) := by + have h1 : (2 * q : ℝ) ≤ (2 * q : ℝ) * r s := + le_mul_of_one_le_right (by positivity) hr1 + exact h1.trans ((by linarith : (2 * q : ℝ) * r s ≤ (2 * q : ℝ) * r s + 1).trans + (Real.add_one_le_exp _)) + calc + ‖conductorCompletedL χ s‖ ≤ Real.exp (Real.log (q : ℝ) * ‖s‖ / 2) * + ((2 * q) * Real.exp (B * r s)) := + (norm_conductorCompletedL_le_hurwitzSum χ hχ s).trans + (mul_le_mul_of_nonneg_left hsum (Real.exp_nonneg _)) + _ ≤ Real.exp ((Real.log (q : ℝ) / 2) * r s) * + (Real.exp ((2 * q : ℝ) * r s) * Real.exp (B * r s)) := by + apply mul_le_mul + · apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left hrs hlog] + · exact mul_le_mul_of_nonneg_right hcard (Real.exp_nonneg _) + · positivity + · positivity + _ = _ := by rw [← Real.exp_add, ← Real.exp_add]; congr 1; dsimp [r]; ring + +theorem conductorCompletedL_analyticOrderAt_eq (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) (s : ℂ) : + analyticOrderAt (conductorCompletedL χ) s = analyticOrderAt (completedLFunction χ) s := by + have hq : (q : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne q) + have ha : AnalyticAt ℂ (fun z : ℂ => (q : ℂ) ^ (z / 2)) s := + ((differentiable_id.div_const (2 : ℂ)).const_cpow (.inl hq)).analyticAt s + change analyticOrderAt ((fun z : ℂ => (q : ℂ) ^ (z / 2)) * completedLFunction χ) s = _ + rw [analyticOrderAt_mul ha ((differentiable_completedLFunction hχ).analyticAt s), + ha.analyticOrderAt_eq_zero.mpr (Complex.cpow_ne_zero_iff.mpr (.inl hq)), zero_add] + +theorem conductorCompletedL_ne_zero_at_zero (χ : DirichletCharacter ℂ q) + (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) : conductorCompletedL χ 0 ≠ 0 := by + intro hzero + have hstrip := completedL_zero_re_mem_Ioo χ hχ hχ1 + ((conductorCompletedL_zero_iff χ 0).mp hzero) + norm_num at hstrip + +theorem conductorCompletedL_analyticOrderNatAt_zero (χ : DirichletCharacter ℂ q) + (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) : + analyticOrderNatAt (conductorCompletedL χ) 0 = 0 := by + rw [analyticOrderNatAt, + analyticOrderAt_eq_zero.mpr (.inr (conductorCompletedL_ne_zero_at_zero χ hχ hχ1))] + rfl + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem conductorCompletedL_norm_growth {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) : + ∃ C > 0, ∀ s : ℂ, ‖conductorCompletedL χ s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := + conductorCompletedL_growth_of_hurwitz χ hχ + (fun j => exists_completedHurwitzZetaEven_zero_growth (ZMod.toAddCircle j)) + (fun j => exists_completedHurwitzZetaOdd_growth (ZMod.toAddCircle j)) + +theorem conductorCompletedL_log_growth {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) : + ∃ C > 0, ∀ s : ℂ, Real.log (1 + ‖conductorCompletedL χ s‖) ≤ + C * (1 + ‖s‖) ^ (3 / 2 : ℝ) := + log_norm_growth_of_norm_growth (conductorCompletedL_norm_growth χ hχ) + + + +open _root_.Erdos970.Complex.Hadamard + +variable {q : ℕ} [NeZero q] + +theorem conductorCompletedL_zeroIndex_vanishes (χ : DirichletCharacter ℂ q) + (hχ : χ ≠ 1) + (p : divisorZeroIndex₀ (conductorCompletedL χ) (Set.univ : Set ℂ)) : + conductorCompletedL χ (divisorZeroIndex₀Val p) = 0 := by + by_contra hnonzero + have ha : AnalyticOnNhd ℂ (conductorCompletedL χ) Set.univ := + fun z _ => (differentiable_conductorCompletedL χ hχ).analyticAt z + have hdiv : MeromorphicOn.divisor (conductorCompletedL χ) Set.univ + (divisorZeroIndex₀Val p) = 0 := by + rw [MeromorphicOn.AnalyticOnNhd.divisor_apply ha (Set.mem_univ _), + (ha _ (Set.mem_univ _)).analyticOrderAt_eq_zero.mpr hnonzero] + simp + exact divisorZeroIndex₀Val_mem_divisor_support p hdiv + +theorem conductorCompletedL_zeroIndex_re_mem_Ioo (χ : DirichletCharacter ℂ q) + (hp : χ.IsPrimitive) (hχ : χ ≠ 1) + (p : divisorZeroIndex₀ (conductorCompletedL χ) (Set.univ : Set ℂ)) : + (divisorZeroIndex₀Val p).re ∈ Set.Ioo (0 : ℝ) 1 := + completedL_zero_re_mem_Ioo χ hp hχ + ((conductorCompletedL_zero_iff χ _).mp (conductorCompletedL_zeroIndex_vanishes χ hχ p)) + +theorem conductorCompletedL_zeroIndex_summable_inv_sq (χ : DirichletCharacter ℂ q) + (hp : χ.IsPrimitive) (hχ : χ ≠ 1) : + Summable (fun p : divisorZeroIndex₀ (conductorCompletedL χ) (Set.univ : Set ℂ) => + ‖divisorZeroIndex₀Val p‖⁻¹ ^ (2 : ℕ)) := by + have hfloor : Nat.floor (3 / 2 : ℝ) = 1 := by + apply (Nat.floor_eq_iff (by norm_num)).mpr + norm_num + simpa [hfloor] using summable_norm_inv_pow_divisorZeroIndex₀_of_growth + (f := conductorCompletedL χ) (ρ := (3 / 2 : ℝ)) (by norm_num) + (differentiable_conductorCompletedL χ hχ) + ⟨0, conductorCompletedL_ne_zero_at_zero χ hp hχ⟩ + (conductorCompletedL_log_growth χ hχ) + +theorem conductorCompletedL_hadamard_factorization (χ : DirichletCharacter ℂ q) + (hp : χ.IsPrimitive) (hχ : χ ≠ 1) : + ∃ P : Polynomial ℂ, P.degree ≤ 1 ∧ ∀ s : ℂ, + conductorCompletedL χ s = Complex.exp (P.eval s) * + divisorCanonicalProduct 1 (conductorCompletedL χ) (Set.univ : Set ℂ) s := by + obtain ⟨P, hP, hfac⟩ := hadamard_factorization_of_growth + (f := conductorCompletedL χ) (ρ := (3 / 2 : ℝ)) (by norm_num) + (differentiable_conductorCompletedL χ hχ) + ⟨0, conductorCompletedL_ne_zero_at_zero χ hp hχ⟩ + (conductorCompletedL_log_growth χ hχ) + have hfloor : Nat.floor (3 / 2 : ℝ) = 1 := by + apply (Nat.floor_eq_iff (by norm_num)).mpr + norm_num + refine ⟨P, by simpa [hfloor] using hP, fun s => ?_⟩ + simpa [hfloor, conductorCompletedL_analyticOrderNatAt_zero χ hp hχ] using hfac s + +theorem conductorCompletedL_logDeriv_hasSum (χ : DirichletCharacter ℂ q) + (hp : χ.IsPrimitive) (hχ : χ ≠ 1) : + ∃ B : ℂ, ∀ s : ℂ, conductorCompletedL χ s ≠ 0 → + HasSum (fun p : divisorZeroIndex₀ (conductorCompletedL χ) (Set.univ : Set ℂ) => + 1 / (s - divisorZeroIndex₀Val p) + 1 / divisorZeroIndex₀Val p) + (logDeriv (conductorCompletedL χ) s - B) := by + obtain ⟨P, hP, hfac⟩ := conductorCompletedL_hadamard_factorization χ hp hχ + have hsum := conductorCompletedL_zeroIndex_summable_inv_sq χ hp hχ + refine ⟨P.coeff 1, fun s hs => ?_⟩ + have hsindex : ∀ p : divisorZeroIndex₀ (conductorCompletedL χ) (Set.univ : Set ℂ), + s ≠ divisorZeroIndex₀Val p := by + intro p hsp + exact hs (hsp ▸ conductorCompletedL_zeroIndex_vanishes χ hχ p) + have hprod : divisorCanonicalProduct 1 (conductorCompletedL χ) (Set.univ : Set ℂ) s ≠ 0 := + divisorCanonicalProduct_ne_zero_of_forall_ne 1 (conductorCompletedL χ) hsum hsindex + have hpd : P.derivative.eval s = P.coeff 1 := by + have heq := congrArg Polynomial.derivative (Polynomial.eq_X_add_C_of_degree_le_one hP) + simpa using congrArg (Polynomial.eval s) heq + have hdexp : HasDerivAt (fun z : ℂ => Complex.exp (P.eval z)) + (Complex.exp (P.eval s) * P.derivative.eval s) s := by + simpa only [Function.comp_def] using + ((Complex.hasDerivAt_exp (P.eval s)).comp s (P.hasDerivAt s)) + have hexp : logDeriv (fun z : ℂ => Complex.exp (P.eval z)) s = P.coeff 1 := by + rw [logDeriv_apply, hdexp.deriv, + hpd] + field_simp + have hlog : logDeriv (conductorCompletedL χ) s = P.coeff 1 + + ∑' p : divisorZeroIndex₀ (conductorCompletedL χ) (Set.univ : Set ℂ), + (1 / (s - divisorZeroIndex₀Val p) + 1 / divisorZeroIndex₀Val p) := by + calc + _ = logDeriv (fun z => Complex.exp (P.eval z) * + divisorCanonicalProduct 1 (conductorCompletedL χ) (Set.univ : Set ℂ) z) s := + congrArg (fun f : ℂ → ℂ => logDeriv f s) (funext hfac) + _ = _ := by + rw [logDeriv_fun_mul (f := fun z : ℂ => Complex.exp (P.eval z)) s + (Complex.exp_ne_zero (P.eval s)) hprod hdexp.differentiableAt + (differentiableAt_divisorCanonicalProduct_univ 1 (conductorCompletedL χ) hsum s), + hexp, logDeriv_divisorCanonicalProduct_one_eq_tsum_of_forall_ne hsum hsindex] + rw [hlog, add_sub_cancel_left] + exact (summable_logDerivTerms_divisorZeroIndex₀_of_summable_inv_sq hsum hsindex).hasSum + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem reflected_reciprocal_tsum {ι : Type*} (ρ : ι → ℂ) (e : ι ≃ ι) + (he : ∀ i, ρ (e i) = 1 - ρ i) : + ∑' i, (1 / ((-1 : ℂ) - ρ i)).re = -∑' i, (1 / ((2 : ℂ) - ρ i)).re := by + calc + ∑' i, (1 / ((-1 : ℂ) - ρ i)).re = + ∑' i, (1 / ((-1 : ℂ) - ρ (e i))).re := (e.tsum_eq _).symm + _ = ∑' i, -(1 / ((2 : ℂ) - ρ i)).re := by + apply tsum_congr + intro i + rw [he i, show (-1 : ℂ) - (1 - ρ i) = -((2 : ℂ) - ρ i) by ring, + div_neg, Complex.neg_re] + _ = -∑' i, (1 / ((2 : ℂ) - ρ i)).re := tsum_neg + + + +open _root_.Complex _root_.Erdos970.Complex DirichletCharacter + +theorem primitive_rootNumber_ne_zero {q : ℕ} [NeZero q] + {χ : DirichletCharacter ℂ q} (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) : + rootNumber χ ≠ 0 := by + intro hroot + have hzero : completedLFunction χ 2 = 0 := by + have h := hχ.completedLFunction_one_sub (-1) + norm_num [hroot] at h + exact h + exact completedL_ne_zero_of_one_le_re χ hχ1 (by norm_num) hzero + +theorem logDeriv_conductorCompletedL_one_sub {q : ℕ} [NeZero q] + {χ : DirichletCharacter ℂ q} (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) (s : ℂ) : + logDeriv (conductorCompletedL χ) (1 - s) = + -logDeriv (conductorCompletedL χ⁻¹) s := by + have hfun : (fun z => conductorCompletedL χ (1 - z)) = + (fun z => rootNumber χ * conductorCompletedL χ⁻¹ z) := + funext (conductorCompletedL_one_sub χ hχ) + have h := congrArg (fun f => logDeriv f s) hfun + rw [logDeriv_fun_comp (differentiable_conductorCompletedL χ hχ1 (1 - s)) + (by fun_prop), logDeriv_const_mul s _ (primitive_rootNumber_ne_zero hχ hχ1)] at h + simpa using congrArg Neg.neg h + +theorem analyticOrderAt_conductorCompletedL_one_sub {q : ℕ} [NeZero q] + {χ : DirichletCharacter ℂ q} (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) (s : ℂ) : + analyticOrderAt (conductorCompletedL χ) (1 - s) = + analyticOrderAt (conductorCompletedL χ⁻¹) s := by + have hfun : (fun z => conductorCompletedL χ (1 - z)) = + (fun z => rootNumber χ * conductorCompletedL χ⁻¹ z) := + funext (conductorCompletedL_one_sub χ hχ) + have hcomp : analyticOrderAt (fun z => conductorCompletedL χ (1 - z)) s = + analyticOrderAt (conductorCompletedL χ) (1 - s) := by + simpa only [Function.comp_def] using + (analyticOrderAt_comp_of_deriv_ne_zero (f := conductorCompletedL χ) (z₀ := s) + (g := fun z : ℂ => 1 - z) (by fun_prop) (by simp)) + have hconst : analyticOrderAt (fun _ : ℂ => rootNumber χ) s = 0 := + (analyticAt_const).analyticOrderAt_eq_zero.mpr (primitive_rootNumber_ne_zero hχ hχ1) + calc + analyticOrderAt (conductorCompletedL χ) (1 - s) = + analyticOrderAt (fun z => rootNumber χ * conductorCompletedL χ⁻¹ z) s := + hcomp.symm.trans (congrArg (fun f => analyticOrderAt f s) hfun) + _ = analyticOrderAt (fun _ : ℂ => rootNumber χ) s + + analyticOrderAt (conductorCompletedL χ⁻¹) s := by + exact analyticOrderAt_mul analyticAt_const + ((differentiable_conductorCompletedL χ⁻¹ (inv_ne_one.mpr hχ1)).analyticAt s) + _ = analyticOrderAt (conductorCompletedL χ⁻¹) s := by rw [hconst, zero_add] + +theorem completed_reciprocal_tsum_reflection {q : ℕ} [NeZero q] + {χ : DirichletCharacter ℂ q} (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) + (hquad : χ.IsQuadratic) : + (∑' j : Σ z : ℂ, Fin (analyticOrderNatAt (conductorCompletedL χ) z), + (1 / ((-1 : ℂ) - j.1)).re) = + -∑' j : Σ z : ℂ, Fin (analyticOrderNatAt (conductorCompletedL χ) z), + (1 / ((2 : ℂ) - j.1)).re := by + let e : (Σ z : ℂ, Fin (analyticOrderNatAt (conductorCompletedL χ) z)) ≃ + (Σ z : ℂ, Fin (analyticOrderNatAt (conductorCompletedL χ) z)) := + Equiv.sigmaCongr (Equiv.subLeft (1 : ℂ)) fun z => finCongr (by + unfold analyticOrderNatAt + apply congrArg ENat.toNat + simpa only [hquad.inv, Equiv.subLeft_apply] using + (analyticOrderAt_conductorCompletedL_one_sub hχ hχ1 z).symm) + exact reflected_reciprocal_tsum Sigma.fst e (fun _ => rfl) + +section RealPart + +variable {q : ℕ} [NeZero q] {χ : DirichletCharacter ℂ q} + +local notation "ZeroIndices" => Σ z : ℂ, Fin (analyticOrderNatAt (conductorCompletedL χ) z) + +theorem real_logDeriv_conductorCompletedL_eq_tsum + (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) (hquad : χ.IsQuadratic) (B : ℝ) + (hbase : Summable (fun j : ZeroIndices => (1 / j.1).re)) + (hexp : ∀ x : ℝ, x = -1 ∨ 1 < x → + HasSum (fun j : ZeroIndices => (1 / ((x : ℂ) - j.1) + 1 / j.1).re) + ((logDeriv (conductorCompletedL χ) (x : ℂ)).re - B)) + {s : ℝ} (hs : 1 < s) : + (logDeriv (conductorCompletedL χ) (s : ℂ)).re = + ∑' j : ZeroIndices, (1 / ((s : ℂ) - j.1)).re := by + let C : ℝ := ∑' j : ZeroIndices, (1 / j.1).re + have hsplit (x : ℝ) (hx : x = -1 ∨ 1 < x) : + (∑' j : ZeroIndices, (1 / ((x : ℂ) - j.1)).re) = + (logDeriv (conductorCompletedL χ) (x : ℂ)).re - B - C := by + apply HasSum.tsum_eq + convert (hexp x hx).sub hbase.hasSum using 1 + ext j + simp only [Complex.add_re, add_sub_cancel_right] + have hreflection : (logDeriv (conductorCompletedL χ) (-1)).re = + -(logDeriv (conductorCompletedL χ) 2).re := by + have h := logDeriv_conductorCompletedL_one_sub hχ hχ1 2 + rw [hquad.inv] at h + have harg : (1 - (2 : ℂ)) = -1 := by ring + simpa only [harg, Complex.neg_re] using congrArg Complex.re h + have hcancel : B + C = 0 := by + have htwo := hsplit 2 (.inr (by norm_num)) + have hneg := hsplit (-1) (.inl rfl) + have hzero := completed_reciprocal_tsum_reflection hχ hχ1 hquad + norm_num only [Complex.ofReal_ofNat, Complex.ofReal_neg, Complex.ofReal_one] at htwo hneg + linarith + rw [hsplit s (.inr hs)] + linarith + +end RealPart + +end WeightedTorusJets + +namespace RealCharacterAnalysis + +open _root_.Complex _root_.Erdos970.Complex _root_.Erdos970.Complex.Hadamard + +theorem toNat_divisor_eq_analyticOrderNatAt {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (z : ℂ) : + Int.toNat (MeromorphicOn.divisor f Set.univ z) = analyticOrderNatAt f z := by + have ha : AnalyticOnNhd ℂ f Set.univ := fun w _ => hf.analyticAt w + rw [MeromorphicOn.AnalyticOnNhd.divisor_apply ha (Set.mem_univ z)] + unfold analyticOrderNatAt + cases h : analyticOrderAt f z <;> simp + +noncomputable def divisorIndexEquivAnalytic {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (h0 : f 0 ≠ 0) : + divisorZeroIndex₀ f Set.univ ≃ Σ z : ℂ, Fin (analyticOrderNatAt f z) := by + have horder : analyticOrderNatAt f 0 = 0 := by + rw [analyticOrderNatAt, (hf.analyticAt 0).analyticOrderAt_eq_zero.mpr h0] + rfl + have horigin : ∀ p : divisorZeroIndex f Set.univ, p.1 ≠ 0 := by + rintro ⟨z, i⟩ hz + dsimp at hz + subst z + have hi : Fin 0 := by + simpa only [toNat_divisor_eq_analyticOrderNatAt hf, horder] using i + exact Fin.elim0 hi + exact (Equiv.subtypeUnivEquiv horigin).trans + (Equiv.sigmaCongrRight fun z => finCongr (toNat_divisor_eq_analyticOrderNatAt hf z)) + +theorem divisorIndexEquivAnalytic_val {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (h0 : f 0 ≠ 0) (p : divisorZeroIndex₀ f Set.univ) : + (divisorIndexEquivAnalytic hf h0 p).1 = divisorZeroIndex₀Val p := rfl + +theorem tsum_divisorIndex_eq_analytic {E : Type*} [NormedAddCommGroup E] {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (h0 : f 0 ≠ 0) (F : ℂ → E) : + (∑' p : divisorZeroIndex₀ f Set.univ, F (divisorZeroIndex₀Val p)) = + ∑' p : Σ z : ℂ, Fin (analyticOrderNatAt f z), F p.1 := by + simpa only [Function.comp_def, divisorIndexEquivAnalytic_val] using + (divisorIndexEquivAnalytic hf h0).tsum_eq (fun p => F p.1) + +theorem summable_divisorIndex_iff_analytic {E : Type*} [NormedAddCommGroup E] {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (h0 : f 0 ≠ 0) (F : ℂ → E) : + Summable (fun p : divisorZeroIndex₀ f Set.univ => F (divisorZeroIndex₀Val p)) ↔ + Summable (fun p : Σ z : ℂ, Fin (analyticOrderNatAt f z) => F p.1) := by + simpa only [Function.comp_def, divisorIndexEquivAnalytic_val] using + (divisorIndexEquivAnalytic hf h0).summable_iff (f := fun p => F p.1) + +end RealCharacterAnalysis + +end +end AnalyticAssemblyScope +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeChartHomogeneousLocal.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeChartHomogeneousLocal.lean new file mode 100644 index 0000000000000000000000000000000000000000..4013a7c9a22303f996e6b0111d5f6b18e3be935c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeChartHomogeneousLocal.lean @@ -0,0 +1,95 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.AffineProjChartPolynomialEquiv +import OAI.NumberTheory.Jacobsthal.Siegel.ConeProjectivePoint + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial HomogeneousLocalization _root_.AlgebraicGeometry + +attribute [local instance] MvPolynomial.gradedAlgebra coneIdeal_isPrime + +universe uProjLocal + +noncomputable def coneChartToHomogeneousLocal {K σ : Type uProjLocal} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + affineProjChart K σ →+* + HomogeneousLocalization.AtPrime (homogeneousSubmodule (Option σ) K) (coneIdeal p) := + HomogeneousLocalization.mapId _ + (Submonoid.powers_le.mpr (X_none_not_mem_coneIdeal p)) + +theorem projectiveLocal_isLocalization {K σ : Type uProjLocal} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + @IsLocalization (affineProjChart K σ) _ + (p.comap (affineProjChartPolynomialEquiv (K := K) (σ := σ)).toRingHom).primeCompl + (HomogeneousLocalization.AtPrime (homogeneousSubmodule (Option σ) K) (coneIdeal p)) _ + (coneChartToHomogeneousLocal p).toAlgebra := by + let C := affineProjChart K σ + let H := HomogeneousLocalization.AtPrime (homogeneousSubmodule (Option σ) K) (coneIdeal p) + let : Algebra C H := (coneChartToHomogeneousLocal p).toAlgebra + let x : ProjectiveSpectrum.basicOpen (homogeneousSubmodule (Option σ) K) (X (none : Option σ)) := + ⟨coneProjectivePoint p, coneProjectivePoint_mem_basicOpen p⟩ + let q : Ideal C := ((ProjectiveSpectrum.Proj.toSpec (homogeneousSubmodule (Option σ) K) + (X (none : Option σ))).base x).asIdeal + have hq : q = p.comap (affineProjChartPolynomialEquiv (K := K) (σ := σ)).toRingHom := by + change (Proj.basicOpenToSpec (homogeneousSubmodule (Option σ) K) (X (none : Option σ)) + ⟨coneProjectivePoint p, coneProjectivePoint_mem_basicOpen p⟩).asIdeal = _ + rw [basicOpenToSpec_coneProjectivePoint] + rfl + let : q.IsPrime := by rw [hq]; infer_instance + have hM : q.primeCompl = + (p.comap (affineProjChartPolynomialEquiv (K := K) (σ := σ)).toRingHom).primeCompl := by + apply Submonoid.ext + intro z + change z ∉ q ↔ z ∉ p.comap (affineProjChartPolynomialEquiv (K := K) (σ := σ)).toRingHom + rw [hq] + have h : @IsLocalization C _ q.primeCompl H _ (coneChartToHomogeneousLocal p).toAlgebra := + ProjectiveSpectrum.Proj.isLocalization_atPrime (homogeneousSubmodule (Option σ) K) + (X (none : Option σ)) x (isHomogeneous_X K (none : Option σ)) + (show 0 < (1 : ℕ) by decide) + rw [hM] at h + exact h + +noncomputable def projectiveLocalPolynomialEquiv {K σ : Type uProjLocal} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + HomogeneousLocalization.AtPrime (homogeneousSubmodule (Option σ) K) (coneIdeal p) ≃+* + Localization.AtPrime p := by + let C := affineProjChart K σ + let H := HomogeneousLocalization.AtPrime (homogeneousSubmodule (Option σ) K) (coneIdeal p) + let : Algebra C H := (coneChartToHomogeneousLocal p).toAlgebra + let e : C ≃+* MvPolynomial σ K := affineProjChartPolynomialEquiv + let : IsLocalization (p.comap e.toRingHom).primeCompl H := projectiveLocal_isLocalization p + refine IsLocalization.ringEquivOfRingEquiv (M := (p.comap e.toRingHom).primeCompl) + (T := p.primeCompl) H (Localization.AtPrime p) e ?_ + exact e.map_primeCompl_comap_eq p + +theorem projectiveLocalPolynomialEquiv_chart {K σ : Type uProjLocal} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (z : affineProjChart K σ) : + projectiveLocalPolynomialEquiv p (coneChartToHomogeneousLocal p z) = + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) + (affineProjChartMap (k := K) (fun i : σ => (X i : MvPolynomial σ K)) z) := by + let C := affineProjChart K σ + let H := HomogeneousLocalization.AtPrime (homogeneousSubmodule (Option σ) K) (coneIdeal p) + let : Algebra C H := (coneChartToHomogeneousLocal p).toAlgebra + let e : C ≃+* MvPolynomial σ K := affineProjChartPolynomialEquiv + let : IsLocalization (p.comap e.toRingHom).primeCompl H := projectiveLocal_isLocalization p + have hmap : (p.comap e.toRingHom).primeCompl.map e.toMonoidHom = p.primeCompl := by + exact e.map_primeCompl_comap_eq p + change IsLocalization.ringEquivOfRingEquiv (M := (p.comap e.toRingHom).primeCompl) + (T := p.primeCompl) H (Localization.AtPrime p) e hmap (algebraMap C H z) = + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (e z) + exact IsLocalization.ringEquivOfRingEquiv_eq hmap z + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeMap.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeMap.lean new file mode 100644 index 0000000000000000000000000000000000000000..1ea1c81c98dce701f4aad55268b5098310234464 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeMap.lean @@ -0,0 +1,430 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +noncomputable def coneMap (p : Ideal (MvPolynomial σ K)) : + MvPolynomial (Option σ) K →ₐ[K] Polynomial (MvPolynomial σ K ⧸ p) := + MvPolynomial.aeval (fun o : Option σ => o.elim Polynomial.X + (fun i => Polynomial.C (Ideal.Quotient.mk p (X i)) * Polynomial.X)) + +noncomputable def coneIdeal (p : Ideal (MvPolynomial σ K)) : + Ideal (MvPolynomial (Option σ) K) := RingHom.ker (coneMap p) + +noncomputable def coneDehomogenize : + MvPolynomial (Option σ) K →ₐ[K] MvPolynomial σ K := + MvPolynomial.aeval (fun o : Option σ => o.elim 1 X) + +@[simp] theorem coneMap_X_none (p : Ideal (MvPolynomial σ K)) : + coneMap p (X none) = Polynomial.X := by + simp [coneMap] + +@[simp] theorem coneMap_X_some (p : Ideal (MvPolynomial σ K)) (i : σ) : + coneMap p (X (some i)) = + Polynomial.C (Ideal.Quotient.mk p (X i)) * Polynomial.X := by + simp [coneMap] + +theorem coneIdeal_isPrime (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + (coneIdeal p).IsPrime := RingHom.ker_isPrime (coneMap p) + +theorem X_none_not_mem_coneIdeal (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + X none ∉ coneIdeal p := by + simpa only [coneIdeal, RingHom.mem_ker, coneMap_X_none] using + (Polynomial.X_ne_zero : (Polynomial.X : Polynomial (MvPolynomial σ K ⧸ p)) ≠ 0) + +theorem eval_one_coneMap (p : Ideal (MvPolynomial σ K)) + (f : MvPolynomial (Option σ) K) : + Polynomial.eval 1 (coneMap p f) = Ideal.Quotient.mk p (coneDehomogenize f) := by + have h : ((Polynomial.aeval (1 : MvPolynomial σ K ⧸ p)).restrictScalars K).comp + (coneMap p) = (Ideal.Quotient.mkₐ K p).comp coneDehomogenize := by + ext i + cases i <;> simp [coneMap, coneDehomogenize] + exact congrArg (fun g => g f) h + +theorem map_coneIdeal_dehomogenize_le (p : Ideal (MvPolynomial σ K)) : + Ideal.map coneDehomogenize.toRingHom (coneIdeal p) ≤ p := by + apply Ideal.map_le_iff_le_comap.mpr + intro f hf + change coneDehomogenize f ∈ p + apply Ideal.Quotient.eq_zero_iff_mem.mp + rw [← eval_one_coneMap] + simpa only [Polynomial.eval_zero] using + congrArg (Polynomial.eval 1) (show coneMap p f = 0 from hf) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry.DegreeBezout + +attribute [local instance] Polynomial.algebra Polynomial.isLocalization + +open Polynomial IsLocalRing + +theorem polynomial_local_coefficient_prime_map + {A : Type*} [CommRing A] (p : Ideal A) [p.IsPrime] : + (p.map (Polynomial.C : A →+* Polynomial A)).map + (algebraMap (Polynomial A) (Polynomial (Localization.AtPrime p))) = + (maximalIdeal (Localization.AtPrime p)).map Polynomial.C := by + rw [← (show p.map (algebraMap A (Localization.AtPrime p)) = + maximalIdeal (Localization.AtPrime p) from Localization.AtPrime.map_eq_maximalIdeal), + Ideal.map_map, Ideal.map_map] + congr 1 + ext a + simp + +theorem polynomial_coefficient_denominators_disjoint + {A : Type*} [CommRing A] (p : Ideal A) [p.IsPrime] : + Disjoint ((p.primeCompl.map Polynomial.C : Submonoid (Polynomial A)) : Set (Polynomial A)) + ((p.map Polynomial.C : Ideal (Polynomial A)) : Set (Polynomial A)) := by + apply Set.disjoint_left.mpr + rintro _ ⟨a, ha, rfl⟩ h + exact ha (by simpa using (Ideal.mem_map_C_iff.mp h) 0) + +noncomputable def polynomialLocalCoefficientPolyEquiv + {A : Type*} [CommRing A] (p : Ideal A) [p.IsPrime] : + Localization.AtPrime (p.map (Polynomial.C : A →+* Polynomial A)) ≃ₐ[Polynomial A] + Localization.AtPrime ((maximalIdeal (Localization.AtPrime p)).map Polynomial.C) := by + let M : Submonoid (Polynomial A) := p.primeCompl.map Polynomial.C + let q : Ideal (Polynomial (Localization.AtPrime p)) := + (maximalIdeal (Localization.AtPrime p)).map Polynomial.C + have ht := IsLocalization.isLocalization_isLocalization_atPrime_isLocalization + (M := M) (Localization.AtPrime q) q + have hq : q = (p.map Polynomial.C).map + (algebraMap (Polynomial A) (Polynomial (Localization.AtPrime p))) := + (polynomial_local_coefficient_prime_map p).symm + have he := IsLocalization.under_map_of_isPrime_disjoint M (Polynomial (Localization.AtPrime p)) + (show (p.map Polynomial.C).IsPrime from inferInstance) + (polynomial_coefficient_denominators_disjoint p) + rw [← hq] at he + change q.comap (algebraMap (Polynomial A) (Polynomial (Localization.AtPrime p))) = + p.map Polynomial.C at he + simp_rw [he] at ht + exact IsLocalization.algEquiv (p.map Polynomial.C).primeCompl _ _ + +noncomputable def polynomialLocalCoefficientEquiv + {A : Type*} [CommRing A] (p : Ideal A) [p.IsPrime] : + Localization.AtPrime (p.map (Polynomial.C : A →+* Polynomial A)) ≃ₐ[A] + Localization.AtPrime ((maximalIdeal (Localization.AtPrime p)).map Polynomial.C) := + (polynomialLocalCoefficientPolyEquiv p).restrictScalars A + +theorem polynomialLocalCoefficientEquiv_polynomial + {A : Type*} [CommRing A] (p : Ideal A) [p.IsPrime] (f : Polynomial A) : + polynomialLocalCoefficientEquiv p + (algebraMap (Polynomial A) (Localization.AtPrime (p.map Polynomial.C)) f) = + algebraMap (Polynomial A) + (Localization.AtPrime ((maximalIdeal (Localization.AtPrime p)).map Polynomial.C)) f := + (polynomialLocalCoefficientPolyEquiv p).commutes f + +theorem polynomialLocalCoefficientEquiv_algebraMap + {A : Type*} [CommRing A] (p : Ideal A) [p.IsPrime] (a : A) : + polynomialLocalCoefficientEquiv p + (algebraMap A (Localization.AtPrime (p.map Polynomial.C)) a) = + algebraMap A + (Localization.AtPrime ((maximalIdeal (Localization.AtPrime p)).map Polynomial.C)) a := + (polynomialLocalCoefficientEquiv p).commutes a + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +noncomputable def conePolynomialMap : + MvPolynomial (Option σ) K →ₐ[K] Polynomial (MvPolynomial σ K) := + MvPolynomial.aeval (fun o : Option σ => o.elim Polynomial.X + (fun i => Polynomial.C (X i) * Polynomial.X)) + +@[simp] theorem conePolynomialMap_X_none : + conePolynomialMap (X (none : Option σ) : MvPolynomial (Option σ) K) = Polynomial.X := by + simp [conePolynomialMap] + +@[simp] theorem conePolynomialMap_X_some (i : σ) : + conePolynomialMap (X (some i) : MvPolynomial (Option σ) K) = + Polynomial.C (X i) * Polynomial.X := by + simp [conePolynomialMap] + +local notation "𝒜" => MvPolynomial σ K +local notation "𝒮" => MvPolynomial (Option σ) K +local notation "𝒰" => Localization.Away (X (none : Option σ) : 𝒮) +local notation "𝒱" => Localization.Away (Polynomial.X : Polynomial 𝒜) + +private noncomputable def coneAwayForward : 𝒰 →ₐ[K] 𝒱 := + IsLocalization.Away.liftAlgHom (X none) + (f := (IsScalarTower.toAlgHom K (Polynomial 𝒜) 𝒱).comp conePolynomialMap) (by + change IsUnit (algebraMap (Polynomial 𝒜) 𝒱 (conePolynomialMap (X none))) + rw [conePolynomialMap_X_none] + exact IsLocalization.Away.algebraMap_isUnit (S := 𝒱) (Polynomial.X : Polynomial 𝒜)) + +private noncomputable def coneAwayInverseCoefficients : 𝒜 →ₐ[K] 𝒰 := + MvPolynomial.aeval (fun i => algebraMap 𝒮 𝒰 (X (some i)) * + IsLocalization.Away.invSelf (S := 𝒰) (X (none : Option σ) : 𝒮)) + +private noncomputable def coneAwayBackward : 𝒱 →ₐ[K] 𝒰 := + IsLocalization.Away.liftAlgHom Polynomial.X + (f := Polynomial.aevalTower coneAwayInverseCoefficients (algebraMap 𝒮 𝒰 (X none))) (by + rw [Polynomial.aevalTower_X] + exact IsLocalization.Away.algebraMap_isUnit (S := 𝒰) (X (none : Option σ) : 𝒮)) + +private theorem coneAwayForward_algebraMap (a : 𝒮) : + coneAwayForward (algebraMap 𝒮 𝒰 a) = algebraMap (Polynomial 𝒜) 𝒱 (conePolynomialMap a) := + by simp [coneAwayForward] + +private theorem coneAwayBackward_algebraMap (a : Polynomial 𝒜) : + coneAwayBackward (algebraMap (Polynomial 𝒜) 𝒱 a) = + Polynomial.aevalTower coneAwayInverseCoefficients (algebraMap 𝒮 𝒰 (X none)) a := + by simp [coneAwayBackward] + +private theorem coneAwayForward_invSelf : + coneAwayForward (IsLocalization.Away.invSelf (X (none : Option σ) : 𝒮) : 𝒰) = + (IsLocalization.Away.invSelf (Polynomial.X : Polynomial 𝒜) : 𝒱) := by + apply (IsLocalization.Away.algebraMap_isUnit (S := 𝒱) + (Polynomial.X : Polynomial 𝒜)).mul_left_cancel + rw [IsLocalization.Away.mul_invSelf] + have h := congrArg (coneAwayForward : 𝒰 →ₐ[K] 𝒱) + (IsLocalization.Away.mul_invSelf (S := 𝒰) (X (none : Option σ) : 𝒮)) + rw [map_mul, map_one, coneAwayForward_algebraMap, conePolynomialMap_X_none] at h + exact h + +private theorem coneAwayForward_comp_backward : + (coneAwayForward : 𝒰 →ₐ[K] 𝒱).comp coneAwayBackward = AlgHom.id K 𝒱 := by + apply IsLocalization.algHom_ext (Submonoid.powers (Polynomial.X : Polynomial 𝒜)) + apply Polynomial.algHom_ext' + · ext i + change coneAwayForward (coneAwayBackward + (algebraMap (Polynomial 𝒜) 𝒱 (Polynomial.C (X i)))) = + algebraMap (Polynomial 𝒜) 𝒱 (Polynomial.C (X i)) + rw [coneAwayBackward_algebraMap, Polynomial.aevalTower_C] + rw [show coneAwayInverseCoefficients (X i) = algebraMap 𝒮 𝒰 (X (some i)) * + IsLocalization.Away.invSelf (S := 𝒰) (X (none : Option σ) : 𝒮) from + MvPolynomial.aeval_X _ _] + rw [map_mul, coneAwayForward_algebraMap, coneAwayForward_invSelf, + conePolynomialMap_X_some, map_mul, mul_assoc, + IsLocalization.Away.mul_invSelf, mul_one] + · change coneAwayForward (coneAwayBackward (algebraMap (Polynomial 𝒜) 𝒱 Polynomial.X)) = + algebraMap (Polynomial 𝒜) 𝒱 Polynomial.X + rw [coneAwayBackward_algebraMap, Polynomial.aevalTower_X, + coneAwayForward_algebraMap, conePolynomialMap_X_none] + +private theorem coneAwayBackward_comp_forward : + (coneAwayBackward : 𝒱 →ₐ[K] 𝒰).comp coneAwayForward = AlgHom.id K 𝒰 := by + apply IsLocalization.algHom_ext (Submonoid.powers (X (none : Option σ) : 𝒮)) + ext i + change coneAwayBackward (coneAwayForward (algebraMap 𝒮 𝒰 (X i))) = algebraMap 𝒮 𝒰 (X i) + rw [coneAwayForward_algebraMap] + cases i with + | none => + rw [conePolynomialMap_X_none, coneAwayBackward_algebraMap, Polynomial.aevalTower_X] + | some i => + rw [conePolynomialMap_X_some, coneAwayBackward_algebraMap, map_mul, + Polynomial.aevalTower_C, Polynomial.aevalTower_X] + rw [show coneAwayInverseCoefficients (X i) = algebraMap 𝒮 𝒰 (X (some i)) * + IsLocalization.Away.invSelf (S := 𝒰) (X (none : Option σ) : 𝒮) from + MvPolynomial.aeval_X _ _] + rw [mul_assoc, mul_comm (IsLocalization.Away.invSelf (S := 𝒰) (X (none : Option σ) : 𝒮)), + IsLocalization.Away.mul_invSelf, mul_one] + +noncomputable def coneAwayEquiv : 𝒰 ≃ₐ[K] 𝒱 := + AlgEquiv.ofAlgHom coneAwayForward coneAwayBackward + coneAwayForward_comp_backward coneAwayBackward_comp_forward + +@[simp] theorem coneAwayEquiv_algebraMap (a : 𝒮) : + coneAwayEquiv (algebraMap 𝒮 𝒰 a) = algebraMap (Polynomial 𝒜) 𝒱 (conePolynomialMap a) := + coneAwayForward_algebraMap a + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +theorem coneIdeal_eq_comap_polynomial (p : Ideal (MvPolynomial σ K)) : + coneIdeal p = (p.map Polynomial.C).comap conePolynomialMap := by + have h : (Polynomial.mapRingHom (Ideal.Quotient.mk p)).comp + conePolynomialMap.toRingHom = (coneMap p).toRingHom := by + apply MvPolynomial.ringHom_ext + · intro r + simp [coneMap, conePolynomialMap] + rfl + · intro i + cases i <;> simp [coneMap, conePolynomialMap] + calc + coneIdeal p = RingHom.ker ((Polynomial.mapRingHom (Ideal.Quotient.mk p)).comp + conePolynomialMap.toRingHom) := by rw [h]; rfl + _ = (RingHom.ker (Polynomial.mapRingHom (Ideal.Quotient.mk p))).comap + conePolynomialMap := rfl + _ = _ := by rw [Polynomial.ker_mapRingHom, Ideal.mk_ker] + +private theorem polynomial_X_powers_disjoint (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + Disjoint ((Submonoid.powers (Polynomial.X : Polynomial (MvPolynomial σ K))) : + Set (Polynomial (MvPolynomial σ K))) + ((p.map Polynomial.C : Ideal (Polynomial (MvPolynomial σ K))) : + Set (Polynomial (MvPolynomial σ K))) := by + apply (Ideal.disjoint_powers_iff_notMem_of_isPrime Polynomial.X).mpr + intro h + have h1 : (1 : MvPolynomial σ K) ∈ p := by simpa using (Ideal.mem_map_C_iff.mp h) 1 + exact (show p.IsPrime from inferInstance).ne_top (p.eq_top_of_isUnit_mem h1 isUnit_one) + +theorem polynomialAwayPrime_isPrime (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + ((p.map Polynomial.C).map (algebraMap (Polynomial (MvPolynomial σ K)) + (Localization.Away (Polynomial.X : Polynomial (MvPolynomial σ K))))).IsPrime := + IsLocalization.isPrime_of_isPrime_disjoint (Submonoid.powers Polynomial.X) _ _ + inferInstance (polynomial_X_powers_disjoint p) + +attribute [local instance] coneIdeal_isPrime polynomialAwayPrime_isPrime + +noncomputable def conePolynomialLocalEquiv (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + Localization.AtPrime (coneIdeal p) ≃ₐ[K] Localization.AtPrime (p.map Polynomial.C) := by + let A := MvPolynomial σ K + let S := MvPolynomial (Option σ) K + let U := Localization.Away (X (none : Option σ) : S) + let V := Localization.Away (Polynomial.X : Polynomial A) + let q : Ideal (Polynomial A) := p.map Polynomial.C + have hd := polynomial_X_powers_disjoint p + let q' := q.map (algebraMap (Polynomial A) V) + have hq' : q'.comap (algebraMap (Polynomial A) V) = q := + IsLocalization.under_map_of_isPrime_disjoint + (Submonoid.powers (Polynomial.X : Polynomial A)) V inferInstance hd + let e : U ≃ₐ[K] V := coneAwayEquiv + let p' := q'.comap e.toRingHom + have hp' : p'.comap (algebraMap S U) = coneIdeal p := by + change q'.comap (e.toRingHom.comp (algebraMap S U)) = _ + have he : e.toRingHom.comp (algebraMap S U) = + (algebraMap (Polynomial A) V).comp conePolynomialMap.toRingHom := by + apply RingHom.ext + intro f + exact coneAwayEquiv_algebraMap f + rw [he, ← Ideal.comap_comap, hq'] + exact (coneIdeal_eq_comap_polynomial p).symm + let eS : Localization.AtPrime (coneIdeal p) ≃ₐ[S] Localization.AtPrime p' := by + let : IsLocalization (coneIdeal p).primeCompl (Localization.AtPrime p') := by + have h := IsLocalization.isLocalization_isLocalization_atPrime_isLocalization + (M := Submonoid.powers (X (none : Option σ) : S)) (Localization.AtPrime p') p' + change IsLocalization (p'.comap (algebraMap S U)).primeCompl (Localization.AtPrime p') at h + simpa only [hp'] using h + exact IsLocalization.algEquiv (coneIdeal p).primeCompl _ _ + let eB : Localization.AtPrime q ≃ₐ[Polynomial A] Localization.AtPrime q' := by + let : IsLocalization q.primeCompl (Localization.AtPrime q') := by + have h := IsLocalization.isLocalization_isLocalization_atPrime_isLocalization + (M := Submonoid.powers (Polynomial.X : Polynomial A)) (Localization.AtPrime q') q' + simpa only [hq'] using h + exact IsLocalization.algEquiv q.primeCompl _ _ + exact ((eS.restrictScalars K).trans + (Localization.localAlgEquiv p' q' e rfl)).trans (eB.restrictScalars K).symm + +theorem conePolynomialLocalEquiv_algebraMap (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : MvPolynomial (Option σ) K) : + conePolynomialLocalEquiv p + (algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p)) f) = + algebraMap (Polynomial (MvPolynomial σ K)) + (Localization.AtPrime (p.map Polynomial.C)) (conePolynomialMap f) := by + dsimp only [conePolynomialLocalEquiv, AlgEquiv.trans_apply] + rw [AlgEquiv.symm_apply_eq] + simp only [AlgEquiv.restrictScalars_apply, AlgEquiv.commutes] + rw [IsScalarTower.algebraMap_apply (MvPolynomial (Option σ) K) + (Localization.Away (X (none : Option σ) : MvPolynomial (Option σ) K))] + rw [IsScalarTower.algebraMap_apply (Polynomial (MvPolynomial σ K)) + (Localization.Away (Polynomial.X : Polynomial (MvPolynomial σ K)))] + exact (Localization.localRingHom_to_map _ _ coneAwayEquiv.toRingHom rfl _).trans + (congrArg _ (coneAwayEquiv_algebraMap f)) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +attribute [local instance] coneIdeal_isPrime Polynomial.algebra Polynomial.isLocalization + +noncomputable def coneLocalEquiv (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + Localization.AtPrime (coneIdeal p) ≃ₐ[K] + Localization.AtPrime + ((IsLocalRing.maximalIdeal (Localization.AtPrime p)).map Polynomial.C) := + (conePolynomialLocalEquiv p).trans + ((DegreeBezout.polynomialLocalCoefficientPolyEquiv p).restrictScalars K) + +theorem coneLocalEquiv_algebraMap (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : MvPolynomial (Option σ) K) : + coneLocalEquiv p + (algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p)) f) = + algebraMap (Polynomial (Localization.AtPrime p)) + (Localization.AtPrime + ((IsLocalRing.maximalIdeal (Localization.AtPrime p)).map Polynomial.C)) + (Polynomial.map (algebraMap (MvPolynomial σ K) (Localization.AtPrime p)) + (conePolynomialMap f)) := by + change DegreeBezout.polynomialLocalCoefficientPolyEquiv p + (conePolynomialLocalEquiv p + (algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p)) f)) = _ + rw [conePolynomialLocalEquiv_algebraMap, AlgEquiv.commutes] + rw [IsScalarTower.algebraMap_apply (Polynomial (MvPolynomial σ K)) + (Polynomial (Localization.AtPrime p))] + rfl + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {A : Type*} [CommRing A] [IsNoetherianRing A] + +theorem polynomial_height_map_C (p : Ideal A) [p.IsPrime] : + (p.map (Polynomial.C : A →+* Polynomial A)).height = p.height := by + have : (p.map (Polynomial.C : A →+* Polynomial A)).LiesOver p := by + constructor + ext r + change r ∈ p ↔ Polynomial.C r ∈ p.map Polynomial.C + constructor + · exact Ideal.mem_map_of_mem _ + · intro h + simpa only [Polynomial.coeff_C_zero] using (Ideal.mem_map_C_iff.mp h) 0 + simp [Ideal.height_eq_height_add_of_liesOver_of_hasGoingDown p] + +theorem local_polynomial_prime_ringKrullDim (p : Ideal A) [p.IsPrime] : + ringKrullDim (Localization.AtPrime (p.map (Polynomial.C : A →+* Polynomial A))) = + ringKrullDim (Localization.AtPrime p) := by + rw [IsLocalization.AtPrime.ringKrullDim_eq_height (p.map Polynomial.C) + (Localization.AtPrime (p.map Polynomial.C)), + IsLocalization.AtPrime.ringKrullDim_eq_height p (Localization.AtPrime p), + polynomial_height_map_C] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K σ : Type*} [CommRing K] [IsNoetherianRing K] [Finite σ] + +theorem coneIdeal_height (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + (coneIdeal p).height = p.height := by + let : (coneIdeal p).IsPrime := coneIdeal_isPrime p + have h := ringKrullDim_eq_of_ringEquiv (conePolynomialLocalEquiv p).toRingEquiv + rw [IsLocalization.AtPrime.ringKrullDim_eq_height (coneIdeal p) + (Localization.AtPrime (coneIdeal p)), + IsLocalization.AtPrime.ringKrullDim_eq_height (p.map Polynomial.C) + (Localization.AtPrime (p.map Polynomial.C)), polynomial_height_map_C] at h + exact WithBot.coe_eq_coe.mp h + +end WeightedTorusJets.Geometry + +end + +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeMapEval.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeMapEval.lean new file mode 100644 index 0000000000000000000000000000000000000000..c14e935287c616a4801bc9a24c8618340dceee16 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeMapEval.lean @@ -0,0 +1,63 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.CoeffPolynomialEvalMul + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +theorem coneMap_eq_eval₂ (p : Ideal (MvPolynomial σ K)) + (f : MvPolynomial (Option σ) K) : + coneMap p f = f.eval₂ (Polynomial.C.comp (algebraMap K (MvPolynomial σ K ⧸ p))) + (fun o : Option σ => Polynomial.C (o.elim 1 (fun i => Ideal.Quotient.mk p (X i))) * + Polynomial.X) := by + rw [coneMap, aeval_def] + have halg : algebraMap K (Polynomial (MvPolynomial σ K ⧸ p)) = + Polynomial.C.comp (algebraMap K (MvPolynomial σ K ⧸ p)) := by + apply RingHom.ext + intro r + exact Polynomial.algebraMap_apply (A := MvPolynomial σ K ⧸ p) r + rw [halg] + congr 1 + funext o + cases o <;> simp + +theorem coneMap_homogeneousComponent (p : Ideal (MvPolynomial σ K)) + (f : MvPolynomial (Option σ) K) (n : ℕ) : + coneMap p (homogeneousComponent n f) = + Polynomial.C ((coneMap p f).coeff n) * Polynomial.X ^ n := by + simp only [coneMap_eq_eval₂, polynomial_eval₂_homogeneousComponent] + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem coneIdeal_isHomogeneous (p : Ideal (MvPolynomial σ K)) : + (coneIdeal p).IsHomogeneous (homogeneousSubmodule (Option σ) K) := by + apply (Ideal.isHomogeneous_iff_forall_subset _ _).mpr + intro n f hf + change GradedRing.proj (homogeneousSubmodule (Option σ) K) n f ∈ coneIdeal p + rw [GradedRing.proj_apply] + change (MvPolynomial.decomposition.decompose' f n : MvPolynomial (Option σ) K) ∈ coneIdeal p + rw [MvPolynomial.decomposition.decompose'_apply] + change coneMap p (homogeneousComponent n f) = 0 + rw [coneMap_homogeneousComponent, show coneMap p f = 0 from hf, + Polynomial.coeff_zero, map_zero, zero_mul] + +end WeightedTorusJets.Geometry + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeProjectivePoint.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeProjectivePoint.lean new file mode 100644 index 0000000000000000000000000000000000000000..9bb4203be699df8456615980a51e74e56feb3e70 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ConeProjectivePoint.lean @@ -0,0 +1,342 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeMapEval +import OAI.NumberTheory.Jacobsthal.Siegel.GenericNormalization +import OAI.NumberTheory.Jacobsthal.Siegel.PolynomialLaurent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +namespace WeightedTorusJets.Geometry + +theorem torus_chart_prime_height_add_quotient_dim {K : Type*} [Field K] (n : ℕ) + (p : Ideal (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))) [p.IsPrime] : + (p.height : WithBot ℕ∞) + + ringKrullDim (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)) ⧸ p) = n := by + let R := MvPolynomial (Fin n) K + let t : R := ∏ i : Fin n, MvPolynomial.X i + let T := Localization.Away t + have ht : t ≠ 0 := Finset.prod_ne_zero_iff.mpr fun i _ ↦ MvPolynomial.X_ne_zero i + let : IsDomain T := IsLocalization.isDomain_of_le_nonZeroDivisors T + (powers_le_nonZeroDivisors_of_noZeroDivisors ht) + simpa only [torus_chart_ringKrullDim] using + prime_height_add_quotient_dim_eq_of_finiteType (K := K) p + + + + +theorem finiteType_prime_codimension_nat + {K A : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [Algebra.FiniteType K A] (p : Ideal A) [p.IsPrime] (n : ℕ) + (hn : ringKrullDim A = n) : + ∃ d : ℕ, d ≤ n ∧ ringKrullDim (A ⧸ p) = d ∧ p.height = (n - d : ℕ) := by + obtain ⟨d, hd, _⟩ := finiteType_dimension_trdeg (K := K) (A := A ⧸ p) + have hp_le : p.height ≤ n := by + have hpdim := p.height_le_ringKrullDim_of_isPrime + rw [hn] at hpdim + exact_mod_cast hpdim + obtain ⟨h, hh⟩ := ENat.ne_top_iff_exists.mp + (lt_of_le_of_lt hp_le (ENat.natCast_lt_top n)).ne + have heq := prime_height_add_quotient_dim_eq_of_finiteType (K := K) p + rw [← hh, hd, hn] at heq + have hsum : h + d = n := by exact_mod_cast heq + refine ⟨d, ?_, hd, ?_⟩ + · exact hsum ▸ Nat.le_add_left d h + · rw [← hh, ← hsum, Nat.add_sub_cancel] + +end WeightedTorusJets.Geometry + + +section + + + + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +theorem mul_X_none_pow_mem_coneIdeal_iff (p : Ideal (MvPolynomial σ K)) + (f : MvPolynomial (Option σ) K) (n : ℕ) : + f * X none ^ n ∈ coneIdeal p ↔ f ∈ coneIdeal p := by + change coneMap p (f * X none ^ n) = 0 ↔ coneMap p f = 0 + rw [map_mul, map_pow, coneMap_X_none] + exact ⟨Polynomial.mul_X_pow_eq_zero, fun h => by rw [h, zero_mul]⟩ + +theorem coneMap_of_isHomogeneous (p : Ideal (MvPolynomial σ K)) + {f : MvPolynomial (Option σ) K} {n : ℕ} (hf : f.IsHomogeneous n) : + coneMap p f = Polynomial.C (Ideal.Quotient.mk p (coneDehomogenize f)) * + Polynomial.X ^ n := by + have heq := coneMap_homogeneousComponent p f n + rw [homogeneousComponent_eq_self hf] at heq + have heval : (coneMap p f).coeff n = Ideal.Quotient.mk p (coneDehomogenize f) := by + rw [← eval_one_coneMap, heq] + simp + rwa [heval] at heq + +theorem homogeneous_mem_coneIdeal_iff (p : Ideal (MvPolynomial σ K)) + {f : MvPolynomial (Option σ) K} {n : ℕ} (hf : f.IsHomogeneous n) : + f ∈ coneIdeal p ↔ coneDehomogenize f ∈ p := by + change coneMap p f = 0 ↔ coneDehomogenize f ∈ p + rw [coneMap_of_isHomogeneous p hf] + constructor + · intro h + apply Ideal.Quotient.eq_zero_iff_mem.mp + exact Polynomial.C_injective (by simpa only [map_zero] using Polynomial.mul_X_pow_eq_zero h) + · intro h + rw [Ideal.Quotient.eq_zero_iff_mem.mpr h, map_zero, zero_mul] + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem homogeneous_ideal_le_coneIdeal_iff (p : Ideal (MvPolynomial σ K)) + (J : Ideal (MvPolynomial (Option σ) K)) + (hJ : J.IsHomogeneous (homogeneousSubmodule (Option σ) K)) : + J ≤ coneIdeal p ↔ Ideal.map coneDehomogenize.toRingHom J ≤ p := by + constructor + · intro h + exact (Ideal.map_mono h).trans (map_coneIdeal_dehomogenize_le p) + · intro h f hf + apply (MvPolynomial.mem_iff_homogeneousComponent_mem (coneIdeal_isHomogeneous p) f).mpr + intro n + apply (homogeneous_mem_coneIdeal_iff p (homogeneousComponent_isHomogeneous n f)).mpr + exact h (Ideal.mem_map_of_mem _ (homogeneousComponent_mem_of_mem hJ hf n)) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem coneIdeal_eq_homogeneousCore (p : Ideal (MvPolynomial σ K)) : + coneIdeal p = + ((Ideal.comap coneDehomogenize.toRingHom p).homogeneousCore + (homogeneousSubmodule (Option σ) K)).toIdeal := by + apply le_antisymm + · have hle : coneIdeal p ≤ Ideal.comap coneDehomogenize.toRingHom p := + Ideal.map_le_iff_le_comap.mp (map_coneIdeal_dehomogenize_le p) + have hmono := Ideal.homogeneousCore_mono (homogeneousSubmodule (Option σ) K) hle + have heq := (coneIdeal_isHomogeneous p).toIdeal_homogeneousCore_eq_self + rw [← heq] + exact hmono + · apply (homogeneous_ideal_le_coneIdeal_iff p _ + (HomogeneousIdeal.isHomogeneous _)).mpr + apply Ideal.map_le_iff_le_comap.mpr + exact Ideal.toIdeal_homogeneousCore_le _ _ + +noncomputable def coneProjectivePoint (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + ProjectiveSpectrum (homogeneousSubmodule (Option σ) K) where + asHomogeneousIdeal := ⟨coneIdeal p, coneIdeal_isHomogeneous p⟩ + isPrime := coneIdeal_isPrime p + not_irrelevant_le := by + intro h + apply X_none_not_mem_coneIdeal p + exact h (HomogeneousIdeal.mem_irrelevant_of_mem + (homogeneousSubmodule (Option σ) K) (by decide : 0 < (1 : ℕ)) + (isHomogeneous_X K none)) + +theorem coneProjectivePoint_mem_basicOpen (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + coneProjectivePoint p ∈ ProjectiveSpectrum.basicOpen + (homogeneousSubmodule (Option σ) K) (X none) := by + exact X_none_not_mem_coneIdeal p + +theorem coneIdeal_le_iff (p q : Ideal (MvPolynomial σ K)) : + coneIdeal p ≤ coneIdeal q ↔ p ≤ q := by + rw [homogeneous_ideal_le_coneIdeal_iff q _ (coneIdeal_isHomogeneous p), + map_coneIdeal_dehomogenize] + +theorem closure_coneProjectivePoint (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + closure ({coneProjectivePoint p} : + Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K))) = + ProjectiveSpectrum.zeroLocus (homogeneousSubmodule (Option σ) K) (coneIdeal p) := by + rw [← ProjectiveSpectrum.zeroLocus_vanishingIdeal_eq_closure, + ProjectiveSpectrum.vanishingIdeal_singleton] + rfl + +theorem coneProjectivePoint_mem_closure_iff (p q : Ideal (MvPolynomial σ K)) + [p.IsPrime] [q.IsPrime] : + coneProjectivePoint q ∈ closure ({coneProjectivePoint p} : + Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K))) ↔ p ≤ q := by + rw [← ProjectiveSpectrum.le_iff_mem_closure] + exact coneIdeal_le_iff p q + +end WeightedTorusJets.Geometry + +noncomputable section +open MvPolynomial HomogeneousLocalization + + +open CategoryTheory _root_.AlgebraicGeometry + +namespace WeightedTorusJets.Geometry + +open CategoryTheory _root_.AlgebraicGeometry +attribute [local instance] MvPolynomial.gradedAlgebra + +universe u + +theorem affineProj_homogenizing_mem (k ι : Type u) [CommRing k] : + (X (none : Option ι) : MvPolynomial (Option ι) k) ∈ + homogeneousSubmodule (Option ι) k 1 := isHomogeneous_X k (none : Option ι) + +end WeightedTorusJets.Geometry +namespace WeightedTorusJets.Geometry + +open CategoryTheory _root_.AlgebraicGeometry MvPolynomial HomogeneousLocalization +attribute [local instance] MvPolynomial.gradedAlgebra + +universe uChart + +theorem basicOpenToSpec_coneProjectivePoint + {K σ : Type uChart} [CommRing K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + Proj.basicOpenToSpec (homogeneousSubmodule (Option σ) K) (X (none : Option σ)) + ⟨coneProjectivePoint p, coneProjectivePoint_mem_basicOpen p⟩ = + PrimeSpectrum.comap (affineProjChartMap (k := K) (fun i : σ => X i)) + ⟨p, inferInstance⟩ := by + apply PrimeSpectrum.ext + apply Ideal.ext + intro z + obtain ⟨n, a, ha, rfl⟩ := Away.mk_surjective (homogeneousSubmodule (Option σ) K) + (isHomogeneous_X K (none : Option σ)) z + change HomogeneousLocalization.mk _ ∈ + ((ProjectiveSpectrum.Proj.toSpec (homogeneousSubmodule (Option σ) K) + (X (none : Option σ))).base + ⟨coneProjectivePoint p, coneProjectivePoint_mem_basicOpen p⟩).asIdeal ↔ _ + refine (ProjectiveSpectrum.Proj.mk_mem_toSpec_base_apply + (homogeneousSubmodule (Option σ) K) + ⟨coneProjectivePoint p, coneProjectivePoint_mem_basicOpen p⟩ _).trans ?_ + change a ∈ coneIdeal p ↔ affineProjChartMap (k := K) (fun i : σ => X i) + (Away.mk (homogeneousSubmodule (Option σ) K) (isHomogeneous_X K (none : Option σ)) n a ha) ∈ p + rw [affineProjChartMap_mk] + have heval : affineProjEval (k := K) (fun i : σ => X i) = + (coneDehomogenize : MvPolynomial (Option σ) K →ₐ[K] MvPolynomial σ K) := by + ext i + cases i <;> simp [affineProjEval, coneDehomogenize] + rw [heval] + exact homogeneous_mem_coneIdeal_iff p ha + +theorem affineIntoProj_polynomial_point + {K σ : Type uChart} [CommRing K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + (affineIntoProj (k := K) (fun i : σ => X i)) ⟨p, inferInstance⟩ = + coneProjectivePoint p := by + let e := Proj.basicOpenIsoSpec (homogeneousSubmodule (Option σ) K) + (X (none : Option σ)) (affineProj_homogenizing_mem K σ) (by decide) + change (Proj.basicOpen (homogeneousSubmodule (Option σ) K) (X (none : Option σ))).ι + (e.inv (PrimeSpectrum.comap (affineProjChartMap (k := K) (fun i : σ => X i)) + ⟨p, inferInstance⟩)) = _ + rw [← basicOpenToSpec_coneProjectivePoint p] + change (Proj.basicOpen (homogeneousSubmodule (Option σ) K) (X (none : Option σ))).ι + (e.inv (e.hom ⟨coneProjectivePoint p, coneProjectivePoint_mem_basicOpen p⟩)) = _ + exact congrArg + (fun f : (Proj.basicOpen (homogeneousSubmodule (Option σ) K) (X (none : Option σ))).toScheme ⟶ + (Proj.basicOpen (homogeneousSubmodule (Option σ) K) (X (none : Option σ))).toScheme => + (Proj.basicOpen (homogeneousSubmodule (Option σ) K) (X (none : Option σ))).ι + (f ⟨coneProjectivePoint p, coneProjectivePoint_mem_basicOpen p⟩)) e.hom_inv_id + +theorem closure_affineIntoProj_zeroLocus + {K σ : Type uChart} [CommRing K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + closure ((affineIntoProj (k := K) (fun i : σ => X i)) '' + PrimeSpectrum.zeroLocus (p : Set (MvPolynomial σ K))) = + ProjectiveSpectrum.zeroLocus (homogeneousSubmodule (Option σ) K) (coneIdeal p) := by + rw [← PrimeSpectrum.closure_singleton (⟨p, inferInstance⟩ : PrimeSpectrum (MvPolynomial σ K))] + have hc : Continuous (fun x : PrimeSpectrum (MvPolynomial σ K) => + ((affineIntoProj (k := K) (fun i : σ => X i)) x : + ProjectiveSpectrum (homogeneousSubmodule (Option σ) K))) := + (affineIntoProj (k := K) (fun i : σ => X i)).continuous + refine (closure_image_closure hc).trans ?_ + rw [Set.image_singleton] + exact (congrArg (fun x : ProjectiveSpectrum (homogeneousSubmodule (Option σ) K) => + closure ({x} : Set (ProjectiveSpectrum (homogeneousSubmodule (Option σ) K)))) + (affineIntoProj_polynomial_point p)).trans (closure_coneProjectivePoint p) + +end WeightedTorusJets.Geometry + +end +end + +namespace WeightedTorusJets.Geometry + +theorem coneIdeal_quotient_ringKrullDim {K σ : Type*} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + ringKrullDim (MvPolynomial (Option σ) K ⧸ coneIdeal p) = + ringKrullDim (MvPolynomial σ K ⧸ p) + 1 := by + let : (coneIdeal p).IsPrime := coneIdeal_isPrime p + obtain ⟨d, hdle, hd, hheight⟩ := finiteType_prime_codimension_nat (K := K) p (Nat.card σ) + (by simp) + obtain ⟨c, hc, _⟩ := finiteType_dimension_trdeg (K := K) + (A := MvPolynomial (Option σ) K ⧸ coneIdeal p) + have hcone := prime_height_add_quotient_dim_eq_of_finiteType (K := K) (coneIdeal p) + rw [coneIdeal_height, hheight, hc] at hcone + have heq : (Nat.card σ - d) + c = Nat.card σ + 1 := by + have : ringKrullDim (MvPolynomial (Option σ) K) = + (Nat.card σ + 1 : ℕ) := by simp + rw [this] at hcone + exact_mod_cast hcone + have hcd : c = d + 1 := by omega + rw [hc, hd, hcd] + simp + + + + +open _root_.AlgebraicGeometry + +variable {A σ : Type*} [CommRing A] [SetLike σ A] [AddSubgroupClass σ A] + (𝒜 : ℕ → σ) [GradedRing 𝒜] + +theorem projective_zeroLocus_topologicalKrullDim_eq_order (I : Ideal A) : + topologicalKrullDim (ProjectiveSpectrum.zeroLocus 𝒜 (I : Set A)) = + Order.krullDim (ProjectiveSpectrum.zeroLocus 𝒜 (I : Set A)) := by + let : QuasiSober (ProjectiveSpectrum 𝒜) := inferInstanceAs (QuasiSober (Proj 𝒜)) + let : T0Space (ProjectiveSpectrum 𝒜) := inferInstanceAs (T0Space (Proj 𝒜)) + let Z := ProjectiveSpectrum.zeroLocus 𝒜 (I : Set A) + have : QuasiSober Z := (ProjectiveSpectrum.isClosed_zeroLocus 𝒜 (I : Set A)).isClosedEmbedding_subtypeVal.quasiSober + have hs (p q : ProjectiveSpectrum 𝒜) : p ≤ q ↔ p ⤳ q := + (ProjectiveSpectrum.le_iff_mem_closure 𝒜 p q).trans specializes_iff_mem_closure.symm + let e : Z ≃o (TopologicalSpace.IrreducibleCloseds Z)ᵒᵈ := + { __ := irreducibleSetEquivPoints.toEquiv.symm.trans OrderDual.toDual + map_rel_iff' {p q} := + (RelIso.symm irreducibleSetEquivPoints).map_rel_iff.trans + ((subtype_specializes_iff p q).trans (hs p.1 q.1).symm) } + exact Order.krullDim_orderDual.symm.trans (Order.krullDim_eq_of_orderIso e).symm + +theorem projective_zeroLocus_dim_le_of_cone_dim + (I m : Ideal A) [m.IsPrime] + (hm : ∀ x : ProjectiveSpectrum 𝒜, x.asHomogeneousIdeal.toIdeal < m) + (n : ℕ) (hdim : ringKrullDim (A ⧸ I) ≤ n + 1) : + topologicalKrullDim (ProjectiveSpectrum.zeroLocus 𝒜 (I : Set A)) ≤ n := by + rw [projective_zeroLocus_topologicalKrullDim_eq_order] + apply iSup_le + intro l + let e : ProjectiveSpectrum.zeroLocus 𝒜 (I : Set A) ↪o PrimeSpectrum.zeroLocus (I : Set A) := + OrderEmbedding.ofMapLEIff + (fun x ↦ ⟨⟨x.1.asHomogeneousIdeal.toIdeal, x.1.isPrime⟩, x.2⟩) + (fun _ _ ↦ Iff.rfl) + let q := l.map e e.strictMono + let m' : PrimeSpectrum.zeroLocus (I : Set A) := + ⟨⟨m, inferInstance⟩, l.last.2.trans (hm l.last.1).le⟩ + have hlt : q.last < m' := hm l.last.1 + have hlength := Order.LTSeries.length_le_krullDim (q.snoc m' hlt) + rw [← ringKrullDim_quotient] at hlength + have hle : (l.length + 1 : ℕ) ≤ n + 1 := by + have hh := hlength.trans hdim + change ((l.length + 1 : ℕ) : WithBot ℕ∞) ≤ n + 1 at hh + exact_mod_cast hh + exact_mod_cast Nat.le_of_succ_le_succ hle + +end WeightedTorusJets.Geometry + + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoordinateLocalizedPrime.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoordinateLocalizedPrime.lean new file mode 100644 index 0000000000000000000000000000000000000000..9db50133f961986d44141b7992850783fb1c658a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/CoordinateLocalizedPrime.lean @@ -0,0 +1,553 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.Homogenize +import OAI.NumberTheory.Jacobsthal.Siegel.PolynomialBox + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +open MvPolynomial +namespace WeightedTorusJets.Geometry + +open scoped AlgebraMonoidAlgebra + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +noncomputable def coordinateLocalizedPrime {K σ : Type*} [Field K] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) : + Ideal (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K))) := + (p.comap (coordinateSplit (K := K) s).symm.toRingHom).map + (algebraMap (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) + (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K)))) + +theorem coordinateLocalizedPrime_height {K σ : Type*} [Field K] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (hs : AlgebraicIndependent K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i)))) : + (coordinateLocalizedPrime s p).height = p.height := by + exact (coefficient_localization_prime_height (F := FractionRing (MvPolynomial s K)) + (p.comap (coordinateSplit (K := K) s).symm.toRingHom) + (coordinateSplit_comap_coefficients_eq_bot_of_fractionField s p hs)).2.trans + ((coordinateSplit (K := K) s).symm.toRingEquiv.height_comap p) + +noncomputable def coordinateFractionLocalEquiv {K σ : Type*} [Field K] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + [(coordinateLocalizedPrime s p).IsPrime] + (hs : AlgebraicIndependent K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i)))) : + Localization.AtPrime p ≃ₐ[K] Localization.AtPrime (coordinateLocalizedPrime s p) := by + have : ((p.comap (coordinateSplit (K := K) s).symm.toRingHom).map + (algebraMap (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) + (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K))))).IsPrime := + ‹(coordinateLocalizedPrime s p).IsPrime› + letI : IsScalarTower K (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) + (Localization.AtPrime (coordinateLocalizedPrime s p)) := + IsScalarTower.to₁₂₄ K (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) + (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K))) + (Localization.AtPrime (coordinateLocalizedPrime s p)) + exact (coordinateSplitLocalEquiv s p).trans + ((coefficientLocalizationLocalEquiv (F := FractionRing (MvPolynomial s K)) + (p.comap (coordinateSplit (K := K) s).symm.toRingHom) + (coordinateSplit_comap_coefficients_eq_bot_of_fractionField s p hs)).restrictScalars K) + +theorem coordinateFraction_localEquiv_algebraMap {K σ : Type*} [Field K] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + [(coordinateLocalizedPrime s p).IsPrime] + (hs : AlgebraicIndependent K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i)))) (f : MvPolynomial σ K) : + coordinateFractionLocalEquiv s p hs (algebraMap _ (Localization.AtPrime p) f) = + algebraMap _ (Localization.AtPrime (coordinateLocalizedPrime s p)) + (MvPolynomial.map (algebraMap (MvPolynomial s K) (FractionRing (MvPolynomial s K))) + (coordinateSplit s f)) := by + have : ((p.comap (coordinateSplit (K := K) s).symm.toRingHom).map + (algebraMap (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) + (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K))))).IsPrime := + ‹(coordinateLocalizedPrime s p).IsPrime› + have hsplit : coordinateSplitLocalEquiv s p (algebraMap _ (Localization.AtPrime p) f) = + algebraMap _ (Localization.AtPrime (p.comap (coordinateSplit (K := K) s).symm.toRingHom)) + (coordinateSplit s f) := by + apply (coordinateSplitLocalEquiv s p).symm.injective + rw [AlgEquiv.symm_apply_apply] + change algebraMap _ (Localization.AtPrime p) f = + Localization.localRingHom _ p (coordinateSplit (K := K) s).symm.toRingHom rfl + (algebraMap _ _ (coordinateSplit s f)) + rw [Localization.localRingHom_to_map] + change algebraMap _ (Localization.AtPrime p) f = + algebraMap _ (Localization.AtPrime p) ((coordinateSplit s).symm (coordinateSplit s f)) + rw [AlgEquiv.symm_apply_apply] + change (coefficientLocalizationLocalEquiv + (F := FractionRing (MvPolynomial s K)) + (p.comap (coordinateSplit (K := K) s).symm.toRingHom) + (coordinateSplit_comap_coefficients_eq_bot_of_fractionField s p hs)) + (coordinateSplitLocalEquiv s p (algebraMap _ (Localization.AtPrime p) f)) = _ + rw [hsplit, AlgEquiv.commutes] + rfl + +theorem coordinateLocalizedPrime_finite_quotient {K σ : Type*} [Field K] [Finite σ] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) + [(coordinateLocalizedPrime s p).IsMaximal] : + Module.Finite (FractionRing (MvPolynomial s K)) + (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K)) ⧸ + coordinateLocalizedPrime s p) := by + let := Ideal.Quotient.field (coordinateLocalizedPrime s p) + exact finite_of_finite_type_of_isJacobsonRing _ _ + +theorem coordinate_complement_card_eq_height {K σ : Type*} [Field K] [Finite σ] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + [(coordinateLocalizedPrime s p).IsMaximal] + (hs : AlgebraicIndependent K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i)))) : + (Nat.card (sᶜ : Set σ) : ℕ∞) = p.height := by + let := Fintype.ofFinite (sᶜ : Set σ) + rw [← coordinateLocalizedPrime_height s p hs, maximal_mvPolynomial_height] + simp only [Nat.card_eq_fintype_card] + +theorem exists_coordinate_localization {K σ : Type*} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + ∃ (s : Set σ) + (_hs : IsTranscendenceBasis K (fun i : s => componentCoordinate p i)) + (hq : (coordinateLocalizedPrime s p).IsMaximal), + letI := hq + Module.Finite (FractionRing (MvPolynomial s K)) + (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K)) ⧸ + coordinateLocalizedPrime s p) ∧ + (Nat.card (sᶜ : Set σ) : ℕ∞) = p.height ∧ + ∃ e : Localization.AtPrime p ≃ₐ[K] Localization.AtPrime (coordinateLocalizedPrime s p), + ∀ f : MvPolynomial σ K, + e (algebraMap _ (Localization.AtPrime p) f) = + algebraMap _ (Localization.AtPrime (coordinateLocalizedPrime s p)) + (MvPolynomial.map + (algebraMap (MvPolynomial s K) (FractionRing (MvPolynomial s K))) + (coordinateSplit s f)) ∧ + (MvPolynomial.map + (algebraMap (MvPolynomial s K) (FractionRing (MvPolynomial s K))) + (coordinateSplit s f)).totalDegree ≤ f.totalDegree := by + obtain ⟨s, hs⟩ := exists_prime_quotient_coordinate_basis p + have hq : (coordinateLocalizedPrime s p).IsMaximal := + coordinateSplit_localized_prime_isMaximal s p hs + refine ⟨s, hs, hq, coordinateLocalizedPrime_finite_quotient s p, + coordinate_complement_card_eq_height s p hs.1, coordinateFractionLocalEquiv s p hs.1, ?_⟩ + intro f + exact ⟨coordinateFraction_localEquiv_algebraMap s p hs.1 f, + totalDegree_localized_coordinateSplit_le s f⟩ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry.DegreeBezout + +theorem ring_length_eq_of_ringEquiv {A B : Type*} [CommRing A] [CommRing B] + (e : A ≃+* B) : Module.length A A = Module.length B B := by + let : Algebra A B := e.toRingHom.toAlgebra + let f : A ≃ₗ[A] B := + { e.toAddEquiv with map_smul' := by intro a b; exact e.map_mul a b } + rw [← Module.length_eq_of_surjective (M := B) e.surjective] + exact f.length_eq + +theorem quotient_length_eq_of_ringEquiv {A B : Type*} [CommRing A] [CommRing B] + (e : A ≃+* B) (I : Ideal A) (J : Ideal B) + (hJ : J = I.map e.toRingHom) : + Module.length A (A ⧸ I) = Module.length B (B ⧸ J) := by + rw [Module.length_eq_of_surjective (S := A) (R := A ⧸ I) (M := A ⧸ I) + (Ideal.Quotient.mk_surjective (I := I)), + Module.length_eq_of_surjective (S := B) (R := B ⧸ J) (M := B ⧸ J) + (Ideal.Quotient.mk_surjective (I := J))] + exact ring_length_eq_of_ringEquiv (Ideal.quotientEquiv I J e hJ) + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry + +theorem radical_map_ringEquiv_eq_maximalIdeal + {A B : Type*} [CommRing A] [CommRing B] [IsLocalRing A] [IsLocalRing B] + (e : A ≃+* B) (I : Ideal A) + (hI : I.radical = IsLocalRing.maximalIdeal A) : + (I.map e.toRingHom).radical = IsLocalRing.maximalIdeal B := by + have hk : RingHom.ker e.toRingHom = ⊥ := + (RingHom.injective_iff_ker_eq_bot e.toRingHom).mp e.injective + rw [← Ideal.map_radical_of_surjective e.surjective + (hk ▸ bot_le), hI] + exact IsLocalRing.map_ringEquiv_maximalIdeal e + +theorem map_span_range_of_commuting_images + {A B ι : Type*} [CommRing A] [CommRing B] + (e : A →+* B) (f : ι → A) (g : ι → B) (h : ∀ i, e (f i) = g i) : + (Ideal.span (Set.range f)).map e = Ideal.span (Set.range g) := by + rw [Ideal.map_span, ← Set.range_comp] + congr 1 + exact congrArg Set.range (funext h) + +theorem quotient_length_eq_of_commuting_images + {A B ι : Type*} [CommRing A] [CommRing B] + (e : A ≃+* B) (f : ι → A) (g : ι → B) (h : ∀ i, e (f i) = g i) : + Module.length A (A ⧸ Ideal.span (Set.range f)) = + Module.length B (B ⧸ Ideal.span (Set.range g)) := by + exact DegreeBezout.quotient_length_eq_of_ringEquiv e _ _ + (map_span_range_of_commuting_images e.toRingHom f g h).symm + +theorem radical_span_eq_maximalIdeal_of_commuting_images + {A B ι : Type*} [CommRing A] [CommRing B] [IsLocalRing A] [IsLocalRing B] + (e : A ≃+* B) (f : ι → A) (g : ι → B) (h : ∀ i, e (f i) = g i) + (hf : (Ideal.span (Set.range f)).radical = IsLocalRing.maximalIdeal A) : + (Ideal.span (Set.range g)).radical = IsLocalRing.maximalIdeal B := by + rw [← map_span_range_of_commuting_images e.toRingHom f g h] + exact radical_map_ringEquiv_eq_maximalIdeal e _ hf + +noncomputable def polynomialRenameLocalEquiv + {K σ τ : Type*} [Field K] (e : σ ≃ τ) + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + Localization.AtPrime p ≃+* + Localization.AtPrime (p.comap (MvPolynomial.renameEquiv K e).symm.toRingHom) := + (Localization.localRingEquiv _ p (MvPolynomial.renameEquiv K e).symm.toRingEquiv rfl).symm + +theorem polynomialRename_localEquiv_algebraMap + {K σ τ : Type*} [Field K] (e : σ ≃ τ) + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (f : MvPolynomial σ K) : + polynomialRenameLocalEquiv e p (algebraMap _ (Localization.AtPrime p) f) = + algebraMap _ (Localization.AtPrime + (p.comap (MvPolynomial.renameEquiv K e).symm.toRingHom)) + (MvPolynomial.renameEquiv K e f) := by + apply (polynomialRenameLocalEquiv e p).symm.injective + rw [RingEquiv.symm_apply_apply] + change algebraMap _ (Localization.AtPrime p) f = + Localization.localRingHom _ p (MvPolynomial.renameEquiv K e).symm.toRingHom rfl + (algebraMap _ _ (MvPolynomial.renameEquiv K e f)) + rw [Localization.localRingHom_to_map] + exact congrArg (algebraMap _ (Localization.AtPrime p)) + ((MvPolynomial.renameEquiv K e).symm_apply_apply f).symm + +theorem maximal_local_bound_of_card_eq + {K σ : Type*} [Field K] [Finite σ] (h d : ℕ) + (hbound : ∀ (q : Ideal (MvPolynomial (Fin h) K)) [q.IsMaximal] + (g : Fin h → MvPolynomial (Fin h) K), + (∀ i, (g i).totalDegree ≤ d) → + (Ideal.span (Set.range (fun i => algebraMap _ (Localization.AtPrime q) (g i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime q) → + Module.length (Localization.AtPrime q) + (Localization.AtPrime q ⧸ Ideal.span + (Set.range (fun i => algebraMap _ (Localization.AtPrime q) (g i)))) ≤ (d ^ h : ℕ∞)) + (p : Ideal (MvPolynomial σ K)) [p.IsMaximal] + (hcard : Nat.card σ = h) (f : Fin h → MvPolynomial σ K) + (hf : ∀ i, (f i).totalDegree ≤ d) + (hrad : (Ideal.span (Set.range (fun i => algebraMap _ (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ Ideal.span + (Set.range (fun i => algebraMap _ (Localization.AtPrime p) (f i)))) ≤ (d ^ h : ℕ∞) := by + let := Fintype.ofFinite σ + let e : σ ≃ Fin h := Fintype.equivFinOfCardEq (by simpa only [Nat.card_eq_fintype_card] using hcard) + let q := p.comap (MvPolynomial.renameEquiv K e).symm.toRingHom + have : q.IsMaximal := Ideal.comap_isMaximal_of_surjective + (MvPolynomial.renameEquiv K e).symm.toRingHom (MvPolynomial.renameEquiv K e).symm.surjective + let g : Fin h → MvPolynomial (Fin h) K := fun i => MvPolynomial.renameEquiv K e (f i) + have hg : ∀ i, (g i).totalDegree ≤ d := by + intro i + exact (MvPolynomial.totalDegree_renameEquiv e (f i)) ▸ hf i + let he := polynomialRenameLocalEquiv e p + have hcomm (i : Fin h) : he (algebraMap _ (Localization.AtPrime p) (f i)) = + algebraMap _ (Localization.AtPrime q) (g i) := polynomialRename_localEquiv_algebraMap e p (f i) + have hrad' := radical_span_eq_maximalIdeal_of_commuting_images he _ _ hcomm hrad + rw [quotient_length_eq_of_commuting_images he _ _ hcomm] + exact hbound q g hg hrad' + +theorem local_parameter_bound_of_isLocalization_atPrime + {R A ι : Type*} [CommRing R] [CommRing A] [Algebra R A] + (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime A p] [IsLocalRing A] + (f : ι → R) (B : ℕ∞) + (hbound : (Ideal.span (Set.range (fun i => algebraMap R (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p) → + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ Ideal.span + (Set.range (fun i => algebraMap R (Localization.AtPrime p) (f i)))) ≤ B) + (hrad : (Ideal.span (Set.range (fun i => algebraMap R A (f i)))).radical = + IsLocalRing.maximalIdeal A) : + Module.length A (A ⧸ Ideal.span (Set.range (fun i => algebraMap R A (f i)))) ≤ B := by + let e := IsLocalization.algEquiv p.primeCompl A (Localization.AtPrime p) + have hcomm (i : ι) : e (algebraMap R A (f i)) = + algebraMap R (Localization.AtPrime p) (f i) := e.commutes (f i) + have hrad' := radical_span_eq_maximalIdeal_of_commuting_images e.toRingEquiv _ _ hcomm hrad + rw [quotient_length_eq_of_commuting_images e.toRingEquiv _ _ hcomm] + exact hbound hrad' + + + +universe u v w + +theorem arbitrary_prime_bound_of_maximal_local_bound + {K : Type u} {σ : Type v} [Field K] [Finite σ] (h d : ℕ) + (hbound : ∀ (F : Type (max u v)) [Field F] + (q : Ideal (MvPolynomial (Fin h) F)) [q.IsMaximal] + (g : Fin h → MvPolynomial (Fin h) F), + (∀ i, (g i).totalDegree ≤ d) → + (Ideal.span (Set.range (fun i => algebraMap _ (Localization.AtPrime q) (g i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime q) → + Module.length (Localization.AtPrime q) + (Localization.AtPrime q ⧸ Ideal.span + (Set.range (fun i => algebraMap _ (Localization.AtPrime q) (g i)))) ≤ (d ^ h : ℕ∞)) + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (hheight : p.height = (h : ℕ∞)) + (f : Fin h → MvPolynomial σ K) (hf : ∀ i, (f i).totalDegree ≤ d) + (hrad : (Ideal.span (Set.range (fun i => algebraMap _ (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ Ideal.span + (Set.range (fun i => algebraMap _ (Localization.AtPrime p) (f i)))) ≤ (d ^ h : ℕ∞) := by + obtain ⟨s, hs, hq, hrest⟩ := exists_coordinate_localization p + let := hq + obtain ⟨_, hcard, e, he⟩ := hrest + let g : Fin h → MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K)) := + fun i => MvPolynomial.map + (algebraMap (MvPolynomial s K) (FractionRing (MvPolynomial s K))) (coordinateSplit s (f i)) + have hg : ∀ i, (g i).totalDegree ≤ d := fun i => (he (f i)).2.trans (hf i) + have hcomm (i : Fin h) : e (algebraMap _ (Localization.AtPrime p) (f i)) = + algebraMap _ (Localization.AtPrime (coordinateLocalizedPrime s p)) (g i) := (he (f i)).1 + let eR : Localization.AtPrime p ≃+* Localization.AtPrime (coordinateLocalizedPrime s p) := + e.toRingEquiv + have hrad' := radical_span_eq_maximalIdeal_of_commuting_images eR + (fun i => algebraMap _ (Localization.AtPrime p) (f i)) + (fun i => algebraMap _ (Localization.AtPrime (coordinateLocalizedPrime s p)) (g i)) + (fun i => hcomm i) hrad + rw [quotient_length_eq_of_commuting_images eR + (fun i => algebraMap _ (Localization.AtPrime p) (f i)) + (fun i => algebraMap _ (Localization.AtPrime (coordinateLocalizedPrime s p)) (g i)) + (fun i => hcomm i)] + apply maximal_local_bound_of_card_eq h d (hbound (FractionRing (MvPolynomial s K))) (coordinateLocalizedPrime s p) _ g hg hrad' + exact WithTop.coe_eq_coe.mp (hcard.trans hheight) + +theorem arbitrary_local_bound_of_maximal_local_bound + {K : Type u} {σ : Type v} {A : Type w} [Field K] [Finite σ] [CommRing A] [Algebra (MvPolynomial σ K) A] + (h d : ℕ) + (hbound : ∀ (F : Type (max u v)) [Field F] + (q : Ideal (MvPolynomial (Fin h) F)) [q.IsMaximal] + (g : Fin h → MvPolynomial (Fin h) F), + (∀ i, (g i).totalDegree ≤ d) → + (Ideal.span (Set.range (fun i => algebraMap _ (Localization.AtPrime q) (g i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime q) → + Module.length (Localization.AtPrime q) + (Localization.AtPrime q ⧸ Ideal.span + (Set.range (fun i => algebraMap _ (Localization.AtPrime q) (g i)))) ≤ (d ^ h : ℕ∞)) + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] [IsLocalization.AtPrime A p] [IsLocalRing A] + (hheight : p.height = (h : ℕ∞)) + (f : Fin h → MvPolynomial σ K) (hf : ∀ i, (f i).totalDegree ≤ d) + (hrad : (Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ K) A (f i)))).radical = + IsLocalRing.maximalIdeal A) : + Module.length A (A ⧸ Ideal.span + (Set.range (fun i => algebraMap (MvPolynomial σ K) A (f i)))) ≤ (d ^ h : ℕ∞) := by + apply local_parameter_bound_of_isLocalization_atPrime p f (d ^ h) + (fun hrad' => arbitrary_prime_bound_of_maximal_local_bound h d hbound p hheight f hf hrad') hrad + + + +section RectangleUpper + +universe uSource +variable {K : Type uSource} [Field K] [Infinite K] +local notation "P₄" => MvPolynomial (Fin 4) K +local notation "T₄" => Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P₄)) + +end RectangleUpper + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry.DegreeBezout +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem coefficient_residue_injective + {B σ : Type*} [CommRing B] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + (hp : p.comap MvPolynomial.C = ⊥) : + Function.Injective (algebraMap B p.ResidueField) := by + rw [RingHom.injective_iff_ker_eq_bot, + IsScalarTower.algebraMap_eq B (MvPolynomial σ B) p.ResidueField, + ← RingHom.comap_ker, Ideal.ker_algebraMap_residueField] + exact hp + +@[instance_reducible] noncomputable def componentCoefficientFractionAlgebra + {B F σ : Type*} [CommRing B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + (hp : p.comap MvPolynomial.C = ⊥) : Algebra F p.ResidueField := + (IsFractionRing.lift (K := F) (coefficient_residue_injective p hp)).toAlgebra + +theorem componentCoefficientFractionAlgebra_tower + {B F σ : Type*} [CommRing B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + (hp : p.comap MvPolynomial.C = ⊥) : + letI := componentCoefficientFractionAlgebra (F := F) p hp + IsScalarTower B F p.ResidueField := by + let := componentCoefficientFractionAlgebra (F := F) p hp + apply IsScalarTower.of_algebraMap_eq + intro b + exact (IsFractionRing.lift_algebraMap (K := F) (coefficient_residue_injective p hp) b).symm + +theorem component_functionField_finite + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [Module.Finite B (MvPolynomial σ B ⧸ p)] + (hp : p.comap MvPolynomial.C = ⊥) : + letI := componentCoefficientFractionAlgebra (F := F) p hp + Module.Finite F p.ResidueField := by + let := componentCoefficientFractionAlgebra (F := F) p hp + let := componentCoefficientFractionAlgebra_tower (F := F) p hp + have hb : Function.Injective (algebraMap B (MvPolynomial σ B ⧸ p)) := by + intro x y hxy + apply coefficient_residue_injective p hp + rw [IsScalarTower.algebraMap_apply B (MvPolynomial σ B ⧸ p) p.ResidueField, + IsScalarTower.algebraMap_apply B (MvPolynomial σ B ⧸ p) p.ResidueField, hxy] + let : FaithfulSMul B (MvPolynomial σ B ⧸ p) := + (faithfulSMul_iff_algebraMap_injective B (MvPolynomial σ B ⧸ p)).mpr hb + apply Module.finite_of_finrank_pos + rw [IsFractionRing.finrank_eq B F (MvPolynomial σ B ⧸ p) p.ResidueField] + exact Module.finrank_pos + +theorem coefficient_localization_isMaximal_of_finite + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [Module.Finite B (MvPolynomial σ B ⧸ p)] + (hp : p.comap MvPolynomial.C = ⊥) : + (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsMaximal := by + let := componentCoefficientFractionAlgebra (F := F) p hp + let := componentCoefficientFractionAlgebra_tower (F := F) p hp + let := component_functionField_finite (F := F) p hp + let M : Submonoid (MvPolynomial σ B) := (nonZeroDivisors B).map MvPolynomial.C + let g := IsScalarTower.toAlgHom B (MvPolynomial σ B) p.ResidueField + have hu : ∀ y : M, IsUnit (g y) := by + intro y + apply isUnit_iff_ne_zero.mpr + intro hy + have hyp : (y : MvPolynomial σ B) ∈ p := + Ideal.algebraMap_residueField_eq_zero.mp hy + exact Set.disjoint_left.mp (coefficient_nonZeroDivisors_disjoint p hp) y.property hyp + let fB : MvPolynomial σ F →ₐ[B] p.ResidueField := IsLocalization.liftAlgHom hu + let f := fB.extendScalarsOfIsLocalization F (nonZeroDivisors B) + have he : f.toRingHom.comp (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) = + algebraMap (MvPolynomial σ B) p.ResidueField := by + exact IsLocalization.lift_comp hu + apply coefficient_localization_isMaximal p f + change (RingHom.ker f.toRingHom).comap + (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) = p + rw [RingHom.comap_ker, he, Ideal.ker_algebraMap_residueField] + +end WeightedTorusJets.Geometry.DegreeBezout + +noncomputable section + +namespace WeightedTorusJets.Geometry.DegreeBezout + +open MvPolynomial +attribute [local instance] MvPolynomial.algebraMvPolynomial + +variable {K σ ι τ : Type*} [CommRing K] + +def normalizationPresentation + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) : + MvPolynomial σ K ≃ₐ[K] MvPolynomial τ (MvPolynomial ι K) := + e.symm.trans ((renameEquiv K (Equiv.sumComm ι τ)).trans (sumAlgEquiv K τ ι)) + +@[simp] theorem normalizationPresentation_symm_C_X + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) (i : ι) : + (normalizationPresentation e).symm (C (X i)) = e (X (Sum.inl i)) := by + simp [normalizationPresentation] + +@[simp] theorem normalizationPresentation_symm_X + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) (j : τ) : + (normalizationPresentation e).symm (X j) = e (X (Sum.inr j)) := by + simp [normalizationPresentation] + +theorem normalizationPresentation_coefficient_map + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (P : Ideal (MvPolynomial σ K)) + (g : MvPolynomial ι K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hg : ∀ i, g (X i) = Ideal.Quotient.mk P (e (X (Sum.inl i)))) + (b : MvPolynomial ι K) : + Ideal.Quotient.mk P ((normalizationPresentation e).symm (C b)) = g b := by + have h : (Ideal.Quotient.mkₐ K P).comp + ((normalizationPresentation e).symm.toAlgHom.comp + (IsScalarTower.toAlgHom K (MvPolynomial ι K) + (MvPolynomial τ (MvPolynomial ι K)))) = g := by + ext i + change Ideal.Quotient.mk P ((normalizationPresentation e).symm (C (X i))) = g (X i) + rw [normalizationPresentation_symm_C_X] + exact (hg i).symm + exact congrArg (fun f : MvPolynomial ι K →ₐ[K] (MvPolynomial σ K ⧸ P) => f b) h + +def normalizationPresentationQuotientEquiv + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (P : Ideal (MvPolynomial σ K)) + (g : MvPolynomial ι K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hg : ∀ i, g (X i) = Ideal.Quotient.mk P (e (X (Sum.inl i)))) : + let := g.toAlgebra + (MvPolynomial τ (MvPolynomial ι K) ⧸ + P.comap (normalizationPresentation e).symm.toRingHom) ≃ₐ[MvPolynomial ι K] + (MvPolynomial σ K ⧸ P) := by + let := g.toAlgebra + let q := P.comap (normalizationPresentation e).symm.toRingHom + let eQ : (MvPolynomial τ (MvPolynomial ι K) ⧸ q) ≃ₐ[K] + (MvPolynomial σ K ⧸ P) := + Ideal.quotientEquivAlg q P (normalizationPresentation e).symm + (Ideal.map_comap_of_surjective (normalizationPresentation e).symm.toRingHom + (normalizationPresentation e).symm.surjective P).symm + refine { eQ.toRingEquiv with commutes' := ?_ } + intro b + change eQ (Ideal.Quotient.mk q (C b)) = g b + change Ideal.Quotient.mk P ((normalizationPresentation e).symm (C b)) = g b + exact normalizationPresentation_coefficient_map e P g hg b + +theorem normalizationPresentation_coefficient_comap_eq_bot + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (P : Ideal (MvPolynomial σ K)) + (g : MvPolynomial ι K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hginj : Function.Injective g) + (hg : ∀ i, g (X i) = Ideal.Quotient.mk P (e (X (Sum.inl i)))) : + (P.comap (normalizationPresentation e).symm.toRingHom).comap C = ⊥ := by + apply bot_unique + intro b hb + apply hginj + rw [map_zero, ← normalizationPresentation_coefficient_map e P g hg b] + exact Ideal.Quotient.eq_zero_iff_mem.mpr hb + +theorem finite_normalizationPresentation_quotient + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (P : Ideal (MvPolynomial σ K)) + (g : MvPolynomial ι K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hg : ∀ i, g (X i) = Ideal.Quotient.mk P (e (X (Sum.inl i)))) + (hfinite : letI := g.toAlgebra + letI : Module (MvPolynomial ι K) (MvPolynomial σ K ⧸ P) := Algebra.toModule + Module.Finite (MvPolynomial ι K) (MvPolynomial σ K ⧸ P)) : + Module.Finite (MvPolynomial ι K) + (MvPolynomial τ (MvPolynomial ι K) ⧸ + P.comap (normalizationPresentation e).symm.toRingHom) := by + let := g.toAlgebra + let : Module (MvPolynomial ι K) (MvPolynomial σ K ⧸ P) := Algebra.toModule + have : Module.Finite (MvPolynomial ι K) (MvPolynomial σ K ⧸ P) := hfinite + exact Module.Finite.equiv (normalizationPresentationQuotientEquiv e P g hg).symm.toLinearEquiv + +end WeightedTorusJets.Geometry.DegreeBezout + +end +end +end +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/DegreeMap.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DegreeMap.lean new file mode 100644 index 0000000000000000000000000000000000000000..d4e526e89d4e0ca9d32fc6971d6514092ba72c2a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DegreeMap.lean @@ -0,0 +1,490 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.HomogeneousDeformation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +section + +noncomputable section + +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial + +variable {K σ : Type*} [Field K] + +attribute [local instance] MvPolynomial.gradedAlgebra + +def degreeMap {I J : Ideal (MvPolynomial σ K)} (hIJ : I ≤ J) (n : ℕ) : + degreePiece I n →ₗ[K] degreePiece J n where + toFun x := ⟨Ideal.Quotient.factorₐ K hIJ x, by + rcases x.property with ⟨p, hp, hpx⟩ + exact ⟨p, hp, by rw [← hpx]; rfl⟩⟩ + map_add' x y := Subtype.ext (map_add _ _ _) + map_smul' a x := Subtype.ext (map_smul _ _ _) + +theorem degreeMap_surjective {I J : Ideal (MvPolynomial σ K)} (hIJ : I ≤ J) (n : ℕ) : + Function.Surjective (degreeMap hIJ n) := by + rintro ⟨x, p, hp, rfl⟩ + exact ⟨⟨Ideal.Quotient.mk I p, p, hp, rfl⟩, rfl⟩ + +def degreeMul (I : Ideal (MvPolynomial σ K)) {f : MvPolynomial σ K} {d : ℕ} + (hf : f.IsHomogeneous d) (n : ℕ) : degreePiece I n →ₗ[K] degreePiece I (d + n) where + toFun x := ⟨Ideal.Quotient.mk I f * x, by + rcases x.property with ⟨p, hp, hpx⟩ + refine ⟨f * p, hf.mul hp, ?_⟩ + change Ideal.Quotient.mk I (f * p) = _ + change Ideal.Quotient.mk I p = _ at hpx + rw [map_mul, hpx]⟩ + map_add' x y := Subtype.ext (mul_add _ _ _) + map_smul' a x := Subtype.ext (mul_smul_comm _ _ _) + +theorem degreeMul_injective (I : Ideal (MvPolynomial σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) + (hreg : IsSMulRegular (MvPolynomial σ K ⧸ I) (Ideal.Quotient.mk I f)) (n : ℕ) : + Function.Injective (degreeMul I hf n) := by + intro x y hxy + apply Subtype.ext + exact hreg (congrArg Subtype.val hxy) + +theorem homogeneous_mem_sup_span_iff + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f p : MvPolynomial σ K} {d n : ℕ} (hf : f.IsHomogeneous d) + (hp : p.IsHomogeneous n) (hdn : d ≤ n) : + p ∈ I ⊔ Ideal.span {f} ↔ + ∃ g : MvPolynomial σ K, g.IsHomogeneous (n - d) ∧ p - f * g ∈ I := by + constructor + · intro h + obtain ⟨a, b, hb, hab⟩ := Ideal.mem_span_singleton_sup.mp (by + simpa only [sup_comm] using h) + rw [mul_comm a f] at hab + refine ⟨homogeneousComponent (n - d) a, homogeneousComponent_isHomogeneous _ _, ?_⟩ + have heq : p - f * homogeneousComponent (n - d) a = homogeneousComponent n b := by + conv_lhs => lhs; rw [← homogeneousComponent_eq_self hp, ← hab] + rw [map_add, homogeneousComponent_mul_of_le hf hdn] + simp + rw [heq] + exact homogeneousComponent_mem_of_mem hI hb n + · rintro ⟨g, _, hpg⟩ + rw [← sub_add_cancel p (f * g)] + exact Ideal.add_mem _ ((le_sup_left : I ≤ I ⊔ Ideal.span {f}) hpg) + ((le_sup_right : Ideal.span {f} ≤ I ⊔ Ideal.span {f}) + (Ideal.mul_mem_right _ _ (Ideal.subset_span (Set.mem_singleton f)))) + +theorem homogeneous_mem_sup_span_iff_of_lt + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f p : MvPolynomial σ K} {d n : ℕ} (hf : f.IsHomogeneous d) + (hp : p.IsHomogeneous n) (hnd : n < d) : + p ∈ I ⊔ Ideal.span {f} ↔ p ∈ I := by + constructor + · intro h + obtain ⟨a, b, hb, hab⟩ := Ideal.mem_span_singleton_sup.mp (by + simpa only [sup_comm] using h) + rw [mul_comm a f] at hab + have heq : p = homogeneousComponent n b := by + rw [← homogeneousComponent_eq_self hp, ← hab, map_add, + homogeneousComponent_mul_of_lt hf hnd, zero_add] + rw [heq] + exact homogeneousComponent_mem_of_mem hI hb n + · exact fun hpI => (le_sup_left : I ≤ I ⊔ Ideal.span {f}) hpI + +theorem ker_degreeMap_eq_range_degreeMul + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) : + LinearMap.ker (degreeMap (le_sup_left : I ≤ I ⊔ Ideal.span {f}) (d + n)) = + LinearMap.range (degreeMul I hf n) := by + ext x + rcases x with ⟨x, p, hp, rfl⟩ + rw [LinearMap.mem_ker, LinearMap.mem_range] + constructor + · intro h + have hpJ : p ∈ I ⊔ Ideal.span {f} := + Ideal.Quotient.eq_zero_iff_mem.mp (congrArg Subtype.val h) + obtain ⟨g, hg, hpg⟩ := (homogeneous_mem_sup_span_iff hI hf hp (Nat.le_add_right d n)).mp hpJ + have hgn : g.IsHomogeneous n := by simpa using hg + refine ⟨⟨Ideal.Quotient.mk I g, g, hgn, rfl⟩, Subtype.ext ?_⟩ + change Ideal.Quotient.mk I f * Ideal.Quotient.mk I g = Ideal.Quotient.mk I p + rw [← map_mul] + exact (Ideal.Quotient.eq.mpr hpg).symm + · rintro ⟨y, hy⟩ + rw [← hy] + apply Subtype.ext + change Ideal.Quotient.factorₐ K _ (Ideal.Quotient.mk I f * (y : MvPolynomial σ K ⧸ I)) = 0 + rw [map_mul] + have hfJ : Ideal.Quotient.mk (I ⊔ Ideal.span {f}) f = 0 := + Ideal.Quotient.eq_zero_iff_mem.mpr + ((le_sup_right : Ideal.span {f} ≤ I ⊔ Ideal.span {f}) (Ideal.subset_span (Set.mem_singleton f))) + change Ideal.Quotient.mk (I ⊔ Ideal.span {f}) f * _ = 0 + rw [hfJ, zero_mul] + +def degreeCokernelEquiv + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) : + (degreePiece I (d + n) ⧸ LinearMap.range (degreeMul I hf n)) ≃ₗ[K] + degreePiece (I ⊔ Ideal.span {f}) (d + n) := + (Submodule.quotEquivOfEq _ _ (ker_degreeMap_eq_range_degreeMul hI hf n).symm).trans + ((degreeMap (le_sup_left : I ≤ I ⊔ Ideal.span {f}) (d + n)).quotKerEquivOfSurjective + (degreeMap_surjective _ _)) + +theorem degreeCokernelEquiv_mk + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) + (x : degreePiece I (d + n)) : + degreeCokernelEquiv hI hf n (Submodule.Quotient.mk x) = degreeMap le_sup_left (d + n) x := by + simp [degreeCokernelEquiv, Submodule.quotEquivOfEq_mk] + +instance degreePiece_finite [Finite σ] (I : Ideal (MvPolynomial σ K)) (n : ℕ) : + Module.Finite K (degreePiece I n) := + Module.Finite.of_fg ((homogeneousSubmodule_fg σ K n).map _) + +theorem finrank_degreePiece_sup_span_add [Finite σ] + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) + (hreg : IsSMulRegular (MvPolynomial σ K ⧸ I) (Ideal.Quotient.mk I f)) (n : ℕ) : + Module.finrank K (degreePiece (I ⊔ Ideal.span {f}) (d + n)) = + Module.finrank K (degreePiece I (d + n)) - Module.finrank K (degreePiece I n) := by + have h := (degreeCokernelEquiv hI hf n).finrank_eq + rw [Submodule.finrank_quotient, + LinearMap.finrank_range_of_inj (degreeMul_injective I hf hreg n)] at h + exact h.symm + +theorem degreeMap_injective_of_lt + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d n : ℕ} (hf : f.IsHomogeneous d) (hnd : n < d) : + Function.Injective (degreeMap (le_sup_left : I ≤ I ⊔ Ideal.span {f}) n) := by + apply LinearMap.ker_eq_bot.mp + ext x + rw [LinearMap.mem_ker, Submodule.mem_bot] + constructor + · intro hx + rcases x with ⟨x, p, hp, rfl⟩ + apply Subtype.ext + change Ideal.Quotient.mk I p = 0 + apply Ideal.Quotient.eq_zero_iff_mem.mpr + apply (homogeneous_mem_sup_span_iff_of_lt hI hf hp hnd).mp + exact Ideal.Quotient.eq_zero_iff_mem.mp (congrArg Subtype.val hx) + · rintro rfl + exact map_zero _ + +def degreeEquivOfLt + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d n : ℕ} (hf : f.IsHomogeneous d) (hnd : n < d) : + degreePiece I n ≃ₗ[K] degreePiece (I ⊔ Ideal.span {f}) n := + LinearEquiv.ofBijective (degreeMap le_sup_left n) + ⟨degreeMap_injective_of_lt hI hf hnd, degreeMap_surjective _ _⟩ + +theorem finrank_degreePiece_sup_span [Finite σ] + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) + (hreg : IsSMulRegular (MvPolynomial σ K ⧸ I) (Ideal.Quotient.mk I f)) (n : ℕ) : + Module.finrank K (degreePiece (I ⊔ Ideal.span {f}) n) = + Module.finrank K (degreePiece I n) - + if d ≤ n then Module.finrank K (degreePiece I (n - d)) else 0 := by + split_ifs with hdn + · have h := finrank_degreePiece_sup_span_add hI hf hreg (n - d) + have hindex : d + (n - d) = n := by omega + rw [hindex] at h + exact h + · simpa using (degreeEquivOfLt hI hf (Nat.lt_of_not_ge hdn)).finrank_eq.symm + +theorem finrank_degreePiece_sup_span_add_finrank [Finite σ] + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) + (hreg : IsSMulRegular (MvPolynomial σ K ⧸ I) (Ideal.Quotient.mk I f)) (n : ℕ) : + Module.finrank K (degreePiece (I ⊔ Ideal.span {f}) n) + + (if d ≤ n then Module.finrank K (degreePiece I (n - d)) else 0) = + Module.finrank K (degreePiece I n) := by + split_ifs with hdn + · have h := (LinearMap.range (degreeMul I hf (n - d))).finrank_quotient_add_finrank + rw [(degreeCokernelEquiv hI hf (n - d)).finrank_eq, + LinearMap.finrank_range_of_inj (degreeMul_injective I hf hreg (n - d))] at h + have hindex : d + (n - d) = n := by omega + rw [hindex] at h + exact h + · simpa using (degreeEquivOfLt hI hf (Nat.lt_of_not_ge hdn)).finrank_eq.symm + +end WeightedTorusJets.Geometry.GradedQuotient + +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial + +variable {K σ : Type*} [Field K] + +attribute [local instance] MvPolynomial.gradedAlgebra + +noncomputable def quotientMulColon (I : Ideal (MvPolynomial σ K)) (f : MvPolynomial σ K) : + (MvPolynomial σ K ⧸ I.colon {f}) →ₗ[K] (MvPolynomial σ K ⧸ I) := + ((I.colon {f}).restrictScalars K).mapQ (I.restrictScalars K) + (LinearMap.mul K (MvPolynomial σ K) f) (by + intro p hp + change f * p ∈ I + change p ∈ I.colon {f} at hp + simpa only [Submodule.mem_colon_singleton, smul_eq_mul, mul_comm] using hp) + +theorem quotientMulColon_mk (I : Ideal (MvPolynomial σ K)) (f p : MvPolynomial σ K) : + quotientMulColon I f (Ideal.Quotient.mk (I.colon {f}) p) = + Ideal.Quotient.mk I (f * p) := rfl + +theorem quotientMulColon_injective (I : Ideal (MvPolynomial σ K)) (f : MvPolynomial σ K) : + Function.Injective (quotientMulColon I f) := by + apply LinearMap.ker_eq_bot.mp + ext x + rw [LinearMap.mem_ker, Submodule.mem_bot] + constructor + · intro hx + obtain ⟨p, rfl⟩ := Ideal.Quotient.mk_surjective x + rw [quotientMulColon_mk, Ideal.Quotient.eq_zero_iff_mem] at hx + apply Ideal.Quotient.eq_zero_iff_mem.mpr + simpa only [Submodule.mem_colon_singleton, smul_eq_mul, mul_comm] using hx + · rintro rfl + exact map_zero _ + +noncomputable def degreeMulColon (I : Ideal (MvPolynomial σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) : + degreePiece (I.colon {f}) n →ₗ[K] degreePiece I (d + n) where + toFun x := ⟨quotientMulColon I f x, by + rcases x.property with ⟨p, hp, hpx⟩ + refine ⟨f * p, hf.mul hp, ?_⟩ + rw [← hpx] + rfl⟩ + map_add' x y := Subtype.ext (map_add (quotientMulColon I f) + (x : MvPolynomial σ K ⧸ I.colon {f}) (y : MvPolynomial σ K ⧸ I.colon {f})) + map_smul' a x := Subtype.ext (map_smul (quotientMulColon I f) a + (x : MvPolynomial σ K ⧸ I.colon {f})) + +theorem degreeMulColon_injective (I : Ideal (MvPolynomial σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) : + Function.Injective (degreeMulColon I hf n) := by + intro x y hxy + apply Subtype.ext + exact quotientMulColon_injective I f (congrArg Subtype.val hxy) + +theorem degreeMulColon_comp_degreeMap (I : Ideal (MvPolynomial σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) : + (degreeMulColon I hf n).comp (degreeMap (Ideal.le_colon : I ≤ I.colon {f}) n) = + degreeMul I hf n := by + ext x + rcases x with ⟨x, p, hp, rfl⟩ + exact map_mul (Ideal.Quotient.mk I) f p + +theorem range_degreeMulColon (I : Ideal (MvPolynomial σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) : + LinearMap.range (degreeMulColon I hf n) = LinearMap.range (degreeMul I hf n) := by + rw [← degreeMulColon_comp_degreeMap I hf n, LinearMap.range_comp, + LinearMap.range_eq_top.mpr (degreeMap_surjective _ _), Submodule.map_top] + +theorem colon_isHomogeneous {I : Ideal (MvPolynomial σ K)} + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) : + (I.colon {f}).IsHomogeneous (homogeneousSubmodule σ K) := by + intro n p hp + change (decomposition.decompose' p n : MvPolynomial σ K) ∈ I.colon {f} + rw [decomposition.decompose'_apply, Submodule.mem_colon_singleton] + change homogeneousComponent n p * f ∈ I + have hfp : f * p ∈ I := by + simpa only [Submodule.mem_colon_singleton, smul_eq_mul, mul_comm] using hp + have h := homogeneousComponent_mem_of_mem hI hfp (d + n) + rw [homogeneousComponent_mul_of_le hf (Nat.le_add_right d n), Nat.add_sub_cancel_left] at h + simpa only [mul_comm] using h + +theorem finrank_degreePiece_sup_span_add_colon [Finite σ] + {I : Ideal (MvPolynomial σ K)} (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + {f : MvPolynomial σ K} {d : ℕ} (hf : f.IsHomogeneous d) (n : ℕ) : + Module.finrank K (degreePiece (I ⊔ Ideal.span {f}) n) + + (if d ≤ n then Module.finrank K (degreePiece (I.colon {f}) (n - d)) else 0) = + Module.finrank K (degreePiece I n) := by + split_ifs with hdn + · have h := (LinearMap.range (degreeMul I hf (n - d))).finrank_quotient_add_finrank + rw [(degreeCokernelEquiv hI hf (n - d)).finrank_eq, + ← range_degreeMulColon I hf (n - d), + LinearMap.finrank_range_of_inj (degreeMulColon_injective I hf (n - d))] at h + have hindex : d + (n - d) = n := by omega + rw [hindex] at h + exact h + · simpa using (degreeEquivOfLt hI hf (Nat.lt_of_not_ge hdn)).finrank_eq.symm + +end WeightedTorusJets.Geometry.GradedQuotient + +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial + +theorem degreePiece_eq_bot_of_variables_mem {K σ : Type*} [Field K] + (I : Ideal (MvPolynomial σ K)) (hI : ∀ i : σ, X i ∈ I) + {n : ℕ} (hn : 0 < n) : degreePiece I n = ⊥ := by + have hvars : idealOfVars σ K ≤ I := Ideal.span_le.mpr (by + rintro _ ⟨i, rfl⟩ + exact hI i) + apply le_antisymm _ bot_le + rintro x ⟨p, hp, rfl⟩ + change Ideal.Quotient.mk I p = 0 + apply Ideal.Quotient.eq_zero_iff_mem.mpr + apply hvars + rw [← pow_one (idealOfVars σ K), mem_pow_idealOfVars_iff'] + intro a ha + exact hp.coeff_eq_zero (by omega) + +theorem finrank_degreePiece_eq_zero_of_variables_mem {K σ : Type*} [Field K] + (I : Ideal (MvPolynomial σ K)) (hI : ∀ i : σ, X i ∈ I) + {n : ℕ} (hn : 0 < n) : Module.finrank K (degreePiece I n) = 0 := by + rw [degreePiece_eq_bot_of_variables_mem I hI hn, finrank_bot] + +end WeightedTorusJets.Geometry.GradedQuotient + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +variable {R : Type*} [CommRing R] + +local notation "HR" => fun S : PowerSeries R ↦ + ∃ d : ℕ, ∃ p : Polynomial R, + ((1 : PowerSeries R) - PowerSeries.X) ^ d * S = (p : PowerSeries R) + +theorem HilbertRational.polynomial (p : Polynomial R) : + HR (p : PowerSeries R) := ⟨0, p, by simp⟩ + +theorem HilbertRational.add {S T : PowerSeries R} + (hS : HR S) (hT : HR T) : HR (S + T) := by + obtain ⟨d, p, hp⟩ := hS + obtain ⟨e, q, hq⟩ := hT + refine ⟨d + e, (1 - Polynomial.X) ^ e * p + (1 - Polynomial.X) ^ d * q, ?_⟩ + push_cast + rw [pow_add, mul_add] + calc + _ = (1 - PowerSeries.X) ^ e * ((1 - PowerSeries.X) ^ d * S) + + (1 - PowerSeries.X) ^ d * ((1 - PowerSeries.X) ^ e * T) := by ring + _ = _ := by rw [hp, hq] + +theorem HilbertRational.X_mul {S : PowerSeries R} (hS : HR S) : + HR (PowerSeries.X * S) := by + obtain ⟨d, p, hp⟩ := hS + refine ⟨d, Polynomial.X * p, ?_⟩ + push_cast + calc + _ = PowerSeries.X * ((1 - PowerSeries.X) ^ d * S) := by ring + _ = _ := by rw [hp] + +theorem HilbertRational.of_eq_add_X_mul_self {S T : PowerSeries R} + (hT : HR T) (hST : S = T + PowerSeries.X * S) : HR S := by + obtain ⟨d, p, hp⟩ := hT + have hclear : (1 - PowerSeries.X) * S = T := by + rw [sub_mul, one_mul] + exact sub_eq_iff_eq_add.mpr hST + refine ⟨d + 1, p, ?_⟩ + rw [pow_succ, mul_assoc, hclear, hp] + +theorem HilbertRational.exists_mul_invOneSubPow {S : PowerSeries R} + (hS : HR S) : + ∃ p : Polynomial R, ∃ d : ℕ, S = p * PowerSeries.invOneSubPow R d := by + obtain ⟨d, p, hp⟩ := hS + refine ⟨p, d, ?_⟩ + calc + S = ((PowerSeries.invOneSubPow R d).val * (1 - PowerSeries.X) ^ d) * S := by + rw [← PowerSeries.invOneSubPow_inv_eq_one_sub_pow, Units.val_inv, one_mul] + _ = (PowerSeries.invOneSubPow R d).val * p := by rw [mul_assoc, hp] + _ = _ := mul_comm _ _ + +theorem hilbertRational_of_noetherian_recurrence + {A : Type*} [PartialOrder A] [WellFoundedGT A] + (H : A → PowerSeries R) (P : A → Prop) + (hstep : ∀ I, P I → HR (H I) ∨ + ∃ J K, I < J ∧ I ≤ K ∧ P J ∧ P K ∧ + H I = H J + PowerSeries.X * H K) : + ∀ I, P I → HR (H I) := by + intro I + induction I using WellFoundedGT.induction with + | ind I ih => + intro hI + rcases hstep I hI with h | ⟨J, K, hIJ, hIK, hJ, hK, hrec⟩ + · exact h + have hJrat := ih J hIJ hJ + rcases hIK.eq_or_lt with hKeq | hKlt + · subst K + exact HilbertRational.of_eq_add_X_mul_self hJrat hrec + · rw [hrec] + exact HilbertRational.add hJrat (HilbertRational.X_mul (ih K hKlt hK)) + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +namespace Polynomial + +open _root_.Polynomial + +variable {F : Type*} [Field F] [CharZero F] + +theorem coeff_hilbertPoly_succ_top (p : F[X]) (d : ℕ) : + (hilbertPoly p (d + 1)).coeff d = p.eval 1 / (d.factorial : F) := by + rw [hilbertPoly_succ] + simp only [finsetSum_coeff, coeff_smul, smul_eq_mul, coeff_preHilbertPoly_self, + ← Finset.sum_mul, div_eq_mul_inv] + congr 1 + simp only [eval_eq_sum, one_pow, mul_one, sum_def] + +theorem natDegree_hilbertPoly_succ_le (p : F[X]) (d : ℕ) : + (hilbertPoly p (d + 1)).natDegree ≤ d := by + rw [hilbertPoly_succ] + apply natDegree_sum_le_of_forall_le + intro i _ + exact (natDegree_smul_le _ _).trans (natDegree_preHilbertPoly F d i).le + +theorem natDegree_hilbertPoly_succ_of_eval_one_ne_zero {p : F[X]} {d : ℕ} + (hp : p.eval 1 ≠ 0) : (hilbertPoly p (d + 1)).natDegree = d := by + apply natDegree_eq_of_le_of_coeff_ne_zero (natDegree_hilbertPoly_succ_le p d) + rw [coeff_hilbertPoly_succ_top] + exact div_ne_zero hp (by exact_mod_cast Nat.factorial_ne_zero d) + +theorem leadingCoeff_hilbertPoly_succ_of_eval_one_ne_zero {p : F[X]} {d : ℕ} + (hp : p.eval 1 ≠ 0) : + (hilbertPoly p (d + 1)).leadingCoeff = p.eval 1 / (d.factorial : F) := by + rw [leadingCoeff, natDegree_hilbertPoly_succ_of_eval_one_ne_zero hp, + coeff_hilbertPoly_succ_top] + +theorem factorial_mul_leadingCoeff_hilbertPoly_succ {p : F[X]} {d : ℕ} + (hp : p.eval 1 ≠ 0) : + (d.factorial : F) * (hilbertPoly p (d + 1)).leadingCoeff = p.eval 1 := by + rw [leadingCoeff_hilbertPoly_succ_of_eval_one_ne_zero hp] + have hd : (d.factorial : F) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero d + field_simp + +theorem hilbertPoly_mul_one_sub_X_pow (p : F[X]) (d e : ℕ) : + hilbertPoly (p * (1 - X ^ e)) (d + 1) = + hilbertPoly (p * ∑ j ∈ Finset.range e, X ^ j) d := by + have hfactor : p * (1 - X ^ e) = + (p * ∑ j ∈ Finset.range e, X ^ j) * (1 - X) := by + rw [← mul_neg_geom_sum (X : F[X]) e] + ring + rw [hfactor, hilbertPoly_mul_one_sub_succ] + +theorem factorial_mul_leadingCoeff_hilbertPoly_hypersurface + {p : F[X]} (d : ℕ) {e : ℕ} (he : 0 < e) (hp : p.eval 1 ≠ 0) : + (d.factorial : F) * (hilbertPoly (p * (1 - X ^ e)) (d + 2)).leadingCoeff = + (e : F) * p.eval 1 := by + rw [show d + 2 = (d + 1) + 1 by omega, hilbertPoly_mul_one_sub_X_pow] + have heval : (p * ∑ j ∈ Finset.range e, (X : F[X]) ^ j).eval 1 = + p.eval 1 * (e : F) := by simp + rw [factorial_mul_leadingCoeff_hilbertPoly_succ (by + rw [heval] + exact mul_ne_zero hp (by exact_mod_cast he.ne')), + heval, mul_comm] + +end Polynomial + +end +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/DegreeSliceQuotientEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DegreeSliceQuotientEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..50f2bd7a0ff4ab86e1dea3308077a21cfa749b11 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DegreeSliceQuotientEquiv.lean @@ -0,0 +1,162 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.HomogeneousDeformation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +section + +open Polynomial + + + +open Ideal RingTheory.Sequence IsLocalRing + + + +open Ideal RingTheory.Sequence +open scoped Pointwise + + +open Ideal RingTheory.Sequence +open CategoryTheory Abelian + +universe u + + +open scoped BigOperators + + + +namespace WeightedTorusJets + +universe uReg + +theorem isRegular_generators_of_contains_regular_sequence {R : Type uReg} [CommRing R] + [IsNoetherianRing R] [IsLocalRing R] (I : Ideal R) (hI : I ≠ ⊤) + (gs rs : List R) (hgs : Ideal.ofList gs = I) (hlen : rs.length = gs.length) + (hmem : ∀ r ∈ rs, r ∈ I) (hreg : IsRegular R rs) : IsRegular R gs := by + apply isRegular_of_exists_regular_sequence_in_ofList gs R _ rs hlen _ hreg + · simpa only [hgs, Ideal.smul_eq_mul, Ideal.mul_top] using hI.lt_top + · simpa only [hgs] using hmem + +end WeightedTorusJets + + + + + + + + + + + + + +end + + +open scoped BigOperators + + +open Module + +namespace WeightedTorusJets + +theorem homogeneousMonomialBasis_repr (σ R : Type*) [CommSemiring R] (n : ℕ) + (p : MvPolynomial.homogeneousSubmodule σ R n) (m : {m : σ →₀ ℕ // m.degree = n}) : + (homogeneousMonomialBasis σ R n).repr p m = (p : MvPolynomial σ R).coeff m := by + rfl + +theorem toMatrix_linearCombination_homogeneous + {σ R κ : Type*} [CommSemiring R] [Fintype κ] [DecidableEq κ] + (n : ℕ) [Fintype {m : σ →₀ ℕ // m.degree = n}] + (p : κ → MvPolynomial.homogeneousSubmodule σ R n) + (m : {m : σ →₀ ℕ // m.degree = n}) (j : κ) : + LinearMap.toMatrix Finsupp.basisSingleOne (homogeneousMonomialBasis σ R n) + (Finsupp.linearCombination R p) m j = (p j : MvPolynomial σ R).coeff m := by + simp only [LinearMap.toMatrix_apply, Finsupp.coe_basisSingleOne, + Finsupp.linearCombination_single, one_smul, homogeneousMonomialBasis_repr] + +end WeightedTorusJets + +open MvPolynomial + +noncomputable section + +namespace WeightedTorusJets.Geometry.GradedQuotient + +variable {K σ : Type*} [Field K] + +def degreeSliceQuotientEquiv (I : Ideal (MvPolynomial σ K)) (n : ℕ) : + (homogeneousSubmodule σ K n ⧸ + (I.restrictScalars K).comap (homogeneousSubmodule σ K n).subtype) ≃ₗ[K] + degreePiece I n := + (Submodule.quotEquivOfEq _ _ (ker_degreePresentation I n).symm).trans + ((degreePresentation I n).quotKerEquivOfSurjective (degreePresentation_surjective I n)) + +def cokernelEquivDegreePiece {V : Type*} [AddCommGroup V] [Module K V] + (I : Ideal (MvPolynomial σ K)) (n : ℕ) (m : V →ₗ[K] homogeneousSubmodule σ K n) + (hrange : LinearMap.range m = + (I.restrictScalars K).comap (homogeneousSubmodule σ K n).subtype) : + (homogeneousSubmodule σ K n ⧸ LinearMap.range m) ≃ₗ[K] degreePiece I n := + (Submodule.quotEquivOfEq _ _ hrange).trans (degreeSliceQuotientEquiv I n) + +end WeightedTorusJets.Geometry.GradedQuotient + + + + + + + + +open scoped BigOperators DirectSum +open MvPolynomial + + + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem homogeneousComponent_mul_of_left_homogeneous {σ K : Type*} [CommRing K] + {p q : MvPolynomial σ K} {m n : ℕ} (hp : p.IsHomogeneous m) : + homogeneousComponent (m + n) (p * q) = p * homogeneousComponent n q := by + induction q using MvPolynomial.induction_on' with + | monomial d c => + rw [homogeneousComponent_of_mem (hp.mul (isHomogeneous_monomial c rfl)), + homogeneousComponent_of_mem (isHomogeneous_monomial c rfl)] + simp only [Nat.add_left_cancel_iff] + split_ifs <;> simp + | add q r hq hr => simp only [mul_add, map_add, hq, hr] + +theorem homogeneousComponent_mul_of_right_homogeneous {σ K : Type*} [CommRing K] + {p q : MvPolynomial σ K} {m n : ℕ} (hq : q.IsHomogeneous n) : + homogeneousComponent (m + n) (p * q) = homogeneousComponent m p * q := by + rw [mul_comm p q, add_comm m n, homogeneousComponent_mul_of_left_homogeneous hq, + mul_comm] + +theorem homogeneousComponent_mul_eq_zero_of_lt {σ K : Type*} [CommRing K] + {p q : MvPolynomial σ K} {m n : ℕ} (hq : q.IsHomogeneous n) (hmn : m < n) : + homogeneousComponent m (p * q) = 0 := by + induction p using MvPolynomial.induction_on' with + | monomial d c => + rw [homogeneousComponent_of_mem ((isHomogeneous_monomial c rfl).mul hq)] + simp [show m ≠ d.degree + n by omega] + | add p r hp hr => simp only [add_mul, map_add, hp, hr, add_zero] + +end WeightedTorusJets.Geometry + +open Module + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/DerivationJet.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DerivationJet.lean new file mode 100644 index 0000000000000000000000000000000000000000..397235ef9e3e4f15c51478ff546e1fc9a119beaf --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DerivationJet.lean @@ -0,0 +1,535 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.RectangleThreshold + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open scoped BigOperators +open scoped BigOperators +namespace WeightedTorusJets.Geometry + +theorem mixed_iterate_add {A : Type*} (D : Fin 3 → A → A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (a b : Fin 3 → ℕ) (x : A) : + (D 0)^[a 0 + b 0] ((D 1)^[a 1 + b 1] ((D 2)^[a 2 + b 2] x)) = + (D 0)^[a 0] ((D 1)^[a 1] ((D 2)^[a 2] + ((D 0)^[b 0] ((D 1)^[b 1] ((D 2)^[b 2] x))))) := by + simp only [Function.iterate_add_apply] + rw [(h01.iterate_iterate (b 0) (a 1)).eq, + (h12.iterate_iterate (b 1) (a 2)).eq, + (h02.iterate_iterate (b 0) (a 2)).eq] + +theorem mixed_derivation_pow_add {R A : Type*} [CommSemiring R] [CommSemiring A] + [Algebra R A] (D : Fin 3 → Derivation R A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (a b : Fin 3 → ℕ) (x : A) : + ((D 0).toLinearMap ^ (a 0 + b 0)) + (((D 1).toLinearMap ^ (a 1 + b 1)) (((D 2).toLinearMap ^ (a 2 + b 2)) x)) = + ((D 0).toLinearMap ^ a 0) (((D 1).toLinearMap ^ a 1) (((D 2).toLinearMap ^ a 2) + (((D 0).toLinearMap ^ b 0) (((D 1).toLinearMap ^ b 1) + (((D 2).toLinearMap ^ b 2) x))))) := by + simpa only [Module.End.pow_apply, Derivation.coeFn_coe] using mixed_iterate_add + (fun i => (D i : A → A)) h01 h02 h12 a b x + +theorem derivation_pow_mixed_derivation_pow {R A : Type*} + [CommSemiring R] [CommSemiring A] [Algebra R A] + (D : Fin 3 → Derivation R A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (j : Fin 3) (n : ℕ) (b : Fin 3 → ℕ) (x : A) : + ((D j).toLinearMap ^ n) + (((D 0).toLinearMap ^ b 0) (((D 1).toLinearMap ^ b 1) + (((D 2).toLinearMap ^ b 2) x))) = + ((D 0).toLinearMap ^ ((b + (Pi.single j n : Fin 3 → ℕ)) 0)) + (((D 1).toLinearMap ^ ((b + (Pi.single j n : Fin 3 → ℕ)) 1)) + (((D 2).toLinearMap ^ ((b + (Pi.single j n : Fin 3 → ℕ)) 2)) x)) := by + have h := mixed_derivation_pow_add D h01 h02 h12 (Pi.single j n) b x + fin_cases j <;> simpa [Pi.single_apply, add_comm] using h.symm + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +lemma extend_selectedIndex_eq_zero (I : Finset (Fin 3)) (α : I → ℕ) {j : Fin 3} + (hj : j ∉ I) : Function.extend (Subtype.val : I → Fin 3) α 0 j = 0 := by + apply Function.extend_apply' + rintro ⟨i, rfl⟩ + exact hj i.property + +lemma extend_selectedIndex_le (I : Finset (Fin 3)) (α : I → ℕ) (t : Fin 3 → ℕ) + (hα : ∀ i, α i ≤ t i) : + ∀ j, Function.extend (Subtype.val : I → Fin 3) α 0 j ≤ t j := by + intro j + by_cases hj : j ∈ I + · rw [Subtype.val_injective.extend_apply α 0 ⟨j, hj⟩] + exact hα ⟨j, hj⟩ + · rw [extend_selectedIndex_eq_zero I α hj] + exact Nat.zero_le _ + +lemma extend_selectedIndex_single (I : Finset (Fin 3)) (i : I) (n : ℕ) : + Function.extend (Subtype.val : I → Fin 3) (Pi.single i n) 0 = Pi.single (i : Fin 3) n := by + funext j + by_cases hj : j ∈ I + · rw [Subtype.val_injective.extend_apply (Pi.single i n) 0 ⟨j, hj⟩] + simp only [Pi.single_apply, Subtype.ext_iff] + · rw [extend_selectedIndex_eq_zero I _ hj] + have hne : j ≠ (i : Fin 3) := by + intro he + exact hj (he.symm ▸ i.property) + rw [Pi.single_eq_of_ne hne] + +theorem add_jet_indices_le_next_stage {σ : Type*} (a α t : σ → ℕ) (b : ℕ) + (ha : ∀ j, a j ≤ b * t j) (hα : ∀ j, α j ≤ t j) : + ∀ j, (a + α) j ≤ (b + 1) * t j := by + intro j + simpa [Pi.add_apply, Nat.add_mul] using Nat.add_le_add (ha j) (hα j) + +theorem selectedIndex_add_stage_bound (I : Finset (Fin 3)) (α : I → ℕ) + (a t : Fin 3 → ℕ) (b : ℕ) (ha : ∀ j, a j ≤ b * t j) (hα : ∀ i, α i ≤ t i) : + ∀ j, (a + Function.extend (Subtype.val : I → Fin 3) α 0) j ≤ (b + 1) * t j := + add_jet_indices_le_next_stage a _ t b ha (extend_selectedIndex_le I α t hα) + +theorem selectedIndex_add_stage_bound_lt (I : Finset (Fin 3)) (α : I → ℕ) + (a t : Fin 3 → ℕ) (b : ℕ) (ha : ∀ j, a j ≤ b * t j) + (hα : ∀ i, α i < t i + 1) : + ∀ j, (a + Function.extend (Subtype.val : I → Fin 3) α 0) j ≤ (b + 1) * t j := + selectedIndex_add_stage_bound I α a t b ha fun i ↦ Nat.lt_succ_iff.mp (hα i) + + + +noncomputable section + +variable {A B : Type*} [CommRing A] [Algebra ℚ A] [CommRing B] [Algebra ℚ B] + +def derivationJet (D : Fin 3 → Derivation ℚ A A) (β : Fin 3 → ℕ) (a : A) : A := + ((D 0).toLinearMap ^ β 0) (((D 1).toLinearMap ^ β 1) (((D 2).toLinearMap ^ β 2) a)) + +def derivativeStageIdeal (D : Fin 3 → Derivation ℚ A A) (t : Fin 3 → ℕ) + (b : ℕ) (F : A) : Ideal A := + Ideal.span ((fun β => derivationJet D β F) '' {β | ∀ j, β j ≤ b * t j}) + +@[simp] theorem derivationJet_zero (D : Fin 3 → Derivation ℚ A A) (a : A) : + derivationJet D 0 a = a := by + simp [derivationJet] + +omit [Algebra ℚ B] in +theorem derivativeStageIdeal_le_ker_iff (D : Fin 3 → Derivation ℚ A A) + (t : Fin 3 → ℕ) (b : ℕ) (F : A) (f : A →+* B) : + derivativeStageIdeal D t b F ≤ RingHom.ker f ↔ + ∀ β, (∀ j, β j ≤ b * t j) → f (derivationJet D β F) = 0 := by + rw [derivativeStageIdeal, Ideal.span_le, Set.image_subset_iff] + rfl + +theorem derivationJet_map (D : Fin 3 → Derivation ℚ A A) + (E : Fin 3 → Derivation ℚ B B) (f : A →+* B) + (h : ∀ i a, f (D i a) = E i (f a)) (β : Fin 3 → ℕ) (a : A) : + f (derivationJet D β a) = derivationJet E β (f a) := by + have hp (i : Fin 3) (n : ℕ) (x : A) : + f (((D i).toLinearMap ^ n) x) = ((E i).toLinearMap ^ n) (f x) := by + induction n with + | zero => rfl + | succ n ih => + simp only [pow_succ', Module.End.mul_apply, Derivation.coeFn_coe, h, ih] + simp only [derivationJet, hp] + +theorem derivativeStageIdeal_map (D : Fin 3 → Derivation ℚ A A) + (E : Fin 3 → Derivation ℚ B B) (f : A →+* B) + (h : ∀ i a, f (D i a) = E i (f a)) (t : Fin 3 → ℕ) (b : ℕ) (F : A) : + Ideal.map f (derivativeStageIdeal D t b F) = derivativeStageIdeal E t b (f F) := by + unfold derivativeStageIdeal + rw [Ideal.map_span, Set.image_image] + simp only [derivationJet_map D E f h] + +theorem derivationJet_shift (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (j : Fin 3) (n : ℕ) (β : Fin 3 → ℕ) (a : A) : + ((D j).toLinearMap ^ n) (derivationJet D β a) = + derivationJet D (β + Pi.single j n) a := + derivation_pow_mixed_derivation_pow D h01 h02 h12 j n β a + +theorem single_index_le {j : Fin 3} {n : ℕ} (t : Fin 3 → ℕ) (hn : n ≤ t j) : + ∀ l, (Pi.single j n : Fin 3 → ℕ) l ≤ t l := by + intro l + by_cases h : l = j + · simpa [h] using hn + · simp [Pi.single_eq_of_ne h] + +theorem pair_index_le {i j : Fin 3} (hij : i ≠ j) {m n : ℕ} (t : Fin 3 → ℕ) + (hm : m ≤ t i) (hn : n ≤ t j) : + ∀ l, ((Pi.single i m : Fin 3 → ℕ) + (Pi.single j n : Fin 3 → ℕ)) l ≤ t l := by + intro l + by_cases hi : l = i + · subst l + simpa [Pi.single_apply, hij] using hm + · by_cases hj : l = j + · subst l + simpa [Pi.single_apply, Ne.symm hij] using hn + · simp [hi, hj] + +theorem triple_index_le {i j k : Fin 3} (hij : i ≠ j) (hik : i ≠ k) (hjk : j ≠ k) + {m n p : ℕ} (t : Fin 3 → ℕ) (hm : m ≤ t i) (hn : n ≤ t j) (hp : p ≤ t k) : + ∀ l, (((Pi.single i m : Fin 3 → ℕ) + (Pi.single j n : Fin 3 → ℕ)) + + (Pi.single k p : Fin 3 → ℕ)) l ≤ t l := by + intro l + by_cases hi : l = i + · subst l + simpa [Pi.single_apply, hij, hik] using hm + · by_cases hj : l = j + · subst l + simpa [Pi.single_apply, Ne.symm hij, hjk] using hn + · by_cases hk : l = k + · subst l + simpa [Pi.single_apply, Ne.symm hik, Ne.symm hjk] using hp + · simp [hi, hj, hk] + +theorem derivativeStageIdeal_le_ker_taylor_one + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i : I) (t : Fin 3 → ℕ) (b : ℕ) (F : A) (f : A →+* B) + (hvanish : ∀ β, (∀ j, β j ≤ (b + 1) * t j) → f (derivationJet D β F) = 0) : + derivativeStageIdeal D t b F ≤ RingHom.ker + (rectangularTaylorThree I (fun j => t j + 1) (D i) 0 0 i i i f) := by + apply Ideal.span_le.mpr + rintro _ ⟨β, hβ, rfl⟩ + change rectangularTaylorThree _ _ _ _ _ _ _ _ _ _ = 0 + rw [rectangularTaylorThree_one_apply] + apply Finset.sum_eq_zero + intro n hn + have hbound := add_jet_indices_le_next_stage β (Pi.single (i : Fin 3) n) t b hβ + (single_index_le t (Nat.lt_succ_iff.mp (Finset.mem_range.mp hn))) + rw [derivationJet_shift D h01 h02 h12, hvanish _ hbound] + simp + +theorem derivativeStageIdeal_le_ker_taylor_two + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i j : I) (hij : i ≠ j) + (t : Fin 3 → ℕ) (b : ℕ) (F : A) (f : A →+* B) + (hvanish : ∀ β, (∀ l, β l ≤ (b + 1) * t l) → f (derivationJet D β F) = 0) : + derivativeStageIdeal D t b F ≤ RingHom.ker + (rectangularTaylorThree I (fun l => t l + 1) (D i) (D j) 0 i j j f) := by + apply Ideal.span_le.mpr + rintro _ ⟨β, hβ, rfl⟩ + change rectangularTaylorThree _ _ _ _ _ _ _ _ _ _ = 0 + rw [rectangularTaylorThree_two_apply] + apply Finset.sum_eq_zero + intro n hn + apply Finset.sum_eq_zero + intro m hm + have hji : (j : Fin 3) ≠ (i : Fin 3) := fun he => hij (Subtype.ext he.symm) + have hbound := add_jet_indices_le_next_stage β + ((Pi.single (j : Fin 3) n : Fin 3 → ℕ) + (Pi.single (i : Fin 3) m : Fin 3 → ℕ)) t b hβ + (pair_index_le hji t (Nat.lt_succ_iff.mp (Finset.mem_range.mp hn)) + (Nat.lt_succ_iff.mp (Finset.mem_range.mp hm))) + rw [derivationJet_shift D h01 h02 h12, derivationJet_shift D h01 h02 h12] + rw [add_assoc, hvanish _ hbound] + simp + +theorem derivativeStageIdeal_le_ker_taylor_three + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i j k : I) (hij : i ≠ j) (hik : i ≠ k) (hjk : j ≠ k) + (t : Fin 3 → ℕ) (b : ℕ) (F : A) (f : A →+* B) + (hvanish : ∀ β, (∀ l, β l ≤ (b + 1) * t l) → f (derivationJet D β F) = 0) : + derivativeStageIdeal D t b F ≤ RingHom.ker + (rectangularTaylorThree I (fun l => t l + 1) (D i) (D j) (D k) i j k f) := by + apply Ideal.span_le.mpr + rintro _ ⟨β, hβ, rfl⟩ + change rectangularTaylorThree _ _ _ _ _ _ _ _ _ _ = 0 + rw [rectangularTaylorThree_apply] + apply Finset.sum_eq_zero + intro p hp + apply Finset.sum_eq_zero + intro n hn + apply Finset.sum_eq_zero + intro m hm + have hkj : (k : Fin 3) ≠ (j : Fin 3) := fun he => hjk (Subtype.ext he.symm) + have hki : (k : Fin 3) ≠ (i : Fin 3) := fun he => hik (Subtype.ext he.symm) + have hji : (j : Fin 3) ≠ (i : Fin 3) := fun he => hij (Subtype.ext he.symm) + have hbound := add_jet_indices_le_next_stage β + (((Pi.single (k : Fin 3) p : Fin 3 → ℕ) + (Pi.single (j : Fin 3) n : Fin 3 → ℕ)) + + (Pi.single (i : Fin 3) m : Fin 3 → ℕ)) t b hβ + (triple_index_le hkj hki hji t (Nat.lt_succ_iff.mp (Finset.mem_range.mp hp)) + (Nat.lt_succ_iff.mp (Finset.mem_range.mp hn)) + (Nat.lt_succ_iff.mp (Finset.mem_range.mp hm))) + rw [derivationJet_shift D h01 h02 h12, derivationJet_shift D h01 h02 h12, + derivationJet_shift D h01 h02 h12] + simp only [add_assoc] at hbound + rw [add_assoc, add_assoc, hvanish _ hbound] + simp + +end + +end WeightedTorusJets.Geometry + +noncomputable section + +namespace WeightedTorusJets.Geometry + +theorem local_module_length_eq_finrank {K A M : Type*} [Field K] [CommRing A] + [IsLocalRing A] [Algebra K A] [AddCommGroup M] [Module K M] [Module A M] + [IsScalarTower K A M] [Module.Finite K M] + (hκ : Function.Surjective (algebraMap K (IsLocalRing.ResidueField A))) : + Module.length A M = Module.finrank K M := by + have hres : Module.length (IsLocalRing.ResidueField K) (IsLocalRing.ResidueField A) = 1 := by + rw [← Module.length_eq_of_surjective (M := IsLocalRing.ResidueField A) + (IsLocalRing.residue_surjective (R := K))] + rw [Module.length_eq_of_surjective (M := IsLocalRing.ResidueField A) hκ] + exact Module.length_eq_one _ _ + have h := IsLocalRing.length_restrictScalars K A M + rw [hres, mul_one, Module.length_eq_finrank K M] at h + exact h.symm + +theorem local_length_eq_finrank {K A : Type*} [Field K] [CommRing A] [IsLocalRing A] + [Algebra K A] [Module.Finite K A] + (hκ : Function.Surjective (algebraMap K (IsLocalRing.ResidueField A))) : + Module.length A A = Module.finrank K A := + local_module_length_eq_finrank hκ + +theorem isNilpotent_of_mem_nilpotent_ideal {A : Type*} [CommRing A] + (I : Ideal A) (hI : IsNilpotent I) {a : A} (ha : a ∈ I) : IsNilpotent a := by + obtain ⟨n, hn⟩ := hI + refine ⟨n, ?_⟩ + have h := Ideal.pow_mem_pow ha n + rw [hn, Ideal.zero_eq_bot, Ideal.mem_bot] at h + exact h + +theorem isLocalRing_of_nilpotent_augmentation {K A : Type*} [Field K] [CommRing A] + [Algebra K A] (ε : A →ₐ[K] K) (hε : IsNilpotent (RingHom.ker ε)) : + IsLocalRing A := by + have : Nontrivial A := ε.toRingHom.domain_nontrivial + apply IsLocalRing.of_isUnit_or_isUnit_one_sub_self + intro a + by_cases ha : ε a = 0 + · exact Or.inr (isNilpotent_of_mem_nilpotent_ideal _ hε ha).isUnit_one_sub + · apply Or.inl + have hn : IsNilpotent (a - algebraMap K A (ε a)) := + isNilpotent_of_mem_nilpotent_ideal _ hε (by simp) + simpa using hn.isUnit_add_left_of_commute + ((isUnit_iff_ne_zero.mpr ha).map (algebraMap K A)) (Commute.all _ _) + +theorem residue_surjective_of_nilpotent_augmentation {K A : Type*} [Field K] + [CommRing A] [Algebra K A] [IsLocalRing A] (ε : A →ₐ[K] K) + (hε : IsNilpotent (RingHom.ker ε)) : + Function.Surjective (algebraMap K (IsLocalRing.ResidueField A)) := by + intro b + obtain ⟨a, rfl⟩ := IsLocalRing.residue_surjective b + refine ⟨ε a, ?_⟩ + have hn : IsNilpotent (a - algebraMap K A (ε a)) := + isNilpotent_of_mem_nilpotent_ideal _ hε (by simp) + have hm : a - algebraMap K A (ε a) ∈ IsLocalRing.maximalIdeal A := hn.not_isUnit + have he := (IsLocalRing.residue_eq_zero_iff _).mpr hm + rw [map_sub, sub_eq_zero] at he + exact he.symm + +theorem length_eq_finrank_of_nilpotent_augmentation {K A : Type*} [Field K] + [CommRing A] [Algebra K A] [Module.Finite K A] (ε : A →ₐ[K] K) + (hε : IsNilpotent (RingHom.ker ε)) : + Module.length A A = Module.finrank K A := by + let := isLocalRing_of_nilpotent_augmentation ε hε + exact local_length_eq_finrank (residue_surjective_of_nilpotent_augmentation ε hε) + +open MvPolynomial + +instance finite_rectangularQuotient {σ K : Type*} [Fintype σ] [CommRing K] (k : σ → ℕ) : + Module.Finite K (MvPolynomial σ K ⧸ rectangularIdeal k) := + Module.Finite.of_basis (rectangularQuotientBasis k) + +open MvPolynomial + +theorem ker_constantCoeff_eq_idealOfVars {σ K : Type*} [CommRing K] : + RingHom.ker (constantCoeff : MvPolynomial σ K →+* K) = idealOfVars σ K := by + classical + ext p + rw [RingHom.mem_ker, idealOfVars, ← Set.image_univ, + mem_ideal_span_X_image] + constructor + · intro hp d hd + have hd0 : d ≠ 0 := by + intro h + subst d + exact (mem_support_iff.mp hd) hp + obtain ⟨i, hi⟩ := Finsupp.ne_iff.mp hd0 + exact ⟨i, Set.mem_univ i, hi⟩ + · intro hp + by_contra h + obtain ⟨i, _, hi⟩ := hp 0 (mem_support_iff.mpr h) + exact hi rfl + +theorem isNilpotent_map_idealOfVars_of_pow_mem + {σ K : Type*} [Finite σ] [CommRing K] + (J : Ideal (MvPolynomial σ K)) (k : σ → ℕ) + (hk : ∀ i, (X i : MvPolynomial σ K) ^ k i ∈ J) : + IsNilpotent ((idealOfVars σ K).map (Ideal.Quotient.mk J)) := by + apply ((idealOfVars_fg σ K).map (Ideal.Quotient.mk J)).isNilpotent_iff_le_nilradical.mpr + rw [Ideal.map_le_iff_le_comap, idealOfVars, Ideal.span_le, Set.range_subset_iff] + intro i + change IsNilpotent (Ideal.Quotient.mk J (X i)) + refine ⟨k i, ?_⟩ + rw [← map_pow] + exact Ideal.Quotient.eq_zero_iff_mem.mpr (hk i) + +def quotientAugmentation {σ K : Type*} [CommRing K] + (J : Ideal (MvPolynomial σ K)) + (hJ : J ≤ RingHom.ker (constantCoeff : MvPolynomial σ K →+* K)) : + (MvPolynomial σ K ⧸ J) →ₐ[K] K := + Ideal.Quotient.liftₐ J (aeval (0 : σ → K)) fun p hp => by + simpa using hJ hp + +@[simp] theorem quotientAugmentation_mk {σ K : Type*} [CommRing K] + (J : Ideal (MvPolynomial σ K)) + (hJ : J ≤ RingHom.ker (constantCoeff : MvPolynomial σ K →+* K)) + (p : MvPolynomial σ K) : + quotientAugmentation J hJ (Ideal.Quotient.mk J p) = constantCoeff p := by + simp [quotientAugmentation] + +theorem ker_quotientAugmentation {σ K : Type*} [CommRing K] + (J : Ideal (MvPolynomial σ K)) + (hJ : J ≤ RingHom.ker (constantCoeff : MvPolynomial σ K →+* K)) : + RingHom.ker (quotientAugmentation J hJ).toRingHom = + (idealOfVars σ K).map (Ideal.Quotient.mk J) := by + rw [← ker_constantCoeff_eq_idealOfVars] + ext x + obtain ⟨p, rfl⟩ := Ideal.Quotient.mk_surjective x + rw [RingHom.mem_ker] + change quotientAugmentation J hJ (Ideal.Quotient.mk J p) = 0 ↔ _ + rw [quotientAugmentation_mk, Ideal.mem_map_iff_of_surjective _ Ideal.Quotient.mk_surjective] + constructor + · intro hp + exact ⟨p, hp, rfl⟩ + · rintro ⟨q, hq, hpq⟩ + change constantCoeff q = 0 at hq + have hmem := (Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mp hpq + have hh := hJ hmem + change constantCoeff (q - p) = 0 at hh + simpa only [map_sub, hq, zero_sub, neg_eq_zero] using hh + +theorem isNilpotent_ker_quotientAugmentation + {σ K : Type*} [Finite σ] [CommRing K] + (J : Ideal (MvPolynomial σ K)) + (hJ : J ≤ RingHom.ker (constantCoeff : MvPolynomial σ K →+* K)) + (k : σ → ℕ) (hk : ∀ i, (X i : MvPolynomial σ K) ^ k i ∈ J) : + IsNilpotent (RingHom.ker (quotientAugmentation J hJ).toRingHom) := by + rw [ker_quotientAugmentation] + exact isNilpotent_map_idealOfVars_of_pow_mem J k hk + +theorem rectangularIdeal_le_ker_constantCoeff + {σ K : Type*} [CommRing K] (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) : + Ideal.span (Set.range fun i => (X i : MvPolynomial σ K) ^ k i) ≤ + RingHom.ker (constantCoeff : MvPolynomial σ K →+* K) := by + rw [Ideal.span_le, Set.range_subset_iff] + intro i + change constantCoeff ((X i : MvPolynomial σ K) ^ k i) = 0 + rw [map_pow, constantCoeff_X, zero_pow (hk i)] + +def rectangularAugmentation {σ K : Type*} [CommRing K] + (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) : + (MvPolynomial σ K ⧸ + Ideal.span (Set.range fun i => (X i : MvPolynomial σ K) ^ k i)) →ₐ[K] K := + quotientAugmentation _ (rectangularIdeal_le_ker_constantCoeff k hk) + +theorem isNilpotent_ker_rectangularAugmentation + {σ K : Type*} [Finite σ] [CommRing K] (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) : + IsNilpotent (RingHom.ker (rectangularAugmentation (K := K) k hk).toRingHom) := by + apply isNilpotent_ker_quotientAugmentation _ _ k + intro i + exact Ideal.subset_span ⟨i, rfl⟩ + + + +variable {K R : Type*} [CommRing K] [CommRing R] [Algebra K R] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem surjective_of_nilpotent_ideal_lifts {A B : Type*} [CommRing A] [CommRing B] + (f : A →+* B) (I : Ideal B) (hI : IsNilpotent I) + (h₀ : ∀ b : B, ∃ a : A, b - f a ∈ I) + (h₁ : ∀ b ∈ I, ∃ a : A, f a ∈ I ∧ b - f a ∈ I ^ 2) : + Function.Surjective f := by + have liftPower : ∀ n : ℕ, ∀ b ∈ I ^ n, + ∃ a : A, f a ∈ I ^ n ∧ b - f a ∈ I ^ (n + 1) := by + intro n + induction n with + | zero => + intro b _ + obtain ⟨a, ha⟩ := h₀ b + exact ⟨a, by simp, by simpa using ha⟩ + | succ n hn => + intro b hb + rw [pow_succ] at hb + refine Submodule.mul_induction_on hb ?_ ?_ + · intro x hx y hy + obtain ⟨a, ha, hxa⟩ := hn x hx + obtain ⟨c, hc, hyc⟩ := h₁ y hy + refine ⟨a * c, ?_, ?_⟩ + · rw [map_mul, pow_succ] + exact Ideal.mul_mem_mul ha hc + · have hleft : (x - f a) * y ∈ I ^ (n + 1 + 1) := by + rw [pow_succ] + exact Ideal.mul_mem_mul hxa hy + have hright : f a * (y - f c) ∈ I ^ (n + 1 + 1) := by + rw [show n + 1 + 1 = n + 2 by omega, pow_add] + exact Ideal.mul_mem_mul ha hyc + convert (I ^ (n + 1 + 1)).add_mem hleft hright using 1 + simp only [map_mul] + ring + · intro x y hx hy + obtain ⟨a, ha, hxa⟩ := hx + obtain ⟨c, hc, hyc⟩ := hy + refine ⟨a + c, ?_, ?_⟩ + · simpa only [map_add] using (I ^ (n + 1)).add_mem ha hc + · convert (I ^ (n + 1 + 1)).add_mem hxa hyc using 1 + simp only [map_add] + ring + have liftAll : ∀ n : ℕ, ∀ b : B, ∃ a : A, b - f a ∈ I ^ n := by + intro n + induction n with + | zero => exact fun b => ⟨0, by simp⟩ + | succ n hn => + intro b + obtain ⟨a, ha⟩ := hn b + obtain ⟨c, _, hc⟩ := liftPower n (b - f a) ha + refine ⟨a + c, ?_⟩ + convert hc using 1 + simp only [map_add] + ring + obtain ⟨n, hn⟩ := hI + intro b + obtain ⟨a, ha⟩ := liftAll n b + rw [hn, Ideal.zero_eq_bot, Ideal.mem_bot] at ha + exact ⟨a, (sub_eq_zero.mp ha).symm⟩ + +end WeightedTorusJets.Geometry + +noncomputable section + +end +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/DirichletRealZeroBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DirichletRealZeroBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6f94796d9d24423db6dfd7e08e43f446fe36c84 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DirichletRealZeroBound.lean @@ -0,0 +1,45 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.RealZeroUniformMasterBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open Filter Topology + +theorem dirichlet_real_zero_bound : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → + (∀ a : ZMod q, (χ a).im = 0) → ∀ β : ℝ, + (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → + c ≤ (1 - β) * Real.log (q : ℝ) := by + by_contra hnot + obtain ⟨q, hq, χ, β, hadm, hqtop, hgap⟩ := exists_contrary_sequence hnot + obtain ⟨C, _hC, hsource⟩ := source_real_zero_uniform_master_bound + obtain ⟨H, hH, γ, hγ, hno⟩ := exists_fixed_parameters_not_eventually_uniform_bound C + obtain ⟨CH, hCH⟩ := hsource H hH + have hqreal : Tendsto (fun n => (q n : ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp hqtop + apply hno (fun n => (q n : ℝ)) (fun n => (1 - β n) * Real.log (q n : ℝ)) CH hqreal hgap + have hNtop : Tendsto (fun n => ⌈(q n : ℝ) ^ γ⌉₊) atTop atTop := + (tendsto_natCeil_rpow_atTop hγ).comp hqreal + filter_upwards [hNtop.eventually_ge_atTop H, hNtop.eventually_ge_atTop 18818, + hqtop.eventually_ne_atTop 8] with n hnH hnN hn8 + let := hq n + exact hCH (q n) (hadm n).1 hn8 (χ n) (hadm n).2.2.2.1 + (hadm n).2.1 (hadm n).2.2.1 (β n) (hadm n).2.2.2.2.1 + (hadm n).2.2.2.2.2.1 (hadm n).2.2.2.2.2.2 + ⌈(q n : ℝ) ^ γ⌉₊ hnH hnN + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/DirichletRealZeroBoundProof.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DirichletRealZeroBoundProof.lean new file mode 100644 index 0000000000000000000000000000000000000000..e42767d0f58de8e6c000ca2fc324bdabd252cd8c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DirichletRealZeroBoundProof.lean @@ -0,0 +1,31 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.DirichletRealZeroBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +end WeightedTorusJets + +end + +section +theorem WeightedTorusJets.dirichletRealZeroBound_proof : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + ∀ β : ℝ, + (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → + c ≤ (1 - β) * Real.log (q : ℝ) := by + exact WeightedTorusJets.dirichlet_real_zero_bound + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/Divisibility.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/Divisibility.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d40b5a989a4c1214747b637c9e0844909fb4b00 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/Divisibility.lean @@ -0,0 +1,77 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.RestrictWeightSortedEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open scoped BigOperators +open WeightedTorusJets NumberField +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem WeightedTorusJets.source_divisibility (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ N H : ℕ, 0 < H → H ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * + ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + ∀ e : ℕ ≃ (Fin 3 → ℕ), Monotone (fun i => w (e i)) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ e) s.card : Set ℕ) ∧ + (∀ i, α i = e (g i)) ∧ + Set.range α = ((greedyPivots B (R ∘ e) s.card).image e : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ N ^ 4 - 1) ∧ + (∀ t : ℕ, s.card ≤ t → + Set.range g = (greedyPivots B (R ∘ e) t : Set ℕ)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + Δ ≠ 0 ∧ + ∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p) := by + classical + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hsource⟩ := + source_character_global_greedy_determinant_divisibility q χ hreal hprim hne hfield + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro N H hH _hHN + exact hsource N H hH + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/DominantFunctionFieldHom.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DominantFunctionFieldHom.lean new file mode 100644 index 0000000000000000000000000000000000000000..a81de7a3acf3e13b246765d67a0589180966d6a6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/DominantFunctionFieldHom.lean @@ -0,0 +1,521 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section OriginalSourceGeometryOverlay + +noncomputable section + +local instance WeightedTorusJets.Geometry.polynomialGradedAlgebra + (R σ : Type*) [CommSemiring R] : + GradedAlgebra (MvPolynomial.homogeneousSubmodule σ R) := MvPolynomial.gradedAlgebra + +open Module + +open CategoryTheory AlgebraicGeometry + +namespace WeightedTorusJets + +universe u + +local instance scheme_top_nonempty (Z : Scheme) [Nonempty Z] : Nonempty (⊤ : Z.Opens) := + ⟨⟨Classical.choice inferInstance, Set.mem_univ _⟩⟩ + +theorem existsUnique_globalSection_scalar (K : Type u) [Field K] [IsAlgClosed K] + {X : Scheme.{u}} [IsIntegral X] (f : X ⟶ Spec (CommRingCat.of K)) + [UniversallyClosed f] (s : Γ(X, ⊤)) : + ∃! c : K, ((Scheme.ΓSpecIso (CommRingCat.of K)).inv ≫ f.appTop).hom c = s := by + have hIntegral : ((Scheme.ΓSpecIso (CommRingCat.of K)).inv ≫ f.appTop).hom.IsIntegral := by + apply RingHom.isIntegral_respectsIso.2 + (e := (Scheme.ΓSpecIso (CommRingCat.of K)).symm.commRingCatIsoToRingEquiv) + exact isIntegral_appTop_of_universallyClosed f + exact (IsAlgClosed.ringHom_bijective_of_isIntegral _ hIntegral).existsUnique s + +variable {X Y : Scheme.{u}} [IsIntegral X] [IsIntegral Y] + +theorem genericPoint_eq_of_isDominant (f : X ⟶ Y) [IsDominant f] : + f (genericPoint X) = genericPoint Y := by + have h : IsGenericPoint (f (genericPoint X)) Set.univ := by + simpa only [Set.image_univ, f.denseRange.closure_range] using + (genericPoint_spec X).image f.continuous + exact h.eq (genericPoint_spec Y) + +noncomputable def dominantFunctionFieldHom (f : X ⟶ Y) [IsDominant f] : + Y.functionField ⟶ X.functionField := + (Y.presheaf.stalkCongr (.of_eq (genericPoint_eq_of_isDominant f).symm)).hom ≫ + f.stalkMap (genericPoint X) + +theorem germToFunctionField_dominantFunctionFieldHom (f : X ⟶ Y) [IsDominant f] : + Y.germToFunctionField ⊤ ≫ dominantFunctionFieldHom f = + f.appTop ≫ X.germToFunctionField ⊤ := by + calc + _ = Y.presheaf.germ ⊤ (f (genericPoint X)) (Set.mem_univ _) ≫ + f.stalkMap (genericPoint X) := by + rw [dominantFunctionFieldHom, ← Category.assoc] + congr 1 + exact Y.presheaf.germ_stalkSpecializes _ + (specializes_of_eq (genericPoint_eq_of_isDominant f)) + _ = _ := f.germ_stalkMap ⊤ (genericPoint X) (Set.mem_univ _) + +theorem isDominant_fromSpecStalk_genericPoint (Z : Scheme.{u}) [IsIntegral Z] : + IsDominant (Z.fromSpecStalk (genericPoint Z)) := by + constructor + rw [denseRange_iff_closure_range] + apply Set.eq_univ_of_univ_subset + rw [← genericPoint_closure Z] + apply closure_mono + exact Set.singleton_subset_iff.mpr + ⟨IsLocalRing.closedPoint Z.functionField, Z.fromSpecStalk_closedPoint⟩ + +end WeightedTorusJets + +open CategoryTheory AlgebraicGeometry + +namespace WeightedTorusJets + +universe u + +theorem finite_integralClosure_of_normal_subring + (R K A L : Type*) [CommRing R] [IsDomain R] [IsNoetherianRing R] + [IsIntegrallyClosed R] [Field K] [CommRing A] [Field L] + [Algebra R K] [IsFractionRing R K] [Algebra R A] [Algebra A L] + [Algebra R L] [IsScalarTower R A L] [Algebra K L] [IsScalarTower R K L] + [Algebra.IsIntegral R A] [FiniteDimensional K L] [Algebra.IsSeparable K L] : + Module.Finite A (integralClosure A L) := by + have : IsIntegralClosure (integralClosure A L) R L := { + algebraMap_injective := Subtype.val_injective + isIntegral_iff := by + intro x + constructor + · intro hx + exact ⟨⟨x, hx.tower_top⟩, rfl⟩ + · rintro ⟨x, rfl⟩ + exact isIntegral_trans (R := R) (A := A) _ x.property } + have : Module.Finite R (integralClosure A L) := + IsIntegralClosure.finite R K L (integralClosure A L) + exact Module.Finite.of_restrictScalars_finite R A (integralClosure A L) + +theorem finite_integralClosure_of_finiteType_charZero (k A : Type*) + [Field k] [CharZero k] [CommRing A] [IsDomain A] [Algebra k A] + [Algebra.FiniteType k A] : Module.Finite A (integralClosure A (FractionRing A)) := by + obtain ⟨n, g, hg, hfin⟩ := exists_finite_inj_algHom_of_fg k A + let P := MvPolynomial (Fin n) k + let : Algebra P A := g.toRingHom.toAlgebra + have : Module.Finite P A := hfin + have : FaithfulSMul P A := (faithfulSMul_iff_algebraMap_injective P A).mpr hg + let := FractionRing.liftAlgebra P (FractionRing A) + have : Module.Finite (FractionRing P) (FractionRing A) := by + apply Module.rank_lt_aleph0_iff.mp + rw [Algebra.IsAlgebraic.rank_fractionRing] + exact Module.rank_lt_aleph0 P A + exact finite_integralClosure_of_normal_subring P (FractionRing P) A (FractionRing A) + +theorem isFractionRing_genericPoint_preimage_sections + (Y : Scheme.{u}) [IsIntegral Y] (U : Y.Opens) (hU : IsAffineOpen U) [Nonempty U] : + let n := Y.fromSpecStalk (genericPoint Y) + let := (n.app U).hom.toAlgebra + IsFractionRing Γ(Y, U) Γ(Spec Y.functionField, n ⁻¹ᵁ U) := by + let n := Y.fromSpecStalk (genericPoint Y) + let := (n.app U).hom.toAlgebra + have hm : genericPoint Y ∈ U := + ((genericPoint_spec Y).mem_open_set_iff U.isOpen).mpr + (by simpa using (inferInstance : Nonempty U)) + have hpre : n ⁻¹ᵁ U = ⊤ := by + apply top_unique + intro x _ + change n x ∈ U + have hx : x = IsLocalRing.closedPoint Y.functionField := + Subsingleton.elim (α := PrimeSpectrum Y.functionField) _ _ + rw [hx, Scheme.fromSpecStalk_closedPoint] + exact hm + let e : Y.functionField ≅ Γ(Spec Y.functionField, n ⁻¹ᵁ U) := + (Scheme.ΓSpecIso Y.functionField).symm ≪≫ + (Spec Y.functionField).presheaf.mapIso (eqToIso hpre).op + let eA : Y.functionField ≃ₐ[Γ(Y, U)] Γ(Spec Y.functionField, n ⁻¹ᵁ U) := + { e.commRingCatIsoToRingEquiv with + commutes' := fun a ↦ by + change e.hom (Y.germToFunctionField U a) = n.app U a + rw [Scheme.fromSpecStalk_app hm] + rfl } + have := functionField_isFractionRing_of_isAffineOpen Y U hU + exact IsFractionRing.of_algEquiv eA + +theorem isFinite_genericNormalization (k : Type u) [Field k] [CharZero k] + (Y : Scheme.{u}) [IsIntegral Y] + (g : Y ⟶ Spec (CommRingCat.of k)) [LocallyOfFiniteType g] : + IsFinite (Y.fromSpecStalk (genericPoint Y)).fromNormalization := by + let n := Y.fromSpecStalk (genericPoint Y) + constructor + intro U hU + let A := Γ(Y, U) + let L := Γ(Spec Y.functionField, n ⁻¹ᵁ U) + let : Algebra A L := (n.app U).hom.toAlgebra + let F := (Scheme.ΓSpecIso (CommRingCat.of k)).inv ≫ g.appLE ⊤ U le_top + let : Algebra k A := F.hom.toAlgebra + have : Algebra.FiniteType k A := by + change F.hom.FiniteType + apply RingHom.finiteType_respectsIso.2 + (e := (Scheme.ΓSpecIso (CommRingCat.of k)).symm.commRingCatIsoToRingEquiv) + exact g.finiteType_appLE (isAffineOpen_top _) hU le_top + have hfin : Module.Finite A (integralClosure A L) := by + by_cases hne : Nonempty U + · have : IsFractionRing A L := isFractionRing_genericPoint_preimage_sections Y U hU + have := finite_integralClosure_of_finiteType_charZero k A + exact Module.Finite.equiv (FractionRing.algEquiv A L).mapIntegralClosure.toLinearEquiv + · have hUbot : U = ⊥ := by + apply bot_unique + intro x hx + exact False.elim (hne ⟨⟨x, hx⟩⟩) + have hprebot : n ⁻¹ᵁ U = ⊥ := by rw [hUbot]; rfl + have : Subsingleton L := by dsimp only [L]; rw [hprebot]; infer_instance + infer_instance + rw [n.fromNormalization_app hU, CommRingCat.hom_comp] + exact (RingHom.Finite.of_surjective _ + (n.normalizationObjIso hU).symm.commRingCatIsoToRingEquiv.surjective).comp + (RingHom.finite_algebraMap.mpr hfin) + +end WeightedTorusJets + +open IsLocalRing + +theorem isDiscreteValuationRing_of_fraction_pole + {R K : Type*} [CommRing R] [IsDomain R] [IsNoetherianRing R] [IsLocalRing R] + [IsIntegrallyClosed R] [Field K] [Algebra R K] [IsFractionRing R K] + (y : K) (hy : y ∉ Set.range (algebraMap R K)) + (hmul : ∀ r ∈ maximalIdeal R, y * algebraMap R K r ∈ Set.range (algebraMap R K)) : + IsDiscreteValuationRing R := by + classical + have hnf : ¬ IsField R := fun h ↦ hy ((IsFractionRing.surjective_iff_isField.mpr h) y) + have hmne : maximalIdeal R ≠ ⊥ := isField_iff_maximalIdeal_eq.not.mp hnf + let M : Submodule R K := Submodule.map (Algebra.linearMap R K) (maximalIdeal R) + have hM : M ≠ ⊥ := by + obtain ⟨a, ha, hane⟩ := (Submodule.ne_bot_iff _).mp hmne + rw [Submodule.ne_bot_iff] + exact ⟨algebraMap R K a, ⟨a, ha, rfl⟩, + (IsFractionRing.to_map_eq_zero_iff (K := K)).not.mpr hane⟩ + have hstable : ¬ ∀ z ∈ M, y * z ∈ M := by + intro h + have hint : IsIntegral R y := isIntegral_of_smul_mem_submodule M hM + (Submodule.FG.map _ (IsNoetherian.noetherian _)) y h + exact hy (IsIntegrallyClosed.algebraMap_eq_of_integral hint) + push Not at hstable + obtain ⟨z, hz, hyz⟩ := hstable + obtain ⟨r, hr, rfl⟩ := hz + obtain ⟨t, ht⟩ := hmul r hr + have htunit : IsUnit t := by + by_contra htunit + apply hyz + exact ⟨t, htunit, ht⟩ + obtain ⟨v, hv⟩ := htunit.exists_right_inv + let u : R := r * v + have hu : u ∈ maximalIdeal R := Ideal.mul_mem_right _ _ hr + have hyu : y * algebraMap R K u = 1 := by + rw [show u = r * v from rfl, map_mul, ← mul_assoc, ← ht, ← map_mul, hv, map_one] + have hp : (maximalIdeal R).IsPrincipal := by + refine ⟨⟨u, le_antisymm ?_ ?_⟩⟩ + · intro a ha + obtain ⟨b, hb⟩ := hmul a ha + apply Ideal.mem_span_singleton'.mpr + refine ⟨b, ?_⟩ + apply IsFractionRing.injective R K + rw [map_mul, hb, mul_right_comm, hyu, one_mul] + · exact Ideal.span_le.mpr (Set.singleton_subset_iff.mpr hu) + exact ((IsDiscreteValuationRing.TFAE R hnf).out 5 1).mp hp + +theorem height_eq_one_of_prime_denominator + {R K : Type*} [CommRing R] [IsDomain R] [IsNoetherianRing R] [IsIntegrallyClosed R] + [Field K] [Algebra R K] [IsFractionRing R K] + (p : Ideal R) [p.IsPrime] (y : K) + (hp : ∀ r : R, r ∈ p ↔ y * algebraMap R K r ∈ Set.range (algebraMap R K)) : + p.height = 1 := by + classical + let S := Localization.subalgebra.ofField K p.primeCompl p.primeCompl_le_nonZeroDivisors + have : IsLocalRing S := IsLocalization.AtPrime.isLocalRing S p + have : IsNoetherianRing S := + IsLocalization.isNoetherianRing p.primeCompl S inferInstance + have : IsIntegrallyClosed S := + isIntegrallyClosed_of_isLocalization S p.primeCompl p.primeCompl_le_nonZeroDivisors + have hmap (a : R) (s : p.primeCompl) : + algebraMap S K (IsLocalization.mk' S a s) = + algebraMap R K a / algebraMap R K s := by + have hs : algebraMap R K s ≠ 0 := (IsFractionRing.to_map_eq_zero_iff (K := K)).not.mpr + (fun hzero ↦ s.2 (hzero ▸ p.zero_mem)) + apply (eq_div_iff hs).mpr + have h := congrArg (algebraMap S K) (IsLocalization.mk'_spec S a s) + simpa only [map_mul, ← IsScalarTower.algebraMap_apply R S K] using h + have hnot : y ∉ Set.range (algebraMap S K) := by + rintro ⟨z, hz⟩ + obtain ⟨a, s, rfl⟩ := IsLocalization.exists_mk'_eq p.primeCompl z + apply s.2 + apply (hp s).mpr + refine ⟨a, ?_⟩ + rw [← hz, hmap] + have hs : algebraMap R K s ≠ 0 := (IsFractionRing.to_map_eq_zero_iff (K := K)).not.mpr + (fun hzero ↦ s.2 (hzero ▸ p.zero_mem)) + exact (div_mul_cancel₀ _ hs).symm + have hmul : ∀ r ∈ maximalIdeal S, + y * algebraMap S K r ∈ Set.range (algebraMap S K) := by + intro z hz + obtain ⟨a, s, rfl⟩ := IsLocalization.exists_mk'_eq p.primeCompl z + have ha : a ∈ p := (IsLocalization.AtPrime.mk'_mem_maximal_iff S p a s).mp hz + obtain ⟨b, hb⟩ := (hp a).mp ha + refine ⟨IsLocalization.mk' S b s, ?_⟩ + rw [hmap, hmap, hb, mul_div_assoc] + have : IsDiscreteValuationRing S := isDiscreteValuationRing_of_fraction_pole y hnot hmul + have hdim := IsDiscreteValuationRing.ringKrullDim_eq_one S + rw [IsLocalization.AtPrime.ringKrullDim_eq_height p S] at hdim + exact_mod_cast hdim + +theorem mem_algebraMap_of_mem_height_one_localizations + {R K : Type*} [CommRing R] [IsDomain R] [IsNoetherianRing R] [IsIntegrallyClosed R] + [Field K] [Algebra R K] [IsFractionRing R K] {x : K} + (hlocal : ∀ p : PrimeSpectrum R, p.asIdeal.height = 1 → + x ∈ Localization.subalgebra.ofField K p.asIdeal.primeCompl + p.asIdeal.primeCompl_le_nonZeroDivisors) : + x ∈ Set.range (algebraMap R K) := by + classical + by_contra hx + let B : Submodule R K := (Algebra.linearMap R K).range + let D : K → Ideal R := fun y ↦ B.colon {y} + have hD (y : K) (r : R) : + r ∈ D y ↔ y * algebraMap R K r ∈ Set.range (algebraMap R K) := by + simp only [D, Submodule.mem_colon_singleton, B, LinearMap.mem_range, + Algebra.linearMap_apply, Algebra.smul_def, mul_comm, Set.mem_range] + have hDx : D x ≠ ⊤ := by + intro heq + have hmem : (1 : R) ∈ D x := heq ▸ (show (1 : R) ∈ (⊤ : Ideal R) by simp) + exact hx (by simpa using (hD x 1).mp hmem) + obtain ⟨p, ⟨hle, hpne, y, rfl⟩, hmax⟩ := + set_has_maximal_iff_noetherian.mpr (inferInstance : IsNoetherianRing R) + {p : Ideal R | D x ≤ p ∧ p ≠ ⊤ ∧ ∃ y : K, p = D y} + ⟨D x, le_rfl, hDx, x, rfl⟩ + have hprime : (D y).IsPrime := by + refine ⟨hpne, ?_⟩ + intro a b hab + by_cases ha : a ∈ D y + · exact Or.inl ha + apply Or.inr + have H : D y ≤ D (algebraMap R K a * y) := by + intro c hc + obtain ⟨d, hd⟩ := (hD y c).mp hc + apply (hD _ c).mpr + refine ⟨a * d, ?_⟩ + rw [map_mul, hd, mul_assoc] + have Hne : D (algebraMap R K a * y) ≠ ⊤ := by + intro heq + apply ha + have hmem : (1 : R) ∈ D (algebraMap R K a * y) := + heq ▸ (show (1 : R) ∈ (⊤ : Ideal R) by simp) + simpa [hD, mul_comm] using hmem + have Heq : D y = D (algebraMap R K a * y) := + H.eq_of_not_lt (hmax _ ⟨hle.trans H, Hne, _, rfl⟩) + rw [Heq, hD] + simpa [map_mul, mul_left_comm, mul_assoc] using (hD y (a * b)).mp hab + have : (D y).IsPrime := hprime + have hheight : (D y).height = 1 := height_eq_one_of_prime_denominator (D y) y (hD y) + obtain ⟨a, s, hs, hxs⟩ := hlocal ⟨D y, hprime⟩ hheight + apply hs + apply hle + apply (hD x s).mpr + refine ⟨a, ?_⟩ + rw [hxs, mul_assoc, inv_mul_cancel₀, mul_one] + exact (IsFractionRing.to_map_eq_zero_iff (K := K)).not.mpr + (fun hzero ↦ hs (hzero ▸ (D y).zero_mem)) + +open AlgebraicGeometry TopologicalSpace CategoryTheory + +namespace AlgebraicGeometry.Scheme + +variable {X : Scheme} [IsIntegral X] [IsLocallyNoetherian X] + +theorem isDiscreteValuationRing_stalk_of_isIntegrallyClosed {x : X} + [IsIntegrallyClosed (X.presheaf.stalk x)] (hx : Order.coheight x = 1) : + IsDiscreteValuationRing (X.presheaf.stalk x) := by + have : Ring.KrullDimLE 1 (X.presheaf.stalk x) := krullDimLE_of_coheight_le hx.le + have hnf : ¬ IsField (X.presheaf.stalk x) := by + intro h + have hzero := ringKrullDim_eq_zero_of_isField h + rw [ringKrullDim_stalk_eq_coheight, hx] at hzero + exact one_ne_zero hzero + apply ((IsDiscreteValuationRing.TFAE (X.presheaf.stalk x) hnf).out 4 1).mp + refine ⟨inferInstance, IsLocalRing.maximalIdeal (X.presheaf.stalk x), ?_, ?_⟩ + · exact ⟨IsLocalRing.isField_iff_maximalIdeal_eq.not.mp hnf, inferInstance⟩ + · intro p hp + exact IsLocalRing.eq_maximalIdeal (hp.2.isMaximal_of_ne_bot hp.1) + +theorem exists_stalk_unit_of_ord_eq_zero {x : X} + [IsDiscreteValuationRing (X.presheaf.stalk x)] + (hx : Order.coheight x = 1) {f : X.functionField} (hf : f ≠ 0) + (hord : X.ord f x = 0) : + ∃ u : X.presheaf.stalk x, IsUnit u ∧ + algebraMap (X.presheaf.stalk x) X.functionField u = f := by + have h : Ring.ordFrac (X.presheaf.stalk x) f = 1 := by + simpa [_root_.AlgebraicGeometry.Scheme.ordHom] using (X.ord_eq_iff hx hf).mp hord + change f ∈ (IsUnit.submonoid (X.presheaf.stalk x)).map + (algebraMap (X.presheaf.stalk x) X.functionField) + rw [← Ring.mker_ordFrac_eq_isUnitSubmonoid] + exact h + +end AlgebraicGeometry.Scheme + +namespace AlgebraicGeometry + +variable {X : Scheme} [IsIntegral X] + +theorem IsAffineOpen.isIntegrallyClosed_of_stalks {U : X.Opens} + (hU : IsAffineOpen U) [Nonempty U] + [∀ x : X, IsIntegrallyClosed (X.presheaf.stalk x)] : IsIntegrallyClosed Γ(X, U) := by + let (p : PrimeSpectrum Γ(X, U)) : Algebra Γ(X, U) (X.presheaf.stalk (hU.fromSpec p)) := + TopCat.Presheaf.algebra_section_stalk X.presheaf ⟨hU.fromSpec p, (hU.isoSpec.inv p).2⟩ + have (p : Ideal Γ(X, U)) [hp : p.IsPrime] : + IsLocalization.AtPrime (X.presheaf.stalk (hU.fromSpec ⟨p, hp⟩)) p := + hU.isLocalization_stalk' ⟨p, hp⟩ (hU.isoSpec.inv _).2 + exact IsIntegrallyClosed.of_isLocalization_maximal + (fun p hp ↦ X.presheaf.stalk (hU.fromSpec ⟨p, hp.isPrime⟩)) (fun _ _ ↦ inferInstance) + +theorem IsAffineOpen.exists_section_of_codim_one_regular {U : X.Opens} + (hU : IsAffineOpen U) [Nonempty U] [IsLocallyNoetherian X] + [∀ x : X, IsIntegrallyClosed (X.presheaf.stalk x)] (f : X.functionField) + (hregular : ∀ x : X, Order.coheight x = 1 → + ∃ u : X.presheaf.stalk x, algebraMap (X.presheaf.stalk x) X.functionField u = f) : + ∃ s : Γ(X, U), X.germToFunctionField U s = f := by + have : IsFractionRing Γ(X, U) X.functionField := + functionField_isFractionRing_of_isAffineOpen X U hU + have : IsIntegrallyClosed Γ(X, U) := IsAffineOpen.isIntegrallyClosed_of_stalks hU + have : IsNoetherianRing Γ(X, U) := IsLocallyNoetherian.component_noetherian ⟨U, hU⟩ + have hmem : f ∈ Set.range (algebraMap Γ(X, U) X.functionField) := by + apply mem_algebraMap_of_mem_height_one_localizations + intro p hp + let x : X := hU.fromSpec p + have hxU : x ∈ U := (hU.isoSpec.inv p).2 + let : Algebra Γ(X, U) (X.presheaf.stalk x) := + TopCat.Presheaf.algebra_section_stalk X.presheaf ⟨x, hxU⟩ + have : IsLocalization.AtPrime (X.presheaf.stalk x) p.asIdeal := + hU.isLocalization_stalk' p hxU + have hx : Order.coheight x = 1 := by + have hdim := IsLocalization.AtPrime.ringKrullDim_eq_height p.asIdeal (X.presheaf.stalk x) + rw [ringKrullDim_stalk_eq_coheight, hp] at hdim + exact_mod_cast hdim + have : IsScalarTower Γ(X, U) (X.presheaf.stalk x) X.functionField := + functionField_isScalarTower X U ⟨x, hxU⟩ + obtain ⟨u, hu⟩ := hregular x hx + obtain ⟨a, s, rfl⟩ := IsLocalization.exists_mk'_eq p.asIdeal.primeCompl u + refine ⟨a, s, s.2, ?_⟩ + rw [← hu, ← div_eq_mul_inv] + have hs : algebraMap Γ(X, U) X.functionField s ≠ 0 := + (IsFractionRing.to_map_eq_zero_iff (K := X.functionField)).not.mpr + (fun hzero ↦ s.2 (hzero ▸ p.asIdeal.zero_mem)) + apply (eq_div_iff hs).mpr + have h := congrArg (algebraMap (X.presheaf.stalk x) X.functionField) + (IsLocalization.mk'_spec (X.presheaf.stalk x) a s) + simpa only [map_mul, ← IsScalarTower.algebraMap_apply Γ(X, U) + (X.presheaf.stalk x) X.functionField] using h + exact hmem + +end AlgebraicGeometry + +namespace AlgebraicGeometry.Scheme + +variable {X : Scheme} [IsIntegral X] + +theorem exists_global_unit_of_stalk_units {f : X.functionField} + (h : ∀ x : X, ∃ u : X.presheaf.stalk x, IsUnit u ∧ + algebraMap (X.presheaf.stalk x) X.functionField u = f) : + ∃ s : Γ(X, ⊤), IsUnit s ∧ + X.presheaf.germ ⊤ (genericPoint X) (by simp) s = f := by + classical + have : Nonempty (⊤ : X.Opens) := ⟨⟨Classical.arbitrary X, by simp⟩⟩ + change ∃ s : Γ(X, ⊤), IsUnit s ∧ X.germToFunctionField ⊤ s = f + have hlocal (x : X) : ∃ (U : X.Opens) (hx : x ∈ U) (s : Γ(X, U)), IsUnit s ∧ + algebraMap (X.presheaf.stalk x) X.functionField (X.presheaf.germ U x hx s) = f := by + obtain ⟨u, hu, huf⟩ := h x + obtain ⟨U, hxU, s, hs⟩ := X.presheaf.exists_germ_eq u + obtain ⟨V, i, hxV, hv⟩ := X.toRingedSpace.isUnit_res_of_isUnit_germ U s x hxU + (hs.symm ▸ hu) + refine ⟨V, hxV, X.presheaf.map i.op s, hv, ?_⟩ + rw [X.presheaf.germ_res_apply i x hxV s, hs, huf] + choose U hx s hs hf using hlocal + have (x : X) : Nonempty (U x) := ⟨⟨x, hx x⟩⟩ + have hfield (x : X) : X.germToFunctionField (U x) (s x) = f := by + rw [← X.algebraMap_germ_eq_germToFunctionField (hx x)] + exact hf x + have hcover : (⊤ : X.Opens) ≤ iSup U := by + intro x _ + exact Opens.mem_iSup.mpr ⟨x, hx x⟩ + have hc : TopCat.Presheaf.IsCompatible X.presheaf U s := by + intro x y + apply TopCat.Presheaf.section_ext X.sheaf + intro z hz + change X.presheaf.germ (U x ⊓ U y) z hz + (X.presheaf.map (Opens.infLELeft (U x) (U y)).op (s x)) = + X.presheaf.germ (U x ⊓ U y) z hz + (X.presheaf.map (Opens.infLERight (U x) (U y)).op (s y)) + apply IsFractionRing.injective (X.presheaf.stalk z) X.functionField + rw [X.presheaf.germ_res_apply, X.presheaf.germ_res_apply, + X.algebraMap_germ_eq_germToFunctionField hz.1, + X.algebraMap_germ_eq_germToFunctionField hz.2] + exact (hfield x).trans (hfield y).symm + obtain ⟨g, hg, _⟩ : ∃ g : Γ(X, ⊤), + (∀ i, X.presheaf.map (homOfLE (show U i ≤ ⊤ from le_top)).op g = s i) ∧ _ := + X.sheaf.existsUnique_gluing' U ⊤ (fun _ ↦ homOfLE le_top) hcover s hc + refine ⟨g, ?_, ?_⟩ + · apply X.toRingedSpace.isUnit_of_isUnit_germ + intro x hxTop + have heq : X.presheaf.germ ⊤ x hxTop g = + X.presheaf.germ (U x) x (hx x) (s x) := by + rw [← hg x, X.presheaf.germ_res_apply] + rw [heq] + exact (hs x).map (X.presheaf.germ (U x) x (hx x)).hom + · let x : X := Classical.arbitrary X + rw [← hfield x, ← hg x, ← X.algebraMap_germ_eq_germToFunctionField (hx x), + X.presheaf.germ_res_apply, X.algebraMap_germ_eq_germToFunctionField] + +variable [IsLocallyNoetherian X] + [∀ x : X, IsIntegrallyClosed (X.presheaf.stalk x)] + +theorem exists_global_unit_of_ord_eq_zero (f : X.functionField) (hf : f ≠ 0) + (hord : ∀ x : X, X.ord f x = 0) : + ∃ s : Γ(X, ⊤), IsUnit s ∧ + X.presheaf.germ ⊤ (genericPoint X) (by simp) s = f := by + have hunit (x : X) (hx : Order.coheight x = 1) : + ∃ u : X.presheaf.stalk x, IsUnit u ∧ + algebraMap (X.presheaf.stalk x) X.functionField u = f := by + have : IsDiscreteValuationRing (X.presheaf.stalk x) := + isDiscreteValuationRing_stalk_of_isIntegrallyClosed hx + exact exists_stalk_unit_of_ord_eq_zero hx hf (hord x) + apply exists_global_unit_of_stalk_units + intro x + obtain ⟨_, ⟨U, hU, rfl⟩, hxU, _⟩ := + X.isBasis_affineOpens.exists_subset_of_mem_open (show x ∈ (⊤ : X.Opens) by simp) + (⊤ : X.Opens).isOpen + have : Nonempty U := ⟨⟨x, hxU⟩⟩ + obtain ⟨s, hs⟩ := IsAffineOpen.exists_section_of_codim_one_regular hU f fun y hy ↦ by + obtain ⟨u, _, hu⟩ := hunit y hy + exact ⟨u, hu⟩ + obtain ⟨t, ht⟩ := IsAffineOpen.exists_section_of_codim_one_regular hU f⁻¹ fun y hy ↦ by + obtain ⟨u, hu, huf⟩ := hunit y hy + refine ⟨↑hu.unit⁻¹, ?_⟩ + rw [map_units_inv, hu.unit_spec, huf] + have hst : s * t = 1 := by + apply X.germToFunctionField_injective U + rw [map_mul, map_one, hs, ht, mul_inv_cancel₀ hf] + have hsu : IsUnit s := IsUnit.of_mul_eq_one t hst + refine ⟨X.presheaf.germ U x hxU s, hsu.map (X.presheaf.germ U x hxU).hom, ?_⟩ + rw [X.algebraMap_germ_eq_germToFunctionField hxU, hs] + +end AlgebraicGeometry.Scheme + +open AlgebraicGeometry TopologicalSpace CategoryTheory + +end +end OriginalSourceGeometryOverlay +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/E.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/E.lean new file mode 100644 index 0000000000000000000000000000000000000000..d8ecbe8ae1f6a3da6de26ad9ea68a2063458b5e5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/E.lean @@ -0,0 +1,529 @@ +/- +Portions of this file have been adapted from an external source. +An attribution header has been generated because the source file did not contain a copyright header. +The applicable license information is stated below. +-/ + +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section AnalyticAssemblyScope +open scoped BigOperators Topology +section + +open scoped BigOperators + +namespace WeightedTorusJets + +open ArithmeticFunction DirichletCharacter + +theorem combined_vonMangoldt_LSeries {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) {s : ℂ} (hs : 1 < s.re) : + LSeries (fun n : ℕ => (vonMangoldt n : ℂ) * (1 + χ n)) s = + -deriv riemannZeta s / riemannZeta s - + deriv (LFunction χ) s / LFunction χ s := by + have heq : (fun n : ℕ => (vonMangoldt n : ℂ) * (1 + χ n)) = + (fun n : ℕ => (vonMangoldt n : ℂ)) + + ((fun n : ℕ => χ n) * (fun n : ℕ => (vonMangoldt n : ℂ))) := by + funext n + simp [mul_add, mul_comm] + rw [heq, LSeries_add (LSeriesSummable_vonMangoldt hs) + (LSeriesSummable_twist_vonMangoldt χ hs), + LSeries_vonMangoldt_eq_deriv_riemannZeta_div hs, + LSeries_twist_vonMangoldt_eq χ hs, + deriv_LFunction_eq_deriv_LSeries χ hs, LFunction_eq_LSeries χ hs] + simp [sub_eq_add_neg, neg_div] + +theorem combined_vonMangoldt_summable {q : ℕ} (χ : DirichletCharacter ℂ q) + {s : ℂ} (hs : 1 < s.re) : + LSeriesSummable (fun n : ℕ => (vonMangoldt n : ℂ) * (1 + χ n)) s := by + convert (LSeriesSummable_vonMangoldt hs).add + (LSeriesSummable_twist_vonMangoldt χ hs) using 1 + funext n + simp [mul_add, mul_comm] + +theorem re_combined_vonMangoldt_term {q : ℕ} (χ : DirichletCharacter ℂ q) + (s : ℝ) (n : ℕ) : + (LSeries.term (fun m : ℕ => (vonMangoldt m : ℂ) * (1 + χ m)) s n).re = + vonMangoldt n * (1 + (χ n).re) / (n : ℝ) ^ s := by + rcases eq_or_ne n 0 with rfl | hn + · simp + · rw [LSeries.term_of_ne_zero hn] + change (((vonMangoldt n : ℂ) * (1 + χ n)) / + (((n : ℝ) : ℂ) ^ (s : ℂ))).re = _ + rw [← Complex.ofReal_cpow (Nat.cast_nonneg n)] + simp [Complex.div_ofReal_re] + +open scoped ComplexOrder in + +theorem combined_vonMangoldt_term_nonneg {q : ℕ} (χ : DirichletCharacter ℂ q) + (hχ : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) (n : ℕ) : + 0 ≤ LSeries.term (fun m : ℕ => (vonMangoldt m : ℂ) * (1 + χ m)) s n := by + apply LSeries.term_nonneg + apply mul_nonneg + · exact_mod_cast (vonMangoldt_nonneg (n := n)) + · rw [Complex.nonneg_iff] + constructor + · simp only [Complex.add_re, Complex.one_re] + have hnorm := χ.norm_le_one (n : ZMod q) + have hre := (abs_le.mp (Complex.abs_re_le_norm (χ n))).1 + linarith + · simp [hχ] + +theorem prime_sum_rpow_le_logDeriv {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) {s : ℝ} (hs : 1 < s) + (P : Finset ℕ) (hP : ∀ p ∈ P, p.Prime ∧ χ p = 1) : + 2 * ∑ p ∈ P, Real.log p / (p : ℝ) ^ s ≤ + (-deriv riemannZeta (s : ℂ) / riemannZeta s - + deriv (LFunction χ) (s : ℂ) / LFunction χ s).re := by + have hsc : 1 < (s : ℂ).re := hs + have hsum := combined_vonMangoldt_summable χ hsc + have hnonneg (n : ℕ) : + 0 ≤ (LSeries.term (fun m : ℕ => (vonMangoldt m : ℂ) * (1 + χ m)) s n).re := by + rw [re_combined_vonMangoldt_term] + apply div_nonneg (mul_nonneg vonMangoldt_nonneg ?_) (Real.rpow_nonneg (Nat.cast_nonneg n) _) + have hnorm := χ.norm_le_one (n : ZMod q) + have hre := (abs_le.mp (Complex.abs_re_le_norm (χ n))).1 + linarith + have hbound := (Complex.hasSum_re hsum.hasSum).summable.sum_le_tsum P + (fun n _ => hnonneg n) + rw [← Complex.re_tsum hsum] at hbound + change _ ≤ (LSeries _ (s : ℂ)).re at hbound + rw [combined_vonMangoldt_LSeries χ hsc] at hbound + refine le_trans ?_ hbound + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + rw [re_combined_vonMangoldt_term, (hP p hp).2, Complex.one_re, + vonMangoldt_apply_prime (hP p hp).1] + ring_nf + exact le_rfl + +theorem log_rpow_compare {x X : ℝ} (hx : 1 ≤ x) (hxX : x ≤ X) (hX : 1 < X) : + (2 / Real.exp 1) * (Real.log x / x) ≤ + 2 * (Real.log x / x ^ (1 + 1 / Real.log X)) := by + have hx0 : 0 < x := lt_of_lt_of_le zero_lt_one hx + have hlogX : 0 < Real.log X := Real.log_pos hX + have hlogx : 0 ≤ Real.log x := Real.log_nonneg hx + have hpow : x ^ (1 + 1 / Real.log X) ≤ x * Real.exp 1 := by + rw [Real.rpow_add hx0, Real.rpow_one, one_div] + exact mul_le_mul_of_nonneg_left + ((Real.rpow_le_rpow hx0.le hxX (inv_nonneg.mpr hlogX.le)).trans + Real.rpow_inv_log_le_exp_one) hx0.le + calc + (2 / Real.exp 1) * (Real.log x / x) = (2 * Real.log x) / (x * Real.exp 1) := by + ring + _ ≤ (2 * Real.log x) / x ^ (1 + 1 / Real.log X) := + div_le_div_of_nonneg_left (mul_nonneg (by norm_num) hlogx) + (Real.rpow_pos_of_pos hx0 _) hpow + _ = 2 * (Real.log x / x ^ (1 + 1 / Real.log X)) := by ring + +theorem positive_prime_mass_le_logDeriv_floor {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) {X : ℝ} (hX : 1 < X) : + (2 / Real.exp 1) * + ∑ p ∈ (Nat.primesLE ⌊X⌋₊).filter (fun p : ℕ => χ p = 1), + Real.log p / (p : ℝ) ≤ + (-deriv riemannZeta ((1 + 1 / Real.log X : ℝ) : ℂ) / + riemannZeta ((1 + 1 / Real.log X : ℝ) : ℂ) - + deriv (LFunction χ) ((1 + 1 / Real.log X : ℝ) : ℂ) / + LFunction χ ((1 + 1 / Real.log X : ℝ) : ℂ)).re := by + classical + have hs : 1 < 1 + 1 / Real.log X := + lt_add_of_pos_right 1 (one_div_pos.mpr (Real.log_pos hX)) + have hprime : ∀ p ∈ (Nat.primesLE ⌊X⌋₊).filter (fun p : ℕ => χ p = 1), + p.Prime ∧ χ p = 1 := by + intro p hp + obtain ⟨hp, hχp⟩ := Finset.mem_filter.mp hp + exact ⟨Nat.prime_of_mem_primesLE hp, hχp⟩ + apply le_trans _ (prime_sum_rpow_le_logDeriv χ hs _ hprime) + rw [Finset.mul_sum, Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + have hp := (Finset.mem_filter.mp hp).1 + exact log_rpow_compare + (Nat.one_le_cast.mpr (Nat.prime_of_mem_primesLE hp).one_le) + ((Nat.le_floor_iff (by linarith)).mp (Nat.le_of_mem_primesLE hp)) hX + +end WeightedTorusJets +end +section + +namespace WeightedTorusJets + +theorem reciprocal_gap_identity {s β : ℝ} (hs : 1 < s) (hβ : β < 1) : + 1 / (s - 1) - 1 / (s - β) = (1 - β) / ((s - 1) * (s - β)) := by + have hs1 : s - 1 ≠ 0 := by linarith + have hsβ : s - β ≠ 0 := by linarith + field_simp + ring + +theorem reciprocal_gap_le {L β : ℝ} (hL : 0 < L) (hβ : β < 1) : + 1 / ((1 + 1 / L) - 1) - 1 / ((1 + 1 / L) - β) ≤ (1 - β) * L ^ 2 := by + have hLi : 0 < 1 / L := one_div_pos.mpr hL + have hs : 1 < 1 + 1 / L := by linarith + rw [reciprocal_gap_identity hs hβ, add_sub_cancel_left] + calc + (1 - β) / ((1 / L) * (1 + 1 / L - β)) ≤ + (1 - β) / ((1 / L) * (1 / L)) := by + apply div_le_div_of_nonneg_left (by linarith) (mul_pos hLi hLi) + exact mul_le_mul_of_nonneg_left (by linarith) hLi.le + _ = (1 - β) * L ^ 2 := by field_simp + +theorem primebias_sampling_point {X : ℝ} (hX : 3 ≤ X) : + 1 < 1 + 1 / Real.log X ∧ 1 + 1 / Real.log X ≤ 2 := by + have hlog : 1 < Real.log X := by + apply (Real.lt_log_iff_exp_lt (by linarith)).mpr + exact Real.exp_one_lt_three.trans_le hX + constructor + · have := one_div_pos.mpr (show 0 < Real.log X by linarith) + linarith + · have := (div_le_one (show 0 < Real.log X by linarith)).mpr hlog.le + linarith + +end WeightedTorusJets +end +section +namespace WeightedTorusJets + +theorem positive_prime_mass_of_logDeriv_upper {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) {X β K : ℝ} (hX : 1 < X) (hβ : β < 1) + (hupper : + (-deriv riemannZeta ((1 + 1 / Real.log X : ℝ) : ℂ) / + riemannZeta ((1 + 1 / Real.log X : ℝ) : ℂ) - + deriv (DirichletCharacter.LFunction χ) ((1 + 1 / Real.log X : ℝ) : ℂ) / + DirichletCharacter.LFunction χ ((1 + 1 / Real.log X : ℝ) : ℂ)).re ≤ + K * Real.log q + 1 / ((1 + 1 / Real.log X) - 1) - + 1 / ((1 + 1 / Real.log X) - β)) : + (∑ p ∈ Nat.primesLE ⌊X⌋₊ with χ ((p : ℕ) : ZMod q) = 1, + Real.log p / p) ≤ + (Real.exp 1 / 2) * K * Real.log q + + (Real.exp 1 / 2) * ((1 - β) * (Real.log X) ^ 2) := by + have hgap := reciprocal_gap_le (Real.log_pos hX) hβ + have hbound := (positive_prime_mass_le_logDeriv_floor χ hX).trans hupper + have hbound' : (2 / Real.exp 1) * + (∑ p ∈ Nat.primesLE ⌊X⌋₊ with χ ((p : ℕ) : ZMod q) = 1, Real.log p / p) ≤ + K * Real.log q + (1 - β) * (Real.log X) ^ 2 := by + linarith + have hscaled := mul_le_mul_of_nonneg_left hbound' + (show 0 ≤ Real.exp 1 / 2 by positivity) + have he : Real.exp 1 ≠ 0 := (Real.exp_pos 1).ne' + field_simp [he] at hscaled + nlinarith + +end WeightedTorusJets +end +section + +open _root_.Complex Filter +open scoped Topology ComplexConjugate + +namespace RealCharacterAnalysis + +theorem real_values_iff_quadratic {q : ℕ} + (χ : DirichletCharacter ℂ q) : + (∀ a : ZMod q, (χ a).im = 0) ↔ χ.IsQuadratic := by + constructor + · intro h + have hc : star χ = χ := by + ext a + exact Complex.conj_eq_iff_im.mpr (h a) + have hi : χ⁻¹ = χ := (MulChar.star_eq_inv χ).symm.trans hc + apply MulChar.isQuadratic_iff_sq_eq_one.mpr + calc + χ ^ 2 = χ * χ := sq χ + _ = χ * χ⁻¹ := congrArg (χ * ·) hi.symm + _ = 1 := mul_inv_cancel χ + · intro h a + rcases h a with h | h | h <;> simp [h] + +theorem apply_prime_eq_zero_iff {q p : ℕ} (χ : DirichletCharacter ℂ q) + (hp : p.Prime) : χ (p : ZMod q) = 0 ↔ p ∣ q := by + rw [MulChar.apply_eq_zero_iff, ZMod.isUnit_prime_iff_not_dvd hp, not_not] + +theorem lSeries_conj (f : ℕ → ℂ) (s : ℂ) : + LSeries (fun n => conj (f n)) (conj s) = conj (LSeries f s) := by + rw [LSeries, LSeries, Complex.conj_tsum] + apply tsum_congr + intro n + by_cases hn : n = 0 + · simp [hn] + · simp only [LSeries.term_of_ne_zero hn, map_div₀] + rw [Complex.cpow_conj _ _ (by simp [Real.pi_ne_zero.symm])] + simp + +theorem lFunction_conj {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (s : ℂ) : + DirichletCharacter.LFunction χ⁻¹ (conj s) = + conj (DirichletCharacter.LFunction χ s) := by + have hi : χ⁻¹ ≠ 1 := inv_ne_one.mpr hχ + have hf := DirichletCharacter.differentiable_LFunction hi + have hg : Differentiable ℂ + (conj ∘ DirichletCharacter.LFunction χ ∘ conj) := by + intro z + simpa using + (DirichletCharacter.differentiable_LFunction hχ (conj z)).conj_conj + have heq : DirichletCharacter.LFunction χ⁻¹ = + conj ∘ DirichletCharacter.LFunction χ ∘ conj := by + apply (hf.differentiableOn.analyticOnNhd isOpen_univ).eq_of_eventuallyEq + (hg.differentiableOn.analyticOnNhd isOpen_univ) + have hn : {z : ℂ | 1 < z.re} ∈ nhds (2 : ℂ) := + (isOpen_lt continuous_const continuous_re).mem_nhds (by norm_num) + filter_upwards [hn] with z hz + simp only [Function.comp_apply] + rw [DirichletCharacter.LFunction_eq_LSeries χ⁻¹ hz, + DirichletCharacter.LFunction_eq_LSeries χ (by simpa using hz)] + have hc : (fun n : ℕ => χ⁻¹ (n : ZMod q)) = + (fun n : ℕ => conj (χ (n : ZMod q))) := by + funext n + simpa using (MulChar.star_apply' χ (n : ZMod q)).symm + rw [hc, ← lSeries_conj, Complex.conj_conj] + simpa using congrFun heq (conj s) + +theorem lFunction_real {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + (hr : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + (DirichletCharacter.LFunction χ (s : ℂ)).im = 0 := by + apply Complex.conj_eq_iff_im.mp + rw [← lFunction_conj χ hχ, Complex.conj_ofReal, + ((real_values_iff_quadratic χ).mp hr).inv] + +end RealCharacterAnalysis +end +section + +/- +Generated attribution header: the source file did not contain a copyright header. +The Mertens estimates in the following namespace are adapted from PrimeNumberTheoremAnd.IEANTN.Mertens. +Source: https://github.com/AlexKontorovich/PrimeNumberTheoremAnd/blob/c39a751132c88b6e8080b74c74023fd95b3d8be0/PrimeNumberTheoremAnd/IEANTN/Mertens.lean +License: Apache License 2.0. + +This code has been modified. +-/ + +namespace WeightedTorusJets.Mertens + +open _root_.Real _root_.Finset Filter Asymptotics Topology +open ArithmeticFunction hiding log + +theorem sum_log_le {x : ℝ} (hx : 1 ≤ x) : + ∑ n ∈ Ioc 0 ⌊ x ⌋₊, log n ≤ x * log x := by + calc + _ ≤ ∑ n ∈ Ioc 0 ⌊ x ⌋₊, log x := by + refine sum_le_sum fun n hn ↦ ?_ + simp only [mem_Ioc] at hn + exact log_le_log (by exact_mod_cast hn.1) (Nat.le_floor_iff (by linarith)|>.mp hn.2) + _ = ⌊x⌋₊ * log x := by simp + _ ≤ _ := by + gcongr + · exact log_nonneg hx + · exact Nat.floor_le (by linarith) + +lemma integral_log_le {a b : ℝ} (ha : 1 ≤ a) (hab : a ≤ b) : + ∫ t in a..b, log t ≤ log b * (b - a) := by + apply le_of_abs_le + have : ∀ t ∈ Set.uIoc a b, ‖log t‖ ≤ log b := by + intro t ht + rw [Set.uIoc_of_le hab, Set.mem_Ioc] at ht + rw [norm_of_nonneg <| log_nonneg (by linarith)] + gcongr <;> linarith + grw [← norm_eq_abs, intervalIntegral.norm_integral_le_of_norm_le_const this, + abs_of_nonneg (by linarith)] + +theorem sum_log_ge {x : ℝ} (hx : 1 ≤ x) : + ∑ n ∈ Ioc 0 ⌊ x ⌋₊, log n ≥ x * log x - 2 * x := by + have one_le_floor : 1 ≤ ⌊x⌋₊ := by simpa + calc + _ = ∑ n ∈ Icc 1 ⌊ x ⌋₊, log n := by rfl + _ = ∑ n ∈ Ico (1 + 1) (⌊ x ⌋₊ + 1), log n := by + rw [← add_sum_Ioc_eq_sum_Icc one_le_floor] + simp + rfl + _ = ∑ n ∈ Ico 1 ⌊ x ⌋₊, log ((n + 1 : ℕ)) := by + rw [← Finset.sum_Ico_add'] + _ ≥ ∫ t in 1..⌊x⌋₊, log t := by + convert MonotoneOn.integral_le_sum_Ico one_le_floor ?_|>.ge + · norm_cast + · exact StrictMonoOn.monotoneOn (strictMonoOn_log.mono fun y hy ↦ (by simp_all; linarith)) + _ = (∫ t in 1..x, log t) - ∫ t in ⌊x⌋₊..x, log t := by + nth_rw 3 [intervalIntegral.integral_symm] + rw [sub_neg_eq_add, intervalIntegral.integral_add_adjacent_intervals] <;> exact intervalIntegral.intervalIntegrable_log' + _ ≥ (∫ t in 1..x, log t) - log x := by + gcongr + grw [integral_log_le (by simpa) (Nat.floor_le (by linarith))] + nth_rw 2 [← mul_one (log x)] + gcongr + · exact log_nonneg hx + · linarith [Nat.lt_floor_add_one x] + _ ≥ x * log x - x - log x := by simp only [integral_log, log_one, mul_zero, sub_zero, ge_iff_le, + tsub_le_iff_right, sub_add_cancel, le_add_iff_nonneg_right, zero_le_one] + _ ≥ _ := by linarith [log_le_self (by linarith : 0 ≤ x)] + +theorem sum_log_eq_sum_mangoldt {x : ℝ} : + ∑ n ∈ Ioc 0 ⌊x⌋₊, log n = ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d * ⌊x / d⌋₊ := by + have : ∀ n : ℕ, log n = (Λ * zeta) n := by simp [vonMangoldt_mul_zeta] + simp_rw [this, sum_Ioc_mul_zeta_eq_sum, ← Nat.floor_div_natCast] + +noncomputable abbrev E₁Λ (x : ℝ) : ℝ := ∑ d ∈ Ioc 0 ⌊ x ⌋₊, (Λ d) / d - log x + +theorem E₁Λ.ge {x : ℝ} (hx : 1 ≤ x) : + E₁Λ x ≥ -2 := by + unfold E₁Λ + suffices x * ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d / d ≥ x * (log x - 2) by + linarith [le_of_mul_le_mul_left this (by linarith)] + calc + _ = ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d * (x / d) := by + rw [Finset.mul_sum] + ring_nf + _ ≥ ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d * ⌊x / d⌋₊ := by + gcongr + exact Nat.floor_le <| div_nonneg (by linarith) (by linarith) + _ ≥ x * log x - 2 * x := + sum_log_eq_sum_mangoldt ▸ sum_log_ge hx + _ = _ := by ring + +theorem E₁Λ.le {x : ℝ} (hx : 1 ≤ x) : + E₁Λ x ≤ log 4 + 4 := by + unfold E₁Λ + suffices x * ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d / d ≤ x * (log x + log 4 + 4) by + linarith [le_of_mul_le_mul_left this (by linarith)] + calc + _ = ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d * (x / d) := by + rw [Finset.mul_sum] + ring_nf + _ ≤ ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d * (⌊x / d⌋₊ + 1) := by + gcongr + exact Nat.lt_floor_add_one _|>.le + _ = (∑ d ∈ Ioc 0 ⌊x⌋₊, log d) + ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d := by + simp_rw [mul_add, mul_one] + rw [Finset.sum_add_distrib, sum_log_eq_sum_mangoldt] + _ ≤ x * log x + (log 4 + 4) * x := by + gcongr + · exact sum_log_le hx + · exact Chebyshev.psi_le_const_mul_self (by linarith) + _ = _ := by ring + +noncomputable abbrev E₁p (x : ℝ) : ℝ := ∑ p ∈ Ioc 0 ⌊ x ⌋₊ with p.Prime, (log p) / p - log x + +theorem E₁p.le_E₁Λ (x : ℝ) : + E₁p x ≤ E₁Λ x := by + unfold E₁p E₁Λ; rw [sum_filter] + gcongr with p _ + split_ifs with hp + · simp [vonMangoldt_apply_prime hp] + have : 0 ≤ Λ p := vonMangoldt_nonneg + positivity + +noncomputable abbrev E₁ : ℝ := ∑' p : ℕ, if p.Prime then (log p) / (p*(p-1)) else 0 + +lemma E₁.summand_nonneg (p : ℕ) : 0 ≤ if p.Prime then (log p) / (p*(p-1)) else 0 := by + split_ifs with h + · refine div_nonneg (log_natCast_nonneg _) (mul_nonneg (Nat.cast_nonneg _) ?_) + suffices 1 ≤ (p : ℝ) by linarith + exact_mod_cast h.one_le + · rfl + +theorem E₁.summable : Summable (fun p : ℕ ↦ if p.Prime then (log p) / (p*(p-1)) else 0) := by + refine (Real.summable_one_div_nat_rpow.mpr (by norm_num: 1 < (3 : ℝ) / 2)|>.const_div + 4).of_nonneg_of_le E₁.summand_nonneg fun n ↦ ?_ + split_ifs with h + · grw [Real.log_le_rpow_div (Nat.cast_nonneg _) (by norm_num : 0 < (1 : ℝ) / 2)] + · have denom : (n : ℝ) * ((n : ℝ) - 1) ≥ n ^ 2/ 2 := by + rw [sq, mul_div_assoc] + gcongr + suffices (n : ℝ) ≥ 2 by linarith + exact_mod_cast h.two_le + grw [denom] + · apply le_of_eq + rw [← Real.rpow_natCast] + field_simp + rw [mul_div_assoc, ← Real.rpow_sub (mod_cast h.pos)] + norm_num + rw [Real.rpow_neg (Nat.cast_nonneg _)] + field + · exact div_pos (pow_pos (mod_cast h.pos) _) (by norm_num) + · apply mul_nonneg (Nat.cast_nonneg _) + suffices 1 ≤ (n : ℝ) by linarith + exact_mod_cast h.one_le + · positivity + +theorem E₁.nonneg : E₁ ≥ 0 := + tsum_nonneg E₁.summand_nonneg + +theorem E₁Λ.le_E₁p_add_E₁ {x : ℝ} (hx : 1 ≤ x) : + E₁Λ x ≤ E₁p x + E₁ := by + unfold E₁Λ E₁p + suffices ∑ d ∈ Ioc 0 ⌊x⌋₊, Λ d / d ≤ ∑ p ∈ Ioc 0 ⌊x⌋₊ with Nat.Prime p, log p / p + E₁ by linarith + simp_rw [vonMangoldt_apply, ite_div, zero_div, ← sum_filter, Chebyshev.sum_PrimePow_eq_sum_sum _ (by linarith)] + calc + _ = ∑ k ∈ Icc 1 ⌊log x / log 2⌋₊, ∑ p ∈ Ioc 0 ⌊x ^ (1 / (k : ℝ))⌋₊ with Nat.Prime p, log p / (p ^ k : ℕ) := by + refine sum_congr rfl fun k hk ↦ sum_congr rfl fun p hp ↦ ?_ + rw [Nat.Prime.pow_minFac (by simp_all) (by simp_all; linarith)] + _ ≤ ∑ k ∈ Icc 1 ⌊log x / log 2⌋₊, ∑ p ∈ Ioc 0 ⌊x⌋₊ with Nat.Prime p, log p / (p ^ k : ℕ) := by + gcongr with k hk + apply rpow_le_self_of_one_le hx + simp only [mem_Icc] at hk + exact div_le_one₀ (by norm_cast; linarith)|>.mpr (mod_cast hk.1) + _ ≤ ∑ k ∈ Icc 1 (max 1 ⌊log x / log 2⌋₊), ∑ p ∈ Ioc 0 ⌊x⌋₊ with Nat.Prime p, log p / (p ^ k : ℕ) := by + apply sum_le_sum_of_subset_of_nonneg + · gcongr + exact le_max_right .. + · exact fun _ _ _ ↦ sum_nonneg fun _ _ ↦ (by positivity) + _ = ∑ p ∈ Ioc 0 ⌊x⌋₊ with Nat.Prime p, (log p / p) + ∑ k ∈ Ioc 1 (max 1 ⌊log x / log 2⌋₊), ∑ p ∈ Ioc 0 ⌊x⌋₊ with Nat.Prime p, log p / (p ^ k : ℕ) := by + rw [← add_sum_Ioc_eq_sum_Icc (le_max_left ..)] + simp + _ ≤ _ := by + gcongr + rw [sum_comm] + conv => lhs; arg 2; ext p; arg 2; ext k; rw [← mul_one_div, Nat.cast_pow, ← one_div_pow] + simp_rw [← mul_sum] + calc + _ ≤ ∑ p ∈ Ioc 0 ⌊x⌋₊ with Nat.Prime p, log p / (p * (p - 1)) := by + gcongr with p hp + simp only [mem_filter, mem_Ioc] at hp + conv => rhs; rw [← mul_one_div] + gcongr + rw [(by rfl : Ioc 1 (max 1 ⌊log x / log 2⌋₊) = Ico 2 (max 1 ⌊log x / log 2⌋₊ + 1))] + grw [geom_sum_Ico_le_of_lt_one (by simp)] + · apply le_of_eq + have : (p : ℝ) ≠ 0 := by exact_mod_cast hp.1.1.ne.symm + field + · simpa using inv_lt_one_of_one_lt₀ (mod_cast hp.2.one_lt) + _ ≤ _ := by + rw [sum_filter] + exact E₁.summable.sum_le_tsum _ fun p hp ↦ E₁.summand_nonneg p + +theorem prime_log_div_bounded_error : + ∃ C > 0, ∀ x : ℝ, 1 ≤ x → + |∑ p ∈ Nat.primesLE ⌊x⌋₊, log p / p - log x| ≤ C := by + refine ⟨log 4 + 6 + E₁, by positivity [E₁.nonneg], fun x hx => ?_⟩ + rw [Nat.primesLE_eq_filter_Ioc_zero] + change |E₁p x| ≤ log 4 + 6 + E₁ + have hlog : 0 ≤ log 4 := by positivity + exact abs_le.mpr + ⟨by linarith [E₁Λ.le_E₁p_add_E₁ hx, E₁Λ.ge hx], + by linarith [E₁Λ.le hx, E₁p.le_E₁Λ x, E₁.nonneg]⟩ + +theorem prime_log_div_isBigO : + (fun x : ℝ => ∑ p ∈ Nat.primesLE ⌊x⌋₊, log p / p - log x) + =O[atTop] (fun _ => (1 : ℝ)) := by + obtain ⟨C, _, hC⟩ := prime_log_div_bounded_error + apply IsBigO.of_bound C + filter_upwards [eventually_ge_atTop (1 : ℝ)] with x hx + simpa only [Real.norm_eq_abs, norm_one, mul_one] using hC x hx + +end WeightedTorusJets.Mertens + +end + +end AnalyticAssemblyScope +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/EvalOneInvariantJetMonomial.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/EvalOneInvariantJetMonomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..57a6b18a00461272f0d108a52a0c1b8bf2c395ae --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/EvalOneInvariantJetMonomial.lean @@ -0,0 +1,32 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.InvariantJetMonomial + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +variable {R ι : Type*} [CommSemiring R] [Fintype ι] + +theorem eval_one_invariantJet_monomial (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) + (m : ι →₀ ℕ) (r : R) : + MvPolynomial.eval (fun _ => 1) (invariantJet c a (MvPolynomial.monomial m r)) = + ((∑ i, c 0 i * (m i : R)) ^ a 0 * + (∑ i, c 1 i * (m i : R)) ^ a 1 * + (∑ i, c 2 i * (m i : R)) ^ a 2) * r := by + rw [invariantJet_monomial, MvPolynomial.smul_eval, MvPolynomial.eval_monomial] + simp + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/FiniteTypeFieldModelEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FiniteTypeFieldModelEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..c8b2eca630fdc4be00c71ef02bc558ec80aba723 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FiniteTypeFieldModelEquiv.lean @@ -0,0 +1,524 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.LogarithmicForm + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section OriginalSourceGeometryOverlay +open Module CategoryTheory _root_.AlgebraicGeometry _root_.OAI.Erdos970.AlgebraicGeometry +open scoped BigOperators TensorProduct +noncomputable section +noncomputable section +namespace WeightedTorusJets.Geometry + +theorem finiteTypeFieldModel_isFractionRing + (k F : Type*) [CommRing k] [Field F] [Algebra k F] [Algebra.EssFiniteType k F] : + IsFractionRing (Algebra.EssFiniteType.subalgebra k F) F := by + apply IsFractionRing.of_field + intro z + obtain ⟨⟨a, s⟩, h⟩ := IsLocalization.surj (Algebra.EssFiniteType.submonoid k F) z + exact ⟨a, s, (eq_div_iff (IsLocalization.map_units F s).ne_zero).mpr h⟩ + +def finiteTypeFieldModelEquiv + (k F : Type*) [CommRing k] [Field F] [Algebra k F] [Algebra.EssFiniteType k F] : + F ≃ₐ[k] FractionRing (Algebra.EssFiniteType.subalgebra k F) := by + have : IsFractionRing (Algebra.EssFiniteType.subalgebra k F) F := + finiteTypeFieldModel_isFractionRing k F + exact (IsLocalization.algEquiv (nonZeroDivisors (Algebra.EssFiniteType.subalgebra k F)) + F (FractionRing (Algebra.EssFiniteType.subalgebra k F))).restrictScalars k + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +universe u + +theorem exists_normal_proper_model_of_essFiniteType_field + (k : Type u) (F : Type*) [Field k] [CharZero k] [Field F] + [Algebra k F] [Algebra.EssFiniteType k F] : + ∃ (N : Scheme.{u}) (hN : IsIntegral N), + let : IsIntegral N := hN + ∃ (p : N ⟶ Spec (CommRingCat.of k)), + IsLocallyNoetherian N ∧ (∀ x : N, IsIntegrallyClosed (N.presheaf.stalk x)) ∧ + LocallyOfFiniteType p ∧ UniversallyClosed p ∧ + (let : Algebra k N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + Nonempty (F →ₐ[k] N.functionField)) := by + have : Small.{u} (Algebra.EssFiniteType.subalgebra k F) := + Algebra.FiniteType.small (R := k) + have : Small.{u} F := small_of_surjective + (IsLocalization.mk'_surjective (S := F) (Algebra.EssFiniteType.submonoid k F)) + let e : Shrink.{u} F ≃ₐ[k] F := Shrink.algEquiv k F + have : Algebra.EssFiniteType k (Shrink.{u} F) := + (Algebra.EssFiniteType.iff_of_algEquiv e).mpr inferInstance + obtain ⟨N, hN, p, hnoeth, hnormal, hft, hclosed, ⟨φ⟩⟩ := + exists_normal_proper_model_of_finiteType_domain k + (Algebra.EssFiniteType.subalgebra k (Shrink.{u} F)) + have := hN + let : Algebra k N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + exact ⟨N, hN, p, hnoeth, hnormal, hft, hclosed, + ⟨φ.comp ((Geometry.finiteTypeFieldModelEquiv k (Shrink.{u} F)).toAlgHom.comp + e.symm.toAlgHom)⟩⟩ + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +theorem scheme_global_germ_isIntegral + {k : Type u} [CommRing k] {X : Scheme.{u}} + (p : X ⟶ Spec (CommRingCat.of k)) [UniversallyClosed p] + (x : X) (s : Γ(X, ⊤)) : + let : Algebra k (X.presheaf.stalk x) := schemeBaseStalkAlgebra p x + IsIntegral k (X.presheaf.germ ⊤ x (by simp) s) := by + let : Algebra k (X.presheaf.stalk x) := schemeBaseStalkAlgebra p x + have hIntegral : ((Scheme.ΓSpecIso (CommRingCat.of k)).inv ≫ p.appTop).hom.IsIntegral := by + apply RingHom.isIntegral_respectsIso.2 + (e := (Scheme.ΓSpecIso (CommRingCat.of k)).symm.commRingCatIsoToRingEquiv) + exact isIntegral_appTop_of_universallyClosed p + have h := (hIntegral s).map (X.presheaf.germ ⊤ x (by simp)).hom + rw [← schemeBaseToStalk_eq_global_germ p x] at h + exact h + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +universe u + +theorem isAlgebraic_of_logarithmicForm_eq_zero + {k F ι : Type*} + [Field k] [CharZero k] [Field F] [Algebra k F] [Algebra.EssFiniteType k F] + [Fintype ι] (c : ι → k) (hc : LinearIndependent ℚ c) + (f : ι → F) (hf : ∀ i, f i ≠ 0) (hform : logarithmicForm c f = 0) : + ∀ i, IsAlgebraic k (f i) := by + obtain ⟨N, hN, p, hnoeth, hnormal, hft, hclosed, ⟨φ⟩⟩ := + exists_normal_proper_model_of_essFiniteType_field k F + have := hN + have := hnoeth + have := hnormal + have := hft + have := hclosed + let : Algebra k N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + intro i + have hf' (j) : φ (f j) ≠ 0 := (map_ne_zero_iff φ φ.injective).mpr (hf j) + have hω : ∑ j, (algebraMap k F (c j) / f j) • + KaehlerDifferential.D k F (f j) = 0 := by + simpa only [logarithmicForm, div_eq_mul_inv] using hform + obtain ⟨s, _, hs⟩ := scheme_global_units_of_locallyOfFiniteType_log_form p c hc + (fun j => φ (f j)) hf' (logarithmic_relation_map_algHom φ c f hω) i + apply (isAlgebraic_algHom_iff φ φ.injective).mp + rw [← hs] + exact (scheme_global_germ_isIntegral p (genericPoint N) s).isAlgebraic + +end WeightedTorusJets.Geometry +namespace WeightedTorusJets.Geometry + +variable {K R : Type*} [CommRing K] [CommRing R] [Algebra K R] + +def derivationOnIdeal (D : Derivation K R R) (I : Ideal R) : I →ₗ[R] R ⧸ I where + toFun x := Ideal.Quotient.mk I (D x) + map_add' x y := by simp + map_smul' r x := by + change Ideal.Quotient.mk I (D (r * x.val)) = r • Ideal.Quotient.mk I (D x.val) + rw [D.leibniz, smul_eq_mul, smul_eq_mul, map_add, map_mul, map_mul] + rw [Ideal.Quotient.eq_zero_iff_mem.mpr x.property, zero_mul, add_zero] + rfl + +def derivationCotangent (D : Derivation K R R) (I : Ideal R) : + I.Cotangent →ₗ[R] R ⧸ I := + Ideal.Cotangent.lift (derivationOnIdeal D I) (by + intro x y + change Ideal.Quotient.mk I (D (x.val * y.val)) = 0 + rw [D.leibniz, smul_eq_mul, smul_eq_mul, map_add, map_mul, map_mul] + rw [Ideal.Quotient.eq_zero_iff_mem.mpr x.property, + Ideal.Quotient.eq_zero_iff_mem.mpr y.property] + simp) + +def derivationCotangentResidue (D : Derivation K R R) (I : Ideal R) : + I.Cotangent →ₗ[R ⧸ I] R ⧸ I where + toFun := derivationCotangent D I + map_add' := (derivationCotangent D I).map_add + map_smul' c x := by + obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective c + change derivationCotangent D I (r • x) = + (algebraMap R (R ⧸ I)) r • derivationCotangent D I x + rw [algebraMap_smul, map_smul] + +theorem independent_functionals_surjective {k V ι : Type*} [Field k] [AddCommGroup V] + [Module k V] [Finite ι] (f : ι → V →ₗ[k] k) (hf : LinearIndependent k f) : + Function.Surjective (LinearMap.pi f) := by + apply LinearMap.range_eq_top.mp + rw [← Submodule.span_eq (LinearMap.range (LinearMap.pi f))] + change Submodule.span k (Set.range (fun x i => f i x)) = ⊤ + apply span_flip_eq_top_iff_linearIndependent.mpr + exact hf.map' (LinearMap.ltoFun k V k k) (LinearMap.ker_eq_bot.mpr DFunLike.coe_injective) + +theorem exists_ideal_element_with_derivatives {ι : Type*} [Finite ι] + (I : Ideal R) [I.IsMaximal] (D : ι → Derivation K R R) + (hD : LinearIndependent (R ⧸ I) (fun i => derivationCotangentResidue (D i) I)) + (c : ι → R ⧸ I) : + ∃ x : I, ∀ i, Ideal.Quotient.mk I (D i x) = c i := by + let := Ideal.Quotient.field I + obtain ⟨y, hy⟩ := independent_functionals_surjective + (fun i => derivationCotangentResidue (D i) I) hD c + obtain ⟨x, rfl⟩ := I.toCotangent_surjective y + exact ⟨x, fun i => congrFun hy i⟩ + + + +variable {R ι : Type*} [CommSemiring R] [Fintype ι] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K ι T : Type*} [CommRing K] [CommRing T] [Fintype ι] + [Algebra K T] [Algebra (MvPolynomial ι K) T] [IsScalarTower K (MvPolynomial ι K) T] + +theorem invariantDerivation_X (c : ι → K) (i : ι) : + invariantDerivation c (MvPolynomial.X i) = c i • (MvPolynomial.X i : MvPolynomial ι K) := by + classical + simp [invariantDerivation, MvPolynomial.pderiv_X, Pi.single_apply] + +theorem localize_invariantDerivation_X (M : Submonoid (MvPolynomial ι K)) + [IsLocalization M T] (c : ι → K) (i : ι) : + localizeDerivation M (invariantDerivation c) + (algebraMap (MvPolynomial ι K) T (MvPolynomial.X i)) = + algebraMap K T (c i) * algebraMap (MvPolynomial ι K) T (MvPolynomial.X i) := by + rw [localizeDerivation_algebraMap, invariantDerivation_X, + MvPolynomial.smul_eq_C_mul, map_mul] + congr 1 + exact (IsScalarTower.algebraMap_apply K (MvPolynomial ι K) T (c i)).symm + +end WeightedTorusJets.Geometry +open scoped TensorProduct + +namespace WeightedTorusJets.Geometry + +variable {K A : Type*} [CommRing K] [CommRing A] [Algebra K A] + +noncomputable def derivationAmbientCovector (I : Ideal A) (D : Derivation K A A) : + (A ⧸ I) ⊗[A] Ω[A⁄K] →ₗ[A ⧸ I] A ⧸ I := + ((Algebra.linearMap A (A ⧸ I)).comp D.liftKaehlerDifferential).liftBaseChange (A ⧸ I) + +@[simp] +theorem derivationAmbientCovector_tmul_D (I : Ideal A) (D : Derivation K A A) (x : A) : + derivationAmbientCovector I D (1 ⊗ₜ[A] KaehlerDifferential.D K A x) = + Ideal.Quotient.mk I (D x) := by + simp [derivationAmbientCovector, Derivation.liftKaehlerDifferential_comp_D] + +theorem derivationAmbientCovector_conormal (I : Ideal A) (D : Derivation K A A) (x : I) : + (conormalDifferential (K := K) I).dualMap (derivationAmbientCovector I D) + (I.toCotangent x) = Ideal.Quotient.mk I (D x) := by + simp [LinearMap.dualMap_apply] + +theorem range_conormalDifferential (I : Ideal A) : + LinearMap.range (conormalDifferential (K := K) I) = + LinearMap.ker (KaehlerDifferential.mapBaseChange K A (A ⧸ I)) := by + apply Submodule.restrictScalars_injective A (A ⧸ I) _ + change LinearMap.range ((KaehlerDifferential.kerCotangentToTensor K A (A ⧸ I)).comp + (Ideal.Cotangent.equivOfEq I (RingHom.ker (algebraMap A (A ⧸ I))) + Ideal.mk_ker.symm).toLinearMap) = _ + rw [LinearMap.range_comp, LinearEquiv.range, Submodule.map_top] + exact KaehlerDifferential.range_kerCotangentToTensor K A (A ⧸ I) + Ideal.Quotient.mk_surjective + +noncomputable def residueTangentMap (I : Ideal A) : + Derivation K (A ⧸ I) (A ⧸ I) →ₗ[A ⧸ I] + Module.Dual (A ⧸ I) ((A ⧸ I) ⊗[A] Ω[A⁄K]) := + (KaehlerDifferential.mapBaseChange K A (A ⧸ I)).dualMap.comp + (KaehlerDifferential.linearMapEquivDerivation K (A ⧸ I)).symm.toLinearMap + +@[simp] +theorem residueTangentMap_tmul_D (I : Ideal A) + (D : Derivation K (A ⧸ I) (A ⧸ I)) (x : A) : + residueTangentMap I D (1 ⊗ₜ[A] KaehlerDifferential.D K A x) = + D (Ideal.Quotient.mk I x) := by + change D.liftKaehlerDifferential + (KaehlerDifferential.mapBaseChange K A (A ⧸ I) + (1 ⊗ₜ[A] KaehlerDifferential.D K A x)) = _ + simp [Derivation.liftKaehlerDifferential_comp_D] + +theorem ker_conormalDual_eq_range_residueTangent (I : Ideal A) [I.IsMaximal] : + LinearMap.ker (conormalDifferential (K := K) I).dualMap = + LinearMap.range (residueTangentMap (K := K) I) := by + let := Ideal.Quotient.field I + rw [residueTangentMap, LinearMap.range_comp, LinearEquiv.range, Submodule.map_top, + LinearMap.ker_dualMap_eq_dualAnnihilator_range, + LinearMap.range_dualMap_eq_dualAnnihilator_ker, range_conormalDifferential] + +noncomputable def normalQuotientEquivCotangentDual (I : Ideal A) [I.IsMaximal] + [Algebra.FormallySmooth K A] [Algebra.FormallySmooth K (A ⧸ I)] : + (Module.Dual (A ⧸ I) ((A ⧸ I) ⊗[A] Ω[A⁄K]) ⧸ + LinearMap.range (residueTangentMap (K := K) I)) ≃ₗ[A ⧸ I] + Module.Dual (A ⧸ I) I.Cotangent := by + letI := Ideal.Quotient.field I + exact (Submodule.quotEquivOfEq _ _ + (ker_conormalDual_eq_range_residueTangent (K := K) I).symm).trans + ((conormalDifferential (K := K) I).dualMap.quotKerEquivOfSurjective + (LinearMap.dualMap_surjective_of_injective (conormalDifferential_injective I))) + +@[simp] +theorem normalQuotientEquivCotangentDual_mk (I : Ideal A) [I.IsMaximal] + [Algebra.FormallySmooth K A] [Algebra.FormallySmooth K (A ⧸ I)] + (φ : Module.Dual (A ⧸ I) ((A ⧸ I) ⊗[A] Ω[A⁄K])) : + normalQuotientEquivCotangentDual (K := K) I (Submodule.Quotient.mk φ) = + (conormalDifferential (K := K) I).dualMap φ := by + simp [normalQuotientEquivCotangentDual] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K S ι : Type*} [CommRing K] [CommRing S] + [Algebra K S] [Algebra (MvPolynomial ι K) S] + [IsScalarTower K (MvPolynomial ι K) S] + [Algebra.FormallyEtale (MvPolynomial ι K) S] + +noncomputable def localizedPolynomialKaehlerBasis : Module.Basis ι S Ω[S⁄K] := + ((KaehlerDifferential.mvPolynomialBasis K ι).baseChange S).map + (KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale K (MvPolynomial ι K) S) + +@[simp] +theorem localizedPolynomialKaehlerBasis_apply (i : ι) : + localizedPolynomialKaehlerBasis (K := K) (S := S) i = + KaehlerDifferential.D K S (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)) := by + simp [localizedPolynomialKaehlerBasis, KaehlerDifferential.mvPolynomialBasis_apply] + +noncomputable def logarithmicKaehlerBasis + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) : + Module.Basis ι S Ω[S⁄K] := + localizedPolynomialKaehlerBasis.unitsSMul (fun i => (hx i).unit⁻¹) + +@[simp] +theorem logarithmicKaehlerBasis_apply + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) (i : ι) : + logarithmicKaehlerBasis hx i = ((hx i).unit⁻¹ : Sˣ) • + KaehlerDifferential.D K S (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)) := by + rw [logarithmicKaehlerBasis, Module.Basis.unitsSMul_apply, + localizedPolynomialKaehlerBasis_apply] + +variable {L : Type*} [Field L] [Algebra S L] [Fintype ι] + +noncomputable def logarithmicAmbientEquiv + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) : + Module.Dual L (L ⊗[S] Ω[S⁄K]) ≃ₗ[L] (ι → L) := by + classical + exact ((logarithmicKaehlerBasis hx).baseChange L).dualBasis.equivFun + +theorem logarithmicAmbientEquiv_apply + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) + (φ : Module.Dual L (L ⊗[S] Ω[S⁄K])) (i : ι) : + logarithmicAmbientEquiv hx φ i = + (algebraMap S L (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)))⁻¹ * + φ (1 ⊗ₜ[S] KaehlerDifferential.D K S + (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) := by + simp only [logarithmicAmbientEquiv, Module.Basis.dualBasis_equivFun, + Module.Basis.baseChange_apply, logarithmicKaehlerBasis_apply] + rw [Units.smul_def, TensorProduct.tmul_smul, LinearMap.map_smul_of_tower, + Algebra.smul_def] + congr 1 + rw [map_units_inv, (hx i).unit_spec] + +variable {ι k F : Type*} [Field k] [Field F] [Algebra k F] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry +attribute [local instance] Ideal.Quotient.field +variable {K S ι : Type*} [Field K] [CommRing S] [Fintype ι] + [Algebra K S] [Algebra (MvPolynomial ι K) S] + [IsScalarTower K (MvPolynomial ι K) S] + [Algebra.FormallyEtale (MvPolynomial ι K) S] + +theorem logarithmicAmbientEquiv_residueTangentMap (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) + (D : Derivation K (S ⧸ I) (S ⧸ I)) : + logarithmicAmbientEquiv hx (residueTangentMap I D) = + logarithmicTangentMap (fun i => Ideal.Quotient.mk I + (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) D := by + ext i + rw [logarithmicAmbientEquiv_apply, residueTangentMap_tmul_D] + rfl + +theorem logarithmicAmbientEquiv_invariantDerivation (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) + (D : Derivation K S S) (a : ι → S) + (ha : ∀ i, D (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)) = + a i * algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)) : + logarithmicAmbientEquiv hx (derivationAmbientCovector I D) = + fun i => Ideal.Quotient.mk I (a i) := by + ext i + rw [logarithmicAmbientEquiv_apply, derivationAmbientCovector_tmul_D, ha, map_mul] + have hi : Ideal.Quotient.mk I + (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)) ≠ 0 := + ((hx i).map (Ideal.Quotient.mk I)).ne_zero + change (Ideal.Quotient.mk I + (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)))⁻¹ * + (Ideal.Quotient.mk I (a i) * Ideal.Quotient.mk I + (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) = _ + rw [mul_left_comm, inv_mul_cancel₀ hi, mul_one] + +theorem map_range_residueTangent_logarithmic (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) : + (LinearMap.range (residueTangentMap (K := K) I)).map + (logarithmicAmbientEquiv hx).toLinearMap = + LinearMap.range (logarithmicTangentMap (k := K) (fun i => Ideal.Quotient.mk I + (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)))) := by + rw [← LinearMap.range_comp] + congr 1 + ext D i + exact congrFun (logarithmicAmbientEquiv_residueTangentMap I hx D) i + +noncomputable def coordinateNormalEquivCotangentDual [PerfectField K] + [Algebra.EssFiniteType K S] (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) : + ((ι → S ⧸ I) ⧸ LinearMap.range (logarithmicTangentMap (k := K) + (fun i => Ideal.Quotient.mk I (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))))) + ≃ₗ[S ⧸ I] Module.Dual (S ⧸ I) I.Cotangent := by + have : Algebra.FormallySmooth K S := Algebra.FormallySmooth.comp K (MvPolynomial ι K) S + have : Algebra.FormallySmooth K (S ⧸ I) := inferInstance + exact (Submodule.Quotient.equiv _ _ (logarithmicAmbientEquiv hx) + (map_range_residueTangent_logarithmic I hx)).symm.trans + (normalQuotientEquivCotangentDual I) + +theorem coordinateNormalEquivCotangentDual_mk [PerfectField K] + [Algebra.EssFiniteType K S] (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) + (φ : Module.Dual (S ⧸ I) ((S ⧸ I) ⊗[S] Ω[S⁄K])) : + coordinateNormalEquivCotangentDual I hx + (Submodule.Quotient.mk (logarithmicAmbientEquiv hx φ)) = + (conormalDifferential (K := K) I).dualMap φ := by + simp [coordinateNormalEquivCotangentDual, Submodule.Quotient.equiv_symm] + +theorem coordinateNormal_invariant_pairing [PerfectField K] + [Algebra.EssFiniteType K S] (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : ι, IsUnit (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i))) + (D : Derivation K S S) (a : ι → S) + (ha : ∀ i, D (algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)) = + a i * algebraMap (MvPolynomial ι K) S (MvPolynomial.X i)) (x : I) : + coordinateNormalEquivCotangentDual I hx + (Submodule.Quotient.mk (fun i => Ideal.Quotient.mk I (a i))) (I.toCotangent x) = + Ideal.Quotient.mk I (D x) := by + rw [← logarithmicAmbientEquiv_invariantDerivation I hx D a ha, + coordinateNormalEquivCotangentDual_mk, derivationAmbientCovector_conormal] + +end WeightedTorusJets.Geometry + +open Module + +namespace WeightedTorusJets.Geometry + +theorem exists_basis_ker_dotProduct_algebraMap {K L n ι : Type*} + [Field K] [Field L] [Algebra K L] [Fintype n] [DecidableEq n] [Fintype ι] + (c : n → K) (hc : c ≠ 0) + (b : Basis ι K (LinearMap.ker (dotProductEquiv K n c))) : + ∃ bL : Basis ι L (LinearMap.ker (dotProductEquiv L n (algebraMap K L ∘ c))), + ∀ i, (bL i : n → L) = algebraMap K L ∘ (b i : n → K) := by + let ωK := dotProductEquiv K n c + let ωL := dotProductEquiv L n (algebraMap K L ∘ c) + have hcL : algebraMap K L ∘ c ≠ 0 := + ((algebraMap K L).injective.comp_left.ne_iff' (by ext; simp)).mpr hc + have hωK : ωK ≠ 0 := (dotProductEquiv K n).map_ne_zero_iff.mpr hc + have hωL : ωL ≠ 0 := (dotProductEquiv L n).map_ne_zero_iff.mpr hcL + have hmem (i : ι) : algebraMap K L ∘ (b i : n → K) ∈ LinearMap.ker ωL := by + change (algebraMap K L ∘ c) ⬝ᵥ (algebraMap K L ∘ (b i : n → K)) = 0 + rw [← (algebraMap K L).map_dotProduct] + have hi : c ⬝ᵥ (b i : n → K) = 0 := (b i).property + rw [hi, map_zero] + let w (i : ι) : LinearMap.ker ωL := ⟨algebraMap K L ∘ (b i : n → K), hmem i⟩ + have hbK : LinearIndependent K (fun i => (b i : n → K)) := + b.linearIndependent.map' (LinearMap.ker ωK).subtype (Submodule.ker_subtype _) + have hbL : LinearIndependent L (fun i => algebraMap K L ∘ (b i : n → K)) := + linearIndependent_algebraMap_comp_iff.mpr hbK + have hw : LinearIndependent L w := + LinearIndependent.of_comp (LinearMap.ker ωL).subtype hbL + have hdK := Module.Dual.finrank_ker_add_one_of_ne_zero hωK + have hdL := Module.Dual.finrank_ker_add_one_of_ne_zero hωL + rw [finrank_pi] at hdK hdL + have hd : finrank L (LinearMap.ker ωL) = finrank K (LinearMap.ker ωK) := + Nat.add_right_cancel (hdL.trans hdK.symm) + have hcard : Fintype.card ι = finrank L (LinearMap.ker ωL) := by + rw [hd, finrank_eq_card_basis b] + let bL := Basis.mk hw (hw.span_eq_top_of_card_eq_finrank' hcard).ge + refine ⟨bL, fun i => ?_⟩ + change (Basis.mk hw _ i : n → L) = _ + rw [Basis.mk_apply] + + + +theorem finrank_normal_image_at_point + {K V : Type*} [Field K] [AddCommGroup V] [Module K V] + (W : Submodule K V) : + Module.finrank K (LinearMap.range ((⊥ : Submodule K V).mkQ.domRestrict W)) = + Module.finrank K W := by + apply LinearMap.finrank_range_of_inj + have hi : Function.Injective (⊥ : Submodule K V).mkQ := by + rw [← LinearMap.ker_eq_bot, Submodule.ker_mkQ] + exact hi.comp W.injective_subtype + +theorem exists_independent_image_finset + {K U V ι : Type*} [Field K] [AddCommGroup U] [Module K U] + [AddCommGroup V] [Module K V] [FiniteDimensional K U] + (b : Module.Basis ι K U) (f : U →ₗ[K] V) : + ∃ I : Finset ι, I.card = Module.finrank K (LinearMap.range f) ∧ + LinearIndepOn K (fun i => f (b i)) (I : Set ι) := by + classical + have hs : Submodule.span K (Set.range (f.rangeRestrict ∘ b)) = ⊤ := by + rw [Set.range_comp, ← Submodule.map_span, b.span_eq, Submodule.map_top, + LinearMap.range_rangeRestrict] + obtain ⟨κ, a, ha, hspan, hli⟩ := exists_linearIndependent' K (f.rangeRestrict ∘ b) + have : Finite κ := hli.finite + let := Fintype.ofFinite κ + have hcard : Fintype.card κ = Module.finrank K (LinearMap.range f) := by + rw [← finrank_span_eq_card hli, hspan, hs, finrank_top] + refine ⟨Finset.univ.map ⟨a, ha⟩, by simpa using hcard, ?_⟩ + have hi := hli.map' (LinearMap.range f).subtype (Submodule.ker_subtype _) + rw [Finset.coe_map, Finset.coe_univ, Set.image_univ] + exact (linearIndepOn_range_iff ha _).mpr hi + +theorem finrank_normal_image_eq_min + {K V : Type*} [Field K] [AddCommGroup V] [Module K V] [FiniteDimensional K V] + (ω : V →ₗ[K] K) (hω : ω ≠ 0) (hdim : Module.finrank K V = 4) + (T : Submodule K V) (hT : T = ⊥ ∨ ¬ T ≤ LinearMap.ker ω) : + Module.finrank K (LinearMap.range (T.mkQ.domRestrict (LinearMap.ker ω))) = + min (4 - Module.finrank K T) 3 := by + have hker : Module.finrank K (LinearMap.ker ω) = 3 := by + have h := Module.Dual.finrank_ker_add_one_of_ne_zero hω + omega + rcases hT with rfl | hT + · rw [finrank_normal_image_at_point, hker] + simp + · have hr := finrank_normal_image_of_not_le ω T hT + rw [hdim] at hr + have hle := (T.mkQ.domRestrict (LinearMap.ker ω)).finrank_range_le + rw [hker, hr] at hle + rw [hr, Nat.min_eq_left hle] + +theorem exists_independent_normal_finset + {K V : Type*} [Field K] [AddCommGroup V] [Module K V] [FiniteDimensional K V] + (ω : V →ₗ[K] K) (hω : ω ≠ 0) (hdim : Module.finrank K V = 4) + (T : Submodule K V) (hT : T = ⊥ ∨ ¬ T ≤ LinearMap.ker ω) + (b : Module.Basis (Fin 3) K (LinearMap.ker ω)) : + ∃ I : Finset (Fin 3), I.card = min (4 - Module.finrank K T) 3 ∧ + LinearIndepOn K (fun i => T.mkQ (b i)) (I : Set (Fin 3)) := by + obtain ⟨I, hI, hind⟩ := + exists_independent_image_finset b (T.mkQ.domRestrict (LinearMap.ker ω)) + refine ⟨I, ?_, hind⟩ + rw [hI, finrank_normal_image_eq_min ω hω hdim T hT] + +end WeightedTorusJets.Geometry + +end +end +end OriginalSourceGeometryOverlay +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankDegreePiecePosPrimeVariableNotMem.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankDegreePiecePosPrimeVariableNotMem.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1e9e7cc6edd257ca65a380b91d477be987f9ee0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankDegreePiecePosPrimeVariableNotMem.lean @@ -0,0 +1,72 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeMapEval +import OAI.NumberTheory.Jacobsthal.Siegel.HilbertSeries + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial + +variable {K σ : Type*} [Field K] [Finite σ] + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem finrank_degreePiece_pos_of_prime_variable_not_mem + (I : Ideal (MvPolynomial σ K)) (hprime : I.IsPrime) + {i : σ} (hi : X i ∉ I) (n : ℕ) : + 0 < Module.finrank K (degreePiece I n) := by + apply Module.finrank_pos_iff_exists_ne_zero.mpr + refine ⟨⟨Ideal.Quotient.mk I (X i ^ n), X i ^ n, isHomogeneous_X_pow i n, rfl⟩, ?_⟩ + intro hzero + exact hi (hprime.mem_of_pow_mem n + (Ideal.Quotient.eq_zero_iff_mem.mp (congrArg Subtype.val hzero))) + +theorem hilbertPolynomial_ne_zero_of_prime_variable_not_mem + (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) (hprime : I.IsPrime) + (hvars : ∃ i : σ, X i ∉ I) : hilbertPolynomial I hI ≠ 0 := by + obtain ⟨i, hi⟩ := hvars + obtain ⟨N, hN⟩ := hilbertPolynomial_spec I hI + intro hzero + have h := hN (N + 1) (by omega) + rw [hzero, Polynomial.eval_zero] at h + have hpos := finrank_degreePiece_pos_of_prime_variable_not_mem I hprime hi (N + 1) + exact (Nat.ne_of_gt hpos) (by exact_mod_cast h) + +theorem projectiveDegree_pos_of_prime_variable_not_mem + (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) (hprime : I.IsPrime) + (hvars : ∃ i : σ, X i ∉ I) : 0 < projectiveDegree I hI := + (projectiveDegree_pos_iff I hI).mpr + (hilbertPolynomial_ne_zero_of_prime_variable_not_mem I hI hprime hvars) + +end WeightedTorusJets.Geometry.GradedQuotient + +namespace WeightedTorusJets.Geometry.GradedQuotient +open MvPolynomial + +theorem cone_projectiveDegree_pos + {K σ : Type*} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + 0 < projectiveDegree (coneIdeal p) (coneIdeal_isHomogeneous p) := + projectiveDegree_pos_of_prime_variable_not_mem + (coneIdeal p) (coneIdeal_isHomogeneous p) (coneIdeal_isPrime p) + ⟨none, X_none_not_mem_coneIdeal p⟩ + +end WeightedTorusJets.Geometry.GradedQuotient + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankDerivationCardTranscendenceBasis.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankDerivationCardTranscendenceBasis.lean new file mode 100644 index 0000000000000000000000000000000000000000..54b695f1ab2caab3ceb11167078b91ff4ea29524 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankDerivationCardTranscendenceBasis.lean @@ -0,0 +1,319 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.CoordinateLocalizedPrime +import OAI.NumberTheory.Jacobsthal.Siegel.LinearShearHom + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +open Module +open scoped RatFunc + +namespace WeightedTorusJets.Geometry + +theorem finrank_derivation_eq_card_transcendenceBasis {K F ι : Type*} + [Field K] [CharZero K] [Field F] [Algebra K F] [Fintype ι] + (v : ι → F) (hv : IsTranscendenceBasis K v) : + finrank F (Derivation K F F) = Fintype.card ι := by + classical + let P := MvPolynomial ι K + let : Algebra P F := (MvPolynomial.aeval v).toRingHom.toAlgebra + have : IsScalarTower K P F := IsScalarTower.of_algHom (MvPolynomial.aeval v) + have : FaithfulSMul P F := + (faithfulSMul_iff_algebraMap_injective P F).mpr hv.1 + have : Algebra.IsAlgebraic (Algebra.adjoin K (Set.range v)) F := hv.isAlgebraic + have : Algebra.IsAlgebraic P F := + Algebra.IsAlgebraic.of_ringHom_of_comp_eq hv.1.aevalEquiv (RingHom.id F) + hv.1.aevalEquiv.surjective Function.injective_id (by + apply RingHom.ext + intro p + exact hv.1.algebraMap_aevalEquiv p) + let E := FractionRing P + let := FractionRing.liftAlgebra P F + have : Algebra.IsAlgebraic E F := IsFractionRing.comap_isAlgebraic_iff.mp ‹_› + have : Algebra.FormallyEtale E F := Algebra.FormallyEtale.of_isSeparable E F + have : Algebra.FormallyEtale P E := + Algebra.FormallyEtale.of_isLocalization (nonZeroDivisors P) + have : Algebra.FormallyEtale P F := Algebra.FormallyEtale.comp P E F + let b : Basis ι F Ω[F⁄K] := ((KaehlerDifferential.mvPolynomialBasis K ι).baseChange F).map + (KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale K P F) + exact finrank_eq_card_basis + (b.dualBasis.map (KaehlerDifferential.linearMapEquivDerivation K F (M := F))) + +theorem finrank_derivation_eq_trdeg_toENat {K F : Type*} + [Field K] [CharZero K] [Field F] [Algebra K F] + (hfin : Algebra.trdeg K F < Cardinal.aleph0) : + (finrank F (Derivation K F F) : ℕ∞) = (Algebra.trdeg K F).toENat := by + classical + obtain ⟨s, hs⟩ := exists_isTranscendenceBasis K F + have : Finite s := Cardinal.lt_aleph0_iff_finite.mp + (hs.cardinalMk_eq_trdeg.trans_lt hfin) + let := Fintype.ofFinite s + rw [finrank_derivation_eq_card_transcendenceBasis _ hs, ← hs.cardinalMk_eq_trdeg] + simp + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +theorem finiteType_dimension_trdeg {K A : Type*} [Field K] + [CommRing A] [IsDomain A] [Algebra K A] [Algebra.FiniteType K A] : + ∃ n : ℕ, ringKrullDim A = (n : WithBot ℕ∞) ∧ Algebra.trdeg K A = n := by + obtain ⟨n, g, hinj, hint⟩ := exists_integral_inj_algHom_of_fg K A + let : Algebra (MvPolynomial (Fin n) K) A := g.toRingHom.toAlgebra + let : Algebra.IsIntegral (MvPolynomial (Fin n) K) A := ⟨hint⟩ + let : FaithfulSMul (MvPolynomial (Fin n) K) A := + (faithfulSMul_iff_algebraMap_injective _ _).mpr hinj + refine ⟨n, ?_, ?_⟩ + · rw [Geometry.ringKrullDim_eq_of_integral_faithful_goingDown + (R := MvPolynomial (Fin n) K)] + simp [MvPolynomial.ringKrullDim_of_isNoetherianRing_of_finite, + ringKrullDim_eq_zero_of_field] + · have hz : Algebra.trdeg (MvPolynomial (Fin n) K) A = 0 := + trdeg_eq_zero_iff.mpr inferInstance + have h := lift_trdeg_add_eq K (MvPolynomial (Fin n) K) A + simpa [hz, MvPolynomial.trdeg_of_isDomain] using h.symm + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +theorem ringKrullDim_eq_finrank_derivation {K A F : Type*} + [Field K] [CharZero K] [CommRing A] [IsDomain A] [Algebra K A] + [Algebra.FiniteType K A] [Field F] [Algebra K F] [Algebra A F] + [IsScalarTower K A F] [IsFractionRing A F] : + ringKrullDim A = (finrank F (Derivation K F F) : WithBot ℕ∞) := by + obtain ⟨n, hdim, htrdeg⟩ := WeightedTorusJets.finiteType_dimension_trdeg + (K := K) (A := A) + let : Algebra.IsAlgebraic A F := IsLocalization.isAlgebraic F (nonZeroDivisors A) + have hz : Algebra.trdeg A F = 0 := trdeg_eq_zero_iff.mpr inferInstance + have hF : Algebra.trdeg K F = n := by + simpa [htrdeg, hz] using (lift_trdeg_add_eq K A F).symm + have hfin : Algebra.trdeg K F < Cardinal.aleph0 := by + rw [hF] + exact Cardinal.natCast_lt_aleph0 + have hder : finrank F (Derivation K F F) = n := by + simpa [hF] using finrank_derivation_eq_trdeg_toENat hfin + rw [hder] + exact hdim + + + +theorem comap_aeval_eq_bot_of_independent_quotient + {K R σ : Type*} [Field K] [CommRing R] [Algebra K R] + (I : Ideal R) (x : σ → R) + (hx : AlgebraicIndependent K (fun i => Ideal.Quotient.mk I (x i))) : + I.comap (MvPolynomial.aeval (R := K) x).toRingHom = ⊥ := by + apply bot_unique + intro p hp + apply hx.eq_zero_of_aeval_eq_zero p + have he := MvPolynomial.comp_aeval_apply (f := x) (φ := Ideal.Quotient.mkₐ K I) (p := p) + simp only [Ideal.Quotient.mkₐ_eq_mk] at he + rw [← he] + exact Ideal.Quotient.eq_zero_iff_mem.mpr hp + + + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +end WeightedTorusJets.Geometry + +noncomputable section +open scoped BigOperators +open MvPolynomial + +namespace WeightedTorusJets.Geometry + +theorem coordinateSplit_height + {K σ : Type*} [CommRing K] (s : Set σ) (p : Ideal (MvPolynomial σ K)) : + (p.comap (coordinateSplit s).symm.toRingHom).height = p.height := + by + exact RingEquiv.height_comap (coordinateSplit (K := K) s).symm.toRingEquiv p + +attribute [local instance] MvPolynomial.algebraMvPolynomial in + +theorem coordinateSplit_localized_mem_minimalPrimes + {K σ : Type*} [Field K] (s : Set σ) (I p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (hp : p ∈ I.minimalPrimes) + (hs : AlgebraicIndependent K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (X i)))) : + ((p.comap (coordinateSplit s).symm.toRingHom).map + (MvPolynomial.map (algebraMap (MvPolynomial s K) (FractionRing (MvPolynomial s K))))) ∈ + ((I.comap (coordinateSplit s).symm.toRingHom).map + (MvPolynomial.map (algebraMap (MvPolynomial s K) (FractionRing (MvPolynomial s K))))).minimalPrimes := by + let B := MvPolynomial s K + let F := FractionRing B + let A := MvPolynomial (sᶜ : Set σ) B + let A' := MvPolynomial (sᶜ : Set σ) F + let p' : Ideal A := p.comap (coordinateSplit s).symm.toRingHom + let I' : Ideal A := I.comap (coordinateSplit s).symm.toRingHom + let M : Submonoid A := (nonZeroDivisors B).map MvPolynomial.C + have hp' : p' ∈ I'.minimalPrimes := + Ideal.minimalPrimes_comap_of_surjective (coordinateSplit (K := K) s).symm.surjective hp + have hcoeff : p'.comap MvPolynomial.C = ⊥ := + coordinateSplit_comap_coefficients_eq_bot_of_fractionField s p hs + have hdisj : Disjoint (M : Set A) (p' : Set A) := by + apply Set.disjoint_left.mpr + rintro _ ⟨b, hb, rfl⟩ hbp + have hz : b = 0 := by + have hmem : b ∈ p'.comap MvPolynomial.C := hbp + simpa [hcoeff] using hmem + exact (mem_nonZeroDivisors_iff_ne_zero.mp hb) hz + change p'.map (algebraMap A A') ∈ (I'.map (algebraMap A A')).minimalPrimes + rw [IsLocalization.minimalPrimes_map M] + change (p'.map (algebraMap A A')).under A ∈ I'.minimalPrimes + rw [IsLocalization.under_map_of_isPrime_disjoint M A' (show p'.IsPrime from inferInstance) hdisj] + exact hp' + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K : Type*} [Field K] + +theorem mvPolynomial_height_eq_card_iff_isMaximal {σ : Type*} [Fintype σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + p.height = Fintype.card σ ↔ p.IsMaximal := by + constructor + · intro hp + have : FiniteRingKrullDim (MvPolynomial σ K) := by + refine finiteRingKrullDim_iff_ne_bot_and_top.mpr ⟨by simp, ?_⟩ + rw [MvPolynomial.ringKrullDim_of_isNoetherianRing_of_finite, + ringKrullDim_eq_zero_of_field, zero_add] + intro htop + exact ENat.natCast_ne_top (Nat.card σ) (WithBot.coe_injective htop) + apply Ideal.isMaximal_of_height_eq_ringKrullDim + simp [hp] + · intro hp + have := hp + exact maximal_mvPolynomial_height p + + + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open scoped AlgebraMonoidAlgebra + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem coordinateLocalizedPrime_isPrime {K σ : Type*} [Field K] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (hs : AlgebraicIndependent K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i)))) : + (coordinateLocalizedPrime s p).IsPrime := by + exact (coefficient_localization_prime_height (F := FractionRing (MvPolynomial s K)) + (p.comap (coordinateSplit (K := K) s).symm.toRingHom) + (coordinateSplit_comap_coefficients_eq_bot_of_fractionField s p hs)).1 + +end WeightedTorusJets.Geometry +namespace WeightedTorusJets + +theorem trdeg_eq_of_integral_polynomial_base {K A : Type*} [Field K] + [CommRing A] [IsDomain A] [Algebra K A] (n : ℕ) + (g : MvPolynomial (Fin n) K →ₐ[K] A) + (hinj : Function.Injective g) (hint : g.IsIntegral) : + Algebra.trdeg K A = n := by + let : Algebra (MvPolynomial (Fin n) K) A := g.toRingHom.toAlgebra + let : Algebra.IsIntegral (MvPolynomial (Fin n) K) A := ⟨hint⟩ + let : FaithfulSMul (MvPolynomial (Fin n) K) A := + (faithfulSMul_iff_algebraMap_injective _ _).mpr hinj + have hz : Algebra.trdeg (MvPolynomial (Fin n) K) A = 0 := + trdeg_eq_zero + have h := lift_trdeg_add_eq K (MvPolynomial (Fin n) K) A + simpa [hz, MvPolynomial.trdeg_of_isDomain] using h.symm + +theorem fractionField_trdeg_eq_nat {K A F : Type*} [Field K] + [CommRing A] [IsDomain A] [Algebra K A] [Field F] + [Algebra K F] [Algebra A F] [IsScalarTower K A F] [IsFractionRing A F] + (n : ℕ) (h : Algebra.trdeg K A = n) : Algebra.trdeg K F = n := by + let : Algebra.IsAlgebraic A F := IsLocalization.isAlgebraic F (nonZeroDivisors A) + have hz : Algebra.trdeg A F = 0 := trdeg_eq_zero + have htower := lift_trdeg_add_eq K A F + simpa [h, hz] using htower.symm + +end WeightedTorusJets +namespace WeightedTorusJets.Geometry + +theorem polynomial_prime_height_add_quotient_dim_of_finite + {K σ : Type*} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + (p.height : WithBot ℕ∞) + ringKrullDim (MvPolynomial σ K ⧸ p) = Nat.card σ := by + obtain ⟨t, ht, hmax, _, hheight, _⟩ := exists_coordinate_localization p + obtain ⟨d, hdim, htr⟩ := WeightedTorusJets.finiteType_dimension_trdeg + (K := K) (A := MvPolynomial σ K ⧸ p) + have hF : Algebra.trdeg K (FractionRing (MvPolynomial σ K ⧸ p)) = d := + WeightedTorusJets.fractionField_trdeg_eq_nat d htr + have hcard : Nat.card t = d := by + have h := congrArg Cardinal.toNat ht.lift_cardinalMk_eq_trdeg + simpa [Nat.card, hF] using h + rw [← hheight, hdim, ← hcard] + have hsum : Nat.card (tᶜ : Set σ) + Nat.card t = Nat.card σ := by + simpa only [Nat.card_coe_set_eq] using Set.ncard_compl_add_ncard t + exact_mod_cast hsum + + + +variable {K σ : Type*} [Field K] [Finite σ] + +theorem polynomial_normalization_quotient_dimension_finite {s : ℕ} + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (g : MvPolynomial (Fin s) K →ₐ[K] MvPolynomial σ K ⧸ p) + (hg : Function.Injective g) (hgi : g.IsIntegral) : + ringKrullDim (MvPolynomial σ K ⧸ p) = (s : WithBot ℕ∞) := by + obtain ⟨d, hdim, htr⟩ := WeightedTorusJets.finiteType_dimension_trdeg + (K := K) (A := MvPolynomial σ K ⧸ p) + have hs := WeightedTorusJets.trdeg_eq_of_integral_polynomial_base s g hg hgi + have hd : d = s := by exact_mod_cast htr.symm.trans hs + simpa only [hd] using hdim + +theorem polynomial_normalization_count_add_height_finite {s : ℕ} + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (g : MvPolynomial (Fin s) K →ₐ[K] MvPolynomial σ K ⧸ p) + (hg : Function.Injective g) (hgi : g.IsIntegral) : + (s : ℕ∞) + p.height = Nat.card σ := by + have h := polynomial_prime_height_add_quotient_dim_of_finite (K := K) p + rw [polynomial_normalization_quotient_dimension_finite p g hg hgi] at h + have hh : p.height + (s : ℕ∞) = Nat.card σ := by exact_mod_cast h + simpa only [add_comm] using hh + +theorem polynomial_normalization_count_le_finite {s : ℕ} + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (g : MvPolynomial (Fin s) K →ₐ[K] MvPolynomial σ K ⧸ p) + (hg : Function.Injective g) (hgi : g.IsIntegral) : s ≤ Nat.card σ := by + have h := polynomial_normalization_count_add_height_finite p g hg hgi + have hs : (s : ℕ∞) ≤ Nat.card σ := by rw [← h]; exact le_self_add + exact_mod_cast hs + +theorem polynomial_normalization_height_eq_sub_finite {s : ℕ} + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (g : MvPolynomial (Fin s) K →ₐ[K] MvPolynomial σ K ⧸ p) + (hg : Function.Injective g) (hgi : g.IsIntegral) : p.height = (Nat.card σ - s : ℕ) := by + have h := polynomial_normalization_count_add_height_finite p g hg hgi + have hs := polynomial_normalization_count_le_finite p g hg hgi + have hn : (Nat.card σ : ℕ∞) = (s : ℕ∞) + ((Nat.card σ - s : ℕ) : ℕ∞) := by + rw [← Nat.cast_add, Nat.add_sub_of_le hs] + rw [hn] at h + exact ENat.add_right_injective_of_ne_top (by simp : (s : ℕ∞) ≠ ⊤) h + + +end WeightedTorusJets.Geometry + +end +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankSpanAlgebraMapImage.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankSpanAlgebraMapImage.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9dafed6b7ecde1ba0c68a64f37b036f7bb6cd26 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FinrankSpanAlgebraMapImage.lean @@ -0,0 +1,103 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.EvalOneInvariantJetMonomial +import OAI.NumberTheory.Jacobsthal.Siegel.GreedyPivots + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open Module Submodule + +namespace WeightedTorusJets.Geometry + +theorem finrank_span_algebraMap_image {K L n : Type*} [Field K] [Field L] + [Algebra K L] [Fintype n] (s : Set (n → K)) : + finrank L (span L ((fun v : n → K => algebraMap K L ∘ v) '' s)) = + finrank K (span K s) := by + obtain ⟨b, _, hbspan, hbind⟩ := Submodule.exists_fun_fin_finrank_span_eq K s + have hbL : LinearIndependent L (fun i => algebraMap K L ∘ b i) := + linearIndependent_algebraMap_comp_iff.mpr hbind + let φ := Pi.algebraMap n K L + have hmap := congrArg (fun p : Submodule K (n → K) => p.map φ) hbspan + simp only [Submodule.map_span, ← Set.range_comp] at hmap + have hspan := congrArg (fun p : Submodule K (n → L) => span L (p : Set (n → L))) hmap + simp only [Submodule.span_span_of_tower] at hspan + change span L (Set.range (fun i => algebraMap K L ∘ b i)) = + span L ((fun v : n → K => algebraMap K L ∘ v) '' s) at hspan + rw [← hspan, finrank_span_eq_card hbL, Fintype.card_fin] + + + +theorem eval_source_jet_monomial_eq_map_row {K : Type*} [Field K] + (φ : K →+* ℂ) (u : Fin 4 → K) (σ τ : K →+* K) + (n : Fin 4 → ℕ) (a : Fin 3 → ℕ) : + MvPolynomial.eval (fun _ => 1) + (invariantJet (fun j i => φ (![u, (fun i => σ (u i)), + (fun i => (σ.comp τ) (u i))] j i)) a + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm n) 1)) = + φ ((∑ i, (n i : K) * u i) ^ a 0 * + σ (∑ i, (n i : K) * u i) ^ a 1 * + (σ.comp τ) (∑ i, (n i : K) * u i) ^ a 2) := by + simp [eval_one_invariantJet_monomial, map_sum, mul_comm] + +theorem finrank_span_source_jet_rows_eq {K κ : Type*} [Field K] [Fintype κ] + (φ : K →+* ℂ) (u : Fin 4 → K) (σ τ : K →+* K) + (n : κ → Fin 4 → ℕ) (s : Set (Fin 3 → ℕ)) : + Module.finrank ℂ (Submodule.span ℂ + ((fun a : Fin 3 → ℕ => fun j => MvPolynomial.eval (fun _ => 1) + (invariantJet (fun k i => φ (![u, (fun i => σ (u i)), + (fun i => (σ.comp τ) (u i))] k i)) a + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (n j)) 1))) '' s)) = + Module.finrank K (Submodule.span K + ((fun a : Fin 3 → ℕ => fun j => + (∑ i, (n j i : K) * u i) ^ a 0 * + σ (∑ i, (n j i : K) * u i) ^ a 1 * + (σ.comp τ) (∑ i, (n j i : K) * u i) ^ a 2) '' s)) := by + let : Algebra K ℂ := φ.toAlgebra + have h := finrank_span_algebraMap_image (L := ℂ) + (((fun a : Fin 3 → ℕ => fun j => + (∑ i, (n j i : K) * u i) ^ a 0 * + σ (∑ i, (n j i : K) * u i) ^ a 1 * + (σ.comp τ) (∑ i, (n j i : K) * u i) ^ a 2)) '' s) + have hr := funext fun a => funext fun j => + eval_source_jet_monomial_eq_map_row φ u σ τ (n j) a + rw [hr] + rw [Set.image_image] at h + exact h + +end WeightedTorusJets.Geometry + +end + +section +namespace WeightedTorusJets + +theorem greedyPivots_eq_global_retained_set {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (v : ℕ → V) (T : ℕ) + (hspan : Submodule.span K (v '' (Finset.range T : Set ℕ)) = ⊤) : + (greedyPivots K v T : Set ℕ) = + {i | v i ∉ Submodule.span K (v '' (Finset.range i : Set ℕ))} := by + ext i + constructor + · intro hi + exact ((mem_greedyPivots_iff v i T).mp hi).2 + · intro hi + have hmem : i ∈ greedyPivots K v (max T (i + 1)) := + (mem_greedyPivots_iff v i (max T (i + 1))).mpr + ⟨(Nat.lt_succ_self i).trans_le (le_max_right T (i + 1)), hi⟩ + rw [← greedyPivots_eq_of_span_eq_top v (le_max_left T (i + 1)) hspan] at hmem + exact hmem + +end WeightedTorusJets + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/FractionEquivAlgebra.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FractionEquivAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..73791d526545dc694a47f53ebbabe5d31b20a521 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FractionEquivAlgebra.lean @@ -0,0 +1,483 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.TorusEvalOne + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section GeometryExtra1 +open CategoryTheory _root_.AlgebraicGeometry + +namespace WeightedTorusJets.Geometry + +theorem ringKrullDim_away_eq_of_finiteType + {K R : Type*} [Field K] [CommRing R] [IsDomain R] [Algebra K R] + [Algebra.FiniteType K R] (r : R) (hr : r ≠ 0) : + ringKrullDim (Localization.Away r) = ringKrullDim R := by + let S := Localization.Away r + have : IsDomain S := Localization.Away.isDomain hr + have : FaithfulSMul R S := + (faithfulSMul_iff_algebraMap_injective R S).mpr + (IsLocalization.injective S + (powers_le_nonZeroDivisors_of_noZeroDivisors hr)) + have : Algebra.IsAlgebraic R S := IsLocalization.isAlgebraic S (Submonoid.powers r) + have : Algebra.FiniteType K S := Algebra.FiniteType.trans + (inferInstance : Algebra.FiniteType K R) (inferInstance : Algebra.FiniteType R S) + obtain ⟨n, hn, htn⟩ := WeightedTorusJets.finiteType_dimension_trdeg (K := K) (A := R) + obtain ⟨m, hm, htm⟩ := WeightedTorusJets.finiteType_dimension_trdeg (K := K) (A := S) + have hz : Algebra.trdeg R S = 0 := trdeg_eq_zero_iff.mpr inferInstance + have ht := lift_trdeg_add_eq K R S + have he : n = m := by simpa [htn, htm, hz] using ht + rw [hm, hn, he] + + + +universe u + +theorem openImmersion_affine_topologicalKrullDim_eq + {K : Type u} [Field K] {R : CommRingCat.{u}} [IsDomain R] [Algebra K R] + [Algebra.FiniteType K R] {X : Scheme.{u}} [Nonempty X] + (j : X ⟶ Spec R) [IsOpenImmersion j] : + topologicalKrullDim X = ringKrullDim R := by + apply le_antisymm + · rw [← PrimeSpectrum.topologicalKrullDim_eq_ringKrullDim R] + exact j.isOpenEmbedding.isInducing.topologicalKrullDim_le + · let x : X := Classical.choice inferInstance + obtain ⟨_, ⟨r, rfl⟩, hrx, hsub⟩ := + PrimeSpectrum.isTopologicalBasis_basic_opens.exists_subset_of_mem_open + (show j x ∈ Set.range j from ⟨x, rfl⟩) j.isOpenEmbedding.isOpen_range + have hr : r ≠ 0 := by + intro hr + exact hrx (hr.symm ▸ Ideal.zero_mem _) + let l : Spec (.of (Localization.Away r)) ⟶ Spec R := + Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away r))) + have hl : Set.range l ⊆ Set.range j := by + change Set.range (PrimeSpectrum.comap (algebraMap R (Localization.Away r))) ⊆ _ + rw [PrimeSpectrum.localization_away_comap_range (Localization.Away r) r] + exact hsub + let k := IsOpenImmersion.lift j l hl + have hlow : topologicalKrullDim (PrimeSpectrum (Localization.Away r)) ≤ + topologicalKrullDim X := k.isOpenEmbedding.isInducing.topologicalKrullDim_le + rw [PrimeSpectrum.topologicalKrullDim_eq_ringKrullDim, + ringKrullDim_away_eq_of_finiteType (K := K) r hr] at hlow + exact hlow + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +universe u + +local instance locallyClosedAlgebra_top_nonempty (Z : Scheme) [Nonempty Z] : + Nonempty (⊤ : Z.Opens) := ⟨⟨Classical.choice inferInstance, Set.mem_univ _⟩⟩ + +theorem exists_prime_fractionField_algEquiv_of_immersion + {K : Type u} [Field K] {R : CommRingCat.{u}} [Algebra K R] + [Algebra.FiniteType K R] {X : Scheme.{u}} [IsIntegral X] + (f : X ⟶ Spec R) [QuasiCompact f] [IsImmersion f] : + let b := f ≫ Spec.map (CommRingCat.ofHom (algebraMap K R)) + let : Algebra K X.functionField := schemeBaseStalkAlgebra b (genericPoint X) + ∃ (P : Ideal R) (hP : P.IsPrime), + letI := hP + ∃ E : FractionRing (R ⧸ P) ≃ₐ[K] X.functionField, + topologicalKrullDim X = ringKrullDim (R ⧸ P) ∧ + ∀ r : R, E (algebraMap (R ⧸ P) (FractionRing (R ⧸ P)) (Ideal.Quotient.mk P r)) = + X.germToFunctionField ⊤ (((Scheme.ΓSpecIso R).inv ≫ f.appTop) r) := by + let b := f ≫ Spec.map (CommRingCat.ofHom (algebraMap K R)) + let : Algebra K X.functionField := schemeBaseStalkAlgebra b (genericPoint X) + obtain ⟨P, e, he⟩ := IsClosedImmersion.Spec_iff.mp + (inferInstance : IsClosedImmersion f.imageι) + have : IsIntegral (Spec (.of (R ⧸ P))) := IsIntegral.of_isIso e.hom + have : IsDomain (R ⧸ P) := (affine_isIntegral_iff (.of (R ⧸ P))).mp inferInstance + have hP : P.IsPrime := (Ideal.Quotient.isDomain_iff_prime P).mp inferInstance + let j : X ⟶ Spec (.of (R ⧸ P)) := f.toImage ≫ e.hom + have hj : j ≫ Spec.map (CommRingCat.ofHom (Ideal.Quotient.mk P)) = f := by + dsimp only [j] + rw [Category.assoc, ← he, f.toImage_imageι] + let g := Spec.map (CommRingCat.ofHom (algebraMap K (R ⧸ P))) + have hg : g = Spec.map (CommRingCat.ofHom (Ideal.Quotient.mk P)) ≫ + Spec.map (CommRingCat.ofHom (algebraMap K R)) := Spec.map_comp _ _ + have hbase : j ≫ g = b := by rw [hg, ← Category.assoc, hj] + let : Algebra K (Spec (.of (R ⧸ P))).functionField := + schemeBaseStalkAlgebra g (genericPoint (Spec (.of (R ⧸ P)))) + have : IsFractionRing (R ⧸ P) (Spec (.of (R ⧸ P))).functionField := + functionField_isFractionRing_of_affine (.of (R ⧸ P)) + let E : FractionRing (R ⧸ P) ≃+* X.functionField := + (FractionRing.algEquiv (R ⧸ P) (Spec (.of (R ⧸ P))).functionField).toRingEquiv.trans + (openImmersionFunctionFieldEquiv j) + have hscalar (c : K) : E (algebraMap K (FractionRing (R ⧸ P)) c) = + algebraMap K X.functionField c := by + change E (algebraMap K (FractionRing (R ⧸ P)) c) = + schemeBaseToStalk b (genericPoint X) c + let : Algebra K X.functionField := schemeBaseStalkAlgebra (j ≫ g) (genericPoint X) + have h := ((affineFractionFieldAlgEquiv K (R ⧸ P)).trans + (openImmersionFunctionFieldAlgEquiv j g)).commutes c + change E (algebraMap K (FractionRing (R ⧸ P)) c) = + schemeBaseToStalk (j ≫ g) (genericPoint X) c at h + simpa only [hbase] using h + refine ⟨P, hP, { E with commutes' := hscalar }, + Geometry.openImmersion_affine_topologicalKrullDim_eq (K := K) j, ?_⟩ + intro r + change openImmersionFunctionFieldEquiv j + ((FractionRing.algEquiv (R ⧸ P) (Spec (.of (R ⧸ P))).functionField) + (algebraMap (R ⧸ P) (FractionRing (R ⧸ P)) (Ideal.Quotient.mk P r))) = _ + rw [AlgEquiv.commutes] + change dominantFunctionFieldHom j ((Spec (.of (R ⧸ P))).germToFunctionField ⊤ + ((Scheme.ΓSpecIso (.of (R ⧸ P))).inv (Ideal.Quotient.mk P r))) = _ + have hn := congrArg (fun h : Γ(Spec (.of (R ⧸ P)), ⊤) ⟶ X.functionField ↦ + h ((Scheme.ΓSpecIso (.of (R ⧸ P))).inv (Ideal.Quotient.mk P r))) + (germToFunctionField_dominantFunctionFieldHom j) + refine hn.trans ?_ + apply congrArg (X.germToFunctionField ⊤) + have hm : CommRingCat.ofHom (Ideal.Quotient.mk P) ≫ + (Scheme.ΓSpecIso (.of (R ⧸ P))).inv ≫ j.appTop = + (Scheme.ΓSpecIso R).inv ≫ f.appTop := by + rw [Scheme.ΓSpecIso_inv_naturality_assoc, ← Scheme.Hom.comp_appTop, hj] + rfl + exact congrArg (fun h : R ⟶ Γ(X, ⊤) ↦ h r) hm + +end WeightedTorusJets + +namespace WeightedTorusJets + +variable {K A F : Type*} [Field K] [CommRing A] [Algebra K A] + [Field F] [Algebra K F] + +noncomputable abbrev fractionEquivAlgebra (E : FractionRing A ≃ₐ[K] F) : Algebra A F := + (E.toRingHom.comp (algebraMap A (FractionRing A))).toAlgebra + +theorem fractionEquiv_isFractionRing_and_scalarTower (E : FractionRing A ≃ₐ[K] F) : + let : Algebra A F := fractionEquivAlgebra E + IsFractionRing A F ∧ IsScalarTower K A F := by + let : Algebra A F := fractionEquivAlgebra E + let Eₐ : FractionRing A ≃ₐ[A] F := { E.toRingEquiv with commutes' := fun _ ↦ rfl } + exact ⟨IsFractionRing.of_algEquiv Eₐ, + IsScalarTower.of_algHom (E.toAlgHom.comp (IsScalarTower.toAlgHom K A (FractionRing A)))⟩ + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +theorem quasiCompact_immersion_of_finiteType_affine + {K : Type u} [Field K] {R : CommRingCat.{u}} [Algebra K R] + [Algebra.FiniteType K R] {X : Scheme.{u}} (f : X ⟶ Spec R) [IsImmersion f] : + QuasiCompact f := by + have : IsNoetherianRing R := Algebra.FiniteType.isNoetherianRing K R + have : TopologicalSpace.NoetherianSpace X := f.isEmbedding.isInducing.noetherianSpace + infer_instance + +end WeightedTorusJets + +end GeometryExtra1 + +section GeometryExtra2 +open CategoryTheory _root_.AlgebraicGeometry + +namespace WeightedTorusJets.Geometry + +universe u + +local instance locallyClosedLogForm_top_nonempty (X : Scheme) [Nonempty X] : + Nonempty (⊤ : X.Opens) := WeightedTorusJets.locallyClosedAlgebra_top_nonempty X + +theorem logarithmicForm_ne_zero_on_locallyClosed_torus_subvariety + {K : Type u} [Field K] [CharZero K] [IsAlgClosed K] + {X : Scheme.{u}} [IsIntegral X] + (j : X ⟶ Spec (.of (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))) + [IsImmersion j] + (hdim : 0 < topologicalKrullDim X) + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) : + let b := j ≫ Spec.map (CommRingCat.ofHom + (algebraMap K (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))) + let : Algebra K X.functionField := WeightedTorusJets.schemeBaseStalkAlgebra b (genericPoint X) + logarithmicForm c (fun i ↦ X.germToFunctionField ⊤ + (((Scheme.ΓSpecIso (.of (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))).inv ≫ j.appTop) + (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) ≠ 0 := by + let b := j ≫ Spec.map (CommRingCat.ofHom + (algebraMap K (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))) + let : Algebra K X.functionField := WeightedTorusJets.schemeBaseStalkAlgebra b (genericPoint X) + have := WeightedTorusJets.laurent_finiteType (K := K) (ι := Fin 4) + have := WeightedTorusJets.quasiCompact_immersion_of_finiteType_affine (K := K) j + obtain ⟨P, hP, E, hE, hx⟩ := + WeightedTorusJets.exists_prime_fractionField_algEquiv_of_immersion (K := K) j + have hn := logarithmicForm_ne_zero_on_torus_subvariety P (hE ▸ hdim) c hc + refine fun h ↦ hn ?_ + have hm := WeightedTorusJets.logarithmic_relation_map_algHom E.symm.toAlgHom c _ + (by simpa only [logarithmicForm, div_eq_mul_inv] using h) + simpa only [AlgEquiv.coe_toAlgHom, ← hx, AlgEquiv.symm_apply_apply, + logarithmicForm, div_eq_mul_inv] using hm + +theorem logarithmicHyperplane_normal_rank_on_locallyClosed_torus_subvariety + {K : Type u} [Field K] [CharZero K] [IsAlgClosed K] + {X : Scheme.{u}} [IsIntegral X] + (j : X ⟶ Spec (.of (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))) + [IsImmersion j] + (hdim : 0 < topologicalKrullDim X) + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) : + let b := j ≫ Spec.map (CommRingCat.ofHom + (algebraMap K (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))) + let : Algebra K X.functionField := WeightedTorusJets.schemeBaseStalkAlgebra b (genericPoint X) + let x := fun i ↦ X.germToFunctionField ⊤ + (((Scheme.ΓSpecIso (.of (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))).inv ≫ j.appTop) + (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + let T := LinearMap.range (logarithmicTangentMap (k := K) x) + Module.finrank X.functionField (LinearMap.range + (T.mkQ.domRestrict (LinearMap.ker (logarithmicLinearForm (F := X.functionField) c)))) = + 4 - ((topologicalKrullDim X).unbotD 0).toNat := by + let b := j ≫ Spec.map (CommRingCat.ofHom + (algebraMap K (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))) + let : Algebra K X.functionField := WeightedTorusJets.schemeBaseStalkAlgebra b (genericPoint X) + have := WeightedTorusJets.laurent_finiteType (K := K) (ι := Fin 4) + have := WeightedTorusJets.quasiCompact_immersion_of_finiteType_affine (K := K) j + obtain ⟨P, hP, E, hE, hx⟩ := + WeightedTorusJets.exists_prime_fractionField_algEquiv_of_immersion (K := K) j + let A := AddMonoidAlgebra K (Fin 4 →₀ ℤ) ⧸ P + let : Algebra A X.functionField := WeightedTorusJets.fractionEquivAlgebra E + obtain ⟨hfrac, htower⟩ := WeightedTorusJets.fractionEquiv_isFractionRing_and_scalarTower E + let x := fun i ↦ X.germToFunctionField ⊤ + (((Scheme.ΓSpecIso (.of (AddMonoidAlgebra K (Fin 4 →₀ ℤ)))).inv ≫ j.appTop) + (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + have hi : Function.Injective (logarithmicTangentMap (k := K) x) := by + let y : Fin 4 → FractionRing A := fun i ↦ algebraMap A (FractionRing A) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + have hy := logarithmicTangentMap_injective_laurent_quotient P + suffices Function.Injective (logarithmicTangentMap (k := K) (fun i ↦ E (y i))) by + simpa only [y, A, hx, x] using this + rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot'] + intro D hD + let D' : Derivation K (FractionRing A) (FractionRing A) := + Derivation.mk' (E.symm.toLinearMap.comp (D.toLinearMap.comp E.toLinearMap)) + (by intro a b; simp [map_mul, D.leibniz]) + have hD'_apply (z : FractionRing A) : D' z = E.symm (D (E z)) := rfl + have hz : logarithmicTangentMap (k := K) y D' = 0 := by + ext i + apply E.injective + simpa [logarithmicTangentMap, hD'_apply] using congrFun hD i + have hz' : D' = 0 := hy (hz.trans (map_zero _).symm) + ext y + apply E.symm.injective + simpa [hD'_apply] using Derivation.congr_fun hz' (E.symm y) + have hn := (logarithmicForm_ne_zero_iff_tangent_not_le c x).mp + (logarithmicForm_ne_zero_on_locallyClosed_torus_subvariety j hdim c hc) + have hr := finrank_normal_image_of_not_le (logarithmicLinearForm c) + (LinearMap.range (logarithmicTangentMap (k := K) x)) hn + rw [LinearMap.finrank_range_of_inj hi] at hr + have hdim' : topologicalKrullDim X = + (Module.finrank X.functionField (Derivation K X.functionField X.functionField) : WithBot ℕ∞) := + hE.trans (ringKrullDim_eq_finrank_derivation (K := K) (A := A) (F := X.functionField)) + simpa [hdim', x] using hr + +end WeightedTorusJets.Geometry + +end GeometryExtra2 + +section GeometryExtra3 +open scoped TensorProduct + +namespace WeightedTorusJets.Geometry + +theorem torusIdentity_tangent_coordinates {K : Type*} [Field K] : + let P := MvPolynomial (Fin 4) K + let S := Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P)) + let : Algebra S K := (torusEvalOne (K := K)).toAlgebra + ∃ e : Module.Dual K (K ⊗[S] Ω[S⁄K]) ≃ₗ[K] (Fin 4 → K), + (∀ (φ : Module.Dual K (K ⊗[S] Ω[S⁄K])) (i : Fin 4), + e φ i = φ (1 ⊗ₜ[S] KaehlerDifferential.D K S + (algebraMap P S (MvPolynomial.X i)))) ∧ + ∀ c : Fin 4 → K, + let D := localizeDerivation (T := S) + (Submonoid.powers (∏ i : Fin 4, (MvPolynomial.X i : P))) (invariantDerivation c) + e (((Algebra.linearMap S K).comp D.liftKaehlerDifferential).liftBaseChange K) = c := by + let P := MvPolynomial (Fin 4) K + let S := Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P)) + let : Algebra S K := (torusEvalOne (K := K)).toAlgebra + let : Algebra.FormallyEtale P S := + Algebra.FormallyEtale.of_isLocalization + (Submonoid.powers (∏ i : Fin 4, (MvPolynomial.X i : P))) + have hx : ∀ i : Fin 4, IsUnit (algebraMap P S (MvPolynomial.X i)) := fun i => + IsLocalization.Away.isUnit_of_dvd _ + (Finset.dvd_prod_of_mem (fun j : Fin 4 => (MvPolynomial.X j : P)) + (Finset.mem_univ i)) + have heval (i : Fin 4) : + algebraMap S K (algebraMap P S (MvPolynomial.X i)) = 1 := by + change torusEvalOne (algebraMap P S (MvPolynomial.X i)) = 1 + simp [P, S] + refine ⟨logarithmicAmbientEquiv hx, ?_, ?_⟩ + · intro φ i + rw [logarithmicAmbientEquiv_apply, heval, inv_one, one_mul] + · intro c + ext i + rw [logarithmicAmbientEquiv_apply, heval, inv_one, one_mul] + simp only [LinearMap.liftBaseChange_tmul, LinearMap.comp_apply, + Derivation.liftKaehlerDifferential_comp_D, Algebra.linearMap_apply, one_smul, + localize_invariantDerivation_X, map_mul] + change torusEvalOne (algebraMap K S (c i)) * + torusEvalOne (algebraMap P S (MvPolynomial.X i)) = c i + rw [torusEvalOne_algebraMap, MvPolynomial.eval_X, mul_one] + rw [IsScalarTower.algebraMap_apply K P S] + change torusEvalOne (algebraMap P S (MvPolynomial.C (c i))) = c i + simp [P, S] + +end WeightedTorusJets.Geometry + +end GeometryExtra3 + +section GeometryExtra4 +namespace WeightedTorusJets.Geometry + +noncomputable def torusEvalPoint {K : Type*} [Field K] (y : Fin 4 → Kˣ) : + Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) →ₐ[K] K := + IsLocalization.Away.liftAlgHom + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) + (f := MvPolynomial.aeval (fun i ↦ (y i : K))) + (by simpa using (Units.isUnit (∏ i : Fin 4, y i))) + +@[simp] +theorem torusEvalPoint_algebraMap {K : Type*} [Field K] (y : Fin 4 → Kˣ) + (f : MvPolynomial (Fin 4) K) : + torusEvalPoint y (algebraMap (MvPolynomial (Fin 4) K) _ f) = + MvPolynomial.aeval (fun i ↦ (y i : K)) f := by + simp [torusEvalPoint] + +theorem torus_point_normal_equiv_rank {K : Type*} [Field K] [CharZero K] + (y : Fin 4 → Kˣ) (c : Fin 4 → K) (hc : LinearIndependent ℚ c) : + let q := RingHom.ker (torusEvalPoint y).toRingHom + let : q.IsPrime := RingHom.ker_isPrime _ + let A := Localization.AtPrime q + let κ := IsLocalRing.ResidueField A + let m := IsLocalRing.maximalIdeal A + let T := LinearMap.range (logarithmicTangentMap (k := K) + (fun i : Fin 4 ↦ algebraMap (MvPolynomial (Fin 4) K) κ (MvPolynomial.X i))) + ∃ e : ((Fin 4 → κ) ⧸ T) ≃ₗ[κ] Module.Dual κ m.Cotangent, + (∀ (D : Derivation K A A) (v : Fin 4 → K), + (∀ i, D (algebraMap (MvPolynomial (Fin 4) K) A (MvPolynomial.X i)) = + algebraMap K A (v i) * + algebraMap (MvPolynomial (Fin 4) K) A (MvPolynomial.X i)) → + ∀ f : m, e (T.mkQ (algebraMap K κ ∘ v)) (m.toCotangent f) = + Ideal.Quotient.mk m (D f)) ∧ + Module.finrank κ (LinearMap.range + ((e.toLinearMap.comp T.mkQ).domRestrict + (LinearMap.ker (dotProductEquiv κ (Fin 4) (algebraMap K κ ∘ c))))) = 3 := by + let q := RingHom.ker (torusEvalPoint y).toRingHom + let : q.IsPrime := RingHom.ker_isPrime _ + let A := Localization.AtPrime q + let p := q.comap (algebraMap (MvPolynomial (Fin 4) K) _) + have : IsLocalization.AtPrime A p := + IsLocalization.isLocalization_isLocalization_atPrime_isLocalization + (Submonoid.powers (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K))) A q + have hp : p = RingHom.ker (MvPolynomial.aeval (fun i ↦ (y i : K))).toRingHom := by + ext f + simp only [p, q, Ideal.mem_comap, RingHom.mem_ker, AlgHom.toRingHom_eq_coe, + RingHom.coe_coe, torusEvalPoint_algebraMap] + let κ := IsLocalRing.ResidueField A + let m := IsLocalRing.maximalIdeal A + let T := LinearMap.range (logarithmicTangentMap (k := K) + (fun i : Fin 4 ↦ algebraMap (MvPolynomial (Fin 4) K) κ (MvPolynomial.X i))) + have hcoords (i : Fin 4) : + IsUnit (algebraMap (MvPolynomial (Fin 4) K) A (MvPolynomial.X i)) ∧ + algebraMap (MvPolynomial (Fin 4) K) κ (MvPolynomial.X i) = algebraMap K κ (y i) := by + constructor + · apply (IsLocalization.AtPrime.isUnit_to_map_iff A p _).mpr + change MvPolynomial.X i ∉ p + rw [hp] + simp + · have hm : MvPolynomial.X i - MvPolynomial.C (y i : K) ∈ p := by + rw [hp] + simp + have hz : algebraMap (MvPolynomial (Fin 4) K) (IsLocalRing.ResidueField A) + (MvPolynomial.X i - MvPolynomial.C (y i : K)) = 0 := by + apply (IsLocalRing.residue_eq_zero_iff _).mpr + exact (IsLocalization.AtPrime.to_map_mem_maximal_iff A p _).mpr hm + simpa only [map_sub, MvPolynomial.C_eq_algebraMap, ← IsScalarTower.algebraMap_apply, + sub_eq_zero] using hz + have hx := fun i ↦ (hcoords i).1 + have : Algebra.FormallyEtale (MvPolynomial (Fin 4) K) A := + Algebra.FormallyEtale.of_isLocalization p.primeCompl + have : Algebra.EssFiniteType (MvPolynomial (Fin 4) K) A := + Algebra.EssFiniteType.of_isLocalization A p.primeCompl + have : Algebra.EssFiniteType K A := Algebra.EssFiniteType.comp K (MvPolynomial (Fin 4) K) A + let e : ((Fin 4 → κ) ⧸ T) ≃ₗ[κ] Module.Dual κ m.Cotangent := + coordinateNormalEquivCotangentDual m hx + refine ⟨e, ?_, ?_⟩ + · intro D v hv f + exact coordinateNormal_invariant_pairing m hx D (fun i ↦ algebraMap K A (v i)) hv f + · have hT : T = ⊥ := by + rw [LinearMap.range_eq_bot] + ext D i + change (algebraMap (MvPolynomial (Fin 4) K) κ (MvPolynomial.X i))⁻¹ * + D (algebraMap (MvPolynomial (Fin 4) K) κ (MvPolynomial.X i)) = 0 + rw [(hcoords i).2, D.map_algebraMap, mul_zero] + have hq : Function.Injective T.mkQ := by + rw [← LinearMap.ker_eq_bot, Submodule.ker_mkQ, hT] + have hi : Function.Injective ((e.toLinearMap.comp T.mkQ).domRestrict + (LinearMap.ker (dotProductEquiv κ (Fin 4) (algebraMap K κ ∘ c)))) := + e.injective.comp (hq.comp (LinearMap.ker + (dotProductEquiv κ (Fin 4) (algebraMap K κ ∘ c))).injective_subtype) + rw [LinearMap.finrank_range_of_inj hi] + have hω : dotProductEquiv κ (Fin 4) (algebraMap K κ ∘ c) ≠ 0 := by + apply (dotProductEquiv κ (Fin 4)).map_ne_zero_iff.mpr + intro h + have hz := congrFun h 0 + exact hc.ne_zero 0 ((map_eq_zero (algebraMap K κ)).mp hz) + have hd := Module.Dual.finrank_ker_add_one_of_ne_zero hω + have h4 : Module.finrank κ (Fin 4 → κ) = 4 := by simp + omega + +end WeightedTorusJets.Geometry + +end GeometryExtra4 + +section GeometryExtra5 +namespace WeightedTorusJets.Geometry + +theorem exists_torusEvalPoint_of_quotient_dimension_zero {K : Type*} + [Field K] [IsAlgClosed K] + (q : Ideal (Localization.Away + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) [q.IsPrime] + (hdim : ringKrullDim (_ ⧸ q) = 0) : + ∃ y : Fin 4 → Kˣ, q = RingHom.ker (torusEvalPoint y).toRingHom := by + let P := MvPolynomial (Fin 4) K + let S := Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P)) + have : Ring.KrullDimLE 0 (S ⧸ q) := + ringKrullDimZero_iff_ringKrullDim_eq_zero.mpr hdim + let : Field (S ⧸ q) := (Ring.KrullDimLE.isField_of_isDomain (R := S ⧸ q)).toField + have : Algebra.FiniteType K S := Algebra.FiniteType.trans (S := P) inferInstance inferInstance + have : Module.Finite K (S ⧸ q) := finite_of_finite_type_of_isJacobsonRing K (S ⧸ q) + let e : (S ⧸ q) →ₐ[K] K := + (AlgEquiv.ofBijective (Algebra.ofId K (S ⧸ q)) + IsAlgClosed.algebraMap_bijective_of_isIntegral).symm.toAlgHom + let φ : S →ₐ[K] K := e.comp (Ideal.Quotient.mkₐ K q) + have hx (i : Fin 4) : IsUnit (algebraMap P S (MvPolynomial.X i)) := + IsLocalization.Away.isUnit_of_dvd _ + (Finset.dvd_prod_of_mem (fun j : Fin 4 => (MvPolynomial.X j : P)) + (Finset.mem_univ i)) + let y : Fin 4 → Kˣ := fun i => ((hx i).map φ.toRingHom).unit + have hφ : φ = torusEvalPoint y := by + apply IsLocalization.algHom_ext + (Submonoid.powers (∏ i : Fin 4, (MvPolynomial.X i : P))) + ext i + change φ (algebraMap P S (MvPolynomial.X i)) = + torusEvalPoint y (algebraMap P S (MvPolynomial.X i)) + rw [torusEvalPoint_algebraMap, MvPolynomial.aeval_X] + exact ((hx i).map φ.toRingHom).unit_spec.symm + refine ⟨y, ?_⟩ + rw [← hφ] + ext s + change s ∈ q ↔ e (Ideal.Quotient.mk q s) = 0 + rw [map_eq_zero, Ideal.Quotient.eq_zero_iff_mem] + +end WeightedTorusJets.Geometry + +end GeometryExtra5 + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/FractionEulerDerivation.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FractionEulerDerivation.lean new file mode 100644 index 0000000000000000000000000000000000000000..6047dbdd1963e4939e8fef13f6f549b3d3939439 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FractionEulerDerivation.lean @@ -0,0 +1,319 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.InvariantJetLinearMap +import OAI.NumberTheory.Jacobsthal.Siegel.LocalizeInvariantDerivationLogCoordinate + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +theorem biquadratic_torus_log_pairing {K : Type*} [Field K] {a b : K} + (ha : a ≠ 0) (hb : b ≠ 0) : + let P := MvPolynomial (Fin 4) K + let z : P := ∏ j : Fin 4, MvPolynomial.X j + let A := Localization.Away z + ∃ u : Fin 4 → Aˣ, + (∀ j, (u j : A) = algebraMap P A (MvPolynomial.X j)) ∧ + ∀ i : Fin 3, ∑ j : Fin 4, algebraMap K A (biquadraticCoefficients a b j) * + ((↑((u j)⁻¹) : A) * + Geometry.localizeDerivation (Submonoid.powers z) + (Geometry.invariantDerivation (biquadraticDirections a b i)) + (algebraMap P A (MvPolynomial.X j))) = 0 := by + let P := MvPolynomial (Fin 4) K + let z : P := ∏ j : Fin 4, MvPolynomial.X j + let A := Localization.Away z + let u : Fin 4 → Aˣ := fun j => (Geometry.torus_coordinate_isUnit (K := K) j).unit + have hu (j : Fin 4) : (u j : A) = algebraMap P A (MvPolynomial.X j) := + (Geometry.torus_coordinate_isUnit (K := K) j).unit_spec + refine ⟨u, hu, ?_⟩ + intro i + have hlog (j : Fin 4) := Geometry.localize_invariantDerivation_log_coordinate + (Submonoid.powers z) (biquadraticDirections a b i) j (u j) (hu j) + calc + _ = ∑ j : Fin 4, algebraMap K A + (biquadraticCoefficients a b j * biquadraticDirections a b i j) := by + apply Finset.sum_congr rfl + intro j _ + rw [hlog, map_mul] + _ = algebraMap K A (biquadraticForm a b (biquadraticDirections a b i)) := by + change _ = algebraMap K A + (∑ j : Fin 4, biquadraticCoefficients a b j * biquadraticDirections a b i j) + rw [map_sum] + _ = 0 := by rw [biquadraticForm_direction ha hb, map_zero] + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + + theorem lift_logarithmicForm_localize_invariantDerivation + {K F ι : Type*} [Field K] [Field F] [Fintype ι] + [Algebra K F] [Algebra (MvPolynomial ι K) F] [IsScalarTower K (MvPolynomial ι K) F] + (M : Submonoid (MvPolynomial ι K)) [IsLocalization M F] + (c d : ι → K) + (hx : ∀ i, algebraMap (MvPolynomial ι K) F (MvPolynomial.X i) ≠ 0) : + (localizeDerivation M (invariantDerivation d)).liftKaehlerDifferential + (logarithmicForm c (fun i => algebraMap (MvPolynomial ι K) F (MvPolynomial.X i))) = + algebraMap K F (∑ i, c i * d i) := by + rw [lift_logarithmicForm, map_sum] + apply Finset.sum_congr rfl + intro i _ + rw [localize_invariantDerivation_X, map_mul] + simp [mul_left_comm, mul_comm, hx i] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + + theorem biquadratic_functionField_logarithmicForm_contraction + {K : Type*} [Field K] {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) (i : Fin 3) : + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + (Geometry.localizeDerivation (T := F) (nonZeroDivisors P) + (Geometry.invariantDerivation (biquadraticDirections a b i))).liftKaehlerDifferential + (Geometry.logarithmicForm (biquadraticCoefficients a b) + (fun j => algebraMap P F (MvPolynomial.X j))) = 0 := by + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + have hx j : algebraMap P F (MvPolynomial.X j) ≠ 0 := + (map_ne_zero_iff _ (IsFractionRing.injective P F)).mpr (MvPolynomial.X_ne_zero j) + dsimp only + rw [Geometry.lift_logarithmicForm_localize_invariantDerivation _ _ _ hx] + change algebraMap K F (biquadraticForm a b (biquadraticDirections a b i)) = 0 + rw [biquadraticForm_direction ha hb, map_zero] + + + + theorem biquadratic_functionField_contraction_zero_iff + {K : Type*} [Field K] (a b : K) (v : Fin 4 → K) : + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + (Geometry.localizeDerivation (T := F) (nonZeroDivisors P) + (Geometry.invariantDerivation v)).liftKaehlerDifferential + (Geometry.logarithmicForm (biquadraticCoefficients a b) + (fun j => algebraMap P F (MvPolynomial.X j))) = 0 ↔ + biquadraticForm a b v = 0 := by + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + have hx j : algebraMap P F (MvPolynomial.X j) ≠ 0 := + (map_ne_zero_iff _ (IsFractionRing.injective P F)).mpr (MvPolynomial.X_ne_zero j) + dsimp only + rw [Geometry.lift_logarithmicForm_localize_invariantDerivation _ _ _ hx] + change algebraMap K F (biquadraticForm a b v) = 0 ↔ biquadraticForm a b v = 0 + exact map_eq_zero _ + + theorem biquadratic_mem_span_iff_functionField_contraction_zero + {K : Type*} [Field K] [CharZero K] {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) + (v : Fin 4 → K) : + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + v ∈ Submodule.span K (Set.range (biquadraticDirections a b)) ↔ + (Geometry.localizeDerivation (T := F) (nonZeroDivisors P) + (Geometry.invariantDerivation v)).liftKaehlerDifferential + (Geometry.logarithmicForm (biquadraticCoefficients a b) + (fun j => algebraMap P F (MvPolynomial.X j))) = 0 := by + dsimp only + rw [span_biquadraticDirections_eq_ker ha hb, LinearMap.mem_ker] + exact (biquadratic_functionField_contraction_zero_iff a b v).symm + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +variable {K ι : Type*} [Field K] [Fintype ι] [DecidableEq ι] + +noncomputable def fractionEulerDerivation (i : ι) : + Derivation K (FractionRing (MvPolynomial ι K)) (FractionRing (MvPolynomial ι K)) := + localizeDerivation (nonZeroDivisors (MvPolynomial ι K)) + (invariantDerivation (Pi.single i 1)) + + theorem logarithmicTangentMap_fractionEulerDerivation (i : ι) : + logarithmicTangentMap (k := K) + (fun j => algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X j)) (fractionEulerDerivation i) = Pi.single i 1 := by + ext j + have hx : algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X j) ≠ 0 := + (map_ne_zero_iff _ (IsFractionRing.injective _ _)).mpr (MvPolynomial.X_ne_zero j) + change (algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X j))⁻¹ * localizeDerivation _ + (invariantDerivation (Pi.single i (1 : K))) _ = _ + rw [localize_invariantDerivation_X] + simp [Pi.single_apply, hx] + +noncomputable def fractionInvariantDerivationLinearMap : + (ι → FractionRing (MvPolynomial ι K)) →ₗ[FractionRing (MvPolynomial ι K)] + Derivation K (FractionRing (MvPolynomial ι K)) (FractionRing (MvPolynomial ι K)) where + toFun v := ∑ i, v i • fractionEulerDerivation i + map_add' v w := by simp only [Pi.add_apply, add_smul, Finset.sum_add_distrib] + map_smul' c v := by simp only [Pi.smul_apply, smul_smul, Finset.smul_sum, RingHom.id_apply, smul_eq_mul] + + theorem logarithmicTangentMap_fractionInvariantDerivation (v : ι → FractionRing (MvPolynomial ι K)) : + logarithmicTangentMap (k := K) + (fun j => algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X j)) (fractionInvariantDerivationLinearMap v) = v := by + change logarithmicTangentMap _ (∑ i, v i • fractionEulerDerivation i) = v + rw [map_sum] + simp_rw [map_smul, logarithmicTangentMap_fractionEulerDerivation] + exact (pi_eq_sum_univ' v).symm + +omit [Fintype ι] [DecidableEq ι] in + theorem logarithmicTangentMap_injective_polynomial_fraction : + Function.Injective (logarithmicTangentMap (k := K) + (fun j => algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X j))) := by + intro D E h + let P := MvPolynomial ι K + let F := FractionRing P + apply localization_derivation_ext (nonZeroDivisors P) + intro p + change D.compAlgebraMap P p = E.compAlgebraMap P p + apply MvPolynomial.derivation_eq_of_forall_mem_vars + intro j _ + have hx : algebraMap P F (MvPolynomial.X j) ≠ 0 := + (map_ne_zero_iff _ (IsFractionRing.injective _ _)).mpr (MvPolynomial.X_ne_zero j) + have hj := congrFun h j + change (algebraMap P F (MvPolynomial.X j))⁻¹ * D _ = + (algebraMap P F (MvPolynomial.X j))⁻¹ * E _ at hj + exact mul_left_cancel₀ (inv_ne_zero hx) hj + +noncomputable def fractionLogarithmicTangentEquiv : + Derivation K (FractionRing (MvPolynomial ι K)) (FractionRing (MvPolynomial ι K)) + ≃ₗ[FractionRing (MvPolynomial ι K)] (ι → FractionRing (MvPolynomial ι K)) := + LinearEquiv.ofBijective (logarithmicTangentMap (k := K) + (fun j => algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X j))) + ⟨logarithmicTangentMap_injective_polynomial_fraction, + fun v => ⟨fractionInvariantDerivationLinearMap v, + logarithmicTangentMap_fractionInvariantDerivation v⟩⟩ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K ι : Type*} [Field K] [Fintype ι] [DecidableEq ι] + + theorem fractionLogarithmicTangentEquiv_localize_invariantDerivation (v : ι → K) : + fractionLogarithmicTangentEquiv (K := K) (ι := ι) + (localizeDerivation (nonZeroDivisors (MvPolynomial ι K)) (invariantDerivation v)) = + fun i => algebraMap K (FractionRing (MvPolynomial ι K)) (v i) := by + ext i + have hx : algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X i) ≠ 0 := + (map_ne_zero_iff _ (IsFractionRing.injective _ _)).mpr (MvPolynomial.X_ne_zero i) + change (algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X i))⁻¹ * localizeDerivation _ (invariantDerivation v) _ = _ + rw [localize_invariantDerivation_X] + simp [mul_left_comm, hx] + +noncomputable def fractionLogarithmicContractionLinearMap (c : ι → K) : + Derivation K (FractionRing (MvPolynomial ι K)) (FractionRing (MvPolynomial ι K)) + →ₗ[FractionRing (MvPolynomial ι K)] FractionRing (MvPolynomial ι K) where + toFun D := D.liftKaehlerDifferential (logarithmicForm c + (fun j => algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K)) + (MvPolynomial.X j))) + map_add' D E := by + simp only [lift_logarithmicForm, Derivation.add_apply, mul_add, Finset.sum_add_distrib] + map_smul' t D := by + simp only [lift_logarithmicForm, Derivation.smul_apply, smul_eq_mul, + RingHom.id_apply, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + + theorem fractionLogarithmicContraction_eq_dotProduct_comp (c : ι → K) : + fractionLogarithmicContractionLinearMap c = + (dotProductBilin (FractionRing (MvPolynomial ι K)) (FractionRing (MvPolynomial ι K)) + (fun i => algebraMap K (FractionRing (MvPolynomial ι K)) (c i))).comp + fractionLogarithmicTangentEquiv.toLinearMap := by + ext D + simp [fractionLogarithmicContractionLinearMap, lift_logarithmicForm, + dotProductBilin, dotProduct, fractionLogarithmicTangentEquiv, logarithmicTangentMap, + mul_assoc] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + + theorem biquadratic_functionField_derivations_span_eq_ker + {K : Type*} [Field K] [CharZero K] {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + Submodule.span F (Set.range (fun i : Fin 3 => + Geometry.localizeDerivation (T := F) (nonZeroDivisors P) + (Geometry.invariantDerivation (biquadraticDirections a b i)))) = + LinearMap.ker (Geometry.fractionLogarithmicContractionLinearMap (biquadraticCoefficients a b)) := by + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + let e := Geometry.fractionLogarithmicTangentEquiv (K := K) (ι := Fin 4) + have hma : algebraMap K F a ≠ 0 := (map_ne_zero _).mpr ha + have hmb : algebraMap K F b ≠ 0 := (map_ne_zero _).mpr hb + have hdirs : (fun i : Fin 3 => e (Geometry.localizeDerivation (T := F) (nonZeroDivisors P) + (Geometry.invariantDerivation (biquadraticDirections a b i)))) = + biquadraticDirections (algebraMap K F a) (algebraMap K F b) := by + exact funext fun i => + (Geometry.fractionLogarithmicTangentEquiv_localize_invariantDerivation + (biquadraticDirections a b i)).trans (map_biquadraticDirections (algebraMap K F) a b i) + have hcmap : (fun i => algebraMap K F (biquadraticCoefficients a b i)) = + biquadraticCoefficients (algebraMap K F a) (algebraMap K F b) := + map_biquadraticCoefficients (algebraMap K F) a b + dsimp only + apply Submodule.map_injective_of_injective e.injective + rw [Submodule.map_span, ← Set.range_comp', LinearEquiv.coe_coe, hdirs, + span_biquadraticDirections_eq_ker hma hmb, + Geometry.fractionLogarithmicContraction_eq_dotProduct_comp, + hcmap, LinearMap.ker_comp] + exact (Submodule.map_comap_eq_of_surjective e.surjective _).symm + + + + theorem biquadratic_functionField_derivations_linearIndependent + {K : Type*} [Field K] [CharZero K] {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + LinearIndependent F (fun i : Fin 3 => + Geometry.localizeDerivation (T := F) (nonZeroDivisors P) + (Geometry.invariantDerivation (biquadraticDirections a b i))) := by + let P := MvPolynomial (Fin 4) K + let F := FractionRing P + let e := Geometry.fractionLogarithmicTangentEquiv (K := K) (ι := Fin 4) + have hma : algebraMap K F a ≠ 0 := (map_ne_zero _).mpr ha + have hmb : algebraMap K F b ≠ 0 := (map_ne_zero _).mpr hb + have hdirs : (fun i : Fin 3 => e (Geometry.localizeDerivation (T := F) (nonZeroDivisors P) + (Geometry.invariantDerivation (biquadraticDirections a b i)))) = + biquadraticDirections (algebraMap K F a) (algebraMap K F b) := by + exact funext fun i => + (Geometry.fractionLogarithmicTangentEquiv_localize_invariantDerivation + (biquadraticDirections a b i)).trans (map_biquadraticDirections (algebraMap K F) a b i) + apply LinearIndependent.of_comp e.toLinearMap + change LinearIndependent F (fun i : Fin 3 => e (Geometry.localizeDerivation (T := F) + (nonZeroDivisors P) (Geometry.invariantDerivation (biquadraticDirections a b i)))) + rw [hdirs] + exact biquadraticDirections_linearIndependent hma hmb + +noncomputable def biquadraticFunctionFieldDerivationBasis + {K : Type*} [Field K] [CharZero K] {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : + Module.Basis (Fin 3) (FractionRing (MvPolynomial (Fin 4) K)) + (LinearMap.ker (Geometry.fractionLogarithmicContractionLinearMap + (biquadraticCoefficients a b))) := + (Module.Basis.span (biquadratic_functionField_derivations_linearIndependent ha hb)).map + (LinearEquiv.ofEq _ _ (biquadratic_functionField_derivations_span_eq_ker ha hb)) + + theorem coe_biquadraticFunctionFieldDerivationBasis + {K : Type*} [Field K] [CharZero K] {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) (i : Fin 3) : + (biquadraticFunctionFieldDerivationBasis ha hb i : + Derivation K (FractionRing (MvPolynomial (Fin 4) K)) (FractionRing (MvPolynomial (Fin 4) K))) = + Geometry.localizeDerivation (nonZeroDivisors (MvPolynomial (Fin 4) K)) + (Geometry.invariantDerivation (biquadraticDirections a b i)) := by + simp [biquadraticFunctionFieldDerivationBasis] + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/FrobeniusRetainedCharacterField.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FrobeniusRetainedCharacterField.lean new file mode 100644 index 0000000000000000000000000000000000000000..24ad6e5fd55f776b0ea804fa5ebc09c94e57d328 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/FrobeniusRetainedCharacterField.lean @@ -0,0 +1,80 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.IntegerCharacter +import OAI.NumberTheory.Jacobsthal.Siegel.SqrtPairFrobeniusDirections + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped NumberField +namespace WeightedTorusJets + +theorem source_frobenius_of_retained_character_field + (q : ℕ) (L : Type*) [Field L] [NumberField L] + [NeZero (8 * q)] [IsCyclotomicExtension {8 * q} ℚ L] [IsAbelianGalois ℚ L] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (a b : L) + (hchar : IntermediateField.adjoin ℚ {a} = characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)) : + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∀ (_ : Module.finrank ℚ B = 4) + (σ τ : B ≃ₐ[ℚ] B) (_ : τ a' = a') + (_ : Nat.card (B ≃ₐ[ℚ] B) = 4) + (_ : ∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ), + ∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x)) := by + dsimp + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + intro hdegree σ τ hτa hcard hall p hp hpn hχp + let : IsGalois ℚ B := IsGalois.of_card_aut_eq_finrank ℚ B (hcard.trans hdegree.symm) + have hquad := real_character_isQuadratic χ hreal + have hquad' : (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ).IsQuadratic := by + rw [MulChar.isQuadratic_iff_sq_eq_one, ← map_pow, hquad.sq_eq_one, map_one] + have hc : p.Coprime (2 * q) := hp.coprime_iff_not_dvd.mpr hpn + have hpm : p.Coprime (8 * q) := by + simpa only [show 8 = 2 ^ 3 from rfl, Nat.coprime_mul_iff_right, + Nat.coprime_pow_right_iff (by decide : 0 < (3 : ℕ))] using hc + let : Fact p.Prime := ⟨hp⟩ + obtain ⟨φ, hfrob, hglobal⟩ := exists_cyclotomic_frobenius_congruence (8 * q) L p + (hp.coprime_iff_not_dvd.mp hpm) + obtain ⟨P, hP, hover⟩ := Ideal.exists_maximal_ideal_liesOver_of_isIntegral + (S := 𝓞 L) (Ideal.span {(p : ℤ)}) + have hφa : φ a ≠ a := by + intro hfix + have hmem := (mem_adjoin_fixingSubgroup_iff a φ).mpr hfix + rw [hchar] at hmem + have hval := (mem_characterField_fixingSubgroup (8 * q) L ℂ _ hquad' φ).mp hmem + rw [galEquivZMod_arithFrob (8 * q) L hp hpm P hover.over.symm φ + (hfrob P inferInstance hover)] at hval + have hcast : (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) + (ZMod.unitOfCoprime p hpm) = χ p := by + rw [DirichletCharacter.changeLevel_eq_cast_of_dvd] + simp + rw [hcast, hχp] at hval + norm_num at hval + let ψ := φ.restrictNormal B + have hψa : ψ a' ≠ a' := by + intro h + apply hφa + simpa [ψ, a', AlgEquiv.restrictNormal_apply] using congrArg (fun x : B => (x : L)) h + have hψglobal : ∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - ψ • x := + frobenius_congruence_descends B.val ψ φ (fun x => AlgEquiv.restrictNormal_apply B φ x) p hglobal + rcases hall ψ with hψ | hψ | hψ | hψ + · exact (hψa (hψ ▸ AlgEquiv.one_apply a')).elim + · exact Or.inl (hψ ▸ hψglobal) + · exact (hψa (hψ ▸ hτa)).elim + · exact Or.inr (hψ ▸ hψglobal) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GenericNormalization.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GenericNormalization.lean new file mode 100644 index 0000000000000000000000000000000000000000..f9bf33979a3a10887a9bbde75b66d910ae8dd32e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GenericNormalization.lean @@ -0,0 +1,502 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.DominantFunctionFieldHom + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section OriginalSourceGeometryOverlay +noncomputable section +attribute [local instance] WeightedTorusJets.Geometry.polynomialGradedAlgebra +open Module +open CategoryTheory _root_.AlgebraicGeometry +open CategoryTheory _root_.AlgebraicGeometry +open IsLocalRing +open _root_.AlgebraicGeometry TopologicalSpace CategoryTheory +open _root_.AlgebraicGeometry TopologicalSpace CategoryTheory +namespace AlgebraicGeometry.Scheme.Hom + +theorem isIntegrallyClosed_stalk_normalization_of_field + {K : Type*} [Field K] {Y : Scheme} + (f : Spec (.of K) ⟶ Y) [QuasiCompact f] [QuasiSeparated f] + (x : f.normalization) : + IsIntegrallyClosed (f.normalization.presheaf.stalk x) := by + classical + obtain ⟨_, ⟨U, hU, rfl⟩, hxU, _⟩ := + Y.isBasis_affineOpens.exists_subset_of_mem_open + (show f.fromNormalization x ∈ (⊤ : Y.Opens) by simp) (⊤ : Y.Opens).isOpen + have hpre : f ⁻¹ᵁ U = ⊤ := by + obtain ⟨a, ha⟩ := f.toNormalization.denseRange.exists_mem_open + (f.fromNormalization ⁻¹ᵁ U).isOpen ⟨x, hxU⟩ + change f.fromNormalization (f.toNormalization a) ∈ U at ha + rw [← Scheme.Hom.comp_apply, f.toNormalization_fromNormalization] at ha + apply top_unique + intro b _ + change f b ∈ U + have hba : b = a := Subsingleton.elim b a + subst b + exact ha + have hfield : IsField Γ(Spec (.of K), f ⁻¹ᵁ U) := by + rw [hpre] + exact (Scheme.ΓSpecIso (.of K)).commRingCatIsoToRingEquiv.toMulEquiv.isField + (Field.toIsField K) + let : Field Γ(Spec (.of K), f ⁻¹ᵁ U) := hfield.toField + let : Algebra Γ(Y, U) Γ(Spec (.of K), f ⁻¹ᵁ U) := (f.app U).hom.toAlgebra + have : IsIntegrallyClosed (integralClosure Γ(Y, U) Γ(Spec (.of K), f ⁻¹ᵁ U)) := + IsIntegrallyClosed.of_isIntegrallyClosedIn _ Γ(Spec (.of K), f ⁻¹ᵁ U) + have : IsIntegrallyClosed Γ(f.normalization, f.fromNormalization ⁻¹ᵁ U) := + IsIntegrallyClosed.of_equiv (f.normalizationObjIso hU).symm.commRingCatIsoToRingEquiv + have : Nonempty (f.fromNormalization ⁻¹ᵁ U) := ⟨⟨x, hxU⟩⟩ + let : Algebra Γ(f.normalization, f.fromNormalization ⁻¹ᵁ U) + (f.normalization.presheaf.stalk x) := + TopCat.Presheaf.algebra_section_stalk f.normalization.presheaf ⟨x, hxU⟩ + have hV := hU.preimage f.fromNormalization + have := hV.isLocalization_stalk ⟨x, hxU⟩ + exact isIntegrallyClosed_of_isLocalization (f.normalization.presheaf.stalk x) + (hV.primeIdealOf ⟨x, hxU⟩).asIdeal.primeCompl + (hV.primeIdealOf ⟨x, hxU⟩).asIdeal.primeCompl_le_nonZeroDivisors + +end AlgebraicGeometry.Scheme.Hom +namespace WeightedTorusJets + +universe u + +variable (Y : Scheme.{u}) [IsIntegral Y] [QuasiSeparatedSpace Y] + +noncomputable def genericNormalization : Scheme.{u} := + (Y.fromSpecStalk (genericPoint Y)).normalization + +noncomputable def genericNormalizationMap : genericNormalization Y ⟶ Y := + (Y.fromSpecStalk (genericPoint Y)).fromNormalization + +instance genericNormalization_isIntegral : IsIntegral (genericNormalization Y) := by + dsimp only [genericNormalization] + infer_instance + +instance genericNormalizationMap_isDominant : IsDominant (genericNormalizationMap Y) := by + apply (IsDominant.comp_iff (Y.fromSpecStalk (genericPoint Y)).toNormalization + (Y.fromSpecStalk (genericPoint Y)).fromNormalization).mp + simpa only [Scheme.Hom.toNormalization_fromNormalization] using + isDominant_fromSpecStalk_genericPoint Y + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +variable {X Y : Scheme.{u}} [IsIntegral X] [IsIntegral Y] + +instance dominantFunctionFieldHom_isIso (f : X ⟶ Y) [IsDominant f] + [IsOpenImmersion f] : IsIso (dominantFunctionFieldHom f) := by + unfold dominantFunctionFieldHom + infer_instance + +noncomputable def openImmersionFunctionFieldEquiv (f : X ⟶ Y) [IsDominant f] + [IsOpenImmersion f] : Y.functionField ≃+* X.functionField := + (asIso (dominantFunctionFieldHom f)).commRingCatIsoToRingEquiv + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +noncomputable def schemeBaseToStalk {R : Type u} [CommRing R] {X : Scheme.{u}} + (f : X ⟶ Spec (CommRingCat.of R)) (x : X) : R →+* X.presheaf.stalk x := + ((StructureSheaf.toStalk R (f x)) ≫ f.stalkMap x).hom + +noncomputable abbrev schemeBaseStalkAlgebra {R : Type u} [CommRing R] {X : Scheme.{u}} + (f : X ⟶ Spec (CommRingCat.of R)) (x : X) : Algebra R (X.presheaf.stalk x) := + (schemeBaseToStalk f x).toAlgebra + +theorem schemeBaseToStalk_eq_global_germ {R : Type u} [CommRing R] {X : Scheme.{u}} + (f : X ⟶ Spec (CommRingCat.of R)) (x : X) : + schemeBaseToStalk f x = + (X.presheaf.germ ⊤ x (by simp)).hom.comp + (((Scheme.ΓSpecIso (CommRingCat.of R)).inv ≫ f.appTop).hom) := by + change (((Scheme.ΓSpecIso (CommRingCat.of R)).inv ≫ + (Spec (CommRingCat.of R)).presheaf.germ ⊤ (f x) (by simp)) ≫ f.stalkMap x).hom = _ + rw [Category.assoc, f.germ_stalkMap] + rfl + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +variable {k : Type u} [CommRing k] {X Y : Scheme.{u}} [IsIntegral X] [IsIntegral Y] + +noncomputable def dominantFunctionFieldAlgHom (f : X ⟶ Y) [IsDominant f] + (g : Y ⟶ Spec (CommRingCat.of k)) : + let : Algebra k Y.functionField := schemeBaseStalkAlgebra g (genericPoint Y) + let : Algebra k X.functionField := schemeBaseStalkAlgebra (f ≫ g) (genericPoint X) + Y.functionField →ₐ[k] X.functionField := by + let : Algebra k Y.functionField := schemeBaseStalkAlgebra g (genericPoint Y) + let : Algebra k X.functionField := schemeBaseStalkAlgebra (f ≫ g) (genericPoint X) + refine { (dominantFunctionFieldHom f).hom with commutes' := ?_ } + intro c + change dominantFunctionFieldHom f (schemeBaseToStalk g (genericPoint Y) c) = + schemeBaseToStalk (f ≫ g) (genericPoint X) c + rw [schemeBaseToStalk_eq_global_germ, schemeBaseToStalk_eq_global_germ] + have hn := congrArg + (fun h : Γ(Y, ⊤) ⟶ X.functionField ↦ + h (((Scheme.ΓSpecIso (CommRingCat.of k)).inv ≫ g.appTop).hom c)) + (germToFunctionField_dominantFunctionFieldHom f) + simpa only [Scheme.Hom.comp_appTop, CommRingCat.hom_comp, RingHom.comp_apply, + CommRingCat.comp_apply] using hn + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +variable {k : Type u} [CommRing k] {X Y : Scheme.{u}} [IsIntegral X] [IsIntegral Y] + +noncomputable def openImmersionFunctionFieldAlgEquiv (f : X ⟶ Y) [IsDominant f] + [IsOpenImmersion f] (g : Y ⟶ Spec (CommRingCat.of k)) : + let : Algebra k Y.functionField := schemeBaseStalkAlgebra g (genericPoint Y) + let : Algebra k X.functionField := schemeBaseStalkAlgebra (f ≫ g) (genericPoint X) + Y.functionField ≃ₐ[k] X.functionField := by + let : Algebra k Y.functionField := schemeBaseStalkAlgebra g (genericPoint Y) + let : Algebra k X.functionField := schemeBaseStalkAlgebra (f ≫ g) (genericPoint X) + let e := openImmersionFunctionFieldEquiv f + exact { e with + commutes' := (dominantFunctionFieldAlgHom f g).commutes } + +noncomputable def normalizationFunctionFieldAlgHom + (f : X ⟶ Y) [IsDominant f] [IsOpenImmersion f] + (g : Y ⟶ Spec (CommRingCat.of k)) : + let : Algebra k X.functionField := schemeBaseStalkAlgebra (f ≫ g) (genericPoint X) + let : Algebra k (genericNormalization Y).functionField := + schemeBaseStalkAlgebra (genericNormalizationMap Y ≫ g) + (genericPoint (genericNormalization Y)) + X.functionField →ₐ[k] (genericNormalization Y).functionField := by + let : Algebra k X.functionField := schemeBaseStalkAlgebra (f ≫ g) (genericPoint X) + let : Algebra k (genericNormalization Y).functionField := + schemeBaseStalkAlgebra (genericNormalizationMap Y ≫ g) + (genericPoint (genericNormalization Y)) + let : Algebra k Y.functionField := schemeBaseStalkAlgebra g (genericPoint Y) + exact (dominantFunctionFieldAlgHom (genericNormalizationMap Y) g).comp + (openImmersionFunctionFieldAlgEquiv f g).symm.toAlgHom + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +noncomputable instance affineFunctionFieldAlgebra (A : Type u) [CommRing A] [IsDomain A] : + Algebra A (Spec (CommRingCat.of A)).functionField := + AlgebraicGeometry.instAlgebraCarrierFunctionFieldSpec (CommRingCat.of A) + +theorem affineFunctionField_isScalarTower (k A : Type u) [CommRing k] [CommRing A] + [IsDomain A] [Algebra k A] : + let : Algebra k (Spec (CommRingCat.of A)).functionField := + schemeBaseStalkAlgebra (Spec.map (CommRingCat.ofHom (algebraMap k A))) + (genericPoint (Spec (CommRingCat.of A))) + IsScalarTower k A (Spec (CommRingCat.of A)).functionField := by + let : Algebra k (Spec (CommRingCat.of A)).functionField := + schemeBaseStalkAlgebra (Spec.map (CommRingCat.ofHom (algebraMap k A))) + (genericPoint (Spec (CommRingCat.of A))) + apply IsScalarTower.of_algebraMap_eq' + change schemeBaseToStalk (Spec.map (CommRingCat.ofHom (algebraMap k A))) + (genericPoint (Spec (CommRingCat.of A))) = _ + rw [schemeBaseToStalk_eq_global_germ, ← Scheme.ΓSpecIso_inv_naturality] + rfl + +noncomputable def affineFractionFieldAlgEquiv (k A : Type u) [CommRing k] [CommRing A] + [IsDomain A] [Algebra k A] : + let : Algebra k (Spec (CommRingCat.of A)).functionField := + schemeBaseStalkAlgebra (Spec.map (CommRingCat.ofHom (algebraMap k A))) + (genericPoint (Spec (CommRingCat.of A))) + FractionRing A ≃ₐ[k] (Spec (CommRingCat.of A)).functionField := by + let : Algebra k (Spec (CommRingCat.of A)).functionField := + schemeBaseStalkAlgebra (Spec.map (CommRingCat.ofHom (algebraMap k A))) + (genericPoint (Spec (CommRingCat.of A))) + have : IsScalarTower k A (Spec (CommRingCat.of A)).functionField := + affineFunctionField_isScalarTower k A + have : IsFractionRing A (Spec (CommRingCat.of A)).functionField := + functionField_isFractionRing_of_affine (CommRingCat.of A) + exact (FractionRing.algEquiv A (Spec (CommRingCat.of A)).functionField).restrictScalars k + +end WeightedTorusJets + +open CategoryTheory _root_.AlgebraicGeometry + +namespace WeightedTorusJets + +universe u + +variable {X Y : Scheme.{u}} (f : X ⟶ Y) [QuasiCompact f] + +theorem isReduced_schemeImage [AlgebraicGeometry.IsReduced X] : + AlgebraicGeometry.IsReduced f.image := by + constructor + intro U + constructor + intro s hs + apply f.image.IsSheaf.section_ext + intro x hx + obtain ⟨_, ⟨_, ⟨V, hV, rfl⟩, rfl⟩, hxV, hVU⟩ := + (Y.isBasis_affineOpens.of_isInducing f.imageι.isEmbedding.isInducing).exists_subset_of_mem_open hx U.isOpen + refine ⟨f.imageι ⁻¹ᵁ V, hVU, hxV, ?_⟩ + apply f.toImage_app_injective ⟨V, hV⟩ + simp only [map_zero] + exact ((hs.map (f.image.presheaf.map (homOfLE hVU).op).hom).map + (f.toImage.app (f.imageι ⁻¹ᵁ V)).hom).eq_zero + +theorem isIntegral_schemeImage [IsIntegral X] : IsIntegral f.image := by + have : AlgebraicGeometry.IsReduced f.image := isReduced_schemeImage f + have : IrreducibleSpace f.image := by + rw [irreducibleSpace_def] + convert! + ((IrreducibleSpace.isIrreducible_univ X).image _ + f.toImage.continuous.continuousOn).closure + simpa using f.toImage.denseRange.closure_range.symm + exact isIntegral_of_irreducibleSpace_of_isReduced _ + +end WeightedTorusJets + +open MvPolynomial HomogeneousLocalization + +namespace WeightedTorusJets.Geometry + +def affineProjEval {k A ι : Type*} [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) : MvPolynomial (Option ι) k →ₐ[k] A := + aeval (Option.elim' 1 x) + +abbrev affineProjChart (k ι : Type*) [CommRing k] := + Away (homogeneousSubmodule (Option ι) k) (X (none : Option ι)) + +def affineProjChartMap {k A ι : Type*} [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) : affineProjChart k ι →+* A := + (IsLocalization.Away.lift (X (none : Option ι)) + (g := (affineProjEval (k := k) x).toRingHom) (by simp [affineProjEval])).comp + (algebraMap (affineProjChart k ι) (Localization.Away (X (none : Option ι) : MvPolynomial (Option ι) k))) + +theorem affineProjChartMap_mk + {k A ι : Type*} [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) (n : ℕ) (p : MvPolynomial (Option ι) k) + (hp : p ∈ homogeneousSubmodule (Option ι) k (n • 1)) : + affineProjChartMap (k := k) x (Away.mk (homogeneousSubmodule (Option ι) k) + (isHomogeneous_X k (none : Option ι)) n p hp) = affineProjEval (k := k) x p := by + change (IsLocalization.Away.lift (X (none : Option ι)) + (S := Localization.Away (X (none : Option ι) : MvPolynomial (Option ι) k)) + (g := (affineProjEval (k := k) x).toRingHom) (by simp [affineProjEval])) + (Localization.mk p ⟨(X (none : Option ι)) ^ n, ⟨n, rfl⟩⟩) = _ + rw [Localization.mk_eq_mk', IsLocalization.Away.lift, IsLocalization.lift_mk'] + rw [Units.mul_inv_eq_iff_eq_mul] + simp [IsUnit.coe_liftRight, affineProjEval] + +theorem affineProjEval_mem_chartMap_range + {k A ι : Type*} [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) (p : MvPolynomial ι k) : aeval x p ∈ (affineProjChartMap (k := k) x).range := by + have hc (c : k) : algebraMap k A c ∈ (affineProjChartMap (k := k) x).range := by + refine ⟨Away.mk (homogeneousSubmodule (Option ι) k) + (isHomogeneous_X k (none : Option ι)) 0 (C c) (by simp), ?_⟩ + rw [affineProjChartMap_mk] + simp [affineProjEval] + have hx (i : ι) : x i ∈ (affineProjChartMap (k := k) x).range := by + refine ⟨Away.mk (homogeneousSubmodule (Option ι) k) + (isHomogeneous_X k (none : Option ι)) 1 (X (some i)) (by simpa using isHomogeneous_X k (some i)), ?_⟩ + rw [affineProjChartMap_mk] + simp [affineProjEval] + induction p using MvPolynomial.induction_on with + | C c => simpa using hc c + | add p q hp hq => simpa using (affineProjChartMap (k := k) x).range.add_mem hp hq + | mul_X p i hp => simpa using (affineProjChartMap (k := k) x).range.mul_mem hp (hx i) + +theorem affineProjChartMap_surjective + {k A ι : Type*} [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) (hx : Function.Surjective (aeval (R := k) x)) : + Function.Surjective (affineProjChartMap (k := k) x) := by + intro a + obtain ⟨p, rfl⟩ := hx a + exact affineProjEval_mem_chartMap_range x p + +theorem affineProjChartMap_fromZero + {k A ι : Type*} [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) (c : homogeneousSubmodule (Option ι) k 0) : + affineProjChartMap (k := k) x + (fromZeroRingHom (homogeneousSubmodule (Option ι) k) + (Submonoid.powers (X (none : Option ι))) c) = affineProjEval (k := k) x c := by + change (IsLocalization.Away.lift (X (none : Option ι)) + (S := Localization.Away (X (none : Option ι) : MvPolynomial (Option ι) k)) + (g := (affineProjEval (k := k) x).toRingHom) (by simp [affineProjEval])) + (algebraMap (MvPolynomial (Option ι) k) + (Localization.Away (X (none : Option ι))) c) = _ + exact IsLocalization.Away.lift_eq _ _ _ + +end WeightedTorusJets.Geometry + +open CategoryTheory _root_.AlgebraicGeometry + +namespace WeightedTorusJets + +universe u + +variable (k ι : Type u) [CommRing k] + +noncomputable def polynomialDegreeZeroEquiv : + k ≃ₐ[k] MvPolynomial.homogeneousSubmodule ι k 0 := by + apply AlgEquiv.ofBijective (Algebra.ofId k (MvPolynomial.homogeneousSubmodule ι k 0)) + constructor + · intro a b h + apply MvPolynomial.C_injective + exact congrArg Subtype.val h + · rintro ⟨p, hp⟩ + refine ⟨p.coeff 0, Subtype.ext ?_⟩ + change MvPolynomial.C (p.coeff 0) = p + exact (MvPolynomial.totalDegree_eq_zero_iff_eq_C.mp + ((MvPolynomial.totalDegree_zero_iff_isHomogeneous ι).mpr hp)).symm + +theorem polynomial_finiteType_degreeZero [Finite ι] : + Algebra.FiniteType (MvPolynomial.homogeneousSubmodule ι k 0) (MvPolynomial ι k) := by + have : IsScalarTower k (MvPolynomial.homogeneousSubmodule ι k 0) (MvPolynomial ι k) := + IsScalarTower.of_algebraMap_eq (R := k) + (S := MvPolynomial.homogeneousSubmodule ι k 0) + (A := MvPolynomial ι k) fun _ ↦ rfl + exact Algebra.FiniteType.of_restrictScalars_finiteType k + (MvPolynomial.homogeneousSubmodule ι k 0) (MvPolynomial ι k) + +noncomputable def polynomialProjToSpec : + Proj (MvPolynomial.homogeneousSubmodule ι k) ⟶ Spec (CommRingCat.of k) := + Proj.toSpecZero (MvPolynomial.homogeneousSubmodule ι k) ≫ + Spec.map (CommRingCat.ofHom (algebraMap k (MvPolynomial.homogeneousSubmodule ι k 0))) + +theorem polynomialProjToSpec_isProper [Finite ι] : IsProper (polynomialProjToSpec k ι) := by + have : Algebra.FiniteType (MvPolynomial.homogeneousSubmodule ι k 0) (MvPolynomial ι k) := + polynomial_finiteType_degreeZero k ι + have : IsIso (CommRingCat.ofHom + (algebraMap k (MvPolynomial.homogeneousSubmodule ι k 0))) := + (ConcreteCategory.isIso_iff_bijective _).mpr (polynomialDegreeZeroEquiv k ι).bijective + dsimp only [polynomialProjToSpec] + infer_instance + +end WeightedTorusJets +namespace WeightedTorusJets.Geometry + +open CategoryTheory _root_.AlgebraicGeometry + +universe u + +attribute [-instance] polynomialGradedAlgebra in +attribute [local instance] MvPolynomial.gradedAlgebra in + +def affineIntoProj {k A ι : Type u} [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) : Spec (CommRingCat.of A) ⟶ Proj (homogeneousSubmodule (Option ι) k) := + Spec.map (CommRingCat.ofHom (affineProjChartMap (k := k) x)) ≫ + Proj.awayι (homogeneousSubmodule (Option ι) k) (X (none : Option ι)) + (show (X (none : Option ι) : MvPolynomial (Option ι) k) ∈ + homogeneousSubmodule (Option ι) k 1 from isHomogeneous_X k (none : Option ι)) (by decide) + +theorem affineIntoProj_isImmersion {k A ι : Type u} + [CommRing k] [CommRing A] [Algebra k A] + (x : ι → A) (hx : Function.Surjective (aeval (R := k) x)) : + IsImmersion (affineIntoProj (k := k) x) := by + have : IsClosedImmersion (Spec.map (CommRingCat.ofHom (affineProjChartMap (k := k) x))) := + IsClosedImmersion.spec_of_surjective _ (affineProjChartMap_surjective x hx) + unfold affineIntoProj + infer_instance + +theorem affineIntoProj_toSpec {k A ι : Type u} + [CommRing k] [CommRing A] [Algebra k A] (x : ι → A) : + affineIntoProj (k := k) x ≫ polynomialProjToSpec k (Option ι) = + Spec.map (CommRingCat.ofHom (algebraMap k A)) := by + simp only [affineIntoProj, polynomialProjToSpec, Category.assoc, + Proj.awayι_toSpecZero_assoc, ← Spec.map_comp] + congr 1 + apply CommRingCat.hom_ext + apply RingHom.ext + intro c + change affineProjChartMap (k := k) x + (fromZeroRingHom (homogeneousSubmodule (Option ι) k) _ + (algebraMap k (homogeneousSubmodule (Option ι) k 0) c)) = algebraMap k A c + rw [affineProjChartMap_fromZero] + change affineProjEval (k := k) x (C c) = _ + simp [affineProjEval] + +theorem exists_proper_immersion_of_finiteType + (k A : Type u) [CommRing k] [CommRing A] [Algebra k A] [Algebra.FiniteType k A] : + ∃ (Y : Scheme.{u}) (f : Spec (CommRingCat.of A) ⟶ Y) + (g : Y ⟶ Spec (CommRingCat.of k)), + IsImmersion f ∧ QuasiCompact f ∧ Scheme.IsSeparated Y ∧ IsProper g ∧ + f ≫ g = Spec.map (CommRingCat.ofHom (algebraMap k A)) := by + obtain ⟨ι, hι, φ, hφ⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial'.mp + (inferInstance : Algebra.FiniteType k A) + let : Fintype ι := hι + let x : ι → A := fun i => φ (X i) + have hx : Function.Surjective (aeval (R := k) x) := by + exact MvPolynomial.aeval_unique φ ▸ hφ + exact ⟨Proj (homogeneousSubmodule (Option ι) k), affineIntoProj x, + polynomialProjToSpec k (Option ι), affineIntoProj_isImmersion x hx, + inferInstance, inferInstance, polynomialProjToSpec_isProper k (Option ι), affineIntoProj_toSpec x⟩ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +universe u + +instance schemeImage_isIntegral {X Y : Scheme.{u}} [IsIntegral X] (f : X ⟶ Y) + [QuasiCompact f] : IsIntegral f.image := isIntegral_schemeImage f + +instance schemeImage_isSeparated {X Y : Scheme.{u}} (f : X ⟶ Y) [Y.IsSeparated] : + f.image.IsSeparated := by + rw [Scheme.isSeparated_iff, ← CategoryTheory.Limits.terminal.comp_from f.imageι] + infer_instance + +theorem exists_normal_proper_model_of_finiteType_domain + (k A : Type u) [Field k] [CharZero k] [CommRing A] [IsDomain A] + [Algebra k A] [Algebra.FiniteType k A] : + ∃ (N : Scheme.{u}) (hN : IsIntegral N), + let : IsIntegral N := hN + ∃ (p : N ⟶ Spec (CommRingCat.of k)), + IsLocallyNoetherian N ∧ (∀ x : N, IsIntegrallyClosed (N.presheaf.stalk x)) ∧ + LocallyOfFiniteType p ∧ UniversallyClosed p ∧ + (let : Algebra k N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + Nonempty (FractionRing A →ₐ[k] N.functionField)) := by + obtain ⟨Y, f, g, hf, hqc, hsep, hproper, hfg⟩ := + Geometry.exists_proper_immersion_of_finiteType k A + let C := f.image + let gC := f.imageι ≫ g + let N := genericNormalization C + let p := genericNormalizationMap C ≫ gC + have : IsFinite (genericNormalizationMap C) := isFinite_genericNormalization k C gC + have : IsLocallyNoetherian N := LocallyOfFiniteType.isLocallyNoetherian p + have hnormal (x : N) : IsIntegrallyClosed (N.presheaf.stalk x) := + _root_.OAI.Erdos970.AlgebraicGeometry.Scheme.Hom.isIntegrallyClosed_stalk_normalization_of_field + (C.fromSpecStalk (genericPoint C)) x + have hcomp : f.toImage ≫ gC = Spec.map (CommRingCat.ofHom (algebraMap k A)) := by + simpa only [gC, ← Category.assoc, Scheme.Hom.toImage_imageι] using hfg + let : Algebra k (Spec (CommRingCat.of A)).functionField := + schemeBaseStalkAlgebra (f.toImage ≫ gC) (genericPoint (Spec (CommRingCat.of A))) + let : Algebra k N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + let e : FractionRing A ≃ₐ[k] (Spec (CommRingCat.of A)).functionField := by + change @AlgEquiv k (FractionRing A) ((Spec (CommRingCat.of A)).functionField) + _ _ _ _ (schemeBaseStalkAlgebra (f.toImage ≫ gC) + (genericPoint (Spec (CommRingCat.of A)))) + rw [hcomp] + exact affineFractionFieldAlgEquiv k A + let φ : (Spec (CommRingCat.of A)).functionField →ₐ[k] N.functionField := + normalizationFunctionFieldAlgHom f.toImage gC + exact ⟨N, inferInstance, p, inferInstance, hnormal, inferInstance, inferInstance, + ⟨φ.comp e.toAlgHom⟩⟩ + +end WeightedTorusJets + +open Polynomial IsLocalRing TensorProduct + +end +end OriginalSourceGeometryOverlay +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalPivotValuationExponent.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalPivotValuationExponent.lean new file mode 100644 index 0000000000000000000000000000000000000000..5735e369572661a06f05c9d12a03d06352fa82a6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalPivotValuationExponent.lean @@ -0,0 +1,37 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.GreedyPivotsWeightLowSpan + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +theorem global_pivot_valuation_exponent_eq {ι : Type*} [Fintype ι] + (α : ι ↪ (Fin 3 → ℕ)) (P : Finset (Fin 3 → ℕ)) + (hP : Set.range α = (P : Set (Fin 3 → ℕ))) (p : ℕ) : + (∑ i, α i 0 / p) = ∑ a ∈ P, ⌊(a 0 : ℝ) / p⌋₊ := by + rw [sum_embedding_eq_sum_finset_of_range α P hP (fun a => a 0 / p)] + simp only [Nat.floor_div_eq_div] + + + +theorem global_pivot_valuation_exponent_cast_eq {ι : Type*} [Fintype ι] + (α : ι ↪ (Fin 3 → ℕ)) (P : Finset (Fin 3 → ℕ)) + (hP : Set.range α = (P : Set (Fin 3 → ℕ))) (p : ℕ) : + ((∑ i, α i 0 / p : ℕ) : ℝ) = ∑ a ∈ P, (⌊(a 0 : ℝ) / p⌋ : ℝ) := by + rw [global_pivot_valuation_exponent_eq α P hP p, Nat.cast_sum] + apply Finset.sum_congr rfl + intro a _ + exact natCast_floor_eq_intCast_floor (by positivity) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalRectanglePivotBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalRectanglePivotBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..88defc1aa2cd406d17caedd0ff0beb8635fd679f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalRectanglePivotBounds.lean @@ -0,0 +1,61 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.GreedyPivotsWeightLowSpan + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open scoped BigOperators + +theorem global_source_rectangle_pivot_bounds {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (H N : ℕ) (hH : 0 < H) + (hHN : H ≤ N) (hN : 18818 ≤ N) (R : (Fin 3 → ℕ) → V) + (e : ℕ ≃ (Fin 3 → ℕ)) + (he : Monotone (fun i => (e i) 0 + H * (e i) 1 + H * (e i) 2)) + (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)) + (hα : Set.range α = + ((greedyPivots K (R ∘ e) (weightedJetIndices H (N ^ 4 - 1)).card).image e : + Set (Fin 3 → ℕ))) + (hspan : Submodule.span K (R '' {a : Fin 3 → ℕ | + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)}) = ⊤) : + let P := (greedyPivots K (R ∘ e) (weightedJetIndices H (N ^ 4 - 1)).card).image e + (N : ℝ) ^ 4 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) / + (4 * 97 ^ 2) ≤ ∑ a ∈ P, (a 0 : ℝ) ∧ + (∑ a ∈ P, ((a 1 : ℝ) + a 2)) ≤ + 192 * (N : ℝ) ^ 4 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) := by + classical + dsimp only + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun a : Fin 3 → ℕ => a 0 + H * a 1 + H * a 2 + let P := (greedyPivots K (R ∘ e) s.card).image e + have hs : ∀ a, a ∈ s ↔ w a ≤ N ^ 4 - 1 := mem_weightedJetIndices_iff hH + let e₀ := restrictWeightSortedEquiv s w (N ^ 4 - 1) hs e he + have hmap : Finset.univ.map α = P := by + apply Finset.coe_injective + rw [Finset.coe_map, Finset.coe_univ, Set.image_univ] + exact hα + have hcard : P.card = N ^ 4 := by rw [← hmap]; simp + have hfinite := finiteGreedyPivots_restrictWeightSortedEquiv + (K := K) s R w (N ^ 4 - 1) hs e he 0 + change finiteGreedyPivots K s R e₀ 0 = P at hfinite + apply weighted_pivot_bounds P H N hH hHN hN hcard + intro a ha + apply fixed_first_greedy_rectangle_weight_bound H N hH R e₀ + (restrictWeightSortedEquiv_monotone s w (N ^ 4 - 1) hs e he) hspan a + rw [hfinite] + exact ha + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalWeightSortedJetEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalWeightSortedJetEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..f9bfe5d8589a0dc005f4988bdf542eb49e811fe5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GlobalWeightSortedJetEquiv.lean @@ -0,0 +1,97 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +theorem exists_weight_sorted_equiv {α : Type*} [Infinite α] [Encodable α] + (w : α → ℕ) (hfinite : ∀ B : ℕ, {a : α | w a ≤ B}.Finite) : + ∃ e : ℕ ≃ α, Monotone (w ∘ e) := by + classical + let pred : α → α → Prop := fun a b => + w a < w b ∨ (w a = w b ∧ Encodable.encode a < Encodable.encode b) + let F : α → Finset α := fun b => (hfinite (w b)).toFinset.filter (fun a => pred a b) + have hmem : ∀ a b, a ∈ F b ↔ pred a b := by + intro a b + simp only [F, Finset.mem_filter, Set.Finite.mem_toFinset, Set.mem_ofPred_eq, pred] + omega + let rank : α → ℕ := fun a => (F a).card + have hrank (a b : α) (hab : pred a b) : rank a < rank b := by + apply Finset.card_lt_card + apply Finset.ssubset_iff_subset_ne.mpr + constructor + · intro c hc + apply (hmem c b).mpr + have hca := (hmem c a).mp hc + dsimp only [pred] at * + omega + · intro hEq + have ha : a ∈ F b := (hmem a b).mpr hab + rw [← hEq] at ha + have h := (hmem a a).mp ha + simp only [pred, lt_self_iff_false, and_false, or_self] at h + have hinj : Function.Injective rank := by + intro a b hab + by_contra hne + have hcode : Encodable.encode a ≠ Encodable.encode b := fun h => + hne (Encodable.encode_injective h) + have horder : pred a b ∨ pred b a := by + dsimp only [pred] + omega + rcases horder with h | h + · have := hrank a b h + omega + · have := hrank b a h + omega + have hweight (a b : α) (hab : rank a ≤ rank b) : w a ≤ w b := by + by_contra h + have hlt := hrank b a (Or.inl (Nat.lt_of_not_ge h)) + omega + let : Infinite (Set.range rank) := (Set.infinite_range_of_injective hinj).to_subtype + let o : ℕ ≃o Set.range rank := Nat.Subtype.orderIsoOfNat (Set.range rank) + let r : α ≃ Set.range rank := Equiv.ofInjective rank hinj + let e : ℕ ≃ α := o.toEquiv.trans r.symm + have he (i : ℕ) : rank (e i) = (o i : ℕ) := + congrArg Subtype.val (r.apply_symm_apply (o i)) + refine ⟨e, ?_⟩ + intro i j hij + apply hweight + rw [he, he] + exact o.monotone hij + +theorem exists_global_weight_sorted_jet_equiv (H : ℕ) (hH : 0 < H) : + ∃ e : ℕ ≃ (Fin 3 → ℕ), + Monotone (fun i => (e i) 0 + H * (e i) 1 + H * (e i) 2) := by + let : Infinite (Fin 3 → ℕ) := Infinite.of_injective + (fun n : ℕ => fun _ : Fin 3 => n) (fun _ _ h => congrFun h 0) + apply exists_weight_sorted_equiv (fun a : Fin 3 → ℕ => a 0 + H * a 1 + H * a 2) + intro B + apply (Set.Finite.pi' (fun _ : Fin 3 => Set.finite_Iic B)).subset + intro a ha i + change a 0 + H * a 1 + H * a 2 ≤ B at ha + have h1 : a 1 ≤ H * a 1 := Nat.le_mul_of_pos_left _ hH + have h2 : a 2 ≤ H * a 2 := Nat.le_mul_of_pos_left _ hH + change a i ≤ B + fin_cases i <;> dsimp <;> omega + +noncomputable def globalWeightSortedJetEquiv (H : ℕ) (hH : 0 < H) : + ℕ ≃ (Fin 3 → ℕ) := (exists_global_weight_sorted_jet_equiv H hH).choose + +theorem globalWeightSortedJetEquiv_monotone (H : ℕ) (hH : 0 < H) : + Monotone (fun i => (globalWeightSortedJetEquiv H hH i) 0 + + H * (globalWeightSortedJetEquiv H hH i) 1 + + H * (globalWeightSortedJetEquiv H hH i) 2) := + (exists_global_weight_sorted_jet_equiv H hH).choose_spec + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GradedIdealQuotient.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GradedIdealQuotient.lean new file mode 100644 index 0000000000000000000000000000000000000000..93d50f85e3fb31625073cef242dcccf487409f36 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GradedIdealQuotient.lean @@ -0,0 +1,222 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.CoefficientSubspaceEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +open scoped BigOperators DirectSum +namespace WeightedTorusJets.Geometry + +@[instance_reducible] +noncomputable def gradedIdealQuotient + {K A : Type*} [Field K] [CommRing A] [Algebra K A] + (𝓐 : ℕ → Submodule K A) [GradedAlgebra 𝓐] + (I : Ideal A) (hI : I.IsHomogeneous 𝓐) : + GradedAlgebra (fun n => (𝓐 n).map (Ideal.Quotient.mkₐ K I).toLinearMap) where + __ := gradedQuotientDecomposition 𝓐 (I.restrictScalars K) hI + one_mem := ⟨1, SetLike.GradedOne.one_mem, by simp⟩ + mul_mem := by + intro i j x y hx hy + obtain ⟨x, hx, rfl⟩ := hx + obtain ⟨y, hy, rfl⟩ := hy + exact ⟨x * y, SetLike.GradedMul.mul_mem hx hy, by simp⟩ + +end WeightedTorusJets.Geometry + +end + +section + +namespace WeightedTorusJets.Geometry + +theorem finrank_homogeneousSubmodule_fin (K : Type*) [Field K] (r n : ℕ) : + Module.finrank K (MvPolynomial.homogeneousSubmodule (Fin r) K n) = + (r + n - 1).choose n := by + simpa using finrank_homogeneousSubmodule (σ := Fin r) (K := K) n + +end WeightedTorusJets.Geometry + +end + +section + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem linear_quotient_map_homogeneous_mem + {K σ τ : Type*} [Field K] (I : Ideal (MvPolynomial σ K)) + (g : MvPolynomial τ K →ₐ[K] (MvPolynomial σ K ⧸ I)) + (hlin : ∀ i, ∃ l : MvPolynomial σ K, + l.IsHomogeneous 1 ∧ g (X i) = Ideal.Quotient.mk I l) + {d : ℕ} {p : MvPolynomial τ K} (hp : p.IsHomogeneous d) : + g p ∈ (homogeneousSubmodule σ K d).map (Ideal.Quotient.mkₐ K I).toLinearMap := by + classical + choose l hl hgl using hlin + have hg : g = (Ideal.Quotient.mkₐ K I).comp (MvPolynomial.aeval l) := by + ext i + simpa only [AlgHom.comp_apply, aeval_X, Ideal.Quotient.mkₐ_eq_mk] using hgl i + refine ⟨MvPolynomial.aeval l p, ?_, ?_⟩ + · change (MvPolynomial.aeval l p).IsHomogeneous d + simpa only [one_mul] using hp.aeval l hl + · rw [hg] + rfl + +theorem linear_quotient_map_gradedSMul + {K σ τ : Type*} [Field K] (I : Ideal (MvPolynomial σ K)) + (g : MvPolynomial τ K →ₐ[K] (MvPolynomial σ K ⧸ I)) + (hlin : ∀ i, ∃ l : MvPolynomial σ K, + l.IsHomogeneous 1 ∧ g (X i) = Ideal.Quotient.mk I l) : + let _ := g.toRingHom.toAlgebra + let _ : Module (MvPolynomial τ K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toModule + let _ : SMul (MvPolynomial τ K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + SetLike.GradedSMul (homogeneousSubmodule τ K) + (fun n => (homogeneousSubmodule σ K n).map + (Ideal.Quotient.mkₐ K I).toLinearMap) := by + let _ := g.toRingHom.toAlgebra + let _ : Module (MvPolynomial τ K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toModule + let _ : SMul (MvPolynomial τ K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + constructor + intro i j p y hp hy + obtain ⟨a, ha, hga⟩ := linear_quotient_map_homogeneous_mem I g hlin hp + obtain ⟨b, hb, hgb⟩ := hy + refine ⟨a * b, ?_, ?_⟩ + · exact SetLike.GradedMul.mul_mem ha hb + · change Ideal.Quotient.mk I (a * b) = g p * y + rw [map_mul] + exact congrArg₂ (· * ·) hga hgb + +end WeightedTorusJets.Geometry + +end + +section + +namespace WeightedTorusJets + +theorem normalization_quotient_finite_torsionFree_finiteVariables {K σ : Type*} [Field K] [Finite σ] {s : ℕ} + (I : Ideal (MvPolynomial σ K)) [I.IsPrime] + (g : MvPolynomial (Fin s) K →ₐ[K] (MvPolynomial σ K ⧸ I)) + (hg : Function.Injective g) (hint : g.toRingHom.IsIntegral) : + let _ := g.toRingHom.toAlgebra + let _ : Module (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toModule + let _ : SMul (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + IsScalarTower K (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) ∧ + Module.Finite (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) ∧ + Module.IsTorsionFree (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := by + let _ := g.toRingHom.toAlgebra + let _ : Module (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toModule + let _ : SMul (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + let : IsScalarTower K (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := + IsScalarTower.of_algHom g + let : Algebra.FiniteType K (MvPolynomial σ K ⧸ I) := + Algebra.FiniteType.of_surjective (Ideal.Quotient.mkₐ K I) Ideal.Quotient.mk_surjective + let : Algebra.FiniteType (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := + Algebra.FiniteType.of_restrictScalars_finiteType K (MvPolynomial (Fin s) K) + (MvPolynomial σ K ⧸ I) + let : Algebra.IsIntegral (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ I) := + ⟨hint⟩ + exact ⟨inferInstance, Algebra.IsIntegral.finite, + Module.isTorsionFree_iff_algebraMap_injective.mpr hg⟩ + +end WeightedTorusJets + +end + +section +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial Filter + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem hilbertPolynomial_normalization_finiteVariables + {K σ : Type*} [Field K] [Finite σ] {d : ℕ} + (I : Ideal (MvPolynomial σ K)) [I.IsPrime] + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + (g : MvPolynomial (Fin (d + 1)) K →ₐ[K] (MvPolynomial σ K ⧸ I)) + (hg : Function.Injective g) (hint : g.toRingHom.IsIntegral) + (hlin : ∀ i, ∃ l : MvPolynomial σ K, + l.IsHomogeneous 1 ∧ g (X i) = Ideal.Quotient.mk I l) : + let _ := g.toRingHom.toAlgebra + let _ : Module (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toModule + let _ : SMul (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + (hilbertPolynomial I hI).natDegree = d ∧ projectiveDegree I hI = + Module.finrank (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := by + let _ := g.toRingHom.toAlgebra + let _ : Module (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toModule + let _ : SMul (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + obtain ⟨htower, hfinite, htfree⟩ := + WeightedTorusJets.normalization_quotient_finite_torsionFree_finiteVariables I g hg hint + let 𝓐 := homogeneousSubmodule (Fin (d + 1)) K + let 𝓜 := degreePiece I + have : GradedAlgebra 𝓜 := gradedIdealQuotient (homogeneousSubmodule σ K) I hI + have : SetLike.GradedSMul 𝓐 𝓜 := linear_quotient_map_gradedSMul I g hlin + have : ∀ m, Module.Finite K (𝓜 m) := by + intro m + have : Module.Finite K (homogeneousSubmodule σ K m) := + Module.Finite.iff_fg.mpr (homogeneousSubmodule_fg σ K m) + exact Module.Finite.map _ _ + have hdim (m : ℕ) : Module.finrank K (𝓐 m) = (m + d).choose d := by + rw [finrank_homogeneousSubmodule_fin] + have hm : d + 1 + m - 1 = m + d := by omega + rw [hm, Nat.choose_symm_add] + have hP : ∀ᶠ m : ℕ in atTop, + (Module.finrank K (𝓜 m) : ℚ) = (hilbertPolynomial I hI).eval (m : ℚ) := by + obtain ⟨N, hN⟩ := hilbertPolynomial_spec I hI + filter_upwards [eventually_gt_atTop N] with m hm + exact hN m hm + have h := hilbertPolynomial_degree_coefficient_eq_rank 𝓐 𝓜 + (a := X (0 : Fin (d + 1))) (X_ne_zero _) (isHomogeneous_X K _) d hdim + (hilbertPolynomial I hI) hP + have heq : (projectiveDegree I hI : ℚ) = + (Module.finrank (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) : ℚ) := by + rw [projectiveDegree_cast, h.1] + exact h.2 + exact ⟨h.1, by exact_mod_cast heq⟩ + +theorem projectiveDegree_eq_normalization_rank_finiteVariables + {K σ : Type*} [Field K] [Finite σ] {d : ℕ} + (I : Ideal (MvPolynomial σ K)) [I.IsPrime] + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + (g : MvPolynomial (Fin (d + 1)) K →ₐ[K] (MvPolynomial σ K ⧸ I)) + (hg : Function.Injective g) (hint : g.toRingHom.IsIntegral) + (hlin : ∀ i, ∃ l : MvPolynomial σ K, + l.IsHomogeneous 1 ∧ g (X i) = Ideal.Quotient.mk I l) : + let _ := g.toRingHom.toAlgebra + let _ : Module (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toModule + let _ : SMul (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + projectiveDegree I hI = + Module.finrank (MvPolynomial (Fin (d + 1)) K) (MvPolynomial σ K ⧸ I) := + (hilbertPolynomial_normalization_finiteVariables I hI g hg hint hlin).2 + +end WeightedTorusJets.Geometry.GradedQuotient +end + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivots.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivots.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d2284cb4a7532110c5f0bea83735d8577ee88a9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivots.lean @@ -0,0 +1,539 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped BigOperators +namespace WeightedTorusJets + +theorem pivot_floor_square_bound {t : ℝ} (ht : 1 ≤ t) : + ((⌊96 * t⌋₊ + 1 : ℕ) : ℝ) ^ 2 ≤ 97 ^ 2 * t ^ 2 := by + have hf := Nat.floor_le (show 0 ≤ 96 * t by positivity) + have hupper : ((⌊96 * t⌋₊ + 1 : ℕ) : ℝ) ≤ 97 * t := by + push_cast + linarith + nlinarith [sq_nonneg (((⌊96 * t⌋₊ + 1 : ℕ) : ℝ) - 97 * t)] + +theorem pivot_second_sum_bound {ι : Type*} (s : Finset ι) (b c : ι → ℕ) + {t : ℝ} (hb : ∀ i ∈ s, (b i : ℝ) ≤ 96 * t) + (hc : ∀ i ∈ s, (c i : ℝ) ≤ 96 * t) : + ∑ i ∈ s, ((b i : ℝ) + c i) ≤ 192 * s.card * t := by + calc + ∑ i ∈ s, ((b i : ℝ) + c i) ≤ ∑ _i ∈ s, (192 * t) := + Finset.sum_le_sum fun i hi => by linarith [hb i hi, hc i hi] + _ = 192 * s.card * t := by simp; ring + +theorem pivot_lower_bound_quarter {M Q S : ℝ} (hQ : 0 < Q) (hM : 2 * Q ≤ M) + (hS : M ^ 2 / (2 * Q) - M / 2 ≤ S) : M ^ 2 / (4 * Q) ≤ S := by + have hnonneg : 0 ≤ M * (M - 2 * Q) := mul_nonneg (by linarith) (by linarith) + have h : M ^ 2 / (4 * Q) ≤ M ^ 2 / (2 * Q) - M / 2 := by + apply (div_le_iff₀ (show 0 < 4 * Q by positivity)).mpr + field_simp + nlinarith + exact h.trans hS + +theorem pivot_lower_constant {M Q H t S : ℝ} (hQ : 0 < Q) (ht : 0 < t) + (hH : 0 < H) (hM : M = H * t ^ 3) (hMQ : 2 * Q ≤ M) + (hQt : Q ≤ 97 ^ 2 * t ^ 2) + (hS : M ^ 2 / (2 * Q) - M / 2 ≤ S) : + M * H * t / (4 * 97 ^ 2) ≤ S := by + have hquarter := pivot_lower_bound_quarter hQ hMQ hS + have hlower : M * H * t / (4 * 97 ^ 2) ≤ M ^ 2 / (4 * Q) := by + apply (le_div_iff₀ (show 0 < 4 * Q by positivity)).mpr + have hnonneg : 0 ≤ M * H * t := by rw [hM]; positivity + have h := mul_le_mul_of_nonneg_left hQt hnonneg + rw [hM] at h ⊢ + nlinarith + exact hlower.trans hquarter + +theorem pivot_ratio_bound {M H t S₁ S₂ : ℝ} (hM : 0 < M) (hH : 0 < H) + (ht : 0 < t) (hS₁ : M * H * t / (4 * 97 ^ 2) ≤ S₁) + (hS₂ : S₂ ≤ 192 * M * t) : S₂ / S₁ ≤ (192 * (4 * 97 ^ 2)) / H := by + have hpos : 0 < S₁ := lt_of_lt_of_le (by positivity) hS₁ + apply (div_le_iff₀ hpos).mpr + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ hH).mpr + have h := mul_le_mul_of_nonneg_left hS₁ (show (0 : ℝ) ≤ 192 * (4 * 97 ^ 2) by norm_num) + have h' := mul_le_mul_of_nonneg_right hS₂ hH.le + nlinarith + +theorem pivot_ratio_le_twelfth {M H t S₁ S₂ : ℝ} (hM : 0 < M) + (hH : 86713344 ≤ H) (ht : 0 < t) + (hS₁ : M * H * t / (4 * 97 ^ 2) ≤ S₁) + (hS₂ : S₂ ≤ 192 * M * t) : S₂ / S₁ ≤ 1 / 12 := by + have hHpos : 0 < H := by linarith + apply (pivot_ratio_bound hM hHpos ht hS₁ hS₂).trans + apply (div_le_iff₀ hHpos).mpr + norm_num at * + linarith + +theorem pivot_scale_ge_one {H N : ℝ} (hH : 1 ≤ H) (hHN : H ≤ N) : + 1 ≤ H ^ (-(1 / 3 : ℝ)) * N ^ (4 / 3 : ℝ) := by + have hHpos : 0 < H := by linarith + calc + 1 ≤ H := hH + _ = H ^ (-(1 / 3 : ℝ)) * H ^ (4 / 3 : ℝ) := by + rw [← Real.rpow_add hHpos] + norm_num + _ ≤ H ^ (-(1 / 3 : ℝ)) * N ^ (4 / 3 : ℝ) := by + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg hHpos.le _) + exact Real.rpow_le_rpow hHpos.le hHN (by norm_num) + +theorem pivot_dimension_eq_cube {N : ℝ} (hN : 0 ≤ N) : + (N ^ (4 / 3 : ℝ)) ^ 3 = N ^ 4 := by + rw [← Real.rpow_natCast, ← Real.rpow_mul hN] + norm_num + +theorem pivot_scale_cube {H N : ℝ} (hH : 0 < H) (hN : 0 ≤ N) : + H * (H ^ (-(1 / 3 : ℝ)) * N ^ (4 / 3 : ℝ)) ^ 3 = N ^ 4 := by + rw [mul_pow, pivot_dimension_eq_cube hN, ← Real.rpow_natCast, + ← Real.rpow_mul hH.le] + norm_num + rw [Real.rpow_neg_one, ← mul_assoc, mul_inv_cancel₀ hH.ne'] + simp + +theorem pivot_primary_scale {H U : ℝ} (hH : 0 < H) : + H * (H ^ (-(1 / 3 : ℝ)) * U) = H ^ (2 / 3 : ℝ) * U := by + rw [← mul_assoc] + have hp := Real.rpow_add hH (1 : ℝ) (-(1 / 3 : ℝ)) + norm_num at hp + rw [← hp] + +theorem pivot_count_threshold {H t Q : ℝ} (hQ : Q ≤ 97 ^ 2 * t ^ 2) + (hscale : 2 * 97 ^ 2 ≤ H * t) : 2 * Q ≤ H * t ^ 3 := by + nlinarith [mul_le_mul_of_nonneg_right hscale (sq_nonneg t)] + +theorem pivot_primary_scale_ge_N {H N : ℝ} (hH : 1 ≤ H) (hN : 1 ≤ N) : + N ≤ H ^ (2 / 3 : ℝ) * N ^ (4 / 3 : ℝ) := by + have hHp : 1 ≤ H ^ (2 / 3 : ℝ) := Real.one_le_rpow hH (by norm_num) + have hNp : N ≤ N ^ (4 / 3 : ℝ) := Real.self_le_rpow_of_one_le hN (by norm_num) + have hprod := mul_le_mul_of_nonneg_right hHp (show 0 ≤ N ^ (4 / 3 : ℝ) by positivity) + simp only [one_mul] at hprod + exact hNp.trans hprod + +theorem pivot_floor_count_eventually {H N : ℝ} (hH : 1 ≤ H) (hHN : H ≤ N) + (hN : 18818 ≤ N) : + 2 * (((⌊96 * (H ^ (-(1 / 3 : ℝ)) * N ^ (4 / 3 : ℝ))⌋₊ + 1 : ℕ) : ℝ) ^ 2) + ≤ N ^ 4 := by + have hHpos : 0 < H := by linarith + have hNnonneg : 0 ≤ N := by linarith + rw [← pivot_scale_cube hHpos hNnonneg] + apply pivot_count_threshold (pivot_floor_square_bound (pivot_scale_ge_one hH hHN)) + rw [pivot_primary_scale hHpos] + have h := pivot_primary_scale_ge_N hH (show 1 ≤ N by linarith) + norm_num + linarith + +theorem pivot_coordinates_of_weight {H U : ℝ} (hH : 0 < H) (a b c : ℕ) + (hw : (a : ℝ) + H * b + H * c ≤ 96 * H ^ (2 / 3 : ℝ) * U) : + (b : ℝ) ≤ 96 * (H ^ (-(1 / 3 : ℝ)) * U) ∧ + (c : ℝ) ≤ 96 * (H ^ (-(1 / 3 : ℝ)) * U) := by + have hs := pivot_primary_scale (U := U) hH + have ha : (0 : ℝ) ≤ a := Nat.cast_nonneg a + have hb : 0 ≤ H * b := mul_nonneg hH.le (Nat.cast_nonneg b) + have hc : 0 ≤ H * c := mul_nonneg hH.le (Nat.cast_nonneg c) + constructor + · apply (mul_le_mul_iff_right₀ hH).mp + nlinarith + · apply (mul_le_mul_iff_right₀ hH).mp + nlinarith + +theorem pivot_weight_of_rectangle {H U : ℝ} (hH : 0 < H) (a b c : ℕ) + (ha : (a : ℝ) ≤ 32 * H ^ (2 / 3 : ℝ) * U) + (hb : (b : ℝ) ≤ 32 * H ^ (-(1 / 3 : ℝ)) * U) + (hc : (c : ℝ) ≤ 32 * H ^ (-(1 / 3 : ℝ)) * U) : + (a : ℝ) + H * b + H * c ≤ 96 * H ^ (2 / 3 : ℝ) * U := by + have hs := pivot_primary_scale (U := U) hH + have hbH := mul_le_mul_of_nonneg_left hb hH.le + have hcH := mul_le_mul_of_nonneg_left hc hH.le + nlinarith + +end WeightedTorusJets + +open scoped BigOperators + +namespace WeightedTorusJets + +theorem card_filter_lt_le_mul {ι : Type*} (s : Finset ι) (a : ι → ℕ) (Q t : ℕ) + (hQ : ∀ k, (s.filter fun i => a i = k).card ≤ Q) : + (s.filter fun i => a i < t).card ≤ Q * t := by + classical + have h := Finset.card_le_mul_card_image_of_maps_to + (s := s.filter fun i => a i < t) (t := Finset.range t) (f := a) + (fun i hi => Finset.mem_range.mpr (Finset.mem_filter.mp hi).2) Q + (fun k _ => le_trans (Finset.card_le_card (by + intro i hi + exact Finset.mem_filter.mpr + ⟨(Finset.mem_filter.mp (Finset.mem_filter.mp hi).1).1, + (Finset.mem_filter.mp hi).2⟩)) (hQ k)) + simpa using h + +theorem card_sq_le_twice_mul_sum_add {ι : Type*} (s : Finset ι) (a : ι → ℕ) + (Q : ℕ) (hQ : ∀ k, (s.filter fun i => a i = k).card ≤ Q) : + s.card * s.card ≤ 2 * Q * (∑ i ∈ s, a i) + Q * s.card := by + classical + have hswap : + (∑ i ∈ s, (s.filter fun j => a i < a j).card) = + ∑ i ∈ s, (s.filter fun j => a j < a i).card := by + simp_rw [Finset.card_filter] + rw [Finset.sum_comm] + have hsplit : s.card * s.card = + 2 * (∑ i ∈ s, (s.filter fun j => a j < a i).card) + + ∑ i ∈ s, (s.filter fun j => a j = a i).card := by + calc + s.card * s.card = ∑ i ∈ s, ∑ j ∈ s, (1 : ℕ) := by simp + _ = ∑ i ∈ s, ∑ j ∈ s, + ((if a j < a i then 1 else 0) + (if a i < a j then 1 else 0) + + (if a j = a i then 1 else 0)) := by + apply Finset.sum_congr rfl + intro i hi + apply Finset.sum_congr rfl + intro j hj + split_ifs <;> omega + _ = (∑ i ∈ s, (s.filter fun j => a j < a i).card) + + (∑ i ∈ s, (s.filter fun j => a i < a j).card) + + ∑ i ∈ s, (s.filter fun j => a j = a i).card := by + simp only [Finset.sum_add_distrib, ← Finset.card_filter] + _ = _ := by rw [hswap]; omega + have hlt : (∑ i ∈ s, (s.filter fun j => a j < a i).card) ≤ + Q * (∑ i ∈ s, a i) := by + rw [Finset.mul_sum] + exact Finset.sum_le_sum fun i _ => card_filter_lt_le_mul s a Q (a i) hQ + have heq : (∑ i ∈ s, (s.filter fun j => a j = a i).card) ≤ Q * s.card := by + calc + _ ≤ ∑ i ∈ s, Q := Finset.sum_le_sum fun i _ => hQ (a i) + _ = _ := by simp [mul_comm] + nlinarith + +theorem sum_lower_of_bounded_multiplicity {ι : Type*} (s : Finset ι) (a : ι → ℕ) + (Q : ℕ) (hQpos : 0 < Q) + (hQ : ∀ k, (s.filter fun i => a i = k).card ≤ Q) : + (s.card : ℝ) ^ 2 / (2 * Q) - s.card / 2 ≤ ∑ i ∈ s, (a i : ℝ) := by + have h : (s.card : ℝ) * s.card ≤ + 2 * (Q : ℝ) * (∑ i ∈ s, (a i : ℝ)) + (Q : ℝ) * s.card := by + exact_mod_cast card_sq_le_twice_mul_sum_add s a Q hQ + have hQpos' : (0 : ℝ) < Q := by exact_mod_cast hQpos + rw [sub_le_iff_le_add, div_le_iff₀ (by positivity : (0 : ℝ) < 2 * Q)] + nlinarith + +theorem coordinate_fiber_card_le (s : Finset (Fin 3 → ℕ)) (B k : ℕ) + (hB : ∀ a ∈ s, a 1 ≤ B ∧ a 2 ≤ B) : + (s.filter fun a => a 0 = k).card ≤ (B + 1) ^ 2 := by + classical + have h := Finset.card_le_card_of_injOn (s := s.filter fun a => a 0 = k) + (t := Finset.range (B + 1) ×ˢ Finset.range (B + 1)) + (fun a => (a 1, a 2)) ?_ ?_ + · simpa [pow_two] using h + · intro a ha + have ha' := (Finset.mem_filter.mp ha).1 + obtain ⟨h1, h2⟩ := hB a ha' + exact Finset.mem_product.mpr ⟨Finset.mem_range.mpr (show a 1 < B + 1 by omega), + Finset.mem_range.mpr (show a 2 < B + 1 by omega)⟩ + · intro a ha b hb hab + have ha0 := (Finset.mem_filter.mp ha).2 + have hb0 := (Finset.mem_filter.mp hb).2 + have ha1 := congrArg Prod.fst hab + have ha2 := congrArg Prod.snd hab + funext i + fin_cases i <;> simp_all + +theorem first_coordinate_sum_lower (s : Finset (Fin 3 → ℕ)) (B : ℕ) + (hB : ∀ a ∈ s, a 1 ≤ B ∧ a 2 ≤ B) : + (s.card : ℝ) ^ 2 / (2 * ((B + 1 : ℕ) : ℝ) ^ 2) - s.card / 2 ≤ + ∑ a ∈ s, (a 0 : ℝ) := by + have h := sum_lower_of_bounded_multiplicity s (fun a => a 0) ((B + 1)^2) + (by positivity) (coordinate_fiber_card_le s B · hB) + simpa using h + + + +theorem weighted_pivot_bounds (P : Finset (Fin 3 → ℕ)) (H N : ℕ) + (hH : 0 < H) (hHN : H ≤ N) (hN : 18818 ≤ N) (hcard : P.card = N ^ 4) + (hw : ∀ a ∈ P, (a 0 : ℝ) + (H : ℝ) * a 1 + (H : ℝ) * a 2 ≤ + 96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)) : + (N : ℝ) ^ 4 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) / + (4 * 97 ^ 2) ≤ ∑ a ∈ P, (a 0 : ℝ) ∧ + (∑ a ∈ P, ((a 1 : ℝ) + a 2)) ≤ + 192 * (N : ℝ) ^ 4 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) := by + let t : ℝ := (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) + have hHpos : (0 : ℝ) < H := by exact_mod_cast hH + have hHone : (1 : ℝ) ≤ H := by exact_mod_cast hH + have hHNreal : (H : ℝ) ≤ N := by exact_mod_cast hHN + have hNreal : (18818 : ℝ) ≤ N := by exact_mod_cast hN + have hNnonneg : (0 : ℝ) ≤ N := Nat.cast_nonneg N + have htone : 1 ≤ t := pivot_scale_ge_one hHone hHNreal + have htpos : 0 < t := by linarith + have hcardreal : (P.card : ℝ) = (N : ℝ) ^ 4 := by exact_mod_cast hcard + have hcoords : ∀ a ∈ P, (a 1 : ℝ) ≤ 96 * t ∧ (a 2 : ℝ) ≤ 96 * t := by + intro a ha + exact pivot_coordinates_of_weight hHpos (a 0) (a 1) (a 2) (hw a ha) + have hcoordsNat : ∀ a ∈ P, a 1 ≤ ⌊96 * t⌋₊ ∧ a 2 ≤ ⌊96 * t⌋₊ := by + intro a ha + exact ⟨Nat.le_floor (hcoords a ha).1, Nat.le_floor (hcoords a ha).2⟩ + have hlower := first_coordinate_sum_lower P ⌊96 * t⌋₊ hcoordsNat + have hlarge : 2 * (((⌊96 * t⌋₊ + 1 : ℕ) : ℝ) ^ 2) ≤ P.card := by + rw [hcardreal] + exact pivot_floor_count_eventually hHone hHNreal hNreal + have hscale : (P.card : ℝ) = (H : ℝ) * t ^ 3 := by + rw [hcardreal] + exact (pivot_scale_cube hHpos hNnonneg).symm + have hfirst := pivot_lower_constant + (show 0 < ((⌊96 * t⌋₊ + 1 : ℕ) : ℝ) ^ 2 by positivity) + htpos hHpos hscale hlarge (pivot_floor_square_bound htone) hlower + constructor + · have hs := pivot_primary_scale (U := (N : ℝ) ^ (4 / 3 : ℝ)) hHpos + change (H : ℝ) * t = _ at hs + rw [hcardreal] at hfirst + simpa only [mul_assoc, hs] using hfirst + · have hsecond := pivot_second_sum_bound P (fun a => a 1) (fun a => a 2) + (fun a ha => (hcoords a ha).1) (fun a ha => (hcoords a ha).2) + rw [hcardreal] at hsecond + simpa [t, mul_assoc] using hsecond + +theorem weighted_pivot_ratio_le_twelfth (P : Finset (Fin 3 → ℕ)) (H N : ℕ) + (hH : 86713344 ≤ H) (hHN : H ≤ N) (hcard : P.card = N ^ 4) + (hw : ∀ a ∈ P, (a 0 : ℝ) + (H : ℝ) * a 1 + (H : ℝ) * a 2 ≤ + 96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)) : + (∑ a ∈ P, ((a 1 : ℝ) + a 2)) / (∑ a ∈ P, (a 0 : ℝ)) ≤ 1 / 12 := by + have hHpos : 0 < H := by omega + have hHposreal : (0 : ℝ) < H := by exact_mod_cast hHpos + have hNposreal : (0 : ℝ) < N := by exact_mod_cast (hHpos.trans_le hHN) + obtain ⟨hfirst, hsecond⟩ := weighted_pivot_bounds P H N hHpos hHN (by omega) hcard hw + have hs := pivot_primary_scale (U := (N : ℝ) ^ (4 / 3 : ℝ)) hHposreal + apply pivot_ratio_le_twelfth + (M := (N : ℝ) ^ 4) (H := H) + (t := (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)) + (by positivity) (by exact_mod_cast hH) (by positivity) + · simpa only [mul_assoc, hs] using hfirst + · simpa only [mul_assoc] using hsecond + + + +open Submodule + +variable {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] + +noncomputable def greedyPivots + {V : Type u_1} [AddCommGroup V] (K : Type u_2) [DivisionRing K] (v : ℕ → V) + [Module K V] : ℕ → Finset ℕ + | 0 => ∅ + | n + 1 => by + classical + exact if v n ∈ span K (v '' (greedyPivots K v n : Set ℕ)) + then greedyPivots K v n else insert n (greedyPivots K v n) + +theorem greedyPivots_subset_range (v : ℕ → V) (n : ℕ) : + greedyPivots K v n ⊆ Finset.range n := by + induction n with + | zero => simp [greedyPivots] + | succ n ih => + classical + simp only [greedyPivots] + split_ifs + · exact ih.trans (Finset.range_mono (Nat.le_succ n)) + · exact Finset.insert_subset (Finset.mem_range.mpr (Nat.lt_succ_self n)) + (ih.trans (Finset.range_mono (Nat.le_succ n))) + +theorem greedyPivots_linearIndepOn (v : ℕ → V) (n : ℕ) : + LinearIndepOn K v (greedyPivots K v n : Set ℕ) := by + induction n with + | zero => simp [greedyPivots] + | succ n ih => + classical + simp only [greedyPivots] + split_ifs with h + · exact ih + · simpa only [Finset.coe_insert] using ih.insert h + +theorem span_greedyPivots (v : ℕ → V) (n : ℕ) : + span K (v '' (greedyPivots K v n : Set ℕ)) = + span K (v '' (Finset.range n : Set ℕ)) := by + induction n with + | zero => rfl + | succ n ih => + classical + simp only [greedyPivots] + split_ifs with h + · rw [Finset.range_add_one, Finset.coe_insert, Set.image_insert_eq, + span_insert_eq_span (ih ▸ h), ih] + · rw [Finset.coe_insert, Finset.range_add_one, Finset.coe_insert, + Set.image_insert_eq, Set.image_insert_eq, span_insert, span_insert, ih] + +theorem mem_greedyPivots_succ_self (v : ℕ → V) (n : ℕ) : + n ∈ greedyPivots K v (n + 1) ↔ + v n ∉ span K (v '' (Finset.range n : Set ℕ)) := by + classical + have hn : n ∉ greedyPivots K v n := fun h => + (Nat.lt_irrefl n) (Finset.mem_range.mp (greedyPivots_subset_range v n h)) + rw [greedyPivots, span_greedyPivots] + split_ifs with h + · exact iff_of_false hn (not_not_intro h) + · exact iff_of_true (Finset.mem_insert_self _ _) h + +theorem greedyPivots_mono (v : ℕ → V) : Monotone (greedyPivots K v) := by + classical + apply monotone_nat_of_le_succ + intro n + simp only [greedyPivots] + split_ifs + · rfl + · exact Finset.subset_insert _ _ + +theorem mem_greedyPivots_iff (v : ℕ → V) (i n : ℕ) : + i ∈ greedyPivots K v n ↔ + i < n ∧ v i ∉ span K (v '' (Finset.range i : Set ℕ)) := by + classical + induction n with + | zero => simp [greedyPivots] + | succ n ih => + by_cases hin : i < n + · have hne : i ≠ n := Nat.ne_of_lt hin + rw [greedyPivots] + split_ifs + · simpa only [hin, Nat.lt_succ_of_lt hin, true_and] using ih + · simpa only [Finset.mem_insert, hne, false_or, hin, + Nat.lt_succ_of_lt hin, true_and] using ih + · by_cases hieq : i = n + · subst i + simpa only [Nat.lt_succ_self, true_and] using mem_greedyPivots_succ_self v n + · have hnle : n + 1 ≤ i := by omega + have hi : i ∉ greedyPivots K v (n + 1) := fun h => + (Nat.not_lt.mpr hnle) + (Finset.mem_range.mp (greedyPivots_subset_range v (n + 1) h)) + exact iff_of_false hi (fun h => Nat.not_lt.mpr hnle h.1) + +theorem card_greedyPivots (v : ℕ → V) (n : ℕ) : + (greedyPivots K v n).card = + Module.finrank K (span K (v '' (Finset.range n : Set ℕ))) := by + classical + have h := finrank_span_eq_card (greedyPivots_linearIndepOn (K := K) v n) + rw [← Set.image_eq_range, span_greedyPivots] at h + rw [Fintype.card_of_finset' (greedyPivots K v n) (fun _ => Iff.rfl)] at h + exact h.symm + +theorem earlier_row_mem_span_greedyPivots (v : ℕ → V) {i n : ℕ} (hi : i < n) : + v i ∈ span K (v '' (greedyPivots K v n : Set ℕ)) := by + rw [span_greedyPivots] + exact subset_span ⟨i, Finset.mem_range.mpr hi, rfl⟩ + +theorem smaller_weight_row_mem_span_greedyPivots (v : ℕ → V) (w : ℕ → ℕ) + (hw : Monotone w) {i n : ℕ} (hi : w i < w n) : + v i ∈ span K (v '' (greedyPivots K v n : Set ℕ)) := by + apply earlier_row_mem_span_greedyPivots + exact lt_of_not_ge (fun h => (not_le_of_gt hi) (hw h)) + +theorem card_greedyPivots_of_span_eq_top (v : ℕ → V) (n : ℕ) + (hspan : span K (v '' (Finset.range n : Set ℕ)) = ⊤) : + (greedyPivots K v n).card = Module.finrank K V := by + rw [card_greedyPivots, hspan, finrank_top] + +theorem greedyPivots_eq_of_span_eq_top (v : ℕ → V) {n m : ℕ} (hnm : n ≤ m) + (hspan : span K (v '' (Finset.range n : Set ℕ)) = ⊤) : + greedyPivots K v n = greedyPivots K v m := by + have hspanm : span K (v '' (Finset.range m : Set ℕ)) = ⊤ := by + apply top_unique + rw [← hspan] + exact span_mono (Set.image_mono (Finset.range_mono hnm)) + apply Finset.eq_of_subset_of_card_le (greedyPivots_mono v hnm) + rw [card_greedyPivots_of_span_eq_top v n hspan, + card_greedyPivots_of_span_eq_top v m hspanm] + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem exists_weight_sorted_enumeration {α : Type*} (s : Finset α) (w : α → ℕ) : + ∃ e : Fin s.card ≃ s, Monotone (fun i => w (e i)) := by + classical + let l : List s := (Finset.univ : Finset s).toList.mergeSort + (fun a b => decide (w a ≤ w b)) + have hlen : l.length = s.card := by simp [l] + have hnd : l.Nodup := + ((Finset.univ : Finset s).nodup_toList).mergeSort + have hmem : ∀ x : s, x ∈ l := by simp [l] + have hpw : l.Pairwise (fun a b : s => w a ≤ w b) := by + have h := List.pairwise_mergeSort + (le := fun a b : s => decide (w a ≤ w b)) + (fun a b c hab hbc => by + simp only [decide_eq_true_eq] at hab hbc ⊢ + exact le_trans hab hbc) + (fun a b => by simp [le_total (w a) (w b)]) (Finset.univ : Finset s).toList + simpa only [decide_eq_true_eq] using h + refine ⟨(finCongr hlen.symm).trans (hnd.getEquivOfForallMemList l hmem), ?_⟩ + intro i j hij + change w (l.get (Fin.cast hlen.symm i)) ≤ w (l.get (Fin.cast hlen.symm j)) + exact hpw.rel_get_of_le hij + +def extendFiniteFamily {α : Type*} {n : ℕ} (f : Fin n → α) (fallback : α) (i : ℕ) : α := + if hi : i < n then f ⟨i, hi⟩ else fallback + +theorem image_extendFiniteFamily_range {α : Type*} {n : ℕ} (f : Fin n → α) + (fallback : α) : + extendFiniteFamily f fallback '' (Finset.range n : Set ℕ) = Set.range f := by + ext x + constructor + · rintro ⟨i, hi, rfl⟩ + have hin : i < n := Finset.mem_range.mp hi + exact ⟨⟨i, hin⟩, by simp [extendFiniteFamily, hin]⟩ + · rintro ⟨i, rfl⟩ + exact ⟨i, Finset.mem_range.mpr i.isLt, by simp [extendFiniteFamily, i.isLt]⟩ + +theorem monotone_extendFiniteFamily {α : Type*} [Preorder α] {n : ℕ} + (f : Fin n → α) (fallback : α) (hf : Monotone f) (hb : ∀ i, f i ≤ fallback) : + Monotone (extendFiniteFamily f fallback) := by + intro i j hij + simp only [extendFiniteFamily] + split_ifs with hi hj hj + · exact hf hij + · exact hb _ + · exact (hi (lt_of_le_of_lt hij hj)).elim + · exact le_rfl + +theorem exists_weight_sorted_cutoff_sequence {α β : Type*} (s : Finset α) + (w : α → ℕ) (R : α → β) (fallback : β) (B : ℕ) + (hs : ∀ a, a ∈ s ↔ w a ≤ B) : + ∃ (v : ℕ → β) (wt : ℕ → ℕ), Monotone wt ∧ + v '' (Finset.range s.card : Set ℕ) = R '' (s : Set α) ∧ + (∀ a, w a ≤ B → ∃ i < s.card, v i = R a ∧ wt i = w a) ∧ + (∀ i < s.card, ∃ a ∈ s, v i = R a ∧ wt i = w a) := by + classical + obtain ⟨e, he⟩ := exists_weight_sorted_enumeration s w + let v := extendFiniteFamily (fun i => R (e i)) fallback + let wt := extendFiniteFamily (fun i => w (e i)) B + have hb : ∀ i, w (e i) ≤ B := fun i => (hs _).mp (e i).property + refine ⟨v, wt, monotone_extendFiniteFamily _ _ he hb, ?_, ?_, ?_⟩ + · change extendFiniteFamily (fun i => R (e i)) fallback '' _ = _ + rw [image_extendFiniteFamily_range] + ext x + constructor + · rintro ⟨i, rfl⟩ + exact ⟨e i, (e i).property, rfl⟩ + · rintro ⟨a, ha, rfl⟩ + exact ⟨e.symm ⟨a, ha⟩, by simp⟩ + · intro a ha + let i := e.symm ⟨a, (hs a).mpr ha⟩ + refine ⟨i, i.isLt, ?_, ?_⟩ + · simp [v, extendFiniteFamily, i.isLt, i] + · simp [wt, extendFiniteFamily, i.isLt, i] + · intro i hi + refine ⟨e ⟨i, hi⟩, (e ⟨i, hi⟩).property, ?_, ?_⟩ + · simp [v, extendFiniteFamily, hi] + · simp [wt, extendFiniteFamily, hi] + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivotsRingEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivotsRingEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..df2575c824471834ddfe54d9c35be62bf05c61d2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivotsRingEquiv.lean @@ -0,0 +1,37 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.AlgebraMapMemSpanImage + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace WeightedTorusJets + +theorem greedyPivots_ringEquiv {K L ι : Type*} [Field K] [Field L] [Fintype ι] + (e : K ≃+* L) (v : ℕ → ι → K) (T : ℕ) : + greedyPivots L (fun i => e ∘ v i) T = greedyPivots K v T := by + let : Algebra K L := e.toRingHom.toAlgebra + exact greedyPivots_algebraMap (L := L) v T + +theorem source_greedy_indices_transport {K L ι α : Type*} + [Field K] [Field L] [Fintype ι] + (e : K ≃+* L) (R : α → ι → K) (R' : α → ι → L) + (hR : ∀ a j, e (R a j) = R' a j) (order : ℕ → α) (T : ℕ) : + greedyPivots L (R' ∘ order) T = greedyPivots K (R ∘ order) T := by + have h : R' ∘ order = fun i => e ∘ (R ∘ order) i := by + funext i j + exact (hR (order i) j).symm + rw [h] + exact greedyPivots_ringEquiv e (R ∘ order) T + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivotsWeightLowSpan.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivotsWeightLowSpan.lean new file mode 100644 index 0000000000000000000000000000000000000000..1eedfa02c1f90d1f678523691de56a0a49683afb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/GreedyPivotsWeightLowSpan.lean @@ -0,0 +1,181 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.RestrictWeightSortedEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open Submodule + +theorem greedyPivots_weight_le_of_low_span {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (v : ℕ → V) (wt : ℕ → ℕ) (hwt : Monotone wt) + (T B : ℕ) (hspan : span K (v '' {j : ℕ | j < T ∧ wt j ≤ B}) = ⊤) : + ∀ i ∈ greedyPivots K v T, wt i ≤ B := by + intro i hi + by_contra h + have hiweight : B < wt i := Nat.lt_of_not_ge h + have hprevious : span K (v '' (Finset.range i : Set ℕ)) = ⊤ := by + apply top_unique + rw [← hspan] + apply span_mono + apply Set.image_mono + intro j hj + apply Finset.mem_range.mpr + exact lt_of_not_ge (fun hij => (not_le_of_gt (hj.2.trans_lt hiweight)) (hwt hij)) + have hnot := ((mem_greedyPivots_iff v i T).mp hi).2 + apply hnot + rw [hprevious] + exact mem_top + +theorem span_low_sequence_eq_top_of_coverage {K V α : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (v : ℕ → V) (wt : ℕ → ℕ) + (R : α → V) (w : α → ℕ) (T B : ℕ) + (hcover : ∀ a, w a ≤ B → ∃ j < T, wt j = w a ∧ v j = R a) + (hspan : span K (R '' {a : α | w a ≤ B}) = ⊤) : + span K (v '' {j : ℕ | j < T ∧ wt j ≤ B}) = ⊤ := by + apply top_unique + rw [← hspan] + apply span_mono + rintro _ ⟨a, ha, rfl⟩ + obtain ⟨j, hj, hjw, hjv⟩ := hcover a ha + exact ⟨j, ⟨hj, hjw.trans_le ha⟩, hjv⟩ + +end WeightedTorusJets + +namespace WeightedTorusJets + +open Submodule + +theorem finite_sorted_greedy_weight_le_of_spanning_cutoff + {K V α : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] + (s : Finset α) (R : α → V) (e : Fin s.card ≃ s) (fallback : α) + (w : α → ℕ) (B₀ B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B₀) + (hsort : Monotone (fun i => w (e i))) + (hspan : span K (R '' {a : α | w a ≤ B}) = ⊤) : + let a := extendFiniteFamily (fun i => (e i : α)) fallback + ∀ i ∈ greedyPivots K (R ∘ a) s.card, w (a i) ≤ B := by + classical + dsimp only + let a := extendFiniteFamily (fun i => (e i : α)) fallback + let v := R ∘ a + change ∀ i ∈ greedyPivots K v s.card, w (a i) ≤ B + by_cases hB₀B : B₀ ≤ B + · intro i hi + have hiT : i < s.card := Finset.mem_range.mp (greedyPivots_subset_range v s.card hi) + change w (extendFiniteFamily (fun i => (e i : α)) fallback i) ≤ B + simp only [extendFiniteFamily, dite_eq_left hiT] + exact ((hs _).mp (e ⟨i, hiT⟩).property).trans hB₀B + · have hBB₀ : B ≤ B₀ := Nat.le_of_lt (Nat.lt_of_not_ge hB₀B) + let wt := extendFiniteFamily (fun i => w (e i)) B₀ + have hwt : Monotone wt := + monotone_extendFiniteFamily _ _ hsort (fun i => (hs _).mp (e i).property) + have hcover : ∀ b, w b ≤ B → ∃ j < s.card, wt j = w b ∧ v j = R b := by + intro b hb + let j : Fin s.card := e.symm ⟨b, (hs b).mpr (hb.trans hBB₀)⟩ + refine ⟨j, j.isLt, ?_, ?_⟩ + · simp [wt, extendFiniteFamily, j.isLt, j] + · simp [v, a, extendFiniteFamily, j.isLt, j] + have hlow := span_low_sequence_eq_top_of_coverage v wt R w s.card B hcover hspan + intro i hi + have hiT : i < s.card := Finset.mem_range.mp (greedyPivots_subset_range v s.card hi) + have hbound := greedyPivots_weight_le_of_low_span v wt hwt s.card B hlow i hi + simpa [wt, a, extendFiniteFamily, hiT] using hbound + +theorem finiteGreedyPivots_weight_le_of_spanning_cutoff + {K V α : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] + (s : Finset α) (R : α → V) (e : Fin s.card ≃ s) (fallback : α) + (w : α → ℕ) (B₀ B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B₀) + (hsort : Monotone (fun i => w (e i))) + (hspan : span K (R '' {a : α | w a ≤ B}) = ⊤) : + ∀ b ∈ finiteGreedyPivots K s R e fallback, w b ≤ B := by + classical + intro b hb + obtain ⟨i, hi, rfl⟩ := Finset.mem_image.mp hb + exact finite_sorted_greedy_weight_le_of_spanning_cutoff + s R e fallback w B₀ B hs hsort hspan i hi + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem fixed_first_greedy_rectangle_weight_bound {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (H N : ℕ) (hH : 0 < H) + (R : (Fin 3 → ℕ) → V) + (e : Fin (weightedJetIndices H (N ^ 4 - 1)).card ≃ weightedJetIndices H (N ^ 4 - 1)) + (hsort : Monotone (fun i => (e i).1 0 + H * (e i).1 1 + H * (e i).1 2)) + (hspan : Submodule.span K (R '' {a : Fin 3 → ℕ | + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)}) = ⊤) : + ∀ a ∈ finiteGreedyPivots K (weightedJetIndices H (N ^ 4 - 1)) R e 0, + (a 0 : ℝ) + (H : ℝ) * a 1 + (H : ℝ) * a 2 ≤ + 96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) := by + let w := fun a : Fin 3 → ℕ => a 0 + H * a 1 + H * a 2 + let B := ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)⌋₊ + have hsets : (weightedJetIndices H B : Set (Fin 3 → ℕ)) = {a | w a ≤ B} := by + ext a + exact mem_weightedJetIndices_iff hH a + have hlow : Submodule.span K (R '' {a : Fin 3 → ℕ | w a ≤ B}) = ⊤ := by + rw [← hsets] + exact span_cutoff_eq_top_of_rectangle hH R hspan + have hbound := finiteGreedyPivots_weight_le_of_spanning_cutoff + (weightedJetIndices H (N ^ 4 - 1)) R e 0 w (N ^ 4 - 1) B + (mem_weightedJetIndices_iff hH) hsort hlow + intro a ha + exact weightedJetIndices_real_weight hH (by positivity) + ((mem_weightedJetIndices_iff hH a).mpr (hbound a ha)) + + + +theorem finiteGreedyPivots_restrictWeightSortedEquiv_map + {K V α : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] + (s : Finset α) (R : α → V) (w : α → ℕ) (B : ℕ) + (hs : ∀ a, a ∈ s ↔ w a ≤ B) (e : ℕ ≃ α) + (he : Monotone (fun i => w (e i))) (fallback : α) : + finiteGreedyPivots K s R (restrictWeightSortedEquiv s w B hs e he) fallback = + (greedyPivots K (R ∘ e) s.card).map e.toEmbedding := by + classical + unfold finiteGreedyPivots + dsimp only + rw [greedyPivots_restrictWeightSortedEquiv s R w B hs e he fallback, + Finset.map_eq_image] + apply Finset.image_congr + intro i hi + exact extend_restrictWeightSortedEquiv_eq s w B hs e he fallback i + (Finset.mem_range.mp (greedyPivots_subset_range (R ∘ e) s.card hi)) + +theorem finiteGreedyPivots_restrictWeightSortedEquiv + {K V α : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [DecidableEq α] + (s : Finset α) (R : α → V) (w : α → ℕ) (B : ℕ) + (hs : ∀ a, a ∈ s ↔ w a ≤ B) (e : ℕ ≃ α) + (he : Monotone (fun i => w (e i))) (fallback : α) : + finiteGreedyPivots K s R (restrictWeightSortedEquiv s w B hs e he) fallback = + (greedyPivots K (R ∘ e) s.card).image e := by + rw [finiteGreedyPivots_restrictWeightSortedEquiv_map, Finset.map_eq_image] + rfl + + + +theorem sum_embedding_eq_sum_finset_of_range {ι α A : Type*} [Fintype ι] + [AddCommMonoid A] (p : ι ↪ α) (s : Finset α) + (hp : Set.range p = (s : Set α)) (f : α → A) : + ∑ i, f (p i) = ∑ a ∈ s, f a := by + classical + have hs : Finset.univ.map p = s := by + apply Finset.coe_injective + rw [Finset.coe_map, Finset.coe_univ, Set.image_univ] + exact hp + rw [← hs, Finset.sum_map] + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/HilbertSeries.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/HilbertSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..195be28bb9b3bbf3bfcd0a81f47948119bc15f2a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/HilbertSeries.lean @@ -0,0 +1,519 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.DegreeMap + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +open MvPolynomial +noncomputable section +open scoped BigOperators +open scoped BigOperators +namespace PowerSeries + +open _root_.PowerSeries + +variable {F : Type*} [Field F] + +theorem coeff_mul_invOneSubPow_one (S : PowerSeries F) (n : ℕ) : + (S * invOneSubPow F 1).coeff n = ∑ j ∈ Finset.range (n + 1), S.coeff j := by + rw [_root_.PowerSeries.coeff_mul, Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk] + simp [invOneSubPow] + +theorem sum_coeff_mul_invOneSubPow (p : Polynomial F) (d n : ℕ) : + (∑ j ∈ Finset.range (n + 1), (p * invOneSubPow F d : PowerSeries F).coeff j) = + (p * invOneSubPow F (d + 1) : PowerSeries F).coeff n := by + rw [← coeff_mul_invOneSubPow_one, invOneSubPow_add, Units.val_mul, mul_assoc] + +theorem sum_coeff_mul_invOneSubPow_eq_hilbertPoly_eval [CharZero F] (p : Polynomial F) + (d : ℕ) {n : ℕ} (hn : p.natDegree < n) : + (∑ j ∈ Finset.range (n + 1), (p * invOneSubPow F d : PowerSeries F).coeff j) = + (Polynomial.hilbertPoly p (d + 1)).eval (n : F) := by + rw [sum_coeff_mul_invOneSubPow] + exact Polynomial.coeff_mul_invOneSubPow_eq_hilbertPoly_eval _ hn + +theorem exists_reduced_mul_invOneSubPow (p : Polynomial F) (d : ℕ) : + ∃ q : Polynomial F, ∃ e : ℕ, + (p * invOneSubPow F d : PowerSeries F) = q * invOneSubPow F e ∧ + (e = 0 ∨ q.eval 1 ≠ 0) := by + induction d generalizing p with + | zero => exact ⟨p, 0, rfl, Or.inl rfl⟩ + | succ d ih => + by_cases hp : p.eval 1 = 0 + · obtain ⟨q, hq⟩ := Polynomial.dvd_iff_isRoot.mpr hp + have hfactor : p = (1 - Polynomial.X) * (-q) := by + rw [hq] + simp only [Polynomial.C_1] + ring + have hcancel : (p * invOneSubPow F (d + 1) : PowerSeries F) = + (-q : Polynomial F) * invOneSubPow F d := by + rw [hfactor, Polynomial.coe_mul, Polynomial.coe_sub, + Polynomial.coe_one, Polynomial.coe_X] + calc + _ = ((-q : Polynomial F) : PowerSeries F) * + ((1 - _root_.PowerSeries.X) ^ 1 * (invOneSubPow F (d + 1)).val) := by ring + _ = _ := by rw [one_sub_pow_mul_invOneSubPow_val_add_eq_invOneSubPow_val] + obtain ⟨r, e, hre, he⟩ := ih (-q) + exact ⟨r, e, hcancel.trans hre, he⟩ + · exact ⟨p, d + 1, rfl, Or.inr hp⟩ + +end PowerSeries + +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial + +variable {K σ : Type*} [Field K] [Finite σ] + +attribute [local instance] MvPolynomial.gradedAlgebra + +noncomputable def hilbertSeries (I : Ideal (MvPolynomial σ K)) : PowerSeries ℚ := + PowerSeries.mk fun n ↦ (Module.finrank K (degreePiece I n) : ℚ) + +theorem hilbertSeries_eq_add_X_mul_colon {I : Ideal (MvPolynomial σ K)} + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) (i : σ) : + hilbertSeries I = hilbertSeries (I ⊔ Ideal.span {X i}) + + PowerSeries.X * hilbertSeries (I.colon {X i}) := by + ext n + rw [map_add, ← pow_one (PowerSeries.X : PowerSeries ℚ), PowerSeries.coeff_X_pow_mul'] + simp only [hilbertSeries, PowerSeries.coeff_mk] + have h := finrank_degreePiece_sup_span_add_colon hI (isHomogeneous_X K i) n + split_ifs with hn + · rw [ite_eq_left hn] at h + exact_mod_cast h.symm + · rw [ite_eq_right hn, add_zero] at h + simpa only [add_zero] using congrArg (Nat.cast : ℕ → ℚ) h.symm + +theorem exists_hilbertSeries_numerator (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + ∃ d : ℕ, ∃ p : Polynomial ℚ, + (1 - PowerSeries.X) ^ d * hilbertSeries I = (p : PowerSeries ℚ) := by + apply hilbertRational_of_noetherian_recurrence hilbertSeries + (fun J ↦ J.IsHomogeneous (homogeneousSubmodule σ K)) ?_ I hI + intro J hJ + by_cases hvars : ∀ i : σ, X i ∈ J + · left + have hconstant : hilbertSeries J = + (Polynomial.C (Module.finrank K (degreePiece J 0) : ℚ) : PowerSeries ℚ) := by + ext n + cases n with + | zero => simp [hilbertSeries] + | succ n => + simp [hilbertSeries, finrank_degreePiece_eq_zero_of_variables_mem J hvars (Nat.succ_pos n)] + rw [hconstant] + exact HilbertRational.polynomial _ + · right + push Not at hvars + obtain ⟨i, hi⟩ := hvars + refine ⟨J ⊔ Ideal.span {X i}, J.colon {X i}, ?_, Ideal.le_colon, + ?_, colon_isHomogeneous hJ (isHomogeneous_X K i), + hilbertSeries_eq_add_X_mul_colon hJ i⟩ + · refine lt_of_le_of_ne le_sup_left ?_ + intro heq + apply hi + rw [heq] + exact (le_sup_right : Ideal.span {X i} ≤ J ⊔ Ideal.span {X i}) + (Ideal.subset_span (Set.mem_singleton (X i))) + · apply hJ.sup + apply Ideal.homogeneous_span + intro f hf + rcases hf with rfl + exact ⟨1, isHomogeneous_X K i⟩ + +theorem exists_hilbertSeries_eq_mul_invOneSubPow (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + ∃ p : Polynomial ℚ, ∃ d : ℕ, + hilbertSeries I = p * PowerSeries.invOneSubPow ℚ d := + HilbertRational.exists_mul_invOneSubPow (exists_hilbertSeries_numerator I hI) + +theorem existsUnique_hilbertPolynomial (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + ∃! P : Polynomial ℚ, ∃ N : ℕ, ∀ n > N, + (Module.finrank K (degreePiece I n) : ℚ) = P.eval (n : ℚ) := by + obtain ⟨p, d, hpd⟩ := exists_hilbertSeries_eq_mul_invOneSubPow I hI + have h := Polynomial.existsUnique_hilbertPoly p d + simpa only [← hpd, hilbertSeries, PowerSeries.coeff_mk] using h + +noncomputable def hilbertPolynomial (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : Polynomial ℚ := + (existsUnique_hilbertPolynomial I hI).choose + +theorem hilbertPolynomial_spec (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + ∃ N : ℕ, ∀ n > N, + (Module.finrank K (degreePiece I n) : ℚ) = (hilbertPolynomial I hI).eval (n : ℚ) := + (existsUnique_hilbertPolynomial I hI).choose_spec.1 + +theorem hilbertPolynomial_eq_of_eventual_eval (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) {P : Polynomial ℚ} + (hP : ∃ N : ℕ, ∀ n > N, + (Module.finrank K (degreePiece I n) : ℚ) = P.eval (n : ℚ)) : + hilbertPolynomial I hI = P := + ((existsUnique_hilbertPolynomial I hI).choose_spec.2 P hP).symm + +theorem exists_component_cumulative_hilbertPoly (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + ∃ p : Polynomial ℚ, ∃ d : ℕ, ∀ n > p.natDegree, + (Module.finrank K (degreePiece I n) : ℚ) = + (Polynomial.hilbertPoly p d).eval (n : ℚ) ∧ + (∑ j ∈ Finset.range (n + 1), (Module.finrank K (degreePiece I j) : ℚ)) = + (Polynomial.hilbertPoly p (d + 1)).eval (n : ℚ) := by + obtain ⟨p, d, hpd⟩ := exists_hilbertSeries_eq_mul_invOneSubPow I hI + refine ⟨p, d, fun n hn ↦ ⟨?_, ?_⟩⟩ + · have h := Polynomial.coeff_mul_invOneSubPow_eq_hilbertPoly_eval (p := p) d hn + simpa only [← hpd, hilbertSeries, PowerSeries.coeff_mk] using h + · have h := PowerSeries.sum_coeff_mul_invOneSubPow_eq_hilbertPoly_eval p d hn + simpa only [← hpd, hilbertSeries, PowerSeries.coeff_mk] using h + +theorem exists_reduced_hilbertSeries (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + ∃ p : Polynomial ℚ, ∃ d : ℕ, + hilbertSeries I = p * PowerSeries.invOneSubPow ℚ d ∧ + (d = 0 ∨ p.eval 1 ≠ 0) := by + obtain ⟨p, d, hpd⟩ := exists_hilbertSeries_eq_mul_invOneSubPow I hI + obtain ⟨q, e, hqe, hred⟩ := PowerSeries.exists_reduced_mul_invOneSubPow p d + exact ⟨q, e, hpd.trans hqe, hred⟩ + +theorem exists_cumulative_hilbertPolynomial (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + (hne : hilbertPolynomial I hI ≠ 0) : + ∃ Q : Polynomial ℚ, + (∃ N : ℕ, ∀ n > N, + (∑ j ∈ Finset.range (n + 1), (Module.finrank K (degreePiece I j) : ℚ)) = + Q.eval (n : ℚ)) ∧ + Q.natDegree = (hilbertPolynomial I hI).natDegree + 1 ∧ + Q.leadingCoeff = (hilbertPolynomial I hI).leadingCoeff / + ((hilbertPolynomial I hI).natDegree + 1 : ℚ) := by + obtain ⟨p, d, hpd, hred⟩ := exists_reduced_hilbertSeries I hI + have hP : hilbertPolynomial I hI = Polynomial.hilbertPoly p d := by + apply hilbertPolynomial_eq_of_eventual_eval + refine ⟨p.natDegree, fun n hn ↦ ?_⟩ + have h := Polynomial.coeff_mul_invOneSubPow_eq_hilbertPoly_eval (p := p) d hn + simpa only [← hpd, hilbertSeries, PowerSeries.coeff_mk] using h + have hd : d ≠ 0 := by + intro hd + apply hne + rw [hP, hd, Polynomial.hilbertPoly_zero_right] + obtain ⟨e, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hd + have hp : p.eval 1 ≠ 0 := hred.resolve_left hd + refine ⟨Polynomial.hilbertPoly p (e + 2), ⟨p.natDegree, fun n hn ↦ ?_⟩, ?_, ?_⟩ + · have h := PowerSeries.sum_coeff_mul_invOneSubPow_eq_hilbertPoly_eval p (e + 1) hn + simpa only [← hpd, hilbertSeries, PowerSeries.coeff_mk] using h + · simp only [hP, show e + 2 = (e + 1) + 1 by omega, + Polynomial.natDegree_hilbertPoly_succ_of_eval_one_ne_zero hp] + · rw [hP, Polynomial.natDegree_hilbertPoly_succ_of_eval_one_ne_zero hp] + rw [show e + 2 = (e + 1) + 1 by omega] + rw [Polynomial.leadingCoeff_hilbertPoly_succ_of_eval_one_ne_zero hp, + Polynomial.leadingCoeff_hilbertPoly_succ_of_eval_one_ne_zero hp] + rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] + rw [div_div] + congr 1 + ring + +end WeightedTorusJets.Geometry.GradedQuotient + +open Filter + +namespace WeightedTorusJets.Geometry + +theorem leadingCoeff_pos_of_eventually_nat_eval_nonneg (P : Polynomial ℚ) (hP : P ≠ 0) + (hpos : ∀ᶠ n : ℕ in atTop, 0 ≤ P.eval (n : ℚ)) : 0 < P.leadingCoeff := by + by_contra h + have hneg : P.leadingCoeff < 0 := + lt_of_le_of_ne (le_of_not_gt h) (Polynomial.leadingCoeff_ne_zero.mpr hP) + by_cases hdeg : 0 < P.degree + · have hlim : Tendsto (fun n : ℕ => P.eval (n : ℚ)) atTop atBot := + (P.tendsto_atBot_of_leadingCoeff_nonpos hdeg hneg.le).comp tendsto_natCast_atTop_atTop + obtain ⟨n, hn, hn'⟩ := (hpos.and (hlim.eventually_lt_atBot 0)).exists + exact hn'.not_ge hn + · obtain ⟨n, hn⟩ := hpos.exists + have hconst : P.eval (n : ℚ) = P.leadingCoeff := by + rw [Polynomial.eq_C_of_degree_le_zero (le_of_not_gt hdeg)] + simp + exact hneg.not_ge (hconst ▸ hn) + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +theorem numerator_eval_one_is_integer (S : PowerSeries ℚ) + (hS : ∀ n : ℕ, ∃ z : ℤ, (z : ℚ) = S.coeff n) + (q : Polynomial ℚ) (d : ℕ) + (hclear : (1 - PowerSeries.X) ^ d * S = (q : PowerSeries ℚ)) : + ∃ z : ℤ, (z : ℚ) = q.eval 1 := by + classical + choose a ha using hS + let T : PowerSeries ℤ := PowerSeries.mk a + have hT : PowerSeries.map (Int.castRingHom ℚ) T = S := by + ext n + simpa only [T, PowerSeries.coeff_map, PowerSeries.coeff_mk, Int.coe_castRingHom] using ha n + let U : PowerSeries ℤ := (1 - PowerSeries.X) ^ d * T + have hU : PowerSeries.map (Int.castRingHom ℚ) U = (q : PowerSeries ℚ) := by + simpa only [U, map_mul, map_pow, map_sub, map_one, PowerSeries.map_X, hT] using hclear + refine ⟨∑ n ∈ q.support, U.coeff n, ?_⟩ + rw [Int.cast_sum, Polynomial.eval_eq_sum, Polynomial.sum_def] + apply Finset.sum_congr rfl + intro n _ + simpa only [one_pow, mul_one, PowerSeries.coeff_map, Int.coe_castRingHom, + Polynomial.coeff_coe] using congrArg (fun P : PowerSeries ℚ => P.coeff n) hU + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial Filter + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem exists_pos_integer_factorial_mul_leadingCoeff_hilbertPolynomial + {K σ : Type*} [Field K] [Finite σ] + (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) + (hne : hilbertPolynomial I hI ≠ 0) : + ∃ z : ℤ, 0 < z ∧ (z : ℚ) = + ((hilbertPolynomial I hI).natDegree.factorial : ℚ) * + (hilbertPolynomial I hI).leadingCoeff := by + obtain ⟨p, d, hpd, hred⟩ := exists_reduced_hilbertSeries I hI + have hP : hilbertPolynomial I hI = Polynomial.hilbertPoly p d := by + apply hilbertPolynomial_eq_of_eventual_eval + refine ⟨p.natDegree, fun n hn ↦ ?_⟩ + have h := Polynomial.coeff_mul_invOneSubPow_eq_hilbertPoly_eval (p := p) d hn + simpa only [← hpd, hilbertSeries, PowerSeries.coeff_mk] using h + have hd : d ≠ 0 := by + intro hd + apply hne + rw [hP, hd, Polynomial.hilbertPoly_zero_right] + have hp : p.eval 1 ≠ 0 := hred.resolve_left hd + have hclear : (1 - PowerSeries.X) ^ d * hilbertSeries I = (p : PowerSeries ℚ) := by + rw [hpd, ← PowerSeries.invOneSubPow_inv_eq_one_sub_pow] + simp only [mul_left_comm (PowerSeries.invOneSubPow ℚ d).inv, + Units.inv_val, mul_one] + obtain ⟨z, hz⟩ := numerator_eval_one_is_integer (hilbertSeries I) + (fun n => ⟨(Module.finrank K (degreePiece I n) : ℤ), by simp [hilbertSeries]⟩) p d hclear + have heq : ((hilbertPolynomial I hI).natDegree.factorial : ℚ) * + (hilbertPolynomial I hI).leadingCoeff = p.eval 1 := by + obtain ⟨e, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hd + rw [hP, Polynomial.natDegree_hilbertPoly_succ_of_eval_one_ne_zero hp, + Polynomial.factorial_mul_leadingCoeff_hilbertPoly_succ hp] + have hlead : 0 < (hilbertPolynomial I hI).leadingCoeff := by + apply leadingCoeff_pos_of_eventually_nat_eval_nonneg _ hne + obtain ⟨N, hN⟩ := hilbertPolynomial_spec I hI + filter_upwards [eventually_gt_atTop N] with n hn + rw [← hN n hn] + positivity + refine ⟨z, ?_, hz.trans heq.symm⟩ + have hpos : 0 < (z : ℚ) := by + rw [hz, ← heq] + exact mul_pos (by positivity) hlead + exact_mod_cast hpos + +end WeightedTorusJets.Geometry.GradedQuotient + +namespace WeightedTorusJets.Geometry.GradedQuotient + +open MvPolynomial + +variable {K σ : Type*} [Field K] [Finite σ] + +attribute [local instance] MvPolynomial.gradedAlgebra + +noncomputable def projectiveDegree (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : ℕ := + if h : hilbertPolynomial I hI = 0 then 0 + else (exists_pos_integer_factorial_mul_leadingCoeff_hilbertPolynomial I hI h).choose.toNat + +theorem projectiveDegree_cast (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + (projectiveDegree I hI : ℚ) = + ((hilbertPolynomial I hI).natDegree.factorial : ℚ) * + (hilbertPolynomial I hI).leadingCoeff := by + unfold projectiveDegree + split_ifs with h + · simp [h] + · have hz := (exists_pos_integer_factorial_mul_leadingCoeff_hilbertPolynomial I hI h).choose_spec + have hcast := Int.toNat_of_nonneg hz.1.le + exact (by exact_mod_cast hcast : + ((exists_pos_integer_factorial_mul_leadingCoeff_hilbertPolynomial I hI h).choose.toNat : ℚ) = + ((exists_pos_integer_factorial_mul_leadingCoeff_hilbertPolynomial I hI h).choose : ℚ)).trans hz.2 + +theorem projectiveDegree_pos_iff (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + 0 < projectiveDegree I hI ↔ hilbertPolynomial I hI ≠ 0 := by + constructor + · intro hpos hzero + simp [projectiveDegree, hzero] at hpos + · intro hne + rw [projectiveDegree, dite_eq_right hne] + have hz := (exists_pos_integer_factorial_mul_leadingCoeff_hilbertPolynomial I hI hne).choose_spec.1 + omega + +theorem projectiveDegree_eq_zero_iff (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) : + projectiveDegree I hI = 0 ↔ hilbertPolynomial I hI = 0 := by + simpa only [not_lt, Nat.le_zero, not_not] using not_congr (projectiveDegree_pos_iff I hI) + +end WeightedTorusJets.Geometry.GradedQuotient + +end +end + +section + +namespace WeightedTorusJets + +open DirectSum + +variable {K A M : Type*} [Field K] [CommRing A] [Algebra K A] + [AddCommGroup M] [Module K M] [Module A M] + (𝒜 : ℕ → Submodule K A) [GradedAlgebra 𝒜] + (ℳ : ℕ → Submodule K M) [DirectSum.Decomposition ℳ] + [SetLike.GradedSMul 𝒜 ℳ] + +theorem decompose_smul_of_homogeneous_right (r : A) {m : M} {j : ℕ} + (hm : m ∈ ℳ j) (i : ℕ) : + (decompose ℳ (r • m) (i + j) : M) = (decompose 𝒜 r i : A) • m := by + refine DirectSum.Decomposition.inductionOn 𝒜 ?_ ?_ ?_ r + · simp + · intro k a + have ham : (a : A) • m ∈ ℳ (k + j) := by + simpa only [vadd_eq_add] using SetLike.GradedSMul.smul_mem a.2 hm + by_cases hki : k = i + · subst k + rw [decompose_of_mem_same ℳ ham, + decompose_of_mem_same 𝒜 a.2] + · rw [decompose_of_mem_ne ℳ ham + (by omega : k + j ≠ i + j), decompose_of_mem_ne 𝒜 a.2 hki, zero_smul] + · intro r s hr hs + simpa only [add_smul, decompose_add, DirectSum.add_apply, Submodule.coe_add] using + congrArg₂ (· + ·) hr hs + +theorem homogeneous_component_smul_mem (N : Submodule A M) (hN : N.IsHomogeneous ℳ) + {r : A} (hr : ∀ m : M, r • m ∈ N) (i : ℕ) (m : M) : + (decompose 𝒜 r i : A) • m ∈ N := by + refine DirectSum.Decomposition.inductionOn ℳ ?_ ?_ ?_ m + · simp + · intro j m + rw [← decompose_smul_of_homogeneous_right 𝒜 ℳ r m.2 i] + exact hN (i + j) (hr m) + · intro m n hm hn + simpa only [smul_add] using N.add_mem hm hn + +theorem exists_homogeneous_annihilator_of_annihilator + (N : Submodule A M) (hN : N.IsHomogeneous ℳ) + {r : A} (hr0 : r ≠ 0) (hr : ∀ m : M, r • m ∈ N) : + ∃ s : A, s ≠ 0 ∧ (∃ i : ℕ, s ∈ 𝒜 i) ∧ ∀ m : M, s • m ∈ N := by + classical + have hex : ∃ i : ℕ, (decompose 𝒜 r i : A) ≠ 0 := by + by_contra! h + apply hr0 + rw [← sum_support_decompose 𝒜 r] + exact Finset.sum_eq_zero (fun i _ => h i) + obtain ⟨i, hi⟩ := hex + exact ⟨decompose 𝒜 r i, hi, ⟨i, (decompose 𝒜 r i).2⟩, + homogeneous_component_smul_mem 𝒜 ℳ N hN hr i⟩ + +theorem exists_homogeneous_annihilator_of_rank_zero [IsDomain A] + (N : Submodule A M) (hN : N.IsHomogeneous ℳ) [Module.Finite A (M ⧸ N)] + (hrank : Module.rank A (M ⧸ N) = 0) : + ∃ s : A, s ≠ 0 ∧ (∃ i : ℕ, s ∈ 𝒜 i) ∧ ∀ m : M, s • m ∈ N := by + have ht : Module.IsTorsion A (M ⧸ N) := by + intro x + obtain ⟨r, hr, hx⟩ := rank_eq_zero_iff.mp hrank x + exact ⟨⟨r, mem_nonZeroDivisors_iff_ne_zero.mpr hr⟩, hx⟩ + obtain ⟨r, hr, hr0⟩ := Submodule.annihilator_top_inter_nonZeroDivisors ht + apply exists_homogeneous_annihilator_of_annihilator 𝒜 ℳ N hN + (mem_nonZeroDivisors_iff_ne_zero.mp hr0) + apply (Module.isTorsionBy_quotient_iff N r).mp + intro x + exact Submodule.mem_annihilator.mp hr x Submodule.mem_top + +include 𝒜 in + +theorem decompose_smul_mem_of_homogeneous (N : Submodule A M) + (r : A) {m : M} (hm : SetLike.IsHomogeneousElem ℳ m) (hNm : m ∈ N) (j : ℕ) : + (decompose ℳ (r • m) j : M) ∈ N := by + classical + rw [← DirectSum.sum_support_decompose 𝒜 r, Finset.sum_smul, + decompose_sum, DFinsupp.finsetSum_apply, AddSubmonoidClass.coe_finsetSum] + apply N.sum_mem + intro k _ + obtain ⟨i, hi⟩ := hm + have hki : (decompose 𝒜 r k : A) • m ∈ ℳ (k + i) := by + simpa only [vadd_eq_add] using + SetLike.GradedSMul.smul_mem (decompose 𝒜 r k).2 hi + by_cases h : k + i = j + · subst j + rw [decompose_of_mem_same ℳ hki] + exact N.smul_mem _ hNm + · rw [decompose_of_mem_ne ℳ hki h] + exact N.zero_mem + +include 𝒜 in + +theorem homogeneous_submodule_span (s : Set M) + (hs : ∀ m ∈ s, SetLike.IsHomogeneousElem ℳ m) : + (Submodule.span A s).IsHomogeneous ℳ := by + rintro i m hm + rw [Finsupp.span_eq_range_linearCombination, LinearMap.mem_range] at hm + obtain ⟨c, rfl⟩ := hm + rw [Finsupp.linearCombination_apply, Finsupp.sum, decompose_sum, + DFinsupp.finsetSum_apply, AddSubmonoidClass.coe_finsetSum] + apply Submodule.sum_mem + intro z _ + exact decompose_smul_mem_of_homogeneous 𝒜 ℳ _ (c z) (hs z z.2) + (Submodule.subset_span z.2) i + +variable [IsScalarTower K A M] + +omit [GradedAlgebra 𝒜] [DirectSum.Decomposition ℳ] in + +theorem homogeneous_coefficients_sum_mem {r D n : ℕ} (v : Fin r → M) + (hv : ∀ i, v i ∈ ℳ D) (hn : D ≤ n) (c : Fin r → 𝒜 (n - D)) : + (∑ i, (c i : A) • v i) ∈ + (ℳ n ⊓ (Submodule.span A (Set.range v)).restrictScalars K) := by + constructor + · apply Submodule.sum_mem + intro i _ + simpa only [vadd_eq_add, Nat.sub_add_cancel hn] using + SetLike.GradedSMul.smul_mem (c i).2 (hv i) + · apply Submodule.sum_mem + intro i _ + exact Submodule.smul_mem _ _ (Submodule.subset_span (Set.mem_range_self i)) + +omit [IsScalarTower K A M] in + +theorem exists_homogeneous_coefficients {r D n : ℕ} (v : Fin r → M) + (hv : ∀ i, v i ∈ ℳ D) (hn : D ≤ n) (y : M) + (hy : y ∈ ℳ n) (hyspan : y ∈ Submodule.span A (Set.range v)) : + ∃ c : Fin r → 𝒜 (n - D), (∑ i, (c i : A) • v i) = y := by + classical + obtain ⟨c, hc⟩ := (Submodule.mem_span_range_iff_exists_fun A).mp hyspan + refine ⟨fun i => decompose 𝒜 (c i) (n - D), ?_⟩ + have hp := congrArg (fun z : M => (decompose ℳ z n : M)) hc + rw [decompose_sum, DFinsupp.finsetSum_apply, AddSubmonoidClass.coe_finsetSum, + decompose_of_mem_same ℳ hy] at hp + convert hp using 1 + apply Finset.sum_congr rfl + intro i _ + have h := (decompose_smul_of_homogeneous_right 𝒜 ℳ (c i) (hv i) (n - D)).symm + rw [Nat.sub_add_cancel hn] at h + exact h + +end WeightedTorusJets + +open scoped BigOperators + +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/HomogeneousDeformation.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/HomogeneousDeformation.lean new file mode 100644 index 0000000000000000000000000000000000000000..b2ef615477363056c85785a1fbbdac401a065272 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/HomogeneousDeformation.lean @@ -0,0 +1,656 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.LocalQuotientEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section + +open scoped BigOperators + +namespace WeightedTorusJets + +open MvPolynomial + +variable {σ R S : Type*} [CommRing R] [CommRing S] + +noncomputable def homogeneousDeformation (f : σ → MvPolynomial σ R) (d : ℕ) (i : σ) : + MvPolynomial σ (Polynomial R) := + homogeneousComponent d (polynomialDeformation f d i) + +theorem map_homogeneousComponent (φ : R →+* S) (n : ℕ) (f : MvPolynomial σ R) : + map φ (homogeneousComponent n f) = homogeneousComponent n (map φ f) := by + ext a + simp only [coeff_map, coeff_homogeneousComponent] + split_ifs <;> simp + +theorem polynomialDeformation_at_one (f : σ → MvPolynomial σ R) (d : ℕ) (i : σ) : + map (Polynomial.evalRingHom 1) (polynomialDeformation f d i) = X i ^ d := by + simp [polynomialDeformation] + +theorem homogeneousDeformation_at_one (f : σ → MvPolynomial σ R) (d : ℕ) (i : σ) : + map (Polynomial.evalRingHom 1) (homogeneousDeformation f d i) = X i ^ d := by + rw [homogeneousDeformation, map_homogeneousComponent, polynomialDeformation_at_one] + simp [homogeneousComponent_of_mem (isHomogeneous_X_pow i d)] + +noncomputable def macaulayColumn (d n : ℕ) (G : σ → MvPolynomial σ R) + (hG : ∀ i, (G i).IsHomogeneous d) + (b : σ × {b : σ →₀ ℕ // b.degree + d = n}) : homogeneousSubmodule σ R n := + ⟨monomial b.2.1 1 * G b.1, by + change (monomial b.2.1 (1 : R) * G b.1).IsHomogeneous n + simpa only [b.2.2] using + (isHomogeneous_monomial (d := b.2.1) (1 : R) rfl).mul (hG b.1)⟩ + +noncomputable def macaulayMap (d n : ℕ) (G : σ → MvPolynomial σ R) + (hG : ∀ i, (G i).IsHomogeneous d) : + ((σ × {b : σ →₀ ℕ // b.degree + d = n}) →₀ R) →ₗ[R] + homogeneousSubmodule σ R n := + Finsupp.linearCombination R (macaulayColumn d n G hG) + +noncomputable def macaulayMatrix (d n : ℕ) (G : σ → MvPolynomial σ R) : + Matrix {a : σ →₀ ℕ // a.degree = n} + (σ × {b : σ →₀ ℕ // b.degree + d = n}) R := + fun a b => (monomial b.2.1 1 * G b.1).coeff a.1 + +theorem macaulayMatrix_map (φ : R →+* S) (d n : ℕ) (G : σ → MvPolynomial σ R) : + (macaulayMatrix d n G).map φ = macaulayMatrix d n (fun i => map φ (G i)) := by + ext a b + change φ ((monomial b.2.1 1 * G b.1).coeff a.1) = + (monomial b.2.1 1 * map φ (G b.1)).coeff a.1 + rw [← coeff_map] + simp + +theorem deformed_macaulay_at_one (f : σ → MvPolynomial σ R) (d n : ℕ) : + (macaulayMatrix d n (homogeneousDeformation f d)).map (Polynomial.evalRingHom 1) = + macaulayMatrix d n (fun i => (X i : MvPolynomial σ R) ^ d) := by + rw [macaulayMatrix_map] + simp only [homogeneousDeformation_at_one] + +end WeightedTorusJets + +open Module + +namespace WeightedTorusJets + +@[instance_reducible] noncomputable def monomialDegreeFintype (σ : Type*) [Finite σ] (n : ℕ) : + Fintype {m : σ →₀ ℕ // m.degree = n} := + (Finsupp.finite_of_degree_eq n).fintype + +@[instance_reducible] noncomputable def monomialSourceFintype (σ : Type*) [Finite σ] (n d : ℕ) : + Fintype {m : σ →₀ ℕ // m.degree + d = n} := + ((Finsupp.finite_of_degree_le n).subset (fun m hm => by + change m.degree + d = n at hm + change m.degree ≤ n + omega)).fintype + +noncomputable def homogeneousMonomialBasis (σ R : Type*) [CommSemiring R] (n : ℕ) : + Basis {m : σ →₀ ℕ // m.degree = n} R (MvPolynomial.homogeneousSubmodule σ R n) := + (MvPolynomial.basisRestrictSupport R {m : σ →₀ ℕ | m.degree = n}).map + (LinearEquiv.ofEq _ _ + (MvPolynomial.homogeneousSubmodule_eq_finsupp_supported (σ := σ) (R := R) n).symm) + +end WeightedTorusJets + +open MvPolynomial + +noncomputable section + +namespace WeightedTorusJets.Geometry.GradedQuotient + +variable {K σ : Type*} [Field K] + +def degreePiece (I : Ideal (MvPolynomial σ K)) (n : ℕ) : + Submodule K (MvPolynomial σ K ⧸ I) := + (homogeneousSubmodule σ K n).map (Ideal.Quotient.mkₐ K I).toLinearMap + +def degreePresentation (I : Ideal (MvPolynomial σ K)) (n : ℕ) : + homogeneousSubmodule σ K n →ₗ[K] degreePiece I n := + (Ideal.Quotient.mkₐ K I).toLinearMap.submoduleMap (homogeneousSubmodule σ K n) + +theorem degreePresentation_surjective (I : Ideal (MvPolynomial σ K)) (n : ℕ) : + Function.Surjective (degreePresentation I n) := + (Ideal.Quotient.mkₐ K I).toLinearMap.submoduleMap_surjective _ + +theorem ker_degreePresentation (I : Ideal (MvPolynomial σ K)) (n : ℕ) : + LinearMap.ker (degreePresentation I n) = + (I.restrictScalars K).comap (homogeneousSubmodule σ K n).subtype := by + change LinearMap.ker (((I.restrictScalars K).mkQ).submoduleMap + (homogeneousSubmodule σ K n)) = _ + rw [LinearMap.ker_submoduleMap, Submodule.ker_mkQ] + +theorem finrank_degreePiece_eq_sub_finrank_range [Finite σ] + {V : Type*} [AddCommGroup V] [Module K V] + (I : Ideal (MvPolynomial σ K)) (n : ℕ) (m : V →ₗ[K] homogeneousSubmodule σ K n) + (hrange : LinearMap.range m = + (I.restrictScalars K).comap (homogeneousSubmodule σ K n).subtype) : + Module.finrank K (degreePiece I n) = + Module.finrank K (homogeneousSubmodule σ K n) - Module.finrank K (LinearMap.range m) := by + let : Module.Finite K (homogeneousSubmodule σ K n) := + Module.Finite.of_fg (homogeneousSubmodule_fg σ K n) + have h := (degreePresentation I n).finrank_range_add_finrank_ker + rw [LinearMap.range_eq_top.mpr (degreePresentation_surjective I n), finrank_top, + ker_degreePresentation, ← hrange] at h + omega + +end WeightedTorusJets.Geometry.GradedQuotient + +namespace WeightedTorusJets.Geometry.GradedQuotient +variable {K σ : Type*} [CommRing K] +attribute [local instance] MvPolynomial.gradedAlgebra +theorem homogeneousComponent_mul_of_le {f g : MvPolynomial σ K} {d n : ℕ} + (hf : f.IsHomogeneous d) (hdn : d ≤ n) : + homogeneousComponent n (f * g) = f * homogeneousComponent (n - d) g := by + have h := DirectSum.coe_decompose_mul_of_left_mem_of_le + (homogeneousSubmodule σ K) (b := g) hf hdn + change (decomposition.decompose' (f * g) n : MvPolynomial σ K) = + f * (decomposition.decompose' g (n - d) : MvPolynomial σ K) at h + simpa only [decomposition.decompose'_apply] using h + +theorem homogeneousComponent_mul_of_lt {f g : MvPolynomial σ K} {d n : ℕ} + (hf : f.IsHomogeneous d) (hnd : n < d) : + homogeneousComponent n (f * g) = 0 := by + have h := DirectSum.coe_decompose_mul_of_left_mem_of_not_le + (homogeneousSubmodule σ K) (b := g) hf (Nat.not_le.mpr hnd) + change (decomposition.decompose' (f * g) n : MvPolynomial σ K) = 0 at h + simpa only [decomposition.decompose'_apply] using h + +end WeightedTorusJets.Geometry.GradedQuotient + +namespace WeightedTorusJets + +open MvPolynomial + +theorem macaulayMap_range_eq_ideal_slice {σ K : Type*} [Fintype σ] [Field K] + (d n : ℕ) (G : σ → MvPolynomial σ K) (hG : ∀ i, (G i).IsHomogeneous d) : + LinearMap.range (macaulayMap d n G hG) = + ((Ideal.span (Set.range G)).restrictScalars K).comap + (homogeneousSubmodule σ K n).subtype := by + classical + let T := LinearMap.range (macaulayMap d n G hG) + let J := T.map (homogeneousSubmodule σ K n).subtype + have hJ (b : σ × {b : σ →₀ ℕ // b.degree + d = n}) : + monomial b.2.1 1 * G b.1 ∈ J := by + refine ⟨macaulayColumn d n G hG b, ?_, rfl⟩ + exact ⟨Finsupp.single b 1, by simp [macaulayMap]⟩ + apply le_antisymm + · rw [macaulayMap, Finsupp.range_linearCombination] + apply Submodule.span_le.mpr + rintro p ⟨b, rfl⟩ + change monomial b.2.1 1 * G b.1 ∈ Ideal.span (Set.range G) + exact Ideal.mul_mem_left _ _ (Ideal.subset_span ⟨b.1, rfl⟩) + · intro p hp + change (p : MvPolynomial σ K) ∈ Ideal.span (Set.range G) at hp + obtain ⟨g, hg⟩ := Ideal.mem_span_range_iff_exists_fun.mp hp + have hmul (i : σ) : homogeneousComponent n (g i * G i) ∈ J := by + by_cases hdn : d ≤ n + · rw [mul_comm (g i) (G i), + Geometry.GradedQuotient.homogeneousComponent_mul_of_le (hG i) hdn, + mul_comm (G i)] + let a := homogeneousComponent (n - d) (g i) + change a * G i ∈ J + rw [a.as_sum, Finset.sum_mul] + apply J.sum_mem + intro b hb + have hbdeg : b.degree = n - d := + (Finsupp.degree_apply b).trans + ((homogeneousComponent_isHomogeneous (n - d) (g i)).degree_eq_sum_deg_support hb).symm + have hbnd : b.degree + d = n := by omega + simpa only [← smul_mul_assoc, smul_monomial, smul_eq_mul, mul_one] using + J.smul_mem (a.coeff b) (hJ (i, ⟨b, hbnd⟩)) + · rw [mul_comm (g i) (G i), + Geometry.GradedQuotient.homogeneousComponent_mul_of_lt (hG i) + (Nat.lt_of_not_ge hdn)] + exact J.zero_mem + have hpJ : (p : MvPolynomial σ K) ∈ J := by + rw [← homogeneousComponent_eq_self p.property, ← hg, map_sum] + exact J.sum_mem fun i _ => hmul i + obtain ⟨p', hp', hpp⟩ := hpJ + have hpp' : p' = p := Subtype.ext hpp + rwa [hpp'] at hp' + +end WeightedTorusJets + +namespace WeightedTorusJets + +open MvPolynomial Geometry.GradedQuotient + +theorem toMatrix_macaulayMap {σ K : Type*} [Fintype σ] [Field K] + (d n : ℕ) (G : σ → MvPolynomial σ K) (hG : ∀ i, (G i).IsHomogeneous d) + [Fintype {a : σ →₀ ℕ // a.degree = n}] + [Fintype {b : σ →₀ ℕ // b.degree + d = n}] + [DecidableEq (σ × {b : σ →₀ ℕ // b.degree + d = n})] : + LinearMap.toMatrix Finsupp.basisSingleOne (homogeneousMonomialBasis σ K n) + (macaulayMap d n G hG) = macaulayMatrix d n G := by + ext a b + simp only [macaulayMap, LinearMap.toMatrix_apply, Finsupp.coe_basisSingleOne, + Finsupp.linearCombination_single, one_smul] + rfl + +theorem macaulayMatrix_rank_eq_finrank_range {σ K : Type*} [Fintype σ] [Field K] + (d n : ℕ) (G : σ → MvPolynomial σ K) (hG : ∀ i, (G i).IsHomogeneous d) + [Fintype {a : σ →₀ ℕ // a.degree = n}] + [Fintype {b : σ →₀ ℕ // b.degree + d = n}] : + (macaulayMatrix d n G).rank = Module.finrank K (LinearMap.range (macaulayMap d n G hG)) := by + classical + rw [← toMatrix_macaulayMap d n G hG] + rw [Matrix.rank_eq_finrank_range_toLin _ (homogeneousMonomialBasis σ K n) + Finsupp.basisSingleOne, Matrix.toLin_toMatrix] + +theorem finrank_degreePiece_span_eq_sub_macaulayMatrix_rank + {σ K : Type*} [Fintype σ] [Field K] + (d n : ℕ) (G : σ → MvPolynomial σ K) (hG : ∀ i, (G i).IsHomogeneous d) + [Fintype {a : σ →₀ ℕ // a.degree = n}] + [Fintype {b : σ →₀ ℕ // b.degree + d = n}] : + Module.finrank K (degreePiece (Ideal.span (Set.range G)) n) = + Module.finrank K (homogeneousSubmodule σ K n) - (macaulayMatrix d n G).rank := by + rw [finrank_degreePiece_eq_sub_finrank_range _ _ _ + (macaulayMap_range_eq_ideal_slice d n G hG), + macaulayMatrix_rank_eq_finrank_range d n G hG] + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +theorem exists_row_minor_det_ne_zero {K ι n : Type*} [Field K] + [Fintype n] [DecidableEq n] (v : ι → n → K) + (hv : Submodule.span K (Set.range v) = ⊤) : + ∃ e : n → ι, Function.Injective e ∧ Matrix.det (fun i j => v (e i) j) ≠ 0 := by + classical + obtain ⟨b, hbmem, _, hbli⟩ := + Submodule.exists_fun_fin_finrank_span_eq K (Set.range v) + choose f hf using hbmem + have hk : Module.finrank K (Submodule.span K (Set.range v)) = Fintype.card n := by + rw [hv, finrank_top, Module.finrank_pi] + let e₀ : n ≃ Fin (Module.finrank K (Submodule.span K (Set.range v))) := + Fintype.equivFinOfCardEq hk.symm + let e : n → ι := f ∘ e₀ + have he : (fun i => v (e i)) = b ∘ e₀ := by + funext i + exact hf (e₀ i) + have hrow : LinearIndependent K (fun i => v (e i)) := by + rw [he] + exact hbli.comp e₀ e₀.injective + refine ⟨e, ?_, ?_⟩ + · intro i j hij + exact hrow.injective (congrArg v hij) + · exact isUnit_iff_ne_zero.mp + ((Matrix.isUnit_iff_isUnit_det _).mp (Matrix.linearIndependent_rows_iff_isUnit.mp hrow)) + +theorem exists_rank_minor {K m n : Type*} [Field K] [Fintype m] [Fintype n] + (A : Matrix m n K) : + ∃ (r : Fin A.rank → m) (c : Fin A.rank → n), (A.submatrix r c).det ≠ 0 := by + classical + rw [A.rank_eq_finrank_span_row] + obtain ⟨b, hbmem, _, hbli⟩ := + Submodule.exists_fun_fin_finrank_span_eq K (Set.range A.row) + choose r hr using hbmem + let B := A.submatrix r id + have hrow : LinearIndependent K B.row := by + have he : B.row = b := by + funext i + exact hr i + rw [he] + exact hbli + have hspan : Submodule.span K (Set.range B.transpose.row) = ⊤ := by + apply Submodule.eq_top_of_finrank_eq + rw [← Matrix.rank_eq_finrank_span_row, Matrix.rank_transpose, hrow.rank_matrix, + Module.finrank_pi] + obtain ⟨c, _, hc⟩ := exists_row_minor_det_ne_zero B.transpose.row hspan + refine ⟨r, c, ?_⟩ + have he : (fun i j => B.transpose.row (c i) j) = (A.submatrix r c).transpose := rfl + rwa [he, Matrix.det_transpose] at hc + +theorem rank_specialization_le {R K L m n : Type*} + [CommRing R] [Field K] [Field L] [Fintype m] [Fintype n] + (φ : R →+* K) (ψ : R →+* L) (hψ : Function.Injective ψ) (A : Matrix m n R) : + (A.map φ).rank ≤ (A.map ψ).rank := by + classical + obtain ⟨r, c, hc⟩ := exists_rank_minor (A.map φ) + have hφ : φ ((A.submatrix r c).det) ≠ 0 := by + rw [φ.map_det] + exact hc + have hdet : (A.submatrix r c).det ≠ 0 := by + intro h + exact hφ (by rw [h, map_zero]) + have hψdet : ψ ((A.submatrix r c).det) ≠ 0 := by + exact fun h => hdet (hψ (h.trans (map_zero ψ).symm)) + have hminor : ((A.map ψ).submatrix r c).det ≠ 0 := by + change (ψ.mapMatrix (A.submatrix r c)).det ≠ 0 + rw [← ψ.map_det] + exact hψdet + have heq := Matrix.rank_of_det_ne_zero hminor + simpa only [Fintype.card_fin] using + heq.symm.le.trans (Matrix.rank_submatrix_le (A.map ψ) r c) + +theorem rank_polynomial_eval_le {K m n : Type*} [Field K] + [Fintype m] [Fintype n] (A : Matrix m n (Polynomial K)) (a : K) : + (A.map (Polynomial.evalRingHom a)).rank ≤ + (A.map (algebraMap (Polynomial K) (RatFunc K))).rank := + rank_specialization_le _ _ (RatFunc.algebraMap_injective K) A + + + +theorem finrank_homogeneousSubmodule {σ K : Type*} [Fintype σ] [Field K] (n : ℕ) : + Module.finrank K (MvPolynomial.homogeneousSubmodule σ K n) = + (Fintype.card σ + n - 1).choose n := by + classical + let e : Sym σ n ≃ {d : σ →₀ ℕ // d.degree = n} := Sym.equivNatSum σ n + let : Fintype {d : σ →₀ ℕ // d.degree = n} := Fintype.ofEquiv (Sym σ n) e + rw [Module.finrank_eq_card_basis (WeightedTorusJets.homogeneousMonomialBasis σ K n)] + exact (Fintype.card_congr e).symm.trans (Sym.card_sym_eq_choose n) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +open MvPolynomial + +theorem deformed_macaulay_generic_rank_ge + {σ K : Type*} [Field K] [Fintype σ] + (f : σ → MvPolynomial σ K) (d n : ℕ) + [Fintype {a : σ →₀ ℕ // a.degree = n}] + [Fintype {b : σ →₀ ℕ // b.degree + d = n}] : + (macaulayMatrix d n (fun i => (X i : MvPolynomial σ K) ^ d)).rank ≤ + (macaulayMatrix d n (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) + (homogeneousDeformation f d i))).rank := by + have h := Geometry.rank_polynomial_eval_le + (macaulayMatrix d n (homogeneousDeformation f d)) (1 : K) + rwa [deformed_macaulay_at_one, macaulayMatrix_map] at h + +end WeightedTorusJets +namespace WeightedTorusJets + +open MvPolynomial Geometry.GradedQuotient + +theorem finrank_degreePiece_deformed_le_pure_powers + {σ K : Type*} [Fintype σ] [Field K] + (f : σ → MvPolynomial σ K) (d n : ℕ) : + Module.finrank (RatFunc K) + (degreePiece (Ideal.span (Set.range (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) + (homogeneousDeformation f d i)))) n) ≤ + Module.finrank K + (degreePiece (Ideal.span (Set.range (fun i => (X i : MvPolynomial σ K) ^ d))) n) := by + let := monomialDegreeFintype σ n + let := monomialSourceFintype σ n d + have hG (i : σ) : + (map (algebraMap (Polynomial K) (RatFunc K)) + (homogeneousDeformation f d i)).IsHomogeneous d := + (homogeneousComponent_isHomogeneous d (polynomialDeformation f d i)).map _ + rw [finrank_degreePiece_span_eq_sub_macaulayMatrix_rank d n _ hG, + finrank_degreePiece_span_eq_sub_macaulayMatrix_rank d n _ (fun i => isHomogeneous_X_pow i d), + Geometry.finrank_homogeneousSubmodule, Geometry.finrank_homogeneousSubmodule] + exact Nat.sub_le_sub_left (deformed_macaulay_generic_rank_ge f d n) _ + +end WeightedTorusJets + +noncomputable section + +open scoped BigOperators DirectSum +open MvPolynomial + +namespace WeightedTorusJets.Geometry + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem homogeneous_quotient_coeLinearMap_injective + {K σ : Type*} [Field K] (I : Ideal (MvPolynomial σ K)) + (hI : I.IsHomogeneous (homogeneousSubmodule σ K)) (N : ℕ) : + Function.Injective (DirectSum.coeLinearMap + (fun i : Fin N => (homogeneousSubmodule σ K (i : ℕ)).map + (Ideal.Quotient.mkₐ K I).toLinearMap)) := by + classical + let A (i : Fin N) := (homogeneousSubmodule σ K (i : ℕ)).map + (Ideal.Quotient.mkₐ K I).toLinearMap + let q := Ideal.Quotient.mkₐ K I + change Function.Injective (DirectSum.coeLinearMap A) + suffices hk : ∀ x : ⨁ i, A i, DirectSum.coeLinearMap A x = 0 → x = 0 by + intro x y hxy + exact sub_eq_zero.mp (hk (x - y) (by simp only [map_sub, hxy, sub_self])) + intro x hx + have hxsum : (∑ i : Fin N, (x i : MvPolynomial σ K ⧸ I)) = 0 := by + rw [_root_.DirectSum.coeLinearMap_eq_dfinsuppSum, + DFinsupp.sum_of_support_subset (Finset.subset_univ _) (fun _ _ => rfl)] at hx + exact hx + have hlift (i : Fin N) : ∃ p : MvPolynomial σ K, + p ∈ homogeneousSubmodule σ K (i : ℕ) ∧ q p = (x i : MvPolynomial σ K ⧸ I) := + (x i).property + choose p hp hpx using hlift + have hsum : (∑ i, p i) ∈ I := by + apply Ideal.Quotient.eq_zero_iff_mem.mp + change q (∑ i, p i) = 0 + rw [map_sum] + simpa only [hpx] using hxsum + apply DFinsupp.ext + intro i + apply Subtype.ext + change (x i : MvPolynomial σ K ⧸ I) = 0 + rw [← hpx i] + apply Ideal.Quotient.eq_zero_iff_mem.mpr + have hmem := homogeneousComponent_mem_of_mem hI hsum (i : ℕ) + have heq : homogeneousComponent (i : ℕ) (∑ j : Fin N, p j) = p i := by + rw [map_sum] + simp_rw [homogeneousComponent_of_mem (hp _)] + simp [Fin.val_inj] + rwa [heq] at hmem + +open MvPolynomial +open scoped DirectSum + +variable {K σ : Type*} [Field K] [Finite σ] + +theorem quotient_finrank_le_sum_homogeneous_images + (I : Ideal (MvPolynomial σ K)) (N : ℕ) + (hzero : ∀ n, N ≤ n → + (homogeneousSubmodule σ K n).map (Ideal.Quotient.mkₐ K I).toLinearMap = ⊥) : + Module.Finite K (MvPolynomial σ K ⧸ I) ∧ + Module.finrank K (MvPolynomial σ K ⧸ I) ≤ + ∑ i : Fin N, Module.finrank K + ((homogeneousSubmodule σ K (i : ℕ)).map (Ideal.Quotient.mkₐ K I).toLinearMap) := by + classical + let q := Ideal.Quotient.mkₐ K I + let A (i : Fin N) := (homogeneousSubmodule σ K (i : ℕ)).map q.toLinearMap + have hfinite (i : Fin N) : Module.Finite K (A i) := by + have : Module.Finite K (homogeneousSubmodule σ K (i : ℕ)) := + Module.Finite.iff_fg.mpr (homogeneousSubmodule_fg σ K (i : ℕ)) + exact Module.Finite.map _ _ + have hspan : (⨆ i, A i) = ⊤ := by + apply eq_top_iff.mpr + intro x _ + obtain ⟨f, rfl⟩ := Ideal.Quotient.mkₐ_surjective K I x + change q f ∈ ⨆ i, A i + rw [← sum_homogeneousComponent f, map_sum] + apply Submodule.sum_mem + intro n _ + by_cases hn : n < N + · apply (le_iSup A ⟨n, hn⟩) + exact Submodule.mem_map_of_mem (homogeneousComponent_mem n f) + · have hz : q (homogeneousComponent n f) = 0 := by + have hm := Submodule.mem_map_of_mem (f := q.toLinearMap) (homogeneousComponent_mem n f) + rw [hzero n (Nat.le_of_not_gt hn)] at hm + exact hm + simpa only [hz] using (⨆ i, A i).zero_mem + have hsurj : Function.Surjective (DirectSum.coeLinearMap A) := by + rw [← LinearMap.range_eq_top, DirectSum.range_coeLinearMap, hspan] + have hfiniteQ := Module.Finite.of_surjective (DirectSum.coeLinearMap A) hsurj + refine ⟨hfiniteQ, ?_⟩ + have heq := Module.finrank_directSum (R := K) (fun i : Fin N => A i) + exact (LinearMap.finrank_le_finrank_of_surjective hsurj).trans_eq heq + +theorem quotient_finrank_le_of_homogeneous_image_finrank_le + {L τ : Type*} [Field L] [Finite τ] + (I : Ideal (MvPolynomial σ K)) (J : Ideal (MvPolynomial τ L)) + (hJ : J.IsHomogeneous (homogeneousSubmodule τ L)) (N : ℕ) + (hcut : ∀ n, N ≤ n → + (homogeneousSubmodule τ L n).map (Ideal.Quotient.mkₐ L J).toLinearMap = ⊥) + (hle : ∀ n, Module.finrank K + ((homogeneousSubmodule σ K n).map (Ideal.Quotient.mkₐ K I).toLinearMap) ≤ + Module.finrank L + ((homogeneousSubmodule τ L n).map (Ideal.Quotient.mkₐ L J).toLinearMap)) : + Module.Finite K (MvPolynomial σ K ⧸ I) ∧ + Module.finrank K (MvPolynomial σ K ⧸ I) ≤ + Module.finrank L (MvPolynomial τ L ⧸ J) := by + classical + have hfiniteI (n : ℕ) : Module.Finite K + ((homogeneousSubmodule σ K n).map (Ideal.Quotient.mkₐ K I).toLinearMap) := by + have : Module.Finite K (homogeneousSubmodule σ K n) := + Module.Finite.iff_fg.mpr (homogeneousSubmodule_fg σ K n) + exact Module.Finite.map _ _ + have hfiniteJ (n : ℕ) : Module.Finite L + ((homogeneousSubmodule τ L n).map (Ideal.Quotient.mkₐ L J).toLinearMap) := by + have : Module.Finite L (homogeneousSubmodule τ L n) := + Module.Finite.iff_fg.mpr (homogeneousSubmodule_fg τ L n) + exact Module.Finite.map _ _ + have hcutI (n : ℕ) (hn : N ≤ n) : + (homogeneousSubmodule σ K n).map (Ideal.Quotient.mkₐ K I).toLinearMap = ⊥ := by + apply Submodule.finrank_eq_zero.mp + have hz := congrArg (fun V : Submodule L (MvPolynomial τ L ⧸ J) => Module.finrank L V) + (hcut n hn) + rw [finrank_bot] at hz + exact Nat.eq_zero_of_le_zero ((hle n).trans_eq hz) + obtain ⟨hIfin, hIbound⟩ := quotient_finrank_le_sum_homogeneous_images I N hcutI + have : Module.Finite L (MvPolynomial τ L ⧸ J) := + (quotient_finrank_le_sum_homogeneous_images J N hcut).1 + have hsumJ : (∑ i : Fin N, Module.finrank L + ((homogeneousSubmodule τ L (i : ℕ)).map (Ideal.Quotient.mkₐ L J).toLinearMap)) ≤ + Module.finrank L (MvPolynomial τ L ⧸ J) := by + have hinj := homogeneous_quotient_coeLinearMap_injective J hJ N + have heq := Module.finrank_directSum (R := L) (fun i : Fin N => + (homogeneousSubmodule τ L (i : ℕ)).map (Ideal.Quotient.mkₐ L J).toLinearMap) + rw [← heq] + exact LinearMap.finrank_le_finrank_of_injective hinj + refine ⟨hIfin, hIbound.trans ((Finset.sum_le_sum ?_).trans hsumJ)⟩ + intro i _ + exact hle i + +open MvPolynomial + +def rectangularIdeal {σ : Type u_1} {K : Type u_2} + [CommRing K] (k : σ → ℕ) : Ideal (MvPolynomial σ K) := + Ideal.span (Set.range fun i => (X i : MvPolynomial σ K) ^ k i) + +theorem mem_rectangularIdeal {σ K : Type*} [CommRing K] (k : σ → ℕ) + (p : MvPolynomial σ K) : + p ∈ rectangularIdeal k ↔ ∀ d ∈ p.support, ∃ i, k i ≤ d i := by + classical + have h : Set.range (fun i => (X i : MvPolynomial σ K) ^ k i) = + (fun d => monomial d (1 : K)) '' Set.range (fun i => Finsupp.single i (k i)) := by + simpa only [X_pow_eq_monomial] using + Set.range_comp' (fun d => monomial d (1 : K)) (fun i => Finsupp.single i (k i)) + simp only [rectangularIdeal, h, mem_ideal_span_monomial_image, Set.mem_range, + exists_exists_eq_and, Finsupp.single_le_iff] + +theorem rectangularIdeal_restrictScalars {σ K : Type*} [CommRing K] (k : σ → ℕ) : + (rectangularIdeal k : Ideal (MvPolynomial σ K)).restrictScalars K = + restrictSupport K {d | ∃ i, k i ≤ d i} := by + ext p + rw [Submodule.restrictScalars_mem, mem_rectangularIdeal, mem_restrictSupport_iff] + rfl + +theorem isCompl_restrictSupport_compl {σ K : Type*} [CommRing K] + (s : Set (σ →₀ ℕ)) : IsCompl (restrictSupport K s) (restrictSupport K sᶜ) := by + have h : IsCompl (Finsupp.supported K K s) (Finsupp.supported K K sᶜ) := + ⟨Finsupp.disjoint_supported_supported disjoint_compl_right, + Finsupp.codisjoint_supported_supported (codisjoint_iff.mpr sup_compl_eq_top)⟩ + simpa only [restrictSupport, AddMonoidAlgebra.supported_eq_map] using + Submodule.isCompl_map (AddMonoidAlgebra.coeffLinearEquiv K).symm h + +def rectangularQuotientEquiv {σ K : Type*} [CommRing K] (k : σ → ℕ) : + (MvPolynomial σ K ⧸ rectangularIdeal k) ≃ₗ[K] + restrictSupport K {d | ∀ i, d i < k i} := by + have h : {d : σ →₀ ℕ | ∃ i, k i ≤ d i}ᶜ = {d | ∀ i, d i < k i} := by + ext d + simp + exact (Submodule.Quotient.restrictScalarsEquiv K (rectangularIdeal k)).symm.trans + ((Submodule.quotEquivOfEq _ _ (rectangularIdeal_restrictScalars k)).trans + ((restrictSupport K {d | ∃ i, k i ≤ d i}).quotientEquivOfIsCompl _ + (h ▸ isCompl_restrictSupport_compl {d | ∃ i, k i ≤ d i}))) + +def rectangularExponentEquiv {σ : Type*} [Fintype σ] (k : σ → ℕ) : + {d : σ →₀ ℕ // ∀ i, d i < k i} ≃ (∀ i, Fin (k i)) where + toFun d i := ⟨d.1 i, d.2 i⟩ + invFun d := ⟨Finsupp.equivFunOnFinite.symm (fun i => (d i).val), fun i => (d i).isLt⟩ + left_inv d := by apply Subtype.ext; ext i; rfl + right_inv d := by funext i; apply Fin.ext; rfl + +def rectangularQuotientBasis {σ K : Type*} [Fintype σ] [CommRing K] (k : σ → ℕ) : + Module.Basis (∀ i, Fin (k i)) K (MvPolynomial σ K ⧸ rectangularIdeal k) := + ((basisRestrictSupport K {d | ∀ i, d i < k i}).reindex + (rectangularExponentEquiv k)).map (rectangularQuotientEquiv k).symm + +theorem finrank_rectangularQuotient {σ K : Type*} [Fintype σ] [Field K] (k : σ → ℕ) : + Module.finrank K (MvPolynomial σ K ⧸ rectangularIdeal k) = ∏ i, k i := by + classical + rw [Module.finrank_eq_card_basis (rectangularQuotientBasis k)] + simp + +open MvPolynomial + +theorem homogeneous_mem_rectangularIdeal {σ K : Type*} [Fintype σ] [CommRing K] + (k : σ → ℕ) {p : MvPolynomial σ K} {n : ℕ} + (hp : p.IsHomogeneous n) (hn : (∑ i, (k i - 1)) < n) : + p ∈ rectangularIdeal k := by + classical + apply (mem_rectangularIdeal k p).mpr + intro d hd + by_contra h + push Not at h + have hsum : (∑ i, d i) ≤ ∑ i, (k i - 1) := + Finset.sum_le_sum fun i _ => Nat.le_pred_of_lt (h i) + have hdegree : n = ∑ i, d i := by + simpa only [← Finsupp.degree_apply, Finsupp.degree_eq_sum] using + hp.degree_eq_sum_deg_support hd + omega + +theorem rectangular_homogeneous_image_eq_bot {σ K : Type*} [Fintype σ] [CommRing K] + (k : σ → ℕ) (n : ℕ) (hn : (∑ i, (k i - 1)) < n) : + (homogeneousSubmodule σ K n).map + (Ideal.Quotient.mkₐ K (rectangularIdeal k)).toLinearMap = ⊥ := by + apply le_antisymm ?_ bot_le + intro x hx + obtain ⟨p, hp, rfl⟩ := Submodule.mem_map.mp hx + change Ideal.Quotient.mk (rectangularIdeal k) p = 0 + apply Ideal.Quotient.eq_zero_iff_mem.mpr + exact homogeneous_mem_rectangularIdeal k + ((mem_homogeneousSubmodule n p).mp hp) hn + +open MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem rectangularIdeal_isHomogeneous {σ K : Type*} [CommRing K] (k : σ → ℕ) : + (rectangularIdeal k : Ideal (MvPolynomial σ K)).IsHomogeneous + (homogeneousSubmodule σ K) := by + apply Ideal.homogeneous_span (homogeneousSubmodule σ K) + rintro _ ⟨i, rfl⟩ + exact ⟨k i, isHomogeneous_X_pow i (k i)⟩ + +theorem quotient_finrank_le_prod_of_homogeneous_image_le_rectangular + {L τ : Type*} [Field L] [Fintype τ] + (I : Ideal (MvPolynomial σ K)) (k : τ → ℕ) + (hle : ∀ n, Module.finrank K + ((homogeneousSubmodule σ K n).map (Ideal.Quotient.mkₐ K I).toLinearMap) ≤ + Module.finrank L ((homogeneousSubmodule τ L n).map + (Ideal.Quotient.mkₐ L (rectangularIdeal k)).toLinearMap)) : + Module.Finite K (MvPolynomial σ K ⧸ I) ∧ + Module.finrank K (MvPolynomial σ K ⧸ I) ≤ ∏ i, k i := by + have h := quotient_finrank_le_of_homogeneous_image_finrank_le I + (rectangularIdeal k : Ideal (MvPolynomial τ L)) (rectangularIdeal_isHomogeneous k) + ((∑ i, (k i - 1)) + 1) + (fun n hn => rectangular_homogeneous_image_eq_bot k n (Nat.lt_of_succ_le hn)) hle + simpa only [finrank_rectangularQuotient] using h + +end WeightedTorusJets.Geometry + +end +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/Homogenize.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/Homogenize.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e51fbf19283495484407125b4915aa69e8e161f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/Homogenize.lean @@ -0,0 +1,488 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeMap + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry.DegreeBezout + +attribute [local instance] Polynomial.algebra Polynomial.isLocalization + +open Polynomial IsLocalRing + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +local notation "𝒜" => MvPolynomial σ K +local notation "𝒮" => MvPolynomial (Option σ) K +local notation "𝒰" => Localization.Away (X (none : Option σ) : 𝒮) +local notation "𝒱" => Localization.Away (Polynomial.X : Polynomial 𝒜) + + + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +attribute [local instance] coneIdeal_isPrime polynomialAwayPrime_isPrime + + + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +attribute [local instance] coneIdeal_isPrime Polynomial.algebra Polynomial.isLocalization + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommSemiring K] + +noncomputable def homogenize (f : MvPolynomial σ K) : MvPolynomial (Option σ) K := + ∑ i ∈ Finset.range (f.totalDegree + 1), + X none ^ (f.totalDegree - i) * rename some (homogeneousComponent i f) + +theorem homogenize_isHomogeneous (f : MvPolynomial σ K) : + (homogenize f).IsHomogeneous f.totalDegree := by + apply IsHomogeneous.sum + intro i hi + have hi' : i ≤ f.totalDegree := Nat.lt_succ_iff.mp (Finset.mem_range.mp hi) + have hrename : (rename some (homogeneousComponent i f)).IsHomogeneous i := by + rw [rename_eq_aeval] + simpa only [one_mul] using (homogeneousComponent_isHomogeneous i f).aeval + (X ∘ some) (fun j => isHomogeneous_X K (some j)) + simpa only [Nat.sub_add_cancel hi'] using + (isHomogeneous_X_pow (R := K) (none : Option σ) (f.totalDegree - i)).mul hrename + +theorem dehomogenize_homogenize (f : MvPolynomial σ K) : + MvPolynomial.aeval (fun o : Option σ => o.elim (1 : MvPolynomial σ K) X) (homogenize f) = f := by + simp only [homogenize, map_sum, map_mul, map_pow, aeval_X, Option.elim_none, + one_pow, one_mul, aeval_rename, Function.comp_def, Option.elim_some, aeval_X_left_apply] + exact sum_homogeneousComponent f + +theorem homogenize_totalDegree (f : MvPolynomial σ K) : + (homogenize f).totalDegree = f.totalDegree := by + by_cases hf : f = 0 + · simp [hf, homogenize] + · apply (homogenize_isHomogeneous f).totalDegree + intro hzero + apply hf + rw [← dehomogenize_homogenize f, hzero, map_zero] + +theorem map_span_homogenize (S : Set (MvPolynomial σ K)) : + Ideal.map (MvPolynomial.aeval + (fun o : Option σ => o.elim (1 : MvPolynomial σ K) X)).toRingHom + (Ideal.span (homogenize '' S)) = Ideal.span S := by + rw [Ideal.map_span, Set.image_image] + congr 1 + ext f + simp only [Set.mem_image, AlgHom.toRingHom_eq_coe, + RingHom.coe_coe, dehomogenize_homogenize, exists_eq_right] + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem span_homogenize_isHomogeneous (S : Set (MvPolynomial σ K)) : + (Ideal.span (homogenize '' S)).IsHomogeneous + (homogeneousSubmodule (Option σ) K) := by + apply Ideal.homogeneous_span + rintro f ⟨g, _, rfl⟩ + exact ⟨g.totalDegree, homogenize_isHomogeneous g⟩ + +theorem homogeneous_eval₂_mul + {R S τ : Type*} [CommSemiring R] [CommSemiring S] + {p : MvPolynomial τ R} {n : ℕ} (hp : p.IsHomogeneous n) + (c : R →+* S) (x : τ → S) (t : S) : + p.eval₂ c (fun i => x i * t) = p.eval₂ c x * t ^ n := by + classical + simp only [eval₂_eq, Finset.sum_mul] + apply Finset.sum_congr rfl + intro d hd + have hn : n = ∑ i ∈ d.support, d i := hp.degree_eq_sum_deg_support hd + simp only [mul_pow, Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum] + rw [← hn, mul_assoc] + +theorem eval₂_homogenize + {S : Type*} [CommSemiring S] (c : K →+* S) (x : σ → S) (t : S) + (p : MvPolynomial σ K) : + (homogenize p).eval₂ c (fun o : Option σ => o.elim t (fun i => x i * t)) = + p.eval₂ c x * t ^ p.totalDegree := by + have hx : (fun o : Option σ => o.elim t (fun i => x i * t)) = + (fun o : Option σ => (o.elim 1 x) * t) := by + funext o + cases o <;> simp + rw [hx, homogeneous_eval₂_mul (homogenize_isHomogeneous p)] + congr 1 + have hcomp : (eval₂Hom c x).comp (MvPolynomial.aeval + (fun o : Option σ => o.elim (1 : MvPolynomial σ K) X)).toRingHom = + eval₂Hom c (fun o : Option σ => o.elim 1 x) := by + apply MvPolynomial.ringHom_ext + · intro r + simp + · intro o + cases o <;> simp + have h := congrArg (eval₂Hom c x) (dehomogenize_homogenize p) + change ((eval₂Hom c x).comp (MvPolynomial.aeval + (fun o : Option σ => o.elim (1 : MvPolynomial σ K) X)).toRingHom) (homogenize p) = _ at h + rwa [hcomp] at h + +theorem polynomial_eval₂_homogenize + {S : Type*} [CommSemiring S] (c : K →+* S) (x : σ → S) + (p : MvPolynomial σ K) : + (homogenize p).eval₂ (Polynomial.C.comp c) + (fun o : Option σ => o.elim Polynomial.X (fun i => Polynomial.C (x i) * Polynomial.X)) = + Polynomial.C (p.eval₂ c x) * Polynomial.X ^ p.totalDegree := by + rw [eval₂_homogenize, ← MvPolynomial.hom_eval₂] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +variable {K σ : Type*} [CommRing K] + +theorem coneMap_homogenize (p : Ideal (MvPolynomial σ K)) (f : MvPolynomial σ K) : + coneMap p (homogenize f) = + Polynomial.C (Ideal.Quotient.mk p f) * Polynomial.X ^ f.totalDegree := by + rw [coneMap, aeval_def] + have halg : algebraMap K (Polynomial (MvPolynomial σ K ⧸ p)) = + Polynomial.C.comp (algebraMap K (MvPolynomial σ K ⧸ p)) := by + apply RingHom.ext + intro r + exact Polynomial.algebraMap_apply (A := MvPolynomial σ K ⧸ p) r + rw [halg] + rw [polynomial_eval₂_homogenize] + congr 2 + have h : (MvPolynomial.aeval (fun i => Ideal.Quotient.mk p (X i)) : + MvPolynomial σ K →ₐ[K] MvPolynomial σ K ⧸ p) = Ideal.Quotient.mkₐ K p := by + ext i + simp + exact congrArg (fun g => g f) h + +theorem homogenize_mem_coneIdeal (p : Ideal (MvPolynomial σ K)) + {f : MvPolynomial σ K} (hf : f ∈ p) : homogenize f ∈ coneIdeal p := by + change coneMap p (homogenize f) = 0 + rw [coneMap_homogenize, Ideal.Quotient.eq_zero_iff_mem.mpr hf, map_zero, zero_mul] + +theorem map_coneIdeal_dehomogenize (p : Ideal (MvPolynomial σ K)) : + Ideal.map coneDehomogenize.toRingHom (coneIdeal p) = p := by + apply le_antisymm (map_coneIdeal_dehomogenize_le p) + intro f hf + have hmem := Ideal.mem_map_of_mem coneDehomogenize.toRingHom + (homogenize_mem_coneIdeal p hf) + simpa only [AlgHom.toRingHom_eq_coe, RingHom.coe_coe, coneDehomogenize, + dehomogenize_homogenize] using hmem + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem conePolynomialMap_homogenize {K σ : Type*} [CommRing K] + (f : MvPolynomial σ K) : + conePolynomialMap (homogenize f) = Polynomial.C f * Polynomial.X ^ f.totalDegree := by + rw [conePolynomialMap, aeval_def] + have halg : algebraMap K (Polynomial (MvPolynomial σ K)) = + Polynomial.C.comp (algebraMap K (MvPolynomial σ K)) := by + apply RingHom.ext + intro r + exact Polynomial.algebraMap_apply (A := MvPolynomial σ K) r + rw [halg, polynomial_eval₂_homogenize, MvPolynomial.algebraMap_eq] + simp + +theorem conePolynomialMap_padded_homogenize {K σ : Type*} [CommRing K] + (f : MvPolynomial σ K) (e : ℕ) : + conePolynomialMap ((X (none : Option σ)) ^ e * homogenize f) = + Polynomial.C f * Polynomial.X ^ (e + f.totalDegree) := by + rw [map_mul, map_pow, conePolynomialMap_X_none, conePolynomialMap_homogenize, pow_add] + exact mul_left_comm _ _ _ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem quotient_length_eq_of_flat_local_extension + {A B : Type*} [CommRing A] [CommRing B] [IsLocalRing A] [IsLocalRing B] + [Algebra A B] [Module.Flat A B] + (hm : (IsLocalRing.maximalIdeal A).map (algebraMap A B) = + IsLocalRing.maximalIdeal B) (I : Ideal A) : + Module.length B (B ⧸ I.map (algebraMap A B)) = Module.length A (A ⧸ I) := by + let : IsLocalHom (algebraMap A B) := + ((IsLocalRing.local_hom_TFAE (algebraMap A B)).out 3 1).mp hm.le + have hlength : Module.length B (B ⧸ IsLocalRing.maximalIdeal B) = 1 := by + rw [Module.length_eq_one_iff, isSimpleModule_iff_isCoatom, ← Ideal.isMaximal_def] + infer_instance + rw [(Algebra.TensorProduct.quotIdealMapEquivTensorQuot B I).toLinearEquiv.length_eq, + IsLocalRing.length_baseChange A B (A ⧸ I), hm, hlength, mul_one] + +theorem quotient_length_local_polynomial + {A : Type*} [CommRing A] [IsLocalRing A] (I : Ideal A) : + let p := (IsLocalRing.maximalIdeal A).map (Polynomial.C : A →+* Polynomial A) + let B := Localization.AtPrime p + Module.length B (B ⧸ I.map (algebraMap A B)) = Module.length A (A ⧸ I) := by + dsimp only + let : Module.Free A (Polynomial A) := .of_basis (Polynomial.basisMonomials A) + apply quotient_length_eq_of_flat_local_extension + rw [IsScalarTower.algebraMap_eq A (Polynomial A) _, ← Ideal.map_map, + Polynomial.algebraMap_eq] + exact Localization.AtPrime.map_eq_maximalIdeal + +theorem local_polynomial_parameter_isUnit + {A : Type*} [CommRing A] [IsLocalRing A] : + let p := (IsLocalRing.maximalIdeal A).map (Polynomial.C : A →+* Polynomial A) + let B := Localization.AtPrime p + IsUnit (algebraMap (Polynomial A) B Polynomial.X) := by + dsimp only + apply IsLocalization.map_units + (M := ((IsLocalRing.maximalIdeal A).map + (Polynomial.C : A →+* Polynomial A)).primeCompl) _ ⟨Polynomial.X, ?_⟩ + change Polynomial.X ∉ + (IsLocalRing.maximalIdeal A).map (Polynomial.C : A →+* Polynomial A) + intro h + have h1 : (1 : A) ∈ IsLocalRing.maximalIdeal A := by + simpa using (Ideal.mem_map_C_iff.mp h) 1 + exact (IsLocalRing.maximalIdeal.isMaximal A).ne_top + ((IsLocalRing.maximalIdeal A).eq_top_of_isUnit_mem h1 isUnit_one) + + + +theorem span_range_mul_units {ι A : Type*} [CommRing A] + (a u : ι → A) (hu : ∀ i, IsUnit (u i)) : + Ideal.span (Set.range fun i => a i * u i) = Ideal.span (Set.range a) := by + simp only [Ideal.span_range_eq_iSup, Ideal.span_singleton_mul_right_unit (hu _)] + +theorem quotient_length_eq_of_ringEquiv {A B : Type*} [CommRing A] [CommRing B] + (e : A ≃+* B) (I : Ideal A) : + Module.length B (B ⧸ I.map e) = Module.length A (A ⧸ I) := by + rw [Module.length_quotient, Module.length_quotient] + exact Order.coheight_orderIso e.idealComapOrderIso.symm I + +theorem radical_map_eq_maximal_of_radical_eq + {A B : Type*} [CommRing A] [CommRing B] [IsLocalRing A] [IsLocalRing B] + (f : A →+* B) (hm : (IsLocalRing.maximalIdeal A).map f = IsLocalRing.maximalIdeal B) + (I : Ideal A) (hI : I.radical = IsLocalRing.maximalIdeal A) : + (I.map f).radical = IsLocalRing.maximalIdeal B := by + apply le_antisymm + · exact (Ideal.radical_mono (Ideal.map_mono (I.le_radical.trans_eq hI))).trans_eq + (by rw [hm]; exact Ideal.IsPrime.radical inferInstance) + · rw [← hm, ← hI] + exact Ideal.map_radical_le f + +theorem mem_minimalPrimes_of_local_radical {A : Type*} [CommRing A] + (p I : Ideal A) [p.IsPrime] + (hI : (I.map (algebraMap A (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + p ∈ I.minimalPrimes := by + have hlocal : IsLocalRing.maximalIdeal (Localization.AtPrime p) ∈ + (I.map (algebraMap A (Localization.AtPrime p))).minimalPrimes := by + rw [← Ideal.radical_minimalPrimes, hI, Ideal.minimalPrimes_eq_subsingleton_self] + exact Set.mem_singleton _ + rwa [IsLocalization.minimalPrimes_map p.primeCompl (Localization.AtPrime p) I, + Set.mem_preimage, IsLocalization.AtPrime.under_maximalIdeal (Localization.AtPrime p) p] at hlocal + +theorem local_polynomial_scaled_span {ι A : Type*} [CommRing A] [IsLocalRing A] + (a : ι → A) (e : ι → ℕ) : + let p := (IsLocalRing.maximalIdeal A).map (Polynomial.C : A →+* Polynomial A) + let B := Localization.AtPrime p + Ideal.span (Set.range fun i => + algebraMap (Polynomial A) B (Polynomial.C (a i) * Polynomial.X ^ e i)) = + (Ideal.span (Set.range a)).map (algebraMap A B) := by + dsimp only + let p := (IsLocalRing.maximalIdeal A).map (Polynomial.C : A →+* Polynomial A) + let B := Localization.AtPrime p + have hunit : IsUnit (algebraMap (Polynomial A) B Polynomial.X) := + local_polynomial_parameter_isUnit + simp only [map_mul, map_pow] + rw [span_range_mul_units _ _ (fun i => hunit.pow (e i)), Ideal.map_span, ← Set.range_comp] + rfl + + + +open MvPolynomial + +noncomputable def paddedHomogenizedIdeal {ι K σ : Type*} [CommRing K] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) : Ideal (MvPolynomial (Option σ) K) := + Ideal.span (Set.range fun i => (X (none : Option σ)) ^ n i * homogenize (f i)) + +theorem paddedHomogenizedIdeal_le_coneIdeal {ι K σ : Type*} [CommRing K] + (p : Ideal (MvPolynomial σ K)) (f : ι → MvPolynomial σ K) (n : ι → ℕ) + (hf : ∀ i, f i ∈ p) : paddedHomogenizedIdeal f n ≤ coneIdeal p := by + apply Ideal.span_le.mpr + rintro _ ⟨i, rfl⟩ + exact Ideal.mul_mem_left _ _ (homogenize_mem_coneIdeal p (hf i)) + +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem paddedHomogenizedIdeal_isHomogeneous {ι K σ : Type*} [CommRing K] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) : + (paddedHomogenizedIdeal f n).IsHomogeneous (homogeneousSubmodule (Option σ) K) := by + apply Ideal.homogeneous_span (homogeneousSubmodule (Option σ) K) + rintro _ ⟨i, rfl⟩ + exact ⟨n i + (f i).totalDegree, + (isHomogeneous_X_pow (R := K) (none : Option σ) (n i)).mul (homogenize_isHomogeneous (f i))⟩ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +attribute [local instance] coneIdeal_isPrime + +theorem coneLocalEquiv_padded_ideal {ι K σ : Type*} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) : + let A := MvPolynomial σ K + let R := Localization.AtPrime p + let S := MvPolynomial (Option σ) K + let L := Localization.AtPrime (coneIdeal p) + let B := Localization.AtPrime ((IsLocalRing.maximalIdeal R).map Polynomial.C) + ((paddedHomogenizedIdeal f n).map (algebraMap S L)).map (coneLocalEquiv p).toRingHom = + ((Ideal.span (Set.range f)).map (algebraMap A R)).map (algebraMap R B) := by + dsimp only + let A := MvPolynomial σ K + let R := Localization.AtPrime p + let S := MvPolynomial (Option σ) K + let L := Localization.AtPrime (coneIdeal p) + let B := Localization.AtPrime ((IsLocalRing.maximalIdeal R).map Polynomial.C) + have hgen (i : ι) : coneLocalEquiv p + (algebraMap S L ((X (none : Option σ)) ^ n i * homogenize (f i))) = + algebraMap (Polynomial R) B + (Polynomial.C (algebraMap A R (f i)) * Polynomial.X ^ (n i + (f i).totalDegree)) := by + rw [coneLocalEquiv_algebraMap, conePolynomialMap_padded_homogenize] + simp only [Polynomial.map_mul, Polynomial.map_C, Polynomial.map_pow, Polynomial.map_X] + rfl + calc + _ = Ideal.span (Set.range fun i => algebraMap (Polynomial R) B + (Polynomial.C (algebraMap A R (f i)) * Polynomial.X ^ (n i + (f i).totalDegree))) := by + simp only [paddedHomogenizedIdeal, Ideal.map_span, + ← Set.range_comp, Function.comp_def] + exact congrArg (fun v : ι → B => Ideal.span (Set.range v)) (funext hgen) + _ = (Ideal.span (Set.range fun i => algebraMap A R (f i))).map (algebraMap R B) := + local_polynomial_scaled_span (fun i => algebraMap A R (f i)) + (fun i => n i + (f i).totalDegree) + _ = _ := by + change (Ideal.span (Set.range fun i => algebraMap A R (f i))).map (algebraMap R B) = + ((Ideal.span (Set.range f)).map (algebraMap A R)).map (algebraMap R B) + congr 1 + rw [Ideal.map_span, ← Set.range_comp] + rfl + +theorem cone_padded_quotient_length {ι K σ : Type*} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) : + let A := MvPolynomial σ K + let R := Localization.AtPrime p + let S := MvPolynomial (Option σ) K + let L := Localization.AtPrime (coneIdeal p) + Module.length L (L ⧸ (paddedHomogenizedIdeal f n).map (algebraMap S L)) = + Module.length R (R ⧸ (Ideal.span (Set.range f)).map (algebraMap A R)) := by + dsimp only + let : CommRing (Localization.AtPrime p) := inferInstance + let : CommRing (Polynomial (Localization.AtPrime p)) := inferInstance + let B := Localization.AtPrime + ((IsLocalRing.maximalIdeal (Localization.AtPrime p)).map Polynomial.C) + refine (quotient_length_eq_of_ringEquiv (B := B) + (coneLocalEquiv p).toRingEquiv _).symm.trans ?_ + exact (congrArg (fun I : Ideal B => Module.length B (B ⧸ I)) + (coneLocalEquiv_padded_ideal p f n)).trans (quotient_length_local_polynomial _) + +theorem cone_padded_local_radical {ι K σ : Type*} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) + (hf : ((Ideal.span (Set.range f)).map + (algebraMap (MvPolynomial σ K) (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + ((paddedHomogenizedIdeal f n).map + (algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime (coneIdeal p)) := by + let A := MvPolynomial σ K + let R := Localization.AtPrime p + let S := MvPolynomial (Option σ) K + let L := Localization.AtPrime (coneIdeal p) + let B := Localization.AtPrime ((IsLocalRing.maximalIdeal R).map Polynomial.C) + let : CommRing R := inferInstance + let : CommRing (Polynomial R) := inferInstance + let J : Ideal L := (paddedHomogenizedIdeal f n).map (algebraMap S L) + have hradB : (J.map (coneLocalEquiv p).toRingHom).radical = IsLocalRing.maximalIdeal B := by + change (((paddedHomogenizedIdeal f n).map (algebraMap S L)).map + (coneLocalEquiv p).toRingHom).radical = _ + rw [coneLocalEquiv_padded_ideal] + apply radical_map_eq_maximal_of_radical_eq (A := R) (B := B) (algebraMap R B) _ _ hf + rw [IsScalarTower.algebraMap_eq R (Polynomial R) _, ← Ideal.map_map, + Polynomial.algebraMap_eq] + exact Localization.AtPrime.map_eq_maximalIdeal + have hradL : J.radical = IsLocalRing.maximalIdeal L := by + let : IsLocalHom (coneLocalEquiv p).toRingHom := + IsLocalHom.of_surjective _ (coneLocalEquiv p).surjective + have h := congrArg (Ideal.comap (coneLocalEquiv p).toRingHom) hradB + rw [Ideal.comap_radical, + Ideal.comap_map_of_bijective (coneLocalEquiv p).toRingHom (coneLocalEquiv p).bijective, + IsLocalRing.maximalIdeal_comap] at h + exact h + exact hradL + +theorem coneIdeal_mem_minimalPrimes_padded {ι K σ : Type*} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : ι → MvPolynomial σ K) (n : ι → ℕ) + (hf : ((Ideal.span (Set.range f)).map + (algebraMap (MvPolynomial σ K) (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + coneIdeal p ∈ (paddedHomogenizedIdeal f n).minimalPrimes := by + exact mem_minimalPrimes_of_local_radical (coneIdeal p) (paddedHomogenizedIdeal f n) + (cone_padded_local_radical p f n hf) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem padded_homogenize_isHomogeneous_of_le {K σ : Type*} [CommSemiring K] + (f : MvPolynomial σ K) (D : ℕ) (hf : f.totalDegree ≤ D) : + ((X (none : Option σ)) ^ (D - f.totalDegree) * homogenize f).IsHomogeneous D := by + simpa only [Nat.sub_add_cancel hf] using + (isHomogeneous_X_pow (R := K) (none : Option σ) (D - f.totalDegree)).mul + (homogenize_isHomogeneous f) + +theorem padded_homogenize_totalDegree_le {K σ : Type*} [CommSemiring K] + (f : MvPolynomial σ K) (D : ℕ) (hf : f.totalDegree ≤ D) : + ((X (none : Option σ)) ^ (D - f.totalDegree) * homogenize f).totalDegree ≤ D := + (padded_homogenize_isHomogeneous_of_le f D hf).totalDegree_le + +end WeightedTorusJets.Geometry + +end + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/IdealPowLayer.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/IdealPowLayer.lean new file mode 100644 index 0000000000000000000000000000000000000000..6e9d10a56c77abd574c6c4cf4068f9c8f0be1f73 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/IdealPowLayer.lean @@ -0,0 +1,558 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.InvariantJetMonomial +import OAI.NumberTheory.Jacobsthal.Siegel.PolynomialLinearCoefficients + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +namespace WeightedTorusJets.Geometry + +theorem finrank_polynomialBox (K : Type*) [Field K] (N : ℕ) : + Module.finrank K (polynomialBox K N) = N ^ 4 := by + let f : (Fin 4 → Fin N) → (Fin 4 →₀ ℕ) := + fun n => Finsupp.equivFunOnFinite.symm fun i => (n i : ℕ) + have hf : Function.Injective f := by + intro n m h + funext i + apply Fin.ext + exact congrArg (fun g : Fin 4 →₀ ℕ => g i) h + have h := (MvPolynomial.basisMonomials (Fin 4) K).linearIndependent.comp f hf + convert! finrank_span_eq_card h using 1 + simp + +theorem invariantJet_mem_polynomialBox {K : Type*} [Field K] {N : ℕ} + (c : Fin 3 → Fin 4 → K) (a : Fin 3 → ℕ) + {F : MvPolynomial (Fin 4) K} (hF : F ∈ polynomialBox K N) : + invariantJet c a F ∈ polynomialBox K N := by + let L : Module.End K (MvPolynomial (Fin 4) K) := + (invariantDerivation (c 0)).toLinearMap ^ a 0 * + (invariantDerivation (c 1)).toLinearMap ^ a 1 * + (invariantDerivation (c 2)).toLinearMap ^ a 2 + have hL (g : MvPolynomial (Fin 4) K) : L g = invariantJet c a g := by + simp only [L, Module.End.mul_apply, Module.End.pow_apply, Derivation.coeFn_coe, + invariantJet] + rw [← hL] + induction hF using Submodule.span_induction with + | mem g hg => + obtain ⟨n, rfl⟩ := hg + rw [hL, invariantJet_monomial] + exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨n, rfl⟩) + | zero => simpa only [map_zero] using (polynomialBox K N).zero_mem + | add f g _ _ hf hg => simpa only [map_add] using Submodule.add_mem _ hf hg + | smul r f _ hf => simpa only [map_smul] using Submodule.smul_mem _ r hf + +theorem invariantDerivation_mem_polynomialBox {K : Type*} [Field K] {N : ℕ} + (c : Fin 4 → K) {F : MvPolynomial (Fin 4) K} (hF : F ∈ polynomialBox K N) : + invariantDerivation c F ∈ polynomialBox K N := by + simpa [invariantJet] using invariantJet_mem_polynomialBox ![c, 0, 0] ![1, 0, 0] hF + + + +theorem surjective_of_rectangular_first_order + {R σ : Type*} [CommRing R] [Algebra ℚ R] [Fintype σ] + (m : Ideal R) [m.IsMaximal] (k : σ → ℕ) (hk : ∀ i, 2 ≤ k i) + (D : σ → Derivation ℚ R R) + (hD : LinearIndependent (R ⧸ m) (fun i => derivationCotangentResidue (D i) m)) + (φ : R →+* (MvPolynomial σ (R ⧸ m) ⧸ rectangularIdeal k)) + (hres : ∀ a, rectangularAugmentation k (fun i => by have := hk i; omega) (φ a) = + Ideal.Quotient.mk m a) + (hfirst : ∀ x : m, φ x - + ∑ i, Ideal.Quotient.mk m (D i x) • + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i) ∈ + (RingHom.ker (rectangularAugmentation (K := R ⧸ m) k + (fun i => by have := hk i; omega)).toRingHom) ^ 2) : + Function.Surjective φ := by + classical + let := Ideal.Quotient.field m + let ε : (MvPolynomial σ (R ⧸ m) ⧸ rectangularIdeal k) →ₐ[R ⧸ m] R ⧸ m := + rectangularAugmentation (K := R ⧸ m) k (fun i => by have := hk i; omega) + let N := RingHom.ker ε.toRingHom + have hres' (a : R) : ε (φ a) = Ideal.Quotient.mk m a := hres a + have hφ : Function.Surjective φ := by + apply surjective_of_nilpotent_ideal_lifts φ N + (isNilpotent_ker_rectangularAugmentation k (fun i => by have := hk i; omega)) + · intro z + obtain ⟨a, ha⟩ := Ideal.Quotient.mk_surjective (ε z) + refine ⟨a, ?_⟩ + change ε (z - φ a) = 0 + rw [map_sub, hres', ha, sub_self] + · intro z hz + let zN : N := ⟨z, hz⟩ + let c : σ → R ⧸ m := rectangularAugmentationCotangentEquiv k hk (N.toCotangent zN) + obtain ⟨x, hx⟩ := exists_ideal_element_with_derivatives m D hD c + refine ⟨x, ?_, ?_⟩ + · change ε (φ x) = 0 + rw [hres'] + exact Ideal.Quotient.eq_zero_iff_mem.mpr x.property + · have hlinear := rectangularAugmentation_linear_representative k hk zN + have hfirstx := hfirst x + simp_rw [hx] at hfirstx + change z - ∑ i, c i • Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i) ∈ + N ^ 2 at hlinear + change φ x - ∑ i, c i • Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i) ∈ + N ^ 2 at hfirstx + convert (N ^ 2).sub_mem hlinear hfirstx using 1 <;> abel + exact hφ + + + +abbrev idealPowLayer {A : Type*} [CommRing A] (I : Ideal A) (n : ℕ) := + ↥(I ^ n) ⧸ (I • ⊤ : Submodule A ↥(I ^ n)) + +theorem idealPowLayer_kernel {A : Type*} [CommRing A] (I : Ideal A) (n : ℕ) : + (LinearMap.ker (Submodule.mkQ (I • ⊤ : Submodule A ↥(I ^ n)))).map + (I ^ n).subtype = I ^ (n + 1) := by + rw [Submodule.ker_mkQ, Submodule.map_smul'', Submodule.map_subtype_top, + Ideal.smul_eq_mul, pow_succ'] + + +def mapIdealPowLayer {R A B : Type*} [CommRing R] [CommRing A] [CommRing B] + [Algebra R A] [Algebra R B] (f : A →ₐ[R] B) + (I : Ideal A) (J : Ideal B) (hf : I ≤ J.comap f) (n : ℕ) : + idealPowLayer I n →ₗ[R] idealPowLayer J n := by + have hpow : I ^ n ≤ (J ^ n).comap f := + (pow_le_pow_left' hf n).trans (Ideal.le_comap_pow f n) + refine Submodule.mapQ ((I • ⊤ : Submodule A ↥(I ^ n)).restrictScalars R) + ((J • ⊤ : Submodule B ↥(J ^ n)).restrictScalars R) ?_ ?_ + · exact f.toLinearMap.restrict (p := (I ^ n).restrictScalars R) + (q := (J ^ n).restrictScalars R) hpow + · intro x hx + rw [Submodule.restrictScalars_mem] at hx + refine Submodule.smul_induction_on hx ?_ (fun _ _ ↦ add_mem) + rintro a ha ⟨b, hb⟩ _ + change (⟨f (a * b), hpow ((I ^ n).mul_mem_left a hb)⟩ : ↥(J ^ n)) ∈ + J • (⊤ : Submodule B ↥(J ^ n)) + convert! + (Submodule.smul_mem_smul (M := ↥(J ^ n)) (r := f a) (n := ⟨f b, hpow hb⟩) + (hf ha) Submodule.mem_top) using 1 + ext + exact map_mul f a b + +def mapIdealPowLayerSemilinear {A B : Type*} [CommRing A] [CommRing B] + (f : A →+* B) (I : Ideal A) (J : Ideal B) (hf : I ≤ J.comap f) (n : ℕ) : + idealPowLayer I n →ₛₗ[Ideal.quotientMap J f hf] idealPowLayer J n := by + let : Algebra A B := f.toAlgebra + let g := mapIdealPowLayer (Algebra.ofId A B) I J hf n + exact + { toFun := g + map_add' := g.map_add + map_smul' := by + intro c x + obtain ⟨a, rfl⟩ := Ideal.Quotient.mk_surjective c + change g (a • x) = f a • g x + exact g.map_smul a x } + + + +theorem length_idealPow_step {A : Type*} [CommRing A] (I : Ideal A) (n : ℕ) : + Module.length A ↥(I ^ n) = + Module.length A ↥(I ^ (n + 1)) + Module.length A (idealPowLayer I n) := by + let P := (I • ⊤ : Submodule A ↥(I ^ n)) + have hP : P.map (I ^ n).subtype = I ^ (n + 1) := by + simpa only [Submodule.ker_mkQ] using idealPowLayer_kernel I n + have hlen : Module.length A P = Module.length A ↥(I ^ (n + 1)) := by + exact (((I ^ n).equivSubtypeMap P).trans (LinearEquiv.ofEq _ _ hP)).length_eq + rw [Module.length_eq_add_of_exact P.subtype P.mkQ (Submodule.subtype_injective P) + (Submodule.mkQ_surjective P) (LinearMap.exact_subtype_mkQ P), hlen] + +theorem length_eq_sum_idealPowLayer {A : Type*} [CommRing A] + (I : Ideal A) (N : ℕ) (hN : I ^ N = ⊥) : + Module.length A A = ∑ n ∈ Finset.range N, Module.length A (idealPowLayer I n) := by + have hsum : ∀ j : ℕ, Module.length A A = + Module.length A ↥(I ^ j) + ∑ n ∈ Finset.range j, Module.length A (idealPowLayer I n) := by + intro j + induction j with + | zero => + simp only [Finset.range_zero, Finset.sum_empty, add_zero] + have htop : I ^ 0 = ⊤ := by simp + exact (Module.length_top (R := A) (M := A)).symm.trans + (LinearEquiv.ofEq _ _ htop).length_eq.symm + | succ j ih => + rw [Finset.sum_range_succ] + calc + Module.length A A = Module.length A ↥(I ^ j) + + ∑ n ∈ Finset.range j, Module.length A (idealPowLayer I n) := ih + _ = Module.length A ↥(I ^ (j + 1)) + Module.length A (idealPowLayer I j) + + ∑ n ∈ Finset.range j, Module.length A (idealPowLayer I n) := by + rw [length_idealPow_step I j] + _ = _ := by ac_rfl + have hzero : Module.length A ↥(I ^ N) = 0 := + (LinearEquiv.ofEq _ _ hN).length_eq.trans (Module.length_bot (R := A) (M := A)) + simpa only [hzero, zero_add] using hsum N + +theorem length_idealPowLayer_eq_finrank {A : Type*} [CommRing A] [IsNoetherianRing A] + (I : Ideal A) [I.IsMaximal] (n : ℕ) : + Module.length A (idealPowLayer I n) = + (Module.finrank (A ⧸ I) (idealPowLayer I n) : ℕ∞) := by + let := Ideal.Quotient.field I + let : Module.Finite (A ⧸ I) (idealPowLayer I n) := + Module.Finite.of_restrictScalars_finite A (A ⧸ I) (idealPowLayer I n) + rw [Module.length_eq_of_surjective (R := A ⧸ I) (S := A) + (Ideal.Quotient.mk_surjective)] + exact Module.length_eq_finrank (A ⧸ I) (idealPowLayer I n) + +theorem length_eq_sum_finrank_idealPowLayer {A : Type*} [CommRing A] [IsNoetherianRing A] + (I : Ideal A) [I.IsMaximal] (N : ℕ) (hN : I ^ N = ⊥) : + Module.length A A = + ∑ n ∈ Finset.range N, (Module.finrank (A ⧸ I) (idealPowLayer I n) : ℕ∞) := by + rw [length_eq_sum_idealPowLayer I N hN] + apply Finset.sum_congr rfl + intro n hn + exact length_idealPowLayer_eq_finrank I n + + + +theorem quotient_length_eq_sum_finrank_idealPowLayer + {R : Type*} [CommRing R] [IsNoetherianRing R] + (J m : Ideal R) [m.IsMaximal] (hJm : J ≤ m) + (N : ℕ) (hN : (m.map (Ideal.Quotient.mk J)) ^ N = ⊥) : + Module.length R (R ⧸ J) = + ∑ n ∈ Finset.range N, + let := Module.compHom (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) + (DoubleQuot.quotQuotEquivQuotOfLE hJm).symm.toRingHom + (Module.finrank (R ⧸ m) (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) : ℕ∞) := by + let I := m.map (Ideal.Quotient.mk J) + let : IsNoetherianRing (R ⧸ J) := + isNoetherianRing_of_surjective R (R ⧸ J) (Ideal.Quotient.mk J) Ideal.Quotient.mk_surjective + let : I.IsMaximal := Ideal.IsMaximal.map_of_surjective_of_ker_le + Ideal.Quotient.mk_surjective (by simpa only [Ideal.mk_ker] using hJm) + calc + Module.length R (R ⧸ J) = Module.length (R ⧸ J) (R ⧸ J) := + Module.length_eq_of_surjective (R := R ⧸ J) (M := R ⧸ J) (S := R) + Ideal.Quotient.mk_surjective + _ = ∑ n ∈ Finset.range N, + (Module.finrank ((R ⧸ J) ⧸ I) (idealPowLayer I n) : ℕ∞) := + length_eq_sum_finrank_idealPowLayer I N hN + _ = _ := by + apply Finset.sum_congr rfl + intro n hn + let e := DoubleQuot.quotQuotEquivQuotOfLE hJm + let := Module.compHom (idealPowLayer I n) e.symm.toRingHom + have hdim : Module.finrank (R ⧸ m) (idealPowLayer I n) = + Module.finrank ((R ⧸ J) ⧸ I) (idealPowLayer I n) := + congrArg Cardinal.toNat (rank_eq_of_equiv_equiv e.symm + (AddEquiv.refl (idealPowLayer I n)) e.symm.bijective (fun _ _ => rfl)) + exact congrArg (fun z : ℕ => (z : ℕ∞)) hdim.symm + + + + +theorem augmentation_length_eq_sum_finrank_idealPowLayer + {K A : Type*} [Field K] [CommRing A] [Algebra K A] [Module.Finite K A] + (q : A →ₐ[K] K) (N : ℕ) (hN : (RingHom.ker q) ^ N = ⊥) : + Module.length A A = + ∑ n ∈ Finset.range N, (Module.finrank K (idealPowLayer (RingHom.ker q) n) : ℕ∞) := by + have hnil : IsNilpotent (RingHom.ker q) := ⟨N, by simpa only [Ideal.zero_eq_bot] using hN⟩ + let := isLocalRing_of_nilpotent_augmentation q hnil + rw [length_eq_sum_idealPowLayer (RingHom.ker q) N hN] + apply Finset.sum_congr rfl + intro n hn + exact local_module_length_eq_finrank (residue_surjective_of_nilpotent_augmentation q hnil) + + + +noncomputable def mapIdealPowLayerQuotientAugmentation {R B : Type*} + [CommRing R] [CommRing B] (J m : Ideal R) (hJm : J ≤ m) [Algebra (R ⧸ m) B] + (f : (R ⧸ J) →+* B) (q : B →ₐ[R ⧸ m] R ⧸ m) + (hcomp : (q.toRingHom.comp f).comp (Ideal.Quotient.mk J) = Ideal.Quotient.mk m) + (n : ℕ) : + let e := DoubleQuot.quotQuotEquivQuotOfLE hJm + letI := Module.compHom (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) e.symm.toRingHom + idealPowLayer (m.map (Ideal.Quotient.mk J)) n →ₗ[R ⧸ m] + idealPowLayer (RingHom.ker q) n := by + let e := DoubleQuot.quotQuotEquivQuotOfLE hJm + letI := Module.compHom (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) e.symm.toRingHom + have hf : m.map (Ideal.Quotient.mk J) ≤ (RingHom.ker q).comap f := by + intro a ha + obtain ⟨r, hr, rfl⟩ := + (Ideal.mem_map_iff_of_surjective (Ideal.Quotient.mk J) Ideal.Quotient.mk_surjective).mp ha + change q (f (Ideal.Quotient.mk J r)) = 0 + exact (RingHom.congr_fun hcomp r).trans (Ideal.Quotient.eq_zero_iff_mem.mpr hr) + have hq : Function.Surjective q := fun c => ⟨algebraMap (R ⧸ m) B c, q.commutes c⟩ + have hscalar (c : R ⧸ m) : + Ideal.quotientMap (RingHom.ker q) f hf (e.symm c) = + algebraMap (R ⧸ m) (B ⧸ RingHom.ker q) c := by + obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective c + change Ideal.quotientMap (RingHom.ker q) f hf + ((DoubleQuot.quotQuotEquivQuotOfLE hJm).symm (Ideal.Quotient.mk m r)) = _ + rw [DoubleQuot.quotQuotEquivQuotOfLE_symm_mk] + apply (q.toRingHom.quotientKerEquivOfSurjective hq).injective + change q (f (Ideal.Quotient.mk J r)) = + q (algebraMap (R ⧸ m) B (Ideal.Quotient.mk m r)) + rw [q.commutes] + exact RingHom.congr_fun hcomp r + let g := mapIdealPowLayerSemilinear f (m.map (Ideal.Quotient.mk J)) (RingHom.ker q) hf n + refine { toFun := g, map_add' := g.map_add, map_smul' := ?_ } + intro c x + change g (e.symm c • x) = c • g x + rw [g.map_smulₛₗ, hscalar, algebraMap_smul] + +theorem quotientAugmentation_comap_ker_eq {R B : Type*} [CommRing R] [CommRing B] + (J m : Ideal R) (hJm : J ≤ m) [Algebra (R ⧸ m) B] + (f : (R ⧸ J) →+* B) (q : B →ₐ[R ⧸ m] R ⧸ m) + (hcomp : (q.toRingHom.comp f).comp (Ideal.Quotient.mk J) = Ideal.Quotient.mk m) : + (RingHom.ker q).comap f = m.map (Ideal.Quotient.mk J) := by + apply Ideal.comap_injective_of_surjective (Ideal.Quotient.mk J) Ideal.Quotient.mk_surjective + rw [Ideal.comap_map_of_surjective _ Ideal.Quotient.mk_surjective, + ← RingHom.ker_eq_comap_bot, Ideal.mk_ker, sup_eq_left.mpr hJm] + change RingHom.ker ((q.toRingHom.comp f).comp (Ideal.Quotient.mk J)) = m + rw [hcomp, Ideal.mk_ker] + +@[simp] +theorem mapIdealPowLayerQuotientAugmentation_mk {R B : Type*} + [CommRing R] [CommRing B] (J m : Ideal R) (hJm : J ≤ m) [Algebra (R ⧸ m) B] + (f : (R ⧸ J) →+* B) (q : B →ₐ[R ⧸ m] R ⧸ m) + (hcomp : (q.toRingHom.comp f).comp (Ideal.Quotient.mk J) = Ideal.Quotient.mk m) + (n : ℕ) (x : ↥((m.map (Ideal.Quotient.mk J)) ^ n)) : + mapIdealPowLayerQuotientAugmentation J m hJm f q hcomp n (Submodule.Quotient.mk x) = + Submodule.Quotient.mk + (⟨f x, (Ideal.le_comap_pow f n) + ((pow_le_pow_left' (quotientAugmentation_comap_ker_eq J m hJm f q hcomp).ge n) + x.property)⟩ : ↥((RingHom.ker q) ^ n)) := rfl + +theorem mapIdealPowLayerQuotientAugmentation_surjective {R B : Type*} + [CommRing R] [CommRing B] (J m : Ideal R) (hJm : J ≤ m) [Algebra (R ⧸ m) B] + (f : (R ⧸ J) →+* B) (q : B →ₐ[R ⧸ m] R ⧸ m) + (hcomp : (q.toRingHom.comp f).comp (Ideal.Quotient.mk J) = Ideal.Quotient.mk m) + (hf : Function.Surjective f) (n : ℕ) : + Function.Surjective (mapIdealPowLayerQuotientAugmentation J m hJm f q hcomp n) := by + intro y + obtain ⟨y, rfl⟩ := Submodule.Quotient.mk_surjective _ y + have hmap : ((m.map (Ideal.Quotient.mk J)) ^ n).map f = (RingHom.ker q) ^ n := by + rw [Ideal.map_pow, ← quotientAugmentation_comap_ker_eq J m hJm f q hcomp, + Ideal.map_comap_of_surjective f hf] + have hy : (y : B) ∈ ((m.map (Ideal.Quotient.mk J)) ^ n).map f := by + rw [hmap] + exact y.property + obtain ⟨x, hx, hxy⟩ := (Ideal.mem_map_iff_of_surjective f hf).mp hy + refine ⟨Submodule.Quotient.mk ⟨x, hx⟩, ?_⟩ + rw [mapIdealPowLayerQuotientAugmentation_mk] + congr 1 + exact Subtype.ext hxy + + +theorem finite_quotientIdealPowLayer_over_residue + {R : Type*} [CommRing R] [IsNoetherianRing R] + (J m : Ideal R) [m.IsMaximal] (hJm : J ≤ m) (n : ℕ) : + let := Module.compHom (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) + (DoubleQuot.quotQuotEquivQuotOfLE hJm).symm.toRingHom + Module.Finite (R ⧸ m) (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) := by + let I := m.map (Ideal.Quotient.mk J) + let : IsNoetherianRing (R ⧸ J) := + isNoetherianRing_of_surjective R (R ⧸ J) (Ideal.Quotient.mk J) Ideal.Quotient.mk_surjective + let : I.IsMaximal := Ideal.IsMaximal.map_of_surjective_of_ker_le + Ideal.Quotient.mk_surjective (by simpa only [Ideal.mk_ker] using hJm) + let := Ideal.Quotient.field m + let := Ideal.Quotient.field I + let : Module.Finite ((R ⧸ J) ⧸ I) (idealPowLayer I n) := + Module.Finite.of_restrictScalars_finite (R ⧸ J) ((R ⧸ J) ⧸ I) (idealPowLayer I n) + let e := DoubleQuot.quotQuotEquivQuotOfLE hJm + let := Module.compHom (idealPowLayer I n) e.symm.toRingHom + apply Module.rank_lt_aleph0_iff.mp + rw [rank_eq_of_equiv_equiv e.symm (AddEquiv.refl (idealPowLayer I n)) + e.symm.bijective (fun _ _ => rfl)] + exact Module.rank_lt_aleph0 _ _ + +theorem augmentation_length_le_quotient_length + {R B : Type*} [CommRing R] [IsNoetherianRing R] [CommRing B] + (J m : Ideal R) [m.IsMaximal] (hJm : J ≤ m) + [Algebra (R ⧸ m) B] [Module.Finite (R ⧸ m) B] + (f : (R ⧸ J) →+* B) (q : B →ₐ[R ⧸ m] R ⧸ m) + (hcomp : (q.toRingHom.comp f).comp (Ideal.Quotient.mk J) = Ideal.Quotient.mk m) + (hf : Function.Surjective f) + (N : ℕ) (hN : (m.map (Ideal.Quotient.mk J)) ^ N = ⊥) : + Module.length B B ≤ Module.length R (R ⧸ J) := by + let := Ideal.Quotient.field m + have htarget : (RingHom.ker q) ^ N = ⊥ := by + rw [← Ideal.map_comap_of_surjective f hf (RingHom.ker q), + quotientAugmentation_comap_ker_eq J m hJm f q hcomp, ← Ideal.map_pow, hN, Ideal.map_bot] + rw [augmentation_length_eq_sum_finrank_idealPowLayer q N htarget, + quotient_length_eq_sum_finrank_idealPowLayer J m hJm N hN] + apply Finset.sum_le_sum + intro n hn + let := Module.compHom (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) + (DoubleQuot.quotQuotEquivQuotOfLE hJm).symm.toRingHom + let := finite_quotientIdealPowLayer_over_residue J m hJm n + change (Module.finrank (R ⧸ m) (idealPowLayer (RingHom.ker q) n) : ℕ∞) ≤ + (Module.finrank (R ⧸ m) (idealPowLayer (m.map (Ideal.Quotient.mk J)) n) : ℕ∞) + exact_mod_cast LinearMap.finrank_le_finrank_of_surjective + (mapIdealPowLayerQuotientAugmentation_surjective J m hJm f q hcomp hf n) + +theorem augmentation_finrank_le_quotient_length + {R B : Type*} [CommRing R] [IsNoetherianRing R] [CommRing B] + (J m : Ideal R) [m.IsMaximal] (hJm : J ≤ m) + [Algebra (R ⧸ m) B] [Module.Finite (R ⧸ m) B] + (f : (R ⧸ J) →+* B) (q : B →ₐ[R ⧸ m] R ⧸ m) + (hcomp : (q.toRingHom.comp f).comp (Ideal.Quotient.mk J) = Ideal.Quotient.mk m) + (hf : Function.Surjective f) + (N : ℕ) (hN : (m.map (Ideal.Quotient.mk J)) ^ N = ⊥) : + (Module.finrank (R ⧸ m) B : ℕ∞) ≤ Module.length R (R ⧸ J) := by + let := Ideal.Quotient.field m + have htarget : (RingHom.ker q) ^ N = ⊥ := by + rw [← Ideal.map_comap_of_surjective f hf (RingHom.ker q), + quotientAugmentation_comap_ker_eq J m hJm f q hcomp, ← Ideal.map_pow, hN, Ideal.map_bot] + have hnil : IsNilpotent (RingHom.ker q) := ⟨N, by simpa only [Ideal.zero_eq_bot] using htarget⟩ + rw [← length_eq_finrank_of_nilpotent_augmentation q hnil] + exact augmentation_length_le_quotient_length J m hJm f q hcomp hf N hN + + +theorem local_graded_length_lower_of_rectangular_first_order + {R σ : Type*} [CommRing R] [Algebra ℚ R] [IsNoetherianRing R] [Fintype σ] + (m J : Ideal R) [m.IsMaximal] (k : σ → ℕ) (hk : ∀ i, 2 ≤ k i) + (D : σ → Derivation ℚ R R) + (hD : LinearIndependent (R ⧸ m) (fun i => derivationCotangentResidue (D i) m)) + (φ : R →+* (MvPolynomial σ (R ⧸ m) ⧸ rectangularIdeal k)) + (hJ : J ≤ RingHom.ker φ) + (hres : ∀ a, rectangularAugmentation k (fun i => by have := hk i; omega) (φ a) = + Ideal.Quotient.mk m a) + (hfirst : ∀ x : m, φ x - + ∑ i, Ideal.Quotient.mk m (D i x) • + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i) ∈ + (RingHom.ker (rectangularAugmentation (K := R ⧸ m) k + (fun i => by have := hk i; omega)).toRingHom) ^ 2) + (hprimary : J.radical = m) : + (∏ i, k i : ℕ) ≤ Module.length R (R ⧸ J) := by + classical + let := Ideal.Quotient.field m + let ε : (MvPolynomial σ (R ⧸ m) ⧸ rectangularIdeal k) →ₐ[R ⧸ m] R ⧸ m := + rectangularAugmentation (K := R ⧸ m) k (fun i => by have := hk i; omega) + have hφ := surjective_of_rectangular_first_order m k hk D hD φ hres hfirst + let ψ := Ideal.Quotient.lift J φ (fun _ hx => hJ hx) + have hψ : Function.Surjective ψ := by + intro z + obtain ⟨a, rfl⟩ := hφ z + exact ⟨Ideal.Quotient.mk J a, rfl⟩ + have hJm : J ≤ m := J.le_radical.trans_eq hprimary + have hcomp : (ε.toRingHom.comp ψ).comp (Ideal.Quotient.mk J) = Ideal.Quotient.mk m := by + ext a + exact hres a + obtain ⟨N, hN⟩ := J.exists_radical_pow_le_of_fg (Ideal.fg_of_isNoetherianRing _) + rw [hprimary] at hN + have hpow : (m.map (Ideal.Quotient.mk J)) ^ N = ⊥ := by + rw [← Ideal.map_pow, Ideal.map_eq_bot_iff_le_ker, Ideal.mk_ker] + exact hN + have h := augmentation_finrank_le_quotient_length J m hJm ψ ε hcomp hψ N hpow + simpa only [finrank_rectangularQuotient] using h + +variable {R : Type*} [CommRing R] [Algebra ℚ R] [IsNoetherianRing R] + +theorem derivativeStageIdeal_graded_length_lower_one (D : Fin 3 → Derivation ℚ R R) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (m : Ideal R) [m.IsMaximal] (I : Finset (Fin 3)) (i : I) (hi : ∀ j : I, j = i) + (t : Fin 3 → ℕ) (ht : ∀ j : I, 2 ≤ t j + 1) (b : ℕ) (F : R) + (hnext : derivativeStageIdeal D t (b + 1) F ≤ m) + (hD : LinearIndependent (R ⧸ m) (fun j : I => derivationCotangentResidue (D j) m)) + (hprimary : (derivativeStageIdeal D t b F).radical = m) : + (∏ j : I, (t j + 1) : ℕ) ≤ Module.length R (R ⧸ derivativeStageIdeal D t b F) := by + have hvanish := (derivativeStageIdeal_le_ker_iff D t (b + 1) F (Ideal.Quotient.mk m)).mp + (by simpa only [Ideal.mk_ker] using hnext) + refine local_graded_length_lower_of_rectangular_first_order m (derivativeStageIdeal D t b F) + (fun j : I => t j + 1) ht (fun j : I => D j) hD + (rectangularTaylorThree I (fun j => t j + 1) (D i) 0 0 i i i (Ideal.Quotient.mk m)) + (derivativeStageIdeal_le_ker_taylor_one D h01 h02 h12 I i t b F _ hvanish) ?_ ?_ hprimary + · intro a + exact rectangularTaylorThree_augmentation _ _ _ _ _ _ _ _ _ a + · intro x + exact rectangularTaylorThree_one_first_order _ ht (fun j : I => D j) i hi + (Ideal.Quotient.mk m) x (Ideal.Quotient.eq_zero_iff_mem.mpr x.property) + +theorem derivativeStageIdeal_graded_length_lower_two (D : Fin 3 → Derivation ℚ R R) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (m : Ideal R) [m.IsMaximal] (I : Finset (Fin 3)) (i j : I) (hij : i ≠ j) + (hcover : ∀ l : I, l = i ∨ l = j) + (t : Fin 3 → ℕ) (ht : ∀ l : I, 2 ≤ t l + 1) (b : ℕ) (F : R) + (hnext : derivativeStageIdeal D t (b + 1) F ≤ m) + (hD : LinearIndependent (R ⧸ m) (fun l : I => derivationCotangentResidue (D l) m)) + (hprimary : (derivativeStageIdeal D t b F).radical = m) : + (∏ l : I, (t l + 1) : ℕ) ≤ Module.length R (R ⧸ derivativeStageIdeal D t b F) := by + have hvanish := (derivativeStageIdeal_le_ker_iff D t (b + 1) F (Ideal.Quotient.mk m)).mp + (by simpa only [Ideal.mk_ker] using hnext) + refine local_graded_length_lower_of_rectangular_first_order m (derivativeStageIdeal D t b F) + (fun l : I => t l + 1) ht (fun l : I => D l) hD + (rectangularTaylorThree I (fun l => t l + 1) (D i) (D j) 0 i j j (Ideal.Quotient.mk m)) + (derivativeStageIdeal_le_ker_taylor_two D h01 h02 h12 I i j hij t b F _ hvanish) ?_ ?_ hprimary + · intro a + exact rectangularTaylorThree_augmentation _ _ _ _ _ _ _ _ _ a + · intro x + exact rectangularTaylorThree_two_first_order _ ht (fun l : I => D l) i j hij hcover + (Ideal.Quotient.mk m) x (Ideal.Quotient.eq_zero_iff_mem.mpr x.property) + +theorem derivativeStageIdeal_graded_length_lower_three (D : Fin 3 → Derivation ℚ R R) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (m : Ideal R) [m.IsMaximal] (I : Finset (Fin 3)) (i j l : I) + (hij : i ≠ j) (hil : i ≠ l) (hjl : j ≠ l) (hcover : ∀ u : I, u = i ∨ u = j ∨ u = l) + (t : Fin 3 → ℕ) (ht : ∀ u : I, 2 ≤ t u + 1) (b : ℕ) (F : R) + (hnext : derivativeStageIdeal D t (b + 1) F ≤ m) + (hD : LinearIndependent (R ⧸ m) (fun u : I => derivationCotangentResidue (D u) m)) + (hprimary : (derivativeStageIdeal D t b F).radical = m) : + (∏ u : I, (t u + 1) : ℕ) ≤ Module.length R (R ⧸ derivativeStageIdeal D t b F) := by + have hvanish := (derivativeStageIdeal_le_ker_iff D t (b + 1) F (Ideal.Quotient.mk m)).mp + (by simpa only [Ideal.mk_ker] using hnext) + refine local_graded_length_lower_of_rectangular_first_order m (derivativeStageIdeal D t b F) + (fun u : I => t u + 1) ht (fun u : I => D u) hD + (rectangularTaylorThree I (fun u => t u + 1) (D i) (D j) (D l) i j l (Ideal.Quotient.mk m)) + (derivativeStageIdeal_le_ker_taylor_three D h01 h02 h12 I i j l hij hil hjl t b F _ hvanish) ?_ ?_ hprimary + · intro a + exact rectangularTaylorThree_augmentation _ _ _ _ _ _ _ _ _ a + · intro x + exact rectangularTaylorThree_three_first_order _ ht (fun u : I => D u) i j l hij hil hjl hcover + (Ideal.Quotient.mk m) x (Ideal.Quotient.eq_zero_iff_mem.mpr x.property) + +theorem derivativeStageIdeal_graded_length_lower (D : Fin 3 → Derivation ℚ R R) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (m : Ideal R) [m.IsMaximal] (I : Finset (Fin 3)) (hI : I.Nonempty) + (t : Fin 3 → ℕ) (ht : ∀ i : I, 2 ≤ t i + 1) (b : ℕ) (F : R) + (hnext : derivativeStageIdeal D t (b + 1) F ≤ m) + (hD : LinearIndependent (R ⧸ m) (fun i : I => derivationCotangentResidue (D i) m)) + (hprimary : (derivativeStageIdeal D t b F).radical = m) : + (∏ i : I, (t i + 1) : ℕ) ≤ Module.length R (R ⧸ derivativeStageIdeal D t b F) := by + classical + have hpos := Finset.card_pos.mpr hI + have hmax : I.card ≤ 3 := by simpa using Finset.card_le_univ I + have hcard : I.card = 1 ∨ I.card = 2 ∨ I.card = 3 := by omega + rcases hcard with hcard | hcard | hcard + · obtain ⟨i, rfl⟩ := Finset.card_eq_one.mp hcard + exact derivativeStageIdeal_graded_length_lower_one D h01 h02 h12 m {i} ⟨i, by simp⟩ + (fun j => Subtype.ext (Finset.mem_singleton.mp j.property)) t ht b F hnext hD hprimary + · obtain ⟨i, j, hij, rfl⟩ := Finset.card_eq_two.mp hcard + let ii : ↥({i, j} : Finset (Fin 3)) := ⟨i, by simp⟩ + let jj : ↥({i, j} : Finset (Fin 3)) := ⟨j, by simp⟩ + refine derivativeStageIdeal_graded_length_lower_two D h01 h02 h12 m {i, j} ii jj + (fun h => hij (congrArg Subtype.val h)) ?_ t ht b F hnext hD hprimary + intro u + rcases Finset.mem_insert.mp u.property with hu | hu + · exact Or.inl (Subtype.ext hu) + · exact Or.inr (Subtype.ext (Finset.mem_singleton.mp hu)) + · obtain ⟨i, j, l, hij, hil, hjl, rfl⟩ := Finset.card_eq_three.mp hcard + let ii : ↥({i, j, l} : Finset (Fin 3)) := ⟨i, by simp⟩ + let jj : ↥({i, j, l} : Finset (Fin 3)) := ⟨j, by simp⟩ + let ll : ↥({i, j, l} : Finset (Fin 3)) := ⟨l, by simp⟩ + refine derivativeStageIdeal_graded_length_lower_three D h01 h02 h12 m {i, j, l} ii jj ll + (fun h => hij (congrArg Subtype.val h)) + (fun h => hil (congrArg Subtype.val h)) + (fun h => hjl (congrArg Subtype.val h)) ?_ t ht b F hnext hD hprimary + intro u + have hu : u.val = i ∨ u.val = j ∨ u.val = l := by + simpa only [Finset.mem_insert, Finset.mem_singleton] using u.property + rcases hu with hu | hu | hu + · exact Or.inl (Subtype.ext hu) + · exact Or.inr (Or.inl (Subtype.ext hu)) + · exact Or.inr (Or.inr (Subtype.ext hu)) + +end WeightedTorusJets.Geometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/IntegerCharacter.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/IntegerCharacter.lean new file mode 100644 index 0000000000000000000000000000000000000000..a59e5f3e5d1d469d65c23b531263572ddb8b40df --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/IntegerCharacter.lean @@ -0,0 +1,487 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open AddChar MulChar + +theorem primitive_gaussSum_mul_inv {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] [IsDomain R] + {χ : DirichletCharacter R q} (hχ : χ.IsPrimitive) + {e : AddChar (ZMod q) R} (he : e.IsPrimitive) : + gaussSum χ e * gaussSum χ⁻¹ e⁻¹ = q := by + classical + calc + gaussSum χ e * gaussSum χ⁻¹ e⁻¹ = + ∑ a : ZMod q, gaussSum χ (e.mulShift a) * e (-a) := by + simp_rw [gaussSum_mulShift_of_isPrimitive e hχ] + change gaussSum χ e * (∑ a : ZMod q, χ⁻¹ a * e (-a)) = _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + ring + _ = ∑ b : ZMod q, χ b * ∑ a : ZMod q, e (a * (b - 1)) := by + simp only [gaussSum, mulShift_apply, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + congr 1 + funext b + apply Finset.sum_congr rfl + intro a _ + rw [mul_assoc, ← e.map_add_eq_mul] + congr 2 + ring + _ = q := by + simp_rw [sum_mulShift _ he] + simp [sub_eq_zero] + +theorem primitive_quadratic_gaussSum_sq {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] [IsDomain R] + {χ : DirichletCharacter R q} (hχ : χ.IsPrimitive) (hquad : χ.IsQuadratic) + {e : AddChar (ZMod q) R} (he : e.IsPrimitive) : + gaussSum χ e ^ 2 = χ (-1) * q := by + rw [pow_two, ← primitive_gaussSum_mul_inv hχ he, hquad.inv, mul_rotate'] + congr 1 + rw [mul_comm, ← gaussSum_mulShift χ e (-1 : (ZMod q)ˣ), e.inv_mulShift] + rfl + +theorem primitive_gaussSum_ne_zero {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] [IsDomain R] [CharZero R] + {χ : DirichletCharacter R q} (hχ : χ.IsPrimitive) + {e : AddChar (ZMod q) R} (he : e.IsPrimitive) : gaussSum χ e ≠ 0 := by + intro h + have hq := primitive_gaussSum_mul_inv hχ he + rw [h, zero_mul] at hq + exact (Nat.cast_ne_zero.mpr (NeZero.ne q)) hq.symm + +theorem primitive_quadratic_gaussSum_integer_square {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] [IsDomain R] + {χ : DirichletCharacter R q} (hχ : χ.IsPrimitive) (hquad : χ.IsQuadratic) + {e : AddChar (ZMod q) R} (he : e.IsPrimitive) : + ∃ D : ℤ, D.natAbs = q ∧ gaussSum χ e ^ 2 = (D : R) := by + have hnonzero : χ (-1) ≠ 0 := (isUnit_neg_one.map χ).ne_zero + rcases hquad (-1) with h | h | h + · exact (hnonzero h).elim + · exact ⟨q, by simp, by simp [primitive_quadratic_gaussSum_sq hχ hquad he, h]⟩ + · exact ⟨-q, by simp, by simp [primitive_quadratic_gaussSum_sq hχ hquad he, h]⟩ + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem factorsThrough_ringHomComp_iff {q d : ℕ} [NeZero q] + {R S : Type*} [CommRing R] [CommRing S] (χ : DirichletCharacter R q) + (f : R →+* S) (hf : Function.Injective f) : + DirichletCharacter.FactorsThrough (χ.ringHomComp f) d ↔ χ.FactorsThrough d := by + by_cases hd : d ∣ q + · rw [DirichletCharacter.factorsThrough_iff_ker_unitsMap hd, + DirichletCharacter.factorsThrough_iff_ker_unitsMap hd] + change (∀ a, a ∈ (ZMod.unitsMap hd).ker → _ = 1) ↔ + (∀ a, a ∈ (ZMod.unitsMap hd).ker → _ = 1) + simp only [← Units.val_inj, MulChar.coe_toUnitHom, Units.val_one, + MulChar.ringHomComp_apply, ← f.map_one, hf.eq_iff] + · exact iff_of_false (fun h ↦ hd h.dvd) (fun h ↦ hd h.dvd) + +theorem conductor_ringHomComp {q : ℕ} [NeZero q] + {R S : Type*} [CommRing R] [CommRing S] (χ : DirichletCharacter R q) + (f : R →+* S) (hf : Function.Injective f) : + DirichletCharacter.conductor (χ.ringHomComp f) = χ.conductor := by + unfold DirichletCharacter.conductor + congr 1 + ext d + exact factorsThrough_ringHomComp_iff χ f hf + +noncomputable def integerCharacter {q : ℕ} (χ : DirichletCharacter ℂ q) + (hquad : χ.IsQuadratic) : DirichletCharacter ℤ q := by + let v : ZMod q → ℤ := fun a ↦ ⌊(χ a).re⌋ + have hv (a : ZMod q) : (v a : ℂ) = χ a := by + rcases hquad a with h | h | h <;> norm_num [v, h] + exact + { toFun := v + map_one' := by + apply Int.cast_injective (α := ℂ) + rw [hv, map_one, Int.cast_one] + map_mul' := fun a b ↦ by + apply Int.cast_injective (α := ℂ) + rw [Int.cast_mul, hv, hv, hv, map_mul] + map_nonunit' := fun a ha ↦ by + apply Int.cast_injective (α := ℂ) + rw [hv, MulChar.map_nonunit χ ha, Int.cast_zero] } + +@[simp] +theorem integerCharacter_cast {q : ℕ} (χ : DirichletCharacter ℂ q) + (hquad : χ.IsQuadratic) (a : ZMod q) : (integerCharacter χ hquad a : ℂ) = χ a := by + change (⌊(χ a).re⌋ : ℂ) = χ a + rcases hquad a with h | h | h <;> norm_num [h] + +theorem integerCharacter_ringHomComp {q : ℕ} (χ : DirichletCharacter ℂ q) + (hquad : χ.IsQuadratic) : + (integerCharacter χ hquad).ringHomComp (Int.castRingHom ℂ) = χ := by + ext a + exact integerCharacter_cast χ hquad a + +theorem integerCharacter_isPrimitive {q : ℕ} [NeZero q] (χ : DirichletCharacter ℂ q) + (hquad : χ.IsQuadratic) (hprim : χ.IsPrimitive) : + (integerCharacter χ hquad).IsPrimitive := by + change DirichletCharacter.conductor (integerCharacter χ hquad) = q + rw [← conductor_ringHomComp (integerCharacter χ hquad) (Int.castRingHom ℂ) + (Int.cast_injective (α := ℂ)), integerCharacter_ringHomComp] + exact hprim + +theorem integerCharacter_isQuadratic {q : ℕ} (χ : DirichletCharacter ℂ q) + (hquad : χ.IsQuadratic) : (integerCharacter χ hquad).IsQuadratic := by + apply MulChar.isQuadratic_iff_sq_eq_one.mpr + apply MulChar.injective_ringHomComp (f := Int.castRingHom ℂ) (Int.cast_injective (α := ℂ)) + dsimp only + rw [← MulChar.ringHomComp_pow, integerCharacter_ringHomComp, + MulChar.ringHomComp_one, hquad.sq_eq_one] + + + +open NumberField IsCyclotomicExtension.Rat + +theorem cyclotomic_gaussSum_action {n : ℕ} [NeZero n] {K : Type*} + [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] + (χ : DirichletCharacter K n) (hχ : χ.IsQuadratic) + (e : AddChar (ZMod n) K) (σ : Gal(K/ℚ)) : + σ (gaussSum χ e) = χ (galEquivZMod n K σ) * gaussSum χ e := by + have hroot (x : ZMod n) : e x ^ n = 1 := by + rw [← e.map_nsmul_eq_pow, nsmul_eq_mul] + simp + have he (x : ZMod n) : σ (e x) = e ((galEquivZMod n K σ) * x) := by + rw [galEquivZMod_apply_of_pow_eq n K σ (hroot x), ← e.map_nsmul_eq_pow, + nsmul_eq_mul, ZMod.natCast_zmod_val] + calc + σ (gaussSum χ e) = gaussSum χ (e.mulShift (galEquivZMod n K σ)) := by + simp only [gaussSum, map_sum, map_mul, AddChar.mulShift_apply] + apply Finset.sum_congr rfl + intro x _ + rw [he] + congr 1 + rcases hχ x with h | h | h <;> simp [h] + _ = χ (galEquivZMod n K σ) * gaussSum χ e := by + rw [gaussSum_mulShift_eq, hχ.inv] + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension.Rat + +variable (n : ℕ) [NeZero n] (K : Type*) [Field K] [NumberField K] + [IsCyclotomicExtension {n} ℚ K] [IsAbelianGalois ℚ K] + (R : Type*) [CommRing R] [HasEnoughRootsOfUnity R (Monoid.exponent (ZMod n)ˣ)] + +noncomputable def characterField (χ : DirichletCharacter R n) : IntermediateField ℚ K := + (intermediateFieldEquivSubgroupChar n K R).symm (Subgroup.zpowers χ) + +theorem characterField_finrank (χ : DirichletCharacter R n) (hχ : χ.IsQuadratic) + (hne : χ ≠ 1) : Module.finrank ℚ (characterField n K R χ) = 2 := by + rw [← card_intermediateFieldEquivSubgroupChar n K R, characterField, + OrderIso.apply_symm_apply, Nat.card_zpowers] + exact orderOf_eq_prime hχ.sq_eq_one hne + +theorem mem_characterField_fixingSubgroup (χ : DirichletCharacter R n) + (hχ : χ.IsQuadratic) (σ : Gal(K/ℚ)) : + σ ∈ (characterField n K R χ).fixingSubgroup ↔ χ (galEquivZMod n K σ) = 1 := by + change σ ∈ (IntermediateField.fixedField + ((subgroupGalEquivSubgroupChar n K R).symm + (OrderDual.toDual (Subgroup.zpowers χ)))).fixingSubgroup ↔ _ + rw [IntermediateField.fixingSubgroup_fixedField, mem_subgroupGalEquivSubgroupChar_symm_iff] + constructor + · intro h + exact h χ (Subgroup.mem_zpowers χ) + · intro h ψ hψ + obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp hψ + obtain ⟨m, rfl | rfl⟩ := Int.eq_nat_or_neg k + · simp only [zpow_natCast, MulChar.pow_apply_coe, h, one_pow] + · simp only [zpow_neg, zpow_natCast, ← inv_pow, hχ.inv, MulChar.pow_apply_coe, h, one_pow] + +theorem characterField_changeLevel [IsDomain R] {m : ℕ} [NeZero m] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {m} ℚ L] + [IsAbelianGalois ℚ L] [Algebra K L] [IsScalarTower ℚ K L] + [HasEnoughRootsOfUnity R (Monoid.exponent (ZMod m)ˣ)] + (hdiv : n ∣ m) (χ : DirichletCharacter R n) (hχ : χ.IsQuadratic) : + characterField m L R (DirichletCharacter.changeLevel hdiv χ) = + (characterField n K R χ).map (IsScalarTower.toAlgHom ℚ K L) := by + have hχ' : (DirichletCharacter.changeLevel hdiv χ).IsQuadratic := by + rw [MulChar.isQuadratic_iff_sq_eq_one, ← map_pow, hχ.sq_eq_one, map_one] + apply (IsGalois.intermediateFieldEquivSubgroup (F := ℚ) (E := L)).injective + change (characterField m L R (DirichletCharacter.changeLevel hdiv χ)).fixingSubgroup = + ((characterField n K R χ).map (IsScalarTower.toAlgHom ℚ K L)).fixingSubgroup + ext σ + have hm : σ ∈ ((characterField n K R χ).map + (IsScalarTower.toAlgHom ℚ K L)).fixingSubgroup ↔ + σ.restrictNormal K ∈ (characterField n K R χ).fixingSubgroup := by + simp only [IntermediateField.mem_fixingSubgroup_iff] + constructor + · intro h x hx + apply (algebraMap K L).injective + rw [AlgEquiv.restrictNormal_commutes] + exact h _ ⟨x, hx, rfl⟩ + · intro h y hy + obtain ⟨x, hx, rfl⟩ := hy + change σ (algebraMap K L x) = algebraMap K L x + rw [← AlgEquiv.restrictNormal_commutes, h x hx] + rw [hm, mem_characterField_fixingSubgroup n K R χ hχ, + mem_characterField_fixingSubgroup m L R _ hχ'] + rw [galEquivZMod_restrictNormal_apply m L K hdiv σ] + simp [DirichletCharacter.changeLevel_def] + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension.Rat + +theorem mem_adjoin_fixingSubgroup_iff {F K : Type*} [Field F] [Field K] [Algebra F K] + (g : K) (σ : Gal(K/F)) : + σ ∈ (IntermediateField.adjoin F {g}).fixingSubgroup ↔ σ g = g := by + rw [← Subgroup.zpowers_le, ← IntermediateField.le_iff_le, + IntermediateField.adjoin_simple_le_iff, IntermediateField.mem_fixedField_iff, + Subgroup.forall_mem_zpowers] + simpa only [MulAction.mem_fixedBy, AlgEquiv.smul_def] using + (MulAction.mem_fixedBy_zpowers_iff_mem_fixedBy (g := σ) (a := g)) + +theorem gaussSum_adjoin_eq_characterField {n : ℕ} [NeZero n] {K : Type*} + [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] [IsAbelianGalois ℚ K] + (χ : DirichletCharacter ℤ n) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + (e : AddChar (ZMod n) K) (he : e.IsPrimitive) : + IntermediateField.adjoin ℚ {gaussSum (χ.ringHomComp (Int.castRingHom K)) e} = + characterField n K ℂ (χ.ringHomComp (Int.castRingHom ℂ)) := by + have hprimK : DirichletCharacter.IsPrimitive (χ.ringHomComp (Int.castRingHom K)) := by + rw [DirichletCharacter.isPrimitive_def, conductor_ringHomComp χ (Int.castRingHom K) + (Int.cast_injective (α := K))] + exact hprim + have hg := primitive_gaussSum_ne_zero hprimK he + apply IsGalois.intermediateFieldEquivSubgroup.injective + change (IntermediateField.adjoin ℚ {_}).fixingSubgroup = + (characterField n K ℂ (χ.ringHomComp (Int.castRingHom ℂ))).fixingSubgroup + ext σ + rw [mem_adjoin_fixingSubgroup_iff, mem_characterField_fixingSubgroup _ _ _ _ + (hχ.comp (Int.castRingHom ℂ)), cyclotomic_gaussSum_action _ + (hχ.comp (Int.castRingHom K)), mul_eq_right₀ hg] + change ((χ (galEquivZMod n K σ) : K) = 1) ↔ + ((χ (galEquivZMod n K σ) : ℂ) = 1) + norm_cast + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem exists_squarefree_generator {K : Type*} [Field K] [CharZero K] [Algebra ℚ K] + {D : ℤ} (hD : D ≠ 0) {g : K} (hg : g ^ 2 = (D : K)) : + ∃ (d c : ℤ) (a : K), Squarefree d ∧ d.natAbs ≤ D.natAbs ∧ c ≠ 0 ∧ + D = c ^ 2 * d ∧ a ^ 2 = (d : K) ∧ IsIntegral ℤ a ∧ g = (c : K) * a ∧ + IntermediateField.adjoin ℚ {a} = IntermediateField.adjoin ℚ {g} := by + obtain ⟨c, d, hcd, hd⟩ := exists_sq_mul_squarefree D + have hc : c ≠ 0 := by + intro h + apply hD + rw [← hcd, h] + simp + have hcK : (c : K) ≠ 0 := Int.cast_ne_zero.mpr hc + have had : (g / (c : K)) ^ 2 = (d : K) := by + rw [div_pow, hg, ← hcd] + push_cast + exact mul_div_cancel_left₀ _ (pow_ne_zero 2 hcK) + refine ⟨d, c, g / (c : K), hd, ?_, hc, hcd.symm, had, ?_, ?_, ?_⟩ + · apply Nat.le_of_dvd (Int.natAbs_pos.mpr hD) + exact Int.natAbs_dvd_natAbs.mpr ⟨c ^ 2, by rw [← hcd, mul_comm]⟩ + · apply IsIntegral.of_pow (by decide : 0 < 2) + rw [had] + exact isIntegral_algebraMap + · exact (mul_div_cancel₀ g hcK).symm + · simpa only [div_eq_mul_inv, map_inv₀, map_intCast] using + IntermediateField.adjoin_simple_mul_algebraMap (F := ℚ) g ((c : ℚ)⁻¹) + (inv_ne_zero (Int.cast_ne_zero.mpr hc)) + + + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem not_isSquare_of_quadratic_adjoin {K : Type*} [Field K] [Algebra ℚ K] + {d : ℤ} {a : K} (ha : a ^ 2 = (d : K)) + (hdim : Module.finrank ℚ (IntermediateField.adjoin ℚ {a}) = 2) : + ¬ IsSquare (d : ℚ) := by + rintro ⟨r, hr⟩ + have hs : a ^ 2 = (algebraMap ℚ K r) ^ 2 := by + calc + a ^ 2 = (d : K) := ha + _ = algebraMap ℚ K (d : ℚ) := by simp + _ = (algebraMap ℚ K r) ^ 2 := by rw [hr, map_mul, pow_two] + have hmem : a ∈ (⊥ : IntermediateField ℚ K) := by + rcases (sq_eq_sq_iff_eq_or_eq_neg).mp hs with h | h + · rw [h] + exact IntermediateField.algebraMap_mem _ _ + · rw [h] + exact (⊥ : IntermediateField ℚ K).neg_mem (IntermediateField.algebraMap_mem _ _) + rw [IntermediateField.adjoin_simple_eq_bot_iff.mpr hmem, + IntermediateField.finrank_bot] at hdim + norm_num at hdim + +theorem exists_squarefree_characterField_generator {n : ℕ} [NeZero n] {K : Type*} + [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] [IsAbelianGalois ℚ K] + (χ : DirichletCharacter ℂ n) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + (hne : χ ≠ 1) : + ∃ (d : ℤ) (a : K), Squarefree d ∧ d.natAbs ≤ n ∧ d.natAbs ∣ n ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : K) ∧ + IsIntegral ℤ a ∧ IntermediateField.adjoin ℚ {a} = characterField n K ℂ χ ∧ + ∀ σ : Gal(K/ℚ), σ a = (integerCharacter χ hχ (galEquivZMod n K σ) : K) * a := by + let χI := integerCharacter χ hχ + let χK := χI.ringHomComp (Int.castRingHom K) + have hI := integerCharacter_isQuadratic χ hχ + have hpI := integerCharacter_isPrimitive χ hχ hprim + have hK : χK.IsQuadratic := hI.comp (Int.castRingHom K) + have hpK : DirichletCharacter.IsPrimitive χK := by + rw [DirichletCharacter.isPrimitive_def, conductor_ringHomComp χI (Int.castRingHom K) + (Int.cast_injective (α := K))] + exact hpI + let e := AddChar.zmodChar n (zeta_spec n ℚ K).pow_eq_one + have he : e.IsPrimitive := AddChar.zmodChar_primitive_of_primitive_root n (zeta_spec n ℚ K) + obtain ⟨D, hDabs, hgD⟩ := primitive_quadratic_gaussSum_integer_square hpK hK he + have hD : D ≠ 0 := by + intro h + have := hDabs + rw [h, Int.natAbs_zero] at this + exact (NeZero.ne n) this.symm + obtain ⟨d, c, a, hd, hbound, hc, hdc, ha, hint, hga, hadj⟩ := + exists_squarefree_generator hD hgD + have hadjχ : IntermediateField.adjoin ℚ {a} = characterField n K ℂ χ := by + rw [hadj, gaussSum_adjoin_eq_characterField χI hI hpI e he] + congr 1 + exact integerCharacter_ringHomComp χ hχ + have hdiv : d.natAbs ∣ n := by + rw [← hDabs] + exact Int.natAbs_dvd_natAbs.mpr ⟨c ^ 2, by rw [hdc, mul_comm]⟩ + have hnsq : ¬ IsSquare (d : ℚ) := by + apply not_isSquare_of_quadratic_adjoin ha + rw [hadjχ] + exact characterField_finrank n K ℂ χ hχ hne + refine ⟨d, a, hd, hDabs ▸ hbound, hdiv, hnsq, ha, hint, hadjχ, ?_⟩ + intro σ + have hact := cyclotomic_gaussSum_action χK hK e σ + rw [hga, map_mul, map_intCast] at hact + apply mul_left_cancel₀ (Int.cast_ne_zero.mpr hc : (c : K) ≠ 0) + change (c : K) * σ a = (χI (galEquivZMod n K σ) : K) * ((c : K) * a) at hact + simpa only [χI, mul_left_comm] using hact + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem galEquivZMod_arithFrob (n : ℕ) [NeZero n] (K : Type*) [Field K] [NumberField K] + [IsCyclotomicExtension {n} ℚ K] {p : ℕ} (hp : p.Prime) (hpn : p.Coprime n) + (P : Ideal (𝓞 K)) (hP : P.under ℤ = Ideal.span {(p : ℤ)}) + (σ : Gal(K/ℚ)) (hσ : IsArithFrobAt ℤ σ P) : + galEquivZMod n K σ = ZMod.unitOfCoprime p hpn := by + have hn : (n : 𝓞 K) ∉ P := by + intro hn + have hn' : (n : ℤ) ∈ P.under ℤ := by simpa [Ideal.under, Ideal.mem_comap] using hn + rw [hP, Ideal.mem_span_singleton] at hn' + exact hp.not_dvd_one (hpn ▸ Nat.dvd_gcd (dvd_refl p) (Int.natCast_dvd_natCast.mp hn')) + have hc : Nat.card (ℤ ⧸ P.under ℤ) = p := by + rw [hP, Nat.card_congr (Int.quotientSpanNatEquivZMod p).toEquiv, Nat.card_zmod] + let ζ := (zeta_spec n ℚ K).toInteger + have hζ : IsPrimitiveRoot ζ n := (zeta_spec n ℚ K).toInteger_isPrimitiveRoot + have he : ζ ^ (galEquivZMod n K σ).val.val = ζ ^ p := by + rw [← galEquivZMod_smul_of_pow_eq n K σ hζ.pow_eq_one] + simpa only [hc, MulSemiringAction.toAlgHom_apply] using hσ.apply_of_pow_eq_one hζ.pow_eq_one hn + have hmod := (hζ.isOfFinOrder (NeZero.ne n)).pow_inj_mod.mp he + rw [← hζ.eq_orderOf] at hmod + apply Units.ext + rw [ZMod.coe_unitOfCoprime, ← ZMod.natCast_zmod_val (galEquivZMod n K σ).val] + exact (ZMod.natCast_eq_natCast_iff' _ _ n).mpr hmod + +theorem arithFrob_map_character_eigenvector (n m : ℕ) [NeZero n] [NeZero m] + (K L : Type*) [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] + [Field L] [NumberField L] [IsCyclotomicExtension {m} ℚ L] + [Algebra K L] [IsScalarTower ℚ K L] (hdiv : n ∣ m) + (χ : DirichletCharacter ℤ n) (a : K) + (ha : ∀ τ : Gal(K/ℚ), τ a = (χ (galEquivZMod n K τ) : K) * a) + {p : ℕ} (hp : p.Prime) (hpm : p.Coprime m) + (P : Ideal (𝓞 L)) (hP : P.under ℤ = Ideal.span {(p : ℤ)}) + (σ : Gal(L/ℚ)) (hσ : IsArithFrobAt ℤ σ P) : + σ (algebraMap K L a) = (χ p : L) * algebraMap K L a := by + let : IsGalois ℚ K := IsCyclotomicExtension.isGalois {n} ℚ K + rw [← AlgEquiv.restrictNormal_commutes, ha, map_mul, map_intCast] + congr 2 + rw [galEquivZMod_restrictNormal_apply m L K hdiv σ, + galEquivZMod_arithFrob m L hp hpm P hP σ hσ] + simp [ZMod.unitsMap_val, ZMod.coe_unitOfCoprime, ZMod.cast_natCast hdiv] + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem exists_squarefree_generator_frobenius_sign (n m : ℕ) [NeZero n] [NeZero m] + (K L : Type*) [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] + [IsAbelianGalois ℚ K] [Field L] [NumberField L] [IsCyclotomicExtension {m} ℚ L] + [Algebra K L] [IsScalarTower ℚ K L] (hdiv : n ∣ m) + (χ : DirichletCharacter ℂ n) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) (hne : χ ≠ 1) : + ∃ (d : ℤ) (a : K), Squarefree d ∧ d.natAbs ≤ n ∧ d.natAbs ∣ n ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : K) ∧ + IsIntegral ℤ a ∧ IntermediateField.adjoin ℚ {a} = characterField n K ℂ χ ∧ + ∀ (p : ℕ), p.Prime → p.Coprime m → + ∀ (P : Ideal (𝓞 L)), P.under ℤ = Ideal.span {(p : ℤ)} → + ∀ (σ : Gal(L/ℚ)), IsArithFrobAt ℤ σ P → χ p = -1 → + σ (algebraMap K L a) = -algebraMap K L a := by + obtain ⟨d, a, hd, hbound, hddiv, hdns, ha, hint, hadj, hact⟩ := + exists_squarefree_characterField_generator (K := K) χ hχ hprim hne + refine ⟨d, a, hd, hbound, hddiv, hdns, ha, hint, hadj, ?_⟩ + intro p hp hpm P hP σ hσ hχp + have hi : integerCharacter χ hχ (p : ZMod n) = -1 := by + apply Int.cast_injective (α := ℂ) + simpa only [Int.cast_neg, Int.cast_one] using + (integerCharacter_cast χ hχ (p : ZMod n)).trans hχp + have he := arithFrob_map_character_eigenvector n m K L hdiv + (integerCharacter χ hχ) a hact hp hpm P hP σ hσ + simpa only [hi, Int.cast_neg, Int.cast_one, neg_one_mul] using he + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension + +noncomputable def cyclotomicDivisorField (n m : ℕ) [NeZero m] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {m} ℚ L] : + IntermediateField ℚ L := + IntermediateField.adjoin ℚ {zeta m ℚ L ^ (m / n)} + +theorem cyclotomicDivisorField_isCyclotomicExtension (n m : ℕ) [NeZero n] [NeZero m] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {m} ℚ L] (hdiv : n ∣ m) : + IsCyclotomicExtension {n} ℚ (cyclotomicDivisorField n m L) := by + have hζ : IsPrimitiveRoot (zeta m ℚ L ^ (m / n)) n := + IsPrimitiveRoot.pow (NeZero.pos m) (zeta_spec m ℚ L) (Nat.div_mul_cancel hdiv).symm + exact hζ.intermediateField_adjoin_isCyclotomicExtension ℚ + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem primitive_eighth_root_difference_sq {K : Type*} [Field K] + {ζ : K} (hζ : IsPrimitiveRoot ζ 8) : (ζ - ζ ^ 3) ^ 2 = 2 := by + have h4 : ζ ^ 4 = -1 := by + apply IsPrimitiveRoot.eq_neg_one_of_two_right + simpa using hζ.pow_div_gcd 4 (by decide : Nat.gcd 8 4 ≠ 0) + linear_combination (ζ ^ 2 - 2) * h4 + +end WeightedTorusJets + +open scoped Pointwise + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/IntegralDeterminantTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/IntegralDeterminantTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..fec6f4b0ebca6fcf7a86192d1e85e12b246099a9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/IntegralDeterminantTransport.lean @@ -0,0 +1,42 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped NumberField +namespace WeightedTorusJets + +theorem integral_determinant_transport + {K L : Type*} [Field K] [Field L] [Algebra ℚ K] [Algebra ℚ L] + (e : K ≃ₐ[ℚ] L) (Δ : 𝓞 K) : + let Δ' := NumberField.RingOfIntegers.mapRingEquiv e.toRingEquiv Δ + (Δ' : L) = e (Δ : K) ∧ + (Δ' ≠ 0 ↔ Δ ≠ 0) ∧ + Algebra.norm ℚ (Δ' : L) = Algebra.norm ℚ (Δ : K) ∧ + Algebra.norm ℤ Δ' = Algebra.norm ℤ Δ ∧ + ∀ p n : ℕ, + ((p : 𝓞 L) ^ n ∣ Δ' ↔ (p : 𝓞 K) ^ n ∣ Δ) ∧ + (Δ' ∈ (Ideal.span {(p : 𝓞 L)}) ^ n ↔ + Δ ∈ (Ideal.span {(p : 𝓞 K)}) ^ n) := by + let eO := NumberField.RingOfIntegers.mapRingEquiv e.toRingEquiv + have hdiv (p n : ℕ) : (p : 𝓞 L) ^ n ∣ eO Δ ↔ (p : 𝓞 K) ^ n ∣ Δ := by + simpa only [map_pow, map_natCast] using + (map_dvd_iff eO (a := (p : 𝓞 K) ^ n) (b := Δ)) + refine ⟨rfl, eO.map_ne_zero_iff, ?_, ?_, ?_⟩ + · exact Algebra.norm_eq_of_algEquiv e (Δ : K) + · exact Algebra.norm_eq_of_algEquiv eO.toIntAlgEquiv Δ + · intro p n + refine ⟨hdiv p n, ?_⟩ + simpa only [Ideal.span_singleton_pow, Ideal.mem_span_singleton] using hdiv p n + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantDerivation.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantDerivation.lean new file mode 100644 index 0000000000000000000000000000000000000000..9fabafb9e4de2bd9b0de156d4eddfa26b04277dc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantDerivation.lean @@ -0,0 +1,371 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.LocalFractionAlgebra + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section + + +namespace WeightedTorusJets.Geometry + +variable {K : Type*} [Field K] + +theorem maximal_mvPolynomial_height {σ : Type*} [Fintype σ] + (p : Ideal (MvPolynomial σ K)) [p.IsMaximal] : p.height = Fintype.card σ := by + let e := (MvPolynomial.renameEquiv K (Fintype.equivFin σ)).toRingEquiv + have := maximal_polynomial_height (Fintype.card σ) (p.map e) + rwa [e.height_map] at this + +end WeightedTorusJets.Geometry + + + + + + + + + + + +namespace WeightedTorusJets.Geometry + +variable {R : Type*} [CommRing R] (I p : Ideal R) [p.IsPrime] + +theorem regular_local_maximal_height [IsRegularLocalRing R] : + (IsLocalRing.maximalIdeal R).height = + (Module.finrank (IsLocalRing.ResidueField R) (IsLocalRing.CotangentSpace R) : ℕ∞) := by + apply WithBot.coe_injective + rw [IsLocalRing.maximalIdeal_height_eq_ringKrullDim] + exact ((IsRegularLocalRing.iff_finrank_cotangentSpace R).mp inferInstance).symm + +variable {K : Type*} [Field K] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K R : Type*} [Field K] [Infinite K] [CommRing R] [Algebra K R] + +theorem exists_mem_submodule_notMem_ideals (V : Submodule K R) + {ι : Type*} [Finite ι] (p : ι → Ideal R) + (hp : ∀ i, ¬ Ideal.span (V : Set R) ≤ p i) : + ∃ x ∈ V, ∀ i, x ∉ p i := by + let q (i : ι) : Submodule K V := + ((p i).restrictScalars K).comap V.subtype + have hq (i : ι) : q i ≠ ⊤ := by + intro hi + apply hp i + rw [Ideal.span_le] + intro x hx + have : (⟨x, hx⟩ : V) ∈ q i := hi ▸ Submodule.mem_top + exact this + obtain ⟨x, hx⟩ := Submodule.exists_forall_notMem_of_forall_ne_top q hq + exact ⟨x, x.property, hx⟩ + +theorem exists_finset_mem_submodule_height [IsNoetherianRing R] + (V : Submodule K R) (r : ℕ) (hr : r ≤ (Ideal.span (V : Set R)).height) : + ∃ s : Finset R, (∀ x ∈ s, x ∈ V) ∧ s.card ≤ r ∧ + r ≤ (Ideal.span (s : Set R)).height := by + classical + induction r with + | zero => exact ⟨∅, by simp, by simp, by simp⟩ + | succ r ih => + obtain ⟨s, hsV, hsc, hsh⟩ := ih ((WithTop.coe_le_coe.mpr r.le_succ).trans hr) + let J : Ideal R := Ideal.span (s : Set R) + let S := {p : Ideal R | p ∈ J.minimalPrimes ∧ p.height = r} + have hS : S.Finite := J.finite_minimalPrimes_of_isNoetherianRing.subset (fun _ h => h.1) + have : Finite S := hS.to_subtype + have hp (p : S) : ¬ Ideal.span (V : Set R) ≤ p.1 := by + intro hVp + have h := hr.trans (Ideal.height_mono hVp) + rw [p.2.2] at h + exact (Nat.not_succ_le_self r) (by exact_mod_cast h) + obtain ⟨x, hxV, hxp⟩ := exists_mem_submodule_notMem_ideals V (fun p : S => p.1) hp + have hspan : Ideal.span ((insert x s : Finset R) : Set R) = J ⊔ Ideal.span {x} := by + rw [Finset.coe_insert, Ideal.span_insert] + exact sup_comm _ _ + refine ⟨insert x s, ?_, (Finset.card_insert_le _ _).trans (Nat.add_le_add_right hsc 1), ?_⟩ + · intro y hy + rcases Finset.mem_insert.mp hy with rfl | hy + · exact hxV + · exact hsV y hy + · rw [hspan, Ideal.height_eq_inf_minimalPrimes] + refine le_iInf₂ fun p hp => ?_ + have : p.IsPrime := hp.isPrime + have hJp : J ≤ p := le_sup_left.trans hp.le + have hle : (r : ℕ∞) ≤ p.height := hsh.trans (Ideal.height_mono hJp) + by_cases htop : p.height = ⊤ + · exact htop ▸ le_top + have : p.FiniteHeight := ⟨Or.inr htop⟩ + have hne : (r : ℕ∞) ≠ p.height := by + intro heq + have hpS : p ∈ S := ⟨Ideal.mem_minimalPrimes_of_height_le hJp (heq.symm.trans_le hsh), + heq.symm⟩ + exact hxp ⟨p, hpS⟩ (hp.le <| Ideal.mem_sup_right <| Ideal.mem_span_singleton_self x) + exact Order.add_one_le_of_lt (lt_of_le_of_ne hle hne) + +theorem exists_parameters_in_submodule [IsNoetherianRing R] [IsLocalRing R] + (V : Submodule K R) (h : ℕ) + (hV : (Ideal.span (V : Set R)).radical = IsLocalRing.maximalIdeal R) + (hdim : (IsLocalRing.maximalIdeal R).height = h) : + ∃ s : Finset R, (∀ x ∈ s, x ∈ V) ∧ s.card = h ∧ + (Ideal.span (s : Set R)).radical = IsLocalRing.maximalIdeal R := by + have hheight : (Ideal.span (V : Set R)).height = h := by + rw [Ideal.height_eq_inf_minimalPrimes, + ← (Ideal.span (V : Set R)).radical_minimalPrimes, hV, + ← Ideal.height_eq_inf_minimalPrimes, hdim] + obtain ⟨s, hsV, hsc, hsh⟩ := exists_finset_mem_submodule_height V h hheight.ge + have hsm : Ideal.span (s : Set R) ≤ IsLocalRing.maximalIdeal R := by + refine (Ideal.span_le.mpr fun x hx => ?_) + rw [← hV] + exact Ideal.le_radical (Ideal.subset_span (hsV x hx)) + have hsproper : Ideal.span (s : Set R) ≠ ⊤ := by + intro ht + exact (IsLocalRing.maximalIdeal.isMaximal R).ne_top (top_le_iff.mp (ht ▸ hsm)) + have hcard : s.card = h := le_antisymm hsc (by + exact_mod_cast hsh.trans (Ideal.height_span_le_card_of_span_ne_top hsproper)) + refine ⟨s, hsV, hcard, le_antisymm ?_ ?_⟩ + · exact (IsLocalRing.maximalIdeal.isMaximal R).isPrime.radical_le_iff.mpr hsm + · rw [← Ideal.sInf_minimalPrimes] + refine le_sInf fun p hp => ?_ + have : p.IsPrime := hp.isPrime + have hpheight : (IsLocalRing.maximalIdeal R).height ≤ p.height := by + rw [hdim] + exact hsh.trans (Ideal.height_mono hp.le) + exact (Ideal.eq_of_le_of_height_le p + (IsLocalRing.le_maximalIdeal hp.isPrime.ne_top) hpheight).ge + +theorem exists_polynomial_parameters [IsNoetherianRing R] [IsLocalRing R] + {σ : Type*} (φ : MvPolynomial σ K →ₐ[K] R) (S : Set (MvPolynomial σ K)) + (d h : ℕ) (hS : ∀ f ∈ S, f.totalDegree ≤ d) + (hI : (Ideal.span (φ '' S)).radical = IsLocalRing.maximalIdeal R) + (hdim : (IsLocalRing.maximalIdeal R).height = h) : + ∃ g : Fin h → MvPolynomial σ K, + (∀ i, g i ∈ Submodule.span K S) ∧ (∀ i, (g i).totalDegree ≤ d) ∧ + Ideal.span (Set.range (φ ∘ g)) ≤ Ideal.span (φ '' S) ∧ + (Ideal.span (Set.range (φ ∘ g))).radical = IsLocalRing.maximalIdeal R := by + let U : Submodule K (MvPolynomial σ K) := Submodule.span K S + let V : Submodule K R := U.map φ.toLinearMap + have hV : (Ideal.span (V : Set R)).radical = IsLocalRing.maximalIdeal R := by + change (Ideal.span ((Submodule.span K S).map φ.toLinearMap : Set R)).radical = _ + rw [Submodule.map_span] + change Ideal.radical (Submodule.span R (Submodule.span K (φ '' S) : Set R)) = _ + rw [Submodule.span_span_of_tower] + exact hI + obtain ⟨s, hsV, hsc, hsrad⟩ := exists_parameters_in_submodule V h hV hdim + have hlift (x : s) : ∃ f ∈ U, φ f = (x : R) := Submodule.mem_map.mp (hsV x x.property) + choose f hfU hf using hlift + let e : s ≃ Fin h := Finset.equivFinOfCardEq hsc + let g (i : Fin h) := f (e.symm i) + have hg (i : Fin h) : g i ∈ U := hfU (e.symm i) + have hgr : Set.range (φ ∘ g) = (s : Set R) := by + ext x + constructor + · rintro ⟨i, rfl⟩ + simpa only [Function.comp_apply, g, hf, Finset.mem_coe] using (e.symm i).property + · intro hx + refine ⟨e ⟨x, hx⟩, ?_⟩ + simpa only [Function.comp_apply, g, e.symm_apply_apply] using hf ⟨x, hx⟩ + refine ⟨g, hg, ?_, ?_, ?_⟩ + · intro i + apply (MvPolynomial.mem_restrictTotalDegree σ d (g i)).mp + exact (Submodule.span_le.mpr fun f hf => + (MvPolynomial.mem_restrictTotalDegree σ d f).mpr (hS f hf)) (hg i) + · apply Ideal.span_le.mpr + rintro x ⟨i, rfl⟩ + exact Submodule.span_subset_span K R _ + (Submodule.apply_mem_span_image_of_mem_span φ.toLinearMap (hg i)) + · rw [hgr] + exact hsrad + +end WeightedTorusJets.Geometry + + +namespace WeightedTorusJets.Geometry + +theorem polynomial_parameters_at_generic_point {K σ A : Type*} + [Field K] [Infinite K] [Finite σ] [CommRing A] [IsLocalRing A] + [Algebra K A] [Algebra (MvPolynomial σ K) A] [IsScalarTower K (MvPolynomial σ K) A] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] [IsLocalization.AtPrime A p] + (S : Set (MvPolynomial σ K)) (hp : p ∈ (Ideal.span S).minimalPrimes) + (d : ℕ) (hS : ∀ f ∈ S, f.totalDegree ≤ d) : + ∃ g : Fin (Module.finrank (IsLocalRing.ResidueField A) (IsLocalRing.CotangentSpace A)) → + MvPolynomial σ K, + (∀ i, g i ∈ Submodule.span K S) ∧ (∀ i, (g i).totalDegree ≤ d) ∧ + Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i))) ≤ + (Ideal.span S).map (algebraMap (MvPolynomial σ K) A) ∧ + (Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i)))).radical = + IsLocalRing.maximalIdeal A := by + have : IsRegularLocalRing A := IsRegularLocalRing.of_ringEquiv + (IsLocalization.algEquiv p.primeCompl (Localization.AtPrime p) A).toRingEquiv + let φ : MvPolynomial σ K →ₐ[K] A := IsScalarTower.toAlgHom K (MvPolynomial σ K) A + have hrad : (Ideal.span (φ '' S)).radical = IsLocalRing.maximalIdeal A := by + change (Ideal.span ((algebraMap (MvPolynomial σ K) A) '' S)).radical = _ + rw [← Ideal.map_span, + IsLocalization.AtPrime.radical_map_of_mem_minimalPrimes A p (Ideal.span S) hp, + IsLocalization.AtPrime.map_eq_maximalIdeal] + obtain ⟨g, hg, hdeg, hle, hrad⟩ := exists_polynomial_parameters φ S d _ hS hrad + (regular_local_maximal_height (R := A)) + refine ⟨g, hg, hdeg, ?_, hrad⟩ + rw [Ideal.map_span] + exact hle + + + +theorem polynomial_parameters_at_localized_generic_point {K σ A : Type*} + [Field K] [Infinite K] [Finite σ] [CommRing A] [IsLocalRing A] + [Algebra K A] [Algebra (MvPolynomial σ K) A] [IsScalarTower K (MvPolynomial σ K) A] + (M : Submonoid (MvPolynomial σ K)) [Algebra (Localization M) A] + [IsScalarTower (MvPolynomial σ K) (Localization M) A] + (p : Ideal (Localization M)) [p.IsPrime] [IsLocalization.AtPrime A p] + (S : Set (MvPolynomial σ K)) + (hp : p ∈ ((Ideal.span S).map (algebraMap (MvPolynomial σ K) (Localization M))).minimalPrimes) + (d : ℕ) (hS : ∀ f ∈ S, f.totalDegree ≤ d) : + ∃ g : Fin (Module.finrank (IsLocalRing.ResidueField A) (IsLocalRing.CotangentSpace A)) → + MvPolynomial σ K, + (∀ i, g i ∈ Submodule.span K S) ∧ (∀ i, (g i).totalDegree ≤ d) ∧ + Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i))) ≤ + (Ideal.span S).map (algebraMap (MvPolynomial σ K) A) ∧ + (Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i)))).radical = + IsLocalRing.maximalIdeal A := by + have : IsLocalization.AtPrime A (p.comap (algebraMap (MvPolynomial σ K) (Localization M))) := + IsLocalization.isLocalization_isLocalization_atPrime_isLocalization M A p + rw [IsLocalization.minimalPrimes_map M (Localization M) (Ideal.span S)] at hp + exact polynomial_parameters_at_generic_point + (p.comap (algebraMap (MvPolynomial σ K) (Localization M))) S hp d hS + + + +theorem quotient_length_antitone {R : Type*} [CommRing R] + {I J : Ideal R} (hIJ : I ≤ J) : + Module.length R (R ⧸ J) ≤ Module.length R (R ⧸ I) := by + exact Module.length_le_of_surjective (Ideal.Quotient.factorₐ R hIJ).toLinearMap + (Ideal.Quotient.factor_surjective hIJ) + +theorem local_quotient_artinian_of_radical {R : Type*} [CommRing R] + [IsNoetherianRing R] [IsLocalRing R] (J : Ideal R) + (hJ : J.radical = IsLocalRing.maximalIdeal R) : IsArtinianRing (R ⧸ J) := by + apply IsLocalRing.quotient_artinian_of_mem_minimalPrimes_of_isLocalRing + rw [← J.radical_minimalPrimes, hJ, Ideal.minimalPrimes_eq_subsingleton_self] + exact Set.mem_singleton _ + +theorem local_quotient_length_ne_top_of_radical {R : Type*} [CommRing R] + [IsNoetherianRing R] [IsLocalRing R] (J : Ideal R) + (hJ : J.radical = IsLocalRing.maximalIdeal R) : + Module.length R (R ⧸ J) ≠ ⊤ := by + have := local_quotient_artinian_of_radical J hJ + have : IsArtinian R (R ⧸ J) := + isArtinian_of_surjective_algebraMap (R := R ⧸ J) Ideal.Quotient.mk_surjective + exact Module.length_ne_top + + + +theorem polynomial_parameters_with_finite_length {K σ A : Type*} + [Field K] [Infinite K] [Finite σ] [CommRing A] [IsLocalRing A] + [Algebra K A] [Algebra (MvPolynomial σ K) A] [IsScalarTower K (MvPolynomial σ K) A] + (M : Submonoid (MvPolynomial σ K)) [Algebra (Localization M) A] + [IsScalarTower (MvPolynomial σ K) (Localization M) A] + (p : Ideal (Localization M)) [p.IsPrime] [IsLocalization.AtPrime A p] + (S : Set (MvPolynomial σ K)) + (hp : p ∈ ((Ideal.span S).map (algebraMap (MvPolynomial σ K) (Localization M))).minimalPrimes) + (d : ℕ) (hS : ∀ f ∈ S, f.totalDegree ≤ d) : + ∃ g : Fin (Module.finrank (IsLocalRing.ResidueField A) (IsLocalRing.CotangentSpace A)) → + MvPolynomial σ K, + (∀ i, g i ∈ Submodule.span K S) ∧ (∀ i, (g i).totalDegree ≤ d) ∧ + Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i))) ≤ + (Ideal.span S).map (algebraMap (MvPolynomial σ K) A) ∧ + (Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i)))).radical = + IsLocalRing.maximalIdeal A ∧ + Module.length A (A ⧸ (Ideal.span S).map (algebraMap (MvPolynomial σ K) A)) ≤ + Module.length A (A ⧸ Ideal.span + (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i)))) ∧ + Module.length A (A ⧸ Ideal.span + (Set.range (fun i => algebraMap (MvPolynomial σ K) A (g i)))) ≠ ⊤ := by + have : IsNoetherianRing A := IsLocalization.isNoetherianRing p.primeCompl A inferInstance + obtain ⟨g, hg, hd, hle, hrad⟩ := + polynomial_parameters_at_localized_generic_point (A := A) M p S hp d hS + exact ⟨g, hg, hd, hle, hrad, quotient_length_antitone hle, + local_quotient_length_ne_top_of_radical _ hrad⟩ + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +variable {R ι : Type*} [CommSemiring R] [Fintype ι] + +noncomputable def invariantDerivation (c : ι → R) : + Derivation R (MvPolynomial ι R) (MvPolynomial ι R) := + ∑ i, c i • ((MvPolynomial.X i : MvPolynomial ι R) • MvPolynomial.pderiv i) + +theorem invariantDerivation_monomial (c : ι → R) (m : ι →₀ ℕ) (r : R) : + invariantDerivation c (MvPolynomial.monomial m r) = + (∑ i, c i * (m i : R)) • MvPolynomial.monomial m r := by + simp only [invariantDerivation, sum_apply, Derivation.smul_apply, smul_eq_mul, + MvPolynomial.X_mul_pderiv_monomial, ← Nat.cast_smul_eq_nsmul R, smul_smul, + Finset.sum_smul] + +theorem coeff_invariantDerivation (c : ι → R) (f : MvPolynomial ι R) (m : ι →₀ ℕ) : + (invariantDerivation c f).coeff m = (∑ i, c i * (m i : R)) * f.coeff m := by + classical + induction f using MvPolynomial.induction_on' with + | monomial n r => + simp only [invariantDerivation_monomial, MvPolynomial.coeff_smul, smul_eq_mul, + MvPolynomial.coeff_monomial] + split_ifs with h + · subst n + rfl + · simp + | add f g hf hg => + simp only [map_add, AddMonoidAlgebra.coeff_add, Finsupp.add_apply, hf, hg, mul_add] + +noncomputable def invariantJet (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) + (f : MvPolynomial ι R) : MvPolynomial ι R := + (invariantDerivation (c 0))^[a 0] + ((invariantDerivation (c 1))^[a 1] + ((invariantDerivation (c 2))^[a 2] f)) + +theorem coeff_iterate_invariantDerivation (c : ι → R) (f : MvPolynomial ι R) + (m : ι →₀ ℕ) (k : ℕ) : + ((invariantDerivation c)^[k] f).coeff m = + (∑ i, c i * (m i : R)) ^ k * f.coeff m := by + induction k with + | zero => simp + | succ k hk => + rw [Function.iterate_succ_apply', coeff_invariantDerivation, hk, pow_succ'] + exact (mul_assoc _ _ _).symm + +theorem coeff_invariantJet (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) + (f : MvPolynomial ι R) (m : ι →₀ ℕ) : + (invariantJet c a f).coeff m = + ((∑ i, c 0 i * (m i : R)) ^ a 0 * + (∑ i, c 1 i * (m i : R)) ^ a 1 * + (∑ i, c 2 i * (m i : R)) ^ a 2) * f.coeff m := by + simp only [invariantJet, coeff_iterate_invariantDerivation, mul_assoc] + +theorem support_invariantJet_subset (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) + (f : MvPolynomial ι R) : (invariantJet c a f).support ⊆ f.support := by + intro m hm + rw [MvPolynomial.mem_support_iff, coeff_invariantJet] at hm + exact MvPolynomial.mem_support_iff.mpr (fun h ↦ hm (by rw [h, mul_zero])) + +theorem totalDegree_invariantJet_le (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) + (f : MvPolynomial ι R) : (invariantJet c a f).totalDegree ≤ f.totalDegree := + MvPolynomial.totalDegree_le_of_support_subset (support_invariantJet_subset c a f) + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantJetLinearMap.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantJetLinearMap.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee5270543ad08d0a3b8089164471e63da3c88f28 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantJetLinearMap.lean @@ -0,0 +1,528 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.EvalOneInvariantJetMonomial +import OAI.NumberTheory.Jacobsthal.Siegel.TorusQuotientDimensionPosCotangentFinrankThree +import OAI.NumberTheory.Jacobsthal.Siegel.WeightedJetIndices + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +variable {R ι : Type*} [CommSemiring R] [Fintype ι] + +theorem invariantJet_add_multiindex (c : Fin 3 → ι → R) (a b : Fin 3 → ℕ) + (f : MvPolynomial ι R) : invariantJet c (a + b) f = invariantJet c a (invariantJet c b f) := by + ext m + simp only [coeff_invariantJet, Pi.add_apply, pow_add] + ring + +noncomputable def invariantJetLinearMap (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) : + Module.End R (MvPolynomial ι R) where + toFun := invariantJet c a + map_add' f g := by + ext m + simp only [coeff_invariantJet, AddMonoidAlgebra.coeff_add, Finsupp.add_apply, mul_add] + map_smul' r f := by + ext m + simp only [coeff_invariantJet, MvPolynomial.coeff_smul, smul_eq_mul, RingHom.id_apply] + ring + +theorem invariantJet_mem_span_monomials {κ : Type*} (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) + (m : κ → ι →₀ ℕ) {f : MvPolynomial ι R} + (hf : f ∈ Submodule.span R (Set.range fun k => MvPolynomial.monomial (m k) (1 : R))) : + invariantJet c a f ∈ + Submodule.span R (Set.range fun k => MvPolynomial.monomial (m k) (1 : R)) := by + change invariantJetLinearMap c a f ∈ _ + induction hf using Submodule.span_induction with + | mem f hf => + obtain ⟨k, rfl⟩ := hf + change invariantJet c a (MvPolynomial.monomial (m k) 1) ∈ _ + rw [invariantJet_monomial] + exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨k, rfl⟩) + | zero => + rw [map_zero] + exact Submodule.zero_mem _ + | add f g _ _ hf hg => simpa only [map_add] using Submodule.add_mem _ hf hg + | smul r f _ hf => simpa only [map_smul] using Submodule.smul_mem _ r hf + +theorem invariantJet_map {S : Type*} [CommSemiring S] (φ : R →+* S) + (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) (f : MvPolynomial ι R) : + invariantJet (fun j i => φ (c j i)) a (MvPolynomial.map φ f) = + MvPolynomial.map φ (invariantJet c a f) := by + ext m + simp [coeff_invariantJet, MvPolynomial.coeff_map, map_sum] + +theorem eval_one_invariantJet_sum_monomials {κ : Type*} [Fintype κ] + (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) (m : κ → ι →₀ ℕ) (w : κ → R) : + MvPolynomial.eval (fun _ => 1) + (invariantJet c a (∑ k, MvPolynomial.monomial (m k) (w k))) = + ∑ k, + ((∑ i, c 0 i * (m k i : R)) ^ a 0 * + (∑ i, c 1 i * (m k i : R)) ^ a 1 * + (∑ i, c 2 i * (m k i : R)) ^ a 2) * w k := by + change MvPolynomial.eval (fun _ => 1) + (invariantJetLinearMap c a (∑ k, MvPolynomial.monomial (m k) (w k))) = _ + simp only [map_sum] + apply Finset.sum_congr rfl + intro k _ + exact eval_one_invariantJet_monomial c a (m k) (w k) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K ι κ : Type*} [Field K] [Fintype ι] [Fintype κ] + +theorem detects_jet_rows_of_polynomial_detection + (c : Fin 3 → ι → K) (m : κ → ι →₀ ℕ) (hm : Function.Injective m) + (s : Finset (Fin 3 → ℕ)) + (hzero : ∀ f : MvPolynomial ι K, + f ∈ Submodule.span K (Set.range fun k => MvPolynomial.monomial (m k) (1 : K)) → + (∀ a ∈ s, MvPolynomial.eval (fun _ => 1) (invariantJet c a f) = 0) → f = 0) : + ∀ w : κ → K, w ≠ 0 → ∃ a ∈ s, + ∑ k, ((∑ i, c 0 i * (m k i : K)) ^ a 0 * + (∑ i, c 1 i * (m k i : K)) ^ a 1 * + (∑ i, c 2 i * (m k i : K)) ^ a 2) * w k ≠ 0 := by + classical + intro w hw + by_contra! h + have hmem : (∑ k, MvPolynomial.monomial (m k) (w k)) ∈ + Submodule.span K (Set.range fun k => MvPolynomial.monomial (m k) (1 : K)) := by + apply Submodule.sum_mem + intro k _ + have hmono := Submodule.smul_mem + (Submodule.span K (Set.range fun k => MvPolynomial.monomial (m k) (1 : K))) + (w k) (Submodule.subset_span ⟨k, rfl⟩) + simpa only [MvPolynomial.smul_monomial, smul_eq_mul, mul_one] using hmono + have hF := hzero _ hmem (fun a ha => by + rw [eval_one_invariantJet_sum_monomials] + exact h a ha) + have hlin : LinearIndependent K (fun k => MvPolynomial.monomial (m k) (1 : K)) := + (MvPolynomial.basisMonomials ι K).linearIndependent.comp m hm + apply hw + funext k + apply Fintype.linearIndependent_iff.mp hlin w _ k + simpa only [MvPolynomial.smul_monomial, smul_eq_mul, mul_one] using hF + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +variable {K L ι κ : Type*} [Field K] [Field L] [Fintype ι] [Fintype κ] + +theorem span_jet_rows_eq_top_of_polynomial_detection + (c : Fin 3 → ι → K) (m : κ → ι →₀ ℕ) (hm : Function.Injective m) + (s : Finset (Fin 3 → ℕ)) + (hzero : ∀ f : MvPolynomial ι K, + f ∈ Submodule.span K (Set.range fun k => MvPolynomial.monomial (m k) (1 : K)) → + (∀ a ∈ s, MvPolynomial.eval (fun _ => 1) (invariantJet c a f) = 0) → f = 0) : + Submodule.span K ((fun a : Fin 3 → ℕ => fun k => + (∑ i, c 0 i * (m k i : K)) ^ a 0 * + (∑ i, c 1 i * (m k i : K)) ^ a 1 * + (∑ i, c 2 i * (m k i : K)) ^ a 2) '' (s : Set (Fin 3 → ℕ))) = ⊤ := + WeightedTorusJets.span_rows_eq_top_of_detects s _ + (detects_jet_rows_of_polynomial_detection c m hm s hzero) + +theorem span_jet_rows_eq_top_of_polynomial_detection_over + (φ : K →+* L) (c : Fin 3 → ι → K) + (m : κ → ι →₀ ℕ) (hm : Function.Injective m) (s : Finset (Fin 3 → ℕ)) + (hzero : ∀ f : MvPolynomial ι L, + f ∈ Submodule.span L (Set.range fun k => MvPolynomial.monomial (m k) (1 : L)) → + (∀ a ∈ s, MvPolynomial.eval (fun _ => 1) + (invariantJet (fun j i => φ (c j i)) a f) = 0) → f = 0) : + Submodule.span K ((fun a : Fin 3 → ℕ => fun k => + (∑ i, c 0 i * (m k i : K)) ^ a 0 * + (∑ i, c 1 i * (m k i : K)) ^ a 1 * + (∑ i, c 2 i * (m k i : K)) ^ a 2) '' (s : Set (Fin 3 → ℕ))) = ⊤ := by + apply WeightedTorusJets.span_rows_eq_top_of_detects + apply WeightedTorusJets.detects_of_field_embedding _ _ φ + intro w hw + obtain ⟨a, ha, hsum⟩ := detects_jet_rows_of_polynomial_detection + (fun j i => φ (c j i)) m hm s hzero w hw + refine ⟨a, ha, ?_⟩ + simpa only [map_mul, map_pow, map_sum, map_natCast] using hsum + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry +theorem detects_jet_rows_of_polynomial_detection_set + {K ι κ : Type*} [Field K] [Fintype ι] [Fintype κ] + (c : Fin 3 → ι → K) (m : κ → ι →₀ ℕ) (hm : Function.Injective m) + (s : Set (Fin 3 → ℕ)) + (hzero : ∀ f : MvPolynomial ι K, + f ∈ Submodule.span K (Set.range fun k => MvPolynomial.monomial (m k) (1 : K)) → + (∀ a ∈ s, MvPolynomial.eval (fun _ => 1) (invariantJet c a f) = 0) → f = 0) : + ∀ w : κ → K, w ≠ 0 → ∃ a ∈ s, + ∑ k, ((∑ i, c 0 i * (m k i : K)) ^ a 0 * + (∑ i, c 1 i * (m k i : K)) ^ a 1 * + (∑ i, c 2 i * (m k i : K)) ^ a 2) * w k ≠ 0 := by + classical + intro w hw + by_contra! h + have hmem : (∑ k, MvPolynomial.monomial (m k) (w k)) ∈ + Submodule.span K (Set.range fun k => MvPolynomial.monomial (m k) (1 : K)) := by + apply Submodule.sum_mem + intro k _ + have hmono := Submodule.smul_mem + (Submodule.span K (Set.range fun k => MvPolynomial.monomial (m k) (1 : K))) + (w k) (Submodule.subset_span ⟨k, rfl⟩) + simpa only [MvPolynomial.smul_monomial, smul_eq_mul, mul_one] using hmono + have hF := hzero _ hmem (fun a ha => by + rw [eval_one_invariantJet_sum_monomials] + exact h a ha) + have hlin : LinearIndependent K (fun k => MvPolynomial.monomial (m k) (1 : K)) := + (MvPolynomial.basisMonomials ι K).linearIndependent.comp m hm + apply hw + funext k + apply Fintype.linearIndependent_iff.mp hlin w _ k + simpa only [MvPolynomial.smul_monomial, smul_eq_mul, mul_one] using hF + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets +theorem span_rows_eq_top_of_detects_set + {K ι n : Type*} [Field K] [Fintype n] + (s : Set ι) (R : ι → n → K) + (hdetect : ∀ c : n → K, c ≠ 0 → ∃ a ∈ s, ∑ j, R a j * c j ≠ 0) : + Submodule.span K (R '' s) = ⊤ := by + classical + apply (Submodule.map_eq_top_iff (e := dotProductEquiv K n)).mp + rw [Submodule.map_span] + apply Submodule.span_eq_top_of_ne_zero + intro c hc + obtain ⟨a, ha, hsum⟩ := hdetect c hc + exact ⟨dotProductEquiv K n (R a), + Set.mem_image_of_mem _ (Set.mem_image_of_mem R ha), hsum⟩ + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +variable {K L ι κ : Type*} [Field K] [Field L] [Fintype ι] [Fintype κ] + +theorem span_jet_rows_eq_top_of_polynomial_detection_set_over + (φ : K →+* L) (c : Fin 3 → ι → K) + (m : κ → ι →₀ ℕ) (hm : Function.Injective m) (s : Set (Fin 3 → ℕ)) + (hzero : ∀ f : MvPolynomial ι L, + f ∈ Submodule.span L (Set.range fun k => MvPolynomial.monomial (m k) (1 : L)) → + (∀ a ∈ s, MvPolynomial.eval (fun _ => 1) + (invariantJet (fun j i => φ (c j i)) a f) = 0) → f = 0) : + Submodule.span K ((fun a : Fin 3 → ℕ => fun k => + (∑ i, c 0 i * (m k i : K)) ^ a 0 * + (∑ i, c 1 i * (m k i : K)) ^ a 1 * + (∑ i, c 2 i * (m k i : K)) ^ a 2) '' s) = ⊤ := by + apply WeightedTorusJets.span_rows_eq_top_of_detects_set + intro w hw + have hfw : (fun k => φ (w k)) ≠ 0 := by + intro h + apply hw + funext k + exact φ.injective (by simpa only [Pi.zero_apply, map_zero] using congr_fun h k) + obtain ⟨a, ha, hsum⟩ := detects_jet_rows_of_polynomial_detection_set + (fun j i => φ (c j i)) m hm s hzero (fun k => φ (w k)) hfw + refine ⟨a, ha, fun h => hsum ?_⟩ + simpa only [map_sum, map_mul, map_pow, map_natCast, map_zero] using congr_arg φ h + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem source_eigenvalue_row_eq_galois_row {K : Type*} [Field K] + (u : Fin 4 → K) (σ τ : K →+* K) (n : Fin 4 → ℕ) (a : Fin 3 → ℕ) : + (∑ i, ![u, (fun i => σ (u i)), (fun i => (σ.comp τ) (u i))] 0 i * (n i : K)) ^ a 0 * + (∑ i, ![u, (fun i => σ (u i)), (fun i => (σ.comp τ) (u i))] 1 i * (n i : K)) ^ a 1 * + (∑ i, ![u, (fun i => σ (u i)), (fun i => (σ.comp τ) (u i))] 2 i * (n i : K)) ^ a 2 = + (∑ i, (n i : K) * u i) ^ a 0 * + σ (∑ i, (n i : K) * u i) ^ a 1 * + (σ.comp τ) (∑ i, (n i : K) * u i) ^ a 2 := by + simp [map_sum, mul_comm] + +theorem source_rectangle_span_of_polynomial_zero_test + {K κ : Type*} [Field K] [Fintype κ] + (φ : K →+* ℂ) (u : Fin 4 → K) (σ τ : K →+* K) + (H N : ℕ) (n : κ → Fin 4 → ℕ) (hninj : Function.Injective n) + (hn : ∀ j i, n j i < N) + (hzero : ∀ F : MvPolynomial (Fin 4) ℂ, F ∈ polynomialBox ℂ N → + (∀ a : Fin 3 → ℕ, + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) → + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) → + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) → + MvPolynomial.eval (fun _ => 1) + (invariantJet (fun j i => φ (![u, (fun i => σ (u i)), + (fun i => (σ.comp τ) (u i))] j i)) a F) = 0) → F = 0) : + let θ := fun j => ∑ i : Fin 4, (n j i : K) * u i + Submodule.span K + ((fun a : Fin 3 → ℕ => fun j => θ j ^ a 0 * σ (θ j) ^ a 1 * + (σ.comp τ) (θ j) ^ a 2) '' {a : Fin 3 → ℕ | + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)}) = ⊤ := by + let m : κ → Fin 4 →₀ ℕ := fun j => Finsupp.equivFunOnFinite.symm (n j) + let c : Fin 3 → Fin 4 → K := ![u, (fun i => σ (u i)), (fun i => (σ.comp τ) (u i))] + have hm : Function.Injective m := by + intro i j h + apply hninj + funext k + exact congrArg (fun d : Fin 4 →₀ ℕ => d k) h + have hmem : Submodule.span ℂ + (Set.range fun j => MvPolynomial.monomial (m j) (1 : ℂ)) ≤ polynomialBox ℂ N := by + apply Submodule.span_le.mpr + rintro _ ⟨j, rfl⟩ + exact Submodule.subset_span ⟨fun i => (⟨n j i, hn j i⟩ : Fin N), rfl⟩ + have hs := span_jet_rows_eq_top_of_polynomial_detection_set_over φ c m hm + {a : Fin 3 → ℕ | + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)} + (fun F hF hvan => hzero F (hmem hF) (fun a h0 h1 h2 => hvan a ⟨h0, h1, h2⟩)) + simpa only [m, c, Finsupp.coe_equivFunOnFinite_symm, + source_eigenvalue_row_eq_galois_row] using hs + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +theorem source_weighted_cutoff_span_of_polynomial_zero_test + {K κ : Type*} [Field K] [Fintype κ] + (φ : K →+* ℂ) (u : Fin 4 → K) (σ τ : K →+* K) + (H N : ℕ) (hH : 0 < H) (n : κ → Fin 4 → ℕ) (hninj : Function.Injective n) + (hn : ∀ j i, n j i < N) + (hzero : ∀ F : MvPolynomial (Fin 4) ℂ, F ∈ polynomialBox ℂ N → + (∀ a : Fin 3 → ℕ, + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) → + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) → + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) → + MvPolynomial.eval (fun _ => 1) + (invariantJet (fun j i => φ (![u, (fun i => σ (u i)), + (fun i => (σ.comp τ) (u i))] j i)) a F) = 0) → F = 0) : + let θ := fun j => ∑ i : Fin 4, (n j i : K) * u i + Submodule.span K + ((fun a : Fin 3 → ℕ => fun j => θ j ^ a 0 * σ (θ j) ^ a 1 * + (σ.comp τ) (θ j) ^ a 2) '' + (WeightedTorusJets.weightedJetIndices H + ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)⌋₊ : Set (Fin 3 → ℕ))) = ⊤ := by + exact WeightedTorusJets.span_cutoff_eq_top_of_rectangle hH _ + (source_rectangle_span_of_polynomial_zero_test φ u σ τ H N n hninj hn hzero) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +variable {K : Type*} [Field K] + +def biquadraticDirections (a b : K) : Fin 3 → Fin 4 → K := + ![![1, a, b, a * b], ![1, -a, b, -(a * b)], ![1, -a, -b, a * b]] + +def biquadraticCoefficients (a b : K) : Fin 4 → K := + ![1, a⁻¹, -b⁻¹, -(a * b)⁻¹] + +def biquadraticForm (a b : K) : (Fin 4 → K) →ₗ[K] K := + dotProductBilin K K (biquadraticCoefficients a b) + +theorem biquadraticForm_apply (a b : K) (v : Fin 4 → K) : + biquadraticForm a b v = v 0 + a⁻¹ * v 1 - b⁻¹ * v 2 - (a * b)⁻¹ * v 3 := by + simp [biquadraticForm, biquadraticCoefficients, dotProductBilin, dotProduct, + Fin.sum_univ_succ, sub_eq_add_neg, add_assoc] + +theorem biquadraticForm_ne_zero (a b : K) : biquadraticForm a b ≠ 0 := by + intro h + have h' := LinearMap.congr_fun h (![1, 0, 0, 0] : Fin 4 → K) + simp [biquadraticForm_apply] at h' + +theorem biquadraticForm_direction {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) + (i : Fin 3) : biquadraticForm a b (biquadraticDirections a b i) = 0 := by + fin_cases i <;> simp [biquadraticForm_apply, biquadraticDirections, ha, hb, mul_assoc] + +theorem biquadraticDirections_linearIndependent [CharZero K] {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : + LinearIndependent K (biquadraticDirections a b) := by + rw [Fintype.linearIndependent_iff] + intro c hc i + have h0 := congrFun hc 0 + have h1 := congrFun hc 1 + have h2 := congrFun hc 2 + simp [Fin.sum_univ_succ, biquadraticDirections] at h0 h1 h2 + have hc0 : c 0 = 0 := by + apply (mul_eq_zero.mp (show 2 * a * c 0 = 0 by linear_combination a * h0 + h1)).resolve_left + exact mul_ne_zero two_ne_zero ha + have hc2 : c 2 = 0 := by + apply (mul_eq_zero.mp (show 2 * b * c 2 = 0 by linear_combination b * h0 - h2)).resolve_left + exact mul_ne_zero two_ne_zero hb + have hc1 : c 1 = 0 := by linear_combination h0 - hc0 - hc2 + fin_cases i <;> assumption + +theorem finrank_ker_biquadraticForm (a b : K) : + Module.finrank K (LinearMap.ker (biquadraticForm a b)) = 3 := by + have hs : Function.Surjective (biquadraticForm a b) := fun y => + ⟨![y, 0, 0, 0], by simp [biquadraticForm_apply]⟩ + have h := (biquadraticForm a b).finrank_range_add_finrank_ker + rw [LinearMap.range_eq_top.mpr hs] at h + simp only [finrank_top, Module.finrank_self, + Module.finrank_fintype_fun_eq_card, Fintype.card_fin] at h + exact Nat.add_left_cancel h + +theorem span_biquadraticDirections_eq_ker [CharZero K] {a b : K} + (ha : a ≠ 0) (hb : b ≠ 0) : + Submodule.span K (Set.range (biquadraticDirections a b)) = + LinearMap.ker (biquadraticForm a b) := by + apply Submodule.eq_of_le_of_finrank_eq + · rw [Submodule.span_le] + rintro _ ⟨i, rfl⟩ + exact biquadraticForm_direction ha hb i + · rw [finrank_span_eq_card (biquadraticDirections_linearIndependent ha hb), + finrank_ker_biquadraticForm] + rfl + +theorem biquadraticCoefficients_linearIndependent [Algebra ℚ K] {a b : K} + (h : LinearIndependent ℚ (![1, a, b, a * b] : Fin 4 → K)) : + LinearIndependent ℚ (biquadraticCoefficients a b) := by + have ha : a ≠ 0 := by simpa using h.ne_zero 1 + have hb : b ≠ 0 := by simpa using h.ne_zero 2 + rw [Fintype.linearIndependent_iff] + intro c hc i + have hscaled : ∑ j, (![ -c 3, -c 2, c 1, c 0] : Fin 4 → ℚ) j • + (![1, a, b, a * b] : Fin 4 → K) j = 0 := by + simp [Fin.sum_univ_succ, biquadraticCoefficients, Algebra.smul_def] at hc ⊢ + field_simp at hc + linear_combination hc + have hz := Fintype.linearIndependent_iff.mp h _ hscaled + fin_cases i + · simpa using hz 3 + · simpa using hz 2 + · simpa using hz 1 + · simpa using hz 0 + +theorem mul_biquadraticCoefficients {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : + (fun i => (a * b) * biquadraticCoefficients a b i) = + (![a * b, b, -a, -1] : Fin 4 → K) := by + ext i + fin_cases i <;> simp [biquadraticCoefficients, hb] <;> field_simp + +theorem exists_basis_scaled_biquadraticCoefficients [Algebra ℚ K] {a b : K} + (e : Module.Basis (Fin 4) ℚ K) (he : ⇑e = ![1, a, b, a * b]) : + ∃ e' : Module.Basis (Fin 4) ℚ K, ⇑e' = ![a * b, b, -a, -1] := by + refine ⟨(e.reindex Fin.revPerm).unitsSMul ![1, 1, -1, -1], ?_⟩ + ext i + fin_cases i <;> simp [Module.Basis.unitsSMul_apply, Module.Basis.reindex_apply, he, + Fin.revPerm] + +theorem map_biquadraticCoefficients {L : Type*} [Field L] (f : K →+* L) (a b : K) : + f ∘ biquadraticCoefficients a b = biquadraticCoefficients (f a) (f b) := by + ext i + fin_cases i <;> simp [biquadraticCoefficients] + +theorem map_biquadraticDirections {L : Type*} [Field L] (f : K →+* L) (a b : K) + (i : Fin 3) : + f ∘ biquadraticDirections a b i = biquadraticDirections (f a) (f b) i := by + ext j + fin_cases i <;> fin_cases j <;> simp [biquadraticDirections] + +theorem biquadraticCoefficients_linearIndependent_map [Algebra ℚ K] + {L : Type*} [Field L] [Algebra ℚ L] (f : K →ₐ[ℚ] L) {a b : K} + (h : LinearIndependent ℚ (![1, a, b, a * b] : Fin 4 → K)) : + LinearIndependent ℚ (biquadraticCoefficients (f a) (f b)) := by + have h' := (biquadraticCoefficients_linearIndependent h).map' f.toLinearMap + (LinearMap.ker_eq_bot.mpr f.injective) + exact (map_biquadraticCoefficients f.toRingHom a b) ▸ h' + +noncomputable def biquadraticDirectionBasis [CharZero K] {a b : K} + (ha : a ≠ 0) (hb : b ≠ 0) : + Module.Basis (Fin 3) K (LinearMap.ker (biquadraticForm a b)) := + (Module.Basis.span (biquadraticDirections_linearIndependent ha hb)).map + (LinearEquiv.ofEq _ _ (span_biquadraticDirections_eq_ker ha hb)) + +theorem coe_biquadraticDirectionBasis [CharZero K] {a b : K} + (ha : a ≠ 0) (hb : b ≠ 0) (i : Fin 3) : + (biquadraticDirectionBasis ha hb i : Fin 4 → K) = biquadraticDirections a b i := by + simp [biquadraticDirectionBasis] + +end WeightedTorusJets + +namespace WeightedTorusJets + + theorem source_same_witness_hyperplane {K : Type*} [Field K] [CharZero K] + (a b : K) (φ : K →+* ℂ) (v : Module.Basis (Fin 4) ℚ K) + (hv : ∀ i, v i = ![1, a, b, a * b] i) (σ τ : K ≃ₐ[ℚ] K) + (hσa : σ a = -a) (hσb : σ b = b) (hτa : τ a = a) (hτb : τ b = -b) : + LinearIndependent ℚ (biquadraticCoefficients (φ a) (φ b)) ∧ + ∃ D : Module.Basis (Fin 3) ℂ (LinearMap.ker (biquadraticForm (φ a) (φ b))), + ∀ j i, (D j : Fin 4 → ℂ) i = + φ ((![![1, a, b, a * b], (fun i => σ (![1, a, b, a * b] i)), + (fun i => (σ * τ) (![1, a, b, a * b] i))] : Fin 3 → Fin 4 → K) j i) := by + have hbase : LinearIndependent ℚ (![1, a, b, a * b] : Fin 4 → K) := + (funext hv) ▸ v.linearIndependent + have ha : a ≠ 0 := by simpa using hbase.ne_zero 1 + have hb : b ≠ 0 := by simpa using hbase.ne_zero 2 + have hφa : φ a ≠ 0 := (map_ne_zero_iff φ φ.injective).mpr ha + have hφb : φ b ≠ 0 := (map_ne_zero_iff φ φ.injective).mpr hb + refine ⟨biquadraticCoefficients_linearIndependent_map φ.toRatAlgHom hbase, + biquadraticDirectionBasis hφa hφb, ?_⟩ + intro j i + rw [coe_biquadraticDirectionBasis] + fin_cases j <;> fin_cases i <;> + simp [biquadraticDirections, AlgEquiv.mul_apply, hσa, hσb, hτa, hτb] + + + +theorem actual_biquadratic_rectangle_span + {K κ : Type*} [Field K] [NumberField K] [Fintype κ] + (a b : K) (v : Module.Basis (Fin 4) ℚ K) + (hv : ∀ i, v i = ![1, a, b, a * b] i) (σ τ : K ≃ₐ[ℚ] K) + (hσa : σ a = -a) (hσb : σ b = b) (hτa : τ a = a) (hτb : τ b = -b) + (H N : ℕ) (hH : 0 < H) (hHN : H ≤ N) + (n : κ → Fin 4 → ℕ) (hninj : Function.Injective n) (hn : ∀ j i, n j i < N) : + let θ := fun j => ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i + Submodule.span K + ((fun α : Fin 3 → ℕ => fun j => θ j ^ α 0 * σ (θ j) ^ α 1 * + (σ * τ) (θ j) ^ α 2) '' {α : Fin 3 → ℕ | + (α 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (α 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (α 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)}) = ⊤ := by + let φ : K →ₐ[ℚ] ℂ := IsAlgClosed.lift + obtain ⟨hc, D, hD⟩ := source_same_witness_hyperplane a b φ.toRingHom v hv σ τ + hσa hσb hτa hτb + have hform : biquadraticForm (φ a) (φ b) = + dotProductEquiv ℂ (Fin 4) (biquadraticCoefficients (φ a) (φ b)) := by + ext x + rfl + let D' := D.map (LinearEquiv.ofEq _ _ (congrArg LinearMap.ker hform)) + apply Geometry.source_rectangle_span_of_polynomial_zero_test φ.toRingHom + ![1, a, b, a * b] σ.toRingHom τ.toRingHom H N n hninj hn + intro F hF hvan + apply Geometry.uniform_rectangular_multiplicity (Nat.succ_le_iff.mpr hH) hHN + (biquadraticCoefficients (φ a) (φ b)) hc D' F hF + intro α hα + have h₀ := hα 0 + have h₁ := hα 1 + have h₂ := hα 2 + simp [Geometry.rectangleThreshold] at h₀ h₁ h₂ + have hdirs : (fun j => (D' j : Fin 4 → ℂ)) = + (fun j i => φ (![![1, a, b, a * b], + (fun i => σ.toRingHom (![1, a, b, a * b] i)), + (fun i => (σ.toRingHom.comp τ.toRingHom) (![1, a, b, a * b] i))] j i)) := by + funext j i + simpa [D'] using hD j i + rw [hdirs] + exact hvan α h₀ (by simpa only [neg_div] using h₁) (by simpa only [neg_div] using h₂) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantJetMonomial.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantJetMonomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..57fdc459bad27e263a662344bb2398941143db1b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/InvariantJetMonomial.lean @@ -0,0 +1,423 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.FinrankDegreePiecePosPrimeVariableNotMem +import OAI.NumberTheory.Jacobsthal.Siegel.TorusDerivationOverRat +import OAI.NumberTheory.Jacobsthal.Siegel.TorusRectangleJetIdealParametersProjectiveDegreeBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section + + + + + + + + + + + + + + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +variable {R ι : Type*} [CommSemiring R] [Fintype ι] + +theorem invariantJet_monomial (c : Fin 3 → ι → R) (a : Fin 3 → ℕ) + (m : ι →₀ ℕ) (r : R) : + invariantJet c a (MvPolynomial.monomial m r) = + ((∑ i, c 0 i * (m i : R)) ^ a 0 * + (∑ i, c 1 i * (m i : R)) ^ a 1 * + (∑ i, c 2 i * (m i : R)) ^ a 2) • MvPolynomial.monomial m r := by + classical + ext n + rw [coeff_invariantJet, MvPolynomial.coeff_smul] + simp only [MvPolynomial.coeff_monomial, smul_eq_mul] + split_ifs with h + · subst n + rfl + · simp + + + + +section ConcreteTorusParameters + +variable {K : Type*} [Field K] [Infinite K] +local notation "P₄" => MvPolynomial (Fin 4) K +local notation "T₄" => Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P₄)) + +end ConcreteTorusParameters + +end WeightedTorusJets.Geometry + + + +noncomputable section +open scoped BigOperators +open MvPolynomial + + + + + + + + +namespace WeightedTorusJets.Geometry + +section RectangleUpper + +universe uSource +variable {K : Type uSource} [Field K] [Infinite K] +local notation "P₄" => MvPolynomial (Fin 4) K +local notation "T₄" => Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P₄)) + +theorem rectangleJetIdeal_length_le + (p : Ideal T₄) [p.IsPrime] (c : Fin 3 → Fin 4 → K) (t : Fin 3 → ℕ) (b : ℕ) + {N : ℕ} (hN : 0 < N) {F : P₄} (hF : F ∈ polynomialBox K N) + (hp : p ∈ (rectangleJetIdeal (fun a => algebraMap P₄ T₄ (invariantJet c a F)) t b).minimalPrimes) : + Module.length (Localization.AtPrime p) (Localization.AtPrime p ⧸ + (rectangleJetIdeal (fun a => algebraMap P₄ T₄ (invariantJet c a F)) t b).map + (algebraMap T₄ (Localization.AtPrime p))) ≤ + ((4 * N) ^ Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime p)) + (IsLocalRing.CotangentSpace (Localization.AtPrime p)) : ℕ∞) := by + obtain ⟨g, _, _, _, hle, hweighted⟩ := + torus_rectangleJetIdeal_exists_parameters_with_projective_degree_bound p c t b hN hF hp + have : (p.comap (algebraMap P₄ T₄)).IsPrime := Ideal.comap_isPrime _ p + have hdegree : (1 : ℕ∞) ≤ (GradedQuotient.projectiveDegree + (coneIdeal (p.comap (algebraMap P₄ T₄))) + (coneIdeal_isHomogeneous (p.comap (algebraMap P₄ T₄))) : ℕ∞) := by + exact_mod_cast (Nat.succ_le_iff.mpr + (GradedQuotient.cone_projectiveDegree_pos (p.comap (algebraMap P₄ T₄)))) + apply hle.trans + exact (le_mul_of_one_le_right' hdegree).trans (by exact_mod_cast hweighted) + +end RectangleUpper + +end WeightedTorusJets.Geometry + +end +end +end +end + + +namespace WeightedTorusJets.Geometry + +open scoped BigOperators + +theorem sum_pi_one {σ M : Type*} [Fintype σ] [DecidableEq σ] [AddCommMonoid M] + (β : σ → Type*) [∀ i, Fintype (β i)] (i : σ) (hcover : ∀ u, u = i) + (g : (∀ u, β u) → M) (h : β i → M) (hg : ∀ α, g α = h (α i)) : + ∑ α, g α = ∑ n, h n := by + let : Unique σ := ⟨⟨i⟩, hcover⟩ + exact Fintype.sum_equiv (Equiv.piUnique β) g h hg + +theorem sum_pi_two {σ M : Type*} [Fintype σ] [DecidableEq σ] [AddCommMonoid M] + (β : σ → Type*) [∀ i, Fintype (β i)] (i j : σ) (hij : i ≠ j) + (hcover : ∀ u, u = i ∨ u = j) + (g : (∀ u, β u) → M) (h : β j → β i → M) (hg : ∀ α, g α = h (α j) (α i)) : + ∑ α, g α = ∑ n, ∑ m, h n m := by + classical + rw [← Fintype.sum_prod_type' h] + apply Fintype.sum_bijective (fun α : ∀ u, β u => (α j, α i)) ?_ g _ hg + constructor + · intro α γ he + funext u + rcases hcover u with rfl | rfl + · exact congrArg Prod.snd he + · exact congrArg Prod.fst he + · rintro ⟨n, m⟩ + refine ⟨fun u => if hu : u = j then hu.symm ▸ n + else ((hcover u).resolve_right hu).symm ▸ m, ?_⟩ + simp [hij] + +theorem sum_pi_three {σ M : Type*} [Fintype σ] [DecidableEq σ] [AddCommMonoid M] + (β : σ → Type*) [∀ i, Fintype (β i)] (i j l : σ) + (hij : i ≠ j) (hil : i ≠ l) (hjl : j ≠ l) + (hcover : ∀ u, u = i ∨ u = j ∨ u = l) + (g : (∀ u, β u) → M) (h : β l → β j → β i → M) + (hg : ∀ α, g α = h (α l) (α j) (α i)) : + ∑ α, g α = ∑ p, ∑ n, ∑ m, h p n m := by + classical + have hsum : (∑ z : β l × β j × β i, h z.1 z.2.1 z.2.2) = + ∑ p, ∑ n, ∑ m, h p n m := by simp only [Fintype.sum_prod_type] + rw [← hsum] + apply Fintype.sum_bijective (fun α : ∀ u, β u => (α l, α j, α i)) ?_ g _ hg + constructor + · intro α γ he + funext u + rcases hcover u with rfl | rfl | rfl + · exact congrArg (fun x => x.2.2) he + · exact congrArg (fun x => x.2.1) he + · exact congrArg Prod.fst he + · rintro ⟨p, n, m⟩ + refine ⟨fun u => if hul : u = l then hul.symm ▸ p + else if huj : u = j then huj.symm ▸ n + else ((hcover u).resolve_right (not_or.mpr ⟨huj, hul⟩)).symm ▸ m, ?_⟩ + simp [hij, hil, hjl] + +variable {A B : Type*} [CommRing A] [Algebra ℚ A] [CommRing B] [Algebra ℚ B] + +theorem rectangularTaylorThree_selected_sum + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i j l : I) (hij : i ≠ j) (hil : i ≠ l) (hjl : j ≠ l) + (hcover : ∀ u : I, u = i ∨ u = j ∨ u = l) (k : I → ℕ) (f : A →+* B) (a : A) : + rectangularTaylorThree I k (D i) (D j) (D l) i j l f a = + ∑ α : (u : I) → Fin (k u), (∏ u : I, ((α u).val.factorial : ℚ))⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun u => (α u).val)) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) + (fun u => (α u).val) 0) a))) := by + classical + rw [rectangularTaylorThree_apply] + simp_rw [Finset.sum_range] + symm + refine sum_pi_three (fun u => Fin (k u)) i j l hij hil hjl hcover _ _ ?_ + intro α + let β : I → ℕ := fun u => (α u).val + have huniv : (Finset.univ : Finset I) = {i, j, l} := by + ext u + simp only [Finset.mem_univ, Finset.mem_insert, Finset.mem_singleton, true_iff] + exact hcover u + have hprod : (∏ u : I, ((β u).factorial : ℚ)) = + ((β i).factorial : ℚ) * ((β j).factorial : ℚ) * ((β l).factorial : ℚ) := by + rw [huniv] + simp [hij, hil, hjl, mul_assoc] + have hexp : Finsupp.equivFunOnFinite.symm β = + Finsupp.single i (β i) + (Finsupp.single j (β j) + Finsupp.single l (β l)) := by + ext u + rcases hcover u with rfl | rfl | rfl <;> + simp [hij, hil, hjl, Ne.symm hij, Ne.symm hil, Ne.symm hjl] + have hjet := derivationJet_selected_three D h01 h02 h12 I i j l hij hil hjl hcover β a + change (∏ u : I, ((β u).factorial : ℚ))⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.monomial + (Finsupp.equivFunOnFinite.symm β) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) β 0) a))) = _ + rw [hprod, hexp, ← hjet] + simp only [mul_inv_rev, mul_assoc, β] + +theorem rectangularTaylorThree_one_selected_sum + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i : I) (hcover : ∀ u : I, u = i) + (k : I → ℕ) (f : A →+* B) (a : A) : + rectangularTaylorThree I k (D i) 0 0 i i i f a = + ∑ α : (u : I) → Fin (k u), (∏ u : I, ((α u).val.factorial : ℚ))⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun u => (α u).val)) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) + (fun u => (α u).val) 0) a))) := by + classical + rw [rectangularTaylorThree_one_apply] + simp_rw [Finset.sum_range] + symm + refine sum_pi_one (fun u => Fin (k u)) i hcover _ _ ?_ + intro α + let β : I → ℕ := fun u => (α u).val + have huniv : (Finset.univ : Finset I) = {i} := by + ext u + simp only [Finset.mem_univ, Finset.mem_singleton, true_iff] + exact hcover u + have hprod : (∏ u : I, ((β u).factorial : ℚ)) = ((β i).factorial : ℚ) := by + rw [huniv, Finset.prod_singleton] + have hexp : Finsupp.equivFunOnFinite.symm β = Finsupp.single i (β i) := by + ext u + rcases hcover u with rfl + simp + have hjet := derivationJet_selected_one D h01 h02 h12 I i hcover β a + change (∏ u : I, ((β u).factorial : ℚ))⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.monomial + (Finsupp.equivFunOnFinite.symm β) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) β 0) a))) = _ + rw [hprod, hexp, ← hjet] + +theorem rectangularTaylorThree_two_selected_sum + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i j : I) (hij : i ≠ j) + (hcover : ∀ u : I, u = i ∨ u = j) (k : I → ℕ) (f : A →+* B) (a : A) : + rectangularTaylorThree I k (D i) (D j) 0 i j j f a = + ∑ α : (u : I) → Fin (k u), (∏ u : I, ((α u).val.factorial : ℚ))⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun u => (α u).val)) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) + (fun u => (α u).val) 0) a))) := by + classical + rw [rectangularTaylorThree_two_apply] + simp_rw [Finset.sum_range] + symm + refine sum_pi_two (fun u => Fin (k u)) i j hij hcover _ _ ?_ + intro α + let β : I → ℕ := fun u => (α u).val + have huniv : (Finset.univ : Finset I) = {i, j} := by + ext u + simp only [Finset.mem_univ, Finset.mem_insert, Finset.mem_singleton, true_iff] + exact hcover u + have hprod : (∏ u : I, ((β u).factorial : ℚ)) = + ((β i).factorial : ℚ) * ((β j).factorial : ℚ) := by + rw [huniv] + simp [hij] + have hexp : Finsupp.equivFunOnFinite.symm β = + Finsupp.single i (β i) + Finsupp.single j (β j) := by + ext u + rcases hcover u with rfl | rfl <;> simp [hij, Ne.symm hij] + have hjet := derivationJet_selected_two D h01 h02 h12 I i j hij hcover β a + change (∏ u : I, ((β u).factorial : ℚ))⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.monomial + (Finsupp.equivFunOnFinite.symm β) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) β 0) a))) = _ + rw [hprod, hexp, ← hjet] + simp only [mul_inv_rev, β] + +theorem exists_selected_taylor_ringHom + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (hI : I.Nonempty) (k : I → ℕ) (f : A →+* B) : + ∃ φ : A →+* (MvPolynomial I B ⧸ rectangularIdeal k), ∀ a, + φ a = ∑ α : (u : I) → Fin (k u), (∏ u : I, ((α u).val.factorial : ℚ))⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun u => (α u).val)) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) + (fun u => (α u).val) 0) a))) := by + classical + have hpos := Finset.card_pos.mpr hI + have hmax : I.card ≤ 3 := by simpa using Finset.card_le_univ I + have hcard : I.card = 1 ∨ I.card = 2 ∨ I.card = 3 := by omega + rcases hcard with hcard | hcard | hcard + · obtain ⟨i, rfl⟩ := Finset.card_eq_one.mp hcard + let ii : ↥({i} : Finset (Fin 3)) := ⟨i, by simp⟩ + refine ⟨rectangularTaylorThree _ k (D i) 0 0 ii ii ii f, fun a => ?_⟩ + exact rectangularTaylorThree_one_selected_sum D h01 h02 h12 {i} ii + (fun j => Subtype.ext (Finset.mem_singleton.mp j.property)) k f a + · obtain ⟨i, j, hij, rfl⟩ := Finset.card_eq_two.mp hcard + let ii : ↥({i, j} : Finset (Fin 3)) := ⟨i, by simp⟩ + let jj : ↥({i, j} : Finset (Fin 3)) := ⟨j, by simp⟩ + refine ⟨rectangularTaylorThree _ k (D i) (D j) 0 ii jj jj f, fun a => ?_⟩ + refine rectangularTaylorThree_two_selected_sum D h01 h02 h12 {i, j} ii jj + (fun h => hij (congrArg Subtype.val h)) ?_ k f a + intro u + rcases Finset.mem_insert.mp u.property with hu | hu + · exact Or.inl (Subtype.ext hu) + · exact Or.inr (Subtype.ext (Finset.mem_singleton.mp hu)) + · obtain ⟨i, j, l, hij, hil, hjl, rfl⟩ := Finset.card_eq_three.mp hcard + let ii : ↥({i, j, l} : Finset (Fin 3)) := ⟨i, by simp⟩ + let jj : ↥({i, j, l} : Finset (Fin 3)) := ⟨j, by simp⟩ + let ll : ↥({i, j, l} : Finset (Fin 3)) := ⟨l, by simp⟩ + refine ⟨rectangularTaylorThree _ k (D i) (D j) (D l) ii jj ll f, fun a => ?_⟩ + refine rectangularTaylorThree_selected_sum D h01 h02 h12 {i, j, l} ii jj ll + (fun h => hij (congrArg Subtype.val h)) + (fun h => hil (congrArg Subtype.val h)) + (fun h => hjl (congrArg Subtype.val h)) ?_ k f a + intro u + have hu : u.val = i ∨ u.val = j ∨ u.val = l := by + simpa only [Finset.mem_insert, Finset.mem_singleton] using u.property + rcases hu with hu | hu | hu + · exact Or.inl (Subtype.ext hu) + · exact Or.inr (Or.inl (Subtype.ext hu)) + · exact Or.inr (Or.inr (Subtype.ext hu)) + +theorem factorial_smul_quotient_monomial {σ K : Type*} [Fintype σ] [Field K] [Algebra ℚ K] + (J : Ideal (MvPolynomial σ K)) (α : σ → ℕ) (c : K) : + (∏ u : σ, ((α u).factorial : ℚ))⁻¹ • + Ideal.Quotient.mk J (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm α) c) = + Ideal.Quotient.mk J (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm α) + (c / ∏ u : σ, ((α u).factorial : K))) := by + let : CharZero K := algebraRat.charZero K + have hs := ratCast_smul_eq ℚ K (∏ u : σ, ((α u).factorial : ℚ))⁻¹ + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm α) c) + simp only [Rat.cast_id] at hs + rw [← map_rat_smul, hs, MvPolynomial.smul_monomial, smul_eq_mul] + simp [div_eq_mul_inv, mul_comm] + +theorem exists_source_taylor_ringHom {K : Type*} [Field K] [Algebra ℚ K] + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (hI : I.Nonempty) (t : Fin 3 → ℕ) (f : A →+* K) : + ∃ φ : A →+* (MvPolynomial I K ⧸ rectangularIdeal (fun u : I => t u + 1)), ∀ a, + φ a = ∑ α : (u : I) → Fin (t u + 1), + Ideal.Quotient.mk (rectangularIdeal (fun u : I => t u + 1)) + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun u => (α u).val)) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) + (fun u => (α u).val) 0) a) / ∏ u : I, ((α u).val.factorial : K))) := by + obtain ⟨φ, hφ⟩ := exists_selected_taylor_ringHom D h01 h02 h12 I hI + (fun u : I => t u + 1) f + refine ⟨φ, fun a => ?_⟩ + rw [hφ] + apply Finset.sum_congr rfl + intro α _ + exact factorial_smul_quotient_monomial _ _ _ + +theorem exists_source_taylor_quotient_ringHom {K : Type*} [Field K] [Algebra ℚ K] + (D : Fin 3 → Derivation ℚ A A) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (hI : I.Nonempty) (t : Fin 3 → ℕ) (b : ℕ) (F : A) + (f : A →+* K) (hnext : derivativeStageIdeal D t (b + 1) F ≤ RingHom.ker f) : + ∃ φ : (A ⧸ derivativeStageIdeal D t b F) →+* + (MvPolynomial I K ⧸ rectangularIdeal (fun u : I => t u + 1)), ∀ a, + φ (Ideal.Quotient.mk (derivativeStageIdeal D t b F) a) = + ∑ α : (u : I) → Fin (t u + 1), + Ideal.Quotient.mk (rectangularIdeal (fun u : I => t u + 1)) + (MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm (fun u => (α u).val)) + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) + (fun u => (α u).val) 0) a) / ∏ u : I, ((α u).val.factorial : K))) := by + classical + obtain ⟨φ, hφ⟩ := exists_source_taylor_ringHom D h01 h02 h12 I hI t f + have hvanish := (derivativeStageIdeal_le_ker_iff D t (b + 1) F f).mp hnext + have hker : derivativeStageIdeal D t b F ≤ RingHom.ker φ := by + apply Ideal.span_le.mpr + rintro _ ⟨β, hβ, rfl⟩ + change φ (derivationJet D β F) = 0 + rw [hφ] + apply Finset.sum_eq_zero + intro α _ + let γ : I → ℕ := fun u => (α u).val + have hbound := selectedIndex_add_stage_bound_lt I γ β t b hβ (fun u => (α u).isLt) + have hjet : derivationJet D (Function.extend (Subtype.val : I → Fin 3) γ 0) + (derivationJet D β F) = + derivationJet D (β + Function.extend (Subtype.val : I → Fin 3) γ 0) F := by + simpa only [derivationJet, Pi.add_apply, Nat.add_comm] using + (mixed_derivation_pow_add D h01 h02 h12 + (Function.extend (Subtype.val : I → Fin 3) γ 0) β F).symm + change Ideal.Quotient.mk _ (MvPolynomial.monomial _ + (f (derivationJet D (Function.extend (Subtype.val : I → Fin 3) γ 0) + (derivationJet D β F)) / _)) = 0 + rw [hjet, hvanish _ hbound] + simp + refine ⟨Ideal.Quotient.lift (derivativeStageIdeal D t b F) φ (fun _ ha => hker ha), ?_⟩ + exact hφ + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/JetRowAutCongr.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/JetRowAutCongr.lean new file mode 100644 index 0000000000000000000000000000000000000000..91a9716156f5fa8e3a2ab519585bf7c402c6c5b3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/JetRowAutCongr.lean @@ -0,0 +1,30 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace WeightedTorusJets + +theorem source_jet_row_autCongr + {K L : Type*} [Field K] [Field L] [Algebra ℚ K] [Algebra ℚ L] + (e : K ≃ₐ[ℚ] L) (σ τ : K ≃ₐ[ℚ] K) (θ : K) (α : Fin 3 → ℕ) : + e (θ ^ α 0 * σ θ ^ α 1 * (σ * τ) θ ^ α 2) = + e θ ^ α 0 * (AlgEquiv.autCongr e σ) (e θ) ^ α 1 * + (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) (e θ) ^ α 2 := by + have he (φ : K ≃ₐ[ℚ] K) (x : K) : (AlgEquiv.autCongr e φ) (e x) = e (φ x) := by + change e (φ (e.symm (e x))) = e (φ x) + rw [e.symm_apply_apply] + simp only [map_mul, map_pow, AlgEquiv.mul_apply, he] + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LaurentEvalOne.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LaurentEvalOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..aba7d29a801a35c3fae3850d2f25b293bca0d446 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LaurentEvalOne.lean @@ -0,0 +1,414 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.PolynomialLaurent +import OAI.NumberTheory.Jacobsthal.Siegel.TorusEvalOne + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace WeightedTorusJets.Geometry + +theorem prime_genericPoint_zeroLocus {R : Type*} [CommRing R] (q : PrimeSpectrum R) : + IsGenericPoint q (PrimeSpectrum.zeroLocus (q.asIdeal : Set R)) := + PrimeSpectrum.closure_singleton q + +theorem zeroLocus_maximal_of_isMinimalPrime {R : Type*} [CommRing R] + (I : Ideal R) (q : PrimeSpectrum R) (hq : I.IsMinimalPrime q.asIdeal) : + Maximal (fun V : Set (PrimeSpectrum R) => IsIrreducible V ∧ + V ⊆ PrimeSpectrum.zeroLocus (I : Set R)) + (PrimeSpectrum.zeroLocus (q.asIdeal : Set R)) := by + refine ⟨⟨(prime_genericPoint_zeroLocus q).isIrreducible, + PrimeSpectrum.zeroLocus_anti_mono_ideal hq.le⟩, ?_⟩ + intro V hV hqV + have hp : (PrimeSpectrum.vanishingIdeal V).IsPrime := + PrimeSpectrum.isIrreducible_iff_vanishingIdeal_isPrime.mp hV.1 + have hIp : I ≤ PrimeSpectrum.vanishingIdeal V := + (PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal V I).mp hV.2 + have hpq : PrimeSpectrum.vanishingIdeal V ≤ q.asIdeal := by + simpa only [PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical, + Ideal.IsPrime.radical] using PrimeSpectrum.vanishingIdeal_anti_mono hqV + exact (PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal V q.asIdeal).mpr + (hq.2 ⟨hp, hIp⟩ hpq) + +theorem isClosed_of_maximal_irreducible_zeroLocus {R : Type*} [CommRing R] + (I : Ideal R) (V : Set (PrimeSpectrum R)) + (hV : Maximal (fun W => IsIrreducible W ∧ + W ⊆ PrimeSpectrum.zeroLocus (I : Set R)) V) : IsClosed V := by + apply isClosed_of_closure_subset + exact hV.2 ⟨hV.1.1.closure, + closure_minimal hV.1.2 (PrimeSpectrum.isClosed_zeroLocus _)⟩ subset_closure + +theorem maximal_component_genericPoint {R : Type*} [CommRing R] + (I : Ideal R) (V : Set (PrimeSpectrum R)) + (hV : Maximal (fun W => IsIrreducible W ∧ + W ⊆ PrimeSpectrum.zeroLocus (I : Set R)) V) : + IsGenericPoint + (⟨PrimeSpectrum.vanishingIdeal V, + PrimeSpectrum.isIrreducible_iff_vanishingIdeal_isPrime.mp hV.1.1⟩ : PrimeSpectrum R) V := by + rw [IsGenericPoint, PrimeSpectrum.closure_singleton, + PrimeSpectrum.zeroLocus_vanishingIdeal_eq_closure] + exact (isClosed_of_maximal_irreducible_zeroLocus I V hV).closure_eq + +theorem shared_minimal_prime_has_generic_component {R : Type*} [CommRing R] + (I J : Ideal R) (q p : PrimeSpectrum R) (hqp : q.asIdeal ≤ p.asIdeal) + (hI : I.IsMinimalPrime q.asIdeal) (hJ : J.IsMinimalPrime q.asIdeal) : + ∃ V : Set (PrimeSpectrum R), p ∈ V ∧ IsGenericPoint q V ∧ + Maximal (fun W => IsIrreducible W ∧ W ⊆ PrimeSpectrum.zeroLocus (I : Set R)) V ∧ + Maximal (fun W => IsIrreducible W ∧ W ⊆ PrimeSpectrum.zeroLocus (J : Set R)) V := + ⟨PrimeSpectrum.zeroLocus (q.asIdeal : Set R), hqp, + prime_genericPoint_zeroLocus q, zeroLocus_maximal_of_isMinimalPrime I q hI, + zeroLocus_maximal_of_isMinimalPrime J q hJ⟩ + + + +theorem zeroLocus_topologicalKrullDim {R : Type*} [CommRing R] (I : Ideal R) : + topologicalKrullDim (PrimeSpectrum.zeroLocus (I : Set R)) = ringKrullDim (R ⧸ I) := by + calc + topologicalKrullDim (PrimeSpectrum.zeroLocus (I : Set R)) = + Order.krullDim (TopologicalSpace.IrreducibleCloseds + (PrimeSpectrum.zeroLocus (I : Set R)))ᵒᵈ := Order.krullDim_orderDual.symm + _ = Order.krullDim (PrimeSpectrum.zeroLocus (I : Set R)) := + (Order.krullDim_eq_of_orderIso (PrimeSpectrum.zeroLocusEquivIrreducibleCloseds + (I : Set R))).symm + _ = ringKrullDim (R ⧸ I) := (ringKrullDim_quotient I).symm + +theorem generic_component_topologicalKrullDim {R : Type*} [CommRing R] + (q : PrimeSpectrum R) (V : Set (PrimeSpectrum R)) (hV : IsGenericPoint q V) : + topologicalKrullDim V = ringKrullDim (R ⧸ q.asIdeal) := by + rw [← hV, PrimeSpectrum.closure_singleton, zeroLocus_topologicalKrullDim] + + + +open _root_.AlgebraicGeometry + +variable {R : Type*} [CommRing R] + +theorem spec_stalk_isLocalRing (p : PrimeSpectrum R) : + IsLocalRing ((Spec.structureSheaf R).presheaf.stalk p) := + (StructureSheaf.stalkIso R p).toRingEquiv.isLocalRing + +attribute [local instance] spec_stalk_isLocalRing + +theorem spec_localization_stalk_regular [IsRegularRing R] + (M : Submonoid R) (p : PrimeSpectrum (Localization M)) : + IsRegularLocalRing ((Spec.structureSheaf (Localization M)).presheaf.stalk p) := + IsRegularLocalRing.of_ringEquiv + ((IsLocalization.localizationLocalizationAtPrimeIsoLocalization M p.asIdeal).toRingEquiv.trans + (StructureSheaf.stalkIso (Localization M) p).toRingEquiv) + +theorem spec_stalk_component_radical (I : Ideal R) (p : PrimeSpectrum R) + (hp : p.asIdeal ∈ I.minimalPrimes) : + (I.map (algebraMap R ((Spec.structureSheaf R).presheaf.stalk p))).radical = + IsLocalRing.maximalIdeal ((Spec.structureSheaf R).presheaf.stalk p) := by + rw [IsLocalization.AtPrime.radical_map_of_mem_minimalPrimes + ((Spec.structureSheaf R).presheaf.stalk p) p.asIdeal I hp, + IsLocalization.AtPrime.map_eq_maximalIdeal] + +theorem spec_stalk_component_primary (I : Ideal R) (p : PrimeSpectrum R) + (hp : p.asIdeal ∈ I.minimalPrimes) : + (I.map (algebraMap R ((Spec.structureSheaf R).presheaf.stalk p))).IsPrimary := by + apply Ideal.isPrimary_of_isMaximal_radical + rw [spec_stalk_component_radical I p hp] + infer_instance + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem torusEvalOne_unique {K : Type*} [CommSemiring K] + (φ : Localization.Away + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) →+* K) + (hC : ∀ c, φ (algebraMap (MvPolynomial (Fin 4) K) _ (MvPolynomial.C c)) = c) + (hX : ∀ i : Fin 4, φ (algebraMap (MvPolynomial (Fin 4) K) _ (MvPolynomial.X i)) = 1) : + φ = torusEvalOne := by + apply IsLocalization.ringHom_ext + (Submonoid.powers (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K))) + apply MvPolynomial.ringHom_ext + · intro c + simpa only [RingHom.comp_apply, torusEvalOne_algebraMap, MvPolynomial.eval_C] using hC c + · intro i + simpa only [RingHom.comp_apply, torusEvalOne_algebraMap, MvPolynomial.eval_X] using hX i + +end WeightedTorusJets.Geometry + +section + +namespace WeightedTorusJets.Geometry + +open scoped BigOperators + +variable (K ι : Type*) [CommRing K] + +local notation "P" => MvPolynomial ι K +local notation "G" => ι →₀ ℤ +local notation "A" => AddMonoidAlgebra K G +local notation "L" => Localization.Away (∏ i : ι, (MvPolynomial.X i : P)) + +variable [Fintype ι] + +@[simp] theorem laurentEquivLocalization_symm_algebraMap (p : P) : + (laurentEquivLocalization K ι).symm (algebraMap P L p) = + polynomialToLaurent K ι p := by + simp [laurentEquivLocalization, localizationToLaurent] + +@[simp] theorem laurentEquivLocalization_polynomial (p : P) : + laurentEquivLocalization K ι (polynomialToLaurent K ι p) = algebraMap P L p := by + rw [← laurentEquivLocalization_symm_algebraMap, AlgEquiv.apply_symm_apply] + +theorem laurentEquivLocalization_inverse_coordinate (i : ι) : + laurentEquivLocalization K ι (AddMonoidAlgebra.single (Finsupp.single i (-1)) 1) = + ((localizedCoordinateUnit K ι i)⁻¹ : Lˣ) := by + simp [laurentEquivLocalization, laurentToLocalization] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable (K ι : Type*) [CommRing K] + +noncomputable def laurentEvalOne : AddMonoidAlgebra K (ι →₀ ℤ) →ₐ[K] K := + AddMonoidAlgebra.lift K K (ι →₀ ℤ) 1 + +@[simp] theorem laurentEvalOne_polynomial (p : MvPolynomial ι K) : + laurentEvalOne K ι (polynomialToLaurent K ι p) = + MvPolynomial.eval (fun _ => 1) p := by + simp [polynomialToLaurent, MvPolynomial.comp_aeval_apply, laurentEvalOne, + MvPolynomial.aeval_eq_eval] + +theorem laurentEvalOne_eq_torusEvalOne + (p : AddMonoidAlgebra K (Fin 4 →₀ ℤ)) : + laurentEvalOne K (Fin 4) p = + torusEvalOne (laurentEquivLocalization K (Fin 4) p) := by + let e := laurentEquivLocalization K (Fin 4) + have h : (laurentEvalOne K (Fin 4)).toRingHom.comp e.symm.toRingHom = torusEvalOne := by + apply torusEvalOne_unique <;> intro x <;> simp [e, laurentEvalOne] + simpa using RingHom.congr_fun h (e p) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem laurent_identity_ideal_map (K : Type*) [Field K] : + (RingHom.ker (laurentEvalOne K (Fin 4)).toRingHom).map + (laurentEquivLocalization K (Fin 4)) = + (torusIdentityPoint (K := K)).asIdeal := by + let e := laurentEquivLocalization K (Fin 4) + have h : (torusIdentityPoint (K := K)).asIdeal.comap e = + RingHom.ker (laurentEvalOne K (Fin 4)).toRingHom := by + ext a + change torusEvalOne (e a) = 0 ↔ laurentEvalOne K (Fin 4) a = 0 + rw [laurentEvalOne_eq_torusEvalOne] + rw [← h, Ideal.map_comap_eq_self_of_equiv] + + + +variable (K ι : Type*) [CommRing K] [Fintype ι] + +noncomputable def laurentLocalRingEquivLocalization + (I : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [I.IsPrime] : + Localization.AtPrime I ≃ₐ[K] + Localization.AtPrime (I.map (laurentEquivLocalization K ι)) := + Localization.localAlgEquiv I _ (laurentEquivLocalization K ι) + (I.comap_map_of_bijective _ (laurentEquivLocalization K ι).bijective).symm + +@[simp] theorem laurentLocalRingEquivLocalization_algebraMap + (I : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [I.IsPrime] + (a : AddMonoidAlgebra K (ι →₀ ℤ)) : + laurentLocalRingEquivLocalization K ι I + (algebraMap _ (Localization.AtPrime I) a) = + algebraMap _ (Localization.AtPrime + (I.map (laurentEquivLocalization K ι))) + (laurentEquivLocalization K ι a) := by + simp [laurentLocalRingEquivLocalization, Localization.localAlgHom] + +end WeightedTorusJets.Geometry +end + +namespace WeightedTorusJets.Geometry + +theorem spectrum_local_irreducible_dimension_eq_localRing + {R : Type*} [CommRing R] (p : PrimeSpectrum R) : + Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R) // p ∈ V} = + ringKrullDim (Localization.AtPrime p.asIdeal) := by + let e := PrimeSpectrum.pointsEquivIrreducibleCloseds R + have hmem (q : PrimeSpectrum R) : + p ∈ (OrderDual.ofDual (e q) : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R)) ↔ + q ≤ p := by + change p ∈ closure ({q} : Set (PrimeSpectrum R)) ↔ q ≤ p + exact (PrimeSpectrum.le_iff_mem_closure q p).symm + let f : (Set.Iic p)ᵒᵈ ≃o + {V : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R) // p ∈ V} := + { toFun := fun q ↦ ⟨OrderDual.ofDual (e q.1), (hmem q.1).mpr q.2⟩ + invFun := fun V ↦ ⟨e.symm (OrderDual.toDual V.1), + (hmem (e.symm (OrderDual.toDual V.1))).mp + (by simpa only [e.apply_symm_apply, OrderDual.ofDual_toDual] using V.2)⟩ + left_inv := fun q ↦ Subtype.ext (e.symm_apply_apply q.1) + right_inv := fun V ↦ Subtype.ext (e.apply_symm_apply (OrderDual.toDual V.1)) + map_rel_iff' := e.le_iff_le } + calc + Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R) // p ∈ V} = + Order.krullDim (Set.Iic p)ᵒᵈ := (Order.krullDim_eq_of_orderIso f).symm + _ = Order.krullDim (Set.Iic p) := Order.krullDim_orderDual + _ = (Order.height p : WithBot ℕ∞) := (Order.height_eq_krullDim_Iic p).symm + _ = (p.asIdeal.height : WithBot ℕ∞) := by rw [PrimeSpectrum.height_eq_orderHeight] + _ = ringKrullDim (Localization.AtPrime p.asIdeal) := + (IsLocalization.AtPrime.ringKrullDim_eq_height p.asIdeal _).symm + + + + +theorem local_irreducible_closed_subspace_dimension_eq + {X : Type*} [TopologicalSpace X] (x : X) (Z : Set X) + (hx : x ∈ Z) (hZ : IsClosed Z) : + Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z} = + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds Z // (⟨x, hx⟩ : Z) ∈ W} := by + let f : {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z} ↪o + {W : TopologicalSpace.IrreducibleCloseds Z // (⟨x, hx⟩ : Z) ∈ W} := + OrderEmbedding.ofMapLEIff + (fun V ↦ ⟨irreducibleClosedSubtypeEmbedding Z ⟨V.1, V.2.2⟩, V.2.1⟩) + (fun _ _ ↦ (irreducibleClosedSubtypeEmbedding Z).le_iff_le) + have hsurj : Function.Surjective f := by + intro W + let V : TopologicalSpace.IrreducibleCloseds X := + ⟨Subtype.val '' (W.1 : Set Z), + W.1.isIrreducible.image _ continuous_subtype_val.continuousOn, + hZ.isClosedMap_subtype_val _ W.1.isClosed⟩ + have hxV : x ∈ V := ⟨⟨x, hx⟩, W.2, rfl⟩ + have hVZ : (V : Set X) ⊆ Z := by + rintro y ⟨z, _, rfl⟩ + exact z.2 + refine ⟨⟨V, hxV, hVZ⟩, ?_⟩ + apply Subtype.ext + apply TopologicalSpace.IrreducibleCloseds.ext + change Subtype.val ⁻¹' (Subtype.val '' (W.1 : Set Z)) = (W.1 : Set Z) + exact Set.preimage_image_eq _ Subtype.val_injective + exact Order.krullDim_eq_of_orderIso (OrderIso.ofSurjective f hsurj) + +theorem zeroLocus_local_irreducible_dimension_eq_height + {R : Type*} [CommRing R] (I : Ideal R) (p : PrimeSpectrum.zeroLocus (I : Set R)) : + Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum.zeroLocus (I : Set R)) // p ∈ V} = + (Order.height p : WithBot ℕ∞) := by + let Z := PrimeSpectrum.zeroLocus (I : Set R) + let e := PrimeSpectrum.zeroLocusEquivIrreducibleCloseds (I : Set R) + have hmem (q : Z) : + p ∈ (OrderDual.ofDual (e q) : TopologicalSpace.IrreducibleCloseds Z) ↔ q ≤ p := by + change p ∈ closure ({q} : Set Z) ↔ q ≤ p + rw [← specializes_iff_mem_closure] + exact (subtype_specializes_iff q p).trans (PrimeSpectrum.le_iff_specializes q.1 p.1).symm + let f : (Set.Iic p)ᵒᵈ ≃o + {V : TopologicalSpace.IrreducibleCloseds Z // p ∈ V} := + { toFun := fun q ↦ ⟨OrderDual.ofDual (e q.1), (hmem q.1).mpr q.2⟩ + invFun := fun V ↦ ⟨e.symm (OrderDual.toDual V.1), + (hmem (e.symm (OrderDual.toDual V.1))).mp + (by simpa only [e.apply_symm_apply, OrderDual.ofDual_toDual] using V.2)⟩ + left_inv := fun q ↦ Subtype.ext (e.symm_apply_apply q.1) + right_inv := fun V ↦ Subtype.ext (e.apply_symm_apply (OrderDual.toDual V.1)) + map_rel_iff' := e.le_iff_le } + calc + Order.krullDim {V : TopologicalSpace.IrreducibleCloseds Z // p ∈ V} = + Order.krullDim (Set.Iic p)ᵒᵈ := (Order.krullDim_eq_of_orderIso f).symm + _ = Order.krullDim (Set.Iic p) := Order.krullDim_orderDual + _ = (Order.height p : WithBot ℕ∞) := (Order.height_eq_krullDim_Iic p).symm + +theorem ideal_local_irreducible_dimension_eq_localRing + {R : Type*} [CommRing R] (I : Ideal R) (p : PrimeSpectrum R) + (hp : I ≤ p.asIdeal) : + let q := I.primeSpectrumQuotientOrderIsoZeroLocus.symm ⟨p, hp⟩ + Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R) // + p ∈ V ∧ (V : Set (PrimeSpectrum R)) ⊆ PrimeSpectrum.zeroLocus (I : Set R)} = + ringKrullDim (Localization.AtPrime q.asIdeal) := by + let e := I.primeSpectrumQuotientOrderIsoZeroLocus + let z : PrimeSpectrum.zeroLocus (I : Set R) := ⟨p, hp⟩ + let q := e.symm z + rw [local_irreducible_closed_subspace_dimension_eq p _ hp (PrimeSpectrum.isClosed_zeroLocus _), + zeroLocus_local_irreducible_dimension_eq_height I z] + have he : Order.height z = Order.height q := by + simpa only [q, e.apply_symm_apply] using Order.height_orderIso e q + rw [he, ← PrimeSpectrum.height_eq_orderHeight] + exact (IsLocalization.AtPrime.ringKrullDim_eq_height q.asIdeal _).symm + +end WeightedTorusJets.Geometry + + +section + + +namespace WeightedTorusJets.Geometry + +variable {K : Type*} [Field K] + +theorem laurent_ringKrullDim (n : ℕ) : + ringKrullDim (AddMonoidAlgebra K (Fin n →₀ ℤ)) = n := by + rw [ringKrullDim_eq_of_ringEquiv (laurentEquivLocalization K (Fin n)).toRingEquiv] + exact torus_chart_ringKrullDim n + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K : Type*} [Field K] + +theorem laurent_prime_dimension_codimension (n : ℕ) + (p : Ideal (AddMonoidAlgebra K (Fin n →₀ ℤ))) [p.IsPrime] : + ∃ d : ℕ, ringKrullDim (AddMonoidAlgebra K (Fin n →₀ ℤ) ⧸ p) = d ∧ + p.height = (n - d : ℕ) := by + have := WeightedTorusJets.laurent_finiteType (K := K) (ι := Fin n) + obtain ⟨d, hdim, _⟩ := WeightedTorusJets.finiteType_dimension_trdeg + (K := K) (A := AddMonoidAlgebra K (Fin n →₀ ℤ) ⧸ p) + refine ⟨d, hdim, ?_⟩ + have hsum := prime_height_add_quotient_dim_eq_of_finiteType (K := K) p + rw [laurent_ringKrullDim, hdim] at hsum + have he : p.height + (d : ℕ∞) = n := by exact_mod_cast hsum + have hfin : p.height ≠ ⊤ := by + intro htop + simp only [htop, top_add, ENat.top_ne_natCast] at he + obtain ⟨h, hh⟩ := ENat.ne_top_iff_exists.mp hfin + rw [← hh] at he ⊢ + have hnat : h + d = n := by exact_mod_cast he + congr 1 + omega + +end WeightedTorusJets.Geometry + + +end + +namespace WeightedTorusJets.Geometry + +theorem finiteType_domain_closedPoint_ringKrullDim + {K A S : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [Algebra.FiniteType K A] [CommRing S] [Algebra A S] + (m : Ideal A) [m.IsMaximal] [IsLocalization.AtPrime S m] : + ringKrullDim S = ringKrullDim A := by + rw [IsLocalization.AtPrime.ringKrullDim_eq_height m S] + exact maximal_height_eq_ringKrullDim_of_finiteType (K := K) m + +theorem finiteType_prime_component_closedPoint_dimension + {K A : Type*} [Field K] [CommRing A] [Algebra K A] [Algebra.FiniteType K A] + (p m : Ideal A) [p.IsPrime] [m.IsMaximal] (hpm : p ≤ m) : + let P := m.map (Ideal.Quotient.mk p) + let : P.IsMaximal := Ideal.IsMaximal.map_of_surjective_of_ker_le + Ideal.Quotient.mk_surjective (by simpa using hpm) + ringKrullDim (Localization.AtPrime P) = ringKrullDim (A ⧸ p) := by + dsimp only + let : (m.map (Ideal.Quotient.mk p)).IsMaximal := + Ideal.IsMaximal.map_of_surjective_of_ker_le + Ideal.Quotient.mk_surjective (by simpa using hpm) + exact finiteType_domain_closedPoint_ringKrullDim (K := K) (m.map (Ideal.Quotient.mk p)) + +end WeightedTorusJets.Geometry + + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LinearShearHom.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LinearShearHom.lean new file mode 100644 index 0000000000000000000000000000000000000000..d9c82a7824d25e9dcb668ecc34d799d4832633f2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LinearShearHom.lean @@ -0,0 +1,786 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem totalDegree_aeval_le_of_linear {K σ τ : Type*} [CommSemiring K] + (v : σ → MvPolynomial τ K) (hv : ∀ i, (v i).totalDegree ≤ 1) + (f : MvPolynomial σ K) : (MvPolynomial.aeval v f).totalDegree ≤ f.totalDegree := by + classical + conv_lhs => rw [f.as_sum, map_sum] + apply totalDegree_finsetSum_le + intro d hd + rw [aeval_monomial, MvPolynomial.algebraMap_eq] + have hmul := totalDegree_mul (C (f.coeff d)) (d.prod fun i k => v i ^ k) + simp only [totalDegree_C, zero_add] at hmul + apply hmul.trans + refine (totalDegree_finsetProd d.support (fun i => v i ^ d i)).trans ?_ + apply le_trans _ (le_totalDegree hd) + apply Finset.sum_le_sum + intro i _ + simpa only [Nat.mul_one] using + (totalDegree_pow (v i) (d i)).trans (Nat.mul_le_mul_left (d i) (hv i)) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.LinearNormalization + +open MvPolynomial + +variable {K : Type*} [Field K] {n : ℕ} + +noncomputable def linearShearHom (c : Fin n → K) : + MvPolynomial (Fin (n + 1)) K →ₐ[K] MvPolynomial (Fin (n + 1)) K := + aeval (Fin.cases (X 0) (fun i => X i.succ + C (c i) * X 0)) + +@[simp] theorem linearShearHom_X_succ (c : Fin n → K) (i : Fin n) : + linearShearHom c (X i.succ) = X i.succ + C (c i) * X 0 := by + simp [linearShearHom] + +theorem linearShearHom_comp_neg (c : Fin n → K) : + (linearShearHom c).comp (linearShearHom (-c)) = AlgHom.id K _ := by + ext i + cases i using Fin.cases <;> simp [map_add, map_mul, linearShearHom] + +noncomputable def linearShear (c : Fin n → K) : + MvPolynomial (Fin (n + 1)) K ≃ₐ[K] MvPolynomial (Fin (n + 1)) K := + AlgEquiv.ofAlgHom (linearShearHom c) (linearShearHom (-c)) + (linearShearHom_comp_neg c) (by simpa using linearShearHom_comp_neg (-c)) + +theorem totalDegree_linearShear_le (c : Fin n → K) (f : MvPolynomial (Fin (n + 1)) K) : + (linearShear c f).totalDegree ≤ f.totalDegree := by + change (linearShearHom c f).totalDegree ≤ f.totalDegree + apply WeightedTorusJets.Geometry.totalDegree_aeval_le_of_linear + intro i + cases i using Fin.cases with + | zero => simp + | succ i => + simp only [Fin.cases_succ] + apply (totalDegree_add _ _).trans + apply max_le (by simp) + apply (totalDegree_mul _ _).trans + simp + +@[simp] theorem totalDegree_linearShear (c : Fin n → K) + (f : MvPolynomial (Fin (n + 1)) K) : + (linearShear c f).totalDegree = f.totalDegree := by + apply le_antisymm (totalDegree_linearShear_le c f) + have h := totalDegree_linearShear_le (-c) (linearShear c f) + have hc : linearShear (-c) (linearShear c f) = f := by + exact congrArg (fun h : MvPolynomial (Fin (n + 1)) K →ₐ[K] MvPolynomial (Fin (n + 1)) K => h f) + (by simpa using linearShearHom_comp_neg (-c)) + simpa only [hc] using h + +theorem isHomogeneous_linearShear (c : Fin n → K) + {f : MvPolynomial (Fin (n + 1)) K} {d : ℕ} (hf : f.IsHomogeneous d) : + (linearShear c f).IsHomogeneous d := by + change (linearShearHom c f).IsHomogeneous d + have hvars : ∀ i : Fin (n + 1), + (Fin.cases (X 0 : MvPolynomial (Fin (n + 1)) K) + (fun j => X j.succ + C (c j) * X 0) i : MvPolynomial (Fin (n + 1)) K).IsHomogeneous 1 := by + intro i + cases i using Fin.cases with + | zero => exact isHomogeneous_X K 0 + | succ i => exact (isHomogeneous_X K i.succ).add (isHomogeneous_C_mul_X _ _) + simpa only [linearShearHom, one_mul] using hf.aeval _ hvars + +theorem eval_mul_of_isHomogeneous {σ : Type*} {f : MvPolynomial σ K} {d : ℕ} + (hf : f.IsHomogeneous d) (a : K) (r : σ → K) : + eval (fun i => a * r i) f = a ^ d * eval r f := by + classical + induction hf using IsWeightedHomogeneous.induction_on with + | zero => simp + | add p q hp hq ihp ihq => simp only [map_add, ihp, ihq, mul_add] + | monomial e b he => + rw [eval_monomial, eval_monomial] + simp_rw [mul_pow, Finsupp.prod_mul] + have he' : e.sum (fun _ k => k) = d := by + simpa only [Finsupp.weight_apply, Pi.one_apply, smul_eq_mul, mul_one] using he + have hp : e.prod (fun _ k => a ^ k) = a ^ d := by + simpa only [Finsupp.prod, Finsupp.sum, Finset.prod_pow_eq_pow_sum] using congrArg (fun k => a ^ k) he' + rw [hp] + ring + +theorem exists_eval_cons_one_ne_zero [Infinite K] + {f : MvPolynomial (Fin (n + 1)) K} {d : ℕ} + (hf : f.IsHomogeneous d) (hf0 : f ≠ 0) : + ∃ c : Fin n → K, eval (Fin.cons 1 c) f ≠ 0 := by + have hxf : (X 0 : MvPolynomial (Fin (n + 1)) K) * f ≠ 0 := + mul_ne_zero (X_ne_zero _) hf0 + obtain ⟨r, hr⟩ : ∃ r : Fin (n + 1) → K, eval r (X 0 * f) ≠ 0 := by + by_contra h + push Not at h + exact hxf (((isHomogeneous_X K 0).mul hf).eq_zero_of_forall_eval_eq_zero h) + have hrs : r 0 ≠ 0 ∧ eval r f ≠ 0 := by + simpa only [map_mul, eval_X, mul_ne_zero_iff] using hr + have hr0 := hrs.1 + have hrf := hrs.2 + refine ⟨fun i => (r 0)⁻¹ * r i.succ, ?_⟩ + have hc : Fin.cons 1 (fun i => (r 0)⁻¹ * r i.succ) = + fun i => (r 0)⁻¹ * r i := by + funext i + cases i using Fin.cases <;> simp [hr0] + rw [hc, eval_mul_of_isHomogeneous hf] + exact mul_ne_zero (pow_ne_zero _ (inv_ne_zero hr0)) hrf + +theorem homogeneousComponent_linearShear (c : Fin n → K) + (d : ℕ) (f : MvPolynomial (Fin (n + 1)) K) : + homogeneousComponent d (linearShear c f) = + linearShear c (homogeneousComponent d f) := by + induction f using MvPolynomial.induction_on' with + | monomial e b => + rw [homogeneousComponent_of_mem + (isHomogeneous_linearShear c (isHomogeneous_monomial b rfl)), + homogeneousComponent_of_mem (isHomogeneous_monomial b rfl)] + split_ifs <;> simp + | add p q hp hq => simp only [map_add, hp, hq] + +theorem eval_cons_one_zero_of_isHomogeneous + {f : MvPolynomial (Fin (n + 1)) K} {d : ℕ} (hf : f.IsHomogeneous d) : + eval (Fin.cons 1 0) f = + constantCoeff ((finSuccEquiv K n f).coeff d) := by + have hdeg : (finSuccEquiv K n f).natDegree < d + 1 := by + have ht := hf.totalDegree_le + have h := degreeOf_le_totalDegree f 0 + rw [← natDegree_finSuccEquiv f] at h + omega + have aux : ∀ i ∈ Finset.range d, + constantCoeff ((finSuccEquiv K n f).coeff i) = 0 := by + intro i hi + rw [Finset.mem_range] at hi + apply (hf.finSuccEquiv_coeff_isHomogeneous i (d - i) (by omega)).coeff_eq_zero + simp only [map_zero] + omega + simp_rw [eval_eq_eval_mv_eval', Polynomial.eval_one_map, + Polynomial.eval_eq_sum_range' hdeg, eval_zero, one_pow, mul_one, map_sum, + Finset.sum_range_succ, Finset.sum_eq_zero aux, zero_add] + +theorem eval_cons_one_zero_linearShear (c : Fin n → K) + (f : MvPolynomial (Fin (n + 1)) K) : + eval (Fin.cons 1 0) (linearShear c f) = eval (Fin.cons 1 c) f := by + have h : (eval (Fin.cons 1 0)).comp (linearShearHom c).toRingHom = + eval (Fin.cons 1 c) := by + apply MvPolynomial.ringHom_ext + · intro b + simp [linearShearHom] + · intro i + cases i using Fin.cases <;> simp [linearShearHom] + exact congrArg (fun g : MvPolynomial (Fin (n + 1)) K →+* K => g f) h + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial Ideal Polynomial RingHom +variable {K : Type*} [Field K] {n : ℕ} + +theorem algEquiv_isIntegral {A B : Type*} [CommRing A] [CommRing B] + [Algebra K A] [Algebra K B] (e : A ≃ₐ[K] B) : e.toAlgHom.IsIntegral := + RingHom.isIntegral_of_surjective e.toAlgHom.toRingHom e.surjective + +theorem isUnit_leadingCoeff_finSuccEquiv_of_full_degree + {f : MvPolynomial (Fin (n + 1)) K} (hf : f ≠ 0) + (hd : degreeOf 0 f = f.totalDegree) : + IsUnit (finSuccEquiv K n f).leadingCoeff := by + have hp : finSuccEquiv K n f ≠ 0 := by + intro h + exact hf ((finSuccEquiv K n).injective (by simpa using h)) + have hnd : (finSuccEquiv K n f).natDegree = f.totalDegree := by + simpa only [natDegree_finSuccEquiv] using hd + have hl : (finSuccEquiv K n f).coeff f.totalDegree ≠ 0 := by + rw [← hnd, coeff_natDegree] + exact leadingCoeff_ne_zero.mpr hp + have ht := totalDegree_coeff_finSuccEquiv_add_le f f.totalDegree hl + have hz : ((finSuccEquiv K n f).coeff f.totalDegree).totalDegree = 0 := by omega + have he := totalDegree_eq_zero_iff_eq_C.mp hz + have hc : ((finSuccEquiv K n f).coeff f.totalDegree).coeff 0 ≠ 0 := by + intro hc + exact hl (by rw [he, hc, map_zero]) + rw [← coeff_natDegree, hnd, he] + exact hc.isUnit.map MvPolynomial.C + +noncomputable def eliminationEquiv (c : Fin n → K) : + MvPolynomial (Fin (n + 1)) K ≃ₐ[K] Polynomial (MvPolynomial (Fin n) K) := + (linearShear c).trans (finSuccEquiv K n) + +noncomputable def eliminationIdeal (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) : + Ideal (Polynomial (MvPolynomial (Fin n) K)) := I.map (eliminationEquiv c) + +noncomputable def eliminationQuotientEquiv (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) : + (Polynomial (MvPolynomial (Fin n) K) ⧸ eliminationIdeal c I) ≃ₐ[K] + MvPolynomial (Fin (n + 1)) K ⧸ I := + Ideal.quotientEquivAlg _ I (eliminationEquiv c).symm (by + change I = Ideal.map (eliminationEquiv c).symm.toRingEquiv.toRingHom + (Ideal.map (eliminationEquiv c).toRingEquiv.toRingHom I) + rw [Ideal.map_map] + have hc : (eliminationEquiv c).symm.toRingEquiv.toRingHom.comp + (eliminationEquiv c).toRingEquiv.toRingHom = RingHom.id _ := + (eliminationEquiv c).toRingEquiv.symm_toRingHom_comp_toRingHom + rw [hc, Ideal.map_id]) + +noncomputable def eliminationBaseHom (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) : + MvPolynomial (Fin n) K →ₐ[MvPolynomial (Fin n) K] + Polynomial (MvPolynomial (Fin n) K) ⧸ eliminationIdeal c I := + (Ideal.Quotient.mkₐ _ _).comp (Algebra.ofId _ _) + +noncomputable def eliminationHom (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) : + MvPolynomial (Fin n) K →ₐ[K] MvPolynomial (Fin (n + 1)) K ⧸ I := + (eliminationQuotientEquiv c I).toAlgHom.comp + ((eliminationBaseHom c I).restrictScalars K) + +theorem eliminationHom_isIntegral (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) + {f : MvPolynomial (Fin (n + 1)) K} (hf : f ≠ 0) (hfi : f ∈ I) + (hd : degreeOf 0 (linearShear c f) = f.totalDegree) : + (eliminationHom c I).IsIntegral := by + have hsf : linearShear c f ≠ 0 := by + intro h + exact hf ((linearShear c).injective (by simpa using h)) + have hu := isUnit_leadingCoeff_finSuccEquiv_of_full_degree hsf + (by simpa only [totalDegree_linearShear] using hd) + have hb : (eliminationBaseHom c I).IsIntegral := by + exact (monic_of_isUnit_leadingCoeff_inv_smul hu).quotient_isIntegral + (Submodule.smul_of_tower_mem _ hu.unit⁻¹.val (Ideal.mem_map_of_mem _ hfi)) + have he := algEquiv_isIntegral + (A := Polynomial (MvPolynomial (Fin n) K) ⧸ eliminationIdeal c I) + (B := MvPolynomial (Fin (n + 1)) K ⧸ I) (eliminationQuotientEquiv c I) + exact hb.trans _ _ he + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial Ideal RingHom +variable {K : Type*} [Field K] {n : ℕ} + +@[simp] theorem linearShear_apply_neg (c : Fin n → K) + (f : MvPolynomial (Fin (n + 1)) K) : + linearShear c (linearShear (-c) f) = f := by + exact congrArg (fun h : MvPolynomial (Fin (n + 1)) K →ₐ[K] + MvPolynomial (Fin (n + 1)) K => h f) (linearShearHom_comp_neg c) + +@[simp] theorem eliminationQuotientEquiv_mk (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) + (p : Polynomial (MvPolynomial (Fin n) K)) : + eliminationQuotientEquiv c I (Ideal.Quotient.mk (eliminationIdeal c I) p) = + Ideal.Quotient.mk I ((eliminationEquiv c).symm p) := by + simp only [eliminationQuotientEquiv, Ideal.quotientEquivAlg_mk] + +theorem eliminationHom_apply_raw (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) (p : MvPolynomial (Fin n) K) : + eliminationHom c I p = Ideal.Quotient.mk I + ((eliminationEquiv c).symm (Polynomial.C p)) := by + exact eliminationQuotientEquiv_mk c I (Polynomial.C p) + +theorem eliminationEquiv_linearShear_neg (c : Fin n → K) + (f : MvPolynomial (Fin (n + 1)) K) : + eliminationEquiv c (linearShear (-c) f) = finSuccEquiv K n f := by + rw [eliminationEquiv, AlgEquiv.trans_apply, linearShear_apply_neg] + +theorem eliminationEquiv_symm_C_X (c : Fin n → K) (i : Fin n) : + (eliminationEquiv c).symm (Polynomial.C (MvPolynomial.X i)) = + linearShear (-c) (MvPolynomial.X i.succ) := by + apply (eliminationEquiv c).symm_apply_eq.mpr + rw [eliminationEquiv_linearShear_neg, finSuccEquiv_X_succ] + +@[simp] theorem eliminationHom_X (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) (i : Fin n) : + eliminationHom c I (MvPolynomial.X i) = + Ideal.Quotient.mk I (linearShear (-c) (MvPolynomial.X i.succ)) := by + rw [eliminationHom_apply_raw, eliminationEquiv_symm_C_X] + +theorem eliminationHom_apply (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) (p : MvPolynomial (Fin n) K) : + eliminationHom c I p = + Ideal.Quotient.mk I (linearShear (-c) (MvPolynomial.rename Fin.succ p)) := by + have h : eliminationHom c I = (Ideal.Quotient.mkₐ K I).comp + ((linearShear (-c)).toAlgHom.comp (MvPolynomial.rename Fin.succ)) := by + ext i + simp only [eliminationHom_X, AlgHom.comp_apply, rename_X, + AlgEquiv.coe_toAlgHom, Quotient.mkₐ_eq_mk] + exact congrArg (fun g : MvPolynomial (Fin n) K →ₐ[K] + MvPolynomial (Fin (n + 1)) K ⧸ I => g p) h + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.Geometry + +open MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem exists_homogeneous_relation_not_dvd_coordinate + {R σ : Type*} [CommRing R] [IsDomain R] + (P : Ideal (MvPolynomial σ R)) [P.IsPrime] + (hP : P.IsHomogeneous (homogeneousSubmodule σ R)) (hP0 : P ≠ ⊥) + (i : σ) (hi : X i ∉ P) : + ∃ (n : ℕ) (f : MvPolynomial σ R), + f ≠ 0 ∧ f ∈ P ∧ f.IsHomogeneous n ∧ ¬ X i ∣ f := by + classical + obtain ⟨a, haP, ha0⟩ := Submodule.exists_mem_ne_zero_of_ne_bot hP0 + have hex : ∃ n : ℕ, ∃ f : MvPolynomial σ R, + f ∈ P ∧ f ≠ 0 ∧ f.totalDegree = n := ⟨a.totalDegree, a, haP, ha0, rfl⟩ + obtain ⟨f, hfP, hf0, hfdeg⟩ := Nat.find_spec hex + obtain ⟨n, hn, hn0⟩ : ∃ n ∈ Finset.range (f.totalDegree + 1), + homogeneousComponent n f ≠ 0 := by + by_contra h + push Not at h + apply hf0 + rw [← sum_homogeneousComponent f] + exact Finset.sum_eq_zero h + have hnP := homogeneousComponent_mem_of_mem hP hfP n + have hhom := homogeneousComponent_isHomogeneous n f + refine ⟨n, homogeneousComponent n f, hn0, hnP, hhom, ?_⟩ + rintro ⟨g, hg⟩ + have hg0 : g ≠ 0 := by + intro hzero + apply hn0 + rw [hg, hzero, mul_zero] + have hgP : g ∈ P := + (Ideal.IsPrime.mem_or_mem inferInstance (hg ▸ hnP)).resolve_left hi + have hmin := Nat.find_min' hex ⟨g, hgP, hg0, rfl⟩ + have hdeg := congrArg MvPolynomial.totalDegree hg + rw [hhom.totalDegree hn0, totalDegree_mul_of_isDomain (X_ne_zero i) hg0, + totalDegree_X] at hdeg + have hnle : n ≤ f.totalDegree := Nat.lt_succ_iff.mp (Finset.mem_range.mp hn) + omega + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem coordinate_dvd_sub_aeval_update_zero + {R σ : Type*} [CommRing R] [DecidableEq σ] + (i : σ) (p : MvPolynomial σ R) : + X i ∣ p - aeval (Function.update (X (R := R)) i 0) p := by + induction p using MvPolynomial.induction_on with + | C a => simp + | add p q hp hq => + simpa only [map_add, add_sub_add_comm] using dvd_add hp hq + | mul_X p j hp => + by_cases hji : j = i + · subst j + simp only [map_mul, aeval_X, Function.update_self, mul_zero, sub_zero] + exact dvd_mul_left _ _ + · simp only [map_mul, aeval_X, Function.update_of_ne hji] + rw [← sub_mul] + exact dvd_mul_of_dvd_left hp _ + +theorem aeval_update_zero_eq_zero_iff + {R σ : Type*} [CommRing R] [DecidableEq σ] + (i : σ) (p : MvPolynomial σ R) : + aeval (Function.update (X (R := R)) i 0) p = 0 ↔ X i ∣ p := by + constructor + · intro h + simpa only [h, sub_zero] using coordinate_dvd_sub_aeval_update_zero i p + · rintro ⟨q, rfl⟩ + simp + +theorem isHomogeneous_aeval_update_zero + {R σ : Type*} [CommSemiring R] [DecidableEq σ] + (i : σ) {p : MvPolynomial σ R} {n : ℕ} (hp : p.IsHomogeneous n) : + (aeval (Function.update (X (R := R)) i 0) p).IsHomogeneous n := by + simpa only [one_mul] using hp.aeval (n := 1) (Function.update (X (R := R)) i 0) + (fun j => by + by_cases h : j = i + · subst j + simpa only [Function.update_self] using isHomogeneous_zero (R := R) (σ := σ) 1 + · simpa only [Function.update_of_ne h] using isHomogeneous_X R j) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial +variable {K : Type*} [Field K] {n : ℕ} + +theorem eval_aeval_update_zero {σ : Type*} [DecidableEq σ] + (i : σ) (r : σ → K) (f : MvPolynomial σ K) : + eval r (aeval (Function.update (X (R := K)) i 0) f) = + eval (Function.update r i 0) f := by + have h : (eval r).comp (aeval (Function.update (X (R := K)) i 0)).toRingHom = + eval (Function.update r i 0) := by + apply MvPolynomial.ringHom_ext + · intro b + simp + · intro j + by_cases hji : j = i + · subst j + simp + · simp [Function.update_of_ne hji] + exact congrArg (fun g : MvPolynomial σ K →+* K => g f) h + +theorem exists_eval_cons_one_with_zero [Infinite K] + (j : Fin n) {f : MvPolynomial (Fin (n + 1)) K} {d : ℕ} + (hf : f.IsHomogeneous d) (hnot : ¬ X j.succ ∣ f) : + ∃ c : Fin n → K, c j = 0 ∧ eval (Fin.cons 1 c) f ≠ 0 := by + have hne : aeval (Function.update (X (R := K)) j.succ 0) f ≠ 0 := + (WeightedTorusJets.Geometry.aeval_update_zero_eq_zero_iff j.succ f).not.mpr hnot + obtain ⟨c, hc⟩ := exists_eval_cons_one_ne_zero + (WeightedTorusJets.Geometry.isHomogeneous_aeval_update_zero j.succ hf) hne + refine ⟨Function.update c j 0, Function.update_self j 0 c, ?_⟩ + have hvec : Function.update (Fin.cons 1 c : Fin (n + 1) → K) j.succ 0 = + (Fin.cons 1 (Function.update c j 0) : Fin (n + 1) → K) := by + funext i + cases i using Fin.cases with + | zero => simp [Function.update_of_ne (Fin.succ_ne_zero j).symm] + | succ i => simp [Function.update_apply, Fin.succ_inj] + rwa [eval_aeval_update_zero, hvec] at hc + +theorem degreeOf_linearShear_eq_of_isHomogeneous + (c : Fin n → K) {f : MvPolynomial (Fin (n + 1)) K} {d : ℕ} + (hf : f.IsHomogeneous d) (heval : eval (Fin.cons 1 c) f ≠ 0) : + degreeOf 0 (linearShear c f) = f.totalDegree := by + have hf0 : f ≠ 0 := by + intro h + exact heval (by simp [h]) + have htd := hf.totalDegree hf0 + apply le_antisymm + · simpa only [totalDegree_linearShear] using degreeOf_le_totalDegree (linearShear c f) 0 + · rw [← eval_cons_one_zero_linearShear, eval_cons_one_zero_of_isHomogeneous + (isHomogeneous_linearShear c hf), constantCoeff_eq, finSuccEquiv_coeff_coeff] at heval + have hdeg := le_degreeOf_of_mem_support 0 (mem_support_iff.mpr heval) + simpa only [Finsupp.cons_zero, htd] using hdeg + +theorem exists_linearShear_fix_coordinate_full [Infinite K] + (j : Fin n) {f : MvPolynomial (Fin (n + 1)) K} {d : ℕ} + (hf : f.IsHomogeneous d) (hnot : ¬ X j.succ ∣ f) : + ∃ c : Fin n → K, c j = 0 ∧ + degreeOf 0 (linearShear c f) = f.totalDegree ∧ + linearShear c (X j.succ) = X j.succ := by + obtain ⟨c, hc, hv⟩ := exists_eval_cons_one_with_zero j hf hnot + refine ⟨c, hc, degreeOf_linearShear_eq_of_isHomogeneous c hf hv, ?_⟩ + change linearShearHom c (X j.succ) = X j.succ + simp [hc] + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial Ideal RingHom +attribute [local instance] MvPolynomial.gradedAlgebra +variable {K : Type*} [Field K] {n : ℕ} + +theorem eliminationKer_isHomogeneous (c : Fin n → K) + (I : Ideal (MvPolynomial (Fin (n + 1)) K)) + (hI : I.IsHomogeneous (homogeneousSubmodule (Fin (n + 1)) K)) : + (RingHom.ker (eliminationHom c I)).IsHomogeneous + (homogeneousSubmodule (Fin n) K) := by + intro d p hp + rw [← DirectSum.Decomposition.decompose'_eq, + MvPolynomial.decomposition.decompose'_apply] + have hpI : linearShear (-c) (MvPolynomial.rename Fin.succ p) ∈ I := by + have hp0 : eliminationHom c I p = 0 := hp + rw [eliminationHom_apply, Ideal.Quotient.eq_zero_iff_mem] at hp0 + exact hp0 + have hd := homogeneousComponent_mem_of_mem hI hpI d + rw [homogeneousComponent_linearShear, ← rename_homogeneousComponent] at hd + change eliminationHom c I (homogeneousComponent d p) = 0 + rw [eliminationHom_apply, Ideal.Quotient.eq_zero_iff_mem] + exact hd + +theorem homogeneous_prime_finOne_eq_bot + (P : Ideal (MvPolynomial (Fin 1) K)) [P.IsPrime] + (hP : P.IsHomogeneous (homogeneousSubmodule (Fin 1) K)) + (hX : X (0 : Fin 1) ∉ P) : P = ⊥ := by + by_contra hP0 + obtain ⟨d, f, hf0, hfP, hf, hnot⟩ := + WeightedTorusJets.Geometry.exists_homogeneous_relation_not_dvd_coordinate P hP hP0 0 hX + have hne : aeval (Function.update (X (R := K)) (0 : Fin 1) 0) f ≠ 0 := + (WeightedTorusJets.Geometry.aeval_update_zero_eq_zero_iff 0 f).not.mpr hnot + have hu : Function.update (X (R := K)) (0 : Fin 1) 0 = + (0 : Fin 1 → MvPolynomial (Fin 1) K) := by + funext i + have hi : i = 0 := Subsingleton.elim _ _ + simp [hi] + have hc : f.coeff 0 ≠ 0 := by + intro hc + apply hne + rw [hu, aeval_zero, constantCoeff_eq, hc, map_zero] + have hd : d = 0 := by + have hd' := hf hc + simpa only [map_zero] using hd'.symm + subst d + have he : f = C (f.coeff 0) := by + simpa only [homogeneousComponent_zero] using (homogeneousComponent_eq_self hf).symm + exact (Ideal.IsPrime.ne_top inferInstance) + (P.eq_top_of_isUnit_mem hfP (he ▸ hc.isUnit.map MvPolynomial.C)) + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial Ideal RingHom +attribute [local instance] MvPolynomial.gradedAlgebra +variable {K : Type*} [Field K] + +theorem exists_integral_injective_linear_quotient_fixed_last [Infinite K] + {n : ℕ} (P : Ideal (MvPolynomial (Fin (n + 1)) K)) [P.IsPrime] + (hP : P.IsHomogeneous (homogeneousSubmodule (Fin (n + 1)) K)) + (hX : X (Fin.last n) ∉ P) : + ∃ s ≤ n, ∃ g : MvPolynomial (Fin (s + 1)) K →ₐ[K] + (MvPolynomial (Fin (n + 1)) K ⧸ P), + Function.Injective g ∧ g.IsIntegral ∧ + (∀ i, ∃ l : MvPolynomial (Fin (n + 1)) K, + l.IsHomogeneous 1 ∧ g (MvPolynomial.X i) = Ideal.Quotient.mk P l) ∧ + g (X (Fin.last s)) = Ideal.Quotient.mk P (X (Fin.last n)) := by + induction n with + | zero => + have hP0 : P = ⊥ := homogeneous_prime_finOne_eq_bot P hP hX + have hbij : Function.Bijective (Ideal.Quotient.mkₐ K P) := + (Ideal.Quotient.mk_bijective_iff_eq_bot P).mpr hP0 + exact ⟨0, le_rfl, Ideal.Quotient.mkₐ K P, hbij.1, + RingHom.isIntegral_of_surjective _ hbij.2, + fun i => ⟨MvPolynomial.X i, isHomogeneous_X K i, rfl⟩, rfl⟩ + | succ n ih => + by_cases hP0 : P = ⊥ + · have hbij : Function.Bijective (Ideal.Quotient.mkₐ K P) := + (Ideal.Quotient.mk_bijective_iff_eq_bot P).mpr hP0 + exact ⟨n + 1, le_rfl, Ideal.Quotient.mkₐ K P, hbij.1, + RingHom.isIntegral_of_surjective _ hbij.2, + fun i => ⟨MvPolynomial.X i, isHomogeneous_X K i, rfl⟩, rfl⟩ + · obtain ⟨d, f, hf0, hfP, hf, hnot⟩ := + WeightedTorusJets.Geometry.exists_homogeneous_relation_not_dvd_coordinate + P hP hP0 (Fin.last (n + 1)) hX + obtain ⟨c, hc, hdeg, _⟩ := exists_linearShear_fix_coordinate_full (Fin.last n) hf + (by simpa using hnot) + have hfix : linearShear (-c) (X (Fin.last n).succ) = X (Fin.last (n + 1)) := by + change linearShearHom (-c) (X (Fin.last n).succ) = _ + rw [linearShearHom_X_succ] + simp [hc] + let e := eliminationHom c P + let J := RingHom.ker e + let φ := Ideal.kerLiftAlg e + let : J.IsPrime := RingHom.ker_isPrime e + have hJ : J.IsHomogeneous (homogeneousSubmodule (Fin (n + 1)) K) := + eliminationKer_isHomogeneous c P hP + have hXJ : X (Fin.last n) ∉ J := by + intro hx + have hx0 : e (X (Fin.last n)) = 0 := hx + change eliminationHom c P (X (Fin.last n)) = 0 at hx0 + rw [eliminationHom_X, hfix, Ideal.Quotient.eq_zero_iff_mem] at hx0 + exact hX hx0 + obtain ⟨s, hs, g, hinj, hint, hlin, hlast⟩ := ih J hJ hXJ + refine ⟨s, Nat.le_succ_of_le hs, φ.comp g, ?_, ?_, ?_, ?_⟩ + · exact (φ.coe_comp g) ▸ (Ideal.kerLiftAlg_injective e).comp hinj + · exact hint.trans g.toRingHom φ.toRingHom + (eliminationHom_isIntegral c P hf0 hfP hdeg).kerLift + · intro i + obtain ⟨l, hl, hgl⟩ := hlin i + refine ⟨linearShear (-c) (MvPolynomial.rename Fin.succ l), + isHomogeneous_linearShear (-c) hl.rename_isHomogeneous, ?_⟩ + rw [AlgHom.comp_apply, hgl] + change e l = _ + exact eliminationHom_apply c P l + · rw [AlgHom.comp_apply, hlast] + change eliminationHom c P (X (Fin.last n)) = _ + rw [eliminationHom_X, hfix] + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial Ideal RingHom +attribute [local instance] MvPolynomial.gradedAlgebra +variable {K : Type*} [Field K] + +theorem exists_integral_injective_linear_quotient_fixed_coordinate [Infinite K] + {n : ℕ} (P : Ideal (MvPolynomial (Fin (n + 1)) K)) [P.IsPrime] + (hP : P.IsHomogeneous (homogeneousSubmodule (Fin (n + 1)) K)) + (i : Fin (n + 1)) (hX : X i ∉ P) : + ∃ s ≤ n, ∃ g : MvPolynomial (Fin (s + 1)) K →ₐ[K] + (MvPolynomial (Fin (n + 1)) K ⧸ P), + Function.Injective g ∧ g.IsIntegral ∧ + (∀ j, ∃ l : MvPolynomial (Fin (n + 1)) K, + l.IsHomogeneous 1 ∧ g (MvPolynomial.X j) = Ideal.Quotient.mk P l) ∧ + g (X 0) = Ideal.Quotient.mk P (X i) := by + classical + let e := MvPolynomial.renameEquiv K (Equiv.swap i (Fin.last n)) + let J := Ideal.comap e.toAlgHom.toRingHom P + let : J.IsPrime := Ideal.comap_isPrime e.toAlgHom.toRingHom P + have hJ : J.IsHomogeneous (homogeneousSubmodule (Fin (n + 1)) K) := by + intro d p hp + rw [← DirectSum.Decomposition.decompose'_eq, + MvPolynomial.decomposition.decompose'_apply] + change MvPolynomial.rename (Equiv.swap i (Fin.last n)) (homogeneousComponent d p) ∈ P + rw [MvPolynomial.rename_homogeneousComponent] + exact homogeneousComponent_mem_of_mem hP hp d + have hlast : X (Fin.last n) ∉ J := by + change e (X (Fin.last n)) ∉ P + simpa only [e, renameEquiv_apply, rename_X, Equiv.swap_apply_right] using hX + have hIJ : P = J.map e.toAlgHom.toRingHom := + (Ideal.map_comap_of_surjective e.toAlgHom.toRingHom e.surjective P).symm + let E := Ideal.quotientEquivAlg J P e hIJ + have hE : ∀ p, E (Ideal.Quotient.mk J p) = Ideal.Quotient.mk P (e p) := by + intro p + exact Ideal.quotientEquivAlg_mk (I := J) (J := P) e hIJ p + obtain ⟨s, hs, g, hinj, hint, hlin, hfix⟩ := + exists_integral_injective_linear_quotient_fixed_last J hJ hlast + let r := MvPolynomial.renameEquiv K (Equiv.swap (0 : Fin (s + 1)) (Fin.last s)) + refine ⟨s, hs, E.toAlgHom.comp (g.comp r.toAlgHom), ?_, ?_, ?_, ?_⟩ + · exact E.injective.comp (hinj.comp r.injective) + · have hrint := algEquiv_isIntegral r + have hEint := algEquiv_isIntegral + (A := MvPolynomial (Fin (n + 1)) K ⧸ J) + (B := MvPolynomial (Fin (n + 1)) K ⧸ P) E + exact (hrint.trans r.toAlgHom.toRingHom g.toRingHom hint).trans _ _ hEint + · intro j + obtain ⟨l, hl, hgl⟩ := hlin ((Equiv.swap (0 : Fin (s + 1)) (Fin.last s)) j) + refine ⟨e l, hl.rename_isHomogeneous, ?_⟩ + change E (g (r (X j))) = Ideal.Quotient.mk P (e l) + simp only [r, renameEquiv_apply, rename_X] + rw [hgl] + exact hE l + · change E (g (r (X 0))) = Ideal.Quotient.mk P (X i) + simp only [r, renameEquiv_apply, rename_X, Equiv.swap_apply_left] + rw [hfix, hE] + simp only [e, renameEquiv_apply, rename_X, Equiv.swap_apply_right] + +theorem finite_of_integral_quotient {n s : ℕ} + (I : Ideal (MvPolynomial (Fin n) K)) + (g : MvPolynomial (Fin s) K →ₐ[K] (MvPolynomial (Fin n) K ⧸ I)) + (hint : g.IsIntegral) : g.Finite := by + let : Algebra.FiniteType K (MvPolynomial (Fin n) K ⧸ I) := + Algebra.FiniteType.of_surjective (Ideal.Quotient.mkₐ K I) Ideal.Quotient.mk_surjective + have h : algebraMap K (MvPolynomial (Fin n) K ⧸ I) = + g.toRingHom.comp (algebraMap K (MvPolynomial (Fin s) K)) := by + ext a + exact (g.commutes a).symm + exact hint.to_finite + ((h ▸ RingHom.finiteType_algebraMap.mpr inferInstance).of_comp_finiteType) + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.Geometry + +theorem ringKrullDim_eq_of_integral_faithful_goingDown + {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] + [Algebra.IsIntegral R S] [FaithfulSMul R S] [Algebra.HasGoingDown R S] : + ringKrullDim S = ringKrullDim R := by + apply le_antisymm + · apply Order.krullDim_le_of_strictMono (PrimeSpectrum.comap (algebraMap R S)) + intro p q hpq + exact Ideal.IsIntegral.under_lt_under hpq + · change Order.krullDim (PrimeSpectrum R) ≤ Order.krullDim (PrimeSpectrum S) + apply iSup_le + intro l + obtain ⟨P⟩ := Ideal.nonempty_primesOver (S := S) l.last.asIdeal + obtain ⟨L, hlen, _, _⟩ := Ideal.exists_ltSeries_of_hasGoingDown l P.1 + simpa only [hlen] using Order.LTSeries.length_le_krullDim L + +theorem ringKrullDim_eq_of_integral_faithful_normal + {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] + [IsDomain S] [Algebra.IsIntegral R S] [FaithfulSMul R S] [IsIntegrallyClosed R] : + ringKrullDim S = ringKrullDim R := + ringKrullDim_eq_of_integral_faithful_goingDown + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra +variable {K : Type*} [Field K] + +theorem ringKrullDim_quotient_eq_normalization_variables {n s : ℕ} + (I : Ideal (MvPolynomial (Fin n) K)) [I.IsPrime] + (g : MvPolynomial (Fin s) K →ₐ[K] (MvPolynomial (Fin n) K ⧸ I)) + (hg : Function.Injective g) (hint : g.IsIntegral) : + ringKrullDim (MvPolynomial (Fin n) K ⧸ I) = s := by + let : Algebra (MvPolynomial (Fin s) K) (MvPolynomial (Fin n) K ⧸ I) := + g.toRingHom.toAlgebra + let : SMul (MvPolynomial (Fin s) K) (MvPolynomial (Fin n) K ⧸ I) := + g.toRingHom.toAlgebra.toSMul + let : Algebra.IsIntegral (MvPolynomial (Fin s) K) (MvPolynomial (Fin n) K ⧸ I) := + ⟨hint⟩ + let : FaithfulSMul (MvPolynomial (Fin s) K) (MvPolynomial (Fin n) K ⧸ I) := + (faithfulSMul_iff_algebraMap_injective + (MvPolynomial (Fin s) K) (MvPolynomial (Fin n) K ⧸ I)).mpr hg + rw [WeightedTorusJets.Geometry.ringKrullDim_eq_of_integral_faithful_normal + (R := MvPolynomial (Fin s) K)] + simp + +end WeightedTorusJets.LinearNormalization + +namespace WeightedTorusJets.LinearNormalization +open MvPolynomial Ideal RingHom +attribute [local instance] MvPolynomial.gradedAlgebra + +theorem exists_finite_linear_normalization_finite_variables + {K σ : Type*} [Field K] [Infinite K] [Finite σ] + (P : Ideal (MvPolynomial σ K)) [P.IsPrime] + (hP : P.IsHomogeneous (homogeneousSubmodule σ K)) + (i : σ) (hX : X i ∉ P) : + ∃ s : ℕ, s + 1 ≤ Nat.card σ ∧ + ∃ g : MvPolynomial (Fin (s + 1)) K →ₐ[K] (MvPolynomial σ K ⧸ P), + Function.Injective g ∧ g.IsIntegral ∧ g.Finite ∧ + (∀ j, ∃ l : MvPolynomial σ K, + l.IsHomogeneous 1 ∧ g (MvPolynomial.X j) = Ideal.Quotient.mk P l) ∧ + g (X 0) = Ideal.Quotient.mk P (X i) ∧ + ringKrullDim (MvPolynomial σ K ⧸ P) = (s + 1 : ℕ) := by + classical + obtain ⟨m, ⟨e⟩⟩ := Finite.exists_equiv_fin σ + cases m with + | zero => exact Fin.elim0 (e i) + | succ n => + let r := MvPolynomial.renameEquiv K e.symm + let J := Ideal.comap r.toAlgHom.toRingHom P + let : J.IsPrime := Ideal.comap_isPrime r.toAlgHom.toRingHom P + have hJ : J.IsHomogeneous (homogeneousSubmodule (Fin (n + 1)) K) := by + intro d p hp + rw [← DirectSum.Decomposition.decompose'_eq, + MvPolynomial.decomposition.decompose'_apply] + change MvPolynomial.rename e.symm (homogeneousComponent d p) ∈ P + rw [MvPolynomial.rename_homogeneousComponent] + exact homogeneousComponent_mem_of_mem hP hp d + have hXi : X (e i) ∉ J := by + change r (X (e i)) ∉ P + simpa only [r, renameEquiv_apply, rename_X, Equiv.symm_apply_apply] using hX + have hJP : P = J.map r.toAlgHom.toRingHom := + (Ideal.map_comap_of_surjective r.toAlgHom.toRingHom r.surjective P).symm + let E := Ideal.quotientEquivAlg J P r hJP + have hE : ∀ p, E (Ideal.Quotient.mk J p) = Ideal.Quotient.mk P (r p) := by + intro p + exact Ideal.quotientEquivAlg_mk (I := J) (J := P) r hJP p + obtain ⟨s, hs, g, hinj, hint, hlin, hfix⟩ := + exists_integral_injective_linear_quotient_fixed_coordinate J hJ (e i) hXi + have hcard : Nat.card σ = n + 1 := by + simpa using Nat.card_congr e + let G := E.toAlgHom.comp g + have hEint := algEquiv_isIntegral + (A := MvPolynomial (Fin (n + 1)) K ⧸ J) + (B := MvPolynomial σ K ⧸ P) E + have hGint : G.IsIntegral := hint.trans _ _ hEint + have hEfin : E.toAlgHom.Finite := + RingHom.Finite.of_surjective E.toAlgHom.toRingHom E.surjective + have hGfin : G.Finite := hEfin.comp (finite_of_integral_quotient J g hint) + refine ⟨s, by rw [hcard]; omega, G, E.injective.comp hinj, hGint, hGfin, ?_, ?_, ?_⟩ + · intro j + obtain ⟨l, hl, hgl⟩ := hlin j + refine ⟨r l, hl.rename_isHomogeneous, ?_⟩ + change E (g (X j)) = _ + rw [hgl] + exact hE l + · change E (g (X 0)) = _ + rw [hfix, hE] + simp only [r, renameEquiv_apply, rename_X, Equiv.symm_apply_apply] + · rw [← ringKrullDim_eq_of_ringEquiv E.toRingEquiv] + exact ringKrullDim_quotient_eq_normalization_variables J g hinj hint + +end WeightedTorusJets.LinearNormalization + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LinearVariableBasis.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LinearVariableBasis.lean new file mode 100644 index 0000000000000000000000000000000000000000..832f379658907a4b5a0bb2736ad31729cb3d4a4c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LinearVariableBasis.lean @@ -0,0 +1,419 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.NormalizationPresentationLocalEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +open MvPolynomial +noncomputable section +open Module TensorProduct +namespace WeightedTorusJets.Geometry.DegreeBezout + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem finite_normalization_local_finrank_eq_length_mul_rank + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] [Finite σ] + [Algebra B F] [IsFractionRing B F] + (I p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [Module.Finite B (MvPolynomial σ B ⧸ p)] + (hp : p.comap MvPolynomial.C = ⊥) (hpI : p ∈ I.minimalPrimes) : + letI := coefficient_localization_isMaximal_of_finite (F := F) p hp + let q := p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) + (Module.finrank F + (Localization.AtPrime q ⧸ + (I.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).map + (algebraMap _ (Localization.AtPrime q))) : ℕ∞) = + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap _ (Localization.AtPrime p))) * + (Module.finrank B (MvPolynomial σ B ⧸ p) : ℕ∞) := by + let := coefficient_localization_isMaximal_of_finite (F := F) p hp + exact coefficient_localization_component_finrank_eq_length_mul_rank I p hp hpI + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.GeometryAcceptance + +theorem mem_minimalPrimes_of_local_radical_eq_maximal + {R : Type*} [CommRing R] (I p : Ideal R) [p.IsPrime] + (hrad : (I.map (algebraMap R (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : p ∈ I.minimalPrimes := by + have hlocal : IsLocalRing.maximalIdeal (Localization.AtPrime p) ∈ + (I.map (algebraMap R (Localization.AtPrime p))).minimalPrimes := by + rw [← Ideal.radical_minimalPrimes, hrad, Ideal.minimalPrimes_eq_subsingleton_self] + exact Set.mem_singleton _ + rwa [IsLocalization.minimalPrimes_map p.primeCompl (Localization.AtPrime p) I, + Set.mem_preimage, Localization.AtPrime.under_maximalIdeal] at hlocal + +end WeightedTorusJets.GeometryAcceptance + +namespace WeightedTorusJets.Geometry.DegreeBezout + +open MvPolynomial Module + +noncomputable section + +def linearVariableBasis (K σ : Type*) [Field K] : + Basis σ K (homogeneousSubmodule σ K 1) := + (Basis.span (linearIndependent_X σ K)).map + (LinearEquiv.ofEq _ _ homogeneousSubmodule_one_eq_span_X.symm) + +@[simp] theorem linearVariableBasis_apply {K σ : Type*} [Field K] (i : σ) : + (linearVariableBasis K σ i : MvPolynomial σ K) = X i := by + simp [linearVariableBasis] + +theorem normalization_linearForms_independent + {K σ ι : Type*} [Field K] (P : Ideal (MvPolynomial σ K)) + (g : MvPolynomial ι K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hg : Function.Injective g) (l : ι → homogeneousSubmodule σ K 1) + (hl : ∀ i, g (X i) = Ideal.Quotient.mk P (l i)) : + LinearIndependent K l := by + have hx : AlgebraicIndependent K (fun i => g (X i)) := by + rw [algebraicIndependent_iff_injective_aeval] + have he : aeval (fun i => g (X i)) = g := by ext i; simp + simpa only [he] using hg + have hcomp : (Ideal.Quotient.mkₐ K P).toLinearMap.comp + (homogeneousSubmodule σ K 1).subtype ∘ l = (fun i => g (X i)) := by + funext i + exact (hl i).symm + apply LinearIndependent.of_comp ((Ideal.Quotient.mkₐ K P).toLinearMap.comp + (homogeneousSubmodule σ K 1).subtype) + rw [hcomp] + exact hx.linearIndependent + +theorem symmetric_basis_coordinate_mem_degree_one + {K M ι : Type*} [Field K] [AddCommGroup M] [Module K M] + (b : Basis ι K M) (m : M) : + SymmetricAlgebra.equivMvPolynomial b (SymmetricAlgebra.ι K M m) ∈ + homogeneousSubmodule ι K 1 := by + let L := (SymmetricAlgebra.equivMvPolynomial b).toLinearMap.comp (SymmetricAlgebra.ι K M) + have hs : Submodule.span K (Set.range b) ≤ (homogeneousSubmodule ι K 1).comap L := by + apply Submodule.span_le.mpr + rintro _ ⟨i, rfl⟩ + change SymmetricAlgebra.equivMvPolynomial b (SymmetricAlgebra.ι K M (b i)) ∈ + homogeneousSubmodule ι K 1 + simpa using (isHomogeneous_X K i) + apply hs + rw [b.span_eq] + exact Submodule.mem_top + +theorem symmetric_standard_coordinates + {K σ : Type*} [Field K] (l : homogeneousSubmodule σ K 1) : + SymmetricAlgebra.equivMvPolynomial (linearVariableBasis K σ) + (SymmetricAlgebra.ι K (homogeneousSubmodule σ K 1) l) = (l : MvPolynomial σ K) := by + have he : (SymmetricAlgebra.equivMvPolynomial (linearVariableBasis K σ)).toLinearMap.comp + (SymmetricAlgebra.ι K (homogeneousSubmodule σ K 1)) = + (homogeneousSubmodule σ K 1).subtype := by + apply (linearVariableBasis K σ).ext + intro i + simp + exact congrArg (fun f : homogeneousSubmodule σ K 1 →ₗ[K] MvPolynomial σ K => f l) he + +def polynomialCoordinatesOfLinearBasis + {K σ ι : Type*} [Field K] (b : Basis ι K (homogeneousSubmodule σ K 1)) : + MvPolynomial ι K ≃ₐ[K] MvPolynomial σ K := + (SymmetricAlgebra.equivMvPolynomial b).symm.trans + (SymmetricAlgebra.equivMvPolynomial (linearVariableBasis K σ)) + +@[simp] theorem polynomialCoordinatesOfLinearBasis_X + {K σ ι : Type*} [Field K] (b : Basis ι K (homogeneousSubmodule σ K 1)) (i : ι) : + polynomialCoordinatesOfLinearBasis b (X i) = (b i : MvPolynomial σ K) := by + simp [polynomialCoordinatesOfLinearBasis, symmetric_standard_coordinates] + +theorem polynomialCoordinatesOfLinearBasis_symm_X_homogeneous + {K σ ι : Type*} [Field K] (b : Basis ι K (homogeneousSubmodule σ K 1)) (j : σ) : + ((polynomialCoordinatesOfLinearBasis b).symm (X j)).IsHomogeneous 1 := by + change ((SymmetricAlgebra.equivMvPolynomial b) + ((SymmetricAlgebra.equivMvPolynomial (linearVariableBasis K σ)).symm (X j))).IsHomogeneous 1 + rw [SymmetricAlgebra.equivMvPolynomial_symm_X] + exact symmetric_basis_coordinate_mem_degree_one b _ + +theorem polynomialCoordinatesOfLinearBasis_homogeneous + {K σ ι : Type*} [Field K] (b : Basis ι K (homogeneousSubmodule σ K 1)) + {p : MvPolynomial ι K} {d : ℕ} (hp : p.IsHomogeneous d) : + (polynomialCoordinatesOfLinearBasis b p).IsHomogeneous d := by + have he : aeval (fun i => polynomialCoordinatesOfLinearBasis b (X i)) = + (polynomialCoordinatesOfLinearBasis b).toAlgHom := by ext i; simp + simpa only [one_mul, he, AlgEquiv.coe_toAlgHom] using hp.aeval (n := 1) + (fun i => polynomialCoordinatesOfLinearBasis b (X i)) + (fun i => by rw [polynomialCoordinatesOfLinearBasis_X]; exact (b i).property) + +theorem polynomialCoordinatesOfLinearBasis_symm_homogeneous + {K σ ι : Type*} [Field K] (b : Basis ι K (homogeneousSubmodule σ K 1)) + {p : MvPolynomial σ K} {d : ℕ} (hp : p.IsHomogeneous d) : + ((polynomialCoordinatesOfLinearBasis b).symm p).IsHomogeneous d := by + have he : aeval (fun i => (polynomialCoordinatesOfLinearBasis b).symm (X i)) = + (polynomialCoordinatesOfLinearBasis b).symm.toAlgHom := by ext i; simp + simpa only [one_mul, he, AlgEquiv.coe_toAlgHom] using hp.aeval (n := 1) + (fun i => (polynomialCoordinatesOfLinearBasis b).symm (X i)) + (polynomialCoordinatesOfLinearBasis_symm_X_homogeneous b) + +theorem basis_sumExtend_inl {K M ι : Type*} [Field K] [AddCommGroup M] [Module K M] + {v : ι → M} (hv : LinearIndependent K v) (i : ι) : + Basis.sumExtend hv (Sum.inl i) = v i := by + simp only [Basis.sumExtend, Basis.reindex_apply, Basis.coe_extend] + rfl + +theorem exists_linearBasis_extension + {K σ ι : Type*} [Field K] [Finite σ] [Finite ι] + {l : ι → homogeneousSubmodule σ K 1} (hl : LinearIndependent K l) : + ∃ h : ℕ, Nat.card ι + h = Nat.card σ ∧ + ∃ b : Basis (ι ⊕ Fin h) K (homogeneousSubmodule σ K 1), + ∀ i, b (Sum.inl i) = l i := by + classical + let : Fintype σ := Fintype.ofFinite σ + let : Fintype ι := Fintype.ofFinite ι + let : Module.Finite K (homogeneousSubmodule σ K 1) := Module.Finite.of_basis (linearVariableBasis K σ) + let b₀ := Basis.sumExtend hl + let J := Basis.sumExtendIndex hl + have : Finite (ι ⊕ J) := Module.Finite.finite_basis b₀ + let : Finite J := Finite.of_injective (Sum.inr : J → ι ⊕ J) Sum.inr_injective + let : Fintype J := Fintype.ofFinite J + let e : (ι ⊕ J) ≃ (ι ⊕ Fin (Fintype.card J)) := + Equiv.sumCongr (Equiv.refl ι) (Fintype.equivFin J) + refine ⟨Fintype.card J, ?_, b₀.reindex e, ?_⟩ + · have he := (Module.finrank_eq_card_basis b₀).symm.trans + (Module.finrank_eq_card_basis (linearVariableBasis K σ)) + simpa only [Fintype.card_sum, Nat.card_eq_fintype_card] using he + · intro i + simpa [Basis.reindex_apply, e, b₀] using basis_sumExtend_inl hl i + +end + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry.DegreeBezout + +open MvPolynomial Module + +theorem totalDegree_algHom_le_of_linear_images + {K σ τ : Type*} [Field K] + (f : MvPolynomial σ K →ₐ[K] MvPolynomial τ K) + (hf : ∀ i, (f (X i)).totalDegree ≤ 1) (p : MvPolynomial σ K) : + (f p).totalDegree ≤ p.totalDegree := by + have h := totalDegree_eval₂_le_of_linear_images (RingHom.id K) + (fun i => f (X i)) hf p + have he : eval₂Hom (C.comp (RingHom.id K)) (fun i => f (X i)) = f.toRingHom := by + ext i <;> simp + change ((eval₂Hom (C.comp (RingHom.id K)) (fun i => f (X i))) p).totalDegree ≤ _ at h + rw [he] at h + exact h + +theorem polynomialCoordinatesOfLinearBasis_totalDegree + {K σ ι : Type*} [Field K] (b : Basis ι K (homogeneousSubmodule σ K 1)) + (p : MvPolynomial ι K) : + (polynomialCoordinatesOfLinearBasis b p).totalDegree = p.totalDegree := by + let e := polynomialCoordinatesOfLinearBasis b + have hf : ∀ i, (e (X i)).totalDegree ≤ 1 := by + intro i + change (polynomialCoordinatesOfLinearBasis b (X i)).totalDegree ≤ 1 + rw [polynomialCoordinatesOfLinearBasis_X] + exact IsHomogeneous.totalDegree_le (b i).property + have hb : ∀ i, (e.symm (X i)).totalDegree ≤ 1 := fun i => + (polynomialCoordinatesOfLinearBasis_symm_X_homogeneous b i).totalDegree_le + apply le_antisymm (totalDegree_algHom_le_of_linear_images e.toAlgHom hf p) + simpa only [AlgEquiv.coe_toAlgHom, AlgEquiv.symm_apply_apply] using + totalDegree_algHom_le_of_linear_images e.symm.toAlgHom hb (e p) + +theorem polynomialCoordinatesOfLinearBasis_symm_totalDegree + {K σ ι : Type*} [Field K] (b : Basis ι K (homogeneousSubmodule σ K 1)) + (p : MvPolynomial σ K) : + ((polynomialCoordinatesOfLinearBasis b).symm p).totalDegree = p.totalDegree := by + simpa only [AlgEquiv.apply_symm_apply] using + (polynomialCoordinatesOfLinearBasis_totalDegree b + ((polynomialCoordinatesOfLinearBasis b).symm p)).symm + +theorem exists_normalization_linear_coordinates + {K σ ι : Type*} [Field K] [Finite σ] [Finite ι] + (P : Ideal (MvPolynomial σ K)) + (g : MvPolynomial ι K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hg : Function.Injective g) + (hl : ∀ i, ∃ l : MvPolynomial σ K, l.IsHomogeneous 1 ∧ g (X i) = Ideal.Quotient.mk P l) : + ∃ h : ℕ, Nat.card ι + h = Nat.card σ ∧ + ∃ e : MvPolynomial (ι ⊕ Fin h) K ≃ₐ[K] MvPolynomial σ K, + (∀ i, g (X i) = Ideal.Quotient.mk P (e (X (Sum.inl i)))) ∧ + (∀ p, (e p).totalDegree = p.totalDegree) ∧ + (∀ p, (e.symm p).totalDegree = p.totalDegree) ∧ + (∀ p d, p.IsHomogeneous d → (e p).IsHomogeneous d) ∧ + (∀ p d, p.IsHomogeneous d → (e.symm p).IsHomogeneous d) := by + classical + choose l hlh hlg using hl + let l' : ι → homogeneousSubmodule σ K 1 := fun i => ⟨l i, hlh i⟩ + have hli := normalization_linearForms_independent P g hg l' hlg + obtain ⟨h, hc, b, hb⟩ := exists_linearBasis_extension hli + refine ⟨h, hc, polynomialCoordinatesOfLinearBasis b, ?_, + polynomialCoordinatesOfLinearBasis_totalDegree b, + polynomialCoordinatesOfLinearBasis_symm_totalDegree b, ?_, ?_⟩ + · intro i + rw [polynomialCoordinatesOfLinearBasis_X, hb] + exact hlg i + · intro p d hp + exact polynomialCoordinatesOfLinearBasis_homogeneous b hp + · intro p d hp + exact polynomialCoordinatesOfLinearBasis_symm_homogeneous b hp + +theorem exists_normalization_linear_coordinates_of_count + {K σ : Type*} [Field K] [Finite σ] {s h : ℕ} + (P : Ideal (MvPolynomial σ K)) + (g : MvPolynomial (Fin s) K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hg : Function.Injective g) + (hl : ∀ i, ∃ l : MvPolynomial σ K, + l.IsHomogeneous 1 ∧ g (X i) = Ideal.Quotient.mk P l) + (hc : s + h = Nat.card σ) : + ∃ e : MvPolynomial (Fin s ⊕ Fin h) K ≃ₐ[K] MvPolynomial σ K, + (∀ i, g (X i) = Ideal.Quotient.mk P (e (X (Sum.inl i)))) ∧ + (∀ p, (e p).totalDegree = p.totalDegree) ∧ + (∀ p, (e.symm p).totalDegree = p.totalDegree) ∧ + (∀ p d, p.IsHomogeneous d → (e p).IsHomogeneous d) ∧ + (∀ p d, p.IsHomogeneous d → (e.symm p).IsHomogeneous d) := by + obtain ⟨h', hc', e, he⟩ := exists_normalization_linear_coordinates P g hg hl + have hh : h' = h := by + apply Nat.add_left_cancel (n := s) + simpa only [Nat.card_fin, hc] using hc' + subst h' + exact ⟨e, he⟩ + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry.DegreeBezout + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem quotient_length_congr_ideal + {R : Type*} [CommRing R] (I J : Ideal R) (h : I = J) : + Module.length R (R ⧸ I) = Module.length R (R ⧸ J) := by + subst J + rfl + +theorem quotient_finrank_congr_ideal + {K R : Type*} [Field K] [CommRing R] [Algebra K R] + (I J : Ideal R) (h : I = J) : + Module.finrank K (R ⧸ I) = Module.finrank K (R ⧸ J) := by + subst J + rfl + +theorem coefficient_localization_weighted_length_le_pow + {B F : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (h D : ℕ) (p : Ideal (MvPolynomial (Fin h) B)) [p.IsPrime] + [Module.Finite B (MvPolynomial (Fin h) B ⧸ p)] + (hp : p.comap MvPolynomial.C = ⊥) + (f : Fin h → MvPolynomial (Fin h) B) + (hf : ∀ i, (MvPolynomial.map (algebraMap B F) (f i)).totalDegree ≤ D) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap _ (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ Ideal.span (Set.range (fun i => + algebraMap _ (Localization.AtPrime p) (f i)))) * + (Module.finrank B (MvPolynomial (Fin h) B ⧸ p) : ℕ∞) ≤ (D ^ h : ℕ) := by + let I := Ideal.span (Set.range f) + have hm : p ∈ I.minimalPrimes := + GeometryAcceptance.mem_minimalPrimes_of_local_radical_eq_maximal I p + (by simpa only [I, Ideal.map_span, ← Set.range_comp, Function.comp_def] using hrad) + have hn := coefficient_localization_finrank_le_pow (F := F) h D p hp f hf hrad + have he := finite_normalization_local_finrank_eq_length_mul_rank (F := F) I p hp hm + let := coefficient_localization_isMaximal_of_finite (F := F) p hp + let q := p.map (algebraMap (MvPolynomial (Fin h) B) (MvPolynomial (Fin h) F)) + let J := Ideal.span (Set.range (fun i => algebraMap _ (Localization.AtPrime p) (f i))) + let JF := Ideal.span (Set.range (fun i => algebraMap _ (Localization.AtPrime q) + (MvPolynomial.map (algebraMap B F) (f i)))) + have hI : I.map (algebraMap _ (Localization.AtPrime p)) = J := by + dsimp only [I] + rw [Ideal.map_span, ← Set.range_comp] + rfl + have hIF : (I.map (algebraMap (MvPolynomial (Fin h) B) + (MvPolynomial (Fin h) F))).map (algebraMap _ (Localization.AtPrime q)) = JF := by + dsimp only [I] + rw [Ideal.map_span, Ideal.map_span, ← Set.range_comp, ← Set.range_comp] + rfl + have hlength := quotient_length_congr_ideal _ _ hI + have hdimension := quotient_finrank_congr_ideal (K := F) _ _ hIF + calc + _ = Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap _ (Localization.AtPrime p))) * + (Module.finrank B (MvPolynomial (Fin h) B ⧸ p) : ℕ∞) := by rw [hlength] + _ = (Module.finrank F (Localization.AtPrime q ⧸ + (I.map (algebraMap (MvPolynomial (Fin h) B) (MvPolynomial (Fin h) F))).map + (algebraMap _ (Localization.AtPrime q))) : ℕ∞) := he.symm + _ = (Module.finrank F (Localization.AtPrime q ⧸ JF) : ℕ∞) := by rw [hdimension] + _ ≤ (D ^ h : ℕ) := by exact_mod_cast hn + +theorem linear_normalization_weighted_local_length_le + {K σ : Type*} [Field K] [Finite σ] {s h D : ℕ} + (P : Ideal (MvPolynomial σ K)) [P.IsPrime] + (g : MvPolynomial (Fin s) K →ₐ[K] (MvPolynomial σ K ⧸ P)) + (hg : Function.Injective g) + (hfinite : letI := g.toAlgebra + letI : Module (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ P) := Algebra.toModule + Module.Finite (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ P)) + (hlin : ∀ i, ∃ l : MvPolynomial σ K, + l.IsHomogeneous 1 ∧ g (MvPolynomial.X i) = Ideal.Quotient.mk P l) + (hcount : s + h = Nat.card σ) + (f : Fin h → MvPolynomial σ K) + (hf : ∀ i, (f i).totalDegree ≤ D) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime P) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime P)) : + letI := g.toAlgebra + letI : Module (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ P) := Algebra.toModule + Module.length (Localization.AtPrime P) + (Localization.AtPrime P ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime P) (f i)))) * + (Module.finrank (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ P) : ℕ∞) ≤ + (D ^ h : ℕ) := by + let := g.toAlgebra + let : Module (MvPolynomial (Fin s) K) (MvPolynomial σ K ⧸ P) := Algebra.toModule + obtain ⟨e, he, _, heinv, _, _⟩ := + exists_normalization_linear_coordinates_of_count P g hg hlin hcount + let p := P.comap (normalizationPresentation e).symm.toRingHom + let : p.IsPrime := Ideal.IsPrime.comap _ + have hp : p.comap MvPolynomial.C = ⊥ := + normalizationPresentation_coefficient_comap_eq_bot e P g hg he + let : Module.Finite (MvPolynomial (Fin s) K) + (MvPolynomial (Fin h) (MvPolynomial (Fin s) K) ⧸ p) := + finite_normalizationPresentation_quotient e P g he hfinite + have hdeg (i : Fin h) : + (MvPolynomial.map (algebraMap (MvPolynomial (Fin s) K) + (FractionRing (MvPolynomial (Fin s) K))) + (normalizationPresentation e (f i))).totalDegree ≤ D := + (totalDegree_localized_normalizationPresentation_le e (f i)).trans + ((heinv (f i)).le.trans (hf i)) + have hrad' := normalizationPresentation_radical_eq_maximal e P f hrad + have hn := coefficient_localization_weighted_length_le_pow + (F := FractionRing (MvPolynomial (Fin s) K)) h D p hp + (fun i => normalizationPresentation e (f i)) hdeg hrad' + have hlength := quotient_length_eq_of_commuting_images + (normalizationPresentationLocalEquiv e P).toRingEquiv + (fun i => algebraMap (MvPolynomial σ K) (Localization.AtPrime P) (f i)) + (fun i => algebraMap _ (Localization.AtPrime p) (normalizationPresentation e (f i))) + (fun i => normalizationPresentationLocalEquiv_algebraMap e P (f i)) + have hrank := (normalizationPresentationQuotientEquiv e P g he).toLinearEquiv.finrank_eq + rw [hlength, ← hrank] + exact hn + +end WeightedTorusJets.Geometry.DegreeBezout + +end +end +end +end +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalFractionAlgebra.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalFractionAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..e50dde92a1ca91e159213e9a111e0cbdbf802ae9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalFractionAlgebra.lean @@ -0,0 +1,521 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.HomogeneousDeformation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section +noncomputable section +open scoped BigOperators DirectSum +open MvPolynomial +namespace WeightedTorusJets + +open MvPolynomial + +theorem generic_homogeneous_deformation_quotient_bound + {σ K : Type*} [Fintype σ] [Field K] + (f : σ → MvPolynomial σ K) (d : ℕ) : + Module.Finite (RatFunc K) + (MvPolynomial σ (RatFunc K) ⧸ Ideal.span (Set.range (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) (homogeneousDeformation f d i)))) ∧ + Module.finrank (RatFunc K) + (MvPolynomial σ (RatFunc K) ⧸ Ideal.span (Set.range (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) (homogeneousDeformation f d i)))) ≤ + d ^ Fintype.card σ := by + classical + have h := Geometry.quotient_finrank_le_prod_of_homogeneous_image_le_rectangular + (L := K) + (Ideal.span (Set.range (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) (homogeneousDeformation f d i)))) + (fun _ : σ => d) (fun n => by + exact finrank_degreePiece_deformed_le_pure_powers f d n) + simpa only [Finset.prod_const, Finset.card_univ] using h + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem exists_lift_of_mem_leadingFormIdeal {ι σ K : Type*} [Fintype ι] [CommRing K] + (f : ι → MvPolynomial σ K) (D : ℕ) (hf : ∀ i, (f i).totalDegree ≤ D) + (p : MvPolynomial σ K) (n : ℕ) (hp : p.IsHomogeneous n) + (hmem : p ∈ Ideal.span (Set.range fun i => homogeneousComponent D (f i))) : + ∃ q ∈ Ideal.span (Set.range f), q.totalDegree ≤ n ∧ homogeneousComponent n q = p := by + classical + obtain ⟨a, ha⟩ := (Submodule.mem_span_range_iff_exists_fun (MvPolynomial σ K)).mp hmem + have ha : ∑ i, a i * homogeneousComponent D (f i) = p := by + simpa only [smul_eq_mul] using ha + by_cases hDn : D ≤ n + · have hright (i : ι) : homogeneousComponent n (a i * homogeneousComponent D (f i)) = + homogeneousComponent (n - D) (a i) * homogeneousComponent D (f i) := by + rw [mul_comm (a i), GradedQuotient.homogeneousComponent_mul_of_le + (homogeneousComponent_isHomogeneous D (f i)) hDn, mul_comm] + have hleft (i : ι) : homogeneousComponent n (homogeneousComponent (n - D) (a i) * f i) = + homogeneousComponent (n - D) (a i) * homogeneousComponent D (f i) := by + rw [GradedQuotient.homogeneousComponent_mul_of_le + (homogeneousComponent_isHomogeneous (n - D) (a i)) (Nat.sub_le n D), + Nat.sub_sub_self hDn] + have he : ∑ i, homogeneousComponent (n - D) (a i) * homogeneousComponent D (f i) = p := by + simpa only [map_sum, hright, homogeneousComponent_eq_self hp] using + congrArg (homogeneousComponent n) ha + refine ⟨∑ i, homogeneousComponent (n - D) (a i) * f i, ?_, ?_, ?_⟩ + · exact Ideal.sum_mem _ fun i _ => Ideal.mul_mem_left _ _ (Ideal.subset_span ⟨i, rfl⟩) + · exact totalDegree_finsetSum_le fun i _ => (totalDegree_mul _ _).trans + ((Nat.add_le_add (homogeneousComponent_isHomogeneous (n - D) (a i)).totalDegree_le + (hf i)).trans_eq (Nat.sub_add_cancel hDn)) + · simpa only [map_sum, hleft] using he + · have hz (i : ι) : homogeneousComponent n (a i * homogeneousComponent D (f i)) = 0 := by + rw [mul_comm, GradedQuotient.homogeneousComponent_mul_of_lt + (homogeneousComponent_isHomogeneous D (f i)) (Nat.lt_of_not_ge hDn)] + have he : p = 0 := by + have h := congrArg (homogeneousComponent n) ha + simpa only [map_sum, hz, Finset.sum_const_zero, homogeneousComponent_eq_self hp] using h.symm + exact ⟨0, Ideal.zero_mem _, by simp, by simp [he]⟩ + +theorem homogeneousComponent_mem_leadingFormIdeal {ι σ K : Type*} [CommRing K] + (f : ι → MvPolynomial σ K) (D : ℕ) (p : MvPolynomial σ K) + (hp : p ∈ Ideal.span (Set.range fun i => homogeneousComponent D (f i))) (n : ℕ) : + homogeneousComponent n p ∈ Ideal.span (Set.range fun i => homogeneousComponent D (f i)) := by + let : GradedAlgebra (homogeneousSubmodule σ K) := MvPolynomial.gradedAlgebra + apply homogeneousComponent_mem_of_mem _ hp n + apply Ideal.homogeneous_span + rintro g ⟨i, rfl⟩ + exact ⟨D, homogeneousComponent_isHomogeneous D (f i)⟩ + +theorem eq_zero_or_totalDegree_lt_of_homogeneousComponent_eq_zero {σ K : Type*} [CommRing K] + (p : MvPolynomial σ K) (n : ℕ) (hp : p.totalDegree ≤ n) + (hn : homogeneousComponent n p = 0) : p = 0 ∨ p.totalDegree < n := by + classical + by_cases hn0 : n = 0 + · left + subst n + have hhom : p.IsHomogeneous 0 := + (totalDegree_zero_iff_isHomogeneous σ).mp (Nat.eq_zero_of_le_zero hp) + simpa only [homogeneousComponent_eq_self hhom] using hn + · right + rw [totalDegree, Finset.sup_lt_iff (Nat.pos_of_ne_zero hn0)] + intro d hd + have hdle : d.degree ≤ n := (le_totalDegree hd).trans hp + apply lt_of_le_of_ne hdle + intro he + have hz := congrArg (fun q : MvPolynomial σ K => q.coeff d) hn + have hdne := mem_support_iff.mp hd + exact hdne (by simpa [coeff_homogeneousComponent, he] using hz) + +theorem representatives_of_homogeneous_lifts {σ K : Type*} [CommRing K] + (I J : Ideal (MvPolynomial σ K)) (S : Submodule K (MvPolynomial σ K)) + (hS : ∀ p ∈ S, ∀ n, homogeneousComponent n p ∈ S) + (hJ : ∀ p ∈ J, ∀ n, homogeneousComponent n p ∈ J) + (hlift : ∀ (p : MvPolynomial σ K) (n : ℕ), p.IsHomogeneous n → p ∈ J → + ∃ q ∈ I, q.totalDegree ≤ n ∧ homogeneousComponent n q = p) + (hrep : ∀ p : MvPolynomial σ K, ∃ s ∈ S, p - s ∈ J) : + ∀ p : MvPolynomial σ K, ∃ s ∈ S, p - s ∈ I := by + have H : ∀ n : ℕ, ∀ p : MvPolynomial σ K, p.totalDegree ≤ n → + ∃ s ∈ S, p - s ∈ I := by + intro n + induction n using Nat.strong_induction_on with + | h n ih => + intro p hp + obtain ⟨s, hs, hps⟩ := hrep (homogeneousComponent n p) + let t := homogeneousComponent n s + have htS : t ∈ S := hS s hs n + have htHom : t.IsHomogeneous n := homogeneousComponent_isHomogeneous n s + have hptHom : (homogeneousComponent n p - t).IsHomogeneous n := + (homogeneousComponent_isHomogeneous n p).sub htHom + have hptJ : homogeneousComponent n p - t ∈ J := by + simpa only [map_sub, + homogeneousComponent_eq_self (homogeneousComponent_isHomogeneous n p)] using hJ _ hps n + obtain ⟨q, hqI, hqdeg, hqtop⟩ := hlift _ n hptHom hptJ + let r := p - t - q + have hrdeg : r.totalDegree ≤ n := + (totalDegree_sub _ _).trans (max_le + ((totalDegree_sub _ _).trans (max_le hp htHom.totalDegree_le)) hqdeg) + have hrtop : homogeneousComponent n r = 0 := by + simp only [r, map_sub, homogeneousComponent_eq_self htHom, hqtop, sub_self] + rcases eq_zero_or_totalDegree_lt_of_homogeneousComponent_eq_zero r n hrdeg hrtop with hr | hr + · refine ⟨t, htS, ?_⟩ + have he : p - t = q := sub_eq_zero.mp hr + rwa [he] + · obtain ⟨u, huS, hruI⟩ := ih r.totalDegree hr r le_rfl + refine ⟨t + u, S.add_mem htS huS, ?_⟩ + have he : p - (t + u) = (r - u) + q := by dsimp [r]; abel + rw [he] + exact I.add_mem hruI hqI + intro p + exact H p.totalDegree p le_rfl + +end WeightedTorusJets.Geometry + +open Module + +namespace WeightedTorusJets + +theorem exists_monomial_basis_quotient + {K σ : Type*} [Field K] (J : Ideal (MvPolynomial σ K)) + [Module.Finite K (MvPolynomial σ K ⧸ J)] : + ∃ m : Fin (finrank K (MvPolynomial σ K ⧸ J)) → (σ →₀ ℕ), + LinearIndependent K (fun i => Ideal.Quotient.mk J (MvPolynomial.monomial (m i) 1)) ∧ + Submodule.span K (Set.range fun i => + Ideal.Quotient.mk J (MvPolynomial.monomial (m i) 1)) = ⊤ := by + classical + let v := fun m : σ →₀ ℕ => Ideal.Quotient.mk J (MvPolynomial.monomial m 1) + let f := (Ideal.Quotient.mkₐ K J).toLinearMap + have hspan : Submodule.span K (Set.range v) = ⊤ := by + have h := congrArg (Submodule.map f) (MvPolynomial.basisMonomials σ K).span_eq + rw [Submodule.map_span, Submodule.map_top, + LinearMap.range_eq_top.mpr (Ideal.Quotient.mkₐ_surjective K J)] at h + simpa [← Set.range_comp, MvPolynomial.coe_basisMonomials, Function.comp_def, f, v] using h + obtain ⟨b, hb, hbspan, hblin⟩ := + Submodule.exists_fun_fin_finrank_span_eq K (Set.range v) + choose m hm using hb + have hdim : finrank K (Submodule.span K (Set.range v)) = + finrank K (MvPolynomial σ K ⧸ J) := by rw [hspan, finrank_top] + let e := finCongr hdim.symm + have hrows : (fun i => v (m (e i))) = b ∘ e := by + funext i + exact hm (e i) + refine ⟨m ∘ e, ?_, ?_⟩ + · change LinearIndependent K (fun i => v (m (e i))) + rw [hrows] + exact hblin.comp e e.injective + · change Submodule.span K (Set.range fun i => v (m (e i))) = ⊤ + rw [hrows, e.surjective.range_comp, hbspan, hspan] + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +theorem homogeneousComponent_mem_span_monomials {τ σ K : Type*} [CommRing K] + (m : τ → (σ →₀ ℕ)) (p : MvPolynomial σ K) + (hp : p ∈ Submodule.span K (Set.range fun i => monomial (m i) (1 : K))) (n : ℕ) : + homogeneousComponent n p ∈ Submodule.span K (Set.range fun i => monomial (m i) (1 : K)) := by + classical + induction hp using Submodule.span_induction with + | mem p hp => + obtain ⟨i, rfl⟩ := hp + rw [homogeneousComponent_of_mem (isHomogeneous_monomial (1 : K) rfl)] + split_ifs + · exact Submodule.subset_span ⟨i, rfl⟩ + · exact Submodule.zero_mem _ + | zero => simpa only [map_zero] using (Submodule.zero_mem _) + | add p q hp hq hp' hq' => simpa only [map_add] using Submodule.add_mem _ hp' hq' + | smul c p hp hp' => simpa only [map_smul] using Submodule.smul_mem _ c hp' + +theorem quotient_span_eq_top_iff_representatives {τ σ K : Type*} [CommRing K] + (J : Ideal (MvPolynomial σ K)) (v : τ → MvPolynomial σ K) : + Submodule.span K (Set.range fun i => Ideal.Quotient.mk J (v i)) = ⊤ ↔ + ∀ p : MvPolynomial σ K, + ∃ s ∈ Submodule.span K (Set.range v), p - s ∈ J := by + let L := (Ideal.Quotient.mkₐ K J).toLinearMap + have hmap : (Submodule.span K (Set.range v)).map L = + Submodule.span K (Set.range fun i => Ideal.Quotient.mk J (v i)) := by + rw [Submodule.map_span, ← Set.range_comp] + rfl + rw [← hmap] + constructor + · intro h p + have hp : L p ∈ (Submodule.span K (Set.range v)).map L := by rw [h]; exact Submodule.mem_top + obtain ⟨s, hs, he⟩ := Submodule.mem_map.mp hp + exact ⟨s, hs, Ideal.Quotient.eq.mp he.symm⟩ + · intro h + apply top_unique + intro x _ + obtain ⟨p, rfl⟩ := Ideal.Quotient.mk_surjective x + obtain ⟨s, hs, he⟩ := h p + exact Submodule.mem_map.mpr ⟨s, hs, (Ideal.Quotient.eq.mpr he).symm⟩ + +theorem finite_and_finrank_le_leadingFormQuotient {ι σ K : Type*} [Fintype ι] [Field K] + (f : ι → MvPolynomial σ K) (D : ℕ) (hf : ∀ i, (f i).totalDegree ≤ D) + [Module.Finite K (MvPolynomial σ K ⧸ + Ideal.span (Set.range fun i => homogeneousComponent D (f i)))] : + Module.Finite K (MvPolynomial σ K ⧸ Ideal.span (Set.range f)) ∧ + Module.finrank K (MvPolynomial σ K ⧸ Ideal.span (Set.range f)) ≤ + Module.finrank K (MvPolynomial σ K ⧸ + Ideal.span (Set.range fun i => homogeneousComponent D (f i))) := by + classical + let J := Ideal.span (Set.range fun i => homogeneousComponent D (f i)) + obtain ⟨m, _, hmspan⟩ := WeightedTorusJets.exists_monomial_basis_quotient J + have hrepJ := (quotient_span_eq_top_iff_representatives J + (fun i => monomial (m i) (1 : K))).mp hmspan + have hrepI := representatives_of_homogeneous_lifts (Ideal.span (Set.range f)) J + (Submodule.span K (Set.range fun i => monomial (m i) (1 : K))) + (homogeneousComponent_mem_span_monomials m) + (homogeneousComponent_mem_leadingFormIdeal f D) + (exists_lift_of_mem_leadingFormIdeal f D hf) hrepJ + have hspanI := (quotient_span_eq_top_iff_representatives (Ideal.span (Set.range f)) + (fun i => monomial (m i) (1 : K))).mpr hrepI + refine ⟨Module.Finite.of_fg_top ?_, ?_⟩ + · rw [← hspanI] + exact Submodule.fg_span (Set.finite_range _) + · simpa only [Fintype.card_fin] using finrank_le_of_span_eq_top hspanI + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +open MvPolynomial + +theorem polynomialDeformation_totalDegree_le {σ R : Type*} [CommRing R] + (f : σ → MvPolynomial σ R) (d : ℕ) (hf : ∀ i, (f i).totalDegree ≤ d) + (i : σ) : (polynomialDeformation f d i).totalDegree ≤ d := by + have hmap : (map Polynomial.C (f i)).totalDegree ≤ (f i).totalDegree := + Finset.sup_mono (support_map_subset _ _) + unfold polynomialDeformation + refine (totalDegree_add _ _).trans (max_le ?_ ?_) + · refine (totalDegree_mul _ _).trans ?_ + simpa only [totalDegree_C, zero_add] using hmap.trans (hf i) + · refine (totalDegree_mul _ _).trans ?_ + simpa only [totalDegree_C, zero_add] using + (isHomogeneous_X_pow (R := Polynomial R) i d).totalDegree_le + +theorem map_polynomialDeformation_totalDegree_le {σ R S : Type*} + [CommRing R] [CommRing S] (φ : Polynomial R →+* S) + (f : σ → MvPolynomial σ R) (d : ℕ) (hf : ∀ i, (f i).totalDegree ≤ d) + (i : σ) : (map φ (polynomialDeformation f d i)).totalDegree ≤ d := by + exact (Finset.sup_mono (support_map_subset _ _)).trans + (polynomialDeformation_totalDegree_le f d hf i) + +end WeightedTorusJets + +namespace WeightedTorusJets + +open MvPolynomial + +theorem generic_affine_deformation_quotient_bound + {σ K : Type*} [Fintype σ] [Field K] + (f : σ → MvPolynomial σ K) (d : ℕ) (hf : ∀ i, (f i).totalDegree ≤ d) : + Module.Finite (RatFunc K) + (MvPolynomial σ (RatFunc K) ⧸ Ideal.span (Set.range (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) (polynomialDeformation f d i)))) ∧ + Module.finrank (RatFunc K) + (MvPolynomial σ (RatFunc K) ⧸ Ideal.span (Set.range (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) (polynomialDeformation f d i)))) ≤ + d ^ Fintype.card σ := by + have htop (i : σ) : + homogeneousComponent d + (map (algebraMap (Polynomial K) (RatFunc K)) (polynomialDeformation f d i)) = + map (algebraMap (Polynomial K) (RatFunc K)) (homogeneousDeformation f d i) := by + rw [homogeneousDeformation, map_homogeneousComponent] + have hIdeals := congrArg + (fun g : σ → MvPolynomial σ (RatFunc K) => Ideal.span (Set.range g)) (funext htop) + let e := (Ideal.quotientEquivAlgOfEq (RatFunc K) hIdeals).toLinearEquiv + obtain ⟨hfinite, hbound⟩ := generic_homogeneous_deformation_quotient_bound f d + let : Module.Finite (RatFunc K) + (MvPolynomial σ (RatFunc K) ⧸ Ideal.span (Set.range (fun i => + map (algebraMap (Polynomial K) (RatFunc K)) (homogeneousDeformation f d i)))) := hfinite + let : Module.Finite (RatFunc K) + (MvPolynomial σ (RatFunc K) ⧸ Ideal.span (Set.range (fun i => + homogeneousComponent d + (map (algebraMap (Polynomial K) (RatFunc K)) (polynomialDeformation f d i))))) := + Module.Finite.equiv e.symm + have h := Geometry.finite_and_finrank_le_leadingFormQuotient + (fun i => map (algebraMap (Polynomial K) (RatFunc K)) (polynomialDeformation f d i)) d + (map_polynomialDeformation_totalDegree_le _ f d hf) + exact ⟨h.1, h.2.trans (e.finrank_eq.trans_le hbound)⟩ + +end WeightedTorusJets + +end + +section + +namespace WeightedTorusJets.Geometry + +variable {K : Type*} [Field K] + +theorem maximal_polynomial_height (n : ℕ) + (p : Ideal (MvPolynomial (Fin n) K)) [p.IsMaximal] : p.height = n := by + induction n with + | zero => + have h := p.height_le_ringKrullDim_of_ne_top Ideal.IsPrime.ne_top' + have h0 : p.height ≤ 0 := WithBot.coe_le_coe.mp (by simpa using h) + exact le_antisymm h0 bot_le + | succ n ih => + let e := (MvPolynomial.finSuccEquiv K n).toRingEquiv + let P : Ideal (Polynomial (MvPolynomial (Fin n) K)) := p.map e + have : P.IsMaximal := Ideal.map_isMaximal_of_equiv e + let q : Ideal (MvPolynomial (Fin n) K) := P.comap Polynomial.C + have : q.IsMaximal := Polynomial.isMaximal_comap_C_of_isJacobsonRing P + have : P.LiesOver q := ⟨rfl⟩ + have hq : q.height = n := ih q + calc + p.height = P.height := (e.height_map p).symm + _ = q.height + 1 := Polynomial.height_eq_height_add_one q P + _ = (n + 1 : ℕ) := by rw [hq]; simp + +end WeightedTorusJets.Geometry + +end + +section + +namespace WeightedTorusJets.Deformation + +@[instance_reducible] noncomputable def localFractionAlgebra + {R F : Type*} [CommRing R] [Field F] + [Algebra R F] [IsFractionRing R F] (p : Ideal R) [p.IsPrime] : + Algebra (Localization.AtPrime p) F := + (IsLocalization.lift (S := Localization.AtPrime p) (g := algebraMap R F) + (fun s : p.primeCompl => isUnit_iff_ne_zero.mpr (by + apply (map_ne_zero_iff (algebraMap R F) (IsFractionRing.injective R F)).mpr + intro hs + exact s.property (hs ▸ p.zero_mem)))).toAlgebra + +theorem localFractionAlgebra_isScalarTower + {R F : Type*} [CommRing R] [Field F] + [Algebra R F] [IsFractionRing R F] (p : Ideal R) [p.IsPrime] : + let := localFractionAlgebra (F := F) p + IsScalarTower R (Localization.AtPrime p) F := by + let := localFractionAlgebra (F := F) p + apply IsScalarTower.of_algebraMap_eq + intro r + change algebraMap R F r = IsLocalization.lift _ (algebraMap R (Localization.AtPrime p) r) + rw [IsLocalization.lift_eq] + +theorem localFractionAlgebra_isFractionRing + {R F : Type*} [CommRing R] [IsDomain R] [Field F] + [Algebra R F] [IsFractionRing R F] (p : Ideal R) [p.IsPrime] : + let := localFractionAlgebra (F := F) p + IsFractionRing (Localization.AtPrime p) F := by + let := localFractionAlgebra (F := F) p + have := localFractionAlgebra_isScalarTower (F := F) p + exact IsFractionRing.isFractionRing_of_isDomain_of_isLocalization p.primeCompl + (Localization.AtPrime p) F + +end WeightedTorusJets.Deformation + +end + +section + +open TensorProduct + +namespace WeightedTorusJets.Deformation + +theorem surjective_baseChange_localization + {R F Q B : Type*} [CommRing R] [Field F] [Algebra R F] + [CommRing Q] [Algebra R Q] [CommRing B] [Algebra R B] + [Algebra Q B] [IsScalarTower R Q B] + (M : Submonoid Q) [IsLocalization M B] + [Module.Finite F (F ⊗[R] Q)] : + Function.Surjective + (Algebra.TensorProduct.map (AlgHom.id R F) (IsScalarTower.toAlgHom R Q B)) := by + let G := F ⊗[R] Q + let L := F ⊗[R] B + let : Algebra G L := + (Algebra.TensorProduct.map (AlgHom.id R F) (IsScalarTower.toAlgHom R Q B)).toAlgebra + have : IsScalarTower F G L := + .of_algebraMap_eq (by intro x; simp [G, L, RingHom.algebraMap_toAlgebra]) + have : IsLocalization + (M.map (Algebra.TensorProduct.includeRight (R := R) (A := F))) L := + IsLocalization.tensorProduct_tensorProduct_right R F M B + (by ext; simp [RingHom.algebraMap_toAlgebra]) + have : IsArtinianRing G := isArtinian_of_tower F (inferInstance : IsArtinian F G) + exact IsArtinianRing.localization_surjective + (M.map (Algebra.TensorProduct.includeRight (R := R) (A := F))) L + +theorem surjective_baseChange_localized_quotient + {R F P S : Type*} [CommRing R] [Field F] [Algebra R F] + [CommRing P] [Algebra R P] [CommRing S] [Algebra R S] + [Algebra P S] [IsScalarTower R P S] + (M : Submonoid P) [IsLocalization M S] (I : Ideal P) + [Module.Finite F (F ⊗[R] (P ⧸ I))] : + Function.Surjective (Algebra.TensorProduct.map (AlgHom.id R F) + (Ideal.quotientMapₐ (I.map (algebraMap P S)) + (IsScalarTower.toAlgHom R P S) Ideal.le_comap_map)) := by + have : IsScalarTower R (P ⧸ I) (S ⧸ I.map (algebraMap P S)) := + .of_algebraMap_eq (by + intro r + change Ideal.Quotient.mk _ (algebraMap R S r) = + Ideal.Quotient.mk _ (algebraMap P S (algebraMap R P r)) + rw [IsScalarTower.algebraMap_apply R P S]) + exact surjective_baseChange_localization (R := R) (F := F) + (B := S ⧸ I.map (algebraMap P S)) (Algebra.algebraMapSubmonoid (P ⧸ I) M) + +noncomputable def genericFiberLocalBaseEquiv + {R A F B : Type*} [CommRing R] [CommRing A] [Algebra R A] + (M : Submonoid R) [IsLocalization M A] + [Field F] [Algebra R F] [Algebra A F] [IsScalarTower R A F] + [CommRing B] [Algebra R B] [Algebra A B] [IsScalarTower R A B] : + (F ⊗[A] B) ≃ₐ[F] (F ⊗[R] B) := by + have := IsLocalization.tensorProduct_compatibleSMul M A F B + exact Algebra.TensorProduct.equivOfCompatibleSMul R A F F B + +end WeightedTorusJets.Deformation + +open TensorProduct + +namespace WeightedTorusJets.Deformation + +variable {R A σ ι : Type*} [CommRing R] [CommRing A] [Algebra R A] + +noncomputable def mvPolynomialQuotientBaseChange (I : Ideal (MvPolynomial σ R)) : + A ⊗[R] (MvPolynomial σ R ⧸ I) ≃ₐ[A] + MvPolynomial σ A ⧸ I.map (MvPolynomial.map (algebraMap R A)) := by + refine (Algebra.TensorProduct.tensorQuotientEquiv A (MvPolynomial σ R) A I).trans + (Ideal.quotientEquivAlg _ _ (MvPolynomial.algebraTensorAlgEquiv R A) ?_) + change I.map (MvPolynomial.map (algebraMap R A)) = + (I.map (Algebra.TensorProduct.includeRight (R := R) (A := A) + (B := MvPolynomial σ R)).toRingHom).map + (MvPolynomial.algebraTensorAlgEquiv R A).toRingHom + rw [Ideal.map_map] + congr 1 + apply RingHom.ext + intro p + simp + +@[simp] +theorem mvPolynomialQuotientBaseChange_tmul_mk + (I : Ideal (MvPolynomial σ R)) (a : A) (p : MvPolynomial σ R) : + mvPolynomialQuotientBaseChange (A := A) I (a ⊗ₜ[R] Ideal.Quotient.mk I p) = + a • Ideal.Quotient.mk _ (MvPolynomial.map (algebraMap R A) p) := by + simp only [mvPolynomialQuotientBaseChange, AlgEquiv.trans_apply, + Algebra.TensorProduct.tensorQuotientEquiv_apply_tmul, Ideal.quotientEquivAlg_mk, + MvPolynomial.algebraTensorAlgEquiv_tmul] + exact (Ideal.Quotient.mkₐ A _).toLinearMap.map_smul a _ + +noncomputable def mvPolynomialSpanQuotientBaseChange (f : ι → MvPolynomial σ R) : + A ⊗[R] (MvPolynomial σ R ⧸ Ideal.span (Set.range f)) ≃ₐ[A] + MvPolynomial σ A ⧸ Ideal.span + (Set.range (fun i => MvPolynomial.map (algebraMap R A) (f i))) := + (mvPolynomialQuotientBaseChange (A := A) (Ideal.span (Set.range f))).trans + (Ideal.quotientEquivAlgOfEq A (by rw [Ideal.map_span, ← Set.range_comp'])) + +@[simp] +theorem mvPolynomialSpanQuotientBaseChange_tmul_mk + (f : ι → MvPolynomial σ R) (a : A) (p : MvPolynomial σ R) : + mvPolynomialSpanQuotientBaseChange (A := A) f + (a ⊗ₜ[R] Ideal.Quotient.mk (Ideal.span (Set.range f)) p) = + a • Ideal.Quotient.mk _ (MvPolynomial.map (algebraMap R A) p) := by + simp [mvPolynomialSpanQuotientBaseChange] + +@[simp] +theorem mvPolynomialSpanQuotientBaseChange_symm_mk_map + (f : ι → MvPolynomial σ R) (p : MvPolynomial σ R) : + (mvPolynomialSpanQuotientBaseChange (A := A) f).symm + (Ideal.Quotient.mk _ (MvPolynomial.map (algebraMap R A) p)) = + 1 ⊗ₜ[R] Ideal.Quotient.mk (Ideal.span (Set.range f)) p := by + apply (mvPolynomialSpanQuotientBaseChange (A := A) f).injective + simp + +end WeightedTorusJets.Deformation + +end +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalLengthMulProjectiveClosureDegree.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalLengthMulProjectiveClosureDegree.lean new file mode 100644 index 0000000000000000000000000000000000000000..ae7d8368c60efa13c298e247e3a45a061619c95f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalLengthMulProjectiveClosureDegree.lean @@ -0,0 +1,96 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeMapEval +import OAI.NumberTheory.Jacobsthal.Siegel.FinrankDerivationCardTranscendenceBasis +import OAI.NumberTheory.Jacobsthal.Siegel.GradedIdealQuotient +import OAI.NumberTheory.Jacobsthal.Siegel.LinearVariableBasis + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +attribute [local instance] coneIdeal_isPrime + +theorem local_length_mul_projectiveClosure_degree_le + {K σ : Type*} [Field K] [Infinite K] [Finite σ] {h D : ℕ} + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (hp : p.height = h) + (f : Fin h → MvPolynomial σ K) + (hf : ∀ i, (f i).totalDegree ≤ D) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (f i)))) * + (GradedQuotient.projectiveDegree (coneIdeal p) (coneIdeal_isHomogeneous p) : ℕ∞) ≤ + (D ^ h : ℕ) := by + obtain ⟨d, _, g, hg, hint, hfinite, hlin, _, _⟩ := + LinearNormalization.exists_finite_linear_normalization_finite_variables + (coneIdeal p) (coneIdeal_isHomogeneous p) none (X_none_not_mem_coneIdeal p) + have hcount : d + 1 + h = Nat.card (Option σ) := by + have hc := polynomial_normalization_count_add_height_finite + (coneIdeal p) g hg hint + rw [coneIdeal_height, hp] at hc + exact_mod_cast hc + let F : Fin h → MvPolynomial (Option σ) K := fun i => homogenize (f i) + have hF (i : Fin h) : (F i).totalDegree ≤ D := by + simpa only [F, homogenize_totalDegree] using hf i + have hrad' : (Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p)) + (F i)))).radical = IsLocalRing.maximalIdeal (Localization.AtPrime (coneIdeal p)) := by + have ha : ((Ideal.span (Set.range f)).map + (algebraMap (MvPolynomial σ K) (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p) := by + simpa only [Ideal.map_span, ← Set.range_comp, Function.comp_def] using hrad + simpa only [paddedHomogenizedIdeal, pow_zero, one_mul, Ideal.map_span, + ← Set.range_comp, Function.comp_def, F] using + cone_padded_local_radical p f (fun _ => 0) ha + have hlength : + Module.length (Localization.AtPrime (coneIdeal p)) + (Localization.AtPrime (coneIdeal p) ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p)) + (F i)))) = + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (f i)))) := by + have hA : (Ideal.span (Set.range f)).map + (algebraMap (MvPolynomial σ K) (Localization.AtPrime p)) = + Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (f i))) := by + rw [Ideal.map_span, ← Set.range_comp] + rfl + have hC : (paddedHomogenizedIdeal f (fun _ => 0)).map + (algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p))) = + Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Option σ) K) (Localization.AtPrime (coneIdeal p)) + (F i))) := by + simp only [paddedHomogenizedIdeal, pow_zero, one_mul, Ideal.map_span, + ← Set.range_comp, Function.comp_def, F] + exact (DegreeBezout.quotient_length_congr_ideal _ _ hC).symm.trans + ((cone_padded_quotient_length p f (fun _ => 0)).trans + (DegreeBezout.quotient_length_congr_ideal _ _ hA)) + have hdegree := GradedQuotient.projectiveDegree_eq_normalization_rank_finiteVariables + (coneIdeal p) (coneIdeal_isHomogeneous p) g hg hint hlin + have hbound := DegreeBezout.linear_normalization_weighted_local_length_le + (coneIdeal p) g hg hfinite hlin hcount F hF hrad' + rw [hlength, ← hdegree] at hbound + exact hbound + +end WeightedTorusJets.Geometry + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalQuotientEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalQuotientEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..aee48fb1c6ce66725300245fdbd2775bca2fe503 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalQuotientEquiv.lean @@ -0,0 +1,521 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.MonicSMulRegularQuotientMapC + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open Polynomial +open Ideal RingTheory.Sequence IsLocalRing +open Ideal RingTheory.Sequence +open scoped Pointwise +open Ideal RingTheory.Sequence +open CategoryTheory Abelian +universe u +open scoped BigOperators +namespace WeightedTorusJets + +theorem isRegular_parameters_mvPolynomial_localization + (K : Type*) [Field K] (σ : Type*) [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (fs : List (Localization.AtPrime p)) + (hrad : (Ideal.ofList fs).radical = IsLocalRing.maximalIdeal (Localization.AtPrime p)) + (hlen : (fs.length : ℕ∞) = + (IsLocalRing.maximalIdeal (Localization.AtPrime p)).height) : + RingTheory.Sequence.IsRegular (Localization.AtPrime p) fs := by + exact isRegular_parameters_of_exists_regular_maximal_generators + (exists_regular_maximal_generators_mvPolynomial_localization K σ p) fs hrad hlen + +end WeightedTorusJets + +namespace WeightedTorusJets.Deformation + +theorem localRingHom_surjective_of_surjective + {R S : Type*} [CommRing R] [CommRing S] + (f : R →+* S) (hf : Function.Surjective f) (p : Ideal S) [p.IsPrime] : + Function.Surjective (Localization.localRingHom (p.comap f) p f rfl) := by + have : IsLocalization ((p.comap f).primeCompl.map f) (Localization.AtPrime p) := by + rw [p.map_primeCompl_comap_of_surjective f hf] + infer_instance + exact IsLocalization.map_surjective_of_surjective (p.comap f).primeCompl + (Localization.AtPrime (p.comap f)) (Localization.AtPrime p) (g := f) hf + +theorem ker_localRingHom_of_surjective + {R S : Type*} [CommRing R] [CommRing S] + (f : R →+* S) (hf : Function.Surjective f) (p : Ideal S) [p.IsPrime] : + RingHom.ker (Localization.localRingHom (p.comap f) p f rfl) = + (RingHom.ker f).map (algebraMap R (Localization.AtPrime (p.comap f))) := by + exact IsLocalization.ker_map (Localization.AtPrime p) f + (p.map_primeCompl_comap_of_surjective f hf) + +noncomputable def localQuotientEquiv + {R S : Type*} [CommRing R] [CommRing S] + (f : R →+* S) (hf : Function.Surjective f) (p : Ideal S) [p.IsPrime] : + (Localization.AtPrime (p.comap f) ⧸ + (RingHom.ker f).map (algebraMap R (Localization.AtPrime (p.comap f)))) ≃+* + Localization.AtPrime p := + (Ideal.quotEquivOfEq (ker_localRingHom_of_surjective f hf p).symm).trans + (RingHom.quotientKerEquivOfSurjective (localRingHom_surjective_of_surjective f hf p)) + +theorem localQuotientEquiv_apply_mk_algebraMap + {R S : Type*} [CommRing R] [CommRing S] + (f : R →+* S) (hf : Function.Surjective f) (p : Ideal S) [p.IsPrime] (x : R) : + localQuotientEquiv f hf p (Ideal.Quotient.mk _ + (algebraMap R (Localization.AtPrime (p.comap f)) x)) = + algebraMap S (Localization.AtPrime p) (f x) := by + simp only [localQuotientEquiv, RingEquiv.trans_apply, Ideal.quotEquivOfEq_mk, + RingHom.quotientKerEquivOfSurjective_apply_mk, Localization.localRingHom_to_map] + +noncomputable def localQuotientAlgEquiv + {K R S : Type*} [CommRing K] [CommRing R] [CommRing S] [Algebra K R] [Algebra K S] + (f : R →ₐ[K] S) (hf : Function.Surjective f) (p : Ideal S) [p.IsPrime] : + (Localization.AtPrime (p.comap f.toRingHom) ⧸ + (RingHom.ker f.toRingHom).map + (algebraMap R (Localization.AtPrime (p.comap f.toRingHom)))) ≃ₐ[K] + Localization.AtPrime p := + (Ideal.quotientEquivAlgOfEq K (ker_localRingHom_of_surjective f.toRingHom hf p).symm).trans + (Ideal.quotientKerAlgEquivOfSurjective + (f := Localization.localAlgHom (p.comap f.toRingHom) p f rfl) + (localRingHom_surjective_of_surjective f.toRingHom hf p)) + +theorem localQuotientAlgEquiv_apply_mk_algebraMap + {K R S : Type*} [CommRing K] [CommRing R] [CommRing S] [Algebra K R] [Algebra K S] + (f : R →ₐ[K] S) (hf : Function.Surjective f) (p : Ideal S) [p.IsPrime] (x : R) : + localQuotientAlgEquiv f hf p (Ideal.Quotient.mk _ + (algebraMap R (Localization.AtPrime (p.comap f.toRingHom)) x)) = + algebraMap S (Localization.AtPrime p) (f x) := by + exact localQuotientEquiv_apply_mk_algebraMap f.toRingHom hf p x + +open Polynomial + +theorem ker_mvPolynomial_evaluation + {R σ : Type*} [CommRing R] (a : R) : + RingHom.ker (MvPolynomial.map (σ := σ) (evalRingHom a) : + MvPolynomial σ R[X] →+* MvPolynomial σ R) = + Ideal.span {MvPolynomial.C (σ := σ) (X - C a)} := by + ext f + rw [RingHom.mem_ker, Ideal.mem_span_singleton] + exact (MvPolynomial.C_dvd_iff_map_hom_eq_zero (evalRingHom a) (X - C a) + (fun _ => dvd_iff_isRoot.symm) f).symm + +noncomputable def mvPolynomialLocalQuotientAlgEquiv + {R σ : Type*} [CommRing R] (p : Ideal (MvPolynomial σ R)) [p.IsPrime] (a : R) : + letI : CommRing (Localization.AtPrime + (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) := inferInstance + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a))) ⧸ + (Ideal.span {algebraMap (MvPolynomial σ R[X]) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) + (MvPolynomial.C (σ := σ) (X - C a))} : + Ideal (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))))) + ≃ₐ[R] Localization.AtPrime p := by + letI : CommRing (Localization.AtPrime + (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) := inferInstance + have h : (Ideal.span {algebraMap (MvPolynomial σ R[X]) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) + (MvPolynomial.C (σ := σ) (X - C a))} : + Ideal (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a))))) = + (RingHom.ker (MvPolynomial.map (σ := σ) (evalRingHom a))).map + (algebraMap (MvPolynomial σ R[X]) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a))))) := by + rw [ker_mvPolynomial_evaluation, Ideal.map_span] + simp + exact (Ideal.quotientEquivAlgOfEq R h).trans + (localQuotientAlgEquiv (MvPolynomial.mapAlgHom (aeval a)) + (MvPolynomial.map_surjective _ (fun r => ⟨C r, eval_C⟩)) p) + +theorem mvPolynomialLocalQuotientAlgEquiv_apply_mk_algebraMap + {R σ : Type*} [CommRing R] (p : Ideal (MvPolynomial σ R)) [p.IsPrime] (a : R) + (f : MvPolynomial σ R[X]) : + mvPolynomialLocalQuotientAlgEquiv p a (Ideal.Quotient.mk _ + (algebraMap (MvPolynomial σ R[X]) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) f)) = + algebraMap (MvPolynomial σ R) (Localization.AtPrime p) (MvPolynomial.map (evalRingHom a) f) := by + exact localQuotientAlgEquiv_apply_mk_algebraMap (MvPolynomial.mapAlgHom (aeval a)) + (MvPolynomial.map_surjective _ (fun r => ⟨C r, eval_C⟩)) p f + +end WeightedTorusJets.Deformation + +namespace WeightedTorusJets.Deformation + +noncomputable def quotientFamilySpecializationAlgEquiv + {K S R ι : Type*} [CommRing K] [CommRing S] [CommRing R] + [Algebra K S] [Algebra K R] + (J : Ideal S) (e : (S ⧸ J) ≃ₐ[K] R) + (f : ι → S) (g : ι → R) + (hfg : ∀ i, e (Ideal.Quotient.mk J (f i)) = g i) : + ((S ⧸ Ideal.span (Set.range f)) ⧸ + J.map (Ideal.Quotient.mk (Ideal.span (Set.range f)))) ≃ₐ[K] + R ⧸ Ideal.span (Set.range g) := by + refine (DoubleQuot.quotQuotEquivCommₐ K (Ideal.span (Set.range f)) J).trans + (Ideal.quotientEquivAlg _ _ e ?_) + change Ideal.span (Set.range g) = + ((Ideal.span (Set.range f)).map (Ideal.Quotient.mk J)).map e.toRingEquiv.toRingHom + rw [Ideal.map_map, Ideal.map_span] + congr 1 + ext x + simp only [Set.mem_range, Set.mem_image, RingHom.coe_comp, Function.comp_apply] + constructor + · rintro ⟨i, rfl⟩ + exact ⟨f i, ⟨i, rfl⟩, hfg i⟩ + · rintro ⟨_, ⟨i, rfl⟩, h⟩ + exact ⟨i, (hfg i).symm.trans h⟩ + +theorem isRegular_quotient_iff + {K S R : Type*} [CommRing K] [CommRing S] [CommRing R] + [Algebra K S] [Algebra K R] + (J : Ideal S) (e : (S ⧸ J) ≃ₐ[K] R) (fs : List S) : + RingTheory.Sequence.IsRegular (S ⧸ J) fs ↔ + RingTheory.Sequence.IsRegular R (fs.map (fun x => e (Ideal.Quotient.mk J x))) := by + apply e.toAddEquiv.isRegular_congr + apply List.forall₂_map_right_iff.mpr + apply List.forall₂_same.mpr + intro r _ x + change e ((Ideal.Quotient.mk J r) * x) = e (Ideal.Quotient.mk J r) * e x + exact e.map_mul _ _ + +theorem isRegular_quotSMulTop_iff + {K S R : Type*} [CommRing K] [CommRing S] [CommRing R] + [Algebra K S] [Algebra K R] + (t : S) (e : (S ⧸ Ideal.span {t}) ≃ₐ[K] R) (fs : List S) : + RingTheory.Sequence.IsRegular (QuotSMulTop t S) fs ↔ + RingTheory.Sequence.IsRegular R + (fs.map (fun x => e (Ideal.Quotient.mk (Ideal.span {t}) x))) := + ((QuotSMulTop.equivQuotTensor t S ≪≫ₗ TensorProduct.rid S (S ⧸ Ideal.span {t})).isRegular_congr fs).trans + (isRegular_quotient_iff (Ideal.span {t}) e fs) + + + +open Polynomial + +theorem isRegular_mvPolynomial_localized_special_fiber + {K σ : Type*} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (a : K) + (Fs : List (MvPolynomial σ K[X])) + (hrad : (Ideal.ofList (Fs.map (fun f => + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) + (MvPolynomial.map (evalRingHom a) f)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) + (hlen : (Fs.length : ℕ∞) = + (IsLocalRing.maximalIdeal (Localization.AtPrime p)).height) : + let S := Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a))) + let t : S := algebraMap (MvPolynomial σ K[X]) S + (MvPolynomial.C (σ := σ) (X - C a)) + RingTheory.Sequence.IsRegular (QuotSMulTop t S) + (Fs.map (algebraMap (MvPolynomial σ K[X]) S)) := by + let S := Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a))) + let : CommRing S := inferInstance + let t : S := algebraMap (MvPolynomial σ K[X]) S + (MvPolynomial.C (σ := σ) (X - C a)) + change RingTheory.Sequence.IsRegular (QuotSMulTop t S) + (Fs.map (algebraMap (MvPolynomial σ K[X]) S)) + let e : (S ⧸ Ideal.span {t}) ≃ₐ[K] Localization.AtPrime p := + mvPolynomialLocalQuotientAlgEquiv p a + apply (isRegular_quotSMulTop_iff (K := K) (S := S) (R := Localization.AtPrime p) + t e (Fs.map (algebraMap (MvPolynomial σ K[X]) S))).mpr + have hreg := WeightedTorusJets.isRegular_parameters_mvPolynomial_localization K σ p + (Fs.map (fun f => algebraMap (MvPolynomial σ K) (Localization.AtPrime p) + (MvPolynomial.map (evalRingHom a) f))) hrad (by simpa only [List.length_map] using hlen) + simpa only [List.map_map, Function.comp_def, e, t, S, + mvPolynomialLocalQuotientAlgEquiv_apply_mk_algebraMap] using hreg + +end WeightedTorusJets.Deformation + +namespace WeightedTorusJets +open MvPolynomial +variable {σ R : Type*} [CommRing R] + +noncomputable def polynomialDeformation (f : σ → MvPolynomial σ R) (d : ℕ) (i : σ) : + MvPolynomial σ (Polynomial R) := + MvPolynomial.C (1 - Polynomial.X) * MvPolynomial.map Polynomial.C (f i) + + MvPolynomial.C Polynomial.X * MvPolynomial.X i ^ d + +theorem polynomialDeformation_at_zero (f : σ → MvPolynomial σ R) (d : ℕ) (i : σ) : + MvPolynomial.map (Polynomial.evalRingHom 0) (polynomialDeformation f d i) = f i := by + have hcomp : (Polynomial.evalRingHom (0 : R)).comp Polynomial.C = RingHom.id R := by + ext r + simp + simp [polynomialDeformation, MvPolynomial.map_map, hcomp, MvPolynomial.map_id] + +end WeightedTorusJets + +namespace WeightedTorusJets.Deformation + +theorem isRegular_source_polynomialDeformation_special_fiber + {K σ : Type*} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : σ → MvPolynomial σ K) (d : ℕ) (is : List σ) + (hrad : (Ideal.ofList (is.map (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) + (hlen : (is.length : ℕ∞) = + (IsLocalRing.maximalIdeal (Localization.AtPrime p)).height) : + let S := Localization.AtPrime + (p.comap (MvPolynomial.map (σ := σ) (Polynomial.evalRingHom (0 : K)))) + let t : S := algebraMap (MvPolynomial σ (Polynomial K)) S + (MvPolynomial.C (σ := σ) (Polynomial.X - Polynomial.C (0 : K))) + RingTheory.Sequence.IsRegular (QuotSMulTop t S) + ((is.map (WeightedTorusJets.polynomialDeformation f d)).map + (algebraMap (MvPolynomial σ (Polynomial K)) S)) := by + exact isRegular_mvPolynomial_localized_special_fiber p 0 + (is.map (WeightedTorusJets.polynomialDeformation f d)) + (by simpa only [List.map_map, Function.comp_def, + WeightedTorusJets.polynomialDeformation_at_zero] using hrad) + (by simpa only [List.length_map] using hlen) + + + +open RingTheory.Sequence +open scoped Pointwise + +theorem parameter_regular_after_quotient + {R M : Type*} [CommRing R] [IsLocalRing R] + [AddCommGroup M] [Module R M] [IsNoetherian R M] + (t : R) (fs : List R) (ht : IsSMulRegular M t) + (hfs : RingTheory.Sequence.IsRegular (QuotSMulTop t M) fs) : + IsSMulRegular (M ⧸ (Ideal.ofList fs • ⊤ : Submodule R M)) t := by + have h : RingTheory.Sequence.IsRegular M (t :: fs) := IsRegular.cons ht hfs + have hp : List.Perm (t :: fs) (fs ++ [t]) := by + exact List.perm_append_comm (l₁ := [t]) (l₂ := fs) + have h' := IsLocalRing.isRegular_of_perm h hp + exact (isWeaklyRegular_singleton_iff _ _).mp + ((isWeaklyRegular_append_iff M fs [t]).mp h'.toIsWeaklyRegular).2 + +theorem flat_of_regular_uniformizer + {R M : Type*} [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] + [AddCommGroup M] [Module R M] + (t : R) (ht : Irreducible t) (hreg : IsSMulRegular M t) : Module.Flat R M := by + have : Module.IsTorsionFree R M := ⟨fun r hr => by + obtain ⟨n, h⟩ := IsDiscreteValuationRing.associated_pow_irreducible hr.ne_zero ht + obtain ⟨u, hu⟩ := h.symm + rw [← hu] + exact (hreg.pow n).mul (u.isSMulRegular M)⟩ + infer_instance + +theorem flat_quotient_of_regular_special_fiber + {A S M : Type*} [CommRing A] [IsDomain A] [IsDiscreteValuationRing A] + [CommRing S] [IsLocalRing S] [Algebra A S] + [AddCommGroup M] [Module S M] [Module A M] [IsScalarTower A S M] + [IsNoetherian S M] (t : A) (ht : Irreducible t) (fs : List S) + (hreg : IsSMulRegular M (algebraMap A S t)) + (hfs : RingTheory.Sequence.IsRegular (QuotSMulTop (algebraMap A S t) M) fs) : + Module.Flat A (M ⧸ (Ideal.ofList fs • ⊤ : Submodule S M)) := by + apply flat_of_regular_uniformizer t ht + exact (isSMulRegular_map (algebraMap A S) fun m => algebraMap_smul S t m).mp + (parameter_regular_after_quotient (algebraMap A S t) fs hreg hfs) + +end WeightedTorusJets.Deformation + +namespace WeightedTorusJets.Deformation + +open Polynomial + +theorem dvr_polynomial_at_linear + {K : Type*} [Field K] (I : Ideal K[X]) [I.IsPrime] + (a : K) (hI : I = Ideal.span {X - C a}) : + IsDiscreteValuationRing (Localization.AtPrime I) := by + apply IsLocalization.AtPrime.isDiscreteValuationRing_of_dedekind_domain K[X] (P := I) + rw [hI, ne_eq, Ideal.span_singleton_eq_bot] + exact (irreducible_X_sub_C a).ne_zero + +theorem irreducible_parameter_at_linear + {K : Type*} [Field K] (I : Ideal K[X]) [I.IsPrime] + (a : K) (hI : I = Ideal.span {X - C a}) : + Irreducible (algebraMap K[X] (Localization.AtPrime I) (X - C a)) := by + have : IsDiscreteValuationRing (Localization.AtPrime I) := dvr_polynomial_at_linear I a hI + apply (IsDiscreteValuationRing.irreducible_iff_uniformizer _).mpr + rw [← Localization.AtPrime.map_eq_maximalIdeal] + calc + Ideal.map (algebraMap K[X] (Localization.AtPrime I)) I = + Ideal.map (algebraMap K[X] (Localization.AtPrime I)) (Ideal.span {X - C a}) := + congrArg (Ideal.map (algebraMap K[X] (Localization.AtPrime I))) hI + _ = _ := by rw [Ideal.map_span]; simp + +noncomputable def residueFieldAtLinearAlgEquiv + {K : Type*} [Field K] (I : Ideal K[X]) [I.IsPrime] + (a : K) (hI : I = Ideal.span {X - C a}) : I.ResidueField ≃ₐ[K] K := by + have : I.IsMaximal := by + rw [hI] + exact PrincipalIdealRing.isMaximal_of_irreducible (irreducible_X_sub_C a) + exact (AlgEquiv.ofBijective (IsScalarTower.toAlgHom K (K[X] ⧸ I) I.ResidueField) + I.bijective_algebraMap_quotient_residueField).symm.trans + ((Ideal.quotientEquivAlgOfEq K hI).trans (quotientSpanXSubCAlgEquiv a)) + +end WeightedTorusJets.Deformation + +namespace WeightedTorusJets.Deformation + +open Polynomial + +theorem specialFiber_prime_comap_C + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (a : K) : + (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a))).comap MvPolynomial.C = + Ideal.span {X - C a} := by + ext f + rw [← ker_evalRingHom a] + change MvPolynomial.map (evalRingHom a) (MvPolynomial.C f) ∈ p ↔ f.eval a = 0 + rw [MvPolynomial.map_C, ← Ideal.Quotient.eq_zero_iff_mem] + let g : K →+* MvPolynomial σ K ⧸ p := (Ideal.Quotient.mk p).comp MvPolynomial.C + change g (f.eval a) = 0 ↔ f.eval a = 0 + exact map_eq_zero_iff g g.injective + +@[instance_reducible] noncomputable def parameterLocalAlgebra + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (I : Ideal K[X]) [I.IsPrime] (a : K) (hI : I = Ideal.span {X - C a}) : + Algebra (Localization.AtPrime I) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) := + (Localization.localRingHom I (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a))) + MvPolynomial.C (hI.trans (specialFiber_prime_comap_C p a).symm)).toAlgebra + +theorem parameterLocalAlgebra_isScalarTower + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (I : Ideal K[X]) [I.IsPrime] (a : K) (hI : I = Ideal.span {X - C a}) : + let := parameterLocalAlgebra p I a hI + IsScalarTower K[X] (Localization.AtPrime I) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) := by + let := parameterLocalAlgebra p I a hI + apply IsScalarTower.of_algebraMap_eq + intro f + change algebraMap K[X] _ f = + Localization.localRingHom I _ MvPolynomial.C _ (algebraMap K[X] _ f) + rw [Localization.localRingHom_to_map] + rfl + +theorem parameterLocalAlgebra_parameter + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (I : Ideal K[X]) [I.IsPrime] (a : K) (hI : I = Ideal.span {X - C a}) : + let := parameterLocalAlgebra p I a hI + algebraMap (Localization.AtPrime I) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) + (algebraMap K[X] (Localization.AtPrime I) (X - C a)) = + algebraMap (MvPolynomial σ K[X]) _ (MvPolynomial.C (X - C a)) := by + let := parameterLocalAlgebra p I a hI + exact Localization.localRingHom_to_map I _ MvPolynomial.C _ (X - C a) + +theorem parameterLocalAlgebra_groundFieldTower + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (I : Ideal K[X]) [I.IsPrime] (a : K) (hI : I = Ideal.span {X - C a}) : + letI := parameterLocalAlgebra p I a hI + IsScalarTower K (Localization.AtPrime I) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) := by + let := parameterLocalAlgebra p I a hI + have := parameterLocalAlgebra_isScalarTower p I a hI + exact IsScalarTower.to₁₃₄ K K[X] (Localization.AtPrime I) _ + +theorem localized_polynomial_parameter_ne_zero + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (a : K) : + algebraMap (MvPolynomial σ K[X]) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) + (MvPolynomial.C (X - C a)) ≠ 0 := by + intro h + have hC : MvPolynomial.C (σ := σ) (X - C a) = 0 := + (FaithfulSMul.algebraMap_injective (MvPolynomial σ K[X]) _) + (h.trans (map_zero _).symm) + exact X_sub_C_ne_zero a ((MvPolynomial.C_injective σ K[X]) + (hC.trans (map_zero _).symm)) + +theorem parameterLocalAlgebra_parameter_regular + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (I : Ideal K[X]) [I.IsPrime] (a : K) (hI : I = Ideal.span {X - C a}) : + letI := parameterLocalAlgebra p I a hI + IsSMulRegular + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) + (algebraMap (Localization.AtPrime I) + (Localization.AtPrime (p.comap (MvPolynomial.map (σ := σ) (evalRingHom a)))) + (algebraMap K[X] (Localization.AtPrime I) (X - C a))) := by + let := parameterLocalAlgebra p I a hI + rw [parameterLocalAlgebra_parameter] + exact IsSMulRegular.of_ne_zero (localized_polynomial_parameter_ne_zero p a) + +end WeightedTorusJets.Deformation + +namespace WeightedTorusJets.Deformation + +theorem flat_ideal_quotient_of_flat_smul_top + {A S : Type*} [CommRing A] [CommRing S] [Algebra A S] + (I : Ideal S) + (hflat : Module.Flat A (S ⧸ (I • ⊤ : Submodule S S))) : + Module.Flat A (S ⧸ I) := by + let := hflat + have hI : (I • ⊤ : Submodule S S) = I := by + rw [Ideal.smul_eq_mul, Ideal.mul_top] + exact Module.Flat.of_linearEquiv + (((Submodule.quotEquivOfEq _ _ hI).restrictScalars A).symm) + +theorem ideal_ofList_ofFn_eq_span_range + {S : Type*} [CommRing S] {n : ℕ} (f : Fin n → S) : + Ideal.ofList (List.ofFn f) = Ideal.span (Set.range f) := by + unfold Ideal.ofList + congr 1 + ext x + exact List.mem_ofFn' f x + +theorem ideal_ofList_map_finRange_eq_span_range + {S : Type*} [CommRing S] {n : ℕ} (f : Fin n → S) : + Ideal.ofList ((List.finRange n).map f) = Ideal.span (Set.range f) := by + rw [← List.ofFn_eq_map] + exact ideal_ofList_ofFn_eq_span_range f + +theorem flat_span_range_quotient_of_flat_ofFn_smul_top + {A S : Type*} [CommRing A] [CommRing S] [Algebra A S] + {n : ℕ} (f : Fin n → S) + (hflat : Module.Flat A (S ⧸ (Ideal.ofList (List.ofFn f) • ⊤ : Submodule S S))) : + Module.Flat A (S ⧸ Ideal.span (Set.range f)) := by + let := flat_ideal_quotient_of_flat_smul_top (Ideal.ofList (List.ofFn f)) hflat + exact Module.Flat.of_linearEquiv + ((Ideal.quotientEquivAlgOfEq A (ideal_ofList_ofFn_eq_span_range f)).toLinearEquiv.symm) + + + +open Polynomial +open scoped Pointwise + +theorem flat_polynomialDeformation_localized + {K : Type*} [Field K] {h : ℕ} + (p : Ideal (MvPolynomial (Fin h) K)) [p.IsPrime] + (I : Ideal K[X]) [I.IsPrime] (hI : I = Ideal.span {X - C (0 : K)}) + (f : Fin h → MvPolynomial (Fin h) K) (d : ℕ) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Fin h) K) (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) + (hlen : (h : ℕ∞) = (IsLocalRing.maximalIdeal (Localization.AtPrime p)).height) : + letI := parameterLocalAlgebra p I 0 hI + let S := Localization.AtPrime + (p.comap (MvPolynomial.map (σ := Fin h) (evalRingHom (0 : K)))) + letI : CommRing S := inferInstance + Module.Flat (Localization.AtPrime I) + (S ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Fin h) K[X]) S (polynomialDeformation f d i)))) := by + let := parameterLocalAlgebra p I 0 hI + have := dvr_polynomial_at_linear I 0 hI + let S := Localization.AtPrime + (p.comap (MvPolynomial.map (σ := Fin h) (evalRingHom (0 : K)))) + let : CommRing S := inferInstance + let fs : Fin h → S := fun i => + algebraMap (MvPolynomial (Fin h) K[X]) S (polynomialDeformation f d i) + apply flat_span_range_quotient_of_flat_ofFn_smul_top fs + apply flat_quotient_of_regular_special_fiber + (algebraMap K[X] (Localization.AtPrime I) (X - C (0 : K))) + (irreducible_parameter_at_linear I 0 hI) (List.ofFn fs) + (parameterLocalAlgebra_parameter_regular p I 0 hI) + rw [show algebraMap (Localization.AtPrime I) S + (algebraMap K[X] (Localization.AtPrime I) (X - C (0 : K))) = + algebraMap (MvPolynomial (Fin h) K[X]) S (MvPolynomial.C (X - C (0 : K))) from + parameterLocalAlgebra_parameter p I 0 hI] + have hs := isRegular_source_polynomialDeformation_special_fiber p f d (List.finRange h) + (by simpa only [ideal_ofList_map_finRange_eq_span_range] using hrad) + (by simpa only [List.length_finRange] using hlen) + simpa only [← List.ofFn_eq_map, List.map_ofFn, Function.comp_def] using hs + +end WeightedTorusJets.Deformation + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalizeInvariantDerivationLogCoordinate.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalizeInvariantDerivationLogCoordinate.lean new file mode 100644 index 0000000000000000000000000000000000000000..683b8786e322372cbaeadfb86c0bff0ab40540c6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LocalizeInvariantDerivationLogCoordinate.lean @@ -0,0 +1,42 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.FiniteTypeFieldModelEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +variable {K ι T : Type*} [CommRing K] [CommRing T] [Fintype ι] + [Algebra K T] [Algebra (MvPolynomial ι K) T] [IsScalarTower K (MvPolynomial ι K) T] + +theorem localize_invariantDerivation_log_coordinate (M : Submonoid (MvPolynomial ι K)) + [IsLocalization M T] (c : ι → K) (i : ι) (u : Tˣ) + (hu : (u : T) = algebraMap (MvPolynomial ι K) T (MvPolynomial.X i)) : + (↑(u⁻¹) : T) * localizeDerivation M (invariantDerivation c) + (algebraMap (MvPolynomial ι K) T (MvPolynomial.X i)) = algebraMap K T (c i) := by + rw [localize_invariantDerivation_X, ← hu] + rw [mul_comm (algebraMap K T (c i)) (u : T)] + exact Units.inv_mul_cancel_left u _ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {k F ι : Type*} [Field k] [Field F] [Algebra k F] [Fintype ι] + +theorem lift_logarithmicForm (c : ι → k) (f : ι → F) (D : Derivation k F F) : + D.liftKaehlerDifferential (logarithmicForm c f) = + ∑ i, algebraMap k F (c i) * (f i)⁻¹ * D (f i) := by + simp [logarithmicForm] + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LogarithmicForm.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LogarithmicForm.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8c3fb362002b0620f401d7b5563ec9b3b5d1ff8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LogarithmicForm.lean @@ -0,0 +1,479 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.FinrankDerivationCardTranscendenceBasis +import OAI.NumberTheory.Jacobsthal.Siegel.ParameterIdeal + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +noncomputable section +attribute [local instance] WeightedTorusJets.Geometry.polynomialGradedAlgebra +open Module +open CategoryTheory _root_.AlgebraicGeometry _root_.OAI.Erdos970.AlgebraicGeometry +open CategoryTheory _root_.AlgebraicGeometry +open IsLocalRing +open _root_.AlgebraicGeometry TopologicalSpace CategoryTheory +open _root_.AlgebraicGeometry TopologicalSpace CategoryTheory +open CategoryTheory _root_.AlgebraicGeometry +open MvPolynomial HomogeneousLocalization +open CategoryTheory _root_.AlgebraicGeometry +open Polynomial IsLocalRing TensorProduct +open TensorProduct IsLocalRing +open scoped TensorProduct +open scoped BigOperators +namespace WeightedTorusJets + +universe u + +open CategoryTheory _root_.AlgebraicGeometry + +theorem scheme_coordinates_constant_of_log_form + {ι : Type*} [Fintype ι] {k : Type u} [Field k] [CharZero k] [IsAlgClosed k] + {X : Scheme.{u}} [IsIntegral X] [IsLocallyNoetherian X] + [∀ x : X, IsIntegrallyClosed (X.presheaf.stalk x)] + (p : X ⟶ Spec (CommRingCat.of k)) [LocallyOfFiniteType p] [UniversallyClosed p] + (c : ι → k) (hc : LinearIndependent ℚ c) + (f : ι → X.functionField) (hf : ∀ i, f i ≠ 0) : + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + (∑ i, (algebraMap k X.functionField (c i) / f i) • + KaehlerDifferential.D k X.functionField (f i) = 0) → + ∀ i, ∃ a : k, algebraMap k X.functionField a = f i := by + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + dsimp only + intro hω i + obtain ⟨s, _, hs⟩ := scheme_global_units_of_locallyOfFiniteType_log_form p c hc f hf hω i + obtain ⟨a, ha, _⟩ := existsUnique_globalSection_scalar k p s + refine ⟨a, ?_⟩ + change schemeBaseToStalk p (genericPoint X) a = f i + rw [schemeBaseToStalk_eq_global_germ, RingHom.comp_apply, ha] + exact hs + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem logarithmic_relation_map_algHom + {ι k F L : Type*} [Fintype ι] [Field k] [Field F] [Field L] + [Algebra k F] [Algebra k L] + (φ : F →ₐ[k] L) (c : ι → k) (f : ι → F) + (h : ∑ i, (algebraMap k F (c i) / f i) • KaehlerDifferential.D k F (f i) = 0) : + ∑ i, (algebraMap k L (c i) / φ (f i)) • + KaehlerDifferential.D k L (φ (f i)) = 0 := by + algebraize [φ.toRingHom] + have hm := congrArg (KaehlerDifferential.map k k F L) h + rw [map_zero] at hm + convert hm using 1 + simp only [map_sum, map_smul, KaehlerDifferential.map_D] + apply Finset.sum_congr rfl + intro i _ + symm + rw [← IsScalarTower.algebraMap_smul L, map_div₀, + IsScalarTower.algebraMap_apply k F L] + rfl + + + +universe u + +open CategoryTheory _root_.AlgebraicGeometry + +theorem coordinates_constant_of_log_form_via_normal_model + {ι F : Type*} [Fintype ι] {k : Type u} [Field k] [CharZero k] [IsAlgClosed k] + [Field F] [Algebra k F] + {X : Scheme.{u}} [IsIntegral X] [IsLocallyNoetherian X] + [∀ x : X, IsIntegrallyClosed (X.presheaf.stalk x)] + (p : X ⟶ Spec (CommRingCat.of k)) [LocallyOfFiniteType p] [UniversallyClosed p] + (c : ι → k) (hc : LinearIndependent ℚ c) + (f : ι → F) (hf : ∀ i, f i ≠ 0) : + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + ∀ _φ : F →ₐ[k] X.functionField, + (∑ i, (algebraMap k F (c i) / f i) • KaehlerDifferential.D k F (f i) = 0) → + ∀ i, ∃ a : k, algebraMap k F a = f i := by + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + dsimp only + intro φ hω i + have hf' (i) : φ (f i) ≠ 0 := by + intro hz + apply hf i + apply φ.injective + change φ (f i) = φ 0 + simpa only [map_zero] using hz + obtain ⟨a, ha⟩ := scheme_coordinates_constant_of_log_form p c hc + (fun i => φ (f i)) hf' (logarithmic_relation_map_algHom φ c f hω) i + refine ⟨a, ?_⟩ + apply φ.injective + change φ (algebraMap k F a) = φ (f i) + exact (φ.commutes a).trans ha + +end WeightedTorusJets + +namespace WeightedTorusJets + +variable {K L ι : Type*} [Field K] [Field L] [Algebra K L] + +theorem laurent_range_mem_intermediateField + (q : AddMonoidAlgebra K (ι →₀ ℤ) →ₐ[K] L) (S : IntermediateField K L) + (h : ∀ i, q (AddMonoidAlgebra.single (Finsupp.single i 1) 1) ∈ S) + (p : AddMonoidAlgebra K (ι →₀ ℤ)) : q p ∈ S := by + have hm (m : ι →₀ ℤ) : q (AddMonoidAlgebra.single m 1) ∈ S := by + induction m using Finsupp.induction_linear with + | zero => change q 1 ∈ S; simp + | add m n hm hn => + rw [show AddMonoidAlgebra.single (m + n) (1 : K) = + AddMonoidAlgebra.single m 1 * AddMonoidAlgebra.single n 1 by simp, map_mul] + exact S.mul_mem hm hn + | single i z => + let f := q.toMonoidHom.comp (AddMonoidAlgebra.of K (ι →₀ ℤ)) + have hz : q (AddMonoidAlgebra.single (Finsupp.single i z) 1) = + q (AddMonoidAlgebra.single (Finsupp.single i 1) 1) ^ z := by + simpa [f, ← ofAdd_zsmul, Finsupp.smul_single, zsmul_eq_mul] using + map_zpow f (Multiplicative.ofAdd (Finsupp.single i 1)) z + rw [hz] + exact S.toSubfield.zpow_mem (h i) z + induction p using AddMonoidAlgebra.induction_on with + | of m => exact hm m + | add p r hp hr => rw [map_add]; exact S.add_mem hp hr + | smul c p hp => rw [map_smul, Algebra.smul_def]; exact S.mul_mem (S.algebraMap_mem c) hp + +theorem laurent_fraction_adjoin_coordinates + (P : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [P.IsPrime] : + IntermediateField.adjoin K (Set.range fun i : ι ↦ + algebraMap _ (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) = ⊤ := by + let B := AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P + let j : B →ₐ[K] FractionRing B := IsScalarTower.toAlgHom K B (FractionRing B) + let S := IntermediateField.adjoin K (Set.range fun i : ι ↦ + j (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) + have hB (b : B) : algebraMap B (FractionRing B) b ∈ S := by + obtain ⟨p, rfl⟩ := Ideal.Quotient.mkₐ_surjective K P b + apply laurent_range_mem_intermediateField (j.comp (Ideal.Quotient.mkₐ K P)) S ?_ p + intro i + exact IntermediateField.subset_adjoin K _ ⟨i, rfl⟩ + apply top_unique + intro x _ + obtain ⟨a, b, _, rfl⟩ := IsFractionRing.div_surjective B x + exact S.div_mem (hB a) (hB b) + +theorem laurent_quotient_exists_nonconstant_coordinate + (P : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [P.IsPrime] + (hdim : 0 < ringKrullDim (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) : + ∃ i, ¬ ∃ c : K, + algebraMap _ (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) = + algebraMap K (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) c := by + by_contra! h + let B := AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P + let j : B →ₐ[K] FractionRing B := IsScalarTower.toAlgHom K B (FractionRing B) + have hsurj : Function.Surjective (algebraMap K B) := by + intro b + obtain ⟨p, rfl⟩ := Ideal.Quotient.mkₐ_surjective K P b + have hp := laurent_range_mem_intermediateField + (j.comp (Ideal.Quotient.mkₐ K P)) (⊥ : IntermediateField K (FractionRing B)) + (fun i ↦ IntermediateField.mem_bot.mpr (by + obtain ⟨c, hc⟩ := h i + exact ⟨c, hc.symm⟩)) p + obtain ⟨c, hc⟩ := IntermediateField.mem_bot.mp hp + refine ⟨c, IsFractionRing.injective B (FractionRing B) ?_⟩ + exact (j.commutes c).trans hc + have hle := ringKrullDim_le_of_surjective (algebraMap K B) hsurj + have hzero : ringKrullDim K = 0 := Order.krullDim_eq_zero_of_unique + rw [hzero] at hle + exact (not_lt_of_ge hle) hdim + +theorem derivation_laurent_fraction_eq_zero + (P : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [P.IsPrime] + (D : Derivation K (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P))) + (h : ∀ i, D (algebraMap _ (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) = 0) : + D = 0 := by + ext x + have hx : x ∈ IntermediateField.adjoin K (Set.range fun i : ι ↦ + algebraMap _ (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) := by + rw [laurent_fraction_adjoin_coordinates P] + exact IntermediateField.mem_top + change D x = 0 + induction hx using IntermediateField.adjoin_induction with + | mem x hx => obtain ⟨i, rfl⟩ := hx; exact h i + | algebraMap c => exact D.map_algebraMap c + | add x y _ _ hx hy => simp [hx, hy] + | inv x _ hx => simp [D.leibniz_inv, hx] + | mul x y _ _ hx hy => simp [D.leibniz, hx, hy] + +theorem laurent_finiteType [Finite ι] : + Algebra.FiniteType K (AddMonoidAlgebra K (ι →₀ ℤ)) := by + apply AddMonoidAlgebra.finiteType_iff_group_fg.mpr + exact AddGroup.fg_of_surjective + (f := (Finsupp.linearEquivFunOnFinite ℤ ℤ ι).symm.toAddMonoidHom) + (Finsupp.linearEquivFunOnFinite ℤ ℤ ι).symm.surjective + +end WeightedTorusJets + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +variable {k F ι : Type*} [Field k] [Field F] [Algebra k F] [Fintype ι] + +noncomputable def logarithmicForm (c : ι → k) (f : ι → F) : + KaehlerDifferential k F := + ∑ i, (algebraMap k F (c i) * (f i)⁻¹) • KaehlerDifferential.D k F (f i) + +theorem logarithmicForm_eq_zero_iff (c : ι → k) (f : ι → F) : + logarithmicForm c f = 0 ↔ + ∀ D : Derivation k F F, ∑ i, algebraMap k F (c i) * (f i)⁻¹ * D (f i) = 0 := by + constructor + · intro h D + simpa [logarithmicForm] using congrArg D.liftKaehlerDifferential h + · intro h + apply (Module.forall_dual_apply_eq_zero_iff F _).mp + intro φ + simpa [logarithmicForm] using h (φ.compDer (KaehlerDifferential.D k F)) + +noncomputable def logarithmicTangentMap (f : ι → F) : + Derivation k F F →ₗ[F] (ι → F) where + toFun D i := (f i)⁻¹ * D (f i) + map_add' D E := by ext i; simp [mul_add] + map_smul' a D := by ext i; simp [mul_left_comm] + +noncomputable def logarithmicLinearForm (c : ι → k) : (ι → F) →ₗ[F] F := + ∑ i, algebraMap k F (c i) • LinearMap.proj i + +theorem logarithmicLinearForm_apply (c : ι → k) (v : ι → F) : + logarithmicLinearForm c v = ∑ i, algebraMap k F (c i) * v i := by + simp [logarithmicLinearForm, Algebra.smul_def] + +theorem logarithmicForm_ne_zero_iff_tangent_not_le (c : ι → k) (f : ι → F) : + logarithmicForm c f ≠ 0 ↔ + ¬ LinearMap.range (logarithmicTangentMap (k := k) f) ≤ + LinearMap.ker (logarithmicLinearForm (F := F) c) := by + rw [not_iff_not, logarithmicForm_eq_zero_iff] + constructor + · intro h v hv + obtain ⟨D, rfl⟩ := hv + rw [LinearMap.mem_ker, logarithmicLinearForm_apply] + simpa only [logarithmicTangentMap, LinearMap.coe_mk, AddHom.coe_mk, mul_assoc] using h D + · intro h D + have hD := h (LinearMap.mem_range_self (logarithmicTangentMap (k := k) f) D) + rw [LinearMap.mem_ker, logarithmicLinearForm_apply] at hD + simpa only [logarithmicTangentMap, LinearMap.coe_mk, AddHom.coe_mk, mul_assoc] using hD + +variable {L : Type*} [Field L] [Algebra k L] [Algebra F L] [IsScalarTower k F L] + +end WeightedTorusJets.Geometry + + +namespace WeightedTorusJets.Geometry + +universe u + +open CategoryTheory _root_.AlgebraicGeometry + +theorem logarithmicForm_ne_zero_on_torus_subvariety_of_normal_model + {K : Type u} {ι : Type} [Field K] [CharZero K] [IsAlgClosed K] [Fintype ι] + (P : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [P.IsPrime] + (hdim : 0 < ringKrullDim (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (c : ι → K) (hc : LinearIndependent ℚ c) + {N : Scheme.{u}} [IsIntegral N] [IsLocallyNoetherian N] + [∀ x : N, IsIntegrallyClosed (N.presheaf.stalk x)] + (p : N ⟶ Spec (CommRingCat.of K)) [LocallyOfFiniteType p] [UniversallyClosed p] : + let : Algebra K N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + ∀ _φ : FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P) →ₐ[K] N.functionField, + logarithmicForm c (fun i ↦ algebraMap _ + (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) ≠ 0 := by + let : Algebra K N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + dsimp only + intro φ hform + let B := AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P + let q : AddMonoidAlgebra K (ι →₀ ℤ) →ₐ[K] FractionRing B := + (IsScalarTower.toAlgHom K B (FractionRing B)).comp (Ideal.Quotient.mkₐ K P) + have hf (i : ι) : q (AddMonoidAlgebra.single (Finsupp.single i 1) 1) ≠ 0 := + ((Group.isUnit (Multiplicative.ofAdd (Finsupp.single i 1))).map + (q.toMonoidHom.comp (AddMonoidAlgebra.of K (ι →₀ ℤ)))).ne_zero + have hconst := coordinates_constant_of_log_form_via_normal_model p c hc + (fun i => q (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) hf φ + (by simpa only [logarithmicForm, div_eq_mul_inv, q, B, AlgHom.comp_apply, + IsScalarTower.toAlgHom_apply, Ideal.Quotient.mkₐ_eq_mk] using hform) + obtain ⟨i, hi⟩ := laurent_quotient_exists_nonconstant_coordinate P hdim + obtain ⟨a, ha⟩ := hconst i + exact hi ⟨a, ha.symm⟩ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +universe u + +open CategoryTheory _root_.AlgebraicGeometry + +theorem logarithmicForm_ne_zero_on_torus_subvariety + {K : Type u} {ι : Type} [Field K] [CharZero K] [IsAlgClosed K] [Fintype ι] + (P : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [P.IsPrime] + (hdim : 0 < ringKrullDim (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (c : ι → K) (hc : LinearIndependent ℚ c) : + logarithmicForm c (fun i ↦ algebraMap _ + (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) ≠ 0 := by + let B := AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P + have : Algebra.FiniteType K (AddMonoidAlgebra K (ι →₀ ℤ)) := laurent_finiteType + obtain ⟨N, hN, hrest⟩ := exists_normal_proper_model_of_finiteType_domain K B + let := hN + obtain ⟨p, hNoeth, hNormal, hFT, hClosed, hφ⟩ := hrest + have := hNoeth + have := hFT + have := hClosed + have : ∀ x : N, IsIntegrallyClosed (N.presheaf.stalk x) := hNormal + let : Algebra K N.functionField := schemeBaseStalkAlgebra p (genericPoint N) + obtain ⟨φ⟩ := hφ + exact logarithmicForm_ne_zero_on_torus_subvariety_of_normal_model P hdim c hc p φ + +end WeightedTorusJets.Geometry + + + + + + +namespace WeightedTorusJets.Geometry + +theorem finrank_normal_image_of_not_le + {K V : Type*} [Field K] [AddCommGroup V] [Module K V] [FiniteDimensional K V] + (ω : V →ₗ[K] K) (T : Submodule K V) (h : ¬ T ≤ LinearMap.ker ω) : + Module.finrank K (LinearMap.range (T.mkQ.domRestrict (LinearMap.ker ω))) = + Module.finrank K V - Module.finrank K T := by + have hs : LinearMap.range (T.mkQ.domRestrict (LinearMap.ker ω)) = ⊤ := by + rw [LinearMap.range_domRestrict, Submodule.map_mkQ_eq_top] + obtain ⟨x, hxT, hxω⟩ := SetLike.not_le_iff_exists.mp h + apply top_unique + rw [← LinearMap.span_singleton_sup_ker_eq_top ω hxω] + exact sup_le_sup_right ((Submodule.span_singleton_le_iff_mem _ _).mpr hxT) _ + rw [hs, finrank_top, Submodule.finrank_quotient] + + + +theorem logarithmicHyperplane_normal_rank_at_point + {K : Type*} [Field K] [CharZero K] (x c : Fin 4 → K) + (hc : LinearIndependent ℚ c) : + Module.finrank K (LinearMap.range + ((LinearMap.range (logarithmicTangentMap (k := K) x)).mkQ.domRestrict + (LinearMap.ker (logarithmicLinearForm (F := K) c)))) = 3 := by + have hT : LinearMap.range (logarithmicTangentMap (k := K) x) = ⊥ := by + rw [LinearMap.range_eq_bot] + ext D i + change (x i)⁻¹ * D (x i) = 0 + have hD : D (x i) = 0 := by simpa using D.map_algebraMap (x i) + rw [hD, mul_zero] + have hi : Function.Injective ((⊥ : Submodule K (Fin 4 → K)).mkQ.domRestrict + (LinearMap.ker (logarithmicLinearForm (F := K) c))) := by + have hq : Function.Injective (⊥ : Submodule K (Fin 4 → K)).mkQ := by + rw [← LinearMap.ker_eq_bot, Submodule.ker_mkQ] + exact hq.comp (LinearMap.ker (logarithmicLinearForm (F := K) c)).injective_subtype + rw [hT, LinearMap.finrank_range_of_inj hi] + have hω : logarithmicLinearForm (F := K) c ≠ 0 := by + intro h + have hh := LinearMap.congr_fun h (Pi.single (0 : Fin 4) 1) + simp [logarithmicLinearForm_apply, Pi.single_apply] at hh + exact hc.ne_zero 0 hh + have h := Module.Dual.finrank_ker_add_one_of_ne_zero hω + have hd : Module.finrank K (Fin 4 → K) = 4 := by simp + omega + + + +theorem logarithmicTangentMap_injective_laurent_quotient + {K ι : Type*} [Field K] + (P : Ideal (AddMonoidAlgebra K (ι →₀ ℤ))) [P.IsPrime] : + Function.Injective (logarithmicTangentMap (k := K) + (fun i ↦ algebraMap _ (FractionRing (AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)))) := by + let B := AddMonoidAlgebra K (ι →₀ ℤ) ⧸ P + let q : AddMonoidAlgebra K (ι →₀ ℤ) →ₐ[K] FractionRing B := + (IsScalarTower.toAlgHom K B (FractionRing B)).comp (Ideal.Quotient.mkₐ K P) + apply LinearMap.ker_eq_bot.mp + rw [Submodule.eq_bot_iff] + intro D hD + rw [LinearMap.mem_ker] at hD + apply WeightedTorusJets.derivation_laurent_fraction_eq_zero P D + intro i + have hi := congrFun hD i + have hcoord : q (AddMonoidAlgebra.single (Finsupp.single i 1) 1) ≠ 0 := + ((Group.isUnit (Multiplicative.ofAdd (Finsupp.single i 1))).map + (q.toMonoidHom.comp (AddMonoidAlgebra.of K (ι →₀ ℤ)))).ne_zero + change (q (AddMonoidAlgebra.single (Finsupp.single i 1) 1))⁻¹ * + D (q (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) = 0 at hi + exact (mul_eq_zero.mp hi).resolve_left (inv_ne_zero hcoord) + + + +theorem logarithmicHyperplane_generic_normal_rank_eq_codim + {K : Type*} [Field K] [CharZero K] [IsAlgClosed K] + (P : Ideal (AddMonoidAlgebra K (Fin 4 →₀ ℤ))) [P.IsPrime] + (hdim : 0 < ringKrullDim (AddMonoidAlgebra K (Fin 4 →₀ ℤ) ⧸ P)) + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) : + let A := AddMonoidAlgebra K (Fin 4 →₀ ℤ) ⧸ P + let F := FractionRing A + let x := fun i ↦ algebraMap _ F + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + let T := LinearMap.range (logarithmicTangentMap (k := K) x) + finrank F (LinearMap.range + (T.mkQ.domRestrict (LinearMap.ker (logarithmicLinearForm c)))) = + 4 - ((ringKrullDim A).unbotD 0).toNat := by + dsimp only + let A := AddMonoidAlgebra K (Fin 4 →₀ ℤ) ⧸ P + let F := FractionRing A + have := WeightedTorusJets.laurent_finiteType (K := K) (ι := Fin 4) + have hd := ringKrullDim_eq_finrank_derivation (K := K) (A := A) (F := F) + let x := fun i ↦ algebraMap _ F + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + have hn := (logarithmicForm_ne_zero_iff_tangent_not_le c x).mp + (logarithmicForm_ne_zero_on_torus_subvariety (K := K) (ι := Fin 4) P hdim c hc) + have hr := finrank_normal_image_of_not_le (logarithmicLinearForm (F := F) c) + (LinearMap.range (logarithmicTangentMap (k := K) x)) hn + rw [LinearMap.finrank_range_of_inj + (logarithmicTangentMap_injective_laurent_quotient P)] at hr + dsimp only [A, F] at hd + simpa [hd] using hr + + + +theorem logarithmic_form_lemma_exact + {K : Type*} [Field K] [CharZero K] [IsAlgClosed K] + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) : + (∀ (P : Ideal (AddMonoidAlgebra K (Fin 4 →₀ ℤ))) (hP : P.IsPrime), + letI := hP + 0 < ringKrullDim (AddMonoidAlgebra K (Fin 4 →₀ ℤ) ⧸ P) → + let A := AddMonoidAlgebra K (Fin 4 →₀ ℤ) ⧸ P + let F := FractionRing A + let x := fun i ↦ algebraMap _ F + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + let T := LinearMap.range (logarithmicTangentMap (k := K) x) + logarithmicForm c x ≠ 0 ∧ + Module.finrank F (LinearMap.range + (T.mkQ.domRestrict (LinearMap.ker (logarithmicLinearForm c)))) = + 4 - ((ringKrullDim A).unbotD 0).toNat) ∧ + ∀ y : Fin 4 → Kˣ, + Module.finrank K (LinearMap.range + ((LinearMap.range (logarithmicTangentMap (k := K) (fun i ↦ (y i : K)))).mkQ.domRestrict + (LinearMap.ker (logarithmicLinearForm (F := K) c)))) = 3 := by + constructor + · intro P hP hdim + let := hP + exact ⟨logarithmicForm_ne_zero_on_torus_subvariety (K := K) (ι := Fin 4) P hdim c hc, + logarithmicHyperplane_generic_normal_rank_eq_codim P hdim c hc⟩ + · intro y + exact logarithmicHyperplane_normal_rank_at_point (fun i ↦ (y i : K)) c hc + +end WeightedTorusJets.Geometry + +end + +open Module CategoryTheory _root_.AlgebraicGeometry +open scoped BigOperators TensorProduct + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/LogarithmicFormLemma.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LogarithmicFormLemma.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f74da9fb70867838748ed8df3e38517d0ec211e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/LogarithmicFormLemma.lean @@ -0,0 +1,37 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.LogarithmicForm + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open WeightedTorusJets.Geometry + +theorem WeightedTorusJets.Geometry.logarithmic_form_lemma_source + (c : Fin 4 → ℂ) (hc : LinearIndependent ℚ c) : + (∀ (P : Ideal (AddMonoidAlgebra ℂ (Fin 4 →₀ ℤ))) (hP : P.IsPrime), + letI := hP + 0 < ringKrullDim (AddMonoidAlgebra ℂ (Fin 4 →₀ ℤ) ⧸ P) → + let A := AddMonoidAlgebra ℂ (Fin 4 →₀ ℤ) ⧸ P + let F := FractionRing A + let x := fun i ↦ algebraMap _ F + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + let T := LinearMap.range (logarithmicTangentMap (k := ℂ) x) + logarithmicForm c x ≠ 0 ∧ + Module.finrank F (LinearMap.range + (T.mkQ.domRestrict (LinearMap.ker (logarithmicLinearForm c)))) = + 4 - ((ringKrullDim A).unbotD 0).toNat) ∧ + ∀ y : Fin 4 → ℂˣ, + Module.finrank ℂ (LinearMap.range + ((LinearMap.range (logarithmicTangentMap (k := ℂ) (fun i ↦ (y i : ℂ)))).mkQ.domRestrict + (LinearMap.ker (logarithmicLinearForm (F := ℂ) c)))) = 3 := by + exact WeightedTorusJets.Geometry.logarithmic_form_lemma_exact (K := ℂ) c hc + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/Main.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..e3275cc580321881d523d575bdce328ab17492dd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/Main.lean @@ -0,0 +1,21 @@ +import OAI.NumberTheory.Jacobsthal.Siegel.BiquadraticBasisGroupTransport +import OAI.NumberTheory.Jacobsthal.Siegel.ClosureSpecMapZeroLocus +import OAI.NumberTheory.Jacobsthal.Siegel.CompletedLAnalyticOrderNeTop +import OAI.NumberTheory.Jacobsthal.Siegel.DegreeSliceQuotientEquiv +import OAI.NumberTheory.Jacobsthal.Siegel.DirichletRealZeroBoundProof +import OAI.NumberTheory.Jacobsthal.Siegel.Divisibility +import OAI.NumberTheory.Jacobsthal.Siegel.FractionEquivAlgebra +import OAI.NumberTheory.Jacobsthal.Siegel.FractionEulerDerivation +import OAI.NumberTheory.Jacobsthal.Siegel.GlobalPivotValuationExponent +import OAI.NumberTheory.Jacobsthal.Siegel.LogarithmicFormLemma +import OAI.NumberTheory.Jacobsthal.Siegel.MapIInfPrimesOver +import OAI.NumberTheory.Jacobsthal.Siegel.NormLogDerivLFunctionNegLogDerivZeta +import OAI.NumberTheory.Jacobsthal.Siegel.NormalizedHomogeneousChartEquation +import OAI.NumberTheory.Jacobsthal.Siegel.PivotBounds +import OAI.NumberTheory.Jacobsthal.Siegel.RectangularGradedPieceGeneratedByDegreeOne +import OAI.NumberTheory.Jacobsthal.Siegel.SumCardFilterSumMin +import OAI.NumberTheory.Jacobsthal.Siegel.SumCharacterPeriodZero +import OAI.NumberTheory.Jacobsthal.Siegel.TorusImmersionGenericPointFormallySmooth +import OAI.NumberTheory.Jacobsthal.Siegel.TorusIntoProj +import OAI.NumberTheory.Jacobsthal.Siegel.TorusJetZeroSchemeInclusion + diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/MapIInfPrimesOver.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/MapIInfPrimesOver.lean new file mode 100644 index 0000000000000000000000000000000000000000..26b653107ab0c3e9acb8efc483eb770f40ff4167 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/MapIInfPrimesOver.lean @@ -0,0 +1,34 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.SqrtPairFrobeniusDirections + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +theorem map_eq_iInf_primesOver + {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] + [Algebra.EssFiniteType R S] (P : Ideal R) [P.IsMaximal] + (hunr : Algebra.IsUnramifiedIn S P) : + P.map (algebraMap R S) = ⨅ Q : Ideal.primesOver P S, Q.1 := by + apply le_antisymm + · refine le_iInf fun Q ↦ ?_ + exact Ideal.map_le_iff_le_comap.mpr Q.2.2.over.le + · intro x hx + apply mem_map_of_forall_mem_primesOver P hunr + intro Q hQ hover + have hle : (⨅ Q : Ideal.primesOver P S, Q.1) ≤ Q := + iInf_le (fun Q : Ideal.primesOver P S ↦ Q.1) ⟨Q, hQ, hover⟩ + exact hle hx + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/MellinConvergentTopIndicator.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/MellinConvergentTopIndicator.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a9c9678577d33a7f0cdaf08f99a2e608534f78c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/MellinConvergentTopIndicator.lean @@ -0,0 +1,516 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section AnalyticAssemblyScope + +open scoped BigOperators Topology + +section + +open Filter Set MeasureTheory +open scoped Topology + +namespace WeightedTorusJets + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] + +lemma mellinConvergent_top_indicator (P : WeakFEPair E) (s : ℂ) : + MellinConvergent ((Ioi 1).indicator (fun t ↦ P.f t - P.f₀)) s := by + have hi : MellinConvergent P.f_modif s := + (P.isStrongFEPair_toStrongFEPair.hasMellin s).1 + change IntegrableOn (fun t : ℝ ↦ (t : ℂ) ^ (s - 1) • P.f_modif t) (Ioi 0) at hi + unfold MellinConvergent + convert hi.indicator (t := Ioi 1) measurableSet_Ioi using 1 + ext t + by_cases ht : 1 < t + · simp [WeakFEPair.f_modif, ht, notMem_Ioo_of_ge ht.le] + · simp [ht] + +lemma f_modif_eq_top_add_inv (P : WeakFEPair E) {t : ℝ} (ht : 0 < t) : + P.f_modif t = (Ioi 1).indicator (fun x ↦ P.f x - P.f₀) t + + P.ε • ((t : ℂ) ^ (-P.k : ℂ) • + (Ioi 1).indicator (fun x ↦ P.g x - P.g₀) t⁻¹) := by + rcases lt_trichotomy t 1 with h | rfl | h + · have hinv : 1 < t⁻¹ := (one_lt_inv₀ ht).mpr h + have heq := P.hf_modif_FE t⁻¹ (inv_pos.mpr ht) + rw [one_div, inv_inv] at heq + rw [Set.indicator_of_notMem (show t ∉ Ioi 1 from not_lt.mpr h.le), zero_add, + Set.indicator_of_mem (show t⁻¹ ∈ Ioi 1 from hinv), heq] + simp only [WeakFEPair.g_modif, Pi.add_apply, + Set.indicator_of_mem (show t⁻¹ ∈ Ioi 1 from hinv), + Set.indicator_of_notMem (notMem_Ioo_of_ge hinv.le), + add_zero, Real.inv_rpow ht.le, ← Real.rpow_neg ht.le, Complex.ofReal_cpow ht.le, + Complex.ofReal_neg, mul_smul] + · simp [WeakFEPair.f_modif] + · have hinv : ¬1 < t⁻¹ := not_lt.mpr ((inv_le_one₀ ht).mpr h.le) + simp [WeakFEPair.f_modif, h, notMem_Ioo_of_ge h.le, hinv] + +lemma mellin_top_indicator_eq (f : ℝ → E) (s : ℂ) : + mellin ((Ioi 1).indicator f) s = + ∫ t : ℝ in Ioi 1, (t : ℂ) ^ (s - 1) • f t := by + simp only [mellin, ← indicator_smul, setIntegral_indicator measurableSet_Ioi, + inter_eq_right.mpr (Ioi_subset_Ioi (by norm_num : (0 : ℝ) ≤ 1))] + +lemma Lambda_zero_eq_top_integrals (P : WeakFEPair E) (s : ℂ) : + P.Λ₀ s = (∫ t : ℝ in Ioi 1, (t : ℂ) ^ (s - 1) • (P.f t - P.f₀)) + + P.ε • (∫ t : ℝ in Ioi 1, (t : ℂ) ^ ((P.k : ℂ) - s - 1) • (P.g t - P.g₀)) := by + let F := (Ioi 1).indicator (fun t ↦ P.f t - P.f₀) + let G := (Ioi 1).indicator (fun t ↦ P.g t - P.g₀) + have hF : MellinConvergent F s := mellinConvergent_top_indicator P s + have hG : MellinConvergent G (P.k - s) := mellinConvergent_top_indicator P.symm _ + have hInv : MellinConvergent (fun t ↦ G t⁻¹) (s - P.k) := by + have hdiv : (s - (P.k : ℂ)) / ((-1 : ℝ) : ℂ) = (P.k : ℂ) - s := by + simp only [Complex.ofReal_neg, Complex.ofReal_one, div_neg, div_one, neg_sub] + simpa only [Real.rpow_neg_one] using + (MellinConvergent.comp_rpow (f := G) (s := s - P.k) + (a := -1) (by norm_num)).mpr (hdiv.symm ▸ hG) + have hSecond : MellinConvergent + (fun t : ℝ ↦ P.ε • ((t : ℂ) ^ (-P.k : ℂ) • G t⁻¹)) s := by + apply MellinConvergent.const_smul + apply MellinConvergent.cpow_smul.mpr + simpa only [sub_eq_add_neg] using hInv + calc + P.Λ₀ s = mellin (fun t : ℝ ↦ F t + P.ε • ((t : ℂ) ^ (-P.k : ℂ) • G t⁻¹)) s := by + apply setIntegral_congr_fun measurableSet_Ioi + intro t ht + exact congrArg (fun v : E ↦ (t : ℂ) ^ (s - 1) • v) (f_modif_eq_top_add_inv P ht) + _ = mellin F s + mellin (fun t : ℝ ↦ P.ε • ((t : ℂ) ^ (-P.k : ℂ) • G t⁻¹)) s := + (hasMellin_add hF hSecond).2 + _ = mellin F s + P.ε • mellin G (P.k - s) := by + rw [mellin_const_smul, mellin_cpow_smul, mellin_comp_inv] + congr 3 + ring + _ = _ := by rw [mellin_top_indicator_eq, mellin_top_indicator_eq] + +lemma norm_top_integral_le (f : ℝ → E) (s : ℂ) : + ‖∫ t : ℝ in Ioi 1, (t : ℂ) ^ (s - 1) • f t‖ ≤ + ∫ t : ℝ in Ioi 1, t ^ (s.re - 1) * ‖f t‖ := by + apply le_trans (norm_integral_le_integral_norm _) + apply le_of_eq + apply setIntegral_congr_fun measurableSet_Ioi + intro t ht + simp only [norm_smul, Complex.norm_cpow_eq_rpow_re_of_pos (zero_lt_one.trans ht), + Complex.sub_re, Complex.one_re] + +theorem norm_Lambda_zero_le_top_integrals (P : WeakFEPair E) (s : ℂ) : + ‖P.Λ₀ s‖ ≤ (∫ t : ℝ in Ioi 1, t ^ (s.re - 1) * ‖P.f t - P.f₀‖) + + ‖P.ε‖ * (∫ t : ℝ in Ioi 1, t ^ (P.k - s.re - 1) * ‖P.g t - P.g₀‖) := by + rw [Lambda_zero_eq_top_integrals] + refine (norm_add_le _ _).trans ?_ + rw [norm_smul] + apply add_le_add (norm_top_integral_le _ s) + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + simpa using (norm_top_integral_le (fun t ↦ P.g t - P.g₀) (P.k - s)) + +end WeightedTorusJets + +namespace WeightedTorusJets + +open _root_.Real Set MeasureTheory + +theorem exponential_moment_integrable {p R : ℝ} (hp : 0 < p) (hR : 0 ≤ R) : + IntegrableOn (fun t : ℝ => t ^ R * exp (-p * t)) (Ioi 1) := by + have h := integrableOn_rpow_mul_exp_neg_mul_rpow (s := R) (p := 1) + (by linarith) zero_lt_one hp + simp only [rpow_one] at h + exact h.mono_set (Ioi_subset_Ioi (by norm_num)) + +theorem exponential_moment_pointwise {p R t : ℝ} + (hp : 0 < p) (hR : 0 ≤ R) (ht : 1 ≤ t) : + t ^ R * exp (-p * t) ≤ + exp ((R + 1) * log (2 * (R + 1) / p)) * exp (-(p / 2) * t) := by + have hr : 0 < R + 1 := by positivity + have ht0 : 0 < t := lt_of_lt_of_le zero_lt_one ht + have ha : 0 < 2 * (R + 1) / p := by positivity + have hlog := Real.log_le_sub_one_of_pos (div_pos ht0 ha) + rw [Real.log_div ht0.ne' ha.ne'] at hlog + have hmul := mul_le_mul_of_nonneg_left hlog hr.le + have heq : (R + 1) * (t / (2 * (R + 1) / p) - 1) = p * t / 2 - (R + 1) := by + field_simp + rw [heq] at hmul + have htlog := Real.log_nonneg ht + rw [Real.rpow_def_of_pos ht0, ← Real.exp_add, ← Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + +theorem exponential_moment_le {p R : ℝ} (hp : 0 < p) (hR : 0 ≤ R) : + (∫ t : ℝ in Ioi 1, t ^ R * exp (-p * t)) ≤ + exp ((R + 1) * log (2 * (R + 1) / p)) * (2 / p) := by + have hp2 : -(p / 2) < 0 := by linarith + have hi := (integrableOn_exp_mul_Ioi hp2 1).const_mul + (exp ((R + 1) * log (2 * (R + 1) / p))) + calc + _ ≤ ∫ t : ℝ in Ioi 1, + exp ((R + 1) * log (2 * (R + 1) / p)) * exp (-(p / 2) * t) := + setIntegral_mono_on (exponential_moment_integrable hp hR) hi measurableSet_Ioi + (fun t ht => exponential_moment_pointwise hp hR ht.le) + _ = exp ((R + 1) * log (2 * (R + 1) / p)) * + (exp (-(p / 2)) * (2 / p)) := by + rw [integral_const_mul, integral_exp_mul_Ioi hp2] + congr 1 + simp only [mul_one] + field_simp + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left _ (exp_pos _).le + calc + _ ≤ 1 * (2 / p) := mul_le_mul_of_nonneg_right + (Real.exp_le_one_iff.mpr hp2.le) (by positivity) + _ = _ := one_mul _ + +theorem mul_log_le_three_halves {u : ℝ} (hu : 1 ≤ u) : + u * log u ≤ 2 * u ^ (3 / 2 : ℝ) := by + have hu0 : 0 < u := lt_of_lt_of_le zero_lt_one hu + have hlog := Real.log_le_rpow_div hu0.le (by norm_num : 0 < (1 / 2 : ℝ)) + have hmul := mul_le_mul_of_nonneg_left hlog hu0.le + have heq : u * u ^ (1 / 2 : ℝ) = u ^ (3 / 2 : ℝ) := by + calc + _ = u ^ ((1 : ℝ) + 1 / 2) := by rw [Real.rpow_add hu0, Real.rpow_one] + _ = _ := by norm_num + nlinarith + +theorem exponential_moment_growth {p : ℝ} (hp : 0 < p) : + ∃ C : ℝ, 0 < C ∧ ∀ R : ℝ, 0 ≤ R → + (∫ t : ℝ in Ioi 1, t ^ R * exp (-p * t)) ≤ + exp (C * (1 + R) ^ (3 / 2 : ℝ)) := by + refine ⟨2 * |log (2 / p)| + 2, by positivity, fun R hR => ?_⟩ + have hr : 0 < R + 1 := by positivity + have hp2 : 0 < 2 / p := by positivity + have hpow : R + 1 ≤ (R + 1) ^ (3 / 2 : ℝ) := by + simpa using Real.rpow_le_rpow_of_exponent_le (by linarith : 1 ≤ R + 1) + (by norm_num : (1 : ℝ) ≤ 3 / 2) + have hpow1 : 1 ≤ (R + 1) ^ (3 / 2 : ℝ) := by + exact one_le_rpow (by linarith) (by norm_num) + have hlog := mul_log_le_three_halves (by linarith : 1 ≤ R + 1) + have hA := le_abs_self (log (2 / p)) + have hAu := mul_le_mul_of_nonneg_left hA hr.le + have hA1 := mul_le_mul_of_nonneg_left hpow1 (abs_nonneg (log (2 / p))) + have hApow := mul_le_mul_of_nonneg_left hpow (abs_nonneg (log (2 / p))) + calc + _ ≤ exp ((R + 1) * log (2 * (R + 1) / p)) * (2 / p) := + exponential_moment_le hp hR + _ = exp ((R + 1) * log (2 * (R + 1) / p) + log (2 / p)) := by + rw [Real.exp_add, Real.exp_log hp2] + _ ≤ _ := by + apply Real.exp_le_exp.mpr + rw [show 2 * (R + 1) / p = (2 / p) * (R + 1) by ring, + Real.log_mul hp2.ne' hr.ne', show 1 + R = R + 1 by ring] + nlinarith + +theorem log_one_add_le_log_two_add {b x : ℝ} (hb : 0 ≤ b) (hx : 0 ≤ x) + (h : b ≤ exp x) : log (1 + b) ≤ log 2 + x := by + calc + _ ≤ log (2 * exp x) := Real.log_le_log (by positivity) + (by linarith [Real.one_le_exp_iff.mpr hx]) + _ = _ := by rw [Real.log_mul (by norm_num) (exp_pos _).ne', Real.log_exp] + +theorem log_norm_growth_of_norm_growth {F : ℂ → ℂ} + (hF : ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖F s‖ ≤ exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ))) : + ∃ D : ℝ, 0 < D ∧ ∀ s : ℂ, + log (1 + ‖F s‖) ≤ D * (1 + ‖s‖) ^ (3 / 2 : ℝ) := by + obtain ⟨C, hC, hF⟩ := hF + refine ⟨C + log 2, by positivity, fun s => ?_⟩ + have hpow1 : 1 ≤ (1 + ‖s‖) ^ (3 / 2 : ℝ) := + one_le_rpow (le_add_of_nonneg_right (norm_nonneg _)) (by norm_num) + have hlog2 : 0 ≤ log 2 := by positivity + have hlog := log_one_add_le_log_two_add (norm_nonneg _) (by positivity) (hF s) + have hmul := mul_le_mul_of_nonneg_left hpow1 hlog2 + nlinarith + +end WeightedTorusJets + +namespace WeightedTorusJets + +open Filter Set MeasureTheory _root_.Real + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] + +omit [NormedSpace ℂ E] in +lemma weighted_norm_integral_le_moment (f : ℝ → E) {p C a R : ℝ} + (hp : 0 < p) (hR : 0 ≤ R) (ha : a ≤ R) + (hf : ∀ t : ℝ, 1 ≤ t → ‖f t‖ ≤ C * exp (-p * t)) : + (∫ t : ℝ in Ioi 1, t ^ a * ‖f t‖) ≤ + C * (∫ t : ℝ in Ioi 1, t ^ R * exp (-p * t)) := by + rw [← integral_const_mul] + apply integral_mono_of_nonneg + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact mul_nonneg (rpow_nonneg (zero_lt_one.trans ht).le _) (norm_nonneg _) + · exact (exponential_moment_integrable hp hR).const_mul C + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + calc + _ ≤ t ^ R * (C * exp (-p * t)) := + mul_le_mul (rpow_le_rpow_of_exponent_le ht.le ha) (hf t ht.le) + (norm_nonneg _) (rpow_nonneg (zero_lt_one.trans ht).le _) + _ = _ := by ring + +theorem norm_Lambda_zero_growth_of_exp_bounds (P : WeakFEPair E) + (hf : ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ + ∀ t : ℝ, 1 ≤ t → ‖P.f t - P.f₀‖ ≤ C * exp (-p * t)) + (hg : ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ + ∀ t : ℝ, 1 ≤ t → ‖P.g t - P.g₀‖ ≤ C * exp (-p * t)) : + ∃ B : ℝ, 0 < B ∧ ∀ s : ℂ, + ‖P.Λ₀ s‖ ≤ exp (B * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := by + obtain ⟨pf, hpf, Cf, hCf, hf⟩ := hf + obtain ⟨pg, hpg, Cg, hCg, hg⟩ := hg + obtain ⟨Ef, hEf, hEf_bound⟩ := exponential_moment_growth hpf + obtain ⟨Eg, hEg, hEg_bound⟩ := exponential_moment_growth hpg + let D := Ef + Eg + let K := (2 + |P.k|) ^ (3 / 2 : ℝ) + let A := Cf + ‖P.ε‖ * Cg + have hD : 0 < D := by dsimp [D]; positivity + have hK : 0 < K := by dsimp [K]; positivity + have hA : 0 < A := by dsimp [A]; positivity + refine ⟨A + D * K, by positivity, ?_⟩ + intro s + let R := 1 + |P.k| + ‖s‖ + let r := (1 + ‖s‖) ^ (3 / 2 : ℝ) + have hR : 0 ≤ R := by dsimp [R]; positivity + have hr : 0 ≤ r := by dsimp [r]; positivity + have hr1 : 1 ≤ r := one_le_rpow (by simp) (by norm_num) + have hfexp : s.re - 1 ≤ R := by + have := Complex.re_le_norm s + dsimp [R] + linarith [abs_nonneg P.k] + have hgexp : P.k - s.re - 1 ≤ R := by + have := (neg_le_abs s.re).trans (Complex.abs_re_le_norm s) + dsimp [R] + linarith [le_abs_self P.k] + have hweight : (1 + R) ^ (3 / 2 : ℝ) ≤ K * r := by + calc + _ ≤ ((2 + |P.k|) * (1 + ‖s‖)) ^ (3 / 2 : ℝ) := by + apply rpow_le_rpow (by positivity) _ (by norm_num) + dsimp [R] + nlinarith [abs_nonneg P.k, norm_nonneg s] + _ = _ := by rw [mul_rpow (by positivity) (by positivity)] + have hEfm : Ef * (1 + R) ^ (3 / 2 : ℝ) ≤ D * K * r := by + have h1 := mul_le_mul_of_nonneg_left hweight hEf.le + have h2 := mul_le_mul_of_nonneg_right (show Ef ≤ D by dsimp [D]; linarith) + (mul_nonneg hK.le hr) + nlinarith + have hEgm : Eg * (1 + R) ^ (3 / 2 : ℝ) ≤ D * K * r := by + have h1 := mul_le_mul_of_nonneg_left hweight hEg.le + have h2 := mul_le_mul_of_nonneg_right (show Eg ≤ D by dsimp [D]; linarith) + (mul_nonneg hK.le hr) + nlinarith + have hfint : (∫ t : ℝ in Ioi 1, t ^ (s.re - 1) * ‖P.f t - P.f₀‖) ≤ + Cf * exp (D * K * r) := by + apply (weighted_norm_integral_le_moment _ hpf hR hfexp hf).trans + exact mul_le_mul_of_nonneg_left + ((hEf_bound R hR).trans (exp_le_exp.mpr hEfm)) hCf.le + have hgint : (∫ t : ℝ in Ioi 1, t ^ (P.k - s.re - 1) * ‖P.g t - P.g₀‖) ≤ + Cg * exp (D * K * r) := by + apply (weighted_norm_integral_le_moment _ hpg hR hgexp hg).trans + exact mul_le_mul_of_nonneg_left + ((hEg_bound R hR).trans (exp_le_exp.mpr hEgm)) hCg.le + have hAexp : A ≤ exp (A * r) := by + have h1 := mul_le_mul_of_nonneg_left hr1 hA.le + exact (by linarith : A ≤ A * r + 1).trans (add_one_le_exp _) + calc + ‖P.Λ₀ s‖ ≤ Cf * exp (D * K * r) + ‖P.ε‖ * (Cg * exp (D * K * r)) := + (norm_Lambda_zero_le_top_integrals P s).trans + (add_le_add hfint (mul_le_mul_of_nonneg_left hgint (norm_nonneg _))) + _ = A * exp (D * K * r) := by dsimp [A]; ring + _ ≤ exp (A * r) * exp (D * K * r) := + mul_le_mul_of_nonneg_right hAexp (exp_nonneg _) + _ = _ := by rw [← exp_add]; congr 1; dsimp [r]; ring + +end WeightedTorusJets + +open Filter Set Asymptotics + +namespace WeightedTorusJets + +theorem exists_global_exp_bound {E : Type*} [NormedAddCommGroup E] + {f : ℝ → E} {p : ℝ} (hf : ContinuousOn f (Ici 1)) + (hdecay : f =O[atTop] (fun t : ℝ => Real.exp (-p * t))) : + ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → ‖f t‖ ≤ C * Real.exp (-p * t) := by + obtain ⟨A, _, hA⟩ := hdecay.exists_pos + obtain ⟨T, hT⟩ := eventually_atTop.mp hA.bound + have hcompact : ContinuousOn (fun t => ‖f t‖ / Real.exp (-p * t)) + (Icc 1 (max 1 T)) := by + apply (hf.mono fun _ ht => ht.1).norm.div + · fun_prop + · exact fun _ _ => Real.exp_ne_zero _ + obtain ⟨B, hB⟩ := isCompact_Icc.exists_bound_of_continuousOn hcompact + refine ⟨max 1 (max A B), lt_of_lt_of_le zero_lt_one (le_max_left _ _), ?_⟩ + intro t ht + by_cases hlarge : T ≤ t + · calc + ‖f t‖ ≤ A * Real.exp (-p * t) := by + simpa only [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] using hT t hlarge + _ ≤ max 1 (max A B) * Real.exp (-p * t) := + mul_le_mul_of_nonneg_right ((le_max_left A B).trans (le_max_right _ _)) + (Real.exp_pos _).le + · have hsmall := hB t ⟨ht, (le_of_not_ge hlarge).trans (le_max_right _ _)⟩ + rw [Real.norm_eq_abs, abs_of_nonneg (div_nonneg (norm_nonneg _) (Real.exp_pos _).le)] + at hsmall + calc + ‖f t‖ ≤ B * Real.exp (-p * t) := (div_le_iff₀ (Real.exp_pos _)).mp hsmall + _ ≤ max 1 (max A B) * Real.exp (-p * t) := + mul_le_mul_of_nonneg_right ((le_max_right A B).trans (le_max_right _ _)) + (Real.exp_pos _).le + +theorem exists_evenKernel_sub_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖HurwitzZeta.evenKernel a t - (if a = 0 then 1 else 0)‖ ≤ + C * Real.exp (-p * t) := by + obtain ⟨p, hp, hdecay⟩ := HurwitzZeta.isBigO_atTop_evenKernel_sub a + refine ⟨p, hp, exists_global_exp_bound ?_ hdecay⟩ + exact ((HurwitzZeta.continuousOn_evenKernel a).sub continuousOn_const).mono + fun t ht => (show (0 : ℝ) < t from lt_of_lt_of_le zero_lt_one ht) + +theorem exists_cosKernel_sub_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖HurwitzZeta.cosKernel a t - 1‖ ≤ C * Real.exp (-p * t) := by + obtain ⟨p, hp, hdecay⟩ := HurwitzZeta.isBigO_atTop_cosKernel_sub a + refine ⟨p, hp, exists_global_exp_bound ?_ hdecay⟩ + exact ((HurwitzZeta.continuousOn_cosKernel a).sub continuousOn_const).mono + fun t ht => (show (0 : ℝ) < t from lt_of_lt_of_le zero_lt_one ht) + +theorem exists_oddKernel_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖HurwitzZeta.oddKernel a t‖ ≤ C * Real.exp (-p * t) := by + obtain ⟨p, hp, hdecay⟩ := HurwitzZeta.isBigO_atTop_oddKernel a + refine ⟨p, hp, exists_global_exp_bound ?_ hdecay⟩ + exact (HurwitzZeta.continuousOn_oddKernel a).mono + fun t ht => (show (0 : ℝ) < t from lt_of_lt_of_le zero_lt_one ht) + +theorem exists_sinKernel_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖HurwitzZeta.sinKernel a t‖ ≤ C * Real.exp (-p * t) := by + obtain ⟨p, hp, hdecay⟩ := HurwitzZeta.isBigO_atTop_sinKernel a + refine ⟨p, hp, exists_global_exp_bound ?_ hdecay⟩ + exact (HurwitzZeta.continuousOn_sinKernel a).mono + fun t ht => (show (0 : ℝ) < t from lt_of_lt_of_le zero_lt_one ht) + +theorem exists_hurwitzEvenFEPair_f_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖(HurwitzZeta.hurwitzEvenFEPair a).f t - (HurwitzZeta.hurwitzEvenFEPair a).f₀‖ ≤ + C * Real.exp (-p * t) := by + obtain ⟨p, hp, C, hC, hbound⟩ := exists_evenKernel_sub_exp_bound a + refine ⟨p, hp, C, hC, fun t ht => ?_⟩ + by_cases ha : a = 0 <;> + simpa [HurwitzZeta.hurwitzEvenFEPair, ha, ← Complex.ofReal_one, + ← Complex.ofReal_sub] using hbound t ht + +theorem exists_hurwitzEvenFEPair_g_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖(HurwitzZeta.hurwitzEvenFEPair a).g t - (HurwitzZeta.hurwitzEvenFEPair a).g₀‖ ≤ + C * Real.exp (-p * t) := by + obtain ⟨p, hp, C, hC, hbound⟩ := exists_cosKernel_sub_exp_bound a + refine ⟨p, hp, C, hC, fun t ht => ?_⟩ + simpa [HurwitzZeta.hurwitzEvenFEPair, ← Complex.ofReal_one, + ← Complex.ofReal_sub] using hbound t ht + +theorem exists_hurwitzOddFEPair_f_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖(HurwitzZeta.hurwitzOddFEPair a).f t - (HurwitzZeta.hurwitzOddFEPair a).f₀‖ ≤ + C * Real.exp (-p * t) := by + obtain ⟨p, hp, C, hC, hbound⟩ := exists_oddKernel_exp_bound a + refine ⟨p, hp, C, hC, fun t ht => ?_⟩ + simpa [HurwitzZeta.hurwitzOddFEPair] using hbound t ht + +theorem exists_hurwitzOddFEPair_g_exp_bound (a : UnitAddCircle) : + ∃ p : ℝ, 0 < p ∧ ∃ C : ℝ, 0 < C ∧ ∀ t : ℝ, 1 ≤ t → + ‖(HurwitzZeta.hurwitzOddFEPair a).g t - (HurwitzZeta.hurwitzOddFEPair a).g₀‖ ≤ + C * Real.exp (-p * t) := by + obtain ⟨p, hp, C, hC, hbound⟩ := exists_sinKernel_exp_bound a + refine ⟨p, hp, C, hC, fun t ht => ?_⟩ + simpa [HurwitzZeta.hurwitzOddFEPair] using hbound t ht + + + +theorem norm_growth_half_shift {F : ℂ → ℂ} + (hF : ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖F s‖ ≤ Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ))) + {b : ℂ} (hb : ‖b‖ ≤ 1) : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖F ((s + b) / 2) / 2‖ ≤ Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := by + obtain ⟨C, hC, hF⟩ := hF + refine ⟨4 * C, by positivity, fun s => ?_⟩ + have harg : 1 + ‖(s + b) / 2‖ ≤ 2 * (1 + ‖s‖) := by + rw [norm_div, Complex.norm_ofNat] + have := norm_add_le s b + nlinarith [norm_nonneg s] + have hpow : (1 + ‖(s + b) / 2‖) ^ (3 / 2 : ℝ) ≤ + 4 * (1 + ‖s‖) ^ (3 / 2 : ℝ) := by + calc + _ ≤ (2 * (1 + ‖s‖)) ^ (3 / 2 : ℝ) := + Real.rpow_le_rpow (by positivity) harg (by norm_num) + _ = (2 : ℝ) ^ (3 / 2 : ℝ) * (1 + ‖s‖) ^ (3 / 2 : ℝ) := + Real.mul_rpow (by norm_num) (by positivity) + _ ≤ _ := by + apply mul_le_mul_of_nonneg_right _ (by positivity) + calc + (2 : ℝ) ^ (3 / 2 : ℝ) ≤ (2 : ℝ) ^ (2 : ℝ) := + Real.rpow_le_rpow_of_exponent_le (by norm_num) (by norm_num) + _ = 4 := by norm_num + calc + _ ≤ ‖F ((s + b) / 2)‖ := by + rw [norm_div, Complex.norm_ofNat] + exact div_le_self (norm_nonneg _) (by norm_num) + _ ≤ Real.exp (C * (1 + ‖(s + b) / 2‖) ^ (3 / 2 : ℝ)) := hF _ + _ ≤ _ := by + apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left hpow hC.le] + +theorem norm_completedHurwitzZetaEven_zero_growth_of_Lambda_zero_growth + (a : UnitAddCircle) + (hF : ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖(HurwitzZeta.hurwitzEvenFEPair a).Λ₀ s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ))) : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖HurwitzZeta.completedHurwitzZetaEven₀ a s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := by + simpa [HurwitzZeta.completedHurwitzZetaEven₀] using + norm_growth_half_shift hF (b := 0) (by simp) + +theorem norm_completedHurwitzZetaOdd_growth_of_Lambda_zero_growth + (a : UnitAddCircle) + (hF : ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖(HurwitzZeta.hurwitzOddFEPair a).Λ₀ s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ))) : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖HurwitzZeta.completedHurwitzZetaOdd a s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := by + have hΛ : (HurwitzZeta.hurwitzOddFEPair a).Λ = + (HurwitzZeta.hurwitzOddFEPair a).Λ₀ := by + ext s + simp [WeakFEPair.Λ, HurwitzZeta.hurwitzOddFEPair] + simpa only [HurwitzZeta.completedHurwitzZetaOdd, hΛ] using + norm_growth_half_shift hF (b := 1) (by simp) + + + +theorem exists_completedHurwitzZetaEven_zero_growth (a : UnitAddCircle) : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖HurwitzZeta.completedHurwitzZetaEven₀ a s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := + norm_completedHurwitzZetaEven_zero_growth_of_Lambda_zero_growth a + (norm_Lambda_zero_growth_of_exp_bounds (HurwitzZeta.hurwitzEvenFEPair a) + (exists_hurwitzEvenFEPair_f_exp_bound a) (exists_hurwitzEvenFEPair_g_exp_bound a)) + +theorem exists_completedHurwitzZetaOdd_growth (a : UnitAddCircle) : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℂ, + ‖HurwitzZeta.completedHurwitzZetaOdd a s‖ ≤ + Real.exp (C * (1 + ‖s‖) ^ (3 / 2 : ℝ)) := + norm_completedHurwitzZetaOdd_growth_of_Lambda_zero_growth a + (norm_Lambda_zero_growth_of_exp_bounds (HurwitzZeta.hurwitzOddFEPair a) + (exists_hurwitzOddFEPair_f_exp_bound a) (exists_hurwitzOddFEPair_g_exp_bound a)) + +end WeightedTorusJets + +end +end AnalyticAssemblyScope +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/MonicSMulRegularQuotientMapC.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/MonicSMulRegularQuotientMapC.lean new file mode 100644 index 0000000000000000000000000000000000000000..d0a90cb868a99226f48f74b6d458efcd7026c7f9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/MonicSMulRegularQuotientMapC.lean @@ -0,0 +1,520 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section + +open Polynomial + +namespace WeightedTorusJets + +theorem monic_isSMulRegular_quotient_map_C {A : Type*} [CommRing A] + (I : Ideal A) {y : A[X]} (hy : y.Monic) : + IsSMulRegular (A[X] ⧸ I.map (Polynomial.C : A →+* A[X])) y := by + let e := I.polynomialQuotientEquivQuotientPolynomial.symm + apply (e.toEquiv.isSMulRegular_congr (r := y) + (s := y.map (Ideal.Quotient.mk I)) ?_).mpr + · exact (hy.map (Ideal.Quotient.mk I)).isRegular.left + · intro z + change e (Ideal.Quotient.mk _ y * z) = y.map (Ideal.Quotient.mk I) * e z + rw [map_mul] + congr 1 + + + +open Ideal IsLocalRing Polynomial RingTheory.Sequence + +theorem exists_regular_generators_polynomial_localization + {A : Type*} [CommRing A] [IsLocalRing A] + (rs : List A) (hreg : IsRegular A rs) (hgen : Ideal.ofList rs = maximalIdeal A) + (p : Ideal A[X]) [p.IsPrime] (hclosed : p.comap Polynomial.C = maximalIdeal A) : + ∃ ss : List (Localization.AtPrime p), + IsRegular (Localization.AtPrime p) ss ∧ + Ideal.ofList ss = maximalIdeal (Localization.AtPrime p) := by + let S := Localization.AtPrime p + let rsC := rs.map (Polynomial.C : A →+* A[X]) + let q := (maximalIdeal A).map (Polynomial.C : A →+* A[X]) + have hweak : IsWeaklyRegular A[X] rsC := by + simpa only [Polynomial.algebraMap_eq] using + hreg.toIsWeaklyRegular.of_flat (S := A[X]) + have hgenC : Ideal.ofList rsC = q := by + rw [show rsC = rs.map (Polynomial.C : A →+* A[X]) from rfl, + ← Ideal.map_ofList, hgen] + have hqle : q ≤ p := by + simpa only [q, ← hclosed] using (Ideal.map_comap_le : (p.comap C).map C ≤ p) + by_cases hpq : p = q + · refine ⟨rsC.map (algebraMap A[X] S), + hweak.isRegular_of_isLocalization_of_mem S p (fun r hr => ?_), ?_⟩ + · apply hqle + rw [← hgenC] + exact Ideal.subset_span hr + · rw [← Ideal.map_ofList, hgenC, ← hpq, Localization.AtPrime.map_eq_maximalIdeal] + · have hm : (p.comap C).IsMaximal := by + rw [hclosed] + infer_instance + obtain ⟨y, hy, hpy⟩ := Polynomial.exists_monic_span_sup_map_eq A p hm + (by simpa only [hclosed] using hpq) + have hgens : Ideal.ofList (rsC ++ [y]) = p := by + rw [Ideal.ofList_append, Ideal.ofList_singleton, hgenC] + simpa only [q, hclosed] using hpy.symm + have hweak' : IsWeaklyRegular A[X] (rsC ++ [y]) := by + rw [isWeaklyRegular_append_iff, isWeaklyRegular_singleton_iff] + refine ⟨hweak, ?_⟩ + rw [Ideal.smul_eq_mul, Ideal.mul_top, hgenC] + exact monic_isSMulRegular_quotient_map_C (maximalIdeal A) hy + refine ⟨(rsC ++ [y]).map (algebraMap A[X] S), + hweak'.isRegular_of_isLocalization_of_mem S p (fun r hr => ?_), ?_⟩ + · rw [← hgens] + exact Ideal.subset_span hr + · rw [← Ideal.map_ofList, hgens, Localization.AtPrime.map_eq_maximalIdeal] + +end WeightedTorusJets + +open Ideal RingTheory.Sequence IsLocalRing + +namespace WeightedTorusJets + +theorem regular_maximal_generators_of_ringEquiv {R S : Type*} [CommRing R] [CommRing S] + [IsLocalRing R] [IsLocalRing S] (e : R ≃+* S) {rs : List R} + (hreg : IsRegular R rs) (hgen : Ideal.ofList rs = maximalIdeal R) : + IsRegular S (rs.map e) ∧ Ideal.ofList (rs.map e) = maximalIdeal S := by + constructor + · apply (e.toAddEquiv.isRegular_congr ?_).mp hreg + exact List.forall₂_map_right_iff.mpr <| + List.forall₂_same.mpr fun r _ z ↦ e.map_mul r z + · change Ideal.ofList (rs.map e.toRingHom) = maximalIdeal S + rw [← Ideal.map_ofList, hgen] + exact map_ringEquiv_maximalIdeal e + +theorem exists_regular_maximal_generators_field_localization (K : Type*) [Field K] + (p : Ideal K) [p.IsPrime] : + ∃ rs : List (Localization.AtPrime p), IsRegular (Localization.AtPrime p) rs ∧ + Ideal.ofList rs = maximalIdeal (Localization.AtPrime p) := by + refine ⟨[], IsRegular.nil _ _, ?_⟩ + have hmap : p.map (algebraMap K (Localization.AtPrime p)) = ⊥ := by + exact (congrArg (Ideal.map (algebraMap K (Localization.AtPrime p))) + (Ideal.eq_bot_of_prime p)).trans Ideal.map_bot + rw [← Localization.AtPrime.map_eq_maximalIdeal, hmap] + simp + +theorem exists_regular_maximal_generators_localizations_of_ringEquiv + {R S : Type*} [CommRing R] [CommRing S] (e : R ≃+* S) + (hR : ∀ (p : Ideal R) [p.IsPrime], + ∃ rs : List (Localization.AtPrime p), IsRegular (Localization.AtPrime p) rs ∧ + Ideal.ofList rs = maximalIdeal (Localization.AtPrime p)) + (p : Ideal S) [p.IsPrime] : + ∃ rs : List (Localization.AtPrime p), IsRegular (Localization.AtPrime p) rs ∧ + Ideal.ofList rs = maximalIdeal (Localization.AtPrime p) := by + obtain ⟨rs, hreg, hgen⟩ := hR (p.comap e) + let E := IsLocalization.ringEquivOfRingEquiv + (Localization.AtPrime (p.comap e)) (Localization.AtPrime p) + e (e.map_primeCompl_comap_eq p) + exact ⟨rs.map E, regular_maximal_generators_of_ringEquiv E hreg hgen⟩ + + + +open Ideal RingTheory.Sequence IsLocalRing Polynomial + +theorem exists_regular_maximal_generators_polynomial_localizations + {R : Type*} [CommRing R] + (hR : ∀ (p : Ideal R) [p.IsPrime], + ∃ rs : List (Localization.AtPrime p), IsRegular (Localization.AtPrime p) rs ∧ + Ideal.ofList rs = maximalIdeal (Localization.AtPrime p)) + (p : Ideal R[X]) [p.IsPrime] : + ∃ rs : List (Localization.AtPrime p), IsRegular (Localization.AtPrime p) rs ∧ + Ideal.ofList rs = maximalIdeal (Localization.AtPrime p) := by + let q := p.comap C + let S := (Localization.AtPrime q)[X] + let pc := Submonoid.map Polynomial.C.toMonoidHom q.primeCompl + let : Algebra R[X] S := Polynomial.algebra R (Localization.AtPrime q) + have : IsLocalization pc S := Polynomial.isLocalization _ _ + let pS := p.map (algebraMap R[X] S) + have disj : Disjoint (pc : Set R[X]) (p : Set R[X]) := by + simpa [pc, q] using! Set.disjoint_image_left.mpr + (Set.disjoint_compl_left_iff_subset.mpr (fun _ a ↦ a)) + have : pS.IsPrime := IsLocalization.isPrime_of_isPrime_disjoint pc _ _ ‹_› disj + have : IsLocalization.AtPrime (Localization.AtPrime pS) p := by + convert IsLocalization.isLocalization_isLocalization_atPrime_isLocalization pc + (Localization.AtPrime pS) pS + exact (IsLocalization.under_map_of_isPrime_disjoint pc _ ‹_› disj).symm + have hclosed : comap C pS = maximalIdeal (Localization.AtPrime q) := by + rw [← IsLocalization.map_under q.primeCompl _ (comap C pS), + ← IsLocalization.map_under q.primeCompl _ (maximalIdeal (Localization.AtPrime q))] + simp only [comap_comap, S, pS] + rw [← Polynomial.algebraMap_eq (R := Localization.AtPrime q), + ← IsScalarTower.algebraMap_eq R (Localization.AtPrime q) (Localization.AtPrime q)[X], + IsScalarTower.algebraMap_eq R R[X] (Localization.AtPrime q)[X], ← comap_comap, + ← Ideal.under_def R[X], IsLocalization.under_map_of_isPrime_disjoint pc _ ‹_› disj] + simp [q, IsLocalization.AtPrime.under_maximalIdeal (Localization.AtPrime q) q] + obtain ⟨rs, hreg, hgen⟩ := hR q + obtain ⟨ss, hsreg, hsgen⟩ := + exists_regular_generators_polynomial_localization rs hreg hgen pS hclosed + let e := (IsLocalization.algEquiv p.primeCompl + (Localization.AtPrime pS) (Localization.AtPrime p)).toRingEquiv + exact ⟨ss.map e, regular_maximal_generators_of_ringEquiv e hsreg hsgen⟩ + +theorem exists_regular_maximal_generators_mvPolynomial_localization + (K : Type*) [Field K] (σ : Type*) [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + ∃ rs : List (Localization.AtPrime p), IsRegular (Localization.AtPrime p) rs ∧ + Ideal.ofList rs = maximalIdeal (Localization.AtPrime p) := by + revert p + induction σ using Finite.induction_empty_option with + | of_equiv e IH => + exact exists_regular_maximal_generators_localizations_of_ringEquiv + (MvPolynomial.renameEquiv K e).toRingEquiv IH + | h_empty => + exact exists_regular_maximal_generators_localizations_of_ringEquiv + (MvPolynomial.isEmptyRingEquiv K PEmpty).symm + (exists_regular_maximal_generators_field_localization K) + | h_option IH => + exact exists_regular_maximal_generators_localizations_of_ringEquiv + (MvPolynomial.optionEquivLeft K _).toRingEquiv.symm + (exists_regular_maximal_generators_polynomial_localizations IH) + +end WeightedTorusJets + +open Ideal RingTheory.Sequence +open scoped Pointwise + +namespace WeightedTorusJets + +theorem span_singleton_sup_eq_of_sub_mem {R : Type*} [CommRing R] + (J : Ideal R) {a b : R} (hdiff : a - b ∈ J) : + Ideal.span {a} ⊔ J = Ideal.span {b} ⊔ J := by + apply le_antisymm + · refine sup_le ((Ideal.span_singleton_le_iff_mem _).mpr ?_) le_sup_right + exact (Submodule.sub_mem_iff_left _ (Submodule.mem_sup_left (Ideal.mem_span_singleton_self b))).mp + (Submodule.mem_sup_right hdiff) + · refine sup_le ((Ideal.span_singleton_le_iff_mem _).mpr ?_) le_sup_right + exact (Submodule.sub_mem_iff_right _ (Submodule.mem_sup_left (Ideal.mem_span_singleton_self a))).mp + (Submodule.mem_sup_right hdiff) + +theorem isRegular_append_singleton_iff_sub_mem {R M : Type*} [CommRing R] + [AddCommGroup M] [Module R M] (rs : List R) {a b : R} + (hdiff : a - b ∈ Ideal.ofList rs) : + IsRegular M (rs ++ [a]) ↔ IsRegular M (rs ++ [b]) := by + have heq : Ideal.ofList (rs ++ [a]) = Ideal.ofList (rs ++ [b]) := by + simpa only [Ideal.ofList_append, Ideal.ofList_singleton, sup_comm] using + span_singleton_sup_eq_of_sub_mem (Ideal.ofList rs) hdiff + have hab : Ideal.Quotient.mk (Ideal.ofList rs) a = + Ideal.Quotient.mk (Ideal.ofList rs) b := + (Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mpr hdiff + simp only [RingTheory.Sequence.isRegular_iff, isWeaklyRegular_append_iff' M, List.map_singleton, hab, heq] + +theorem isRegular_cons_iff_sub_mem {R M : Type*} [CommRing R] [IsLocalRing R] + [AddCommGroup M] [Module R M] [IsNoetherian R M] (rs : List R) {a b : R} + (hdiff : a - b ∈ Ideal.ofList rs) : + IsRegular M (a :: rs) ↔ IsRegular M (b :: rs) := by + have hp (x : R) : IsRegular M (x :: rs) ↔ IsRegular M (rs ++ [x]) := + ⟨fun h => IsLocalRing.isRegular_of_perm h (List.perm_append_singleton x rs).symm, + fun h => IsLocalRing.isRegular_of_perm h (List.perm_append_singleton x rs)⟩ + exact (hp a).trans ((isRegular_append_singleton_iff_sub_mem rs hdiff).trans (hp b).symm) + +theorem exists_regular_sequence_of_mem_sup_annihilator {R M : Type*} [CommRing R] + [AddCommGroup M] [Module R M] (J : Ideal R) (rs : List R) + (hmem : ∀ r ∈ rs, r ∈ J ⊔ Module.annihilator R M) (hreg : IsRegular M rs) : + ∃ ss : List R, ss.length = rs.length ∧ (∀ s ∈ ss, s ∈ J) ∧ IsRegular M ss := by + have hrepresent : ∃ ss : List R, + List.Forall₂ (fun r s : R => ∀ m : M, r • m = s • m) rs ss ∧ + (∀ s ∈ ss, s ∈ J) := by + clear hreg + induction rs with + | nil => exact ⟨[], .nil, by simp⟩ + | cons r rs ih => + obtain ⟨s, hs, a, ha, hr⟩ := Submodule.mem_sup.mp (hmem r (by simp)) + obtain ⟨ss, hss, hssmem⟩ := ih (fun z hz => hmem z (by simp [hz])) + refine ⟨s :: ss, .cons ?_ hss, ?_⟩ + · intro m + rw [← hr, add_smul, Module.mem_annihilator.mp ha m, add_zero] + · intro z hz + rcases List.mem_cons.mp hz with rfl | hz + · exact hs + · exact hssmem z hz + obtain ⟨ss, hss, hssmem⟩ := hrepresent + exact ⟨ss, hss.length_eq.symm, hssmem, + ((AddEquiv.refl M).isRegular_congr hss).mp hreg⟩ + +theorem exists_regular_sequence_quotSMulTop_of_mem_sup {R M : Type*} [CommRing R] + [AddCommGroup M] [Module R M] (x : R) (J : Ideal R) (rs : List R) + (hmem : ∀ r ∈ rs, r ∈ Ideal.span {x} ⊔ J) + (hreg : IsRegular (QuotSMulTop x M) rs) : + ∃ ss : List R, ss.length = rs.length ∧ (∀ s ∈ ss, s ∈ J) ∧ + IsRegular (QuotSMulTop x M) ss := by + apply exists_regular_sequence_of_mem_sup_annihilator J rs _ hreg + intro r hr + exact (show Ideal.span {x} ⊔ J ≤ J ⊔ Module.annihilator R (QuotSMulTop x M) from + sup_le (le_sup_of_le_right ((Ideal.span_singleton_le_iff_mem _).mpr + (QuotSMulTop.mem_annihilator M x))) le_sup_left) (hmem r hr) + +end WeightedTorusJets + +open Ideal RingTheory.Sequence +open CategoryTheory Abelian + +universe u + +namespace WeightedTorusJets + +theorem exists_regular_sequence_quotient_of_regular_element {R : Type u} [CommRing R] + [IsNoetherianRing R] (M : ModuleCat.{u} R) [Module.Finite R M] {I : Ideal R} + (hI : I • (⊤ : Submodule R M) < ⊤) {x : R} (hxmem : x ∈ I) + (hx : IsSMulRegular M x) (n : ℕ) (rs : List R) (hlen : rs.length = n + 1) + (hmem : ∀ r ∈ rs, r ∈ I) (hreg : IsRegular M rs) : + ∃ ss : List R, ss.length = n ∧ (∀ r ∈ ss, r ∈ I) ∧ + IsRegular (QuotSMulTop x M) ss := by + let Q := ModuleCat.of R (R ⧸ I) + have hsupp : Module.support R Q = PrimeSpectrum.zeroLocus I := by + rw [Module.support_eq_zeroLocus, Ideal.annihilator_quotient] + have hext : ∀ i < n + 1, Subsingleton (Ext Q M i) := by + intro i hi + exact ModuleCat.subsingleton_ext_of_exists_isRegular I Q hsupp.subset M hI rs + hmem hreg i (hi.trans_eq hlen.symm) + have hext' : ∀ i < n, Subsingleton (Ext Q (ModuleCat.of R (QuotSMulTop x M)) i) := by + intro i hi + have hzero₁ := AddCommGrpCat.isZero_of_iff_subsingleton.mpr (hext i (by omega)) + have hzero₂ := AddCommGrpCat.isZero_of_iff_subsingleton.mpr (hext (i + 1) (by omega)) + exact AddCommGrpCat.subsingleton_of_isZero <| + ShortComplex.Exact.isZero_of_both_zeros + ((Ext.covariant_sequence_exact₃' Q hx.smulShortComplex_shortExact) i (i + 1) rfl) + (hzero₁.eq_zero_of_src _) (hzero₂.eq_zero_of_tgt _) + have hquot : I • (⊤ : Submodule R (QuotSMulTop x M)) ≠ ⊤ := by + intro htop + absurd congrArg (Submodule.comap (Submodule.mkQ _)) htop + simpa [Submodule.comap_smul_top_of_surjective I _ (Submodule.mkQ_surjective _), + Submodule.smul_mono_left ((span_singleton_le_iff_mem I).mpr hxmem), + ← Submodule.ideal_span_singleton_smul] using hI.ne + exact ModuleCat.exists_isRegular_of_exists_subsingleton_ext I n + (ModuleCat.of R (QuotSMulTop x M)) hquot.lt_top Q hsupp hext' + +end WeightedTorusJets + +open scoped BigOperators + +namespace WeightedTorusJets + +theorem exists_add_not_mem_of_prime_antichain {R : Type*} [CommRing R] + (s : Finset (Ideal R)) (hp : ∀ P ∈ s, P.IsPrime) + (hanti : ∀ P ∈ s, ∀ Q ∈ s, P ≠ Q → ¬ P ≤ Q) + (a : R) (J : Ideal R) + (havoid : ∀ P ∈ s, ¬ (Ideal.span {a} ⊔ J ≤ P)) : + ∃ b ∈ J, ∀ P ∈ s, a + b ∉ P := by + classical + have hex (P : Ideal R) (hP : P ∈ s) : + ∃ b : R, b ∈ J ∧ (∀ Q ∈ s, Q ≠ P → b ∈ Q) ∧ + (a ∈ P → b ∉ P) ∧ (a ∉ P → b = 0) := by + by_cases ha : a ∈ P + · have hJ : ¬ J ≤ P := by + intro h + exact havoid P hP (sup_le (P.span_singleton_le_iff_mem.mpr ha) h) + have hi : ¬ (s.erase P).inf id ≤ P := by + rw [(hp P hP).inf_le'] + rintro ⟨Q, hQ, hQP⟩ + have hm := Finset.mem_erase.mp hQ + exact hanti Q hm.2 P hP hm.1 hQP + have hn : ¬ J ⊓ (s.erase P).inf id ≤ P := by + rw [(hp P hP).inf_le] + exact not_or.mpr ⟨hJ, hi⟩ + obtain ⟨b, hb, hbp⟩ := SetLike.not_le_iff_exists.mp hn + refine ⟨b, hb.1, ?_, (fun _ => hbp), (fun h => (h ha).elim)⟩ + intro Q hQ hQP + exact (Finset.inf_le (f := id) (Finset.mem_erase.mpr ⟨hQP, hQ⟩)) hb.2 + · exact ⟨0, J.zero_mem, fun Q _ _ => Q.zero_mem, (fun h => (ha h).elim), (fun _ => rfl)⟩ + choose b hbJ hbQ hbP hbzero using hex + let v : s → R := fun P => b P P.property + refine ⟨∑ P : s, v P, J.sum_mem (fun P _ => hbJ P P.property), ?_⟩ + intro P hP ha + let p : s := ⟨P, hP⟩ + have hrest : (∑ Q ∈ (Finset.univ : Finset s).erase p, v Q) ∈ P := by + apply P.sum_mem + intro Q hQ + have hQp : (Q : Ideal R) ≠ P := by + intro heq + exact (Finset.mem_erase.mp hQ).1 (Subtype.ext heq) + exact hbQ Q Q.property P hP hQp.symm + have hsum : (∑ Q : s, v Q) = v p + ∑ Q ∈ (Finset.univ : Finset s).erase p, v Q := by + symm + exact Finset.add_sum_erase _ _ (Finset.mem_univ p) + rw [hsum] at ha + by_cases haP : a ∈ P + · have hv : v p ∈ P := by + have h := P.sub_mem ha (P.add_mem haP hrest) + simpa [sub_eq_add_neg, add_assoc, add_left_comm, add_comm] using h + exact hbP P hP haP hv + · have hv : v p = 0 := hbzero P hP haP + exact haP (by simpa [hv] using P.sub_mem ha hrest) + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +theorem exists_add_not_mem_of_finite_prime {R : Type*} [CommRing R] + (s : Finset (Ideal R)) (hp : ∀ P ∈ s, P.IsPrime) (a : R) (J : Ideal R) + (havoid : ∀ P ∈ s, ¬ (Ideal.span {a} ⊔ J ≤ P)) : + ∃ b ∈ J, ∀ P ∈ s, a + b ∉ P := by + classical + let t := s.filter (Maximal (· ∈ s)) + have htanti : ∀ P ∈ t, ∀ Q ∈ t, P ≠ Q → ¬ P ≤ Q := by + intro P hP Q hQ hne hle + exact hne (le_antisymm hle + ((Finset.mem_filter.mp hP).2.2 (Finset.mem_filter.mp hQ).1 hle)) + obtain ⟨b, hb, hbavoid⟩ := exists_add_not_mem_of_prime_antichain t + (fun P hP ↦ hp P (Finset.mem_filter.mp hP).1) htanti a J + (fun P hP ↦ havoid P (Finset.mem_filter.mp hP).1) + refine ⟨b, hb, fun P hP hab ↦ ?_⟩ + obtain ⟨Q, hPQ, hQ⟩ := s.exists_le_maximal hP + exact hbavoid Q (Finset.mem_filter.mpr ⟨hQ.1, hQ⟩) (hPQ hab) + +theorem exists_add_isSMulRegular {R M : Type*} [CommRing R] [IsNoetherianRing R] + [AddCommGroup M] [Module R M] [IsNoetherian R M] (a : R) (J : Ideal R) + (havoid : ∀ P ∈ associatedPrimes R M, ¬ (Ideal.span {a} ⊔ J ≤ P)) : + ∃ b ∈ J, IsSMulRegular M (a + b) := by + classical + have hfinite := associatedPrimes.finite R M + obtain ⟨b, hb, hbavoid⟩ := exists_add_not_mem_of_finite_prime hfinite.toFinset + (fun P hP ↦ (hfinite.mem_toFinset.mp hP).isPrime) a J + (fun P hP ↦ havoid P (hfinite.mem_toFinset.mp hP)) + refine ⟨b, hb, ?_⟩ + have hnot : a + b ∉ ⋃ P ∈ associatedPrimes R M, (P : Set R) := by + intro h + obtain ⟨P, hP⟩ := Set.mem_iUnion.mp h + obtain ⟨hPass, hmem⟩ := Set.mem_iUnion.mp hP + exact hbavoid P (hfinite.mem_toFinset.mpr hPass) hmem + simpa only [biUnion_associatedPrimes_eq_compl_regular R M, Set.mem_compl_iff, + Set.mem_ofPred_eq, not_not] using hnot + +theorem exists_add_isSMulRegular_of_exists {R M : Type*} [CommRing R] [IsNoetherianRing R] + [AddCommGroup M] [Module R M] [IsNoetherian R M] (a : R) (J : Ideal R) + (h : ∃ x ∈ Ideal.span {a} ⊔ J, IsSMulRegular M x) : + ∃ b ∈ J, IsSMulRegular M (a + b) := by + obtain ⟨x, hx, hxreg⟩ := h + apply exists_add_isSMulRegular a J + intro P hP hle + have hxnot : x ∉ ⋃ Q ∈ associatedPrimes R M, (Q : Set R) := by + simpa only [biUnion_associatedPrimes_eq_compl_regular R M, Set.mem_compl_iff, + Set.mem_ofPred_eq, not_not] using hxreg + exact hxnot (Set.mem_iUnion.mpr ⟨P, Set.mem_iUnion.mpr ⟨hP, hle hx⟩⟩) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +universe uReg + +theorem isRegular_of_exists_regular_sequence_in_ofList {R : Type uReg} [CommRing R] + [IsNoetherianRing R] [IsLocalRing R] (gs : List R) (M : Type uReg) + [AddCommGroup M] [Module R M] [Module.Finite R M] + (hproper : Ideal.ofList gs • (⊤ : Submodule R M) < ⊤) + (rs : List R) (hlen : rs.length = gs.length) + (hmem : ∀ r ∈ rs, r ∈ Ideal.ofList gs) (hreg : IsRegular M rs) : + IsRegular M gs := by + induction gs generalizing M rs with + | nil => + have hrs : rs = [] := List.length_eq_zero_iff.mp hlen + subst rs + exact hreg + | cons a gs ih => + cases rs with + | nil => simp at hlen + | cons z zs => + obtain ⟨b, hb, hxreg⟩ := Geometry.exists_add_isSMulRegular_of_exists a + (Ideal.ofList gs) ⟨z, by simpa only [Ideal.ofList_cons] using hmem z (by simp), + ((isRegular_cons_iff M z zs).mp hreg).1⟩ + let x := a + b + have hdiff : x - a ∈ Ideal.ofList gs := by + simpa only [x, add_sub_cancel_left] using hb + have heq : Ideal.ofList (x :: gs) = Ideal.ofList (a :: gs) := by + simpa only [Ideal.ofList_cons] using + span_singleton_sup_eq_of_sub_mem (Ideal.ofList gs) hdiff + have hxmem : x ∈ Ideal.ofList (a :: gs) := + heq ▸ Ideal.subset_span (by simp) + obtain ⟨ss, hsslen, hssmem, hssreg⟩ := + exists_regular_sequence_quotient_of_regular_element (ModuleCat.of R M) hproper + hxmem hxreg gs.length (z :: zs) hlen hmem hreg + obtain ⟨ts, htslen, htsmem, htsreg⟩ := + exists_regular_sequence_quotSMulTop_of_mem_sup x (Ideal.ofList gs) ss + (fun r hr => by simpa only [← heq, Ideal.ofList_cons] using hssmem r hr) hssreg + have hquot : Ideal.ofList gs • (⊤ : Submodule R (QuotSMulTop x M)) < ⊤ := by + apply lt_top_iff_ne_top.mpr + intro htop + have htop' := (Submodule.top_eq_ofList_cons_smul_iff (M := M) + (r := x) (rs := gs)).mpr htop.symm + rw [heq] at htop' + exact hproper.ne htop'.symm + have htail := ih (QuotSMulTop x M) hquot ts (htslen.trans hsslen) htsmem htsreg + exact (isRegular_cons_iff_sub_mem gs hdiff).mp + ((isRegular_cons_iff M x gs).mpr ⟨hxreg, htail⟩) + +end WeightedTorusJets + +namespace WeightedTorusJets +open IsLocalRing +theorem exists_regular_sequence_of_le_radical {R : Type u} [CommRing R] + [IsNoetherianRing R] (M : ModuleCat.{u} R) [Module.Finite R M] {I J : Ideal R} + (hI : I • (⊤ : Submodule R M) < ⊤) (hJ : J • (⊤ : Submodule R M) < ⊤) + (hIJ : I ≤ J.radical) (rs : List R) (hmem : ∀ r ∈ rs, r ∈ I) + (hreg : IsRegular M rs) : + ∃ ss : List R, ss.length = rs.length ∧ (∀ r ∈ ss, r ∈ J) ∧ IsRegular M ss := by + let Q := ModuleCat.of R (R ⧸ J) + have hsupp : Module.support R Q = PrimeSpectrum.zeroLocus J := by + rw [Module.support_eq_zeroLocus, Ideal.annihilator_quotient] + have hsub : Module.support R Q ⊆ PrimeSpectrum.zeroLocus I := by + rw [hsupp, PrimeSpectrum.zeroLocus_subset_zeroLocus_iff] + exact hIJ + have hext := ModuleCat.subsingleton_ext_of_exists_isRegular I Q hsub M hI rs hmem hreg + exact ModuleCat.exists_isRegular_of_exists_subsingleton_ext J rs.length M hJ Q hsupp hext + +theorem regular_maximal_generators_length {R : Type*} [CommRing R] + [IsNoetherianRing R] [IsLocalRing R] {rs : List R} + (hreg : IsRegular R rs) (hgen : Ideal.ofList rs = maximalIdeal R) : + (rs.length : ℕ∞) = (maximalIdeal R).height := by + let := Ideal.Quotient.field (maximalIdeal R) + have h := ringKrullDim_add_length_eq_ringKrullDim_of_isRegular rs hreg + rw [hgen, ringKrullDim_eq_zero_of_field, zero_add, + ← maximalIdeal_height_eq_ringKrullDim] at h + exact_mod_cast h + +end WeightedTorusJets +namespace WeightedTorusJets + +universe uReg + +theorem isRegular_parameters_of_exists_regular_maximal_generators + {R : Type uReg} [CommRing R] [IsNoetherianRing R] [IsLocalRing R] + (hex : ∃ rs : List R, IsRegular R rs ∧ + Ideal.ofList rs = IsLocalRing.maximalIdeal R) + (fs : List R) (hrad : (Ideal.ofList fs).radical = IsLocalRing.maximalIdeal R) + (hlen : (fs.length : ℕ∞) = (IsLocalRing.maximalIdeal R).height) : + IsRegular R fs := by + obtain ⟨rs, hrsreg, hrsgen⟩ := hex + have hproper : Ideal.ofList fs ≠ ⊤ := by + intro htop + rw [htop, Ideal.radical_top] at hrad + exact (IsLocalRing.maximalIdeal.isMaximal R).ne_top hrad.symm + have hM : IsLocalRing.maximalIdeal R • (⊤ : Submodule R R) < ⊤ := by + simpa only [Ideal.smul_eq_mul, Ideal.mul_top] using + (IsLocalRing.maximalIdeal.isMaximal R).ne_top.lt_top + obtain ⟨ss, hsslen, hssmem, hssreg⟩ := exists_regular_sequence_of_le_radical + (ModuleCat.of R R) hM + (by simpa only [Ideal.smul_eq_mul, Ideal.mul_top] using hproper.lt_top) + (le_of_eq hrad.symm) rs + (fun r hr => hrsgen ▸ Ideal.subset_span hr) hrsreg + have hrslen : rs.length = fs.length := by + exact_mod_cast (regular_maximal_generators_length hrsreg hrsgen).trans hlen.symm + exact isRegular_of_exists_regular_sequence_in_ofList fs R + (by simpa only [Ideal.smul_eq_mul, Ideal.mul_top] using hproper.lt_top) + ss (hsslen.trans hrslen) hssmem hssreg + +end WeightedTorusJets + +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormLogDerivLFunctionNegLogDerivZeta.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormLogDerivLFunctionNegLogDerivZeta.lean new file mode 100644 index 0000000000000000000000000000000000000000..620bebf8caa846d5abacdce67a1107702597568f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormLogDerivLFunctionNegLogDerivZeta.lean @@ -0,0 +1,277 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.SumLogPrimeFactors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace WeightedTorusJets +open ArithmeticFunction DirichletCharacter +open scoped LSeries.notation BigOperators ComplexOrder +theorem norm_logDeriv_LFunction_le_neg_logDeriv_zeta {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) {s : ℂ} (hs : 1 < s.re) : + ‖deriv (LFunction χ) s / LFunction χ s‖ ≤ + (-deriv riemannZeta (s.re : ℂ) / riemannZeta (s.re : ℂ)).re := by + have htw := LSeriesSummable_twist_vonMangoldt χ hs + have hΛ := LSeriesSummable_vonMangoldt (show 1 < (s.re : ℂ).re from hs) + calc + ‖deriv (LFunction χ) s / LFunction χ s‖ = ‖LSeries (↗χ * ↗Λ) s‖ := by + rw [LSeries_twist_vonMangoldt_eq χ hs, + deriv_LFunction_eq_deriv_LSeries χ hs, LFunction_eq_LSeries χ hs] + simp [neg_div] + _ ≤ ∑' n, ‖LSeries.term (↗χ * ↗Λ) s n‖ := norm_tsum_le_tsum_norm htw.norm + _ ≤ ∑' n, ‖LSeries.term ↗Λ (s.re : ℂ) n‖ := by + apply htw.norm.tsum_le_tsum _ hΛ.norm + intro n + have hcoeff : ‖(↗χ * ↗Λ) n‖ ≤ ‖(↗Λ n : ℂ)‖ := by + simpa using mul_le_of_le_one_left (norm_nonneg (vonMangoldt n : ℂ)) + (χ.norm_le_one (n : ZMod q)) + simpa only [LSeries.norm_term_eq, Complex.ofReal_re] using + (LSeries.norm_term_le (f := ↗χ * ↗Λ) (g := ↗Λ) (n := n) s hcoeff) + _ = (LSeries ↗Λ (s.re : ℂ)).re := by + rw [LSeries, Complex.re_tsum hΛ] + apply tsum_congr + intro n + have hn : 0 ≤ LSeries.term ↗Λ (s.re : ℂ) n := + LSeries.term_nonneg (by exact_mod_cast (vonMangoldt_nonneg (n := n))) s.re + simpa using congrArg Complex.re (RCLike.norm_of_nonneg' hn) + _ = (-deriv riemannZeta (s.re : ℂ) / riemannZeta (s.re : ℂ)).re := + congrArg Complex.re (LSeries_vonMangoldt_eq_deriv_riemannZeta_div (show 1 < (s.re : ℂ).re from hs)) + +end WeightedTorusJets + +namespace WeightedTorusJets + +open _root_.Erdos970.Complex DirichletCharacter _root_.Erdos970.Complex.Hadamard + +theorem exists_upper_bound_completedL_logDeriv : + ∃ K : ℝ, 0 < K ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → ∀ s : ℝ, 1 < s → s ≤ 2 → + (logDeriv (conductorCompletedL χ) (s : ℂ)).re ≤ + 1 / (s - 1) + K * Real.log q := by + obtain ⟨Kg, hKg, hg⟩ := exists_upper_bound_conductor_gammaFactor_logDeriv + obtain ⟨Cz, hCz, hz⟩ := exists_upper_bound_zeta_logDeriv_re + refine ⟨Kg + Cz, by positivity, ?_⟩ + intro q _ hq χ hχ s hs hs2 + have hqR : (3 : ℝ) ≤ q := by exact_mod_cast hq + have hlogq : 1 < Real.log q := + (Real.lt_log_iff_exp_lt (by linarith)).mpr (Real.exp_one_lt_three.trans_le hqR) + have hnorm := norm_logDeriv_LFunction_le_neg_logDeriv_zeta χ + (s := (s : ℂ)) (by simpa using hs) + have hL : (logDeriv (LFunction χ) (s : ℂ)).re ≤ + (-logDeriv riemannZeta (s : ℂ)).re := by + simpa only [logDeriv_apply, Complex.ofReal_re, neg_div] using + (Complex.re_le_norm (deriv (LFunction χ) (s : ℂ) / LFunction χ (s : ℂ))).trans hnorm + have hdecomp := congrArg Complex.re + (conductorCompletedL_logDeriv_decomposition χ hχ (s := (s : ℂ)) + (by simpa using hs)) + rw [Complex.add_re] at hdecomp + have hgamma := hg q hq χ s hs hs2 + have hzeta := hz s hs hs2 + nlinarith + +theorem reciprocal_re_lower_of_near_one {r : ℝ} (hr : 0 < r) {z : ℂ} + (hzre : z.re ≤ 1) (hz : ‖z - 1‖ ≤ r) : + 1 / (6 * r) ≤ (1 / (((1 + 4 * r : ℝ) : ℂ) - z)).re := by + have hre := (Complex.abs_re_le_norm (z - 1)).trans hz + have him := (Complex.abs_im_le_norm (z - 1)).trans hz + simp only [Complex.sub_re, Complex.one_re, Complex.sub_im, Complex.one_im, + sub_zero] at hre him + have hu : 4 * r ≤ 1 + 4 * r - z.re := by linarith + have hu' : 1 + 4 * r - z.re ≤ 5 * r := by + have := (abs_le.mp hre).1 + linarith + have him2 : z.im ^ 2 ≤ r ^ 2 := by + exact sq_le_sq.mpr (by simpa only [abs_of_pos hr] using him) + have hden : 0 < (1 + 4 * r - z.re) ^ 2 + z.im ^ 2 := by + nlinarith [sq_pos_of_pos (by linarith : 0 < 1 + 4 * r - z.re), sq_nonneg z.im] + have hcomp : (1 + 4 * r - z.re) ^ 2 + z.im ^ 2 ≤ + 6 * r * (1 + 4 * r - z.re) := by + nlinarith [mul_nonneg (sub_nonneg.mpr hu') (by linarith : 0 ≤ 1 + 4 * r - z.re)] + have hdiv : 1 / (6 * r) ≤ (1 + 4 * r - z.re) / + ((1 + 4 * r - z.re) ^ 2 + z.im ^ 2) := + (div_le_div_iff₀ (by positivity) hden).mpr (by nlinarith) + simpa only [one_div, Complex.inv_re, Complex.normSq_apply, Complex.sub_re, + Complex.ofReal_re, Complex.sub_im, Complex.ofReal_im, zero_sub, neg_mul_neg, + pow_two] using hdiv + +theorem near_one_indices_eq_of_tsum_bound {ι : Type*} (z : ι → ℂ) + {r B : ℝ} (hr : 0 < r) (hB : r * B < 1 / 12) + (hre : ∀ i, (z i).re ≤ 1) + (hsum : Summable (fun i => (1 / (((1 + 4 * r : ℝ) : ℂ) - z i)).re)) + (hbound : (∑' i, (1 / (((1 + 4 * r : ℝ) : ℂ) - z i)).re) ≤ + 1 / (4 * r) + B) + {i j : ι} (hi : ‖z i - 1‖ ≤ r) (hj : ‖z j - 1‖ ≤ r) : i = j := by + classical + by_contra hij + have hnonneg : ∀ k, 0 ≤ (1 / (((1 + 4 * r : ℝ) : ℂ) - z k)).re := by + intro k + simp only [one_div, Complex.inv_re, Complex.sub_re, Complex.ofReal_re] + exact div_nonneg (by have := hre k; linarith) (Complex.normSq_nonneg _) + have htwo := hsum.sum_le_tsum {i, j} (fun k _ => hnonneg k) + simp only [Finset.sum_pair hij] at htwo + have hi' := reciprocal_re_lower_of_near_one hr (hre i) hi + have hj' := reciprocal_re_lower_of_near_one hr (hre j) hj + have hle : 2 / (6 * r) ≤ 1 / (4 * r) + B := by + rw [show 2 / (6 * r) = 1 / (6 * r) + 1 / (6 * r) by ring] + linarith + have hr0 : r ≠ 0 := ne_of_gt hr + have hcalc : r * (2 / (6 * r)) = 1 / 3 := by field_simp; ring + have hcalc' : r * (1 / (4 * r) + B) = 1 / 4 + r * B := by + field_simp + have hmul := mul_le_mul_of_nonneg_left hle hr.le + rw [hcalc, hcalc'] at hmul + linarith + +theorem exists_near_one_divisor_indices_unique : + ∃ c : ℝ, 0 < c ∧ c < 1 / 4 ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → χ.IsQuadratic → + ∀ i j : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ, + ‖divisorZeroIndex₀Val i - 1‖ ≤ c / Real.log q → + ‖divisorZeroIndex₀Val j - 1‖ ≤ c / Real.log q → i = j := by + obtain ⟨K, hK, hupper⟩ := exists_upper_bound_completedL_logDeriv + let c : ℝ := 1 / (24 * (K + 1)) + have hc : 0 < c := by dsimp [c]; positivity + have hc4 : c < 1 / 4 := by + dsimp [c] + apply (div_lt_iff₀ (by positivity)).mpr + linarith + refine ⟨c, hc, hc4, ?_⟩ + intro q _ hq χ hprim hχ hquad i j hi hj + have hqR : (3 : ℝ) ≤ q := by exact_mod_cast hq + have hlogq : 1 < Real.log q := + (Real.lt_log_iff_exp_lt (by linarith)).mpr (Real.exp_one_lt_three.trans_le hqR) + let r : ℝ := c / Real.log q + have hr : 0 < r := div_pos hc (by linarith) + have hr4 : r < 1 / 4 := by + apply lt_trans (b := c) + · exact (div_lt_self hc hlogq) + · exact hc4 + have hKc : c * K < 1 / 12 := by + dsimp [c] + rw [div_mul_eq_mul_div, (div_lt_iff₀ (by positivity))] + nlinarith + have hBr : r * (K * Real.log q) < 1 / 12 := by + have heq : r * (K * Real.log q) = c * K := by + dsimp [r] + field_simp + rwa [heq] + have hs : 1 < 1 + 4 * r := by linarith + have hs2 : 1 + 4 * r ≤ 2 := by linarith + apply near_one_indices_eq_of_tsum_bound divisorZeroIndex₀Val hr hBr + (fun k => (conductorCompletedL_divisorIndex_re_mem_Ioo χ hprim hχ k).2.le) + (conductorCompletedL_zero_sum_absolutely_summable χ hprim hχ hs).of_abs _ hi hj + rw [← real_logDeriv_conductorCompletedL_eq_divisor_tsum_source χ hprim hχ hquad hs] + simpa only [add_sub_cancel_left] using hupper q hq χ hχ (1 + 4 * r) hs hs2 + +theorem analyticOrderAt_eq_one_of_divisor_indices_unique {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (hfne : f ≠ 0) {z : ℂ} (hz0 : z ≠ 0) + (hz : f z = 0) + (hunique : ∀ i j : divisorZeroIndex₀ f Set.univ, + divisorZeroIndex₀Val i = z → divisorZeroIndex₀Val j = z → i = j) : + analyticOrderAt f z = 1 := by + have htop : analyticOrderAt f z ≠ ⊤ := by + exact fun h => hfne ((AnalyticOnNhd.analyticOrderAt_eq_top_iff_eq_zero z hf.analyticAt).mp h) + have hpos : 0 < analyticOrderNatAt f z := by + rw [Nat.pos_iff_ne_zero, analyticOrderNatAt, ne_eq, ENat.toNat_eq_zero, not_or] + exact ⟨(hf.analyticAt z).analyticOrderAt_ne_zero.mpr hz, htop⟩ + have hnat : analyticOrderNatAt f z = 1 := by + by_contra hn + have htwo : 1 < analyticOrderNatAt f z := by omega + let i : divisorZeroIndex₀ f Set.univ := ⟨⟨z, ⟨0, by + rw [RealCharacterAnalysis.toNat_divisor_eq_analyticOrderNatAt hf] + exact hpos⟩⟩, hz0⟩ + let j : divisorZeroIndex₀ f Set.univ := ⟨⟨z, ⟨1, by + rw [RealCharacterAnalysis.toNat_divisor_eq_analyticOrderNatAt hf] + exact htwo⟩⟩, hz0⟩ + have heq := hunique i j rfl rfl + have : (0 : ℕ) = 1 := congrArg (fun p => p.val.snd.val) heq + omega + rw [← Nat.cast_analyticOrderNatAt htop, hnat] + rfl + +end WeightedTorusJets + +namespace WeightedTorusJets + +open _root_.Erdos970.Complex DirichletCharacter _root_.Erdos970.Complex.Hadamard +open scoped ComplexConjugate + +theorem exists_classical_near_one_zero_unique_real_simple : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) (hq : 3 ≤ q), + let _ : NeZero q := ⟨by omega⟩ + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → + (∀ a : ZMod q, (χ a).im = 0) → ∀ z : ℂ, + ‖z - 1‖ ≤ c / Real.log q → LFunction χ z = 0 → + z.im = 0 ∧ analyticOrderAt (LFunction χ) z = 1 ∧ + ∀ w : ℂ, ‖w - 1‖ ≤ c / Real.log q → LFunction χ w = 0 → w = z := by + obtain ⟨c, hc, hc4, hindex_unique⟩ := exists_near_one_divisor_indices_unique + refine ⟨c, hc, ?_⟩ + intro q hq _ χ hprim hχ hreal z hzdisk hz + have hquad := (RealCharacterAnalysis.real_values_iff_quadratic χ).mp hreal + have hqR : (3 : ℝ) ≤ q := by exact_mod_cast hq + have hlogq : 1 < Real.log q := + (Real.lt_log_iff_exp_lt (by linarith)).mpr (Real.exp_one_lt_three.trans_le hqR) + have hrad : c / Real.log q < 1 / 4 := (div_lt_self hc hlogq).trans hc4 + have hpos : ∀ w : ℂ, ‖w - 1‖ ≤ c / Real.log q → 0 < w.re := by + intro w hw + have hre := (Complex.abs_re_le_norm (w - 1)).trans hw + simp only [Complex.sub_re, Complex.one_re] at hre + have := (abs_le.mp hre).1 + linarith + have hf := differentiable_conductorCompletedL χ hχ + have hfne : conductorCompletedL χ ≠ 0 := by + intro hzero + have hzero₁ : conductorCompletedL χ 1 = 0 := congrFun hzero 1 + exact completedL_ne_zero_of_one_le_re χ hχ (s := 1) (by simp) + ((conductorCompletedL_zero_iff χ 1).mp hzero₁) + have hzero : ∀ w : ℂ, ‖w - 1‖ ≤ c / Real.log q → LFunction χ w = 0 → + conductorCompletedL χ w = 0 := by + intro w hw hwzero + rw [conductorCompletedL_zero_iff, + completedL_eq_mul_gammaFactor χ (hpos w hw), hwzero, zero_mul] + have hindex : ∀ w : ℂ, ‖w - 1‖ ≤ c / Real.log q → LFunction χ w = 0 → + ∃ p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ, + divisorZeroIndex₀Val p = w := by + intro w hw hwzero + apply exists_divisorZeroIndex_val_eq_of_zero hf hfne _ (hzero w hw hwzero) + intro hw0 + have := hpos w hw + simp [hw0] at this + obtain ⟨p, hp⟩ := hindex z hzdisk hz + have hunique : ∀ w : ℂ, ‖w - 1‖ ≤ c / Real.log q → LFunction χ w = 0 → w = z := by + intro w hw hwzero + obtain ⟨p', hp'⟩ := hindex w hw hwzero + have heq := hindex_unique q hq χ hprim hχ hquad p' p + (by simpa only [hp'] using hw) (by simpa only [hp] using hzdisk) + simpa only [hp', hp] using congrArg divisorZeroIndex₀Val heq + have hconjzero : LFunction χ (conj z) = 0 := by + have h := RealCharacterAnalysis.lFunction_conj χ hχ z + simpa only [hquad.inv, hz, map_zero] using h + have hconjdisk : ‖conj z - 1‖ ≤ c / Real.log q := by + have heq : ‖conj z - 1‖ = ‖z - 1‖ := by + simpa only [map_sub, map_one] using Complex.norm_conj (z - 1) + rwa [heq] + have hzim : z.im = 0 := Complex.conj_eq_iff_im.mp (hunique _ hconjdisk hconjzero) + have horder : analyticOrderAt (conductorCompletedL χ) z = 1 := by + refine analyticOrderAt_eq_one_of_divisor_indices_unique hf hfne ?_ (hzero z hzdisk hz) ?_ + · intro hz0 + have := hpos z hzdisk + simp [hz0] at this + · intro i j hi hj + exact hindex_unique q hq χ hprim hχ hquad i j + (by simpa only [hi] using hzdisk) (by simpa only [hj] using hzdisk) + refine ⟨hzim, ?_, hunique⟩ + rwa [conductorCompletedL_analyticOrderAt_eq_LFunction χ hχ (hpos z hzdisk)] at horder + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormSqReal.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormSqReal.lean new file mode 100644 index 0000000000000000000000000000000000000000..11b65d3b86bc544b925c5fdbfb5e3d2dad153e79 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormSqReal.lean @@ -0,0 +1,494 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.RestrictWeightSortedEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped BigOperators +open scoped BigOperators +open Module +open scoped BigOperators +open scoped BigOperators +open Module +open scoped BigOperators +open InnerProductSpace +namespace WeightedTorusJets + +theorem norm_of_sq_eq_real {z : ℂ} {r : ℝ} (hz : z ^ 2 = (r : ℂ)) : + ‖z‖ = Real.sqrt |r| := by + rw [← Real.sqrt_sq (norm_nonneg z), ← norm_pow, hz, Complex.norm_real, Real.norm_eq_abs] + +theorem norm_biquadratic_box_le {a b : ℂ} {d : ℤ} {q N : ℕ} + (ha : a ^ 2 = (d : ℂ)) (hb : b ^ 2 = 2) + (hd : |(d : ℝ)| ≤ q) (hq : 1 ≤ q) + (n₁ n₂ n₃ n₄ : ℕ) (hn₁ : n₁ ≤ N) (hn₂ : n₂ ≤ N) + (hn₃ : n₃ ≤ N) (hn₄ : n₄ ≤ N) : + ‖(n₁ : ℂ) + n₂ * a + n₃ * b + n₄ * (a * b)‖ ≤ + 8 * N * Real.sqrt q := by + have hna : ‖a‖ ≤ Real.sqrt q := by + rw [norm_of_sq_eq_real (r := (d : ℝ)) (by simpa using ha)] + exact Real.sqrt_le_sqrt hd + have hnb : ‖b‖ ≤ 2 := by + rw [norm_of_sq_eq_real (r := 2) (by simpa using hb), Real.sqrt_le_iff] + norm_num + have hq' : (1 : ℝ) ≤ q := by exact_mod_cast hq + have hsq : 1 ≤ Real.sqrt q := (Real.one_le_sqrt).mpr hq' + have hnN : (0 : ℝ) ≤ N := Nat.cast_nonneg _ + have hab : ‖a * b‖ ≤ 2 * Real.sqrt q := by + simpa only [mul_comm] using norm_mul_le_of_le hna hnb + calc + ‖(n₁ : ℂ) + n₂ * a + n₃ * b + n₄ * (a * b)‖ ≤ + ‖(n₁ : ℂ)‖ + ‖(n₂ : ℂ) * a‖ + ‖(n₃ : ℂ) * b‖ + + ‖(n₄ : ℂ) * (a * b)‖ := norm_add₄_le + _ = n₁ + n₂ * ‖a‖ + n₃ * ‖b‖ + n₄ * ‖a * b‖ := by simp + _ ≤ N + N * Real.sqrt q + N * 2 + N * (2 * Real.sqrt q) := by + gcongr + _ ≤ 8 * N * Real.sqrt q := by nlinarith [mul_le_mul_of_nonneg_left hsq hnN] + +theorem norm_embedding_biquadratic_box_le {K : Type*} [CommRing K] + (ν : K →+* ℂ) {a b : K} {d : ℤ} {q N : ℕ} + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (hd : |(d : ℝ)| ≤ q) (hq : 1 ≤ q) + (n : Fin 4 → ℕ) (hn : ∀ i, n i < N) : + ‖ν ((n 0 : K) + n 1 * a + n 2 * b + n 3 * (a * b))‖ ≤ + 8 * N * Real.sqrt q := by + simp only [map_add, map_mul, map_natCast] + refine norm_biquadratic_box_le ?_ ?_ hd hq _ _ _ _ + (hn 0).le (hn 1).le (hn 2).le (hn 3).le + · simpa using congrArg ν ha + · simpa only [map_pow, map_ofNat] using congrArg ν hb + +theorem norm_three_powers_le {x y z : ℂ} {B : ℝ} + (hx : ‖x‖ ≤ B) (hy : ‖y‖ ≤ B) (hz : ‖z‖ ≤ B) + (i j k : ℕ) : ‖x ^ i * y ^ j * z ^ k‖ ≤ B ^ (i + j + k) := by + have hB : 0 ≤ B := (norm_nonneg x).trans hx + simp only [norm_mul, norm_pow, pow_add] + gcongr + +theorem norm_embedding_basis_sum_le {K : Type*} [CommRing K] + (ν : K →+* ℂ) {a b : K} {d : ℤ} {q N : ℕ} + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (hd : |(d : ℝ)| ≤ q) (hq : 1 ≤ q) + (n : Fin 4 → ℕ) (hn : ∀ i, n i < N) : + ‖ν (∑ i : Fin 4, (n i : K) * ![1, a, b, a * b] i)‖ ≤ + 8 * N * Real.sqrt q := by + simpa [Fin.sum_univ_succ, add_assoc] using + norm_embedding_biquadratic_box_le ν ha hb hd hq n hn + +theorem norm_embedding_derivative_entry_le {K : Type*} [CommRing K] + (ν : K →+* ℂ) (σ τ : K →+* K) {a b : K} {d : ℤ} {q N : ℕ} + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (hd : |(d : ℝ)| ≤ q) (hq : 1 ≤ q) + (n : Fin 4 → ℕ) (hn : ∀ i, n i < N) (α : Fin 3 → ℕ) : + let θ := ∑ i : Fin 4, (n i : K) * ![1, a, b, a * b] i + ‖ν (θ ^ (α 0) * σ θ ^ (α 1) * (σ.comp τ) θ ^ (α 2))‖ ≤ + (8 * N * Real.sqrt q) ^ (α 0 + α 1 + α 2) := by + dsimp only + simp only [map_mul, map_pow] + apply norm_three_powers_le + · exact norm_embedding_basis_sum_le ν ha hb hd hq n hn + · exact norm_embedding_basis_sum_le (ν.comp σ) ha hb hd hq n hn + · exact norm_embedding_basis_sum_le (ν.comp (σ.comp τ)) ha hb hd hq n hn + +end WeightedTorusJets + +open _root_.Erdos970.Finset + +namespace WeightedTorusJets + +variable {K : Type*} [Field K] [NumberField K] + +theorem abs_field_norm_eq_prod_embeddings (a : K) : + |(Algebra.norm ℚ a : ℝ)| = ∏ σ : K →ₐ[ℚ] ℂ, ‖σ a‖ := by + simpa only [eq_ratCast, Complex.norm_ratCast, norm_prod] using + congrArg (‖·‖) (Algebra.norm_eq_prod_embeddings ℚ ℂ a) + +theorem log_abs_field_norm_eq_sum_embeddings {a : K} (ha : a ≠ 0) : + Real.log |(Algebra.norm ℚ a : ℝ)| = + ∑ σ : K →ₐ[ℚ] ℂ, Real.log ‖σ a‖ := by + rw [abs_field_norm_eq_prod_embeddings, Real.log_prod] + simp [ha] + +theorem quarter_log_field_norm_le_of_embeddings {a : K} (ha : a ≠ 0) + (hdegree : Module.finrank ℚ K = 4) {B : ℝ} + (hbound : ∀ σ : K →ₐ[ℚ] ℂ, Real.log ‖σ a‖ ≤ B) : + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ a : ℝ)| ≤ B := by + rw [log_abs_field_norm_eq_sum_embeddings ha] + have hsum := Finset.sum_le_card_nsmul Finset.univ _ B (fun σ _ ↦ hbound σ) + simp only [Finset.card_univ, AlgHom.card, hdegree, nsmul_eq_mul, Nat.cast_ofNat] at hsum + linarith + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem archimedean_jet_determinant_bound {K : Type*} [Field K] [NumberField K] + (hdegree : Module.finrank ℚ K = 4) + (σ τ : K →+* K) {a b : K} {d : ℤ} {q N : ℕ} + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (hd : |(d : ℝ)| ≤ q) (hq : 1 ≤ q) (hN : 0 < N) + (n : Fin (N ^ 4) → Fin 4 → ℕ) (hn : ∀ j i, n j i < N) + (α : Fin (N ^ 4) → Fin 3 → ℕ) : + let θ := fun j => ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i + let A := Matrix.of fun i j => θ j ^ α i 0 * σ (θ j) ^ α i 1 * + (σ.comp τ) (θ j) ^ α i 2 + A.det ≠ 0 → + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ A.det : ℝ)| ≤ + ((N ^ 4 : ℕ) : ℝ) / 2 * Real.log (N ^ 4 : ℕ) + + ((∑ i, α i 0 : ℕ) + (∑ i, (α i 1 + α i 2) : ℕ)) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + dsimp only + intro hdet + apply quarter_log_field_norm_le_of_embeddings hdet hdegree + intro ν + convert SiegelJets.log_norm_map_det_archimedean (pow_pos hN 4) hN + (Nat.lt_of_lt_of_le Nat.zero_lt_one hq) ν.toRingHom _ hdet + (fun i => α i 0 + α i 1 + α i 2) + (fun i j => norm_embedding_derivative_entry_le ν.toRingHom σ τ ha hb hd hq + (n j) (hn j) (α i)) using 1 + simp only [Finset.sum_add_distrib, Nat.cast_add, add_assoc] + + + +open scoped NumberField BigOperators + +theorem archimedean_bound_of_integral_jet_determinant {K : Type*} + [Field K] [NumberField K] (hdegree : Module.finrank ℚ K = 4) + (σ τ : K →+* K) {a b : K} {d : ℤ} {q N : ℕ} + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (hd : |(d : ℝ)| ≤ q) (hq : 1 ≤ q) (hN : 0 < N) + (n : Fin (N ^ 4) → Fin 4 → ℕ) (hn : ∀ j i, n j i < N) + (α : Fin (N ^ 4) → Fin 3 → ℕ) (Δ : 𝓞 K) (hne : Δ ≠ 0) + (hΔ : (Δ : K) = + Matrix.det (fun i j => + (∑ k : Fin 4, (n j k : K) * ![1, a, b, a * b] k) ^ α i 0 * + σ (∑ k : Fin 4, (n j k : K) * ![1, a, b, a * b] k) ^ α i 1 * + (σ.comp τ) (∑ k : Fin 4, (n j k : K) * ![1, a, b, a * b] k) ^ α i 2)) : + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : K) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + let θ := fun j => ∑ i : Fin 4, (n j i : K) * ![1, a, b, a * b] i + let A : Matrix (Fin (N ^ 4)) (Fin (N ^ 4)) K := + Matrix.of fun i j => θ j ^ α i 0 * σ (θ j) ^ α i 1 * (σ.comp τ) (θ j) ^ α i 2 + change (Δ : K) = A.det at hΔ + have hcast : (Δ : K) ≠ 0 := fun h => hne (Subtype.ext h) + have hdet : A.det ≠ 0 := hΔ ▸ hcast + have hbound := archimedean_jet_determinant_bound hdegree σ τ ha hb hd hq hN n hn α hdet + change (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ A.det : ℝ)| ≤ _ at hbound + rw [← hΔ] at hbound + simpa only [Nat.cast_pow, Nat.cast_sum, Nat.cast_add] using hbound + +end WeightedTorusJets + +open scoped BigOperators NumberField + +namespace WeightedTorusJets + +theorem quarter_log_field_norm_lower {K : Type*} [Field K] [NumberField K] + (hdegree : Module.finrank ℚ K = 4) (x : 𝓞 K) (hx : x ≠ 0) + (P : Finset ℕ) (E : ℕ → ℕ) (hp : ∀ p ∈ P, p.Prime) + (hdvd : ∀ p ∈ P, (p : 𝓞 K) ^ E p ∣ x) : + ∑ p ∈ P, (E p : ℝ) * Real.log p ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (x : K) : ℝ)| := by + have hd : (∏ p ∈ P, (p : ℤ) ^ (4 * E p)) ∣ Algebra.norm ℤ x := by + apply Finset.prod_dvd_of_coprime ?_ ?_ + · intro p hpm q hqm hpq + exact ((Nat.coprime_primes (hp p hpm) (hp q hqm)).mpr hpq).isCoprime.pow + · intro p hpm + simpa [map_pow, Algebra.norm_natCast, NumberField.RingOfIntegers.rank, + hdegree, ← pow_mul] using map_dvd (Algebra.norm ℤ) (hdvd p hpm) + have hle : (∏ p ∈ P, p ^ (4 * E p)) ≤ (Algebra.norm ℤ x).natAbs := by + simpa only [← Nat.cast_pow, ← Nat.cast_prod, Int.natAbs_natCast] using + Int.natAbs_le_of_dvd_ne_zero hd (Algebra.norm_ne_zero_iff.mpr hx) + have hpos : (0 : ℝ) < ∏ p ∈ P, (p : ℝ) ^ (4 * E p) := + Finset.prod_pos fun p hpm => pow_pos (by exact_mod_cast (hp p hpm).pos) _ + have hlog := Real.log_le_log (y := ((Algebra.norm ℤ x).natAbs : ℝ)) hpos + (by exact_mod_cast hle) + rw [Real.log_prod (fun p hpm => pow_ne_zero _ + (by exact_mod_cast (hp p hpm).ne_zero))] at hlog + simp only [Real.log_pow, Nat.cast_mul, Nat.cast_ofNat, mul_assoc, + ← Finset.mul_sum] at hlog + rw [← Algebra.coe_norm_int, Rat.cast_intCast, ← Int.cast_abs, ← Nat.cast_natAbs] + linarith + +theorem prime_floor_sum_lower_raw {ι : Type*} (s : Finset ι) (a : ι → ℕ) + (U : ℝ) (P : Finset ℕ) (hP : P ⊆ Nat.primesLE ⌊U⌋₊) : + (∑ i ∈ s, (a i : ℝ)) * (∑ p ∈ P, Real.log p / (p : ℝ)) - + (s.card : ℝ) * (∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p) ≤ + ∑ p ∈ P, ((∑ i ∈ s, a i / p : ℕ) : ℝ) * Real.log p := by + have hlog : (∑ p ∈ P, Real.log p) ≤ ∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p := + Finset.sum_le_sum_of_subset_of_nonneg hP (fun p _ _ => Real.log_natCast_nonneg p) + calc + _ ≤ (∑ i ∈ s, (a i : ℝ)) * (∑ p ∈ P, Real.log p / (p : ℝ)) - + (s.card : ℝ) * (∑ p ∈ P, Real.log p) := + sub_le_sub_left (mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg s.card)) _ + _ = ∑ p ∈ P, ((∑ i ∈ s, (a i : ℝ)) / p - s.card) * Real.log p := by + rw [Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro p _ + ring + _ ≤ _ := by + apply Finset.sum_le_sum + intro p _ + apply mul_le_mul_of_nonneg_right _ (Real.log_natCast_nonneg p) + have h := Finset.sum_le_sum (s := s) + (fun i _ => (Nat.sub_one_lt_floor ((a i : ℝ) / p)).le) + simpa [Finset.sum_sub_distrib, ← Finset.sum_div, Nat.floor_div_eq_div] using h + +theorem finite_place_raw_norm_bounds {K ι : Type*} [Field K] [NumberField K] + (hdegree : Module.finrank ℚ K = 4) (Δ : 𝓞 K) (hΔ : Δ ≠ 0) + (s : Finset ι) (a : ι → ℕ) (U : ℝ) (P : Finset ℕ) + (hP : P ⊆ Nat.primesLE ⌊U⌋₊) + (hdiv : ∀ p ∈ P, (p : 𝓞 K) ^ (∑ i ∈ s, a i / p) ∣ Δ) : + (∑ p ∈ P, ((∑ i ∈ s, a i / p : ℕ) : ℝ) * Real.log p ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : K) : ℝ)|) ∧ + ((∑ i ∈ s, (a i : ℝ)) * (∑ p ∈ P, Real.log p / (p : ℝ)) - + (s.card : ℝ) * (∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p) ≤ + ∑ p ∈ P, ((∑ i ∈ s, a i / p : ℕ) : ℝ) * Real.log p) := + ⟨quarter_log_field_norm_lower hdegree Δ hΔ P (fun p => ∑ i ∈ s, a i / p) + (fun _ hp => Nat.prime_of_mem_primesLE (hP hp)) hdiv, + prime_floor_sum_lower_raw s a U P hP⟩ + + + +theorem prime_floor_sum_lower {ι : Type*} (s : Finset ι) (a : ι → ℕ) + {U : ℝ} (hU : 0 ≤ U) (P : Finset ℕ) (hP : P ⊆ Nat.primesLE ⌊U⌋₊) : + (∑ i ∈ s, (a i : ℝ)) * (∑ p ∈ P, Real.log p / (p : ℝ)) - + Real.log 4 * s.card * U ≤ + ∑ p ∈ P, (∑ i ∈ s, ((a i / p : ℕ) : ℝ)) * Real.log p := by + have hlog : (∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p) ≤ Real.log 4 * U := by + rw [← Chebyshev.theta_eq_sum_primesLE] + exact Chebyshev.theta_le_log4_mul_x hU + have hraw := prime_floor_sum_lower_raw s a U P hP + simp only [Nat.cast_sum] at hraw + apply le_trans _ hraw + apply sub_le_sub_left + convert mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg s.card) using 1 + ring + + + +open scoped BigOperators NumberField + +theorem finite_place_bounds_of_source_determinant {K : Type*} [Field K] [NumberField K] + (hdegree : Module.finrank ℚ K = 4) {m : ℕ} + (Δ : 𝓞 K) (hΔ : Δ ≠ 0) (α : Fin m → Fin 3 → ℕ) + (q H : ℕ) (χ : ℕ → ℂ) + (hdiv : ∀ p : ℕ, p.Prime → H < p → ¬p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 K)}) ^ (∑ i, α i 0 / p)) + (U : ℝ) (hU : 0 ≤ U) : + let P := (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ χ p = -1) + let E := fun p => ∑ i, α i 0 / p + let S₁ := ∑ i, (α i 0 : ℝ) + (∑ p ∈ P, (E p : ℝ) * Real.log p ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : K) : ℝ)|) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - + (m : ℝ) * (∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p) ≤ + ∑ p ∈ P, (E p : ℝ) * Real.log p) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - Real.log 4 * m * U ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : K) : ℝ)|) := by + dsimp only + let P := (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ χ p = -1) + have hdiv' (p : ℕ) (hp : p ∈ P) : (p : 𝓞 K) ^ (∑ i, α i 0 / p) ∣ Δ := by + obtain ⟨hpprime, hH, hpq, hχ⟩ := Finset.mem_filter.mp hp + simpa only [Ideal.span_singleton_pow, Ideal.mem_span_singleton] using + hdiv p (Nat.prime_of_mem_primesLE hpprime) hH hpq hχ + have hraw := finite_place_raw_norm_bounds hdegree Δ hΔ Finset.univ + (fun i => α i 0) U P (Finset.filter_subset _ _) hdiv' + simp only [Finset.card_univ, Fintype.card_fin] at hraw + refine ⟨hraw.1, hraw.2, ?_⟩ + have hcheb := prime_floor_sum_lower Finset.univ (fun i => α i 0) + hU P (Finset.filter_subset _ _) + simp only [Finset.card_univ, Fintype.card_fin] at hcheb + exact hcheb.trans (by simpa only [Nat.cast_sum] using hraw.1) + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_character_global_greedy_determinant_local_bounds (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ N H : ℕ, 0 < H → H ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * + ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + ∀ e : ℕ ≃ (Fin 3 → ℕ), Monotone (fun i => w (e i)) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ e) s.card : Set ℕ) ∧ + (∀ i, α i = e (g i)) ∧ + Set.range α = ((greedyPivots B (R ∘ e) s.card).image e : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ N ^ 4 - 1) ∧ + (∀ t : ℕ, s.card ≤ t → + Set.range g = (greedyPivots B (R ∘ e) t : Set ℕ)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + Δ ≠ 0 ∧ + ((1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)| ≤ + (N : ℝ) ^ 4 / 2 * Real.log ((N : ℝ) ^ 4) + + ((∑ i, (α i 0 : ℝ)) + (∑ i, ((α i 1 : ℝ) + α i 2))) * + (Real.log N + 1 / 2 * Real.log q + Real.log 8)) ∧ + (∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p)) ∧ + ∀ U : ℝ, 0 ≤ U → + let P := (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ χ p = -1) + let E := fun p => ∑ i, α i 0 / p + let S₁ := ∑ i, (α i 0 : ℝ) + (∑ p ∈ P, (E p : ℝ) * Real.log p ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)|) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - + (N : ℝ) ^ 4 * (∑ p ∈ Nat.primesLE ⌊U⌋₊, Real.log p) ≤ + ∑ p ∈ P, (E p : ℝ) * Real.log p) ∧ + (S₁ * (∑ p ∈ P, Real.log p / (p : ℝ)) - + Real.log 4 * (N : ℝ) ^ 4 * U ≤ + (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : B) : ℝ)|) := by + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hsource⟩ := + source_character_global_greedy_determinant_divisibility q χ hreal hprim hne hfield + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro N H hH hHN n + dsimp only + intro e he + obtain ⟨g, α, hg, hα, hrange, hmono, hweight, hstable, Δ, hΔ, hneΔ, hdiv⟩ := + hsource N H hH n e he + refine ⟨g, α, hg, hα, hrange, hmono, hweight, hstable, Δ, hΔ, hneΔ, ?_, hdiv, ?_⟩ + · let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + have ha' : a' ^ 2 = (d : B) := by apply Subtype.ext; exact ha + have hb' : b' ^ 2 = (2 : B) := by apply Subtype.ext; exact hb + have hdreal : |(d : ℝ)| ≤ q := by + simpa only [Nat.cast_natAbs, Int.cast_abs] using + (show (d.natAbs : ℝ) ≤ q from Nat.cast_le.mpr hbound) + exact archimedean_bound_of_integral_jet_determinant hdegree σ.toRingHom τ.toRingHom + ha' hb' hdreal (Nat.one_le_iff_ne_zero.mpr (NeZero.ne q)) (hH.trans_le hHN) + (fun j i => (n j i : ℕ)) (fun j i => (n j i).isLt) α Δ hneΔ hΔ + + · intro U hU + simpa only [Nat.cast_pow] using finite_place_bounds_of_source_determinant hdegree + Δ hneΔ α q H (fun p => χ p) hdiv U hU + +end WeightedTorusJets + +namespace WeightedTorusJets + +open scoped BigOperators NumberField + +theorem finite_place_lower_of_source_determinant {K : Type*} [Field K] [NumberField K] + (hdegree : Module.finrank ℚ K = 4) {m : ℕ} + (Δ : 𝓞 K) (hΔ : Δ ≠ 0) (α : Fin m → Fin 3 → ℕ) + (q H : ℕ) (χ : ℕ → ℂ) + (hdiv : ∀ p : ℕ, p.Prime → H < p → ¬p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 K)}) ^ (∑ i, α i 0 / p)) + {U C ell delta CH : ℝ} (hU : 0 ≤ U) (hC : Real.log 4 ≤ C) + (hbias : Real.log U - C * ell - C * delta * (Real.log U) ^ 2 / ell - CH ≤ + ∑ p ∈ (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ χ p = -1), Real.log p / (p : ℝ)) : + (∑ i, (α i 0 : ℝ)) * + (Real.log U - C * ell - C * delta * (Real.log U) ^ 2 / ell - CH) - + C * m * U ≤ (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : K) : ℝ)| := by + have hbound := (finite_place_bounds_of_source_determinant + hdegree Δ hΔ α q H χ hdiv U hU).2.2 + refine le_trans ?_ hbound + exact sub_le_sub + (mul_le_mul_of_nonneg_left hbias (Finset.sum_nonneg fun i _ => Nat.cast_nonneg (α i 0))) + (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right hC (Nat.cast_nonneg m)) hU) + +theorem three_le_level_of_nonprincipal {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hne : χ ≠ 1) : 3 ≤ q := by + by_contra hq + have hq0 : q ≠ 0 := NeZero.ne q + have hsmall : q = 1 ∨ q = 2 := by omega + rcases hsmall with rfl | rfl + · exact hne (DirichletCharacter.level_one χ) + · apply hne + apply MulChar.eq_one_iff.mpr + intro u + rw [(by decide : ∀ u : (ZMod 2)ˣ, u = 1) u] + simp + +end WeightedTorusJets + +namespace WeightedTorusJets + +open scoped BigOperators NumberField + +theorem source_given_determinant_finite_lower_of_real_zero : + ∃ C : ℝ, 0 < C ∧ Real.log 4 ≤ C ∧ + ∀ H : ℕ, ∃ CH : ℝ, + ∀ (q : ℕ) [NeZero q], ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ x : ZMod q, (χ x).im = 0) → + ∀ β : ℝ, 0 < β → β < 1 → DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ (K : Type*) [Field K] [NumberField K], Module.finrank ℚ K = 4 → + ∀ (m : ℕ) (Δ : 𝓞 K), Δ ≠ 0 → ∀ α : Fin m → Fin 3 → ℕ, + (∀ p : ℕ, p.Prime → H < p → ¬p ∣ 2 * q → χ (p : ZMod q) = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 K)}) ^ (∑ i, α i 0 / p)) → + ∀ U : ℝ, 0 ≤ U → + (∑ i, (α i 0 : ℝ)) * + (Real.log U - C * Real.log q - + C * ((1 - β) * Real.log q) * (Real.log U) ^ 2 / Real.log q - CH) - + C * m * U ≤ (1 / 4 : ℝ) * Real.log |(Algebra.norm ℚ (Δ : K) : ℝ)| := by + obtain ⟨C, hC, hC4, hmass⟩ := source_good_prime_mass_all_parameters + refine ⟨C, hC, hC4, ?_⟩ + intro H + obtain ⟨CH, hCH⟩ := hmass H + refine ⟨CH, ?_⟩ + intro q _ χ hprim hne hreal β hβ0 hβ1 hzero K _ _ hdegree m Δ hΔ α hdiv U hU + exact finite_place_lower_of_source_determinant hdegree Δ hΔ α q H + (fun p => χ (p : ZMod q)) hdiv hU hC4 + (hCH q (three_le_level_of_nonprincipal χ hne) χ hprim hne hreal + β hβ0 hβ1 hzero U hU) + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizationPresentationLocalEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizationPresentationLocalEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..b5dd223c8b79c49e1dcec1fa4c63a25f841c3b6f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizationPresentationLocalEquiv.lean @@ -0,0 +1,545 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.CoordinateLocalizedPrime +import OAI.NumberTheory.Jacobsthal.Siegel.ResidueTensorQuotientAlgEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +section +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +open MvPolynomial +noncomputable section +namespace WeightedTorusJets.Geometry.DegreeBezout + +open MvPolynomial +attribute [local instance] MvPolynomial.algebraMvPolynomial + +variable {K σ ι τ : Type*} [CommRing K] + +noncomputable def normalizationPresentationLocalEquiv + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (P : Ideal (MvPolynomial σ K)) [P.IsPrime] : + Localization.AtPrime P ≃ₐ[K] + Localization.AtPrime (P.comap (normalizationPresentation e).symm.toRingHom) := + (Localization.localAlgEquiv (P.comap (normalizationPresentation e).symm.toRingHom) P + (normalizationPresentation e).symm rfl).symm + +theorem normalizationPresentationLocalEquiv_algebraMap + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (P : Ideal (MvPolynomial σ K)) [P.IsPrime] (f : MvPolynomial σ K) : + normalizationPresentationLocalEquiv e P (algebraMap _ (Localization.AtPrime P) f) = + algebraMap _ (Localization.AtPrime + (P.comap (normalizationPresentation e).symm.toRingHom)) + (normalizationPresentation e f) := by + apply (normalizationPresentationLocalEquiv e P).symm.injective + rw [AlgEquiv.symm_apply_apply] + change algebraMap _ (Localization.AtPrime P) f = + Localization.localRingHom _ P (normalizationPresentation e).symm.toRingHom rfl + (algebraMap _ _ (normalizationPresentation e f)) + rw [Localization.localRingHom_to_map] + exact congrArg (algebraMap _ (Localization.AtPrime P)) + ((normalizationPresentation e).symm_apply_apply f).symm + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry + +theorem totalDegree_eval₂_le_of_linear_images + {R S σ τ : Type*} [CommSemiring R] [CommSemiring S] + (f : R →+* S) (x : σ → MvPolynomial τ S) + (hx : ∀ i, (x i).totalDegree ≤ 1) (p : MvPolynomial σ R) : + (p.eval₂ (MvPolynomial.C.comp f) x).totalDegree ≤ p.totalDegree := by + classical + let φ := MvPolynomial.eval₂Hom (MvPolynomial.C.comp f) x + change (φ p).totalDegree ≤ p.totalDegree + conv_lhs => rw [p.as_sum, map_sum] + apply MvPolynomial.totalDegree_finsetSum_le + intro d hd + apply le_trans _ (MvPolynomial.le_totalDegree hd) + rw [MvPolynomial.monomial_eq, map_mul, Finsupp.prod, map_prod] + calc + _ ≤ (φ (MvPolynomial.C (p.coeff d))).totalDegree + + (∑ i ∈ d.support, (φ (MvPolynomial.X i ^ d i)).totalDegree) := + (MvPolynomial.totalDegree_mul _ _).trans + (Nat.add_le_add_left (MvPolynomial.totalDegree_finsetProd _ _) _) + _ = ∑ i ∈ d.support, ((x i) ^ d i).totalDegree := by simp [φ] + _ ≤ ∑ i ∈ d.support, d i := by + apply Finset.sum_le_sum + intro i _ + exact (MvPolynomial.totalDegree_pow _ _).trans + (by simpa using Nat.mul_le_mul_left (d i) (hx i)) + _ = d.sum (fun _ e => e) := rfl + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry.DegreeBezout + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem coefficient_localization_finrank_le_pow + {B F : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (h D : ℕ) (p : Ideal (MvPolynomial (Fin h) B)) [p.IsPrime] + [Module.Finite B (MvPolynomial (Fin h) B ⧸ p)] + (hp : p.comap MvPolynomial.C = ⊥) + (f : Fin h → MvPolynomial (Fin h) B) + (hf : ∀ i, (MvPolynomial.map (algebraMap B F) (f i)).totalDegree ≤ D) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap _ (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + let := coefficient_localization_isMaximal_of_finite (F := F) p hp + let q := p.map (algebraMap (MvPolynomial (Fin h) B) (MvPolynomial (Fin h) F)) + Module.finrank F (Localization.AtPrime q ⧸ Ideal.span (Set.range (fun i => + algebraMap _ (Localization.AtPrime q) + (MvPolynomial.map (algebraMap B F) (f i))))) ≤ D ^ h := by + let := coefficient_localization_isMaximal_of_finite (F := F) p hp + let q := p.map (algebraMap (MvPolynomial (Fin h) B) (MvPolynomial (Fin h) F)) + let e := coefficientLocalizationLocalEquiv (F := F) p hp + have hcomm (i : Fin h) : e (algebraMap _ (Localization.AtPrime p) (f i)) = + algebraMap _ (Localization.AtPrime q) + (MvPolynomial.map (algebraMap B F) (f i)) := by + rw [AlgEquiv.commutes] + rfl + have hrad' := radical_span_eq_maximalIdeal_of_commuting_images + e.toRingEquiv _ _ hcomm hrad + exact WeightedTorusJets.Deformation.finrank_local_quotient_le_pow_of_radical h D q + (fun i => MvPolynomial.map (algebraMap B F) (f i)) hf hrad' + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry.DegreeBezout + +open MvPolynomial +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem totalDegree_normalizationPresentation_le + {K σ ι τ : Type*} [Field K] + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (f : MvPolynomial σ K) : + (normalizationPresentation e f).totalDegree ≤ (e.symm f).totalDegree := by + let s := ((renameEquiv K (Equiv.sumComm ι τ)).trans (sumAlgEquiv K τ ι)).toRingHom + have hs : s = eval₂Hom (C.comp (C : K →+* MvPolynomial ι K)) + (Sum.elim (fun i => C (X i)) X) := by + apply MvPolynomial.ringHom_ext + · intro r + simp [s] + · intro i + cases i <;> simp [s] + change (s (e.symm f)).totalDegree ≤ _ + rw [hs] + apply totalDegree_eval₂_le_of_linear_images + intro i + cases i <;> simp + +theorem totalDegree_localized_normalizationPresentation_le + {K σ ι τ : Type*} [Field K] + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (f : MvPolynomial σ K) : + (MvPolynomial.map (algebraMap (MvPolynomial ι K) (FractionRing (MvPolynomial ι K))) + (normalizationPresentation e f)).totalDegree ≤ (e.symm f).totalDegree := by + exact (Finset.sup_mono (support_map_subset _ _)).trans + (totalDegree_normalizationPresentation_le e f) + +theorem normalizationPresentation_radical_eq_maximal + {K σ ι τ ν : Type*} [CommRing K] + (e : MvPolynomial (ι ⊕ τ) K ≃ₐ[K] MvPolynomial σ K) + (P : Ideal (MvPolynomial σ K)) [P.IsPrime] (f : ν → MvPolynomial σ K) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap _ (Localization.AtPrime P) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime P)) : + (Ideal.span (Set.range (fun i => algebraMap _ + (Localization.AtPrime (P.comap (normalizationPresentation e).symm.toRingHom)) + (normalizationPresentation e (f i))))).radical = IsLocalRing.maximalIdeal + (Localization.AtPrime (P.comap (normalizationPresentation e).symm.toRingHom)) := by + exact radical_span_eq_maximalIdeal_of_commuting_images + (normalizationPresentationLocalEquiv e P).toRingEquiv + (fun i => algebraMap _ (Localization.AtPrime P) (f i)) + (fun i => algebraMap _ + (Localization.AtPrime (P.comap (normalizationPresentation e).symm.toRingHom)) + (normalizationPresentation e (f i))) + (fun i => normalizationPresentationLocalEquiv_algebraMap e P (f i)) hrad + +end WeightedTorusJets.Geometry.DegreeBezout + +open Module TensorProduct + +namespace WeightedTorusJets.Deformation + +theorem finrank_eq_length_mul_residue_degree + (K R M : Type*) [Field K] [CommRing R] [IsLocalRing R] [Algebra K R] + [AddCommGroup M] [Module K M] [Module R M] [IsScalarTower K R M] + [Module.Finite K M] [Module.Finite K (IsLocalRing.ResidueField R)] : + (Module.finrank K M : ℕ∞) = Module.length R M * + (Module.finrank K (IsLocalRing.ResidueField R) : ℕ∞) := by + have h := IsLocalRing.length_restrictScalars K R M + rw [← Module.length_eq_of_surjective (M := IsLocalRing.ResidueField R) + (IsLocalRing.residue_surjective (R := K)), + Module.length_eq_finrank K M, + Module.length_eq_finrank K (IsLocalRing.ResidueField R)] at h + exact h + +theorem finrank_localization_le (F A B : Type*) [Field F] + [CommRing A] [Algebra F A] [Module.Finite F A] + [CommRing B] [Algebra A B] [Algebra F B] [IsScalarTower F A B] + (S : Submonoid A) [IsLocalization S B] : + Module.finrank F B ≤ Module.finrank F A := by + have : IsArtinianRing A := isArtinian_of_tower F (inferInstance : IsArtinian F A) + exact LinearMap.finrank_le_finrank_of_surjective + (f := (IsScalarTower.toAlgHom F A B).toLinearMap) + (IsArtinianRing.localization_surjective S B) + +end WeightedTorusJets.Deformation + +namespace WeightedTorusJets.Geometry + +variable {R : Type*} [CommRing R] (I p : Ideal R) [p.IsPrime] + +theorem component_local_artinian [IsNoetherianRing R] (hp : p ∈ I.minimalPrimes) : + IsArtinianRing + (Localization.AtPrime p ⧸ I.map (algebraMap R (Localization.AtPrime p))) := by + apply IsLocalRing.quotient_artinian_of_mem_minimalPrimes_of_isLocalRing + rwa [IsLocalization.minimalPrimes_map p.primeCompl (Localization.AtPrime p) I, + Set.mem_preimage, Localization.AtPrime.under_maximalIdeal] + +theorem component_local_length_ne_top [IsNoetherianRing R] (hp : p ∈ I.minimalPrimes) : + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap R (Localization.AtPrime p))) ≠ ⊤ := by + have := component_local_artinian I p hp + have : IsArtinian (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap R (Localization.AtPrime p))) := + isArtinian_of_surjective_algebraMap + (R := Localization.AtPrime p ⧸ I.map (algebraMap R (Localization.AtPrime p))) + Ideal.Quotient.mk_surjective + exact Module.length_ne_top + +variable {K : Type*} [Field K] + +theorem polynomial_component_regular (p : Ideal (MvPolynomial (Fin 4) K)) [p.IsPrime] : + IsRegularLocalRing (Localization.AtPrime p) := inferInstance + +theorem regular_localization_component [IsRegularRing R] + (M : Submonoid R) (q : Ideal (Localization M)) [q.IsPrime] : + IsRegularLocalRing (Localization.AtPrime q) := + IsRegularLocalRing.of_ringEquiv + (IsLocalization.localizationLocalizationAtPrimeIsoLocalization M q).toRingEquiv + +theorem regular_localization_component_cotangent_dim [IsRegularRing R] + (M : Submonoid R) (q : Ideal (Localization M)) [q.IsPrime] : + (Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) : WithBot ℕ∞) = + (q.comap (algebraMap R (Localization M))).height := by + have := regular_localization_component M q + rw [← IsLocalization.AtPrime.ringKrullDim_eq_height + (q.comap (algebraMap R (Localization M))) (Localization.AtPrime q)] + exact (IsRegularLocalRing.iff_finrank_cotangentSpace _).mp inferInstance + +theorem polynomial_component_height_bounds + (p : Ideal (MvPolynomial (Fin 4) K)) [p.IsPrime] + {F : MvPolynomial (Fin 4) K} (hF : F ≠ 0) (hFp : F ∈ p) : + 1 ≤ p.height ∧ p.height ≤ 4 := by + constructor + · rw [Order.one_le_iff_ne_zero, Ne, Ideal.height_eq_zero_iff_eq_bot] + intro hp + apply hF + simpa only [hp, Ideal.mem_bot] using hFp + · have h := p.height_le_ringKrullDim_of_ne_top Ideal.IsPrime.ne_top' + exact WithBot.coe_le_coe.mp (by simpa using h) + +theorem polynomial_component_cotangent_dim + (p : Ideal (MvPolynomial (Fin 4) K)) [p.IsPrime] : + (Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime p)) + (IsLocalRing.CotangentSpace (Localization.AtPrime p)) : WithBot ℕ∞) = p.height := by + rw [← IsLocalization.AtPrime.ringKrullDim_eq_height p (Localization.AtPrime p)] + exact (IsRegularLocalRing.iff_finrank_cotangentSpace _).mp inferInstance + +theorem localization_component_cotangent_bounds + (M : Submonoid (MvPolynomial (Fin 4) K)) + (p : Ideal (Localization M)) [p.IsPrime] + {F : MvPolynomial (Fin 4) K} (hF : F ≠ 0) + (hFp : algebraMap (MvPolynomial (Fin 4) K) (Localization M) F ∈ p) : + 1 ≤ Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime p)) + (IsLocalRing.CotangentSpace (Localization.AtPrime p)) ∧ + Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime p)) + (IsLocalRing.CotangentSpace (Localization.AtPrime p)) ≤ 4 := by + have hb := polynomial_component_height_bounds + (p.comap (algebraMap (MvPolynomial (Fin 4) K) (Localization M))) hF hFp + have hd := regular_localization_component_cotangent_dim M p + have hd' := WithBot.coe_injective hd + rw [← hd'] at hb + constructor + · exact_mod_cast hb.1 + · exact_mod_cast hb.2 + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry.DegreeBezout + +theorem map_extended_ideal_eq {R A B : Type*} [CommRing R] [CommRing A] [CommRing B] + [Algebra R A] [Algebra R B] (e : A ≃ₐ[R] B) (I : Ideal R) : + (I.map (algebraMap R A)).map e.toRingEquiv.toRingHom = I.map (algebraMap R B) := by + rw [Ideal.map_map] + congr 1 + exact RingHom.ext e.commutes + +noncomputable def quotientExtendedAlgEquiv {R A B : Type*} + [CommRing R] [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] + (e : A ≃ₐ[R] B) (I : Ideal R) : + (A ⧸ I.map (algebraMap R A)) ≃ₐ[R] (B ⧸ I.map (algebraMap R B)) := + Ideal.quotientEquivAlg _ _ e (map_extended_ideal_eq e I).symm + +theorem extended_quotient_length_eq {R A B : Type*} + [CommRing R] [CommRing A] [CommRing B] [Algebra R A] [Algebra R B] + (e : A ≃ₐ[R] B) (I : Ideal R) : + Module.length A (A ⧸ I.map (algebraMap R A)) = + Module.length B (B ⧸ I.map (algebraMap R B)) := + quotient_length_eq_of_ringEquiv e.toRingEquiv _ _ (map_extended_ideal_eq e I).symm + +theorem local_quotient_length_eq_after_localization {R : Type*} [CommRing R] + (S : Submonoid R) (p : Ideal (Localization S)) [p.IsPrime] (I : Ideal R) : + Module.length (Localization.AtPrime (p.comap (algebraMap R (Localization S)))) + (Localization.AtPrime (p.comap (algebraMap R (Localization S))) ⧸ + I.map (algebraMap R (Localization.AtPrime + (p.comap (algebraMap R (Localization S)))))) = + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap R (Localization.AtPrime p))) := + extended_quotient_length_eq + (IsLocalization.localizationLocalizationAtPrimeIsoLocalization S p) I + + + +open IsLocalRing Module + +section Local + +variable (K R M : Type*) [Field K] [CommRing R] [IsLocalRing R] [Algebra K R] + [AddCommGroup M] [Module K M] [Module R M] [IsScalarTower K R M] + +theorem field_length_eq_local_length_mul_residue_length : + length K M = length R M * length K (ResidueField R) := by + rw [IsLocalRing.length_restrictScalars K R M, + ← Module.length_eq_of_surjective (M := ResidueField R) + (IsLocalRing.residue_surjective (R := K))] + +theorem finite_of_finite_length_of_finite_residue + [Module.Finite K (ResidueField R)] (hM : IsFiniteLength R M) : + Module.Finite K M := by + have hlen : length K M ≠ ⊤ := by + rw [field_length_eq_local_length_mul_residue_length K R M, + Module.length_eq_finrank K (ResidueField R)] + lift length R M to ℕ using Module.length_ne_top_iff.mpr hM with n hn + rw [← Nat.cast_mul] + exact ENat.natCast_ne_top _ + have hfinite := Module.length_ne_top_iff.mp hlen + have := (isFiniteLength_iff_isNoetherian_isArtinian.mp hfinite).1 + infer_instance + +theorem finrank_eq_local_length_toNat_mul_residue_degree + [Module.Finite K M] [Module.Finite K (ResidueField R)] : + finrank K M = (length R M).toNat * finrank K (ResidueField R) := by + simpa using congrArg ENat.toNat (WeightedTorusJets.Deformation.finrank_eq_length_mul_residue_degree K R M) + +end Local + +section FiniteAlgebra + +variable (K A : Type*) [Field K] [CommRing A] [Algebra K A] [Module.Finite K A] + +theorem local_weighted_length_le_finrank (p : PrimeSpectrum A) : + length (Localization.AtPrime p.asIdeal) (Localization.AtPrime p.asIdeal) * + (finrank K (ResidueField (Localization.AtPrime p.asIdeal)) : ℕ∞) ≤ + finrank K A := by + let R := Localization.AtPrime p.asIdeal + let : IsArtinianRing A := isArtinian_of_tower K (inferInstance : IsArtinian K A) + have hsurj : Function.Surjective (algebraMap A R) := + IsArtinianRing.localization_surjective p.asIdeal.primeCompl R + let : Module.Finite K R := Module.Finite.of_surjective + (Algebra.algHom K A R).toLinearMap hsurj + rw [← WeightedTorusJets.Deformation.finrank_eq_length_mul_residue_degree K R R, + ← Module.length_eq_finrank K R, ← Module.length_eq_finrank K A] + exact Module.length_le_of_surjective (Algebra.algHom K A R).toLinearMap hsurj + +theorem finrank_eq_sum_local_length_mul_residue_degree + [Fintype (PrimeSpectrum A)] : + finrank K A = ∑ p : PrimeSpectrum A, + (length (Localization.AtPrime p.asIdeal) (Localization.AtPrime p.asIdeal)).toNat * + finrank K (ResidueField (Localization.AtPrime p.asIdeal)) := by + let : IsArtinianRing A := isArtinian_of_tower K (inferInstance : IsArtinian K A) + rw [IsArtinianRing.finrank_eq_sum_primeSpectrum A K] + apply Finset.sum_congr rfl + intro p _ + let R := Localization.AtPrime p.asIdeal + let : Module.Finite K R := Module.Finite.of_surjective + (Algebra.algHom K A R).toLinearMap + (IsArtinianRing.localization_surjective p.asIdeal.primeCompl R) + exact finrank_eq_local_length_toNat_mul_residue_degree K R R + +end FiniteAlgebra + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry.DegreeBezout + +open IsLocalRing Module + +variable (K A : Type*) [Field K] [CommRing A] [Algebra K A] + +theorem finite_residue_of_maximal [Algebra.FiniteType K A] + (p : Ideal A) [p.IsMaximal] : + Module.Finite K (ResidueField (Localization.AtPrime p)) := by + let : Field (A ⧸ p) := Ideal.Quotient.field p + let : Module.Finite K (A ⧸ p) := finite_of_finite_type_of_isJacobsonRing K (A ⧸ p) + let : Module.Finite (A ⧸ p) p.ResidueField := Module.Finite.of_surjective + (Algebra.linearMap (A ⧸ p) p.ResidueField) + p.bijective_algebraMap_quotient_residueField.surjective + exact Module.Finite.trans (A ⧸ p) p.ResidueField + +theorem isolated_quotient_finite [IsNoetherianRing A] [Algebra.FiniteType K A] + (I p : Ideal A) [p.IsMaximal] (hp : p ∈ I.minimalPrimes) : + Module.Finite K + (Localization.AtPrime p ⧸ I.map (algebraMap A (Localization.AtPrime p))) := by + let := finite_residue_of_maximal K A p + exact finite_of_finite_length_of_finite_residue K (Localization.AtPrime p) _ + (Module.length_ne_top_iff.mp (component_local_length_ne_top I p hp)) + +theorem isolated_component_finrank [IsNoetherianRing A] [Algebra.FiniteType K A] + (I p : Ideal A) [p.IsMaximal] (hp : p ∈ I.minimalPrimes) : + (finrank K + (Localization.AtPrime p ⧸ I.map (algebraMap A (Localization.AtPrime p))) : ℕ∞) = + length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap A (Localization.AtPrime p))) * + (finrank K (ResidueField (Localization.AtPrime p)) : ℕ∞) := by + let := finite_residue_of_maximal K A p + let := isolated_quotient_finite K A I p hp + exact WeightedTorusJets.Deformation.finrank_eq_length_mul_residue_degree K + (Localization.AtPrime p) _ + +end WeightedTorusJets.Geometry.DegreeBezout + +namespace WeightedTorusJets.Geometry.DegreeBezout + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +noncomputable def coefficientLocalizationResidueAlgEquiv + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [(p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsPrime] + [Algebra F p.ResidueField] [IsScalarTower B F p.ResidueField] + (hp : p.comap MvPolynomial.C = ⊥) : + p.ResidueField ≃ₐ[F] + (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).ResidueField := + (IsLocalRing.ResidueField.mapAlgEquiv + ((coefficientLocalizationLocalEquiv p hp).restrictScalars B)).extendScalarsOfIsLocalization + F (nonZeroDivisors B) + +theorem coefficient_localization_residue_degree_eq_rank + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [(p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsPrime] + [Algebra F p.ResidueField] [IsScalarTower B F p.ResidueField] + (hp : p.comap MvPolynomial.C = ⊥) : + Module.finrank F + (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).ResidueField = + Module.finrank B (MvPolynomial σ B ⧸ p) := by + rw [← (coefficientLocalizationResidueAlgEquiv p hp).toLinearEquiv.finrank_eq] + exact IsFractionRing.finrank_eq B F (MvPolynomial σ B ⧸ p) p.ResidueField + +theorem projected_residue_degree_eq_component_rank + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [(p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsPrime] + (hp : p.comap MvPolynomial.C = ⊥) : + Module.finrank F + (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).ResidueField = + Module.finrank B (MvPolynomial σ B ⧸ p) := by + let := componentCoefficientFractionAlgebra (F := F) p hp + let := componentCoefficientFractionAlgebra_tower (F := F) p hp + exact coefficient_localization_residue_degree_eq_rank p hp + +theorem coefficient_localization_quotient_length + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (I p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [(p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsPrime] + (hp : p.comap MvPolynomial.C = ⊥) : + let q := p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap _ (Localization.AtPrime p))) = + Module.length (Localization.AtPrime q) + (Localization.AtPrime q ⧸ + (I.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).map + (algebraMap _ (Localization.AtPrime q))) := by + dsimp only + rw [Ideal.map_map, ← IsScalarTower.algebraMap_eq] + exact extended_quotient_length_eq (coefficientLocalizationLocalEquiv p hp) I + +theorem coefficient_localization_component_finrank + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] [Finite σ] + [Algebra B F] [IsFractionRing B F] + (I p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [(p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsMaximal] + (hp : p.comap MvPolynomial.C = ⊥) (hpI : p ∈ I.minimalPrimes) : + let q := p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) + (Module.finrank F + (Localization.AtPrime q ⧸ + (I.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).map + (algebraMap _ (Localization.AtPrime q))) : ℕ∞) = + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap _ (Localization.AtPrime p))) * + (Module.finrank F (IsLocalRing.ResidueField (Localization.AtPrime q)) : ℕ∞) := by + let q := p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) + let M : Submonoid (MvPolynomial σ B) := (nonZeroDivisors B).map MvPolynomial.C + have hq : q ∈ (I.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).minimalPrimes := by + rw [IsLocalization.minimalPrimes_map M (MvPolynomial σ F) I, Set.mem_preimage] + change q.comap (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) ∈ I.minimalPrimes + have he := IsLocalization.under_map_of_isPrime_disjoint M (MvPolynomial σ F) + (show p.IsPrime from inferInstance) (coefficient_nonZeroDivisors_disjoint p hp) + change q.comap (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) = p at he + rwa [he] + have h := isolated_component_finrank F (MvPolynomial σ F) + (I.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))) q hq + rw [← coefficient_localization_quotient_length I p hp] at h + exact h + +theorem coefficient_localization_component_finrank_eq_length_mul_rank + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] [Finite σ] + [Algebra B F] [IsFractionRing B F] + (I p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [(p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsMaximal] + (hp : p.comap MvPolynomial.C = ⊥) (hpI : p ∈ I.minimalPrimes) : + let q := p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) + (Module.finrank F + (Localization.AtPrime q ⧸ + (I.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).map + (algebraMap _ (Localization.AtPrime q))) : ℕ∞) = + Module.length (Localization.AtPrime p) + (Localization.AtPrime p ⧸ I.map (algebraMap _ (Localization.AtPrime p))) * + (Module.finrank B (MvPolynomial σ B ⧸ p) : ℕ∞) := by + rw [← projected_residue_degree_eq_component_rank (F := F) p hp] + exact coefficient_localization_component_finrank I p hp hpI + +end WeightedTorusJets.Geometry.DegreeBezout + +end +end +end +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizedHomogeneousChartEquation.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizedHomogeneousChartEquation.lean new file mode 100644 index 0000000000000000000000000000000000000000..812babe6db88407048fce264f21374417f3a8f0f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizedHomogeneousChartEquation.lean @@ -0,0 +1,79 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeChartHomogeneousLocal + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +open MvPolynomial HomogeneousLocalization _root_.AlgebraicGeometry + +attribute [local instance] MvPolynomial.gradedAlgebra coneIdeal_isPrime + +universe uProjEq + +noncomputable def normalizedHomogeneousChartEquation {K σ : Type*} [CommRing K] + (f : MvPolynomial σ K) (n : ℕ) : affineProjChart K σ := + Away.mk (homogeneousSubmodule (Option σ) K) (isHomogeneous_X K (none : Option σ)) + (n + f.totalDegree) (X none ^ n * homogenize f) (by + simpa only [smul_eq_mul, mul_one, mem_homogeneousSubmodule] using + (isHomogeneous_X_pow (R := K) (none : Option σ) n).mul (homogenize_isHomogeneous f)) + +theorem affineProjChartMap_normalizedHomogeneousChartEquation {K σ : Type*} [CommRing K] + (f : MvPolynomial σ K) (n : ℕ) : + affineProjChartMap (k := K) (fun i : σ => (X i : MvPolynomial σ K)) + (normalizedHomogeneousChartEquation f n) = f := by + rw [normalizedHomogeneousChartEquation, affineProjChartMap_mk] + have heval : affineProjEval (k := K) (fun i : σ => (X i : MvPolynomial σ K)) = + (coneDehomogenize : MvPolynomial (Option σ) K →ₐ[K] MvPolynomial σ K) := by + simp only [coneDehomogenize, affineProjEval, ← Option.elim'_eq_elim] + rw [heval, map_mul, map_pow] + have hX : (coneDehomogenize : MvPolynomial (Option σ) K →ₐ[K] MvPolynomial σ K) + (X none) = 1 := by simp [coneDehomogenize] + rw [hX, one_pow, one_mul] + exact dehomogenize_homogenize f + +noncomputable def projectiveStalkPolynomialEquiv {K σ : Type uProjEq} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + ((Proj (homogeneousSubmodule (Option σ) K)).presheaf.stalk (coneProjectivePoint p)) ≃+* + Localization.AtPrime p := + (Proj.stalkIso' (homogeneousSubmodule (Option σ) K) (coneProjectivePoint p)).trans + (projectiveLocalPolynomialEquiv p) + +noncomputable def normalizedHomogeneousStalkEquation {K σ : Type uProjEq} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (f : MvPolynomial σ K) (n : ℕ) : + (Proj (homogeneousSubmodule (Option σ) K)).presheaf.stalk (coneProjectivePoint p) := + (Proj.stalkIso' (homogeneousSubmodule (Option σ) K) (coneProjectivePoint p)).symm + (coneChartToHomogeneousLocal p (normalizedHomogeneousChartEquation f n)) + +theorem projectiveStalkPolynomialEquiv_normalizedEquation {K σ : Type uProjEq} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (f : MvPolynomial σ K) (n : ℕ) : + projectiveStalkPolynomialEquiv p (normalizedHomogeneousStalkEquation p f n) = + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) f := by + have h := congrArg (projectiveLocalPolynomialEquiv p) + ((Proj.stalkIso' (homogeneousSubmodule (Option σ) K) (coneProjectivePoint p)).apply_symm_apply + (coneChartToHomogeneousLocal p (normalizedHomogeneousChartEquation f n))) + exact h.trans ((projectiveLocalPolynomialEquiv_chart p _).trans + (congrArg (algebraMap (MvPolynomial σ K) (Localization.AtPrime p)) + (affineProjChartMap_normalizedHomogeneousChartEquation f n))) + +theorem projectiveStalk_normalized_parameter_ideal {ι : Type*} {K σ : Type uProjEq} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] (f : ι → MvPolynomial σ K) (n : ι → ℕ) : + (Ideal.span (Set.range fun i => normalizedHomogeneousStalkEquation p (f i) (n i))).map + (projectiveStalkPolynomialEquiv p).toRingHom = + (Ideal.span (Set.range f)).map (algebraMap (MvPolynomial σ K) (Localization.AtPrime p)) := by + simp only [Ideal.map_span, ← Set.range_comp, Function.comp_def] + exact congrArg (fun g : ι → Localization.AtPrime p => Ideal.span (Set.range g)) + (funext fun i => projectiveStalkPolynomialEquiv_normalizedEquation p (f i) (n i)) + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizedMasterBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizedMasterBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..acebdbad42d44129a2dde1856e6585e798e0c66a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NormalizedMasterBound.lean @@ -0,0 +1,43 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.FinalComparison + +theorem normalized_master_bound + {L S₁ S₂ M U ℓ logN logU logM δ C C_H : ℝ} + (hS₁ : 0 < S₁) (hlogU : 0 < logU) (hℓ : 0 < ℓ) + (hN : logN = 3 / 4 * logU) + (harch : L ≤ M / 2 * logM + (S₁ + S₂) * (logN + 1 / 2 * ℓ + Real.log 8)) + (hlower : S₁ * (logU - C * ℓ - C * δ * logU ^ 2 / ℓ - C_H) - C * M * U ≤ L) : + 1 ≤ 3 / 4 * (1 + S₂ / S₁) + + (C + 1 / 2 * (1 + S₂ / S₁)) * (ℓ / logU) + C * δ * (logU / ℓ) + + (C_H + (1 + S₂ / S₁) * Real.log 8) / logU + + (C * M * U + 1 / 2 * M * logM) / (S₁ * logU) := by + apply (mul_le_mul_iff_left₀ (mul_pos hS₁ hlogU)).mp + have hEq : S₁ * logU * + (3 / 4 * (1 + S₂ / S₁) + + (C + 1 / 2 * (1 + S₂ / S₁)) * (ℓ / logU) + C * δ * (logU / ℓ) + + (C_H + (1 + S₂ / S₁) * Real.log 8) / logU + + (C * M * U + 1 / 2 * M * logM) / (S₁ * logU)) = + M / 2 * logM + (S₁ + S₂) * (logN + 1 / 2 * ℓ + Real.log 8) + + S₁ * (C * ℓ + C * δ * logU ^ 2 / ℓ + C_H) + C * M * U := by + rw [hN] + field_simp + ring + conv_rhs => rw [mul_comm] + rw [hEq, one_mul] + linarith + +end WeightedTorusJets.FinalComparison + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/NotEventuallyMaster.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NotEventuallyMaster.lean new file mode 100644 index 0000000000000000000000000000000000000000..6feeedab57ebba84cc2d148695ae93c2b7d54731 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/NotEventuallyMaster.lean @@ -0,0 +1,449 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.NormalizedMasterBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open Filter Topology + +namespace WeightedTorusJets.FinalComparison + +theorem not_eventually_master + {ι : Type*} {l : Filter ι} [NeBot l] + {r x e : ι → ℝ} {C A : ℝ} + (hA : 0 < A) (hchoice : (C + 13 / 24) / A ≤ 1 / 16) + (hr : ∀ᶠ n in l, r n ≤ 1 / 12) + (hx : Tendsto x l (𝓝 A)) (he : Tendsto e l (𝓝 0)) : + ¬ (∀ᶠ n in l, + 1 ≤ 3 / 4 * (1 + r n) + (C + 1 / 2 * (1 + r n)) / x n + e n) := by + intro hmaster + have hxpos : ∀ᶠ n in l, 0 < x n := hx.eventually (eventually_gt_nhds hA) + have hlim : Tendsto + (fun n ↦ 13 / 16 + (C + 13 / 24) / x n + e n) l + (𝓝 (13 / 16 + (C + 13 / 24) / A)) := by + simpa using (tendsto_const_nhds.add (tendsto_const_nhds.div hx hA.ne')).add he + have hle : 1 ≤ 13 / 16 + (C + 13 / 24) / A := ge_of_tendsto hlim (by + filter_upwards [hr, hxpos, hmaster] with n hrn hxn hn + have hfirst : 3 / 4 * (1 + r n) ≤ (13 : ℝ) / 16 := by linarith + have hsecond : (C + 1 / 2 * (1 + r n)) / x n ≤ (C + 13 / 24) / x n := + (div_le_div_iff_of_pos_right hxn).mpr (by linarith) + linarith) + linarith + +end WeightedTorusJets.FinalComparison + +end + +section +open Filter _root_.Real +open scoped Topology + +namespace WeightedTorusJets + +theorem tendsto_log_natCeil_rpow_div_log {γ : ℝ} (hγ : 0 < γ) : + Tendsto (fun q : ℝ ↦ log (⌈q ^ γ⌉₊ : ℝ) / log q) atTop (𝓝 γ) := by + have hpow := tendsto_rpow_atTop hγ + have hratio : Tendsto (fun q : ℝ ↦ (⌈q ^ γ⌉₊ : ℝ) / q ^ γ) atTop (𝓝 1) := + tendsto_nat_ceil_div_atTop.comp hpow + have hlog : Tendsto (fun q : ℝ ↦ log ((⌈q ^ γ⌉₊ : ℝ) / q ^ γ)) atTop (𝓝 0) := by + simpa using hratio.log one_ne_zero + have herr := hlog.div_atTop tendsto_log_atTop + have hsum := herr.add_const γ + simp only [zero_add] at hsum + apply hsum.congr' + filter_upwards [eventually_gt_atTop (1 : ℝ)] with q hq + have hq₀ : 0 < q := lt_trans zero_lt_one hq + have hqp : 0 < q ^ γ := rpow_pos_of_pos hq₀ γ + have hceil : 0 < (⌈q ^ γ⌉₊ : ℝ) := lt_of_lt_of_le hqp (Nat.le_ceil _) + rw [log_div hceil.ne' hqp.ne', log_rpow hq₀] + field_simp [(log_pos hq).ne'] + ring + +theorem tendsto_log_scale_natCeil_rpow_div_log {γ : ℝ} (hγ : 0 < γ) : + Tendsto (fun q : ℝ ↦ log ((⌈q ^ γ⌉₊ : ℝ) ^ (4 / 3 : ℝ)) / log q) + atTop (𝓝 (4 * γ / 3)) := by + have h := (tendsto_log_natCeil_rpow_div_log hγ).const_mul (4 / 3 : ℝ) + have heq : (4 / 3 : ℝ) * γ = 4 * γ / 3 := by ring + rw [heq] at h + apply h.congr' + filter_upwards [eventually_gt_atTop (0 : ℝ)] with q hq + have hceil : 0 < (⌈q ^ γ⌉₊ : ℝ) := + lt_of_lt_of_le (rpow_pos_of_pos hq γ) (Nat.le_ceil _) + rw [log_rpow hceil] + ring + +theorem tendsto_natCeil_rpow_atTop {γ : ℝ} (hγ : 0 < γ) : + Tendsto (fun q : ℝ ↦ ⌈q ^ γ⌉₊) atTop atTop := + tendsto_nat_ceil_atTop.comp (tendsto_rpow_atTop hγ) + +theorem tendsto_scale_natCeil_rpow_atTop {γ : ℝ} (hγ : 0 < γ) : + Tendsto (fun q : ℝ ↦ (⌈q ^ γ⌉₊ : ℝ) ^ (4 / 3 : ℝ)) atTop atTop := + (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 4 / 3)).comp + (tendsto_natCast_atTop_atTop.comp (tendsto_natCeil_rpow_atTop hγ)) + +theorem exists_gamma_second_term_bound (C : ℝ) : + ∃ γ : ℝ, 0 < γ ∧ (C + 13 / 24) / (4 * γ / 3) < 1 / 16 := by + refine ⟨12 * (|C| + 1), by positivity, ?_⟩ + have hC : C ≤ |C| := le_abs_self C + rw [div_lt_iff₀ (by positivity : 0 < 4 * (12 * (|C| + 1)) / 3)] + linarith + +theorem scale_cube_eq_degree_four {N : ℝ} (hN : 0 ≤ N) : + (N ^ (4 / 3 : ℝ)) ^ (3 : ℕ) = N ^ (4 : ℕ) := by + rw [← rpow_mul_natCast hN] + norm_num + +theorem log_degree_four_eq_three_log_scale {N : ℝ} (hN : 0 < N) : + log (N ^ (4 : ℕ)) = 3 * log (N ^ (4 / 3 : ℝ)) := by + rw [log_pow, log_rpow hN] + ring + +theorem log_eq_three_quarters_log_scale {N : ℝ} (hN : 0 < N) : + log N = (3 / 4 : ℝ) * log (N ^ (4 / 3 : ℝ)) := by + rw [log_rpow hN] + ring + +end WeightedTorusJets + +end + +section +namespace WeightedTorusJets + +theorem weight_rpow_shift {H : ℝ} (hH : 0 < H) : + H ^ (-1 / 3 : ℝ) * H = H ^ (2 / 3 : ℝ) := by + rw [← Real.rpow_add_one hH.ne'] + norm_num + +theorem rectangle_weight_sum {H U : ℝ} (hH : 0 < H) : + 32 * H ^ (2 / 3 : ℝ) * U + H * (32 * H ^ (-1 / 3 : ℝ) * U) + + H * (32 * H ^ (-1 / 3 : ℝ) * U) = 96 * H ^ (2 / 3 : ℝ) * U := by + rw [← weight_rpow_shift hH] + ring + +theorem rectangle_weight_le {H U a₁ a₂ a₃ : ℝ} (hH : 0 < H) + (ha₁ : a₁ ≤ 32 * H ^ (2 / 3 : ℝ) * U) + (ha₂ : a₂ ≤ 32 * H ^ (-1 / 3 : ℝ) * U) + (ha₃ : a₃ ≤ 32 * H ^ (-1 / 3 : ℝ) * U) : + a₁ + H * a₂ + H * a₃ ≤ 96 * H ^ (2 / 3 : ℝ) * U := by + rw [← rectangle_weight_sum hH] + exact add_le_add (add_le_add ha₁ (mul_le_mul_of_nonneg_left ha₂ hH.le)) + (mul_le_mul_of_nonneg_left ha₃ hH.le) + +theorem transverse_coordinates_le {H U a₁ a₂ a₃ : ℝ} (hH : 0 < H) + (ha₁ : 0 ≤ a₁) (ha₂ : 0 ≤ a₂) (ha₃ : 0 ≤ a₃) + (hw : a₁ + H * a₂ + H * a₃ ≤ 96 * H ^ (2 / 3 : ℝ) * U) : + a₂ ≤ 96 * H ^ (-1 / 3 : ℝ) * U ∧ + a₃ ≤ 96 * H ^ (-1 / 3 : ℝ) * U := by + have hbound : 96 * H ^ (2 / 3 : ℝ) * U = + H * (96 * H ^ (-1 / 3 : ℝ) * U) := by rw [← weight_rpow_shift hH]; ring + rw [hbound] at hw + constructor + · exact (mul_le_mul_iff_right₀ hH).mp (by nlinarith) + · exact (mul_le_mul_iff_right₀ hH).mp (by nlinarith) + +theorem pivot_ratio_le {H M U S₁ S₂ : ℝ} (hH : 0 < H) (hM : 0 < M) + (hU : 0 < U) + (hS₁ : M * H ^ (2 / 3 : ℝ) * U / (4 * 97 ^ 2) ≤ S₁) + (hS₂ : S₂ ≤ 192 * M * H ^ (-1 / 3 : ℝ) * U) : + S₂ / S₁ ≤ 7226112 / H := by + have hpow : 0 < H ^ (2 / 3 : ℝ) := Real.rpow_pos_of_pos hH _ + have hS₁pos : 0 < S₁ := lt_of_lt_of_le (by positivity) hS₁ + rw [div_le_div_iff₀ hS₁pos hH] + have hmul := mul_le_mul_of_nonneg_right hS₂ hH.le + have hlower := (div_le_iff₀ (by norm_num : (0 : ℝ) < 4 * 97 ^ 2)).mp hS₁ + calc + S₂ * H ≤ 192 * M * H ^ (-1 / 3 : ℝ) * U * H := hmul + _ = 192 * (M * H ^ (2 / 3 : ℝ) * U) := by rw [← weight_rpow_shift hH]; ring + _ ≤ 7226112 * S₁ := by nlinarith + +theorem pivot_ratio_le_one_twelfth {H M U S₁ S₂ : ℝ} (hH : 86713344 ≤ H) + (hM : 0 < M) (hU : 0 < U) + (hS₁ : M * H ^ (2 / 3 : ℝ) * U / (4 * 97 ^ 2) ≤ S₁) + (hS₂ : S₂ ≤ 192 * M * H ^ (-1 / 3 : ℝ) * U) : + S₂ / S₁ ≤ 1 / 12 := by + have hHpos : 0 < H := by linarith + exact (pivot_ratio_le hHpos hM hU hS₁ hS₂).trans + ((div_le_iff₀ hHpos).mpr (by linarith)) + +theorem floor_square_bound {t : ℝ} (ht : 1 ≤ t) : + ((⌊96 * t⌋₊ : ℝ) + 1) ^ 2 ≤ 97 ^ 2 * t ^ 2 := by + have hfloor := Nat.floor_le (by linarith : 0 ≤ 96 * t) + have hfloorpos : 0 ≤ (⌊96 * t⌋₊ : ℝ) := Nat.cast_nonneg _ + have hbound : (⌊96 * t⌋₊ : ℝ) + 1 ≤ 97 * t := by linarith + nlinarith + +theorem transverse_scale_ge {H N : ℝ} (hH : 0 < H) (hHN : H ≤ N) : + N ≤ H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ) := by + have hN : 0 < N := hH.trans_le hHN + have hmono := Real.rpow_le_rpow hH.le hHN (by norm_num : (0 : ℝ) ≤ 1 / 3) + have hroot : 0 < H ^ (1 / 3 : ℝ) := Real.rpow_pos_of_pos hH _ + have hNpow : N ^ (4 / 3 : ℝ) = N * N ^ (1 / 3 : ℝ) := by + rw [show (4 / 3 : ℝ) = 1 + 1 / 3 by norm_num, Real.rpow_add hN, Real.rpow_one] + rw [show (-1 / 3 : ℝ) = -(1 / 3 : ℝ) by ring, Real.rpow_neg hH.le, hNpow] + calc + N = (H ^ (1 / 3 : ℝ))⁻¹ * (N * H ^ (1 / 3 : ℝ)) := by field_simp + _ ≤ (H ^ (1 / 3 : ℝ))⁻¹ * (N * N ^ (1 / 3 : ℝ)) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hmono hN.le) (inv_nonneg.mpr hroot.le) + +theorem pivot_floor_square_rpow_bound {H N : ℝ} (hH : 1 ≤ H) (hHN : H ≤ N) : + ((⌊96 * H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ)⌋₊ : ℝ) + 1) ^ 2 ≤ + 97 ^ 2 * H ^ (-2 / 3 : ℝ) * (N ^ (4 / 3 : ℝ)) ^ 2 := by + have hHpos : 0 < H := by linarith + have hscale := (hH.trans hHN).trans (transverse_scale_ge hHpos hHN) + have hbound := floor_square_bound hscale + have hpow : (H ^ (-1 / 3 : ℝ)) ^ 2 = H ^ (-2 / 3 : ℝ) := by + rw [← Real.rpow_mul_natCast hHpos.le] + norm_num + simpa only [mul_assoc, mul_pow, hpow] using hbound + +theorem twice_pivot_floor_square_le {H N : ℝ} (hH : 1 ≤ H) (hHN : H ≤ N) + (hNlarge : 18818 ≤ N) : + 2 * (((⌊96 * H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ)⌋₊ : ℝ) + 1) ^ 2) ≤ + N ^ 4 := by + have hN : 0 ≤ N := by linarith + have hbound := pivot_floor_square_rpow_bound hH hHN + have hp : H ^ (-2 / 3 : ℝ) ≤ 1 := + Real.rpow_le_one_of_one_le_of_nonpos hH (by norm_num) + have hpbound : 97 ^ 2 * H ^ (-2 / 3 : ℝ) * (N ^ (4 / 3 : ℝ)) ^ 2 ≤ + 97 ^ 2 * (N ^ (4 / 3 : ℝ)) ^ 2 := by nlinarith [sq_nonneg (N ^ (4 / 3 : ℝ))] + have hNU : N ≤ N ^ (4 / 3 : ℝ) := + Real.self_le_rpow_of_one_le (by linarith) (by norm_num) + have hM := scale_cube_eq_degree_four hN + have hlarge := mul_le_mul_of_nonneg_right (hNlarge.trans hNU) + (sq_nonneg (N ^ (4 / 3 : ℝ))) + nlinarith + +end WeightedTorusJets + +end + +section +open Filter +open scoped Topology + +namespace WeightedTorusJets + +theorem normalized_error_component_bounds {M U S A : ℝ} + (hM : 0 < M) (hU : 1 < U) (hA : 0 < A) + (hS : A * M * U ≤ S) (hlog : Real.log M = 3 * Real.log U) : + M * U / (S * Real.log U) ≤ 1 / (A * Real.log U) ∧ + M * Real.log M / (S * Real.log U) ≤ 3 / (A * U) := by + have hU0 : 0 < U := lt_trans zero_lt_one hU + have hL : 0 < Real.log U := Real.log_pos hU + have hden : 0 < A * M * U * Real.log U := by positivity + have hden_le : A * M * U * Real.log U ≤ S * Real.log U := + mul_le_mul_of_nonneg_right hS hL.le + constructor + · calc + M * U / (S * Real.log U) ≤ M * U / (A * M * U * Real.log U) := + div_le_div_of_nonneg_left (by positivity) hden hden_le + _ = _ := by field_simp + · have hnum : 0 ≤ M * Real.log M := by rw [hlog]; positivity + calc + M * Real.log M / (S * Real.log U) ≤ + M * Real.log M / (A * M * U * Real.log U) := + div_le_div_of_nonneg_left hnum hden hden_le + _ = _ := by rw [hlog]; field_simp + +theorem normalized_error_component_bounds_weighted {M U S H : ℝ} + (hM : 0 < M) (hU : 1 < U) (hH : 0 < H) + (hS : M * H ^ (2 / 3 : ℝ) * U / (4 * 97 ^ 2) ≤ S) + (hlog : Real.log M = 3 * Real.log U) : + M * U / (S * Real.log U) ≤ 37636 * H ^ (-(2 / 3 : ℝ)) / Real.log U ∧ + M * Real.log M / (S * Real.log U) ≤ 112908 * H ^ (-(2 / 3 : ℝ)) / U := by + have hA : 0 < H ^ (2 / 3 : ℝ) / 37636 := by positivity + have hS' : H ^ (2 / 3 : ℝ) / 37636 * M * U ≤ S := by + convert hS using 1 + ring + obtain ⟨hfirst, hsecond⟩ := normalized_error_component_bounds hM hU hA hS' hlog + constructor + · convert hfirst using 1 + rw [Real.rpow_neg hH.le] + field_simp + · convert hsecond using 1 + rw [Real.rpow_neg hH.le] + field_simp + norm_num + +theorem determinant_error_le {M U S A C : ℝ} + (hM : 0 < M) (hU : 1 < U) (hA : 0 < A) (hC : 0 ≤ C) + (hS : A * M * U ≤ S) (hlog : Real.log M = 3 * Real.log U) : + (C * M * U + (1 / 2 : ℝ) * M * Real.log M) / (S * Real.log U) ≤ + C / (A * Real.log U) + 3 / (2 * A * U) := by + obtain ⟨hfirst, hsecond⟩ := normalized_error_component_bounds hM hU hA hS hlog + calc + _ = C * (M * U / (S * Real.log U)) + + (1 / 2 : ℝ) * (M * Real.log M / (S * Real.log U)) := by ring + _ ≤ C * (1 / (A * Real.log U)) + (1 / 2 : ℝ) * (3 / (A * U)) := + add_le_add (mul_le_mul_of_nonneg_left hfirst hC) + (mul_le_mul_of_nonneg_left hsecond (by norm_num)) + _ = _ := by ring + +theorem tendsto_determinant_error {ι : Type*} {l : Filter ι} + {M U S : ι → ℝ} {A C : ℝ} (hA : 0 < A) (hC : 0 ≤ C) + (hU : Tendsto U l atTop) + (hM : ∀ᶠ n in l, 0 < M n) + (hS : ∀ᶠ n in l, A * M n * U n ≤ S n) + (hlog : ∀ᶠ n in l, Real.log (M n) = 3 * Real.log (U n)) : + Tendsto (fun n => + (C * M n * U n + (1 / 2 : ℝ) * M n * Real.log (M n)) / + (S n * Real.log (U n))) l (𝓝 0) := by + have hU1 : ∀ᶠ n in l, 1 < U n := hU.eventually_gt_atTop 1 + have hbound : Tendsto (fun n => + C / (A * Real.log (U n)) + 3 / (2 * A * U n)) l (𝓝 0) := by + have hL := Real.tendsto_log_atTop.comp hU + have hfirst := (tendsto_const_nhds (x := C)).div_atTop (hL.const_mul_atTop hA) + have hsecond := (tendsto_const_nhds (x := (3 : ℝ))).div_atTop + (hU.const_mul_atTop (by positivity : 0 < 2 * A)) + simpa using hfirst.add hsecond + refine squeeze_zero' ?_ ?_ hbound + · filter_upwards [hM, hS, hlog, hU1] with n hMn hSn hlogn hUn + have hL : 0 < Real.log (U n) := Real.log_pos hUn + have hUn0 : 0 < U n := lt_trans zero_lt_one hUn + have hSn0 : 0 < S n := lt_of_lt_of_le (by positivity) hSn + rw [hlogn] + positivity + · filter_upwards [hM, hS, hlog, hU1] with n hMn hSn hlogn hUn + exact determinant_error_le hMn hUn hA hC hSn hlogn + +theorem tendsto_bounded_ratio_log_error {ι : Type*} {l : Filter ι} + {r U : ι → ℝ} {R B K : ℝ} (hU : Tendsto U l atTop) + (hr : ∀ᶠ n in l, |r n| ≤ R) : + Tendsto (fun n => (B + (1 + r n) * K) / Real.log (U n)) l (𝓝 0) := by + have hbound := (tendsto_const_nhds (x := |B| + (1 + R) * |K|)).div_atTop + (Real.tendsto_log_atTop.comp hU) + refine squeeze_zero_norm' ?_ hbound + filter_upwards [hr, hU.eventually_gt_atTop 1] with n hrn hUn + have hL : 0 < Real.log (U n) := Real.log_pos hUn + simp only [Real.norm_eq_abs, abs_div, abs_of_pos hL] + apply div_le_div_of_nonneg_right _ hL.le + calc + |B + (1 + r n) * K| ≤ |B| + |(1 + r n) * K| := abs_add_le _ _ + _ = |B| + |1 + r n| * |K| := by rw [abs_mul] + _ ≤ |B| + (1 + R) * |K| := by + have hsum : |1 + r n| ≤ 1 + R := by + calc + _ ≤ |(1 : ℝ)| + |r n| := abs_add_le _ _ + _ ≤ 1 + R := by simpa using add_le_add_left hrn 1 + exact add_le_add le_rfl (mul_le_mul_of_nonneg_right hsum (abs_nonneg K)) + +theorem tendsto_normalized_error_sum {ι : Type*} {l : Filter ι} + {M U S₁ S₂ δ ℓ : ι → ℝ} {A C C_H a : ℝ} (hA : 0 < A) (hC : 0 ≤ C) + (hU : Tendsto U l atTop) (hδ : Tendsto δ l (𝓝 0)) + (hquot : Tendsto (fun n => Real.log (U n) / ℓ n) l (𝓝 a)) + (hM : ∀ᶠ n in l, 0 < M n) + (hS₁ : ∀ᶠ n in l, A * M n * U n ≤ S₁ n) + (hS₂ : ∀ᶠ n in l, 0 ≤ S₂ n) + (hr : ∀ᶠ n in l, S₂ n / S₁ n ≤ 1 / 12) + (hlog : ∀ᶠ n in l, Real.log (M n) = 3 * Real.log (U n)) : + Tendsto (fun n => + C * δ n * (Real.log (U n) / ℓ n) + + (C_H + (1 + S₂ n / S₁ n) * Real.log 8) / Real.log (U n) + + (C * M n * U n + (1 / 2 : ℝ) * M n * Real.log (M n)) / + (S₁ n * Real.log (U n))) l (𝓝 0) := by + have hrabs : ∀ᶠ n in l, |S₂ n / S₁ n| ≤ 1 / 12 := by + filter_upwards [hM, hS₁, hS₂, hr, hU.eventually_gt_atTop 0] + with n hMn hS₁n hS₂n hrn hUn + have hS₁pos : 0 < S₁ n := lt_of_lt_of_le (by positivity) hS₁n + rwa [abs_of_nonneg (div_nonneg hS₂n hS₁pos.le)] + have hfirst := (hδ.const_mul C).mul hquot + have hsecond := tendsto_bounded_ratio_log_error (B := C_H) (K := Real.log 8) hU hrabs + have hthird := tendsto_determinant_error hA hC hU hM hS₁ hlog + simpa using (hfirst.add hsecond).add hthird + +end WeightedTorusJets + +end + +section +namespace WeightedTorusJets.FinalComparison + +theorem uniform_master_bound {L M U ℓ S₁ S₂ δ C C_H D : ℝ} + (hM : 0 < M) (hU : 1 < U) (hℓ : 0 < ℓ) (hD : 0 < D) (hC : 0 ≤ C) + (hS₁ : D * M * U ≤ S₁) (hr : S₂ / S₁ ≤ 1 / 12) + (hlogM : Real.log M = 3 * Real.log U) + (hupper : L ≤ M / 2 * Real.log M + + (S₁ + S₂) * (3 / 4 * Real.log U + 1 / 2 * ℓ + Real.log 8)) + (hlower : S₁ * (Real.log U - C * ℓ - C * δ * Real.log U ^ 2 / ℓ - C_H) - + C * M * U ≤ L) : + 1 ≤ 13 / 16 + (C + 13 / 24) * (ℓ / Real.log U) + + C * δ * (Real.log U / ℓ) + (C_H + 13 / 12 * Real.log 8) / Real.log U + + C / (D * Real.log U) + 3 / (2 * D * U) := by + have hUpos : 0 < U := zero_lt_one.trans hU + have hlogU : 0 < Real.log U := Real.log_pos hU + have hS₁pos : 0 < S₁ := lt_of_lt_of_le (by positivity) hS₁ + have hmaster := normalized_master_bound hS₁pos hlogU hℓ rfl hupper hlower + have hfirst : 3 / 4 * (1 + S₂ / S₁) ≤ (13 : ℝ) / 16 := by linarith + have hsecond : (C + 1 / 2 * (1 + S₂ / S₁)) * (ℓ / Real.log U) ≤ + (C + 13 / 24) * (ℓ / Real.log U) := + mul_le_mul_of_nonneg_right (by linarith) (div_nonneg hℓ.le hlogU.le) + have hfixed : (C_H + (1 + S₂ / S₁) * Real.log 8) / Real.log U ≤ + (C_H + 13 / 12 * Real.log 8) / Real.log U := by + apply (div_le_div_iff_of_pos_right hlogU).mpr + have hlog8 : 0 ≤ Real.log 8 := Real.log_nonneg (by norm_num) + have := mul_le_mul_of_nonneg_right (by linarith : 1 + S₂ / S₁ ≤ 13 / 12) hlog8 + linarith + have hdet := WeightedTorusJets.determinant_error_le hM hU hD hC hS₁ hlogM + linarith + +end WeightedTorusJets.FinalComparison + +end + +section +namespace WeightedTorusJets + +open Filter Topology + +theorem exists_fixed_parameters_not_eventually_uniform_bound (C : ℝ) : + ∃ H : ℕ, 86713344 ≤ H ∧ ∃ γ : ℝ, 0 < γ ∧ + ∀ (q δ : ℕ → ℝ) (C_H : ℝ), + Tendsto q atTop atTop → Tendsto δ atTop (𝓝 0) → + let N : ℕ → ℝ := fun k ↦ (⌈q k ^ γ⌉₊ : ℝ) + let U : ℕ → ℝ := fun k ↦ N k ^ (4 / 3 : ℝ) + let D : ℝ := (H : ℝ) ^ (2 / 3 : ℝ) / (4 * 97 ^ 2) + ¬ (∀ᶠ k in atTop, + 1 ≤ 13 / 16 + (C + 13 / 24) * (Real.log (q k) / Real.log (U k)) + + C * δ k * (Real.log (U k) / Real.log (q k)) + + (C_H + 13 / 12 * Real.log 8) / Real.log (U k) + + C / (D * Real.log (U k)) + 3 / (2 * D * U k)) := by + obtain ⟨γ, hγ, hchoice⟩ := exists_gamma_second_term_bound C + refine ⟨86713344, le_rfl, γ, hγ, ?_⟩ + intro q δ C_H hq hδ N U D hbound + have hD : 0 < D := by dsimp [D]; positivity + have hU : Tendsto U atTop atTop := (tendsto_scale_natCeil_rpow_atTop hγ).comp hq + have hlogU := Real.tendsto_log_atTop.comp hU + have hratio : Tendsto (fun k ↦ Real.log (U k) / Real.log (q k)) + atTop (𝓝 (4 * γ / 3)) := (tendsto_log_scale_natCeil_rpow_div_log hγ).comp hq + have hδterm : Tendsto (fun k ↦ C * δ k * (Real.log (U k) / Real.log (q k))) + atTop (𝓝 0) := by simpa using (hδ.const_mul C).mul hratio + have hfixed := (tendsto_const_nhds (x := C_H + 13 / 12 * Real.log 8)).div_atTop hlogU + have hdet₁ := (tendsto_const_nhds (x := C)).div_atTop (hlogU.const_mul_atTop hD) + have hdet₂ := (tendsto_const_nhds (x := (3 : ℝ))).div_atTop + (hU.const_mul_atTop (by positivity : 0 < 2 * D)) + have herror : Tendsto (fun k ↦ C * δ k * (Real.log (U k) / Real.log (q k)) + + (C_H + 13 / 12 * Real.log 8) / Real.log (U k) + C / (D * Real.log (U k)) + + 3 / (2 * D * U k)) atTop (𝓝 0) := by + simpa using ((hδterm.add hfixed).add hdet₁).add hdet₂ + apply FinalComparison.not_eventually_master (r := fun _ ↦ (1 / 12 : ℝ)) + (by positivity) hchoice.le (.of_forall fun _ ↦ le_rfl) hratio herror + filter_upwards [hbound] with k hk + simpa only [show (3 / 4 : ℝ) * (1 + 1 / 12) = 13 / 16 by norm_num, + show (1 / 2 : ℝ) * (1 + 1 / 12) = 13 / 24 by norm_num, + div_div_eq_mul_div, mul_div_assoc, add_assoc] using hk + +end WeightedTorusJets + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ParameterIdeal.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ParameterIdeal.lean new file mode 100644 index 0000000000000000000000000000000000000000..41f80c007ac1f5606be1b7495955417c6bc95f3b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ParameterIdeal.lean @@ -0,0 +1,499 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.GenericNormalization + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section OriginalSourceGeometryOverlay +noncomputable section +attribute [local instance] WeightedTorusJets.Geometry.polynomialGradedAlgebra +open Module +open CategoryTheory _root_.AlgebraicGeometry _root_.OAI.Erdos970.AlgebraicGeometry +open CategoryTheory _root_.AlgebraicGeometry +open IsLocalRing +open _root_.AlgebraicGeometry TopologicalSpace CategoryTheory +open _root_.AlgebraicGeometry TopologicalSpace CategoryTheory +open CategoryTheory _root_.AlgebraicGeometry +open MvPolynomial HomogeneousLocalization +open CategoryTheory _root_.AlgebraicGeometry +open Polynomial IsLocalRing TensorProduct +namespace WeightedTorusJets + +theorem transcendental_of_nonzero_nonunit + {k A : Type*} [Field k] [CommRing A] [IsDomain A] [Algebra k A] + {t : A} (ht0 : t ≠ 0) (htu : ¬ IsUnit t) : Transcendental k t := by + intro h + exact htu (h.isIntegral.isUnit ht0) + +theorem residue_aeval_eq_eval_zero + {k A : Type*} [Field k] [CommRing A] [IsLocalRing A] [Algebra k A] + {t : A} (ht : t ∈ maximalIdeal A) (p : k[X]) : + residue A (Polynomial.aeval t p) = algebraMap k (ResidueField A) (p.eval 0) := by + have ht0 : residue A t = 0 := (residue_eq_zero_iff t).mpr ht + change (IsScalarTower.toAlgHom k A (ResidueField A)) (Polynomial.aeval t p) = _ + rw [← Polynomial.aeval_algHom_apply] + change Polynomial.aeval (residue A t) p = _ + rw [ht0, ← Polynomial.coeff_zero_eq_aeval_zero', Polynomial.coeff_zero_eq_eval_zero] + +theorem isUnit_aeval_of_eval_zero_ne_zero + {k A : Type*} [Field k] [CommRing A] [IsLocalRing A] [Algebra k A] + {t : A} (ht : t ∈ maximalIdeal A) {p : k[X]} (hp : p.eval 0 ≠ 0) : + IsUnit (Polynomial.aeval t p) := by + rw [← residue_ne_zero_iff_isUnit, residue_aeval_eq_eval_zero ht] + exact (_root_.map_ne_zero (algebraMap k (ResidueField A))).mpr hp + +abbrev parameterIdeal (k : Type*) [Field k] : Ideal k[X] := + RingHom.ker (Polynomial.evalRingHom (0 : k)) + +instance parameterIdeal_isPrime (k : Type*) [Field k] : (parameterIdeal k).IsPrime := + RingHom.ker_isPrime _ + +abbrev parameterRing (k : Type*) [Field k] := Localization.AtPrime (parameterIdeal k) + +theorem exists_parameter_local_algebra + {k A : Type*} [Field k] [CommRing A] [IsDomain A] + [IsDiscreteValuationRing A] [Algebra k A] (t : A) (ht : Irreducible t) : + ∃ φ : parameterRing k →ₐ[k] A, + Function.Injective φ ∧ IsLocalHom φ.toRingHom ∧ + (maximalIdeal (parameterRing k)).map φ.toRingHom = maximalIdeal A := by + let p := parameterIdeal k + let R := Localization.AtPrime p + have htmem : t ∈ maximalIdeal A := ht.not_isUnit + let φ : R →ₐ[k] A := IsLocalization.liftAlgHom (M := p.primeCompl) + (f := Polynomial.aeval t) fun s ↦ isUnit_aeval_of_eval_zero_ne_zero htmem s.property + have hφ : φ.toRingHom.comp (algebraMap k[X] R) = (Polynomial.aeval t).toRingHom := by + apply RingHom.ext + intro r + exact IsLocalization.lift_eq _ r + have hinj : Function.Injective φ := by + rw [show Function.Injective φ = Function.Injective φ.toRingHom from rfl, + IsLocalization.injective_iff_map_algebraMap_eq p.primeCompl] + intro x y + simp only [← RingHom.comp_apply, hφ] + change _ ↔ Polynomial.aeval t x = Polynomial.aeval t y + exact (FaithfulSMul.algebraMap_injective k[X] R).eq_iff.trans + ((transcendental_iff_injective.mp + (transcendental_of_nonzero_nonunit ht.ne_zero ht.not_isUnit)).eq_iff).symm + have hmap : (maximalIdeal R).map φ.toRingHom = maximalIdeal A := by + rw [← Localization.AtPrime.map_eq_maximalIdeal, Ideal.map_map, hφ] + have hp : p = Ideal.span {(Polynomial.X : k[X])} := by + simpa [p, parameterIdeal] using Polynomial.ker_evalRingHom (0 : k) + rw [hp, Ideal.map_span, Set.image_singleton] + change Ideal.span {Polynomial.aeval t Polynomial.X} = maximalIdeal A + rw [Polynomial.aeval_X, ht.maximalIdeal_eq] + exact ⟨φ, hinj, ((local_hom_TFAE φ.toRingHom).out 3 1).mp hmap.le, hmap⟩ + +end WeightedTorusJets + +open TensorProduct IsLocalRing + +namespace WeightedTorusJets + +theorem formallySmooth_of_flat_of_essFiniteType_of_map_maximalIdeal + {R S : Type*} [CommRing R] [CommRing S] [IsNoetherianRing R] + [IsLocalRing R] [IsLocalRing S] [Algebra R S] + [IsLocalHom (algebraMap R S)] [Module.Flat R S] + [Algebra.EssFiniteType R S] [PerfectField (ResidueField R)] + (hmap : (maximalIdeal R).map (algebraMap R S) = maximalIdeal S) : + Algebra.FormallySmooth R S := by + let e : (ResidueField R ⊗[R] S) ≃+* ResidueField S := + (Algebra.TensorProduct.quotIdealMapEquivQuotTensor S (maximalIdeal R)).symm.toRingEquiv.trans + (Ideal.quotEquivOfEq hmap) + let : Field (ResidueField R ⊗[R] S) := + (e.toMulEquiv.isField (Field.toIsField (ResidueField S))).toField + let P := Algebra.EssFiniteType.subalgebra R S + let M := Algebra.EssFiniteType.submonoid R S + have : Algebra.FinitePresentation R P := + Algebra.FinitePresentation.of_finiteType.mp inferInstance + exact Algebra.FormallySmooth.of_formallySmooth_residueField_tensor M + + + +theorem formallySmooth_of_essFiniteType_of_discreteValuationRing + {k A : Type*} [Field k] [CharZero k] [CommRing A] [IsDomain A] + [IsDiscreteValuationRing A] [Algebra k A] [Algebra.EssFiniteType k A] : + Algebra.FormallySmooth k A := by + obtain ⟨t, ht⟩ := IsDiscreteValuationRing.exists_irreducible A + obtain ⟨φ, hinj, hlocal, hmap⟩ := exists_parameter_local_algebra (k := k) t ht + let R := parameterRing k + algebraize [φ.toRingHom] + have : IsLocalHom (algebraMap R A) := hlocal + have : Module.IsTorsionFree R A := + Module.isTorsionFree_iff_algebraMap_injective.mpr hinj + have : Algebra.EssFiniteType R A := Algebra.EssFiniteType.of_comp k R A + have : CharZero (ResidueField R) := Algebra.charZero_of_charZero k (ResidueField R) + have : Algebra.FormallySmooth R A := + formallySmooth_of_flat_of_essFiniteType_of_map_maximalIdeal hmap + have : Algebra.FormallyEtale k[X] R := + Algebra.FormallyEtale.of_isLocalization (parameterIdeal k).primeCompl + have : Algebra.FormallySmooth k R := Algebra.FormallySmooth.comp k k[X] R + exact Algebra.FormallySmooth.comp k R A + +end WeightedTorusJets + +open scoped TensorProduct + +namespace WeightedTorusJets.Geometry + +variable {K A : Type*} [CommRing K] [CommRing A] [Algebra K A] + +noncomputable def conormalDifferential (I : Ideal A) : + I.Cotangent →ₗ[A ⧸ I] (A ⧸ I) ⊗[A] Ω[A⁄K] := + LinearMap.extendScalarsOfSurjective Ideal.Quotient.mk_surjective + ((KaehlerDifferential.kerCotangentToTensor K A (A ⧸ I)).comp + (Ideal.Cotangent.equivOfEq I (RingHom.ker (algebraMap A (A ⧸ I))) + Ideal.mk_ker.symm).toLinearMap) + +@[simp] +theorem conormalDifferential_toCotangent (I : Ideal A) (x : I) : + conormalDifferential (K := K) I (I.toCotangent x) = + 1 ⊗ₜ[A] KaehlerDifferential.D K A x.val := by + simp only [conormalDifferential, LinearMap.extendScalarsOfSurjective_apply, + LinearMap.comp_apply, LinearEquiv.coe_coe, Ideal.Cotangent.equivOfEq_toCotangent, + KaehlerDifferential.kerCotangentToTensor_toCotangent] + rfl + +theorem conormalDifferential_injective (I : Ideal A) + [Algebra.FormallySmooth K A] [Algebra.FormallySmooth K (A ⧸ I)] : + Function.Injective (conormalDifferential (K := K) I) := by + have hi : Function.Injective (KaehlerDifferential.kerCotangentToTensor K A (A ⧸ I)) := + (Algebra.FormallySmooth.kerCotangentToTensor_injective_iff + (R := K) Ideal.Quotient.mk_surjective).mpr inferInstance + exact hi.comp (Ideal.Cotangent.equivOfEq I + (RingHom.ker (algebraMap A (A ⧸ I))) Ideal.mk_ker.symm).injective + +theorem exists_derivation_residue_eq_one (I : Ideal A) [I.IsMaximal] + [Algebra.FormallySmooth K A] [Algebra.FormallySmooth K (A ⧸ I)] + (x : I) (hx : I.toCotangent x ≠ 0) : + ∃ D : Derivation K A A, Ideal.Quotient.mk I (D x) = 1 := by + let := Ideal.Quotient.field I + obtain ⟨φ, hφ⟩ := Module.Projective.exists_dual_eq_one (A ⧸ I) hx + obtain ⟨ψ, hψ⟩ := LinearMap.dualMap_surjective_of_injective + (conormalDifferential_injective (K := K) I) φ + let l : Ω[A⁄K] →ₗ[A] A ⧸ I := ψ.restrictScalars A ∘ₗ + TensorProduct.mk A (A ⧸ I) Ω[A⁄K] 1 + obtain ⟨f, hf⟩ := Module.projective_lifting_property (Algebra.linearMap A (A ⧸ I)) l + Ideal.Quotient.mk_surjective + refine ⟨KaehlerDifferential.linearMapEquivDerivation K A f, ?_⟩ + change Ideal.Quotient.mk I (f (KaehlerDifferential.D K A x)) = 1 + have he := LinearMap.congr_fun hf (KaehlerDifferential.D K A x) + change Ideal.Quotient.mk I (f (KaehlerDifferential.D K A x)) = + ψ (1 ⊗ₜ[A] KaehlerDifferential.D K A x) at he + rw [he, ← conormalDifferential_toCotangent] + exact (LinearMap.congr_fun hψ (I.toCotangent x)).trans hφ + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem uniformizer_cotangent_ne_zero {A : Type*} [CommRing A] [IsDomain A] + [IsDiscreteValuationRing A] (t : A) (ht : Irreducible t) + (hm : t ∈ IsLocalRing.maximalIdeal A) : + (IsLocalRing.maximalIdeal A).toCotangent ⟨t, hm⟩ ≠ 0 := by + intro h + have hd := ((IsLocalRing.maximalIdeal A).toCotangent_eq_zero ⟨t, hm⟩).mp h + change t ∈ IsLocalRing.maximalIdeal A ^ 2 at hd + rw [ht.maximalIdeal_eq, Ideal.span_singleton_pow, Ideal.mem_span_singleton] at hd + have hle : 2 ≤ 1 := (pow_dvd_pow_iff ht.ne_zero ht.not_isUnit).mp (by simpa using hd) + omega + +theorem exists_transverse_derivation_uniformizer {K A : Type*} [Field K] [PerfectField K] + [CommRing A] [IsDomain A] [IsDiscreteValuationRing A] [Algebra K A] + [Algebra.EssFiniteType K A] [Algebra.FormallySmooth K A] + (t : A) (ht : Irreducible t) : + ∃ D : Derivation K A A, IsLocalRing.residue A (D t) = 1 := by + have hm : t ∈ IsLocalRing.maximalIdeal A := by + rw [ht.maximalIdeal_eq] + exact Ideal.subset_span (Set.mem_singleton t) + let := Ideal.Quotient.field (IsLocalRing.maximalIdeal A) + have : Algebra.FormallySmooth K (A ⧸ IsLocalRing.maximalIdeal A) := inferInstance + exact exists_derivation_residue_eq_one (K := K) (IsLocalRing.maximalIdeal A) + ⟨t, hm⟩ (uniformizer_cotangent_ne_zero t ht hm) + + + +variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] + [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] + +noncomputable def localizeDerivation (M : Submonoid S) [IsLocalization M T] + (D : Derivation R S S) : Derivation R T T := + letI := Algebra.FormallyEtale.of_isLocalization (Rₘ := T) M + let d := (Algebra.ofId S T).toLinearMap.compDer D + ((d.liftKaehlerDifferential.liftBaseChange T).comp + (KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale R S T).symm.toLinearMap).compDer + (KaehlerDifferential.D R T) + +theorem localizeDerivation_algebraMap (M : Submonoid S) [IsLocalization M T] + (D : Derivation R S S) (s : S) : + localizeDerivation M D (algebraMap S T s) = algebraMap S T (D s) := by + let := Algebra.FormallyEtale.of_isLocalization (Rₘ := T) M + change ((Algebra.ofId S T).toLinearMap.compDer D).liftKaehlerDifferential.liftBaseChange T + ((KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale R S T).symm + (KaehlerDifferential.D R T (algebraMap S T s))) = _ + rw [KaehlerDifferential.tensorKaehlerEquivOfFormallyEtale_symm_D_algebraMap] + simp + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +namespace WeightedTorusJets + +theorem int_coefficients_eq_zero_of_sum_eq_zero + {ι K : Type*} [Fintype ι] [Field K] [CharZero K] + {c : ι → K} (hc : LinearIndependent ℚ c) + {n : ι → ℤ} (h : ∑ i, c i * (n i : K) = 0) : ∀ i, n i = 0 := by + apply Fintype.linearIndependent_iff.mp (hc.restrict_scalars' ℤ) n + simpa [zsmul_eq_mul, mul_comm] using h + +theorem exists_unit_mul_zpow_order + {X : AlgebraicGeometry.Scheme} [AlgebraicGeometry.IsIntegral X] + [AlgebraicGeometry.IsLocallyNoetherian X] + {x : X} (hx : Order.coheight x = 1) + [IsDiscreteValuationRing (X.presheaf.stalk x)] + {t : X.presheaf.stalk x} (ht : Irreducible t) + {f : X.functionField} (hf : f ≠ 0) : + ∃ u : (X.presheaf.stalk x)ˣ, + f = algebraMap (X.presheaf.stalk x) X.functionField (u : X.presheaf.stalk x) * + algebraMap (X.presheaf.stalk x) X.functionField t ^ X.ord f x := by + have hf_order : Ring.ordFrac (X.presheaf.stalk x) f = WithZero.exp (X.ord f x) := by + exact (AlgebraicGeometry.Scheme.ord_eq_iff hx hf).mp rfl + have hpow : Ring.ordFrac (X.presheaf.stalk x) + (algebraMap (X.presheaf.stalk x) X.functionField t ^ X.ord f x) = + Ring.ordFrac (X.presheaf.stalk x) f := by + rw [map_zpow₀, Ring.ordFrac_irreducible ht, hf_order, ← WithZero.exp_zsmul] + simp + obtain ⟨u, hu⟩ := Ring.associated_of_ordFrac_eq (R := X.presheaf.stalk x) + (algebraMap (X.presheaf.stalk x) X.functionField t ^ X.ord f x) f hpow + exact ⟨u, by simpa [Units.smul_def, Algebra.smul_def] using hu.symm⟩ + + + +theorem log_deriv_mul_zpow + {R K : Type*} [CommRing R] [Field K] [Algebra R K] + (D : Derivation R K K) {u t : K} (hu : u ≠ 0) (ht : t ≠ 0) (n : ℤ) : + D (u * t ^ n) / (u * t ^ n) = D u / u + (n : K) * (D t / t) := by + rw [D.leibniz, D.leibniz_zpow] + simp only [smul_eq_mul, zsmul_eq_mul, zpow_sub₀ ht, zpow_one] + field_simp + ring + +theorem exists_rescaled_log_deriv_lift + {R A K L : Type*} [CommRing R] [CommRing A] [Field K] [Field L] + [Algebra R A] [Algebra R K] + (φ : A →+* K) (ψ : A →+* L) + (d : Derivation R A A) (D : Derivation R K K) + (hD : ∀ a, D (φ a) = φ (d a)) + (u : Aˣ) (t : A) (n : ℤ) (ht : φ t ≠ 0) + (hres_t : ψ t = 0) : + ∃ a : A, + φ a = φ t * (D (φ (u : A) * φ t ^ n) / (φ (u : A) * φ t ^ n)) ∧ + ψ a = (n : L) * ψ (d t) := by + refine ⟨t * (↑(u⁻¹) : A) * d (u : A) + (n : A) * d t, ?_, ?_⟩ + · have hu : φ (u : A) ≠ 0 := (u.isUnit.map φ).ne_zero + rw [log_deriv_mul_zpow D hu ht n, hD, hD] + simp only [map_add, map_mul, map_intCast, map_units_inv] + field_simp + · simp [hres_t] + +theorem sum_orders_eq_zero_of_kaehler_relation + {ι k A F E : Type*} [Fintype ι] [Field k] [CommRing A] [Field F] [Field E] + [Algebra k A] [Algebra k F] [Algebra k E] + (φ : A →ₐ[k] F) (ψ : A →ₐ[k] E) (hφ : Function.Injective φ) + (d : Derivation k A A) (D : Derivation k F F) + (hD : ∀ a, D (φ a) = φ (d a)) + (u : ι → Aˣ) (t : A) (n : ι → ℤ) (c : ι → k) (ht : φ t ≠ 0) + (hres_t : ψ t = 0) (hres_dt : ψ (d t) ≠ 0) + (hω : ∑ i, (algebraMap k F (c i) / (φ (u i : A) * φ t ^ n i)) • + KaehlerDifferential.D k F (φ (u i : A) * φ t ^ n i) = 0) : + ∑ i, algebraMap k E (c i) * (n i : E) = 0 := by + have hlog : ∑ i, algebraMap k F (c i) * + (D (φ (u i : A) * φ t ^ n i) / (φ (u i : A) * φ t ^ n i)) = 0 := by + simpa only [map_sum, map_smul, map_zero, Derivation.liftKaehlerDifferential_comp_D, + smul_eq_mul, div_mul_eq_mul_div, mul_div_assoc] using + congrArg D.liftKaehlerDifferential hω + choose a ha hres using fun i => + exists_rescaled_log_deriv_lift φ.toRingHom ψ.toRingHom d D hD + (u i) t (n i) ht hres_t + simp only [AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom] at ha hres + have hA : ∑ i, algebraMap k A (c i) * a i = 0 := by + apply hφ + simp only [map_sum, map_mul, AlgHom.commutes, map_zero] + simp_rw [ha, mul_left_comm (algebraMap k F _) (φ t)] + rw [← Finset.mul_sum, hlog, mul_zero] + have hE : ∑ i, algebraMap k E (c i) * ((n i : E) * ψ (d t)) = 0 := by + simpa only [map_sum, map_mul, AlgHom.commutes, map_zero, hres] using congrArg ψ hA + simp_rw [← mul_assoc] at hE + rw [← Finset.sum_mul] at hE + exact (mul_eq_zero.mp hE).resolve_right hres_dt + + + +theorem scheme_residue_equation_of_log_form + {ι k : Type*} [Fintype ι] [Field k] [CharZero k] + {X : AlgebraicGeometry.Scheme} [AlgebraicGeometry.IsIntegral X] + [AlgebraicGeometry.IsLocallyNoetherian X] + {x : X} (hx : Order.coheight x = 1) + [IsDiscreteValuationRing (X.presheaf.stalk x)] + [Algebra k (X.presheaf.stalk x)] [Algebra k X.functionField] + [IsScalarTower k (X.presheaf.stalk x) X.functionField] + [Algebra.EssFiniteType k (X.presheaf.stalk x)] + (c : ι → k) + {f : ι → X.functionField} (hf : ∀ i, f i ≠ 0) + (hω : ∑ i, (algebraMap k X.functionField (c i) / f i) • + KaehlerDifferential.D k X.functionField (f i) = 0) : + ∑ i, c i * (X.ord (f i) x : k) = 0 := by + let A := X.presheaf.stalk x + have : Algebra.FormallySmooth k A := + formallySmooth_of_essFiniteType_of_discreteValuationRing + let φ : A →ₐ[k] X.functionField := IsScalarTower.toAlgHom k A X.functionField + let ψ : A →ₐ[k] IsLocalRing.ResidueField A := + IsScalarTower.toAlgHom k A (IsLocalRing.ResidueField A) + obtain ⟨t, ht⟩ := IsDiscreteValuationRing.exists_irreducible A + obtain ⟨d, hd⟩ := Geometry.exists_transverse_derivation_uniformizer (K := k) t ht + let D : Derivation k X.functionField X.functionField := + Geometry.localizeDerivation (nonZeroDivisors A) d + have hD : ∀ a, D (φ a) = φ (d a) := + fun a => Geometry.localizeDerivation_algebraMap (nonZeroDivisors A) d a + choose u hu using fun i => exists_unit_mul_zpow_order hx ht (hf i) + have htφ : φ t ≠ 0 := by + simpa only [φ, IsScalarTower.toAlgHom_apply, map_zero] using + (IsFractionRing.injective A X.functionField).ne ht.ne_zero + have hres_t : ψ t = 0 := by + apply (IsLocalRing.residue_eq_zero_iff t).mpr + rw [IsLocalRing.mem_maximalIdeal] + exact ht.not_isUnit + have hres_dt : ψ (d t) ≠ 0 := by + change IsLocalRing.residue A (d t) ≠ 0 + rw [hd] + exact one_ne_zero + have hω' : ∑ i, (algebraMap k X.functionField (c i) / + (φ (u i : A) * φ t ^ X.ord (f i) x)) • + KaehlerDifferential.D k X.functionField + (φ (u i : A) * φ t ^ X.ord (f i) x) = 0 := by + have hu' (i) : φ (u i : A) * φ t ^ X.ord (f i) x = f i := (hu i).symm + simpa only [hu'] using hω + apply (algebraMap k (IsLocalRing.ResidueField A)).injective + simpa only [map_sum, map_mul, map_intCast, map_zero] using + (sum_orders_eq_zero_of_kaehler_relation φ ψ (IsFractionRing.injective A X.functionField) + d D hD u t (fun i => X.ord (f i) x) c htφ hres_t hres_dt hω') + + + +universe u + +open CategoryTheory _root_.AlgebraicGeometry + +theorem schemeBaseStalkAlgebra_essFiniteType {R : Type u} [CommRing R] {X : Scheme.{u}} + (f : X ⟶ Spec (CommRingCat.of R)) [LocallyOfFiniteType f] (x : X) : + let := schemeBaseStalkAlgebra f x + Algebra.EssFiniteType R (X.presheaf.stalk x) := by + change (schemeBaseToStalk f x).EssFiniteType + have hbase : (StructureSheaf.toStalk R (f x)).hom.EssFiniteType := by + let : Algebra R ((Spec.structureSheaf R).presheaf.stalk (f x)) := + StructureSheaf.stalkAlgebra R (f x) + change Algebra.EssFiniteType R ((Spec.structureSheaf R).presheaf.stalk (f x)) + let q : PrimeSpectrum R := f x + exact Algebra.EssFiniteType.of_isLocalization _ q.asIdeal.primeCompl + exact hbase.comp (LocallyOfFiniteType.stalkMap f x) + +theorem schemeBaseStalkAlgebra_isScalarTower {R : Type u} [CommRing R] + {X : Scheme.{u}} [IrreducibleSpace X] + (f : X ⟶ Spec (CommRingCat.of R)) (x : X) : + let := schemeBaseStalkAlgebra f x + let : Algebra R X.functionField := schemeBaseStalkAlgebra f (genericPoint X) + IsScalarTower R (X.presheaf.stalk x) X.functionField := by + let := schemeBaseStalkAlgebra f x + let : Algebra R X.functionField := schemeBaseStalkAlgebra f (genericPoint X) + have : Nonempty (⊤ : X.Opens) := ⟨⟨Classical.arbitrary X, by simp⟩⟩ + apply IsScalarTower.of_algebraMap_eq' + ext a + change schemeBaseToStalk f (genericPoint X) a = + algebraMap (X.presheaf.stalk x) X.functionField (schemeBaseToStalk f x a) + simp only [schemeBaseToStalk_eq_global_germ, RingHom.comp_apply] + exact (X.algebraMap_germ_eq_germToFunctionField (show x ∈ (⊤ : X.Opens) by simp) _).symm + +end WeightedTorusJets + +namespace WeightedTorusJets + +universe u + +open CategoryTheory _root_.AlgebraicGeometry + +theorem scheme_residue_equation_of_locallyOfFiniteType + {ι : Type*} [Fintype ι] {k : Type u} [Field k] [CharZero k] + {X : Scheme.{u}} [IsIntegral X] [IsLocallyNoetherian X] + (p : X ⟶ Spec (CommRingCat.of k)) [LocallyOfFiniteType p] + {x : X} (hx : Order.coheight x = 1) + [IsIntegrallyClosed (X.presheaf.stalk x)] + (c : ι → k) (f : ι → X.functionField) (hf : ∀ i, f i ≠ 0) : + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + (∑ i, (algebraMap k X.functionField (c i) / f i) • + KaehlerDifferential.D k X.functionField (f i) = 0) → + ∑ i, c i * (X.ord (f i) x : k) = 0 := by + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + dsimp only + intro hω + let := schemeBaseStalkAlgebra p x + have : Algebra.EssFiniteType k (X.presheaf.stalk x) := + schemeBaseStalkAlgebra_essFiniteType p x + have : IsScalarTower k (X.presheaf.stalk x) X.functionField := + schemeBaseStalkAlgebra_isScalarTower p x + have : IsDiscreteValuationRing (X.presheaf.stalk x) := + Scheme.isDiscreteValuationRing_stalk_of_isIntegrallyClosed hx + exact scheme_residue_equation_of_log_form hx c hf hω + +theorem scheme_orders_zero_of_locallyOfFiniteType_log_form + {ι : Type*} [Fintype ι] {k : Type u} [Field k] [CharZero k] + {X : Scheme.{u}} [IsIntegral X] [IsLocallyNoetherian X] + [∀ x : X, IsIntegrallyClosed (X.presheaf.stalk x)] + (p : X ⟶ Spec (CommRingCat.of k)) [LocallyOfFiniteType p] + (c : ι → k) (hc : LinearIndependent ℚ c) + (f : ι → X.functionField) (hf : ∀ i, f i ≠ 0) : + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + (∑ i, (algebraMap k X.functionField (c i) / f i) • + KaehlerDifferential.D k X.functionField (f i) = 0) → + ∀ i, X.ord (f i) = 0 := by + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + dsimp only + intro hω i + funext x + change X.ord (f i) x = 0 + by_cases hx : Order.coheight x = 1 + · exact int_coefficients_eq_zero_of_sum_eq_zero hc + (scheme_residue_equation_of_locallyOfFiniteType p hx c f hf hω) i + · exact Scheme.ord_eq_zero_of_coheight_neq_one hx (f i) + +theorem scheme_global_units_of_locallyOfFiniteType_log_form + {ι : Type*} [Fintype ι] {k : Type u} [Field k] [CharZero k] + {X : Scheme.{u}} [IsIntegral X] [IsLocallyNoetherian X] + [∀ x : X, IsIntegrallyClosed (X.presheaf.stalk x)] + (p : X ⟶ Spec (CommRingCat.of k)) [LocallyOfFiniteType p] + (c : ι → k) (hc : LinearIndependent ℚ c) + (f : ι → X.functionField) (hf : ∀ i, f i ≠ 0) : + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + (∑ i, (algebraMap k X.functionField (c i) / f i) • + KaehlerDifferential.D k X.functionField (f i) = 0) → + ∀ i, ∃ s : Γ(X, ⊤), IsUnit s ∧ + X.presheaf.germ ⊤ (genericPoint X) (by simp) s = f i := by + let : Algebra k X.functionField := schemeBaseStalkAlgebra p (genericPoint X) + dsimp only + intro hω i + apply Scheme.exists_global_unit_of_ord_eq_zero (f i) (hf i) + intro x + exact congrFun (scheme_orders_zero_of_locallyOfFiniteType_log_form p c hc f hf hω i) x + +end WeightedTorusJets + +end +end OriginalSourceGeometryOverlay +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/PivotBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PivotBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..5d2a3e3b5a782d9fb34b9963a6ee97875d14ca96 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PivotBounds.lean @@ -0,0 +1,97 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.CharacterGlobalGreedyDeterminantMasterBounds + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_pivot_bounds : + ∃ c₁ C₁ : ℝ, 0 < c₁ ∧ 0 < C₁ ∧ + ∀ H : ℕ, 0 < H → ∃ N₀ : ℕ, + ∀ (q : ℕ) [NeZero q] (χ : DirichletCharacter ℂ q), + (∀ x : ZMod q, (χ x).im = 0) → χ.IsPrimitive → χ ≠ 1 → + characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ) → + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ N : ℕ, H ≤ N → N₀ ≤ N → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * + ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + ∀ e : ℕ ≃ (Fin 3 → ℕ), Monotone (fun i => w (e i)) → + let P := (greedyPivots B (R ∘ e) s.card).image e + P.card = N ^ 4 ∧ + c₁ * (N : ℝ) ^ 4 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ≤ + (∑ α ∈ P, (α 0 : ℝ)) ∧ + (∑ α ∈ P, ((α 1 : ℝ) + α 2)) ≤ + C₁ * (N : ℝ) ^ 4 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (∑ α ∈ P, ((α 1 : ℝ) + α 2)) / (∑ α ∈ P, (α 0 : ℝ)) ≤ + (C₁ / c₁) / (H : ℝ) := by + classical + obtain ⟨_, _, _, _, hmaster⟩ := source_character_global_greedy_determinant_master_bounds + refine ⟨1 / (4 * 97 ^ 2), 192, by norm_num, by norm_num, ?_⟩ + intro H hH + refine ⟨18818, ?_⟩ + intro q _ χ hreal hprim hne hfield + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hsource⟩ := + hmaster q χ hreal hprim hne hfield + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro N hHN hN n + dsimp only + intro e he + obtain ⟨g, α, _, _, hrange, _, _, _, Δ, _, _, _, _, _, _, hweights⟩ := + hsource N H hH hHN n e he + obtain ⟨hlower, hupper, _, _⟩ := hweights hN + have hHpos : (0 : ℝ) < H := by exact_mod_cast hH + have hNpos : (0 : ℝ) < N := by exact_mod_cast (hH.trans_le hHN) + refine ⟨?_, ?_, hupper, ?_⟩ + · simpa only [hrange, Set.ncard_coe_finset, Nat.card_fin] using + Set.ncard_range_of_injective α.injective + · convert hlower using 1 ; ring + · convert pivot_ratio_bound (M := (N : ℝ) ^ 4) (H := (H : ℝ)) + (t := (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)) + (by positivity) hHpos (by positivity) + (by convert hlower using 1 ; simp only [mul_assoc, pivot_primary_scale hHpos]) + (by convert hupper using 1 ; ring) using 1 ; norm_num + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialBox.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialBox.lean new file mode 100644 index 0000000000000000000000000000000000000000..61d4871a1a9f368d9e1f017b7b65d2abad9ceae2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialBox.lean @@ -0,0 +1,527 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.InvariantDerivation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section +open scoped BigOperators +namespace WeightedTorusJets.Geometry + +noncomputable def polynomialBox (K : Type*) [Field K] (N : ℕ) : + Submodule K (MvPolynomial (Fin 4) K) := + Submodule.span K (Set.range fun n : Fin 4 → Fin N => + MvPolynomial.monomial (Finsupp.equivFunOnFinite.symm fun i => (n i : ℕ)) 1) + +theorem totalDegree_lt_of_mem_polynomialBox {K : Type*} [Field K] {N : ℕ} + (hN : 0 < N) {F : MvPolynomial (Fin 4) K} (hF : F ∈ polynomialBox K N) : + F.totalDegree < 4 * N := by + induction hF using Submodule.span_induction with + | mem F hF => + obtain ⟨n, rfl⟩ := hF + change (MvPolynomial.monomial + (Finsupp.equivFunOnFinite.symm fun i => (n i : ℕ)) (1 : K)).totalDegree < _ + rw [MvPolynomial.totalDegree_monomial _ one_ne_zero, Finsupp.sum_fintype] + · simpa using Finset.sum_lt_sum_of_nonempty (s := Finset.univ) + Finset.univ_nonempty (fun i _ ↦ (n i).isLt) + · simp + | zero => simp [Nat.mul_pos (by decide : 0 < 4) hN] + | add F G _ _ hF hG => + exact (MvPolynomial.totalDegree_add F G).trans_lt (max_lt hF hG) + | smul a F _ hF => exact (MvPolynomial.totalDegree_smul_le a F).trans_lt hF + + + +def rectangleJetIdeal {ι R : Type*} [CommRing R] + (jet : (ι → ℕ) → R) (t : ι → ℕ) (b : ℕ) : Ideal R := + Ideal.span (jet '' {a | ∀ j, a j ≤ b * t j}) + +theorem rectangleJetIdeal_map {ι R S : Type*} [CommRing R] [CommRing S] + (f : R →+* S) (jet : (ι → ℕ) → R) (t : ι → ℕ) (b : ℕ) : + (rectangleJetIdeal jet t b).map f = rectangleJetIdeal (fun a => f (jet a)) t b := by + simp only [rectangleJetIdeal, Ideal.map_span, Set.image_image] + +theorem polynomial_prime_height_eq_cotangent_finrank + {K σ A : Type*} [Field K] [Finite σ] [CommRing A] [IsLocalRing A] + [Algebra (MvPolynomial σ K) A] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] [IsLocalization.AtPrime A p] : + p.height = (Module.finrank (IsLocalRing.ResidueField A) + (IsLocalRing.CotangentSpace A) : ℕ∞) := by + have : IsRegularLocalRing A := IsRegularLocalRing.of_ringEquiv + (IsLocalization.algEquiv p.primeCompl (Localization.AtPrime p) A).toRingEquiv + apply WithBot.coe_injective + rw [← IsLocalization.AtPrime.ringKrullDim_eq_height p A, + ← IsLocalRing.maximalIdeal_height_eq_ringKrullDim, regular_local_maximal_height] + +theorem rectangleJetIdeal_exists_parameters_with_length + {K A : Type*} [Field K] [Infinite K] [CommRing A] [IsLocalRing A] + [Algebra K A] [Algebra (MvPolynomial (Fin 4) K) A] + [IsScalarTower K (MvPolynomial (Fin 4) K) A] + [Algebra (Localization (Submonoid.powers + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) A] + [IsScalarTower (MvPolynomial (Fin 4) K) + (Localization (Submonoid.powers + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) A] + (p : Ideal (Localization (Submonoid.powers + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K))))) + [p.IsPrime] [IsLocalization.AtPrime A p] + (c : Fin 3 → Fin 4 → K) (t : Fin 3 → ℕ) (b : ℕ) + {N : ℕ} (hN : 0 < N) {F : MvPolynomial (Fin 4) K} + (hF : F ∈ polynomialBox K N) + (hp : p ∈ (rectangleJetIdeal + (fun a => algebraMap _ _ (invariantJet c a F)) t b).minimalPrimes) : + ∃ g : Fin (Module.finrank (IsLocalRing.ResidueField A) (IsLocalRing.CotangentSpace A)) → + MvPolynomial (Fin 4) K, + (∀ i, g i ∈ Submodule.span K + ((fun a => invariantJet c a F) '' {a | ∀ j, a j ≤ b * t j})) ∧ + (∀ i, (g i).totalDegree ≤ 4 * N) ∧ + (Ideal.span (Set.range (fun i => algebraMap (MvPolynomial (Fin 4) K) A (g i)))).radical = + IsLocalRing.maximalIdeal A ∧ + Module.length A (A ⧸ (rectangleJetIdeal + (fun a => algebraMap (MvPolynomial (Fin 4) K) + (Localization (Submonoid.powers + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) + (invariantJet c a F)) t b).map + (algebraMap (Localization (Submonoid.powers + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) A)) ≤ + Module.length A (A ⧸ Ideal.span + (Set.range (fun i => algebraMap (MvPolynomial (Fin 4) K) A (g i)))) ∧ + Module.length A (A ⧸ Ideal.span + (Set.range (fun i => algebraMap (MvPolynomial (Fin 4) K) A (g i)))) ≠ ⊤ := by + let M := Submonoid.powers (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) + let S := (fun a => invariantJet c a F) '' {a | ∀ j, a j ≤ b * t j} + have hS : ∀ f ∈ S, f.totalDegree ≤ 4 * N := by + rintro f ⟨a, _, rfl⟩ + exact (totalDegree_invariantJet_le c a F).trans + (totalDegree_lt_of_mem_polynomialBox hN hF).le + have hp' : p ∈ ((Ideal.span S).map + (algebraMap (MvPolynomial (Fin 4) K) (Localization M))).minimalPrimes := by + change p ∈ ((rectangleJetIdeal (fun a => invariantJet c a F) t b).map _).minimalPrimes + rwa [rectangleJetIdeal_map] + obtain ⟨g, hg, hd, _, hrad, hle, hfin⟩ := + polynomial_parameters_with_finite_length (A := A) M p S hp' (4 * N) hS + have hlocal : (Ideal.span S).map (algebraMap (MvPolynomial (Fin 4) K) A) = + (rectangleJetIdeal (fun a => algebraMap (MvPolynomial (Fin 4) K) (Localization M) + (invariantJet c a F)) t b).map (algebraMap (Localization M) A) := by + change (rectangleJetIdeal (fun a => invariantJet c a F) t b).map _ = _ + rw [rectangleJetIdeal_map, rectangleJetIdeal_map] + simp only [← IsScalarTower.algebraMap_apply (MvPolynomial (Fin 4) K) (Localization M) A] + refine ⟨g, hg, hd, hrad, ?_, hfin⟩ + rw [← (Ideal.quotientEquivAlgOfEq A hlocal).toLinearEquiv.length_eq] + exact hle + + +variable {K : Type*} [Field K] [Infinite K] +local notation "P₄" => MvPolynomial (Fin 4) K +local notation "T₄" => Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P₄)) + +theorem torus_rectangleJetIdeal_exists_bounded_parameters + (p : Ideal T₄) [p.IsPrime] (c : Fin 3 → Fin 4 → K) (t : Fin 3 → ℕ) (b : ℕ) + {N : ℕ} (hN : 0 < N) {F : P₄} (hF : F ∈ polynomialBox K N) + (hp : p ∈ (rectangleJetIdeal (fun a => algebraMap P₄ T₄ (invariantJet c a F)) t b).minimalPrimes) : + ∃ g : Fin (Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime p)) + (IsLocalRing.CotangentSpace (Localization.AtPrime p))) → P₄, + (∀ i, (g i).totalDegree ≤ 4 * N) ∧ + (Ideal.span (Set.range (fun i => algebraMap P₄ (Localization.AtPrime p) (g i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p) ∧ + Module.length (Localization.AtPrime p) (Localization.AtPrime p ⧸ + (rectangleJetIdeal (fun a => algebraMap P₄ T₄ (invariantJet c a F)) t b).map + (algebraMap T₄ (Localization.AtPrime p))) ≤ + Module.length (Localization.AtPrime p) (Localization.AtPrime p ⧸ + Ideal.span (Set.range (fun i => algebraMap P₄ (Localization.AtPrime p) (g i)))) := by + obtain ⟨g, _, hd, hrad, hle, _⟩ := rectangleJetIdeal_exists_parameters_with_length + (A := Localization.AtPrime p) p c t b hN hF hp + exact ⟨g, hd, hrad, hle⟩ + + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem adjoin_fractionField_coordinates + {K R L ι : Type*} [Field K] [CommRing R] [Field L] + [Algebra K R] [Algebra R L] [Algebra K L] [IsScalarTower K R L] + [IsFractionRing R L] (x : ι → R) + (hgen : Algebra.adjoin K (Set.range x) = ⊤) : + IntermediateField.adjoin K (Set.range (fun i => algebraMap R L (x i))) = ⊤ := by + let E := IntermediateField.adjoin K (Set.range (fun i => algebraMap R L (x i))) + have hR : (IsScalarTower.toAlgHom K R L).range ≤ E.toSubalgebra := by + rw [← Algebra.map_top, ← hgen, AlgHom.map_adjoin] + apply Algebra.adjoin_le + rintro _ ⟨r, ⟨i, rfl⟩, rfl⟩ + exact IntermediateField.subset_adjoin _ _ ⟨i, rfl⟩ + apply top_le_iff.mp + intro z _ + obtain ⟨a, b, _, rfl⟩ := IsFractionRing.div_surjective R z + exact E.div_mem (hR ⟨a, rfl⟩) (hR ⟨b, rfl⟩) + +theorem adjoin_quotient_coordinates + {K σ : Type*} [Field K] (I : Ideal (MvPolynomial σ K)) : + Algebra.adjoin K (Set.range (fun i => Ideal.Quotient.mk I (MvPolynomial.X i))) = ⊤ := by + rw [Algebra.adjoin_range_eq_range_aeval] + have h : MvPolynomial.aeval (fun i => Ideal.Quotient.mk I (MvPolynomial.X i)) = + Ideal.Quotient.mkₐ K I := by + ext i + simp + rw [h] + exact (AlgHom.range_eq_top _).mpr (Ideal.Quotient.mkₐ_surjective K I) + +theorem exists_coordinate_transcendence_basis + {K L ι : Type*} [Field K] [Field L] [Algebra K L] + (x : ι → L) (hgen : IntermediateField.adjoin K (Set.range x) = ⊤) : + ∃ s : Set ι, IsTranscendenceBasis K (fun i : s => x i) := by + have : Algebra.IsAlgebraic (Algebra.adjoin K (Set.range x)) L := by + rw [← IntermediateField.isAlgebraic_adjoin_iff_top, hgen, + Algebra.isAlgebraic_iff_isIntegral] + exact Algebra.isIntegral_of_surjective IntermediateField.topEquiv.surjective + obtain ⟨t, htr, ht⟩ := exists_isTranscendenceBasis_subset (R := K) (Set.range x) + obtain ⟨s, rfl, hxs⟩ := Set.exists_image_eq_injOn_of_subset_range htr + exact ⟨s, (isTranscendenceBasis_image hxs).mpr ht⟩ + +theorem exists_prime_quotient_coordinate_basis + {K σ : Type*} [Field K] (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + ∃ s : Set σ, IsTranscendenceBasis K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i))) := by + exact exists_coordinate_transcendence_basis + (K := K) (L := FractionRing (MvPolynomial σ K ⧸ p)) + (fun i : σ => algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i))) + (adjoin_fractionField_coordinates + (K := K) (R := MvPolynomial σ K ⧸ p) (L := FractionRing (MvPolynomial σ K ⧸ p)) + (fun i : σ => Ideal.Quotient.mk p (MvPolynomial.X i)) (adjoin_quotient_coordinates p)) + + + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem coefficient_nonZeroDivisors_disjoint + {B σ : Type*} [CommRing B] [IsDomain B] + (p : Ideal (MvPolynomial σ B)) + (hp : p.comap MvPolynomial.C = ⊥) : + Disjoint (((nonZeroDivisors B).map MvPolynomial.C : + Submonoid (MvPolynomial σ B)) : Set (MvPolynomial σ B)) (p : Set _) := by + apply Set.disjoint_left.mpr + rintro _ ⟨b, hb, rfl⟩ hbp + have hz : b = 0 := by + have hmem : b ∈ p.comap MvPolynomial.C := hbp + simpa [hp] using hmem + exact (mem_nonZeroDivisors_iff_ne_zero.mp hb) hz + +theorem coefficient_localization_prime_height + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + (hp : p.comap MvPolynomial.C = ⊥) : + (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsPrime ∧ + (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).height = p.height := by + let M : Submonoid (MvPolynomial σ B) := + (nonZeroDivisors B).map MvPolynomial.C + have hM := coefficient_nonZeroDivisors_disjoint p hp + exact ⟨IsLocalization.isPrime_of_isPrime_disjoint M (MvPolynomial σ F) p inferInstance hM, + IsLocalization.height_map_of_disjoint M p hM⟩ + +noncomputable def coefficientLocalizationLocalEquiv + {B F σ : Type*} [CommRing B] [IsDomain B] [Field F] + [Algebra B F] [IsFractionRing B F] + (p : Ideal (MvPolynomial σ B)) [p.IsPrime] + [((p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)))).IsPrime] + (hp : p.comap MvPolynomial.C = ⊥) : + Localization.AtPrime p ≃ₐ[MvPolynomial σ B] + Localization.AtPrime (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))) := by + let M : Submonoid (MvPolynomial σ B) := + (nonZeroDivisors B).map MvPolynomial.C + let q := p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) + have hM := coefficient_nonZeroDivisors_disjoint p hp + have := IsLocalization.isLocalization_isLocalization_atPrime_isLocalization + (M := M) (Localization.AtPrime q) q + simp_rw [q, IsLocalization.under_map_of_isPrime_disjoint M (MvPolynomial σ F) + (show p.IsPrime from inferInstance) hM] + at this + exact IsLocalization.algEquiv p.primeCompl _ _ + +theorem kernel_isMaximal_of_algebraic_field + {F L A : Type*} [Field F] [Field L] [CommRing A] + [Algebra F L] [Algebra F A] [Algebra.IsAlgebraic F L] + (f : A →ₐ[F] L) : (RingHom.ker f).IsMaximal := by + apply Ideal.Quotient.maximal_of_isField + exact (Ideal.quotientKerEquivRange f).toMulEquiv.isField + (Subalgebra.isField_of_algebraic f.range) + +theorem coefficient_localization_isMaximal + {B F L σ : Type*} [CommRing B] [Field F] [Field L] + [Algebra B F] [IsFractionRing B F] [Algebra F L] [Algebra.IsAlgebraic F L] + (p : Ideal (MvPolynomial σ B)) (f : MvPolynomial σ F →ₐ[F] L) + (hp : (RingHom.ker f).comap + (algebraMap (MvPolynomial σ B) (MvPolynomial σ F)) = p) : + (p.map (algebraMap (MvPolynomial σ B) (MvPolynomial σ F))).IsMaximal := by + rw [← hp, IsLocalization.map_under ((nonZeroDivisors B).map MvPolynomial.C) + (MvPolynomial σ F)] + exact kernel_isMaximal_of_algebraic_field f + +@[instance_reducible] noncomputable def coordinateFractionAlgebra + {K L σ : Type*} [Field K] [Field L] [Algebra K L] + {x : σ → L} (hx : AlgebraicIndependent K x) : + Algebra (FractionRing (MvPolynomial σ K)) L := + (IsFractionRing.liftAlgHom (K := FractionRing (MvPolynomial σ K)) + (algebraicIndependent_iff_injective_aeval.2 hx)).toRingHom.toAlgebra + +theorem coordinateFractionAlgebra_algebraMap + {K L σ : Type*} [Field K] [Field L] [Algebra K L] + {x : σ → L} (hx : AlgebraicIndependent K x) (b : MvPolynomial σ K) : + letI := coordinateFractionAlgebra hx + algebraMap (FractionRing (MvPolynomial σ K)) L + (algebraMap (MvPolynomial σ K) (FractionRing (MvPolynomial σ K)) b) = + MvPolynomial.aeval x b := by + exact IsFractionRing.lift_algebraMap + (algebraicIndependent_iff_injective_aeval.2 hx) b + +theorem transcendenceBasis_isAlgebraic_coordinateFraction + {K L σ : Type*} [Field K] [Field L] [Algebra K L] + {x : σ → L} (hx : IsTranscendenceBasis K x) : + letI := coordinateFractionAlgebra hx.1 + Algebra.IsAlgebraic (FractionRing (MvPolynomial σ K)) L := by + let := coordinateFractionAlgebra hx.1 + have := hx.isAlgebraic_field + apply Algebra.IsAlgebraic.of_ringHom_of_comp_eq + hx.1.aevalEquivField.toRingHom (RingHom.id L) + hx.1.aevalEquivField.surjective Function.injective_id + rfl + +theorem coordinateFraction_aeval_comp_map + {K L σ τ : Type*} [Field K] [Field L] [Algebra K L] + {x : σ → L} (hx : AlgebraicIndependent K x) (y : τ → L) : + letI := coordinateFractionAlgebra hx + (MvPolynomial.aeval (R := FractionRing (MvPolynomial σ K)) y).toRingHom.comp + (MvPolynomial.map (algebraMap (MvPolynomial σ K) + (FractionRing (MvPolynomial σ K)))) = + MvPolynomial.eval₂Hom (MvPolynomial.aeval x).toRingHom y := by + let := coordinateFractionAlgebra hx + apply MvPolynomial.ringHom_ext + · intro b + simp only [RingHom.comp_apply, MvPolynomial.map_C, MvPolynomial.eval₂Hom_C] + change MvPolynomial.aeval (R := FractionRing (MvPolynomial σ K)) y + (MvPolynomial.C (algebraMap (MvPolynomial σ K) (FractionRing (MvPolynomial σ K)) b)) = + MvPolynomial.aeval x b + rw [MvPolynomial.aeval_C] + exact coordinateFractionAlgebra_algebraMap hx b + · intro i + simp + +theorem coordinateFraction_kernel_isMaximal + {K L σ τ : Type*} [Field K] [Field L] [Algebra K L] + {x : σ → L} (hx : IsTranscendenceBasis K x) (y : τ → L) : + letI := coordinateFractionAlgebra hx.1 + ((RingHom.ker (MvPolynomial.eval₂Hom (MvPolynomial.aeval x).toRingHom y)).map + (algebraMap (MvPolynomial τ (MvPolynomial σ K)) + (MvPolynomial τ (FractionRing (MvPolynomial σ K))))).IsMaximal := by + let := coordinateFractionAlgebra hx.1 + have := transcendenceBasis_isAlgebraic_coordinateFraction hx + apply coefficient_localization_isMaximal _ + (MvPolynomial.aeval (R := FractionRing (MvPolynomial σ K)) y) + change RingHom.ker ((MvPolynomial.aeval (R := FractionRing (MvPolynomial σ K)) y).toRingHom.comp + (algebraMap (MvPolynomial τ (MvPolynomial σ K)) + (MvPolynomial τ (FractionRing (MvPolynomial σ K))))) = _ + rw [MvPolynomial.algebraMap_def, coordinateFraction_aeval_comp_map hx.1 y] + +end WeightedTorusJets.Geometry + +open scoped BigOperators +open MvPolynomial + +namespace WeightedTorusJets.Geometry + +def coordinateSplit {K σ : Type*} [CommSemiring K] (s : Set σ) : + MvPolynomial σ K ≃ₐ[K] MvPolynomial (sᶜ : Set σ) (MvPolynomial s K) := by + classical + exact (renameEquiv K ((Equiv.Set.sumCompl s).symm.trans (Equiv.sumComm _ _))).trans + (sumAlgEquiv K (sᶜ : Set σ) s) + +@[simp] theorem coordinateSplit_C {K σ : Type*} [CommSemiring K] + (s : Set σ) (c : K) : coordinateSplit s (C c) = C (C c) := by + classical + simp [coordinateSplit] + +@[simp] theorem coordinateSplit_X_mem {K σ : Type*} [CommSemiring K] + (s : Set σ) (i : s) : coordinateSplit (K := K) s (X i) = C (X i) := by + classical + simp [coordinateSplit] + +@[simp] theorem coordinateSplit_X_compl {K σ : Type*} [CommSemiring K] + (s : Set σ) (i : (sᶜ : Set σ)) : coordinateSplit (K := K) s (X i) = X i := by + classical + simp [coordinateSplit] + +theorem coordinateSplit_symm_C {K σ : Type*} [CommSemiring K] + (s : Set σ) (p : MvPolynomial s K) : + (coordinateSplit s).symm (C p) = rename (Subtype.val : s → σ) p := by + have he : (coordinateSplit (K := K) s).toAlgHom.comp + (rename (Subtype.val : s → σ)) = + IsScalarTower.toAlgHom K (MvPolynomial s K) (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) := by + ext i + simp + apply (coordinateSplit s).injective + simpa using congrArg (fun f : MvPolynomial s K →ₐ[K] + MvPolynomial (sᶜ : Set σ) (MvPolynomial s K) => f p) he.symm + +@[simp] theorem coordinateSplit_symm_X_compl {K σ : Type*} [CommSemiring K] + (s : Set σ) (i : (sᶜ : Set σ)) : + (coordinateSplit (K := K) s).symm (X i) = X (i : σ) := by + apply (coordinateSplit s).injective + simp only [AlgEquiv.apply_symm_apply, coordinateSplit_X_compl] + +theorem aeval_coordinateSplit_symm + {K A σ : Type*} [CommSemiring K] [CommSemiring A] [Algebra K A] + (s : Set σ) (x : σ → A) (q : MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) : + aeval x ((coordinateSplit s).symm q) = + eval₂ (aeval (R := K) (fun i : s => x i)).toRingHom (fun i : (sᶜ : Set σ) => x i) q := by + have he : (aeval (R := K) x).toRingHom.comp (coordinateSplit s).symm.toRingHom = + eval₂Hom (aeval (R := K) (fun i : s => x i)).toRingHom (fun i : (sᶜ : Set σ) => x i) := by + apply MvPolynomial.ringHom_ext + · intro r + simp [coordinateSplit_symm_C, aeval_rename, Function.comp_def] + · intro i + simp + exact congrArg (fun f : MvPolynomial (sᶜ : Set σ) (MvPolynomial s K) →+* A => f q) he + +theorem coordinateSplit_comap_coefficients_eq_bot + {K σ : Type*} [Field K] (s : Set σ) (p : Ideal (MvPolynomial σ K)) + (hs : AlgebraicIndependent K (fun i : s => Ideal.Quotient.mk p (X i))) : + (p.comap (coordinateSplit s).symm.toRingHom).comap + (algebraMap (MvPolynomial s K) (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K))) = ⊥ := by + apply bot_unique + intro q hq + change (coordinateSplit s).symm (C q) ∈ p at hq + rw [coordinateSplit_symm_C] at hq + apply hs.eq_zero_of_aeval_eq_zero q + have he : aeval (fun i : s => Ideal.Quotient.mk p (X i)) = + (Ideal.Quotient.mkₐ K p).comp (rename (Subtype.val : s → σ)) := by + ext i + simp + rw [he] + exact Ideal.Quotient.eq_zero_iff_mem.mpr hq + +theorem coordinateSplit_comap_coefficients_eq_bot_of_fractionField + {K σ : Type*} [Field K] (s : Set σ) (p : Ideal (MvPolynomial σ K)) + (hs : AlgebraicIndependent K (fun i : s => + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (X i)))) : + (p.comap (coordinateSplit s).symm.toRingHom).comap + (algebraMap (MvPolynomial s K) (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K))) = ⊥ := by + apply coordinateSplit_comap_coefficients_eq_bot s p + exact hs.of_comp (IsScalarTower.toAlgHom K (MvPolynomial σ K ⧸ p) + (FractionRing (MvPolynomial σ K ⧸ p))) + +def coordinateSplitLocalEquiv + {K σ : Type*} [CommRing K] (s : Set σ) (p : Ideal (MvPolynomial σ K)) [p.IsPrime] : + Localization.AtPrime p ≃ₐ[K] + Localization.AtPrime (p.comap (coordinateSplit s).symm.toRingHom) := + (Localization.localAlgEquiv (p.comap (coordinateSplit s).symm.toRingHom) p + (coordinateSplit s).symm rfl).symm + +theorem totalDegree_coordinateSplit_le + {K σ : Type*} [CommSemiring K] (s : Set σ) (p : MvPolynomial σ K) : + (coordinateSplit s p).totalDegree ≤ p.totalDegree := by + classical + let φ := (coordinateSplit (K := K) s).toRingHom + have hX : ∀ i : σ, (φ (X i)).totalDegree ≤ 1 := by + intro i + by_cases hi : i ∈ s + · change (coordinateSplit s (X (⟨i, hi⟩ : s))).totalDegree ≤ 1 + rw [coordinateSplit_X_mem s ⟨i, hi⟩] + simp + · change (coordinateSplit s (X (⟨i, hi⟩ : (sᶜ : Set σ)))).totalDegree ≤ 1 + rw [coordinateSplit_X_compl s ⟨i, hi⟩] + cases subsingleton_or_nontrivial K + · simp [Subsingleton.elim (X (⟨i, hi⟩ : (sᶜ : Set σ)) : MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) 0] + · simp + change (φ p).totalDegree ≤ p.totalDegree + conv_lhs => rw [p.as_sum, map_sum] + apply totalDegree_finsetSum_le + intro d hd + apply le_trans _ (le_totalDegree hd) + rw [monomial_eq, map_mul, Finsupp.prod, map_prod] + calc + _ ≤ (φ (C (p.coeff d))).totalDegree + + (∑ i ∈ d.support, (φ (X i ^ d i)).totalDegree) := + (totalDegree_mul _ _).trans + (Nat.add_le_add_left (totalDegree_finsetProd _ _) _) + _ = ∑ i ∈ d.support, ((φ (X i)) ^ d i).totalDegree := by simp [φ] + _ ≤ ∑ i ∈ d.support, d i := by + apply Finset.sum_le_sum + intro i _ + exact (totalDegree_pow _ _).trans + (by simpa using Nat.mul_le_mul_left (d i) (hX i)) + _ = d.sum (fun _ e => e) := rfl + +theorem totalDegree_localized_coordinateSplit_le + {K σ : Type*} [Field K] (s : Set σ) (p : MvPolynomial σ K) : + (MvPolynomial.map (algebraMap (MvPolynomial s K) (FractionRing (MvPolynomial s K))) + (coordinateSplit s p)).totalDegree ≤ p.totalDegree := by + exact (Finset.sup_mono (support_map_subset _ _)).trans (totalDegree_coordinateSplit_le s p) + + + + +def componentCoordinate {K σ : Type*} [Field K] + (p : Ideal (MvPolynomial σ K)) (i : σ) : + FractionRing (MvPolynomial σ K ⧸ p) := + algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p (MvPolynomial.X i)) + +theorem aeval_componentCoordinate {K σ : Type*} [Field K] + (p : Ideal (MvPolynomial σ K)) : + MvPolynomial.aeval (componentCoordinate p) = + (IsScalarTower.toAlgHom K (MvPolynomial σ K ⧸ p) + (FractionRing (MvPolynomial σ K ⧸ p))).comp (Ideal.Quotient.mkₐ K p) := by + ext i + simp [componentCoordinate] + +theorem ker_aeval_componentCoordinate {K σ : Type*} [Field K] + (p : Ideal (MvPolynomial σ K)) : + RingHom.ker (MvPolynomial.aeval (componentCoordinate p)).toRingHom = p := by + rw [aeval_componentCoordinate] + ext q + change algebraMap (MvPolynomial σ K ⧸ p) (FractionRing (MvPolynomial σ K ⧸ p)) + (Ideal.Quotient.mk p q) = 0 ↔ q ∈ p + rw [map_eq_zero_iff _ (IsFractionRing.injective (MvPolynomial σ K ⧸ p) + (FractionRing (MvPolynomial σ K ⧸ p))), Ideal.Quotient.eq_zero_iff_mem] + +theorem coordinateSplit_prime_eq_evaluation_kernel {K σ : Type*} [Field K] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) : + p.comap (coordinateSplit s).symm.toRingHom = + RingHom.ker (MvPolynomial.eval₂Hom + (MvPolynomial.aeval (R := K) (fun i : s => componentCoordinate p i)).toRingHom + (fun i : (sᶜ : Set σ) => componentCoordinate p i)) := by + conv_lhs => rw [← ker_aeval_componentCoordinate p] + rw [RingHom.comap_ker] + congr 1 + apply RingHom.ext + intro q + exact aeval_coordinateSplit_symm s (componentCoordinate p) q + +attribute [local instance] MvPolynomial.algebraMvPolynomial + +theorem coordinateSplit_localized_prime_isMaximal {K σ : Type*} [Field K] + (s : Set σ) (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (hs : IsTranscendenceBasis K (fun i : s => componentCoordinate p i)) : + ((p.comap (coordinateSplit s).symm.toRingHom).map + (algebraMap (MvPolynomial (sᶜ : Set σ) (MvPolynomial s K)) + (MvPolynomial (sᶜ : Set σ) (FractionRing (MvPolynomial s K))))).IsMaximal := by + rw [coordinateSplit_prime_eq_evaluation_kernel] + exact coordinateFraction_kernel_isMaximal hs + (fun i : (sᶜ : Set σ) => componentCoordinate p i) + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialLaurent.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialLaurent.lean new file mode 100644 index 0000000000000000000000000000000000000000..f79ef3740aa91c8b45e1b5c3a042b4ff36f67626 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialLaurent.lean @@ -0,0 +1,487 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.FinrankDerivationCardTranscendenceBasis +import OAI.NumberTheory.Jacobsthal.Siegel.NormalizationPresentationLocalEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section + +namespace WeightedTorusJets.Geometry +open scoped BigOperators +variable (K ι : Type*) [CommRing K] +local notation "P" => MvPolynomial ι K +local notation "G" => ι →₀ ℤ +local notation "A" => AddMonoidAlgebra K G +local notation "L" => Localization.Away (∏ i : ι, (MvPolynomial.X i : P)) + +noncomputable def polynomialToLaurent : P →ₐ[K] A := + MvPolynomial.aeval fun i => AddMonoidAlgebra.single (Finsupp.single i 1) 1 + +@[simp] theorem polynomialToLaurent_X (i : ι) : + polynomialToLaurent K ι (MvPolynomial.X i) = + AddMonoidAlgebra.single (Finsupp.single i 1) 1 := + MvPolynomial.aeval_X _ _ + +variable [Fintype ι] + +noncomputable def localizationToLaurent : L →ₐ[K] A := + IsLocalization.Away.liftAlgHom (∏ i : ι, (MvPolynomial.X i : P)) + (f := polynomialToLaurent K ι) (by + simpa [map_prod] using + (Group.isUnit (Multiplicative.ofAdd (∑ i : ι, Finsupp.single i (1 : ℤ)))).map + (AddMonoidAlgebra.of K G)) + +noncomputable def localizedCoordinateUnit (i : ι) : Lˣ := + (IsLocalization.Away.isUnit_of_dvd _ + (Finset.dvd_prod_of_mem (fun j : ι => (MvPolynomial.X j : P)) (Finset.mem_univ i))).unit + +@[simp] theorem localizedCoordinateUnit_val (i : ι) : + (localizedCoordinateUnit K ι i : L) = algebraMap P L (MvPolynomial.X i) := by + rfl + +noncomputable def localizedExponentHom : Multiplicative G →* Lˣ := + AddMonoidHom.toMultiplicativeLeft + (Finsupp.liftAddHom fun i => + zmultiplesHom (Additive Lˣ) (Additive.ofMul (localizedCoordinateUnit K ι i))) + +@[simp] theorem localizedExponentHom_single (i : ι) (n : ℤ) : + localizedExponentHom K ι (Multiplicative.ofAdd (Finsupp.single i n)) = + localizedCoordinateUnit K ι i ^ n := by + simp [localizedExponentHom] + +noncomputable def laurentToLocalization : A →ₐ[K] L := + AddMonoidAlgebra.lift K L G + ((Units.coeHom L).comp (localizedExponentHom K ι)) + +noncomputable def laurentEquivLocalization : A ≃ₐ[K] L := + AlgEquiv.ofAlgHom (laurentToLocalization K ι) (localizationToLaurent K ι) + (by + ext i + simp [Algebra.algHom, localizationToLaurent, laurentToLocalization]) + (by + apply (AddMonoidAlgebra.lift K A G).symm.injective + ext i + simp [localizationToLaurent, laurentToLocalization]) + +@[simp] theorem laurentEquivLocalization_coordinate (i : ι) : + laurentEquivLocalization K ι (AddMonoidAlgebra.single (Finsupp.single i 1) 1) = + algebraMap P L (MvPolynomial.X i) := by + simp [laurentEquivLocalization, laurentToLocalization] + +end WeightedTorusJets.Geometry + +end + +section SamePrimeDimensionPrerequisites + +namespace WeightedTorusJets.Geometry + +theorem prime_height_eq_under_of_integral_goingDown + {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] + [Algebra.IsIntegral R S] [Algebra.HasGoingDown R S] + (P : Ideal S) [P.IsPrime] : P.height = (P.under R).height := by + let f := PrimeSpectrum.comap (algebraMap R S) + have hf : StrictMono f := by + intro p q hpq + exact Ideal.IsIntegral.under_lt_under hpq + have hlift : ∀ a : PrimeSpectrum S, ∀ b : PrimeSpectrum R, b < f a → + ∃ a' : PrimeSpectrum S, a' < a ∧ f a' = b := by + intro a b hba + obtain ⟨Q, hQa, hQ, hQb⟩ := + Ideal.exists_ideal_lt_liesOver_of_lt a.asIdeal hba + let := hQ + let := hQb + refine ⟨⟨Q, hQ⟩, hQa, ?_⟩ + apply PrimeSpectrum.ext + exact (Q.over_def b.asIdeal).symm + have h := Order.height_eq_of_strictMono f hf hlift + (⟨P, inferInstance⟩ : PrimeSpectrum S) + rw [← PrimeSpectrum.height_eq_orderHeight, + ← PrimeSpectrum.height_eq_orderHeight] at h + exact h + + + +theorem maximal_height_eq_ringKrullDim_of_finiteType + {K A : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [Algebra.FiniteType K A] (P : Ideal A) [P.IsMaximal] : + (P.height : WithBot ℕ∞) = ringKrullDim A := by + obtain ⟨n, g, hinj, hint⟩ := exists_integral_inj_algHom_of_fg K A + let : Algebra (MvPolynomial (Fin n) K) A := g.toRingHom.toAlgebra + let : Algebra.IsIntegral (MvPolynomial (Fin n) K) A := ⟨hint⟩ + let : FaithfulSMul (MvPolynomial (Fin n) K) A := + (faithfulSMul_iff_algebraMap_injective _ _).mpr hinj + let : (P.under (MvPolynomial (Fin n) K)).IsMaximal := + Ideal.isMaximal_under_of_isIntegral_of_isMaximal P + rw [prime_height_eq_under_of_integral_goingDown (R := MvPolynomial (Fin n) K) P, + maximal_polynomial_height n (P.under (MvPolynomial (Fin n) K)), + ringKrullDim_eq_of_integral_faithful_goingDown (R := MvPolynomial (Fin n) K)] + simp + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets + +end WeightedTorusJets + +namespace WeightedTorusJets.Geometry + +universe uK uA uF uC uE + +theorem altitude_of_relative_fraction_fields + {K : Type uK} {A : Type uA} {F : Type uF} {C : Type uC} {E : Type uE} + [Field K] [CommRing A] [IsDomain A] [Algebra K A] [Algebra.FiniteType K A] + [Field F] [Algebra K F] [CommRing C] [IsDomain C] [Algebra F C] + [Algebra.FiniteType F C] [Field E] [Algebra K E] [Algebra A E] + [IsScalarTower K A E] [IsFractionRing A E] [Algebra F E] [Algebra C E] + [IsScalarTower F C E] [IsFractionRing C E] [IsScalarTower K F E] + (p : Ideal A) [p.IsPrime] (P : Ideal C) [P.IsMaximal] + (hpht : p.height = P.height) + (hF : Cardinal.lift.{uA} (Algebra.trdeg K F) = + Cardinal.lift.{uF} (Algebra.trdeg K (A ⧸ p))) : + (p.height : WithBot ℕ∞) + ringKrullDim (A ⧸ p) = ringKrullDim A := by + obtain ⟨nA, hdimA, htrdegA⟩ := finiteType_dimension_trdeg (K := K) (A := A) + obtain ⟨nC, hdimC, htrdegC⟩ := finiteType_dimension_trdeg (K := F) (A := C) + obtain ⟨nQ, hdimQ, htrdegQ⟩ := finiteType_dimension_trdeg (K := K) (A := A ⧸ p) + have hAE : Algebra.trdeg K E = nA := fractionField_trdeg_eq_nat nA htrdegA + have hCE : Algebra.trdeg F E = nC := fractionField_trdeg_eq_nat nC htrdegC + have hKF : Algebra.trdeg K F = nQ := by simpa [htrdegQ] using hF + have htower := lift_trdeg_add_eq K F E + have hsum : nQ + nC = nA := by + simpa [hKF, hCE, hAE, ← Nat.cast_add] using htower + rw [hpht, maximal_height_eq_ringKrullDim_of_finiteType (K := F), hdimC, hdimQ, + hdimA, ← Nat.cast_add, Nat.add_comm nC nQ, hsum] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem exists_injective_polynomial_quotient_lift + {K A ι : Type*} [CommRing K] [CommRing A] [Algebra K A] + (p : Ideal A) (g : MvPolynomial ι K →ₐ[K] A ⧸ p) + (hinj : Function.Injective g) : + ∃ f : MvPolynomial ι K →ₐ[K] A, + (Ideal.Quotient.mkₐ K p).comp f = g ∧ Function.Injective f := by + classical + choose x hx using fun i : ι => Ideal.Quotient.mkₐ_surjective K p (g (MvPolynomial.X i)) + let f : MvPolynomial ι K →ₐ[K] A := MvPolynomial.aeval x + have hf : (Ideal.Quotient.mkₐ K p).comp f = g := by + ext i + simpa [f] using hx i + refine ⟨f, hf, ?_⟩ + intro a b hab + apply hinj + simpa only [← hf, AlgHom.comp_apply] using congrArg (Ideal.Quotient.mkₐ K p) hab + +theorem polynomial_quotient_lift_properties + {K A ι : Type*} [Field K] [CommRing A] [Algebra K A] + (p : Ideal A) [p.IsPrime] (f : MvPolynomial ι K →ₐ[K] A) + (g : MvPolynomial ι K →ₐ[K] A ⧸ p) + (hf : (Ideal.Quotient.mkₐ K p).comp f = g) + (hinj : Function.Injective g) (hint : g.IsIntegral) : + let : Algebra (MvPolynomial ι K) A := f.toRingHom.toAlgebra + p.under (MvPolynomial ι K) = ⊥ ∧ + Algebra.IsIntegral (MvPolynomial ι K) (A ⧸ p) ∧ + Algebra.algebraMapSubmonoid A (nonZeroDivisors (MvPolynomial ι K)) ≤ p.primeCompl := by + let : Algebra (MvPolynomial ι K) A := f.toRingHom.toAlgebra + have hm : algebraMap (MvPolynomial ι K) (A ⧸ p) = g.toRingHom := by + apply RingHom.ext + intro b + exact congrArg (fun h : MvPolynomial ι K →ₐ[K] A ⧸ p => h b) hf + have hzero (b : MvPolynomial ι K) (hb : f b ∈ p) : b = 0 := by + apply hinj + rw [map_zero, ← hf, AlgHom.comp_apply] + exact Ideal.Quotient.eq_zero_iff_mem.mpr hb + refine ⟨?_, ⟨?_, ?_⟩⟩ + · apply le_antisymm _ bot_le + intro b hb + exact Ideal.mem_bot.mpr (hzero b hb) + · constructor + intro b + change (algebraMap (MvPolynomial ι K) (A ⧸ p)).IsIntegralElem b + rw [hm] + exact hint b + · rintro b ⟨c, hc, rfl⟩ + change f c ∉ p + intro hp + exact (mem_nonZeroDivisors_iff_ne_zero.mp hc) (hzero c hp) + + + +theorem localized_prime_isMaximal_of_quotient_integral + {B A : Type*} [CommRing B] [IsDomain B] [CommRing A] [Algebra B A] + (C : Type*) [CommRing C] [Algebra A C] + [IsLocalization (Algebra.algebraMapSubmonoid A (nonZeroDivisors B)) C] + (p : Ideal A) [p.IsPrime] (hp : p.under B = ⊥) + [Algebra.IsIntegral B (A ⧸ p)] : + (p.map (algebraMap A C)).IsMaximal := by + let M := Algebra.algebraMapSubmonoid A (nonZeroDivisors B) + have hdisj : Disjoint (M : Set A) (p : Set A) := by + apply Set.disjoint_left.mpr + rintro a ⟨b, hb, rfl⟩ ha + have hbp : b ∈ p.under B := ha + rw [hp] at hbp + exact nonZeroDivisors.ne_zero hb hbp + have : (p.map (algebraMap A C)).IsPrime := + IsLocalization.isPrime_of_isPrime_disjoint M C p inferInstance hdisj + let Q := C ⧸ p.map (algebraMap A C) + have : IsLocalization (Algebra.algebraMapSubmonoid (A ⧸ p) (nonZeroDivisors B)) Q := by + simpa only [M, Algebra.algebraMapSubmonoid_map_map] using + (inferInstance : IsLocalization (Algebra.algebraMapSubmonoid (A ⧸ p) M) Q) + let f : FractionRing B →+* Q := IsLocalization.map Q (algebraMap B (A ⧸ p)) + (show nonZeroDivisors B ≤ + (Algebra.algebraMapSubmonoid (A ⧸ p) (nonZeroDivisors B)).comap _ from + (nonZeroDivisors B).le_comap_map) + let : Algebra (FractionRing B) Q := f.toAlgebra + have : Algebra.IsIntegral (FractionRing B) Q := + ⟨isIntegral_localization (M := nonZeroDivisors B)⟩ + apply Ideal.Quotient.maximal_of_isField + exact isField_of_isIntegral_of_isField' (R := FractionRing B) (S := Q) (Field.toIsField _) + + + +variable {B A : Type*} [CommRing B] [CommRing A] [IsDomain A] + [Algebra B A] [FaithfulSMul B A] + +theorem relative_denominators_le_nonZeroDivisors : + Algebra.algebraMapSubmonoid A (nonZeroDivisors B) ≤ nonZeroDivisors A := + map_le_nonZeroDivisors_of_injective (algebraMap B A) + (FaithfulSMul.algebraMap_injective B A) le_rfl + +noncomputable abbrev relativeLocalizationFractionAlgebra : + Algebra (Localization (Algebra.algebraMapSubmonoid A (nonZeroDivisors B))) + (FractionRing A) := + IsLocalization.localizationAlgebraOfSubmonoidLe _ _ + (Algebra.algebraMapSubmonoid A (nonZeroDivisors B)) (nonZeroDivisors A) + relative_denominators_le_nonZeroDivisors + +attribute [local instance] relativeLocalizationFractionAlgebra + +theorem relativeLocalizationFraction_scalarTower : + IsScalarTower A + (Localization (Algebra.algebraMapSubmonoid A (nonZeroDivisors B))) + (FractionRing A) := + IsLocalization.localization_isScalarTower_of_submonoid_le _ _ + (Algebra.algebraMapSubmonoid A (nonZeroDivisors B)) (nonZeroDivisors A) + relative_denominators_le_nonZeroDivisors + +attribute [local instance] relativeLocalizationFraction_scalarTower + +attribute [local instance] FractionRing.liftAlgebra + +theorem relativeLocalization_fractionBase_scalarTower : + IsScalarTower (FractionRing B) + (Localization (Algebra.algebraMapSubmonoid A (nonZeroDivisors B))) + (FractionRing A) := by + let C := Localization (Algebra.algebraMapSubmonoid A (nonZeroDivisors B)) + have : IsScalarTower B C (FractionRing A) := IsScalarTower.to₁₃₄ B A C (FractionRing A) + apply IsScalarTower.of_algebraMap_eq' + apply IsLocalization.ringHom_ext (nonZeroDivisors B) + ext b + simp only [RingHom.comp_apply, ← IsScalarTower.algebraMap_apply] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem prime_height_add_quotient_dim_eq_of_finiteType + {K A : Type*} [Field K] [CommRing A] [IsDomain A] [Algebra K A] + [Algebra.FiniteType K A] (p : Ideal A) [p.IsPrime] : + (p.height : WithBot ℕ∞) + ringKrullDim (A ⧸ p) = ringKrullDim A := by + obtain ⟨n, g, hginj, hgint⟩ := exists_integral_inj_algHom_of_fg K (A ⧸ p) + obtain ⟨f, hf, hfinj⟩ := exists_injective_polynomial_quotient_lift p g hginj + let B := MvPolynomial (Fin n) K + let : Algebra B A := f.toRingHom.toAlgebra + let : FaithfulSMul B A := + (faithfulSMul_iff_algebraMap_injective _ _).mpr hfinj + obtain ⟨hpB, hqint, hdenom⟩ := polynomial_quotient_lift_properties p f g hf hginj hgint + let : Algebra.IsIntegral B (A ⧸ p) := hqint + let : Algebra.FiniteType B A := Algebra.FiniteType.of_restrictScalars_finiteType K B A + let M := Algebra.algebraMapSubmonoid A (nonZeroDivisors B) + let C := Localization M + let : IsDomain C := IsLocalization.isDomain_of_le_nonZeroDivisors C + (relative_denominators_le_nonZeroDivisors (B := B) (A := A)) + let : Algebra.FiniteType (FractionRing B) C := Algebra.FiniteType.equiv inferInstance + (Localization.tensorRightAlgEquiv (nonZeroDivisors B) A) + let P := p.map (algebraMap A C) + let : P.IsMaximal := localized_prime_isMaximal_of_quotient_integral C p hpB + have hdisj : Disjoint (M : Set A) (p : Set A) := by + apply Set.disjoint_left.mpr + intro a ha hpa + exact hdenom ha hpa + have hpht : p.height = P.height := by + have hu : P.under A = p := IsLocalization.under_map_of_isPrime_disjoint M C + inferInstance hdisj + simpa only [hu] using IsLocalization.height_under M P + let : Algebra C (FractionRing A) := relativeLocalizationFractionAlgebra + let : IsScalarTower A C (FractionRing A) := relativeLocalizationFraction_scalarTower + let : IsFractionRing C (FractionRing A) := + IsFractionRing.isFractionRing_of_isLocalization M _ _ + (relative_denominators_le_nonZeroDivisors (B := B) (A := A)) + let : Algebra (FractionRing B) (FractionRing A) := FractionRing.liftAlgebra B (FractionRing A) + let : IsScalarTower (FractionRing B) C (FractionRing A) := + relativeLocalization_fractionBase_scalarTower + have hqtr : Algebra.trdeg K (A ⧸ p) = n := + trdeg_eq_of_integral_polynomial_base n g hginj hgint + have hftr : Algebra.trdeg K (FractionRing B) = n := + fractionField_trdeg_eq_nat (K := K) (A := B) (F := FractionRing B) n + (by simp [B, MvPolynomial.trdeg_of_isDomain]) + apply altitude_of_relative_fraction_fields (K := K) (F := FractionRing B) + (C := C) (E := FractionRing A) p P hpht + simp [hftr, hqtr] + + + +variable {K : Type*} [Field K] + +theorem localization_mvPolynomial_ringKrullDim_le (n : ℕ) + (M : Submonoid (MvPolynomial (Fin n) K)) + (S : Type*) [CommRing S] [Algebra (MvPolynomial (Fin n) K) S] [IsLocalization M S] : + ringKrullDim S ≤ n := by + apply (ringKrullDim_le_iff_height_le _).mpr + intro p hp + have := hp + rw [← IsLocalization.height_under M p] + have h := (p.under (MvPolynomial (Fin n) K)).height_le_ringKrullDim_of_isPrime + simpa using h + +theorem torus_chart_ringKrullDim (n : ℕ) : + ringKrullDim (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) = n := by + let R := MvPolynomial (Fin n) K + let t : R := ∏ i : Fin n, MvPolynomial.X i + let T := Localization.Away t + have hle : ringKrullDim T ≤ n := + localization_mvPolynomial_ringKrullDim_le n (Submonoid.powers t) T + apply le_antisymm hle + let p : Ideal R := RingHom.ker (MvPolynomial.eval (fun _ : Fin n ↦ (1 : K))) + have hp : p.IsMaximal := RingHom.ker_isMaximal_of_surjective _ (by + intro c + exact ⟨MvPolynomial.C c, MvPolynomial.eval_C c⟩) + have hdisj : Disjoint (Submonoid.powers t : Set R) (p : Set R) := by + apply (Ideal.disjoint_powers_iff_notMem_of_isPrime t).mpr + change MvPolynomial.eval (fun _ : Fin n ↦ (1 : K)) + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)) ≠ 0 + simp only [map_prod, MvPolynomial.eval_X, Finset.prod_const_one, ne_eq, one_ne_zero, not_false_eq_true] + have hpT : (p.map (algebraMap R T)).IsPrime := + IsLocalization.isPrime_of_isPrime_disjoint (Submonoid.powers t) T p hp.isPrime hdisj + have hheight : (p.map (algebraMap R T)).height = n := by + rw [IsLocalization.height_map_of_disjoint (Submonoid.powers t) p hdisj] + exact maximal_polynomial_height n p + have h := (p.map (algebraMap R T)).height_le_ringKrullDim_of_isPrime + simpa [hheight] using h + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem torus_component_cotangent_eq_codimension {K : Type*} [Field K] (n : ℕ) + (q : Ideal (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))) [q.IsPrime] : + Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) = + n - ((ringKrullDim (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)) ⧸ q)).unbotD 0).toNat := by + let R := MvPolynomial (Fin n) K + let t : R := ∏ i : Fin n, MvPolynomial.X i + let T := Localization.Away t + have ht : t ≠ 0 := Finset.prod_ne_zero_iff.mpr fun i _ ↦ MvPolynomial.X_ne_zero i + have : IsDomain T := IsLocalization.isDomain_of_le_nonZeroDivisors T + (powers_le_nonZeroDivisors_of_noZeroDivisors ht) + have : IsRegularLocalRing (Localization.AtPrime q) := + regular_localization_component (Submonoid.powers t) q + have hheight : (Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) : WithBot ℕ∞) = q.height := + ((IsRegularLocalRing.iff_finrank_cotangentSpace (Localization.AtPrime q)).mp inferInstance).trans + (IsLocalization.AtPrime.ringKrullDim_eq_height q (Localization.AtPrime q)) + have htotal := prime_height_add_quotient_dim_eq_of_finiteType (K := K) q + rw [torus_chart_ringKrullDim, ← hheight] at htotal + obtain ⟨d, hquot, _⟩ := WeightedTorusJets.finiteType_dimension_trdeg + (K := K) (A := T ⧸ q) + change Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) = + n - ((ringKrullDim (T ⧸ q)).unbotD 0).toNat + have hsum : Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) + d = n := by + rw [show ringKrullDim (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)) ⧸ q) = + (d : WithBot ℕ∞) from hquot] at htotal + exact_mod_cast htotal + simpa [hquot] using Nat.eq_sub_of_add_eq hsum + +end WeightedTorusJets.Geometry + +end SamePrimeDimensionPrerequisites + +section + +namespace WeightedTorusJets.Geometry + +noncomputable def localizationResidueAlgEquiv {R A : Type*} [CommRing R] + [CommRing A] [IsLocalRing A] [Algebra R A] + (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime A p] : + p.ResidueField ≃ₐ[R] IsLocalRing.ResidueField A := + IsLocalRing.ResidueField.mapAlgEquiv + (IsLocalization.algEquiv p.primeCompl (Localization.AtPrime p) A) + +theorem localization_residue_algEquiv_algebraMap {R A : Type*} [CommRing R] + [CommRing A] [IsLocalRing A] [Algebra R A] + (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime A p] (x : R) : + localizationResidueAlgEquiv (A := A) p (algebraMap R p.ResidueField x) = + algebraMap R (IsLocalRing.ResidueField A) x := + (localizationResidueAlgEquiv (A := A) p).commutes x + +theorem localization_residue_isFractionRing {R A : Type*} [CommRing R] + [CommRing A] [IsLocalRing A] [Algebra R A] + (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime A p] + [Algebra (R ⧸ p) (IsLocalRing.ResidueField A)] + [IsScalarTower R (R ⧸ p) (IsLocalRing.ResidueField A)] : + IsFractionRing (R ⧸ p) (IsLocalRing.ResidueField A) := + IsFractionRing.of_algEquiv + ((localizationResidueAlgEquiv (A := A) p).extendScalarsOfSurjective + (S := R ⧸ p) Ideal.Quotient.mk_surjective) + +@[instance_reducible] +noncomputable def localizationResidueQuotientAlgebra {R A : Type*} [CommRing R] + [CommRing A] [IsLocalRing A] [Algebra R A] + (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime A p] : + Algebra (R ⧸ p) (IsLocalRing.ResidueField A) := + ((localizationResidueAlgEquiv (A := A) p).toRingHom.comp + (algebraMap (R ⧸ p) p.ResidueField)).toAlgebra + +theorem localization_residue_quotientAlgebra_data {R A : Type*} [CommRing R] + [CommRing A] [IsLocalRing A] [Algebra R A] + (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime A p] : + let : Algebra (R ⧸ p) (IsLocalRing.ResidueField A) := + localizationResidueQuotientAlgebra (A := A) p + IsScalarTower R (R ⧸ p) (IsLocalRing.ResidueField A) ∧ + IsFractionRing (R ⧸ p) (IsLocalRing.ResidueField A) := by + let : Algebra (R ⧸ p) (IsLocalRing.ResidueField A) := + localizationResidueQuotientAlgebra (A := A) p + have h : IsScalarTower R (R ⧸ p) (IsLocalRing.ResidueField A) := + IsScalarTower.of_algebraMap_eq fun x => + (localization_residue_algEquiv_algebraMap (A := A) p x).symm + exact ⟨h, localization_residue_isFractionRing p⟩ + +theorem localization_residue_quotientAlgebra_mk {R A : Type*} [CommRing R] + [CommRing A] [IsLocalRing A] [Algebra R A] + (p : Ideal R) [p.IsPrime] [IsLocalization.AtPrime A p] (x : R) : + let : Algebra (R ⧸ p) (IsLocalRing.ResidueField A) := + localizationResidueQuotientAlgebra (A := A) p + algebraMap (R ⧸ p) (IsLocalRing.ResidueField A) (Ideal.Quotient.mk p x) = + algebraMap R (IsLocalRing.ResidueField A) x := + localization_residue_algEquiv_algebraMap (A := A) p x + +end WeightedTorusJets.Geometry + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialLinearCoefficients.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialLinearCoefficients.lean new file mode 100644 index 0000000000000000000000000000000000000000..69cadb3f5e7a99221cf707b781b509c5e8c447b5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/PolynomialLinearCoefficients.lean @@ -0,0 +1,523 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.DerivationJet + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +noncomputable section +noncomputable section +namespace WeightedTorusJets.Geometry +open MvPolynomial +theorem mem_vars_square_iff {σ K : Type*} [CommRing K] (p : MvPolynomial σ K) : + p ∈ idealOfVars σ K ^ 2 ↔ p.coeff 0 = 0 ∧ ∀ i, p.coeff (Finsupp.single i 1) = 0 := by + rw [mem_pow_idealOfVars_iff'] + constructor + · intro h + exact ⟨h 0 (by simp), fun i => h (Finsupp.single i 1) (by simp)⟩ + · rintro ⟨h₀, h₁⟩ d hd + have h : d.degree = 0 ∨ d.degree = 1 := by omega + rcases h with h | h + · exact (Finsupp.degree_eq_zero_iff d).mp h ▸ h₀ + · obtain ⟨i, rfl⟩ := (Finsupp.range_single_one (σ := σ) ▸ h : + d ∈ Set.range (fun i : σ => Finsupp.single i 1)) + exact h₁ i + +def polynomialLinearCoefficients {σ K : Type*} [CommRing K] : + MvPolynomial σ K →ₗ[K] (σ → K) := + LinearMap.pi fun i => lcoeff K (Finsupp.single i 1) + +@[simp] theorem polynomialLinearCoefficients_apply {σ K : Type*} [CommRing K] + (p : MvPolynomial σ K) (i : σ) : + polynomialLinearCoefficients p i = p.coeff (Finsupp.single i 1) := rfl + +def varsCotangentCoefficients {σ K : Type*} [CommRing K] : + (idealOfVars σ K).Cotangent →ₗ[K] (σ → K) := + Ideal.Cotangent.lift + (polynomialLinearCoefficients.comp ((idealOfVars σ K).subtype.restrictScalars K)) + fun x y => by + ext i + exact (mem_vars_square_iff (x * y)).mp + (by rw [pow_two]; exact Ideal.mul_mem_mul x.property y.property) |>.2 i + +@[simp] theorem varsCotangentCoefficients_toCotangent {σ K : Type*} [CommRing K] + (p : idealOfVars σ K) (i : σ) : + varsCotangentCoefficients ((idealOfVars σ K).toCotangent p) i = + (p : MvPolynomial σ K).coeff (Finsupp.single i 1) := rfl + +theorem varsCotangentCoefficients_injective {σ K : Type*} [CommRing K] : + Function.Injective (varsCotangentCoefficients (σ := σ) (K := K)) := by + rw [injective_iff_map_eq_zero] + intro x hx + obtain ⟨p, rfl⟩ := (idealOfVars σ K).toCotangent_surjective x + apply ((idealOfVars σ K).toCotangent_eq_zero p).mpr + rw [mem_vars_square_iff] + refine ⟨?_, fun i => congrFun hx i⟩ + exact (mem_pow_idealOfVars_iff' 1 (p : MvPolynomial σ K)).mp + (by simpa only [pow_one] using p.property) 0 (by simp) + +theorem varsCotangentCoefficients_surjective + {σ K : Type*} [Fintype σ] [CommRing K] : + Function.Surjective (varsCotangentCoefficients (σ := σ) (K := K)) := by + classical + intro v + let p : MvPolynomial σ K := ∑ i, v i • X i + have hp : p ∈ idealOfVars σ K := by + apply Ideal.sum_mem + intro i _ + exact ((idealOfVars σ K).restrictScalars K).smul_mem (v i) + (Ideal.subset_span ⟨i, rfl⟩) + refine ⟨(idealOfVars σ K).toCotangent ⟨p, hp⟩, ?_⟩ + ext i + simp [p, coeff_X, Finsupp.single_left_inj] + +def varsCotangentEquiv {σ K : Type*} [Fintype σ] [CommRing K] : + (idealOfVars σ K).Cotangent ≃ₗ[K] (σ → K) := + LinearEquiv.ofBijective varsCotangentCoefficients + ⟨varsCotangentCoefficients_injective, varsCotangentCoefficients_surjective⟩ + +def quotientVarsCotangentMap {σ K : Type*} [CommRing K] + (J : Ideal (MvPolynomial σ K)) : + (idealOfVars σ K).Cotangent →ₗ[K] + ((idealOfVars σ K).map (Ideal.Quotient.mk J)).Cotangent := + Ideal.mapCotangent _ _ (Ideal.Quotient.mkₐ K J) + (fun _ hp => Ideal.mem_map_of_mem (Ideal.Quotient.mk J) hp) + +theorem quotientVarsCotangentMap_surjective {σ K : Type*} [CommRing K] + (J : Ideal (MvPolynomial σ K)) : + Function.Surjective (quotientVarsCotangentMap J) := by + intro x + obtain ⟨b, rfl⟩ := ((idealOfVars σ K).map (Ideal.Quotient.mk J)).toCotangent_surjective x + obtain ⟨p, hp, hpb⟩ := (Ideal.mem_map_iff_of_surjective (Ideal.Quotient.mk J) + Ideal.Quotient.mk_surjective).mp b.property + refine ⟨(idealOfVars σ K).toCotangent ⟨p, hp⟩, ?_⟩ + change ((idealOfVars σ K).map (Ideal.Quotient.mk J)).toCotangent + ⟨Ideal.Quotient.mk J p, _⟩ = _ + congr 1 + exact Subtype.ext hpb + +theorem quotientVarsCotangentMap_injective {σ K : Type*} [CommRing K] + (J : Ideal (MvPolynomial σ K)) (hJ : J ≤ idealOfVars σ K ^ 2) : + Function.Injective (quotientVarsCotangentMap J) := by + rw [injective_iff_map_eq_zero] + intro x hx + obtain ⟨p, rfl⟩ := (idealOfVars σ K).toCotangent_surjective x + change ((idealOfVars σ K).map (Ideal.Quotient.mk J)).toCotangent + ⟨Ideal.Quotient.mk J p, _⟩ = 0 at hx + have hp₂ := (((idealOfVars σ K).map (Ideal.Quotient.mk J)).toCotangent_eq_zero _).mp hx + rw [← Ideal.map_pow] at hp₂ + obtain ⟨q, hq, hqp⟩ := (Ideal.mem_map_iff_of_surjective (Ideal.Quotient.mk J) + Ideal.Quotient.mk_surjective).mp hp₂ + have hd : q - p ∈ J := (Ideal.Quotient.mk_eq_mk_iff_sub_mem _ _).mp hqp + apply ((idealOfVars σ K).toCotangent_eq_zero p).mpr + simpa using (idealOfVars σ K ^ 2).sub_mem hq (hJ hd) + +def polynomialQuotientCotangentEquiv {σ K : Type*} [Fintype σ] [CommRing K] + (J : Ideal (MvPolynomial σ K)) (hJ : J ≤ idealOfVars σ K ^ 2) : + ((idealOfVars σ K).map (Ideal.Quotient.mk J)).Cotangent ≃ₗ[K] (σ → K) := + (LinearEquiv.ofBijective (quotientVarsCotangentMap J) + ⟨quotientVarsCotangentMap_injective J hJ, quotientVarsCotangentMap_surjective J⟩).symm.trans + varsCotangentEquiv + +@[simp] theorem polynomialQuotientCotangentEquiv_map_toCotangent + {σ K : Type*} [Fintype σ] [CommRing K] + (J : Ideal (MvPolynomial σ K)) (hJ : J ≤ idealOfVars σ K ^ 2) + (p : idealOfVars σ K) (i : σ) : + polynomialQuotientCotangentEquiv J hJ + (quotientVarsCotangentMap J ((idealOfVars σ K).toCotangent p)) i = + (p : MvPolynomial σ K).coeff (Finsupp.single i 1) := by + let e := LinearEquiv.ofBijective (quotientVarsCotangentMap J) + ⟨quotientVarsCotangentMap_injective J hJ, quotientVarsCotangentMap_surjective J⟩ + change varsCotangentEquiv (e.symm (e ((idealOfVars σ K).toCotangent p))) i = _ + rw [LinearEquiv.symm_apply_apply] + rfl + +theorem rectangularIdeal_le_vars_square {σ K : Type*} [CommRing K] + (k : σ → ℕ) (hk : ∀ i, 2 ≤ k i) : + Ideal.span (Set.range fun i => (X i : MvPolynomial σ K) ^ k i) ≤ idealOfVars σ K ^ 2 := by + rw [Ideal.span_le, Set.range_subset_iff] + intro i + have hi : (X i : MvPolynomial σ K) ∈ idealOfVars σ K := Ideal.subset_span ⟨i, rfl⟩ + exact Ideal.pow_le_pow_right (hk i) (Ideal.pow_mem_pow hi (k i)) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +open MvPolynomial + +noncomputable def cotangentEquivOfEqOver (R : Type*) {A : Type*} + [CommRing R] [CommRing A] [Algebra R A] (I J : Ideal A) (h : I = J) : + I.Cotangent ≃ₗ[R] J.Cotangent := by + subst J + exact LinearEquiv.refl R _ + +@[simp] theorem cotangentEquivOfEqOver_toCotangent (R : Type*) {A : Type*} + [CommRing R] [CommRing A] [Algebra R A] (I J : Ideal A) (h : I = J) (p : I) : + cotangentEquivOfEqOver R I J h (I.toCotangent p) = + J.toCotangent ⟨p, h ▸ p.property⟩ := by + subst J + rfl + +noncomputable def rectangularAugmentationCotangentEquiv + {σ K : Type*} [Fintype σ] [CommRing K] + (k : σ → ℕ) (hk : ∀ i, 2 ≤ k i) : + (RingHom.ker (rectangularAugmentation (K := K) k + (fun i => by have := hk i; omega)).toRingHom).Cotangent ≃ₗ[K] (σ → K) := + (cotangentEquivOfEqOver K _ _ (ker_quotientAugmentation _ _)).trans + (polynomialQuotientCotangentEquiv _ (rectangularIdeal_le_vars_square k hk)) + +theorem rectangularAugmentationCotangentEquiv_toCotangent_mk + {σ K : Type*} [Fintype σ] [CommRing K] + (k : σ → ℕ) (hk : ∀ i, 2 ≤ k i) (p : idealOfVars σ K) (i : σ) : + rectangularAugmentationCotangentEquiv k hk + ((RingHom.ker (rectangularAugmentation (K := K) k + (fun j => by have := hk j; omega)).toRingHom).toCotangent + ⟨Ideal.Quotient.mk _ p, by + change quotientAugmentation (K := K) _ _ + (Ideal.Quotient.mk _ (p : MvPolynomial σ K)) = 0 + rw [quotientAugmentation_mk] + exact (congrArg (fun J : Ideal (MvPolynomial σ K) => + (p : MvPolynomial σ K) ∈ J) ker_constantCoeff_eq_idealOfVars).mpr p.property⟩) i = + (p : MvPolynomial σ K).coeff (Finsupp.single i 1) := by + let J : Ideal (MvPolynomial σ K) := Ideal.span (Set.range fun j => X j ^ k j) + let h₀ : J ≤ RingHom.ker (constantCoeff : MvPolynomial σ K →+* K) := + rectangularIdeal_le_ker_constantCoeff k (fun j => by have := hk j; omega) + let n : Ideal (MvPolynomial σ K ⧸ J) := RingHom.ker (quotientAugmentation J h₀).toRingHom + have hp₀ : constantCoeff (p : MvPolynomial σ K) = 0 := + (congrArg (fun I : Ideal (MvPolynomial σ K) => + (p : MvPolynomial σ K) ∈ I) ker_constantCoeff_eq_idealOfVars).mpr p.property + have hqp : Ideal.Quotient.mk J (p : MvPolynomial σ K) ∈ n := by + change quotientAugmentation J h₀ (Ideal.Quotient.mk J p) = 0 + simpa only [quotientAugmentation_mk] using hp₀ + change polynomialQuotientCotangentEquiv J (rectangularIdeal_le_vars_square k hk) + (cotangentEquivOfEqOver K n _ (ker_quotientAugmentation J h₀) + (n.toCotangent ⟨Ideal.Quotient.mk J p, hqp⟩)) i = _ + rw [cotangentEquivOfEqOver_toCotangent] + exact polynomialQuotientCotangentEquiv_map_toCotangent J _ p i + +theorem rectangularAugmentation_linear_representative + {σ K : Type*} [Fintype σ] [CommRing K] + (k : σ → ℕ) (hk : ∀ i, 2 ≤ k i) + (b : RingHom.ker (rectangularAugmentation (K := K) k + (fun j => by have := hk j; omega)).toRingHom) : + (b : MvPolynomial σ K ⧸ Ideal.span (Set.range fun j => (X j : MvPolynomial σ K) ^ k j)) - + ∑ i, (rectangularAugmentationCotangentEquiv k hk + ((RingHom.ker (rectangularAugmentation (K := K) k + (fun j => by have := hk j; omega)).toRingHom).toCotangent b)) i • + Ideal.Quotient.mk _ (X i) ∈ + (RingHom.ker (rectangularAugmentation (K := K) k + (fun j => by have := hk j; omega)).toRingHom) ^ 2 := by + classical + let J : Ideal (MvPolynomial σ K) := Ideal.span (Set.range fun j => X j ^ k j) + let N : Ideal (MvPolynomial σ K ⧸ J) := RingHom.ker + (rectangularAugmentation (K := K) k (fun j => by have := hk j; omega)).toRingHom + let e := rectangularAugmentationCotangentEquiv (K := K) k hk + let c : σ → K := e (N.toCotangent b) + let p : MvPolynomial σ K := ∑ i, c i • X i + have hp : p ∈ idealOfVars σ K := by + apply Ideal.sum_mem + intro i _ + exact ((idealOfVars σ K).restrictScalars K).smul_mem (c i) + (Ideal.subset_span ⟨i, rfl⟩) + have hpn : Ideal.Quotient.mk J p ∈ N := by + change quotientAugmentation (K := K) _ _ (Ideal.Quotient.mk J p) = 0 + rw [quotientAugmentation_mk] + exact (congrArg (fun I : Ideal (MvPolynomial σ K) => p ∈ I) + ker_constantCoeff_eq_idealOfVars).mpr hp + have hc : e (N.toCotangent ⟨Ideal.Quotient.mk J p, hpn⟩) = c := by + ext i + exact (rectangularAugmentationCotangentEquiv_toCotangent_mk k hk ⟨p, hp⟩ i).trans + (by simp [p, coeff_X, Finsupp.single_left_inj]) + have hq : Ideal.Quotient.mk J p = ∑ i, c i • Ideal.Quotient.mk J (X i) := by + change (Ideal.Quotient.mkₐ K J) p = _ + simp only [p, map_sum, map_smul, Ideal.Quotient.mkₐ_eq_mk] + have hdiff := N.toCotangent_eq.mp (e.injective hc.symm) + simpa only [hq] using hdiff + + + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +theorem taylor_sum_sub_first_order_mem {A : Type*} [CommRing A] [Algebra ℚ A] + (D : Derivation ℚ A A) (I : Ideal A) {u : A} (hu : u ∈ I) + {n : ℕ} (hn : 2 ≤ n) (a : A) : + (∑ i ∈ Finset.range n, (i.factorial : ℚ)⁻¹ • (u ^ i * (D.toLinearMap ^ i) a)) - + (a + u * D a) ∈ I ^ 2 := by + induction n, hn using Nat.le_induction with + | base => simp [Finset.sum_range_succ] + | succ n hn ih => + have hu' : u ^ n ∈ I ^ 2 := Ideal.pow_le_pow_right hn (Ideal.pow_mem_pow hu n) + have hterm : (n.factorial : ℚ)⁻¹ • (u ^ n * (D.toLinearMap ^ n) a) ∈ I ^ 2 := by + rw [Algebra.smul_def] + exact (I ^ 2).mul_mem_left _ ((I ^ 2).mul_mem_right _ hu') + rw [Finset.sum_range_succ] + convert (I ^ 2).add_mem ih hterm using 1 + ring + +theorem ringHom_comp_sub_first_order_mem {A : Type*} [CommRing A] + (I : Ideal A) (f g : A →+* A) + (hf : ∀ x ∈ I, f x - x ∈ I ^ 2) {a : A} (hg : g a - a ∈ I) : + f (g a) - (f a + g a - a) ∈ I ^ 2 := by + have h := hf (g a - a) hg + rw [map_sub] at h + convert h using 1 + ring + + + +variable {A : Type*} [CommRing A] [Algebra ℚ A] + +theorem truncatedTaylor_sub_first_order_mem (D : Derivation ℚ A A) (I : Ideal A) + (u : A) (hDu : D u = 0) {n : ℕ} (hun : u ^ n = 0) (hn : 2 ≤ n) + (hu : u ∈ I) (a : A) : + truncatedTaylor D u hDu hun a - (a + u * D a) ∈ I ^ 2 := by + rw [truncatedTaylor_apply] + exact taylor_sum_sub_first_order_mem D I hu hn a + +theorem truncatedTaylor_sub_self_mem (D : Derivation ℚ A A) (I : Ideal A) + (u : A) (hDu : D u = 0) {n : ℕ} (hun : u ^ n = 0) (hn : 2 ≤ n) + (hu : u ∈ I) (a : A) : + truncatedTaylor D u hDu hun a - a ∈ I := by + have h := (Ideal.pow_le_self (by decide : 2 ≠ 0)) + (truncatedTaylor_sub_first_order_mem D I u hDu hun hn hu a) + convert I.add_mem h (I.mul_mem_right (D a) hu) using 1 + ring + +theorem truncatedTaylor_sub_self_mem_sq (D : Derivation ℚ A A) (I : Ideal A) + (u : A) (hDu : D u = 0) {n : ℕ} (hun : u ^ n = 0) (hn : 2 ≤ n) + (hu : u ∈ I) (hDI : ∀ a ∈ I, D a ∈ I) {a : A} (ha : a ∈ I) : + truncatedTaylor D u hDu hun a - a ∈ I ^ 2 := by + have h := truncatedTaylor_sub_first_order_mem D I u hDu hun hn hu a + have hc : u * D a ∈ I ^ 2 := by + rw [pow_two] + exact Ideal.mul_mem_mul hu (hDI a ha) + convert (I ^ 2).add_mem h hc using 1 + ring + +omit [Algebra ℚ A] in + +theorem ringHom_comp3_sub_first_order_mem (I : Ideal A) (f₁ f₂ f₃ : A →+* A) + (hf₁ : ∀ x ∈ I, f₁ x - x ∈ I ^ 2) + (hf₂ : ∀ x ∈ I, f₂ x - x ∈ I ^ 2) + (hg₂ : ∀ x, f₂ x - x ∈ I) + {a e₁ e₂ e₃ : A} (hg₃ : f₃ a - a ∈ I) + (h₁ : f₁ a - (a + e₁) ∈ I ^ 2) + (h₂ : f₂ a - (a + e₂) ∈ I ^ 2) + (h₃ : f₃ a - (a + e₃) ∈ I ^ 2) : + f₁ (f₂ (f₃ a)) - (a + e₁ + e₂ + e₃) ∈ I ^ 2 := by + have h23 : f₂ (f₃ a) - a ∈ I := by + convert I.add_mem (hg₂ (f₃ a)) hg₃ using 1 + ring + have hc₁ := ringHom_comp_sub_first_order_mem I f₁ (f₂.comp f₃) hf₁ h23 + have hc₂ := ringHom_comp_sub_first_order_mem I f₂ f₃ hf₂ hg₃ + have h := (I ^ 2).add_mem ((I ^ 2).add_mem ((I ^ 2).add_mem + ((I ^ 2).add_mem hc₁ hc₂) h₁) h₂) h₃ + convert h using 1 + simp only [RingHom.comp_apply] + ring + +theorem rectangularCoefficientDerivation_mem_vars (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) {p : MvPolynomial σ A ⧸ rectangularIdeal k} + (hp : p ∈ (MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k))) : + rectangularCoefficientDerivation σ k D p ∈ + (MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k)) := by + have he : (MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k)) = + Ideal.span (Set.range fun i => Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.X i : MvPolynomial σ A)) := by + rw [MvPolynomial.idealOfVars, Ideal.map_span, ← Set.range_comp] + rfl + rw [he] at hp ⊢ + apply derivation_mem_span_of_vanishes _ _ _ hp + rintro _ ⟨i, rfl⟩ + exact rectangularCoefficientDerivation_X σ k D i + +theorem rectangularTaylorAlong_sub_first_order_mem (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (i : σ) (hk : 2 ≤ k i) + (p : MvPolynomial σ A ⧸ rectangularIdeal k) : + rectangularTaylorAlong σ k D i p - + (p + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i) * + rectangularCoefficientDerivation σ k D p) ∈ + ((MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k))) ^ 2 := by + apply truncatedTaylor_sub_first_order_mem _ _ _ _ _ hk + exact Ideal.mem_map_of_mem _ (Ideal.subset_span ⟨i, rfl⟩) + +theorem rectangularTaylorAlong_sub_self_mem (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (i : σ) (hk : 2 ≤ k i) + (p : MvPolynomial σ A ⧸ rectangularIdeal k) : + rectangularTaylorAlong σ k D i p - p ∈ + (MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k)) := by + apply truncatedTaylor_sub_self_mem _ _ _ _ _ hk + exact Ideal.mem_map_of_mem _ (Ideal.subset_span ⟨i, rfl⟩) + +theorem rectangularTaylorAlong_sub_self_mem_sq (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (i : σ) (hk : 2 ≤ k i) + {p : MvPolynomial σ A ⧸ rectangularIdeal k} + (hp : p ∈ (MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k))) : + rectangularTaylorAlong σ k D i p - p ∈ + ((MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k))) ^ 2 := by + apply truncatedTaylor_sub_self_mem_sq _ _ _ _ _ hk _ _ hp + · exact Ideal.mem_map_of_mem _ (Ideal.subset_span ⟨i, rfl⟩) + · exact fun _ => rectangularCoefficientDerivation_mem_vars σ k D + +theorem rectangularTaylorComp3_sub_first_order_mem (σ : Type*) (k : σ → ℕ) + (D₁ D₂ D₃ : Derivation ℚ A A) (i₁ i₂ i₃ : σ) + (hk₁ : 2 ≤ k i₁) (hk₂ : 2 ≤ k i₂) (hk₃ : 2 ≤ k i₃) + (p : MvPolynomial σ A ⧸ rectangularIdeal k) : + rectangularTaylorAlong σ k D₁ i₁ + (rectangularTaylorAlong σ k D₂ i₂ (rectangularTaylorAlong σ k D₃ i₃ p)) - + (p + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i₁) * + rectangularCoefficientDerivation σ k D₁ p + + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i₂) * + rectangularCoefficientDerivation σ k D₂ p + + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i₃) * + rectangularCoefficientDerivation σ k D₃ p) ∈ + ((MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k))) ^ 2 := by + apply ringHom_comp3_sub_first_order_mem _ + (rectangularTaylorAlong σ k D₁ i₁).toRingHom + (rectangularTaylorAlong σ k D₂ i₂).toRingHom + (rectangularTaylorAlong σ k D₃ i₃).toRingHom + · exact fun _ => rectangularTaylorAlong_sub_self_mem_sq σ k D₁ i₁ hk₁ + · exact fun _ => rectangularTaylorAlong_sub_self_mem_sq σ k D₂ i₂ hk₂ + · exact rectangularTaylorAlong_sub_self_mem σ k D₂ i₂ hk₂ + · exact rectangularTaylorAlong_sub_self_mem σ k D₃ i₃ hk₃ p + · exact rectangularTaylorAlong_sub_first_order_mem σ k D₁ i₁ hk₁ p + · exact rectangularTaylorAlong_sub_first_order_mem σ k D₂ i₂ hk₂ p + · exact rectangularTaylorAlong_sub_first_order_mem σ k D₃ i₃ hk₃ p + +omit [Algebra ℚ A] in + +theorem rectangularMap_vars_le {B : Type*} [CommRing B] (σ : Type*) (k : σ → ℕ) + (f : A →+* B) : + ((MvPolynomial.idealOfVars σ A).map (Ideal.Quotient.mk (rectangularIdeal k))).map + (rectangularMap k f) ≤ + (MvPolynomial.idealOfVars σ B).map (Ideal.Quotient.mk (rectangularIdeal k)) := by + rw [Ideal.map_map, MvPolynomial.idealOfVars, Ideal.map_span] + apply Ideal.span_le.mpr + rintro _ ⟨p, ⟨i, rfl⟩, rfl⟩ + change rectangularMap k f (Ideal.Quotient.mk _ (MvPolynomial.X i)) ∈ _ + rw [rectangularMap_mk, MvPolynomial.map_X] + exact Ideal.mem_map_of_mem _ (Ideal.subset_span ⟨i, rfl⟩) + +theorem rectangularTaylorThree_sub_first_order_mem {B : Type*} [CommRing B] + (σ : Type*) (k : σ → ℕ) (D₁ D₂ D₃ : Derivation ℚ A A) + (i₁ i₂ i₃ : σ) (hk₁ : 2 ≤ k i₁) (hk₂ : 2 ≤ k i₂) (hk₃ : 2 ≤ k i₃) + (f : A →+* B) (a : A) : + rectangularTaylorThree σ k D₁ D₂ D₃ i₁ i₂ i₃ f a - + (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.C (f a)) + + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i₁) * + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.C (f (D₁ a))) + + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i₂) * + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.C (f (D₂ a))) + + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i₃) * + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.C (f (D₃ a)))) ∈ + ((MvPolynomial.idealOfVars σ B).map (Ideal.Quotient.mk (rectangularIdeal k))) ^ 2 := by + have h := rectangularTaylorComp3_sub_first_order_mem σ k D₁ D₂ D₃ i₁ i₂ i₃ + hk₁ hk₂ hk₃ (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.C a)) + have hm := Ideal.mem_map_of_mem (rectangularMap k f) h + rw [Ideal.map_pow] at hm + have ht := pow_le_pow_left' (rectangularMap_vars_le σ k f) 2 hm + simpa only [map_sub, map_add, map_mul, rectangularCoefficientDerivation_mk, + coefficientDerivation_C, rectangularMap_mk, MvPolynomial.map_C, + MvPolynomial.map_X, rectangularTaylorThree, RingHom.comp_apply, + AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom] using ht + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {R B σ : Type*} [CommRing R] [Algebra ℚ R] [CommRing B] [Fintype σ] + +omit [Fintype σ] in +theorem quotient_X_mul_C (J : Ideal (MvPolynomial σ B)) (i : σ) (a : B) : + Ideal.Quotient.mk J (MvPolynomial.X i) * Ideal.Quotient.mk J (MvPolynomial.C a) = + a • Ideal.Quotient.mk J (MvPolynomial.X i) := by + rw [← map_mul, mul_comm, MvPolynomial.C_mul'] + exact (Ideal.Quotient.mkₐ B J).toLinearMap.map_smul a (MvPolynomial.X i) + +omit [Fintype σ] in +theorem rectangular_augmentation_ker_eq (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) : + (RingHom.ker (rectangularAugmentation (K := B) k hk).toRingHom : + Ideal (MvPolynomial σ B ⧸ rectangularIdeal k)) = + (MvPolynomial.idealOfVars σ B).map (Ideal.Quotient.mk (rectangularIdeal k)) := by + exact ker_quotientAugmentation (rectangularIdeal k) (rectangularIdeal_le_ker_constantCoeff k hk) + +theorem rectangularTaylorThree_one_first_order (k : σ → ℕ) (hk : ∀ j, 2 ≤ k j) + (D : σ → Derivation ℚ R R) (i : σ) (hi : ∀ j, j = i) + (f : R →+* B) (a : R) (ha : f a = 0) : + rectangularTaylorThree σ k (D i) 0 0 i i i f a - + ∑ j, f (D j a) • Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X j) ∈ + (RingHom.ker (rectangularAugmentation (K := B) k + (fun j => by have := hk j; omega)).toRingHom : + Ideal (MvPolynomial σ B ⧸ rectangularIdeal k)) ^ 2 := by + classical + have h := rectangularTaylorThree_sub_first_order_mem σ k (D i) 0 0 i i i + (hk i) (hk i) (hk i) f a + have hs : (∑ j, f (D j a) • Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.X j : MvPolynomial σ B)) = + f (D i a) • Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i) := by + apply Finset.sum_eq_single i + · intro j hj hji + exact False.elim (hji (hi j)) + · simp + rw [hs] + rw [rectangular_augmentation_ker_eq] + simpa [ha, quotient_X_mul_C] using h + +theorem rectangularTaylorThree_two_first_order (k : σ → ℕ) (hk : ∀ l, 2 ≤ k l) + (D : σ → Derivation ℚ R R) (i j : σ) (hij : i ≠ j) + (hijcover : ∀ l, l = i ∨ l = j) (f : R →+* B) (a : R) (ha : f a = 0) : + rectangularTaylorThree σ k (D i) (D j) 0 i j j f a - + ∑ l, f (D l a) • Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X l) ∈ + (RingHom.ker (rectangularAugmentation (K := B) k + (fun l => by have := hk l; omega)).toRingHom : + Ideal (MvPolynomial σ B ⧸ rectangularIdeal k)) ^ 2 := by + classical + have h := rectangularTaylorThree_sub_first_order_mem σ k (D i) (D j) 0 i j j + (hk i) (hk j) (hk j) f a + have hu : (Finset.univ : Finset σ) = {i, j} := by + ext l + simpa using hijcover l + rw [hu, Finset.sum_pair hij] + rw [rectangular_augmentation_ker_eq] + simpa [ha, quotient_X_mul_C] using h + +theorem rectangularTaylorThree_three_first_order (k : σ → ℕ) (hk : ∀ l, 2 ≤ k l) + (D : σ → Derivation ℚ R R) (i j l : σ) (hij : i ≠ j) (hil : i ≠ l) (hjl : j ≠ l) + (hcover : ∀ u, u = i ∨ u = j ∨ u = l) (f : R →+* B) (a : R) (ha : f a = 0) : + rectangularTaylorThree σ k (D i) (D j) (D l) i j l f a - + ∑ u, f (D u a) • Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X u) ∈ + (RingHom.ker (rectangularAugmentation (K := B) k + (fun u => by have := hk u; omega)).toRingHom : + Ideal (MvPolynomial σ B ⧸ rectangularIdeal k)) ^ 2 := by + classical + have h := rectangularTaylorThree_sub_first_order_mem σ k (D i) (D j) (D l) i j l + (hk i) (hk j) (hk l) f a + have hu : (Finset.univ : Finset σ) = {i, j, l} := by + ext u + simpa using hcover u + rw [hu] + simp only [Finset.sum_insert, Finset.mem_insert, Finset.mem_singleton, hij, hil, hjl, + or_self, not_false_eq_true, Finset.sum_singleton] + rw [rectangular_augmentation_ker_eq] + simpa [ha, quotient_X_mul_C, add_assoc] using h + +end WeightedTorusJets.Geometry + +end +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticAdjoinBasis.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticAdjoinBasis.lean new file mode 100644 index 0000000000000000000000000000000000000000..e017c64c3700f08fddd7234ea6f45a6c1f5ff2ee --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticAdjoinBasis.lean @@ -0,0 +1,503 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.IntegerCharacter +import OAI.NumberTheory.Jacobsthal.Siegel.SqrtPairFrobeniusDirections + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +namespace WeightedTorusJets + +open Module NumberField + +theorem trace_norm_quadratic_basis {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d r s : ℚ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) : + Algebra.trace ℚ K ((r : K) + s * a) = 2 * r ∧ + Algebra.norm ℚ ((r : K) + s * a) = r ^ 2 - d * s ^ 2 := by + have hu0 : u 0 = 1 := congrFun hu 0 + have hu1 : u 1 = a := congrFun hu 1 + have hr0 : u.repr 1 = Finsupp.single 0 1 := by rw [← hu0, u.repr_self] + have hr1 : u.repr a = Finsupp.single 1 1 := by rw [← hu1, u.repr_self] + have hrc (c : ℚ) : u.repr (c : K) = c • Finsupp.single 0 1 := by + simpa [Algebra.smul_def, hr0] using u.repr.map_smul c (1 : K) + have hm0 : ((r : K) + s * a) * 1 = r • (1 : K) + s • a := by + simp [Algebra.smul_def] + have hm1 : ((r : K) + s * a) * a = (d * s) • (1 : K) + r • a := by + calc + _ = (s : K) * a ^ 2 + r * a := by ring + _ = _ := by rw [ha]; simp [Algebra.smul_def, mul_comm] + have hmat : Algebra.leftMulMatrix u ((r : K) + s * a) = !![r, d*s; s,r] := by + ext i j + rw [Algebra.leftMulMatrix_eq_repr_mul] + fin_cases i <;> fin_cases j + all_goals simp [-Rat.cast_mul, hu0, hu1, hm0, hm1, hrc, hr1] + rw [Algebra.trace_eq_matrix_trace u, Algebra.norm_eq_matrix_det u, hmat] + simp [Matrix.trace, Matrix.det_fin_two, Fin.sum_univ_succ] + constructor <;> ring + +theorem rat_int_of_squarefree_mul_sq_eq_int (d n : ℤ) (hd : Squarefree d) + (x : ℚ) (hx : (d : ℚ) * x ^ 2 = n) : ∃ m : ℤ, x = m := by + have heq : d * x.num ^ 2 = n * (x.den : ℤ) ^ 2 := by + apply Int.cast_injective (α := ℚ) + push_cast + rw [← x.num_div_den] at hx + have hden : (x.den : ℚ) ≠ 0 := by exact_mod_cast x.den_ne_zero + field_simp at hx + nlinarith [hx] + have hdiv : (x.den : ℤ) * (x.den : ℤ) ∣ d * x.num ^ 2 := by + rw [heq, ← pow_two] + exact dvd_mul_left _ _ + have hden := hd.dvd_of_squarefree_of_mul_dvd_mul_right hdiv + have hden_nat : x.den ∣ x.num.natAbs ^ 2 := by + simpa only [Int.natCast_dvd, Int.natAbs_pow] using hden + have hone : x.den = 1 := Nat.eq_one_of_dvd_coprimes (x.reduced.pow_left 2) + hden_nat (dvd_refl _) + exact ⟨x.num, ((Rat.den_eq_one_iff x).mp hone).symm⟩ + +theorem integral_quadratic_half_coordinates {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d : ℤ) (r s : ℚ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) (hd : Squarefree d) + (hx : IsIntegral ℤ ((r : K) + s * a)) : + ∃ m k : ℤ, 2 * r = m ∧ 2 * s = k ∧ 4 ∣ m ^ 2 - d * k ^ 2 := by + obtain ⟨ht, hn⟩ := trace_norm_quadratic_basis u a (d : ℚ) r s hu (by simpa using ha) + have hit : IsIntegral ℤ (2 * r) := ht ▸ Algebra.isIntegral_trace hx + have hin : IsIntegral ℤ (r ^ 2 - (d : ℚ) * s ^ 2) := hn ▸ Algebra.isIntegral_norm ℚ hx + obtain ⟨m, hm⟩ := IsIntegrallyClosed.isIntegral_iff.mp hit + obtain ⟨n, hn⟩ := IsIntegrallyClosed.isIntegral_iff.mp hin + change (m : ℚ) = 2 * r at hm + change (n : ℚ) = r ^ 2 - (d : ℚ) * s ^ 2 at hn + have hsq : (d : ℚ) * (2 * s) ^ 2 = (m ^ 2 - 4 * n : ℤ) := by + push_cast + rw [hm, hn] + ring + obtain ⟨k, hk⟩ := rat_int_of_squarefree_mul_sq_eq_int d (m ^ 2 - 4 * n) hd (2 * s) hsq + refine ⟨m, k, hm.symm, hk, n, ?_⟩ + apply Int.cast_injective (α := ℚ) + push_cast + rw [hm, ← hk, hn] + ring + +theorem even_coordinates_of_four_dvd (d m k : ℤ) (hd : d % 4 = 2 ∨ d % 4 = 3) + (h : 4 ∣ m ^ 2 - d * k ^ 2) : Even m ∧ Even k := by + have heq : (m ^ 2 - d * k ^ 2) % 4 = 0 := Int.emod_eq_zero_of_dvd h + rw [Int.sub_emod, Int.mul_emod, Int.sq_emod_four, Int.sq_emod_four] at heq + simp only [Int.even_iff] + rcases hd with hd | hd <;> rw [hd] at heq <;> omega + +theorem even_sub_coordinates_of_four_dvd (d m k : ℤ) (hd : d % 4 = 1) + (h : 4 ∣ m ^ 2 - d * k ^ 2) : Even (m - k) := by + have heq : (m ^ 2 - d * k ^ 2) % 4 = 0 := Int.emod_eq_zero_of_dvd h + rw [Int.sub_emod, Int.mul_emod, Int.sq_emod_four, Int.sq_emod_four, hd] at heq + simp only [Int.even_iff] + omega + +theorem integral_quadratic_eq_int_add_int_mul {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d : ℤ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) (hd : Squarefree d) + (hd4 : d % 4 = 2 ∨ d % 4 = 3) (x : K) (hx : IsIntegral ℤ x) : + ∃ i j : ℤ, x = i + j * a := by + let r := u.repr x 0 + let s := u.repr x 1 + have hrep : (r : K) + s * a = x := by + simpa [r, s, hu, Fin.sum_univ_succ, Algebra.smul_def] using u.sum_repr x + obtain ⟨m, k, hm, hk, hmk⟩ := integral_quadratic_half_coordinates u a d r s hu ha hd + (by simpa only [hrep] using hx) + obtain ⟨hm2, hk2⟩ := even_coordinates_of_four_dvd d m k hd4 hmk + obtain ⟨i, hi⟩ := even_iff_two_dvd.mp hm2 + obtain ⟨j, hj⟩ := even_iff_two_dvd.mp hk2 + have hri : r = (i : ℚ) := by + have hi' : (m : ℚ) = 2 * i := by exact_mod_cast hi + linarith + have hsj : s = (j : ℚ) := by + have hj' : (k : ℚ) = 2 * j := by exact_mod_cast hj + linarith + refine ⟨i, j, ?_⟩ + rw [← hrep, hri, hsj] + norm_cast + +theorem integral_quadratic_eq_int_add_int_mul_half {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d : ℤ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) (hd : Squarefree d) + (hd4 : d % 4 = 1) (x : K) (hx : IsIntegral ℤ x) : + ∃ i j : ℤ, x = i + j * ((1 + a) / 2) := by + let r := u.repr x 0 + let s := u.repr x 1 + have hrep : (r : K) + s * a = x := by + simpa [r, s, hu, Fin.sum_univ_succ, Algebra.smul_def] using u.sum_repr x + obtain ⟨m, k, hm, hk, hmk⟩ := integral_quadratic_half_coordinates u a d r s hu ha hd + (by simpa only [hrep] using hx) + obtain ⟨i, hi⟩ := even_iff_two_dvd.mp (even_sub_coordinates_of_four_dvd d m k hd4 hmk) + have hri : r = (i : ℚ) + (k : ℚ) / 2 := by + have hi' : (m : ℚ) - k = 2 * i := by exact_mod_cast hi + linarith + have hsk : s = (k : ℚ) / 2 := by linarith + refine ⟨i, k, ?_⟩ + rw [← hrep, hri, hsk] + push_cast + ring + +theorem integral_quadratic_half_generator {K : Type*} [Field K] [CharZero K] + (a : K) (d : ℤ) (ha : a ^ 2 = d) (hd : d % 4 = 1) : + IsIntegral ℤ ((1 + a) / 2) := by + have hdv : d = 4 * (d / 4) + 1 := by omega + refine ⟨Polynomial.X ^ 2 - (Polynomial.X + Polynomial.C (d / 4)), + Polynomial.monic_X_pow_sub (by rw [Polynomial.degree_X_add_C]; norm_num), ?_⟩ + change Polynomial.aeval ((1 + a) / 2) + (Polynomial.X ^ 2 - (Polynomial.X + Polynomial.C (d / 4))) = 0 + simp only [map_sub, map_pow, Polynomial.aeval_X, map_add, Polynomial.aeval_C] + have hdK : (d : K) = 4 * ((d / 4 : ℤ) : K) + 1 := by exact_mod_cast hdv + field_simp + linear_combination ha + hdK + +theorem exists_ringOfIntegers_pair_basis {K : Type*} [Field K] [NumberField K] + (w : K) (hw : IsIntegral ℤ w) (hdim : Module.finrank ℚ K = 2) + (hspan : ∀ x : K, IsIntegral ℤ x → ∃ m n : ℤ, x = m + n * w) : + ∃ B : Basis (Fin 2) ℤ (𝓞 K), + (fun i => ((B i : 𝓞 K) : K)) = ![1, w] := by + let W : 𝓞 K := ⟨w, hw⟩ + let v : Fin 2 → 𝓞 K := ![1, W] + have hs : ⊤ ≤ Submodule.span ℤ (Set.range v) := by + intro x _ + obtain ⟨m, n, hmn⟩ := hspan x x.property + have hmn' : x = m • (1 : 𝓞 K) + n • W := by + apply RingOfIntegers.ext + change (x : K) = algebraMap (𝓞 K) K (m • (1 : 𝓞 K) + n • W) + rw [map_add, map_zsmul, map_zsmul, map_one] + change (x : K) = m • (1 : K) + n • w + simpa [Algebra.smul_def] using hmn + rw [hmn'] + exact Submodule.add_mem _ + (Submodule.smul_mem _ m (Submodule.subset_span ⟨0, rfl⟩)) + (Submodule.smul_mem _ n (Submodule.subset_span ⟨1, rfl⟩)) + have hc : Fintype.card (Fin 2) = Module.finrank ℤ (𝓞 K) := by + simpa [RingOfIntegers.rank] using hdim.symm + let B : Basis (Fin 2) ℤ (𝓞 K) := basisOfTopLeSpanOfCardEqFinrank v hs hc + refine ⟨B, ?_⟩ + ext i + fin_cases i <;> simp [B, v, W] + rfl + +theorem discr_quadratic_pair {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d r s : ℚ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) : + Algebra.discr ℚ ![1, (r : K) + s * a] = 4 * d * s ^ 2 := by + have ht := (trace_norm_quadratic_basis u a d r s hu ha).1 + have ht1 : Algebra.trace ℚ K 1 = 2 := by + simpa using Algebra.trace_algebraMap_of_basis u (1 : ℚ) + have hww : ((r : K) + s * a) * ((r : K) + s * a) = + ((r ^ 2 + d * s ^ 2 : ℚ) : K) + ((2 * r * s : ℚ) : K) * a := by + push_cast + linear_combination (s : K) ^ 2 * ha + have htww : Algebra.trace ℚ K (((r : K) + s * a) * ((r : K) + s * a)) = + 2 * (r ^ 2 + d * s ^ 2) := by + rw [hww] + exact (trace_norm_quadratic_basis u a d (r ^ 2 + d * s ^ 2) (2 * r * s) hu ha).1 + rw [Algebra.discr_def, Matrix.det_fin_two] + change Algebra.trace ℚ K (1 * 1) * + Algebra.trace ℚ K (((r : K) + s * a) * ((r : K) + s * a)) - + Algebra.trace ℚ K (1 * ((r : K) + s * a)) * + Algebra.trace ℚ K (((r : K) + s * a) * 1) = _ + rw [one_mul, one_mul, mul_one, ht, ht1, htww] + ring + +theorem coe_discr_eq_pair_of_integer_basis {K : Type*} [Field K] [NumberField K] + (B : Basis (Fin 2) ℤ (𝓞 K)) (w : K) + (hB : (fun i => ((B i : 𝓞 K) : K)) = ![1, w]) : + (NumberField.discr K : ℚ) = Algebra.discr ℚ ![1, w] := by + rw [← NumberField.discr_eq_discr K B] + change (algebraMap ℤ ℚ) (Algebra.discr ℤ B) = _ + rw [← Algebra.discr_localizationLocalization ℤ (nonZeroDivisors ℤ) K B] + congr 1 + funext i + rw [Basis.localizationLocalization_apply] + exact congrFun hB i + +theorem numberField_discr_quadratic_eq_four_mul {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d : ℤ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) (hd : Squarefree d) + (hd4 : d % 4 = 2 ∨ d % 4 = 3) : NumberField.discr K = 4 * d := by + have hai : IsIntegral ℤ a := IsIntegral.of_pow (by decide : 0 < 2) + (ha ▸ isIntegral_intCast d) + have hdim : Module.finrank ℚ K = 2 := by simpa using Module.finrank_eq_card_basis u + obtain ⟨B, hB⟩ := exists_ringOfIntegers_pair_basis a hai hdim + (integral_quadratic_eq_int_add_int_mul u a d hu ha hd hd4) + apply Int.cast_injective (α := ℚ) + push_cast + rw [coe_discr_eq_pair_of_integer_basis B a hB] + simpa using discr_quadratic_pair u a (d : ℚ) 0 1 hu (by simpa using ha) + +theorem numberField_discr_quadratic_eq_self {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d : ℤ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) (hd : Squarefree d) + (hd4 : d % 4 = 1) : NumberField.discr K = d := by + have hwi := integral_quadratic_half_generator a d ha hd4 + have hdim : Module.finrank ℚ K = 2 := by simpa using Module.finrank_eq_card_basis u + obtain ⟨B, hB⟩ := exists_ringOfIntegers_pair_basis ((1 + a) / 2) hwi hdim + (integral_quadratic_eq_int_add_int_mul_half u a d hu ha hd hd4) + have hw : (1 + a) / 2 = ((1 / 2 : ℚ) : K) + ((1 / 2 : ℚ) : K) * a := by + push_cast + ring + apply Int.cast_injective (α := ℚ) + rw [coe_discr_eq_pair_of_integer_basis B ((1 + a) / 2) hB, hw, + discr_quadratic_pair u a (d : ℚ) (1 / 2) (1 / 2) hu (by simpa using ha)] + ring + +theorem isFundamentalDiscr_quadratic {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d : ℤ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) (hd : Squarefree d) : + Int.IsFundamentalDiscr (NumberField.discr K) := by + by_cases hd1 : d % 4 = 1 + · rw [numberField_discr_quadratic_eq_self u a d hu ha hd hd1] + exact Int.isFundamentalDiscr_iff_squarefree.mpr (Or.inl ⟨hd1, hd⟩) + · have hd0 : d % 4 ≠ 0 := by + intro h + exact Int.squarefree_iff_prime_sq_not_dvd.mp hd 2 Nat.prime_two + (by simpa using Int.dvd_of_emod_eq_zero h) + have hd4 : d % 4 = 2 ∨ d % 4 = 3 := by omega + rw [numberField_discr_quadratic_eq_four_mul u a d hu ha hd hd4] + exact Int.isFundamentalDiscr_four_mul.mpr ⟨hd, hd4⟩ + +theorem isUnramifiedIn_two_iff_radical_mod_four {K : Type*} [Field K] [NumberField K] + (u : Basis (Fin 2) ℚ K) (a : K) (d : ℤ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) (hd : Squarefree d) : + Algebra.IsUnramifiedIn (𝓞 K) (Ideal.span {(2 : ℤ)}) ↔ d % 4 = 1 := by + rw [← NumberField.not_dvd_discr_iff_isUnramifiedIn K (𝓞 K) + ((Int.prime_iff_natAbs_prime (k := 2)).mpr Nat.prime_two)] + by_cases hd1 : d % 4 = 1 + · rw [numberField_discr_quadratic_eq_self u a d hu ha hd hd1] + have hodd : ¬ (2 : ℤ) ∣ d := by + rw [Int.dvd_iff_emod_eq_zero] + omega + simp [hodd, hd1] + · have hd0 : d % 4 ≠ 0 := by + intro h + exact Int.squarefree_iff_prime_sq_not_dvd.mp hd 2 Nat.prime_two + (by simpa using Int.dvd_of_emod_eq_zero h) + have hd4 : d % 4 = 2 ∨ d % 4 = 3 := by omega + rw [numberField_discr_quadratic_eq_four_mul u a d hu ha hd hd4] + have hdiv : (2 : ℤ) ∣ 4 * d := dvd_mul_of_dvd_left (by norm_num) d + simp [hdiv, hd1] + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem isUnramifiedIn_of_numberField_extension + {K L : Type*} [Field K] [Field L] [NumberField K] [NumberField L] + [Algebra K L] (P : Ideal ℤ) (hunr : Algebra.IsUnramifiedIn (𝓞 L) P) : + Algebra.IsUnramifiedIn (𝓞 K) P := by + intro Q hQ hover + obtain ⟨⟨Q', hQ', hover'⟩⟩ := Ideal.nonempty_primesOver (S := 𝓞 L) Q + have : Q'.LiesOver P := Ideal.LiesOver.trans Q' Q P + have : Algebra.IsUnramifiedAt ℤ Q' := hunr Q' inferInstance inferInstance + exact Algebra.IsUnramifiedAt.of_liesOver ℤ Q Q' + + + +theorem quadratic_radical_mod_four_of_odd_cyclotomic_overfield + (n : ℕ) [NeZero n] (K L : Type*) [Field K] [Field L] + [NumberField K] [NumberField L] [Algebra K L] + [IsCyclotomicExtension {n} ℚ L] + (u : Module.Basis (Fin 2) ℚ K) (a : K) (d : ℤ) + (hu : (u : Fin 2 → K) = ![1, a]) (ha : a ^ 2 = d) + (hd : Squarefree d) (hn : Odd n) : d % 4 = 1 := by + apply (isUnramifiedIn_two_iff_radical_mod_four u a d hu ha hd).mp + exact isUnramifiedIn_of_numberField_extension (L := L) _ + (cyclotomic_isUnramifiedIn n L 2 hn.not_two_dvd_nat) + + + +noncomputable def quadraticAdjoinBasis {F E : Type*} [Field F] [Field E] [Algebra F E] + (a : E) (ha : IsIntegral F a) + (hdim : Module.finrank F (IntermediateField.adjoin F {a}) = 2) : + Module.Basis (Fin 2) F (IntermediateField.adjoin F {a}) := + let pb := IntermediateField.adjoin.powerBasis ha + pb.basis.reindex (finCongr (pb.finrank.symm.trans hdim)) + +@[simp] +theorem quadraticAdjoinBasis_apply {F E : Type*} [Field F] [Field E] [Algebra F E] + (a : E) (ha : IsIntegral F a) + (hdim : Module.finrank F (IntermediateField.adjoin F {a}) = 2) (i : Fin 2) : + quadraticAdjoinBasis a ha hdim i = ![1, IntermediateField.AdjoinSimple.gen F a] i := by + fin_cases i <;> + simp [quadraticAdjoinBasis, Module.Basis.reindex_apply, PowerBasis.basis_eq_pow] + + + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem primitive_odd_quadratic_signed_level_mod_four {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℤ q) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + (hodd : Odd q) : (χ (-1) * (q : ℤ)) % 4 = 1 := by + classical + by_cases hne : χ = 1 + · subst χ + have hq : q = 1 := hprim.symm.trans DirichletCharacter.conductor_one + subst q + rw [MulChar.one_apply isUnit_neg_one] + norm_num + let K := CyclotomicField q ℚ + let : IsCyclotomicExtension {q} ℚ K := CyclotomicField.isCyclotomicExtension q ℚ + let : IsAbelianGalois ℚ K := IsCyclotomicExtension.isAbelianGalois {q} ℚ K + let χK := χ.ringHomComp (Int.castRingHom K) + have hpK : DirichletCharacter.IsPrimitive χK := by + rw [DirichletCharacter.isPrimitive_def, conductor_ringHomComp χ (Int.castRingHom K) + (Int.cast_injective (α := K))] + exact hprim + let e := AddChar.zmodChar q (zeta_spec q ℚ K).pow_eq_one + have he : e.IsPrimitive := AddChar.zmodChar_primitive_of_primitive_root q (zeta_spec q ℚ K) + let g := gaussSum χK e + let D : ℤ := χ (-1) * q + have hgD : g ^ 2 = (D : K) := by + change gaussSum χK e ^ 2 = ((χ (-1) * (q : ℤ) : ℤ) : K) + rw [primitive_quadratic_gaussSum_sq hpK (hχ.comp (Int.castRingHom K)) he] + change (χ (-1) : K) * (q : K) = ((χ (-1) * (q : ℤ) : ℤ) : K) + rw [Int.cast_mul, Int.cast_natCast] + have hqsf : Squarefree q := odd_divisor_primitive_quadratic_squarefree χ hχ hprim hodd dvd_rfl + have hDsf : Squarefree D := by + apply Int.squarefree_natAbs.mp + change Squarefree (χ (-1) * (q : ℤ)).natAbs + rw [Int.natAbs_mul, Int.natAbs_of_isUnit (isUnit_neg_one.map χ), one_mul] + exact hqsf + have hneC : χ.ringHomComp (Int.castRingHom ℂ) ≠ 1 := by + exact (MulChar.ringHomComp_ne_one_iff (f := Int.castRingHom ℂ) + (Int.cast_injective (α := ℂ))).mpr hne + have hdim : Module.finrank ℚ (IntermediateField.adjoin ℚ {g}) = 2 := by + rw [show IntermediateField.adjoin ℚ {g} = + characterField q K ℂ (χ.ringHomComp (Int.castRingHom ℂ)) from + gaussSum_adjoin_eq_characterField χ hχ hprim e he] + exact characterField_finrank q K ℂ _ (hχ.comp (Int.castRingHom ℂ)) hneC + have hgi : IsIntegral ℚ g := IsIntegral.of_pow (by decide : 0 < 2) + (hgD ▸ isIntegral_intCast D) + let F := IntermediateField.adjoin ℚ {g} + let a : F := IntermediateField.AdjoinSimple.gen ℚ g + let u := quadraticAdjoinBasis g hgi hdim + have hu : (u : Fin 2 → F) = ![1, a] := by + funext i + exact quadraticAdjoinBasis_apply g hgi hdim i + have ha : a ^ 2 = (D : F) := by + apply Subtype.ext + exact hgD + exact quadratic_radical_mod_four_of_odd_cyclotomic_overfield q F K u a D hu ha hDsf hodd + +end WeightedTorusJets + +namespace WeightedTorusJets + +noncomputable def crtUnits {m n : ℕ} (h : m.Coprime n) : + (ZMod (m * n))ˣ ≃* (ZMod m)ˣ × (ZMod n)ˣ := + (Units.mapEquiv (ZMod.chineseRemainder h).toMulEquiv).trans MulEquiv.prodUnits + +@[simp] +theorem crtUnits_fst {m n : ℕ} (h : m.Coprime n) (u : (ZMod (m * n))ˣ) : + (crtUnits h u).1 = ZMod.unitsMap (Nat.dvd_mul_right m n) u := by + apply Units.ext + exact DFunLike.congr_fun (RingHom.ext_zmod + ((RingHom.fst (ZMod m) (ZMod n)).comp (ZMod.chineseRemainder h).toRingHom) + (ZMod.castHom (Nat.dvd_mul_right m n) (ZMod m))) (u : ZMod (m * n)) + +@[simp] +theorem crtUnits_snd {m n : ℕ} (h : m.Coprime n) (u : (ZMod (m * n))ˣ) : + (crtUnits h u).2 = ZMod.unitsMap (Nat.dvd_mul_left n m) u := by + apply Units.ext + exact DFunLike.congr_fun (RingHom.ext_zmod + ((RingHom.snd (ZMod m) (ZMod n)).comp (ZMod.chineseRemainder h).toRingHom) + (ZMod.castHom (Nat.dvd_mul_left n m) (ZMod n))) (u : ZMod (m * n)) + +noncomputable def crtCharacterLeft {m n : ℕ} {R : Type*} [CommRing R] + (h : m.Coprime n) (χ : DirichletCharacter R (m * n)) : DirichletCharacter R m := + MulChar.ofUnitHom (χ.toUnitHom.comp + ((crtUnits h).symm.toMonoidHom.comp (MonoidHom.inl _ _))) + +noncomputable def crtCharacterRight {m n : ℕ} {R : Type*} [CommRing R] + (h : m.Coprime n) (χ : DirichletCharacter R (m * n)) : DirichletCharacter R n := + MulChar.ofUnitHom (χ.toUnitHom.comp + ((crtUnits h).symm.toMonoidHom.comp (MonoidHom.inr _ _))) + +@[simp] +theorem crtCharacterLeft_apply_unit {m n : ℕ} {R : Type*} [CommRing R] + (h : m.Coprime n) (χ : DirichletCharacter R (m * n)) (u : (ZMod m)ˣ) : + crtCharacterLeft h χ u = χ ((crtUnits h).symm (u, 1)) := by + simp [crtCharacterLeft] + +@[simp] +theorem crtCharacterRight_apply_unit {m n : ℕ} {R : Type*} [CommRing R] + (h : m.Coprime n) (χ : DirichletCharacter R (m * n)) (u : (ZMod n)ˣ) : + crtCharacterRight h χ u = χ ((crtUnits h).symm (1, u)) := by + simp [crtCharacterRight] + +theorem crtCharacter_decomposition {m n : ℕ} {R : Type*} [CommRing R] + (h : m.Coprime n) (χ : DirichletCharacter R (m * n)) : + χ = DirichletCharacter.changeLevel (Nat.dvd_mul_right m n) (crtCharacterLeft h χ) * + DirichletCharacter.changeLevel (Nat.dvd_mul_left n m) (crtCharacterRight h χ) := by + apply MulChar.ext + intro u + rw [MulChar.mul_apply] + simp only [DirichletCharacter.changeLevel_def, MulChar.ofUnitHom_coe, + MonoidHom.comp_apply, MulChar.coe_toUnitHom] + rw [crtCharacterLeft_apply_unit, crtCharacterRight_apply_unit, ← map_mul] + congr 1 + have hu : u = (crtUnits h).symm (ZMod.unitsMap (Nat.dvd_mul_right m n) u, 1) * + (crtUnits h).symm (1, ZMod.unitsMap (Nat.dvd_mul_left n m) u) := by + apply (crtUnits h).injective + simp only [map_mul, MulEquiv.apply_symm_apply] + apply Prod.ext <;> simp + exact congrArg Units.val hu + +theorem crtCharacterLeft_isPrimitive {m n : ℕ} [NeZero m] [NeZero n] + {R : Type*} [CommRing R] (h : m.Coprime n) + (χ : DirichletCharacter R (m * n)) (hprim : χ.IsPrimitive) : + (crtCharacterLeft h χ).IsPrimitive := by + have hdiv := DirichletCharacter.conductor_mul_dvd_lcm_conductor + (DirichletCharacter.changeLevel (Nat.dvd_mul_right m n) (crtCharacterLeft h χ)) + (DirichletCharacter.changeLevel (Nat.dvd_mul_left n m) (crtCharacterRight h χ)) + rw [← crtCharacter_decomposition h χ, hprim, + DirichletCharacter.conductor_changeLevel, DirichletCharacter.conductor_changeLevel] at hdiv + apply Nat.dvd_antisymm (crtCharacterLeft h χ).conductor_dvd_level + apply Nat.dvd_of_mul_dvd_mul_right (NeZero.pos n) + exact hdiv.trans (Nat.lcm_dvd (Nat.dvd_mul_right _ n) + ((crtCharacterRight h χ).conductor_dvd_level.trans (Nat.dvd_mul_left n _))) + +theorem crtCharacterRight_isPrimitive {m n : ℕ} [NeZero m] [NeZero n] + {R : Type*} [CommRing R] (h : m.Coprime n) + (χ : DirichletCharacter R (m * n)) (hprim : χ.IsPrimitive) : + (crtCharacterRight h χ).IsPrimitive := by + have hdiv := DirichletCharacter.conductor_mul_dvd_lcm_conductor + (DirichletCharacter.changeLevel (Nat.dvd_mul_right m n) (crtCharacterLeft h χ)) + (DirichletCharacter.changeLevel (Nat.dvd_mul_left n m) (crtCharacterRight h χ)) + rw [← crtCharacter_decomposition h χ, hprim, + DirichletCharacter.conductor_changeLevel, DirichletCharacter.conductor_changeLevel] at hdiv + apply Nat.dvd_antisymm (crtCharacterRight h χ).conductor_dvd_level + apply Nat.dvd_of_mul_dvd_mul_left (NeZero.pos m) + exact hdiv.trans (Nat.lcm_dvd + ((crtCharacterLeft h χ).conductor_dvd_level.trans (Nat.dvd_mul_right m _)) + (Nat.dvd_mul_left _ m)) + +theorem changeLevel_neg_one {m n : ℕ} {R : Type*} [CommRing R] + (h : m ∣ n) (χ : DirichletCharacter R m) : + DirichletCharacter.changeLevel h χ (-1) = χ (-1) := by + have he := DirichletCharacter.changeLevel_eq_cast_of_dvd χ h (-1 : (ZMod n)ˣ) + simpa only [Units.val_neg, Units.val_one, ZMod.cast_neg h, ZMod.cast_one h] using he + +theorem crtCharacter_neg_one {m n : ℕ} {R : Type*} [CommRing R] + (h : m.Coprime n) (χ : DirichletCharacter R (m * n)) : + χ (-1) = crtCharacterLeft h χ (-1) * crtCharacterRight h χ (-1) := by + have he := congrArg (fun ψ : DirichletCharacter R (m * n) => ψ (-1)) + (crtCharacter_decomposition h χ) + simpa only [MulChar.mul_apply, changeLevel_neg_one] using he + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticEigencharacter.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticEigencharacter.lean new file mode 100644 index 0000000000000000000000000000000000000000..22d7f1ea7caea13b9e5cf68a6e07f1d268f14d69 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticEigencharacter.lean @@ -0,0 +1,401 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.SqrtTwoField + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +namespace WeightedTorusJets + +lemma exists_root_normalizing_automorphism {K L : Type*} [Field K] [Field L] + [Algebra ℚ K] [Algebra ℚ L] (ν : K →ₐ[ℚ] L) (a b : K) (A B : L) + (σ τ : K ≃ₐ[ℚ] K) (hσa : σ a = -a) (hσb : σ b = b) + (hτa : τ a = a) (hτb : τ b = -b) + (ha : (ν a) ^ 2 = A ^ 2) (hb : (ν b) ^ 2 = B ^ 2) : + ∃ h : K ≃ₐ[ℚ] K, (h = 1 ∨ h = σ ∨ h = τ ∨ h = σ * τ) ∧ + ν (h a) = A ∧ ν (h b) = B := by + rcases sq_eq_sq_iff_eq_or_eq_neg.mp ha with ha | ha <;> + rcases sq_eq_sq_iff_eq_or_eq_neg.mp hb with hb | hb + · exact ⟨1, Or.inl rfl, ha, hb⟩ + · refine ⟨τ, Or.inr (Or.inr (Or.inl rfl)), ?_, ?_⟩ + · simpa [hτa] using ha + · simp [hτb, hb] + · refine ⟨σ, Or.inr (Or.inl rfl), ?_, ?_⟩ + · simp [hσa, ha] + · simpa [hσb] using hb + · refine ⟨σ * τ, Or.inr (Or.inr (Or.inr rfl)), ?_, ?_⟩ + · simp [AlgEquiv.mul_apply, hτa, hσa, ha] + · simp [AlgEquiv.mul_apply, hτb, hσb, hb] + +lemma exists_embedding_principal_roots {K : Type*} [Field K] [NumberField K] + (a b : K) (d : ℤ) (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (σ τ : K ≃ₐ[ℚ] K) (hσa : σ a = -a) (hσb : σ b = b) + (hτa : τ a = a) (hτb : τ b = -b) : + ∃ ν : K →ₐ[ℚ] ℂ, ν a = Complex.sqrt (d : ℂ) ∧ ν b = (Real.sqrt 2 : ℂ) := by + let : Algebra.IsAlgebraic ℚ K := NumberField.isAlgebraic K + let ν : K →ₐ[ℚ] ℂ := IsAlgClosed.lift + have hA : (Complex.sqrt (d : ℂ)) ^ 2 = (d : ℂ) := by + exact Complex.cpow_nat_inv_pow _ (by decide : (2 : ℕ) ≠ 0) + have hB : (Real.sqrt 2 : ℂ) ^ 2 = 2 := by + rw [← Complex.ofReal_pow, Real.sq_sqrt (by positivity)] + rfl + have ha' : (ν a) ^ 2 = (Complex.sqrt (d : ℂ)) ^ 2 := by + rw [hA, ← map_pow, ha, map_intCast] + have hb' : (ν b) ^ 2 = (Real.sqrt 2 : ℂ) ^ 2 := by + rw [hB, ← map_pow, hb, map_ofNat] + obtain ⟨h, _, hha, hhb⟩ := exists_root_normalizing_automorphism ν a b + (Complex.sqrt (d : ℂ)) (Real.sqrt 2 : ℂ) σ τ hσa hσb hτa hτb ha' hb' + exact ⟨ν.comp h.toAlgHom, hha, hhb⟩ + +lemma basis_fieldRange_eq_adjoin {K L : Type*} [Field K] [Field L] + [Algebra ℚ K] [Algebra ℚ L] (v : Module.Basis (Fin 4) ℚ K) (a b : K) + (hv : ∀ i, v i = ![1, a, b, a * b] i) (ν : K →ₐ[ℚ] L) : + ν.fieldRange = IntermediateField.adjoin ℚ ({ν a, ν b} : Set L) := by + let F := IntermediateField.adjoin ℚ ({a, b} : Set K) + have haF : a ∈ F := IntermediateField.subset_adjoin ℚ _ (by simp) + have hbF : b ∈ F := IntermediateField.subset_adjoin ℚ _ (by simp) + have hF : F = ⊤ := by + apply top_unique + intro x _ + rw [← v.sum_repr x] + apply F.toSubalgebra.sum_mem + intro i _ + apply F.toSubalgebra.smul_mem + rw [hv] + fin_cases i + · exact F.one_mem + · exact haF + · exact hbF + · exact F.mul_mem haF hbF + have htop : (⊤ : IntermediateField ℚ K).map ν = ν.fieldRange := by + ext x + simp [IntermediateField.mem_map] + rw [← htop, ← hF, IntermediateField.adjoin_map] + simp + +lemma exists_principal_root_field_equiv {K : Type*} [Field K] [NumberField K] + (v : Module.Basis (Fin 4) ℚ K) (a b : K) (d : ℤ) + (hv : ∀ i, v i = ![1, a, b, a * b] i) + (ha : a ^ 2 = (d : K)) (hb : b ^ 2 = 2) + (σ τ : K ≃ₐ[ℚ] K) (hσa : σ a = -a) (hσb : σ b = b) + (hτa : τ a = a) (hτb : τ b = -b) : + ∃ e : K ≃ₐ[ℚ] IntermediateField.adjoin ℚ + ({Complex.sqrt (d : ℂ), (Real.sqrt 2 : ℂ)} : Set ℂ), + (e a : ℂ) = Complex.sqrt (d : ℂ) ∧ (e b : ℂ) = (Real.sqrt 2 : ℂ) := by + obtain ⟨ν, hνa, hνb⟩ := exists_embedding_principal_roots a b d ha hb σ τ hσa hσb hτa hτb + have hrange : ν.fieldRange = IntermediateField.adjoin ℚ + ({Complex.sqrt (d : ℂ), (Real.sqrt 2 : ℂ)} : Set ℂ) := by + rw [basis_fieldRange_eq_adjoin v a b hv ν, hνa, hνb] + refine ⟨ν.equivFieldRange.trans (IntermediateField.equivOfEq hrange), ?_, ?_⟩ + · simpa using hνa + · simpa using hνb + +end WeightedTorusJets + +open scoped NumberField + +namespace WeightedTorusJets + +variable {K L : Type*} [Field K] [Field L] [NumberField K] [NumberField L] + +lemma integral_autCongr_equivariant (e : K ≃ₐ[ℚ] L) (σ : K ≃ₐ[ℚ] K) (x : 𝓞 K) : + NumberField.RingOfIntegers.mapRingEquiv e.toRingEquiv (σ • x) = + AlgEquiv.autCongr e σ • NumberField.RingOfIntegers.mapRingEquiv e.toRingEquiv x := by + apply NumberField.RingOfIntegers.ext + change e (σ (x : K)) = AlgEquiv.autCongr e σ (e (x : K)) + simp [AlgEquiv.autCongr_apply] + +lemma integer_frobenius_transport (e : K ≃ₐ[ℚ] L) (σ : K ≃ₐ[ℚ] K) (p : ℕ) + (hfrob : ∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) : + ∀ y : 𝓞 L, (p : 𝓞 L) ∣ y ^ p - AlgEquiv.autCongr e σ • y := by + let E := NumberField.RingOfIntegers.mapRingEquiv e.toRingEquiv + intro y + have h := map_dvd E (hfrob (E.symm y)) + dsimp only [E] at h + simpa only [map_natCast, map_sub, map_pow, integral_autCongr_equivariant, + RingEquiv.apply_symm_apply] using h + +lemma integer_two_direction_frobenius_transport (e : K ≃ₐ[ℚ] L) + (σ τ : K ≃ₐ[ℚ] K) (p : ℕ) + (hfrob : (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - (σ * τ) • x)) : + (∀ y : 𝓞 L, (p : 𝓞 L) ∣ y ^ p - AlgEquiv.autCongr e σ • y) ∨ + (∀ y : 𝓞 L, (p : 𝓞 L) ∣ y ^ p - + (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) • y) := by + rcases hfrob with h | h + · exact Or.inl (integer_frobenius_transport e σ p h) + · right + simpa only [map_mul] using integer_frobenius_transport e (σ * τ) p h + +lemma transported_sign_actions (e : K ≃ₐ[ℚ] L) (a b : K) (σ τ : K ≃ₐ[ℚ] K) + (hσa : σ a = -a) (hσb : σ b = b) (hτa : τ a = a) (hτb : τ b = -b) : + AlgEquiv.autCongr e σ (e a) = -e a ∧ + AlgEquiv.autCongr e σ (e b) = e b ∧ + AlgEquiv.autCongr e τ (e a) = e a ∧ + AlgEquiv.autCongr e τ (e b) = -e b := by + simp [AlgEquiv.autCongr_apply, hσa, hσb, hτa, hτb] + +lemma transported_four_automorphisms (e : K ≃ₐ[ℚ] L) (σ τ : K ≃ₐ[ℚ] K) + (hcard : Nat.card (K ≃ₐ[ℚ] K) = 4) + (hall : ∀ f : K ≃ₐ[ℚ] K, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) + (hcomm : ∀ f g : K ≃ₐ[ℚ] K, Commute f g) : + Nat.card (L ≃ₐ[ℚ] L) = 4 ∧ + (∀ f : L ≃ₐ[ℚ] L, f = 1 ∨ f = AlgEquiv.autCongr e σ ∨ + f = AlgEquiv.autCongr e τ ∨ f = AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) ∧ + (∀ f g : L ≃ₐ[ℚ] L, Commute f g) := by + refine ⟨(Nat.card_congr (AlgEquiv.autCongr e).toEquiv).symm.trans hcard, ?_, ?_⟩ + · intro f + obtain ⟨g, rfl⟩ := (AlgEquiv.autCongr e).surjective f + rcases hall g with h | h | h | h <;> simp only [h, map_one, map_mul, true_or, or_true] + · intro f g + obtain ⟨f', rfl⟩ := (AlgEquiv.autCongr e).surjective f + obtain ⟨g', rfl⟩ := (AlgEquiv.autCongr e).surjective g + exact (hcomm f' g').map (AlgEquiv.autCongr e).toMonoidHom + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem adjoin_simple_eq_of_sq_eq {F E : Type*} [Field F] [Field E] [Algebra F E] + {a b : E} (h : a ^ 2 = b ^ 2) : + IntermediateField.adjoin F {a} = IntermediateField.adjoin F {b} := by + rcases eq_or_eq_neg_of_sq_eq_sq a b h with hab | hab + · rw [hab] + · subst a + apply le_antisymm + · apply IntermediateField.adjoin_le_iff.mpr + simpa using (IntermediateField.adjoin F {b}).neg_mem + (IntermediateField.mem_adjoin_simple_self F b) + · apply IntermediateField.adjoin_le_iff.mpr + simpa using (IntermediateField.adjoin F {-b}).neg_mem + (IntermediateField.mem_adjoin_simple_self F (-b)) + +theorem adjoin_sqrt_two_map {L : Type*} [Field L] [CharZero L] + (ν : L →ₐ[ℚ] ℂ) (b : L) (hb : b ^ 2 = 2) : + (IntermediateField.adjoin ℚ {b}).map ν = + IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} := by + rw [IntermediateField.adjoin_map, Set.image_singleton] + apply adjoin_simple_eq_of_sq_eq + rw [← map_pow, hb, map_ofNat] + have h : (Real.sqrt 2) ^ 2 = (2 : ℝ) := Real.sq_sqrt (by norm_num) + exact_mod_cast h.symm + +theorem sqrt_two_field_exclusion_map_iff {L : Type*} [Field L] [CharZero L] + (F : IntermediateField ℚ L) (ν : L →ₐ[ℚ] ℂ) (b : L) (hb : b ^ 2 = 2) : + F.map ν ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} ↔ + F ≠ IntermediateField.adjoin ℚ {b} := by + rw [← adjoin_sqrt_two_map ν b hb] + constructor + · intro h heq + exact h (congrArg (fun E : IntermediateField ℚ L => E.map ν) heq) + · intro h heq + exact h (IntermediateField.map_injective ν heq) + +theorem sourceSqrtTwoField_exclusion_map_iff (q : ℕ) [NeZero (8 * q)] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {8 * q} ℚ L] + (F : IntermediateField ℚ L) (ν : L →ₐ[ℚ] ℂ) : + F.map ν ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} ↔ + F ≠ sourceSqrtTwoField q L := by + exact sqrt_two_field_exclusion_map_iff F ν _ (sourceSqrtTwoField_root_sq q L) + + + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_biquadratic_arithmetic_principal_of_field_ne (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + ∃ d : ℤ, Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ ¬ IsSquare (d : ℚ) ∧ + Int.IsFundamentalDiscr (if d % 4 = 1 then d else 4 * d) ∧ + (if d % 4 = 1 then d else 4 * d).natAbs = q ∧ + let Kχ := IntermediateField.adjoin ℚ ({Complex.sqrt (d : ℂ)} : Set ℂ) + let K := IntermediateField.adjoin ℚ + ({Complex.sqrt (d : ℂ), (Real.sqrt 2 : ℂ)} : Set ℂ) + let a : K := ⟨Complex.sqrt (d : ℂ), IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b : K := ⟨(Real.sqrt 2 : ℂ), IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ hKχ : NumberField Kχ, ∃ hK : NumberField K, + letI := hKχ + letI := hK + NumberField.discr Kχ = (if d % 4 = 1 then d else 4 * d) ∧ + Kχ ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} ∧ IsGalois ℚ K ∧ + (∃ ν : CyclotomicField (8 * q) ℚ →ₐ[ℚ] ℂ, + (characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)).map ν = Kχ) ∧ + ∃ v : Module.Basis (Fin 4) ℚ K, + (∀ i, v i = ![1, a, b, a * b] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ K = 4 ∧ + ∃ σ τ : K ≃ₐ[ℚ] K, + σ a = -a ∧ σ b = b ∧ τ a = a ∧ τ b = -b ∧ + Nat.card (K ≃ₐ[ℚ] K) = 4 ∧ + (∀ f : K ≃ₐ[ℚ] K, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : K ≃ₐ[ℚ] K, Commute f g) ∧ + ∀ (p : ℕ), p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - (σ * τ) • x)) := by + let L := CyclotomicField (8 * q) ℚ + obtain ⟨d, aL, bL, hd, hbound, hddiv, hdns, haL, hbL, hχfield, hdiscrabs, + hfund, hdiscrformula, v, hv, hint, hdim, σ, τ, hσa, hσb, hτa, hτb, + hcard, hall, hcomm, hfrob⟩ := + source_biquadratic_arithmetic_canonical_of_field_ne q χ hreal hprim hne hfield + let B := IntermediateField.adjoin ℚ ({aL, bL} : Set L) + let aB : B := ⟨aL, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let bB : B := ⟨bL, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + have haB : aB ^ 2 = (d : B) := by apply Subtype.ext; exact haL + have hbB : bB ^ 2 = 2 := by apply Subtype.ext; exact hbL + let Kχ := IntermediateField.adjoin ℚ ({Complex.sqrt (d : ℂ)} : Set ℂ) + let K := IntermediateField.adjoin ℚ + ({Complex.sqrt (d : ℂ), (Real.sqrt 2 : ℂ)} : Set ℂ) + let aK : K := ⟨Complex.sqrt (d : ℂ), IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let bK : K := ⟨(Real.sqrt 2 : ℂ), IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + obtain ⟨e, heaC, hebC⟩ := exists_principal_root_field_equiv v aB bB d hv haB hbB + σ τ hσa hσb hτa hτb + have hea : e aB = aK := Subtype.ext heaC + have heb : e bB = bK := Subtype.ext hebC + let hK : NumberField K := NumberField.of_ringEquiv B K e.toRingEquiv + let : NumberField K := hK + let νB : B →ₐ[ℚ] ℂ := K.val.comp e.toAlgHom + obtain ⟨νL, hνL⟩ := IsAlgClosed.surjective_domRestrict_of_isAlgebraic + (K := ℚ) (L := B) (M := ℂ) (E := L) νB + have hνLa : νL aL = Complex.sqrt (d : ℂ) := by + have h := AlgHom.congr_fun hνL aB + change νL aL = (e aB : ℂ) at h + exact h.trans heaC + have hχmap : (characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ)).map νL = Kχ := by + rw [← hχfield, IntermediateField.adjoin_map, Set.image_singleton, hνLa] + have hKχne : Kχ ≠ IntermediateField.adjoin ℚ {(Real.sqrt 2 : ℂ)} := by + rw [← hχmap] + exact (sourceSqrtTwoField_exclusion_map_iff q L _ νL).2 hfield + let Q := IntermediateField.adjoin ℚ ({aL} : Set L) + have hQmap : Q.map νL = Kχ := by + rw [IntermediateField.adjoin_map, Set.image_singleton, hνLa] + let eχ : Q ≃ₐ[ℚ] Kχ := (Q.equivMap νL).trans (IntermediateField.equivOfEq hQmap) + let hKχ : NumberField Kχ := NumberField.of_ringEquiv Q Kχ eχ.toRingEquiv + let : NumberField Kχ := hKχ + have hdiscrKχ : NumberField.discr Kχ = (if d % 4 = 1 then d else 4 * d) := + (NumberField.discr_eq_discr_of_algEquiv Q eχ).symm.trans hdiscrformula + rw [hdiscrformula] at hfund hdiscrabs + let w := v.map e.toLinearEquiv + have hw (i : Fin 4) : w i = ![1, aK, bK, aK * bK] i := by + change e (v i) = _ + have hv' : v i = ![1, aB, bB, aB * bB] i := hv i + rw [hv'] + fin_cases i + · exact map_one e + · exact hea + · exact heb + · change e (aB * bB) = aK * bK + rw [map_mul, hea, heb] + have haK : aK ^ 2 = (d : K) := by rw [← hea, ← map_pow, haB, map_intCast] + have hbK : bK ^ 2 = 2 := by rw [← heb, ← map_pow, hbB, map_ofNat] + have hgal : IsGalois ℚ K := biquadratic_isGalois w aK bK (d : ℚ) 2 hw + (by simpa [pow_two] using haK) (by simpa [pow_two] using hbK) + have hsign := transported_sign_actions e aB bB σ τ hσa hσb hτa hτb + rw [hea, heb] at hsign + obtain ⟨hcardK, hallK, hcommK⟩ := transported_four_automorphisms e σ τ hcard hall hcomm + refine ⟨d, hd, hbound, hddiv, hdns, hfund, hdiscrabs, hKχ, hK, hdiscrKχ, hKχne, hgal, + ⟨νL, hχmap⟩, w, hw, ?_, ?_, AlgEquiv.autCongr e σ, AlgEquiv.autCongr e τ, + hsign.1, hsign.2.1, hsign.2.2.1, hsign.2.2.2, hcardK, hallK, hcommK, ?_⟩ + · intro i + exact map_isIntegral_int e.toRingHom (hint i) + · simpa using Module.finrank_eq_card_basis w + · intro p hp hpn hχp + exact integer_two_direction_frobenius_transport e σ τ p (hfrob p hp hpn hχp) + +end WeightedTorusJets + +namespace WeightedTorusJets + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem characterField_ne_sourceSqrtTwoField_of_ne_eight (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hprim : χ.IsPrimitive) (hquad : χ.IsQuadratic) + (hne : χ ≠ 1) (hq8 : q ≠ 8) : + characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ) := by + intro hfield + have hdiscr := characterField_changeLevel_discr_natAbs + (L := CyclotomicField (8 * q) ℚ) (dvd_mul_left q 8) χ hquad hprim hne + have htwo := (quadraticAdjoin_discriminant _ 2 + (sourceSqrtTwoField_root_sq q (CyclotomicField (8 * q) ℚ)) + (Int.squarefree_natAbs.mp Nat.prime_two.squarefree) not_isSquare_rat_two).1 + change NumberField.discr (sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) = _ at htwo + norm_num at htwo + rw [hfield, htwo] at hdiscr + exact hq8 (by simpa using hdiscr.symm) + +end WeightedTorusJets + +namespace WeightedTorusJets + +variable {K : Type*} [Field K] [Algebra ℚ K] + +def quadraticEigencharacter (a : K) (d : ℚ) + (ha : a * a = algebraMap ℚ K d) (ha0 : a ≠ 0) : (K ≃ₐ[ℚ] K) →* K where + toFun f := f a / a + map_one' := by simp [ha0] + map_mul' f g := by + rcases quadratic_algEquiv_dichotomy a d ha g with hg | hg <;> + simp [AlgEquiv.mul_apply, hg, ha0, neg_div] + +lemma quadraticEigencharacter_apply_mul (a : K) (d : ℚ) + (ha : a * a = algebraMap ℚ K d) (ha0 : a ≠ 0) (f : K ≃ₐ[ℚ] K) : + quadraticEigencharacter a d ha ha0 f * a = f a := + div_mul_cancel₀ _ ha0 + +lemma quadraticEigencharacter_range (a : K) (d : ℚ) + (ha : a * a = algebraMap ℚ K d) (ha0 : a ≠ 0) (f : K ≃ₐ[ℚ] K) : + quadraticEigencharacter a d ha ha0 f = 1 ∨ quadraticEigencharacter a d ha ha0 f = -1 := by + rcases quadratic_algEquiv_dichotomy a d ha f with hf | hf <;> + simp [quadraticEigencharacter, hf, ha0] + +lemma quadraticEigencharacter_eq_neg_one_iff (a : K) (d : ℚ) + (ha : a * a = algebraMap ℚ K d) (ha0 : a ≠ 0) (f : K ≃ₐ[ℚ] K) : + quadraticEigencharacter a d ha ha0 f = -1 ↔ f a = -a := by + change f a / a = -1 ↔ f a = -a + rw [div_eq_iff ha0] + simp + +end WeightedTorusJets +namespace WeightedTorusJets + +theorem source_quadratic_group_character {K : Type*} [Field K] [Algebra ℚ K] + (a : K) (d : ℚ) (ha : a ^ 2 = algebraMap ℚ K d) (hd : ¬ IsSquare d) + (σ τ : K ≃ₐ[ℚ] K) (hσ : σ a = -a) (hτ : τ a = a) : + ∃ ξ : (K ≃ₐ[ℚ] K) →* K, + (∀ f, f a = ξ f * a) ∧ + (∀ f, ξ f = 1 ∨ ξ f = -1) ∧ + ξ σ = -1 ∧ ξ τ = 1 ∧ ξ (σ * τ) = -1 := by + have ha0 : a ≠ 0 := by + intro h + have hd0 : d = 0 := (algebraMap ℚ K).injective (by simpa [h] using ha.symm) + exact hd ⟨0, by simp [hd0]⟩ + have ha' : a * a = algebraMap ℚ K d := by simpa [pow_two] using ha + let ξ := quadraticEigencharacter a d ha' ha0 + have hξσ : ξ σ = -1 := (quadraticEigencharacter_eq_neg_one_iff a d ha' ha0 σ).mpr hσ + have hξτ : ξ τ = 1 := by simp [ξ, quadraticEigencharacter, hτ, ha0] + refine ⟨ξ, fun f => (quadraticEigencharacter_apply_mul a d ha' ha0 f).symm, + quadraticEigencharacter_range a d ha' ha0, hξσ, hξτ, ?_⟩ + rw [map_mul, hξσ, hξτ, mul_one] + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticEigencharacterAutCongr.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticEigencharacterAutCongr.lean new file mode 100644 index 0000000000000000000000000000000000000000..2355e65013f773a908a1457072a71e2f3495dc84 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticEigencharacterAutCongr.lean @@ -0,0 +1,88 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.QuadraticGroupCharacterFrobenius + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped NumberField +namespace WeightedTorusJets + +theorem quadraticEigencharacter_autCongr {K L : Type*} + [Field K] [Field L] [Algebra ℚ K] [Algebra ℚ L] + (e : K ≃ₐ[ℚ] L) (a : K) (b : L) (d : ℚ) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ L d) + (ha0 : a ≠ 0) (hb0 : b ≠ 0) (he : e a = b) (f : K ≃ₐ[ℚ] K) : + quadraticEigencharacter b d hb hb0 (AlgEquiv.autCongr e f) = + e (quadraticEigencharacter a d ha ha0 f) := by + simp [quadraticEigencharacter, ← he, AlgEquiv.autCongr_apply] + +theorem quadraticEigencharacter_autCongr_complex {K L : Type*} + [Field K] [Field L] [Algebra ℚ K] [Algebra ℚ L] + (e : K ≃ₐ[ℚ] L) (a : K) (b : L) (d : ℚ) + (ha : a * a = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ L d) + (ha0 : a ≠ 0) (hb0 : b ≠ 0) (he : e a = b) + (ν : L →ₐ[ℚ] ℂ) (f : K ≃ₐ[ℚ] K) : + ν (quadraticEigencharacter b d hb hb0 (AlgEquiv.autCongr e f)) = + (ν.comp e.toAlgHom) (quadraticEigencharacter a d ha ha0 f) := + congrArg ν (quadraticEigencharacter_autCongr e a b d ha hb ha0 hb0 he f) + +theorem source_quadratic_group_character_principal_transport + {K L : Type*} [Field K] [Field L] [NumberField K] [NumberField L] + (e : K ≃ₐ[ℚ] L) (a : K) (b : L) (d : ℚ) + (ha : a ^ 2 = algebraMap ℚ K d) (hb : b * b = algebraMap ℚ L d) + (hd : ¬ IsSquare d) (he : e a = b) + (σ τ : K ≃ₐ[ℚ] K) (hσ : σ a = -a) (hτ : τ a = a) + (ν : L →ₐ[ℚ] ℂ) (q : ℕ) (χ : DirichletCharacter ℂ q) + (hfrob : ∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - (σ * τ) • x))) : + ∃ hb0 : b ≠ 0, + let ξ := quadraticEigencharacter b d hb hb0 + (∀ f, f b = ξ f * b) ∧ + (∀ f, ξ f = 1 ∨ ξ f = -1) ∧ + ξ (AlgEquiv.autCongr e σ) = -1 ∧ ξ (AlgEquiv.autCongr e τ) = 1 ∧ + ξ (AlgEquiv.autCongr e σ * AlgEquiv.autCongr e τ) = -1 ∧ + ∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ∃ φ : K ≃ₐ[ℚ] K, (φ = σ ∨ φ = σ * τ) ∧ + (∀ (P : Ideal (𝓞 L)) (_ : P.IsPrime), + P.LiesOver (Ideal.span {(p : ℤ)}) → IsArithFrobAt ℤ (AlgEquiv.autCongr e φ) P) ∧ + ν (ξ (AlgEquiv.autCongr e φ)) = χ p ∧ + ∀ x : 𝓞 L, (p : 𝓞 L) ∣ x ^ p - AlgEquiv.autCongr e φ • x := by + have ha0 : a ≠ 0 := by + intro h + have hd0 : d = 0 := (algebraMap ℚ K).injective (by simpa [h] using ha.symm) + exact hd (hd0 ▸ IsSquare.zero) + have hb0 : b ≠ 0 := he ▸ (map_ne_zero e).mpr ha0 + have ha' : a * a = algebraMap ℚ K d := by simpa [pow_two] using ha + obtain ⟨ξK, hξK, hrange, hξσ, hξτ, hξστ, hprimes⟩ := + source_quadratic_group_character_with_frobenius a d ha hd σ τ hσ hτ + (ν.comp e.toAlgHom) q χ hfrob + let ξ := quadraticEigencharacter b d hb hb0 + have hnat (f : K ≃ₐ[ℚ] K) : ξ (AlgEquiv.autCongr e f) = e (ξK f) := + (quadraticEigencharacter_autCongr e a b d ha' hb ha0 hb0 he f).trans + (congrArg e (div_eq_of_eq_mul ha0 (hξK f))) + refine ⟨hb0, fun f => (quadraticEigencharacter_apply_mul b d hb hb0 f).symm, + quadraticEigencharacter_range b d hb hb0, ?_, ?_, ?_, ?_⟩ + · simpa [hξσ] using hnat σ + · simpa [hξτ] using hnat τ + · simpa only [map_mul, hξστ, map_neg, map_one] using hnat (σ * τ) + · intro p hp hpn hχp + obtain ⟨φ, hchoice, _, hvalue, hglobal⟩ := hprimes p hp hpn hχp + have hglobal' := integer_frobenius_transport e φ p hglobal + refine ⟨φ, hchoice, ?_, ?_, hglobal'⟩ + · intro P _ hP + let : P.LiesOver (Ideal.span {(p : ℤ)}) := hP + exact isArithFrobAt_of_integer_global_congruence p (AlgEquiv.autCongr e φ) hglobal' P + · exact (congrArg ν (hnat φ)).trans hvalue + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticGroupCharacterFrobenius.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticGroupCharacterFrobenius.lean new file mode 100644 index 0000000000000000000000000000000000000000..a93887ca4ae1915d45a4cba1b0c81a2cf2a655b2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/QuadraticGroupCharacterFrobenius.lean @@ -0,0 +1,48 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ArithFrobIntegerGlobalCongruence +import OAI.NumberTheory.Jacobsthal.Siegel.QuadraticEigencharacter + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped NumberField +open scoped NumberField + +namespace WeightedTorusJets + +theorem source_quadratic_group_character_with_frobenius + {K : Type*} [Field K] [NumberField K] + (a : K) (d : ℚ) (ha : a ^ 2 = algebraMap ℚ K d) (hd : ¬ IsSquare d) + (σ τ : K ≃ₐ[ℚ] K) (hσ : σ a = -a) (hτ : τ a = a) + (ν : K →ₐ[ℚ] ℂ) (q : ℕ) (χ : DirichletCharacter ℂ q) + (hfrob : ∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - (σ * τ) • x))) : + ∃ ξ : (K ≃ₐ[ℚ] K) →* K, + (∀ f, f a = ξ f * a) ∧ + (∀ f, ξ f = 1 ∨ ξ f = -1) ∧ + ξ σ = -1 ∧ ξ τ = 1 ∧ ξ (σ * τ) = -1 ∧ + ∀ p : ℕ, p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ∃ φ : K ≃ₐ[ℚ] K, (φ = σ ∨ φ = σ * τ) ∧ + (∀ (P : Ideal (𝓞 K)) (_ : P.IsPrime), + P.LiesOver (Ideal.span {(p : ℤ)}) → IsArithFrobAt ℤ φ P) ∧ + ν (ξ φ) = χ p ∧ ∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - φ • x := by + obtain ⟨ξ, hξ, hrange, hξσ, hξτ, hξστ⟩ := source_quadratic_group_character a d ha hd σ τ hσ hτ + refine ⟨ξ, hξ, hrange, hξσ, hξτ, hξστ, ?_⟩ + intro p hp hpn hχp + obtain ⟨φ, hchoice, hφ, hglobal⟩ := + exists_source_frobenius_of_global_choice p σ τ (hfrob p hp hpn hχp) + refine ⟨φ, hchoice, hφ, ?_, hglobal⟩ + rcases hchoice with rfl | rfl <;> simp [hξσ, hξστ, hχp] + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/RealLogDerivConductorCompletedLDivisorTsum.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RealLogDerivConductorCompletedLDivisorTsum.lean new file mode 100644 index 0000000000000000000000000000000000000000..b5baa10cd9eacb5780b1e6d31d5ccb962408fe7f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RealLogDerivConductorCompletedLDivisorTsum.lean @@ -0,0 +1,538 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConductorCompletedL + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section AnalyticAssemblyScope +open scoped BigOperators Topology +section +open Filter Set MeasureTheory +open scoped Topology +open Filter Set Asymptotics +namespace WeightedTorusJets + +open _root_.Erdos970.Complex DirichletCharacter _root_.Erdos970.Complex.Hadamard RealCharacterAnalysis + +section + +variable {q : ℕ} [NeZero q] {χ : DirichletCharacter ℂ q} + +local notation "DivisorIndices" => divisorZeroIndex₀ (conductorCompletedL χ) Set.univ + +theorem real_logDeriv_conductorCompletedL_eq_divisor_tsum + (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) (hquad : χ.IsQuadratic) (B : ℂ) + (hbase : Summable (fun j : DivisorIndices => (1 / divisorZeroIndex₀Val j).re)) + (hexp : ∀ z : ℂ, conductorCompletedL χ z ≠ 0 → + HasSum (fun j : DivisorIndices => + 1 / (z - divisorZeroIndex₀Val j) + 1 / divisorZeroIndex₀Val j) + (logDeriv (conductorCompletedL χ) z - B)) + {s : ℝ} (hs : 1 < s) : + (logDeriv (conductorCompletedL χ) (s : ℂ)).re = + ∑' j : DivisorIndices, (1 / ((s : ℂ) - divisorZeroIndex₀Val j)).re := by + have hf := differentiable_conductorCompletedL χ hχ1 + have h0 := conductorCompletedL_ne_zero_at_zero χ hχ hχ1 + have hnz (x : ℝ) (hx : x = -1 ∨ 1 < x) : conductorCompletedL χ (x : ℂ) ≠ 0 := by + intro hzero + have hstrip := completedL_zero_re_mem_Ioo χ hχ hχ1 + ((conductorCompletedL_zero_iff χ (x : ℂ)).mp hzero) + simp only [Set.mem_Ioo, Complex.ofReal_re] at hstrip + rcases hx with rfl | hx + · linarith + · linarith + rw [tsum_divisorIndex_eq_analytic hf h0 (fun z => (1 / ((s : ℂ) - z)).re)] + apply real_logDeriv_conductorCompletedL_eq_tsum hχ hχ1 hquad B.re + ((summable_divisorIndex_iff_analytic hf h0 (fun z => (1 / z).re)).mp hbase) _ hs + intro x hx + apply ((divisorIndexEquivAnalytic hf h0).hasSum_iff + (f := fun j => (1 / ((x : ℂ) - j.1) + 1 / j.1).re)).mp + simpa only [Function.comp_def, divisorIndexEquivAnalytic_val, Complex.sub_re] using + Complex.hasSum_re (hexp (x : ℂ) (hnz x hx)) + +end + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem abs_reciprocal_sub_re_le_normSq {ρ : ℂ} {s : ℝ} + (hρ₀ : 0 < ρ.re) (hρ₁ : ρ.re < 1) (hs : 1 < s) : + |(1 / ((s : ℂ) - ρ)).re| ≤ + (s * (1 + 1 / (s - 1) ^ 2)) / Complex.normSq ρ := by + have hs₀ : 0 < s := zero_lt_one.trans hs + have hsquare : 0 < (s - 1) ^ 2 := sq_pos_of_pos (by linarith) + have hρne : ρ ≠ 0 := by + intro h + simp [h] at hρ₀ + have hnorm : 0 < Complex.normSq ρ := Complex.normSq_pos.mpr hρne + have hdenlower : (s - 1) ^ 2 ≤ Complex.normSq ((s : ℂ) - ρ) := by + simp only [Complex.normSq_apply, Complex.sub_re, Complex.ofReal_re, + Complex.sub_im, Complex.ofReal_im, zero_sub] + nlinarith [sq_nonneg ρ.im, mul_self_le_mul_self + (show 0 ≤ s - 1 by linarith) (show s - 1 ≤ s - ρ.re by linarith)] + have hden : 0 < Complex.normSq ((s : ℂ) - ρ) := hsquare.trans_le hdenlower + have hnormadd : Complex.normSq ρ ≤ 1 + Complex.normSq ((s : ℂ) - ρ) := by + simp only [Complex.normSq_apply, Complex.sub_re, Complex.ofReal_re, + Complex.sub_im, Complex.ofReal_im, zero_sub] + nlinarith [sq_nonneg (s - ρ.re), mul_self_le_mul_self hρ₀.le hρ₁.le] + have hone : 1 ≤ Complex.normSq ((s : ℂ) - ρ) / (s - 1) ^ 2 := by + exact (le_div_iff₀ hsquare).mpr (by simpa using hdenlower) + have hbound : Complex.normSq ρ ≤ + (1 + 1 / (s - 1) ^ 2) * Complex.normSq ((s : ℂ) - ρ) := by + calc + Complex.normSq ρ ≤ 1 + Complex.normSq ((s : ℂ) - ρ) := hnormadd + _ ≤ Complex.normSq ((s : ℂ) - ρ) / (s - 1) ^ 2 + + Complex.normSq ((s : ℂ) - ρ) := by linarith + _ = _ := by ring + have hnum : 0 ≤ s - ρ.re := by linarith + simp only [one_div, Complex.inv_re, Complex.sub_re, Complex.ofReal_re] + rw [abs_of_nonneg (div_nonneg hnum hden.le)] + apply (div_le_div_iff₀ hden hnorm).mpr + calc + (s - ρ.re) * Complex.normSq ρ ≤ s * Complex.normSq ρ := + mul_le_mul_of_nonneg_right (sub_le_self s hρ₀.le) hnorm.le + _ ≤ s * ((1 + 1 / (s - 1) ^ 2) * Complex.normSq ((s : ℂ) - ρ)) := + mul_le_mul_of_nonneg_left hbound hs₀.le + _ = _ := by ring + +theorem abs_reciprocal_re_le_normSq {ρ : ℂ} + (hρ₀ : 0 ≤ ρ.re) (hρ₁ : ρ.re ≤ 1) : + |(1 / ρ).re| ≤ 1 / Complex.normSq ρ := by + simp only [one_div, Complex.inv_re] + rw [abs_of_nonneg (div_nonneg hρ₀ (Complex.normSq_nonneg ρ))] + simpa only [one_div] using div_le_div_of_nonneg_right hρ₁ (Complex.normSq_nonneg ρ) + +theorem summable_abs_reciprocal_sub_re {ι : Type*} (ρ : ι → ℂ) + (hstrip : ∀ i, 0 < (ρ i).re ∧ (ρ i).re < 1) + (hsum : Summable (fun i => ‖ρ i‖⁻¹ ^ (2 : ℕ))) + {s : ℝ} (hs : 1 < s) : + Summable (fun i => |(1 / ((s : ℂ) - ρ i)).re|) := by + have hnormSq : Summable (fun i => 1 / Complex.normSq (ρ i)) := by + simpa only [Complex.normSq_eq_norm_sq, one_div, inv_pow] using hsum + apply (hnormSq.mul_left (s * (1 + 1 / (s - 1) ^ 2))).of_norm_bounded + intro i + simpa only [Real.norm_eq_abs, abs_abs, mul_one_div] using + abs_reciprocal_sub_re_le_normSq (hstrip i).1 (hstrip i).2 hs + +theorem summable_abs_reciprocal_re {ι : Type*} (ρ : ι → ℂ) + (hstrip : ∀ i, 0 ≤ (ρ i).re ∧ (ρ i).re ≤ 1) + (hsum : Summable (fun i => ‖ρ i‖⁻¹ ^ (2 : ℕ))) : + Summable (fun i => |(1 / ρ i).re|) := by + have hnormSq : Summable (fun i => 1 / Complex.normSq (ρ i)) := by + simpa only [Complex.normSq_eq_norm_sq, one_div, inv_pow] using hsum + apply hnormSq.of_norm_bounded + intro i + simpa only [Real.norm_eq_abs, abs_abs] using + abs_reciprocal_re_le_normSq (hstrip i).1 (hstrip i).2 + + + +open _root_.Erdos970.Complex.Hadamard + +theorem divisorZeroIndex_val_zero {f : ℂ → ℂ} (hf : Differentiable ℂ f) + (p : divisorZeroIndex₀ f Set.univ) : f (divisorZeroIndex₀Val p) = 0 := by + by_contra hz + have ha : AnalyticOnNhd ℂ f Set.univ := fun z _ => hf.analyticAt z + have hzero := (hf.analyticAt (divisorZeroIndex₀Val p)).analyticOrderAt_eq_zero.mpr hz + have hsupport := divisorZeroIndex₀Val_mem_divisor_support p + rw [MeromorphicOn.AnalyticOnNhd.divisor_apply ha (Set.mem_univ _), hzero] at hsupport + simp at hsupport + +theorem conductorCompletedL_divisorIndex_re_mem_Ioo {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsPrimitive) (hχ₁ : χ ≠ 1) + (p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ) : + 0 < (divisorZeroIndex₀Val p).re ∧ (divisorZeroIndex₀Val p).re < 1 := by + have hzero := divisorZeroIndex_val_zero (differentiable_conductorCompletedL χ hχ₁) p + exact completedL_zero_re_mem_Ioo χ hχ hχ₁ + ((conductorCompletedL_zero_iff χ _).mp hzero) + +theorem conductorCompletedL_abs_reciprocal_summable {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsPrimitive) (hχ₁ : χ ≠ 1) + (hsum : Summable (fun p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ => + ‖divisorZeroIndex₀Val p‖⁻¹ ^ (2 : ℕ))) + {s : ℝ} (hs : 1 < s) : + Summable (fun p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ => + |(1 / ((s : ℂ) - divisorZeroIndex₀Val p)).re|) ∧ + Summable (fun p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ => + |(1 / divisorZeroIndex₀Val p).re|) := by + have hstrip := conductorCompletedL_divisorIndex_re_mem_Ioo χ hχ hχ₁ + exact ⟨summable_abs_reciprocal_sub_re _ hstrip hsum hs, + summable_abs_reciprocal_re _ (fun p => ⟨(hstrip p).1.le, (hstrip p).2.le⟩) hsum⟩ + +theorem exists_divisorZeroIndex_val_eq_of_zero {f : ℂ → ℂ} + (hf : Differentiable ℂ f) (hfne : f ≠ 0) {z : ℂ} (hz₀ : z ≠ 0) (hz : f z = 0) : + ∃ p : divisorZeroIndex₀ f Set.univ, divisorZeroIndex₀Val p = z := by + have horder : analyticOrderAt f z ≠ 0 := (hf.analyticAt z).analyticOrderAt_ne_zero.mpr hz + have htop : analyticOrderAt f z ≠ ⊤ := by + exact fun h => hfne ((AnalyticOnNhd.analyticOrderAt_eq_top_iff_eq_zero z hf.analyticAt).mp h) + have hpos : 0 < analyticOrderNatAt f z := by + rw [Nat.pos_iff_ne_zero, analyticOrderNatAt, ne_eq, ENat.toNat_eq_zero, not_or] + exact ⟨horder, htop⟩ + refine ⟨⟨⟨z, ⟨0, ?_⟩⟩, hz₀⟩, rfl⟩ + rw [RealCharacterAnalysis.toNat_divisor_eq_analyticOrderNatAt hf] + exact hpos + +theorem real_zero_le_divisor_reciprocal_tsum {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsPrimitive) (hχ₁ : χ ≠ 1) + (hsum : Summable (fun p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ => + ‖divisorZeroIndex₀Val p‖⁻¹ ^ (2 : ℕ))) + {β s : ℝ} (hβ₀ : 0 < β) + (hβ : DirichletCharacter.LFunction χ (β : ℂ) = 0) (hs : 1 < s) : + 1 / (s - β) ≤ + ∑' p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ, + (1 / ((s : ℂ) - divisorZeroIndex₀Val p)).re := by + have hf := differentiable_conductorCompletedL χ hχ₁ + have hfne : conductorCompletedL χ ≠ 0 := by + intro hzero + have hzero₁ : conductorCompletedL χ 1 = 0 := congrFun hzero 1 + exact completedL_ne_zero_of_one_le_re χ hχ₁ (s := 1) (by simp) + ((conductorCompletedL_zero_iff χ 1).mp hzero₁) + have hzeroβ : conductorCompletedL χ (β : ℂ) = 0 := by + rw [conductorCompletedL_zero_iff, + completedL_eq_mul_gammaFactor χ (by simpa using hβ₀), hβ, zero_mul] + obtain ⟨p, hp⟩ := exists_divisorZeroIndex_val_eq_of_zero hf hfne + (Complex.ofReal_ne_zero.mpr hβ₀.ne') hzeroβ + have hsummable := (conductorCompletedL_abs_reciprocal_summable χ hχ hχ₁ hsum hs).1.of_abs + have hle := hsummable.le_tsum p (fun j _ => by + have hj := conductorCompletedL_divisorIndex_re_mem_Ioo χ hχ hχ₁ j + simp only [one_div, Complex.inv_re, Complex.sub_re, Complex.ofReal_re] + exact div_nonneg (by linarith) (Complex.normSq_nonneg _)) + simpa only [hp, ← Complex.ofReal_sub, one_div, ← Complex.ofReal_inv, + Complex.ofReal_re] using hle + +end WeightedTorusJets +namespace WeightedTorusJets + +open _root_.Erdos970.Complex DirichletCharacter _root_.Erdos970.Complex.Hadamard + +theorem conductorCompletedL_zero_sum_absolutely_summable {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) + {s : ℝ} (hs : 1 < s) : + Summable (fun p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ => + |(1 / ((s : ℂ) - divisorZeroIndex₀Val p)).re|) := + (conductorCompletedL_abs_reciprocal_summable χ hχ hχ1 + (conductorCompletedL_zeroIndex_summable_inv_sq χ hχ hχ1) hs).1 + +theorem real_logDeriv_conductorCompletedL_eq_divisor_tsum_source {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) + (hquad : χ.IsQuadratic) {s : ℝ} (hs : 1 < s) : + (logDeriv (conductorCompletedL χ) (s : ℂ)).re = + ∑' p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ, + (1 / ((s : ℂ) - divisorZeroIndex₀Val p)).re := by + obtain ⟨B, hB⟩ := conductorCompletedL_logDeriv_hasSum χ hχ hχ1 + apply real_logDeriv_conductorCompletedL_eq_divisor_tsum hχ hχ1 hquad B _ hB hs + exact (summable_abs_reciprocal_re divisorZeroIndex₀Val + (fun p => let h := conductorCompletedL_zeroIndex_re_mem_Ioo χ hχ hχ1 p + ⟨h.1.le, h.2.le⟩) + (conductorCompletedL_zeroIndex_summable_inv_sq χ hχ hχ1)).of_abs + +theorem real_zero_le_conductorCompletedL_logDeriv {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsPrimitive) (hχ1 : χ ≠ 1) + (hquad : χ.IsQuadratic) {β s : ℝ} (hβ0 : 0 < β) + (hβ : LFunction χ (β : ℂ) = 0) (hs : 1 < s) : + 1 / (s - β) ≤ (logDeriv (conductorCompletedL χ) (s : ℂ)).re := by + rw [real_logDeriv_conductorCompletedL_eq_divisor_tsum_source χ hχ hχ1 hquad hs] + exact real_zero_le_divisor_reciprocal_tsum χ hχ hχ1 + (conductorCompletedL_zeroIndex_summable_inv_sq χ hχ hχ1) hβ0 hβ hs + +end WeightedTorusJets + +end +section + +open Filter Set +open scoped Topology + +namespace WeightedTorusJets + +lemma analyticAt_Gamma_of_re_pos {s : ℂ} (hs : 0 < s.re) : + AnalyticAt ℂ Complex.Gamma s := by + have hd : DifferentiableOn ℂ Complex.Gamma {z : ℂ | 0 < z.re} := by + intro z hz + refine (Complex.differentiableAt_Gamma z ?_).differentiableWithinAt + intro m hm + have hre := congrArg Complex.re hm + simp only [Complex.neg_re, Complex.natCast_re] at hre + have hn : (0 : ℝ) ≤ m := Nat.cast_nonneg m + have hzpos : 0 < z.re := hz + linarith + exact hd.analyticAt ((Complex.continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds hs) + +theorem exists_bound_Gamma_logDeriv_parity : + ∃ C : ℝ, 0 < C ∧ ∀ s ε : ℝ, 1 < s → s ≤ 2 → (ε = 0 ∨ ε = 1) → + ‖logDeriv Complex.Gamma (((s + ε) / 2 : ℝ) : ℂ)‖ ≤ C := by + have hc : ContinuousOn (fun t : ℝ ↦ logDeriv Complex.Gamma (t : ℂ)) + (Icc (1 / 2) (3 / 2)) := by + intro t ht + have htpos : 0 < t := by linarith [ht.1] + have ha := analyticAt_Gamma_of_re_pos (s := (t : ℂ)) (by simpa using htpos) + exact ((ha.deriv.continuousAt.div ha.continuousAt + (Complex.Gamma_ne_zero_of_re_pos (by simpa using htpos))).comp + Complex.continuous_ofReal.continuousAt).continuousWithinAt + obtain ⟨C, hC⟩ := isCompact_Icc.exists_bound_of_continuousOn hc + refine ⟨max C 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), ?_⟩ + intro s ε hs hs2 hε + apply (hC ((s + ε) / 2) ?_).trans (le_max_left _ _) + rcases hε with rfl | rfl <;> constructor <;> linarith + +end WeightedTorusJets + +end +section + +open scoped Classical + +namespace WeightedTorusJets + +theorem character_parity_parameter {q : ℕ} (χ : DirichletCharacter ℂ q) : + (1 - χ (-1)) / 2 = if χ.Even then (0 : ℂ) else 1 := by + rcases χ.even_or_odd with h | h + · simp [h, show χ (-1) = 1 from h] + · simp [h.not_even, show χ (-1) = -1 from h] + +theorem character_parity_parameter_real {q : ℕ} (χ : DirichletCharacter ℂ q) : + (1 - (χ (-1)).re) / 2 = if χ.Even then (0 : ℝ) else 1 := by + rcases χ.even_or_odd with h | h + · simp [h, show χ (-1) = 1 from h] + · simp [h.not_even, show χ (-1) = -1 from h] + +theorem character_gamma_argument_mem_Icc {q : ℕ} (χ : DirichletCharacter ℂ q) + {s : ℝ} (hs : 1 < s) (hs₂ : s ≤ 2) : + (s + (1 - (χ (-1)).re) / 2) / 2 ∈ Set.Icc (1 / 2 : ℝ) (3 / 2 : ℝ) := by + rw [character_parity_parameter_real] + split_ifs <;> constructor <;> linarith + +end WeightedTorusJets + +end +section +namespace WeightedTorusJets + +theorem logDeriv_GammaR_add {s a : ℂ} (hs : 0 < (s + a).re) : + logDeriv (fun z : ℂ => Complex.Gammaℝ (z + a)) s = + -Complex.log (Real.pi : ℂ) / 2 + logDeriv Complex.Gamma ((s + a) / 2) / 2 := by + have hpi : (Real.pi : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr Real.pi_ne_zero + have hp : (Real.pi : ℂ) ^ (-(s + a) / 2) ≠ 0 := + Complex.cpow_ne_zero_iff.mpr (.inl hpi) + have hgpos : 0 < ((s + a) / 2).re := by + simpa only [Complex.div_ofNat_re] using half_pos hs + have hg := (analyticAt_Gamma_of_re_pos hgpos).differentiableAt + have hgn : Complex.Gamma ((s + a) / 2) ≠ 0 := + Complex.Gamma_ne_zero_of_re_pos hgpos + have hpow : HasDerivAt (fun z : ℂ => (Real.pi : ℂ) ^ (-(z + a) / 2)) + ((Real.pi : ℂ) ^ (-(s + a) / 2) * Complex.log (Real.pi : ℂ) * (-1 / 2)) s := by + simpa only [id_eq, Pi.neg_apply] using + (((hasDerivAt_id s).add_const a).neg.div_const (2 : ℂ)).const_cpow (Or.inl hpi) + have harg : HasDerivAt (fun z : ℂ => (z + a) / 2) (1 / 2) s := + ((hasDerivAt_id s).add_const a).div_const (2 : ℂ) + change logDeriv (fun z : ℂ => (Real.pi : ℂ) ^ (-(z + a) / 2) * + Complex.Gamma ((z + a) / 2)) s = _ + rw [logDeriv_fun_mul (f := fun z : ℂ => (Real.pi : ℂ) ^ (-(z + a) / 2)) + (g := fun z : ℂ => Complex.Gamma ((z + a) / 2)) s hp hgn hpow.differentiableAt + (hg.comp s harg.differentiableAt)] + rw [logDeriv_apply, hpow.deriv] + rw [logDeriv_fun_comp (f := Complex.Gamma) (g := fun z : ℂ => (z + a) / 2) + hg harg.differentiableAt, harg.deriv] + field_simp + +theorem gammaFactor_logDeriv_real_parity {q : ℕ} (χ : DirichletCharacter ℂ q) + {s : ℝ} (hs : 0 < s) : + logDeriv χ.gammaFactor (s : ℂ) = + -Complex.log (Real.pi : ℂ) / 2 + + logDeriv Complex.Gamma (((s + (1 - (χ (-1)).re) / 2) / 2 : ℝ) : ℂ) / 2 := by + classical + rw [character_parity_parameter_real] + by_cases hχ : χ.Even + · have hf : χ.gammaFactor = Complex.Gammaℝ := funext hχ.gammaFactor_def + rw [hf] + simpa only [hχ, ite_true, add_zero, Complex.ofReal_div, Complex.ofReal_ofNat] using + logDeriv_GammaR_add (s := (s : ℂ)) (a := 0) (by simpa using hs) + · have hf : χ.gammaFactor = (fun z : ℂ => Complex.Gammaℝ (z + 1)) := by + funext z + simp [DirichletCharacter.gammaFactor, hχ] + rw [hf] + simpa only [hχ, ite_false, Complex.ofReal_div, Complex.ofReal_add, + Complex.ofReal_one, Complex.ofReal_ofNat] using + logDeriv_GammaR_add (s := (s : ℂ)) (a := 1) (by simp; linarith) + +theorem conductor_gamma_correction_real {q : ℕ} (hq : q ≠ 0) + (χ : DirichletCharacter ℂ q) {s : ℝ} (hs : 0 < s) : + (Complex.log (q : ℂ) / 2 + logDeriv χ.gammaFactor (s : ℂ)).re = + Real.log ((q : ℝ) / Real.pi) / 2 + + (logDeriv Complex.Gamma (((s + (1 - (χ (-1)).re) / 2) / 2 : ℝ) : ℂ)).re / 2 := by + rw [gammaFactor_logDeriv_real_parity χ hs] + rw [Complex.add_re, Complex.add_re, Complex.div_ofNat_re, Complex.div_ofNat_re, + Complex.div_ofNat_re, Complex.neg_re, ← Complex.ofReal_natCast, + Complex.log_ofReal_re, Complex.log_ofReal_re] + rw [Real.log_div (Nat.cast_ne_zero.mpr hq) Real.pi_ne_zero] + ring + +theorem exists_bound_gammaFactor_logDeriv : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) (χ : DirichletCharacter ℂ q), + ∀ s : ℝ, 1 < s → s ≤ 2 → ‖logDeriv χ.gammaFactor (s : ℂ)‖ ≤ C := by + obtain ⟨C, hC, hbound⟩ := exists_bound_Gamma_logDeriv_parity + refine ⟨‖Complex.log (Real.pi : ℂ)‖ / 2 + C / 2, by positivity, ?_⟩ + intro q χ s hs hs2 + have heps : (1 - (χ (-1)).re) / 2 = 0 ∨ (1 - (χ (-1)).re) / 2 = 1 := by + rw [character_parity_parameter_real] + split_ifs <;> simp + have hg := hbound s ((1 - (χ (-1)).re) / 2) hs hs2 heps + rw [gammaFactor_logDeriv_real_parity χ (by linarith)] + calc + _ ≤ ‖-Complex.log (Real.pi : ℂ) / 2‖ + + ‖logDeriv Complex.Gamma (((s + (1 - (χ (-1)).re) / 2) / 2 : ℝ) : ℂ) / 2‖ := + norm_add_le _ _ + _ = ‖Complex.log (Real.pi : ℂ)‖ / 2 + + ‖logDeriv Complex.Gamma (((s + (1 - (χ (-1)).re) / 2) / 2 : ℝ) : ℂ)‖ / 2 := by + simp only [norm_div, norm_neg, Complex.norm_ofNat] + _ ≤ _ := by linarith + +theorem exists_upper_bound_conductor_gammaFactor_logDeriv : + ∃ K : ℝ, 0 < K ∧ ∀ (q : ℕ), 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + ∀ s : ℝ, 1 < s → s ≤ 2 → + (Complex.log (q : ℂ) / 2 + logDeriv χ.gammaFactor (s : ℂ)).re ≤ + K * Real.log q := by + obtain ⟨C, hC, hbound⟩ := exists_bound_gammaFactor_logDeriv + refine ⟨C + 1, by linarith, ?_⟩ + intro q hq χ s hs hs2 + have hqR : (3 : ℝ) ≤ q := by exact_mod_cast hq + have hlogq : 1 < Real.log q := + (Real.lt_log_iff_exp_lt (by linarith)).mpr (Real.exp_one_lt_three.trans_le hqR) + have hg : (logDeriv χ.gammaFactor (s : ℂ)).re ≤ C := + (Complex.re_le_norm _).trans (hbound q χ s hs hs2) + rw [Complex.add_re, Complex.div_ofNat_re, ← Complex.ofReal_natCast, + Complex.log_ofReal_re] + nlinarith + +end WeightedTorusJets +end +section + +open Filter Set +open scoped Topology + +namespace WeightedTorusJets + +lemma riemannZeta₁_ne_zero_of_one_le_re {s : ℂ} (hs : 1 ≤ s.re) : + riemannZeta₁ s ≠ 0 := by + rcases eq_or_ne s 1 with rfl | hne + · simp + · intro hz + have h := riemannZeta_ne_zero_of_one_le_re hs + rw [riemannZeta_eq_inv_sub_mul hne, hz, mul_zero] at h + exact h rfl + +lemma logDeriv_riemannZeta₁ {s : ℂ} (hs : 1 < s.re) : + logDeriv riemannZeta₁ s = 1 / (s - 1) + logDeriv riemannZeta s := by + have hne : s ≠ 1 := by intro h; simp [h] at hs + have hz := riemannZeta₁_ne_zero_of_one_le_re hs.le + rw [logDeriv_apply, logDeriv_apply, + deriv_riemannZeta_eq_neg_inv_sub_sq_mul_add hne, riemannZeta_eq_inv_sub_mul hne] + field_simp + ring + +theorem exists_bound_zeta_logDeriv : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℝ, 1 < s → s ≤ 2 → + ‖-logDeriv riemannZeta (s : ℂ) - 1 / ((s : ℂ) - 1)‖ ≤ C := by + have hc : ContinuousOn (fun s : ℝ ↦ logDeriv riemannZeta₁ (s : ℂ)) (Icc 1 2) := by + intro s hs + have ha := differentiable_riemannZeta₁.analyticAt (s : ℂ) + exact ((ha.deriv.continuousAt.div ha.continuousAt + (riemannZeta₁_ne_zero_of_one_le_re (by simpa using hs.1))).comp + Complex.continuous_ofReal.continuousAt).continuousWithinAt + obtain ⟨C, hC⟩ := isCompact_Icc.exists_bound_of_continuousOn hc + refine ⟨max C 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), ?_⟩ + intro s hs hs2 + have heq : -logDeriv riemannZeta (s : ℂ) - 1 / ((s : ℂ) - 1) = + -logDeriv riemannZeta₁ (s : ℂ) := by + rw [logDeriv_riemannZeta₁ (by simpa using hs)] + ring + rw [heq, norm_neg] + exact (hC s ⟨hs.le, hs2⟩).trans (le_max_left _ _) + +theorem exists_upper_bound_zeta_logDeriv_re : + ∃ C : ℝ, 0 < C ∧ ∀ s : ℝ, 1 < s → s ≤ 2 → + (-logDeriv riemannZeta (s : ℂ)).re ≤ 1 / (s - 1) + C := by + obtain ⟨C, hC, hbound⟩ := exists_bound_zeta_logDeriv + refine ⟨C, hC, ?_⟩ + intro s hs hs2 + have h := (Complex.re_le_norm _).trans (hbound s hs hs2) + have heq : (1 / ((s : ℂ) - 1)).re = 1 / (s - 1) := by + rw [← Complex.ofReal_one, ← Complex.ofReal_sub, ← Complex.ofReal_div, + Complex.ofReal_re] + rw [Complex.sub_re, heq] at h + linarith + +end WeightedTorusJets +end +section +namespace WeightedTorusJets + +theorem conductorCompletedL_logDeriv_decomposition {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) {s : ℂ} (hs : 1 < s.re) : + logDeriv (conductorCompletedL χ) s = logDeriv (DirichletCharacter.LFunction χ) s + + (Complex.log (q : ℂ) / 2 + logDeriv χ.gammaFactor s) := by + classical + have hs0 : 0 < s.re := by linarith + have hgn := gammaFactor_ne_zero_of_re_pos χ hs0 + have hinv : Differentiable ℂ (fun z => (χ.gammaFactor z)⁻¹) := by + rcases χ.even_or_odd with heven | hodd + · convert Complex.differentiable_Gammaℝ_inv using 1 + funext z + rw [heven.gammaFactor_def] + · convert Complex.differentiable_Gammaℝ_inv.comp (differentiable_id.add_const 1) using 1 + funext z + rw [hodd.gammaFactor_def] + rfl + have hgamma : DifferentiableAt ℂ χ.gammaFactor s := by + convert (hinv s).inv (inv_ne_zero hgn) using 1 + funext z + exact (inv_inv (χ.gammaFactor z)).symm + have heq : DirichletCharacter.completedLFunction χ =ᶠ[nhds s] + fun z => DirichletCharacter.LFunction χ z * χ.gammaFactor z := by + have hU : {z : ℂ | 0 < z.re} ∈ nhds s := + (Complex.continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds hs0 + filter_upwards [hU] with z hz using completedL_eq_mul_gammaFactor χ hz + have hl := (logDeriv_congr_nhds heq).eq_of_nhds + rw [conductorCompletedL_logDeriv χ hχ + (completedL_ne_zero_of_one_le_re χ hχ hs.le), hl] + rw [logDeriv_fun_mul s + (DirichletCharacter.LFunction_ne_zero_of_one_le_re χ (.inl hχ) hs.le) hgn + (DirichletCharacter.differentiable_LFunction hχ s) hgamma] + ring + +theorem logDeriv_upper_of_completedL_lower : + ∃ K : ℝ, 0 < K ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → ∀ s β : ℝ, 1 < s → s ≤ 2 → + 1 / (s - β) ≤ (logDeriv (conductorCompletedL χ) (s : ℂ)).re → + (-logDeriv riemannZeta (s : ℂ) - + logDeriv (DirichletCharacter.LFunction χ) (s : ℂ)).re ≤ + K * Real.log q + 1 / (s - 1) - 1 / (s - β) := by + obtain ⟨Kg, hKg, hgamma⟩ := exists_upper_bound_conductor_gammaFactor_logDeriv + obtain ⟨Cz, hCz, hzeta⟩ := exists_upper_bound_zeta_logDeriv_re + refine ⟨Kg + Cz, by linarith, ?_⟩ + intro q _ hq χ hχ s β hs hs2 hzero + have hqR : (3 : ℝ) ≤ q := by exact_mod_cast hq + have hlogq : 1 < Real.log q := + (Real.lt_log_iff_exp_lt (by linarith)).mpr (Real.exp_one_lt_three.trans_le hqR) + have hdecomp := congrArg Complex.re + (conductorCompletedL_logDeriv_decomposition χ hχ (s := (s : ℂ)) (by simpa using hs)) + rw [Complex.add_re] at hdecomp + have hg := hgamma q hq χ s hs hs2 + have hz := hzeta s hs hs2 + rw [Complex.sub_re] + nlinarith + +end WeightedTorusJets +end + +end AnalyticAssemblyScope +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/RealZeroUniformMasterBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RealZeroUniformMasterBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..d853ed8f52984f593c690cceb99a6decb4e6efcb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RealZeroUniformMasterBound.lean @@ -0,0 +1,99 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.CharacterGlobalGreedyDeterminantMasterBounds +import OAI.NumberTheory.Jacobsthal.Siegel.GlobalWeightSortedJetEquiv +import OAI.NumberTheory.Jacobsthal.Siegel.NotEventuallyMaster +import OAI.NumberTheory.Jacobsthal.Siegel.QuadraticEigencharacter + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +end WeightedTorusJets + +end + +section +namespace WeightedTorusJets + +open scoped BigOperators NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_real_zero_uniform_master_bound : + ∃ C : ℝ, 0 < C ∧ ∀ H : ℕ, 86713344 ≤ H → ∃ CH : ℝ, + ∀ (q : ℕ) [NeZero q], 3 ≤ q → q ≠ 8 → + ∀ χ : DirichletCharacter ℂ q, + (∀ x : ZMod q, (χ x).im = 0) → χ.IsPrimitive → χ ≠ 1 → + ∀ β : ℝ, 0 < β → β < 1 → DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ N : ℕ, H ≤ N → 18818 ≤ N → + let U : ℝ := (N : ℝ) ^ (4 / 3 : ℝ) + let D : ℝ := (H : ℝ) ^ (2 / 3 : ℝ) / (4 * 97 ^ 2) + 1 ≤ 13 / 16 + (C + 13 / 24) * (Real.log (q : ℝ) / Real.log U) + + C * ((1 - β) * Real.log (q : ℝ)) * (Real.log U / Real.log (q : ℝ)) + + (CH + 13 / 12 * Real.log 8) / Real.log U + + C / (D * Real.log U) + 3 / (2 * D * U) := by + classical + obtain ⟨C, hC, _hC4, CH, hsource⟩ := + source_character_global_greedy_determinant_master_bounds + refine ⟨C, hC, ?_⟩ + intro H hH + have hHnat : 0 < H := by omega + obtain ⟨e, he⟩ := exists_global_weight_sorted_jet_equiv H hHnat + refine ⟨CH H, ?_⟩ + intro q _ hq hq8 χ hreal hprim hne + have hfield := characterField_ne_sourceSqrtTwoField_of_ne_eight q χ hprim + (real_character_isQuadratic χ hreal) hne hq8 + obtain ⟨d, a, b, _hd, _hdsize, _hddiv, _hdns, _ha, _hb, _hfield, _hdisc, + _hfund, _hformula, v, _hv, _hint, _hdegree, σ, τ, _hσa, _hσb, _hτa, _hτb, + _hcard, _hall, _hcomm, hdata⟩ := hsource q χ hreal hprim hne hfield + intro β hβ0 hβ1 hzero N hHN hN U D + let n : Fin (N ^ 4) ≃ (Fin 4 → Fin N) := + (Fintype.equivFinOfCardEq (by simp : Fintype.card (Fin 4 → Fin N) = N ^ 4)).symm + obtain ⟨g, α, _hg, _hα, hrange, _hmono, _hweight, _hstable, + Δ, _hΔ, _hΔne, harch, _hdiv, _hraw, hfinite, hlarge⟩ := hdata N H hHnat hHN n e he + obtain ⟨hpivot₁, hpivot₂, _hSpos, _hmaster⟩ := hlarge hN + have hS₁eq := sum_embedding_eq_sum_finset_of_range α _ hrange (fun a => (a 0 : ℝ)) + have hS₂eq := sum_embedding_eq_sum_finset_of_range α _ hrange + (fun a => ((a 1 : ℝ) + a 2)) + rw [← hS₁eq] at hpivot₁ + rw [← hS₂eq] at hpivot₂ + have hNpos : (0 : ℝ) < N := by exact_mod_cast hHnat.trans_le hHN + have hM : 0 < (N : ℝ) ^ 4 := pow_pos hNpos _ + have hUone : 1 < U := Real.one_lt_rpow + (by exact_mod_cast (show 1 < N by omega)) (by norm_num) + have hD : 0 < D := by dsimp [D]; positivity + have hS₁ : D * (N : ℝ) ^ 4 * U ≤ ∑ i, (α i 0 : ℝ) := by + convert hpivot₁ using 1 + dsimp [D, U] + ring + have hratio : (∑ i, ((α i 1 : ℝ) + α i 2)) / (∑ i, (α i 0 : ℝ)) ≤ 1 / 12 := + pivot_ratio_le_one_twelfth (H := (H : ℝ)) (M := (N : ℝ) ^ 4) (U := U) + (by exact_mod_cast hH) hM (zero_lt_one.trans hUone) + (by simpa only [U] using hpivot₁) + (by simpa only [U, neg_div] using hpivot₂) + have hlower := hfinite β hβ0 hβ1 hzero U (zero_lt_one.trans hUone).le + have hlogM : Real.log ((N : ℝ) ^ 4) = 3 * Real.log U := + log_degree_four_eq_three_log_scale hNpos + have hlogN : Real.log (N : ℝ) = 3 / 4 * Real.log U := + log_eq_three_quarters_log_scale hNpos + apply FinalComparison.uniform_master_bound hM hUone + (Real.log_pos (by exact_mod_cast (show 1 < q by omega))) hD hC.le hS₁ hratio hlogM + ?_ hlower + simpa only [hlogN] using harch + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/RectangleThreshold.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RectangleThreshold.lean new file mode 100644 index 0000000000000000000000000000000000000000..c08344262a21465cf95eed3c2947a6c0b5111727 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RectangleThreshold.lean @@ -0,0 +1,612 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.NormalizationPresentationLocalEquiv +import OAI.NumberTheory.Jacobsthal.Siegel.TorusEvalOne + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open scoped BigOperators +open scoped BigOperators +namespace WeightedTorusJets.Geometry + +noncomputable def rectangleThreshold (H N : ℝ) (j : Fin 3) : ℝ := + 32 * H ^ (if j = 0 then (2 / 3 : ℝ) else (-1 / 3 : ℝ)) * N ^ (4 / 3 : ℝ) + +lemma rectangleThreshold_pos {H N : ℝ} (hH : 0 < H) (hN : 0 < N) (j : Fin 3) : + 0 < rectangleThreshold H N j := by + unfold rectangleThreshold + positivity + +lemma short_side_lower {H N : ℝ} (hH : 0 < H) (hHN : H ≤ N) : + N ≤ H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ) := by + have hN : 0 < N := lt_of_lt_of_le hH hHN + have hp : N ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ) = N := by + rw [← Real.rpow_add hN] + norm_num + calc + N = N ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ) := hp.symm + _ ≤ H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ) := + mul_le_mul_of_nonneg_right + (Real.rpow_le_rpow_of_nonpos hH hHN (by norm_num : (-1 / 3 : ℝ) ≤ 0)) + (Real.rpow_nonneg hN.le _) + +lemma short_side_le_threshold {H N : ℝ} (hH : 1 ≤ H) (hN : 0 ≤ N) (j : Fin 3) : + 8 * H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ) ≤ rectangleThreshold H N j / 4 := by + have he : H ^ (-1 / 3 : ℝ) ≤ + H ^ (if j = 0 then (2 / 3 : ℝ) else (-1 / 3 : ℝ)) := by + apply Real.rpow_le_rpow_of_exponent_le hH + split_ifs <;> norm_num + have hm := mul_le_mul_of_nonneg_right he (Real.rpow_nonneg hN (4 / 3 : ℝ)) + unfold rectangleThreshold + linarith + +theorem rectangle_floor_product_gt_short_power {H N : ℝ} (hH : 1 ≤ H) (hN : 0 < N) + (I : Finset (Fin 3)) (hI : I.Nonempty) : + (8 * H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ)) ^ I.card < + ∏ j ∈ I, ((⌊rectangleThreshold H N j / 4⌋₊ : ℝ) + 1) := by + have hp := Finset.prod_lt_prod_of_nonempty₀ + (s := I) (f := fun _ ↦ 8 * H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ)) + (g := fun j ↦ ((⌊rectangleThreshold H N j / 4⌋₊ : ℝ) + 1)) + (fun _ _ ↦ by have : 0 < H := lt_of_lt_of_le zero_lt_one hH; positivity) + (fun j _ ↦ (short_side_le_threshold hH hN.le j).trans_lt (Nat.lt_floor_add_one _)) hI + simpa using hp + +lemma rectangleThreshold_product {H N : ℝ} (hH : 0 < H) (hN : 0 < N) : + (∏ j : Fin 3, rectangleThreshold H N j / 4) = 8 ^ 3 * N ^ 4 := by + have hhp : H ^ (2 / 3 : ℝ) * H ^ (-1 / 3 : ℝ) * H ^ (-1 / 3 : ℝ) = 1 := by + rw [← Real.rpow_add hH, ← Real.rpow_add hH] + norm_num + have hnp : (N ^ (4 / 3 : ℝ)) ^ 3 = N ^ 4 := by + rw [← Real.rpow_mul_natCast hN.le] + norm_num + rw [Fin.prod_univ_three] + simp only [rectangleThreshold, ↓reduceIte, Fin.isValue, one_ne_zero, show (2 : Fin 3) ≠ 0 by decide] + calc + _ = 8 ^ 3 * (H ^ (2 / 3 : ℝ) * H ^ (-1 / 3 : ℝ) * H ^ (-1 / 3 : ℝ)) * + (N ^ (4 / 3 : ℝ)) ^ 3 := by ring + _ = 8 ^ 3 * N ^ 4 := by rw [hhp, hnp]; ring + +theorem rectangle_floor_product_gt {H N : ℝ} (hH : 1 ≤ H) (hHN : H ≤ N) + {h : ℕ} (hh : 1 ≤ h) (hh4 : h ≤ 4) (I : Finset (Fin 3)) + (hI : I.card = min h 3) : + (4 * N) ^ h < ∏ j ∈ I, ((⌊rectangleThreshold H N j / 4⌋₊ : ℝ) + 1) := by + have hHp : 0 < H := lt_of_lt_of_le zero_lt_one hH + have hNp : 0 < N := lt_of_lt_of_le hHp hHN + have hIne : I.Nonempty := Finset.card_pos.mp (by omega) + by_cases hh3 : h ≤ 3 + · have hIc : I.card = h := by omega + have hprod : (8 * N) ^ h < + ∏ j ∈ I, ((⌊rectangleThreshold H N j / 4⌋₊ : ℝ) + 1) := by + have hp := rectangle_floor_product_gt_short_power hH hNp I hIne + rw [hIc] at hp + have hs : 8 * N ≤ 8 * H ^ (-1 / 3 : ℝ) * N ^ (4 / 3 : ℝ) := by + have := short_side_lower hHp hHN + linarith + exact (pow_le_pow_left₀ (by positivity) hs h).trans_lt hp + exact (pow_lt_pow_left₀ (by nlinarith : 4 * N < 8 * N) (by positivity) + (by omega : h ≠ 0)).trans hprod + · have heq : h = 4 := by omega + subst h + have hIu : I = Finset.univ := I.eq_univ_of_card (by simpa using hI) + subst I + have hp := Finset.prod_lt_prod_of_nonempty₀ + (s := (Finset.univ : Finset (Fin 3))) + (f := fun j ↦ rectangleThreshold H N j / 4) + (g := fun j ↦ ((⌊rectangleThreshold H N j / 4⌋₊ : ℝ) + 1)) + (fun j _ ↦ div_pos (rectangleThreshold_pos hHp hNp j) (by norm_num)) + (fun _ _ ↦ Nat.lt_floor_add_one _) (by simp) + rw [rectangleThreshold_product hHp hNp] at hp + have hn4 : 0 < N ^ 4 := pow_pos hNp _ + nlinarith + +theorem rectangle_floor_product_gt_nat {H N : ℕ} (hH : 1 ≤ H) (hHN : H ≤ N) + {h : ℕ} (hh : 1 ≤ h) (hh4 : h ≤ 4) (I : Finset (Fin 3)) + (hI : I.card = min h 3) : + (4 * N) ^ h < ∏ j ∈ I, (⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊ + 1) := by + have hp := rectangle_floor_product_gt + (H := (H : ℝ)) (N := (N : ℝ)) (by exact_mod_cast hH) (by exact_mod_cast hHN) + hh hh4 I hI + exact_mod_cast hp + +theorem rectangle_jet_cutoff {H N : ℝ} (hH : 0 < H) (hN : 0 < N) + (j : Fin 3) {a b : ℕ} (hb : b ≤ 4) + (ha : a ≤ b * ⌊rectangleThreshold H N j / 4⌋₊) : + (a : ℝ) ≤ rectangleThreshold H N j := by + have ht := rectangleThreshold_pos hH hN j + have hf := Nat.floor_le (le_of_lt (div_pos ht (by norm_num : (0 : ℝ) < 4))) + have hab : (a : ℝ) ≤ 4 * (⌊rectangleThreshold H N j / 4⌋₊ : ℝ) := by + exact_mod_cast ha.trans (Nat.mul_le_mul_right _ hb) + linarith + +theorem rectangle_cutoff_lower {H N : ℕ} (hH : 1 ≤ H) (hHN : H ≤ N) (j : Fin 3) : + 8 * N + 1 ≤ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊ + 1 := by + apply Nat.succ_le_succ + apply Nat.le_floor + have hHr : (1 : ℝ) ≤ H := by exact_mod_cast hH + have hHNr : (H : ℝ) ≤ N := by exact_mod_cast hHN + have hs := short_side_lower (lt_of_lt_of_le zero_lt_one hHr) hHNr + have ht := short_side_le_threshold hHr (Nat.cast_nonneg N) j + push_cast + linarith + +theorem rectangle_cutoff_ge_nine {H N : ℕ} (hH : 1 ≤ H) (hHN : H ≤ N) (j : Fin 3) : + 9 ≤ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊ + 1 := by + have := rectangle_cutoff_lower hH hHN j + have hN : 1 ≤ N := hH.trans hHN + omega + + + +section TorusJetAssembly + +variable {K : Type*} [Field K] + +local notation "PolyRing" => MvPolynomial (Fin 4) K +local notation "torusCoordinateProduct" => (∏ i : Fin 4, (MvPolynomial.X i : PolyRing)) +local notation "TorusCoordRing" => Localization.Away torusCoordinateProduct + +theorem torus_mixed_derivatives_algebraMap (c : Fin 3 → Fin 4 → K) + (a : Fin 3 → ℕ) (F : PolyRing) : + ((localizeDerivation (T := TorusCoordRing) (Submonoid.powers torusCoordinateProduct) + (invariantDerivation (c 0))).toLinearMap ^ a 0) + (((localizeDerivation (T := TorusCoordRing) (Submonoid.powers torusCoordinateProduct) + (invariantDerivation (c 1))).toLinearMap ^ a 1) + (((localizeDerivation (T := TorusCoordRing) (Submonoid.powers torusCoordinateProduct) + (invariantDerivation (c 2))).toLinearMap ^ a 2) (algebraMap PolyRing TorusCoordRing F))) = + algebraMap PolyRing TorusCoordRing (invariantJet c a F) := by + simpa only [Module.End.pow_apply, Derivation.coeFn_coe, invariantJet] using + mixed_localizeDerivation_algebraMap (T := TorusCoordRing) (Submonoid.powers torusCoordinateProduct) + (fun j ↦ invariantDerivation (c j)) a F + +theorem torus_rectangleJetIdeal_le_identity {H N : ℕ} (hH : 1 ≤ H) (hHN : H ≤ N) + (c : Fin 3 → Fin 4 → K) (F : PolyRing) + (hvanish : ∀ a : Fin 3 → ℕ, + (∀ j, (a j : ℝ) ≤ rectangleThreshold (H : ℝ) (N : ℝ) j) → + MvPolynomial.eval (fun _ ↦ 1) (invariantJet c a F) = 0) + {b : ℕ} (hb : b ≤ 4) : + rectangleJetIdeal (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F)) + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) b ≤ + (torusIdentityPoint (K := K)).asIdeal := by + change _ ≤ RingHom.ker (torusEvalOne (K := K)) + apply rectangleJetIdeal_le_ker + (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F)) + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) + (torusEvalOne (K := K)) hb + intro a ha + rw [torusEvalOne_algebraMap] + apply hvanish a + intro j + exact rectangle_jet_cutoff + (by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one hH)) + (by exact_mod_cast (lt_of_lt_of_le Nat.zero_lt_one (hH.trans hHN))) + j le_rfl (ha j) + +theorem torus_rectangle_has_shared_minimal_prime {H N : ℕ} + (hH : 1 ≤ H) (hHN : H ≤ N) (c : Fin 3 → Fin 4 → K) (F : PolyRing) (hF : F ≠ 0) + (hvanish : ∀ a : Fin 3 → ℕ, + (∀ j, (a j : ℝ) ≤ rectangleThreshold (H : ℝ) (N : ℝ) j) → + MvPolynomial.eval (fun _ ↦ 1) (invariantJet c a F) = 0) : + let jet := fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F) + let t := fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊ + ∃ b ≤ 3, ∃ q : Ideal TorusCoordRing, q ≤ (torusIdentityPoint (K := K)).asIdeal ∧ + (rectangleJetIdeal jet t b).IsMinimalPrime q ∧ + (rectangleJetIdeal jet t (b + 1)).IsMinimalPrime q := by + have hu : torusCoordinateProduct ≠ 0 := Finset.prod_ne_zero_iff.mpr fun i _ ↦ MvPolynomial.X_ne_zero i + let : IsDomain TorusCoordRing := IsLocalization.isDomain_of_le_nonZeroDivisors TorusCoordRing + (powers_le_nonZeroDivisors_of_noZeroDivisors hu) + apply rectangleJets_have_shared_minimal_prime _ _ (torusIdentityPoint (K := K)) + · exact torus_rectangleJetIdeal_le_identity hH hHN c F hvanish le_rfl + · simpa only [invariantJet, Pi.zero_apply, Function.iterate_zero, id_eq] using + (torus_polynomial_ne_zero hF) + · exact four_variable_localization_ringKrullDim_le (Submonoid.powers torusCoordinateProduct) + +theorem torus_rectangle_shared_component_data {H N : ℕ} + (hH : 1 ≤ H) (hHN : H ≤ N) (c : Fin 3 → Fin 4 → K) + (F : PolyRing) (hF : F ≠ 0) + (hvanish : ∀ a : Fin 3 → ℕ, + (∀ j, (a j : ℝ) ≤ rectangleThreshold (H : ℝ) (N : ℝ) j) → + MvPolynomial.eval (fun _ ↦ 1) (invariantJet c a F) = 0) : + let jet := fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F) + let t := fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊ + ∃ b ≤ 3, ∃ q : PrimeSpectrum TorusCoordRing, + q.asIdeal ≤ (torusIdentityPoint (K := K)).asIdeal ∧ + (rectangleJetIdeal jet t b).IsMinimalPrime q.asIdeal ∧ + (rectangleJetIdeal jet t (b + 1)).IsMinimalPrime q.asIdeal ∧ + 1 ≤ Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal)) ∧ + Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal)) ≤ 4 := by + obtain ⟨b, hb, q, hqp, hqb, hqb'⟩ := + torus_rectangle_has_shared_minimal_prime hH hHN c F hF hvanish + have : q.IsPrime := hqb.isPrime + have hmem : algebraMap PolyRing TorusCoordRing F ∈ q := by + apply hqb.le + apply rectangleJetIdeal_mono _ _ (Nat.zero_le b) + rw [rectangleJetIdeal_zero] + apply Ideal.subset_span + simp only [Set.mem_singleton_iff, invariantJet, Pi.zero_apply, Function.iterate_zero, id_eq] + exact ⟨b, hb, ⟨q, hqb.isPrime⟩, hqp, hqb, hqb', + localization_component_cotangent_bounds (Submonoid.powers torusCoordinateProduct) q hF hmem⟩ + +end TorusJetAssembly + + + +noncomputable section + +variable {A : Type*} [CommRing A] [Algebra ℚ A] + +def coefficientDerivationLinear (σ : Type*) (D : Derivation ℚ A A) : + MvPolynomial σ A →ₗ[ℚ] MvPolynomial σ A := + (AddMonoidAlgebra.coeffLinearEquiv ℚ).symm.toLinearMap ∘ₗ + Finsupp.mapRange.linearMap D.toLinearMap ∘ₗ + (AddMonoidAlgebra.coeffLinearEquiv ℚ).toLinearMap + +theorem coefficientDerivationLinear_monomial (σ : Type*) (D : Derivation ℚ A A) + (d : σ →₀ ℕ) (a : A) : + coefficientDerivationLinear σ D (MvPolynomial.monomial d a) = + MvPolynomial.monomial d (D a) := by + classical + ext e + change D ((MvPolynomial.monomial d a).coeff e) = + (MvPolynomial.monomial d (D a)).coeff e + simp [MvPolynomial.coeff_monomial, apply_ite D] + +def coefficientDerivation (σ : Type*) (D : Derivation ℚ A A) : + Derivation ℚ (MvPolynomial σ A) (MvPolynomial σ A) where + toLinearMap := coefficientDerivationLinear σ D + map_one_eq_zero' := by + rw [MvPolynomial.one_def, coefficientDerivationLinear_monomial] + simp + leibniz' p q := by + induction p using MvPolynomial.induction_on' with + | add p r hp hr => + simp only [add_mul, map_add, hp, hr, smul_eq_mul] + ring + | monomial d a => + induction q using MvPolynomial.induction_on' with + | add q r hq hr => + simp only [mul_add, map_add, hq, hr, smul_eq_mul] + ring + | monomial e b => + simp only [MvPolynomial.monomial_mul_monomial, + coefficientDerivationLinear_monomial, Derivation.leibniz, smul_eq_mul, + map_add, add_comm e d] + +@[simp] theorem coefficientDerivation_coeff (σ : Type*) (D : Derivation ℚ A A) + (p : MvPolynomial σ A) (d : σ →₀ ℕ) : + (coefficientDerivation σ D p).coeff d = D (p.coeff d) := rfl + +@[simp] theorem coefficientDerivation_monomial (σ : Type*) (D : Derivation ℚ A A) + (d : σ →₀ ℕ) (a : A) : + coefficientDerivation σ D (MvPolynomial.monomial d a) = + MvPolynomial.monomial d (D a) := + coefficientDerivationLinear_monomial σ D d a + +@[simp] theorem coefficientDerivation_C (σ : Type*) (D : Derivation ℚ A A) (a : A) : + coefficientDerivation σ D (MvPolynomial.C a) = MvPolynomial.C (D a) := + coefficientDerivation_monomial σ D 0 a + +@[simp] theorem coefficientDerivation_X (σ : Type*) (D : Derivation ℚ A A) (i : σ) : + coefficientDerivation σ D (MvPolynomial.X i) = 0 := by + simp [MvPolynomial.X] + +theorem derivation_mem_span_of_vanishes (D : Derivation ℚ A A) (s : Set A) + (h : ∀ a ∈ s, D a = 0) {a : A} (ha : a ∈ Ideal.span s) : + D a ∈ Ideal.span s := by + induction ha using Submodule.span_induction with + | mem a ha => simp [h a ha] + | zero => simp + | add a b ha hb hda hdb => simpa using (Ideal.span s).add_mem hda hdb + | smul r a ha hda => + simpa only [Derivation.leibniz, smul_eq_mul] using + (Ideal.span s).add_mem ((Ideal.span s).mul_mem_left r hda) + ((Ideal.span s).mul_mem_right (D r) ha) + +def quotientDerivation (D : Derivation ℚ A A) (I : Ideal A) + (hI : ∀ a ∈ I, D a ∈ I) : Derivation ℚ (A ⧸ I) (A ⧸ I) := + Derivation.liftOfSurjective (f := Ideal.Quotient.mkₐ ℚ I) + (Ideal.Quotient.mkₐ_surjective ℚ I) + (fun a ha => Ideal.Quotient.eq_zero_iff_mem.mpr + (hI a (Ideal.Quotient.eq_zero_iff_mem.mp ha))) + +@[simp] theorem quotientDerivation_mk (D : Derivation ℚ A A) (I : Ideal A) + (hI : ∀ a ∈ I, D a ∈ I) (a : A) : + quotientDerivation D I hI (Ideal.Quotient.mk I a) = + Ideal.Quotient.mk I (D a) := by + unfold quotientDerivation + apply Derivation.liftOfSurjective_apply + +theorem quotientDerivation_pow_mk (D : Derivation ℚ A A) (I : Ideal A) + (hI : ∀ a ∈ I, D a ∈ I) (n : ℕ) (a : A) : + ((quotientDerivation D I hI).toLinearMap ^ n) (Ideal.Quotient.mk I a) = + Ideal.Quotient.mk I ((D.toLinearMap ^ n) a) := by + induction n with + | zero => rfl + | succ n ih => + simp only [pow_succ', Module.End.mul_apply, ih, Derivation.coeFn_coe, + quotientDerivation_mk] + +theorem coefficientDerivation_pow_monomial (σ : Type*) (D : Derivation ℚ A A) + (n : ℕ) (d : σ →₀ ℕ) (a : A) : + ((coefficientDerivation σ D).toLinearMap ^ n) (MvPolynomial.monomial d a) = + MvPolynomial.monomial d ((D.toLinearMap ^ n) a) := by + induction n with + | zero => rfl + | succ n ih => + simp only [pow_succ', Module.End.mul_apply, ih, Derivation.coeFn_coe, + coefficientDerivation_monomial] + +theorem coefficientDerivation_mem_rectangularIdeal (σ : Type*) + (k : σ → ℕ) (D : Derivation ℚ A A) {p : MvPolynomial σ A} + (hp : p ∈ rectangularIdeal k) : + coefficientDerivation σ D p ∈ rectangularIdeal k := by + apply derivation_mem_span_of_vanishes _ _ _ hp + rintro _ ⟨i, rfl⟩ + simp + +def rectangularCoefficientDerivation (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) : + Derivation ℚ (MvPolynomial σ A ⧸ rectangularIdeal k) + (MvPolynomial σ A ⧸ rectangularIdeal k) := + quotientDerivation (coefficientDerivation σ D) (rectangularIdeal k) + (fun _ hp => coefficientDerivation_mem_rectangularIdeal σ k D hp) + +@[simp] theorem rectangularCoefficientDerivation_mk (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (p : MvPolynomial σ A) : + rectangularCoefficientDerivation σ k D (Ideal.Quotient.mk (rectangularIdeal k) p) = + Ideal.Quotient.mk (rectangularIdeal k) (coefficientDerivation σ D p) := + quotientDerivation_mk _ _ _ p + +theorem rectangularCoefficientDerivation_X (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (i : σ) : + rectangularCoefficientDerivation σ k D + (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i)) = 0 := by + simp + +theorem rectangularCoefficientDerivation_pow_monomial (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (n : ℕ) (d : σ →₀ ℕ) (a : A) : + ((rectangularCoefficientDerivation σ k D).toLinearMap ^ n) + (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.monomial d a)) = + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial d ((D.toLinearMap ^ n) a)) := by + rw [rectangularCoefficientDerivation, quotientDerivation_pow_mk, + coefficientDerivation_pow_monomial] + +theorem rectangularVariable_pow_eq_zero {σ R : Type*} [CommRing R] + (k : σ → ℕ) (i : σ) : + (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i : MvPolynomial σ R)) ^ k i = + 0 := by + rw [← map_pow, Ideal.Quotient.eq_zero_iff_mem] + exact Ideal.subset_span ⟨i, rfl⟩ + +variable {σ R S : Type*} [CommRing R] [CommRing S] + +def rectangularMap (k : σ → ℕ) (f : R →+* S) : + (MvPolynomial σ R ⧸ rectangularIdeal k) →+* + (MvPolynomial σ S ⧸ rectangularIdeal k) := by + let g := (Ideal.Quotient.mk (rectangularIdeal k)).comp (MvPolynomial.map f) + apply Ideal.Quotient.lift (rectangularIdeal k) g + have hg : rectangularIdeal k ≤ RingHom.ker g := by + apply Ideal.span_le.mpr + rintro _ ⟨i, rfl⟩ + change g ((MvPolynomial.X i) ^ k i) = 0 + simp only [g, RingHom.comp_apply, map_pow, MvPolynomial.map_X] + exact rectangularVariable_pow_eq_zero k i + exact fun p hp => hg hp + +@[simp] theorem rectangularMap_mk (k : σ → ℕ) (f : R →+* S) (p : MvPolynomial σ R) : + rectangularMap k f (Ideal.Quotient.mk (rectangularIdeal k) p) = + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.map f p) := rfl + +theorem rectangularMap_monomial (k : σ → ℕ) (f : R →+* S) + (d : σ →₀ ℕ) (a : R) : + rectangularMap k f (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.monomial d a)) = + Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.monomial d (f a)) := by + simp + +end + + + +noncomputable section + +variable {A : Type*} [CommRing A] [Algebra ℚ A] + +def nilpotentDerivationExp (D : Derivation ℚ A A) + (hD : IsNilpotent D.toLinearMap) : A →ₐ[ℚ] A where + toFun := fun a => (IsNilpotent.exp D.toLinearMap : Module.End ℚ A) a + map_zero' := (IsNilpotent.exp D.toLinearMap : Module.End ℚ A).map_zero + map_add' := (IsNilpotent.exp D.toLinearMap : Module.End ℚ A).map_add + map_one' := by + simpa using IsNilpotent.exp_smul_eq_sum (a := D.toLinearMap) (m := (1 : A)) + (k := 1) (by simp) hD + map_mul' := Module.End.exp_mul_of_derivation ℚ A D.toLinearMap + (fun x y => by simp [smul_eq_mul, mul_comm]) hD + commutes' r := by + have hone : IsNilpotent.exp D.toLinearMap (1 : A) = 1 := by + simpa using IsNilpotent.exp_smul_eq_sum (a := D.toLinearMap) (m := (1 : A)) + (k := 1) (by simp) hD + rw [Algebra.algebraMap_eq_smul_one, map_smul, hone] + +theorem nilpotentDerivationExp_apply (D : Derivation ℚ A A) + {n : ℕ} (hD : D.toLinearMap ^ n = 0) (a : A) : + nilpotentDerivationExp D ⟨n, hD⟩ a = + ∑ i ∈ Finset.range n, (i.factorial : ℚ)⁻¹ • ((D.toLinearMap ^ i) a) := by + simp [nilpotentDerivationExp, IsNilpotent.exp_eq_sum hD] + +theorem scaledDerivation_pow_apply (D : Derivation ℚ A A) (u : A) + (hu : D u = 0) (n : ℕ) (a : A) : + ((u • D).toLinearMap ^ n) a = u ^ n * (D.toLinearMap ^ n) a := by + induction n with + | zero => simp + | succ n ih => + simp only [pow_succ', Module.End.mul_apply, Derivation.coeFn_coe, + Derivation.smul_apply, smul_eq_mul, ih, Derivation.leibniz, + Derivation.leibniz_pow, hu, smul_zero, mul_zero, add_zero] + ring + +theorem scaledDerivation_pow_eq_zero (D : Derivation ℚ A A) (u : A) + (hu : D u = 0) {n : ℕ} (hn : u ^ n = 0) : + (u • D).toLinearMap ^ n = 0 := by + ext a + change ((u • D).toLinearMap ^ n) a = 0 + rw [scaledDerivation_pow_apply D u hu, hn, zero_mul] + +def truncatedTaylor (D : Derivation ℚ A A) (u : A) + (hu : D u = 0) {n : ℕ} (hn : u ^ n = 0) : A →ₐ[ℚ] A := + nilpotentDerivationExp (u • D) ⟨n, scaledDerivation_pow_eq_zero D u hu hn⟩ + +theorem truncatedTaylor_apply (D : Derivation ℚ A A) (u : A) + (hu : D u = 0) {n : ℕ} (hn : u ^ n = 0) (a : A) : + truncatedTaylor D u hu hn a = + ∑ i ∈ Finset.range n, (i.factorial : ℚ)⁻¹ • (u ^ i * (D.toLinearMap ^ i) a) := by + rw [truncatedTaylor, nilpotentDerivationExp_apply (u • D) + (scaledDerivation_pow_eq_zero D u hu hn)] + simp only [scaledDerivation_pow_apply D u hu] + +theorem map_truncatedTaylor {B : Type*} [CommRing B] [Algebra ℚ B] + (f : A →+* B) (D : Derivation ℚ A A) (u : A) (hu : D u = 0) + {n : ℕ} (hn : u ^ n = 0) (hnpos : 0 < n) (hfu : f u = 0) (a : A) : + f (truncatedTaylor D u hu hn a) = f a := by + rw [truncatedTaylor_apply] + simp only [map_sum, map_rat_smul, map_mul, map_pow, hfu] + rw [Finset.sum_eq_single 0] + · simp + · intro b hb hb0 + simp [zero_pow hb0] + · intro h + exact False.elim (h (Finset.mem_range.mpr hnpos)) + +end + + + +noncomputable section + +variable {A : Type*} [CommRing A] [Algebra ℚ A] + +def rectangularTaylorAlong (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (i : σ) : + (MvPolynomial σ A ⧸ rectangularIdeal k) →ₐ[ℚ] + (MvPolynomial σ A ⧸ rectangularIdeal k) := + truncatedTaylor (rectangularCoefficientDerivation σ k D) + (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i)) + (rectangularCoefficientDerivation_X σ k D i) + (rectangularVariable_pow_eq_zero k i) + +theorem rectangularTaylorAlong_monomial (σ : Type*) (k : σ → ℕ) + (D : Derivation ℚ A A) (i : σ) (d : σ →₀ ℕ) (a : A) : + rectangularTaylorAlong σ k D i + (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.monomial d a)) = + ∑ n ∈ Finset.range (k i), (n.factorial : ℚ)⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial (Finsupp.single i n + d) ((D.toLinearMap ^ n) a)) := by + rw [rectangularTaylorAlong, truncatedTaylor_apply] + apply Finset.sum_congr rfl + intro n hn + rw [rectangularCoefficientDerivation_pow_monomial, + ← map_pow, ← map_mul, ← MvPolynomial.monomial_single_add] + +@[simp] theorem rectangularCoefficientDerivation_zero (σ : Type*) (k : σ → ℕ) : + rectangularCoefficientDerivation σ k (0 : Derivation ℚ A A) = 0 := by + apply Derivation.ext + intro p + obtain ⟨p, rfl⟩ := Ideal.Quotient.mk_surjective p + rw [rectangularCoefficientDerivation_mk] + have hp : coefficientDerivation σ (0 : Derivation ℚ A A) p = 0 := by + ext d + simp + simp [hp] + +@[simp] theorem rectangularTaylorAlong_zero (σ : Type*) (k : σ → ℕ) (i : σ) : + rectangularTaylorAlong σ k (0 : Derivation ℚ A A) i = AlgHom.id ℚ _ := by + ext p + simp [rectangularTaylorAlong, truncatedTaylor, nilpotentDerivationExp] + +def rectangularTaylorThree {B : Type*} [CommRing B] (σ : Type*) (k : σ → ℕ) + (D₁ D₂ D₃ : Derivation ℚ A A) (i₁ i₂ i₃ : σ) (f : A →+* B) : + A →+* (MvPolynomial σ B ⧸ rectangularIdeal k) := + (rectangularMap k f).comp + ((rectangularTaylorAlong σ k D₁ i₁).toRingHom.comp + ((rectangularTaylorAlong σ k D₂ i₂).toRingHom.comp + ((rectangularTaylorAlong σ k D₃ i₃).toRingHom.comp + ((Ideal.Quotient.mk (rectangularIdeal k)).comp MvPolynomial.C)))) + +theorem rectangularTaylorThree_apply {B : Type*} [CommRing B] [Algebra ℚ B] + (σ : Type*) (k : σ → ℕ) (D₁ D₂ D₃ : Derivation ℚ A A) + (i₁ i₂ i₃ : σ) (f : A →+* B) (a : A) : + rectangularTaylorThree σ k D₁ D₂ D₃ i₁ i₂ i₃ f a = + ∑ n₃ ∈ Finset.range (k i₃), ∑ n₂ ∈ Finset.range (k i₂), + ∑ n₁ ∈ Finset.range (k i₁), + (((n₃.factorial : ℚ)⁻¹ * (n₂.factorial : ℚ)⁻¹) * (n₁.factorial : ℚ)⁻¹) • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial + (Finsupp.single i₁ n₁ + (Finsupp.single i₂ n₂ + Finsupp.single i₃ n₃)) + (f ((D₁.toLinearMap ^ n₁) ((D₂.toLinearMap ^ n₂) ((D₃.toLinearMap ^ n₃) a))))) := by + simp only [rectangularTaylorThree, RingHom.comp_apply, AlgHom.toRingHom_eq_coe, + AlgHom.coe_toRingHom, MvPolynomial.C_apply] + simp only [rectangularTaylorAlong_monomial, map_sum, map_rat_smul, + rectangularMap_monomial, Finset.smul_sum, smul_smul, add_zero, mul_assoc] + +theorem rectangularTaylorThree_two_apply {B : Type*} [CommRing B] [Algebra ℚ B] + (σ : Type*) (k : σ → ℕ) (D₁ D₂ : Derivation ℚ A A) + (i₁ i₂ : σ) (f : A →+* B) (a : A) : + rectangularTaylorThree σ k D₁ D₂ 0 i₁ i₂ i₂ f a = + ∑ n₂ ∈ Finset.range (k i₂), ∑ n₁ ∈ Finset.range (k i₁), + ((n₂.factorial : ℚ)⁻¹ * (n₁.factorial : ℚ)⁻¹) • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial (Finsupp.single i₁ n₁ + Finsupp.single i₂ n₂) + (f ((D₁.toLinearMap ^ n₁) ((D₂.toLinearMap ^ n₂) a)))) := by + simp only [rectangularTaylorThree, RingHom.comp_apply, AlgHom.toRingHom_eq_coe, + AlgHom.coe_toRingHom, rectangularTaylorAlong_zero, AlgHom.id_apply, MvPolynomial.C_apply] + simp only [rectangularTaylorAlong_monomial, map_sum, map_rat_smul, + rectangularMap_monomial, Finset.smul_sum, smul_smul, add_zero] + +theorem rectangularTaylorThree_one_apply {B : Type*} [CommRing B] [Algebra ℚ B] + (σ : Type*) (k : σ → ℕ) (D : Derivation ℚ A A) (i : σ) + (f : A →+* B) (a : A) : + rectangularTaylorThree σ k D 0 0 i i i f a = + ∑ n ∈ Finset.range (k i), (n.factorial : ℚ)⁻¹ • + Ideal.Quotient.mk (rectangularIdeal k) + (MvPolynomial.monomial (Finsupp.single i n) (f ((D.toLinearMap ^ n) a))) := by + simp only [rectangularTaylorThree, RingHom.comp_apply, AlgHom.toRingHom_eq_coe, + AlgHom.coe_toRingHom, rectangularTaylorAlong_zero, AlgHom.id_apply, MvPolynomial.C_apply] + simp only [rectangularTaylorAlong_monomial, map_sum, map_rat_smul, + rectangularMap_monomial, add_zero] + +theorem rectangularTaylorThree_residue {B : Type*} [CommRing B] [Algebra ℚ B] + (σ : Type*) (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) + (D₁ D₂ D₃ : Derivation ℚ A A) (i₁ i₂ i₃ : σ) (f : A →+* B) + (ε : (MvPolynomial σ B ⧸ rectangularIdeal k) →+* B) + (hε : ∀ p, ε (Ideal.Quotient.mk (rectangularIdeal k) p) = MvPolynomial.constantCoeff p) + (a : A) : + ε (rectangularTaylorThree σ k D₁ D₂ D₃ i₁ i₂ i₃ f a) = f a := by + let g := ε.comp (rectangularMap k f) + have hg (i : σ) : g (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.X i)) = 0 := by + simp [g, hε] + have hstep (D : Derivation ℚ A A) (i : σ) (p) : + g (rectangularTaylorAlong σ k D i p) = g p := by + apply map_truncatedTaylor g _ _ _ _ (Nat.pos_of_ne_zero (hk i)) (hg i) + change g (rectangularTaylorAlong σ k D₁ i₁ + (rectangularTaylorAlong σ k D₂ i₂ + (rectangularTaylorAlong σ k D₃ i₃ + (Ideal.Quotient.mk (rectangularIdeal k) (MvPolynomial.C a))))) = f a + rw [hstep, hstep, hstep] + simp [g, hε] + +end + +end WeightedTorusJets.Geometry + +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/RectangularGradedPieceGeneratedByDegreeOne.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RectangularGradedPieceGeneratedByDegreeOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..ecc5eb7bc3cb60f9a6d3f54dfa07659ceb5e8dd8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RectangularGradedPieceGeneratedByDegreeOne.lean @@ -0,0 +1,72 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.TorusQuotientDimensionPosCotangentFinrankThree + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +open scoped Pointwise + +theorem rectangular_graded_piece_generated_by_degree_one {σ K : Type*} [CommRing K] + (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) (n : ℕ) : + let A := MvPolynomial σ K ⧸ rectangularIdeal k + let N : Ideal A := RingHom.ker (rectangularAugmentation k hk).toRingHom + Submodule.span K + ((fun x : ↥(N ^ n) => (Submodule.Quotient.mk x : idealPowLayer N n)) '' + {x : ↥(N ^ n) | (x : A) ∈ (N : Set A) ^ n}) = ⊤ := by + let A := MvPolynomial σ K ⧸ rectangularIdeal k + let ε : A →ₐ[K] K := rectangularAugmentation k hk + let N : Ideal A := RingHom.ker ε.toRingHom + let S : Set A := (N : Set A) ^ n + let U : Submodule K (idealPowLayer N n) := Submodule.span K + ((fun x : ↥(N ^ n) => (Submodule.Quotient.mk x : idealPowLayer N n)) '' + {x : ↥(N ^ n) | (x : A) ∈ S}) + have hspan : Submodule.span A S = N ^ n := (Submodule.pow_eq_span_pow_set N n).symm + have hscalar (a : A) (x : ↥(N ^ n)) : + (Submodule.Quotient.mk (a • x) : idealPowLayer N n) = + ε a • (Submodule.Quotient.mk x : idealPowLayer N n) := by + rw [← Submodule.Quotient.mk_smul, ← algebraMap_smul A (ε a) x] + apply (idealPowLayer_eq N n _ _).mpr + change a * (x : A) - algebraMap K A (ε a) * (x : A) ∈ (N ^ (n + 1) : Ideal A) + rw [← sub_mul] + rw [show (N ^ (n + 1) : Ideal A) = N * N ^ n from pow_succ' N n] + apply Ideal.mul_mem_mul _ x.property + change ε (a - algebraMap K A (ε a)) = 0 + simp + have hmem (a : A) (ha : a ∈ Submodule.span A S) : + ∀ h : a ∈ N ^ n, (Submodule.Quotient.mk ⟨a, h⟩ : idealPowLayer N n) ∈ U := by + induction ha using Submodule.span_induction with + | mem a ha => + intro h + exact Submodule.subset_span ⟨⟨a, h⟩, ha, rfl⟩ + | zero => + intro h + exact U.zero_mem + | add a b ha hb ia ib => + intro h + have haN : a ∈ N ^ n := hspan ▸ ha + have hbN : b ∈ N ^ n := hspan ▸ hb + exact U.add_mem (ia haN) (ib hbN) + | smul a b hb ih => + intro h + have hbN : b ∈ N ^ n := hspan ▸ hb + change (Submodule.Quotient.mk (a • (⟨b, hbN⟩ : ↥(N ^ n))) : idealPowLayer N n) ∈ U + rw [hscalar] + exact U.smul_mem (ε a) (ih hbN) + apply top_unique + intro z _ + obtain ⟨x, rfl⟩ := Submodule.Quotient.mk_surjective _ z + exact hmem x (hspan.symm ▸ x.property) x.property + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/ResidueTensorQuotientAlgEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ResidueTensorQuotientAlgEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..657a6a480dbcc46153150988a99a29a24dc5609c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/ResidueTensorQuotientAlgEquiv.lean @@ -0,0 +1,398 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.LocalFractionAlgebra + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open scoped BigOperators +open Module +open MvPolynomial +noncomputable section +section +open TensorProduct +open TensorProduct +namespace WeightedTorusJets.Deformation + +open TensorProduct + +theorem exists_surjective_global_polynomial_quotient_to_local_generic_fiber + {R A F S σ ι : Type*} [CommRing R] [CommRing A] [Field F] [CommRing S] + [Algebra R A] [Algebra R F] [Algebra A F] [IsScalarTower R A F] + [Algebra R S] [Algebra A S] [IsScalarTower R A S] + [Algebra (MvPolynomial σ R) S] [IsScalarTower R (MvPolynomial σ R) S] + (M : Submonoid R) [IsLocalization M A] + (N : Submonoid (MvPolynomial σ R)) [IsLocalization N S] + (f : ι → MvPolynomial σ R) + [Module.Finite F (MvPolynomial σ F ⧸ Ideal.span + (Set.range (fun i => MvPolynomial.map (algebraMap R F) (f i))))] : + ∃ π : (MvPolynomial σ F ⧸ Ideal.span + (Set.range (fun i => MvPolynomial.map (algebraMap R F) (f i)))) →ₗ[F] + F ⊗[A] (S ⧸ Ideal.span + (Set.range (fun i => algebraMap (MvPolynomial σ R) S (f i)))), + Function.Surjective π ∧ ∀ p : MvPolynomial σ R, + π (Ideal.Quotient.mk _ (MvPolynomial.map (algebraMap R F) p)) = + 1 ⊗ₜ[A] Ideal.Quotient.mk _ (algebraMap (MvPolynomial σ R) S p) := by + let I := Ideal.span (Set.range f) + let E := mvPolynomialSpanQuotientBaseChange (A := F) f + have : Module.Finite F (F ⊗[R] (MvPolynomial σ R ⧸ I)) := + Module.Finite.equiv E.symm.toLinearEquiv + let qmap := Ideal.quotientMapₐ (I.map (algebraMap (MvPolynomial σ R) S)) + (IsScalarTower.toAlgHom R (MvPolynomial σ R) S) Ideal.le_comap_map + let Tmap := Algebra.TensorProduct.map (AlgHom.id F F) qmap + have hT : Function.Surjective Tmap := + surjective_baseChange_localized_quotient (R := R) (F := F) + (P := MvPolynomial σ R) (S := S) N I + let EB := genericFiberLocalBaseEquiv (A := A) (F := F) + (B := S ⧸ I.map (algebraMap (MvPolynomial σ R) S)) M + let EJ := Ideal.quotientEquivAlgOfEq A + (show I.map (algebraMap (MvPolynomial σ R) S) = + Ideal.span (Set.range (fun i => algebraMap (MvPolynomial σ R) S (f i))) by + dsimp only [I] + rw [Ideal.map_span, ← Set.range_comp']) + let ET := Algebra.TensorProduct.congr (AlgEquiv.refl : F ≃ₐ[F] F) EJ + let π := ET.toLinearEquiv.toLinearMap.comp (EB.symm.toLinearEquiv.toLinearMap.comp + (Tmap.toLinearMap.comp E.symm.toLinearEquiv.toLinearMap)) + refine ⟨π, ET.surjective.comp (EB.symm.surjective.comp (hT.comp E.symm.surjective)), ?_⟩ + intro p + simp only [π, LinearMap.comp_apply, LinearEquiv.coe_coe, + E, AlgEquiv.toLinearEquiv_apply, + mvPolynomialSpanQuotientBaseChange_symm_mk_map] + change ET (EB.symm (Tmap (1 ⊗ₜ[R] Ideal.Quotient.mk I p))) = _ + simp only [Tmap, Algebra.TensorProduct.map_tmul, AlgHom.id_apply, + qmap] + change ET (1 ⊗ₜ[A] Ideal.Quotient.mk _ (algebraMap (MvPolynomial σ R) S p)) = _ + simp only [ET, Algebra.TensorProduct.congr_apply, Algebra.TensorProduct.map_tmul, + AlgEquiv.coe_toAlgHom, EJ, Ideal.quotientEquivAlgOfEq_mk] + rfl + +end WeightedTorusJets.Deformation + +end + +section + +namespace WeightedTorusJets.Deformation + +theorem finiteLength_quotient_of_radical_eq_maximalIdeal + {R : Type*} [CommRing R] [IsNoetherianRing R] [IsLocalRing R] + (I : Ideal R) (hrad : I.radical = IsLocalRing.maximalIdeal R) : + IsFiniteLength R (R ⧸ I) := by + have hI : I ≠ ⊤ := by + intro h + have := congrArg (fun J : Ideal R => J.radical) h + rw [hrad, Ideal.radical_top] at this + exact (IsLocalRing.maximalIdeal.isMaximal R).ne_top this + have : Nontrivial (R ⧸ I) := Ideal.Quotient.nontrivial_iff.mpr hI + have := IsLocalRing.of_surjective' (Ideal.Quotient.mk I) Ideal.Quotient.mk_surjective + have hmax : (IsLocalRing.maximalIdeal R).map (Ideal.Quotient.mk I) = + IsLocalRing.maximalIdeal (R ⧸ I) := by + apply IsLocalRing.eq_maximalIdeal + exact Ideal.IsMaximal.map_of_surjective_of_ker_le Ideal.Quotient.mk_surjective + (by simpa only [Ideal.mk_ker] using IsLocalRing.le_maximalIdeal hI) + have hart : IsArtinianRing (R ⧸ I) := by + apply (isArtinianRing_iff_isNilpotent_maximalIdeal (R ⧸ I)).mpr + obtain ⟨n, hn⟩ := I.exists_radical_pow_le_of_fg (Ideal.fg_of_isNoetherianRing _) + refine ⟨n, ?_⟩ + rw [← hmax, ← Ideal.map_pow, Ideal.zero_eq_bot, Ideal.map_eq_bot_iff_le_ker, + Ideal.mk_ker] + rwa [hrad] at hn + rw [isFiniteLength_iff_isNoetherian_isArtinian] + exact ⟨isNoetherian_quotient I, + isArtinian_of_surjective_algebraMap (Ideal.Quotient.mk_surjective (I := I))⟩ + +theorem finite_of_finiteLength_of_finite_residue + {K R M : Type*} [Field K] [CommRing R] [IsLocalRing R] [Algebra K R] + [AddCommGroup M] [Module K M] [Module R M] [IsScalarTower K R M] + [Module.Finite K (IsLocalRing.ResidueField R)] (hM : IsFiniteLength R M) : + Module.Finite K M := by + have hres : Module.length (IsLocalRing.ResidueField K) (IsLocalRing.ResidueField R) ≠ ⊤ := by + rw [← Module.length_eq_of_surjective (M := IsLocalRing.ResidueField R) + (IsLocalRing.residue_surjective (R := K))] + exact Module.length_ne_top + have hlen : Module.length K M ≠ ⊤ := by + rw [IsLocalRing.length_restrictScalars K R M] + exact WithTop.mul_ne_top (Module.length_ne_top_iff.mpr hM) hres + have : IsNoetherian K M := + (isFiniteLength_iff_isNoetherian_isArtinian.mp (Module.length_ne_top_iff.mp hlen)).1 + infer_instance + +theorem length_le_finrank_of_finiteLength_of_finite_residue + {K R M : Type*} [Field K] [CommRing R] [IsLocalRing R] [Algebra K R] + [AddCommGroup M] [Module K M] [Module R M] [IsScalarTower K R M] + [Module.Finite K (IsLocalRing.ResidueField R)] (hM : IsFiniteLength R M) : + Module.length R M ≤ (Module.finrank K M : ℕ∞) := by + let := finite_of_finiteLength_of_finite_residue (K := K) hM + have h := (⊤ : Submodule R M).length_le_length_restrictScalars K + rw [Submodule.restrictScalars_top, Module.length_top, Module.length_top, + Module.length_eq_finrank] at h + exact h + +theorem finite_quotient_of_radical_eq_maximalIdeal + {K R : Type*} [Field K] [CommRing R] [IsNoetherianRing R] [IsLocalRing R] + [Algebra K R] [Module.Finite K (IsLocalRing.ResidueField R)] + (I : Ideal R) (hrad : I.radical = IsLocalRing.maximalIdeal R) : + Module.Finite K (R ⧸ I) := + finite_of_finiteLength_of_finite_residue + (finiteLength_quotient_of_radical_eq_maximalIdeal I hrad) + +end WeightedTorusJets.Deformation +end + +section + +open TensorProduct + +namespace WeightedTorusJets.Deformation + +noncomputable def residueTensorQuotientAlgEquiv + {K A B : Type*} [Field K] [CommRing A] [IsLocalRing A] [CommRing B] + [Algebra K A] [Algebra A B] [Algebra K B] [IsScalarTower K A B] + (t : A) (ht : IsLocalRing.maximalIdeal A = Ideal.span {t}) : + (IsLocalRing.ResidueField A ⊗[A] B) ≃ₐ[K] + B ⧸ Ideal.span {algebraMap A B t} := by + refine (((Algebra.TensorProduct.comm A (IsLocalRing.ResidueField A) B).trans + ((Algebra.TensorProduct.quotIdealMapEquivTensorQuot B + (IsLocalRing.maximalIdeal A)).symm.restrictScalars A)).restrictScalars K).trans ?_ + apply Ideal.quotientEquivAlgOfEq K + rw [ht, Ideal.map_span] + simp + +theorem finite_residueTensor_of_finite_quotient + {K A B : Type*} [Field K] [CommRing A] [IsLocalRing A] [CommRing B] + [Algebra K A] [Algebra A B] [Algebra K B] [IsScalarTower K A B] + (t : A) (ht : IsLocalRing.maximalIdeal A = Ideal.span {t}) + [Module.Finite K (B ⧸ Ideal.span {algebraMap A B t})] : + Module.Finite (IsLocalRing.ResidueField A) (IsLocalRing.ResidueField A ⊗[A] B) := by + have : Module.Finite K (IsLocalRing.ResidueField A ⊗[A] B) := + Module.Finite.of_surjective (residueTensorQuotientAlgEquiv (K := K) t ht).symm.toLinearMap + (residueTensorQuotientAlgEquiv (K := K) t ht).symm.surjective + exact Module.Finite.of_restrictScalars_finite K (IsLocalRing.ResidueField A) _ + +theorem finrank_residueTensor_eq_quotient + {K A B : Type*} [Field K] [CommRing A] [IsLocalRing A] [CommRing B] + [Algebra K A] [Algebra A B] [Algebra K B] [IsScalarTower K A B] + (t : A) (ht : IsLocalRing.maximalIdeal A = Ideal.span {t}) + (e : IsLocalRing.ResidueField A ≃ₐ[K] K) : + Module.finrank (IsLocalRing.ResidueField A) (IsLocalRing.ResidueField A ⊗[A] B) = + Module.finrank K (B ⧸ Ideal.span {algebraMap A B t}) := by + have hdegree : Module.finrank K (IsLocalRing.ResidueField A) = 1 := by + simpa using e.toLinearEquiv.finrank_eq + have hdim := Module.finrank_mul_finrank K (IsLocalRing.ResidueField A) + (IsLocalRing.ResidueField A ⊗[A] B) + rw [hdegree, one_mul] at hdim + exact hdim.trans (residueTensorQuotientAlgEquiv (K := K) t ht).toLinearEquiv.finrank_eq + +end WeightedTorusJets.Deformation + +end + +section + +open Module TensorProduct + +namespace WeightedTorusJets.Deformation + +theorem finrank_special_fiber_le_generic + (R F M : Type*) [CommRing R] [IsLocalRing R] + [Field F] [Algebra R F] [IsFractionRing R F] + [AddCommGroup M] [Module R M] [Module.Flat R M] + [Module.Finite (IsLocalRing.ResidueField R) (IsLocalRing.ResidueField R ⊗[R] M)] + [Module.Finite F (F ⊗[R] M)] : + Module.finrank (IsLocalRing.ResidueField R) (IsLocalRing.ResidueField R ⊗[R] M) ≤ + Module.finrank F (F ⊗[R] M) := by + classical + let k := IsLocalRing.ResidueField R + let b := Module.finBasis k (k ⊗[R] M) + choose v hv using fun i => + TensorProduct.mk_surjective R M k (IsLocalRing.residue_surjective (R := R)) (b i) + have hspecial : LinearIndependent k (TensorProduct.mk R k M 1 ∘ v) := by + simpa only [Function.comp_def, hv] using b.linearIndependent + have hbase : LinearIndependent R v := IsLocalRing.linearIndependent_of_flat v hspecial + have hgeneric : LinearIndependent F (TensorProduct.mk R F M 1 ∘ v) := + hbase.of_isLocalizedModule F (nonZeroDivisors R) (TensorProduct.mk R F M 1) + simpa using hgeneric.fintype_card_le_finrank + +theorem finrank_special_fiber_le_global_generic + (R F M G : Type*) [CommRing R] [IsLocalRing R] + [Field F] [Algebra R F] [IsFractionRing R F] + [AddCommGroup M] [Module R M] [Module.Flat R M] + [Module.Finite (IsLocalRing.ResidueField R) (IsLocalRing.ResidueField R ⊗[R] M)] + [AddCommGroup G] [Module F G] [Module.Finite F G] + (π : G →ₗ[F] F ⊗[R] M) (hπ : Function.Surjective π) : + Module.finrank (IsLocalRing.ResidueField R) (IsLocalRing.ResidueField R ⊗[R] M) ≤ + Module.finrank F G := by + have : Module.Finite F (F ⊗[R] M) := Module.Finite.of_surjective π hπ + exact (finrank_special_fiber_le_generic R F M).trans + (LinearMap.finrank_le_finrank_of_surjective hπ) + +end WeightedTorusJets.Deformation + +end + +section + +namespace WeightedTorusJets.Deformation + +theorem finite_residueField_mvPolynomial_maximal + {K σ : Type*} [Field K] [Finite σ] + (p : Ideal (MvPolynomial σ K)) [p.IsMaximal] : Module.Finite K p.ResidueField := by + let := Ideal.Quotient.field p + let : Module.Finite K (MvPolynomial σ K ⧸ p) := + finite_of_finite_type_of_isJacobsonRing K _ + exact Module.Finite.of_surjective + (IsScalarTower.toAlgHom K (MvPolynomial σ K ⧸ p) p.ResidueField).toLinearMap + p.bijective_algebraMap_quotient_residueField.surjective + +end WeightedTorusJets.Deformation + +end + +section +namespace WeightedTorusJets.Deformation + +open Polynomial + +noncomputable def polynomialDeformationSpecialFiberAlgEquiv + {K σ : Type*} [CommRing K] + (p : Ideal (MvPolynomial σ K)) [p.IsPrime] + (f : σ → MvPolynomial σ K) (d : ℕ) : + let S := Localization.AtPrime + (p.comap (MvPolynomial.map (σ := σ) (evalRingHom (0 : K)))) + letI : CommRing S := inferInstance + let fs := fun i => algebraMap (MvPolynomial σ K[X]) S (polynomialDeformation f d i) + let I := Ideal.span (Set.range fs) + let t := algebraMap (MvPolynomial σ K[X]) S (MvPolynomial.C (σ := σ) (Polynomial.X - Polynomial.C (0 : K))) + ((S ⧸ I) ⧸ (Ideal.span {t}).map (Ideal.Quotient.mk I)) ≃ₐ[K] + (Localization.AtPrime p) ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (f i))) := by + intro S + letI : CommRing S := inferInstance + have he := quotientFamilySpecializationAlgEquiv + (Ideal.span {algebraMap (MvPolynomial σ K[X]) S + (MvPolynomial.C (σ := σ) (Polynomial.X - Polynomial.C (0 : K)))} : Ideal S) + (mvPolynomialLocalQuotientAlgEquiv p (0 : K)) + (fun i => algebraMap (MvPolynomial σ K[X]) S (polynomialDeformation f d i)) + (fun i => algebraMap (MvPolynomial σ K) (Localization.AtPrime p) (f i)) + (fun i => by + rw [mvPolynomialLocalQuotientAlgEquiv_apply_mk_algebraMap, + polynomialDeformation_at_zero]) + exact he + +end WeightedTorusJets.Deformation +end + +section +namespace WeightedTorusJets.Deformation + +open Polynomial TensorProduct + +theorem finrank_local_quotient_le_pow_of_radical + {K : Type*} [Field K] (h d : ℕ) + (p : Ideal (MvPolynomial (Fin h) K)) [p.IsMaximal] + (f : Fin h → MvPolynomial (Fin h) K) + (hf : ∀ i, (f i).totalDegree ≤ d) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Fin h) K) (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Module.finrank K ((Localization.AtPrime p) ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Fin h) K) (Localization.AtPrime p) (f i)))) ≤ d ^ h := by + let I : Ideal K[X] := RingHom.ker (evalRingHom (0 : K)) + have hI : I = Ideal.span {Polynomial.X - Polynomial.C (0 : K)} := ker_evalRingHom _ + let : I.IsPrime := RingHom.ker_isPrime (evalRingHom (0 : K)) + let A := Localization.AtPrime I + let q := p.comap (MvPolynomial.map (σ := Fin h) (evalRingHom (0 : K))) + let S := Localization.AtPrime q + let : CommRing S := inferInstance + let : Algebra A S := parameterLocalAlgebra p I (0 : K) hI + have : IsScalarTower K[X] A S := parameterLocalAlgebra_isScalarTower p I (0 : K) hI + have : IsScalarTower K A S := parameterLocalAlgebra_groundFieldTower p I (0 : K) hI + have hFracTower := localFractionAlgebra_isScalarTower (F := RatFunc K) I + have hFracField := localFractionAlgebra_isFractionRing (F := RatFunc K) I + let : Algebra A (RatFunc K) := localFractionAlgebra (F := RatFunc K) I + let : SMul A (RatFunc K) := (localFractionAlgebra (F := RatFunc K) I).toSMul + have : IsScalarTower K[X] A (RatFunc K) := hFracTower + have : IsFractionRing A (RatFunc K) := hFracField + let Fs := fun i => algebraMap (MvPolynomial (Fin h) K[X]) S (polynomialDeformation f d i) + let J := Ideal.span (Set.range Fs) + let B := S ⧸ J + let t : A := algebraMap K[X] A (Polynomial.X - Polynomial.C (0 : K)) + let L := (Localization.AtPrime p) ⧸ Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Fin h) K) (Localization.AtPrime p) (f i))) + have ht : IsLocalRing.maximalIdeal A = Ideal.span {t} := by + rw [← Localization.AtPrime.map_eq_maximalIdeal] + calc + I.map (algebraMap K[X] A) = + (Ideal.span {Polynomial.X - Polynomial.C (0 : K)}).map (algebraMap K[X] A) := + congrArg (Ideal.map (algebraMap K[X] A)) hI + _ = _ := by + rw [Ideal.map_span] + simp only [Set.image_singleton] + rfl + let e : (B ⧸ Ideal.span {algebraMap A B t}) ≃ₐ[K] L := by + have hJ : (Ideal.span {algebraMap A B t} : Ideal B) = + (Ideal.span {algebraMap (MvPolynomial (Fin h) K[X]) S + (MvPolynomial.C (σ := Fin h) (Polynomial.X - Polynomial.C (0 : K)))} : Ideal S).map + (Ideal.Quotient.mk J) := by + rw [Ideal.map_span, Set.image_singleton] + congr 1 + congr 1 + rw [IsScalarTower.algebraMap_apply A S B, parameterLocalAlgebra_parameter] + rfl + exact (Ideal.quotientEquivAlgOfEq K hJ).trans + (polynomialDeformationSpecialFiberAlgEquiv p f d) + have : Module.Finite K p.ResidueField := finite_residueField_mvPolynomial_maximal p + have : Module.Finite K L := finite_quotient_of_radical_eq_maximalIdeal _ hrad + have : Module.Finite K (B ⧸ Ideal.span {algebraMap A B t}) := + Module.Finite.equiv e.symm.toLinearEquiv + have : Module.Finite (IsLocalRing.ResidueField A) (IsLocalRing.ResidueField A ⊗[A] B) := + finite_residueTensor_of_finite_quotient (K := K) t ht + have hlen : (h : ℕ∞) = + (IsLocalRing.maximalIdeal (Localization.AtPrime p)).height := by + have hd := IsLocalization.AtPrime.ringKrullDim_eq_height p (Localization.AtPrime p) + rw [← IsLocalRing.maximalIdeal_height_eq_ringKrullDim, + Geometry.maximal_polynomial_height h p] at hd + exact_mod_cast hd.symm + have : Module.Flat A B := flat_polynomialDeformation_localized p I hI f d hrad hlen + let G := MvPolynomial (Fin h) (RatFunc K) ⧸ Ideal.span (Set.range (fun i => + MvPolynomial.map (algebraMap K[X] (RatFunc K)) (polynomialDeformation f d i))) + obtain ⟨hfinite, hbound⟩ := generic_affine_deformation_quotient_bound f d hf + let : Module.Finite (RatFunc K) G := hfinite + obtain ⟨π, hπ, _⟩ := exists_surjective_global_polynomial_quotient_to_local_generic_fiber + (A := A) (F := RatFunc K) (S := S) I.primeCompl q.primeCompl + (polynomialDeformation f d) + have hcomp := finrank_special_fiber_le_global_generic A (RatFunc K) B G π hπ + rw [finrank_residueTensor_eq_quotient (K := K) t ht + (residueFieldAtLinearAlgEquiv I (0 : K) hI), e.toLinearEquiv.finrank_eq] at hcomp + exact hcomp.trans (by simpa only [Fintype.card_fin] using hbound) + +theorem length_local_quotient_le_pow_of_radical + {K : Type*} [Field K] (h d : ℕ) + (p : Ideal (MvPolynomial (Fin h) K)) [p.IsMaximal] + (f : Fin h → MvPolynomial (Fin h) K) + (hf : ∀ i, (f i).totalDegree ≤ d) + (hrad : (Ideal.span (Set.range (fun i => + algebraMap (MvPolynomial (Fin h) K) (Localization.AtPrime p) (f i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p)) : + Module.length (Localization.AtPrime p) ((Localization.AtPrime p) ⧸ + Ideal.span (Set.range (fun i => algebraMap (MvPolynomial (Fin h) K) + (Localization.AtPrime p) (f i)))) ≤ (d ^ h : ℕ∞) := by + have : Module.Finite K p.ResidueField := finite_residueField_mvPolynomial_maximal p + exact (length_le_finrank_of_finiteLength_of_finite_residue (K := K) + (finiteLength_quotient_of_radical_eq_maximalIdeal _ hrad)).trans + (by exact_mod_cast finrank_local_quotient_le_pow_of_radical h d p f hf hrad) + +end WeightedTorusJets.Deformation +end + +end +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/RestrictWeightSortedEquiv.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RestrictWeightSortedEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..43584e9892d4240e2a5163433763020d4dd429bd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/RestrictWeightSortedEquiv.lean @@ -0,0 +1,569 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.BiquadraticArithmeticFull +import OAI.NumberTheory.Jacobsthal.Siegel.WeightedJetIndices + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped BigOperators +open scoped BigOperators +open Module +open scoped BigOperators +namespace WeightedTorusJets + +theorem exists_first_greedy_jet_rows {K : Type*} [Field K] {M : ℕ} + (θ y z : Fin M → K) (hθ : Function.Injective θ) (H : ℕ) (hH : 0 < H) : + let s := weightedJetIndices H (M - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + let R := fun α : Fin 3 → ℕ => fun j => θ j ^ α 0 * y j ^ α 1 * z j ^ α 2 + ∃ e : Fin s.card ≃ s, Monotone (fun i => w (e i)) ∧ + let β := extendFiniteFamily (fun i => (e i : Fin 3 → ℕ)) 0 + ∃ (g : Fin M ↪o ℕ) (α : Fin M ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots K (R ∘ β) s.card : Set ℕ) ∧ + (∀ i, α i = β (g i)) ∧ + Set.range α = (finiteGreedyPivots K s R e 0 : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ M - 1) ∧ + (∀ i a b c, a + H * b + H * c < w (α i) → + (fun j => θ j ^ a * y j ^ b * z j ^ c) ∈ + Submodule.span K ((R ∘ α) '' {j | j < i})) ∧ + Matrix.det (fun i j => R (α i) j) ≠ 0 := by + classical + dsimp only + let s := weightedJetIndices H (M - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + let R := fun α : Fin 3 → ℕ => fun j => θ j ^ α 0 * y j ^ α 1 * z j ^ α 2 + obtain ⟨e, he⟩ := exists_weight_sorted_enumeration s w + have hs : ∀ α, α ∈ s ↔ w α ≤ M - 1 := mem_weightedJetIndices_iff hH + obtain ⟨g, α, hg, hα, hrange, hmono, hαmono, hlt, hprefix, + hselected, hcoverage, hdet, hcard, hsum⟩ := + finite_weighted_greedy_package s R e 0 w (M - 1) hs he + (jet_weight_ball_span_eq_top θ y z hθ H hH) + refine ⟨e, he, g, α, hg, hα, hrange, hαmono, + fun i => (hselected i).2.2, ?_, hdet⟩ + intro i a b c hweight + have habc : w ![a, b, c] ≤ M - 1 := + Nat.le_trans (Nat.le_of_lt hweight) (hselected i).2.2 + obtain ⟨r, _, _, hwr, hvr⟩ := hcoverage ![a, b, c] habc + have hrows : R ∘ α = (R ∘ extendFiniteFamily (fun i => (e i : Fin 3 → ℕ)) 0) ∘ g := by + funext j + exact (hselected j).1.symm + have hstrict : (extendFiniteFamily (fun j => w (e j)) (M - 1)) r < + (extendFiniteFamily (fun j => w (e j)) (M - 1)) (g i) := by + rw [hwr, (hselected i).2.1] + exact hweight + have hmem := smaller_weight_mem_span_earlier_retained_rows _ _ hmono s.card g hg + (R ∘ α) hrows i r hstrict + rw [hvr] at hmem + simpa only [R, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val, + Matrix.head_cons] using hmem + +end WeightedTorusJets + +open scoped BigOperators +open Module + +namespace WeightedTorusJets + +theorem basis_nat_sum_injective {ι V : Type*} [Fintype ι] + [AddCommGroup V] [Module ℚ V] (b : Basis ι ℚ V) : + Function.Injective (fun n : ι → ℕ => ∑ i, (n i : ℚ) • b i) := by + intro n m h + funext i + have hi := congrArg (fun v => b.repr v i) h + simp only [Basis.repr_sum_self] at hi + exact_mod_cast hi + +theorem basis_nat_sum_mul_injective {ι K : Type*} [Fintype ι] + [CommRing K] [Algebra ℚ K] (b : Basis ι ℚ K) : + Function.Injective (fun n : ι → ℕ => ∑ i, (n i : K) * b i) := by + have h : (fun n : ι → ℕ => ∑ i, (n i : ℚ) • b i) = + (fun n : ι → ℕ => ∑ i, (n i : K) * b i) := by + funext n + simp [Algebra.smul_def] + rw [← h] + exact basis_nat_sum_injective b + +theorem basis_fin_sum_mul_injective {ι K : Type*} [Fintype ι] + [CommRing K] [Algebra ℚ K] (b : Basis ι ℚ K) (N : ℕ) : + Function.Injective (fun n : ι → Fin N => ∑ i, ((n i : ℕ) : K) * b i) := by + intro n m h + have hcoords := basis_nat_sum_mul_injective b h + funext i + exact Fin.ext (congrFun hcoords i) + + + +theorem exists_first_greedy_jet_rows_of_sorted_enumeration {K : Type*} [Field K] {M : ℕ} + (θ y z : Fin M → K) (hθ : Function.Injective θ) (H : ℕ) (hH : 0 < H) : + let s := weightedJetIndices H (M - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + let R := fun α : Fin 3 → ℕ => fun j => θ j ^ α 0 * y j ^ α 1 * z j ^ α 2 + ∀ e : Fin s.card ≃ s, Monotone (fun i => w (e i)) → + let β := extendFiniteFamily (fun i => (e i : Fin 3 → ℕ)) 0 + ∃ (g : Fin M ↪o ℕ) (α : Fin M ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots K (R ∘ β) s.card : Set ℕ) ∧ + (∀ i, α i = β (g i)) ∧ + Set.range α = (finiteGreedyPivots K s R e 0 : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ M - 1) ∧ + (∀ i a b c, a + H * b + H * c < w (α i) → + (fun j => θ j ^ a * y j ^ b * z j ^ c) ∈ + Submodule.span K ((R ∘ α) '' {j | j < i})) ∧ + Matrix.det (fun i j => R (α i) j) ≠ 0 := by + classical + dsimp only + let s := weightedJetIndices H (M - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + let R := fun α : Fin 3 → ℕ => fun j => θ j ^ α 0 * y j ^ α 1 * z j ^ α 2 + intro e he + have hs : ∀ α, α ∈ s ↔ w α ≤ M - 1 := mem_weightedJetIndices_iff hH + obtain ⟨g, α, hg, hα, hrange, hmono, hαmono, hlt, hprefix, + hselected, hcoverage, hdet, hcard, hsum⟩ := + finite_weighted_greedy_package s R e 0 w (M - 1) hs he + (jet_weight_ball_span_eq_top θ y z hθ H hH) + refine ⟨g, α, hg, hα, hrange, hαmono, + fun i => (hselected i).2.2, ?_, hdet⟩ + intro i a b c hweight + have habc : w ![a, b, c] ≤ M - 1 := + Nat.le_trans (Nat.le_of_lt hweight) (hselected i).2.2 + obtain ⟨r, _, _, hwr, hvr⟩ := hcoverage ![a, b, c] habc + have hrows : R ∘ α = (R ∘ extendFiniteFamily (fun i => (e i : Fin 3 → ℕ)) 0) ∘ g := by + funext j + exact (hselected j).1.symm + have hstrict : (extendFiniteFamily (fun j => w (e j)) (M - 1)) r < + (extendFiniteFamily (fun j => w (e j)) (M - 1)) (g i) := by + rw [hwr, (hselected i).2.1] + exact hweight + have hmem := smaller_weight_mem_span_earlier_retained_rows _ _ hmono s.card g hg + (R ∘ α) hrows i r hstrict + rw [hvr] at hmem + simpa only [R, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val, + Matrix.head_cons] using hmem + + + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_character_fixed_greedy_determinant_divisibility_of_field_ne (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ N H : ℕ, 0 < H → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * + ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + ∀ e : Fin s.card ≃ s, Monotone (fun i => w (e i)) → + let β := extendFiniteFamily (fun i => (e i : Fin 3 → ℕ)) 0 + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ β) s.card : Set ℕ) ∧ + (∀ i, α i = β (g i)) ∧ + Set.range α = (finiteGreedyPivots B s R e 0 : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ N ^ 4 - 1) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + Δ ≠ 0 ∧ + ∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p) := by + classical + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hFrob⟩ := + source_biquadratic_arithmetic_canonical_of_field_ne q χ hreal hprim hne hfield + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro N H hH n + dsimp only + intro e he + let L := CyclotomicField (8 * q) ℚ + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + have hθ : Function.Injective θ := by + have hinj := (basis_fin_sum_mul_injective v N).comp n.injective + simpa only [Function.comp_def, hv, θ, a', b'] using hinj + obtain ⟨g, α, hg, hα, hrange, hmono, hweight, hspan, hdet⟩ := + exists_first_greedy_jet_rows_of_sorted_enumeration + θ (σ ∘ θ) ((σ * τ) ∘ θ) hθ H hH e he + refine ⟨g, α, hg, hα, hrange, hmono, hweight, ?_⟩ + have ha' : a' ^ 2 = (d : B) := by + apply Subtype.ext + exact ha + have hb' : b' ^ 2 = (2 : B) := by + apply Subtype.ext + exact hb + obtain ⟨Δ, hΔ, hneΔ, hdiv⟩ := exists_integral_jet_determinant_divisible + σ.toRingHom τ.toRingHom ha' hb' (fun j i => (n j i : ℕ)) α H hspan hdet + refine ⟨Δ, hΔ, hneΔ, ?_⟩ + intro p hp hHp hpq hχp + exact hdiv p hHp (frobenius_action_choice_quotient σ τ p (hFrob p hp hpq hχp)) + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem greedyPivots_congr_prefix {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (v v' : ℕ → V) (n : ℕ) + (h : ∀ i < n, v i = v' i) : greedyPivots K v n = greedyPivots K v' n := by + induction n with + | zero => rfl + | succ n ih => + classical + have hprevious := ih (fun i hi => h i (Nat.lt_succ_of_lt hi)) + have hlast := h n (Nat.lt_succ_self n) + have himage : v '' (greedyPivots K v' n : Set ℕ) = + v' '' (greedyPivots K v' n : Set ℕ) := by + apply Set.image_congr + intro i hi + exact h i (Nat.lt_succ_of_lt + (Finset.mem_range.mp (greedyPivots_subset_range v' n hi))) + simp only [greedyPivots, hprevious, hlast, himage] + + + +theorem weight_sorted_equiv_mem_iff_lt_card {α : Type*} + (s : Finset α) (w : α → ℕ) (B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B) + (e : ℕ ≃ α) (he : Monotone (fun i => w (e i))) (i : ℕ) : + e i ∈ s ↔ i < s.card := by + classical + let t := s.map e.symm.toEmbedding + have htmem : ∀ j, j ∈ t ↔ e j ∈ s := fun j => Finset.mem_map_equiv + have htcard : t.card = s.card := Finset.card_map _ + have hsub : t ⊆ Finset.range s.card := by + intro j hj + have hlow : Finset.range (j + 1) ⊆ t := by + intro k hk + apply (htmem k).mpr + apply (hs _).mpr + exact (he (Nat.le_of_lt_succ (Finset.mem_range.mp hk))).trans + ((hs _).mp ((htmem j).mp hj)) + have hcard := Finset.card_le_card hlow + rw [Finset.card_range, htcard] at hcard + exact Finset.mem_range.mpr (Nat.lt_of_succ_le hcard) + have ht : t = Finset.range s.card := + Finset.eq_of_subset_of_card_le hsub (by rw [Finset.card_range, htcard]) + rw [← htmem, ht, Finset.mem_range] + +noncomputable def restrictWeightSortedEquiv {α : Type*} + (s : Finset α) (w : α → ℕ) (B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B) + (e : ℕ ≃ α) (he : Monotone (fun i => w (e i))) : Fin s.card ≃ s where + toFun i := ⟨e i, (weight_sorted_equiv_mem_iff_lt_card s w B hs e he i).mpr i.isLt⟩ + invFun a := ⟨e.symm a, (weight_sorted_equiv_mem_iff_lt_card s w B hs e he (e.symm a)).mp + (by rw [e.apply_symm_apply]; exact a.property)⟩ + left_inv i := Fin.ext (e.symm_apply_apply i) + right_inv a := Subtype.ext (e.apply_symm_apply a) + +theorem restrictWeightSortedEquiv_apply {α : Type*} + (s : Finset α) (w : α → ℕ) (B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B) + (e : ℕ ≃ α) (he : Monotone (fun i => w (e i))) (i : Fin s.card) : + (restrictWeightSortedEquiv s w B hs e he i : α) = e i := rfl + +theorem restrictWeightSortedEquiv_monotone {α : Type*} + (s : Finset α) (w : α → ℕ) (B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B) + (e : ℕ ≃ α) (he : Monotone (fun i => w (e i))) : + Monotone (fun i => w (restrictWeightSortedEquiv s w B hs e he i)) := by + intro i j hij + exact he hij + +theorem extend_restrictWeightSortedEquiv_eq {α : Type*} + (s : Finset α) (w : α → ℕ) (B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B) + (e : ℕ ≃ α) (he : Monotone (fun i => w (e i))) (fallback : α) + (i : ℕ) (hi : i < s.card) : + extendFiniteFamily (fun j => (restrictWeightSortedEquiv s w B hs e he j : α)) + fallback i = e i := by + simp only [extendFiniteFamily, dite_eq_left hi, restrictWeightSortedEquiv_apply] + +theorem greedyPivots_restrictWeightSortedEquiv {K V α : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] + (s : Finset α) (R : α → V) (w : α → ℕ) (B : ℕ) + (hs : ∀ a, a ∈ s ↔ w a ≤ B) (e : ℕ ≃ α) + (he : Monotone (fun i => w (e i))) (fallback : α) : + greedyPivots K + (R ∘ extendFiniteFamily + (fun j => (restrictWeightSortedEquiv s w B hs e he j : α)) fallback) s.card = + greedyPivots K (R ∘ e) s.card := by + apply greedyPivots_congr_prefix + intro i hi + exact congrArg R (extend_restrictWeightSortedEquiv_eq s w B hs e he fallback i hi) + + + +theorem weight_sorted_equiv_image_range {α : Type*} + (s : Finset α) (w : α → ℕ) (B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B) + (e : ℕ ≃ α) (he : Monotone (fun i => w (e i))) : + e '' (Finset.range s.card : Set ℕ) = (s : Set α) := by + ext a + constructor + · rintro ⟨i, hi, rfl⟩ + exact (weight_sorted_equiv_mem_iff_lt_card s w B hs e he i).mpr + (Finset.mem_range.mp hi) + · intro ha + refine ⟨e.symm a, ?_, e.apply_symm_apply a⟩ + apply Finset.mem_range.mpr + apply (weight_sorted_equiv_mem_iff_lt_card s w B hs e he (e.symm a)).mp + simpa using ha + +theorem span_global_weight_cutoff_eq_top {K V α : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] + (s : Finset α) (R : α → V) (w : α → ℕ) (B : ℕ) + (hs : ∀ a, a ∈ s ↔ w a ≤ B) (e : ℕ ≃ α) + (he : Monotone (fun i => w (e i))) + (hspan : Submodule.span K (R '' (s : Set α)) = ⊤) : + Submodule.span K ((R ∘ e) '' (Finset.range s.card : Set ℕ)) = ⊤ := by + rw [Set.image_comp, weight_sorted_equiv_image_range s w B hs e he] + exact hspan + +theorem greedyPivots_global_weight_cutoff {K V α : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] + (s : Finset α) (R : α → V) (w : α → ℕ) (B : ℕ) + (hs : ∀ a, a ∈ s ↔ w a ≤ B) (e : ℕ ≃ α) + (he : Monotone (fun i => w (e i))) + (hspan : Submodule.span K (R '' (s : Set α)) = ⊤) + (m : ℕ) (hm : s.card ≤ m) : + greedyPivots K (R ∘ e) m = greedyPivots K (R ∘ e) s.card := by + exact (greedyPivots_eq_of_span_eq_top (R ∘ e) hm + (span_global_weight_cutoff_eq_top s R w B hs e he hspan)).symm + + + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_character_global_greedy_determinant_divisibility (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) + (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + ∃ (d : ℤ) (a b : (CyclotomicField (8 * q) ℚ)), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : (CyclotomicField (8 * q) ℚ)) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set (CyclotomicField (8 * q) ℚ)) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ N H : ℕ, 0 < H → + ∀ n : Fin (N ^ 4) ≃ (Fin 4 → Fin N), + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * + ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + ∀ e : ℕ ≃ (Fin 3 → ℕ), Monotone (fun i => w (e i)) → + ∃ (g : Fin (N ^ 4) ↪o ℕ) (α : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots B (R ∘ e) s.card : Set ℕ) ∧ + (∀ i, α i = e (g i)) ∧ + Set.range α = ((greedyPivots B (R ∘ e) s.card).image e : Set (Fin 3 → ℕ)) ∧ + Monotone (fun i => w (α i)) ∧ (∀ i, w (α i) ≤ N ^ 4 - 1) ∧ + (∀ t : ℕ, s.card ≤ t → + Set.range g = (greedyPivots B (R ∘ e) t : Set ℕ)) ∧ + ∃ Δ : 𝓞 B, (Δ : B) = Matrix.det (fun i j => R (α i) j) ∧ + Δ ≠ 0 ∧ + ∀ p : ℕ, p.Prime → H < p → ¬ p ∣ 2 * q → χ p = -1 → + Δ ∈ (Ideal.span {(p : 𝓞 B)}) ^ (∑ i, α i 0 / p) := by + classical + obtain ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hsource⟩ := + source_character_fixed_greedy_determinant_divisibility_of_field_ne + q χ hreal hprim hne hfield + refine ⟨d, a, b, hd, hbound, hddiv, hns, ha, hb, hchar, hdisc, hfund, hformula, + v, hv, hint, hdegree, σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro N H hH n + dsimp only + intro e he + let L := CyclotomicField (8 * q) ℚ + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let θ := fun j => ∑ i : Fin 4, ((n j i : ℕ) : B) * ![1, a', b', a' * b'] i + let R := fun α : Fin 3 → ℕ => fun j => + θ j ^ α 0 * σ (θ j) ^ α 1 * (σ * τ) (θ j) ^ α 2 + let s := weightedJetIndices H (N ^ 4 - 1) + let w := fun α : Fin 3 → ℕ => α 0 + H * α 1 + H * α 2 + have hs : ∀ α, α ∈ s ↔ w α ≤ N ^ 4 - 1 := mem_weightedJetIndices_iff hH + let e₀ := restrictWeightSortedEquiv s w (N ^ 4 - 1) hs e he + have he₀ : Monotone (fun i => w (e₀ i)) := + restrictWeightSortedEquiv_monotone s w (N ^ 4 - 1) hs e he + obtain ⟨g, α, hg, hα, _, hmono, hweight, Δ, hΔ, hneΔ, hdiv⟩ := + hsource N H hH n e₀ he₀ + have hgGlobal : Set.range g = (greedyPivots B (R ∘ e) s.card : Set ℕ) := + hg.trans (congrArg (fun t : Finset ℕ => (t : Set ℕ)) + (greedyPivots_restrictWeightSortedEquiv s R w (N ^ 4 - 1) hs e he 0)) + have hαGlobal : ∀ i, α i = e (g i) := by + intro i + have hi : g i ∈ greedyPivots B (R ∘ e) s.card := by + change g i ∈ (greedyPivots B (R ∘ e) s.card : Set ℕ) + rw [← hgGlobal] + exact Set.mem_range_self i + have hiT := Finset.mem_range.mp (greedyPivots_subset_range (R ∘ e) s.card hi) + exact (hα i).trans + (extend_restrictWeightSortedEquiv_eq s w (N ^ 4 - 1) hs e he 0 (g i) hiT) + have hθ : Function.Injective θ := by + have hinj := (basis_fin_sum_mul_injective v N).comp n.injective + simpa only [Function.comp_def, hv, θ, a', b'] using hinj + have hball : Submodule.span B (R '' (s : Set (Fin 3 → ℕ))) = ⊤ := + jet_weight_ball_span_eq_top θ (σ ∘ θ) ((σ * τ) ∘ θ) hθ H hH + have hspan : Submodule.span B ((R ∘ e) '' (Finset.range s.card : Set ℕ)) = ⊤ := + span_global_weight_cutoff_eq_top s R w (N ^ 4 - 1) hs e he hball + refine ⟨g, α, hgGlobal, hαGlobal, ?_, hmono, hweight, ?_, Δ, hΔ, hneΔ, hdiv⟩ + · rw [show (α : Fin (N ^ 4) → Fin 3 → ℕ) = e ∘ g from funext hαGlobal, + Set.range_comp, hgGlobal, Finset.coe_image] + · intro t ht + exact hgGlobal.trans (congrArg (fun u : Finset ℕ => (u : Set ℕ)) + (greedyPivots_eq_of_span_eq_top (R ∘ e) ht hspan)) + +end WeightedTorusJets + +open scoped BigOperators +open InnerProductSpace + +namespace SiegelJets + +theorem norm_det_le_prod_norm {n : ℕ} (A : Matrix (Fin n) (Fin n) ℂ) : + ‖A.det‖ ≤ ∏ i, ‖(WithLp.toLp 2 (A i) : EuclideanSpace ℂ (Fin n))‖ := by + let v : Fin n → EuclideanSpace ℂ (Fin n) := fun i => WithLp.toLp 2 (A i) + let e := EuclideanSpace.basisFun (Fin n) ℂ + have hdim : Module.finrank ℂ (EuclideanSpace ℂ (Fin n)) = Fintype.card (Fin n) := by + simp + let b := gramSchmidtOrthonormalBasis hdim v + have hchange : e.toBasis.det v = e.toBasis.det b * b.toBasis.det v := by + have h := congrArg (fun f : (EuclideanSpace ℂ (Fin n)) [⋀^Fin n]→ₗ[ℂ] ℂ => f v) + (e.toBasis.det.eq_smul_basis_det b.toBasis) + simpa using h + have hnorm : ‖e.toBasis.det v‖ = ‖b.toBasis.det v‖ := by + rw [hchange, norm_mul, e.det_to_matrix_orthonormalBasis b, one_mul] + have hdet : e.toBasis.det v = A.det := by + rw [Module.Basis.det_apply, ← Matrix.det_transpose A] + congr + rw [← hdet, hnorm] + change ‖b.toBasis.det v‖ ≤ ∏ i, ‖v i‖ + rw [show b.toBasis.det v = ∏ i, inner ℂ (b i) (v i) from + gramSchmidtOrthonormalBasis_det hdim v, norm_prod] + exact Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) fun i _ => by + simpa using norm_inner_le_norm (b i) (v i) + +theorem norm_det_le_of_entry_bound {n : ℕ} (A : Matrix (Fin n) (Fin n) ℂ) + (d : Fin n → ℕ) {B : ℝ} (hB : 0 ≤ B) + (hA : ∀ i j, ‖A i j‖ ≤ B ^ d i) : + ‖A.det‖ ≤ (Real.sqrt n) ^ n * B ^ (∑ i, d i) := by + have hrow (i : Fin n) : + ‖(WithLp.toLp 2 (A i) : EuclideanSpace ℂ (Fin n))‖ ≤ + Real.sqrt n * B ^ d i := by + rw [EuclideanSpace.norm_eq] + calc + Real.sqrt (∑ j, ‖A i j‖ ^ 2) ≤ Real.sqrt (∑ _ : Fin n, (B ^ d i) ^ 2) := by + apply Real.sqrt_le_sqrt + exact Finset.sum_le_sum fun j _ => pow_le_pow_left₀ (norm_nonneg _) (hA i j) 2 + _ = Real.sqrt n * B ^ d i := by + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + rw [Real.sqrt_mul (Nat.cast_nonneg n), Real.sqrt_sq (pow_nonneg hB _)] + calc + ‖A.det‖ ≤ ∏ i, ‖(WithLp.toLp 2 (A i) : EuclideanSpace ℂ (Fin n))‖ := + norm_det_le_prod_norm A + _ ≤ ∏ i, (Real.sqrt n * B ^ d i) := + Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun i _ => hrow i) + _ = (Real.sqrt n) ^ n * B ^ (∑ i, d i) := by + rw [Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum] + simp + +theorem log_norm_det_le_of_entry_bound {n : ℕ} (hn : 0 < n) + (A : Matrix (Fin n) (Fin n) ℂ) (hdet : A.det ≠ 0) + (d : Fin n → ℕ) {B : ℝ} (hB : 0 < B) + (hA : ∀ i j, ‖A i j‖ ≤ B ^ d i) : + Real.log ‖A.det‖ ≤ (n : ℝ) / 2 * Real.log n + (∑ i, d i : ℕ) * Real.log B := by + have hn' : (0 : ℝ) < n := Nat.cast_pos.mpr hn + calc + Real.log ‖A.det‖ ≤ Real.log ((Real.sqrt n) ^ n * B ^ (∑ i, d i)) := + Real.log_le_log (norm_pos_iff.mpr hdet) (norm_det_le_of_entry_bound A d hB.le hA) + _ = (n : ℝ) / 2 * Real.log n + (∑ i, d i : ℕ) * Real.log B := by + rw [Real.log_mul (pow_ne_zero _ (Real.sqrt_pos.mpr hn').ne') + (pow_ne_zero _ hB.ne'), Real.log_pow, Real.log_pow, + Real.log_sqrt hn'.le] + ring + +theorem log_norm_det_archimedean {m N q : ℕ} (hm : 0 < m) (hN : 0 < N) (hq : 0 < q) + (A : Matrix (Fin m) (Fin m) ℂ) (hdet : A.det ≠ 0) + (d : Fin m → ℕ) + (hA : ∀ i j, ‖A i j‖ ≤ (8 * N * Real.sqrt q) ^ d i) : + Real.log ‖A.det‖ ≤ (m : ℝ) / 2 * Real.log m + + (∑ i, d i : ℕ) * (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + have hN' : (0 : ℝ) < N := Nat.cast_pos.mpr hN + have hq' : (0 : ℝ) < q := Nat.cast_pos.mpr hq + have hB : (0 : ℝ) < 8 * N * Real.sqrt q := by positivity + have hlog : Real.log (8 * N * Real.sqrt q) = + Real.log N + 1 / 2 * Real.log q + Real.log 8 := by + rw [Real.log_mul (mul_pos (by norm_num) hN').ne' (Real.sqrt_pos.mpr hq').ne', + Real.log_mul (by norm_num) hN'.ne', Real.log_sqrt hq'.le] + ring + simpa only [hlog] using log_norm_det_le_of_entry_bound hm A hdet d hB hA + +theorem log_norm_map_det_archimedean {K : Type*} [Field K] {m N q : ℕ} + (hm : 0 < m) (hN : 0 < N) (hq : 0 < q) + (ν : K →+* ℂ) (A : Matrix (Fin m) (Fin m) K) (hdet : A.det ≠ 0) + (d : Fin m → ℕ) + (hA : ∀ i j, ‖ν (A i j)‖ ≤ (8 * N * Real.sqrt q) ^ d i) : + Real.log ‖ν A.det‖ ≤ (m : ℝ) / 2 * Real.log m + + (∑ i, d i : ℕ) * (Real.log N + 1 / 2 * Real.log q + Real.log 8) := by + have hmapped : (ν.mapMatrix A).det ≠ 0 := by + rw [← RingHom.map_det] + exact (map_ne_zero ν).mpr hdet + simpa only [← RingHom.map_det] using + log_norm_det_archimedean hm hN hq (ν.mapMatrix A) hmapped d hA + +end SiegelJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/SqrtPairFrobeniusDirections.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SqrtPairFrobeniusDirections.lean new file mode 100644 index 0000000000000000000000000000000000000000..6585873b3100ca20dc168a214d448385606d4f48 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SqrtPairFrobeniusDirections.lean @@ -0,0 +1,479 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.BiquadraticBasis + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped Pointwise +open scoped NumberField +namespace WeightedTorusJets + +open scoped NumberField + +lemma sqrtPair_frobenius_directions {L : Type*} [Field L] [NumberField L] + (a b : L) (d e : ℚ) (ha : a ^ 2 = algebraMap ℚ L d) + (hb : b ^ 2 = algebraMap ℚ L e) (hd : ¬ IsSquare d) (he : ¬ IsSquare e) + (hne : IntermediateField.adjoin ℚ {a} ≠ IntermediateField.adjoin ℚ {b}) : + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ (p : ℕ) (φ : L ≃ₐ[ℚ] L), φ a = -a → + (∀ y : 𝓞 L, (p : 𝓞 L) ∣ y ^ p - φ • y) → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x)) := by + dsimp + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + obtain ⟨σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm⟩ := + sqrtPair_four_automorphisms a b d e ha hb hd he hne + have ha0 : a ≠ 0 := by + intro h + have hmap : algebraMap ℚ L d = 0 := by simpa [h] using ha.symm + have hd0 : d = 0 := (algebraMap ℚ L).injective (hmap.trans (map_zero _).symm) + exact hd (hd0 ▸ IsSquare.zero) + have ha'0 : a' ≠ 0 := fun h => ha0 (congrArg (fun x : B => (x : L)) h) + have ha'neg : a' ≠ -a' := fun h => ha'0 (CharZero.eq_neg_self_iff.mp h) + refine ⟨σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + intro p φ hφ hfrob + let : IsGalois ℚ B := sqrtPair_isGalois a b d e ha hb hd he hne + let ψ := φ.restrictNormal B + have hψa : ψ a' = -a' := by + apply Subtype.ext + simpa [ψ, a', AlgEquiv.restrictNormal_apply] using hφ + have hψcomm (x : B) : B.val (ψ x) = φ (B.val x) := + AlgEquiv.restrictNormal_apply B φ x + have hψfrob : ∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - ψ • x := + frobenius_congruence_descends B.val ψ φ hψcomm p hfrob + rcases hall ψ with hψ | hψ | hψ | hψ + · rw [hψ, AlgEquiv.one_apply] at hψa + exact (ha'neg hψa).elim + · exact Or.inl (hψ ▸ hψfrob) + · rw [hψ, hτa] at hψa + exact (ha'neg hψa).elim + · exact Or.inr (hψ ▸ hψfrob) + +end WeightedTorusJets + +open scoped NumberField + +namespace WeightedTorusJets + +theorem mem_map_of_forall_mem_primesOver + {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] + [Algebra.EssFiniteType R S] (P : Ideal R) [hP : P.IsMaximal] + (hunr : Algebra.IsUnramifiedIn S P) {x : S} + (hx : ∀ (Q : Ideal S) (_ : Q.IsPrime), Q.LiesOver P → x ∈ Q) : + x ∈ P.map (algebraMap R S) := by + apply Ideal.mem_of_localization_maximal + intro Q hQ + by_cases hle : P.map (algebraMap R S) ≤ Q + · have hover : Q.LiesOver P := ⟨hP.eq_of_le (Ideal.IsPrime.ne_top' (I := Q.under R)) + (Ideal.map_le_iff_le_comap.mp hle)⟩ + have : Algebra.IsUnramifiedAt R Q := hunr Q inferInstance hover + let := Localization.AtPrime.algebraOfLiesOver P Q + rw [Ideal.map_map, ← IsScalarTower.algebraMap_eq, + ((Algebra.isUnramifiedAt_iff_map_eq R P Q).mp inferInstance).2] + exact (IsLocalization.AtPrime.to_map_mem_maximal_iff + (Localization.AtPrime Q) Q x).mpr (hx Q inferInstance hover) + · rw [IsLocalization.AtPrime.map_eq_top_of_not_le _ hle] + simp + +theorem arithFrobAt_eq_of_under_eq + {R S G : Type*} [CommRing R] [CommRing S] [Algebra R S] + [CommGroup G] [MulSemiringAction G S] [SMulCommClass G R S] + [Finite G] [Algebra.IsInvariant R S G] + (Q Q' : Ideal S) [Q.IsPrime] [Q'.IsPrime] + [Finite (S ⧸ Q)] [Finite (S ⧸ Q')] + (h : Q.under R = Q'.under R) : + arithFrobAt R G Q = arithFrobAt R G Q' := + isConj_iff_eq.mp (isConj_arithFrobAt R G Q Q' h) + +theorem arithFrobAt_sub_pow_mem_map + {R S G : Type*} [CommRing R] [CommRing S] [Algebra R S] + [CommGroup G] [MulSemiringAction G S] [SMulCommClass G R S] + [Finite G] [Algebra.IsInvariant R S G] [Algebra.EssFiniteType R S] + [Ring.HasFiniteQuotients S] [FaithfulSMul R S] + (P : Ideal R) [P.IsMaximal] (hP : P ≠ ⊥) + (hunr : Algebra.IsUnramifiedIn S P) + (Q : Ideal S) [Q.IsPrime] [Q.LiesOver P] [Finite (S ⧸ Q)] (x : S) : + arithFrobAt R G Q • x - x ^ Nat.card (R ⧸ P) ∈ P.map (algebraMap R S) := by + apply mem_map_of_forall_mem_primesOver P hunr + intro Q' hQ' hover + have : Q'.LiesOver P := hover + have : Finite (S ⧸ Q') := Ring.HasFiniteQuotients.finiteQuotient + (Ideal.ne_bot_of_liesOver_of_ne_bot hP Q') + have hbase : Q.under R = Q'.under R := (Q.over_def P).symm.trans (Q'.over_def P) + rw [arithFrobAt_eq_of_under_eq Q Q' hbase, Q'.over_def P] + exact IsArithFrobAt.arithFrobAt R G Q' x + +theorem prime_dvd_pow_sub_arithFrobAt + {S G : Type*} [CommRing S] [CommGroup G] [MulSemiringAction G S] + [SMulCommClass G ℤ S] [Finite G] [Algebra.IsInvariant ℤ S G] + [Algebra.EssFiniteType ℤ S] [Ring.HasFiniteQuotients S] [CharZero S] + (p : ℕ) [Fact p.Prime] + (hunr : Algebra.IsUnramifiedIn S (Ideal.span {(p : ℤ)})) + (Q : Ideal S) [Q.IsPrime] [Q.LiesOver (Ideal.span {(p : ℤ)})] + [Finite (S ⧸ Q)] (x : S) : + (p : S) ∣ x ^ p - arithFrobAt ℤ G Q • x := by + have hP : (Ideal.span {(p : ℤ)} : Ideal ℤ) ≠ ⊥ := by + simpa using (Nat.cast_ne_zero.mpr (Fact.out : p.Prime).ne_zero : (p : ℤ) ≠ 0) + have h := arithFrobAt_sub_pow_mem_map (G := G) + (Ideal.span {(p : ℤ)}) hP hunr Q x + rw [Int.card_ideal_quot, Ideal.map_span, Set.image_singleton, map_natCast, + Ideal.mem_span_singleton] at h + simpa only [neg_sub] using dvd_neg.mpr h + +theorem ringOfIntegers_isInvariant + {K : Type*} [Field K] [NumberField K] [IsGalois ℚ K] : + Algebra.IsInvariant ℤ (𝓞 K) (K ≃ₐ[ℚ] K) := by + refine ⟨fun x hx ↦ ?_⟩ + apply (Algebra.isInvariant_of_isGalois ℤ ℚ K (𝓞 K)).isInvariant x + intro g + apply NumberField.RingOfIntegers.ext + change algebraMap (𝓞 K) K (galRestrict ℤ ℚ K (𝓞 K) g x) = algebraMap (𝓞 K) K x + rw [algebraMap_galRestrict_apply] + exact congrArg (fun z : 𝓞 K ↦ (z : K)) (hx g) + +theorem exists_integer_frobenius_congruence + {K : Type*} [Field K] [NumberField K] [IsGalois ℚ K] + (hcomm : ∀ f g : K ≃ₐ[ℚ] K, Commute f g) + (p : ℕ) [Fact p.Prime] + (hunr : Algebra.IsUnramifiedIn (𝓞 K) (Ideal.span {(p : ℤ)})) : + ∃ σ : K ≃ₐ[ℚ] K, + (∀ (Q : Ideal (𝓞 K)) (_ : Q.IsPrime), + Q.LiesOver (Ideal.span {(p : ℤ)}) → IsArithFrobAt ℤ σ Q) ∧ + ∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x := by + let : CommGroup (K ≃ₐ[ℚ] K) := .mk hcomm + have : Algebra.IsInvariant ℤ (𝓞 K) (K ≃ₐ[ℚ] K) := ringOfIntegers_isInvariant + obtain ⟨Q, hQ, hover⟩ := Ideal.exists_maximal_ideal_liesOver_of_isIntegral + (S := 𝓞 K) (Ideal.span {(p : ℤ)}) + have : Q.LiesOver (Ideal.span {(p : ℤ)}) := hover + have hp0 : (Ideal.span {(p : ℤ)} : Ideal ℤ) ≠ ⊥ := by + simpa using (Nat.cast_ne_zero.mpr (Fact.out : p.Prime).ne_zero : (p : ℤ) ≠ 0) + have : Finite ((𝓞 K) ⧸ Q) := Ring.HasFiniteQuotients.finiteQuotient + (Ideal.ne_bot_of_liesOver_of_ne_bot hp0 Q) + refine ⟨arithFrobAt ℤ (K ≃ₐ[ℚ] K) Q, ?_, prime_dvd_pow_sub_arithFrobAt p hunr Q⟩ + intro Q' hQ' hover' + have : Q'.LiesOver (Ideal.span {(p : ℤ)}) := hover' + have : Finite ((𝓞 K) ⧸ Q') := Ring.HasFiniteQuotients.finiteQuotient + (Ideal.ne_bot_of_liesOver_of_ne_bot hp0 Q') + have hbase : Q.under ℤ = Q'.under ℤ := hover.over.symm.trans hover'.over + rw [arithFrobAt_eq_of_under_eq Q Q' hbase] + exact IsArithFrobAt.arithFrobAt ℤ (K ≃ₐ[ℚ] K) Q' + + + +theorem cyclotomic_isUnramifiedIn + (n : ℕ) [NeZero n] (K : Type*) [Field K] [NumberField K] + [IsCyclotomicExtension {n} ℚ K] (p : ℕ) [Fact p.Prime] (hpn : ¬ p ∣ n) : + Algebra.IsUnramifiedIn (𝓞 K) (Ideal.span {(p : ℤ)}) := by + rw [Algebra.isUnramifiedIn_iff_forall_ramificationIdx_eq_one] + intro Q hQ hover + exact IsCyclotomicExtension.Rat.ramificationIdx_eq_of_not_dvd p K Q hpn + +theorem exists_cyclotomic_frobenius_congruence + (n : ℕ) [NeZero n] (K : Type*) [Field K] [NumberField K] + [IsCyclotomicExtension {n} ℚ K] (p : ℕ) [Fact p.Prime] (hpn : ¬ p ∣ n) : + ∃ σ : K ≃ₐ[ℚ] K, + (∀ (Q : Ideal (𝓞 K)) (_ : Q.IsPrime), + Q.LiesOver (Ideal.span {(p : ℤ)}) → IsArithFrobAt ℤ σ Q) ∧ + ∀ x : 𝓞 K, (p : 𝓞 K) ∣ x ^ p - σ • x := by + have : IsGalois ℚ K := IsCyclotomicExtension.isGalois {n} ℚ K + apply exists_integer_frobenius_congruence (p := p) + · intro σ τ + change σ * τ = τ * σ + apply (IsCyclotomicExtension.Rat.galEquivZMod n K).injective + simp only [map_mul, mul_comm] + · exact cyclotomic_isUnramifiedIn n K p hpn + + + +theorem not_isSquare_rat_two : ¬ IsSquare (2 : ℚ) := by + norm_num + + + +theorem real_character_inv {q : ℕ} (χ : DirichletCharacter ℂ q) + (hreal : ∀ a : ZMod q, (χ a).im = 0) : χ⁻¹ = χ := by + rw [← MulChar.star_eq_inv] + apply MulChar.ext' + intro a + exact Complex.conj_eq_iff_im.mpr (hreal a) + +theorem real_character_isQuadratic {q : ℕ} (χ : DirichletCharacter ℂ q) + (hreal : ∀ a : ZMod q, (χ a).im = 0) : χ.IsQuadratic := by + rw [MulChar.isQuadratic_iff_sq_eq_one] + calc + χ ^ 2 = χ⁻¹ * χ := by rw [pow_two, real_character_inv χ hreal] + _ = 1 := inv_mul_cancel χ + + + +open NumberField + +theorem canonicalCyclotomicLevelNeZero (q : ℕ) [NeZero q] : NeZero (8 * q) := + ⟨Nat.mul_ne_zero (by decide) (NeZero.ne q)⟩ +attribute [local instance] canonicalCyclotomicLevelNeZero + +theorem canonicalCyclotomicExtension (n : ℕ) [NeZero n] : + IsCyclotomicExtension {n} ℚ (CyclotomicField n ℚ) := by + let : NeZero (n : ℚ) := ⟨Nat.cast_ne_zero.mpr (NeZero.ne n)⟩ + convert CyclotomicField.isCyclotomicExtension n ℚ using 1 + exact Subsingleton.elim _ _ +attribute [local instance] canonicalCyclotomicExtension + +theorem canonicalCyclotomicNumberField (n : ℕ) [NeZero n] : + NumberField (CyclotomicField n ℚ) := + IsCyclotomicExtension.numberField {n} ℚ (CyclotomicField n ℚ) +attribute [local instance] canonicalCyclotomicNumberField + +theorem canonicalCyclotomicAbelian (n : ℕ) [NeZero n] : + IsAbelianGalois ℚ (CyclotomicField n ℚ) := + IsCyclotomicExtension.isAbelianGalois {n} ℚ (CyclotomicField n ℚ) + +attribute [local instance] canonicalCyclotomicAbelian + + + +open NumberField IsCyclotomicExtension.Rat + +variable (n : ℕ) [NeZero n] (K : Type*) [Field K] [NumberField K] + [IsCyclotomicExtension {n} ℚ K] [IsAbelianGalois ℚ K] + (R : Type*) [CommRing R] [HasEnoughRootsOfUnity R (Monoid.exponent (ZMod n)ˣ)] + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem quadratic_factorsThrough_of_odd_kernel {q d : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) (hχ : χ.IsQuadratic) + (hd : d ∣ q) (hodd : Odd (Nat.card (ZMod.unitsMap hd).ker)) : + χ.FactorsThrough d := by + rw [DirichletCharacter.factorsThrough_iff_ker_unitsMap hd] + intro u hu + rw [MonoidHom.mem_ker, ← Units.val_inj, MulChar.coe_toUnitHom, Units.val_one] + have hupow : u ^ Nat.card (ZMod.unitsMap hd).ker = 1 := by + exact congrArg Subtype.val (pow_card_eq_one' (x := (⟨u, hu⟩ : (ZMod.unitsMap hd).ker))) + have hvpow : χ u ^ Nat.card (ZMod.unitsMap hd).ker = 1 := by + rw [← map_pow, ← Units.val_pow_eq_pow_val, hupow, Units.val_one, map_one] + have hchar := congrArg (fun ψ : DirichletCharacter R q ↦ ψ u) (hχ.pow_odd hodd) + rw [MulChar.pow_apply_coe] at hchar + exact hchar.symm.trans hvpow + +theorem card_unitsMap_kernel_mul_totient {q d : ℕ} [NeZero q] (hd : d ∣ q) : + Nat.card (ZMod.unitsMap hd).ker * d.totient = q.totient := by + have : NeZero d := ⟨fun h ↦ (NeZero.ne q) (Nat.eq_zero_of_zero_dvd (h ▸ hd))⟩ + let f := ZMod.unitsMap hd + have hind : f.ker.index = Nat.card (ZMod d)ˣ := by + rw [← MonoidHom.comap_bot, Subgroup.index_comap_of_surjective ⊥ + (ZMod.unitsMap_surjective hd), Subgroup.index_bot] + have hcard := f.ker.card_mul_index + have hcd : Nat.card (ZMod d)ˣ = d.totient := by + rw [Nat.card_eq_fintype_card, ZMod.card_units_eq_totient] + have hcq : Nat.card (ZMod q)ˣ = q.totient := by + rw [Nat.card_eq_fintype_card, ZMod.card_units_eq_totient] + rwa [hind, hcd, hcq] at hcard + +theorem card_unitsMap_kernel_prime_mul {p m : ℕ} (hp : p.Prime) (hm : m ≠ 0) + (hpm : p ∣ m) : + Nat.card (ZMod.unitsMap (Nat.dvd_mul_left m p)).ker = p := by + have : NeZero (p * m) := ⟨Nat.mul_ne_zero hp.ne_zero hm⟩ + have hcard := card_unitsMap_kernel_mul_totient (Nat.dvd_mul_left m p) + rw [Nat.totient_mul_of_prime_of_dvd hp hpm] at hcard + exact Nat.eq_of_mul_eq_mul_right (Nat.totient_pos.mpr (Nat.pos_of_ne_zero hm)) hcard + +theorem primitive_quadratic_no_odd_prime_square {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) + (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) {p : ℕ} + (hp : p.Prime) (hodd : Odd p) : ¬ p ^ 2 ∣ q := by + intro hpq + obtain ⟨k, hk⟩ := hpq + have hq : q = p * (p * k) := by rw [hk]; ring + have hdiv : p * k ∣ q := ⟨p, by rw [hq, mul_comm]⟩ + have hm : p * k ≠ 0 := by + intro h + exact (NeZero.ne q) (by rw [hq, h, mul_zero]) + have hcard : Nat.card (ZMod.unitsMap hdiv).ker = p := by + clear hk + subst q + exact card_unitsMap_kernel_prime_mul hp hm (Nat.dvd_mul_right p k) + have hfactor := quadratic_factorsThrough_of_odd_kernel χ hχ hdiv (hcard.symm ▸ hodd) + have hle : q ≤ p * k := by + rw [← hprim] + exact Nat.sInf_le hfactor + have hlt : p * k < q := by + rw [hq] + exact lt_mul_of_one_lt_left (Nat.pos_of_ne_zero hm) hp.one_lt + exact (not_lt_of_ge hle) hlt + +theorem unitsMap_sixteen_mul_kernel_square {m : ℕ} [NeZero (16 * m)] + (u : (ZMod (16 * m))ˣ) + (hu : ZMod.unitsMap (show 8 * m ∣ 16 * m from ⟨2, by ring⟩) u = 1) : + ∃ y : ZMod (16 * m), y ^ 2 = (u : ZMod (16 * m)) := by + let hd : 8 * m ∣ 16 * m := ⟨2, by ring⟩ + have hval : ((8 * m : ℕ) : ℤ) ∣ (u.val.val - 1 : ℤ) := by + rw [← Units.val_inj, Units.val_one, ZMod.unitsMap_def, Units.coe_map] at hu + have hcast : ZMod.castHom hd (ZMod (8 * m)) u.val = + ((u.val.val : ℤ) : ZMod (8 * m)) := by simp + rwa [MonoidHom.coe_coe, hcast, ← Int.cast_one, eq_comm, + ZMod.intCast_eq_intCast_iff_dvd_sub] at hu + obtain ⟨k, hk⟩ := hval + have huval : u.val = 1 + (8 * m : ZMod (16 * m)) * (k : ZMod (16 * m)) := by + have hcast := congrArg (fun z : ℤ ↦ (z : ZMod (16 * m))) hk + push_cast at hcast + rw [ZMod.natCast_zmod_val] at hcast + rw [sub_eq_iff_eq_add] at hcast + simpa only [add_comm] using hcast + refine ⟨1 + (4 * m : ZMod (16 * m)) * (k : ZMod (16 * m)), ?_⟩ + rw [huval] + have hz : (16 * m : ZMod (16 * m)) = 0 := by + exact_mod_cast (ZMod.natCast_self (16 * m)) + calc + (1 + (4 * m : ZMod (16 * m)) * k) ^ 2 = + 1 + (8 * m : ZMod (16 * m)) * k + (16 * m : ZMod (16 * m)) * (m * k ^ 2) := by ring + _ = _ := by rw [hz, zero_mul, add_zero] + +theorem quadratic_factorsThrough_eight_mul {m : ℕ} [NeZero (16 * m)] + {R : Type*} [CommRing R] (χ : DirichletCharacter R (16 * m)) (hχ : χ.IsQuadratic) : + χ.FactorsThrough (8 * m) := by + rw [DirichletCharacter.factorsThrough_iff_ker_unitsMap (show 8 * m ∣ 16 * m from ⟨2, by ring⟩)] + intro u hu + rw [MonoidHom.mem_ker] at hu + rw [MonoidHom.mem_ker, ← Units.val_inj, MulChar.coe_toUnitHom, Units.val_one] + obtain ⟨y, hy⟩ := unitsMap_sixteen_mul_kernel_square u hu + have hyunit : IsUnit y := (isUnit_pow_iff (by decide : 2 ≠ 0)).mp (hy.symm ▸ u.isUnit) + rw [← hy, map_pow] + have hs := congrArg (fun ψ : DirichletCharacter R (16 * m) ↦ ψ hyunit.unit) hχ.sq_eq_one + rw [MulChar.pow_apply_coe, MulChar.one_apply_coe] at hs + simpa only [hyunit.unit_spec] using hs + +theorem primitive_quadratic_not_sixteen_dvd {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) + (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) : ¬ 16 ∣ q := by + rintro ⟨m, rfl⟩ + have hm : 0 < m := Nat.pos_of_ne_zero fun h ↦ (NeZero.ne (16 * m)) (by simp [h]) + have hle : 16 * m ≤ 8 * m := by + rw [← hprim] + exact Nat.sInf_le (quadratic_factorsThrough_eight_mul χ hχ) + omega + +theorem quadratic_factorsThrough_odd_two_mul {m : ℕ} [NeZero (2 * m)] + {R : Type*} [CommRing R] (χ : DirichletCharacter R (2 * m)) + (hχ : χ.IsQuadratic) (hm : Odd m) : χ.FactorsThrough m := by + have hmpos : 0 < m := Nat.pos_of_ne_zero fun h ↦ (NeZero.ne (2 * m)) (by simp [h]) + have hcard : Nat.card (ZMod.unitsMap (Nat.dvd_mul_left m 2)).ker = 1 := by + apply Nat.eq_of_mul_eq_mul_right (Nat.totient_pos.mpr hmpos) + rw [one_mul, card_unitsMap_kernel_mul_totient, Nat.totient_two_mul_of_odd hm] + apply quadratic_factorsThrough_of_odd_kernel χ hχ (Nat.dvd_mul_left m 2) + rw [hcard] + decide + +theorem primitive_quadratic_mod_four_ne_two {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) + (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) : q % 4 ≠ 2 := by + intro hqmod + have hq : q = 2 * (2 * (q / 4) + 1) := by omega + obtain ⟨m, hm, hq⟩ : ∃ m, Odd m ∧ q = 2 * m := + ⟨2 * (q / 4) + 1, ⟨q / 4, rfl⟩, hq⟩ + subst q + have hle : 2 * m ≤ m := by + rw [← hprim] + exact Nat.sInf_le (quadratic_factorsThrough_odd_two_mul χ hχ hm) + have hmpos : 0 < m := Nat.pos_of_ne_zero fun h ↦ (NeZero.ne (2 * m)) (by simp [h]) + omega + +theorem square_divisor_of_primitive_quadratic {q c : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) + (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) (hc : c ^ 2 ∣ q) : c = 1 ∨ c = 2 := by + have hc0 : c ≠ 0 := by + intro h + apply NeZero.ne q + apply Nat.eq_zero_of_zero_dvd + simpa [h] using hc + obtain ⟨k, hk⟩ : ∃ k, c = 2 ^ k := ⟨_, Nat.eq_prime_pow_of_unique_prime_dvd (p := 2) hc0 (by + intro p hp hpc + by_contra hne + exact primitive_quadratic_no_odd_prime_square χ hχ hprim hp (hp.odd_of_ne_two hne) + ((pow_dvd_pow_of_dvd hpc 2).trans hc))⟩ + have hk1 : k ≤ 1 := by + by_contra! hk2 + have h16 : 16 ∣ c ^ 2 := by + rw [hk, ← pow_mul] + exact pow_dvd_pow 2 (by omega : 4 ≤ k * 2) + exact primitive_quadratic_not_sixteen_dvd χ hχ hprim (h16.trans hc) + interval_cases k <;> simp_all + +theorem primitive_quadratic_radicand_eq_or_four_mul {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) + (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + {D c d : ℤ} (hD : D.natAbs = q) (hDc : D = c ^ 2 * d) : D = d ∨ D = 4 * d := by + have hdiv : c.natAbs ^ 2 ∣ q := by + have h := Int.natAbs_dvd_natAbs.mpr (show c ^ 2 ∣ D from ⟨d, hDc⟩) + simpa only [Int.natAbs_pow, hD] using h + rcases square_divisor_of_primitive_quadratic χ hχ hprim hdiv with hc | hc + · have hsq : c ^ 2 = 1 := by + have h := congrArg (fun n : ℕ ↦ (n : ℤ) ^ 2) hc + norm_num [Int.natCast_natAbs] at h + rcases h with rfl | rfl <;> norm_num + left + simpa only [hsq, one_mul] using hDc + · have hsq : c ^ 2 = 4 := by + have h := congrArg (fun n : ℕ ↦ (n : ℤ) ^ 2) hc + norm_num [Int.natCast_natAbs] at h + exact h + right + simpa only [hsq] using hDc + +theorem odd_divisor_primitive_quadratic_squarefree {q m : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) + (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) (hm : Odd m) (hmq : m ∣ q) : + Squarefree m := by + rw [Nat.squarefree_iff_prime_squarefree] + intro p hp hpp + rcases hp.eq_two_or_odd' with rfl | hodd + · exact hm.not_two_dvd_nat ((Nat.dvd_mul_right 2 2).trans hpp) + · exact primitive_quadratic_no_odd_prime_square χ hχ hprim hp hodd + ((by simpa only [pow_two] using hpp : p ^ 2 ∣ m).trans hmq) + +theorem primitive_quadratic_conductor_shape {q : ℕ} [NeZero q] + {R : Type*} [CommRing R] (χ : DirichletCharacter R q) + (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) : + ∃ u : ℕ, Odd u ∧ Squarefree u ∧ (q = u ∨ q = 4 * u ∨ q = 8 * u) := by + have h16 : q % 16 ≠ 0 := fun h ↦ + primitive_quadratic_not_sixteen_dvd χ hχ hprim (Nat.dvd_of_mod_eq_zero h) + have h4 := primitive_quadratic_mod_four_ne_two χ hχ hprim + by_cases hodd : q % 2 = 1 + · have ho : Odd q := Nat.odd_iff.mpr hodd + exact ⟨q, ho, odd_divisor_primitive_quadratic_squarefree χ hχ hprim ho dvd_rfl, + Or.inl rfl⟩ + · by_cases h8 : q % 8 = 0 + · have hq : q = 8 * (q / 8) := by omega + have ho : Odd (q / 8) := Nat.odd_iff.mpr (by omega) + have hd : q / 8 ∣ q := ⟨8, by omega⟩ + exact ⟨q / 8, ho, odd_divisor_primitive_quadratic_squarefree χ hχ hprim ho hd, + Or.inr (Or.inr hq)⟩ + · have hq : q = 4 * (q / 4) := by omega + have ho : Odd (q / 4) := Nat.odd_iff.mpr (by omega) + have hd : q / 4 ∣ q := ⟨4, by omega⟩ + exact ⟨q / 4, ho, odd_divisor_primitive_quadratic_squarefree χ hχ hprim ho hd, + Or.inr (Or.inl hq)⟩ + +end WeightedTorusJets + +open scoped NumberField + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/SqrtTwoField.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SqrtTwoField.lean new file mode 100644 index 0000000000000000000000000000000000000000..6690e9ff667e48383732e697159459f4d69b6106 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SqrtTwoField.lean @@ -0,0 +1,513 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.QuadraticAdjoinBasis + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +namespace WeightedTorusJets + +theorem primitive_mod_four_character_neg_one (χ : DirichletCharacter ℤ 4) + (hprim : χ.IsPrimitive) : χ (-1) = -1 := by + have hne : χ ≠ 1 := by + intro h + have hc := hprim + rw [DirichletCharacter.isPrimitive_def, h, DirichletCharacter.conductor_one] at hc + norm_num at hc + obtain ⟨u, hu⟩ := MulChar.ne_one_iff.mp hne + have hu_cases : u = 1 ∨ u = -1 := by + exact (by decide : ∀ u : (ZMod 4)ˣ, u = 1 ∨ u = -1) u + rcases hu_cases with rfl | rfl + · simp at hu + · have hval := Int.isUnit_eq_one_or ((isUnit_neg_one : IsUnit (-1 : ZMod 4)).map χ) + exact hval.resolve_left (by simpa only [Units.val_neg, Units.val_one] using hu) + + + +theorem primitive_four_mul_exists_odd_part {u : ℕ} [NeZero u] (hu : Odd u) + (χ : DirichletCharacter ℤ (4 * u)) (hprim : χ.IsPrimitive) : + ∃ η : DirichletCharacter ℤ u, η.IsPrimitive ∧ χ (-1) = -η (-1) := by + have hc : Nat.Coprime 4 u := by + simpa using hu.coprime_two_left.pow_left 2 + refine ⟨crtCharacterRight hc χ, crtCharacterRight_isPrimitive hc χ hprim, ?_⟩ + rw [crtCharacter_neg_one hc χ, primitive_mod_four_character_neg_one _ + (crtCharacterLeft_isPrimitive hc χ hprim), neg_one_mul] + + + +theorem primitive_four_mul_quadratic_signed_part_mod_four {u : ℕ} [NeZero u] + (χ : DirichletCharacter ℤ (4 * u)) (hprim : χ.IsPrimitive) (hu : Odd u) : + (χ (-1) * (u : ℤ)) % 4 = 3 := by + obtain ⟨η, hηprim, hneg⟩ := primitive_four_mul_exists_odd_part hu χ hprim + have hηquad : η.IsQuadratic := by + intro a + by_cases ha : IsUnit a + · exact Or.inr (Int.isUnit_eq_one_or (ha.map η)) + · exact Or.inl (η.map_nonunit ha) + have hodd := primitive_odd_quadratic_signed_level_mod_four η hηquad hηprim hu + rw [hneg, neg_mul] + omega + + + +theorem fundamentalDiscr_eight_odd_case {D d : ℤ} {u : ℕ} (hu : Odd u) + (hd : Squarefree d) (hDd : D = d ∨ D = 4 * d) (hD : D.natAbs = 8 * u) : + Int.IsFundamentalDiscr D := by + rcases hDd with rfl | hDd + · have hf := Nat.squarefree_iff_prime_squarefree.mp (Int.squarefree_natAbs.mpr hd) + exact (hf 2 Nat.prime_two ⟨2 * u, by omega⟩).elim + · rw [hDd, Int.isFundamentalDiscr_four_mul] + refine ⟨hd, Or.inl ?_⟩ + have heq : 4 * d.natAbs = 8 * u := by simpa [hDd, Int.natAbs_mul] using hD + have hn : d.natAbs = 2 * u := by omega + have hh := congrArg (fun n : ℕ ↦ (n : ℤ)) hn + rw [Int.natCast_natAbs, Nat.cast_mul, Nat.cast_ofNat] at hh + obtain ⟨k, hk⟩ := hu + rcases le_total 0 d with h | h + · rw [abs_of_nonneg h] at hh + omega + · rw [abs_of_nonpos h] at hh + omega + +theorem fundamentalDiscr_four_parity_case {D d s : ℤ} {u : ℕ} + (hd : Squarefree d) (hDd : D = d ∨ D = 4 * d) + (hD : D = s * (4 * (u : ℤ))) (hparity : (s * (u : ℤ)) % 4 = 3) : + Int.IsFundamentalDiscr D := by + rcases hDd with rfl | hDd + · have hf := Int.squarefree_iff_prime_sq_not_dvd.mp hd 2 Nat.prime_two + apply (hf ?_).elim + refine ⟨s * (u : ℤ), ?_⟩ + rw [hD] + ring + · rw [hDd, Int.isFundamentalDiscr_four_mul] + refine ⟨hd, Or.inr ?_⟩ + have heq : d = s * (u : ℤ) := by + apply mul_left_cancel₀ (by norm_num : (4 : ℤ) ≠ 0) + calc + 4 * d = D := hDd.symm + _ = s * (4 * (u : ℤ)) := hD + _ = 4 * (s * (u : ℤ)) := by ring + rwa [heq] + + + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem exists_signed_squarefree_characterField_generator {n : ℕ} [NeZero n] {K : Type*} + [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] [IsAbelianGalois ℚ K] + (χ : DirichletCharacter ℂ n) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + (hne : χ ≠ 1) : + ∃ (D d : ℤ) (a : K), D = integerCharacter χ hχ (-1) * (n : ℤ) ∧ + D.natAbs = n ∧ Squarefree d ∧ (D = d ∨ D = 4 * d) ∧ + d.natAbs ≤ n ∧ d.natAbs ∣ n ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : K) ∧ + IsIntegral ℤ a ∧ IntermediateField.adjoin ℚ {a} = characterField n K ℂ χ ∧ + ∀ σ : Gal(K/ℚ), σ a = (integerCharacter χ hχ (galEquivZMod n K σ) : K) * a := by + let χI := integerCharacter χ hχ + let χK := χI.ringHomComp (Int.castRingHom K) + have hI := integerCharacter_isQuadratic χ hχ + have hpI := integerCharacter_isPrimitive χ hχ hprim + have hK : χK.IsQuadratic := hI.comp (Int.castRingHom K) + have hpK : DirichletCharacter.IsPrimitive χK := by + rw [DirichletCharacter.isPrimitive_def, conductor_ringHomComp χI (Int.castRingHom K) + (Int.cast_injective (α := K))] + exact hpI + let e := AddChar.zmodChar n (zeta_spec n ℚ K).pow_eq_one + have he : e.IsPrimitive := AddChar.zmodChar_primitive_of_primitive_root n (zeta_spec n ℚ K) + obtain ⟨D, hDabs, hgD⟩ := primitive_quadratic_gaussSum_integer_square hpK hK he + have hD : D ≠ 0 := by + intro h + have := hDabs + rw [h, Int.natAbs_zero] at this + exact (NeZero.ne n) this.symm + obtain ⟨d, c, a, hd, hbound, hc, hdc, ha, hint, hga, hadj⟩ := + exists_squarefree_generator hD hgD + have hadjχ : IntermediateField.adjoin ℚ {a} = characterField n K ℂ χ := by + rw [hadj, gaussSum_adjoin_eq_characterField χI hI hpI e he] + congr 1 + exact integerCharacter_ringHomComp χ hχ + have hdiv : d.natAbs ∣ n := by + rw [← hDabs] + exact Int.natAbs_dvd_natAbs.mpr ⟨c ^ 2, by rw [hdc, mul_comm]⟩ + have hnsq : ¬ IsSquare (d : ℚ) := by + apply not_isSquare_of_quadratic_adjoin ha + rw [hadjχ] + exact characterField_finrank n K ℂ χ hχ hne + have hDchar : D = χI (-1) * (n : ℤ) := by + apply Int.cast_injective (α := K) + push_cast + calc + (D : K) = gaussSum χK e ^ 2 := hgD.symm + _ = χK (-1) * (n : K) := primitive_quadratic_gaussSum_sq hpK hK he + _ = (χI (-1) : K) * (n : K) := rfl + have hcases := primitive_quadratic_radicand_eq_or_four_mul χ hχ hprim hDabs hdc + refine ⟨D, d, a, hDchar, hDabs, hd, hcases, hDabs ▸ hbound, hdiv, hnsq, + ha, hint, hadjχ, ?_⟩ + intro σ + have hact := cyclotomic_gaussSum_action χK hK e σ + rw [hga, map_mul, map_intCast] at hact + apply mul_left_cancel₀ (Int.cast_ne_zero.mpr hc : (c : K) ≠ 0) + change (c : K) * σ a = (χI (galEquivZMod n K σ) : K) * ((c : K) * a) at hact + simpa only [χI, mul_left_comm] using hact + +end WeightedTorusJets + +namespace WeightedTorusJets + +open Module NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem normalized_signed_conductor_isFundamentalDiscr {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℤ q) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + {D d : ℤ} (hDsign : D = χ (-1) * (q : ℤ)) (hDabs : D.natAbs = q) + (hd : Squarefree d) (hDd : D = d ∨ D = 4 * d) : Int.IsFundamentalDiscr D := by + obtain ⟨u, hu, hsfu, hq | hq | hq⟩ := primitive_quadratic_conductor_shape χ hχ hprim + · have hodd : Odd q := hq ▸ hu + apply Int.isFundamentalDiscr_iff_squarefree.mpr + refine Or.inl ⟨?_, Int.squarefree_natAbs.mp ?_⟩ + · rw [hDsign] + exact primitive_odd_quadratic_signed_level_mod_four χ hχ hprim hodd + · rwa [hDabs, hq] + · subst hq + let : NeZero u := ⟨hsfu.ne_zero⟩ + exact fundamentalDiscr_four_parity_case hd hDd + (by simpa only [Nat.cast_mul, Nat.cast_ofNat] using hDsign) + (primitive_four_mul_quadratic_signed_part_mod_four χ hprim hu) + · exact fundamentalDiscr_eight_odd_case hu hd hDd (hDabs.trans hq) + +theorem characterField_discr_eq_signed_conductor {n : ℕ} [NeZero n] + {K : Type*} [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] + [IsAbelianGalois ℚ K] (χ : DirichletCharacter ℂ n) (hχ : χ.IsQuadratic) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) : + NumberField.discr (characterField n K ℂ χ) = integerCharacter χ hχ (-1) * (n : ℤ) := by + obtain ⟨D, d, a, hDsign, hDabs, hd, hDd, _, _, _, ha, hint, hadj, _⟩ := + exists_signed_squarefree_characterField_generator (K := K) χ hχ hprim hne + have hfund := normalized_signed_conductor_isFundamentalDiscr (integerCharacter χ hχ) + (integerCharacter_isQuadratic χ hχ) (integerCharacter_isPrimitive χ hχ hprim) + hDsign hDabs hd hDd + have hdim : Module.finrank ℚ (IntermediateField.adjoin ℚ {a}) = 2 := by + rw [hadj] + exact characterField_finrank n K ℂ χ hχ hne + have hai : IsIntegral ℚ a := hint.tower_top + let u := quadraticAdjoinBasis a hai hdim + let a' := IntermediateField.AdjoinSimple.gen ℚ a + have hu : (u : Fin 2 → IntermediateField.adjoin ℚ {a}) = ![1, a'] := by + funext i + exact quadraticAdjoinBasis_apply a hai hdim i + have ha' : a' ^ 2 = (d : IntermediateField.adjoin ℚ {a}) := by + apply Subtype.ext + exact ha + have hdiscr : NumberField.discr (IntermediateField.adjoin ℚ {a}) = D := by + rcases hDd with hDd | hDd + · rw [hDd] at hfund ⊢ + have hd4 : d % 4 ≠ 0 := by + intro h + exact Int.squarefree_iff_prime_sq_not_dvd.mp hd 2 Nat.prime_two + (by simpa using Int.dvd_of_emod_eq_zero h) + exact numberField_discr_quadratic_eq_self u a' d hu ha' hd + (hfund.emod_four_eq_zero_or_one.resolve_left hd4) + · rw [hDd] at hfund ⊢ + exact numberField_discr_quadratic_eq_four_mul u a' d hu ha' hd + (Int.isFundamentalDiscr_four_mul.mp hfund).2 + rw [hadj, hDsign] at hdiscr + exact hdiscr + + + +open NumberField IsCyclotomicExtension.Rat + +variable (n : ℕ) [NeZero n] (K : Type*) [Field K] [NumberField K] + [IsCyclotomicExtension {n} ℚ K] [IsAbelianGalois ℚ K] + (R : Type*) [CommRing R] [HasEnoughRootsOfUnity R (Monoid.exponent (ZMod n)ˣ)] + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem characterField_changeLevel_discr_eq_signed_conductor {q m : ℕ} + [NeZero q] [NeZero m] {L : Type*} [Field L] [NumberField L] + [IsCyclotomicExtension {m} ℚ L] [IsAbelianGalois ℚ L] + (hdiv : q ∣ m) (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) : + NumberField.discr (characterField m L ℂ (DirichletCharacter.changeLevel hdiv χ)) = + integerCharacter χ hχ (-1) * (q : ℤ) := by + let K := cyclotomicDivisorField q m L + let : IsCyclotomicExtension {q} ℚ K := + cyclotomicDivisorField_isCyclotomicExtension q m L hdiv + let : IsAbelianGalois ℚ K := IsCyclotomicExtension.isAbelianGalois {q} ℚ K + rw [characterField_changeLevel q K ℂ L hdiv χ hχ] + exact (NumberField.discr_eq_discr_of_algEquiv (characterField q K ℂ χ) + ((characterField q K ℂ χ).equivMap (IsScalarTower.toAlgHom ℚ K L))).symm.trans + (characterField_discr_eq_signed_conductor χ hχ hprim hne) + +theorem characterField_changeLevel_discr_natAbs {q m : ℕ} + [NeZero q] [NeZero m] {L : Type*} [Field L] [NumberField L] + [IsCyclotomicExtension {m} ℚ L] [IsAbelianGalois ℚ L] + (hdiv : q ∣ m) (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) : + (NumberField.discr + (characterField m L ℂ (DirichletCharacter.changeLevel hdiv χ))).natAbs = q := by + rw [characterField_changeLevel_discr_eq_signed_conductor hdiv χ hχ hprim hne] + rcases Int.isUnit_eq_one_or ((isUnit_neg_one : IsUnit (-1 : ZMod q)).map + (integerCharacter χ hχ)) with h | h <;> simp [h] + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField + +theorem quadraticAdjoin_discriminant {L : Type*} [Field L] [NumberField L] + (a : L) (d : ℤ) (ha : a ^ 2 = d) (hd : Squarefree d) + (hns : ¬ IsSquare (d : ℚ)) : + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + (Algebra.IsUnramifiedIn (𝓞 (IntermediateField.adjoin ℚ {a})) + (Ideal.span {(2 : ℤ)}) ↔ d % 4 = 1) := by + let F := IntermediateField.adjoin ℚ {a} + let A : F := IntermediateField.AdjoinSimple.gen ℚ a + have hroot : a ^ 2 = algebraMap ℚ L (d : ℚ) := by simpa using ha + have hi : IsIntegral ℚ a := IsIntegral.of_pow (by decide : 0 < 2) + (hroot ▸ isIntegral_algebraMap) + have hdim := finrank_adjoin_sqrt a (d : ℚ) hroot hns + let u : Module.Basis (Fin 2) ℚ F := quadraticAdjoinBasis a hi hdim + have hu : (u : Fin 2 → F) = ![1, A] := by + funext i + exact quadraticAdjoinBasis_apply a hi hdim i + have hA : A ^ 2 = (d : F) := by + apply Subtype.ext + exact ha + refine ⟨?_, isFundamentalDiscr_quadratic u A d hu hA hd, + isUnramifiedIn_two_iff_radical_mod_four u A d hu hA hd⟩ + by_cases hd1 : d % 4 = 1 + · simp only [ite_eq_left hd1] + exact numberField_discr_quadratic_eq_self u A d hu hA hd hd1 + · simp only [ite_eq_right hd1] + have hd0 : d % 4 ≠ 0 := by + intro h + exact Int.squarefree_iff_prime_sq_not_dvd.mp hd 2 Nat.prime_two + (by simpa using Int.dvd_of_emod_eq_zero h) + exact numberField_discr_quadratic_eq_four_mul u A d hu hA hd (by omega) + + + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +end WeightedTorusJets + +namespace WeightedTorusJets + +open IsCyclotomicExtension IsCyclotomicExtension.Rat + +noncomputable def sourceSqrtTwoField (q : ℕ) [NeZero (8 * q)] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {8 * q} ℚ L] : + IntermediateField ℚ L := + let ζ := zeta (8 * q) ℚ L ^ ((8 * q) / 8) + IntermediateField.adjoin ℚ ({ζ - ζ ^ 3} : Set L) + +theorem sourceSqrtTwoField_root_sq (q : ℕ) [NeZero (8 * q)] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {8 * q} ℚ L] : + let ζ := zeta (8 * q) ℚ L ^ ((8 * q) / 8) + (ζ - ζ ^ 3) ^ 2 = 2 := by + have h8m : 8 ∣ 8 * q := dvd_mul_right 8 q + exact primitive_eighth_root_difference_sq + ((zeta_spec (8 * q) ℚ L).pow (NeZero.pos (8 * q)) (Nat.div_mul_cancel h8m).symm) + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField IsCyclotomicExtension IsCyclotomicExtension.Rat + +theorem exists_auxiliary_sqrt_pair_of_field_ne (q : ℕ) [NeZero q] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {8 * q} ℚ L] + [NeZero (8 * q)] [IsAbelianGalois ℚ L] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) (hprim : χ.IsPrimitive) + (hne : χ ≠ 1) (hfield : characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ sourceSqrtTwoField q L) : + ∃ (d : ℤ) (a b : L), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : L) ∧ b ^ 2 = 2 ∧ + IsIntegral ℤ a ∧ IsIntegral ℤ b ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + IntermediateField.adjoin ℚ {a} ≠ IntermediateField.adjoin ℚ {b} ∧ + ∀ (p : ℕ), p.Prime → ¬ p ∣ 2 * q → + ∀ (P : Ideal (𝓞 L)), P.under ℤ = Ideal.span {(p : ℤ)} → + ∀ (σ : Gal(L/ℚ)), IsArithFrobAt ℤ σ P → χ p = -1 → σ a = -a := by + have hqm : q ∣ 8 * q := dvd_mul_left q 8 + have h8m : 8 ∣ 8 * q := dvd_mul_right 8 q + let K := cyclotomicDivisorField q (8 * q) L + let : IsCyclotomicExtension {q} ℚ K := + cyclotomicDivisorField_isCyclotomicExtension q (8 * q) L hqm + let : IsAbelianGalois ℚ K := IsCyclotomicExtension.isAbelianGalois {q} ℚ K + obtain ⟨d, aK, hd, hbound, hddiv, hdns, haK, _, hadjK, hsign⟩ := + exists_squarefree_generator_frobenius_sign q (8 * q) K L hqm χ hχ hprim hne + let a : L := algebraMap K L aK + have ha : a ^ 2 = (d : L) := by + change (algebraMap K L aK) ^ 2 = _ + rw [← map_pow, haK, map_intCast] + let ζ : L := zeta (8 * q) ℚ L ^ ((8 * q) / 8) + have hζ : IsPrimitiveRoot ζ 8 := + (zeta_spec (8 * q) ℚ L).pow (NeZero.pos (8 * q)) (Nat.div_mul_cancel h8m).symm + let b := ζ - ζ ^ 3 + have hb : b ^ 2 = 2 := primitive_eighth_root_difference_sq hζ + have hadj : IntermediateField.adjoin ℚ {a} = + characterField (8 * q) L ℂ (DirichletCharacter.changeLevel hqm χ) := by + rw [characterField_changeLevel q K ℂ L hqm χ hχ, ← hadjK, + IntermediateField.adjoin_map, Set.image_singleton] + rfl + have hneq : IntermediateField.adjoin ℚ {a} ≠ IntermediateField.adjoin ℚ {b} := by + intro heq + exact hfield (hadj.symm.trans heq) + refine ⟨d, a, b, hd, hbound, hddiv, hdns, ha, hb, ?_, ?_, hadj, hneq, ?_⟩ + · apply IsIntegral.of_pow (by decide : 0 < 2) + rw [ha] + exact isIntegral_algebraMap + · apply IsIntegral.of_pow (by decide : 0 < 2) + rw [hb] + exact isIntegral_natCast 2 + · intro p hp hpn P hP σ hσ hχp + have hc : p.Coprime (2 * q) := hp.coprime_iff_not_dvd.mpr hpn + have h2 := (Nat.coprime_mul_iff_right.mp hc).1 + have hq := (Nat.coprime_mul_iff_right.mp hc).2 + have h8 : p.Coprime 8 := by simpa using h2.pow_right 3 + exact hsign p hp (h8.mul_right hq) P hP σ hσ hχp + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField + +theorem source_biquadratic_arithmetic_of_field_ne (q : ℕ) [NeZero q] + (L : Type*) [Field L] [NumberField L] [IsCyclotomicExtension {8 * q} ℚ L] + [NeZero (8 * q)] [IsAbelianGalois ℚ L] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) (hfield : characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ sourceSqrtTwoField q L) : + ∃ (d : ℤ) (a b : L), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : L) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ (p : ℕ), p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x)) := by + have hquad := real_character_isQuadratic χ hreal + obtain ⟨d, a, b, hd, hbound, hddiv, hdns, ha, hb, _, _, hadj, hfields, hsign⟩ := + exists_auxiliary_sqrt_pair_of_field_ne q L χ hquad hprim hne hfield + have haRat : a ^ 2 = algebraMap ℚ L (d : ℚ) := by simpa using ha + have hbRat : b ^ 2 = algebraMap ℚ L (2 : ℚ) := by simpa using hb + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let v := sqrtPairBasis a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields + have hv (i : Fin 4) : v i = ![1, a', b', a' * b'] i := by + apply Subtype.ext + change (sqrtPairBasis a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields i : L) = _ + rw [coe_sqrtPairBasis_apply] + fin_cases i <;> rfl + have ha' : a' ^ 2 = (d : B) := by apply Subtype.ext; exact ha + have hb' : b' ^ 2 = (2 : B) := by apply Subtype.ext; exact hb + have hint := biquadratic_monomials_integral a' b' d 2 ha' (by simpa using hb') + obtain ⟨σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, hdesc⟩ := + sqrtPair_frobenius_directions a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields + obtain ⟨hformula, hfund, _⟩ := quadraticAdjoin_discriminant a d ha hd hdns + refine ⟨d, a, b, hd, hbound, hddiv, hdns, ha, hb, hadj, ?_, hfund, hformula, v, hv, ?_, ?_, + σ, τ, hσa, hσb, hτa, hτb, hcard, hall, hcomm, ?_⟩ + · rw [hadj] + exact characterField_changeLevel_discr_natAbs (dvd_mul_left q 8) χ hquad hprim hne + · intro i + rw [hv] + fin_cases i + · exact hint.1 + · exact hint.2.1 + · exact hint.2.2.1 + · exact hint.2.2.2 + · exact finrank_adjoin_pair_sqrt a b (d : ℚ) 2 haRat hbRat hdns not_isSquare_rat_two hfields + · intro p hp hpn hχp + let : Fact p.Prime := ⟨hp⟩ + let : NeZero (8 * q) := ⟨Nat.mul_ne_zero (by decide) (NeZero.ne q)⟩ + have hc : p.Coprime (2 * q) := hp.coprime_iff_not_dvd.mpr hpn + have h2 := (Nat.coprime_mul_iff_right.mp hc).1 + have hq := (Nat.coprime_mul_iff_right.mp hc).2 + have h8 : p.Coprime 8 := by simpa using h2.pow_right 3 + have hpm : ¬ p ∣ 8 * q := hp.coprime_iff_not_dvd.mp (h8.mul_right hq) + obtain ⟨φ, hfrob, hglobal⟩ := exists_cyclotomic_frobenius_congruence (8 * q) L p hpm + obtain ⟨P, hP, hover⟩ := Ideal.exists_maximal_ideal_liesOver_of_isIntegral + (S := 𝓞 L) (Ideal.span {(p : ℤ)}) + exact hdesc p φ (hsign p hp hpn P hover.over.symm φ (hfrob P inferInstance hover) hχp) hglobal + +end WeightedTorusJets + +namespace WeightedTorusJets + +open NumberField + +attribute [local instance] canonicalCyclotomicLevelNeZero canonicalCyclotomicExtension + canonicalCyclotomicNumberField canonicalCyclotomicAbelian + +theorem source_biquadratic_arithmetic_canonical_of_field_ne (q : ℕ) [NeZero q] + (χ : DirichletCharacter ℂ q) (hreal : ∀ x : ZMod q, (χ x).im = 0) + (hprim : χ.IsPrimitive) (hne : χ ≠ 1) (hfield : characterField (8 * q) (CyclotomicField (8 * q) ℚ) ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ≠ + sourceSqrtTwoField q (CyclotomicField (8 * q) ℚ)) : + let L := CyclotomicField (8 * q) ℚ + ∃ (d : ℤ) (a b : L), Squarefree d ∧ d.natAbs ≤ q ∧ d.natAbs ∣ q ∧ + ¬ IsSquare (d : ℚ) ∧ a ^ 2 = (d : L) ∧ b ^ 2 = 2 ∧ + IntermediateField.adjoin ℚ {a} = characterField (8 * q) L ℂ + (DirichletCharacter.changeLevel (dvd_mul_left q 8) χ) ∧ + (NumberField.discr (IntermediateField.adjoin ℚ {a})).natAbs = q ∧ + Int.IsFundamentalDiscr (NumberField.discr (IntermediateField.adjoin ℚ {a})) ∧ + NumberField.discr (IntermediateField.adjoin ℚ {a}) = + (if d % 4 = 1 then d else 4 * d) ∧ + let B := IntermediateField.adjoin ℚ ({a, b} : Set L) + let a' : B := ⟨a, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + let b' : B := ⟨b, IntermediateField.subset_adjoin ℚ _ (by simp)⟩ + ∃ v : Module.Basis (Fin 4) ℚ B, + (∀ i, v i = ![1, a', b', a' * b'] i) ∧ + (∀ i, IsIntegral ℤ (v i)) ∧ Module.finrank ℚ B = 4 ∧ + ∃ σ τ : B ≃ₐ[ℚ] B, + σ a' = -a' ∧ σ b' = b' ∧ τ a' = a' ∧ τ b' = -b' ∧ + Nat.card (B ≃ₐ[ℚ] B) = 4 ∧ + (∀ f : B ≃ₐ[ℚ] B, f = 1 ∨ f = σ ∨ f = τ ∨ f = σ * τ) ∧ + (∀ f g : B ≃ₐ[ℚ] B, Commute f g) ∧ + ∀ (p : ℕ), p.Prime → ¬ p ∣ 2 * q → χ p = -1 → + ((∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - σ • x) ∨ + (∀ x : 𝓞 B, (p : 𝓞 B) ∣ x ^ p - (σ * τ) • x)) := by + exact source_biquadratic_arithmetic_of_field_ne q (CyclotomicField (8 * q) ℚ) + χ hreal hprim hne hfield + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumCardFilterSumMin.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumCardFilterSumMin.lean new file mode 100644 index 0000000000000000000000000000000000000000..a956e3437c1661d48f240c6c6e784feae38a732c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumCardFilterSumMin.lean @@ -0,0 +1,92 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.GreedyPivots + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets + +open scoped BigOperators + +theorem sum_card_filter_lt_eq_sum_min {ι : Type*} (s : Finset ι) (a : ι → ℕ) (T : ℕ) : + (∑ k ∈ Finset.range T, (s.filter fun i => k < a i).card) = + ∑ i ∈ s, min T (a i) := by + classical + simp_rw [Finset.card_filter] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i hi + rw [← Finset.card_filter] + have h : (Finset.range T).filter (fun k => k < a i) = Finset.range (min T (a i)) := by + ext k + simp [lt_min_iff] + rw [h, Finset.card_range] + +theorem sum_range_div_le_of_bounded_multiplicity {ι : Type*} (s : Finset ι) + (a : ι → ℕ) (Q : ℕ) (hQpos : 0 < Q) + (hQ : ∀ k, (s.filter fun i => a i = k).card ≤ Q) : + (∑ i ∈ Finset.range s.card, i / Q) ≤ ∑ i ∈ s, a i := by + classical + have htail (k : ℕ) : + ((Finset.range s.card).filter fun i => k < i / Q).card ≤ + (s.filter fun i => k < a i).card := by + have hlow : ((Finset.range s.card).filter fun i => i / Q ≤ k).card = + min s.card ((k + 1) * Q) := by + have hset : (Finset.range s.card).filter (fun i => i / Q ≤ k) = + Finset.range (min s.card ((k + 1) * Q)) := by + ext i + simp only [Finset.mem_filter, Finset.mem_range, lt_min_iff] + rw [← Nat.lt_succ_iff, Nat.div_lt_iff_lt_mul hQpos] + rw [hset, Finset.card_range] + have hsmall : (s.filter fun i => a i ≤ k).card ≤ min s.card ((k + 1) * Q) := by + apply le_min (Finset.card_filter_le _ _) + simpa [Nat.lt_succ_iff, Nat.mul_comm] using card_filter_lt_le_mul s a Q (k + 1) hQ + have hc := Finset.card_filter_add_card_filter_not (s := s) (fun i => a i ≤ k) + have hd := Finset.card_filter_add_card_filter_not (s := Finset.range s.card) + (fun i => i / Q ≤ k) + simp only [not_le, Finset.card_range] at hc hd + omega + calc + _ = ∑ i ∈ Finset.range s.card, min s.card (i / Q) := by + apply Finset.sum_congr rfl + intro i hi + exact (min_eq_right ((Nat.div_le_self i Q).trans (Finset.mem_range.mp hi).le)).symm + _ = ∑ k ∈ Finset.range s.card, + ((Finset.range s.card).filter fun i => k < i / Q).card := + (sum_card_filter_lt_eq_sum_min (Finset.range s.card) (fun i => i / Q) s.card).symm + _ ≤ ∑ k ∈ Finset.range s.card, (s.filter fun i => k < a i).card := + Finset.sum_le_sum fun k _ => htail k + _ = ∑ i ∈ s, min s.card (a i) := sum_card_filter_lt_eq_sum_min s a s.card + _ ≤ ∑ i ∈ s, a i := Finset.sum_le_sum fun i _ => min_le_right _ _ + +theorem filling_order_minimizes_sum (M Q : ℕ) (hQ : 0 < Q) : + (∀ k, ((Finset.range M).filter fun i => i / Q = k).card ≤ Q) ∧ + ∀ a : ℕ → ℕ, (∀ k, ((Finset.range M).filter fun i => a i = k).card ≤ Q) → + (∑ i ∈ Finset.range M, i / Q) ≤ ∑ i ∈ Finset.range M, a i := by + classical + constructor + · intro k + have h := Finset.card_le_card_of_injOn + (s := (Finset.range M).filter fun i => i / Q = k) (t := Finset.range Q) + (fun i => i % Q) ?_ ?_ + · simpa using h + · intro i _ + exact Finset.mem_range.mpr (Nat.mod_lt i hQ) + · intro i hi j hj hij + change i % Q = j % Q at hij + exact (Nat.ext_div_mod_iff Q i j).mpr + ⟨(Finset.mem_filter.mp hi).2.trans (Finset.mem_filter.mp hj).2.symm, hij⟩ + · intro a ha + simpa using sum_range_div_le_of_bounded_multiplicity (Finset.range M) a Q hQ ha + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumCharacterPeriodZero.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumCharacterPeriodZero.lean new file mode 100644 index 0000000000000000000000000000000000000000..50a247a6af18787b6350c78be8f774931927594c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumCharacterPeriodZero.lean @@ -0,0 +1,728 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.DirichletRealZeroBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section IntroDependency0 + +section GrowthDependency0 + +namespace WeightedTorusJets + +open _root_.Finset MeasureTheory +open scoped Fin.NatCast + +theorem sum_character_period_eq_zero {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) : + ∑ k ∈ range q, χ (k : ZMod q) = 0 := by + classical + rw [← Fin.sum_univ_eq_sum_range] + have heq : ∀ a : Fin q, (ZMod.finEquiv q).toEquiv a = (a : ℕ) := by + intro a + cases q with + | zero => exact (NeZero.ne 0 rfl).elim + | succ q => + change a = ((a : ℕ) : Fin (q + 1)) + exact (Fin.cast_val_eq_self a).symm + have hsum := Equiv.sum_comp (ZMod.finEquiv q).toEquiv (fun a => χ a) + simpa only [heq, MulChar.sum_eq_zero_of_ne_one hχ] using hsum + +theorem norm_sum_character_range_lt {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (n : ℕ) : + ‖∑ k ∈ range n, χ (k : ZMod q)‖ < q := by + classical + have hperiod : Function.Periodic (fun n => ∑ k ∈ range n, χ (k : ZMod q)) q := by + intro n + change (∑ k ∈ range (n + q), χ (k : ZMod q)) = ∑ k ∈ range n, χ (k : ZMod q) + rw [Nat.add_comm n q, Finset.sum_range_add, sum_character_period_eq_zero χ hχ] + simp + rw [← hperiod.map_mod_nat n] + have hbound : ‖∑ k ∈ range (n % q), χ (k : ZMod q)‖ ≤ (n % q : ℕ) := by + calc + _ ≤ ∑ k ∈ range (n % q), ‖χ (k : ZMod q)‖ := norm_sum_le _ _ + _ ≤ ∑ _k ∈ range (n % q), (1 : ℝ) := sum_le_sum fun k _ => χ.norm_le_one k + _ = (n % q : ℕ) := by simp + exact hbound.trans_lt (by exact_mod_cast Nat.mod_lt n (NeZero.pos q)) + +theorem norm_sum_character_Icc_lt {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) (n : ℕ) : + ‖∑ k ∈ Icc 1 n, χ (k : ZMod q)‖ < q := by + have hzero : χ 0 = 0 := χ.map_zero' (hχ ∘ χ.level_one') + have hbound := norm_sum_character_range_lt χ hχ (n + 1) + rw [sum_range_eq_add_Ico _ (Nat.succ_pos n), Nat.cast_zero, hzero, zero_add, + Nat.succ_eq_add_one, Ico_add_one_right_eq_Icc] at hbound + exact hbound + +theorem isBigO_sum_character_Icc_one {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) : + Asymptotics.IsBigO Filter.atTop (fun n : ℕ => ∑ k ∈ Icc 1 n, χ (k : ZMod q)) + (fun _ => (1 : ℝ)) := by + apply Asymptotics.isBigO_iff.mpr + refine ⟨q, Filter.Eventually.of_forall fun n => ?_⟩ + simpa using (norm_sum_character_Icc_lt χ hχ n).le + +theorem mellin_partial_sum_neg {q : ℕ} + (χ : DirichletCharacter ℂ q) (s : ℂ) : + mellin (fun t : ℝ => ∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) (-s) = + ∫ t : ℝ in Set.Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) * (t : ℂ) ^ (-(s + 1)) := by + unfold mellin + rw [setIntegral_eq_of_subset_of_forall_sdiff_eq_zero measurableSet_Ioi + (Set.Ici_subset_Ioi.mpr zero_lt_one) ?_] + · rw [integral_Ici_eq_integral_Ioi] + apply setIntegral_congr_fun measurableSet_Ioi + intro t _ + simp only [smul_eq_mul, neg_add, sub_eq_add_neg] + exact mul_comm _ _ + · intro t ht + have ht1 : t < 1 := lt_of_not_ge ht.2 + simp [Nat.floor_eq_zero.mpr ht1] + +theorem differentiableAt_partial_sum_integral {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) {s : ℂ} (hs : 0 < s.re) : + DifferentiableAt ℂ (fun z => z * ∫ t : ℝ in Set.Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) * (t : ℂ) ^ (-(z + 1))) s := by + have hmeas : Measurable (fun t : ℝ => ∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) := + (measurable_from_nat (f := fun n : ℕ => ∑ k ∈ Icc 1 n, χ (k : ZMod q))).comp + Nat.measurable_floor + have hmem : MemLp (fun t : ℝ => ∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) ⊤ := + memLp_top_of_bound hmeas.aestronglyMeasurable q + (Filter.Eventually.of_forall fun t => (norm_sum_character_Icc_lt χ hχ ⌊t⌋₊).le) + have htop : Asymptotics.IsBigO Filter.atTop + (fun t : ℝ => ∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) (fun t => t ^ (-(0 : ℝ))) := by + refine Asymptotics.isBigO_iff.mpr ⟨q, Filter.Eventually.of_forall fun t => ?_⟩ + simpa using (norm_sum_character_Icc_lt χ hχ ⌊t⌋₊).le + have hbot : Asymptotics.IsBigO (nhdsWithin (0 : ℝ) (Set.Ioi 0)) + (fun t : ℝ => ∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) + (fun t => t ^ (-(-s.re - 1))) := by + refine Asymptotics.isBigO_iff.mpr ⟨0, ?_⟩ + filter_upwards [(eventually_lt_nhds (show (0 : ℝ) < 1 from zero_lt_one)).filter_mono + nhdsWithin_le_nhds] with t ht + simp [Nat.floor_eq_zero.mpr ht] + have hm : DifferentiableAt ℂ + (mellin (fun t : ℝ => ∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q))) (-s) := by + apply mellin_differentiableAt_of_isBigO_rpow + ((hmem.locallyIntegrable le_top).locallyIntegrableOn _) htop + (by simpa using neg_neg_of_pos hs) hbot + simp only [Complex.neg_re] + linarith + have hfun : (fun z : ℂ => z * ∫ t : ℝ in Set.Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) * (t : ℂ) ^ (-(z + 1))) = + (fun z : ℂ => z * mellin (fun t : ℝ => ∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) (-z)) := by + funext z + rw [mellin_partial_sum_neg] + rw [hfun] + exact differentiableAt_id.mul (hm.comp s differentiableAt_id.neg) + +theorem LFunction_eq_partial_sum_integral {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) {s : ℂ} (hs : 1 < s.re) : + DirichletCharacter.LFunction χ s = s * ∫ t : ℝ in Set.Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) * (t : ℂ) ^ (-(s + 1)) := by + rw [DirichletCharacter.LFunction_eq_LSeries χ hs] + apply LSeries_eq_mul_integral (r := 0) _ le_rfl (zero_lt_one.trans hs) + · exact DirichletCharacter.LSeriesSummable_of_one_lt_re χ hs + · simpa using isBigO_sum_character_Icc_one χ hχ + +end WeightedTorusJets + +namespace WeightedTorusJets + +open _root_.Finset MeasureTheory +open scoped Topology + +theorem LFunction_eq_partial_sum_integral_of_re_pos {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) {s : ℂ} (hs : 0 < s.re) : + DirichletCharacter.LFunction χ s = s * ∫ t : ℝ in Set.Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) * (t : ℂ) ^ (-(s + 1)) := by + let U : Set ℂ := {z | 0 < z.re} + let F := DirichletCharacter.LFunction χ + let G : ℂ → ℂ := fun z => z * ∫ t : ℝ in Set.Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) * (t : ℂ) ^ (-(z + 1)) + have hUo : IsOpen U := Complex.continuous_re.isOpen_preimage _ isOpen_Ioi + have hUc : IsPreconnected U := + ((convex_Ioi (0 : ℝ)).linear_preimage Complex.reCLM.toLinearMap).isPreconnected + have hF : AnalyticOnNhd ℂ F U := + (DirichletCharacter.differentiable_LFunction hχ).differentiableOn.analyticOnNhd hUo + have hG : AnalyticOnNhd ℂ G U := by + refine DifferentiableOn.analyticOnNhd (fun z hz => ?_) hUo + exact (differentiableAt_partial_sum_integral χ hχ hz).differentiableWithinAt + have hV : {z : ℂ | 1 < z.re} ∈ 𝓝 (2 : ℂ) := + (Complex.continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds (by norm_num) + have hFG : F =ᶠ[𝓝 (2 : ℂ)] G := by + filter_upwards [hV] with z hz + exact LFunction_eq_partial_sum_integral χ hχ hz + exact hF.eqOn_of_preconnected_of_eventuallyEq hG hUc (by norm_num [U]) hFG hs + +end WeightedTorusJets + +end GrowthDependency0 + +section GrowthDependency1 + +open MeasureTheory Set + +namespace WeightedTorusJets + + theorem integrableOn_min_mul_rpow {q r : ℝ} (hq : 0 ≤ q) (hr : r < -1) : + IntegrableOn (fun x : ℝ => min x q * x ^ r) (Ioi 1) := by + have hcont : ContinuousOn (fun x : ℝ => min x q * x ^ r) (Ioi 1) := + (continuous_id.min continuous_const).continuousOn.mul + (continuousOn_id.rpow_const (fun x hx => Or.inl (ne_of_gt (lt_trans zero_lt_one hx)))) + apply ((integrableOn_Ioi_rpow_of_lt hr zero_lt_one).const_mul q).mono' + (hcont.aestronglyMeasurable measurableSet_Ioi) + filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx + have hx0 : 0 ≤ x := (lt_trans zero_lt_one hx).le + rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg (le_min hx0 hq) (Real.rpow_nonneg hx0 _))] + exact mul_le_mul_of_nonneg_right (min_le_right x q) (Real.rpow_nonneg hx0 _) + + theorem integral_min_mul_rpow_exact {q η : ℝ} (hq : 1 ≤ q) (hη : 0 < η) (hη1 : η < 1) : + (∫ x : ℝ in Ioi 1, min x q * x ^ (η - 2)) = + (q ^ η - 1) / η + q ^ η / (1 - η) := by + have hq0 : 0 < q := lt_of_lt_of_le zero_lt_one hq + have hr : η - 2 < -1 := by linarith + have hint := integrableOn_min_mul_rpow hq0.le hr + have hfirst : (∫ x : ℝ in 1..q, min x q * x ^ (η - 2)) = (q ^ η - 1) / η := by + calc + _ = ∫ x : ℝ in 1..q, x ^ (η - 1) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hq] at hx + have hx0 : 0 < x := lt_of_lt_of_le zero_lt_one hx.1 + dsimp only + rw [min_eq_left hx.2] + calc + _ = x ^ (1 + (η - 2)) := by rw [Real.rpow_add hx0, Real.rpow_one] + _ = _ := by congr 1; ring + _ = _ := by + rw [integral_rpow (Or.inl (by linarith : -1 < η - 1))] + simp only [show η - 1 + 1 = η by ring, Real.one_rpow] + have htail : (∫ x : ℝ in Ioi q, min x q * x ^ (η - 2)) = q ^ η / (1 - η) := by + calc + _ = ∫ x : ℝ in Ioi q, q * x ^ (η - 2) := by + apply setIntegral_congr_fun measurableSet_Ioi + intro x hx + dsimp only + rw [min_eq_right hx.le] + _ = q * (-q ^ (η - 2 + 1) / (η - 2 + 1)) := by + rw [integral_const_mul, integral_Ioi_rpow_of_lt hr hq0] + _ = _ := by + have hp : q * q ^ (η - 1) = q ^ η := by + calc + _ = q ^ (1 + (η - 1)) := by rw [Real.rpow_add hq0, Real.rpow_one] + _ = _ := by congr 1; ring + rw [show η - 2 + 1 = η - 1 by ring] + have hηn : η - 1 ≠ 0 := by linarith + have hηn' : 1 - η ≠ 0 := by linarith + field_simp + nlinarith [hp] + have hsplit := intervalIntegral.integral_interval_add_Ioi hint + (hint.mono_set (Ioi_subset_Ioi hq)) + rw [hfirst, htail] at hsplit + exact hsplit.symm + + theorem integral_min_mul_rpow_le {q η σ : ℝ} (hq : 1 ≤ q) (hη : 0 < η) + (hηhalf : η ≤ 1 / 2) (hσ : 1 - η ≤ σ) : + (∫ x : ℝ in Ioi 1, min x q * x ^ (-σ - 1)) ≤ q ^ η * (1 / η + 2) := by + have hq0 : 0 ≤ q := le_trans zero_le_one hq + have hσ0 : 0 < σ := by linarith + have hη1 : η < 1 := by linarith + have hint := integrableOn_min_mul_rpow hq0 (by linarith : -σ - 1 < -1) + have henv := integrableOn_min_mul_rpow hq0 (by linarith : η - 2 < -1) + calc + _ ≤ ∫ x : ℝ in Ioi 1, min x q * x ^ (η - 2) := by + apply integral_mono_ae hint henv + filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx + exact mul_le_mul_of_nonneg_left + (Real.rpow_le_rpow_of_exponent_le hx.le (by linarith)) + (le_min (le_trans zero_le_one hx.le) hq0) + _ = (q ^ η - 1) / η + q ^ η / (1 - η) := integral_min_mul_rpow_exact hq hη hη1 + _ ≤ q ^ η * (1 / η + 2) := by + have hp : 0 ≤ q ^ η := Real.rpow_nonneg hq0 _ + have hfirst : (q ^ η - 1) / η ≤ q ^ η / η := + div_le_div_of_nonneg_right (by linarith) hη.le + have htail : q ^ η / (1 - η) ≤ 2 * q ^ η := by + apply (div_le_iff₀ (by linarith : 0 < 1 - η)).mpr + nlinarith + calc + _ ≤ q ^ η / η + 2 * q ^ η := add_le_add hfirst htail + _ = _ := by ring + +end WeightedTorusJets + +end GrowthDependency1 + +namespace WeightedTorusJets + +open _root_.Finset MeasureTheory + +theorem norm_sum_character_Icc_le_min {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) {t : ℝ} (ht : 0 ≤ t) : + ‖∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)‖ ≤ min t (q : ℝ) := by + apply le_min + · calc + ‖∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)‖ ≤ + ∑ k ∈ Icc 1 ⌊t⌋₊, ‖χ (k : ZMod q)‖ := norm_sum_le _ _ + _ ≤ ∑ _k ∈ Icc 1 ⌊t⌋₊, (1 : ℝ) := sum_le_sum fun k _ => χ.norm_le_one k + _ = (⌊t⌋₊ : ℝ) := by simp + _ ≤ t := Nat.floor_le ht + · exact (norm_sum_character_Icc_lt χ hχ ⌊t⌋₊).le + +theorem norm_LFunction_le_rpow_near_one {η : ℝ} (hη : 0 < η) (hηhalf : η ≤ 1 / 2) + {q : ℕ} [NeZero q] (hq : 3 ≤ q) (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) + {s : ℂ} (hre : 1 - η ≤ s.re) (hnorm : ‖s‖ ≤ 2) : + ‖DirichletCharacter.LFunction χ s‖ ≤ (2 / η + 4) * (q : ℝ) ^ η := by + have hs : 0 < s.re := by linarith + have hq1 : 1 ≤ (q : ℝ) := by exact_mod_cast (show 1 ≤ q by omega) + have hint := integrableOn_min_mul_rpow (Nat.cast_nonneg q) + (by linarith : -s.re - 1 < -1) + have hI : ‖∫ t : ℝ in Set.Ioi 1, + (∑ k ∈ Icc 1 ⌊t⌋₊, χ (k : ZMod q)) * (t : ℂ) ^ (-(s + 1))‖ ≤ + ∫ t : ℝ in Set.Ioi 1, min t (q : ℝ) * t ^ (-s.re - 1) := by + apply norm_integral_le_of_norm_le hint + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + have ht0 : 0 < t := lt_trans zero_lt_one ht + rw [norm_mul, Complex.norm_cpow_eq_rpow_re_of_pos ht0] + have he : (-(s + 1)).re = -s.re - 1 := by simp; ring + rw [he] + exact mul_le_mul_of_nonneg_right (norm_sum_character_Icc_le_min χ hχ ht0.le) + (Real.rpow_nonneg ht0.le _) + have hbound := hI.trans (integral_min_mul_rpow_le hq1 hη hηhalf hre) + rw [LFunction_eq_partial_sum_integral_of_re_pos χ hχ hs, norm_mul] + calc + ‖s‖ * _ ≤ 2 * ((q : ℝ) ^ η * (1 / η + 2)) := + mul_le_mul hnorm hbound (norm_nonneg _) (by norm_num) + _ = (2 / η + 4) * (q : ℝ) ^ η := by ring + +theorem LFunction_uniform_closedBall_bound (η : ℝ) (hη : 0 < η) (hηhalf : η ≤ 1 / 2) : + ∃ A : ℝ, 0 < A ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → + ∀ s ∈ Metric.closedBall (1 : ℂ) η, + ‖DirichletCharacter.LFunction χ s‖ ≤ A * (q : ℝ) ^ η := by + refine ⟨2 / η + 4, by positivity, ?_⟩ + intro q _ hq χ hχ s hs + have hnorm : ‖s - 1‖ ≤ η := by simpa [Metric.mem_closedBall, dist_eq_norm] using hs + have hreal : |s.re - 1| ≤ η := by + simpa using (Complex.abs_re_le_norm (s - 1)).trans hnorm + have hre : 1 - η ≤ s.re := by + have := (abs_le.mp hreal).1 + linarith + have hnorm2 : ‖s‖ ≤ 2 := by + have ht := norm_le_norm_sub_add s (1 : ℂ) + simp only [norm_one] at ht + linarith + exact norm_LFunction_le_rpow_near_one hη hηhalf hq χ hχ hre hnorm2 + +end WeightedTorusJets + +end IntroDependency0 + +section IntroDependency2 + +open _root_.Erdos970.Complex Filter ArithmeticFunction MeasureTheory Set +open scoped Topology ComplexOrder LSeries.notation + +namespace WeightedTorusJets + +theorem one_le_zeta_mul_LFunction {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) {x : ℝ} (hx : 1 < x) : + 1 ≤ riemannZeta (x : ℂ) * DirichletCharacter.LFunction χ (x : ℂ) := by + have hs : 1 < (x : ℂ).re := hx + have hpos : 1 ≤ LSeries χ.zetaMul (x : ℂ) := by + have h := (χ.LSeriesSummable_zetaMul hs).le_tsum 1 + (fun n _ => LSeries.term_nonneg (χ.zetaMul_nonneg hχ.sq_eq_one n) x) + simpa [LSeries, LSeries.term_def, χ.isMultiplicative_zetaMul.map_one] using h + have heq : LSeries χ.zetaMul (x : ℂ) = + riemannZeta (x : ℂ) * DirichletCharacter.LFunction χ (x : ℂ) := by + rw [DirichletCharacter.zetaMul, ← coe_mul, LSeries_convolution'] + · rw [DirichletCharacter.LFunction_eq_LSeries χ hs] + congr 1 + · simpa only [← natCoe_apply] using LSeries_zeta_eq_riemannZeta hs + · exact (LSeries_congr χ.apply_eq_toArithmeticFunction_apply (x : ℂ)).symm + · exact LSeriesSummable_zeta_iff.mpr hs + · exact (LSeriesSummable_congr _ fun h => (χ.apply_eq_toArithmeticFunction_apply h).symm).mpr + (ZMod.LSeriesSummable_of_one_lt_re χ hs) + rwa [heq] at hpos + +theorem riemannZeta_re_eq_tsum_rpow {x : ℝ} (hx : 1 < x) : + (riemannZeta (x : ℂ)).re = ∑' n : ℕ, ((n + 1 : ℕ) : ℝ) ^ (-x) := by + rw [zeta_eq_tsum_one_div_nat_add_one_cpow (by simpa using hx)] + have heq (n : ℕ) : (1 : ℂ) / (n + 1) ^ (x : ℂ) = + (((n + 1 : ℕ) : ℝ) ^ (-x) : ℝ) := by + rw [Real.rpow_neg (by positivity), Complex.ofReal_inv, + Complex.ofReal_cpow (by positivity)] + simp + simp_rw [heq] + rw [← Complex.ofReal_tsum, Complex.ofReal_re] + +theorem riemannZeta_re_le_one_add_inv {x : ℝ} (hx : 1 < x) : + (riemannZeta (x : ℂ)).re ≤ 1 + 1 / (x - 1) := by + rw [riemannZeta_re_eq_tsum_rpow hx] + have hs : Summable (fun n : ℕ => (n : ℝ) ^ (-x)) := + Real.summable_nat_rpow.mpr (by linarith) + have hs' : Summable (fun n : ℕ => ((n + 1 : ℕ) : ℝ) ^ (-x)) := + (summable_nat_add_iff 1).mpr hs + have hanti : AntitoneOn (fun y : ℝ => y ^ (-x)) (Ici 1) := + (Real.antitoneOn_rpow_Ioi_of_exponent_nonpos (by linarith : -x ≤ 0)).mono + (by intro y hy; exact lt_of_lt_of_le (by norm_num : (0 : ℝ) < 1) hy) + have htail := AntitoneOn.tsum_comp_add_le_integral 1 (by simpa using hanti) + (integrableOn_Ioi_rpow_of_lt (by linarith : -x < -1) (by norm_num)) + (by intro y hy; have hy' : 1 < y := by simpa using hy + exact Real.rpow_nonneg (by linarith) _) + rw [integral_Ioi_rpow_of_lt (by linarith : -x < -1) (by norm_num)] at htail + norm_num only [Nat.cast_one] at htail + have heq : -(1 : ℝ) ^ (-x + 1) / (-x + 1) = 1 / (x - 1) := by + rw [Real.one_rpow, show -x + 1 = -(x - 1) by ring] + exact neg_div_neg_eq 1 (x - 1) + rw [heq] at htail + rw [hs'.tsum_eq_zero_add] + simpa using add_le_add_left htail 1 + +theorem one_div_zeta_re_le_LFunction_re {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) {x : ℝ} (hx : 1 < x) : + 1 / (riemannZeta (x : ℂ)).re ≤ (DirichletCharacter.LFunction χ (x : ℂ)).re := by + have hz := Complex.pos_iff.mp (riemannZeta_pos_of_one_lt hx) + have hprod := (Complex.le_def.mp (one_le_zeta_mul_LFunction χ hχ hx)).1 + rw [Complex.mul_re, ← hz.2, zero_mul, sub_zero, Complex.one_re] at hprod + exact (div_le_iff₀ hz.1).mpr (by simpa [mul_comm] using hprod) + +theorem half_mul_le_LFunction_one_add_re {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) {t : ℝ} (ht : 0 < t) + (ht1 : t ≤ 1) : t / 2 ≤ (DirichletCharacter.LFunction χ ((1 + t : ℝ) : ℂ)).re := by + have hx : 1 < 1 + t := by linarith + have hz := (Complex.pos_iff.mp (riemannZeta_pos_of_one_lt hx)).1 + have hupper : (riemannZeta ((1 + t : ℝ) : ℂ)).re ≤ 2 / t := by + calc + _ ≤ 1 + 1 / t := by simpa using riemannZeta_re_le_one_add_inv hx + _ ≤ 2 / t := by + apply (le_div_iff₀ ht).mpr + rw [add_mul, one_mul, one_div_mul_cancel ht.ne'] + linarith + calc + t / 2 = 1 / (2 / t) := by rw [one_div_div] + _ ≤ 1 / (riemannZeta ((1 + t : ℝ) : ℂ)).re := + one_div_le_one_div_of_le hz hupper + _ ≤ (DirichletCharacter.LFunction χ ((1 + t : ℝ) : ℂ)).re := + one_div_zeta_re_le_LFunction_re χ hχ hx + +end WeightedTorusJets + +end IntroDependency2 + +section IntroDependency1 + +open _root_.Erdos970.Complex Filter +open scoped Topology ComplexConjugate + +namespace RealCharacterAnalysis + +end RealCharacterAnalysis + +open _root_.Erdos970.Complex Filter ArithmeticFunction +open scoped Topology ComplexOrder LSeries.notation + +namespace RealCharacterAnalysis + +theorem lFunction_positive_of_one_lt {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) {x : ℝ} (hx : 1 < x) : + 0 < DirichletCharacter.LFunction χ (x : ℂ) := by + have hpos : 0 < riemannZeta (x : ℂ) * DirichletCharacter.LFunction χ (x : ℂ) := + lt_of_lt_of_le zero_lt_one (WeightedTorusJets.one_le_zeta_mul_LFunction χ hχ hx) + have hzeta := riemannZeta_pos_of_one_lt hx + have hdiv := div_pos hpos hzeta + simpa only [mul_div_cancel_left₀ _ (ne_of_gt hzeta)] using hdiv + +theorem lFunction_positive_at_one {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ.IsQuadratic) (hne : χ ≠ 1) : + 0 < DirichletCharacter.LFunction χ 1 := by + have hc : ContinuousAt (fun x : ℝ => DirichletCharacter.LFunction χ (x : ℂ)) 1 := + (DirichletCharacter.differentiable_LFunction hne).continuous.continuousAt.comp + Complex.continuous_ofReal.continuousAt + have hn : 0 ≤ DirichletCharacter.LFunction χ 1 := by + apply ge_of_tendsto (hc.tendsto.mono_left + (show 𝓝[>] (1 : ℝ) ≤ 𝓝 1 from nhdsWithin_le_nhds)) + filter_upwards [self_mem_nhdsWithin] with x hx + exact (lFunction_positive_of_one_lt χ hχ hx).le + exact lt_of_le_of_ne hn (DirichletCharacter.LFunction_apply_one_ne_zero hne).symm + +end RealCharacterAnalysis + +namespace WeightedTorusJets + +theorem real_character_LFunction_eq_real_part {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hne : χ ≠ 1) + (hreal : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + DirichletCharacter.LFunction χ (s : ℂ) = + ((DirichletCharacter.LFunction χ (s : ℂ)).re : ℂ) := by + apply Complex.ext + · rfl + · simpa using RealCharacterAnalysis.lFunction_real χ hne hreal s + +theorem real_character_LFunction_one_re_pos {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hne : χ ≠ 1) + (hreal : ∀ a : ZMod q, (χ a).im = 0) : + 0 < (DirichletCharacter.LFunction χ 1).re := by + exact (Complex.pos_iff.mp (RealCharacterAnalysis.lFunction_positive_at_one χ + ((RealCharacterAnalysis.real_values_iff_quadratic χ).mp hreal) hne)).1 + +theorem real_character_LFunction_re_zero_iff {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hne : χ ≠ 1) + (hreal : ∀ a : ZMod q, (χ a).im = 0) (s : ℝ) : + (DirichletCharacter.LFunction χ (s : ℂ)).re = 0 ↔ + DirichletCharacter.LFunction χ (s : ℂ) = 0 := by + constructor + · intro h + rw [real_character_LFunction_eq_real_part χ hne hreal s, h, Complex.ofReal_zero] + · intro h + simp [h] + +end WeightedTorusJets + +end IntroDependency1 + +section IntroDependency3 + +open Metric + +namespace WeightedTorusJets + +theorem norm_second_deriv_le_of_closedBall + {f : ℂ → ℂ} (hf : Differentiable ℂ f) {c x : ℂ} {R M : ℝ} + (hR : 0 < R) (hx : dist x c ≤ R / 2) + (hM : ∀ z ∈ closedBall c R, ‖f z‖ ≤ M) : + ‖deriv (deriv f) x‖ ≤ 8 * M / R ^ 2 := by + have h := Complex.norm_iteratedDeriv_le_of_forall_mem_sphere_norm_le + (f := f) (c := x) (R := R / 2) 2 (half_pos hR) hf.diffContOnCl + (fun z hz => hM z (by + rw [mem_closedBall] + have hz' : dist z x = R / 2 := mem_sphere.mp hz + calc + dist z c ≤ dist z x + dist x c := dist_triangle z x c + _ ≤ R := by linarith)) + have h' : ‖deriv (deriv f) x‖ ≤ 2 * M / (R / 2) ^ 2 := by + simpa [iteratedDeriv_succ] using h + convert h' using 1 + ring + +theorem real_deriv_eq_re_complex_deriv {f : ℂ → ℂ} (hf : Differentiable ℂ f) : + deriv (fun x : ℝ => (f x).re) = fun x : ℝ => (deriv f x).re := by + funext x + exact (hf x).hasDerivAt.real_of_complex.deriv + +theorem differentiable_real_restriction {f : ℂ → ℂ} (hf : Differentiable ℂ f) : + Differentiable ℝ (fun x : ℝ => (f x).re) := by + intro x + exact (hf x).hasDerivAt.real_of_complex.differentiableAt + +theorem differentiable_deriv_real_restriction {f : ℂ → ℂ} (hf : Differentiable ℂ f) : + Differentiable ℝ (deriv (fun x : ℝ => (f x).re)) := by + rw [real_deriv_eq_re_complex_deriv hf] + exact differentiable_real_restriction hf.deriv + +theorem real_second_deriv_eq_re_complex_second_deriv + {f : ℂ → ℂ} (hf : Differentiable ℂ f) : + deriv (deriv (fun x : ℝ => (f x).re)) = + fun x : ℝ => (deriv (deriv f) x).re := by + rw [real_deriv_eq_re_complex_deriv hf] + exact real_deriv_eq_re_complex_deriv hf.deriv + +theorem abs_real_second_deriv_le_of_closedBall + {f : ℂ → ℂ} (hf : Differentiable ℂ f) {R M x : ℝ} + (hR : 0 < R) (hx : |x - 1| ≤ R / 2) + (hM : ∀ z ∈ closedBall (1 : ℂ) R, ‖f z‖ ≤ M) : + |deriv (deriv (fun t : ℝ => (f t).re)) x| ≤ 8 * M / R ^ 2 := by + rw [real_second_deriv_eq_re_complex_second_deriv hf] + refine (Complex.abs_re_le_norm _).trans + (norm_second_deriv_le_of_closedBall hf hR ?_ hM) + simpa only [← Complex.ofReal_one, Complex.isometry_ofReal.dist_eq, Real.dist_eq] using hx + +end WeightedTorusJets + +end IntroDependency3 + +section IntroDependency4 + +namespace WeightedTorusJets + +theorem siegel_parameter_selection (ε C c₀ : ℝ) (hε : 0 < ε) + (hC : 0 < C) (hc₀ : 0 < c₀) : + let η := min ε (1 / 2) + let κ := min (η / 2) (min (1 / (8 * C)) (c₀ * η / 2)) + 0 < η ∧ η ≤ ε ∧ η ≤ 1 / 2 ∧ 0 < κ ∧ 0 < κ / 8 ∧ + ∀ q : ℝ, 3 ≤ q → + let t := κ * q ^ (-η) + 0 < t ∧ t ≤ η / 2 ∧ t ≤ 1 / 2 ∧ 0 ≤ C * q ^ η ∧ + (C * q ^ η) * t ≤ 1 / 8 ∧ t * Real.log q ≤ c₀ / 2 ∧ + (κ / 8) * q ^ (-ε) ≤ t / 8 := by + let η := min ε (1 / 2) + let κ := min (η / 2) (min (1 / (8 * C)) (c₀ * η / 2)) + have hη : 0 < η := lt_min hε (by norm_num) + have hηε : η ≤ ε := min_le_left _ _ + have hηhalf : η ≤ 1 / 2 := min_le_right _ _ + have hκ : 0 < κ := by dsimp [κ]; positivity + have hκη : κ ≤ η / 2 := min_le_left _ _ + have hκC : κ ≤ 1 / (8 * C) := (min_le_right _ _).trans (min_le_left _ _) + have hκc : κ ≤ c₀ * η / 2 := (min_le_right _ _).trans (min_le_right _ _) + have hCκ : C * κ ≤ 1 / 8 := by + have h := (le_div_iff₀ (show 0 < 8 * C by positivity)).mp hκC + nlinarith + refine ⟨hη, hηε, hηhalf, hκ, by positivity, ?_⟩ + intro q hq + have hqpos : 0 < q := by linarith + have hqone : 1 ≤ q := by linarith + have hp : 0 < q ^ η := Real.rpow_pos_of_pos hqpos η + have hn : 0 < q ^ (-η) := Real.rpow_pos_of_pos hqpos (-η) + have hn1 : q ^ (-η) ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hqone (by linarith) + let t := κ * q ^ (-η) + have ht : 0 < t := mul_pos hκ hn + have htκ : t ≤ κ := by simpa [t] using mul_le_mul_of_nonneg_left hn1 hκ.le + have htη : t ≤ η / 2 := htκ.trans hκη + refine ⟨ht, htη, by linarith, by positivity, ?_, ?_, ?_⟩ + · calc + (C * q ^ η) * t = C * κ * (q ^ η * q ^ (-η)) := by dsimp [t]; ring + _ = C * κ := by rw [← Real.rpow_add hqpos, add_neg_cancel, Real.rpow_zero, mul_one] + _ ≤ 1 / 8 := hCκ + · calc + t * Real.log q ≤ t * (q ^ η / η) := + mul_le_mul_of_nonneg_left (Real.log_le_rpow_div hqpos.le hη) ht.le + _ = κ / η := by + dsimp [t] + rw [Real.rpow_neg hqpos.le] + field_simp + _ ≤ c₀ / 2 := (div_le_iff₀ hη).mpr (by nlinarith [hκc]) + · have hr : q ^ (-ε) ≤ q ^ (-η) := + Real.rpow_le_rpow_of_exponent_le hqone (by linarith) + calc + (κ / 8) * q ^ (-ε) ≤ (κ / 8) * q ^ (-η) := + mul_le_mul_of_nonneg_left hr (by positivity) + _ = t / 8 := by dsimp [t]; ring + +end WeightedTorusJets + +end IntroDependency4 + +section IntroDependency5 + +namespace WeightedTorusJets + +open Set + +theorem value_one_lower_bound_of_real_zero_gap (f : ℝ → ℝ) + (hf : Differentiable ℝ f) (hf' : Differentiable ℝ (deriv f)) + {r B c ℓ : ℝ} (hr : 0 < r) (hrhalf : r ≤ 1 / 2) (hB : 0 ≤ B) + (hc : 0 < c) (hℓ : 0 < ℓ) + (hbound : ∀ x ∈ Icc (1 - r) (1 + r), |deriv (deriv f) x| ≤ B) + (hBr : B * r ≤ 1 / 8) (hrℓ : r * ℓ ≤ c / 2) + (hpositive : 0 < f 1) (hright : r / 2 ≤ f (1 + r)) + (hgap : ∀ β ∈ Ioo (0 : ℝ) 1, f β = 0 → c ≤ (1 - β) * ℓ) : + r / 8 ≤ f 1 := by + by_contra! hsmall + obtain ⟨u, hu, hequ⟩ := exists_deriv_eq_slope f (show 1 < 1 + r by linarith) + hf.continuous.continuousOn hf.differentiableOn + obtain ⟨v, hv, heqv⟩ := exists_deriv_eq_slope f (show 1 - r < 1 by linarith) + hf.continuous.continuousOn hf.differentiableOn + have hvu : v < u := hv.2.trans hu.1 + have hdiff : deriv f u - deriv f v ≤ B * (u - v) := + (convex_Icc (1 - r) (1 + r)).image_sub_le_mul_sub_of_deriv_le + hf'.continuous.continuousOn hf'.differentiableOn + (fun x hx => (le_abs_self _).trans (hbound x (interior_subset hx))) + v ⟨hv.1.le, (hvu.trans hu.2).le⟩ u ⟨(hv.1.trans hvu).le, hu.2.le⟩ hvu.le + have hlength : u - v ≤ 2 * r := by linarith [hu.2, hv.1] + have hdiff' : deriv f u - deriv f v ≤ B * (2 * r) := + hdiff.trans (mul_le_mul_of_nonneg_left hlength hB) + have hplus : deriv f u * r = f (1 + r) - f 1 := + (eq_div_iff hr.ne').mp (by simpa only [add_sub_cancel_left] using hequ) + have hden : (1 : ℝ) - (1 - r) = r := by ring + rw [hden] at heqv + have hminus : deriv f v * r = f 1 - f (1 - r) := (eq_div_iff hr.ne').mp heqv + have hprod := mul_le_mul_of_nonneg_right hdiff' hr.le + have hprodB := mul_le_mul_of_nonneg_right hBr hr.le + have hleft : f (1 - r) < 0 := by nlinarith + obtain ⟨β, hβ, hzero⟩ := intermediate_value_Ioo (show 1 - r ≤ 1 by linarith) + hf.continuous.continuousOn ⟨hleft, hpositive⟩ + have hβpos : 0 < β := by linarith [hβ.1] + have hcontr := hgap β ⟨hβpos, hβ.2⟩ hzero + have hshort : (1 - β) * ℓ < r * ℓ := + mul_lt_mul_of_pos_right (by linarith [hβ.1]) hℓ + linarith + +end WeightedTorusJets + +end IntroDependency5 + +section IntroDependency6 +namespace WeightedTorusJets + +theorem siegel_LFunction_one_lower_bound_of_zero_gap (hmain : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → + (∀ a : ZMod q, (χ a).im = 0) → ∀ β : ℝ, + (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → + c ≤ (1 - β) * Real.log (q : ℝ)) : + ∀ ε : ℝ, 0 < ε → ∃ c : ℝ, 0 < c ∧ + ∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + c * (q : ℝ) ^ (-ε) ≤ (DirichletCharacter.LFunction χ 1).re := by + obtain ⟨c₀, hc₀, hgap⟩ := hmain + intro ε hε + let η := min ε (1 / 2) + have hη : 0 < η := lt_min hε (by norm_num) + have hηhalf : η ≤ 1 / 2 := min_le_right _ _ + obtain ⟨A, hA, hnorm⟩ := LFunction_uniform_closedBall_bound η hη hηhalf + let C := 8 * A / η ^ 2 + have hC : 0 < C := by dsimp [C]; positivity + let κ := min (η / 2) (min (1 / (8 * C)) (c₀ * η / 2)) + obtain ⟨_, _, _, _, hκ, hparameters⟩ := siegel_parameter_selection ε C c₀ hε hC hc₀ + refine ⟨κ / 8, hκ, ?_⟩ + intro q _ hq χ hprim hne hreal + have hqreal : (3 : ℝ) ≤ q := by exact_mod_cast hq + obtain ⟨hr, hrη, hrhalf, hB, hBr, hrlog, hcompare⟩ := hparameters (q : ℝ) hqreal + let r := κ * (q : ℝ) ^ (-η) + let f := fun x : ℝ => (DirichletCharacter.LFunction χ (x : ℂ)).re + have hf := DirichletCharacter.differentiable_LFunction hne + have hbound : ∀ x ∈ Set.Icc (1 - r) (1 + r), + |deriv (deriv f) x| ≤ C * (q : ℝ) ^ η := by + intro x hx + have hx' : |x - 1| ≤ η / 2 := by + apply abs_le.mpr + constructor <;> linarith [hx.1, hx.2] + calc + |deriv (deriv f) x| ≤ 8 * (A * (q : ℝ) ^ η) / η ^ 2 := + abs_real_second_deriv_le_of_closedBall hf hη hx' (hnorm q hq χ hne) + _ = C * (q : ℝ) ^ η := by dsimp [C]; ring + have hlower : r / 8 ≤ f 1 := by + apply value_one_lower_bound_of_real_zero_gap f + (differentiable_real_restriction hf) (differentiable_deriv_real_restriction hf) + hr hrhalf hB hc₀ (Real.log_pos (by linarith : (1 : ℝ) < q)) hbound hBr hrlog + · simpa [f] using real_character_LFunction_one_re_pos χ hne hreal + · exact half_mul_le_LFunction_one_add_re χ + ((RealCharacterAnalysis.real_values_iff_quadratic χ).mp hreal) hr (by linarith) + · intro β hβ hzero + exact hgap q hq χ hprim hne hreal β + ⟨hβ.1, hβ.2, (real_character_LFunction_re_zero_iff χ hne hreal β).mp hzero⟩ + exact hcompare.trans hlower + +end WeightedTorusJets + +end IntroDependency6 + +namespace WeightedTorusJets + +theorem siegel_LFunction_one_lower_bound : + ∀ ε : ℝ, 0 < ε → ∃ c : ℝ, 0 < c ∧ + ∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + c * (q : ℝ) ^ (-ε) ≤ (DirichletCharacter.LFunction χ 1).re := + siegel_LFunction_one_lower_bound_of_zero_gap dirichlet_real_zero_bound + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumLogDivFilterDvdTwoMul.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumLogDivFilterDvdTwoMul.lean new file mode 100644 index 0000000000000000000000000000000000000000..9fcfd120edc4163aaa250826795eda7a5869e178 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumLogDivFilterDvdTwoMul.lean @@ -0,0 +1,353 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.IntegerCharacter +import OAI.NumberTheory.Jacobsthal.Siegel.SumLogPrimeFactors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators Topology +section + +open scoped BigOperators + +namespace WeightedTorusJets + +theorem sum_log_div_filter_dvd_two_mul_le (q : ℕ) (hq : q ≠ 0) (s : Finset ℕ) + (hprime : ∀ p ∈ s, p.Prime) : + ∑ p ∈ s with p ∣ 2 * q, Real.log p / p ≤ Real.log q + Real.log 2 := by + calc + _ ≤ Real.log (2 * q : ℕ) := + sum_log_div_filter_dvd_le (2 * q) (Nat.mul_ne_zero (by decide) hq) s hprime + _ = Real.log q + Real.log 2 := by + rw [Nat.cast_mul, Nat.cast_ofNat, Real.log_mul (by norm_num : (2 : ℝ) ≠ 0) + (Nat.cast_ne_zero.mpr hq), add_comm] + +end WeightedTorusJets +end + +namespace WeightedTorusJets + +theorem source_good_prime_mass_with_chebyshev_constant : + ∃ C : ℝ, 0 < C ∧ Real.log 4 ≤ C ∧ + ∀ H : ℕ, 2 ≤ H → ∃ CH : ℝ, + ∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + ∀ β : ℝ, 0 < β → β < 1 → DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ U : ℝ, 3 ≤ U → + Real.log U - C * Real.log q - + C * ((1 - β) * Real.log q) * (Real.log U) ^ 2 / Real.log q - CH ≤ + ∑ p ∈ Nat.primesLE ⌊U⌋₊ with + H < p ∧ ¬p ∣ 2 * q ∧ χ ((p : ℕ) : ZMod q) = -1, + Real.log p / p := by + obtain ⟨C₀, hC₀, _hpositive, hgood⟩ := source_analytic_lemma + refine ⟨max C₀ (Real.log 4), hC₀.trans_le (le_max_left _ _), le_max_right _ _, ?_⟩ + intro H hH + obtain ⟨CH, hCH⟩ := hgood H hH + refine ⟨CH, ?_⟩ + intro q _ hq χ hprim hχ hreal β hβ0 hβ1 hzero U hU + have hbase := hCH q hq χ hprim hχ hreal β hβ0 hβ1 hzero U hU + have hell : 0 ≤ Real.log q := Real.log_natCast_nonneg q + have hdelta : 0 ≤ (1 - β) * Real.log q := mul_nonneg (by linarith) hell + have herror : 0 ≤ ((1 - β) * Real.log q) * (Real.log U) ^ 2 / Real.log q := + div_nonneg (mul_nonneg hdelta (sq_nonneg _)) hell + have hlinear := mul_le_mul_of_nonneg_right (le_max_left C₀ (Real.log 4)) hell + have hquadratic := mul_le_mul_of_nonneg_right (le_max_left C₀ (Real.log 4)) herror + have hbound : Real.log U - max C₀ (Real.log 4) * Real.log q - + max C₀ (Real.log 4) * + (((1 - β) * Real.log q) * (Real.log U) ^ 2 / Real.log q) - CH ≤ + ∑ p ∈ Nat.primesLE ⌊U⌋₊ with + H < p ∧ ¬p ∣ 2 * q ∧ χ ((p : ℕ) : ZMod q) = -1, Real.log p / p := by + linarith + convert hbound using 1 + ring + +end WeightedTorusJets + +end + +open scoped BigOperators + +namespace WeightedTorusJets + +theorem good_prime_filter_max_two (q H : ℕ) (c : ℕ → ℂ) (U : ℝ) : + (Nat.primesLE ⌊U⌋₊).filter (fun p => max H 2 < p ∧ ¬p ∣ 2 * q ∧ c p = -1) = + (Nat.primesLE ⌊U⌋₊).filter (fun p => H < p ∧ ¬p ∣ 2 * q ∧ c p = -1) := by + apply Finset.filter_congr + intro p hp + by_cases hq : p ∣ 2 * q + · simp [hq] + have hpgt : 2 < p := lt_of_le_of_ne (Nat.prime_of_mem_primesLE hp).two_le (by + rintro rfl + exact hq (dvd_mul_right 2 q)) + simp [max_lt_iff, hpgt] + +theorem good_prime_mass_extend_small_parameters (q H : ℕ) (c : ℕ → ℂ) + {C ell delta CH : ℝ} (hC : 0 ≤ C) (hell : 0 ≤ ell) (hdelta : 0 ≤ delta) + (hlarge : ∀ U : ℝ, 3 ≤ U → + Real.log U - C * ell - C * delta * (Real.log U) ^ 2 / ell - CH ≤ + ∑ p ∈ (Nat.primesLE ⌊U⌋₊).filter + (fun p => max H 2 < p ∧ ¬p ∣ 2 * q ∧ c p = -1), Real.log p / (p : ℝ)) + {U : ℝ} (hU : 0 ≤ U) : + Real.log U - C * ell - C * delta * (Real.log U) ^ 2 / ell - max CH (Real.log 3) ≤ + ∑ p ∈ (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ c p = -1), Real.log p / (p : ℝ) := by + by_cases hU3 : 3 ≤ U + · have h := hlarge U hU3 + rw [good_prime_filter_max_two] at h + exact le_trans (sub_le_sub_left (le_max_left _ _) _) h + · have hlog : Real.log U ≤ Real.log 3 := by + by_cases hU0 : U = 0 + · rw [hU0, Real.log_zero] + exact Real.log_nonneg (by norm_num) + · exact Real.log_le_log (lt_of_le_of_ne hU (Ne.symm hU0)) (by linarith) + have hsum : 0 ≤ ∑ p ∈ (Nat.primesLE ⌊U⌋₊).filter + (fun p => H < p ∧ ¬p ∣ 2 * q ∧ c p = -1), Real.log p / (p : ℝ) := + by positivity + have hlin : 0 ≤ C * ell := by positivity + have herr : 0 ≤ C * delta * (Real.log U) ^ 2 / ell := by positivity + have hCH := le_max_right CH (Real.log 3) + linarith + + + +theorem source_good_prime_mass_all_parameters : + ∃ C : ℝ, 0 < C ∧ Real.log 4 ≤ C ∧ + ∀ H : ℕ, ∃ CH : ℝ, + ∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + ∀ β : ℝ, 0 < β → β < 1 → DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ U : ℝ, 0 ≤ U → + Real.log U - C * Real.log q - + C * ((1 - β) * Real.log q) * (Real.log U) ^ 2 / Real.log q - CH ≤ + ∑ p ∈ Nat.primesLE ⌊U⌋₊ with + H < p ∧ ¬p ∣ 2 * q ∧ χ ((p : ℕ) : ZMod q) = -1, + Real.log p / p := by + obtain ⟨C, hC, hC4, hmass⟩ := source_good_prime_mass_with_chebyshev_constant + refine ⟨C, hC, hC4, ?_⟩ + intro H + obtain ⟨CH, hCH⟩ := hmass (max H 2) (le_max_right _ _) + refine ⟨max CH (Real.log 3), ?_⟩ + intro q _ hq χ hprim hne hreal β hβ0 hβ1 hzero U hU + have hell : 0 ≤ Real.log q := Real.log_natCast_nonneg q + have hdelta : 0 ≤ (1 - β) * Real.log q := mul_nonneg (by linarith) hell + exact good_prime_mass_extend_small_parameters q H (fun p => χ (p : ZMod q)) + hC.le hell hdelta (fun X hX => hCH q hq χ hprim hne hreal β hβ0 hβ1 hzero X hX) hU + + + + + + + + + + + + + +theorem primitive_eighth_root_difference_pow {K : Type*} [Field K] + {ζ : K} (hζ : IsPrimitiveRoot ζ 8) (u : (ZMod 8)ˣ) : + ζ ^ u.val.val - (ζ ^ u.val.val) ^ 3 = + (ZMod.χ₈ u : ℤ) * (ζ - ζ ^ 3) := by + have h4 : ζ ^ 4 = -1 := by + apply IsPrimitiveRoot.eq_neg_one_of_two_right + simpa using hζ.pow_div_gcd 4 (by decide : Nat.gcd 8 4 ≠ 0) + have hunit : IsUnit (u : ZMod 8) := u.isUnit + generalize hu : (u : ZMod 8) = x at * + fin_cases x + · exact False.elim ((by decide : ¬ IsUnit (0 : ZMod 8)) hunit) + · change ζ ^ 1 - (ζ ^ 1) ^ 3 = (1 : ℤ) * (ζ - ζ ^ 3) + simp + · exact False.elim ((by decide : ¬ IsUnit (2 : ZMod 8)) hunit) + · change ζ ^ 3 - (ζ ^ 3) ^ 3 = (-1 : ℤ) * (ζ - ζ ^ 3) + push_cast + linear_combination (-ζ ^ 5 + ζ) * h4 + · exact False.elim ((by decide : ¬ IsUnit (4 : ZMod 8)) hunit) + · change ζ ^ 5 - (ζ ^ 5) ^ 3 = (-1 : ℤ) * (ζ - ζ ^ 3) + push_cast + linear_combination (-ζ ^ 11 + ζ ^ 7 - ζ ^ 3 + ζ) * h4 + · exact False.elim ((by decide : ¬ IsUnit (6 : ZMod 8)) hunit) + · change ζ ^ 7 - (ζ ^ 7) ^ 3 = (1 : ℤ) * (ζ - ζ ^ 3) + push_cast + linear_combination (-ζ ^ 17 + ζ ^ 13 - ζ ^ 9 + ζ ^ 5 + ζ ^ 3 - ζ) * h4 + +theorem cyclotomic_eight_sqrt_two_action {K : Type*} [Field K] [NumberField K] + [IsCyclotomicExtension {8} ℚ K] (σ : Gal(K/ℚ)) : + let ζ := IsCyclotomicExtension.zeta 8 ℚ K + σ (ζ - ζ ^ 3) = (ZMod.χ₈ (IsCyclotomicExtension.Rat.galEquivZMod 8 K σ) : ℤ) * + (ζ - ζ ^ 3) := by + dsimp only + rw [map_sub, map_pow, IsCyclotomicExtension.Rat.galEquivZMod_apply_of_pow_eq 8 K σ + (IsCyclotomicExtension.zeta_spec 8 ℚ K).pow_eq_one] + exact primitive_eighth_root_difference_pow (IsCyclotomicExtension.zeta_spec 8 ℚ K) _ + + + +theorem chiEight_not_factorsThrough_four : + ¬ DirichletCharacter.FactorsThrough ZMod.χ₈ 4 := by + rw [DirichletCharacter.factorsThrough_iff_ker_unitsMap (by decide : 4 ∣ 8)] + intro h + let u : (ZMod 8)ˣ := ZMod.unitOfCoprime 5 (by decide) + have hu : u ∈ (ZMod.unitsMap (by decide : 4 ∣ 8)).ker := by decide + have hχ := h hu + change (ZMod.χ₈ : DirichletCharacter ℤ 8).toUnitHom u = 1 at hχ + have hc := congrArg Units.val hχ + norm_num [MulChar.coe_toUnitHom, u, ZMod.χ₈] at hc + +theorem chiEight_isPrimitive : + DirichletCharacter.IsPrimitive ZMod.χ₈ := by + let χ : DirichletCharacter ℤ 8 := ZMod.χ₈ + have hd : χ.conductor ∣ 2 ^ 3 := by simpa using χ.conductor_dvd_level + obtain ⟨k, hk, heq⟩ := (Nat.dvd_prime_pow Nat.prime_two).mp hd + have hf := χ.factorsThrough_conductor + change χ.conductor = 8 + interval_cases k + · have h4 : χ.FactorsThrough 4 := hf.mono χ (by simp [heq]) (by decide) + exact (chiEight_not_factorsThrough_four h4).elim + · have h4 : χ.FactorsThrough 4 := hf.mono χ (by simp [heq]) (by decide) + exact (chiEight_not_factorsThrough_four h4).elim + · have h4 : χ.FactorsThrough 4 := hf.mono χ (by simp [heq]) (by decide) + exact (chiEight_not_factorsThrough_four h4).elim + · simpa using heq + + + +open NumberField IsCyclotomicExtension.Rat + +theorem cyclotomic_eight_adjoin_eq_characterField {K : Type*} + [Field K] [NumberField K] [IsCyclotomicExtension {8} ℚ K] [IsAbelianGalois ℚ K] : + let ζ := IsCyclotomicExtension.zeta 8 ℚ K + IntermediateField.adjoin ℚ {ζ - ζ ^ 3} = + characterField 8 K ℂ (ZMod.χ₈.ringHomComp (Int.castRingHom ℂ)) := by + dsimp only + let t := IsCyclotomicExtension.zeta 8 ℚ K - (IsCyclotomicExtension.zeta 8 ℚ K) ^ 3 + have ht : t ≠ 0 := by + have hsq := primitive_eighth_root_difference_sq (IsCyclotomicExtension.zeta_spec 8 ℚ K) + change t ^ 2 = 2 at hsq + intro h + rw [h] at hsq + norm_num at hsq + apply IsGalois.intermediateFieldEquivSubgroup.injective + change (IntermediateField.adjoin ℚ {t}).fixingSubgroup = + (characterField 8 K ℂ (ZMod.χ₈.ringHomComp (Int.castRingHom ℂ))).fixingSubgroup + ext σ + have hfix : σ ∈ (IntermediateField.adjoin ℚ {t}).fixingSubgroup ↔ σ t = t := by + rw [IntermediateField.mem_fixingSubgroup_iff] + constructor + · intro h + exact h t (IntermediateField.mem_adjoin_simple_self ℚ t) + · intro h x hx + have hmap : σ.toAlgHom.comp (IntermediateField.adjoin ℚ {t}).val = + (IntermediateField.adjoin ℚ {t}).val := by + apply IntermediateField.adjoin_algHom_ext + intro y hy + obtain rfl := Set.mem_singleton_iff.mp hy + exact h + exact DFunLike.congr_fun hmap ⟨x, hx⟩ + rw [hfix, mem_characterField_fixingSubgroup _ _ _ _ + (ZMod.isQuadratic_χ₈.comp (Int.castRingHom ℂ))] + change (σ t = t) ↔ _ + rw [show σ t = (ZMod.χ₈ (galEquivZMod 8 K σ) : ℤ) * t from + cyclotomic_eight_sqrt_two_action σ, mul_eq_right₀ ht] + change ((ZMod.χ₈ (galEquivZMod 8 K σ) : K) = 1) ↔ + ((ZMod.χ₈ (galEquivZMod 8 K σ) : ℂ) = 1) + norm_cast + +theorem quadratic_character_eq_of_characterField_eq {n : ℕ} [NeZero n] + {K : Type*} [Field K] [NumberField K] [IsCyclotomicExtension {n} ℚ K] + [IsAbelianGalois ℚ K] {R : Type*} [CommRing R] [IsDomain R] + [HasEnoughRootsOfUnity R (Monoid.exponent (ZMod n)ˣ)] + {χ ψ : DirichletCharacter R n} (hχ : χ.IsQuadratic) (hψ : ψ.IsQuadratic) + (hfield : characterField n K R χ = characterField n K R ψ) : χ = ψ := by + apply MulChar.ext + intro u + have hiff : χ u = 1 ↔ ψ u = 1 := by + have hm := congrArg (fun F : IntermediateField ℚ K => + (galEquivZMod n K).symm u ∈ F.fixingSubgroup) hfield + simpa only [mem_characterField_fixingSubgroup n K R χ hχ, + mem_characterField_fixingSubgroup n K R ψ hψ, MulEquiv.apply_symm_apply] using + Iff.of_eq hm + have hχ0 : χ u ≠ 0 := (u.isUnit.map χ).ne_zero + have hψ0 : ψ u ≠ 0 := (u.isUnit.map ψ).ne_zero + rcases hχ u with hx | hx | hx <;> rcases hψ u with hy | hy | hy <;> simp_all + +theorem primitive_level_eq_eight_of_same_lifted_characterField + {q m : ℕ} [NeZero m] {K : Type*} [Field K] [NumberField K] + [IsCyclotomicExtension {m} ℚ K] [IsAbelianGalois ℚ K] + (hq : q ∣ m) (h8 : 8 ∣ m) (χ : DirichletCharacter ℂ q) + (hprim : χ.IsPrimitive) (hquad : χ.IsQuadratic) + (hfield : characterField m K ℂ (DirichletCharacter.changeLevel hq χ) = + characterField m K ℂ (DirichletCharacter.changeLevel h8 + (ZMod.χ₈.ringHomComp (Int.castRingHom ℂ)))) : q = 8 := by + have hquadq : (DirichletCharacter.changeLevel hq χ).IsQuadratic := by + rw [MulChar.isQuadratic_iff_sq_eq_one, ← map_pow, hquad.sq_eq_one, map_one] + have hquad8 : (DirichletCharacter.changeLevel h8 + (ZMod.χ₈.ringHomComp (Int.castRingHom ℂ))).IsQuadratic := by + rw [MulChar.isQuadratic_iff_sq_eq_one, ← map_pow, + (ZMod.isQuadratic_χ₈.comp (Int.castRingHom ℂ)).sq_eq_one, map_one] + have heq := quadratic_character_eq_of_characterField_eq hquadq hquad8 hfield + have hc := congrArg DirichletCharacter.conductor heq + rw [DirichletCharacter.conductor_changeLevel, DirichletCharacter.conductor_changeLevel, + hprim, conductor_ringHomComp ZMod.χ₈ (Int.castRingHom ℂ) + (Int.cast_injective (α := ℂ))] at hc + exact hc.trans chiEight_isPrimitive + +theorem primitive_level_eq_eight_of_sqrt_two_field + {q m : ℕ} [NeZero m] {K L : Type*} + [Field K] [NumberField K] [IsCyclotomicExtension {m} ℚ K] [IsAbelianGalois ℚ K] + [Field L] [NumberField L] [IsCyclotomicExtension {8} ℚ L] [IsAbelianGalois ℚ L] + [Algebra L K] [IsScalarTower ℚ L K] + (hq : q ∣ m) (h8 : 8 ∣ m) (χ : DirichletCharacter ℂ q) + (hprim : χ.IsPrimitive) (hquad : χ.IsQuadratic) (b : K) (hb : b ^ 2 = 2) + (hfield : characterField m K ℂ (DirichletCharacter.changeLevel hq χ) = + IntermediateField.adjoin ℚ {b}) : q = 8 := by + let t : L := IsCyclotomicExtension.zeta 8 ℚ L - (IsCyclotomicExtension.zeta 8 ℚ L) ^ 3 + let tK : K := algebraMap L K t + have htK : tK ^ 2 = 2 := by + change (algebraMap L K t) ^ 2 = 2 + rw [← map_pow, primitive_eighth_root_difference_sq + (IsCyclotomicExtension.zeta_spec 8 ℚ L), map_ofNat] + have hadj : IntermediateField.adjoin ℚ {b} = IntermediateField.adjoin ℚ {tK} := by + rcases sq_eq_sq_iff_eq_or_eq_neg.mp (hb.trans htK.symm) with h | h + · rw [h] + · rw [h] + apply le_antisymm + · apply IntermediateField.adjoin_simple_le_iff.mpr + exact IntermediateField.neg_mem _ (IntermediateField.mem_adjoin_simple_self ℚ tK) + · apply IntermediateField.adjoin_simple_le_iff.mpr + have hm := IntermediateField.neg_mem (IntermediateField.adjoin ℚ {-tK}) + (IntermediateField.mem_adjoin_simple_self ℚ (-tK)) + simpa using hm + apply primitive_level_eq_eight_of_same_lifted_characterField (K := K) hq h8 χ hprim hquad + rw [hfield, characterField_changeLevel 8 L ℂ K h8 _ + (ZMod.isQuadratic_χ₈.comp (Int.castRingHom ℂ)), + ← cyclotomic_eight_adjoin_eq_characterField, IntermediateField.adjoin_map, + Set.image_singleton] + exact hadj + +theorem primitive_level_eq_eight_of_lifted_sqrt_two_field + {q m : ℕ} [NeZero m] {K : Type*} + [Field K] [NumberField K] [IsCyclotomicExtension {m} ℚ K] [IsAbelianGalois ℚ K] + (hq : q ∣ m) (h8 : 8 ∣ m) (χ : DirichletCharacter ℂ q) + (hprim : χ.IsPrimitive) (hquad : χ.IsQuadratic) (b : K) (hb : b ^ 2 = 2) + (hfield : characterField m K ℂ (DirichletCharacter.changeLevel hq χ) = + IntermediateField.adjoin ℚ {b}) : q = 8 := by + let ζ : K := IsCyclotomicExtension.zeta m ℚ K ^ (m / 8) + have hζ : IsPrimitiveRoot ζ 8 := + (IsCyclotomicExtension.zeta_spec m ℚ K).pow (NeZero.pos m) + (Nat.div_mul_cancel h8).symm + let L := IntermediateField.adjoin ℚ {ζ} + let : IsCyclotomicExtension {8} ℚ L := + hζ.intermediateField_adjoin_isCyclotomicExtension (K := ℚ) + exact primitive_level_eq_eight_of_sqrt_two_field (L := L) hq h8 χ hprim hquad b hb hfield + +end WeightedTorusJets + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumLogPrimeFactors.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumLogPrimeFactors.lean new file mode 100644 index 0000000000000000000000000000000000000000..afb44b90ef07862342cc1cde6f72ed675ac325cc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/SumLogPrimeFactors.lean @@ -0,0 +1,482 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.E +import OAI.NumberTheory.Jacobsthal.Siegel.RealLogDerivConductorCompletedLDivisorTsum + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section AnalyticAssemblyScope +open scoped BigOperators Topology +section + +open scoped BigOperators + +namespace WeightedTorusJets + +theorem sum_log_primeFactors_le (q : ℕ) : + ∑ p ∈ q.primeFactors, Real.log p ≤ Real.log q := by + rcases eq_or_ne q 0 with rfl | hq + · simp + have hp : ∀ p ∈ q.primeFactors, 0 < (p : ℝ) := by + intro p hp + exact_mod_cast (Nat.mem_primeFactors.mp hp).1.pos + rw [← Real.log_prod (fun p hp' => (hp p hp').ne')] + apply Real.log_le_log (Finset.prod_pos hp) + rw [← Nat.cast_prod] + exact_mod_cast Nat.le_of_dvd (Nat.pos_of_ne_zero hq) (Nat.prod_primeFactors_dvd q) + +theorem sum_log_div_primeFactors_le (q : ℕ) : + ∑ p ∈ q.primeFactors, Real.log p / p ≤ Real.log q := by + refine (Finset.sum_le_sum fun p hp => ?_).trans (sum_log_primeFactors_le q) + have hp1 : 1 ≤ (p : ℝ) := by + exact_mod_cast (Nat.mem_primeFactors.mp hp).1.one_le + exact div_le_self (Real.log_nonneg hp1) hp1 + +theorem sum_log_div_filter_dvd_le (q : ℕ) (hq : q ≠ 0) (s : Finset ℕ) + (hprime : ∀ p ∈ s, p.Prime) : + ∑ p ∈ s with p ∣ q, Real.log p / p ≤ Real.log q := by + refine (Finset.sum_le_sum_of_subset_of_nonneg ?_ ?_).trans + (sum_log_div_primeFactors_le q) + · intro p hp + rcases Finset.mem_filter.mp hp with ⟨hps, hpq⟩ + exact Nat.mem_primeFactors.mpr ⟨hprime p hps, hpq, hq⟩ + · intro p _ _ + exact div_nonneg (Real.log_natCast_nonneg p) (Nat.cast_nonneg p) + +theorem sum_log_div_filter_le_cutoff (s : Finset ℕ) (H : ℕ) : + ∑ p ∈ s with p ≤ H, Real.log p / p ≤ + ∑ p ∈ Finset.range (H + 1), Real.log p / p := by + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro p hp + exact Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.mem_filter.mp hp).2) + · intro p _ _ + exact div_nonneg (Real.log_natCast_nonneg p) (Nat.cast_nonneg p) + +end WeightedTorusJets +end +section + +open scoped BigOperators + +namespace WeightedTorusJets + +theorem prime_mass_partition_le {q H : ℕ} (hH : 2 ≤ H) (s : Finset ℕ) + (c : ℕ → ℂ) (hprime : ∀ p ∈ s, p.Prime) + (hclass : ∀ p ∈ s, c p = 1 ∨ p ∣ q ∨ c p = -1) : + ∑ p ∈ s, Real.log p / p ≤ + (∑ p ∈ s with c p = 1, Real.log p / p) + + (∑ p ∈ s with p ∣ q, Real.log p / p) + + (∑ p ∈ s with p ≤ H, Real.log p / p) + + ∑ p ∈ s with H < p ∧ ¬ p ∣ 2 * q ∧ c p = -1, Real.log p / p := by + classical + simp only [Finset.sum_filter] + rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib, ← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro p hp + have hn : 0 ≤ Real.log p / p := by + apply div_nonneg (Real.log_nonneg _) (Nat.cast_nonneg _) + exact_mod_cast (hprime p hp).one_lt.le + by_cases hsmall : p ≤ H + · simp only [hsmall, ite_true] + split_ifs <;> linarith + have hlarge : H < p := lt_of_not_ge hsmall + rcases hclass p hp with hpos | hram | hneg + · simp only [hpos, ite_true] + split_ifs <;> linarith + · simp only [hram, ite_true] + split_ifs <;> linarith + · by_cases hram : p ∣ q + · simp only [hram, ite_true] + split_ifs <;> linarith + have htwo : ¬ p ∣ 2 := by + intro hp2 + have := Nat.le_of_dvd (by decide : 0 < 2) hp2 + omega + simp only [hsmall, hram, hneg, hlarge, (hprime p hp).not_dvd_mul htwo hram, + ite_false, ite_true, and_self, not_false_eq_true] + split_ifs <;> linarith + +theorem good_mass_of_estimates {q H : ℕ} (hH : 2 ≤ H) (s : Finset ℕ) + (c : ℕ → ℂ) (hprime : ∀ p ∈ s, p.Prime) + (hclass : ∀ p ∈ s, c p = 1 ∨ p ∣ q ∨ c p = -1) + {L ell E A B D CH : ℝ} (hell : 0 ≤ ell) (hE : 0 ≤ E) + (hA : 0 ≤ A) (hB : 0 ≤ B) + (htotal : L - D ≤ ∑ p ∈ s, Real.log p / p) + (hpositive : (∑ p ∈ s with c p = 1, Real.log p / p) ≤ A * ell + B * E) + (hramified : (∑ p ∈ s with p ∣ q, Real.log p / p) ≤ ell) + (hsmall : (∑ p ∈ s with p ≤ H, Real.log p / p) ≤ CH) : + L - (A + B + 1) * ell - (A + B + 1) * E - (D + CH) ≤ + ∑ p ∈ s with H < p ∧ ¬ p ∣ 2 * q ∧ c p = -1, Real.log p / p := by + have hpartition := prime_mass_partition_le hH s c hprime hclass + nlinarith [mul_nonneg hB hell, mul_nonneg hA hE] + +end WeightedTorusJets +end +section +namespace WeightedTorusJets + +theorem good_prime_mass_of_primebias {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) : + ∃ C : ℝ, 0 < C ∧ ∀ H : ℕ, 2 ≤ H → ∃ CH : ℝ, + ∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + (∀ a : ZMod q, (χ a).im = 0) → ∀ X δ : ℝ, 3 ≤ X → 0 ≤ δ → + (∑ p ∈ Nat.primesLE ⌊X⌋₊ with χ ((p : ℕ) : ZMod q) = 1, Real.log p / p) ≤ + A * Real.log q + B * (δ * (Real.log X) ^ 2 / Real.log q) → + Real.log X - C * Real.log q - C * (δ * (Real.log X) ^ 2 / Real.log q) - CH ≤ + ∑ p ∈ Nat.primesLE ⌊X⌋₊ with + H < p ∧ ¬ p ∣ 2 * q ∧ χ ((p : ℕ) : ZMod q) = -1, Real.log p / p := by + classical + obtain ⟨D, _, hD⟩ := Mertens.prime_log_div_bounded_error + refine ⟨A + B + 1, by linarith, fun H hH => + ⟨D + ∑ p ∈ Finset.range (H + 1), Real.log p / p, ?_⟩⟩ + intro q _ hq χ hreal X δ hX hδ hbias + have hprime : ∀ p ∈ Nat.primesLE ⌊X⌋₊, p.Prime := by + intro p hp + exact Nat.prime_of_mem_primesLE hp + have hquadratic := (RealCharacterAnalysis.real_values_iff_quadratic χ).mp hreal + have hclass : ∀ p ∈ Nat.primesLE ⌊X⌋₊, + χ ((p : ℕ) : ZMod q) = 1 ∨ p ∣ q ∨ χ ((p : ℕ) : ZMod q) = -1 := by + intro p hp + rcases hquadratic ((p : ℕ) : ZMod q) with hz | ho | hm + · exact Or.inr (Or.inl ((RealCharacterAnalysis.apply_prime_eq_zero_iff χ + (hprime p hp)).mp hz)) + · exact Or.inl ho + · exact Or.inr (Or.inr hm) + have hlogq : 0 ≤ Real.log q := Real.log_natCast_nonneg q + have hE : 0 ≤ δ * (Real.log X) ^ 2 / Real.log q := + div_nonneg (mul_nonneg hδ (sq_nonneg _)) hlogq + have htotal : Real.log X - D ≤ + ∑ p ∈ Nat.primesLE ⌊X⌋₊, Real.log p / p := by + have := (abs_le.mp (hD X (by linarith))).1 + linarith + exact good_mass_of_estimates hH (Nat.primesLE ⌊X⌋₊) (fun p => χ ((p : ℕ) : ZMod q)) + hprime hclass hlogq hE hA hB htotal hbias + (sum_log_div_filter_dvd_le q (by omega) _ hprime) + (sum_log_div_filter_le_cutoff _ H) + +end WeightedTorusJets +end +section +namespace WeightedTorusJets + +theorem source_analytic_lemma : + ∃ C : ℝ, 0 < C ∧ + (∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + ∀ β : ℝ, 0 < β → β < 1 → DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ X : ℝ, 3 ≤ X → + (∑ p ∈ Nat.primesLE ⌊X⌋₊ with χ ((p : ℕ) : ZMod q) = 1, Real.log p / p) ≤ + C * Real.log q + C * (((1 - β) * Real.log q) * (Real.log X) ^ 2 / Real.log q)) ∧ + (∀ H : ℕ, 2 ≤ H → ∃ CH : ℝ, + ∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + ∀ β : ℝ, 0 < β → β < 1 → DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ X : ℝ, 3 ≤ X → + Real.log X - C * Real.log q - + C * (((1 - β) * Real.log q) * (Real.log X) ^ 2 / Real.log q) - CH ≤ + ∑ p ∈ Nat.primesLE ⌊X⌋₊ with + H < p ∧ ¬ p ∣ 2 * q ∧ χ ((p : ℕ) : ZMod q) = -1, Real.log p / p) := by + classical + obtain ⟨K, hK, hupper⟩ := logDeriv_upper_of_completedL_lower + let A := Real.exp 1 / 2 * K + let B := Real.exp 1 / 2 + have hA : 0 ≤ A := by dsimp [A]; positivity + have hB : 0 ≤ B := by dsimp [B]; positivity + let Cb := A + B + 1 + have hCb : 0 < Cb := by dsimp [Cb]; linarith + have hbias : ∀ (q : ℕ) [NeZero q], 3 ≤ q → ∀ χ : DirichletCharacter ℂ q, + χ.IsPrimitive → χ ≠ 1 → (∀ a : ZMod q, (χ a).im = 0) → + ∀ β : ℝ, 0 < β → β < 1 → DirichletCharacter.LFunction χ (β : ℂ) = 0 → + ∀ X : ℝ, 3 ≤ X → + (∑ p ∈ Nat.primesLE ⌊X⌋₊ with χ ((p : ℕ) : ZMod q) = 1, Real.log p / p) ≤ + Cb * Real.log q + Cb * (((1 - β) * Real.log q) * (Real.log X) ^ 2 / Real.log q) := by + intro q _ hq χ hprim hχ hreal β hβ0 hβ1 hzero X hX + have hs := primebias_sampling_point hX + have hu := hupper q hq χ hχ (1 + 1 / Real.log X) β hs.1 hs.2 + (real_zero_le_conductorCompletedL_logDeriv χ hprim hχ + ((RealCharacterAnalysis.real_values_iff_quadratic χ).mp hreal) hβ0 hzero hs.1) + have hp := positive_prime_mass_of_logDeriv_upper χ (X := X) (β := β) (K := K) (by linarith) hβ1 + (by simpa only [logDeriv_apply, neg_div] using hu) + have hell : 0 < Real.log q := Real.log_pos (by exact_mod_cast (show 1 < q by omega)) + have hdelta : 0 ≤ (1 - β) * Real.log q := mul_nonneg (by linarith) hell.le + have hE : 0 ≤ ((1 - β) * Real.log q) * (Real.log X) ^ 2 / Real.log q := + div_nonneg (mul_nonneg hdelta (sq_nonneg _)) hell.le + have heq : ((1 - β) * Real.log q) * (Real.log X) ^ 2 / Real.log q = + (1 - β) * (Real.log X) ^ 2 := by field_simp + rw [← heq] at hp + dsimp [A, B, Cb] at * + nlinarith [mul_nonneg hB hell.le, mul_nonneg hA hE] + obtain ⟨Cg, _, hgood⟩ := good_prime_mass_of_primebias hCb.le hCb.le + refine ⟨max Cb Cg, hCb.trans_le (le_max_left _ _), ?_, ?_⟩ + · intro q _ hq χ hprim hχ hreal β hβ0 hβ1 hzero X hX + have hp := hbias q hq χ hprim hχ hreal β hβ0 hβ1 hzero X hX + have hell : 0 ≤ Real.log q := Real.log_natCast_nonneg q + have hE : 0 ≤ ((1 - β) * Real.log q) * (Real.log X) ^ 2 / Real.log q := + div_nonneg (mul_nonneg (mul_nonneg (by linarith) hell) (sq_nonneg _)) hell + nlinarith [mul_nonneg (sub_nonneg.mpr (le_max_left Cb Cg)) hell, + mul_nonneg (sub_nonneg.mpr (le_max_left Cb Cg)) hE] + · intro H hH + obtain ⟨CH, hCH⟩ := hgood H hH + refine ⟨CH, ?_⟩ + intro q _ hq χ hprim hχ hreal β hβ0 hβ1 hzero X hX + have hell : 0 ≤ Real.log q := Real.log_natCast_nonneg q + have hdelta : 0 ≤ (1 - β) * Real.log q := mul_nonneg (by linarith) hell + have hE : 0 ≤ ((1 - β) * Real.log q) * (Real.log X) ^ 2 / Real.log q := + div_nonneg (mul_nonneg hdelta (sq_nonneg _)) hell + have hg := hCH q hq χ hreal X ((1 - β) * Real.log q) hX hdelta + (hbias q hq χ hprim hχ hreal β hβ0 hβ1 hzero X hX) + nlinarith [mul_nonneg (sub_nonneg.mpr (le_max_right Cb Cg)) hell, + mul_nonneg (sub_nonneg.mpr (le_max_right Cb Cg)) hE] + +end WeightedTorusJets +end +section +namespace WeightedTorusJets + +open _root_.Erdos970.Complex.Hadamard + +theorem source_hadamard_logDeriv_identity {q : ℕ} [NeZero q] (hq : 3 ≤ q) + (χ : DirichletCharacter ℂ q) (hprim : χ.IsPrimitive) (hχ : χ ≠ 1) + (hreal : ∀ a : ZMod q, (χ a).im = 0) {s : ℝ} (hs : 1 < s) : + (-logDeriv (DirichletCharacter.LFunction χ) (s : ℂ)).re = + Real.log ((q : ℝ) / Real.pi) / 2 + + (logDeriv Complex.Gamma (((s + (1 - (χ (-1)).re) / 2) / 2 : ℝ) : ℂ)).re / 2 - + ∑' p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ, + (1 / ((s : ℂ) - divisorZeroIndex₀Val p)).re := by + have hd := congrArg Complex.re + (conductorCompletedL_logDeriv_decomposition χ hχ (s := (s : ℂ)) (by simpa using hs)) + rw [Complex.add_re] at hd + have hg := conductor_gamma_correction_real (by omega : q ≠ 0) χ (by linarith : 0 < s) + have hz := real_logDeriv_conductorCompletedL_eq_divisor_tsum_source χ hprim hχ + ((RealCharacterAnalysis.real_values_iff_quadratic χ).mp hreal) hs + rw [Complex.neg_re] + linarith + +theorem source_logDeriv_upper : + ∃ K : ℝ, 0 < K ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → + (∀ a : ZMod q, (χ a).im = 0) → ∀ β : ℝ, 0 < β → β < 1 → + DirichletCharacter.LFunction χ (β : ℂ) = 0 → ∀ s : ℝ, 1 < s → s ≤ 2 → + (-logDeriv riemannZeta (s : ℂ) - + logDeriv (DirichletCharacter.LFunction χ) (s : ℂ)).re ≤ + K * Real.log q + 1 / (s - 1) - 1 / (s - β) := by + obtain ⟨K, hK, hupper⟩ := logDeriv_upper_of_completedL_lower + refine ⟨K, hK, ?_⟩ + intro q _ hq χ hprim hχ hreal β hβ0 _ hzero s hs hs2 + exact hupper q hq χ hχ s β hs hs2 + (real_zero_le_conductorCompletedL_logDeriv χ hprim hχ + ((RealCharacterAnalysis.real_values_iff_quadratic χ).mp hreal) hβ0 hzero hs) + +end WeightedTorusJets +end + +namespace WeightedTorusJets + +theorem logDeriv_real_of_complex {f : ℂ → ℂ} {s : ℝ} + (hf : DifferentiableAt ℂ f (s : ℂ)) (hreal : (f (s : ℂ)).im = 0) : + (logDeriv f (s : ℂ)).re = logDeriv (fun x : ℝ => (f (x : ℂ)).re) s := by + have hderiv := hf.hasDerivAt.real_of_complex.deriv + have hval : ((f (s : ℂ)).re : ℂ) = f (s : ℂ) := by + apply Complex.ext <;> simp [hreal] + rw [logDeriv_apply, logDeriv_apply, hderiv, ← hval, Complex.div_ofReal_re] + simp + + + +open _root_.Erdos970.Complex.Hadamard + +theorem source_hadamard_logDeriv_identity_real {q : ℕ} [NeZero q] (hq : 3 ≤ q) + (χ : DirichletCharacter ℂ q) (hprim : χ.IsPrimitive) (hχ : χ ≠ 1) + (hreal : ∀ a : ZMod q, (χ a).im = 0) {s : ℝ} (hs : 1 < s) : + -logDeriv (fun x : ℝ => (DirichletCharacter.LFunction χ (x : ℂ)).re) s = + Real.log ((q : ℝ) / Real.pi) / 2 + + logDeriv Real.Gamma ((s + (1 - (χ (-1)).re) / 2) / 2) / 2 - + ∑' p : divisorZeroIndex₀ (conductorCompletedL χ) Set.univ, + (1 / ((s : ℂ) - divisorZeroIndex₀Val p)).re := by + have hL := logDeriv_real_of_complex + (DirichletCharacter.differentiable_LFunction hχ (s : ℂ)) + (RealCharacterAnalysis.lFunction_real χ hχ hreal s) + have harg : 0 < (s + (1 - (χ (-1)).re) / 2) / 2 := by + rw [character_parity_parameter_real] + split_ifs <;> linarith + have hG := logDeriv_real_of_complex + (analyticAt_Gamma_of_re_pos (s := (((s + (1 - (χ (-1)).re) / 2) / 2 : ℝ) : ℂ)) + (by simpa using harg)).differentiableAt + (by rw [Complex.Gamma_ofReal]; rfl) + simp only [Complex.Gamma_ofReal, Complex.ofReal_re] at hG + rw [← hL, ← hG] + simpa only [Complex.neg_re] using source_hadamard_logDeriv_identity hq χ hprim hχ hreal hs + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem completedL_analyticOrderAt_eq_LFunction {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) {s : ℂ} (hs : 0 < s.re) : + analyticOrderAt (DirichletCharacter.completedLFunction χ) s = + analyticOrderAt (DirichletCharacter.LFunction χ) s := by + have hgn := gammaFactor_ne_zero_of_re_pos χ hs + have hinv : Differentiable ℂ (fun z => (χ.gammaFactor z)⁻¹) := by + rcases χ.even_or_odd with heven | hodd + · convert Complex.differentiable_Gammaℝ_inv using 1 + funext z + rw [heven.gammaFactor_def] + · convert Complex.differentiable_Gammaℝ_inv.comp (differentiable_id.add_const 1) using 1 + funext z + rw [hodd.gammaFactor_def] + rfl + have hgamma : AnalyticAt ℂ χ.gammaFactor s := by + convert (hinv.analyticAt s).inv (inv_ne_zero hgn) using 1 + funext z + exact (inv_inv (χ.gammaFactor z)).symm + have heq : DirichletCharacter.completedLFunction χ =ᶠ[nhds s] + fun z => DirichletCharacter.LFunction χ z * χ.gammaFactor z := by + have hU : {z : ℂ | 0 < z.re} ∈ nhds s := + (Complex.continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds hs + filter_upwards [hU] with z hz using completedL_eq_mul_gammaFactor χ hz + rw [analyticOrderAt_congr heq] + change analyticOrderAt (DirichletCharacter.LFunction χ * χ.gammaFactor) s = _ + rw [analyticOrderAt_mul ((DirichletCharacter.differentiable_LFunction hχ).analyticAt s) hgamma, + hgamma.analyticOrderAt_eq_zero.mpr hgn, add_zero] + +theorem conductorCompletedL_analyticOrderAt_eq_LFunction {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) {s : ℂ} (hs : 0 < s.re) : + analyticOrderAt (conductorCompletedL χ) s = + analyticOrderAt (DirichletCharacter.LFunction χ) s := + (conductorCompletedL_analyticOrderAt_eq χ hχ s).trans + (completedL_analyticOrderAt_eq_LFunction χ hχ hs) + + + +theorem exists_radius_LFunction_ne_zero {q : ℕ} [NeZero q] + (χ : DirichletCharacter ℂ q) (hχ : χ ≠ 1) : + ∃ ε : ℝ, 0 < ε ∧ ∀ β : ℝ, |β - 1| < ε → + DirichletCharacter.LFunction χ (β : ℂ) ≠ 0 := by + have hcont : ContinuousAt (fun β : ℝ => DirichletCharacter.LFunction χ (β : ℂ)) 1 := + (DirichletCharacter.differentiable_LFunction hχ).continuous.continuousAt.comp + Complex.continuous_ofReal.continuousAt + have hnonzero : DirichletCharacter.LFunction χ ((1 : ℝ) : ℂ) ≠ 0 := by + simpa using DirichletCharacter.LFunction_apply_one_ne_zero hχ + obtain ⟨ε, hε, hball⟩ := Metric.mem_nhds_iff.mp (hcont.eventually_ne hnonzero) + refine ⟨ε, hε, fun β hβ => hball ?_⟩ + simpa [Metric.mem_ball, Real.dist_eq] using hβ + +theorem exists_radius_LFunction_ne_zero_fixed_modulus (q : ℕ) [NeZero q] : + ∃ ε : ℝ, 0 < ε ∧ ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → + ∀ β : ℝ, |β - 1| < ε → DirichletCharacter.LFunction χ (β : ℂ) ≠ 0 := by + classical + have h : ∀ᶠ β : ℝ in nhds 1, ∀ χ : DirichletCharacter ℂ q, + χ ≠ 1 → DirichletCharacter.LFunction χ (β : ℂ) ≠ 0 := by + apply Filter.eventually_all.mpr + intro χ + by_cases hχ : χ = 1 + · exact Filter.Eventually.of_forall fun _ hne => (hne hχ).elim + · obtain ⟨ε, hε, hzero⟩ := exists_radius_LFunction_ne_zero χ hχ + have hr : ∀ᶠ β : ℝ in nhds 1, |β - 1| < ε := by + filter_upwards [Metric.ball_mem_nhds (1 : ℝ) hε] with β hβ + simpa [Metric.mem_ball, Real.dist_eq] using hβ + exact hr.mono fun β hβ _ => hzero β hβ + obtain ⟨ε, hε, hball⟩ := Metric.mem_nhds_iff.mp h + refine ⟨ε, hε, fun χ hχ β hβ => hball ?_ χ hχ⟩ + simpa [Metric.mem_ball, Real.dist_eq] using hβ + +theorem exists_gap_fixed_modulus (q : ℕ) [NeZero q] (hq : 3 ≤ q) : + ∃ c : ℝ, 0 < c ∧ ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → + ∀ β : ℝ, (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → c ≤ (1 - β) * Real.log (q : ℝ) := by + obtain ⟨ε, hε, hne⟩ := exists_radius_LFunction_ne_zero_fixed_modulus q + have hlog : 0 < Real.log (q : ℝ) := Real.log_pos (by exact_mod_cast (show 1 < q by omega)) + refine ⟨ε * Real.log (q : ℝ), mul_pos hε hlog, ?_⟩ + intro χ hχ β hβ + apply mul_le_mul_of_nonneg_right _ hlog.le + by_contra! hlt + have habs : |β - 1| = 1 - β := by + rw [abs_sub_comm, abs_of_pos (sub_pos.mpr hβ.2.1)] + exact hne χ hχ β (by simpa [habs] using hlt) hβ.2.2 + +theorem exists_gap_bounded_moduli (Q : ℕ) : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → q ≤ Q → + ∀ χ : DirichletCharacter ℂ q, χ ≠ 1 → + ∀ β : ℝ, (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → c ≤ (1 - β) * Real.log (q : ℝ) := by + induction Q with + | zero => + refine ⟨1, zero_lt_one, ?_⟩ + intro q _ hq hQ + omega + | succ Q ih => + obtain ⟨c, hc, hbound⟩ := ih + by_cases hQ : 3 ≤ Q + 1 + · let : NeZero (Q + 1) := ⟨by omega⟩ + obtain ⟨d, hd, hlast⟩ := exists_gap_fixed_modulus (Q + 1) hQ + refine ⟨min c d, lt_min hc hd, ?_⟩ + intro q _ hq hqQ χ hχ β hβ + rcases Nat.lt_or_eq_of_le hqQ with hlt | rfl + · exact (min_le_left _ _).trans (hbound q hq (by omega) χ hχ β hβ) + · exact (min_le_right _ _).trans (hlast χ hχ β hβ) + · refine ⟨1, zero_lt_one, ?_⟩ + intro q _ hq hqQ + omega + +theorem exists_small_gap_large_modulus (hnot : ¬ (∃ c : ℝ, 0 < c ∧ + ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → + (∀ a : ZMod q, (χ a).im = 0) → ∀ β : ℝ, + (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → + c ≤ (1 - β) * Real.log (q : ℝ))) + (Q : ℕ) {ε : ℝ} (hε : 0 < ε) : + ∃ q : ℕ, ∃ hq : NeZero q, 3 ≤ q ∧ Q < q ∧ + ∃ χ : DirichletCharacter ℂ q, χ.IsPrimitive ∧ χ ≠ 1 ∧ (∀ a : ZMod q, (χ a).im = 0) ∧ + ∃ β : ℝ, (0 < β ∧ β < 1 ∧ @DirichletCharacter.LFunction q hq χ (β : ℂ) = 0) ∧ + (1 - β) * Real.log (q : ℝ) < ε := by + classical + obtain ⟨c, hc, hbound⟩ := exists_gap_bounded_moduli Q + have hfail : ¬ (∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → + (∀ a : ZMod q, (χ a).im = 0) → ∀ β : ℝ, + (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → + min c ε ≤ (1 - β) * Real.log (q : ℝ)) := fun h => + hnot ⟨min c ε, lt_min hc hε, h⟩ + push Not at hfail + obtain ⟨q, hq0, hq, χ, hprim, hχ, hreal, β, hβ, hsmall⟩ := hfail + let := hq0 + have hQ : Q < q := by + by_contra! hle + exact (not_lt_of_ge (hbound q hq hle χ hχ β hβ)) + (hsmall.trans_le (min_le_left _ _)) + exact ⟨q, hq0, hq, hQ, χ, hprim, hχ, hreal, β, hβ, + hsmall.trans_le (min_le_right _ _)⟩ + +theorem exists_contrary_sequence (hnot : ¬ (∃ c : ℝ, 0 < c ∧ + ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ χ : DirichletCharacter ℂ q, χ.IsPrimitive → χ ≠ 1 → + (∀ a : ZMod q, (χ a).im = 0) → ∀ β : ℝ, + (0 < β ∧ β < 1 ∧ DirichletCharacter.LFunction χ (β : ℂ) = 0) → + c ≤ (1 - β) * Real.log (q : ℝ))) : + ∃ q : ℕ → ℕ, ∃ hq : ∀ n, NeZero (q n), + ∃ χ : ∀ n, DirichletCharacter ℂ (q n), ∃ β : ℕ → ℝ, + (∀ n, 3 ≤ q n ∧ (χ n).IsPrimitive ∧ χ n ≠ 1 ∧ (∀ a : ZMod (q n), (χ n a).im = 0) ∧ + (0 < β n ∧ β n < 1 ∧ @DirichletCharacter.LFunction (q n) (hq n) (χ n) (β n : ℂ) = 0)) ∧ + Filter.Tendsto q Filter.atTop Filter.atTop ∧ + Filter.Tendsto (fun n => (1 - β n) * Real.log (q n : ℝ)) + Filter.atTop (nhds 0) := by + classical + have hex (n : ℕ) := exists_small_gap_large_modulus hnot n + (ε := 1 / ((n : ℝ) + 1)) (by positivity) + choose q hq hq3 hn χ hprim hχ hreal β hβ hsmall using hex + refine ⟨q, hq, χ, β, fun n => ⟨hq3 n, hprim n, hχ n, hreal n, hβ n⟩, + Filter.tendsto_atTop_mono (fun n => (hn n).le) Filter.tendsto_id, ?_⟩ + refine squeeze_zero (fun n => ?_) (fun n => (hsmall n).le) + tendsto_one_div_add_atTop_nhds_zero_nat + exact mul_nonneg (sub_nonneg.mpr (hβ n).2.1.le) (Real.log_natCast_nonneg (q n)) + +end WeightedTorusJets + +end AnalyticAssemblyScope + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusDerivationOverRat.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusDerivationOverRat.lean new file mode 100644 index 0000000000000000000000000000000000000000..f1c446de6865b712f78d451596e2f02e1b195daf --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusDerivationOverRat.lean @@ -0,0 +1,310 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.DerivationJet + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +noncomputable section +namespace WeightedTorusJets.Geometry + +theorem rectangularTaylorThree_augmentation {R B σ : Type*} + [CommRing R] [Algebra ℚ R] [CommRing B] [Algebra ℚ B] + (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) (D₁ D₂ D₃ : Derivation ℚ R R) + (i₁ i₂ i₃ : σ) (f : R →+* B) (a : R) : + rectangularAugmentation k hk (rectangularTaylorThree σ k D₁ D₂ D₃ i₁ i₂ i₃ f a) = f a := + rectangularTaylorThree_residue σ k hk D₁ D₂ D₃ i₁ i₂ i₃ f + (rectangularAugmentation k hk).toRingHom (fun p => quotientAugmentation_mk _ _ p) a + +variable {R : Type*} [CommRing R] [Algebra ℚ R] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + + +variable {K : Type*} [Field K] [CharZero K] + +local notation "PolyRing" => MvPolynomial (Fin 4) K +local notation "torusCoordinateProduct" => (∏ i : Fin 4, (MvPolynomial.X i : PolyRing)) +local notation "TorusCoordRing" => Localization.Away torusCoordinateProduct + +noncomputable def torusDerivationOverRat (c : Fin 3 → Fin 4 → K) (j : Fin 3) : + Derivation ℚ TorusCoordRing TorusCoordRing := + (localizeDerivation (T := TorusCoordRing) (Submonoid.powers torusCoordinateProduct) + (invariantDerivation (c j))).restrictScalars ℚ + +noncomputable def localTorusDerivationOverRat (c : Fin 3 → Fin 4 → K) + (q : PrimeSpectrum TorusCoordRing) (j : Fin 3) : + Derivation ℚ (Localization.AtPrime q.asIdeal) (Localization.AtPrime q.asIdeal) := + localizeDerivation q.asIdeal.primeCompl (torusDerivationOverRat c j) + +theorem torusDerivationOverRat_commute (c : Fin 3 → Fin 4 → K) (i j : Fin 3) : + Function.Commute (torusDerivationOverRat c i) (torusDerivationOverRat c j) := by + simpa only [torusDerivationOverRat, Derivation.coe_restrictScalars] using + localizeDerivation_commute (T := TorusCoordRing) (Submonoid.powers torusCoordinateProduct) + (invariantDerivation (c i)) (invariantDerivation (c j)) + (invariantDerivation_commute (c i) (c j)) + +theorem localTorusDerivationOverRat_commute (c : Fin 3 → Fin 4 → K) + (q : PrimeSpectrum TorusCoordRing) (i j : Fin 3) : + Function.Commute (localTorusDerivationOverRat c q i) (localTorusDerivationOverRat c q j) := + localizeDerivation_commute q.asIdeal.primeCompl + (torusDerivationOverRat c i) (torusDerivationOverRat c j) + (torusDerivationOverRat_commute c i j) + +theorem torus_derivationJet_eq (c : Fin 3 → Fin 4 → K) (a : Fin 3 → ℕ) (F : PolyRing) : + derivationJet (torusDerivationOverRat c) a (algebraMap PolyRing TorusCoordRing F) = + algebraMap PolyRing TorusCoordRing (invariantJet c a F) := by + simpa only [derivationJet, torusDerivationOverRat, Module.End.pow_apply, + Derivation.coeFn_coe, Derivation.coe_restrictScalars] using + torus_mixed_derivatives_algebraMap c a F + +theorem torus_derivativeStageIdeal_eq (c : Fin 3 → Fin 4 → K) + (t : Fin 3 → ℕ) (b : ℕ) (F : PolyRing) : + derivativeStageIdeal (torusDerivationOverRat c) t b (algebraMap PolyRing TorusCoordRing F) = + rectangleJetIdeal (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F)) t b := by + simp only [derivativeStageIdeal, rectangleJetIdeal, torus_derivationJet_eq] + +theorem local_torus_derivativeStageIdeal_eq (c : Fin 3 → Fin 4 → K) + (q : PrimeSpectrum TorusCoordRing) (t : Fin 3 → ℕ) (b : ℕ) (F : PolyRing) : + Ideal.map (algebraMap TorusCoordRing (Localization.AtPrime q.asIdeal)) + (rectangleJetIdeal (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F)) t b) = + derivativeStageIdeal (localTorusDerivationOverRat c q) t b + (algebraMap TorusCoordRing (Localization.AtPrime q.asIdeal) + (algebraMap PolyRing TorusCoordRing F)) := by + rw [← torus_derivativeStageIdeal_eq] + apply derivativeStageIdeal_map + intro j f + exact (localizeDerivation_algebraMap q.asIdeal.primeCompl (torusDerivationOverRat c j) f).symm + +theorem local_torus_stage_le_maximal (c : Fin 3 → Fin 4 → K) + (q : PrimeSpectrum TorusCoordRing) (t : Fin 3 → ℕ) (b : ℕ) (F : PolyRing) + (hq : rectangleJetIdeal + (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F)) t b ≤ q.asIdeal) : + derivativeStageIdeal (localTorusDerivationOverRat c q) t b + (algebraMap TorusCoordRing (Localization.AtPrime q.asIdeal) + (algebraMap PolyRing TorusCoordRing F)) ≤ + IsLocalRing.maximalIdeal (Localization.AtPrime q.asIdeal) := by + rw [← local_torus_derivativeStageIdeal_eq] + exact (Ideal.map_mono hq).trans_eq + (IsLocalization.AtPrime.map_eq_maximalIdeal q.asIdeal (Localization.AtPrime q.asIdeal)) + +theorem local_torus_stage_primary_data (c : Fin 3 → Fin 4 → K) + (q : PrimeSpectrum TorusCoordRing) (t : Fin 3 → ℕ) (b : ℕ) (F : PolyRing) + (hq : (rectangleJetIdeal + (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet c a F)) t b).IsMinimalPrime q.asIdeal) : + let J := derivativeStageIdeal (localTorusDerivationOverRat c q) t b + (algebraMap TorusCoordRing (Localization.AtPrime q.asIdeal) + (algebraMap PolyRing TorusCoordRing F)) + J.radical = IsLocalRing.maximalIdeal (Localization.AtPrime q.asIdeal) ∧ J.IsPrimary ∧ + ∃ n : ℕ, IsLocalRing.maximalIdeal (Localization.AtPrime q.asIdeal) ^ n ≤ J := by + dsimp only + rw [← local_torus_derivativeStageIdeal_eq] + exact ⟨component_local_radical _ q.asIdeal hq, component_local_primary _ q.asIdeal hq, + component_local_contains_maximal_pow _ q.asIdeal hq⟩ + + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +section ScalarCompatibility + +variable {K S L : Type*} [CommRing K] [Algebra ℚ K] + [CommRing S] [Algebra K S] [Algebra ℚ S] [IsScalarTower ℚ K S] + [CommRing L] [Algebra K L] [Algebra ℚ L] [IsScalarTower ℚ K L] + [Algebra S L] [IsScalarTower K S L] [IsScalarTower ℚ S L] + +theorem derivationCotangentResidue_restrictScalars (D : Derivation K S S) (I : Ideal S) : + derivationCotangentResidue (D.restrictScalars ℚ) I = derivationCotangentResidue D I := by + ext x + obtain ⟨x, rfl⟩ := I.toCotangent_surjective x + rfl + +end ScalarCompatibility + + +attribute [local instance] Ideal.Quotient.field + +variable {K : Type*} [Field K] [CharZero K] + +local notation "PolyRing" => MvPolynomial (Fin 4) K +local notation "torusCoordinateProduct" => (∏ i : Fin 4, (MvPolynomial.X i : PolyRing)) +local notation "TorusCoordRing" => Localization.Away torusCoordinateProduct + +theorem localTorusDerivationOverRat_eq_direct (c : Fin 3 → Fin 4 → K) + (q : PrimeSpectrum TorusCoordRing) (M : Submonoid PolyRing) + [IsLocalization M (Localization.AtPrime q.asIdeal)] (j : Fin 3) : + localTorusDerivationOverRat c q j = + (localizeDerivation (T := Localization.AtPrime q.asIdeal) M + (invariantDerivation (c j))).restrictScalars ℚ := by + apply localization_derivation_ext M + intro F + rw [IsScalarTower.algebraMap_apply PolyRing TorusCoordRing (Localization.AtPrime q.asIdeal)] + simp only [localTorusDerivationOverRat, localizeDerivation_algebraMap, + torusDerivationOverRat, Derivation.coe_restrictScalars] + rw [← IsScalarTower.algebraMap_apply PolyRing TorusCoordRing (Localization.AtPrime q.asIdeal), + ← IsScalarTower.algebraMap_apply PolyRing TorusCoordRing (Localization.AtPrime q.asIdeal), + localizeDerivation_algebraMap] + +theorem localTorusDerivationOverRat_cotangent_eq_direct (c : Fin 3 → Fin 4 → K) + (q : PrimeSpectrum TorusCoordRing) (M : Submonoid PolyRing) + [IsLocalization M (Localization.AtPrime q.asIdeal)] (j : Fin 3) : + derivationCotangentResidue (localTorusDerivationOverRat c q j) + (IsLocalRing.maximalIdeal (Localization.AtPrime q.asIdeal)) = + derivationCotangentResidue + (localizeDerivation (T := Localization.AtPrime q.asIdeal) M (invariantDerivation (c j))) + (IsLocalRing.maximalIdeal (Localization.AtPrime q.asIdeal)) := by + rw [localTorusDerivationOverRat_eq_direct c q M j, derivationCotangentResidue_restrictScalars] + + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {R : Type*} [CommRing R] [Algebra ℚ R] + +theorem derivationJet_selected_one (D : Fin 3 → Derivation ℚ R R) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i : I) (hi : ∀ j : I, j = i) (α : I → ℕ) (F : R) : + ((D i).toLinearMap ^ α i) F = + derivationJet D (Function.extend (Subtype.val : I → Fin 3) α 0) F := by + classical + have hα : α = Pi.single i (α i) := by + funext j + rw [hi j] + simp + rw [hα, extend_selectedIndex_single] + simpa using derivationJet_shift D h01 h02 h12 i (α i) (0 : Fin 3 → ℕ) F + +theorem derivationJet_selected_two (D : Fin 3 → Derivation ℚ R R) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i j : I) (hij : i ≠ j) + (hcover : ∀ u : I, u = i ∨ u = j) (α : I → ℕ) (F : R) : + ((D i).toLinearMap ^ α i) (((D j).toLinearMap ^ α j) F) = + derivationJet D (Function.extend (Subtype.val : I → Fin 3) α 0) F := by + classical + have hα : α = Pi.single j (α j) + Pi.single i (α i) := by + funext u + rcases hcover u with rfl | rfl <;> simp [hij, hij.symm] + conv_lhs => rw [← derivationJet_zero D F] + rw [derivationJet_shift D h01 h02 h12, derivationJet_shift D h01 h02 h12] + have he : Function.extend (Subtype.val : I → Fin 3) α 0 = + Pi.single (j : Fin 3) (α j) + Pi.single (i : Fin 3) (α i) := by + conv_lhs => rw [hα] + calc + _ = Function.extend (Subtype.val : I → Fin 3) (Pi.single j (α j)) 0 + + Function.extend (Subtype.val : I → Fin 3) (Pi.single i (α i)) 0 := + Function.extend_add (Subtype.val : I → Fin 3) _ _ 0 0 + _ = _ := by rw [extend_selectedIndex_single, extend_selectedIndex_single] + rw [he, zero_add] + +theorem derivationJet_selected_three (D : Fin 3 → Derivation ℚ R R) + (h01 : Function.Commute (D 0) (D 1)) + (h02 : Function.Commute (D 0) (D 2)) + (h12 : Function.Commute (D 1) (D 2)) + (I : Finset (Fin 3)) (i j k : I) (hij : i ≠ j) (hik : i ≠ k) (hjk : j ≠ k) + (hcover : ∀ u : I, u = i ∨ u = j ∨ u = k) (α : I → ℕ) (F : R) : + ((D i).toLinearMap ^ α i) (((D j).toLinearMap ^ α j) (((D k).toLinearMap ^ α k) F)) = + derivationJet D (Function.extend (Subtype.val : I → Fin 3) α 0) F := by + classical + have hα : α = (Pi.single k (α k) + Pi.single j (α j)) + Pi.single i (α i) := by + funext u + rcases hcover u with rfl | rfl | rfl <;> simp [hij, hij.symm, hik, hik.symm, hjk, hjk.symm] + conv_lhs => rw [← derivationJet_zero D F] + rw [derivationJet_shift D h01 h02 h12, derivationJet_shift D h01 h02 h12, + derivationJet_shift D h01 h02 h12] + have he : Function.extend (Subtype.val : I → Fin 3) α 0 = + (Pi.single (k : Fin 3) (α k) + Pi.single (j : Fin 3) (α j)) + + Pi.single (i : Fin 3) (α i) := by + conv_lhs => rw [hα] + calc + _ = Function.extend (Subtype.val : I → Fin 3) (Pi.single k (α k) + Pi.single j (α j)) 0 + + Function.extend (Subtype.val : I → Fin 3) (Pi.single i (α i)) 0 := + Function.extend_add (Subtype.val : I → Fin 3) _ _ 0 0 + _ = (Function.extend (Subtype.val : I → Fin 3) (Pi.single k (α k)) 0 + + Function.extend (Subtype.val : I → Fin 3) (Pi.single j (α j)) 0) + + Function.extend (Subtype.val : I → Fin 3) (Pi.single i (α i)) 0 := by + congr 1 + exact Function.extend_add (Subtype.val : I → Fin 3) _ _ 0 0 + _ = _ := by rw [extend_selectedIndex_single, extend_selectedIndex_single, + extend_selectedIndex_single] + rw [he, zero_add] + +end WeightedTorusJets.Geometry + +open scoped TensorProduct + + +open scoped TensorProduct + + + + + + + +open Module + + + + +open scoped BigOperators + + + + + + + +namespace WeightedTorusJets.Geometry + + +variable {K : Type*} [Field K] [CharZero K] [IsAlgClosed K] + +local notation "PolyRing" => MvPolynomial (Fin 4) K +local notation "torusCoordinateProduct" => (∏ i : Fin 4, (MvPolynomial.X i : PolyRing)) +local notation "TorusCoordRing" => Localization.Away torusCoordinateProduct + + + + + +variable {K : Type*} [Field K] [CharZero K] [IsAlgClosed K] + +local notation "PolyRing" => MvPolynomial (Fin 4) K +local notation "TorusCoordRing" => Localization.Away + (∏ i : Fin 4, (MvPolynomial.X i : PolyRing)) + + +end WeightedTorusJets.Geometry + +end +end + + + + +open scoped BigOperators + + +open Module + + +open MvPolynomial + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusEvalOne.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusEvalOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..f60644584a4624d83fc8226b109b457914fcf55b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusEvalOne.lean @@ -0,0 +1,721 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.FiniteTypeFieldModelEquiv + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section OriginalSourceGeometryOverlay +open Module CategoryTheory _root_.AlgebraicGeometry _root_.OAI.Erdos970.AlgebraicGeometry +open scoped BigOperators TensorProduct +noncomputable section +noncomputable section +open scoped TensorProduct +open Module +namespace WeightedTorusJets.Geometry + +theorem exists_independent_normal_finset_algebraMap {K L : Type*} + [Field K] [Field L] [Algebra K L] + (c : Fin 4 → K) (hc : c ≠ 0) + (b : Module.Basis (Fin 3) K (LinearMap.ker (dotProductEquiv K (Fin 4) c))) + (T : Submodule L (Fin 4 → L)) + (hT : T = ⊥ ∨ ¬ T ≤ LinearMap.ker + (dotProductEquiv L (Fin 4) (algebraMap K L ∘ c))) : + ∃ I : Finset (Fin 3), I.card = min (4 - Module.finrank L T) 3 ∧ + LinearIndepOn L (fun i => T.mkQ (algebraMap K L ∘ (b i : Fin 4 → K))) + (I : Set (Fin 3)) := by + obtain ⟨bL, hbL⟩ := exists_basis_ker_dotProduct_algebraMap (L := L) c hc b + let ωL := dotProductEquiv L (Fin 4) (algebraMap K L ∘ c) + have hd : Module.finrank L (LinearMap.ker ωL) = 3 := by + simpa using Module.finrank_eq_card_basis bL + have hωL : ωL ≠ 0 := by + intro hzero + rw [hzero, LinearMap.ker_zero, finrank_top, Module.finrank_pi, + Fintype.card_fin] at hd + omega + obtain ⟨I, hI, hind⟩ := exists_independent_normal_finset ωL hωL (by simp) T hT bL + refine ⟨I, hI, ?_⟩ + simpa only [hbL] using hind + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry +attribute [local instance] Ideal.Quotient.field + +theorem cotangent_finrank_add_logarithmic_tangent_finrank + {K S : Type*} [Field K] [PerfectField K] [CommRing S] + [Algebra K S] [Algebra (MvPolynomial (Fin 4) K) S] + [IsScalarTower K (MvPolynomial (Fin 4) K) S] + (M : Submonoid (MvPolynomial (Fin 4) K)) [IsLocalization M S] + (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : Fin 4, IsUnit (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) : + Module.finrank (S ⧸ I) I.Cotangent + + Module.finrank (S ⧸ I) (LinearMap.range (logarithmicTangentMap (k := K) + (fun i : Fin 4 => Ideal.Quotient.mk I + (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))))) = 4 := by + have : Algebra.FormallyEtale (MvPolynomial (Fin 4) K) S := + Algebra.FormallyEtale.of_isLocalization M + have : Algebra.EssFiniteType (MvPolynomial (Fin 4) K) S := + Algebra.EssFiniteType.of_isLocalization S M + have : Algebra.EssFiniteType K S := Algebra.EssFiniteType.comp K (MvPolynomial (Fin 4) K) S + let T := LinearMap.range (logarithmicTangentMap (k := K) + (fun i : Fin 4 => Ideal.Quotient.mk I + (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i)))) + have he := (coordinateNormalEquivCotangentDual I hx).finrank_eq + rw [Subspace.dual_finrank_eq] at he + rw [← he] + simpa only [Module.finrank_pi, Fintype.card_fin] using T.finrank_quotient_add_finrank + +theorem exists_selected_independent_normal_coordinates + {K S : Type*} [Field K] [PerfectField K] [CommRing S] + [Algebra K S] [Algebra (MvPolynomial (Fin 4) K) S] + [IsScalarTower K (MvPolynomial (Fin 4) K) S] + (M : Submonoid (MvPolynomial (Fin 4) K)) [IsLocalization M S] + (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : Fin 4, IsUnit (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) + (c : Fin 4 → K) (hc : c ≠ 0) + (b : Module.Basis (Fin 3) K (LinearMap.ker (dotProductEquiv K (Fin 4) c))) + (hform : Module.finrank (S ⧸ I) I.Cotangent ≤ 3 → + logarithmicForm c (fun i : Fin 4 => Ideal.Quotient.mk I + (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) ≠ 0) : + ∃ J : Finset (Fin 3), J.card = min (Module.finrank (S ⧸ I) I.Cotangent) 3 ∧ + LinearIndependent (S ⧸ I) (fun j : J => + (LinearMap.range (logarithmicTangentMap (k := K) (fun i : Fin 4 => + Ideal.Quotient.mk I (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))))).mkQ + (algebraMap K (S ⧸ I) ∘ (b j : Fin 4 → K))) := by + let f (i : Fin 4) := Ideal.Quotient.mk I + (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i)) + let T := LinearMap.range (logarithmicTangentMap (k := K) f) + have hdim : Module.finrank (S ⧸ I) I.Cotangent + Module.finrank (S ⧸ I) T = 4 := + cotangent_finrank_add_logarithmic_tangent_finrank M I hx + have hω : logarithmicLinearForm (F := S ⧸ I) c = + dotProductEquiv (S ⧸ I) (Fin 4) (algebraMap K (S ⧸ I) ∘ c) := by + ext v + simp [logarithmicLinearForm_apply, dotProduct, Function.comp_def] + have hT : T = ⊥ ∨ ¬ T ≤ LinearMap.ker + (dotProductEquiv (S ⧸ I) (Fin 4) (algebraMap K (S ⧸ I) ∘ c)) := by + by_cases hh : Module.finrank (S ⧸ I) I.Cotangent ≤ 3 + · exact Or.inr (hω ▸ (logarithmicForm_ne_zero_iff_tangent_not_le c f).mp (hform hh)) + · exact Or.inl (Submodule.finrank_eq_zero.mp (by omega)) + obtain ⟨J, hJ, hind⟩ := exists_independent_normal_finset_algebraMap c hc b T hT + exact ⟨J, hJ.trans (by congr 1; omega), hind⟩ + +theorem coordinateNormal_invariant_functional_eq + {K S : Type*} [Field K] [PerfectField K] [CommRing S] + [Algebra K S] [Algebra (MvPolynomial (Fin 4) K) S] + [IsScalarTower K (MvPolynomial (Fin 4) K) S] + [Algebra.FormallyEtale (MvPolynomial (Fin 4) K) S] [Algebra.EssFiniteType K S] + (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : Fin 4, IsUnit (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) + (D : Derivation K S S) (v : Fin 4 → K) + (hD : ∀ i, D (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i)) = + algebraMap K S (v i) * algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i)) : + coordinateNormalEquivCotangentDual I hx (Submodule.Quotient.mk (algebraMap K (S ⧸ I) ∘ v)) = + derivationCotangentResidue D I := by + ext x + obtain ⟨x, rfl⟩ := I.toCotangent_surjective x + exact coordinateNormal_invariant_pairing I hx D (fun i => algebraMap K S (v i)) hD x + +theorem exists_selected_independent_conormal_derivations + {K S : Type*} [Field K] [PerfectField K] [CommRing S] + [Algebra K S] [Algebra (MvPolynomial (Fin 4) K) S] + [IsScalarTower K (MvPolynomial (Fin 4) K) S] + (M : Submonoid (MvPolynomial (Fin 4) K)) [IsLocalization M S] + (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : Fin 4, IsUnit (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) + (c : Fin 4 → K) (hc : c ≠ 0) + (b : Module.Basis (Fin 3) K (LinearMap.ker (dotProductEquiv K (Fin 4) c))) + (hform : Module.finrank (S ⧸ I) I.Cotangent ≤ 3 → + logarithmicForm c (fun i : Fin 4 => Ideal.Quotient.mk I + (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) ≠ 0) : + ∃ J : Finset (Fin 3), J.card = min (Module.finrank (S ⧸ I) I.Cotangent) 3 ∧ + LinearIndependent (S ⧸ I) (fun j : J => derivationCotangentResidue + (localizeDerivation M (invariantDerivation (b j : Fin 4 → K))) I) := by + have : Algebra.FormallyEtale (MvPolynomial (Fin 4) K) S := + Algebra.FormallyEtale.of_isLocalization M + have : Algebra.EssFiniteType (MvPolynomial (Fin 4) K) S := + Algebra.EssFiniteType.of_isLocalization S M + have : Algebra.EssFiniteType K S := Algebra.EssFiniteType.comp K (MvPolynomial (Fin 4) K) S + obtain ⟨J, hJ, hind⟩ := exists_selected_independent_normal_coordinates M I hx c hc b hform + refine ⟨J, hJ, ?_⟩ + let e := coordinateNormalEquivCotangentDual I hx + have he (j : J) : e (Submodule.Quotient.mk (algebraMap K (S ⧸ I) ∘ (b j : Fin 4 → K))) = + derivationCotangentResidue + (localizeDerivation M (invariantDerivation (b j : Fin 4 → K))) I := + coordinateNormal_invariant_functional_eq I hx + (localizeDerivation M (invariantDerivation (b j : Fin 4 → K))) (b j : Fin 4 → K) + (fun i => localize_invariantDerivation_X M (b j : Fin 4 → K) i) + have hi := hind.map' e.toLinearMap (LinearMap.ker_eq_bot.mpr e.injective) + change LinearIndependent (S ⧸ I) (fun j : J => + e (Submodule.Quotient.mk (algebraMap K (S ⧸ I) ∘ (b j : Fin 4 → K)))) at hi + have hfamily := funext he + rwa [hfamily] at hi + + + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry +attribute [local instance] Ideal.Quotient.field + +theorem local_logarithmicForm_ne_zero_of_cotangent_le_three + {K S : Type*} [Field K] [CharZero K] [IsAlgClosed K] [CommRing S] + [Algebra K S] [Algebra (MvPolynomial (Fin 4) K) S] + [IsScalarTower K (MvPolynomial (Fin 4) K) S] + (M : Submonoid (MvPolynomial (Fin 4) K)) [IsLocalization M S] + (I : Ideal S) [I.IsMaximal] + (hx : ∀ i : Fin 4, IsUnit (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) + (hdim : Module.finrank (S ⧸ I) I.Cotangent ≤ 3) : + logarithmicForm c (fun i : Fin 4 => Ideal.Quotient.mk I + (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i))) ≠ 0 := by + have : Algebra.EssFiniteType (MvPolynomial (Fin 4) K) S := + Algebra.EssFiniteType.of_isLocalization S M + have : Algebra.EssFiniteType K S := Algebra.EssFiniteType.comp K (MvPolynomial (Fin 4) K) S + let f (i : Fin 4) := Ideal.Quotient.mk I + (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i)) + intro hform + have hf (i : Fin 4) : f i ≠ 0 := ((hx i).map (Ideal.Quotient.mk I)).ne_zero + have halg := isAlgebraic_of_logarithmicForm_eq_zero c hc f hf hform + have hT : LinearMap.range (logarithmicTangentMap (k := K) f) = ⊥ := by + apply LinearMap.range_eq_bot.mpr + ext D i + obtain ⟨a, ha⟩ := (halg i).isIntegral.mem_range_algebraMap_of_minpoly_splits + (K := K) (by simpa using IsAlgClosed.splits (minpoly K (f i))) + change (f i)⁻¹ * D (f i) = 0 + rw [← ha, D.map_algebraMap, mul_zero] + have hd := cotangent_finrank_add_logarithmic_tangent_finrank M I hx + change Module.finrank (S ⧸ I) I.Cotangent + + Module.finrank (S ⧸ I) (LinearMap.range (logarithmicTangentMap (k := K) f)) = 4 at hd + rw [hT, finrank_bot] at hd + omega + +theorem exists_selected_independent_conormal_derivations_atPrime + {K S : Type*} [Field K] [CharZero K] [IsAlgClosed K] [CommRing S] [IsLocalRing S] + [Algebra K S] [Algebra (MvPolynomial (Fin 4) K) S] + [IsScalarTower K (MvPolynomial (Fin 4) K) S] + (p : Ideal (MvPolynomial (Fin 4) K)) [p.IsPrime] [IsLocalization.AtPrime S p] + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) + (b : Module.Basis (Fin 3) K (LinearMap.ker (dotProductEquiv K (Fin 4) c))) + (hX : ∀ i : Fin 4, MvPolynomial.X i ∉ p) : + ∃ J : Finset (Fin 3), + J.card = min (Module.finrank (S ⧸ IsLocalRing.maximalIdeal S) (IsLocalRing.maximalIdeal S).Cotangent) 3 ∧ + LinearIndependent (S ⧸ IsLocalRing.maximalIdeal S) (fun j : J => derivationCotangentResidue + (localizeDerivation p.primeCompl (invariantDerivation (b j : Fin 4 → K))) + (IsLocalRing.maximalIdeal S)) := by + have hx (i : Fin 4) : IsUnit (algebraMap (MvPolynomial (Fin 4) K) S (MvPolynomial.X i)) := + IsLocalization.map_units S (⟨MvPolynomial.X i, hX i⟩ : p.primeCompl) + have hc0 : c ≠ 0 := by + intro hzero + exact hc.ne_zero (0 : Fin 4) (congrFun hzero 0) + apply exists_selected_independent_conormal_derivations p.primeCompl + (IsLocalRing.maximalIdeal S) hx c hc0 b + intro hdim + exact local_logarithmicForm_ne_zero_of_cotangent_le_three p.primeCompl + (IsLocalRing.maximalIdeal S) hx c hc hdim + +theorem exists_selected_first_order_taylor_parameters_atPrime + {K S : Type*} [Field K] [CharZero K] [IsAlgClosed K] [CommRing S] [IsLocalRing S] + [Algebra K S] [Algebra (MvPolynomial (Fin 4) K) S] + [IsScalarTower K (MvPolynomial (Fin 4) K) S] + (p : Ideal (MvPolynomial (Fin 4) K)) [p.IsPrime] [IsLocalization.AtPrime S p] + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) + (b : Module.Basis (Fin 3) K (LinearMap.ker (dotProductEquiv K (Fin 4) c))) + (hX : ∀ i : Fin 4, MvPolynomial.X i ∉ p) : + ∃ J : Finset (Fin 3), + J.card = min (Module.finrank (S ⧸ IsLocalRing.maximalIdeal S) (IsLocalRing.maximalIdeal S).Cotangent) 3 ∧ + ∀ a : J → S ⧸ IsLocalRing.maximalIdeal S, ∃ x : IsLocalRing.maximalIdeal S, + ∀ j : J, Ideal.Quotient.mk (IsLocalRing.maximalIdeal S) + (localizeDerivation p.primeCompl (invariantDerivation (b j : Fin 4 → K)) x) = a j := by + obtain ⟨J, hJ, hind⟩ := exists_selected_independent_conormal_derivations_atPrime (S := S) p c hc b hX + exact ⟨J, hJ, exists_ideal_element_with_derivatives (IsLocalRing.maximalIdeal S) + (fun j : J => localizeDerivation p.primeCompl (invariantDerivation (b j : Fin 4 → K))) hind⟩ + +end WeightedTorusJets.Geometry + +end +end +end OriginalSourceGeometryOverlay + +section + +open scoped BigOperators + +namespace WeightedTorusJets.Geometry + +variable {R ι : Type*} [CommSemiring R] [Fintype ι] + +theorem invariantDerivation_commute (c d : ι → R) : + Function.Commute (invariantDerivation c) (invariantDerivation d) := by + intro f + induction f using MvPolynomial.induction_on' with + | monomial m r => + simp only [invariantDerivation_monomial, Derivation.map_smul, smul_smul] + rw [mul_comm] + | add f g hf hg => simp only [map_add, hf, hg] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] + [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] + +omit [Algebra R S] [IsScalarTower R S T] in +theorem localization_derivation_ext (M : Submonoid S) [IsLocalization M T] + {D E : Derivation R T T} + (h : ∀ s : S, D (algebraMap S T s) = E (algebraMap S T s)) : D = E := by + apply Derivation.ext + intro t + obtain ⟨s, m, rfl⟩ := IsLocalization.exists_mk'_eq M t + have hd := D.leibniz (IsLocalization.mk' T s m) (algebraMap S T m) + have he := E.leibniz (IsLocalization.mk' T s m) (algebraMap S T m) + rw [IsLocalization.mk'_spec, h] at hd + rw [IsLocalization.mk'_spec] at he + simp only [smul_eq_mul, h] at hd he + have heq : algebraMap S T (m : S) * D (IsLocalization.mk' T s m) = + algebraMap S T (m : S) * E (IsLocalization.mk' T s m) := by + exact add_left_cancel (hd.symm.trans he) + exact (IsLocalization.map_units T m).mul_left_cancel heq + +theorem iterate_localizeDerivation_algebraMap (M : Submonoid S) [IsLocalization M T] + (D : Derivation R S S) (n : ℕ) (s : S) : + (localizeDerivation M D)^[n] (algebraMap S T s) = algebraMap S T (D^[n] s) := by + induction n with + | zero => rfl + | succ n hn => + rw [Function.iterate_succ_apply', hn, localizeDerivation_algebraMap, + Function.iterate_succ_apply'] + +theorem localizeDerivation_commute (M : Submonoid S) [IsLocalization M T] + (D E : Derivation R S S) (h : Function.Commute D E) : + Function.Commute (localizeDerivation M D : T → T) (localizeDerivation M E) := by + have hzero : ⁅localizeDerivation (T := T) M D, localizeDerivation (T := T) M E⁆ = + (0 : Derivation R T T) := by + apply localization_derivation_ext M + intro s + simp only [Derivation.commutator_apply, localizeDerivation_algebraMap, + Derivation.zero_apply] + rw [h s, sub_self] + intro t + exact sub_eq_zero.mp (by + simpa only [Derivation.commutator_apply, Derivation.zero_apply] using + congrArg (fun F : Derivation R T T => F t) hzero) + +theorem mixed_localizeDerivation_algebraMap (M : Submonoid S) [IsLocalization M T] + (D : Fin 3 → Derivation R S S) (a : Fin 3 → ℕ) (s : S) : + ((localizeDerivation M (D 0)).toLinearMap ^ a 0) + (((localizeDerivation M (D 1)).toLinearMap ^ a 1) + (((localizeDerivation M (D 2)).toLinearMap ^ a 2) (algebraMap S T s))) = + algebraMap S T (((D 0).toLinearMap ^ a 0) + (((D 1).toLinearMap ^ a 1) (((D 2).toLinearMap ^ a 2) s))) := by + simp only [Module.End.pow_apply, Derivation.coeFn_coe, + iterate_localizeDerivation_algebraMap] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {K : Type*} [Field K] + +theorem torus_algebraMap_injective : + Function.Injective (algebraMap (MvPolynomial (Fin 4) K) + (Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) := by + have ht : (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) ≠ 0 := + Finset.prod_ne_zero_iff.mpr fun i _ ↦ MvPolynomial.X_ne_zero i + exact IsLocalization.injective _ (powers_le_nonZeroDivisors_of_noZeroDivisors ht) + +theorem torus_polynomial_ne_zero {F : MvPolynomial (Fin 4) K} (hF : F ≠ 0) : + algebraMap (MvPolynomial (Fin 4) K) + (Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K))) F ≠ 0 := by + exact fun h ↦ hF (torus_algebraMap_injective (h.trans (map_zero _).symm)) + +theorem torus_coordinate_isUnit (i : Fin 4) : + IsUnit (algebraMap (MvPolynomial (Fin 4) K) + (Localization.Away (∏ j : Fin 4, (MvPolynomial.X j : MvPolynomial (Fin 4) K))) + (MvPolynomial.X i)) := by + have h := IsLocalization.Away.algebraMap_isUnit + (S := Localization.Away (∏ j : Fin 4, (MvPolynomial.X j : MvPolynomial (Fin 4) K))) + (∏ j : Fin 4, (MvPolynomial.X j : MvPolynomial (Fin 4) K)) + rw [map_prod] at h + exact IsUnit.prod_univ_iff.mp h i + + + +variable {R : Type*} [CommRing R] (I p : Ideal R) [p.IsPrime] + +variable {K : Type*} [Field K] + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +variable {R : Type*} [CommRing R] (I p : Ideal R) [p.IsPrime] + +theorem component_local_radical (hp : p ∈ I.minimalPrimes) : + (I.map (algebraMap R (Localization.AtPrime p))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime p) := by + rw [IsLocalization.AtPrime.radical_map_of_mem_minimalPrimes (Localization.AtPrime p) p I hp, + Localization.AtPrime.map_eq_maximalIdeal] + +theorem component_local_primary (hp : p ∈ I.minimalPrimes) : + (I.map (algebraMap R (Localization.AtPrime p))).IsPrimary := by + apply Ideal.isPrimary_of_isMaximal_radical + rw [component_local_radical I p hp] + infer_instance + +theorem component_local_contains_maximal_pow [IsNoetherianRing R] + (hp : p ∈ I.minimalPrimes) : + ∃ n : ℕ, IsLocalRing.maximalIdeal (Localization.AtPrime p) ^ n ≤ + I.map (algebraMap R (Localization.AtPrime p)) := by + have h := (I.map (algebraMap R (Localization.AtPrime p))).exists_radical_pow_le_of_fg + (Ideal.fg_of_isNoetherianRing _) + rwa [component_local_radical I p hp] at h + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +noncomputable def torusEvalOne {K : Type*} [CommSemiring K] : + Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) →+* K := + IsLocalization.Away.lift + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) + (g := MvPolynomial.eval (fun _ ↦ (1 : K))) (by simp [map_prod]) + +@[simp] theorem torusEvalOne_algebraMap {K : Type*} [CommSemiring K] + (F : MvPolynomial (Fin 4) K) : + torusEvalOne (algebraMap (MvPolynomial (Fin 4) K) + (Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K))) F) = + MvPolynomial.eval (fun _ ↦ 1) F := by + simp [torusEvalOne] + +noncomputable def torusIdentityPoint {K : Type*} [Field K] : + PrimeSpectrum + (Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K))) := + ⟨RingHom.ker torusEvalOne, RingHom.ker_isPrime _⟩ + + + +theorem rectangleJetIdeal_mono {ι R : Type*} [CommRing R] + (jet : (ι → ℕ) → R) (t : ι → ℕ) : Monotone (rectangleJetIdeal jet t) := by + intro b c hbc + apply Ideal.span_mono + exact Set.image_mono fun a ha j ↦ (ha j).trans (Nat.mul_le_mul_right (t j) hbc) + +theorem rectangleJetIdeal_zero {ι R : Type*} [CommRing R] + (jet : (ι → ℕ) → R) (t : ι → ℕ) : + rectangleJetIdeal jet t 0 = Ideal.span {jet 0} := by + unfold rectangleJetIdeal + congr 1 + ext x + simp only [Set.mem_image, Set.mem_ofPred_eq, zero_mul, Nat.le_zero_eq, + Set.mem_singleton_iff] + constructor + · rintro ⟨a, ha, rfl⟩ + exact congrArg jet (funext ha) + · rintro rfl + exact ⟨0, fun _ ↦ rfl, rfl⟩ + +theorem rectangleJetZeroLocus_antitone {ι R : Type*} [CommRing R] + (jet : (ι → ℕ) → R) (t : ι → ℕ) : + Antitone (fun b ↦ PrimeSpectrum.zeroLocus (rectangleJetIdeal jet t b : Set R)) := + fun _ _ h ↦ PrimeSpectrum.zeroLocus_anti_mono_ideal (rectangleJetIdeal_mono jet t h) + +theorem rectangleJetIdeal_le_ker {ι R S : Type*} [CommRing R] [CommRing S] + (jet : (ι → ℕ) → R) (t : ι → ℕ) (φ : R →+* S) {b c : ℕ} + (hbc : b ≤ c) (hvanish : ∀ a, (∀ j, a j ≤ c * t j) → φ (jet a) = 0) : + rectangleJetIdeal jet t b ≤ RingHom.ker φ := by + apply Ideal.span_le.mpr + rintro _ ⟨a, ha, rfl⟩ + exact hvanish a fun j ↦ (ha j).trans (Nat.mul_le_mul_right (t j) hbc) + +theorem exists_consecutive_eq_of_dimension_bound (d : ℕ → ℕ) (n : ℕ) + (hd : ∀ b, b ≤ n → d (b + 1) ≤ d b) (hbound : d 0 ≤ n) : + ∃ b, b ≤ n ∧ d b = d (b + 1) := by + by_contra! h + have hdecrease : ∀ b ≤ n, d (b + 1) < d b := by + intro b hb + exact lt_of_le_of_ne (hd b hb) (Ne.symm (h b hb)) + have hsteps : ∀ b ≤ n + 1, d b + b ≤ d 0 := by + intro b + induction b with + | zero => simp + | succ b ih => + intro hb + have hi := ih (by omega) + have hj := hdecrease b (by omega) + omega + have := hsteps (n + 1) le_rfl + omega + +theorem isIrreducible_subtype_preimage {X : Type*} [TopologicalSpace X] + {S Z : Set X} (hS : IsIrreducible S) (hSZ : S ⊆ Z) : + IsIrreducible ((Subtype.val : Z → X) ⁻¹' S) := by + let := Subtype.irreducibleSpace hS + let f : S → Z := fun s ↦ ⟨s, hSZ s.2⟩ + have hf : Continuous f := continuous_subtype_val.subtype_mk _ + have hi := (IrreducibleSpace.isIrreducible_univ S).image f hf.continuousOn + convert hi using 1 + ext z + constructor + · intro hz + exact ⟨⟨z, hz⟩, Set.mem_univ _, Subtype.ext rfl⟩ + · rintro ⟨y, _, rfl⟩ + exact y.2 + +def irreducibleClosedSubtypeEmbedding {X : Type*} [TopologicalSpace X] (Z : Set X) : + {V : TopologicalSpace.IrreducibleCloseds X // (V : Set X) ⊆ Z} ↪o + TopologicalSpace.IrreducibleCloseds Z := + OrderEmbedding.ofMapLEIff + (fun V ↦ ⟨Subtype.val ⁻¹' (V.1 : Set X), + isIrreducible_subtype_preimage V.1.isIrreducible V.2, + V.1.isClosed.preimage continuous_subtype_val⟩) + fun A _ ↦ ⟨fun h x hx ↦ h (show (⟨x, A.2 hx⟩ : Z) ∈ + Subtype.val ⁻¹' (A.1 : Set X) from hx), fun h _ hx ↦ h hx⟩ + +theorem local_irreducible_dimension_nat {X : Type*} [TopologicalSpace X] + (x : X) (Z : Set X) (hx : x ∈ Z) (hZ : IsClosed Z) (n : ℕ) + (hdim : topologicalKrullDim Z ≤ n) : + ∃ d ≤ n, Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z} = d := by + let A := {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z} + let e : A ↪o {V : TopologicalSpace.IrreducibleCloseds X // (V : Set X) ⊆ Z} := + Subtype.orderEmbedding (fun _ hV ↦ hV.2) + have hb : Order.krullDim A ≤ n := + (Order.krullDim_le_of_orderEmbedding (e.trans (irreducibleClosedSubtypeEmbedding Z))).trans hdim + let : Nonempty A := ⟨⟨⟨closure {x}, isIrreducible_singleton.closure, isClosed_closure⟩, + subset_closure (Set.mem_singleton x), + closure_minimal (Set.singleton_subset_iff.mpr hx) hZ⟩⟩ + let : FiniteDimensionalOrder A := + Order.finiteDimensionalOrder_iff_krullDim_ne_bot_and_top.mpr + ⟨Order.krullDim_ne_bot_iff.mpr inferInstance, + ne_top_of_le_ne_top (WithBot.coe_lt_coe.mpr (ENat.natCast_lt_top n)).ne hb⟩ + have heq := Order.krullDim_eq_length_of_finiteDimensionalOrder (α := A) + refine ⟨(LTSeries.longestOf A).length, ?_, heq⟩ + rw [heq] at hb + exact_mod_cast hb + +theorem localization_ringKrullDim_le {R S : Type*} [CommRing R] [CommRing S] + (M : Submonoid R) [Algebra R S] [IsLocalization M S] : + ringKrullDim S ≤ ringKrullDim R := by + rw [ringKrullDim, Order.krullDim_eq_of_orderIso (IsLocalization.primeSpectrumOrderIso M S)] + exact Order.krullDim_le_of_orderEmbedding (OrderEmbedding.subtype _) + +theorem hypersurface_ringKrullDim_le {R : Type*} [CommRing R] [IsDomain R] + {F : R} (hF : F ≠ 0) {n : ℕ} (hdim : ringKrullDim R ≤ n + 1) : + ringKrullDim (R ⧸ Ideal.span {F}) ≤ n := by + exact ENat.WithBot.add_le_add_one_right_iff.mp + ((ringKrullDim_quotient_succ_le_of_nonZeroDivisor + (mem_nonZeroDivisors_of_ne_zero hF)).trans hdim) + +theorem four_variable_localization_ringKrullDim_le {k S : Type*} [Field k] [CommRing S] + (M : Submonoid (MvPolynomial (Fin 4) k)) [Algebra (MvPolynomial (Fin 4) k) S] + [IsLocalization M S] : ringKrullDim S ≤ 4 := by + have hdim := localization_ringKrullDim_le (S := S) M + simpa [MvPolynomial.ringKrullDim_of_isNoetherianRing_of_finite, + ringKrullDim_eq_zero_of_field] using hdim + +theorem vanishingIdeal_isMinimalPrime_of_maximal {R : Type*} [CommRing R] + (I : Ideal R) (V : Set (PrimeSpectrum R)) + (hV : Maximal (fun S ↦ IsIrreducible S ∧ S ⊆ PrimeSpectrum.zeroLocus (I : Set R)) V) : + I.IsMinimalPrime (PrimeSpectrum.vanishingIdeal V) := by + refine ⟨⟨PrimeSpectrum.isIrreducible_iff_vanishingIdeal_isPrime.mp hV.1.1, + (PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal V I).mp hV.1.2⟩, ?_⟩ + intro q hq hqV + have hVq : V ⊆ PrimeSpectrum.zeroLocus (q : Set R) := + (PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal V q).mpr hqV + have hqV' : PrimeSpectrum.zeroLocus (q : Set R) ⊆ V := + hV.2 ⟨(PrimeSpectrum.isIrreducible_zeroLocus_iff_of_radical q hq.1.isRadical).mpr hq.1, + PrimeSpectrum.zeroLocus_anti_mono_ideal hq.2⟩ hVq + have h := PrimeSpectrum.vanishingIdeal_anti_mono hqV' + simpa only [PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical, hq.1.isRadical.radical] using h + +theorem exists_shared_maximal_of_krullDim_eq_with_height {α β : Type*} + [PartialOrder α] [PartialOrder β] (e : β ↪o α) (n : ℕ) + (hα : Order.krullDim α = n) (hβ : Order.krullDim β = n) : + ∃ b : β, IsMax b ∧ IsMax (e b) ∧ Order.height b = n ∧ Order.height (e b) = n := by + obtain ⟨p, hp⟩ := Order.le_krullDim_iff.mp (le_of_eq hβ.symm) + let q := p.map e e.strictMono + have hmax : IsMax (e p.last) := by + intro a ha + by_contra hnot + have hlt : q.last < a := lt_of_le_not_ge ha hnot + have hlength := Order.LTSeries.length_le_krullDim (q.snoc a hlt) + have hn : (n + 1 : WithBot ℕ∞) ≤ n := by + simpa [q, hp, hα] using hlength + norm_cast at hn + omega + refine ⟨p.last, fun b hb ↦ e.le_iff_le.mp (hmax (e.monotone hb)), hmax, ?_, ?_⟩ + · apply le_antisymm + · have hd := Order.height_le_krullDim p.last + rw [hβ] at hd + exact_mod_cast hd + · simpa [hp] using Order.length_le_height_last (p := p) + · apply le_antisymm + · have hd := Order.height_le_krullDim (e p.last) + rw [hα] at hd + exact_mod_cast hd + · simpa [q, hp] using Order.length_le_height_last (p := q) + +theorem local_irreducible_dimension_eq_order_height + {X : Type*} [TopologicalSpace X] (x : X) (Z : Set X) + (V : {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z}) : + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds X // x ∈ W ∧ (W : Set X) ⊆ V.1} = + (Order.height V : WithBot ℕ∞) := by + let e : {W : TopologicalSpace.IrreducibleCloseds X // x ∈ W ∧ (W : Set X) ⊆ V.1} ≃o + Set.Iic V := + { toFun := fun W ↦ ⟨⟨W.1, W.2.1, W.2.2.trans V.2.2⟩, W.2.2⟩ + invFun := fun W ↦ ⟨W.1.1, W.1.2.1, W.2⟩ + left_inv := fun _ ↦ rfl + right_inv := fun _ ↦ rfl + map_rel_iff' := Iff.rfl } + exact (Order.krullDim_eq_of_orderIso e).trans (Order.height_eq_krullDim_Iic V).symm + +theorem exists_shared_component_of_full_local_dimension + {X : Type*} [TopologicalSpace X] (x : X) (Z₁ Z₂ : Set X) + (hZ₁ : IsClosed Z₁) (hZ₂Z₁ : Z₂ ⊆ Z₁) (n : ℕ) + (hd₁ : Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z₁} = n) + (hd₂ : Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z₂} = n) : + ∃ V : Set X, x ∈ V ∧ V ⊆ Z₂ ∧ + Maximal (fun S ↦ IsIrreducible S ∧ S ⊆ Z₁) V ∧ + Maximal (fun S ↦ IsIrreducible S ∧ S ⊆ Z₂) V ∧ + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds X // x ∈ W ∧ (W : Set X) ⊆ V} = n := by + let e : {V : TopologicalSpace.IrreducibleCloseds X // + x ∈ V ∧ (V : Set X) ⊆ Z₂} ↪o + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z₁} := + Subtype.orderEmbedding (fun V hV ↦ ⟨hV.1, hV.2.trans hZ₂Z₁⟩) + obtain ⟨V, _, hmax, hVheight, _⟩ := + exists_shared_maximal_of_krullDim_eq_with_height e n hd₁ hd₂ + have hm : Maximal (fun S : Set X ↦ IsIrreducible S ∧ S ⊆ Z₁) (V.1 : Set X) := by + refine ⟨⟨V.1.isIrreducible, V.2.2.trans hZ₂Z₁⟩, ?_⟩ + intro S hS hVS + let W : {W : TopologicalSpace.IrreducibleCloseds X // + x ∈ W ∧ (W : Set X) ⊆ Z₁} := + ⟨⟨closure S, hS.1.closure, isClosed_closure⟩, + subset_closure (hVS V.2.1), closure_minimal hS.2 hZ₁⟩ + have hVW : e V ≤ W := fun _ hy ↦ subset_closure (hVS hy) + exact subset_closure.trans (hmax hVW) + refine ⟨V.1, V.2.1, V.2.2, hm, + ⟨⟨V.1.isIrreducible, V.2.2⟩, + fun S hS hVS ↦ hm.2 ⟨hS.1, hS.2.trans hZ₂Z₁⟩ hVS⟩, ?_⟩ + rw [local_irreducible_dimension_eq_order_height x Z₂ V, hVheight] + rfl + +theorem exists_shared_component_of_dimension_three_full + {X : Type*} [TopologicalSpace X] (x : X) (Z : ℕ → Set X) + (hclosed : ∀ b ≤ 4, IsClosed (Z b)) (hnested : Antitone Z) + (hx : x ∈ Z 4) (hdim : topologicalKrullDim (Z 0) ≤ 3) : + ∃ b ≤ 3, ∃ n : ℕ, n ≤ 3 ∧ ∃ V : Set X, + x ∈ V ∧ V ⊆ Z (b + 1) ∧ + Maximal (fun S ↦ IsIrreducible S ∧ S ⊆ Z b) V ∧ + Maximal (fun S ↦ IsIrreducible S ∧ S ⊆ Z (b + 1)) V ∧ + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds X // x ∈ W ∧ (W : Set X) ⊆ Z b} = n ∧ + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds X // x ∈ W ∧ (W : Set X) ⊆ Z (b + 1)} = n ∧ + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds X // x ∈ W ∧ (W : Set X) ⊆ V} = n := by + have hex : ∀ b, b ≤ 4 → ∃ d : ℕ, d ≤ 3 ∧ Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z b} = d := by + intro b hb + apply local_irreducible_dimension_nat x (Z b) (hnested hb hx) (hclosed b hb) 3 + have he := (Topology.IsEmbedding.inclusion (hnested (Nat.zero_le b))).isInducing + exact he.topologicalKrullDim_le.trans hdim + let d (b : ℕ) : ℕ := if hb : b ≤ 4 then (hex b hb).choose else 0 + have hd : ∀ b, b ≤ 4 → Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z b} = d b := by + intro b hb + simpa only [d, dite_eq_left hb] using (hex b hb).choose_spec.2 + have hdle : ∀ b, b ≤ 4 → d b ≤ 3 := by + intro b hb + simpa only [d, dite_eq_left hb] using (hex b hb).choose_spec.1 + have hmono : ∀ b, b ≤ 3 → d (b + 1) ≤ d b := by + intro b hb + let e : {V : TopologicalSpace.IrreducibleCloseds X // + x ∈ V ∧ (V : Set X) ⊆ Z (b + 1)} ↪o + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z b} := + Subtype.orderEmbedding (fun V hV ↦ ⟨hV.1, hV.2.trans (hnested (Nat.le_succ b))⟩) + have he := Order.krullDim_le_of_orderEmbedding e + rw [hd b (by omega), hd (b + 1) (by omega)] at he + exact_mod_cast he + obtain ⟨b, hb, heq⟩ := exists_consecutive_eq_of_dimension_bound d 3 hmono (hdle 0 (by omega)) + have hdnext : Order.krullDim + {V : TopologicalSpace.IrreducibleCloseds X // x ∈ V ∧ (V : Set X) ⊆ Z (b + 1)} = d b := by + rw [hd (b + 1) (by omega), heq] + obtain ⟨V, hxV, hVZ, hm₁, hm₂, hVdim⟩ := + exists_shared_component_of_full_local_dimension x (Z b) (Z (b + 1)) + (hclosed b (by omega)) (hnested (Nat.le_succ b)) (d b) (hd b (by omega)) hdnext + exact ⟨b, hb, d b, hdle b (by omega), V, hxV, hVZ, hm₁, hm₂, + hd b (by omega), hdnext, hVdim⟩ + +theorem rectangleJets_have_shared_component_full + {ι R : Type*} [CommRing R] [IsDomain R] + (jet : (ι → ℕ) → R) (t : ι → ℕ) (p : PrimeSpectrum R) + (hp : rectangleJetIdeal jet t 4 ≤ p.asIdeal) (hjet : jet 0 ≠ 0) + (hdim : ringKrullDim R ≤ 4) : + let Z := fun b ↦ PrimeSpectrum.zeroLocus (rectangleJetIdeal jet t b : Set R) + ∃ b ≤ 3, ∃ n : ℕ, n ≤ 3 ∧ ∃ V : Set (PrimeSpectrum R), + p ∈ V ∧ V ⊆ Z (b + 1) ∧ + Maximal (fun S ↦ IsIrreducible S ∧ S ⊆ Z b) V ∧ + Maximal (fun S ↦ IsIrreducible S ∧ S ⊆ Z (b + 1)) V ∧ + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R) // + p ∈ W ∧ (W : Set (PrimeSpectrum R)) ⊆ Z b} = n ∧ + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R) // + p ∈ W ∧ (W : Set (PrimeSpectrum R)) ⊆ Z (b + 1)} = n ∧ + Order.krullDim + {W : TopologicalSpace.IrreducibleCloseds (PrimeSpectrum R) // + p ∈ W ∧ (W : Set (PrimeSpectrum R)) ⊆ V} = n := by + apply exists_shared_component_of_dimension_three_full p + (fun b ↦ PrimeSpectrum.zeroLocus (rectangleJetIdeal jet t b : Set R)) + (fun b _ ↦ PrimeSpectrum.isClosed_zeroLocus _) + (rectangleJetZeroLocus_antitone jet t) hp + calc + topologicalKrullDim (PrimeSpectrum.zeroLocus (rectangleJetIdeal jet t 0 : Set R)) = + Order.krullDim (TopologicalSpace.IrreducibleCloseds + (PrimeSpectrum.zeroLocus (rectangleJetIdeal jet t 0 : Set R)))ᵒᵈ := + Order.krullDim_orderDual.symm + _ = Order.krullDim (PrimeSpectrum.zeroLocus (rectangleJetIdeal jet t 0 : Set R)) := + (Order.krullDim_eq_of_orderIso + (PrimeSpectrum.zeroLocusEquivIrreducibleCloseds + (rectangleJetIdeal jet t 0 : Set R))).symm + _ = ringKrullDim (R ⧸ rectangleJetIdeal jet t 0) := (ringKrullDim_quotient _).symm + _ ≤ 3 := by + rw [rectangleJetIdeal_zero] + exact hypersurface_ringKrullDim_le hjet hdim + +theorem rectangleJets_have_shared_minimal_prime {ι R : Type*} [CommRing R] [IsDomain R] + (jet : (ι → ℕ) → R) (t : ι → ℕ) (p : PrimeSpectrum R) + (hp : rectangleJetIdeal jet t 4 ≤ p.asIdeal) (hjet : jet 0 ≠ 0) + (hdim : ringKrullDim R ≤ 4) : + ∃ b ≤ 3, ∃ q : Ideal R, q ≤ p.asIdeal ∧ + (rectangleJetIdeal jet t b).IsMinimalPrime q ∧ + (rectangleJetIdeal jet t (b + 1)).IsMinimalPrime q := by + obtain ⟨b, hb, _, _, V, hpV, _, hVb, hVb', _⟩ := + rectangleJets_have_shared_component_full jet t p hp hjet hdim + refine ⟨b, hb, PrimeSpectrum.vanishingIdeal V, ?_, + vanishingIdeal_isMinimalPrime_of_maximal _ V hVb, + vanishingIdeal_isMinimalPrime_of_maximal _ V hVb'⟩ + simpa only [PrimeSpectrum.vanishingIdeal_singleton] using + PrimeSpectrum.vanishingIdeal_anti_mono (Set.singleton_subset_iff.mpr hpV) + +end WeightedTorusJets.Geometry + +open scoped BigOperators + +end +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusImmersionGenericPointFormallySmooth.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusImmersionGenericPointFormallySmooth.lean new file mode 100644 index 0000000000000000000000000000000000000000..23225c7ea63b14031108e79c1da9dafde2bc042e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusImmersionGenericPointFormallySmooth.lean @@ -0,0 +1,36 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.LogarithmicForm + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open CategoryTheory _root_.AlgebraicGeometry + +namespace WeightedTorusJets.Geometry + +theorem torus_immersion_genericPoint_formallySmooth + {X : Scheme} [IsIntegral X] + (j : X ⟶ Spec (.of (AddMonoidAlgebra ℂ (Fin 4 →₀ ℤ)))) [IsImmersion j] : + ((j ≫ Spec.map (CommRingCat.ofHom + (algebraMap ℂ (AddMonoidAlgebra ℂ (Fin 4 →₀ ℤ))))).stalkMap + (genericPoint X)).hom.FormallySmooth := by + have : Algebra.FiniteType ℂ (AddMonoidAlgebra ℂ (Fin 4 →₀ ℤ)) := + WeightedTorusJets.laurent_finiteType + let b := Spec.map (CommRingCat.ofHom + (algebraMap ℂ (AddMonoidAlgebra ℂ (Fin 4 →₀ ℤ)))) + have : LocallyOfFiniteType b := + (HasRingHomProperty.Spec_iff (P := @LocallyOfFiniteType)).mpr + (RingHom.finiteType_algebraMap.mpr inferInstance) + exact (j ≫ b).genericPoint_mem_smoothLocus_of_perfectField + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusIntoProj.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusIntoProj.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c1e7759a4bdba86417adcfd6fe29f21a2f0b947 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusIntoProj.lean @@ -0,0 +1,73 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.ConeProjectivePoint + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +open CategoryTheory _root_.AlgebraicGeometry MvPolynomial +attribute [local instance] MvPolynomial.gradedAlgebra + +universe uTorusClosure + +noncomputable def torusIntoProj {K σ : Type uTorusClosure} [CommRing K] [Fintype σ] : + Spec (CommRingCat.of (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))) ⟶ + Proj (homogeneousSubmodule (Option σ) K) := + Spec.map (CommRingCat.ofHom + (algebraMap (MvPolynomial σ K) (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K))))) ≫ + affineIntoProj (k := K) (fun i : σ => (X i : MvPolynomial σ K)) + +@[simp] +theorem torusIntoProj_apply {K σ : Type uTorusClosure} [CommRing K] [Fintype σ] + (q : PrimeSpectrum (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))) : + torusIntoProj (K := K) (σ := σ) q = + affineIntoProj (k := K) (fun i : σ => (X i : MvPolynomial σ K)) + (PrimeSpectrum.comap + (algebraMap (MvPolynomial σ K) + (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))) q) := rfl + +theorem closure_torusIntoProj_zeroLocus_eq_affine + {K σ : Type uTorusClosure} [CommRing K] [Fintype σ] + (J : Ideal (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))) : + closure (torusIntoProj (K := K) (σ := σ) '' PrimeSpectrum.zeroLocus J) = + closure (affineIntoProj (k := K) (fun i : σ => (X i : MvPolynomial σ K)) '' + PrimeSpectrum.zeroLocus (J.comap + (algebraMap (MvPolynomial σ K) + (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))) : Set (MvPolynomial σ K))) := by + let f := algebraMap (MvPolynomial σ K) + (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K))) + let g : PrimeSpectrum (MvPolynomial σ K) → + ProjectiveSpectrum (homogeneousSubmodule (Option σ) K) := + fun x => affineIntoProj (k := K) (fun i : σ => (X i : MvPolynomial σ K)) x + have hc : Continuous g := + (affineIntoProj (k := K) (fun i : σ => (X i : MvPolynomial σ K))).continuous + change closure ((fun q => g (PrimeSpectrum.comap f q)) '' PrimeSpectrum.zeroLocus J) = + closure (g '' PrimeSpectrum.zeroLocus (J.comap f)) + rw [← Set.image_image, ← closure_image_closure hc, PrimeSpectrum.closure_image_comap_zeroLocus] + +theorem closure_torusIntoProj_zeroLocus + {K σ : Type uTorusClosure} [CommRing K] [Fintype σ] + (q : PrimeSpectrum (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))) : + closure (torusIntoProj (K := K) (σ := σ) '' PrimeSpectrum.zeroLocus q.asIdeal) = + ProjectiveSpectrum.zeroLocus (homogeneousSubmodule (Option σ) K) + (coneIdeal (q.asIdeal.comap + (algebraMap (MvPolynomial σ K) + (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))))) := by + let p := q.asIdeal.comap (algebraMap (MvPolynomial σ K) + (Localization.Away (∏ i : σ, (X i : MvPolynomial σ K)))) + let : p.IsPrime := Ideal.comap_isPrime _ q.asIdeal + exact (closure_torusIntoProj_zeroLocus_eq_affine q.asIdeal).trans + (closure_affineIntoProj_zeroLocus p) + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusJetZeroSchemeInclusion.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusJetZeroSchemeInclusion.lean new file mode 100644 index 0000000000000000000000000000000000000000..507d889277f6949c541a680851eac987fab8b247 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusJetZeroSchemeInclusion.lean @@ -0,0 +1,211 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.AffineZeroScheme + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +section +open CategoryTheory _root_.AlgebraicGeometry +namespace WeightedTorusJets.Geometry + +section TorusJetZeroSchemeNested +variable {K : Type*} [Field K] +local notation "Poly" => MvPolynomial (Fin 4) K +local notation "Torus" => Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : Poly)) + +noncomputable def torusJetZeroSchemeInclusion (c : Fin 3 → Fin 4 → K) (F : Poly) + (t : Fin 3 → ℕ) {b d : ℕ} (hbd : b ≤ d) : + torusJetZeroScheme c F t d ⟶ torusJetZeroScheme c F t b := + affineZeroSchemeInclusion _ _ + (rectangleJetIdeal_mono (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t hbd) + +theorem torusJetZeroSchemeInclusion_isClosedImmersion (c : Fin 3 → Fin 4 → K) (F : Poly) + (t : Fin 3 → ℕ) {b d : ℕ} (hbd : b ≤ d) : + IsClosedImmersion (torusJetZeroSchemeInclusion c F t hbd) := + affineZeroSchemeInclusion_isClosedImmersion _ _ _ + +theorem torusJetZeroScheme_component_genericPoint (c : Fin 3 → Fin 4 → K) (F : Poly) + (t : Fin 3 → ℕ) (b : ℕ) (q : PrimeSpectrum Torus) + (hq : (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b).IsMinimalPrime + q.asIdeal) : + ∃ V : Set (torusJetZeroScheme c F t b), + IsGenericPoint (affineZeroSchemePoint + (rectangleJetIdeal (fun a ↦ algebraMap Poly Torus (invariantJet c a F)) t b) q hq.le) V ∧ + Maximal IsIrreducible V := + affineZeroSchemePoint_isGenericPoint_component _ q hq + +end TorusJetZeroSchemeNested + + + + + + +theorem quotient_maximal_ideal_isNilpotent {R : Type*} [CommRing R] + [IsNoetherianRing R] [IsLocalRing R] (J : Ideal R) + (hJ : J.radical = IsLocalRing.maximalIdeal R) : + IsNilpotent ((IsLocalRing.maximalIdeal R).map (Ideal.Quotient.mk J)) := by + apply (Ideal.fg_of_isNoetherianRing _).isNilpotent_iff_le_nilradical.mpr + simpa only [← hJ, Ideal.map_quotient_self, nilradical, Ideal.zero_eq_bot] using + (Ideal.map_radical_le (I := J) (Ideal.Quotient.mk J)) + + + +attribute [local instance] spec_stalk_isLocalRing + +theorem spec_stalk_component_filtration_nilpotent {R : Type*} [CommRing R] + [IsNoetherianRing R] (I : Ideal R) (q : PrimeSpectrum R) + (hq : I.IsMinimalPrime q.asIdeal) : + IsNilpotent ((IsLocalRing.maximalIdeal + ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk q)).map + (Ideal.Quotient.mk (I.map (algebraMap R + ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk q))))) := by + have : IsNoetherianRing ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk q) := + IsLocalization.isNoetherianRing q.asIdeal.primeCompl _ inferInstance + exact quotient_maximal_ideal_isNilpotent _ (spec_stalk_component_radical I q hq) + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +noncomputable def localizationQuotientEquivStalkQuotient {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) : + (Localization.AtPrime p.asIdeal ⧸ I.map (algebraMap R (Localization.AtPrime p.asIdeal))) ≃ₐ[R] + (((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p) ⧸ + I.map (algebraMap R ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p))) := by + refine Ideal.quotientEquivAlg _ _ (AlgebraicGeometry.StructureSheaf.stalkIso R p) ?_ + rw [Ideal.map_map] + exact congrArg I.map (AlgebraicGeometry.StructureSheaf.stalkIso R p).toAlgHom.comp_algebraMap.symm + +noncomputable def affineZeroSchemeStalkEquivAmbientQuotient {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + (affineZeroScheme I).presheaf.stalk (affineZeroSchemePoint I p hp) ≃+* + (((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p) ⧸ + I.map (algebraMap R ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p))) := + (affineZeroSchemeStalkEquivAt I p hp).trans + (localizationQuotientEquivStalkQuotient I p).toRingEquiv + +theorem affineZeroSchemeStalk_length_ambientStalk {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + Module.length ((affineZeroScheme I).presheaf.stalk (affineZeroSchemePoint I p hp)) + ((affineZeroScheme I).presheaf.stalk (affineZeroSchemePoint I p hp)) = + Module.length ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p) + (((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p) ⧸ + I.map (algebraMap R ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p))) := + (ringEquiv_self_length (affineZeroSchemeStalkEquivAmbientQuotient I p hp)).trans + (Module.length_eq_of_surjective (M := + ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p) ⧸ + I.map (algebraMap R ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p))) + Ideal.Quotient.mk_surjective).symm + +theorem ambient_stalk_quotient_length_eq_localization {R : Type*} [CommRing R] + (I : Ideal R) (p : PrimeSpectrum R) (hp : I ≤ p.asIdeal) : + Module.length ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p) + (((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p) ⧸ + I.map (algebraMap R ((AlgebraicGeometry.Spec.structureSheaf R).presheaf.stalk p))) = + Module.length (Localization.AtPrime p.asIdeal) + (Localization.AtPrime p.asIdeal ⧸ I.map (algebraMap R (Localization.AtPrime p.asIdeal))) := + (affineZeroSchemeStalk_length_ambientStalk I p hp).symm.trans + (affineZeroSchemeStalk_length I p hp) + +end WeightedTorusJets.Geometry +end + +section +namespace WeightedTorusJets.Geometry + +variable {K : Type*} [Field K] + +noncomputable def torusToPolynomialFractionRing (n : ℕ) : + Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)) →ₐ[ + MvPolynomial (Fin n) K] FractionRing (MvPolynomial (Fin n) K) := + Localization.mapToFractionRing (FractionRing (MvPolynomial (Fin n) K)) + (Submonoid.powers (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (powers_le_nonZeroDivisors_of_noZeroDivisors + (Finset.prod_ne_zero_iff.mpr fun i _ => MvPolynomial.X_ne_zero i)) + +theorem torusToPolynomialFractionRing_algebraMap (n : ℕ) (F : MvPolynomial (Fin n) K) : + torusToPolynomialFractionRing n (algebraMap (MvPolynomial (Fin n) K) + (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) F) = + algebraMap (MvPolynomial (Fin n) K) (FractionRing (MvPolynomial (Fin n) K)) F := + (torusToPolynomialFractionRing n).commutes F + +@[instance_reducible] +noncomputable def torusPolynomialFractionAlgebra (n : ℕ) : + Algebra (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := + (torusToPolynomialFractionRing n).toRingHom.toAlgebra + +theorem torusPolynomialFractionAlgebra_data (n : ℕ) : + let : Algebra (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := torusPolynomialFractionAlgebra n + IsScalarTower (MvPolynomial (Fin n) K) + (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) ∧ + IsFractionRing (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := by + let : Algebra (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := torusPolynomialFractionAlgebra n + have h : IsScalarTower (MvPolynomial (Fin n) K) + (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := + IsScalarTower.of_algebraMap_eq fun x => (torusToPolynomialFractionRing n).commutes x |>.symm + exact ⟨h, IsFractionRing.isFractionRing_of_isDomain_of_isLocalization + (Submonoid.powers (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) _ _⟩ + +noncomputable def torusFractionRingEquiv (n : ℕ) : + let : Algebra (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := torusPolynomialFractionAlgebra n + FractionRing (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) ≃ₐ[ + Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))] + FractionRing (MvPolynomial (Fin n) K) := by + let : Algebra (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := torusPolynomialFractionAlgebra n + have := (torusPolynomialFractionAlgebra_data (K := K) n).2 + exact IsLocalization.algEquiv + (nonZeroDivisors (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))) + (FractionRing (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))) + (FractionRing (MvPolynomial (Fin n) K)) + +noncomputable def torusFractionRingEquivOverK (n : ℕ) : + FractionRing (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) ≃ₐ[K] + FractionRing (MvPolynomial (Fin n) K) := by + let : Algebra (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := torusPolynomialFractionAlgebra n + have := (torusPolynomialFractionAlgebra_data (K := K) n).1 + have : IsScalarTower K + (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := IsScalarTower.to₁₃₄ K (MvPolynomial (Fin n) K) + (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) + exact (torusFractionRingEquiv (K := K) n).restrictScalars K + +theorem torusFractionRingEquivOverK_algebraMap (n : ℕ) (f : MvPolynomial (Fin n) K) : + torusFractionRingEquivOverK n + (algebraMap (MvPolynomial (Fin n) K) + (FractionRing (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))) f) = + algebraMap (MvPolynomial (Fin n) K) (FractionRing (MvPolynomial (Fin n) K)) f := by + let : Algebra (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (MvPolynomial (Fin n) K)) := torusPolynomialFractionAlgebra n + change torusFractionRingEquiv n _ = _ + rw [IsScalarTower.algebraMap_apply (MvPolynomial (Fin n) K) + (Localization.Away (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K))) + (FractionRing (Localization.Away + (∏ i : Fin n, (MvPolynomial.X i : MvPolynomial (Fin n) K)))), + (torusFractionRingEquiv (K := K) n).commutes] + exact torusToPolynomialFractionRing_algebraMap n f + +end WeightedTorusJets.Geometry +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusQuotientDimensionPosCotangentFinrankThree.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusQuotientDimensionPosCotangentFinrankThree.lean new file mode 100644 index 0000000000000000000000000000000000000000..fe2e7576d47cd92ca40305949b9ca57d75d4344a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusQuotientDimensionPosCotangentFinrankThree.lean @@ -0,0 +1,306 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.IdealPowLayer +import OAI.NumberTheory.Jacobsthal.Siegel.PolynomialLaurent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +namespace WeightedTorusJets.Geometry + +theorem torus_quotient_dimension_pos_of_cotangent_finrank_le_three + {K : Type*} [Field K] + (q : Ideal (Localization.Away + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) [q.IsPrime] + (hdim : Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) ≤ 3) : + 0 < ringKrullDim (Localization.Away + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) ⧸ q) := by + obtain ⟨d, hd, _⟩ := WeightedTorusJets.finiteType_dimension_trdeg + (K := K) (A := Localization.Away + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)) ⧸ q) + have hrank : Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) = 4 - d := by + simpa [hd] using + torus_component_cotangent_eq_codimension (K := K) 4 q + have hpos : 0 < d := by omega + rw [hd] + exact_mod_cast hpos + +theorem laurent_quotient_dimension_pos_of_torus_cotangent_finrank_le_three + {K : Type*} [Field K] + (q : Ideal (Localization.Away + (∏ i : Fin 4, (MvPolynomial.X i : MvPolynomial (Fin 4) K)))) [q.IsPrime] + (hdim : Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) ≤ 3) : + 0 < ringKrullDim (AddMonoidAlgebra K (Fin 4 →₀ ℤ) ⧸ + q.comap (laurentEquivLocalization K (Fin 4)).toRingHom) := by + let e := laurentEquivLocalization K (Fin 4) + have he : q = (q.comap e.toRingHom).map e.toRingHom := + (Ideal.map_comap_of_surjective e.toRingHom e.surjective q).symm + rw [ringKrullDim_eq_of_ringEquiv + (Ideal.quotientEquivAlg _ q e he).toRingEquiv] + exact torus_quotient_dimension_pos_of_cotangent_finrank_le_three q hdim + + + +open MvPolynomial + +theorem torus_prime_fractionField_residue_equiv + {K : Type*} [Field K] + (q : PrimeSpectrum (Localization.Away + (∏ i : Fin 4, (X i : MvPolynomial (Fin 4) K)))) : + let L := AddMonoidAlgebra K (Fin 4 →₀ ℤ) + let T := Localization.Away (∏ i : Fin 4, (X i : MvPolynomial (Fin 4) K)) + let P := q.asIdeal.comap (laurentEquivLocalization K (Fin 4)).toRingHom + let S := Localization.AtPrime q.asIdeal + ∃ E : FractionRing (L ⧸ P) ≃ₐ[K] IsLocalRing.ResidueField S, + ∀ i : Fin 4, E (algebraMap (L ⧸ P) (FractionRing (L ⧸ P)) + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) = + algebraMap T (IsLocalRing.ResidueField S) + (algebraMap (MvPolynomial (Fin 4) K) T (X i)) := by + dsimp only + let L := AddMonoidAlgebra K (Fin 4 →₀ ℤ) + let T := Localization.Away (∏ i : Fin 4, (X i : MvPolynomial (Fin 4) K)) + let e := laurentEquivLocalization K (Fin 4) + let P := q.asIdeal.comap e.toRingHom + let S := Localization.AtPrime q.asIdeal + let F := IsLocalRing.ResidueField S + have : P.IsPrime := Ideal.comap_isPrime _ q.asIdeal + let : Algebra (T ⧸ q.asIdeal) F := localizationResidueQuotientAlgebra (A := S) q.asIdeal + obtain ⟨htower, hfrac⟩ := localization_residue_quotientAlgebra_data (A := S) q.asIdeal + have : IsScalarTower K (T ⧸ q.asIdeal) F := by + apply IsScalarTower.of_algebraMap_eq' (R := K) (S := T ⧸ q.asIdeal) (A := F) + ext c + change algebraMap K F c = algebraMap (T ⧸ q.asIdeal) F + (Ideal.Quotient.mk q.asIdeal (algebraMap K T c)) + rw [localization_residue_quotientAlgebra_mk] + exact IsScalarTower.algebraMap_apply K T F c + let E₀ : (L ⧸ P) ≃ₐ[K] (T ⧸ q.asIdeal) := Ideal.quotientEquivAlg P q.asIdeal e + (q.asIdeal.map_comap_of_surjective e.toRingHom e.surjective).symm + let E : FractionRing (L ⧸ P) ≃ₐ[K] F := IsFractionRing.algEquivOfAlgEquiv E₀ + refine ⟨E, fun i ↦ ?_⟩ + rw [IsFractionRing.algEquivOfAlgEquiv_algebraMap] + change algebraMap (T ⧸ q.asIdeal) F + (Ideal.Quotient.mk q.asIdeal (e (AddMonoidAlgebra.single (Finsupp.single i 1) 1))) = _ + rw [localization_residue_quotientAlgebra_mk, laurentEquivLocalization_coordinate] + +theorem torus_prime_residue_logarithmicForm_ne_zero + {K : Type*} [Field K] [CharZero K] [IsAlgClosed K] + (q : PrimeSpectrum (Localization.Away + (∏ i : Fin 4, (X i : MvPolynomial (Fin 4) K)))) + (hdim : Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal)) ≤ 3) + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) : + let S := Localization.AtPrime q.asIdeal + logarithmicForm (F := IsLocalRing.ResidueField S) c + (fun i : Fin 4 ↦ Ideal.Quotient.mk (IsLocalRing.maximalIdeal S) + (algebraMap (MvPolynomial (Fin 4) K) S (X i))) ≠ 0 := by + dsimp only + let L := AddMonoidAlgebra K (Fin 4 →₀ ℤ) + let T := Localization.Away (∏ i : Fin 4, (X i : MvPolynomial (Fin 4) K)) + let P := q.asIdeal.comap (laurentEquivLocalization K (Fin 4)).toRingHom + let S := Localization.AtPrime q.asIdeal + let F := IsLocalRing.ResidueField S + have : P.IsPrime := Ideal.comap_isPrime _ q.asIdeal + have hpos := laurent_quotient_dimension_pos_of_torus_cotangent_finrank_le_three + q.asIdeal hdim + have hn := logarithmicForm_ne_zero_on_torus_subvariety P hpos c hc + obtain ⟨E, hE⟩ := torus_prime_fractionField_residue_equiv q + let x : Fin 4 → FractionRing (L ⧸ P) := fun i ↦ algebraMap (L ⧸ P) _ + (Ideal.Quotient.mk P (AddMonoidAlgebra.single (Finsupp.single i 1) 1)) + have hcoords (i : Fin 4) : E (x i) = + Ideal.Quotient.mk (IsLocalRing.maximalIdeal S) + (algebraMap (MvPolynomial (Fin 4) K) S (X i)) := by + rw [hE] + rw [← IsScalarTower.algebraMap_apply (MvPolynomial (Fin 4) K) T F] + rfl + dsimp only [S] at hcoords + intro hzero + apply hn + have hm := WeightedTorusJets.logarithmic_relation_map_algHom E.symm.toAlgHom c _ + (by simpa only [logarithmicForm, div_eq_mul_inv] using hzero) + simpa only [AlgEquiv.coe_toAlgHom, ← hcoords, AlgEquiv.symm_apply_apply, + logarithmicForm, div_eq_mul_inv] using hm + +end WeightedTorusJets.Geometry + +namespace WeightedTorusJets.Geometry + +section SourceLocalLengthLower + +variable {K : Type*} [Field K] [CharZero K] [IsAlgClosed K] + +local notation "PolyRing" => MvPolynomial (Fin 4) K +local notation "torusCoordinateProduct" => (∏ i : Fin 4, (MvPolynomial.X i : PolyRing)) +local notation "TorusCoordRing" => Localization.Away torusCoordinateProduct + +theorem source_local_torus_rectangle_graded_length_gt {H N : ℕ} (hH : 1 ≤ H) (hHN : H ≤ N) + (c : Fin 4 → K) (hc : LinearIndependent ℚ c) + (v : Module.Basis (Fin 3) K (LinearMap.ker (dotProductEquiv K (Fin 4) c))) + (q : PrimeSpectrum TorusCoordRing) (b : ℕ) (F : PolyRing) + (hq : (rectangleJetIdeal + (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet (fun j => (v j : Fin 4 → K)) a F)) + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) b).IsMinimalPrime q.asIdeal) + (hnext : rectangleJetIdeal + (fun a ↦ algebraMap PolyRing TorusCoordRing (invariantJet (fun j => (v j : Fin 4 → K)) a F)) + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) (b + 1) ≤ q.asIdeal) + (hpos : 1 ≤ Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal))) + (hdim : Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal)) ≤ 4) : + ((4 * N) ^ (Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal))) : ℕ) < + Module.length (Localization.AtPrime q.asIdeal) (Localization.AtPrime q.asIdeal ⧸ + Ideal.map (algebraMap TorusCoordRing (Localization.AtPrime q.asIdeal)) + (rectangleJetIdeal (fun a ↦ algebraMap PolyRing TorusCoordRing + (invariantJet (fun j => (v j : Fin 4 → K)) a F)) + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) b)) := by + let p : Ideal PolyRing := q.asIdeal.comap (algebraMap PolyRing TorusCoordRing) + have : p.IsPrime := Ideal.comap_isPrime _ q.asIdeal + have : IsLocalization.AtPrime (Localization.AtPrime q.asIdeal) p := + IsLocalization.isLocalization_isLocalization_atPrime_isLocalization + (Submonoid.powers torusCoordinateProduct) (Localization.AtPrime q.asIdeal) q.asIdeal + have hX (i : Fin 4) : MvPolynomial.X i ∉ p := by + intro hi + exact q.isPrime.ne_top (Ideal.eq_top_of_isUnit_mem _ hi (torus_coordinate_isUnit i)) + have hx (i : Fin 4) : IsUnit + (algebraMap PolyRing (Localization.AtPrime q.asIdeal) (MvPolynomial.X i)) := + IsLocalization.map_units (Localization.AtPrime q.asIdeal) + (⟨MvPolynomial.X i, hX i⟩ : p.primeCompl) + have hc0 : c ≠ 0 := by + intro hzero + exact hc.ne_zero (0 : Fin 4) (congrFun hzero 0) + obtain ⟨I, hI, hD⟩ := exists_selected_independent_conormal_derivations + (S := Localization.AtPrime q.asIdeal) p.primeCompl + (IsLocalRing.maximalIdeal (Localization.AtPrime q.asIdeal)) hx c hc0 v + (fun hsmall => torus_prime_residue_logarithmicForm_ne_zero q hsmall c hc) + change I.card = min (Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q.asIdeal)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q.asIdeal))) 3 at hI + have hposI : I.Nonempty := Finset.card_pos.mp (by rw [hI]; omega) + have hprimary := (local_torus_stage_primary_data (fun j => (v j : Fin 4 → K)) q + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) b F hq).1 + have hlower := derivativeStageIdeal_graded_length_lower + (localTorusDerivationOverRat (fun j => (v j : Fin 4 → K)) q) + (localTorusDerivationOverRat_commute _ q 0 1) + (localTorusDerivationOverRat_commute _ q 0 2) + (localTorusDerivationOverRat_commute _ q 1 2) + (IsLocalRing.maximalIdeal (Localization.AtPrime q.asIdeal)) I hposI + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) + (fun j => (by decide : 2 ≤ 9).trans (rectangle_cutoff_ge_nine hH hHN j)) b + (algebraMap TorusCoordRing (Localization.AtPrime q.asIdeal) + (algebraMap PolyRing TorusCoordRing F)) + (local_torus_stage_le_maximal (fun j => (v j : Fin 4 → K)) q _ (b + 1) F hnext) + (by simpa only [localTorusDerivationOverRat_cotangent_eq_direct (fun j => (v j : Fin 4 → K)) q p.primeCompl] using hD) hprimary + have hnum := rectangle_floor_product_gt_nat hH hHN hpos hdim I hI + rw [local_torus_derivativeStageIdeal_eq] + rw [Finset.prod_coe_sort I (fun j : Fin 3 => ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊ + 1)] at hlower + exact lt_of_lt_of_le (by exact_mod_cast hnum) hlower + +end SourceLocalLengthLower + + + +theorem uniform_rectangular_multiplicity + {H N : ℕ} (hH : 1 ≤ H) (hHN : H ≤ N) + (c : Fin 4 → ℂ) (hc : LinearIndependent ℚ c) + (v : Module.Basis (Fin 3) ℂ + (LinearMap.ker (dotProductEquiv ℂ (Fin 4) c))) + (F : MvPolynomial (Fin 4) ℂ) (hF : F ∈ polynomialBox ℂ N) + (hvanish : ∀ a : Fin 3 → ℕ, + (∀ j, (a j : ℝ) ≤ rectangleThreshold (H : ℝ) (N : ℝ) j) → + MvPolynomial.eval (fun _ ↦ 1) + (invariantJet (fun j ↦ (v j : Fin 4 → ℂ)) a F) = 0) : + F = 0 := by + by_contra hF0 + obtain ⟨b, _, q, _, hq, hqnext, hpos, hdim⟩ := + torus_rectangle_shared_component_data hH hHN (fun j ↦ (v j : Fin 4 → ℂ)) F hF0 hvanish + have hlength := source_local_torus_rectangle_graded_length_gt hH hHN c hc v q b F + hq hqnext.le hpos hdim + have hN : 0 < N := lt_of_lt_of_le Nat.zero_lt_one (hH.trans hHN) + have hupper := rectangleJetIdeal_length_le q.asIdeal + (fun j ↦ (v j : Fin 4 → ℂ)) + (fun j ↦ ⌊rectangleThreshold (H : ℝ) (N : ℝ) j / 4⌋₊) b hN hF hq + exact (not_lt_of_ge hupper) hlength + + + +theorem idealPowLayer_eq {A : Type*} [CommRing A] (I : Ideal A) (n : ℕ) + (x y : ↥(I ^ n)) : + (Submodule.Quotient.mk x : idealPowLayer I n) = Submodule.Quotient.mk y ↔ + (x - y : A) ∈ I ^ (n + 1) := by + rw [Submodule.Quotient.eq, ← idealPowLayer_kernel I n] + constructor + · intro h + exact Submodule.mem_map.mpr ⟨x - y, by simpa only [Submodule.ker_mkQ] using h, rfl⟩ + · intro h + obtain ⟨z, hz, heq⟩ := Submodule.mem_map.mp h + have hzy : z = x - y := Subtype.ext heq + simpa only [Submodule.ker_mkQ, hzy] using hz + + + +theorem quotient_taylor_degree_one + {R σ : Type*} [CommRing R] [Algebra ℚ R] [Fintype σ] + (J m : Ideal R) (hJm : J ≤ m) + (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) + (D : σ → Derivation ℚ R R) + (φ : (R ⧸ J) →+* (MvPolynomial σ (R ⧸ m) ⧸ + Ideal.span (Set.range fun i => (MvPolynomial.X i : MvPolynomial σ (R ⧸ m)) ^ k i))) + (hres : ((rectangularAugmentation k hk).toRingHom.comp φ).comp + (Ideal.Quotient.mk J) = Ideal.Quotient.mk m) + (x : m) + (hfirst : φ (Ideal.Quotient.mk J x) - + ∑ i, Ideal.Quotient.mk m (D i x) • + Ideal.Quotient.mk (Ideal.span (Set.range fun j => (MvPolynomial.X j : MvPolynomial σ (R ⧸ m)) ^ k j)) + (MvPolynomial.X i) ∈ + (RingHom.ker (rectangularAugmentation (K := R ⧸ m) k hk)) ^ 2) : + let N := RingHom.ker (rectangularAugmentation (K := R ⧸ m) k hk) + let vars (i : σ) : ↥(N ^ 1) := ⟨ + Ideal.Quotient.mk (Ideal.span (Set.range fun j => (MvPolynomial.X j : MvPolynomial σ (R ⧸ m)) ^ k j)) + (MvPolynomial.X i), by + simp only [pow_one] + exact (quotientAugmentation_mk _ _ (MvPolynomial.X i)).trans + (MvPolynomial.constantCoeff_X _ i)⟩ + mapIdealPowLayerQuotientAugmentation J m hJm φ (rectangularAugmentation k hk) hres 1 + (Submodule.Quotient.mk (⟨Ideal.Quotient.mk J x, by + simpa only [pow_one] using Ideal.mem_map_of_mem (Ideal.Quotient.mk J) x.property⟩ : + ↥((m.map (Ideal.Quotient.mk J)) ^ 1))) = + ∑ i, Ideal.Quotient.mk m (D i x) • + (Submodule.Quotient.mk (vars i) : idealPowLayer N 1) := by + classical + intro N vars + rw [mapIdealPowLayerQuotientAugmentation_mk] + have hsum : (Submodule.Quotient.mk + (∑ i, Ideal.Quotient.mk m (D i x) • vars i) : idealPowLayer N 1) = + ∑ i, Ideal.Quotient.mk m (D i x) • + (Submodule.Quotient.mk (vars i) : idealPowLayer N 1) := by + change (Submodule.mkQ _) + (∑ i, Ideal.Quotient.mk m (D i x) • vars i) = _ + simp only [map_sum, LinearMap.map_smul_of_tower, Submodule.mkQ_apply] + rw [← hsum] + apply (idealPowLayer_eq N 1 _ _).mpr + simpa only [Submodule.coe_sub, Submodule.coe_sum, Submodule.coe_smul_of_tower] using hfirst + + + +theorem rectangular_variable_ideal_isMaximal {σ K : Type*} [Field K] + (k : σ → ℕ) (hk : ∀ i, k i ≠ 0) : + ((MvPolynomial.idealOfVars σ K).map + (Ideal.Quotient.mk (Ideal.span (Set.range fun i => + (MvPolynomial.X i : MvPolynomial σ K) ^ k i)))).IsMaximal := by + rw [← ker_quotientAugmentation _ (rectangularIdeal_le_ker_constantCoeff k hk)] + apply RingHom.ker_isMaximal_of_surjective + intro c + exact ⟨algebraMap K _ c, (quotientAugmentation _ _).commutes c⟩ + +end WeightedTorusJets.Geometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusRectangleJetIdealParametersProjectiveDegreeBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusRectangleJetIdealParametersProjectiveDegreeBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d03890bc589390d8cabcf83ea2227104d11f8a6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/TorusRectangleJetIdealParametersProjectiveDegreeBound.lean @@ -0,0 +1,78 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.LocalLengthMulProjectiveClosureDegree + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +section +namespace WeightedTorusJets.Geometry + +section TorusWeightedParameters + +variable {K : Type*} [Field K] [Infinite K] +local notation "P₄" => MvPolynomial (Fin 4) K +local notation "T₄" => Localization.Away (∏ i : Fin 4, (MvPolynomial.X i : P₄)) + +theorem torus_rectangleJetIdeal_exists_parameters_with_projective_degree_bound + (q : Ideal T₄) [q.IsPrime] (c : Fin 3 → Fin 4 → K) (t : Fin 3 → ℕ) (b : ℕ) + {N : ℕ} (hN : 0 < N) {F : P₄} (hF : F ∈ polynomialBox K N) + (hq : q ∈ (rectangleJetIdeal + (fun a => algebraMap P₄ T₄ (invariantJet c a F)) t b).minimalPrimes) : + ∃ g : Fin (Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q))) → P₄, + (∀ i, g i ∈ Submodule.span K + ((fun a => invariantJet c a F) '' {a | ∀ j, a j ≤ b * t j})) ∧ + (∀ i, (g i).totalDegree ≤ 4 * N) ∧ + (Ideal.span (Set.range (fun i => algebraMap P₄ (Localization.AtPrime q) (g i)))).radical = + IsLocalRing.maximalIdeal (Localization.AtPrime q) ∧ + Module.length (Localization.AtPrime q) (Localization.AtPrime q ⧸ + (rectangleJetIdeal (fun a => algebraMap P₄ T₄ (invariantJet c a F)) t b).map + (algebraMap T₄ (Localization.AtPrime q))) ≤ + Module.length (Localization.AtPrime q) (Localization.AtPrime q ⧸ Ideal.span + (Set.range (fun i => algebraMap P₄ (Localization.AtPrime q) (g i)))) ∧ + Module.length (Localization.AtPrime q) (Localization.AtPrime q ⧸ Ideal.span + (Set.range (fun i => algebraMap P₄ (Localization.AtPrime q) (g i)))) * + (GradedQuotient.projectiveDegree + (coneIdeal (q.comap (algebraMap P₄ T₄))) + (coneIdeal_isHomogeneous (q.comap (algebraMap P₄ T₄))) : ℕ∞) ≤ + ((4 * N) ^ Module.finrank (IsLocalRing.ResidueField (Localization.AtPrime q)) + (IsLocalRing.CotangentSpace (Localization.AtPrime q)) : ℕ) := by + obtain ⟨g, hspan, hdeg, hrad, hlength, _⟩ := + rectangleJetIdeal_exists_parameters_with_length + (A := Localization.AtPrime q) q c t b hN hF hq + let p := q.comap (algebraMap P₄ T₄) + let : p.IsPrime := Ideal.comap_isPrime _ q + let : IsLocalization.AtPrime (Localization.AtPrime q) p := + IsLocalization.isLocalization_isLocalization_atPrime_isLocalization + (Submonoid.powers (∏ i : Fin 4, (MvPolynomial.X i : P₄))) (Localization.AtPrime q) q + refine ⟨g, hspan, hdeg, hrad, hlength, ?_⟩ + let e := IsLocalization.algEquiv p.primeCompl + (Localization.AtPrime q) (Localization.AtPrime p) + have hcomm i : e (algebraMap P₄ (Localization.AtPrime q) (g i)) = + algebraMap P₄ (Localization.AtPrime p) (g i) := e.commutes (g i) + have hrad' := radical_span_eq_maximalIdeal_of_commuting_images e.toRingEquiv + (fun i => algebraMap P₄ (Localization.AtPrime q) (g i)) + (fun i => algebraMap P₄ (Localization.AtPrime p) (g i)) hcomm hrad + rw [quotient_length_eq_of_commuting_images e.toRingEquiv + (fun i => algebraMap P₄ (Localization.AtPrime q) (g i)) + (fun i => algebraMap P₄ (Localization.AtPrime p) (g i)) hcomm] + exact local_length_mul_projectiveClosure_degree_le p + (polynomial_prime_height_eq_cotangent_finrank (A := Localization.AtPrime q) p) + g hdeg hrad' + +end TorusWeightedParameters + +end WeightedTorusJets.Geometry + +end + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Siegel/WeightedJetIndices.lean b/lean/OAI/NumberTheory/Jacobsthal/Siegel/WeightedJetIndices.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5d3afcb5dbcbdb7f90f3e724648e30a3f7377b9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Siegel/WeightedJetIndices.lean @@ -0,0 +1,497 @@ +import Mathlib +import PrimeNumberTheoremAnd.Erdos970.HadamardSupport +import OAI.NumberTheory.Jacobsthal.Siegel.GreedyPivots + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section +open scoped BigOperators +open scoped Pointwise +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped NumberField +open scoped BigOperators +open scoped BigOperators +namespace WeightedTorusJets + +def weightedJetIndices (H B : ℕ) : Finset (Fin 3 → ℕ) := + (Fintype.piFinset (fun _ : Fin 3 => Finset.range (B + 1))).filter + (fun α => α 0 + H * α 1 + H * α 2 ≤ B) + +theorem mem_weightedJetIndices_iff {H B : ℕ} (hH : 0 < H) (α : Fin 3 → ℕ) : + α ∈ weightedJetIndices H B ↔ α 0 + H * α 1 + H * α 2 ≤ B := by + constructor + · exact fun h => (Finset.mem_filter.mp h).2 + · intro h + apply Finset.mem_filter.mpr + refine ⟨Fintype.mem_piFinset.mpr ?_, h⟩ + intro i + apply Finset.mem_range.mpr + have h1 : α 1 ≤ H * α 1 := Nat.le_mul_of_pos_left _ hH + have h2 : α 2 ≤ H * α 2 := Nat.le_mul_of_pos_left _ hH + fin_cases i + · change α 0 < B + 1 + omega + · change α 1 < B + 1 + omega + · change α 2 < B + 1 + omega + + + +theorem extendFiniteFamily_injOn_range {α : Type*} {n : ℕ} (f : Fin n → α) + (hf : Function.Injective f) (fallback : α) : + Set.InjOn (extendFiniteFamily f fallback) (Finset.range n : Set ℕ) := by + intro i hi j hj hij + have hi' := Finset.mem_range.mp hi + have hj' := Finset.mem_range.mp hj + have heq : f ⟨i, hi'⟩ = f ⟨j, hj'⟩ := by + simpa [extendFiniteFamily, hi', hj'] using hij + exact congrArg Fin.val (hf heq) + +noncomputable def finiteGreedyPivots (K : Type*) [DivisionRing K] + {α V : Type*} [AddCommGroup V] [Module K V] (s : Finset α) (R : α → V) + (e : Fin s.card ≃ s) (fallback : α) : Finset α := by + classical + let a := extendFiniteFamily (fun i => (e i : α)) fallback + exact (greedyPivots K (R ∘ a) s.card).image a + +theorem finiteGreedyPivots_spec {K α V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (s : Finset α) (R : α → V) + (e : Fin s.card ≃ s) (fallback : α) + (hspan : Submodule.span K (R '' (s : Set α)) = ⊤) : + finiteGreedyPivots K s R e fallback ⊆ s ∧ + (finiteGreedyPivots K s R e fallback).card = Module.finrank K V ∧ + LinearIndepOn K R (finiteGreedyPivots K s R e fallback : Set α) ∧ + Submodule.span K (R '' (finiteGreedyPivots K s R e fallback : Set α)) = ⊤ := by + classical + let a := extendFiniteFamily (fun i => (e i : α)) fallback + let v := R ∘ a + let I := greedyPivots K v s.card + have hI : I ⊆ Finset.range s.card := greedyPivots_subset_range v s.card + have hainj : Set.InjOn a (Finset.range s.card : Set ℕ) := + extendFiniteFamily_injOn_range _ (Subtype.val_injective.comp e.injective) fallback + have haimage : a '' (Finset.range s.card : Set ℕ) = (s : Set α) := by + rw [show a = extendFiniteFamily (fun i => (e i : α)) fallback from rfl, + image_extendFiniteFamily_range] + ext x + constructor + · rintro ⟨i, rfl⟩ + exact (e i).property + · intro hx + exact ⟨e.symm ⟨x, hx⟩, by simp⟩ + have hvimage : v '' (Finset.range s.card : Set ℕ) = R '' (s : Set α) := by + rw [show v = R ∘ a from rfl, Set.image_comp, haimage] + have hvspan : Submodule.span K (v '' (Finset.range s.card : Set ℕ)) = ⊤ := by + rw [hvimage, hspan] + change I.image a ⊆ s ∧ (I.image a).card = _ ∧ + LinearIndepOn K R (I.image a : Set α) ∧ _ + refine ⟨?_, ?_, ?_, ?_⟩ + · intro x hx + rcases Finset.mem_image.mp hx with ⟨i, hi, rfl⟩ + change a i ∈ (s : Set α) + rw [← haimage] + exact Set.mem_image_of_mem a (hI hi) + · rw [Finset.card_image_of_injOn (hainj.mono hI)] + exact card_greedyPivots_of_span_eq_top v s.card hvspan + · rw [Finset.coe_image] + exact LinearIndepOn.image_of_comp a R (greedyPivots_linearIndepOn v s.card) + · change Submodule.span K (R '' (I.image a : Set α)) = ⊤ + rw [Finset.coe_image, ← Set.image_comp] + exact (span_greedyPivots v s.card).trans hvspan + +theorem finiteGreedyPivots_weighted_bounds {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (s : Finset (Fin 3 → ℕ)) (R : (Fin 3 → ℕ) → V) + (e : Fin s.card ≃ s) (H N : ℕ) (hH : 0 < H) (hHN : H ≤ N) + (hN : 18818 ≤ N) (hdim : Module.finrank K V = N ^ 4) + (hspan : Submodule.span K (R '' (s : Set (Fin 3 → ℕ))) = ⊤) + (hw : ∀ a ∈ s, (a 0 : ℝ) + (H : ℝ) * a 1 + (H : ℝ) * a 2 ≤ + 96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)) : + let P := finiteGreedyPivots K s R e 0 + P.card = N ^ 4 ∧ LinearIndepOn K R (P : Set (Fin 3 → ℕ)) ∧ + (N : ℝ) ^ 4 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) / + (4 * 97 ^ 2) ≤ ∑ a ∈ P, (a 0 : ℝ) ∧ + (∑ a ∈ P, ((a 1 : ℝ) + a 2)) ≤ + 192 * (N : ℝ) ^ 4 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) := by + dsimp only + obtain ⟨hsub, hcard, hlin, _⟩ := finiteGreedyPivots_spec s R e 0 hspan + have hcard' := hcard.trans hdim + exact ⟨hcard', hlin, weighted_pivot_bounds _ H N hH hHN hN hcard' + (fun a ha => hw a (hsub ha))⟩ + +theorem row_space_finrank {K : Type*} [DivisionRing K] (N : ℕ) : + Module.finrank K ((Fin 4 → Fin N) → K) = N ^ 4 := by + simp + +theorem finiteGreedyPivots_sum {K α V β : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] [AddCommMonoid β] + (s : Finset α) (R : α → V) (e : Fin s.card ≃ s) (fallback : α) (f : α → β) : + let a := extendFiniteFamily (fun i => (e i : α)) fallback + ∑ x ∈ finiteGreedyPivots K s R e fallback, f x = + ∑ i ∈ greedyPivots K (R ∘ a) s.card, f (a i) := by + classical + dsimp only [finiteGreedyPivots] + apply Finset.sum_image + have hinj := extendFiniteFamily_injOn_range (fun i => (e i : α)) + (Subtype.val_injective.comp e.injective) fallback + exact hinj.mono (greedyPivots_subset_range _ _) + +theorem sum_embedding_eq_sum_of_range {β : Type*} [AddCommMonoid β] + (I : Finset ℕ) (m : ℕ) (e : Fin m ↪ ℕ) (he : Set.range e = (I : Set ℕ)) + (f : ℕ → β) : (∑ i : Fin m, f (e i)) = ∑ i ∈ I, f i := by + apply Finset.sum_bij (fun i _ => e i) + · intro i _ + change e i ∈ (I : Set ℕ) + rw [← he] + exact Set.mem_range_self i + · intro i _ j _ hij + exact e.injective hij + · intro j hj + have hj' : j ∈ Set.range e := he ▸ hj + obtain ⟨i, rfl⟩ := hj' + exact ⟨i, Finset.mem_univ i, rfl⟩ + · intro i _ + rfl + +theorem weightedJetIndices_real_weight {H : ℕ} (hH : 0 < H) {W : ℝ} + (hW : 0 ≤ W) {a : Fin 3 → ℕ} (ha : a ∈ weightedJetIndices H ⌊W⌋₊) : + (a 0 : ℝ) + (H : ℝ) * a 1 + (H : ℝ) * a 2 ≤ W := by + have hnat := (mem_weightedJetIndices_iff hH a).mp ha + have hreal : (a 0 : ℝ) + (H : ℝ) * a 1 + (H : ℝ) * a 2 ≤ (⌊W⌋₊ : ℝ) := by + exact_mod_cast hnat + exact hreal.trans (Nat.floor_le hW) + + + +theorem mem_weightedJetIndices_of_rectangle {H : ℕ} {U : ℝ} (hH : 0 < H) + (a : Fin 3 → ℕ) + (ha₀ : (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * U) + (ha₁ : (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * U) + (ha₂ : (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * U) : + a ∈ weightedJetIndices H ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * U⌋₊ := by + apply (mem_weightedJetIndices_iff hH a).mpr + apply Nat.le_floor + push_cast + exact pivot_weight_of_rectangle (by exact_mod_cast hH) (a 0) (a 1) (a 2) ha₀ ha₁ ha₂ + +theorem span_cutoff_eq_top_of_rectangle {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] {H : ℕ} {U : ℝ} (hH : 0 < H) + (R : (Fin 3 → ℕ) → V) + (hspan : Submodule.span K (R '' {a : Fin 3 → ℕ | + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * U ∧ + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * U ∧ + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * U}) = ⊤) : + Submodule.span K (R '' (weightedJetIndices H + ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * U⌋₊ : Set (Fin 3 → ℕ))) = ⊤ := by + apply top_unique + rw [← hspan] + apply Submodule.span_mono + apply Set.image_mono + intro a ha + exact mem_weightedJetIndices_of_rectangle hH a ha.1 ha.2.1 ha.2.2 + + + +theorem rectangle_span_yields_sorted_greedy_pivots {K V : Type*} [DivisionRing K] + [AddCommGroup V] [Module K V] (R : (Fin 3 → ℕ) → V) + (H N : ℕ) (hH : 0 < H) (hHN : H ≤ N) (hN : 18818 ≤ N) + (hdim : Module.finrank K V = N ^ 4) + (hspan : Submodule.span K (R '' {a : Fin 3 → ℕ | + (a 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (a 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)}) = ⊤) : + let s := weightedJetIndices H + ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)⌋₊ + ∃ e : Fin s.card ≃ s, + Monotone (fun i => (e i).1 0 + H * (e i).1 1 + H * (e i).1 2) ∧ + let P := finiteGreedyPivots K s R e 0 + P.card = N ^ 4 ∧ LinearIndepOn K R (P : Set (Fin 3 → ℕ)) ∧ + (N : ℝ) ^ 4 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) / + (4 * 97 ^ 2) ≤ ∑ a ∈ P, (a 0 : ℝ) ∧ + (∑ a ∈ P, ((a 1 : ℝ) + a 2)) ≤ + 192 * (N : ℝ) ^ 4 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) := by + dsimp only + obtain ⟨e, he⟩ := exists_weight_sorted_enumeration + (weightedJetIndices H ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)⌋₊) + (fun a => a 0 + H * a 1 + H * a 2) + refine ⟨e, he, ?_⟩ + apply finiteGreedyPivots_weighted_bounds _ R e H N hH hHN hN hdim + (span_cutoff_eq_top_of_rectangle hH R hspan) + intro a ha + exact weightedJetIndices_real_weight hH (by positivity) ha + +end WeightedTorusJets + +open Module +open scoped BigOperators + +namespace WeightedTorusJets + +theorem det_ne_zero_of_linearIndepOn_rows + {K ι n : Type*} [Field K] [Fintype n] [DecidableEq n] + (s : Finset ι) (R : ι → n → K) (e : n ≃ s) + (hlin : LinearIndepOn K R (s : Set ι)) : + Matrix.det (fun i j => R (e i) j) ≠ 0 := by + classical + have hrows : LinearIndependent K (fun i j => R (e i) j) := + hlin.comp e e.injective + exact ((Matrix.isUnit_iff_isUnit_det _).mp + (Matrix.linearIndependent_rows_iff_isUnit.mp hrows)).ne_zero + +theorem span_rows_eq_top_of_detects + {K ι n : Type*} [Field K] [Fintype n] + (s : Finset ι) (R : ι → n → K) + (hdetect : ∀ c : n → K, c ≠ 0 → ∃ a ∈ s, ∑ j, R a j * c j ≠ 0) : + Submodule.span K (R '' (s : Set ι)) = ⊤ := by + classical + apply (Submodule.map_eq_top_iff (e := dotProductEquiv K n)).mp + rw [Submodule.map_span] + apply Submodule.span_eq_top_of_ne_zero + intro c hc + obtain ⟨a, ha, hsum⟩ := hdetect c hc + exact ⟨dotProductEquiv K n (R a), + Set.mem_image_of_mem _ (Set.mem_image_of_mem R ha), hsum⟩ + +theorem detects_of_field_embedding + {K L ι n : Type*} [Field K] [Field L] [Fintype n] + (s : Finset ι) (R : ι → n → K) (f : K →+* L) + (hdetect : ∀ c : n → L, c ≠ 0 → ∃ a ∈ s, ∑ j, f (R a j) * c j ≠ 0) : + ∀ c : n → K, c ≠ 0 → ∃ a ∈ s, ∑ j, R a j * c j ≠ 0 := by + intro c hc + have hfc : (fun j => f (c j)) ≠ 0 := by + intro heq + apply hc + funext j + apply f.injective + simpa only [Pi.zero_apply, map_zero] using congr_fun heq j + obtain ⟨a, ha, hsum⟩ := hdetect (fun j => f (c j)) hfc + refine ⟨a, ha, fun heq => hsum ?_⟩ + simpa only [map_sum, map_mul, map_zero] using congr_arg f heq + + +theorem finite_weighted_greedy_package {K α : Type*} [Field K] {M : ℕ} + (s : Finset α) (R : α → Fin M → K) (e : Fin s.card ≃ s) (fallback : α) + (w : α → ℕ) (B : ℕ) (hs : ∀ a, a ∈ s ↔ w a ≤ B) + (hsort : Monotone (fun i => w (e i))) + (hspan : Submodule.span K (R '' (s : Set α)) = ⊤) : + let a := extendFiniteFamily (fun i => (e i : α)) fallback + let v := R ∘ a + let wt := extendFiniteFamily (fun i => w (e i)) B + let P := finiteGreedyPivots K s R e fallback + ∃ (g : Fin M ↪o ℕ) (p : Fin M ↪ α), + Set.range g = (greedyPivots K v s.card : Set ℕ) ∧ + (∀ i, p i = a (g i)) ∧ Set.range p = (P : Set α) ∧ + Monotone wt ∧ Monotone (fun i => w (p i)) ∧ + (∀ i, g i < s.card) ∧ + (∀ r < s.card, wt r = w (a r)) ∧ + (∀ i, v (g i) = R (p i) ∧ wt (g i) = w (p i) ∧ w (p i) ≤ B) ∧ + (∀ b, w b ≤ B → ∃ r < s.card, a r = b ∧ wt r = w b ∧ v r = R b) ∧ + Matrix.det (fun i j => R (p i) j) ≠ 0 ∧ P.card = M ∧ + (∀ (β : Type) [AddCommMonoid β] (F : α → β), + (∑ i, F (p i)) = ∑ b ∈ P, F b) := by + classical + dsimp only + let a := extendFiniteFamily (fun i => (e i : α)) fallback + let v := R ∘ a + let G := greedyPivots K v s.card + have haimage : a '' (Finset.range s.card : Set ℕ) = (s : Set α) := by + rw [show a = extendFiniteFamily (fun i => (e i : α)) fallback from rfl, + image_extendFiniteFamily_range] + ext x + constructor + · rintro ⟨i, rfl⟩ + exact (e i).property + · intro hx + exact ⟨e.symm ⟨x, hx⟩, by simp⟩ + have hvspan : Submodule.span K (v '' (Finset.range s.card : Set ℕ)) = ⊤ := by + rw [show v = R ∘ a from rfl, Set.image_comp, haimage, hspan] + have hcard : G.card = M := by + simpa [G] using card_greedyPivots_of_span_eq_top v s.card hvspan + let g := G.orderEmbOfFin hcard + have hg : Set.range g = (G : Set ℕ) := G.range_orderEmbOfFin hcard + have hgT : ∀ i, g i < s.card := fun i => + Finset.mem_range.mp (greedyPivots_subset_range v s.card + (G.orderEmbOfFin_mem hcard i)) + have hainj : Set.InjOn a (Finset.range s.card : Set ℕ) := + extendFiniteFamily_injOn_range _ (Subtype.val_injective.comp e.injective) fallback + let p : Fin M ↪ α := ⟨a ∘ g, fun i j hij => g.injective + (hainj (Finset.mem_range.mpr (hgT i)) (Finset.mem_range.mpr (hgT j)) hij)⟩ + have hpe : ∀ i, p i = (e ⟨g i, hgT i⟩ : α) := by + intro i + change a (g i) = _ + simp only [a, extendFiniteFamily, dite_eq_left (hgT i)] + have hpbound : ∀ i, w (p i) ≤ B := by + intro i + rw [hpe i] + exact (hs _).mp (e ⟨g i, hgT i⟩).property + have hpmono : Monotone (fun i => w (p i)) := by + intro i j hij + change w (p i) ≤ w (p j) + rw [hpe i, hpe j] + exact hsort (show (⟨g i, hgT i⟩ : Fin s.card) ≤ ⟨g j, hgT j⟩ from g.monotone hij) + refine ⟨g, p, hg, fun _ => rfl, ?_, ?_, hpmono, hgT, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · change Set.range (a ∘ g) = ((greedyPivots K v s.card).image a : Set α) + rw [Set.range_comp, hg, Finset.coe_image] + · exact monotone_extendFiniteFamily _ _ hsort (fun i => (hs _).mp (e i).property) + · intro r hr + simp [extendFiniteFamily, hr] + · intro i + refine ⟨rfl, ?_, hpbound i⟩ + rw [hpe i] + simp only [extendFiniteFamily, dite_eq_left (hgT i)] + · intro b hb + let r : Fin s.card := e.symm ⟨b, (hs b).mpr hb⟩ + refine ⟨r, r.isLt, ?_, ?_, ?_⟩ + · simp [extendFiniteFamily, r.isLt, r] + · simp [extendFiniteFamily, r.isLt, r] + · simp [extendFiniteFamily, r.isLt, r] + · exact det_ne_zero_of_linearIndepOn_rows G v (G.orderIsoOfFin hcard).toEquiv + (greedyPivots_linearIndepOn v s.card) + · simpa using (finiteGreedyPivots_spec s R e fallback hspan).2.1 + · intro β _ F + rw [finiteGreedyPivots_sum] + exact sum_embedding_eq_sum_of_range G M g.toEmbedding hg (F ∘ a) + + + +theorem rectangle_greedy_selection_package {K : Type*} [Field K] (H N : ℕ) + (R : (Fin 3 → ℕ) → Fin (N ^ 4) → K) + (hH : 0 < H) (hHN : H ≤ N) (hN : 18818 ≤ N) + (hspan : Submodule.span K (R '' {b : Fin 3 → ℕ | + (b 0 : ℝ) ≤ 32 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (b 1 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) ∧ + (b 2 : ℝ) ≤ 32 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ)}) = ⊤) : + let w := fun b : Fin 3 → ℕ => b 0 + H * b 1 + H * b 2 + let B := ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)⌋₊ + let s := weightedJetIndices H B + ∃ e : Fin s.card ≃ s, + Monotone (fun i => w (e i)) ∧ + let a := extendFiniteFamily (fun i => (e i : Fin 3 → ℕ)) 0 + let v := R ∘ a + let wt := extendFiniteFamily (fun i => w (e i)) B + let P := finiteGreedyPivots K s R e 0 + ∃ (g : Fin (N ^ 4) ↪o ℕ) (p : Fin (N ^ 4) ↪ (Fin 3 → ℕ)), + Set.range g = (greedyPivots K v s.card : Set ℕ) ∧ + (∀ i, p i = a (g i)) ∧ Set.range p = (P : Set (Fin 3 → ℕ)) ∧ + Monotone wt ∧ Monotone (fun i => w (p i)) ∧ + (∀ i, g i < s.card) ∧ (∀ r < s.card, wt r = w (a r)) ∧ + (∀ i, v (g i) = R (p i) ∧ wt (g i) = w (p i) ∧ w (p i) ≤ B) ∧ + (∀ b, w b ≤ B → ∃ r < s.card, a r = b ∧ wt r = w b ∧ v r = R b) ∧ + Matrix.det (fun i j => R (p i) j) ≠ 0 ∧ P.card = N ^ 4 ∧ + (∀ (β : Type) [AddCommMonoid β] (F : (Fin 3 → ℕ) → β), + (∑ i, F (p i)) = ∑ b ∈ P, F b) ∧ + (N : ℝ) ^ 4 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ) / + (4 * 97 ^ 2) ≤ ∑ i, ((p i) 0 : ℝ) ∧ + (∑ i, (((p i) 1 : ℝ) + (p i) 2)) ≤ + 192 * (N : ℝ) ^ 4 * (H : ℝ) ^ (-(1 / 3 : ℝ)) * (N : ℝ) ^ (4 / 3 : ℝ) := by + classical + dsimp only + let w := fun b : Fin 3 → ℕ => b 0 + H * b 1 + H * b 2 + let B := ⌊96 * (H : ℝ) ^ (2 / 3 : ℝ) * (N : ℝ) ^ (4 / 3 : ℝ)⌋₊ + let s := weightedJetIndices H B + obtain ⟨e, he⟩ := exists_weight_sorted_enumeration s w + have hcut : Submodule.span K (R '' (s : Set (Fin 3 → ℕ))) = ⊤ := + span_cutoff_eq_top_of_rectangle hH R hspan + obtain ⟨g, p, hg, hpa, hp, hwt, hpmono, hgT, hprefix, hrows, hcover, + hdet, hcard, hsum⟩ := finite_weighted_greedy_package s R e 0 w B + (mem_weightedJetIndices_iff hH) he hcut + have hbounds := finiteGreedyPivots_weighted_bounds s R e H N hH hHN hN + (by simp) hcut (fun b hb => weightedJetIndices_real_weight hH (by positivity) hb) + refine ⟨e, he, g, p, hg, hpa, hp, hwt, hpmono, hgT, hprefix, hrows, hcover, + hdet, hcard, hsum, ?_, ?_⟩ + · have h := hbounds.2.2.1 + rw [← hsum ℝ (fun b => (b 0 : ℝ))] at h + exact h + · have h := hbounds.2.2.2 + rw [← hsum ℝ (fun b => (b 1 : ℝ) + b 2)] at h + exact h + +open Submodule +variable {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] + +theorem greedyPivots_filter_lt (v : ℕ → V) (n r : ℕ) (hrn : r ≤ n) : + (greedyPivots K v n).filter (fun j => j < r) = greedyPivots K v r := by + classical + ext j + simp only [Finset.mem_filter, mem_greedyPivots_iff] + constructor + · rintro ⟨⟨_, hind⟩, hjr⟩ + exact ⟨hjr, hind⟩ + · rintro ⟨hjr, hind⟩ + exact ⟨⟨hjr.trans_le hrn, hind⟩, hjr⟩ + +theorem span_greedyPivots_eq_span_earlier_rows {ι : Type*} [LinearOrder ι] + (v : ℕ → V) (n : ℕ) (e : ι ↪o ℕ) + (he : Set.range e = (greedyPivots K v n : Set ℕ)) (i : ι) : + span K (v '' (greedyPivots K v (e i) : Set ℕ)) = + span K ((v ∘ e) '' {j | j < i}) := by + have hei : e i ∈ greedyPivots K v n := by + change e i ∈ (greedyPivots K v n : Set ℕ) + rw [← he] + exact Set.mem_range_self i + have hein : e i ≤ n := + (Finset.mem_range.mp (greedyPivots_subset_range v n hei)).le + rw [← greedyPivots_filter_lt v n (e i) hein] + congr 1 + ext x + constructor + · rintro ⟨r, hr, rfl⟩ + obtain ⟨hr, hri⟩ := Finset.mem_filter.mp hr + have hrange : r ∈ Set.range e := by rwa [he] + obtain ⟨j, rfl⟩ := hrange + exact ⟨j, e.lt_iff_lt.mp hri, rfl⟩ + · rintro ⟨j, hj, rfl⟩ + refine ⟨e j, Finset.mem_filter.mpr ⟨?_, e.strictMono hj⟩, rfl⟩ + change e j ∈ (greedyPivots K v n : Set ℕ) + rw [← he] + exact Set.mem_range_self j + +theorem smaller_weight_mem_span_earlier_retained_rows {ι : Type*} [LinearOrder ι] + (v : ℕ → V) (w : ℕ → ℕ) (hw : Monotone w) (n : ℕ) (e : ι ↪o ℕ) + (he : Set.range e = (greedyPivots K v n : Set ℕ)) + (rows : ι → V) (hrows : rows = v ∘ e) (i : ι) (r : ℕ) + (hr : w r < w (e i)) : + v r ∈ span K (rows '' {j | j < i}) := by + rw [hrows, ← span_greedyPivots_eq_span_earlier_rows v n e he i] + exact smaller_weight_row_mem_span_greedyPivots v w hw hr + +end WeightedTorusJets + +namespace WeightedTorusJets + +theorem jet_weight_ball_span_eq_top {K : Type*} [Field K] {M : ℕ} + (θ y z : Fin M → K) (hθ : Function.Injective θ) (H : ℕ) (hH : 0 < H) : + Submodule.span K + ((fun α : Fin 3 → ℕ => fun j => θ j ^ α 0 * y j ^ α 1 * z j ^ α 2) '' + (weightedJetIndices H (M - 1) : Set (Fin 3 → ℕ))) = ⊤ := by + classical + let V : Matrix (Fin M) (Fin M) K := (Matrix.vandermonde θ).transpose + have hdet : V.det ≠ 0 := by + simpa only [V, Matrix.det_transpose] using + (Matrix.det_vandermonde_ne_zero_iff.mpr hθ) + have hspan : Submodule.span K (Set.range V) = ⊤ := + (Matrix.linearIndependent_rows_of_det_ne_zero hdet).span_eq_top_of_card_eq_finrank' + (by simp) + apply top_unique + rw [← hspan] + apply Submodule.span_mono + rintro _ ⟨k, rfl⟩ + refine ⟨![k.val, 0, 0], ?_, ?_⟩ + · apply (mem_weightedJetIndices_iff hH _).mpr + simp only [Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val, + Nat.mul_zero, Nat.add_zero] + omega + · funext j + simp [V, Matrix.vandermonde_apply] + +end WeightedTorusJets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ActualCofactorArithmetic.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ActualCofactorArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..444b6ebf4098d10f5db86e393e037f5adba45637 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ActualCofactorArithmetic.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceDenseCellContradiction + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseBoxApplication +open ErdosCofactorChoices ErdosInverseCells ErdosInverseRefinement ErdosInverseBoxHeight +open NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints + NumberTheoryLean.LogarithmicBinPartition + +theorem actual_excluded_bin_coprime {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) + (i : Fin (binCount (sourceW z) z xi)) (hi : m i = 0) + (q : ℕ) (hq : q ∈ cofactorChoices (actualBins z xi) m) : + ∀ p ∈ actualBins z xi i,q.Coprime p := + cofactor_coprime_excluded_bin (actualBins z xi) m + (fun j _ hp => (bin_prime_in_source hw hwz hxi j hp).1) + (fun i j hij => bins_pairwise_disjoint hw hwz hxi i j hij) i hi q hq + +theorem actual_distinct_bins_coprime {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (i j : Fin (binCount (sourceW z) z xi)) (hij : i ≠ j) : + ∀ p ∈ actualBins z xi i,∀ u ∈ actualBins z xi j,p.Coprime u := + distinct_bins_coprime (actualBins z xi) + (fun j _ hp => (bin_prime_in_source hw hwz hxi j hp).1) + (fun i j hij => bins_pairwise_disjoint hw hwz hxi i j hij) i j hij + +theorem actual_parent_small_coprime {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) + (q : ℕ) (hq : q ∈ cofactorChoices (actualBins z xi) m) + (i : Fin (binCount (sourceW z) z xi)) (p : ℕ) (hp : p ∈ actualBins z xi i) : + ∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q).Coprime t := by + intro t ht htw + have hqcop := cofactor_coprime_small (actualBins z xi) m + (fun j _ hp => (bin_prime_in_source hw hwz hxi j hp).1) (sourceW z) + (fun j _ hp => (bin_prime_in_source hw hwz hxi j hp).2.1) q hq t ht htw + apply Nat.Coprime.mul_left _ hqcop + have hps := bin_prime_in_source hw hwz hxi i hp + apply (Nat.coprime_primes hps.1 ht).mpr + intro he + subst p + linarith [hps.2.1] + +theorem actual_source_cofactor_inflation {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (Clen : ℝ) (m : Fin (binCount (sourceW z) z xi) → ℕ) + (hm : ((∑ i,m i : ℕ) : ℝ) ≤ Clen*Real.log (sourceB z)) + (q : ℕ) (hq : q ∈ cofactorChoices (actualBins z xi) m) : + 1 ≤ cofactorScale z xi m/(q : ℝ) ∧ + cofactorScale z xi m/(q : ℝ) ≤ + (1+effectiveWidth (sourceW z) z xi)^(Clen*Real.log (sourceB z)) := by + have hqpos : (0 : ℝ) < q := by exact_mod_cast actual_cofactor_positive hw hwz hxi m q hq + have htheta := effectiveWidth_pos hw hwz hxi + have hF : 0 < 1+effectiveWidth (sourceW z) z xi := by linarith + have hrange := actual_cofactor_effective_range hw hwz hxi m q hq + refine ⟨(one_le_div hqpos).mpr hrange.2,?_⟩ + calc + _ ≤ (1+effectiveWidth (sourceW z) z xi)^(∑ i,m i) := by + apply (div_le_iff₀ hqpos).mpr + have hh := (div_le_iff₀ (pow_pos hF _)).mp hrange.1 + nlinarith + _ = (1+effectiveWidth (sourceW z) z xi)^((∑ i,m i : ℕ) : ℝ) := + (Real.rpow_natCast _ _).symm + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le (by linarith) hm + +end ErdosInverseBoxApplication + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ActualCofactorCellData.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ActualCofactorCellData.lean new file mode 100644 index 0000000000000000000000000000000000000000..6acc79956dfb51b846284cfddfb4ab1401212897 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ActualCofactorCellData.lean @@ -0,0 +1,775 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Estimates.SmallModelSourceScales + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosCofactorChoices +attribute [local instance] Classical.decEq + +noncomputable def selections {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) : Finset (ι → Finset ℕ) := + Fintype.piFinset (fun i => (P i).powersetCard (m i)) + +theorem mem_selections {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) (f : ι → Finset ℕ) : + f ∈ selections P m ↔ ∀ i, f i ⊆ P i ∧ (f i).card = m i := by + simp only [selections, Fintype.mem_piFinset, Finset.mem_powersetCard] + +def selectionProduct {ι : Type*} [Fintype ι] (f : ι → Finset ℕ) : ℕ := + ∏ i, ∏ p ∈ f i, p + +noncomputable def selectionPrimes {ι : Type*} [Fintype ι] + (f : ι → Finset ℕ) : Finset ℕ := Finset.univ.biUnion f + +theorem selection_disjoint {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (f : ι → Finset ℕ) (hf : ∀ i, f i ⊆ P i) : + Pairwise (fun i j => Disjoint (f i) (f j)) := by + intro i j hij + exact (hd hij).mono (hf i) (hf j) + +theorem selectionProduct_eq_union {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (f : ι → Finset ℕ) (hf : ∀ i, f i ⊆ P i) : + selectionProduct f = ∏ p ∈ selectionPrimes f, p := by + symm + exact Finset.prod_biUnion (fun i _ j _ hij => selection_disjoint P hd f hf hij) + +theorem recover_bin {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (f : ι → Finset ℕ) (hf : ∀ i, f i ⊆ P i) (i : ι) : + selectionPrimes f ∩ P i = f i := by + ext p + constructor + · intro hp + obtain ⟨hu, hpi⟩ := Finset.mem_inter.mp hp + obtain ⟨j, _hj, hpj⟩ := Finset.mem_biUnion.mp hu + by_cases hji : j = i + · simpa only [hji] using hpj + · exact False.elim ((Finset.disjoint_left.mp (hd hji)) (hf j hpj) hpi) + · intro hp + exact Finset.mem_inter.mpr ⟨Finset.mem_biUnion.mpr ⟨i, Finset.mem_univ i, hp⟩, hf i hp⟩ + +theorem selectionProduct_primeFactors {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (f : ι → Finset ℕ) (hf : ∀ i, f i ⊆ P i) : + (selectionProduct f).primeFactors = selectionPrimes f := by + rw [selectionProduct_eq_union P hd f hf] + apply Nat.primeFactors_prod + intro p hp + obtain ⟨i, _hi, hpi⟩ := Finset.mem_biUnion.mp hp + exact hP i p (hf i hpi) + +theorem selectionProduct_pos {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (f : ι → Finset ℕ) (hf : ∀ i, f i ⊆ P i) : 0 < selectionProduct f := + Finset.prod_pos (fun i _ => Finset.prod_pos (fun p hp => (hP i p (hf i hp)).pos)) + +end ErdosCofactorChoices + +end + +section + +namespace ErdosCofactorChoices +attribute [local instance] Classical.decEq + +theorem selectionProduct_injOn {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) : + Set.InjOn selectionProduct (selections P m : Set (ι → Finset ℕ)) := by + intro f hf g hg he + have hfs := (mem_selections P m f).mp hf + have hgs := (mem_selections P m g).mp hg + have hu : selectionPrimes f = selectionPrimes g := by + rw [← selectionProduct_primeFactors P hP hd f (fun i => (hfs i).1), + ← selectionProduct_primeFactors P hP hd g (fun i => (hgs i).1), he] + funext i + rw [← recover_bin P hd f (fun j => (hfs j).1) i, + ← recover_bin P hd g (fun j => (hgs j).1) i, hu] + +noncomputable def cofactorChoices {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) : Finset ℕ := + (selections P m).image selectionProduct + +theorem selections_card {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) : + (selections P m).card = ∏ i, (P i).card.choose (m i) := by + simp only [selections, Fintype.card_piFinset, Finset.card_powersetCard] + +theorem cofactorChoices_card {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) : + (cofactorChoices P m).card = ∏ i, (P i).card.choose (m i) := by + rw [cofactorChoices, Finset.card_image_of_injOn (selectionProduct_injOn P m hP hd)] + exact selections_card P m + +theorem cofactorChoices_nonempty {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (hm : ∀ i, m i ≤ (P i).card) : (cofactorChoices P m).Nonempty := by + apply Finset.card_pos.mp + rw [cofactorChoices_card P m hP hd] + exact Finset.prod_pos (fun i _ => Nat.choose_pos (hm i)) + +theorem cofactor_positive {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) (q : ℕ) + (hq : q ∈ cofactorChoices P m) : 0 < q := by + obtain ⟨f, hf, rfl⟩ := Finset.mem_image.mp hq + exact selectionProduct_pos P hP f (fun i => ((mem_selections P m f).mp hf i).1) + +end ErdosCofactorChoices + +end + +section + +namespace ErdosCofactorChoices + +theorem half_power_le_choose (n m : ℕ) (hm : 2*m ≤ n) : + ((n : ℝ)/2)^m/(m.factorial : ℝ) ≤ (n.choose m : ℝ) := by + have hsub : m ≤ n+1 := by omega + have hhalf : (n : ℝ)/2 ≤ ((n+1-m : ℕ) : ℝ) := by + rw [Nat.cast_sub hsub, Nat.cast_add, Nat.cast_one] + have hh : 2*(m : ℝ) ≤ n := by exact_mod_cast hm + linarith + calc + _ ≤ (((n+1-m : ℕ) : ℝ)^m)/(m.factorial : ℝ) := + div_le_div_of_nonneg_right (pow_le_pow_left₀ (by positivity) hhalf m) (Nat.cast_nonneg _) + _ ≤ (n.choose m : ℝ) := by + simpa only [Nat.cast_pow] using (Nat.pow_le_choose (α := ℝ) m n) + +theorem factorial_le_uniform_power (m K : ℕ) (hm : m ≤ K) : + (m.factorial : ℝ) ≤ (K : ℝ)^m := by + exact_mod_cast (Nat.factorial_le_pow m).trans (Nat.pow_le_pow_left hm m) + +theorem scaled_power_le_choose (n m K : ℕ) (hK : 0 < K) (hm : m ≤ K) + (hn : 2*m ≤ n) (R H : ℝ) (hR : 0 ≤ R) (hH : 0 < H) + (hcount : R/H ≤ n) : + (R/(2*H*(K : ℝ)))^m ≤ (n.choose m : ℝ) := by + have hKR : (0 : ℝ) < K := by exact_mod_cast hK + have hfact : (0 : ℝ) < m.factorial := by exact_mod_cast Nat.factorial_pos m + have hp : (R/H/2)^m ≤ ((n : ℝ)/2)^m := + pow_le_pow_left₀ (by positivity) (div_le_div_of_nonneg_right hcount (by norm_num)) m + calc + _ = (R/H/2)^m/(K : ℝ)^m := by + rw [← div_pow] + congr 1 + field_simp + _ ≤ ((n : ℝ)/2)^m/(K : ℝ)^m := + div_le_div_of_nonneg_right hp (pow_nonneg hKR.le _) + _ ≤ ((n : ℝ)/2)^m/(m.factorial : ℝ) := + div_le_div_of_nonneg_left (by positivity) hfact (factorial_le_uniform_power m K hm) + _ ≤ (n.choose m : ℝ) := half_power_le_choose n m hn + +end ErdosCofactorChoices + +end + +section + +namespace ErdosCofactorChoices +attribute [local instance] Classical.decEq + +theorem selectionProduct_squarefree {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (f : ι → Finset ℕ) (hf : ∀ i, f i ⊆ P i) : Squarefree (selectionProduct f) := by + rw [selectionProduct_eq_union P hd f hf] + have hp (p : ℕ) (h : p ∈ selectionPrimes f) : p.Prime := by + obtain ⟨i, _hi, hpi⟩ := Finset.mem_biUnion.mp h + exact hP i p (hf i hpi) + apply Finset.squarefree_prod_of_pairwise_isCoprime + · intro p hpp q hqq hpq + exact Nat.coprime_iff_isRelPrime.mp ((Nat.coprime_primes (hp p hpp) (hp q hqq)).mpr hpq) + · intro p hpp + exact (hp p hpp).squarefree + +theorem cofactor_squarefree {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (q : ℕ) (hq : q ∈ cofactorChoices P m) : Squarefree q := by + obtain ⟨f, hf, rfl⟩ := Finset.mem_image.mp hq + exact selectionProduct_squarefree P hP hd f (fun i => ((mem_selections P m f).mp hf i).1) + +theorem prime_factor_bin_recovery {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (f : ι → Finset ℕ) (hf : f ∈ selections P m) (i : ι) : + (selectionProduct f).primeFactors ∩ P i = f i := by + have hs := (mem_selections P m f).mp hf + rw [selectionProduct_primeFactors P hP hd f (fun j => (hs j).1)] + exact recover_bin P hd f (fun j => (hs j).1) i + +end ErdosCofactorChoices + +end + +section + +namespace ErdosCofactorChoices +attribute [local instance] Classical.decEq + +theorem cofactor_card_half_lower {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (hm : ∀ i, 2*m i ≤ (P i).card) : + (∏ i, (((P i).card : ℝ)/2)^(m i)/((m i).factorial : ℝ)) ≤ + ((cofactorChoices P m).card : ℝ) := by + rw [cofactorChoices_card P m hP hd, Nat.cast_prod] + exact Finset.prod_le_prod₀ (fun i _ => by positivity) + (fun i _ => half_power_le_choose (P i).card (m i) (hm i)) + +theorem cofactor_card_scaled_lower {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (hm : ∀ i, 2*m i ≤ (P i).card) + (R : ι → ℝ) (hR : ∀ i, 0 ≤ R i) (H : ℝ) (hH : 0 < H) + (hcount : ∀ i, R i/H ≤ (P i).card) : + (∏ i, (R i)^(m i))/(2*H*((∑ i, m i)+1 : ℕ))^(∑ i, m i) ≤ + ((cofactorChoices P m).card : ℝ) := by + let K : ℕ := (∑ i, m i)+1 + have hK : 0 < K := Nat.succ_pos _ + have hmi (i : ι) : m i ≤ K := by + exact (Finset.single_le_sum (fun j _ => Nat.zero_le (m j)) (Finset.mem_univ i)).trans + (Nat.le_succ _) + calc + _ = ∏ i, (R i/(2*H*(K : ℝ)))^(m i) := by + simp only [div_pow, Finset.prod_div_distrib, Finset.prod_pow_eq_pow_sum] + rfl + _ ≤ ∏ i, ((P i).card.choose (m i) : ℝ) := + Finset.prod_le_prod₀ (fun i _ => pow_nonneg (div_nonneg (hR i) (by positivity)) _) + (fun i _ => scaled_power_le_choose (P i).card (m i) K hK (hmi i) + (hm i) (R i) H (hR i) hH (hcount i)) + _ = ((cofactorChoices P m).card : ℝ) := by + rw [cofactorChoices_card P m hP hd, Nat.cast_prod] + +end ErdosCofactorChoices + +end + +section + +namespace ErdosCofactorChoices + +theorem denominator_loss_budget (A C T : ℝ) (hA : 0 < A) (hC : 0 ≤ C) + (hT : 1 ≤ T) (k : ℕ) (hk : (k : ℝ) ≤ C*T) : + (2*(A*Real.exp T)*((k+1 : ℕ) : ℝ))^k ≤ + Real.exp (C*(2*A+C+1)*T^2) := by + have hT0 : 0 ≤ T := by linarith + have hD : 0 ≤ 2*A+C+1 := by positivity + have hconst : 2*A ≤ Real.exp (2*A*T) := by + have he := Real.add_one_le_exp (2*A) + have hm := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hT (by positivity : 0 ≤ 2*A)) + norm_num only [mul_one] at hm + linarith + have hkexp : ((k+1 : ℕ) : ℝ) ≤ Real.exp (C*T) := by + have he := Real.add_one_le_exp (C*T) + push_cast + linarith + have hbase : 2*(A*Real.exp T)*((k+1 : ℕ) : ℝ) ≤ + Real.exp ((2*A+C+1)*T) := by + calc + _ = (2*A)*Real.exp T*((k+1 : ℕ) : ℝ) := by ring + _ ≤ Real.exp (2*A*T)*Real.exp T*Real.exp (C*T) := + mul_le_mul (mul_le_mul_of_nonneg_right hconst (Real.exp_pos _).le) hkexp + (Nat.cast_nonneg _) (by positivity) + _ = _ := by + rw [← Real.exp_add, ← Real.exp_add] + congr 1 + ring + calc + _ ≤ (Real.exp ((2*A+C+1)*T))^k := pow_le_pow_left₀ (by positivity) hbase k + _ = Real.exp ((k : ℝ)*((2*A+C+1)*T)) := (Real.exp_nat_mul _ _).symm + _ ≤ Real.exp (C*(2*A+C+1)*T^2) := by + apply Real.exp_le_exp.mpr + have h := mul_le_mul_of_nonneg_right hk (mul_nonneg hD hT0) + nlinarith only [h] + +theorem cofactor_card_exponential_lower {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) + (hP : ∀ i, ∀ p ∈ P i, Nat.Prime p) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (hm : ∀ i, 2*m i ≤ (P i).card) + (R : ι → ℝ) (hR : ∀ i, 0 ≤ R i) (A C T : ℝ) + (hA : 0 < A) (hC : 0 ≤ C) (hT : 1 ≤ T) + (hcount : ∀ i, R i/(A*Real.exp T) ≤ (P i).card) + (hk : ((∑ i, m i) : ℝ) ≤ C*T) : + (∏ i, (R i)^(m i))*Real.exp (-C*(2*A+C+1)*T^2) ≤ + ((cofactorChoices P m).card : ℝ) := by + have hden := denominator_loss_budget A C T hA hC hT (∑ i, m i) + (by simpa only [Nat.cast_sum] using hk) + have hfinite := cofactor_card_scaled_lower P m hP hd hm R hR (A*Real.exp T) (by positivity) hcount + calc + _ = (∏ i, (R i)^(m i))/Real.exp (C*(2*A+C+1)*T^2) := by + rw [div_eq_mul_inv, ← Real.exp_neg] + congr 2 + ring + _ ≤ (∏ i, (R i)^(m i))/(2*(A*Real.exp T)*((∑ i, m i)+1 : ℕ))^(∑ i, m i) := + div_le_div_of_nonneg_left (Finset.prod_nonneg (fun i _ => pow_nonneg (hR i) _)) + (by positivity) hden + _ ≤ _ := hfinite + +end ErdosCofactorChoices + +end + +section + +open _root_.Filter +namespace ErdosCofactorChoices +open ErdosInverseBoxHeight ErdosInverseEuler ErdosInversePrimeBin + +theorem source_log_budget : ∀ᶠ z : ℝ in atTop, + 0 < Real.log z ∧ 1 ≤ Real.log (Real.log z) ∧ + 0 < sourceW z ∧ 0 < sourceB z ∧ + Real.log (sourceB z) ≤ Real.log (Real.log z) := by + filter_upwards [source_B_bounds, + (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop 1] + with z hs ht + have hw : 0 < sourceW z := (Real.exp_pos 1).trans_le hs.1 + have hb : 0 < sourceB z := by linarith [hs.2.1] + exact ⟨hb.trans_le hs.2.2, ht, hw, hb, Real.log_le_log hb hs.2.2⟩ + +theorem sqrt_sourceW_dominates (D : ℝ) (hD : 0 ≤ D) : + ∀ᶠ z : ℝ in atTop, D*Real.log (Real.log z) ≤ Real.sqrt (sourceW z) := by + have heps : 0 < 1/(D+1) := by positivity + have hsmall := (isLittleO_log_rpow_rpow_atTop (2 : ℝ) + (by norm_num : (0 : ℝ) < 1/2)).bound heps + filter_upwards [Real.tendsto_log_atTop.eventually hsmall, source_log_budget] with z hz hs + have hT : 0 < Real.log (Real.log z) := by linarith [hs.2.1] + have hbound : (Real.log (Real.log z))^2 ≤ Real.sqrt (Real.log z)/(D+1) := by + have hh : (Real.log (Real.log z))^2 ≤ (1/(D+1))*(Real.log z)^((1 : ℝ)/2) := by + simpa only [Real.norm_eq_abs, Real.rpow_two, + abs_of_nonneg (sq_nonneg (Real.log (Real.log z))), + abs_of_nonneg (Real.rpow_nonneg hs.1.le ((1 : ℝ)/2))] using hz + rw [← Real.sqrt_eq_rpow] at hh + simpa only [one_div, one_mul, div_eq_mul_inv, mul_comm] using hh + have hpay : D*(Real.log (Real.log z))^2 ≤ Real.sqrt (Real.log z) := by + have hh := (le_div_iff₀ (by positivity : 0 < D+1)).mp hbound + nlinarith [sq_nonneg (Real.log (Real.log z))] + have he : Real.sqrt (sourceW z) = Real.sqrt (Real.log z)/Real.log (Real.log z) := by + rw [sourceW, Real.sqrt_div hs.1.le, Real.sqrt_sq_eq_abs, abs_of_pos hT] + rw [he] + apply (le_div_iff₀ hT).mpr + nlinarith only [hpay] + +theorem source_multiplicity_room (eta C : ℝ) (heta : 0 < eta) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, + 2*C*Real.log (sourceB z) ≤ eta*Real.sqrt (sourceW z)/8 := by + filter_upwards [sqrt_sourceW_dominates (16*C/eta) (by positivity), source_log_budget] + with z hh hs + have hdiv : (16*C*Real.log (Real.log z))/eta ≤ Real.sqrt (sourceW z) := by + simpa only [div_mul_eq_mul_div] using hh + have hmul := (div_le_iff₀ heta).mp hdiv + have hlog := mul_le_mul_of_nonneg_left hs.2.2.2.2 (show 0 ≤ 2*C by positivity) + linarith + +end ErdosCofactorChoices + +end + +section + +open _root_.Filter +namespace ErdosCofactorChoices +open ErdosInverseBoxHeight ErdosInverseEuler ErdosInversePrimeBin + +theorem source_prime_bin_data (eta C : ℝ) (heta : 0 < eta) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, ∀ R xi : ℝ, sourceW z ≤ R → eta ≤ xi → xi ≤ 1 → + (1+xi)*R ≤ z → + 2*C*Real.log (sourceB z) ≤ ((primeBin R xi).card : ℝ) ∧ + ((1+xi)*R)/((8/eta)*Real.log z) ≤ ((primeBin R xi).card : ℝ) := by + obtain ⟨R0, hR0⟩ := eventually_atTop.mp (uniform_prime_bin_count heta) + filter_upwards [sourceW_tendsto_atTop.eventually_ge_atTop R0, + source_multiplicity_room eta C heta hC, source_log_budget] with z hz hroom hs + have hL : 0 < Real.log z := hs.1 + intro R xi hR hxi hxi1 hRz + have hc := hR0 R (hz.trans hR) + have hRp : 0 < R := by linarith [hc.1] + have hxp : 0 < xi := heta.trans_le hxi + have hlog : 0 < Real.log R := Real.log_pos (by linarith [hc.1]) + have hU : R ≤ (1+xi)*R := by nlinarith + have hlogle : Real.log R ≤ Real.log z := Real.log_le_log hRp (hU.trans hRz) + have htwo : (1+xi)*R ≤ 2*R := by nlinarith + have hlower := (hc.2 xi hxi hxi1).1 + constructor + · calc + _ ≤ eta*Real.sqrt (sourceW z)/8 := hroom + _ ≤ eta*Real.sqrt R/8 := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hR) heta.le) + (by norm_num) + _ ≤ xi*R/(4*Real.log R) := bin_scale_sqrt_lower hc.1 heta hxi + _ ≤ _ := hlower + · calc + _ = eta*((1+xi)*R)/(8*Real.log z) := by + simp only [div_eq_mul_inv, mul_inv_rev, inv_inv] + ring + _ ≤ eta*(2*R)/(8*Real.log z) := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left htwo heta.le) (by positivity) + _ = eta*R/(4*Real.log z) := by ring + _ ≤ eta*R/(4*Real.log R) := + div_le_div_of_nonneg_left (by positivity) (by positivity) + (mul_le_mul_of_nonneg_left hlogle (by norm_num)) + _ ≤ xi*R/(4*Real.log R) := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hxi hRp.le) (by positivity) + _ ≤ _ := hlower + +theorem source_cofactor_count_lower (eta C : ℝ) (heta : 0 < eta) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, ∀ (ι : Type*) [Fintype ι] (R xi : ι → ℝ) (m : ι → ℕ), + (∀ i, sourceW z ≤ R i) → (∀ i, eta ≤ xi i) → (∀ i, xi i ≤ 1) → + (∀ i, (1+xi i)*R i ≤ z) → + Pairwise (fun i j => Disjoint (primeBin (R i) (xi i)) (primeBin (R j) (xi j))) → + ((∑ i, m i : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → + (∏ i, ((1+xi i)*R i)^(m i))* + Real.exp (-C*(16/eta+C+1)*(Real.log (Real.log z))^2) ≤ + ((cofactorChoices (fun i => primeBin (R i) (xi i)) m).card : ℝ) := by + filter_upwards [source_prime_bin_data eta C heta hC, source_log_budget] with z hb hs + intro ι inst R xi m hR hxi hxi1 hU hd hk + have hprime (i : ι) (p : ℕ) (hp : p ∈ primeBin (R i) (xi i)) : Nat.Prime p := + ((mem_primeBin ((hs.2.2.1).trans_le (hR i)).le (heta.le.trans (hxi i)) p).mp hp).1 + have hhalf (i : ι) : 2*m i ≤ (primeBin (R i) (xi i)).card := by + have hmi : m i ≤ ∑ j, m j := + Finset.single_le_sum (fun j _ => Nat.zero_le (m j)) (Finset.mem_univ i) + have hmiR : (m i : ℝ) ≤ ((∑ j, m j : ℕ) : ℝ) := by exact_mod_cast hmi + have hh := (hb (R i) (xi i) (hR i) (hxi i) (hxi1 i) (hU i)).1 + have hmR : 2*(m i : ℝ) ≤ (primeBin (R i) (xi i)).card := by linarith + exact_mod_cast hmR + have hcount (i : ι) : ((1+xi i)*R i)/((8/eta)*Real.exp (Real.log (Real.log z))) ≤ + ((primeBin (R i) (xi i)).card : ℝ) := by + rw [Real.exp_log hs.1] + exact (hb (R i) (xi i) (hR i) (hxi i) (hxi1 i) (hU i)).2 + have hsize : ((∑ i, m i : ℕ) : ℝ) ≤ C*Real.log (Real.log z) := + hk.trans (mul_le_mul_of_nonneg_left hs.2.2.2.2 hC) + have hnonneg (i : ι) : 0 ≤ (1+xi i)*R i := + mul_nonneg (by linarith [hxi i]) ((hs.2.2.1).trans_le (hR i)).le + have hh := cofactor_card_exponential_lower (fun i => primeBin (R i) (xi i)) m + hprime hd hhalf (fun i => (1+xi i)*R i) hnonneg (8/eta) C (Real.log (Real.log z)) + (by positivity) hC hs.2.1 hcount (by simpa only [Nat.cast_sum] using hsize) + have he : (2 : ℝ)*(8/eta) = 16/eta := by ring + rw [he] at hh + exact hh + +end ErdosCofactorChoices + +end + +section + +open _root_.Filter +namespace ErdosCofactorChoices +open ErdosInverseBoxHeight ErdosInverseEuler ErdosInversePrimeBin +open NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints +open NumberTheoryLean.LogarithmicBinPartition + +theorem source_span_geometry : ∀ᶠ z : ℝ in atTop, + 0 < sourceW z ∧ sourceW z < z ∧ + ∀ xi : ℝ, 0 < xi → xi ≤ 1 → Real.log (1+xi) ≤ Real.log (z/sourceW z) := by + have hsmall := Real.isLittleO_log_id_atTop.bound (by norm_num : (0 : ℝ) < 1/2) + filter_upwards [source_log_budget, hsmall, eventually_gt_atTop (1 : ℝ)] with z hs hz hz1 + have hzp : 0 < z := by linarith + have hlogz : 0 < Real.log z := hs.1 + have hlog : Real.log z ≤ (1/2 : ℝ)*z := by + simpa only [Real.norm_eq_abs, abs_of_pos hlogz, abs_of_pos hzp, id_eq] using hz + have hden : 1 ≤ (Real.log (Real.log z))^2 := by nlinarith [hs.2.1] + have hWle : sourceW z ≤ Real.log z := div_le_self hlogz.le hden + have hw : 0 < sourceW z := hs.2.2.1 + have hwz : sourceW z < z := by linarith + refine ⟨hw, hwz, ?_⟩ + intro xi hxi hxi1 + apply Real.log_le_log (by linarith : 0 < 1+xi) + apply (le_div_iff₀ hw).mpr + nlinarith [mul_le_mul_of_nonneg_right hxi1 hw.le] + +noncomputable def actualBins (z xi : ℝ) : Fin (binCount (sourceW z) z xi) → Finset ℕ := + fun i => primeBin (lower (sourceW z) z xi i) (width (sourceW z) z xi i) + +noncomputable def cofactorScale (z xi : ℝ) (m : Fin (binCount (sourceW z) z xi) → ℕ) : ℝ := + ∏ i, (upper (sourceW z) z xi i)^(m i) + +theorem cofactorScale_nonneg {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) : 0 ≤ cofactorScale z xi m := by + apply Finset.prod_nonneg + intro i _ + have hb := bin_source_bounds hw hwz hxi i + exact pow_nonneg ((hw.trans_le hb.1).trans hb.2.1).le _ + +theorem actual_source_many_cofactors (C xi : ℝ) (hC : 0 ≤ C) (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop, ∀ m : Fin (binCount (sourceW z) z xi) → ℕ, + ((∑ i, m i : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → + cofactorScale z xi m*Real.exp (-C*(64/xi+C+1)*(Real.log (Real.log z))^2) ≤ + ((cofactorChoices (actualBins z xi) m).card : ℝ) := by + filter_upwards [source_cofactor_count_lower (xi/4) C (by positivity) hC, source_span_geometry] + with z hc hs + intro m hm + have hwide := effectiveWidth_ge_quarter hs.1 hs.2.1 hxi hxi1 (hs.2.2 xi hxi hxi1) + have hwidth := effectiveWidth_le hs.1 hs.2.1 hxi + have hh := hc (Fin (binCount (sourceW z) z xi)) (lower (sourceW z) z xi) + (width (sourceW z) z xi) m + (fun i => (bin_source_bounds hs.1 hs.2.1 hxi i).1) + (fun _ => hwide) (fun _ => hwidth.trans hxi1) + (fun i => (bin_source_bounds hs.1 hs.2.1 hxi i).2.2) + (fun i j hij => bins_pairwise_disjoint hs.1 hs.2.1 hxi i j hij) hm + have he : (16 : ℝ)/(xi/4) = 64/xi := by + rw [div_div_eq_mul_div] + norm_num + rw [he] at hh + exact hh + +theorem actual_source_many_cofactors_power (C xi eps : ℝ) (hC : 0 ≤ C) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, ∀ m : Fin (binCount (sourceW z) z xi) → ℕ, + ((∑ i, m i : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → + cofactorScale z xi m/(sourceZ z)^eps ≤ + ((cofactorChoices (actualBins z xi) m).card : ℝ) := by + have hD : 0 ≤ C*(64/xi+C+1) := by positivity + filter_upwards [actual_source_many_cofactors C xi hC hxi hxi1, + exp_loglog_sq_le_sourceZ (C*(64/xi+C+1)) eps hD heps, source_span_geometry] + with z hc hg hs + intro m hm + calc + _ ≤ cofactorScale z xi m/Real.exp ((C*(64/xi+C+1))*(Real.log (Real.log z))^2) := + div_le_div_of_nonneg_left (cofactorScale_nonneg hs.1 hs.2.1 hxi m) (Real.exp_pos _) hg + _ = cofactorScale z xi m*Real.exp (-C*(64/xi+C+1)*(Real.log (Real.log z))^2) := by + rw [div_eq_mul_inv, ← Real.exp_neg] + congr 2 + ring + _ ≤ _ := hc m hm + +end ErdosCofactorChoices + +end + +section + +namespace ErdosCofactorChoices +attribute [local instance] Classical.decEq +open ErdosInverseBoxHeight ErdosInversePrimeBin +open NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints + +theorem selectionProduct_upper {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) (f : ι → Finset ℕ) (hf : f ∈ selections P m) + (U : ι → ℝ) (hU : ∀ i, ∀ p ∈ P i, (p : ℝ) ≤ U i) : + (selectionProduct f : ℝ) ≤ ∏ i, (U i)^(m i) := by + rw [selectionProduct, Nat.cast_prod] + apply Finset.prod_le_prod₀ (fun i _ => Nat.cast_nonneg _) + intro i _ + have hs := (mem_selections P m f).mp hf i + rw [Nat.cast_prod] + calc + _ ≤ ∏ _p ∈ f i, U i := Finset.prod_le_prod₀ (fun p _ => Nat.cast_nonneg p) + (fun p hp => hU i p (hs.1 hp)) + _ = (U i)^(m i) := by rw [Finset.prod_const, hs.2] + +theorem selectionProduct_lower {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) (f : ι → Finset ℕ) (hf : f ∈ selections P m) + (U : ι → ℝ) (hU : ∀ i, 0 ≤ U i) (F : ℝ) (hF : 0 < F) + (hlower : ∀ i, ∀ p ∈ P i, U i/F ≤ (p : ℝ)) : + (∏ i, (U i)^(m i))/F^(∑ i, m i) ≤ (selectionProduct f : ℝ) := by + calc + _ = ∏ i, (U i/F)^(m i) := by + simp only [div_pow, Finset.prod_div_distrib, Finset.prod_pow_eq_pow_sum] + _ ≤ (selectionProduct f : ℝ) := by + rw [selectionProduct, Nat.cast_prod] + apply Finset.prod_le_prod₀ (fun i _ => pow_nonneg (div_nonneg (hU i) hF.le) _) + intro i _ + have hs := (mem_selections P m f).mp hf i + rw [Nat.cast_prod, ← hs.2, ← Finset.prod_const] + exact Finset.prod_le_prod₀ (fun _ _ => div_nonneg (hU i) hF.le) + (fun p hp => hlower i p (hs.1 hp)) + +theorem actual_cofactor_range {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) (q : ℕ) + (hq : q ∈ cofactorChoices (actualBins z xi) m) : + cofactorScale z xi m/(1+xi)^(∑ i, m i) ≤ (q : ℝ) ∧ (q : ℝ) ≤ cofactorScale z xi m := by + obtain ⟨f, hf, rfl⟩ := Finset.mem_image.mp hq + have hU (i : Fin (binCount (sourceW z) z xi)) : 0 ≤ upper (sourceW z) z xi i := by + have hb := bin_source_bounds hw hwz hxi i + exact ((hw.trans_le hb.1).trans hb.2.1).le + have hlower (i : Fin (binCount (sourceW z) z xi)) (p : ℕ) (hp : p ∈ actualBins z xi i) : + upper (sourceW z) z xi i/(1+xi) ≤ (p : ℝ) := by + have hb := (mem_primeBin (endpoint_pos hw i.1).le (effectiveWidth_pos hw hwz hxi).le p).mp hp + have hwidth := effectiveWidth_le hw hwz hxi + have hl : upper (sourceW z) z xi i/(1+xi) ≤ lower (sourceW z) z xi i := by + apply (div_le_iff₀ (by linarith : 0 < 1+xi)).mpr + change (1+effectiveWidth (sourceW z) z xi)*lower (sourceW z) z xi i ≤ _ + have hl0 : 0 ≤ lower (sourceW z) z xi i := (endpoint_pos hw i.1).le + have h := mul_le_mul_of_nonneg_right hwidth hl0 + nlinarith + exact hl.trans hb.2.1.le + have hupper (i : Fin (binCount (sourceW z) z xi)) (p : ℕ) (hp : p ∈ actualBins z xi i) : + (p : ℝ) ≤ upper (sourceW z) z xi i := + ((mem_primeBin (endpoint_pos hw i.1).le (effectiveWidth_pos hw hwz hxi).le p).mp hp).2.2 + exact ⟨selectionProduct_lower (actualBins z xi) m f hf (upper (sourceW z) z xi) hU (1+xi) + (by linarith) hlower, + selectionProduct_upper (actualBins z xi) m f hf (upper (sourceW z) z xi) hupper⟩ + +theorem actual_cofactor_positive {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) (q : ℕ) + (hq : q ∈ cofactorChoices (actualBins z xi) m) : 0 < q := + cofactor_positive (actualBins z xi) m + (fun i _ hp => (bin_prime_in_source hw hwz hxi i hp).1) q hq + +theorem actual_cofactor_ratio {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) (q r : ℕ) + (hq : q ∈ cofactorChoices (actualBins z xi) m) (hr : r ∈ cofactorChoices (actualBins z xi) m) : + (q : ℝ)/(r : ℝ) ≤ (1+xi)^(∑ i, m i) := by + have hqp := actual_cofactor_range hw hwz hxi m q hq + have hrp := actual_cofactor_range hw hwz hxi m r hr + have hF : 0 < (1+xi)^(∑ i, m i) := by positivity + have hr0 : (0 : ℝ) < r := by exact_mod_cast actual_cofactor_positive hw hwz hxi m r hr + apply (div_le_iff₀ hr0).mpr + have h := (div_le_iff₀ hF).mp hrp.1 + simpa only [mul_comm] using hqp.2.trans h + +end ErdosCofactorChoices + +end + +section + +open _root_.Filter +namespace ErdosCofactorChoices +open ErdosInverseBoxHeight ErdosInverseEuler +open NumberTheoryLean.LogarithmicBinScale + +theorem actual_reciprocal_variation {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) (q r : ℕ) + (hq : q ∈ cofactorChoices (actualBins z xi) m) (hr : r ∈ cofactorChoices (actualBins z xi) m) : + (q : ℝ)⁻¹ ≤ (1+xi)^(∑ i, m i)*(r : ℝ)⁻¹ := by + have h := actual_cofactor_ratio hw hwz hxi m r q hr hq + have hq0 : (0 : ℝ) < q := by exact_mod_cast actual_cofactor_positive hw hwz hxi m q hq + have hr0 : (0 : ℝ) < r := by exact_mod_cast actual_cofactor_positive hw hwz hxi m r hr + have hm := (div_le_iff₀ hq0).mp h + have hi : (1 : ℝ)/(q : ℝ) ≤ (1+xi)^(∑ i, m i)/(r : ℝ) := by + apply (div_le_div_iff₀ hq0 hr0).mpr + simpa only [one_mul] using hm + simpa only [one_div, div_eq_mul_inv, one_mul] using hi + +theorem source_bin_factor_subpower (C eps : ℝ) (hC : 0 ≤ C) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, ∀ (xi : ℝ) (k : ℕ), 0 < xi → xi ≤ 1 → + (k : ℝ) ≤ C*Real.log (sourceB z) → (1+xi)^k ≤ (sourceZ z)^eps := by + filter_upwards [source_log_budget, exp_loglog_sq_le_sourceZ C eps hC heps] with z hs hg + intro xi k hxi hxi1 hk + have hbase : 0 < 1+xi := by linarith + have hlog : Real.log (1+xi) ≤ 1 := by + have h := Real.log_le_sub_one_of_pos hbase + linarith + have hlen : (k : ℝ) ≤ C*Real.log (Real.log z) := + hk.trans (mul_le_mul_of_nonneg_left hs.2.2.2.2 hC) + have hT : Real.log (Real.log z) ≤ (Real.log (Real.log z))^2 := by nlinarith [hs.2.1] + calc + _ = Real.exp ((k : ℝ)*Real.log (1+xi)) := by + rw [Real.exp_nat_mul, Real.exp_log hbase] + _ ≤ Real.exp (C*(Real.log (Real.log z))^2) := by + apply Real.exp_le_exp.mpr + calc + _ ≤ (k : ℝ)*1 := mul_le_mul_of_nonneg_left hlog (Nat.cast_nonneg k) + _ ≤ C*Real.log (Real.log z) := by simpa only [mul_one] using hlen + _ ≤ _ := mul_le_mul_of_nonneg_left hT hC + _ ≤ _ := hg + +theorem source_cofactor_weight_variation (C xi eps : ℝ) (hC : 0 ≤ C) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, ∀ m : Fin (binCount (sourceW z) z xi) → ℕ, + ((∑ i, m i : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → ∀ q r : ℕ, + q ∈ cofactorChoices (actualBins z xi) m → r ∈ cofactorChoices (actualBins z xi) m → + (q : ℝ)/(r : ℝ) ≤ (sourceZ z)^eps ∧ + (q : ℝ)⁻¹ ≤ (sourceZ z)^eps*(r : ℝ)⁻¹ := by + filter_upwards [source_span_geometry, source_bin_factor_subpower C eps hC heps] with z hs hb + intro m hm q r hq hr + have hf := hb xi (∑ i, m i) hxi hxi1 hm + exact ⟨(actual_cofactor_ratio hs.1 hs.2.1 hxi m q r hq hr).trans hf, + (actual_reciprocal_variation hs.1 hs.2.1 hxi m q r hq hr).trans + (mul_le_mul_of_nonneg_right hf (inv_nonneg.mpr (Nat.cast_nonneg r)))⟩ + +end ErdosCofactorChoices + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseCells +open ErdosCofactorChoices ErdosInverseBoxHeight ErdosInverseEuler ErdosInversePrimeBin +open NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints NumberTheoryLean.LogarithmicBinPartition + +theorem actual_cofactorScale_pos {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) : 0 < cofactorScale z xi m := by + apply Finset.prod_pos + intro i _ + have hb := bin_source_bounds hw hwz hxi i + exact pow_pos ((hw.trans_le hb.1).trans hb.2.1) _ + +theorem actual_cofactor_squarefree {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) (q : ℕ) + (hq : q ∈ cofactorChoices (actualBins z xi) m) : Squarefree q := + cofactor_squarefree (actualBins z xi) m (fun i _ hp => (bin_prime_in_source hw hwz hxi i hp).1) + (fun i j hij => bins_pairwise_disjoint hw hwz hxi i j hij) q hq + +theorem actual_cofactor_effective_range {z xi : ℝ} (hw : 0 < sourceW z) (hwz : sourceW z < z) + (hxi : 0 < xi) (m : Fin (binCount (sourceW z) z xi) → ℕ) (q : ℕ) + (hq : q ∈ cofactorChoices (actualBins z xi) m) : + cofactorScale z xi m/(1+effectiveWidth (sourceW z) z xi)^(∑ i,m i) ≤ (q : ℝ) ∧ + (q : ℝ) ≤ cofactorScale z xi m := by + have hupper := (actual_cofactor_range hw hwz hxi m q hq).2 + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp hq + have htheta := effectiveWidth_pos hw hwz hxi + have hF : 0 < 1+effectiveWidth (sourceW z) z xi := by linarith + have hU : ∀ i : Fin (binCount (sourceW z) z xi),0 ≤ upper (sourceW z) z xi i := by + intro i + have hb := bin_source_bounds hw hwz hxi i + exact ((hw.trans_le hb.1).trans hb.2.1).le + have hlower : ∀ i : Fin (binCount (sourceW z) z xi),∀ p ∈ actualBins z xi i, + upper (sourceW z) z xi i/(1+effectiveWidth (sourceW z) z xi) ≤ (p : ℝ) := by + intro i p hp + have hh := (mem_primeBin (endpoint_pos hw i.1).le htheta.le p).mp hp + have he : upper (sourceW z) z xi i/(1+effectiveWidth (sourceW z) z xi) = lower (sourceW z) z xi i := by + change ((1+effectiveWidth (sourceW z) z xi)*lower (sourceW z) z xi i)/(1+effectiveWidth (sourceW z) z xi) = _ + field_simp + rw [he] + exact hh.2.1.le + exact ⟨selectionProduct_lower (actualBins z xi) m f hf (upper (sourceW z) z xi) hU + (1+effectiveWidth (sourceW z) z xi) hF hlower,hupper⟩ + +theorem source_cofactor_cell_data (C xi eps : ℝ) (hC : 0 ≤ C) (hxi : 0 < xi) + (hxi1 : xi ≤ 1) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop,∀ m : Fin (binCount (sourceW z) z xi) → ℕ, + ((∑ i,m i : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → + 0 < cofactorScale z xi m ∧ 0 < (cofactorChoices (actualBins z xi) m).card ∧ + cofactorScale z xi m/(sourceZ z)^eps ≤ ((cofactorChoices (actualBins z xi) m).card : ℝ) ∧ + ∀ q ∈ cofactorChoices (actualBins z xi) m,0 < q ∧ Squarefree q := by + filter_upwards [source_span_geometry,actual_source_many_cofactors_power C xi eps hC hxi hxi1 heps] with z hs hc + intro m hm + have hS := actual_cofactorScale_pos hs.1 hs.2.1 hxi m + have hcount := hc m hm + have hZ : 0 < sourceZ z := Real.exp_pos _ + have hn : (0 : ℝ) < (cofactorChoices (actualBins z xi) m).card := + (div_pos hS (Real.rpow_pos_of_pos hZ eps)).trans_le hcount + refine ⟨hS,by exact_mod_cast hn,hcount,?_⟩ + intro q hq + exact ⟨actual_cofactor_positive hs.1 hs.2.1 hxi m q hq, + actual_cofactor_squarefree hs.1 hs.2.1 hxi m q hq⟩ + +end ErdosInverseCells + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/AdmittedExponentMarginal.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AdmittedExponentMarginal.lean new file mode 100644 index 0000000000000000000000000000000000000000..653b27dfc946afc475d1342e534ca040dbe7d720 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AdmittedExponentMarginal.lean @@ -0,0 +1,335 @@ +import Mathlib.MeasureTheory.Function.JacobianOneDim +import OAI.NumberTheory.Jacobsthal.Estimates.HarmonicChangeOfVariable +import OAI.NumberTheory.Jacobsthal.Paths.AdmittedHarmonicPaths +import OAI.NumberTheory.Jacobsthal.Probability.HarmonicPrefixKernel + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.HarmonicExponentMeasure + +open Set MeasureTheory +open scoped ENNReal +open FinitePathGeometry HarmonicChangeOfVariable + +theorem nextExponent_measurable (r : ℝ) : Measurable (nextExponent r) := + measurable_const.div (measurable_id.add_const 1) + +theorem exponent_image_Ici {r a : ℝ} (hr : 0 < r) (ha : 0 < a) : + nextExponent r '' Ici a = Ioc 0 (nextExponent r a) := by + ext x + constructor + · rintro ⟨t, ht, rfl⟩ + change a ≤ t at ht + refine ⟨nextExponent_pos hr (ha.trans_le ht), ?_⟩ + exact div_le_div_of_nonneg_left hr.le (by linarith : 0 < a + 1) (by linarith) + · intro hx + refine ⟨r / x - 1, ?_, ?_⟩ + · change a ≤ r / x - 1 + have hm := (le_div_iff₀ (by linarith : 0 < a + 1)).mp hx.2 + have hd : a + 1 ≤ r / x := (le_div_iff₀ hx.1).mpr (by nlinarith) + linarith + · unfold nextExponent + simp only [sub_add_cancel] + field_simp [hr.ne', hx.1.ne'] + +theorem nextExponent_injOn {r a : ℝ} (hr : 0 < r) (ha : 0 < a) : + InjOn (nextExponent r) (Ici a) := by + intro t ht u hu heq + have h := congrArg (fun x : ℝ => r / x - 1) heq + simpa only [inverse_exponent hr (ha.trans_le ht), inverse_exponent hr (ha.trans_le hu)] using h + +theorem harmonic_lintegral_substitution {r a : ℝ} (hr : 0 < r) (ha : 0 < a) + (H : ℝ → ℝ≥0∞) : + (∫⁻ t in Ici a, ENNReal.ofReal (1 / (t + 1)) * H (nextExponent r t)) = + ∫⁻ x in Ioc 0 (nextExponent r a), ENNReal.ofReal x⁻¹ * H x := by + have h := lintegral_image_eq_lintegral_abs_deriv_mul (f := nextExponent r) + (f' := fun t => -r / (t + 1)^2) measurableSet_Ici + (fun t ht => (exponent_hasDerivAt (r := r) (ha.trans_le ht)).hasDerivWithinAt) + (nextExponent_injOn hr ha) (fun x => ENNReal.ofReal x⁻¹ * H x) + rw [exponent_image_Ici hr ha] at h + rw [h] + apply lintegral_congr_ae + apply ae_restrict_of_forall_mem measurableSet_Ici + intro t ht + have ht0 := ha.trans_le ht + have hx := nextExponent_pos hr ht0 + have heq : |(-r / (t + 1)^2)| * (nextExponent r t)⁻¹ = 1 / (t + 1) := by + have hj := harmonic_jacobian hr ht0 + rw [(exponent_hasDerivAt (r := r) ht0).deriv] at hj + simpa only [div_eq_mul_inv] using hj + dsimp only + rw [← mul_assoc, ← ENNReal.ofReal_mul (abs_nonneg _), heq] + +noncomputable def ratioMeasure (a : ℝ) : Measure ℝ := + (volume.restrict (Ici a)).withDensity (fun t : ℝ => ENNReal.ofReal (1 / (t + 1))) + +noncomputable def exponentMeasure (b : ℝ) : Measure ℝ := + (volume.restrict (Ioc 0 b)).withDensity (fun x : ℝ => ENNReal.ofReal x⁻¹) + +theorem ratioMeasure_map {r a : ℝ} (hr : 0 < r) (ha : 0 < a) : + (ratioMeasure a).map (nextExponent r) = exponentMeasure (nextExponent r a) := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH (nextExponent_measurable r)] + unfold ratioMeasure exponentMeasure + rw [lintegral_withDensity_eq_lintegral_mul _ (f := fun t : ℝ => ENNReal.ofReal (1 / (t + 1))) + (g := fun t : ℝ => H (nextExponent r t)) (by fun_prop) + (hH.comp (nextExponent_measurable r)), + lintegral_withDensity_eq_lintegral_mul _ (f := fun x : ℝ => ENNReal.ofReal x⁻¹) (g := H) (by fun_prop) hH] + exact harmonic_lintegral_substitution hr ha H + +noncomputable def inverseRatio (r x : ℝ) : ℝ := r / x - 1 + +theorem inverseRatio_measurable (r : ℝ) : Measurable (inverseRatio r) := + (measurable_const.div measurable_id).sub_const 1 + +theorem inverse_lintegral_substitution {r a : ℝ} (hr : 0 < r) (ha : 0 < a) + (H : ℝ → ℝ≥0∞) : + (∫⁻ t in Ici a, ENNReal.ofReal (1 / (t + 1)) * H t) = + ∫⁻ x in Ioc 0 (nextExponent r a), ENNReal.ofReal x⁻¹ * H (inverseRatio r x) := by + calc + _ = ∫⁻ t in Ici a, ENNReal.ofReal (1 / (t + 1)) * H (inverseRatio r (nextExponent r t)) := by + apply lintegral_congr_ae + apply ae_restrict_of_forall_mem measurableSet_Ici + intro t ht + dsimp only + rw [inverseRatio, inverse_exponent hr (ha.trans_le ht)] + _ = _ := harmonic_lintegral_substitution hr ha (fun x => H (inverseRatio r x)) + +theorem exponentMeasure_map {r a : ℝ} (hr : 0 < r) (ha : 0 < a) : + (exponentMeasure (nextExponent r a)).map (inverseRatio r) = ratioMeasure a := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH (inverseRatio_measurable r)] + unfold ratioMeasure exponentMeasure + rw [lintegral_withDensity_eq_lintegral_mul _ (f := fun x : ℝ => ENNReal.ofReal x⁻¹) + (g := fun x : ℝ => H (inverseRatio r x)) (by fun_prop) (hH.comp (inverseRatio_measurable r)), + lintegral_withDensity_eq_lintegral_mul _ (f := fun t : ℝ => ENNReal.ofReal (1 / (t + 1))) + (g := H) (by fun_prop) hH] + exact (inverse_lintegral_substitution hr ha H).symm + +theorem ratioMeasure_map_update {β : Type*} [MeasurableSpace β] + {r a : ℝ} (hr : 0 < r) (ha : 0 < a) (U : ℝ → β) (hU : Measurable U) : + (ratioMeasure a).map U = + (exponentMeasure (nextExponent r a)).map (fun x => U (inverseRatio r x)) := by + rw [← exponentMeasure_map hr ha, Measure.map_map hU (inverseRatio_measurable r)] + rfl + +theorem accepted_exponent_measure {r a ell : ℝ} (hr : 0 < r) (ha : 0 < a) (hell : 0 ≤ ell) : + ((ratioMeasure a).restrict {t | ell < nextExponent r t}).map (nextExponent r) = + (volume.restrict (Ioc ell (nextExponent r a))).withDensity (fun x : ℝ => ENNReal.ofReal x⁻¹) := by + change ((ratioMeasure a).restrict ((nextExponent r) ⁻¹' Ioi ell)).map (nextExponent r) = _ + rw [← Measure.restrict_map (nextExponent_measurable r) (s := Ioi ell) measurableSet_Ioi, ratioMeasure_map hr ha] + unfold exponentMeasure + rw [restrict_withDensity measurableSet_Ioi, Measure.restrict_restrict measurableSet_Ioi] + congr 2 + ext x + simp only [mem_inter_iff, mem_Ioi, mem_Ioc] + constructor + · rintro ⟨hx, _, hu⟩ + exact ⟨hx, hu⟩ + · intro hx + exact ⟨hx.1, lt_of_le_of_lt hell hx.1, hx.2⟩ + +end NumberTheoryLean.HarmonicExponentMeasure + +end + +section + +namespace NumberTheoryLean.HarmonicExponentRows + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostGrouping +open HarmonicExponentMeasure HarmonicKernelDensities HarmonicWeightKernel +open ArrivalKernelGeometry AdmittedHarmonicPaths RegeneratingInverseBands +open Erdos970Dependency.OrdinaryKernelInvariance + + theorem exponentMeasure_restrict (b : ℝ) {ell : ℝ} (hell : 0 ≤ ell) : + (exponentMeasure b).restrict (Ioi ell) = + (volume.restrict (Ioc ell b)).withDensity (fun x : ℝ => ENNReal.ofReal x⁻¹) := by + unfold exponentMeasure + rw [restrict_withDensity measurableSet_Ioi, Measure.restrict_restrict measurableSet_Ioi] + congr 2 + ext x + simp only [mem_inter_iff, mem_Ioi, mem_Ioc] + constructor + · rintro ⟨hx, _, hu⟩; exact ⟨hx, hu⟩ + · intro hx; exact ⟨hx.1, lt_of_le_of_lt hell hx.1, hx.2⟩ + +theorem exponentMeasure_ae_interval (b : ℝ) : + ∀ᵐ x ∂exponentMeasure b, x ∈ Ioc 0 b := by + unfold exponentMeasure + rw [ae_withDensity_iff (by fun_prop : Measurable (fun x : ℝ => ENNReal.ofReal x⁻¹))] + filter_upwards [self_mem_ae_restrict measurableSet_Ioc] with x hx + intro _ + exact hx + +theorem accepted_update_measure {β : Type*} [MeasurableSpace β] + {r a ell : ℝ} (hr : 0 < r) (ha : 0 < a) (hell : 0 ≤ ell) + (U : ℝ → β) (hU : Measurable U) (A : Set β) (hA : MeasurableSet A) + (hcut : ∀ t, a ≤ t → (U t ∈ A ↔ ell < nextExponent r t)) : + ((ratioMeasure a).map U).restrict A = + ((volume.restrict (Ioc ell (nextExponent r a))).withDensity + (fun x : ℝ => ENNReal.ofReal x⁻¹)).map (fun x => U (inverseRatio r x)) := by + rw [ratioMeasure_map_update hr ha U hU, + Measure.restrict_map (f := fun x => U (inverseRatio r x)) (hU.comp (inverseRatio_measurable r)) hA] + have hEq : (fun x => U (inverseRatio r x)) ⁻¹' A =ᵐ[exponentMeasure (nextExponent r a)] Ioi ell := by + filter_upwards [exponentMeasure_ae_interval (nextExponent r a)] with x hx + obtain ⟨t, ht, rfl⟩ := (exponent_image_Ici hr ha).symm.subset hx + apply propext + change U (inverseRatio r (nextExponent r t)) ∈ A ↔ ell < nextExponent r t + rw [inverseRatio, HarmonicChangeOfVariable.inverse_exponent hr (ha.trans_le ht)] + exact hcut t ht + rw [Measure.restrict_congr_set hEq, exponentMeasure_restrict _ hell] + +theorem harmonic_even_ratioMeasure (s : EvenState) (T : ℝ) : + harmonicKernel (.inl s, T) = (ratioMeasure (s.1 - 1)).map (evenUpdateReal T) := by + rw [harmonic_even_measure] + unfold harmonicRatioDensity + rw [withDensity_indicator measurableSet_Ici] + rfl + +theorem harmonic_odd_ratioMeasure (s : OddState) (T : ℝ) : + harmonicKernel (.inr s, T) = (ratioMeasure (max 2 (s.1 - 1))).map (oddUpdateReal T) := by + rw [harmonic_odd_measure] + unfold harmonicRatioDensity + rw [withDensity_indicator measurableSet_Ici] + rfl + +theorem evenUpdate_exponent (v T : ℝ) (s : EvenState) {t : ℝ} (ht : s.1 - 1 ≤ t) : + currentExponent v (evenUpdateReal T t) = nextExponent (Real.exp (v - T)) t := by + have hratio : stateRatio (.inr (oddLift t)) = t := by + change max (95 / 100 : ℝ) t = t + apply max_eq_right + linarith [s.2] + change currentExponent v (.inr (oddLift t), T + cost t) = _ + simpa only [hratio, gapValue] using currentExponent_update v ((.inl s), T) (.inr (oddLift t)) + +theorem oddUpdate_exponent (v T : ℝ) (s : OddState) {t : ℝ} (ht : max 2 (s.1 - 1) ≤ t) : + currentExponent v (oddUpdateReal T t) = nextExponent (Real.exp (v - T)) t := by + have hratio : stateRatio (.inl (evenLift t)) = t := by + change max (198 / 100 : ℝ) t = t + apply max_eq_right + linarith [le_max_left (2 : ℝ) (s.1 - 1)] + change currentExponent v (.inl (evenLift t), T + cost t) = _ + simpa only [hratio, gapValue] using currentExponent_update v ((.inr s), T) (.inl (evenLift t)) + +theorem admitted_even_exponent_row (v T : ℝ) (s : EvenState) {ell : ℝ} (hell : 0 ≤ ell) : + admittedHarmonic v ell (.inl s, T) = + ((volume.restrict (Ioc ell (Real.exp (v - T) / s.1))).withDensity + (fun x : ℝ => ENNReal.ofReal x⁻¹)).map + (fun x => evenUpdateReal T (inverseRatio (Real.exp (v - T)) x)) := by + rw [admittedHarmonic, Kernel.restrict_apply, harmonic_even_ratioMeasure] + have h := accepted_update_measure (Real.exp_pos (v - T)) + (by linarith [s.2] : 0 < s.1 - 1) hell (evenUpdateReal T) (evenUpdateReal_measurable T) + (arrivalSet v ell) (arrivalSet_measurable v ell) (fun t ht => by + change ell < currentExponent v (evenUpdateReal T t) ↔ _ + rw [evenUpdate_exponent v T s ht]) + simpa only [nextExponent, sub_add_cancel] using h + +theorem admitted_odd_exponent_row (v T : ℝ) (s : OddState) {ell : ℝ} (hell : 0 ≤ ell) : + admittedHarmonic v ell (.inr s, T) = + ((volume.restrict (Ioc ell (nextExponent (Real.exp (v - T)) (max 2 (s.1 - 1))))).withDensity + (fun x : ℝ => ENNReal.ofReal x⁻¹)).map + (fun x => oddUpdateReal T (inverseRatio (Real.exp (v - T)) x)) := by + rw [admittedHarmonic, Kernel.restrict_apply, harmonic_odd_ratioMeasure] + exact accepted_update_measure (Real.exp_pos (v - T)) + (lt_of_lt_of_le (by norm_num : (0 : ℝ) < 2) (le_max_left _ _)) hell + (oddUpdateReal T) (oddUpdateReal_measurable T) (arrivalSet v ell) (arrivalSet_measurable v ell) + (fun t ht => by + change ell < currentExponent v (oddUpdateReal T t) ↔ _ + rw [oddUpdate_exponent v T s ht]) + +end NumberTheoryLean.HarmonicExponentRows + +end + +section + +namespace NumberTheoryLean.AdmittedExponentMarginal + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostGrouping +open HarmonicExponentMeasure HarmonicExponentRows HarmonicKernelDensities +open ArrivalKernelGeometry AdmittedHarmonicPaths + + theorem inverse_update_marginal {β : Type*} [MeasurableSpace β] + {r a ell : ℝ} (hr : 0 < r) (ha : 0 < a) (hell : 0 ≤ ell) + (U : ℝ → β) (hU : Measurable U) (V : β → ℝ) (hV : Measurable V) + (hVU : ∀ t, a ≤ t → V (U t) = nextExponent r t) : + ((((volume.restrict (Ioc ell (nextExponent r a))).withDensity + (fun x : ℝ => ENNReal.ofReal x⁻¹)).map (fun x => U (inverseRatio r x))).map V) = + (volume.restrict (Ioc ell (nextExponent r a))).withDensity (fun x : ℝ => ENNReal.ofReal x⁻¹) := by + let μ := (volume.restrict (Ioc ell (nextExponent r a))).withDensity (fun x : ℝ => ENNReal.ofReal x⁻¹) + have hs : ∀ᵐ x ∂μ, x ∈ Ioc ell (nextExponent r a) := + (withDensity_absolutelyContinuous _ _).ae_le (ae_restrict_mem measurableSet_Ioc) + have hEq : (V ∘ (fun x => U (inverseRatio r x))) =ᵐ[μ] id := by + filter_upwards [hs] with x hx + have hx' : x ∈ Ioc 0 (nextExponent r a) := ⟨lt_of_le_of_lt hell hx.1, hx.2⟩ + obtain ⟨t, ht, rfl⟩ := (exponent_image_Ici hr ha).symm.subset hx' + change V (U (inverseRatio r (nextExponent r t))) = nextExponent r t + rw [inverseRatio, HarmonicChangeOfVariable.inverse_exponent hr (ha.trans_le ht)] + exact hVU t ht + rw [Measure.map_map (f := fun x => U (inverseRatio r x)) hV (hU.comp (inverseRatio_measurable r))] + exact (Measure.map_congr hEq).trans Measure.map_id + +theorem admitted_even_exponent_marginal (v T : ℝ) (s : EvenState) {ell : ℝ} (hell : 0 ≤ ell) : + (admittedHarmonic v ell (.inl s, T)).map (currentExponent v) = + ErdosPrimeInputs.HarmonicPrefixKernel.kernel ell (currentExponent v (.inl s, T)) := by + rw [admitted_even_exponent_row v T s hell, ErdosPrimeInputs.HarmonicPrefixKernel.kernel_eq_restrict] + have h := inverse_update_marginal (Real.exp_pos (v - T)) + (by linarith [s.2] : 0 < s.1 - 1) hell (evenUpdateReal T) (evenUpdateReal_measurable T) + (currentExponent v) (currentExponent_measurable v) (fun t ht => evenUpdate_exponent v T s ht) + simpa only [nextExponent, sub_add_cancel, currentExponent, RegeneratingInverseBands.gapValue, + stateRatio, Sum.elim_inl] using h + +theorem admitted_odd_exponent_marginal (v T : ℝ) (s : OddState) {ell : ℝ} (hell : 0 ≤ ell) : + (admittedHarmonic v ell (.inr s, T)).map (currentExponent v) = + ErdosPrimeInputs.HarmonicPrefixKernel.kernel ell + (nextExponent (Real.exp (v - T)) (max 2 (s.1 - 1))) := by + rw [admitted_odd_exponent_row v T s hell, ErdosPrimeInputs.HarmonicPrefixKernel.kernel_eq_restrict] + exact inverse_update_marginal (Real.exp_pos (v - T)) + (lt_of_lt_of_le (by norm_num : (0 : ℝ) < 2) (le_max_left _ _)) hell + (oddUpdateReal T) (oddUpdateReal_measurable T) (currentExponent v) (currentExponent_measurable v) + (fun t ht => oddUpdate_exponent v T s ht) + +theorem harmonic_cutoff_mono (ell : ℝ) {a b : ℝ} (hab : a ≤ b) : + ErdosPrimeInputs.HarmonicPrefixKernel.kernel ell a ≤ + ErdosPrimeInputs.HarmonicPrefixKernel.kernel ell b := by + rw [ErdosPrimeInputs.HarmonicPrefixKernel.kernel_eq_restrict, + ErdosPrimeInputs.HarmonicPrefixKernel.kernel_eq_restrict, + ← withDensity_indicator measurableSet_Ioc, ← withDensity_indicator measurableSet_Ioc] + apply withDensity_mono + apply Filter.Eventually.of_forall + intro x + by_cases hx : x ∈ Ioc ell a + · have hx' : x ∈ Ioc ell b := ⟨hx.1, hx.2.trans hab⟩ + rw [indicator_of_mem hx, indicator_of_mem hx'] + · rw [indicator_of_notMem hx] + exact zero_le + +theorem admitted_exponent_marginal_le (v : ℝ) {ell : ℝ} (hell : 0 ≤ ell) (z : CostState) : + (admittedHarmonic v ell z).map (currentExponent v) ≤ + ErdosPrimeInputs.HarmonicPrefixKernel.kernel ell (currentExponent v z) := by + rcases z with ⟨s, T⟩ + cases s with + | inl s => exact (admitted_even_exponent_marginal v T s hell).le + | inr s => + rw [admitted_odd_exponent_marginal v T s hell] + apply harmonic_cutoff_mono + exact exponent_le_cutoff (i := .odd) (s := s.1) s.2 le_rfl (Real.exp_pos (v - T)) + +end NumberTheoryLean.AdmittedExponentMarginal + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/AlignedCofactorSplit.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AlignedCofactorSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..19d5451840a4d42bf6386b7bbd6d6ec1b1a3e6ed --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AlignedCofactorSplit.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceLabelCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosInverseAlignment ErdosPrimitiveIntercept ErdosInverseCells +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def alignedPrimeFactors (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) : Finset ℕ := + qf.primeFactors.filter (aligns a r) + +noncomputable def alignedPrimeProduct (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) : ℕ := + ∏ p ∈ alignedPrimeFactors a r qf,p + +noncomputable def alignedCofactor (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) : ℕ := + qf/badPrimeProduct a r qf + +theorem badPrimeProduct_pos (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) : 0 < badPrimeProduct a r qf := + Finset.prod_pos (fun _p hp => (Nat.prime_of_mem_primeFactors (Finset.mem_filter.mp hp).1).pos) + +theorem alignedPrimeProduct_pos (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) : 0 < alignedPrimeProduct a r qf := + Finset.prod_pos (fun _p hp => (Nat.prime_of_mem_primeFactors (Finset.mem_filter.mp hp).1).pos) + +theorem aligned_bad_product (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + alignedPrimeProduct a r qf*badPrimeProduct a r qf = qf := by + rw [alignedPrimeProduct,alignedPrimeFactors,badPrimeProduct,badPrimeFactors, + Finset.prod_filter_mul_prod_filter_not,Nat.prod_primeFactors_of_squarefree hq] + +theorem alignedCofactor_eq_product (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + alignedCofactor a r qf = alignedPrimeProduct a r qf := by + unfold alignedCofactor + nth_rw 1 [← aligned_bad_product a r qf hq] + exact Nat.mul_div_cancel _ (badPrimeProduct_pos a r qf) + +theorem alignedCofactor_pos (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + 0 < alignedCofactor a r qf := by + rw [alignedCofactor_eq_product a r qf hq] + exact alignedPrimeProduct_pos a r qf + +theorem alignedCofactor_mul_bad (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + alignedCofactor a r qf*badPrimeProduct a r qf = qf := by + rw [alignedCofactor_eq_product a r qf hq] + exact aligned_bad_product a r qf hq + +theorem alignedCofactor_coprime_den (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (alignedCofactor a r qf).Coprime r.den := by + rw [alignedCofactor_eq_product a r qf hq] + apply Nat.coprime_prod_left_iff.mpr + intro p hp + obtain ⟨hpf,halign⟩ := Finset.mem_filter.mp hp + have hprime := Nat.prime_of_mem_primeFactors hpf + exact hprime.coprime_iff_not_dvd.mpr (aligned_prime_not_dvd_den a r hprime halign) + +theorem alignedCofactor_coprime_bad (a : ℕ → ℤ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (alignedCofactor a r qf).Coprime (badPrimeProduct a r qf) := by + rw [alignedCofactor_eq_product a r qf hq] + apply Nat.coprime_prod_left_iff.mpr + intro p hp + obtain ⟨hpf,halign⟩ := Finset.mem_filter.mp hp + apply Nat.coprime_prod_right_iff.mpr + intro u hu + obtain ⟨huf,hnon⟩ := Finset.mem_filter.mp hu + apply (Nat.coprime_primes (Nat.prime_of_mem_primeFactors hpf) (Nat.prime_of_mem_primeFactors huf)).mpr + intro he + subst u + exact hnon halign + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/AlignedPrimeCongruence.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AlignedPrimeCongruence.lean new file mode 100644 index 0000000000000000000000000000000000000000..399c4f78599f418102e15e174a4121c990d01a5b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AlignedPrimeCongruence.lean @@ -0,0 +1,513 @@ +import Mathlib +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Mathlib.Algebra.BigOperators.Ring.Finset +import Mathlib.Algebra.Order.BigOperators.Group.Finset +import Mathlib.Data.Finset.Max +import Mathlib.Order.Interval.Finset.Nat +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.NormNum +import OAI.NumberTheory.Jacobsthal.Estimates.FactorDividesAbscissa +import OAI.NumberTheory.Jacobsthal.Primes.PrimeHitRepresentative + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.SievePartition + +open scoped BigOperators + +variable {α ι : Type*} [DecidableEq α] [LinearOrder ι] + +noncomputable def survivors (C : Finset α) (P : Finset ι) + (bad : ι → α → Prop) : Finset α := by + classical + exact C.filter fun x => ∀ p ∈ P, ¬ bad p x + +noncomputable def childCell (C : Finset α) (P : Finset ι) + (bad : ι → α → Prop) (p : ι) : Finset α := by + classical + exact C.filter fun x => bad p x ∧ ∀ q ∈ P, q < p → ¬ bad q x + +omit [DecidableEq α] [LinearOrder ι] in +@[simp] theorem mem_survivors {C : Finset α} {P : Finset ι} + {bad : ι → α → Prop} {x : α} : + x ∈ survivors C P bad ↔ x ∈ C ∧ ∀ p ∈ P, ¬ bad p x := by + classical + simp [survivors] + +omit [DecidableEq α] in +@[simp] theorem mem_childCell {C : Finset α} {P : Finset ι} + {bad : ι → α → Prop} {p : ι} {x : α} : + x ∈ childCell C P bad p ↔ + x ∈ C ∧ bad p x ∧ ∀ q ∈ P, q < p → ¬ bad q x := by + classical + simp [childCell] + +omit [DecidableEq α] in + +theorem exists_childCell {C : Finset α} {P : Finset ι} + {bad : ι → α → Prop} {x : α} + (hx : x ∈ C) (hnot : x ∉ survivors C P bad) : + ∃ p ∈ P, x ∈ childCell C P bad p := by + classical + have hbad : ∃ p ∈ P, bad p x := by + by_contra h + exact hnot (mem_survivors.mpr ⟨hx, fun p hp hpx => h ⟨p, hp, hpx⟩⟩) + let B := P.filter fun p => bad p x + have hB : B.Nonempty := by + obtain ⟨p, hp, hpx⟩ := hbad + exact ⟨p, Finset.mem_filter.mpr ⟨hp, hpx⟩⟩ + let p := B.min' hB + have hpB : p ∈ B := Finset.min'_mem B hB + obtain ⟨hpP, hpx⟩ := Finset.mem_filter.mp hpB + refine ⟨p, hpP, mem_childCell.mpr ⟨hx, hpx, ?_⟩⟩ + intro q hqP hqp hqx + have hqB : q ∈ B := Finset.mem_filter.mpr ⟨hqP, hqx⟩ + exact (not_lt_of_ge (Finset.min'_le B q hqB)) hqp + +omit [DecidableEq α] in + +theorem childCell_disjoint {C : Finset α} {P : Finset ι} + {bad : ι → α → Prop} {p q : ι} + (hp : p ∈ P) (hq : q ∈ P) (hne : p ≠ q) : + Disjoint (childCell C P bad p) (childCell C P bad q) := by + classical + apply Finset.disjoint_left.mpr + intro x hxp hxq + obtain ⟨_, hpx, hpmin⟩ := mem_childCell.mp hxp + obtain ⟨_, hqx, hqmin⟩ := mem_childCell.mp hxq + rcases lt_or_gt_of_ne hne with hpq | hqp + · exact hqmin p hp hpq hpx + · exact hpmin q hq hqp hqx + +theorem biUnion_childCell (C : Finset α) (P : Finset ι) + (bad : ι → α → Prop) : + P.biUnion (childCell C P bad) = C \ survivors C P bad := by + classical + ext x + constructor + · intro hx + obtain ⟨p, hp, hxp⟩ := Finset.mem_biUnion.mp hx + obtain ⟨hxC, hpx, _⟩ := mem_childCell.mp hxp + exact Finset.mem_sdiff.mpr ⟨hxC, + fun hxs => (mem_survivors.mp hxs).2 p hp hpx⟩ + · intro hx + obtain ⟨hxC, hxnot⟩ := Finset.mem_sdiff.mp hx + exact Finset.mem_biUnion.mpr (exists_childCell hxC hxnot) + +theorem sum_card_childCell (C : Finset α) (P : Finset ι) + (bad : ι → α → Prop) : + ∑ p ∈ P, (childCell C P bad p).card = (C \ survivors C P bad).card := by + classical + rw [← biUnion_childCell C P bad] + symm + exact Finset.card_biUnion fun p hp q hq hne => childCell_disjoint hp hq hne + +theorem card_survivors_add_sum (C : Finset α) (P : Finset ι) + (bad : ι → α → Prop) : + (survivors C P bad).card + ∑ p ∈ P, (childCell C P bad p).card = C.card := by + rw [sum_card_childCell, Nat.add_comm] + exact Finset.card_sdiff_add_card_eq_card fun _ hx => (mem_survivors.mp hx).1 + +theorem card_survivors_eq_sub_sum (C : Finset α) (P : Finset ι) + (bad : ι → α → Prop) : + ((survivors C P bad).card : ℤ) = + (C.card : ℤ) - ∑ p ∈ P, ((childCell C P bad p).card : ℤ) := by + have h : ((survivors C P bad).card : ℤ) + + ∑ p ∈ P, ((childCell C P bad p).card : ℤ) = (C.card : ℤ) := by + exact_mod_cast card_survivors_add_sum C P bad + linarith + +def residueBad (a : ℕ → ℕ) (p n : ℕ) : Prop := n % p = a p % p + +instance decidableResidueBad (a : ℕ → ℕ) (p n : ℕ) : Decidable (residueBad a p n) := + inferInstanceAs (Decidable (n % p = a p % p)) + +noncomputable def residueCandidates (Y : ℕ) (H small : Finset ℕ) + (a : ℕ → ℕ) : Finset ℕ := by + classical + exact (Finset.Icc 1 Y).filter fun n => + (∀ p ∈ H, residueBad a p n) ∧ ∀ q ∈ small, ¬ residueBad a q n + +@[simp] theorem mem_residueCandidates {Y : ℕ} {H small : Finset ℕ} + {a : ℕ → ℕ} {n : ℕ} : + n ∈ residueCandidates Y H small a ↔ + 1 ≤ n ∧ n ≤ Y ∧ + (∀ p ∈ H, residueBad a p n) ∧ ∀ q ∈ small, ¬ residueBad a q n := by + classical + simp only [residueCandidates, Finset.mem_filter, Finset.mem_Icc] + tauto + +theorem residueCandidates_insert (Y : ℕ) (H small : Finset ℕ) + (a : ℕ → ℕ) (p : ℕ) : + residueCandidates Y (insert p H) small a = + (residueCandidates Y H small a).filter (residueBad a p) := by + classical + ext n + simp only [mem_residueCandidates, Finset.mem_filter, Finset.mem_insert, + forall_eq_or_imp] + tauto + +theorem residue_childCell_eq (Y : ℕ) (H small P : Finset ℕ) + (a : ℕ → ℕ) (p : ℕ) : + childCell (residueCandidates Y H small a) P (residueBad a) p = + survivors (residueCandidates Y (insert p H) small a) + (P.filter fun q => q < p) (residueBad a) := by + classical + rw [residueCandidates_insert] + ext n + simp only [mem_childCell, mem_survivors, Finset.mem_filter] + constructor + · rintro ⟨hn, hpn, hleast⟩ + exact ⟨⟨hn, hpn⟩, fun q hq => hleast q hq.1 hq.2⟩ + · rintro ⟨⟨hn, hpn⟩, hleast⟩ + exact ⟨hn, hpn, fun q hq hqp => hleast q ⟨hq, hqp⟩⟩ + +theorem residue_tree_identity (Y : ℕ) (H small P : Finset ℕ) (a : ℕ → ℕ) : + ((survivors (residueCandidates Y H small a) P (residueBad a)).card : ℤ) = + ((residueCandidates Y H small a).card : ℤ) - + ∑ p ∈ P, + ((survivors (residueCandidates Y (insert p H) small a) + (P.filter fun q => q < p) (residueBad a)).card : ℤ) := by + classical + simpa only [residue_childCell_eq] using + card_survivors_eq_sub_sum (residueCandidates Y H small a) P (residueBad a) + +end NumberTheoryLean.SievePartition + +end + +section + +namespace NumberTheoryLean.SieveTree + +open scoped BigOperators + +variable {V : Type*} [DecidableEq V] + +structure Data (V : Type*) [DecidableEq V] where + children : V → Finset V + retained : V → Finset V + retained_subset : ∀ v, retained v ⊆ children v + mass : V → ℤ + survivors : V → ℤ + survivors_nonneg : ∀ v, 0 ≤ survivors v + partition : ∀ v, survivors v = mass v - ∑ w ∈ children v, survivors w + stopLower : V → Bool + +def bounds (D : Data V) : ℕ → V → ℤ × ℤ + | 0, v => (D.survivors v, D.mass v) + | n + 1, v => + (if D.stopLower v then D.survivors v + else D.mass v - ∑ w ∈ D.children v, (bounds D n w).2, + D.mass v - ∑ w ∈ D.retained v, (bounds D n w).1) + +theorem survivors_le_mass (D : Data V) (v : V) : + D.survivors v ≤ D.mass v := by + have hsum : 0 ≤ ∑ w ∈ D.children v, D.survivors w := + Finset.sum_nonneg fun w _ => D.survivors_nonneg w + have hid := D.partition v + linarith + +theorem bounds_correct (D : Data V) (n : ℕ) (v : V) : + (bounds D n v).1 ≤ D.survivors v ∧ + D.survivors v ≤ (bounds D n v).2 := by + induction n generalizing v with + | zero => + exact ⟨le_refl _, survivors_le_mass D v⟩ + | succ n ih => + have hAll : (∑ w ∈ D.children v, D.survivors w) ≤ + ∑ w ∈ D.children v, (bounds D n w).2 := + Finset.sum_le_sum fun w _ => (ih w).2 + have hKept : (∑ w ∈ D.retained v, (bounds D n w).1) ≤ + ∑ w ∈ D.retained v, D.survivors w := + Finset.sum_le_sum fun w _ => (ih w).1 + have hSubset : (∑ w ∈ D.retained v, D.survivors w) ≤ + ∑ w ∈ D.children v, D.survivors w := + Finset.sum_le_sum_of_subset_of_nonneg (D.retained_subset v) + (fun w _ _ => D.survivors_nonneg w) + have hid := D.partition v + constructor + · simp only [bounds] + split + · exact le_refl _ + · linarith + · simp only [bounds] + linarith + +theorem stopped_tree_lower_bound (D : Data V) (depth : ℕ) (root : V) : + (bounds D depth root).1 ≤ D.survivors root := + (bounds_correct D depth root).1 + +theorem exact_lower_stop (D : Data V) (n : ℕ) (v : V) + (h : D.stopLower v = true) : + (bounds D (n + 1) v).1 = D.survivors v := by + simp [bounds, h] + +theorem leaf_mass_eq (D : Data V) (v : V) (h : D.children v = ∅) : + D.mass v = D.survivors v := by + simpa [h] using (D.partition v).symm + +end NumberTheoryLean.SieveTree + +end + +section + +namespace NumberTheoryLean.ResidueSieveTree + +open scoped BigOperators +open SievePartition + +abbrev Vertex := Finset ℕ × Finset ℕ + +def child (v : Vertex) (p : ℕ) : Vertex := + (insert p v.1, v.2.filter fun q => q < p) + +def children (v : Vertex) : Finset Vertex := v.2.image (child v) + +noncomputable def retained (admissible : Vertex → ℕ → Prop) (v : Vertex) : Finset Vertex := by + classical + exact (v.2.filter (admissible v)).image (child v) + +theorem retained_subset (admissible : Vertex → ℕ → Prop) (v : Vertex) : + retained admissible v ⊆ children v := by + classical + exact Finset.image_subset_image (Finset.filter_subset _ _) + +theorem child_injOn (v : Vertex) : Set.InjOn (child v) (v.2 : Set ℕ) := by + intro p hp q hq heq + have hsets := congrArg Prod.snd heq + change v.2.filter (fun r => r < p) = v.2.filter (fun r => r < q) at hsets + by_contra hne + rcases lt_or_gt_of_ne hne with hpq | hqp + · have hm : p ∈ v.2.filter (fun r => r < q) := Finset.mem_filter.mpr ⟨hp, hpq⟩ + rw [← hsets] at hm + exact (lt_irrefl p) (Finset.mem_filter.mp hm).2 + · have hm : q ∈ v.2.filter (fun r => r < p) := Finset.mem_filter.mpr ⟨hq, hqp⟩ + rw [hsets] at hm + exact (lt_irrefl q) (Finset.mem_filter.mp hm).2 + +theorem child_card_lt (v : Vertex) {p : ℕ} (hp : p ∈ v.2) : + (child v p).2.card < v.2.card := by + apply Finset.card_lt_card + exact Finset.filter_ssubset.mpr ⟨p, hp, lt_irrefl p⟩ + +noncomputable def mass (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : ℤ := + (residueCandidates Y v.1 small a).card + +noncomputable def survivorCount (Y : ℕ) (small : Finset ℕ) + (a : ℕ → ℕ) (v : Vertex) : ℤ := + (survivors (residueCandidates Y v.1 small a) v.2 (residueBad a)).card + +theorem survivorCount_nonneg (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : + 0 ≤ survivorCount Y small a v := Int.natCast_nonneg _ + +theorem partition (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : + survivorCount Y small a v = mass Y small a v - + ∑ w ∈ children v, survivorCount Y small a w := by + classical + rw [children, Finset.sum_image (child_injOn v)] + exact residue_tree_identity Y v.1 small v.2 a + +noncomputable def data (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (admissible : Vertex → ℕ → Prop) (stop : Vertex → Bool) : SieveTree.Data Vertex where + children := children + retained := retained admissible + retained_subset := retained_subset admissible + mass := mass Y small a + survivors := survivorCount Y small a + survivors_nonneg := survivorCount_nonneg Y small a + partition := partition Y small a + stopLower := stop + +theorem bounds_correct (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (admissible : Vertex → ℕ → Prop) (stop : Vertex → Bool) (depth : ℕ) (v : Vertex) : + (SieveTree.bounds (data Y small a admissible stop) depth v).1 ≤ + survivorCount Y small a v ∧ + survivorCount Y small a v ≤ + (SieveTree.bounds (data Y small a admissible stop) depth v).2 := + SieveTree.bounds_correct (data Y small a admissible stop) depth v + +theorem stopped_tree_lower_bound (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (admissible : Vertex → ℕ → Prop) (stop : Vertex → Bool) (depth : ℕ) (v : Vertex) : + (SieveTree.bounds (data Y small a admissible stop) depth v).1 ≤ + ((survivors (residueCandidates Y v.1 small a) v.2 (residueBad a)).card : ℤ) := + (bounds_correct Y small a admissible stop depth v).1 + +theorem bounds_succ_eq_of_card_le (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (admissible : Vertex → ℕ → Prop) (stop : Vertex → Bool) (depth : ℕ) (v : Vertex) + (hdepth : v.2.card ≤ depth) : + SieveTree.bounds (data Y small a admissible stop) (depth + 1) v = + SieveTree.bounds (data Y small a admissible stop) depth v := by + classical + let D := data Y small a admissible stop + change SieveTree.bounds D (depth + 1) v = SieveTree.bounds D depth v + induction depth generalizing v with + | zero => + have hP : v.2 = ∅ := Finset.card_eq_zero.mp (Nat.eq_zero_of_le_zero hdepth) + have hc : children v = ∅ := by simp [children, hP] + have hr : retained admissible v = ∅ := by + apply Finset.subset_empty.mp + simpa only [hc] using retained_subset admissible v + have hS : survivorCount Y small a v = mass Y small a v := by + simpa only [hc, Finset.sum_empty, sub_zero] using partition Y small a v + simp [SieveTree.bounds, D, data, hc, hr, hS] + | succ depth ih => + have hchild : ∀ w ∈ D.children v, + SieveTree.bounds D (depth + 1) w = SieveTree.bounds D depth w := by + intro w hw + obtain ⟨p, hp, rfl⟩ := Finset.mem_image.mp hw + apply ih + have hlt := child_card_lt v hp + omega + have hupper : (∑ w ∈ D.children v, (SieveTree.bounds D (depth + 1) w).2) = + ∑ w ∈ D.children v, (SieveTree.bounds D depth w).2 := by + apply Finset.sum_congr rfl + intro w hw + exact congrArg Prod.snd (hchild w hw) + have hlower : (∑ w ∈ D.retained v, (SieveTree.bounds D (depth + 1) w).1) = + ∑ w ∈ D.retained v, (SieveTree.bounds D depth w).1 := by + apply Finset.sum_congr rfl + intro w hw + exact congrArg Prod.fst (hchild w (D.retained_subset v hw)) + conv_lhs => rw [SieveTree.bounds] + conv_rhs => rw [SieveTree.bounds] + rw [hupper, hlower] + +theorem bounds_stabilize (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (admissible : Vertex → ℕ → Prop) (stop : Vertex → Bool) (v : Vertex) (extra : ℕ) : + SieveTree.bounds (data Y small a admissible stop) (v.2.card + extra) v = + SieveTree.bounds (data Y small a admissible stop) v.2.card v := by + induction extra with + | zero => rfl + | succ extra ih => + rw [Nat.add_succ, bounds_succ_eq_of_card_le Y small a admissible stop + (v.2.card + extra) v (Nat.le_add_right _ _)] + exact ih + +end NumberTheoryLean.ResidueSieveTree + +end + +section + +namespace ErdosInverseCounts +open NumberTheoryLean NumberTheoryLean.SievePartition + +noncomputable def modulusCandidates (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (m : ℕ) : Finset ℕ := + residueCandidates Y m.primeFactors small a + +noncomputable def modulusCount (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (m : ℕ) : ℤ := + (modulusCandidates Y small a m).card + +theorem mem_modulusCandidates (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (m n : ℕ) : + n ∈ modulusCandidates Y small a m ↔ 1 ≤ n ∧ n ≤ Y ∧ + (∀ p ∈ m.primeFactors,n % p = a p % p) ∧ ∀ p ∈ small,n % p ≠ a p % p := by + exact mem_residueCandidates + +theorem modulusCount_eq_mass (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (m : ℕ) (P : Finset ℕ) : + modulusCount Y small a m = ResidueSieveTree.mass Y small a (m.primeFactors,P) := rfl + +theorem modulusCount_nonneg (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (m : ℕ) : + 0 ≤ modulusCount Y small a m := Int.natCast_nonneg _ + +theorem modulusCandidates_prime_mul (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (p m : ℕ) (hp : Nat.Prime p) (hm : m ≠ 0) : + modulusCandidates Y small a (p*m) = (modulusCandidates Y small a m).filter (residueBad a p) := by + classical + unfold modulusCandidates + rw [Nat.primeFactors_mul hp.ne_zero hm,hp.primeFactors,Finset.singleton_union] + exact residueCandidates_insert Y m.primeFactors small a p + +theorem primeFactors_product (H : Finset ℕ) (hH : ∀ p ∈ H,Nat.Prime p) : + (∏ p ∈ H,p).primeFactors = H := by + classical + revert hH + induction H using Finset.induction_on with + | empty => intro _;simp + | @insert p H hp ih => + intro hH + have hprime := hH p (Finset.mem_insert_self _ _) + have hrest : ∀ q ∈ H,Nat.Prime q := fun q hq => hH q (Finset.mem_insert_of_mem hq) + have hprod : (∏ q ∈ H,q) ≠ 0 := Finset.prod_ne_zero_iff.mpr (fun q hq => (hrest q hq).ne_zero) + rw [Finset.prod_insert hp,Nat.primeFactors_mul hprime.ne_zero hprod,hprime.primeFactors, + ih hrest,Finset.singleton_union] + +theorem modulusCount_product_eq_mass (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (H P : Finset ℕ) (hH : ∀ p ∈ H,Nat.Prime p) : + modulusCount Y small a (∏ p ∈ H,p) = ResidueSieveTree.mass Y small a (H,P) := by + rw [modulusCount_eq_mass Y small a _ P,primeFactors_product H hH] + +end ErdosInverseCounts + +end + +section + +namespace ErdosAlignedProgression +open ErdosInverseAlignment ErdosInverseHits ErdosInverseCounts + +theorem aligned_den_coprime_prime (a : ℕ → ℕ) (r : ℚ) (p : ℕ) (hp : p.Prime) + (ha : aligns (fun s => (a s : ℤ)) r p) : r.den.Coprime p := + (hp.coprime_iff_not_dvd.mpr (aligned_prime_not_dvd_den _ r hp ha)).symm + +theorem aligned_den_coprime (a : ℕ → ℕ) (r : ℚ) (d : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) : r.den.Coprime d := by + rw [← Nat.prod_primeFactors_of_squarefree hd] + exact Nat.Coprime.prod_right (fun p hp => aligned_den_coprime_prime a r p + (Nat.prime_of_mem_primeFactors hp) (ha p hp)) + +theorem aligned_prime_hit_iff (a : ℕ → ℕ) (r : ℚ) (p t : ℕ) (hp : p.Prime) + (ha : aligns (fun s => (a s : ℤ)) r p) : + t % p = a p % p ↔ Int.ModEq (p : ℤ) ((r.den : ℤ)*(t : ℤ)) r.num := by + let : Fact p.Prime := ⟨hp⟩ + have hD : (r.den : ZMod p) ≠ 0 := by + intro h + exact aligned_prime_not_dvd_den _ r hp ha ((ZMod.natCast_eq_zero_iff _ _).mp h) + change Nat.ModEq p t (a p) ↔ _ + rw [← ZMod.natCast_eq_natCast_iff, ← ZMod.intCast_eq_intCast_iff] + simp only [Int.cast_mul, Int.cast_natCast] + change (t : ZMod p) = (a p : ZMod p) ↔ (r.den : ZMod p)*(t : ZMod p) = (r.num : ZMod p) + have ha' : (r.den : ZMod p)*(a p : ZMod p) = (r.num : ZMod p) := by + simpa only [aligns, Int.cast_natCast] using ha + constructor + · intro ht + rw [ht] + exact ha' + · intro ht + exact mul_left_cancel₀ hD (ht.trans ha'.symm) + +theorem squarefree_int_modEq_iff (d : ℕ) (hd : Squarefree d) (x y : ℤ) : + Int.ModEq (d : ℤ) x y ↔ ∀ p ∈ d.primeFactors, Int.ModEq (p : ℤ) x y := by + simp only [Int.modEq_iff_dvd, Int.natCast_dvd] + have h := modEq_prime_product_iff d.primeFactors (fun p hp => Nat.prime_of_mem_primeFactors hp) + (y-x).natAbs 0 + rw [Nat.prod_primeFactors_of_squarefree hd] at h + simpa only [Nat.modEq_zero_iff_dvd] using h + +theorem required_hits_iff_parameter (a : ℕ → ℕ) (r : ℚ) (d t : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) : + (∀ p ∈ d.primeFactors, t % p = a p % p) ↔ + ∃ m : ℤ, (r.den : ℤ)*(t : ℤ) = r.num+(d : ℤ)*m := by + have hp : (∀ p ∈ d.primeFactors, t % p = a p % p) ↔ + ∀ p ∈ d.primeFactors, Int.ModEq (p : ℤ) ((r.den : ℤ)*(t : ℤ)) r.num := by + exact forall_congr' (fun p => forall_congr' (fun h => + aligned_prime_hit_iff a r p t (Nat.prime_of_mem_primeFactors h) (ha p h))) + rw [hp, ← squarefree_int_modEq_iff d hd, Int.modEq_comm, Int.modEq_iff_dvd] + constructor + · rintro ⟨m, hm⟩ + exact ⟨m, by linarith⟩ + · rintro ⟨m, hm⟩ + exact ⟨m, by linarith⟩ + +end ErdosAlignedProgression + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/AugmentedCRTCell.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AugmentedCRTCell.lean new file mode 100644 index 0000000000000000000000000000000000000000..3833323533f94e22c61d25e47a45f25c4f789def --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/AugmentedCRTCell.lean @@ -0,0 +1,85 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.RealCoprimeResidueCount + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +def augmentedModuli {ι : Type*} (M0 : ℕ) (u : ι → ℕ) : Option ι → ℕ + | none => M0 + | some i => u i + +noncomputable def cellResidues {ι : Type*} (M0 : ℕ) (u : ι → ℕ) (v : ZMod M0) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) (E : ∀ i,Finset (ZMod (u i))) : + ∀ j : Option ι,Finset (ZMod (augmentedModuli M0 u j)) + | none => {v} + | some i => affineResidues (c i) (b i) (E i) + +theorem augmented_coprime {ι : Type*} (M0 : ℕ) (u : ι → ℕ) + (h0 : ∀ i,Nat.Coprime M0 (u i)) (hu : Pairwise (fun i j => Nat.Coprime (u i) (u j))) : + Pairwise (fun i j => Nat.Coprime (augmentedModuli M0 u i) (augmentedModuli M0 u j)) := by + rintro (_|i) (_|j) hne + · exact False.elim (hne rfl) + · exact h0 j + · exact (h0 i).symm + · exact hu (fun h => hne (congrArg Option.some h)) + +theorem augmented_product {ι : Type*} [Fintype ι] (M0 : ℕ) (u : ι → ℕ) : + (∏ j : Option ι,augmentedModuli M0 u j) = M0*∏ i,u i := by + simp only [Fintype.prod_option,augmentedModuli] + +theorem cell_card_product {ι : Type*} [Fintype ι] (M0 : ℕ) (u : ι → ℕ) (v : ZMod M0) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) (E : ∀ i,Finset (ZMod (u i))) : + (∏ j : Option ι,(cellResidues M0 u v c b E j).card) = ∏ i,(E i).card := by + rw [Fintype.prod_option] + have hbase : (cellResidues M0 u v c b E none).card = 1 := Finset.card_singleton v + rw [hbase,one_mul] + apply Finset.prod_congr rfl + intro i hi + exact affineResidues_card (c i) (b i) (E i) + +noncomputable def slopeCell {ι : Type*} [Fintype ι] (p M0 : ℕ) (u : ι → ℕ) (v : ZMod M0) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) (E : ∀ i,Finset (ZMod (u i))) : Finset ℤ := + (Finset.Ico (0 : ℤ) (p : ℤ)).filter (fun s => (s : ZMod M0) = v ∧ ∀ i,(c i : ZMod (u i))*(s : ZMod (u i))+b i ∈ E i) + +theorem slopeCell_eq_crtSlopes {ι : Type*} [Fintype ι] (p M0 : ℕ) (u : ι → ℕ) (v : ZMod M0) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) (E : ∀ i,Finset (ZMod (u i))) : + slopeCell p M0 u v c b E = crtSlopes 0 p (augmentedModuli M0 u) (cellResidues M0 u v c b E) := by + ext s + simp only [slopeCell,crtSlopes,Finset.mem_filter] + apply and_congr_right + intro _hs + constructor + · rintro ⟨hv,hE⟩ j + cases j with + | none => exact Finset.mem_singleton.mpr hv + | some i => exact (mem_affineResidues (c i) (b i) (E i) (s : ZMod (u i))).mpr (hE i) + · intro h + exact ⟨Finset.mem_singleton.mp (h none),fun i => (mem_affineResidues (c i) (b i) (E i) (s : ZMod (u i))).mp (h (some i))⟩ + +theorem slopeCell_card_upper {ι : Type*} [Fintype ι] (p M0 : ℕ) (u : ι → ℕ) (v : ZMod M0) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) (E : ∀ i,Finset (ZMod (u i))) + (hM : 0 < M0) (hU : ∀ i,0 < u i) (h0 : ∀ i,Nat.Coprime M0 (u i)) + (hu : Pairwise (fun i j => Nat.Coprime (u i) (u j))) : + ((slopeCell p M0 u v c b E).card : ℝ) ≤ + (p : ℝ)*((∏ i,(E i).card : ℕ) : ℝ)/(M0*(∏ i,u i) : ℕ)+((∏ i,(E i).card : ℕ) : ℝ) := by + have hN : 0 < ∏ j : Option ι,augmentedModuli M0 u j := by + rw [augmented_product] + exact Nat.mul_pos hM (Finset.prod_pos (fun i _ => hU i)) + have hh := crt_initial_count_upper p (augmentedModuli M0 u) (augmented_coprime M0 u h0 hu) + (cellResidues M0 u v c b E) hN + rw [← slopeCell_eq_crtSlopes,augmented_product,cell_card_product] at hh + exact hh + +end ErdosInverseCRT + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/BoxWitnessFactorization.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/BoxWitnessFactorization.lean new file mode 100644 index 0000000000000000000000000000000000000000..61f489c805435e7fbef5ac0cd56ab2ed524e816b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/BoxWitnessFactorization.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.HarmonicConditioning +import OAI.NumberTheory.Jacobsthal.Partitions.ActualBoxFourSum + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.BoxWitnessFactorization +open ErdosCofactorChoices ErdosInverseCells ErdosInverseSampling +open TwoPrimeObservableSum ParentTailPartition ParentCofactorChoices BinCutSelections FourCoordinateBoxSum CanonicalSubsetBox + +attribute [local instance] Classical.propDecidable + +noncomputable def selectionWitnessMass {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i j : Fin n) (W : (ℕ × ℕ) → ℕ → Prop) : ℝ := + ∑ f ∈ (selections P m).filter (fun f => W (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j)), + (selectionProduct f:ℝ)⁻¹ + +theorem witness_three_sum (P Q U : Finset ℕ) (W : (ℕ × ℕ) → ℕ → Prop) : + weightedWitness P Q U W=∑ p ∈ P,∑ u ∈ U,∑ q ∈ Q, + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹)*(if W (p,q) u then 1 else 0) := by + unfold weightedWitness witnessPairs + simp only [Finset.sum_filter,Finset.product_eq_sprod,Finset.sum_product,tripleWeight] + apply Finset.sum_congr rfl + intro p _hp + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro u _hu + apply Finset.sum_congr rfl + intro q _hq + split_ifs <;> ring + +theorem four_sum_descendants (P Q U D : Finset ℕ) (G : ℕ → ℕ → ℕ → ℝ) : + (∑ p ∈ P,∑ u ∈ U,∑ q ∈ Q,∑ d ∈ D, + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹*(d:ℝ)⁻¹)*G p q u)= + harmonicMass D*(∑ p ∈ P,∑ u ∈ U,∑ q ∈ Q,((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹)*G p q u) := by + have hh : ∀ p u q : ℕ,(∑ d ∈ D,((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹*(d:ℝ)⁻¹)*G p q u)= + harmonicMass D*(((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹)*G p q u) := by + intro p u q + rw [harmonicMass,Finset.sum_mul] + apply Finset.sum_congr rfl + intro d _hd + ring + simp_rw [hh] + simp only [← Finset.mul_sum] + +theorem selection_witness_factor {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hP : ∀ i,∀ p ∈ P i,p.Prime) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (i j : Fin n) (hji : j < i) (hi : m i=1) (hj : m j=1) (W : (ℕ × ℕ) → ℕ → Prop) : + selectionWitnessMass P m i j W= + harmonicMass (cofactorChoices P (belowMultiplicity m j))* + weightedWitness (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j) W := by + have hh := four_coordinate_sum P m hP hd i j hji hi hj (fun p u q _d => if W (p,q) u then (1:ℝ) else 0) + have he : selectionWitnessMass P m i j W= + ∑ f ∈ selections P m,(selectionProduct f:ℝ)⁻¹* + (if W (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j) then 1 else 0) := by + simp only [selectionWitnessMass,Finset.sum_filter,mul_ite,mul_one,mul_zero] + rw [he,hh,four_sum_descendants,witness_three_sum] + +theorem full_box_mass_factor {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hP : ∀ i,∀ p ∈ P i,p.Prime) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (i j : Fin n) (hji : j < i) (hi : m i=1) (hj : m j=1) : + selectionMass P m=harmonicMass (cofactorChoices P (belowMultiplicity m j))* + (harmonicMass (P i)*harmonicMass (cofactorChoices P (parentCofactorMultiplicity m i j))*harmonicMass (P j)) := by + have hh := selection_witness_factor P m hP hd i j hji hi hj (fun _ _ => True) + have he : weightedWitness (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j) (fun _ _ => True)= + harmonicMass (P i)*harmonicMass (cofactorChoices P (parentCofactorMultiplicity m i j))*harmonicMass (P j) := by + unfold weightedWitness witnessPairs + simp only [Finset.filter_true_of_mem (fun _ _ => trivial)] + exact triple_weight_sum _ _ _ + simpa only [selectionWitnessMass,Finset.filter_true_of_mem (fun _ _ => trivial),selectionMass,he] using hh +end NumberTheoryLean.BoxWitnessFactorization + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/BuchstabBridge.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/BuchstabBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..927126b71635383adfe6bc2a00ab037f1ab7a428 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/BuchstabBridge.lean @@ -0,0 +1,1205 @@ +import Mathlib.Analysis.Calculus.MeanValue +import Mathlib.Analysis.Calculus.ParametricIntegral +import Mathlib.Analysis.SpecialFunctions.Gamma.Basic +import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals +import Mathlib.Analysis.SpecialFunctions.Integrals.Basic +import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.RoughRecursion +import OAI.NumberTheory.Jacobsthal.Renewal.LaplaceODE +import OAI.NumberTheory.Jacobsthal.Sieve.LinearSieveFunctions + +namespace OAI + +namespace Erdos970 + +section + +open scoped Interval +open MeasureTheory +open Filter + +namespace ErdosAverageCertificates + +noncomputable section + +noncomputable def buchstabStage : ℕ → ℝ → ℝ + | 0, _ => 1 + | n + 1, u => + if u ≤ 2 then 1 + else 1 + ∫ t in 1..u - 1, buchstabStage n t / t + +@[simp] theorem buchstabStage_zero (u : ℝ) : buchstabStage 0 u = 1 := rfl + +theorem buchstabStage_succ_eq_one {n : ℕ} {u : ℝ} (hu : u ≤ 2) : + buchstabStage (n + 1) u = 1 := by + simp [buchstabStage, hu] + +theorem buchstabStage_succ_eq_integral {n : ℕ} {u : ℝ} (hu : 2 < u) : + buchstabStage (n + 1) u = + 1 + ∫ t in 1..u - 1, buchstabStage n t / t := by + rw [buchstabStage, ite_eq_right (not_le_of_gt hu)] + +theorem buchstabStage_succ_eq_stage {n : ℕ} {u : ℝ} + (hu1 : 1 ≤ u) (hun : u ≤ n + 2) : + buchstabStage (n + 1) u = buchstabStage n u := by + induction n generalizing u with + | zero => + have hu2 : u ≤ 2 := by simpa using hun + simp [buchstabStage, hu2] + | succ n ih => + by_cases hu2 : u ≤ 2 + · simp [buchstabStage, hu2] + · have hu2' : 2 < u := lt_of_not_ge hu2 + rw [buchstabStage_succ_eq_integral hu2', + buchstabStage_succ_eq_integral hu2'] + congr 1 + apply intervalIntegral.integral_congr + intro t ht + have ht' : t ∈ Set.Icc (1 : ℝ) (u - 1) := by + simpa [Set.uIcc_of_le (by linarith : (1 : ℝ) ≤ u - 1)] using ht + have htupper : t ≤ n + 2 := by + norm_num at hun ⊢ + linarith [ht'.2] + change buchstabStage (n + 1) t / t = buchstabStage n t / t + rw [ih ht'.1 htupper] + +theorem buchstabStage_eq_of_le {m n : ℕ} {u : ℝ} + (hu1 : 1 ≤ u) (hum : u ≤ m + 2) (hmn : m ≤ n) : + buchstabStage n u = buchstabStage m u := by + induction n, hmn using Nat.le_induction with + | base => rfl + | succ n hmn ih => + have hun : u ≤ n + 2 := by + exact hum.trans (by exact_mod_cast Nat.add_le_add_right hmn 2) + rw [buchstabStage_succ_eq_stage hu1 hun, ih] + +noncomputable def buchstabAux (u : ℝ) : ℝ := + if u < 1 then 0 else buchstabStage ⌈u⌉₊ u + +noncomputable def buchstabFunction (u : ℝ) : ℝ := + if u < 1 then 0 else buchstabAux u / u + +theorem buchstabAux_eq_stage {n : ℕ} {u : ℝ} + (hu1 : 1 ≤ u) (hun : u ≤ n + 2) : + buchstabAux u = buchstabStage n u := by + rw [buchstabAux, ite_eq_right (not_lt_of_ge hu1)] + let k : ℕ := max ⌈u⌉₊ n + have huceil : u ≤ (⌈u⌉₊ : ℝ) + 2 := + (Nat.le_ceil u).trans (by norm_num) + have hceilk : ⌈u⌉₊ ≤ k := le_max_left _ _ + have hnk : n ≤ k := le_max_right _ _ + calc + buchstabStage ⌈u⌉₊ u = buchstabStage k u := + (buchstabStage_eq_of_le hu1 huceil hceilk).symm + _ = buchstabStage n u := buchstabStage_eq_of_le hu1 hun hnk + +theorem buchstabFunction_eq_aux_div {u : ℝ} (hu : 1 ≤ u) : + buchstabFunction u = buchstabAux u / u := by + rw [buchstabFunction, ite_eq_right (not_lt_of_ge hu)] + +theorem buchstabFunction_eq_stage_div {n : ℕ} {u : ℝ} + (hu1 : 1 ≤ u) (hun : u ≤ n + 2) : + buchstabFunction u = buchstabStage n u / u := by + rw [buchstabFunction_eq_aux_div hu1, buchstabAux_eq_stage hu1 hun] + +theorem buchstabAux_eq_one {u : ℝ} (hu1 : 1 ≤ u) (hu2 : u ≤ 2) : + buchstabAux u = 1 := by + simpa using buchstabAux_eq_stage (n := 0) hu1 (by simpa using hu2) + +theorem buchstabFunction_eq_inv {u : ℝ} (hu1 : 1 ≤ u) (hu2 : u ≤ 2) : + buchstabFunction u = u⁻¹ := by + rw [buchstabFunction_eq_aux_div hu1, buchstabAux_eq_one hu1 hu2] + exact one_div u + +theorem mul_buchstabFunction {u : ℝ} (hu : 1 ≤ u) : + u * buchstabFunction u = buchstabAux u := by + rw [buchstabFunction_eq_aux_div hu] + field_simp [show u ≠ 0 by linarith] + +theorem buchstabAux_eq_one_add_integral {u : ℝ} (hu : 2 < u) : + buchstabAux u = 1 + ∫ t in 1..u - 1, buchstabFunction t := by + let n : ℕ := ⌈u⌉₊ + have hu1 : 1 ≤ u := by linarith + have hun : u ≤ ((n + 1 : ℕ) : ℝ) + 2 := by + dsimp [n] + have hceil := Nat.le_ceil u + norm_num at hceil ⊢ + linarith + rw [buchstabAux_eq_stage hu1 hun, + buchstabStage_succ_eq_integral hu] + congr 1 + apply intervalIntegral.integral_congr + intro t ht + have ht' : t ∈ Set.Icc (1 : ℝ) (u - 1) := by + simpa [Set.uIcc_of_le (by linarith : (1 : ℝ) ≤ u - 1)] using ht + have htn : t ≤ (n : ℝ) + 2 := by + dsimp [n] + have hceil := Nat.le_ceil u + linarith [ht'.2] + change buchstabStage n t / t = buchstabFunction t + rw [← buchstabAux_eq_stage ht'.1 htn, + ← buchstabFunction_eq_aux_div ht'.1] + +theorem mul_buchstabFunction_eq_one_add_integral {u : ℝ} (hu : 2 < u) : + u * buchstabFunction u = + 1 + ∫ t in 1..u - 1, buchstabFunction t := by + rw [mul_buchstabFunction (by linarith), buchstabAux_eq_one_add_integral hu] + +private noncomputable def buchstabStageIntegrand (n : ℕ) (t : ℝ) : ℝ := + buchstabStage n (max t 1) / max t 1 + +private theorem integral_buchstabStageIntegrand_eq {n : ℕ} {u : ℝ} + (hu : 2 ≤ u) : + (∫ t in 1..u - 1, buchstabStageIntegrand n t) = + ∫ t in 1..u - 1, buchstabStage n t / t := by + apply intervalIntegral.integral_congr + intro t ht + have ht' : t ∈ Set.Icc (1 : ℝ) (u - 1) := by + simpa [Set.uIcc_of_le (by linarith : (1 : ℝ) ≤ u - 1)] using ht + simp [buchstabStageIntegrand, max_eq_left ht'.1] + +private theorem continuous_buchstabStage : ∀ n : ℕ, + Continuous (buchstabStage n) + | 0 => by exact continuous_const + | n + 1 => by + have hstage := continuous_buchstabStage n + have hmax : Continuous (fun t : ℝ ↦ max t 1) := + continuous_id.max continuous_const + have hmax0 : ∀ t : ℝ, max t 1 ≠ 0 := fun t ↦ by + have : (1 : ℝ) ≤ max t 1 := le_max_right _ _ + linarith + have hint : Continuous (buchstabStageIntegrand n) := by + unfold buchstabStageIntegrand + exact (hstage.comp hmax).div hmax (hmax0) + have hright : Continuous (fun u : ℝ ↦ + 1 + ∫ t in 1..u - 1, buchstabStageIntegrand n t) := by + have hprimitive : Continuous (fun v : ℝ ↦ + ∫ t in 1..v, buchstabStageIntegrand n t) := + (intervalIntegral.differentiable_integral_of_continuous hint).continuous + exact continuous_const.add + (hprimitive.comp (continuous_id.sub continuous_const)) + rw [show buchstabStage (n + 1) = fun u : ℝ ↦ + if u ≤ 2 then 1 + else 1 + ∫ t in 1..u - 1, buchstabStageIntegrand n t by + funext u + by_cases hu : u ≤ 2 + · simp [buchstabStage, hu] + · rw [buchstabStage, ite_eq_right hu, + integral_buchstabStageIntegrand_eq (le_of_not_ge hu)] + simp [hu] ] + apply continuous_if_le continuous_id continuous_const + · exact continuous_const.continuousOn + · exact hright.continuousOn + · rintro u rfl + norm_num + +theorem continuousOn_buchstabAux : ContinuousOn buchstabAux (Set.Ici 1) := by + intro u hu + let n : ℕ := ⌈u⌉₊ + have huBound : u < (n : ℝ) + 2 := by + dsimp [n] + have hceil := Nat.le_ceil u + linarith + have hlocal : ∀ᶠ v in nhdsWithin u (Set.Ici (1 : ℝ)), + buchstabAux v = buchstabStage n v := by + filter_upwards [nhdsWithin_le_nhds (Iio_mem_nhds huBound), + eventually_mem_nhdsWithin] with v hvBound hv1 + exact buchstabAux_eq_stage hv1 hvBound.le + exact (continuous_buchstabStage n).continuousAt.continuousWithinAt.congr_of_eventuallyEq + hlocal (buchstabAux_eq_stage hu huBound.le) + +theorem continuousOn_buchstabFunction : + ContinuousOn buchstabFunction (Set.Ici 1) := by + have hdiv : ContinuousOn (fun u ↦ buchstabAux u / u) (Set.Ici (1 : ℝ)) := + continuousOn_buchstabAux.div continuousOn_id fun u hu ↦ by + change 1 ≤ u at hu + linarith + exact hdiv.congr fun u hu ↦ buchstabFunction_eq_aux_div hu + +private noncomputable def buchstabContinuousExtension (t : ℝ) : ℝ := + buchstabFunction (max t 1) + +private theorem continuous_buchstabContinuousExtension : + Continuous buchstabContinuousExtension := by + have hmax : Continuous (fun t : ℝ ↦ max t 1) := + continuous_id.max continuous_const + unfold buchstabContinuousExtension + simpa only [Function.comp_def] using + continuousOn_buchstabFunction.comp_continuous hmax + (fun t ↦ le_max_right t 1) + +private theorem integral_buchstabContinuousExtension_eq {u : ℝ} (hu : 2 ≤ u) : + (∫ t in 1..u - 1, buchstabContinuousExtension t) = + ∫ t in 1..u - 1, buchstabFunction t := by + apply intervalIntegral.integral_congr + intro t ht + have ht' : t ∈ Set.Icc (1 : ℝ) (u - 1) := by + simpa [Set.uIcc_of_le (by linarith : (1 : ℝ) ≤ u - 1)] using ht + simp [buchstabContinuousExtension, max_eq_left ht'.1] + +theorem hasDerivAt_buchstabAux {u : ℝ} (hu : 2 < u) : + HasDerivAt buchstabAux (buchstabFunction (u - 1)) u := by + have hext := continuous_buchstabContinuousExtension + have hprim := intervalIntegral.integral_hasDerivAt_right + (a := (1 : ℝ)) (b := u - 1) + (hext.intervalIntegrable _ _) + hext.aestronglyMeasurable.stronglyMeasurableAtFilter hext.continuousAt + have hcomp := hprim.comp u ((hasDerivAt_id u).sub_const 1) + have hright : HasDerivAt + (fun v : ℝ ↦ 1 + ∫ t in 1..v - 1, buchstabContinuousExtension t) + (buchstabContinuousExtension (u - 1)) u := by + have h := hcomp.const_add 1 + change HasDerivAt + (fun v : ℝ ↦ 1 + ∫ t in 1..v - 1, buchstabContinuousExtension t) + (buchstabContinuousExtension (u - 1) * 1) u at h + simpa only [mul_one] using h + have heq : buchstabAux =ᶠ[nhds u] + fun v : ℝ ↦ 1 + ∫ t in 1..v - 1, buchstabContinuousExtension t := by + filter_upwards [Ioi_mem_nhds hu] with v hv + rw [buchstabAux_eq_one_add_integral hv, + integral_buchstabContinuousExtension_eq hv.le] + have h := hright.congr_of_eventuallyEq heq + simpa [buchstabContinuousExtension, max_eq_left (by linarith : (1 : ℝ) ≤ u - 1)] using h + +theorem hasDerivAt_mul_buchstabFunction {u : ℝ} (hu : 2 < u) : + HasDerivAt (fun v ↦ v * buchstabFunction v) + (buchstabFunction (u - 1)) u := by + have heq : (fun v : ℝ ↦ v * buchstabFunction v) =ᶠ[nhds u] buchstabAux := by + filter_upwards [Ioi_mem_nhds (show 1 < u by linarith)] with v hv + exact mul_buchstabFunction hv.le + exact (hasDerivAt_buchstabAux hu).congr_of_eventuallyEq heq + +theorem hasDerivAt_buchstabFunction {u : ℝ} (hu : 2 < u) : + HasDerivAt buchstabFunction + ((buchstabFunction (u - 1) - buchstabFunction u) / u) u := by + have hu0 : u ≠ 0 := by linarith + have hquot := (hasDerivAt_buchstabAux hu).div (hasDerivAt_id u) hu0 + have hEq : ∀ᶠ v in nhds u, buchstabFunction v = buchstabAux v / v := by + filter_upwards [Ioi_mem_nhds (show 1 < u by linarith)] with v hv + exact buchstabFunction_eq_aux_div hv.le + have h := hquot.congr_of_eventuallyEq hEq + apply h.congr_deriv + dsimp only [id_eq, one_mul] + rw [← mul_buchstabFunction (show 1 ≤ u by linarith)] + field_simp + +private theorem buchstabStage_nonneg : ∀ n : ℕ, ∀ {u : ℝ}, 1 ≤ u → + 0 ≤ buchstabStage n u + | 0, _, _ => by simp [buchstabStage] + | n + 1, u, hu => by + by_cases hu2 : u ≤ 2 + · simp [buchstabStage, hu2] + · rw [buchstabStage_succ_eq_integral (lt_of_not_ge hu2)] + have hInt : 0 ≤ ∫ t in 1..u - 1, buchstabStage n t / t := by + apply intervalIntegral.integral_nonneg (by linarith) + intro t ht + have ht1 : 1 ≤ t := by linarith [ht.1] + exact div_nonneg (buchstabStage_nonneg n ht1) (by linarith) + linarith + +private theorem buchstabStage_one_le : ∀ n : ℕ, ∀ {u : ℝ}, 1 ≤ u → + 1 ≤ buchstabStage n u + | 0, _, _ => by simp [buchstabStage] + | n + 1, u, hu => by + by_cases hu2 : u ≤ 2 + · simp [buchstabStage, hu2] + · rw [buchstabStage_succ_eq_integral (lt_of_not_ge hu2)] + have hInt : 0 ≤ ∫ t in 1..u - 1, buchstabStage n t / t := by + apply intervalIntegral.integral_nonneg (by linarith) + intro t ht + have ht1 : 1 ≤ t := by linarith [ht.1] + exact div_nonneg (buchstabStage_nonneg n ht1) (by linarith) + linarith + +theorem buchstabAux_one_le {u : ℝ} (hu : 1 ≤ u) : + 1 ≤ buchstabAux u := by + rw [buchstabAux_eq_stage (n := ⌈u⌉₊) hu + ((Nat.le_ceil u).trans (by norm_num))] + exact buchstabStage_one_le _ hu + +theorem buchstabFunction_nonneg {u : ℝ} (hu : 1 ≤ u) : + 0 ≤ buchstabFunction u := by + rw [buchstabFunction_eq_aux_div hu] + exact div_nonneg (buchstabAux_one_le hu |>.trans' zero_le_one) (by linarith) + +theorem inv_le_buchstabFunction {u : ℝ} (hu : 1 ≤ u) : + u⁻¹ ≤ buchstabFunction u := by + rw [buchstabFunction_eq_aux_div hu, inv_eq_one_div] + exact div_le_div_of_nonneg_right (buchstabAux_one_le hu) (by linarith) + +private theorem buchstabFunction_le_one_induction : ∀ n : ℕ, + ∀ {u : ℝ}, 1 ≤ u → u ≤ n + 2 → buchstabFunction u ≤ 1 + | 0, u, hu1, hu2 => by + rw [buchstabFunction_eq_inv hu1 (by simpa using hu2)] + exact inv_le_one_of_one_le₀ hu1 + | n + 1, u, hu1, huN => by + by_cases hu2 : u ≤ 2 + · rw [buchstabFunction_eq_inv hu1 hu2] + exact inv_le_one_of_one_le₀ hu1 + · have hu2' : 2 < u := lt_of_not_ge hu2 + rw [buchstabFunction_eq_aux_div hu1, + buchstabAux_eq_one_add_integral hu2'] + rw [div_le_iff₀ (by linarith : 0 < u)] + have hInt : (∫ t in 1..u - 1, buchstabFunction t) ≤ u - 2 := by + have hcont : ContinuousOn buchstabFunction (Set.Icc (1 : ℝ) (u - 1)) := + continuousOn_buchstabFunction.mono (by + intro t ht + exact ht.1) + calc + (∫ t in 1..u - 1, buchstabFunction t) ≤ + ∫ _t in 1..u - 1, (1 : ℝ) := by + apply intervalIntegral.integral_mono_on (by linarith) + · exact ContinuousOn.intervalIntegrable (by + rwa [Set.uIcc_of_le (by linarith : (1 : ℝ) ≤ u - 1)]) + · exact continuousOn_const.intervalIntegrable + · intro t ht + have ht1 : 1 ≤ t := ht.1 + have htu : t ≤ n + 2 := by + norm_num at huN ⊢ + linarith [ht.2] + exact buchstabFunction_le_one_induction n ht1 htu + _ = u - 2 := by simp; ring + linarith + +theorem buchstabFunction_le_one {u : ℝ} (hu : 1 ≤ u) : + buchstabFunction u ≤ 1 := by + let n : ℕ := ⌈u⌉₊ + apply buchstabFunction_le_one_induction n hu + dsimp [n] + exact (Nat.le_ceil u).trans (by norm_num) + +theorem abs_buchstabFunction_le_one {u : ℝ} (hu : 1 ≤ u) : + |buchstabFunction u| ≤ 1 := by + rw [abs_of_nonneg (buchstabFunction_nonneg hu)] + exact buchstabFunction_le_one hu + +theorem norm_deriv_mul_buchstabFunction_le_one {u : ℝ} (hu : 2 < u) : + ‖deriv (fun v ↦ v * buchstabFunction v) u‖ ≤ 1 := by + rw [(hasDerivAt_mul_buchstabFunction hu).deriv] + simpa only [Real.norm_eq_abs] using + abs_buchstabFunction_le_one (show 1 ≤ u - 1 by linarith) + +theorem abs_deriv_buchstabFunction_le_two_div {u : ℝ} (hu : 2 < u) : + |deriv buchstabFunction u| ≤ 2 / u := by + rw [(hasDerivAt_buchstabFunction hu).deriv, abs_div, + abs_of_pos (by linarith : 0 < u)] + have hnum : |buchstabFunction (u - 1) - buchstabFunction u| ≤ 2 := by + calc + |buchstabFunction (u - 1) - buchstabFunction u| ≤ + |buchstabFunction (u - 1)| + |buchstabFunction u| := abs_sub _ _ + _ ≤ 1 + 1 := add_le_add + (abs_buchstabFunction_le_one (by linarith)) + (abs_buchstabFunction_le_one (by linarith)) + _ = 2 := by norm_num + exact div_le_div_of_nonneg_right hnum (by linarith) + +theorem abs_buchstabFunction_sub_shift_le_two_div {u : ℝ} (hu : 3 < u) : + |buchstabFunction u - buchstabFunction (u - 1)| ≤ 2 / (u - 1) := by + have hdiff : ∀ x ∈ Set.Icc (u - 1) u, + DifferentiableAt ℝ buchstabFunction x := by + intro x hx + exact (hasDerivAt_buchstabFunction (by linarith [hx.1])).differentiableAt + have hbound : ∀ x ∈ Set.Icc (u - 1) u, + ‖deriv buchstabFunction x‖ ≤ 2 / (u - 1) := by + intro x hx + rw [Real.norm_eq_abs] + calc + |deriv buchstabFunction x| ≤ 2 / x := + abs_deriv_buchstabFunction_le_two_div (by linarith [hx.1]) + _ ≤ 2 / (u - 1) := by + exact div_le_div_of_nonneg_left (by norm_num) (by linarith) hx.1 + have hmv := (convex_Icc (u - 1) u).norm_image_sub_le_of_norm_deriv_le + hdiff hbound (Set.left_mem_Icc.mpr (by linarith)) + (Set.right_mem_Icc.mpr (by linarith)) + convert hmv using 1; norm_num + +theorem abs_deriv_buchstabFunction_le_two_div_mul_sub_one {u : ℝ} + (hu : 3 < u) : + |deriv buchstabFunction u| ≤ 2 / (u * (u - 1)) := by + rw [(hasDerivAt_buchstabFunction (by linarith)).deriv, abs_div, + abs_of_pos (by linarith : 0 < u)] + have h := abs_buchstabFunction_sub_shift_le_two_div hu + rw [abs_sub_comm] at h + calc + |buchstabFunction (u - 1) - buchstabFunction u| / u ≤ + (2 / (u - 1)) / u := + div_le_div_of_nonneg_right h (by linarith) + _ = 2 / (u * (u - 1)) := by + field_simp [show u ≠ 0 by linarith, show u - 1 ≠ 0 by linarith] + +theorem continuousOn_deriv_buchstabFunction : + ContinuousOn (deriv buchstabFunction) (Set.Ioi 2) := by + have hω : ContinuousOn buchstabFunction (Set.Ioi (2 : ℝ)) := + continuousOn_buchstabFunction.mono (Set.Ioi_subset_Ici_self.trans + (Set.Ici_subset_Ici.mpr (by norm_num))) + have hshift : ContinuousOn (fun u : ℝ ↦ buchstabFunction (u - 1)) + (Set.Ioi 2) := by + apply continuousOn_buchstabFunction.comp + (continuousOn_id.sub continuousOn_const) + intro u hu + change 1 ≤ u - 1 + linarith [Set.mem_Ioi.mp hu] + have hformula : ContinuousOn + (fun u : ℝ ↦ (buchstabFunction (u - 1) - buchstabFunction u) / u) + (Set.Ioi 2) := + (hshift.sub hω).div continuousOn_id fun u hu ↦ by + exact ne_of_gt (by linarith [Set.mem_Ioi.mp hu]) + exact hformula.congr fun u hu ↦ + (hasDerivAt_buchstabFunction (Set.mem_Ioi.mp hu)).deriv + +theorem integrableOn_deriv_buchstabFunction : + IntegrableOn (deriv buchstabFunction) (Set.Ioi 3) := by + have hmodel : IntegrableOn + (fun x : ℝ ↦ 2 * (x + (-1)) ^ (-2 : ℝ)) (Set.Ioi 3) := + (integrableOn_add_rpow_Ioi_of_lt (a := (-2 : ℝ)) (c := (3 : ℝ)) + (m := (-1 : ℝ)) (by norm_num) (by norm_num)).const_mul 2 + apply hmodel.mono' + · exact (continuousOn_deriv_buchstabFunction.mono + (Set.Ioi_subset_Ioi (by norm_num))).aestronglyMeasurable measurableSet_Ioi + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx + have hx3 : 3 < x := Set.mem_Ioi.mp hx + rw [Real.norm_eq_abs] + calc + |deriv buchstabFunction x| ≤ 2 / (x * (x - 1)) := + abs_deriv_buchstabFunction_le_two_div_mul_sub_one hx3 + _ ≤ 2 / ((x - 1) * (x - 1)) := by + exact div_le_div_of_nonneg_left (by norm_num) + (mul_pos (by linarith) (by linarith)) + (mul_le_mul_of_nonneg_right (by linarith) (by linarith)) + _ = 2 * (x + (-1)) ^ (-2 : ℝ) := by + rw [show x + (-1) = x - 1 by ring, + show (-2 : ℝ) = ((-2 : ℤ) : ℝ) by norm_num, + Real.rpow_intCast] + norm_num [div_eq_mul_inv, zpow_neg] + field_simp [show x - 1 ≠ 0 by linarith] + +noncomputable def buchstabLimit : ℝ := + limUnder atTop buchstabFunction + +theorem tendsto_buchstabFunction_atTop : + Tendsto buchstabFunction atTop (nhds buchstabLimit) := by + exact tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi + (a := (3 : ℝ)) + (fun x hx ↦ ((hasDerivAt_buchstabFunction + (by linarith [Set.mem_Ioi.mp hx])).differentiableAt).hasDerivAt) + integrableOn_deriv_buchstabFunction + +theorem buchstabLimit_nonneg : 0 ≤ buchstabLimit := by + apply ge_of_tendsto tendsto_buchstabFunction_atTop + filter_upwards [eventually_ge_atTop (1 : ℝ)] with u hu + exact buchstabFunction_nonneg hu + +theorem buchstabLimit_le_one : buchstabLimit ≤ 1 := by + apply le_of_tendsto tendsto_buchstabFunction_atTop + filter_upwards [eventually_ge_atTop (1 : ℝ)] with u hu + exact buchstabFunction_le_one hu + +theorem abs_buchstabFunction_sub_le_two_div_sub_one {u v : ℝ} + (hu : 3 < u) (huv : u ≤ v) : + |buchstabFunction v - buchstabFunction u| ≤ 2 / (u - 1) := by + let g : ℝ → ℝ := fun t ↦ 2 / ((t - 1) * (t - 1)) + let G : ℝ → ℝ := fun t ↦ -2 / (t - 1) + have hderivCont : ContinuousOn (deriv buchstabFunction) (Set.Icc u v) := + continuousOn_deriv_buchstabFunction.mono (by + intro t ht + exact Set.mem_Ioi.mpr (by linarith [ht.1])) + have hderivInt : IntervalIntegrable (deriv buchstabFunction) volume u v := by + rw [← Set.uIcc_of_le huv] at hderivCont + exact hderivCont.intervalIntegrable + have hFTC : (∫ t in u..v, deriv buchstabFunction t) = + buchstabFunction v - buchstabFunction u := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + · intro t ht + have ht' : t ∈ Set.Icc u v := by simpa [Set.uIcc_of_le huv] using ht + exact ((hasDerivAt_buchstabFunction + (by linarith [ht'.1])).differentiableAt).hasDerivAt + · exact hderivInt + have hgCont : ContinuousOn g (Set.Icc u v) := by + unfold g + apply continuousOn_const.div + ((continuousOn_id.sub continuousOn_const).mul + (continuousOn_id.sub continuousOn_const)) + intro t ht + change (t - 1) * (t - 1) ≠ 0 + exact mul_ne_zero (by linarith [ht.1]) (by linarith [ht.1]) + have hgInt : IntervalIntegrable g volume u v := by + rw [← Set.uIcc_of_le huv] at hgCont + exact hgCont.intervalIntegrable + have hmono : (∫ t in u..v, |deriv buchstabFunction t|) ≤ + ∫ t in u..v, g t := by + apply intervalIntegral.integral_mono_on huv hderivInt.norm hgInt + intro t ht + have ht3 : 3 < t := by linarith [ht.1] + calc + |deriv buchstabFunction t| ≤ 2 / (t * (t - 1)) := + abs_deriv_buchstabFunction_le_two_div_mul_sub_one ht3 + _ ≤ 2 / ((t - 1) * (t - 1)) := by + exact div_le_div_of_nonneg_left (by norm_num) + (mul_pos (by linarith) (by linarith)) + (mul_le_mul_of_nonneg_right (by linarith) (by linarith)) + _ = g t := rfl + have hGderiv : ∀ t ∈ Set.uIcc u v, HasDerivAt G (g t) t := by + intro t ht + have ht' : t ∈ Set.Icc u v := by simpa [Set.uIcc_of_le huv] using ht + have ht0 : t - 1 ≠ 0 := by linarith [ht'.1] + dsimp only [G, g] + have h := (hasDerivAt_const t (-2 : ℝ)).div + ((hasDerivAt_id t).sub_const 1) ht0 + have hfun : HasDerivAt (fun x : ℝ ↦ -2 / (x - 1)) + ((0 * (t - 1) - -2 * 1) / (t - 1) ^ 2) t := by + apply h.congr_of_eventuallyEq + filter_upwards with x + rfl + apply hfun.congr_deriv + norm_num [pow_two] + have hgEval : (∫ t in u..v, g t) = G v - G u := + intervalIntegral.integral_eq_sub_of_hasDerivAt hGderiv hgInt + calc + |buchstabFunction v - buchstabFunction u| = + |∫ t in u..v, deriv buchstabFunction t| := by rw [hFTC] + _ ≤ ∫ t in u..v, |deriv buchstabFunction t| := + intervalIntegral.abs_integral_le_integral_abs huv + _ ≤ ∫ t in u..v, g t := hmono + _ = G v - G u := hgEval + _ ≤ 2 / (u - 1) := by + dsimp [G] + have hv : 0 ≤ 2 / (v - 1) := div_nonneg (by norm_num) (by linarith) + calc + -2 / (v - 1) - -2 / (u - 1) = + 2 / (u - 1) - 2 / (v - 1) := by ring + _ ≤ 2 / (u - 1) := sub_le_self _ hv + +theorem abs_buchstabFunction_sub_limit_le_two_div_sub_one {u : ℝ} + (hu : 3 < u) : + |buchstabFunction u - buchstabLimit| ≤ 2 / (u - 1) := by + have ht : Tendsto (fun v : ℝ ↦ + |buchstabFunction v - buchstabFunction u|) atTop + (nhds |buchstabLimit - buchstabFunction u|) := + (tendsto_buchstabFunction_atTop.sub tendsto_const_nhds).abs + have hle : |buchstabLimit - buchstabFunction u| ≤ 2 / (u - 1) := by + apply le_of_tendsto ht + filter_upwards [eventually_ge_atTop u] with v hv + exact abs_buchstabFunction_sub_le_two_div_sub_one hu hv + simpa only [abs_sub_comm] using hle + +theorem integrableOn_buchstabFunction_sub_limit_div : + IntegrableOn (fun u : ℝ ↦ + (buchstabFunction u - buchstabLimit) / u) (Set.Ioi 3) := by + have hmodel : IntegrableOn + (fun x : ℝ ↦ 2 * (x + (-1)) ^ (-2 : ℝ)) (Set.Ioi 3) := + (integrableOn_add_rpow_Ioi_of_lt (a := (-2 : ℝ)) (c := (3 : ℝ)) + (m := (-1 : ℝ)) (by norm_num) (by norm_num)).const_mul 2 + apply hmodel.mono' + · have hω : ContinuousOn buchstabFunction (Set.Ioi (3 : ℝ)) := + continuousOn_buchstabFunction.mono (by + intro u hu + exact Set.mem_Ici.mpr (by linarith [Set.mem_Ioi.mp hu])) + have hcont : ContinuousOn (fun u : ℝ ↦ + (buchstabFunction u - buchstabLimit) / u) (Set.Ioi 3) := by + apply (hω.sub continuousOn_const).div continuousOn_id + intro u hu + change u ≠ 0 + exact ne_of_gt (by linarith [Set.mem_Ioi.mp hu]) + exact hcont.aestronglyMeasurable measurableSet_Ioi + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx + have hx3 : 3 < x := Set.mem_Ioi.mp hx + rw [Real.norm_eq_abs, abs_div, abs_of_pos (by linarith : 0 < x)] + calc + |buchstabFunction x - buchstabLimit| / x ≤ + (2 / (x - 1)) / x := + div_le_div_of_nonneg_right + (abs_buchstabFunction_sub_limit_le_two_div_sub_one hx3) + (by linarith) + _ ≤ 2 / ((x - 1) * (x - 1)) := by + rw [div_div] + exact div_le_div_of_nonneg_left (by norm_num) + (mul_pos (by linarith) (by linarith)) + (mul_le_mul_of_nonneg_left (by linarith) (by linarith)) + _ = 2 * (x + (-1)) ^ (-2 : ℝ) := by + rw [show x + (-1) = x - 1 by ring, + show (-2 : ℝ) = ((-2 : ℤ) : ℝ) by norm_num, + Real.rpow_intCast] + norm_num [div_eq_mul_inv, zpow_neg] + field_simp [show x - 1 ≠ 0 by linarith] + +noncomputable def buchstabLaplace (s : ℝ) : ℝ := + ∫ u in Set.Ioi (1 : ℝ), buchstabFunction u * Real.exp (-s * u) + +theorem measurable_buchstabFunction : Measurable buchstabFunction := by + have hlow : ContinuousOn buchstabFunction (Set.Iio (1 : ℝ)) := by + have hz : ∀ u ∈ Set.Iio (1 : ℝ), buchstabFunction u = 0 := by + intro u hu + rw [buchstabFunction, ite_eq_left (Set.mem_Iio.mp hu)] + exact continuousOn_const.congr fun u hu ↦ hz u hu + have hhigh : ContinuousOn buchstabFunction (Set.Ici (1 : ℝ)) := + continuousOn_buchstabFunction + have hpiece : buchstabFunction = (Set.Ici (1 : ℝ)).piecewise + buchstabFunction (fun _ ↦ 0) := by + funext u + by_cases hu : 1 ≤ u + · simp [hu] + · simp [Set.piecewise, hu, buchstabFunction, lt_of_not_ge hu] + rw [hpiece] + exact hhigh.measurable_piecewise + (continuousOn_const.mono (by + intro u hu + exact Set.mem_Iio.mpr (lt_of_not_ge hu))) measurableSet_Ici + +theorem integrableOn_buchstabLaplace_integrand {s : ℝ} (hs : 0 < s) : + IntegrableOn (fun u : ℝ ↦ + buchstabFunction u * Real.exp (-s * u)) (Set.Ioi 1) := by + have hexp : IntegrableOn (fun u : ℝ ↦ Real.exp (-s * u)) (Set.Ioi 1) := + exp_neg_integrableOn_Ioi 1 hs + apply hexp.mono' + · have hprod : Measurable (fun u : ℝ ↦ + buchstabFunction u * Real.exp (-s * u)) := + measurable_buchstabFunction.mul + ((Real.continuous_exp.comp + (show Continuous (fun u : ℝ ↦ -s * u) from + continuous_const.mul continuous_id)).measurable) + exact hprod.aestronglyMeasurable + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with u hu + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + exact mul_le_of_le_one_left (Real.exp_pos _).le + (abs_buchstabFunction_le_one (Set.mem_Ioi.mp hu).le) + +private theorem integrableOn_id_mul_exp_neg_mul {s : ℝ} (hs : 0 < s) : + IntegrableOn (fun u : ℝ ↦ u * Real.exp (-s * u)) (Set.Ioi 1) := by + let f : ℝ → ℝ := fun t ↦ Real.exp (-t) * t + have hf : IntegrableOn f (Set.Ioi 0) := by + have h := Real.GammaIntegral_convergent (s := (2 : ℝ)) (by norm_num) + convert h using 1 + funext u + norm_num [f, Real.rpow_one, mul_comm] + have hcomp : IntegrableOn (fun u : ℝ ↦ f (s * u)) (Set.Ioi 0) := + (integrableOn_Ioi_comp_mul_left_iff f 0 hs).mpr (by simpa using hf) + have hscaled : IntegrableOn (fun u : ℝ ↦ s⁻¹ * f (s * u)) (Set.Ioi 0) := + Integrable.const_mul hcomp s⁻¹ + have htarget : IntegrableOn (fun u : ℝ ↦ + u * Real.exp (-s * u)) (Set.Ioi 0) := by + apply hscaled.congr_fun _ measurableSet_Ioi + intro u hu + dsimp [f] + field_simp [hs.ne'] + exact htarget.mono_set (Set.Ioi_subset_Ioi (by norm_num)) + +private theorem integrableOn_buchstabLaplace_deriv_integrand {s : ℝ} + (hs : 0 < s) : + IntegrableOn (fun u : ℝ ↦ + -u * buchstabFunction u * Real.exp (-s * u)) (Set.Ioi 1) := by + have hmodel := integrableOn_id_mul_exp_neg_mul hs + apply hmodel.mono' + · have hm : Measurable (fun u : ℝ ↦ + -u * buchstabFunction u * Real.exp (-s * u)) := + (measurable_id.neg.mul measurable_buchstabFunction).mul + ((Real.continuous_exp.comp + (show Continuous (fun u : ℝ ↦ -s * u) from + continuous_const.mul continuous_id)).measurable) + exact hm.aestronglyMeasurable + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with u hu + have hu1 : 1 ≤ u := (Set.mem_Ioi.mp hu).le + rw [Real.norm_eq_abs, abs_mul, abs_mul, + abs_of_pos (Real.exp_pos _), abs_neg, abs_of_pos (by linarith : 0 < u)] + calc + u * |buchstabFunction u| * Real.exp (-s * u) ≤ + u * 1 * Real.exp (-s * u) := by + gcongr + exact abs_buchstabFunction_le_one hu1 + _ = u * Real.exp (-s * u) := by ring + +theorem hasDerivAt_buchstabLaplace {s : ℝ} (hs : 0 < s) : + HasDerivAt buchstabLaplace + (∫ u in Set.Ioi (1 : ℝ), + -(u * buchstabFunction u * Real.exp (-s * u))) s := by + let P : ℝ → ℝ → ℝ := fun x u ↦ + buchstabFunction u * Real.exp (-x * u) + let P' : ℝ → ℝ → ℝ := fun x u ↦ + -u * buchstabFunction u * Real.exp (-x * u) + let b : ℝ → ℝ := fun u ↦ + u * Real.exp (-(s / 2) * u) + have hsHalf : 0 < s / 2 := by linarith + have hnhds : Set.Ioi (s / 2) ∈ nhds s := Ioi_mem_nhds (by linarith) + have hPmeas : ∀ᶠ x in nhds s, + AEStronglyMeasurable (P x) (volume.restrict (Set.Ioi 1)) := by + filter_upwards with x + have hm : Measurable (P x) := by + unfold P + exact measurable_buchstabFunction.mul + ((Real.continuous_exp.comp + (show Continuous (fun u : ℝ ↦ -x * u) from + continuous_const.mul continuous_id)).measurable) + exact hm.aestronglyMeasurable + have hPint : Integrable (P s) (volume.restrict (Set.Ioi 1)) := by + change IntegrableOn (P s) (Set.Ioi 1) + simpa [P] using integrableOn_buchstabLaplace_integrand hs + have hP'meas : AEStronglyMeasurable (P' s) + (volume.restrict (Set.Ioi 1)) := by + have hm : Measurable (P' s) := by + unfold P' + exact (measurable_id.neg.mul measurable_buchstabFunction).mul + ((Real.continuous_exp.comp + (show Continuous (fun u : ℝ ↦ -s * u) from + continuous_const.mul continuous_id)).measurable) + exact hm.aestronglyMeasurable + have hbint : Integrable b (volume.restrict (Set.Ioi 1)) := by + change IntegrableOn b (Set.Ioi 1) + simpa [b] using integrableOn_id_mul_exp_neg_mul hsHalf + have hbound : ∀ᵐ u ∂(volume.restrict (Set.Ioi 1)), + ∀ x ∈ Set.Ioi (s / 2), ‖P' x u‖ ≤ b u := by + filter_upwards [ae_restrict_mem measurableSet_Ioi] with u hu + intro x hx + have hu1 : 1 ≤ u := (Set.mem_Ioi.mp hu).le + have hu0 : 0 ≤ u := zero_le_one.trans hu1 + have hexp : Real.exp (-x * u) ≤ Real.exp (-(s / 2) * u) := by + apply Real.exp_le_exp.mpr + nlinarith [Set.mem_Ioi.mp hx] + rw [Real.norm_eq_abs, abs_mul, abs_mul, abs_neg, + abs_of_nonneg hu0, abs_of_pos (Real.exp_pos _)] + dsimp [P', b] + calc + u * |buchstabFunction u| * Real.exp (-x * u) ≤ + u * 1 * Real.exp (-x * u) := by + gcongr + exact abs_buchstabFunction_le_one hu1 + _ ≤ u * Real.exp (-(s / 2) * u) := by + simpa using mul_le_mul_of_nonneg_left hexp hu0 + have hdiff : ∀ᵐ u ∂(volume.restrict (Set.Ioi 1)), + ∀ x ∈ Set.Ioi (s / 2), HasDerivAt (P · u) (P' x u) x := by + filter_upwards with u + intro x hx + have hexp : HasDerivAt (fun y : ℝ ↦ Real.exp (-y * u)) + (-u * Real.exp (-x * u)) x := by + have hinner : HasDerivAt (fun y : ℝ ↦ -y * u) (-u) x := by + simpa [mul_neg, neg_mul] using (hasDerivAt_id x).mul_const (-u) + apply hinner.exp.congr_deriv + ring + dsimp [P, P'] + have hc := hexp.const_mul (buchstabFunction u) + apply hc.congr_deriv + ring + have hmain := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := P) (x₀ := s) (s := Set.Ioi (s / 2)) (bound := b) + hnhds hPmeas hPint hP'meas hbound hbint hdiff + change HasDerivAt + (fun n : ℝ ↦ ∫ u in Set.Ioi (1 : ℝ), + buchstabFunction u * Real.exp (-n * u)) + (∫ u in Set.Ioi (1 : ℝ), + -(u * buchstabFunction u * Real.exp (-s * u))) s + simpa [P, P'] using hmain.2 + +theorem differentiableOn_buchstabLaplace : + DifferentiableOn ℝ buchstabLaplace (Set.Ioi 0) := by + intro s hs + exact DifferentiableAt.differentiableWithinAt + (hasDerivAt_buchstabLaplace (Set.mem_Ioi.mp hs)).differentiableAt + +private theorem integrableOn_buchstabShift_mul_exp {s : ℝ} (hs : 0 < s) : + IntegrableOn (fun u : ℝ ↦ + buchstabFunction (u - 1) * Real.exp (-s * u)) (Set.Ioi 2) := by + have hexp : IntegrableOn (fun u : ℝ ↦ Real.exp (-s * u)) (Set.Ioi 2) := + exp_neg_integrableOn_Ioi 2 hs + apply hexp.mono' + · have hm : Measurable (fun u : ℝ ↦ + buchstabFunction (u - 1) * Real.exp (-s * u)) := + (measurable_buchstabFunction.comp + (measurable_id.sub measurable_const)).mul + ((Real.continuous_exp.comp + (show Continuous (fun u : ℝ ↦ -s * u) from + continuous_const.mul continuous_id)).measurable) + exact hm.aestronglyMeasurable + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with u hu + have hu1 : 1 ≤ u - 1 := by linarith [Set.mem_Ioi.mp hu] + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + exact mul_le_of_le_one_left (Real.exp_pos _).le + (abs_buchstabFunction_le_one hu1) + +private theorem integrableOn_mul_buchstab_mul_exp_deriv {s : ℝ} (hs : 0 < s) : + IntegrableOn (fun u : ℝ ↦ + (u * buchstabFunction u) * (-s * Real.exp (-s * u))) (Set.Ioi 2) := by + have hbase := integrableOn_buchstabLaplace_deriv_integrand hs + have hscaled : IntegrableOn (fun u : ℝ ↦ + s * (-u * buchstabFunction u * Real.exp (-s * u))) (Set.Ioi 1) := + Integrable.const_mul hbase s + have hcongr : IntegrableOn (fun u : ℝ ↦ + (u * buchstabFunction u) * (-s * Real.exp (-s * u))) (Set.Ioi 1) := by + apply hscaled.congr_fun _ measurableSet_Ioi + intro u hu + ring + exact hcongr.mono_set (Set.Ioi_subset_Ioi (by norm_num)) + +theorem integral_mul_buchstab_mul_exp_Ioi_two {s : ℝ} (hs : 0 < s) : + (∫ u in Set.Ioi (2 : ℝ), + (u * buchstabFunction u) * Real.exp (-s * u)) = + Real.exp (-s * 2) / s + + (1 / s) * ∫ u in Set.Ioi (2 : ℝ), + buchstabFunction (u - 1) * Real.exp (-s * u) := by + let g : ℝ → ℝ := fun u ↦ u * buchstabFunction u + let g' : ℝ → ℝ := fun u ↦ buchstabFunction (u - 1) + let e : ℝ → ℝ := fun u ↦ Real.exp (-s * u) + let e' : ℝ → ℝ := fun u ↦ -s * Real.exp (-s * u) + have hg : ∀ u ∈ Set.Ioi (2 : ℝ), HasDerivAt g (g' u) u := by + intro u hu + exact hasDerivAt_mul_buchstabFunction (Set.mem_Ioi.mp hu) + have he : ∀ u ∈ Set.Ioi (2 : ℝ), HasDerivAt e (e' u) u := by + intro u hu + dsimp [e, e'] + have hinner : HasDerivAt (fun x : ℝ ↦ -s * x) (-s) u := by + simpa only [id_eq, mul_one] using (hasDerivAt_id u).const_mul (-s) + apply hinner.exp.congr_deriv + ring + have hge' : IntegrableOn (g * e') (Set.Ioi (2 : ℝ)) := by + change IntegrableOn (fun u : ℝ ↦ + (u * buchstabFunction u) * (-s * Real.exp (-s * u))) (Set.Ioi 2) + exact integrableOn_mul_buchstab_mul_exp_deriv hs + have hg'e : IntegrableOn (g' * e) (Set.Ioi (2 : ℝ)) := by + change IntegrableOn (fun u : ℝ ↦ + buchstabFunction (u - 1) * Real.exp (-s * u)) (Set.Ioi 2) + exact integrableOn_buchstabShift_mul_exp hs + have hzero : Tendsto (g * e) (nhdsWithin 2 (Set.Ioi 2)) + (nhds (Real.exp (-s * 2))) := by + have hω2 : ContinuousAt buchstabFunction 2 := + continuousOn_buchstabFunction.continuousAt + (Ici_mem_nhds (by norm_num)) + have hprod : ContinuousAt (fun u : ℝ ↦ + (u * buchstabFunction u) * Real.exp (-s * u)) 2 := + (continuousAt_id.mul hω2).mul + (Real.continuous_exp.continuousAt.comp + ((continuousAt_const.mul continuousAt_id))) + have ht : Tendsto (fun u : ℝ ↦ + (u * buchstabFunction u) * Real.exp (-s * u)) + (nhdsWithin 2 (Set.Ioi 2)) + (nhds ((2 * buchstabFunction 2) * Real.exp (-s * 2))) := + hprod.tendsto.mono_left inf_le_left + change Tendsto (fun u : ℝ ↦ + (u * buchstabFunction u) * Real.exp (-s * u)) + (nhdsWithin 2 (Set.Ioi 2)) (nhds (Real.exp (-s * 2))) + simpa [buchstabFunction_eq_inv (u := (2 : ℝ)) + (by norm_num) (by norm_num)] using ht + have hinfty : Tendsto (g * e) atTop (nhds 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (g := fun u : ℝ ↦ + u ^ (1 : ℝ) * Real.exp (-s * u)) + · filter_upwards with u + exact norm_nonneg _ + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with u hu + have hu0 : 0 ≤ u := zero_le_one.trans hu + change ‖(u * buchstabFunction u) * Real.exp (-s * u)‖ ≤ _ + rw [Real.norm_eq_abs, abs_mul, abs_mul, + abs_of_nonneg hu0, abs_of_pos (Real.exp_pos _)] + calc + u * |buchstabFunction u| * Real.exp (-s * u) ≤ + u * 1 * Real.exp (-s * u) := by + gcongr + exact abs_buchstabFunction_le_one hu + _ = u ^ (1 : ℝ) * Real.exp (-s * u) := by + rw [Real.rpow_one, mul_one] + · exact tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero 1 s hs + have hibp := integral_Ioi_mul_deriv_eq_deriv_mul + hg he hge' hg'e hzero hinfty + have hleft : (∫ u in Set.Ioi (2 : ℝ), g u * e' u) = + -s * ∫ u in Set.Ioi (2 : ℝ), g u * e u := by + rw [← integral_const_mul] + apply setIntegral_congr_fun measurableSet_Ioi + intro u hu + dsimp [e'] + ring + rw [hleft] at hibp + dsimp [g, g', e] at hibp ⊢ + have hs0 : s ≠ 0 := hs.ne' + let A := ∫ u in Set.Ioi (2 : ℝ), + u * buchstabFunction u * Real.exp (-s * u) + let B := ∫ u in Set.Ioi (2 : ℝ), + buchstabFunction (u - 1) * Real.exp (-s * u) + let E := Real.exp (-s * 2) + have hAB : s * A = E + B := by + dsimp [A, B, E] + linarith [hibp] + change A = E / s + (1 / s) * B + calc + A = (E + B) / s := (eq_div_iff hs0).2 (by simpa [mul_comm] using hAB) + _ = E / s + (1 / s) * B := by field_simp [hs0] + +theorem integral_buchstabShift_mul_exp_Ioi_two {s : ℝ} : + (∫ u in Set.Ioi (2 : ℝ), + buchstabFunction (u - 1) * Real.exp (-s * u)) = + Real.exp (-s) * buchstabLaplace s := by + let h : ℝ → ℝ := fun u ↦ + buchstabFunction (u - 1) * Real.exp (-s * u) + calc + (∫ u in Set.Ioi (2 : ℝ), + buchstabFunction (u - 1) * Real.exp (-s * u)) = + ∫ u : ℝ, (Set.Ioi (2 : ℝ)).indicator h u := by + rw [integral_indicator measurableSet_Ioi] + _ = ∫ v : ℝ, (Set.Ioi (2 : ℝ)).indicator h (v + 1) := by + rw [integral_add_right_eq_self] + _ = ∫ v : ℝ, (Set.Ioi (1 : ℝ)).indicator + (fun v ↦ Real.exp (-s) * + (buchstabFunction v * Real.exp (-s * v))) v := by + apply integral_congr_ae + filter_upwards with v + by_cases hv : 1 < v + · rw [Set.indicator_of_mem (show v + 1 ∈ Set.Ioi (2 : ℝ) by + exact Set.mem_Ioi.mpr (by linarith)), + Set.indicator_of_mem (Set.mem_Ioi.mpr hv)] + dsimp [h] + rw [show v + 1 - 1 = v by ring, + show -s * (v + 1) = -s + (-s * v) by ring, Real.exp_add] + ring_nf + · rw [Set.indicator_of_notMem (show v + 1 ∉ Set.Ioi (2 : ℝ) by + intro hv' + exact hv (by linarith [Set.mem_Ioi.mp hv'])), + Set.indicator_of_notMem (show v ∉ Set.Ioi (1 : ℝ) by exact hv)] + _ = ∫ v in Set.Ioi (1 : ℝ), Real.exp (-s) * + (buchstabFunction v * Real.exp (-s * v)) := by + rw [integral_indicator measurableSet_Ioi] + _ = Real.exp (-s) * buchstabLaplace s := by + rw [integral_const_mul] + rfl + +theorem integral_mul_buchstab_mul_exp_Ioi_one {s : ℝ} (hs : 0 < s) : + (∫ u in Set.Ioi (1 : ℝ), + (u * buchstabFunction u) * Real.exp (-s * u)) = + (Real.exp (-s) / s) * (1 + buchstabLaplace s) := by + let q : ℝ → ℝ := fun u ↦ + (u * buchstabFunction u) * Real.exp (-s * u) + have hq1 : IntegrableOn q (Set.Ioi (1 : ℝ)) := by + have h := (integrableOn_buchstabLaplace_deriv_integrand hs).neg + apply h.congr_fun _ measurableSet_Ioi + intro u hu + dsimp [q] + ring + have hq2 : IntegrableOn q (Set.Ioi (2 : ℝ)) := + hq1.mono_set (Set.Ioi_subset_Ioi (by norm_num)) + have hsplit := intervalIntegral.integral_interval_add_Ioi hq1 hq2 + have hfinite : (∫ u in (1 : ℝ)..2, q u) = + ∫ u in (1 : ℝ)..2, Real.exp (-s * u) := by + apply intervalIntegral.integral_congr + intro u hu + have hu' : u ∈ Set.Icc (1 : ℝ) 2 := by + simpa [Set.uIcc_of_le (by norm_num : (1 : ℝ) ≤ 2)] using hu + dsimp [q] + rw [buchstabFunction_eq_inv hu'.1 hu'.2] + have hu0 : u ≠ 0 := ne_of_gt (zero_lt_one.trans_le hu'.1) + field_simp [hu0] + have hexp1 : IntegrableOn (fun u : ℝ ↦ Real.exp (-s * u)) + (Set.Ioi 1) := exp_neg_integrableOn_Ioi 1 hs + have hexp2 : IntegrableOn (fun u : ℝ ↦ Real.exp (-s * u)) + (Set.Ioi 2) := exp_neg_integrableOn_Ioi 2 hs + have hexpSplit := intervalIntegral.integral_interval_add_Ioi hexp1 hexp2 + have hexpTail (c : ℝ) : + (∫ u in Set.Ioi c, Real.exp (-s * u)) = Real.exp (-s * c) / s := by + have h := integral_exp_mul_Ioi (a := -s) (by linarith) c + rw [h] + field_simp [hs.ne'] + rw [hexpTail 1, hexpTail 2] at hexpSplit + rw [hfinite] at hsplit + have htail := integral_mul_buchstab_mul_exp_Ioi_two hs + rw [integral_buchstabShift_mul_exp_Ioi_two] at htail + dsimp [q] at hsplit ⊢ + rw [htail] at hsplit + have hs0 : s ≠ 0 := hs.ne' + field_simp [hs0] at hexpSplit hsplit ⊢ + nlinarith [hsplit, hexpSplit] + +theorem buchstabLaplace_nonneg {s : ℝ} : 0 ≤ buchstabLaplace s := by + apply setIntegral_nonneg measurableSet_Ioi + intro u hu + exact mul_nonneg + (buchstabFunction_nonneg (Set.mem_Ioi.mp hu).le) + (Real.exp_pos _).le + +theorem buchstabLaplace_ode {s : ℝ} (hs : 0 < s) : + s * deriv buchstabLaplace s + + Real.exp (-s) * (1 + buchstabLaplace s) = 0 := by + have hd := (hasDerivAt_buchstabLaplace hs).deriv + rw [integral_neg] at hd + have htotal := integral_mul_buchstab_mul_exp_Ioi_one hs + rw [hd, htotal] + field_simp [hs.ne'] + ring + +theorem tendsto_buchstabLaplace_atTop : + Tendsto buchstabLaplace atTop (nhds 0) := by + apply squeeze_zero' (g := fun s : ℝ ↦ Real.exp (-s)) + · filter_upwards with s + exact buchstabLaplace_nonneg + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs1 + have hs : 0 < s := zero_lt_one.trans_le hs1 + have hFint := integrableOn_buchstabLaplace_integrand hs + have hexp : IntegrableOn (fun u : ℝ ↦ Real.exp (-s * u)) + (Set.Ioi 1) := exp_neg_integrableOn_Ioi 1 hs + have hle : buchstabLaplace s ≤ + ∫ u in Set.Ioi (1 : ℝ), Real.exp (-s * u) := by + apply setIntegral_mono_on hFint hexp measurableSet_Ioi + intro u hu + exact mul_le_of_le_one_left (Real.exp_pos _).le + (buchstabFunction_le_one (Set.mem_Ioi.mp hu).le) + have heval : (∫ u in Set.Ioi (1 : ℝ), Real.exp (-s * u)) = + Real.exp (-s) / s := by + have h := integral_exp_mul_Ioi (a := -s) (by linarith) 1 + rw [h] + field_simp [hs.ne'] + rw [heval] at hle + exact hle.trans (div_le_self (Real.exp_pos _).le hs1) + · exact Real.tendsto_exp_neg_atTop_nhds_zero + +theorem one_add_buchstabLaplace_eq_exponentialIntegral {s : ℝ} (hs : 0 < s) : + 1 + buchstabLaplace s = Real.exp + (∫ t in Set.Ioi s, Real.exp (-t) / t) := by + exact laplace_ode_solution differentiableOn_buchstabLaplace + (fun x hx ↦ by linarith [buchstabLaplace_nonneg (s := x)]) + (fun x hx ↦ buchstabLaplace_ode hx) + tendsto_buchstabLaplace_atTop s hs + +theorem buchstabLimit_eq_exp_neg_eulerMascheroniConstant : + buchstabLimit = Real.exp (-Real.eulerMascheroniConstant) := by + let l := nhdsWithin (0 : ℝ) (Set.Ioi 0) + have hzero : Tendsto (fun s : ℝ ↦ s) l (nhds 0) := + tendsto_id.mono_left inf_le_left + have hleft : Tendsto (fun s : ℝ ↦ + s * (1 + buchstabLaplace s)) l (nhds buchstabLimit) := by + have hab : Tendsto (fun s : ℝ ↦ s * buchstabLaplace s) l + (nhds buchstabLimit) := + laplace_final_value_of_tendsto buchstabFunction buchstabLimit 1 + measurable_buchstabFunction (by norm_num) + (fun u hu ↦ abs_buchstabFunction_le_one hu) + tendsto_buchstabFunction_atTop + have hsum := hzero.add hab + simpa [mul_add] using hsum + have hright : Tendsto (fun s : ℝ ↦ + s * (1 + buchstabLaplace s)) l + (nhds (Real.exp (-Real.eulerMascheroniConstant))) := by + apply exponentialIntegral_exp_limit.congr' + filter_upwards [self_mem_nhdsWithin] with s hs + rw [one_add_buchstabLaplace_eq_exponentialIntegral hs] + exact tendsto_nhds_unique hleft hright + +theorem abs_buchstabFunction_sub_exp_neg_eulerMascheroni_le {u : ℝ} + (hu : 3 < u) : + |buchstabFunction u - Real.exp (-Real.eulerMascheroniConstant)| ≤ + 2 / (u - 1) := by + rw [← buchstabLimit_eq_exp_neg_eulerMascheroniConstant] + exact abs_buchstabFunction_sub_limit_le_two_div_sub_one hu + +theorem integrableOn_buchstabFunction_sub_exp_neg_eulerMascheroni_div : + IntegrableOn (fun u : ℝ ↦ + (buchstabFunction u - Real.exp (-Real.eulerMascheroniConstant)) / u) + (Set.Ioi 3) := by + rw [← buchstabLimit_eq_exp_neg_eulerMascheroniConstant] + exact integrableOn_buchstabFunction_sub_limit_div + +theorem tendsto_mul_buchstabLaplace_zero_right : + Tendsto (fun s : ℝ ↦ s * buchstabLaplace s) + (nhdsWithin 0 (Set.Ioi 0)) (nhds buchstabLimit) := by + exact laplace_final_value_of_tendsto buchstabFunction buchstabLimit 1 + measurable_buchstabFunction (by norm_num) + (fun u hu ↦ abs_buchstabFunction_le_one hu) + tendsto_buchstabFunction_atTop + +end + +end ErdosAverageCertificates + +end + +section + +namespace NumberTheoryLean.BuchstabBridge + +open MeasureTheory Filter +open scoped Topology +open LinearSieveFunctions + +theorem plus_eq_buchstabAux {s : ℝ} (hs : 1 ≤ s) : + plus (s - 1) = ErdosAverageCertificates.buchstabAux s := by + apply DelayUniqueness.shifted_unique 1 (fun u => plus (u - 1)) ErdosAverageCertificates.buchstabAux + · intro u _ hu2 + exact plus_initial (by linarith) + · intro u hu1 hu2 + exact ErdosAverageCertificates.buchstabAux_eq_one hu1 hu2 + · intro u hu + simpa only [plus, one_mul] using + DelayConstruction.delay_integral_of_one_le 1 (u := u - 1) (by linarith) + · intro u hu + rw [ErdosAverageCertificates.buchstabAux_eq_one_add_integral hu, one_mul] + apply congrArg (fun I : ℝ => 1 + I) + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le (by linarith : (1 : ℝ) ≤ u - 1)] at ht + exact ErdosAverageCertificates.buchstabFunction_eq_aux_div ht.1 + · exact hs + +theorem plus_div_eq_buchstabFunction {s : ℝ} (hs : 1 ≤ s) : + plus (s - 1) / s = ErdosAverageCertificates.buchstabFunction s := by + rw [plus_eq_buchstabAux hs] + exact (ErdosAverageCertificates.buchstabFunction_eq_aux_div hs).symm + +theorem pair_sum_eq_buchstab (A : ℝ) {s : ℝ} (hs : 1 ≤ s) : + F A s + f A s = A * ErdosAverageCertificates.buchstabFunction s := by + rw [← plus_div_eq_buchstabFunction hs, f_eq_difference] + unfold F + have hs0 : s ≠ 0 := by linarith + field_simp + ring + +noncomputable def sieveA : ℝ := 2 * Real.exp Real.eulerMascheroniConstant + +theorem sieveA_pos : 0 < sieveA := by unfold sieveA; positivity + +theorem sieveA_gt_two : 2 < sieveA := by + have hgamma : 0 < Real.eulerMascheroniConstant := by + linarith [Real.one_half_lt_eulerMascheroniConstant] + have hexp : 1 < Real.exp Real.eulerMascheroniConstant := Real.one_lt_exp_iff.mpr hgamma + unfold sieveA + linarith + +theorem sieveA_normalization : sieveA * Real.exp (-Real.eulerMascheroniConstant) = 2 := by + unfold sieveA + rw [mul_assoc, ← Real.exp_add] + simp + +theorem normalized_pair_sum_tendsto_two : + Tendsto (fun s : ℝ => F sieveA s + f sieveA s) atTop (𝓝 2) := by + have hlim := ErdosAverageCertificates.tendsto_buchstabFunction_atTop.const_mul sieveA + rw [ErdosAverageCertificates.buchstabLimit_eq_exp_neg_eulerMascheroniConstant, + sieveA_normalization] at hlim + apply hlim.congr' + filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs + exact (pair_sum_eq_buchstab sieveA hs).symm + +theorem pair_gap_tendsto_zero (A : ℝ) : + Tendsto (fun s : ℝ => F A s - f A s) atTop (𝓝 0) := by + have hshift : Tendsto (fun s : ℝ => s - 1) atTop atTop := by + apply tendsto_atTop.mpr + intro b + exact eventually_atTop.mpr ⟨b + 1, fun s hs => by linarith⟩ + have hrho := DickmanDecay.rho_tendsto_zero.comp hshift + have hlim := (hrho.const_mul A).mul (tendsto_inv_atTop_zero : Tendsto (fun s : ℝ => s⁻¹) atTop (𝓝 0)) + simp only [mul_zero] at hlim + apply hlim.congr' + filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs + rw [gap_identity A hs, div_eq_mul_inv] + rfl + +theorem normalized_F_tendsto_one : Tendsto (F sieveA) atTop (𝓝 1) := by + have hlim := (normalized_pair_sum_tendsto_two.add (pair_gap_tendsto_zero sieveA)).div_const 2 + norm_num at hlim + apply hlim.congr + intro s + ring + +theorem normalized_f_tendsto_one : Tendsto (f sieveA) atTop (𝓝 1) := by + have hlim := (normalized_pair_sum_tendsto_two.sub (pair_gap_tendsto_zero sieveA)).div_const 2 + norm_num at hlim + apply hlim.congr + intro s + ring + +end NumberTheoryLean.BuchstabBridge + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/CRTPrimeCost.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CRTPrimeCost.lean new file mode 100644 index 0000000000000000000000000000000000000000..790b9ea5224d9ced1e70d02633ef70be7bcb9adf --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CRTPrimeCost.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceSamplePopulation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseSampleCost +open ErdosInverseSampling +attribute [local instance] Classical.decEq + +noncomputable def primeCost (U : Finset ℕ) (h M0 : ℕ) [NeZero M0] + (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) (p : ℕ) (s : Sample U h) : ℝ := + ((p : ℝ)/(M0 : ℝ))*(∑ v : ZMod M0,∏ i : Fin h,((E p v (s i)).card : ℝ)/((s i).val : ℝ))+ + (M0 : ℝ)*(∏ i : Fin h,((s i).val : ℝ)) + +theorem primeCost_nonneg (U : Finset ℕ) (h M0 : ℕ) [NeZero M0] + (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) (p : ℕ) (s : Sample U h) : + 0 ≤ primeCost U h M0 E p s := by unfold primeCost;positivity + +theorem primeCost_average_bound (U : Finset ℕ) (h M0 : ℕ) [NeZero M0] + (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) (p : ℕ) (tau T : ℝ) + (hU : 0 < U.card) (hh : h ≤ U.card) + (hPref : (U.card : ℝ)^h/(U.card.descFactorial h : ℝ) ≤ 2) + (hMean : ∀ v : ZMod M0,(∑ u : U,((E p v u).card : ℝ)/(u.val : ℝ))/(U.card : ℝ) ≤ tau) + (hCap : ∀ u : U,(u.val : ℝ) ≤ T) : + sampleAverage U h (primeCost U h M0 E p) ≤ 2*(p : ℝ)*tau^h+(M0 : ℝ)*T^h := by + have hRatio : ∀ (v : ZMod M0) (u : U),0 ≤ ((E p v u).card : ℝ)/(u.val : ℝ) := by + intro v u + positivity + have hProduct : ∀ v : ZMod M0, + sampleAverage U h (fun s => ∏ i : Fin h,((E p v (s i)).card : ℝ)/((s i).val : ℝ)) ≤ 2*tau^h := by + intro v + have hm0 : 0 ≤ (∑ u : U,((E p v u).card : ℝ)/(u.val : ℝ))/(U.card : ℝ) := + div_nonneg (Finset.sum_nonneg (fun u _ => hRatio v u)) (Nat.cast_nonneg _) + calc + _ ≤ ((U.card : ℝ)^h/(U.card.descFactorial h : ℝ))* + ((∑ u : U,((E p v u).card : ℝ)/(u.val : ℝ))/(U.card : ℝ))^h := + sample_product_average_le U h (fun u => ((E p v u).card : ℝ)/(u.val : ℝ)) (hRatio v) hU hh + _ ≤ 2*tau^h := mul_le_mul hPref (pow_le_pow_left₀ hm0 (hMean v) h) + (pow_nonneg hm0 h) (by norm_num) + have hRound : sampleAverage U h (fun s => ∏ i : Fin h,((s i).val : ℝ)) ≤ T^h := + sampleAverage_product_bound U h hh (fun u => (u.val : ℝ)) T (fun u => Nat.cast_nonneg _) hCap + have hM : (M0 : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (NeZero.ne M0) + unfold primeCost + rw [sampleAverage_add,sampleAverage_mul,sampleAverage_mul,sampleAverage_sum] + calc + _ ≤ ((p : ℝ)/(M0 : ℝ))*(∑ _v : ZMod M0,2*tau^h)+(M0 : ℝ)*T^h := + add_le_add (mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun v _ => hProduct v)) (by positivity)) + (mul_le_mul_of_nonneg_left hRound (Nat.cast_nonneg _)) + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,ZMod.card,nsmul_eq_mul] + field_simp + +end ErdosInverseSampleCost + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ClockExponentialTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ClockExponentialTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..516d23a85d8d1cd0cacbfda624874b3017efdd2a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ClockExponentialTail.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.ClockTailReward + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal + +lemma spacing_tail_exponential {eta : ℝ} (heta : 0 < eta) (a : ℝ) : + markedSpacingLaw (Ioi a) ≤ ENNReal.ofReal (Real.exp (-eta*a))*costTransform markedSpacingLaw eta := by + calc + _ = ∫⁻ G, (Ioi a).indicator (fun _ => (1:ℝ≥0∞)) G ∂markedSpacingLaw := by + rw [lintegral_indicator measurableSet_Ioi] + simp + _ ≤ ∫⁻ G, ENNReal.ofReal (Real.exp (-eta*a))*ENNReal.ofReal (Real.exp (eta*G)) ∂markedSpacingLaw := by + apply lintegral_mono + intro G + by_cases hG : G ∈ Ioi a + · rw [indicator_of_mem hG] + change (1:ℝ≥0∞) ≤ ENNReal.ofReal (Real.exp (-eta*a))*ENNReal.ofReal (Real.exp (eta*G)) + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le,← Real.exp_add] + have he : (1:ℝ) ≤ Real.exp (-eta*a+eta*G) := Real.one_le_exp_iff.mpr (by change a spacing_tail_exponential heta (H+j)) + _ = (∑' j : ℕ, ENNReal.ofReal (Real.exp (-eta*(H+j))))*costTransform markedSpacingLaw eta := ENNReal.tsum_mul_right + _ = _ := by rw [exponential_tail_sum]; ac_rfl + +theorem clockOvershoot_exponential : ∃ eta C : ℝ, 0 < eta ∧ 0 < C ∧ ∀ v H : ℝ, + 0 < v → 0 ≤ H → clockOvershoot v H ≤ ENNReal.ofReal (C*Real.exp (-eta*H)) := by + obtain ⟨eta,heta,_hWait,hMoment⟩ := marked_waiting_common_exponential_moment + obtain ⟨B,hB,hreward⟩ := clock_renewal_reward_tail_bound + let r : ℝ≥0∞ := ENNReal.ofReal (Real.exp (-eta)) + have hr : r < 1 := by + dsimp [r] + exact ENNReal.ofReal_lt_one.mpr (Real.exp_lt_one_iff.mpr (by linarith)) + have hInv : (1-r)⁻¹ < ∞ := lt_top_iff_ne_top.mpr (ENNReal.inv_ne_top.mpr (tsub_pos_iff_lt.mpr hr).ne') + let K : ℝ≥0∞ := ENNReal.ofReal B*costTransform markedSpacingLaw eta*(1-r)⁻¹ + have hK : K < ∞ := ENNReal.mul_lt_top + (ENNReal.mul_lt_top (lt_top_iff_ne_top.mpr ENNReal.ofReal_ne_top) hMoment) hInv + let C : ℝ := K.toReal+1 + have hC : 0 < C := by dsimp [C]; positivity + have hKC : K ≤ ENNReal.ofReal C := by + calc + _ = ENNReal.ofReal K.toReal := (ENNReal.ofReal_toReal hK.ne).symm + _ ≤ _ := ENNReal.ofReal_le_ofReal (by dsimp [C]; linarith) + refine ⟨eta,C,heta,hC,?_⟩ + intro v H hv _hH + calc + _ ≤ ENNReal.ofReal B*(∑' j : ℕ, markedSpacingLaw (Ioi (H+j))) := + (clockOvershoot_le_reward hv H).trans (hreward v H) + _ ≤ ENNReal.ofReal B*(costTransform markedSpacingLaw eta*(1-r)⁻¹* + ENNReal.ofReal (Real.exp (-eta*H))) := mul_le_mul_right (spacing_tail_series_bound heta H) _ + _ = K*ENNReal.ofReal (Real.exp (-eta*H)) := by dsimp [K]; ac_rfl + _ ≤ ENNReal.ofReal C*ENNReal.ofReal (Real.exp (-eta*H)) := mul_le_mul_left hKC _ + _ = _ := (ENNReal.ofReal_mul hC.le).symm + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ClosedEulerIndividualUpper.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ClosedEulerIndividualUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..3355d36768f356dd1e34728fd12b22f4f4981de1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ClosedEulerIndividualUpper.lean @@ -0,0 +1,127 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.HypotheticalIndividualUpper +import OAI.NumberTheory.Jacobsthal.Primes.ReferenceSourcePrimeSets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseEuler +open NumberTheoryLean ErdosPrimeInputs.MertensStrong + +theorem cutoffPrimes_eq_filtered_Ioc (z : ℕ) : + LargePrimeDeletion.cutoffPrimes z = (Finset.Ioc 0 z).filter Nat.Prime := by + ext p + rw [LargePrimeDeletion.mem_cutoffPrimes] + simp only [Finset.mem_filter,Finset.mem_Ioc] + exact ⟨fun h => ⟨⟨h.1.pos,h.2⟩,h.1⟩,fun h => ⟨h.2,h.1.2⟩⟩ + +theorem smallEuler_eq_primeProduct (w : ℝ) : + SmallSieveFinite.smallEuler ⌊w⌋₊ = primeProduct w := by + unfold SmallSieveFinite.smallEuler primeProduct + rw [cutoffPrimes_eq_filtered_Ioc] + simp only [one_div] + +open _root_.Filter +open scoped Topology + +theorem smallEuler_log_bounds : ∀ᶠ w : ℝ in atTop, + 2 ≤ w ∧ 0 < SmallSieveFinite.smallEuler ⌊w⌋₊ ∧ + Real.exp (-Real.eulerMascheroniConstant)/(2*Real.log w) ≤ SmallSieveFinite.smallEuler ⌊w⌋₊ ∧ + (SmallSieveFinite.smallEuler ⌊w⌋₊)⁻¹ ≤ 2*Real.exp Real.eulerMascheroniConstant*Real.log w := by + have hnorm := (tendsto_order.mp ReferenceMertens.normalization_tendsto_one).2 2 (by norm_num) + filter_upwards [hnorm,eventually_ge_atTop (2 : ℝ)] with w hn hw + have hw0 : 0 < w := by linarith + have hL : 0 < Real.log w := Real.log_pos (by linarith) + have hV : 0 < SmallSieveFinite.smallEuler ⌊w⌋₊ := + (inv_pos.mpr hw0).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw) + have hn' : Real.exp (-Real.eulerMascheroniConstant)/ + (Real.log w*SmallSieveFinite.smallEuler ⌊w⌋₊) ≤ 2 := by + simpa only [ReferenceMertens.normalization,← smallEuler_eq_primeProduct] using hn.le + have hprod := (div_le_iff₀ (mul_pos hL hV)).mp hn' + have hlo : Real.exp (-Real.eulerMascheroniConstant)/(2*Real.log w) ≤ SmallSieveFinite.smallEuler ⌊w⌋₊ := by + apply (div_le_iff₀ (by positivity : 0 < 2*Real.log w)).mpr + nlinarith + have hlowpos : 0 < Real.exp (-Real.eulerMascheroniConstant)/(2*Real.log w) := by positivity + have hi := (inv_le_inv₀ hV hlowpos).mpr hlo + refine ⟨hw,hV,hlo,?_⟩ + calc + _ ≤ (Real.exp (-Real.eulerMascheroniConstant)/(2*Real.log w))⁻¹ := hi + _ = 2*Real.exp Real.eulerMascheroniConstant*Real.log w := by + rw [inv_div,Real.exp_neg,div_inv_eq_mul] + ring + +end ErdosInverseEuler + +end + +section + +namespace ErdosStoppedArithmetic +open NumberTheoryLean ErdosInverseCounts ErdosInverseEuler + ErdosPrimeInputs.MertensStrong ReferenceProductsBasics +attribute [local instance] Classical.propDecidable + +theorem smallEuler_nat_primeProduct (P : ℕ) : + SmallSieveFinite.smallEuler P=primeProduct (P : ℝ) := by + simpa only [Nat.floor_natCast] using smallEuler_eq_primeProduct (P : ℝ) + +theorem smallEuler_prime_step (P : ℕ) (hP : P.Prime) : + SmallSieveFinite.smallEuler P=(1-(P : ℝ)⁻¹)*SmallSieveFinite.smallEuler (P-1) := by + have hset : LargePrimeDeletion.cutoffPrimes P = insert P (LargePrimeDeletion.cutoffPrimes (P-1)) := by + ext p + simp only [LargePrimeDeletion.mem_cutoffPrimes,Finset.mem_insert] + constructor + · rintro ⟨hp,hpP⟩ + by_cases he : p=P + · exact Or.inl he + · exact Or.inr ⟨hp,by omega⟩ + · rintro (rfl | ⟨hp,hpP⟩) + · exact ⟨hP,le_rfl⟩ + · exact ⟨hp,by omega⟩ + have hnot : P ∉ LargePrimeDeletion.cutoffPrimes (P-1) := by + rw [LargePrimeDeletion.mem_cutoffPrimes] + have hp := hP.pos + omega + unfold SmallSieveFinite.smallEuler + rw [hset,Finset.prod_insert hnot] + +theorem smallEuler_strict_le_two_closed (P : ℕ) (hP : P.Prime) : + SmallSieveFinite.smallEuler (P-1) ≤ 2*primeProduct (P : ℝ) := by + have hV : 0 ≤ SmallSieveFinite.smallEuler (P-1) := by + rw [smallEuler_nat_primeProduct] + exact (actual_primeProduct_pos _).le + have hp : (0 : ℝ) < P := by exact_mod_cast hP.pos + have h2 : (2 : ℝ) ≤ P := by exact_mod_cast hP.two_le + have hinv : (P : ℝ)⁻¹ ≤ 1/2 := by rw [← one_div];exact (div_le_iff₀ hp).mpr (by linarith) + have hfactor := mul_le_mul_of_nonneg_right (show (1/2 : ℝ) ≤ 1-(P : ℝ)⁻¹ by linarith) hV + rw [← smallEuler_nat_primeProduct P,smallEuler_prime_step P hP] + nlinarith + +theorem original_individual_upper_closed : + ∃ C : ℝ,0 < C ∧ ∃ P0 : ℕ,2 ≤ P0 ∧ ∀ P : ℕ,P.Prime → P0 ≤ P → + ∀ (Y d : ℕ) (a : ℕ → ℕ),0 < Y → Squarefree d → + (∀ t ∈ d.primeFactors,P ≤ t) → (P : ℝ)^2 ≤ (Y : ℝ)/(d : ℝ) → + (modulusCount Y (LargePrimeDeletion.cutoffPrimes (P-1)) a d : ℝ) ≤ + C*((Y : ℝ)/(d : ℝ))*primeProduct (P : ℝ) := by + obtain ⟨C,hC,P0,hP0,hUpper⟩ := original_individual_upper + refine ⟨2*C,by positivity,P0,hP0,?_⟩ + intro P hPrime hP Y d a hY hd hlarge hJ + have hU := hUpper P hP Y d a hY hd hlarge hJ + have hE := smallEuler_strict_le_two_closed P hPrime + have hm := mul_le_mul_of_nonneg_left hE + (show 0 ≤ C*((Y : ℝ)/(d : ℝ)) by positivity) + calc + _ ≤ C*((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler (P-1) := hU + _ ≤ C*((Y : ℝ)/(d : ℝ))*(2*primeProduct (P : ℝ)) := hm + _ = _ := by ring + +end ErdosStoppedArithmetic + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/CofactorAllChoiceBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CofactorAllChoiceBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..28bdd71ea09766a9b496772ab89b061b300978c8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CofactorAllChoiceBounds.lean @@ -0,0 +1,105 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.BoundedEdgeBins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ParentCofactorChoices +open ErdosCofactorChoices ErdosSubsetWord BinCutSelections AssembleAtBin SingletonBinSelection SingletonBinProduct +open BinCutPrefixGeometry +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition + +attribute [local instance] Classical.propDecidable + +noncomputable def parentCofactorMultiplicity {n : ℕ} (m : Fin n → ℕ) (i j : Fin n) : Fin n → ℕ := + eraseMultiplicity (aboveMultiplicity m j) i +noncomputable def completeParent {n : ℕ} (anchor f : Fin n → Finset ℕ) (i j : Fin n) (p u : ℕ) : Fin n → Finset ℕ := + assemble anchor (fillSelection f i p) j u + +theorem cofactor_slots_zero {n : ℕ} (m : Fin n → ℕ) (i j : Fin n) : + parentCofactorMultiplicity m i j i=0 ∧ parentCofactorMultiplicity m i j j=0 := by + simp [parentCofactorMultiplicity,eraseMultiplicity,aboveMultiplicity] + +theorem cofactor_total_le {n : ℕ} (m : Fin n → ℕ) (i j : Fin n) : + (∑ k,parentCofactorMultiplicity m i j k) ≤ ∑ k,m k := by + apply Finset.sum_le_sum + intro k _ + simp only [parentCofactorMultiplicity,eraseMultiplicity,aboveMultiplicity] + split_ifs <;> omega + +theorem complete_parent_mem {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i j : Fin n) (hji : j < i) (hi : m i=1) (hj : m j=1) + (anchor f : Fin n → Finset ℕ) (ha : anchor ∈ selections P m) + (hf : f ∈ selections P (parentCofactorMultiplicity m i j)) (p u : ℕ) (hp : p ∈ P i) (hu : u ∈ P j) : + completeParent anchor f i j p u ∈ selections P m := by + have hmi : aboveMultiplicity m j i=1 := by simp [aboveMultiplicity,hji,hi] + exact assembled_mem P m anchor _ j u ha (fill_selection_mem P _ i hmi f hf p hp) hj hu + +theorem complete_parent_product {w top xi : ℝ} (_hw : 1 < w) (_htop : w < top) (_hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (i j : Fin (binCount w top xi)) (hji : j < i) (hi : m i=1) + (anchor f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) (parentCofactorMultiplicity m i j)) + (p u : ℕ) (hp : p ∈ globalBins w top xi i) : + selectionProduct (aboveSelection (completeParent anchor f i j p u) j)=p*selectionProduct f := by + have hmi : aboveMultiplicity m j i=1 := by simp [aboveMultiplicity,hji,hi] + have hfill := fill_selection_mem (globalBins w top xi) _ i hmi f hf p hp + rw [completeParent,assembled_above _ m anchor _ j u hfill] + exact filled_product f i p (erased_coordinate_empty _ (aboveMultiplicity m j) i f hf) +end NumberTheoryLean.ParentCofactorChoices + + + +namespace NumberTheoryLean.CofactorAllChoiceBounds +open FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport +open ErdosCofactorChoices ErdosSubsetWord BinCutSelections AssembleAtBin ParentCofactorChoices +open FullBoxLengthBounds BoundedEdgeBins SafeSubsetBoxGeometry +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition + +attribute [local instance] Classical.propDecidable + +theorem cofactor_all_choice_lengths {w top xi B C K a M X : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) + (hcomp : Real.log B ≤ 2*Real.log w) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) + (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) + (i j : Fin (binCount w top xi)) (hji : j < i) (hi : m i=1) + (hj : boundedEdgeBin w top xi Y m M X j) : + (∀ q ∈ cofactorChoices (globalBins w top xi) (parentCofactorMultiplicity m i j), + ∀ p ∈ globalBins w top xi i,Real.log ((Y:ℝ)/((p:ℝ)*(q:ℝ)))/Real.log w ≤ M+2*C*xi) ∧ + (∀ q ∈ cofactorChoices (globalBins w top xi) (parentCofactorMultiplicity m i j), + ∀ p ∈ globalBins w top xi i,∀ u ∈ globalBins w top xi j, + a ≤ Real.log ((Y:ℝ)/((p:ℝ)*(q:ℝ)*(u:ℝ)))/Real.log w) := by + have hmj := bounded_edge_singleton m j hj + obtain ⟨g,hgmem,u₀,hgju,hparent,_hx⟩ := hj + have hu₀ : u₀ ∈ globalBins w top xi j := ((mem_selections _ _ _).mp hgmem j).1 (by rw [hgju]; simp) + have hlen := anchor_total_length hw htop hxi z m ha + have hall : ∀ f ∈ selections (globalBins w top xi) (parentCofactorMultiplicity m i j), + ∀ p ∈ globalBins w top xi i,∀ u ∈ globalBins w top xi j, + Real.log ((Y:ℝ)/((p:ℝ)*(selectionProduct f:ℝ)))/Real.log w ≤ M+2*C*xi ∧ + a ≤ Real.log ((Y:ℝ)/((p:ℝ)*(selectionProduct f:ℝ)*(u:ℝ)))/Real.log w := by + intro f hf p hp u hu + let F := completeParent g f i j p u + have hF : F ∈ selections (globalBins w top xi) m := complete_parent_mem _ m i j hji hi hmj g f hgmem hf p u hp hu + have hFu : F j={u} := assembled_edge _ _ j u + have hprod : selectionProduct (aboveSelection F j)=p*selectionProduct f := complete_parent_product hw htop hxi m i j hji hi g f hf p u hp + have hmove := parent_length_movement hw htop hxi hC hcomp Y hY z hroot m hlen F g hF hgmem j + have hupper : parentLength w Y F j ≤ M+2*C*xi := by linarith [(abs_le.mp hmove).2] + have hlower := full_box_child_length_lower hw htop hxi hC hcomp Y hY z hroot hs hz hg hclosed hcap m ha F hF j u hFu + simpa only [parentLength,childLength,hprod,Nat.cast_mul] using And.intro hupper hlower + constructor + · intro q hq p hp + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp hq + exact (hall f hf p hp u₀ hu₀).1 + · intro q hq p hp u hu + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp hq + exact (hall f hf p hp u hu).2 +end NumberTheoryLean.CofactorAllChoiceBounds + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/CompactExponentialMoments.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CompactExponentialMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5fec15f137ac7a0ac111f7c8bb243c55a047ec8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CompactExponentialMoments.lean @@ -0,0 +1,162 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.RegenerationDrift + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.CompactExponentialMoments + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open DerivativeWeights WeightFutureIntegrals WeightTailBounds +open TransitionKernels RegenerationTails RegenerationDrift + +theorem exponential_moment_of_upper_tail (μ : Measure ℝ) [IsProbabilityMeasure μ] (m : ℝ) + (htail : ∀ h : ℝ, 0 ≤ h → μ (Ici (m + h)) ≤ ENNReal.ofReal (Real.exp (-2 * h))) : + (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂μ) ≤ ENNReal.ofReal (2 * Real.exp m) := by + let q : ℝ → ℝ := fun x => max m x + have hq : Measurable q := measurable_const.max measurable_id + let ν := μ.map q + let : IsProbabilityMeasure ν := + (Measure.isProbabilityMeasure_map_iff (μ := μ) hq.aemeasurable).mpr inferInstance + have hs : ∀ᵐ x ∂ν, m ≤ x := by + apply (ae_map_iff hq.aemeasurable measurableSet_Ici).mpr + exact Eventually.of_forall (fun x => le_max_left m x) + have ht : ∀ h : ℝ, 0 ≤ h → ν (Ici (m + h)) ≤ ENNReal.ofReal (Real.exp (-2 * h)) := by + intro h hh + by_cases h0 : h = 0 + · subst h + simp only [mul_zero, Real.exp_zero, ENNReal.ofReal_one] + exact le_trans (measure_mono (subset_univ _)) (by rw [measure_univ]) + · change μ.map q (Ici (m + h)) ≤ _ + rw [Measure.map_apply hq measurableSet_Ici] + have hpre : q ⁻¹' Ici (m + h) = Ici (m + h) := by + ext x + change (m + h ≤ max m x) ↔ m + h ≤ x + rw [le_max_iff] + constructor + · intro hx + rcases hx with hx | hx + · exfalso + have hh0 : 0 < h := lt_of_le_of_ne hh (Ne.symm h0) + linarith + · exact hx + · exact Or.inr + rw [hpre] + exact htail h hh + calc + _ ≤ ∫⁻ x, ENNReal.ofReal (Real.exp (q x)) ∂μ := lintegral_mono (fun x => + ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr (le_max_right m x))) + _ = ∫⁻ x, ENNReal.ofReal (Real.exp x) ∂ν := + (lintegral_map (ENNReal.measurable_ofReal.comp Real.measurable_exp) hq).symm + _ ≤ _ := exponential_moment_of_tail ν m hs ht + +theorem exponential_integrable_of_upper_tail (μ : Measure ℝ) [IsProbabilityMeasure μ] (m : ℝ) + (htail : ∀ h : ℝ, 0 ≤ h → μ (Ici (m + h)) ≤ ENNReal.ofReal (Real.exp (-2 * h))) : + Integrable Real.exp μ := by + refine ⟨Real.continuous_exp.aestronglyMeasurable, ?_⟩ + apply (hasFiniteIntegral_iff_ofReal (Eventually.of_forall (fun x => (Real.exp_pos x).le))).mpr + exact lt_of_le_of_lt (exponential_moment_of_upper_tail μ m htail) ENNReal.ofReal_lt_top + +theorem evenKernel_tail_above (s : EvenState) {v : ℝ} (hv : s.1 ≤ v) : + evenKernel s (Ici (v - 1)) = ENNReal.ofReal (phiEven v / phiEven s.1) := by + have h := evenKernel_tail s (sub_nonneg.mpr hv) + rw [show s.1 - 1 + (v - s.1) = v - 1 by ring, + show s.1 + (v - s.1) = v by ring] at h + exact h + +theorem oddKernel_tail_above (s : OddState) {v : ℝ} (hv : max 3 s.1 ≤ v) : + oddKernel s (Ici (v - 1)) = ENNReal.ofReal (phiOdd v / phiOdd s.1) := by + rw [oddKernel_apply, ← ofReal_integral_eq_lintegral_ofReal + (oddDensity_integrable s).integrableOn (Eventually.of_forall (oddDensity_nonneg s))] + congr 1 + change (∫ t in Ici (v - 1), tailDensity (max 2 (s.1 - 1)) (phiOdd s.1) + (fun t => W t * phiEven t) t) = _ + have hv3 := le_trans (le_max_left (3 : ℝ) s.1) hv + have hvs := le_trans (le_max_right (3 : ℝ) s.1) hv + rw [tailDensity_setIntegral (by apply max_le <;> linarith), integral_Ici_eq_integral_Ioi] + have hf := (phiOdd_future_integral v).2 + rw [max_eq_right (show 2 ≤ v - 1 by linarith)] at hf + rw [← hf] + +theorem kernel_uniform_upper_tails : ∃ U : ℝ, 4 ≤ U ∧ + (∀ V : ℝ, U ≤ V → ∀ s : EvenState, s.1 ≤ V → ∀ h : ℝ, 0 ≤ h → + evenKernel s (Ici (V - 1 + h)) ≤ ENNReal.ofReal (Real.exp (-2 * h))) ∧ + (∀ V : ℝ, U ≤ V → ∀ s : OddState, s.1 ≤ V → ∀ h : ℝ, 0 ≤ h → + oddKernel s (Ici (V - 1 + h)) ≤ ENNReal.ofReal (Real.exp (-2 * h))) := by + obtain ⟨U, hU, hb⟩ := weights_logDeriv_growth 2 + refine ⟨U, hU, ?_, ?_⟩ + · intro V hV s hs h hh + rw [show V - 1 + h = V + h - 1 by ring, evenKernel_tail_above s (by linarith)] + apply ENNReal.ofReal_le_ofReal + apply (div_le_iff₀ (phiEven_pos (by linarith [s.2]))).mpr + have hx := exponential_comparison (P := phiEven) + (fun t ht => phiEven_pos (by linarith)) + (fun t ht => (phiEven_hasDerivAt (by linarith)).differentiableAt) + (fun t ht => (hb t ht).1) hV (show V ≤ V + h by linarith) + rw [add_sub_cancel_left] at hx + have hm : phiEven V ≤ phiEven s.1 := + phiEven_strictAntiOn.antitoneOn (by change 1 < s.1; linarith [s.2]) (by change 1 < V; linarith) hs + exact le_trans hx (by nlinarith [mul_le_mul_of_nonneg_right hm (Real.exp_pos (-2 * h)).le]) + · intro V hV s hs h hh + rw [show V - 1 + h = V + h - 1 by ring, oddKernel_tail_above s (by apply max_le <;> linarith)] + apply ENNReal.ofReal_le_ofReal + apply (div_le_iff₀ (phiOdd_pos s.1)).mpr + have hx := exponential_comparison (P := phiOdd) (fun t _ => phiOdd_pos t) + (fun t ht => (phiOdd_hasDerivAt (by linarith)).differentiableAt) + (fun t ht => (hb t ht).2) hV (show V ≤ V + h by linarith) + rw [add_sub_cancel_left] at hx + have hm := phiOdd_antitone hs + exact le_trans hx (by nlinarith [mul_le_mul_of_nonneg_right hm (Real.exp_pos (-2 * h)).le]) + +theorem kernel_compact_exponential_moments (S : ℝ) : ∃ C : ℝ, 0 < C ∧ + (∀ s : EvenState, s.1 ≤ S → Integrable Real.exp (evenKernel s) ∧ + (∫ t, Real.exp t ∂evenKernel s) ≤ C) ∧ + (∀ s : OddState, s.1 ≤ S → Integrable Real.exp (oddKernel s) ∧ + (∫ t, Real.exp t ∂oddKernel s) ≤ C) := by + obtain ⟨U, _, he, ho⟩ := kernel_uniform_upper_tails + let V := max U S + let C := 2 * Real.exp (V - 1) + have hC : 0 < C := by dsimp [C]; positivity + refine ⟨C, hC, ?_, ?_⟩ + · intro s hs + have ht := he V (le_max_left _ _) s (le_trans hs (le_max_right _ _)) + have hi := exponential_integrable_of_upper_tail (evenKernel s) (V - 1) ht + refine ⟨hi, (ENNReal.ofReal_le_ofReal_iff hC.le).mp ?_⟩ + rw [ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall (fun t => (Real.exp_pos t).le))] + exact exponential_moment_of_upper_tail _ (V - 1) ht + · intro s hs + have ht := ho V (le_max_left _ _) s (le_trans hs (le_max_right _ _)) + have hi := exponential_integrable_of_upper_tail (oddKernel s) (V - 1) ht + refine ⟨hi, (ENNReal.ofReal_le_ofReal_iff hC.le).mp ?_⟩ + rw [ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall (fun t => (Real.exp_pos t).le))] + exact exponential_moment_of_upper_tail _ (V - 1) ht + +theorem kernel_global_drift : ∃ C : ℝ, 0 < C ∧ + (∀ s : EvenState, Integrable Real.exp (evenKernel s) ∧ + (∫ t, Real.exp t ∂evenKernel s) ≤ driftFactor * Real.exp s.1 + C) ∧ + (∀ s : OddState, Integrable Real.exp (oddKernel s) ∧ + (∫ t, Real.exp t ∂oddKernel s) ≤ driftFactor * Real.exp s.1 + C) := by + obtain ⟨U, _, he, ho⟩ := kernel_drift_expectation + obtain ⟨C, hC, heC, hoC⟩ := kernel_compact_exponential_moments U + refine ⟨C, hC, ?_, ?_⟩ + · intro s + by_cases hs : U ≤ s.1 + · exact ⟨(he s hs).1, by linarith [(he s hs).2]⟩ + · exact ⟨(heC s (le_of_not_ge hs)).1, by + nlinarith [(heC s (le_of_not_ge hs)).2, mul_pos driftFactor_pos (Real.exp_pos s.1)]⟩ + · intro s + by_cases hs : U ≤ s.1 + · exact ⟨(ho s hs).1, by linarith [(ho s hs).2]⟩ + · exact ⟨(hoC s (le_of_not_ge hs)).1, by + nlinarith [(hoC s (le_of_not_ge hs)).2, mul_pos driftFactor_pos (Real.exp_pos s.1)]⟩ + +end NumberTheoryLean.CompactExponentialMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/CoprimePositionSieve.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CoprimePositionSieve.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f0767adf374149e45215a29086c7efba0ea1366 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/CoprimePositionSieve.lean @@ -0,0 +1,253 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualModelTargets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosVarianceMoments +open NumberTheoryLean ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +def divisorJoint (w : ℝ) (H : ℕ) (C0 : ℤ) (beta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (m : ℤ) (k : ZMod (divisorModulus w H)) : Prop := + ∀ t ∈ divisorPrimes w H,∀ j ∈ S,(k.val : ZMod t)+divisorPhase C0 m t*(j : ZMod t) ≠ beta t + +def coprimeJoint (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (m : ℤ) (p : (ZMod (coprimeModulus w H))ˣ) : Prop := + ∀ t ∈ coprimePrimes w H,∀ j ∈ S,(p.val.val : ZMod t)*(qA : ZMod t)* + ((m : ZMod t)+(H : ZMod t)*(j : ZMod t)) ≠ delta t + +theorem jointCondition_coordinates (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (m : ℤ) (s : Pattern w H) : + jointCondition w H C0 qA beta delta S (m,s) ↔ + divisorJoint w H C0 beta S m s.2 ∧ coprimeJoint w H qA delta S m s.1 := + jointCondition_split w H C0 qA beta delta S (m,s) + +theorem divisorJoint_card (w : ℝ) (H : ℕ) (C0 : ℤ) (beta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (m : ℤ) (hC0 : Int.gcd C0 (H : ℤ) = 1) (hm : m.natAbs.Coprime H) : + (Finset.univ.filter (divisorJoint w H C0 beta S m)).card = + ∏ t ∈ divisorPrimes w H,(t-(positionResidues S t).card) := by + let u (t : ℕ) : (ZMod t)ˣ := + if ht : t ∣ H then divisorPhaseUnit H C0 m hC0 hm t ht else 1 + have hunit (t : ℕ) (ht : t ∈ divisorPrimes w H) : (u t : ZMod t) = divisorPhase C0 m t := by + simp only [u,dite_eq_left (Finset.mem_filter.mp ht).2,divisorPhaseUnit_coe] + have hP (t : ℕ) (ht : t ∈ divisorPrimes w H) : t.Prime := + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1 + let : NeZero (∏ t ∈ divisorPrimes w H,t) := ⟨(divisorModulus_pos w H).ne'⟩ + have hh := prime_unit_avoidance_card (divisorPrimes w H) S hP u beta + have he : Finset.univ.filter (divisorJoint w H C0 beta S m) = + Finset.univ.filter (fun k : ZMod (divisorModulus w H) => + ∀ t ∈ divisorPrimes w H,∀ j ∈ S,(k.val : ZMod t)+(u t : ZMod t)*(j : ZMod t) ≠ beta t) := by + apply Finset.filter_congr + intro k _hk + unfold divisorJoint + exact forall_congr' (fun t => forall_congr' (fun ht => by rw [hunit t ht])) + rw [he] + exact hh + +theorem divisorJoint_card_real (w : ℝ) (H : ℕ) (C0 : ℤ) (beta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (m : ℤ) (hC0 : Int.gcd C0 (H : ℤ) = 1) (hm : m.natAbs.Coprime H) : + ((Finset.univ.filter (divisorJoint w H C0 beta S m)).card : ℝ) = + (divisorModulus w H : ℝ)*jointDensity (divisorPrimes w H) S := by + rw [divisorJoint_card w H C0 beta S m hC0 hm] + exact product_allowed_eq_density _ S (fun _ ht => + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1) + +theorem conditional_pattern_card (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (m : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (hm : m.natAbs.Coprime H) : + (Finset.univ.filter (fun s : Pattern w H => jointCondition w H C0 qA beta delta S (m,s))).card = + (Finset.univ.filter (coprimeJoint w H qA delta S m)).card* + ∏ t ∈ divisorPrimes w H,(t-(positionResidues S t).card) := by + have he : Finset.univ.filter (fun s : Pattern w H => jointCondition w H C0 qA beta delta S (m,s)) = + (Finset.univ.filter (coprimeJoint w H qA delta S m)).product + (Finset.univ.filter (divisorJoint w H C0 beta S m)) := by + ext s + simp only [Finset.mem_filter,Finset.mem_univ,true_and,Finset.product_eq_sprod,Finset.mem_product, + jointCondition_coordinates,and_comm] + rw [he,Finset.product_eq_sprod,Finset.card_product,divisorJoint_card w H C0 beta S m hC0 hm] + +end ErdosVarianceMoments + + + +namespace ErdosVarianceMoments +open NumberTheoryLean ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def patternPrimeUnit (w : ℝ) (H : ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (t : ℕ) (ht : t ∣ coprimeModulus w H) : (ZMod t)ˣ := + Units.map (ZMod.castHom ht (ZMod t)).toMonoidHom p + +theorem patternPrimeUnit_coe (w : ℝ) (H : ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (t : ℕ) (ht : t ∣ coprimeModulus w H) : + (patternPrimeUnit w H p t ht : ZMod t) = (p.val.val : ZMod t) := by + change ZMod.castHom ht (ZMod t) p.val = _ + calc + ZMod.castHom ht (ZMod t) p.val = + ZMod.castHom ht (ZMod t) (p.val.val : ZMod (coprimeModulus w H)) := by rw [ZMod.natCast_zmod_val] + _ = _ := map_natCast (ZMod.castHom ht (ZMod t)) p.val.val + +theorem unit_mul_eq_iff {M : Type*} [Monoid M] (u : Mˣ) (x c : M) : + (u : M)*x = c ↔ x = (u⁻¹ : Mˣ)*c := by + constructor + · intro h + have hh := congrArg (fun y : M => (u⁻¹ : Mˣ)*y) h + simpa only [← mul_assoc,Units.inv_mul,one_mul] using hh + · intro h + rw [h,← mul_assoc,Units.mul_inv,one_mul] + +noncomputable def coprimeCoefficientUnit (w : ℝ) (H qA : ℕ) + (p : (ZMod (coprimeModulus w H))ˣ) (t : ℕ) + (ht : t ∈ coprimePrimes w H) (hqA : qA.Coprime t) : (ZMod t)ˣ := + patternPrimeUnit w H p t (Finset.dvd_prod_of_mem _ ht)*ZMod.unitOfCoprime qA hqA + +noncomputable def coprimeShiftUnit (w : ℝ) (H t : ℕ) (ht : t ∈ coprimePrimes w H) : (ZMod t)ˣ := + ZMod.unitOfCoprime H ((LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1.coprime_iff_not_dvd.mpr (Finset.mem_filter.mp ht).2).symm + +noncomputable def coprimeForbidden (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) (t : ℕ) + (ht : t ∈ coprimePrimes w H) (hqA : qA.Coprime t) : Finset (ZMod t) := + forbiddenClasses S t (coprimeShiftUnit w H t ht) + ((coprimeCoefficientUnit w H qA p t ht hqA)⁻¹*delta t) + +theorem mem_coprimeForbidden (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) (t : ℕ) + (ht : t ∈ coprimePrimes w H) (hqA : qA.Coprime t) (x : ZMod t) : + x ∈ coprimeForbidden w H qA delta S p t ht hqA ↔ + ∃ j ∈ S,(p.val.val : ZMod t)*(qA : ZMod t)*(x+(H : ZMod t)*(j : ZMod t)) = delta t := by + rw [coprimeForbidden,mem_forbiddenClasses] + apply exists_congr + intro j + apply and_congr_right + intro _hj + have hh := unit_mul_eq_iff (coprimeCoefficientUnit w H qA p t ht hqA) + (x+(H : ZMod t)*(j : ZMod t)) (delta t) + have hc : (coprimeCoefficientUnit w H qA p t ht hqA : ZMod t) = + (p.val.val : ZMod t)*(qA : ZMod t) := by + simpa only [coprimeCoefficientUnit,Units.val_mul,ZMod.coe_unitOfCoprime] using + congrArg (fun v : ZMod t => v*(qA : ZMod t)) + (patternPrimeUnit_coe w H p t (Finset.dvd_prod_of_mem _ ht)) + rw [hc] at hh + simpa only [coprimeShiftUnit,ZMod.coe_unitOfCoprime] using hh.symm + +theorem coprimeForbidden_card (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) (t : ℕ) + (ht : t ∈ coprimePrimes w H) (hqA : qA.Coprime t) : + (coprimeForbidden w H qA delta S p t ht hqA).card = (positionResidues S t).card := + forbiddenClasses_card _ _ _ _ + +end ErdosVarianceMoments + + + +namespace ErdosVarianceMoments +open NumberTheoryLean ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def coprimeForbiddenFamily (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) (t : ℕ) : Finset (ZMod t) := + if ht : t ∈ coprimePrimes w H then coprimeForbidden w H qA delta S p t ht (hqA t ht) else ∅ + +theorem coprimeForbiddenFamily_card (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) (t : ℕ) (ht : t ∈ coprimePrimes w H) : + (coprimeForbiddenFamily w H qA delta S p hqA t).card = (positionResidues S t).card := by + simp only [coprimeForbiddenFamily,dite_eq_left ht,coprimeForbidden_card] + +theorem coprimeJoint_avoidance (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) (m : ℤ) : + coprimeJoint w H qA delta S m p ↔ + ∀ t ∈ coprimePrimes w H,(m : ZMod t) ∉ coprimeForbiddenFamily w H qA delta S p hqA t := by + unfold coprimeJoint + apply forall_congr' + intro t + apply forall_congr' + intro ht + simp only [coprimeForbiddenFamily,dite_eq_left ht,mem_coprimeForbidden,not_exists,not_and] + +theorem nonzero_positionDensity_two (P S : Finset ℕ) (hS : S.card ≤ 2) + (hne : jointDensity P S ≠ 0) (h2 : 2 ∈ P) : positionDensity S 2 ≤ 1/2 := by + have hn : 1-positionDensity S 2 ≠ 0 := (Finset.prod_ne_zero_iff.mp hne) 2 h2 + have hcard := positionResidues_le_positions S 2 + have hnot : (positionResidues S 2).card ≠ 2 := by + intro he + apply hn + norm_num [positionDensity,he] + have hle : (positionResidues S 2).card ≤ 1 := by omega + unfold positionDensity + exact div_le_div_of_nonneg_right (by exact_mod_cast hle) (by norm_num) + +noncomputable def coprimePositionSurvivors (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) (b c : ℝ) : Finset ℤ := + (unitIntervalIntegers H b c).filter (fun m => coprimeJoint w H qA delta S m p) + +theorem coprimePositionSurvivors_sieve_sum (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) (b c : ℝ) : + ((coprimePositionSurvivors w H qA delta S p b c).card : ℝ) = + ∑ m ∈ unitIntervalIntegers H b c,(1 : ℝ)*BonferroniBlocks.survives (coprimePrimes w H) + (fun t => (m : ZMod t) ∈ coprimeForbiddenFamily w H qA delta S p hqA t) := by + rw [coprimePositionSurvivors,Finset.card_filter,Nat.cast_sum] + simp only [Nat.cast_ite,Nat.cast_one,Nat.cast_zero,one_mul,BonferroniBlocks.survives, + coprimeJoint_avoidance w H qA delta S p hqA] + apply Finset.sum_congr rfl + intro m _hm + split_ifs <;> rfl + +theorem coprimePositionSurvivors_estimate (w : ℝ) (hw : 2 ≤ w) (s : ℝ) (hs : 480024 ≤ s) + (H qA : ℕ) (hH : 0 < H) (delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (hS : S.card ≤ 2) + (p : (ZMod (coprimeModulus w H))ˣ) (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) + (b c : ℝ) (hbc : b ≤ c) (hne : jointDensity (coprimePrimes w H) S ≠ 0) : + |((coprimePositionSurvivors w H qA delta S p b c).card : ℝ)- + ((c-b)*((H.totient : ℝ)/(H : ℝ)))*jointDensity (coprimePrimes w H) S| ≤ + ((c-b)*((H.totient : ℝ)/(H : ℝ)))*jointDensity (coprimePrimes w H) S*Real.exp (-s/96)+ + 4*(H.divisors.card : ℝ)*(w^s)^2 := by + let P := coprimePrimes w H + let E := coprimeForbiddenFamily w H qA delta S p hqA + have hP (t : ℕ) (ht : t ∈ P) : t.Prime := + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1 + have hsize (t : ℕ) (ht : t ∈ P) : (t : ℝ) ≤ w := + (Nat.le_floor_iff (by linarith)).mp (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).2 + have hHP (t : ℕ) (ht : t ∈ P) : H.Coprime t := + ((hP t ht).coprime_iff_not_dvd.mpr (Finset.mem_filter.mp ht).2).symm + have hge (t : ℕ) (ht : t ∈ P) : residueDensity E t = positionDensity S t := by + unfold residueDensity positionDensity + rw [coprimeForbiddenFamily_card w H qA delta S p hqA t ht] + have hg0 (t : ℕ) (ht : t ∈ P) : 0 ≤ residueDensity E t := by + rw [hge t ht] + let : NeZero t := ⟨(hP t ht).ne_zero⟩ + exact (positionDensity_bounds S t).1 + have hdim (t : ℕ) (ht : t ∈ P) : residueDensity E t ≤ 2/(t : ℝ) := by + rw [hge t ht] + let : NeZero t := ⟨(hP t ht).ne_zero⟩ + exact positionDensity_le_two S hS t + have htwo (h2 : 2 ∈ P) : residueDensity E 2 ≤ 1/2 := by + rw [hge 2 h2] + exact nonzero_positionDensity_two P S hS hne h2 + have hX : 0 ≤ (c-b)*((H.totient : ℝ)/(H : ℝ)) := mul_nonneg (sub_nonneg.mpr hbc) (by positivity) + have hprod : (∏ t ∈ P,(1-residueDensity E t)) = jointDensity P S := + Finset.prod_congr rfl (fun t ht => by rw [hge t ht]) + have hf := RealFundamentalSieve.fundamental_lemma (unitIntervalIntegers H b c) (fun _ => 1) + (fun _ _ => by norm_num) (fun t m => (m : ZMod t) ∈ E t) + w s P ((c-b)*((H.totient : ℝ)/(H : ℝ))) (residueDensity E) + hw hs hX hP hsize hg0 hdim htwo + rw [hprod] at hf + rw [coprimePositionSurvivors_sieve_sum w H qA delta S p hqA b c] + have hD : 1 ≤ w^s := Real.one_le_rpow (by linarith) (by linarith) + have hr := remainder_sum_bound H hH P hP hHP E b c hbc w s hD + exact hf.trans (add_le_add le_rfl hr) + +end ErdosVarianceMoments + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/DivisorHarmonic.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/DivisorHarmonic.lean new file mode 100644 index 0000000000000000000000000000000000000000..87737bd6a626a6307fc72f0d9dcb19ea0fb380b4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/DivisorHarmonic.lean @@ -0,0 +1,112 @@ +import Mathlib.Analysis.SpecialFunctions.Sqrt +import Mathlib.NumberTheory.Divisors +import Mathlib.NumberTheory.Harmonic.Bounds +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators + +namespace ErdosHyperbola + +noncomputable def harmonicWeight (N : ℕ) : ℝ := + ∑ n ∈ Finset.Icc 1 N, 1/(n : ℝ) + +theorem harmonicWeight_nonneg (N : ℕ) : 0 ≤ harmonicWeight N := by + unfold harmonicWeight + positivity + +theorem multiple_reciprocal_sum_le (N d : ℕ) (hd : 0 < d) : + (∑ n ∈ (Finset.Icc 1 N).filter (d ∣ ·), 1/(n : ℝ)) ≤ + (1/(d : ℝ))*harmonicWeight N := by + let S := (Finset.Icc 1 N).filter (d ∣ ·) + let f : ℕ → ℕ := fun n => n/d + have hi : Set.InjOn f (S : Set ℕ) := by + intro a ha b hb he + have ha' := (Finset.mem_filter.mp ha).2 + have hb' := (Finset.mem_filter.mp hb).2 + calc + a = d*(a/d) := (Nat.mul_div_cancel' ha').symm + _ = d*(b/d) := by rw [show a/d = b/d from he] + _ = b := Nat.mul_div_cancel' hb' + have hsub : S.image f ⊆ Finset.Icc 1 N := by + intro j hj + obtain ⟨n,hn,rfl⟩ := Finset.mem_image.mp hj + obtain ⟨hnI,hnD⟩ := Finset.mem_filter.mp hn + obtain ⟨hn1,hnN⟩ := Finset.mem_Icc.mp hnI + have he := Nat.mul_div_cancel' hnD + have hjp : 0 < (n/d : ℕ) := by + apply Nat.pos_of_ne_zero + intro hz + rw [hz,mul_zero] at he + omega + exact Finset.mem_Icc.mpr ⟨hjp,(Nat.div_le_self n d).trans hnN⟩ + have heq : (∑ n ∈ S, 1/(n : ℝ)) = + (1/(d : ℝ)) * ∑ j ∈ S.image f, 1/(j : ℝ) := by + rw [Finset.mul_sum,Finset.sum_image] + · apply Finset.sum_congr rfl + intro n hn + have hnD := (Finset.mem_filter.mp hn).2 + dsimp only [f] + rw [one_div_mul_one_div,← Nat.cast_mul,Nat.mul_div_cancel' hnD] + · exact fun a ha b hb he => hi ha hb he + change (∑ n ∈ S, 1/(n : ℝ)) ≤ _ + rw [heq] + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => by positivity) + +theorem sqrt_multiple_sum_le (N d : ℕ) (hd : 0 < d) : + (∑ n ∈ (Finset.Icc 1 N).filter (d ∣ ·), Real.sqrt d/(n : ℝ)) ≤ harmonicWeight N := by + have hd1 : (1 : ℝ) ≤ d := by exact_mod_cast hd + have hdp : (0 : ℝ) < d := by exact_mod_cast hd + have hsqrt : Real.sqrt (d : ℝ) ≤ (d : ℝ) := by + apply Real.sqrt_le_iff.mpr + exact ⟨by positivity, by nlinarith⟩ + have hs : Real.sqrt (d : ℝ)/(d : ℝ) ≤ 1 := (div_le_one hdp).mpr hsqrt + calc + _ = Real.sqrt d * (∑ n ∈ (Finset.Icc 1 N).filter (d ∣ ·),1/(n : ℝ)) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro n _ + ring + _ ≤ Real.sqrt d * ((1/(d : ℝ))*harmonicWeight N) := + mul_le_mul_of_nonneg_left (multiple_reciprocal_sum_le N d hd) (Real.sqrt_nonneg _) + _ = (Real.sqrt (d : ℝ)/(d : ℝ))*harmonicWeight N := by ring + _ ≤ 1*harmonicWeight N := mul_le_mul_of_nonneg_right hs (harmonicWeight_nonneg N) + _ = _ := one_mul _ + +theorem gcd_harmonic_sum_le (N : ℕ) (hN : 0 < N) : + (∑ n ∈ Finset.Icc 1 N, Real.sqrt (Nat.gcd n N)/(n : ℝ)) ≤ + (N.divisors.card : ℝ)*harmonicWeight N := by + calc + _ ≤ ∑ n ∈ Finset.Icc 1 N, ∑ d ∈ N.divisors, + if d ∣ n then Real.sqrt d/(n : ℝ) else 0 := by + apply Finset.sum_le_sum + intro n hn + have hg : Nat.gcd n N ∈ N.divisors := + Nat.mem_divisors.mpr ⟨Nat.gcd_dvd_right _ _,Nat.ne_of_gt hN⟩ + have h := Finset.single_le_sum (s := N.divisors) + (f := fun d => if d ∣ n then Real.sqrt d/(n : ℝ) else 0) + (fun _ _ => by positivity) hg + simpa only [ite_eq_left (Nat.gcd_dvd_left n N)] using h + _ = ∑ d ∈ N.divisors, + ∑ n ∈ (Finset.Icc 1 N).filter (d ∣ ·),Real.sqrt d/(n : ℝ) := by + rw [Finset.sum_comm] + simp only [Finset.sum_filter] + _ ≤ ∑ _d ∈ N.divisors,harmonicWeight N := by + apply Finset.sum_le_sum + intro d hd + exact sqrt_multiple_sum_le N d (Nat.pos_of_mem_divisors hd) + _ = _ := by simp + +end ErdosHyperbola + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/DivisorLogGrowth.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/DivisorLogGrowth.lean new file mode 100644 index 0000000000000000000000000000000000000000..df966c58ec6acf4bdba0f5209fc64ce1bf49e154 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/DivisorLogGrowth.lean @@ -0,0 +1,188 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UnitCyclicBounds +import OAI.NumberTheory.Jacobsthal.Primes.PrimePowerGrowth + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosDivisorBounds + +theorem prime_factor_product (n : ℕ) (hn : n ≠ 0) (eps : ℝ) : + (∏ p ∈ n.primeFactors, ((p : ℝ)^eps)^(n.factorization p)) = (n : ℝ)^eps := by + calc + _ = ∏ p ∈ n.primeFactors, ((p : ℝ)^(n.factorization p))^eps := by + apply Finset.prod_congr rfl + intro p _ + rw [← Real.rpow_mul_natCast (Nat.cast_nonneg p), + ← Real.rpow_natCast_mul (Nat.cast_nonneg p)] + congr 1 + ring + _ = (∏ p ∈ n.primeFactors, (p : ℝ)^(n.factorization p))^eps := + Real.finsetProd_rpow _ _ (fun p _ => by positivity) eps + _ = _ := by + have h : (n : ℝ) = ∏ p ∈ n.primeFactors, (p : ℝ)^(n.factorization p) := by + exact_mod_cast Nat.prod_primeFactors_pow_factorization hn + rw [← h] + +theorem small_factor_product (s : Finset ℕ) (P : ℕ) {B : ℝ} (hB : 1 ≤ B) : + (∏ p ∈ s, if p < P then B else 1) ≤ B^P := by + classical + have hcard : (s.filter (fun p => p < P)).card ≤ P := by + calc + _ ≤ (Finset.range P).card := Finset.card_le_card (by + intro p hp + exact Finset.mem_range.mpr (Finset.mem_filter.mp hp).2) + _ = P := Finset.card_range P + rw [Finset.prod_ite] + simpa using pow_le_pow_right₀ hB hcard + +theorem divisor_subpower {eps : ℝ} (heps : 0 < eps) : + ∃ A : ℝ, 0 < A ∧ ∀ n : ℕ, 1 ≤ n → (n.divisors.card : ℝ) ≤ A*(n : ℝ)^eps := by + classical + obtain ⟨B,hB,hsmall⟩ := local_power_bound heps + obtain ⟨P,hlarge⟩ := large_prime_power_bound heps + refine ⟨B^P, pow_pos (by linarith) _, ?_⟩ + intro n hn + have hn0 : n ≠ 0 := by omega + have hcard : (n.divisors.card : ℝ) = + ∏ p ∈ n.primeFactors, ((n.factorization p : ℝ)+1) := by + exact_mod_cast Nat.card_divisors hn0 + have hlocal (p : ℕ) (hp : p ∈ n.primeFactors) : + (n.factorization p : ℝ)+1 ≤ + (if p < P then B else 1)*((p : ℝ)^eps)^(n.factorization p) := by + by_cases h : p < P + · simpa only [h,ite_true] using hsmall p (Nat.prime_of_mem_primeFactors hp).two_le (n.factorization p) + · simpa only [h,ite_false,one_mul] using hlarge p (by omega) (n.factorization p) + calc + _ = _ := hcard + _ ≤ ∏ p ∈ n.primeFactors, + (if p < P then B else 1)*((p : ℝ)^eps)^(n.factorization p) := + Finset.prod_le_prod₀ (fun p _ => by positivity) hlocal + _ = (∏ p ∈ n.primeFactors, if p < P then B else 1) * + (∏ p ∈ n.primeFactors, ((p : ℝ)^eps)^(n.factorization p)) := Finset.prod_mul_distrib + _ ≤ B^P*(∏ p ∈ n.primeFactors, ((p : ℝ)^eps)^(n.factorization p)) := + mul_le_mul_of_nonneg_right (small_factor_product _ P hB) (by positivity) + _ = _ := by rw [prime_factor_product n hn0 eps] + +theorem divisor_power_subpower (C : ℕ) {eps : ℝ} (heps : 0 < eps) : + ∃ A : ℝ, 0 < A ∧ ∀ n : ℕ, 1 ≤ n → (n.divisors.card : ℝ)^C ≤ A*(n : ℝ)^eps := by + let delta : ℝ := eps/((C : ℝ)+1) + have hden : 0 < (C : ℝ)+1 := by positivity + have hd : 0 < delta := div_pos heps hden + obtain ⟨A,hA,hbound⟩ := divisor_subpower hd + refine ⟨A^C,pow_pos hA _,?_⟩ + intro n hn + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn + have hde : delta*(C : ℝ) ≤ eps := by + have he : delta*((C : ℝ)+1) = eps := by dsimp [delta]; field_simp + nlinarith + + calc + _ ≤ (A*(n : ℝ)^delta)^C := pow_le_pow_left₀ (Nat.cast_nonneg _) (hbound n hn) C + _ = A^C*(n : ℝ)^(delta*(C : ℝ)) := by + rw [mul_pow,Real.rpow_mul_natCast (Nat.cast_nonneg n)] + _ ≤ _ := mul_le_mul_of_nonneg_left + (Real.rpow_le_rpow_of_exponent_le hn1 hde) (pow_nonneg hA.le _) + +end ErdosDivisorBounds + +end + +section + +namespace ErdosUniformMobiusRemainder + +theorem totient_ratio_le_divisors (H : ℕ) (hH : 1 ≤ H) : + (H : ℝ)/(H.totient : ℝ) ≤ (H.divisors.card : ℝ) := by + have hphi : 0 < H.totient := Nat.totient_pos.mpr hH + have hs : H ≤ H.divisors.card*H.totient := by + calc + _ = ∑ d ∈ H.divisors,d.totient := (Nat.sum_totient H).symm + _ ≤ ∑ _d ∈ H.divisors,H.totient := Finset.sum_le_sum (fun d hd => + Nat.le_of_dvd hphi (Nat.totient_dvd_of_dvd (Nat.dvd_of_mem_divisors hd))) + _ = _ := by simp + apply (div_le_iff₀ (show (0 : ℝ) < H.totient by exact_mod_cast hphi)).mpr + exact_mod_cast hs + +theorem divisor_totient_quarter : ∃ C : ℝ,0 < C ∧ ∀ H : ℕ,1 ≤ H → + (H.divisors.card : ℝ)*(H : ℝ)/(H.totient : ℝ) ≤ C*(H : ℝ)^((1 : ℝ)/4) := by + obtain ⟨C,hC,hb⟩ := ErdosDivisorBounds.divisor_power_subpower 2 (by norm_num : (0 : ℝ) < 1/4) + refine ⟨C,hC,?_⟩ + intro H hH + calc + _ = (H.divisors.card : ℝ)*((H : ℝ)/(H.totient : ℝ)) := by ring + _ ≤ (H.divisors.card : ℝ)*(H.divisors.card : ℝ) := + mul_le_mul_of_nonneg_left (totient_ratio_le_divisors H hH) (Nat.cast_nonneg _) + _ = (H.divisors.card : ℝ)^2 := by ring + _ ≤ _ := hb H hH + +theorem divisor_totient_length_bound : ∃ C : ℝ,0 < C ∧ ∀ (H : ℕ) (Y : ℝ), + 1 ≤ H → (H : ℝ) ≤ Y → + (H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ)) ≤ C/Y^((1 : ℝ)/2) := by + obtain ⟨C,hC,hb⟩ := divisor_totient_quarter + refine ⟨C,hC,?_⟩ + intro H Y hH hHY + have hY1 : 1 ≤ Y := (show (1 : ℝ) ≤ H by exact_mod_cast hH).trans hHY + have hY : 0 < Y := by linarith + have hpow : (H : ℝ)^((1 : ℝ)/4) ≤ Y^((1 : ℝ)/2) := + (Real.rpow_le_rpow (Nat.cast_nonneg _) hHY (by norm_num)).trans + (Real.rpow_le_rpow_of_exponent_le hY1 (by norm_num)) + have hroot : 0 < Y^((1 : ℝ)/2) := Real.rpow_pos_of_pos hY _ + have hrootSq : Y^((1 : ℝ)/2)*Y^((1 : ℝ)/2)=Y := by + rw [← Real.rpow_add hY] + norm_num + calc + _ = ((H.divisors.card : ℝ)*(H : ℝ)/(H.totient : ℝ))/Y := by ring + _ ≤ (C*(H : ℝ)^((1 : ℝ)/4))/Y := div_le_div_of_nonneg_right (hb H hH) hY.le + _ ≤ (C*Y^((1 : ℝ)/2))/Y := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hpow hC.le) hY.le + _ = _ := by + apply (div_eq_div_iff hY.ne' hroot.ne').mpr + rw [mul_assoc,hrootSq] + +end ErdosUniformMobiusRemainder + +end + +section + +namespace ErdosHyperbolaWeighted + +theorem divisor_log_square_subpower (C : ℕ) {eps : ℝ} (heps : 0 < eps) : + ∃ A : ℝ, 0 < A ∧ ∀ N : ℕ, 1 ≤ N → + (N.divisors.card : ℝ)^C*(Real.log (2*(N : ℝ)))^2 ≤ A*(N : ℝ)^eps := by + let alpha := eps/2 + let beta := eps/4 + have ha : 0 < alpha := by dsimp [alpha]; positivity + have hb : 0 < beta := by dsimp [beta]; positivity + obtain ⟨A, hA, hdiv⟩ := ErdosDivisorBounds.divisor_power_subpower C ha + let L := (2 : ℝ)^beta/beta + have hL : 0 < L := by dsimp [L]; positivity + refine ⟨A*L^2, by positivity, ?_⟩ + intro N hN + have hN1 : (1 : ℝ) ≤ N := by exact_mod_cast hN + have hNpos : (0 : ℝ) < N := by linarith + have hlog : 0 ≤ Real.log (2*(N : ℝ)) := Real.log_nonneg (by linarith) + have hlogbound : (Real.log (2*(N : ℝ)))^2 ≤ L^2*(N : ℝ)^(beta*2) := by + calc + _ ≤ (L*(N : ℝ)^beta)^2 := pow_le_pow_left₀ hlog (log_two_mul_le_power hb hNpos) 2 + _ = _ := by + rw [mul_pow, ← Real.rpow_mul_natCast (Nat.cast_nonneg N)] + norm_num + calc + _ ≤ (A*(N : ℝ)^alpha)*(L^2*(N : ℝ)^(beta*2)) := + mul_le_mul (hdiv N hN) hlogbound (sq_nonneg _) (by positivity) + _ = A*L^2*(N : ℝ)^eps := by + have he : alpha+beta*2 = eps := by dsimp [alpha,beta]; ring + rw [← he, Real.rpow_add hNpos] + ring + +end ErdosHyperbolaWeighted + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/EndpointCofactorSplit.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/EndpointCofactorSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8a4e422a921c83323cd2db97033c71e3b65d0b6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/EndpointCofactorSplit.lean @@ -0,0 +1,111 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FullWordHighAlignment +import OAI.NumberTheory.Jacobsthal.Primes.SourcePrimeProductData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.FullIsolatedCofactor +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseAlignment +open SingletonBinSelection SingletonBinProduct TwoPrimeObservableSum +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinEndpoints LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem isolated_product {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (f : Fin n → Finset ℕ) (hf : f∈selections P m) (i : Fin n) (hi : m i=1) : + selectionProduct f=pickedPrime f i*selectionProduct (eraseSelection f i) := by + obtain ⟨p,_hp,hfi,hfill⟩ := singleton_selection_recovery P m i hi f hf + have hprod := filled_product (eraseSelection f i) i p (by simp [eraseSelection]) + rw [hfill] at hprod + simpa [pickedPrime,hfi] using hprod + +theorem full_word_isolated_product {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (i : Fin (binCount w top xi)) (hi : m i=1) : + (descendingWord f).prod=pickedPrime f i*selectionProduct (eraseSelection f i) := by + rw [descendingWord_product (globalBins w top xi) + (fun k l hkl => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) + f (fun k => ((mem_selections _ _ _).mp hf k).1)] + exact isolated_product _ m f hf i hi + +theorem full_cofactor_alignment_word {w top xi Cs : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (i : Fin (binCount w top xi)) (hi : m i=1) + (a : ℕ → ℤ) (q : ℚ) + (ha : ∀ p∈(pickedPrime f i*selectionProduct (eraseSelection f i)).primeFactors, + Cs < primeExponent w p → aligns a q p) : + ∀ p∈descendingWord f,Cs < primeExponent w p → aligns a q p := by + intro p hp hhigh + apply ha p _ hhigh + rw [← isolated_product _ m f hf i hi, + selectionProduct_primeFactors (globalBins w top xi) + (fun k _p hp => (bin_prime_in_source (zero_lt_one.trans hw) htop hxi k hp).1) + (fun k l hkl => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) + f (fun k => ((mem_selections _ _ _).mp hf k).1)] + obtain ⟨k,hpk⟩ := (mem_descendingWord f p).mp hp + exact Finset.mem_biUnion.mpr ⟨k,Finset.mem_univ _,hpk⟩ +end NumberTheoryLean.FullIsolatedCofactor + + + +namespace NumberTheoryLean.EndpointCofactorSplit +open ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection TwoPrimeObservableSum +open ParentTailPartition ParentCofactorChoices BinCutSelections SelectionWordSplit +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinEndpoints LogarithmicBinPartition + + +theorem endpoint_cofactor_split {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (i j : Fin (binCount w top xi)) + (hji : j < i) (hj : m j=1) : + selectionProduct (eraseSelection f i)=selectionProduct (parentCofactorSelection f i j)* + (pickedPrime f j*selectionProduct (belowSelection f j)) := by + obtain ⟨u,_hu,hfu,_hfill⟩ := singleton_selection_recovery _ m j hj f hf + have hfi : eraseSelection f i j={u} := by simp [eraseSelection,ne_of_lt hji,hfu] + have hErase := erase_selection_mem _ m f hf i + have hParent := erase_selection_mem _ _ _ (above_selection_mem _ m f hf j) i + have hBelow := below_selection_mem _ m f hf j + have hA : aboveSelection (eraseSelection f i) j=parentCofactorSelection f i j := by + funext k + by_cases hki : k=i <;> by_cases hjk : j < k <;> + simp [aboveSelection,eraseSelection,parentCofactorSelection,hki,hjk] + have hD : belowSelection (eraseSelection f i) j=belowSelection f j := by + funext k + by_cases hki : k=i + · subst k + simp [belowSelection,not_lt_of_ge hji.le] + · simp [belowSelection,eraseSelection,hki] + have hd : Pairwise (fun k l => Disjoint (globalBins w top xi k) (globalBins w top xi l)) := + fun k l hkl => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl + have hword := selected_word_split hw htop hxi _ _ hErase j u hfi + have hprod := congrArg List.prod hword + rw [List.prod_append,List.prod_cons,hA,hD] at hprod + rw [descendingWord_product _ hd _ (fun k => ((mem_selections _ _ _).mp hErase k).1), + descendingWord_product _ hd (parentCofactorSelection f i j) (fun k => ((mem_selections _ _ _).mp hParent k).1), + descendingWord_product _ hd _ (fun k => ((mem_selections _ _ _).mp hBelow k).1)] at hprod + simpa [pickedPrime,hfu] using hprod + +theorem endpoint_extra_factor_pos {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (j : Fin (binCount w top xi)) (hj : m j=1) : + 0 < pickedPrime f j*selectionProduct (belowSelection f j) := by + obtain ⟨u,hu,hfu,_hfill⟩ := singleton_selection_recovery _ m j hj f hf + have hp : 0 < pickedPrime f j := by + simpa [pickedPrime,hfu] using (bin_prime_in_source (zero_lt_one.trans hw) htop hxi j hu).1.pos + have hd : 0 < selectionProduct (belowSelection f j) := selectionProduct_pos (globalBins w top xi) + (fun k _p hp => (bin_prime_in_source (zero_lt_one.trans hw) htop hxi k hp).1) _ + (fun k => ((mem_selections _ _ _).mp (below_selection_mem _ m f hf j) k).1) + exact Nat.mul_pos hp hd +end NumberTheoryLean.EndpointCofactorSplit + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ErasedCofactorGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ErasedCofactorGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..98bde98a70d7b0c7e55854cabfe73c0ca355c48b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ErasedCofactorGeometry.lean @@ -0,0 +1,42 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceDenseCellContradiction +import OAI.NumberTheory.Jacobsthal.Paths.FiniteBoxWordMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceWeighted +open NumberTheoryLean ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection ErdosInverseRefinement + LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinEndpoints +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem erased_cofactor_arithmetic {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (i : Fin (binCount w top xi)) + (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) (eraseMultiplicity m i)) : + Squarefree (selectionProduct f) ∧ (∀ t ∈ (selectionProduct f).primeFactors,w < (t : ℝ)) ∧ + ∀ p ∈ globalBins w top xi i,(selectionProduct f).Coprime p := by + let P := globalBins w top xi + have hP : ∀ j,∀ p ∈ P j,p.Prime := fun j p hp => (bin_prime_in_source (by linarith) htop hxi j hp).1 + have hd : Pairwise (fun j k => Disjoint (P j) (P k)) := + fun j k hjk => bins_pairwise_disjoint (by linarith) htop hxi j k hjk + have hq : selectionProduct f ∈ cofactorChoices P (eraseMultiplicity m i) := + Finset.mem_image.mpr ⟨f,hf,rfl⟩ + refine ⟨cofactor_squarefree P _ hP hd _ hq,?_, + cofactor_coprime_excluded_bin P _ hP hd i (by simp [eraseMultiplicity]) _ hq⟩ + intro t ht + rw [selectionProduct_primeFactors P hP hd f (fun j => ((mem_selections P _ f).mp hf j).1)] at ht + obtain ⟨j,_hj,htj⟩ := Finset.mem_biUnion.mp ht + exact (bin_prime_in_source (by linarith) htop hxi j (((mem_selections P _ f).mp hf j).1 htj)).2.1 + +end ErdosVarianceWeighted + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/EulerProductRatio.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/EulerProductRatio.lean new file mode 100644 index 0000000000000000000000000000000000000000..c6cf055c2af0fb79b4bf76ffb11fdc1af623900d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/EulerProductRatio.lean @@ -0,0 +1,648 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Real +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.FundamentalBlockEstimate +import OAI.NumberTheory.Jacobsthal.Sieve.RealCoprimeResidueCount + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosVarianceMoments +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem prime_residue_choices_card (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) + [NeZero (∏ p ∈ P,p)] (E : ∀ p : ℕ,Finset (ZMod p)) : + (Finset.univ.filter (fun r : ZMod (∏ p ∈ P,p) => ∀ p ∈ P,(r.val : ZMod p) ∈ E p)).card = + ∏ p ∈ P,(E p).card := by + have hcop : Pairwise (fun i j : P => Nat.Coprime i.val j.val) := by + intro i j hij + exact (Nat.coprime_primes (hP i i.property) (hP j j.property)).mpr + (fun he => hij (Subtype.ext he)) + have he : (∏ i : P,(i : ℕ)) = ∏ p ∈ P,p := Finset.prod_coe_sort P (fun p => p) + let : NeZero (∏ i : P,(i : ℕ)) := ⟨by rw [he];exact NeZero.ne _⟩ + have hc := literal_residue_choices_card (fun i : P => (i : ℕ)) hcop (fun i => E i) + have hn := (canonical_filter_card (∏ i : P,(i : ℕ)) + (fun n => ∀ i : P,(n : ZMod i.val) ∈ E i.val)).symm.trans hc + calc + _ = ((Finset.range (∏ p ∈ P,p)).filter (fun n => ∀ p ∈ P,(n : ZMod p) ∈ E p)).card := + canonical_filter_card _ _ + _ = _ := by + simpa only [he,Finset.prod_coe_sort P (fun p => (E p).card),Subtype.forall] using hn + +theorem prime_unit_avoidance_card (P S : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) + [NeZero (∏ p ∈ P,p)] (u : ∀ p : ℕ,(ZMod p)ˣ) (c : ∀ p : ℕ,ZMod p) : + (Finset.univ.filter (fun r : ZMod (∏ p ∈ P,p) => + ∀ p ∈ P,∀ j ∈ S,(r.val : ZMod p)+(u p : ZMod p)*(j : ZMod p) ≠ c p)).card = + ∏ p ∈ P,(p-(positionResidues S p).card) := by + let E (p : ℕ) : Finset (ZMod p) := + if hp : p = 0 then ∅ else @allowedClasses S p ⟨hp⟩ (u p) (c p) + have hmem (p : ℕ) (hp : p ∈ P) (x : ZMod p) : + x ∈ E p ↔ ∀ j ∈ S,x+(u p : ZMod p)*(j : ZMod p) ≠ c p := by + have hn := (hP p hp).ne_zero + let : NeZero p := ⟨hn⟩ + simp only [E,dite_eq_right hn,mem_allowedClasses] + have hcard (p : ℕ) (hp : p ∈ P) : (E p).card = p-(positionResidues S p).card := by + have hn := (hP p hp).ne_zero + let : NeZero p := ⟨hn⟩ + simp only [E,dite_eq_right hn,allowedClasses_card] + have hf : Finset.univ.filter (fun r : ZMod (∏ p ∈ P,p) => + ∀ p ∈ P,∀ j ∈ S,(r.val : ZMod p)+(u p : ZMod p)*(j : ZMod p) ≠ c p) = + Finset.univ.filter (fun r : ZMod (∏ p ∈ P,p) => ∀ p ∈ P,(r.val : ZMod p) ∈ E p) := by + apply Finset.filter_congr + intro r _hr + exact forall_congr' (fun p => forall_congr' (fun hp => (hmem p hp _).symm)) + rw [hf,prime_residue_choices_card P hP E] + exact Finset.prod_congr rfl hcard + +theorem product_allowed_eq_density (P S : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) : + ((∏ p ∈ P,(p-(positionResidues S p).card) : ℕ) : ℝ) = + ((∏ p ∈ P,p : ℕ) : ℝ)*jointDensity P S := by + rw [Nat.cast_prod,Nat.cast_prod,jointDensity,← Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro p hp + let : NeZero p := ⟨(hP p hp).ne_zero⟩ + have hle := positionResidues_le_modulus S p + rw [Nat.cast_sub hle,positionDensity] + have hn : (p : ℝ) ≠ 0 := by exact_mod_cast (hP p hp).ne_zero + field_simp + +end ErdosVarianceMoments + +end + +section + +namespace ErdosVarianceMoments +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def primeResidueSet (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) + (E : ∀ p : ℕ,Finset (ZMod p)) : Finset (ZMod (∏ p ∈ P,p)) := by + letI : NeZero (∏ p ∈ P,p) := ⟨(Finset.prod_pos (fun p hp => (hP p hp).pos)).ne'⟩ + exact Finset.univ.filter (fun r => ∀ p ∈ P,(r.val : ZMod p) ∈ E p) + +theorem primeResidueSet_card (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) + (E : ∀ p : ℕ,Finset (ZMod p)) : + (primeResidueSet P hP E).card = ∏ p ∈ P,(E p).card := by + let : NeZero (∏ p ∈ P,p) := ⟨(Finset.prod_pos (fun p hp => (hP p hp).pos)).ne'⟩ + exact prime_residue_choices_card P hP E + +theorem cast_int_residue (M t : ℕ) [NeZero M] (htM : t ∣ M) (n : ℤ) : + (((n : ZMod M).val : ℕ) : ZMod t) = (n : ZMod t) := by + have hh := congrArg (ZMod.castHom htM (ZMod t)) (ZMod.natCast_zmod_val (n : ZMod M)) + simpa only [map_natCast,map_intCast] using hh + +theorem int_mem_primeResidueSet (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) + (E : ∀ p : ℕ,Finset (ZMod p)) (n : ℤ) : + (n : ZMod (∏ p ∈ P,p)) ∈ primeResidueSet P hP E ↔ ∀ p ∈ P,(n : ZMod p) ∈ E p := by + let : NeZero (∏ p ∈ P,p) := ⟨(Finset.prod_pos (fun p hp => (hP p hp).pos)).ne'⟩ + change ((n : ZMod (∏ p ∈ P,p)) ∈ Finset.univ.filter (fun r => ∀ p ∈ P,(r.val : ZMod p) ∈ E p)) ↔ _ + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact forall_congr' (fun p => forall_congr' (fun hp => by + rw [cast_int_residue _ p (Finset.dvd_prod_of_mem _ hp) n])) + +noncomputable def integerPrimeIntersection (H : ℕ) (P : Finset ℕ) + (E : ∀ p : ℕ,Finset (ZMod p)) (b c : ℝ) : Finset ℤ := + (Finset.Ico ⌈b⌉ ⌈c⌉).filter (fun n => H.Coprime n.natAbs ∧ ∀ p ∈ P,(n : ZMod p) ∈ E p) + +theorem integerPrimeIntersection_error (H : ℕ) (hH : 0 < H) (P : Finset ℕ) + (hP : ∀ p ∈ P,p.Prime) (hHP : ∀ p ∈ P,H.Coprime p) + (E : ∀ p : ℕ,Finset (ZMod p)) (b c : ℝ) (hbc : b ≤ c) : + |((integerPrimeIntersection H P E b c).card : ℝ)- + (c-b)*((H.totient : ℝ)/(H : ℝ))*(∏ p ∈ P,((E p).card : ℝ)/(p : ℝ))| ≤ + 2*(H.divisors.card : ℝ)*(∏ p ∈ P,((E p).card : ℝ)) := by + have hL : 0 < ∏ p ∈ P,p := Finset.prod_pos (fun p hp => (hP p hp).pos) + have hcop : H.Coprime (∏ p ∈ P,p) := Nat.coprime_prod_right_iff.mpr hHP + have he : integerPrimeIntersection H P E b c = + ErdosCoprimeResidueInterval.realCoprimeResidues H (∏ p ∈ P,p) (primeResidueSet P hP E) b c := by + ext n + simp only [integerPrimeIntersection,Finset.mem_filter,Finset.mem_Ico,Int.ceil_le,Int.lt_ceil, + ErdosCoprimeResidueInterval.mem_realCoprimeResidues,int_mem_primeResidueSet,and_assoc] + rw [he] + have hh := ErdosCoprimeResidueInterval.real_coprime_residue_count H _ hH hL hcop + (primeResidueSet P hP E) b c hbc + simpa only [primeResidueSet_card,Nat.cast_prod,Finset.prod_div_distrib] using hh + +end ErdosVarianceMoments + +end + +section + +namespace NumberTheoryLean.RealFundamentalSieve + +open scoped BigOperators + +noncomputable def levelDivisors (P : Finset ℕ) (v s : ℝ) : Finset ℕ := by + classical + exact (∏ p ∈ P, p).divisors.filter fun d => (d : ℝ) ≤ v ^ s + +theorem floor_level_le (v s : ℝ) (hv : 1 ≤ v) (hs : 0 ≤ s) : + (((⌊v⌋₊ ^ ⌊s⌋₊ : ℕ) : ℝ)) ≤ v ^ s := by + rw [Nat.cast_pow, ← Real.rpow_natCast] + calc + (⌊v⌋₊ : ℝ) ^ (⌊s⌋₊ : ℝ) ≤ v ^ (⌊s⌋₊ : ℝ) := + Real.rpow_le_rpow (Nat.cast_nonneg _) (Nat.floor_le (by linarith)) (Nat.cast_nonneg _) + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le hv (Nat.floor_le hs) + +theorem fundamental_lemma {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (hit : ℕ → α → Prop) + (v s : ℝ) (P : Finset ℕ) (X : ℝ) (g : ℕ → ℝ) + (hv : 2 ≤ v) (hs : 480024 ≤ s) (hX : 0 ≤ X) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, (p : ℝ) ≤ v) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hdim : ∀ p ∈ P, g p ≤ 2 / p) + (htwo : 2 ∈ P → g 2 ≤ 1 / 2) : + |(∑ x ∈ C, weight x * BonferroniBlocks.survives P (fun p => hit p x)) - + X * (∏ p ∈ P, (1 - g p))| ≤ + X * (∏ p ∈ P, (1 - g p)) * Real.exp (-s / 96) + + ∑ d ∈ levelDivisors P v s, |FundamentalBlockEstimate.integerRemainder C weight hit X g d| := by + have hv0 : 0 ≤ v := by linarith + have hs0 : 0 ≤ s := by linarith + have hV : 2 ≤ ⌊v⌋₊ := (Nat.le_floor_iff hv0).mpr (by exact_mod_cast hv) + have hS : 240012 ≤ ⌊s⌋₊ := (Nat.le_floor_iff hs0).mpr (by norm_num; linarith) + have hPsize : ∀ p ∈ P, p ≤ ⌊v⌋₊ := fun p hp => (Nat.le_floor_iff hv0).mpr (hsize p hp) + have h := FundamentalBlockEstimate.fundamental_integer_parameter C weight hweight hit + ⌊v⌋₊ ⌊s⌋₊ P X g hV hS hX hprime hPsize hg0 hdim htwo + apply h.trans + apply add_le_add + · have hcap := BonferroniDensity.prime_density_le_two_thirds P g hprime hdim htwo + have hEuler : 0 ≤ ∏ p ∈ P, (1 - g p) := Finset.prod_nonneg (fun p hp => by linarith [hcap p hp]) + apply mul_le_mul_of_nonneg_left _ (mul_nonneg hX hEuler) + apply Real.exp_le_exp.mpr + have hfloor := Nat.lt_floor_add_one s + linarith + · apply Finset.sum_le_sum_of_subset_of_nonneg + · intro d hd + obtain ⟨hdP, hdL⟩ := Finset.mem_filter.mp hd + apply Finset.mem_filter.mpr + refine ⟨hdP, ?_⟩ + have hdLReal : (d : ℝ) ≤ ((⌊v⌋₊ ^ ⌊s⌋₊ : ℕ) : ℝ) := by exact_mod_cast hdL + exact hdLReal.trans (floor_level_le v s (by linarith) hs0) + · intro d _ _ + exact abs_nonneg _ + +end NumberTheoryLean.RealFundamentalSieve + +end + +section + +namespace ErdosVarianceMoments +open NumberTheoryLean +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def unitIntervalIntegers (H : ℕ) (b c : ℝ) : Finset ℤ := + (Finset.Ico ⌈b⌉ ⌈c⌉).filter (fun n => H.Coprime n.natAbs) + +noncomputable def residueDensity (E : ∀ p : ℕ,Finset (ZMod p)) (p : ℕ) : ℝ := + ((E p).card : ℝ)/(p : ℝ) + +theorem actual_intersection_mass (H : ℕ) (P : Finset ℕ) + (E : ∀ p : ℕ,Finset (ZMod p)) (b c : ℝ) : + BonferroniBlocks.intersectionMass (unitIntervalIntegers H b c) (fun _ => 1) + (fun p n => (n : ZMod p) ∈ E p) P = (integerPrimeIntersection H P E b c).card := by + have he : integerPrimeIntersection H P E b c = + (unitIntervalIntegers H b c).filter (fun n => ∀ p ∈ P,(n : ZMod p) ∈ E p) := by + ext n + simp only [integerPrimeIntersection,unitIntervalIntegers,Finset.mem_filter,and_assoc] + rw [he,Finset.card_filter,Nat.cast_sum] + simp only [BonferroniBlocks.intersectionMass,BonferroniBlocks.intersectionValue,one_mul, + Nat.cast_ite,Nat.cast_one,Nat.cast_zero] + apply Finset.sum_congr rfl + intro n _hn + split_ifs <;> rfl + +theorem integerRemainder_bound (H : ℕ) (hH : 0 < H) (P : Finset ℕ) + (hP : ∀ p ∈ P,p.Prime) (hHP : ∀ p ∈ P,H.Coprime p) + (E : ∀ p : ℕ,Finset (ZMod p)) (b c : ℝ) (hbc : b ≤ c) + (d : ℕ) (hd : d ∣ ∏ p ∈ P,p) : + |FundamentalBlockEstimate.integerRemainder (unitIntervalIntegers H b c) (fun _ => 1) + (fun p n => (n : ZMod p) ∈ E p) ((c-b)*((H.totient : ℝ)/(H : ℝ))) (residueDensity E) d| ≤ + 2*(H.divisors.card : ℝ)*(d : ℝ) := by + have hsq : Squarefree (∏ p ∈ P,p) := IntervalBoundingSieve.squarefree_primeSet_product P hP + have hdsq := hsq.squarefree_of_dvd hd + have hsub : d.primeFactors ⊆ P := by + rw [← Nat.primeFactors_prod hP] + exact Nat.primeFactors_mono hd hsq.ne_zero + have hprime (p : ℕ) (hp : p ∈ d.primeFactors) : p.Prime := (Nat.mem_primeFactors.mp hp).1 + have herr := integerPrimeIntersection_error H hH d.primeFactors hprime + (fun p hp => hHP p (hsub hp)) E b c hbc + have hcard : (∏ p ∈ d.primeFactors,((E p).card : ℝ)) ≤ d := by + calc + _ ≤ ∏ p ∈ d.primeFactors,(p : ℝ) := by + apply Finset.prod_le_prod₀ (fun _ _ => Nat.cast_nonneg _) + intro p hp + let : NeZero p := ⟨(hprime p hp).ne_zero⟩ + have hh := Finset.card_le_univ (E p) + rw [ZMod.card] at hh + exact_mod_cast hh + _ = d := by rw [← Nat.cast_prod,Nat.prod_primeFactors_of_squarefree hdsq] + unfold FundamentalBlockEstimate.integerRemainder BonferroniBlocks.intersectionRemainder + rw [actual_intersection_mass] + exact herr.trans (mul_le_mul_of_nonneg_left hcard (by positivity)) + +theorem remainder_sum_bound (H : ℕ) (hH : 0 < H) (P : Finset ℕ) + (hP : ∀ p ∈ P,p.Prime) (hHP : ∀ p ∈ P,H.Coprime p) + (E : ∀ p : ℕ,Finset (ZMod p)) (b c : ℝ) (hbc : b ≤ c) + (v s : ℝ) (hD : 1 ≤ v^s) : + (∑ d ∈ RealFundamentalSieve.levelDivisors P v s, + |FundamentalBlockEstimate.integerRemainder (unitIntervalIntegers H b c) (fun _ => 1) + (fun p n => (n : ZMod p) ∈ E p) ((c-b)*((H.totient : ℝ)/(H : ℝ))) (residueDensity E) d|) ≤ + 4*(H.divisors.card : ℝ)*(v^s)^2 := by + let D := v^s + let F := RealFundamentalSieve.levelDivisors P v s + have hsize (d : ℕ) (hd : d ∈ F) : (d : ℝ) ≤ D := (Finset.mem_filter.mp hd).2 + have hsub : F ⊆ Finset.range (⌊D⌋₊+1) := by + intro d hd + exact Finset.mem_range.mpr (Nat.lt_succ_of_le ((Nat.le_floor_iff (by dsimp [D];linarith)).mpr (hsize d hd))) + have hcard : (F.card : ℝ) ≤ 2*D := by + have hc : (F.card : ℝ) ≤ ((⌊D⌋₊+1 : ℕ) : ℝ) := by + exact_mod_cast (Finset.card_le_card hsub).trans_eq (Finset.card_range _) + have hf := Nat.floor_le (show 0 ≤ D by dsimp [D];linarith) + push_cast at hc + dsimp [D] at * + linarith + have hsum : (∑ d ∈ F, + |FundamentalBlockEstimate.integerRemainder (unitIntervalIntegers H b c) (fun _ => 1) + (fun p n => (n : ZMod p) ∈ E p) ((c-b)*((H.totient : ℝ)/(H : ℝ))) (residueDensity E) d|) ≤ + (F.card : ℝ)*(2*(H.divisors.card : ℝ)*D) := by + calc + _ ≤ ∑ _d ∈ F,2*(H.divisors.card : ℝ)*D := by + apply Finset.sum_le_sum + intro d hd + exact (integerRemainder_bound H hH P hP hHP E b c hbc d + (Nat.dvd_of_mem_divisors (Finset.mem_filter.mp hd).1)).trans + (mul_le_mul_of_nonneg_left (hsize d hd) (by positivity)) + _ = _ := by rw [Finset.sum_const,nsmul_eq_mul] + have hnon : 0 ≤ 2*(H.divisors.card : ℝ)*D := by dsimp [D];positivity + have hh := mul_le_mul_of_nonneg_right hcard hnon + exact hsum.trans (by dsimp [D] at hh ⊢;nlinarith) + +end ErdosVarianceMoments + +end + +section + +namespace NumberTheoryLean.SmallSieveFinite + +open scoped BigOperators + +noncomputable def smallEuler (z : ℕ) : ℝ := + ∏ p ∈ LargePrimeDeletion.cutoffPrimes z, (1 - (p : ℝ)⁻¹) + +theorem squarefree_dvd_iff_primeFactors {d x : ℕ} (hd : Squarefree d) : + d ∣ x ↔ ∀ p ∈ d.primeFactors, p ∣ x := by + constructor + · intro h p hp + exact (Nat.dvd_of_mem_primeFactors hp).trans h + · intro h + by_cases hx : x = 0 + · simp [hx] + · rw [← Nat.prod_primeFactors_of_squarefree hd, Nat.prod_primeFactors_dvd_iff hx] + intro p hp + exact Nat.mem_primeFactors.mpr ⟨Nat.prime_of_mem_primeFactors hp, h p hp, hx⟩ + +theorem intersectionValue_divisibility (A i d : ℕ) (hd : Squarefree d) : + BonferroniBlocks.intersectionValue d.primeFactors (fun p => p ∣ A + i) = + (if d ∣ A + i then 1 else 0 : ℝ) := by + classical + unfold BonferroniBlocks.intersectionValue + simp only [← squarefree_dvd_iff_primeFactors hd] + +theorem reciprocal_primeFactors_product {d : ℕ} (hd : Squarefree d) : + (∏ p ∈ d.primeFactors, (p : ℝ)⁻¹) = (d : ℝ)⁻¹ := by + rw [Finset.prod_inv_distrib, ← Nat.cast_prod, Nat.prod_primeFactors_of_squarefree hd] + +theorem integerRemainder_eq_interval_rem (A N D : ℕ) (hD : Squarefree D) + {d : ℕ} (hd : d ∣ D) : + FundamentalBlockEstimate.integerRemainder (Finset.range N) (fun _ => 1) + (fun p i => p ∣ A + i) (N : ℝ) (fun p => (p : ℝ)⁻¹) d = + (IntervalBoundingSieve.intervalSieve A N D hD).rem d := by + classical + have hdsq : Squarefree d := hD.squarefree_of_dvd hd + unfold FundamentalBlockEstimate.integerRemainder BonferroniBlocks.intersectionRemainder + BonferroniBlocks.intersectionMass + simp_rw [one_mul, intersectionValue_divisibility A _ d hdsq] + rw [reciprocal_primeFactors_product hdsq] + change (∑ i ∈ Finset.range N, if d ∣ A + i then (1 : ℝ) else 0) - + (N : ℝ) * (d : ℝ)⁻¹ = _ + rw [BoundingSieve.rem, IntervalBoundingSieve.interval_multSum] + simp only [LargePrimeDeletion.deletionCell, ← Nat.cast_add, Int.natCast_dvd_natCast, + Finset.sum_boole, IntervalBoundingSieve.intervalSieve, IntervalBoundingSieve.reciprocalDensity_apply] + ring + +theorem integerRemainder_abs_le_two (A N D : ℕ) (hD : Squarefree D) + {d : ℕ} (hd : d ∣ D) (J : ℝ) (hNJ : |(N : ℝ) - J| ≤ 1) : + |FundamentalBlockEstimate.integerRemainder (Finset.range N) (fun _ => 1) + (fun p i => p ∣ A + i) J (fun p => (p : ℝ)⁻¹) d| ≤ 2 := by + have hdpos : 0 < d := Nat.pos_of_dvd_of_pos hd (Nat.pos_of_ne_zero hD.ne_zero) + have hdsq : Squarefree d := hD.squarefree_of_dvd hd + have hEq : FundamentalBlockEstimate.integerRemainder (Finset.range N) (fun _ => 1) + (fun p i => p ∣ A + i) J (fun p => (p : ℝ)⁻¹) d = + (IntervalBoundingSieve.intervalSieve A N D hD).rem d + ((N : ℝ) - J) * (d : ℝ)⁻¹ := by + rw [← integerRemainder_eq_interval_rem A N D hD hd] + unfold FundamentalBlockEstimate.integerRemainder BonferroniBlocks.intersectionRemainder + rw [reciprocal_primeFactors_product hdsq] + ring + rw [hEq] + have hInv : (d : ℝ)⁻¹ ≤ 1 := inv_le_one_of_one_le₀ (by exact_mod_cast hdpos) + have hErr : |((N : ℝ) - J) * (d : ℝ)⁻¹| ≤ 1 := by + rw [abs_mul, abs_of_nonneg (show (0 : ℝ) ≤ (d : ℝ)⁻¹ from inv_nonneg.mpr (Nat.cast_nonneg d))] + simpa only [one_mul] using mul_le_mul hNJ hInv (inv_nonneg.mpr (Nat.cast_nonneg d)) zero_le_one + exact (abs_add_le _ _).trans (by linarith [IntervalBoundingSieve.interval_rem_abs_le_one A N D hD hdpos]) + +theorem survives_sum_eq_coprimeOffsets (A N : ℕ) (P : Finset ℕ) + (hprime : ∀ p ∈ P, p.Prime) : + (∑ i ∈ Finset.range N, (1 : ℝ) * BonferroniBlocks.survives P (fun p => p ∣ A + i)) = + ((LargePrimeDeletion.coprimeOffsets N (∏ p ∈ P, p) (A : ℤ)).card : ℝ) := by + classical + have hD : Squarefree (∏ p ∈ P, p) := IntervalBoundingSieve.squarefree_primeSet_product P hprime + have hfac : (∏ p ∈ P, p).primeFactors = P := Nat.primeFactors_prod hprime + have hpoint : ∀ i : ℕ, BonferroniBlocks.survives P (fun p => p ∣ A + i) = + if (A + i).Coprime (∏ p ∈ P, p) then 1 else 0 := by + intro i + unfold BonferroniBlocks.survives + have hcop := LargePrimeDeletion.coprime_iff_avoid_primeFactors + (Nat.pos_of_ne_zero hD.ne_zero) ((A + i : ℕ) : ℤ) + simp only [hfac, Int.natAbs_natCast, Int.natCast_dvd_natCast] at hcop + simp only [← hcop] + simp_rw [one_mul, hpoint] + simp only [LargePrimeDeletion.coprimeOffsets, ← Nat.cast_add, Int.natAbs_natCast, Finset.sum_boole] + +theorem realLevelDivisors_card_le (P : Finset ℕ) (u s : ℝ) (hu : 0 ≤ u) : + ((RealFundamentalSieve.levelDivisors P u s).card : ℝ) ≤ u ^ s := by + classical + have hpow : 0 ≤ u ^ s := Real.rpow_nonneg hu s + have hsub : RealFundamentalSieve.levelDivisors P u s ⊆ Finset.Icc 1 ⌊u ^ s⌋₊ := by + intro d hd + obtain ⟨hdP, hdL⟩ := Finset.mem_filter.mp hd + exact Finset.mem_Icc.mpr ⟨Nat.pos_of_mem_divisors hdP, (Nat.le_floor_iff hpow).mpr hdL⟩ + have hcard : (RealFundamentalSieve.levelDivisors P u s).card ≤ ⌊u ^ s⌋₊ := by + simpa only [Nat.card_Icc, Nat.add_sub_cancel] using Finset.card_le_card hsub + exact (show ((RealFundamentalSieve.levelDivisors P u s).card : ℝ) ≤ (⌊u ^ s⌋₊ : ℝ) by exact_mod_cast hcard).trans + (Nat.floor_le hpow) + +theorem cutoffSurvivors_eq_residueAvoidingOffsets (N z : ℕ) (residue : ℕ → ℕ) : + LargePrimeDeletion.cutoffSurvivors N z residue = + IntervalBoundingSieve.residueAvoidingOffsets N (IntervalBoundingSieve.cutoffProduct z) residue := by + classical + ext i + simp only [LargePrimeDeletion.mem_cutoffSurvivors, IntervalBoundingSieve.residueAvoidingOffsets, + Finset.mem_filter, Finset.mem_range, IntervalBoundingSieve.cutoffProduct_primeFactors, + LargePrimeDeletion.mem_cutoffPrimes] + tauto + +theorem finite_small_sieve_bound (N : ℕ) (u s J : ℝ) (residue : ℕ → ℕ) + (hu : 2 ≤ u) (hs : 480024 ≤ s) (hJ : 0 ≤ J) (hNJ : |(N : ℝ) - J| ≤ 1) : + |((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) - J * smallEuler ⌊u⌋₊| ≤ + J * smallEuler ⌊u⌋₊ * Real.exp (-s / 96) + 2 * u ^ s := by + classical + let z := ⌊u⌋₊ + let P := LargePrimeDeletion.cutoffPrimes z + let D := IntervalBoundingSieve.cutoffProduct z + have hD : Squarefree D := IntervalBoundingSieve.cutoffProduct_squarefree z + have hprime : ∀ p ∈ P, p.Prime := fun p hp => (LargePrimeDeletion.mem_cutoffPrimes.mp hp).1 + have hsize : ∀ p ∈ P, (p : ℝ) ≤ u := by + intro p hp + have hpz := (LargePrimeDeletion.mem_cutoffPrimes.mp hp).2 + exact (show (p : ℝ) ≤ (z : ℝ) by exact_mod_cast hpz).trans (Nat.floor_le (by linarith)) + obtain ⟨A, hA⟩ := IntervalBoundingSieve.exists_residue_count_translation N D + (Nat.pos_of_ne_zero hD.ne_zero) residue + have hcount : (LargePrimeDeletion.cutoffSurvivors N z residue).card = + (LargePrimeDeletion.coprimeOffsets N D (A : ℤ)).card := by + rw [cutoffSurvivors_eq_residueAvoidingOffsets, hA] + have h := RealFundamentalSieve.fundamental_lemma (Finset.range N) (fun _ => (1 : ℝ)) + (fun _ _ => by norm_num) (fun p i => p ∣ A + i) u s P J (fun p => (p : ℝ)⁻¹) + hu hs hJ hprime hsize (fun _ _ => inv_nonneg.mpr (Nat.cast_nonneg _)) + (fun p _ => by simpa only [one_div] using + div_le_div_of_nonneg_right (by norm_num : (1 : ℝ) ≤ 2) (Nat.cast_nonneg p)) + (fun _ => by norm_num) + rw [survives_sum_eq_coprimeOffsets A N P hprime] at h + change |((LargePrimeDeletion.coprimeOffsets N D (A : ℤ)).card : ℝ) - J * smallEuler z| ≤ _ at h + rw [← hcount] at h + apply h.trans + apply add_le_add le_rfl + calc + _ ≤ ∑ _d ∈ RealFundamentalSieve.levelDivisors P u s, (2 : ℝ) := by + apply Finset.sum_le_sum + intro d hd + exact integerRemainder_abs_le_two A N D hD + (Nat.dvd_of_mem_divisors (Finset.mem_filter.mp hd).1) J hNJ + _ = 2 * ((RealFundamentalSieve.levelDivisors P u s).card : ℝ) := by simp [mul_comm] + _ ≤ 2 * u ^ s := mul_le_mul_of_nonneg_left (realLevelDivisors_card_le P u s (by linarith)) (by norm_num) + +theorem all_integer_euler_product (z : ℕ) (hz : 1 ≤ z) : + (∏ n ∈ Finset.Icc 2 z, (1 - (n : ℝ)⁻¹)) = (z : ℝ)⁻¹ := by + induction z, hz using Nat.le_induction with + | base => simp + | succ z hz ih => + rw [Finset.prod_Icc_succ_top (by omega), ih] + have hz0 : (z : ℝ) ≠ 0 := by exact_mod_cast (show z ≠ 0 by omega) + have hzs : ((z + 1 : ℕ) : ℝ) ≠ 0 := by positivity + push_cast + field_simp + ring + +theorem smallEuler_ge_inv (z : ℕ) (hz : 2 ≤ z) : (z : ℝ)⁻¹ ≤ smallEuler z := by + have hsubset : LargePrimeDeletion.cutoffPrimes z ⊆ Finset.Icc 2 z := by + intro p hp + obtain ⟨hprime, hpz⟩ := LargePrimeDeletion.mem_cutoffPrimes.mp hp + exact Finset.mem_Icc.mpr ⟨hprime.two_le, hpz⟩ + rw [← all_integer_euler_product z (by omega)] + apply Finset.prod_le_prod_of_subset_of_le_one₀ hsubset + · intro n hn + apply sub_nonneg.mpr + exact inv_le_one_of_one_le₀ (by exact_mod_cast (show 1 ≤ n by have := (Finset.mem_Icc.mp hn).1; omega)) + · intro n _ _ + have h := inv_nonneg.mpr (Nat.cast_nonneg (α := ℝ) n) + linarith + +theorem smallEuler_floor_ge_inv (u : ℝ) (hu : 2 ≤ u) : u⁻¹ ≤ smallEuler ⌊u⌋₊ := by + have hz : 2 ≤ ⌊u⌋₊ := (Nat.le_floor_iff (by linarith)).mpr (by exact_mod_cast hu) + have hzpos : (0 : ℝ) < (⌊u⌋₊ : ℝ) := by exact_mod_cast (show 0 < ⌊u⌋₊ by omega) + exact ((inv_le_inv₀ (by linarith) hzpos).mpr (Nat.floor_le (by linarith))).trans (smallEuler_ge_inv _ hz) + +end NumberTheoryLean.SmallSieveFinite + +end + +section + +namespace NumberTheoryLean.EulerProductRatio + +open scoped BigOperators + +theorem restricted_block_union (z K : ℕ) (P : Finset ℕ) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ z) + (hlower : ∀ p ∈ P, 2 ^ (2 ^ K) ≤ p) : + (Finset.Icc K (PrimeDensityBlocks.lastBlock z)).biUnion (PrimeDensityBlocks.primeBlock P) = P := by + ext p + constructor + · intro hp + obtain ⟨j, _, hpj⟩ := Finset.mem_biUnion.mp hp + exact (Finset.mem_inter.mp hpj).1 + · intro hp + have hfull := PrimeDensityBlocks.primeBlock_union z P hprime hsize + have hpFull : p ∈ (PrimeDensityBlocks.blockIndices z).biUnion (PrimeDensityBlocks.primeBlock P) := by + simpa only [hfull] using hp + obtain ⟨j, hj, hpj⟩ := Finset.mem_biUnion.mp hpFull + have hjJ : j ≤ PrimeDensityBlocks.lastBlock z := Nat.le_of_lt_succ (Finset.mem_range.mp hj) + have hKj : K ≤ j := by + by_contra hnot + have hjK : j + 1 ≤ K := by omega + have he : 2 ^ (j + 1) ≤ 2 ^ K := Nat.pow_le_pow_right (by norm_num) hjK + have htop : 2 ^ (2 ^ (j + 1)) ≤ 2 ^ (2 ^ K) := Nat.pow_le_pow_right (by norm_num) he + have hbelow := (PrimeDensityBlocks.mem_geometricPrimes.mp (Finset.mem_inter.mp hpj).2).2.1 + have habove := hlower p hp + omega + exact Finset.mem_biUnion.mpr ⟨j, Finset.mem_Icc.mpr ⟨hKj, hjJ⟩, hpj⟩ + +theorem tail_euler_lower (z h : ℕ) (P : Finset ℕ) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ z) + (hlower : ∀ p ∈ P, 2 ^ (2 ^ (PrimeDensityBlocks.lastBlock z - h)) ≤ p) : + Real.exp (-4596 * ((h + 1 : ℕ) : ℝ)) ≤ ∏ p ∈ P, (1 - (p : ℝ)⁻¹) := by + let J := PrimeDensityBlocks.lastBlock z + let B := Finset.Icc (J - h) J + have hdim : ∀ p ∈ P, (p : ℝ)⁻¹ ≤ 2 / p := by + intro p _ + simpa only [one_div] using div_le_div_of_nonneg_right (by norm_num : (1 : ℝ) ≤ 2) (Nat.cast_nonneg p) + have hcap := BonferroniDensity.prime_density_le_two_thirds P (fun p => (p : ℝ)⁻¹) + hprime hdim (fun _ => by norm_num) + have heach : ∀ j ∈ B, Real.exp (-4596) ≤ + ∏ p ∈ PrimeDensityBlocks.primeBlock P j, (1 - (p : ℝ)⁻¹) := by + intro j _ + have hsum := PrimeDensityBlocks.primeBlock_density_sum_le P j (fun p => (p : ℝ)⁻¹) hdim + have he := BonferroniDensity.exp_neg_three_mul_le_eulerProduct (PrimeDensityBlocks.primeBlock P j) + (fun p => (p : ℝ)⁻¹) (fun p _ => inv_nonneg.mpr (Nat.cast_nonneg p)) + (fun p hp => hcap p (Finset.mem_inter.mp hp).1) hsum + norm_num at he + exact he + have hcard : B.card ≤ h + 1 := by + dsimp [B] + rw [Nat.card_Icc] + omega + have hdis : (B : Set ℕ).PairwiseDisjoint (PrimeDensityBlocks.primeBlock P) := by + intro i _ j _ hij + exact (PrimeDensityBlocks.geometricPrimes_disjoint hij).mono Finset.inter_subset_right Finset.inter_subset_right + calc + Real.exp (-4596 * ((h + 1 : ℕ) : ℝ)) ≤ Real.exp (-4596 * (B.card : ℝ)) := by + apply Real.exp_le_exp.mpr + have hc : (B.card : ℝ) ≤ ((h + 1 : ℕ) : ℝ) := by exact_mod_cast hcard + linarith + _ = ∏ _j ∈ B, Real.exp (-4596) := by + rw [Finset.prod_const, ← Real.exp_nat_mul] + congr 1 + ring + _ ≤ ∏ j ∈ B, ∏ p ∈ PrimeDensityBlocks.primeBlock P j, (1 - (p : ℝ)⁻¹) := + Finset.prod_le_prod₀ (fun _ _ => (Real.exp_pos _).le) heach + _ = _ := by rw [← Finset.prod_biUnion hdis, restricted_block_union z (J - h) P hprime hsize hlower] + +theorem smallEuler_nonneg (z : ℕ) : 0 ≤ SmallSieveFinite.smallEuler z := by + apply Finset.prod_nonneg + intro p hp + apply sub_nonneg.mpr + have hprime := (LargePrimeDeletion.mem_cutoffPrimes.mp hp).1 + exact inv_le_one_of_one_le₀ (by exact_mod_cast hprime.one_lt.le) + +theorem smallEuler_ratio_nat (z t h : ℕ) (htz : t ≤ z) + (hlower : 2 ^ (2 ^ (PrimeDensityBlocks.lastBlock z - h)) ≤ t) : + SmallSieveFinite.smallEuler t ≤ Real.exp (4596 * ((h + 1 : ℕ) : ℝ)) * SmallSieveFinite.smallEuler z := by + classical + let Pz := LargePrimeDeletion.cutoffPrimes z + let Pt := LargePrimeDeletion.cutoffPrimes t + let Q := Pz \ Pt + have hsub : Pt ⊆ Pz := by + intro p hp + obtain ⟨hpp, hpt⟩ := LargePrimeDeletion.mem_cutoffPrimes.mp hp + exact LargePrimeDeletion.mem_cutoffPrimes.mpr ⟨hpp, hpt.trans htz⟩ + have hprime : ∀ p ∈ Q, p.Prime := fun p hp => + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_sdiff.mp hp).1).1 + have hsize : ∀ p ∈ Q, p ≤ z := fun p hp => + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_sdiff.mp hp).1).2 + have hQlow : ∀ p ∈ Q, 2 ^ (2 ^ (PrimeDensityBlocks.lastBlock z - h)) ≤ p := by + intro p hp + have hn := (Finset.mem_sdiff.mp hp).2 + have hpp := hprime p hp + have htp : t < p := by + by_contra hnot + exact hn (LargePrimeDeletion.mem_cutoffPrimes.mpr ⟨hpp, Nat.le_of_not_lt hnot⟩) + exact hlower.trans htp.le + have he := tail_euler_lower z h Q hprime hsize hQlow + have hprod : SmallSieveFinite.smallEuler z = + SmallSieveFinite.smallEuler t * ∏ p ∈ Q, (1 - (p : ℝ)⁻¹) := by + unfold SmallSieveFinite.smallEuler + rw [← Finset.prod_sdiff hsub] + ring + have hmul : SmallSieveFinite.smallEuler t * Real.exp (-4596 * ((h + 1 : ℕ) : ℝ)) ≤ + SmallSieveFinite.smallEuler z := by + rw [hprod] + exact mul_le_mul_of_nonneg_left he (smallEuler_nonneg t) + have hfinal := mul_le_mul_of_nonneg_left hmul (Real.exp_pos (4596 * ((h + 1 : ℕ) : ℝ))).le + have hcancel : Real.exp (4596 * ((h + 1 : ℕ) : ℝ)) * + (SmallSieveFinite.smallEuler t * Real.exp (-4596 * ((h + 1 : ℕ) : ℝ))) = SmallSieveFinite.smallEuler t := by + calc + _ = SmallSieveFinite.smallEuler t * + (Real.exp (4596 * ((h + 1 : ℕ) : ℝ)) * Real.exp (-4596 * ((h + 1 : ℕ) : ℝ))) := by ring + _ = _ := by rw [← Real.exp_add]; simp + rw [hcancel] at hfinal + exact hfinal + +noncomputable def rootCutoff (u : ℝ) (h : ℕ) : ℝ := u ^ (((2 ^ h : ℕ) : ℝ)⁻¹) + +theorem rootExponent_pos (h : ℕ) : (0 : ℝ) < ((2 ^ h : ℕ) : ℝ)⁻¹ := by positivity + +theorem rootExponent_le_one (h : ℕ) : ((2 ^ h : ℕ) : ℝ)⁻¹ ≤ 1 := + inv_le_one_of_one_le₀ (by exact_mod_cast Nat.one_le_pow h 2 (by norm_num)) + +theorem rootCutoff_le (u : ℝ) (h : ℕ) (hu : 1 ≤ u) : rootCutoff u h ≤ u := + Real.rpow_le_self_of_one_le hu (rootExponent_le_one h) + +theorem rootCutoff_ge_two (u : ℝ) (h : ℕ) (hu : (2 : ℝ) ^ (2 ^ h : ℕ) ≤ u) : + 2 ≤ rootCutoff u h := by + have hroot := Real.rpow_le_rpow (by positivity : (0 : ℝ) ≤ (2 : ℝ) ^ (2 ^ h : ℕ)) hu (rootExponent_pos h).le + rw [Real.pow_rpow_inv_natCast (by norm_num) (pow_ne_zero h (by norm_num : (2 : ℕ) ≠ 0))] at hroot + exact hroot + +theorem geometric_endpoint_le_rootCutoff (u : ℝ) (h : ℕ) (hu : 2 ≤ u) (hw : 2 ≤ rootCutoff u h) : + ((2 ^ (2 ^ (PrimeDensityBlocks.lastBlock ⌊u⌋₊ - h)) : ℕ) : ℝ) ≤ rootCutoff u h := by + let z := ⌊u⌋₊ + let J := PrimeDensityBlocks.lastBlock z + have hz : 2 ≤ z := (Nat.le_floor_iff (by linarith)).mpr (by exact_mod_cast hu) + by_cases hhJ : h ≤ J + · let n := 2 ^ (2 ^ (J - h)) + have hpow : n ^ (2 ^ h) = 2 ^ (2 ^ J) := by + dsimp [n] + have he : 2 ^ (J - h) * 2 ^ h = 2 ^ J := by rw [← pow_add, Nat.sub_add_cancel hhJ] + rw [← pow_mul, he] + have hbaseN : n ^ (2 ^ h) ≤ z := hpow ▸ PrimeDensityBlocks.lastBlock_lower_le z hz + have hbaseR : (n : ℝ) ^ (2 ^ h : ℕ) ≤ u := by + have hcast : (n : ℝ) ^ (2 ^ h : ℕ) ≤ (z : ℝ) := by exact_mod_cast hbaseN + exact hcast.trans (Nat.floor_le (by linarith)) + have hroot := Real.rpow_le_rpow (pow_nonneg (Nat.cast_nonneg n) _) hbaseR (rootExponent_pos h).le + rw [Real.pow_rpow_inv_natCast (Nat.cast_nonneg n) (pow_ne_zero h (by norm_num : (2 : ℕ) ≠ 0))] at hroot + exact hroot + · have hJh : J ≤ h := by omega + have hzero : J - h = 0 := Nat.sub_eq_zero_of_le hJh + change ((2 ^ (2 ^ (J - h)) : ℕ) : ℝ) ≤ _ + simpa only [hzero, pow_zero, pow_one, Nat.cast_ofNat] using hw + +theorem smallEuler_ratio_rootCutoff (u : ℝ) (h : ℕ) (hu : 2 ≤ u) (hw : 2 ≤ rootCutoff u h) : + SmallSieveFinite.smallEuler ⌊rootCutoff u h⌋₊ ≤ + Real.exp (4596 * ((h + 1 : ℕ) : ℝ)) * SmallSieveFinite.smallEuler ⌊u⌋₊ := by + apply smallEuler_ratio_nat + · exact Nat.floor_mono (rootCutoff_le u h (by linarith)) + · apply (Nat.le_floor_iff (by linarith : 0 ≤ rootCutoff u h)).mpr + exact geometric_endpoint_le_rootCutoff u h hu hw + +end NumberTheoryLean.EulerProductRatio + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExceptionalResidues.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExceptionalResidues.lean new file mode 100644 index 0000000000000000000000000000000000000000..306bf3601c4fd17a660a010e68ec0a68d7c4b1f2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExceptionalResidues.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.PrimeFourierSieve + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseSpectrum +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def deviationResidues (N : ℕ) (S : Finset ℤ) (T : ℝ) : Finset ℕ := + (Finset.range N).filter (fun e => T/(N : ℝ) < |(integerResidueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ)|) + +noncomputable def exceptionalResidues (N : ℕ) (S : Finset ℤ) (T : ℝ) : Finset (ZMod N) := + (deviationResidues N S T).image (fun e : ℕ => (e : ZMod N)) + +theorem exceptionalResidues_card (N : ℕ) (S : Finset ℤ) (T : ℝ) : + (exceptionalResidues N S T).card = (deviationResidues N S T).card := by + apply Finset.card_image_of_injOn + intro a ha b hb he + have haN := Finset.mem_range.mp (Finset.mem_filter.mp ha).1 + have hbN := Finset.mem_range.mp (Finset.mem_filter.mp hb).1 + have hh := congrArg ZMod.val he + simpa only [ZMod.val_natCast_of_lt haN,ZMod.val_natCast_of_lt hbN] using hh + +theorem mem_exceptionalResidues (N : ℕ) [NeZero N] (S : Finset ℤ) (T : ℝ) (e : ZMod N) : + e ∈ exceptionalResidues N S T ↔ + T/(N : ℝ) < |(residueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ)| := by + constructor + · intro he + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp he + obtain ⟨haN,hdev⟩ := Finset.mem_filter.mp ha + rw [residueCount_at_val,ZMod.val_natCast_of_lt (Finset.mem_range.mp haN)] + exact hdev + · intro he + apply Finset.mem_image.mpr + refine ⟨e.val,Finset.mem_filter.mpr ⟨Finset.mem_range.mpr (ZMod.val_lt e),?_⟩,ZMod.natCast_zmod_val e⟩ + rwa [residueCount_at_val] at he + +theorem exceptional_fraction_le_variance (N : ℕ) (hN : 0 < N) (S : Finset ℤ) (T : ℝ) (hT : 0 < T) : + ((exceptionalResidues N S T).card : ℝ)/(N : ℝ) ≤ + (N : ℝ)*integerResidueVariance N S/T^2 := by + have hNR : (0 : ℝ) < N := by exact_mod_cast hN + have hthreshold : 0 ≤ T/(N : ℝ) := (div_pos hT hNR).le + have hsum : ((deviationResidues N S T).card : ℝ)*(T/(N : ℝ))^2 ≤ integerResidueVariance N S := by + calc + _ = ∑ _e ∈ deviationResidues N S T,(T/(N : ℝ))^2 := by simp + _ ≤ ∑ e ∈ deviationResidues N S T,((integerResidueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ))^2 := by + apply Finset.sum_le_sum + intro e he + have hh := (Finset.mem_filter.mp he).2 + calc + _ ≤ |(integerResidueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ)|^2 := + pow_le_pow_left₀ hthreshold hh.le 2 + _ = _ := sq_abs _ + _ ≤ integerResidueVariance N S := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun _ _ _ => sq_nonneg _) + rw [exceptionalResidues_card] + apply (div_le_div_iff₀ hNR (sq_pos_of_pos hT)).mpr + calc + _ = (((deviationResidues N S T).card : ℝ)*(T/(N : ℝ))^2)*(N : ℝ)^2 := by field_simp + _ ≤ integerResidueVariance N S*(N : ℝ)^2 := mul_le_mul_of_nonneg_right hsum (sq_nonneg _) + _ = _ := by ring + +end ErdosInverseSpectrum + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentMarginals.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentMarginals.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b896c8941522b42784e4ac7f91ea21d755b3086 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentMarginals.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ProductRestriction + +namespace OAI + +namespace Erdos970 + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +lemma product_event_indicator {ι : Type*} [Fintype ι] (A : ι → Prop) + (w : ι → ℝ) : + (∏ i, if A i then w i else 0) = if ∀ i, A i then ∏ i, w i else 0 := by + classical + by_cases h : ∀ i, A i + · simp [h] + · rw [ite_eq_right h] + obtain ⟨i, hi⟩ := not_forall.mp h + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +theorem product_marginal (E : Finset ℕ) (hE : ∀ p ∈ E, 2 ≤ p) + (A : E → Sample → Prop) (a : E → ℝ) + (ha : ∀ p, (∑' s : Sample, if A p s then jointMass (p : ℝ) s else 0) = a p) : + eventMass E (fun s => ∀ p, A p (s p)) = ∏ p, a p := by + have h := hasSum_finite_product (fun p s => if A p s then jointMass (p : ℝ) s else 0) + a (by intro p s; split_ifs; exact jointMass_nonneg (by exact_mod_cast hE p p.property) s; rfl) + (by intro p; rw [← ha p]; exact (event_summable (by exact_mod_cast hE p p.property) (A p)).hasSum) + rw [← h.tsum_eq] + apply tsum_congr + intro s + have he := (product_event_indicator (fun p => A p (s p)) (fun p => jointMass (p : ℝ) (s p))).symm + by_cases hh : ∀ p, A p (s p) + · rw [ite_eq_left hh] at he + rw [ite_eq_left hh] + exact he + · rw [ite_eq_right hh] at he + rw [ite_eq_right hh] + exact he + +theorem upper_vector_marginal (E : Finset ℕ) (hE : ∀ p ∈ E, 2 ≤ p) (k : E → ℕ) : + eventMass E (fun s => ∀ p, upperExponent (s p) = k p) = + ∏ p : E, eulerMass (p : ℝ) (k p) := by + exact product_marginal E hE (fun p s => upperExponent s = k p) + (fun p => eulerMass (p : ℝ) (k p)) + (by + intro p + have hp := upperExponent_marginal (p := (p : ℝ)) (by exact_mod_cast hE p p.property) (k p) + convert hp using 1 + apply tsum_congr + intro s + by_cases hh : upperExponent s = k p <;> simp only [hh, ite_true, ite_false]) + +theorem lower_vector_marginal (E : Finset ℕ) (hE : ∀ p ∈ E, 2 ≤ p) (k : E → ℕ) : + eventMass E (fun s => ∀ p, lowerExponent (s p) = k p) = + ∏ p : E, geometricMass (p : ℝ) (k p) := by + exact product_marginal E hE (fun p s => lowerExponent s = k p) + (fun p => geometricMass (p : ℝ) (k p)) + (by + intro p + have hp := lowerExponent_marginal (p := (p : ℝ)) (by exact_mod_cast hE p p.property) (k p) + convert hp using 1 + apply tsum_congr + intro s + by_cases hh : lowerExponent s = k p <;> simp only [hh, ite_true, ite_false]) + +end EulerWeightedLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialIntegral.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a553ba24ebfa33135c0a236f4a9874c03350a39 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialIntegral.lean @@ -0,0 +1,239 @@ +import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals +import Mathlib.MeasureTheory.Integral.DominatedConvergence +import Mathlib.MeasureTheory.Integral.IntegralEqImproper +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.PVIdentity + +namespace OAI + +namespace Erdos970 + +section + +open Real Set MeasureTheory Filter Topology +open scoped Interval + +namespace ErdosAverageCertificates + +noncomputable section + +theorem exponentialIntegral_log_limit : + Tendsto + (fun s : ℝ ↦ Real.log s + + ∫ t in Set.Ioi s, Real.exp (-t) / t) + (nhdsWithin 0 (Set.Ioi 0)) + (nhds (-Real.eulerMascheroniConstant)) := by + have hbase := tendsto_integral_one_sub_exp_neg_div + have htail : Tendsto + (fun _s : ℝ ↦ ∫ t in Set.Ioi (1 : ℝ), Real.exp (-t) / t) + (nhdsWithin 0 (Set.Ioi 0)) + (nhds (∫ t in Set.Ioi (1 : ℝ), Real.exp (-t) / t)) := + tendsto_const_nhds + have hlim := hbase.neg.add htail + have htarget : + -(∫ t in (0 : ℝ)..1, (1 - Real.exp (-t)) / t) + + ∫ t in Set.Ioi (1 : ℝ), Real.exp (-t) / t = + -Real.eulerMascheroniConstant := by + rw [eulerMascheroni_eq_integral] + ring + rw [htarget] at hlim + refine hlim.congr' ?_ + filter_upwards [self_mem_nhdsWithin, + nhdsWithin_le_nhds (Iio_mem_nhds (show (0 : ℝ) < 1 by norm_num))] + with s hs0 hs1 + have hs : 0 < s := hs0 + have hsle : s ≤ 1 := hs1.le + have hfinite : IntervalIntegrable + (fun t : ℝ ↦ Real.exp (-t) / t) volume s 1 := by + apply ContinuousOn.intervalIntegrable + apply ContinuousOn.div + · exact (continuous_exp.comp continuous_neg).continuousOn + · exact continuousOn_id + · intro t ht + have ht' := Set.mem_uIcc.mp ht + rcases ht' with ht' | ht' + · change t ≠ 0 + linarith + · change t ≠ 0 + linarith + have hone : IntervalIntegrable (fun t : ℝ ↦ 1 / t) volume s 1 := by + apply ContinuousOn.intervalIntegrable + apply ContinuousOn.div continuousOn_const continuousOn_id + intro t ht + have ht' := Set.mem_uIcc.mp ht + rcases ht' with ht' | ht' + · change t ≠ 0 + linarith + · change t ≠ 0 + linarith + have hsplitSet : Set.Ioi s = Set.Ioc s 1 ∪ Set.Ioi 1 := + (Set.Ioc_union_Ioi_eq_Ioi hsle).symm + have hdisj : Disjoint (Set.Ioc s 1) (Set.Ioi 1) := + Set.Ioc_disjoint_Ioi_same + have htailInt : IntegrableOn + (fun t : ℝ ↦ Real.exp (-t) / t) (Set.Ioi 1) := + integrableOn_exp_neg_div_Ioi + have hfiniteOn : IntegrableOn + (fun t : ℝ ↦ Real.exp (-t) / t) (Set.Ioc s 1) := by + rwa [← intervalIntegrable_iff_integrableOn_Ioc_of_le hsle] + rw [hsplitSet, setIntegral_union hdisj measurableSet_Ioi hfiniteOn htailInt] + have hlog : (∫ t in s..1, (1 : ℝ) / t) = -Real.log s := by + simp_rw [one_div] + rw [integral_inv_of_pos hs one_pos] + rw [Real.log_div one_ne_zero hs.ne'] + simp + have hsub : + (∫ t in s..1, (1 - Real.exp (-t)) / t) = + (∫ t in s..1, (1 : ℝ) / t) - + ∫ t in s..1, Real.exp (-t) / t := by + rw [← intervalIntegral.integral_sub hone hfinite] + congr 1 + funext t + ring + rw [hsub, hlog] + rw [← intervalIntegral.integral_of_le hsle] + ring + +theorem exponentialIntegral_exp_limit : + Tendsto + (fun s : ℝ ↦ s * Real.exp + (∫ t in Set.Ioi s, Real.exp (-t) / t)) + (nhdsWithin 0 (Set.Ioi 0)) + (nhds (Real.exp (-Real.eulerMascheroniConstant))) := by + have h := (continuous_exp.tendsto + (-Real.eulerMascheroniConstant)).comp exponentialIntegral_log_limit + refine h.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with s hs + change Real.exp (Real.log s + + ∫ t in Set.Ioi s, Real.exp (-t) / t) = _ + rw [Real.exp_add, Real.exp_log hs] + +theorem laplace_final_value_of_tendsto + (f : ℝ → ℝ) (L C : ℝ) + (hf : Measurable f) (hC : 0 ≤ C) + (hbound : ∀ u : ℝ, 1 ≤ u → |f u| ≤ C) + (hlim : Tendsto f atTop (nhds L)) : + Tendsto + (fun s : ℝ ↦ s * ∫ u in Set.Ioi 1, f u * Real.exp (-s * u)) + (nhdsWithin 0 (Set.Ioi 0)) (nhds L) := by + let F : ℝ → ℝ → ℝ := fun s t ↦ + (Set.Ioi s).indicator (fun t ↦ f (t / s) * Real.exp (-t)) t + let G : ℝ → ℝ := fun t ↦ + (Set.Ioi (0 : ℝ)).indicator (fun t ↦ L * Real.exp (-t)) t + let B : ℝ → ℝ := fun t ↦ + (Set.Ioi (0 : ℝ)).indicator (fun t ↦ C * Real.exp (-t)) t + have hBint : Integrable B := by + have hexp : IntegrableOn (fun t : ℝ ↦ Real.exp (-t)) (Set.Ioi 0) := + integrableOn_exp_neg_Ioi 0 + have hmul : IntegrableOn (fun t : ℝ ↦ C * Real.exp (-t)) (Set.Ioi 0) := + hexp.const_mul C + simpa [B, integrable_indicator_iff measurableSet_Ioi] using hmul + have hFmeas : ∀ᶠ s : ℝ in nhdsWithin 0 (Set.Ioi 0), + AEStronglyMeasurable (F s) := by + filter_upwards [self_mem_nhdsWithin] with s hs + have hs0 : s ≠ 0 := ne_of_gt hs + have hcomp : Measurable (fun t : ℝ ↦ f (t / s)) := + hf.comp (measurable_id.div_const s) + have hprod : Measurable (fun t : ℝ ↦ + f (t / s) * Real.exp (-t)) := + hcomp.mul ((continuous_exp.comp continuous_neg).measurable) + exact hprod.aestronglyMeasurable.indicator measurableSet_Ioi + have hFbound : ∀ᶠ s : ℝ in nhdsWithin 0 (Set.Ioi 0), + ∀ᵐ t : ℝ, ‖F s t‖ ≤ B t := by + filter_upwards [self_mem_nhdsWithin] with s hs + filter_upwards with t + by_cases hst : s < t + · have hs0 : 0 < s := hs + have ht0 : 0 < t := hs0.trans hst + have hratio : 1 ≤ t / s := by + rw [le_div_iff₀ hs0] + simpa using hst.le + have hfC := hbound (t / s) hratio + have hstmem : t ∈ Set.Ioi s := hst + have htmem : t ∈ Set.Ioi (0 : ℝ) := ht0 + change ‖(Set.Ioi s).indicator + (fun v ↦ f (v / s) * Real.exp (-v)) t‖ ≤ + (Set.Ioi 0).indicator (fun v ↦ C * Real.exp (-v)) t + rw [Set.indicator_of_mem hstmem, Set.indicator_of_mem htmem] + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + exact mul_le_mul_of_nonneg_right hfC (Real.exp_pos _).le + · have hnot : t ∉ Set.Ioi s := hst + change ‖(Set.Ioi s).indicator + (fun v ↦ f (v / s) * Real.exp (-v)) t‖ ≤ + (Set.Ioi 0).indicator (fun v ↦ C * Real.exp (-v)) t + rw [Set.indicator_of_notMem hnot, norm_zero] + by_cases ht0 : 0 < t + · have htmem : t ∈ Set.Ioi (0 : ℝ) := ht0 + rw [Set.indicator_of_mem htmem] + positivity + · have htmem : t ∉ Set.Ioi (0 : ℝ) := ht0 + rw [Set.indicator_of_notMem htmem] + have hFlim : ∀ᵐ t : ℝ, + Tendsto (fun s : ℝ ↦ F s t) (nhdsWithin 0 (Set.Ioi 0)) (nhds (G t)) := by + filter_upwards with t + by_cases ht : 0 < t + · have hevent : ∀ᶠ s : ℝ in nhdsWithin 0 (Set.Ioi 0), s < t := + nhdsWithin_le_nhds (Iio_mem_nhds ht) + have hratio : Tendsto (fun s : ℝ ↦ t / s) + (nhdsWithin 0 (Set.Ioi 0)) atTop := by + simpa [div_eq_mul_inv] using + tendsto_const_nhds.pos_mul_atTop ht tendsto_inv_nhdsGT_zero + have hfpart := hlim.comp hratio + have hconst : Tendsto (fun _s : ℝ ↦ Real.exp (-t)) + (nhdsWithin 0 (Set.Ioi 0)) (nhds (Real.exp (-t))) := + tendsto_const_nhds + have hprod := hfpart.mul hconst + have hprod' : Tendsto + (fun s : ℝ ↦ f (t / s) * Real.exp (-t)) + (nhdsWithin 0 (Set.Ioi 0)) + (nhds (L * Real.exp (-t))) := hprod + have hG : G t = L * Real.exp (-t) := by simp [G, ht] + rw [hG] + apply hprod'.congr' + filter_upwards [hevent] with s hst + simp [F, hst] + · have ht0 : t ≤ 0 := le_of_not_gt ht + have hevent : ∀ᶠ s : ℝ in nhdsWithin 0 (Set.Ioi 0), 0 < s := + self_mem_nhdsWithin + have hzero : Tendsto (fun _s : ℝ ↦ (0 : ℝ)) + (nhdsWithin 0 (Set.Ioi 0)) (nhds 0) := tendsto_const_nhds + have hzero' : G t = 0 := by simp [G, ht] + rw [hzero'] + apply hzero.congr' + filter_upwards [hevent] with s hs + have hnot : ¬s < t := by linarith + simp [F, hnot] + have hint := MeasureTheory.tendsto_integral_filter_of_dominated_convergence + B hFmeas hFbound hBint hFlim + have hGint : (∫ t : ℝ, G t) = L := by + have hGset : (∫ t : ℝ, G t) = + ∫ t in Set.Ioi (0 : ℝ), L * Real.exp (-t) := by + rw [← integral_indicator measurableSet_Ioi] + rw [hGset, integral_const_mul, integral_exp_neg_Ioi_zero, mul_one] + rw [hGint] at hint + refine hint.congr' ?_ + filter_upwards [self_mem_nhdsWithin] with s hs + have hs0 : 0 < s := hs + have hsne : s ≠ 0 := hs0.ne' + have hscale := integral_comp_mul_left_Ioi + (fun t : ℝ ↦ f (t / s) * Real.exp (-t)) 1 hs0 + have hscale' : + (∫ u in Set.Ioi (1 : ℝ), f u * Real.exp (-s * u)) = + s⁻¹ * ∫ t in Set.Ioi s, f (t / s) * Real.exp (-t) := by + simpa [hsne, smul_eq_mul] using hscale + have hFset : (∫ t : ℝ, F s t) = + ∫ t in Set.Ioi s, f (t / s) * Real.exp (-t) := by + rw [← integral_indicator measurableSet_Ioi] + rw [hFset] + rw [hscale'] + simp [hsne] + +end + +end ErdosAverageCertificates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialMesh.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialMesh.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ada02a7f1bb9918c1706edcc79765c894142e35 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialMesh.lean @@ -0,0 +1,116 @@ +import Mathlib.Analysis.Complex.Exponential +import OAI.NumberTheory.Jacobsthal.Primes.PrimeGridGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ExponentialMesh + +open _root_.Set _root_.Filter +open scoped Topology + +noncomputable def mesh (κ w : ℝ) : ℝ := 1/(⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊:ℝ) + +theorem mesh_pos (κ w : ℝ) : 0 < mesh κ w := by + apply one_div_pos.mpr + exact_mod_cast Nat.ceil_pos.mpr (Real.exp_pos (κ*Real.sqrt (Real.log w))) + +theorem mesh_upper (κ w : ℝ) : mesh κ w ≤ Real.exp (-κ*Real.sqrt (Real.log w)) := by + have h := one_div_le_one_div_of_le (Real.exp_pos (κ*Real.sqrt (Real.log w))) + (Nat.le_ceil (Real.exp (κ*Real.sqrt (Real.log w)))) + have he : 1/Real.exp (κ*Real.sqrt (Real.log w)) = Real.exp (-κ*Real.sqrt (Real.log w)) := by + rw [one_div,← Real.exp_neg] + congr 1 + ring + exact h.trans_eq he + +theorem mesh_reciprocal (κ w : ℝ) : 1/mesh κ w = (⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊:ℝ) := by + unfold mesh + simp + +theorem reciprocal_upper {κ : ℝ} (hκ : 0 ≤ κ) (w : ℝ) : + 1/mesh κ w ≤ 2*Real.exp (κ*Real.sqrt (Real.log w)) := by + rw [mesh_reciprocal] + have hc := Nat.ceil_lt_add_one (Real.exp_pos (κ*Real.sqrt (Real.log w))).le + have he : 1 ≤ Real.exp (κ*Real.sqrt (Real.log w)) := Real.one_le_exp_iff.mpr (by positivity) + linarith + +theorem mesh_le_one {κ : ℝ} (hκ : 0 ≤ κ) (w : ℝ) : mesh κ w ≤ 1 := by + apply (mesh_upper κ w).trans + apply Real.exp_le_one_iff.mpr + nlinarith [Real.sqrt_nonneg (Real.log w)] + +theorem half_sqrt_lower {x : ℝ} (hx : 0 ≤ x) : Real.sqrt x/2 ≤ Real.sqrt ((1/2:ℝ)*x) := by + apply (sq_le_sq₀ (by positivity : 0 ≤ Real.sqrt x/2) (Real.sqrt_nonneg _)).mp + rw [Real.sq_sqrt (by positivity : 0 ≤ (1/2:ℝ)*x)] + nlinarith [Real.sq_sqrt hx] + +theorem prime_error_dominated {c κ w : ℝ} (hκ : 0 ≤ κ) (hc : 2*κ ≤ c) (hw : 0 ≤ Real.log w) : + Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)) ≤ Real.exp (-κ*Real.sqrt (Real.log w)) := by + have hc0 : 0 ≤ c := by linarith + have hhalf := half_sqrt_lower hw + have hmul := mul_le_mul_of_nonneg_left hhalf hc0 + have hcmp := mul_le_mul_of_nonneg_right hc (Real.sqrt_nonneg (Real.log w)) + apply Real.exp_le_exp.mpr + nlinarith + +theorem prime_error_over_mesh {c κ w : ℝ} (hκ : 0 ≤ κ) (hc : 4*κ ≤ c) (hw : 0 ≤ Real.log w) : + Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))/mesh κ w ≤ + 2*Real.exp (-κ*Real.sqrt (Real.log w)) := by + have hp := prime_error_dominated (c:=c) (κ:=2*κ) (by positivity) (by linarith) hw + have hr := reciprocal_upper hκ w + have hm := mesh_pos κ w + calc + _ = Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))*(1/mesh κ w) := by ring + _ ≤ Real.exp (-(2*κ)*Real.sqrt (Real.log w))*(2*Real.exp (κ*Real.sqrt (Real.log w))) := + mul_le_mul hp hr (by positivity) (Real.exp_pos _).le + _ = _ := by + rw [show Real.exp (-(2*κ)*Real.sqrt (Real.log w))*(2*Real.exp (κ*Real.sqrt (Real.log w))) = + 2*(Real.exp (-(2*κ)*Real.sqrt (Real.log w))*Real.exp (κ*Real.sqrt (Real.log w))) by ring, + ← Real.exp_add] + congr 2 + ring + +theorem log_pow_sqrt (n : ℕ) {w : ℝ} (hw : 0 ≤ Real.log w) : + (Real.sqrt (Real.log w))^(2*n) = (Real.log w)^n := by + rw [pow_mul,Real.sq_sqrt hw] + +theorem log_power_exp_tendsto (C : ℝ) (n : ℕ) {c : ℝ} (hc : 0 < c) : + Tendsto (fun w : ℝ => C*(Real.log w)^n*Real.exp (-c*Real.sqrt (Real.log w))) atTop (𝓝 0) := by + have hbase : Tendsto (fun x : ℝ => C*x^(2*n)*Real.exp (-c*x)) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero ((2*n:ℕ):ℝ) c hc).const_mul C + simpa only [Real.rpow_natCast,mul_zero,mul_assoc] using h + apply Tendsto.congr' _ (hbase.comp (Real.tendsto_sqrt_atTop.comp Real.tendsto_log_atTop)) + filter_upwards [Real.tendsto_log_atTop.eventually (eventually_ge_atTop (0:ℝ))] with w hw + simp only [Function.comp_apply,log_pow_sqrt n hw] + +theorem log_power_exp_absorption (C : ℝ) (n : ℕ) {c : ℝ} (hc : 0 < c) : + ∀ᶠ w : ℝ in atTop, C*(Real.log w)^n*Real.exp (-c*Real.sqrt (Real.log w)) ≤ + Real.exp (-(c/2)*Real.sqrt (Real.log w)) := by + have ht := log_power_exp_tendsto C n (show 0 < c/2 by positivity) + filter_upwards [ht.eventually (eventually_lt_nhds (by norm_num : (0:ℝ) < 1))] with w hw + calc + _ = (C*(Real.log w)^n*Real.exp (-(c/2)*Real.sqrt (Real.log w)))* + Real.exp (-(c/2)*Real.sqrt (Real.log w)) := by + rw [show -c*Real.sqrt (Real.log w) = -(c/2)*Real.sqrt (Real.log w)+-(c/2)*Real.sqrt (Real.log w) by ring, + Real.exp_add] + ring + _ ≤ 1*Real.exp (-(c/2)*Real.sqrt (Real.log w)) := mul_le_mul_of_nonneg_right hw.le (Real.exp_pos _).le + _ = _ := one_mul _ + +theorem exp_increment {x : ℝ} (hx : 0 ≤ x) (hx1 : x ≤ 1) : Real.exp x-1 ≤ 3*x := by + have h := Real.abs_exp_sub_one_le (x:=x) (by rw [abs_of_nonneg hx]; exact hx1) + rw [abs_of_nonneg hx] at h + linarith [le_abs_self (Real.exp x-1)] + +end NumberTheoryLean.ExponentialMesh + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialTailBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialTailBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..81a0f95a1d9ebcc58e907bf8266882321e3699df --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ExponentialTailBound.lean @@ -0,0 +1,109 @@ +import Mathlib.Analysis.SpecialFunctions.Exponential +import OAI.NumberTheory.Jacobsthal.Estimates.LossBounds +import OAI.NumberTheory.Jacobsthal.Probability.OrderedAffineMoment + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosOmissionTail + +noncomputable def expTerm (x : ℝ) (n : ℕ) : ℝ := x^n/(n.factorial:ℝ) +noncomputable def firstExpTerm (x : ℝ) (n : ℕ) : ℝ := (n:ℝ)*expTerm x n +noncomputable def secondExpTerm (x : ℝ) (n : ℕ) : ℝ := (n:ℝ)*((n:ℝ)-1)*expTerm x n +noncomputable def weightedExpTerm (x : ℝ) (n : ℕ) : ℝ := ((n:ℝ)+1)^2*expTerm x n + +theorem expTerm_hasSum (x : ℝ) : HasSum (expTerm x) (Real.exp x) := by + simpa only [Real.exp_eq_exp_ℝ] using! NormedSpace.expSeries_div_hasSum_exp x + +theorem firstExpTerm_succ (x : ℝ) (n : ℕ) : firstExpTerm x (n+1)=x*expTerm x n := by + unfold firstExpTerm expTerm + rw [Nat.factorial_succ,pow_succ,Nat.cast_mul] + have hn : ((n+1:ℕ):ℝ) ≠ 0 := by positivity + field_simp + +theorem secondExpTerm_add_two (x : ℝ) (n : ℕ) : secondExpTerm x (n+2)=x^2*expTerm x n := by + unfold secondExpTerm expTerm + rw [show n+2=(n+1)+1 by omega,Nat.factorial_succ,Nat.factorial_succ,pow_succ,pow_succ] + push_cast + have hn1 : (n:ℝ)+1 ≠ 0 := by positivity + have hn2 : (n:ℝ)+1+1 ≠ 0 := by positivity + field_simp + ring + +theorem firstExpTerm_hasSum (x : ℝ) : HasSum (firstExpTerm x) (x*Real.exp x) := by + apply (hasSum_nat_add_iff' 1).mp + have hh := (expTerm_hasSum x).mul_left x + simp_rw [firstExpTerm_succ] + simpa only [Finset.sum_range_one,firstExpTerm,Nat.cast_zero,zero_mul,sub_zero] using! hh + +theorem secondExpTerm_hasSum (x : ℝ) : HasSum (secondExpTerm x) (x^2*Real.exp x) := by + apply (hasSum_nat_add_iff' 2).mp + have hh := (expTerm_hasSum x).mul_left (x^2) + simp_rw [secondExpTerm_add_two] + simpa only [Finset.sum_range_succ,Finset.sum_range_zero,Finset.sum_empty, + secondExpTerm,Nat.cast_zero,Nat.cast_one,zero_mul,sub_self,mul_zero,add_zero,sub_zero] using! hh + +theorem weightedExpTerm_hasSum (x : ℝ) : + HasSum (weightedExpTerm x) ((x^2+3*x+1)*Real.exp x) := by + have hh := ((secondExpTerm_hasSum x).add ((firstExpTerm_hasSum x).mul_left 3)).add (expTerm_hasSum x) + convert! hh using 1 + · funext n + unfold weightedExpTerm secondExpTerm firstExpTerm + ring + · ring + +theorem weighted_log_two_tail_hasSum : + HasSum (fun n : ℕ => weightedExpTerm (Real.log 2) (n+4)) + (1+2*Real.log 2-(5:ℝ)/2*(Real.log 2)^2-(8:ℝ)/3*(Real.log 2)^3) := by + have hh := (hasSum_nat_add_iff' 4).mpr (weightedExpTerm_hasSum (Real.log 2)) + rw [Real.exp_log (by norm_num : (0:ℝ)<2)] at hh + convert! hh using 1 + norm_num [weightedExpTerm,expTerm,Finset.sum_range_succ] + ring + +theorem weighted_log_two_tail_lt : + (∑' n : ℕ,weightedExpTerm (Real.log 2) (n+4)) < (314:ℝ)/1000 := by + rw [weighted_log_two_tail_hasSum.tsum_eq] + have h := ErdosBoundaryLoss.log_two_bounds + have hq : 0 < (Real.log 2)^2+(69:ℝ)/100*Real.log 2+(69:ℝ)^2/10000 := by positivity + have hp := mul_pos (sub_pos.mpr h.1) + (show 0 < (5:ℝ)/2*(Real.log 2+(69:ℝ)/100)+(8:ℝ)/3* + ((Real.log 2)^2+(69:ℝ)/100*Real.log 2+(69:ℝ)^2/10000)-2 by nlinarith) + nlinarith + +theorem log_two_mean_factor_bounds : + 0 < 3/Real.log 2-2 ∧ 3/Real.log 2-2 < (235:ℝ)/100 := by + have h := ErdosBoundaryLoss.log_two_bounds + have hp : 0 < Real.log 2 := by linarith + constructor + · have hh : 2*Real.log 2 < 3 := by linarith + exact sub_pos.mpr ((lt_div_iff₀ hp).mpr hh) + · have hh : 3/Real.log 2 < (435:ℝ)/100 := (div_lt_iff₀ hp).mpr (by linarith) + linarith + +theorem numerical_tail_majorant_lt : + (1:ℝ)/2*(3/Real.log 2-2)*(∑' n : ℕ,weightedExpTerm (Real.log 2) (n+4)) < (37:ℝ)/100 := by + have hf := log_two_mean_factor_bounds + have ht := weighted_log_two_tail_lt + have hnon : 0 ≤ ∑' n : ℕ,weightedExpTerm (Real.log 2) (n+4) := by + apply tsum_nonneg + intro n + unfold weightedExpTerm expTerm + positivity + have hm := mul_lt_mul_of_pos_left ht (mul_pos (by norm_num : (0:ℝ)<1/2) hf.1) + have hf' := mul_lt_mul_of_pos_right hf.2 (by norm_num : (0:ℝ)<(314:ℝ)/2000) + nlinarith + +end ErdosOmissionTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/FrozenSieveMean.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/FrozenSieveMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..cd8e002a49574fb020586d734329d4fce675b7c9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/FrozenSieveMean.lean @@ -0,0 +1,102 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SmallModelSourceScales +import OAI.NumberTheory.Jacobsthal.Primes.PrimeExceptionalMean + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseFrozen +open ErdosInverseSpectrum ErdosHyperbolaIdentities + +noncomputable def frozenIntegers (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) + (a : ℕ → ℕ) : Finset ℤ := + (frozenCoordinates N w p q b v a).image (fun j : ℕ => (j : ℤ)) + +theorem frozenIntegers_card (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) : + (frozenIntegers N w p q b v a).card = (frozenCoordinates N w p q b v a).card := by + unfold frozenIntegers + exact Finset.card_image_of_injective _ Int.ofNat_injective + +theorem frozenIntegers_subset (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) : + frozenIntegers N w p q b v a ⊆ Finset.Ico (0 : ℤ) (N : ℤ) := by + intro x hx + obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx + have hjN := (mem_frozenCoordinates N w p q b v a j).mp hj |>.1 + exact Finset.mem_Ico.mpr ⟨Int.natCast_nonneg _,by exact_mod_cast hjN⟩ + +theorem frozen_residueCount (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) + (u : ℕ) [NeZero u] (e : ZMod u) : + residueCount u (frozenIntegers N w p q b v a) e = + ((frozenCoordinates N w p q b v a).filter (fun j : ℕ => (j : ZMod u) = e)).card := by + classical + unfold residueCount integerFibre frozenIntegers + simp only [Finset.filter_image,Int.cast_natCast] + exact Finset.card_image_of_injective _ Int.ofNat_injective + +noncomputable def frozenExceptional (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) + (u : ℕ) (delta V0 : ℝ) : Finset (ZMod u) := + exceptionalResidues u (frozenIntegers N w p q b v a) (delta*(N : ℝ)*V0) + +theorem mem_frozenExceptional (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) + (u : ℕ) [NeZero u] (delta V0 : ℝ) (e : ZMod u) : + e ∈ frozenExceptional N w p q b v a u delta V0 ↔ + delta*(N : ℝ)*V0/u < + |(((frozenCoordinates N w p q b v a).filter (fun j : ℕ => (j : ZMod u) = e)).card : ℝ)- + ((frozenCoordinates N w p q b v a).card : ℝ)/u| := by + rw [frozenExceptional,mem_exceptionalResidues,frozen_residueCount,frozenIntegers_card] + +end ErdosInverseFrozen + +end + +section + +namespace ErdosInverseFrozen +open NumberTheoryLean ErdosInverseSpectrum + +theorem frozen_upper (eta : ℝ) (heta : 0 < eta) : + ∃ C : ℝ,0 < C ∧ ∃ w0 : ℝ,2 ≤ w0 ∧ + ∀ (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ),w0 ≤ w → w^eta ≤ (N : ℝ) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*q).Coprime t) → + ((frozenCoordinates N w p q b v a).card : ℝ) ≤ C*(N : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊ := by + obtain ⟨C,hC,w0,hw0,hupper⟩ := SmallSieveUpper.progression_small_upper eta heta + refine ⟨C,hC,w0,hw0,?_⟩ + intro N w p q b v a hw hN hcop + exact hupper N w N (b+(q : ℤ)*v) (p*q) a hw hN (by simp) hcop + +theorem frozen_exceptional_mean (eta : ℝ) (heta : 0 < eta) : + ∃ C : ℝ,0 < C ∧ ∃ w0 : ℝ,2 ≤ w0 ∧ + ∀ (N Q : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) + (U : Finset ℕ) (delta : ℝ), + w0 ≤ w → w^eta ≤ (N : ℝ) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*q).Coprime t) → + (∀ u ∈ U,u.Prime) → (∀ u ∈ U,u ≤ Q) → 0 < U.card → 0 < delta → + (∑ u ∈ U,((frozenExceptional N w p q b v a u delta (SmallSieveFinite.smallEuler ⌊w⌋₊)).card : ℝ)/(u : ℝ))/(U.card : ℝ) ≤ + (4+8*Real.pi^2)*C*((N : ℝ)+(Q : ℝ)^2)/ + ((U.card : ℝ)*delta^2*(N : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) := by + obtain ⟨C,hC,w0,hw0,hupper⟩ := frozen_upper eta heta + refine ⟨C,hC,w0,hw0,?_⟩ + intro N Q w p q b v a U delta hw hN hcop hU hQ hn hd + have hw2 : 2 ≤ w := hw0.trans hw + have hwpos : 0 < w := by linarith + have hNpos : 0 < N := by + exact_mod_cast (Real.rpow_pos_of_pos hwpos eta).trans_le hN + have hV : 0 < SmallSieveFinite.smallEuler ⌊w⌋₊ := + (inv_pos.mpr hwpos).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2) + have hm : ((frozenIntegers N w p q b v a).card : ℝ) ≤ C*(N : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊ := by + rw [frozenIntegers_card] + exact hupper N w p q b v a hw hN hcop + exact exceptional_average_of_survivor_upper U hU hn Q N hNpos 0 _ + (by simpa only [zero_add] using frozenIntegers_subset N w p q b v a) hQ + delta _ C hd hV hm + +end ErdosInverseFrozen + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/FullPatternCongruences.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/FullPatternCongruences.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a39c5aeee67cb0eebb68e39f11485267e244883 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/FullPatternCongruences.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.FullPatternCoordinates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceLargeMap +open ErdosVarianceSmallModel ErdosVarianceMoments +attribute [local instance] Classical.propDecidable + +theorem full_pattern_units (w : ℝ) (H : ℕ) (v : ErdosLargePatternLaw.FullPattern w H) : + Int.gcd (v.1.val.val : ℤ) (divisorModulus w H : ℤ) = 1 ∧ + Int.gcd (v.2.2.1.val.val : ℤ) (coprimeModulus w H : ℤ) = 1 := by + constructor + · simpa only [Int.gcd_def,Int.natAbs_natCast] using (ZMod.val_coe_unit_coprime v.1).gcd_eq_one + · simpa only [Int.gcd_def,Int.natAbs_natCast] using (ZMod.val_coe_unit_coprime v.2.2.1).gcd_eq_one + +theorem full_pattern_residue_congruences (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) (p : goodPrimes P H) : + let v := actualFullPattern P w H C0 hw hP hlarge p + Int.ModEq (divisorModulus w H : ℤ) (p.val : ℤ) (v.1.val.val : ℤ) ∧ + Int.ModEq (coprimeModulus w H : ℤ) (p.val : ℤ) (v.2.2.1.val.val : ℤ) ∧ + Int.ModEq (coprimeModulus w H : ℤ) (primeM P H C0 hP p) (v.2.2.2.val : ℤ) := by + dsimp only + constructor + · rw [← ZMod.intCast_eq_intCast_iff] + simpa only [Int.cast_natCast] using (full_p0_projection P w H C0 hw hP hlarge p _ dvd_rfl).symm + · constructor + · rw [← ZMod.intCast_eq_intCast_iff] + simpa only [Int.cast_natCast] using (full_p1_projection P w H C0 hw hP hlarge p _ dvd_rfl).symm + · rw [← ZMod.intCast_eq_intCast_iff] + simpa only [Int.cast_natCast] using (full_m1_projection P w H C0 hw hP hlarge p _ dvd_rfl).symm + +theorem full_pattern_product_congruence (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) (p : goodPrimes P H) : + let v := actualFullPattern P w H C0 hw hP hlarge p + Int.ModEq ((H*divisorModulus w H : ℕ) : ℤ) ((p.val : ℤ)*primeM P H C0 hP p) + (C0+(H : ℤ)*(v.2.1.val : ℤ)) := by + dsimp only + have hk : Int.ModEq (divisorModulus w H : ℤ) + ((actualFullPattern P w H C0 hw hP hlarge p).2.1.val : ℤ) (primeK P H C0 hP p : ℤ) := by + rw [← ZMod.intCast_eq_intCast_iff] + simpa only [Int.cast_natCast] using full_k0_projection P w H C0 hw hP hlarge p _ dvd_rfl + obtain ⟨u,hu⟩ := Int.modEq_iff_add_fac.mp hk + apply Int.ModEq.symm + apply Int.modEq_iff_add_fac.mpr + refine ⟨u,?_⟩ + rw [primeMK_identity,hu] + push_cast + ring + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/HypotheticalCofactorHit.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/HypotheticalCofactorHit.lean new file mode 100644 index 0000000000000000000000000000000000000000..343dc294fcd6b7dd04af5e8bb0f91d2df6ebe436 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/HypotheticalCofactorHit.lean @@ -0,0 +1,46 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.EffectiveProgression + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosInverseCells ErdosInverseHits ErdosHypotheticalTag + +theorem cofactorHit_eq_of_residues (a b : ℕ → ℕ) (qf : ℕ) (hq : Squarefree qf) + (hres : ∀ t ∈ qf.primeFactors,a t%t = b t%t) : cofactorHit qf a = cofactorHit qf b := by + have ha := cofactorHit_spec qf hq a + have hb := cofactorHit_spec qf hq b + have hm : Nat.ModEq qf (cofactorHit qf a) (cofactorHit qf b) := by + rw [cofactorHit_eq qf hq b] + apply ((primeHitRepresentative_spec qf hq b).2.2 _).mp + intro t ht + exact (ha.2.2 t ht).trans (hres t ht) + have hs := Nat.ModEq.sub ha.1 hb.1 hm (Nat.ModEq.refl 1) + change (cofactorHit qf a-1)%qf = (cofactorHit qf b-1)%qf at hs + rw [Nat.mod_eq_of_lt (by omega : cofactorHit qf a-1 < qf), + Nat.mod_eq_of_lt (by omega : cofactorHit qf b-1 < qf)] at hs + omega + +theorem cofactorHit_hypothetical (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) [NeZero p] + (hq : Squarefree qf) (hqp : qf.Coprime p) : + cofactorHit qf (hypotheticalClass a r p) = cofactorHit qf a := by + apply cofactorHit_eq_of_residues _ _ qf hq + intro t ht + have htp : t ≠ p := by + intro he + subst t + exact (Nat.prime_of_mem_primeFactors ht).coprime_iff_not_dvd.mp hqp.symm + (Nat.dvd_of_mem_primeFactors ht) + rw [hypothetical_other a r p t htp] + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/HypotheticalResidues.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/HypotheticalResidues.lean new file mode 100644 index 0000000000000000000000000000000000000000..04409702d430dad144d2ceb99cd5563a5afe1e5c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/HypotheticalResidues.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RationalCandidateSets + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHypotheticalTag +open ErdosInverseAlignment ErdosAlignedProgression ErdosInverseCounts +attribute [local instance] Classical.decEq + +noncomputable def hypotheticalResidue (r : ℚ) (p : ℕ) [NeZero p] : ℕ := + ((r.num : ZMod p)*(r.den : ZMod p)⁻¹).val + +noncomputable def hypotheticalClass (a : ℕ → ℕ) (r : ℚ) (p : ℕ) [NeZero p] : ℕ → ℕ := + Function.update a p (hypotheticalResidue r p) + +theorem hypothetical_other (a : ℕ → ℕ) (r : ℚ) (p : ℕ) [NeZero p] + (s : ℕ) (hsp : s ≠ p) : hypotheticalClass a r p s = a s := + Function.update_of_ne hsp _ _ + +theorem hypothetical_aligns (a : ℕ → ℕ) (r : ℚ) (p : ℕ) [NeZero p] + (hp : p.Prime) (hD : r.den.Coprime p) : + aligns (fun s => (hypotheticalClass a r p s : ℤ)) r p := by + let : Fact p.Prime := ⟨hp⟩ + have hd0 : (r.den : ZMod p) ≠ 0 := by + intro h + exact (hp.coprime_iff_not_dvd.mp hD.symm) ((ZMod.natCast_eq_zero_iff _ _).mp h) + simp only [aligns, hypotheticalClass, Function.update_self, hypotheticalResidue, + Int.cast_natCast, ZMod.natCast_zmod_val] + rw [mul_left_comm, mul_inv_cancel₀ hd0, mul_one] + +theorem hypothetical_mod_agrees (a : ℕ → ℕ) (r : ℚ) (p : ℕ) [NeZero p] (hp : p.Prime) + (ha : aligns (fun s => (a s : ℤ)) r p) (s : ℕ) : + hypotheticalClass a r p s % s = a s % s := by + by_cases hsp : s = p + · subst s + have hD := aligned_den_coprime_prime a r p hp ha + have hh := hypothetical_aligns a r p hp hD + exact (aligned_prime_hit_iff a r p (hypotheticalClass a r p p) hp ha).mpr + ((aligns_iff_modEq (fun s => (hypotheticalClass a r p s : ℤ)) r p).mp hh) + · rw [hypothetical_other a r p s hsp] + +theorem hypothetical_candidates_agree (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d p : ℕ) [NeZero p] (hp : p.Prime) + (ha : aligns (fun s => (a s : ℤ)) r p) : + modulusCandidates Y small (hypotheticalClass a r p) d = modulusCandidates Y small a d := by + ext t + simp only [mem_modulusCandidates, hypothetical_mod_agrees a r p hp ha] + +theorem hypothetical_count_agrees (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d p : ℕ) [NeZero p] (hp : p.Prime) + (ha : aligns (fun s => (a s : ℤ)) r p) : + modulusCount Y small (hypotheticalClass a r p) d = modulusCount Y small a d := by + rw [modulusCount, modulusCount, hypothetical_candidates_agree Y small a r d p hp ha] + +end ErdosHypotheticalTag + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerLaw.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9aab4f22c380ac264101b62c2c035534e1c7776 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerLaw.lean @@ -0,0 +1,79 @@ +import Mathlib.Data.Nat.Factorization.Basic +import Mathlib.NumberTheory.SmoothNumbers +import OAI.NumberTheory.Jacobsthal.Estimates.ProductRestriction + +namespace OAI + +namespace Erdos970 + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +def integerProduct (E : Finset ℕ) (k : E → ℕ) : ℕ := ∏ p : E, (p : ℕ) ^ k p + +variable (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) +include hE + +lemma integerProduct_pos (k : E → ℕ) : 0 < integerProduct E k := by + exact Finset.prod_pos (fun p _ => pow_pos (hE p p.property).pos _) + +theorem integerProduct_factorization (k : E → ℕ) (q : E) : + (integerProduct E k).factorization q = k q := by + classical + rw [integerProduct, Nat.factorization_prod (S := Finset.univ) (g := fun p : E => (p : ℕ) ^ k p) (fun p _ => pow_ne_zero _ (hE p p.property).ne_zero)] + simp only [Finsupp.finsetSum_apply] + have h (p : E) : ((p : ℕ) ^ k p).factorization q = if p = q then k p else 0 := by + rw [(hE p p.property).factorization_pow] + simp only [Finsupp.single_apply, Subtype.val_inj] + simp only [h, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + +theorem integerProduct_injective : Function.Injective (integerProduct E) := by + intro a b hab + funext p + simpa only [integerProduct_factorization E hE] using congrArg (fun d : ℕ => d.factorization p) hab + +theorem integerProduct_factorization_outside (k : E → ℕ) {q : ℕ} (hq : q ∉ E) : + (integerProduct E k).factorization q = 0 := by + rw [integerProduct, Nat.factorization_prod (S := Finset.univ) + (g := fun p : E => (p : ℕ) ^ k p) (fun p _ => pow_ne_zero _ (hE p p.property).ne_zero)] + simp only [Finsupp.finsetSum_apply] + apply Finset.sum_eq_zero + intro p _ + rw [(hE p p.property).factorization_pow] + apply Finsupp.single_eq_of_ne + intro hpq + exact hq (hpq ▸ p.property) + +theorem integerProduct_support (k : E → ℕ) : (integerProduct E k).primeFactors ⊆ E := by + intro q hq + by_contra hn + have hh : q ∈ (integerProduct E k).factorization.support := by + simpa only [Nat.support_factorization] using hq + exact Finsupp.mem_support_iff.mp hh (integerProduct_factorization_outside E hE k hn) + +omit hE in + +theorem integerProduct_factorization_reconstruct {d : ℕ} (hd : d ≠ 0) + (hs : d.primeFactors ⊆ E) : + integerProduct E (fun p => d.factorization p) = d := by + rw [integerProduct] + change (∏ p ∈ E.attach, (p : ℕ) ^ d.factorization p) = d + rw [Finset.prod_attach E (fun p : ℕ => p ^ d.factorization p)] + calc + _ = d.factorization.prod (· ^ ·) := by + symm + apply Finset.prod_subset + · simpa only [Nat.support_factorization] using hs + · intro p _ hp + have hz : d.factorization p = 0 := Finsupp.notMem_support_iff.mp hp + simp only [hz, pow_zero] + _ = d := Nat.prod_factorization_pow_eq_self hd + +end EulerWeightedLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerResidueVariance.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerResidueVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..cd065b43de6d728613d7eee2d0b3617a4faff881 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerResidueVariance.lean @@ -0,0 +1,364 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Estimates.ReducedFractions +import OAI.NumberTheory.Jacobsthal.Harmonic.FourierDerivative +import OAI.NumberTheory.Jacobsthal.Harmonic.HyperbolaFourier + +namespace OAI + +namespace Erdos970 + +section + +open MeasureTheory Set Complex +open scoped BigOperators ComplexConjugate + +namespace AdditiveLargeSieve + +noncomputable def exponential (x : ℝ) : ℂ := Complex.exp (2 * Real.pi * I * x) + +theorem monomial_eq_exponential (n : ℤ) (x : ℝ) : + monomial n x = exponential ((n : ℝ) * x) := by + rw [monomial, fourier_coe_apply] + simp only [exponential, Complex.ofReal_one, div_one, Complex.ofReal_mul, Complex.ofReal_intCast] + congr 1 + ring + +theorem monomial_add (m n : ℤ) (x : ℝ) : + monomial (m + n) x = monomial m x * monomial n x := fourier_add + +theorem monomial_norm (n : ℤ) (x : ℝ) : ‖monomial n x‖ = 1 := by + exact Circle.norm_coe _ + +theorem shifted_sum_norm (J : ℕ) (M : ℤ) (b : ℕ → ℂ) (x : ℝ) : + ‖∑ j ∈ Finset.range J, b j * exponential (((M + (j : ℤ) : ℤ) : ℝ) * x)‖ = + ‖∑ j ∈ Finset.range J, b j * monomial (j : ℤ) x‖ := by + simp_rw [← monomial_eq_exponential] + have h : (∑ j ∈ Finset.range J, b j * monomial (M + (j : ℤ)) x) = + monomial M x * ∑ j ∈ Finset.range J, b j * monomial (j : ℤ) x := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + rw [monomial_add] + ring + rw [h, norm_mul, monomial_norm, one_mul] + +theorem separated_consecutive_bound {ι : Type*} (samples : Finset ι) (t : ι → ℝ) + (J : ℕ) (M : ℤ) (b : ℕ → ℂ) {δ : ℝ} (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hpoints : ∀ i ∈ samples, t i ∈ Icc (0 : ℝ) 1) + (hsep : ∀ i ∈ samples, ∀ j ∈ samples, i ≠ j → δ ≤ |t i - t j|) : + (∑ i ∈ samples, ‖∑ j ∈ Finset.range J, + b j * exponential (((M + (j : ℤ) : ℤ) : ℝ) * t i)‖ ^ 2) ≤ + (4 + 8 * Real.pi ^ 2) * ((J : ℝ) + δ⁻¹) * ∑ j ∈ Finset.range J, ‖b j‖ ^ 2 := by + by_cases hJ : J = 0 + · simp [hJ] + have hJpos : 0 < (J : ℝ) := by exact_mod_cast (show 0 < J by omega) + let s : Finset ℤ := (Finset.range J).image (fun j : ℕ => (j : ℤ)) + have hinj : Function.Injective (fun j : ℕ => (j : ℤ)) := Int.ofNat_injective + have hf (n : ℤ) (hn : n ∈ s) : |(n : ℝ)| ≤ (J : ℝ) := by + rcases Finset.mem_image.mp hn with ⟨j, hj, rfl⟩ + have hj' := Finset.mem_range.mp hj + norm_cast + omega + have h := separated_polynomial_bound samples t s (fun n => b n.toNat) + hJpos hδ hδ1 hpoints hsep hf + have hp (x : ℝ) : polynomial s (fun n => b n.toNat) x = + ∑ j ∈ Finset.range J, b j * monomial (j : ℤ) x := by + rw [polynomial, Finset.sum_image hinj.injOn] + simp + have he : (∑ n ∈ s, ‖b n.toNat‖ ^ 2) = ∑ j ∈ Finset.range J, ‖b j‖ ^ 2 := by + rw [Finset.sum_image hinj.injOn] + simp + simp_rw [hp] at h + rw [he] at h + simpa only [shifted_sum_norm] using h + +theorem additive_large_sieve (Q J : ℕ) (M : ℤ) (b : ℤ → ℂ) : + (∑ q ∈ Finset.Icc 1 Q, ∑ a ∈ (Finset.range q).filter (fun a => a.Coprime q), + ‖∑ j ∈ Finset.range J, b (M + (j : ℤ)) * + exponential ((((M + (j : ℤ) : ℤ) : ℝ) * a) / q)‖ ^ 2) ≤ + (4 + 8 * Real.pi ^ 2) * ((J : ℝ) + (Q : ℝ) ^ 2) * + ∑ j ∈ Finset.range J, ‖b (M + (j : ℤ))‖ ^ 2 := by + by_cases hQ : Q = 0 + · simp only [hQ, Finset.Icc_eq_empty_of_lt (by omega : (0 : ℕ) < 1), Finset.sum_empty, Nat.cast_zero, zero_pow (by norm_num : (2 : ℕ) ≠ 0), add_zero] + positivity + have hQpos : 0 < Q := by omega + have hQreal : 0 < (Q : ℝ) := by exact_mod_cast hQpos + have hQone : (1 : ℝ) ≤ Q := by exact_mod_cast hQpos + have hdelta : 0 < ((Q : ℝ) ^ 2)⁻¹ := inv_pos.mpr (sq_pos_of_pos hQreal) + have hdelta1 : ((Q : ℝ) ^ 2)⁻¹ ≤ (1 : ℝ) := by + apply (inv_le_one₀ (sq_pos_of_pos hQreal)).2 + nlinarith + have h := separated_consecutive_bound (reducedFractions Q) fractionValue J M + (fun j => b (M + (j : ℤ))) hdelta hdelta1 + (fun _ hz => ⟨(fractionValue_mem hz).1, (fractionValue_mem hz).2.le⟩) + (fun _ hx _ hy hne => reduced_fraction_separation hQpos hx hy hne) + rw [sum_reducedFractions] at h + simpa only [fractionValue, inv_inv, mul_div_assoc] using h + +end AdditiveLargeSieve + +end + +section + +open scoped ComplexConjugate +namespace ErdosInverseSpectrum +open ErdosHyperbolaIdentities +attribute [local instance] Classical.decEq + +noncomputable def residueCount (N : ℕ) (S : Finset ℤ) (e : ZMod N) : ℕ := + (integerFibre N S e).card + +noncomputable def spectrum (N : ℕ) [NeZero N] (S : Finset ℤ) (a : ZMod N) : ℂ := + integerWeight N S (-a) + +theorem spectrum_eq_sum (N : ℕ) [NeZero N] (S : Finset ℤ) (a : ZMod N) : + spectrum N S a = ∑ x ∈ S,ZMod.stdAddChar (a*(x : ZMod N)) := by + simp only [spectrum,integerWeight,neg_neg] + +theorem spectrum_zero (N : ℕ) [NeZero N] (S : Finset ℤ) : spectrum N S 0 = (S.card : ℂ) := by + simp [spectrum,integerWeight] + +theorem spectrum_orthogonality (N : ℕ) [NeZero N] (S : Finset ℤ) (e : ZMod N) : + (∑ a : ZMod N,spectrum N S a*ZMod.stdAddChar (-a*e)) = (N : ℂ)*(residueCount N S e : ℂ) := by + have he : (∑ a : ZMod N,integerWeight N S (-a)*ZMod.stdAddChar ((-a)*e)) = + ∑ a : ZMod N,integerWeight N S a*ZMod.stdAddChar (a*e) := + Fintype.sum_equiv (Equiv.neg (ZMod N)) _ _ (fun _ => rfl) + exact he.trans (integerWeight_orthogonality N S e) + +theorem conjugate_spectrum (N : ℕ) [NeZero N] (S : Finset ℤ) (a : ZMod N) : + conj (spectrum N S a) = ∑ x ∈ S,ZMod.stdAddChar (-a*(x : ZMod N)) := by + rw [spectrum_eq_sum,map_sum] + apply Finset.sum_congr rfl + intro x hx + rw [← AddChar.map_neg_eq_conj] + congr 1 + ring + +end ErdosInverseSpectrum + +end + +section + +namespace ErdosInverseSpectrum +open ErdosHyperbolaIdentities +attribute [local instance] Classical.decEq + +theorem residue_weighted_sum {R : Type*} [CommSemiring R] (N : ℕ) [NeZero N] + (S : Finset ℤ) (f : ZMod N → R) : + (∑ e : ZMod N,f e*(residueCount N S e : R)) = ∑ x ∈ S,f (x : ZMod N) := by + calc + _ = ∑ e : ZMod N,∑ _x ∈ integerFibre N S e,f e := by + apply Finset.sum_congr rfl + intro e he + simp [residueCount,mul_comm] + _ = ∑ e : ZMod N,∑ x ∈ S,if (x : ZMod N) = e then f e else 0 := by + simp only [integerFibre,Finset.sum_filter] + _ = ∑ x ∈ S,∑ e : ZMod N,if (x : ZMod N) = e then f e else 0 := Finset.sum_comm + _ = _ := by simp + +theorem residue_count_sum (N : ℕ) [NeZero N] (S : Finset ℤ) : + (∑ e : ZMod N,residueCount N S e) = S.card := by + have hh := residue_weighted_sum (R := ℕ) N S (fun _ => 1) + simpa only [Nat.cast_id,one_mul,Finset.sum_const,nsmul_eq_mul,mul_one] using hh + +theorem residue_square_sum (N : ℕ) [NeZero N] (S : Finset ℤ) : + (∑ x ∈ S,residueCount N S (x : ZMod N)) = ∑ e : ZMod N,(residueCount N S e)^2 := by + simpa only [Nat.cast_id,pow_two] using (residue_weighted_sum (R := ℕ) N S (residueCount N S)).symm + +end ErdosInverseSpectrum + +end + +section + +open scoped ComplexConjugate +namespace ErdosInverseSpectrum +attribute [local instance] Classical.decEq + +theorem spectrum_conjugate_sum (N : ℕ) [NeZero N] (S : Finset ℤ) : + (∑ a : ZMod N,spectrum N S a*conj (spectrum N S a)) = + (N : ℂ)*∑ e : ZMod N,(residueCount N S e : ℂ)^2 := by + have hf : (∑ x ∈ S,(residueCount N S (x : ZMod N) : ℂ)) = + ∑ e : ZMod N,(residueCount N S e : ℂ)^2 := by + exact_mod_cast residue_square_sum N S + calc + _ = ∑ a : ZMod N,∑ x ∈ S,spectrum N S a*ZMod.stdAddChar (-a*(x : ZMod N)) := by + simp_rw [conjugate_spectrum,Finset.mul_sum] + _ = ∑ x ∈ S,∑ a : ZMod N,spectrum N S a*ZMod.stdAddChar (-a*(x : ZMod N)) := Finset.sum_comm + _ = ∑ x ∈ S,(N : ℂ)*(residueCount N S (x : ZMod N) : ℂ) := + Finset.sum_congr rfl (fun x _ => spectrum_orthogonality N S (x : ZMod N)) + _ = (N : ℂ)*(∑ x ∈ S,(residueCount N S (x : ZMod N) : ℂ)) := (Finset.mul_sum _ _ _).symm + _ = _ := by rw [hf] + +theorem spectrum_parseval (N : ℕ) [NeZero N] (S : Finset ℤ) : + (∑ a : ZMod N,‖spectrum N S a‖^2) = (N : ℝ)*∑ e : ZMod N,(residueCount N S e : ℝ)^2 := by + have hh := spectrum_conjugate_sum N S + simp_rw [Complex.mul_conj,Complex.normSq_eq_norm_sq] at hh + exact_mod_cast hh + +theorem centered_residue_variance (N : ℕ) [NeZero N] (S : Finset ℤ) : + (N : ℝ)*(∑ e : ZMod N,((residueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ))^2) = + ∑ a ∈ (Finset.univ.erase (0 : ZMod N)),‖spectrum N S a‖^2 := by + have hN : (N : ℝ) ≠ 0 := by exact_mod_cast NeZero.ne N + have hsum : (∑ e : ZMod N,(residueCount N S e : ℝ)) = (S.card : ℝ) := by + exact_mod_cast residue_count_sum N S + have hcenter : (N : ℝ)*(∑ e : ZMod N,((residueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ))^2) = + (N : ℝ)*(∑ e : ZMod N,(residueCount N S e : ℝ)^2)-(S.card : ℝ)^2 := by + simp_rw [sub_sq] + rw [Finset.sum_add_distrib,Finset.sum_sub_distrib] + have hcross : (∑ e : ZMod N,2*(residueCount N S e : ℝ)*((S.card : ℝ)/(N : ℝ))) = + 2*(S.card : ℝ)*((S.card : ℝ)/(N : ℝ)) := by + rw [← Finset.sum_mul,← Finset.mul_sum,hsum] + rw [hcross] + simp only [Finset.sum_const,Finset.card_univ,ZMod.card,nsmul_eq_mul] + field_simp + ring + have hzero : ‖spectrum N S (0 : ZMod N)‖^2 = (S.card : ℝ)^2 := by + rw [spectrum_zero] + norm_num + have he := Finset.sum_erase_add (Finset.univ : Finset (ZMod N)) + (fun a => ‖spectrum N S a‖^2) (Finset.mem_univ (0 : ZMod N)) + rw [hzero,spectrum_parseval] at he + rw [hcenter] + linarith + +end ErdosInverseSpectrum + +end + +section + +namespace ErdosInverseSpectrum +attribute [local instance] Classical.decEq + +noncomputable def exponentialSum (S : Finset ℤ) (a q : ℕ) : ℂ := + ∑ x ∈ S,AdditiveLargeSieve.exponential (((x : ℝ)*(a : ℝ))/(q : ℝ)) + +theorem spectrum_eq_exponentialSum (N : ℕ) [NeZero N] (S : Finset ℤ) (a : ℕ) : + spectrum N S (a : ZMod N) = exponentialSum S a N := by + rw [spectrum_eq_sum] + apply Finset.sum_congr rfl + intro x hx + have he : (a : ZMod N)*(x : ZMod N) = (((a : ℤ)*x : ℤ) : ZMod N) := by + simp only [Int.cast_mul,Int.cast_natCast] + rw [he,ZMod.stdAddChar_coe] + unfold AdditiveLargeSieve.exponential + congr 1 + push_cast + ring + +theorem spectrum_eq_exponentialSum_val (N : ℕ) [NeZero N] (S : Finset ℤ) (a : ZMod N) : + spectrum N S a = exponentialSum S a.val N := by + simpa only [ZMod.natCast_zmod_val] using spectrum_eq_exponentialSum N S a.val + +end ErdosInverseSpectrum + +end + +section + +namespace ErdosInverseSpectrum +attribute [local instance] Classical.decEq + +theorem residue_values_univ (N : ℕ) [NeZero N] : + (Finset.univ : Finset (ZMod N)).image ZMod.val = Finset.range N := by + ext a + constructor + · intro ha + obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp ha + exact Finset.mem_range.mpr (ZMod.val_lt r) + · intro ha + exact Finset.mem_image.mpr ⟨(a : ZMod N),Finset.mem_univ _,ZMod.val_natCast_of_lt (Finset.mem_range.mp ha)⟩ + +theorem sum_over_residues (N : ℕ) [NeZero N] (f : ℕ → ℝ) : + (∑ e : ZMod N,f e.val) = ∑ e ∈ Finset.range N,f e := by + rw [← residue_values_univ N,Finset.sum_image] + intro a ha b hb hab + exact ZMod.val_injective N hab + +theorem residue_values_nonzero (N : ℕ) [NeZero N] : + ((Finset.univ : Finset (ZMod N)).erase 0).image ZMod.val = (Finset.range N).erase 0 := by + ext a + constructor + · intro ha + obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp ha + obtain ⟨hr0,hrU⟩ := Finset.mem_erase.mp hr + apply Finset.mem_erase.mpr + refine ⟨?_,Finset.mem_range.mpr (ZMod.val_lt r)⟩ + intro hz + apply hr0 + apply ZMod.val_injective N + simpa only [ZMod.val_zero] using hz + · intro ha + obtain ⟨ha0,haN⟩ := Finset.mem_erase.mp ha + have haval := ZMod.val_natCast_of_lt (Finset.mem_range.mp haN) + have har : (a : ZMod N) ≠ 0 := by + intro hh + have hval := congrArg ZMod.val hh + rw [haval,ZMod.val_zero] at hval + exact ha0 hval + exact Finset.mem_image.mpr ⟨(a : ZMod N),Finset.mem_erase.mpr ⟨har,Finset.mem_univ _⟩,haval⟩ + +theorem sum_over_nonzero_residues (N : ℕ) [NeZero N] (f : ℕ → ℝ) : + (∑ e ∈ (Finset.univ.erase (0 : ZMod N)),f e.val) = ∑ e ∈ (Finset.range N).erase 0,f e := by + rw [← residue_values_nonzero N,Finset.sum_image] + intro a ha b hb hab + exact ZMod.val_injective N hab + +theorem centered_variance_exponential (N : ℕ) [NeZero N] (S : Finset ℤ) : + (N : ℝ)*(∑ e : ZMod N,((residueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ))^2) = + ∑ a ∈ (Finset.range N).erase 0,‖exponentialSum S a N‖^2 := by + rw [centered_residue_variance] + simp_rw [spectrum_eq_exponentialSum_val] + exact sum_over_nonzero_residues N (fun a => ‖exponentialSum S a N‖^2) + +end ErdosInverseSpectrum + +end + +section + +namespace ErdosInverseSpectrum +open ErdosHyperbolaIdentities +attribute [local instance] Classical.decEq + +noncomputable def integerResidueCount (N : ℕ) (S : Finset ℤ) (e : ℕ) : ℕ := + (S.filter (fun x => x % (N : ℤ) = (e : ℤ))).card + +noncomputable def integerResidueVariance (N : ℕ) (S : Finset ℤ) : ℝ := + ∑ e ∈ Finset.range N,((integerResidueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ))^2 + +theorem residueCount_at_val (N : ℕ) [NeZero N] (S : Finset ℤ) (e : ZMod N) : + residueCount N S e = integerResidueCount N S e.val := by + unfold residueCount integerResidueCount + congr 1 + ext x + simp only [integerFibre,Finset.mem_filter] + apply and_congr_right + intro _hx + rw [← ZMod.val_intCast x] + constructor + · intro he + rw [he] + · intro he + exact ZMod.val_injective N (Int.ofNat_inj.mp he) + +theorem variance_eq_integerResidueVariance (N : ℕ) [NeZero N] (S : Finset ℤ) : + (∑ e : ZMod N,((residueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ))^2) = integerResidueVariance N S := by + simp_rw [residueCount_at_val] + exact sum_over_residues N (fun e => ((integerResidueCount N S e : ℝ)-(S.card : ℝ)/(N : ℝ))^2) + +theorem integer_variance_fourier (N : ℕ) [NeZero N] (S : Finset ℤ) : + (N : ℝ)*integerResidueVariance N S = ∑ a ∈ (Finset.range N).erase 0,‖exponentialSum S a N‖^2 := by + rw [← variance_eq_integerResidueVariance] + exact centered_variance_exponential N S + +end ErdosInverseSpectrum + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerRichLine.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerRichLine.lean new file mode 100644 index 0000000000000000000000000000000000000000..0477b598a0dc2e34e7af72a898b487a60fbc3844 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerRichLine.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RichLineHeights + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRichLine +open ErdosCriticalGeometry ErdosComplexCurveFactors ErdosConvexGraph + +noncomputable def integerComplexification (P : MV ℤ) : MV ℂ := + MvPolynomial.map (Int.castRingHom ℂ) P + +theorem integerComplexification_degree (P : MV ℤ) : + (integerComplexification P).totalDegree = P.totalDegree := by + unfold integerComplexification MvPolynomial.totalDegree + rw [MvPolynomial.support_map_of_injective P (Int.cast_injective)] + +theorem integerComplexification_eval (P : MV ℤ) (p : ℤ × ℤ) : + MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] (integerComplexification P) = + (MvPolynomial.eval ![p.1,p.2] P : ℂ) := by + have he : (Int.castRingHom ℂ) ∘ (![p.1,p.2] : Fin 2 → ℤ) = ![(p.1 : ℂ),(p.2 : ℂ)] := by + funext i + fin_cases i <;> rfl + have h := MvPolynomial.map_eval (Int.castRingHom ℂ) ![p.1,p.2] P + rw [he] at h + exact h.symm + +theorem integer_polynomial_rich_line (P : MV ℤ) (hP : P ≠ 0) (D : ℕ) (hD : P.totalDegree ≤ D) + (S : ℝ) (hS : 0 ≤ S) (X : Finset (ℤ × ℤ)) + (hbox : ∀ p ∈ X, InSquare S p) (hzero : ∀ p ∈ X, MvPolynomial.eval ![p.1,p.2] P = 0) + (hinj : Set.InjOn Prod.fst (X : Set (ℤ × ℤ))) (M : ℝ) (hM : 1 ≤ M) + (hlarge : 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+(D : ℝ)*M < (X.card : ℝ)) : + ∃ (l : PrimitiveIntegerLine) (Y : Finset (ℤ × ℤ)), + Y ⊆ X ∧ M < (Y.card : ℝ) ∧ (∀ r ∈ Y, l.Contains r) ∧ + (l.denominator : ℝ) ≤ 2*S/(Y.card : ℝ) ∧ + |(l.slope : ℝ)| ≤ 2*S/(Y.card : ℝ) ∧ + |(l.intercept : ℝ)| ≤ 4*S^2/(Y.card : ℝ) := by + have hPc : integerComplexification P ≠ 0 := by + intro h + apply hP + exact MvPolynomial.map_injective (Int.castRingHom ℂ) Int.cast_injective + (by simpa only [integerComplexification,map_zero] using h) + have hDc : (integerComplexification P).totalDegree ≤ D := by rwa [integerComplexification_degree] + have hX : X ⊆ complexSquarePoints (integerComplexification P) S := by + intro p hp + apply (mem_complexSquarePoints _ S p).mpr + refine ⟨hbox p hp,?_⟩ + rw [integerComplexification_eval,hzero p hp,Int.cast_zero] + obtain ⟨F,l,Y,_hF,_hFP,_hdeg,_hY,hsub,hcard,hline,hden,hslope,hinter⟩ := + exists_rich_line_with_heights (integerComplexification P) hPc D hDc S hS X hX hinj M hM hlarge + exact ⟨l,Y,hsub,hcard,hline,hden,hslope,hinter⟩ + +end ErdosRichLine + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerSlopeConstruction.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerSlopeConstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0ae1b96c77cbe9fcf60b1cd1ffb4c48c9357bb5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntegerSlopeConstruction.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.AuxiliaryPolynomialLifting + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +noncomputable def residueSlopes (P : Finset ℕ) (T : P → Finset ℤ) (p : P) : Finset (ZMod p.val) := by + classical + exact (T p).image (fun s : ℤ => (s : ZMod p.val)) + +theorem residueSlopes_card_le (P : Finset ℕ) (T : P → Finset ℤ) (p : P) : + (residueSlopes P T p).card ≤ (T p).card := by + classical + exact Finset.card_image_le + +theorem exists_integer_slope_polynomial (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : P → Finset ℤ) (a : P → ℤ) (D : ℕ) : + ∃ (Q : MvPolynomial (Fin 2) ℤ) (H : ℕ), Q ≠ 0 ∧ Q.totalDegree ≤ D ∧ 0 < H ∧ + (∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) ∧ + (∀ p : P, ∀ s ∈ T p, + lineSub (Int.castRingHom (ZMod p.val)) (a p : ZMod p.val) (s : ZMod p.val) Q = 0) ∧ + Real.log (2*(H : ℝ)) ≤ Real.log 4+2/((D : ℝ)+2)* + (∑ p : P, ((T p).card : ℝ)*Real.log (p.val : ℝ)) := by + classical + obtain ⟨Q,H,hQ,hD,hH,hcoeff,hline,hlog⟩ := exists_small_line_polynomial P hP + (residueSlopes P T) (fun p => (a p : ZMod p.val)) D + refine ⟨Q,H,hQ,hD,hH,hcoeff,?_,?_⟩ + · intro p s hs + apply hline p ⟨(s : ZMod p.val),?_⟩ + exact Finset.mem_image.mpr ⟨s,hs,rfl⟩ + · have hc : logarithmicCost P (residueSlopes P T) ≤ + ∑ p : P, ((T p).card : ℝ)*Real.log (p.val : ℝ) := + logarithmicCost_le_budget P hP (residueSlopes P T) (fun p => ((T p).card : ℝ)) + (fun p => by exact_mod_cast residueSlopes_card_le P T p) + exact hlog.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left hc (by positivity))) + +def IntegerLineIncidence (P : Finset ℕ) (T : P → Finset ℤ) + (a : P → ℤ) (x y : ℤ) (p : P) : Prop := + ∃ s ∈ T p, (y : ZMod p.val) = (a p : ZMod p.val)-(s : ZMod p.val)*(x : ZMod p.val) + +theorem exists_integer_auxiliary_polynomial_lifting (P : Finset ℕ) (hP : ∀ p ∈ P, Nat.Prime p) + (T : P → Finset ℤ) (a : P → ℤ) (D : ℕ) : + ∃ (Q : MvPolynomial (Fin 2) ℤ) (H : ℕ), Q ≠ 0 ∧ Q.totalDegree ≤ D ∧ 0 < H ∧ + (∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) ∧ + (∀ p : P, ∀ s ∈ T p, + lineSub (Int.castRingHom (ZMod p.val)) (a p : ZMod p.val) (s : ZMod p.val) Q = 0) ∧ + Real.log (2*(H : ℝ)) ≤ Real.log 4+2/((D : ℝ)+2)* + (∑ p : P, ((T p).card : ℝ)*Real.log (p.val : ℝ)) ∧ + ∀ (S : ℝ) (x y : ℤ), (0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) → + (0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) → + ∀ (I : Finset ℕ) (hIP : I ⊆ P), + (∀ p : I, IntegerLineIncidence P T a x y ⟨p.val,hIP p.property⟩) → + logarithmicValueBudget D H S < ∑ p ∈ I, Real.log (p : ℝ) → + MvPolynomial.eval ![x,y] Q = 0 := by + classical + obtain ⟨Q,H,hQ,hD,hH,hcoeff,hline,hlog⟩ := + exists_integer_slope_polynomial P (fun p hp => (hP p hp).pos) T a D + refine ⟨Q,H,hQ,hD,hH,hcoeff,hline,hlog,?_⟩ + intro S x y hx hy I hIP hinc hlarge + unfold IntegerLineIncidence at hinc + choose s hsmem hs using hinc + apply value_zero_of_log_prime_budget Q D H hD hcoeff hH S x y hx hy I + (fun p hp => hP p (hIP hp)) + (fun p : I => (a ⟨p.val,hIP p.property⟩ : ZMod p.val)) + (fun p : I => (s p : ZMod p.val)) + · exact fun p => hline ⟨p.val,hIP p.property⟩ (s p) (hsmem p) + · exact hs + · exact hlarge + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntervalBoundingSieve.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntervalBoundingSieve.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6304d7c8b2b92c2ea101511ba11af26f270ca0b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/IntervalBoundingSieve.lean @@ -0,0 +1,221 @@ +import Mathlib.Data.Nat.Cast.Order.Field +import Mathlib.Data.Nat.ChineseRemainder +import Mathlib.NumberTheory.SelbergSieve +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.Ring +import OAI.NumberTheory.Jacobsthal.Primes.LargePrimeDeletion + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.IntervalBoundingSieve + +open scoped BigOperators + +noncomputable def reciprocalDensity : ArithmeticFunction ℝ where + toFun := fun d => (d : ℝ)⁻¹ + map_zero' := by simp + +@[simp] theorem reciprocalDensity_apply (d : ℕ) : + reciprocalDensity d = (d : ℝ)⁻¹ := rfl + +theorem reciprocalDensity_multiplicative : reciprocalDensity.IsMultiplicative := by + refine ⟨by simp, ?_⟩ + intro m n _ + simp only [reciprocalDensity_apply, Nat.cast_mul, mul_inv_rev, mul_comm] + +noncomputable def intervalSieve (A J P : ℕ) (hP : Squarefree P) : BoundingSieve where + support := (Finset.range J).image fun i => A + i + prodPrimes := P + prodPrimes_squarefree := hP + weights := fun _ => 1 + weights_nonneg := by intro n; norm_num + totalMass := J + nu := reciprocalDensity + nu_mult := reciprocalDensity_multiplicative + nu_pos_of_prime := by + intro p hp _ + exact inv_pos.mpr (by exact_mod_cast hp.pos) + nu_lt_one_of_prime := by + intro p hp _ + exact inv_lt_one_of_one_lt₀ (by exact_mod_cast hp.one_lt) + +theorem interval_multSum (A J P : ℕ) (hP : Squarefree P) (d : ℕ) : + @BoundingSieve.multSum (intervalSieve A J P hP) d = + ((LargePrimeDeletion.deletionCell (Finset.range J) (A : ℤ) d).card : ℝ) := by + classical + change (∑ n ∈ (Finset.range J).image (fun i => A + i), + if d ∣ n then (1 : ℝ) else 0) = _ + rw [Finset.sum_image] + · simp only [LargePrimeDeletion.deletionCell, ← Nat.cast_add, + Int.natCast_dvd_natCast, Finset.sum_boole] + · intro i _ j _ hij + exact Nat.add_left_cancel hij + +theorem interval_siftedSum (A J P : ℕ) (hP : Squarefree P) : + @BoundingSieve.siftedSum (intervalSieve A J P hP) = + ((LargePrimeDeletion.coprimeOffsets J P (A : ℤ)).card : ℝ) := by + classical + change (∑ n ∈ (Finset.range J).image (fun i => A + i), + if P.Coprime n then (1 : ℝ) else 0) = _ + rw [Finset.sum_image] + · simp only [LargePrimeDeletion.coprimeOffsets, ← Nat.cast_add, + Int.natAbs_natCast, Nat.coprime_comm, Finset.sum_boole] + · intro i _ j _ hij + exact Nat.add_left_cancel hij + +theorem interval_rem_abs_le_one (A J P : ℕ) (hP : Squarefree P) + {d : ℕ} (hd : 0 < d) : + |@BoundingSieve.rem (intervalSieve A J P hP) d| ≤ 1 := by + have hdR : (0 : ℝ) < d := by exact_mod_cast hd + have hlow : ((J / d : ℕ) : ℝ) ≤ (J : ℝ) / d := Nat.cast_div_le + have hmod : ((J % d : ℕ) : ℝ) < d := by exact_mod_cast Nat.mod_lt J hd + have heq : (J : ℝ) = ((J / d : ℕ) : ℝ) * d + (J % d : ℕ) := by + exact_mod_cast (show J = J / d * d + J % d by simpa [Nat.mul_comm] using (Nat.div_add_mod J d).symm) + have hupp : (J : ℝ) / d < ((J / d : ℕ) : ℝ) + 1 := by + apply (div_lt_iff₀ hdR).mpr + nlinarith + have hcount := LargePrimeDeletion.card_deletionCell_range J (A : ℤ) hd + change |@BoundingSieve.multSum (intervalSieve A J P hP) d - + reciprocalDensity d * (J : ℝ)| ≤ 1 + rw [interval_multSum, reciprocalDensity_apply, inv_mul_eq_div] + rw [hcount] + split_ifs <;> push_cast <;> rw [abs_le] <;> constructor <;> linarith + +theorem coprime_count_le_upperMoebius (A J P : ℕ) (hP : Squarefree P) + (muPlus : ℕ → ℝ) (hmu : BoundingSieve.IsUpperMoebius muPlus) : + ((LargePrimeDeletion.coprimeOffsets J P (A : ℤ)).card : ℝ) ≤ + (J : ℝ) * (∑ d ∈ P.divisors, muPlus d / d) + + ∑ d ∈ P.divisors, |muPlus d| := by + have hs := BoundingSieve.siftedSum_le_mainSum_errSum_of_upperMoebius (s := intervalSieve A J P hP) muPlus hmu + rw [interval_siftedSum] at hs + have hmain : @BoundingSieve.mainSum (intervalSieve A J P hP) muPlus = ∑ d ∈ P.divisors, muPlus d / d := by + change (∑ d ∈ P.divisors, muPlus d * reciprocalDensity d) = _ + simp only [reciprocalDensity_apply, div_eq_mul_inv] + have herr : @BoundingSieve.errSum (intervalSieve A J P hP) muPlus ≤ ∑ d ∈ P.divisors, |muPlus d| := by + change (∑ d ∈ P.divisors, |muPlus d| * + |@BoundingSieve.rem (intervalSieve A J P hP) d|) ≤ _ + apply Finset.sum_le_sum + intro d hd + have hdpos := Nat.pos_of_mem_divisors hd + calc + _ ≤ |muPlus d| * 1 := mul_le_mul_of_nonneg_left + (interval_rem_abs_le_one A J P hP hdpos) (abs_nonneg _) + _ = _ := mul_one _ + rw [hmain] at hs + exact hs.trans (add_le_add le_rfl herr) + +theorem exists_residue_translation (P : ℕ) (residue : ℕ → ℕ) : + ∃ A : ℕ, ∀ p ∈ P.primeFactors, ∀ i : ℕ, + p ∣ A + i ↔ i % p = residue p % p := by + classical + have hnz : ∀ p ∈ P.primeFactors, (id p : ℕ) ≠ 0 := by + intro p hp + exact (Nat.prime_of_mem_primeFactors hp).ne_zero + have hpair : Set.Pairwise (P.primeFactors : Set ℕ) + (fun p q => Nat.Coprime (id p) (id q)) := by + intro p hp q hq hpq + exact (Nat.coprime_primes (Nat.prime_of_mem_primeFactors hp) + (Nat.prime_of_mem_primeFactors hq)).mpr hpq + let t := Nat.chineseRemainderOfFinset (fun p => p - residue p % p) id + P.primeFactors hnz hpair + refine ⟨t.val, ?_⟩ + intro p hp i + have hp0 := (Nat.prime_of_mem_primeFactors hp).pos + have hsum : Nat.ModEq p (t.val + residue p) 0 := by + have ht := (t.property p hp).add (Nat.mod_modEq (residue p) p).symm + have ht' : Nat.ModEq p (t.val + residue p) p := by + simpa only [id_eq, Nat.sub_add_cancel (Nat.mod_lt (residue p) hp0).le] using ht + exact ht'.trans (dvd_refl p).modEq_zero_nat + constructor + · intro hdiv + exact Nat.ModEq.add_left_cancel' t.val (hdiv.modEq_zero_nat.trans hsum.symm) + · intro hres + exact Nat.modEq_zero_iff_dvd.mp ((Nat.ModEq.add_left t.val hres).trans hsum) + +noncomputable def residueAvoidingOffsets (J P : ℕ) (residue : ℕ → ℕ) : Finset ℕ := by + classical + exact (Finset.range J).filter fun i => ∀ p ∈ P.primeFactors, + i % p ≠ residue p % p + +theorem exists_residue_count_translation (J P : ℕ) (hP : 0 < P) + (residue : ℕ → ℕ) : + ∃ A : ℕ, residueAvoidingOffsets J P residue = + LargePrimeDeletion.coprimeOffsets J P (A : ℤ) := by + classical + obtain ⟨A, hA⟩ := exists_residue_translation P residue + refine ⟨A, ?_⟩ + ext i + simp only [residueAvoidingOffsets, Finset.mem_filter, Finset.mem_range, + LargePrimeDeletion.mem_coprimeOffsets, + LargePrimeDeletion.coprime_iff_avoid_primeFactors hP, ← Nat.cast_add, + Int.natCast_dvd_natCast] + exact and_congr_right fun _ => forall₂_congr fun p hp => not_congr (hA p hp i).symm + +theorem residue_count_le_upperMoebius (J P : ℕ) (hP : Squarefree P) + (residue : ℕ → ℕ) (muPlus : ℕ → ℝ) + (hmu : BoundingSieve.IsUpperMoebius muPlus) : + ((residueAvoidingOffsets J P residue).card : ℝ) ≤ + (J : ℝ) * (∑ d ∈ P.divisors, muPlus d / d) + + ∑ d ∈ P.divisors, |muPlus d| := by + obtain ⟨A, hA⟩ := exists_residue_count_translation J P (Nat.pos_of_ne_zero hP.ne_zero) residue + rw [hA] + exact coprime_count_le_upperMoebius A J P hP muPlus hmu + +theorem squarefree_primeSet_product (s : Finset ℕ) + (hs : ∀ p ∈ s, p.Prime) : Squarefree (∏ p ∈ s, p) := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert p s hp ih => + have hpprime : p.Prime := hs p (Finset.mem_insert_self p s) + have hsprime : ∀ q ∈ s, q.Prime := fun q hq => hs q (Finset.mem_insert_of_mem hq) + rw [Finset.prod_insert hp] + apply Nat.squarefree_mul_iff.mpr + refine ⟨?_, hpprime.squarefree, ih hsprime⟩ + apply Nat.Coprime.prod_right + intro q hq + exact (Nat.coprime_primes hpprime (hsprime q hq)).mpr (by + intro heq + exact hp (heq ▸ hq)) + +def cutoffProduct (z : ℕ) : ℕ := ∏ p ∈ LargePrimeDeletion.cutoffPrimes z, p + +theorem cutoffProduct_squarefree (z : ℕ) : Squarefree (cutoffProduct z) := by + apply squarefree_primeSet_product + intro p hp + exact (LargePrimeDeletion.mem_cutoffPrimes.mp hp).1 + +@[simp] theorem cutoffProduct_primeFactors (z : ℕ) : + (cutoffProduct z).primeFactors = LargePrimeDeletion.cutoffPrimes z := by + apply Nat.primeFactors_prod + intro p hp + exact (LargePrimeDeletion.mem_cutoffPrimes.mp hp).1 + +theorem cutoffSurvivors_card_le_upperMoebius (J z : ℕ) (residue : ℕ → ℕ) + (muPlus : ℕ → ℝ) (hmu : BoundingSieve.IsUpperMoebius muPlus) : + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + (J : ℝ) * (∑ d ∈ (cutoffProduct z).divisors, muPlus d / d) + + ∑ d ∈ (cutoffProduct z).divisors, |muPlus d| := by + have hsets : LargePrimeDeletion.cutoffSurvivors J z residue = + residueAvoidingOffsets J (cutoffProduct z) residue := by + classical + ext i + simp only [LargePrimeDeletion.mem_cutoffSurvivors, residueAvoidingOffsets, + Finset.mem_filter, Finset.mem_range, cutoffProduct_primeFactors, + LargePrimeDeletion.mem_cutoffPrimes] + tauto + rw [hsets] + exact residue_count_le_upperMoebius J (cutoffProduct z) (cutoffProduct_squarefree z) + residue muPlus hmu + +end NumberTheoryLean.IntervalBoundingSieve + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/KloostermanCRT.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/KloostermanCRT.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3ea2aee3cbc700c3ea2a99d39c5362d7dcd49c5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/KloostermanCRT.lean @@ -0,0 +1,46 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.KloostermanCRTCharacter + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman + +attribute [local instance] Classical.decEq + +theorem sum_mulShift {R : Type*} [CommRing R] [Fintype R] + (ψ : AddChar R ℂ) (r a b : R) : + sum (ψ.mulShift r) a b = sum ψ (r*a) (r*b) := by + unfold sum + apply Finset.sum_congr rfl + intro u _ + rw [AddChar.mulShift_apply] + congr 1 + ring + +theorem standardSum_crt (m n : ℕ) [NeZero m] [NeZero n] (hmn : m.Coprime n) + (h k : ℤ) : + standardSum (m*n) h k = + standardSum m (Nat.gcdB m n * h) (Nat.gcdB m n * k) * + standardSum n (Nat.gcdA m n * h) (Nat.gcdA m n * k) := by + unfold standardSum + rw [stdAddChar_crt m n hmn, sum_product_ringEquiv] + simp only [map_intCast, Prod.fst_intCast, Prod.snd_intCast, sum_mulShift, + Int.cast_mul] + +theorem norm_standardSum_crt (m n : ℕ) [NeZero m] [NeZero n] (hmn : m.Coprime n) + (h k : ℤ) : + ‖standardSum (m*n) h k‖ = + ‖standardSum m (Nat.gcdB m n * h) (Nat.gcdB m n * k)‖ * + ‖standardSum n (Nat.gcdA m n * h) (Nat.gcdA m n * k)‖ := by + rw [standardSum_crt m n hmn, norm_mul] + +end ErdosKloosterman + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/KloostermanPrimeExponent.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/KloostermanPrimeExponent.lean new file mode 100644 index 0000000000000000000000000000000000000000..c5cba044c0d182276752a8da2858cdf3c20f2cb3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/KloostermanPrimeExponent.lean @@ -0,0 +1,39 @@ +import OAI.NumberTheory.Jacobsthal.Primes.KloostermanPrimeBound + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman + +theorem norm_le_three_quarters {F : Type*} [Field F] [Fintype F] + (ψ : AddChar F ℂ) (hψ : ψ.IsPrimitive) (a b : F) (hab : a ≠ 0 ∨ b ≠ 0) : + ‖sum ψ a b‖ ≤ 2 * (Fintype.card F : ℝ)^((3 : ℝ)/4) := by + have hfour := fourth_norm_le ψ hψ a b hab + have hq : 0 ≤ (Fintype.card F : ℝ) := Nat.cast_nonneg _ + have hp : ((Fintype.card F : ℝ)^((3 : ℝ)/4))^4 = (Fintype.card F : ℝ)^3 := by + rw [← Real.rpow_mul_natCast hq] + norm_num + have hright : (2 * (Fintype.card F : ℝ)^((3 : ℝ)/4))^4 = + 16 * (Fintype.card F : ℝ)^3 := by rw [mul_pow, hp]; norm_num + have hb : ‖sum ψ a b‖^4 ≤ (2 * (Fintype.card F : ℝ)^((3 : ℝ)/4))^4 := by + rw [hright] + nlinarith [show 0 ≤ (Fintype.card F : ℝ)^3 by positivity] + exact (pow_le_pow_iff_left₀ (norm_nonneg _) (by positivity) (by decide : 4 ≠ 0)).mp hb + +theorem standardSum_prime_bound (p : ℕ) [Fact p.Prime] (h k : ℤ) + (hk : (h : ZMod p) ≠ 0 ∨ (k : ZMod p) ≠ 0) : + ‖standardSum p h k‖ ≤ 2 * (p : ℝ)^((3 : ℝ)/4) := by + simpa only [standardSum, ZMod.card] using + norm_le_three_quarters ZMod.stdAddChar (ZMod.isPrimitive_stdAddChar p) + (h : ZMod p) (k : ZMod p) hk + +end ErdosKloosterman + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/LargeModulusSiegelWalfisz.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LargeModulusSiegelWalfisz.lean new file mode 100644 index 0000000000000000000000000000000000000000..1385a00e85c88d7339bb971d716cf55af7fffa39 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LargeModulusSiegelWalfisz.lean @@ -0,0 +1,736 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SiegelWalfisz + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +noncomputable def cubeHeight (X : ℝ) : ℝ := (Real.log X)^((1:ℝ)/3) + +lemma cubeHeight_pos {X : ℝ} (hX : 1 < X) : 0 < cubeHeight X := + Real.rpow_pos_of_pos (Real.log_pos hX) _ + +lemma cubeHeight_pow_three {X : ℝ} (hX : 1 ≤ X) : (cubeHeight X)^3 = Real.log X := by + unfold cubeHeight + rw [← Real.rpow_mul_natCast (Real.log_nonneg hX)] + norm_num + +lemma cubeHeight_mono {X Y : ℝ} (hX : 1 < X) (hXY : X ≤ Y) : cubeHeight X ≤ cubeHeight Y := + Real.rpow_le_rpow (Real.log_pos hX).le (Real.log_le_log (by linarith) hXY) (by norm_num) + +lemma cubeHeight_tendsto : Tendsto cubeHeight atTop atTop := + (tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/3)).comp Real.tendsto_log_atTop + +lemma eventually_polynomial_le_exp (K : ℝ) (n : ℕ) {c : ℝ} (hc : 0 < c) : + ∀ᶠ h : ℝ in atTop, 1 ≤ h ∧ K*h^n ≤ Real.exp (c*h) := by + have hl : Tendsto (fun h:ℝ => K*h^n*Real.exp (-c*h)) atTop (𝓝 0) := by + simpa only [Real.rpow_natCast,mul_assoc,mul_zero] using + (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (n:ℝ) c hc).const_mul K + filter_upwards [eventually_ge_atTop (1:ℝ),hl.eventually (gt_mem_nhds zero_lt_one)] with h hh hsmall + refine ⟨hh,?_⟩ + have hm := mul_le_mul_of_nonneg_right hsmall.le (Real.exp_pos (c*h)).le + have he : Real.exp (-c*h)*Real.exp (c*h)=1 := by rw [← Real.exp_add,show -c*h+c*h=0 by ring,Real.exp_zero] + simpa only [mul_assoc,he,mul_one,one_mul] using hm + +lemma exponential_height_bound {h : ℝ} (hh : Real.log 7 ≤ h) (q : ℕ) [NeZero q] + (hq : (q:ℝ) ≤ Real.exp h) : modulusHeight q (Real.exp h) ≤ 3*h := by + have hh0 : 0 < h := (Real.log_pos (by norm_num : (1:ℝ)<7)).trans_le hh + have hT : 1 ≤ Real.exp h := Real.one_le_exp_iff.mpr hh0.le + have hq0 : (0:ℝ) < q := by exact_mod_cast NeZero.pos q + have hql : Real.log (q:ℝ) ≤ h := by + have he := Real.log_le_log hq0 hq + simpa only [Real.log_exp] using he + have hsum : Real.exp h+6 ≤ 7*Real.exp h := by linarith + have hl : Real.log (Real.exp h+6) ≤ Real.log 7+h := by + have he := Real.log_le_log (by positivity : 0 < Real.exp h+6) hsum + rwa [Real.log_mul (by norm_num : (7:ℝ)≠0) (Real.exp_ne_zero h),Real.log_exp] at he + unfold modulusHeight + rw [abs_of_pos (Real.exp_pos h)] + linarith + +lemma exponential_left_saving {a X : ℝ} (ha : 0 < a) (hX : 1 < X) + (hh : Real.log 7 ≤ cubeHeight X) (q : ℕ) [NeZero q] + (hq : (q:ℝ) ≤ Real.exp (cubeHeight X)) : + Real.exp (-a*Real.log X/(modulusHeight q (Real.exp (cubeHeight X)))^2) ≤ + Real.exp (-(a/9)*cubeHeight X) := by + let h := cubeHeight X + let H := modulusHeight q (Real.exp h) + have hh0 : 0 < h := cubeHeight_pos hX + have hH : 0 < H := lt_of_lt_of_le zero_lt_one (modulusHeight_ge_one q _) + have hHle : H ≤ 3*h := exponential_height_bound hh q hq + have hsq : H^2 ≤ 9*h^2 := by nlinarith [sq_nonneg (3*h-H)] + have hcube : h^3 = Real.log X := cubeHeight_pow_three hX.le + apply Real.exp_le_exp.mpr + change -a*Real.log X/H^2 ≤ -(a/9)*h + apply (div_le_iff₀ (sq_pos_of_pos hH)).mpr + rw [← hcube] + have hm := mul_le_mul_of_nonneg_left hsq (show 0 ≤ (a/9)*h by positivity) + nlinarith + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma eventually_exponential_contour_savings {a : ℝ} (ha : 0 < a) (ha100 : a ≤ 1/100) : + ∃ c : ℝ, 0 < c ∧ c ≤ 1/2 ∧ ∀ᶠ X : ℝ in atTop, + 3 ≤ X ∧ 1 ≤ Real.log X ∧ ∀ (q : ℕ) [NeZero q], + (q:ℝ) ≤ Real.exp (cubeHeight X) → + let T := Real.exp (cubeHeight X) + let H := modulusHeight q T + H^3*Real.exp (-a*Real.log X/H^2) ≤ Real.exp (-c*cubeHeight X) ∧ + H^3/(1+T^2) ≤ Real.exp (-c*cubeHeight X) ∧ + Real.log X/T ≤ Real.exp (-c*cubeHeight X) := by + let c : ℝ := a/18 + have hc : 0 < c := by dsimp [c]; positivity + have hc2 : c ≤ 1/2 := by dsimp [c]; linarith + refine ⟨c,hc,hc2,?_⟩ + filter_upwards [eventually_ge_atTop (3:ℝ), + cubeHeight_tendsto.eventually (eventually_ge_atTop (Real.log 7)), + cubeHeight_tendsto.eventually (eventually_polynomial_le_exp 27 3 hc)] with X hX hh7 hhpoly + have hx1 : 1 < X := by linarith + have hx0 : 0 < X := by linarith + have hL : 1 ≤ Real.log X := + ((Real.lt_log_iff_exp_lt hx0).mpr (Real.exp_one_lt_three.trans_le hX)).le + refine ⟨hX,hL,?_⟩ + intro q _ hq + let h := cubeHeight X + let T := Real.exp h + let H := modulusHeight q T + have hh : 0 < h := cubeHeight_pos hx1 + have hH : 0 < H := lt_of_lt_of_le zero_lt_one (modulusHeight_ge_one q _) + have hHle : H ≤ 3*h := exponential_height_bound hh7 q hq + have hHp : H^3 ≤ Real.exp (c*h) := by + have hp := pow_le_pow_left₀ hH.le hHle 3 + calc + _ ≤ (3*h)^3 := hp + _ = 27*h^3 := by ring + _ ≤ _ := hhpoly.2 + have hLp : Real.log X ≤ Real.exp (c*h) := by + calc + _ = h^3 := (cubeHeight_pow_three hx1.le).symm + _ ≤ 27*h^3 := by nlinarith [pow_nonneg hh.le 3] + _ ≤ _ := hhpoly.2 + have hs := exponential_left_saving ha hx1 hh7 q hq + have hT2 : T^2 = Real.exp (2*h) := by + dsimp [T] + rw [pow_two,← Real.exp_add] + congr 1 + ring + refine ⟨?_,?_,?_⟩ + · calc + _ ≤ Real.exp (c*h)*Real.exp (-(a/9)*h) := + mul_le_mul hHp hs (Real.exp_pos _).le (Real.exp_pos _).le + _ = Real.exp (-c*h) := by rw [← Real.exp_add]; congr 1; dsimp [c]; ring + · calc + _ ≤ H^3/T^2 := div_le_div_of_nonneg_left (by positivity) (by dsimp [T]; positivity) (by linarith) + _ ≤ Real.exp (c*h)/T^2 := div_le_div_of_nonneg_right hHp (sq_nonneg _) + _ = Real.exp (c*h-2*h) := by rw [hT2,Real.exp_sub] + _ ≤ Real.exp (-c*h) := Real.exp_le_exp.mpr (by nlinarith) + · calc + _ ≤ Real.exp (c*h)/T := div_le_div_of_nonneg_right hLp (by dsimp [T]; positivity) + _ = Real.exp (c*h-h) := by dsimp [T]; rw [Real.exp_sub] + _ ≤ Real.exp (-c*h) := Real.exp_le_exp.mpr (by nlinarith) + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +theorem riesz_character_exponential : + ∃ c K : ℝ, 0 < c ∧ c ≤ 1/2 ∧ 0 < K ∧ ∀ᶠ X : ℝ in atTop, + ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), chi ≠ 1 → + (q:ℝ) ≤ Real.exp (cubeHeight X) → + ‖rieszSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ + K*X*Real.exp (-c*cubeHeight X) := by + obtain ⟨a,ha,ha100,C,hC,B,hB,hcontour⟩ := exists_uniform_riesz_contour_bound + obtain ⟨c,hc,hc2,hsavings⟩ := eventually_exponential_contour_savings ha ha100 + let P : ℝ := 4*Real.pi*C+16*C*Real.exp 1+8*(B+1)*Real.exp 1 + let K : ℝ := (1/(2*Real.pi))*P + have hP : 0 < P := by dsimp only [P]; positivity + have hK : 0 < K := by dsimp only [K]; positivity + refine ⟨c,K,hc,hc2,hK,?_⟩ + filter_upwards [hsavings] with X hX + intro q _ chi hchi hq + obtain ⟨hX3,hL1,hSavings⟩ := hX + obtain ⟨hleft,hhor,hratio⟩ := hSavings q hq + let L : ℝ := Real.log X + let T : ℝ := Real.exp (cubeHeight X) + let R : ℝ := Real.exp (-c*cubeHeight X) + let H : ℝ := modulusHeight q T + let sigma : ℝ := 1+L⁻¹ + have hXp : 0 < X := by linarith + have hX1 : 1 < X := by linarith + have hLp : 0 < L := by linarith + have hTp : 0 < T := Real.exp_pos _ + have hs1 : 1 < sigma := by + have hi : 0 < L⁻¹ := inv_pos.mpr hLp + dsimp only [sigma] + linarith + have hs2 : sigma ≤ 2 := by + have hinv : L⁻¹ ≤ 1 := by rw [← one_div]; exact (div_le_iff₀ hLp).mpr (by linarith) + dsimp only [sigma] + linarith + have h := hcontour q chi hchi X sigma T (by linarith) hs1 hs2 hTp + have hrightpow : X^sigma = X*Real.exp 1 := rpow_perron_sigma hX1 + have hleftpow : X^(rieszContourLeft a q T) = X*Real.exp (-a*L/H^2) := rpow_rieszContourLeft hXp a q T + have hinv : (sigma-1)⁻¹ = L := by dsimp only [sigma]; rw [add_sub_cancel_left,inv_inv] + rw [hrightpow,hleftpow,hinv] at h + change H^3*Real.exp (-a*L/H^2) ≤ R at hleft + change H^3/(1+T^2) ≤ R at hhor + change L/T ≤ R at hratio + have hBL := mul_le_mul_of_nonneg_left (show 1 ≤ L by linarith) hB + have hLB : L+B ≤ (B+1)*L := by nlinarith only [hBL] + have htail : (L+B)/T ≤ (B+1)*R := by + calc + _ ≤ ((B+1)*L)/T := div_le_div_of_nonneg_right hLB hTp.le + _ = (B+1)*(L/T) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hratio (by linarith) + have h1 := mul_le_mul_of_nonneg_left hleft (show 0 ≤ 4*Real.pi*C*X by positivity) + have h2 := mul_le_mul_of_nonneg_left hhor (show 0 ≤ 16*C*Real.exp 1*X by positivity) + have h3 := mul_le_mul_of_nonneg_left htail (show 0 ≤ 8*Real.exp 1*X by positivity) + have he : 4*Real.pi*C*H^3*(X*Real.exp (-a*L/H^2)) + + 16*C*H^3*(X*Real.exp 1)/(1+T^2)+8*(L+B)*(X*Real.exp 1)/T ≤ P*X*R := by + calc + _ = (4*Real.pi*C*X)*(H^3*Real.exp (-a*L/H^2)) + + (16*C*Real.exp 1*X)*(H^3/(1+T^2))+(8*Real.exp 1*X)*((L+B)/T) := by ring + _ ≤ (4*Real.pi*C*X)*R+(16*C*Real.exp 1*X)*R+ + (8*Real.exp 1*X)*((B+1)*R) := add_le_add (add_le_add h1 h2) h3 + _ = _ := by dsimp only [P]; ring + apply h.trans + calc + _ ≤ (1/(2*Real.pi))*(P*X*R) := mul_le_mul_of_nonneg_left he (by positivity) + _ = K*X*Real.exp (-c*cubeHeight X) := by dsimp only [K,R]; ring + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma cubeHeight_le_log {X : ℝ} (hX : 1 ≤ X) (hh : 1 ≤ cubeHeight X) : + cubeHeight X ≤ Real.log X := by + have hp : 1 ≤ (cubeHeight X)^2 := by nlinarith + have hm := mul_le_mul_of_nonneg_right hp (show 0 ≤ cubeHeight X by linarith) + rw [← cubeHeight_pow_three hX] + nlinarith + +lemma exponential_recovery_scale {d X : ℝ} (hd : 0 < d) (hd1 : d ≤ 1) + (hX : 3 ≤ X) (hh : 1 ≤ cubeHeight X) : + let delta := Real.exp (-d*cubeHeight X) + let Y := (1+delta)*X + 0 < delta ∧ delta ≤ 1 ∧ 1 ≤ delta*X ∧ X ≤ Y ∧ Y ≤ 2*X ∧ + cubeHeight X ≤ cubeHeight Y ∧ Real.log Y ≤ 2*Real.log X := by + let delta := Real.exp (-d*cubeHeight X) + let Y := (1+delta)*X + have hx0 : 0 < X := by linarith + have hx1 : 1 < X := by linarith + have hh0 : 0 < cubeHeight X := cubeHeight_pos hx1 + have hdpos : 0 < delta := Real.exp_pos _ + have hdle : delta ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith) + have hsmall : d*cubeHeight X ≤ Real.log X := by + calc + _ ≤ cubeHeight X := by nlinarith + _ ≤ _ := cubeHeight_le_log hx1.le hh + have hpower : Real.exp (d*cubeHeight X) ≤ X := by + simpa only [Real.exp_log hx0] using Real.exp_le_exp.mpr hsmall + have hid : delta*Real.exp (d*cubeHeight X)=1 := by + dsimp [delta] + rw [← Real.exp_add,show -d*cubeHeight X+d*cubeHeight X=0 by ring,Real.exp_zero] + have hdX : 1 ≤ delta*X := by + have hm := mul_le_mul_of_nonneg_left hpower hdpos.le + rwa [hid] at hm + have hXY : X ≤ Y := by dsimp [Y]; nlinarith + have hY2 : Y ≤ 2*X := by dsimp [Y]; nlinarith + have hY0 : 0 < Y := hx0.trans_le hXY + have hhY : cubeHeight X ≤ cubeHeight Y := cubeHeight_mono hx1 hXY + have hlog2 : Real.log 2 ≤ Real.log X := Real.log_le_log (by norm_num) (by linarith) + have hlogY : Real.log Y ≤ 2*Real.log X := by + have h := Real.log_le_log hY0 hY2 + rw [Real.log_mul (by norm_num : (2:ℝ)≠0) hx0.ne'] at h + linarith + exact ⟨hdpos,hdle,hdX,hXY,hY2,hhY,hlogY⟩ + +lemma exponential_recovery_tail {c X : ℝ} (hc : 0 < c) (hc2 : c ≤ 1/2) + (hX : 3 ≤ X) (hh : 1 ≤ cubeHeight X) + (hpoly : (cubeHeight X)^3 ≤ Real.exp ((c/4)*cubeHeight X)) : + let delta := Real.exp (-(c/2)*cubeHeight X) + (delta*X+1)*Real.log ((1+delta)*X) ≤ 4*X*Real.exp (-(c/4)*cubeHeight X) := by + let delta := Real.exp (-(c/2)*cubeHeight X) + obtain ⟨hd,_,hdX,hXY,_,_,hlogY⟩ := exponential_recovery_scale (d:=c/2) + (by positivity) (by linarith) hX hh + have hx0 : 0 < X := by linarith + have hY0 : 0 < (1+delta)*X := by positivity + have hlogY0 : 0 ≤ Real.log ((1+delta)*X) := Real.log_nonneg (by linarith) + have hprod : delta*Real.log X ≤ Real.exp (-(c/4)*cubeHeight X) := by + calc + _ = delta*(cubeHeight X)^3 := by rw [cubeHeight_pow_three (by linarith : 1≤X)] + _ ≤ delta*Real.exp ((c/4)*cubeHeight X) := mul_le_mul_of_nonneg_left hpoly hd.le + _ = _ := by dsimp [delta]; rw [← Real.exp_add]; congr 1; ring + calc + _ ≤ (2*delta*X)*(2*Real.log X) := mul_le_mul (by nlinarith) hlogY hlogY0 (by positivity) + _ = 4*X*(delta*Real.log X) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hprod (by positivity) + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +theorem sharp_character_exponential : + ∃ c K : ℝ, 0 < c ∧ c ≤ 1/2 ∧ 0 < K ∧ ∀ᶠ X : ℝ in atTop, + ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), chi ≠ 1 → + (q:ℝ) ≤ Real.exp (cubeHeight X) → + ‖sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ + K*X*Real.exp (-c*cubeHeight X) := by + obtain ⟨c,C,hc,hc2,hC,hRiesz⟩ := riesz_character_exponential + obtain ⟨X0,hX0⟩ := eventually_atTop.mp hRiesz + refine ⟨c/4,5*C+4,by positivity,by linarith,by positivity,?_⟩ + filter_upwards [eventually_ge_atTop X0,eventually_ge_atTop (3:ℝ), + cubeHeight_tendsto.eventually (eventually_polynomial_le_exp 1 3 (by positivity : 0 chi n*(ArithmeticFunction.vonMangoldt n:ℂ) + have hx0 : 0 < X := by linarith + have hx1 : 1 < X := by linarith + have hh0 : 0 < h := cubeHeight_pos hx1 + obtain ⟨hd,hd1,hdX,hXY,hY2,hhY,_⟩ := exponential_recovery_scale (d:=c/2) + (by positivity) (by linarith) hX hpoly.1 + have hqY : (q:ℝ) ≤ Real.exp (cubeHeight Y) := hq.trans (Real.exp_le_exp.mpr hhY) + have hx := hX0 X hthreshold q chi hchi hq + have hy := hX0 Y (hthreshold.trans hXY) q chi hchi hqY + have hdecay : Real.exp (-c*cubeHeight Y) ≤ Real.exp (-c*h) := + Real.exp_le_exp.mpr (by nlinarith) + have hy' : ‖rieszSum f Y‖ ≤ 2*C*X*Real.exp (-c*h) := by + calc + _ ≤ C*Y*Real.exp (-c*cubeHeight Y) := hy + _ ≤ C*Y*Real.exp (-c*h) := mul_le_mul_of_nonneg_left hdecay (by positivity) + _ ≤ C*(2*X)*Real.exp (-c*h) := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hY2 hC.le) (Real.exp_pos _).le + _ = _ := by ring + have hnum : (1+delta)*‖rieszSum f Y‖+‖rieszSum f X‖ ≤ 5*C*X*Real.exp (-c*h) := by + have h1 := mul_le_mul_of_nonneg_left hy' (show 0 ≤ 1+delta by linarith) + have h2 := mul_le_mul_of_nonneg_right (show 1+delta ≤ 2 by linarith) + (show 0 ≤ 2*C*X*Real.exp (-c*h) by positivity) + apply (add_le_add (h1.trans h2) hx).trans_eq + ring + have hterm : ((1+delta)*‖rieszSum f Y‖+‖rieszSum f X‖)/delta ≤ + 5*C*X*Real.exp (-(c/4)*h) := by + calc + _ ≤ (5*C*X*Real.exp (-c*h))/delta := div_le_div_of_nonneg_right hnum hd.le + _ = 5*C*X*Real.exp (-(c/2)*h) := by + dsimp [delta] + rw [mul_div_assoc,← Real.exp_sub] + congr 1 + congr 1 + ring + _ ≤ _ := mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (by nlinarith)) (by positivity) + have htail := exponential_recovery_tail hc hc2 hX hpoly.1 (by simpa only [one_mul] using hpoly.2) + have hcoeff : ∀ n : ℕ, 0 < n → ‖f n‖ ≤ Real.log (n:ℝ) := + fun n _ => character_vonMangoldt_norm_le chi n + have hsharp := sharpSum_norm_le_riesz f hcoeff (show 1 ≤ X by linarith) hd + apply (hsharp.trans (add_le_add hterm htail)).trans_eq + ring + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma eventually_polynomial_le_X_exp (K : ℝ) (n : ℕ) (d : ℝ) : + ∀ᶠ X : ℝ in atTop, K*(cubeHeight X)^n ≤ X*Real.exp (-d*cubeHeight X) := by + filter_upwards [eventually_ge_atTop (3:ℝ), + cubeHeight_tendsto.eventually (eventually_ge_atTop (d+1)), + cubeHeight_tendsto.eventually (eventually_polynomial_le_exp K n (by norm_num : (0:ℝ)<1))] + with X hX hd hp + let h := cubeHeight X + have hh : 0 ≤ h := by linarith [hp.1] + have hh2 : h ≤ h^2 := by nlinarith [hp.1] + have hsq : d+1 ≤ h^2 := hd.trans hh2 + have hm := mul_le_mul_of_nonneg_right hsq hh + have hcube : h^3=Real.log X := cubeHeight_pow_three (by linarith) + have he : h ≤ Real.log X-d*h := by rw [← hcube]; nlinarith + calc + _ ≤ Real.exp h := by simpa only [one_mul] using hp.2 + _ ≤ Real.exp (Real.log X-d*h) := Real.exp_le_exp.mpr he + _ = X*Real.exp (-d*h) := by rw [sub_eq_add_neg,Real.exp_add,Real.exp_log (by linarith : 0 (ArithmeticFunction.vonMangoldt n:ℂ)) X-(X:ℂ)‖ ≤ + K*X*Real.exp (-d*cubeHeight X) := by + obtain ⟨a,ha,hPNT⟩ := _root_.Erdos970.Strong_PNT + obtain ⟨K,hK,hbound⟩ := hPNT.exists_pos + refine ⟨K,hK,?_⟩ + filter_upwards [hbound.bound,eventually_exp_sqrt_log_le ha hd, + eventually_ge_atTop (3:ℝ)] with X hb he hX + have hx0 : 0 < X := by linarith + change ‖_root_.Erdos970.ChebyshevPsi X-X‖ ≤ K*‖X*Real.exp (-a*(Real.log X)^(1/2:ℝ))‖ at hb + rw [sharpSum_vonMangoldt_eq hx0.le,← Complex.ofReal_sub,Complex.norm_real] + simp only [Real.norm_eq_abs] at hb ⊢ + rw [abs_of_nonneg (by positivity : 0≤X*Real.exp (-a*(Real.log X)^(1/2:ℝ))), + ← Real.sqrt_eq_rpow] at hb + calc + _ ≤ K*(X*Real.exp (-a*Real.sqrt (Real.log X))) := hb + _ ≤ K*(X*Real.exp (-d*cubeHeight X)) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left he hx0.le) hK.le + _ = _ := by ring + +lemma principal_difference_exponential (d : ℝ) : + ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q], (q:ℝ) ≤ Real.exp (cubeHeight X) → + ‖sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ X*Real.exp (-d*cubeHeight X) := by + filter_upwards [eventually_ge_atTop (3:ℝ),eventually_polynomial_le_X_exp (1/Real.log 2) 4 d] + with X hX hpoly + intro q _ hq + have hx1 : 1 < X := by linarith + have hL : 0 ≤ Real.log X := (Real.log_pos hx1).le + have hq0 : (0:ℝ) < q := by exact_mod_cast NeZero.pos q + have hql : Real.log (q:ℝ) ≤ cubeHeight X := by + have he := Real.log_le_log hq0 hq + simpa only [Real.log_exp] using he + calc + _ ≤ (Real.log X/Real.log 2)*Real.log (q:ℝ) := norm_principal_sharp_difference_real q hx1.le + _ ≤ (Real.log X/Real.log 2)*cubeHeight X := mul_le_mul_of_nonneg_left hql (by positivity) + _ = (1/Real.log 2)*(cubeHeight X)^4 := by rw [← cubeHeight_pow_three hx1.le]; ring + _ ≤ _ := hpoly + +theorem principal_character_exponential {d : ℝ} (hd : 0 < d) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q], + (q:ℝ) ≤ Real.exp (cubeHeight X) → + ‖sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X-(X:ℂ)‖ ≤ + K*X*Real.exp (-d*cubeHeight X) := by + obtain ⟨K,hK,hOrd⟩ := ordinary_psi_exponential hd + refine ⟨1+K,by positivity,?_⟩ + filter_upwards [principal_difference_exponential d,hOrd] with X hDiff hOrd + intro q _ hq + have hn := norm_add_le + (sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X) + (sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X-(X:ℂ)) + rw [sub_add_sub_cancel] at hn + apply (hn.trans (add_le_add (hDiff q hq) hOrd)).trans_eq + ring + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +theorem all_character_exponential : + ∃ c K : ℝ, 0 < c ∧ c ≤ 1/2 ∧ 0 < K ∧ ∀ᶠ X : ℝ in atTop, + ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + (q:ℝ) ≤ Real.exp (cubeHeight X) → + ‖sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0)‖ ≤ K*X*Real.exp (-c*cubeHeight X) := by + classical + obtain ⟨c,C,hc,hc2,hC,hNon⟩ := sharp_character_exponential + obtain ⟨D,hD,hPrin⟩ := principal_character_exponential hc + refine ⟨c,C+D,hc,hc2,by positivity,?_⟩ + filter_upwards [hNon,hPrin,eventually_ge_atTop (3:ℝ)] with X hNon hPrin hX + intro q _ chi hq + have hx0 : 0 ≤ X := by linarith + have hcb : C*X*Real.exp (-c*cubeHeight X) ≤ (C+D)*X*Real.exp (-c*cubeHeight X) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (by linarith) hx0) (Real.exp_pos _).le + have hdb : D*X*Real.exp (-c*cubeHeight X) ≤ (C+D)*X*Real.exp (-c*cubeHeight X) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (by linarith) hx0) (Real.exp_pos _).le + by_cases hchi : chi=1 + · subst chi + simpa using! (hPrin q hq).trans hdb + · simpa [hchi] using! (hNon q chi hchi hq).trans hcb + +theorem residuePsi_exponential : + ∃ c K : ℝ, 0 < c ∧ c ≤ 1/2 ∧ 0 < K ∧ ∀ᶠ X : ℝ in atTop, + ∀ (q : ℕ) [NeZero q] (a : ZMod q), IsUnit a → + (q:ℝ) ≤ Real.exp (cubeHeight X) → + |residuePsi a X-X/(q.totient:ℝ)| ≤ K*X*Real.exp (-c*cubeHeight X) := by + obtain ⟨c,K,hc,hc2,hK,hall⟩ := all_character_exponential + refine ⟨c,K,hc,hc2,hK,?_⟩ + filter_upwards [hall] with X hX + intro q _ a ha hq + have h := residuePsi_error_le a ha X (K*X*Real.exp (-c*cubeHeight X)) (fun chi => hX q chi hq) + have he : ‖(residuePsi a X:ℂ)-(X:ℂ)/(q.totient:ℂ)‖ = + |residuePsi a X-X/(q.totient:ℝ)| := by + rw [show (q.totient:ℂ) = ((q.totient:ℝ):ℂ) by simp, + ← Complex.ofReal_div,← Complex.ofReal_sub,Complex.norm_real,Real.norm_eq_abs] + rwa [he] at h + +theorem residueTheta_exponential : + ∃ c K : ℝ, 0 < c ∧ c ≤ 1/2 ∧ 0 < K ∧ ∀ᶠ X : ℝ in atTop, + ∀ (q : ℕ) [NeZero q] (a : ZMod q), IsUnit a → + (q:ℝ) ≤ Real.exp (cubeHeight X) → + |residueTheta a X-X/(q.totient:ℝ)| ≤ K*X*Real.exp (-c*cubeHeight X) := by + obtain ⟨c,K,hc,hc2,hK,hpsi⟩ := residuePsi_exponential + obtain ⟨D,hD⟩ := Chebyshev.psi_sub_theta_le_mul_sqrt + let C : ℝ := max D 1 + have hC : 0 < C := lt_of_lt_of_le zero_lt_one (le_max_right _ _) + refine ⟨c,K+C,hc,hc2,by positivity,?_⟩ + filter_upwards [hpsi,eventually_sqrt_le_X_exp c] with X hX hsqrt + intro q _ a ha hq + have hgap := residuePsi_sub_theta_bounds a X + have hb : residuePsi a X-residueTheta a X ≤ C*X*Real.exp (-c*cubeHeight X) := by + calc + _ ≤ D*Real.sqrt X := hgap.2.trans (hD X) + _ ≤ C*Real.sqrt X := mul_le_mul_of_nonneg_right (le_max_left _ _) (Real.sqrt_nonneg _) + _ ≤ C*(X*Real.exp (-c*cubeHeight X)) := mul_le_mul_of_nonneg_left hsqrt hC.le + _ = _ := by ring + calc + _ ≤ |residuePsi a X-X/(q.totient:ℝ)|+|residuePsi a X-residueTheta a X| := by + have h := abs_sub_le (residueTheta a X) (residuePsi a X) (X/(q.totient:ℝ)) + rw [abs_sub_comm (residueTheta a X) (residuePsi a X),add_comm] at h + exact h + _ ≤ K*X*Real.exp (-c*cubeHeight X)+C*X*Real.exp (-c*cubeHeight X) := by + rw [abs_of_nonneg hgap.1] + exact add_le_add (hX q a ha hq) hb + _ = _ := by ring + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter _root_.MeasureTheory +open scoped Topology + +lemma cubeHeight_above_sqrt {X t : ℝ} (hX : 3 ≤ Real.sqrt X) (ht : Real.sqrt X ≤ t) : + cubeHeight X/2 ≤ cubeHeight t := by + have hs : 0 < Real.sqrt X := by linarith + have hx0 : 0 < X := Real.sqrt_pos.mp hs + have hx1 : 1 < X := by nlinarith [Real.sq_sqrt hx0.le] + have ht1 : 1 < t := by linarith + have hhX : 0 < cubeHeight X := cubeHeight_pos hx1 + have hht : 0 < cubeHeight t := cubeHeight_pos ht1 + have hcompare : Real.log X ≤ 2*Real.log t := by + have he := Real.log_le_log hs ht + rw [Real.log_sqrt hx0.le] at he + linarith + apply (pow_le_pow_iff_left₀ (show 0 ≤ cubeHeight X/2 by positivity) hht.le (by decide : (3:ℕ)≠0)).mp + rw [show (cubeHeight X/2)^3=(cubeHeight X)^3/8 by ring, + cubeHeight_pow_three hx1.le,cubeHeight_pow_three ht1.le] + have hlog := Real.log_pos hx1 + linarith + +lemma modulus_exponential_above_sqrt {c X t : ℝ} (hc : c ≤ 1/2) + (hX : 3 ≤ Real.sqrt X) (ht : Real.sqrt X ≤ t) {q : ℕ} + (hq : (q:ℝ) ≤ Real.exp (c*cubeHeight X)) : + (q:ℝ) ≤ Real.exp (cubeHeight t) := by + have hx0 : 0 < X := Real.sqrt_pos.mp (by linarith) + have hhX : 0 < cubeHeight X := cubeHeight_pos (by nlinarith [Real.sq_sqrt hx0.le]) + apply hq.trans (Real.exp_le_exp.mpr ?_) + calc + _ ≤ cubeHeight X/2 := by nlinarith + _ ≤ _ := cubeHeight_above_sqrt hX ht + +lemma residueErrorKernel_exp_upper {q : ℕ} (a : ZMod q) {K d X t : ℝ} + (hK : 0 ≤ K) (hd : 0 < d) (hX : 3 ≤ Real.sqrt X) (ht : Real.sqrt X ≤ t) + (herror : |residueTheta a t-t/(q.totient:ℝ)| ≤ K*t*Real.exp (-d*cubeHeight t)) : + |residueErrorKernel a t| ≤ K*Real.exp (-(d/2)*cubeHeight X) := by + have ht3 : 3 ≤ t := hX.trans ht + have ht0 : 0 < t := by linarith + have hl1 : 1 ≤ Real.log t := + ((Real.lt_log_iff_exp_lt ht0).mpr (Real.exp_one_lt_three.trans_le ht3)).le + have hcompare := cubeHeight_above_sqrt hX ht + rw [residueErrorKernel_eq a ht0,abs_div,abs_of_pos (by positivity : 0 by + rw [Set.uIoc_of_le hsX] at ht + simpa only [Real.norm_eq_abs] using + residueErrorKernel_exp_upper a hK hd hX ht.1.le (herror t ht.1.le)) + rw [Real.norm_eq_abs,abs_of_nonneg (sub_nonneg.mpr hsX)] at he + calc + _ ≤ K*Real.exp (-(d/2)*cubeHeight X)*(X-Real.sqrt X) := he + _ ≤ K*Real.exp (-(d/2)*cubeHeight X)*X := + mul_le_mul_of_nonneg_left (sub_le_self _ (Real.sqrt_nonneg _)) (by positivity) + _ = _ := by ring + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter _root_.MeasureTheory +open scoped Topology +open ErdosPrimeInputs.PrimeCountAbel (logarithmicIntegral) + +lemma large_modulus_siegel_walfisz_eventually : + ∃ c C : ℝ, 0 < c ∧ c ≤ 1/2 ∧ 0 < C ∧ ∀ᶠ X : ℝ in atTop, + ∀ (q : ℕ) [NeZero q] (r : ℤ), IsUnit (r:ZMod q) → + (q:ℝ) ≤ Real.exp (c*cubeHeight X) → + |((intervalPrimes 0 X q r).card:ℝ)-logarithmicIntegral X/(q.totient:ℝ)| ≤ + C*X*Real.exp (-c*cubeHeight X) := by + obtain ⟨d,K,hd,hd2,hK,hθ⟩ := residueTheta_exponential + obtain ⟨b,hb⟩ := eventually_atTop.mp hθ + let c : ℝ := d/2 + have hc : 0 < c := by dsimp [c]; positivity + have hc2 : c ≤ 1/2 := by dsimp [c]; linarith + let D : ℝ := (Real.log 4+1)/(Real.log 2)^2 + let E : ℝ := 2/Real.log 2 + have hD : 0 < D := by dsimp [D]; positivity + have hE : 0 < E := by dsimp [E]; positivity + refine ⟨c,E+2*K+D,hc,hc2,by positivity,?_⟩ + filter_upwards [Real.tendsto_sqrt_atTop.eventually (eventually_ge_atTop (max 3 b)), + eventually_ge_atTop (3:ℝ),eventually_sqrt_le_X_exp c, + eventually_polynomial_le_X_exp 1 0 c] with X hs hX hroot hscale + intro q _ r hr hq + have hs3 : 3 ≤ Real.sqrt X := (le_max_left _ _).trans hs + have hsb : b ≤ Real.sqrt X := (le_max_right _ _).trans hs + have hx0 : 0 < X := by linarith + have hsX : Real.sqrt X ≤ X := by nlinarith [Real.sq_sqrt hx0.le] + have hhX : 0 < cubeHeight X := cubeHeight_pos (by linarith) + have hL1 : 1 ≤ Real.log X := + ((Real.lt_log_iff_exp_lt hx0).mpr (Real.exp_one_lt_three.trans_le hX)).le + have hL : 0 < Real.log X := by linarith + have hscale1 : 1 ≤ X*Real.exp (-c*cubeHeight X) := by simpa only [pow_zero,mul_one] using hscale + have herror : ∀ t, Real.sqrt X ≤ t → + |residueTheta (r:ZMod q) t-t/(q.totient:ℝ)| ≤ K*t*Real.exp (-d*cubeHeight t) := by + intro t ht + exact hb t (hsb.trans ht) q (r:ZMod q) hr + (modulus_exponential_above_sqrt hc2 hs3 ht hq) + have hdecay : Real.exp (-d*cubeHeight X) ≤ Real.exp (-c*cubeHeight X) := + Real.exp_le_exp.mpr (by dsimp [c]; nlinarith) + have hend : |(residueTheta (r:ZMod q) X-X/(q.totient:ℝ))/Real.log X| ≤ + K*X*Real.exp (-c*cubeHeight X) := by + rw [abs_div,abs_of_pos hL] + calc + _ ≤ (K*X*Real.exp (-d*cubeHeight X))/Real.log X := + div_le_div_of_nonneg_right (herror X hsX) hL.le + _ ≤ K*X*Real.exp (-d*cubeHeight X) := div_le_self (by positivity) hL1 + _ ≤ _ := mul_le_mul_of_nonneg_left hdecay (by positivity) + have hlo : |∫ t in 2..Real.sqrt X, residueErrorKernel (r:ZMod q) t| ≤ + D*X*Real.exp (-c*cubeHeight X) := by + calc + _ ≤ D*Real.sqrt X := residueErrorKernel_low_integral _ (by linarith) + _ ≤ D*(X*Real.exp (-c*cubeHeight X)) := mul_le_mul_of_nonneg_left hroot hD.le + _ = _ := by ring + have hhi := residueErrorKernel_exp_high_integral (r:ZMod q) hK.le hd hs3 herror + have hsplit := intervalIntegral.integral_add_adjacent_intervals + (residueErrorKernel_integrable (r:ZMod q) (by norm_num) (by linarith : (2:ℝ)≤Real.sqrt X)) + (residueErrorKernel_integrable (r:ZMod q) (by linarith : (2:ℝ)≤Real.sqrt X) hsX) + have hint : |∫ t in 2..X, residueErrorKernel (r:ZMod q) t| ≤ + D*X*Real.exp (-c*cubeHeight X)+K*X*Real.exp (-c*cubeHeight X) := by + rw [← hsplit] + exact (abs_add_le _ _).trans (add_le_add hlo hhi) + have hphi : (1:ℝ) ≤ q.totient := by exact_mod_cast Nat.totient_pos.mpr (NeZero.pos q) + have hconst : |2/((q.totient:ℝ)*Real.log 2)| ≤ E*X*Real.exp (-c*cubeHeight X) := by + rw [abs_of_nonneg (by positivity)] + calc + _ = E/(q.totient:ℝ) := by dsimp [E]; ring + _ ≤ E := div_le_self hE.le hphi + _ ≤ E*(X*Real.exp (-c*cubeHeight X)) := by simpa only [mul_one] using mul_le_mul_of_nonneg_left hscale1 hE.le + _ = _ := by ring + rw [intervalPrimes_error_eq (by linarith) q r] + calc + _ ≤ |2/((q.totient:ℝ)*Real.log 2)|+ + |(residueTheta (r:ZMod q) X-X/(q.totient:ℝ))/Real.log X|+ + |∫ t in 2..X, residueErrorKernel (r:ZMod q) t| := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ ≤ E*X*Real.exp (-c*cubeHeight X)+K*X*Real.exp (-c*cubeHeight X)+ + (D*X*Real.exp (-c*cubeHeight X)+K*X*Real.exp (-c*cubeHeight X)) := + add_le_add (add_le_add hconst hend) hint + _ = _ := by ring + +theorem large_modulus_siegel_walfisz : + ∃ c C X₀ : ℝ, 0 < c ∧ 0 < C ∧ 3 ≤ X₀ ∧ ∀ X : ℝ, X₀ ≤ X → + ∀ (q : ℕ) (r : ℤ), 0 < q → IsCoprime r (q:ℤ) → + (q:ℝ) ≤ Real.exp (c*(Real.log X)^((1:ℝ)/3)) → + |((intervalPrimes 0 X q r).card:ℝ)-logarithmicIntegral X/(q.totient:ℝ)| ≤ + C*X*Real.exp (-c*(Real.log X)^((1:ℝ)/3)) := by + obtain ⟨c,C,hc,_hc2,hC,h⟩ := large_modulus_siegel_walfisz_eventually + obtain ⟨b,hb⟩ := eventually_atTop.mp h + refine ⟨c,C,max 3 b,hc,hC,le_max_left _ _,?_⟩ + intro X hX q r hq hr hbound + let _ : NeZero q := ⟨hq.ne'⟩ + exact hb X ((le_max_right _ _).trans hX) q r (isUnit_intCast_of_isCoprime hr) hbound + +end Erdos970Dependency.SiegelWalfisz + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/LargePrimeDivisors.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LargePrimeDivisors.lean new file mode 100644 index 0000000000000000000000000000000000000000..40d2b2795bdad1bc3fc7d9dec85381ca2ca02137 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LargePrimeDivisors.lean @@ -0,0 +1,52 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosLineCollision + +noncomputable def dividingPrimes (P : Finset ℕ) (m : ℤ) : Finset ℕ := by + classical + exact P.filter (fun p => (p : ℤ) ∣ m) + +theorem dividingPrimes_card_bound (P : Finset ℕ) (m : ℤ) (hm : m ≠ 0) + (hprime : ∀ p ∈ P, Nat.Prime p) (z alpha C : ℝ) (hz : 1 < z) (ha : 0 < alpha) + (hlarge : ∀ p ∈ P, z^alpha ≤ (p : ℝ)) (hheight : |(m : ℝ)| ≤ z^C) : + ((dividingPrimes P m).card : ℝ) ≤ C/alpha := by + classical + have hd : (∏ p ∈ dividingPrimes P m,p) ∣ m.natAbs := + Finset.prod_primes_dvd m.natAbs + (fun p hp => (hprime p (Finset.mem_filter.mp hp).1).prime) + (fun _ hp => Int.natCast_dvd.mp (Finset.mem_filter.mp hp).2) + have hprod := Nat.le_of_dvd (Int.natAbs_pos.mpr hm) hd + have hpow : z^(alpha*((dividingPrimes P m).card : ℝ)) ≤ z^C := by + calc + _ = ∏ _p ∈ dividingPrimes P m,z^alpha := by + rw [Finset.prod_const,Real.rpow_mul_natCast (by linarith : 0 ≤ z)] + _ ≤ ∏ p ∈ dividingPrimes P m,(p : ℝ) := + Finset.prod_le_prod₀ (fun _ _ => Real.rpow_nonneg (by linarith) _) + (fun p hp => hlarge p (Finset.mem_filter.mp hp).1) + _ = ((∏ p ∈ dividingPrimes P m,p : ℕ) : ℝ) := by simp + _ ≤ (m.natAbs : ℝ) := by exact_mod_cast hprod + _ = |(m : ℝ)| := by rw [Nat.cast_natAbs,Int.cast_abs] + _ ≤ _ := hheight + have hh := (Real.rpow_le_rpow_left_iff hz).mp hpow + apply (le_div_iff₀ ha).mpr + nlinarith + +theorem integer_difference_abs_le {x y : ℤ} {S : ℝ} + (hx : 0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) (hy : 0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) : + |((x-y : ℤ) : ℝ)| ≤ S := by + rw [Int.cast_sub,abs_le] + constructor <;> linarith [hx.1,hx.2,hy.1,hy.2] + +end ErdosLineCollision + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/LastPrimeModulusCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LastPrimeModulusCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..1b6b77b0cf09d8029997942bd16726eb465ff4f9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LastPrimeModulusCount.lean @@ -0,0 +1,180 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualSampleWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.StoppedModulusCount + +open _root_.Finset +open FinitePathGeometry PrimeHistories StoppedCountVertex StoppedVertexHistory StoppedTraceSets +open StoppedTraceAdmission StoppedCountAdapters ReferencePruning ErdosInverseCounts +attribute [local instance] Classical.propDecidable + +theorem trace_product_eq_finset (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ expanded w stop n v ∨ ps ∈ stopped w stop n v) : + (∏ p ∈ ps.toFinset,p) = ps.prod := by + simpa only [List.map_id'] using List.prod_toFinset (fun p : ℕ => p) (trace_nodup w stop n v hp) + +theorem trace_primeFactors (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (hP : ∀ p ∈ v.available,Nat.Prime p) {ps : List ℕ} + (hp : ps ∈ expanded w stop n v ∨ ps ∈ stopped w stop n v) : ps.prod.primeFactors = ps.toFinset := by + have hprime : ∀ p ∈ ps.toFinset,Nat.Prime p := + fun p hp' => trace_primes w stop n v hP hp p (List.mem_toFinset.mp hp') + have h := ErdosInverseCounts.primeFactors_product ps.toFinset hprime + rwa [trace_product_eq_finset w stop n v hp] at h + +theorem trace_product_squarefree (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (hP : ∀ p ∈ v.available,Nat.Prime p) {ps : List ℕ} + (hp : ps ∈ expanded w stop n v ∨ ps ∈ stopped w stop n v) : Squarefree ps.prod := by + have hprime : ∀ p ∈ ps.toFinset,Nat.Prime p := + fun p hp' => trace_primes w stop n v hP hp p (List.mem_toFinset.mp hp') + rw [← trace_product_eq_finset w stop n v hp] + refine Finset.squarefree_prod_of_pairwise_isCoprime (fun p hp q hq hpq => ?_) + (fun p hp => (hprime p hp).squarefree) + exact Nat.coprime_iff_isRelPrime.mp ((Nat.coprime_primes (hprime p hp) (hprime q hq)).mpr hpq) + +theorem trace_mass_eq_modulusCount (w : ℝ) (Y : ℕ) (small P : Finset ℕ) (a : ℕ → ℕ) + (z : Node) (mu : ℝ) (stop : List ℕ → Prop) (n : ℕ) + (hP : ∀ p ∈ P,Nat.Prime p) {ps : List ℕ} + (hp : ps ∈ expanded w stop n (rootVertex z ∅ P mu) ∨ ps ∈ stopped w stop n (rootVertex z ∅ P mu)) : + countMass Y small a (after w (rootVertex z ∅ P mu) ps) = (modulusCount Y small a ps.prod : ℝ) := by + rw [root_after_mass,Finset.empty_union,modulusCount_eq_mass Y small a _ (suffixPrimes P ps), + trace_primeFactors w stop n (rootVertex z ∅ P mu) hP hp] + +theorem trace_survivors_eq_product_node (w : ℝ) (Y : ℕ) (small P : Finset ℕ) (a : ℕ → ℕ) + (z : Node) (mu : ℝ) (stop : List ℕ → Prop) (n : ℕ) + (hP : ∀ p ∈ P,Nat.Prime p) {ps : List ℕ} + (hp : ps ∈ expanded w stop n (rootVertex z ∅ P mu) ∨ ps ∈ stopped w stop n (rootVertex z ∅ P mu)) : + countSurvivors Y small a (after w (rootVertex z ∅ P mu) ps) = + (ResidueSieveTree.survivorCount Y small a (ps.prod.primeFactors,suffixPrimes P ps) : ℝ) := by + rw [root_after_survivors,Finset.empty_union,trace_primeFactors w stop n (rootVertex z ∅ P mu) hP hp] + +theorem trace_bad_edge_iff (w : ℝ) (Y : ℕ) (small P : Finset ℕ) (a : ℕ → ℕ) + (z : Node) (mu delta V0 : ℝ) (stop : List ℕ → Prop) (n : ℕ) + (hP : ∀ p ∈ P,Nat.Prime p) {ps : List ℕ} + (hp : ps ∈ expanded w stop n (rootVertex z ∅ P mu) ∨ ps ∈ stopped w stop n (rootVertex z ∅ P mu)) + {u : ℕ} (hu : u ∈ (after w (rootVertex z ∅ P mu) ps).available) : + NodeBadEdge Y small a delta V0 ps.prod u ↔ + |countMass Y small a (child w (after w (rootVertex z ∅ P mu) ps) u)- + countMass Y small a (after w (rootVertex z ∅ P mu) ps)/(u:ℝ)| > + delta*(Y:ℝ)*V0/((ps.prod:ℝ)*(u:ℝ)) := by + have hpf := trace_primeFactors w stop n (rootVertex z ∅ P mu) hP hp + have hm : ps.prod ≠ 0 := (trace_product_squarefree w stop n (rootVertex z ∅ P mu) hP hp).ne_zero + have hup : u ∈ P := by + rw [after_available] at hu + exact (Finset.mem_filter.mp hu).1 + rw [nodeBadEdge_iff_tree_mass Y small a delta V0 ps.prod u (suffixPrimes P ps) hm (hP u hup)] + simp only [countMass_eq_tree_mass,child,after_required,after_available,rootVertex, + Finset.empty_union,ResidueSieveTree.child,hpf] + +end NumberTheoryLean.StoppedModulusCount + +end + +section + +namespace NumberTheoryLean.LastPrimeModulusCount +open PrimeHistories StoppedCountVertex StoppedVertexHistory StoppedCountAdapters +open ReferencePruning SievePartition LargePrimeDeletion LogarithmicBinPartition ErdosInverseCounts +attribute [local instance] Classical.propDecidable + +theorem survivor_required_union (Y : ℕ) (H small P : Finset ℕ) (a : ℕ → ℕ) : + survivors (residueCandidates Y H small a) P (residueBad a)=residueCandidates Y H (small∪P) a := by + ext n + simp only [mem_survivors,mem_residueCandidates,Finset.mem_union,or_imp,forall_and] + tauto + +theorem below_all_last (ps : List ℕ) (hne : ps≠[]) (hd : ps.Pairwise (· > ·)) (q : ℕ) : + (∀ p∈ps,q rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [he] + constructor + · intro h + exact h _ (List.getLast_mem hne) + · intro h p hp + have hd' : (ps.dropLast++[ps.getLast hne]).Pairwise (· > ·) := by rwa [List.dropLast_append_getLast] + rw [← List.dropLast_append_getLast hne] at hp + rcases List.mem_append.mp hp with hp | hp + · exact h.trans ((List.pairwise_append.mp hd').2.2 p hp _ (by simp)) + · simpa only [List.mem_singleton.mp hp] using h + +theorem small_suffix_strict_cutoff {w top : ℝ} (hw : 0 < w) (htop : w < top) + (ps : List ℕ) (hne : ps≠[]) (hd : ps.Pairwise (· > ·)) + (hsource : ∀ p∈ps,p∈sourcePrimeSet w top) : + cutoffPrimes ⌊w⌋₊∪suffixPrimes (sourcePrimeSet w top) ps=cutoffPrimes (ps.getLastD 0-1) := by + have he : ps.getLastD 0=ps.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + have hlast : ps.getLastD 0∈ps := by rw [he]; exact List.getLast_mem hne + have hP := (mem_sourcePrimeSet hw htop _).mp (hsource _ hlast) + ext q + constructor + · intro hq + rcases Finset.mem_union.mp hq with hq | hq + · obtain ⟨hqprime,hqw⟩ := mem_cutoffPrimes.mp hq + have hqr : (q:ℝ) < (ps.getLastD 0:ℝ) := ((Nat.le_floor_iff hw.le).mp hqw).trans_lt hP.2.1 + have hqn : q < ps.getLastD 0 := by exact_mod_cast hqr + exact mem_cutoffPrimes.mpr ⟨hqprime,by omega⟩ + · obtain ⟨hqS,hall⟩ := Finset.mem_filter.mp hq + have hqprime := ((mem_sourcePrimeSet hw htop q).mp hqS).1 + have hlastq := (below_all_last ps hne hd q).mp hall + exact mem_cutoffPrimes.mpr ⟨hqprime,by omega⟩ + · intro hq + obtain ⟨hqprime,hql⟩ := mem_cutoffPrimes.mp hq + have hPlast : 0 < ps.getLastD 0 := hP.1.pos + have hqP : q < ps.getLastD 0 := by omega + by_cases hqw : q ≤ ⌊w⌋₊ + · exact Finset.mem_union_left _ (mem_cutoffPrimes.mpr ⟨hqprime,hqw⟩) + · have hwq : w < (q:ℝ) := lt_of_not_ge (fun h => hqw ((Nat.le_floor_iff hw.le).mpr h)) + have hqt : (q:ℝ) ≤ top := (show (q:ℝ) ≤ (ps.getLastD 0:ℝ) by exact_mod_cast hqP.le).trans hP.2.2 + exact Finset.mem_union_right _ (Finset.mem_filter.mpr + ⟨(mem_sourcePrimeSet hw htop q).mpr ⟨hqprime,hwq,hqt⟩,(below_all_last ps hne hd q).mpr hqP⟩) + +theorem after_survivors_eq_last_modulusCount (Y : ℕ) {w top : ℝ} + (hw : 0 < w) (htop : w < top) (a : ℕ → ℕ) (z : Node) (mu : ℝ) + (ps : List ℕ) (hne : ps≠[]) (hd : ps.Pairwise (· > ·)) + (hsource : ∀ p∈ps,p∈sourcePrimeSet w top) : + countSurvivors Y (cutoffPrimes ⌊w⌋₊) a (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)= + (modulusCount Y (cutoffPrimes (ps.getLastD 0-1)) a ps.prod:ℝ) := by + have hprime : ∀ p∈ps.toFinset,p.Prime := fun p hp => + ((mem_sourcePrimeSet hw htop p).mp (hsource p (List.mem_toFinset.mp hp))).1 + have hprod : (∏ p∈ps.toFinset,p)=ps.prod := by + simpa only [List.map_id'] using List.prod_toFinset (fun p : ℕ => p) (hd.imp (fun h => ne_of_gt h)) + have hfac : ps.prod.primeFactors=ps.toFinset := by + rw [← hprod] + exact primeFactors_product ps.toFinset hprime + unfold countSurvivors + rw [after_required,after_available] + change ((survivors (residueCandidates Y (∅∪ps.toFinset) (cutoffPrimes ⌊w⌋₊) a) + (suffixPrimes (sourcePrimeSet w top) ps) (residueBad a)).card:ℝ)=_ + rw [Finset.empty_union,survivor_required_union,small_suffix_strict_cutoff hw htop ps hne hd hsource] + simp only [modulusCount,modulusCandidates,Int.cast_natCast,hfac] + +theorem frozen_survivors_eq_modulusCount (Y : ℕ) {w top : ℝ} + (hw : 0 < w) (htop : w < top) (a : ℕ → ℕ) (z : Node) (mu : ℝ) + (pre tail : List ℕ) (p : ℕ) (htail : tail≠[]) + (hd : (pre++p::tail).Pairwise (· > ·)) + (hsource : ∀ q∈pre++p::tail,q∈sourcePrimeSet w top) : + countSurvivors Y (cutoffPrimes ⌊w⌋₊) a (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) (pre++p::tail))= + (modulusCount Y (cutoffPrimes (tail.getLastD 0-1)) a (p*(pre.prod*tail.prod)):ℝ) := by + have hlast : (pre++p::tail).getLastD 0=tail.getLastD 0 := by + rw [← List.dropLast_append_getLast htail] + rw [← List.cons_append,← List.append_assoc] + simp only [List.getLastD_concat] + rw [after_survivors_eq_last_modulusCount Y hw htop a z mu _ (by simp) hd hsource,hlast] + congr 2 + simp only [List.prod_append,List.prod_cons] + ring +end NumberTheoryLean.LastPrimeModulusCount + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/LineCongruenceConstruction.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LineCongruenceConstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..c2f0e5f0e3921dd913ca4865be40a32689847061 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LineCongruenceConstruction.lean @@ -0,0 +1,70 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LineSubstitution +import OAI.NumberTheory.Jacobsthal.Partitions.CoefficientBoxCollision + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +abbrev ResidueSystem (P : Finset ℕ) (T : ∀ p : P, Finset (ZMod p.val)) (D : ℕ) := + ∀ p : P, ∀ _s : T p, Fin (D+1) → ZMod p.val + +@[implicit_reducible] +noncomputable def residueFintype (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : ∀ p : P, Finset (ZMod p.val)) (D : ℕ) : Fintype (ResidueSystem P T D) := by + letI (p : P) : NeZero p.val := ⟨Nat.ne_of_gt (hP p p.property)⟩ + exact inferInstance + +theorem residueSystem_card (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : ∀ p : P, Finset (ZMod p.val)) (D : ℕ) : + @Fintype.card (ResidueSystem P T D) (residueFintype P hP T D) = + ∏ p : P, p.val^((D+1)*(T p).card) := by + classical + let (p : P) : NeZero p.val := ⟨Nat.ne_of_gt (hP p p.property)⟩ + change Fintype.card (∀ p : P, ∀ _s : T p, Fin (D+1) → ZMod p.val) = _ + simp [Fintype.card_pi,← pow_mul] + +noncomputable def constraintMap (P : Finset ℕ) (T : ∀ p : P, Finset (ZMod p.val)) + (a : ∀ p : P, ZMod p.val) (D : ℕ) : (MonomialIndex D → ℤ) →+ ResidueSystem P T D where + toFun v p s k := (lineSub (Int.castRingHom (ZMod p.val)) (a p) s.val (encode v)).coeff k + map_zero' := by + funext p s k + simp [encode] + map_add' v w := by + funext p s k + change (lineSub (Int.castRingHom (ZMod p.val)) (a p) s.val (encode (v+w))).coeff k = + (lineSub (Int.castRingHom (ZMod p.val)) (a p) s.val (encode v)).coeff k + + (lineSub (Int.castRingHom (ZMod p.val)) (a p) s.val (encode w)).coeff k + rw [show encode (v+w) = encode v+encode w from (encodeHom D).map_add v w, + map_add,Polynomial.coeff_add] + +theorem exists_line_congruence_polynomial (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : ∀ p : P, Finset (ZMod p.val)) (a : ∀ p : P, ZMod p.val) (D H : ℕ) + (hbox : (∏ p : P, p.val^((D+1)*(T p).card)) < (H+1)^((D+2).choose 2)) : + ∃ Q : MvPolynomial (Fin 2) ℤ, Q ≠ 0 ∧ Q.totalDegree ≤ D ∧ + (∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) ∧ + ∀ p : P, ∀ s : T p, lineSub (Int.castRingHom (ZMod p.val)) (a p) s.val Q = 0 := by + classical + let := residueFintype P hP T D + have hc : Fintype.card (ResidueSystem P T D) < (H+1)^(Fintype.card (MonomialIndex D)) := by + rw [residueSystem_card,monomialIndex_card] + exact hbox + obtain ⟨v,hv,hbound,hzero⟩ := exists_bounded_kernel_vector (constraintMap P T a D) H hc + refine ⟨encode v,(encode_eq_zero_iff v).not.mpr hv,encode_degree_le v, + encode_coefficient_bound v hbound,?_⟩ + intro p s + apply lineSub_encode_eq_zero + intro k + have h := congrFun (congrFun (congrFun hzero p) s) k + exact h + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/LinearSieveFunctions.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LinearSieveFunctions.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a5aa8bf7c5230d03f8a4a2a2528bf1bde415210 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LinearSieveFunctions.lean @@ -0,0 +1,196 @@ +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Renewal.DickmanFiniteDecay + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.LinearSieveFunctions + +open MeasureTheory Filter +open scoped Topology + +noncomputable def plus : ℝ → ℝ := DelayConstruction.delay 1 + +theorem plus_continuous : Continuous plus := DelayConstruction.delay_continuous 1 + +theorem plus_initial {u : ℝ} (hu : u ≤ 1) : plus u = 1 := DelayConstruction.delay_initial 1 hu + +noncomputable def f (A s : ℝ) : ℝ := + if s ≤ 2 then 0 else A * (plus (s - 1) - Dickman.rho (s - 1)) / (2 * s) + +noncomputable def F (A s : ℝ) : ℝ := + A * (plus (s - 1) + Dickman.rho (s - 1)) / (2 * s) + +noncomputable def startingExtension (A s : ℝ) : ℝ := A * Real.log (s - 1) / s + +theorem f_initial (A : ℝ) {s : ℝ} (hs : s ≤ 2) : f A s = 0 := by simp only [f, ite_eq_left hs] + +theorem f_eq_difference (A s : ℝ) : + f A s = A * (plus (s - 1) - Dickman.rho (s - 1)) / (2 * s) := by + by_cases hs : s ≤ 2 + · rw [f_initial A hs, plus_initial (by linarith), Dickman.rho_initial (by linarith)] + simp + · simp only [f, ite_eq_right hs] + +theorem plus_add_rho_initial {u : ℝ} (hu : u ≤ 2) : plus u + Dickman.rho u = 2 := by + change DelayConstruction.delay 1 u + DelayConstruction.delay (-1) u = 2 + rw [DelayConstruction.delay_eq_stepApprox 1 1 (by norm_num; exact hu), + DelayConstruction.delay_eq_stepApprox (-1) 1 (by norm_num; exact hu)] + simp only [DelayConstruction.stepApprox, DelayConstruction.kernel, one_mul, neg_one_mul] + ring + +theorem mass_f (A : ℝ) {s : ℝ} (hs : s ≠ 0) : + s * f A s = (A / 2) * (plus (s - 1) - Dickman.rho (s - 1)) := by + rw [f_eq_difference] + field_simp + +theorem mass_F (A : ℝ) {s : ℝ} (hs : s ≠ 0) : + s * F A s = (A / 2) * (plus (s - 1) + Dickman.rho (s - 1)) := by + unfold F + field_simp + +theorem F_initial (A : ℝ) {s : ℝ} (hs0 : 0 < s) (hs3 : s ≤ 3) : F A s = A / s := by + unfold F + rw [plus_add_rho_initial (by linarith)] + field_simp + +theorem f_continuousAt_of_ne_zero (A : ℝ) {s : ℝ} (hs : s ≠ 0) : ContinuousAt (f A) s := by + have hnum : Continuous (fun x : ℝ => A * (plus (x - 1) - Dickman.rho (x - 1))) := + continuous_const.mul ((plus_continuous.comp (continuous_id.sub continuous_const)).sub + (Dickman.rho_continuous.comp (continuous_id.sub continuous_const))) + have hraw : ContinuousAt (fun x : ℝ => A * (plus (x - 1) - Dickman.rho (x - 1)) / (2 * x)) s := + hnum.continuousAt.div (continuous_const.mul continuous_id).continuousAt (by exact mul_ne_zero (by norm_num) hs) + exact (continuousAt_congr (Filter.Eventually.of_forall (f_eq_difference A))).mpr hraw + +theorem f_continuous (A : ℝ) : Continuous (f A) := by + apply continuous_iff_continuousAt.mpr + intro s + by_cases hs : s = 0 + · subst s + have heq : f A =ᶠ[𝓝 0] (fun _ => 0) := by + filter_upwards [Iio_mem_nhds (by norm_num : (0 : ℝ) < 2)] with x hx + exact f_initial A hx.le + exact (continuousAt_congr heq).mpr continuous_const.continuousAt + · exact f_continuousAt_of_ne_zero A hs + +theorem F_continuousAt (A : ℝ) {s : ℝ} (hs : s ≠ 0) : ContinuousAt (F A) s := by + have hnum : Continuous (fun x : ℝ => A * (plus (x - 1) + Dickman.rho (x - 1))) := + continuous_const.mul ((plus_continuous.comp (continuous_id.sub continuous_const)).add + (Dickman.rho_continuous.comp (continuous_id.sub continuous_const))) + exact hnum.continuousAt.div (continuous_const.mul continuous_id).continuousAt (mul_ne_zero (by norm_num) hs) + +theorem gap_identity (A : ℝ) {s : ℝ} (hs : 1 ≤ s) : + F A s - f A s = A * Dickman.rho (s - 1) / s := by + rw [f_eq_difference] + unfold F + have hs0 : s ≠ 0 := by linarith + field_simp + ring + +theorem mass_f_hasDerivAt (A : ℝ) {s : ℝ} (hs : 2 < s) : + HasDerivAt (fun x => x * f A x) (F A (s - 1)) s := by + have hp : HasDerivAt plus (plus (s - 1 - 1) / (s - 1)) (s - 1) := by + simpa only [plus, one_mul] using DelayConstruction.delay_hasDerivAt 1 (u := s - 1) (by linarith) + have hpShift := hp.comp s ((hasDerivAt_id s).sub_const 1) + have hrShift := (Dickman.rho_hasDerivAt (u := s - 1) (by linarith)).comp s ((hasDerivAt_id s).sub_const 1) + have hraw := (hpShift.sub hrShift).const_mul (A / 2) + have heq : (fun x => x * f A x) =ᶠ[𝓝 s] + (fun x => (A / 2) * (plus (x - 1) - Dickman.rho (x - 1))) := by + filter_upwards [Ioi_mem_nhds (show 0 < s by linarith)] with x hx + exact mass_f A (ne_of_gt hx) + have hd := hraw.congr_of_eventuallyEq heq + convert! hd using 1 + unfold F + field_simp + ring + +theorem mass_F_hasDerivAt (A : ℝ) {s : ℝ} (hs : 2 < s) : + HasDerivAt (fun x => x * F A x) (f A (s - 1)) s := by + have hp : HasDerivAt plus (plus (s - 1 - 1) / (s - 1)) (s - 1) := by + simpa only [plus, one_mul] using DelayConstruction.delay_hasDerivAt 1 (u := s - 1) (by linarith) + have hpShift := hp.comp s ((hasDerivAt_id s).sub_const 1) + have hrShift := (Dickman.rho_hasDerivAt (u := s - 1) (by linarith)).comp s ((hasDerivAt_id s).sub_const 1) + have hraw := (hpShift.add hrShift).const_mul (A / 2) + have heq : (fun x => x * F A x) =ᶠ[𝓝 s] + (fun x => (A / 2) * (plus (x - 1) + Dickman.rho (x - 1))) := by + filter_upwards [Ioi_mem_nhds (show 0 < s by linarith)] with x hx + exact mass_F A (ne_of_gt hx) + have hd := hraw.congr_of_eventuallyEq heq + convert! hd using 1 + rw [f_eq_difference] + field_simp + ring + +theorem F_continuousOn (A : ℝ) : ContinuousOn (F A) (Set.Ioi 0) := by + intro s hs + exact (F_continuousAt A (ne_of_gt hs)).continuousWithinAt + +theorem mass_F_initial (A : ℝ) {s : ℝ} (hs1 : 1 ≤ s) (hs3 : s ≤ 3) : s * F A s = A := by + rw [F_initial A (by linarith) hs3] + field_simp + +theorem mass_f_integral (A : ℝ) {s : ℝ} (hs : 2 ≤ s) : + s * f A s = ∫ t in (2 : ℝ)..s, F A (t - 1) := by + have hInt : IntervalIntegrable (fun t : ℝ => F A (t - 1)) volume 2 s := by + apply ContinuousOn.intervalIntegrable + intro t ht + rw [Set.uIcc_of_le hs] at ht + have hF := F_continuousAt A (s := t - 1) (by linarith [ht.1]) + have hshift : ContinuousAt (fun x : ℝ => x - 1) t := (continuous_id.sub continuous_const).continuousAt + exact (hF.comp (f := fun x : ℝ => x - 1) (x := t) hshift).continuousWithinAt + have hFTC := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hs + (continuous_id.mul (f_continuous A)).continuousOn + (fun t ht => mass_f_hasDerivAt A ht.1) hInt + simpa only [Pi.mul_apply, id_eq, f_initial A (le_refl 2), mul_zero, sub_zero] using hFTC.symm + +theorem mass_F_integral (A : ℝ) {s : ℝ} (hs : 3 ≤ s) : + s * F A s = A + ∫ t in (3 : ℝ)..s, f A (t - 1) := by + have hcont : ContinuousOn (fun t : ℝ => t * F A t) (Set.Icc 3 s) := by + intro t ht + exact (continuousAt_id.mul (F_continuousAt A (by linarith [ht.1]))).continuousWithinAt + have hshift : Continuous (fun x : ℝ => x - 1) := continuous_id.sub continuous_const + have hInt : IntervalIntegrable (fun t : ℝ => f A (t - 1)) volume 3 s := + ((f_continuous A).comp hshift).intervalIntegrable 3 s + have hFTC := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hs hcont + (fun t ht => mass_F_hasDerivAt A (by linarith [ht.1])) hInt + rw [mass_F_initial A (s := 3) (by norm_num) (le_refl 3)] at hFTC + linarith + +theorem f_first_formula (A : ℝ) {s : ℝ} (hs2 : 2 ≤ s) (hs4 : s ≤ 4) : + f A s = A * Real.log (s - 1) / s := by + have hMass := mass_f_integral A hs2 + have hInt : (∫ t in (2 : ℝ)..s, F A (t - 1)) = A * Real.log (s - 1) := by + calc + (∫ t in (2 : ℝ)..s, F A (t - 1)) = ∫ t in (2 : ℝ)..s, A / (t - 1) := by + apply intervalIntegral.integral_congr + intro t ht + rw [Set.uIcc_of_le hs2] at ht + change F A (t - 1) = A / (t - 1) + exact F_initial A (by linarith [ht.1]) (by linarith [ht.2]) + _ = ∫ t in (1 : ℝ)..s - 1, A / t := by + simpa only [show (2 : ℝ) - 1 = 1 by norm_num] using + intervalIntegral.integral_comp_sub_right (fun t : ℝ => A / t) 1 (a := 2) (b := s) + _ = A * ∫ t in (1 : ℝ)..s - 1, 1 / t := by + simp only [div_eq_mul_inv, one_mul, intervalIntegral.integral_const_mul] + _ = _ := by rw [integral_one_div_of_pos (by norm_num) (by linarith), div_one] + rw [hInt] at hMass + apply (eq_div_iff (show s ≠ 0 by linarith)).mpr + nlinarith + +theorem startingExtension_eq_f (A : ℝ) {s : ℝ} (hs2 : 2 ≤ s) (hs4 : s ≤ 4) : + startingExtension A s = f A s := (f_first_formula A hs2 hs4).symm + +theorem gap_pos {A s : ℝ} (hA : 0 < A) (hs : 1 ≤ s) : 0 < F A s - f A s := by + rw [gap_identity A hs] + exact div_pos (mul_pos hA (Dickman.rho_pos _)) (by linarith) + +end NumberTheoryLean.LinearSieveFunctions + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/LiteralModulusEnvelope.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LiteralModulusEnvelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..bbb317185c58e67d2ff165431925e58de9e5b8b3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/LiteralModulusEnvelope.lean @@ -0,0 +1,97 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueCountDifference + +namespace OAI + +namespace Erdos970 + + +namespace ErdosModulusRelative +open ErdosInverseHits ErdosInverseCounts NumberTheoryLean + +theorem modulus_small_upper (aStar : ℝ) (ha : 0 < aStar) : + ∃ C w0 : ℝ,0 < C ∧ 2 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → + ∀ (Y d : ℕ) (a : ℕ → ℕ),0 < Y → Squarefree d → + (∀ p ∈ d.primeFactors,w < (p : ℝ)) → + aStar ≤ Real.log ((Y : ℝ)/(d : ℝ))/Real.log w → + (modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a d : ℝ) ≤ + C*((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊ := by + obtain ⟨C,hC,w0,hw0,hupper⟩ := SmallSieveUpper.progression_small_upper aStar ha + refine ⟨C,w0,hC,hw0,?_⟩ + intro w hw Y d a hY hd hlarge hv + have hw2 : 2 ≤ w := hw0.trans hw + have hw1 : 1 < w := by linarith + have hd0 : 0 < d := Nat.pos_of_ne_zero hd.ne_zero + have hJ : 0 < (Y : ℝ)/(d : ℝ) := by positivity + have hJL : w^aStar ≤ (Y : ℝ)/(d : ℝ) := by + calc + _ ≤ w^(Real.log ((Y : ℝ)/(d : ℝ))/Real.log w) := + Real.rpow_le_rpow_of_exponent_le hw1.le hv + _ = _ := SmallSieveRelative.rpow_log_ratio w _ hw1 hJ + have hb := primeHitRepresentative_spec d hd a + have hN := hitLength_error Y d (primeHitRepresentative d hd a) hd0 hb.1 hb.2.1 + have hh := hupper (hitLength Y d (primeHitRepresentative d hd a)) w ((Y : ℝ)/(d : ℝ)) + (primeHitRepresentative d hd a : ℤ) d a hw hJL hN (large_modulus_coprime_small w d hd hlarge) + rw [modulus_count_eq_offsets Y _ a d hd,offsets_eq_progression,Int.cast_natCast] + exact hh + +theorem modulus_error_uniform_bound (aStar : ℝ) (ha : 0 < aStar) : + ∃ B w0 : ℝ,0 < B ∧ 2 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → + ∀ (Y d : ℕ) (a : ℕ → ℕ),0 < Y → Squarefree d → + (∀ p ∈ d.primeFactors,w < (p : ℝ)) → + aStar ≤ Real.log ((Y : ℝ)/(d : ℝ))/Real.log w → + |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a d : ℝ)/ + (((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊)-1| ≤ B := by + obtain ⟨C,w0,hC,hw0,hupper⟩ := modulus_small_upper aStar ha + refine ⟨C+1,w0,by linarith,hw0,?_⟩ + intro w hw Y d a hY hd hlarge hv + have hw2 : 2 ≤ w := hw0.trans hw + have hd0 : 0 < d := Nat.pos_of_ne_zero hd.ne_zero + have hJ : 0 < (Y : ℝ)/(d : ℝ) := by positivity + have hV : 0 < SmallSieveFinite.smallEuler ⌊w⌋₊ := + (inv_pos.mpr (show 0 < w by linarith)).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2) + have hDen : 0 < ((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊ := mul_pos hJ hV + have hu := (div_le_iff₀ hDen).mpr (by + simpa only [mul_assoc] using hupper w hw Y d a hY hd hlarge hv) + have hnon : 0 ≤ (modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a d : ℝ) := by + exact_mod_cast modulusCount_nonneg Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a d + have hn := div_nonneg hnon hDen.le + rw [abs_le] + constructor <;> linarith + +theorem modulus_error_envelope (aStar : ℝ) (ha : 0 < aStar) : + ∃ C w0 : ℝ,0 < C ∧ 1 < w0 ∧ ∀ w : ℝ,w0 ≤ w → + ∀ (Y d : ℕ) (a : ℕ → ℕ),0 < Y → 0 < d → Squarefree d → + (∀ p ∈ d.primeFactors,w < (p : ℝ)) → + aStar ≤ Real.log ((Y : ℝ)/(d : ℝ))/Real.log w → + |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a d : ℝ)/ + (((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊)-1| ≤ + C*Real.exp (-(Real.log ((Y : ℝ)/(d : ℝ))/Real.log w)/192) := by + obtain ⟨B,w0,hB,hw0,hbound⟩ := modulus_error_uniform_bound aStar ha + let C := max 3 (B*Real.exp ((960048 : ℝ)/192)) + have hC3 : 3 ≤ C := le_max_left _ _ + have hCB : B*Real.exp ((960048 : ℝ)/192) ≤ C := le_max_right _ _ + refine ⟨C,w0,by linarith,by linarith,?_⟩ + intro w hw Y d a hY _hdpos hd hlarge hv + let v := Real.log ((Y : ℝ)/(d : ℝ))/Real.log w + by_cases hbig : 960048 ≤ v + · exact (modulus_small_relative w Y d a (hw0.trans hw) hY hd hlarge hbig).trans + (mul_le_mul_of_nonneg_right hC3 (Real.exp_pos (-v/192)).le) + · have hvmax : v ≤ 960048 := le_of_lt (lt_of_not_ge hbig) + have he : 1 ≤ Real.exp ((960048 : ℝ)/192)*Real.exp (-v/192) := by + rw [← Real.exp_add] + exact Real.one_le_exp_iff.mpr (by linarith) + have hBC : B ≤ C*Real.exp (-v/192) := by + calc + _ = B*1 := by ring + _ ≤ B*(Real.exp ((960048 : ℝ)/192)*Real.exp (-v/192)) := + mul_le_mul_of_nonneg_left he hB.le + _ = (B*Real.exp ((960048 : ℝ)/192))*Real.exp (-v/192) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right hCB (Real.exp_pos _).le + exact (hbound w hw Y d a hY hd hlarge hv).trans hBC + +end ErdosModulusRelative + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/MarkedCycleFactorization.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/MarkedCycleFactorization.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d6c39ef8be210ac95b886e2d8155b7925cc1ba7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/MarkedCycleFactorization.lean @@ -0,0 +1,87 @@ +import OAI.NumberTheory.Jacobsthal.Probability.MarkedCostSublaws + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.CycleRegeneration +open NumberTheoryLean.RegenerationTails + +lemma completedMarked_ae_regeneration (z : OddCost) : + ∀ᵐ y ∂completedMarkedKernel z, y.2 ∈ returnSet := by + have he := returnLaw_ae_regeneration z + rw [← completedMarked_forget z] at he + exact (ae_map_iff measurable_snd.aemeasurable returnSet_measurable).mp he + +lemma completedMarked_increment_law (s : OddState) (hs : s.1 ≤ 3) (T : ℝ) : + (completedMarkedKernel (s,T)).map (markedShift (-T)) = sourceCycleLaw := by + rw [completedMarked_regeneration s hs T] + have ht := completedMarked_translation regenerationState 0 T + simp only [zero_add] at ht + rw [← ht,Measure.map_map (markedShift_measurable (-T)) (markedShift_measurable T)] + have he : markedShift (-T) ∘ markedShift T = id := by + funext z + ext <;> simp [markedShift,shiftCost,Function.comp_apply,add_assoc] + rw [he,Measure.map_id] + rfl + +def markCostProjection (z : MarkedOddCost) : Bool × ℝ := (z.1,z.2.2) + +lemma markCostProjection_measurable : Measurable markCostProjection := + measurable_fst.prodMk (measurable_snd.comp measurable_snd) + +noncomputable def jointMarkCostLaw : Measure (Bool × ℝ) := sourceCycleLaw.map markCostProjection + +instance jointMarkCostLaw_isProbabilityMeasure : IsProbabilityMeasure jointMarkCostLaw := by + unfold jointMarkCostLaw + exact (Measure.isProbabilityMeasure_map_iff markCostProjection_measurable.aemeasurable).mpr inferInstance + +lemma marked_cycle_increment_integral (z : OddCost) (hz : z ∈ returnSet) + {F : Bool × ℝ → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F (y.1,y.2.2-z.2) ∂completedMarkedKernel z) = ∫⁻ u, F u ∂jointMarkCostLaw := by + have he := congrArg (fun μ : Measure MarkedOddCost => ∫⁻ y, F (markCostProjection y) ∂μ) + (completedMarked_increment_law z.1 hz z.2) + rw [lintegral_map (f := fun y : MarkedOddCost => F (markCostProjection y)) + (hF.comp markCostProjection_measurable) (markedShift_measurable (-z.2))] at he + rw [jointMarkCostLaw,lintegral_map hF markCostProjection_measurable] + simpa only [markCostProjection,markedShift,shiftCost,sub_eq_add_neg] using he + +noncomputable def markedCycleProductExpectation : List (Bool × ℝ → ℝ≥0∞) → OddCost → ℝ≥0∞ + | [], _ => 1 + | F :: Fs, z => ∫⁻ y, F (y.1,y.2.2-z.2)*markedCycleProductExpectation Fs y.2 ∂completedMarkedKernel z + +theorem finite_marked_cycle_factorization (Fs : List (Bool × ℝ → ℝ≥0∞)) + (hFs : ∀ F ∈ Fs, Measurable F) (z : OddCost) (hz : z ∈ returnSet) : + markedCycleProductExpectation Fs z = + (Fs.map (fun F => ∫⁻ u, F u ∂jointMarkCostLaw)).prod := by + induction Fs generalizing z with + | nil => rfl + | cons F Fs ih => + have hF : Measurable F := hFs F (by simp) + have hrest : ∀ G ∈ Fs, Measurable G := fun G hG => hFs G (by simp [hG]) + change (∫⁻ y, F (y.1,y.2.2-z.2)*markedCycleProductExpectation Fs y.2 ∂completedMarkedKernel z) = + (∫⁻ u, F u ∂jointMarkCostLaw)*(Fs.map (fun F => ∫⁻ u, F u ∂jointMarkCostLaw)).prod + calc + _ = ∫⁻ y, F (y.1,y.2.2-z.2)*(Fs.map (fun F => ∫⁻ u, F u ∂jointMarkCostLaw)).prod ∂completedMarkedKernel z := by + apply lintegral_congr_ae + filter_upwards [completedMarked_ae_regeneration z] with y hy + rw [ih hrest y.2 hy] + _ = (∫⁻ y, F (y.1,y.2.2-z.2) ∂completedMarkedKernel z)* + (Fs.map (fun F => ∫⁻ u, F u ∂jointMarkCostLaw)).prod := + lintegral_mul_const _ (hF.comp (measurable_fst.prodMk + ((measurable_snd.comp measurable_snd).sub measurable_const))) + _ = _ := by rw [marked_cycle_increment_integral z hz hF] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/MobiusCoprimeExpansion.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/MobiusCoprimeExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce79aa1102127f81cfef8cc076c98d7dada676db --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/MobiusCoprimeExpansion.lean @@ -0,0 +1,74 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosCoprimeResidueInterval +open scoped ArithmeticFunction.Moebius +attribute [local instance] Classical.propDecidable + +theorem moebius_divisor_sum (n : ℕ) : + (∑ d ∈ n.divisors, (μ d : ℝ)) = if n = 1 then 1 else 0 := by + have h := congrArg (fun f : ArithmeticFunction ℝ => f n) + (ArithmeticFunction.coe_moebius_mul_coe_zeta (R := ℝ)) + simpa only [ArithmeticFunction.coe_mul_zeta_apply,ArithmeticFunction.intCoe_apply, + ArithmeticFunction.one_apply] using h + +theorem coprime_indicator (H : ℕ) (hH : 0 < H) (m : ℤ) : + (∑ d ∈ H.divisors, if (d : ℤ) ∣ m then (μ d : ℝ) else 0) = + if H.Coprime m.natAbs then 1 else 0 := by + have hg : 0 < H.gcd m.natAbs := Nat.gcd_pos_of_pos_left m.natAbs hH + have hf : H.divisors.filter (fun d : ℕ => (d : ℤ) ∣ m) = (H.gcd m.natAbs).divisors := by + ext d + simp only [Finset.mem_filter,Nat.mem_divisors,Int.natCast_dvd,Nat.dvd_gcd_iff] + constructor + · rintro ⟨⟨hdH,_⟩,hdm⟩ + exact ⟨⟨hdH,hdm⟩,hg.ne'⟩ + · rintro ⟨⟨hdH,hdm⟩,_⟩ + exact ⟨⟨hdH,hH.ne'⟩,hdm⟩ + rw [← Finset.sum_filter,hf,moebius_divisor_sum] + +theorem moebius_abs_le_one (d : ℕ) : |(μ d : ℝ)| ≤ 1 := by + exact_mod_cast ArithmeticFunction.abs_moebius_le_one (n := d) + +theorem moebius_density (H : ℕ) (hH : 0 < H) : + (∑ d ∈ H.divisors, (μ d : ℝ)/(d : ℝ)) = (H.totient : ℝ)/(H : ℝ) := by + have ht : ∀ n : ℕ, 0 < n → (∑ d ∈ n.divisors, (d.totient : ℝ)) = (n : ℝ) := by + intro n _ + exact_mod_cast Nat.sum_totient n + have hi := ArithmeticFunction.sum_eq_iff_sum_mul_moebius_eq.mp ht H hH + rw [Nat.sum_divisorsAntidiagonal (fun d k => (μ d : ℝ)*(k : ℝ))] at hi + apply (eq_div_iff (show (H : ℝ) ≠ 0 by exact_mod_cast hH.ne')).mpr + rw [Finset.sum_mul] + calc + _ = ∑ d ∈ H.divisors, (μ d : ℝ)*((H/d : ℕ) : ℝ) := by + apply Finset.sum_congr rfl + intro d hd + rw [Nat.cast_div (Nat.dvd_of_mem_divisors hd) + (by exact_mod_cast (Nat.pos_of_mem_divisors hd).ne')] + ring + _ = _ := hi + +theorem coprime_count_expansion (H : ℕ) (hH : 0 < H) (C : Finset ℤ) (F : ℤ → Prop) : + ((C.filter (fun m => H.Coprime m.natAbs ∧ F m)).card : ℝ) = + ∑ d ∈ H.divisors, (μ d : ℝ)*((C.filter (fun m => (d : ℤ) ∣ m ∧ F m)).card : ℝ) := by + classical + simp only [Finset.card_filter,Nat.cast_sum,Nat.cast_ite,Nat.cast_one,Nat.cast_zero, + Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro m _ + by_cases hF : F m + · simpa only [hF,and_true,mul_ite,mul_one,mul_zero] using (coprime_indicator H hH m).symm + · simp [hF] + +end ErdosCoprimeResidueInterval + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/OddEulerCorrection.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OddEulerCorrection.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf99961f0d2e868db7911c838ed79b713d0457dc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OddEulerCorrection.lean @@ -0,0 +1,88 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + + +namespace ErdosOddEulerCorrection + +noncomputable def correction (k : ℕ) : ℝ := 1-1/((k : ℝ)+2)^2 + +theorem correction_nonneg (k : ℕ) : 0 ≤ correction k := by + have hk : (0 : ℝ) ≤ k := Nat.cast_nonneg k + have hp : (0 : ℝ) < ((k : ℝ)+2)^2 := by positivity + apply sub_nonneg.mpr + apply (div_le_one hp).mpr + nlinarith + +theorem correction_le_one (k : ℕ) : correction k ≤ 1 := by + dsimp [correction] + have : (0 : ℝ) ≤ 1/((k : ℝ)+2)^2 := by positivity + linarith + +theorem correction_range (N : ℕ) : + (∏ k ∈ Finset.range N, correction k) = ((N : ℝ)+2)/(2*((N : ℝ)+1)) := by + induction N with + | zero => norm_num + | succ N ih => + rw [Finset.prod_range_succ,ih] + dsimp [correction] + push_cast + have h1 : (N : ℝ)+1 ≠ 0 := by positivity + have h2 : (N : ℝ)+2 ≠ 0 := by positivity + field_simp + ring + +theorem correction_finite_lower (S : Finset ℕ) : + (1 : ℝ)/2 ≤ ∏ k ∈ S, correction k := by + let N := S.sup id+1 + have hS : S ⊆ Finset.range N := by + intro k hk + apply Finset.mem_range.mpr + exact Nat.lt_succ_of_le (Finset.le_sup (f := id) hk) + have hprod := Finset.prod_le_prod_of_subset_of_le_one₀ hS + (fun k _ => correction_nonneg k) (fun k _ _ => correction_le_one k) + have hhalf : (1 : ℝ)/2 ≤ ∏ k ∈ Finset.range N, correction k := by + rw [correction_range] + apply (le_div_iff₀ (show (0 : ℝ) < 2*((N : ℝ)+1) by positivity)).mpr + linarith + exact hhalf.trans hprod + +theorem odd_correction_product_lower (P : Finset ℕ) (hP : ∀ p ∈ P,3 ≤ p) : + (1 : ℝ)/2 ≤ ∏ p ∈ P, (1-1/((p : ℝ)-1)^2) := by + classical + have h := correction_finite_lower (P.image (fun p => p-3)) + rw [Finset.prod_image (fun p hp q hq he => by have := hP p hp; have := hP q hq; omega)] at h + have he : (∏ p ∈ P, correction (p-3)) = ∏ p ∈ P, (1-1/((p : ℝ)-1)^2) := by + apply Finset.prod_congr rfl + intro p hp + dsimp [correction] + rw [Nat.cast_sub (hP p hp)] + norm_num only [Nat.cast_ofNat] + rw [show (p : ℝ)-3+2=(p : ℝ)-1 by ring] + rwa [he] at h + +theorem odd_two_class_factorization (P : Finset ℕ) (hP : ∀ p ∈ P,3 ≤ p) : + (∏ p ∈ P, (1-2/(p : ℝ))) = + (∏ p ∈ P, (1-1/((p : ℝ)-1)^2))*(∏ p ∈ P, (1-1/(p : ℝ)))^2 := by + rw [← Finset.prod_pow,← Finset.prod_mul_distrib] + apply Finset.prod_congr rfl + intro p hp + have hp3 : (3 : ℝ) ≤ p := by exact_mod_cast hP p hp + have hp0 : (p : ℝ) ≠ 0 := by linarith + have hp1 : (p : ℝ)-1 ≠ 0 := by linarith + field_simp + ring + +theorem odd_two_class_product_lower (P : Finset ℕ) (hP : ∀ p ∈ P,3 ≤ p) : + (1 : ℝ)/2*(∏ p ∈ P, (1-1/(p : ℝ)))^2 ≤ ∏ p ∈ P, (1-2/(p : ℝ)) := by + rw [odd_two_class_factorization P hP] + exact mul_le_mul_of_nonneg_right (odd_correction_product_lower P hP) (sq_nonneg _) + +end ErdosOddEulerCorrection + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalCofactorPoints.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalCofactorPoints.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac042b7478b1d40c70f894734ac7bd8f50452f5b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalCofactorPoints.lean @@ -0,0 +1,173 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.NonstructuredCounts +import OAI.NumberTheory.Jacobsthal.Partitions.SourceLabelCount +import OAI.NumberTheory.Jacobsthal.Paths.ActualSampleWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseRefinement +open ErdosInverseSampling +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def selectedRow (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (q : ℕ) : Finset ℕ := + P.filter (fun p => ∀ i : Fin h,witness (p,q) (s i).val) + +noncomputable def rowReward (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (q : ℕ) : ℝ := (selectedRow P U witness h s q).card/(P.card : ℝ) + +theorem selected_pairs_card_by_rows (P C U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) : + (selectedPairs (P.product C) U witness h s).card = ∑ q ∈ C,(selectedRow P U witness h s q).card := by + calc + _ = ∑ p ∈ P,∑ q ∈ C,if (∀ i : Fin h,witness (p,q) (s i).val) then (1 : ℕ) else 0 := by + simp only [selectedPairs,Finset.card_eq_sum_ones,Finset.sum_filter] + exact Finset.sum_product P C (fun v : ℕ × ℕ => if (∀ i : Fin h,witness v (s i).val) then (1 : ℕ) else 0) + _ = ∑ q ∈ C,∑ p ∈ P,if (∀ i : Fin h,witness (p,q) (s i).val) then (1 : ℕ) else 0 := Finset.sum_comm + _ = _ := by simp only [selectedRow,Finset.card_eq_sum_ones,Finset.sum_filter] + +theorem rowReward_bounds (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (q : ℕ) (hP : 0 < P.card) : + 0 ≤ rowReward P U witness h s q ∧ rowReward P U witness h s q ≤ 1 := by + have hPpos : (0 : ℝ) < P.card := by exact_mod_cast hP + refine ⟨div_nonneg (Nat.cast_nonneg _) hPpos.le,?_⟩ + apply (div_le_iff₀ hPpos).mpr + simpa only [one_mul] using (show ((selectedRow P U witness h s q).card : ℝ) ≤ P.card by + exact_mod_cast Finset.card_le_card (Finset.filter_subset _ _)) + +theorem rowReward_sum (P C U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (hP : 0 < P.card) (hC : 0 < C.card) : + (∑ q ∈ C,rowReward P U witness h s q) = selectedFraction (P.product C) U witness h s*(C.card : ℝ) := by + have hp : (P.card : ℝ) ≠ 0 := by exact_mod_cast hP.ne' + have hc : (C.card : ℝ) ≠ 0 := by exact_mod_cast hC.ne' + unfold rowReward selectedFraction + rw [← Finset.sum_div,selected_pairs_card_by_rows,Nat.cast_sum,Finset.product_eq_sprod,Finset.card_product,Nat.cast_mul] + field_simp + +end ErdosInverseRefinement + +end + +section + +namespace ErdosInverseRefinement +open ErdosInverseSampling +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def richCofactors (D P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (gamma : ℝ) : Finset ℕ := + D.filter (fun q => gamma/8 ≤ rowReward P U witness h s q) + +theorem richCofactors_subset (D P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (gamma : ℝ) : richCofactors D P U witness h s gamma ⊆ D := + Finset.filter_subset _ _ + +theorem richCofactors_card_lower (D P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (gamma : ℝ) (hg : 0 ≤ gamma) (hP : 0 < P.card) + (hdense : (gamma/4)*(D.card : ℝ) ≤ ∑ q ∈ D,rowReward P U witness h s q) : + (gamma/8)*(D.card : ℝ) ≤ ((richCofactors D P U witness h s gamma).card : ℝ) := by + have hh := many_large_weights D (rowReward P U witness h s) (gamma/4) (by positivity) + (fun q _ => (rowReward_bounds P U witness h s q hP).2) hdense + simpa only [div_div,show (4 : ℝ)*2 = 8 by norm_num,richCofactors] using hh + +theorem richCofactor_row_card (D P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (gamma : ℝ) (hP : 0 < P.card) (q : ℕ) + (hq : q ∈ richCofactors D P U witness h s gamma) : + (gamma/8)*(P.card : ℝ) ≤ ((selectedRow P U witness h s q).card : ℝ) := by + have hp : (0 : ℝ) < P.card := by exact_mod_cast hP + have hh := (Finset.mem_filter.mp hq).2 + exact (le_div_iff₀ hp).mp hh + +theorem richCofactors_source_size (D P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (h : ℕ) (s : Sample U h) (gamma S Z : ℝ) (hg : 0 < gamma) (hS : 0 ≤ S) (hZ : 0 < Z) + (hP : 0 < P.card) (hD : S/Z^3 ≤ (D.card : ℝ)) (hInv : 1/Z ≤ gamma/8) + (hdense : (gamma/4)*(D.card : ℝ) ≤ ∑ q ∈ D,rowReward P U witness h s q) : + S/Z^4 ≤ ((richCofactors D P U witness h s gamma).card : ℝ) := by + calc + _ = (1/Z)*(S/Z^3) := by field_simp + _ ≤ (gamma/8)*(S/Z^3) := mul_le_mul_of_nonneg_right hInv (by positivity) + _ ≤ (gamma/8)*(D.card : ℝ) := mul_le_mul_of_nonneg_left hD (by positivity) + _ ≤ _ := richCofactors_card_lower D P U witness h s gamma hg.le hP hdense + +end ErdosInverseRefinement + +end + +section + +namespace ErdosInverseRefinement +open ErdosInverseCells ErdosConvexGraph +attribute [local instance] Classical.decEq + +noncomputable def cofactorPoint (a : ℕ → ℕ) (q : ℕ) : ℤ × ℤ := + ((q : ℤ),(cofactorHit q a : ℤ)) + +noncomputable def cofactorPoints (D : Finset ℕ) (a : ℕ → ℕ) : Finset (ℤ × ℤ) := + D.image (cofactorPoint a) + +theorem cofactorPoint_injective (a : ℕ → ℕ) : Function.Injective (cofactorPoint a) := by + intro q r he + have hh := congrArg Prod.fst he + change (q : ℤ) = (r : ℤ) at hh + exact_mod_cast hh + +theorem cofactorPoints_card (D : Finset ℕ) (a : ℕ → ℕ) : + (cofactorPoints D a).card = D.card := + Finset.card_image_of_injective D (cofactorPoint_injective a) + +theorem cofactorPoints_x_injective (D : Finset ℕ) (a : ℕ → ℕ) : + Set.InjOn Prod.fst (cofactorPoints D a : Set (ℤ × ℤ)) := by + rintro v hv w hw he + obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hv + obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp hw + have hqr : q = r := by + change (q : ℤ) = (r : ℤ) at he + exact_mod_cast he + exact congrArg (cofactorPoint a) hqr + +theorem cofactorPoints_square (D : Finset ℕ) (a : ℕ → ℕ) (S : ℝ) + (hq : ∀ q ∈ D,Squarefree q ∧ (q : ℝ) ≤ S) : + ∀ v ∈ cofactorPoints D a,InSquare S v := by + intro v hv + obtain ⟨q,hqD,rfl⟩ := Finset.mem_image.mp hv + have hb := cofactorHit_spec q (hq q hqD).1 a + have hbq : (cofactorHit q a : ℝ) ≤ q := by exact_mod_cast hb.2.1 + change (0 ≤ ((q : ℤ) : ℝ) ∧ ((q : ℤ) : ℝ) ≤ S) ∧ + (0 ≤ ((cofactorHit q a : ℤ) : ℝ) ∧ ((cofactorHit q a : ℤ) : ℝ) ≤ S) + push_cast + exact ⟨⟨Nat.cast_nonneg _,(hq q hqD).2⟩,⟨Nat.cast_nonneg _,hbq.trans (hq q hqD).2⟩⟩ + +theorem cofactorPoints_prime_hits (D : Finset ℕ) (a : ℕ → ℕ) + (hq : ∀ q ∈ D,Squarefree q) : + ∀ v ∈ cofactorPoints D a,∀ p ∈ v.1.toNat.primeFactors, + (v.2 : ZMod p) = (a p : ZMod p) := by + intro v hv + obtain ⟨q,hqD,rfl⟩ := Finset.mem_image.mp hv + intro p hp + have hh := (cofactorHit_spec q (hq q hqD) a).2.2 p hp + change ((cofactorHit q a : ℤ) : ZMod p) = (a p : ZMod p) + rw [Int.cast_natCast] + exact (ZMod.natCast_eq_natCast_iff _ _ _).mpr hh + +theorem rich_points_source_size (D P U : Finset ℕ) (a : ℕ → ℕ) + (witness : (ℕ × ℕ) → ℕ → Prop) (h : ℕ) (s : ErdosInverseSampling.Sample U h) + (gamma S Z : ℝ) (hg : 0 < gamma) (hS : 0 ≤ S) (hZ : 0 < Z) + (hP : 0 < P.card) (hD : S/Z^3 ≤ (D.card : ℝ)) (hInv : 1/Z ≤ gamma/8) + (hdense : (gamma/4)*(D.card : ℝ) ≤ ∑ q ∈ D,rowReward P U witness h s q) : + S/Z^4 ≤ ((cofactorPoints (richCofactors D P U witness h s gamma) a).card : ℝ) := by + rw [cofactorPoints_card] + exact richCofactors_source_size D P U witness h s gamma S Z hg hS hZ hP hD hInv hdense + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalCofactorSums.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalCofactorSums.lean new file mode 100644 index 0000000000000000000000000000000000000000..a628be63e5f3533cfa6c95e033f6e45b4aab10f7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalCofactorSums.lean @@ -0,0 +1,40 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.TwoSingletonBins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.OriginalCofactorSums +open ErdosCofactorChoices TwoSingletonBins + +attribute [local instance] Classical.propDecidable + +theorem cofactor_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hP : ∀ i,∀ p ∈ P i,p.Prime) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (G : ℕ → ℝ) : + (∑ f ∈ selections P m,G (selectionProduct f))=∑ q ∈ cofactorChoices P m,G q := by + symm + rw [cofactorChoices,Finset.sum_image] + exact fun f hf g hg he => selectionProduct_injOn P m hP hd hf hg he + +theorem two_prime_cofactor_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hP : ∀ i,∀ p ∈ P i,p.Prime) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (i j : Fin n) + (G : ℕ → ℕ → ℕ → ℝ) : + (∑ p ∈ P i,∑ u ∈ P j,∑ f ∈ selections P (eraseTwo m i j), + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(selectionProduct f:ℝ)⁻¹)*G p u (selectionProduct f))= + ∑ p ∈ P i,∑ u ∈ P j,∑ q ∈ cofactorChoices P (eraseTwo m i j), + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹)*G p u q := by + apply Finset.sum_congr rfl + intro p _hp + apply Finset.sum_congr rfl + intro u _hu + exact cofactor_sum P (eraseTwo m i j) hP hd (fun q => ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹)*G p u q) +end NumberTheoryLean.OriginalCofactorSums + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalPairSieve.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalPairSieve.lean new file mode 100644 index 0000000000000000000000000000000000000000..ebc74a19a5c08b31f5bbbb41c0f670d4c9403d41 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/OriginalPairSieve.lean @@ -0,0 +1,125 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.HarmonicLevelBound +import OAI.NumberTheory.Jacobsthal.Estimates.OriginalPairMembership +import OAI.NumberTheory.Jacobsthal.Estimates.PatternMainTerm + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosVarianceLargeCount +open NumberTheoryLean ErdosHyperbolaError ErdosPrimeInputs.PrimeProductOmissions +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +def largeSieveLevel : ℝ := 480024 +noncomputable def largeSieveExponent : ℝ := 1/(10*largeSieveLevel) +noncomputable def largeSieveCutoff (R : ℝ) : ℝ := R^largeSieveExponent + +theorem largeSieveExponent_bounds : 0 < largeSieveExponent ∧ largeSieveExponent < 1 := by + norm_num [largeSieveExponent,largeSieveLevel] + +theorem largeSieveCutoff_level (R : ℝ) (hR : 0 < R) : + (largeSieveCutoff R)^largeSieveLevel = R^((1 : ℝ)/10) := by + unfold largeSieveCutoff + rw [← Real.rpow_mul hR.le] + norm_num [largeSieveExponent,largeSieveLevel] + +theorem largeSieveCutoff_log (R : ℝ) (hR : 0 < R) : + Real.log (largeSieveCutoff R) = largeSieveExponent*Real.log R := Real.log_rpow hR _ + +theorem largeSieveCutoff_tendsto : Tendsto largeSieveCutoff atTop atTop := + tendsto_rpow_atTop largeSieveExponent_bounds.1 + +theorem largeSieveCutoff_lt (R : ℝ) (hR : 1 < R) : largeSieveCutoff R < R := by + simpa only [largeSieveCutoff,Real.rpow_one] using + Real.rpow_lt_rpow_of_exponent_lt hR largeSieveExponent_bounds.2 + +theorem source_main_R_upper : ∃ C : ℝ,0 < C ∧ ∀ᶠ R : ℝ in atTop,1 < R ∧ 2 ≤ largeSieveCutoff R ∧ + ∀ (H T0 T1 : ℕ),0 < H → 0 < T0 → 0 < T1 → T0 ∣ H → H.Coprime T1 → + ∀ (U V : ℝ),0 ≤ U → 0 ≤ V → V ≤ 2*(H : ℝ) → + sourceMain H T0 T1 U V* + (∏ t ∈ reducedPrimes ⌊largeSieveCutoff R⌋₊ (H*T1),(1-1/(t : ℝ)))* + (1+Real.exp (-largeSieveLevel/96)) ≤ + C*U/((patternCard T0 T1 : ℝ)*Real.log R) := by + obtain ⟨C,v0,hC,hv0,hmain⟩ := source_main_uniform_upper + refine ⟨C/largeSieveExponent,div_pos hC largeSieveExponent_bounds.1,?_⟩ + filter_upwards [largeSieveCutoff_tendsto.eventually_ge_atTop v0,eventually_gt_atTop (1 : ℝ)] + with R hv hR + refine ⟨hR,hv0.trans hv,?_⟩ + intro H T0 T1 hH hT0 hT1 hT0H hcop U V hU hV hVH + have hh := hmain (largeSieveCutoff R) hv H T0 T1 hH hT0 hT1 hT0H hcop U V largeSieveLevel hU hV hVH + (by norm_num [largeSieveLevel]) + rw [largeSieveCutoff_log R (by linarith)] at hh + calc + _ ≤ C*U/((patternCard T0 T1 : ℝ)*(largeSieveExponent*Real.log R)) := hh + _ = _ := by ring + +end ErdosVarianceLargeCount + +end + +section + +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceLargeCount ErdosHyperbolaError + ErdosPrimeInputs.PrimeProductOmissions +attribute [local instance] Classical.propDecidable + +theorem prime_avoids_cutoff (p : ℕ) (hp : p.Prime) (v : ℝ) (hvp : v < (p : ℝ)) + (t : ℕ) (ht : t.Prime) (htv : (t : ℝ) ≤ v) : ¬(t : ℤ) ∣ (p : ℤ) := by + intro hdiv + have hd : t ∣ p := by exact_mod_cast hdiv + rcases (Nat.dvd_prime hp).mp hd with he|he + · exact ht.ne_one he + · subst t + linarith + +theorem original_pair_mem_sifted (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) (p : goodPrimes P H) + (R : ℝ) (hR : 1 < R) (hpR : R < (p.val : ℝ)) + (x0 x1 y0 y1 : ℝ) (hp : x0 < (p.val : ℝ) ∧ (p.val : ℝ) ≤ x1) + (hm : y0 ≤ (primeM P H C0 hP p : ℝ) ∧ (primeM P H C0 hP p : ℝ) < y1) : + let v := actualFullPattern P w H C0 hw hP hlarge p + ((p.val : ℤ),primeM P H C0 hP p) ∈ + siftedSourcePairs H (divisorModulus w H) (coprimeModulus w H) C0 (v.2.1.val : ℤ) + (v.1.val.val : ℤ) (v.2.2.1.val.val : ℤ) (v.2.2.2.val : ℤ) x0 x1 y0 y1 false true true false + (reducedPrimes ⌊largeSieveCutoff R⌋₊ (H*coprimeModulus w H)) := by + dsimp only + apply Finset.mem_filter.mpr + refine ⟨original_pair_mem_sourcePairs P w H C0 hw hP hlarge p x0 x1 y0 y1 hp hm,?_⟩ + intro t ht + have hc := LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_sdiff.mp ht).1 + have hcut0 : 0 ≤ largeSieveCutoff R := Real.rpow_nonneg (by linarith) _ + have htv := (Nat.le_floor_iff hcut0).mp hc.2 + exact prime_avoids_cutoff p.val (hP p.val (Finset.mem_filter.mp p.property).1) (largeSieveCutoff R) + ((largeSieveCutoff_lt R hR).trans hpR) t hc.1 htv + +theorem original_prime_fibre_le_pairs (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (A : Finset (goodPrimes P H)) (v : ErdosLargePatternLaw.FullPattern w H) + (R : ℝ) (hR : 1 < R) (x0 x1 y0 y1 : ℝ) + (hA : ∀ p ∈ A,actualFullPattern P w H C0 hw hP hlarge p = v ∧ R < (p.val : ℝ) ∧ + (x0 < (p.val : ℝ) ∧ (p.val : ℝ) ≤ x1) ∧ + (y0 ≤ (primeM P H C0 hP p : ℝ) ∧ (primeM P H C0 hP p : ℝ) < y1)) : + A.card ≤ (siftedSourcePairs H (divisorModulus w H) (coprimeModulus w H) C0 (v.2.1.val : ℤ) + (v.1.val.val : ℤ) (v.2.2.1.val.val : ℤ) (v.2.2.2.val : ℤ) x0 x1 y0 y1 false true true false + (reducedPrimes ⌊largeSieveCutoff R⌋₊ (H*coprimeModulus w H))).card := by + apply Finset.card_le_card_of_injOn (fun p => ((p.val : ℤ),primeM P H C0 hP p)) + · intro p hp + obtain ⟨he,hpR,hpI,hmI⟩ := hA p hp + have hm := original_pair_mem_sifted P w H C0 hw hP hlarge p R hR hpR x0 x1 y0 y1 hpI hmI + dsimp only at hm + rwa [he] at hm + · exact (original_prime_pair_injective P H C0 hP).injOn + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrimeExponentialTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrimeExponentialTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..08b287565da3a1f1f61b3638e216d0e473d980a9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrimeExponentialTail.lean @@ -0,0 +1,208 @@ +import Mathlib.Algebra.Order.Field.GeomSum +import OAI.NumberTheory.Jacobsthal.Partitions.SourceAllInverseBins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ExponentialMeshTail + +open _root_.Finset + +theorem quadratic_exp_majorant {c r : ℝ} (hc : 0 < c) (hr : 0 ≤ r) : + r^2*Real.exp (-c*r) ≤ (8/c^2)*Real.exp (-c*r/2) := by + have h := Real.pow_div_factorial_le_exp (x := c*r/2) (by positivity) 2 + norm_num only [Nat.factorial_succ,Nat.factorial_zero,Nat.cast_one,Nat.cast_ofNat] at h + have hc2 : 0 < c^2 := sq_pos_of_pos hc + have hp : r^2 ≤ (8/c^2)*Real.exp (c*r/2) := by + have hh : r^2 ≤ 8*Real.exp (c*r/2)/c^2 := (le_div_iff₀ hc2).mpr (by nlinarith [h]) + convert hh using 1; ring + calc + _ ≤ ((8/c^2)*Real.exp (c*r/2))*Real.exp (-c*r) := + mul_le_mul_of_nonneg_right hp (Real.exp_pos _).le + _ = _ := by rw [mul_assoc,← Real.exp_add]; congr 2; ring + +noncomputable def envelope (c K t : ℝ) : ℝ := + (8/c^2)*Real.exp (-c*K/4)*Real.exp (-c*t/4) + +theorem reward_le_envelope {c r K t : ℝ} (hc : 0 < c) (hr : 0 ≤ r) + (hK : K ≤ r) (ht : t ≤ r) : r^2*Real.exp (-c*r) ≤ envelope c K t := by + refine (quadratic_exp_majorant hc hr).trans ?_ + unfold envelope + rw [mul_assoc,← Real.exp_add] + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Real.exp_le_exp.mpr + nlinarith + +theorem exponential_mesh_sum {a h : ℝ} (ha : 0 < a) (hh : 0 < h) (N : ℕ) : + (∑ j ∈ range N,h*Real.exp (-a*((j:ℝ)*h))) ≤ h+1/a := by + let e := Real.exp (-a*h) + have he0 : 0 < e := Real.exp_pos _ + have he1 : e < 1 := Real.exp_lt_one_iff.mpr (by nlinarith) + have hg : (∑ j ∈ range N,e^j) ≤ 1/(1-e) := by + simpa only [Nat.Ico_zero_eq_range,pow_zero] using + (geom_sum_Ico_le_of_lt_one (m:=0) (n:=N) he0.le he1) + have heq : (∑ j ∈ range N,h*Real.exp (-a*((j:ℝ)*h))) = h*(∑ j ∈ range N,e^j) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _hj + dsimp [e] + rw [← Real.exp_nat_mul] + congr 2 + ring + have hbasic : (1+a*h)*e ≤ 1 := by + calc + _ ≤ Real.exp (a*h)*e := mul_le_mul_of_nonneg_right (by simpa only [add_comm] using Real.add_one_le_exp (a*h)) he0.le + _ = _ := by dsimp [e]; rw [← Real.exp_add]; simp + have hInv : a*(1/a) = 1 := by field_simp + have hden : 0 < 1-e := by linarith + have hlast : h/(1-e) ≤ h+1/a := by + apply (div_le_iff₀ hden).mpr + have hinv0 : 0 < 1/a := one_div_pos.mpr ha + have hm := mul_le_mul_of_nonneg_left hbasic hinv0.le + nlinarith + rw [heq] + exact (mul_le_mul_of_nonneg_left hg hh.le).trans (by simpa only [mul_one_div] using hlast) + +theorem envelope_mesh_sum {c h : ℝ} (hc : 0 < c) (hh : 0 < h) (hh1 : h ≤ 1) (K : ℝ) (N : ℕ) : + (∑ j ∈ range N,h*envelope c K ((j:ℝ)*h)) ≤ + (8/c^2)*(1+4/c)*Real.exp (-c*K/4) := by + have hb := exponential_mesh_sum (a:=c/4) (by positivity) hh N + have heq : (∑ j ∈ range N,h*envelope c K ((j:ℝ)*h)) = + ((8/c^2)*Real.exp (-c*K/4))*(∑ j ∈ range N,h*Real.exp (-(c/4)*((j:ℝ)*h))) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _hj + unfold envelope + rw [show -(c/4)*((j:ℝ)*h) = -c*((j:ℝ)*h)/4 by ring] + ring + rw [heq] + have hconst : 0 ≤ (8/c^2)*Real.exp (-c*K/4) := by positivity + calc + _ ≤ ((8/c^2)*Real.exp (-c*K/4))*(h+1/(c/4)) := mul_le_mul_of_nonneg_left hb hconst + _ ≤ ((8/c^2)*Real.exp (-c*K/4))*(1+4/c) := by + apply mul_le_mul_of_nonneg_left _ hconst + have he : 1/(c/4) = 4/c := by ring + rw [he] + linarith + _ = _ := by ring + +end NumberTheoryLean.ExponentialMeshTail + +end + +section + +namespace NumberTheoryLean.PrimeExponentialTail + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open PrimeGridGeometry PrimeGridKernel PrimeInverseBins PrimeCompactWeights ExponentialMeshTail DerivativeWeights + +variable {w ell S : ℝ} {start : Node} + +noncomputable def tailReward (c K : ℝ) : ChainState w ell S start → ℝ≥0∞ + | none => 0 + | some h => if K < h.node.gap then + ENNReal.ofReal (h.node.gap^2*Real.exp (-c*h.node.gap)/weight h.node.side h.node.ratio) else 0 + +theorem grid_above {m : ℕ} (hm : 1 ≤ m) (S : ℝ) : + S < point m (⌈S*(m:ℝ)⌉₊+1) := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hceil := Nat.le_ceil (S*(m:ℝ)) + unfold point + apply (lt_div_iff₀ hm0).mpr + push_cast + linarith + +theorem actual_tail_bin_envelope {c K : ℝ} (hc : 0 < c) {m : ℕ} (hm : 1 ≤ m) + (hell : 1 ≤ ell) (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (hcons : Consistent start) (hcut : ell ≤ start.cutoff) (hsS : start.ratio ≤ S) + (z : ChainState w ell S start) : + tailReward c K z ≤ ∑ j ∈ range (⌈S*(m:ℝ)⌉₊+1), + ENNReal.ofReal (envelope c K (point m j))*(bin m j).indicator inverseWeight z := by + classical + cases z with + | none => exact zero_le + | some h => + by_cases hh : K < h.node.gap + · have hg : 0 < h.node.gap := terminal_gap_positive (by linarith) hr hs h.admissible + have hv : Valid h.node.side h.node.ratio := terminal_valid hs h.admissible + have hs0 := (valid_pos hv).le + have hS : h.node.ratio ≤ S := terminal_ratio_le hsS h.admissible + obtain ⟨j,hj,hcell⟩ := finite_grid_cover hm hs0 (hS.trans_lt (grid_above hm S)) + have hmem : some h ∈ bin m j := (mem_bin h m j).mpr hcell + have hratio : point m j ≤ h.node.gap := hcell.1.trans (history_ratio_le_gap hell hr hs hcons hcut h) + have hreward := reward_le_envelope hc hg.le hh.le hratio + have hφ := weight_pos hv + have hterm : tailReward c K (some h) ≤ + ENNReal.ofReal (envelope c K (point m j))*(bin m j).indicator inverseWeight (some h) := by + rw [indicator_of_mem hmem] + change (if K < h.node.gap then _ else _) ≤ ENNReal.ofReal _*ENNReal.ofReal _ + rw [ite_eq_left hh,← ENNReal.ofReal_mul (by unfold envelope; positivity)] + apply ENNReal.ofReal_le_ofReal + simpa only [mul_one_div] using div_le_div_of_nonneg_right hreward hφ.le + exact hterm.trans (Finset.single_le_sum (s:=range (⌈S*(m:ℝ)⌉₊+1)) (a:=j) + (f:=fun k => ENNReal.ofReal (envelope c K (point m k))*(bin m k).indicator inverseWeight (some h)) + (fun _ _ => zero_le) (by simpa only [Finset.mem_range] using Nat.lt_succ_of_le hj)) + · simp only [tailReward,ite_eq_right hh] + exact zero_le + +theorem actual_tail_integral_bins {c K : ℝ} (hc : 0 < c) {m : ℕ} (hm : 1 ≤ m) + (hell : 1 ≤ ell) (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (hcons : Consistent start) (hcut : ell ≤ start.cutoff) (hsS : start.ratio ≤ S) (n : ℕ) : + (∫⁻ z,tailReward c K z ∂pathLaw w ell S start n) ≤ + ∑ j ∈ range (⌈S*(m:ℝ)⌉₊+1),ENNReal.ofReal (envelope c K (point m j))*inverseBin w ell S start m n j := by + calc + _ ≤ ∫⁻ z,∑ j ∈ range (⌈S*(m:ℝ)⌉₊+1), + ENNReal.ofReal (envelope c K (point m j))*(bin m j).indicator inverseWeight z ∂pathLaw w ell S start n := + lintegral_mono (actual_tail_bin_envelope hc hm hell hr hs hcons hcut hsS) + _ = _ := by + rw [lintegral_finsetSum] + · apply Finset.sum_congr rfl + intro j _hj + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,lintegral_indicator (bin_measurable m j)] + rfl + · intro j _hj + exact measurable_const.mul ((measurable_of_countable inverseWeight).indicator (bin_measurable m j)) + +theorem actual_tail_from_inverse_bins {c K C : ℝ} (hc : 0 < c) (hC : 0 ≤ C) + {m : ℕ} (hm : 1 ≤ m) (hm1 : width m ≤ 1) + (hell : 1 ≤ ell) (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (hcons : Consistent start) (hcut : ell ≤ start.cutoff) (hsS : start.ratio ≤ S) (n : ℕ) + (hbins : ∀ j,inverseBin w ell S start m n j ≤ ENNReal.ofReal (C*width m)) : + (∫⁻ z,tailReward c K z ∂pathLaw w ell S start n) ≤ + ENNReal.ofReal (C*(8/c^2)*(1+4/c)*Real.exp (-c*K/4)) := by + have hh := width_pos hm + refine (actual_tail_integral_bins hc hm hell hr hs hcons hcut hsS n).trans ?_ + calc + _ ≤ ∑ j ∈ range (⌈S*(m:ℝ)⌉₊+1),ENNReal.ofReal (envelope c K (point m j))*ENNReal.ofReal (C*width m) := + Finset.sum_le_sum (fun j _ => mul_le_mul_of_nonneg_left (hbins j) zero_le) + _ = ENNReal.ofReal (C*(∑ j ∈ range (⌈S*(m:ℝ)⌉₊+1),width m*envelope c K (point m j))) := by + rw [Finset.mul_sum,ENNReal.ofReal_sum_of_nonneg] + · apply Finset.sum_congr rfl + intro j _hj + rw [← ENNReal.ofReal_mul (by unfold envelope; positivity)] + congr 1 + ring + · intro j _hj + unfold envelope + positivity + _ ≤ _ := by + apply ENNReal.ofReal_le_ofReal + have he : ∀ j : ℕ,point m j = (j:ℝ)*width m := by intro j; unfold point width; ring + simp only [he] + have h := envelope_mesh_sum hc hh hm1 K (⌈S*(m:ℝ)⌉₊+1) + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left h hC + +end NumberTheoryLean.PrimeExponentialTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrimeFibreBrunBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrimeFibreBrunBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7def3eee9d0e9b11598b37e1efb19468ff942b7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrimeFibreBrunBound.lean @@ -0,0 +1,113 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.RealProgressionCoordinates +import OAI.NumberTheory.Jacobsthal.Primes.PrimeFibreInterval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosPrimeInputs.BrunTitchmarshUpper + +open _root_.Finset AffinePrimeSieve ProgressionPrimeUpper RealProgressionCoordinates + +theorem finite_prime_set_upper : ∃ C B : ℝ, 0 < C ∧ 1 < B ∧ + ∀ (x H : ℝ) (q : ℕ) (r : ℤ) (P : Finset ℕ), 0 < q → B ≤ H/q → + (∀ p ∈ P, p.Prime ∧ x < (p:ℝ) ∧ (p:ℝ) ≤ x+H ∧ Int.ModEq (q:ℤ) (p:ℤ) r) → + (P.card:ℝ) ≤ C*H/((q.totient:ℝ)*Real.log (H/q)) := by + obtain ⟨C,B,hC,hB,hupper⟩ := progression_prime_upper + refine ⟨C,B,hC,hB,?_⟩ + intro x H q r P hq hBnd hP + have hqR : (0:ℝ) < q := by exact_mod_cast hq + have hJ : 1 < H/q := hB.trans_le hBnd + have hH : 0 < H := by + have h := (lt_div_iff₀ hqR).mp (lt_trans zero_lt_one hJ) + simpa only [zero_mul] using h + obtain ⟨N,a,index,hcount,hcoord⟩ := exists_coordinates x H q r hq hH.le + let f : ℕ → ℕ := fun p => index (p:ℤ) + have hdata : ∀ p ∈ P, f p < N ∧ value a q (f p) = (p:ℤ) := by + intro p hp + obtain ⟨_,hlo,hhi,hmod⟩ := hP p hp + exact hcoord (p:ℤ) (by exact_mod_cast hlo) (by exact_mod_cast hhi) hmod + have hinj : Set.InjOn f P := by + intro p hp t ht heq + have hz : (p:ℤ)=(t:ℤ) := (hdata p hp).2.symm.trans + ((congrArg (value a q) heq).trans (hdata t ht).2) + exact_mod_cast hz + have hsub : P.image f ⊆ primeIndices N a q := by + intro i hi + obtain ⟨p,hp,rfl⟩ := mem_image.mp hi + apply mem_filter.mpr + refine ⟨mem_range.mpr (hdata p hp).1,?_⟩ + rw [(hdata p hp).2] + simpa only [Int.natAbs_natCast] using And.intro (hP p hp).1 (Int.natCast_nonneg p) + have hc : P.card ≤ (primeIndices N a q).card := by + calc + _ = (P.image f).card := (card_image_iff.mpr hinj).symm + _ ≤ _ := card_le_card hsub + have htR : (0:ℝ) < q.totient := by exact_mod_cast Nat.totient_pos.mpr hq + have hlog := Real.log_pos hJ + calc + (P.card:ℝ) ≤ ((primeIndices N a q).card:ℝ) := by exact_mod_cast hc + _ ≤ C*(H/q)*((q:ℝ)/q.totient)/Real.log (H/q) := hupper N a q (H/q) hBnd hq hcount + _ = _ := by field_simp + +noncomputable def intervalPrimes (x H : ℝ) (q : ℕ) (r : ℤ) : Finset ℕ := + (range (⌊max (x+H) 0⌋₊+1)).filter (fun p => + p.Prime ∧ x < (p:ℝ) ∧ (p:ℝ) ≤ x+H ∧ Int.ModEq (q:ℤ) (p:ℤ) r) + +theorem mem_intervalPrimes (x H : ℝ) (q : ℕ) (r : ℤ) (p : ℕ) : + p ∈ intervalPrimes x H q r ↔ + p.Prime ∧ x < (p:ℝ) ∧ (p:ℝ) ≤ x+H ∧ Int.ModEq (q:ℤ) (p:ℤ) r := by + constructor + · intro h + exact (mem_filter.mp h).2 + · intro h + apply mem_filter.mpr + refine ⟨mem_range.mpr (Nat.lt_succ_of_le ?_),h⟩ + exact (Nat.le_floor_iff (le_max_right _ _)).mpr (h.2.2.1.trans (le_max_left _ _)) + +theorem brun_titchmarsh_upper : ∃ C B : ℝ, 0 < C ∧ 1 < B ∧ + ∀ (x H : ℝ) (q : ℕ) (r : ℤ), 0 < q → B ≤ H/q → + ((intervalPrimes x H q r).card:ℝ) ≤ C*H/((q.totient:ℝ)*Real.log (H/q)) := by + obtain ⟨C,B,hC,hB,h⟩ := finite_prime_set_upper + exact ⟨C,B,hC,hB,fun x H q r hq hJ => h x H q r _ hq hJ + (fun p hp => (mem_intervalPrimes x H q r p).mp hp)⟩ + +end ErdosPrimeInputs.BrunTitchmarshUpper + +end + +section + +namespace ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable + +noncomputable def residueFibre (P : Finset ℕ) (H C0 : ℝ) (m : ℤ) (M : ℕ) (b : ℤ) : Finset ℕ := + (geometricFibre P H C0 m).filter (fun p => Int.ModEq (M : ℤ) (p : ℤ) b) + +theorem residue_fibre_prime_bound : ∃ C B : ℝ,0 < C ∧ 1 < B ∧ + ∀ (P : Finset ℕ) (R xi H C0 : ℝ) (m : ℤ) (M : ℕ) (b : ℤ), + 0 < R → 0 < xi → xi ≤ 1 → 0 < H → 0 < M → + B ≤ 5*primeWidth R xi H C0/(M : ℝ) → + (∀ p ∈ P,p.Prime ∧ R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) → + ((residueFibre P H C0 m M b).card : ℝ) ≤ + C*(5*primeWidth R xi H C0)/((M.totient : ℝ)*Real.log (5*primeWidth R xi H C0/(M : ℝ))) := by + obtain ⟨C,B,hC,hB,hupper⟩ := ErdosPrimeInputs.BrunTitchmarshUpper.finite_prime_set_upper + refine ⟨C,B,hC,hB,?_⟩ + intro P R xi H C0 m M b hR hxi hxi1 hH hM hRatio hP + obtain ⟨x,hx⟩ := geometric_fibre_interval P R xi H C0 m hR hxi hxi1 hH (fun p hp => (hP p hp).2) + apply hupper x (5*primeWidth R xi H C0) M b (residueFibre P H C0 m M b) hM hRatio + intro p hp + obtain ⟨hgeo,hmod⟩ := Finset.mem_filter.mp hp + have hpP := (Finset.mem_filter.mp hgeo).1 + exact ⟨(hP p hpP).1,(hx p hgeo).1,(hx p hgeo).2,hmod⟩ + +end ErdosVarianceSmallModel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrincipalEulerCorrection.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrincipalEulerCorrection.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed8596484ec2fd765e00a21376c298a2d250b208 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/PrincipalEulerCorrection.lean @@ -0,0 +1,150 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.NonquadraticZeroFree + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +noncomputable def localEulerFactor (alpha : ℂ) (p : ℕ) (s : ℂ) : ℂ := + 1-alpha*(p:ℂ)^(-s) + +lemma prime_cpow_neg_norm_le_half {p : ℕ} (hp : p.Prime) {s : ℂ} (hs : 1 ≤ s.re) : + ‖(p:ℂ)^(-s)‖ ≤ 1/2 := by + rw [Complex.norm_natCast_cpow_of_pos hp.pos, Complex.neg_re] + have hpR : (2:ℝ) ≤ p := by exact_mod_cast hp.two_le + calc + _ ≤ (p:ℝ)^(-1:ℝ) := Real.rpow_le_rpow_of_exponent_le (by linarith) (by linarith) + _ = 1/(p:ℝ) := by rw [Real.rpow_neg_one, one_div] + _ ≤ 1/2 := one_div_le_one_div_of_le (by norm_num) hpR + +lemma localEulerFactor_ne_zero {p : ℕ} (hp : p.Prime) {alpha s : ℂ} + (ha : ‖alpha‖ ≤ 1) (hs : 1 ≤ s.re) : localEulerFactor alpha p s ≠ 0 := by + have hu : ‖alpha*(p:ℂ)^(-s)‖ ≤ 1/2 := by + rw [norm_mul] + exact (mul_le_mul_of_nonneg_right ha (norm_nonneg _)).trans (by simpa using prime_cpow_neg_norm_le_half hp hs) + intro hz + have he : alpha*(p:ℂ)^(-s) = 1 := (sub_eq_zero.mp hz).symm + rw [he, norm_one] at hu + norm_num at hu + +lemma localEulerFactor_differentiable {p : ℕ} (hp : p.Prime) (alpha : ℂ) : + Differentiable ℂ (localEulerFactor alpha p) := by + unfold localEulerFactor + fun_prop (disch := exact Or.inl (by exact_mod_cast hp.ne_zero)) + +lemma localEulerFactor_deriv {p : ℕ} (hp : p.Prime) (alpha s : ℂ) : + deriv (localEulerFactor alpha p) s = + (Real.log (p:ℝ):ℂ) * (alpha*(p:ℂ)^(-s)) := by + have hn : (p:ℂ) ≠ 0 := by exact_mod_cast hp.ne_zero + have hd := ((((hasDerivAt_id s).neg).const_cpow (c := (p:ℂ)) (Or.inl hn)).const_mul alpha).const_sub 1 + simp only [Pi.neg_apply, id_eq] at hd + convert! hd.deriv using 1 + rw [← Complex.natCast_log] + ring + +lemma norm_logDeriv_localEulerFactor {p : ℕ} (hp : p.Prime) {alpha s : ℂ} + (ha : ‖alpha‖ ≤ 1) (hs : 1 ≤ s.re) : + ‖logDeriv (localEulerFactor alpha p) s‖ ≤ Real.log (p:ℝ) := by + have hpR : (2:ℝ) ≤ p := by exact_mod_cast hp.two_le + have hlog : 0 ≤ Real.log (p:ℝ) := Real.log_nonneg (by linarith) + have hu : ‖alpha*(p:ℂ)^(-s)‖ ≤ 1/2 := by + rw [norm_mul] + exact (mul_le_mul_of_nonneg_right ha (norm_nonneg _)).trans (by simpa using prime_cpow_neg_norm_le_half hp hs) + have hden : ‖alpha*(p:ℂ)^(-s)‖ ≤ ‖localEulerFactor alpha p s‖ := by + have h := norm_sub_norm_le (1:ℂ) (alpha*(p:ℂ)^(-s)) + rw [norm_one] at h + change 1-‖alpha*(p:ℂ)^(-s)‖ ≤ ‖localEulerFactor alpha p s‖ at h + linarith + rw [logDeriv_apply, localEulerFactor_deriv hp, norm_div, norm_mul, + Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg hlog] + exact (div_le_iff₀ (norm_pos_iff.mpr (localEulerFactor_ne_zero hp ha hs))).mpr + (mul_le_mul_of_nonneg_left hden hlog) + +lemma sum_log_primeFactors_le_log (q : ℕ) [NeZero q] : + ∑ p ∈ q.primeFactors, Real.log (p:ℝ) ≤ Real.log (q:ℝ) := by + have hpos : 0 < ∏ p ∈ q.primeFactors, (p:ℝ) := + Finset.prod_pos (fun p hp => by exact_mod_cast (Nat.prime_of_mem_primeFactors hp).pos) + rw [← Real.log_prod (fun p hp => by exact_mod_cast (Nat.prime_of_mem_primeFactors hp).ne_zero)] + apply Real.log_le_log hpos + have h : (((∏ p ∈ q.primeFactors, p : ℕ):ℕ):ℝ) ≤ (q:ℝ) := by + exact_mod_cast Nat.le_of_dvd (NeZero.pos q) (Nat.prod_primeFactors_dvd q) + simpa only [Nat.cast_prod] using! h + +theorem norm_euler_log_correction_le_log (q : ℕ) [NeZero q] (S : Finset ℕ) + (hS : S ⊆ q.primeFactors) (alpha : ℕ → ℂ) (ha : ∀ p ∈ S, ‖alpha p‖ ≤ 1) + {s : ℂ} (hs : 1 ≤ s.re) : + ‖∑ p ∈ S, logDeriv (localEulerFactor (alpha p) p) s‖ ≤ Real.log (q:ℝ) := by + apply (norm_sum_le _ _).trans + apply (Finset.sum_le_sum (fun p hp => norm_logDeriv_localEulerFactor + (Nat.prime_of_mem_primeFactors (hS hp)) (ha p hp) hs)).trans + apply (Finset.sum_le_sum_of_subset_of_nonneg hS (fun p hp _ => + Real.log_nonneg (by exact_mod_cast (Nat.prime_of_mem_primeFactors hp).one_le))).trans + exact sum_log_primeFactors_le_log q + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology BigOperators + +noncomputable def modulusEulerProduct (q : ℕ) (s : ℂ) : ℂ := + ∏ p ∈ q.primeFactors, localEulerFactor 1 p s + +lemma principal_log_derivative_eq (q : ℕ) [NeZero q] {s : ℂ} (hs : 1 < s.re) : + logDeriv (DirichletCharacter.LFunctionTrivChar q) s = logDeriv riemannZeta s + + ∑ p ∈ q.primeFactors, logDeriv (localEulerFactor 1 p) s := by + have hs1 : s ≠ 1 := by intro h; simp [h] at hs + have he : DirichletCharacter.LFunctionTrivChar q =ᶠ[𝓝 s] + (fun z => modulusEulerProduct q z * riemannZeta z) := by + filter_upwards [isOpen_ne.mem_nhds hs1] with z hz + simpa only [modulusEulerProduct, localEulerFactor, one_mul] using + (DirichletCharacter.LFunctionTrivChar_eq_mul_riemannZeta (N := q) hz) + have hf (p:ℕ) (hp : p ∈ q.primeFactors) : localEulerFactor 1 p s ≠ 0 := + localEulerFactor_ne_zero (Nat.prime_of_mem_primeFactors hp) (by simp) hs.le + have hd (p:ℕ) (hp : p ∈ q.primeFactors) : DifferentiableAt ℂ (localEulerFactor 1 p) s := + (localEulerFactor_differentiable (Nat.prime_of_mem_primeFactors hp) 1).differentiableAt + have hprod : modulusEulerProduct q s ≠ 0 := Finset.prod_ne_zero_iff.mpr hf + have hdiff : DifferentiableAt ℂ (modulusEulerProduct q) s := DifferentiableAt.fun_finsetProd hd + have hld : logDeriv (DirichletCharacter.LFunctionTrivChar q) s = + logDeriv (fun z => modulusEulerProduct q z * riemannZeta z) s := by + simp only [logDeriv_apply, he.deriv_eq, he.eq_of_nhds] + rw [hld, logDeriv_fun_mul s hprod (riemannZeta_ne_zero_of_one_le_re hs.le) hdiff + (differentiableAt_riemannZeta hs1)] + have hsum : logDeriv (modulusEulerProduct q) s = + ∑ p ∈ q.primeFactors, logDeriv (localEulerFactor 1 p) s := logDeriv_fun_prod hf hd + rw [hsum, add_comm] + +theorem norm_principal_log_derivative_difference (q : ℕ) [NeZero q] + {s : ℂ} (hs : 1 < s.re) : + ‖logDeriv (DirichletCharacter.LFunctionTrivChar q) s - logDeriv riemannZeta s‖ ≤ + Real.log (q:ℝ) := by + rw [principal_log_derivative_eq q hs, add_sub_cancel_left] + exact norm_euler_log_correction_le_log q q.primeFactors (Finset.Subset.refl _) + (fun _ => 1) (by intro p hp; simp) hs.le + +theorem principal_neg_real_log_derivative_le (q : ℕ) [NeZero q] + {s : ℂ} (hs : 1 < s.re) : + (-logDeriv (DirichletCharacter.LFunctionTrivChar q) s).re ≤ + (-logDeriv riemannZeta s).re + Real.log (q:ℝ) := by + have h := (Complex.re_le_norm (-(logDeriv (DirichletCharacter.LFunctionTrivChar q) s - + logDeriv riemannZeta s))).trans + (by simpa only [norm_neg] using norm_principal_log_derivative_difference q hs) + simp only [Complex.neg_re, Complex.sub_re] at h ⊢ + linarith + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/RealCoprimeResidueCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/RealCoprimeResidueCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..3bd24851c792c17414707023d96cb49d03c2f4d6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/RealCoprimeResidueCount.lean @@ -0,0 +1,589 @@ +import Mathlib +import Mathlib.Data.Int.CardIntervalMod +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.PositionDensities +import OAI.NumberTheory.Jacobsthal.Sieve.MobiusCoprimeExpansion + +namespace OAI + +namespace Erdos970 + + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq + +noncomputable def crtResidues {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) : Finset (ZMod (∏ i,m i)) := + (Fintype.piFinset E).map (ZMod.prodEquivPi m hcop).symm.toEquiv.toEmbedding + +theorem mem_crtResidues {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (r : ZMod (∏ i,m i)) : + r ∈ crtResidues m hcop E ↔ ∀ i,(ZMod.prodEquivPi m hcop r) i ∈ E i := by + constructor + · intro hr + obtain ⟨f,hf,hfr⟩ := Finset.mem_map.mp hr + have he : ZMod.prodEquivPi m hcop r = f := by + rw [← hfr] + exact (ZMod.prodEquivPi m hcop).apply_symm_apply f + rw [he] + exact Fintype.mem_piFinset.mp hf + · intro hr + exact Finset.mem_map.mpr ⟨ZMod.prodEquivPi m hcop r,Fintype.mem_piFinset.mpr hr, + (ZMod.prodEquivPi m hcop).symm_apply_apply r⟩ + +theorem crtResidues_card {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) (E : ∀ i,Finset (ZMod (m i))) : + (crtResidues m hcop E).card = ∏ i,(E i).card := by + rw [crtResidues,Finset.card_map,Fintype.card_piFinset] + +theorem intCast_mem_crtResidues {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (s : ℤ) : + (s : ZMod (∏ i,m i)) ∈ crtResidues m hcop E ↔ ∀ i,(s : ZMod (m i)) ∈ E i := by + rw [mem_crtResidues] + have he (i : ι) : ZMod.prodEquivPi m hcop (s : ZMod (∏ j,m j)) i = (s : ZMod (m i)) := by + rw [ZMod.prodEquivPi_apply] + exact map_intCast (ZMod.castHom (Finset.dvd_prod_of_mem m (Finset.mem_univ i)) (ZMod (m i))) s + simp only [he] + +end ErdosInverseCRT + + + +namespace Erdos66Dependency.SingleResidueCount + +open Finset + +noncomputable def residueClass (a b Q r : ℤ) : Finset ℤ := + (Ico a b).filter (fun x => Int.ModEq Q x r) + +theorem count_exact (a b Q r : ℤ) (hQ : 0 < Q) : + ((residueClass a b Q r).card : ℤ) = + max (⌈((b : ℚ) - r) / Q⌉ - ⌈((a : ℚ) - r) / Q⌉) 0 := + Int.Ico_filter_modEq_card a b hQ r + +lemma count_error_rat (a b Q r : ℤ) (hQ : 0 < Q) (hab : a ≤ b) : + |((residueClass a b Q r).card : ℚ) - ((b : ℚ) - a) / Q| ≤ 1 := by + have hQQ : (0:ℚ) < Q := by exact_mod_cast hQ + have hx : ((a : ℚ) - r) / Q ≤ ((b : ℚ) - r) / Q := + div_le_div_of_nonneg_right (by exact_mod_cast sub_le_sub_right hab r) hQQ.le + have hceil := Int.ceil_mono hx + have hcount := count_exact a b Q r hQ + rw [max_eq_left (sub_nonneg.mpr hceil)] at hcount + have hcast := congrArg (fun z : ℤ => (z : ℚ)) hcount + push_cast at hcast + rw [hcast] + have ha := Int.le_ceil (((a : ℚ) - r) / Q) + have ha' := Int.ceil_lt_add_one (((a : ℚ) - r) / Q) + have hb := Int.le_ceil (((b : ℚ) - r) / Q) + have hb' := Int.ceil_lt_add_one (((b : ℚ) - r) / Q) + have heq : ((b : ℚ) - a) / Q = ((b : ℚ) - r) / Q - ((a : ℚ) - r) / Q := by ring + rw [heq,abs_le] + constructor <;> linarith + +theorem count_error_length (a b Q r : ℤ) (hQ : 0 < Q) (hab : a ≤ b) : + |((residueClass a b Q r).card : ℝ) - ((b : ℝ) - a) / Q| ≤ 1 := by + have h := count_error_rat a b Q r hQ hab + have hh := (Rat.cast_le (K := ℝ)).mpr h + push_cast at hh + exact hh + +theorem count_error (a b Q r : ℤ) (hQ : 0 < Q) : + |((residueClass a b Q r).card : ℝ) - ((Ico a b).card : ℝ) / Q| ≤ 1 := by + by_cases hab : a ≤ b + · have hc : ((Ico a b).card : ℤ) = b-a := by + rw [Int.card_Ico,Int.toNat_of_nonneg (sub_nonneg.mpr hab)] + have hcast := congrArg (fun z : ℤ => (z : ℝ)) hc + push_cast at hcast + rw [hcast] + exact count_error_length a b Q r hQ hab + · have he : Ico a b = (∅ : Finset ℤ) := Ico_eq_empty_of_le (le_of_not_ge hab) + simp [residueClass,he] + +end Erdos66Dependency.SingleResidueCount + + + +namespace ErdosVarianceMoments +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem crt_coordinate_val {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + [NeZero (∏ i,m i)] (r : ZMod (∏ i,m i)) (i : ι) : + (ZMod.prodEquivPi m hcop r) i = (r.val : ZMod (m i)) := by + calc + (ZMod.prodEquivPi m hcop r) i = + (ZMod.prodEquivPi m hcop (r.val : ZMod (∏ j,m j))) i := by + rw [ZMod.natCast_zmod_val] + _ = (r.val : ZMod (m i)) := by + rw [ZMod.prodEquivPi_apply] + exact map_natCast (ZMod.castHom (Finset.dvd_prod_of_mem m (Finset.mem_univ i)) (ZMod (m i))) r.val + +theorem literal_residue_choices_card {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + [NeZero (∏ i,m i)] (E : ∀ i,Finset (ZMod (m i))) : + (Finset.univ.filter (fun r : ZMod (∏ i,m i) => ∀ i,(r.val : ZMod (m i)) ∈ E i)).card = + ∏ i,(E i).card := by + have he : Finset.univ.filter (fun r : ZMod (∏ i,m i) => ∀ i,(r.val : ZMod (m i)) ∈ E i) = + ErdosInverseCRT.crtResidues m hcop E := by + ext r + simp only [Finset.mem_filter,Finset.mem_univ,true_and,ErdosInverseCRT.mem_crtResidues, + crt_coordinate_val] + rw [he,ErdosInverseCRT.crtResidues_card] + +theorem canonical_filter_card (N : ℕ) [NeZero N] (f : ℕ → Prop) [DecidablePred f] : + (Finset.univ.filter (fun r : ZMod N => f r.val)).card = + ((Finset.range N).filter f).card := by + apply Finset.card_bij (fun r _ => r.val) + · intro r hr + exact Finset.mem_filter.mpr ⟨Finset.mem_range.mpr r.val_lt,(Finset.mem_filter.mp hr).2⟩ + · intro r _hr s _hs he + exact ZMod.val_injective N he + · intro n hn + have hlt := Finset.mem_range.mp (Finset.mem_filter.mp hn).1 + refine ⟨(n : ZMod N),?_,?_⟩ + · simp only [Finset.mem_filter,Finset.mem_univ,true_and,ZMod.val_natCast,Nat.mod_eq_of_lt hlt] + exact (Finset.mem_filter.mp hn).2 + · simp only [ZMod.val_natCast,Nat.mod_eq_of_lt hlt] + +noncomputable def allowedClasses (S : Finset ℕ) (p : ℕ) [NeZero p] + (u : (ZMod p)ˣ) (c : ZMod p) : Finset (ZMod p) := + Finset.univ \ forbiddenClasses S p u c + +theorem mem_allowedClasses (S : Finset ℕ) (p : ℕ) [NeZero p] + (u : (ZMod p)ˣ) (c x : ZMod p) : + x ∈ allowedClasses S p u c ↔ ∀ j ∈ S,x+(u : ZMod p)*(j : ZMod p) ≠ c := by + simp only [allowedClasses,Finset.mem_sdiff,Finset.mem_univ,true_and,mem_forbiddenClasses, + not_exists,not_and] + +theorem allowedClasses_card (S : Finset ℕ) (p : ℕ) [NeZero p] + (u : (ZMod p)ˣ) (c : ZMod p) : + (allowedClasses S p u c).card = p-(positionResidues S p).card := by + rw [allowedClasses,Finset.card_sdiff,Finset.inter_univ,Finset.card_univ,ZMod.card, + forbiddenClasses_card] + +end ErdosVarianceMoments + + + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq + +noncomputable def integerCRTResidues {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) (E : ∀ i,Finset (ZMod (m i))) : Finset ℤ := + (crtResidues m hcop E).image (fun r => (r.val : ℤ)) + +theorem integerCRTResidues_card {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (hN : 0 < ∏ i,m i) : + (integerCRTResidues m hcop E).card = ∏ i,(E i).card := by + let : NeZero (∏ i,m i) := ⟨hN.ne'⟩ + have hinj : Function.Injective (fun r : ZMod (∏ i,m i) => (r.val : ℤ)) := by + intro r s he + exact ZMod.val_injective _ (Int.ofNat_inj.mp he) + rw [integerCRTResidues,Finset.card_image_of_injective _ hinj,crtResidues_card] + +theorem integerCRTResidues_subset {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (hN : 0 < ∏ i,m i) : + integerCRTResidues m hcop E ⊆ Finset.Ico 0 (∏ i,m i : ℕ) := by + let : NeZero (∏ i,m i) := ⟨hN.ne'⟩ + intro s hs + obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp hs + exact Finset.mem_Ico.mpr ⟨Int.natCast_nonneg _,by exact_mod_cast ZMod.val_lt r⟩ + +theorem emod_mem_integerCRTResidues {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (hN : 0 < ∏ i,m i) (s : ℤ) : + s % (∏ i,m i : ℕ) ∈ integerCRTResidues m hcop E ↔ ∀ i,(s : ZMod (m i)) ∈ E i := by + let : NeZero (∏ i,m i) := ⟨hN.ne'⟩ + rw [← intCast_mem_crtResidues m hcop E s,← ZMod.val_intCast s] + constructor + · intro hs + obtain ⟨r,hr,he⟩ := Finset.mem_image.mp hs + have heq : r = (s : ZMod (∏ i,m i)) := ZMod.val_injective _ (Int.ofNat_inj.mp he) + rwa [← heq] + · intro hs + exact Finset.mem_image.mpr ⟨(s : ZMod (∏ i,m i)),hs,rfl⟩ + +theorem product_card_le_moduli {ι : Type*} [Fintype ι] (m : ι → ℕ) + (E : ∀ i,Finset (ZMod (m i))) (hm : ∀ i,0 < m i) : + (∏ i,(E i).card) ≤ ∏ i,m i := by + apply Finset.prod_le_prod₀ (fun _ _ => Nat.zero_le _) + intro i hi + let : NeZero (m i) := ⟨(hm i).ne'⟩ + simpa only [ZMod.card] using Finset.card_le_univ (E i) + +end ErdosInverseCRT + + + +namespace Erdos66Dependency.ResidueLifts + +open Finset SingleResidueCount + +noncomputable def liftsOn (J : Finset ℤ) (Q : ℤ) (A : Finset ℤ) : Finset ℤ := + J.filter (fun x => x % Q ∈ A) + +theorem lifts_eq_union (a b Q : ℤ) (A : Finset ℤ) (hA : A ⊆ Ico 0 Q) : + liftsOn (Ico a b) Q A = A.biUnion (residueClass a b Q) := by + classical + ext x + simp only [liftsOn,mem_filter,mem_biUnion,residueClass] + constructor + · rintro ⟨hx,hA⟩ + exact ⟨x%Q,hA,hx,by unfold Int.ModEq; rw [Int.emod_emod]⟩ + · rintro ⟨r,hr,hx,hmod⟩ + have hrange := mem_Ico.mp (hA hr) + have he : x%Q=r := by simpa only [Int.ModEq,Int.emod_eq_of_lt hrange.1 hrange.2] using hmod + exact ⟨hx,he ▸ hr⟩ + +theorem classes_disjoint (a b Q : ℤ) (A : Finset ℤ) (hA : A ⊆ Ico 0 Q) : + (A : Set ℤ).PairwiseDisjoint (residueClass a b Q) := by + intro r hr s hs hne + apply Finset.disjoint_left.mpr + intro x hxr hxs + have hrange := mem_Ico.mp (hA hr) + have hsrange := mem_Ico.mp (hA hs) + have hmodr := (mem_filter.mp hxr).2 + have hmods := (mem_filter.mp hxs).2 + have heqR : x%Q=r := by simpa only [Int.ModEq,Int.emod_eq_of_lt hrange.1 hrange.2] using hmodr + have heqS : x%Q=s := by simpa only [Int.ModEq,Int.emod_eq_of_lt hsrange.1 hsrange.2] using hmods + exact hne (heqR.symm.trans heqS) + +theorem count_eq_sum (a b Q : ℤ) (A : Finset ℤ) (hA : A ⊆ Ico 0 Q) : + (liftsOn (Ico a b) Q A).card = ∑ r ∈ A, (residueClass a b Q r).card := by + rw [lifts_eq_union a b Q A hA,card_biUnion (classes_disjoint a b Q A hA)] + +theorem count_error (a b Q : ℤ) (A : Finset ℤ) (hQ : 0 < Q) (hA : A ⊆ Ico 0 Q) : + |((liftsOn (Ico a b) Q A).card : ℝ) - ((Ico a b).card : ℝ) * A.card / Q| ≤ A.card := by + rw [count_eq_sum a b Q A hA,Nat.cast_sum] + have heq : (∑ r ∈ A, ((residueClass a b Q r).card : ℝ)) - ((Ico a b).card : ℝ)*A.card/Q = + ∑ r ∈ A, (((residueClass a b Q r).card : ℝ) - ((Ico a b).card : ℝ)/Q) := by + rw [sum_sub_distrib] + simp only [sum_const,nsmul_eq_mul] + ring + rw [heq] + calc + _ ≤ ∑ r ∈ A, |((residueClass a b Q r).card : ℝ) - ((Ico a b).card : ℝ)/Q| := abs_sum_le_sum_abs _ _ + _ ≤ ∑ _r ∈ A, (1:ℝ) := sum_le_sum (fun r _ => SingleResidueCount.count_error a b Q r hQ) + _ = (A.card:ℝ) := by simp + +lemma card_Ico_real {a b : ℤ} (hab : a ≤ b) : ((Ico a b).card : ℝ) = (b:ℝ)-a := by + have h : ((Ico a b).card : ℤ) = b-a := by rw [Int.card_Ico,Int.toNat_of_nonneg (sub_nonneg.mpr hab)] + have hh := congrArg (fun z : ℤ => (z:ℝ)) h + push_cast at hh + exact hh + +theorem count_error_length (a b Q : ℤ) (A : Finset ℤ) (hQ : 0 < Q) + (hA : A ⊆ Ico 0 Q) (hab : a ≤ b) : + |((liftsOn (Ico a b) Q A).card : ℝ) - ((b:ℝ)-a)*A.card/Q| ≤ A.card := by + simpa only [card_Ico_real hab] using count_error a b Q A hQ hA + +theorem count_error_Icc (a b Q : ℤ) (A : Finset ℤ) (hQ : 0 < Q) (hA : A ⊆ Ico 0 Q) : + |((liftsOn (Icc a b) Q A).card : ℝ) - ((Icc a b).card : ℝ)*A.card/Q| ≤ A.card := by + have he : Icc a b = Ico a (b+1) := by ext x; simp only [mem_Icc,mem_Ico]; omega + rw [he] + exact count_error a (b+1) Q A hQ hA + +theorem count_error_Ioc (a b Q : ℤ) (A : Finset ℤ) (hQ : 0 < Q) (hA : A ⊆ Ico 0 Q) : + |((liftsOn (Ioc a b) Q A).card : ℝ) - ((Ioc a b).card : ℝ)*A.card/Q| ≤ A.card := by + have he : Ioc a b = Ico (a+1) (b+1) := by ext x; simp only [mem_Ioc,mem_Ico]; omega + rw [he] + exact count_error (a+1) (b+1) Q A hQ hA + +theorem count_error_Ioo (a b Q : ℤ) (A : Finset ℤ) (hQ : 0 < Q) (hA : A ⊆ Ico 0 Q) : + |((liftsOn (Ioo a b) Q A).card : ℝ) - ((Ioo a b).card : ℝ)*A.card/Q| ≤ A.card := by + have he : Ioo a b = Ico (a+1) b := by ext x; simp only [mem_Ioo,mem_Ico]; omega + rw [he] + exact count_error (a+1) b Q A hQ hA + +end Erdos66Dependency.ResidueLifts + + + +namespace ErdosInverseCRT +open Erdos66Dependency +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def crtSlopes {ι : Type*} [Fintype ι] (a b : ℤ) (m : ι → ℕ) + (E : ∀ i,Finset (ZMod (m i))) : Finset ℤ := + (Finset.Ico a b).filter (fun s => ∀ i,(s : ZMod (m i)) ∈ E i) + +theorem crtSlopes_eq_lifts {ι : Type*} [Fintype ι] (a b : ℤ) (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (hN : 0 < ∏ i,m i) : + crtSlopes a b m E = ResidueLifts.liftsOn (Finset.Ico a b) (∏ i,m i : ℕ) (integerCRTResidues m hcop E) := by + ext s + simp only [crtSlopes,ResidueLifts.liftsOn,Finset.mem_filter,emod_mem_integerCRTResidues m hcop E hN s] + +theorem crt_interval_count_upper {ι : Type*} [Fintype ι] (a b : ℤ) (hab : a ≤ b) (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (hN : 0 < ∏ i,m i) : + ((crtSlopes a b m E).card : ℝ) ≤ + ((b : ℝ)-(a : ℝ))*((∏ i,(E i).card : ℕ) : ℝ)/(∏ i,m i : ℕ)+((∏ i,(E i).card : ℕ) : ℝ) := by + have hQ : (0 : ℤ) < (∏ i,m i : ℕ) := by exact_mod_cast hN + have hh := ResidueLifts.count_error_length a b (∏ i,m i : ℕ) (integerCRTResidues m hcop E) + hQ (integerCRTResidues_subset m hcop E hN) hab + rw [← crtSlopes_eq_lifts a b m hcop E hN,integerCRTResidues_card m hcop E hN] at hh + have hup := (abs_le.mp hh).2 + push_cast at hup ⊢ + linarith + +theorem crt_initial_count_upper {ι : Type*} [Fintype ι] (p : ℕ) (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i,Finset (ZMod (m i))) (hN : 0 < ∏ i,m i) : + ((crtSlopes 0 p m E).card : ℝ) ≤ + (p : ℝ)*((∏ i,(E i).card : ℕ) : ℝ)/(∏ i,m i : ℕ)+((∏ i,(E i).card : ℕ) : ℝ) := by + simpa only [Int.cast_natCast,Int.cast_zero,sub_zero] using + crt_interval_count_upper 0 p (Int.natCast_nonneg p) m hcop E hN + +end ErdosInverseCRT + + + +namespace ErdosCoprimeResidueInterval +attribute [local instance] Classical.propDecidable + +abbrev binaryModuli (d l : ℕ) (i : Bool) : ℕ := match i with + | false => d + | true => l + +theorem binary_coprime (d l : ℕ) (h : d.Coprime l) : + Pairwise (fun i j => Nat.Coprime (binaryModuli d l i) (binaryModuli d l j)) := by + intro i j hij + cases i <;> cases j + · exact False.elim (hij rfl) + · exact h + · exact h.symm + · exact False.elim (hij rfl) + +noncomputable def binaryClasses (d l : ℕ) (A : Finset (ZMod l)) (i : Bool) : + Finset (ZMod (binaryModuli d l i)) := match i with + | false => {0} + | true => A + +theorem binary_modulus_product (d l : ℕ) : (∏ i : Bool,binaryModuli d l i) = d*l := by + simp [binaryModuli,mul_comm] + +noncomputable def divisibleResidues (d l : ℕ) (h : d.Coprime l) (A : Finset (ZMod l)) : Finset ℤ := + ErdosInverseCRT.integerCRTResidues (binaryModuli d l) (binary_coprime d l h) (binaryClasses d l A) + +theorem divisibleResidues_card (d l : ℕ) (hd : 0 < d) (hl : 0 < l) + (h : d.Coprime l) (A : Finset (ZMod l)) : (divisibleResidues d l h A).card = A.card := by + have hN : 0 < ∏ i : Bool,binaryModuli d l i := by rw [binary_modulus_product]; positivity + unfold divisibleResidues + rw [ErdosInverseCRT.integerCRTResidues_card _ _ _ hN] + simp only [Fintype.prod_bool,binaryClasses,Finset.card_singleton,mul_one] + +theorem divisibleResidues_range (d l : ℕ) (hd : 0 < d) (hl : 0 < l) + (h : d.Coprime l) (A : Finset (ZMod l)) : + divisibleResidues d l h A ⊆ Finset.Ico 0 (d*l : ℕ) := by + have hN : 0 < ∏ i : Bool,binaryModuli d l i := by rw [binary_modulus_product]; positivity + simpa only [divisibleResidues,binary_modulus_product] using ErdosInverseCRT.integerCRTResidues_subset + (binaryModuli d l) (binary_coprime d l h) (binaryClasses d l A) hN + +theorem mem_divisibleResidues (d l : ℕ) (hd : 0 < d) (hl : 0 < l) + (h : d.Coprime l) (A : Finset (ZMod l)) (m : ℤ) : + m % (d*l : ℕ) ∈ divisibleResidues d l h A ↔ (d : ℤ) ∣ m ∧ (m : ZMod l) ∈ A := by + have hN : 0 < ∏ i : Bool,binaryModuli d l i := by rw [binary_modulus_product]; positivity + unfold divisibleResidues + rw [← binary_modulus_product d l,ErdosInverseCRT.emod_mem_integerCRTResidues _ _ _ hN] + simp only [Bool.forall_bool,binaryClasses,binaryModuli] + change ((m : ZMod d) ∈ ({0} : Finset (ZMod d)) ∧ (m : ZMod l) ∈ A) ↔ _ + rw [Finset.mem_singleton,ZMod.intCast_zmod_eq_zero_iff_dvd] + +theorem divisible_residue_count (d l : ℕ) (hd : 0 < d) (hl : 0 < l) + (h : d.Coprime l) (A : Finset (ZMod l)) (b c : ℤ) : + |(((Finset.Ico b c).filter (fun m : ℤ => (d : ℤ) ∣ m ∧ (m : ZMod l) ∈ A)).card : ℝ) - + ((Finset.Ico b c).card : ℝ)*(A.card : ℝ)/((d : ℝ)*l)| ≤ A.card := by + have he : (Finset.Ico b c).filter (fun m : ℤ => (d : ℤ) ∣ m ∧ (m : ZMod l) ∈ A) = + Erdos66Dependency.ResidueLifts.liftsOn (Finset.Ico b c) (d*l : ℕ) (divisibleResidues d l h A) := by + ext m + simp only [Erdos66Dependency.ResidueLifts.liftsOn,Finset.mem_filter, + mem_divisibleResidues d l hd hl h A] + rw [he] + have hh := Erdos66Dependency.ResidueLifts.count_error b c (d*l : ℕ) (divisibleResidues d l h A) + (by exact_mod_cast Nat.mul_pos hd hl) (divisibleResidues_range d l hd hl h A) + simpa only [divisibleResidues_card d l hd hl h A,Nat.cast_mul,Int.cast_mul,Int.cast_natCast] using hh + +end ErdosCoprimeResidueInterval + + + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq + +def affineEquiv {R : Type*} [CommRing R] (c : Rˣ) (b : R) : R ≃ R where + toFun s := (c : R)*s+b + invFun t := (↑(c⁻¹) : R)*(t-b) + left_inv s := by + change (↑(c⁻¹) : R)*((c : R)*s+b-b) = s + have he : (c : R)*s+b-b = (c : R)*s := by ring + rw [he,Units.inv_mul_cancel_left] + right_inv t := by + change (c : R)*((↑(c⁻¹) : R)*(t-b))+b = t + rw [Units.mul_inv_cancel_left] + ring + +noncomputable def affineResidues {R : Type*} [CommRing R] (c : Rˣ) (b : R) (E : Finset R) : Finset R := + E.map (affineEquiv c b).symm.toEmbedding + +theorem mem_affineResidues {R : Type*} [CommRing R] (c : Rˣ) (b : R) (E : Finset R) (s : R) : + s ∈ affineResidues c b E ↔ (c : R)*s+b ∈ E := by + constructor + · intro hs + obtain ⟨t,ht,he⟩ := Finset.mem_map.mp hs + have hh : (c : R)*s+b = t := by + rw [← he] + exact (affineEquiv c b).apply_symm_apply t + rwa [hh] + · intro hs + exact Finset.mem_map.mpr ⟨(c : R)*s+b,hs,(affineEquiv c b).symm_apply_apply s⟩ + +theorem affineResidues_card {R : Type*} [CommRing R] (c : Rˣ) (b : R) (E : Finset R) : + (affineResidues c b E).card = E.card := Finset.card_map _ + +theorem source_edge_class_affine {R : Type*} [CommRing R] (p q : Rˣ) (a b s : R) : + (a-b-(q : R)*s)*(↑((p*q)⁻¹) : R) = + (↑(-(p⁻¹)) : R)*s+(a-b)*(↑((p*q)⁻¹) : R) := by + have hc : (q : R)*(↑((p*q)⁻¹) : R) = (↑(p⁻¹) : R) := by + change (↑(q*(p*q)⁻¹) : R) = (↑(p⁻¹) : R) + congr 1 + simp [mul_inv_rev] + calc + _ = (a-b)*(↑((p*q)⁻¹) : R)-s*((q : R)*(↑((p*q)⁻¹) : R)) := by ring + _ = _ := by rw [hc];simp only [Units.val_neg];ring + +end ErdosInverseCRT + + + +namespace ErdosCoprimeResidueInterval +open scoped ArithmeticFunction.Moebius +attribute [local instance] Classical.propDecidable + +noncomputable def coprimeResidues (H l : ℕ) (A : Finset (ZMod l)) (b c : ℤ) : Finset ℤ := + (Finset.Ico b c).filter (fun m => H.Coprime m.natAbs ∧ (m : ZMod l) ∈ A) + +theorem coprime_residue_count (H l : ℕ) (hH : 0 < H) (hl : 0 < l) + (hcop : H.Coprime l) (A : Finset (ZMod l)) (b c : ℤ) : + |((coprimeResidues H l A b c).card : ℝ) - ((Finset.Ico b c).card : ℝ)* + ((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ))| ≤ + (H.divisors.card : ℝ)*(A.card : ℝ) := by + classical + let f (d : ℕ) := (((Finset.Ico b c).filter + (fun m : ℤ => (d : ℤ) ∣ m ∧ (m : ZMod l) ∈ A)).card : ℝ) + have hcount : ((coprimeResidues H l A b c).card : ℝ) = + ∑ d ∈ H.divisors, (μ d : ℝ)*f d := by + convert coprime_count_expansion H hH (Finset.Ico b c) (fun m : ℤ => (m : ZMod l) ∈ A) using 1 + · apply congrArg (fun S : Finset ℤ => (S.card : ℝ)) + ext m + simp only [coprimeResidues,Finset.mem_filter] + · apply Finset.sum_congr rfl + intro d _ + congr 1 + apply congrArg (fun S : Finset ℤ => (S.card : ℝ)) + ext m + simp only [Finset.mem_filter] + have he : ((coprimeResidues H l A b c).card : ℝ) - ((Finset.Ico b c).card : ℝ)* + ((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ)) = + ∑ d ∈ H.divisors, (μ d : ℝ)*(f d-((Finset.Ico b c).card : ℝ)*(A.card : ℝ)/((d : ℝ)*l)) := by + rw [hcount] + rw [← moebius_density H hH] + simp only [Finset.mul_sum,Finset.sum_mul,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro d _ + dsimp only [f] + ring + rw [he] + calc + _ ≤ ∑ d ∈ H.divisors, |(μ d : ℝ)*(f d-((Finset.Ico b c).card : ℝ)*(A.card : ℝ)/((d : ℝ)*l))| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _d ∈ H.divisors, (A.card : ℝ) := by + apply Finset.sum_le_sum + intro d hd + have hd0 := Nat.pos_of_mem_divisors hd + have hdl : d.Coprime l := Nat.Coprime.of_dvd_left (Nat.dvd_of_mem_divisors hd) hcop + have herr := divisible_residue_count d l hd0 hl hdl A b c + change |(μ d : ℝ)*(f d-((Finset.Ico b c).card : ℝ)*(A.card : ℝ)/((d : ℝ)*l))| ≤ (A.card : ℝ) + rw [abs_mul] + exact (mul_le_mul (moebius_abs_le_one d) herr (abs_nonneg _) (by norm_num)).trans_eq (one_mul _) + _ = _ := by simp + +theorem coprime_residue_count_length (H l : ℕ) (hH : 0 < H) (hl : 0 < l) + (hcop : H.Coprime l) (A : Finset (ZMod l)) (b c : ℤ) (hbc : b ≤ c) : + |((coprimeResidues H l A b c).card : ℝ) - ((c : ℝ)-b)* + ((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ))| ≤ + (H.divisors.card : ℝ)*(A.card : ℝ) := by + simpa only [Erdos66Dependency.ResidueLifts.card_Ico_real hbc] using + coprime_residue_count H l hH hl hcop A b c + +end ErdosCoprimeResidueInterval + + + +namespace ErdosCoprimeResidueInterval +attribute [local instance] Classical.propDecidable + +noncomputable def realCoprimeResidues (H l : ℕ) (A : Finset (ZMod l)) (b c : ℝ) : Finset ℤ := + coprimeResidues H l A ⌈b⌉ ⌈c⌉ + +theorem mem_realCoprimeResidues (H l : ℕ) (A : Finset (ZMod l)) (b c : ℝ) (m : ℤ) : + m ∈ realCoprimeResidues H l A b c ↔ + b ≤ (m : ℝ) ∧ (m : ℝ) < c ∧ H.Coprime m.natAbs ∧ (m : ZMod l) ∈ A := by + simp only [realCoprimeResidues,coprimeResidues,Finset.mem_filter,Finset.mem_Ico, + Int.ceil_le,Int.lt_ceil,and_assoc] + +theorem ceiling_interval_error (b c : ℝ) (hbc : b ≤ c) : + |((Finset.Ico ⌈b⌉ ⌈c⌉).card : ℝ)-(c-b)| ≤ 1 := by + rw [Erdos66Dependency.ResidueLifts.card_Ico_real (Int.ceil_mono hbc),abs_le] + constructor <;> linarith [Int.le_ceil b,Int.ceil_lt_add_one b,Int.le_ceil c,Int.ceil_lt_add_one c] + +theorem coprime_density_bounds (H l : ℕ) (hH : 0 < H) (hl : 0 < l) (A : Finset (ZMod l)) : + 0 ≤ ((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ)) ∧ + ((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ)) ≤ (A.card : ℝ) := by + have hV : (H.totient : ℝ)/(H : ℝ) ≤ 1 := + (div_le_one (show (0 : ℝ) < H by exact_mod_cast hH)).mpr (by exact_mod_cast Nat.totient_le H) + have hAl : (A.card : ℝ)/(l : ℝ) ≤ A.card := + div_le_self (Nat.cast_nonneg _) (by exact_mod_cast hl) + refine ⟨by positivity,?_⟩ + exact (mul_le_mul_of_nonneg_right hV (by positivity)).trans (by simpa only [one_mul] using hAl) + +theorem real_coprime_residue_count (H l : ℕ) (hH : 0 < H) (hl : 0 < l) + (hcop : H.Coprime l) (A : Finset (ZMod l)) (b c : ℝ) (hbc : b ≤ c) : + |((realCoprimeResidues H l A b c).card : ℝ) - (c-b)* + ((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ))| ≤ + 2*(H.divisors.card : ℝ)*(A.card : ℝ) := by + let rho := ((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ)) + let L := ((Finset.Ico ⌈b⌉ ⌈c⌉).card : ℝ) + have hr := coprime_density_bounds H l hH hl A + have hbase := coprime_residue_count H l hH hl hcop A ⌈b⌉ ⌈c⌉ + have hround := ceiling_interval_error b c hbc + have hpert : |(L-(c-b))*rho| ≤ A.card := by + rw [abs_mul,abs_of_nonneg hr.1] + exact (mul_le_mul_of_nonneg_right hround hr.1).trans (by simpa only [one_mul] using hr.2) + have ht : (1 : ℝ) ≤ H.divisors.card := by + exact_mod_cast Nat.succ_le_iff.mpr (Finset.card_pos.mpr ⟨1,Nat.one_mem_divisors.mpr hH.ne'⟩) + have htA := mul_le_mul_of_nonneg_right ht (Nat.cast_nonneg A.card) + have he : ((realCoprimeResidues H l A b c).card : ℝ)-(c-b)*rho = + (((coprimeResidues H l A ⌈b⌉ ⌈c⌉).card : ℝ)-L*rho)+(L-(c-b))*rho := by + dsimp [realCoprimeResidues] + ring + change |((realCoprimeResidues H l A b c).card : ℝ)-(c-b)*((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ))| ≤ _ + rw [mul_assoc,he] + have hh := abs_add_le (((coprimeResidues H l A ⌈b⌉ ⌈c⌉).card : ℝ)-L*rho) ((L-(c-b))*rho) + change |((coprimeResidues H l A ⌈b⌉ ⌈c⌉).card : ℝ)-L*((H.totient : ℝ)/(H : ℝ))*((A.card : ℝ)/(l : ℝ))| ≤ _ at hbase + rw [mul_assoc] at hbase + nlinarith [hh,hpert,hbase,htA] + +end ErdosCoprimeResidueInterval + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ReferenceEulerRecurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ReferenceEulerRecurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..f749a7925bb503d33c00c18ba148d707c7837e70 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ReferenceEulerRecurrence.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.Jacobsthal.Primes.ReferenceSourcePrimeSets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceEulerRecurrence + +open _root_.Finset +open ReferencePruning ReferencePrefixRecurrence ReferenceCutoffRecurrence +open ReferenceSourcePrimeSets ReferenceProductsBasics ReferenceMertens ReferenceAdmission +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.HarmonicPrimeMeasure + +lemma signedWeight_cons (p : ℕ) (ps : List ℕ) : + signedWeight (p::ps)=(-(p:ℝ)⁻¹)*signedWeight ps := by + simp only [signedWeight,List.length_cons,pow_succ,prefixWeight,List.map_cons,List.prod_cons] + ring + +theorem survivor_first_recurrence (P : Finset ℕ) : + survivorProduct P=1-∑ p ∈ P,(p:ℝ)⁻¹*survivorProduct (P.filter (fun q => q q q q q q q q q q (source_reference_transport hw htop z hs hz hg hclosed hcap ps (hF hps)).1 + have hsum : (∑ ps∈F,prefixWeight ps*Real.exp (-c*(terminal w z ps).gap))= + ∑ ps∈F,prefixWeight ps*tailListReward c (3*((M:ℝ)+1)) w z ps := by + apply Finset.sum_congr rfl + intro ps hps + rw [tailListReward,ite_eq_left (hK.trans_lt (hGap ps hps))] + rw [hsum] + have hle := Finset.sum_le_sum_of_subset_of_nonneg hsub + (fun ps _ _ => mul_nonneg (prefixWeight_nonneg ps) (tailListReward_nonneg c (3*((M:ℝ)+1)) w z ps)) + exact (mul_le_mul_of_nonneg_left hle (sq_nonneg B)).trans + (hTail M le_rfl B w ((le_max_left _ _).trans hB) hw₀ 1 (by norm_num) (by linarith) + hcomp z hi h199 h23 hz hcut) +end NumberTheoryLean.ReferenceExponentialTail + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/RefinementPrimeCongruences.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/RefinementPrimeCongruences.lean new file mode 100644 index 0000000000000000000000000000000000000000..b1753b410fad54bf77d926e367887418d37930eb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/RefinementPrimeCongruences.lean @@ -0,0 +1,102 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualPointSlopes + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseRefinement +open ErdosInverseSampling ErdosInverseSampleCost ErdosInversePrimeBin ErdosInverseEuler ErdosInverseBoxHeight + +noncomputable def sampleModulus (U : Finset ℕ) (h : ℕ) (s : Sample U h) : ℕ := ∏ i : Fin h,(s i).val + +theorem sampleModulus_pos (U : Finset ℕ) (h : ℕ) (s : Sample U h) + (hU : ∀ u ∈ U,0 < u) : 0 < sampleModulus U h s := + Finset.prod_pos (fun i _ => hU _ (s i).property) + +theorem sample_prime_dvd_modulus (U : Finset ℕ) (h : ℕ) (s : Sample U h) (i : Fin h) : + (s i).val ∣ sampleModulus U h s := Finset.dvd_prod_of_mem _ (Finset.mem_univ i) + +theorem sampleModulus_upper (U : Finset ℕ) (h : ℕ) (s : Sample U h) (T : ℝ) + (hU : ∀ u ∈ U,(u : ℝ) ≤ T) : (sampleModulus U h s : ℝ) ≤ T^h := by + unfold sampleModulus + rw [Nat.cast_prod] + have hh := Finset.prod_le_prod₀ (s := Finset.univ) (fun i _ => Nat.cast_nonneg (s i).val) + (fun i _ => hU _ (s i).property) + simpa only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] using hh + +theorem source_sample_modulus_square (K eps : ℝ) (h : ℕ) (hK : 0 ≤ K) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop,∀ U theta : ℝ,0 ≤ U → U ≤ (sourceW z)^K → 0 ≤ theta → theta ≤ 1 → + ∀ s : Sample (primeBin U theta) h, + ((sampleModulus (primeBin U theta) h s : ℝ))^2 ≤ (sourceZ z)^eps := by + let A : ℝ := (2*(h : ℝ))*(Real.log 2+K) + have hA : 0 ≤ A := by dsimp [A];positivity + filter_upwards [sourceW_log_bounds,(Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop 1, + exp_loglog_sq_le_sourceZ A eps hA heps] with z hz hs hExp + intro U theta hU0 hUtop htheta htheta1 s + have hWpos : 0 < sourceW z := (Real.rpow_pos_of_pos hz.2.1 _).trans_le hz.2.2.1 + have hUL : U ≤ (Real.log z)^K := hUtop.trans (Real.rpow_le_rpow hWpos.le hz.2.2.2 hK) + have hcap : ∀ u ∈ primeBin U theta,(u : ℝ) ≤ 2*U := by + intro u hu + have hh := ((mem_primeBin hU0 htheta u).mp hu).2.2 + nlinarith + have hM := sampleModulus_upper (primeBin U theta) h s (2*U) hcap + have hML : (sampleModulus (primeBin U theta) h s : ℝ) ≤ (2*(Real.log z)^K)^h := + hM.trans (pow_le_pow_left₀ (by positivity) (mul_le_mul_of_nonneg_left hUL (by norm_num)) h) + have hLL1 : 1 ≤ Real.log (Real.log z) := hs + have hLL2 : Real.log (Real.log z) ≤ (Real.log (Real.log z))^2 := by nlinarith + have hsq1 : 1 ≤ (Real.log (Real.log z))^2 := by nlinarith + have hlogs : Real.log 2+K*Real.log (Real.log z) ≤ (Real.log 2+K)*(Real.log (Real.log z))^2 := by + have h1 := mul_le_mul_of_nonneg_left hsq1 (Real.log_nonneg (by norm_num : (1 : ℝ) ≤ 2)) + have h2 := mul_le_mul_of_nonneg_left hLL2 hK + nlinarith + calc + _ ≤ ((2*(Real.log z)^K)^h)^2 := pow_le_pow_left₀ (Nat.cast_nonneg _) hML 2 + _ = Real.exp ((2*(h : ℝ))*(Real.log 2+K*Real.log (Real.log z))) := by + rw [← pow_mul,← Real.exp_log (mul_pos (by norm_num : (0 : ℝ) < 2) (Real.rpow_pos_of_pos hz.2.1 K))] + rw [← Real.exp_nat_mul] + congr 1 + rw [Real.log_mul (by norm_num : (2 : ℝ) ≠ 0) (Real.rpow_pos_of_pos hz.2.1 K).ne',Real.log_rpow hz.2.1] + push_cast + ring + _ ≤ Real.exp (A*(Real.log (Real.log z))^2) := by + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_left hlogs (show 0 ≤ 2*(h : ℝ) by positivity) + dsimp [A] + nlinarith + _ ≤ _ := hExp + +end ErdosInverseRefinement + +end + +section + +namespace ErdosInverseRefinement +open ErdosInverseCells ErdosInverseSampling + +theorem refinement_sample_congruences (C U : Finset ℕ) (a : ℕ → ℕ) + (h : ℕ) (s : Sample U h) (j : RefinementLabel (sampleModulus U h s)) (q r : ℕ) + (hq : q ∈ refinementCell C a (sampleModulus U h s) j) + (hr : r ∈ refinementCell C a (sampleModulus U h s) j) (i : Fin h) : + (q : ZMod (s i).val) = (r : ZMod (s i).val) ∧ + (cofactorHit q a : ZMod (s i).val) = (cofactorHit r a : ZMod (s i).val) := by + have hh := refinement_congruences C a (sampleModulus U h s) j q r hq hr + have hd : ((s i).val : ℤ) ∣ (sampleModulus U h s : ℤ) := by + exact_mod_cast sample_prime_dvd_modulus U h s i + have hq' := Int.ModEq.of_dvd hd hh.1 + have hb' := Int.ModEq.of_dvd hd hh.2 + exact ⟨(ZMod.natCast_eq_natCast_iff _ _ _).mpr (Int.natCast_modEq_iff.mp hq'), + (ZMod.natCast_eq_natCast_iff _ _ _).mpr (Int.natCast_modEq_iff.mp hb')⟩ + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueCountDifference.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueCountDifference.lean new file mode 100644 index 0000000000000000000000000000000000000000..6945ade5747f09ad8b8d7ab7f5a9799e05692fbc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueCountDifference.lean @@ -0,0 +1,763 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Real +import Mathlib.Data.Int.GCD +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Sieve.EulerProductRatio + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.ProgressionSieve + +open scoped BigOperators + +theorem exists_affine_residue {p q : ℕ} (hp : p.Prime) (hqp : q.Coprime p) + (r c : ℕ) : ∃ b : ℕ, ∀ t : ℕ, + (r + q * t) % p = c % p ↔ t % p = b % p := by + obtain ⟨b, _, hb⟩ := Nat.exists_mul_mod_eq_of_coprime (p - r % p + c) hqp hp.ne_zero + have hsol : Nat.ModEq p (r + q * b) c := by + have h := (Nat.mod_modEq r p).symm.add (show Nat.ModEq p (q * b) (p - r % p + c) from hb) + have heq : r % p + (p - r % p + c) = p + c := by + have := Nat.mod_lt r hp.pos + omega + rw [heq] at h + exact h.trans (show Nat.ModEq p (p + c) c by simp [Nat.ModEq]) + refine ⟨b, ?_⟩ + intro t + constructor + · intro h + have hprod := Nat.ModEq.add_left_cancel' r ((show Nat.ModEq p (r + q * t) c from h).trans hsol.symm) + exact hprod.cancel_left_of_coprime hqp.symm.gcd_eq_one + · intro h + exact ((show Nat.ModEq p t b from h).mul_left q |>.add_left r).trans hsol + +theorem exists_progression_residues (z q r : ℕ) (hq : q.Prime) (hzq : z < q) + (residue : ℕ → ℕ) : ∃ transformed : ℕ → ℕ, + ∀ p, p.Prime → p ≤ z → ∀ t : ℕ, + (r + q * t) % p = residue p % p ↔ t % p = transformed p % p := by + classical + have hchoice : ∀ p : ℕ, ∃ b : ℕ, p.Prime → p ≤ z → ∀ t : ℕ, + (r + q * t) % p = residue p % p ↔ t % p = b % p := by + intro p + by_cases hp : p.Prime ∧ p ≤ z + · have hqp : q.Coprime p := (Nat.coprime_primes hq hp.1).mpr (by omega) + obtain ⟨b, hb⟩ := exists_affine_residue hp.1 hqp r (residue p) + exact ⟨b, fun _ _ => hb⟩ + · exact ⟨0, fun hprime hpz => False.elim (hp ⟨hprime, hpz⟩)⟩ + choose transformed htrans using hchoice + exact ⟨transformed, htrans⟩ + +theorem divisibilityResidue_lt (a : ℤ) {q : ℕ} (hq : 0 < q) : + LargePrimeDeletion.divisibilityResidue a q < q := by + have hqz : (0 : ℤ) < q := by exact_mod_cast hq + have hr0 : 0 ≤ (-a) % q := Int.emod_nonneg _ (ne_of_gt hqz) + have hrq : (-a) % q < q := Int.emod_lt_of_pos _ hqz + exact_mod_cast (show ((LargePrimeDeletion.divisibilityResidue a q : ℕ) : ℤ) < q by + simpa only [LargePrimeDeletion.divisibilityResidue, Int.toNat_of_nonneg hr0] using hrq) + +theorem offset_eq_residue_add_mul_div (a : ℤ) {q i : ℕ} (hq : 0 < q) + (hdiv : (q : ℤ) ∣ a + i) : + i = LargePrimeDeletion.divisibilityResidue a q + q * (i / q) := by + have hmod := (LargePrimeDeletion.divisibility_iff_modEq a hq i).mp hdiv + have hr := divisibilityResidue_lt a hq + have hi : i % q = LargePrimeDeletion.divisibilityResidue a q := by + simpa only [Nat.ModEq, Nat.mod_eq_of_lt hr] using hmod + have hdecomp := Nat.mod_add_div i q + rw [hi] at hdecomp + exact hdecomp.symm + +def progressionLength (Y z : ℕ) : ℕ := Y / (z + 1) + 1 + +theorem exists_deletion_pullback (Y z : ℕ) (residue : ℕ → ℕ) (a : ℤ) + {q : ℕ} (hq : q.Prime) (hzq : z < q) : + ∃ transformed : ℕ → ℕ, + (LargePrimeDeletion.deletionCell (LargePrimeDeletion.cutoffSurvivors Y z residue) a q).card ≤ + (LargePrimeDeletion.cutoffSurvivors (progressionLength Y z) z transformed).card := by + classical + let r := LargePrimeDeletion.divisibilityResidue a q + obtain ⟨transformed, htrans⟩ := exists_progression_residues z q r hq hzq residue + refine ⟨transformed, ?_⟩ + apply Finset.card_le_card_of_injOn (fun i : ℕ => i / q) + · intro i hi + obtain ⟨his, hdiv⟩ := LargePrimeDeletion.mem_deletionCell.mp hi + obtain ⟨hiY, hav⟩ := LargePrimeDeletion.mem_cutoffSurvivors.mp his + apply LargePrimeDeletion.mem_cutoffSurvivors.mpr + refine ⟨?_, ?_⟩ + · have hquot : i / q ≤ Y / (z + 1) := + Nat.div_le_div (Nat.le_of_lt hiY) (Nat.succ_le_of_lt hzq) (Nat.succ_ne_zero z) + exact Nat.lt_succ_of_le hquot + · intro p hp hpz hbad + have hdecomp := offset_eq_residue_add_mul_div a hq.pos hdiv + have hhit := (htrans p hp hpz (i / q)).mpr hbad + change (r + q * (i / q)) % p = residue p % p at hhit + rw [← hdecomp] at hhit + exact hav p hp hpz hhit + · intro i hi j hj hquot + obtain ⟨_, hdivi⟩ := LargePrimeDeletion.mem_deletionCell.mp hi + obtain ⟨_, hdivj⟩ := LargePrimeDeletion.mem_deletionCell.mp hj + change i / q = j / q at hquot + rw [offset_eq_residue_add_mul_div a hq.pos hdivi, + offset_eq_residue_add_mul_div a hq.pos hdivj, hquot] + +noncomputable def deletionBudget (Y z : ℕ) : ℝ := + 255 * (1 + (progressionLength Y z : ℝ) / Real.log (progressionLength Y z)) + +theorem deletionBudget_nonneg (Y z : ℕ) : 0 ≤ deletionBudget Y z := by + have hT : 1 ≤ progressionLength Y z := by simp [progressionLength] + have hlog : 0 ≤ Real.log (progressionLength Y z : ℝ) := + Real.log_nonneg (by exact_mod_cast hT) + unfold deletionBudget + exact mul_nonneg (by norm_num) (add_nonneg zero_le_one + (div_nonneg (Nat.cast_nonneg _) hlog)) + +theorem largePrime_deletion_le_log (Y z : ℕ) (residue : ℕ → ℕ) (a : ℤ) + {q : ℕ} (hq : q.Prime) (hzq : z < q) (hTz : progressionLength Y z ≤ z) : + ((LargePrimeDeletion.deletionCell + (LargePrimeDeletion.cutoffSurvivors Y z residue) a q).card : ℝ) ≤ deletionBudget Y z := by + obtain ⟨transformed, hcard⟩ := exists_deletion_pullback Y z residue a hq hzq + calc + _ ≤ ((LargePrimeDeletion.cutoffSurvivors (progressionLength Y z) z transformed).card : ℝ) := by + exact_mod_cast hcard + _ ≤ _ := SquarefreeHarmonic.cutoffSurvivors_le_uniform_log + (progressionLength Y z) z transformed hTz + +theorem sum_largePrime_deletions_le_log (Y n z k : ℕ) + (hcard : n.primeFactors.card ≤ k) (residue : ℕ → ℕ) (a : ℤ) + (hTz : progressionLength Y z ≤ z) : + (∑ q ∈ LargePrimeDeletion.largePrimeFactors n z, + ((LargePrimeDeletion.deletionCell + (LargePrimeDeletion.cutoffSurvivors Y z residue) a q).card : ℝ)) ≤ + (k : ℝ) * deletionBudget Y z := by + have hlargecard : (LargePrimeDeletion.largePrimeFactors n z).card ≤ k := + (Finset.card_filter_le _ _).trans hcard + calc + _ ≤ ∑ _q ∈ LargePrimeDeletion.largePrimeFactors n z, deletionBudget Y z := by + apply Finset.sum_le_sum + intro q hq + obtain ⟨hqn, hqz⟩ := LargePrimeDeletion.mem_largePrimeFactors.mp hq + exact largePrime_deletion_le_log Y z residue a + (Nat.mem_primeFactors.mp hqn).1 hqz hTz + _ = ((LargePrimeDeletion.largePrimeFactors n z).card : ℝ) * deletionBudget Y z := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast hlargecard) (deletionBudget_nonneg Y z) + +theorem isJacobsthalBound_of_cutoff_lower (Y z k : ℕ) + (hTz : progressionLength Y z ≤ z) {S : ℝ} + (hlower : ∀ residue : ℕ → ℕ, + S ≤ (LargePrimeDeletion.cutoffSurvivors Y z residue).card) + (hbudget : (k : ℝ) * deletionBudget Y z < S) : + Targets.IsJacobsthalBound k Y := by + apply LargePrimeDeletion.isJacobsthalBound_of_cutoff_estimates Y z k + (deletionBudget_nonneg Y z) hlower + · intro residue a q hq hqz + exact largePrime_deletion_le_log Y z residue a hq hqz hTz + · exact hbudget + +end NumberTheoryLean.ProgressionSieve + + + +namespace NumberTheoryLean.SmallSieveRelative + +open scoped BigOperators + +theorem normalized_remainder_le (u v : ℝ) (hu : 2 ≤ u) (hv : 4 ≤ v) : + u ^ (v / 2) / (u ^ v * SmallSieveFinite.smallEuler ⌊u⌋₊) ≤ Real.exp (-v / 192) := by + have hu0 : 0 < u := by linarith + have hJ : 0 < u ^ v := Real.rpow_pos_of_pos hu0 v + have hEuler := SmallSieveFinite.smallEuler_floor_ge_inv u hu + have hinv : 0 < u⁻¹ := inv_pos.mpr hu0 + have hlog2 : (1 / 2 : ℝ) ≤ Real.log 2 := by + have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 2) + norm_num at h + exact h + have hlogu : (1 / 2 : ℝ) ≤ Real.log u := hlog2.trans (Real.log_le_log (by norm_num) hu) + calc + u ^ (v / 2) / (u ^ v * SmallSieveFinite.smallEuler ⌊u⌋₊) ≤ + u ^ (v / 2) / (u ^ v * u⁻¹) := + div_le_div_of_nonneg_left (Real.rpow_nonneg hu0.le _) (mul_pos hJ hinv) + (mul_le_mul_of_nonneg_left hEuler hJ.le) + _ = (u ^ (v / 2) / u ^ v) * u := by field_simp + _ = u ^ (v / 2 - v) * u := by rw [Real.rpow_sub hu0] + _ = u ^ (1 - v / 2) := by + have hidx : (v / 2 - v) + 1 = 1 - v / 2 := by ring + rw [← hidx, Real.rpow_add hu0, Real.rpow_one] + _ = Real.exp (Real.log u * (1 - v / 2)) := Real.rpow_def_of_pos hu0 _ + _ ≤ _ := by + apply Real.exp_le_exp.mpr + have h := mul_nonneg (show 0 ≤ v / 2 - 1 by linarith) (sub_nonneg.mpr hlogu) + nlinarith + +theorem relative_bound_rpow (N : ℕ) (u v : ℝ) (residue : ℕ → ℕ) + (hu : 2 ≤ u) (hv : 960048 ≤ v) (hNJ : |(N : ℝ) - u ^ v| ≤ 1) : + |((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) / + (u ^ v * SmallSieveFinite.smallEuler ⌊u⌋₊) - 1| ≤ 3 * Real.exp (-v / 192) := by + have hu0 : 0 < u := by linarith + have hJ : 0 < u ^ v := Real.rpow_pos_of_pos hu0 v + have hEuler : 0 < SmallSieveFinite.smallEuler ⌊u⌋₊ := + (inv_pos.mpr hu0).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv u hu) + have hDen : 0 < u ^ v * SmallSieveFinite.smallEuler ⌊u⌋₊ := mul_pos hJ hEuler + have h := SmallSieveFinite.finite_small_sieve_bound N u (v / 2) (u ^ v) residue + hu (by linarith) hJ.le hNJ + have hparam : -(v / 2) / 96 = -v / 192 := by ring + rw [hparam] at h + have hrem := normalized_remainder_le u v hu (by linarith) + let A : ℝ := (LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card + let D : ℝ := u ^ v * SmallSieveFinite.smallEuler ⌊u⌋₊ + have hD0 : D ≠ 0 := ne_of_gt hDen + have hEq : A / D - 1 = (A - D) / D := by field_simp [hD0] + change |A / D - 1| ≤ _ + rw [hEq, abs_div, abs_of_pos hDen] + calc + |A - D| / D ≤ (D * Real.exp (-v / 192) + 2 * u ^ (v / 2)) / D := + div_le_div_of_nonneg_right h hDen.le + _ = Real.exp (-v / 192) + 2 * (u ^ (v / 2) / D) := by field_simp [hD0] + _ ≤ _ := by change u ^ (v / 2) / D ≤ _ at hrem; linarith + +theorem rpow_log_ratio (u J : ℝ) (hu : 1 < u) (hJ : 0 < J) : + u ^ (Real.log J / Real.log u) = J := by + have hlu : Real.log u ≠ 0 := ne_of_gt (Real.log_pos hu) + rw [Real.rpow_def_of_pos (by linarith)] + have he : Real.log u * (Real.log J / Real.log u) = Real.log J := by field_simp + rw [he, Real.exp_log hJ] + +theorem small_relative (N : ℕ) (u J : ℝ) (residue : ℕ → ℕ) + (hu : 2 ≤ u) (hJ : 0 < J) (hNJ : |(N : ℝ) - J| ≤ 1) + (hv : 960048 ≤ Real.log J / Real.log u) : + |((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) / + (J * SmallSieveFinite.smallEuler ⌊u⌋₊) - 1| ≤ + 3 * Real.exp (-(Real.log J / Real.log u) / 192) := by + have hpow := rpow_log_ratio u J (by linarith) hJ + have h := relative_bound_rpow N u (Real.log J / Real.log u) residue hu hv (by simpa only [hpow] using hNJ) + simpa only [hpow] using h + +end NumberTheoryLean.SmallSieveRelative + + + +namespace NumberTheoryLean.ProgressionSmallSieve + +def progressionHit (a : ℤ) (q : ℕ) (residue : ℕ → ℕ) (p i : ℕ) : Prop := + Int.ModEq (p : ℤ) (a + (q : ℤ) * i) (residue p : ℤ) + +noncomputable def progressionSurvivors (N z : ℕ) (a : ℤ) (q : ℕ) (residue : ℕ → ℕ) : Finset ℕ := + SievePartition.survivors (Finset.range N) (LargePrimeDeletion.cutoffPrimes z) + (progressionHit a q residue) + +theorem exists_integer_affine_residue (a : ℤ) (q c : ℕ) {p : ℕ} + (hp : p.Prime) (hqp : q.Coprime p) : ∃ b : ℕ, ∀ i : ℕ, + Int.ModEq (p : ℤ) (a + (q : ℤ) * i) (c : ℤ) ↔ Nat.ModEq p i b := by + let r : ℕ := (a % p).toNat + have hpz : (0 : ℤ) < p := by exact_mod_cast hp.pos + have hr : (r : ℤ) = a % p := Int.toNat_of_nonneg (Int.emod_nonneg _ (ne_of_gt hpz)) + have ha : Int.ModEq (p : ℤ) a r := by + unfold Int.ModEq + rw [hr, Int.emod_emod] + obtain ⟨b, hb⟩ := ProgressionSieve.exists_affine_residue hp hqp r c + refine ⟨b, ?_⟩ + intro i + have hshift : Int.ModEq (p : ℤ) (a + (q : ℤ) * i) ((r + q * i : ℕ) : ℤ) := by + simpa only [Nat.cast_add, Nat.cast_mul] using ha.add_right ((q : ℤ) * i) + constructor + · intro h + have hnat : Nat.ModEq p (r + q * i) c := Int.natCast_modEq_iff.mp (hshift.symm.trans h) + exact (hb i).mp hnat + · intro h + have hnat : Nat.ModEq p (r + q * i) c := (hb i).mpr h + exact hshift.trans (Int.natCast_modEq_iff.mpr hnat) + +theorem exists_coordinate_residues (z : ℕ) (a : ℤ) (q : ℕ) (residue : ℕ → ℕ) + (hcoprime : ∀ p : ℕ, p.Prime → p ≤ z → q.Coprime p) : + ∃ transformed : ℕ → ℕ, ∀ p, p.Prime → p ≤ z → ∀ i : ℕ, + progressionHit a q residue p i ↔ SievePartition.residueBad transformed p i := by + classical + have hchoice : ∀ p : ℕ, ∃ b : ℕ, p.Prime → p ≤ z → ∀ i : ℕ, + progressionHit a q residue p i ↔ Nat.ModEq p i b := by + intro p + by_cases hp : p.Prime ∧ p ≤ z + · obtain ⟨b, hb⟩ := exists_integer_affine_residue a q (residue p) hp.1 (hcoprime p hp.1 hp.2) + exact ⟨b, fun _ _ => hb⟩ + · exact ⟨0, fun hprime hpz => False.elim (hp ⟨hprime, hpz⟩)⟩ + choose transformed htrans using hchoice + exact ⟨transformed, htrans⟩ + +theorem exists_progressionSurvivors_eq (N z : ℕ) (a : ℤ) (q : ℕ) (residue : ℕ → ℕ) + (hcoprime : ∀ p : ℕ, p.Prime → p ≤ z → q.Coprime p) : + ∃ transformed : ℕ → ℕ, + progressionSurvivors N z a q residue = LargePrimeDeletion.cutoffSurvivors N z transformed := by + classical + obtain ⟨transformed, htrans⟩ := exists_coordinate_residues z a q residue hcoprime + refine ⟨transformed, ?_⟩ + ext i + simp only [progressionSurvivors, LargePrimeDeletion.cutoffSurvivors, SievePartition.mem_survivors] + apply and_congr_right + intro _ + apply forall₂_congr + intro p hp + obtain ⟨hprime, hpz⟩ := LargePrimeDeletion.mem_cutoffPrimes.mp hp + exact not_congr (htrans p hprime hpz i) + +theorem progression_small_relative (N : ℕ) (u J : ℝ) (a : ℤ) (q : ℕ) (residue : ℕ → ℕ) + (hu : 2 ≤ u) (hJ : 0 < J) (hNJ : |(N : ℝ) - J| ≤ 1) + (hv : 960048 ≤ Real.log J / Real.log u) + (hcoprime : ∀ p : ℕ, p.Prime → (p : ℝ) ≤ u → q.Coprime p) : + |((progressionSurvivors N ⌊u⌋₊ a q residue).card : ℝ) / + (J * SmallSieveFinite.smallEuler ⌊u⌋₊) - 1| ≤ + 3 * Real.exp (-(Real.log J / Real.log u) / 192) := by + have hcop : ∀ p, p.Prime → p ≤ ⌊u⌋₊ → q.Coprime p := by + intro p hp hpz + exact hcoprime p hp ((Nat.le_floor_iff (by linarith)).mp hpz) + obtain ⟨transformed, hEq⟩ := exists_progressionSurvivors_eq N ⌊u⌋₊ a q residue hcop + rw [hEq] + exact SmallSieveRelative.small_relative N u J transformed hu hJ hNJ hv + +end NumberTheoryLean.ProgressionSmallSieve + + + +namespace ErdosModulusRelative +open ErdosInverseHits ErdosInverseCounts NumberTheoryLean +attribute [local instance] Classical.propDecidable + +noncomputable def modulusOffsets (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (d : ℕ) (hd : Squarefree d) : Finset ℕ := + (Finset.range (hitLength Y d (primeHitRepresentative d hd a))).filter + (fun j => ∀ p ∈ small,(primeHitRepresentative d hd a+d*j)%p ≠ a p%p) + +theorem modulus_candidates_eq_offsets (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (d : ℕ) (hd : Squarefree d) : + modulusCandidates Y small a d = + (modulusOffsets Y small a d hd).image (fun j => primeHitRepresentative d hd a+d*j) := by + classical + have hd0 : 0 < d := Nat.pos_of_ne_zero hd.ne_zero + have hb := primeHitRepresentative_spec d hd a + ext n + rw [mem_modulusCandidates] + simp only [modulusOffsets,Finset.mem_image,Finset.mem_filter,Finset.mem_range] + constructor + · rintro ⟨hn1,hnY,hpr,hsmall⟩ + obtain ⟨j,rfl⟩ := exists_positive_coordinate d _ n hd0 hb.1 hb.2.1 hn1 ((hb.2.2 n).mp hpr) + exact ⟨j,⟨(lt_hitLength_iff Y d _ j hd0 hb.2.1).mpr hnY,hsmall⟩,rfl⟩ + · rintro ⟨j,⟨hj,hsmall⟩,rfl⟩ + refine ⟨by omega,(lt_hitLength_iff Y d _ j hd0 hb.2.1).mp hj,?_,hsmall⟩ + apply (hb.2.2 _).mpr + change (_+d*j)%d=_%d + simp + +theorem modulus_count_eq_offsets (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (d : ℕ) (hd : Squarefree d) : + modulusCount Y small a d = ((modulusOffsets Y small a d hd).card : ℤ) := by + unfold modulusCount + rw [modulus_candidates_eq_offsets,Finset.card_image_of_injective] + intro i j hij + exact Nat.eq_of_mul_eq_mul_left (Nat.pos_of_ne_zero hd.ne_zero) (Nat.add_left_cancel hij) + +theorem offsets_eq_progression (Y z : ℕ) (a : ℕ → ℕ) (d : ℕ) (hd : Squarefree d) : + modulusOffsets Y (LargePrimeDeletion.cutoffPrimes z) a d hd = + ProgressionSmallSieve.progressionSurvivors (hitLength Y d (primeHitRepresentative d hd a)) + z (primeHitRepresentative d hd a : ℤ) d a := by + ext j + simp only [modulusOffsets,ProgressionSmallSieve.progressionSurvivors,SievePartition.mem_survivors, + Finset.mem_filter,Finset.mem_range,ProgressionSmallSieve.progressionHit] + apply and_congr_right + intro _hj + apply forall_congr' + intro p + apply forall_congr' + intro _hp + rw [← Nat.cast_mul,← Nat.cast_add,Int.natCast_modEq_iff] + rfl + +theorem large_modulus_coprime_small (w : ℝ) (d : ℕ) (hd : Squarefree d) + (hlarge : ∀ p ∈ d.primeFactors,w < (p : ℝ)) (p : ℕ) (hp : p.Prime) (hpw : (p : ℝ) ≤ w) : + d.Coprime p := by + apply Nat.Coprime.symm + apply hp.coprime_iff_not_dvd.mpr + intro hpd + have h := hlarge p (Nat.mem_primeFactors.mpr ⟨hp,hpd,hd.ne_zero⟩) + linarith + +end ErdosModulusRelative + + + +namespace NumberTheoryLean.SmallSieveUpper + +theorem cutoffSurvivors_antitone (N z t : ℕ) (htz : t ≤ z) (residue : ℕ → ℕ) : + LargePrimeDeletion.cutoffSurvivors N z residue ⊆ LargePrimeDeletion.cutoffSurvivors N t residue := by + intro i hi + obtain ⟨hiN, hav⟩ := LargePrimeDeletion.mem_cutoffSurvivors.mp hi + exact LargePrimeDeletion.mem_cutoffSurvivors.mpr ⟨hiN, fun p hp hpt => hav p hp (hpt.trans htz)⟩ + +theorem count_le_four_of_relative (N : ℕ) (u J : ℝ) (residue : ℕ → ℕ) + (hu : 2 ≤ u) (hJ : 0 < J) (hNJ : |(N : ℝ) - J| ≤ 1) + (hv : 960048 ≤ Real.log J / Real.log u) : + ((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) ≤ + 4 * J * SmallSieveFinite.smallEuler ⌊u⌋₊ := by + have h := SmallSieveRelative.small_relative N u J residue hu hJ hNJ hv + have hExp : Real.exp (-(Real.log J / Real.log u) / 192) ≤ 1 := by + apply Real.exp_le_one_iff.mpr + linarith + have hEuler : 0 < SmallSieveFinite.smallEuler ⌊u⌋₊ := + (inv_pos.mpr (show 0 < u by linarith)).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv u hu) + have hDen : 0 < J * SmallSieveFinite.smallEuler ⌊u⌋₊ := mul_pos hJ hEuler + have hRatio := (abs_le.mp h).2 + have hBound : ((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) ≤ + 4 * (J * SmallSieveFinite.smallEuler ⌊u⌋₊) := (div_le_iff₀ hDen).mp (by linarith) + simpa only [mul_assoc] using hBound + +theorem threshold_ge_two (h : ℕ) : (2 : ℝ) ≤ (2 : ℝ) ^ (2 ^ h : ℕ) := by + have hn : 1 ≤ 2 ^ h := Nat.one_le_pow _ _ (by norm_num) + have hp := pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) hn + simpa only [pow_one] using hp + +theorem small_upper_explicit (N : ℕ) (u J η : ℝ) (residue : ℕ → ℕ) (h : ℕ) + (hscale : 960048 ≤ η * ((2 ^ h : ℕ) : ℝ)) + (hu : (2 : ℝ) ^ (2 ^ h : ℕ) ≤ u) (hJlower : u ^ η ≤ J) (hNJ : |(N : ℝ) - J| ≤ 1) : + ((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) ≤ + (4 * Real.exp (4596 * ((h + 1 : ℕ) : ℝ))) * J * SmallSieveFinite.smallEuler ⌊u⌋₊ := by + let w := EulerProductRatio.rootCutoff u h + have hu2 : 2 ≤ u := (threshold_ge_two h).trans hu + have hu0 : 0 < u := by linarith + have hw2 : 2 ≤ w := EulerProductRatio.rootCutoff_ge_two u h hu + have hwle : w ≤ u := EulerProductRatio.rootCutoff_le u h (by linarith) + have hJ : 0 < J := (Real.rpow_pos_of_pos hu0 η).trans_le hJlower + have hlu : 0 < Real.log u := Real.log_pos (by linarith) + have hlw : 0 < Real.log w := Real.log_pos (by linarith) + have hn : (0 : ℝ) < ((2 ^ h : ℕ) : ℝ) := by positivity + have hη : 960048 * (((2 ^ h : ℕ) : ℝ)⁻¹) ≤ η := by + rw [← div_eq_mul_inv] + exact (div_le_iff₀ hn).mpr hscale + have hlogJ : η * Real.log u ≤ Real.log J := by + have hlog := Real.log_le_log (Real.rpow_pos_of_pos hu0 η) hJlower + rwa [Real.log_rpow hu0] at hlog + have hlogw : Real.log w = (((2 ^ h : ℕ) : ℝ)⁻¹) * Real.log u := Real.log_rpow hu0 _ + have hvw : 960048 ≤ Real.log J / Real.log w := by + apply (le_div_iff₀ hlw).mpr + rw [hlogw] + have hmul := mul_le_mul_of_nonneg_right hη hlu.le + nlinarith + have hCount := count_le_four_of_relative N w J residue hw2 hJ hNJ hvw + have hEuler := EulerProductRatio.smallEuler_ratio_rootCutoff u h hu2 hw2 + have hSubset := cutoffSurvivors_antitone N ⌊u⌋₊ ⌊w⌋₊ (Nat.floor_mono hwle) residue + calc + ((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) ≤ + ((LargePrimeDeletion.cutoffSurvivors N ⌊w⌋₊ residue).card : ℝ) := by + exact_mod_cast Finset.card_le_card hSubset + _ ≤ 4 * J * SmallSieveFinite.smallEuler ⌊w⌋₊ := hCount + _ ≤ 4 * J * (Real.exp (4596 * ((h + 1 : ℕ) : ℝ)) * SmallSieveFinite.smallEuler ⌊u⌋₊) := + mul_le_mul_of_nonneg_left hEuler (by positivity) + _ = _ := by ring + +theorem small_upper (η : ℝ) (hη : 0 < η) : + ∃ C : ℝ, 0 < C ∧ ∃ u₀ : ℝ, 2 ≤ u₀ ∧ + ∀ (N : ℕ) (u J : ℝ) (residue : ℕ → ℕ), u₀ ≤ u → u ^ η ≤ J → + |(N : ℝ) - J| ≤ 1 → + ((LargePrimeDeletion.cutoffSurvivors N ⌊u⌋₊ residue).card : ℝ) ≤ + C * J * SmallSieveFinite.smallEuler ⌊u⌋₊ := by + obtain ⟨h, hh⟩ := pow_unbounded_of_one_lt (960048 / η) (by norm_num : (1 : ℝ) < 2) + have hscale : 960048 ≤ η * ((2 ^ h : ℕ) : ℝ) := by + have hmul := (div_lt_iff₀ hη).mp hh + push_cast + nlinarith + refine ⟨4 * Real.exp (4596 * ((h + 1 : ℕ) : ℝ)), by positivity, + (2 : ℝ) ^ (2 ^ h : ℕ), threshold_ge_two h, ?_⟩ + intro N u J residue hu hJ hNJ + exact small_upper_explicit N u J η residue h hscale hu hJ hNJ + +theorem progression_small_upper (η : ℝ) (hη : 0 < η) : + ∃ C : ℝ, 0 < C ∧ ∃ u₀ : ℝ, 2 ≤ u₀ ∧ + ∀ (N : ℕ) (u J : ℝ) (a : ℤ) (q : ℕ) (residue : ℕ → ℕ), + u₀ ≤ u → u ^ η ≤ J → |(N : ℝ) - J| ≤ 1 → + (∀ p : ℕ, p.Prime → (p : ℝ) ≤ u → q.Coprime p) → + ((ProgressionSmallSieve.progressionSurvivors N ⌊u⌋₊ a q residue).card : ℝ) ≤ + C * J * SmallSieveFinite.smallEuler ⌊u⌋₊ := by + obtain ⟨C, hC, u₀, hu₀, hBound⟩ := small_upper η hη + refine ⟨C, hC, u₀, hu₀, ?_⟩ + intro N u J a q residue hu hJ hNJ hcop + have hcopNat : ∀ p : ℕ, p.Prime → p ≤ ⌊u⌋₊ → q.Coprime p := by + intro p hp hpu + exact hcop p hp ((Nat.le_floor_iff (by linarith)).mp hpu) + obtain ⟨transformed, hEq⟩ := ProgressionSmallSieve.exists_progressionSurvivors_eq N ⌊u⌋₊ a q residue hcopNat + rw [hEq] + exact hBound N u J transformed hu hJ hNJ + +end NumberTheoryLean.SmallSieveUpper + + + +namespace ErdosPrimeInputs.SubsetPrimeSieve + +open Finset +open NumberTheoryLean +open SmallSieveFinite IntervalBoundingSieve + +noncomputable def euler (P : Finset ℕ) : ℝ := ∏ p ∈ P, (1 - (p : ℝ)⁻¹) + +theorem finite_subset_sieve_bound (N : ℕ) (u s J : ℝ) (P : Finset ℕ) (residue : ℕ → ℕ) + (hu : 2 ≤ u) (hs : 480024 ≤ s) (hJ : 0 ≤ J) (hNJ : |(N : ℝ) - J| ≤ 1) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, (p : ℝ) ≤ u) : + |((residueAvoidingOffsets N (∏ p ∈ P, p) residue).card : ℝ) - J * euler P| ≤ + J * euler P * Real.exp (-s / 96) + 2 * u ^ s := by + classical + let D := ∏ p ∈ P, p + have hD : Squarefree D := squarefree_primeSet_product P hprime + obtain ⟨A,hA⟩ := exists_residue_count_translation N D (Nat.pos_of_ne_zero hD.ne_zero) residue + have h := RealFundamentalSieve.fundamental_lemma (Finset.range N) (fun _ => (1 : ℝ)) + (fun _ _ => by norm_num) (fun p i => p ∣ A+i) u s P J (fun p => (p : ℝ)⁻¹) + hu hs hJ hprime hsize (fun _ _ => inv_nonneg.mpr (Nat.cast_nonneg _)) + (fun p _ => by simpa only [one_div] using + div_le_div_of_nonneg_right (by norm_num : (1:ℝ) ≤ 2) (Nat.cast_nonneg p)) + (fun _ => by norm_num) + rw [survives_sum_eq_coprimeOffsets A N P hprime] at h + change |((LargePrimeDeletion.coprimeOffsets N D (A : ℤ)).card : ℝ) - J * euler P| ≤ _ at h + rw [← hA] at h + apply h.trans + apply add_le_add le_rfl + calc + _ ≤ ∑ _d ∈ RealFundamentalSieve.levelDivisors P u s, (2:ℝ) := by + apply sum_le_sum + intro d hd + exact integerRemainder_abs_le_two A N D hD + (Nat.dvd_of_mem_divisors (mem_filter.mp hd).1) J hNJ + _ = 2 * ((RealFundamentalSieve.levelDivisors P u s).card : ℝ) := by simp [mul_comm] + _ ≤ 2 * u ^ s := mul_le_mul_of_nonneg_left (realLevelDivisors_card_le P u s (by linarith)) (by norm_num) + +theorem euler_pos {P : Finset ℕ} (hprime : ∀ p ∈ P, p.Prime) : 0 < euler P := by + apply prod_pos + intro p hp + have hp1 : (1:ℝ) < p := by exact_mod_cast (hprime p hp).one_lt + exact sub_pos.mpr (inv_lt_one_of_one_lt₀ hp1) + +end ErdosPrimeInputs.SubsetPrimeSieve + + + +namespace ErdosModulusRelative +open ErdosInverseHits ErdosInverseCounts NumberTheoryLean + +theorem modulus_small_relative (w : ℝ) (Y d : ℕ) (a : ℕ → ℕ) + (hw : 2 ≤ w) (hY : 0 < Y) (hd : Squarefree d) + (hlarge : ∀ p ∈ d.primeFactors,w < (p : ℝ)) + (hv : 960048 ≤ Real.log ((Y : ℝ)/(d : ℝ))/Real.log w) : + |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a d : ℝ)/ + (((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊)-1| ≤ + 3*Real.exp (-(Real.log ((Y : ℝ)/(d : ℝ))/Real.log w)/192) := by + have hd0 : 0 < d := Nat.pos_of_ne_zero hd.ne_zero + have hb := primeHitRepresentative_spec d hd a + have hJ : 0 < (Y : ℝ)/(d : ℝ) := by positivity + have hN := hitLength_error Y d (primeHitRepresentative d hd a) hd0 hb.1 hb.2.1 + have hs := ProgressionSmallSieve.progression_small_relative + (hitLength Y d (primeHitRepresentative d hd a)) w ((Y : ℝ)/(d : ℝ)) + (primeHitRepresentative d hd a : ℤ) d a hw hJ hN hv + (large_modulus_coprime_small w d hd hlarge) + rw [modulus_count_eq_offsets Y _ a d hd,offsets_eq_progression,Int.cast_natCast] + exact hs + +theorem uniform_modulus_small_relative (eps : ℝ) (heps : 0 < eps) : + ∃ K0 w0 : ℝ,1 ≤ K0 ∧ 1 < w0 ∧ ∀ w : ℝ,w0 ≤ w → + ∀ (Y d : ℕ) (a : ℕ → ℕ),0 < Y → 0 < d → Squarefree d → + (∀ p ∈ d.primeFactors,w < (p : ℝ)) → + K0 ≤ Real.log ((Y : ℝ)/(d : ℝ))/Real.log w → + |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a d : ℝ)/ + (((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊)-1| ≤ eps := by + let K0 := max (960048 : ℝ) (-192*Real.log (eps/3)) + have hK : 960048 ≤ K0 := le_max_left _ _ + have hKe : -192*Real.log (eps/3) ≤ K0 := le_max_right _ _ + have hExp : 3*Real.exp (-K0/192) ≤ eps := by + have hh : -K0/192 ≤ Real.log (eps/3) := by linarith + have he := Real.exp_le_exp.mpr hh + rw [Real.exp_log (by positivity : 0 < eps/3)] at he + linarith + refine ⟨K0,2,by linarith,by norm_num,?_⟩ + intro w hw Y d a hY _hdpos hd hlarge hv + calc + _ ≤ 3*Real.exp (-(Real.log ((Y : ℝ)/(d : ℝ))/Real.log w)/192) := + modulus_small_relative w Y d a hw hY hd hlarge (hK.trans hv) + _ ≤ 3*Real.exp (-K0/192) := by + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (by linarith)) (by norm_num) + _ ≤ _ := hExp + +end ErdosModulusRelative + + + +namespace ErdosInverseTail +open NumberTheoryLean + +noncomputable def sieveTail (J N z : ℕ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : Finset ℕ := + SievePartition.survivors (Finset.Ico J N) (LargePrimeDeletion.cutoffPrimes z) + (ProgressionSmallSieve.progressionHit b step a) + +theorem progressionHit_shift (J i t : ℕ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + ProgressionSmallSieve.progressionHit (b+(step : ℤ)*J) step a t i ↔ + ProgressionSmallSieve.progressionHit b step a t (J+i) := by + unfold ProgressionSmallSieve.progressionHit + have h : b+(step : ℤ)*J+(step : ℤ)*i = b+(step : ℤ)*(J+i) := by ring + rw [h] + simp only [Nat.cast_add] + +theorem sieveTail_eq_image (J N z : ℕ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + sieveTail J N z b step a = + (ProgressionSmallSieve.progressionSurvivors (N-J) z (b+(step : ℤ)*J) step a).image + (fun i => J+i) := by + classical + ext j + simp only [sieveTail,SievePartition.mem_survivors,Finset.mem_Ico,Finset.mem_image, + ProgressionSmallSieve.progressionSurvivors,Finset.mem_range,progressionHit_shift] + constructor + · rintro ⟨⟨hJj,hjN⟩,ha⟩ + refine ⟨j-J,⟨by omega,?_⟩,Nat.add_sub_of_le hJj⟩ + simpa only [Nat.add_sub_of_le hJj] using ha + · rintro ⟨i,⟨hi,ha⟩,rfl⟩ + exact ⟨⟨by omega,by omega⟩,ha⟩ + +theorem sieveTail_card (J N z : ℕ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + (sieveTail J N z b step a).card = + (ProgressionSmallSieve.progressionSurvivors (N-J) z (b+(step : ℤ)*J) step a).card := by + rw [sieveTail_eq_image,Finset.card_image_of_injective] + exact fun _ _ h => Nat.add_left_cancel h + +theorem survivor_card_split (J N z : ℕ) (hJN : J ≤ N) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + (ProgressionSmallSieve.progressionSurvivors N z b step a).card = + (ProgressionSmallSieve.progressionSurvivors J z b step a).card+(sieveTail J N z b step a).card := by + classical + have hset : ProgressionSmallSieve.progressionSurvivors N z b step a = + ProgressionSmallSieve.progressionSurvivors J z b step a ∪ sieveTail J N z b step a := by + ext j + simp only [ProgressionSmallSieve.progressionSurvivors,sieveTail,SievePartition.mem_survivors, + Finset.mem_range,Finset.mem_Ico,Finset.mem_union] + constructor + · rintro ⟨hj,ha⟩ + by_cases hh : j < J + · exact Or.inl ⟨hh,ha⟩ + · exact Or.inr ⟨⟨by omega,hj⟩,ha⟩ + · rintro (⟨hj,ha⟩ | ⟨⟨_,hj⟩,ha⟩) + · exact ⟨lt_of_lt_of_le hj hJN,ha⟩ + · exact ⟨hj,ha⟩ + have hdis : Disjoint (ProgressionSmallSieve.progressionSurvivors J z b step a) (sieveTail J N z b step a) := by + apply Finset.disjoint_left.mpr + intro j hj ht + have hjJ := Finset.mem_range.mp (SievePartition.mem_survivors.mp hj).1 + have hJj := (Finset.mem_Ico.mp (SievePartition.mem_survivors.mp ht).1).1 + omega + rw [hset,Finset.card_union_of_disjoint hdis] + +end ErdosInverseTail + + + +namespace ErdosInverseTail +open NumberTheoryLean ErdosInverseHits + +noncomputable def residueOffset (J u : ℕ) [NeZero u] (e : ZMod u) : ℕ := (e-(J : ZMod u)).val + +theorem residueOffset_lt (J u : ℕ) [NeZero u] (e : ZMod u) : residueOffset J u e < u := ZMod.val_lt _ + +theorem residue_coordinate_exists (J j u : ℕ) [NeZero u] (e : ZMod u) + (hJj : J ≤ j) (hje : (j : ZMod u) = e) : + ∃ i : ℕ,j = J+residueOffset J u e+u*i := by + have hc : ((j-J : ℕ) : ZMod u) = e-(J : ZMod u) := by rw [Nat.cast_sub hJj,hje] + have hv := congrArg ZMod.val hc + have hmod : (j-J)%u = residueOffset J u e := by simpa only [ZMod.val_natCast,residueOffset] using hv + refine ⟨(j-J)/u,?_⟩ + have he := Nat.mod_add_div (j-J) u + rw [hmod] at he + omega + +theorem residue_coordinate_hit (J u i : ℕ) [NeZero u] (e : ZMod u) : + ((J+residueOffset J u e+u*i : ℕ) : ZMod u) = e := by + simp only [Nat.cast_add,Nat.cast_mul,residueOffset,ZMod.natCast_zmod_val,ZMod.natCast_self, + zero_mul,add_zero] + ring + +theorem progressionHit_stride (A i u t : ℕ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + ProgressionSmallSieve.progressionHit (b+(step : ℤ)*A) (step*u) a t i ↔ + ProgressionSmallSieve.progressionHit b step a t (A+u*i) := by + unfold ProgressionSmallSieve.progressionHit + have he : b+(step : ℤ)*A+((step*u : ℕ) : ℤ)*i = b+(step : ℤ)*(A+u*i) := by push_cast;ring + rw [he] + simp only [Nat.cast_add,Nat.cast_mul] + +theorem residue_tail_eq_image (J N z u : ℕ) [NeZero u] (e : ZMod u) + (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + (sieveTail J N z b step a).filter (fun j : ℕ => (j : ZMod u) = e) = + (ProgressionSmallSieve.progressionSurvivors (hitLength (N-J) u (residueOffset J u e+1)) z + (b+(step : ℤ)*((J+residueOffset J u e : ℕ) : ℤ)) (step*u) a).image + (fun i => J+residueOffset J u e+u*i) := by + classical + have hu : 0 < u := Nat.pos_of_ne_zero (NeZero.ne u) + have hr := residueOffset_lt J u e + have hlen : ∀ i : ℕ,i < hitLength (N-J) u (residueOffset J u e+1) ↔ + residueOffset J u e+u*i < N-J := by + intro i + rw [lt_hitLength_iff (N-J) u _ i hu (by omega)] + omega + ext j + simp only [Finset.mem_filter,sieveTail,SievePartition.mem_survivors,Finset.mem_Ico, + Finset.mem_image,ProgressionSmallSieve.progressionSurvivors,Finset.mem_range, + progressionHit_stride,hlen] + constructor + · rintro ⟨⟨⟨hJj,hjN⟩,ha⟩,hje⟩ + obtain ⟨i,rfl⟩ := residue_coordinate_exists J j u e hJj hje + exact ⟨i,⟨by omega,ha⟩,rfl⟩ + · rintro ⟨i,⟨hi,ha⟩,rfl⟩ + exact ⟨⟨⟨by omega,by omega⟩,ha⟩,residue_coordinate_hit J u i e⟩ + +theorem residue_tail_card (J N z u : ℕ) [NeZero u] (e : ZMod u) + (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + ((sieveTail J N z b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card = + (ProgressionSmallSieve.progressionSurvivors (hitLength (N-J) u (residueOffset J u e+1)) z + (b+(step : ℤ)*((J+residueOffset J u e : ℕ) : ℤ)) (step*u) a).card := by + rw [residue_tail_eq_image,Finset.card_image_of_injective] + intro i j hij + exact Nat.eq_of_mul_eq_mul_left (Nat.pos_of_ne_zero (NeZero.ne u)) (Nat.add_left_cancel hij) + +end ErdosInverseTail + + + +namespace ErdosInverseTail +open NumberTheoryLean + +theorem residue_survivor_card_split (J N z u : ℕ) [NeZero u] (hJN : J ≤ N) + (e : ZMod u) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + ((ProgressionSmallSieve.progressionSurvivors N z b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card = + ((ProgressionSmallSieve.progressionSurvivors J z b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card+ + ((sieveTail J N z b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card := by + classical + have hset : (ProgressionSmallSieve.progressionSurvivors N z b step a).filter (fun j : ℕ => (j : ZMod u) = e) = + (ProgressionSmallSieve.progressionSurvivors J z b step a).filter (fun j : ℕ => (j : ZMod u) = e) ∪ + (sieveTail J N z b step a).filter (fun j : ℕ => (j : ZMod u) = e) := by + ext j + simp only [Finset.mem_filter,ProgressionSmallSieve.progressionSurvivors,sieveTail, + SievePartition.mem_survivors,Finset.mem_range,Finset.mem_Ico,Finset.mem_union] + constructor + · rintro ⟨⟨hj,ha⟩,he⟩ + by_cases hh : j < J + · exact Or.inl ⟨⟨hh,ha⟩,he⟩ + · exact Or.inr ⟨⟨⟨by omega,hj⟩,ha⟩,he⟩ + · rintro (⟨⟨hj,ha⟩,he⟩ | ⟨⟨⟨_,hj⟩,ha⟩,he⟩) + · exact ⟨⟨lt_of_lt_of_le hj hJN,ha⟩,he⟩ + · exact ⟨⟨hj,ha⟩,he⟩ + rw [hset,Finset.card_union_of_disjoint] + apply Finset.disjoint_left.mpr + intro j hj ht + have hjJ := Finset.mem_range.mp (SievePartition.mem_survivors.mp (Finset.mem_filter.mp hj).1).1 + have hJj := (Finset.mem_Ico.mp (SievePartition.mem_survivors.mp (Finset.mem_filter.mp ht).1).1).1 + omega + +theorem residue_count_difference (J N z u : ℕ) [NeZero u] (hJN : J ≤ N) + (e : ZMod u) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + |(((ProgressionSmallSieve.progressionSurvivors N z b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card : ℝ)- + (((ProgressionSmallSieve.progressionSurvivors J z b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card : ℝ)| = + ((sieveTail J N z b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card := by + rw [residue_survivor_card_split J N z u hJN e b step a,Nat.cast_add,add_sub_cancel_left, + abs_of_nonneg (Nat.cast_nonneg _)] + +end ErdosInverseTail + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueFibres.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueFibres.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7a735e3c266ca22db6b32e082a60a7595fc8571 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueFibres.lean @@ -0,0 +1,57 @@ +import Mathlib.GroupTheory.Index +import OAI.NumberTheory.Jacobsthal.Primes.PrimePowerStationarity + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosKloosterman.PrimePower + +attribute [local instance] Classical.decEq + +private theorem card_mul_fibre {A B : Type*} [AddGroup A] [Fintype A] + [AddGroup B] [Fintype B] (f : A →+ B) (hf : Function.Surjective f) (b : B) : + Fintype.card B * ((Finset.univ : Finset A).filter fun x => f x = b).card = + Fintype.card A := by + calc + _ = ∑ _y : B, ((Finset.univ : Finset A).filter fun x => f x = b).card := by simp + _ = ∑ y : B, ((Finset.univ : Finset A).filter fun x => f x = y).card := by + apply Finset.sum_congr rfl + intro y _ + exact AddMonoidHom.card_fiber_eq_of_mem_range f (hf b) (hf y) + _ = _ := by + rw [Finset.sum_card_fiberwise_eq_card_filter] + simp + +def reduction (n d : ℕ) : ZMod (n*d) →+* ZMod d := + ZMod.castHom (dvd_mul_left d n) (ZMod d) + +theorem reduction_fibre_card (n d : ℕ) [NeZero n] [NeZero d] (y : ZMod d) : + ((Finset.univ : Finset (ZMod (n*d))).filter fun x => reduction n d x = y).card = n := by + have hf : Function.Surjective (reduction n d) := + ZMod.castHom_surjective (dvd_mul_left d n) + have hc := card_mul_fibre (reduction n d).toAddMonoidHom hf y + simp only [ZMod.card] at hc + apply Nat.eq_of_mul_eq_mul_left (NeZero.pos d) + convert hc.trans (Nat.mul_comm n d) using 1 + congr 2 + ext x + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + rfl + +theorem reduction_preimage_card (n d : ℕ) [NeZero n] [NeZero d] (S : Finset (ZMod d)) : + ((Finset.univ : Finset (ZMod (n*d))).filter fun x => reduction n d x ∈ S).card = + S.card * n := by + rw [← Finset.sum_card_fiberwise_eq_card_filter] + simp only [reduction_fibre_card, Finset.sum_const, nsmul_eq_mul, Nat.cast_id] + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueGCDBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueGCDBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..1ed60f304509a70d6cdc69638aac9a79a6b1030a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueGCDBounds.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UnitCyclicBounds + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHyperbolaError + +theorem gcd_three_le_second (N x y : ℕ) (hN : 0 < N) : + Nat.gcd N (Nat.gcd x y) ≤ Nat.gcd y N := by + apply Nat.le_of_dvd (Nat.gcd_pos_of_pos_right y hN) + exact Nat.dvd_gcd ((Nat.gcd_dvd_right N (Nat.gcd x y)).trans (Nat.gcd_dvd_right x y)) + (Nat.gcd_dvd_left N (Nat.gcd x y)) + +theorem gcd_natCast_val (N : ℕ) [NeZero N] (x : ℕ) : + Nat.gcd ((x : ZMod N).val) N = Nat.gcd x N := by + rw [ZMod.val_natCast, ← Nat.gcd_rec, Nat.gcd_comm N] + +theorem gcd_shift_le (H T x j : ℕ) (hH : 0 < H) (hT : 0 < T) : + Nat.gcd (x+H*j) (H*T) ≤ T * Nat.gcd x (H*T) := by + let g := Nat.gcd (x+H*j) (H*T) + have hgx : g ∣ x+H*j := Nat.gcd_dvd_left _ _ + have hgN : g ∣ H*T := Nat.gcd_dvd_right _ _ + have hsum : g ∣ T*(x+H*j) := dvd_mul_of_dvd_right hgx T + have hNj : g ∣ (H*T)*j := dvd_mul_of_dvd_left hgN j + have he : T*(x+H*j) = T*x+(H*T)*j := by ring + rw [he] at hsum + have hTx : g ∣ T*x := (Nat.dvd_add_iff_left hNj).mpr hsum + have hTN : g ∣ T*(H*T) := dvd_mul_of_dvd_right hgN T + have hd : g ∣ T*Nat.gcd x (H*T) := by + simpa only [Nat.gcd_mul_left] using Nat.dvd_gcd hTx hTN + exact Nat.le_of_dvd (mul_pos hT (Nat.gcd_pos_of_pos_right x (mul_pos hH hT))) hd + +theorem shifted_gcd_le (H T : ℕ) [NeZero H] [NeZero T] + (h : ZMod (H*T)) (j : ZMod T) : + Nat.gcd (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))).val (H*T) ≤ + T*Nat.gcd h.val (H*T) := by + have he : h+(H : ZMod (H*T))*(j.val : ZMod (H*T)) = + ((h.val+H*j.val : ℕ) : ZMod (H*T)) := by simp + rw [he, gcd_natCast_val] + exact gcd_shift_le H T h.val j.val (NeZero.pos H) (NeZero.pos T) + +end ErdosHyperbolaError + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueProjection.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueProjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..f0d87c14f786bb0b8eb89e7faa89d49262905403 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueProjection.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeEventCounting + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceMoments +open ErdosVarianceSmallModel + +theorem cast_nat_residue (M t n : ℕ) [NeZero M] (htM : t ∣ M) : + (((n : ZMod M).val : ℕ) : ZMod t) = (n : ZMod t) := by + have hh : Nat.ModEq M (n : ZMod M).val n := (ZMod.natCast_eq_natCast_iff _ _ _).mp + (ZMod.natCast_zmod_val (n : ZMod M)) + exact (ZMod.natCast_eq_natCast_iff _ _ _).mpr (Nat.ModEq.of_dvd htM hh) + +theorem int_isCoprime_of_natAbs (m : ℤ) (H : ℕ) (hm : m.natAbs.Coprime H) : IsCoprime m (H : ℤ) := by + apply Int.isCoprime_iff_gcd_eq_one.mpr + simpa only [Int.gcd_def,Int.natAbs_natCast] using hm.gcd_eq_one + +noncomputable def divisorPhase (C0 m : ℤ) (t : ℕ) : ZMod t := (C0 : ZMod t)*(m : ZMod t)⁻¹ + +noncomputable def patternPValue (w : ℝ) (H : ℕ) (s : Pattern w H) (t : ℕ) : ZMod t := + (s.1.val.val : ZMod t) +noncomputable def patternKValue (w : ℝ) (H : ℕ) (s : Pattern w H) (t : ℕ) : ZMod t := + (s.2.val : ZMod t) + +noncomputable def divisorPhaseUnit (H : ℕ) (C0 m : ℤ) (hC0 : Int.gcd C0 (H : ℤ) = 1) + (hm : m.natAbs.Coprime H) (t : ℕ) (htH : t ∣ H) : (ZMod t)ˣ := + (ZMod.unitOfIsCoprime C0 (int_isCoprime_of_natAbs C0 t (by + have hc : C0.natAbs.Coprime H := by + rw [Nat.coprime_iff_gcd_eq_one] + simpa only [Int.gcd_def,Int.natAbs_natCast] using hC0 + exact hc.of_dvd_right htH))) * + (ZMod.unitOfIsCoprime m (int_isCoprime_of_natAbs m t (hm.of_dvd_right htH)))⁻¹ + +theorem divisorPhaseUnit_coe (H : ℕ) (C0 m : ℤ) (hC0 : Int.gcd C0 (H : ℤ) = 1) + (hm : m.natAbs.Coprime H) (t : ℕ) (htH : t ∣ H) : + (divisorPhaseUnit H C0 m hC0 hm t htH : ZMod t) = divisorPhase C0 m t := rfl + +theorem prime_divisorPhase_eq (P : Finset ℕ) (H : ℕ) (C0 : ℤ) (hP : ∀ p ∈ P,p.Prime) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (p : goodPrimes P H) (t : ℕ) (htH : t ∣ H) : + (p.val : ZMod t) = divisorPhase C0 (primeM P H C0 hP p) t := by + have hm := (primeM_coprime P H C0 hP hC0 p).of_dvd_right htH + have hminv := ZMod.coe_int_mul_inv_eq_one (int_isCoprime_of_natAbs _ t hm) + have hH0 : (H : ZMod t) = 0 := (ZMod.natCast_eq_zero_iff _ _).mpr htH + have he := congrArg (fun n : ℤ => (n : ZMod t)) (primeMK_identity P H C0 hP p) + have hEq : (p.val : ZMod t)*(primeM P H C0 hP p : ZMod t) = (C0 : ZMod t) := by + simpa only [Int.cast_mul,Int.cast_natCast,Int.cast_add,hH0,zero_mul,add_zero] using he + have hh := congrArg (fun x : ZMod t => x*(primeM P H C0 hP p : ZMod t)⁻¹) hEq + simpa only [mul_assoc,hminv,mul_one,divisorPhase] using hh + +theorem primePoint_pValue (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) (t : ℕ) (ht : t ∣ coprimeModulus w H) : + patternPValue w H (primePoint P w H C0 hw hP hlarge p).2 t = (p.val : ZMod t) := by + exact cast_nat_residue (coprimeModulus w H) t p.val ht + +theorem primePoint_kValue (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) (t : ℕ) (ht : t ∣ divisorModulus w H) : + patternKValue w H (primePoint P w H C0 hw hP hlarge p).2 t = (primeK P H C0 hP p : ZMod t) := by + exact cast_nat_residue (divisorModulus w H) t (primeK P H C0 hP p) ht + +end ErdosVarianceMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueSqrtSplit.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueSqrtSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..938c5f30e2c8b7cb4c824ab381fb4c133fa3b46e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueSqrtSplit.lean @@ -0,0 +1,459 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.AllCharacterLogPower +import OAI.NumberTheory.Jacobsthal.Primes.IntervalPrimesDefinition +import OAI.NumberTheory.Jacobsthal.Primes.PrimeCountAbel + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology BigOperators + +noncomputable def residuePsi {q : ℕ} (a : ZMod q) (X : ℝ) : ℝ := + ∑ n ∈ Finset.range (⌊X⌋₊+1), ArithmeticFunction.vonMangoldt.residueClass a n + +lemma residuePsi_character_sum {q : ℕ} [NeZero q] (a : ZMod q) (ha : IsUnit a) (X : ℝ) : + (residuePsi a X:ℂ) = (q.totient:ℂ)⁻¹ * + ∑ chi : DirichletCharacter ℂ q, chi a⁻¹ * + sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X := by + classical + unfold residuePsi + rw [Complex.ofReal_sum] + simp_rw [ArithmeticFunction.vonMangoldt.residueClass_apply ha] + rw [← Finset.mul_sum,Finset.sum_comm] + congr 1 + apply Finset.sum_congr rfl + intro chi _ + unfold sharpSum + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro n _ + ring + +lemma residuePsi_error_le {q : ℕ} [NeZero q] (a : ZMod q) (ha : IsUnit a) (X E : ℝ) + (herror : ∀ chi : DirichletCharacter ℂ q, + ‖sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0)‖ ≤ E) : + ‖(residuePsi a X:ℂ)-(X:ℂ)/(q.totient:ℂ)‖ ≤ E := by + classical + have hai : IsUnit a⁻¹ := isUnit_of_dvd_one ⟨a,(ZMod.inv_mul_of_unit a ha).symm⟩ + have hmain : (∑ chi : DirichletCharacter ℂ q, + chi a⁻¹ * (if chi=1 then (X:ℂ) else 0)) = (X:ℂ) := by + simp [MulChar.one_apply hai] + have hsum : (∑ chi : DirichletCharacter ℂ q, chi a⁻¹ * + (sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0))) = + (∑ chi : DirichletCharacter ℂ q, chi a⁻¹ * + sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X)-(X:ℂ) := by + simp_rw [mul_sub] + rw [Finset.sum_sub_distrib,hmain] + have he : (residuePsi a X:ℂ)-(X:ℂ)/(q.totient:ℂ) = + (q.totient:ℂ)⁻¹ * ∑ chi : DirichletCharacter ℂ q, chi a⁻¹ * + (sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0)) := by + rw [residuePsi_character_sum a ha X,hsum] + ring + have hcard : Fintype.card (DirichletCharacter ℂ q) = q.totient := by + simpa only [Nat.card_eq_fintype_card] using + (DirichletCharacter.card_eq_totient_of_hasEnoughRootsOfUnity ℂ q) + have hphi : (0:ℝ) < q.totient := by exact_mod_cast Nat.totient_pos.mpr (NeZero.pos q) + have hterm (chi : DirichletCharacter ℂ q) : + ‖chi a⁻¹ * (sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0))‖ ≤ E := by + rw [norm_mul] + have h := mul_le_mul_of_nonneg_right (chi.norm_le_one a⁻¹) + (norm_nonneg (sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0))) + simp only [one_mul] at h + exact h.trans (herror chi) + have hnorm : ‖∑ chi : DirichletCharacter ℂ q, chi a⁻¹ * + (sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0))‖ ≤ (q.totient:ℝ)*E := by + calc + _ ≤ ∑ chi : DirichletCharacter ℂ q, ‖chi a⁻¹ * + (sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0))‖ := norm_sum_le _ _ + _ ≤ ∑ _chi : DirichletCharacter ℂ q, E := Finset.sum_le_sum (fun chi _ => hterm chi) + _ = _ := by simp [hcard] + rw [he,norm_mul,norm_inv,Complex.norm_natCast] + calc + _ ≤ (q.totient:ℝ)⁻¹*((q.totient:ℝ)*E) := mul_le_mul_of_nonneg_left hnorm (by positivity) + _ = E := by rw [← mul_assoc,inv_mul_cancel₀ hphi.ne',one_mul] + +theorem residuePsi_log_power (A M : ℝ) (hA : 0 < A) (hM : 0 < M) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q] (a : ZMod q), + IsUnit a → (q:ℝ) ≤ (Real.log X)^A → + |residuePsi a X-X/(q.totient:ℝ)| ≤ K*X/(Real.log X)^M := by + obtain ⟨K,hK,hall⟩ := all_character_log_power A M hA hM + refine ⟨K,hK,?_⟩ + filter_upwards [hall] with X hX + intro q _ a ha hq + have h := residuePsi_error_le a ha X (K*X/(Real.log X)^M) (fun chi => hX q chi hq) + have he : ‖(residuePsi a X:ℂ)-(X:ℂ)/(q.totient:ℂ)‖ = + |residuePsi a X-X/(q.totient:ℝ)| := by + rw [show (q.totient:ℂ) = ((q.totient:ℝ):ℂ) by simp, + ← Complex.ofReal_div,← Complex.ofReal_sub,Complex.norm_real,Real.norm_eq_abs] + rwa [he] at h + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology BigOperators + +noncomputable def residuePrimeWeight {q : ℕ} (a : ZMod q) (n : ℕ) : ℝ := + if n.Prime then ArithmeticFunction.vonMangoldt.residueClass a n else 0 + +noncomputable def residueTheta {q : ℕ} (a : ZMod q) (X : ℝ) : ℝ := + ∑ n ∈ Finset.range (⌊X⌋₊+1), residuePrimeWeight a n + +lemma residuePrimeWeight_eq {q : ℕ} (a : ZMod q) (n : ℕ) : + residuePrimeWeight a n = if n.Prime ∧ (n:ZMod q)=a then Real.log n else 0 := by + classical + by_cases hp : n.Prime + · by_cases ha : (n:ZMod q)=a + · simp [residuePrimeWeight,ArithmeticFunction.vonMangoldt.residueClass,hp,ha, + ArithmeticFunction.vonMangoldt_apply_prime hp] + · simp [residuePrimeWeight,ArithmeticFunction.vonMangoldt.residueClass,hp,ha] + · simp [residuePrimeWeight,hp] + +lemma residuePsi_sub_theta_bounds {q : ℕ} (a : ZMod q) (X : ℝ) : + 0 ≤ residuePsi a X-residueTheta a X ∧ + residuePsi a X-residueTheta a X ≤ Chebyshev.psi X-Chebyshev.theta X := by + classical + rw [residuePsi,residueTheta,← Finset.sum_sub_distrib] + constructor + · apply Finset.sum_nonneg + intro n _ + unfold residuePrimeWeight + split_ifs + · simp only [sub_self,le_refl] + · simpa only [sub_zero] using ArithmeticFunction.vonMangoldt.residueClass_nonneg a n + · rw [Chebyshev.psi_eq_sum_Icc,Chebyshev.theta_eq_sum_Icc,Finset.sum_filter, + ← Finset.sum_sub_distrib,← Nat.range_succ_eq_Icc_zero] + apply Finset.sum_le_sum + intro n _ + unfold residuePrimeWeight + by_cases hp : n.Prime + · simp [hp,ArithmeticFunction.vonMangoldt_apply_prime hp] + · simpa only [hp,ite_false,sub_zero] using ArithmeticFunction.vonMangoldt.residueClass_le a n + +lemma eventually_sqrt_le_log_power (M : ℝ) : + ∀ᶠ X : ℝ in atTop, Real.sqrt X ≤ X/(Real.log X)^M := by + filter_upwards [eventually_log_rpow_le_self (2*M)] with X hX + have hXp : 0 < X := by linarith [hX.1] + have hL : 0 < Real.log X := Real.log_pos (by linarith [hX.1]) + have hp : 0 < (Real.log X)^M := Real.rpow_pos_of_pos hL _ + have hsq : ((Real.log X)^M)^2 ≤ X := by + rw [← Real.rpow_mul_natCast hL.le] + simpa only [Nat.cast_ofNat,mul_comm] using hX.2 + have hle : (Real.log X)^M ≤ Real.sqrt X := (Real.le_sqrt hp.le hXp.le).mpr hsq + apply (le_div_iff₀ hp).mpr + calc + _ ≤ Real.sqrt X*Real.sqrt X := mul_le_mul_of_nonneg_left hle (Real.sqrt_nonneg _) + _ = X := Real.mul_self_sqrt hXp.le + +theorem residueTheta_log_power (A M : ℝ) (hA : 0 < A) (hM : 0 < M) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q] (a : ZMod q), + IsUnit a → (q:ℝ) ≤ (Real.log X)^A → + |residueTheta a X-X/(q.totient:ℝ)| ≤ K*X/(Real.log X)^M := by + obtain ⟨K,hK,hpsi⟩ := residuePsi_log_power A M hA hM + obtain ⟨D,hD⟩ := Chebyshev.psi_sub_theta_le_mul_sqrt + let C : ℝ := max D 1 + have hC : 0 < C := lt_of_lt_of_le zero_lt_one (le_max_right _ _) + refine ⟨K+C,by positivity,?_⟩ + filter_upwards [hpsi,eventually_sqrt_le_log_power M] with X hX hsqrt + intro q _ a ha hq + have hgap := residuePsi_sub_theta_bounds a X + have hb : residuePsi a X-residueTheta a X ≤ C*X/(Real.log X)^M := by + calc + _ ≤ D*Real.sqrt X := hgap.2.trans (hD X) + _ ≤ C*Real.sqrt X := mul_le_mul_of_nonneg_right (le_max_left _ _) (Real.sqrt_nonneg _) + _ ≤ C*(X/(Real.log X)^M) := mul_le_mul_of_nonneg_left hsqrt hC.le + _ = _ := by ring + calc + _ ≤ |residuePsi a X-X/(q.totient:ℝ)|+|residuePsi a X-residueTheta a X| := by + have h := abs_sub_le (residueTheta a X) (residuePsi a X) (X/(q.totient:ℝ)) + rw [abs_sub_comm (residueTheta a X) (residuePsi a X),add_comm] at h + exact h + _ ≤ K*X/(Real.log X)^M+C*X/(Real.log X)^M := by + rw [abs_of_nonneg hgap.1] + exact add_le_add (hX q a ha hq) hb + _ = _ := by ring + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Finset _root_.MeasureTheory +open scoped Topology BigOperators + +lemma intervalPrimes_zero_eq {X : ℝ} (hX : 0 ≤ X) (q : ℕ) (r : ℤ) : + intervalPrimes 0 X q r = (range (⌊X⌋₊+1)).filter + (fun n:ℕ => n.Prime ∧ (n:ZMod q)=(r:ZMod q)) := by + classical + ext n + have hm : (n:ZMod q)=(r:ZMod q) ↔ Int.ModEq (q:ℤ) (n:ℤ) r := by + simpa using (ZMod.intCast_eq_intCast_iff (n:ℤ) r q) + rw [mem_intervalPrimes,mem_filter,mem_range,hm] + constructor + · rintro ⟨hp,_,hn,hr⟩ + refine ⟨Nat.lt_succ_of_le ((Nat.le_floor_iff hX).mpr ?_),hp,hr⟩ + simpa only [zero_add] using hn + · rintro ⟨hn,hp,hr⟩ + refine ⟨hp,by exact_mod_cast hp.pos,?_,hr⟩ + simpa only [zero_add] using (Nat.le_floor_iff hX).mp (Nat.le_of_lt_succ hn) + +lemma intervalPrimes_card_eq_sum_weight {X : ℝ} (hX : 0 ≤ X) (q : ℕ) (r : ℤ) : + ((intervalPrimes 0 X q r).card:ℝ) = + ∑ n ∈ Icc 0 ⌊X⌋₊, (Real.log n)⁻¹ * residuePrimeWeight (r:ZMod q) n := by + classical + rw [intervalPrimes_zero_eq hX,card_eq_sum_ones,Nat.range_succ_eq_Icc_zero,sum_filter] + push_cast + apply sum_congr rfl + intro n _ + rw [residuePrimeWeight_eq] + by_cases hp : n.Prime ∧ (n:ZMod q)=(r:ZMod q) + · have hl : Real.log (n:ℝ) ≠ 0 := Real.log_ne_zero_of_pos_of_ne_one + (by exact_mod_cast hp.1.pos) (by exact_mod_cast hp.1.ne_one) + simp [hp,hl] + · simp [hp] + +lemma residueTheta_kernel_integrable (q : ℕ) (a : ZMod q) (X : ℝ) : + IntegrableOn (fun t => residueTheta a t/(t*Real.log t^2)) (Set.Icc 2 X) volume := by + conv => arg 1; ext; rw [residueTheta,Nat.range_succ_eq_Icc_zero,div_eq_mul_one_div,mul_comm] + refine integrableOn_mul_sum_Icc _ (by norm_num) <| ContinuousOn.integrableOn_Icc ?_ + intro x hx + have hx0 : x ≠ 0 := by linarith [hx.1] + have hl0 : Real.log x ≠ 0 := (Real.log_pos (by linarith [hx.1])).ne' + have hd : x*Real.log x^2 ≠ 0 := mul_ne_zero hx0 (pow_ne_zero 2 hl0) + exact ContinuousAt.continuousWithinAt (by fun_prop) + +theorem intervalPrimes_card_eq_theta {X : ℝ} (hX : 2 ≤ X) (q : ℕ) (r : ℤ) : + ((intervalPrimes 0 X q r).card:ℝ) = + residueTheta (r:ZMod q) X/Real.log X + + ∫ t in 2..X, residueTheta (r:ZMod q) t/(t*Real.log t^2) := by + rw [intervalPrimes_card_eq_sum_weight (by linarith) q r] + rw [sum_mul_eq_sub_integral_mul₁ (residuePrimeWeight (r:ZMod q)) + (f := fun n => (Real.log n)⁻¹) (by simp [residuePrimeWeight]) + (by simp [residuePrimeWeight]),← intervalIntegral.integral_of_le hX] + · have hi (f : ℝ → ℝ) : + ∫ u in 2..X, deriv (fun x => (Real.log x)⁻¹) u*f u = + ∫ u in 2..X, f u * -(u*Real.log u^2)⁻¹ := + intervalIntegral.integral_congr fun u _ => by simp [field] + rw [hi] + simp only [residueTheta,Nat.range_succ_eq_Icc_zero,div_eq_mul_inv,mul_neg, + intervalIntegral.integral_neg,sub_neg_eq_add] + ring + · intro z hz + have hz0 : z ≠ 0 := by linarith [hz.1] + have hl0 : Real.log z ≠ 0 := (Real.log_pos (by linarith [hz.1])).ne' + fun_prop + · refine ContinuousOn.integrableOn_Icc fun z hz => ContinuousWithinAt.congr ?_ + (fun _ _ => Real.deriv_inv_log_apply) Real.deriv_inv_log_apply + have hz0 : z ≠ 0 := by linarith [hz.1] + have hl0 : Real.log z^2 ≠ 0 := pow_ne_zero 2 (Real.log_pos (by linarith [hz.1])).ne' + exact ContinuousAt.continuousWithinAt (by fun_prop) + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory +open scoped Topology BigOperators +open ErdosPrimeInputs.PrimeCountAbel (logarithmicIntegral mainKernel) + +noncomputable def residueErrorKernel {q : ℕ} (a : ZMod q) (t : ℝ) : ℝ := + residueTheta a t/(t*Real.log t^2)-mainKernel t/(q.totient:ℝ) + +lemma residueErrorKernel_integrable {q : ℕ} (a : ZMod q) {u v : ℝ} + (hu : 2 ≤ u) (huv : u ≤ v) : IntervalIntegrable (residueErrorKernel a) volume u v := by + apply IntervalIntegrable.sub + · apply (intervalIntegrable_iff_integrableOn_Icc_of_le huv).mpr + exact (residueTheta_kernel_integrable q a v).mono_set (Set.Icc_subset_Icc_left hu) + · exact (ErdosPrimeInputs.PrimeCountAbel.mainKernel_integrable hu huv).div_const _ + +lemma residueErrorKernel_eq {q : ℕ} (a : ZMod q) {t : ℝ} (ht : 0 < t) : + residueErrorKernel a t = (residueTheta a t-t/(q.totient:ℝ))/(t*Real.log t^2) := by + unfold residueErrorKernel mainKernel + field_simp + +theorem intervalPrimes_error_eq {X : ℝ} (hX : 2 ≤ X) (q : ℕ) (r : ℤ) : + ((intervalPrimes 0 X q r).card:ℝ)-logarithmicIntegral X/(q.totient:ℝ) = + 2/((q.totient:ℝ)*Real.log 2) + + (residueTheta (r:ZMod q) X-X/(q.totient:ℝ))/Real.log X + + ∫ t in 2..X, residueErrorKernel (r:ZMod q) t := by + have hli := _root_.Erdos970.integral_log_inv 2 X (by norm_num) hX + have hi : (∫ t in 2..X, residueErrorKernel (r:ZMod q) t) = + (∫ t in 2..X, residueTheta (r:ZMod q) t/(t*Real.log t^2)) - + (∫ t in 2..X, mainKernel t)/(q.totient:ℝ) := by + unfold residueErrorKernel + rw [intervalIntegral.integral_sub, + intervalIntegral.integral_div] + · exact (intervalIntegrable_iff_integrableOn_Icc_of_le hX).mpr + (residueTheta_kernel_integrable q _ X) + · exact (ErdosPrimeInputs.PrimeCountAbel.mainKernel_integrable (by norm_num) hX).div_const _ + rw [intervalPrimes_card_eq_theta hX,hi] + unfold logarithmicIntegral mainKernel + simp only [one_div] + rw [hli] + ring + +lemma residueTheta_nonneg {q : ℕ} (a : ZMod q) (t : ℝ) : 0 ≤ residueTheta a t := by + apply Finset.sum_nonneg + intro n _ + unfold residuePrimeWeight + split_ifs + · exact ArithmeticFunction.vonMangoldt.residueClass_nonneg a n + · exact le_refl 0 + +lemma residueTheta_le_theta {q : ℕ} (a : ZMod q) (t : ℝ) : + residueTheta a t ≤ Chebyshev.theta t := by + classical + rw [residueTheta,Chebyshev.theta_eq_sum_Icc,Finset.sum_filter,Nat.range_succ_eq_Icc_zero] + apply Finset.sum_le_sum + intro n _ + unfold residuePrimeWeight + by_cases hp : n.Prime + · simpa only [hp,ite_true,ArithmeticFunction.vonMangoldt_apply_prime hp] using + ArithmeticFunction.vonMangoldt.residueClass_le a n + · simp [hp] + +lemma residueErrorKernel_coarse {q : ℕ} [NeZero q] (a : ZMod q) {t : ℝ} (ht : 2 ≤ t) : + |residueErrorKernel a t| ≤ (Real.log 4+1)/(Real.log 2)^2 := by + have ht0 : 0 < t := by linarith + have hl : 0 < Real.log t := Real.log_pos (by linarith) + have hphi : (1:ℝ) ≤ q.totient := by exact_mod_cast Nat.totient_pos.mpr (NeZero.pos q) + have hdiv : t/(q.totient:ℝ) ≤ t := div_le_self ht0.le hphi + have hnum : |residueTheta a t-t/(q.totient:ℝ)| ≤ (Real.log 4+1)*t := by + calc + _ ≤ |residueTheta a t|+|t/(q.totient:ℝ)| := abs_sub _ _ + _ = residueTheta a t+t/(q.totient:ℝ) := by rw [abs_of_nonneg (residueTheta_nonneg a t),abs_of_nonneg (by positivity)] + _ ≤ Real.log 4*t+t := add_le_add ((residueTheta_le_theta a t).trans + (Chebyshev.theta_le_log4_mul_x ht0.le)) hdiv + _ = _ := by ring + rw [residueErrorKernel_eq a ht0,abs_div,abs_of_pos (by positivity : 0 < t*Real.log t^2)] + calc + _ ≤ ((Real.log 4+1)*t)/(t*Real.log t^2) := div_le_div_of_nonneg_right hnum (by positivity) + _ = (Real.log 4+1)/Real.log t^2 := by field_simp + _ ≤ _ := by + have hlog : Real.log 2 ≤ Real.log t := Real.log_le_log (by norm_num) ht + exact div_le_div_of_nonneg_left (by positivity) (by positivity) + (sq_le_sq₀ (Real.log_pos (by norm_num : (1:ℝ)<2)).le hl.le |>.mpr hlog) + +lemma residueErrorKernel_low_integral {q : ℕ} [NeZero q] (a : ZMod q) {Y : ℝ} (hY : 2 ≤ Y) : + |∫ t in 2..Y, residueErrorKernel a t| ≤ (Real.log 4+1)/(Real.log 2)^2*Y := by + have h := intervalIntegral.norm_integral_le_of_norm_le_const (a:=2) (b:=Y) + (f:=residueErrorKernel a) (C:=(Real.log 4+1)/(Real.log 2)^2) (fun t ht => by + rw [Set.uIoc_of_le hY] at ht + simpa only [Real.norm_eq_abs] using residueErrorKernel_coarse a ht.1.le) + rw [Real.norm_eq_abs,abs_of_nonneg (by linarith : 0 ≤ Y-2)] at h + exact h.trans (mul_le_mul_of_nonneg_left (by linarith) (by positivity)) + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter _root_.MeasureTheory +open scoped Topology + +lemma modulus_admissible_above_sqrt {A X t : ℝ} (hA : 0 < A) (hX : 3 ≤ Real.sqrt X) + (hlog : 2*(2:ℝ)^A ≤ Real.log X) (ht : Real.sqrt X ≤ t) {q : ℕ} + (hq : (q:ℝ) ≤ (Real.log X)^A) : + (q:ℝ) ≤ (Real.log t)^(A+1) := by + have hs : 0 < Real.sqrt X := by linarith + have hx0 : 0 ≤ X := (Real.sqrt_pos.mp hs).le + have ht3 : 3 ≤ t := hX.trans ht + have hl : 0 < Real.log t := Real.log_pos (by linarith) + have hcompare : Real.log X ≤ 2*Real.log t := by + have h : Real.log (Real.sqrt X) ≤ Real.log t := Real.log_le_log hs ht + rw [Real.log_sqrt hx0] at h + linarith + have hpow : (2:ℝ)^A ≤ Real.log t := by linarith + have hL : 0 ≤ Real.log X := le_trans (by positivity) hlog + calc + _ ≤ (Real.log X)^A := hq + _ ≤ (2*Real.log t)^A := Real.rpow_le_rpow hL hcompare hA.le + _ = (2:ℝ)^A*(Real.log t)^A := Real.mul_rpow (by norm_num) hl.le + _ ≤ Real.log t*(Real.log t)^A := mul_le_mul_of_nonneg_right hpow (by positivity) + _ = (Real.log t)^(A+1) := by rw [Real.rpow_add hl,Real.rpow_one]; ring + +lemma residueErrorKernel_upper_bound {q : ℕ} (a : ZMod q) {K M X t : ℝ} + (hK : 0 ≤ K) (hM : 0 < M) (hX : 3 ≤ Real.sqrt X) (ht : Real.sqrt X ≤ t) + (herror : |residueTheta a t-t/(q.totient:ℝ)| ≤ K*t/(Real.log t)^M) : + |residueErrorKernel a t| ≤ K*(2:ℝ)^M/(Real.log X)^M := by + have hs : 0 < Real.sqrt X := by linarith + have hx0 : 0 < X := Real.sqrt_pos.mp hs + have hx3 : 3 ≤ X := by nlinarith [Real.sq_sqrt hx0.le] + have ht3 : 3 ≤ t := hX.trans ht + have ht0 : 0 < t := by linarith + have hl1 : 1 ≤ Real.log t := + ((Real.lt_log_iff_exp_lt ht0).mpr (Real.exp_one_lt_three.trans_le ht3)).le + have hl : 0 < Real.log t := by linarith + have hL : 0 < Real.log X := Real.log_pos (by linarith) + have hcompare : Real.log X ≤ 2*Real.log t := by + have h : Real.log (Real.sqrt X) ≤ Real.log t := Real.log_le_log hs ht + rw [Real.log_sqrt hx0.le] at h + linarith + have hp : (Real.log X)^M ≤ (2:ℝ)^M*(Real.log t)^M := by + rw [← Real.mul_rpow (by norm_num : (0:ℝ)≤2) hl.le] + exact Real.rpow_le_rpow hL.le hcompare hM.le + rw [residueErrorKernel_eq a ht0,abs_div,abs_of_pos (by positivity : 0 < t*Real.log t^2)] + calc + _ ≤ (K*t/(Real.log t)^M)/(t*Real.log t^2) := + div_le_div_of_nonneg_right herror (by positivity) + _ = (K/(Real.log t)^M)/(Real.log t)^2 := by field_simp + _ ≤ K/(Real.log t)^M := div_le_self (by positivity) (by nlinarith) + _ ≤ _ := by + apply (div_le_div_iff₀ (by positivity : 0 < (Real.log t)^M) + (by positivity : 0 < (Real.log X)^M)).mpr + calc + _ ≤ K*((2:ℝ)^M*(Real.log t)^M) := mul_le_mul_of_nonneg_left hp hK + _ = _ := by ring + +lemma residueErrorKernel_high_integral {q : ℕ} (a : ZMod q) {K M X : ℝ} + (hK : 0 ≤ K) (hM : 0 < M) (hX : 3 ≤ Real.sqrt X) + (herror : ∀ t, Real.sqrt X ≤ t → + |residueTheta a t-t/(q.totient:ℝ)| ≤ K*t/(Real.log t)^M) : + |∫ t in Real.sqrt X..X, residueErrorKernel a t| ≤ + (K*(2:ℝ)^M)*X/(Real.log X)^M := by + have hs : 0 < Real.sqrt X := by linarith + have hx0 : 0 < X := Real.sqrt_pos.mp hs + have hsX : Real.sqrt X ≤ X := by nlinarith [Real.sq_sqrt hx0.le] + have hL : 0 < Real.log X := Real.log_pos (by nlinarith [Real.sq_sqrt hx0.le]) + have h := intervalIntegral.norm_integral_le_of_norm_le_const (a:=Real.sqrt X) (b:=X) + (f:=residueErrorKernel a) (C:=K*(2:ℝ)^M/(Real.log X)^M) (fun t ht => by + rw [Set.uIoc_of_le hsX] at ht + simpa only [Real.norm_eq_abs] using + residueErrorKernel_upper_bound a hK hM hX ht.1.le (herror t ht.1.le)) + rw [Real.norm_eq_abs,abs_of_nonneg (sub_nonneg.mpr hsX)] at h + calc + _ ≤ K*(2:ℝ)^M/(Real.log X)^M*(X-Real.sqrt X) := h + _ ≤ K*(2:ℝ)^M/(Real.log X)^M*X := + mul_le_mul_of_nonneg_left (sub_le_self _ (Real.sqrt_nonneg _)) (by positivity) + _ = _ := by ring + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueTailUpper.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueTailUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..345c3fcd41b26befcca15010b2921928b1d6650a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/ResidueTailUpper.lean @@ -0,0 +1,102 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueCountDifference + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseTail +open NumberTheoryLean + +theorem progressionSurvivors_mono (N M z : ℕ) (hNM : N ≤ M) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + ProgressionSmallSieve.progressionSurvivors N z b step a ⊆ + ProgressionSmallSieve.progressionSurvivors M z b step a := by + intro j hj + obtain ⟨hj,ha⟩ := SievePartition.mem_survivors.mp hj + exact SievePartition.mem_survivors.mpr ⟨Finset.mem_range.mpr ((Finset.mem_range.mp hj).trans_le hNM),ha⟩ + +theorem sieve_tail_upper (eta : ℝ) (heta : 0 < eta) : + ∃ C : ℝ,0 < C ∧ ∃ w0 : ℝ,2 ≤ w0 ∧ + ∀ (J N : ℕ) (w L : ℝ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ), + w0 ≤ w → w^eta ≤ L → ((N-J : ℕ) : ℝ) ≤ L → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → step.Coprime t) → + ((sieveTail J N ⌊w⌋₊ b step a).card : ℝ) ≤ C*L*SmallSieveFinite.smallEuler ⌊w⌋₊ := by + obtain ⟨C,hC,w0,hw0,hupper⟩ := SmallSieveUpper.progression_small_upper eta heta + refine ⟨C,hC,w0,hw0,?_⟩ + intro J N w L b step a hw hL hNL hcop + have hwpos : 0 < w := by linarith + have hLpos : 0 < L := (Real.rpow_pos_of_pos hwpos eta).trans_le hL + have hle : N-J ≤ ⌈L⌉₊ := by exact_mod_cast hNL.trans (Nat.le_ceil L) + have hround : |(⌈L⌉₊ : ℝ)-L| ≤ 1 := by + have hlo := Nat.le_ceil L + have hhi := Nat.ceil_lt_add_one hLpos.le + rw [abs_le] + constructor <;> linarith + rw [sieveTail_card] + calc + _ ≤ ((ProgressionSmallSieve.progressionSurvivors ⌈L⌉₊ ⌊w⌋₊ (b+(step : ℤ)*J) step a).card : ℝ) := by + exact_mod_cast Finset.card_le_card (progressionSurvivors_mono (N-J) ⌈L⌉₊ ⌊w⌋₊ hle _ step a) + _ ≤ _ := hupper ⌈L⌉₊ w L (b+(step : ℤ)*J) step a hw hL hround hcop + +theorem survivor_count_difference (J N z : ℕ) (hJN : J ≤ N) (b : ℤ) (step : ℕ) (a : ℕ → ℕ) : + |((ProgressionSmallSieve.progressionSurvivors N z b step a).card : ℝ)- + ((ProgressionSmallSieve.progressionSurvivors J z b step a).card : ℝ)| = + (sieveTail J N z b step a).card := by + rw [survivor_card_split J N z hJN b step a,Nat.cast_add,add_sub_cancel_left, + abs_of_nonneg (Nat.cast_nonneg _)] + +end ErdosInverseTail + +end + +section + +namespace ErdosInverseTail +open NumberTheoryLean ErdosInverseHits + +theorem residue_tail_upper (eta : ℝ) (heta : 0 < eta) : + ∃ C : ℝ,0 < C ∧ ∃ w0 : ℝ,2 ≤ w0 ∧ + ∀ (J N u : ℕ) [NeZero u] (e : ZMod u) (w L : ℝ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ), + w0 ≤ w → w^eta ≤ L/(u : ℝ) → ((N-J : ℕ) : ℝ) ≤ L → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (step*u).Coprime t) → + (((sieveTail J N ⌊w⌋₊ b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card : ℝ) ≤ + 2*C*(L/(u : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊ := by + obtain ⟨C,hC,w0,hw0,hupper⟩ := SmallSieveUpper.progression_small_upper eta heta + refine ⟨C,hC,w0,hw0,?_⟩ + intro J N u inst e w L b step a hw hL hNL hcop + have hu : 0 < u := Nat.pos_of_ne_zero (NeZero.ne u) + have huR : (0 : ℝ) < u := by exact_mod_cast hu + have hw1 : 1 ≤ w := by linarith + have hratio1 : 1 ≤ L/(u : ℝ) := (Real.one_le_rpow hw1 heta.le).trans hL + have hlong : w^eta ≤ 2*(L/(u : ℝ)) := hL.trans (by linarith) + have hlongpos : 0 < 2*(L/(u : ℝ)) := by linarith + have hr := residueOffset_lt J u e + have herr := hitLength_error (N-J) u (residueOffset J u e+1) hu (by omega) (by omega) + have hT : (hitLength (N-J) u (residueOffset J u e+1) : ℝ) ≤ 2*(L/(u : ℝ)) := by + have hh := (abs_le.mp herr).2 + have hdiv := div_le_div_of_nonneg_right hNL huR.le + linarith + have hle : hitLength (N-J) u (residueOffset J u e+1) ≤ ⌈2*(L/(u : ℝ))⌉₊ := by + exact_mod_cast hT.trans (Nat.le_ceil (2*(L/(u : ℝ)))) + have hround : |(⌈2*(L/(u : ℝ))⌉₊ : ℝ)-2*(L/(u : ℝ))| ≤ 1 := by + have hlo := Nat.le_ceil (2*(L/(u : ℝ))) + have hhi := Nat.ceil_lt_add_one hlongpos.le + rw [abs_le] + constructor <;> linarith + rw [residue_tail_card] + calc + _ ≤ ((ProgressionSmallSieve.progressionSurvivors ⌈2*(L/(u : ℝ))⌉₊ ⌊w⌋₊ + (b+(step : ℤ)*((J+residueOffset J u e : ℕ) : ℤ)) (step*u) a).card : ℝ) := by + exact_mod_cast Finset.card_le_card (progressionSurvivors_mono _ _ ⌊w⌋₊ hle _ (step*u) a) + _ ≤ C*(2*(L/(u : ℝ)))*SmallSieveFinite.smallEuler ⌊w⌋₊ := + hupper _ w _ _ (step*u) a hw hlong hround hcop + _ = _ := by ring + +end ErdosInverseTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/SieveScale.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/SieveScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..db0af7019408b3ce1b3b5addb722a9b5d012c5c7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/SieveScale.lean @@ -0,0 +1,175 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import OAI.NumberTheory.Jacobsthal.Primes.PrimeProductOmissions + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosPrimeInputs.AffinePrimeSieve + +open _root_.Finset +open NumberTheoryLean IntervalBoundingSieve SubsetPrimeSieve PrimeProductOmissions + +noncomputable def value (a : ℤ) (q i : ℕ) : ℤ := a + (q:ℤ)*i +noncomputable def survivors (N : ℕ) (a : ℤ) (q : ℕ) (P : Finset ℕ) : Finset ℕ := + (range N).filter (fun i => ∀ p ∈ P, ¬Int.ModEq (p:ℤ) (value a q i) 0) +noncomputable def primeIndices (N : ℕ) (a : ℤ) (q : ℕ) : Finset ℕ := + (range N).filter (fun i => (value a q i).natAbs.Prime ∧ 0 ≤ value a q i) +noncomputable def smallPrimeIndices (N : ℕ) (a : ℤ) (q : ℕ) (u : ℝ) : Finset ℕ := + (primeIndices N a q).filter (fun i => ((value a q i).natAbs : ℝ) ≤ u) + +theorem exists_coordinate_residues (N : ℕ) (a : ℤ) (q : ℕ) (P : Finset ℕ) + (hP : ∀ p ∈ P, p.Prime) (hcop : ∀ p ∈ P, q.Coprime p) : + ∃ r : ℕ → ℕ, survivors N a q P = residueAvoidingOffsets N (∏ p ∈ P, p) r := by + classical + have hc : ∀ p : ℕ, ∃ r : ℕ, p ∈ P → ∀ i : ℕ, + Int.ModEq (p:ℤ) (value a q i) 0 ↔ Nat.ModEq p i r := by + intro p + by_cases hp : p ∈ P + · obtain ⟨r,hr⟩ := ProgressionSmallSieve.exists_integer_affine_residue a q 0 (hP p hp) (hcop p hp) + exact ⟨r,fun _ i => hr i⟩ + · exact ⟨0,fun h => (hp h).elim⟩ + choose r hr using hc + refine ⟨r,?_⟩ + ext i + simp only [survivors,residueAvoidingOffsets,mem_filter,Nat.primeFactors_prod hP] + apply and_congr_right + intro _ + apply forall₂_congr + intro p hp + exact not_congr (hr p hp i) + +theorem affine_sieve_error (N : ℕ) (a : ℤ) (q : ℕ) (u s J : ℝ) (P : Finset ℕ) + (hu : 2 ≤ u) (hs : 480024 ≤ s) (hJ : 0 ≤ J) (hNJ : |(N:ℝ)-J| ≤ 1) + (hP : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, (p:ℝ) ≤ u) + (hcop : ∀ p ∈ P, q.Coprime p) : + |((survivors N a q P).card : ℝ) - J*euler P| ≤ + J*euler P*Real.exp (-s/96) + 2*u^s := by + obtain ⟨r,hr⟩ := exists_coordinate_residues N a q P hP hcop + rw [hr] + exact finite_subset_sieve_bound N u s J P r hu hs hJ hNJ hP hsize + +lemma natAbs_cast_of_nonneg {x : ℤ} (hx : 0 ≤ x) : (x.natAbs : ℤ) = x := by + simpa only [abs_of_nonneg hx] using Int.natCast_natAbs x + +theorem prime_above_survives (N : ℕ) (a : ℤ) (q : ℕ) (u : ℝ) (P : Finset ℕ) + (hP : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, (p:ℝ) ≤ u) + {i : ℕ} (hi : i ∈ primeIndices N a q) (hbig : u < ((value a q i).natAbs : ℝ)) : + i ∈ survivors N a q P := by + obtain ⟨hiN,hprime,hpos⟩ := mem_filter.mp hi + refine mem_filter.mpr ⟨hiN,?_⟩ + intro p hp hmod + have hd : (p:ℤ) ∣ value a q i := Int.modEq_zero_iff_dvd.mp hmod + rw [← natAbs_cast_of_nonneg hpos] at hd + have hdN : p ∣ (value a q i).natAbs := Int.natCast_dvd_natCast.mp hd + have heq : p = (value a q i).natAbs := ((hprime.dvd_iff_eq (hP p hp).ne_one).mp hdN).symm + have hle := hsize p hp + rw [heq] at hle + exact (not_lt_of_ge hle) hbig + +theorem value_injective (a : ℤ) {q : ℕ} (hq : 0 < q) : Function.Injective (value a q) := by + intro m n h + have hq0 : (q:ℤ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hq + have he : (m:ℤ)=(n:ℤ) := mul_left_cancel₀ hq0 (add_left_cancel h) + exact_mod_cast he + +theorem small_prime_count_le (N : ℕ) (a : ℤ) (q : ℕ) (u : ℝ) (hq : 0 < q) (hu : 0 ≤ u) : + ((smallPrimeIndices N a q u).card : ℝ) ≤ u := by + classical + let S := smallPrimeIndices N a q u + let f := fun i : ℕ => (value a q i).natAbs + have hinj : Set.InjOn f S := by + intro m hm n hn hmn + have hmpos := ((mem_filter.mp (mem_filter.mp hm).1).2).2 + have hnpos := ((mem_filter.mp (mem_filter.mp hn).1).2).2 + apply value_injective a hq + rw [← natAbs_cast_of_nonneg hmpos,← natAbs_cast_of_nonneg hnpos] + exact congrArg (fun v : ℕ => (v:ℤ)) hmn + have hsub : S.image f ⊆ Icc 1 ⌊u⌋₊ := by + intro y hy + obtain ⟨i,hi,rfl⟩ := mem_image.mp hy + obtain ⟨hip,hsmall⟩ := mem_filter.mp hi + have hprime := (mem_filter.mp hip).2.1 + exact mem_Icc.mpr ⟨hprime.pos,(Nat.le_floor_iff hu).mpr hsmall⟩ + have hc : S.card ≤ ⌊u⌋₊ := by + calc + _ = (S.image f).card := (card_image_iff.mpr hinj).symm + _ ≤ (Icc 1 ⌊u⌋₊).card := card_le_card hsub + _ = ⌊u⌋₊ := by simp + exact (show (S.card:ℝ) ≤ (⌊u⌋₊:ℝ) by exact_mod_cast hc).trans (Nat.floor_le hu) + +theorem prime_count_le_sifted_add (N : ℕ) (a : ℤ) (q : ℕ) (u : ℝ) (P : Finset ℕ) + (hq : 0 < q) (hu : 0 ≤ u) (hP : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, (p:ℝ) ≤ u) : + ((primeIndices N a q).card : ℝ) ≤ ((survivors N a q P).card : ℝ) + u := by + classical + have hsub : primeIndices N a q ⊆ survivors N a q P ∪ smallPrimeIndices N a q u := by + intro i hi + by_cases hsmall : ((value a q i).natAbs : ℝ) ≤ u + · exact mem_union.mpr (Or.inr (mem_filter.mpr ⟨hi,hsmall⟩)) + · exact mem_union.mpr (Or.inl (prime_above_survives N a q u P hP hsize hi (lt_of_not_ge hsmall))) + have hc : (primeIndices N a q).card ≤ (survivors N a q P).card + (smallPrimeIndices N a q u).card := + (card_le_card hsub).trans (card_union_le _ _) + calc + _ ≤ ((survivors N a q P).card:ℝ) + ((smallPrimeIndices N a q u).card:ℝ) := by exact_mod_cast hc + _ ≤ _ := add_le_add le_rfl (small_prime_count_le N a q u hq hu) + +end ErdosPrimeInputs.AffinePrimeSieve + +end + +section + +namespace ErdosPrimeInputs.SieveScale + +open _root_.Filter +open scoped Topology + +noncomputable def level : ℝ := 480024 +noncomputable def exponent : ℝ := 1 / (2*level) +noncomputable def cutoff (J : ℝ) : ℝ := J ^ exponent + +lemma exponent_pos : 0 < exponent := by norm_num [exponent,level] +lemma exponent_le_half : exponent ≤ 1/2 := by norm_num [exponent,level] + +lemma cutoff_tendsto : Tendsto cutoff atTop atTop := tendsto_rpow_atTop exponent_pos + +lemma cutoff_eventually_ge (u₀ : ℝ) : ∃ J₀ : ℝ, 1 < J₀ ∧ ∀ J : ℝ, J₀ ≤ J → u₀ ≤ cutoff J := by + obtain ⟨b,hb⟩ := eventually_atTop.mp (cutoff_tendsto.eventually (eventually_ge_atTop u₀)) + refine ⟨max 2 b,lt_of_lt_of_le (by norm_num) (le_max_left _ _),?_⟩ + intro J hJ + exact hb J ((le_max_right _ _).trans hJ) + +lemma cutoff_power {J : ℝ} (hJ : 0 ≤ J) : cutoff J ^ level = Real.sqrt J := by + rw [cutoff,← Real.rpow_mul hJ] + have h : exponent * level = 1/2 := by norm_num [exponent,level] + rw [h,Real.sqrt_eq_rpow] + +lemma log_cutoff {J : ℝ} (hJ : 0 < J) : Real.log (cutoff J) = exponent * Real.log J := + Real.log_rpow hJ exponent + +lemma cutoff_le_sqrt {J : ℝ} (hJ : 1 ≤ J) : cutoff J ≤ Real.sqrt J := by + rw [cutoff,Real.sqrt_eq_rpow] + exact Real.rpow_le_rpow_of_exponent_le hJ exponent_le_half + +lemma sqrt_le_log_scale {J : ℝ} (hJ : 1 < J) : Real.sqrt J ≤ 2*J/Real.log J := by + have hJ0 : 0 < J := by linarith + have hl0 := Real.log_pos hJ + have hs0 := Real.sqrt_pos.mpr hJ0 + have hs2 := Real.sq_sqrt hJ0.le + have hlog : Real.log J ≤ 2 * Real.sqrt J := by + have h := Real.log_le_sub_one_of_pos hs0 + rw [Real.log_sqrt hJ0.le] at h + linarith + apply (le_div_iff₀ hl0).mpr + nlinarith [mul_le_mul_of_nonneg_left hlog hs0.le] + +end ErdosPrimeInputs.SieveScale + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/SourcePairSieve.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/SourcePairSieve.lean new file mode 100644 index 0000000000000000000000000000000000000000..8cde849afa8a9993893a50af124287c68248c280 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/SourcePairSieve.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourcePairRemainder + +namespace OAI + +namespace Erdos970 + + +namespace ErdosVarianceLargeCount +open NumberTheoryLean ErdosHyperbolaError +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def siftedSourcePairs (H T0 T1 : ℕ) (C0 k0 p0 p1 m1 : ℤ) + (x0 x1 y0 y1 : ℝ) (lcI rcI lcJ rcJ : Bool) (P : Finset ℕ) : Finset (ℤ × ℤ) := + (sourcePairs H T0 T1 C0 k0 p0 p1 m1 1 x0 x1 y0 y1 lcI rcI lcJ rcJ).filter + (fun pm => ∀ t ∈ P,¬(t : ℤ) ∣ pm.1) + +theorem siftedSourcePairs_sum (H T0 T1 : ℕ) (C0 k0 p0 p1 m1 : ℤ) + (x0 x1 y0 y1 : ℝ) (lcI rcI lcJ rcJ : Bool) (P : Finset ℕ) : + ((siftedSourcePairs H T0 T1 C0 k0 p0 p1 m1 x0 x1 y0 y1 lcI rcI lcJ rcJ P).card : ℝ) = + ∑ pm ∈ sourcePairs H T0 T1 C0 k0 p0 p1 m1 1 x0 x1 y0 y1 lcI rcI lcJ rcJ, + (1 : ℝ)*BonferroniBlocks.survives P (fun t => (t : ℤ) ∣ pm.1) := by + rw [siftedSourcePairs,Finset.card_filter,Nat.cast_sum] + simp only [Nat.cast_ite,Nat.cast_one,Nat.cast_zero,one_mul,BonferroniBlocks.survives] + apply Finset.sum_congr rfl + intro pm _hpm + split_ifs <;> rfl + +theorem source_pair_sieve_upper (H T0 T1 : ℕ) (hH : 2 ≤ H) (hT0 : 0 < T0) (hT1 : 0 < T1) + (hSF : Squarefree T0) (hsupport : ∀ t : ℕ,t.Prime → t ∣ T0 → t ∣ H) + (hT1N : T1.Coprime (H*T0)) (C0 k0 p0 p1 m1 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (hp0 : Int.gcd p0 (T0 : ℤ) = 1) + (hp1 : Int.gcd p1 (T1 : ℤ) = 1) (P : Finset ℕ) (hP : ∀ t ∈ P,t.Prime) + (hPcop : ∀ t ∈ P,t.Coprime (H*T1)) (v s : ℝ) (hv : 2 ≤ v) (hs : 480024 ≤ s) + (hPv : ∀ t ∈ P,(t : ℝ) ≤ v) + (x0 x1 y0 y1 : ℝ) (hx : x0 ≤ x1) (hy : y0 ≤ y1) (lcI rcI lcJ rcJ : Bool) : + ((siftedSourcePairs H T0 T1 C0 k0 p0 p1 m1 x0 x1 y0 y1 lcI rcI lcJ rcJ P).card : ℝ) ≤ + sourceMain H T0 T1 (x1-x0) (y1-y0)*(∏ t ∈ P,(1-1/(t : ℝ)))*(1+Real.exp (-s/96))+ + ∑ d ∈ RealFundamentalSieve.levelDivisors P v s, + hyperbolaEnvelope H T0*(1+(x1-x0)/((d : ℝ)*((H*T0 : ℕ) : ℝ))+(y1-y0)/((H*T0 : ℕ) : ℝ)) := by + let C := sourcePairs H T0 T1 C0 k0 p0 p1 m1 1 x0 x1 y0 y1 lcI rcI lcJ rcJ + let X := sourceMain H T0 T1 (x1-x0) (y1-y0) + have hX : 0 ≤ X := by dsimp [X,sourceMain];positivity + have hf := RealFundamentalSieve.fundamental_lemma C (fun _ => 1) (fun _ _ => by norm_num) + (fun t pm => (t : ℤ) ∣ pm.1) v s P X (fun t => 1/(t : ℝ)) hv hs hX hP hPv + (fun _ _ => by positivity) (fun t _ => div_le_div_of_nonneg_right (by norm_num) (Nat.cast_nonneg t)) + (fun _ => by norm_num) + have hsq := IntervalBoundingSieve.squarefree_primeSet_product P hP + have hprodCop : (∏ t ∈ P,t).Coprime (H*T1) := Nat.coprime_prod_left_iff.mpr hPcop + have hrem : (∑ d ∈ RealFundamentalSieve.levelDivisors P v s, + |FundamentalBlockEstimate.integerRemainder C (fun _ => 1) (fun t pm => (t : ℤ) ∣ pm.1) X + (fun t => 1/(t : ℝ)) d|) ≤ + ∑ d ∈ RealFundamentalSieve.levelDivisors P v s, + hyperbolaEnvelope H T0*(1+(x1-x0)/((d : ℝ)*((H*T0 : ℕ) : ℝ))+(y1-y0)/((H*T0 : ℕ) : ℝ)) := by + apply Finset.sum_le_sum + intro d hd + have hdiv := Nat.dvd_of_mem_divisors (Finset.mem_filter.mp hd).1 + exact source_pair_remainder_bound H T0 T1 hH hT0 hT1 hSF hsupport hT1N C0 k0 p0 p1 m1 + hC0 hp0 hp1 d (hsq.squarefree_of_dvd hdiv) (hprodCop.of_dvd_left hdiv) + x0 x1 y0 y1 hx hy lcI rcI lcJ rcJ + rw [siftedSourcePairs_sum] + have hu := (abs_le.mp hf).2 + dsimp [C,X] at * + nlinarith + +end ErdosVarianceLargeCount + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/SurvivorResidueShift.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/SurvivorResidueShift.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d689e48b77e2e38b032b8ebc0ff4bfd80a1d36c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/SurvivorResidueShift.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualTagFreezing +import OAI.NumberTheory.Jacobsthal.Primes.LargePrimeDeletion + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SurvivorResidueShift +open SievePartition LargePrimeDeletion + +attribute [local instance] Classical.propDecidable + +def successorResidues (a : ℕ → ℕ) (p : ℕ) : ℕ := a p+1 + +theorem residueBad_successor (a : ℕ → ℕ) (p i : ℕ) : + residueBad (successorResidues a) p (i+1) ↔ residueBad a p i := by + change Nat.ModEq p (i+1) (a p+1) ↔ Nat.ModEq p i (a p) + exact ⟨Nat.ModEq.add_right_cancel' 1,Nat.ModEq.add_right 1⟩ + +theorem positive_survivors_image (Y z : ℕ) (a : ℕ → ℕ) : + residueCandidates Y ∅ (cutoffPrimes z) (successorResidues a)= + (cutoffSurvivors Y z a).image (fun i => i+1) := by + ext n + constructor + · intro hn + obtain ⟨hn1,hnY,_hreq,havoid⟩ := mem_residueCandidates.mp hn + obtain ⟨i,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n≠0) + apply Finset.mem_image.mpr + refine ⟨i,mem_cutoffSurvivors.mpr ⟨by omega,?_⟩,rfl⟩ + intro p hp hpz + have hh := havoid p (mem_cutoffPrimes.mpr ⟨hp,hpz⟩) + intro he + exact hh ((residueBad_successor a p i).mpr he) + · intro hn + obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp hn + obtain ⟨hiY,havoid⟩ := mem_cutoffSurvivors.mp hi + apply mem_residueCandidates.mpr + refine ⟨by omega,by omega,by simp,?_⟩ + intro p hp + have hh := mem_cutoffPrimes.mp hp + intro hb + exact havoid p hh.1 hh.2 ((residueBad_successor a p i).mp hb) + +theorem positive_survivors_card (Y z : ℕ) (a : ℕ → ℕ) : + (residueCandidates Y ∅ (cutoffPrimes z) (successorResidues a)).card= + (cutoffSurvivors Y z a).card := by + rw [positive_survivors_image] + apply Finset.card_image_iff.mpr + intro i _hi j _hj he + exact Nat.add_right_cancel he +end NumberTheoryLean.SurvivorResidueShift + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagCRTPeriodicity.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagCRTPeriodicity.lean new file mode 100644 index 0000000000000000000000000000000000000000..07eba2359e1b07f009186e2d43c87189e4d7add3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagCRTPeriodicity.lean @@ -0,0 +1,188 @@ +import OAI.NumberTheory.Jacobsthal.Primes.TagSmallPrimeData + +namespace OAI + +namespace Erdos970 + + +namespace ErdosStoppedTagSieve +open scoped BigOperators +attribute [local instance] Classical.decEq + +abbrev IntersectionIndex (T : Finset ℕ) := {t // t∈T} +def intersectionModuli (Q : ℕ) (T : Finset ℕ) : Option (IntersectionIndex T) → ℕ + | none => Q + | some t => t.val + +lemma intersection_moduli_product (Q : ℕ) (T : Finset ℕ) : + (∏ i,intersectionModuli Q T i)=Q*(∏ t∈T,t) := by + rw [Fintype.prod_option] + simp only [intersectionModuli] + congr 1 + exact Finset.prod_coe_sort T (fun t : ℕ => t) + +lemma intersection_moduli_pairwise (Q : ℕ) (T : Finset ℕ) + (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) : + Pairwise (fun i j => Nat.Coprime (intersectionModuli Q T i) (intersectionModuli Q T j)) := by + intro i j hij + cases i with + | none => + cases j with + | none => exact (hij rfl).elim + | some t => exact hQT t.val t.property + | some t => + cases j with + | none => exact (hQT t.val t.property).symm + | some u => + apply (hT t.val t.property).coprime_iff_not_dvd.mpr + intro hd + rcases (hT u.val u.property).eq_one_or_self_of_dvd t.val hd with he | he + · exact (hT t.val t.property).ne_one he + · exact hij (congrArg Option.some (Subtype.ext he)) + +noncomputable def baseClasses (Q : ℕ) (A : Finset ℕ) : Finset (ZMod Q) := + A.image (fun a : ℕ => (a:ZMod Q)) + +lemma baseClasses_card (Q : ℕ) (A : Finset ℕ) (hA : ∀ a∈A,a baseClasses Q A + | some t => {rho t.val} + +noncomputable def intersectionResidues (Q : ℕ) (T : Finset ℕ) (A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) : Finset ℕ := + ErdosUnitLifts.crtNat (intersectionModuli Q T) (intersection_moduli_pairwise Q T hT hQT) + (intersectionClasses Q T A rho) + +lemma intersection_moduli_pos (Q : ℕ) (hQ : 0 < Q) (T : Finset ℕ) (hT : ∀ t∈T,t.Prime) : + 0 < ∏ i,intersectionModuli Q T i := by + rw [intersection_moduli_product] + exact Nat.mul_pos hQ (Finset.prod_pos (fun t ht => (hT t ht).pos)) + +theorem mem_intersectionResidues (Q : ℕ) (hQ : 0 < Q) (T A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) + (hA : ∀ a∈A,a exact (mem_baseClasses Q A hA p).mpr hp + | some t => exact Finset.mem_singleton.mpr (h t.val t.property) + +theorem intersectionResidues_card (Q : ℕ) (hQ : 0 < Q) (T A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) + (hA : ∀ a∈A,a (hT t ht).pos)) + have hQd : Q∣M := dvd_mul_right Q _ + have hmodQ : (p%M)%Q=p%Q := Nat.mod_mod_of_dvd p hQd + have htmod (t : ℕ) (ht : t∈T) : ((p%M:ℕ):ZMod t)=(p:ZMod t) := by + have htd : t∣M := dvd_mul_of_dvd_right (Finset.dvd_prod_of_mem (fun t => t) ht) Q + exact (ZMod.natCast_eq_natCast_iff' _ _ _).mpr (Nat.mod_mod_of_dvd p htd) + rw [mem_intersectionResidues Q hQ T A rho hT hQT hA] + change p%M intro h t ht + · simpa only [htmod t ht] using h t ht + · simpa only [htmod t ht] using h t ht + +lemma totient_prime_product (T : Finset ℕ) (hT : ∀ t∈T,t.Prime) : + (∏ t∈T,t).totient=∏ t∈T,(t-1) := by + classical + induction T using Finset.induction_on with + | empty => simp + | @insert t T ht ih => + have htp : t.Prime := hT t (Finset.mem_insert_self _ _) + have hTp : ∀ p∈T,p.Prime := fun p hp => hT p (Finset.mem_insert_of_mem hp) + have hc : t.Coprime (∏ p∈T,p) := by + apply Nat.coprime_prod_right_iff.mpr + intro p hp + apply htp.coprime_iff_not_dvd.mpr + intro hd + rcases (hTp p hp).eq_one_or_self_of_dvd t hd with he | he + · exact htp.ne_one he + · exact ht (he.symm ▸ hp) + rw [Finset.prod_insert ht,Nat.totient_mul hc,Nat.totient_prime htp,ih hTp,Finset.prod_insert ht] + +theorem totient_intersection_modulus (Q : ℕ) (T : Finset ℕ) + (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) : + (Q*(∏ t∈T,t)).totient=Q.totient*(∏ t∈T,(t-1)) := by + rw [Nat.totient_mul (Nat.coprime_prod_right_iff.mpr hQT),totient_prime_product T hT] + +end ErdosStoppedTagSieve + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagPrimeSieveLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagPrimeSieveLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..4c380e36d8efac3d5f08cd8646c6ed9fffec7763 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagPrimeSieveLower.lean @@ -0,0 +1,98 @@ +import OAI.NumberTheory.Jacobsthal.Paths.TagAffineConditions + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedTagSieve + +open _root_.Filter +open scoped Topology +open ErdosUnitLifts Erdos970Dependency.SiegelWalfisz + +theorem tag_prime_sieve_lower (Cs K rho xi gamma : ℝ) + (hCs : 0 ≤ Cs) (hK : 0 < K) (hrho : 1 < rho) (hxi : 0 < xi) (hgamma : 0 < gamma) : + ∃ w₀ : ℝ,3 ≤ w₀ ∧ ∀ w P R V : ℝ,w₀ ≤ w → + Real.exp (K*(Real.log w)^3) ≤ P → P ≤ Real.exp ((rho*K)*(Real.log w)^3) → + Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ R → + xi/(16*w^(2*Cs+10)) ≤ V/R → V/R ≤ w^(-(2*Cs+10)) → + ∀ D : ℕ,0 < D → (D:ℝ) ≤ w^Cs → ∀ A : ℤ,A.natAbs.Coprime D → + ∀ residue : ℕ → ℤ,∀ q d0 ell : ℕ,∀ m : ℤ, + (∀ t∈smallPrimeSet P,q.Coprime t) → 0 < d0 → + (∀ t∈d0.primeFactors,t∈unalignedPrimes P D A residue) → + ell.Prime → P<(ell:ℝ) → m.natAbs=d0*ell → + (1-gamma)*(((intervalPrimes R V 1 0).card:ℝ)/(D:ℝ))* + eulerWeight (restrictedPrimes P D A residue d0) ≤ + ((actualSurvivorPrimes P R V D A ((q:ℤ)*m) residue).card:ℝ) := by + have hcap : 0 ≤ rho*K := mul_nonneg (by linarith) hK.le + obtain ⟨WC,hWC⟩ := eventually_atTop.mp + (unit_lift_sieve_lower_eventually Cs (rho*K) xi gamma hCs hcap hxi hgamma) + obtain ⟨WD,hWD⟩ := eventually_atTop.mp (eventually_cutoff_dominates (max Cs 1) K hK) + obtain ⟨WT,hWT⟩ := eventually_atTop.mp (eventually_cutoff_le_subbin (rho*K)) + refine ⟨max 3 (max WC (max WD WT)),le_max_left _ _,?_⟩ + intro w P R V hw hPlow hPup hR hlo hhi D hD hDw A hAc residue q d0 ell m hq hd0 hsupport hell hellP hm + have hwAll : max WC (max WD WT) ≤ w := (le_max_right _ _).trans hw + have hCore := hWC w ((le_max_left _ _).trans hwAll) + have hwDt : max WD WT ≤ w := (le_max_right _ _).trans hwAll + have hDom := hWD w ((le_max_left _ _).trans hwDt) + have hTag := hWT w ((le_max_right _ _).trans hwDt) + have hw3 := hCore.1 + have hw1 : 1 ≤ w := by linarith + have hPow : w ≤ w^(max Cs 1) := Real.self_le_rpow_of_one_le hw1 (le_max_right _ _) + have hwP : w

(hInfo t ht).1) (fun t ht => (hInfo t ht).2.1) + (fun t ht => (hInfo t ht).2.2) + (fun t ht => forbiddenClass_ne_zero P D A B residue d0 hprofile t ht) + have hEq := actualSurvivorPrimes_eq_sieve P R V hPR D hD hDP A B residue d0 hd0 hsupport hprofile + rw [← hEq] at hCount + exact hCount + +lemma natAbs_of_signed_prime_multiple (d0 ell : ℕ) (m : ℤ) + (hm : m=(d0:ℤ)*ell ∨ m= -((d0:ℤ)*ell)) : m.natAbs=d0*ell := by + rcases hm with rfl | rfl + · rw [← Nat.cast_mul] + exact Int.natAbs_natCast _ + · rw [Int.natAbs_neg,← Nat.cast_mul] + exact Int.natAbs_natCast _ + +noncomputable def boundedSurvivorPrimes (Y : ℕ) (P R V : ℝ) (D : ℕ) (A B : ℤ) + (residue : ℕ → ℤ) : Finset ℕ := + (actualSurvivorPrimes P R V D A B residue).filter + (fun p => 1 ≤ actualN D A B p ∧ actualN D A B p ≤ (Y:ℤ)) + +theorem boundedSurvivorPrimes_eq (Y : ℕ) (P R V : ℝ) (D : ℕ) (A B : ℤ) (residue : ℕ → ℤ) + (hRange : ∀ p∈intervalPrimes R V 1 0,(D:ℤ)∣A+B*p → + 1 ≤ actualN D A B p ∧ actualN D A B p ≤ (Y:ℤ)) : + boundedSurvivorPrimes Y P R V D A B residue=actualSurvivorPrimes P R V D A B residue := by + apply Finset.filter_eq_self.mpr + intro p hp + obtain ⟨hp,hInt,_⟩ := Finset.mem_filter.mp hp + exact hRange p hp hInt + +end ErdosStoppedTagSieve + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagUnitSieveLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagUnitSieveLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..0020a916b8184a435637cfedf5dedb2d2da5aa03 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/TagUnitSieveLower.lean @@ -0,0 +1,334 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Paths.TagIntersectionError +import OAI.NumberTheory.Jacobsthal.Paths.TagRelativeAlgebra +import OAI.NumberTheory.Jacobsthal.Primes.TagSubbinPrimeLower +import OAI.NumberTheory.Jacobsthal.Sieve.EulerProductRatio + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedTagSieve + +open scoped BigOperators + +noncomputable def primeFactor (p : ℕ) : ℝ := 1-1/((p:ℝ)-1) +noncomputable def eulerWeight (S : Finset ℕ) : ℝ := ∏ p∈S,primeFactor p + +lemma shifted_nonneg (k : ℕ) : 0 ≤ (1:ℝ)-1/((k:ℝ)+2) := by + have hk : (0:ℝ) ≤ k := Nat.cast_nonneg k + have hh : (0:ℝ) < (k:ℝ)+2 := by positivity + have h := (div_le_one hh).mpr (show (1:ℝ) ≤ (k:ℝ)+2 by linarith) + linarith + +lemma shifted_le_one (k : ℕ) : (1:ℝ)-1/((k:ℝ)+2) ≤ 1 := by + have : (0:ℝ) ≤ 1/((k:ℝ)+2) := by positivity + linarith + +lemma shifted_product (N : ℕ) : + (∏ k∈Finset.range N,((1:ℝ)-1/((k:ℝ)+2)))=1/((N:ℝ)+1) := by + induction N with + | zero => norm_num + | succ N ih => + rw [Finset.prod_range_succ,ih] + push_cast + have h1 : (N:ℝ)+1 ≠ 0 := by positivity + have h2 : (N:ℝ)+2 ≠ 0 := by positivity + field_simp + ring + +theorem eulerWeight_lower (P : ℝ) (hP : 3 ≤ P) (S : Finset ℕ) + (hS : ∀ p∈S,3 ≤ p ∧ (p:ℝ) ≤ P) : 1/P ≤ eulerWeight S := by + classical + have hP0 : 0 ≤ P := by linarith + have hf : 3 ≤ ⌊P⌋₊ := (Nat.le_floor_iff hP0).mpr (by exact_mod_cast hP) + let N := ⌊P⌋₊-2 + have hsub : (S.image (fun p : ℕ => (p-3:ℕ)) : Finset ℕ) ⊆ Finset.range N := by + intro k hk + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hk + have hpl : p ≤ ⌊P⌋₊ := (Nat.le_floor_iff hP0).mpr (hS p hp).2 + have hp3 := (hS p hp).1 + apply Finset.mem_range.mpr + dsimp [N] + omega + have hnP : (N:ℝ)+1 ≤ P := by + dsimp [N] + rw [Nat.cast_sub (by omega)] + have hfl := Nat.floor_le hP0 + norm_num only [Nat.cast_ofNat] + linarith + have hprod := Finset.prod_le_prod_of_subset_of_le_one₀ hsub + (fun k _ => shifted_nonneg k) (fun k _ _ => shifted_le_one k) + have himage : (∏ k∈(S.image (fun p : ℕ => (p-3:ℕ)) : Finset ℕ),((1:ℝ)-1/((k:ℝ)+2)))=eulerWeight S := by + rw [Finset.prod_image (fun p hp q hq he => by have := (hS p hp).1; have := (hS q hq).1; omega)] + apply Finset.prod_congr rfl + intro p hp + dsimp [primeFactor] + rw [Nat.cast_sub (hS p hp).1] + norm_num only [Nat.cast_ofNat] + ring + rw [himage,shifted_product] at hprod + exact (one_div_le_one_div_of_le (by positivity) hnP).trans hprod + +end ErdosStoppedTagSieve + + + +namespace ErdosStoppedTagSieve + + +lemma primeFactor_nonneg (p : ℕ) (hp : 2 ≤ p) : 0 ≤ primeFactor p := by + have hpR : (2:ℝ) ≤ p := by exact_mod_cast hp + have hden : 0 < (p:ℝ)-1 := by linarith + have hh := (div_le_one hden).mpr (show (1:ℝ) ≤ (p:ℝ)-1 by linarith) + unfold primeFactor + linarith + +lemma primeFactor_le_one (p : ℕ) (hp : 2 ≤ p) : primeFactor p ≤ 1 := by + have hpR : (2:ℝ) ≤ p := by exact_mod_cast hp + have h : (0:ℝ) ≤ 1/((p:ℝ)-1) := div_nonneg (by norm_num) (by linarith) + unfold primeFactor + linarith + +lemma eulerWeight_nonneg (S : Finset ℕ) (hS : ∀ p∈S,2 ≤ p) : 0 ≤ eulerWeight S := + Finset.prod_nonneg (fun p hp => primeFactor_nonneg p (hS p hp)) + +lemma eulerWeight_le_one (S : Finset ℕ) (hS : ∀ p∈S,2 ≤ p) : eulerWeight S ≤ 1 := + Finset.prod_le_one₀ (fun p hp => primeFactor_nonneg p (hS p hp)) + (fun p hp => primeFactor_le_one p (hS p hp)) + +lemma eulerWeight_eq_zero_of_two (S : Finset ℕ) (hS : 2∈S) : eulerWeight S=0 := by + apply Finset.prod_eq_zero hS + norm_num [primeFactor] + +lemma odd_of_eulerWeight_ne_zero (S : Finset ℕ) (hS : ∀ p∈S,2 ≤ p) + (hne : eulerWeight S≠0) : ∀ p∈S,3 ≤ p := by + intro p hp + have hp2 := hS p hp + by_contra h + have he : p=2 := by omega + subst p + exact hne (eulerWeight_eq_zero_of_two S hp) + +lemma reciprocal_totient_density_le (p : ℕ) (hp : 2 ≤ p) : 1/((p:ℝ)-1) ≤ 2/(p:ℝ) := by + have hpR : (2:ℝ) ≤ p := by exact_mod_cast hp + apply (div_le_div_iff₀ (by linarith) (by linarith)).mpr + linarith + + + + + +open scoped BigOperators +open Erdos970Dependency.SiegelWalfisz +open NumberTheoryLean +attribute [local instance] Classical.propDecidable + +noncomputable def basePrimes (R V : ℝ) (Q : ℕ) (A : Finset ℕ) : Finset ℕ := + (intervalPrimes R V 1 0).filter (fun p => p%Q∈A) +noncomputable def survivorPrimes (R V : ℝ) (Q : ℕ) (S A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) : Finset ℕ := + (basePrimes R V Q A).filter (fun p => ∀ t∈S,(p:ZMod t)≠rho t) + +lemma actual_intersection_mass (R V : ℝ) (Q : ℕ) (T A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) : + BonferroniBlocks.intersectionMass (basePrimes R V Q A) (fun _ => 1) + (fun t p => (p:ZMod t)=rho t) T = ((intersectionPrimes R V Q T A rho).card:ℝ) := by + simp only [BonferroniBlocks.intersectionMass,BonferroniBlocks.intersectionValue,one_mul] + have he : (basePrimes R V Q A).filter (fun p => ∀ t∈T,(p:ZMod t)=rho t)=intersectionPrimes R V Q T A rho := by + ext p + simp only [basePrimes,intersectionPrimes,Finset.mem_filter] + tauto + rw [← he] + rw [Finset.natCast_card_filter (R := ℝ)] + apply Finset.sum_congr rfl + intro p _hp + split_ifs <;> rfl + +lemma actual_survivor_mass (R V : ℝ) (Q : ℕ) (S A : Finset ℕ) + (rho : (t : ℕ) → ZMod t) : + (∑ p∈basePrimes R V Q A, (1:ℝ)*BonferroniBlocks.survives S (fun t => (p:ZMod t)=rho t))= + ((survivorPrimes R V Q S A rho).card:ℝ) := by + simp only [BonferroniBlocks.survives,one_mul,survivorPrimes] + rw [Finset.natCast_card_filter (R := ℝ)] + apply Finset.sum_congr rfl + intro p _hp + split_ifs <;> rfl + +theorem finite_tag_sieve_error : + ∃ c C X₀ : ℝ,0 < c ∧ 0 < C ∧ 3 ≤ X₀ ∧ + ∀ R V : ℝ,X₀ ≤ R → 0 ≤ V → V ≤ R → ∀ Q : ℕ,0 < Q → + ∀ S A : Finset ℕ,∀ rho : (t : ℕ) → ZMod t, + (∀ t∈S,t.Prime) → (∀ t∈S,3 ≤ t) → (∀ t∈S,Q.Coprime t) → + (∀ a∈A,a 1/((t:ℝ)-1) + have hX : 0 ≤ X := by dsimp [X]; positivity + have hR0 : 0 ≤ R := by have := hX₀.trans hR; linarith + have hg : ∀ t∈S,0 ≤ g t := by + intro t ht + have htR : (3:ℝ) ≤ t := by exact_mod_cast hOdd t ht + exact div_nonneg (by norm_num) (by linarith) + have hdim : ∀ t∈S,g t ≤ 2/(t:ℝ) := fun t ht => reciprocal_totient_density_le t (by have := hOdd t ht; omega) + have htwo : 2∈S → g 2 ≤ 1/2 := by intro h; have := hOdd 2 h; omega + have hf := RealFundamentalSieve.fundamental_lemma (basePrimes R V Q A) (fun _ => 1) + (fun _ _ => by norm_num) (fun t p => (p:ZMod t)=rho t) u s S X g + (by linarith) hs hX hPrime hsize hg hdim htwo + have hEuler : (∏ t∈S,(1-g t))=eulerWeight S := rfl + rw [actual_survivor_mass,hEuler] at hf + have hRem : ∀ d∈RealFundamentalSieve.levelDivisors S u s, + |FundamentalBlockEstimate.integerRemainder (basePrimes R V Q A) (fun _ => 1) + (fun t p => (p:ZMod t)=rho t) X g d| ≤ (A.card:ℝ)*C*R*Real.exp (-c*cubeHeight R) := by + intro d hd + obtain ⟨hdP,hdL⟩ := Finset.mem_filter.mp hd + have hddiv := Nat.dvd_of_mem_divisors hdP + have hsq := IntervalBoundingSieve.squarefree_primeSet_product S hPrime + have hdsq := hsq.squarefree_of_dvd hddiv + have hsub : d.primeFactors ⊆ S := by + rw [← Nat.primeFactors_prod hPrime] + exact Nat.primeFactors_mono hddiv hsq.ne_zero + have hm : (Q*(∏ t∈d.primeFactors,t):ℕ) ≤ Real.exp (c*cubeHeight R) := by + rw [Nat.prod_primeFactors_of_squarefree hdsq,Nat.cast_mul] + exact (mul_le_mul_of_nonneg_left hdL (Nat.cast_nonneg Q)).trans hlevel + have hh := hAP R V hR hV hVR Q hQ d.primeFactors A rho + (fun t ht => hPrime t (hsub ht)) (fun t ht => hQS t (hsub ht)) + hA hAc (fun t ht => hrho t (hsub ht)) hm + unfold FundamentalBlockEstimate.integerRemainder BonferroniBlocks.intersectionRemainder + rw [actual_intersection_mass] + exact hh + have hSum : (∑ d∈RealFundamentalSieve.levelDivisors S u s, + |FundamentalBlockEstimate.integerRemainder (basePrimes R V Q A) (fun _ => 1) + (fun t p => (p:ZMod t)=rho t) X g d|) ≤ + (A.card:ℝ)*C*R*(u^s)*Real.exp (-c*cubeHeight R) := by + calc + _ ≤ ∑ _d∈RealFundamentalSieve.levelDivisors S u s, + (A.card:ℝ)*C*R*Real.exp (-c*cubeHeight R) := Finset.sum_le_sum hRem + _ = ((RealFundamentalSieve.levelDivisors S u s).card:ℝ)*((A.card:ℝ)*C*R*Real.exp (-c*cubeHeight R)) := by + rw [Finset.sum_const,nsmul_eq_mul] + _ ≤ (u^s)*((A.card:ℝ)*C*R*Real.exp (-c*cubeHeight R)) := + mul_le_mul_of_nonneg_right (SmallSieveFinite.realLevelDivisors_card_le S u s (by linarith)) (by positivity) + _ = _ := by ring + exact hf.trans (add_le_add le_rfl hSum) + +end ErdosStoppedTagSieve + + + +namespace ErdosStoppedTagSieve + +open _root_.Filter +open scoped Topology BigOperators +open Erdos970Dependency.SiegelWalfisz ErdosUnitLifts + +theorem unit_lift_sieve_lower_eventually (Cs K xi gamma : ℝ) + (hCs : 0 ≤ Cs) (hK : 0 ≤ K) (hxi : 0 < xi) (hgamma : 0 < gamma) : + ∀ᶠ w : ℝ in atTop,3 ≤ w ∧ ∀ P R V : ℝ,3 ≤ P → P ≤ Real.exp (K*(Real.log w)^3) → + Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ R → + xi/(16*w^(2*Cs+10)) ≤ V/R → V/R ≤ w^(-(2*Cs+10)) → + ∀ D : ℕ,0 < D → (D:ℝ) ≤ w^Cs → ∀ A B : ℤ,∀ residue : ℕ → ℤ, + IsUnit (A:ZMod D) → IsUnit (B:ZMod D) → ∀ S : Finset ℕ,∀ rho : (t : ℕ) → ZMod t, + (∀ t∈S,t.Prime) → (∀ t∈S,(t:ℝ) ≤ P) → (∀ t∈S,¬t∣D) → (∀ t∈S,rho t≠0) → + (1-gamma)*(((intervalPrimes R V 1 0).card:ℝ)/(D:ℝ))*eulerWeight S ≤ + ((survivorPrimes R V (D*radical D) S (actualClasses D A B residue) rho).card:ℝ) := by + obtain ⟨c,C,X₀,hc,hC,hX₀,hSieve⟩ := finite_tag_sieve_error + let s : ℝ := max 480024 (-96*Real.log (gamma/2)) + have hs : 480024 ≤ s := le_max_left _ _ + have hs0 : 0 ≤ s := by linarith + have hrel : Real.exp (-s/96) ≤ gamma/2 := by + have hh := le_max_right (480024:ℝ) (-96*Real.log (gamma/2)) + change -96*Real.log (gamma/2) ≤ s at hh + calc + _ ≤ Real.exp (Real.log (gamma/2)) := Real.exp_le_exp.mpr (by linarith) + _ = _ := Real.exp_log (by positivity) + obtain ⟨Wn,_hWn,hNlower⟩ := moving_subbin_prime_lower Cs xi hCs hxi + have hMod := eventually_moving_exponential_domination (2*Cs) s K c (by linarith) hs0 hK hc + have hRate := eventually_moving_error (4*Cs+10) (s+1) K c (64*C/xi) (gamma/2) + (by linarith) (by linarith) hK hc (by positivity) (by positivity) + filter_upwards [eventually_ge_atTop (max Wn X₀),hMod,hRate] with w hw hwMod hwRate + refine ⟨hwMod.1,?_⟩ + intro P R V hP hPcap hRscale hlo hhi D hD hDw A B residue hAunit hBunit S rho hPrime hsize hSD hrho + let Q := D*radical D + let Cls := actualClasses D A B residue + let N : ℝ := (intervalPrimes R V 1 0).card + have hw3 := hwMod.1 + have hw0 : 0 < w := by linarith + have hP0 : 0 < P := by linarith + have hD0 : (0:ℝ) < D := by exact_mod_cast hD + have hQ : 0 < Q := Nat.mul_pos hD (radical_pos D) + obtain ⟨hR0,hV0,hVR,hN,hN0⟩ := hNlower w R V ((le_max_left _ _).trans hw) hRscale hlo hhi + have hRw : w ≤ R := (moving_lower_ge_self (by linarith)).trans hRscale + have hRX : X₀ ≤ R := ((le_max_right _ _).trans hw).trans hRw + have hR3 : 3 ≤ R := hw3.trans hRw + have hL : 0 < Real.log R := Real.log_pos (by linarith) + have hWnonneg : 0 ≤ eulerWeight S := eulerWeight_nonneg S (fun t ht => (hPrime t ht).two_le) + by_cases hzero : eulerWeight S=0 + · rw [hzero,mul_zero] + exact Nat.cast_nonneg _ + have hOdd : ∀ t∈S,3 ≤ t := odd_of_eulerWeight_ne_zero S (fun t ht => (hPrime t ht).two_le) hzero + have hEW : 1/P ≤ eulerWeight S := eulerWeight_lower P hP S (fun t ht => ⟨hOdd t ht,hsize t ht⟩) + have hQS : ∀ t∈S,Q.Coprime t := by + intro t ht + have hdt := ((hPrime t ht).coprime_iff_not_dvd.mpr (hSD t ht)).symm + exact Nat.coprime_mul_iff_left.mpr ⟨hdt,Nat.Coprime.coprime_dvd_left (radical_dvd D) hdt⟩ + have hCls : ∀ a∈Cls,a + actualClasses_reduced D hD A B residue hAunit hBunit a ha + have hlevel : (Q:ℝ)*P^s ≤ Real.exp (c*cubeHeight R) := + (mul_le_mul_of_nonneg_right (lift_modulus_bound hw0 hD hDw) (Real.rpow_nonneg hP0.le s)).trans + (hwMod.2 P R (by linarith) hPcap hRscale) + have hf := hSieve R V hRX hV0.le hVR Q hQ S Cls rho hPrime hOdd hQS + (fun a ha => (hCls a ha).1) (fun a ha => (hCls a ha).2) hrho P s hP hs hsize hlevel + have hXeq : N*(Cls.card:ℝ)/(Q.totient:ℝ)=N/(D:ℝ) := by + calc + _ = N*((Cls.card:ℝ)/(Q.totient:ℝ)) := by ring + _ = N*(1/(D:ℝ)) := by rw [actualClasses_fraction_real D hD A B residue hBunit] + _ = _ := by ring + dsimp only at hf + change |((survivorPrimes R V Q S Cls rho).card:ℝ)-(N*(Cls.card:ℝ)/(Q.totient:ℝ))*eulerWeight S| ≤ _ at hf + rw [hXeq] at hf + have hNV : xi*R/(64*w^(2*Cs+10)*Real.log R) ≤ N := by + have hv := (le_div_iff₀ hR0).mp hlo + have hh := div_le_div_of_nonneg_right hv (show 0 ≤ 4*Real.log R by positivity) + have he : ((xi/(16*w^(2*Cs+10)))*R)/(4*Real.log R)=xi*R/(64*w^(2*Cs+10)*Real.log R) := by ring + rw [he] at hh + exact hh.trans hN + have hCard : (Cls.card:ℝ) ≤ D := by exact_mod_cast actualClasses_card_le D hD A B residue hBunit + have hrem := relative_remainder_bound (Cls.card:ℝ) (D:ℝ) (w^Cs) N (eulerWeight S) + (w^(2*Cs+10)) P (Real.log R) R C (P^s) (Real.exp (-c*cubeHeight R)) xi + (Nat.cast_nonneg _) hCard hD0 hDw (by positivity) hP0 hL hR0 hC.le + (Real.rpow_nonneg hP0.le s) (Real.exp_pos _).le hxi hNV hEW + have hwPower : (w^Cs)^2*w^(2*Cs+10)=w^(4*Cs+10) := by + rw [← Real.rpow_mul_natCast hw0.le,← Real.rpow_add hw0] + congr 1 + norm_num + ring + have hPPower : P*(P^s)=P^(s+1) := by rw [Real.rpow_add_one hP0.ne']; ring + have hshape : (64*C/xi)*(w^Cs)^2*w^(2*Cs+10)*P*(P^s)*Real.log R*Real.exp (-c*cubeHeight R)= + (64*C/xi)*w^(4*Cs+10)*P^(s+1)*Real.log R*Real.exp (-c*cubeHeight R) := by + calc + _ = (64*C/xi)*((w^Cs)^2*w^(2*Cs+10))*(P*(P^s))*Real.log R*Real.exp (-c*cubeHeight R) := by ring + _ = _ := by rw [hwPower,hPPower] + rw [hshape] at hrem + have hr := hwRate.2 P R (by linarith) hPcap hRscale + have hmu : 0 ≤ (N/(D:ℝ))*eulerWeight S := mul_nonneg (div_nonneg hN0.le hD0.le) hWnonneg + have hrem' := hrem.trans (mul_le_mul_of_nonneg_left hr hmu) + have hrel' := mul_le_mul_of_nonneg_left hrel hmu + have hAbs := hf.trans (add_le_add hrel' hrem') + have hLower := (abs_le.mp hAbs).1 + change (1-gamma)*(N/(D:ℝ))*eulerWeight S ≤ ((survivorPrimes R V Q S Cls rho).card:ℝ) + nlinarith + +end ErdosStoppedTagSieve + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Sieve/UniformExponentialOccupation.lean b/lean/OAI/NumberTheory/Jacobsthal/Sieve/UniformExponentialOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce582262c48e0d1746779f69f939ecb51145a980 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Sieve/UniformExponentialOccupation.lean @@ -0,0 +1,101 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.UncappedCompactMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.UniformExponentialOccupation + +attribute [local instance] Classical.propDecidable +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open UncappedCompactMass LiteralUniformPrimeTail LiteralPrimeOccupation +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +noncomputable def positiveGapEnvelope (c r : ℝ) : ℝ := if 2 ≤ r then Real.exp (-c*r) else 0 + +noncomputable def exponentialPrefixMass (c w ell : ℝ) (start : Node) : ℝ := + ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*positiveGapEnvelope c (terminal w start ps).gap + +theorem envelope_nonneg (c r : ℝ) : 0 ≤ positiveGapEnvelope c r := by + unfold positiveGapEnvelope + split_ifs <;> positivity + +theorem compact_tail_split {c : ℝ} (hc : 0 < c) (K w ell : ℝ) (start : Node) : + exponentialPrefixMass c w ell start ≤ compactPrefixMass K w ell start+ + ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*tailListReward c K w start ps := by + unfold exponentialPrefixMass compactPrefixMass + rw [← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro ps _hp + rw [← mul_add] + apply mul_le_mul_of_nonneg_left _ (prefixWeight_nonneg ps) + unfold positiveGapEnvelope tailListReward + by_cases hr : 2 ≤ (terminal w start ps).gap + · rw [ite_eq_left hr] + by_cases hK : (terminal w start ps).gap ≤ K + · rw [ite_eq_left ⟨hr,hK⟩,ite_eq_right (not_lt_of_ge hK)] + simpa only [add_zero] using Real.exp_le_one_iff.mpr + (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc.le) (by linarith)) + · rw [ite_eq_right (fun h => hK h.2),ite_eq_left (lt_of_not_ge hK),zero_add] + · rw [ite_eq_right hr,ite_eq_right (fun h => hr h.1),zero_add] + split_ifs <;> positivity + +theorem uniform_exponential_prefix_mass (ell c d : ℝ) (hell : 1 ≤ ell) (hc : 0 < c) (hd : 0 < d) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → B^2*exponentialPrefixMass c w ell start ≤ C := by + obtain ⟨M,BT,wT,hBT,hwT,htail⟩ := actual_uniform_original_prime_tail d c 1 hd hc (by norm_num) + let K : ℝ := 3*((M:ℝ)+1) + have hK : 3 ≤ K := by dsimp [K]; have hn := Nat.cast_nonneg (α:=ℝ) M; linarith + obtain ⟨CC,BC,wC,hCC,hBC,hwC,hcompact⟩ := uniform_uncapped_compact_mass K ell d hK hell hd + refine ⟨CC+1,max BC (max BT ell),max wC wT,by linarith, + hBC.trans_le (le_max_left _ _),hwC.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBC' : BC ≤ B := (le_max_left _ _).trans hB + have hBT' : BT ≤ B := ((le_max_left _ _).trans (le_max_right _ _)).trans hB + have hellB : ell ≤ B := ((le_max_right _ _).trans (le_max_right _ _)).trans hB + have hwC' : wC ≤ w := (le_max_left _ _).trans hw + have hwT' : wT ≤ w := (le_max_right _ _).trans hw + have ht := htail M le_rfl B w hBT' hwT' ell hell hellB hcomp start hi h199 h23 hcons hcut + have hcc := hcompact B w hBC' hwC' hcomp start hi h199 h23 hcons hcut + have hsplit := mul_le_mul_of_nonneg_left (compact_tail_split hc K w ell start) (sq_nonneg B) + dsimp only [K] at hsplit hcc + nlinarith + +theorem uniform_signed_exponential_rewards (ell c d : ℝ) (hell : 1 ≤ ell) (hc : 0 < c) (hd : 0 < d) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → ∀ A : ℝ,0 ≤ A → ∀ F : List ℕ → ℝ, + (∀ ps ∈ uncappedPrefixes w ell start,|F ps| ≤ A*positiveGapEnvelope c (terminal w start ps).gap) → + B^2*|∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps| ≤ A*C := by + obtain ⟨C,B₀,w₀,hC,hB₀,hw₀,h⟩ := uniform_exponential_prefix_mass ell c d hell hc hd + refine ⟨C,B₀,w₀,hC,hB₀,hw₀,?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut A hA F hF + have hmass := h B w hB hw hcomp start hi h199 h23 hcons hcut + have hab : |∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps| ≤ + A*exponentialPrefixMass c w ell start := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + rw [exponentialPrefixMass,Finset.mul_sum] + apply Finset.sum_le_sum + intro ps hp + rw [abs_mul,abs_of_nonneg (prefixWeight_nonneg ps)] + have hm := mul_le_mul_of_nonneg_left (hF ps hp) (prefixWeight_nonneg ps) + convert hm using 1 + ring + have hm := mul_le_mul_of_nonneg_left hab (sq_nonneg B) + have hfinal := mul_le_mul_of_nonneg_left hmass hA + nlinarith + +end NumberTheoryLean.UniformExponentialOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveFirstForm.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveFirstForm.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffe6b85889c69b2f0f6f1615eeff8b6c7e0523b0 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveFirstForm.lean @@ -0,0 +1,93 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationFirstForm +import OAI.NumberTheory.JointDickman.Arithmetic.AmplificationSmoothCutoff + +namespace OAI + +/-! # Restricting the Cauchy volume to the actual multiplier range -/ + +namespace JointDickman +open Finset + +noncomputable def activeFirstFormWeight (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + (T N : ℕ) (D : Finset ℕ) (m : ℕ) : ℝ := + if T*(∏ p ∈ D, p)*m < N then firstFormWeight B L τ C u D m else 0 + +noncomputable def activeFirstFormVolume (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) (T N : ℕ) : ℝ := + (∑ i ∈ (auxiliaryPrimes B).powerset ×ˢ range N, + activeFirstFormWeight B L τ C u T N i.1 i.2) / (N : ℝ) + +theorem firstFormInner_eq_zero_of_inactive (B L : ℕ) (τ C : ℝ) + (v : ℕ → ℕ → ℝ) (J : ℕ → ℂ) (T N : ℕ) + (hv : ∀ a c, v a c ≠ 0 → T*c ≤ a) (D : Finset ℕ) (m : ℕ) + (hm : ¬ T*(∏ p ∈ D, p)*m < N) : firstFormInner B L τ C v J N D m = 0 := by + classical + unfold firstFormInner + apply sum_eq_zero + intro A _ + dsimp only + split_ifs with h + · have hz : v (∏ p ∈ A, p) (∏ p ∈ D, p) = 0 := by + by_contra hn + have hle := Nat.mul_le_mul_right m (hv _ _ hn) + exact hm (hle.trans_lt h.1) + simp only [hz, mul_zero, Complex.ofReal_zero, zero_mul] + · rfl + +theorem activeFirstFormWeight_nonneg (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + (hu : ∀ c, 0 ≤ u c) (T N : ℕ) (D : Finset ℕ) (m : ℕ) : + 0 ≤ activeFirstFormWeight B L τ C u T N D m := by + unfold activeFirstFormWeight + split_ifs + · exact firstFormWeight_nonneg B L τ C u hu D m + · rfl + +/-- The Cauchy volume only counts multipliers permitted by the smooth +coefficient window, giving the factor 1/(Tc) in its later mean estimate. -/ +theorem firstDivisorForm_active_cauchy (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + (v : ℕ → ℕ → ℝ) (g J : ℕ → ℂ) (T N : ℕ) + (hu : ∀ c, 0 ≤ u c) (hg : ∀ m, ‖g m‖ ≤ 1) + (hv : ∀ a c, v a c ≠ 0 → T*c ≤ a) : + ‖firstDivisorForm B L τ C u v g J N‖^2 ≤ + activeFirstFormVolume B L τ C u T N * firstFormEnergy B L τ C u v J N := by + classical + have hp (D : Finset ℕ) (m : ℕ) : + (activeFirstFormWeight B L τ C u T N D m : ℂ) * star (g m) * + firstFormInner B L τ C v J N D m = + (firstFormWeight B L τ C u D m : ℂ) * star (g m) * + firstFormInner B L τ C v J N D m := by + unfold activeFirstFormWeight + split_ifs with hm + · rfl + · rw [firstFormInner_eq_zero_of_inactive B L τ C v J T N hv D m hm] + simp + have he (D : Finset ℕ) (m : ℕ) : + activeFirstFormWeight B L τ C u T N D m * ‖firstFormInner B L τ C v J N D m‖^2 = + firstFormWeight B L τ C u D m * ‖firstFormInner B L τ C v J N D m‖^2 := by + unfold activeFirstFormWeight + split_ifs with hm + · rfl + · rw [firstFormInner_eq_zero_of_inactive B L τ C v J T N hv D m hm] + simp + have h := normalized_weighted_complex_cauchy (ι := Finset ℕ × ℕ) + ((auxiliaryPrimes B).powerset ×ˢ range N) + (fun i => activeFirstFormWeight B L τ C u T N i.1 i.2) (fun i => star (g i.2)) + (fun i => firstFormInner B L τ C v J N i.1 i.2) + (fun i _ => activeFirstFormWeight_nonneg B L τ C u hu T N i.1 i.2) + (fun i _ => by simpa only [norm_star] using hg i.2) (N := (N : ℝ)) (Nat.cast_nonneg N) + simpa only [hp, he, firstDivisorForm, activeFirstFormVolume, firstFormEnergy, + Complex.ofReal_natCast] using h + +/-- The concrete bump has the required lower support condition. -/ +theorem amplificationBump_ratio_lower (T a c : ℕ) + (h : amplificationBump (((a : ℝ) / ((T : ℝ)*c))) ≠ 0) : T*c ≤ a := by + have hs := (amplificationBump_support h).1 + by_cases hc : T*c = 0 + · omega + have hc0 : (0 : ℝ) < (T : ℝ)*c := by exact_mod_cast (Nat.pos_of_ne_zero hc) + have ha := (lt_div_iff₀ hc0).mp hs + norm_num at ha + exact_mod_cast ha.le + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveVolumeBound.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveVolumeBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..716c3becf689417302c5ebc9bd3e6a0c1811a120 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveVolumeBound.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.JointDickman.Amplification.ActiveVolumeMajorant + +namespace OAI + +/-! # The active Cauchy volume is eventually at most 2 B / T -/ + +namespace JointDickman +open Filter Finset +open scoped Topology + +theorem activeVolumeMajorant_limit (B : ℕ) {T : ℕ} (hT : 0 < T) : + Tendsto (activeVolumeMajorant B T) atTop (nhds + (((∑ D ∈ (auxiliaryPrimes B).powerset, + coefficientWeight B (∏ p ∈ D, p)/(∏ p ∈ D, (p : ℝ))) * baseArithmeticResidueMean B)/(T : ℝ))) := by + have hlim : Tendsto (activeVolumeMajorant B T) atTop (nhds + (∑ D ∈ (auxiliaryPrimes B).powerset, coefficientWeight B (∏ p ∈ D, p) * + (baseArithmeticResidueMean B / ((T*(∏ p ∈ D, p) : ℕ) : ℝ)))) := by + apply tendsto_finsetSum + intro D hD + have hd : 0 < ∏ p ∈ D, p := prod_pos (fun p hp => + (auxiliaryPrimes_prime B p (mem_powerset.mp hD hp)).pos) + exact (mean_scaled_prefix (baseArithmeticResidueWeight_mean_tendsto B) (Nat.mul_pos hT hd)).const_mul _ + convert hlim using 1 + congr 1 + rw [sum_mul, sum_div] + apply sum_congr rfl + intro D hD + have hd : (∏ p ∈ D, (p : ℝ)) ≠ 0 := prod_ne_zero_iff.mpr (fun p hp => by + exact_mod_cast (auxiliaryPrimes_prime B p (mem_powerset.mp hD hp)).ne_zero) + have ht : (T : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hT) + rw [Nat.cast_mul, Nat.cast_prod] + field_simp + +theorem activeFirstFormVolume_bound {B : ℕ} (hB : 1 < B) (L : ℕ) (τ C : ℝ) + (u : ℕ → ℝ) {T : ℕ} (hT : 0 < T) (hu : ∀ c, u c ∈ Set.Icc (0 : ℝ) 1) : + ∀ᶠ N : ℕ in atTop, activeFirstFormVolume B L τ C u T N ≤ 2*(B : ℝ)/(T : ℝ) := by + have hBp : (0 : ℝ) < B := by exact_mod_cast (Nat.zero_lt_of_lt hB) + have hTp : (0 : ℝ) < T := by exact_mod_cast hT + have hb := div_le_div_of_nonneg_right (coefficient_harmonic_mul_residueMean_le hB) hTp.le + have hstrict : ((∑ D ∈ (auxiliaryPrimes B).powerset, + coefficientWeight B (∏ p ∈ D, p)/(∏ p ∈ D, (p : ℝ))) * baseArithmeticResidueMean B)/(T : ℝ) < + 2*(B : ℝ)/(T : ℝ) := by + apply lt_of_le_of_lt hb + rw [mul_div_assoc] + have := div_pos hBp hTp + linarith + filter_upwards [(activeVolumeMajorant_limit B hT).eventually (eventually_le_nhds hstrict)] with N hN + exact (activeFirstFormVolume_le_majorant B L τ C u hT N hu).trans hN + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveVolumeMajorant.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveVolumeMajorant.lean new file mode 100644 index 0000000000000000000000000000000000000000..35dda5f66636357c347554688a17fd63f9ebfef2 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ActiveVolumeMajorant.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.JointDickman.Amplification.ActiveFirstForm +import OAI.NumberTheory.JointDickman.Counting.ScaledPeriodicMeans +import OAI.NumberTheory.JointDickman.Amplification.IndependentRegularityLoss + +namespace OAI + +/-! # A periodic majorant for the active Cauchy volume -/ + +namespace JointDickman +open Finset + +noncomputable def activeVolumeMajorant (B T N : ℕ) : ℝ := + ∑ D ∈ (auxiliaryPrimes B).powerset, + coefficientWeight B (∏ p ∈ D, p) * + ((∑ m ∈ range (N/(T*(∏ p ∈ D, p))+1), baseArithmeticResidueWeight B m)/(N : ℝ)) + +theorem baseArithmeticResidueWeight_nonneg (B n : ℕ) : 0 ≤ baseArithmeticResidueWeight B n := by + unfold baseArithmeticResidueWeight residueBaseWeight + exact mul_nonneg (Real.rpow_nonneg (by unfold auxiliaryRatio; positivity) _) (by positivity) + +theorem arithmeticResidueWeight_le_base (B L : ℕ) (τ C : ℝ) (n : ℕ) : + arithmeticResidueWeight B L τ C n ≤ baseArithmeticResidueWeight B n := by + unfold arithmeticResidueWeight regularResidueWeight baseArithmeticResidueWeight + split_ifs + · rfl + · exact baseArithmeticResidueWeight_nonneg B n + +theorem active_residue_prefix_le (B L : ℕ) (τ C : ℝ) {d : ℕ} (hd : 0 < d) (N : ℕ) : + (∑ m ∈ range N, if d*m < N then arithmeticResidueWeight B L τ C m else 0) ≤ + ∑ m ∈ range (N/d+1), baseArithmeticResidueWeight B m := by + classical + have hs : (range N).filter (fun m => d*m < N) ⊆ range (N/d+1) := by + intro m hm + have hmul : m*d ≤ N := by simpa only [mul_comm] using (mem_filter.mp hm).2.le + have hdiv := (Nat.le_div_iff_mul_le hd).mpr hmul + exact mem_range.mpr (by omega) + rw [← sum_filter] + calc + _ ≤ ∑ m ∈ (range N).filter (fun m => d*m < N), baseArithmeticResidueWeight B m := + sum_le_sum (fun m _ => arithmeticResidueWeight_le_base B L τ C m) + _ ≤ _ := sum_le_sum_of_subset_of_nonneg hs (fun m _ _ => baseArithmeticResidueWeight_nonneg B m) + +theorem activeFirstFormVolume_le_majorant (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + {T : ℕ} (hT : 0 < T) (N : ℕ) (hu : ∀ c, u c ∈ Set.Icc (0 : ℝ) 1) : + activeFirstFormVolume B L τ C u T N ≤ activeVolumeMajorant B T N := by + classical + unfold activeFirstFormVolume activeVolumeMajorant + rw [sum_product, sum_div] + apply sum_le_sum + intro D hD + let c := ∏ p ∈ D, p + have hcpos : 0 < c := prod_pos (fun p hp => + (auxiliaryPrimes_prime B p (mem_powerset.mp hD hp)).pos) + have hs := active_residue_prefix_le B L τ C (Nat.mul_pos hT hcpos) N + have hc : u c * regularCoefficientWeight B L τ C c ≤ coefficientWeight B c := + (mul_le_of_le_one_left (regularCoefficientWeight_nonneg B L τ C c) (hu c).2).trans + (regularCoefficientWeight_le B L τ C c) + have he : (∑ m ∈ range N, activeFirstFormWeight B L τ C u T N D m) = + (u c * regularCoefficientWeight B L τ C c) * + ∑ m ∈ range N, if T*c*m < N then arithmeticResidueWeight B L τ C m else 0 := by + rw [mul_sum] + apply sum_congr rfl + intro m _ + unfold activeFirstFormWeight firstFormWeight + dsimp only [c] + split_ifs <;> simp only [mul_zero] + rw [he, mul_div_assoc] + apply mul_le_mul hc (div_le_div_of_nonneg_right hs (Nat.cast_nonneg N)) + · apply div_nonneg _ (Nat.cast_nonneg N) + apply sum_nonneg + intro m _ + split_ifs + · exact regularResidueWeight_nonneg B L τ C _ + · rfl + · exact coefficientWeight_nonneg B c + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticFluctuation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticFluctuation.lean new file mode 100644 index 0000000000000000000000000000000000000000..75f8f7af698fabce78d3071352aa96d8bfc1b629 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticFluctuation.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticForcedCost +import OAI.NumberTheory.JointDickman.Amplification.MaskedArithmeticFluctuation + +namespace OAI + +/-! # Removing the root-identification exceptions from the arithmetic kernel -/ + +namespace JointDickman +open Finset Filter PublishedInputs Classical +open scoped Topology + +noncomputable def actualCandidateCutError (B L T H M : ℕ) (τ C : ℝ) + (χ : BlockCandidateIndex M → ℝ) (u : ℕ) : ℝ := + kernelCutNorm (fun i k => actualCandidateKernel B L T H M τ C χ u i k- + latentCandidateKernel B L T H M τ C (fun i => coefficientPrimeSet B (u+(i.val+1))) χ i k) + +theorem actualCandidateCutError_eq_masked {B L T H M u : ℕ} {τ C : ℝ} + (hT : T ≤ auxiliaryCutoff B) (χ : BlockCandidateIndex M → ℝ) + (hf : ¬ ForcedCandidateHit B L T H M τ C (fun i => coefficientPrimeSet B (u+(i.val+1)))) + (ha : ¬ ActualCoefficientException B L T H M τ C u) + (hm : ¬ MaskedCoefficientException B L T H M τ C u) : + actualCandidateCutError B L T H M τ C χ u = + maskedDigitCutError B L T H M τ C χ (arithmeticFirstDigits B u) := by + have hk := actualCandidateKernel_eq_masked hT χ + (fun e he hw => hf ⟨e,he,hw⟩) ha hm + unfold actualCandidateCutError + rw [hk] + unfold maskedDigitCutError patternRootCutError + rw [residuePrimePatterns_arithmetic] + have hs : primePatternsSites (arithmeticPrimePatterns B M u) = + (fun i => coefficientPrimeSet B (u+(i.val+1))) := + funext (primePatternsSites_arithmetic B M u) + rw [hs] + have hd : arithmeticFirstDigits B u = (fun p : auxiliaryPrimes B => (u : ZMod p.val)) := by + funext p + let : NeZero p.val := ⟨(auxiliaryPrimes_prime B p.val p.property).ne_zero⟩ + exact primeDigits_first u + rw [hd] + +theorem actualCandidateCutError_pointwise {B L T H M u : ℕ} {τ C : ℝ} + (hT : T ≤ auxiliaryCutoff B) (χ : BlockCandidateIndex M → ℝ) + (hcap : actualCandidateCutError B L T H M τ C χ u ≤ (B : ℝ)^10) : + actualCandidateCutError B L T H M τ C χ u ≤ + maskedDigitCutError B L T H M τ C χ (arithmeticFirstDigits B u)+ + (B : ℝ)^10 * + ((if ForcedCandidateHit B L T H M τ C + (fun i => coefficientPrimeSet B (u+(i.val+1))) then 1 else 0)+ + (if ActualCoefficientException B L T H M τ C u then 1 else 0)+ + (if MaskedCoefficientException B L T H M τ C u then 1 else 0)) := by + have hg : 0 ≤ maskedDigitCutError B L T H M τ C χ (arithmeticFirstDigits B u) := + kernelCutNorm_nonneg _ + have hQ : 0 ≤ (B : ℝ)^10 := pow_nonneg (Nat.cast_nonneg B) _ + by_cases hf : ForcedCandidateHit B L T H M τ C + (fun i => coefficientPrimeSet B (u+(i.val+1))) + · simp only [hf,ite_true] + split_ifs <;> nlinarith + · by_cases ha : ActualCoefficientException B L T H M τ C u + · simp only [hf,ha,ite_false,ite_true] + split_ifs <;> nlinarith + · by_cases hm : MaskedCoefficientException B L T H M τ C u + · simp only [hf,ha,hm,ite_false,ite_true] + nlinarith + · rw [actualCandidateCutError_eq_masked hT χ hf ha hm] + simp only [hf,ha,hm,ite_false,mul_zero,add_zero,le_refl] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticLimit.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..91fbe299642722984b561a237d7d5a9f4cee5f2d --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticLimit.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.JointDickman.Amplification.ActualArithmeticMean + +namespace OAI + +/-! # Uniform decay of the arithmetic candidate root fluctuations -/ + +namespace JointDickman +open Filter +open scoped Topology + +noncomputable def arithmeticFluctuationError (K : ℝ) (B : ℕ) : ℝ := + K*(B : ℝ)^(-(7/200 : ℝ))+(B : ℝ)^10*conditionedRootError B+ + coefficientRootError B+10*(B : ℝ)^19/(auxiliaryCutoff B : ℝ)+4/(B : ℝ) + +theorem arithmeticFluctuationError_tendsto (K : ℝ) : + Tendsto (arithmeticFluctuationError K) atTop (𝓝 0) := by + have hr := (tendsto_rpow_neg_atTop (by norm_num : (0 : ℝ) < 7/200)).comp + tendsto_natCast_atTop_atTop + have hp := (polynomial_div_primeCutoff_tendsto_zero (k := 19) (by norm_num)).comp + tendsto_natCast_atTop_atTop + have hp' : Tendsto (fun B : ℕ => (B : ℝ)^19/(auxiliaryCutoff B : ℝ)) atTop (𝓝 0) := by + simpa only [Function.comp_def,auxiliaryCutoff,Nat.cast_pow] using hp + have hi : Tendsto (fun B : ℕ => 4/(B : ℝ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + have ht := ((((hr.const_mul K).add conditionedRootError_weighted_tendsto).add + coefficientRootError_tendsto).add (hp'.const_mul 10)).add hi + simp only [mul_zero,add_zero] at ht + convert ht using 1 + funext B + unfold arithmeticFluctuationError + simp only [Function.comp_def] + ring + +theorem forced_cost_polynomial {B M : ℕ} (hB : 2 ≤ B) (hM : M ≤ B^2) : + (B : ℝ)^10*(5*(M : ℝ)^3*(B : ℝ)^3/(Real.log 2*auxiliaryCutoff B)) ≤ + 10*(B : ℝ)^19/(auxiliaryCutoff B : ℝ) := by + have hP : (0 : ℝ) < auxiliaryCutoff B := by + exact_mod_cast (show 0 < auxiliaryCutoff B from pow_pos (by omega) _) + have hMr : (M : ℝ) ≤ (B : ℝ)^2 := by exact_mod_cast hM + have hlog : (1/2 : ℝ) ≤ Real.log 2 := by have h := Real.log_two_gt_d9; linarith + have hinv : 1/(Real.log 2*auxiliaryCutoff B) ≤ 2/(auxiliaryCutoff B : ℝ) := by + have hh : (auxiliaryCutoff B : ℝ)/2 ≤ Real.log 2*auxiliaryCutoff B := by nlinarith + exact (one_div_le_one_div_of_le (by positivity) hh).trans_eq (by ring) + calc + _ = 5*(B : ℝ)^10*(M : ℝ)^3*(B : ℝ)^3*(1/(Real.log 2*auxiliaryCutoff B)) := by ring + _ ≤ 5*(B : ℝ)^10*((B : ℝ)^2)^3*(B : ℝ)^3*(2/(auxiliaryCutoff B : ℝ)) := by gcongr + _ = _ := by ring + +theorem actual_arithmetic_fluctuation_decay + (hFord : PublishedInputs.FordUpperSieveInput) + (hMertens : PublishedInputs.PrimeReciprocalMertensInput) + {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∃ E : ℕ → ℝ, Tendsto E atTop (𝓝 0) ∧ + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T H M : ℕ), + 0 < T → (T : ℝ) ≤ Real.exp ((1/10 : ℝ)*B) → T ≤ auxiliaryCutoff B → + 0 < M → M ≤ B^2 → (M : ℝ) ≤ Real.exp B → + ∀ χ : BlockCandidateIndex M → ℝ, (∀ e, 0 ≤ χ e ∧ χ e ≤ 1) → + arithmeticSquareMean B (actualCandidateCutError B L T H M τ C χ) ≤ E B := by + obtain ⟨K,_,hbound⟩ := actual_arithmetic_fluctuation_bound hFord hMertens hL hτ hτsmall + refine ⟨arithmeticFluctuationError K,arithmeticFluctuationError_tendsto K,?_⟩ + filter_upwards [hbound,eventually_ge_atTop 2] with B hbound hB + intro C T H M hT hTs hTP hM0 hM hMexp χ hχ + exact (hbound C T H M hT hTs hTP hM0 hM hMexp χ hχ).trans + (by unfold arithmeticFluctuationError; linarith only [forced_cost_polynomial hB hM]) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticMean.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..421181d58d810aba99d0ebd11a8f8c8db3e3d2bf --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualArithmeticMean.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.JointDickman.Amplification.ActualArithmeticFluctuation +import OAI.NumberTheory.JointDickman.Counting.CoefficientErrorScale + +namespace OAI + +/-! # Vanishing arithmetic candidate fluctuations after all root exceptions -/ + +namespace JointDickman +open Finset Filter PublishedInputs Classical +open scoped Topology + +theorem actual_arithmetic_fluctuation_bound + (hFord : FordUpperSieveInput) (hMertens : PrimeReciprocalMertensInput) + {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T H M : ℕ), + 0 < T → (T : ℝ) ≤ Real.exp ((1/10 : ℝ)*B) → T ≤ auxiliaryCutoff B → + 0 < M → M ≤ B^2 → (M : ℝ) ≤ Real.exp B → + ∀ χ : BlockCandidateIndex M → ℝ, (∀ e, 0 ≤ χ e ∧ χ e ≤ 1) → + arithmeticSquareMean B (actualCandidateCutError B L T H M τ C χ) ≤ + K*(B : ℝ)^(-(7/200 : ℝ))+(B : ℝ)^10*conditionedRootError B+ + coefficientRootError B+ + (B : ℝ)^10*(5*(M : ℝ)^3*(B : ℝ)^3/(Real.log 2*auxiliaryCutoff B))+4/(B : ℝ) := by + obtain ⟨K,hK,hmask⟩ := masked_arithmetic_fluctuation_bound hFord hMertens hL hτ hτsmall + refine ⟨K,hK,?_⟩ + filter_upwards [hmask,arithmetic_forced_cost hL hτ hτsmall, + candidate_root_error_cap hL hτ hτsmall,blockCandidates_card hL hτ hτsmall, + eventually_ge_atTop 2] with B hmask hforced hcap hcount hB + intro C T H M hT hTs hTP hM0 hM hMexp χ hχ + have hTe : (T : ℝ) ≤ Real.exp B := hTs.trans (Real.exp_le_exp.mpr (by + have hBr := Nat.cast_nonneg (α := ℝ) B + nlinarith)) + have hP : 0 < auxiliaryCutoff B := pow_pos (by omega) _ + have hsize : ∀ p ∈ auxiliaryPrimes B, M < p := + fun _ hp => (block_prime_twice_sites hB hM hp).1 + have hhalf : ∀ p ∈ auxiliaryPrimes B, 2*M ≤ p := + fun _ hp => (block_prime_twice_sites hB hM hp).2 + have hN : M^2*B^2 ≤ B^6 := by + calc + _ ≤ (B^2)^2*B^2 := Nat.mul_le_mul_right _ (Nat.pow_le_pow_left hM 2) + _ = _ := by ring + let fa := fun u => if ActualCoefficientException B L T H M τ C u then (1 : ℝ) else 0 + let fm := fun u => if MaskedCoefficientException B L T H M τ C u then (1 : ℝ) else 0 + let ff := fun u => if ForcedCandidateHit B L T H M τ C + (fun i => coefficientPrimeSet B (u+(i.val+1))) then (1 : ℝ) else 0 + have ha := actual_coefficient_exception_bound hB hTe hMexp hP hTP + (fun S => hcount C T H M S) + have hm := masked_coefficient_exception_bound hB hTe hMexp hP hsize hhalf + (fun S => hcount C T H M S) + have hcoeff : (B : ℝ)^10*(arithmeticSquareMean B fa+arithmeticSquareMean B fm) ≤ + coefficientRootError B := coefficient_error_polynomial hB hN ha hm + have hpoint u : actualCandidateCutError B L T H M τ C χ u ≤ + maskedDigitCutError B L T H M τ C χ (arithmeticFirstDigits B u)+ + (B : ℝ)^10*(ff u+fa u+fm u) := by + apply actualCandidateCutError_pointwise hTP χ + have hc : |actualCandidateCutError B L T H M τ C χ u| ≤ (B : ℝ)^10 := + hcap C T H M hM0 hM (fun i => coefficientPrimeSet B (u+(i.val+1))) χ hχ + (primeSiteTranspose _ (auxiliaryPrimes B) + (arithmeticCandidatePrimeFamily B _ (candidateArithmeticQuotient u))) + exact (le_abs_self _).trans hc + have he := arithmeticSquareMean_mono B hpoint + rw [arithmeticSquareMean_add,arithmeticSquareMean_const_mul, + arithmeticSquareMean_add,arithmeticSquareMean_add] at he + have hfo := hforced C T H M hTe hMexp hM + rw [arithmeticSquareMean_const_mul] at hfo + have hma := hmask C T H M hT hTs hM0 hM hMexp χ hχ + change (B : ℝ)^10*arithmeticSquareMean B ff ≤ + (B : ℝ)^10*(5*(M : ℝ)^3*(B : ℝ)^3/(Real.log 2*auxiliaryCutoff B))+2/(B : ℝ) at hfo + calc + _ ≤ arithmeticSquareMean B (fun u => maskedDigitCutError B L T H M τ C χ (arithmeticFirstDigits B u))+ + (B : ℝ)^10*arithmeticSquareMean B ff+ + (B : ℝ)^10*(arithmeticSquareMean B fa+arithmeticSquareMean B fm) := he.trans_eq (by ring) + _ ≤ (K*(B : ℝ)^(-(7/200 : ℝ))+(B : ℝ)^10*conditionedRootError B+2/(B : ℝ))+ + ((B : ℝ)^10*(5*(M : ℝ)^3*(B : ℝ)^3/(Real.log 2*auxiliaryCutoff B))+2/(B : ℝ))+ + coefficientRootError B := add_le_add (add_le_add hma hfo) hcoeff + _ = _ := by ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ActualCandidateProduct.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualCandidateProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..c40a1773bd659d61e78986773e4a49a5e00ba5a5 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ActualCandidateProduct.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.JointDickman.Amplification.RootComparisonScale +import OAI.NumberTheory.JointDickman.Amplification.CandidateRepeatProbability + +namespace OAI + +/-! # The product estimate for the actual endpoint-dependent candidate list -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +theorem block_prime_twice_sites {B M p : ℕ} (hB : 2 ≤ B) (hM : M ≤ B^2) + (hp : p ∈ auxiliaryPrimes B) : M < p ∧ 2*M ≤ p := by + have hcut : auxiliaryCutoff B < p := by exact_mod_cast (mem_filter.mp hp).2 + have hpow : 2*M ≤ auxiliaryCutoff B := by + change 2*M ≤ B^1000 + have hmul : B*B^2 = B^3 := by rw [pow_succ]; exact Nat.mul_comm _ _ + have hpower : B^3 ≤ B^1000 := + pow_le_pow_right₀ (show 1 ≤ B from Nat.le_trans (by decide : 1 ≤ 2) hB) + (show (3 : ℕ) ≤ 1000 by decide) + exact (Nat.mul_le_mul_left 2 hM).trans + ((Nat.mul_le_mul_right (B^2) hB).trans (hmul.le.trans hpower)) + exact ⟨by omega,(hpow.trans hcut.le)⟩ + +theorem actual_candidate_roots_inj {B L T H M : ℕ} {τ C : ℝ} + {S : Fin M → Finset ℕ} (h : ¬ RepeatedCandidateRoot B L T H M τ C S) : + Set.InjOn blockCandidateRoot (blockCandidates B L T H M τ C S : Set (BlockCandidateIndex M)) := by + intro e he f hf hr + by_contra hne + exact h ⟨e,he,f,hf,hne,hr⟩ + +open Classical in +theorem actual_outside_candidate_product {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} + (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T H M : ℕ) (S : Fin M → Finset ℕ), + (T : ℝ) ≤ Real.exp B → (M : ℝ) ≤ Real.exp B → M ≤ B^2 → + ¬ RepeatedCandidateRoot B L T H M τ C S → + ∀ (Q : Finset ℕ) (hQ : Q ⊆ auxiliaryPrimes B), + (∑ R, |outsideCandidateProductMass B (blockCandidates B L T H M τ C S) Q hQ R- + bernoulliProductMass (blockCandidates B L T H M τ C S) + (fun p : Q => fun _ => 1/(p.val : ℝ)) R|) ≤ + 212*(B : ℝ)^19/(auxiliaryCutoff B : ℝ) := by + filter_upwards [blockCandidates_card hL hτ hτsmall,eventually_ge_atTop 2] with B hcard hB + intro C T H M S hT hMexp hM hroot Q hQ + let I := blockCandidates B L T H M τ C S + have hP : 0 < auxiliaryCutoff B := pow_pos (by omega) 1000 + have hs : (∑ p ∈ auxiliaryPrimes B, 1/(p : ℝ)^2) ≤ 1/(auxiliaryCutoff B : ℝ) := + sum_reciprocal_square_tail _ hP.ne' (fun p hp => by exact_mod_cast (mem_filter.mp hp).2) + have hd := candidateDefectPrimes_mass hB hT hMexp hP I + (fun _ he => (mem_blockCandidates.mp he).2) (actual_candidate_roots_inj hroot) + exact (outsideCandidateProduct_l1 I Q hQ + (fun p hp => (block_prime_twice_sites hB hM (hQ hp)).1) + (fun p hp => (block_prime_twice_sites hB hM (hQ hp)).2)).trans + (root_product_error_polynomial (by omega) hM (hcard C T H M S) hs hd) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionCutoffScale.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionCutoffScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..4cf164c6041b4d916b9ecf69054a999f5190e114 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionCutoffScale.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.SieveScale + +namespace OAI + +/-! # The fixed sieve cutoff used for the addition-product small-ball bound -/ + +namespace JointDickman + +open Filter +open scoped Topology + +noncomputable def additionSieveCutoff (Y : ℝ) : ℕ := ⌊Real.exp (Y / 100)⌋₊ + +theorem additionSieveCutoff_eventually : + ∀ᶠ Y : ℝ in atTop, 0 < Y ∧ 2 ≤ additionSieveCutoff Y ∧ + Y / 200 ≤ Real.log (additionSieveCutoff Y) ∧ + (additionSieveCutoff Y : ℝ) ≤ Real.exp (Y / 100) ∧ + (2 * (additionSieveCutoff Y + 1 : ℝ) * additionSieveCutoff Y) * Y ≤ Real.exp (Y / 2) := by + have hexp : ∀ᶠ Y : ℝ in atTop, 2 ≤ Real.exp (Y / 200) := by + apply (Real.tendsto_exp_atTop.comp ?_).eventually_ge_atTop 2 + exact tendsto_id.atTop_div_const (by norm_num : (0 : ℝ) < 200) + have hlim : Tendsto (fun Y : ℝ => 4 * (Y / Real.exp ((12 / 25 : ℝ) * Y))) atTop (𝓝 0) := by + have h := (isLittleO_pow_exp_pos_mul_atTop 1 (by norm_num : (0 : ℝ) < 12 / 25)).tendsto_div_nhds_zero + simpa only [pow_one, mul_zero] using h.const_mul 4 + filter_upwards [hexp, hlim.eventually (eventually_le_nhds (by norm_num : (0 : ℝ) < 1)), + eventually_gt_atTop 0] with Y he hs hY + have hfloor : Real.exp (Y / 200) ≤ (additionSieveCutoff Y : ℝ) := by + have hh := Nat.lt_floor_add_one (Real.exp (Y / 100)) + change Real.exp (Y / 100) < (additionSieveCutoff Y : ℝ) + 1 at hh + have heq : Real.exp (Y / 100) = Real.exp (Y / 200)^2 := by + rw [← Real.exp_nat_mul] + congr 1 + ring + rw [heq] at hh + nlinarith only [hh, he] + have hlog : Y / 200 ≤ Real.log (additionSieveCutoff Y) := by + have hh := Real.log_le_log (Real.exp_pos (Y / 200)) hfloor + simpa only [Real.log_exp] using hh + have hZupper : (additionSieveCutoff Y : ℝ) ≤ Real.exp (Y / 100) := Nat.floor_le (Real.exp_pos _).le + have hZ0 : (0 : ℝ) ≤ additionSieveCutoff Y := Nat.cast_nonneg _ + have he1 : 1 ≤ Real.exp (Y / 100) := Real.one_le_exp_iff.mpr (by positivity) + have hrem : 2 * (additionSieveCutoff Y + 1 : ℝ) * additionSieveCutoff Y ≤ + 4 * Real.exp (Y / 50) := by + calc + _ ≤ 2 * (2 * Real.exp (Y / 100)) * Real.exp (Y / 100) := by gcongr; linarith only [hZupper, he1] + _ = _ := by rw [show Y / 50 = Y / 100 + Y / 100 by ring, Real.exp_add]; ring + have hsmall : 4 * Y ≤ Real.exp ((12 / 25 : ℝ) * Y) := by + apply (div_le_one (Real.exp_pos _)).mp + convert hs using 1 + ring + refine ⟨hY, ?_, hlog, hZupper, ?_⟩ + · exact_mod_cast he.trans hfloor + · calc + _ ≤ (4 * Real.exp (Y / 50)) * Y := mul_le_mul_of_nonneg_right hrem hY.le + _ = (4 * Y) * Real.exp (Y / 50) := by ring + _ ≤ Real.exp ((12 / 25 : ℝ) * Y) * Real.exp (Y / 50) := + mul_le_mul_of_nonneg_right hsmall (Real.exp_pos _).le + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionProgressionGeometry.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionProgressionGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b1967a44266d5562d01df688f6ffff032bd1184 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionProgressionGeometry.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.NumericPrefixHarmonic +import Mathlib.Data.Nat.ModEq +import Mathlib.Data.Nat.GCD.BigOperators + +namespace OAI + +/-! # The actual progression of numeric additions -/ + +namespace JointDickman +open Finset Classical + +/-- Every selected coefficient is a unit modulo an allowed lag. -/ +theorem auxiliary_product_coprime_lag {B j : ℕ} {A : Finset ℕ} + (hA : A ⊆ auxiliaryPrimes B) (hj : 0 < j) (hcut : j ≤ auxiliaryCutoff B) : + (∏ p ∈ A, p : ℕ).Coprime j := by + apply Nat.coprime_prod_left_iff.mpr + intro p hp + have hprime := auxiliaryPrimes_prime B p (hA hp) + have hbig : auxiliaryCutoff B < p := by exact_mod_cast (mem_filter.mp (hA hp)).2 + exact Nat.coprime_of_lt_prime hj.ne' (lt_of_le_of_lt hcut hbig) hprime + +/-- Once the retained factors and the other addition are fixed, two valid +numeric additions have the same residue modulo the lag. -/ +theorem addition_equation_modEq {e j b z w c d : ℕ} (hej : e.Coprime j) + (hz : e*z = b+j*c) (hw : e*w = b+j*d) : Nat.ModEq j z w := by + have he : Nat.ModEq j (e*z) (e*w) := by + change (e*z)%j = (e*w)%j + rw [hz,hw] + simp [Nat.add_mod] + exact Nat.ModEq.cancel_left_of_coprime hej.symm he + +/-- A nonempty coefficient class has one residue z₀ and one integral +intercept c₀. Every other member is z=z₀+jt, c=c₀+et with t=z/j. -/ +theorem addition_equation_progression {e j b w d : ℕ} (hj : 0 < j) (hej : e.Coprime j) + (hw : e*w = b+j*d) : + ∃ (z₀ : ℕ) (c₀ : ℤ), z₀ < j ∧ + (e : ℤ)*z₀ = b+(j : ℤ)*c₀ ∧ + ∀ (z c : ℕ), e*z = b+j*c → + z = z₀+j*(z/j) ∧ (c : ℤ) = c₀+(e : ℤ)*((z/j : ℕ) : ℤ) := by + let z₀ := w%j + let c₀ : ℤ := (d : ℤ)-(e : ℤ)*((w/j : ℕ) : ℤ) + have hwdecomp : w = z₀+j*(w/j) := (Nat.mod_add_div w j).symm + have hwInt : (e : ℤ)*w = b+(j : ℤ)*d := by exact_mod_cast hw + have hwdecInt : (w : ℤ) = z₀+(j : ℤ)*((w/j : ℕ) : ℤ) := by exact_mod_cast hwdecomp + have hbase : (e : ℤ)*z₀ = b+(j : ℤ)*c₀ := by + dsimp [c₀] + simp only [Int.natCast_ediv] at hwdecInt + linear_combination hwInt-(e : ℤ)*hwdecInt + refine ⟨z₀,c₀,Nat.mod_lt _ hj,hbase,?_⟩ + intro z c hz + have hmod : z%j = w%j := addition_equation_modEq hej hz hw + have hzdec : z = z₀+j*(z/j) := by + change z = w%j+j*(z/j) + rw [← hmod] + exact (Nat.mod_add_div z j).symm + refine ⟨hzdec,?_⟩ + have hzInt : (e : ℤ)*z = b+(j : ℤ)*c := by exact_mod_cast hz + have hzdecInt : (z : ℤ) = z₀+(j : ℤ)*((z/j : ℕ) : ℤ) := by exact_mod_cast hzdec + apply mul_left_cancel₀ (show (j : ℤ) ≠ 0 by exact_mod_cast hj.ne') + simp only [Int.natCast_ediv] at hzdecInt ⊢ + linear_combination -hzInt+hbase+(e : ℤ)*hzdecInt + +/-- The determinant of the two progression forms is the fixed nonzero +opposite coefficient, with no dependence on the progression variable. -/ +theorem addition_progression_determinant {e j b z₀ : ℕ} {c₀ : ℤ} + (hbase : (e : ℤ)*z₀ = b+(j : ℤ)*c₀) : + (z₀ : ℤ)*e-c₀*j = b := by linear_combination hbase + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionProgressionInterval.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionProgressionInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..0534e5b42112a533e851e3f8b215d14ca7e430da --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionProgressionInterval.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.AdditionProgressionSieve + +namespace OAI + +/-! # A common interval for additions in a factor-four size window -/ + +namespace JointDickman +open Finset Classical + +noncomputable def additionIntervalLower (W : ℝ) (j : ℕ) : ℕ := ⌊W/j⌋₊ +noncomputable def additionIntervalUpper (W : ℝ) (j : ℕ) : ℕ := ⌊4*W/j⌋₊+1 + +theorem additionInterval_order {W : ℝ} {j : ℕ} (hW : 0 ≤ W) : + additionIntervalLower W j ≤ additionIntervalUpper W j := by + have hh : W/(j : ℝ) ≤ 4*W/j := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + linarith + exact (Nat.floor_mono hh).trans (Nat.le_succ _) + +theorem additionInterval_contains {W : ℝ} {j z : ℕ} (hWz : W ≤ (z : ℝ)) + (hzW : (z : ℝ) ≤ 4*W) : z/j ∈ Ico (additionIntervalLower W j) (additionIntervalUpper W j) := by + apply mem_Ico.mpr + have hlo := Nat.floor_mono (div_le_div_of_nonneg_right hWz (Nat.cast_nonneg j)) + have hhi := Nat.floor_mono (div_le_div_of_nonneg_right hzW (Nat.cast_nonneg j)) + rw [Nat.floor_div_eq_div] at hlo hhi + exact ⟨hlo,Nat.lt_succ_of_le hhi⟩ + +theorem additionInterval_denominator {W : ℝ} {j z₀ n : ℕ} + (hj : 0 < j) (hW : 2*(j : ℝ) ≤ W) + (hn : n ∈ Ico (additionIntervalLower W j) (additionIntervalUpper W j)) : + W/2 ≤ (z₀ : ℝ)+(j : ℝ)*n := by + have hjr : (0 : ℝ) < j := by exact_mod_cast hj + have hf := Nat.lt_floor_add_one (W/(j : ℝ)) + change W/(j : ℝ) < (additionIntervalLower W j : ℝ)+1 at hf + have hmul := (div_lt_iff₀ hjr).mp hf + have hnr : (additionIntervalLower W j : ℝ) ≤ n := by exact_mod_cast (mem_Ico.mp hn).1 + have hz₀ : (0 : ℝ) ≤ z₀ := Nat.cast_nonneg _ + nlinarith [mul_le_mul_of_nonneg_left hnr hjr.le] + +theorem additionInterval_length {W : ℝ} {j : ℕ} (hj : 0 < j) (hW : (j : ℝ) ≤ W) : + (additionIntervalUpper W j : ℝ)-additionIntervalLower W j ≤ 5*W/j := by + have hjr : (0 : ℝ) < j := by exact_mod_cast hj + have hW0 : 0 ≤ W := hjr.le.trans hW + have hf := Nat.floor_le (div_nonneg (by linarith : 0 ≤ 4*W) hjr.le) + have hlo : (0 : ℝ) ≤ additionIntervalLower W j := Nat.cast_nonneg _ + have hfrac : (1 : ℝ) ≤ W/j := (le_div_iff₀ hjr).mpr (by simpa using hW) + dsimp only [additionIntervalUpper] + push_cast + linarith [show 5*W/j = 4*W/j+W/j by ring] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionScaleDichotomy.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionScaleDichotomy.lean new file mode 100644 index 0000000000000000000000000000000000000000..53803d73998b838876694af5605271fa54268709 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionScaleDichotomy.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.JointDickman.Amplification.LargeCardinalityPartition +import OAI.NumberTheory.JointDickman.Amplification.NumericAdditionClass + +namespace OAI + +/-! # The finite grid dichotomy for the two addition products -/ + +namespace JointDickman +open Finset Classical + +theorem addition_product_large_of_not_prefix {B : ℕ} {g : ℝ} {Z : Finset ℕ} + (hg : g < 1) (hZ : Z ⊆ auxiliaryPrimes B) (hnot : ¬ Z ⊆ primePrefix B g Z) : + Real.exp ((B : ℝ)^g) ≤ (∏ p ∈ Z, p : ℕ) := by + obtain ⟨p,hp,hout⟩ := Finset.not_subset.mp hnot + have hprime := auxiliaryPrimes_prime B p (hZ hp) + have hp0 : (0 : ℝ) < p := by exact_mod_cast hprime.pos + have hlog : (B : ℝ)^g < Real.log p := by + apply lt_of_not_ge + intro hh + exact hout (by simpa only [primePrefix,ite_eq_left hg] using mem_filter.mpr ⟨hp,hh⟩) + have hprodpos : 0 < (∏ q ∈ Z, q : ℕ) := + prod_pos (fun q hq => (auxiliaryPrimes_prime B q (hZ hq)).pos) + have hpProd : p ≤ ∏ q ∈ Z, q := Nat.le_of_dvd hprodpos (dvd_prod_of_mem id hp) + calc + _ ≤ Real.exp (Real.log p) := (Real.exp_le_exp.mpr hlog.le) + _ = (p : ℝ) := Real.exp_log hp0 + _ ≤ _ := by exact_mod_cast hpProd + +/-- Either both additions stay in the first three grid cells, or at their +first common grid cell one of the products is at least exp(B^(g-1/L)). -/ +theorem addition_scale_dichotomy {B L : ℕ} (hL : 3 ≤ L) {Z Y : Finset ℕ} + (hZ : Z ⊆ auxiliaryPrimes B) (hY : Y ⊆ auxiliaryPrimes B) : + (Z ⊆ primePrefix B ((3 : ℝ)/L) Z ∧ Y ⊆ primePrefix B ((3 : ℝ)/L) Y) ∨ + ∃ k ∈ Icc 4 L, + Z ⊆ primePrefix B ((k : ℝ)/L) Z ∧ Y ⊆ primePrefix B ((k : ℝ)/L) Y ∧ + (Real.exp ((B : ℝ)^(((k : ℝ)-1)/L)) ≤ (∏ p ∈ Z, p : ℕ) ∨ + Real.exp ((B : ℝ)^(((k : ℝ)-1)/L)) ≤ (∏ p ∈ Y, p : ℕ)) := by + by_cases hsmall : Z ⊆ primePrefix B ((3 : ℝ)/L) Z ∧ Y ⊆ primePrefix B ((3 : ℝ)/L) Y + · exact Or.inl hsmall + · right + have hL0 : (L : ℝ) ≠ 0 := by exact_mod_cast (by omega : L ≠ 0) + let P := fun k : ℕ => 3 ≤ k ∧ k ≤ L ∧ + Z ⊆ primePrefix B ((k : ℝ)/L) Z ∧ Y ⊆ primePrefix B ((k : ℝ)/L) Y + have hex : ∃ k, P k := by + refine ⟨L,hL,le_rfl,?_,?_⟩ <;> simp [primePrefix,div_self hL0] + let k := Nat.find hex + have hk := Nat.find_spec hex + change 3 ≤ k ∧ k ≤ L ∧ Z ⊆ primePrefix B ((k : ℝ)/L) Z ∧ + Y ⊆ primePrefix B ((k : ℝ)/L) Y at hk + have hk4 : 4 ≤ k := by + by_contra hn + have hkeq : k = 3 := by omega + rw [hkeq] at hk + exact hsmall ⟨hk.2.2.1,hk.2.2.2⟩ + have hprev : ¬ (Z ⊆ primePrefix B (((k-1 : ℕ) : ℝ)/L) Z ∧ + Y ⊆ primePrefix B (((k-1 : ℕ) : ℝ)/L) Y) := by + intro hh + have hn := Nat.find_min hex (show k-1 < k by omega) + apply hn + exact ⟨by omega,by omega,hh⟩ + have hprevlt : (((k-1 : ℕ) : ℝ)/L) < 1 := by + have hLpos : (0 : ℝ) < L := by exact_mod_cast (by omega : 0 < L) + apply (div_lt_one hLpos).mpr + exact_mod_cast (by omega : k-1 < L) + refine ⟨k,mem_Icc.mpr ⟨hk4,hk.2.1⟩,hk.2.2.1,hk.2.2.2,?_⟩ + have heq : ((k-1 : ℕ) : ℝ) = (k : ℝ)-1 := by + rw [Nat.cast_sub (by omega : 1 ≤ k)] + norm_num + by_cases hz : Z ⊆ primePrefix B (((k-1 : ℕ) : ℝ)/L) Z + · right + have hy : ¬ Y ⊆ primePrefix B (((k-1 : ℕ) : ℝ)/L) Y := fun hh => hprev ⟨hz,hh⟩ + simpa only [heq] using addition_product_large_of_not_prefix hprevlt hY hy + · left + simpa only [heq] using addition_product_large_of_not_prefix hprevlt hZ hz + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionSmallBall.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionSmallBall.lean new file mode 100644 index 0000000000000000000000000000000000000000..aab2842311da2e0609ca0faf1eed9d220fbd3db6 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditionSmallBall.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.AdditionIntervalSieve +import OAI.NumberTheory.JointDickman.Amplification.AdditionCutoffScale + +namespace OAI + +/-! # Uniform small-ball bounds for the addition product -/ + +namespace JointDickman + +open Filter Finset +open scoped Topology + +/-- Any logarithmic interval of bounded length above Y/2 carries O(1/Y) +quarter-product mass. The prime set may extend above or below the interval; +only its containing the fixed sieve range is needed. -/ +theorem addition_product_small_ball + (hFord : PublishedInputs.FordUpperSieveInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) {H : ℝ} (hH : 0 ≤ H) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ Y : ℝ in atTop, ∀ (P : ℕ) (Q : Finset ℕ) (v : ℝ), + Y / 2 ≤ v → (∀ p ∈ Q, p.Prime) → (∀ p ∈ Q, P < p) → + (Nat.primesLE (additionSieveCutoff Y)).filter (fun p => P < p) ⊆ Q → + (∑ n ∈ Icc ⌈Real.exp v⌉₊ ⌊Real.exp (v + H)⌋₊, primeProductMass Q (1 / 4) n) ≤ K / Y := by + obtain ⟨K, hK, hsieve⟩ := addition_product_interval_sieve hFord hM + refine ⟨200 * K * (Real.exp H + 1) + 1, by positivity, ?_⟩ + filter_upwards [additionSieveCutoff_eventually] with Y hscale + intro P Q v hv hQ hrough hprefix + have hY : 0 < Y := hscale.1 + have hZ := hscale.2.1 + have hlog := hscale.2.2.1 + have hrem := hscale.2.2.2.2 + have hlog0 : 0 < Real.log (additionSieveCutoff Y) := (by positivity : 0 < Y / 200).trans_le hlog + have hv0 : 0 ≤ v := (by positivity : 0 ≤ Y / 2).trans hv + have hX : 0 < Real.exp v := Real.exp_pos v + have hX1 : 1 ≤ Real.exp v := Real.one_le_exp_iff.mpr hv0 + have huv : ⌈Real.exp v⌉₊ ≤ ⌊Real.exp (v + H)⌋₊ + 1 := by + apply Nat.ceil_le.mpr + have hh : Real.exp v ≤ Real.exp (v + H) := Real.exp_le_exp.mpr (by linarith only [hH]) + have hf := Nat.lt_floor_add_one (Real.exp (v + H)) + exact hh.trans (by exact_mod_cast hf.le) + have hlow : ∀ n ∈ Ico ⌈Real.exp v⌉₊ (⌊Real.exp (v + H)⌋₊ + 1), Real.exp v ≤ (n : ℝ) := by + intro n hn + exact (Nat.le_ceil (Real.exp v)).trans (by exact_mod_cast (mem_Ico.mp hn).1) + have hbound := hsieve P (additionSieveCutoff Y) ⌈Real.exp v⌉₊ (⌊Real.exp (v + H)⌋₊ + 1) + Q (Real.exp v) huv hZ hX hQ hrough hprefix hlow + have hlen : ((⌊Real.exp (v + H)⌋₊ + 1 : ℕ) : ℝ) - ⌈Real.exp v⌉₊ ≤ + (Real.exp H + 1) * Real.exp v := by + have hf := Nat.floor_le (Real.exp_pos (v + H)).le + have hc := Nat.le_ceil (Real.exp v) + rw [Real.exp_add] at hf + push_cast + rw [Real.exp_add] + nlinarith only [hf, hc, hX1] + have hfrac : (((⌊Real.exp (v + H)⌋₊ + 1 : ℕ) : ℝ) - ⌈Real.exp v⌉₊) / + (Real.exp v * Real.log (additionSieveCutoff Y)) ≤ 200 * (Real.exp H + 1) / Y := by + calc + _ ≤ ((Real.exp H + 1) * Real.exp v) / (Real.exp v * Real.log (additionSieveCutoff Y)) := + div_le_div_of_nonneg_right hlen (mul_nonneg hX.le hlog0.le) + _ = (Real.exp H + 1) / Real.log (additionSieveCutoff Y) := by field_simp + _ ≤ _ := by + apply (div_le_div_iff₀ hlog0 hY).mpr + have hh := mul_le_mul_of_nonneg_left hlog (by positivity : 0 ≤ 200 * (Real.exp H + 1)) + nlinarith only [hh] + have hrem' : 2 * (additionSieveCutoff Y + 1 : ℝ) * additionSieveCutoff Y / Real.exp v ≤ 1 / Y := by + apply (div_le_div_iff₀ hX hY).mpr + simpa only [one_mul] using hrem.trans (Real.exp_le_exp.mpr hv) + have hI : Ico ⌈Real.exp v⌉₊ (⌊Real.exp (v + H)⌋₊ + 1) = + Icc ⌈Real.exp v⌉₊ ⌊Real.exp (v + H)⌋₊ := by + ext n + simp only [mem_Ico, mem_Icc] + omega + rw [hI] at hbound + calc + _ ≤ _ := hbound + _ ≤ K * (200 * (Real.exp H + 1) / Y) + 1 / Y := + add_le_add (mul_le_mul_of_nonneg_left hfrac hK.le) hrem' + _ = _ := by ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AdditivePhaseBridge.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditivePhaseBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..1cec0af8d17a9bf561dca155bd64f5309cf52481 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditivePhaseBridge.lean @@ -0,0 +1,35 @@ +import OAI.NumberTheory.JointDickman.Amplification.OscillatoryTests +import OAI.NumberTheory.JointDickman.Amplification.RamanujanSum + +namespace OAI + +/-! # Relating real exponential notation to residue characters -/ + +namespace JointDickman + +theorem additivePhase_add (s t : ℝ) : + additivePhase (s + t) = additivePhase s * additivePhase t := by + unfold additivePhase + rw [← Complex.exp_add] + congr 1 + push_cast + ring + +theorem stdAddChar_as_additivePhase {q : ℕ} [NeZero q] (n : ℕ) : + ZMod.stdAddChar (n : ZMod q) = additivePhase ((n : ℝ) / q) := by + rw [stdAddChar_natCast] + unfold additivePhase + congr 1 + push_cast + ring + +theorem unit_nat_phase {q : ℕ} [NeZero q] (u : (ZMod q)ˣ) (n : ℕ) : + ZMod.stdAddChar ((u : ZMod q) * (n : ZMod q)) = + additivePhase (((u : ZMod q).val : ℝ) * n / q) := by + conv_lhs => rw [← ZMod.natCast_zmod_val (u : ZMod q), ← Nat.cast_mul, stdAddChar_as_additivePhase] + push_cast + rfl + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AdditivePhaseVariation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditivePhaseVariation.lean new file mode 100644 index 0000000000000000000000000000000000000000..19abe5a06cf0c5187901b1aefea6470c612dbeec --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AdditivePhaseVariation.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.JointDickman.Amplification.PolylogMultiplicativeSum +import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds + +namespace OAI + +/-! # Finite partial summation for a nearby additive frequency -/ +namespace JointDickman +open Finset + +lemma additivePhase_sub_one_norm_le (t : ℝ) : + ‖additivePhase t-1‖ ≤ 2*Real.pi*|t| := by + have he : additivePhase t = Complex.exp (Complex.I*((2*Real.pi*t:ℝ):ℂ)) := by + unfold additivePhase + congr 1 + push_cast + ring + rw [he] + have h := Real.norm_exp_I_mul_ofReal_sub_one_le (x := 2*Real.pi*t) + simpa [Real.norm_eq_abs,abs_mul,abs_of_pos Real.pi_pos] using h + +lemma additivePhase_difference_norm_le (x y : ℝ) : + ‖additivePhase x-additivePhase y‖ ≤ 2*Real.pi*|x-y| := by + have he : additivePhase x = additivePhase y*additivePhase (x-y) := by + rw [←additivePhase_add] + congr 1 + ring + rw [he,show additivePhase y*additivePhase (x-y)-additivePhase y = + additivePhase y*(additivePhase (x-y)-1) by ring,norm_mul,norm_additivePhase,one_mul] + exact additivePhase_sub_one_norm_le (x-y) + +lemma bounded_partial_sums_weighted (z w : ℕ → ℂ) (N : ℕ) (T M L : ℝ) + (hT : 0 ≤ T) (hM : 0 ≤ M) (hL : 0 ≤ L) + (hz : ∀ k ≤ N, ‖∑ i ∈ range k, z i‖ ≤ T) + (hw : ∀ i < N, ‖w i‖ ≤ M) + (hd : ∀ i < N, ‖w (i+1)-w i‖ ≤ L) : + ‖∑ i ∈ range N, w i*z i‖ ≤ T*(M+N*L) := by + cases N with + | zero => simpa using mul_nonneg hT hM + | succ N => + rw [show (∑ i ∈ range (N+1), w i*z i) = ∑ i ∈ range (N+1), w i • z i by simp] + rw [sum_range_by_parts] + simp only [Nat.add_sub_cancel,smul_eq_mul] + have hf : ‖w N*(∑ i ∈ range (N+1), z i)‖ ≤ M*T := by + rw [norm_mul] + exact mul_le_mul (hw N (by omega)) (hz (N+1) le_rfl) (norm_nonneg _) hM + have hs : ‖∑ i ∈ range N, (w (i+1)-w i)*(∑ j ∈ range (i+1), z j)‖ ≤ (N:ℝ)*(L*T) := by + apply (norm_sum_le _ _).trans + calc + _ ≤ ∑ _i ∈ range N, L*T := by + apply sum_le_sum + intro i hi + rw [norm_mul] + exact mul_le_mul (hd i (by have := mem_range.mp hi; omega)) + (hz (i+1) (by have := mem_range.mp hi; omega)) (norm_nonneg _) hL + _ = _ := by simp + have hh := (norm_sub_le _ _).trans (add_le_add hf hs) + apply hh.trans + push_cast + nlinarith + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AffineLocalFactors.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AffineLocalFactors.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ee118ae30f1ce7c69b649a475893e312456f86f --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AffineLocalFactors.lean @@ -0,0 +1,105 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.AffineRectangleSieve + +namespace OAI + +/-! # Exact local means for the three forms b, c, b+jc -/ + +namespace JointDickman + +open Finset + +open Classical in +noncomputable def residueWeight {α : Type*} (t : ℝ) (a x : α) : ℝ := + if x = a then t else 1 + +open Classical in +theorem sum_residueWeight {α : Type*} [Fintype α] (t : ℝ) (a : α) : + ∑ x : α, residueWeight t a x = (Fintype.card α : ℝ) - 1 + t := by + have heq (x : α) : residueWeight t a x = 1 + (if x = a then t - 1 else 0) := by + by_cases h : x = a <;> simp [residueWeight, h] + simp_rw [heq] + simp only [sum_add_distrib, sum_const, card_univ, nsmul_eq_mul, sum_ite_eq', mem_univ, ite_true] + ring + +open Classical in +theorem sum_two_residueWeights {α : Type*} [Fintype α] (t u : ℝ) (a b : α) + (hab : a ≠ b) : + ∑ x : α, residueWeight t a x * residueWeight u b x = + (Fintype.card α : ℝ) - 2 + t + u := by + have heq (x : α) : residueWeight t a x * residueWeight u b x = + 1 + (if x = a then t - 1 else 0) + (if x = b then u - 1 else 0) := by + by_cases ha : x = a <;> by_cases hb : x = b + · exact False.elim (hab (ha.symm.trans hb)) + all_goals simp [residueWeight, ha, hb, hab, Ne.symm hab] + simp_rw [heq] + simp only [sum_add_distrib, sum_const, card_univ, nsmul_eq_mul, sum_ite_eq', mem_univ, ite_true] + ring + +open Classical in +theorem sum_squared_residueWeight {α : Type*} [Fintype α] (t : ℝ) (a : α) : + ∑ x : α, residueWeight t a x ^ 2 = (Fintype.card α : ℝ) - 1 + t ^ 2 := by + have heq (x : α) : residueWeight t a x ^ 2 = residueWeight (t ^ 2) a x := by + by_cases h : x = a <;> simp [residueWeight, h] + simp_rw [heq] + exact sum_residueWeight _ _ + +open Classical in +theorem three_affine_residue_sum {p : ℕ} [Fact p.Prime] + (j : ZMod p) (hj : j ≠ 0) (t : ℝ) : + (∑ b : ZMod p, ∑ c : ZMod p, + residueWeight t 0 b * residueWeight t 0 c * residueWeight t 0 (b + j * c)) = + t * ((p : ℝ) - 1 + t ^ 2) + ((p : ℝ) - 1) * ((p : ℝ) - 2 + 2 * t) := by + rw [sum_comm] + have hinner (c : ZMod p) : (∑ b : ZMod p, + residueWeight t 0 b * residueWeight t 0 c * residueWeight t 0 (b + j * c)) = + if c = 0 then t * ((p : ℝ) - 1 + t ^ 2) else (p : ℝ) - 2 + 2 * t := by + by_cases hc : c = 0 + · subst c + simp only [mul_zero, add_zero, residueWeight, ite_true] + have hs := sum_squared_residueWeight t (0 : ZMod p) + simp only [ZMod.card] at hs + calc + _ = t * ∑ b : ZMod p, residueWeight t 0 b ^ 2 := by + rw [mul_sum] + apply sum_congr rfl + intro b _ + by_cases hb : b = 0 + · simp [residueWeight, hb] + ring + · simp [residueWeight, hb] + _ = _ := by rw [hs] + · have hroot : (0 : ZMod p) ≠ -(j * c) := by + intro h + have : j * c = 0 := neg_eq_zero.mp h.symm + exact (mul_ne_zero hj hc) this + have heq (b : ZMod p) : residueWeight t 0 (b + j * c) = residueWeight t (-(j * c)) b := by + simp [residueWeight, add_eq_zero_iff_eq_neg] + simp only [hc, residueWeight, ite_false, mul_one] + change (∑ b : ZMod p, residueWeight t 0 b * residueWeight t 0 (b + j * c)) = _ + simp_rw [heq] + simpa only [ZMod.card, two_mul, add_assoc] using + sum_two_residueWeights t t (0 : ZMod p) (-(j * c)) hroot + simp_rw [hinner] + have heq (c : ZMod p) : + (if c = 0 then t * ((p : ℝ) - 1 + t ^ 2) else (p : ℝ) - 2 + 2 * t) = + ((p : ℝ) - 2 + 2 * t) + + (if c = 0 then t * ((p : ℝ) - 1 + t ^ 2) - ((p : ℝ) - 2 + 2 * t) else 0) := by + by_cases hc : c = 0 <;> simp [hc] + simp_rw [heq] + simp only [sum_add_distrib, sum_const, card_univ, ZMod.card, nsmul_eq_mul, sum_ite_eq', mem_univ, + ite_true] + ring + +open Classical in +theorem three_affine_residue_sum_degenerate {p : ℕ} [NeZero p] (t : ℝ) : + (∑ b : ZMod p, ∑ c : ZMod p, + residueWeight t 0 b * residueWeight t 0 c * residueWeight t 0 b) = + ((p : ℝ) - 1 + t ^ 2) * ((p : ℝ) - 1 + t) := by + have heq (b c : ZMod p) : residueWeight t 0 b * residueWeight t 0 c * residueWeight t 0 b = + residueWeight t 0 b ^ 2 * residueWeight t 0 c := by ring + simp_rw [heq, ← mul_sum] + rw [← sum_mul, sum_squared_residueWeight, sum_residueWeight, ZMod.card] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeHighExpectation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeHighExpectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..767e20681a48b61f4b76e699fe7e6f128bb6e3bd --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeHighExpectation.lean @@ -0,0 +1,50 @@ +import OAI.NumberTheory.JointDickman.Amplification.LargeCardinalityPartition +import OAI.NumberTheory.JointDickman.Amplification.LargeAlternativeExpectation + +namespace OAI + +/-! # Exact cardinality-class decomposition in the tilted expectation -/ + +namespace JointDickman +open Finset Classical + +noncomputable def tiltedAllLargeHighPairCount (B L k j : ℕ) (τ C Δ : ℝ) + (A D V : Finset ℕ) : ℝ := + ∑ U ∈ (auxiliaryPrimes B \ A).powerset, + bernoulliSubsetMass (auxiliaryPrimes B \ A) (fun p => 1/(2*(p : ℝ)-1)) U * + if RegularPrimeSet B L τ C U then + ((allLargeHighAlternativePairs B L k j τ C Δ A U D V).card : ℝ) else 0 + +theorem tiltedAllLargeHighPairCount_eq_sum {B L k j : ℕ} {τ C Δ : ℝ} + (A D V : Finset ℕ) (hk : k ∈ Icc 1 L) + (hτ : τ ≤ 1/2) (hℓ : 0 ≤ auxiliaryLogLength B) + (hV : RegularPrimeSet B L τ C V) : + tiltedAllLargeHighPairCount B L k j τ C Δ A D V = + ∑ d ∈ range (⌊auxiliaryLogLength B⌋₊+1), ∑ f ∈ range (⌊auxiliaryLogLength B⌋₊+1), + tiltedLargeHighPairCount B L k j d f τ C Δ A D V := by + unfold tiltedAllLargeHighPairCount tiltedLargeHighPairCount + calc + _ = ∑ U ∈ (auxiliaryPrimes B \ A).powerset, + ∑ d ∈ range (⌊auxiliaryLogLength B⌋₊+1), ∑ f ∈ range (⌊auxiliaryLogLength B⌋₊+1), + bernoulliSubsetMass (auxiliaryPrimes B \ A) (fun p => 1/(2*(p : ℝ)-1)) U * + if RegularPrimeSet B L τ C U then + ((largeHighAlternativePairs B L k j d f τ C Δ A U D V).card : ℝ) else 0 := by + apply sum_congr rfl + intro U _ + by_cases hU : RegularPrimeSet B L τ C U + · simp only [hU,ite_true,← mul_sum] + have hc : ((allLargeHighAlternativePairs B L k j τ C Δ A U D V).card : ℝ) = + ∑ d ∈ range (⌊auxiliaryLogLength B⌋₊+1), ∑ f ∈ range (⌊auxiliaryLogLength B⌋₊+1), + ((largeHighAlternativePairs B L k j d f τ C Δ A U D V).card : ℝ) := by + exact_mod_cast allLargeHighAlternativePairs_card A U D V hk hτ hℓ hU hV + rw [hc] + · simp [hU] + _ = _ := by + rw [sum_comm] + apply sum_congr rfl + intro d _ + rw [sum_comm] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeHighVanishing.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeHighVanishing.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e0ad731072829aa09ab5c89929dafb933d5f960 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeHighVanishing.lean @@ -0,0 +1,96 @@ +import OAI.NumberTheory.JointDickman.Amplification.AllLargeHighExpectation +import OAI.NumberTheory.JointDickman.Amplification.LargeHighVanishing + +namespace OAI + +/-! # Summing every cardinality class of a large high-endpoint addition -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +noncomputable def allLargeClassError (K η ν : ℝ) (B : ℕ) : ℝ := + (K/η)*(Real.log B+1)^5/(B : ℝ)^((32/100 : ℝ)-ν) + +theorem log_add_one_fifth_div_rpow_tendsto {c : ℝ} (hc : 0 < c) : + Tendsto (fun B : ℝ => (Real.log B+1)^5/B^c) atTop (𝓝 0) := by + have ht : Tendsto (fun B : ℝ => 32*(Real.log B)^5/B^c) atTop (𝓝 0) := by + simpa only [Real.rpow_natCast,mul_zero,mul_div_assoc] using + (log_power_div_power_tendsto_zero (5 : ℕ) hc).const_mul 32 + apply squeeze_zero' _ _ ht + · filter_upwards [Real.tendsto_log_atTop.eventually_ge_atTop 1,eventually_gt_atTop (0 : ℝ)] with B hlog hB + positivity + · filter_upwards [Real.tendsto_log_atTop.eventually_ge_atTop 1,eventually_gt_atTop (0 : ℝ)] with B hlog hB + apply div_le_div_of_nonneg_right _ (Real.rpow_nonneg hB.le _) + have hh : Real.log B+1 ≤ 2*Real.log B := by linarith + have hp := pow_le_pow_left₀ (by linarith : 0 ≤ Real.log B+1) hh 5 + nlinarith + +theorem allLargeClassError_tendsto {K η ν : ℝ} (hν : ν < 32/100) : + Tendsto (allLargeClassError K η ν) atTop (𝓝 0) := by + have hh := ((log_add_one_fifth_div_rpow_tendsto (sub_pos.mpr hν)).comp + tendsto_natCast_atTop_atTop).const_mul (K/η) + unfold allLargeClassError + simpa only [mul_zero,mul_div_assoc,Function.comp_apply] using hh + +/-- All cardinality classes together still have vanishing expected +multiplicity. The only loss from summing them is two logarithmic powers. -/ +theorem all_large_high_class_vanishing + (hFord : PublishedInputs.FordUpperSieveInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + {L k : ℕ} (hk : k ∈ Icc 1 L) {g Δ δ ε η : ℝ} + (hkg : (k : ℝ)/L = g) (hg : 0 < g) (hg1 : g ≤ 1) + (hΔ : 0 < Δ) (hgap : 2*Δ < g) + (hδ : 0 < δ) (hδ1 : δ ≤ 1/2) (hε : 0 < ε) (hη : 0 < η) : + ∃ τ₀ : ℝ, 0 < τ₀ ∧ ∀ τ : ℝ, 0 < τ → τ ≤ τ₀ → + largeMultiplicityLoss Δ δ τ ε < 4/100 → + ∃ E : ℕ → ℝ, Tendsto E atTop (𝓝 0) ∧ ∀ᶠ B : ℕ in atTop, + ∀ (C : ℝ) (A D V : Finset ℕ) (j : ℕ), + A ⊆ auxiliaryPrimes B → D ⊆ auxiliaryPrimes B → V ⊆ auxiliaryPrimes B → + RegularPrimeSet B L τ C A → RegularPrimeSet B L τ C D → RegularPrimeSet B L τ C V → + (∏ p ∈ A, p : ℕ) ≤ Real.exp ((16/5 : ℝ)*B) → + 0 < j → j ≤ auxiliaryCutoff B → (j : ℝ) ≤ (B : ℝ)^2 → + η*(B : ℝ)^(32/100 : ℝ) ≤ j → + tiltedAllLargeHighPairCount B L k j τ C Δ A D V ≤ E B := by + obtain ⟨τ₁,hτ₁,hbound⟩ := large_high_class_error_bound hFord hM hk hkg hg hg1 hΔ hgap hδ hδ1 hε hη + refine ⟨min τ₁ (1/2),lt_min hτ₁ (by norm_num),?_⟩ + intro τ hτ hτsmall hloss + have hτ₁' : τ ≤ τ₁ := hτsmall.trans (min_le_left _ _) + have hτhalf : τ ≤ 1/2 := hτsmall.trans (min_le_right _ _) + obtain ⟨K,hK,_,hestimate⟩ := hbound τ hτ hτ₁' hloss + let ν := largeMultiplicityBase+largeMultiplicityLoss Δ δ τ ε + have hν : ν < 32/100 := by + have hh := largeMultiplicityBase_bounds.2 + dsimp only [ν] + linarith + refine ⟨allLargeClassError K η ν,allLargeClassError_tendsto hν,?_⟩ + filter_upwards [hestimate,auxiliaryLogLength_between,eventually_gt_atTop 1] with B hB hℓB hB1 + intro C A D V j hA hD hV hAr hDr hVr hAsize hj hcut hjB hjlow + rw [tiltedAllLargeHighPairCount_eq_sum A D V hk hτhalf hℓB.1 hVr] + let N := ⌊auxiliaryLogLength B⌋₊+1 + have hN : (N : ℝ) ≤ Real.log B+1 := by + have hh := Nat.floor_le hℓB.1 + dsimp only [N] + push_cast + linarith [hℓB.2] + have hlog : 0 ≤ Real.log B := Real.log_nonneg (by exact_mod_cast hB1.le) + have hE : 0 ≤ largeClassError K η ν B := by + unfold largeClassError + positivity + calc + _ ≤ ∑ d ∈ range N, ∑ f ∈ range N, largeClassError K η ν B := by + apply sum_le_sum + intro d _ + apply sum_le_sum + intro f _ + exact hB C A D V j d f hA hD hV hAr hDr hVr hAsize hj hcut hjB hjlow + _ = (N : ℝ)^2*largeClassError K η ν B := by + simp only [sum_const,card_range,nsmul_eq_mul] + ring + _ ≤ (Real.log B+1)^2*largeClassError K η ν B := + mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (Nat.cast_nonneg _) hN 2) hE + _ = _ := by unfold largeClassError allLargeClassError; ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeLowExpectation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeLowExpectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..b002b0a5729a810b01914db2a1c201ede098566c --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeLowExpectation.lean @@ -0,0 +1,50 @@ +import OAI.NumberTheory.JointDickman.Amplification.LowCardinalityPartition +import OAI.NumberTheory.JointDickman.Amplification.LowAlternativeExpectation + +namespace OAI + +/-! # Exact cardinality-class decomposition in the tilted expectation -/ + +namespace JointDickman +open Finset Classical + +noncomputable def tiltedAllLargeLowPairCount (B L k j : ℕ) (τ C Δ : ℝ) + (A D V : Finset ℕ) : ℝ := + ∑ U ∈ (auxiliaryPrimes B \ A).powerset, + bernoulliSubsetMass (auxiliaryPrimes B \ A) (fun p => 1/(2*(p : ℝ)-1)) U * + if RegularPrimeSet B L τ C U then + ((allLargeLowAlternativePairs B L k j τ C Δ A U D V).card : ℝ) else 0 + +theorem tiltedAllLargeLowPairCount_eq_sum {B L k j : ℕ} {τ C Δ : ℝ} + (A D V : Finset ℕ) (hk : k ∈ Icc 1 L) + (hτ : τ ≤ 1/2) (hℓ : 0 ≤ auxiliaryLogLength B) + (hV : RegularPrimeSet B L τ C V) : + tiltedAllLargeLowPairCount B L k j τ C Δ A D V = + ∑ d ∈ range (⌊auxiliaryLogLength B⌋₊+1), ∑ f ∈ range (⌊auxiliaryLogLength B⌋₊+1), + tiltedLargeLowPairCount B L k j d f τ C Δ A D V := by + unfold tiltedAllLargeLowPairCount tiltedLargeLowPairCount + calc + _ = ∑ U ∈ (auxiliaryPrimes B \ A).powerset, + ∑ d ∈ range (⌊auxiliaryLogLength B⌋₊+1), ∑ f ∈ range (⌊auxiliaryLogLength B⌋₊+1), + bernoulliSubsetMass (auxiliaryPrimes B \ A) (fun p => 1/(2*(p : ℝ)-1)) U * + if RegularPrimeSet B L τ C U then + ((largeLowAlternativePairs B L k j d f τ C Δ A U D V).card : ℝ) else 0 := by + apply sum_congr rfl + intro U _ + by_cases hU : RegularPrimeSet B L τ C U + · simp only [hU,ite_true,← mul_sum] + have hc : ((allLargeLowAlternativePairs B L k j τ C Δ A U D V).card : ℝ) = + ∑ d ∈ range (⌊auxiliaryLogLength B⌋₊+1), ∑ f ∈ range (⌊auxiliaryLogLength B⌋₊+1), + ((largeLowAlternativePairs B L k j d f τ C Δ A U D V).card : ℝ) := by + exact_mod_cast allLargeLowAlternativePairs_card A U D V hk hτ hℓ hU hV + rw [hc] + · simp [hU] + _ = _ := by + rw [sum_comm] + apply sum_congr rfl + intro d _ + rw [sum_comm] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeLowVanishing.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeLowVanishing.lean new file mode 100644 index 0000000000000000000000000000000000000000..ebfe20ff17891f4b738f18e8766df19678418ec7 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AllLargeLowVanishing.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.JointDickman.Amplification.AllLargeLowExpectation +import OAI.NumberTheory.JointDickman.Amplification.LargeLowVanishing +import OAI.NumberTheory.JointDickman.Amplification.AllLargeHighVanishing + +namespace OAI + +/-! # Summing every cardinality class of a large low-endpoint addition -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +/-- All cardinality classes together still have vanishing expected +multiplicity. The only loss from summing them is two logarithmic powers. -/ +theorem all_large_low_class_vanishing + (hFord : PublishedInputs.FordUpperSieveInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + {L k : ℕ} (hk : k ∈ Icc 1 L) {g Δ δ ε η : ℝ} + (hkg : (k : ℝ)/L = g) (hg : 0 < g) (hg1 : g ≤ 1) + (hΔ : 0 < Δ) (hgap : 2*Δ < g) + (hδ : 0 < δ) (hδ1 : δ ≤ 1/2) (hε : 0 < ε) (hη : 0 < η) : + ∃ τ₀ : ℝ, 0 < τ₀ ∧ ∀ τ : ℝ, 0 < τ → τ ≤ τ₀ → + largeMultiplicityLoss Δ δ τ ε < 4/100 → + ∃ E : ℕ → ℝ, Tendsto E atTop (𝓝 0) ∧ ∀ᶠ B : ℕ in atTop, + ∀ (C : ℝ) (A D V : Finset ℕ) (j : ℕ), + A ⊆ auxiliaryPrimes B → D ⊆ auxiliaryPrimes B → V ⊆ auxiliaryPrimes B → + RegularPrimeSet B L τ C A → RegularPrimeSet B L τ C D → RegularPrimeSet B L τ C V → + (∏ p ∈ A, p : ℕ) ≤ Real.exp ((16/5 : ℝ)*B) → + 0 < j → j ≤ auxiliaryCutoff B → (j : ℝ) ≤ (B : ℝ)^2 → + η*(B : ℝ)^(32/100 : ℝ) ≤ j → + tiltedAllLargeLowPairCount B L k j τ C Δ A D V ≤ E B := by + obtain ⟨τ₁,hτ₁,hbound⟩ := large_low_class_error_bound hFord hM hk hkg hg hg1 hΔ hgap hδ hδ1 hε hη + refine ⟨min τ₁ (1/2),lt_min hτ₁ (by norm_num),?_⟩ + intro τ hτ hτsmall hloss + have hτ₁' : τ ≤ τ₁ := hτsmall.trans (min_le_left _ _) + have hτhalf : τ ≤ 1/2 := hτsmall.trans (min_le_right _ _) + obtain ⟨K,hK,_,hestimate⟩ := hbound τ hτ hτ₁' hloss + let ν := largeMultiplicityBase+largeMultiplicityLoss Δ δ τ ε + have hν : ν < 32/100 := by + have hh := largeMultiplicityBase_bounds.2 + dsimp only [ν] + linarith + refine ⟨allLargeClassError K η ν,allLargeClassError_tendsto hν,?_⟩ + filter_upwards [hestimate,auxiliaryLogLength_between,eventually_gt_atTop 1] with B hB hℓB hB1 + intro C A D V j hA hD hV hAr hDr hVr hAsize hj hcut hjB hjlow + rw [tiltedAllLargeLowPairCount_eq_sum A D V hk hτhalf hℓB.1 hVr] + let N := ⌊auxiliaryLogLength B⌋₊+1 + have hN : (N : ℝ) ≤ Real.log B+1 := by + have hh := Nat.floor_le hℓB.1 + dsimp only [N] + push_cast + linarith [hℓB.2] + have hlog : 0 ≤ Real.log B := Real.log_nonneg (by exact_mod_cast hB1.le) + have hE : 0 ≤ largeClassError K η ν B := by + unfold largeClassError + positivity + calc + _ ≤ ∑ d ∈ range N, ∑ f ∈ range N, largeClassError K η ν B := by + apply sum_le_sum + intro d _ + apply sum_le_sum + intro f _ + exact hB C A D V j d f hA hD hV hAr hDr hVr hAsize hj hcut hjB hjlow + _ = (N : ℝ)^2*largeClassError K η ν B := by + simp only [sum_const,card_range,nsmul_eq_mul] + ring + _ ≤ (Real.log B+1)^2*largeClassError K η ν B := + mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (Nat.cast_nonneg _) hN 2) hE + _ = _ := by unfold largeClassError allLargeClassError; ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationArithmeticFeatures.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationArithmeticFeatures.lean new file mode 100644 index 0000000000000000000000000000000000000000..401dc09d0f7356d45327a03be40e1e6ffb1d315b --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationArithmeticFeatures.lean @@ -0,0 +1,70 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationBoxFeatures +import OAI.NumberTheory.JointDickman.Amplification.AmplificationDyadicIdentity + +namespace OAI + +/-! # The original amplification arithmetic sum has a bounded finite-feature kernel -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +noncomputable def amplificationPrimeKernel (P : MvPolynomial (Fin 4) ℝ) + (m : (Fin 4 →₀ ℕ) → ℕ) (B j : ℕ) (c : (Fin 4 →₀ ℕ) → ℕ → ℝ) + (H : (Fin 4 →₀ ℕ) → ℕ) (T : ℝ) : + (auxiliaryPrimes B → Bool) → (auxiliaryPrimes B → Bool) → ℝ := + polynomialPrimeKernel P m B j c H T (Real.log 2) + (dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T)) + (fun k => Real.log (Real.exp ((k : ℝ)*Real.log 2)/T)/B) + +theorem amplification_arithmetic_feature_comparison + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) + (hSW : PublishedInputs.SquarefreeCharacterEstimateInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (hMP : PublishedInputs.PrimeProductMertensInput) + {η : ℝ} (hη : 0 < η) : + ∀ δ : ℝ, 0 < δ → ∃ P : MvPolynomial (Fin 4) ℝ, + ∃ c : (Fin 4 →₀ ℕ) → ℕ → ℝ, + (∀ d, c d 0 = squarefreeLeadingConstant (1/2) ∧ 0 < c d 0) ∧ + ∃ H m : (Fin 4 →₀ ℕ) → ℕ, (∀ d, 0 < m d) ∧ + ∃ C₀ : ℝ, 0 ≤ C₀ ∧ ∃ ε : ℕ → ℝ, Tendsto ε atTop (𝓝 0) ∧ ∀ᶠ B : ℕ in atTop, + ∀ j : ℕ, [NeZero j] → ∀ Q : ℕ, 0 < Q → j*Q ≤ B → (B : ℝ)^(2/5 : ℝ) ≤ Q → + ∀ T : ℝ, 1 ≤ T → Real.log T ≤ (B : ℝ)/10 → η*T ≤ j → + ∀ U V : ℕ, + (∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ ≤ U) → + (∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊ ≤ V) → + ∀ g h : (auxiliaryPrimes B → Bool) → ℝ, + (∀ x, |g x| ≤ 1) → (∀ x, |h x| ≤ 1) → + T*|amplificationArithmeticSum B j T U V g h- + (singularSeries j/(j : ℝ))*(∑ x, ∑ y, + fullPrimeMass (auxiliaryPrimes B) x*fullPrimeMass (auxiliaryPrimes B) y*g x*h y* + amplificationPrimeKernel P m B j c H T x y)| ≤ ε B+δ*(T/j)*singularSeries j ∧ + ∀ x y, |amplificationPrimeKernel P m B j c H T x y| ≤ C₀ := by + intro δ hδ + obtain ⟨P,c,hc,H,m,hm,C₀,hC₀,ε,hε,hcompare⟩ := amplification_box_feature_comparison + hSD hSW hM hMP (Real.log_pos (by norm_num : (1 : ℝ) < 2)) hη δ hδ + refine ⟨P,c,hc,H,m,hm,C₀,hC₀,ε,hε,?_⟩ + filter_upwards [hcompare,eventually_ge_atTop 30] with B hb hB + intro j _ Q hQ hscale hcut T hT hlogT hlag U V hU hV g h hg hh + obtain ⟨_,hwindow,_⟩ := dyadic_scale_window hB hT hlogT + let S := dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T) + let s := fun k : ℤ => Real.log (Real.exp ((k : ℝ)*Real.log 2)/T)/B + have hBpos : (0 : ℝ) < B := by exact_mod_cast (lt_of_lt_of_le (by norm_num : 0 < 30) hB) + have hs : ∀ k ∈ S, |s k| ≤ 3 := by + intro k hk + rw [abs_le] + constructor + · apply (le_div_iff₀ hBpos).mpr + nlinarith [(hwindow k hk).2.1] + · apply (div_le_iff₀ hBpos).mpr + nlinarith [(hwindow k hk).2.2] + have he := hb j Q hQ hscale hcut T (lt_of_lt_of_le zero_lt_one hT) hlag S + (fun k hk => (hwindow k hk).1) (fun k hk => (hwindow k hk).2) s hs g h hg hh + rw [amplification_dyadic_identity hB hT hlogT j U V g h hU hV] at he + exact he + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationBoxFeatures.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationBoxFeatures.lean new file mode 100644 index 0000000000000000000000000000000000000000..d39e55b160b25f78cdf855e3a76ddab97469ff2e --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationBoxFeatures.lean @@ -0,0 +1,87 @@ +import OAI.NumberTheory.JointDickman.Probability.AmplificationTensorProfile + +namespace OAI + +/-! # Finite prime-site approximation for the actual smooth amplification box weight -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +theorem amplification_box_feature_comparison + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) + (hSW : PublishedInputs.SquarefreeCharacterEstimateInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (hMP : PublishedInputs.PrimeProductMertensInput) + {t η : ℝ} (ht : 0 < t) (hη : 0 < η) : + ∀ δ : ℝ, 0 < δ → ∃ P : MvPolynomial (Fin 4) ℝ, + ∃ c : (Fin 4 →₀ ℕ) → ℕ → ℝ, + (∀ d, c d 0 = squarefreeLeadingConstant (1/2) ∧ 0 < c d 0) ∧ + ∃ H m : (Fin 4 →₀ ℕ) → ℕ, (∀ d, 0 < m d) ∧ + ∃ C₀ : ℝ, 0 ≤ C₀ ∧ ∃ ε : ℕ → ℝ, Tendsto ε atTop (𝓝 0) ∧ ∀ᶠ B : ℕ in atTop, + ∀ j : ℕ, [NeZero j] → ∀ Q : ℕ, 0 < Q → j*Q ≤ B → (B : ℝ)^(2/5 : ℝ) ≤ Q → + ∀ T : ℝ, 0 < T → η*T ≤ j → ∀ S : Finset ℤ, + (∀ k ∈ S, (k : ℝ)*t ∈ Set.Icc ((9/10 : ℝ)*B) ((5/2 : ℝ)*B)) → + (∀ k ∈ S, Real.log (Real.exp ((k : ℝ)*t)/T) ∈ + Set.Icc ((9/10 : ℝ)*B) ((11/5 : ℝ)*B)) → + ∀ s : ℤ → ℝ, (∀ k ∈ S, |s k| ≤ 3) → + ∀ g h : (auxiliaryPrimes B → Bool) → ℝ, + (∀ x, |g x| ≤ 1) → (∀ x, |h x| ≤ 1) → + T*|geometricSmoothArithmeticSum B j (1/4) (17/4) (1/4) (17/4) T t S + (fun k x y z => amplificationBoxWeight B (s k) x y z) g h- + (singularSeries j/(j : ℝ))*(∑ x, ∑ y, + fullPrimeMass (auxiliaryPrimes B) x*fullPrimeMass (auxiliaryPrimes B) y* + g x*h y*polynomialPrimeKernel P m B j c H T t S s x y)| ≤ + ε B+δ*(T/j)*singularSeries j ∧ + ∀ x y, |polynomialPrimeKernel P m B j c H T t S s x y| ≤ C₀ := by + obtain ⟨C,hC,hfreeze⟩ := amplificationBoxWeight_freezing + obtain ⟨D,hD,ε₀,hε₀,hmass⟩ := smooth_arithmetic_mass_bound hSD hSW hM hMP ht hη + have hrate : Tendsto (fun B : ℕ => C/(B : ℝ)) atTop (𝓝 0) := by + simpa using (tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop) + intro δ hδ + obtain ⟨P,c,hc,H,m,hm,C₀,hC₀,ε₁,hε₁,hcompare⟩ := smooth_arithmetic_feature_comparison + hSD hSW hM hMP amplificationTensorProfile amplificationTensorProfile_continuous ht hη + (δ/2) (by positivity) + have hbudget : ∀ᶠ B : ℕ in atTop, (C/(B : ℝ))*D ≤ δ/2 := + (hrate.mul_const D).eventually_le_const (by simpa using half_pos hδ) + refine ⟨P,c,hc,H,m,hm,C₀,hC₀,fun B => ε₁ B+(C/(B : ℝ))*ε₀ B,?_,?_⟩ + · simpa using hε₁.add (hrate.mul hε₀) + filter_upwards [hcompare,hmass,hbudget,eventually_gt_atTop 0] with B hb hmassB hbud hB + intro j _ Q hQ hscale hcut T hT hlag S hbox hlog s hs g h hg hh + obtain ⟨hcomp,hbound⟩ := hb j Q hQ hscale hcut T hT hlag S hbox hlog s hs g h hg hh + refine ⟨?_,hbound⟩ + let A := geometricSmoothArithmeticSum B j (1/4) (17/4) (1/4) (17/4) T t S + (fun k x y z => amplificationBoxWeight B (s k) x y z) g h + let A₀ := geometricSmoothArithmeticSum B j (1/4) (17/4) (1/4) (17/4) T t S + (fun k x y z => amplificationTensorProfile ![x,y,z,s k]*tensorCutoff x y z) g h + let V := geometricSmoothArithmeticSum B j (1/4) (17/4) (1/4) (17/4) T t S + (fun _ x y z => tensorCutoff x y z) (fun _ => 1) (fun _ => 1) + let K := (singularSeries j/(j : ℝ))*(∑ x, ∑ y, + fullPrimeMass (auxiliaryPrimes B) x*fullPrimeMass (auxiliaryPrimes B) y*g x*h y* + polynomialPrimeKernel P m B j c H T t S s x y) + have hdiff : |A-A₀| ≤ (C/(B : ℝ))*V := by + change |geometricSmoothArithmeticSum B j (1/4) (17/4) (1/4) (17/4) T t S _ g h- + geometricSmoothArithmeticSum B j (1/4) (17/4) (1/4) (17/4) T t S _ g h| ≤ _ + rw [← geometricSmoothArithmeticSum_sub,← geometricSmoothArithmeticSum_smul] + apply geometricSmoothArithmeticSum_abs_le _ _ _ _ _ _ _ _ _ _ _ g h hg hh + intro k _ x y z + rw [amplificationTensorProfile_cutoff] + exact hfreeze B hB (s k) x y z + have hV : T*V ≤ ε₀ B+D*(T/j)*singularSeries j := + hmassB j Q hQ hscale hcut T hT hlag S hbox hlog + have hdiff' : T*|A-A₀| ≤ (C/(B : ℝ))*(ε₀ B+D*(T/j)*singularSeries j) := by + calc + _ ≤ T*((C/(B : ℝ))*V) := mul_le_mul_of_nonneg_left hdiff hT.le + _ = (C/(B : ℝ))*(T*V) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hV (div_nonneg hC (Nat.cast_nonneg B)) + have hSp := (singularSeries_bounds hMP j).1 + have hbud' := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right hbud (show 0 ≤ T/(j : ℝ) by positivity)) hSp + have hcomp' : T*|A₀-K| ≤ ε₁ B+(δ/2)*(T/j)*singularSeries j := hcomp + change T*|A-K| ≤ _ + have htri := mul_le_mul_of_nonneg_left (abs_sub_le A A₀ K) hT.le + nlinarith + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationBoxSupport.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationBoxSupport.lean new file mode 100644 index 0000000000000000000000000000000000000000..d8579e4a6e9182e88caef1f48b048664824af6da --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationBoxSupport.lean @@ -0,0 +1,92 @@ +import OAI.NumberTheory.JointDickman.Amplification.GeometricDyadicPartition +import OAI.NumberTheory.JointDickman.Amplification.FiniteTripleExtension + +namespace OAI + +/-! # Exact support of the amplification integrand in each geometric box -/ + +namespace JointDickman +open Finset + +theorem mem_tensor_interval_of_ratio {n : ℕ} {N : ℝ} (hN : 0 < N) + (hn : (n : ℝ)/N ∈ Set.Icc (1/2 : ℝ) 4) : + n ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊ := by + have hlo := (le_div_iff₀ hN).mp hn.1 + have hhi := (div_le_iff₀ hN).mp hn.2 + apply mem_Ioc.mpr + constructor + · apply (Nat.floor_lt (show 0 ≤ (1/4 : ℝ)*N by positivity)).mpr + nlinarith + · apply (Nat.le_floor_iff (show 0 ≤ (17/4 : ℝ)*N by positivity)).mpr + nlinarith + +theorem amplificationBoxWeight_integer_support (B : ℕ) {T N : ℝ} + (hT : 0 < T) (hN : 0 < N) (s : ℝ) (a b c : ℕ) + (hw : amplificationBoxWeight B s (a/N) (b/N) (c/(N/T)) ≠ 0) : + c ∈ Ioc ⌊(1/4 : ℝ)*(N/T)⌋₊ ⌊(17/4 : ℝ)*(N/T)⌋₊ ∧ + a ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊ ∧ + b ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊ := by + obtain ⟨ha,hb,hc⟩ := amplificationSpatialProfile_support (right_ne_zero_of_mul hw) + exact ⟨mem_tensor_interval_of_ratio (div_pos hN hT) ⟨hc.1,hc.2.trans (by norm_num)⟩, + mem_tensor_interval_of_ratio hN ha,mem_tensor_interval_of_ratio hN hb⟩ + +noncomputable def amplificationArithmeticTerm (B j : ℕ) (T : ℝ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) : ℝ := + if a = b+j*c then + signedSplitProductMass (auxiliaryPrimes B) (subsetSiteTest (auxiliaryPrimes B) g) a* + signedSplitProductMass (auxiliaryPrimes B) (subsetSiteTest (auxiliaryPrimes B) h) b* + coefficientWeight B c* + (amplificationBump (Real.log c/B)*amplificationBump (a/(T*c))*amplificationBump (b/(T*c))) + else 0 + +noncomputable def amplificationBoxTerm (B j : ℕ) (T N : ℝ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) : ℝ := + if a = b+j*c then + signedSplitProductMass (auxiliaryPrimes B) (subsetSiteTest (auxiliaryPrimes B) g) a* + signedSplitProductMass (auxiliaryPrimes B) (subsetSiteTest (auxiliaryPrimes B) h) b* + coefficientWeight B c* + amplificationBoxWeight B (Real.log (N/T)/B) (a/N) (b/N) (c/(N/T)) + else 0 + +theorem amplificationBoxTerm_support (B j : ℕ) {T N : ℝ} (hT : 0 < T) (hN : 0 < N) + (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) + (hf : amplificationBoxTerm B j T N g h c b a ≠ 0) : + c ∈ Ioc ⌊(1/4 : ℝ)*(N/T)⌋₊ ⌊(17/4 : ℝ)*(N/T)⌋₊ ∧ + b ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊ ∧ + a ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊ := by + have hw : amplificationBoxWeight B (Real.log (N/T)/B) (a/N) (b/N) (c/(N/T)) ≠ 0 := by + intro hz + apply hf + simp only [amplificationBoxTerm,hz,mul_zero,ite_self] + obtain ⟨hc,ha,hb⟩ := amplificationBoxWeight_integer_support B hT hN _ a b c hw + exact ⟨hc,hb,ha⟩ + +theorem amplificationBoxTerm_eq (B j : ℕ) {T N : ℝ} (hT : 0 < T) (hN : 0 < N) + (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) : + amplificationBoxTerm B j T N g h c b a = + amplificationArithmeticTerm B j T g h c b a*dyadicPartitionWeight (c/(N/T)) := by + by_cases hc : c = 0 + · simp [amplificationBoxTerm,amplificationArithmeticTerm,hc,coefficientWeight] + · have hcpos : (0 : ℝ) < c := by exact_mod_cast Nat.pos_of_ne_zero hc + unfold amplificationBoxTerm amplificationArithmeticTerm + rw [amplificationBoxWeight_normalized B hT hN hcpos] + split_ifs <;> ring + + +theorem amplificationArithmeticTerm_log_support {B : ℕ} (hB : 0 < B) (j : ℕ) (T : ℝ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) + (hf : amplificationArithmeticTerm B j T g h c b a ≠ 0) : + (B : ℝ) ≤ Real.log c ∧ Real.log c ≤ 2*B := by + have hne : amplificationBump (Real.log c/B) ≠ 0 := by + intro hz + apply hf + simp [amplificationArithmeticTerm,hz] + have hBr : (0 : ℝ) < B := by exact_mod_cast hB + have hh := amplificationBump_support hne + have hlo := (lt_div_iff₀ hBr).mp hh.1 + have hhi := (div_lt_iff₀ hBr).mp hh.2 + constructor <;> nlinarith + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationDyadicIdentity.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationDyadicIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..da252c828be0440d2d83e5f75e15a5a51425a17f --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationDyadicIdentity.lean @@ -0,0 +1,87 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationBoxSupport +import OAI.NumberTheory.JointDickman.Counting.DyadicScaleWindow + +namespace OAI + +/-! # Exact reconstruction of the unpartitioned amplification triple sum -/ + +namespace JointDickman +open Finset + +noncomputable def amplificationArithmeticSum (B j : ℕ) (T : ℝ) (U V : ℕ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) : ℝ := + B*∑ c ∈ Ioc 0 V, ∑ b ∈ Ioc 0 U, ∑ a ∈ Ioc 0 U, + amplificationArithmeticTerm B j T g h c b a + +theorem sum_triple_interchange {ι α β : Type*} (S : Finset ι) (A : Finset α) (C : Finset β) + (f : ι → β → α → α → ℝ) : + (∑ k ∈ S, ∑ c ∈ C, ∑ b ∈ A, ∑ a ∈ A, f k c b a) = + ∑ c ∈ C, ∑ b ∈ A, ∑ a ∈ A, ∑ k ∈ S, f k c b a := by + rw [sum_comm] + apply sum_congr rfl + intro c _ + rw [sum_comm] + apply sum_congr rfl + intro b _ + exact sum_comm + +theorem amplification_dyadic_identity {B : ℕ} (hB : 30 ≤ B) {T : ℝ} + (hT : 1 ≤ T) (hlogT : Real.log T ≤ (B : ℝ)/10) (j U V : ℕ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) + (hU : ∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ ≤ U) + (hV : ∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊ ≤ V) : + geometricSmoothArithmeticSum B j (1/4) (17/4) (1/4) (17/4) T (Real.log 2) + (dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T)) + (fun k x y z => amplificationBoxWeight B (Real.log (Real.exp ((k : ℝ)*Real.log 2)/T)/B) x y z) + g h = amplificationArithmeticSum B j T U V g h := by + have hTpos := lt_of_lt_of_le zero_lt_one hT + let S := dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T) + obtain ⟨hLU,_,hbracket⟩ := dyadic_scale_window hB hT hlogT + unfold geometricSmoothArithmeticSum amplificationArithmeticSum + congr 1 + change (∑ k ∈ S, + ∑ c ∈ Ioc ⌊(1/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊ + ⌊(17/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊, + ∑ b ∈ Ioc ⌊(1/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ + ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊, + ∑ a ∈ Ioc ⌊(1/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ + ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊, + amplificationBoxTerm B j T (Real.exp ((k : ℝ)*Real.log 2)) g h c b a) = _ + calc + _ = ∑ k ∈ S, ∑ c ∈ Ioc 0 V, ∑ b ∈ Ioc 0 U, ∑ a ∈ Ioc 0 U, + amplificationBoxTerm B j T (Real.exp ((k : ℝ)*Real.log 2)) g h c b a := by + apply sum_congr rfl + intro k hk + apply finite_triple_sum_extend + · intro n hn + obtain ⟨hnl,hnu⟩ := mem_Ioc.mp hn + exact mem_Ioc.mpr ⟨Nat.lt_of_le_of_lt (Nat.zero_le _) hnl,hnu.trans (hU k hk)⟩ + · intro n hn + obtain ⟨hnl,hnu⟩ := mem_Ioc.mp hn + exact mem_Ioc.mpr ⟨Nat.lt_of_le_of_lt (Nat.zero_le _) hnl,hnu.trans (hV k hk)⟩ + · exact amplificationBoxTerm_support B j hTpos (Real.exp_pos _) g h + _ = ∑ c ∈ Ioc 0 V, ∑ b ∈ Ioc 0 U, ∑ a ∈ Ioc 0 U, + ∑ k ∈ S, amplificationBoxTerm B j T (Real.exp ((k : ℝ)*Real.log 2)) g h c b a := + sum_triple_interchange S (Ioc 0 U) (Ioc 0 V) _ + _ = _ := by + apply sum_congr rfl + intro c hc + apply sum_congr rfl + intro b _ + apply sum_congr rfl + intro a _ + simp_rw [amplificationBoxTerm_eq B j hTpos (Real.exp_pos _) g h c b a,div_div_eq_mul_div] + rw [← mul_sum] + by_cases he : amplificationArithmeticTerm B j T g h c b a = 0 + · simp [he] + · have hBp : 0 < B := lt_of_lt_of_le (by norm_num) hB + obtain ⟨hlo,hhi⟩ := amplificationArithmeticTerm_log_support hBp j T g h c b a he + have hcp : (0 : ℝ) < c := by exact_mod_cast (mem_Ioc.mp hc).1 + obtain ⟨hcl,hcu⟩ := hbracket c hcp hlo hhi + rw [geometric_dyadic_partition hLU (c*T) hcl hcu,mul_one] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationEnvelope.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationEnvelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..dccb65060a7a4d7848ebb2b00e5f8667eeee96cd --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationEnvelope.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.JointDickman.Probability.TwoSiteSplitProduct +import OAI.NumberTheory.JointDickman.Probability.AmplificationSecondMoment + +namespace OAI + +/-! # The independent-model amplification envelope and its second moment -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +open Classical in +noncomputable def independentAmplificationEnvelope (B L T : ℕ) (τ C : ℝ) + (S R : Finset ℕ) : ℝ := + B * sitePairSplitAverage (auxiliaryPrimes B) S R + (fun A D => if amplificationSplitGood B L T τ C S R A D then 1 else 0) + +open Classical in +theorem independentAmplificationEnvelope_second_identity (B L T : ℕ) (τ C : ℝ) : + (∑ S ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) S * + ∑ R ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) R * + (independentAmplificationEnvelope B L T τ C S R)^2) = + (B : ℝ)^2 * twoSiteSplitProbability (auxiliaryPrimes B) (bothAmplificationSplitsGood B L T τ C) := by + let F := fun S R A D => if amplificationSplitGood B L T τ C S R A D then (1 : ℝ) else 0 + have hp : (∑ x : TwoSiteSplit (auxiliaryPrimes B), twoSiteSplitMass (auxiliaryPrimes B) x * + F x.site₁.val x.site₂.val x.first₁.val x.first₂.val * + F x.site₁.val x.site₂.val x.second₁.val x.second₂.val) = + twoSiteSplitProbability (auxiliaryPrimes B) (bothAmplificationSplitsGood B L T τ C) := by + apply sum_congr rfl + intro x _ + unfold F bothAmplificationSplitsGood + by_cases h₁ : amplificationSplitGood B L T τ C x.site₁.val x.site₂.val x.first₁.val x.first₂.val <;> + by_cases h₂ : amplificationSplitGood B L T τ C x.site₁.val x.site₂.val x.second₁.val x.second₂.val <;> + simp only [h₁, h₂, and_self, and_false, false_and, ite_true, ite_false, mul_one, mul_zero] + rw [← hp, twoSiteSplit_product] + simp only [independentAmplificationEnvelope, mul_sum] + apply sum_congr rfl + intro S _ + apply sum_congr rfl + intro R _ + dsimp only [F] + ring + +/-- The B-normalized fair-split envelope has a bounded second moment. -/ +theorem independentAmplificationEnvelope_second_bound + (hFord : PublishedInputs.FordUpperSieveInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) : + ∀ (L : ℕ) (τ C : ℝ), ∃ K : ℝ, 0 < K ∧ ∀ᶠ B : ℕ in atTop, + ∀ T : ℕ, 0 < T → (T : ℝ) ≤ Real.exp ((1 / 10 : ℝ) * B) → + (∑ S ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) S * + ∑ R ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) R * + (independentAmplificationEnvelope B L T τ C S R)^2) ≤ K := by + intro L τ C + obtain ⟨K, hK, hb⟩ := amplification_second_moment_probability hFord hM L τ C + refine ⟨K, hK, ?_⟩ + filter_upwards [hb, eventually_gt_atTop 0] with B hB hB0 + intro T hT hTsize + rw [independentAmplificationEnvelope_second_identity] + have hz : (B : ℝ)^2 ≠ 0 := pow_ne_zero _ (by exact_mod_cast (Nat.ne_of_gt hB0)) + calc + _ ≤ (B : ℝ)^2 * (K / (B : ℝ)^2) := + mul_le_mul_of_nonneg_left (hB T hT hTsize) (sq_nonneg _) + _ = K := by field_simp + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationEnvelopeFirst.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationEnvelopeFirst.lean new file mode 100644 index 0000000000000000000000000000000000000000..a056eab7d189ae31295cc7c1f09571d733b59e84 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationEnvelopeFirst.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationEnvelope +import OAI.NumberTheory.JointDickman.Probability.SitePairFirstLaw + +namespace OAI + +/-! # The positive first moment of the independent amplification envelope -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +open Classical in +theorem independentAmplificationEnvelope_first_identity (B L T : ℕ) (τ C : ℝ) : + (∑ S ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) S * + ∑ R ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) R * + independentAmplificationEnvelope B L T τ C S R) = + (B : ℝ) * fairRegularAmplificationMass B L T τ C := by + let H := fun A R D Q => if (∏ p ∈ A, p, ∏ p ∈ D, p) ∈ amplificationCoefficientPairs B T ∧ + RegularPrimeSet B L τ C A ∧ RegularPrimeSet B L τ C D ∧ + RegularPrimeSet B L τ C R ∧ RegularPrimeSet B L τ C Q then (1 : ℝ) else 0 + have he : (∑ S ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) S * + ∑ R ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) R * + sitePairSplitAverage (auxiliaryPrimes B) S R (fun A D => H A (S \ A) D (R \ D))) = + fairRegularAmplificationMass B L T τ C := by + rw [sitePair_first_law] + unfold fairRegularAmplificationMass fairRegularAmplificationAt + apply sum_congr rfl + intro A _ + apply sum_congr rfl + intro D _ + by_cases hp : (∏ p ∈ A, p, ∏ p ∈ D, p) ∈ amplificationCoefficientPairs B T + · simp only [hp, ite_true] + apply sum_congr rfl + intro R _ + apply sum_congr rfl + intro Q _ + dsimp only [H] + simp only [hp, true_and, and_assoc] + split_ifs <;> simp only [mul_one, mul_zero] + · simp only [hp, ite_false, H, false_and, mul_zero, sum_const_zero] + calc + _ = (B : ℝ) * (∑ S ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) S * + ∑ R ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) R * + sitePairSplitAverage (auxiliaryPrimes B) S R (fun A D => H A (S \ A) D (R \ D))) := by + simp only [independentAmplificationEnvelope, mul_sum] + apply sum_congr rfl + intro S _ + apply sum_congr rfl + intro R _ + unfold amplificationSplitGood + dsimp only [H] + ac_rfl + _ = _ := congrArg (fun x : ℝ => (B : ℝ) * x) he + +/-- A positive first moment, uniformly after choosing the regularity cutoff. -/ +theorem independentAmplificationEnvelope_first_lower + (hFord : PublishedInputs.FordUpperSieveInput) + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (hMP : PublishedInputs.PrimeProductMertensInput) : + ∃ d : ℝ, 0 < d ∧ ∀ (L : ℕ) (τ : ℝ), 0 < L → 0 < τ → + ∃ C₀ : ℝ, 0 ≤ C₀ ∧ ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T : ℕ), C₀ ≤ C → + 0 < T → (T : ℝ) ≤ Real.exp ((1 / 10 : ℝ) * B) → + d ≤ ∑ S ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) S * + ∑ R ∈ (auxiliaryPrimes B).powerset, + bernoulliSubsetMass (auxiliaryPrimes B) (fun p => 1 / (p : ℝ)) R * + independentAmplificationEnvelope B L T τ C S R := by + simp only [independentAmplificationEnvelope_first_identity] + exact regular_amplification_first_moment_lower hFord hSD hM hMP + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationFairFeatures.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationFairFeatures.lean new file mode 100644 index 0000000000000000000000000000000000000000..bce340aeef15081ddd9e0c1d45c6c9909d32c57d --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationFairFeatures.lean @@ -0,0 +1,55 @@ +import OAI.NumberTheory.JointDickman.Probability.AmplificationFairKernel +import OAI.NumberTheory.JointDickman.Amplification.AmplificationArithmeticFeatures + +namespace OAI + +/-! # The conditional finite-feature comparison for the actual split kernel -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +theorem amplification_fair_feature_comparison + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) + (hSW : PublishedInputs.SquarefreeCharacterEstimateInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (hMP : PublishedInputs.PrimeProductMertensInput) + {η : ℝ} (hη : 0 < η) : + ∀ δ : ℝ, 0 < δ → ∃ P : MvPolynomial (Fin 4) ℝ, + ∃ c : (Fin 4 →₀ ℕ) → ℕ → ℝ, + (∀ d, c d 0 = squarefreeLeadingConstant (1/2) ∧ 0 < c d 0) ∧ + ∃ H m : (Fin 4 →₀ ℕ) → ℕ, (∀ d, 0 < m d) ∧ + ∃ C₀ : ℝ, 0 ≤ C₀ ∧ ∃ ε : ℕ → ℝ, Tendsto ε atTop (𝓝 0) ∧ ∀ᶠ B : ℕ in atTop, + ∀ j : ℕ, [NeZero j] → ∀ Q : ℕ, 0 < Q → j*Q ≤ B → (B : ℝ)^(2/5 : ℝ) ≤ Q → + ∀ T : ℝ, 1 ≤ T → Real.log T ≤ (B : ℝ)/10 → η*T ≤ j → + ∀ V : ℕ, + (∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊ ≤ V) → + ∀ g h : (auxiliaryPrimes B → Bool) → ℝ, + (∀ x, |g x| ≤ 1) → (∀ x, |h x| ≤ 1) → + T*|(∑ x : auxiliaryPrimes B → Bool, ∑ y : auxiliaryPrimes B → Bool, + fullPrimeMass (auxiliaryPrimes B) x*fullPrimeMass (auxiliaryPrimes B) y*g x*h y* + amplificationFairKernel B j T V x y)- + (singularSeries j/(j : ℝ))*(∑ x, ∑ y, + fullPrimeMass (auxiliaryPrimes B) x*fullPrimeMass (auxiliaryPrimes B) y*g x*h y* + amplificationPrimeKernel P m B j c H T x y)| ≤ ε B+δ*(T/j)*singularSeries j ∧ + ∀ x y, |amplificationPrimeKernel P m B j c H T x y| ≤ C₀ := by + intro δ hδ + obtain ⟨P,c,hc,H,m,hm,C₀,hC₀,ε,hε,hcompare⟩ := + amplification_arithmetic_feature_comparison hSD hSW hM hMP hη δ hδ + refine ⟨P,c,hc,H,m,hm,C₀,hC₀,ε,hε,?_⟩ + filter_upwards [hcompare] with B hB + intro j _ Q hQ hscale hcut T hT hlogT hlag V hV g h hg hh + let S := dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T) + let f : ℤ → ℕ := fun k => ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ + let U := max (∏ p ∈ auxiliaryPrimes B,p) (S.sup f) + have hprod : (∏ p ∈ auxiliaryPrimes B,p) ≤ U := le_max_left _ _ + have hU : ∀ k ∈ S, f k ≤ U := fun k hk => + (le_sup (f := f) hk).trans (le_max_right _ _) + have he := hB j Q hQ hscale hcut T hT hlogT hlag U V hU hV g h hg hh + rw [amplificationArithmeticSum_eq_fairKernel B j T U V hprod g h] at he + exact he + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationFirstForm.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationFirstForm.lean new file mode 100644 index 0000000000000000000000000000000000000000..e0e8800b93482a21e65f29beca54044b2efbc4b7 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationFirstForm.lean @@ -0,0 +1,88 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationReindex +import OAI.NumberTheory.JointDickman.Amplification.WeightedCauchy + +namespace OAI + +/-! # The first divisor form and its quadratic energy -/ + +namespace JointDickman +open Finset + +noncomputable def firstFormWeight (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + (D : Finset ℕ) (m : ℕ) : ℝ := + u (∏ p ∈ D, p) * regularCoefficientWeight B L τ C (∏ p ∈ D, p) * + arithmeticResidueWeight B L τ C m + +open Classical in +noncomputable def firstFormInner (B L : ℕ) (τ C : ℝ) (v : ℕ → ℕ → ℝ) + (J : ℕ → ℂ) (N : ℕ) (D : Finset ℕ) (m : ℕ) : ℂ := + ∑ A ∈ (auxiliaryPrimes B).powerset, + let a := ∏ p ∈ A, p + let c := ∏ p ∈ D, p + if a*m < N ∧ c ∣ a*m+1 then + ((regularCoefficientWeight B L τ C a * + arithmeticResidueWeight B L τ C ((a*m+1)/c) * v a c : ℝ) : ℂ) * J (a*m) + else 0 + +noncomputable def firstDivisorForm (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) (v : ℕ → ℕ → ℝ) + (g J : ℕ → ℂ) (N : ℕ) : ℂ := + (∑ i ∈ (auxiliaryPrimes B).powerset ×ˢ range N, + (firstFormWeight B L τ C u i.1 i.2 : ℂ) * star (g i.2) * + firstFormInner B L τ C v J N i.1 i.2) / (N : ℂ) + +noncomputable def firstFormVolume (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) (N : ℕ) : ℝ := + (∑ i ∈ (auxiliaryPrimes B).powerset ×ˢ range N, + firstFormWeight B L τ C u i.1 i.2) / (N : ℝ) + +noncomputable def firstFormEnergy (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) (v : ℕ → ℕ → ℝ) + (J : ℕ → ℂ) (N : ℕ) : ℝ := + (∑ i ∈ (auxiliaryPrimes B).powerset ×ˢ range N, + firstFormWeight B L τ C u i.1 i.2 * ‖firstFormInner B L τ C v J N i.1 i.2‖^2) / (N : ℝ) + +theorem amplification_first_form (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + (v : ℕ → ℕ → ℝ) (g J : ℕ → ℂ) (N : ℕ) + (hg : ∀ A ∈ (auxiliaryPrimes B).powerset, ∀ m : ℕ, g ((∏ p ∈ A, p)*m) = g m) : + amplificationDivisorForm B L τ C (fun a c => u c * v a c) + (fun n => star (g n) * J n) N / (N : ℂ) = firstDivisorForm B L τ C u v g J N := by + unfold amplificationDivisorForm firstDivisorForm + congr 1 + rw [sum_product, sum_comm] + apply sum_congr rfl + intro D _ + rw [sum_comm] + apply sum_congr rfl + intro m _ + unfold firstFormInner + rw [mul_sum] + apply sum_congr rfl + intro A hA + dsimp only + by_cases h : (∏ p ∈ A, p)*m < N ∧ (∏ p ∈ D, p) ∣ (∏ p ∈ A, p)*m+1 + · rw [ite_eq_left h, ite_eq_left h, hg A hA m] + unfold firstFormWeight + push_cast + ring + · simp only [ite_eq_right h, mul_zero] + +theorem firstFormWeight_nonneg (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + (hu : ∀ c, 0 ≤ u c) (D : Finset ℕ) (m : ℕ) : + 0 ≤ firstFormWeight B L τ C u D m := + mul_nonneg (mul_nonneg (hu _) (regularCoefficientWeight_nonneg B L τ C _)) + (regularResidueWeight_nonneg B L τ C _) + +/-- The Cauchy step removes the first label from the actual divisor form. -/ +theorem firstDivisorForm_cauchy (B L : ℕ) (τ C : ℝ) (u : ℕ → ℝ) + (v : ℕ → ℕ → ℝ) (g J : ℕ → ℂ) (N : ℕ) + (hu : ∀ c, 0 ≤ u c) (hg : ∀ m, ‖g m‖ ≤ 1) : + ‖firstDivisorForm B L τ C u v g J N‖^2 ≤ + firstFormVolume B L τ C u N * firstFormEnergy B L τ C u v J N := by + exact normalized_weighted_complex_cauchy (ι := Finset ℕ × ℕ) + ((auxiliaryPrimes B).powerset ×ˢ range N) + (fun i => firstFormWeight B L τ C u i.1 i.2) (fun i => star (g i.2)) + (fun i => firstFormInner B L τ C v J N i.1 i.2) + (fun i _ => firstFormWeight_nonneg B L τ C u hu i.1 i.2) + (fun i _ => by simpa only [norm_star] using hg i.2) (N := (N : ℝ)) (Nat.cast_nonneg N) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationMultiplier.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationMultiplier.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0bb6e5596b47714f959bc4b1804bf8f81a2f650 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationMultiplier.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.JointDickman.Amplification.RegularWeightCap + +namespace OAI + +/-! # The manuscript's multiplier scale and negligible diagonal cap -/ + +namespace JointDickman +open Filter +open scoped Topology + +noncomputable def amplificationMultiplier (B : ℕ) : ℕ := ⌊(B : ℝ) ^ (8/25 : ℝ)⌋₊ + +theorem amplificationMultiplier_comparable : ∀ᶠ B : ℕ in atTop, + 0 < amplificationMultiplier B ∧ + (B : ℝ) ^ (8/25 : ℝ) / 2 ≤ amplificationMultiplier B ∧ + (amplificationMultiplier B : ℝ) ≤ (B : ℝ) ^ (8/25 : ℝ) := by + have hp := (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 8/25)).comp + tendsto_natCast_atTop_atTop + filter_upwards [hp.eventually_ge_atTop 2] with B hB + change 2 ≤ (B : ℝ) ^ (8/25 : ℝ) at hB + have hl := Nat.lt_floor_add_one ((B : ℝ) ^ (8/25 : ℝ)) + have hpos : 0 < amplificationMultiplier B := by + apply Nat.floor_pos.mpr + linarith + exact ⟨hpos,by dsimp [amplificationMultiplier]; linarith, + Nat.floor_le (Real.rpow_nonneg (Nat.cast_nonneg _) _)⟩ + +theorem amplificationMultiplier_valid : ∀ᶠ B : ℕ in atTop, + 0 < amplificationMultiplier B ∧ + (amplificationMultiplier B : ℝ) ≤ Real.exp ((1/10 : ℝ)*B) := by + have hlim := ((isLittleO_rpow_exp_pos_mul_atTop (8/25 : ℝ) + (by norm_num : (0 : ℝ) < 1/10)).tendsto_div_nhds_zero).comp tendsto_natCast_atTop_atTop + filter_upwards [amplificationMultiplier_comparable, + hlim.eventually (eventually_le_nhds (by norm_num : (0 : ℝ) < 1))] with B hB he + refine ⟨hB.1, hB.2.2.trans ?_⟩ + exact (div_le_one (Real.exp_pos _)).mp he + +theorem power_div_amplificationMultiplier {r : ℝ} (hr : r < 8/25) : + Tendsto (fun B : ℕ => (B : ℝ)^r / amplificationMultiplier B) atTop (nhds 0) := by + have hp := (power_div_power_tendsto_zero hr).comp tendsto_natCast_atTop_atTop + have hu : ∀ᶠ B : ℕ in atTop, + (B : ℝ)^r / amplificationMultiplier B ≤ 2*((B : ℝ)^r / (B : ℝ)^(8/25 : ℝ)) := by + filter_upwards [amplificationMultiplier_comparable,eventually_gt_atTop 0] with B hB hB0 + have hpow : 0 < (B : ℝ)^(8/25 : ℝ) := Real.rpow_pos_of_pos (by exact_mod_cast hB0) _ + have hT : (0 : ℝ) < amplificationMultiplier B := by exact_mod_cast hB.1 + apply (div_le_iff₀ hT).mpr + have hnon := Real.rpow_nonneg (Nat.cast_nonneg B) r + calc + _ = 2*((B : ℝ)^r / (B : ℝ)^(8/25 : ℝ)) * ((B : ℝ)^(8/25 : ℝ)/2) := by + field_simp + _ ≤ _ := mul_le_mul_of_nonneg_left hB.2.1 (by positivity) + apply squeeze_zero' (Eventually.of_forall fun B => div_nonneg + (Real.rpow_nonneg (Nat.cast_nonneg _) _) (Nat.cast_nonneg _)) hu + simpa using hp.const_mul 2 + +/-- Both regular weights together are bounded by one power strictly below +T's exponent, uniformly in the later tail cutoff. -/ +theorem regular_pair_cap_negligible {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} + (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∃ Q : ℕ → ℝ, + Tendsto (fun B => Q B / amplificationMultiplier B) atTop (nhds 0) ∧ + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (a : ℕ) (S : Finset ℕ), + regularCoefficientWeight B L τ C a * regularResidueWeight B L τ C S ≤ Q B := by + let ε : ℝ := ((8/25 : ℝ) - 2*weightExponent τ)/4 + have hm := (weight_margins_of_le_samplingTau hτsmall).1 + have hε : 0 < ε := by dsimp [ε]; linarith + have hr : 2*(weightExponent τ + ε) < 8/25 := by dsimp [ε]; linarith + refine ⟨fun B => (B : ℝ)^(2*(weightExponent τ+ε)),power_div_amplificationMultiplier hr,?_⟩ + filter_upwards [regular_weights_cap hL hτ hε,eventually_gt_atTop 0] with B hB hB0 + intro C a S + have hab : regularCoefficientWeight B L τ C a * regularResidueWeight B L τ C S ≤ + (B : ℝ)^(weightExponent τ+ε) * (B : ℝ)^(weightExponent τ+ε) := + mul_le_mul ((hB C).2 a) ((hB C).1 S) (regularResidueWeight_nonneg B L τ C S) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + have hBpos : (0 : ℝ) < B := by exact_mod_cast hB0 + rw [← Real.rpow_add hBpos] at hab + convert hab using 1 + congr 1 + ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationPointBounds.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationPointBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a6c1830753e7947982558a12e5c7ab5c8900be6 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationPointBounds.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationEnvelope + +namespace OAI + +/-! # Pointwise bounds for the normalized fair-split envelope -/ + +namespace JointDickman +open Finset + +theorem subsetRetentionMass_sum {P S : Finset ℕ} (hS : S ⊆ P) : + (∑ A ∈ P.powerset, subsetRetentionMass S A) = 1 := by + have hs := subsetRetentionMass_sum_support hS (fun _ => 1) + simp only [mul_one] at hs + rw [hs] + calc + _ = ∑ A ∈ S.powerset, bernoulliSubsetMass S (fun _ => (1 / 2 : ℝ)) A := by + apply sum_congr rfl + intro A hA + exact (bernoulliHalf_eq_retention (mem_powerset.mp hA)).symm + _ = 1 := bernoulliSubsetMass_sum _ _ + +theorem sitePairSplitAverage_const_one {P S T : Finset ℕ} (hS : S ⊆ P) (hT : T ⊆ P) : + sitePairSplitAverage P S T (fun _ _ => 1) = 1 := by + unfold sitePairSplitAverage + simp only [mul_one, ← sum_mul_sum, subsetRetentionMass_sum hS, subsetRetentionMass_sum hT] + +theorem sitePairSplitAverage_mono (P S T : Finset ℕ) (F G : Finset ℕ → Finset ℕ → ℝ) + (hFG : ∀ A ⊆ P, ∀ D ⊆ P, F A D ≤ G A D) : + sitePairSplitAverage P S T F ≤ sitePairSplitAverage P S T G := by + apply sum_le_sum + intro A hA + apply sum_le_sum + intro D hD + exact mul_le_mul_of_nonneg_left (hFG A (mem_powerset.mp hA) D (mem_powerset.mp hD)) + (mul_nonneg (subsetRetentionMass_nonneg _ _) (subsetRetentionMass_nonneg _ _)) + +open Classical in +theorem independentAmplificationEnvelope_nonneg (B L T : ℕ) (τ C : ℝ) (S R : Finset ℕ) : + 0 ≤ independentAmplificationEnvelope B L T τ C S R := by + unfold independentAmplificationEnvelope sitePairSplitAverage + apply mul_nonneg (Nat.cast_nonneg _) + apply sum_nonneg + intro A _ + apply sum_nonneg + intro D _ + apply mul_nonneg (mul_nonneg (subsetRetentionMass_nonneg _ _) (subsetRetentionMass_nonneg _ _)) + dsimp only + split_ifs <;> norm_num + +open Classical in +theorem independentAmplificationEnvelope_le {B L T : ℕ} {τ C : ℝ} {S R : Finset ℕ} + (hS : S ⊆ auxiliaryPrimes B) (hR : R ⊆ auxiliaryPrimes B) : + independentAmplificationEnvelope B L T τ C S R ≤ B := by + have hh := sitePairSplitAverage_mono (auxiliaryPrimes B) S R + (fun A D => if amplificationSplitGood B L T τ C S R A D then (1 : ℝ) else 0) + (fun _ _ => 1) (by intros; split_ifs <;> norm_num) + rw [sitePairSplitAverage_const_one hS hR] at hh + exact (mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg B)).trans_eq (mul_one _) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationPositiveMass.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationPositiveMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf219742e1c8fbe50a5b2a50eb18bf953b21e406 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationPositiveMass.lean @@ -0,0 +1,55 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationArithmeticFeatures +import OAI.NumberTheory.JointDickman.Arithmetic.PrimeKernelMeanBound + +namespace OAI + +/-! # Total positive arithmetic mass for removing remainder restrictions -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +theorem amplification_positive_mass_bound + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) + (hSW : PublishedInputs.SquarefreeCharacterEstimateInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (hMP : PublishedInputs.PrimeProductMertensInput) + {η : ℝ} (hη : 0 < η) : + ∃ K : ℝ, 0 ≤ K ∧ ∃ ε : ℕ → ℝ, Tendsto ε atTop (𝓝 0) ∧ + ∀ᶠ B : ℕ in atTop, ∀ j : ℕ, [NeZero j] → + ∀ Q : ℕ, 0 < Q → j*Q ≤ B → (B : ℝ)^(2/5 : ℝ) ≤ Q → + ∀ T : ℝ, 1 ≤ T → Real.log T ≤ (B : ℝ)/10 → η*T ≤ j → + ∀ U V : ℕ, + (∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ ≤ U) → + (∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊ ≤ V) → + T*amplificationArithmeticSum B j T U V (fun _ => 1) (fun _ => 1) ≤ + ε B+K*(T/j)*singularSeries j := by + obtain ⟨P,c,hc,H,m,hm,K,hK,ε,hε,hcomp⟩ := + amplification_arithmetic_feature_comparison hSD hSW hM hMP hη 1 (by norm_num) + refine ⟨K+1,by linarith,ε,hε,?_⟩ + filter_upwards [hcomp] with B hb + intro j _ Q hQ hscale hcut T hT hlog hlag U V hU hV + obtain ⟨he,hkernel⟩ := hb j Q hQ hscale hcut T hT hlog hlag U V hU hV + (fun _ => 1) (fun _ => 1) (by simp) (by simp) + let E := ∑ x, ∑ y, fullPrimeMass (auxiliaryPrimes B) x* + fullPrimeMass (auxiliaryPrimes B) y*amplificationPrimeKernel P m B j c H T x y + have hE : |E| ≤ K := primeKernel_mean_abs_le B _ hkernel + have hSp := (singularSeries_bounds hMP j).1 + have hscalar : 0 ≤ singularSeries j/(j : ℝ) := div_nonneg hSp (Nat.cast_nonneg _) + have hmodel : T*((singularSeries j/(j : ℝ))*E) ≤ T*((singularSeries j/(j : ℝ))*K) := + mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left ((le_abs_self E).trans hE) hscalar) + (lt_of_lt_of_le zero_lt_one hT).le + have herr : T*(amplificationArithmeticSum B j T U V (fun _ => 1) (fun _ => 1)- + (singularSeries j/(j : ℝ))*E) ≤ ε B+(T/j)*singularSeries j := by + exact (mul_le_mul_of_nonneg_left (le_abs_self _) (lt_of_lt_of_le zero_lt_one hT).le).trans + (by simpa only [mul_one,one_mul] using he) + have hid : T*((singularSeries j/(j : ℝ))*K) = K*(T/j)*singularSeries j := by ring + rw [hid] at hmodel + nlinarith + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularity.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d94635cfe49b2c9437fc3f5e9c8531ed0fecd9c --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularity.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.JointDickman.Amplification.FourSubsetFailure + +namespace OAI + +/-! # Removing all four regularity cutoffs in the amplification mass -/ + +namespace JointDickman + +open Filter Finset +open scoped Topology + +/-- In the actual independent-site fair-split model, the B-normalized +size-and-ratio mass lost at any of the four cutoffs tends to zero, up to +the uniform exponential tail-cutoff error. -/ +theorem amplification_regularity_loss + (hFord : PublishedInputs.FordUpperSieveInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) : + ∃ K : ℝ, 0 < K ∧ ∀ (L : ℕ) (τ : ℝ), 0 < L → 0 < τ → + ∃ ε : ℕ → ℝ, (∀ B, 0 ≤ ε B) ∧ Tendsto ε atTop (𝓝 0) ∧ + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T : ℕ), 0 ≤ C → 0 < T → + (T : ℝ) ≤ Real.exp ((1 / 10 : ℝ) * B) → + (B : ℝ) * fairFourSubsetFailure B L T τ C ≤ + K * (ε B + Real.exp (-(1 / 10 : ℝ) * C)) := by + classical + obtain ⟨Kc, hKc, hcoef⟩ := coefficient_cutoff_removal hFord hM + obtain ⟨Kr, hKr, hremaining⟩ := fair_remaining_pair_regularity_loss hM + (by norm_num : (0 : ℝ) < 16 / 5) + obtain ⟨M, hM0, hmass⟩ := coefficient_size_ratio_event_bound hFord hM + let K := Kc + M * Kr + refine ⟨K, by dsimp [K]; positivity, ?_⟩ + intro L τ hL hτ + obtain ⟨εc, hεc0, hεc, hclarge⟩ := hcoef L τ hL hτ + obtain ⟨εr, hεr0, hεr, hrlarge⟩ := hremaining L τ hL hτ + let ε := fun B => εc B + εr B + refine ⟨ε, fun B => add_nonneg (hεc0 B) (hεr0 B), ?_, ?_⟩ + · simpa only [ε, add_zero] using hεc.add hεr + filter_upwards [hclarge, hrlarge, hmass, amplificationCoefficientPairs_size, + eventually_gt_atTop 0] with B hc hr hm hsize hB + intro C T hC hT hTsize + let F := εr B + Real.exp (-(1 / 10 : ℝ) * C) + have hF : 0 ≤ F := add_nonneg (hεr0 B) (Real.exp_pos _).le + have hB0 : (0 : ℝ) ≤ B := Nat.cast_nonneg B + have hrem : (∑ A ∈ (auxiliaryPrimes B).powerset, ∑ D ∈ (auxiliaryPrimes B).powerset, + if (∏ p ∈ A, p, ∏ p ∈ D, p) ∈ amplificationCoefficientPairs B T then + fairRemainingPairFailure B L τ C A D else 0) ≤ + (∑ ac ∈ amplificationCoefficientPairs B T, + primeProductMass (auxiliaryPrimes B) (1 / 2) ac.1 * + primeProductMass (auxiliaryPrimes B) (1 / 2) ac.2) * Kr * F := by + rw [primeProductPair_sum_event] + simp only [sum_mul] + apply sum_le_sum + intro A hA + apply sum_le_sum + intro D hD + by_cases hp : (∏ p ∈ A, p, ∏ p ∈ D, p) ∈ amplificationCoefficientPairs B T + · simp only [hp, ite_true] + obtain ⟨ha, hd⟩ := hsize T _ _ hT hTsize hp + exact hr A D C hC (mem_powerset.mp hA) (mem_powerset.mp hD) ha hd + · simp only [hp, ite_false, zero_mul, le_refl] + have hrem' : (B : ℝ) * (∑ A ∈ (auxiliaryPrimes B).powerset, ∑ D ∈ (auxiliaryPrimes B).powerset, + if (∏ p ∈ A, p, ∏ p ∈ D, p) ∈ amplificationCoefficientPairs B T then + fairRemainingPairFailure B L τ C A D else 0) ≤ M * Kr * F := by + calc + _ ≤ (B : ℝ) * ((∑ ac ∈ amplificationCoefficientPairs B T, + primeProductMass (auxiliaryPrimes B) (1 / 2) ac.1 * + primeProductMass (auxiliaryPrimes B) (1 / 2) ac.2) * Kr * F) := + mul_le_mul_of_nonneg_left hrem hB0 + _ = ((B : ℝ) * (∑ ac ∈ amplificationCoefficientPairs B T, + primeProductMass (auxiliaryPrimes B) (1 / 2) ac.1 * + primeProductMass (auxiliaryPrimes B) (1 / 2) ac.2)) * Kr * F := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (hm T hT hTsize) hKr.le) hF + have hc' := hc C T hC hT hTsize + have hu := mul_le_mul_of_nonneg_left (fairFourSubsetFailure_union B L T τ C) hB0 + have hx := mul_nonneg hKc.le (hεr0 B) + have hy := mul_nonneg (mul_nonneg hM0.le hKr.le) (hεc0 B) + dsimp only [K, ε, F] at * + nlinarith only [hu, hc', hrem', hx, hy] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularityIdentity.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularityIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..398fded2a16e845d863f3c646c1a0dbc78d41179 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularityIdentity.lean @@ -0,0 +1,152 @@ +import OAI.NumberTheory.JointDickman.Amplification.DyadicBoxRegularity +import OAI.NumberTheory.JointDickman.Amplification.AmplificationDyadicIdentity + +namespace OAI + +/-! # Exact dyadic recombination of the discarded regularity mass -/ + +namespace JointDickman +open Finset + +open Classical in +noncomputable def discardedAmplificationTerm (B L j : ℕ) (τ C T : ℝ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) : ℝ := + if coefficientTripleRegular B L τ C a b c then 0 else + |(B : ℝ)*amplificationArithmeticTerm B j T g h c b a| + +open Classical in +noncomputable def discardedAmplificationBoxTerm (B L j : ℕ) (τ C T N : ℝ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) : ℝ := + if coefficientTripleRegular B L τ C a b c then 0 else + |(B : ℝ)*amplificationBoxTerm B j T N g h c b a| + +open Classical in +theorem discardedAmplificationBoxTerm_eq (B L j : ℕ) (τ C : ℝ) {T N : ℝ} + (hT : 0 < T) (hN : 0 < N) (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) : + discardedAmplificationBoxTerm B L j τ C T N g h c b a = + discardedAmplificationTerm B L j τ C T g h c b a*dyadicPartitionWeight (c/(N/T)) := by + unfold discardedAmplificationBoxTerm discardedAmplificationTerm + rw [amplificationBoxTerm_eq B j hT hN] + by_cases hr : coefficientTripleRegular B L τ C a b c + · simp only [hr,ite_true,zero_mul] + · simp only [hr,ite_false] + rw [← mul_assoc,abs_mul,abs_of_nonneg (dyadicPartitionWeight_bounds _).1] + +open Classical in +theorem discardedAmplificationBoxTerm_support (B L j : ℕ) (τ C : ℝ) {T N : ℝ} + (hT : 0 < T) (hN : 0 < N) (g h : (auxiliaryPrimes B → Bool) → ℝ) (c b a : ℕ) + (hn : discardedAmplificationBoxTerm B L j τ C T N g h c b a ≠ 0) : + c ∈ Ioc ⌊(1/4 : ℝ)*(N/T)⌋₊ ⌊(17/4 : ℝ)*(N/T)⌋₊ ∧ + b ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊ ∧ + a ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊ := by + apply amplificationBoxTerm_support B j hT hN g h + intro hz + exact hn (by simp [discardedAmplificationBoxTerm,hz]) + +open Classical in +theorem discardedAmplificationBox_sum (B L j : ℕ) (τ C T N : ℝ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) : + (∑ c ∈ Ioc ⌊(1/4 : ℝ)*(N/T)⌋₊ ⌊(17/4 : ℝ)*(N/T)⌋₊, + ∑ b ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊, + ∑ a ∈ Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊, + discardedAmplificationBoxTerm B L j τ C T N g h c b a) = + signedLocalRegularityError B L j τ C + (Ico (tensorIntervalLower N) (tensorIntervalUpper N)) + (Ico (tensorIntervalLower (N/T)) (tensorIntervalUpper (N/T))) g h + (fun a b c => amplificationBoxWeight B (Real.log (N/T)/B) + (a/N) (b/N) (c/(N/T))) := by + have hi (a b : ℕ) : Ico (a+1) (b+1) = Ioc a b := by + ext n + simp only [mem_Ico,mem_Ioc] + omega + unfold signedLocalRegularityError + simp only [tensorIntervalLower,tensorIntervalUpper,hi] + rw [sum_comm] + simp_rw [sum_comm (s := Ioc ⌊(1/4 : ℝ)*(N/T)⌋₊ ⌊(17/4 : ℝ)*(N/T)⌋₊) + (t := Ioc ⌊(1/4 : ℝ)*N⌋₊ ⌊(17/4 : ℝ)*N⌋₊)] + rw [sum_comm] + apply sum_congr rfl + intro a _ + apply sum_congr rfl + intro b _ + apply sum_congr rfl + intro c _ + unfold discardedAmplificationBoxTerm amplificationBoxTerm + by_cases hr : coefficientTripleRegular B L τ C a b c + · rw [ite_eq_left hr,ite_eq_right (show ¬ (a = b+j*c ∧ + ¬ coefficientTripleRegular B L τ C a b c) from fun hh => hh.2 hr)] + · rw [ite_eq_right hr] + by_cases he : a = b+j*c + · rw [ite_eq_left he,ite_eq_left ⟨he,hr⟩] + congr 1 + ring + · rw [ite_eq_right he,ite_eq_right (fun hh => he hh.1)] + simp only [mul_zero,abs_zero] + +open Classical in +theorem discarded_amplification_dyadic_identity {B : ℕ} (hB : 30 ≤ B) {T : ℝ} + (hT : 1 ≤ T) (hlogT : Real.log T ≤ (B : ℝ)/10) (L j U V : ℕ) (τ C : ℝ) + (g h : (auxiliaryPrimes B → Bool) → ℝ) + (hU : ∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ ≤ U) + (hV : ∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊ ≤ V) : + (∑ c ∈ Ioc 0 V, ∑ b ∈ Ioc 0 U, ∑ a ∈ Ioc 0 U, + discardedAmplificationTerm B L j τ C T g h c b a) = + ∑ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + signedLocalRegularityError B L j τ C + (Ico (tensorIntervalLower (Real.exp ((k : ℝ)*Real.log 2))) + (tensorIntervalUpper (Real.exp ((k : ℝ)*Real.log 2)))) + (Ico (tensorIntervalLower (Real.exp ((k : ℝ)*Real.log 2)/T)) + (tensorIntervalUpper (Real.exp ((k : ℝ)*Real.log 2)/T))) g h + (fun a b c => amplificationBoxWeight B (Real.log (Real.exp ((k : ℝ)*Real.log 2)/T)/B) + (a/Real.exp ((k : ℝ)*Real.log 2)) (b/Real.exp ((k : ℝ)*Real.log 2)) + (c/(Real.exp ((k : ℝ)*Real.log 2)/T))) := by + have hTpos := lt_of_lt_of_le zero_lt_one hT + let S := dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T) + obtain ⟨hLU,_,hbracket⟩ := dyadic_scale_window hB hT hlogT + symm + simp_rw [← discardedAmplificationBox_sum] + change (∑ k ∈ S, ∑ c ∈ _, ∑ b ∈ _, ∑ a ∈ _, + discardedAmplificationBoxTerm B L j τ C T (Real.exp ((k : ℝ)*Real.log 2)) g h c b a) = _ + calc + _ = ∑ k ∈ S, ∑ c ∈ Ioc 0 V, ∑ b ∈ Ioc 0 U, ∑ a ∈ Ioc 0 U, + discardedAmplificationBoxTerm B L j τ C T (Real.exp ((k : ℝ)*Real.log 2)) g h c b a := by + apply sum_congr rfl + intro k hk + apply finite_triple_sum_extend + · intro n hn + obtain ⟨hnl,hnu⟩ := mem_Ioc.mp hn + exact mem_Ioc.mpr ⟨Nat.lt_of_le_of_lt (Nat.zero_le _) hnl,hnu.trans (hU k hk)⟩ + · intro n hn + obtain ⟨hnl,hnu⟩ := mem_Ioc.mp hn + exact mem_Ioc.mpr ⟨Nat.lt_of_le_of_lt (Nat.zero_le _) hnl,hnu.trans (hV k hk)⟩ + · exact discardedAmplificationBoxTerm_support B L j τ C hTpos (Real.exp_pos _) g h + _ = ∑ c ∈ Ioc 0 V, ∑ b ∈ Ioc 0 U, ∑ a ∈ Ioc 0 U, + ∑ k ∈ S, discardedAmplificationBoxTerm B L j τ C T + (Real.exp ((k : ℝ)*Real.log 2)) g h c b a := + sum_triple_interchange S (Ioc 0 U) (Ioc 0 V) _ + _ = _ := by + apply sum_congr rfl + intro c hc + apply sum_congr rfl + intro b _ + apply sum_congr rfl + intro a _ + simp_rw [discardedAmplificationBoxTerm_eq B L j τ C hTpos (Real.exp_pos _) g h c b a, + div_div_eq_mul_div] + rw [← mul_sum] + by_cases he : discardedAmplificationTerm B L j τ C T g h c b a = 0 + · simp [he] + · have harith : amplificationArithmeticTerm B j T g h c b a ≠ 0 := by + intro hz + exact he (by simp [discardedAmplificationTerm,hz]) + have hBp : 0 < B := lt_of_lt_of_le (by norm_num) hB + obtain ⟨hlo,hhi⟩ := amplificationArithmeticTerm_log_support hBp j T g h c b a harith + have hcp : (0 : ℝ) < c := by exact_mod_cast (mem_Ioc.mp hc).1 + obtain ⟨hcl,hcu⟩ := hbracket c hcp hlo hhi + rw [geometric_dyadic_partition hLU (c*T) hcl hcu,mul_one] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularityLoss.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularityLoss.lean new file mode 100644 index 0000000000000000000000000000000000000000..c3f17d4846dcf101bc51c8441f343b50d579853a --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationRegularityLoss.lean @@ -0,0 +1,85 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationRegularityIdentity +import Mathlib.Analysis.Complex.ExponentialBounds + +namespace OAI + +/-! # The unpartitioned signed regularity error in the amplification argument -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +theorem dyadicBoxIndices_card_bound {B : ℕ} (hB : 30 ≤ B) {T : ℝ} + (hT : 1 ≤ T) (hlog : Real.log T ≤ (B : ℝ)/10) : + ((dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T)).card : ℝ) ≤ 5*B := by + have hBr : (30 : ℝ) ≤ B := by exact_mod_cast hB + have hlog2 : (1/2 : ℝ) ≤ Real.log 2 := by linarith [Real.log_two_gt_d9] + have hnon : 0 ≤ (2*(B : ℝ)+Real.log T)/Real.log 2 := + div_nonneg (by linarith [Real.log_nonneg hT]) (by linarith) + have hceil := Nat.ceil_lt_add_one hnon + have hfrac : (2*(B : ℝ)+Real.log T)/Real.log 2 ≤ (21/5 : ℝ)*B := by + apply (div_le_iff₀ (by linarith : 0 < Real.log 2)).mpr + nlinarith + have hU : (dyadicBoxUpper B T : ℝ) ≤ 5*B := by + simp only [dyadicBoxUpper,Nat.cast_add,Nat.cast_one] + linarith + have hcard : (dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T)).card ≤ + dyadicBoxUpper B T := by + unfold dyadicBoxIndices + exact card_image_le.trans (by rw [Nat.card_Ico]; exact Nat.sub_le _ _) + exact (by exact_mod_cast hcard : + ((dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T)).card : ℝ) ≤ + dyadicBoxUpper B T).trans hU + +open Classical in +/-- The published sieve input controls the entire signed smooth regularity +loss; the dyadic number of boxes cancels the local factor 1/B. -/ +theorem amplification_signed_regularity_loss + (hFord : PublishedInputs.FordUpperSieveInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) : + ∃ K : ℝ, 0 < K ∧ ∀ L : ℕ, ∀ τ : ℝ, 0 < L → 0 < τ → + ∃ ε : ℕ → ℝ, (∀ B, 0 ≤ ε B) ∧ Tendsto ε atTop (𝓝 0) ∧ + ∀ᶠ B : ℕ in atTop, ∀ T : ℝ, 1 ≤ T → Real.log T ≤ (B : ℝ)/10 → + ∀ (C : ℝ) (j U V : ℕ), 0 ≤ C → j ≠ 0 → + (∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*Real.exp ((k : ℝ)*Real.log 2)⌋₊ ≤ U) → + (∀ k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + ⌊(17/4 : ℝ)*(Real.exp ((k : ℝ)*Real.log 2)/T)⌋₊ ≤ V) → + ∀ g h : (auxiliaryPrimes B → Bool) → ℝ, + (∀ x, |g x| ≤ 1) → (∀ x, |h x| ≤ 1) → + (∑ c ∈ Ioc 0 V, ∑ b ∈ Ioc 0 U, ∑ a ∈ Ioc 0 U, + discardedAmplificationTerm B L j τ C T g h c b a) ≤ + K/T*singularFactor 24 j*(ε B+Real.exp (-(1/10 : ℝ)*C)) := by + obtain ⟨K,hK,hbox⟩ := dyadicBox_signed_regularity_loss hFord hM + refine ⟨5*K,by positivity,?_⟩ + intro L τ hL hτ + obtain ⟨ε,hε0,hε,hbox⟩ := hbox L τ hL hτ + refine ⟨ε,hε0,hε,?_⟩ + filter_upwards [hbox,eventually_ge_atTop 30] with B hb hB + intro T hT hlog C j U V hC hj hU hV g h hg hh + rw [discarded_amplification_dyadic_identity hB hT hlog L j U V τ C g h hU hV] + have hT0 : 0 < T := lt_of_lt_of_le zero_lt_one hT + have hB0 : (0 : ℝ) < B := by exact_mod_cast (show 0 < B by omega) + have hA0 : 0 ≤ K/((B : ℝ)*T)*singularFactor 24 j* + (ε B+Real.exp (-(1/10 : ℝ)*C)) := by + apply mul_nonneg + · exact mul_nonneg (by positivity) + (zero_le_one.trans (singularFactor_one_le (by norm_num) j)) + · exact add_nonneg (hε0 B) (Real.exp_pos _).le + calc + _ ≤ ∑ _k ∈ dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T), + K/((B : ℝ)*T)*singularFactor 24 j*(ε B+Real.exp (-(1/10 : ℝ)*C)) := by + apply sum_le_sum + intro k hk + exact hb T hT hlog k hk C j hC hj g h hg hh + _ = ((dyadicBoxIndices (dyadicBoxLower B T) (dyadicBoxUpper B T)).card : ℝ)* + (K/((B : ℝ)*T)*singularFactor 24 j*(ε B+Real.exp (-(1/10 : ℝ)*C))) := by + rw [sum_const,nsmul_eq_mul] + _ ≤ (5*(B : ℝ))*(K/((B : ℝ)*T)*singularFactor 24 j* + (ε B+Real.exp (-(1/10 : ℝ)*C))) := + mul_le_mul_of_nonneg_right (dyadicBoxIndices_card_bound hB hT hlog) hA0 + _ = _ := by field_simp + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationReindex.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationReindex.lean new file mode 100644 index 0000000000000000000000000000000000000000..445126c38b6a8e0a3cf92ab90a8d10827854566f --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationReindex.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.DivisorReindex + +namespace OAI + +/-! # Reindexing the actual arithmetic amplification into a divisor form -/ + +namespace JointDickman +open Finset + +noncomputable def arithmeticResidueWeight (B L : ℕ) (τ C : ℝ) (n : ℕ) : ℝ := + regularResidueWeight B L τ C (coefficientPrimeSet B n) + +open Classical in +noncomputable def amplificationDivisorForm (B L : ℕ) (τ C : ℝ) + (w : ℕ → ℕ → ℝ) (H : ℕ → ℂ) (N : ℕ) : ℂ := + ∑ A ∈ (auxiliaryPrimes B).powerset, ∑ D ∈ (auxiliaryPrimes B).powerset, + let a := ∏ p ∈ A, p + let c := ∏ p ∈ D, p + ∑ m ∈ range N, if a*m < N ∧ c ∣ a*m+1 then + H (a*m) * (((regularCoefficientWeight B L τ C a * arithmeticResidueWeight B L τ C m) * + (regularCoefficientWeight B L τ C c * arithmeticResidueWeight B L τ C ((a*m+1)/c)) * + w a c : ℝ) : ℂ) else 0 + +theorem sum_two_divisors_reindex {a c : ℕ} (ha : 0 < a) (N : ℕ) + (H : ℕ → ℂ) (F : ℕ → ℕ → ℂ) : + (∑ n ∈ range N, if a ∣ n ∧ c ∣ n+1 then H n * F (n/a) ((n+1)/c) else 0) = + ∑ m ∈ range N, if a*m < N ∧ c ∣ a*m+1 then H (a*m) * F m ((a*m+1)/c) else 0 := by + classical + have h := sum_dvd_ite_reindex ha N + (fun n => if c ∣ n+1 then H n * F (n/a) ((n+1)/c) else 0) + simpa only [ite_and, Nat.mul_div_cancel_left _ ha, ite_self] using h + +/-- The finite first-form identity, including the precise endpoint. -/ +theorem arithmeticAmplification_reindex (B L : ℕ) (τ C : ℝ) + (w : ℕ → ℕ → ℝ) (H : ℕ → ℂ) (N : ℕ) : + (∑ n ∈ range N, H n * (arithmeticSubsetAmplification B L τ C w n : ℂ)) = + (1 / (B : ℂ)) * amplificationDivisorForm B L τ C w H N := by + classical + let F (n : ℕ) (A D : Finset ℕ) : ℂ := + if (∏ p ∈ A, p) ∣ n ∧ (∏ p ∈ D, p) ∣ n+1 then + H n * (((regularCoefficientWeight B L τ C (∏ p ∈ A, p) * + arithmeticResidueWeight B L τ C (n/(∏ p ∈ A, p))) * + (regularCoefficientWeight B L τ C (∏ p ∈ D, p) * + arithmeticResidueWeight B L τ C ((n+1)/(∏ p ∈ D, p))) * + w (∏ p ∈ A, p) (∏ p ∈ D, p) : ℝ) : ℂ) else 0 + have he (n : ℕ) : H n * (arithmeticSubsetAmplification B L τ C w n : ℂ) = + (1 / (B : ℂ)) * ∑ A ∈ (auxiliaryPrimes B).powerset, + ∑ D ∈ (auxiliaryPrimes B).powerset, F n A D := by + unfold arithmeticSubsetAmplification + simp only [Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_one, + Complex.ofReal_natCast, Complex.ofReal_sum] + rw [mul_left_comm, mul_sum] + congr 1 + apply sum_congr rfl + intro A _ + rw [mul_sum] + apply sum_congr rfl + intro D _ + dsimp only [F, arithmeticResidueWeight] + split_ifs <;> simp only [Complex.ofReal_mul, Complex.ofReal_zero, mul_zero] + simp_rw [he] + rw [← mul_sum] + congr 1 + rw [sum_comm] + unfold amplificationDivisorForm + apply sum_congr rfl + intro A hA + rw [sum_comm] + apply sum_congr rfl + intro D _ + have ha : 0 < ∏ p ∈ A, p := prod_pos (fun p hp => + (auxiliaryPrimes_prime B p (mem_powerset.mp hA hp)).pos) + exact sum_two_divisors_reindex ha N H + (fun m l => (((regularCoefficientWeight B L τ C (∏ p ∈ A, p) * + arithmeticResidueWeight B L τ C m) * + (regularCoefficientWeight B L τ C (∏ p ∈ D, p) * arithmeticResidueWeight B L τ C l) * + w (∏ p ∈ A, p) (∏ p ∈ D, p) : ℝ) : ℂ)) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationScaleSum.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationScaleSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..a13d0327b0e00038a9f3d28a0a9549d5e7d712fe --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationScaleSum.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.JointDickman.Amplification.DyadicTailSum + +namespace OAI + +/-! # The convergent scale sum in the amplification second moment -/ + +namespace JointDickman + +open Filter Finset +open scoped Topology + +theorem amplification_scale_sum (S : Finset ℕ) {B L : ℝ} + (hB : 0 < B) (hL : 0 < L) + (hcap : ∀ i ∈ S, (2 : ℝ)^i * L ≤ 8 * B) : + (∑ i ∈ S, (((2 : ℝ)^i * L) / B)^amplificationExponent / ((2 : ℝ)^i * L)) ≤ + ((8 : ℝ)^(amplificationExponent - 1) * + ((2 : ℝ)^(amplificationExponent - 1) / + ((2 : ℝ)^(amplificationExponent - 1) - 1))) / B := by + have ha : 0 < amplificationExponent - 1 := sub_pos.mpr amplificationExponent_gt_one + have heq (i : ℕ) : + (((2 : ℝ)^i * L) / B)^amplificationExponent / ((2 : ℝ)^i * L) = + (8 : ℝ)^(amplificationExponent - 1) / B * + (((2 : ℝ)^i * L) / (8 * B))^(amplificationExponent - 1) := by + have hx : 0 < (2 : ℝ)^i * L := by positivity + have hratio : ((2 : ℝ)^i * L) / B = 8 * (((2 : ℝ)^i * L) / (8 * B)) := by field_simp + have hpow : (((2 : ℝ)^i * L) / B)^(amplificationExponent - 1) = + (8 : ℝ)^(amplificationExponent - 1) * + (((2 : ℝ)^i * L) / (8 * B))^(amplificationExponent - 1) := by + rw [hratio, Real.mul_rpow (by norm_num) (by positivity)] + calc + _ = (((2 : ℝ)^i * L) / B)^(amplificationExponent - 1) / B := by + rw [Real.rpow_sub (div_pos hx hB), Real.rpow_one] + field_simp + _ = _ := by rw [hpow]; ring + simp_rw [heq] + rw [← mul_sum] + have hsum := dyadic_power_sum_bound S (mul_pos (by norm_num : (0 : ℝ) < 8) hB) + hL.le ha hcap + have hh := mul_le_mul_of_nonneg_left hsum + (by positivity : (0 : ℝ) ≤ (8 : ℝ)^(amplificationExponent - 1) / B) + convert hh using 1; ring + +/-- The no-change contribution, including the outside factor B, tends to zero. -/ +theorem amplification_no_change_tendsto : + Tendsto (fun B : ℕ => (B : ℝ) * (auxiliaryRatio B)^(-amplificationExponent)) + atTop (𝓝 0) := by + have ht := amplification_log_loss.comp tendsto_natCast_atTop_atTop + apply ht.congr' + filter_upwards [eventually_gt_atTop 1] with B hB + have hB0 : (0 : ℝ) < B := by exact_mod_cast (lt_trans Nat.zero_lt_one hB) + have hlog : 0 < Real.log (B : ℝ) := Real.log_pos (by exact_mod_cast hB) + rw [auxiliaryRatio, Real.rpow_neg (by positivity : (0 : ℝ) ≤ B / (1000 * Real.log B)), + Real.div_rpow hB0.le (by positivity)] + dsimp only [Function.comp_def] + field_simp + +/-- Four regular high-prime sets supply the exponent strictly exceeding one. -/ +theorem four_tail_coin_bound {B Y C : ℝ} {n : ℕ} + (hB : 0 < B) (hY : 0 < Y) + (hn : 4 * ((2 / 5 : ℝ) * Real.log (B / Y) - C) ≤ (n : ℝ)) : + (1 / 2 : ℝ)^n ≤ (2 : ℝ)^(4 * C) * (Y / B)^amplificationExponent := by + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hpow : (1 / 2 : ℝ)^n = Real.exp (-(n : ℝ) * Real.log 2) := by + rw [← Real.rpow_natCast, Real.rpow_def_of_pos (by norm_num), + show Real.log (1 / 2 : ℝ) = -Real.log 2 by rw [one_div, Real.log_inv]] + congr 1 + ring + rw [hpow, Real.rpow_def_of_pos (by norm_num : (0 : ℝ) < 2), + Real.rpow_def_of_pos (div_pos hY hB), ← Real.exp_add] + apply Real.exp_le_exp.mpr + have hlogs : Real.log (Y / B) = -Real.log (B / Y) := by + rw [Real.log_div hY.ne' hB.ne', Real.log_div hB.ne' hY.ne'] + ring + rw [hlogs] + have hh := mul_le_mul_of_nonneg_right hn hlog2.le + unfold amplificationExponent + nlinarith only [hh] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationSquareRate.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationSquareRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0c72a4453790b298ea3da9897382ea0cd6f98aa --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationSquareRate.lean @@ -0,0 +1,27 @@ +import OAI.NumberTheory.JointDickman.Amplification.AmplificationMultiplier + +namespace OAI + +/-! # The model's inverse-length row moment is smaller than the sampling scale -/ +namespace JointDickman +open Filter +open scoped Topology + +theorem amplification_inverse_square_rate (C : ℝ) : + ∀ᶠ B : ℕ in atTop, C/(amplificationMultiplier B : ℝ) ≤ (B : ℝ)^(-(21/100 : ℝ)) := by + have ht := (power_div_amplificationMultiplier (by norm_num : (21/100 : ℝ) < 8/25)).const_mul C + have ht' : Tendsto (fun B : ℕ => C*((B : ℝ)^(21/100 : ℝ)/amplificationMultiplier B)) + atTop (𝓝 0) := by simpa only [mul_zero] using ht + filter_upwards [ht'.eventually (eventually_le_nhds (by norm_num : (0 : ℝ) < 1)), + eventually_gt_atTop 0] with B hb hB + have hBp : (0 : ℝ) < B := by exact_mod_cast hB + have hp : 0 < (B : ℝ)^(21/100 : ℝ) := Real.rpow_pos_of_pos hBp _ + rw [Real.rpow_neg hBp.le,← one_div] + apply (le_div_iff₀ hp).mpr + calc + _ = C*((B : ℝ)^(21/100 : ℝ)/amplificationMultiplier B) := by ring + _ ≤ 1 := hb + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationVolumeProducts.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationVolumeProducts.lean new file mode 100644 index 0000000000000000000000000000000000000000..f91680ad927548fbf38b66217f760808a99786b1 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationVolumeProducts.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.JointDickman.Probability.ResidueProductMean +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticPeriod +import OAI.NumberTheory.JointDickman.Amplification.AuxiliaryOdds + +namespace OAI + +/-! # The coefficient harmonic mass cancels the residue-weight mean -/ + +namespace JointDickman +open Finset + +noncomputable def baseArithmeticResidueWeight (B n : ℕ) : ℝ := + residueBaseWeight B (coefficientPrimeSet B n) + +noncomputable def baseArithmeticResidueMean (B : ℕ) : ℝ := + auxiliaryRatio B ^ (1/2 : ℝ) * primeNormalizer (auxiliaryPrimes B) (1/2) + +theorem baseArithmeticResidueWeight_product (B n : ℕ) : + baseArithmeticResidueWeight B n = auxiliaryRatio B ^ (1/2 : ℝ) * + ∏ p ∈ auxiliaryPrimes B, if p ∣ n then (1/2 : ℝ) else 1 := by + unfold baseArithmeticResidueWeight residueBaseWeight coefficientPrimeSet + rw [← prod_const, prod_filter] + +theorem baseArithmeticResidueWeight_mean (B : ℕ) : + (∑ a : ZMod (auxiliarySquarePeriod B), baseArithmeticResidueWeight B a.val) / + (auxiliarySquarePeriod B : ℝ) = baseArithmeticResidueMean B := by + have hd : (∏ p ∈ auxiliaryPrimes B, p) ∣ auxiliarySquarePeriod B := by + unfold auxiliarySquarePeriod + exact dvd_pow_self _ (by norm_num : 2 ≠ 0) + have h := residue_divisor_product_mean (auxiliaryPrimes B) (auxiliaryPrimes_prime B) hd + (fun _ => (-1/2 : ℝ)) + simp only [show (1 : ℝ) + -1/2 = 1/2 by norm_num] at h + simp_rw [baseArithmeticResidueWeight_product] + rw [← mul_sum, mul_div_assoc, h] + unfold baseArithmeticResidueMean primeNormalizer + congr 1 + apply prod_congr rfl + intro p _ + ring + +theorem coefficient_harmonic_product (B : ℕ) : + (∑ D ∈ (auxiliaryPrimes B).powerset, + coefficientWeight B (∏ p ∈ D, p) / (∏ p ∈ D, (p : ℝ))) = + coefficientScale B * ∏ p ∈ auxiliaryPrimes B, (1 + (1/2 : ℝ)/p) := by + rw [prod_one_add, mul_sum] + apply sum_congr rfl + intro D hD + rw [coefficientWeight_primeProduct (mem_powerset.mp hD)] + simp only [residueBaseWeight, coefficientScale, prod_div_distrib, prod_const, one_div] + ring + +/-- This exact finite cancellation bounds the Cauchy volume without a +further interval asymptotic: the leftover Euler factors are at most one. -/ +theorem coefficient_harmonic_mul_residueMean_le {B : ℕ} (hB : 1 < B) : + (∑ D ∈ (auxiliaryPrimes B).powerset, + coefficientWeight B (∏ p ∈ D, p) / (∏ p ∈ D, (p : ℝ))) * + baseArithmeticResidueMean B ≤ B := by + rw [coefficient_harmonic_product, baseArithmeticResidueMean] + have he : (coefficientScale B * ∏ p ∈ auxiliaryPrimes B, (1+(1/2 : ℝ)/p)) * + (auxiliaryRatio B^(1/2 : ℝ) * primeNormalizer (auxiliaryPrimes B) (1/2)) = + (B : ℝ) * ∏ p ∈ auxiliaryPrimes B, (1 - ((1/2 : ℝ)/p)^2) := by + rw [mul_mul_mul_comm, coefficientScale_mul_sqrt_ratio hB] + unfold primeNormalizer + rw [← prod_mul_distrib] + congr 1 + apply prod_congr rfl + intro p _ + ring + rw [he] + apply mul_le_of_le_one_right (Nat.cast_nonneg B) + apply prod_le_one₀ + · intro p hp + have hp2 : (2 : ℝ) ≤ p := by exact_mod_cast (auxiliaryPrimes_prime B p hp).two_le + have hp0 : (0 : ℝ) < p := by linarith + have hd : (1/2 : ℝ)/p ≤ 1 := (div_le_one hp0).mpr (by linarith) + have hn : 0 ≤ (1/2 : ℝ)/p := by positivity + nlinarith + · intro p _ + exact sub_le_self _ (sq_nonneg _) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationWeightBound.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationWeightBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..3523f2ee7fb6f703b65d58547edbdfb08a895478 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplificationWeightBound.lean @@ -0,0 +1,75 @@ +import OAI.NumberTheory.JointDickman.Probability.AmplificationFairKernel +import OAI.NumberTheory.JointDickman.Counting.CoefficientProductSupport + +namespace OAI + +/-! # The unique-quotient bound used when removing coprimality -/ + +namespace JointDickman +open Finset + +open Classical in +theorem amplificationScalarWeight_bounds (B j : ℕ) (T : ℝ) (c b a : ℕ) : + 0 ≤ amplificationScalarWeight B j T c b a ∧ + amplificationScalarWeight B j T c b a ≤ coefficientScale B := by + unfold amplificationScalarWeight + split_ifs + · have h1 := amplificationBump_bounds (Real.log c/B) + have h2 := amplificationBump_bounds (a/(T*c)) + have h3 := amplificationBump_bounds (b/(T*c)) + have hprod : 0 ≤ amplificationBump (Real.log c/B)*amplificationBump (a/(T*c))* + amplificationBump (b/(T*c)) := mul_nonneg (mul_nonneg h1.1 h2.1) h3.1 + have hprod1 : amplificationBump (Real.log c/B)*amplificationBump (a/(T*c))* + amplificationBump (b/(T*c)) ≤ 1 := by + calc + _ ≤ (1 : ℝ)*1*1 := mul_le_mul (mul_le_mul h1.2 h2.2 h2.1 (by norm_num)) + h3.2 h3.1 (by norm_num) + _ = _ := by norm_num + exact ⟨mul_nonneg (coefficientWeight_nonneg B c) hprod, + (mul_le_of_le_one_right (coefficientWeight_nonneg B c) hprod1).trans + (coefficientWeight_le_scale B c)⟩ + · exact ⟨le_rfl,coefficientScale_nonneg B⟩ + +open Classical in +theorem amplificationScalarWeight_sum_le (B : ℕ) {j : ℕ} (hj : 0 < j) + (T : ℝ) (V a b : ℕ) : + (∑ c ∈ Ioc 0 V, amplificationScalarWeight B j T c b a) ≤ coefficientScale B := by + let C := (Ioc 0 V).filter (fun c => a = b+j*c) + have hcard : C.card ≤ 1 := by + apply card_le_one.mpr + intro c hc d hd + have hc' := (mem_filter.mp hc).2 + have hd' := (mem_filter.mp hd).2 + exact Nat.mul_left_cancel hj (Nat.add_left_cancel (hc'.symm.trans hd')) + calc + _ = ∑ c ∈ C, amplificationScalarWeight B j T c b a := by + symm + apply sum_subset (filter_subset _ _) + intro c hc hnot + have hrel : a ≠ b+j*c := by + intro he + exact hnot (mem_filter.mpr ⟨hc,he⟩) + simp [amplificationScalarWeight,hrel] + _ ≤ ∑ _c ∈ C, coefficientScale B := + sum_le_sum (fun c _ => (amplificationScalarWeight_bounds B j T c b a).2) + _ = (C.card : ℝ)*coefficientScale B := by simp + _ ≤ (1 : ℝ)*coefficientScale B := + mul_le_mul_of_nonneg_right (by exact_mod_cast hcard) (coefficientScale_nonneg B) + _ = _ := one_mul _ + +open Classical in +noncomputable def amplificationProductWeight (B j : ℕ) (T : ℝ) (V a b : ℕ) : ℝ := + B*∑ c ∈ Ioc 0 V, amplificationScalarWeight B j T c b a + +theorem amplificationProductWeight_bounds (B : ℕ) {j : ℕ} (hj : 0 < j) + (T : ℝ) (V a b : ℕ) : + 0 ≤ amplificationProductWeight B j T V a b ∧ + amplificationProductWeight B j T V a b ≤ (B : ℝ)*coefficientScale B := by + unfold amplificationProductWeight + exact ⟨mul_nonneg (Nat.cast_nonneg _) (sum_nonneg + (fun c _ => (amplificationScalarWeight_bounds B j T c b a).1)), + mul_le_mul_of_nonneg_left (amplificationScalarWeight_sum_le B hj T V a b) (Nat.cast_nonneg _)⟩ + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplifiedProfile.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplifiedProfile.lean new file mode 100644 index 0000000000000000000000000000000000000000..99f3d6afb62f47a81dca0898269396835cf0f215 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplifiedProfile.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticProfilePreservation +import OAI.NumberTheory.JointDickman.Probability.ResidueProfileLimits + +namespace OAI + +/-! # Nonzero arithmetic correlations survive smooth amplification -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +theorem amplification_norm_lower {β : ℂ} (hβ : β ≠ 0) {d : ℝ} (hd : 0 < d) + (u : ℕ → ℂ) (m : ℕ → ℝ) + (hm : ∀ᶠ B : ℕ in atTop, d ≤ m B) + (he : Tendsto (fun B => u B - β * (m B : ℂ)) atTop (nhds 0)) : + ∀ᶠ B : ℕ in atTop, d/2 * ‖β‖ ≤ ‖u B‖ := by + have hpos : 0 < d/2 * ‖β‖ := mul_pos (half_pos hd) (norm_pos_iff.mpr hβ) + have he' := (Metric.tendsto_nhds.mp he) (d/2 * ‖β‖) hpos + filter_upwards [hm,he'] with B hB heB + rw [dist_zero_right] at heB + have hm0 : 0 ≤ m B := le_trans hd.le hB + have ht := norm_sub_le (u B) (u B - β * (m B : ℂ)) + have hid : u B - (u B - β * (m B : ℂ)) = β * (m B : ℂ) := by ring + rw [hid, norm_mul, Complex.norm_real, Real.norm_eq_abs, abs_of_nonneg hm0] at ht + nlinarith [mul_le_mul_of_nonneg_right hB (norm_nonneg β)] + +/-- The positive lower constant is independent of the later fixed regularity +cutoff. The outer limit is still conditional only on the cited analytic inputs. -/ +theorem smooth_amplified_profile_lower + (hFord : PublishedInputs.FordUpperSieveInput) + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (hMP : PublishedInputs.PrimeProductMertensInput) + (W : ResidueProfile) (hW : W.mean ≠ 0) : + ∃ d : ℝ, 0 < d ∧ ∀ (L : ℕ) (τ : ℝ), 0 < L → 0 < τ → + ∃ C₀ : ℝ, 0 ≤ C₀ ∧ ∀ C : ℝ, C₀ ≤ C → ∀ T : ℕ → ℕ, + (∀ᶠ B : ℕ in atTop, 0 < T B ∧ (T B : ℝ) ≤ Real.exp ((1/10 : ℝ)*B)) → + ∀ᶠ B : ℕ in atTop, d * ‖W.mean‖ ≤ + ‖W.correlation (amplificationPeriod B) (smoothResidueAmplification B L τ C (T B))‖ := by + obtain ⟨d,hd,hl⟩ := smooth_arithmetic_first_lower hFord hSD hM hMP + refine ⟨d/2,half_pos hd,?_⟩ + intro L τ hL hτ + obtain ⟨C₀,hC₀,hb⟩ := hl L τ hL hτ + refine ⟨C₀,hC₀,?_⟩ + intro C hC T hT + apply amplification_norm_lower hW hd + (fun B => W.correlation (amplificationPeriod B) (smoothResidueAmplification B L τ C (T B))) + (fun B => arithmeticAmplificationMoment B L τ C (amplificationSmoothWeight B (T B)) 1) + · filter_upwards [hb,hT] with B hB hTB + exact hB C (T B) hC hTB.1 hTB.2 + · exact smooth_arithmetic_profile_preservation hFord hM W L τ C T hT + +/-- A single extracted subsequence supplies all the inner arithmetic limits. +The profile and its bounds are constructed from the bounded array. -/ +theorem exists_arithmetic_amplification_profile (H : ℕ → ℕ → ℂ) {C : ℝ} + (hC : 0 ≤ C) (hH : ∀ N n, ‖H N n‖ ≤ C) {β : ℂ} + (hmean : Tendsto (fun N => (∑ n ∈ range N, H N n) / (N : ℂ)) atTop (nhds β)) : + ∃ (s : ℕ → ℕ), StrictMono s ∧ ∃ W : ResidueProfile, W.mean = β ∧ + ∀ (B L : ℕ) (τ C' : ℝ) (T : ℕ), + Tendsto (fun N => (∑ n ∈ range (s N), H (s N) n * + (arithmeticSubsetAmplification B L τ C' (amplificationSmoothWeight B T) n : ℂ)) / (s N : ℂ)) + atTop (nhds (W.correlation (amplificationPeriod B) + (smoothResidueAmplification B L τ C' T))) := by + obtain ⟨s,hs,W,_,hW⟩ := exists_residueProfile H hC hH + have hm := hW 1 (fun _ => 1) + simp only [empiricalResidueTest, mul_one] at hm + have hβ : W.mean = β := tendsto_nhds_unique hm (hmean.comp hs.tendsto_atTop) + refine ⟨s,hs,W,hβ,?_⟩ + intro B L τ C' T + have h := hW (amplificationPeriod B) (smoothResidueAmplification B L τ C' T) + have he (n : ℕ) : smoothResidueAmplification B L τ C' T (n : ZMod (amplificationPeriod B : ℕ)) = + (arithmeticSubsetAmplification B L τ C' (amplificationSmoothWeight B T) n : ℂ) := by + exact congrArg (fun r : ℝ => (r : ℂ)) + (residueAmplification_natCast B L n τ C' (amplificationSmoothWeight B T)) + simpa only [empiricalResidueTest, he, ResidueProfile.correlation] using h + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AmplitudeParameterVariation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplitudeParameterVariation.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6edb56c92f94eeab20bda418b949dbd38b2b975 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AmplitudeParameterVariation.lean @@ -0,0 +1,45 @@ +import OAI.NumberTheory.JointDickman.Counting.CoarseCoefficientVariation + +namespace OAI + +/-! # Variation of coarse coefficients under changing box amplitudes -/ +namespace JointDickman +open Finset Classical + +theorem endpointSpatialWeight_amplitude_difference (m B : ℕ) (t β : ℝ) + (d e : ℤ → ℝ) (w₁ w₂ w : ℝ → ℝ) {D M₁ M₂ M₀ : ℝ} + (hD : 0 ≤ D) (hM₁ : 0 ≤ M₁) (hM₂ : 0 ≤ M₂) + (k : ℤ) (hd : |d k-e k| ≤ D) (hw₁ : ∀ z, |w₁ z| ≤ M₁) + (hw₂ : ∀ z, |w₂ z| ≤ M₂) (hw : ∀ z, |w z| ≤ M₀) + (i j : Fin (channelFineCount m B)) : + |endpointSpatialWeight m B t β d w₁ w₂ w k i j- + endpointSpatialWeight m B t β e w₁ w₂ w k i j| ≤ D*M₁*M₂*M₀ := by + let x := Real.exp ((B : ℝ)*channelLower (channelFineCount m B) i)/Real.exp ((k : ℝ)*t) + let y := Real.exp ((B : ℝ)*channelLower (channelFineCount m B) j)/Real.exp ((k : ℝ)*t) + change |d k*w₁ x*w₂ y*w (β*x-β*y)-e k*w₁ x*w₂ y*w (β*x-β*y)| ≤ _ + rw [show d k*w₁ x*w₂ y*w (β*x-β*y)-e k*w₁ x*w₂ y*w (β*x-β*y) = + (d k-e k)*w₁ x*w₂ y*w (β*x-β*y) by ring] + simp only [abs_mul] + exact mul_le_mul (mul_le_mul (mul_le_mul hd (hw₁ x) (abs_nonneg _) hD) + (hw₂ y) (abs_nonneg _) (mul_nonneg hD hM₁)) (hw _) (abs_nonneg _) + (mul_nonneg (mul_nonneg hD hM₁) hM₂) + +theorem geometric_coarseCoefficient_amplitude_difference {m B : ℕ} + (hm : 0 < m) (hB : 1 ≤ B) {t L U β D M₁ M₂ M₀ : ℝ} + (ht : 0 < t) (hLU : L ≤ U) (hD : 0 ≤ D) (hM₁ : 0 ≤ M₁) + (hM₂ : 0 ≤ M₂) (hM₀ : 0 ≤ M₀) + (S : Finset ℤ) (d e : ℤ → ℝ) (w₁ w₂ w : ℝ → ℝ) + (hd : ∀ k ∈ S, |d k-e k| ≤ D) (hw₁ : ∀ z, |w₁ z| ≤ M₁) + (hw₂ : ∀ z, |w₂ z| ≤ M₂) (hw : ∀ z, |w z| ≤ M₀) (a b : Fin m) : + |primeCoarseCoefficient m B + (geometricWindowKernel m B t L U S (endpointSpatialWeight m B t β d w₁ w₂ w)) a b- + primeCoarseCoefficient m B + (geometricWindowKernel m B t L U S (endpointSpatialWeight m B t β e w₁ w₂ w)) a b| ≤ + channelMesh m*(2*(((1+U-L)/t+1)*(D*M₁*M₂*M₀))*(U-L+2)) := by + exact geometric_coarseCoefficient_difference hm hB ht hLU (by positivity) S _ _ + (fun k hk i j _ _ => endpointSpatialWeight_amplitude_difference m B t β d e w₁ w₂ w + hD hM₁ hM₂ k (hd k hk) hw₁ hw₂ hw i j) a b + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithGraph.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..e827345629c82f2a91e7a141150467205d1d10f1 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithGraph.lean @@ -0,0 +1,62 @@ +import Mathlib.RingTheory.Coprime.Basic +import Mathlib.Tactic + +namespace OAI + +/-! +# Exact arithmetic reindexing in the divisor graph + +The change of variables turns two divisor representations into an additive +edge. The underlying integer identities hold in both directions without +asymptotic hypotheses. +-/ + +namespace JointDickman + +/-- Reconstruct the second quotient and the additive edge from the first +quotient. All variables are integers, allowing both signs of the lag. -/ +theorem divisor_edge_forward {a b c j m z : ℤ} + (hcoeff : a - b = j * c) (hquot : c * z = a * m + 1) : + c * (z - j * m) = b * m + 1 ∧ + b * z + j = a * (z - j * m) := by + constructor + · linear_combination hquot + m * hcoeff + · linear_combination -z * hcoeff - j * hquot + +/-- The congruence at the new endpoint reconstructs the old divisor +representation. Coprimality with the lag is precisely the cancellation +needed in the reverse direction. -/ +theorem divisor_edge_iff {a b c j z : ℤ} + (hcoeff : a - b = j * c) (hcop : IsCoprime a j) : + (∃ m : ℤ, c * z = a * m + 1) ↔ a ∣ b * z + j := by + constructor + · rintro ⟨m, hm⟩ + exact ⟨z - j * m, (divisor_edge_forward hcoeff hm).2⟩ + · rintro ⟨k, hk⟩ + have hdiv : a ∣ j * (c * z - 1) := by + refine ⟨z - k, ?_⟩ + linear_combination -z * hcoeff - hk + obtain ⟨m, hm⟩ := hcop.dvd_of_dvd_mul_left hdiv + exact ⟨m, by linarith⟩ + +/-- No multiplicity is introduced by the reindexing. -/ +theorem divisor_edge_quotient_unique {a c z m₁ m₂ : ℤ} (ha : a ≠ 0) + (hm₁ : c * z = a * m₁ + 1) (hm₂ : c * z = a * m₂ + 1) : m₁ = m₂ := by + apply mul_left_cancel₀ ha + linarith + +/-- Both old divisibility conditions imply the coefficient difference is +divisible by `c`, because the multiplier is a unit modulo `c`. -/ +theorem common_divisor_difference {a b c m : ℤ} + (ha : c ∣ a * m + 1) (hb : c ∣ b * m + 1) : c ∣ a - b := by + have hm : IsCoprime c m := by + obtain ⟨z, hz⟩ := ha + refine ⟨z, -a, ?_⟩ + linear_combination -hz + apply hm.dvd_of_dvd_mul_right + convert dvd_sub ha hb using 1 + ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticAmplification.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticAmplification.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf905ecba1ff80ffd0c3afc883984de12f5bfa89 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticAmplification.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.SquarefreeQuotientSite +import OAI.NumberTheory.JointDickman.Amplification.WeightedAmplification + +namespace OAI + +/-! # The divisor weight equals the fair-split model away from square hits -/ + +namespace JointDickman +open Finset + +open Classical in +noncomputable def arithmeticSubsetAmplification (B L : ℕ) (τ C : ℝ) + (w : ℕ → ℕ → ℝ) (n : ℕ) : ℝ := + (1 / (B : ℝ)) * ∑ A ∈ (auxiliaryPrimes B).powerset, ∑ D ∈ (auxiliaryPrimes B).powerset, + if (∏ p ∈ A, p) ∣ n ∧ (∏ p ∈ D, p) ∣ n + 1 then + (regularCoefficientWeight B L τ C (∏ p ∈ A, p) * + regularResidueWeight B L τ C (coefficientPrimeSet B (n / (∏ p ∈ A, p)))) * + (regularCoefficientWeight B L τ C (∏ p ∈ D, p) * + regularResidueWeight B L τ C (coefficientPrimeSet B ((n + 1) / (∏ p ∈ D, p)))) * + w (∏ p ∈ A, p) (∏ p ∈ D, p) else 0 + +open Classical in +theorem arithmeticSubsetAmplification_eq_model {B L n : ℕ} {τ C : ℝ} + (hB : 1 < B) (w : ℕ → ℕ → ℝ) + (hno₁ : ∀ p ∈ auxiliaryPrimes B, ¬ p^2 ∣ n) + (hno₂ : ∀ p ∈ auxiliaryPrimes B, ¬ p^2 ∣ n + 1) : + arithmeticSubsetAmplification B L τ C w n = + independentWeightedAmplification B L τ C w + (coefficientPrimeSet B n) (coefficientPrimeSet B (n + 1)) := by + have hB0 : (B : ℝ) ≠ 0 := by exact_mod_cast (by omega : B ≠ 0) + have hS : coefficientPrimeSet B n ⊆ auxiliaryPrimes B := filter_subset _ _ + have hR : coefficientPrimeSet B (n + 1) ⊆ auxiliaryPrimes B := filter_subset _ _ + unfold arithmeticSubsetAmplification independentWeightedAmplification sitePairSplitAverage + simp only [mul_sum] + apply sum_congr rfl + intro A hA + apply sum_congr rfl + intro D hD + have hAP := mem_powerset.mp hA + have hDP := mem_powerset.mp hD + by_cases hd : (∏ p ∈ A, p) ∣ n ∧ (∏ p ∈ D, p) ∣ n + 1 + · rw [ite_eq_left hd, + coefficientPrimeSet_quotient hAP hd.1 hno₁, coefficientPrimeSet_quotient hDP hd.2 hno₂] + have hAS := (primeProduct_dvd_site_iff hAP).mp hd.1 + have hDR := (primeProduct_dvd_site_iff hDP).mp hd.2 + rw [regular_arithmetic_split_identity hB hS hAS, regular_arithmetic_split_identity hB hR hDR] + by_cases h₁ : RegularPrimeSet B L τ C A <;> + by_cases h₂ : RegularPrimeSet B L τ C D <;> + by_cases h₃ : RegularPrimeSet B L τ C (coefficientPrimeSet B n \ A) <;> + by_cases h₄ : RegularPrimeSet B L τ C (coefficientPrimeSet B (n + 1) \ D) + all_goals simp only [h₁, h₂, h₃, h₄, and_self, and_false, and_true, + ite_true, ite_false, mul_zero, zero_mul, mul_one] + field_simp + · rw [ite_eq_right hd, mul_zero] + by_cases ha : A ⊆ coefficientPrimeSet B n + · have hdn : ¬ D ⊆ coefficientPrimeSet B (n + 1) := fun hh => + hd ⟨(primeProduct_dvd_site_iff hAP).mpr ha, (primeProduct_dvd_site_iff hDP).mpr hh⟩ + simp only [subsetRetentionMass, hdn, ite_false, mul_zero, zero_mul] + · simp only [subsetRetentionMass, ha, ite_false, mul_zero, zero_mul] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticAmplificationBounds.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticAmplificationBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..b76ce682c821243983671ab5ca5e0f4600a1c17f --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticAmplificationBounds.lean @@ -0,0 +1,104 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticAmplification +import OAI.NumberTheory.JointDickman.Probability.QuotientSiteUnion + +namespace OAI + +/-! # Uniform bounds for the actual arithmetic amplification -/ + +namespace JointDickman +open Finset + +open Classical in +noncomputable def arithmeticSiteWeight (B L : ℕ) (τ C : ℝ) (n : ℕ) : ℝ := + ∑ A ∈ (auxiliaryPrimes B).powerset, + if (∏ p ∈ A, p) ∣ n then + regularCoefficientWeight B L τ C (∏ p ∈ A, p) * + regularResidueWeight B L τ C (coefficientPrimeSet B (n / (∏ p ∈ A, p))) + else 0 + +open Classical in +theorem arithmeticSiteWeight_nonneg (B L n : ℕ) (τ C : ℝ) : + 0 ≤ arithmeticSiteWeight B L τ C n := by + apply sum_nonneg + intro A _ + split_ifs + · exact mul_nonneg (regularCoefficientWeight_nonneg ..) (regularResidueWeight_nonneg ..) + · exact le_rfl + +open Classical in +theorem arithmeticSiteWeight_le {B L n : ℕ} (τ C : ℝ) (hB : 1 < B) : + arithmeticSiteWeight B L τ C n ≤ B := by + let S := coefficientPrimeSet B n + have hS : S ⊆ auxiliaryPrimes B := filter_subset _ _ + have hf : (auxiliaryPrimes B).powerset.filter (fun A => A ⊆ S) = S.powerset := by + ext A + simp only [mem_filter, mem_powerset] + exact and_iff_right_of_imp (fun h => h.trans hS) + calc + _ ≤ ∑ A ∈ (auxiliaryPrimes B).powerset, + if A ⊆ S then (B : ℝ) * (1 / 2 : ℝ)^S.card else 0 := by + apply sum_le_sum + intro A hA + have hAP := mem_powerset.mp hA + have he : A ⊆ S ↔ (∏ p ∈ A, p) ∣ n := (primeProduct_dvd_site_iff hAP).symm + simp only [he] + split_ifs with ha + · exact arithmetic_split_weight_le hB hAP ha + · exact le_rfl + _ = (2 : ℝ)^S.card * ((B : ℝ) * (1 / 2 : ℝ)^S.card) := by + rw [← sum_filter, hf] + simp + _ = B := by + calc + _ = (B : ℝ) * ((2 : ℝ) * (1 / 2))^S.card := by rw [mul_pow]; ring + _ = _ := by norm_num + +open Classical in +theorem arithmeticSubsetAmplification_nonneg (B L n : ℕ) (τ C : ℝ) + (w : ℕ → ℕ → ℝ) (hw : ∀ a c, 0 ≤ w a c) : + 0 ≤ arithmeticSubsetAmplification B L τ C w n := by + unfold arithmeticSubsetAmplification + apply mul_nonneg (by positivity) + apply sum_nonneg + intro A _ + apply sum_nonneg + intro D _ + split_ifs + · exact mul_nonneg (mul_nonneg + (mul_nonneg (regularCoefficientWeight_nonneg ..) (regularResidueWeight_nonneg ..)) + (mul_nonneg (regularCoefficientWeight_nonneg ..) (regularResidueWeight_nonneg ..))) (hw _ _) + · exact le_rfl + +open Classical in +theorem arithmeticSubsetAmplification_le {B L n : ℕ} (τ C : ℝ) + (hB : 1 < B) (w : ℕ → ℕ → ℝ) (hw : ∀ a c, w a c ≤ 1) : + arithmeticSubsetAmplification B L τ C w n ≤ B := by + have hB0 : (0 : ℝ) < B := by exact_mod_cast (by omega : 0 < B) + have hs := arithmeticSiteWeight_nonneg B L n τ C + have ht := arithmeticSiteWeight_nonneg B L (n + 1) τ C + calc + _ ≤ (1 / (B : ℝ)) * (arithmeticSiteWeight B L τ C n * + arithmeticSiteWeight B L τ C (n + 1)) := by + unfold arithmeticSubsetAmplification arithmeticSiteWeight + apply mul_le_mul_of_nonneg_left _ (by positivity) + rw [sum_mul] + simp only [mul_sum] + apply sum_le_sum + intro A _ + apply sum_le_sum + intro D _ + split_ifs + · exact mul_le_of_le_one_right (mul_nonneg + (mul_nonneg (regularCoefficientWeight_nonneg ..) (regularResidueWeight_nonneg ..)) + (mul_nonneg (regularCoefficientWeight_nonneg ..) (regularResidueWeight_nonneg ..))) + (hw _ _) + all_goals simp_all only [and_self, and_true, and_false, mul_zero, zero_mul, not_true_eq_false, le_refl] + _ ≤ (1 / (B : ℝ)) * ((B : ℝ) * B) := + mul_le_mul_of_nonneg_left + (mul_le_mul (arithmeticSiteWeight_le τ C hB) (arithmeticSiteWeight_le τ C hB) + ht hB0.le) (by positivity) + _ = B := by field_simp + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateRoots.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..bda241c1f6292e0cae5267f72d6b1c0125aa7151 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateRoots.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticGraphPair +import OAI.NumberTheory.JointDickman.Amplification.CandidateModularRoots + +namespace OAI + +/-! # The arithmetic quotient and its candidate root -/ + +namespace JointDickman +open Finset + +/-- The reconstructed multiplier satisfies the exact affine equation before +any residue model or exceptional event is introduced. -/ +theorem divisorEdgeInverse_equation {a b c N : ℕ} {j : ℤ} + (ha : 0 < a) (hc : 0 < c) (he : (a : ℤ)-b = j*c) + (hcop : a.Coprime j.natAbs) {n : ℕ} + (hn : n ∈ divisorEdgeNew a b c N j) : + a*b*divisorEdgeInverse a b c n+b = c*n := by + obtain ⟨hm,hback⟩ := divisorEdge_inverse_mem ha hc he hcop hn + obtain ⟨_,_,_,hca,_⟩ := mem_filter.mp hm + calc + _ = b*(a*divisorEdgeInverse a b c n+1) := by ring + _ = b*(c*((a*divisorEdgeInverse a b c n+1)/c)) := by + rw [Nat.mul_div_cancel' hca] + _ = c*(b*((a*divisorEdgeInverse a b c n+1)/c)) := by ring + _ = _ := by rw [hback] + +/-- Outside coefficient primes the remaining arithmetic argument has the +ordinary linear root used by the candidate model. -/ +theorem affine_quotient_prime_root {a b c m n p : ℕ} [Fact p.Prime] + (he : a*b*m+b = c*n) (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) + (hc : ¬ p ∣ c) : + p ∣ m ↔ (n : ZMod p) = (b : ZMod p)/(c : ZMod p) := by + have ha0 : (a : ZMod p) ≠ 0 := fun h => ha ((ZMod.natCast_eq_zero_iff _ _).mp h) + have hb0 : (b : ZMod p) ≠ 0 := fun h => hb ((ZMod.natCast_eq_zero_iff _ _).mp h) + have hc0 : (c : ZMod p) ≠ 0 := fun h => hc ((ZMod.natCast_eq_zero_iff _ _).mp h) + have hz : (a : ZMod p)*b*m+b = (c : ZMod p)*n := by + simpa only [Nat.cast_add,Nat.cast_mul] using congrArg (fun t : ℕ => (t : ZMod p)) he + rw [← ZMod.natCast_eq_zero_iff, eq_div_iff hc0] + constructor + · intro hm + simpa only [hm,mul_zero,zero_add,mul_comm] using hz.symm + · intro hn + have hm : (a : ZMod p)*b*m = 0 := by linear_combination hz + hn + exact (mul_eq_zero.mp hm).resolve_left (mul_ne_zero ha0 hb0) + +/-- A prime of the third coefficient cannot divide the remaining argument. -/ +theorem affine_quotient_no_third_coefficient {a b c m n p : ℕ} [Fact p.Prime] + (he : a*b*m+b = c*n) (hb : ¬ p ∣ b) (hc : p ∣ c) : ¬ p ∣ m := by + intro hm + have hleft : p ∣ a*b*m+b := by + rw [he] + exact dvd_mul_of_dvd_left hc n + have habm : p ∣ a*b*m := dvd_mul_of_dvd_right hm (a*b) + exact hb ((Nat.dvd_add_iff_right habm).mpr hleft) + +/-- For a coefficient with exactly one factor of `p`, testing the quotient +for `p` is a test of the original numerator modulo `p²`. -/ +theorem prime_square_product_iff {p d m : ℕ} (hp : p.Prime) + (hd : p ∣ d) (hdd : ¬ p^2 ∣ d) : p^2 ∣ d*m ↔ p ∣ m := by + obtain ⟨k,rfl⟩ := hd + have hk : ¬ p ∣ k := by + intro h + apply hdd + simpa only [pow_two] using Nat.mul_dvd_mul_left p h + rw [pow_two,mul_assoc,Nat.mul_dvd_mul_iff_left hp.pos] + exact ⟨fun h => (hp.dvd_mul.mp h).resolve_left hk, fun h => dvd_mul_of_dvd_right h k⟩ + +theorem affine_quotient_coefficient_root {a b c m n p : ℕ} (hp : p.Prime) + (he : a*b*m+b = c*n) (hpab : p ∣ a*b) (hpab2 : ¬ p^2 ∣ a*b) : + p ∣ m ↔ p^2 ∣ c*n-b := by + have hsub : c*n-b = a*b*m := by omega + rw [hsub] + exact (prime_square_product_iff hp hpab hpab2).symm + +/-- With the manuscript's site indexing, the linear root is precisely +`candidateModRoot`, not a new independently specified residue. -/ +theorem candidate_affine_quotient_root {M p u m : ℕ} [Fact p.Prime] + (e : BlockCandidateIndex M) + (he : candidateHigh e*candidateLow e*m+candidateLow e = + candidateQuotient e*(u+(e.1.1.val+1))) + (ha : ¬ p ∣ candidateHigh e) (hb : ¬ p ∣ candidateLow e) + (hc : ¬ p ∣ candidateQuotient e) : + p ∣ m ↔ (u : ZMod p) = candidateModRoot p e := by + rw [affine_quotient_prime_root he ha hb hc] + have hc0 : (candidateQuotient e : ZMod p) ≠ 0 := + fun h => hc ((ZMod.natCast_eq_zero_iff _ _).mp h) + unfold candidateModRoot candidateRootNumerator + simp only [Nat.cast_add,Nat.cast_one,Int.cast_sub,Int.cast_natCast,Int.cast_mul, + Int.cast_add,Int.cast_one] + rw [eq_div_iff hc0,eq_div_iff hc0] + constructor <;> intro h <;> linear_combination h + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateSum.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..00e88674f509cfb15f80f6058ef63d29eeea2eb6 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateSum.lean @@ -0,0 +1,92 @@ +import OAI.NumberTheory.JointDickman.Amplification.GraphCandidateDecoding + +namespace OAI + +/-! # Exact reindexing of the arithmetic graph by its endpoint candidates -/ + +namespace JointDickman +open Finset Classical + +noncomputable def arithmeticCandidateWeight (B L T : ℕ) (τ C : ℝ) + {M : ℕ} (u : ℕ) (e : BlockCandidateIndex M) : ℝ := + candidateRootWeight B L τ C (fun i => coefficientPrimeSet B (u+(i.val+1))) + (candidateCutoff (amplificationOuterWeight B) (amplificationInnerWeight T)) e + (coefficientPrimeSet B (divisorEdgeInverse (candidateHigh e) (candidateLow e) + (candidateQuotient e) (u+(e.1.1.val+1)))) + +theorem rawArithmeticGraphKernel_candidate_sum {B L T H M N u : ℕ} {τ C : ℝ} + (hB : 0 < B) (hT : 0 < T) (hTP : T ≤ auxiliaryCutoff B) + {i k : Fin M} (hik : i < k) (hH : H < k.val-i.val) + (hsq : ¬ BlockSquareHit B M u) : + rawArithmeticGraphKernel B L τ C T N ((k.val-i.val : ℕ) : ℤ) + (u+(i.val+1))/(B : ℝ) = + ∑ e ∈ blockCandidates B L T H M τ C + (fun l => coefficientPrimeSet B (u+(l.val+1))), + if e.1 = (i,k) ∧ u+(i.val+1) ∈ graphTripleEdges N (candidateGraphTriple B e) + then arithmeticCandidateWeight B L T τ C u e else 0 := by + unfold rawArithmeticGraphKernel + rw [sum_div] + let f (g : GraphCoefficientTriple) : ℝ := + (if graphTripleLag g = ((k.val-i.val : ℕ) : ℤ) ∧ + u+(i.val+1) ∈ graphTripleEdges N g + then graphTripleWeight B L τ C T g (u+(i.val+1)) else 0)/(B : ℝ) + have hsupport (g : GraphCoefficientTriple) (hf : f g ≠ 0) : + graphTripleLag g = ((k.val-i.val : ℕ) : ℤ) ∧ + u+(i.val+1) ∈ graphTripleEdges N g ∧ + graphTripleWeight B L τ C T g (u+(i.val+1)) ≠ 0 := by + dsimp [f] at hf + by_cases h : graphTripleLag g = ((k.val-i.val : ℕ) : ℤ) ∧ + u+(i.val+1) ∈ graphTripleEdges N g + · refine ⟨h.1,h.2,?_⟩ + intro hz + simp [h,hz] at hf + · simp [h] at hf + apply sum_bij_ne_zero (fun g _ _ => graphBlockCandidate i k g) + · intro g hg hf + obtain ⟨hlag,hn,hw⟩ := hsupport g hf + exact graphBlockCandidate_mem hB hT hik hH hg hlag hn hw hsq + · intro g hg hf g' hg' hf' heq + have hs := hsupport g hf + have hs' := hsupport g' hf' + have hr := graphBlockCandidate_roundtrip hik + (graphTripleWeight_nonzero_supported hB hT τ C hg hs.1 hs.2.2) + have hr' := graphBlockCandidate_roundtrip hik + (graphTripleWeight_nonzero_supported hB hT τ C hg' hs'.1 hs'.2.2) + exact hr.symm.trans ((congrArg (candidateGraphTriple B) heq).trans hr') + · intro e he hwe + have hp : e.1 = (i,k) ∧ + u+(i.val+1) ∈ graphTripleEdges N (candidateGraphTriple B e) := by + by_contra h + simp only [ite_eq_right h,ne_eq,not_true_eq_false] at hwe + have hg := candidateGraphTriple_mem _ (fun l => filter_subset _ _) hTP he + have ha := (mem_blockCandidates.mp he).2 + have hj : candidateLag e = k.val-i.val := by + change e.1.2.val-e.1.1.val = _ + rw [hp.1] + have hlag : graphTripleLag (candidateGraphTriple B e) = ((k.val-i.val : ℕ) : ℤ) := + (candidateGraphTriple_lag ha).trans (congrArg (fun j : ℕ => (j : ℤ)) hj) + refine ⟨candidateGraphTriple B e,hg,?_,candidateGraphTriple_roundtrip hp.1⟩ + have heweight := candidateGraphTriple_weight he hsq + have hilow : e.1.1 = i := congrArg Prod.fst hp.1 + change _ = arithmeticCandidateWeight B L T τ C u e at heweight + rw [hilow] at heweight + dsimp [f] + rw [ite_eq_left ⟨hlag,hp.2⟩,heweight] + simpa only [ite_eq_left hp] using hwe + · intro g hg hf + obtain ⟨hlag,hn,hw⟩ := hsupport g hf + have hs := graphTripleWeight_nonzero_supported hB hT τ C hg hlag hw + have he := graphBlockCandidate_mem hB hT hik hH hg hlag hn hw hsq + have hr := graphBlockCandidate_roundtrip hik hs + have hwgt := candidateGraphTriple_weight he hsq + change _ = arithmeticCandidateWeight B L T τ C u (graphBlockCandidate i k g) at hwgt + rw [hr] at hwgt + rw [ite_eq_left ⟨hlag,hn⟩,ite_eq_left (show + (graphBlockCandidate i k g).1 = (i,k) ∧ + u+(i.val+1) ∈ graphTripleEdges N (candidateGraphTriple B (graphBlockCandidate i k g)) + from ⟨rfl,hr.symm ▸ hn⟩)] + exact hwgt + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateWeight.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateWeight.lean new file mode 100644 index 0000000000000000000000000000000000000000..58b28d8eac650c8ad33bcb4eb44af2a964f03938 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticCandidateWeight.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticRootIdentification +import OAI.NumberTheory.JointDickman.Counting.BlockSquareHits +import OAI.NumberTheory.JointDickman.Arithmetic.SquarefreeQuotientSite + +namespace OAI + +/-! # The six arithmetic graph factors are the candidate root weight -/ + +namespace JointDickman +open Finset Classical + +noncomputable def candidateCutoff {M : ℕ} (w : ℕ → ℝ) (v : ℕ → ℕ → ℝ) + (e : BlockCandidateIndex M) : ℝ := + w (candidateQuotient e)*v (candidateHigh e) (candidateQuotient e)* + v (candidateLow e) (candidateQuotient e) + +/-- Removing the selected squarefree factors leaves exactly the two +endpoint complements occurring in the candidate kernel. -/ +theorem arithmetic_graph_candidate_weight {B L T H M u : ℕ} {τ C : ℝ} + (w : ℕ → ℝ) (v : ℕ → ℕ → ℝ) {e : BlockCandidateIndex M} + (he : e ∈ blockCandidates B L T H M τ C + (fun i => coefficientPrimeSet B (u+(i.val+1)))) + (hsq : ¬ BlockSquareHit B M u) : + arithmeticGraphPairWeight B L τ C w v + (candidateHigh e) (candidateLow e) (candidateQuotient e) (candidateLag e) + (u+(e.1.1.val+1))/(B : ℝ) = + candidateRootWeight B L τ C (fun i => coefficientPrimeSet B (u+(i.val+1))) + (candidateCutoff w v) e + (coefficientPrimeSet B (divisorEdgeInverse (candidateHigh e) (candidateLow e) + (candidateQuotient e) (u+(e.1.1.val+1)))) := by + obtain ⟨hs,hadm⟩ := mem_blockCandidates.mp he + obtain ⟨hlo,_,_⟩ := mem_endpointSplits.mp hs.1 + obtain ⟨hhi,_,_⟩ := mem_endpointSplits.mp hs.2 + have hlowP : e.2.1 ⊆ auxiliaryPrimes B := hlo.trans (filter_subset _ _) + have hhighP : e.2.2 ⊆ auxiliaryPrimes B := hhi.trans (filter_subset _ _) + have hlowD : candidateLow e ∣ u+(e.1.1.val+1) := + (primeProduct_dvd_site_iff hlowP).mpr hlo + have hhighD : candidateHigh e ∣ u+(e.1.2.val+1) := + (primeProduct_dvd_site_iff hhighP).mpr hhi + have hno (i : Fin M) (p : ℕ) (hp : p ∈ auxiliaryPrimes B) : ¬ p^2 ∣ u+(i.val+1) := + fun hd => hsq ⟨i,p,hp,hd⟩ + have hqlow := coefficientPrimeSet_quotient hlowP hlowD (hno e.1.1) + have hqhigh := coefficientPrimeSet_quotient hhighP hhighD (hno e.1.2) + change coefficientPrimeSet B ((u+(e.1.1.val+1))/candidateLow e) = _ at hqlow + change coefficientPrimeSet B ((u+(e.1.2.val+1))/candidateHigh e) = _ at hqhigh + have hshift : (((u+(e.1.1.val+1) : ℕ) : ℤ)+(candidateLag e : ℤ)).toNat = + u+(e.1.2.val+1) := by + have hi : e.1.1.val ≤ e.1.2.val := (show e.1.1.val < e.1.2.val from hadm.1).le + have hl : (candidateLag e : ℤ) = (e.1.2.val : ℤ)-e.1.1.val := Int.ofNat_sub hi + rw [hl] + omega + unfold arithmeticGraphPairWeight arithmeticResidueWeight candidateRootWeight candidateCutoff + rw [hshift] + change (_ * (_ * regularResidueWeight B L τ C + (coefficientPrimeSet B ((u+(e.1.1.val+1))/candidateLow e)) * _) * + (_ * regularResidueWeight B L τ C + (coefficientPrimeSet B ((u+(e.1.2.val+1))/candidateHigh e)) * _))/(B : ℝ) = _ + rw [hqlow,hqhigh] + ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticFeatureComparison.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticFeatureComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..64ba254258ed8fdff349518928c48c23c0d45bd6 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticFeatureComparison.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.JointDickman.Amplification.PeriodCoarseVanishing +import OAI.NumberTheory.JointDickman.Amplification.GeometricArithmeticIdentity +import OAI.NumberTheory.JointDickman.Probability.GroupedKernelFeatures + +namespace OAI + +/-! # The separated arithmetic kernel has a finite-feature approximation -/ + +namespace JointDickman +open Finset Filter +open scoped Topology SchwartzMap + +theorem geometric_arithmetic_feature_comparison + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) + (hSW : PublishedInputs.SquarefreeCharacterEstimateInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (hMP : PublishedInputs.PrimeProductMertensInput) + {a b l u t η : ℝ} (ha : 0 < a) (hab : a ≤ b) (hl : 0 < l) (hlu : l ≤ u) + (ht : 0 < t) (hη : 0 < η) + (w₁ w₂ w₁' w₂' : ℝ → ℝ) (w : 𝓢(ℝ,ℝ)) (w' : ℝ → ℝ) + {M D₁ D₂ M₀ D₀ : ℝ} (hMb : 0 ≤ M) (hD₁ : 0 ≤ D₁) (hD₂ : 0 ≤ D₂) + (hM₀ : 0 ≤ M₀) (hD₀ : 0 ≤ D₀) + (hw₁ : ∀ x, HasDerivAt w₁ (w₁' x) x) (hw₂ : ∀ x, HasDerivAt w₂ (w₂' x) x) + (hwb₁ : ∀ x, |w₁ x| ≤ M) (hwb₂ : ∀ x, |w₂ x| ≤ M) + (hwd₁ : ∀ x, |w₁' x| ≤ D₁) (hwd₂ : ∀ x, |w₂' x| ≤ D₂) + (hs₁ : ∀ x, x ≤ a ∨ b < x → w₁ x = 0) + (hs₂ : ∀ x, x ≤ a ∨ b < x → w₂ x = 0) + (hw : ∀ x, HasDerivAt w (w' x) x) (hw' : Continuous w') + (hwb : ∀ x, |w x| ≤ M₀) (hwd : ∀ x, |w' x| ≤ D₀) + (hsupp : ∀ x, x ≤ l ∨ u < x → w x = 0) : + ∃ c : ℕ → ℝ, c 0 = squarefreeLeadingConstant (1/2) ∧ 0 < c 0 ∧ + ∃ H : ℕ, ∃ ε : ℕ → ℝ, Tendsto ε atTop (𝓝 0) ∧ + ∀ δ : ℝ, 0 < δ → ∃ m : ℕ, 0 < m ∧ ∀ᶠ B : ℕ in atTop, + ∀ j : ℕ, [NeZero j] → ∀ Q : ℕ, 0 < Q → j*Q ≤ B → + (B : ℝ)^(2/5 : ℝ) ≤ Q → + ∀ T : ℝ, 0 < T → η*T ≤ j → ∀ S : Finset ℤ, + (∀ k ∈ S, (k : ℝ)*t ∈ Set.Icc ((9/10 : ℝ)*B) ((5/2 : ℝ)*B)) → + (∀ k ∈ S, Real.log (Real.exp ((k : ℝ)*t)/T) ∈ + Set.Icc ((9/10 : ℝ)*B) ((11/5 : ℝ)*B)) → + ∀ g h : (auxiliaryPrimes B → Bool) → ℝ, + (∀ x, |g x| ≤ 1) → (∀ x, |h x| ≤ 1) → + let d := fun k : ℤ => coefficientDensity c H B (Real.log (Real.exp ((k : ℝ)*t)/T)/B) + let K := geometricWindowKernel m B t (Real.log a) (Real.log b) S + (endpointSpatialWeight m B t (T/j) d w₁ w₂ w) + T*|geometricArithmeticSum B j a b l u T t S g h w₁ w₂ w- + (singularSeries j/(j : ℝ))* + (∑ x, ∑ y, fullPrimeMass (auxiliaryPrimes B) x*fullPrimeMass (auxiliaryPrimes B) y* + g x*h y*primeCoarseKernel m B K x y)| ≤ + ε B+δ*(T/j)*singularSeries j := by + obtain ⟨c,hc,hcpos,H,ε,hε,hcompare⟩ := geometric_period_coarse_vanishing + hSD hSW hM hMP ha hab hl hlu ht hη w₁ w₂ w₁' w₂' w w' + hMb hD₁ hD₂ hM₀ hD₀ hw₁ hw₂ hwb₁ hwb₂ hwd₁ hwd₂ hs₁ hs₂ hw hw' hwb hwd hsupp + refine ⟨c,hc,hcpos,H,ε,hε,?_⟩ + intro δ hδ + obtain ⟨m,hm,hcompareB⟩ := hcompare δ hδ + refine ⟨m,hm,?_⟩ + filter_upwards [hcompareB,eventually_gt_atTop 0] with B hcB hB + intro j _ Q hQ hscale hcut T hT hlag S hbox hlog g h hg hh + dsimp only + have he := hcB j Q hQ hscale hcut T hT hlag S hbox hlog g h hg hh + dsimp only at he + rw [geometricPeriodSum_eq_arithmeticSum B j hT hl hlu S g h w₁ w₂ w hsupp, + coarseLogMassBilinear_eq_kernel_test hm hB] at he + simpa only [← Complex.ofReal_natCast,← Complex.ofReal_div,← Complex.ofReal_mul, + ← Complex.ofReal_sub,Complex.norm_real,Real.norm_eq_abs] using he + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticForcedCost.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticForcedCost.lean new file mode 100644 index 0000000000000000000000000000000000000000..ec45cc83ac5a1d696af4bde466f7cc007002320b --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticForcedCost.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticPatternMeans +import OAI.NumberTheory.JointDickman.Amplification.CandidateForcedProbability +import OAI.NumberTheory.JointDickman.Amplification.ActualCandidateProduct + +namespace OAI + +/-! # Weighted cost of forced third-site hits in the arithmetic block -/ + +namespace JointDickman +open Finset Filter PublishedInputs Classical +open scoped Topology + +theorem blockPatternEquiv_symm_sites {B M : ℕ} + (S : Fin M → (auxiliaryPrimes B).powerset) : + primePatternsSites ((blockPatternEquiv B M).symm S) = (fun i => (S i).val) := by + have h := (blockPatternEquiv B M).apply_symm_apply S + funext i + exact congrArg Subtype.val (congrFun h i) + +theorem arithmetic_forced_cost {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} + (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T H M : ℕ), + (T : ℝ) ≤ Real.exp B → (M : ℝ) ≤ Real.exp B → M ≤ B^2 → + arithmeticSquareMean B (fun u => (B : ℝ)^10 * + (if ForcedCandidateHit B L T H M τ C + (fun i => coefficientPrimeSet B (u+(i.val+1))) then 1 else 0)) ≤ + (B : ℝ)^10 * (5*(M : ℝ)^3*(B : ℝ)^3/(Real.log 2*auxiliaryCutoff B))+2/(B : ℝ) := by + filter_upwards [forcedCandidateHit_probability hL hτ hτsmall,eventually_ge_atTop 2] + with B hprob hB + intro C T H M hT hMexp hM + let F := fun S : BlockPrimePatterns B M => (B : ℝ)^10 * + (if ForcedCandidateHit B L T H M τ C (primePatternsSites S) then (1 : ℝ) else 0) + have hcap S : |F S| ≤ 1*(B : ℝ)^10 := by + dsimp only [F] + split_ifs <;> simp [abs_of_nonneg (pow_nonneg (Nat.cast_nonneg (α := ℝ) B) 10)] + have hsize : ∀ p ∈ auxiliaryPrimes B, M < p := + fun _ hp => (block_prime_twice_sites hB hM hp).1 + have hc := arithmeticSquareMean_pattern_comparison (by omega : 1 < B) hM hsize F + (C := 1) (by norm_num) hcap + have hleft : arithmeticSquareMean B (fun u => F (arithmeticPrimePatterns B M u)) = + arithmeticSquareMean B (fun u => (B : ℝ)^10 * + (if ForcedCandidateHit B L T H M τ C + (fun i => coefficientPrimeSet B (u+(i.val+1))) then 1 else 0)) := by + apply congrArg (arithmeticSquareMean B) + funext u + have hs : primePatternsSites (arithmeticPrimePatterns B M u) = + (fun i => coefficientPrimeSet B (u+(i.val+1))) := + funext (primePatternsSites_arithmetic B M u) + dsimp only [F] + rw [hs] + have hright : finiteExpectation (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) + (fun S => F ((blockPatternEquiv B M).symm S)) = + (B : ℝ)^10 * finiteProbability (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) + (fun S => ForcedCandidateHit B L T H M τ C (fun i => (S i).val)) := by + simp only [F,blockPatternEquiv_symm_sites,finiteProbability_eq_indicator_mean, + finiteExpectation_const_mul] + rw [hleft,hright] at hc + have hp := mul_le_mul_of_nonneg_left (hprob C T H M hT hMexp) + (pow_nonneg (Nat.cast_nonneg (α := ℝ) B) 10) + have hu := (le_abs_self _).trans hc + simp only [mul_one] at hu + linarith only [hp,hu] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphBounds.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..94be478e2e91bfbc454dac1f53a575d1471dc165 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphBounds.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.JointDickman.Probability.ArithmeticGraphKernel + +namespace OAI + +/-! # Positivity and support of the actual arithmetic graph kernel -/ + +namespace JointDickman +open Finset + +theorem arithmeticGraphPairWeight_nonneg (B L : ℕ) (τ C : ℝ) + (u : ℕ → ℝ) (v : ℕ → ℕ → ℝ) (hu : ∀ c, 0 ≤ u c) + (hv : ∀ a c, 0 ≤ v a c) (a b c : ℕ) (j : ℤ) (n : ℕ) : + 0 ≤ arithmeticGraphPairWeight B L τ C u v a b c j n := by + have hA (d l : ℕ) : 0 ≤ regularCoefficientWeight B L τ C d * + arithmeticResidueWeight B L τ C l * v d c := + mul_nonneg (mul_nonneg (regularCoefficientWeight_nonneg B L τ C d) + (regularResidueWeight_nonneg B L τ C _)) (hv d c) + have hC : 0 ≤ u c * regularCoefficientWeight B L τ C c * + arithmeticResidueWeight B L τ C (divisorEdgeInverse a b c n) := + mul_nonneg (mul_nonneg (hu c) (regularCoefficientWeight_nonneg B L τ C c)) + (regularResidueWeight_nonneg B L τ C _) + exact mul_nonneg (mul_nonneg hC (hA a (n/b))) (hA b (((n : ℤ)+j).toNat/a)) + +theorem rawArithmeticGraphKernel_nonneg (B L : ℕ) (τ C : ℝ) + (T N : ℕ) (j : ℤ) (n : ℕ) : 0 ≤ rawArithmeticGraphKernel B L τ C T N j n := by + classical + apply sum_nonneg + intro i _ + split_ifs + · exact arithmeticGraphPairWeight_nonneg B L τ C (amplificationOuterWeight B) + (amplificationInnerWeight T) (fun _ => (amplificationBump_bounds _).1) + (fun _ _ => (amplificationBump_bounds _).1) _ _ _ _ _ + · rfl + +theorem rawArithmeticGraphKernel_zero_lag (B L : ℕ) (τ C : ℝ) (T N n : ℕ) : + rawArithmeticGraphKernel B L τ C T N 0 n = 0 := by + classical + apply sum_eq_zero + intro i hi + have hne := (mem_filter.mp hi).2.2.1 + change coefficientPairLag i.1 i.2.1 i.2.2 ≠ 0 at hne + have hn : ¬ (graphTripleLag i = 0 ∧ n ∈ graphTripleEdges N i) := fun h => hne h.1 + exact ite_eq_right hn + +theorem rawArithmeticGraphKernel_large_lag (B L : ℕ) (τ C : ℝ) + (T N : ℕ) (j : ℤ) (n : ℕ) (hj : T ≤ j.natAbs) : + rawArithmeticGraphKernel B L τ C T N j n = 0 := by + classical + apply sum_eq_zero + intro i hi + have hlt := (mem_filter.mp hi).2.2.2.1 + have hn : ¬ (graphTripleLag i = j ∧ n ∈ graphTripleEdges N i) := by + intro h + change (graphTripleLag i).natAbs < T at hlt + rw [h.1] at hlt + omega + exact ite_eq_right hn + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphCandidateCount.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphCandidateCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6a92f6a629e075f93aef806fd03c739513d2d15 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphCandidateCount.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticGraphPointCap + +namespace OAI + +/-! # Polynomial graph multiplicity without excluding site squares -/ + +namespace JointDickman +open Finset Filter Classical +open scoped Topology + +noncomputable def activeGraphTriples (B L T N : ℕ) (τ C : ℝ) (j : ℤ) (n : ℕ) : + Finset GraphCoefficientTriple := + (arithmeticGraphTriples B T).filter (fun g => graphTripleLag g = j ∧ + n ∈ graphTripleEdges N g ∧ graphTripleWeight B L τ C T g n ≠ 0) + +theorem rawArithmeticGraphKernel_active (B L T N : ℕ) (τ C : ℝ) (j : ℤ) (n : ℕ) : + rawArithmeticGraphKernel B L τ C T N j n/(B : ℝ) = + ∑ g ∈ activeGraphTriples B L T N τ C j n, graphTripleWeight B L τ C T g n/(B : ℝ) := by + unfold rawArithmeticGraphKernel activeGraphTriples + rw [sum_div,sum_filter] + apply sum_congr rfl + intro g _ + by_cases hc : graphTripleLag g = j ∧ n ∈ graphTripleEdges N g + · by_cases hw : graphTripleWeight B L τ C T g n = 0 + · simp [hc,hw] + · simp [hc.1,hc.2,hw] + · have hn : ¬ (graphTripleLag g = j ∧ n ∈ graphTripleEdges N g ∧ + graphTripleWeight B L τ C T g n ≠ 0) := fun h => hc ⟨h.1,h.2.1⟩ + simp [hc,hn] + +theorem activeGraphTriples_card {B L T M N u : ℕ} {τ C : ℝ} + (hB : 0 < B) (hT : 0 < T) + (hcount : ∀ S R : Finset ℕ, RegularPrimeSet B L τ C S → RegularPrimeSet B L τ C R → + 2^(S ∪ R).card ≤ B) + {i k : Fin M} (hik : i < k) : + (activeGraphTriples B L T N τ C ((k.val-i.val : ℕ) : ℤ) (u+(i.val+1))).card ≤ B^2 := by + let G := activeGraphTriples B L T N τ C ((k.val-i.val : ℕ) : ℤ) (u+(i.val+1)) + have hg (g : GraphCoefficientTriple) (h : g ∈ G) : + g ∈ arithmeticGraphTriples B T ∧ graphTripleLag g = ((k.val-i.val : ℕ) : ℤ) ∧ + u+(i.val+1) ∈ graphTripleEdges N g ∧ graphTripleWeight B L τ C T g (u+(i.val+1)) ≠ 0 := + mem_filter.mp h + change G.card ≤ B^2 + by_cases hne : G.Nonempty + · obtain ⟨g0,hg0⟩ := hne + obtain ⟨h0,hj0,hn0,hw0⟩ := hg g0 hg0 + have hcounts := graph_regular_endpoint_count hcount hik h0 hj0 hn0 hw0 + let S := (coefficientPrimeSet B (u+(i.val+1))).powerset ×ˢ + (coefficientPrimeSet B (u+(k.val+1))).powerset + have hmap : ∀ g ∈ G, (g.2.2,g.2.1) ∈ S := by + intro g h + obtain ⟨hgg,hj,hn,_⟩ := hg g h + have hs := graph_endpoint_prime_subsets hik hgg hj hn + exact mem_product.mpr ⟨mem_powerset.mpr hs.1,mem_powerset.mpr hs.2⟩ + have hinj : (G : Set GraphCoefficientTriple).InjOn (fun g => (g.2.2,g.2.1)) := by + intro g h g' h' heq + obtain ⟨hgg,hj,_,hw⟩ := hg g h + obtain ⟨hgg',hj',_,hw'⟩ := hg g' h' + have hr := graphBlockCandidate_roundtrip hik (graphTripleWeight_nonzero_supported hB hT τ C hgg hj hw) + have hr' := graphBlockCandidate_roundtrip hik (graphTripleWeight_nonzero_supported hB hT τ C hgg' hj' hw') + have he : graphBlockCandidate i k g = graphBlockCandidate i k g' := Prod.ext rfl heq + exact hr.symm.trans ((congrArg (candidateGraphTriple B) he).trans hr') + calc + G.card ≤ S.card := card_le_card_of_injOn _ hmap hinj + _ = 2^(coefficientPrimeSet B (u+(i.val+1))).card * + 2^(coefficientPrimeSet B (u+(k.val+1))).card := by simp [S] + _ ≤ B*B := Nat.mul_le_mul hcounts.1 hcounts.2 + _ = B^2 := by ring + · simp only [not_nonempty_iff_eq_empty.mp hne,card_empty] + exact Nat.zero_le _ + +theorem rawArithmeticGraphKernel_forward_cap {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} + (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T M N u : ℕ), 0 < T → + ∀ (i k : Fin M), i < k → + rawArithmeticGraphKernel B L τ C T N ((k.val-i.val : ℕ) : ℤ) (u+(i.val+1))/(B : ℝ) ≤ + (B : ℝ)^2 := by + filter_upwards [regular_endpoint_subset_count hL hτ hτsmall, + graphTripleWeight_le_one hL hτ hτsmall,eventually_gt_atTop 0] with B hcount hweight hB + intro C T M N u hT i k hik + rw [rawArithmeticGraphKernel_active] + calc + _ ≤ ∑ _g ∈ activeGraphTriples B L T N τ C ((k.val-i.val : ℕ) : ℤ) (u+(i.val+1)), (1 : ℝ) := + sum_le_sum (fun g _ => hweight C T _ g) + _ = ((activeGraphTriples B L T N τ C ((k.val-i.val : ℕ) : ℤ) (u+(i.val+1))).card : ℝ) := by simp + _ ≤ (B : ℝ)^2 := by exact_mod_cast activeGraphTriples_card hB hT (hcount C) hik + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphPair.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphPair.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb434cae9f49f9f1af1d163e2108bb5d7b4631f7 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphPair.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.JointDickman.Amplification.FirstFormPairs + +namespace OAI + +/-! # The arithmetic graph weight obtained from the actual quadratic form -/ + +namespace JointDickman +open Finset + +noncomputable def arithmeticGraphPairWeight (B L : ℕ) (τ C : ℝ) + (u : ℕ → ℝ) (v : ℕ → ℕ → ℝ) (a b c : ℕ) (j : ℤ) (n : ℕ) : ℝ := + (u c * regularCoefficientWeight B L τ C c * + arithmeticResidueWeight B L τ C (divisorEdgeInverse a b c n)) * + (regularCoefficientWeight B L τ C a * arithmeticResidueWeight B L τ C (n/b) * v a c) * + (regularCoefficientWeight B L τ C b * + arithmeticResidueWeight B L τ C (((n : ℤ)+j).toNat/a) * v b c) + +theorem divisorEdge_new_quotients {a b c N : ℕ} {j : ℤ} + (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) + (he : (a : ℤ)-b = j*c) (hcop : a.Coprime j.natAbs) + {n : ℕ} (hn : n ∈ divisorEdgeNew a b c N j) : + (a*divisorEdgeInverse a b c n+1)/c = n/b ∧ + (b*divisorEdgeInverse a b c n+1)/c = ((n : ℤ)+j).toNat/a := by + obtain ⟨hm,hback⟩ := divisorEdge_inverse_mem ha hc he hcop hn + obtain ⟨_,_,_,hca,hcb⟩ := mem_filter.mp hm + constructor + · calc + _ = (b*((a*divisorEdgeInverse a b c n+1)/c))/b := + (Nat.mul_div_cancel_left _ hb).symm + _ = n/b := congrArg (fun t => t/b) hback + · have hend : (n : ℤ)+j = ((a*((b*divisorEdgeInverse a b c n+1)/c) : ℕ) : ℤ) := by + have h := natural_divisor_edge_endpoints hc hca hcb he + rwa [hback] at h + rw [hend,Int.toNat_natCast,Nat.mul_div_cancel_left _ ha] + +theorem firstFormPairWeight_graph {B L : ℕ} (τ C : ℝ) + (u : ℕ → ℝ) (v : ℕ → ℕ → ℝ) {D A E : Finset ℕ} {N : ℕ} {j : ℤ} + (ha : 0 < ∏ p ∈ A, p) (hb : 0 < ∏ p ∈ E, p) (hc : 0 < ∏ p ∈ D, p) + (he : ((∏ p ∈ A, p : ℕ) : ℤ)-(∏ p ∈ E, p : ℕ) = j*(∏ p ∈ D, p : ℕ)) + (hcop : (∏ p ∈ A, p).Coprime j.natAbs) {n : ℕ} + (hn : n ∈ divisorEdgeNew (∏ p ∈ A, p) (∏ p ∈ E, p) (∏ p ∈ D, p) N j) : + firstFormPairWeight B L τ C u v D A E + (divisorEdgeInverse (∏ p ∈ A, p) (∏ p ∈ E, p) (∏ p ∈ D, p) n) = + arithmeticGraphPairWeight B L τ C u v + (∏ p ∈ A, p) (∏ p ∈ E, p) (∏ p ∈ D, p) j n := by + obtain ⟨hqa,hqb⟩ := divisorEdge_new_quotients ha hb hc he hcop hn + unfold firstFormPairWeight arithmeticGraphPairWeight firstFormWeight + rw [hqa,hqb] + +/-- This is the exact arithmetic graph expression for a fixed coefficient +pair in the original energy. It includes both signs of the additive lag. -/ +theorem firstFormPairEnergy_graph {B L : ℕ} (τ C : ℝ) + (u : ℕ → ℝ) (v : ℕ → ℕ → ℝ) {D A E : Finset ℕ} {j : ℤ} + (ha : 0 < ∏ p ∈ A, p) (hb : 0 < ∏ p ∈ E, p) (hc : 0 < ∏ p ∈ D, p) + (he : ((∏ p ∈ A, p : ℕ) : ℤ)-(∏ p ∈ E, p : ℕ) = j*(∏ p ∈ D, p : ℕ)) + (hcop : (∏ p ∈ A, p).Coprime j.natAbs) (N : ℕ) (F : ℕ → ℂ) + (hFa : ∀ n, F ((∏ p ∈ A, p)*n) = F n) + (hFb : ∀ n, F ((∏ p ∈ E, p)*n) = F n) + (hFc : ∀ n, F ((∏ p ∈ D, p)*n) = F n) : + firstFormPairEnergy B L τ C u v (fun m => F (m+1)) N D A E = + ∑ n ∈ divisorEdgeNew (∏ p ∈ A, p) (∏ p ∈ E, p) (∏ p ∈ D, p) N j, + arithmeticGraphPairWeight B L τ C u v + (∏ p ∈ A, p) (∏ p ∈ E, p) (∏ p ∈ D, p) j n * + (star (F n) * F ((n : ℤ)+j).toNat).re := by + rw [firstFormPairEnergy_as_old, + weighted_divisor_edge_reindex ha hb hc he hcop N + (firstFormPairWeight B L τ C u v D A E) F hFa hFb hFc] + apply sum_congr rfl + intro n hn + rw [firstFormPairWeight_graph τ C u v ha hb hc he hcop hn] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphPointCap.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphPointCap.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f524fa47b466f14328a5393feb3a0901e8f5b86 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphPointCap.lean @@ -0,0 +1,94 @@ +import OAI.NumberTheory.JointDickman.Amplification.GraphCandidateDecoding +import OAI.NumberTheory.JointDickman.Probability.QuotientSiteUnion +import OAI.NumberTheory.JointDickman.Amplification.CandidateWeightCap + +namespace OAI + +/-! # A pointwise graph bound valid even on site-square exceptions -/ + +namespace JointDickman +open Finset Filter Classical +open scoped Topology + +theorem graphTripleWeight_le_one {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} + (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T n : ℕ) (g : GraphCoefficientTriple), + graphTripleWeight B L τ C T g n/(B : ℝ) ≤ 1 := by + filter_upwards [six_regular_weights_small hL hτ hτsmall,eventually_ge_atTop 1] with B hB hB1 + intro C T n g + let a := ∏ p ∈ g.2.1, p + let b := ∏ p ∈ g.2.2, p + let c := ∏ p ∈ g.1, p + let j := graphTripleLag g + let W := fun d m => regularCoefficientWeight B L τ C d*arithmeticResidueWeight B L τ C m + have hW d m : 0 ≤ W d m := mul_nonneg (regularCoefficientWeight_nonneg _ _ _ _ _) + (regularResidueWeight_nonneg _ _ _ _ _) + have hc : amplificationOuterWeight B c*W c (divisorEdgeInverse a b c n) ≤ + W c (divisorEdgeInverse a b c n) := + mul_le_of_le_one_left (hW _ _) (amplificationBump_bounds _).2 + have ha : W a (n/b)*amplificationInnerWeight T a c ≤ W a (n/b) := + mul_le_of_le_one_right (hW _ _) (amplificationBump_bounds _).2 + have hb : W b (((n : ℤ)+j).toNat/a)*amplificationInnerWeight T b c ≤ W b (((n : ℤ)+j).toNat/a) := + mul_le_of_le_one_right (hW _ _) (amplificationBump_bounds _).2 + have hp : graphTripleWeight B L τ C T g n ≤ + W c (divisorEdgeInverse a b c n)*W a (n/b)*W b (((n : ℤ)+j).toNat/a) := by + change (amplificationOuterWeight B c*regularCoefficientWeight B L τ C c* + arithmeticResidueWeight B L τ C (divisorEdgeInverse a b c n))* + (W a (n/b)*amplificationInnerWeight T a c)* + (W b (((n : ℤ)+j).toNat/a)*amplificationInnerWeight T b c) ≤ _ + rw [mul_assoc (amplificationOuterWeight B c)] + exact mul_le_mul (mul_le_mul hc ha (mul_nonneg (hW _ _) (amplificationBump_bounds _).1) + (hW _ _)) hb (mul_nonneg (hW _ _) (amplificationBump_bounds _).1) + (mul_nonneg (hW _ _) (hW _ _)) + calc + _ ≤ (W c (divisorEdgeInverse a b c n)*W a (n/b)*W b (((n : ℤ)+j).toNat/a))/(B : ℝ) := + div_le_div_of_nonneg_right hp (Nat.cast_nonneg B) + _ ≤ (B : ℝ)^(-(7/100 : ℝ)) := hB C c a b _ _ _ + _ ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos (by exact_mod_cast hB1) (by norm_num) + +theorem graph_endpoint_prime_subsets {B T M N u : ℕ} {i k : Fin M} + (hik : i < k) {g : GraphCoefficientTriple} (hg : g ∈ arithmeticGraphTriples B T) + (hlag : graphTripleLag g = ((k.val-i.val : ℕ) : ℤ)) + (hn : u+(i.val+1) ∈ graphTripleEdges N g) : + g.2.2 ⊆ coefficientPrimeSet B (u+(i.val+1)) ∧ + g.2.1 ⊆ coefficientPrimeSet B (u+(k.val+1)) := by + have hs := graphTriple_subsets hg + have hbdiv : (∏ p ∈ g.2.2, p) ∣ u+(i.val+1) := (mem_filter.mp hn).2.1 + have hadiv : (∏ p ∈ g.2.1, p) ∣ u+(k.val+1) := by + have h := (mem_filter.mp hn).2.2.1 + have he : (((u+(i.val+1) : ℕ) : ℤ)+graphTripleLag g) = (u+(k.val+1) : ℕ) := by + rw [hlag,Int.ofNat_sub hik.le] + push_cast + ring + rw [he] at h + exact_mod_cast h + exact ⟨(primeProduct_dvd_site_iff hs.2.2).mp hbdiv, + (primeProduct_dvd_site_iff hs.2.1).mp hadiv⟩ + +theorem graph_regular_endpoint_count {B L T M N u : ℕ} {τ C : ℝ} + (hcount : ∀ S R : Finset ℕ, RegularPrimeSet B L τ C S → RegularPrimeSet B L τ C R → + 2^(S ∪ R).card ≤ B) + {i k : Fin M} (hik : i < k) {g : GraphCoefficientTriple} + (hg : g ∈ arithmeticGraphTriples B T) + (hlag : graphTripleLag g = ((k.val-i.val : ℕ) : ℤ)) + (hn : u+(i.val+1) ∈ graphTripleEdges N g) + (hw : graphTripleWeight B L τ C T g (u+(i.val+1)) ≠ 0) : + 2^(coefficientPrimeSet B (u+(i.val+1))).card ≤ B ∧ + 2^(coefficientPrimeSet B (u+(k.val+1))).card ≤ B := by + have hs := graphTriple_subsets hg + have hr := graphTripleWeight_nonzero_regular hg hw + have hbdiv : (∏ p ∈ g.2.2, p) ∣ u+(i.val+1) := (mem_filter.mp hn).2.1 + have hshift : (((u+(i.val+1) : ℕ) : ℤ)+graphTripleLag g).toNat = u+(k.val+1) := by + rw [hlag,Int.ofNat_sub hik.le] + omega + have hsub := graph_endpoint_prime_subsets hik hg hlag hn + have hadiv := (primeProduct_dvd_site_iff hs.2.1).mpr hsub.2 + have hlo := hcount g.2.2 _ hr.2.2.1 hr.2.2.2.1 + have hhi := hcount g.2.1 _ hr.2.1 hr.2.2.2.2 + rw [coefficientPrimeSet_union_quotient hs.2.2 hbdiv] at hlo + rw [hshift,coefficientPrimeSet_union_quotient hs.2.1 hadiv] at hhi + exact ⟨hlo,hhi⟩ + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphSymmetry.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphSymmetry.lean new file mode 100644 index 0000000000000000000000000000000000000000..db914978d2545d9526b37bc3fdd13c1385e2c56d --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticGraphSymmetry.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.JointDickman.Amplification.GraphEdgeSwap +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticGraphCandidateCount + +namespace OAI + +/-! # Symmetry of the original arithmetic graph at its two endpoints -/ + +namespace JointDickman +open Finset Classical + +theorem graphTripleSwap_condition {B T N n n' : ℕ} {j : ℤ} {g : GraphCoefficientTriple} + (hg : g ∈ arithmeticGraphTriples B T) (he : (n : ℤ)+j = n') : + (graphTripleLag (graphTripleSwap g) = -j ∧ n' ∈ graphTripleEdges N (graphTripleSwap g)) ↔ + (graphTripleLag g = j ∧ n ∈ graphTripleEdges N g) := by + rw [graphTripleSwap_lag hg,neg_inj] + constructor + · rintro ⟨hlag,hn⟩ + have hs := (graphTripleSwap_edge (graphTripleSwap_mem hg) hn).1 + have hback : ((n' : ℤ)+graphTripleLag (graphTripleSwap g)).toNat = n := by + rw [graphTripleSwap_lag hg,hlag] + omega + rw [hback,graphTripleSwap_involutive g] at hs + exact ⟨hlag,hs⟩ + · rintro ⟨hlag,hn⟩ + have hs := (graphTripleSwap_edge hg hn).1 + have hforward : ((n : ℤ)+graphTripleLag g).toNat = n' := by rw [hlag,he,Int.toNat_natCast] + rw [hforward] at hs + exact ⟨hlag,hs⟩ + +theorem rawArithmeticGraphKernel_reverse {B L T N n n' : ℕ} {τ C : ℝ} {j : ℤ} + (he : (n : ℤ)+j = n') : + rawArithmeticGraphKernel B L τ C T N (-j) n' = + rawArithmeticGraphKernel B L τ C T N j n := by + unfold rawArithmeticGraphKernel + symm + apply sum_bij (fun g _ => graphTripleSwap g) + · intro g hg + exact graphTripleSwap_mem hg + · intro g _ g' _ heq + exact graphTripleSwap_involutive.injective heq + · intro g hg + exact ⟨graphTripleSwap g,graphTripleSwap_mem hg,graphTripleSwap_involutive g⟩ + · intro g hg + have hc := graphTripleSwap_condition (N := N) hg he + by_cases hh : graphTripleLag g = j ∧ n ∈ graphTripleEdges N g + · have hs := hc.mpr hh + rw [ite_eq_left hh,ite_eq_left hs] + have hw := graphTripleSwap_weight (L := L) (τ := τ) (C := C) hg hh.2 + have hn : ((n : ℤ)+graphTripleLag g).toNat = n' := by rw [hh.1,he,Int.toNat_natCast] + rw [hn] at hw + exact hw.symm + · rw [ite_eq_right hh,ite_eq_right (fun h => hh (hc.mp h))] + +theorem rawArithmeticGraphKernel_block_reverse {B L T M N u : ℕ} {τ C : ℝ} + (i k : Fin M) : + rawArithmeticGraphKernel B L τ C T N ((i.val : ℤ)-k.val) (u+(k.val+1)) = + rawArithmeticGraphKernel B L τ C T N ((k.val : ℤ)-i.val) (u+(i.val+1)) := by + have he : ((u+(i.val+1) : ℕ) : ℤ)+((k.val : ℤ)-i.val) = (u+(k.val+1) : ℕ) := by + push_cast + ring + simpa only [neg_sub] using rawArithmeticGraphKernel_reverse (B := B) (L := L) + (T := T) (N := N) (τ := τ) (C := C) he + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticInputs.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticInputs.lean new file mode 100644 index 0000000000000000000000000000000000000000..8bea99d18b2814e16b1e54f2b90da267570186ec --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticInputs.lean @@ -0,0 +1,113 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.RoughConvolution +import Mathlib.Analysis.SpecialFunctions.Gamma.Basic +import Mathlib.NumberTheory.Harmonic.EulerMascheroni +import Mathlib.Topology.Algebra.InfiniteSum.Basic + +namespace OAI + +/-! +# Published arithmetic inputs at the strength needed here + +The fixed-order Selberg–Delange expansion is Granville–Koukoulopoulos, +*Beyond the LSD method* (2019), Theorem 1, specialized to +`μ²(n) z^ω(n)`, or Koukoulopoulos, *The Distribution of Prime Numbers*, +Theorem 13.2. The expansion concerns squarefree weights and contains no +character estimates. +-/ + +namespace JointDickman + +open Filter Finset +open scoped Topology + +noncomputable def squarefreeSummatory (z Y : ℝ) : ℝ := + ∑ n ∈ Ioc 0 ⌊Y⌋₊, squarefreeWeight z n + +/-- The convergent Euler-product normalization of the first LSD coefficient. -/ +noncomputable def squarefreeLeadingConstant (z : ℝ) : ℝ := + (∏' p : {p : ℕ // p.Prime}, + (1 + z / (p.val : ℝ)) * (1 - 1 / (p.val : ℝ)) ^ z) / Real.Gamma z + +namespace PublishedInputs + +/-- Only the two positive exponents used by the paper, with all fixed +expansion orders and the actual leading coefficient. -/ +def SquarefreeSelbergDelangeInput : Prop := + ∀ z : ℝ, z = 1 / 4 ∨ z = 1 / 2 → + ∃ c : ℕ → ℝ, c 0 = squarefreeLeadingConstant z ∧ 0 < c 0 ∧ + ∀ H : ℕ, ∃ C : ℝ, 0 ≤ C ∧ ∀ Y : ℝ, 3 ≤ Y → + |squarefreeSummatory z Y - + Y * ∑ j ∈ range (H + 1), c j * (Real.log Y) ^ (z - 1 - j)| ≤ + C * Y * (Real.log Y) ^ (z - 2 - H) + +/-- The classical reciprocal-prime Mertens estimate, at its usual +`O(1/log x)` strength: Montgomery–Vaughan, Multiplicative Number Theory I, +Theorem 2.7(d). -/ +def PrimeReciprocalMertensInput : Prop := + ∃ M C : ℝ, 0 ≤ C ∧ ∀ x : ℝ, 2 ≤ x → + |(∑ p ∈ (Icc 2 ⌊x⌋₊).filter Nat.Prime, 1 / (p : ℝ)) - + Real.log (Real.log x) - M| ≤ C / Real.log x + +/-- Mertens' product theorem, with its normalized limiting constant: +Montgomery–Vaughan, Multiplicative Number Theory I, Theorem 2.7(e). -/ +def PrimeProductMertensInput : Prop := + Tendsto (fun x : ℝ => Real.log x * + ∏ p ∈ (Icc 2 ⌊x⌋₊).filter Nat.Prime, (1 - 1 / (p : ℝ))) + atTop (𝓝 (Real.exp (-Real.eulerMascheroniConstant))) + +end PublishedInputs + +/-- The fixed-order expansion in particular supplies the leading term with +one full logarithmic saving, with no uniformity in an unbounded order. -/ +theorem squarefreeSummatory_one_term + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) {z : ℝ} + (hz : z = 1 / 4 ∨ z = 1 / 2) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ Y : ℝ, 3 ≤ Y → + |squarefreeSummatory z Y - + Y * squarefreeLeadingConstant z * (Real.log Y) ^ (z - 1)| ≤ + C * Y * (Real.log Y) ^ (z - 2) := by + obtain ⟨c, hc, _, horders⟩ := hSD z hz + obtain ⟨C, hC, hbound⟩ := horders 0 + refine ⟨C, hC, fun Y hY => ?_⟩ + simpa [hc, mul_assoc] using hbound Y hY + +/-- The leading normalized asymptotic, proved from the cited expansion. -/ +theorem squarefreeSummatory_normalized_tendsto + (hSD : PublishedInputs.SquarefreeSelbergDelangeInput) {z : ℝ} + (hz : z = 1 / 4 ∨ z = 1 / 2) : + Tendsto (fun Y : ℝ => squarefreeSummatory z Y / + (Y * (Real.log Y) ^ (z - 1))) atTop (𝓝 (squarefreeLeadingConstant z)) := by + obtain ⟨C, _, hbound⟩ := squarefreeSummatory_one_term hSD hz + apply tendsto_iff_norm_sub_tendsto_zero.mpr + have hlim : Tendsto (fun Y : ℝ => C / Real.log Y) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop Real.tendsto_log_atTop + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ hlim + filter_upwards [eventually_ge_atTop (3 : ℝ)] with Y hY + have hY0 : 0 < Y := by linarith + have hlog : 0 < Real.log Y := Real.log_pos (by linarith) + have hp : 0 < (Real.log Y) ^ (z - 1) := Real.rpow_pos_of_pos hlog _ + have hden : 0 < Y * (Real.log Y) ^ (z - 1) := mul_pos hY0 hp + have hexp : (Real.log Y) ^ (z - 2) = (Real.log Y) ^ (z - 1) / Real.log Y := by + rw [show z - 2 = (z - 1) - 1 by ring, Real.rpow_sub_one hlog.ne'] + rw [Real.norm_eq_abs] + have heq : |squarefreeSummatory z Y / (Y * (Real.log Y) ^ (z - 1)) - + squarefreeLeadingConstant z| = + |squarefreeSummatory z Y - Y * squarefreeLeadingConstant z * (Real.log Y) ^ (z - 1)| / + (Y * (Real.log Y) ^ (z - 1)) := by + calc + _ = |(squarefreeSummatory z Y - Y * squarefreeLeadingConstant z * + (Real.log Y) ^ (z - 1)) / (Y * (Real.log Y) ^ (z - 1))| := by + congr 1 + field_simp + _ = _ := by rw [abs_div, abs_of_pos hden] + rw [heq] + calc + _ ≤ (C * Y * (Real.log Y) ^ (z - 2)) / (Y * (Real.log Y) ^ (z - 1)) := + div_le_div_of_nonneg_right (hbound Y hY) hden.le + _ = C / Real.log Y := by + rw [hexp] + field_simp + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticLongFluctuation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticLongFluctuation.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e4cc1030d959857caa776fe7e1ee7c7740601c4 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticLongFluctuation.lean @@ -0,0 +1,32 @@ +import OAI.NumberTheory.JointDickman.Probability.ArithmeticKernelPeriod + +namespace OAI + +/-! # Vanishing fluctuations in ordinary long arithmetic averages -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +theorem actual_candidate_long_mean_small + (hFord : PublishedInputs.FordUpperSieveInput) + (hMertens : PublishedInputs.PrimeReciprocalMertensInput) + {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∃ E : ℕ → ℝ, Tendsto E atTop (𝓝 0) ∧ + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T H M : ℕ), + 0 < T → (T : ℝ) ≤ Real.exp ((1/10 : ℝ)*B) → T ≤ auxiliaryCutoff B → + 0 < M → M ≤ B^2 → (M : ℝ) ≤ Real.exp B → + ∀ χ : BlockCandidateIndex M → ℝ, (∀ e, 0 ≤ χ e ∧ χ e ≤ 1) → + ∀ ε : ℝ, 0 < ε → ∀ᶠ N : ℕ in atTop, + (∑ u ∈ range N, actualCandidateCutError B L T H M τ C χ u)/(N : ℝ) < E B+ε := by + obtain ⟨E,hE,hbound⟩ := actual_arithmetic_fluctuation_decay hFord hMertens hL hτ hτsmall + refine ⟨E,hE,?_⟩ + filter_upwards [hbound] with B hbound + intro C T H M hT hTs hTP hM0 hM hMexp χ hχ ε hε + have hb := hbound C T H M hT hTs hTP hM0 hM hMexp χ hχ + have ht := actualCandidateCutError_mean_tendsto (L := L) (H := H) (τ := τ) (C := C) hTP χ + exact ht.eventually (Iio_mem_nhds (lt_add_of_le_of_pos hb hε)) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticModelError.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticModelError.lean new file mode 100644 index 0000000000000000000000000000000000000000..3f87bec6aac44113bf13662fc4c2b06c23c3f07e --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticModelError.lean @@ -0,0 +1,55 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticSquareHits +import OAI.NumberTheory.JointDickman.Arithmetic.PrimeSiteResidues + +namespace OAI + +/-! # The arithmetic and fair-split weights differ only at rare square hits -/ + +namespace JointDickman +open Finset + +open Classical in +theorem independentWeightedAmplification_le {B L : ℕ} {τ C : ℝ} + (w : ℕ → ℕ → ℝ) (hw : ∀ a c, w a c ≤ 1) {S R : Finset ℕ} + (hS : S ⊆ auxiliaryPrimes B) (hR : R ⊆ auxiliaryPrimes B) : + independentWeightedAmplification B L τ C w S R ≤ B := by + have hh := sitePairSplitAverage_mono (auxiliaryPrimes B) S R + (fun A D => if RegularPrimeSet B L τ C A ∧ RegularPrimeSet B L τ C D ∧ + RegularPrimeSet B L τ C (S \ A) ∧ RegularPrimeSet B L τ C (R \ D) + then w (∏ p ∈ A, p) (∏ p ∈ D, p) else 0) + (fun _ _ => 1) (by intros; split_ifs; exact hw _ _; norm_num) + rw [sitePairSplitAverage_const_one hS hR] at hh + exact (mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg B)).trans_eq (mul_one _) + +open Classical in +theorem arithmetic_model_power_error {B L n : ℕ} {τ C : ℝ} + (hB : 1 < B) (w : ℕ → ℕ → ℝ) (hw : ∀ a c, 0 ≤ w a c ∧ w a c ≤ 1) (k : ℕ) : + |(arithmeticSubsetAmplification B L τ C w n)^k - + (independentWeightedAmplification B L τ C w + (coefficientPrimeSet B n) (coefficientPrimeSet B (n+1)))^k| ≤ + (B : ℝ)^k * (if AuxiliarySquareHit B n then 1 else 0) := by + by_cases h : AuxiliarySquareHit B n + · rw [ite_eq_left h, mul_one] + have ha0 := arithmeticSubsetAmplification_nonneg B L n τ C w (fun a c => (hw a c).1) + have ha1 := arithmeticSubsetAmplification_le (L := L) τ C hB w (fun a c => (hw a c).2) (n := n) + have hb0 := independentWeightedAmplification_nonneg B L τ C w (fun a c => (hw a c).1) + (coefficientPrimeSet B n) (coefficientPrimeSet B (n+1)) + have hb1 := independentWeightedAmplification_le (B := B) (L := L) (τ := τ) (C := C) w (fun a c => (hw a c).2) + (S := coefficientPrimeSet B n) (R := coefficientPrimeSet B (n+1)) + (filter_subset _ _) (filter_subset _ _) + have ha := pow_le_pow_left₀ ha0 ha1 k + have hb := pow_le_pow_left₀ hb0 hb1 k + have ha' := pow_nonneg ha0 k + have hb' := pow_nonneg hb0 k + rw [abs_le] + constructor <;> linarith + · have hn : ∀ p ∈ auxiliaryPrimes B, ¬p^2 ∣ n := + fun p hp hd => h ⟨p, hp, Or.inl hd⟩ + have hn' : ∀ p ∈ auxiliaryPrimes B, ¬p^2 ∣ n+1 := + fun p hp hd => h ⟨p, hp, Or.inr hd⟩ + rw [arithmeticSubsetAmplification_eq_model hB w hn hn', sub_self, abs_zero, + ite_eq_right h, mul_zero] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticOffDiagonalGraph.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticOffDiagonalGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..075ccfd8d69a412dcbe533180e0487559118d51c --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticOffDiagonalGraph.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.JointDickman.Counting.GraphCoefficientSupport + +namespace OAI + +/-! # Exact graph representation of the full off-diagonal energy -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +open Classical in +noncomputable def arithmeticOffDiagonalGraph (B L : ℕ) (τ C : ℝ) + (T N : ℕ) (F : ℕ → ℂ) : ℝ := + (∑ D ∈ (auxiliaryPrimes B).powerset, ∑ A ∈ (auxiliaryPrimes B).powerset, + ∑ E ∈ (auxiliaryPrimes B).powerset, if GraphCoefficientAdmissible T D A E then + ∑ n ∈ divisorEdgeNew (∏ p ∈ A, p) (∏ p ∈ E, p) (∏ p ∈ D, p) N (coefficientPairLag D A E), + arithmeticGraphPairWeight B L τ C (amplificationOuterWeight B) (amplificationInnerWeight T) + (∏ p ∈ A, p) (∏ p ∈ E, p) (∏ p ∈ D, p) (coefficientPairLag D A E) n * + (star (F n) * F ((n : ℤ)+coefficientPairLag D A E).toNat).re + else 0) / (N : ℝ) + +/-- The original off-diagonal energy equals the arithmetic graph, including +its actual coefficient/residue weights and exact finite endpoints. -/ +theorem firstFormOffDiagonal_graph (B L : ℕ) (τ C : ℝ) (T N : ℕ) + (hT : T ≤ auxiliaryCutoff B) (F : ℕ → ℂ) + (hF : ∀ A ∈ (auxiliaryPrimes B).powerset, ∀ n, F ((∏ p ∈ A, p)*n) = F n) : + firstFormOffDiagonal B L τ C (amplificationOuterWeight B) (amplificationInnerWeight T) + (fun m => F (m+1)) N = arithmeticOffDiagonalGraph B L τ C T N F := by + classical + rw [firstFormOffDiagonal_eq_pairSum] + unfold arithmeticOffDiagonalGraph + congr 1 + apply sum_congr rfl + intro D hD + apply sum_congr rfl + intro A hA + apply sum_congr rfl + intro E hE + have hp (S : Finset ℕ) (hS : S ∈ (auxiliaryPrimes B).powerset) : 0 < ∏ p ∈ S, p := + prod_pos (fun p hp => (auxiliaryPrimes_prime B p (mem_powerset.mp hS hp)).pos) + by_cases hg : GraphCoefficientAdmissible T D A E + · rw [ite_eq_left hg,ite_eq_right hg.1] + exact firstFormPairEnergy_graph τ C (amplificationOuterWeight B) (amplificationInnerWeight T) + (hp A hA) (hp E hE) (hp D hD) hg.2.2.2.1 hg.2.2.2.2 N F (hF A hA) (hF E hE) (hF D hD) + · rw [ite_eq_right hg] + by_cases hAE : A = E + · rw [ite_eq_left hAE] + · rw [ite_eq_right hAE] + by_contra hn + exact hg (nonzero_pairEnergy_admissible τ C (amplificationOuterWeight B) + (fun m => F (m+1)) N (mem_powerset.mp hD) (mem_powerset.mp hA) (mem_powerset.mp hE) hAE hT hn) + +/-- The exact graph identity for the moving centered second bin label. -/ +theorem centered_binLabel_offDiagonal_graph {ι : Type*} [Fintype ι] + (J : ℕ) (hJ : 0 < J) (k : ι → ℕ) (hk : ∀ i, 1 ≤ k i) + (z : ι → ℂ) (μ : ℂ) (B L : ℕ) (τ C : ℝ) (T : ℕ) (hT : T ≤ auxiliaryCutoff B) : + ∀ᶠ N : ℕ in atTop, + firstFormOffDiagonal B L τ C (amplificationOuterWeight B) (amplificationInnerWeight T) + (fun m => movingBinLabel J k z N (m+1)-μ) N = + arithmeticOffDiagonalGraph B L τ C T N (fun n => movingBinLabel J k z N n-μ) := by + filter_upwards [centered_movingBinLabel_invariant J hJ k hk z μ B] with N hN + exact firstFormOffDiagonal_graph B L τ C T N hT + (fun n => movingBinLabel J k z N n-μ) hN + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticPatternMeans.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticPatternMeans.lean new file mode 100644 index 0000000000000000000000000000000000000000..008dbdeceb7fa37630311defa251a80e6fcb99e8 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticPatternMeans.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.JointDickman.Counting.BlockPatternTranspose +import OAI.NumberTheory.JointDickman.Counting.ArithmeticCoefficientProbability + +namespace OAI + +/-! # First-digit pattern averages over the full prime-square period -/ + +namespace JointDickman +open Finset PublishedInputs Classical + +theorem residuePrimePatterns_mean {B M : ℕ} + [∀ p : auxiliaryPrimes B, NeZero p.val] + (hsize : ∀ p ∈ auxiliaryPrimes B, M < p) (F : BlockPrimePatterns B M → ℝ) : + finiteExpectation (primeDigitMass B) (fun r => F (residuePrimePatterns r)) = + ∑ S : BlockPrimePatterns B M, categoricalProductMass univ + (fun p : auxiliaryPrimes B => fun _ : Fin M => 1/(p.val : ℝ)) S * F S := by + have ht := finiteProductMass_pushforward_test + (fun (p : auxiliaryPrimes B) (_ : ZMod p.val) => 1/(p.val : ℝ)) + (fun p : auxiliaryPrimes B => blockPrimeHit M p.val) (fun S => (F S : ℂ)) + simp only [blockPrimeHit_pushMass M _ (hsize _ (Subtype.property _))] at ht + exact_mod_cast ht.symm + +theorem arithmeticSquareMean_patterns {B M : ℕ} + (hsize : ∀ p ∈ auxiliaryPrimes B, M < p) (F : BlockPrimePatterns B M → ℝ) : + arithmeticSquareMean B (fun u => F (arithmeticPrimePatterns B M u)) = + ∑ S : BlockPrimePatterns B M, categoricalProductMass univ + (fun p : auxiliaryPrimes B => fun _ : Fin M => 1/(p.val : ℝ)) S * F S := by + let : ∀ p : auxiliaryPrimes B, NeZero p.val := + fun p => ⟨(auxiliaryPrimes_prime B p.val p.property).ne_zero⟩ + have hh := prime_square_crt_average B (fun r _ => F (residuePrimePatterns r)) + change arithmeticSquareMean B (fun u => F (residuePrimePatterns (arithmeticFirstDigits B u))) = _ at hh + simp only [residuePrimePatterns_arithmetic,finiteExpectation_const _ (primeDigitMass_sum B)] at hh + exact hh.trans (residuePrimePatterns_mean hsize F) + +theorem arithmeticSquareMean_pattern_comparison {B M : ℕ} + (hB : 1 < B) (hM : M ≤ B^2) (hsize : ∀ p ∈ auxiliaryPrimes B, M < p) + (F : BlockPrimePatterns B M → ℝ) {C : ℝ} (hC : 0 ≤ C) + (hF : ∀ S, |F S| ≤ C*(B : ℝ)^10) : + |arithmeticSquareMean B (fun u => F (arithmeticPrimePatterns B M u))- + finiteExpectation (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) + (fun S => F ((blockPatternEquiv B M).symm S))| ≤ 2*C/(B : ℝ) := by + have hc := block_sites_auxiliary_comparison hB hM F hC hF + rw [block_sites_crt_mean M (auxiliaryPrimes B) (auxiliaryPrimes_prime B) hsize] at hc + rw [← arithmeticSquareMean_patterns hsize F] at hc + have ht := blockPatternEquiv_sum (fun S => F ((blockPatternEquiv B M).symm S)) + simp only [Equiv.symm_apply_apply] at ht + rwa [ht] at hc + +theorem arithmeticSquareMean_add (B : ℕ) (f g : ℕ → ℝ) : + arithmeticSquareMean B (fun u => f u+g u) = arithmeticSquareMean B f+arithmeticSquareMean B g := by + simp only [arithmeticSquareMean,sum_add_distrib,add_div] + +theorem arithmeticSquareMean_const_mul (B : ℕ) (c : ℝ) (f : ℕ → ℝ) : + arithmeticSquareMean B (fun u => c*f u) = c*arithmeticSquareMean B f := by + simp only [arithmeticSquareMean,← mul_sum,mul_div_assoc] + +theorem arithmeticSquareMean_mono (B : ℕ) {f g : ℕ → ℝ} (h : ∀ u, f u ≤ g u) : + arithmeticSquareMean B f ≤ arithmeticSquareMean B g := + div_le_div_of_nonneg_right (sum_le_sum (fun u _ => h u)) (by positivity) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticPeriod.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticPeriod.lean new file mode 100644 index 0000000000000000000000000000000000000000..22544301d9a9f217f8ac5867e88274fe022d07a6 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticPeriod.lean @@ -0,0 +1,98 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticAmplificationBounds +import OAI.NumberTheory.JointDickman.Counting.PeriodicNonnegative + +namespace OAI + +/-! # The exact finite period of the divisor amplification -/ + +namespace JointDickman +open Finset + +noncomputable def auxiliarySquarePeriod (B : ℕ) : ℕ := + (∏ p ∈ auxiliaryPrimes B, p)^2 + +theorem auxiliarySquarePeriod_pos (B : ℕ) : 0 < auxiliarySquarePeriod B := by + unfold auxiliarySquarePeriod + exact pow_pos (prod_pos (fun p hp => (auxiliaryPrimes_prime B p hp).pos)) _ + +instance (B : ℕ) : NeZero (auxiliarySquarePeriod B) := + ⟨(auxiliarySquarePeriod_pos B).ne'⟩ + +theorem auxiliaryProduct_dvd_period {B : ℕ} {A : Finset ℕ} + (hA : A ⊆ auxiliaryPrimes B) : (∏ p ∈ A, p) ∣ auxiliarySquarePeriod B := by + exact (prod_dvd_prod_of_subset A (auxiliaryPrimes B) id hA).trans (dvd_pow_self _ (by omega)) + +theorem auxiliaryProduct_mul_prime_dvd_period {B p : ℕ} {A : Finset ℕ} + (hp : p ∈ auxiliaryPrimes B) (hA : A ⊆ auxiliaryPrimes B) : + (∏ p ∈ A, p) * p ∣ auxiliarySquarePeriod B := by + unfold auxiliarySquarePeriod + rw [pow_two] + exact Nat.mul_dvd_mul (prod_dvd_prod_of_subset A (auxiliaryPrimes B) id hA) + (dvd_prod_of_mem id hp) + +theorem coefficientPrimeSet_quotient_modEq {B n m : ℕ} {A : Finset ℕ} + (h : n ≡ m [MOD auxiliarySquarePeriod B]) (hA : A ⊆ auxiliaryPrimes B) + (ha : (∏ p ∈ A, p) ∣ n) (hb : (∏ p ∈ A, p) ∣ m) : + coefficientPrimeSet B (n / (∏ p ∈ A, p)) = + coefficientPrimeSet B (m / (∏ p ∈ A, p)) := by + ext p + simp only [coefficientPrimeSet, mem_filter] + constructor + · rintro ⟨hp, hn⟩ + refine ⟨hp, (Nat.dvd_div_iff_mul_dvd hb).mpr ?_⟩ + exact (h.dvd_iff (auxiliaryProduct_mul_prime_dvd_period hp hA)).mp + ((Nat.dvd_div_iff_mul_dvd ha).mp hn) + · rintro ⟨hp, hm⟩ + refine ⟨hp, (Nat.dvd_div_iff_mul_dvd ha).mpr ?_⟩ + exact (h.dvd_iff (auxiliaryProduct_mul_prime_dvd_period hp hA)).mpr + ((Nat.dvd_div_iff_mul_dvd hb).mp hm) + +open Classical in +theorem arithmeticSubsetAmplification_modEq {B L n m : ℕ} (τ C : ℝ) + (w : ℕ → ℕ → ℝ) (h : n ≡ m [MOD auxiliarySquarePeriod B]) : + arithmeticSubsetAmplification B L τ C w n = + arithmeticSubsetAmplification B L τ C w m := by + unfold arithmeticSubsetAmplification + congr 1 + apply sum_congr rfl + intro A hA + apply sum_congr rfl + intro D hD + have hAP := mem_powerset.mp hA + have hDP := mem_powerset.mp hD + have ha := h.dvd_iff (auxiliaryProduct_dvd_period hAP) + have hd := (h.add_right 1).dvd_iff (auxiliaryProduct_dvd_period hDP) + by_cases hn : (∏ p ∈ A, p) ∣ n ∧ (∏ p ∈ D, p) ∣ n + 1 + · have hm := And.intro (ha.mp hn.1) (hd.mp hn.2) + rw [ite_eq_left hn, ite_eq_left hm, + coefficientPrimeSet_quotient_modEq h hAP hn.1 hm.1, + coefficientPrimeSet_quotient_modEq (h.add_right 1) hDP hn.2 hm.2] + · have hm : ¬ ((∏ p ∈ A, p) ∣ m ∧ (∏ p ∈ D, p) ∣ m + 1) := + fun hm => hn ⟨ha.mpr hm.1, hd.mpr hm.2⟩ + rw [ite_eq_right hn, ite_eq_right hm] + +open Classical in +noncomputable def residueAmplification (B L : ℕ) (τ C : ℝ) (w : ℕ → ℕ → ℝ) + (a : ZMod (auxiliarySquarePeriod B)) : ℝ := + arithmeticSubsetAmplification B L τ C w a.val + +theorem residueAmplification_natCast (B L n : ℕ) (τ C : ℝ) (w : ℕ → ℕ → ℝ) : + residueAmplification B L τ C w n = arithmeticSubsetAmplification B L τ C w n := by + unfold residueAmplification + rw [ZMod.val_natCast] + exact arithmeticSubsetAmplification_modEq τ C w (Nat.mod_modEq _ _) + +/-- The ordinary mean has this exact finite residue mean as its limit. -/ +theorem arithmeticAmplification_mean_tendsto (B L : ℕ) (τ C : ℝ) (w : ℕ → ℕ → ℝ) : + Filter.Tendsto (fun N : ℕ => + (∑ n ∈ range N, arithmeticSubsetAmplification B L τ C w n) / (N : ℝ)) + Filter.atTop (nhds ((∑ a : ZMod (auxiliarySquarePeriod B), + residueAmplification B L τ C w a) / (auxiliarySquarePeriod B : ℝ))) := by + have h := periodicAverage_tendsto (fun a => (residueAmplification B L τ C w a : ℂ)) + have hr := Complex.continuous_re.continuousAt.tendsto.comp h + simpa only [Function.comp_def, periodicAverage, residueMean, residueAmplification_natCast, + Complex.div_natCast_re, Complex.re_sum, Complex.ofReal_re] using hr + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticProfilePreservation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticProfilePreservation.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf61ab7d8f25bfb2baddd44fc3cee47a3bf7f20e --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticProfilePreservation.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.JointDickman.Amplification.ProfilePreservation + +namespace OAI + +/-! # Profile preservation for the manuscript's actual smooth divisor weight -/ + +namespace JointDickman +open Finset Filter +open scoped Topology + +noncomputable def amplificationPeriod (B : ℕ) : ℕ+ := + ⟨auxiliarySquarePeriod B, auxiliarySquarePeriod_pos B⟩ + +noncomputable def smoothResidueAmplification (B L : ℕ) (τ C : ℝ) (T : ℕ) : + ZMod (amplificationPeriod B : ℕ) → ℂ := + fun a => (residueAmplification B L τ C (amplificationSmoothWeight B T) a : ℂ) + +theorem smoothResidueAmplification_energy (B L : ℕ) (τ C : ℝ) (T : ℕ) : + residueEnergy (smoothResidueAmplification B L τ C T) = + arithmeticAmplificationMoment B L τ C (amplificationSmoothWeight B T) 2 := by + unfold residueEnergy smoothResidueAmplification arithmeticAmplificationMoment + residueAmplification amplificationPeriod + simp only [Complex.norm_real, Real.norm_eq_abs, sq_abs] + rfl + +theorem smoothResidueAmplification_mean (B L : ℕ) (τ C : ℝ) (T : ℕ) : + residueMean (smoothResidueAmplification B L τ C T) = + (arithmeticAmplificationMoment B L τ C (amplificationSmoothWeight B T) 1 : ℂ) := + residueAmplification_mean B L τ C (amplificationSmoothWeight B T) + +/-- The precise preservation statement, using the actual arithmetic weight. +Only the previously cited sieve and Mertens inputs enter its moment bound. -/ +theorem smooth_arithmetic_profile_preservation + (hFord : PublishedInputs.FordUpperSieveInput) + (hM : PublishedInputs.PrimeReciprocalMertensInput) + (W : ResidueProfile) (L : ℕ) (τ C : ℝ) (T : ℕ → ℕ) + (hT : ∀ᶠ B : ℕ in atTop, 0 < T B ∧ (T B : ℝ) ≤ Real.exp ((1/10 : ℝ)*B)) : + Tendsto (fun B => W.correlation (amplificationPeriod B) + (smoothResidueAmplification B L τ C (T B)) - W.mean * + (arithmeticAmplificationMoment B L τ C (amplificationSmoothWeight B (T B)) 1 : ℂ)) + atTop (nhds 0) := by + have hcop (d : ℕ+) : ∀ᶠ B : ℕ in atTop, + (d : ℕ).Coprime (amplificationPeriod B) := by + filter_upwards [auxiliarySquarePeriod_eventually_coprime d d.pos] with B hB + exact hB.symm + obtain ⟨K,hK,hb⟩ := smooth_arithmetic_second_bound hFord hM L τ C + have hm : ∀ᶠ B : ℕ in atTop, + residueEnergy (smoothResidueAmplification B L τ C (T B)) ≤ K := by + filter_upwards [hb,hT] with B hB hTB + rw [smoothResidueAmplification_energy] + exact hB (T B) hTB.1 hTB.2 + simpa only [smoothResidueAmplification_mean] using + W.preservation amplificationPeriod (fun B => smoothResidueAmplification B L τ C (T B)) + hcop ⟨K,hK,hm⟩ + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticRootIdentification.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticRootIdentification.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0baea924fb9d98a2af86ef4bd2322a63f0df945 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticRootIdentification.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.JointDickman.Counting.ArithmeticCoefficientHits +import OAI.NumberTheory.JointDickman.Counting.MaskedCoefficientErrors + +namespace OAI + +/-! # Arithmetic root families agree outside the explicit exceptional events -/ + +namespace JointDickman +open Finset Classical + +theorem trimmedCandidatePrimeHit_eq {B M p : ℕ} [Fact p.Prime] + (I : Finset (BlockCandidateIndex M)) (H : (univ : Finset (Fin M)).powerset) + (r : ZMod p) + (hno : ∀ e ∈ I, p ∈ candidateCoefficientPrimes B e → + e ∉ (maskedCandidatePrimeHit I p H r).val) : + trimmedCandidatePrimeHit B I p H r = maskedCandidatePrimeHit I p H r := by + apply Subtype.ext + apply filter_eq_self.mpr + intro e he + have hei : e ∈ I := mem_powerset.mp (maskedCandidatePrimeHit I p H r).property he + exact fun hc => hno e hei hc he + +noncomputable def arithmeticCandidatePrimeFamily {M : ℕ} (B : ℕ) + (I : Finset (BlockCandidateIndex M)) (m : BlockCandidateIndex M → ℕ) : + auxiliaryPrimes B → I.powerset := fun p => arithmeticCandidateHit I p.val m + +/-- All three exclusions have their own proved probability bounds. The +quotient family here is the actual family satisfying the affine equations. -/ +theorem arithmetic_roots_eq_masked {B L T H M u : ℕ} {τ C : ℝ} + (I : Finset (BlockCandidateIndex M)) (m : BlockCandidateIndex M → ℕ) + (he : ∀ e ∈ I, BlockCandidateAdmissible B L T H τ C e) + (heq : ∀ e ∈ I, candidateHigh e*candidateLow e*m e+candidateLow e = + candidateQuotient e*(u+(e.1.1.val+1))) + (hforce : ∀ e ∈ I, ¬ CandidateForcedWitness B e + (fun i => coefficientPrimeSet B (u+(i.val+1)))) + (hactual : ¬ ArithmeticCoefficientHit B I m) + (hmasked : ¬ MaskedCoefficientEvent I (arithmeticPrimePatterns B M u) + (fun p => (u : ZMod p.val))) : + arithmeticCandidatePrimeFamily B I m = + maskedPrimeRootFamily I (arithmeticPrimePatterns B M u) (fun p => (u : ZMod p.val)) := by + funext p + let : Fact p.val.Prime := ⟨auxiliaryPrimes_prime B p.val p.property⟩ + have hc : ∀ e ∈ I, p.val ∈ candidateCoefficientPrimes B e → ¬ p.val ∣ m e := by + intro e hei hcoef hdiv + exact hactual ⟨e,hei,p.val,hcoef,hdiv⟩ + have hm : ∀ e ∈ I, p.val ∈ candidateCoefficientPrimes B e → + e ∉ (maskedCandidatePrimeHit I p.val (blockPrimeHit M p.val (u : ZMod p.val)) + (u : ZMod p.val)).val := by + intro e hei hcoef hdiv + apply hmasked + refine ⟨e,hei,p.val,hcoef,?_⟩ + simpa only [maskedCoefficientTest,dite_eq_left p.property,arithmeticPrimePatterns] using hdiv + exact (arithmetic_candidate_hit_eq_trimmed I m p.property he heq hforce hc).trans + (trimmedCandidatePrimeHit_eq I _ _ hm) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticRootMask.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticRootMask.lean new file mode 100644 index 0000000000000000000000000000000000000000..eea3bf2822c80bb6d14ea116ed26b2542c406e59 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticRootMask.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticCandidateRoots +import OAI.NumberTheory.JointDickman.Probability.MaskedResidueModel +import OAI.NumberTheory.JointDickman.Amplification.CandidateForcedEvent + +namespace OAI + +/-! # Matching arithmetic quotient tests with the masked residue tests -/ + +namespace JointDickman +open Finset Classical + +theorem candidateSiteValue_low {M : ℕ} (e : BlockCandidateIndex M) : + candidateSiteValue e e.1.1 = (candidateLow e : ℤ) := by + simp [candidateSiteValue] + +theorem candidateSiteValue_high {B L T H M : ℕ} {τ C : ℝ} + {e : BlockCandidateIndex M} (he : BlockCandidateAdmissible B L T H τ C e) : + candidateSiteValue e e.1.2 = (candidateHigh e : ℤ) := by + have hi : e.1.1.val ≤ e.1.2.val := (show e.1.1.val < e.1.2.val from he.1).le + have hlag : (candidateLag e : ℤ) = (e.1.2.val : ℤ)-e.1.1.val := by + unfold candidateLag + exact Int.ofNat_sub hi + have hco : (candidateHigh e : ℤ) = candidateLow e+ + (candidateLag e : ℤ)*candidateQuotient e := by + exact_mod_cast he.2.2.2.2.1 + rw [hlag] at hco + exact hco.symm + +/-- Away from coefficient primes, an occupied residue root would be one +of the already controlled forced hits at a third site. -/ +theorem candidate_occupied_root_impossible {B L T H M p u : ℕ} {τ C : ℝ} + [Fact p.Prime] {e : BlockCandidateIndex M} + (he : BlockCandidateAdmissible B L T H τ C e) (hp : p ∈ auxiliaryPrimes B) + (ha : ¬ p ∣ candidateHigh e) (hb : ¬ p ∣ candidateLow e) + (hc : ¬ p ∣ candidateQuotient e) + (hno : ¬ CandidateForcedWitness B e (fun i => coefficientPrimeSet B (u+(i.val+1)))) + (hocc : blockPrimeHit M p (u : ZMod p) ≠ emptyBlockPrimeHit M) : + (u : ZMod p) ≠ candidateModRoot p e := by + intro hroot + have hnonempty : (blockPrimeHit M p (u : ZMod p)).val.Nonempty := by + apply nonempty_iff_ne_empty.mpr + intro h + exact hocc (Subtype.ext h) + obtain ⟨s,hs⟩ := hnonempty + have hsite : blockSiteRoot M p s = (u : ZMod p) := (mem_filter.mp hs).2 + have hd := candidateModRoot_site_collision e s hc (hroot.symm.trans hsite.symm) + by_cases hslo : s = e.1.1 + · subst s + rw [candidateSiteValue_low,Int.natAbs_natCast] at hd + exact hb hd + by_cases hshi : s = e.1.2 + · subst s + rw [candidateSiteValue_high he,Int.natAbs_natCast] at hd + exact ha hd + apply hno + refine ⟨s,hslo,hshi,p,mem_filter.mpr ⟨hp,hd⟩,?_⟩ + exact mem_filter.mpr ⟨hp,(blockPrimeHit_divisibility M p u s).mp hs⟩ + +/-- Thus every nonexceptional auxiliary prime has the same test in the +actual quotient and the masked conditional model. -/ +theorem arithmetic_quotient_masked_hit {B L T H M p u m : ℕ} {τ C : ℝ} + [Fact p.Prime] (I : Finset (BlockCandidateIndex M)) + {e : BlockCandidateIndex M} (heI : e ∈ I) + (he : BlockCandidateAdmissible B L T H τ C e) (hp : p ∈ auxiliaryPrimes B) + (heq : candidateHigh e*candidateLow e*m+candidateLow e = + candidateQuotient e*(u+(e.1.1.val+1))) + (ha : ¬ p ∣ candidateHigh e) (hb : ¬ p ∣ candidateLow e) + (hc : ¬ p ∣ candidateQuotient e) + (hno : ¬ CandidateForcedWitness B e (fun i => coefficientPrimeSet B (u+(i.val+1)))) : + p ∣ m ↔ e ∈ (maskedCandidatePrimeHit I p + (blockPrimeHit M p (u : ZMod p)) (u : ZMod p)).val := by + have hr := candidate_affine_quotient_root e heq ha hb hc + by_cases hocc : blockPrimeHit M p (u : ZMod p) = emptyBlockPrimeHit M + · simp only [maskedCandidatePrimeHit,hocc,ite_true,rootHitType,rootHitSet, + mem_filter,heI,true_and] + exact hr.trans eq_comm + · have hn := candidate_occupied_root_impossible he hp ha hb hc hno hocc + have hm : ¬ p ∣ m := fun h => hn (hr.mp h) + simp [maskedCandidatePrimeHit,hocc,hm] + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticSquareHits.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticSquareHits.lean new file mode 100644 index 0000000000000000000000000000000000000000..38f9b3e9baa1f8536c97140801704ca3416ee2dc --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/ArithmeticSquareHits.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticPeriod +import OAI.NumberTheory.JointDickman.Probability.ResidueQuotientMean + +namespace OAI + +/-! # The exact rare-square error for the arithmetic amplification -/ + +namespace JointDickman +open Finset + +open Classical in +def AuxiliarySquareHit (B n : ℕ) : Prop := + ∃ p ∈ auxiliaryPrimes B, p^2 ∣ n ∨ p^2 ∣ n+1 + +theorem auxiliarySquare_dvd_period {B p : ℕ} (hp : p ∈ auxiliaryPrimes B) : + p^2 ∣ auxiliarySquarePeriod B := by + unfold auxiliarySquarePeriod + exact pow_dvd_pow_of_dvd (dvd_prod_of_mem id hp) 2 + +open Classical in +theorem residue_square_divisor_mean {B p : ℕ} (hp : p ∈ auxiliaryPrimes B) (k : ℕ) : + (∑ a : ZMod (auxiliarySquarePeriod B), + if p^2 ∣ a.val+k then (1 : ℝ) else 0) / (auxiliarySquarePeriod B : ℝ) = + 1 / (p : ℝ)^2 := by + let : NeZero (p^2) := ⟨pow_ne_zero _ (auxiliaryPrimes_prime B p hp).ne_zero⟩ + have h := residue_quotient_mean (auxiliarySquare_dvd_period hp) + (fun r : ZMod (p^2) => if r = -(k : ZMod (p^2)) then (1 : ℝ) else 0) + have he (n : ℕ) : + (if (n : ZMod (p^2)) = -(k : ZMod (p^2)) then (1 : ℝ) else 0) = + if p^2 ∣ n+k then 1 else 0 := by + congr 1 + rw [← ZMod.natCast_eq_zero_iff] + simp only [Nat.cast_add, add_eq_zero_iff_eq_neg] + simp only [he, sum_ite_eq', mem_univ, ite_true, Nat.cast_pow] at h + exact h + +open Classical in +theorem squareHit_indicator_le (B n : ℕ) : + (if AuxiliarySquareHit B n then (1 : ℝ) else 0) ≤ + ∑ p ∈ auxiliaryPrimes B, + ((if p^2 ∣ n then (1 : ℝ) else 0) + (if p^2 ∣ n+1 then (1 : ℝ) else 0)) := by + have hn (p : ℕ) : 0 ≤ (if p^2 ∣ n then (1 : ℝ) else 0) + + (if p^2 ∣ n+1 then (1 : ℝ) else 0) := by positivity + by_cases h : AuxiliarySquareHit B n + · rw [ite_eq_left h] + obtain ⟨p, hp, hd⟩ := h + have ht : (1 : ℝ) ≤ (if p^2 ∣ n then (1 : ℝ) else 0) + + (if p^2 ∣ n+1 then (1 : ℝ) else 0) := by + rcases hd with hd | hd <;> simp only [hd, ite_true] <;> split_ifs <;> norm_num + exact ht.trans (single_le_sum (fun p _ => hn p) hp) + · rw [ite_eq_right h] + exact sum_nonneg (fun p _ => hn p) + +open Classical in +theorem residue_squareHit_mean_bound (B : ℕ) : + (∑ a : ZMod (auxiliarySquarePeriod B), + if AuxiliarySquareHit B a.val then (1 : ℝ) else 0) / (auxiliarySquarePeriod B : ℝ) ≤ + 2 * ∑ p ∈ auxiliaryPrimes B, 1 / (p : ℝ)^2 := by + calc + _ ≤ (∑ a : ZMod (auxiliarySquarePeriod B), ∑ p ∈ auxiliaryPrimes B, + ((if p^2 ∣ a.val then (1 : ℝ) else 0) + + (if p^2 ∣ a.val+1 then (1 : ℝ) else 0))) / (auxiliarySquarePeriod B : ℝ) := + div_le_div_of_nonneg_right (sum_le_sum (fun a _ => squareHit_indicator_le B a.val)) + (Nat.cast_nonneg _) + _ = _ := by + rw [sum_comm, sum_div] + simp_rw [sum_add_distrib, add_div] + have h0 (p : ℕ) (hp : p ∈ auxiliaryPrimes B) := residue_square_divisor_mean hp 0 + simp only [add_zero] at h0 + rw [mul_sum] + apply sum_congr rfl + intro p hp + rw [h0 p hp, residue_square_divisor_mean hp 1] + ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AtomicProductMeasure.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AtomicProductMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab8f23f9f2ca128df4f5654ead50dfa591b3e40a --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AtomicProductMeasure.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.PrimeProductMeasure + +namespace OAI + +/-! # Exact finite atomic expansions of product measures -/ +namespace JointDickman +open Finset MeasureTheory +open scoped NNReal ENNReal + +noncomputable def finitePointMeasure {Ω : Type*} [MeasurableSpace Ω] (t : Ω) : FiniteMeasure Ω := + ⟨Measure.dirac t, inferInstance⟩ + +open Classical in +theorem finitePointMeasure_apply {Ω : Type*} [MeasurableSpace Ω] [MeasurableSingletonClass Ω] + (t : Ω) (s : Set Ω) : finitePointMeasure t s = if t ∈ s then 1 else 0 := by + by_cases h : t ∈ s <;> simp [finitePointMeasure, Measure.dirac_apply, h] + +theorem finiteMeasure_sum_apply {Ω β : Type*} [MeasurableSpace Ω] + (P : Finset β) (μ : β → FiniteMeasure Ω) (s : Set Ω) : + (∑ p ∈ P, μ p) s = ∑ p ∈ P, μ p s := by + classical + induction P using Finset.induction_on with + | empty => simp + | @insert p P hp ih => simp only [sum_insert hp, FiniteMeasure.coeFn_add, Pi.add_apply, ih] + +noncomputable def finiteAtomicMeasure (P : Finset ℕ) (w : ℕ → ℝ≥0) (f : ℕ → ℝ) : FiniteMeasure ℝ := + ∑ p ∈ P, w p • finitePointMeasure (f p) + +noncomputable def atomicTupleMeasure (P : Finset ℕ) (w : ℕ → ℝ≥0) (f : ℕ → ℝ) (h : ℕ) : + FiniteMeasure (Fin h → ℝ) := + ∑ v ∈ Fintype.piFinset (fun _ : Fin h => P), + (∏ i, w (v i)) • finitePointMeasure (fun i => f (v i)) + +open Classical in +theorem finiteAtomicMeasure_apply (P : Finset ℕ) (w : ℕ → ℝ≥0) (f : ℕ → ℝ) (s : Set ℝ) : + finiteAtomicMeasure P w f s = ∑ p ∈ P, if f p ∈ s then w p else 0 := by + rw [finiteAtomicMeasure, finiteMeasure_sum_apply] + apply sum_congr rfl + intro p hp + rw [FiniteMeasure.smul_apply, smul_eq_mul, finitePointMeasure_apply] + split_ifs <;> simp + +open Classical in +theorem atomicTupleMeasure_apply (P : Finset ℕ) (w : ℕ → ℝ≥0) (f : ℕ → ℝ) + (h : ℕ) (s : Set (Fin h → ℝ)) : + atomicTupleMeasure P w f h s = ∑ v ∈ Fintype.piFinset (fun _ : Fin h => P), + if (fun i => f (v i)) ∈ s then ∏ i, w (v i) else 0 := by + rw [atomicTupleMeasure, finiteMeasure_sum_apply] + apply sum_congr rfl + intro v hv + rw [FiniteMeasure.smul_apply, smul_eq_mul, finitePointMeasure_apply] + split_ifs <;> simp + +theorem finiteAtomicMeasure_pi (P : Finset ℕ) (w : ℕ → ℝ≥0) (f : ℕ → ℝ) (h : ℕ) : + FiniteMeasure.pi (fun _ : Fin h => finiteAtomicMeasure P w f) = atomicTupleMeasure P w f h := by + classical + apply FiniteMeasure.toMeasure_injective + apply Measure.pi_eq + intro s hs + have he : atomicTupleMeasure P w f h (Set.pi Set.univ s) = + ∏ i, finiteAtomicMeasure P w f (s i) := by + rw [atomicTupleMeasure_apply] + simp only [Set.mem_pi, Set.mem_univ, forall_true_left] + calc + _ = ∑ v ∈ Fintype.piFinset (fun _ : Fin h => P), + ∏ i, if f (v i) ∈ s i then w (v i) else 0 := by + apply sum_congr rfl + intro v hv + rw [Fintype.prod_ite_zero] + split_ifs <;> rfl + _ = ∏ i : Fin h, ∑ p ∈ P, if f p ∈ s i then w p else 0 := + by + symm + rw [prod_univ_sum] + _ = _ := by simp only [finiteAtomicMeasure_apply] + simp only [← FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure] + exact_mod_cast he + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandChoice.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandChoice.lean new file mode 100644 index 0000000000000000000000000000000000000000..ccb743daa82ff7526a2c8378eb9b6dc13140ea94 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandChoice.lean @@ -0,0 +1,45 @@ +import OAI.NumberTheory.JointDickman.Amplification.AuxiliaryBandCount + +namespace OAI + +/-! # Choosing the small power band with an arbitrarily small missing density -/ +namespace JointDickman +open Finset Filter TwoPointCorrelations +open scoped Classical Topology + +theorem exists_auxiliary_power_band {ε d : ℝ} (hε : 0 < ε) (hd : 0 < d) : + ∃ α β : ℝ, 0 < α ∧ α ≤ β ∧ β < d ∧ + ∀ᶠ N : ℕ in atTop, + (((Ioc N (2*N)).filter fun n => + mrtPrimeAvoids (mrtPrimeBand ((N:ℝ)^α) ((N:ℝ)^β)) n).card:ℝ)/N ≤ ε := by + obtain ⟨C,M,hC,_hM,hbound⟩ := auxiliary_power_missing_count + let R := max 1 (3*C/ε) + have hR : 1 ≤ R := le_max_left _ _ + have hR0 : 0 < R := by linarith + have hmain : C/R ≤ ε/3 := by + apply (div_le_iff₀ hR0).mpr + have hh := (div_le_iff₀ hε).mp (show 3*C/ε ≤ R from le_max_right _ _) + nlinarith + obtain ⟨r,hr⟩ := pow_unbounded_of_one_lt + (3*Real.exp (2*(Real.log R+M))/ε) (by norm_num : (1:ℝ)<2) + have htail : Real.exp (2*(Real.log R+M))/(2:ℝ)^(2*r+1) ≤ ε/3 := by + have hp : (2:ℝ)^r ≤ 2^(2*r+1) := pow_le_pow_right₀ (by norm_num) (by omega) + have hh := (div_lt_iff₀ hε).mp (hr.trans_le hp) + apply (div_le_iff₀ (by positivity : (0:ℝ)<2^(2*r+1))).mpr + nlinarith + let β := min (d/2) (1/(8*((r:ℝ)+1))) + have hβ : 0 < β := lt_min (by positivity) (by positivity) + have hβd : β < d := (min_le_left _ _).trans_lt (by linarith) + have hsmall : β*(4*r:ℕ)<1 := by + have hb := min_le_right (d/2) (1/(8*((r:ℝ)+1))) + change β ≤ _ at hb + have hh := (le_div_iff₀ (by positivity : 0<8*((r:ℝ)+1))).mp hb + push_cast + nlinarith [show (0:ℝ)≤r by positivity] + refine ⟨β/R,β,div_pos hβ hR0,div_le_self hβ.le hR,hβd,?_⟩ + filter_upwards [hbound R β hR hβ r hsmall (ε/3) (by positivity)] with N hN + linarith + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandCount.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..36c24b0ab0eeb58b816f4004beeec30e7d1e104c --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandCount.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.JointDickman.Amplification.AuxiliaryPowerDensity + +namespace OAI + +/-! # Missing auxiliary factors in the actual dyadic interval -/ +namespace JointDickman +open Finset Filter TwoPointCorrelations +open scoped Classical Topology + +lemma uniformFiniteLaw_shifted_count (A N : ℕ) [NeZero N] (E : ℕ → Prop) : + (uniformFiniteLaw (Fin N)).probability (fun j => E (A+j.val)) = + (((Ico A (A+N)).filter E).card:ℝ)/N := by + rw [uniformFiniteLaw_nat_count N (fun n => E (A+n))] + have he : (((range N).filter (fun n => E (A+n))).image (fun n => A+n)) = + (Ico A (A+N)).filter E := by + ext n + simp only [mem_image,mem_filter,mem_range,mem_Ico] + constructor + · rintro ⟨k,⟨hk,hEk⟩,rfl⟩ + exact ⟨⟨by omega,by omega⟩,hEk⟩ + · rintro ⟨⟨hlo,hhi⟩,hEn⟩ + refine ⟨n-A,⟨by omega,?_⟩,by omega⟩ + simpa only [Nat.add_sub_of_le hlo] using hEn + rw [← he,card_image_of_injective _ (fun _ _ h => Nat.add_left_cancel h)] + +lemma uniformFiniteLaw_dyadic_count (N : ℕ) [NeZero N] (E : ℕ → Prop) : + (uniformFiniteLaw (Fin N)).probability (fun j => E (N+1+j.val)) = + (((Ioc N (2*N)).filter E).card:ℝ)/N := by + rw [uniformFiniteLaw_shifted_count] + have he : Ico (N+1) (N+1+N)=Ioc N (2*N) := by + ext n + simp only [mem_Ico,mem_Ioc] + omega + rw [he] + +theorem auxiliary_power_missing_count : ∃ C M : ℝ, 0 < C ∧ 0 ≤ M ∧ + ∀ R β : ℝ, 1 ≤ R → 0 < β → ∀ r : ℕ, β*(4*r:ℕ)<1 → + ∀ ε : ℝ, 0 < ε → ∀ᶠ N : ℕ in atTop, + (((Ioc N (2*N)).filter fun n => + mrtPrimeAvoids (mrtPrimeBand ((N:ℝ)^(β/R)) ((N:ℝ)^β)) n).card:ℝ)/N ≤ + C/R+Real.exp (2*(Real.log R+M))/(2:ℝ)^(2*r+1)+ε := by + obtain ⟨C,M,hC,hM,hbound⟩ := auxiliary_power_missing + refine ⟨C,M,hC,hM,?_⟩ + intro R β hR hβ r hsmall ε hε + have hh := (hbound R β hR hβ r hsmall ε hε).filter_mono tendsto_natCast_atTop_atTop + filter_upwards [hh,eventually_gt_atTop (0:ℕ)] with N hN hN0 + let : NeZero N := ⟨hN0.ne'⟩ + have hb := hN (N+1) N le_rfl + rwa [uniformFiniteLaw_dyadic_count] at hb + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandDensity.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2c434d1d2cabb784273b797398281318b084a30 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryBandDensity.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.JointDickman.Amplification.CanonicalTypicalDensity +import OAI.NumberTheory.TwoPointCorrelations.MRTTypicalSieveScale + +namespace OAI + +/-! # A fixed logarithmic-ratio auxiliary band misses few integers -/ +namespace JointDickman +open Finset Filter TwoPointCorrelations +open scoped Classical Topology + +theorem auxiliary_band_missing_bound : ∃ C M : ℝ, 0 < C ∧ 0 ≤ M ∧ + ∀ P Q R : ℝ, 2 ≤ P → P ≤ Q → 1 ≤ R → Real.log Q=R*Real.log P → + ∀ (A N : ℕ) [NeZero N] (r : ℕ), + (uniformFiniteLaw (Fin N)).probability + (fun j => mrtPrimeAvoids (mrtPrimeBand P Q) (A+j.val)) ≤ + C/R+Real.exp (2*(Real.log R+M))/(2:ℝ)^(2*r+1)+ + ((2*r+1:ℕ):ℝ)*2^(2*r)*Q^(4*r)/(N:ℝ) := by + obtain ⟨C,hC,hbound⟩ := mrt_missing_band_probability + obtain ⟨M,hM,hmass⟩ := mrt_prime_band_mertens + refine ⟨C,M,hC,hM,?_⟩ + intro P Q R hP hPQ hR hrel A N _ r + have hP0 : 0 < P := by linarith + have hQ1 : 1 ≤ Q := by linarith + have hR0 : 0 < R := by linarith + have hlP : 0 < Real.log P := Real.log_pos (by linarith) + have he : Real.log (Real.log Q)-Real.log (Real.log P)=Real.log R := by + rw [hrel,Real.log_mul hR0.ne' hlP.ne'] + ring + have hm : (∑ p ∈ mrtPrimeBand P Q,1/(p:ℝ)) ≤ Real.log R+M := by + have hh := (abs_le.mp (hmass P Q hP hPQ)).2 + rw [he] at hh + linarith + have hmain : C*Real.log P/Real.log Q=C/R := by + rw [hrel] + field_simp + have hb : ((mrtPrimeBand P Q).card:ℝ)*Q+1 ≤ 2*Q^2 := by + have hc := mrt_prime_band_card_le P Q (by linarith) + have hh := mul_le_mul_of_nonneg_right hc (by linarith : 0 ≤ Q) + nlinarith [sq_nonneg (Q-1)] + have hpow := pow_le_pow_left₀ (by positivity : 0 ≤ ((mrtPrimeBand P Q).card:ℝ)*Q+1) hb (2*r) + have hpow' : (((mrtPrimeBand P Q).card:ℝ)*Q+1)^(2*r) ≤ 2^(2*r)*Q^(4*r) := by + convert hpow using 1 + rw [mul_pow,← pow_mul] + congr 2 + omega + have hh := hbound P Q hP hPQ A N r + rw [hmain] at hh + apply hh.trans + apply add_le_add + · exact add_le_add le_rfl + (div_le_div_of_nonneg_right (Real.exp_le_exp.mpr (by linarith)) (by positivity)) + · have hp := mul_le_mul_of_nonneg_left hpow' + (by positivity : 0 ≤ 1/(N:ℝ)*((2*r+1:ℕ):ℝ)) + convert hp using 1; ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryCofactorScales.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryCofactorScales.lean new file mode 100644 index 0000000000000000000000000000000000000000..4fdb6c1edd81493138e810c740982fe6244ea1da --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryCofactorScales.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.JointDickman.Amplification.AuxiliaryRangeScales + +namespace OAI + +/-! # Floor lengths for cofactors in the small power auxiliary band -/ +namespace JointDickman +open Filter +open scoped Topology + +theorem auxiliary_cofactor_floor_scales : + ∀ᶠ N : ℕ in atTop, ∀ a : ℝ, 1 ≤ a → a ≤ (N:ℝ)^(1/4:ℝ) → + (N:ℝ)^(1/2:ℝ) ≤ (⌊(N:ℝ)/a⌋₊:ℝ) ∧ + (N:ℝ) ≤ (⌊(2*N:ℝ)/a⌋₊:ℝ)^2 ∧ + (⌊(2*N:ℝ)/a⌋₊:ℝ) ≤ 2*(N:ℝ) := by + have hg := ((tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/4)).comp + tendsto_natCast_atTop_atTop).eventually (eventually_ge_atTop 2) + filter_upwards [hg,eventually_ge_atTop (1:ℕ)] with N hquarter hN a ha haN + have hn : (0:ℝ) (Real.log X)^4*X^(β-1/12)) atTop (𝓝 0) := by + apply hp.congr' + filter_upwards [eventually_gt_atTop (0:ℝ)] with X hX + rw [show β-1/12=-(1/12-β) by ring,Real.rpow_neg hX.le] + norm_num [div_eq_mul_inv] + have h1 := hlog.const_mul (8*L^2/c^4) + have h2 := hp'.const_mul (2*L^2*(H+1)) + have hh := (h1.add h2).const_mul 48000 + unfold auxiliaryVanishingCost + simpa only [Function.comp_apply,div_eq_mul_inv,mul_assoc,mul_zero,add_zero] using hh + +theorem auxiliary_cost_eventually_bound (C H L : ℝ) (hC : 0 ≤ C) (hH : 0 ≤ H) + {α β : ℝ} (hα : 0 < α) : + ∀ᶠ N : ℕ in atTop, ∀ T a b k : ℝ, + 0 ≤ T → T ≤ N → Real.exp (-1)*(N:ℝ)^α ≤ a → a ≤ (N:ℝ)^β → + 0 ≤ k → k ≤ L*Real.log (N:ℝ) → + k^2*auxiliarySampleCost C H N N T a b ≤ + auxiliaryVanishingCost H L (α/2) β N+L^2*b^2*C/(α/2)^2 := by + have hlow := (eventually_auxiliary_log_lower hα).filter_mono tendsto_natCast_atTop_atTop + have hlog := (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).eventually + (eventually_ge_atTop 1) + filter_upwards [hlow,hlog,eventually_gt_atTop (0:ℕ)] with N hlow hlog hN + intro T a b k hT hTN ha haβ hk0 hk + have hn : (0:ℝ) ((Real.log a)^10)⁻¹ < + ‖mrtExponentialPolynomial Q (fun p => f p/(p:ℂ)) + (fun p => -Real.log (p:ℝ)) t‖)).card):ℝ) ≤ a^γ := by + let r := ⌈B⌉₊ + obtain ⟨C,hC,hbound⟩ := fixed_prime_moment_large_bound r + let k : ℕ := 2+10*(2*r) + have hlim : Tendsto (fun a : ℝ => C*(Real.log a)^k/a^γ) atTop (𝓝 0) := by + have hh := (log_power_div_power_tendsto_zero (k:ℝ) hγ).const_mul C + simpa only [Real.rpow_natCast,mul_zero,mul_div_assoc] using hh + filter_upwards [eventually_ge_atTop (Real.exp 1), + hlim.eventually (eventually_le_nhds (by norm_num : (0:ℝ)<1))] with a ha hsmall + intro Q hQ f hf U hsep hU + have ha1 : 1 ≤ a := (Real.one_le_exp (by norm_num : (0:ℝ)≤1)).trans ha + have hlog : 0 < Real.log a := lt_of_lt_of_le (by norm_num : (0:ℝ)<1) + (by simpa using Real.log_le_log (Real.exp_pos 1) ha) + have hheight : a^B ≤ a^r := by + have hh := Real.rpow_le_rpow_of_exponent_le ha1 (Nat.le_ceil B) + simpa only [Real.rpow_natCast] using hh + let V := ((Real.log a)^10)⁻¹ + let S := U.filter (fun t => V < ‖mrtExponentialPolynomial Q (fun p => f p/(p:ℂ)) + (fun p => -Real.log (p:ℝ)) t‖) + have hh := hbound a ha Q hQ f hf S + (fun x hx y hy hxy => hsep x (mem_filter.mp hx).1 y (mem_filter.mp hy).1 hxy) + (fun t ht => (hU t (mem_filter.mp ht).1).trans hheight) V (by dsimp [V]; positivity) + (fun t ht => (mem_filter.mp ht).2.le) + have he : C*(Real.log a)^2/V^(2*r) = C*(Real.log a)^k := by + dsimp [V,k] + rw [inv_pow,div_inv_eq_mul,mul_assoc,← pow_mul,← pow_add] + apply hh.trans + rw [he] + exact (div_le_one (Real.rpow_pos_of_pos (by linarith : 0 Real.log (Real.log (auxiliaryCutoff B)) / Real.log B) atTop (𝓝 0) := by + have hlog := Real.tendsto_log_atTop.comp (tendsto_natCast_atTop_atTop : Tendsto (fun B : ℕ => (B : ℝ)) atTop atTop) + have hsmall := Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp hlog + have hconst : Tendsto (fun B : ℕ => Real.log 1000 / Real.log B) atTop (𝓝 0) := tendsto_const_nhds.div_atTop hlog + have h := hconst.add hsmall + norm_num only [zero_add] at h + apply h.congr' + filter_upwards [eventually_gt_atTop 1] with B hB + have hl : 0 < Real.log B := Real.log_pos (by exact_mod_cast hB) + rw [log_auxiliaryCutoff, Real.log_mul (by norm_num : (1000 : ℝ) ≠ 0) hl.ne', add_div] + rfl + +theorem auxiliaryLogLength_div_log_tendsto : + Tendsto (fun B : ℕ => auxiliaryLogLength B / Real.log B) atTop (𝓝 1) := by + have h := (tendsto_const_nhds : Tendsto (fun _ : ℕ => (1 : ℝ)) atTop (𝓝 1)).sub logLogCutoff_div_log_tendsto_zero + norm_num only [sub_zero] at h + apply h.congr' + filter_upwards [eventually_gt_atTop 1] with B hB + have hl : 0 < Real.log B := Real.log_pos (by exact_mod_cast hB) + rw [auxiliaryLogLength_eq hB, log_auxiliaryCutoff, + Real.log_mul (by norm_num : (1000 : ℝ) ≠ 0) hl.ne'] + field_simp + ring + +theorem log_div_auxiliaryLogLength_tendsto : + Tendsto (fun B : ℕ => Real.log B / auxiliaryLogLength B) atTop (𝓝 1) := by + have h := auxiliaryLogLength_div_log_tendsto.inv₀ (by norm_num : (1 : ℝ) ≠ 0) + simpa only [inv_div, inv_one] using h + +theorem logLogCutoff_div_auxiliaryLogLength_tendsto_zero : + Tendsto (fun B : ℕ => Real.log (Real.log (auxiliaryCutoff B)) / auxiliaryLogLength B) atTop (𝓝 0) := by + have h := logLogCutoff_div_log_tendsto_zero.mul log_div_auxiliaryLogLength_tendsto + norm_num only [zero_mul] at h + apply h.congr' + filter_upwards [eventually_gt_atTop 1] with B hB + have hl : Real.log B ≠ 0 := (Real.log_pos (by exact_mod_cast hB)).ne' + field_simp + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryOdds.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryOdds.lean new file mode 100644 index 0000000000000000000000000000000000000000..f330e594c53349a6c8a4055307901a00c284792e --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryOdds.lean @@ -0,0 +1,76 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.SelectedPrimeOdds +import OAI.NumberTheory.JointDickman.Counting.CoefficientWeights + +namespace OAI + +/-! # Bounded odds corrections at the manuscript's auxiliary scale -/ + +namespace JointDickman + +open Filter Finset +open scoped Topology + +theorem coefficientScale_mul_sqrt_ratio {B : ℕ} (hB : 1 < B) : + coefficientScale B * auxiliaryRatio B ^ (1 / 2 : ℝ) = B := by + unfold coefficientScale + rw [mul_assoc, ← Real.rpow_add (auxiliaryRatio_pos hB)] + norm_num only [show (1 / 2 : ℝ) + 1 / 2 = 1 by norm_num, Real.rpow_one] + rw [mul_comm, auxiliaryRatio_mul_log hB] + +theorem primeNormalizer_coefficientScale_bound + (hM : PublishedInputs.PrimeReciprocalMertensInput) : + ∃ C : ℝ, 0 < C ∧ ∀ᶠ B : ℕ in atTop, + primeNormalizer (auxiliaryPrimes B) (1 / 2) ≤ C * coefficientScale B / B := by + let C : ℝ := (4 : ℝ) ^ (-(1 / 2 : ℝ)) + 1 + have hC : 0 < C := by unfold C; positivity + refine ⟨C, hC, ?_⟩ + have ht := auxiliary_primeNormalizer_tendsto hM (z := 1 / 2) (by norm_num) (by norm_num) + filter_upwards [ht.eventually (Iio_mem_nhds (show (4 : ℝ) ^ (-(1 / 2 : ℝ)) < C by + dsimp [C]; linarith)), eventually_gt_atTop 1] with B hQ hB + have hB0 : (0 : ℝ) < B := by exact_mod_cast (Nat.zero_lt_of_lt hB) + apply (le_div_iff₀ hB0).mpr + calc + _ = (primeNormalizer (auxiliaryPrimes B) (1 / 2) * auxiliaryRatio B ^ (1 / 2 : ℝ)) * + coefficientScale B := by rw [mul_right_comm, mul_assoc, coefficientScale_mul_sqrt_ratio hB] + _ ≤ C * coefficientScale B := + mul_le_mul_of_nonneg_right hQ.le (coefficientScale_nonneg B) + +theorem auxiliary_selected_odds_bound : + ∀ᶠ B : ℕ in atTop, ∀ S : Finset ℕ, S ⊆ auxiliaryPrimes B → + (∏ p ∈ S, p : ℕ) ≤ Real.exp ((16 / 5 : ℝ) * B) → + (∏ p ∈ S, (1 - (1 / 2 : ℝ) / p)⁻¹) ≤ Real.exp 1 := by + have ht : Tendsto (fun B : ℕ => (32 / (5 * Real.log 2)) * + ((B : ℝ) / (auxiliaryCutoff B : ℝ))) atTop (𝓝 0) := by + have hp := ((polynomial_div_primeCutoff_tendsto_zero (k := 1) (by norm_num)).comp + tendsto_natCast_atTop_atTop).const_mul (32 / (5 * Real.log 2)) + simpa only [Function.comp_def, auxiliaryCutoff, Nat.cast_pow, pow_one, mul_zero] using hp + filter_upwards [ht.eventually (Iio_mem_nhds (by norm_num : (0 : ℝ) < 1)), + eventually_gt_atTop 1] with B hsmall hB + intro S hS hn + have hP : (0 : ℝ) < auxiliaryCutoff B := by + exact_mod_cast (pow_pos (Nat.zero_lt_of_lt hB) 1000) + have hprime : ∀ p ∈ S, p.Prime := by + intro p hp + exact (Nat.mem_primesLE.mp (mem_filter.mp (hS hp)).1).2 + have hcut : ∀ p ∈ S, (auxiliaryCutoff B : ℝ) ≤ p := by + intro p hp + exact (mem_filter.mp (hS hp)).2.le + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + have hcard : (S.card : ℝ) ≤ (16 / 5 : ℝ) * B / Real.log 2 := by + apply (le_div_iff₀ hlog2).mpr + refine (selectedPrime_card_log_bound S hprime).trans ?_ + have hn0 : (0 : ℝ) < (∏ p ∈ S, p : ℕ) := by + exact_mod_cast prod_pos (fun p hp => (hprime p hp).pos) + simpa only [Real.log_exp] using Real.log_le_log hn0 hn + apply (inverseSelectedPrimeOdds_le hP (by norm_num) (by norm_num) S hprime hcut).trans + apply Real.exp_le_exp.mpr + calc + 2 * (S.card : ℝ) / auxiliaryCutoff B ≤ + 2 * ((16 / 5 : ℝ) * B / Real.log 2) / auxiliaryCutoff B := by + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hcard (by norm_num)) hP.le + _ = (32 / (5 * Real.log 2)) * ((B : ℝ) / (auxiliaryCutoff B : ℝ)) := by ring + _ ≤ 1 := hsmall.le + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryPowerDensity.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryPowerDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..e880a4be19c3b4fcf0fdeb5628c289bc7f9a98f4 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryPowerDensity.lean @@ -0,0 +1,56 @@ +import OAI.NumberTheory.JointDickman.Amplification.AuxiliaryBandDensity + +namespace OAI + +/-! # A power-scale auxiliary band's finite-sieve error vanishes -/ +namespace JointDickman +open Finset Filter TwoPointCorrelations +open scoped Classical Topology + +lemma auxiliary_power_boundary_tendsto {β : ℝ} (r : ℕ) + (hβ : β*(4*r:ℕ)<1) : + Tendsto (fun X : ℝ => ((2*r+1:ℕ):ℝ)*2^(2*r)*(X^β)^(4*r)/X) + atTop (𝓝 0) := by + have hpow := tendsto_rpow_neg_atTop (show 0 < 1-β*(4*r:ℕ) by linarith) + have hh := hpow.const_mul (((2*r+1:ℕ):ℝ)*2^(2*r)) + simp only [mul_zero] at hh + apply hh.congr' + filter_upwards [eventually_gt_atTop (0:ℝ)] with X hX + rw [← Real.rpow_mul_natCast hX.le, + show -(1-β*(4*r:ℕ))=β*(4*r:ℕ)-1 by ring,Real.rpow_sub_one hX.ne'] + ring + +theorem auxiliary_power_missing : ∃ C M : ℝ, 0 < C ∧ 0 ≤ M ∧ + ∀ R β : ℝ, 1 ≤ R → 0 < β → ∀ r : ℕ, β*(4*r:ℕ)<1 → + ∀ ε : ℝ, 0 < ε → ∀ᶠ X : ℝ in atTop, + ∀ (A N : ℕ) [NeZero N], X ≤ (N:ℝ) → + (uniformFiniteLaw (Fin N)).probability + (fun j => mrtPrimeAvoids (mrtPrimeBand (X^(β/R)) (X^β)) (A+j.val)) ≤ + C/R+Real.exp (2*(Real.log R+M))/(2:ℝ)^(2*r+1)+ε := by + obtain ⟨C,M,hC,hM,hbound⟩ := auxiliary_band_missing_bound + refine ⟨C,M,hC,hM,?_⟩ + intro R β hR hβ r hsmall ε hε + have hR0 : 0 < R := by linarith + have hleft := tendsto_rpow_atTop (div_pos hβ hR0) + filter_upwards [hleft.eventually (eventually_ge_atTop 2),eventually_gt_atTop (1:ℝ), + (auxiliary_power_boundary_tendsto r hsmall).eventually (eventually_lt_nhds hε)] with + X hP hX herr + intro A N _ hXN + have hN0 : (0:ℝ) nlinarith + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryScale.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..36ef26c59681d835a578040dda8002653962fc50 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AuxiliaryScale.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.JointDickman.Arithmetic.PrimeNormalizer +import OAI.NumberTheory.JointDickman.Amplification.ParameterEstimates + +namespace OAI + +/-! +# The manuscript's auxiliary prime scale + +The lower cutoff is `B^1000`, the upper cutoff is `exp (4 B)`, and +`R = B / log (B^1000)`. The normalizing constant below is derived from +the published reciprocal-prime Mertens estimate. +-/ + +namespace JointDickman + +open Filter Asymptotics +open scoped Topology + +def auxiliaryCutoff (B : ℕ) : ℕ := B ^ 1000 + +noncomputable def auxiliaryUpper (B : ℕ) : ℝ := Real.exp (4 * (B : ℝ)) + +noncomputable def auxiliaryRatio (B : ℕ) : ℝ := + (B : ℝ) / (1000 * Real.log B) + +noncomputable def auxiliaryPrimes (B : ℕ) : Finset ℕ := + largePrimeSet (auxiliaryUpper B) (auxiliaryCutoff B) + +theorem auxiliaryCutoff_tendsto : Tendsto auxiliaryCutoff atTop atTop := + tendsto_pow_atTop (by norm_num : (1000 : ℕ) ≠ 0) + +theorem auxiliaryUpper_tendsto : Tendsto auxiliaryUpper atTop atTop := + Real.tendsto_exp_atTop.comp + (tendsto_natCast_atTop_atTop.const_mul_atTop (by norm_num : (0 : ℝ) < 4)) + +theorem auxiliaryCutoff_le_upper : + ∀ᶠ B in atTop, (auxiliaryCutoff B : ℝ) ≤ auxiliaryUpper B := by + have h := (isLittleO_pow_exp_pos_mul_atTop 1000 (by norm_num : (0 : ℝ) < 4)).def + (by norm_num : (0 : ℝ) < 1) + filter_upwards [tendsto_natCast_atTop_atTop.eventually h] with B hB + have hpow : (0 : ℝ) ≤ (B : ℝ) ^ 1000 := pow_nonneg (Nat.cast_nonneg B) _ + simpa only [Real.norm_eq_abs, abs_of_nonneg hpow, + abs_of_pos (Real.exp_pos _), one_mul, auxiliaryCutoff, auxiliaryUpper, + Nat.cast_pow] using hB + +theorem auxiliaryRatio_pos {B : ℕ} (hB : 1 < B) : 0 < auxiliaryRatio B := by + have hBreal : (1 : ℝ) < B := by exact_mod_cast hB + exact div_pos (by linarith) (mul_pos (by norm_num) (Real.log_pos hBreal)) + +theorem auxiliaryRatio_tendsto : Tendsto auxiliaryRatio atTop atTop := by + have hlim : Tendsto (fun B : ℕ => 1000 * (Real.log B / (B : ℝ))) + atTop (𝓝 0) := by + simpa using (Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp + tendsto_natCast_atTop_atTop).const_mul 1000 + have hpos : ∀ᶠ B : ℕ in atTop, 0 < 1000 * (Real.log B / (B : ℝ)) := by + filter_upwards [eventually_gt_atTop 1] with B hB + have hBreal : (1 : ℝ) < B := by exact_mod_cast hB + exact mul_pos (by norm_num) (div_pos (Real.log_pos hBreal) (by linarith)) + have hgt : Tendsto (fun B : ℕ => 1000 * (Real.log B / (B : ℝ))) + atTop (𝓝[>] 0) := tendsto_nhdsWithin_iff.mpr ⟨hlim, hpos⟩ + convert hgt.inv_tendsto_nhdsGT_zero using 1 + ext B + simp only [auxiliaryRatio, Pi.inv_apply, mul_inv_rev, inv_div] + ring + +theorem auxiliary_log_ratio (B : ℕ) : + Real.log (auxiliaryUpper B) / Real.log (auxiliaryCutoff B) = + 4 * auxiliaryRatio B := by + simp only [auxiliaryUpper, Real.log_exp, auxiliaryCutoff, Nat.cast_pow, + Real.log_pow, auxiliaryRatio] + ring + +/-- The paper's `Q_{z,B} ~ (4 R)^{-z}` in normalized-limit form. -/ +theorem auxiliary_primeNormalizer_tendsto + (hM : PublishedInputs.PrimeReciprocalMertensInput) + {z : ℝ} (hz : 0 ≤ z) (hz1 : z ≤ 1) : + Tendsto (fun B => primeNormalizer (auxiliaryPrimes B) z * + auxiliaryRatio B ^ z) atTop (𝓝 ((4 : ℝ) ^ (-z))) := by + have h := primeNormalizer_normalized_tendsto hM auxiliaryCutoff auxiliaryUpper + auxiliaryCutoff_tendsto auxiliaryUpper_tendsto auxiliaryCutoff_le_upper hz hz1 + simp_rw [auxiliary_log_ratio] at h + have hdiv := h.div_const ((4 : ℝ) ^ z) + have heq : (fun B => primeNormalizer (largePrimeSet (auxiliaryUpper B) + (auxiliaryCutoff B)) z * (4 * auxiliaryRatio B) ^ z / (4 : ℝ) ^ z) + =ᶠ[atTop] (fun B => primeNormalizer (auxiliaryPrimes B) z * auxiliaryRatio B ^ z) := by + filter_upwards [eventually_gt_atTop 1] with B hB + rw [Real.mul_rpow (by norm_num : (0 : ℝ) ≤ 4) (auxiliaryRatio_pos hB).le] + change _ = primeNormalizer (largePrimeSet (auxiliaryUpper B) (auxiliaryCutoff B)) z * _ + have hfour : (4 : ℝ) ^ z ≠ 0 := (Real.rpow_pos_of_pos (by norm_num) z).ne' + field_simp + simpa [Real.rpow_neg (by norm_num : (0 : ℝ) ≤ 4)] using hdiv.congr' heq + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AveragedConditionedRoots.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AveragedConditionedRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca2afdb0fca77d198d1d7c9ca991c349fa6d88b2 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AveragedConditionedRoots.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.JointDickman.Probability.SiteConditionedError + +namespace OAI + +/-! # Averaging the conditioned root comparison over the actual candidate lists -/ + +namespace JointDickman +open Finset Filter PublishedInputs +open scoped Topology + +open Classical in +theorem averaged_siteConditionedError {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} + (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T H M : ℕ), 0 < T → + (T : ℝ) ≤ Real.exp B → (M : ℝ) ≤ Real.exp B → M ≤ B^2 → + finiteExpectation (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) + (fun S => siteConditionedError B L T H M τ C (fun i => (S i).val)) ≤ + 212*(B : ℝ)^19/(auxiliaryCutoff B : ℝ)+ + 2*(B : ℝ)^6*(M : ℝ)/(auxiliaryCutoff B : ℝ)+ + 2*((M : ℝ)^3*(B : ℝ)^2/((T : ℝ)*Real.exp B)) := by + filter_upwards [siteConditionedError_pointwise hL hτ hτsmall, + repeatedCandidateRoot_probability hL hτ hτsmall,eventually_ge_atTop 2] + with B hpoint hrepeat hB + intro C T H M hT hTexp hMexp hM + let w := siteProductMass (fun _ : Fin M => independentPrimeSetMass B) + have hw : ∀ S, 0 ≤ w S := siteProductMass_nonneg _ (fun _ => independentPrimeSetMass_nonneg B) + have hwone : ∑ S, w S = 1 := siteProductMass_sum _ (fun _ => independentPrimeSetMass_sum B) + have hind : finiteExpectation w (fun S => + if RepeatedCandidateRoot B L T H M τ C (fun i => (S i).val) then 2 else 0) = + 2*finiteProbability w (fun S => RepeatedCandidateRoot B L T H M τ C (fun i => (S i).val)) := by + unfold finiteExpectation finiteProbability + dsimp only + rw [mul_sum] + apply sum_congr rfl + intro S _ + by_cases h : RepeatedCandidateRoot B L T H M τ C (fun i => (S i).val) <;> simp [h,mul_comm] + have hs : (∑ p ∈ auxiliaryPrimes B, 1/(p : ℝ)^2) ≤ 1/(auxiliaryCutoff B : ℝ) := + sum_reciprocal_square_tail _ (pow_ne_zero _ (by omega)) + (fun p hp => by exact_mod_cast (mem_filter.mp hp).2) + have hoc : finiteExpectation w (fun S => occupiedPrimeReciprocalMass B (fun i => (S i).val)) ≤ + (M : ℝ)/(auxiliaryCutoff B : ℝ) := + (independent_occupied_prime_mass B M).trans (by + simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hs (Nat.cast_nonneg M)) + calc + _ ≤ finiteExpectation w (fun S => + 212*(B : ℝ)^19/(auxiliaryCutoff B : ℝ)+ + 2*(B : ℝ)^6*occupiedPrimeReciprocalMass B (fun i => (S i).val)+ + if RepeatedCandidateRoot B L T H M τ C (fun i => (S i).val) then 2 else 0) := + finiteExpectation_mono w hw (fun S => hpoint C T H M _ hTexp hMexp hM) + _ = 212*(B : ℝ)^19/(auxiliaryCutoff B : ℝ)+ + 2*(B : ℝ)^6*finiteExpectation w (fun S => occupiedPrimeReciprocalMass B (fun i => (S i).val))+ + 2*finiteProbability w (fun S => RepeatedCandidateRoot B L T H M τ C (fun i => (S i).val)) := by + rw [finiteExpectation_add,finiteExpectation_add,finiteExpectation_const w hwone, + finiteExpectation_const_mul,hind] + _ ≤ _ := by + have ha := mul_le_mul_of_nonneg_left hoc (show 0 ≤ 2*(B : ℝ)^6 by positivity) + have hb := mul_le_mul_of_nonneg_left (hrepeat C T H M hT) (show (0 : ℝ) ≤ 2 by norm_num) + convert add_le_add (add_le_add le_rfl ha) hb using 1 + ring + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/AveragedRootFluctuation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/AveragedRootFluctuation.lean new file mode 100644 index 0000000000000000000000000000000000000000..384c7965b5bcd8f8f3d7fe15602dc246c0f990aa --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/AveragedRootFluctuation.lean @@ -0,0 +1,84 @@ +import OAI.NumberTheory.JointDickman.Amplification.CandidateForwardMass + +namespace OAI + +/-! # The independent-root fluctuation vanishes after averaging endpoint types -/ + +namespace JointDickman +open Finset Filter PublishedInputs +open scoped Topology + +/-- The actual endpoint-dependent candidate list has bounded expected +weight per block position. -/ +theorem candidateMean_total_mean + (hFord : FordUpperSieveInput) (hM : PrimeReciprocalMertensInput) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ B : ℕ in atTop, ∀ (L T H M : ℕ) (τ C : ℝ), + 0 < T → (T : ℝ) ≤ Real.exp ((1/10 : ℝ)*B) → + ∀ χ : BlockCandidateIndex M → ℝ, (∀ e, χ e ≤ 1) → + finiteExpectation (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) + (fun S => ∑ e : blockCandidates B L T H M τ C (fun i => (S i).val), + candidateMeanWeight B L τ C (fun i => (S i).val) χ e.val) ≤ K*M := by + obtain ⟨K,hK,hbound⟩ := latentCandidateKernel_forward_total_mean hFord hM + refine ⟨K,hK,?_⟩ + filter_upwards [hbound] with B hbound + intro L T H M τ C hT hTs χ hχ + have he (S : Fin M → (auxiliaryPrimes B).powerset) : + (∑ i : Fin M, ∑ k : Fin M, + if i < k then latentCandidateKernel B L T H M τ C (fun i => (S i).val) χ i k else 0) = + ∑ e : blockCandidates B L T H M τ C (fun i => (S i).val), + candidateMeanWeight B L τ C (fun i => (S i).val) χ e.val := by + exact candidateMatrix_forward_total + (fun e : blockCandidates B L T H M τ C (fun i => (S i).val) => e.val.1.1) + (fun e => e.val.1.2) + (fun e => candidateMeanWeight B L τ C (fun i => (S i).val) χ e.val) + (fun e => (mem_blockCandidates.mp e.property).2.1) + simpa only [he] using hbound L T H M τ C hT hTs χ hχ + +noncomputable def averagedIndependentRootError (B L T H M : ℕ) (τ C : ℝ) + (χ : BlockCandidateIndex M → ℝ) : ℝ := + finiteExpectation (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) (fun S => + finiteExpectation (siteProductMass + (fun _ : blockCandidates B L T H M τ C (fun i => (S i).val) => independentPrimeSetMass B)) + (fun R => kernelCutNorm (fun i k => + independentCandidateKernel B L T H M τ C (fun i => (S i).val) χ R i k- + latentCandidateKernel B L T H M τ C (fun i => (S i).val) χ i k))) + +/-- No dependence on the regularity constant C, or on the endpoint types, +remains in the error coefficient. -/ +theorem averagedIndependentRootError_bound + (hFord : FordUpperSieveInput) (hM : PrimeReciprocalMertensInput) + {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ B : ℕ in atTop, ∀ (C : ℝ) (T H M : ℕ), + 0 < T → (T : ℝ) ≤ Real.exp ((1/10 : ℝ)*B) → 0 < M → + ∀ χ : BlockCandidateIndex M → ℝ, (∀ e, 0 ≤ χ e ∧ χ e ≤ 1) → + averagedIndependentRootError B L T H M τ C χ ≤ + K*(B : ℝ)^(-(7/200 : ℝ)) := by + obtain ⟨K,hK,hmean⟩ := candidateMean_total_mean hFord hM + refine ⟨3*Real.log 2+4*K,by positivity,?_⟩ + filter_upwards [hmean,actual_candidate_root_fluctuation hL hτ hτsmall] with B hmean hfluc + intro C T H M hT hTs hM0 χ hχ + let w := siteProductMass (fun _ : Fin M => independentPrimeSetMass B) + let f := fun S : Fin M → (auxiliaryPrimes B).powerset => + ∑ e : blockCandidates B L T H M τ C (fun i => (S i).val), + candidateMeanWeight B L τ C (fun i => (S i).val) χ e.val + let δ : ℝ := (B : ℝ)^(-(7/200 : ℝ)) + have hw : ∀ S, 0 ≤ w S := siteProductMass_nonneg _ (fun _ => independentPrimeSetMass_nonneg B) + have hwone : (∑ S, w S) = 1 := siteProductMass_sum _ (fun _ => independentPrimeSetMass_sum B) + have hMr : (0 : ℝ) < M := by exact_mod_cast hM0 + have hm : finiteExpectation w f/(M : ℝ) ≤ K := by + exact (div_le_iff₀ hMr).mpr (hmean L T H M τ C hT hTs χ (fun e => (hχ e).2)) + calc + _ ≤ finiteExpectation w (fun S => δ*(3*Real.log 2+4*f S/(M : ℝ))) := + finiteExpectation_mono w hw (fun S => hfluc C T H M hM0 (fun i => (S i).val) χ hχ) + _ = δ*(3*Real.log 2+4*finiteExpectation w f/(M : ℝ)) := by + simp only [div_eq_mul_inv,finiteExpectation_const_mul,finiteExpectation_add, + finiteExpectation_mul_const,finiteExpectation_const w hwone] + _ ≤ δ*(3*Real.log 2+4*K) := by + apply mul_le_mul_of_nonneg_left _ (Real.rpow_nonneg (Nat.cast_nonneg B) _) + rw [mul_div_assoc] + exact add_le_add le_rfl (mul_le_mul_of_nonneg_left hm (show (0 : ℝ) ≤ 4 by norm_num)) + _ = _ := mul_comm _ _ + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BaseCandidateMass.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BaseCandidateMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..e50fe0087bf63c54cdbffc8e2de0b69508d2ef99 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BaseCandidateMass.lean @@ -0,0 +1,109 @@ +import OAI.NumberTheory.JointDickman.Amplification.FiniteRampMean +import OAI.NumberTheory.JointDickman.Amplification.ArithmeticPatternMeans +import OAI.NumberTheory.JointDickman.Amplification.CandidateExpectedDegree + +namespace OAI + +/-! # The mean candidate mass that controls the counting-cutoff error -/ +namespace JointDickman +open Finset Filter Classical PublishedInputs +open scoped Topology + +theorem baseCandidateContribution_sum (B L T H M u : ℕ) (τ C : ℝ) : + (∑ e ∈ primeCandidatePool B M, baseCandidateContribution B L T H M τ C e u) = + (∑ i, ∑ k, latentCandidateKernel B L T H M τ C + (fun j => coefficientPrimeSet B (u+(j.val+1))) (smoothCandidateCutoff B T) i k)/2 := by + let S := fun j : Fin M => coefficientPrimeSet B (u+(j.val+1)) + have hs : (∑ e ∈ primeCandidatePool B M, baseCandidateContribution B L T H M τ C e u) = + ∑ e ∈ blockCandidates B L T H M τ C S, + candidateMeanWeight B L τ C S (smoothCandidateCutoff B T) e := by + symm + calc + _ = ∑ e ∈ blockCandidates B L T H M τ C S, + baseCandidateContribution B L T H M τ C e u := by + apply sum_congr rfl + intro e he + dsimp only [S] at he ⊢ + simp only [baseCandidateContribution,he,ite_true] + _ = _ := by + apply sum_subset (blockCandidates_subset_primePool (fun _ => filter_subset _ _)) + intro e _ he + change e ∉ blockCandidates B L T H M τ C S at he + dsimp only [S] at he + simp only [baseCandidateContribution,he,ite_false] + rw [hs] + have ht := candidateMatrix_total + (fun e : blockCandidates B L T H M τ C S => e.val.1.1) + (fun e => e.val.1.2) + (fun e => candidateMeanWeight B L τ C S (smoothCandidateCutoff B T) e.val) + change (∑ e ∈ blockCandidates B L T H M τ C S, + candidateMeanWeight B L τ C S (smoothCandidateCutoff B T) e) = _ + rw [sum_coe_sort (blockCandidates B L T H M τ C S) + (fun e => candidateMeanWeight B L τ C S (smoothCandidateCutoff B T) e)] at ht + change (∑ i, ∑ k, latentCandidateKernel B L T H M τ C S (smoothCandidateCutoff B T) i k) = _ at ht + rw [ht] + ring + +theorem baseCandidateMassMean_eq (B L T H M : ℕ) (τ C : ℝ) : + baseCandidateMassMean B L T H M τ C = + arithmeticSquareMean B (fun u => (∑ i, ∑ k, + latentCandidateKernel B L T H M τ C + (fun j => coefficientPrimeSet B (u+(j.val+1))) (smoothCandidateCutoff B T) i k)/2) := by + unfold baseCandidateMassMean + rw [← sum_div,sum_comm] + simp_rw [residueBaseContribution,baseCandidateContribution_sum] + have hs := residue_sum_eq_range (q := auxiliarySquarePeriod B) (fun r => + (((∑ i, ∑ k, latentCandidateKernel B L T H M τ C + (fun j => coefficientPrimeSet B (r.val+(j.val+1))) (smoothCandidateCutoff B T) i k)/2 : ℝ) : ℂ)) + have hs' : (∑ r : ZMod (auxiliarySquarePeriod B), (∑ i, ∑ k, + latentCandidateKernel B L T H M τ C + (fun j => coefficientPrimeSet B (r.val+(j.val+1))) (smoothCandidateCutoff B T) i k)/2) = + ∑ u ∈ range (auxiliarySquarePeriod B), (∑ i, ∑ k, + latentCandidateKernel B L T H M τ C + (fun j => coefficientPrimeSet B (u+(j.val+1))) (smoothCandidateCutoff B T) i k)/2 := by + simp only [ZMod.val_natCast] at hs + have hp (u : ℕ) : (fun j : Fin M => coefficientPrimeSet B + (u % auxiliarySquarePeriod B+(j.val+1))) = + (fun j => coefficientPrimeSet B (u+(j.val+1))) := + blockPrimeSites_modEq (Nat.mod_modEq u _) + simp only [hp] at hs + exact_mod_cast hs + rw [hs'] + simp only [arithmeticSquareMean,auxiliarySquarePeriod,Nat.cast_prod,Nat.cast_pow,← prod_pow] + +theorem latentCandidateKernel_mean_total_le {B L T H M : ℕ} {τ C K : ℝ} + (χ : BlockCandidateIndex M → ℝ) + (hrow : ∀ (i : Fin M) (a : (auxiliaryPrimes B).powerset), + (∑ k : Fin M, finiteExpectation (independentPrimeSetMass B) + (fun R => candidateSiteKernel B L T H M τ C χ i k a.val R.val)) ≤ K) : + finiteExpectation (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) + (fun S => ∑ i, ∑ k, latentCandidateKernel B L T H M τ C (fun j => (S j).val) χ i k) ≤ + (M : ℝ)*K := by + let p := fun _ : Fin M => independentPrimeSetMass B + have hp : ∀ i, ∑ a, p i a = 1 := fun _ => independentPrimeSetMass_sum B + simp_rw [← latentPrimeSiteKernel_realizes,realizedSiteKernel] + rw [finiteExpectation_sum] + calc + _ ≤ ∑ _i : Fin M, K := by + apply sum_le_sum + intro i _ + rw [finiteExpectation_sum] + change (∑ k : Fin M, finiteExpectation (siteProductMass p) + (fun S => latentPrimeSiteKernel B L T H M τ C χ i k (S i) (S k))) ≤ K + have he (k : Fin M) : finiteExpectation (siteProductMass p) + (fun S => latentPrimeSiteKernel B L T H M τ C χ i k (S i) (S k)) = + finiteExpectation (p i) (fun a => finiteExpectation (p k) + (fun b => latentPrimeSiteKernel B L T H M τ C χ i k a b)) := by + by_cases hik : i = k + · subst k + simp only [latentPrimeSiteKernel,candidateSiteKernel_diag,finiteExpectation,mul_zero,sum_const_zero] + · exact siteProduct_expectation_two p hp hik _ + simp_rw [he] + rw [← finiteExpectation_sum] + exact (finiteExpectation_mono (p i) (independentPrimeSetMass_nonneg B) (hrow i)).trans_eq + (finiteExpectation_const (p i) (hp i) K) + _ = _ := by simp + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BaseCandidateMassBound.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BaseCandidateMassBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..e7fd9dfe80972ff96e80ef60d9263b257981773a --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BaseCandidateMassBound.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.JointDickman.Amplification.BaseCandidateMass + +namespace OAI + +/-! # A uniform bound on the mean mass in the counting-cutoff error -/ +namespace JointDickman +open Finset Filter Classical PublishedInputs +open scoped Topology + +theorem baseCandidateMassMean_bound + (hFord : PublishedInputs.FordUpperSieveInput) + (hMertens : PublishedInputs.PrimeReciprocalMertensInput) + {L : ℕ} (hL : 1 ≤ L) {τ : ℝ} (hτ : 0 ≤ τ) (hτsmall : τ ≤ samplingTau) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ B : ℕ in atTop, ∀ (T H M : ℕ) (C : ℝ), + 0 < T → (T : ℝ) ≤ Real.exp ((1/10 : ℝ)*B) → 0 < M → M ≤ B^2 → + baseCandidateMassMean B L T H M τ C ≤ K*(M : ℝ) := by + obtain ⟨K,hK,hrow⟩ := candidateSiteKernel_expected_degree hFord hMertens + refine ⟨K+4,by positivity,?_⟩ + filter_upwards [hrow,candidate_kernels_polynomial_mass hL hτ hτsmall,eventually_ge_atTop 2] + with B hrow hmass hB + intro T H M C hT hTs hM hM2 + let χ : BlockCandidateIndex M → ℝ := smoothCandidateCutoff B T + have hχ : ∀ e, 0 ≤ χ e ∧ χ e ≤ 1 := by + intro e + refine ⟨smoothCandidateCutoff_nonneg B T e,?_⟩ + change amplificationBump _*amplificationBump _*amplificationBump _ ≤ 1 + exact (mul_le_mul + (mul_le_mul (amplificationBump_bounds _).2 (amplificationBump_bounds _).2 + (amplificationBump_bounds _).1 (by norm_num)) + (amplificationBump_bounds _).2 (amplificationBump_bounds _).1 (by norm_num)).trans_eq + (by norm_num) + let F (S : BlockPrimePatterns B M) : ℝ := + ∑ i, ∑ k, latentCandidateKernel B L T H M τ C (primePatternsSites S) χ i k + have hB1 : (1 : ℝ) ≤ B := by exact_mod_cast (show 1 ≤ B by omega) + have hF : ∀ S, |F S| ≤ 2*(B : ℝ)^10 := by + intro S + calc + _ ≤ ∑ i : Fin M, ∑ k : Fin M, + |latentCandidateKernel B L T H M τ C (primePatternsSites S) χ i k| := + (abs_sum_le_sum_abs _ _).trans + (sum_le_sum (fun _ _ => abs_sum_le_sum_abs _ _)) + _ ≤ 2*(M : ℝ)^2*(B : ℝ)^2 := (hmass C T H M (primePatternsSites S) χ hχ).1 + _ ≤ 2*((B : ℝ)^2)^2*(B : ℝ)^2 := by + gcongr + exact_mod_cast hM2 + _ = 2*(B : ℝ)^6 := by ring + _ ≤ 2*(B : ℝ)^10 := mul_le_mul_of_nonneg_left + (pow_le_pow_right₀ hB1 (by norm_num : 6 ≤ 10)) (by norm_num) + have hsize : ∀ p ∈ auxiliaryPrimes B, M < p := + fun p hp => (block_prime_twice_sites hB hM2 hp).1 + have hc := arithmeticSquareMean_pattern_comparison (by omega : 1 < B) hM2 hsize + F (by norm_num : (0 : ℝ) ≤ 2) hF + have he : finiteExpectation (siteProductMass (fun _ : Fin M => independentPrimeSetMass B)) + (fun S => F ((blockPatternEquiv B M).symm S)) ≤ (M : ℝ)*K := by + have hv (S : Fin M → (auxiliaryPrimes B).powerset) : + primePatternsSites ((blockPatternEquiv B M).symm S) = (fun j => (S j).val) := by + funext j + rw [← blockPatternEquiv_val,Equiv.apply_symm_apply] + simp_rw [F,hv] + exact latentCandidateKernel_mean_total_le χ (fun i a => + hrow L T H M τ C hT hTs χ (fun e => (hχ e).2) i a.val (mem_powerset.mp a.property)) + have ha : arithmeticSquareMean B (fun u => F (arithmeticPrimePatterns B M u)) ≤ + (M : ℝ)*K+4/(B : ℝ) := by + have hh := (le_abs_self _).trans hc + linarith + have hb : baseCandidateMassMean B L T H M τ C = + arithmeticSquareMean B (fun u => F (arithmeticPrimePatterns B M u))/2 := by + rw [baseCandidateMassMean_eq] + have hv (u : ℕ) : primePatternsSites (arithmeticPrimePatterns B M u) = + (fun j => coefficientPrimeSet B (u+(j.val+1))) := + funext (primePatternsSites_arithmetic B M u) + simp only [F,hv,χ,arithmeticSquareMean,div_eq_mul_inv,mul_sum,mul_comm,mul_left_comm] + rw [hb] + have hMr : (1 : ℝ) ≤ M := by exact_mod_cast hM + have hfrac : 4/(B : ℝ) ≤ 4 := div_le_self (by norm_num) hB1 + nlinarith + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinAuxiliaryCofactor.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinAuxiliaryCofactor.lean new file mode 100644 index 0000000000000000000000000000000000000000..f352e144243cac0de9ee56024310994ca7a977e4 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinAuxiliaryCofactor.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.JointDickman.Amplification.AuxiliaryPowerSeparation +import OAI.NumberTheory.JointDickman.Amplification.BinCofactorBound + +namespace OAI + +/-! # Cofactor cancellation in every bin of the actual auxiliary band -/ +namespace JointDickman +open Finset Filter TwoPointCorrelations +open scoped Classical Topology + +theorem bin_auxiliary_cofactor {J : ℕ} (hJ : 0 < J) + (E : Finset ℕ) (hE : ∀ p ∈ E, p.Prime) {A H α β : ℝ} + (hA : 0 < A) (hH : 2 ≤ H) (hα : 0 < α) (hαβ : α ≤ β) + (hαJ : α ≤ (1:ℝ)/J) (hβ : β < 1/12) {ε : ℝ} (hε : 0 < ε) : + ∃ T : ℝ, 0 < T ∧ ∀ᶠ N : ℕ in atTop, + ∀ x : ℝ, (N:ℝ)/A ≤ x → + ∀ ζ : Fin (J-1) → ℂ, (∀ i, ‖ζ i‖ ≤ 1) → + ∀ w : ℕ → ℝ, (∀ p ∈ E, 0 ≤ w p ∧ w p ≤ 1) → + ∀ k ∈ auxiliaryLogBins H α β N, ∀ t : ℝ, T ≤ |t| → |t| ≤ N → + ‖mrtCofactorPolynomial (mrtPrimeBand ((N:ℝ)^α) ((N:ℝ)^β)) + (finiteWeightedCoefficient + (binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ) E w) + N (mrtPrimeLogLower H k) t‖ ≤ ε := by + have hc : 0 < α/4 := by positivity + have hc1 : α/4 ≤ 1 := by linarith + have hroot : 0 < (1:ℝ)/J := by positivity + obtain ⟨T,K,hT,_hK,hbound⟩ := bin_cofactor_away_zero hJ hc hc1 E hE hε + refine ⟨T,hT,?_⟩ + have hdiv : Tendsto (fun N : ℕ => (N:ℝ)/A) atTop atTop := + tendsto_natCast_atTop_atTop.atTop_div_const hA + have hcut := (eventually_scaled_power_lt (show α/4<α by linarith) + (by norm_num : (0:ℝ)<2) (by norm_num : (0:ℝ)<1)).filter_mono tendsto_natCast_atTop_atTop + have hscale := (eventually_scaled_power_lt (show α/4<(1:ℝ)/J by linarith) + (by norm_num : (0:ℝ)<2) hA).filter_mono tendsto_natCast_atTop_atTop + have hfinite : ∀ᶠ N : ℕ in atTop, ∀ p ∈ E, + (p:ℝ) ≤ (N:ℝ)^α ∧ (p:ℝ) ≤ ((N:ℝ)/A)^((1:ℝ)/J) := by + apply (eventually_all_finset E).mpr + intro p _ + exact (((tendsto_rpow_atTop hα).comp tendsto_natCast_atTop_atTop).eventually + (eventually_ge_atTop (p:ℝ))).and + (((tendsto_rpow_atTop hroot).comp hdiv).eventually (eventually_ge_atTop (p:ℝ))) + filter_upwards [hcut,hscale,hfinite,auxiliary_cofactor_floor_scales, + auxiliary_range_scales 1 hα (show β<1 by linarith), + hdiv.eventually (eventually_ge_atTop 1), + ((tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/2)).comp tendsto_natCast_atTop_atTop).eventually + (eventually_ge_atTop (K:ℝ)),eventually_ge_atTop (1:ℕ)] with + N hcut hscale hfinite hfloor hrange hdiv1 hKroot hN + intro x hx ζ hζ w hw k hk t htlo hthi + have hn : (0:ℝ) (hfinite p hp).2.trans hrootx) ζ hζ _ ?_ ?_ w hw t htlo (hthi.trans hnorm) + · intro p hp + have hb := mrtPrimeBand_bounds (Real.rpow_nonneg hn.le α) (Real.rpow_nonneg hn.le β) hp + refine ⟨mrtPrimeBand_prime hp,?_,?_⟩ + · exact lt_of_le_of_lt hcupper ((show (2*(N:ℝ))^(α/4)<(N:ℝ)^α by simpa using hcut).trans hb.1) + · exact hb.2.trans ((Real.rpow_le_rpow_of_exponent_le hn1 (by linarith : β≤1/2)).trans hm) + · apply disjoint_left.mpr + intro p hpE hpP + have hb := mrtPrimeBand_bounds (Real.rpow_nonneg hn.le α) (Real.rpow_nonneg hn.le β) hpP + exact (not_lt_of_ge (hfinite p hpE).1) hb.1 + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinAwaySpectral.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinAwaySpectral.lean new file mode 100644 index 0000000000000000000000000000000000000000..2495d5df7c19d16e655c3638769cd9d8e29eba26 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinAwaySpectral.lean @@ -0,0 +1,60 @@ +import OAI.NumberTheory.JointDickman.Counting.CanonicalAffineEnergy +import OAI.NumberTheory.JointDickman.Counting.BinExceptionalEnergy + +namespace OAI + +/-! # Affine energy away from zero for the actual weighted bin labels -/ +namespace JointDickman +open Finset Filter MeasureTheory TwoPointCorrelations +open scoped Classical Topology + +theorem bin_away_spectral {J : ℕ} (hJ : 0 < J) + : ∃ C : ℝ, 0 < C ∧ ∀ᶠ H : ℝ in atTop, + ∀ (E : Finset ℕ), (∀ p ∈ E, p.Prime) → ∀ A : ℝ, 0 < A → + ∃ T₀ : ℝ, 0 < T₀ ∧ + ∀ᶠ N : ℕ in atTop, ∀ x : ℝ, (N:ℝ)/A ≤ x → + ∀ ζ : Fin (J-1) → ℂ, (∀ i, ‖ζ i‖ ≤ 1) → + ∀ w : ℕ → ℝ, (∀ p ∈ E, 0 ≤ w p ∧ w p ≤ 1) → + ∀ S : Set ℝ, MeasurableSet S → ∀ T : ℝ, 0 < T → T ≤ N → + S ⊆ Set.Ioc (-T) T → (∀ t ∈ S, T₀ ≤ |t|) → + (∫ t in S, ‖angularMellinPolynomial (Ioc N (2*N)) + (finiteWeightedCoefficient + (binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ) E w) t‖^2) ≤ + 4/H+canonicalAffineBase C H+canonicalAffineSlope C H*T/N := by + obtain ⟨C,hC,hcanonical⟩ := canonical_affine_energy + refine ⟨C,hC,?_⟩ + filter_upwards [hcanonical,eventually_mellin_application_scales, + eventually_gt_atTop (0:ℝ)] with H hcan hscale hH + obtain ⟨hP,hPQ,hlogP,hQ,hbudget,hR⟩ := hscale + intro E hE A hA + obtain ⟨T₀,hT₀,hex⟩ := bin_exceptional_energy (mellinFirstPrime H) (mellinLastPrime H) + hP hPQ (by linarith) hQ hR hJ E hE hA (by positivity : 0<(1:ℝ)/H) + refine ⟨T₀,hT₀,?_⟩ + filter_upwards [hcan hQ,hex] with N hcan hex + dsimp only at hcan hex + intro x hx ζ hζ w hw S hSm T hT hTN hS hST + let F := finiteWeightedCoefficient + (binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ) E w + let B := canonicalMellinBands (mellinFirstPrime H) (mellinLastPrime H) (1/12) + let L := mellinBandCount (mellinLastPrime H) (Real.sqrt (Real.log (N:ℝ))) hQ + let R := S ∩ mrtNoSmallBand B.bins (B.polynomial F) B.threshold L + have hRm : MeasurableSet R := hSm.inter + (mrt_no_small_band_measurable _ _ _ (B.polynomial_continuous F) L) + have hRN : R ⊆ Set.Ioc (-(N:ℝ)) N := by + intro t ht + have hh := hS ht.1 + exact ⟨by linarith [hh.1],hh.2.trans hTN⟩ + have he := hex x hx ζ hζ w hw R hRm hRN Set.inter_subset_right + (fun t ht => hST t ht.1) + have hm := finiteWeightedCoefficient_multiplicative + (binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ) + (binLabel_isMultiplicative _ _) hE w + have hn : ∀ n, ‖F n‖ ≤ 1 := finiteWeightedCoefficient_norm _ + (norm_binLabel_le_one_of_norm_le _ ζ hζ) hw + have hc := hcan F (fun _ _ _ _ hcop => hm.2 hcop) hn S T hSm hT hS + dsimp only [R,B,L] at he + linear_combination hc + 4*he + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinCofactorBound.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCofactorBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..833443050d12437dbd6071690df3cfdd2d06fc4d --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCofactorBound.lean @@ -0,0 +1,77 @@ +import OAI.NumberTheory.JointDickman.Amplification.FiniteWeightCofactorComplete +import OAI.NumberTheory.JointDickman.Amplification.BinLowFrequency + +namespace OAI + +/-! # Cofactor cancellation for the actual finite-prime weighted bin labels -/ +namespace JointDickman +open Finset Filter TwoPointCorrelations +open scoped Classical Topology + +lemma bin_prime_above_first_root {J : ℕ} (hJ : 0 < J) {x : ℝ} (hx : 1 ≤ x) + (i : Fin (J-1)) {p : ℕ} (hp : p ∈ primeBin x J (i.val+1)) : + p.Prime ∧ x^((1:ℝ)/J) < (p:ℝ) := by + have hh := (mem_primeBin_iff (by linarith : 0 ≤ x) J (i.val+1) p).mp hp + refine ⟨hh.1,lt_of_le_of_lt ?_ hh.2.1⟩ + apply Real.rpow_le_rpow_of_exponent_le hx + have hJr : (0:ℝ) ≤ J := by exact_mod_cast hJ.le + apply div_le_div_of_nonneg_right _ hJr + push_cast + linarith [show (0:ℝ) ≤ i.val by positivity] + +lemma binLabel_small_prime_power {J : ℕ} (hJ : 0 < J) {x : ℝ} (hx : 1 ≤ x) + (ζ : Fin (J-1) → ℂ) {p : ℕ} (hp : p.Prime) + (hpx : (p:ℝ) ≤ x^((1:ℝ)/J)) (k : ℕ) : + binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ (p^k) = 1 := by + apply binLabel_eq_one_of_no_factor _ _ (pow_ne_zero _ hp.ne_zero) + intro i q hq hqp + obtain ⟨hqprime,hqx⟩ := bin_prime_above_first_root hJ hx i hq + have heq : q=p := ((Nat.dvd_prime hp).mp (hqprime.dvd_of_dvd_pow hqp)).resolve_left hqprime.ne_one + subst q + linarith + +lemma binLabel_fixed_product_invariant {J : ℕ} (hJ : 0 < J) {x : ℝ} (hx : 1 ≤ x) + (ζ : Fin (J-1) → ℂ) (E : Finset ℕ) (hE : ∀ p ∈ E, p.Prime) + (hEx : ∀ p ∈ E, (p:ℝ) ≤ x^((1:ℝ)/J)) : + ∀ D ∈ E.powerset, ∀ n : ℕ, 0 < n → + binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ ((∏ p ∈ D,p)*n) = + binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ n := by + intro D hD n _ + apply binLabel_mul_invariant _ _ + (ne_of_gt (prod_pos (fun p hp => (hE p (mem_powerset.mp hD hp)).pos))) + intro i q hq hqd + obtain ⟨hqprime,hqx⟩ := bin_prime_above_first_root hJ hx i hq + obtain ⟨p,hp,hqp⟩ := (hqprime.prime.dvd_finsetProd_iff id).mp hqd + have heq : q=p := ((Nat.dvd_prime (hE p (mem_powerset.mp hD hp))).mp hqp).resolve_left hqprime.ne_one + have hpx := hEx p (mem_powerset.mp hD hp) + subst q + linarith + +/-- The functions here are exactly the manuscript's bin labels with a fixed +finite-prime weight. Only the explicit prime-scale inequalities remain. -/ +theorem bin_cofactor_away_zero {J : ℕ} (hJ : 0 < J) {c : ℝ} (hc : 0 < c) (hc1 : c ≤ 1) + (E : Finset ℕ) (hE : ∀ p ∈ E, p.Prime) {ε : ℝ} (hε : 0 < ε) : + ∃ T : ℝ, ∃ K : ℕ, 0 < T ∧ 2 ≤ K ∧ + ∀ (N : ℕ) (a x : ℝ), 1 ≤ a → 1 ≤ x → K ≤ ⌊(N:ℝ)/a⌋₊ → + (⌊(2*N:ℝ)/a⌋₊:ℝ)^c ≤ x^((1:ℝ)/J) → + (∀ p ∈ E, (p:ℝ) ≤ x^((1:ℝ)/J)) → + ∀ (ζ : Fin (J-1) → ℂ), (∀ i, ‖ζ i‖ ≤ 1) → + ∀ P : Finset ℕ, (∀ p ∈ P, p.Prime ∧ + (⌊(2*N:ℝ)/a⌋₊:ℝ)^c < (p:ℝ) ∧ (p:ℝ) ≤ (⌊(N:ℝ)/a⌋₊:ℝ)) → + Disjoint E P → ∀ w : ℕ → ℝ, (∀ p ∈ E, 0 ≤ w p ∧ w p ≤ 1) → + ∀ t : ℝ, T ≤ |t| → |t| ≤ (⌊(2*N:ℝ)/a⌋₊:ℝ)^2 → + ‖mrtCofactorPolynomial P + (finiteWeightedCoefficient + (binLabel (fun i : Fin (J-1) => primeBin x J (i.val+1)) ζ) E w) N a t‖ ≤ ε := by + obtain ⟨T,K,hT,hK,hbound⟩ := finite_weight_count_window_away_zero hc hc1 E hE hε + refine ⟨T,K,hT,hK,?_⟩ + intro N a x ha hx hm hcut hEx ζ hζ P hP hdis w hw t htlo hthi + apply hbound N a ha hm _ (binLabel_isMultiplicative _ _) + (norm_binLabel_le_one_of_norm_le _ ζ hζ) ?_ + (binLabel_fixed_product_invariant hJ hx ζ E hE hEx) P hP hdis w hw t htlo hthi + intro p k hp hpc _ + exact binLabel_small_prime_power hJ hx ζ hp (hpc.trans hcut) k + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinCorrelationLimit.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCorrelationLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..531761bcbf1e2ad75bc4abe2eae5d84b3ac70288 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCorrelationLimit.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.JointDickman.Counting.ArithmeticBlockMean +import OAI.NumberTheory.JointDickman.Counting.SubsequencePositiveBlocks + +namespace OAI + +/-! # Every convergent mixed bin-label correlation has zero centered limit -/ +namespace JointDickman +open Finset Filter Classical PublishedInputs +open scoped Topology + +theorem bin_correlation_limit_zero + (hMR : RealShortIntervalInput) (hMRT : ComplexShortIntervalInput) + (hKMT : CharacterDistanceDivergence) (hFord : FordUpperSieveInput) + (hSD : SquarefreeSelbergDelangeInput) (hSW : SquarefreeCharacterEstimateInput) + (hM : PrimeReciprocalMertensInput) (hMP : PrimeProductMertensInput) + (hMC : ∀ B M : ℕ, FiniteMcDiarmidInput (Fin M) (auxiliaryPrimes B).powerset) + {ι : Type*} [Fintype ι] + (J₁ : ℕ) (hJ₁ : 0 < J₁) (k₁ : ι → ℕ) (hk₁ : ∀ i, 1 ≤ k₁ i) + (z₁ : ι → ℂ) (hz₁ : ∀ i, ‖z₁ i‖ = 1) + {J₂ : ℕ} (hJ₂ : 0 < J₂) (z₂ : Fin (J₂-1) → ℂ) (hz₂ : ∀ i, ‖z₂ i‖ = 1) + (μ : ℂ) (hμ : ‖μ‖ ≤ 1) + (hcenter : ∀ D : ℝ, 0 < D → Tendsto (centeredBinPrefix J₂ z₂ μ D) atTop (𝓝 0)) + (r : ℕ → ℕ) (hr : StrictMono r) {β : ℂ} + (hlimit : Tendsto (fun N => (∑ n ∈ range (r N), + star (movingBinLabel J₁ k₁ z₁ (r N) n) * + (movingBinLabel J₂ (fun i : Fin (J₂-1) => i.val+1) z₂ (r N) (n+1)-μ))/(r N : ℂ)) + atTop (𝓝 β)) : β = 0 := by + by_contra hβ + obtain ⟨s,hs,e,A,he,hA,hpositive⟩ := nonzero_binLabel_correlation_along_forces_blocks + hFord hSD hM hMP J₁ hJ₁ k₁ hk₁ z₁ hz₁ J₂ hJ₂ (fun i : Fin (J₂-1) => i.val+1) + (fun _ => by omega) z₂ hz₂ μ hμ r hr hβ hlimit + obtain ⟨τ,hτ,_,hτsmall,hzero⟩ := arithmetic_block_centered_mean hMR hMRT hKMT hFord hSD hSW hM hMP hMC + hJ₂ z₂ hz₂ μ hμ hcenter hA (by norm_num : 10000 ≤ (10000 : ℕ)) (by norm_num : (0 : ℝ) < 1) + obtain ⟨C₀,hC₀,hpos⟩ := hpositive 10000 τ (by norm_num) hτ hτsmall + obtain ⟨C₁,hC₁,hneg⟩ := hzero (e/2) (half_pos he) + have hp := hpos (max C₀ C₁) (le_max_left _ _) + have hn := hneg (max C₀ C₁) (le_max_right _ _) + have hfalse : ∀ᶠ B : ℕ in atTop, False := by + filter_upwards [hp,hn] with B hb hsmall + have hsmall' := (hr.comp hs).tendsto_atTop.eventually hsmall + obtain ⟨N,hN,hNsmall⟩ := (hb.and hsmall').exists + have hh : e ≤ |arithmeticBlockAverage B 10000 τ (max C₀ C₁) (amplificationMultiplier B) + (r (s N)) (amplificationMultiplier B/A) (A*amplificationMultiplier B) + (fun n => movingBinLabel J₂ (fun i : Fin (J₂-1) => i.val+1) z₂ (r (s N)) n-μ)| := + hN.trans (le_abs_self _) + change _ < e/2 at hNsmall + simp only [movingBinLabel,Function.comp_apply] at hh hNsmall + linarith only [hh,hNsmall,he] + exact hfalse.exists.elim (fun _ h => h) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinCorrelationLimitDischarge.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCorrelationLimitDischarge.lean new file mode 100644 index 0000000000000000000000000000000000000000..c30f2f57fc37c2d46bcb4a69a04642dc83a5617c --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCorrelationLimitDischarge.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.JointDickman.Amplification.BinCorrelationLimit +import OAI.NumberTheory.JointDickman.Counting.ArithmeticBlockMeanDischarge + +namespace OAI + +/-! # Application consequences of the proved short-average estimates -/ +namespace JointDickman +open Finset Filter MeasureTheory Classical PublishedInputs +open scoped Topology + +theorem bin_correlation_limit_zero_proved + (hKMT : CharacterDistanceDivergence) (hFord : FordUpperSieveInput) + (hSD : SquarefreeSelbergDelangeInput) (hSW : SquarefreeCharacterEstimateInput) + (hM : PrimeReciprocalMertensInput) (hMP : PrimeProductMertensInput) + (hMC : ∀ B M : ℕ, FiniteMcDiarmidInput (Fin M) (auxiliaryPrimes B).powerset) + {ι : Type*} [Fintype ι] + (J₁ : ℕ) (hJ₁ : 0 < J₁) (k₁ : ι → ℕ) (hk₁ : ∀ i, 1 ≤ k₁ i) + (z₁ : ι → ℂ) (hz₁ : ∀ i, ‖z₁ i‖ = 1) + {J₂ : ℕ} (hJ₂ : 0 < J₂) (z₂ : Fin (J₂-1) → ℂ) (hz₂ : ∀ i, ‖z₂ i‖ = 1) + (μ : ℂ) (hμ : ‖μ‖ ≤ 1) + (hcenter : ∀ D : ℝ, 0 < D → Tendsto (centeredBinPrefix J₂ z₂ μ D) atTop (𝓝 0)) + (r : ℕ → ℕ) (hr : StrictMono r) {β : ℂ} + (hlimit : Tendsto (fun N => (∑ n ∈ range (r N), + star (movingBinLabel J₁ k₁ z₁ (r N) n) * + (movingBinLabel J₂ (fun i : Fin (J₂-1) => i.val+1) z₂ (r N) (n+1)-μ))/(r N : ℂ)) + atTop (𝓝 β)) : β = 0 := by + by_contra hβ + obtain ⟨s,hs,e,A,he,hA,hpositive⟩ := nonzero_binLabel_correlation_along_forces_blocks + hFord hSD hM hMP J₁ hJ₁ k₁ hk₁ z₁ hz₁ J₂ hJ₂ (fun i : Fin (J₂-1) => i.val+1) + (fun _ => by omega) z₂ hz₂ μ hμ r hr hβ hlimit + obtain ⟨τ,hτ,_,hτsmall,hzero⟩ := arithmetic_block_centered_mean_proved hKMT hFord hSD hSW hM hMP hMC + hJ₂ z₂ hz₂ μ hμ hcenter hA (by norm_num : 10000 ≤ (10000 : ℕ)) (by norm_num : (0 : ℝ) < 1) + obtain ⟨C₀,hC₀,hpos⟩ := hpositive 10000 τ (by norm_num) hτ hτsmall + obtain ⟨C₁,hC₁,hneg⟩ := hzero (e/2) (half_pos he) + have hp := hpos (max C₀ C₁) (le_max_left _ _) + have hn := hneg (max C₀ C₁) (le_max_right _ _) + have hfalse : ∀ᶠ B : ℕ in atTop, False := by + filter_upwards [hp,hn] with B hb hsmall + have hsmall' := (hr.comp hs).tendsto_atTop.eventually hsmall + obtain ⟨N,hN,hNsmall⟩ := (hb.and hsmall').exists + have hh : e ≤ |arithmeticBlockAverage B 10000 τ (max C₀ C₁) (amplificationMultiplier B) + (r (s N)) (amplificationMultiplier B/A) (A*amplificationMultiplier B) + (fun n => movingBinLabel J₂ (fun i : Fin (J₂-1) => i.val+1) z₂ (r (s N)) n-μ)| := + hN.trans (le_abs_self _) + change _ < e/2 at hNsmall + simp only [movingBinLabel,Function.comp_apply] at hh hNsmall + linarith only [hh,hNsmall,he] + exact hfalse.exists.elim (fun _ h => h) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinCounts.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..991c7b0ae8e8e1eeca318ccc646f3189a2658464 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinCounts.lean @@ -0,0 +1,183 @@ +import OAI.NumberTheory.JointDickman.Amplification.BinLabels +import OAI.NumberTheory.JointDickman.Basic + +namespace OAI + +/-! +# Bounded multiplicity counts and smoothness at bin endpoints + +A product of the prime powers counted in a bin divides the integer. This +bounds every bin count uniformly on fixed windows `n ≤ C*x`. The endpoint +criterion identifies smoothness with vanishing counts in all higher bins. +-/ + +namespace JointDickman + +open Filter Finset +open scoped Topology + +theorem mem_primeBin_iff {x : ℝ} (hx : 0 ≤ x) (J k p : ℕ) : + p ∈ primeBin x J k ↔ p.Prime ∧ + x ^ ((k : ℝ) / J) < (p : ℝ) ∧ (p : ℝ) ≤ x ^ (((k : ℝ) + 1) / J) := by + classical + simp only [primeBin, Finset.mem_filter, Finset.mem_Ioc] + constructor + · rintro ⟨⟨hl, hu⟩, hp⟩ + exact ⟨hp, Nat.lt_of_floor_lt hl, + (Nat.le_floor_iff (Real.rpow_nonneg hx _)).mp hu⟩ + · rintro ⟨hp, hl, hu⟩ + exact ⟨⟨(Nat.floor_lt (Real.rpow_nonneg hx _)).mpr hl, + (Nat.le_floor_iff (Real.rpow_nonneg hx _)).mpr hu⟩, hp⟩ + +/-- The product of the complete prime powers selected by a finite bin divides `n`. -/ +theorem bin_primePower_prod_dvd (E : Finset ℕ) (n : ℕ) : + (∏ p ∈ E, p ^ n.factorization p) ∣ n := by + classical + let f : ℕ →₀ ℕ := n.factorization.filter (fun p => p ∈ E) + have hf : f ≤ n.factorization := by + intro p + simp only [f, Finsupp.filter_apply] + split_ifs <;> simp + have hsupp : f.support ⊆ E := by + intro p hp + exact (Finset.mem_filter.mp (show p ∈ n.factorization.support.filter (fun p => p ∈ E) from hp)).2 + have heq : f.prod (fun p a => p ^ a) = ∏ p ∈ E, p ^ n.factorization p := by + rw [Finsupp.prod_of_support_subset f hsupp _ (by simp)] + apply Finset.prod_congr rfl + intro p hp + simp only [f, Finsupp.filter_apply, ite_eq_left hp] + rw [← heq] + exact Nat.prod_pow_dvd_of_le_factorization hf + +/-- A lower bound for every counted prime gives a power lower bound for `n`. -/ +theorem binCount_pow_le (E : Finset ℕ) {n : ℕ} (hn : n ≠ 0) + {q : ℝ} (hq : 0 ≤ q) (hE : ∀ p ∈ E, q ≤ (p : ℝ)) : + q ^ binCount E n ≤ (n : ℝ) := by + calc + q ^ binCount E n = ∏ p ∈ E, q ^ n.factorization p := + (Finset.prod_pow_eq_pow_sum E n.factorization q).symm + _ ≤ ∏ p ∈ E, (p : ℝ) ^ n.factorization p := + Finset.prod_le_prod₀ (fun p _ => pow_nonneg hq _) + (fun p hp => pow_le_pow_left₀ hq (hE p hp) _) + _ = ((∏ p ∈ E, p ^ n.factorization p : ℕ) : ℝ) := by norm_cast + _ ≤ n := by exact_mod_cast Nat.le_of_dvd (Nat.pos_of_ne_zero hn) (bin_primePower_prod_dvd E n) + +/-- Uniform boundedness of every relevant count, sufficient for interpolation. +The bound holds simultaneously for all bin indices `k ≥ 1`. -/ +theorem primeBin_count_eventually_le (J : ℕ) (hJ : 0 < J) (C : ℝ) : + ∀ᶠ x : ℝ in atTop, ∀ k : ℕ, 1 ≤ k → ∀ n : ℕ, 1 ≤ n → + (n : ℝ) ≤ C * x → binCount (primeBin x J k) n ≤ J := by + have hJreal : (0 : ℝ) < J := by exact_mod_cast hJ + have hroot := (tendsto_rpow_atTop (div_pos zero_lt_one hJreal)).eventually + (eventually_gt_atTop C) + filter_upwards [hroot, eventually_ge_atTop (1 : ℝ)] with x hxC hxone + intro k hk n hn hnupper + let q : ℝ := x ^ ((1 : ℝ) / J) + have hxpos : 0 < x := lt_of_lt_of_le zero_lt_one hxone + have hq : 1 ≤ q := Real.one_le_rpow hxone (div_nonneg zero_le_one hJreal.le) + have hprimes : ∀ p ∈ primeBin x J k, q ≤ (p : ℝ) := by + intro p hp + have hl := ((mem_primeBin_iff hxpos.le J k p).mp hp).2.1 + have hexp : (1 : ℝ) / J ≤ (k : ℝ) / J := + div_le_div_of_nonneg_right (by exact_mod_cast hk) hJreal.le + exact (Real.rpow_le_rpow_of_exponent_le hxone hexp).trans hl.le + have hpow := binCount_pow_le (primeBin x J k) (by omega : n ≠ 0) (le_trans zero_le_one hq) hprimes + have hrootpow : q ^ J = x := by + simpa only [q, one_div] using Real.rpow_inv_natCast_pow hxpos.le (by omega : J ≠ 0) + by_contra hcount + have hjcount : J + 1 ≤ binCount (primeBin x J k) n := by omega + have hmon := pow_le_pow_right₀ hq hjcount + have hbig : C * x < q ^ (J + 1) := by + rw [pow_succ, hrootpow] + dsimp [q] at hxC ⊢ + nlinarith + linarith + +/-- A finite sequence crossing a level has an adjacent pair straddling it. -/ +private theorem exists_adjacent_crossing (y : ℕ → ℝ) (a : ℝ) {d : ℕ} + (hzero : y 0 < a) (hend : a ≤ y d) : + ∃ k : ℕ, k < d ∧ y k < a ∧ a ≤ y (k + 1) := by + induction d with + | zero => exact False.elim (not_lt_of_ge hend hzero) + | succ d ih => + by_cases hd : a ≤ y d + · obtain ⟨k, hk, hl, hu⟩ := ih hd + exact ⟨k, Nat.lt_trans hk (Nat.lt_succ_self d), hl, hu⟩ + · exact ⟨d, Nat.lt_succ_self d, lt_of_not_ge hd, hend⟩ + +/-- Every number between a bin endpoint and `x` belongs to a higher bin. -/ +theorem exists_higher_primeBin {x : ℝ} (hx : 0 ≤ x) {J r p : ℕ} + (hJ : 0 < J) (hr : r ≤ J) (hp : p.Prime) + (hlow : x ^ ((r : ℝ) / J) < (p : ℝ)) (hhigh : (p : ℝ) ≤ x) : + ∃ k ∈ Finset.Ico r J, p ∈ primeBin x J k := by + let y : ℕ → ℝ := fun i => x ^ (((r + i : ℕ) : ℝ) / J) + have hzero : y 0 < (p : ℝ) := by simpa only [y, Nat.add_zero] using hlow + have hend : (p : ℝ) ≤ y (J - r) := by + have hindices : r + (J - r) = J := by omega + change (p : ℝ) ≤ x ^ (((r + (J - r) : ℕ) : ℝ) / J) + rw [hindices, div_self (by exact_mod_cast (Nat.ne_of_gt hJ) : (J : ℝ) ≠ 0), + Real.rpow_one] + exact hhigh + obtain ⟨i, hi, hlo, hhi⟩ := exists_adjacent_crossing y (p : ℝ) hzero hend + refine ⟨r + i, Finset.mem_Ico.mpr ⟨by omega, by omega⟩, ?_⟩ + apply (mem_primeBin_iff hx J (r + i) p).mpr + refine ⟨hp, hlo, ?_⟩ + simpa only [y, Nat.cast_add, Nat.cast_one, add_assoc] using hhi + +/-- Smoothness at a rational endpoint is exactly vanishing of the higher-bin +multiplicity counts, provided `1 ≤ n ≤ x`. -/ +theorem maxPrimeFac_le_iff_higher_counts_zero {x : ℝ} (hx : 1 ≤ x) + {J r n : ℕ} (hJ : 0 < J) (hr : r ≤ J) (hn : 1 ≤ n) (hnx : (n : ℝ) ≤ x) : + (n.maxPrimeFac : ℝ) ≤ x ^ ((r : ℝ) / J) ↔ + ∀ k ∈ Finset.Ico r J, binCount (primeBin x J k) n = 0 := by + have hnzero : n ≠ 0 := by omega + have hxzero : 0 ≤ x := le_trans zero_le_one hx + constructor + · intro hsmooth k hk + apply binCount_eq_zero_of_no_factor + intro p hp hpdiv + obtain ⟨hpprime, hplower, _⟩ := (mem_primeBin_iff hxzero J k p).mp hp + have hpmax : (p : ℝ) ≤ n.maxPrimeFac := by + exact_mod_cast Nat.le_maxPrimeFac hnzero hpprime hpdiv + have hexp : (r : ℝ) / J ≤ (k : ℝ) / J := + div_le_div_of_nonneg_right (by exact_mod_cast (Finset.mem_Ico.mp hk).1) (Nat.cast_nonneg _) + have hpower := Real.rpow_le_rpow_of_exponent_le hx hexp + linarith + · intro hcounts + by_cases hone : n = 1 + · subst n + simpa using Real.one_le_rpow hx (div_nonneg (Nat.cast_nonneg r) (Nat.cast_nonneg J)) + by_contra hsmooth + have hpprime := Nat.prime_maxPrimeFac_of_one_lt (show 1 < n by omega) + have hpupper : (n.maxPrimeFac : ℝ) ≤ x := by + have hpn : (n.maxPrimeFac : ℝ) ≤ n := by exact_mod_cast Nat.maxPrimeFac_le (n := n) + exact hpn.trans hnx + obtain ⟨k, hk, hpmem⟩ := exists_higher_primeBin hxzero hJ hr hpprime + (lt_of_not_ge hsmooth) hpupper + have hpcount : 0 < n.factorization n.maxPrimeFac := + hpprime.factorization_pos_of_dvd hnzero Nat.maxPrimeFac_dvd + have hle : n.factorization n.maxPrimeFac ≤ binCount (primeBin x J k) n := + Finset.single_le_sum (fun p _ => Nat.zero_le (n.factorization p)) hpmem + rw [hcounts k hk] at hle + omega + + +/-- The fixed coefficient vector from interpolation works on every fixed +window `n ≤ C*x`, once the scale is sufficiently large. -/ +theorem centered_binLabel_interpolation_on_window {ι : Type*} [Fintype ι] [DecidableEq ι] + (J : ℕ) (hJ : 0 < J) (k : ι → ℕ) (hk : ∀ i, 1 ≤ k i) + (ζ : ι → ℂ) (μ : ℂ) (C : ℝ) : + ∃ c : (ι → Fin (J + 1)) → ℂ, ∀ᶠ x : ℝ in atTop, + ∀ n : ℕ, 1 ≤ n → (n : ℝ) ≤ C * x → + binLabel (fun i => primeBin x J (k i)) ζ n - μ = + ∑ a : ι → Fin (J + 1), c a * + (binLabel (fun i => primeBin x J (k i)) + (fun i => interpolationNode (a i)) n : ℂ) := by + obtain ⟨c, hc⟩ := centered_binLabel_interpolation ζ μ J + refine ⟨c, ?_⟩ + filter_upwards [primeBin_count_eventually_le J hJ C] with x hx n hn hnupper + exact hc _ n (by omega) (fun i => hx (k i) (hk i) n hn hnupper) + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinDecorrelation.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinDecorrelation.lean new file mode 100644 index 0000000000000000000000000000000000000000..8bf809db77ae6a483145fa5051938668205f8731 --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinDecorrelation.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.JointDickman.Amplification.BinCorrelationLimit + +namespace OAI + +/-! # Centered bin labels at consecutive integers decorrelate -/ +namespace JointDickman +open Finset Filter Classical PublishedInputs +open scoped Topology + +noncomputable def centeredBinCorrelation {ι : Type*} [Fintype ι] + (J₁ : ℕ) (k₁ : ι → ℕ) (z₁ : ι → ℂ) (J₂ : ℕ) + (z₂ : Fin (J₂-1) → ℂ) (μ : ℂ) (N : ℕ) : ℂ := + (∑ n ∈ range N, star (movingBinLabel J₁ k₁ z₁ N n) * + (movingBinLabel J₂ (fun i : Fin (J₂-1) => i.val+1) z₂ N (n+1)-μ))/(N : ℂ) + +theorem centeredBinCorrelation_norm_le_two {ι : Type*} [Fintype ι] + (J₁ : ℕ) (k₁ : ι → ℕ) (z₁ : ι → ℂ) (hz₁ : ∀ i, ‖z₁ i‖ = 1) + (J₂ : ℕ) (z₂ : Fin (J₂-1) → ℂ) (hz₂ : ∀ i, ‖z₂ i‖ = 1) + (μ : ℂ) (hμ : ‖μ‖ ≤ 1) (N : ℕ) : + ‖centeredBinCorrelation J₁ k₁ z₁ J₂ z₂ μ N‖ ≤ 2 := by + have hterm (n : ℕ) : ‖star (movingBinLabel J₁ k₁ z₁ N n) * + (movingBinLabel J₂ (fun i : Fin (J₂-1) => i.val+1) z₂ N (n+1)-μ)‖ ≤ 2 := by + rw [norm_mul,norm_star] + have h₁ := norm_binLabel_le_one (fun i => primeBin (N : ℝ) J₁ (k₁ i)) z₁ hz₁ n + have h₂ := norm_centered_binLabel_le_two (fun i : Fin (J₂-1) => primeBin (N : ℝ) J₂ (i.val+1)) + z₂ hz₂ μ hμ (n+1) + exact (mul_le_mul h₁ h₂ (norm_nonneg _) (by norm_num)).trans_eq (one_mul _) + unfold centeredBinCorrelation + rw [norm_div,Complex.norm_natCast] + by_cases hN : N = 0 + · simp [hN] + have hs := norm_sum_le_of_le (range N) (fun n _ => hterm n) + simp only [sum_const,nsmul_eq_mul,Finset.card_range] at hs + exact (div_le_iff₀ (by exact_mod_cast Nat.pos_of_ne_zero hN : (0 : ℝ) < N)).mpr (by simpa only [mul_comm] using hs) + +theorem centeredBinCorrelation_tendsto + (hMR : RealShortIntervalInput) (hMRT : ComplexShortIntervalInput) + (hKMT : CharacterDistanceDivergence) (hFord : FordUpperSieveInput) + (hSD : SquarefreeSelbergDelangeInput) (hSW : SquarefreeCharacterEstimateInput) + (hM : PrimeReciprocalMertensInput) (hMP : PrimeProductMertensInput) + (hMC : ∀ B M : ℕ, FiniteMcDiarmidInput (Fin M) (auxiliaryPrimes B).powerset) + {ι : Type*} [Fintype ι] + (J₁ : ℕ) (hJ₁ : 0 < J₁) (k₁ : ι → ℕ) (hk₁ : ∀ i, 1 ≤ k₁ i) + (z₁ : ι → ℂ) (hz₁ : ∀ i, ‖z₁ i‖ = 1) + {J₂ : ℕ} (hJ₂ : 0 < J₂) (z₂ : Fin (J₂-1) → ℂ) (hz₂ : ∀ i, ‖z₂ i‖ = 1) + (μ : ℂ) (hμ : ‖μ‖ ≤ 1) + (hcenter : ∀ D : ℝ, 0 < D → Tendsto (centeredBinPrefix J₂ z₂ μ D) atTop (𝓝 0)) : + Tendsto (centeredBinCorrelation J₁ k₁ z₁ J₂ z₂ μ) atTop (𝓝 0) := by + apply tendsto_of_subseq_tendsto + intro ns hns + obtain ⟨r,hr,hnr⟩ := strictMono_subseq_of_tendsto_atTop hns + have hbound (n : ℕ) : centeredBinCorrelation J₁ k₁ z₁ J₂ z₂ μ (ns (r n)) ∈ + Metric.closedBall (0 : ℂ) 2 := by + rw [Metric.mem_closedBall,dist_zero_right] + exact centeredBinCorrelation_norm_le_two J₁ k₁ z₁ hz₁ J₂ z₂ hz₂ μ hμ _ + obtain ⟨β,_,s,hs,hlim⟩ := (isCompact_closedBall (0 : ℂ) 2).tendsto_subseq hbound + have hzero : β = 0 := bin_correlation_limit_zero hMR hMRT hKMT hFord hSD hSW hM hMP hMC + J₁ hJ₁ k₁ hk₁ z₁ hz₁ hJ₂ z₂ hz₂ μ hμ hcenter (ns ∘ r ∘ s) (hnr.comp hs) hlim + exact ⟨r ∘ s,by simpa only [hzero,Function.comp_def] using hlim⟩ + +end JointDickman + +end OAI diff --git a/lean/OAI/NumberTheory/JointDickman/Amplification/BinDecorrelationDischarge.lean b/lean/OAI/NumberTheory/JointDickman/Amplification/BinDecorrelationDischarge.lean new file mode 100644 index 0000000000000000000000000000000000000000..069e2a3c9ff4cafc0f3a7ec1ab3dfc7b36e65bff --- /dev/null +++ b/lean/OAI/NumberTheory/JointDickman/Amplification/BinDecorrelationDischarge.lean @@ -0,0 +1,37 @@ +import OAI.NumberTheory.JointDickman.Amplification.BinDecorrelation +import OAI.NumberTheory.JointDickman.Amplification.BinCorrelationLimitDischarge + +namespace OAI + +/-! # Application consequences of the proved short-average estimates -/ +namespace JointDickman +open Finset Filter MeasureTheory Classical PublishedInputs +open scoped Topology + +theorem centeredBinCorrelation_tendsto_proved + (hKMT : CharacterDistanceDivergence) (hFord : FordUpperSieveInput) + (hSD : SquarefreeSelbergDelangeInput) (hSW : SquarefreeCharacterEstimateInput) + (hM : PrimeReciprocalMertensInput) (hMP : PrimeProductMertensInput) + (hMC : ∀ B M : ℕ, FiniteMcDiarmidInput (Fin M) (auxiliaryPrimes B).powerset) + {ι : Type*} [Fintype ι] + (J₁ : ℕ) (hJ₁ : 0 < J₁) (k₁ : ι → ℕ) (hk₁ : ∀ i, 1 ≤ k₁ i) + (z₁ : ι → ℂ) (hz₁ : ∀ i, ‖z₁ i‖ = 1) + {J₂ : ℕ} (hJ₂ : 0 < J₂) (z₂ : Fin (J₂-1) → ℂ) (hz₂ : ∀ i, ‖z₂ i‖ = 1) + (μ : ℂ) (hμ : ‖μ‖ ≤ 1) + (hcenter : ∀ D : ℝ, 0 < D → Tendsto (centeredBinPrefix J₂ z₂ μ D) atTop (𝓝 0)) : + Tendsto (centeredBinCorrelation J₁ k₁ z₁ J₂ z₂ μ) atTop (𝓝 0) := by + apply tendsto_of_subseq_tendsto + intro ns hns + obtain ⟨r,hr,hnr⟩ := strictMono_subseq_of_tendsto_atTop hns + have hbound (n : ℕ) : centeredBinCorrelation J₁ k₁ z₁ J₂ z₂ μ (ns (r n)) ∈ + Metric.closedBall (0 : ℂ) 2 := by + rw [Metric.mem_closedBall,dist_zero_right] + exact centeredBinCorrelation_norm_le_two J₁ k₁ z₁ hz₁ J₂ z₂ hz₂ μ hμ _ + obtain ⟨β,_,s,hs,hlim⟩ := (isCompact_closedBall (0 : ℂ) 2).tendsto_subseq hbound + have hzero : β = 0 := bin_correlation_limit_zero_proved hKMT hFord hSD hSW hM hMP hMC + J₁ hJ₁ k₁ hk₁ z₁ hz₁ hJ₂ z₂ hz₂ μ hμ hcenter (ns ∘ r ∘ s) (hnr.comp hs) hlim + exact ⟨r ∘ s,by simpa only [hzero,Function.comp_def] using hlim⟩ + +end JointDickman + +end OAI

(hJ i hi k hk).2.1) + have herrors : (91*accurateGrid m)*s.meanLog≤ min (1/1024:ℝ) (Real.exp (-100)/(512*640000)) := by + have hh := mul_le_mul_of_nonneg_left hm.2 (by have := accurateGrid_pos m; positivity : 0≤91*accurateGrid m) + exact hh.trans (by simpa only [mul_assoc] using herr) + have hcoverage := coverage_from_scalar_guards s D X (windowSmoothing W m) + (middleBlocks a m w J) (accurateBlock m (1/20)) _ _ _ qmid qbot + (by linarith only [hm.1]) (by have := windowSmoothing_pos W m; omega) + (by linarith only [hX]) hprime + (herrors.trans (min_le_right _ _)) (herrors.trans (min_le_left _ _)) + (hccost _ _ hbotcost hbmid) (fun i => hhazard _ ((Real.exp_pos X).trans_le (hprime i).1) (hprime i).2) + obtain ⟨hn,hshort,hnL,hnL',hnmax,hLmax⟩ := hint j hdata.1 hdata.2.1 + have hN : Real.exp (20*X)≤(windowSmoothing W m:ℝ) := by + apply le_trans _ (windowSmoothing_bounds W m).1 + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_right (pow_le_pow_right₀ (by norm_num : (1:ℝ)≤100) hw.le) (Real.exp_nonneg (m:ℝ)) + dsimp only [X] + nlinarith only [hh] + have hNLength : batchWordLength j≤windowSmoothing W m := by + have h := hsmooth ((2:ℝ)^j) (batchWordLength j) (windowSmoothing W m) hTpos + (by + have hh : (2:ℝ)^j≤Real.exp (21/20*X) := by + rw [←Real.exp_log hTpos,Real.log_pow] + exact Real.exp_le_exp.mpr hdata.2.1 + linarith only [hh,Real.exp_nonneg (21/20*X)]) + (Nat.cast_nonneg _) hLmax hN + exact_mod_cast h.1 + refine ⟨{ + pre := pre++topBlocks a (J w) + rest := middleBlocks a m w J++accurateBlock m (1/20) + schedule := by simp only [commonBlocks,middleBlocks,hpre,List.append_assoc] + T := (2:ℝ)^j + nonempty := hne + prime_scale := hpj + large := by linarith only [hT,Real.add_one_le_exp X,hX] + mean := hm.1 + b := bandSize s topParameter (a*(2:ℝ)^j) topIterations + n := packageRepetitions j + τ := 1/4 + A := X/400 + η := 1/100 + δ := 1/10000 + u := fun i => (s.signedPrime i:ℝ)*Real.exp (-X/200) + band := qtop + coverage := hcoverage + cap := qtop.size_cap (by linarith only [hm.1]) + repetitions := hn + length := batchWordLength_pos j + floor := by norm_num + gain := by linarith only [hX] + exceptions := fun i => by positivity + short := fun i => hshort.trans_le (hpj _ (s.enumeration i.2).property).1 + smooth_length := hNLength + smooth_error := fun i => (hsmooth _ _ _ ((Real.exp_pos X).trans_le (hprime i).1) + (hprime i).2 (Nat.cast_nonneg _) hLmax hN).2 + list := ?_ + rate := ?_ + }⟩ + · intro i + have hh := package_list_arithmetic hX hT ((Real.exp_pos X).trans_le (hprime i).1) + (hpj _ (s.enumeration i.2).property).2 hnL + dsimp only [s] at hh + convert hh using 1; congr 2; ring_nf + · apply package_rate_arithmetic (by linarith only [hX]) hTpos hc + (by simpa only [Real.log_pow] using hdata.1) + (by simpa only [Real.log_pow] using hdata.2.1) hm.2 + (by convert hbsize using 1; ring) hnL' + (hpcost _ _ _ (Nat.cast_nonneg _) hnmax hrestcost hT) hE + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/GaussianMoat/WindowParameters.lean b/lean/OAI/NumberTheory/GaussianMoat/WindowParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7c081b6ca52fd77762f2125bc0549a903221ec4 --- /dev/null +++ b/lean/OAI/NumberTheory/GaussianMoat/WindowParameters.lean @@ -0,0 +1,340 @@ +import OAI.NumberTheory.GaussianMoat.AccurateScales + +namespace OAI + +universe uIota + +namespace GaussianMoat + +section +open scoped BigOperators Classical +open Filter + +noncomputable def topParameter : ℝ := 1/1000000 +def topIterations : ℕ := 20 +noncomputable def topCoefficient (a : ℝ) : ℝ := (topParameter^2)^topIterations*a + +lemma topParameter_pos : 0 + bandLength topParameter (a*Real.exp x) i.val)++post) + 0 (bandSize s topParameter (a*Real.exp x) topIterations) (1/10000)) ∧ + topCoefficient a*Real.exp x/(4*x)≤ + (bandSize s topParameter (a*Real.exp x) topIterations:ℝ) := by + have hc := topCoefficient_pos ha + have hlarge := eventually_poly_le_exp (2*bandConstant D) + (a := topParameter^5*topCoefficient a) (mul_pos (pow_pos topParameter_pos _) hc) 1 + filter_upwards [hlarge,eventually_ge_atTop (2:ℝ)] with x hlarge hx + intro s pre post hne hp hdense hpost hlen + have hT2 : 2≤Real.exp x := by linarith only [Real.add_one_le_exp x,hx] + have hm := s.meanLog_bounds hne (Real.exp_pos x) hp + rw [Real.log_exp] at hm + have hmean : 1≤ s.meanLog := by linarith only [hm.1,hx] + have hmean0 : 0< s.meanLog := by linarith only [hmean] + have hlog2 : Real.log 2≤x := by + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith only [hh,hx] + have hmean' : s.meanLog≤2*x := by + rw [Real.log_mul (by norm_num) (Real.exp_ne_zero _),Real.log_exp] at hm + linarith only [hm.2,hlog2] + have hscale : bandScale topParameter (a*Real.exp x) topIterations=topCoefficient a*Real.exp x := by + unfold bandScale topCoefficient; ring + have hmargin : bandConstant D*s.meanLog≤topParameter^5* + bandScale topParameter (a*Real.exp x) topIterations := by + have hh := mul_le_mul_of_nonneg_left hmean' (bandConstant_pos D).le + rw [hscale] + simp only [pow_one] at hlarge + nlinarith only [hh,hlarge] + have hcap := dense_sieve_cap s hne hT2 hp hdense + (by nlinarith only [haδ,Real.exp_pos x] : 2*(a*Real.exp x)≤δ*Real.exp x) + have hband := entropyBand_from_margin s pre post 0 topIterations hD topParameter_pos + topParameter_small (mul_pos ha (Real.exp_pos _)) hmean hmargin hcap + (by simpa only [hscale,mul_assoc] using hpost) + (by simp only [Nat.cast_zero]; positivity) + (by simpa only [hscale,mul_assoc] using hlen) top_deficit + refine ⟨hband,?_⟩ + have hg5 : topParameter^5≤1 := pow_le_one₀ topParameter_pos.le (by norm_num [topParameter]) + have hVpos := bandScale_pos topParameter_pos (mul_pos ha (Real.exp_pos x)) topIterations + have hn := mul_le_mul_of_nonneg_right hg5 hVpos.le + have hC : 2≤bandConstant D := by + unfold bandConstant + linarith only [abs_nonneg (Real.log D),abs_nonneg (Real.log (max D ((latticeBall (4*D)).card:ℝ)))] + have hm2 := mul_le_mul_of_nonneg_right hC hmean0.le + have hV : 2*s.meanLog≤bandScale topParameter (a*Real.exp x) topIterations := by + nlinarith only [hmargin,hn,hm2] + have hh := bandSize_lower_of_scale hmean0 + (show 0 bandLength topParameter (a*(2:ℝ)^j) i.val) + +noncomputable def topBlocks (a : ℝ) (J : Finset ℕ) : List ℕ := + (J.sort (·≥·)).flatMap (topBlock a) + +noncomputable def accurateBlock (m : ℕ) (a : ℝ) : List ℕ := + List.ofFn (fun i : Fin (accurateIterations m) => + bandLength (accurateGrid m) (Real.exp (a*Real.exp m)) i.val) + +lemma topBlocks_length (a : ℝ) (J : Finset ℕ) : + (topBlocks a J).length=J.card*topIterations := by + unfold topBlocks + rw [List.length_flatMap] + simp only [topBlock,List.length_ofFn,List.map_const',List.sum_replicate,Finset.length_sort, + smul_eq_mul] + +lemma topBlock_bound {a H : ℝ} (ha : 0≤a) (j : ℕ) + (h : topParameter*a*(2:ℝ)^j≤H) : + ∀ n∈topBlock a j, (n:ℝ)≤Real.exp H := by + intro n hn + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hn + exact (bandLength_le_exp_start topParameter_pos.le + (by norm_num [topParameter]) (mul_nonneg ha (by positivity)) i.val).trans + (Real.exp_le_exp.mpr (by simpa only [mul_assoc] using h)) + +lemma accurateBlock_bound {a H : ℝ} {m : ℕ} (hg : accurateGrid m≤1) + (h : accurateGrid m*Real.exp (a*Real.exp m)≤H) : + ∀ n∈accurateBlock m a, (n:ℝ)≤Real.exp H := by + intro n hn + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hn + exact (bandLength_le_exp_start (accurateGrid_pos m).le hg (Real.exp_nonneg _) i.val).trans + (Real.exp_le_exp.mpr h) + +lemma sorted_split {J : Finset ℕ} {j : ℕ} (hj : j∈J) : + ∃ pre post : List ℕ, J.sort (·≥·)=pre++j::post ∧ + (∀ i∈post, i∈J ∧ i < j) ∧ (∀ i∈pre, i∈J ∧ j < i) := by + have hm : j∈J.sort (·≥·) := (Finset.mem_sort (·≥·)).mpr hj + obtain ⟨pre,post,he⟩ := List.mem_iff_append.mp hm + have hp : (J.sort (·≥·)).Pairwise (·>·) := by + exact (Finset.sortedGT_sort J).pairwise + rw [he,List.pairwise_append,List.pairwise_cons] at hp + refine ⟨pre,post,he,?_,?_⟩ + · intro i hi + refine ⟨(Finset.mem_sort (·≥·)).mp ?_,hp.2.1.1 i hi⟩ + rw [he]; exact List.mem_append_right _ (List.mem_cons_of_mem _ hi) + · intro i hi + refine ⟨(Finset.mem_sort (·≥·)).mp ?_,hp.2.2 i hi j (List.mem_cons_self ..)⟩ + rw [he]; exact List.mem_append_left _ hi + +lemma topBlocks_split {a : ℝ} {J : Finset ℕ} {j : ℕ} (hj : j∈J) : + ∃ pre post : List ℕ, topBlocks a J=pre++topBlock a j++post ∧ + post.length≤J.card*topIterations ∧ + (∀ n∈post, ∃ i∈J, i + topBlocks a (J w)++accurateBlock m ((100:ℝ)^w/4)) + +lemma windowBlocks_succ (a : ℝ) (m : ℕ) (J : ℕ → Finset ℕ) (W : ℕ) : + windowBlocks a m J (W+1)=topBlocks a (J W)++accurateBlock m ((100:ℝ)^W/4)++ + windowBlocks a m J W := by + simp only [windowBlocks,List.range_succ,List.reverse_append,List.reverse_singleton, + List.flatMap_append,List.flatMap_cons,List.flatMap_nil,List.append_nil,List.append_assoc] + +lemma windowBlocks_split (a : ℝ) (m : ℕ) (J : ℕ → Finset ℕ) {W w : ℕ} (hw : w omega + | succ W ih => + rw [windowBlocks_succ] + by_cases he : w=W + · subst w; exact ⟨[],by simp only [List.nil_append]⟩ + · obtain ⟨pre,hp⟩ := ih (by omega) + rw [hp] + exact ⟨topBlocks a (J W)++accurateBlock m ((100:ℝ)^W/4)++pre,by simp only [List.append_assoc]⟩ + +lemma windowBlocks_mem (a : ℝ) (m : ℕ) (J : ℕ → Finset ℕ) {W n : ℕ} + (hn : n∈windowBlocks a m J W) : + ∃ w simp only [Finset.sum_empty]; positivity + | @insert a J hmax ih => + have ha : a∉J := fun h => (lt_irrefl a) (hmax a h) + have hci : ∀ b∈J, b+K≤a := by + intro b hb + exact hsep b (Finset.mem_insert_of_mem hb) a (Finset.mem_insert_self ..) + (hmax b hb) + have hi := ih (fun b hb c hc hbc => hsep b (Finset.mem_insert_of_mem hb) + c (Finset.mem_insert_of_mem hc) hbc) hci + rw [Finset.sum_insert ha] + have hp := pow_le_pow_right₀ (by norm_num : (1:ℝ)≤2) (hcap a (Finset.mem_insert_self ..)) + have hd := (div_le_div_iff_of_pos_right hden).mpr hp + rw [pow_add] at hd + have he : (2:ℝ)^a+(2:ℝ)^a/((2:ℝ)^K-1)=(2:ℝ)^a*2^K/(2^K-1) := by + field_simp; ring + exact (add_le_add (le_refl ((2:ℝ)^a)) hi).trans (he ▸ hd) + +lemma residueWeight_union_le (F G : Finset GaussianInt) : + residueWeight (F∪G)≤residueWeight F+residueWeight G := by + classical + have hh := Finset.sum_union_inter (s₁ := F) (s₂ := G) (f := fun f : GaussianInt => Real.log f.norm.natAbs) + change residueWeight (F∪G)+residueWeight (F∩G)=residueWeight F+residueWeight G at hh + linarith only [hh,residueWeight_nonneg (F∩G)] + +lemma residueWeight_biUnion_le {ι : Type uIota} (J : Finset ι) (F : ι → Finset GaussianInt) : + residueWeight (J.biUnion F)≤∑ j∈J, residueWeight (F j) := by + induction J using Finset.induction_on with + | empty => simp [residueWeight] + | @insert j J hj ih => + rw [Finset.biUnion_insert,Finset.sum_insert hj] + exact (residueWeight_union_le _ _).trans (add_le_add (le_refl _) ih) + +lemma separated_factor_cost (J : Finset ℕ) {K j : ℕ} (hK : 0 (dyadicSieve a).availableFactors))≤ + (4*Real.log 4/((2:ℝ)^K-1))*(2:ℝ)^j := by + have hsum := Finset.sum_le_sum (fun a (_ : a∈J) => dyadicSieve_available_weight a) + rw [←Finset.mul_sum] at hsum + have hh := mul_le_mul_of_nonneg_left (separated_power_sum J hK hsep hcap) + (show 0≤4*Real.log 4 by positivity) + have ht := (residueWeight_biUnion_le J (fun a => (dyadicSieve a).availableFactors)).trans (hsum.trans hh) + calc + _ ≤ 4*Real.log 4*((2:ℝ)^j/(2^K-1)) := ht + _ = _ := by ring + +open scoped BigOperators Classical +open Filter + +lemma log_two_lower : (1/2:ℝ)≤Real.log 2 := by + have hh := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh + exact hh + +lemma narrow_bins_card {X : ℝ} (hX : 2≤X) (J : Finset ℕ) + (hJ : ∀ j∈J, (j:ℝ)*Real.log 2≤21/20*X) : + (J.card:ℝ)≤3*X := by + have hj : ∀ j∈J, (j:ℝ)≤21/10*X := by + intro j hj + have hh := mul_le_mul_of_nonneg_left log_two_lower (Nat.cast_nonneg j) + linarith only [hh,hJ j hj] + have hs : J⊆Finset.range (⌊21/10*X⌋₊+1) := by + intro j hj' + apply Finset.mem_range.mpr + exact Nat.lt_succ_of_le ((Nat.le_floor_iff (by positivity)).mpr (hj j hj')) + have hc : (J.card:ℝ)≤(⌊21/10*X⌋₊:ℝ)+1 := by + exact_mod_cast (Finset.card_le_card hs).trans_eq (Finset.card_range _) + have hf := Nat.floor_le (show 0≤21/10*X by linarith only [hX]) + linarith only [hc,hf,hX] + +lemma topBlock_separated {a : ℝ} (ha : 0 (hJ i hi).2.1) + have hlen' : (post.length+2:ℝ)≤Real.exp (topParameter*topCoefficient a*(2:ℝ)^j) := by + have hp : (post.length:ℝ)≤(J.card:ℝ)*topIterations := by exact_mod_cast hpl + simp only [pow_one,hT] at hlen + have he := Real.add_one_le_exp (topParameter*topCoefficient a*(2:ℝ)^j) + norm_num only [topIterations,Nat.cast_ofNat] at hp + nlinarith only [hp,hcard,hlen,he,hlog,hX2] + have hprime : ∀ p∈(dyadicSieve j).primes, Real.exp (j*Real.log 2)≤(p:ℝ) ∧ + (p:ℝ)≤2*Real.exp (j*Real.log 2) := by + intro p hp + rw [hT] + have hh := (PrimeLogMass.mem_dyadicBatch j p).mp hp + constructor + · exact_mod_cast hh.1 + · have hh' : p≤2^(j+1) := hh.2.1.le + rw [pow_succ] at hh' + exact_mod_cast (by simpa only [mul_comm] using hh' : p≤2*2^j) + have hdense : δ*Real.exp (j*Real.log 2)/Real.log (2*Real.exp (j*Real.log 2))≤ + (dyadicSieve j).primes.card := by + change δ*Real.exp (j*Real.log 2)/Real.log (2*Real.exp (j*Real.log 2))≤ + (PrimeLogMass.dyadicBatch j).card + simpa only [hT,pow_succ,mul_comm] using (hJ j hj).2.2 + have hpst : ∀ n∈post, (n:ℝ)≤Real.exp (topParameter*topCoefficient a*Real.exp (j*Real.log 2)) := by + intro n hnp + obtain ⟨i,hi,hij,hni⟩ := hpm n hnp + rw [hT] + exact topBlock_separated ha hgap (hsep i hi j hj hij) n hni + obtain ⟨hb,hbsize⟩ := hband (dyadicSieve j) (initial++pre) post hn hprime hdense hpst + (by simpa only [hT] using hlen') + refine ⟨?_,?_⟩ + · simpa only [hT,he,topBlock,List.append_assoc] using hb + · simpa only [hT,Real.log_pow] using hbsize + +end GaussianMoat + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ActualLossDensity.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ActualLossDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..f25e654942d8ffcde6d7033a5b643315dd38c0bb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ActualLossDensity.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.BoundaryRadialCoefficient +import OAI.NumberTheory.Jacobsthal.Estimates.OmissionSeries +import OAI.NumberTheory.Jacobsthal.Estimates.StandardBoundaryCoefficient + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.BuchstabBridge +open ErdosBoundaryIntegral Erdos970Dependency.StandardBoundary + +noncomputable def sourceWeight : Side → ℝ → ℝ + | .even,y => y^2-1 + | .odd,y => y^2 + +def sourceDomain : Side → Set ℝ + | .even => Ioi 1 + | .odd => Ioi 0 + +noncomputable def lossDensity (i : Side) (y : ℝ) : ℝ := + 2*sourceWeight i y*omissionDefect i (2*y+2) 2 +noncomputable def omissionDensity (n : ℕ) (i : Side) (y : ℝ) : ℝ := + 2*sourceWeight i y*gateIterate n omissionForce i (2*y+2) 2 + +theorem sourceWeight_nonnegative (i : Side) {y : ℝ} (hy : y ∈ sourceDomain i) : + 0 ≤ sourceWeight i y := by + cases i with + | even => change 1 < y at hy; change 0 ≤ y^2-1; nlinarith + | odd => exact sq_nonneg y + +theorem omissionDensity_continuous (n : ℕ) (i : Side) : Continuous (omissionDensity n i) := by + have hw : Continuous (sourceWeight i) := by cases i <;> unfold sourceWeight <;> fun_prop + have hc : Continuous (fun y : ℝ => gateIterate n omissionForce i (2*y+2) 2) := + (gateIterate_continuous omissionForce_continuous n i).comp + (((continuous_const.mul continuous_id).add continuous_const).prodMk continuous_const) + exact (continuous_const.mul hw).mul hc + +theorem omissionDensity_nonnegative (n : ℕ) (i : Side) {y : ℝ} (hy : y ∈ sourceDomain i) : + 0 ≤ omissionDensity n i y := + mul_nonneg (mul_nonneg (by norm_num) (sourceWeight_nonnegative i hy)) + (gateIterate_nonnegative omissionForce_nonnegative n i (2*y+2) 2) + +theorem lossDensity_nonnegative (i : Side) {y : ℝ} (hy : y ∈ sourceDomain i) : + 0 ≤ lossDensity i y := + mul_nonneg (mul_nonneg (by norm_num) (sourceWeight_nonnegative i hy)) (omissionDefect_nonnegative i (2*y+2) 2) + +theorem lossDensity_hasSum (i : Side) (y : ℝ) : + HasSum (fun n : ℕ => omissionDensity n i y) (lossDensity i y) := + (actual_omission_hasSum i (2*y+2) 2).mul_left (2*sourceWeight i y) + +theorem lossDensity_even (y : ℝ) : lossDensity .even y= + (y^2-1)*(1-f sieveA (y+1))-(y^2-1)*(lowerReference y-f sieveA (y+1)) := by + norm_num [lossDensity,sourceWeight,omissionDefect,survivorBaseline,baseCutoff,lowerReference] + ring + +theorem lossDensity_odd (y : ℝ) : lossDensity .odd y= + y^2*(upperReference y-F sieveA (y+1))-y^2*(1-F sieveA (y+1)) := by + norm_num [lossDensity,sourceWeight,omissionDefect,survivorBaseline,baseCutoff,upperReference] + ring + +theorem lossDensity_integrable (i : Side) : IntegrableOn (lossDensity i) (sourceDomain i) := by + cases i with + | even => + have h := standard_coefficient_integrable.1.sub lower_coefficient_integrable + apply h.congr_fun _ measurableSet_Ioi + intro y _ + exact (lossDensity_even y).symm + | odd => + have h := upper_coefficient_integrable.sub standard_coefficient_integrable.2 + apply h.congr_fun _ measurableSet_Ioi + intro y _ + exact (lossDensity_odd y).symm + +theorem actual_loss_integral : + standardCoefficient-signedCoefficientI= + (∫ y in sourceDomain .even,lossDensity .even y)+(∫ y in sourceDomain .odd,lossDensity .odd y) := by + simp_rw [sourceDomain,lossDensity_even,lossDensity_odd] + rw [integral_sub standard_coefficient_integrable.1 lower_coefficient_integrable, + integral_sub upper_coefficient_integrable standard_coefficient_integrable.2] + unfold standardCoefficient signedCoefficientI + ring + +end ErdosContinuousOmission + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/BonferroniDensity.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/BonferroniDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba3ec065f4b80818773a243b835fd11f3339f242 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/BonferroniDensity.lean @@ -0,0 +1,326 @@ +import Mathlib.Algebra.Order.Ring.Pow +import Mathlib.Analysis.Complex.Exponential +import Mathlib.Analysis.SpecialFunctions.Log.Basic +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.BonferroniBlocks + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.BonferroniDensity + +open scoped BigOperators + +noncomputable def elementarySum (P : Finset ℕ) (g : ℕ → ℝ) (k : ℕ) : ℝ := + ∑ T ∈ P.powersetCard k, ∏ p ∈ T, g p + +@[simp] theorem elementarySum_zero (P : Finset ℕ) (g : ℕ → ℝ) : + elementarySum P g 0 = 1 := by simp [elementarySum] + +theorem elementarySum_nonneg (P : Finset ℕ) (g : ℕ → ℝ) + (hg : ∀ p ∈ P, 0 ≤ g p) (k : ℕ) : 0 ≤ elementarySum P g k := by + apply Finset.sum_nonneg + intro T hT + exact Finset.prod_nonneg fun p hp => hg p ((Finset.mem_powersetCard.mp hT).1 hp) + +theorem elementarySum_insert (P : Finset ℕ) (g : ℕ → ℝ) {a : ℕ} (ha : a ∉ P) (k : ℕ) : + elementarySum (insert a P) g (k + 1) = + elementarySum P g (k + 1) + g a * elementarySum P g k := by + classical + have hdis : Disjoint (P.powersetCard (k + 1)) ((P.powersetCard k).image (insert a)) := by + apply Finset.disjoint_left.mpr + intro T hT hTi + obtain ⟨U, hU, rfl⟩ := Finset.mem_image.mp hTi + exact ha ((Finset.mem_powersetCard.mp hT).1 (Finset.mem_insert_self a U)) + have hinj : Set.InjOn (insert a) (P.powersetCard k : Set (Finset ℕ)) := by + intro T hT U hU hEq + have haT : a ∉ T := fun h => ha ((Finset.mem_powersetCard.mp hT).1 h) + have haU : a ∉ U := fun h => ha ((Finset.mem_powersetCard.mp hU).1 h) + have h := congrArg (fun S : Finset ℕ => S.erase a) hEq + simpa only [Finset.erase_insert haT, Finset.erase_insert haU] using h + unfold elementarySum + rw [Finset.powersetCard_succ_insert ha, Finset.sum_union hdis, Finset.sum_image hinj, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro T hT + exact Finset.prod_insert (fun haT => ha ((Finset.mem_powersetCard.mp hT).1 haT)) + +theorem factorial_mul_elementarySum_le (P : Finset ℕ) (g : ℕ → ℝ) + (hg : ∀ p ∈ P, 0 ≤ g p) (k : ℕ) : + (k.factorial : ℝ) * elementarySum P g k ≤ (∑ p ∈ P, g p) ^ k := by + classical + revert hg k + induction P using Finset.induction_on with + | empty => + intro _ k + cases k with + | zero => simp [elementarySum] + | succ k => + have he : (∅ : Finset ℕ).powersetCard (k + 1) = ∅ := + Finset.powersetCard_eq_empty.mpr (by simp) + simp only [elementarySum, he, Finset.sum_empty, mul_zero, zero_pow (Nat.succ_ne_zero k), le_refl] + | @insert a P ha ih => + intro hg k + have hga : 0 ≤ g a := hg a (Finset.mem_insert_self a P) + have hgP : ∀ p ∈ P, 0 ≤ g p := fun p hp => hg p (Finset.mem_insert_of_mem hp) + have hsum : 0 ≤ ∑ p ∈ P, g p := Finset.sum_nonneg hgP + cases k with + | zero => simp + | succ k => + rw [elementarySum_insert P g ha, Finset.sum_insert ha] + have hi0 := ih hgP k + have hi1 := ih hgP (k + 1) + calc + (((k + 1).factorial : ℕ) : ℝ) * + (elementarySum P g (k + 1) + g a * elementarySum P g k) = + (((k + 1).factorial : ℕ) : ℝ) * elementarySum P g (k + 1) + + ((k + 1 : ℕ) : ℝ) * g a * ((k.factorial : ℝ) * elementarySum P g k) := by + rw [Nat.factorial_succ] + push_cast + ring + _ ≤ (∑ p ∈ P, g p) ^ (k + 1) + + ((k + 1 : ℕ) : ℝ) * g a * (∑ p ∈ P, g p) ^ k := + add_le_add hi1 (mul_le_mul_of_nonneg_left hi0 (by positivity)) + _ ≤ ((∑ p ∈ P, g p) + g a) ^ (k + 1) := by + have h := pow_add_mul_le_add_pow hsum + (show 0 ≤ 2 * (∑ p ∈ P, g p) + g a by positivity) (k + 1) + simpa only [Nat.add_sub_cancel, mul_assoc, mul_left_comm, mul_comm] using h + _ = _ := by rw [add_comm] + +theorem elementarySum_le_pow_div_factorial (P : Finset ℕ) (g : ℕ → ℝ) + (hg : ∀ p ∈ P, 0 ≤ g p) {A : ℝ} (_hA : 0 ≤ A) + (hsum : ∑ p ∈ P, g p ≤ A) (k : ℕ) : + elementarySum P g k ≤ A ^ k / k.factorial := by + apply (le_div_iff₀ (by exact_mod_cast Nat.factorial_pos k)).mpr + calc + elementarySum P g k * (k.factorial : ℝ) = + (k.factorial : ℝ) * elementarySum P g k := mul_comm _ _ + _ ≤ (∑ p ∈ P, g p) ^ k := factorial_mul_elementarySum_le P g hg k + _ ≤ A ^ k := pow_le_pow_left₀ (Finset.sum_nonneg hg) hsum k + +theorem elementarySum_le_exponential (P : Finset ℕ) (g : ℕ → ℝ) + (hg : ∀ p ∈ P, 0 ≤ g p) {A : ℝ} (hA : 0 ≤ A) + (hsum : ∑ p ∈ P, g p ≤ A) (k : ℕ) : + elementarySum P g k ≤ Real.exp (2 * A) / (2 : ℝ) ^ k := by + calc + elementarySum P g k ≤ A ^ k / k.factorial := elementarySum_le_pow_div_factorial P g hg hA hsum k + _ = ((2 * A) ^ k / k.factorial) / (2 : ℝ) ^ k := by + rw [mul_pow] + field_simp + _ ≤ _ := div_le_div_of_nonneg_right + (Real.pow_div_factorial_le_exp (2 * A) (by positivity) k) (by positivity) + +theorem exp_neg_three_mul_le_eulerProduct (P : Finset ℕ) (g : ℕ → ℝ) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hg2 : ∀ p ∈ P, g p ≤ 2 / 3) + {A : ℝ} (hsum : ∑ p ∈ P, g p ≤ A) : + Real.exp (-3 * A) ≤ ∏ p ∈ P, (1 - g p) := by + have hpoint : ∀ p ∈ P, Real.exp (-3 * g p) ≤ 1 - g p := by + intro p hp + have h0 := hg0 p hp + have h2 := hg2 p hp + have hpos : 0 < 1 - g p := by linarith + have hinv : (1 - g p)⁻¹ ≤ 1 + 3 * g p := by + apply (inv_le_iff_one_le_mul₀ hpos).mpr + nlinarith [mul_nonneg h0 (show 0 ≤ 2 - 3 * g p by linarith)] + have hlog : -3 * g p ≤ Real.log (1 - g p) := by + have h := Real.one_sub_inv_le_log_of_pos hpos + linarith + exact (Real.le_log_iff_exp_le hpos).mp hlog + calc + Real.exp (-3 * A) ≤ Real.exp (-3 * ∑ p ∈ P, g p) := Real.exp_le_exp.mpr (by linarith) + _ = ∏ p ∈ P, Real.exp (-3 * g p) := by rw [Finset.mul_sum, Real.exp_sum] + _ ≤ _ := Finset.prod_le_prod₀ (fun _ _ => (Real.exp_pos _).le) hpoint + +theorem relative_elementarySum_le_exponential (P : Finset ℕ) (g : ℕ → ℝ) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hg2 : ∀ p ∈ P, g p ≤ 2 / 3) + {A : ℝ} (hA : 0 ≤ A) (hsum : ∑ p ∈ P, g p ≤ A) (k : ℕ) : + elementarySum P g k / (∏ p ∈ P, (1 - g p)) ≤ Real.exp (5 * A) / (2 : ℝ) ^ k := by + have hEuler := exp_neg_three_mul_le_eulerProduct P g hg0 hg2 hsum + have hpos : 0 < ∏ p ∈ P, (1 - g p) := (Real.exp_pos _).trans_le hEuler + have hexp : Real.exp (2 * A) / Real.exp (-3 * A) = Real.exp (5 * A) := by + rw [← Real.exp_sub] + congr 1 + ring + calc + _ ≤ (Real.exp (2 * A) / (2 : ℝ) ^ k) / (∏ p ∈ P, (1 - g p)) := + div_le_div_of_nonneg_right (elementarySum_le_exponential P g hg0 hA hsum k) hpos.le + _ ≤ (Real.exp (2 * A) / (2 : ℝ) ^ k) / Real.exp (-3 * A) := + div_le_div_of_nonneg_left (by positivity) (Real.exp_pos _) hEuler + _ = (Real.exp (2 * A) / Real.exp (-3 * A)) / (2 : ℝ) ^ k := by ring + _ = _ := by rw [hexp] + +theorem relative_elementarySum_le_exp_decay (P : Finset ℕ) (g : ℕ → ℝ) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hg2 : ∀ p ∈ P, g p ≤ 2 / 3) + {A : ℝ} (hA : 0 ≤ A) (hsum : ∑ p ∈ P, g p ≤ A) (k : ℕ) + (hthreshold : 5 * A ≤ (k : ℝ) * Real.log 2 / 2) : + elementarySum P g k / (∏ p ∈ P, (1 - g p)) ≤ + Real.exp (-(k : ℝ) * Real.log 2 / 2) := by + have hpow : (2 : ℝ) ^ k = Real.exp ((k : ℝ) * Real.log 2) := by + rw [Real.exp_nat_mul, Real.exp_log (by norm_num : (0 : ℝ) < 2)] + apply (relative_elementarySum_le_exponential P g hg0 hg2 hA hsum k).trans + rw [hpow, ← Real.exp_sub] + apply Real.exp_le_exp.mpr + linarith + +theorem prime_density_le_two_thirds (P : Finset ℕ) (g : ℕ → ℝ) + (hprime : ∀ p ∈ P, p.Prime) (hdim : ∀ p ∈ P, g p ≤ 2 / p) + (htwo : 2 ∈ P → g 2 ≤ 1 / 2) : ∀ p ∈ P, g p ≤ 2 / 3 := by + intro p hp + by_cases hp2 : p = 2 + · subst p + have h := htwo hp + linarith + · have hp3 : 3 ≤ p := by have := (hprime p hp).two_le; omega + apply (hdim p hp).trans + exact div_le_div_of_nonneg_left (by norm_num) (by norm_num) (by exact_mod_cast hp3) + +noncomputable def densityPolynomial (m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) : ℝ := + ∑ r ∈ Finset.range (m + 1), (-1 : ℝ) ^ r * elementarySum P g r + +@[simp] theorem densityPolynomial_zero (P : Finset ℕ) (g : ℕ → ℝ) : + densityPolynomial 0 P g = 1 := by simp [densityPolynomial] + +theorem densityPolynomial_succ (m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) : + densityPolynomial (m + 1) P g = densityPolynomial m P g + + (-1 : ℝ) ^ (m + 1) * elementarySum P g (m + 1) := by + exact Finset.sum_range_succ _ _ + +theorem densityPolynomial_empty (m : ℕ) (g : ℕ → ℝ) : + densityPolynomial m ∅ g = 1 := by + induction m with + | zero => simp + | succ m ih => + rw [densityPolynomial_succ, ih] + have he : (∅ : Finset ℕ).powersetCard (m + 1) = ∅ := + Finset.powersetCard_eq_empty.mpr (by simp) + simp only [elementarySum, he, Finset.sum_empty, mul_zero, add_zero] + +theorem densityPolynomial_insert (m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) + {a : ℕ} (ha : a ∉ P) : + densityPolynomial (m + 1) (insert a P) g = + densityPolynomial (m + 1) P g - g a * densityPolynomial m P g := by + induction m with + | zero => + rw [densityPolynomial_succ, densityPolynomial_succ, + elementarySum_insert P g ha] + simp only [densityPolynomial_zero, elementarySum_zero, mul_one] + ring + | succ m ih => + rw [densityPolynomial_succ (m + 1) (insert a P), ih, + elementarySum_insert P g ha (m + 1), densityPolynomial_succ (m + 1) P, + densityPolynomial_succ m P, pow_succ (-1 : ℝ) (m + 1)] + ring + +theorem densityPolynomial_bounds (P : Finset ℕ) (g : ℕ → ℝ) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hg1 : ∀ p ∈ P, g p ≤ 1) (m : ℕ) : + densityPolynomial (2 * m + 1) P g ≤ (∏ p ∈ P, (1 - g p)) ∧ + (∏ p ∈ P, (1 - g p)) ≤ densityPolynomial (2 * m) P g := by + classical + revert hg0 hg1 m + induction P using Finset.induction_on with + | empty => intro _ _ m; simp only [densityPolynomial_empty, Finset.prod_empty, le_refl, and_self] + | @insert a P ha ih => + intro hg0 hg1 m + have hga := hg0 a (Finset.mem_insert_self a P) + have hgP0 : ∀ p ∈ P, 0 ≤ g p := fun p hp => hg0 p (Finset.mem_insert_of_mem hp) + have hgP1 : ∀ p ∈ P, g p ≤ 1 := fun p hp => hg1 p (Finset.mem_insert_of_mem hp) + have hbase := ih hgP0 hgP1 m + constructor + · rw [densityPolynomial_insert (2 * m) P g ha, Finset.prod_insert ha] + nlinarith [mul_nonneg hga (sub_nonneg.mpr hbase.2)] + · cases m with + | zero => + simp only [Nat.mul_zero, densityPolynomial_zero] + apply Finset.prod_le_one₀ + · intro p hp + exact sub_nonneg.mpr (hg1 p hp) + · intro p hp + linarith [hg0 p hp] + | succ m => + have hlow := (ih hgP0 hgP1 m).1 + have hupp := (ih hgP0 hgP1 (m + 1)).2 + have hidx : 2 * (m + 1) = (2 * m + 1) + 1 := by omega + rw [hidx, densityPolynomial_insert (2 * m + 1) P g ha, Finset.prod_insert ha] + rw [hidx] at hupp + nlinarith [mul_nonneg hga (sub_nonneg.mpr hlow)] + +theorem densityPolynomial_gap (m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) : + densityPolynomial (2 * m) P g - densityPolynomial (2 * m + 1) P g = + elementarySum P g (2 * m + 1) := by + rw [densityPolynomial_succ] + simp only [pow_add, pow_mul, neg_one_sq, one_pow, pow_one, one_mul] + ring + +theorem densityPolynomial_relative_error (P : Finset ℕ) (g : ℕ → ℝ) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hg2 : ∀ p ∈ P, g p ≤ 2 / 3) + {A : ℝ} (hA : 0 ≤ A) (hsum : ∑ p ∈ P, g p ≤ A) (m : ℕ) : + |densityPolynomial (2 * m) P g / (∏ p ∈ P, (1 - g p)) - 1| ≤ + Real.exp (5 * A) / (2 : ℝ) ^ (2 * m + 1) ∧ + |densityPolynomial (2 * m + 1) P g / (∏ p ∈ P, (1 - g p)) - 1| ≤ + Real.exp (5 * A) / (2 : ℝ) ^ (2 * m + 1) := by + have hEuler := exp_neg_three_mul_le_eulerProduct P g hg0 hg2 hsum + have hpos : 0 < ∏ p ∈ P, (1 - g p) := (Real.exp_pos _).trans_le hEuler + have hb := densityPolynomial_bounds P g hg0 (fun p hp => by linarith [hg2 p hp]) m + have hgap := densityPolynomial_gap m P g + have htail := relative_elementarySum_le_exponential P g hg0 hg2 hA hsum (2 * m + 1) + have hUP : 0 ≤ densityPolynomial (2 * m) P g / (∏ p ∈ P, (1 - g p)) - 1 := by + apply sub_nonneg.mpr + exact (le_div_iff₀ hpos).mpr (by simpa using hb.2) + have hLP : densityPolynomial (2 * m + 1) P g / (∏ p ∈ P, (1 - g p)) - 1 ≤ 0 := by + apply sub_nonpos.mpr + exact (div_le_iff₀ hpos).mpr (by simpa using hb.1) + constructor + · rw [abs_of_nonneg hUP] + apply le_trans ?_ htail + have hEq : densityPolynomial (2 * m) P g / (∏ p ∈ P, (1 - g p)) - 1 = + (densityPolynomial (2 * m) P g - (∏ p ∈ P, (1 - g p))) / + (∏ p ∈ P, (1 - g p)) := by + field_simp + rw [hEq] + exact (div_le_div_iff_of_pos_right hpos).mpr (by linarith) + · rw [abs_of_nonpos hLP] + apply le_trans ?_ htail + have hEq : -(densityPolynomial (2 * m + 1) P g / (∏ p ∈ P, (1 - g p)) - 1) = + ((∏ p ∈ P, (1 - g p)) - densityPolynomial (2 * m + 1) P g) / + (∏ p ∈ P, (1 - g p)) := by + field_simp + ring + rw [hEq] + exact (div_le_div_iff_of_pos_right hpos).mpr (by linarith) + +theorem densityPolynomial_eq_momentPolynomial (m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) : + densityPolynomial m P g = BonferroniBlocks.momentPolynomial m P (fun T => ∏ p ∈ T, g p) := rfl + +theorem prime_densityPolynomial_relative_exp_decay (P : Finset ℕ) (g : ℕ → ℝ) + (hprime : ∀ p ∈ P, p.Prime) (hg0 : ∀ p ∈ P, 0 ≤ g p) + (hdim : ∀ p ∈ P, g p ≤ 2 / p) (htwo : 2 ∈ P → g 2 ≤ 1 / 2) + {A : ℝ} (hA : 0 ≤ A) (hsum : ∑ p ∈ P, g p ≤ A) (m : ℕ) + (hthreshold : 5 * A ≤ ((2 * m + 1 : ℕ) : ℝ) * Real.log 2 / 2) : + Real.exp (-3 * A) ≤ (∏ p ∈ P, (1 - g p)) ∧ + |densityPolynomial (2 * m) P g / (∏ p ∈ P, (1 - g p)) - 1| ≤ + Real.exp (-((2 * m + 1 : ℕ) : ℝ) * Real.log 2 / 2) ∧ + |densityPolynomial (2 * m + 1) P g / (∏ p ∈ P, (1 - g p)) - 1| ≤ + Real.exp (-((2 * m + 1 : ℕ) : ℝ) * Real.log 2 / 2) := by + have hcap := prime_density_le_two_thirds P g hprime hdim htwo + have hbounds := densityPolynomial_relative_error P g hg0 hcap hA hsum m + have hdecay : Real.exp (5 * A) / (2 : ℝ) ^ (2 * m + 1) ≤ + Real.exp (-((2 * m + 1 : ℕ) : ℝ) * Real.log 2 / 2) := by + have hpow : (2 : ℝ) ^ (2 * m + 1) = + Real.exp (((2 * m + 1 : ℕ) : ℝ) * Real.log 2) := by + rw [Real.exp_nat_mul, Real.exp_log (by norm_num : (0 : ℝ) < 2)] + rw [hpow, ← Real.exp_sub] + apply Real.exp_le_exp.mpr + linarith + exact ⟨exp_neg_three_mul_le_eulerProduct P g hg0 hcap hsum, + hbounds.1.trans hdecay, hbounds.2.trans hdecay⟩ + +end NumberTheoryLean.BonferroniDensity + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/BoundaryProductLimit.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/BoundaryProductLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..06dcaf7ecbc0d168d6270d3d2922e15aedd73cdb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/BoundaryProductLimit.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceProductErrors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter _root_.Erdos970.Filter +open scoped Topology +namespace ErdosContinuousAnomaly +open ErdosContinuousBoundary +open NumberTheoryLean.ReferenceAdmission NumberTheoryLean.ReferencePruning +open NumberTheoryLean.ReferenceProductsBasics NumberTheoryLean.ReferenceMertens +open NumberTheoryLean.ReferenceProductErrors + +noncomputable def boundaryProduct (w : ℝ) : ℝ := survivorProduct (boundaryPrimes w) + +theorem boundaryProduct_eq_referenceProduct (w : ℝ) : + boundaryProduct w=referenceProduct w 2 true := by + simp only [boundaryProduct,referenceProduct,availableProduct,availablePrimes_closed,boundaryPrimes] + +theorem boundaryProduct_tendsto_half : Tendsto boundaryProduct atTop (𝓝 (1/2:ℝ)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := reference_product_absolute + have he : ∀ᶠ w : ℝ in atTop, + ‖referenceProduct w 2 true-normalization w/2‖ ≤ boundaryPrimeError c (C/2) w := by + filter_upwards [eventually_ge_atTop w₀] with w hw + have hh := (h w hw).2.2 2 le_rfl true + have hw1 : 1 < w := hw₀.trans_le hw + have hs : Real.sqrt (Real.log w) ≤ Real.sqrt (2*Real.log w) := by + apply Real.sqrt_le_sqrt + nlinarith [Real.log_pos hw1] + have hm : Real.exp (-c*Real.sqrt (2*Real.log w)) ≤ Real.exp (-c*Real.sqrt (Real.log w)) := + Real.exp_le_exp.mpr (by nlinarith) + rw [Real.norm_eq_abs] + exact hh.trans (mul_le_mul_of_nonneg_left hm (by positivity : 0 ≤ C/2)) + have hz : Tendsto (fun w : ℝ => referenceProduct w 2 true-normalization w/2) atTop (𝓝 0) := + squeeze_zero_norm' he (boundaryPrimeError_tendsto_zero hc (C/2)) + have hsum := hz.add (normalization_tendsto_one.div_const (2:ℝ)) + have hv : Tendsto (fun w : ℝ => referenceProduct w 2 true) atTop (𝓝 (1/2:ℝ)) := by + simpa only [sub_add_cancel,zero_add] using! hsum + exact hv.congr' (Eventually.of_forall fun w => (boundaryProduct_eq_referenceProduct w).symm) + +end ErdosContinuousAnomaly + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/CanonicalBadCompact.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CanonicalBadCompact.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e5615572395f7f42b00979ea4c9447f9a773fd5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CanonicalBadCompact.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Probability.CompletedMarkEvents + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.CanonicalBadCompact + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open FinitePathMeasures FinitePathGeometry FiniteHistoryTransport CemeteryKernel CemeteryHistoryMap +open LiveKilledPrefixes CompletedMarkEvents CanonicalMarkSlack CanonicalCoupledHistories +open RegeneratingInverseBands ArrivalKernelGeometry ContinuousKilledBins +open Erdos970Dependency.MarkedVisits + +theorem canonical_bad_compact_subset {r R b₀ b₁ : ℝ} + (hr : 0 < r) (hb₀ : 0 < b₀) (hb₁ : 0 < b₁) (hR : R < 6*b₀) + (E : Set CostState) (s : State) (N : ℕ) : + ∀ᵐ h ∂finitePathMeasure s N, + killHist E N h ∈ badCompactPath (Real.log r) R b₀ b₁ N → + h ∈ closedNoHitEvent 1 N r b₀ b₁ 1 := by + have hCosts : ∀ᵐ h ∂finitePathMeasure s N, h ∈ increasingCosts 0 N := + rawExtension_increasingCosts 0 N (fun _ => (s,0)) + filter_upwards [canonical_all_marks_slack hr hb₀ hb₁ s N,hCosts] with h hMarks hCost + rintro ⟨j,hcompact,hNo⟩ + cases hz : killHist E N h j with + | inr u => rw [hz] at hcompact; exact False.elim hcompact + | inl z => + rw [hz] at hcompact + have horig := (live_coordinate_original E N j.1 (Finset.mem_Iic.mp j.2) h z hz).1 + have hgapj : gapValue (Real.log r) (h j) ≤ R := by rw [horig]; exact hcompact + have hNoHit : h ∉ anyPairHit 1 N (Real.log (r/b₁)) (Real.log (b₁/(10*b₀))) := by + rintro ⟨k,hk,hHit⟩ + have hslack := hMarks 1 k hk hHit + let m : Finset.Iic N := ⟨1+2*k+1,Finset.mem_Iic.mpr hk⟩ + by_cases hmj : m.1 ≤ j.1 + · have hp := live_prefix_preserved E N j.1 (Finset.mem_Iic.mp j.2) h z hz m.1 hmj + have hn := hNo m hmj + rw [hp] at hn + exact hn ⟨hslack.1,hslack.2.1,hslack.2.2.1,hslack.2.2.2.1,hslack.2.2.2.2.1⟩ + · have hcm := hCost j m (Nat.zero_le _) (by omega) + have hgm : gapValue (Real.log r) (h m) ≤ gapValue (Real.log r) (h j) := + Real.exp_le_exp.mpr (sub_le_sub_left hcm _) + have hsGap : 6*b₀ < gapValue (Real.log r) (h m) := hslack.2.2.2.2.2 + linarith + refine ⟨hNoHit,Or.inl ?_⟩ + have hcN := hCost j ⟨N,by simp⟩ (Nat.zero_le _) (Finset.mem_Iic.mp j.2) + have hgN : gapValue (Real.log r) (rawLast N h) ≤ gapValue (Real.log r) (h j) := + Real.exp_le_exp.mpr (sub_le_sub_left hcN _) + rw [gapValue_log_eq_gapAt hr] at hgN + linarith + +theorem canonical_bad_compact_mass {r R b₀ b₁ : ℝ} + (hr : 0 < r) (hb₀ : 0 < b₀) (hb₁ : 0 < b₁) (hR : R < 6*b₀) + {E : Set CostState} (hE : MeasurableSet E) (s : State) (N : ℕ) : + ((finitePathMeasure s N).map (killHist E N)) (badCompactPath (Real.log r) R b₀ b₁ N) ≤ + finitePathMeasure s N (closedNoHitEvent 1 N r b₀ b₁ 1) := by + rw [Measure.map_apply (killHist_measurable hE N) (badCompactPath_measurable _ _ _ _ _)] + exact measure_mono_ae (canonical_bad_compact_subset hr hb₀ hb₁ hR E s N) + +theorem completed_bad_compact_mass {r R b₀ b₁ : ℝ} + (hr : 0 < r) (hb₀ : 0 < b₀) (hb₁ : 0 < b₁) (hR : R < 6*b₀) + (ell S : ℝ) (s : State) (N : ℕ) : + pathKernel (continuousChain (Real.log r) ell S) N (fun _ => Sum.inl (s,0)) + (badCompactPath (Real.log r) R b₀ b₁ N) ≤ + finitePathMeasure s N (closedNoHitEvent 1 N r b₀ b₁ 1) := by + rw [← canonical_killing_image s N (Real.log r) ell S] + exact canonical_bad_compact_mass hr hb₀ hb₁ hR (LowStateHorizon.lowDomain_measurable _ _ _) s N + +end NumberTheoryLean.CanonicalBadCompact + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactCorrectionLimit.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactCorrectionLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..e7e1e2bc17f03847972e0cc803c0071694ff0b0e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactCorrectionLimit.lean @@ -0,0 +1,112 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.CompactAnomalyTest + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Finset +namespace ErdosCorrectionOccupation +attribute [local instance] Classical.propDecidable +open ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.PrimeBinMembership NumberTheoryLean.ActualPrimeHigh +open NumberTheoryLean.UncappedCompactMass NumberTheoryLean.SourceNodeCoordinates +open NumberTheoryLean.ActualBoundaryDomain NumberTheoryLean.LiteralUniformPrimeTail +open NumberTheoryLean.LiteralPrimeOccupation +open ErdosPrimeInputs.PrimePrefixMass +open ErdosPrimeInputs.PrimePrefixTail + +noncomputable def compactCorrection (K w ell : ℝ) (start : Node) : ℝ := + ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps* + compactAnomalyTest K (terminal w start ps).side ((terminal w start ps).gap,(terminal w start ps).ratio) + +theorem compact_correction_error {C c K B w ell : ℝ} + (hA : ∀ r : ℝ,2 ≤ r → ∀ i : Side,|continuousAnomaly i r| ≤ C*Real.exp (-c*r)) + (hB : 4 ≤ B) (hell : 2 ≤ ell) (hellB : ell ≤ B) (start : Node) + (hi : start.side=.even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hcons : Consistent start) (hcut : start.cutoff=B) : + |continuousBoundaryCorrection w ell start-compactCorrection K w ell start| ≤ + C*(∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*tailListReward c K w start ps) := by + obtain ⟨hs,hr,_hBgap,_hsize⟩ := source_node_bounds (by linarith : 0 < B) start hi h199 h23 hcons hcut + rw [continuousBoundaryCorrection_eq_state_reward w ell start hi,compactCorrection,← Finset.sum_sub_distrib] + apply (Finset.abs_sum_le_sum_abs _ _).trans + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro ps hp + have hpA : uncappedAllowed w ell start ps := (Finset.mem_filter.mp hp).2 + have hr2 := boundary_gap_ge_two (source_boundary_domain hB hell start hi h199 h23 hcons hcut hpA) + have hratio := uncapped_terminal_ratio_le_gap (by linarith : 1 ≤ ell) hr hs hcons (by rwa [hcut]) hpA + have he := compactAnomalyTest_error K (terminal w start ps).side hr2 hratio.1.le hratio.2 + have henv : (if K < (terminal w start ps).gap then |continuousAnomaly (terminal w start ps).side (terminal w start ps).gap| else 0) ≤ + C*tailListReward c K w start ps := by + unfold tailListReward + split_ifs + · exact hA _ hr2 _ + · simp + rw [← mul_sub,abs_mul,abs_of_nonneg (prefixWeight_nonneg ps)] + have hh := mul_le_mul_of_nonneg_left (he.trans henv) (prefixWeight_nonneg ps) + convert hh using 1 + ring + +theorem uniform_compact_correction (ell d eps : ℝ) (hell : 2 ≤ ell) + (hd : 0 < d) (heps : 0 < eps) : + ∃ K B₀ w₀ : ℝ,3 ≤ K ∧ 0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + B^2*|continuousBoundaryCorrection w ell start-compactCorrection K w ell start| ≤ eps := by + obtain ⟨C,c,_wA,hC,hc,_hwA,_hD,hA⟩ := common_anomaly_exponential + obtain ⟨M₀,BT,wT,hBT,hwT,hT⟩ := actual_uniform_original_prime_tail d c (eps/C) hd hc (div_pos heps hC) + let K : ℝ := 3*((M₀:ℝ)+1) + have hK : 3 ≤ K := by dsimp [K]; have hn := Nat.cast_nonneg (α := ℝ) M₀; linarith + refine ⟨K,max BT (max 4 ell),wT,hK,hBT.trans_le (le_max_left _ _),hwT,?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBT' : BT ≤ B := (le_max_left _ _).trans hB + have hB4 : 4 ≤ B := ((le_max_left _ _).trans (le_max_right _ _)).trans hB + have hellB : ell ≤ B := ((le_max_right _ _).trans (le_max_right _ _)).trans hB + have ht := hT M₀ le_rfl B w hBT' hw ell (by linarith) hellB hcomp start hi h199 h23 hcons hcut + have he := compact_correction_error (K := K) (w := w) hA hB4 hell hellB start hi h199 h23 hcons hcut + have heB := mul_le_mul_of_nonneg_left he (sq_nonneg B) + have htC := mul_le_mul_of_nonneg_left ht hC.le + have hcanc : C*(eps/C)=eps := mul_div_cancel₀ eps (ne_of_gt hC) + rw [hcanc] at htC + nlinarith + +end ErdosCorrectionOccupation + +end + +section + +namespace ErdosCorrectionOccupation +open ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.PrimeBinMembership NumberTheoryLean.ActualPrimeHigh +open NumberTheoryLean.OriginalPrimeOccupationLimit +open NumberTheoryLean.CompactLogOccupationTest NumberTheoryLean.NormalizedOccupationLimit + +theorem fixed_compact_correction_limit (K ell d eps : ℝ) (hK : 3 ≤ K) (hell : 2 ≤ ell) + (hd : 0 < d) (heps : 0 < eps) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |(start.gap^2/weight start.side start.ratio)*compactCorrection K w ell start- + invariantAverage (arrivalTest ell (compactAnomalyTest K))| ≤ eps := by + simpa only [compactCorrection] using + literal_original_prime_occupation + (fun i => compactAnomalyTest_continuous K i) + (fun i => compactAnomalyTest_compact K i) + (by norm_num : (0:ℝ)<1) (by linarith : 0 compactAnomalyTest_support K i r s hr) d eps hd heps + +end ErdosCorrectionOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactSmallCountErrors.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactSmallCountErrors.lean new file mode 100644 index 0000000000000000000000000000000000000000..413ba04123d704fdf4215fb97979ccfdb019735a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactSmallCountErrors.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LargeGapCountErrors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CompactSmallCountErrors +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission StrongSourceFamilies +open ActualCountErrorEdges ActualCountErrorMass SourcePrimeProductData +open LogarithmicBinPartition ErdosInverseCounts +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + + +theorem uniform_compact_small_count_errors (K d : ℝ) (hK : 3 ≤ K) (hd : 0 < d) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → + w < top → Real.log B ≤ d*Real.log w → ∀ z : Node, + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ Y : ℕ,0 < Y → ∀ residue : ℕ → ℕ,∀ eps : ℝ,0 ≤ eps → ∀ F : Finset (List ℕ), + F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps∈F,(terminal w z ps).gap ≤ K ∧ + |wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) ps| ≤ eps) → + (B^2/((Y:ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊))*(∑ ps∈F, + |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue ps.prod:ℝ)- + ((Y:ℝ)/(ps.prod:ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊|) ≤ C*eps := by + obtain ⟨C,B₀,W,hC,hB₀,hW,hMass⟩ := uniform_source_family_mass K d hK hd + refine ⟨C,B₀,max W 2,hC,hB₀,hW.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw₀ htop hcomp z hi h199 h23 hz hcut hclosed hpower Y hY residue eps heps F hF hGood + have hw : 1 < w := hW.trans_le ((le_max_left _ _).trans hw₀) + have hw2 : 2 ≤ w := (le_max_right _ _).trans hw₀ + have hV : 0 < SmallSieveFinite.smallEuler ⌊w⌋₊ := + (inv_pos.mpr (zero_lt_one.trans hw)).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2) + have hp : ∀ ps∈F,0 < ps.prod := fun ps hps => (reference_word_product_data hw htop z.side z.gap ps (hF hps)).1 + rw [finite_count_error_weight B Y _ residue _ hY hV F hp] + have he : (∑ ps∈F,prefixWeight ps*|wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue + (SmallSieveFinite.smallEuler ⌊w⌋₊) ps|) ≤ (∑ ps∈F,prefixWeight ps)*eps := by + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro ps hps + exact mul_le_mul_of_nonneg_left (hGood ps hps).2 (prefixWeight_nonneg ps) + have hsum := hMass B w top hB ((le_max_left _ _).trans hw₀) htop hcomp z hi h199 h23 hz hcut hclosed hpower F hF + (fun ps hps => (hGood ps hps).1) + have hh := mul_le_mul_of_nonneg_left he (sq_nonneg B) + have hc := mul_le_mul_of_nonneg_right hsum heps + nlinarith +end NumberTheoryLean.CompactSmallCountErrors + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactTestMeasurable.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactTestMeasurable.lean new file mode 100644 index 0000000000000000000000000000000000000000..0eacf7843bd980a76431f46d27a5bb6a6f007d95 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CompactTestMeasurable.lean @@ -0,0 +1,87 @@ +import Mathlib.MeasureTheory.Integral.Bochner.Basic +import OAI.NumberTheory.Jacobsthal.Partitions.CompactTestGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.CompactTestMeasurable + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open CompactTestGeometry RegeneratingInverseBands ActualCouplingUpdates ArrivalKernelGeometry + +variable {w ell S : ℝ} {start : Node} + +theorem primeTest_measurable (F : Side → ℝ×ℝ → ℝ) : + Measurable (primeTest (w:=w) (ell:=ell) (S:=S) (start:=start) F) := measurable_of_countable _ + +theorem continuousTest_measurable (v : ℝ) (F : Side → ℝ×ℝ → ℝ) (hF : ∀ i,Measurable (F i)) : + Measurable (continuousTest v F) := by + have hcoord : Measurable (fun z : CostState => (gapValue v z,stateRatio z.1)) := + (gapValue_measurable v).prodMk (stateRatio_measurable.comp measurable_fst) + have hside : MeasurableSet {z : CostState | stateSide z.1 = .even} := + measurable_fst (side_set_measurable .even) + have heq : (fun z : CostState => F (stateSide z.1) (gapValue v z,stateRatio z.1)) = + (fun z => if stateSide z.1 = .even then F .even (gapValue v z,stateRatio z.1) + else F .odd (gapValue v z,stateRatio z.1)) := by + funext z + rcases z with ⟨s,t⟩ + cases s <;> rfl + have hb : Measurable (fun z : CostState => F (stateSide z.1) (gapValue v z,stateRatio z.1)) := by + rw [heq] + exact Measurable.ite hside ((hF .even).comp hcoord) ((hF .odd).comp hcoord) + exact hb.sumElim measurable_const + +theorem primeTest_bound {F : Side → ℝ×ℝ → ℝ} {A : ℝ} (hA : 0 ≤ A) + (hF : ∀ i x,|F i x| ≤ A) (z : ChainState w ell S start) : |primeTest F z| ≤ A := by + cases z with + | none => simpa only [primeTest,abs_zero] using hA + | some h => exact hF _ _ + +theorem continuousTest_bound {F : Side → ℝ×ℝ → ℝ} {A : ℝ} (hA : 0 ≤ A) + (hF : ∀ i x,|F i x| ≤ A) (v : ℝ) (z : CemeteryKernel.Space CostState) : + |continuousTest v F z| ≤ A := by + cases z with + | inr u => simpa only [continuousTest,abs_zero] using hA + | inl y => exact hF _ _ + +theorem test_difference_bound {F : Side → ℝ×ℝ → ℝ} {A : ℝ} (hA : 0 ≤ A) + (hF : ∀ i x,|F i x| ≤ A) (v : ℝ) (p : ChainState w ell S start) (z : CemeteryKernel.Space CostState) : + |primeTest F p-continuousTest v F z| ≤ 2*A := by + exact (abs_sub _ _).trans (by linarith [primeTest_bound hA hF p,continuousTest_bound hA hF v z]) + +section Generic +variable {α : Type*} [MeasurableSpace α] {μ : Measure α} + +theorem bounded_integrable [IsFiniteMeasure μ] {f : α → ℝ} (hf : Measurable f) + {A : ℝ} (hb : ∀ x,|f x| ≤ A) : Integrable f μ := by + refine (integrable_const A).mono' hf.aestronglyMeasurable ?_ + exact Filter.Eventually.of_forall (fun x => by simpa only [Real.norm_eq_abs] using hb x) + +theorem integral_difference_enorm {f g : α → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) : + ENNReal.ofReal |(∫ x,f x ∂μ)-(∫ x,g x ∂μ)| ≤ ∫⁻ x,ENNReal.ofReal |f x-g x| ∂μ := by + rw [← integral_sub hf hg] + simpa only [Real.enorm_eq_ofReal_abs] using enorm_integral_le_lintegral_enorm (fun x => f x-g x) + +theorem finite_integral_difference (μ : ℕ → Measure α) (f g : α → ℝ) (N : ℕ) + (hf : ∀ n ∈ range N,Integrable f (μ n)) (hg : ∀ n ∈ range N,Integrable g (μ n)) : + ENNReal.ofReal |(∑ n ∈ range N,∫ x,f x ∂μ n)-(∑ n ∈ range N,∫ x,g x ∂μ n)| ≤ + ∑ n ∈ range N,∫⁻ x,ENNReal.ofReal |f x-g x| ∂μ n := by + rw [← Finset.sum_sub_distrib] + refine (ENNReal.ofReal_le_ofReal (Finset.abs_sum_le_sum_abs _ _)).trans ?_ + rw [ENNReal.ofReal_sum_of_nonneg (fun _ _ => abs_nonneg _)] + exact Finset.sum_le_sum (fun n hn => integral_difference_enorm (hf n hn) (hg n hn)) +end Generic + +end NumberTheoryLean.CompactTestMeasurable + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousCorrectionLimit.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousCorrectionLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..59023dd0f196ffb7bc055ea6f3538c85b21d0e49 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousCorrectionLimit.lean @@ -0,0 +1,252 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.BoundaryRadialCoefficient +import OAI.NumberTheory.Jacobsthal.Estimates.CorrectionStateSections +import OAI.NumberTheory.Jacobsthal.Estimates.CorrectionUniformTruncation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.MeasureTheory +open scoped Interval +namespace ErdosBoundaryIntegral +open ErdosContinuousAnomaly + +theorem even_ratio_integral (r : ℝ) : (∫ _t : ℝ in 2..r/2,1)=r/2-2 := by simp + +theorem odd_ratio_integral {r : ℝ} (hr : 2 ≤ r) : + (∫ t : ℝ in 1..r/2,(1-(t^2)⁻¹))=r/2+2/r-2 := by + have hab : (1:ℝ) ≤ r/2 := by linarith + have hn : ∀ t ∈ uIcc (1:ℝ) (r/2),t ≠ 0 := by + intro t ht + rw [uIcc_of_le hab] at ht + have hh := ht.1 + linarith + have hd : ∀ t ∈ uIcc (1:ℝ) (r/2), + HasDerivAt (fun x : ℝ => x+x⁻¹) (1-(t^2)⁻¹) t := by + intro t ht + convert! (hasDerivAt_id t).add (hasDerivAt_inv (hn t ht)) using 1 + have hc : ContinuousOn (fun t : ℝ => 1-(t^2)⁻¹) (uIcc (1:ℝ) (r/2)) := + continuousOn_const.sub ((continuous_id.pow 2).continuousOn.inv₀ (by + intro t ht; exact pow_ne_zero 2 (hn t ht))) + have hi := hc.intervalIntegrable (μ := volume) + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt hd hi + rw [h] + simp only [inv_one] + have hr0 : r ≠ 0 := by linarith + field_simp + ring + +theorem nested_ratio_coefficient_eq_twice_I : + ((∫ r in Ioi 4,r*continuousAnomaly .even r*(∫ _t : ℝ in 2..r/2,1))- + ∫ r in Ioi 2,r*continuousAnomaly .odd r*(∫ t : ℝ in 1..r/2,(1-(t^2)⁻¹)))= + 2*signedCoefficientI := by + have he : (∫ r in Ioi 4,r*continuousAnomaly .even r*(∫ _t : ℝ in 2..r/2,1))= + ∫ r in Ioi 4,r*(r/2-2)*continuousAnomaly .even r := by + apply setIntegral_congr_fun measurableSet_Ioi + intro r _hr + dsimp only + rw [even_ratio_integral] + ring + have ho : (∫ r in Ioi 2,r*continuousAnomaly .odd r*(∫ t : ℝ in 1..r/2,(1-(t^2)⁻¹)))= + ∫ r in Ioi 2,(r^2/2-2*r+2)*continuousAnomaly .odd r := by + apply setIntegral_congr_fun measurableSet_Ioi + intro r hr + have hr2 : 2 < r := hr + dsimp only + rw [odd_ratio_integral hr2.le] + have hr0 : r ≠ 0 := by linarith + field_simp + ring + rw [he,ho] + exact radial_coefficient_eq_twice_I + +end ErdosBoundaryIntegral + +end + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology ENNReal +namespace ErdosCorrectionLimit +open ErdosContinuousAnomaly ErdosBoundaryIntegral +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeOccupationDensity +open NumberTheoryLean.OccupationDensityIntegral +open Erdos970Dependency.InvariantCostBound + +theorem anomaly_moment_integrable (i : Side) (n : ℕ) : + IntegrableOn (fun r : ℝ => r^n*continuousAnomaly i r) (Ioi 2) := by + obtain ⟨C,c,_w,hC,hc,_hw,_hd,ha⟩ := common_anomaly_exponential + have hg : IntegrableOn (fun r : ℝ => r^n*Real.exp (-c*r)) (Ioi 0) := by + have h := integrableOn_rpow_mul_exp_neg_mul_rpow (s := (n:ℝ)) (p := 1) + (by have hn := Nat.cast_nonneg (α := ℝ) n; linarith) (by norm_num) hc + simpa only [Real.rpow_natCast,Real.rpow_one] using! h + have hm : ContinuousOn (fun r : ℝ => r^n*continuousAnomaly i r) (Ioi 2) := + (continuous_id.pow n).continuousOn.mul ((continuousAnomaly_continuousOn i).mono Ioi_subset_Ici_self) + apply ((hg.mono_set (Ioi_subset_Ioi (by norm_num : (0:ℝ)≤2))).const_mul C).mono' + (hm.aestronglyMeasurable measurableSet_Ioi) + filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr + have hr2 : 2 < r := hr + change ‖r^n*continuousAnomaly i r‖ ≤ C*(r^n*Real.exp (-c*r)) + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (pow_nonneg (by linarith) n)] + have hb := mul_le_mul_of_nonneg_left (ha r hr2.le i) (pow_nonneg (by linarith : 0≤r) n) + nlinarith + +theorem exp_cutoff_integral {a : ℝ} (ha : 0 < a) (g : ℝ → ℝ) : + ((∫ u : ℝ,if a < Real.exp u then Real.exp u*g (Real.exp u) else 0)=∫ r in Ioi a,g r) ∧ + (Integrable (fun u : ℝ => if a < Real.exp u then Real.exp u*g (Real.exp u) else 0) ↔ + IntegrableOn g (Ioi a)) := by + have him : Real.exp '' Ioi (Real.log a)=Ioi a := by + ext r + constructor + · rintro ⟨u,hu,rfl⟩ + exact (Real.log_lt_iff_lt_exp ha).mp hu + · intro hr + have hra : a < r := hr + have hr0 : 0 < r := ha.trans hra + exact ⟨Real.log r,Real.log_lt_log ha hra,Real.exp_log hr0⟩ + have hd : ∀ u ∈ Ioi (Real.log a), HasDerivWithinAt Real.exp (Real.exp u) (Ioi (Real.log a)) u := + fun u _ => (Real.hasDerivAt_exp u).hasDerivWithinAt + have hf : (fun u : ℝ => if a < Real.exp u then Real.exp u*g (Real.exp u) else 0)= + (Ioi (Real.log a)).indicator (fun u => Real.exp u*g (Real.exp u)) := by + funext u + simp only [indicator_apply,mem_Ioi,Real.log_lt_iff_lt_exp ha] + constructor + · rw [hf,integral_indicator measurableSet_Ioi] + have hh := integral_image_eq_integral_abs_deriv_smul measurableSet_Ioi hd Real.exp_injective.injOn g + simpa only [him,abs_of_pos (Real.exp_pos _),smul_eq_mul] using! hh.symm + · rw [hf,integrable_indicator_iff measurableSet_Ioi] + have hh := integrableOn_image_iff_integrableOn_abs_deriv_smul measurableSet_Ioi hd Real.exp_injective.injOn g + simpa only [him,abs_of_pos (Real.exp_pos _),smul_eq_mul] using! hh.symm + +noncomputable def evenRadial (r : ℝ) : ℝ := r*(r/2-2)*continuousAnomaly .even r +noncomputable def oddRadial (r : ℝ) : ℝ := (r^2/2-2*r+2)*continuousAnomaly .odd r + +theorem radial_parts_integrable : IntegrableOn evenRadial (Ioi 4) ∧ IntegrableOn oddRadial (Ioi 2) := by + have h1 (i : Side) : IntegrableOn (fun r : ℝ => r*continuousAnomaly i r) (Ioi 2) := by + simpa only [pow_one] using anomaly_moment_integrable i 1 + have h0 (i : Side) : IntegrableOn (continuousAnomaly i) (Ioi 2) := by + simpa only [pow_zero,one_mul] using anomaly_moment_integrable i 0 + constructor + · have hh : IntegrableOn (fun r : ℝ => (r^2*continuousAnomaly .even r)/2-2*(r*continuousAnomaly .even r)) (Ioi 2) := + ((anomaly_moment_integrable .even 2).div_const 2).sub ((h1 .even).const_mul 2) + apply (hh.mono_set (Ioi_subset_Ioi (by norm_num : (2:ℝ)≤4))).congr_fun _ measurableSet_Ioi + intro r _ + dsimp only [evenRadial] + ring + · have hh : IntegrableOn (fun r : ℝ => ((r^2*continuousAnomaly .odd r)/2-2*(r*continuousAnomaly .odd r))+2*continuousAnomaly .odd r) (Ioi 2) := + (((anomaly_moment_integrable .odd 2).div_const 2).sub ((h1 .odd).const_mul 2)).add ((h0 .odd).const_mul 2) + apply hh.congr_fun _ measurableSet_Ioi + intro r _ + dsimp only [oddRadial] + ring + +theorem full_limiting_integral_eq : + (∫ x,rawTest fullAnomalyTest x ∂limitingMeasure 2)=2*signedCoefficientI/costMass := by + have he := exp_cutoff_integral (by norm_num : (0:ℝ)<4) evenRadial + have ho := exp_cutoff_integral (by norm_num : (0:ℝ)<2) oddRadial + have hie := he.2.mpr radial_parts_integrable.1 + have hio := ho.2.mpr radial_parts_integrable.2 + rw [full_limiting_integral_fubini] + simp_rw [fullWeighted_section_radial] + have hfun : (fun u : ℝ => Real.exp u/costMass*radialNumerator (Real.exp u))= + (fun u => ((if 4 < Real.exp u then Real.exp u*evenRadial (Real.exp u) else 0)- + (if 2 < Real.exp u then Real.exp u*oddRadial (Real.exp u) else 0))/costMass) := by + funext u + unfold radialNumerator evenRadial oddRadial + split_ifs <;> ring + rw [hfun,integral_div,integral_sub hie hio,he.1,ho.1] + have hh : (∫ r in Ioi 4,evenRadial r)-(∫ r in Ioi 2,oddRadial r)=2*signedCoefficientI := + radial_coefficient_eq_twice_I + rw [hh] + +end ErdosCorrectionLimit + +end + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology +namespace ErdosCorrectionLimit +open ErdosCorrectionOccupation ErdosContinuousAnomaly ErdosBoundaryIntegral +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.CompactLogOccupationTest NumberTheoryLean.NormalizedOccupationLimit +open NumberTheoryLean.PrimeBinMembership +open NumberTheoryLean.SourceNodeCoordinates NumberTheoryLean.SourceLowRemoval +open Erdos970Dependency.InvariantCostBound + +theorem compact_invariant_coefficient_tendsto : + Tendsto (fun K : ℝ => invariantAverage (arrivalTest 2 (compactAnomalyTest K))) atTop + (𝓝 (2*signedCoefficientI/costMass)) := by + simpa only [full_limiting_integral_eq] using compact_invariant_tendsto + +theorem full_continuous_correction_limit (d eps : ℝ) (hd : 0 < d) (heps : 0 < eps) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |(start.gap^2/weight start.side start.ratio)*continuousBoundaryCorrection w 2 start- + 2*signedCoefficientI/costMass| ≤ eps := by + have he3 : 0 < eps/3 := by linarith + obtain ⟨Kmin,hKmin⟩ := eventually_atTop.mp + (compact_invariant_coefficient_tendsto.eventually + (Metric.ball_mem_nhds (2*signedCoefficientI/costMass) he3)) + obtain ⟨K,BT,wT,hK,hKK,hBT,hwT,hT⟩ := + uniform_compact_correction_above Kmin 2 d (eps/(3*scaleConstant)) + le_rfl hd (div_pos heps (mul_pos (by norm_num) scaleConstant_pos)) + obtain ⟨BF,wF,hBF,hwF,hF⟩ := fixed_compact_correction_limit K 2 d (eps/3) hK le_rfl hd he3 + refine ⟨max BT BF,max wT wF,hBT.trans_le (le_max_left _ _),hwT.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBT' : BT ≤ B := (le_max_left _ _).trans hB + have hBF' : BF ≤ B := (le_max_right _ _).trans hB + have hwT' : wT ≤ w := (le_max_left _ _).trans hw + have hwF' : wF ≤ w := (le_max_right _ _).trans hw + have hBpos : 0 < B := hBT.trans_le hBT' + have ht := hT B w hBT' hwT' hcomp start hi h199 h23 hcons hcut + have hf := hF B w hBF' hwF' hcomp start hi h199 h23 hcons hcut + have hk : |invariantAverage (arrivalTest 2 (compactAnomalyTest K))-2*signedCoefficientI/costMass| < eps/3 := by + simpa only [Metric.mem_ball,Real.dist_eq] using hKmin K hKK + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hn : 0 ≤ start.gap^2/weight start.side start.ratio := div_nonneg (sq_nonneg _) (weight_pos hs).le + have hscale := node_scale_upper hBpos start hi h199 h23 hcons hcut + have herr : |(start.gap^2/weight start.side start.ratio)* + (continuousBoundaryCorrection w 2 start-compactCorrection K w 2 start)| ≤ eps/3 := by + rw [abs_mul,abs_of_nonneg hn] + have hh := mul_le_mul_of_nonneg_right hscale + (abs_nonneg (continuousBoundaryCorrection w 2 start-compactCorrection K w 2 start)) + have ht' := mul_le_mul_of_nonneg_left ht scaleConstant_pos.le + have hcancel : scaleConstant*(eps/(3*scaleConstant))=eps/3 := by + field_simp [scaleConstant_pos.ne'] + rw [hcancel] at ht' + nlinarith + have hsum := abs_add_le ((start.gap^2/weight start.side start.ratio)* + (continuousBoundaryCorrection w 2 start-compactCorrection K w 2 start)) + ((start.gap^2/weight start.side start.ratio)*compactCorrection K w 2 start- + invariantAverage (arrivalTest 2 (compactAnomalyTest K))) + have hsum' := abs_add_le + (((start.gap^2/weight start.side start.ratio)* + (continuousBoundaryCorrection w 2 start-compactCorrection K w 2 start))+ + ((start.gap^2/weight start.side start.ratio)*compactCorrection K w 2 start- + invariantAverage (arrivalTest 2 (compactAnomalyTest K)))) + (invariantAverage (arrivalTest 2 (compactAnomalyTest K))-2*signedCoefficientI/costMass) + have heq : ((start.gap^2/weight start.side start.ratio)* + (continuousBoundaryCorrection w 2 start-compactCorrection K w 2 start))+ + ((start.gap^2/weight start.side start.ratio)*compactCorrection K w 2 start- + invariantAverage (arrivalTest 2 (compactAnomalyTest K)))+ + (invariantAverage (arrivalTest 2 (compactAnomalyTest K))-2*signedCoefficientI/costMass)= + (start.gap^2/weight start.side start.ratio)*continuousBoundaryCorrection w 2 start- + 2*signedCoefficientI/costMass := by ring + rw [heq] at hsum' + linarith + +end ErdosCorrectionLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousHighRemoval.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousHighRemoval.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2b6395e902401a5d179f2f12708cd7fa57faf7b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousHighRemoval.lean @@ -0,0 +1,119 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LogSquaredDecay +import OAI.NumberTheory.Jacobsthal.Paths.HighPrefixBounds + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosPrimeInputs.ContinuousHighRemoval + +open Filter +open scoped ENNReal Topology +open HighPrefixBounds LogSquaredDecay + +lemma tail_coefficient_eq (ell B : ℝ) (m : ℕ) : + ((2:ℝ≥0∞)⁻¹)^m*ENNReal.ofReal ((B/ell)^2) = + ENNReal.ofReal ((1/2:ℝ)^m*(B/ell)^2) := by + have hh : (2:ℝ≥0∞)⁻¹=ENNReal.ofReal (1/2:ℝ) := by + rw [one_div,ENNReal.ofReal_inv_of_pos (by norm_num : (0:ℝ)<2)] + norm_num + rw [hh,← ENNReal.ofReal_pow (by norm_num : (0:ℝ)≤1/2), + ← ENNReal.ofReal_mul (pow_nonneg (by norm_num : (0:ℝ)≤1/2) m)] + +lemma tail_coefficient_bound {ell B : ℝ} (hell : 1≤ell) (hB : ell≤B) : + ((2:ℝ≥0∞)⁻¹)^⌊(Real.log B)^2/2⌋₊ * ENNReal.ofReal ((B/ell)^2) ≤ + ENNReal.ofReal (2*B^2*Real.exp (-Real.log 2*((Real.log B)^2/2))) := by + rw [tail_coefficient_eq] + apply ENNReal.ofReal_le_ofReal + have hB0 : 0≤B := zero_le_one.trans (hell.trans hB) + have hell0 : 0 ∑ n ∈ Finset.range N,(-1:ℝ)^n*boundaryTerm n j s t) i r b=_ + rw [gate_sum N (fun n j s t => (-1:ℝ)^n*boundaryTerm n j s t) + (fun n j => continuous_const.mul (boundaryTerm_continuous n j))] + apply Finset.sum_congr rfl + intro n _hn + rw [gate_mul] + rfl + +theorem truncatedReference_recurrence (N : ℕ) (i : Side) (r b : ℝ) : + truncatedReference (N+1) i r b=1-gate (truncatedReference N) i r b := by + have hfirst : truncatedReference (N+1) i r b= + (∑ n ∈ Finset.range N,(-1:ℝ)^(n+1)*boundaryTerm (n+1) i r b)+1 := by + rw [truncatedReference,Finset.sum_range_succ'] + simp only [pow_zero,show boundaryTerm 0 i r b=(1:ℝ) by rfl,one_mul] + have hs (n : ℕ) : (-1:ℝ)^(n+1)*boundaryTerm (n+1) i r b= + -((-1:ℝ)^n*boundaryTerm (n+1) i r b) := by rw [pow_succ]; ring + rw [hfirst] + simp_rw [hs] + rw [Finset.sum_neg_distrib,← gate_truncatedReference] + ring + +theorem boundaryReference_recurrence (i : Side) (r b : ℝ) : + boundaryReference i r b=1-gate boundaryReference i r b := by + let N := referenceDepth r + have hN : 2 ≤ N := (referenceDepth_bounds r).1 + have hrN : r ≤ (N:ℝ)-1 := (referenceDepth_bounds r).2 + have hq : boundaryReference i r b=truncatedReference (N+1) i r b := + boundaryReference_eq_truncated (N+1) (by omega) i (by push_cast; linarith) + have hchild : gate boundaryReference i r b=gate (truncatedReference N) i r b := by + unfold gate + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (upperCutoff_bounds i r b).1] at hx + dsimp only + rw [boundaryReference_eq_truncated N hN i.flip (by linarith [hx.1] : r-x ≤ (N:ℝ)-1)] + rw [hq,truncatedReference_recurrence,← hchild] + +end ErdosContinuousOmission + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousReference.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..56ff66ebc2c954e356d4c8856ca267167055397e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ContinuousReference.lean @@ -0,0 +1,82 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.BoundaryGateSets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.MeasureTheory _root_.Set _root_.Filter +open scoped Topology +namespace ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry + +noncomputable def truncatedReference (N : ℕ) (i : Side) (r b : ℝ) : ℝ := + ∑ n ∈ Finset.range N,(-1:ℝ)^n*boundaryTerm n i r b + +theorem boundaryTerm_zero_of_index (n : ℕ) (hn : 2 ≤ n) (i : Side) {r b : ℝ} + (hr : r ≤ (n:ℝ)-1) : boundaryTerm n i r b=0 := by + have he : n=(n-2)+2 := by omega + rw [he] + apply boundaryTerm_depth_zero + have hc : ((n-2:ℕ):ℝ)=(n:ℝ)-2 := by rw [Nat.cast_sub hn]; norm_num + linarith + +theorem truncatedReference_stable {N M : ℕ} (hN : 2 ≤ N) (hNM : N ≤ M) + (i : Side) {r b : ℝ} (hr : r ≤ (N:ℝ)-1) : + truncatedReference N i r b=truncatedReference M i r b := by + unfold truncatedReference + apply Finset.sum_subset (Finset.range_mono hNM) + intro n _hnM hnN + have hNn : N ≤ n := le_of_not_gt (by simpa only [Finset.mem_range] using hnN) + have hrn : r ≤ (n:ℝ)-1 := hr.trans (sub_le_sub_right (by exact_mod_cast hNn) 1) + rw [boundaryTerm_zero_of_index n (hN.trans hNn) i hrn,mul_zero] + +noncomputable def referenceDepth (r : ℝ) : ℕ := ⌈max r 0⌉₊+3 + +theorem referenceDepth_bounds (r : ℝ) : 2 ≤ referenceDepth r ∧ r ≤ (referenceDepth r : ℝ)-1 := by + have h := Nat.le_ceil (max r 0) + have hr : r ≤ max r 0 := le_max_left _ _ + unfold referenceDepth + constructor + · omega + · push_cast + linarith + +noncomputable def boundaryReference (i : Side) (r b : ℝ) : ℝ := + truncatedReference (referenceDepth r) i r b + +theorem boundaryReference_eq_truncated (N : ℕ) (hN : 2 ≤ N) (i : Side) + {r b : ℝ} (hr : r ≤ (N:ℝ)-1) : boundaryReference i r b=truncatedReference N i r b := by + unfold boundaryReference + rcases le_total (referenceDepth r) N with h | h + · exact truncatedReference_stable (referenceDepth_bounds r).1 h i (referenceDepth_bounds r).2 + · exact (truncatedReference_stable hN h i hr).symm + +theorem truncatedReference_continuous (N : ℕ) (i : Side) : + Continuous (fun p : ℝ×ℝ => truncatedReference N i p.1 p.2) := by + apply continuous_finsetSum + intro n _hn + exact continuous_const.mul (boundaryTerm_continuous n i) + +theorem boundaryReference_continuous (i : Side) : + Continuous (fun p : ℝ×ℝ => boundaryReference i p.1 p.2) := by + apply continuous_iff_continuousAt.mpr + intro p + let N := referenceDepth (p.1+1) + have hc := (truncatedReference_continuous N i).continuousAt (x:=p) + apply hc.congr_of_eventuallyEq + have he : ∀ᶠ q : ℝ×ℝ in 𝓝 p,q.1 < p.1+1 := + continuous_fst.continuousAt.preimage_mem_nhds (Iio_mem_nhds (by linarith : p.1 < p.1+1)) + filter_upwards [he] with q hq + exact boundaryReference_eq_truncated N (referenceDepth_bounds (p.1+1)).1 i + (hq.le.trans (referenceDepth_bounds (p.1+1)).2) + +end ErdosContinuousBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/CorrectedCompactTransfer.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CorrectedCompactTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee2960495a8b3ad6acef56e726c72d394d6028b1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CorrectedCompactTransfer.lean @@ -0,0 +1,446 @@ +import Mathlib.Analysis.Normed.Group.Bounded +import Mathlib.Topology.UniformSpace.HeineCantor +import OAI.NumberTheory.Jacobsthal.Paths.FlaggedHarmonicTransform +import OAI.NumberTheory.Jacobsthal.Probability.SourceCompactCoupling + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SignedCompactTransfer + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open CompactTestGeometry CompactTestMeasurable CompactCouplingError SourceCompactCoupling +open ActualProcessCoupling PersistentFailureFlag ContinuousKilledBins LowStateHorizon +open ExponentialMesh UniformBudgetRate + +noncomputable def primeExpectation (F : Side → ℝ×ℝ → ℝ) (w ell S : ℝ) (start : Node) (N : ℕ) : ℝ := + ∑ n ∈ range N,∫ z,primeTest F z ∂pathLaw w ell S start n + +noncomputable def continuousExpectation (F : Side → ℝ×ℝ → ℝ) (v ell S : ℝ) (z : CostState) (N : ℕ) : ℝ := + ∑ n ∈ range N,∫ y,continuousTest v F y ∂((continuousChain v ell S)^n) (.inl z) + +variable {w ell S : ℝ} {start : Node} +variable (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) + +include hw hell hS0 hS hr hsS in +theorem actual_signed_difference (F : Side → ℝ×ℝ → ℝ) (hF : ∀ i,Measurable (F i)) + {A : ℝ} (hA : 0 ≤ A) (hbound : ∀ i x,|F i x| ≤ A) (mesh : ℝ) (N : ℕ) : + ENNReal.ofReal |primeExpectation F w ell S start N- + continuousExpectation F (Real.log start.gap) ell S (FlaggedSourceStart.sourceCostState hs) N| ≤ + ∑ n ∈ range N,∫⁻ q,difference (Real.log start.gap) F q ∂CouplingData.sourceLaw w ell S start hs mesh n := by + let μ := fun n => CouplingData.sourceLaw w ell S start hs mesh n + let P := fun q : FlagState (JointState w ell S start) => primeTest F q.1.1 + let Q := fun q : FlagState (JointState w ell S start) => continuousTest (Real.log start.gap) F q.1.2 + have hP : Measurable P := (primeTest_measurable F).comp (measurable_fst.comp measurable_fst) + have hQ : Measurable Q := (continuousTest_measurable _ F hF).comp (measurable_snd.comp measurable_fst) + have hIP : ∀ n ∈ range N,Integrable P (μ n) := by + intro n _hn + let := CouplingData.source_probability hw hell hS0 hS hr hs hsS mesh n + exact bounded_integrable hP (fun q => primeTest_bound hA hbound q.1.1) + have hIQ : ∀ n ∈ range N,Integrable Q (μ n) := by + intro n _hn + let := CouplingData.source_probability hw hell hS0 hS hr hs hsS mesh n + exact bounded_integrable hQ (fun q => continuousTest_bound hA hbound _ q.1.2) + have hp : primeExpectation F w ell S start N = ∑ n ∈ range N,∫ q,P q ∂μ n := by + apply Finset.sum_congr rfl + intro n _hn + rw [← CouplingData.source_prime hw hell hS0 hS hr hs hsS mesh n, + integral_map (φ:=fun q : FlagState (JointState w ell S start) => q.1.1) + (measurable_fst.comp measurable_fst).aemeasurable (primeTest_measurable F).aestronglyMeasurable] + have hq : continuousExpectation F (Real.log start.gap) ell S (FlaggedSourceStart.sourceCostState hs) N = + ∑ n ∈ range N,∫ q,Q q ∂μ n := by + apply Finset.sum_congr rfl + intro n _hn + have he := FlaggedSourceStart.sourceLaw_continuous hw hell hS0 hS hr hs hsS mesh n + rw [CouplingData.sourceLaw_eq hw hell hS0 hS hr hs hsS] at he + rw [← he,integral_map (φ:=fun q : FlagState (JointState w ell S start) => q.1.2) + (measurable_snd.comp measurable_fst).aemeasurable (continuousTest_measurable _ F hF).aestronglyMeasurable] + rw [hp,hq] + exact finite_integral_difference μ P Q N hIP hIQ + +theorem source_signed_compact_transfer (F : Side → ℝ×ℝ → ℝ) + (hF : ∀ i,UniformContinuous (F i)) {K A : ℝ} (hK : 0 ≤ K) (hA : 0 ≤ A) + (hbound : ∀ i x,|F i x| ≤ A) (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → F i (r,s)=0) + (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.gap ≤ (23/10:ℝ)*B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + |primeExpectation F w ell S start N- + continuousExpectation F (Real.log start.gap) ell S (FlaggedSourceStart.sourceCostState hs) N| ≤ ε := by + obtain ⟨κ₀,hκ₀,hcouple⟩ := source_compact_coupling F hF hK hA hbound hsupport + let κ := κ₀/2 + have hκ : 0 < κ := by dsimp [κ]; positivity + obtain ⟨wP,hwP,hcouple⟩ := hcouple κ hκ (by dsimp [κ]; linarith) d ε hd hε + obtain ⟨wScale,hwScale⟩ := eventually_atTop.mp + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + refine ⟨max wP (max normalizationThreshold wScale),hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hB hlogB hcomp hr h23 hcons hsize + dsimp only + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hscale := source_scale_bound + (hwScale w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw)) hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hdiff := actual_signed_difference hnorm hell hS0 hscale.1 hr hs hsS F + (fun i => (hF i).continuous.measurable) hA hbound (mesh κ w) N + have hsmall := hcouple w ((le_max_left _ _).trans hw) ell B start hs hell hB hlogB hcomp hr h23 hcons hsize + exact (ENNReal.ofReal_le_ofReal_iff hε.le).mp (hdiff.trans hsmall) + +end NumberTheoryLean.SignedCompactTransfer + +end + +section + +namespace NumberTheoryLean.CompactInverseTest + +open _root_.Set +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open DerivativeWeights CompactTestGeometry SignedCompactTransfer InvariantInverseWeights + +noncomputable def lowerRatio : Side → ℝ | .even => 198/100 | .odd => 95/100 + +theorem valid_lower (i : Side) (s : ℝ) : Valid i s ↔ lowerRatio i ≤ s := by cases i <;> rfl + +noncomputable def safeWeight (i : Side) (s : ℝ) : ℝ := weight i (max (lowerRatio i) s) + +theorem safeWeight_pos (i : Side) (s : ℝ) : 0 < safeWeight i s := + weight_pos ((valid_lower _ _).mpr (le_max_left _ _)) + +theorem safeWeight_eq {i : Side} {s : ℝ} (hs : Valid i s) : safeWeight i s = weight i s := by + unfold safeWeight + rw [max_eq_right ((valid_lower _ _).mp hs)] + +theorem safeWeight_continuous (i : Side) : Continuous (safeWeight i) := by + cases i with + | even => + apply continuous_iff_continuousAt.mpr + intro x + have hx : 1 < max (198/100:ℝ) x := lt_of_lt_of_le (by norm_num) (le_max_left _ _) + exact (phiEven_continuousAt hx).comp (continuous_const.max continuous_id).continuousAt + | odd => exact phiOdd_continuous.comp (continuous_const.max continuous_id) + +noncomputable def inverseTest (H : Side → ℝ×ℝ → ℝ) (i : Side) (x : ℝ×ℝ) : ℝ := + x.1^2*H i x/safeWeight i x.2 + +theorem inverseTest_continuous {H : Side → ℝ×ℝ → ℝ} (hH : ∀ i,Continuous (H i)) (i : Side) : + Continuous (inverseTest H i) := + ((continuous_fst.pow 2).mul (hH i)).div ((safeWeight_continuous i).comp continuous_snd) + (fun x => (safeWeight_pos i x.2).ne') + +theorem inverseTest_compact {H : Side → ℝ×ℝ → ℝ} (hH : ∀ i,HasCompactSupport (H i)) (i : Side) : + HasCompactSupport (inverseTest H i) := by + have he : inverseTest H i = (fun x : ℝ×ℝ => x.1^2/safeWeight i x.2)*(H i) := by + funext x + dsimp [inverseTest] + ring + rw [he] + exact (hH i).mul_left + +theorem inverseTest_uniform {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) : + ∀ i,UniformContinuous (inverseTest H i) := fun i => + (inverseTest_compact hcompact i).uniformContinuous_of_continuous (inverseTest_continuous hH i) + +theorem inverseTest_bounded {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) : + ∃ A : ℝ,0 ≤ A ∧ ∀ i x,|inverseTest H i x| ≤ A := by + obtain ⟨Ae,he⟩ := (inverseTest_continuous hH .even).bounded_above_of_compact_support (inverseTest_compact hcompact .even) + obtain ⟨Ao,ho⟩ := (inverseTest_continuous hH .odd).bounded_above_of_compact_support (inverseTest_compact hcompact .odd) + refine ⟨max 0 (max Ae Ao),le_max_left _ _,?_⟩ + intro i x + cases i with + | even => + have hx : |inverseTest H .even x| ≤ Ae := by simpa only [Real.norm_eq_abs] using he x + exact hx.trans ((le_max_left _ _).trans (le_max_right _ _)) + | odd => + have hx : |inverseTest H .odd x| ≤ Ao := by simpa only [Real.norm_eq_abs] using ho x + exact hx.trans ((le_max_right _ _).trans (le_max_right _ _)) + +theorem inverseTest_gap_support {H : Side → ℝ×ℝ → ℝ} {K : ℝ} + (hH : ∀ i : Side,∀ r s : ℝ,K < r → H i (r,s)=0) : + ∀ i : Side,∀ r s : ℝ,K < r → inverseTest H i (r,s)=0 := by + intro i r s hr + simp [inverseTest,hH i r s hr] + +theorem inverseTest_eq {H : Side → ℝ×ℝ → ℝ} {i : Side} {r s : ℝ} (hs : Valid i s) : + inverseTest H i (r,s) = r^2*H i (r,s)/weight i s := by + simp only [inverseTest,safeWeight_eq hs] + +theorem prime_inverseTest_eq {w ell S : ℝ} {start : Node} {H : Side → ℝ×ℝ → ℝ} + (hs : Valid start.side start.ratio) (h : History w ell S start) : + primeTest (inverseTest H) (some h) = + h.node.gap^2*H h.node.side (h.node.gap,h.node.ratio)/weight h.node.side h.node.ratio := + inverseTest_eq (terminal_valid hs h.admissible) + +end NumberTheoryLean.CompactInverseTest + +end + +section + +namespace NumberTheoryLean.CompactNormalizationCorrection + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeCompactVisits +open CompactTestGeometry CompactTestMeasurable SignedCompactTransfer PrimeCorrectionFactor + +variable {w ell S : ℝ} {start : Node} + +noncomputable def correctedTest (F : Side → ℝ×ℝ → ℝ) : ChainState w ell S start → ℝ + | none => 0 + | some h => (1+epsilon w)^h.primes.length*F h.node.side (h.node.gap,h.node.ratio) + +noncomputable def correctedExpectation (F : Side → ℝ×ℝ → ℝ) (w ell S : ℝ) (start : Node) (N : ℕ) : ℝ := + ∑ n ∈ range N,∫ z,correctedTest F z ∂pathLaw w ell S start n + +theorem correctedTest_measurable (F : Side → ℝ×ℝ → ℝ) : + Measurable (correctedTest (w:=w) (ell:=ell) (S:=S) (start:=start) F) := measurable_of_countable _ + +theorem correction_difference_bound {d w ell B K A : ℝ} {start : Node} + (F : Side → ℝ×ℝ → ℝ) (_hA : 0 ≤ A) (hbound : ∀ i x,|F i x| ≤ A) + (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → F i (r,s)=0) + (hlogB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) (hell : 1 ≤ ell) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) + (z : ChainState w ell ((Real.log B)^2) start) : + |correctedTest F z-primeTest F z| ≤ (correctionBudget d w*A)*visit K z := by + cases z with + | none => simp [correctedTest,primeTest,visit] + | some h => + have hc := history_correction hlogB hcomp hell hr hs hB hsize h + by_cases hh : h.node.gap ≤ K + · have hnon : 0 ≤ (1+epsilon w)^h.primes.length-1 := hc.1 + change |(1+epsilon w)^h.primes.length*F h.node.side (h.node.gap,h.node.ratio)-F h.node.side (h.node.gap,h.node.ratio)| ≤ _ + rw [show (1+epsilon w)^h.primes.length*F h.node.side (h.node.gap,h.node.ratio)-F h.node.side (h.node.gap,h.node.ratio) = + ((1+epsilon w)^h.primes.length-1)*F h.node.side (h.node.gap,h.node.ratio) by ring, + abs_mul,abs_of_nonneg hnon] + simp only [visit,ite_eq_left hh,mul_one] + exact mul_le_mul hc.2 (hbound _ _) (abs_nonneg _) ((hnon.trans hc.2)) + · have hf := hsupport h.node.side h.node.gap h.node.ratio (lt_of_not_ge hh) + simp [correctedTest,primeTest,visit,hf,hh] + +theorem correctedTest_bound {d w ell B A : ℝ} {start : Node} + (F : Side → ℝ×ℝ → ℝ) (hA : 0 ≤ A) (hbound : ∀ i x,|F i x| ≤ A) + (hlogB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) (hell : 1 ≤ ell) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) + (z : ChainState w ell ((Real.log B)^2) start) : + |correctedTest F z| ≤ (1+correctionBudget d w)*A := by + have he := history_correction hlogB hcomp hell hr hs hB hsize (History.empty : History w ell ((Real.log B)^2) start) + have hb0 : 0 ≤ correctionBudget d w := by simpa only [History.empty,List.length_nil,pow_zero,sub_self] using he.2 + cases z with + | none => change |(0:ℝ)| ≤ _; rw [abs_zero]; positivity + | some h => + have hc := history_correction hlogB hcomp hell hr hs hB hsize h + have hpow : 0 ≤ (1+epsilon w)^h.primes.length := pow_nonneg (normalizer_pos w).le _ + change |(1+epsilon w)^h.primes.length*F h.node.side (h.node.gap,h.node.ratio)| ≤ _ + rw [abs_mul,abs_of_nonneg hpow] + exact mul_le_mul (by linarith : (1+epsilon w)^h.primes.length ≤ 1+correctionBudget d w) + (hbound _ _) (abs_nonneg _) (by linarith) + +theorem actual_compact_correction {d w ell B K A : ℝ} {start : Node} + (F : Side → ℝ×ℝ → ℝ) (hK : 0 ≤ K) (hA : 0 ≤ A) (hbound : ∀ i x,|F i x| ≤ A) + (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → F i (r,s)=0) + (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS : (Real.log B)^2 ≤ (Real.log w)^3) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ (Real.log B)^2) + (hB : 0 < B) (hsize : start.gap ≤ (23/10:ℝ)*B) + (hlogB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) (N : ℕ) : + |correctedExpectation F w ell ((Real.log B)^2) start N-primeExpectation F w ell ((Real.log B)^2) start N| ≤ + correctionBudget d w*A*(K+1) := by + have he := history_correction hlogB hcomp hell hr hs hB hsize (History.empty : History w ell ((Real.log B)^2) start) + have hb0 : 0 ≤ correctionBudget d w := by simpa only [History.empty,List.length_nil,pow_zero,sub_self] using he.2 + have hδ0 : 0 ≤ correctionBudget d w*A := mul_nonneg hb0 hA + have hIC : ∀ n ∈ range N,Integrable (correctedTest F) (pathLaw w ell ((Real.log B)^2) start n) := by + intro n _hn + let := pathLaw_isProbability hw hell (sq_nonneg _) hS hr hs hsS n + exact bounded_integrable (correctedTest_measurable F) (correctedTest_bound F hA hbound hlogB hcomp hell hr hs hB hsize) + have hIP : ∀ n ∈ range N,Integrable (primeTest F) (pathLaw w ell ((Real.log B)^2) start n) := by + intro n _hn + let := pathLaw_isProbability hw hell (sq_nonneg _) hS hr hs hsS n + exact bounded_integrable (primeTest_measurable F) (primeTest_bound hA hbound) + have hdiff := finite_integral_difference (fun n => pathLaw w ell ((Real.log B)^2) start n) + (correctedTest F) (primeTest F) N hIC hIP + have hpoint := correction_difference_bound F hA hbound hsupport hlogB hcomp hell hr hs hB hsize + have hsum : (∑ n ∈ range N,∫⁻ z,ENNReal.ofReal |correctedTest F z-primeTest F z| ∂pathLaw w ell ((Real.log B)^2) start n) ≤ + ENNReal.ofReal (correctionBudget d w*A)*(∑ n ∈ range N,∫⁻ z,ENNReal.ofReal (visit K z) ∂pathLaw w ell ((Real.log B)^2) start n) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro n _hn + calc + _ ≤ ∫⁻ z,ENNReal.ofReal (correctionBudget d w*A)*ENNReal.ofReal (visit K z) ∂pathLaw w ell ((Real.log B)^2) start n := by + apply lintegral_mono + intro z + change ENNReal.ofReal |correctedTest F z-primeTest F z| ≤ ENNReal.ofReal (correctionBudget d w*A)*ENNReal.ofReal (visit K z) + rw [← ENNReal.ofReal_mul hδ0] + exact ENNReal.ofReal_le_ofReal (hpoint z) + _ = _ := lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + have hvisit := finite_compact_visits hw hell (sq_nonneg _) hS hr hs hsS hK N + have h := hdiff.trans (hsum.trans (mul_le_mul_of_nonneg_left hvisit zero_le)) + rw [← ENNReal.ofReal_mul hδ0] at h + exact (ENNReal.ofReal_le_ofReal_iff (by positivity : 0 ≤ correctionBudget d w*A*(K+1))).mp h + +end NumberTheoryLean.CompactNormalizationCorrection + +end + +section + +namespace NumberTheoryLean.ContinuousCompactHighError + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures CompactTestGeometry CompactTestMeasurable CompactInverseTest +open RegeneratingInverseBands InvariantInverseWeights OriginalHarmonicOccupation +open ContinuousHighPartition FlaggedHarmonicTransform FiniteAdmittedOccupation +open LowStateHorizon AdmittedHarmonicPaths + +noncomputable def baseReward (v : ℝ) (H : FinitePathGeometry.Side → ℝ×ℝ → ℝ) (z : CostState) : ℝ := + H (stateSide z.1) (gapValue v z,stateRatio z.1) + +noncomputable def inverseReward (v : ℝ) (H : FinitePathGeometry.Side → ℝ×ℝ → ℝ) (z : CostState) : ℝ := + continuousTest v (inverseTest H) (.inl z) + +theorem baseReward_measurable (v : ℝ) {H : FinitePathGeometry.Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) : Measurable (baseReward v H) := + (continuousTest_measurable v H (fun i => (hH i).measurable)).comp measurable_inl + +theorem inverseReward_measurable (v : ℝ) {H : FinitePathGeometry.Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) : Measurable (inverseReward v H) := + (continuousTest_measurable v (inverseTest H) (fun i => (inverseTest_continuous hH i).measurable)).comp measurable_inl + +theorem inverseReward_abs (v : ℝ) (H : FinitePathGeometry.Side → ℝ×ℝ → ℝ) (z : CostState) : + ENNReal.ofReal |inverseReward v H z| = gapSquaredWeight v z*ENNReal.ofReal |baseReward v H z| := by + have hs := stateRatio_valid z.1 + change ENNReal.ofReal |inverseTest H (stateSide z.1) (gapValue v z,stateRatio z.1)| = _ + rw [inverseTest_eq hs,← SuccessfulRewardComparison.stateWeight_eq] + unfold gapSquaredWeight baseReward + rw [abs_div,abs_mul,abs_of_nonneg (sq_nonneg _),abs_of_pos (stateWeight_pos z.1), + ← ENNReal.ofReal_mul (div_nonneg (sq_nonneg _) (stateWeight_pos z.1).le)] + congr 1 + ring + +theorem phase_compact_bound {H : FinitePathGeometry.Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) : + ∃ A : ℝ,0 ≤ A ∧ ∀ i x,|H i x| ≤ A := by + obtain ⟨Ae,he⟩ := (hH .even).bounded_above_of_compact_support (hcompact .even) + obtain ⟨Ao,ho⟩ := (hH .odd).bounded_above_of_compact_support (hcompact .odd) + refine ⟨max 0 (max Ae Ao),le_max_left _ _,?_⟩ + intro i x + cases i with + | even => + have hx : |H .even x| ≤ Ae := by simpa only [Real.norm_eq_abs] using he x + exact hx.trans ((le_max_left _ _).trans (le_max_right _ _)) + | odd => + have hx : |H .odd x| ≤ Ao := by simpa only [Real.norm_eq_abs] using ho x + exact hx.trans ((le_max_right _ _).trans (le_max_right _ _)) + +theorem compact_high_error_bound {H : FinitePathGeometry.Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {K : ℝ} (hsupport : ∀ i : FinitePathGeometry.Side,∀ r s : ℝ,K < r → H i (r,s)=0) : + ∃ A : ℝ,0 ≤ A ∧ ∀ v ell S B : ℝ,1 ≤ ell → 0 < S → 0 < B → + ∀ s : State,stateRatio s ≤ S → gapValue v (s,0) ≤ (23/10:ℝ)*B → + ENNReal.ofReal |(∫ z,inverseReward v H z ∂occupation (admittedTilted v ell) (s,0))- + (∫ z,inverseReward v H z ∂occupation (lowKernel costKernel v ell S) (s,0))| ≤ + ENNReal.ofReal ((Real.exp v)^2/stateWeight s)*ENNReal.ofReal A* + AdmittedHighRemoval.lowHighMass v ell S (s,0) K := by + obtain ⟨A,hA,hbase⟩ := phase_compact_bound hH hcompact + obtain ⟨D,hD,hinverse⟩ := inverseTest_bounded hH hcompact + refine ⟨A,hA,?_⟩ + intro v ell S B hell hS hB s hs hgap + have hG : ∀ z : CostState,|inverseReward v H z| ≤ D := fun z => hinverse _ _ + have herr := admitted_low_signed_error v ell S B hell hS hB s hs hgap (inverseReward_measurable v hH) hG + have hbaseM : Measurable (fun z => ENNReal.ofReal |baseReward v H z|) := + ENNReal.measurable_ofReal.comp (baseReward_measurable v hH).abs + have hb : ∀ z : CostState,ENNReal.ofReal |baseReward v H z| ≤ ENNReal.ofReal A := + fun z => ENNReal.ofReal_le_ofReal (hbase _ _) + have hz : ∀ z : CostState,K < gapValue v z → ENNReal.ofReal |baseReward v H z| = 0 := by + intro z hz + simp [baseReward,hsupport _ _ _ hz] + have hhigh := high_inverse_compact_le v ell S s hbaseM ENNReal.ofReal_ne_top hb hz + have he : (fun z : CostState => ENNReal.ofReal |inverseReward v H z|) = + (fun z => gapSquaredWeight v z*ENNReal.ofReal |baseReward v H z|) := funext (inverseReward_abs v H) + rw [he] at herr + exact herr.trans hhigh + +end NumberTheoryLean.ContinuousCompactHighError + +end + +section + +namespace NumberTheoryLean.CorrectedCompactTransfer + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open CompactTestGeometry CompactNormalizationCorrection CompactInverseTest +open SignedCompactTransfer PrimeCorrectionFactor UniformBudgetRate LowStateHorizon + +theorem source_corrected_compact_transfer (F : Side → ℝ×ℝ → ℝ) + (hF : ∀ i,UniformContinuous (F i)) {K A : ℝ} (hK : 0 ≤ K) (hA : 0 ≤ A) + (hbound : ∀ i x,|F i x| ≤ A) (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → F i (r,s)=0) + (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.gap ≤ (23/10:ℝ)*B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + |correctedExpectation F w ell S start N- + continuousExpectation F (Real.log start.gap) ell S (FlaggedSourceStart.sourceCostState hs) N| ≤ ε := by + obtain ⟨wP,hwP,htransfer⟩ := source_signed_compact_transfer F hF hK hA hbound hsupport d (ε/2) hd (by linarith) + have hlimit : Tendsto (fun w : ℝ => correctionBudget d w*A*(K+1)) atTop (𝓝 0) := by + simpa only [zero_mul] using ((correctionBudget_tendsto_zero d).mul_const A).mul_const (K+1) + have hevent := (hlimit.eventually (eventually_le_nhds (show 0 < ε/2 by linarith))).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + obtain ⟨wAux,hwAux⟩ := eventually_atTop.mp hevent + refine ⟨max wP (max normalizationThreshold wAux),hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hB hlogB hcomp hr h23 hcons hsize + dsimp only + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hwe := hwAux w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw) + have hscale := source_scale_bound hwe.2 hlogB hcomp + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hcorrection := actual_compact_correction F hK hA hbound hsupport hnorm hell hscale.1 + hr hs hsS hB hsize hlogB hcomp N + have hprime := htransfer w ((le_max_left _ _).trans hw) ell B start hs hell hB hlogB hcomp hr h23 hcons hsize + have htri := abs_sub_le (correctedExpectation F w ell S start N) (primeExpectation F w ell S start N) + (continuousExpectation F (Real.log start.gap) ell S (FlaggedSourceStart.sourceCostState hs) N) + linarith + +theorem source_inverse_compact_transfer (H : Side → ℝ×ℝ → ℝ) + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {K : ℝ} (hK : 0 ≤ K) (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → H i (r,s)=0) + (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.gap ≤ (23/10:ℝ)*B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + |correctedExpectation (inverseTest H) w ell S start N- + continuousExpectation (inverseTest H) (Real.log start.gap) ell S (FlaggedSourceStart.sourceCostState hs) N| ≤ ε := by + obtain ⟨A,hA,hbound⟩ := inverseTest_bounded hH hcompact + exact source_corrected_compact_transfer (inverseTest H) (inverseTest_uniform hH hcompact) hK hA hbound + (inverseTest_gap_support hsupport) d ε hd hε + +end NumberTheoryLean.CorrectedCompactTransfer + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/CorrectionWeightedIntegral.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CorrectionWeightedIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef8d0128dac4bbf6a4d8de951ae3488fd954009b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/CorrectionWeightedIntegral.lean @@ -0,0 +1,260 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CorrectionEnvelope + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology ENNReal +namespace ErdosCorrectionLimit +open ErdosCorrectionOccupation +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.InvariantInverseWeights +open NumberTheoryLean.PrimeOccupationDensity NumberTheoryLean.OccupationDensityIntegral +open Erdos970Dependency.StateKernelInvariance Erdos970Dependency.InvariantCostBound + +noncomputable def densityEnvelope (c : ℝ) (x : ℝ×State) : ℝ := + density 2 x*Real.exp (-c*Real.exp x.1) + +theorem densityEnvelope_nonneg (c : ℝ) (x : ℝ×State) : 0 ≤ densityEnvelope c x := + mul_nonneg (density_nonneg 2 x) (Real.exp_pos _).le + +theorem densityEnvelope_measurable (c : ℝ) : Measurable (densityEnvelope c) := + (density_measurable 2).mul (Real.measurable_exp.comp + (measurable_const.mul (Real.measurable_exp.comp measurable_fst))) + +theorem densityEnvelope_factor (c u : ℝ) (s : State) : + ENNReal.ofReal (densityEnvelope c (u,s))= + ENNReal.ofReal ((Real.exp u)^2*Real.exp (-c*Real.exp u)/costMass)* + inverseWeightCutoff (Real.exp u/2) s := by + classical + by_cases h : stateRatio s < Real.exp u/2 + · rw [inverseWeightCutoff,indicator_of_mem (show s ∈ {s | stateRatio s < Real.exp u/2} from h)] + unfold densityEnvelope density + rw [ite_eq_left h] + have he : (Real.exp u)^2/(stateWeight s*costMass)*Real.exp (-c*Real.exp u)= + ((Real.exp u)^2*Real.exp (-c*Real.exp u)/costMass)/stateWeight s := by ring + rw [he,ENNReal.ofReal_div_of_pos (stateWeight_pos s),div_eq_mul_inv] + · rw [inverseWeightCutoff,indicator_of_notMem (show s ∉ {s | stateRatio s < Real.exp u/2} from h),mul_zero] + simp only [densityEnvelope,density,ite_eq_right h,zero_mul,ENNReal.ofReal_zero] + +theorem densityEnvelope_section_le (c u : ℝ) : + (∫⁻ s : State,ENNReal.ofReal (densityEnvelope c (u,s)) ∂stateMeasure) ≤ + ENNReal.ofReal ((Real.exp u)^3*Real.exp (-c*Real.exp u)/costMass) := by + simp_rw [densityEnvelope_factor] + rw [lintegral_const_mul _ (inverseWeightCutoff_measurable _)] + have hb := inverseWeightCutoff_mass_le (L := Real.exp u/2) (by positivity) + have hc : 0 ≤ (Real.exp u)^2*Real.exp (-c*Real.exp u)/costMass := + div_nonneg (mul_nonneg (sq_nonneg _) (Real.exp_pos _).le) costMass_pos.le + calc + _ ≤ ENNReal.ofReal ((Real.exp u)^2*Real.exp (-c*Real.exp u)/costMass)* + ENNReal.ofReal (2*(Real.exp u/2)) := mul_le_mul le_rfl hb (by positivity) (by positivity) + _ = _ := by rw [← ENNReal.ofReal_mul hc]; congr 1; ring + +theorem densityEnvelope_integrable {c : ℝ} (hc : 0 < c) : + Integrable (densityEnvelope c) baseMeasure := by + have hgn : ∀ u : ℝ,0 ≤ (Real.exp u)^3*Real.exp (-c*Real.exp u)/costMass := + fun u => div_nonneg (mul_nonneg (pow_nonneg (Real.exp_pos _).le _) (Real.exp_pos _).le) costMass_pos.le + have hgi : Integrable (fun u : ℝ => (Real.exp u)^3*Real.exp (-c*Real.exp u)/costMass) := by + simpa only [Nat.reduceAdd] using (exp_gap_moment_integrable 2 hc).div_const costMass + refine ⟨(densityEnvelope_measurable c).aestronglyMeasurable,?_⟩ + apply (hasFiniteIntegral_iff_ofReal (Eventually.of_forall (densityEnvelope_nonneg c))).mpr + have hm : Measurable (fun x => ENNReal.ofReal (densityEnvelope c x)) := + ENNReal.measurable_ofReal.comp (densityEnvelope_measurable c) + rw [baseMeasure,lintegral_prod _ hm.aemeasurable] + exact (lintegral_mono (densityEnvelope_section_le c)).trans_lt + ((hasFiniteIntegral_iff_ofReal (Eventually.of_forall hgn)).mp hgi.hasFiniteIntegral) + +theorem fullRaw_integrable : Integrable (rawTest fullAnomalyTest) (limitingMeasure 2) := by + obtain ⟨C,c,hC,hc,ha⟩ := full_anomaly_exponential + have hm := rawTest_measurable fullAnomalyTest_continuous + have hD := ENNReal.measurable_ofReal.comp (density_measurable 2) + have ht : ∀ᵐ x ∂baseMeasure,ENNReal.ofReal (density 2 x)<∞ := + Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top) + apply (integrable_withDensity_iff_integrable_smul' hD ht).mpr + have hi : Integrable (fun x => density 2 x*rawTest fullAnomalyTest x) baseMeasure := by + apply ((densityEnvelope_integrable hc).const_mul C).mono' + ((density_measurable 2).mul hm).aestronglyMeasurable + apply Eventually.of_forall + intro x + change ‖density 2 x*rawTest fullAnomalyTest x‖ ≤ C*densityEnvelope c x + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (density_nonneg 2 x)] + have hb := mul_le_mul_of_nonneg_left (ha (stateSide x.2) (Real.exp x.1)) (density_nonneg 2 x) + change density 2 x*|extendedSignedAnomaly (stateSide x.2) (Real.exp x.1)| ≤ _ + unfold densityEnvelope + nlinarith + apply hi.congr + filter_upwards with x + change density 2 x*rawTest fullAnomalyTest x = (ENNReal.ofReal (density 2 x)).toReal • rawTest fullAnomalyTest x + rw [ENNReal.toReal_ofReal (density_nonneg 2 x),smul_eq_mul] + +end ErdosCorrectionLimit + +end + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology ENNReal +namespace ErdosCorrectionLimit +open ErdosCorrectionOccupation ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.PrimeOccupationDensity NumberTheoryLean.OccupationDensityIntegral +open NumberTheoryLean.CompactLogOccupationTest NumberTheoryLean.NormalizedOccupationLimit +open NumberTheoryLean.TransitionKernels NumberTheoryLean.OccupationBoundaries +open Erdos970Dependency.StateKernelInvariance Erdos970Dependency.OrdinaryKernelInvariance +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantFiniteness + +theorem invariant_ratio_ge_one : ∀ᵐ s : State ∂stateMeasure,1 ≤ stateRatio s := by + have hp : MeasurableSet {s : State | 1 ≤ stateRatio s} := + measurableSet_le measurable_const stateRatio_measurable + rw [stateMeasure,ae_add_measure_iff] + constructor + · apply (ae_map_iff measurable_inl.aemeasurable hp).mpr + exact Eventually.of_forall (fun s => by change 1 ≤ s.1; linarith [s.2]) + · apply (ae_map_iff measurable_inr.aemeasurable hp).mpr + rw [oddStateMeasure] + apply (ae_map_iff oddLift_measurable.aemeasurable + (measurableSet_le measurable_const measurable_subtype_coe)).mpr + have hm : Measurable (fun t => ENNReal.ofReal (Erdos970Dependency.InvariantDensities.oddDensity t)) := + ENNReal.measurable_ofReal.comp Erdos970Dependency.InvariantDensities.oddDensity_measurable + unfold oddMeasure + apply (ae_withDensity_iff hm).mpr + apply Eventually.of_forall + intro t ht + by_cases h : 1 ≤ t + · change 1 ≤ max (95/100:ℝ) t + exact h.trans (le_max_right _ _) + · exfalso + apply ht + rw [Erdos970Dependency.InvariantDensities.oddDensity,indicator_of_notMem (show t ∉ Ici (1:ℝ) from h),ENNReal.ofReal_zero] + +theorem limiting_gap_ge_two : ∀ᵐ x : ℝ×State ∂limitingMeasure 2,2 ≤ Real.exp x.1 := by + have hbase : ∀ᵐ x : ℝ×State ∂baseMeasure,1 ≤ stateRatio x.2 := by + have hset : MeasurableSet {x : ℝ×State | 1 ≤ stateRatio x.2} := + measurableSet_le measurable_const (stateRatio_measurable.comp measurable_snd) + exact (Measure.ae_prod_iff_ae_ae hset).mpr (Eventually.of_forall (fun _ => invariant_ratio_ge_one)) + have hm : Measurable (fun x => ENNReal.ofReal (density 2 x)) := + ENNReal.measurable_ofReal.comp (density_measurable 2) + rw [limitingMeasure,ae_withDensity_iff hm] + filter_upwards [hbase] with x hx hd + have harr : stateRatio x.2 < Real.exp x.1/2 := by + by_contra h + exact hd (by simp only [density,ite_eq_right h,ENNReal.ofReal_zero]) + linarith + +theorem compact_raw_tendsto : + ∀ᵐ x : ℝ×State ∂limitingMeasure 2, + Tendsto (fun K : ℝ => rawTest (compactAnomalyTest K) x) atTop + (𝓝 (rawTest fullAnomalyTest x)) := by + filter_upwards [limiting_gap_ge_two] with x hx + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (max (Real.exp x.1) (stateRatio x.2))] with K hK + have hrK : Real.exp x.1 ≤ K := (le_max_left _ _).trans hK + have hsK : stateRatio x.2 ≤ K := (le_max_right _ _).trans hK + change extendedSignedAnomaly (stateSide x.2) (Real.exp x.1)= + compactCutoff K (Real.exp x.1,stateRatio x.2)*extendedSignedAnomaly (stateSide x.2) (Real.exp x.1) + rw [(compactCutoff_spec K).2.2.1 _ _ hx hrK (stateRatio_pos _).le hsK,one_mul] + +theorem compact_raw_norm_le (K : ℝ) (x : ℝ×State) : + ‖rawTest (compactAnomalyTest K) x‖ ≤ ‖rawTest fullAnomalyTest x‖ := by + have hb := (compactCutoff_spec K).2.1 (Real.exp x.1,stateRatio x.2) + change ‖compactCutoff K (Real.exp x.1,stateRatio x.2)*extendedSignedAnomaly (stateSide x.2) (Real.exp x.1)‖ ≤ + ‖extendedSignedAnomaly (stateSide x.2) (Real.exp x.1)‖ + rw [Real.norm_eq_abs,Real.norm_eq_abs,abs_mul,abs_of_nonneg hb.1] + exact mul_le_of_le_one_left (abs_nonneg _) hb.2 + +theorem compact_limiting_integral_tendsto : + Tendsto (fun K : ℝ => ∫ x,rawTest (compactAnomalyTest K) x ∂limitingMeasure 2) atTop + (𝓝 (∫ x,rawTest fullAnomalyTest x ∂limitingMeasure 2)) := by + apply tendsto_integral_filter_of_dominated_convergence (fun x => ‖rawTest fullAnomalyTest x‖) + · exact Eventually.of_forall (fun K => (rawTest_measurable (compactAnomalyTest_continuous K)).aestronglyMeasurable) + · exact Eventually.of_forall (fun K => Eventually.of_forall (compact_raw_norm_le K)) + · exact fullRaw_integrable.norm + · exact compact_raw_tendsto + +theorem compact_invariant_tendsto : + Tendsto (fun K : ℝ => invariantAverage (arrivalTest 2 (compactAnomalyTest K))) atTop + (𝓝 (∫ x,rawTest fullAnomalyTest x ∂limitingMeasure 2)) := by + apply compact_limiting_integral_tendsto.congr' + filter_upwards [eventually_ge_atTop (3:ℝ)] with K hK + exact (continuous_test_density (compactAnomalyTest_continuous K) (compactAnomalyTest_compact K) + (a := 1) (b := K+1) (by norm_num) (by linarith) (by norm_num : (0:ℝ)<2) + (fun i r s hr => compactAnomalyTest_support K i r s hr)).2 + +end ErdosCorrectionLimit + +end + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology ENNReal +namespace ErdosCorrectionLimit +open ErdosCorrectionOccupation +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PrimeOccupationDensity +open NumberTheoryLean.OccupationDensityIntegral +open Erdos970Dependency.StateKernelInvariance + +noncomputable def fullWeighted (x : ℝ×State) : ℝ := density 2 x*rawTest fullAnomalyTest x + +theorem fullWeighted_measurable : Measurable fullWeighted := + (density_measurable 2).mul (rawTest_measurable fullAnomalyTest_continuous) + +theorem fullWeighted_integrable : Integrable fullWeighted baseMeasure := by + have hD : Measurable (fun x => ENNReal.ofReal (density 2 x)) := + ENNReal.measurable_ofReal.comp (density_measurable 2) + have ht : ∀ᵐ x ∂baseMeasure,ENNReal.ofReal (density 2 x)<∞ := + Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top) + have hi := (integrable_withDensity_iff_integrable_smul' hD ht).mp fullRaw_integrable + apply hi.congr + filter_upwards with x + change (ENNReal.ofReal (density 2 x)).toReal • rawTest fullAnomalyTest x=fullWeighted x + rw [ENNReal.toReal_ofReal (density_nonneg 2 x),smul_eq_mul] + rfl + +theorem densityEnvelope_section_integrable (c u : ℝ) : + Integrable (fun s : State => densityEnvelope c (u,s)) stateMeasure := by + have hm : Measurable (fun s : State => densityEnvelope c (u,s)) := (densityEnvelope_measurable c).comp (measurable_const.prodMk measurable_id) + refine ⟨hm.aestronglyMeasurable,?_⟩ + apply (hasFiniteIntegral_iff_ofReal (Eventually.of_forall (fun s => densityEnvelope_nonneg c (u,s)))).mpr + exact (densityEnvelope_section_le c u).trans_lt ENNReal.ofReal_lt_top + +theorem fullWeighted_section_integrable (u : ℝ) : + Integrable (fun s : State => fullWeighted (u,s)) stateMeasure := by + obtain ⟨C,c,hC,_hc,ha⟩ := full_anomaly_exponential + have hm : Measurable (fun s : State => fullWeighted (u,s)) := fullWeighted_measurable.comp (measurable_const.prodMk measurable_id) + apply ((densityEnvelope_section_integrable c u).const_mul C).mono' hm.aestronglyMeasurable + apply Eventually.of_forall + intro s + change ‖density 2 (u,s)*rawTest fullAnomalyTest (u,s)‖ ≤ C*densityEnvelope c (u,s) + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (density_nonneg 2 (u,s))] + have hb := mul_le_mul_of_nonneg_left (ha (stateSide s) (Real.exp u)) (density_nonneg 2 (u,s)) + change density 2 (u,s)*|extendedSignedAnomaly (stateSide s) (Real.exp u)| ≤ _ + unfold densityEnvelope + nlinarith + +theorem full_limiting_integral_fubini : + (∫ x,rawTest fullAnomalyTest x ∂limitingMeasure 2)= + ∫ u : ℝ,∫ s : State,fullWeighted (u,s) ∂stateMeasure := by + have hD : Measurable (fun x => ENNReal.ofReal (density 2 x)) := + ENNReal.measurable_ofReal.comp (density_measurable 2) + have ht : ∀ᵐ x ∂baseMeasure,ENNReal.ofReal (density 2 x)<∞ := + Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top) + rw [limitingMeasure,integral_withDensity_eq_integral_toReal_smul hD ht] + have he : (fun x => (ENNReal.ofReal (density 2 x)).toReal • rawTest fullAnomalyTest x)=fullWeighted := by + funext x + rw [ENNReal.toReal_ofReal (density_nonneg 2 x),smul_eq_mul] + rfl + rw [he] + exact integral_prod fullWeighted fullWeighted_integrable + +end ErdosCorrectionLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/DeficitIntegralValues.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/DeficitIntegralValues.lean new file mode 100644 index 0000000000000000000000000000000000000000..eefa87d787a904a9391a3add085878ecfd85e0c2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/DeficitIntegralValues.lean @@ -0,0 +1,93 @@ +import Mathlib.MeasureTheory.Group.Integral +import OAI.NumberTheory.Jacobsthal.Estimates.InvariantFiniteness + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory +namespace Erdos970Dependency.DeficitIntegralValues +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.BuchstabBridge +open NumberTheoryLean.NormalizedDeficits NumberTheoryLean.DeficitFutureIntegrals + +theorem shift_indicator (f : ℝ → ℝ) (a d : ℝ) : + (fun s ↦ (Ioi a).indicator f (s - d)) = (Ioi (a + d)).indicator (fun s ↦ f (s - d)) := by + funext s + by_cases hs : a + d < s + · rw [indicator_of_mem (show s ∈ Ioi (a + d) from hs), + indicator_of_mem (show s - d ∈ Ioi a by change a < s - d; linarith)] + · rw [indicator_of_notMem (show s ∉ Ioi (a + d) from hs), + indicator_of_notMem (show s - d ∉ Ioi a by change ¬a < s - d; linarith)] + +theorem integrableOn_shift_Ioi {f : ℝ → ℝ} {a : ℝ} (hf : IntegrableOn f (Ioi a)) (d : ℝ) : + IntegrableOn (fun s ↦ f (s - d)) (Ioi (a + d)) := by + have h := ((integrable_indicator_iff measurableSet_Ioi).mpr hf).comp_sub_right d + rw [shift_indicator] at h + exact (integrable_indicator_iff measurableSet_Ioi).mp h + +theorem integral_shift_Ioi (f : ℝ → ℝ) (a d : ℝ) : + (∫ s in Ioi (a + d), f (s - d)) = ∫ s in Ioi a, f s := by + have h := integral_sub_right_eq_self (μ := (volume : Measure ℝ)) ((Ioi a).indicator f) d + rw [shift_indicator, integral_indicator measurableSet_Ioi, integral_indicator measurableSet_Ioi] at h + exact h + +theorem upper_integral_one : IntegrableOn upperDeficit (Ioi (1 : ℝ)) ∧ + (∫ s in Ioi (1 : ℝ), upperDeficit s) = 2 := by + have h := lower_future_integral (s := 2) (by norm_num) + norm_num only [show (2 : ℝ) - 1 = 1 by norm_num] at h + refine ⟨h.1, ?_⟩ + rw [← h.2] + norm_num [lowerDeficit, f_initial sieveA (s := 2) (by norm_num)] + +theorem lower_integral_zero : IntegrableOn lowerDeficit (Ioi (0 : ℝ)) ∧ + (∫ s in Ioi (0 : ℝ), lowerDeficit s) = sieveA - 1 := by + have h := upper_future_integral (s := 1) (by norm_num) + norm_num only [show (1 : ℝ) - 1 = 0 by norm_num, one_mul] at h + refine ⟨h.1, ?_⟩ + rw [← h.2] + norm_num [upperDeficit, F_initial sieveA (s := 1) (by norm_num) (by norm_num)] + +theorem lower_integral_two : IntegrableOn lowerDeficit (Ioi (2 : ℝ)) ∧ + (∫ s in Ioi (2 : ℝ), lowerDeficit s) = sieveA - 3 := by + have h := upper_future_integral (s := 3) (by norm_num) + norm_num only [show (3 : ℝ) - 1 = 2 by norm_num] at h + refine ⟨h.1, ?_⟩ + rw [← h.2] + simp only [upperDeficit, F_initial sieveA (s := 3) (by norm_num) (by norm_num)] + ring + +theorem even_majorant_integral : + IntegrableOn (fun s ↦ lowerDeficit s + upperDeficit (s - 1)) (Ici (2 : ℝ)) ∧ + (∫ s in Ici (2 : ℝ), lowerDeficit s + upperDeficit (s - 1)) = sieveA - 1 := by + have ha := lower_integral_two.1 + have hc : IntegrableOn (fun s ↦ upperDeficit (s - 1)) (Ioi (2 : ℝ)) := by + simpa only [show (1 : ℝ) + 1 = 2 by norm_num] using integrableOn_shift_Ioi upper_integral_one.1 1 + refine ⟨Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi (ha.add hc), ?_⟩ + rw [integral_Ici_eq_integral_Ioi, integral_add ha hc, lower_integral_two.2] + have h := integral_shift_Ioi upperDeficit 1 1 + norm_num only [show (1 : ℝ) + 1 = 2 by norm_num] at h + rw [h, upper_integral_one.2] + ring + +theorem odd_majorant_integral : + IntegrableOn (fun s ↦ upperDeficit s + lowerDeficit (s - 1)) (Ici (1 : ℝ)) ∧ + (∫ s in Ici (1 : ℝ), upperDeficit s + lowerDeficit (s - 1)) = sieveA + 1 := by + have hc := upper_integral_one.1 + have ha : IntegrableOn (fun s ↦ lowerDeficit (s - 1)) (Ioi (1 : ℝ)) := by + simpa only [zero_add] using integrableOn_shift_Ioi lower_integral_zero.1 1 + refine ⟨Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi (hc.add ha), ?_⟩ + rw [integral_Ici_eq_integral_Ioi, integral_add hc ha, upper_integral_one.2] + have h := integral_shift_Ioi lowerDeficit 0 1 + rw [zero_add] at h + rw [h, lower_integral_zero.2] + ring + +end Erdos970Dependency.DeficitIntegralValues + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/DensityComparison.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/DensityComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..598a6acb6ed832bfe73573dcc51f46e85f53ca13 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/DensityComparison.lean @@ -0,0 +1,366 @@ +import OAI.NumberTheory.Jacobsthal.Probability.StateKernelInvariance + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory +namespace Erdos970Dependency.InitialDensityFormulas +open NumberTheoryLean NumberTheoryLean.BuchstabBridge NumberTheoryLean.DerivativeWeights +open NumberTheoryLean.WeightFutureIntegrals NumberTheoryLean.TransitionKernels +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.RegenerationTails NumberTheoryLean.TwoStepDensityBounds +open Erdos970Dependency.WeightIntegrals Erdos970Dependency.OrdinaryKernelInvariance + +noncomputable def initialTwoDensity (s : EvenState) (t : ℝ) : ℝ := + (Ici (2 : ℝ)).indicator (fun t ↦ (W t * phiEven t / phiEven s.1) * wMass (s.1 - 1) (t + 1)) t + +noncomputable def regTwoDensity (u : ℝ) : ℝ := + (Ici (1 : ℝ)).indicator (fun u ↦ (W u * phiOdd u / sieveA) * tailW u) u + +noncomputable def regThreeDensity (t : ℝ) : ℝ := + (Ici (2 : ℝ)).indicator (fun t ↦ (W t * phiEven t / sieveA) * regIntegral t) t + +noncomputable def initialIncoming (s : EvenState) (t u : ℝ) : ℝ := + TransitionKernels.evenDensity s u * transitionDensity .odd (oddLift u).1 t + +noncomputable def regTwoIncoming (u y : ℝ) : ℝ := + TransitionKernels.oddDensity regenerationState y * transitionDensity .even (evenLift y).1 u + +noncomputable def regThreeIncoming (t u : ℝ) : ℝ := + regTwoDensity u * transitionDensity .odd (oddLift u).1 t + +theorem regTwoDensity_measurable : Measurable regTwoDensity := + (((W_measurable.mul phiOdd_continuous.measurable).div_const sieveA).mul tailW_measurable).indicator measurableSet_Ici + +theorem regTwoDensity_nonneg (u : ℝ) : 0 ≤ regTwoDensity u := by + by_cases hu : 1 ≤ u + · rw [regTwoDensity, indicator_of_mem (show u ∈ Ici (1 : ℝ) from hu)] + exact mul_nonneg (div_nonneg (mul_nonneg (W_pos (by linarith)).le (phiOdd_pos u).le) sieveA_pos.le) + (tailW_nonneg hu) + · rw [regTwoDensity, indicator_of_notMem (show u ∉ Ici (1 : ℝ) from hu)] + +theorem initialIncoming_formula (s : EvenState) {t : ℝ} (ht : 2 ≤ t) (u : ℝ) : + initialIncoming s t u = (Icc (s.1 - 1) (t + 1)).indicator + (fun u ↦ (W t * phiEven t / phiEven s.1) * W u) u := by + classical + by_cases hu : s.1 - 1 ≤ u + · have hlift : (oddLift u).1 = u := max_eq_right (by linarith [s.2]) + by_cases hut : u ≤ t + 1 + · rw [initialIncoming, hlift, indicator_of_mem (show u ∈ Icc (s.1 - 1) (t + 1) from ⟨hu, hut⟩)] + change transitionDensity .even s.1 u * transitionDensity .odd u t = _ + have htwo := two_step_density_eq (i := .even) (s := s.1) (t := u) (u := t) s.2 hu + (show max 2 (u - 1) ≤ t from max_le ht (by linarith)) + simp only [Side.flip, weight] at htwo + exact htwo.trans (by ring) + · have hn : t ∉ Ici (max 2 (u - 1)) := by + intro h + have := le_trans (le_max_right (2 : ℝ) (u - 1)) h + linarith + rw [initialIncoming, hlift, transitionDensity, minRatio, weight, Side.flip, weight, + TransitionKernels.tailDensity, indicator_of_notMem hn, mul_zero, + indicator_of_notMem (show u ∉ Icc (s.1 - 1) (t + 1) from fun h ↦ hut h.2)] + · rw [initialIncoming, TransitionKernels.evenDensity, TransitionKernels.tailDensity, + indicator_of_notMem (show u ∉ Ici (s.1 - 1) from hu), zero_mul, + indicator_of_notMem (show u ∉ Icc (s.1 - 1) (t + 1) from fun h ↦ hu h.1)] + +theorem initialIncoming_zero (s : EvenState) {t : ℝ} (ht : t < 2) (u : ℝ) : initialIncoming s t u = 0 := by + unfold initialIncoming transitionDensity + simp only [minRatio, weight, Side.flip, TransitionKernels.tailDensity] + rw [indicator_of_notMem (show t ∉ Ici (max 2 ((oddLift u).1 - 1)) from fun h ↦ + (not_le_of_gt ht) (le_trans (le_max_left _ _) h)), mul_zero] + +theorem regTwoIncoming_formula (u y : ℝ) : + regTwoIncoming u y = (Icc (2 : ℝ) (u + 1)).indicator + (fun y ↦ (W u * phiOdd u / sieveA) * W y) y := by + classical + have hmin : max 2 (regenerationState.1 - 1) = 2 := by norm_num [regenerationState] + by_cases hy : 2 ≤ y + · have hlift : (evenLift y).1 = y := max_eq_right (by linarith) + by_cases hyu : y ≤ u + 1 + · rw [regTwoIncoming, hlift, indicator_of_mem (show y ∈ Icc (2 : ℝ) (u + 1) from ⟨hy, hyu⟩)] + change transitionDensity .odd regenerationState.1 y * transitionDensity .even y u = _ + have htwo := two_step_density_eq (i := .odd) (s := regenerationState.1) (t := y) (u := u) + regenerationState.2 (by simpa only [minRatio, hmin] using hy) (by change y - 1 ≤ u; linarith) + simp only [Side.flip, weight] at htwo + rw [phiOdd_initial (s := regenerationState.1) (by norm_num [regenerationState])] at htwo + exact htwo.trans (by ring) + · rw [regTwoIncoming, hlift, transitionDensity, minRatio, weight, Side.flip, weight, + TransitionKernels.tailDensity, + indicator_of_notMem (show u ∉ Ici (y - 1) by change ¬y - 1 ≤ u; linarith), mul_zero, + indicator_of_notMem (show y ∉ Icc (2 : ℝ) (u + 1) from fun h ↦ hyu h.2)] + · rw [regTwoIncoming, TransitionKernels.oddDensity, TransitionKernels.tailDensity, hmin, + indicator_of_notMem (show y ∉ Ici (2 : ℝ) from hy), zero_mul, + indicator_of_notMem (show y ∉ Icc (2 : ℝ) (u + 1) from fun h ↦ hy h.1)] + +theorem regTwoIncoming_zero {u : ℝ} (hu : u < 1) (y : ℝ) : regTwoIncoming u y = 0 := by + have hmin : max 2 (regenerationState.1 - 1) = 2 := by norm_num [regenerationState] + by_cases hy : 2 ≤ y + · have hlift : (evenLift y).1 = y := max_eq_right (by linarith) + rw [regTwoIncoming, hlift, transitionDensity, minRatio, weight, Side.flip, weight, + TransitionKernels.tailDensity, + indicator_of_notMem (show u ∉ Ici (y - 1) by change ¬y - 1 ≤ u; linarith), mul_zero] + · rw [regTwoIncoming, TransitionKernels.oddDensity, TransitionKernels.tailDensity, hmin, + indicator_of_notMem (show y ∉ Ici (2 : ℝ) from hy), zero_mul] + +theorem regThreeIncoming_formula {t : ℝ} (ht : 2 ≤ t) (u : ℝ) : + regThreeIncoming t u = (Icc (1 : ℝ) (t + 1)).indicator + (fun u ↦ (W t * phiEven t / sieveA) * (W u * tailW u)) u := by + classical + by_cases hu : 1 ≤ u + · have hlift : (oddLift u).1 = u := max_eq_right (by linarith) + by_cases hut : u ≤ t + 1 + · rw [regThreeIncoming, regTwoDensity, indicator_of_mem (show u ∈ Ici (1 : ℝ) from hu), hlift, + transitionDensity, minRatio, weight, Side.flip, weight, TransitionKernels.tailDensity, + indicator_of_mem (show t ∈ Ici (max 2 (u - 1)) from max_le ht (by linarith)), + indicator_of_mem (show u ∈ Icc (1 : ℝ) (t + 1) from ⟨hu, hut⟩)] + field_simp [(phiOdd_pos u).ne', sieveA_pos.ne'] + · have hn : t ∉ Ici (max 2 (u - 1)) := by + intro h + have := le_trans (le_max_right (2 : ℝ) (u - 1)) h + linarith + rw [regThreeIncoming, hlift, transitionDensity, minRatio, weight, Side.flip, weight, + TransitionKernels.tailDensity, indicator_of_notMem hn, mul_zero, + indicator_of_notMem (show u ∉ Icc (1 : ℝ) (t + 1) from fun h ↦ hut h.2)] + · rw [regThreeIncoming, regTwoDensity, indicator_of_notMem (show u ∉ Ici (1 : ℝ) from hu), zero_mul, + indicator_of_notMem (show u ∉ Icc (1 : ℝ) (t + 1) from fun h ↦ hu h.1)] + +theorem regThreeIncoming_zero {t : ℝ} (ht : t < 2) (u : ℝ) : regThreeIncoming t u = 0 := by + unfold regThreeIncoming transitionDensity + simp only [minRatio, weight, Side.flip, TransitionKernels.tailDensity] + rw [indicator_of_notMem (show t ∉ Ici (max 2 ((oddLift u).1 - 1)) from fun h ↦ + (not_le_of_gt ht) (le_trans (le_max_left _ _) h)), mul_zero] + +end Erdos970Dependency.InitialDensityFormulas + +end + +section + +open Set MeasureTheory +namespace Erdos970Dependency.CompactIncomingIntegrals +open NumberTheoryLean.DerivativeWeights NumberTheoryLean.TransitionKernels +open Erdos970Dependency.WeightIntegrals Erdos970Dependency.InitialDensityFormulas + +theorem initialIncoming_integrable (s : EvenState) (t : ℝ) : Integrable (initialIncoming s t) := by + by_cases ht : 2 ≤ t + · rw [show initialIncoming s t = (Icc (s.1 - 1) (t + 1)).indicator + (fun u ↦ (W t * phiEven t / phiEven s.1) * W u) from funext (initialIncoming_formula s ht)] + apply (integrable_indicator_iff measurableSet_Icc).mpr + apply ContinuousOn.integrableOn_Icc + intro u hu + have hu0 : 0 < u := by linarith [s.2, hu.1] + exact (continuousAt_const.mul (W_continuousAt (ne_of_gt hu0))).continuousWithinAt + · rw [show initialIncoming s t = 0 from funext (initialIncoming_zero s (lt_of_not_ge ht))] + exact integrable_zero _ _ _ + +theorem regTwoIncoming_integrable (u : ℝ) : Integrable (regTwoIncoming u) := by + by_cases hu : 1 ≤ u + · rw [show regTwoIncoming u = (Icc (2 : ℝ) (u + 1)).indicator + (fun y ↦ (W u * phiOdd u / NumberTheoryLean.BuchstabBridge.sieveA) * W y) + from funext (regTwoIncoming_formula u)] + apply (integrable_indicator_iff measurableSet_Icc).mpr + apply ContinuousOn.integrableOn_Icc + intro y hy + exact (continuousAt_const.mul (W_continuousAt (by linarith [hy.1]))).continuousWithinAt + · rw [show regTwoIncoming u = 0 from funext (regTwoIncoming_zero (lt_of_not_ge hu))] + exact integrable_zero _ _ _ + +theorem regThreeIncoming_integrable (t : ℝ) : Integrable (regThreeIncoming t) := by + by_cases ht : 2 ≤ t + · rw [show regThreeIncoming t = (Icc (1 : ℝ) (t + 1)).indicator + (fun u ↦ (W t * phiEven t / NumberTheoryLean.BuchstabBridge.sieveA) * (W u * tailW u)) + from funext (regThreeIncoming_formula ht)] + apply (integrable_indicator_iff measurableSet_Icc).mpr + exact ((regKernel_continuousOn (b := t + 1) (by norm_num : (0 : ℝ) < 1)).const_mul _).integrableOn_Icc + · rw [show regThreeIncoming t = 0 from funext (regThreeIncoming_zero (lt_of_not_ge ht))] + exact integrable_zero _ _ _ + +theorem initialIncoming_integral (s : EvenState) (hsup : s.1 ≤ 23 / 10) (t : ℝ) : + (∫ u, initialIncoming s t u) = initialTwoDensity s t := by + by_cases ht : 2 ≤ t + · simp_rw [initialIncoming_formula s ht] + rw [integral_indicator measurableSet_Icc, integral_const_mul, integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le (show s.1 - 1 ≤ t + 1 by linarith), + initialTwoDensity, indicator_of_mem (show t ∈ Ici (2 : ℝ) from ht)] + rfl + · simp only [initialIncoming_zero s (lt_of_not_ge ht), integral_zero] + rw [initialTwoDensity, indicator_of_notMem (show t ∉ Ici (2 : ℝ) from ht)] + +theorem regTwoIncoming_integral (u : ℝ) : (∫ y, regTwoIncoming u y) = regTwoDensity u := by + by_cases hu : 1 ≤ u + · simp_rw [regTwoIncoming_formula] + rw [integral_indicator measurableSet_Icc, integral_const_mul, integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le (show (2 : ℝ) ≤ u + 1 by linarith), + regTwoDensity, indicator_of_mem (show u ∈ Ici (1 : ℝ) from hu), tailW_eq_mass hu] + rfl + · simp only [regTwoIncoming_zero (lt_of_not_ge hu), integral_zero] + rw [regTwoDensity, indicator_of_notMem (show u ∉ Ici (1 : ℝ) from hu)] + +theorem regThreeIncoming_integral (t : ℝ) : (∫ u, regThreeIncoming t u) = regThreeDensity t := by + by_cases ht : 2 ≤ t + · simp_rw [regThreeIncoming_formula ht] + rw [integral_indicator measurableSet_Icc, integral_const_mul, integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le (show (1 : ℝ) ≤ t + 1 by linarith), + regThreeDensity, indicator_of_mem (show t ∈ Ici (2 : ℝ) from ht)] + rfl + · simp only [regThreeIncoming_zero (lt_of_not_ge ht), integral_zero] + rw [regThreeDensity, indicator_of_notMem (show t ∉ Ici (2 : ℝ) from ht)] + +end Erdos970Dependency.CompactIncomingIntegrals + +end + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.MarginalDensityMeasures +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.KernelDensityBridge NumberTheoryLean.RegenerationTails +open Erdos970Dependency.OrdinaryKernelInvariance Erdos970Dependency.DensityConservation +open Erdos970Dependency.InitialDensityFormulas Erdos970Dependency.CompactIncomingIntegrals + +noncomputable def initialTwoMeasure (s : EvenState) : Measure ℝ := oddRealKernel ∘ₘ evenKernel s +noncomputable def regTwoMeasure : Measure ℝ := evenRealKernel ∘ₘ oddKernel regenerationState +noncomputable def regThreeMeasure : Measure ℝ := oddRealKernel ∘ₘ regTwoMeasure + +instance initialTwoMeasure_isProbabilityMeasure (s : EvenState) : IsProbabilityMeasure (initialTwoMeasure s) := by + unfold initialTwoMeasure + infer_instance +instance regTwoMeasure_isProbabilityMeasure : IsProbabilityMeasure regTwoMeasure := by unfold regTwoMeasure; infer_instance +instance regThreeMeasure_isProbabilityMeasure : IsProbabilityMeasure regThreeMeasure := by unfold regThreeMeasure; infer_instance + +theorem even_input_measurable (s : EvenState) : Measurable (evenDensity s) := + evenDensity_measurable.comp (measurable_const.prodMk measurable_id) + +theorem odd_input_measurable (s : OddState) : Measurable (oddDensity s) := + oddDensity_measurable.comp (measurable_const.prodMk measurable_id) + +theorem evenKernel_eq_density (s : EvenState) : + evenKernel s = volume.withDensity (fun u ↦ ENNReal.ofReal (evenDensity s u)) := by + ext B hB + rw [evenKernel_apply, withDensity_apply _ hB] + +theorem oddKernel_eq_density (s : OddState) : + oddKernel s = volume.withDensity (fun u ↦ ENNReal.ofReal (oddDensity s u)) := by + ext B hB + rw [oddKernel_apply, withDensity_apply _ hB] + +theorem odd_lifted_density_measurable : + Measurable (fun z : ℝ × ℝ ↦ transitionDensity .odd (oddLift z.1).1 z.2) := + (transitionDensity_joint_measurable .odd).comp + (((measurable_subtype_coe.comp oddLift_measurable).comp measurable_fst).prodMk measurable_snd) + +theorem even_lifted_density_measurable : + Measurable (fun z : ℝ × ℝ ↦ transitionDensity .even (evenLift z.1).1 z.2) := + (transitionDensity_joint_measurable .even).comp + (((measurable_subtype_coe.comp evenLift_measurable).comp measurable_fst).prodMk measurable_snd) + +theorem initialTwoMeasure_eq_density (s : EvenState) (hsup : s.1 ≤ 23 / 10) : + initialTwoMeasure s = volume.withDensity (fun t ↦ ENNReal.ofReal (initialTwoDensity s t)) := by + rw [initialTwoMeasure, evenKernel_eq_density] + apply kernel_density_conservation oddRealKernel (evenDensity s) (initialTwoDensity s) + (fun u t ↦ transitionDensity .odd (oddLift u).1 t) (even_input_measurable s) (evenDensity_nonneg s) + · exact ((even_input_measurable s).comp measurable_fst).mul odd_lifted_density_measurable + · intro u B _ + exact oddKernel_apply (oddLift u) B + · intro t + exact initialIncoming_integrable s t + · intro u t + exact mul_nonneg (evenDensity_nonneg s u) (oddDensity_nonneg (oddLift u) t) + · intro t + exact initialIncoming_integral s hsup t + +theorem regTwoMeasure_eq_density : + regTwoMeasure = volume.withDensity (fun u ↦ ENNReal.ofReal (regTwoDensity u)) := by + rw [regTwoMeasure, oddKernel_eq_density] + apply kernel_density_conservation evenRealKernel (oddDensity regenerationState) regTwoDensity + (fun y u ↦ transitionDensity .even (evenLift y).1 u) + (odd_input_measurable regenerationState) (oddDensity_nonneg regenerationState) + · exact ((odd_input_measurable regenerationState).comp measurable_fst).mul even_lifted_density_measurable + · intro y B _ + exact evenKernel_apply (evenLift y) B + · intro u + exact regTwoIncoming_integrable u + · intro y u + exact mul_nonneg (oddDensity_nonneg regenerationState y) (evenDensity_nonneg (evenLift y) u) + · intro u + exact regTwoIncoming_integral u + +theorem regThreeMeasure_eq_density : + regThreeMeasure = volume.withDensity (fun t ↦ ENNReal.ofReal (regThreeDensity t)) := by + rw [regThreeMeasure, regTwoMeasure_eq_density] + apply kernel_density_conservation oddRealKernel regTwoDensity regThreeDensity + (fun u t ↦ transitionDensity .odd (oddLift u).1 t) regTwoDensity_measurable regTwoDensity_nonneg + · exact (regTwoDensity_measurable.comp measurable_fst).mul odd_lifted_density_measurable + · intro u B _ + exact oddKernel_apply (oddLift u) B + · intro t + exact regThreeIncoming_integrable t + · intro u t + exact mul_nonneg (regTwoDensity_nonneg u) (oddDensity_nonneg (oddLift u) t) + · intro t + exact regThreeIncoming_integral t + +end Erdos970Dependency.MarginalDensityMeasures + +end + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.DensityComparison +open NumberTheoryLean.BuchstabBridge NumberTheoryLean.DerivativeWeights NumberTheoryLean.WeightFutureIntegrals +open NumberTheoryLean.TransitionKernels +open Erdos970Dependency.WeightIntegrals Erdos970Dependency.InitialDensityFormulas +open Erdos970Dependency.MarginalDensityMeasures + +noncomputable def dominationConstant : ℝ := 48 * sieveA / phiEven (23 / 10) + +theorem dominationConstant_pos : 0 < dominationConstant := + div_pos (mul_pos (by norm_num) sieveA_pos) (phiEven_pos (by norm_num)) + +theorem initial_density_le (s : EvenState) (hs : 199 / 100 ≤ s.1) (hsup : s.1 ≤ 23 / 10) (t : ℝ) : + initialTwoDensity s t ≤ dominationConstant * regThreeDensity t := by + by_cases ht : 2 ≤ t + · rw [initialTwoDensity, regThreeDensity, + indicator_of_mem (show t ∈ Ici (2 : ℝ) from ht), indicator_of_mem (show t ∈ Ici (2 : ℝ) from ht)] + have hnum : 0 < W t * phiEven t := mul_pos (W_pos (by linarith)) (phiEven_pos (by linarith)) + have hden : 0 < phiEven s.1 := phiEven_pos (by linarith) + have hmin : 0 < phiEven (23 / 10) := phiEven_pos (by norm_num) + have hdenle : phiEven (23 / 10) ≤ phiEven s.1 := + phiEven_strictAntiOn.antitoneOn (by linarith : 1 < s.1) (by norm_num) hsup + calc + _ ≤ (W t * phiEven t / phiEven s.1) * (48 * regIntegral t) := + mul_le_mul_of_nonneg_left (initial_integral_le hs hsup ht) (div_pos hnum hden).le + _ ≤ (W t * phiEven t / phiEven (23 / 10)) * (48 * regIntegral t) := + mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_left hnum.le hmin hdenle) + (mul_nonneg (by norm_num) (regIntegral_nonneg ht)) + _ = dominationConstant * ((W t * phiEven t / sieveA) * regIntegral t) := by + unfold dominationConstant + field_simp [sieveA_pos.ne', hmin.ne'] + · rw [initialTwoDensity, regThreeDensity, + indicator_of_notMem (show t ∉ Ici (2 : ℝ) from ht), + indicator_of_notMem (show t ∉ Ici (2 : ℝ) from ht), mul_zero] + +theorem initial_real_measure_le (s : EvenState) (hs : 199 / 100 ≤ s.1) (hsup : s.1 ≤ 23 / 10) : + initialTwoMeasure s ≤ ENNReal.ofReal dominationConstant • regThreeMeasure := by + rw [initialTwoMeasure_eq_density s hsup, regThreeMeasure_eq_density, + ← withDensity_smul' (ENNReal.ofReal dominationConstant) (fun t ↦ ENNReal.ofReal (regThreeDensity t)) ENNReal.ofReal_ne_top] + apply withDensity_mono + apply Filter.Eventually.of_forall + intro t + change ENNReal.ofReal (initialTwoDensity s t) ≤ ENNReal.ofReal dominationConstant * ENNReal.ofReal (regThreeDensity t) + rw [← ENNReal.ofReal_mul dominationConstant_pos.le] + exact ENNReal.ofReal_le_ofReal (initial_density_le s hs hsup t) + +end Erdos970Dependency.DensityComparison + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/DensityConservation.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/DensityConservation.lean new file mode 100644 index 0000000000000000000000000000000000000000..95d661bb9dafdb378e5e6ad8af841b1ef45a28db --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/DensityConservation.lean @@ -0,0 +1,170 @@ +import Mathlib.Probability.Kernel.Composition.MeasureComp +import OAI.NumberTheory.Jacobsthal.Estimates.InvariantFiniteness + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory +namespace Erdos970Dependency.IncomingDensityIdentities +open NumberTheoryLean.DerivativeWeights NumberTheoryLean.FinitePathGeometry +open Erdos970Dependency.InvariantDensities + +noncomputable def incomingOdd (t s : ℝ) : ℝ := + oddDensity s * transitionDensity .odd s t +noncomputable def incomingEven (t s : ℝ) : ℝ := + evenDensity s * transitionDensity .even s t + +theorem incomingOdd_formula {t : ℝ} (ht : 2 ≤ t) (s : ℝ) : + incomingOdd t s = (Icc (1 : ℝ) (t + 1)).indicator + (fun s ↦ (W t * phiEven t) * oddFactor s) s := by + classical + by_cases hs1 : 1 ≤ s + · rw [incomingOdd, oddDensity, indicator_of_mem (show s ∈ Ici (1 : ℝ) from hs1)] + by_cases hst : s ≤ t + 1 + · have hmax : max 2 (s - 1) ≤ t := max_le ht (by linarith) + rw [transitionDensity, minRatio, weight, Side.flip, weight, + NumberTheoryLean.TransitionKernels.tailDensity, + indicator_of_mem (show t ∈ Ici (max 2 (s - 1)) from hmax), + indicator_of_mem (show s ∈ Icc (1 : ℝ) (t + 1) from ⟨hs1, hst⟩)] + field_simp [(phiOdd_pos s).ne'] + · have hmax : ¬max 2 (s - 1) ≤ t := by + intro h + have := le_trans (le_max_right (2 : ℝ) (s - 1)) h + linarith + rw [transitionDensity, minRatio, weight, Side.flip, weight, + NumberTheoryLean.TransitionKernels.tailDensity, + indicator_of_notMem (show t ∉ Ici (max 2 (s - 1)) from hmax), + indicator_of_notMem (show s ∉ Icc (1 : ℝ) (t + 1) from fun h ↦ hst h.2), mul_zero] + · rw [incomingOdd, oddDensity, + indicator_of_notMem (show s ∉ Ici (1 : ℝ) from hs1), zero_mul, + indicator_of_notMem (show s ∉ Icc (1 : ℝ) (t + 1) from fun h ↦ hs1 h.1)] + +theorem incomingEven_formula (t s : ℝ) : + incomingEven t s = (Icc (2 : ℝ) (t + 1)).indicator (fun _ ↦ W t * phiOdd t) s := by + classical + by_cases hs2 : 2 ≤ s + · rw [incomingEven, evenDensity, indicator_of_mem (show s ∈ Ici (2 : ℝ) from hs2)] + by_cases hst : s ≤ t + 1 + · rw [transitionDensity, minRatio, weight, Side.flip, weight, + NumberTheoryLean.TransitionKernels.tailDensity, + indicator_of_mem (show t ∈ Ici (s - 1) by change s - 1 ≤ t; linarith), + indicator_of_mem (show s ∈ Icc (2 : ℝ) (t + 1) from ⟨hs2, hst⟩)] + field_simp [(phiEven_pos (by linarith : 1 < s)).ne'] + · rw [transitionDensity, minRatio, weight, Side.flip, weight, + NumberTheoryLean.TransitionKernels.tailDensity, + indicator_of_notMem (show t ∉ Ici (s - 1) by change ¬s - 1 ≤ t; linarith), + indicator_of_notMem (show s ∉ Icc (2 : ℝ) (t + 1) from fun h ↦ hst h.2), mul_zero] + · rw [incomingEven, evenDensity, + indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs2), zero_mul, + indicator_of_notMem (show s ∉ Icc (2 : ℝ) (t + 1) from fun h ↦ hs2 h.1)] + +theorem incomingOdd_zero {t : ℝ} (ht : t < 2) (s : ℝ) : incomingOdd t s = 0 := by + unfold incomingOdd transitionDensity + simp only [minRatio, weight, Side.flip, NumberTheoryLean.TransitionKernels.tailDensity] + rw [indicator_of_notMem (show t ∉ Ici (max 2 (s - 1)) from fun h ↦ + (not_le_of_gt ht) (le_trans (le_max_left _ _) h)), mul_zero] + +theorem incomingEven_zero {t : ℝ} (ht : t < 1) (s : ℝ) : incomingEven t s = 0 := by + by_cases hs : 2 ≤ s + · unfold incomingEven transitionDensity + simp only [minRatio, weight, Side.flip, NumberTheoryLean.TransitionKernels.tailDensity] + rw [indicator_of_notMem (show t ∉ Ici (s - 1) by change ¬s - 1 ≤ t; linarith), mul_zero] + · rw [incomingEven, evenDensity, indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs), zero_mul] + +theorem incomingOdd_integral (t : ℝ) : (∫ s, incomingOdd t s) = evenDensity t := by + by_cases ht : 2 ≤ t + · simp_rw [incomingOdd_formula ht] + rw [integral_indicator measurableSet_Icc, integral_const_mul, + integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le (show (1 : ℝ) ≤ t + 1 by linarith), + integral_oddFactor (by linarith : (1 : ℝ) ≤ t + 1), + evenDensity, indicator_of_mem (show t ∈ Ici (2 : ℝ) from ht)] + unfold W + field_simp + ring + · simp only [incomingOdd_zero (lt_of_not_ge ht), integral_zero] + rw [evenDensity, indicator_of_notMem (show t ∉ Ici (2 : ℝ) from ht)] + +theorem incomingEven_integral (t : ℝ) : (∫ s, incomingEven t s) = oddDensity t := by + by_cases ht : 1 ≤ t + · simp_rw [incomingEven_formula] + rw [integral_indicator measurableSet_Icc, integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le (show (2 : ℝ) ≤ t + 1 by linarith), + intervalIntegral.integral_const, oddDensity, indicator_of_mem (show t ∈ Ici (1 : ℝ) from ht)] + simp only [smul_eq_mul] + unfold W oddFactor + field_simp + ring + · simp only [incomingEven_zero (lt_of_not_ge ht), integral_zero] + rw [oddDensity, indicator_of_notMem (show t ∉ Ici (1 : ℝ) from ht)] + +theorem incomingOdd_integrable (t : ℝ) : Integrable (incomingOdd t) := by + by_cases ht : 2 ≤ t + · rw [show incomingOdd t = (Icc (1 : ℝ) (t + 1)).indicator + (fun s ↦ (W t * phiEven t) * oddFactor s) from funext (incomingOdd_formula ht)] + apply (integrable_indicator_iff measurableSet_Icc).mpr + apply ContinuousOn.integrableOn_Icc + intro s hs + apply ContinuousAt.continuousWithinAt + unfold oddFactor + exact continuousAt_const.mul (continuousAt_const.sub + (continuousAt_const.div (continuousAt_id.pow 2) (by nlinarith [hs.1]))) + · rw [show incomingOdd t = 0 from funext (incomingOdd_zero (lt_of_not_ge ht))] + exact integrable_zero _ _ _ + +theorem incomingEven_integrable (t : ℝ) : Integrable (incomingEven t) := by + rw [show incomingEven t = (Icc (2 : ℝ) (t + 1)).indicator (fun _ ↦ W t * phiOdd t) + from funext (incomingEven_formula t)] + exact (integrable_indicator_iff measurableSet_Icc).mpr continuous_const.integrableOn_Icc + +end Erdos970Dependency.IncomingDensityIdentities + +end + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.DensityConservation + +theorem kernel_density_conservation (K : Kernel ℝ ℝ) (d e : ℝ → ℝ) (k : ℝ → ℝ → ℝ) + (hd : Measurable d) (hd0 : ∀ s, 0 ≤ d s) + (hprod : Measurable (fun z : ℝ × ℝ ↦ d z.1 * k z.1 z.2)) + (hkernel : ∀ s (B : Set ℝ), MeasurableSet B → K s B = ∫⁻ t in B, ENNReal.ofReal (k s t)) + (hint : ∀ t, Integrable (fun s ↦ d s * k s t)) + (hpos : ∀ s t, 0 ≤ d s * k s t) + (hconserve : ∀ t, (∫ s, d s * k s t) = e t) : + K ∘ₘ (volume.withDensity (fun s ↦ ENNReal.ofReal (d s))) = + volume.withDensity (fun t ↦ ENNReal.ofReal (e t)) := by + apply Measure.ext + intro B hB + rw [Measure.bind_apply hB K.aemeasurable] + have hdensity := lintegral_withDensity_eq_lintegral_mul volume (ENNReal.measurable_ofReal.comp hd) + (K.measurable_coe hB) + simp only [Function.comp_def, Pi.mul_apply] at hdensity + rw [hdensity] + simp_rw [hkernel _ _ hB] + have hrewrite (s : ℝ) : ENNReal.ofReal (d s) * (∫⁻ t in B, ENNReal.ofReal (k s t)) = + ∫⁻ t in B, ENNReal.ofReal (d s * k s t) := by + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro t + exact (ENNReal.ofReal_mul (hd0 s)).symm + simp_rw [hrewrite] + have hm : Measurable (Function.uncurry (fun s t : ℝ ↦ ENNReal.ofReal (d s * k s t))) := by + change Measurable (fun z : ℝ × ℝ ↦ ENNReal.ofReal (d z.1 * k z.1 z.2)) + simpa only [Function.comp_def] using ENNReal.measurable_ofReal.comp hprod + rw [lintegral_lintegral_swap (μ := volume) (ν := volume.restrict B) hm.aemeasurable] + simp_rw [← ofReal_integral_eq_lintegral_ofReal (hint _) (Eventually.of_forall (fun s ↦ hpos s _)), + hconserve] + exact (withDensity_apply _ hB).symm + +end Erdos970Dependency.DensityConservation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/HarmonicReferenceMeasure.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/HarmonicReferenceMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..07745dd7f38ad4cbec596d5eec5d89811173f0d8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/HarmonicReferenceMeasure.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.WeightedMonotoneBound +import OAI.NumberTheory.Jacobsthal.Primes.HighPrimeRemoval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.HarmonicReferenceMeasure + +open _root_.MeasureTheory _root_.Set +open ErdosMonotoneQuadrature ErdosPrimeInputs.PrimeEndpoints + +noncomputable def referenceMeasure (u v : ℝ) : Measure ℝ := + reciprocalMeasure (volume.restrict (Icc u v)) u + +theorem referenceMeasure_finite {u v : ℝ} (hu : 0 < u) : IsFiniteMeasure (referenceMeasure u v) := + reciprocalMeasure_finite _ hu + +theorem referenceMeasure_real {u v : ℝ} (hu : 0 < u) {J : Set ℝ} + (hJ : MeasurableSet J) (hsub : J ⊆ Icc u v) : + (referenceMeasure u v).real J=∫ x in J,(1:ℝ)/x := by + rw [referenceMeasure,reciprocalMeasure_real _ hu hJ,Measure.restrict_restrict hJ, + inter_eq_left.mpr hsub] + apply setIntegral_congr_fun hJ + intro x hx + rw [reciprocalWeight_eq (hsub hx).1,one_div] + +theorem referenceMeasure_weightedIntegral {u v : ℝ} (hu : 0 < u) (g : ℝ → ℝ) {J : Set ℝ} + (hJ : MeasurableSet J) (hsub : J ⊆ Icc u v) : + (∫ x in J,g x/x ∂referenceMeasure u v)=∫ x in J,g x/x^2 := by + rw [referenceMeasure,reciprocalMeasure_integral _ hu _ hJ,Measure.restrict_restrict hJ, + inter_eq_left.mpr hsub] + apply setIntegral_congr_fun hJ + intro x hx + dsimp only + rw [reciprocalWeight_eq (hsub hx).1] + simp only [div_eq_mul_inv,pow_two,mul_inv_rev] + ring + +theorem intervalGuard_subset {u v a b : ℝ} (hua : u ≤ a) (hbv : b ≤ v) (lc rc : Bool) : + {x | intervalGuard lc rc a b x} ⊆ Icc u v := by + intro x hx + have ha : a ≤ x := by cases lc <;> simp only [intervalGuard,ite_true,Bool.false_eq_true,ite_false] at hx <;> linarith [hx.1] + have hb : x ≤ b := by cases rc <;> simp only [intervalGuard,ite_true,Bool.false_eq_true,ite_false] at hx <;> linarith [hx.2] + exact ⟨hua.trans ha,hb.trans hbv⟩ + +theorem intervalGuard_measurable (lc rc : Bool) (a b : ℝ) : MeasurableSet {x | intervalGuard lc rc a b x} := by + cases lc <;> cases rc <;> simp only [intervalGuard,ite_true,Bool.false_eq_true,ite_false] <;> measurability + +theorem referenceMeasure_interval {u v a b : ℝ} (hu : 0 < u) (hua : u ≤ a) (hab : a ≤ b) (hbv : b ≤ v) + (lc rc : Bool) : + (referenceMeasure u v).real {x | intervalGuard lc rc a b x}=Real.log b-Real.log a := by + rw [referenceMeasure_real hu (intervalGuard_measurable lc rc a b) (intervalGuard_subset hua hbv lc rc)] + have ha : 0 < a := hu.trans_le hua + have hb : 0 < b := ha.trans_le hab + have hbase : (∫ x in Ioc a b,(1:ℝ)/x)=Real.log b-Real.log a := by + rw [← intervalIntegral.integral_of_le hab,integral_one_div_of_pos ha hb,Real.log_div (ne_of_gt hb) (ne_of_gt ha)] + cases lc <;> cases rc + · change (∫ x in Ioo a b,(1:ℝ)/x)=_ + rw [← integral_Ioc_eq_integral_Ioo] + exact hbase + · exact hbase + · change (∫ x in Ico a b,(1:ℝ)/x)=_ + rw [integral_Ico_eq_integral_Ioc] + exact hbase + · change (∫ x in Icc a b,(1:ℝ)/x)=_ + rw [integral_Icc_eq_integral_Ioc] + exact hbase + +end NumberTheoryLean.HarmonicReferenceMeasure + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ImplicitDerivatives.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ImplicitDerivatives.lean new file mode 100644 index 0000000000000000000000000000000000000000..a60e972135b9be2cfe8a193fcdacc4cfba14d5e1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ImplicitDerivatives.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.BivariateCalculus + +namespace OAI + +namespace Erdos970 + +section + +open Filter +open scoped Topology +namespace ErdosImplicitCurvature + +theorem graph_zero_near (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} (hI : IsOpen I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) : + (fun t => peval Q t (f t)) =ᶠ[𝓝 x] (fun _ => 0) := by + filter_upwards [hI.mem_nhds hx] with t ht + exact hcurve t ht + +theorem implicit_first_equation (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hf : DifferentiableOn ℝ f I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) : + peval (partialX Q) x (f x)+peval (partialY Q) x (f x)*deriv f x = 0 := by + have hd := hasDerivAt_peval_graph Q f (deriv f x) x + (hf.differentiableAt (hI.mem_nhds hx)).hasDerivAt + have hz := (hasDerivAt_const x (0 : ℝ)).congr_of_eventuallyEq + (graph_zero_near Q f hI hcurve hx) + exact hd.unique hz + +theorem implicit_first_derivative (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hf : DifferentiableOn ℝ f I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) + (hQy : peval (partialY Q) x (f x) ≠ 0) : + deriv f x = -peval (partialX Q) x (f x)/peval (partialY Q) x (f x) := by + apply (eq_div_iff hQy).mpr + have h := implicit_first_equation Q f hI hf hcurve hx + nlinarith only [h] + +theorem implicit_second_equation (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hf : ContDiffOn ℝ 2 f I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) : + peval (partialX (partialX Q)) x (f x) + + 2*peval (partialX (partialY Q)) x (f x)*deriv f x + + peval (partialY (partialY Q)) x (f x)*(deriv f x)^2 + + peval (partialY Q) x (f x)*deriv (deriv f) x = 0 := by + have hf1 : DifferentiableOn ℝ f I := hf.differentiableOn (by norm_num) + have hdf : ContDiffOn ℝ 1 (deriv f) I := hf.deriv_of_isOpen hI (by norm_num) + have hd1 := (hf1.differentiableAt (hI.mem_nhds hx)).hasDerivAt + have hd2 := ((hdf.differentiableOn (by norm_num)).differentiableAt (hI.mem_nhds hx)).hasDerivAt + have hPx := hasDerivAt_peval_graph (partialX Q) f (deriv f x) x hd1 + have hPy := hasDerivAt_peval_graph (partialY Q) f (deriv f x) x hd1 + have hactual := hPx.add (hPy.mul hd2) + have he : (fun t => peval (partialX Q) t (f t)+peval (partialY Q) t (f t)*deriv f t) + =ᶠ[𝓝 x] (fun _ => 0) := by + filter_upwards [hI.mem_nhds hx] with t ht + exact implicit_first_equation Q f hI hf1 hcurve ht + have hz := (hasDerivAt_const x (0 : ℝ)).congr_of_eventuallyEq he + have h := hactual.unique hz + rw [mixed_partials Q] at h + linear_combination h + +end ErdosImplicitCurvature + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/IntegralDifferenceBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/IntegralDifferenceBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..f175e24f5d9b79a4023fbe846055c10823f51c3a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/IntegralDifferenceBound.lean @@ -0,0 +1,42 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +open MeasureTheory Set +namespace ErdosContinuousBoundary + +theorem integral_upper_difference_bound + (F G : ℝ → ℝ) (hF : Continuous F) (hG : Continuous G) + (a b D : ℝ) (ha : a ∈ Icc 1 2) (hD : 0 ≤ D) + (hFG : ∀ x, |F x-G x| ≤ D) (hGb : ∀ x, |G x| ≤ 1) : + |(∫ x in (1:ℝ)..a,F x)-(∫ x in (1:ℝ)..b,G x)| ≤ D+|a-b| := by + have hs := intervalIntegral.integral_sub (hF.intervalIntegrable (μ:=volume) 1 a) (hG.intervalIntegrable (μ:=volume) 1 a) + have hadd := intervalIntegral.integral_add_adjacent_intervals + (hG.intervalIntegrable (μ:=volume) 1 b) (hG.intervalIntegrable (μ:=volume) b a) + have he : (∫ x in (1:ℝ)..a,F x)-(∫ x in (1:ℝ)..b,G x) = + (∫ x in (1:ℝ)..a,F x-G x)+(∫ x in b..a,G x) := by + rw [hs] + linarith + have hfirst := intervalIntegral.norm_integral_le_of_norm_le_const (a:=1) (b:=a) + (f:=fun x => F x-G x) (C:=D) (fun x _ => by simpa only [Real.norm_eq_abs] using hFG x) + have hsecond := intervalIntegral.norm_integral_le_of_norm_le_const (a:=b) (b:=a) + (f:=G) (C:=1) (fun x _ => by simpa only [Real.norm_eq_abs] using hGb x) + rw [Real.norm_eq_abs,abs_of_nonneg (by linarith [ha.1] : 0 ≤ a-1)] at hfirst + rw [Real.norm_eq_abs,one_mul] at hsecond + have hfirst' : |∫ x in (1:ℝ)..a,F x-G x| ≤ D := by + apply hfirst.trans + nlinarith [ha.2] + rw [he] + exact (abs_add_le _ _).trans (add_le_add hfirst' hsecond) + +end ErdosContinuousBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/JointModelDensity.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/JointModelDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d69cfd4154adf1c72ce0609398715ca8568abea --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/JointModelDensity.lean @@ -0,0 +1,165 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.JointModelCount +import OAI.NumberTheory.Jacobsthal.Sieve.OddEulerCorrection + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceMoments +open ErdosRandomVariance +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem jointDensity_nonneg (P S : Finset ℕ) (hP : ∀ t ∈ P,t.Prime) : + 0 ≤ jointDensity P S := by + apply Finset.prod_nonneg + intro t ht + let : NeZero t := ⟨(hP t ht).ne_zero⟩ + exact sub_nonneg.mpr (positionDensity_bounds S t).2 + +theorem odd_position_density_lower (P S : Finset ℕ) (hP : ∀ t ∈ P,3 ≤ t) (hS : S.card ≤ 2) : + (1 : ℝ)/2*(sieveProduct P)^2 ≤ jointDensity P S := by + have hh := ErdosOddEulerCorrection.odd_two_class_product_lower P hP + apply hh.trans + apply Finset.prod_le_prod₀ + · intro t ht + have ht3 : (3 : ℝ) ≤ t := by exact_mod_cast hP t ht + exact sub_nonneg.mpr ((div_le_one (by linarith)).mpr (by linarith)) + · intro t ht + let : NeZero t := ⟨by have := hP t ht;omega⟩ + exact sub_le_sub_left (positionDensity_le_two S hS t) 1 + +theorem nonzero_jointDensity_lower (P S : Finset ℕ) (hP : ∀ t ∈ P,t.Prime) + (hS : S.card ≤ 2) (hne : jointDensity P S ≠ 0) : + (1 : ℝ)/2*(sieveProduct P)^2 ≤ jointDensity P S := by + by_cases h2 : 2 ∈ P + · have hodd (t : ℕ) (ht : t ∈ P.erase 2) : 3 ≤ t := by + have hh := Finset.mem_erase.mp ht + have hp := (hP t hh.2).two_le + omega + have hO := odd_position_density_lower (P.erase 2) S hodd hS + have hO0 := jointDensity_nonneg (P.erase 2) S (fun t ht => hP t (Finset.mem_erase.mp ht).2) + have hT := nonzero_positionDensity_two P S hS hne h2 + have hK : jointDensity P S = (1-positionDensity S 2)*jointDensity (P.erase 2) S := + (Finset.mul_prod_erase P (fun t => 1-positionDensity S t) h2).symm + have hV : sieveProduct P = (1/2 : ℝ)*sieveProduct (P.erase 2) := by + rw [sieveProduct,← Finset.mul_prod_erase P (fun t => 1-1/(t : ℝ)) h2] + norm_num [sieveProduct] + have hmul := mul_le_mul_of_nonneg_right (show (1 : ℝ)/2 ≤ 1-positionDensity S 2 by linarith) hO0 + rw [hV,hK] + nlinarith [sq_nonneg (sieveProduct (P.erase 2))] + · exact odd_position_density_lower P S (fun t ht => by + have hp := (hP t ht).two_le + have hn : t ≠ 2 := fun he => h2 (he ▸ ht) + omega) hS + +end ErdosVarianceMoments + +end + +section + +open _root_.Filter +namespace ErdosVarianceUniformMoments +open NumberTheoryLean ErdosVarianceMoments ErdosRandomVariance ErdosInverseEuler +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def densityInverseConstant : ℝ := 8*(Real.exp Real.eulerMascheroniConstant)^2 + +theorem densityInverseConstant_pos : 0 < densityInverseConstant := by + dsimp [densityInverseConstant] + positivity + +theorem actual_sieveProduct (w : ℝ) : + sieveProduct (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) = SmallSieveFinite.smallEuler ⌊w⌋₊ := by + simp only [sieveProduct,SmallSieveFinite.smallEuler,one_div] + +theorem uniform_density_inverse : ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ + ∀ S : Finset ℕ,S.card ≤ 2 → jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S ≠ 0 → + (jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S)⁻¹ ≤ + densityInverseConstant*(Real.log w)^2 := by + filter_upwards [smallEuler_log_bounds] with w hw + refine ⟨hw.1,?_⟩ + intro S hS hne + let P := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V := SmallSieveFinite.smallEuler ⌊w⌋₊ + let K := jointDensity P S + let B := 2*Real.exp Real.eulerMascheroniConstant*Real.log w + have hP (t : ℕ) (ht : t ∈ P) : t.Prime := (LargePrimeDeletion.mem_cutoffPrimes.mp ht).1 + have hlow := nonzero_jointDensity_lower P S hP hS hne + rw [actual_sieveProduct] at hlow + have hV : 0 < V := hw.2.1 + have hVB : 1 ≤ V*B := by + have hh := mul_le_mul_of_nonneg_left hw.2.2.2 hV.le + change V*V⁻¹ ≤ V*B at hh + simpa only [mul_inv_cancel₀ hV.ne'] using hh + have hsq : (1 : ℝ) ≤ V^2*B^2 := by + have hh := pow_le_pow_left₀ (by norm_num : (0 : ℝ) ≤ 1) hVB 2 + simpa only [one_pow,mul_pow] using hh + have hm := mul_le_mul_of_nonneg_right hlow (sq_nonneg B) + have hKpos : 0 < K := (by dsimp [K,V] at *;positivity : 0 < (1 : ℝ)/2*V^2).trans_le hlow + have hb : 2*B^2 = densityInverseConstant*(Real.log w)^2 := by + dsimp [B,densityInverseConstant] + ring + have hmain : 1 ≤ (densityInverseConstant*(Real.log w)^2)*K := by + rw [← hb] + dsimp [K,V] at * + nlinarith + rw [← one_div] + exact (div_le_iff₀ hKpos).mpr hmain + +end ErdosVarianceUniformMoments + +end + +section + +namespace ErdosVarianceMoments +open NumberTheoryLean ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem jointDensity_le_one (P S : Finset ℕ) (hP : ∀ t ∈ P,t.Prime) : jointDensity P S ≤ 1 := by + apply Finset.prod_le_one₀ + · intro t ht + let : NeZero t := ⟨(hP t ht).ne_zero⟩ + exact sub_nonneg.mpr (positionDensity_bounds S t).2 + · intro t ht + let : NeZero t := ⟨(hP t ht).ne_zero⟩ + have hh := (positionDensity_bounds S t).1 + linarith + +theorem jointDensity_split (w : ℝ) (H : ℕ) (S : Finset ℕ) : + jointDensity (divisorPrimes w H) S*jointDensity (coprimePrimes w H) S = + jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S := by + unfold jointDensity divisorPrimes coprimePrimes + exact Finset.prod_filter_mul_prod_filter_not _ _ _ + +theorem model_normalization_identity (R xi w : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 0 < R) (hxi : 0 ≤ xi) (hH : 0 < H) : + atomWeight R xi w H C0*(divisorModulus w H : ℝ)* + ((coprimeModulus w H).totient : ℝ)* + (modelLength R xi (H : ℝ) (C0 : ℝ)*((H.totient : ℝ)/(H : ℝ))) = 1 := by + have hHN : (H : ℝ) ≠ 0 := by exact_mod_cast hH.ne' + have hphi : (H.totient : ℝ) ≠ 0 := by exact_mod_cast (Nat.totient_pos.mpr hH).ne' + have hT0 : (divisorModulus w H : ℝ) ≠ 0 := by exact_mod_cast (divisorModulus_pos w H).ne' + have hT1 : ((coprimeModulus w H).totient : ℝ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (coprimeModulus_pos w H)).ne' + have hY : 0 < modelLength R xi (H : ℝ) (C0 : ℝ) := by + have hHR : (0 : ℝ) < H := by exact_mod_cast hH + dsimp [modelLength,interceptScale] + positivity + unfold atomWeight + field_simp + +end ErdosVarianceMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/LipschitzMeasureQuadrature.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/LipschitzMeasureQuadrature.lean new file mode 100644 index 0000000000000000000000000000000000000000..18e6ea1eabb4485dba82eae44ed7d5d1fc84ab85 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/LipschitzMeasureQuadrature.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.WeightedMonotoneBound + +namespace OAI + +namespace Erdos970 + +section + +open MeasureTheory Set +namespace ErdosContinuousBoundary +open ErdosMonotoneQuadrature + +theorem lipschitz_add_linear_monotone {g : ℝ → ℝ} {L : NNReal} + (hg : LipschitzOnWith L g (Icc 1 2)) : + MonotoneOn (fun x => g x+(L:ℝ)*x) (Icc 1 2) := by + intro x hx y hy hxy + have h := hg.dist_le_mul x hx y hy + rw [Real.dist_eq,Real.dist_eq,abs_of_nonpos (sub_nonpos.mpr hxy)] at h + have hle := le_abs_self (g x-g y) + dsimp only + nlinarith + +theorem lipschitz_measure_discrepancy + (μ ν : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (g : ℝ → ℝ) (L : NNReal) (D E : ℝ) (hD : 0 ≤ D) + (hg : LipschitzOnWith L g (Icc 1 2)) (hbound : ∀ x ∈ Icc 1 2,|g x| ≤ D) + (hd : ∀ S : Set ℝ,S.OrdConnected → S ⊆ Icc 1 2 → |μ.real S-ν.real S| ≤ E) + {J : Set ℝ} (hJ : J.OrdConnected) (hsub : J ⊆ Icc 1 2) : + |(∫ x in J,g x ∂μ)-(∫ x in J,g x ∂ν)| ≤ 3*E*(D+4*(L:ℝ)) := by + let A : ℝ → ℝ := fun x => g x+(L:ℝ)*x + let B : ℝ → ℝ := fun x => (L:ℝ)*x + have hL : 0 ≤ (L:ℝ) := L.property + have hA : MonotoneOn A (Icc 1 2) := lipschitz_add_linear_monotone hg + have hB : MonotoneOn B (Icc 1 2) := fun x _ y _ hxy => mul_le_mul_of_nonneg_left hxy hL + have hBb : ∀ x ∈ Icc 1 2,|B x| ≤ 2*(L:ℝ) := by + intro x hx + rw [abs_of_nonneg (mul_nonneg hL (by linarith [hx.1]))] + nlinarith [hx.2] + have hAb : ∀ x ∈ Icc 1 2,|A x| ≤ D+2*(L:ℝ) := by + intro x hx + exact (abs_add_le _ _).trans (add_le_add (hbound x hx) (hBb x hx)) + have hqa := signed_monotone_integral_discrepancy μ ν 1 2 (D+2*(L:ℝ)) E + (by positivity) A (Or.inl hA) hAb hd hJ hsub + have hqb := signed_monotone_integral_discrepancy μ ν 1 2 (2*(L:ℝ)) E + (by positivity) B (Or.inl hB) hBb hd hJ hsub + have hAm : IntegrableOn A J μ := (hA.integrableOn_isCompact isCompact_Icc).mono_set hsub + have hAn : IntegrableOn A J ν := (hA.integrableOn_isCompact isCompact_Icc).mono_set hsub + have hBm : IntegrableOn B J μ := (hB.integrableOn_isCompact isCompact_Icc).mono_set hsub + have hBn : IntegrableOn B J ν := (hB.integrableOn_isCompact isCompact_Icc).mono_set hsub + have he : g = fun x => A x-B x := by funext x; dsimp [A,B]; ring + have heq : (∫ x in J,g x ∂μ)-(∫ x in J,g x ∂ν) = + ((∫ x in J,A x ∂μ)-(∫ x in J,A x ∂ν))- + ((∫ x in J,B x ∂μ)-(∫ x in J,B x ∂ν)) := by + rw [he,integral_sub hAm hBm,integral_sub hAn hBn] + ring + rw [heq] + calc + _ ≤ |(∫ x in J,A x ∂μ)-(∫ x in J,A x ∂ν)|+ + |(∫ x in J,B x ∂μ)-(∫ x in J,B x ∂ν)| := abs_sub _ _ + _ ≤ 3*E*(D+2*(L:ℝ))+3*E*(2*(L:ℝ)) := add_le_add hqa hqb + _ = _ := by ring + +end ErdosContinuousBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/LiteralCompactRemoval.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/LiteralCompactRemoval.lean new file mode 100644 index 0000000000000000000000000000000000000000..e88d7a79614e960e96826af0f22860de8b093498 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/LiteralCompactRemoval.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceNodeCoordinates +import OAI.NumberTheory.Jacobsthal.Primes.LiteralUniformPrimeTail + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.LiteralCompactRemoval + +open _root_.Set _root_.Filter _root_.Finset +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualPrimeHigh PrimeFamilyOccupation LiteralPrimeOccupation SourceNodeCoordinates +open ContinuousCompactHighError SourceLowRemoval DerivativeWeights +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def uncappedFamilyValue (H : Side → ℝ×ℝ → ℝ) (w ell : ℝ) (start : Node) : ℝ := + (start.gap^2/weight start.side start.ratio)* + (∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*nodeReward H w start ps) + +theorem compact_exponential_envelope {H : Side → ℝ×ℝ → ℝ} {A K : ℝ} + (hA : 0 ≤ A) (hbound : ∀ i x,|H i x| ≤ A) + (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → H i (r,s)=0) + (w : ℝ) (start : Node) (ps : List ℕ) : + |nodeReward H w start ps| ≤ ((A+1)*Real.exp K)*Real.exp (-(terminal w start ps).gap) := by + by_cases hr : (terminal w start ps).gap ≤ K + · have he : 1 ≤ Real.exp (K-(terminal w start ps).gap) := Real.one_le_exp_iff.mpr (by linarith) + have hb := hbound (terminal w start ps).side ((terminal w start ps).gap,(terminal w start ps).ratio) + change |H _ _| ≤ _ + rw [mul_assoc,← Real.exp_add] + have hh := mul_le_mul_of_nonneg_left he (show 0 ≤ A+1 by linarith) + simp only [sub_eq_add_neg] at hh + linarith + · have hz := hsupport (terminal w start ps).side (terminal w start ps).gap (terminal w start ps).ratio (lt_of_not_ge hr) + simp only [nodeReward,hz,abs_zero] + positivity + +theorem weighted_sum_div (I : Finset (List ℕ)) (F : List ℕ → ℝ) (D : ℝ) : + (∑ ps ∈ I,prefixWeight ps*(F ps/D)) = (∑ ps ∈ I,prefixWeight ps*F ps)/D := by + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro ps _hp + ring + +theorem source_compact_family_removal {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {K : ℝ} (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → H i (r,s)=0) : + ∃ C w₀ : ℝ,0 ≤ C ∧ 1 < w₀ ∧ ∀ᶠ B : ℝ in atTop,∀ w : ℝ,w₀ ≤ w → + ∀ ell : ℝ,1 ≤ ell → ell ≤ B → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |uncappedFamilyValue H w ell start-familyValue H w ell ((Real.log B)^2) start| ≤ C/B := by + obtain ⟨A,hA,hbound⟩ := phase_compact_bound hH hcompact + let D := (A+1)*Real.exp K + have hD : 0 < D := by dsimp [D]; positivity + obtain ⟨M,w₀,hM,hw₀,hremove⟩ := removed_signed_reward_every_power + refine ⟨scaleConstant*M*D,w₀,by have hh := scaleConstant_pos; positivity,hw₀,?_⟩ + filter_upwards [hremove 1 (by norm_num) 3,eventually_ge_atTop (Real.exp 2)] with B hrem hBexp + intro w hw ell hell hellB start hi h199 h23 hcons hcut + have hB : 0 < B := (Real.exp_pos 2).trans_le hBexp + have hlogB : 2 ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hBexp + obtain ⟨hs,hr,_,_⟩ := source_node_bounds hB start hi h199 h23 hcons hcut + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + let F := nodeReward H w start + have hF : ∀ ps ∈ uncappedPrefixes w ell start,|F ps/D| ≤ Real.exp (-(1:ℝ)*(terminal w start ps).gap) := by + intro ps _hp + rw [abs_div,abs_of_pos hD] + apply (div_le_iff₀ hD).mpr + have h := compact_exponential_envelope hA hbound hsupport w start ps + simpa only [neg_mul,one_mul,mul_comm] using h + have herror := hrem w hw ell hell hellB start hcut hr hs hcons hsS (fun ps => F ps/D) hF + rw [weighted_sum_div,weighted_sum_div,← sub_div,abs_div,abs_of_pos hD] at herror + have hdiff := (div_le_iff₀ hD).mp herror + have hscale := node_scale_upper hB start hi h199 h23 hcons hcut + have hnormal : 0 ≤ start.gap^2/weight start.side start.ratio := div_nonneg (sq_nonneg _) (weight_pos hs).le + change |(start.gap^2/weight start.side start.ratio)*(∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*F ps)- + (start.gap^2/weight start.side start.ratio)*(∑ ps ∈ retainedPrefixes w ell ((Real.log B)^2) start,prefixWeight ps*F ps)| ≤ _ + rw [← mul_sub,abs_mul,abs_of_nonneg hnormal] + calc + _ ≤ (scaleConstant*B^2)*((M*B^(-(3:ℝ)))*D) := + mul_le_mul hscale hdiff (abs_nonneg _) (mul_nonneg scaleConstant_pos.le (sq_nonneg _)) + _ = _ := by + rw [Real.rpow_neg hB.le,Real.rpow_ofNat] + field_simp + +end NumberTheoryLean.LiteralCompactRemoval + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/LocalZeroLogDerivative.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/LocalZeroLogDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..c53de63c5b8adca2d76458db2b2b6c264e190798 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/LocalZeroLogDerivative.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.Jacobsthal.Primes.UniformDirichletBasepoint + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology BigOperators + +theorem exists_local_zero_log_derivative_constant : + ∃ C : ℝ, 0 < C ∧ ∀ (B : ℝ), 1 < B → ∀ f : ℂ → ℂ, + (∀ z ∈ Metric.closedBall (0 : ℂ) 1, AnalyticAt ℂ f z) → + f 0 = 1 → (∀ z ∈ Metric.closedBall (0 : ℂ) 1, ‖f z‖ ≤ B) → + ∃ S : Finset ℂ, (∀ z, z ∈ S ↔ ‖z‖ ≤ 19/20 ∧ f z = 0) ∧ + ∀ z : ℂ, ‖z‖ ≤ 17/20 → f z ≠ 0 → + ‖deriv f z / f z - ∑ rho ∈ S, (analyticOrderAt f rho).toNat / (z-rho)‖ ≤ + C * Real.log B := by + classical + let K : ℝ := 16 * (9/10)^2 / (((9/10)-(17/20))^3) + + 1 / (((39/40)^2/(19/20)-(19/20)) * Real.log ((39/40)/(19/20))) + refine ⟨max 1 K, lt_of_lt_of_le zero_lt_one (le_max_left _ _), ?_⟩ + intro B hB f hf hf0 hfB + have hfne : f 0 ≠ 0 := by rw [hf0]; norm_num + have hfinite : (_root_.Erdos970.zerosetKfR (19/20) (by norm_num) f).Finite := + _root_.Erdos970.lem_Contra_finiteKR (19/20) (by norm_num) (by norm_num) f hf ⟨0, by simp, hfne⟩ + have hex (rho : ℂ) : ∃ g : ℂ → ℂ, + rho ∈ _root_.Erdos970.zerosetKfR (19/20) (by norm_num) f → + AnalyticAt ℂ g rho ∧ g rho ≠ 0 ∧ + ∀ᶠ z in 𝓝 rho, f z = (z-rho)^(analyticOrderAt f rho).toNat * g z := by + by_cases hr : rho ∈ _root_.Erdos970.zerosetKfR (19/20) (by norm_num) f + · obtain ⟨g, hg⟩ := _root_.Erdos970.lem_analytic_zero_factor (39/40) (19/20) + (by norm_num) (by norm_num) (by norm_num) f hf hfne rho hr + exact ⟨g, fun _ => hg⟩ + · exact ⟨fun _ => 1, fun h => (hr h).elim⟩ + choose g hg using hex + refine ⟨hfinite.toFinset, ?_, ?_⟩ + · intro z + simp only [Set.Finite.mem_toFinset, _root_.Erdos970.zerosetKfR, Set.mem_ofPred_eq, + Metric.mem_closedBall, dist_zero_right] + · intro z hz hzne + have hz' : z ∈ Metric.closedBall (0 : ℂ) (17/20) \ + _root_.Erdos970.zerosetKfR (19/20) (by norm_num) f := by + refine ⟨by simpa only [Metric.mem_closedBall, dist_zero_right] using hz, ?_⟩ + intro h + exact hzne h.2 + have h := _root_.Erdos970.final_ineq1 B hB (17/20) (9/10) (39/40) (19/20) + (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num) + f hf hf0 hfinite hg + (fun w hw => hfB w ((Metric.closedBall_subset_closedBall (by norm_num : (39/40:ℝ) ≤ 1)) hw)) z hz' + apply h.trans + exact mul_le_mul_of_nonneg_right (le_max_right (1:ℝ) K) (Real.log_pos hB).le + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/NormalizedCollisionSmallness.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/NormalizedCollisionSmallness.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a323da1d81cb7f9c15c09ed6d0eafad1ca63f5e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/NormalizedCollisionSmallness.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Estimates.UniformCollisionError + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosLineCollision + +theorem normalized_collision_bound (I K C n R N L : ℝ) + (hK0 : 0 ≤ K) (hC : 0 ≤ C) (hn : 0 < n) (hN : 0 < N) (hL : 0 < L) + (hcollision : I^2 ≤ K*(C*N^2+I)) (hthin : K ≤ n*R/L^6) (hI : I ≤ n*N) : + (I/(n*N))^2 ≤ C*R/(n*L^6)+R/(N*L^6) := by + have hup : I^2 ≤ (n*R/L^6)*(C*N^2+n*N) := by + calc + _ ≤ K*(C*N^2+I) := hcollision + _ ≤ K*(C*N^2+n*N) := mul_le_mul_of_nonneg_left (add_le_add le_rfl hI) hK0 + _ ≤ _ := mul_le_mul_of_nonneg_right hthin (by positivity) + rw [div_pow] + calc + _ ≤ ((n*R/L^6)*(C*N^2+n*N))/(n*N)^2 := + div_le_div_of_nonneg_right hup (sq_nonneg _) + _ = _ := by field_simp + +end ErdosLineCollision + +end + +section + +open Filter +open scoped Topology +namespace ErdosSourceCollision +open ErdosLineCollision + +theorem uniform_normalized_collision (C eta eps : ℝ) (hC : 0 ≤ C) (heta : 0 < eta) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ inc K R N n : ℝ, + 1 < R → R ≤ z^((1 : ℝ)/100) → z^((93 : ℝ)/100) ≤ N → + eta*R/(4*Real.log R) ≤ n → 0 ≤ K → + inc^2 ≤ K*(C*N^2+inc) → K ≤ n*R/(Real.log z)^6 → inc ≤ n*N → + inc ≤ eps*n*N := by + filter_upwards [uniform_collision_error C eta eps hC heta heps] with z hz + refine ⟨hz.1,?_⟩ + intro inc K R N n hR hRz hN hcount hK hcoll hthin hI + have hz0 : 0 < z := by linarith [hz.1] + have hR0 : 0 < R := by linarith + have hlogR : 0 < Real.log R := Real.log_pos hR + have hn : 0 < n := (div_pos (mul_pos heta hR0) (mul_pos (by norm_num) hlogR)).trans_le hcount + have hNp : 0 < N := (Real.rpow_pos_of_pos hz0 _).trans_le hN + have hL : 0 < Real.log z := by linarith [hz.2.1] + have hsq := (normalized_collision_bound inc K C n R N (Real.log z) hK hC hn hNp hL hcoll hthin hI).trans + (hz.2.2 R N n hR hRz hN hcount) + have hratio : inc/(n*N) ≤ eps := by nlinarith [sq_nonneg (inc/(n*N)-eps)] + have hh := (div_le_iff₀ (mul_pos hn hNp)).mp hratio + nlinarith + +end ErdosSourceCollision + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/OmissionForceIntegral.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/OmissionForceIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c4657ddd0e302d7c337d8de29ccdbe2d23f07c9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/OmissionForceIntegral.lean @@ -0,0 +1,59 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.OmissionSeries + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.ReferenceAdmission + +theorem reciprocal_square_integral {a b : ℝ} (ha : 1 ≤ a) (hab : a ≤ b) : + (∫ x : ℝ in a..b,(x^2)⁻¹)=a⁻¹-b⁻¹ := by + have hn : ∀ x ∈ uIcc a b,x ≠ 0 := by + intro x hx + rw [uIcc_of_le hab] at hx + linarith [hx.1] + have hc : ContinuousOn (fun x : ℝ => (x^2)⁻¹) (uIcc a b) := + (continuous_id.pow 2).continuousOn.inv₀ (fun x hx => pow_ne_zero 2 (hn x hx)) + have hd : ∀ x ∈ uIcc a b,HasDerivAt (fun t : ℝ => -t⁻¹) ((x^2)⁻¹) x := by + intro x hx + simpa only [neg_neg] using! (hasDerivAt_inv (hn x hx)).neg + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd (hc.intervalIntegrable (μ := volume))] + ring + +theorem omissionForce_odd_integral (r b : ℝ) : + omissionForce .odd r b=∫ x : ℝ in upperCutoff .odd r b..baseCutoff b,(x^2)⁻¹ := by + rw [reciprocal_square_integral (upperCutoff_bounds .odd r b).1 (cutoff_le_base .odd r b)] + rfl + +theorem literal_omission_window (r b x : ℝ) : + x ∈ Ioc (upperCutoff .odd r b) (baseCutoff b) ↔ + 1 < x ∧ x ≤ 2 ∧ x ≤ b ∧ ¬childAdmitted .odd r x := by + constructor + · intro hx + have hx1 : 1 < x := (upperCutoff_bounds .odd r b).1.trans_lt hx.1 + have he : x ∈ Ioc 1 (upperCutoff .even r b) := ⟨hx1,hx.2⟩ + obtain ⟨_,hx2,hxb,_⟩ := (mem_upperCutoff .even r b x).mp he + refine ⟨hx1,hx2,hxb,?_⟩ + intro hgate + have ha := (mem_upperCutoff .odd r b x).mpr ⟨hx1,hx2,hxb,hgate⟩ + exact (not_lt_of_ge ha.2) hx.1 + · rintro ⟨hx1,hx2,hxb,hbad⟩ + have he := (mem_upperCutoff .even r b x).mpr ⟨hx1,hx2,hxb,trivial⟩ + refine ⟨?_,he.2⟩ + apply lt_of_not_ge + intro hcap + exact hbad ((mem_upperCutoff .odd r b x).mp ⟨hx1,hcap⟩).2.2.2 + +end ErdosContinuousOmission + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/OrderedTriangleFubini.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/OrderedTriangleFubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b4e1de4f7d21a752b8018c5d745310659c9754a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/OrderedTriangleFubini.lean @@ -0,0 +1,60 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.BoundedRectangleFubini + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings + +theorem ordered_triangle_swap {f : ℝ×ℝ → ℝ} (hf : Measurable f) {C : ℝ} (hC : 0 ≤ C) + (hbound : ∀ x ∈ Icc (1:ℝ) 2,∀ t ∈ Icc (1:ℝ) 2,|f (x,t)| ≤ C) : + (∫ x : ℝ in 1..2,∫ t : ℝ in 1..x,f (x,t))= + ∫ t : ℝ in 1..2,∫ x : ℝ in t..2,f (x,t) := by + classical + let g : ℝ×ℝ → ℝ := fun p => if p.2 ≤ p.1 then f p else 0 + have hg : Measurable g := Measurable.ite (measurableSet_le measurable_snd measurable_fst) hf measurable_const + have hb : ∀ x ∈ Icc (1:ℝ) 2,∀ t ∈ Icc (1:ℝ) 2,|g (x,t)| ≤ C := by + intro x hx t ht + dsimp only [g] + split_ifs + · exact hbound x hx t ht + · simpa only [abs_zero] using hC + have hs := bounded_rectangle_swap hg 1 2 1 2 C hb + have hleft (x : ℝ) (hx : x ∈ Icc (1:ℝ) 2) : + (∫ t in Icc (1:ℝ) 2,g (x,t))=∫ t : ℝ in 1..x,f (x,t) := by + have hset : Icc (1:ℝ) 2 ∩ Iic x=Icc 1 x := by + ext t + constructor + · rintro ⟨ht,hx'⟩; exact ⟨ht.1,hx'⟩ + · intro ht; exact ⟨⟨ht.1,ht.2.trans hx.2⟩,ht.2⟩ + change (∫ t in Icc (1:ℝ) 2,(Iic x).indicator (fun t => f (x,t)) t)=_ + rw [setIntegral_indicator measurableSet_Iic,hset,integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le hx.1] + have hright (t : ℝ) (ht : t ∈ Icc (1:ℝ) 2) : + (∫ x in Icc (1:ℝ) 2,g (x,t))=∫ x : ℝ in t..2,f (x,t) := by + have hset : Icc (1:ℝ) 2 ∩ Ici t=Icc t 2 := by + ext x + constructor + · rintro ⟨hx,ht'⟩; exact ⟨ht',hx.2⟩ + · intro hx; exact ⟨⟨ht.1.trans hx.1,hx.2⟩,hx.1⟩ + change (∫ x in Icc (1:ℝ) 2,(Ici t).indicator (fun x => f (x,t)) x)=_ + rw [setIntegral_indicator measurableSet_Ici,hset,integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le ht.2] + have he : (∫ x in Icc (1:ℝ) 2,∫ t in Icc (1:ℝ) 2,g (x,t))= + ∫ x in Icc (1:ℝ) 2,∫ t : ℝ in 1..x,f (x,t) := + setIntegral_congr_fun measurableSet_Icc hleft + have ho : (∫ t in Icc (1:ℝ) 2,∫ x in Icc (1:ℝ) 2,g (x,t))= + ∫ t in Icc (1:ℝ) 2,∫ x : ℝ in t..2,f (x,t) := + setIntegral_congr_fun measurableSet_Icc hright + rw [he,ho] at hs + simpa only [integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤2)] using hs + +end ErdosOmissionBindings + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/PairDensityExpansion.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/PairDensityExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..e0ee5b1ce3119b7f0be0532b8429b3a1d0d998bd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/PairDensityExpansion.lean @@ -0,0 +1,140 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.IntervalPairCount +import OAI.NumberTheory.Jacobsthal.Primes.PrimeHitRepresentative + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRandomVariance +attribute [local instance] Classical.propDecidable + +noncomputable def sieveProduct (P : Finset ℕ) : ℝ := ∏ p ∈ P, (1-(1 : ℝ)/p) +noncomputable def pairKernel (P : Finset ℕ) (i j : ℕ) : ℝ := + ∏ p ∈ P, (((1 : ℝ)/p)*congruenceIndicator p i j+(1-2/(p : ℝ))) +noncomputable def pairCoefficient (P S : Finset ℕ) : ℝ := + (∏ p ∈ S, (1 : ℝ)/p)*(∏ p ∈ P \ S, (1-2/(p : ℝ))) + +theorem prime_indicator_product (P : Finset ℕ) (hP : ∀ p ∈ P, p.Prime) (i j : ℕ) : + (∏ p ∈ P, congruenceIndicator p i j) = congruenceIndicator (∏ p ∈ P,p) i j := by + by_cases h : Nat.ModEq (∏ p ∈ P,p) i j + · have hh := (ErdosInverseHits.modEq_prime_product_iff P hP i j).mp h + rw [show congruenceIndicator (∏ p ∈ P,p) i j = 1 by simp [congruenceIndicator,h]] + apply Finset.prod_eq_one + intro p hp + simp [congruenceIndicator,hh p hp] + · have hn : ¬∀ p ∈ P, Nat.ModEq p i j := + fun hh => h ((ErdosInverseHits.modEq_prime_product_iff P hP i j).mpr hh) + push Not at hn + obtain ⟨p,hp,hn⟩ := hn + rw [show congruenceIndicator (∏ p ∈ P,p) i j = 0 by simp [congruenceIndicator,h]] + apply Finset.prod_eq_zero hp + simp [congruenceIndicator,hn] + +theorem pairCoefficient_nonneg (P S : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) : + 0 ≤ pairCoefficient P S := by + unfold pairCoefficient + apply mul_nonneg + · exact Finset.prod_nonneg (fun p _ => by positivity) + · apply Finset.prod_nonneg + intro p hp + have hh := hP p (Finset.mem_sdiff.mp hp).1 + apply sub_nonneg.mpr + exact (div_le_one (show (0 : ℝ) < p by exact_mod_cast hh.pos)).mpr (by exact_mod_cast hh.two_le) + +theorem pairKernel_expansion (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) (i j : ℕ) : + pairKernel P i j = ∑ S ∈ P.powerset, + pairCoefficient P S*congruenceIndicator (∏ p ∈ S,p) i j := by + rw [pairKernel, Finset.prod_add] + apply Finset.sum_congr rfl + intro S hS + have hpS : ∀ p ∈ S,p.Prime := fun p hp => hP p ((Finset.mem_powerset.mp hS) hp) + rw [Finset.prod_mul_distrib, prime_indicator_product S hpS] + unfold pairCoefficient + ring + +theorem pairCoefficient_sum (P : Finset ℕ) : + (∑ S ∈ P.powerset, pairCoefficient P S) = sieveProduct P := by + unfold pairCoefficient sieveProduct + rw [← Finset.prod_add] + apply Finset.prod_congr rfl + intro p _ + ring + +theorem pairCoefficient_div_product (P S : Finset ℕ) : + pairCoefficient P S/((∏ p ∈ S,p : ℕ) : ℝ) = + (∏ p ∈ S, ((1 : ℝ)/p)^2)*(∏ p ∈ P \ S, (1-2/(p : ℝ))) := by + unfold pairCoefficient + rw [Nat.cast_prod] + calc + _ = ((∏ p ∈ S,(1 : ℝ)/p)/(∏ p ∈ S,(p : ℝ)))*(∏ p ∈ P \ S,(1-2/(p : ℝ))) := by ring + _ = _ := by + rw [← Finset.prod_div_distrib] + congr 1 + apply Finset.prod_congr rfl + intro p _ + ring + +theorem pairCoefficient_normalized_sum (P : Finset ℕ) : + (∑ S ∈ P.powerset, pairCoefficient P S/((∏ p ∈ S,p : ℕ) : ℝ)) = (sieveProduct P)^2 := by + simp only [pairCoefficient_div_product] + rw [← Finset.prod_add] + unfold sieveProduct + rw [← Finset.prod_pow] + apply Finset.prod_congr rfl + intro p _ + ring + +theorem pairKernel_diagonal (P : Finset ℕ) (i : ℕ) : pairKernel P i i = sieveProduct P := by + unfold pairKernel sieveProduct + apply Finset.prod_congr rfl + intro p _ + simp only [congruenceIndicator, Nat.ModEq.refl, ite_true, mul_one] + ring + +theorem pairKernel_parity_zero (P : Finset ℕ) (h2 : 2 ∈ P) (i j : ℕ) + (hodd : ¬Nat.ModEq 2 i j) : pairKernel P i j = 0 := by + unfold pairKernel + apply Finset.prod_eq_zero h2 + norm_num [congruenceIndicator,hodd] + +theorem pairKernel_interval_sum (P : Finset ℕ) (hP : ∀ p ∈ P,p.Prime) (J : ℕ) : + (∑ i ∈ Finset.range J, ∑ j ∈ Finset.range J, pairKernel P i j) ≤ + ((J : ℝ)*sieveProduct P)^2+(J : ℝ)*sieveProduct P := by + have hexpand : + (∑ i ∈ Finset.range J, ∑ j ∈ Finset.range J, pairKernel P i j) = + ∑ S ∈ P.powerset, pairCoefficient P S* + (∑ i ∈ Finset.range J, ∑ j ∈ Finset.range J, congruenceIndicator (∏ p ∈ S,p) i j) := by + simp only [pairKernel_expansion P hP] + have hs (i : ℕ) : + (∑ j ∈ Finset.range J, ∑ S ∈ P.powerset, + pairCoefficient P S*congruenceIndicator (∏ p ∈ S,p) i j) = + ∑ S ∈ P.powerset, ∑ j ∈ Finset.range J, + pairCoefficient P S*congruenceIndicator (∏ p ∈ S,p) i j := Finset.sum_comm + simp only [hs] + rw [Finset.sum_comm] + simp only [Finset.mul_sum] + rw [hexpand] + calc + _ ≤ ∑ S ∈ P.powerset, pairCoefficient P S*((J : ℝ)^2/((∏ p ∈ S,p : ℕ) : ℝ)+J) := by + apply Finset.sum_le_sum + intro S hS + have hprod : 0 < ∏ p ∈ S,p := Finset.prod_pos + (fun p hp => (hP p ((Finset.mem_powerset.mp hS) hp)).pos) + exact mul_le_mul_of_nonneg_left (interval_pair_congruence_bound J _ hprod) (pairCoefficient_nonneg P S hP) + _ = (J : ℝ)^2*(∑ S ∈ P.powerset,pairCoefficient P S/((∏ p ∈ S,p : ℕ) : ℝ))+ + (J : ℝ)*(∑ S ∈ P.powerset,pairCoefficient P S) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro S _ + ring + _ = _ := by rw [pairCoefficient_normalized_sum,pairCoefficient_sum]; ring + +end ErdosRandomVariance + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/PaperContinuousCorrection.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/PaperContinuousCorrection.lean new file mode 100644 index 0000000000000000000000000000000000000000..89bb004444f452c08b2ed2ba7e9452e9c6c4e106 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/PaperContinuousCorrection.lean @@ -0,0 +1,87 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CorrectionFloorRemainder + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology +namespace ErdosCorrectionLimit +open ErdosContinuousAnomaly ErdosBoundaryIntegral +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.PrimeBinMembership NumberTheoryLean.DerivativeWeights +open NumberTheoryLean.JacobsthalSourceScale +open Erdos970Dependency.InvariantCostBound + +noncomputable def paperStart (a : ℝ) (e : ℝ → ℝ) (closed : Bool) (L : ℝ) : Node where + side := .even + gap := paperGap a e L + ratio := paperGap a e L/sourceB L + cutoff := sourceB L + closed := closed + +theorem paper_start_eventually (a : ℝ) (closed : Bool) {e : ℝ → ℝ} (he : Tendsto e atTop (𝓝 0)) : + ∀ᶠ L : ℝ in atTop, + 0 < sourceB L ∧ 1 < sourceW L ∧ + Real.log (sourceB L) ≤ 2*Real.log (sourceW L) ∧ + 199/100 ≤ (paperStart a e closed L).ratio ∧ (paperStart a e closed L).ratio ≤ 23/10 ∧ + 0 < (paperStart a e closed L).gap ∧ Consistent (paperStart a e closed L) := by + have hr := (paper_ratio_tendsto a he).eventually + (Ioo_mem_nhds (by norm_num : (199:ℝ)/100 < 2) (by norm_num : (2:ℝ) < 23/10)) + filter_upwards [source_scale_eventually,hr] with L hs hr + have hB : 0 < sourceB L := hs.2.1 + have hg : 0 < paperGap a e L := by + have hh := (lt_div_iff₀ hB).mp hr.1 + nlinarith + refine ⟨hB,hs.1,hs.2.2.2.2,hr.1.le,hr.2.le,hg,?_⟩ + change sourceB L=paperGap a e L/(paperGap a e L/sourceB L) + field_simp + +theorem paper_normalized_correction_tendsto (a : ℝ) (closed : Bool) {e : ℝ → ℝ} + (he : Tendsto e atTop (𝓝 0)) : + Tendsto (fun L => ((paperStart a e closed L).gap^2/weight .even (paperStart a e closed L).ratio)* + continuousBoundaryCorrection (sourceW L) 2 (paperStart a e closed L)) atTop + (𝓝 (2*signedCoefficientI/costMass)) := by + apply Metric.tendsto_nhds.mpr + intro eps heps + obtain ⟨B₀,w₀,_hB₀,_hw₀,h⟩ := full_continuous_correction_limit 2 (eps/2) (by norm_num) (by linarith) + filter_upwards [paper_start_eventually a closed he, + sourceB_tendsto.eventually (eventually_ge_atTop B₀), + sourceW_tendsto.eventually (eventually_ge_atTop w₀)] with L hs hB hw + have hh := h (sourceB L) (sourceW L) hB hw hs.2.2.1 + (paperStart a e closed L) rfl hs.2.2.2.1 hs.2.2.2.2.1 hs.2.2.2.2.2.2 rfl + rw [Real.dist_eq] + exact hh.trans_lt (by linarith) + +theorem paper_continuous_correction_tendsto (a : ℝ) (closed : Bool) {e : ℝ → ℝ} + (he : Tendsto e atTop (𝓝 0)) : + Tendsto (fun L => (sourceB L)^2*continuousBoundaryCorrection (sourceW L) 2 (paperStart a e closed L)) + atTop (𝓝 (Real.exp Real.eulerMascheroniConstant*(2*signedCoefficientI/costMass))) := by + have ht := (paper_prefactor_tendsto a he).mul (paper_normalized_correction_tendsto a closed he) + apply ht.congr' + filter_upwards [paper_start_eventually a closed he] with L hs + have hg : paperGap a e L ≠ 0 := hs.2.2.2.2.2.1.ne' + have hp : phiEven (paperGap a e L/sourceB L) ≠ 0 := + (phiEven_pos (by have hh := hs.2.2.2.1; change 199/100 ≤ paperGap a e L/sourceB L at hh; linarith)).ne' + change (sourceB L)^2*phiEven (paperGap a e L/sourceB L)/(paperGap a e L)^2* + ((paperGap a e L)^2/phiEven (paperGap a e L/sourceB L)* + continuousBoundaryCorrection (sourceW L) 2 (paperStart a e closed L))=_ + field_simp + +theorem paper_z_continuous_correction_tendsto (a : ℝ) (closed : Bool) {e : ℝ → ℝ} + (he : Tendsto e atTop (𝓝 0)) : + Tendsto (fun z => (sourceB (Real.log z))^2* + continuousBoundaryCorrection (sourceW (Real.log z)) 2 (paperStart a e closed (Real.log z))) atTop + (𝓝 (Real.exp Real.eulerMascheroniConstant*(2*signedCoefficientI/costMass))) := by + exact (paper_continuous_correction_tendsto a closed he).comp Real.tendsto_log_atTop + +end ErdosCorrectionLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/PatternErrorNormalization.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/PatternErrorNormalization.lean new file mode 100644 index 0000000000000000000000000000000000000000..a7b466b1edca36d6a56038312a922dfe00a54c95 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/PatternErrorNormalization.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PatternCardGrowth +import OAI.NumberTheory.Jacobsthal.Estimates.SourceExtensionScale + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +open _root_.Filter +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceLargeCount ErdosLargeHeightBlocks + ErdosInversePrimeBin ErdosInverseBoxHeight ErdosInverseEuler + +theorem normalization_budgets (xi eps : ℝ) (hxi : 0 < xi) (heps : 0 < eps) : + ∀ᶠ R : ℝ in atTop,1 < R ∧ Real.log R ≤ R^((1 : ℝ)/40) ∧ + 16 ≤ eps*xi*R^((1 : ℝ)/20) := by + have hlog := (isLittleO_log_rpow_rpow_atTop (1 : ℝ) (by norm_num : (0 : ℝ) < 1/40)).bound zero_lt_one + filter_upwards [hlog,(tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 1/20)).eventually_ge_atTop (16/(eps*xi)), + eventually_gt_atTop (1 : ℝ)] with R hlog hc hR + have hR0 : 0 < R := by linarith + refine ⟨hR,?_,?_⟩ + · simpa only [Real.rpow_one,Real.norm_eq_abs,abs_of_nonneg (Real.log_pos hR).le, + abs_of_nonneg (Real.rpow_nonneg hR0.le _),one_mul] using hlog + · have hh := (div_le_iff₀ (mul_pos heps hxi)).mp hc + nlinarith + +theorem source_pattern_error_normalized (alpha xi eps : ℝ) + (halpha : 0 < alpha) (hxi : 0 < xi) (hxi1 : xi ≤ 1) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop,∀ (R theta : ℝ),z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + ∀ (H : ℕ) (C0 : ℤ),0 < H → + max (H : ℝ) (|(C0 : ℝ)|/R)/(H : ℝ) ≤ (sourceZ z)^12 → + ((blockCount C0 R theta H : ℝ)* + (patternCard (divisorModulus (sourceW z) H) (coprimeModulus (sourceW z) H) : ℝ)*R^((9 : ℝ)/10))/ + ((primeBin R theta).card : ℝ) ≤ eps := by + obtain ⟨R0,hR0⟩ := eventually_atTop.mp (normalization_budgets xi eps hxi heps) + filter_upwards [source_model_population alpha xi halpha hxi hxi1,source_patternCard_Z, + source_Z_power_R alpha (1/40) 14 halpha (by norm_num) (by decide), + sourceZ_tendsto_atTop.eventually_ge_atTop 2,(tendsto_rpow_atTop halpha).eventually_ge_atTop R0] + with z hpop hM hZpow hZ hzR + intro R theta hRlo hthetal hthetau H C0 hH hratio + have hp := hpop R theta hRlo hthetal hthetau + have hb := hR0 R (hzR.trans hRlo) + have hR : 0 < R := by linarith [hp.1] + have hlog : 0 < Real.log R := Real.log_pos hp.1 + have htheta : 0 ≤ theta := (by positivity : (0 : ℝ) ≤ xi/4).trans hthetal + let n : ℝ := blockCount C0 R theta H + let M : ℝ := patternCard (divisorModulus (sourceW z) H) (coprimeModulus (sourceW z) H) + have hn : n ≤ (sourceZ z)^13 := blockCount_source_bound C0 R theta (sourceZ z) H + hR htheta (hthetau.trans hxi1) hH hZ hratio + have hMZ : M ≤ sourceZ z := hM H + have hnM : n*M ≤ R^((1 : ℝ)/40) := by + calc + _ ≤ (sourceZ z)^13*sourceZ z := mul_le_mul hn hMZ (Nat.cast_nonneg _) (by positivity) + _ = (sourceZ z)^14 := by ring + _ ≤ _ := hZpow.2 R hRlo + have hprod : (n*M*R^((9 : ℝ)/10))*(16*Real.log R) ≤ 16*R^((19 : ℝ)/20) := by + have hpair := mul_le_mul hnM hb.2.1 hlog.le (Real.rpow_nonneg hR.le _) + have hm := mul_le_mul_of_nonneg_left hpair (show 0 ≤ 16*R^((9 : ℝ)/10) by positivity) + calc + _ ≤ 16*R^((9 : ℝ)/10)*(R^((1 : ℝ)/40)*R^((1 : ℝ)/40)) := by nlinarith + _ = 16*(R^((9 : ℝ)/10)*(R^((1 : ℝ)/40)*R^((1 : ℝ)/40))) := by ring + _ = _ := by rw [← Real.rpow_add hR,← Real.rpow_add hR];norm_num + have htarget : 16*R^((19 : ℝ)/20) ≤ eps*xi*R := by + have hh := mul_le_mul_of_nonneg_right hb.2.2 (Real.rpow_nonneg hR.le ((19 : ℝ)/20)) + calc + _ ≤ (eps*xi*R^((1 : ℝ)/20))*R^((19 : ℝ)/20) := hh + _ = _ := by rw [mul_assoc (eps*xi),← Real.rpow_add hR];norm_num + have herr : n*M*R^((9 : ℝ)/10) ≤ eps*(xi*R/(16*Real.log R)) := by + have hh := (le_div_iff₀ (show 0 < 16*Real.log R by positivity)).mpr (hprod.trans htarget) + have he : eps*(xi*R/(16*Real.log R)) = eps*xi*R/(16*Real.log R) := by ring + exact hh.trans_eq he.symm + have hlow : 0 < xi*R/(16*Real.log R) := by positivity + have hPC : 0 < ((primeBin R theta).card : ℝ) := hlow.trans_le hp.2.2 + apply (div_le_iff₀ hPC).mpr + exact herr.trans (mul_le_mul_of_nonneg_left hp.2.2 heps.le) + +end ErdosVarianceLargeMap + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/RawCompactPlacement.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RawCompactPlacement.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6d3ac332e430092b03e4cbfc7d6456866a9d978 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RawCompactPlacement.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawFullHitIncreasing + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.FirstHitKernels + +lemma gapAt_antitone_cost {r T U : ℝ} (hr : 0 ≤ r) (hTU : T ≤ U) : gapAt r U ≤ gapAt r T := + mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (neg_le_neg hTU)) hr + +lemma increasingCosts_before_smallGap {a b : ℕ} {h : RawHistory b} + (hh : h ∈ increasingCosts a b) {r K : ℝ} (hr : 0 ≤ r) + (i j : Finset.Iic b) (haj : a ≤ j.1) + (hi : K < gapAt r (h i).2) (hj : gapAt r (h j).2 ≤ K) : i.1 < j.1 := by + by_contra hn + have hji : j.1 ≤ i.1 := by omega + have hc := hh j i haj hji + have hg := gapAt_antitone_cost hr hc + exact (not_lt_of_ge (hg.trans hj)) hi + +lemma rawEvenHit_actual_anchor (a : ℕ) (v H : ℝ) (h0 : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a v H h0, + let q := rawEvenFinalCycle a z + q.2.2 ⟨q.1,Finset.mem_Iic.mpr (by omega)⟩ ∈ regenerationSet := + rawEvenHit_anchor_regenerates a v H h0 + +theorem rawEvenHit_before_compact {r b0 b1 K : ℝ} (hr : 0 < r) (hb0 : 0 < b0) + (hb1 : 0 < b1) (hK : K ≤ 6*b0) (a : ℕ) (h0 : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a (Real.log (r/b1)) (Real.log (b1/(10*b0))) h0, + let q := rawEvenFinalCycle a z + ∀ j : Finset.Iic (q.1+2*(q.2.1+1)), a ≤ j.1 → + gapAt r (q.2.2 j).2 ≤ K → q.1+1 < j.1 := by + filter_upwards [rawEvenHit_ae_geometric hr hb0 hb1 a h0, + rawEvenHit_increasing a (Real.log (r/b1)) (Real.log (b1/(10*b0))) h0] with z hG hI + obtain ⟨tau,_ht0,_ht1,_hF,_hg0,_hg1,_hx0,_hx1,_hx2,_hx3,hgap,_hratio⟩ := hG + have hR := rawEvenFinalCycle_record a z + rw [hR] at hgap + rcases he : rawEvenFinalCycle a z with ⟨t,n,h⟩ + change rawEvenFinalCycle a z ∈ selectedIncreasing a at hI + rw [he] at hI hgap + change h ∈ increasingCosts a (t+2*(n+1)) at hI + change 6*b0 < gapAt r (h ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩).2 at hgap + change ∀ j : Finset.Iic (t+2*(n+1)), a ≤ j.1 → gapAt r (h j).2 ≤ K → t+1 < j.1 + intro j haj hj + exact increasingCosts_before_smallGap hI hr.le ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩ j haj + (hK.trans_lt hgap) hj + +theorem rawEvenHit_before_compact_extension {r b0 b1 K : ℝ} (hr : 0 < r) (hb0 : 0 < b0) + (hb1 : 0 < b1) (hK : K ≤ 6*b0) (a : ℕ) (h0 : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a (Real.log (r/b1)) (Real.log (b1/(10*b0))) h0, + let q := rawEvenFinalCycle a z + ∀ (c : ℕ) (_hc : q.1+2*(q.2.1+1) ≤ c), + ∀ᵐ y ∂rawExtension (q.1+2*(q.2.1+1)) c q.2.2, + ∀ j : Finset.Iic c, a ≤ j.1 → gapAt r (y j).2 ≤ K → q.1+1 < j.1 := by + filter_upwards [rawEvenHit_ae_geometric hr hb0 hb1 a h0, + rawEvenHit_increasing a (Real.log (r/b1)) (Real.log (b1/(10*b0))) h0] with z hG hI + obtain ⟨tau,_ht0,_ht1,_hF,_hg0,_hg1,_hx0,_hx1,_hx2,_hx3,hgap,_hratio⟩ := hG + have hR := rawEvenFinalCycle_record a z + rw [hR] at hgap + rcases he : rawEvenFinalCycle a z with ⟨t,n,h⟩ + change rawEvenFinalCycle a z ∈ selectedIncreasing a at hI + rw [he] at hI hgap + change h ∈ increasingCosts a (t+2*(n+1)) at hI + change 6*b0 < gapAt r (h ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩).2 at hgap + change ∀ (c : ℕ) (hc : t+2*(n+1) ≤ c), ∀ᵐ y ∂rawExtension (t+2*(n+1)) c h, + ∀ j : Finset.Iic c, a ≤ j.1 → gapAt r (y j).2 ≤ K → t+1 < j.1 + intro c hc + filter_upwards [rawExtension_preserves_increasing hc h hI,rawExtension_retains_prefix hc h] with y hy hp + have heval := congrFun hp (⟨t+1,Finset.mem_Iic.mpr (by omega)⟩ : Finset.Iic (t+2*(n+1))) + change y ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩=h ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩ at heval + intro j haj hj + apply increasingCosts_before_smallGap hy hr.le ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩ j haj _ hj + rw [heval] + exact hK.trans_lt hgap + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/RealCoefficientNormalization.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RealCoefficientNormalization.lean new file mode 100644 index 0000000000000000000000000000000000000000..d24f2ea3c273a12c2e79741cb44d65d675e431fc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RealCoefficientNormalization.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.ComplexSquareScaling + +namespace OAI + +namespace Erdos970 + +section + +open scoped ComplexConjugate +namespace ErdosComplexCurveFactors +open ErdosCriticalGeometry + +noncomputable def realCoefficients (F : MV ℂ) : MV ℝ := + AddMonoidAlgebra.ofCoeff (Finsupp.mapRange Complex.re (by simp) (AddMonoidAlgebra.coeff F)) + +theorem coeff_realCoefficients (F : MV ℂ) (m : Fin 2 →₀ ℕ) : + (realCoefficients F).coeff m = (F.coeff m).re := rfl + +theorem complexify_realCoefficients (F : MV ℂ) (hF : conjugate F = F) : + complexify (realCoefficients F) = F := by + ext m + change (MvPolynomial.map (algebraMap ℝ ℂ) (realCoefficients F)).coeff m = F.coeff m + rw [MvPolynomial.coeff_map,coeff_realCoefficients] + apply Complex.conj_eq_iff_re.mp + have h := congrArg (fun P : MV ℂ => P.coeff m) hF + simpa only [coeff_conjugate] using h + +def RealScalable (F : MV ℂ) : Prop := + ∃ a : ℂ, a ≠ 0 ∧ ∃ R : MV ℝ, F = MvPolynomial.C a * complexify R + +theorem normalized_conjugate_eq (F : MV ℂ) (c : ℂ) (hc : c ≠ 0) + (hrel : conjugate F = MvPolynomial.C c * F) (m : Fin 2 →₀ ℕ) + (hm : F.coeff m ≠ 0) : + conjugate (MvPolynomial.C (F.coeff m)⁻¹ * F) = MvPolynomial.C (F.coeff m)⁻¹ * F := by + have hcoeff (k : Fin 2 →₀ ℕ) : conj (F.coeff k) = c*F.coeff k := by + have h := congrArg (fun P : MV ℂ => P.coeff k) hrel + simpa only [coeff_conjugate,MvPolynomial.coeff_C_mul] using h + ext k + simp only [coeff_conjugate,MvPolynomial.coeff_C_mul,map_mul,map_inv₀,hcoeff] + field_simp [hc,hm] + +theorem realScalable_of_dvd_conjugate (F : MV ℂ) (hF : Irreducible F) + (hdiv : F ∣ conjugate F) : RealScalable F := by + obtain ⟨H,hH⟩ := hdiv + have hu : IsUnit H := ((conjugate_irreducible hF).2 hH).resolve_left hF.not_isUnit + obtain ⟨c,hc,hC⟩ := MvPolynomial.isUnit_iff_eq_C_of_isReduced.mp hu + have hc0 : c ≠ 0 := hc.ne_zero + have hrel : conjugate F = MvPolynomial.C c * F := by rw [hH,hC,mul_comm] + obtain ⟨m,hm⟩ := MvPolynomial.exists_coeff_ne_zero hF.ne_zero + let N := MvPolynomial.C (F.coeff m)⁻¹ * F + have hN : conjugate N = N := normalized_conjugate_eq F c hc0 hrel m hm + have hR : complexify (realCoefficients N) = N := complexify_realCoefficients N hN + refine ⟨F.coeff m,hm,realCoefficients N,?_⟩ + rw [hR] + change F = MvPolynomial.C (F.coeff m) * (MvPolynomial.C (F.coeff m)⁻¹ * F) + rw [← mul_assoc,← map_mul,mul_inv_cancel₀ hm,map_one,one_mul] + +theorem nonreal_not_dvd_conjugate (F : MV ℂ) (hF : Irreducible F) + (hreal : ¬RealScalable F) : ¬F ∣ conjugate F := + fun h => hreal (realScalable_of_dvd_conjugate F hF h) + +end ErdosComplexCurveFactors + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/RetainedNormalizedReward.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RetainedNormalizedReward.lean new file mode 100644 index 0000000000000000000000000000000000000000..531fcd57b5c12fd186ba91cee29808de5f86822a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RetainedNormalizedReward.lean @@ -0,0 +1,104 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceNodeCoordinates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.MeasureTheory _root_.Set _root_.Finset +namespace ErdosRetainedRewardTransfer +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.PrimeKilledChain NumberTheoryLean.PrimeCompactWeights +open NumberTheoryLean.PrimeCorrectionFactor NumberTheoryLean.PrimeFamilyOccupation +open NumberTheoryLean.SourceNodeCoordinates +open NumberTheoryLean.PrimeBinMembership +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def transferConstant : ℝ := 2*weight .even (199/100) + +theorem transferConstant_positive : 0 < transferConstant := by + unfold transferConstant + exact mul_pos (by norm_num) (weight_pos (by norm_num [Valid])) + +theorem scaled_normalized_reward_bound {d w ell B delta : ℝ} {start : Node} + (hB : 0 < B) (hell : 1 ≤ ell) (hlogB : 2 ≤ Real.log B) + (hcomp : Real.log B ≤ d*Real.log w) (hbudget : correctionBudget d w ≤ 1) + (hi : start.side=.even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hcons : Consistent start) (hcut : start.cutoff=B) (_hdelta : 0 ≤ delta) + (h : History w ell ((Real.log B)^2) start) (F : List ℕ → ℝ) + (hF : h.node.gap^2*|F h.primes|/weight h.node.side h.node.ratio ≤ delta) : + scaledWeight w B start (some h)*|F h.primes| ≤ transferConstant*delta := by + obtain ⟨hs,hr,hBr,hsize⟩ := source_node_bounds hB start hi h199 h23 hcons hcut + have hphi : 0 < weight h.node.side h.node.ratio := weight_pos (terminal_valid hs h.admissible) + have hp0 : 0 ≤ weight start.side start.ratio := (weight_pos hs).le + have hW : 0 ≤ weight .even (199/100) := (weight_pos (by norm_num [Valid])).le + have hinit : weight start.side start.ratio ≤ weight .even (199/100) := by + rw [hi] + exact NumberTheoryLean.TwoStepDensityBounds.weight_antitone (by norm_num [Valid]) (hi ▸ hs) h199 + have hc : (1+epsilon w)^h.primes.length ≤ 2 := by + have hh := (history_correction hlogB hcomp hell hr hs hB hsize h).2 + linarith + have hc0 : 0 ≤ (1+epsilon w)^h.primes.length := pow_nonneg (normalizer_pos w).le _ + have hratio : 0 ≤ B/start.gap := div_nonneg hB.le hr.le + have hratio1 : B/start.gap ≤ 1 := (div_le_one hr).mpr hBr + have hsq : (B/start.gap)^2 ≤ 1 := by nlinarith + have hF0 : 0 ≤ h.node.gap^2*|F h.primes|/weight h.node.side h.node.ratio := by positivity + calc + _ = ((B/start.gap)^2*(1+epsilon w)^h.primes.length*weight start.side start.ratio)* + (h.node.gap^2*|F h.primes|/weight h.node.side h.node.ratio) := by unfold scaledWeight; ring + _ ≤ (1*2*weight .even (199/100))*delta := + mul_le_mul (mul_le_mul (mul_le_mul hsq hc hc0 (by norm_num)) hinit hp0 (by norm_num)) hF hF0 (by positivity) + _ = _ := by unfold transferConstant; ring + +theorem retained_normalized_reward_sum {d w ell B delta : ℝ} {start : Node} + (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) + (hS : (Real.log B)^2 ≤ (Real.log w)^3) (hsS : start.ratio ≤ (Real.log B)^2) + (hB : 0 < B) (hlogB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) + (hbudget : correctionBudget d w ≤ 1) + (hi : start.side=.even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hcons : Consistent start) (hcut : start.cutoff=B) (hdelta : 0 ≤ delta) (F : List ℕ → ℝ) + (hF : ∀ ps ∈ retainedPrefixes w ell ((Real.log B)^2) start, + (terminal w start ps).gap^2*|F ps|/weight (terminal w start ps).side (terminal w start ps).ratio ≤ delta) : + B^2*(∑ ps ∈ retainedPrefixes w ell ((Real.log B)^2) start,prefixWeight ps*|F ps|) ≤ + transferConstant*(NumberTheoryLean.LowStateHorizon.sourceHorizon ((Real.log B)^2) B : ℝ)*delta := by + classical + obtain ⟨hs,hr,_hBr,hsize⟩ := source_node_bounds hB start hi h199 h23 hcons hcut + have hw1 : 1 < w := normalizationThreshold_gt_one.trans_le hw + let := historyFintype (ell:=ell) (S:=(Real.log B)^2) hw1 start + have hpoint (z : ChainState w ell ((Real.log B)^2) start) : + ‖scaledWeight w B start z*listReward (fun ps => |F ps|) z‖ ≤ transferConstant*delta := by + cases z with + | none => + simp only [scaledWeight,listReward,mul_zero,norm_zero] + exact mul_nonneg transferConstant_positive.le hdelta + | some h => + have hnorm : 0 ≤ scaledWeight w B start (some h)*|F h.primes| := + mul_nonneg (scaledWeight_nonneg hs _) (abs_nonneg _) + change ‖scaledWeight w B start (some h)*|F h.primes|‖ ≤ transferConstant*delta + rw [Real.norm_of_nonneg hnorm] + apply scaled_normalized_reward_bound hB hell hlogB hcomp hbudget hi h199 h23 hcons hcut hdelta h F + exact hF h.primes ((mem_retainedPrefixes hw1 start h.primes).mpr h.admissible) + have hterm (n : ℕ) : + (∫ z,scaledWeight w B start z*listReward (fun ps => |F ps|) z ∂pathLaw w ell ((Real.log B)^2) start n) ≤ + transferConstant*delta := by + let := pathLaw_isProbability hw hell (sq_nonneg _) hS hr hs hsS n + have hn := norm_integral_le_of_norm_le_const (μ:=pathLaw w ell ((Real.log B)^2) start n) + (Filter.Eventually.of_forall hpoint) + rw [Real.norm_eq_abs] at hn + have hle := le_abs_self (∫ z,scaledWeight w B start z*listReward (fun ps => |F ps|) z ∂pathLaw w ell ((Real.log B)^2) start n) + exact hle.trans (by simpa using hn) + rw [← finite_signed_original_occupation hw hell (sq_nonneg _) hS hr hs hsS hB hsize (fun ps => |F ps|)] + calc + _ ≤ ∑ _n ∈ range (NumberTheoryLean.LowStateHorizon.sourceHorizon ((Real.log B)^2) B),transferConstant*delta := + Finset.sum_le_sum (fun n _ => hterm n) + _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; ring + +end ErdosRetainedRewardTransfer + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/RieszIntegralRepresentation.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RieszIntegralRepresentation.lean new file mode 100644 index 0000000000000000000000000000000000000000..2fe4852bc7ccf1a7882486d2ea5e2ccea2fdaedc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RieszIntegralRepresentation.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RieszTermCalculus + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory _root_.Filter +open scoped Topology BigOperators + +noncomputable def mellinFactor : ℂ := ((1/(2*Real.pi):ℝ):ℂ) + +lemma rieszTerm_integral (f : ℕ → ℂ) (hf0 : f 0 = 0) {sigma X : ℝ} + (hs : 1/2 ≤ sigma) (hX : 0 < X) (n : ℕ) : + mellinFactor * (∫ t:ℝ, rieszDirichletTerm f sigma X n t) = + f n * (rieszWeight ((n:ℝ)/X):ℂ) := by + by_cases hn : n=0 + · simp [rieszDirichletTerm,hn,hf0] + · have hr : 0 < (n:ℝ)/X := div_pos (by exact_mod_cast Nat.pos_of_ne_zero hn) hX + have hi := riesz_mellin_inversion hs hr + have hi' : mellinFactor * (∫ t:ℝ, (((n:ℝ)/X:ℝ):ℂ)^(-((sigma:ℂ)+(t:ℂ)*Complex.I)) * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)) = (rieszWeight ((n:ℝ)/X):ℂ) := by + simpa only [mellinInv,smul_eq_mul,RCLike.real_smul_eq_coe_mul,mellinFactor] using! hi + have he : (∫ t:ℝ, rieszDirichletTerm f sigma X n t) = + f n * (∫ t:ℝ, (((n:ℝ)/X:ℝ):ℂ)^(-((sigma:ℂ)+(t:ℂ)*Complex.I)) * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + simp_rw [rieszDirichletTerm_eq_scaled f hf0 sigma hX n,mul_assoc] + exact integral_const_mul _ _ + rw [he] + calc + _ = f n * (mellinFactor * (∫ t:ℝ, (((n:ℝ)/X:ℝ):ℂ)^(-((sigma:ℂ)+(t:ℂ)*Complex.I)) * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I))) := by ring + _ = _ := by rw [hi'] + +theorem hasSum_riesz_integral (f : ℕ → ℂ) (hf0 : f 0 = 0) {sigma X : ℝ} + (hs : 1/2 ≤ sigma) (hf : LSeriesSummable f (sigma:ℂ)) (hX : 0 < X) : + HasSum (fun n:ℕ => f n*(rieszWeight ((n:ℝ)/X):ℂ)) + (mellinFactor * ∫ t:ℝ, LSeries f ((sigma:ℂ)+(t:ℂ)*Complex.I) * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I) * (X:ℂ)^((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + have hnorm : Summable (fun n:ℕ => ∫ t:ℝ, ‖rieszDirichletTerm f sigma X n t‖) := by + simp_rw [integral_norm_rieszDirichletTerm f hX] + exact (hf.norm.mul_right (X^sigma)).mul_right _ + have h := hasSum_integral_of_summable_integral_norm + (fun n:ℕ => integrable_rieszDirichletTerm f hs hX n) hnorm + have hscaled := h.mul_left mellinFactor + simp_rw [rieszTerm_integral f hf0 hs hX] at hscaled + have hseries (t:ℝ) : (∑' n:ℕ, rieszDirichletTerm f sigma X n t) = + LSeries f ((sigma:ℂ)+(t:ℂ)*Complex.I) * rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I) * + (X:ℂ)^((sigma:ℂ)+(t:ℂ)*Complex.I) := by + simp only [rieszDirichletTerm,tsum_mul_right,LSeries] + simp_rw [hseries] at hscaled + exact hscaled + +theorem character_riesz_mellin {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + {sigma X : ℝ} (hs : 1 < sigma) (hX : 0 < X) : + (∑' n:ℕ, (chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) * (rieszWeight ((n:ℝ)/X):ℂ)) = + mellinFactor * ∫ t:ℝ, + (-deriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I) / + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I)) * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I) * (X:ℂ)^((sigma:ℂ)+(t:ℂ)*Complex.I) := by + have hf0 : (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) 0 = 0 := by simp + have hf : LSeriesSummable (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) (sigma:ℂ) := + DirichletCharacter.LSeriesSummable_twist_vonMangoldt chi (by simpa using hs) + rw [(hasSum_riesz_integral _ hf0 (by linarith) hf hX).tsum_eq] + congr 1 + apply integral_congr_ae + exact Filter.Eventually.of_forall (fun t => by + dsimp only + rw [twisted_series_eq_actual_log_derivative chi (by simpa using hs)]) + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/RieszMajorantIntegrals.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RieszMajorantIntegrals.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad611d102fc0c6d5820bf3f8f499ebb86b191f08 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/RieszMajorantIntegrals.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RieszCauchy + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory _root_.Set + +lemma arctan_le_self_nonneg {x : ℝ} (hx : 0 ≤ x) : Real.arctan x ≤ x := by + have h := intervalIntegral.integral_mono_on (a := 0) (b := x) hx + integrable_inv_one_add_sq.intervalIntegrable (intervalIntegrable_const (c := (1:ℝ))) + (fun t _ => show (1+t^2)⁻¹ ≤ 1 by + rw [← one_div] + exact (div_le_iff₀ (by positivity : 0 < 1+t^2)).mpr (by nlinarith [sq_nonneg t])) + rw [integral_inv_one_add_sq,Real.arctan_zero,sub_zero] at h + simpa using h + +lemma rieszMajorant_upper_tail {T : ℝ} (hT : 0 < T) : + (∫ t in Ici T, (4:ℝ)/(1+t^2)) ≤ 4/T := by + rw [integral_Ici_eq_integral_Ioi] + simp only [div_eq_mul_inv,integral_const_mul,integral_Ioi_inv_one_add_sq] + have hi := Real.arctan_inv_of_pos hT + simp only [div_eq_mul_inv] at hi + rw [← hi] + exact mul_le_mul_of_nonneg_left (arctan_le_self_nonneg (inv_nonneg.mpr hT.le)) (by norm_num) + +lemma rieszMajorant_lower_tail {T : ℝ} (hT : 0 < T) : + (∫ t in Iic (-T), (4:ℝ)/(1+t^2)) ≤ 4/T := by + have he : (∫ t in Iic (-T), (4:ℝ)/(1+t^2)) = ∫ t in Ici T, (4:ℝ)/(1+t^2) := by + rw [integral_Ici_eq_integral_Ioi] + simp only [div_eq_mul_inv,integral_const_mul,integral_Iic_inv_one_add_sq, + integral_Ioi_inv_one_add_sq,Real.arctan_neg] + ring + rw [he] + exact rieszMajorant_upper_tail hT + +lemma rieszMajorant_interval_le (T : ℝ) : + (∫ t in (-T)..T, (4:ℝ)/(1+t^2)) ≤ 4*Real.pi := by + simp only [div_eq_mul_inv,intervalIntegral.integral_const_mul,integral_inv_one_add_sq,Real.arctan_neg] + have h := Real.arctan_lt_pi_div_two T + linarith + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ScalarMassContinuity.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ScalarMassContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..26cc25a97e76573267dea1e02c9eecfd3783eb88 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ScalarMassContinuity.lean @@ -0,0 +1,44 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ScalarTailRecurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology +namespace ErdosOmissionTail +open ErdosContinuousBoundary + +theorem scalarTailMass_continuous (n : ℕ) : + Continuous (fun p : ℝ×ℝ => scalarTailMass n p.1 p.2) := by + apply continuous_iff_continuousAt.mpr + intro p + let Y : ℝ := |p.1|+(n:ℝ)+5 + have hY : 0 ≤ Y := by dsimp [Y]; positivity + let F : (ℝ×ℝ) → ℝ → ℝ := fun q y => scalarTailIntegrand n q.1 q.2 y + have hpmap : Continuous (fun q : (ℝ×ℝ)×ℝ => (2*q.2+2-q.1.1,q.1.2)) := by fun_prop + have hh : Continuous (fun q : (ℝ×ℝ)×ℝ => scalarFreeIterate n terminalBlock (2*q.2+2-q.1.1) q.1.2) := + (scalarFreeIterate_continuous terminalBlock_continuous n).comp hpmap + have hF : Continuous F.uncurry := (continuous_const.mul (continuous_snd.pow 2)).mul hh + have hI : Continuous (fun q : ℝ×ℝ => ∫ y in Icc (0:ℝ) Y,F q y) := + continuous_parametric_integral_of_continuous hF isCompact_Icc + apply hI.continuousAt.congr_of_eventuallyEq + have hnear : ∀ᶠ q : ℝ×ℝ in 𝓝 p,q.1 < p.1+1 := + continuous_fst.continuousAt.preimage_mem_nhds (Iio_mem_nhds (by linarith : p.1 < p.1+1)) + filter_upwards [hnear] with q hq + have hp := le_abs_self p.1 + have hp0 := abs_nonneg p.1 + have hhigh : q.1/2+(n:ℝ)+4 ≤ Y := by dsimp [Y]; linarith + rw [scalarTailMass_bounded n q.1 q.2 Y hY hhigh, + intervalIntegral.integral_of_le hY,← integral_Icc_eq_integral_Ioc] + +end ErdosOmissionTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/SmallModelMeasure.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SmallModelMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..f20814762e86f6abcb84fe769df16acedf121257 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SmallModelMeasure.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SmallModelSourceScales + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def modelUnitIntegers (R xi : ℝ) (H : ℕ) (C0 : ℤ) : Finset ℤ := + (modelIntegers R xi (H : ℝ) (C0 : ℝ)).filter (fun m => m.natAbs.Coprime H) + +noncomputable def modelUniverse (R xi w : ℝ) (H : ℕ) (C0 : ℤ) : Finset (ModelPoint w H) := + (modelUnitIntegers R xi H C0).product Finset.univ + +noncomputable def atomWeight (R xi w : ℝ) (H : ℕ) (C0 : ℤ) : ℝ := + (H : ℝ)/((H.totient : ℝ)*modelLength R xi (H : ℝ) (C0 : ℝ)* + (divisorModulus w H : ℝ)*((coprimeModulus w H).totient : ℝ)) + +noncomputable def modelMass (R xi w : ℝ) (H : ℕ) (C0 : ℤ) (E : ModelPoint w H → Prop) : ℝ := + ∑ _v ∈ (modelUniverse R xi w H C0).filter E,atomWeight R xi w H C0 + +theorem mem_modelUniverse (R xi w : ℝ) (H : ℕ) (C0 : ℤ) (v : ModelPoint w H) : + v ∈ modelUniverse R xi w H C0 ↔ + modelLeft R xi (C0 : ℝ) ≤ (v.1 : ℝ) ∧ (v.1 : ℝ) < modelRight R xi (H : ℝ) (C0 : ℝ) ∧ + v.1.natAbs.Coprime H := by + simp only [modelUniverse,Finset.product_eq_sprod,Finset.mem_product,Finset.mem_univ,and_true, + modelUnitIntegers,Finset.mem_filter,mem_modelIntegers,and_assoc] + +theorem atomWeight_pos (R xi w : ℝ) (H : ℕ) (C0 : ℤ) (hR : 0 < R) (hxi : 0 ≤ xi) (hH : 0 < H) : + 0 < atomWeight R xi w H C0 := by + have hHR : (0 : ℝ) < H := by exact_mod_cast hH + have hphi : (0 : ℝ) < H.totient := by exact_mod_cast Nat.totient_pos.mpr hH + have hT0 : (0 : ℝ) < divisorModulus w H := by exact_mod_cast divisorModulus_pos w H + have hT1 : (0 : ℝ) < (coprimeModulus w H).totient := by + exact_mod_cast Nat.totient_pos.mpr (coprimeModulus_pos w H) + have hY : 0 < modelLength R xi (H : ℝ) (C0 : ℝ) := by + dsimp [modelLength,interceptScale] + positivity + unfold atomWeight + positivity + +theorem modelMass_card (R xi w : ℝ) (H : ℕ) (C0 : ℤ) (E : ModelPoint w H → Prop) : + modelMass R xi w H C0 E = + (((modelUniverse R xi w H C0).filter E).card : ℝ)*atomWeight R xi w H C0 := by + simp only [modelMass,Finset.sum_const,nsmul_eq_mul] + +theorem modelUniverse_card (R xi w : ℝ) (H : ℕ) (C0 : ℤ) : + (modelUniverse R xi w H C0).card = + (modelUnitIntegers R xi H C0).card*(divisorModulus w H*(coprimeModulus w H).totient) := by + simp only [modelUniverse,Finset.product_eq_sprod,Finset.card_product,Finset.card_univ,pattern_card] + +theorem model_total_mass (R xi w : ℝ) (H : ℕ) (C0 : ℤ) (hR : 0 < R) (hxi : 0 ≤ xi) (hH : 0 < H) : + modelMass R xi w H C0 (fun _ => True) = + ((modelUnitIntegers R xi H C0).card : ℝ)*(H : ℝ)/ + ((H.totient : ℝ)*modelLength R xi (H : ℝ) (C0 : ℝ)) := by + have hphi : (0 : ℝ) < H.totient := by exact_mod_cast Nat.totient_pos.mpr hH + have hT0 : (0 : ℝ) < divisorModulus w H := by exact_mod_cast divisorModulus_pos w H + have hT1 : (0 : ℝ) < (coprimeModulus w H).totient := by + exact_mod_cast Nat.totient_pos.mpr (coprimeModulus_pos w H) + have hY : 0 < modelLength R xi (H : ℝ) (C0 : ℝ) := by + have hHR : (0 : ℝ) < H := by exact_mod_cast hH + dsimp [modelLength,interceptScale] + positivity + rw [modelMass_card,Finset.filter_true,modelUniverse_card] + simp only [Nat.cast_mul,atomWeight] + field_simp + +end ErdosVarianceSmallModel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceBadCompactOccurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceBadCompactOccurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..45efd8b9567f57c5ca2b377bfdcceb97075f0a97 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceBadCompactOccurrence.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.Jacobsthal.Paths.NearPrefixOccurrence +import OAI.NumberTheory.Jacobsthal.Probability.CompletedMarkEvents + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceBadCompactOccurrence + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualCoupledHistories ActualSuccessfulHistories ActualFlagInvariant ActualProcessCoupling +open FiniteHistoryTransport PriorPrimeWindow CompactPrefixOccurrence CompletedMarkEvents +open RegeneratingInverseBands NearbyParentGeometry + +variable {w ell S R b₀ b₁ : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem missing_occurrence_inclusion (hc : Consistent start) (hb₀ : 0 < b₀) + {mesh : ℝ} (hm : 0 < mesh) (hmesh : mesh ≤ 1/100) (N : ℕ) + (herror : 4*(N:ℝ)*mesh ≤ Real.log (11/10)) (E : Set (List ℕ)) + (hE : ∀ p : History w ell S start,p.primes ∈ E → + p.node.gap ≤ R ∧ ¬hasPrimeWindow w b₀ b₁ start p.primes) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + occurs E N h → (last N h).2 = true ∨ + mapHist (fun q => q.1.2) N h ∈ badCompactPath (Real.log start.gap) ((11/10)*R) b₀ b₁ N := by + filter_upwards [sourceHistory_success_good hw hell hS0 hS hr hs hsS hm N, + sourceHistory_prior_mark hw hell hS0 hS hr hs hsS hc hm hmesh N herror] with h hg hprior + intro hocc + by_cases hf : (last N h).2 = true + · exact Or.inl hf + have hfalse : (last N h).2 = false := by cases hval : (last N h).2 <;> simp_all + obtain ⟨j,hjE⟩ := hocc + let j' : Finset.Iic N := ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩ + cases hp : (h j').1.1 with + | none => + change selectedNode E (h j').1.1 at hjE + rw [hp] at hjE + exact False.elim hjE + | some p => + change selectedNode E (h j').1.1 at hjE + rw [hp] at hjE + have hpE := hE p hjE + have hgj : GoodAt (Real.log start.gap) mesh j'.1 (some p,(h j').1.2) := by + simpa only [← hp] using hg hfalse j' + cases hz : (h j').1.2 with + | inr u => rw [hz] at hgj; exact False.elim hgj + | inl z => + rw [hz] at hgj + have hn : (j'.1:ℝ) ≤ N := by exact_mod_cast Finset.mem_Iic.mp j'.2 + have herr : 4*(j'.1:ℝ)*mesh ≤ Real.log (11/10) := + (by nlinarith : 4*(j'.1:ℝ)*mesh ≤ 4*(N:ℝ)*mesh).trans herror + have he : Real.exp (4*(j'.1:ℝ)*mesh) ≤ (11/10:ℝ) := by + rw [← Real.exp_log (by norm_num : 0 < (11/10:ℝ))] + exact Real.exp_le_exp.mpr herr + have hpPos := terminal_gap_positive (by linarith : 0 ≤ ell) hr hs p.admissible + have hrel := log_gap_relative hpPos (Real.exp_pos _) hgj.2.2.2 + have hgap : gapValue (Real.log start.gap) z ≤ (11/10)*R := + hrel.2.trans ((mul_le_mul_of_nonneg_right he hpPos.le).trans + (mul_le_mul_of_nonneg_left hpE.1 (by norm_num))) + apply Or.inr + refine ⟨j',?_,?_⟩ + · change compactPoint (Real.log start.gap) ((11/10)*R) (h j').1.2 + rw [hz] + exact hgap + · intro i hij hMark + change markedPoint (Real.log start.gap) b₀ b₁ (h i).1.2 at hMark + cases hi : (h i).1.2 with + | inr u => rw [hi] at hMark; exact False.elim hMark + | inl y => + rw [hi] at hMark + exact hpE.2 (hprior hfalse i j' hij p hp y hi b₀ b₁ hb₀ + hMark.1 hMark.2.1 hMark.2.2.1 hMark.2.2.2.1 hMark.2.2.2.2) + +end NumberTheoryLean.SourceBadCompactOccurrence + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceCompactErrorMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceCompactErrorMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..56f6b766c8fadb137abef1fc3bc59d8c8a5869c3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceCompactErrorMass.lean @@ -0,0 +1,203 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.GeometricTotalBoxMass +import OAI.NumberTheory.Jacobsthal.Probability.ActualUnlistedEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GlobalCompactTransfer +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate +open JacobsthalSourceScale ActualRegularBoxes ActualBinOwners UniformGeometricRegularMass +open GeometricTotalBoxMass GeometricBoxImages GeometricRegularWords +open ExpandedCompactPartition CountErrorClassification RegularStoppedEvent PaperRegularStopping +open EligibleBoxLists ActualUnlistedEvent FilteredBoxWordMass CanonicalSubsetBox +open StoppedCountVertex StoppedCountAdapters StoppedTraceSets +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosCofactorChoices ErdosSubsetWord ErdosVarianceEligible +open ErdosPrimeInputs.PrimePrefixMass +open scoped Topology +attribute [local instance] Classical.propDecidable + +theorem paper_compact_from_local_bounds (K : ℝ) (hK : 3 ≤ K) : + ∃ Clen₀ Cgeom A : ℝ,1 ≤ Clen₀ ∧ 0 < Cgeom ∧ 0 < A ∧ + ∀ Clen : ℝ,Clen₀ ≤ Clen → ∀ geoErr : ℝ,0 < geoErr → + ∃ alpha : ℝ,0 < alpha ∧ alpha ≤ 1/400 ∧ + ∀ L Cs eta : ℝ,0 ≤ L → 0 ≤ Cs → 0 < eta → eta < 1/2 → + ∀ NQ : ℕ,∀ capErr : ℝ,0 < capErr → ∀ xi : ℝ,∀ hxi : 0 < xi, + xi ≤ 1 → 20*Clen*xi ≤ 1 → + ∃ rho : ℝ,10 < rho ∧ ∀ Kstop : ℝ,0 < Kstop → + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ Y : ℕ,Y ≤ ⌊top^2/(Real.log top)^2⌋₊ → ∀ (z : Node) (a : ℕ → ℕ), + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → + z.cutoff=sourceB (Real.log top) → z.closed=true → + ∀ eps tau : ℝ,0 ≤ tau → + ∀ Qraw : (Fin (binCount (sourceW (Real.log top)) top xi) → ℕ) → Finset ℚ, + let M := geometricBoxes hw htop hxi Clen (sourceB (Real.log top)) K L alpha (1/100) z + (∀ m∈M,(Qraw m).card ≤ NQ) → + (∀ m∈M,(∑ f∈(selections (globalBins (sourceW (Real.log top)) top xi) m).filter + (unwitnessedSelection hw htop hxi Y Cs Clen (sourceB (Real.log top)) K L alpha (1/100) eps a z (Qraw m)), + (selectionProduct f:ℝ)⁻¹) ≤ tau*selectionMass (globalBins (sourceW (Real.log top)) top xi) m) → + let w := sourceW (Real.log top) + let B := sourceB (Real.log top) + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + let stop := stopCandidate Y w Cs eta Clen B xi (Kstop*(Real.log w)^2) (rho*Kstop*(Real.log w)^2) + (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) a z + B^2*(∑ ps∈badCompactWords w K eps Y small a V0 z + (expanded w stop (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*V0))),prefixWeight ps) + ≤ Cgeom*(2*Clen*xi)+geoErr+A*tau+capErr := by + obtain ⟨A,BA,WA,hA,hBA,hWA,hTotal⟩ := uniform_geometric_box_mass K hK + obtain ⟨Clen₀,Cgeom,hClen₀,hCgeom,hGeometry⟩ := geometric_defect_uniform_in_L K hK 2 (by norm_num) + (1/400) (by norm_num) (by norm_num) + refine ⟨Clen₀,Cgeom,A,hClen₀,hCgeom,hA,?_⟩ + intro Clen hClen geoErr hgeoErr + have hClen1 : 1 ≤ Clen := hClen₀.trans hClen + obtain ⟨alpha,halpha,halphaUpper,hL⟩ := hGeometry Clen hClen geoErr hgeoErr + refine ⟨alpha,halpha,halphaUpper,?_⟩ + intro L Cs eta hL0 hCs heta0 heta NQ capErr hcapErr xi hxi hxi1 h20 + obtain ⟨BG,WG,hBG,hWG,hGeometry⟩ := hL L hL0 + have hbeta : 4*(1/400:ℝ)=1/100 := by norm_num + rw [hbeta] at hGeometry + have hDelta : 2*Clen*xi ≤ 1 := by + have hp : 0 ≤ Clen*xi := mul_nonneg (by linarith) hxi.le + nlinarith + obtain ⟨rho,hrho,hCapture⟩ := paper_regular_uncaptured_mass hK hClen1 hCs heta0 heta hxi hxi1 hDelta NQ capErr hcapErr + refine ⟨rho,hrho,?_⟩ + intro Kstop hKstop + have hBT := sourceB_tendsto.comp Real.tendsto_log_atTop + have hWT := sourceW_tendsto.comp Real.tendsto_log_atTop + filter_upwards [hCapture Kstop hKstop,hBT.eventually_ge_atTop (max BG BA), + hWT.eventually_ge_atTop (max WG WA),Real.tendsto_log_atTop.eventually source_scale_eventually] + with top hCapture hB hW hscale + dsimp only [Function.comp_def] at hB hW + obtain ⟨hw,htop,hCapture⟩ := hCapture + refine ⟨hw,htop,?_⟩ + intro Y hY z a hi h199 h23 hz hcut hclosed eps tau htau Qraw + dsimp only + intro hcard hLocal + let w := sourceW (Real.log top) + let B := sourceB (Real.log top) + let P := sourcePrimeSet w top + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + let v := rootVertex z ∅ P ((Y:ℝ)*V0) + let M := geometricBoxes hw htop hxi Clen B K L alpha (1/100) z + let Q := eligibleLists (Y:ℝ) w Cs M Qraw + let b₀ := Kstop*(Real.log w)^2 + let b₁ := rho*Kstop*(Real.log w)^2 + let stop := stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z + let F := badCompactWords w K eps Y small a V0 z (expanded w stop P.card v) + have hpower : w^B=top := (sourceW_pow_sourceB hw).trans (Real.exp_log ((zero_lt_one.trans hw).trans htop)) + have hRef := bad_compact_reference_data w top K eps Y a z stop P.card V0 + have hGeom := hGeometry B w top ((le_max_left _ _).trans hB) ((le_max_left _ _).trans hW) + hw htop xi hxi hxi1 h20 hscale.2.2.2.2 z hi h199 h23 hz hcut hclosed hpower F hRef.1 hRef.2 + have hTot := hTotal B w top ((le_max_right _ _).trans hB) ((le_max_right _ _).trans hW) + hw htop xi Clen hxi hClen1 hscale.2.2.2.2 hDelta z hi h199 h23 hz hcut hclosed hpower L alpha (1/100) + have hCard := eligibleLists_card (Y:ℝ) w Cs M Qraw NQ hcard + have hCap := hCapture Y hY z a hi h199 h23 hz hcut hclosed Q + (fun m _hm => hCard m) (fun m _hm q hq => eligibleLists_eligible (Y:ℝ) w Cs M Qraw m q hq) + have hBox : ∀ m∈M,selectedWordMass (globalBins w top xi) m + (unlistedGeometric hw htop hxi Cs Clen B K L alpha (1/100) a z Q F) ≤ tau*selectionMass (globalBins w top xi) m := by + intro m hm + exact (selected_unlisted_le_unwitnessed_mass (Cs:=Cs) (C:=Clen) (B:=B) (K:=K) (L:=L) + (alpha:=alpha) (beta:=1/100) (eps:=eps) hw htop hxi Y M Qraw m hm a z (expanded w stop P.card v)).trans (hLocal m hm) + have hUnlisted := unlisted_box_transfer hw htop hxi htau a z Q F hTot hBox + have hSplit := expanded_geometric_mass_split hw htop hxi Y Cs eta Clen B K L alpha (1/100) b₀ b₁ a z + ∅ ((Y:ℝ)*V0) P.card Q F (fun _ hp => (Finset.mem_filter.mp hp).1) + have hScaled := mul_le_mul_of_nonneg_left hSplit (sq_nonneg B) + change B^2*(∑ ps∈F,prefixWeight ps) ≤ Cgeom*(2*Clen*xi)+geoErr+A*tau+capErr + nlinarith +end NumberTheoryLean.GlobalCompactTransfer + + + +namespace NumberTheoryLean.SourceCompactErrorMass +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate +open GlobalCompactTransfer GeometricBoxImages GeometricRegularWords CountErrorClassification +open StoppedCountVertex StoppedCountAdapters StoppedTraceSets CanonicalSubsetBox +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInverseBoxHeight ErdosCofactorChoices ErdosSubsetWord ErdosVarianceEligible ErdosVarianceFactory +open ErdosPrimeInputs.PrimePrefixMass +open scoped Topology +attribute [local instance] Classical.propDecidable + +theorem source_compact_error_mass (K eps budget aStar Cmin : ℝ) + (hK : 3 ≤ K) (heps : 0 < eps) (hbudget : 0 < budget) (ha : 0 < aStar) (ha1 : aStar ≤ 1) : + ∃ Clen Cs xi₀ : ℝ,1 ≤ Clen ∧ 0 < Cs ∧ Cmin ≤ Cs ∧ 0 < xi₀ ∧ xi₀ ≤ 1 ∧ + ∀ eta : ℝ,0 < eta → eta < 1/2 → ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ xi₀ → + ∃ rho : ℝ,10 < rho ∧ ∀ Kstop : ℝ,0 < Kstop → + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW top,∃ htop : sourceW top < top, + ∀ (z : Node) (a : ℕ → ℕ),z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + Consistent z → z.cutoff=sourceB top → z.closed=true → + z.gap=Real.log (sourceY top:ℝ)/Real.log (sourceW top)-aStar+2 → + let w := sourceW top + let B := sourceB top + let Y := sourceY top + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + let stop := stopCandidate Y w Cs eta Clen B xi (Kstop*(Real.log w)^2) (rho*Kstop*(Real.log w)^2) + (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) a z + B^2*(∑ ps∈badCompactWords w K eps Y small a V0 z + (expanded w stop (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*V0))),prefixWeight ps) ≤ budget := by + obtain ⟨Clen,Cgeom,A,hClen,hCgeom,hA,hGlobal⟩ := paper_compact_from_local_bounds K hK + have hClen0 : 0 < Clen := by linarith + have hquarter : 0 < budget/4 := by positivity + obtain ⟨alpha,halpha,_halphaUpper,hGlobal⟩ := hGlobal Clen (le_refl _) (budget/4) hquarter + let tau := budget/(4*A) + have htau : 0 < tau := by dsimp [tau]; positivity + obtain ⟨Kstar,hKstar,NQ,Cs,hCs,hCsMin,_hCsK,xiF,hxiF,hxiF1,hFactory⟩ := + source_raw_box_factory Clen K aStar alpha eps tau Cmin hClen hK ha ha1 halpha heps htau + let xi₀ := min xiF (min (1/(20*Clen)) (budget/(8*Clen*Cgeom))) + have hxi₀ : 0 < xi₀ := lt_min hxiF (lt_min (by positivity) (by positivity)) + have hxi₀1 : xi₀ ≤ 1 := (min_le_left _ _).trans hxiF1 + refine ⟨Clen,Cs,xi₀,hClen,hCs,hCsMin,hxi₀,hxi₀1,?_⟩ + intro eta heta0 heta xi hxi hx + have hxF : xi ≤ xiF := hx.trans (min_le_left _ _) + have hxi1 : xi ≤ 1 := hx.trans hxi₀1 + have h20 : 20*Clen*xi ≤ 1 := by + have hh := (le_div_iff₀ (show 0 < 20*Clen by positivity)).mp + ((hx.trans (min_le_right _ _)).trans (min_le_left _ _)) + nlinarith + have hGeomBudget : Cgeom*(2*Clen*xi) ≤ budget/4 := by + have hh := (le_div_iff₀ (show 0 < 8*Clen*Cgeom by positivity)).mp + ((hx.trans (min_le_right _ _)).trans (min_le_right _ _)) + nlinarith + have hL : 0 ≤ 2*Kstar+5 := by linarith + obtain ⟨rho,hrho,hGlobal⟩ := hGlobal (2*Kstar+5) Cs eta hL hCs.le heta0 heta NQ (budget/4) hquarter xi hxi hxi1 h20 + refine ⟨rho,hrho,?_⟩ + intro Kstop hKstop + filter_upwards [hGlobal Kstop hKstop,hFactory xi hxi hxF] with top hGlobal hFactory + obtain ⟨hw,htop,hGlobal⟩ := hGlobal + obtain ⟨_hwF,_htopF,hFactory⟩ := hFactory + refine ⟨hw,htop,?_⟩ + intro z a hi h199 h23 hz hcut hclosed hroot + dsimp only + let M := geometricBoxes hw htop hxi Clen (sourceB top) K (2*Kstar+5) alpha (1/100) z + have hLists (m : Fin (binCount (sourceW top) top xi) → ℕ) (hm : m∈M) := + hFactory z hi h199 hz hcut hclosed hroot a m hm + have hAll : ∀ m : Fin (binCount (sourceW top) top xi) → ℕ,∃ Q : Finset ℚ, + Q.card ≤ NQ ∧ (m∈M → + (∑ f∈(selections (globalBins (sourceW top) top xi) m).filter + (unwitnessedSelection hw htop hxi (sourceY top) Cs Clen (sourceB top) K (2*Kstar+5) alpha (1/100) eps a z Q), + (selectionProduct f:ℝ)⁻¹) ≤ tau*selectionMass (globalBins (sourceW top) top xi) m) := by + intro m + by_cases hm : m∈M + · obtain ⟨Q,hcard,hMass⟩ := hLists m hm + exact ⟨Q,hcard,fun _ => hMass⟩ + · exact ⟨∅,by simp,fun hm' => False.elim (hm hm')⟩ + choose Qraw hCard hLocal using hAll + have hBound := hGlobal (sourceY top) (le_refl _) z a hi h199 h23 hz hcut hclosed eps tau htau.le Qraw + (fun m _hm => hCard m) hLocal + have hTau : A*tau=budget/4 := by dsimp [tau]; field_simp [hA.ne'] + rw [hTau] at hBound + dsimp only at hBound + exact hBound.trans (by nlinarith) +end NumberTheoryLean.SourceCompactErrorMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceCompactSingletons.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceCompactSingletons.lean new file mode 100644 index 0000000000000000000000000000000000000000..b03dd0651e10d716770441515b516c475e5dda79 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceCompactSingletons.lean @@ -0,0 +1,84 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RepeatedPositionNeighbors +import OAI.NumberTheory.Jacobsthal.Probability.RepeatedWordEvents + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CompactPositionRepetition +open FinitePathGeometry PrimeHistories RepeatedWordEvents RepeatedPositionNeighbors +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem compact_position_repetition {n : ℕ} (lab : ℕ → Fin n) (w L : ℝ) (z : Node) + (pre tail : List ℕ) (p : ℕ) + (hord : ((pre++p::tail).map lab).Pairwise (· ≥ ·)) + (hc : 2 ≤ ((pre++p::tail).map lab).count (lab p)) + (hgap : (terminal w z pre).gap ≤ L) (hp : 0 ≤ primeExponent w p) : + compactAdjacentWord w lab L z (pre++p::tail) := by + rcases repeated_position_neighbor lab pre tail p hord hc with ⟨pre',q,hpre,hq⟩ | ⟨q,tail',htail,hq⟩ + · refine ⟨pre',q,p,tail,?_,hq,?_⟩ + · rw [hpre] + simp + · rwa [← hpre] + · refine ⟨pre,p,q,tail',by rw [htail],hq.symm,?_⟩ + have hg : (terminal w z (pre++[p])).gap=(terminal w z pre).gap-primeExponent w p := by + simp [terminal,step] + rw [hg] + linarith + +theorem compact_position_singleton {n : ℕ} (lab : ℕ → Fin n) (w L : ℝ) (z : Node) + (ps : List ℕ) (hord : (ps.map lab).Pairwise (· ≥ ·)) + (hno : ¬compactAdjacentWord w lab L z ps) + (pre tail : List ℕ) (p : ℕ) (he : ps=pre++p::tail) + (hgap : (terminal w z pre).gap ≤ L) (hp : 0 ≤ primeExponent w p) : + (ps.map lab).count (lab p) ≤ 1 := by + by_contra hc + have hc' : 2 ≤ (ps.map lab).count (lab p) := by omega + apply hno + rw [he] at hord hc' ⊢ + exact compact_position_repetition lab w L z pre tail p hord hc' hgap hp +end NumberTheoryLean.CompactPositionRepetition + + + +namespace NumberTheoryLean.SourceCompactSingletons +open FinitePathGeometry PrimeHistories RepeatedWordEvents CompactPositionRepetition SortedLabelRepetition +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem source_compact_singleton {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (L : ℝ) (z : Node) (ps : List ℕ) (hd : ps.Pairwise (· > ·)) + (hsrc : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) + (hno : ¬compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L z ps) + (pre tail : List ℕ) (p : ℕ) (he : ps=pre++p::tail) (hgap : (terminal w z pre).gap ≤ L) : + (ps.map (label (zero_lt_one.trans hw) htop hxi)).count (label (zero_lt_one.trans hw) htop hxi p)=1 := by + have hp : p ∈ ps := by rw [he]; simp + have hp' := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hsrc p hp) + have hxp : 0 ≤ primeExponent w p := by + unfold primeExponent + exact div_nonneg (Real.log_nonneg (le_trans hw.le hp'.2.1.le)) (Real.log_nonneg hw.le) + have hle := compact_position_singleton _ w L z ps + (source_word_labels_ordered hw htop hxi ps hd hsrc) hno pre tail p he hgap hxp + have hpos : 0 < (ps.map (label (zero_lt_one.trans hw) htop hxi)).count (label (zero_lt_one.trans hw) htop hxi p) := + List.count_pos_iff.mpr (List.mem_map.mpr ⟨p,hp,rfl⟩) + omega + +theorem source_search_singleton {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (ps : List ℕ) (hno : ¬searchRepeatedWord hw htop hxi ps) + (b : Fin (binCount w top xi)) (hs : ActualSourceTags.searchBin w (LogarithmicBinEndpoints.lower w top xi b)) + (hm : b ∈ ps.map (label (zero_lt_one.trans hw) htop hxi)) : + (ps.map (label (zero_lt_one.trans hw) htop hxi)).count b=1 := by + have hc := List.count_pos_iff.mpr hm + have hn : ¬2 ≤ (ps.map (label (zero_lt_one.trans hw) htop hxi)).count b := fun h => hno ⟨b,hs,h⟩ + omega +end NumberTheoryLean.SourceCompactSingletons + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceProductLimit.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceProductLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..79b42809a383b9bf3c9870fd66dc352d9beb1689 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceProductLimit.lean @@ -0,0 +1,70 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceCenteredGap + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Filter +open scoped Topology +namespace ErdosSourceReferenceMargin +open NumberTheoryLean.ReferenceMertens NumberTheoryLean.ReferenceProductErrors + +theorem root_B_log_W {z : ℝ} (hw : 1 < ErdosInverseBoxHeight.sourceW z) : + ErdosInverseBoxHeight.sourceB z*Real.log (ErdosInverseBoxHeight.sourceW z)=Real.log z := by + exact div_mul_cancel₀ _ (Real.log_pos hw).ne' + +theorem root_product_error_decay {c : ℝ} (hc : 0 < c) : + Tendsto (fun z : ℝ => Real.exp (-c*Real.sqrt (Real.log z))) atTop (𝓝 0) := by + have ht := (Real.tendsto_sqrt_atTop.comp Real.tendsto_log_atTop).const_mul_atTop hc + simpa only [Function.comp_def,neg_mul] using! Real.tendsto_exp_neg_atTop_nhds_zero.comp ht + +theorem root_referenceProduct_error_tendsto (closed : Bool) : + Tendsto (fun z => ErdosInverseBoxHeight.sourceB z* + referenceProduct (ErdosInverseBoxHeight.sourceW z) (ErdosInverseBoxHeight.sourceB z) closed- + normalization (ErdosInverseBoxHeight.sourceW z)) atTop (𝓝 0) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := reference_product_absolute + have hlim : Tendsto (fun z : ℝ => C*Real.exp (-c*Real.sqrt (Real.log z))) atTop (𝓝 0) := by + simpa only [mul_zero] using (root_product_error_decay hc).const_mul C + have hbound : ∀ᶠ z : ℝ in atTop, + |ErdosInverseBoxHeight.sourceB z*referenceProduct (ErdosInverseBoxHeight.sourceW z) + (ErdosInverseBoxHeight.sourceB z) closed-normalization (ErdosInverseBoxHeight.sourceW z)| ≤ + C*Real.exp (-c*Real.sqrt (Real.log z)) := by + filter_upwards [rootB_tendsto.eventually (eventually_ge_atTop (2:ℝ)), + rootW_tendsto.eventually (eventually_ge_atTop w₀)] with z hb hw + have hW : 1 < ErdosInverseBoxHeight.sourceW z := hw₀.trans_le hw + have hB : 0 < ErdosInverseBoxHeight.sourceB z := by linarith + have hp := (h (ErdosInverseBoxHeight.sourceW z) hw).2.2 (ErdosInverseBoxHeight.sourceB z) hb closed + rw [root_B_log_W hW] at hp + have hh := mul_le_mul_of_nonneg_left hp hB.le + have he : ErdosInverseBoxHeight.sourceB z*referenceProduct (ErdosInverseBoxHeight.sourceW z) + (ErdosInverseBoxHeight.sourceB z) closed-normalization (ErdosInverseBoxHeight.sourceW z)= + ErdosInverseBoxHeight.sourceB z*(referenceProduct (ErdosInverseBoxHeight.sourceW z) + (ErdosInverseBoxHeight.sourceB z) closed-normalization (ErdosInverseBoxHeight.sourceW z)/ErdosInverseBoxHeight.sourceB z) := by + field_simp + rw [he,abs_mul,abs_of_pos hB] + have hcanc : ErdosInverseBoxHeight.sourceB z* + ((C/ErdosInverseBoxHeight.sourceB z)*Real.exp (-c*Real.sqrt (Real.log z)))= + C*Real.exp (-c*Real.sqrt (Real.log z)) := by field_simp + exact hh.trans_eq hcanc + have habs := squeeze_zero' (Filter.Eventually.of_forall (fun z => abs_nonneg + (ErdosInverseBoxHeight.sourceB z*referenceProduct (ErdosInverseBoxHeight.sourceW z) + (ErdosInverseBoxHeight.sourceB z) closed-normalization (ErdosInverseBoxHeight.sourceW z)))) hbound hlim + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simpa only [Real.norm_eq_abs] using habs + +theorem root_referenceProduct_tendsto (closed : Bool) : + Tendsto (fun z => ErdosInverseBoxHeight.sourceB z* + referenceProduct (ErdosInverseBoxHeight.sourceW z) (ErdosInverseBoxHeight.sourceB z) closed) atTop (𝓝 1) := by + have hh := (root_referenceProduct_error_tendsto closed).add (normalization_tendsto_one.comp rootW_tendsto) + simpa only [sub_add_cancel,zero_add,Function.comp_def] using! hh + +end ErdosSourceReferenceMargin + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceReferenceLimit.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceReferenceLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..1eab0559e6fbdbc154ef603e597ba917a2277201 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/SourceReferenceLimit.lean @@ -0,0 +1,41 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceParentBenchmark +import OAI.NumberTheory.Jacobsthal.Estimates.SourceReferenceRemainders + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceReferenceMargin +open ErdosCorrectionLimit ErdosContinuousAnomaly ErdosBoundaryIntegral +open NumberTheoryLean.ReferenceSourceDecomposition NumberTheoryLean.ReferenceLocalResidual +open Erdos970Dependency.InvariantCostBound + +theorem root_sourceReference_tendsto (a : ℝ) : + Tendsto (fun z => (ErdosInverseBoxHeight.sourceB z)^2* + sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode a z)) atTop + (𝓝 (Real.exp Real.eulerMascheroniConstant*(-a+2*signedCoefficientI/costMass))) := by + have hh := (((root_source_remainder_tendsto a).add (root_anomaly_replacement_tendsto a)).add + (root_nodeBenchmark_tendsto a)).add (floored_source_correction_tendsto a) + convert! hh using 1 + · funext z + ring + · ring_nf + +theorem actual_sourceReference_tendsto : + Tendsto (fun z => (ErdosInverseBoxHeight.sourceB z)^2* + sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode (1/100) z)) atTop + (𝓝 (Real.exp Real.eulerMascheroniConstant*(-(1:ℝ)/100+2*signedCoefficientI/costMass))) := by + simpa only [neg_div] using! root_sourceReference_tendsto (1/100) + +end ErdosSourceReferenceMargin + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/TerminalForceIntegral.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/TerminalForceIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..52f37a8d556ad36eec61a3c3ba49ca64c411039e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/TerminalForceIntegral.lean @@ -0,0 +1,212 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ScalarTailRecurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission ErdosContinuousBoundary ErdosOmissionBindings +open NumberTheoryLean.FinitePathGeometry + +theorem terminalBlock_mask (S y : ℝ) {b : ℝ} (_hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + terminalBlock (2*y+2-S) b= + ∫ a in Icc (1:ℝ) b,if S/2+a ≤ y then + gate omissionForce .even (2*y+2-S-a) a/(max 1 a) else 0 := by + have hset : Ioc (1:ℝ) (upperCutoff .odd (2*y+2-S) b)= + Ioc (1:ℝ) b ∩ {a : ℝ | S/2+a ≤ y} := by + ext a + constructor + · intro ha + obtain ⟨ha1,ha2,hab,hgate⟩ := (mem_upperCutoff .odd (2*y+2-S) b a).mp ha + have hh := (strong_gate_below_two ha2).mp hgate + exact ⟨⟨ha1,hab⟩,by change S/2+a ≤ y; linarith⟩ + · rintro ⟨⟨ha1,hab⟩,hy⟩ + apply (mem_upperCutoff .odd (2*y+2-S) b a).mpr + refine ⟨ha1,hab.trans hb2,hab,?_⟩ + apply (strong_gate_below_two (hab.trans hb2)).mpr + change S/2+a ≤ y at hy + linarith + have hm : MeasurableSet {a : ℝ | S/2+a ≤ y} := + measurableSet_le (measurable_const.add measurable_id) measurable_const + change (∫ a : ℝ in 1..upperCutoff .odd (2*y+2-S) b, + gate omissionForce .even (2*y+2-S-a) a/(max 1 a))=_ + rw [intervalIntegral.integral_of_le (upperCutoff_bounds .odd (2*y+2-S) b).1, + hset,← setIntegral_indicator hm,← integral_Icc_eq_integral_Ioc] + rfl + +noncomputable def terminalOuterIntegrand (S : ℝ) (p : ℝ×ℝ) : ℝ := + if S/2+p.2 ≤ p.1 then + 2*p.1^2*gate omissionForce .even (2*p.1+2-S-p.2) p.2/(max 1 p.2) else 0 + +theorem terminalOuterIntegrand_measurable (S : ℝ) : Measurable (terminalOuterIntegrand S) := by + have hc0 : Continuous (fun p : ℝ×ℝ => gate omissionForce .even p.1 p.2) := + gate_continuous omissionForce_continuous .even + have hp : Continuous (fun p : ℝ×ℝ => (2*p.1+2-S-p.2,p.2)) := by fun_prop + have hc : Continuous (fun p : ℝ×ℝ => gate omissionForce .even (2*p.1+2-S-p.2) p.2) := hc0.comp hp + exact Measurable.ite (measurableSet_le (measurable_const.add measurable_snd) measurable_fst) + (((measurable_const.mul (measurable_fst.pow_const 2)).mul hc.measurable).div + (measurable_const.max measurable_snd)) measurable_const + +theorem terminalOuterIntegrand_bound (S a : ℝ) {y Y : ℝ} (hy0 : 0 ≤ y) (hyY : y ≤ Y) : + |terminalOuterIntegrand S (y,a)| ≤ 2*Y^2 := by + unfold terminalOuterIntegrand + split_ifs + · have hp := gate_nonnegative omissionForce_nonnegative .even (2*y+2-S-a) a + have hu := gateIterate_force_le_one 1 .even (2*y+2-S-a) a + change gate omissionForce .even (2*y+2-S-a) a ≤ 1 at hu + have hn : 0 ≤ 2*y^2*gate omissionForce .even (2*y+2-S-a) a := by positivity + have hm := mul_le_mul_of_nonneg_left hu (mul_nonneg (by norm_num : (0:ℝ)≤2) (sq_nonneg y)) + rw [abs_of_nonneg (div_nonneg hn (zero_le_one.trans (le_max_left _ _)))] + apply (div_le_self hn (le_max_left (1:ℝ) a)).trans + nlinarith + · simpa only [abs_zero] using mul_nonneg (by norm_num : (0:ℝ)≤2) (sq_nonneg Y) + +theorem scalarTailMass_zero_outer {S b : ℝ} (hS : 0 ≤ S) (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + scalarTailMass 0 S b= + ∫ a : ℝ in 1..b,(2/a)*(∫ y : ℝ in S/2+a..S/2+4, + y^2*gate omissionForce .even (2*y+2-S-a) a) := by + let Y : ℝ := S/2+4 + have hY : 0 ≤ Y := by dsimp [Y]; linarith + have hl (y : ℝ) : scalarTailIntegrand 0 S b y=∫ a in Icc (1:ℝ) b,terminalOuterIntegrand S (y,a) := by + change 2*y^2*terminalBlock (2*y+2-S) b=_ + rw [terminalBlock_mask S y hb1 hb2,← integral_const_mul] + apply integral_congr_ae + filter_upwards with a + dsimp only [terminalOuterIntegrand] + split_ifs <;> ring + have hs := bounded_rectangle_swap (terminalOuterIntegrand_measurable S) 0 Y 1 b (2*Y^2) + (fun y hy a _ha => terminalOuterIntegrand_bound S a hy.1 hy.2) + have hr (a : ℝ) (ha : a ∈ Icc (1:ℝ) b) : + (∫ y in Icc (0:ℝ) Y,terminalOuterIntegrand S (y,a))= + (2/a)*(∫ y : ℝ in S/2+a..Y,y^2*gate omissionForce .even (2*y+2-S-a) a) := by + have ha2 : a ≤ 2 := ha.2.trans hb2 + have hlo : 0 ≤ S/2+a := by linarith [ha.1] + have hhi : S/2+a ≤ Y := by dsimp [Y]; linarith + have hset : Icc (0:ℝ) Y ∩ Ici (S/2+a)=Icc (S/2+a) Y := by + ext y + constructor + · rintro ⟨hy,hylo⟩; exact ⟨hylo,hy.2⟩ + · intro hy; exact ⟨⟨hlo.trans hy.1,hy.2⟩,hy.1⟩ + have he : (fun y : ℝ => terminalOuterIntegrand S (y,a))= + (Ici (S/2+a)).indicator (fun y => (2/a)*(y^2*gate omissionForce .even (2*y+2-S-a) a)) := by + funext y + unfold terminalOuterIntegrand + by_cases h : S/2+a ≤ y + · rw [ite_eq_left h,indicator_of_mem (show y ∈ Ici (S/2+a) from h),max_eq_right ha.1] + ring + · rw [ite_eq_right h,indicator_of_notMem (show y ∉ Ici (S/2+a) from h)] + rw [he,setIntegral_indicator measurableSet_Ici,hset,integral_const_mul, + integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le hhi] + rw [scalarTailMass_bounded 0 S b Y hY (by dsimp [Y]; norm_num), + intervalIntegral.integral_of_le hY,← integral_Icc_eq_integral_Ioc] + simp_rw [hl] + rw [hs,intervalIntegral.integral_of_le hb1,← integral_Icc_eq_integral_Ioc] + exact setIntegral_congr_fun measurableSet_Icc hr + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission ErdosContinuousBoundary ErdosOmissionBindings +open NumberTheoryLean.FinitePathGeometry + +theorem evenGate_weighted_swap (S a l Y : ℝ) (ha1 : 1 ≤ a) (ha2 : a ≤ 2) + (hl : 0 ≤ l) (hlY : l ≤ Y) : + (∫ y : ℝ in l..Y,y^2*gate omissionForce .even (2*y+2-S-a) a)= + ∫ u : ℝ in 1..a,(∫ y : ℝ in l..Y,y^2*omissionForce .odd (2*y+2-S-a-u) u)/u := by + let G : ℝ×ℝ → ℝ := fun p => p.1^2*omissionForce .odd (2*p.1+2-S-a-p.2) p.2/(max 1 p.2) + have hpmap : Continuous (fun p : ℝ×ℝ => (2*p.1+2-S-a-p.2,p.2)) := by fun_prop + have hc : Continuous (fun p : ℝ×ℝ => omissionForce .odd (2*p.1+2-S-a-p.2) p.2) := + (omissionForce_continuous .odd).comp hpmap + have hG : Continuous G := by + apply ((continuous_fst.pow 2).mul hc).div (continuous_const.max continuous_snd) + intro p + exact ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _)) + have hbnd : ∀ y ∈ Icc l Y,∀ u ∈ Icc (1:ℝ) a,|G (y,u)| ≤ Y^2 := by + intro y hy u _hu + have hy0 : 0 ≤ y := hl.trans hy.1 + have hp := omissionForce_nonnegative .odd (2*y+2-S-a-u) u + have hu := omissionForce_le_one .odd (2*y+2-S-a-u) u + have hn : 0 ≤ y^2*omissionForce .odd (2*y+2-S-a-u) u := by positivity + have hh := mul_le_mul_of_nonneg_left hu (sq_nonneg y) + dsimp only [G] + rw [abs_of_nonneg (div_nonneg hn (zero_le_one.trans (le_max_left _ _)))] + apply (div_le_self hn (le_max_left (1:ℝ) u)).trans + nlinarith [hy.2] + have hs := bounded_rectangle_swap hG.measurable l Y 1 a (Y^2) hbnd + have hs' : (∫ y : ℝ in l..Y,∫ u : ℝ in 1..a,G (y,u))= + ∫ u : ℝ in 1..a,∫ y : ℝ in l..Y,G (y,u) := by + simpa only [integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le hlY, + ← intervalIntegral.integral_of_le ha1] using hs + have hl' : (∫ y : ℝ in l..Y,y^2*gate omissionForce .even (2*y+2-S-a) a)= + ∫ y : ℝ in l..Y,∫ u : ℝ in 1..a,G (y,u) := by + apply intervalIntegral.integral_congr + intro y _hy + dsimp only + rw [gate,show upperCutoff .even (2*y+2-S-a) a=a from baseCutoff_on ha1 ha2, + ← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro u _hu + dsimp only [G,Side.flip] + ring + rw [hl',hs'] + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le ha1] at hu + dsimp only + rw [← intervalIntegral.integral_div] + apply intervalIntegral.integral_congr + intro y _hy + dsimp only [G] + rw [max_eq_right hu.1] + +theorem scalarTailMass_zero_triple {S b : ℝ} (hS : 0 ≤ S) (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + scalarTailMass 0 S b= + ∫ a : ℝ in 1..b,∫ u : ℝ in 1..a,∫ c : ℝ in 1..u, + lastWindowCoefficient S a u c/(a*u*c) := by + rw [scalarTailMass_zero_outer hS hb1 hb2] + apply intervalIntegral.integral_congr + intro a ha + rw [uIcc_of_le hb1] at ha + have ha2 : a ≤ 2 := ha.2.trans hb2 + have hl : 0 ≤ S/2+a := by linarith [ha.1] + have hlY : S/2+a ≤ S/2+4 := by linarith + dsimp only + rw [evenGate_weighted_swap S a (S/2+a) (S/2+4) ha.1 ha2 hl hlY, + ← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le ha.1] at hu + have hu2 : u ≤ 2 := hu.2.trans ha2 + have hw := integrated_force_window (S+a+u) (S/2+a) (S/2+4) u 0 hl hu.1 hu2 + (by linarith [hu.1]) (by linarith) + simp only [sub_zero,zero_mul] at hw + have hgap (y : ℝ) : 2*y+2-S-a-u=2*y+2-(S+a+u) := by ring + dsimp only + simp_rw [hgap] + rw [hw,← intervalIntegral.integral_div,← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro c hc + rw [uIcc_of_le hu.1] at hc + have ha0 : a ≠ 0 := by linarith [ha.1] + have hu0 : u ≠ 0 := by linarith [hu.1] + have hc0 : c ≠ 0 := by linarith [hc.1] + dsimp only [lastWindowCoefficient] + field_simp + ring + +end ErdosOmissionTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ThirdMovingIntegrals.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ThirdMovingIntegrals.lean new file mode 100644 index 0000000000000000000000000000000000000000..b2bf1ee62f5d71b1ddcaf7834e1a1cfbdf587151 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ThirdMovingIntegrals.lean @@ -0,0 +1,91 @@ +import OAI.NumberTheory.Jacobsthal.Probability.ThirdInnerKernel + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosContinuousBoundary ErdosBoundaryLoss + +noncomputable def thirdLowerIntegral (p : ℝ×ℝ) : ℝ := + ∫ t : ℝ in 1..baseCutoff p.2,clampedThird p.1 p.2 t + +noncomputable def thirdUpperIntegral (p : ℝ×ℝ) : ℝ := + ∫ x : ℝ in baseCutoff p.1..2,clampedThird x p.1 p.2 + +theorem thirdLowerIntegral_continuous : Continuous thirdLowerIntegral := by + let F : (ℝ×ℝ) → ℝ → ℝ := fun p t => clampedThird p.1 p.2 t + have hF : Continuous F.uncurry := by + change Continuous ((fun q : ℝ×ℝ×ℝ => clampedThird q.1 q.2.1 q.2.2) ∘ + (fun p : (ℝ×ℝ)×ℝ => (p.1.1,p.1.2,p.2))) + exact clampedThird_continuous.comp + (continuous_fst.fst.prodMk (continuous_fst.snd.prodMk continuous_snd)) + exact continuous_variable_upper_integral F hF (fun p => baseCutoff p.2) + (baseCutoff_continuous.comp continuous_snd) + +theorem thirdUpperIntegral_continuous : Continuous thirdUpperIntegral := by + let F : (ℝ×ℝ) → ℝ → ℝ := fun p x => clampedThird x p.1 p.2 + have hF : Continuous F.uncurry := by + change Continuous ((fun q : ℝ×ℝ×ℝ => clampedThird q.1 q.2.1 q.2.2) ∘ + (fun p : (ℝ×ℝ)×ℝ => (p.2,p.1.1,p.1.2))) + exact clampedThird_continuous.comp + (continuous_snd.prodMk (continuous_fst.fst.prodMk continuous_fst.snd)) + have h2 := continuous_variable_upper_integral F hF (fun _ => (2:ℝ)) continuous_const + have hc := continuous_variable_upper_integral F hF (fun p => baseCutoff p.1) + (baseCutoff_continuous.comp continuous_fst) + have he (p : ℝ×ℝ) : (∫ x : ℝ in 1..2,F p x)-(∫ x : ℝ in 1..baseCutoff p.1,F p x)=thirdUpperIntegral p := by + have hf : Continuous (F p) := by + change Continuous (F.uncurry ∘ (fun x : ℝ => (p,x))) + exact hF.comp (continuous_const.prodMk continuous_id) + have hi := intervalIntegral.integral_add_adjacent_intervals + (hf.intervalIntegrable (μ := volume) 1 (baseCutoff p.1)) + (hf.intervalIntegrable (μ := volume) (baseCutoff p.1) 2) + change (∫ x in 1..2,F p x)-(∫ x in 1..baseCutoff p.1,F p x)=∫ x in baseCutoff p.1..2,F p x + linarith + exact (h2.sub hc).congr he + +theorem thirdLowerIntegral_bound (p : ℝ×ℝ) : |thirdLowerIntegral p| ≤ 64 := by + have h := intervalIntegral.norm_integral_le_of_norm_le_const (a:=1) (b:=baseCutoff p.2) + (C:=64) (f:=fun t => clampedThird p.1 p.2 t) + (fun t _ => by simpa only [Real.norm_eq_abs] using clampedThird_bound p.1 p.2 t) + have hc := baseCutoff_bounds p.2 + change |thirdLowerIntegral p| ≤ 64 + rw [Real.norm_eq_abs,abs_of_nonneg (by linarith : 0 ≤ baseCutoff p.2-1)] at h + exact h.trans (by nlinarith) + +theorem thirdUpperIntegral_bound (p : ℝ×ℝ) : |thirdUpperIntegral p| ≤ 64 := by + have h := intervalIntegral.norm_integral_le_of_norm_le_const (a:=baseCutoff p.1) (b:=2) + (C:=64) (f:=fun x => clampedThird x p.1 p.2) + (fun x _ => by simpa only [Real.norm_eq_abs] using clampedThird_bound x p.1 p.2) + have hc := baseCutoff_bounds p.1 + change |thirdUpperIntegral p| ≤ 64 + rw [Real.norm_eq_abs,abs_of_nonneg (by linarith : 0 ≤ 2-baseCutoff p.1)] at h + exact h.trans (by nlinarith) + +theorem thirdLowerIntegral_eq {x u : ℝ} (hx : x ∈ Icc (1:ℝ) 2) (hu : u ∈ Icc (1:ℝ) 2) : + thirdLowerIntegral (x,u)=∫ t : ℝ in 1..u,loss3Kernel t u x := by + rw [thirdLowerIntegral,baseCutoff_on hu.1 hu.2] + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hu.1] at ht + exact clampedThird_eq hx hu ⟨ht.1,ht.2.trans hu.2⟩ + +theorem thirdUpperIntegral_eq {u t : ℝ} (hu : u ∈ Icc (1:ℝ) 2) (ht : t ∈ Icc (1:ℝ) 2) : + thirdUpperIntegral (u,t)=∫ x : ℝ in u..2,loss3Kernel t u x := by + rw [thirdUpperIntegral,baseCutoff_on hu.1 hu.2] + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hu.2] at hx + exact clampedThird_eq ⟨hu.1.trans hx.1,hx.2⟩ hu ht + +end ErdosOmissionBindings + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/ThresholdFubini.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ThresholdFubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..73910c34a76752d787b280682ee9f25010d08b75 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/ThresholdFubini.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.BoundedLossTerms + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings + +theorem weighted_threshold_swap {P W T : ℝ → ℝ} + (hP : Measurable P) (hW : Measurable W) (hT : Measurable T) + (a Y b CP CW : ℝ) (hCP : 0 ≤ CP) (hCW : 0 ≤ CW) + (hPb : ∀ y ∈ Icc a Y,|P y| ≤ CP) + (hWb : ∀ t ∈ Icc (1:ℝ) b,|W t| ≤ CW) + (hTb : ∀ t ∈ Icc (1:ℝ) b,a ≤ T t ∧ T t ≤ Y) : + (∫ y in Icc a Y,P y*(∫ t in Icc (1:ℝ) b,if y if p.1 simp + have hright (t : ℝ) (ht : t ∈ Icc (1:ℝ) b) : + (∫ y in Icc a Y,G (y,t))=W t*(∫ y : ℝ in a..T t,P y) := by + have hset : Icc a Y ∩ Iio (T t)=Ico a (T t) := by + ext y + constructor + · rintro ⟨hy,hyT⟩; exact ⟨hy.1,hyT⟩ + · intro hy; exact ⟨⟨hy.1,hy.2.le.trans (hTb t ht).2⟩,hy.2⟩ + have he : (fun y : ℝ => G (y,t))=(Iio (T t)).indicator (fun y => W t*P y) := by + funext y + dsimp only [G] + by_cases hh : y H + have hH : ∀ i,Continuous (HH i) := fun _ => H.continuous + have hCpt : ∀ i,HasCompactSupport (HH i) := fun _ => hcompact + have hsupport : ∀ i : Side,∀ r s : ℝ,r<1 ∨ K+1 hzero + obtain ⟨BL,w₀,hBL,hw₀,hlim⟩ := original_prime_continuous_occupation_limit hH hCpt + (by norm_num : 0 < (1:ℝ)) (by linarith : 0 < K+1) hell hsupport d 1 hd (by norm_num) + let L : ℝ := |invariantAverage (arrivalTest ell HH)|+1 + let W : ℝ := weight .even (199/100) + have hL : 0 < L := by dsimp [L]; positivity + have hW : 0 < W := weight_pos (by norm_num [Valid]) + refine ⟨W*L,max BL ell,w₀,mul_pos hW hL,hBL.trans_le (le_max_left _ _),hw₀,?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBL' : BL ≤ B := (le_max_left _ _).trans hB + have hellB : ell ≤ B := (le_max_right _ _).trans hB + have hBpos : 0 < B := hBL.trans_le hBL' + obtain ⟨hs,hr,hBgap,_hsize⟩ := source_node_bounds hBpos start hi h199 h23 hcons hcut + have hlimit := hlim B w hBL' hw hcomp start hi h199 h23 hcons hcut + have hnorm : uncappedFamilyValue HH w ell start ≤ L := by + have hu := (abs_le.mp hlimit).2 + have hab := le_abs_self (invariantAverage (arrivalTest ell HH)) + dsimp only [L] + linarith + let Z : ℝ := ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*nodeReward HH w start ps + have hZ : 0 ≤ Z := Finset.sum_nonneg (fun ps _ => mul_nonneg (prefixWeight_nonneg ps) (hbounds _).1) + have hdom : compactPrefixMass K w ell start ≤ Z := by + apply Finset.sum_le_sum + intro ps hp + apply mul_le_mul_of_nonneg_left _ (prefixWeight_nonneg ps) + change (if 2 ≤ (terminal w start ps).gap ∧ (terminal w start ps).gap ≤ K then 1 else 0) ≤ + H ((terminal w start ps).gap,(terminal w start ps).ratio) + split_ifs with hgap + · have hpA : uncappedAllowed w ell start ps := (Finset.mem_filter.mp hp).2 + have hratio := uncapped_terminal_ratio_le_gap hell hr hs hcons (by rwa [hcut]) hpA + rw [hOne _ _ hgap.1 hgap.2 hratio.1.le (hratio.2.trans hgap.2)] + · exact (hbounds _).1 + have hwpos := weight_pos hs + have hwupper : weight start.side start.ratio ≤ W := by + rw [hi] + exact TwoStepDensityBounds.weight_antitone (by norm_num [Valid]) (by rwa [hi] at hs) h199 + have hsq : B^2 ≤ start.gap^2 := by nlinarith + calc + B^2*compactPrefixMass K w ell start ≤ B^2*Z := mul_le_mul_of_nonneg_left hdom (sq_nonneg B) + _ ≤ start.gap^2*Z := mul_le_mul_of_nonneg_right hsq hZ + _ = weight start.side start.ratio*uncappedFamilyValue HH w ell start := by + unfold uncappedFamilyValue + dsimp only [Z] + field_simp + _ ≤ weight start.side start.ratio*L := mul_le_mul_of_nonneg_left hnorm hwpos.le + _ ≤ W*L := mul_le_mul_of_nonneg_right hwupper hL.le + +end NumberTheoryLean.UncappedCompactMass + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/VariableUpperIntegral.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/VariableUpperIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c73c26e327cd8b21ceb1b37d8c8d1ed4a413c9d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/VariableUpperIntegral.lean @@ -0,0 +1,36 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +open MeasureTheory Set +namespace ErdosContinuousBoundary + +theorem continuous_variable_upper_integral + (F : (ℝ×ℝ) → ℝ → ℝ) (hF : Continuous F.uncurry) + (c : (ℝ×ℝ) → ℝ) (hc : Continuous c) : + Continuous (fun p => ∫ x in (1:ℝ)..c p,F p x) := by + let G : (ℝ×ℝ) → ℝ → ℝ := fun p t => F p ((c p-1)*t+1) + have hG : Continuous G.uncurry := by + change Continuous (F.uncurry ∘ (fun q : (ℝ×ℝ)×ℝ => (q.1,(c q.1-1)*q.2+1))) + apply hF.comp + exact continuous_fst.prodMk + (((hc.comp continuous_fst).sub continuous_const).mul continuous_snd |>.add continuous_const) + have hi : Continuous (fun p => ∫ t in Icc (0:ℝ) 1,G p t) := + continuous_parametric_integral_of_continuous hG isCompact_Icc + have heq (p : ℝ×ℝ) : (c p-1)*(∫ t in Icc (0:ℝ) 1,G p t)=∫ x in (1:ℝ)..c p,F p x := by + have h := intervalIntegral.smul_integral_comp_mul_add (a:=0) (b:=1) (fun x => F p x) (c p-1) 1 + rw [intervalIntegral.integral_of_le (by norm_num : (0:ℝ)≤1),← integral_Icc_eq_integral_Ioc] at h + simpa only [smul_eq_mul,mul_zero,zero_add,mul_one,sub_add_cancel,G] using h + exact ((hc.sub continuous_const).mul hi).congr heq + +end ErdosContinuousBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/WeightFutureIntegrals.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/WeightFutureIntegrals.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f2a6515dd5d7a7d79ad91d1eeb271c07d30a5af --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/WeightFutureIntegrals.lean @@ -0,0 +1,686 @@ +import Mathlib.MeasureTheory.Integral.IntegralEqImproper +import OAI.NumberTheory.Jacobsthal.Estimates.PairedDeficitPositivity +import OAI.NumberTheory.Jacobsthal.Sieve.BuchstabBridge + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.NormalizedDeficits + +open Filter Set +open scoped Topology +open LinearSieveFunctions BuchstabBridge + +noncomputable def lowerDeficit (s : ℝ) : ℝ := 1 - f sieveA s +noncomputable def upperDeficit (s : ℝ) : ℝ := F sieveA s - 1 +noncomputable def gap (s : ℝ) : ℝ := F sieveA s - f sieveA s + +theorem deficit_sum (s : ℝ) : lowerDeficit s + upperDeficit s = gap s := by + unfold lowerDeficit upperDeficit gap + ring + +theorem gap_eq_rho {s : ℝ} (hs : 1 ≤ s) : gap s = sieveA * Dickman.rho (s - 1) / s := + gap_identity sieveA hs + +theorem lowerDeficit_continuous : Continuous lowerDeficit := + continuous_const.sub (f_continuous sieveA) + +theorem upperDeficit_continuousOn : ContinuousOn upperDeficit (Ici 1) := + ((F_continuousOn sieveA).mono (by intro s hs; change 0 < s; exact lt_of_lt_of_le zero_lt_one hs)).sub continuousOn_const + +theorem gap_continuousOn : ContinuousOn gap (Ici 1) := by + have h := lowerDeficit_continuous.continuousOn.add upperDeficit_continuousOn + have heq : gap = fun s => lowerDeficit s + upperDeficit s := funext (fun s => (deficit_sum s).symm) + rw [heq] + exact h + +theorem gap_pos {s : ℝ} (hs : 1 ≤ s) : 0 < gap s := + LinearSieveFunctions.gap_pos sieveA_pos hs + +theorem lowerDeficit_mass_deriv {s : ℝ} (hs : 2 < s) : + HasDerivAt (fun t => t * lowerDeficit t) (-upperDeficit (s - 1)) s := by + convert! (hasDerivAt_id s).sub (mass_f_hasDerivAt sieveA hs) using 1 + · ext t + change t * (1 - f sieveA t) = t - t * f sieveA t + ring + · simp only [upperDeficit] + ring + +theorem upperDeficit_mass_deriv {s : ℝ} (hs : 2 < s) : + HasDerivAt (fun t => t * upperDeficit t) (-lowerDeficit (s - 1)) s := by + convert! (mass_F_hasDerivAt sieveA hs).sub (hasDerivAt_id s) using 1 + · ext t + change t * (F sieveA t - 1) = t * F sieveA t - t + ring + · simp only [lowerDeficit] + ring + +theorem gap_mass_deriv {s : ℝ} (hs : 2 < s) : + HasDerivAt (fun t => t * gap t) (-gap (s - 1)) s := by + convert! (mass_F_hasDerivAt sieveA hs).sub (mass_f_hasDerivAt sieveA hs) using 1 + · ext t + change t * (F sieveA t - f sieveA t) = t * F sieveA t - t * f sieveA t + ring + · simp only [gap] + ring + +theorem lowerDeficit_tendsto_zero : Tendsto lowerDeficit atTop (𝓝 0) := by + convert! normalized_f_tendsto_one.const_sub 1 using 1 + simp + +theorem upperDeficit_tendsto_zero : Tendsto upperDeficit atTop (𝓝 0) := by + convert! normalized_F_tendsto_one.sub_const 1 using 1 + simp + +theorem gap_tendsto_zero : Tendsto gap atTop (𝓝 0) := pair_gap_tendsto_zero sieveA + +theorem deficits_pos {s : ℝ} (hs : 1 ≤ s) : 0 < lowerDeficit s ∧ 0 < upperDeficit s := by + apply PairedDeficitPositivity.paired_pos lowerDeficit_continuous.continuousOn + upperDeficit_continuousOn ?_ ?_ ?_ (fun _ h => lowerDeficit_mass_deriv h) + (fun _ h => upperDeficit_mass_deriv h) lowerDeficit_tendsto_zero upperDeficit_tendsto_zero s hs + · intro t ht + simp only [lowerDeficit, f_initial sieveA ht.2, sub_zero, zero_lt_one] + · intro t ht + have ht0 : 0 < t := lt_of_lt_of_le zero_lt_one ht.1 + change 0 < F sieveA t - 1 + rw [F_initial sieveA ht0 (by linarith [ht.2])] + have h := (lt_div_iff₀ ht0).mpr (show 1 * t < sieveA by linarith [sieveA_gt_two, ht.2]) + linarith + · intro t ht + rw [deficit_sum] + exact gap_pos ht + +theorem deficit_offsets_pos {δ : ℝ} (hhalf : δ < 1 / 2) + (hδA : δ * sieveA < 1) (hδA2 : δ * sieveA < sieveA - 2) + {s : ℝ} (hs : 1 ≤ s) : + 0 < lowerDeficit s - δ * gap s ∧ 0 < upperDeficit s - δ * gap s := by + let a : ℝ → ℝ := fun t => lowerDeficit t - δ * gap t + let c : ℝ → ℝ := fun t => upperDeficit t - δ * gap t + have ha : ContinuousOn a (Ici 1) := + lowerDeficit_continuous.continuousOn.sub (continuousOn_const.mul gap_continuousOn) + have hc : ContinuousOn c (Ici 1) := + upperDeficit_continuousOn.sub (continuousOn_const.mul gap_continuousOn) + have hginit : ∀ t ∈ Icc 1 2, gap t = sieveA / t := by + intro t ht + simp only [gap, f_initial sieveA ht.2, sub_zero, + F_initial sieveA (s := t) (by linarith [ht.1]) (by linarith [ht.2])] + have hai : ∀ t ∈ Icc 1 2, 0 < a t := by + intro t ht + have ht0 : 0 < t := lt_of_lt_of_le zero_lt_one ht.1 + have hdiv : δ * sieveA / t < 1 := (div_lt_one ht0).mpr (lt_of_lt_of_le hδA ht.1) + dsimp [a, lowerDeficit] + rw [f_initial sieveA ht.2, hginit t ht] + have heq : δ * (sieveA / t) = δ * sieveA / t := by ring + rw [heq] + linarith + have hci : ∀ t ∈ Icc 1 2, 0 < c t := by + intro t ht + have ht0 : 0 < t := lt_of_lt_of_le zero_lt_one ht.1 + have hdiv : 0 < (sieveA - δ * sieveA - t) / t := + div_pos (by linarith [ht.2]) ht0 + dsimp [c, upperDeficit] + rw [F_initial sieveA ht0 (by linarith [ht.2]), hginit t ht] + convert! hdiv using 1 + field_simp + ring + have hsum : ∀ t, 1 ≤ t → 0 < a t + c t := by + intro t ht + have heq : a t + c t = (1 - 2 * δ) * gap t := by + dsimp [a, c] + rw [← deficit_sum t] + ring + rw [heq] + exact mul_pos (by linarith) (gap_pos ht) + have hda : ∀ t, 2 < t → HasDerivAt (fun u => u * a u) (-c (t - 1)) t := by + intro t ht + convert! (lowerDeficit_mass_deriv ht).sub ((gap_mass_deriv ht).const_mul δ) using 1 + · ext u + change u * (lowerDeficit u - δ * gap u) = u * lowerDeficit u - δ * (u * gap u) + ring + · dsimp [c] + ring + have hdc : ∀ t, 2 < t → HasDerivAt (fun u => u * c u) (-a (t - 1)) t := by + intro t ht + convert! (upperDeficit_mass_deriv ht).sub ((gap_mass_deriv ht).const_mul δ) using 1 + · ext u + change u * (upperDeficit u - δ * gap u) = u * upperDeficit u - δ * (u * gap u) + ring + · dsimp [a] + ring + have hla : Tendsto a atTop (𝓝 0) := by + simpa only [mul_zero, sub_zero] using lowerDeficit_tendsto_zero.sub (gap_tendsto_zero.const_mul δ) + have hlc : Tendsto c atTop (𝓝 0) := by + simpa only [mul_zero, sub_zero] using upperDeficit_tendsto_zero.sub (gap_tendsto_zero.const_mul δ) + exact PairedDeficitPositivity.paired_pos ha hc hai hci hsum hda hdc hla hlc s hs + +theorem deficits_uniform_comparison : ∃ δ : ℝ, 0 < δ ∧ δ < 1 / 2 ∧ + ∀ s : ℝ, 1 ≤ s → + δ * gap s < lowerDeficit s ∧ lowerDeficit s < (1 - δ) * gap s ∧ + δ * gap s < upperDeficit s ∧ upperDeficit s < (1 - δ) * gap s := by + let δ : ℝ := min 1 (sieveA - 2) / (4 * sieveA) + have hδpos : 0 < δ := div_pos (lt_min zero_lt_one (sub_pos.mpr sieveA_gt_two)) + (mul_pos (by norm_num) sieveA_pos) + have heq : δ * sieveA = min 1 (sieveA - 2) / 4 := by + dsimp [δ] + field_simp [ne_of_gt sieveA_pos] + have hδA : δ * sieveA < 1 := by rw [heq]; linarith [min_le_left (1 : ℝ) (sieveA - 2)] + have hδA2 : δ * sieveA < sieveA - 2 := by + rw [heq] + linarith [min_le_right (1 : ℝ) (sieveA - 2), sieveA_gt_two] + have hhalf : δ < 1 / 2 := by nlinarith [sieveA_gt_two] + refine ⟨δ, hδpos, hhalf, ?_⟩ + intro s hs + obtain ⟨ha, hc⟩ := deficit_offsets_pos hhalf hδA hδA2 hs + have hsum := deficit_sum s + constructor + · linarith + constructor + · nlinarith + constructor + · linarith + · nlinarith + +end NumberTheoryLean.NormalizedDeficits + +end + +section + +namespace NumberTheoryLean.DeficitFutureIntegrals + +open Filter Set MeasureTheory +open scoped Topology +open LinearSieveFunctions BuchstabBridge NormalizedDeficits + +theorem future_integral_of_mass {a b : ℝ → ℝ} {base : ℝ} (hbase : 1 ≤ base) + (ha : ContinuousOn a (Ioi 0)) + (hb : ∀ t, base - 1 < t → 0 ≤ b t) + (hd : ∀ t, base < t → HasDerivAt (fun u => u * a u) (-b (t - 1)) t) + (hl : Tendsto (fun t => t * a t) atTop (𝓝 0)) + {s : ℝ} (hs : base ≤ s) : + IntegrableOn b (Ioi (s - 1)) ∧ s * a s = ∫ t in Ioi (s - 1), b t := by + let H : ℝ → ℝ := fun t => (t + 1) * a (t + 1) + have hs0 : 0 < s := lt_of_lt_of_le (by linarith : 0 < base) hs + have hc : ContinuousWithinAt H (Ici (s - 1)) (s - 1) := by + have hm : ContinuousAt (fun t => t * a t) s := + continuousAt_id.mul (ha.continuousAt (Ioi_mem_nhds hs0)) + have hm' : ContinuousAt (fun t => t * a t) ((s - 1) + 1) := by simpa only [sub_add_cancel] using hm + have hc' := hm'.comp (f := fun t : ℝ => t + 1) (x := s - 1) + ((continuous_id.add continuous_const : Continuous (fun t : ℝ => t + 1)).continuousAt) + convert! hc'.continuousWithinAt using 1 + have hder : ∀ t ∈ Ioi (s - 1), HasDerivAt H (-b t) t := by + intro t ht + have hdt := (hd (t + 1) (by change s - 1 < t at ht; linarith)).comp t + ((hasDerivAt_id t).add_const 1) + convert! hdt using 1 + simp + have hnonpos : ∀ t ∈ Ioi (s - 1), -b t ≤ 0 := by + intro t ht + exact neg_nonpos.mpr (hb t (by change s - 1 < t at ht; linarith)) + have hshift : Tendsto (fun t : ℝ => t + 1) atTop atTop := by + apply tendsto_atTop.mpr + intro v + exact eventually_atTop.mpr ⟨v - 1, fun t ht => by linarith⟩ + have hlim : Tendsto H atTop (𝓝 0) := hl.comp hshift + have hint := integrableOn_Ioi_deriv_of_nonpos hc hder hnonpos hlim + have heq := integral_Ioi_of_hasDerivAt_of_nonpos hc hder hnonpos hlim + constructor + · exact integrable_neg_iff.mp hint + · simp only [integral_neg, H, sub_add_cancel, zero_sub] at heq + linarith + +theorem deficit_mass_bounds {s : ℝ} (hs : 1 ≤ s) : + (0 ≤ s * lowerDeficit s ∧ s * lowerDeficit s ≤ sieveA * Dickman.rho (s - 1)) ∧ + (0 ≤ s * upperDeficit s ∧ s * upperDeficit s ≤ sieveA * Dickman.rho (s - 1)) := by + obtain ⟨ha, hc⟩ := deficits_pos hs + have hsum := deficit_sum s + have hg : s * gap s = sieveA * Dickman.rho (s - 1) := by + rw [gap_eq_rho hs] + field_simp + have hs0 : 0 < s := lt_of_lt_of_le zero_lt_one hs + have hbA : s * lowerDeficit s ≤ s * gap s := + mul_le_mul_of_nonneg_left (by linarith) hs0.le + have hbC : s * upperDeficit s ≤ s * gap s := + mul_le_mul_of_nonneg_left (by linarith) hs0.le + exact ⟨⟨mul_nonneg hs0.le ha.le, by simpa only [hg] using hbA⟩, + ⟨mul_nonneg hs0.le hc.le, by simpa only [hg] using hbC⟩⟩ + +theorem lowerDeficit_mass_tendsto_zero : + Tendsto (fun s => s * lowerDeficit s) atTop (𝓝 0) := by + have hshift : Tendsto (fun s : ℝ => s - 1) atTop atTop := by + apply tendsto_atTop.mpr + intro v + exact eventually_atTop.mpr ⟨v + 1, fun s hs => by linarith⟩ + have hlim := (DickmanDecay.rho_tendsto_zero.comp hshift).const_mul sieveA + simp only [mul_zero] at hlim + apply squeeze_zero' ?_ ?_ hlim + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs + exact (deficit_mass_bounds hs).1.1 + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs + exact (deficit_mass_bounds hs).1.2 + +theorem upperDeficit_mass_tendsto_zero : + Tendsto (fun s => s * upperDeficit s) atTop (𝓝 0) := by + have hshift : Tendsto (fun s : ℝ => s - 1) atTop atTop := by + apply tendsto_atTop.mpr + intro v + exact eventually_atTop.mpr ⟨v + 1, fun s hs => by linarith⟩ + have hlim := (DickmanDecay.rho_tendsto_zero.comp hshift).const_mul sieveA + simp only [mul_zero] at hlim + apply squeeze_zero' ?_ ?_ hlim + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs + exact (deficit_mass_bounds hs).2.1 + · filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs + exact (deficit_mass_bounds hs).2.2 + +theorem upperDeficit_mass_deriv_of_one_lt {s : ℝ} (hs : 1 < s) : + HasDerivAt (fun t => t * upperDeficit t) (-lowerDeficit (s - 1)) s := by + by_cases hs2 : 2 < s + · exact upperDeficit_mass_deriv hs2 + · have heq : (fun t => t * upperDeficit t) =ᶠ[𝓝 s] (fun t => sieveA - t) := by + filter_upwards [Ioo_mem_nhds (show 0 < s by linarith) (show s < 3 by linarith)] with t ht + change t * (F sieveA t - 1) = sieveA - t + rw [F_initial sieveA ht.1 ht.2.le] + field_simp [ne_of_gt ht.1] + have h := ((hasDerivAt_const s sieveA).sub (hasDerivAt_id s)).congr_of_eventuallyEq heq + convert! h using 1 + simp only [lowerDeficit, f_initial sieveA (s := s - 1) (by linarith), sub_zero, zero_sub] + +theorem lowerDeficit_nonneg (s : ℝ) : 0 ≤ lowerDeficit s := by + by_cases hs : 1 ≤ s + · exact (deficits_pos hs).1.le + · simp only [lowerDeficit, f_initial sieveA (by linarith : s ≤ 2), sub_zero, zero_le_one] + +theorem lower_future_integral {s : ℝ} (hs : 2 ≤ s) : + IntegrableOn upperDeficit (Ioi (s - 1)) ∧ + s * lowerDeficit s = ∫ t in Ioi (s - 1), upperDeficit t := by + exact future_integral_of_mass (a := lowerDeficit) (b := upperDeficit) (base := 2) (by norm_num) + lowerDeficit_continuous.continuousOn (fun t ht => (deficits_pos (s := t) (by linarith)).2.le) + (fun _ ht => lowerDeficit_mass_deriv ht) lowerDeficit_mass_tendsto_zero hs + +theorem upper_future_integral {s : ℝ} (hs : 1 ≤ s) : + IntegrableOn lowerDeficit (Ioi (s - 1)) ∧ + s * upperDeficit s = ∫ t in Ioi (s - 1), lowerDeficit t := by + exact future_integral_of_mass (a := upperDeficit) (b := lowerDeficit) (base := 1) le_rfl + ((F_continuousOn sieveA).sub continuousOn_const) (fun t _ => lowerDeficit_nonneg t) + (fun _ ht => upperDeficit_mass_deriv_of_one_lt ht) upperDeficit_mass_tendsto_zero hs + +end NumberTheoryLean.DeficitFutureIntegrals + +end + +section + +namespace NumberTheoryLean.DerivativeWeights + +open Filter Set MeasureTheory +open scoped Topology +open LinearSieveFunctions BuchstabBridge NormalizedDeficits DeficitFutureIntegrals + +noncomputable def evenInitial (s : ℝ) : ℝ := + sieveA * (s / (s - 1) - Real.log (s - 1)) + +noncomputable def phiEven (s : ℝ) : ℝ := + if s ≤ 2 then evenInitial s else s * (lowerDeficit s + upperDeficit (s - 1)) + +noncomputable def phiOdd (s : ℝ) : ℝ := + if s ≤ 3 then sieveA else s * (upperDeficit s + lowerDeficit (s - 1)) + +noncomputable def W (t : ℝ) : ℝ := (t + 1) / t ^ 2 + +theorem phiOdd_initial {s : ℝ} (hs : s ≤ 3) : phiOdd s = sieveA := by + simp only [phiOdd, ite_eq_left hs] + +theorem phiEven_initial {s : ℝ} (hs : s ≤ 2) : phiEven s = evenInitial s := by + simp only [phiEven, ite_eq_left hs] + +theorem phiEven_eq_deficits {s : ℝ} (hs : 2 ≤ s) : + phiEven s = s * (lowerDeficit s + upperDeficit (s - 1)) := by + rcases eq_or_lt_of_le hs with h | h + · subst s + norm_num [phiEven, evenInitial, lowerDeficit, upperDeficit, + f_initial, F_initial sieveA (s := 1) (by norm_num) (by norm_num)] + ring + · exact ite_eq_right (not_le_of_gt h) + +theorem phiOdd_eq_deficits {s : ℝ} (hs : 1 ≤ s) : + phiOdd s = s * (upperDeficit s + lowerDeficit (s - 1)) := by + by_cases hs3 : s ≤ 3 + · rw [phiOdd_initial hs3] + simp only [upperDeficit, lowerDeficit, f_initial sieveA (s := s - 1) (by linarith), + F_initial sieveA (s := s) (by linarith) hs3] + field_simp + ring + · exact ite_eq_right hs3 + +theorem phiEven_explicit {s : ℝ} (hs : 1 < s) (hs4 : s ≤ 4) : + phiEven s = evenInitial s := by + by_cases hs2 : s ≤ 2 + · exact phiEven_initial hs2 + · rw [phiEven_eq_deficits (by linarith)] + unfold lowerDeficit upperDeficit evenInitial + rw [f_first_formula sieveA (by linarith) hs4, + F_initial sieveA (s := s - 1) (by linarith) (by linarith)] + field_simp + ring + +theorem hasDerivAt_of_mass {g : ℝ → ℝ} {s v : ℝ} (hs : s ≠ 0) + (hm : HasDerivAt (fun t => t * g t) v s) : + HasDerivAt g ((v - g s) / s) s := by + have heq : g =ᶠ[𝓝 s] (fun t => (t * g t) / t) := by + filter_upwards [eventually_ne_nhds hs] with t ht + field_simp + have h := (hm.div (hasDerivAt_id s) hs).congr_of_eventuallyEq heq + convert! h using 1 + simp only [id_eq, mul_one] + field_simp + +theorem lowerDeficit_hasDerivAt {s : ℝ} (hs : 2 < s) : + HasDerivAt lowerDeficit (-phiEven s / s ^ 2) s := by + have h := hasDerivAt_of_mass (by linarith : s ≠ 0) (lowerDeficit_mass_deriv hs) + convert! h using 1 + rw [phiEven_eq_deficits hs.le] + field_simp + ring + +theorem upperDeficit_hasDerivAt {s : ℝ} (hs : 1 < s) : + HasDerivAt upperDeficit (-phiOdd s / s ^ 2) s := by + have h := hasDerivAt_of_mass (by linarith : s ≠ 0) (upperDeficit_mass_deriv_of_one_lt hs) + convert! h using 1 + rw [phiOdd_eq_deficits hs.le] + field_simp + ring + +theorem evenInitial_hasDerivAt {s : ℝ} (hs : 1 < s) : + HasDerivAt evenInitial (-s / (s - 1) ^ 2 * sieveA) s := by + have hn : s - 1 ≠ 0 := by linarith + have h := (((hasDerivAt_id s).div ((hasDerivAt_id s).sub_const 1) hn).sub + (((hasDerivAt_id s).sub_const 1).log hn)).const_mul sieveA + convert! h using 1 + simp only [id_eq, one_mul, mul_one] + field_simp + ring + +theorem phiEven_hasDerivAt {s : ℝ} (hs : 1 < s) : + HasDerivAt phiEven (-s / (s - 1) ^ 2 * phiOdd (s - 1)) s := by + by_cases hs3 : s < 3 + · have heq : phiEven =ᶠ[𝓝 s] evenInitial := by + filter_upwards [Ioo_mem_nhds hs hs3] with t ht + exact phiEven_explicit ht.1 (by linarith [ht.2]) + rw [phiOdd_initial (s := s - 1) (by linarith)] + exact (evenInitial_hasDerivAt hs).congr_of_eventuallyEq heq + · have hs2 : 2 < s := by linarith + have hU := (upperDeficit_hasDerivAt (s := s - 1) (by linarith)).comp s + ((hasDerivAt_id s).sub_const 1) + have h := (hasDerivAt_id s).mul ((lowerDeficit_hasDerivAt hs2).add hU) + have heq : phiEven =ᶠ[𝓝 s] (fun t => t * (lowerDeficit t + upperDeficit (t - 1))) := by + filter_upwards [Ioi_mem_nhds hs2] with t ht + exact phiEven_eq_deficits ht.le + have hd := h.congr_of_eventuallyEq heq + convert! hd using 1 + simp only [id_eq, Pi.add_apply, Function.comp_apply, one_mul, mul_one] + rw [phiEven_eq_deficits hs2.le] + field_simp + ring + +theorem phiOdd_hasDerivAt {s : ℝ} (hs : 3 < s) : + HasDerivAt phiOdd (-s / (s - 1) ^ 2 * phiEven (s - 1)) s := by + have hA := (lowerDeficit_hasDerivAt (s := s - 1) (by linarith)).comp s + ((hasDerivAt_id s).sub_const 1) + have h := (hasDerivAt_id s).mul ((upperDeficit_hasDerivAt (by linarith : 1 < s)).add hA) + have heq : phiOdd =ᶠ[𝓝 s] (fun t => t * (upperDeficit t + lowerDeficit (t - 1))) := by + filter_upwards [Ioi_mem_nhds (show 1 < s by linarith)] with t ht + exact phiOdd_eq_deficits ht.le + have hd := h.congr_of_eventuallyEq heq + convert! hd using 1 + simp only [id_eq, Pi.add_apply, Function.comp_apply, one_mul, mul_one] + rw [phiOdd_eq_deficits (by linarith)] + field_simp + ring + +theorem phiEven_pos {s : ℝ} (hs : 1 < s) : 0 < phiEven s := by + by_cases hs2 : 2 ≤ s + · rw [phiEven_eq_deficits hs2] + exact mul_pos (by linarith) (add_pos (deficits_pos (by linarith)).1 + (deficits_pos (s := s - 1) (by linarith)).2) + · rw [phiEven_initial (by linarith)] + unfold evenInitial + have hlog : Real.log (s - 1) < 0 := Real.log_neg (by linarith) (by linarith) + exact mul_pos sieveA_pos (sub_pos.mpr (lt_trans hlog (div_pos (by linarith) (by linarith)))) + +theorem phiOdd_pos (s : ℝ) : 0 < phiOdd s := by + by_cases hs3 : s ≤ 3 + · rw [phiOdd_initial hs3] + exact sieveA_pos + · rw [phiOdd_eq_deficits (by linarith)] + exact mul_pos (by linarith) (add_pos (deficits_pos (by linarith)).2 + (deficits_pos (s := s - 1) (by linarith)).1) + +theorem phiEven_continuousAt {s : ℝ} (hs : 1 < s) : ContinuousAt phiEven s := + (phiEven_hasDerivAt hs).continuousAt + +theorem phiOdd_continuous : Continuous phiOdd := by + apply continuous_iff_continuousAt.mpr + intro s + by_cases hs3 : s < 3 + · have heq : phiOdd =ᶠ[𝓝 s] (fun _ => sieveA) := by + filter_upwards [Iio_mem_nhds hs3] with t ht + exact phiOdd_initial ht.le + exact continuousAt_const.congr_of_eventuallyEq heq + · have heq : phiOdd =ᶠ[𝓝 s] (fun t => t * (upperDeficit t + lowerDeficit (t - 1))) := by + filter_upwards [Ioi_mem_nhds (show 1 < s by linarith)] with t ht + exact phiOdd_eq_deficits ht.le + have hcU : ContinuousAt upperDeficit s := + (F_continuousAt sieveA (by linarith)).sub continuousAt_const + have hcA : ContinuousAt (fun t => lowerDeficit (t - 1)) s := + (lowerDeficit_continuous.comp (continuous_id.sub continuous_const)).continuousAt + exact (continuousAt_id.mul (hcU.add hcA)).congr_of_eventuallyEq heq + +theorem f_hasDerivAt {s : ℝ} (hs : 2 < s) : + HasDerivAt (f sieveA) (phiEven s / s ^ 2) s := by + convert! (lowerDeficit_hasDerivAt hs).const_sub 1 using 1 + · ext t + change f sieveA t = 1 - (1 - f sieveA t) + ring + · ring + +theorem F_hasDerivAt {s : ℝ} (hs : 0 < s) : + HasDerivAt (F sieveA) (-phiOdd s / s ^ 2) s := by + by_cases hs1 : 1 < s + · convert! (upperDeficit_hasDerivAt hs1).add_const 1 using 1 + ext t + change F sieveA t = (F sieveA t - 1) + 1 + ring + · have heq : F sieveA =ᶠ[𝓝 s] (fun t => sieveA / t) := by + filter_upwards [Ioo_mem_nhds hs (show s < 3 by linarith)] with t ht + exact F_initial sieveA ht.1 ht.2.le + have hd := ((hasDerivAt_const s sieveA).div (hasDerivAt_id s) (ne_of_gt hs)).congr_of_eventuallyEq heq + convert! hd using 1 + rw [phiOdd_initial (by linarith)] + simp only [id_eq, zero_mul, zero_sub, mul_one] + +theorem startingExtension_hasDerivAt {s : ℝ} (hs : 1 < s) : + HasDerivAt (startingExtension sieveA) (evenInitial s / s ^ 2) s := by + have hn : s - 1 ≠ 0 := by linarith + have hd := ((((hasDerivAt_id s).sub_const 1).log hn).const_mul sieveA).div + (hasDerivAt_id s) (by linarith : s ≠ 0) + convert! hd using 1 + simp only [evenInitial, id_eq, mul_one] + field_simp + +theorem f_right_derivative_two : + HasDerivWithinAt (f sieveA) (phiEven 2 / 2 ^ 2) (Ici 2) 2 := by + rw [phiEven_initial le_rfl] + apply (startingExtension_hasDerivAt (s := 2) (by norm_num)).hasDerivWithinAt.congr_of_eventuallyEq_of_mem + · filter_upwards [self_mem_nhdsWithin, + (nhdsWithin_le_nhds (Iio_mem_nhds (show (2 : ℝ) < 4 by norm_num)))] with t ht ht4 + exact (startingExtension_eq_f sieveA ht ht4.le).symm + · exact self_mem_Ici + +theorem phiEven_eq_deriv {s : ℝ} (hs : 2 < s) : + phiEven s = s ^ 2 * deriv (f sieveA) s := by + rw [(f_hasDerivAt hs).deriv] + field_simp + +theorem phiOdd_eq_deriv {s : ℝ} (hs : 0 < s) : + phiOdd s = -s ^ 2 * deriv (F sieveA) s := by + rw [(F_hasDerivAt hs).deriv] + field_simp + +theorem phiEven_eq_right_deriv_two : + phiEven 2 = 2 ^ 2 * derivWithin (f sieveA) (Ici 2) 2 := by + rw [f_right_derivative_two.derivWithin (uniqueDiffWithinAt_Ici (2 : ℝ))] + ring + +theorem phiEven_strictAntiOn : StrictAntiOn phiEven (Ioi 1) := by + apply strictAntiOn_of_deriv_neg (convex_Ioi 1) + · intro s hs + exact (phiEven_continuousAt hs).continuousWithinAt + · intro s hs + rw [interior_Ioi] at hs + change 1 < s at hs + rw [(phiEven_hasDerivAt hs).deriv] + exact mul_neg_of_neg_of_pos (div_neg_of_neg_of_pos (by linarith) + (sq_pos_of_pos (by linarith))) (phiOdd_pos _) + +theorem phiOdd_antitone : Antitone phiOdd := by + have htail : AntitoneOn phiOdd (Ici 3) := by + apply antitoneOn_of_deriv_nonpos (convex_Ici 3) phiOdd_continuous.continuousOn + · intro s hs + rw [interior_Ici] at hs + exact (phiOdd_hasDerivAt hs).differentiableAt.differentiableWithinAt + · intro s hs + rw [interior_Ici] at hs + change 3 < s at hs + rw [(phiOdd_hasDerivAt hs).deriv] + exact mul_nonpos_of_nonpos_of_nonneg (div_nonpos_of_nonpos_of_nonneg (by linarith) (sq_nonneg _)) + (phiEven_pos (by linarith)).le + intro x y hxy + by_cases hy : y ≤ 3 + · rw [phiOdd_initial hy, phiOdd_initial (le_trans hxy hy)] + · by_cases hx : x ≤ 3 + · rw [phiOdd_initial hx, ← phiOdd_initial (s := 3) le_rfl] + exact htail (by simp) (le_of_not_ge hy) (le_of_not_ge hy) + · exact htail (le_of_not_ge hx) (le_of_not_ge hy) hxy + +end NumberTheoryLean.DerivativeWeights + +end + +section + +namespace NumberTheoryLean.WeightFutureIntegrals + +open Filter Set MeasureTheory +open scoped Topology +open NormalizedDeficits DeficitFutureIntegrals DerivativeWeights + +theorem phiEven_tendsto_zero : Tendsto phiEven atTop (𝓝 0) := by + have hshift : Tendsto (fun s : ℝ => s - 1) atTop atTop := by + apply tendsto_atTop.mpr + intro v + exact eventually_atTop.mpr ⟨v + 1, fun s hs => by linarith⟩ + have hl := lowerDeficit_mass_tendsto_zero.add + ((upperDeficit_mass_tendsto_zero.comp hshift).add (upperDeficit_tendsto_zero.comp hshift)) + simp only [add_zero] at hl + apply hl.congr' + filter_upwards [eventually_ge_atTop (2 : ℝ)] with s hs + rw [phiEven_eq_deficits hs] + simp only [Function.comp_apply] + ring + +theorem phiOdd_tendsto_zero : Tendsto phiOdd atTop (𝓝 0) := by + have hshift : Tendsto (fun s : ℝ => s - 1) atTop atTop := by + apply tendsto_atTop.mpr + intro v + exact eventually_atTop.mpr ⟨v + 1, fun s hs => by linarith⟩ + have hl := upperDeficit_mass_tendsto_zero.add + ((lowerDeficit_mass_tendsto_zero.comp hshift).add (lowerDeficit_tendsto_zero.comp hshift)) + simp only [add_zero] at hl + apply hl.congr' + filter_upwards [eventually_ge_atTop (1 : ℝ)] with s hs + rw [phiOdd_eq_deficits hs] + simp only [Function.comp_apply] + ring + +theorem W_pos {t : ℝ} (ht : 0 < t) : 0 < W t := by + unfold W + positivity + +theorem future_integral_of_shifted_deriv {P B : ℝ → ℝ} {s : ℝ} + (hc : ContinuousAt P s) + (hd : ∀ t, s < t → HasDerivAt P (-B (t - 1)) t) + (hb : ∀ t, s - 1 < t → 0 ≤ B t) + (hl : Tendsto P atTop (𝓝 0)) : + IntegrableOn B (Ioi (s - 1)) ∧ P s = ∫ t in Ioi (s - 1), B t := by + let H : ℝ → ℝ := fun t => P (t + 1) + have hc' : ContinuousWithinAt H (Ici (s - 1)) (s - 1) := by + have hcs : ContinuousAt P ((s - 1) + 1) := by simpa only [sub_add_cancel] using hc + exact (hcs.comp (f := fun t : ℝ => t + 1) (x := s - 1) + (continuous_id.add continuous_const).continuousAt).continuousWithinAt + have hder : ∀ t ∈ Ioi (s - 1), HasDerivAt H (-B t) t := by + intro t ht + have h := (hd (t + 1) (by change s - 1 < t at ht; linarith)).comp t + ((hasDerivAt_id t).add_const 1) + convert! h using 1 + simp + have hn : ∀ t ∈ Ioi (s - 1), -B t ≤ 0 := fun t ht => neg_nonpos.mpr (hb t ht) + have hshift : Tendsto (fun t : ℝ => t + 1) atTop atTop := by + apply tendsto_atTop.mpr + intro v + exact eventually_atTop.mpr ⟨v - 1, fun t ht => by linarith⟩ + have hlim : Tendsto H atTop (𝓝 0) := hl.comp hshift + have hint := integrableOn_Ioi_deriv_of_nonpos hc' hder hn hlim + have heq := integral_Ioi_of_hasDerivAt_of_nonpos hc' hder hn hlim + constructor + · exact integrable_neg_iff.mp hint + · simp only [integral_neg, H, sub_add_cancel, zero_sub] at heq + linarith + +theorem phiEven_future_integral {s : ℝ} (hs : 1 < s) : + IntegrableOn (fun t => W t * phiOdd t) (Ioi (s - 1)) ∧ + phiEven s = ∫ t in Ioi (s - 1), W t * phiOdd t := by + apply future_integral_of_shifted_deriv (phiEven_continuousAt hs) ?_ ?_ phiEven_tendsto_zero + · intro t ht + convert! phiEven_hasDerivAt (lt_trans hs ht) using 1 + simp only [W, sub_add_cancel] + ring + · intro t ht + exact (mul_pos (W_pos (by linarith)) (phiOdd_pos t)).le + +theorem phiOdd_future_integral (s : ℝ) : + IntegrableOn (fun t => W t * phiEven t) (Ioi (max 2 (s - 1))) ∧ + phiOdd s = ∫ t in Ioi (max 2 (s - 1)), W t * phiEven t := by + have hc := phiOdd_continuous.continuousAt (x := max 3 s) + have hder : ∀ t, max 3 s < t → + HasDerivAt phiOdd (-(W (t - 1) * phiEven (t - 1))) t := by + intro t ht + convert! phiOdd_hasDerivAt (lt_of_le_of_lt (le_max_left _ _) ht) using 1 + simp only [W, sub_add_cancel] + ring + have hn : ∀ t, max 3 s - 1 < t → 0 ≤ W t * phiEven t := by + intro t ht + have ht1 : 1 < t := by linarith [le_max_left (3 : ℝ) s] + exact (mul_pos (W_pos (by linarith)) (phiEven_pos ht1)).le + have h := future_integral_of_shifted_deriv hc hder hn phiOdd_tendsto_zero + have hmax : max 3 s - 1 = max 2 (s - 1) := by + by_cases hs : s ≤ 3 + · rw [max_eq_left hs, max_eq_left (by linarith)] + norm_num + · rw [max_eq_right (le_of_not_ge hs), max_eq_right (by linarith)] + have heq : phiOdd (max 3 s) = phiOdd s := by + by_cases hs : s ≤ 3 + · rw [max_eq_left hs, phiOdd_initial le_rfl, phiOdd_initial hs] + · rw [max_eq_right (le_of_not_ge hs)] + simpa only [hmax, heq] using h + +end NumberTheoryLean.WeightFutureIntegrals + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Analysis/WeightIntegrals.lean b/lean/OAI/NumberTheory/Jacobsthal/Analysis/WeightIntegrals.lean new file mode 100644 index 0000000000000000000000000000000000000000..6389eb6f3804ace89a63d0b323f3ce9f0446fe8a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Analysis/WeightIntegrals.lean @@ -0,0 +1,272 @@ +import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Paths.FiniteHistorySupport + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.TwoStepDensityBounds + +open Set +open DerivativeWeights WeightFutureIntegrals FinitePathGeometry + +noncomputable def baseRatio : Side → ℝ | .even => 198 / 100 | .odd => 95 / 100 + +theorem baseRatio_valid (i : Side) : Valid i (baseRatio i) := by cases i <;> exact le_rfl + +theorem baseRatio_le {i : Side} {s : ℝ} (hs : Valid i s) : baseRatio i ≤ s := by + cases i <;> exact hs + +theorem valid_of_three_le (i : Side) {s : ℝ} (hs : 3 ≤ s) : Valid i s := by + cases i <;> dsimp [Valid] <;> linarith + +theorem weight_antitone {i : Side} {s t : ℝ} (hs : Valid i s) (ht : Valid i t) (hst : s ≤ t) : + weight i t ≤ weight i s := by + cases i with + | even => + exact phiEven_strictAntiOn.antitoneOn + (by change 1 < s; dsimp [Valid] at hs; linarith) + (by change 1 < t; dsimp [Valid] at ht; linarith) hst + | odd => exact phiOdd_antitone hst + +theorem two_step_density_eq {i : Side} {s t u : ℝ} (hs : Valid i s) + (ht : minRatio i s ≤ t) (hu : minRatio i.flip t ≤ u) : + transitionDensity i s t * transitionDensity i.flip t u = + (W t * W u) * (weight i u / weight i s) := by + have htV := valid_next hs ht + have hw := weight_pos hs + have hwt := weight_pos htV + have hflip : i.flip.flip = i := by cases i <;> rfl + unfold transitionDensity TransitionKernels.tailDensity + rw [indicator_of_mem (show t ∈ Ici (minRatio i s) from ht), + indicator_of_mem (show u ∈ Ici (minRatio i.flip t) from hu), hflip] + field_simp + +theorem rectangle_admissible {i : Side} {s L t u : ℝ} (hL : 3 ≤ L) (hsL : s ≤ L) + (ht : t ∈ Icc L (L + 1)) (hu : u ∈ Icc (L + 1) (L + 2)) : + minRatio i s ≤ t ∧ minRatio i.flip t ≤ u := by + cases i <;> dsimp [minRatio, Side.flip] + · constructor + · linarith [ht.1] + · apply max_le <;> linarith [ht.2, hu.1] + · constructor + · apply max_le <;> linarith [ht.1] + · linarith [ht.2, hu.1] + +theorem W_lower {t M : ℝ} (ht : 0 < t) (htM : t ≤ M) : 1 / M ≤ W t := by + have hM : 0 < M := lt_of_lt_of_le ht htM + unfold W + apply (div_le_div_iff₀ hM (sq_pos_of_pos ht)).mpr + nlinarith + +noncomputable def rectangleLower (i : Side) (L : ℝ) : ℝ := + (1 / (L + 2)) ^ 2 * (weight i (L + 2) / weight i (baseRatio i)) + +theorem rectangleLower_pos (i : Side) {L : ℝ} (hL : 3 ≤ L) : 0 < rectangleLower i L := by + unfold rectangleLower + exact mul_pos (sq_pos_of_pos (one_div_pos.mpr (by linarith))) + (div_pos (weight_pos (valid_of_three_le i (by linarith))) (weight_pos (baseRatio_valid i))) + +theorem rectangle_density_lower {i : Side} {s L t u : ℝ} (hL : 3 ≤ L) + (hs : Valid i s) (hsL : s ≤ L) + (ht : t ∈ Icc L (L + 1)) (hu : u ∈ Icc (L + 1) (L + 2)) : + rectangleLower i L ≤ transitionDensity i s t * transitionDensity i.flip t u := by + obtain ⟨hadt, hadu⟩ := rectangle_admissible (i := i) hL hsL ht hu + rw [two_step_density_eq hs hadt hadu] + have ht0 : 0 < t := by linarith [ht.1] + have hu0 : 0 < u := by linarith [hu.1] + have htM : t ≤ L + 2 := by linarith [ht.2] + have hW : (1 / (L + 2)) ^ 2 ≤ W t * W u := by + simpa only [pow_two] using mul_le_mul (W_lower ht0 htM) (W_lower hu0 hu.2) + (one_div_nonneg.mpr (by linarith)) (W_pos ht0).le + have hsW := weight_pos hs + have hbaseW := weight_pos (baseRatio_valid i) + have hMW := weight_pos (valid_of_three_le i (s := L + 2) (by linarith)) + have huV := valid_of_three_le i (s := u) (by linarith [hu.1]) + have hden := weight_antitone (baseRatio_valid i) hs (baseRatio_le hs) + have hnum := weight_antitone huV (valid_of_three_le i (s := L + 2) (by linarith)) hu.2 + have hratio : weight i (L + 2) / weight i (baseRatio i) ≤ weight i u / weight i s := by + calc + _ ≤ weight i (L + 2) / weight i s := div_le_div_of_nonneg_left hMW.le hsW hden + _ ≤ _ := div_le_div_of_nonneg_right hnum hsW.le + exact mul_le_mul hW hratio (div_pos hMW hbaseW).le (mul_pos (W_pos ht0) (W_pos hu0)).le + +noncomputable def minorizationSize (L : ℝ) : ℝ := + min 1 (min (rectangleLower .even L) (rectangleLower .odd L)) + +theorem minorizationSize_pos {L : ℝ} (hL : 3 ≤ L) : 0 < minorizationSize L := + lt_min zero_lt_one (lt_min (rectangleLower_pos .even hL) (rectangleLower_pos .odd hL)) + +theorem minorizationSize_le_one (L : ℝ) : minorizationSize L ≤ 1 := min_le_left _ _ + +theorem minorizationSize_le_rectangle (i : Side) (L : ℝ) : minorizationSize L ≤ rectangleLower i L := by + cases i with + | even => exact le_trans (min_le_right _ _) (min_le_left _ _) + | odd => exact le_trans (min_le_right _ _) (min_le_right _ _) + +end NumberTheoryLean.TwoStepDensityBounds + +end + +section + +open Set MeasureTheory +namespace Erdos970Dependency.WeightIntegrals +open NumberTheoryLean.DerivativeWeights NumberTheoryLean.WeightFutureIntegrals + +noncomputable def wPrimitive (t : ℝ) : ℝ := Real.log t - 1 / t +noncomputable def wMass (a b : ℝ) : ℝ := ∫ t in a..b, W t + +theorem W_continuousAt {t : ℝ} (ht : t ≠ 0) : ContinuousAt W t := by + unfold W + fun_prop (disch := simp [ht]) + +theorem wPrimitive_deriv {t : ℝ} (ht : 0 < t) : HasDerivAt wPrimitive (W t) t := by + have h := (Real.hasDerivAt_log (ne_of_gt ht)).sub + ((hasDerivAt_const t (1 : ℝ)).div (hasDerivAt_id t) (ne_of_gt ht)) + convert! h using 1 + simp only [W, id_eq, zero_mul, zero_sub, mul_one] + field_simp + ring + +theorem wMass_eq {a b : ℝ} (ha : 0 < a) (hb : 0 < b) : + wMass a b = wPrimitive b - wPrimitive a := by + have hp (t : ℝ) (ht : t ∈ uIcc a b) : 0 < t := + lt_of_lt_of_le (lt_min ha hb) ht.1 + apply intervalIntegral.integral_eq_sub_of_hasDerivAt + · intro t ht + exact wPrimitive_deriv (hp t ht) + · apply ContinuousOn.intervalIntegrable + intro t ht + exact (W_continuousAt (ne_of_gt (hp t ht))).continuousWithinAt + +theorem wMass_nonneg {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) : 0 ≤ wMass a b := by + apply intervalIntegral.integral_nonneg hab + intro t ht + exact (W_pos (ha.trans_le ht.1)).le + +theorem wMass_mono_right {a b c : ℝ} (ha : 0 < a) (hab : a ≤ b) (hbc : b ≤ c) : + wMass a b ≤ wMass a c := by + have hsplit : wMass a c = wMass a b + wMass b c := by + rw [wMass_eq ha (ha.trans_le (hab.trans hbc)), wMass_eq ha (ha.trans_le hab), + wMass_eq (ha.trans_le hab) (ha.trans_le (hab.trans hbc))] + ring + rw [hsplit] + linarith [wMass_nonneg (ha.trans_le hab) hbc] + +theorem wMass_two_three_lower : (1 : ℝ) / 3 ≤ wMass 2 3 := by + have hW : ∀ t ∈ Icc (2 : ℝ) 3, (1 : ℝ) / 3 ≤ W t := by + intro t ht + exact NumberTheoryLean.TwoStepDensityBounds.W_lower (by linarith [ht.1]) ht.2 + have hI : IntervalIntegrable W volume 2 3 := by + apply ContinuousOn.intervalIntegrable + intro t ht + rw [uIcc_of_le (by norm_num : (2 : ℝ) ≤ 3)] at ht + exact (W_continuousAt (by linarith [ht.1])).continuousWithinAt + have h := intervalIntegral.integral_mono_on (by norm_num : (2 : ℝ) ≤ 3) + (by simp : IntervalIntegrable (fun _ : ℝ ↦ (1 : ℝ) / 3) volume 2 3) hI hW + norm_num only [intervalIntegral.integral_const, smul_eq_mul] at h + exact h + +theorem wMass_initial_upper {a : ℝ} (ha : 99 / 100 ≤ a) (ha2 : a ≤ 2) : wMass a 2 ≤ 5 := by + have ha0 : 0 < a := by linarith + have hW : ∀ t ∈ Icc a (2 : ℝ), W t ≤ 4 := by + intro t ht + have ht0 : 0 < t := ha0.trans_le ht.1 + unfold W + apply (div_le_iff₀ (sq_pos_of_pos ht0)).mpr + nlinarith [sq_nonneg (t - 99 / 100), ht.1, ht.2] + have hI : IntervalIntegrable W volume a 2 := by + apply ContinuousOn.intervalIntegrable + intro t ht + rw [uIcc_of_le ha2] at ht + exact (W_continuousAt (ne_of_gt (ha0.trans_le ht.1))).continuousWithinAt + have h := intervalIntegral.integral_mono_on ha2 hI + (by simp : IntervalIntegrable (fun _ : ℝ ↦ (4 : ℝ)) volume a 2) hW + simp only [intervalIntegral.integral_const, smul_eq_mul] at h + exact h.trans (by linarith) + +noncomputable def tailW (u : ℝ) : ℝ := wPrimitive (u + 1) - wPrimitive 2 + +noncomputable def regIntegral (t : ℝ) : ℝ := ∫ u in (1 : ℝ)..t + 1, W u * tailW u + +theorem tailW_measurable : Measurable tailW := by + unfold tailW wPrimitive + fun_prop + +theorem tailW_eq_mass {u : ℝ} (hu : 1 ≤ u) : tailW u = wMass 2 (u + 1) := by + rw [wMass_eq (by norm_num) (by linarith : 0 < u + 1)] + rfl + +theorem tailW_nonneg {u : ℝ} (hu : 1 ≤ u) : 0 ≤ tailW u := by + rw [tailW_eq_mass hu] + exact wMass_nonneg (by norm_num) (by linarith) + +theorem tailW_continuousAt {u : ℝ} (hu : 0 < u) : ContinuousAt tailW u := by + have hc := (wPrimitive_deriv (by linarith : 0 < u + 1)).continuousAt + exact (hc.comp (f := fun x : ℝ ↦ x + 1) (x := u) + (continuousAt_id.add continuousAt_const)).sub continuousAt_const + +theorem regKernel_continuousOn {a b : ℝ} (ha : 0 < a) : + ContinuousOn (fun u ↦ W u * tailW u) (Icc a b) := by + intro u hu + have hu0 : 0 < u := ha.trans_le hu.1 + exact ((W_continuousAt (ne_of_gt hu0)).mul (tailW_continuousAt hu0)).continuousWithinAt + +theorem wKernel_intervalIntegrable {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) : + IntervalIntegrable W volume a b := by + apply ContinuousOn.intervalIntegrable + intro u hu + rw [uIcc_of_le hab] at hu + exact (W_continuousAt (ne_of_gt (ha.trans_le hu.1))).continuousWithinAt + +theorem regIntegral_lower {t : ℝ} (ht : 2 ≤ t) : + (1 : ℝ) / 3 * wMass 2 (t + 1) ≤ regIntegral t := by + have h12 : IntervalIntegrable (fun u ↦ W u * tailW u) volume 1 2 := + (regKernel_continuousOn (b := 2) (by norm_num : (0 : ℝ) < 1)).intervalIntegrable_of_Icc (by norm_num) + have h2T : IntervalIntegrable (fun u ↦ W u * tailW u) volume 2 (t + 1) := + (regKernel_continuousOn (b := t + 1) (by norm_num : (0 : ℝ) < 2)).intervalIntegrable_of_Icc (by linarith) + have hfirst : 0 ≤ ∫ u in (1 : ℝ)..2, W u * tailW u := by + apply intervalIntegral.integral_nonneg (by norm_num) + intro u hu + exact mul_nonneg (W_pos (by linarith [hu.1])).le (tailW_nonneg hu.1) + have hbound : (1 : ℝ) / 3 * wMass 2 (t + 1) ≤ ∫ u in (2 : ℝ)..t + 1, W u * tailW u := by + unfold wMass + rw [← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_mono_on (by linarith) + ((wKernel_intervalIntegrable (by norm_num) (by linarith : (2 : ℝ) ≤ t + 1)).const_mul _) h2T + intro u hu + have htail : (1 : ℝ) / 3 ≤ tailW u := by + rw [tailW_eq_mass (by linarith [hu.1])] + exact wMass_two_three_lower.trans (wMass_mono_right (by norm_num) (by norm_num) (by linarith [hu.1])) + simpa only [mul_comm] using mul_le_mul_of_nonneg_left htail (W_pos (by linarith [hu.1])).le + have hsplit := intervalIntegral.integral_add_adjacent_intervals h12 h2T + unfold regIntegral + linarith + +theorem regIntegral_nonneg {t : ℝ} (ht : 2 ≤ t) : 0 ≤ regIntegral t := + le_trans (mul_nonneg (by norm_num) (wMass_nonneg (by norm_num) (by linarith))) (regIntegral_lower ht) + +theorem initial_integral_le {s t : ℝ} (hs : 199 / 100 ≤ s) (hsup : s ≤ 23 / 10) (ht : 2 ≤ t) : + wMass (s - 1) (t + 1) ≤ 48 * regIntegral t := by + have ha : 0 < s - 1 := by linarith + have hsplit : wMass (s - 1) (t + 1) = wMass (s - 1) 2 + wMass 2 (t + 1) := by + rw [wMass_eq ha (by linarith), wMass_eq ha (by norm_num), wMass_eq (by norm_num) (by linarith)] + ring + have hsmall := wMass_initial_upper (a := s - 1) (by linarith) (by linarith) + have hbig : (1 : ℝ) / 3 ≤ wMass 2 (t + 1) := + wMass_two_three_lower.trans (wMass_mono_right (by norm_num) (by norm_num) (by linarith)) + have hreg := regIntegral_lower ht + rw [hsplit] + linarith + +end Erdos970Dependency.WeightIntegrals + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7b81c60e98754a66c81e0439bd18711ccb54277 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogBound.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.IteratedLogBudget +import OAI.NumberTheory.Jacobsthal.Conclusions.IteratedLogFinite +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalFromRootLower +import OAI.NumberTheory.Jacobsthal.Conclusions.SourceRootCompletion + +namespace OAI + +namespace Erdos970.NumberTheoryLean.IteratedLogBound + +open _root_.Filter IteratedLogScales JacobsthalTerminalScales +open StoppedCountVertex StoppedCountAdapters LogarithmicBinPartition +open RootCutoffSurvivors ProgressionSieve +open scoped Topology + +/-- The strengthened main follows from the same precise survivor estimate as +the old quadratic main. No strengthened conclusion is assumed here. -/ +theorem of_source_root_lower (c : ℝ) (hc : 0 < c) + (z : ℝ → PrimeHistories.Node) + (hLower : ∀ᶠ top : ℝ in atTop, ∀ a : ℕ → ℕ, + c * ((ErdosInverseBoxHeight.sourceY top : ℝ) * + SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW top⌋₊ / + (ErdosInverseBoxHeight.sourceB top) ^ 2) ≤ + countSurvivors (ErdosInverseBoxHeight.sourceY top) + (LargePrimeDeletion.cutoffPrimes ⌊ErdosInverseBoxHeight.sourceW top⌋₊) a + (rootVertex (z top) ∅ (sourcePrimeSet (ErdosInverseBoxHeight.sourceW top) top) + ((ErdosInverseBoxHeight.sourceY top : ℝ) * + SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW top⌋₊))) : + Targets.JacobsthalIteratedLog := by + obtain ⟨A, hA, hbudget⟩ := IteratedLogBudget.separation c hc + have hA0 : 0 < A := by linarith + have hu := rescale_tendsto A hA + have hData : ∀ᶠ k : ℝ in atTop, + ∃ m : ℕ, (∀ k' : ℕ, (k' : ℝ) = k → Targets.IsJacobsthalBound k' m) ∧ + (m : ℝ) ≤ A ^ 2 * k ^ 2 / (loglog k) ^ 2 := by + filter_upwards [hu.eventually eventual_terminal_numerics, + hu.eventually JacobsthalFromRootLower.terminal_w_le_top, + hbudget, (terminal_top_tendsto.comp hu).eventually hLower] with k hn hw hb hl + refine ⟨terminalY (rescale A k), ?_, ?_⟩ + · intro k' hk' + apply isJacobsthalBound_of_cutoff_lower _ _ k' hn.2.2.2.2.2.2.1 + · exact cutoff_lower_of_root_lower _ hw (z (terminalTop (rescale A k))) hl + · simpa only [hk', Function.comp_def, terminalY] using hb + · calc + _ ≤ (rescale A k) ^ 2 := hn.2.2.2.2.2.1 + _ = A ^ 2 * k ^ 2 / (loglog k) ^ 2 := by + simp only [rescale, div_pow, mul_pow] + apply IteratedLogFinite.of_eventually + refine ⟨A ^ 2, sq_pos_of_pos hA0, ?_⟩ + filter_upwards [(tendsto_natCast_atTop_atTop : Tendsto (fun k : ℕ => (k : ℝ)) + atTop atTop).eventually hData] with k hk + obtain ⟨m, hm, hb⟩ := hk + exact ⟨m, hm k rfl, hb⟩ + +end Erdos970.NumberTheoryLean.IteratedLogBound + +namespace Erdos970.Erdos970Final + +/-- Manuscript 293, strengthened Theorem 1.1, revision ad16712e7b45. -/ +theorem erdos_970_iterated_log : NumberTheoryLean.Targets.JacobsthalIteratedLog := by + obtain ⟨c, hc, hLower⟩ := source_root_survivor_lower + exact NumberTheoryLean.IteratedLogBound.of_source_root_lower c hc + (ErdosCorrectionLimit.sourceRootNode (1 / 100)) hLower + +end Erdos970.Erdos970Final + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogBudget.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..b91a181ee892b8e823346ccb6e05b0e14d76162c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogBudget.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.IteratedLogScales + +namespace OAI + +namespace Erdos970.NumberTheoryLean.IteratedLogBudget + +open _root_.Filter IteratedLogScales JacobsthalTerminalScales +open JacobsthalSurvivorScale JacobsthalDeletionBudget ProgressionSieve +open scoped Topology + +/-- The revised cutoff makes the deletion loss smaller than the old, already +proved survivor lower bound. The factor `A` is chosen before the limit. -/ +theorem separation (c : ℝ) (hc : 0 < c) : + ∃ A : ℝ, 3 ≤ A ∧ ∀ᶠ k : ℝ in atTop, + k * deletionBudget (terminalY (rescale A k)) (terminalCutoff (rescale A k)) < + c * ((terminalY (rescale A k) : ℝ) * + SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW + (terminalTop (rescale A k))⌋₊ / + (ErdosInverseBoxHeight.sourceB (terminalTop (rescale A k))) ^ 2) := by + let c0 : ℝ := Real.exp (-Real.eulerMascheroniConstant) / 2 + have hc0 : 0 < c0 := by dsimp [c0]; positivity + let A : ℝ := max 3 ((4 * 1276 * 32) / (c * c0)) + have hA : 3 ≤ A := le_max_left _ _ + have hA0 : 0 < A := by linarith + have hAb : 4 * 1276 * 32 ≤ A * (c * c0) := + (div_le_iff₀ (mul_pos hc hc0)).mp (le_max_right _ _) + have hcoef : 4 * 1275 / A < c * c0 / 32 := by + apply (div_lt_iff₀ hA0).mpr + nlinarith + refine ⟨A, hA, ?_⟩ + have hu := rescale_tendsto A hA + have hWT := JacobsthalBudgetSeparation.terminal_w_tendsto.comp hu + filter_upwards [hu.eventually eventual_terminal_numerics, + hu.eventually eventual_terminal_logs, + hWT.eventually ErdosInverseEuler.smallEuler_log_bounds, + eventual_loglog_bounds, eventual_loglog_le_logW A hA] with k hn hl he hk hll + let u := rescale A k + let w := ErdosInverseBoxHeight.sourceW (terminalTop u) + obtain ⟨hx, hlog, hlogs, _hTop, hYlo, _hYhi, _hTcut, hT, hTL⟩ := hn + have hu0 : 0 < u := by dsimp [u]; linarith + have hlog0 : 0 < Real.log u := by linarith + have hw2 : 2 ≤ w := he.1 + have hw : 1 < w := by linarith + have hlogw : 0 < Real.log w := Real.log_pos hw + have hV : c0 / Real.log w ≤ + SmallSieveFinite.smallEuler ⌊w⌋₊ := by + calc + _ = Real.exp (-Real.eulerMascheroniConstant) / (2 * Real.log w) := by + dsimp [c0] + ring + _ ≤ _ := he.2.2.1 + have hscale := normalized_scale_lower hu0 hlog0 hl.2.2.2.2.1 hl.2.2.2.2.2 + hw hc0 hYlo hV + have hbudget := source_deletion_budget hu0 hlog0 hlogs + (terminalY u) (terminalCutoff u) hT hTL + have hf : 1275 * loglog k / A < c * c0 * Real.log w / 32 := by + calc + _ ≤ 1275 * (4 * Real.log w) / A := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hll (by norm_num)) hA0.le + _ = (4 * 1275 / A) * Real.log w := by ring + _ < (c * c0 / 32) * Real.log w := mul_lt_mul_of_pos_right hcoef hlogw + _ = _ := by ring + have hden : 0 < u ^ 2 / (Real.log u) ^ 2 := + div_pos (sq_pos_of_pos hu0) (sq_pos_of_pos hlog0) + calc + k * deletionBudget (terminalY u) (terminalCutoff u) = + (loglog k / A) * (u * deletionBudget (terminalY u) (terminalCutoff u)) := by + dsimp [u, rescale] + field_simp [hA0.ne', hk.2.1.ne'] + _ ≤ (loglog k / A) * (1275 * u ^ 2 / (Real.log u) ^ 2) := + mul_le_mul_of_nonneg_left hbudget (div_pos hk.2.1 hA0).le + _ = (1275 * loglog k / A) * (u ^ 2 / (Real.log u) ^ 2) := by ring + _ < (c * c0 * Real.log w / 32) * (u ^ 2 / (Real.log u) ^ 2) := + mul_lt_mul_of_pos_right hf hden + _ = c * (c0 * u ^ 2 * Real.log w / (32 * (Real.log u) ^ 2)) := by ring + _ ≤ c * ((terminalY u : ℝ) * SmallSieveFinite.smallEuler ⌊w⌋₊ / + (Real.log (terminalTop u) / Real.log w) ^ 2) := + mul_le_mul_of_nonneg_left hscale hc.le + _ = _ := rfl + +end Erdos970.NumberTheoryLean.IteratedLogBudget + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogFinite.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogFinite.lean new file mode 100644 index 0000000000000000000000000000000000000000..63b84da60585b60a107c5bfdb6b9207a090d157f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogFinite.lean @@ -0,0 +1,45 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.IteratedLogScales +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalFinite + +namespace OAI + +namespace Erdos970.NumberTheoryLean.IteratedLogFinite + +open _root_.Filter IteratedLogScales +open scoped BigOperators Topology + +/-- Absorb the bounded range without changing any interval quantifier. -/ +theorem of_eventually + (hlarge : ∃ C : ℝ, 0 < C ∧ ∀ᶠ k : ℕ in atTop, + ∃ m : ℕ, Targets.IsJacobsthalBound k m ∧ + (m : ℝ) ≤ C * (k : ℝ) ^ 2 / (loglog k) ^ 2) : + Targets.JacobsthalIteratedLog := by + obtain ⟨C, hC, hlarge⟩ := hlarge + obtain ⟨K, hK⟩ := eventually_atTop.mp hlarge + let weight : ℕ → ℝ := fun k => + (((k + 1) * (k + 1).factorial : ℕ) : ℝ) * (loglog k) ^ 2 + let D : ℝ := C + ∑ k ∈ Finset.range K, weight k + have hw (k : ℕ) : 0 ≤ weight k := mul_nonneg (Nat.cast_nonneg _) (sq_nonneg _) + have hCD : C ≤ D := le_add_of_nonneg_right (Finset.sum_nonneg fun k _ => hw k) + have hD : 0 < D := hC.trans_le hCD + refine ⟨D, hD, ?_⟩ + intro k hk + have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk + have hden : 0 < (loglog k) ^ 2 := sq_pos_of_pos (loglog_pos hkR) + by_cases hKk : K ≤ k + · obtain ⟨m, hm, hb⟩ := hK k hKk + refine ⟨m, hm, hb.trans ?_⟩ + exact div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_right hCD (sq_nonneg _)) hden.le + · refine ⟨(k + 1) * (k + 1).factorial, + JacobsthalFinite.factorial_isJacobsthalBound k, ?_⟩ + apply (le_div_iff₀ hden).mpr + have hsum : weight k ≤ ∑ i ∈ Finset.range K, weight i := + Finset.single_le_sum (fun i _ => hw i) (Finset.mem_range.mpr (by omega)) + have hweight : weight k ≤ D := hsum.trans (by dsimp [D]; linarith) + have hk2 : (1 : ℝ) ≤ (k : ℝ) ^ 2 := by nlinarith + exact hweight.trans (by nlinarith) + +end Erdos970.NumberTheoryLean.IteratedLogFinite + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogModel.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..a765db1627f575ab14d9030a5ed75413b334f120 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogModel.lean @@ -0,0 +1,16 @@ +import OAI.NumberTheory.Jacobsthal.Model + +namespace OAI + +namespace Erdos970.NumberTheoryLean.Targets + +/-- The strengthened main theorem of Manuscript 293, revision ad16712e. +The interval, prime-factor and translation quantifiers are unchanged. -/ +def JacobsthalIteratedLog : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ k : ℕ, 0 < k → + ∃ m : ℕ, IsJacobsthalBound k m ∧ + (m : ℝ) ≤ C * (k : ℝ) ^ 2 / (Real.log (Real.log (3 * (k : ℝ)))) ^ 2 + +end Erdos970.NumberTheoryLean.Targets + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogScales.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogScales.lean new file mode 100644 index 0000000000000000000000000000000000000000..95adefcd65ac23d7bde643ba12d884a38bd01199 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/IteratedLogScales.lean @@ -0,0 +1,98 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalBudgetSeparation +import OAI.NumberTheory.Jacobsthal.Conclusions.IteratedLogModel + +namespace OAI + +namespace Erdos970.NumberTheoryLean.IteratedLogScales + +open _root_.Filter JacobsthalTerminalScales +open scoped Topology + +noncomputable def loglog (x : ℝ) : ℝ := Real.log (Real.log (3 * x)) + +noncomputable def rescale (A x : ℝ) : ℝ := A * x / loglog x + +theorem loglog_pos {x : ℝ} (hx : 1 ≤ x) : 0 < loglog x := by + apply Real.log_pos + have h3 : 1 < Real.log 3 := by + have := Real.log_three_gt_d9 + linarith + exact h3.trans_le (Real.log_le_log (by norm_num) (by linarith)) + +theorem loglog_tendsto : Tendsto loglog atTop atTop := by + exact Real.tendsto_log_atTop.comp (Real.tendsto_log_atTop.comp + (tendsto_id.const_mul_atTop (by norm_num : (0 : ℝ) < 3))) + +theorem eventual_loglog_bounds : ∀ᶠ x : ℝ in atTop, + 4 ≤ x ∧ 0 < loglog x ∧ loglog x ≤ Real.sqrt x := by + filter_upwards [eventual_terminal_logs] with x hx + have hx0 : 0 < x := by linarith [hx.1] + have hl0 : 0 < Real.log x := by linarith [hx.2.1] + have h3x : Real.log (3 * x) ≤ 2 * Real.log x := by + rw [Real.log_mul (by norm_num : (3 : ℝ) ≠ 0) hx0.ne'] + have := Real.log_le_log (by norm_num : (0 : ℝ) < 3) (by linarith [hx.1] : 3 ≤ x) + linarith + have hll : loglog x ≤ Real.log (3 * x) := + (Real.log_le_sub_one_of_pos (Real.log_pos (by nlinarith [hx.1] : 1 < 3 * x))).trans + (by linarith) + exact ⟨hx.1, loglog_pos (by linarith [hx.1]), + hll.trans (h3x.trans (by linarith [hx.2.2.2.1]))⟩ + +theorem eventual_rescale_lower (A : ℝ) (hA : 3 ≤ A) : + ∀ᶠ x : ℝ in atTop, Real.sqrt (3 * x) ≤ rescale A x := by + filter_upwards [eventual_loglog_bounds] with x hx + have hx0 : 0 < x := by linarith [hx.1] + have hs : 0 < Real.sqrt x := Real.sqrt_pos.mpr hx0 + have hxs : x / Real.sqrt x = Real.sqrt x := by + apply (div_eq_iff hs.ne').mpr + nlinarith [Real.sq_sqrt hx0.le] + have hlower : 3 * Real.sqrt x ≤ rescale A x := by + calc + _ = 3 * x / Real.sqrt x := by rw [mul_div_assoc, hxs] + _ ≤ A * x / Real.sqrt x := div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_right hA hx0.le) hs.le + _ ≤ A * x / loglog x := div_le_div_of_nonneg_left (by positivity) hx.2.1 hx.2.2 + have hsq : Real.sqrt (3 * x) ≤ 3 * Real.sqrt x := by + nlinarith [Real.sq_sqrt (by positivity : 0 ≤ 3 * x), Real.sqrt_nonneg (3 * x), + Real.sq_sqrt hx0.le, Real.sqrt_nonneg x] + exact hsq.trans hlower + +theorem rescale_tendsto (A : ℝ) (hA : 3 ≤ A) : Tendsto (rescale A) atTop atTop := by + apply tendsto_atTop_mono' atTop (eventual_rescale_lower A hA) + exact Real.tendsto_sqrt_atTop.comp + (tendsto_id.const_mul_atTop (by norm_num : (0 : ℝ) < 3)) + +theorem eventual_loglog_le_logW (A : ℝ) (hA : 3 ≤ A) : + ∀ᶠ x : ℝ in atTop, + loglog x ≤ 4 * Real.log (ErdosInverseBoxHeight.sourceW (terminalTop (rescale A x))) := by + have hu := rescale_tendsto A hA + filter_upwards [eventual_rescale_lower A hA, eventual_loglog_bounds, + loglog_tendsto.eventually_ge_atTop (2 * Real.log 2), + hu.eventually eventual_terminal_logs, + (Real.tendsto_log_atTop.comp (terminal_top_tendsto.comp hu)).eventually + JacobsthalSourceScale.sourceW_bounds_eventually] with x hroot hx hll huLog hw + have hx0 : 0 < x := by linarith [hx.1] + have h3x : 0 < 3 * x := by positivity + have hlog3x : 0 < Real.log (3 * x) := Real.log_pos (by nlinarith [hx.1]) + have hroot0 : 0 < Real.sqrt (3 * x) := Real.sqrt_pos.mpr h3x + have hu0 : 0 < rescale A x := hroot0.trans_le hroot + have hlogu : 0 < Real.log (rescale A x) := by linarith [huLog.2.1] + have h1 := Real.log_le_log hroot0 hroot + rw [Real.log_sqrt h3x.le] at h1 + have h2 := Real.log_le_log (half_pos hlog3x) h1 + rw [show Real.log (3 * x) / 2 = Real.log (3 * x) * (1 / 2) by ring, + Real.log_mul hlog3x.ne' (by norm_num : (1 / 2 : ℝ) ≠ 0), + Real.log_div (by norm_num : (1 : ℝ) ≠ 0) (by norm_num : (2 : ℝ) ≠ 0), + Real.log_one] at h2 + have h3 := Real.log_le_log hlogu huLog.2.2.2.2.1 + have hL0 : 0 < Real.log (terminalTop (rescale A x)) := hlogu.trans_le huLog.2.2.2.2.1 + have h4 := Real.log_le_log (Real.sqrt_pos.mpr hL0) hw.2.1 + rw [Real.log_sqrt hL0.le] at h4 + change Real.log (Real.log (terminalTop (rescale A x))) / 2 ≤ + Real.log (ErdosInverseBoxHeight.sourceW (terminalTop (rescale A x))) at h4 + dsimp only [loglog] at hll ⊢ + linarith + +end Erdos970.NumberTheoryLean.IteratedLogScales + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalBudgetSeparation.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalBudgetSeparation.lean new file mode 100644 index 0000000000000000000000000000000000000000..54abbdce94c5120c618d9af936c47aa60896f0f9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalBudgetSeparation.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalSurvivorScale +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalTerminalScales +import OAI.NumberTheory.Jacobsthal.Sieve.ClosedEulerIndividualUpper + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.JacobsthalBudgetSeparation +open _root_.Filter JacobsthalTerminalScales JacobsthalSurvivorScale JacobsthalDeletionBudget ProgressionSieve +open scoped Topology + +theorem terminal_w_tendsto : Tendsto (fun x : ℝ => ErdosInverseBoxHeight.sourceW (terminalTop x)) atTop atTop := + (JacobsthalSourceScale.sourceW_tendsto.comp Real.tendsto_log_atTop).comp terminal_top_tendsto + +theorem terminal_budget_separation (c : ℝ) (hc : 0 < c) : + ∀ᶠ x : ℝ in atTop, + x*deletionBudget (terminalY x) (terminalCutoff x) < + c*((terminalY x:ℝ)*SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW (terminalTop x)⌋₊/ + (ErdosInverseBoxHeight.sourceB (terminalTop x))^2) := by + let c0 : ℝ := Real.exp (-Real.eulerMascheroniConstant)/2 + have hc0 : 0 < c0 := by dsimp [c0]; positivity + have hWT := terminal_w_tendsto + have hLog := Real.tendsto_log_atTop.comp hWT + filter_upwards [eventual_terminal_numerics,eventual_terminal_logs, + hWT.eventually ErdosInverseEuler.smallEuler_log_bounds, + hLog.eventually_gt_atTop ((1276*32)/(c*c0))] with x hn hl he hloglarge + obtain ⟨hx,hlog,hlogs,hTop,hYlo,_hYhi,_hTcut,hT,hTL⟩ := hn + have hx0 : 0 < x := by linarith + have hl0 : 0 < Real.log x := by linarith + have hw : 1 < ErdosInverseBoxHeight.sourceW (terminalTop x) := by linarith [he.1] + have hV : c0/Real.log (ErdosInverseBoxHeight.sourceW (terminalTop x)) ≤ + SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW (terminalTop x)⌋₊ := by + convert he.2.2.1 using 1 + dsimp [c0] + ring + have hscale := normalized_scale_lower hx0 hl0 hl.2.2.2.2.1 hl.2.2.2.2.2 hw hc0 hYlo hV + have hsep : 1275 < c*c0*Real.log (ErdosInverseBoxHeight.sourceW (terminalTop x))/32 := by + have hh := (div_lt_iff₀ (mul_pos hc hc0)).mp hloglarge + dsimp only [Function.comp_def] at hh + nlinarith + have hden : 0 < x^2/(Real.log x)^2 := div_pos (sq_pos_of_pos hx0) (sq_pos_of_pos hl0) + have hbudget := source_deletion_budget hx0 hl0 hlogs (terminalY x) (terminalCutoff x) hT hTL + calc + _ ≤ 1275*x^2/(Real.log x)^2 := hbudget + _ = 1275*(x^2/(Real.log x)^2) := by ring + _ < (c*c0*Real.log (ErdosInverseBoxHeight.sourceW (terminalTop x))/32)*(x^2/(Real.log x)^2) := + mul_lt_mul_of_pos_right hsep hden + _ = c*(c0*x^2*Real.log (ErdosInverseBoxHeight.sourceW (terminalTop x))/(32*(Real.log x)^2)) := by ring + _ ≤ c*((terminalY x:ℝ)*SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW (terminalTop x)⌋₊/ + (Real.log (terminalTop x)/Real.log (ErdosInverseBoxHeight.sourceW (terminalTop x)))^2) := + mul_le_mul_of_nonneg_left hscale hc.le + _ = _ := rfl +end NumberTheoryLean.JacobsthalBudgetSeparation + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalDeletionBudget.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalDeletionBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..fe8b54b3e02ee83e3186593cd391f2adf26fce06 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalDeletionBudget.lean @@ -0,0 +1,39 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalProgressionLength + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.JacobsthalDeletionBudget +open ProgressionSieve + +theorem source_deletion_budget {x l : ℝ} (hx : 0 < x) (hl : 0 < l) + (hlx : l^2 ≤ x) (Y Z : ℕ) + (hT : (progressionLength Y Z:ℝ) ≤ 2*x/l) + (hlog : l/2 ≤ Real.log (progressionLength Y Z:ℝ)) : + x*deletionBudget Y Z ≤ 1275*x^2/l^2 := by + have hlog0 : 0 < Real.log (progressionLength Y Z:ℝ) := by linarith + have hquot : (progressionLength Y Z:ℝ)/Real.log (progressionLength Y Z:ℝ) ≤ 4*x/l^2 := by + calc + _ ≤ (2*x/l)/Real.log (progressionLength Y Z:ℝ) := div_le_div_of_nonneg_right hT hlog0.le + _ ≤ (2*x/l)/(l/2) := div_le_div_of_nonneg_left (by positivity) (by positivity) hlog + _ = _ := by field_simp; ring + have hunit : x ≤ x^2/l^2 := by + apply (le_div_iff₀ (sq_pos_of_pos hl)).mpr + nlinarith + unfold deletionBudget + calc + _ ≤ x*(255*(1+4*x/l^2)) := by + apply mul_le_mul_of_nonneg_left _ hx.le + apply mul_le_mul_of_nonneg_left _ (by norm_num : (0:ℝ)≤255) + linarith + _ = 255*x+1020*(x^2/l^2) := by ring + _ ≤ 1275*(x^2/l^2) := by linarith + _ = _ := by ring +end NumberTheoryLean.JacobsthalDeletionBudget + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalFinite.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalFinite.lean new file mode 100644 index 0000000000000000000000000000000000000000..10b6dc9c4933d8fcf8a70984c6e6d9b6de5e2b92 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalFinite.lean @@ -0,0 +1,167 @@ +import Mathlib.Data.Finset.Card +import Mathlib.Data.Int.Basic +import Mathlib.Data.Nat.Factorial.Basic +import Mathlib.Data.Nat.Prime.Int +import Mathlib.Tactic.Choose +import Mathlib.Tactic.Linarith +import Mathlib.Tactic.Ring +import Mathlib.Tactic.WLOG +import OAI.NumberTheory.Jacobsthal.Conclusions.Targets + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.JacobsthalFinite + +theorem exists_offset_one (M : ℕ) (hM : 0 < M) (a : ℤ) : + ∃ r : ℕ, r < M ∧ (M : ℤ) ∣ a + r - 1 := by + let z : ℤ := (1 - a) % M + have hMz : (0 : ℤ) < M := by exact_mod_cast hM + have hz0 : 0 ≤ z := Int.emod_nonneg _ (ne_of_gt hMz) + have hzM : z < M := Int.emod_lt_of_pos _ hMz + refine ⟨z.toNat, ?_, ?_⟩ + · exact_mod_cast (show (z.toNat : ℤ) < M by simpa only [Int.toNat_of_nonneg hz0] using hzM) + · refine ⟨-((1 - a) / M), ?_⟩ + rw [Int.toNat_of_nonneg hz0] + dsimp [z] + rw [Int.emod_def] + ring + +theorem prime_not_dvd_of_dvd_step {p M : ℕ} (hp : p.Prime) + (hpM : p ∣ M) {b : ℤ} (hb : (M : ℤ) ∣ b - 1) : + ¬ (p : ℤ) ∣ b := by + intro hpb + have hd : (p : ℤ) ∣ b - 1 := + (Int.natCast_dvd_natCast.mpr hpM).trans hb + have hone : (p : ℤ) ∣ 1 := by + have := dvd_sub hpb hd + simpa using this + exact hp.ne_one (Nat.dvd_one.mp (Int.natCast_dvd_natCast.mp hone)) + +theorem progression_prime_hit_unique {k p M : ℕ} (hp : p.Prime) + (hkp : k < p) (hpM : ¬ p ∣ M) (b : ℤ) + {j l : ℕ} (hj : j ≤ k) (hl : l ≤ k) + (hpj : (p : ℤ) ∣ b + M * j) (hpl : (p : ℤ) ∣ b + M * l) : + j = l := by + wlog hjl : j ≤ l generalizing j l + · exact (this hl hj hpl hpj (by omega)).symm + have hd : (p : ℤ) ∣ (M * (l - j) : ℕ) := by + have hd' : (p : ℤ) ∣ (b + M * l) - (b + M * j) := dvd_sub hpl hpj + have heq : ((M * (l - j) : ℕ) : ℤ) = (b + M * l) - (b + M * j) := by + push_cast [Nat.cast_sub hjl]; ring + rw [heq] + exact hd' + have hdiff : p ∣ l - j := + (hp.dvd_mul.mp (Int.natCast_dvd_natCast.mp hd)).resolve_left hpM + have hlt : l - j < p := lt_of_le_of_lt (Nat.sub_le l j) (lt_of_le_of_lt hl hkp) + have hz := Nat.eq_zero_of_dvd_of_lt hdiff hlt + omega + +theorem exists_coprime_progression (k n : ℕ) (hn : 0 < n) + (hcard : n.primeFactors.card ≤ k) (b : ℤ) + (hb : ((k + 1).factorial : ℤ) ∣ b - 1) : + ∃ j : ℕ, j ≤ k ∧ (b + (k + 1).factorial * j).natAbs.Coprime n := by + classical + by_contra hnone + have hbad : ∀ j : ℕ, j ∈ Finset.range (k + 1) → + ∃ p : ℕ, p ∈ n.primeFactors ∧ + (p : ℤ) ∣ b + (k + 1).factorial * j := by + intro j hj + have hnc : ¬ (b + (k + 1).factorial * j).natAbs.Coprime n := by + intro hc + exact hnone ⟨j, Nat.le_of_lt_succ (Finset.mem_range.mp hj), hc⟩ + obtain ⟨p, hp, hpd, hpn⟩ := Nat.Prime.not_coprime_iff_dvd.mp hnc + exact ⟨p, Nat.mem_primeFactors.mpr ⟨hp, hpn, ne_of_gt hn⟩, + Int.natCast_dvd.mpr hpd⟩ + choose f hfmem hfdvd using hbad + let F : ℕ → ℕ := fun j => if hj : j ∈ Finset.range (k + 1) then f j hj else 0 + have hFmem : ∀ j ∈ Finset.range (k + 1), F j ∈ n.primeFactors := by + intro j hj + simpa only [F, dite_eq_left hj] using hfmem j hj + have hFdvd : ∀ j ∈ Finset.range (k + 1), + (F j : ℤ) ∣ b + (k + 1).factorial * j := by + intro j hj + simpa only [F, dite_eq_left hj] using hfdvd j hj + have hinj : Set.InjOn F (Finset.range (k + 1) : Set ℕ) := by + intro j hj l hl heq + have hp := (Nat.mem_primeFactors.mp (hFmem j hj)).1 + have hpj := hFdvd j hj + have hpl := hFdvd l hl + rw [← heq] at hpl + have hpM : ¬ F j ∣ (k + 1).factorial := by + intro hpM + have hbase : (F j : ℤ) ∣ b := by + have hmul : (F j : ℤ) ∣ (k + 1).factorial * j := + dvd_mul_of_dvd_left (Int.natCast_dvd_natCast.mpr hpM) _ + simpa using dvd_sub hpj hmul + exact prime_not_dvd_of_dvd_step hp hpM hb hbase + have hlarge : k < F j := by + have := not_le.mp (fun hle => hpM (Nat.dvd_factorial hp.pos hle)) + omega + exact progression_prime_hit_unique hp hlarge hpM b + (Nat.le_of_lt_succ (Finset.mem_range.mp hj)) + (Nat.le_of_lt_succ (Finset.mem_range.mp hl)) hpj hpl + have hcount := Finset.card_le_card_of_injOn F hFmem hinj + simp only [Finset.card_range] at hcount + omega + +theorem factorial_isJacobsthalBound (k : ℕ) : + Targets.IsJacobsthalBound k ((k + 1) * (k + 1).factorial) := by + intro n hn hcard a + obtain ⟨r, hr, hres⟩ := exists_offset_one (k + 1).factorial (Nat.factorial_pos _) a + obtain ⟨j, hj, hcop⟩ := exists_coprime_progression k n hn hcard (a + r) hres + refine ⟨r + (k + 1).factorial * j, ?_, ?_⟩ + · have hmul := Nat.mul_le_mul_left (k + 1).factorial hj + nlinarith + · simpa only [Nat.cast_add, Nat.cast_mul, add_assoc] using hcop + +theorem exists_isJacobsthalBound (k : ℕ) : + ∃ m : ℕ, Targets.IsJacobsthalBound k m := + ⟨(k + 1) * (k + 1).factorial, factorial_isJacobsthalBound k⟩ + +theorem quadratic_of_eventually_quadratic + (hlarge : ∃ C : ℝ, 0 < C ∧ ∃ K : ℕ, ∀ k : ℕ, K ≤ k → 0 < k → + ∃ m : ℕ, Targets.IsJacobsthalBound k m ∧ (m : ℝ) ≤ C * (k : ℝ) ^ 2) : + Targets.JacobsthalQuadratic := by + obtain ⟨C, hC, K, hK⟩ := hlarge + let D : ℝ := max C (((K + 1) * (K + 1).factorial : ℕ) : ℝ) + have hCD : C ≤ D := le_max_left _ _ + have hD : 0 < D := lt_of_lt_of_le hC hCD + refine ⟨D, hD, ?_⟩ + intro k hk + by_cases hKk : K ≤ k + · obtain ⟨m, hm, hbound⟩ := hK k hKk hk + exact ⟨m, hm, hbound.trans (mul_le_mul_of_nonneg_right hCD (sq_nonneg _))⟩ + · refine ⟨(k + 1) * (k + 1).factorial, factorial_isJacobsthalBound k, ?_⟩ + have hsmall : k + 1 ≤ K + 1 := by omega + have hfac : (k + 1) * (k + 1).factorial ≤ (K + 1) * (K + 1).factorial := + Nat.mul_le_mul hsmall (Nat.factorial_le hsmall) + have hfacR : (((k + 1) * (k + 1).factorial : ℕ) : ℝ) ≤ + (((K + 1) * (K + 1).factorial : ℕ) : ℝ) := by exact_mod_cast hfac + have hkR : (1 : ℝ) ≤ k := by exact_mod_cast hk + have hk2 : (1 : ℝ) ≤ (k : ℝ) ^ 2 := by nlinarith + calc + (((k + 1) * (k + 1).factorial : ℕ) : ℝ) ≤ + (((K + 1) * (K + 1).factorial : ℕ) : ℝ) := hfacR + _ ≤ D := le_max_right _ _ + _ ≤ D * (k : ℝ) ^ 2 := by nlinarith + +theorem quadratic_iff_eventually_quadratic : + Targets.JacobsthalQuadratic ↔ + ∃ C : ℝ, 0 < C ∧ ∃ K : ℕ, ∀ k : ℕ, K ≤ k → 0 < k → + ∃ m : ℕ, Targets.IsJacobsthalBound k m ∧ (m : ℝ) ≤ C * (k : ℝ) ^ 2 := by + constructor + · rintro ⟨C, hC, hbound⟩ + exact ⟨C, hC, 0, fun k _ hk => hbound k hk⟩ + · exact quadratic_of_eventually_quadratic + +end NumberTheoryLean.JacobsthalFinite + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalFromRootLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalFromRootLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6b0b489468fb62b510ad322205dc5f3e5e2d2f7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalFromRootLower.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalBudgetSeparation +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalFinite +import OAI.NumberTheory.Jacobsthal.Estimates.RootCutoffSurvivors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.JacobsthalFromRootLower +open _root_.Filter JacobsthalTerminalScales JacobsthalBudgetSeparation +open StoppedCountVertex StoppedCountAdapters LogarithmicBinPartition +open RootCutoffSurvivors ProgressionSieve +open scoped Topology + +theorem terminal_w_le_top : ∀ᶠ x : ℝ in atTop, + ErdosInverseBoxHeight.sourceW (terminalTop x) ≤ terminalTop x := by + filter_upwards [(Real.tendsto_log_atTop.comp terminal_top_tendsto).eventually + JacobsthalSourceScale.sourceW_bounds_eventually,terminal_top_tendsto.eventually_gt_atTop 1] + with x hw ht + have hW : ErdosInverseBoxHeight.sourceW (terminalTop x) ≤ Real.log (terminalTop x) := hw.2.2 + have hlog := Real.log_le_sub_one_of_pos (zero_lt_one.trans ht) + linarith + +theorem jacobsthal_of_source_root_lower (c : ℝ) (hc : 0 < c) + (z : ℝ → PrimeHistories.Node) + (hLower : ∀ᶠ top : ℝ in atTop,∀ a : ℕ → ℕ, + c*((ErdosInverseBoxHeight.sourceY top:ℝ)* + SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW top⌋₊/(ErdosInverseBoxHeight.sourceB top)^2) ≤ + countSurvivors (ErdosInverseBoxHeight.sourceY top) + (LargePrimeDeletion.cutoffPrimes ⌊ErdosInverseBoxHeight.sourceW top⌋₊) a + (rootVertex (z top) ∅ (sourcePrimeSet (ErdosInverseBoxHeight.sourceW top) top) + ((ErdosInverseBoxHeight.sourceY top:ℝ)*SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW top⌋₊))) : + Targets.JacobsthalQuadratic := by + have hData : ∀ᶠ x : ℝ in atTop, + (terminalY x:ℝ) ≤ x^2 ∧ + progressionLength (terminalY x) (terminalCutoff x) ≤ terminalCutoff x ∧ + ErdosInverseBoxHeight.sourceW (terminalTop x) ≤ terminalTop x ∧ + x*deletionBudget (terminalY x) (terminalCutoff x) < + c*((terminalY x:ℝ)*SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW (terminalTop x)⌋₊/ + (ErdosInverseBoxHeight.sourceB (terminalTop x))^2) ∧ + ∀ a : ℕ → ℕ,c*((terminalY x:ℝ)*SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW (terminalTop x)⌋₊/ + (ErdosInverseBoxHeight.sourceB (terminalTop x))^2) ≤ + ((LargePrimeDeletion.cutoffSurvivors (terminalY x) (terminalCutoff x) a).card:ℝ) := by + filter_upwards [eventual_terminal_numerics,terminal_w_le_top,terminal_budget_separation c hc, + terminal_top_tendsto.eventually hLower] with x hn hw hb hl + refine ⟨hn.2.2.2.2.2.1,hn.2.2.2.2.2.2.1,hw,hb,?_⟩ + exact cutoff_lower_of_root_lower (terminalY x) hw (z (terminalTop x)) hl + have hNat : ∀ᶠ k : ℕ in atTop, + ∃ m : ℕ,Targets.IsJacobsthalBound k m ∧ (m:ℝ) ≤ (1:ℝ)*(k:ℝ)^2 := by + filter_upwards [(tendsto_natCast_atTop_atTop : Tendsto (fun k : ℕ => (k:ℝ)) atTop atTop).eventually hData] with k hk + refine ⟨terminalY (k:ℝ),?_,by simpa only [one_mul] using hk.1⟩ + exact isJacobsthalBound_of_cutoff_lower _ _ k hk.2.1 hk.2.2.2.2 hk.2.2.2.1 + obtain ⟨K,hK⟩ := eventually_atTop.mp hNat + exact JacobsthalFinite.quadratic_of_eventually_quadratic ⟨1,by norm_num,K,fun k hk _hpos => hK k hk⟩ +end NumberTheoryLean.JacobsthalFromRootLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalProgressionLength.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalProgressionLength.lean new file mode 100644 index 0000000000000000000000000000000000000000..297df93ec067eb5eead196556206ed556427f78b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalProgressionLength.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalSourceRounding + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.JacobsthalProgressionLength +open ProgressionSieve + +theorem progression_real_bounds (Y Z : ℕ) : + (Y:ℝ)/((Z:ℝ)+1) ≤ (progressionLength Y Z:ℝ) ∧ + (progressionLength Y Z:ℝ) ≤ (Y:ℝ)/((Z:ℝ)+1)+1 := by + constructor + · have hdiv := Nat.mod_add_div Y (Z+1) + have hmod := Nat.mod_lt Y (Nat.succ_pos Z) + have hn : Y ≤ (Y/(Z+1)+1)*(Z+1) := by nlinarith + apply (div_le_iff₀ (by positivity : (0:ℝ)<(Z:ℝ)+1)).mpr + exact_mod_cast hn + · have hh : ((Y/(Z+1):ℕ):ℝ) ≤ (Y:ℝ)/((Z+1:ℕ):ℝ) := Nat.cast_div_le + push_cast at hh + simp only [progressionLength,Nat.cast_add,Nat.cast_one] + linarith + +theorem source_progression_bounds {x l : ℝ} (hx : 4 ≤ x) (hl : 2 ≤ l) + (hlx : l^2 ≤ x) (Y Z : ℕ) + (hYlo : x^2/8 ≤ (Y:ℝ)) (hYhi : (Y:ℝ) ≤ x^2) + (hZlo : x*l/2 ≤ (Z:ℝ)) (hZhi : (Z:ℝ)+1 ≤ 2*x*l) + (hZstrict : x*l < (Z:ℝ)+1) : + x/(16*l) ≤ (progressionLength Y Z:ℝ) ∧ + (progressionLength Y Z:ℝ) ≤ 2*x/l ∧ progressionLength Y Z ≤ Z := by + have hx0 : 0 < x := by linarith + have hl0 : 0 < l := by linarith + have hZ0 : (0:ℝ)<(Z:ℝ)+1 := by positivity + have hT := progression_real_bounds Y Z + have hlo : x/(16*l) ≤ (progressionLength Y Z:ℝ) := by + calc + _ = (x^2/8)/(2*x*l) := by field_simp; ring + _ ≤ (x^2/8)/((Z:ℝ)+1) := + div_le_div_of_nonneg_left (by positivity) hZ0 hZhi + _ ≤ (Y:ℝ)/((Z:ℝ)+1) := div_le_div_of_nonneg_right hYlo hZ0.le + _ ≤ _ := hT.1 + have hhi : (progressionLength Y Z:ℝ) ≤ 2*x/l := by + have hlx' : l ≤ x := by nlinarith + have hone : 1 ≤ x/l := (one_le_div hl0).mpr hlx' + calc + _ ≤ (Y:ℝ)/((Z:ℝ)+1)+1 := hT.2 + _ ≤ x^2/((Z:ℝ)+1)+1 := by + have hh := div_le_div_of_nonneg_right hYhi hZ0.le + linarith + _ ≤ x^2/(x*l)+1 := by + have hh := div_le_div_of_nonneg_left (sq_nonneg x) (mul_pos hx0 hl0) hZstrict.le + linarith + _ = x/l+1 := by field_simp + _ ≤ 2*(x/l) := by linarith + _ = _ := by ring + refine ⟨hlo,hhi,?_⟩ + have hbound : 2*x/l ≤ x*l/2 := by + apply (div_le_iff₀ hl0).mpr + nlinarith + exact_mod_cast hhi.trans (hbound.trans hZlo) + +theorem progression_log_lower {x l : ℝ} (hx : 0 < x) (hl : 0 < l) + (hlarge : 16*l ≤ Real.sqrt x) (Y Z : ℕ) + (hT : x/(16*l) ≤ (progressionLength Y Z:ℝ)) : + Real.log x/2 ≤ Real.log (progressionLength Y Z:ℝ) := by + have hs : Real.sqrt x ≤ x/(16*l) := by + apply (le_div_iff₀ (by positivity : 0 < 16*l)).mpr + have hh := mul_le_mul_of_nonneg_left hlarge (Real.sqrt_nonneg x) + nlinarith [Real.sq_sqrt hx.le] + have hh := Real.log_le_log (Real.sqrt_pos.mpr hx) (hs.trans hT) + simpa only [Real.log_sqrt hx.le] using hh +end NumberTheoryLean.JacobsthalProgressionLength + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSourceRounding.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSourceRounding.lean new file mode 100644 index 0000000000000000000000000000000000000000..b288b6a75cbd293690aa774f398ca21ea0842562 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSourceRounding.lean @@ -0,0 +1,42 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueCountDifference + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.JacobsthalSourceRounding + +theorem floor_length_bounds {x l L : ℝ} (hx : 4 ≤ x) (hl : 0 < l) + (hlL : l ≤ L) (hLl : L ≤ 2*l) : + x^2/8 ≤ (⌊(x*l)^2/L^2⌋₊:ℝ) ∧ (⌊(x*l)^2/L^2⌋₊:ℝ) ≤ x^2 := by + have hL : 0 < L := hl.trans_le hlL + have hl2 : 0 < l^2 := sq_pos_of_pos hl + have hL2 : 0 < L^2 := sq_pos_of_pos hL + have hlow : x^2/4 ≤ (x*l)^2/L^2 := by + calc + _ = (x*l)^2/(2*l)^2 := by field_simp [hl.ne']; ring + _ ≤ _ := div_le_div_of_nonneg_left (sq_nonneg _) hL2 (by nlinarith) + have hu : (x*l)^2/L^2 ≤ x^2 := by + calc + _ ≤ (x*l)^2/l^2 := div_le_div_of_nonneg_left (sq_nonneg _) hl2 (by nlinarith) + _ = _ := by field_simp [hl.ne'] + have hfloor := Nat.floor_le (div_nonneg (sq_nonneg (x*l)) (sq_nonneg L)) + have hround := Nat.lt_floor_add_one ((x*l)^2/L^2) + constructor + · have hs : 16 ≤ x^2 := by nlinarith + linarith + · exact hfloor.trans hu + +theorem floor_cutoff_bounds {top : ℝ} (htop : 2 ≤ top) : + top/2 ≤ (⌊top⌋₊:ℝ) ∧ (⌊top⌋₊:ℝ) ≤ top ∧ + top < (⌊top⌋₊:ℝ)+1 ∧ (⌊top⌋₊:ℝ)+1 ≤ 2*top := by + have hu := Nat.floor_le (by linarith : 0 ≤ top) + have hl := Nat.lt_floor_add_one top + exact ⟨by linarith,hu,hl,by linarith⟩ +end NumberTheoryLean.JacobsthalSourceRounding + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSourceScale.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSourceScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b0759f0a52541650dc862bd9496942afbc3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSourceScale.lean @@ -0,0 +1,90 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.MovingLocalReference + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.JacobsthalSourceScale + +open _root_.Filter Asymptotics +open scoped Topology + +noncomputable def sourceW (L : ℝ) : ℝ := L/(Real.log L)^2 +noncomputable def sourceB (L : ℝ) : ℝ := L/Real.log (sourceW L) + +theorem log_square_le_sqrt_eventually : ∀ᶠ L : ℝ in atTop,(Real.log L)^2 ≤ Real.sqrt L := by + have h := (isLittleO_log_rpow_rpow_atTop (2:ℝ) (s:=1/2) (by norm_num)).bound (by norm_num : (0:ℝ)<1) + filter_upwards [h,eventually_gt_atTop (1:ℝ)] with L hL hpos + have hr : 0 ≤ L^((1/2:ℝ)) := Real.rpow_nonneg (by linarith) _ + simpa only [Real.rpow_ofNat,Real.norm_eq_abs,abs_of_nonneg (sq_nonneg (Real.log L)), + abs_of_nonneg hr,one_mul,← Real.sqrt_eq_rpow,abs_of_nonneg (Real.sqrt_nonneg L)] using hL + +theorem sourceW_bounds_eventually : ∀ᶠ L : ℝ in atTop, + 1 < sourceW L ∧ Real.sqrt L ≤ sourceW L ∧ sourceW L ≤ L := by + filter_upwards [log_square_le_sqrt_eventually,eventually_gt_atTop (1:ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with L hsmall hL hlog + have hL0 : 0 < L := by linarith + have hden : 0 < (Real.log L)^2 := sq_pos_of_pos (by linarith) + have hsq : Real.sqrt L ≤ sourceW L := by + apply (le_div_iff₀ hden).mpr + have hm := mul_le_mul_of_nonneg_left hsmall (Real.sqrt_nonneg L) + simpa only [Real.mul_self_sqrt hL0.le] using hm + have hlow : 1 < Real.sqrt L := by + simpa only [Real.sqrt_one] using Real.sqrt_lt_sqrt (by norm_num : (0:ℝ) ≤ 1) hL + refine ⟨hlow.trans_le hsq,hsq,?_⟩ + exact div_le_self hL0.le (by nlinarith : 1 ≤ (Real.log L)^2) + +theorem sourceW_tendsto : Tendsto sourceW atTop atTop := by + apply tendsto_atTop.mpr + intro R + filter_upwards [sourceW_bounds_eventually,Real.tendsto_sqrt_atTop.eventually (eventually_ge_atTop R)] with L hW hR + exact hR.trans hW.2.1 + +theorem source_scale_eventually : ∀ᶠ L : ℝ in atTop, + 1 < sourceW L ∧ 0 < sourceB L ∧ Real.sqrt L ≤ sourceB L ∧ sourceB L ≤ L ∧ + Real.log (sourceB L) ≤ 2*Real.log (sourceW L) := by + filter_upwards [sourceW_bounds_eventually,log_square_le_sqrt_eventually,eventually_gt_atTop (1:ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ)), + sourceW_tendsto.eventually (eventually_ge_atTop (Real.exp 1))] with L hW hsmall hL hlog hWexp + have hL0 : 0 < L := by linarith + have hW0 : 0 < sourceW L := by linarith [hW.1] + have hlogW : 1 ≤ Real.log (sourceW L) := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 1) hWexp + have hlogWL : Real.log (sourceW L) ≤ Real.log L := Real.log_le_log hW0 hW.2.2 + have hlogSmall : Real.log (sourceW L) ≤ Real.sqrt L := by + have hh : Real.log L ≤ (Real.log L)^2 := by nlinarith + exact hlogWL.trans (hh.trans hsmall) + have hBpos : 0 < sourceB L := div_pos hL0 (by linarith) + have hBsq : Real.sqrt L ≤ sourceB L := by + apply (le_div_iff₀ (show 0 < Real.log (sourceW L) by linarith)).mpr + have hm := mul_le_mul_of_nonneg_left hlogSmall (Real.sqrt_nonneg L) + simpa only [Real.mul_self_sqrt hL0.le] using hm + have hBL : sourceB L ≤ L := div_le_self hL0.le hlogW + have hLWsq : L ≤ (sourceW L)^2 := by + have hh := mul_self_le_mul_self (Real.sqrt_nonneg L) hW.2.1 + nlinarith [Real.sq_sqrt hL0.le] + have hcomp := Real.log_le_log hBpos (hBL.trans hLWsq) + refine ⟨hW.1,hBpos,hBsq,hBL,?_⟩ + simpa only [Real.log_pow,Nat.cast_ofNat] using hcomp + +theorem sourceB_tendsto : Tendsto sourceB atTop atTop := by + apply tendsto_atTop.mpr + intro R + filter_upwards [source_scale_eventually,Real.tendsto_sqrt_atTop.eventually (eventually_ge_atTop R)] with L h hR + exact hR.trans h.2.2.1 + +theorem sourceW_pow_sourceB {L : ℝ} (hW : 1 < sourceW L) : + (sourceW L)^(sourceB L)=Real.exp L := by + rw [sourceB,Real.rpow_def_of_pos (by linarith : 0 < sourceW L)] + congr 1 + field_simp [ne_of_gt (Real.log_pos hW)] + +end NumberTheoryLean.JacobsthalSourceScale + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSurvivorScale.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSurvivorScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..9e93613137580c48a2dd120721357d6ec1180093 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalSurvivorScale.lean @@ -0,0 +1,35 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalSourceRounding + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.JacobsthalSurvivorScale + +theorem normalized_scale_lower {x l L w V0 Y c0 : ℝ} + (hx : 0 < x) (hl : 0 < l) (hlL : l ≤ L) (hLl : L ≤ 2*l) + (hw : 1 < w) (hc0 : 0 < c0) (hY : x^2/8 ≤ Y) (hV : c0/Real.log w ≤ V0) : + c0*x^2*Real.log w/(32*l^2) ≤ Y*V0/(L/Real.log w)^2 := by + have hL : 0 < L := hl.trans_le hlL + have hlog : 0 < Real.log w := Real.log_pos hw + have hY0 : 0 ≤ Y := (div_pos (sq_pos_of_pos hx) (by norm_num : (0:ℝ)<8)).le.trans hY + have hdiv : L/Real.log w ≤ (2*l)/Real.log w := div_le_div_of_nonneg_right hLl hlog.le + have hdl : 0 < L/Real.log w := div_pos hL hlog + have hdu : 0 < (2*l)/Real.log w := by positivity + have hsq : (L/Real.log w)^2 ≤ ((2*l)/Real.log w)^2 := by nlinarith + have hnum : (x^2/8)*(c0/Real.log w) ≤ Y*V0 := + mul_le_mul hY hV (by positivity) hY0 + calc + _ = ((x^2/8)*(c0/Real.log w))/((2*l)/Real.log w)^2 := by + field_simp [hl.ne',hlog.ne'] + ring + _ ≤ ((x^2/8)*(c0/Real.log w))/(L/Real.log w)^2 := + div_le_div_of_nonneg_left (by positivity) (sq_pos_of_pos hdl) hsq + _ ≤ _ := div_le_div_of_nonneg_right hnum (sq_nonneg _) +end NumberTheoryLean.JacobsthalSurvivorScale + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalTerminalScales.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalTerminalScales.lean new file mode 100644 index 0000000000000000000000000000000000000000..899b21d9228981ab2c4a062192a0dad79ff11808 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/JacobsthalTerminalScales.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalDeletionBudget +import OAI.NumberTheory.Jacobsthal.Estimates.CorrectionFloorRemainder + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.JacobsthalTerminalScales +open _root_.Filter Asymptotics JacobsthalSourceScale JacobsthalSourceRounding JacobsthalProgressionLength ProgressionSieve +open scoped Topology + +noncomputable def terminalTop (x : ℝ) : ℝ := x*Real.log x +noncomputable def terminalY (x : ℝ) : ℕ := ErdosInverseBoxHeight.sourceY (terminalTop x) +noncomputable def terminalCutoff (x : ℝ) : ℕ := ⌊terminalTop x⌋₊ + +theorem eventual_terminal_logs : ∀ᶠ x : ℝ in atTop, + 4 ≤ x ∧ 2 ≤ Real.log x ∧ (Real.log x)^2 ≤ x ∧ 16*Real.log x ≤ Real.sqrt x ∧ + Real.log x ≤ Real.log (terminalTop x) ∧ Real.log (terminalTop x) ≤ 2*Real.log x := by + have hsmall := (isLittleO_log_rpow_rpow_atTop (1:ℝ) (s:=1/2) (by norm_num)).bound (by norm_num : (0:ℝ)<1/16) + filter_upwards [eventually_ge_atTop (4:ℝ),Real.tendsto_log_atTop.eventually_ge_atTop 2, + log_square_le_sqrt_eventually,hsmall] with x hx hlog hs hsmall + have hx0 : 0 < x := by linarith + have hl0 : 0 < Real.log x := by linarith + have hr : Real.sqrt x ≤ x := by nlinarith [Real.sq_sqrt hx0.le,Real.sqrt_nonneg x] + have h16 : Real.log x ≤ (1/16:ℝ)*Real.sqrt x := by + simpa only [Real.rpow_one,Real.norm_eq_abs,abs_of_nonneg hl0.le, + ← Real.sqrt_eq_rpow,abs_of_nonneg (Real.sqrt_nonneg x)] using hsmall + have hll0 := Real.log_nonneg (by linarith : 1 ≤ Real.log x) + have hllu := Real.log_le_sub_one_of_pos hl0 + have he : Real.log (terminalTop x)=Real.log x+Real.log (Real.log x) := + Real.log_mul hx0.ne' hl0.ne' + refine ⟨hx,hlog,hs.trans hr,by linarith,?_,?_⟩ <;> rw [he] <;> linarith + +theorem terminal_top_tendsto : Tendsto terminalTop atTop atTop := by + apply tendsto_atTop.mpr + intro R + filter_upwards [eventual_terminal_logs,eventually_ge_atTop R] with x hx hR + unfold terminalTop + nlinarith [hx.1,hx.2.1] + +theorem eventual_terminal_numerics : ∀ᶠ x : ℝ in atTop, + 4 ≤ x ∧ 2 ≤ Real.log x ∧ (Real.log x)^2 ≤ x ∧ 1 < terminalTop x ∧ + x^2/8 ≤ (terminalY x:ℝ) ∧ (terminalY x:ℝ) ≤ x^2 ∧ + progressionLength (terminalY x) (terminalCutoff x) ≤ terminalCutoff x ∧ + (progressionLength (terminalY x) (terminalCutoff x):ℝ) ≤ 2*x/Real.log x ∧ + Real.log x/2 ≤ Real.log (progressionLength (terminalY x) (terminalCutoff x):ℝ) := by + filter_upwards [eventual_terminal_logs] with x hx + obtain ⟨hx,hlog,hs,h16,hlo,hhi⟩ := hx + have hx0 : 0 < x := by linarith + have hl0 : 0 < Real.log x := by linarith + have htop : 2 ≤ terminalTop x := by unfold terminalTop; nlinarith + have hY : x^2/8 ≤ (terminalY x:ℝ) ∧ (terminalY x:ℝ) ≤ x^2 := by + simpa only [terminalY,ErdosInverseBoxHeight.sourceY,terminalTop] using floor_length_bounds hx hl0 hlo hhi + have hZ := floor_cutoff_bounds htop + have hT := source_progression_bounds hx hlog hs (terminalY x) (terminalCutoff x) hY.1 hY.2 hZ.1 + (by simpa only [terminalCutoff,terminalTop,mul_assoc] using hZ.2.2.2) hZ.2.2.1 + exact ⟨hx,hlog,hs,by linarith,hY.1,hY.2,hT.2.2,hT.2.1, + progression_log_lower hx0 hl0 h16 _ _ hT.1⟩ +end NumberTheoryLean.JacobsthalTerminalScales + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/QuadraticBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/QuadraticBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f6dd39a4c039e86b8bb8b0217f060c7b5ef326c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/QuadraticBound.lean @@ -0,0 +1,23 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalFromRootLower +import OAI.NumberTheory.Jacobsthal.Conclusions.SourceRootCompletion + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace Erdos970Final + + +theorem erdos_970_quadratic : NumberTheoryLean.Targets.JacobsthalQuadratic := by + obtain ⟨c,hc,hLower⟩ := source_root_survivor_lower + exact NumberTheoryLean.JacobsthalFromRootLower.jacobsthal_of_source_root_lower c hc + (ErdosCorrectionLimit.sourceRootNode (1/100)) hLower + +end Erdos970Final + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/SourceRootCompletion.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/SourceRootCompletion.lean new file mode 100644 index 0000000000000000000000000000000000000000..6048acefdb06b280e9b68bda176ba5a32d50777f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/SourceRootCompletion.lean @@ -0,0 +1,55 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceRootErrorLower +import OAI.NumberTheory.Jacobsthal.Paths.SourceStoppedCorrection + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace Erdos970Final +open _root_.Filter NumberTheoryLean NumberTheoryLean.PrimeHistories + NumberTheoryLean.SourceRootErrorLower NumberTheoryLean.StoppedCountVertex + NumberTheoryLean.StoppedCountAdapters NumberTheoryLean.LogarithmicBinPartition + NumberTheoryLean.LargePrimeDeletion + ErdosInverseBoxHeight ErdosCorrectionLimit + + +theorem source_root_survivor_lower : ∃ c : ℝ,0 < c ∧ ∀ᶠ top : ℝ in atTop, + ∀ a : ℕ → ℕ, + c*((sourceY top : ℝ)*SmallSieveFinite.smallEuler ⌊sourceW top⌋₊/(sourceB top)^2) ≤ + countSurvivors (sourceY top) (cutoffPrimes ⌊sourceW top⌋₊) a + (rootVertex (sourceRootNode (1/100) top) ∅ (sourcePrimeSet (sourceW top) top) + ((sourceY top : ℝ)*SmallSieveFinite.smallEuler ⌊sourceW top⌋₊)) := by + obtain ⟨eta0,heta0,heta01,hCorrection⟩ := source_stopped_correction + obtain ⟨c,Clen,Cs,xi0,hc,hClen,hCs,_hCsMin,hxi0,hxi01,hError⟩ := + source_root_lower_with_stopped_correction 1 + have hClenPos : 0 < Clen := by linarith + obtain ⟨K,hK,hCorrection⟩ := hCorrection Cs hCs.le + let eta : ℝ := eta0/2 + let xi : ℝ := min (xi0/2) (1/(40*Clen)) + have heta : 0 < eta := by dsimp [eta];positivity + have hetaU : eta ≤ eta0 := by dsimp [eta];linarith + have hetaHalf : eta < 1/2 := by dsimp [eta];linarith + have hxi : 0 < xi := lt_min (by positivity) (by positivity) + have hxiU : xi ≤ xi0 := (min_le_left _ _).trans (by linarith) + have hxi1 : xi ≤ 1 := hxiU.trans hxi01 + obtain ⟨rho,hrho,hError⟩ := hError eta heta hetaHalf xi hxi hxiU + have hKstop : 0 < 2*K := by positivity + have hCorrection := hCorrection Clen hClenPos.le eta heta.le hetaU xi hxi hxi1 rho (by linarith) + refine ⟨c,hc,?_⟩ + filter_upwards [hError (2*K) hKstop,hCorrection] with top hError hCorrection + obtain ⟨_hw,_htop,hError⟩ := hError + obtain ⟨_hwC,_htopC,hCorrection⟩ := hCorrection + intro a + have hLower := hError a + have hSign := hCorrection a + dsimp only at hLower hSign + linarith + +end Erdos970Final + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Conclusions/Targets.lean b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/Targets.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e50941f81a83e40c4637d07fb71dba372fb59f6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Conclusions/Targets.lean @@ -0,0 +1,70 @@ +import Mathlib.Analysis.SpecialFunctions.Log.Basic +import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic +import Mathlib.Data.Nat.Factors +import Mathlib.Order.Filter.AtTopBot.Basic +import OAI.NumberTheory.Jacobsthal.Model + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.Targets + +open Filter +open scoped Topology + +noncomputable def representationCount (A : Set ℕ) (n : ℕ) : ℕ := by + classical + exact ((Finset.range (n + 1)).filter fun a => a ∈ A ∧ n - a ∈ A).card + +noncomputable def orderedRepresentations (A : Set ℕ) (n : ℕ) : Finset (ℕ × ℕ) := by + classical + exact ((Finset.range (n + 1)).product (Finset.range (n + 1))).filter + fun r => r.1 ∈ A ∧ r.2 ∈ A ∧ r.1 + r.2 = n + +theorem representationCount_eq_card_orderedRepresentations (A : Set ℕ) (n : ℕ) : + representationCount A n = (orderedRepresentations A n).card := by + classical + unfold representationCount orderedRepresentations + apply Finset.card_bij (fun a _ => (a, n - a)) + · intro a ha + obtain ⟨harange, haA, hbA⟩ := Finset.mem_filter.mp ha + have han := Finset.mem_range.mp harange + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_product.mpr ⟨harange, Finset.mem_range.mpr (by omega)⟩, + haA, hbA, ?_⟩ + omega + · intro a₁ _ a₂ _ heq + exact congrArg Prod.fst heq + · intro r hr + obtain ⟨hrange, hxA, hyA, hsum⟩ := Finset.mem_filter.mp hr + have hxrange := (Finset.mem_product.mp hrange).1 + have hdiff : n - r.1 = r.2 := by omega + refine ⟨r.1, Finset.mem_filter.mpr ⟨hxrange, hxA, ?_⟩, ?_⟩ + · simpa only [hdiff] using hyA + · exact Prod.ext rfl hdiff + +def LogarithmicRepresentationLimit : Prop := + ∃ A : Set ℕ, ∃ c : ℝ, c ≠ 0 ∧ + Tendsto (fun n : ℕ => (representationCount A n : ℝ) / Real.log n) + atTop (𝓝 c) + +def AdditiveBasisPiLimit : Prop := + ∃ A : Set ℕ, + Tendsto (fun n : ℕ => (representationCount A n : ℝ) / Real.log n) + atTop (𝓝 Real.pi) + +theorem public_limit_of_pi_limit (h : AdditiveBasisPiLimit) : + LogarithmicRepresentationLimit := by + obtain ⟨A, hA⟩ := h + exact ⟨A, Real.pi, ne_of_gt Real.pi_pos, hA⟩ + +end NumberTheoryLean.Targets + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualCollisionBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualCollisionBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..2322350dcd87a47b4d14a2a0733d05ea0e9b014d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualCollisionBound.lean @@ -0,0 +1,410 @@ +import OAI.NumberTheory.Jacobsthal.Primes.BadPrimeProduct +import OAI.NumberTheory.Jacobsthal.Primes.PrimeRationalList +import OAI.NumberTheory.Jacobsthal.Probability.PreciseIncidenceMoment +import OAI.NumberTheory.Jacobsthal.Sieve.LargePrimeDivisors + +namespace OAI + +namespace Erdos970 + + +namespace ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +noncomputable def sourceRationalList (P : Finset ℕ) (a : ℕ → ℤ) (Sq R Z c : ℝ) : Finset ℚ := + rationalList P a ⌊Sq*R*Z^10⌋₊ ⌊R*Z^10⌋₊ c + +theorem mem_sourceRationalList (P : Finset ℕ) (a : ℕ → ℤ) {Sq R Z c : ℝ} + (hSq : 0 ≤ Sq) (hR : 0 ≤ R) (q : ℚ) : + q ∈ sourceRationalList P a Sq R Z c ↔ + (q.num.natAbs : ℝ) ≤ Sq*R*Z^10 ∧ (q.den : ℝ) ≤ R*Z^10 ∧ + c*(P.card : ℝ) ≤ ((P.filter (aligns a q)).card : ℝ) := by + rw [sourceRationalList,mem_rationalList, + Nat.le_floor_iff (show 0 ≤ Sq*R*Z^10 by positivity), + Nat.le_floor_iff (show 0 ≤ R*Z^10 by positivity)] + +theorem source_height_product_bound {Sq R Z : ℝ} + (hSq : 0 ≤ Sq) (hR : 0 ≤ R) : + ((2*⌊Sq*R*Z^10⌋₊*⌊R*Z^10⌋₊ : ℕ) : ℝ) ≤ 2*Sq*R^2*Z^20 := by + push_cast + calc + _ ≤ (2*(Sq*R*Z^10))*(R*Z^10) := + mul_le_mul (mul_le_mul_of_nonneg_left (Nat.floor_le (by positivity)) (by norm_num)) + (Nat.floor_le (by positivity)) (Nat.cast_nonneg _) (by positivity) + _ = _ := by ring + +theorem source_rational_list_bound (P : Finset ℕ) (a : ℕ → ℤ) + {Sq R Z z α C c : ℝ} (hSq : 0 ≤ Sq) (hR : 0 ≤ R) + (hz : 1 < z) (hα : 0 < α) (hC : 0 ≤ C) (hc : 0 < c) + (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,z^α ≤ (p : ℝ)) + (hheight : 2*Sq*R^2*Z^20 ≤ z^C) (hPpos : 0 < P.card) + (henough : 2*(C/α) ≤ c^2*(P.card : ℝ)) : + (sourceRationalList P a Sq R Z c).card ≤ ⌈2/c^2⌉₊ := by + exact prime_rational_list_card_le_ceil P a _ _ hz hα hC hc hP hlarge + ((source_height_product_bound hSq hR).trans hheight) hPpos henough + +end ErdosInverseAlignment + + + +namespace ErdosPrimitiveIntercept +open ErdosRichLine + +theorem InterceptReduction.denominator_le {l : PrimitiveIntegerLine} (r : InterceptReduction l) : + r.rational.den ≤ l.denominator := by + rw [r.denominator_eq] + simpa using Nat.mul_le_mul_right r.rational.den (Nat.succ_le_of_lt r.factor_pos) + +theorem InterceptReduction.numerator_abs_le {l : PrimitiveIntegerLine} (r : InterceptReduction l) : + r.rational.num.natAbs ≤ l.intercept.natAbs := by + rw [r.intercept_eq,Int.natAbs_mul,Int.natAbs_natCast] + simpa using Nat.mul_le_mul_right r.rational.num.natAbs (Nat.succ_le_of_lt r.factor_pos) + +theorem InterceptReduction.height_transfer {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (Hden Hnum : ℝ) (hd : (l.denominator : ℝ) ≤ Hden) (hn : |(l.intercept : ℝ)| ≤ Hnum) : + (r.rational.den : ℝ) ≤ Hden ∧ |(r.rational.num : ℝ)| ≤ Hnum := by + have hden : (r.rational.den : ℝ) ≤ l.denominator := by exact_mod_cast r.denominator_le + have hnum : |(r.rational.num : ℝ)| ≤ |(l.intercept : ℝ)| := by + have hh : (r.rational.num.natAbs : ℝ) ≤ l.intercept.natAbs := by exact_mod_cast r.numerator_abs_le + simpa only [Nat.cast_natAbs,Int.cast_abs] using hh + exact ⟨hden.trans hd,hnum.trans hn⟩ + +end ErdosPrimitiveIntercept + + + +namespace ErdosPrimitiveIntercept +open ErdosRichLine + +theorem exists_canonical_structured_intercept (l : PrimitiveIntegerLine) : + ∃ (t : ℚ) (g : ℕ), 0 < g ∧ l.denominator = g*t.den ∧ l.intercept = (g : ℤ)*t.num ∧ + t = (l.intercept : ℚ)/(l.denominator : ℚ) ∧ + t.den ≤ l.denominator ∧ t.num.natAbs ≤ l.intercept.natAbs ∧ + (∀ p : ℤ × ℤ, l.Contains p → (g : ℤ) ∣ p.1) ∧ + ∀ (a : ℕ → ℤ) (q : ℕ) (b : ℤ), l.Contains ((q : ℤ),b) → + (∀ ell ∈ q.primeFactors, (b : ZMod ell) = (a ell : ZMod ell)) → + t.den*badPrimeProduct a t q ≤ l.denominator := by + obtain ⟨r⟩ := exists_intercept_reduction l + exact ⟨r.rational,r.factor,r.factor_pos,r.denominator_eq,r.intercept_eq,r.rational_value, + r.denominator_le,r.numerator_abs_le,r.factor_dvd_abscissa,r.structure_bound⟩ + +end ErdosPrimitiveIntercept + + + +namespace ErdosInverseStructured +open ErdosInverseAlignment ErdosPrimitiveIntercept ErdosRichLine + +def Structured (P : Finset ℕ) (a : ℕ → ℤ) (S R Z cp : ℝ) (p q : ℕ) : Prop := + ∃ t ∈ sourceRationalList P a S R Z cp, aligns a t p ∧ + ((t.den*badPrimeProduct a t q : ℕ) : ℝ) ≤ R*Z^10 + +def Nonstructured (P : Finset ℕ) (a : ℕ → ℤ) (S R Z cp : ℝ) (p q : ℕ) : Prop := + ¬Structured P a S R Z cp p q + +theorem structured_of_line_alignment {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (a : ℕ → ℤ) (S R Z cp : ℝ) (p q : ℕ) (b : ℤ) + (hlist : r.rational ∈ sourceRationalList P a S R Z cp) + (hden : (l.denominator : ℝ) ≤ R*Z^10) (hline : l.Contains ((q : ℤ),b)) + (hclass : ∀ ell ∈ q.primeFactors,(b : ZMod ell) = (a ell : ZMod ell)) + (halign : aligns a r.rational p) : Structured P a S R Z cp p q := by + refine ⟨r.rational,hlist,halign,?_⟩ + have hh : ((r.rational.den*badPrimeProduct a r.rational q : ℕ) : ℝ) ≤ l.denominator := + Nat.cast_le.mpr (r.structure_bound a q b hline hclass) + exact hh.trans hden + +theorem nonstructured_not_aligned_on_line {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (a : ℕ → ℤ) (S R Z cp : ℝ) (p q : ℕ) (b : ℤ) + (hlist : r.rational ∈ sourceRationalList P a S R Z cp) + (hden : (l.denominator : ℝ) ≤ R*Z^10) (hline : l.Contains ((q : ℤ),b)) + (hclass : ∀ ell ∈ q.primeFactors,(b : ZMod ell) = (a ell : ZMod ell)) + (hnon : Nonstructured P a S R Z cp p q) : ¬aligns a r.rational p := + fun ha => hnon (structured_of_line_alignment r P a S R Z cp p q b hlist hden hline hclass ha) + +end ErdosInverseStructured + + + +namespace ErdosLineCollision +open ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment + +noncomputable def slopeClass (l : PrimitiveIntegerLine) (a : ℤ) (p : ℕ) (hp : Nat.Prime p) (s : ℤ) : ZMod p := by + letI : Fact (Nat.Prime p) := ⟨hp⟩ + exact ((l.denominator : ZMod p)*(a : ZMod p)-(l.intercept : ZMod p))/ + ((l.slope : ZMod p)+(l.denominator : ZMod p)*(s : ZMod p)) + +theorem unaligned_numerator_ne_zero {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (a : ℕ → ℤ) (p : ℕ) (hp : Nat.Prime p) (hpd : ¬p ∣ l.denominator) + (hna : ¬aligns a r.rational p) : + (l.denominator : ZMod p)*(a p : ZMod p)-(l.intercept : ZMod p) ≠ 0 := by + let : Fact (Nat.Prime p) := ⟨hp⟩ + have hpg : ¬p ∣ r.factor := fun h => hpd (h.trans r.factor_dvd_denominator) + have hg : (r.factor : ZMod p) ≠ 0 := (ZMod.natCast_eq_zero_iff _ _).not.mpr hpg + have hdiff : (r.rational.den : ZMod p)*(a p : ZMod p)-(r.rational.num : ZMod p) ≠ 0 := + sub_ne_zero.mpr hna + have he : (l.denominator : ZMod p)*(a p : ZMod p)-(l.intercept : ZMod p) = + (r.factor : ZMod p)*((r.rational.den : ZMod p)*(a p : ZMod p)-(r.rational.num : ZMod p)) := by + rw [r.denominator_eq,r.intercept_eq,Nat.cast_mul,Int.cast_mul,Int.cast_natCast] + ring + rw [he] + exact mul_ne_zero hg hdiff + +theorem point_residue_eq_slopeClass {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (a : ℕ → ℤ) (p : ℕ) (hp : Nat.Prime p) (hpd : ¬p ∣ l.denominator) + (hna : ¬aligns a r.rational p) (v : ℤ × ℤ) (hv : l.Contains v) (s : ℤ) + (hinc : (v.2 : ZMod p) = (a p : ZMod p)-(s : ZMod p)*(v.1 : ZMod p)) : + (v.1 : ZMod p) = slopeClass l (a p) p hp s := by + let : Fact (Nat.Prime p) := ⟨hp⟩ + have hnum := unaligned_numerator_ne_zero r a p hp hpd hna + have hvZ : (l.denominator : ZMod p)*(v.2 : ZMod p) = + (l.slope : ZMod p)*(v.1 : ZMod p)+(l.intercept : ZMod p) := by + have h := congrArg (fun n : ℤ => (n : ZMod p)) hv + simpa only [PrimitiveIntegerLine.Contains,Int.cast_mul,Int.cast_add,Int.cast_natCast] using h + have he : ((l.slope : ZMod p)+(l.denominator : ZMod p)*(s : ZMod p))*(v.1 : ZMod p) = + (l.denominator : ZMod p)*(a p : ZMod p)-(l.intercept : ZMod p) := by + linear_combination (l.denominator : ZMod p)*hinc-hvZ + have hcoeff : (l.slope : ZMod p)+(l.denominator : ZMod p)*(s : ZMod p) ≠ 0 := by + intro hz + exact hnum (by simpa only [hz,zero_mul] using he.symm) + unfold slopeClass + apply (eq_div_iff hcoeff).mpr + simpa only [mul_comm] using he + +end ErdosLineCollision + + + +namespace ErdosLineCollision +open ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment + +noncomputable def incidentPoints (X : Finset (ℤ × ℤ)) (a : ℤ) (p : ℕ) (T : Finset ℤ) : Finset (ℤ × ℤ) := by + classical + exact X.filter (fun v => ∃ s ∈ T, + (v.2 : ZMod p) = (a : ZMod p)-(s : ZMod p)*(v.1 : ZMod p)) + +noncomputable def occupiedClasses (X : Finset (ℤ × ℤ)) (a : ℤ) (p : ℕ) (T : Finset ℤ) : Finset (ZMod p) := by + classical + exact (incidentPoints X a p T).image (fun v => (v.1 : ZMod p)) + +theorem occupiedClasses_subset_slope_image {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (X : Finset (ℤ × ℤ)) (hline : ∀ v ∈ X, l.Contains v) (a : ℕ → ℤ) (p : ℕ) + (hp : Nat.Prime p) (hpd : ¬p ∣ l.denominator) (hna : ¬aligns a r.rational p) (T : Finset ℤ) : + occupiedClasses X (a p) p T ⊆ T.image (slopeClass l (a p) p hp) := by + classical + intro t ht + obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp ht + obtain ⟨hvX,s,hs,hinc⟩ := Finset.mem_filter.mp hv + exact Finset.mem_image.mpr ⟨s,hs,(point_residue_eq_slopeClass r a p hp hpd hna v + (hline v hvX) s hinc).symm⟩ + +theorem occupiedClasses_card_le {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (X : Finset (ℤ × ℤ)) (hline : ∀ v ∈ X, l.Contains v) (a : ℕ → ℤ) (p : ℕ) + (hp : Nat.Prime p) (hpd : ¬p ∣ l.denominator) (hna : ¬aligns a r.rational p) (T : Finset ℤ) : + (occupiedClasses X (a p) p T).card ≤ T.card := by + classical + exact (Finset.card_le_card (occupiedClasses_subset_slope_image r X hline a p hp hpd hna T)).trans + (Finset.card_image_le) + +end ErdosLineCollision + + + +namespace ErdosLineCollision +attribute [local instance] Classical.propDecidable + +noncomputable def occupiedRows (P : Finset ℕ) (X : Finset (ℤ × ℤ)) + (a : ℕ → ℤ) (T : ℕ → Finset ℤ) : Finset (ℕ × ℕ) := by + classical + exact P.biUnion (fun p => (occupiedClasses X (a p) p (T p)).image (fun c => (p,c.val))) + +def RowIncidence (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (v : ℤ × ℤ) (row : ℕ × ℕ) : Prop := + v ∈ incidentPoints X (a row.1) row.1 (T row.1) ∧ (v.1 : ZMod row.1).val = row.2 + +theorem row_modulus_mem {P : Finset ℕ} {X : Finset (ℤ × ℤ)} {a : ℕ → ℤ} {T : ℕ → Finset ℤ} + {row : ℕ × ℕ} (hr : row ∈ occupiedRows P X a T) : row.1 ∈ P := by + classical + obtain ⟨p,hp,hpRow⟩ := Finset.mem_biUnion.mp hr + obtain ⟨c,hc,hrow⟩ := Finset.mem_image.mp hpRow + subst row + exact hp + +theorem point_rows_eq (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (v : ℤ × ℤ) : + (occupiedRows P X a T).filter (RowIncidence X a T v) = + (P.filter (fun p => v ∈ incidentPoints X (a p) p (T p))).image + (fun p => (p,(v.1 : ZMod p).val)) := by + classical + ext row + constructor + · intro hr + obtain ⟨hrow,hinc,hval⟩ := Finset.mem_filter.mp hr + exact Finset.mem_image.mpr ⟨row.1,Finset.mem_filter.mpr ⟨row_modulus_mem hrow,hinc⟩, + Prod.ext rfl hval⟩ + · intro hr + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hr + obtain ⟨hpP,hv⟩ := Finset.mem_filter.mp hp + have hclass : (v.1 : ZMod p) ∈ occupiedClasses X (a p) p (T p) := + Finset.mem_image.mpr ⟨v,hv,rfl⟩ + refine Finset.mem_filter.mpr ⟨?_,hv,rfl⟩ + exact Finset.mem_biUnion.mpr ⟨p,hpP,Finset.mem_image.mpr ⟨(v.1 : ZMod p),hclass,rfl⟩⟩ + +theorem point_rows_card (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (v : ℤ × ℤ) : + ((occupiedRows P X a T).filter (RowIncidence X a T v)).card = + (P.filter (fun p => v ∈ incidentPoints X (a p) p (T p))).card := by + classical + rw [point_rows_eq] + apply Finset.card_image_of_injective + intro p q he + exact congrArg Prod.fst he + +end ErdosLineCollision + + + +namespace ErdosLineCollision +open ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem occupiedRows_card_le {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (hline : ∀ v ∈ X, l.Contains v) (hP : ∀ p ∈ P, Nat.Prime p) + (hpd : ∀ p ∈ P, ¬p ∣ l.denominator) (hna : ∀ p ∈ P, ¬aligns a r.rational p) : + (occupiedRows P X a T).card ≤ ∑ p ∈ P,(T p).card := by + classical + apply Finset.card_biUnion_le.trans + apply Finset.sum_le_sum + intro p hp + exact Finset.card_image_le.trans (occupiedClasses_card_le r X hline a p (hP p hp) (hpd p hp) (hna p hp) (T p)) + +noncomputable def commonRows (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (v w : ℤ × ℤ) : Finset (ℕ × ℕ) := + (occupiedRows P X a T).filter (fun row => RowIncidence X a T v row ∧ RowIncidence X a T w row) + +theorem commonRows_modulus_injective (P : Finset ℕ) (X : Finset (ℤ × ℤ)) + (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (v w : ℤ × ℤ) : + Set.InjOn Prod.fst (commonRows P X a T v w : Set (ℕ × ℕ)) := by + intro row hr row' hr' he + have hval := ((Finset.mem_filter.mp hr).2).1.2 + have hval' := ((Finset.mem_filter.mp hr').2).1.2 + rw [he] at hval + exact Prod.ext he (hval.symm.trans hval') + +theorem commonRows_modulus_divides (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) + (T : ℕ → Finset ℤ) (hP : ∀ p ∈ P, Nat.Prime p) (v w : ℤ × ℤ) + (row : ℕ × ℕ) (hr : row ∈ commonRows P X a T v w) : (row.1 : ℤ) ∣ v.1-w.1 := by + have hp := row_modulus_mem (Finset.mem_filter.mp hr).1 + let : Fact (Nat.Prime row.1) := ⟨hP row.1 hp⟩ + have hval := ((Finset.mem_filter.mp hr).2).1.2 + have hval' := ((Finset.mem_filter.mp hr).2).2.2 + have he : (v.1 : ZMod row.1) = (w.1 : ZMod row.1) := + ZMod.val_injective row.1 (hval.trans hval'.symm) + apply (ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp + simp only [Int.cast_sub,he,sub_self] + +theorem commonRows_card_le (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (hP : ∀ p ∈ P, Nat.Prime p) (v w : ℤ × ℤ) (hx : v.1 ≠ w.1) + (z alpha C : ℝ) (hz : 1 < z) (ha : 0 < alpha) + (hlarge : ∀ p ∈ P,z^alpha ≤ (p : ℝ)) (hheight : |((v.1-w.1 : ℤ) : ℝ)| ≤ z^C) : + ((commonRows P X a T v w).card : ℝ) ≤ C/alpha := by + classical + have hsub : (commonRows P X a T v w).image Prod.fst ⊆ dividingPrimes P (v.1-w.1) := by + intro p hp + obtain ⟨row,hrow,rfl⟩ := Finset.mem_image.mp hp + exact Finset.mem_filter.mpr ⟨row_modulus_mem (Finset.mem_filter.mp hrow).1, + commonRows_modulus_divides P X a T hP v w row hrow⟩ + have hc : (commonRows P X a T v w).card ≤ (dividingPrimes P (v.1-w.1)).card := by + rw [← Finset.card_image_of_injOn (commonRows_modulus_injective P X a T v w)] + exact Finset.card_le_card hsub + apply (show ((commonRows P X a T v w).card : ℝ) ≤ (dividingPrimes P (v.1-w.1)).card by exact_mod_cast hc).trans + exact dividingPrimes_card_bound P (v.1-w.1) (sub_ne_zero.mpr hx) hP z alpha C hz ha hlarge hheight + +end ErdosLineCollision + + + +namespace ErdosLineCollision +open ErdosInverseIncidence +attribute [local instance] Classical.propDecidable + +theorem row_multiplicity_sum (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) : + (∑ row ∈ occupiedRows P X a T,multiplicity X (RowIncidence X a T) row) = + ∑ p ∈ P,((incidentPoints X (a p) p (T p)).card : ℝ) := by + classical + let R : (ℤ × ℤ) → ℕ → Prop := fun v p => v ∈ incidentPoints X (a p) p (T p) + have hdegree (v : ℤ × ℤ) : degree (occupiedRows P X a T) (RowIncidence X a T) v = degree P R v := + by simpa only [ErdosInverseIncidence.degree,R] using point_rows_card P X a T v + have hcount (p : ℕ) : multiplicity X R p = ((incidentPoints X (a p) p (T p)).card : ℝ) := by + have he : X.filter (fun v => v ∈ incidentPoints X (a p) p (T p)) = incidentPoints X (a p) p (T p) := by + ext v + simp only [Finset.mem_filter] + exact ⟨fun h => h.2,fun h => ⟨(Finset.mem_filter.mp h).1,h⟩⟩ + have hh : (∑ v ∈ X,if v ∈ incidentPoints X (a p) p (T p) then (1 : ℝ) else 0) = + ((X.filter (fun v => v ∈ incidentPoints X (a p) p (T p))).card : ℝ) := + Finset.sum_boole (fun v => v ∈ incidentPoints X (a p) p (T p)) X + rw [he] at hh + have hsum : multiplicity X R p = + ∑ v ∈ X,if v ∈ incidentPoints X (a p) p (T p) then (1 : ℝ) else 0 := by + unfold ErdosInverseIncidence.multiplicity + apply Finset.sum_congr rfl + intro v hv + by_cases hmem : v ∈ incidentPoints X (a p) p (T p) <;> + simp [ErdosInverseIncidence.bit,R,hmem] + exact hsum.trans hh + calc + _ = ∑ v ∈ X,(degree (occupiedRows P X a T) (RowIncidence X a T) v : ℝ) := multiplicity_sum _ _ _ + _ = ∑ v ∈ X,(degree P R v : ℝ) := by simp_rw [hdegree] + _ = ∑ p ∈ P,multiplicity X R p := (multiplicity_sum X P R).symm + _ = _ := Finset.sum_congr rfl (fun p _ => hcount p) + +theorem total_incidence_le_product (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) : + (∑ p ∈ P,((incidentPoints X (a p) p (T p)).card : ℝ)) ≤ (P.card : ℝ)*(X.card : ℝ) := by + calc + _ ≤ ∑ _p ∈ P,(X.card : ℝ) := Finset.sum_le_sum (fun p _ => by + have hc : (incidentPoints X (a p) p (T p)).card ≤ X.card := Finset.card_filter_le X _ + exact Nat.cast_le.mpr hc) + _ = _ := by simp + +end ErdosLineCollision + + + +namespace ErdosLineCollision +open ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment ErdosInverseIncidence ErdosConvexGraph + +theorem actual_collision_bound {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (hline : ∀ v ∈ X,l.Contains v) (hP : ∀ p ∈ P,Nat.Prime p) + (hpd : ∀ p ∈ P,¬p ∣ l.denominator) (hna : ∀ p ∈ P,¬aligns a r.rational p) + (hinj : Set.InjOn Prod.fst (X : Set (ℤ × ℤ))) (S z alpha : ℝ) + (hbox : ∀ v ∈ X,InSquare S v) (hz : 1 < z) (ha : 0 < alpha) + (hlarge : ∀ p ∈ P,z^alpha ≤ (p : ℝ)) (hS : S ≤ z^3) : + (∑ p ∈ P,((incidentPoints X (a p) p (T p)).card : ℝ))^2 ≤ + (∑ p ∈ P,((T p).card : ℝ))* + ((3/alpha)*(X.card : ℝ)^2+∑ p ∈ P,((incidentPoints X (a p) p (T p)).card : ℝ)) := by + classical + have hK : (0 : ℝ) ≤ 3/alpha := by positivity + have hB : 0 ≤ ∑ p ∈ P,((T p).card : ℝ) := Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _) + have hQ : ((occupiedRows P X a T).card : ℝ) ≤ ∑ p ∈ P,((T p).card : ℝ) := by + exact_mod_cast occupiedRows_card_le r P X a T hline hP hpd hna + have hpair : ∀ v ∈ X,∀ w ∈ X,v ≠ w → + (((occupiedRows P X a T).filter + (fun row => RowIncidence X a T v row ∧ RowIncidence X a T w row)).card : ℝ) ≤ 3/alpha := by + intro v hv w hw hne + have hx : v.1 ≠ w.1 := fun he => hne (hinj hv hw he) + have hh : |((v.1-w.1 : ℤ) : ℝ)| ≤ z^(3 : ℝ) := by + have he : z^(3 : ℝ) = z^3 := Real.rpow_natCast z 3 + rw [he] + exact (integer_difference_abs_le (hbox v hv).1 (hbox w hw).1).trans hS + exact commonRows_card_le P X a T hP v w hx z alpha 3 hz ha hlarge hh + have hh := precise_incidence_cauchy X (occupiedRows P X a T) (RowIncidence X a T) + (3/alpha) (∑ p ∈ P,((T p).card : ℝ)) hK hB hQ hpair + rwa [row_multiplicity_sum] at hh + +end ErdosLineCollision + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualModelTargets.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualModelTargets.lean new file mode 100644 index 0000000000000000000000000000000000000000..8291294e13ae4d8c3bedfa96c103e64c030fbe11 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualModelTargets.lean @@ -0,0 +1,432 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Partitions.EffectiveCommonInterval +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueProjection +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueTailUpper + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceCommon + +theorem relative_deviation_iff (N mu eps : ℝ) (hmu : 0 < mu) : + eps < |N/mu-1| ↔ eps*mu < |N-mu| := by + have he : N/mu-1 = (N-mu)/mu := by field_simp + rw [he,abs_div,abs_of_pos hmu,lt_div_iff₀ hmu] + +theorem common_deviation_transfer (N mu S M eps A B : ℝ) + (hM : 0 ≤ M) (hmu : M ≤ mu) (heps : 0 < eps) + (hN : |N-S| ≤ A*M) (href : |mu-M| ≤ B*M) (hbudget : A+B ≤ eps/2) + (hbad : eps*mu < |N-mu|) : (eps/2)*M < |S-M| := by + have htri : |N-mu| ≤ |N-S|+|S-M|+|mu-M| := by + calc + _ ≤ |N-S|+|S-mu| := abs_sub_le N S mu + _ ≤ |N-S|+(|S-M|+|M-mu|) := add_le_add le_rfl (abs_sub_le S M mu) + _ = _ := by rw [abs_sub_comm M mu];ring + have hmu' := mul_le_mul_of_nonneg_left hmu heps.le + have hsum := mul_le_mul_of_nonneg_right hbudget hM + nlinarith + +end ErdosVarianceCommon + +end + +section + +namespace ErdosVarianceMoments +open ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable + +def modelSurvives (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (j : ℕ) (v : ModelPoint w H) : Prop := + (∀ t ∈ divisorPrimes w H,patternKValue w H v.2 t+divisorPhase C0 v.1 t*(j : ZMod t) ≠ beta t) ∧ + (∀ t ∈ coprimePrimes w H,patternPValue w H v.2 t*(qA : ZMod t)* + ((v.1 : ZMod t)+(H : ZMod t)*(j : ZMod t)) ≠ delta t) + +noncomputable def modelIndicator (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (j : ℕ) (v : ModelPoint w H) : ℝ := + if modelSurvives w H C0 qA beta delta j v then 1 else 0 + +def jointCondition (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (v : ModelPoint w H) : Prop := + ∀ j ∈ S,modelSurvives w H C0 qA beta delta j v + +noncomputable def jointIndicator (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (v : ModelPoint w H) : ℝ := + if jointCondition w H C0 qA beta delta S v then 1 else 0 + +theorem modelIndicator_binary (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (j : ℕ) (v : ModelPoint w H) : + modelIndicator w H C0 qA beta delta j v = 0 ∨ modelIndicator w H C0 qA beta delta j v = 1 := by + unfold modelIndicator + split <;> simp + +theorem jointCondition_split (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (v : ModelPoint w H) : + jointCondition w H C0 qA beta delta S v ↔ + (∀ t ∈ divisorPrimes w H,∀ j ∈ S,patternKValue w H v.2 t+divisorPhase C0 v.1 t*(j : ZMod t) ≠ beta t) ∧ + (∀ t ∈ coprimePrimes w H,∀ j ∈ S,patternPValue w H v.2 t*(qA : ZMod t)* + ((v.1 : ZMod t)+(H : ZMod t)*(j : ZMod t)) ≠ delta t) := by + constructor + · intro h + exact ⟨fun t ht j hj => (h j hj).1 t ht,fun t ht j hj => (h j hj).2 t ht⟩ + · rintro ⟨h0,h1⟩ j hj + exact ⟨fun t ht => h0 t ht j hj,fun t ht => h1 t ht j hj⟩ + +theorem jointIndicator_singleton (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (j : ℕ) (v : ModelPoint w H) : + jointIndicator w H C0 qA beta delta {j} v = modelIndicator w H C0 qA beta delta j v := by + simp [jointIndicator,jointCondition,modelIndicator] + +theorem jointIndicator_pair (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (i j : ℕ) (v : ModelPoint w H) : + jointIndicator w H C0 qA beta delta {i,j} v = + modelIndicator w H C0 qA beta delta i v*modelIndicator w H C0 qA beta delta j v := by + by_cases hi : modelSurvives w H C0 qA beta delta i v <;> + by_cases hj : modelSurvives w H C0 qA beta delta j v <;> + simp [jointIndicator,jointCondition,modelIndicator,hi,hj] + +theorem jointIndicator_empty (w : ℝ) (H : ℕ) (C0 : ℤ) (qA : ℕ) + (beta delta : ∀ t : ℕ,ZMod t) (v : ModelPoint w H) : + jointIndicator w H C0 qA beta delta ∅ v = 1 := by simp [jointIndicator,jointCondition] + +end ErdosVarianceMoments + +end + +section + +namespace ErdosVarianceCommon +open NumberTheoryLean + +noncomputable def referenceCount (Y : ℕ) (w : ℝ) (p qf : ℕ) : ℝ := + (Y : ℝ)/((p : ℝ)*qf)*SmallSieveFinite.smallEuler ⌊w⌋₊ + +noncomputable def commonReference (J : ℕ) (w : ℝ) : ℝ := + (J : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊ + +theorem reference_above_common (Y qf p : ℕ) (hq : 0 < qf) (hp : 0 < p) (w R xi : ℝ) + (hR : 0 < R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hV : 0 ≤ SmallSieveFinite.smallEuler ⌊w⌋₊) + (hbin : R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) : + commonReference (commonLength Y qf R xi) w ≤ referenceCount Y w p qf := + mul_le_mul_of_nonneg_right (commonLength_reference_bounds Y qf p hq hp R xi hR hxi hxi1 hbin).1 hV + +theorem common_reference_error (Y qf p : ℕ) (hq : 0 < qf) (hp : 0 < p) (w R xi : ℝ) + (hR : 0 < R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hV : 0 ≤ SmallSieveFinite.smallEuler ⌊w⌋₊) + (hbin : R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) + (hpay : 3 ≤ xi*(commonLength Y qf R xi : ℝ)) : + |referenceCount Y w p qf-commonReference (commonLength Y qf R xi) w| ≤ + 2*xi*commonReference (commonLength Y qf R xi) w := by + have hr := commonLength_reference_bounds Y qf p hq hp R xi hR hxi hxi1 hbin + have hd : (Y : ℝ)/((p : ℝ)*qf)-(commonLength Y qf R xi : ℝ) ≤ + 2*xi*(commonLength Y qf R xi : ℝ) := by linarith [hr.2] + rw [abs_of_nonneg (sub_nonneg.mpr (reference_above_common Y qf p hq hp w R xi hR hxi hxi1 hV hbin))] + have hh := mul_le_mul_of_nonneg_right hd hV + dsimp [referenceCount,commonReference] + nlinarith + +end ErdosVarianceCommon + +end + +section + +namespace ErdosVarianceCommon +open NumberTheoryLean ErdosVarianceEffective ErdosInverseCounts ErdosHypotheticalTag + ErdosInverseHits ErdosInverseTail +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def commonSurvivors (J : ℕ) (w : ℝ) (a : ℕ → ℕ) (r : ℚ) + (qf p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : Finset ℕ := + ProgressionSmallSieve.progressionSurvivors J ⌊w⌋₊ (effectiveBase a r qf p hHp) (p*qf) a + +theorem effectiveSurvivors_eq_progression (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) (r : ℚ) + (qf p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : + effectiveSurvivors Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a r qf p hHp = + commonSurvivors (hitLength Y (p*qf) (effectiveBase a r qf p hHp)) w a r qf p hHp := by + ext j + simp only [effectiveSurvivors,commonSurvivors,ProgressionSmallSieve.progressionSurvivors, + SievePartition.mem_survivors,Finset.mem_filter,Finset.mem_range,ProgressionSmallSieve.progressionHit] + apply and_congr_right + intro _hj + apply forall_congr' + intro t + apply forall_congr' + intro _ht + rw [← Nat.cast_mul,← Nat.cast_add,Int.natCast_modEq_iff] + rfl + +theorem mem_commonSurvivors (J : ℕ) (w : ℝ) (a : ℕ → ℕ) (r : ℚ) + (qf p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) (j : ℕ) : + j ∈ commonSurvivors J w a r qf p hHp ↔ j < J ∧ + ∀ t ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊, + (effectiveInteger a r qf p hHp (j : ℤ) : ZMod t) ≠ (a t : ZMod t) := by + simp only [commonSurvivors,ProgressionSmallSieve.progressionSurvivors,SievePartition.mem_survivors, + Finset.mem_range,ProgressionSmallSieve.progressionHit] + apply and_congr_right + intro _hj + apply forall_congr' + intro t + apply forall_congr' + intro _ht + rw [← Nat.cast_mul,← Nat.cast_add,effectiveInteger_nat_coordinate,← ZMod.intCast_eq_intCast_iff] + simp only [Int.cast_natCast] + +theorem hypothetical_count_eq_full_common_card (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) (r : ℚ) + (qf : ℕ) (hq : Squarefree qf) (p : ℕ) [NeZero p] (hp : p.Prime) + (hqp : qf.Coprime p) (hHp : (effectiveModulus a r qf).Coprime p) + (hps : p ∉ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) : + (modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) (hypotheticalClass a r p) (p*qf) : ℝ) = + ((commonSurvivors (hitLength Y (p*qf) (effectiveBase a r qf p hHp)) w a r qf p hHp).card : ℝ) := by + rw [hypothetical_count_eq_effective_card Y _ a r qf hq p hp hqp hHp hps, + effectiveSurvivors_eq_progression Y w a r qf p hHp,Int.cast_natCast] + +end ErdosVarianceCommon + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceCommon +open ErdosInverseTail ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_common_interval_slack (aStar xi : ℝ) (ha : 0 < aStar) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,2 ≤ sourceW z ∧ + ∀ (Y qf p : ℕ) (R : ℝ),0 < qf → 0 < p → 0 < R → + R < (p : ℝ) → (p : ℝ) ≤ (1+xi)*R → + 3*aStar/4 ≤ Real.log ((Y : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z) → + (sourceW z)^(5*aStar/8) ≤ (commonLength Y qf R xi : ℝ) ∧ + 3 ≤ xi*(commonLength Y qf R xi : ℝ) ∧ + (sourceW z)^(aStar/2) ≤ 2*xi*(commonLength Y qf R xi : ℝ) := by + have h8 := (tendsto_rpow_atTop (by positivity : 0 < aStar/8)).comp sourceW_tendsto_atTop + have h34 := (tendsto_rpow_atTop (by positivity : 0 < 3*aStar/4)).comp sourceW_tendsto_atTop + filter_upwards [source_common_length_regime aStar xi ha hxi hxi1, + h8.eventually_ge_atTop 4,h34.eventually_ge_atTop 4] with z hreg h8z h34z + refine ⟨hreg.1,?_⟩ + intro Y qf p R hq hp hR hpR hpU hlen + change 4 ≤ (sourceW z)^(aStar/8) at h8z + change 4 ≤ (sourceW z)^(3*aStar/4) at h34z + have hcomp := bin_upper_comparison R xi hR hxi.le p ⟨hpR,hpU⟩ + have hlen' : 3*aStar/4 ≤ Real.log ((Y : ℝ)/((qf : ℝ)*p*1))/Real.log (sourceW z) := by + simpa only [mul_one,mul_comm (qf : ℝ) (p : ℝ)] using hlen + have hsmall := hreg.2 Y qf p 1 ((1+xi)*R) hq hp Nat.zero_lt_one hcomp.1 hcomp.2 (by simpa only [Nat.cast_one] using hlen') + have hgeo := common_length_from_log Y qf p 1 hq hp Nat.zero_lt_one ((1+xi)*R) xi (sourceW z) aStar + hcomp.1 hcomp.2 hxi.le hxi1 (by linarith [hreg.1]) ha (by simpa only [Nat.cast_one] using hlen') + simp only [Nat.cast_one,div_one] at hsmall hgeo + have hlow : (sourceW z)^(3*aStar/4)/4 ≤ (commonLength Y qf R xi : ℝ) := by + change (sourceW z)^(3*aStar/4) ≤ 2*(commonLength Y qf R xi : ℝ)+2 at hgeo + nlinarith + have hW : 0 < sourceW z := by linarith [hreg.1] + have hfactor : (sourceW z)^(5*aStar/8)*(sourceW z)^(aStar/8) = (sourceW z)^(3*aStar/4) := by + rw [← Real.rpow_add hW] + congr 1 + ring + have hmul := mul_le_mul_of_nonneg_left h8z (Real.rpow_nonneg hW.le (5*aStar/8)) + refine ⟨?_,hsmall.1,hsmall.2⟩ + nlinarith + +theorem commonLength_comparable (Y qf : ℕ) (hq : 0 < qf) (R xi : ℝ) + (hR : 0 < R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) (hJ : 1 ≤ commonLength Y qf R xi) : + (Y : ℝ)/(R*(qf : ℝ))/4 ≤ (commonLength Y qf R xi : ℝ) ∧ + (commonLength Y qf R xi : ℝ) ≤ (Y : ℝ)/(R*(qf : ℝ)) := by + have hqR : (0 : ℝ) < qf := by exact_mod_cast hq + have hF : 0 < 1+xi := by linarith + have hA : 0 ≤ (Y : ℝ)/((qf : ℝ)*((1+xi)*R)) := by positivity + have hfloor : (commonLength Y qf R xi : ℝ) ≤ (Y : ℝ)/((qf : ℝ)*((1+xi)*R)) := Nat.floor_le hA + have hceil : (Y : ℝ)/((qf : ℝ)*((1+xi)*R)) < (commonLength Y qf R xi : ℝ)+1 := Nat.lt_floor_add_one _ + have hJr : (1 : ℝ) ≤ commonLength Y qf R xi := by exact_mod_cast hJ + have he : (Y : ℝ)/(R*(qf : ℝ)) = (1+xi)*((Y : ℝ)/((qf : ℝ)*((1+xi)*R))) := by field_simp + constructor + · have hm := mul_le_mul_of_nonneg_left hceil.le hF.le + have hj0 : (0 : ℝ) ≤ commonLength Y qf R xi := Nat.cast_nonneg _ + nlinarith + · apply hfloor.trans + apply div_le_div_of_nonneg_left (Nat.cast_nonneg _) (by positivity) + have hm := mul_nonneg hxi (mul_pos hR hqR).le + nlinarith + +end ErdosVarianceCommon + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceCommon +open NumberTheoryLean ErdosVarianceEffective ErdosInverseCounts ErdosHypotheticalTag + ErdosInverseHits ErdosInverseTail ErdosInverseBoxHeight ErdosInverseEuler + +theorem large_prime_not_cutoff (w : ℝ) (hw : 0 ≤ w) (p : ℕ) (hwp : w < (p : ℝ)) : + p ∉ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ := by + intro hp + have hh := (LargePrimeDeletion.mem_cutoffPrimes.mp hp).2 + have hhR := (Nat.le_floor_iff hw).mp hh + linarith + +theorem effective_step_coprime_small (w : ℝ) (qf : ℕ) (hq : Squarefree qf) + (hlarge : ∀ t ∈ qf.primeFactors,w < (t : ℝ)) (p : ℕ) (hp : p.Prime) (hwp : w < (p : ℝ)) : + ∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*qf).Coprime t := by + intro t ht htw + have hqt := full_cofactor_coprime_small qf hq w hlarge t ht htw + apply Nat.Coprime.mul_left _ hqt + apply (Nat.coprime_primes hp ht).mpr + intro he + subst p + linarith + +theorem source_common_count_errors (aStar : ℝ) (ha : 0 < aStar) : + ∃ C : ℝ,0 < C ∧ ∀ xi : ℝ,0 < xi → xi ≤ 1 → + ∀ᶠ z : ℝ in atTop,2 ≤ sourceW z ∧ + ∀ (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (_hq : Squarefree qf) + (p : ℕ) [NeZero p] (_hp : p.Prime) (_hqp : qf.Coprime p) + (hHp : (effectiveModulus a r qf).Coprime p) (R : ℝ), + 0 < R → R < (p : ℝ) → (p : ℝ) ≤ (1+xi)*R → sourceW z < (p : ℝ) → + (∀ t ∈ qf.primeFactors,sourceW z < (t : ℝ)) → + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z) → + let J := commonLength (sourceY z) qf R xi + (sourceW z)^(5*aStar/8) ≤ (J : ℝ) ∧ + |(modulusCount (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) + (hypotheticalClass a r p) (p*qf) : ℝ)- + ((commonSurvivors J (sourceW z) a r qf p hHp).card : ℝ)| ≤ + 2*C*xi*commonReference J (sourceW z) ∧ + |referenceCount (sourceY z) (sourceW z) p qf-commonReference J (sourceW z)| ≤ + 2*xi*commonReference J (sourceW z) := by + obtain ⟨C,hC,w0,hw0,hupper⟩ := sieve_tail_upper (aStar/2) (by positivity) + refine ⟨C,hC,?_⟩ + intro xi hxi hxi1 + filter_upwards [source_common_interval_slack aStar xi ha hxi hxi1, + sourceW_tendsto_atTop.eventually_ge_atTop w0] with z hslack hW + refine ⟨hslack.1,?_⟩ + intro a r qf hq p instP hp hqp hHp R hR hpl hpu hwp hlarge hlen + let J := commonLength (sourceY z) qf R xi + let N := hitLength (sourceY z) (p*qf) (effectiveBase a r qf p hHp) + have hqpos := Nat.pos_of_ne_zero hq.ne_zero + have hs := hslack.2 (sourceY z) qf p R hqpos hp.pos hR hpl hpu hlen + have hwpos : 0 < sourceW z := by linarith [hslack.1] + have hV : 0 ≤ SmallSieveFinite.smallEuler ⌊sourceW z⌋₊ := + ((inv_pos.mpr hwpos).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv (sourceW z) hslack.1)).le + have hJN : J ≤ N := commonLength_le_effective (sourceY z) a r qf hq p hHp R xi hR hxi.le ⟨hpl,hpu⟩ + have htail : ((N-J : ℕ) : ℝ) ≤ 2*xi*(J : ℝ) := by + have hh := commonLength_tail_bound (sourceY z) a r qf hq p hHp R xi hR hxi.le hxi1 ⟨hpl,hpu⟩ + change ((N-J : ℕ) : ℝ) ≤ xi*(J : ℝ)+3 at hh + linarith [hs.2.1] + refine ⟨hs.1,?_,common_reference_error (sourceY z) qf p hqpos hp.pos (sourceW z) R xi hR hxi.le hxi1 hV ⟨hpl,hpu⟩ hs.2.1⟩ + rw [hypothetical_count_eq_full_common_card (sourceY z) (sourceW z) a r qf hq p hp hqp hHp + (large_prime_not_cutoff (sourceW z) hwpos.le p hwp)] + rw [commonSurvivors,commonSurvivors,survivor_count_difference J N ⌊sourceW z⌋₊ hJN] + have hh := hupper J N (sourceW z) (2*xi*(J : ℝ)) (effectiveBase a r qf p hHp) (p*qf) a + hW hs.2.2 htail (effective_step_coprime_small (sourceW z) qf hq hlarge p hp hwp) + dsimp only [commonReference] + nlinarith + +end ErdosVarianceCommon + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceCommon +open NumberTheoryLean ErdosVarianceEffective ErdosInverseCounts ErdosHypotheticalTag + ErdosInverseHits ErdosInverseTail ErdosInverseBoxHeight ErdosInverseEuler ErdosInverseAlignment + +theorem source_actual_bad_to_common (aStar eps : ℝ) (ha : 0 < aStar) (heps : 0 < eps) : + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ ∀ xi : ℝ,0 < xi → xi ≤ xi0 → + ∀ᶠ z : ℝ in atTop, + ∀ (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (_hq : Squarefree qf) + (p : ℕ) [NeZero p] (_hp : p.Prime) (_hqp : qf.Coprime p) + (hHp : (effectiveModulus a r qf).Coprime p) (R : ℝ), + 0 < R → R < (p : ℝ) → (p : ℝ) ≤ (1+xi)*R → sourceW z < (p : ℝ) → + (∀ t ∈ qf.primeFactors,sourceW z < (t : ℝ)) → + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z) → + aligns (fun t => (a t : ℤ)) r p → + eps < |(modulusCount (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a (p*qf) : ℝ)/ + referenceCount (sourceY z) (sourceW z) p qf-1| → + let J := commonLength (sourceY z) qf R xi + (sourceW z)^(5*aStar/8) ≤ (J : ℝ) ∧ + (eps/2)*commonReference J (sourceW z) < + |((commonSurvivors J (sourceW z) a r qf p hHp).card : ℝ)-commonReference J (sourceW z)| := by + obtain ⟨C,hC,herrors⟩ := source_common_count_errors aStar ha + have hden : 0 < 4*(C+1) := by positivity + refine ⟨min 1 (eps/(4*(C+1))),lt_min zero_lt_one (div_pos heps hden),min_le_left _ _,?_⟩ + intro xi hxi hxib + have hxi1 : xi ≤ 1 := hxib.trans (min_le_left _ _) + have hxiBudget := (le_div_iff₀ hden).mp (hxib.trans (min_le_right _ _)) + have hBudget : 2*C*xi+2*xi ≤ eps/2 := by nlinarith + filter_upwards [herrors xi hxi hxi1] with z hz + intro a r qf hq p instP hp hqp hHp R hR hpl hpu hwp hlarge hlen halign hbad + let J := commonLength (sourceY z) qf R xi + have herr := hz.2 a r qf hq p hp hqp hHp R hR hpl hpu hwp hlarge hlen + have hcount := herr.2.1 + rw [hypothetical_count_agrees (sourceY z) _ a r (p*qf) p hp halign] at hcount + have hW : 0 < sourceW z := by linarith [hz.1] + have hV : 0 < SmallSieveFinite.smallEuler ⌊sourceW z⌋₊ := + (inv_pos.mpr hW).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv (sourceW z) hz.1) + have hJ : (0 : ℝ) < J := (Real.rpow_pos_of_pos hW _).trans_le herr.1 + have hM : 0 < commonReference J (sourceW z) := mul_pos hJ hV + have hmu := reference_above_common (sourceY z) qf p (Nat.pos_of_ne_zero hq.ne_zero) hp.pos + (sourceW z) R xi hR hxi.le hxi1 hV.le ⟨hpl,hpu⟩ + have hmuPos : 0 < referenceCount (sourceY z) (sourceW z) p qf := hM.trans_le hmu + have hbad' := (relative_deviation_iff _ _ eps hmuPos).mp hbad + refine ⟨herr.1,?_⟩ + exact common_deviation_transfer _ _ _ _ eps (2*C*xi) (2*xi) hM.le hmu heps hcount herr.2.2 hBudget hbad' + +end ErdosVarianceCommon + +end + +section + +namespace ErdosVarianceMoments +open ErdosVarianceSmallModel ErdosVarianceEffective ErdosInverseCells ErdosPrimitiveIntercept ErdosInverseAlignment + +noncomputable def actualDivisorTarget (a : ℕ → ℕ) (qf t : ℕ) : ZMod t := + ((a t : ZMod t)-(cofactorHit qf a : ZMod t))*(qf : ZMod t)⁻¹ + +noncomputable def actualCoprimeTarget (a : ℕ → ℕ) (r : ℚ) (t : ℕ) : ZMod t := + (r.den : ZMod t)*(a t : ZMod t)-(r.num : ZMod t) + +def actualModelSurvives (w : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf j : ℕ) + (v : ModelPoint w (effectiveModulus a r qf)) : Prop := + modelSurvives w (effectiveModulus a r qf) (effectiveIntercept a r qf) + (alignedCofactor (fun t => (a t : ℤ)) r qf) (actualDivisorTarget a qf) (actualCoprimeTarget a r) j v + +noncomputable def actualModelIndicator (w : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf j : ℕ) + (v : ModelPoint w (effectiveModulus a r qf)) : ℝ := + modelIndicator w (effectiveModulus a r qf) (effectiveIntercept a r qf) + (alignedCofactor (fun t => (a t : ℤ)) r qf) (actualDivisorTarget a qf) (actualCoprimeTarget a r) j v + +theorem aligned_isolated_coprime_effective (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) (hp : p.Prime) (hqp : qf.Coprime p) (halign : aligns (fun t => (a t : ℤ)) r p) : + (effectiveModulus a r qf).Coprime p := by + have hD := ErdosAlignedProgression.aligned_den_coprime_prime a r p hp halign + have hd : badPrimeProduct (fun t => (a t : ℤ)) r qf ∣ qf := by + refine ⟨alignedCofactor (fun t => (a t : ℤ)) r qf,?_⟩ + simpa only [mul_comm] using (alignedCofactor_mul_bad (fun t => (a t : ℤ)) r qf hq).symm + exact hD.mul_left (hqp.of_dvd_left hd) + +theorem aligned_coefficient_coprime_small (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (w : ℝ) (hlarge : ∀ u ∈ qf.primeFactors,w < (u : ℝ)) (t : ℕ) (ht : t.Prime) (htw : (t : ℝ) ≤ w) : + (alignedCofactor (fun u => (a u : ℤ)) r qf).Coprime t := by + have hd : alignedCofactor (fun u => (a u : ℤ)) r qf ∣ qf := + ⟨badPrimeProduct (fun u => (a u : ℤ)) r qf,(alignedCofactor_mul_bad (fun u => (a u : ℤ)) r qf hq).symm⟩ + exact (full_cofactor_coprime_small qf hq w hlarge t ht htw).of_dvd_left hd + +end ErdosVarianceMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualOddPairLink.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualOddPairLink.lean new file mode 100644 index 0000000000000000000000000000000000000000..5dfe398c3d1cc0e6a5bc0c6c52235bd3526ca420 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualOddPairLink.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.OddPairCycleGrouping + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.CostReturnLaw + +noncomputable def oddGoodInput (v H : ℝ) : Set OddCost := returnSet ∩ ordinaryCostWindow v H + +lemma oddGoodInput_embed (v H : ℝ) (z : OddCost) : + embedOdd z ∈ regenerativeCostWindow v H ↔ z ∈ oddGoodInput v H := Iff.rfl + +lemma pairWindowContinue_apply (v H : ℝ) (z : OddCost) : + pairWindowContinue v H z=if z ∈ ordinaryCostWindow v H then pairBranchKernel false z else pairedCostKernel z := by + rw [pairWindowContinue,_root_.add_apply,stateFilter_input] + by_cases hz : z ∈ ordinaryCostWindow v H + · simp [hz] + · simp only [hz,ite_false,mem_compl_iff,not_false_eq_true,ite_true] + have he := congrArg (fun K : Kernel OddCost OddCost => K z) pairBranch_sum + rw [_root_.add_apply] at he + simpa only [add_comm] using he + +lemma oddConsecutiveContinue_apply (v H : ℝ) (z : OddCost) : + oddConsecutiveContinue v H z=if z ∈ oddGoodInput v H then pairBranchKernel false z else pairedCostKernel z := by + rw [oddConsecutiveContinue,_root_.add_apply,nonregenerationInput,stateFilter_input,regenerationInput,stateFilter_input] + by_cases hr : z ∈ returnSet + · simp only [hr,ite_true,mem_compl_iff,not_true_eq_false,ite_false,zero_add] + rw [pairWindowContinue_apply] + simp only [oddGoodInput,mem_inter_iff,hr,true_and] + · simp only [hr,ite_false,mem_compl_iff,not_false_eq_true,ite_true,add_zero] + simp only [oddGoodInput,mem_inter_iff,hr,false_and,ite_false] + +lemma consecutiveContinue_apply (v H : ℝ) (s : CostState) : + consecutiveContinue v H s=if s ∈ regenerativeCostWindow v H then + (costKernel ∘ₖ costKernel.restrict markedArrival_measurable.compl) s else (costKernel^2) s := by + ext S hS + rw [consecutiveContinue,Kernel.comp_apply' _ _ _ hS,consecutiveFirstContinue,Kernel.piecewise_apply] + by_cases hs : s ∈ regenerativeCostWindow v H + · rw [ite_eq_left hs,ite_eq_left hs,Kernel.comp_apply' _ _ _ hS] + · rw [ite_eq_right hs,ite_eq_right hs,pow_two] + exact (Kernel.comp_apply' costKernel costKernel s hS).symm + +lemma false_arrival_restriction : + costKernel.restrict (firstArrivalMark_measurable (measurableSet_singleton false))= + costKernel.restrict markedArrival_measurable.compl := by + ext s S hS + rw [Kernel.restrict_apply' _ _ _ hS,Kernel.restrict_apply' _ _ _ hS] + change costKernel s (S ∩ {y | firstArrivalMark y=false})=costKernel s (S ∩ markedArrivalᶜ) + rw [false_arrival_set] + +theorem oddConsecutiveContinue_embed (v H : ℝ) (z : OddCost) : + (oddConsecutiveContinue v H z).map embedOdd=consecutiveContinue v H (embedOdd z) := by + rw [oddConsecutiveContinue_apply,consecutiveContinue_apply] + by_cases hz : z ∈ oddGoodInput v H + · rw [ite_eq_left hz,ite_eq_left ((oddGoodInput_embed v H z).mpr hz),pairBranch_full_projection,false_arrival_restriction] + · rw [ite_eq_right hz,ite_eq_right (fun h => hz ((oddGoodInput_embed v H z).mp h))] + exact pairedCost_full_grouping z + +lemma oddConsecutiveCapture_mass (v H : ℝ) (z : OddCost) : + oddConsecutiveCapture v H z univ=if z ∈ oddGoodInput v H then nextMarkWeight z else 0 := by + rw [oddConsecutiveCapture,regenerationInput,stateFilter_input] + by_cases hr : z ∈ returnSet + · rw [ite_eq_left hr,ordinaryWindowCapture_mass] + simp only [oddGoodInput,mem_inter_iff,hr,true_and] + · rw [ite_eq_right hr] + simp [oddGoodInput,hr] + +lemma consecutiveCapture_mass (v H : ℝ) (s : CostState) : + consecutiveCapture v H s univ=if s ∈ regenerativeCostWindow v H then costKernel s markedArrival else 0 := by + rw [consecutiveCapture,stateFilter_input] + split_ifs + · rw [Kernel.restrict_apply' _ _ _ MeasurableSet.univ,univ_inter] + · rfl + +theorem oddConsecutiveCapture_mass_embed (v H : ℝ) (z : OddCost) : + oddConsecutiveCapture v H z univ=consecutiveCapture v H (embedOdd z) univ := by + rw [oddConsecutiveCapture_mass,consecutiveCapture_mass] + by_cases hz : z ∈ oddGoodInput v H + · rw [ite_eq_left hz,ite_eq_left ((oddGoodInput_embed v H z).mpr hz),nextMarkWeight_pair_mass,pairBranch_marked_first_mass] + · rw [ite_eq_right hz,ite_eq_right (fun h => hz ((oddGoodInput_embed v H z).mp h))] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualPatternClass.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualPatternClass.lean new file mode 100644 index 0000000000000000000000000000000000000000..63f33e86ee9c5d6c2de105c5fff8c66d90544796 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualPatternClass.lean @@ -0,0 +1,113 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SmallModelSourceScales + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceSmallModel +open ErdosHyperbolaError + +noncomputable def coordinateUnit (w : ℝ) (H : ℕ) (m : ℤ) (hm : m.natAbs.Coprime H) : + (ZMod (H*divisorModulus w H))ˣ := + ZMod.unitOfIsCoprime m (by + have hgm : Int.gcd m (H : ℤ) = 1 := by + simpa only [Int.gcd_def,Int.natAbs_natCast] using hm.gcd_eq_one + have hh := source_product_coprime H (divisorModulus w H) (divisorModulus_dvd_H w H) m 0 hgm + simpa only [mul_zero,add_zero] using hh) + +noncomputable def liftedNumeratorUnit (w : ℝ) (H : ℕ) (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (k : ZMod (divisorModulus w H)) : + (ZMod (H*divisorModulus w H))ˣ := + ZMod.unitOfIsCoprime (C0+(H : ℤ)*(k.val : ℤ)) + (source_product_coprime H (divisorModulus w H) (divisorModulus_dvd_H w H) C0 k.val hC0) + +noncomputable def restrictionUnit (w : ℝ) (H : ℕ) (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (m : ℤ) (hm : m.natAbs.Coprime H) + (k : ZMod (divisorModulus w H)) : (ZMod (H*divisorModulus w H))ˣ := + liftedNumeratorUnit w H C0 hC0 k*(coordinateUnit w H m hm)⁻¹ + +noncomputable def patternClass (w : ℝ) (H : ℕ) [NeZero H] (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (m : ℤ) (hm : m.natAbs.Coprime H) (s : Pattern w H) : ℕ := + (Nat.chineseRemainder (effective_pattern_coprime w H) + (restrictionUnit w H C0 hC0 m hm s.2).val.val s.1.val.val).val + +theorem patternClass_components (w : ℝ) (H : ℕ) [NeZero H] (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (m : ℤ) (hm : m.natAbs.Coprime H) (s : Pattern w H) : + Nat.ModEq (H*divisorModulus w H) (patternClass w H C0 hC0 m hm s) + (restrictionUnit w H C0 hC0 m hm s.2).val.val ∧ + Nat.ModEq (coprimeModulus w H) (patternClass w H C0 hC0 m hm s) s.1.val.val := + (Nat.chineseRemainder (effective_pattern_coprime w H) + (restrictionUnit w H C0 hC0 m hm s.2).val.val s.1.val.val).property + +theorem patternClass_coprime (w : ℝ) (H : ℕ) [NeZero H] (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (m : ℤ) (hm : m.natAbs.Coprime H) (s : Pattern w H) : + (patternClass w H C0 hC0 m hm s).Coprime (H*divisorModulus w H*coprimeModulus w H) := by + have hh := patternClass_components w H C0 hC0 m hm s + have h0 : (patternClass w H C0 hC0 m hm s).Coprime (H*divisorModulus w H) := by + apply (ZMod.isUnit_iff_coprime _ _).mp + rw [(ZMod.natCast_eq_natCast_iff _ _ _).mpr hh.1,ZMod.natCast_zmod_val] + exact (restrictionUnit w H C0 hC0 m hm s.2).isUnit + have h1 : (patternClass w H C0 hC0 m hm s).Coprime (coprimeModulus w H) := by + apply (ZMod.isUnit_iff_coprime _ _).mp + rw [(ZMod.natCast_eq_natCast_iff _ _ _).mpr hh.2,ZMod.natCast_zmod_val] + exact s.1.isUnit + exact h0.mul_right h1 + +end ErdosVarianceSmallModel + +end + +section + +namespace ErdosVarianceSmallModel + +theorem actual_pattern_class (w : ℝ) (H : ℕ) [NeZero H] (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (m : ℤ) (hm : m.natAbs.Coprime H) + (s : Pattern w H) (p k : ℕ) + (hEquation : (p : ℤ)*m = C0+(H : ℤ)*(k : ℤ)) + (hp1 : (p : ZMod (coprimeModulus w H)) = (s.1 : ZMod (coprimeModulus w H))) + (hk0 : (k : ZMod (divisorModulus w H)) = s.2) : + Int.ModEq ((H*divisorModulus w H*coprimeModulus w H : ℕ) : ℤ) + (p : ℤ) (patternClass w H C0 hC0 m hm s : ℤ) := by + have hkNat : Nat.ModEq (divisorModulus w H) k s.2.val := by + apply (ZMod.natCast_eq_natCast_iff _ _ _).mp + rw [ZMod.natCast_zmod_val] + exact hk0 + have hkInt := Int.natCast_modEq_iff.mpr hkNat + have hlift : Int.ModEq ((H : ℤ)*(divisorModulus w H : ℤ)) + ((H : ℤ)*(k : ℤ)) ((H : ℤ)*(s.2.val : ℤ)) := hkInt.mul_left' + have hpm : Int.ModEq ((H*divisorModulus w H : ℕ) : ℤ) ((p : ℤ)*m) + (C0+(H : ℤ)*(s.2.val : ℤ)) := by + simpa only [Nat.cast_mul,← hEquation] using hlift.add_left C0 + have hpmZ : (p : ZMod (H*divisorModulus w H))*(m : ZMod (H*divisorModulus w H)) = + (liftedNumeratorUnit w H C0 hC0 s.2 : ZMod (H*divisorModulus w H)) := by + simpa only [liftedNumeratorUnit,ZMod.coe_unitOfIsCoprime,Int.cast_mul,Int.cast_natCast] using + (ZMod.intCast_eq_intCast_iff _ _ _).mpr hpm + have hminv : (m : ZMod (H*divisorModulus w H))* + (↑((coordinateUnit w H m hm)⁻¹) : ZMod (H*divisorModulus w H)) = 1 := by + simpa only [coordinateUnit,ZMod.coe_unitOfIsCoprime] using (coordinateUnit w H m hm).mul_inv + have hmul := congrArg (fun x : ZMod (H*divisorModulus w H) => + x*(↑((coordinateUnit w H m hm)⁻¹) : ZMod (H*divisorModulus w H))) hpmZ + have hpUnit : (p : ZMod (H*divisorModulus w H)) = + (restrictionUnit w H C0 hC0 m hm s.2 : ZMod (H*divisorModulus w H)) := by + simpa only [mul_assoc,hminv,mul_one,restrictionUnit,Units.val_mul] using hmul + have hp0 : Nat.ModEq (H*divisorModulus w H) p (restrictionUnit w H C0 hC0 m hm s.2).val.val := by + apply (ZMod.natCast_eq_natCast_iff _ _ _).mp + rw [ZMod.natCast_zmod_val] + exact hpUnit + have hp1' : Nat.ModEq (coprimeModulus w H) p s.1.val.val := by + apply (ZMod.natCast_eq_natCast_iff _ _ _).mp + rw [ZMod.natCast_zmod_val] + exact hp1 + exact Int.natCast_modEq_iff.mpr (Nat.chineseRemainder_modEq_unique (effective_pattern_coprime w H) hp0 hp1') + +end ErdosVarianceSmallModel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualPointSlopes.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualPointSlopes.lean new file mode 100644 index 0000000000000000000000000000000000000000..0eb3bdb0f25d542f17a4eae716b8be0144014803 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualPointSlopes.lean @@ -0,0 +1,693 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Estimates.SourceExtensionScale +import OAI.NumberTheory.Jacobsthal.Partitions.EdgeBinBounds +import OAI.NumberTheory.Jacobsthal.Partitions.SourceIntervalReplacement +import OAI.NumberTheory.Jacobsthal.Primes.SourcePrimeSampleBound +import OAI.NumberTheory.Jacobsthal.Sieve.CRTPrimeCost +import OAI.NumberTheory.Jacobsthal.Sieve.FrozenSieveMean +import OAI.NumberTheory.Jacobsthal.Sieve.OriginalCofactorPoints + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseSaving + +theorem mean_envelope (N Q n : ℕ) (hN : 0 < N) (w U K xi delta C V : ℝ) + (hw : 1 < w) (hU : 1 < U) (hK : 0 ≤ K) (hxi : 0 < xi) (hd : 0 < delta) + (hC : 0 ≤ C) (hV : 0 < V) + (hcount : xi*U/(16*Real.log U) ≤ (n : ℝ)) + (hEuler : V⁻¹ ≤ 2*Real.exp Real.eulerMascheroniConstant*Real.log w) + (hQ : (Q : ℝ) ≤ 3*U) (hlogU : Real.log U ≤ K*Real.log w) : + (4+8*Real.pi^2)*C*((N : ℝ)+(Q : ℝ)^2)/((n : ℝ)*delta^2*(N : ℝ)*V) ≤ + (32*(4+8*Real.pi^2)*C*K*Real.exp Real.eulerMascheroniConstant/(xi*delta^2))*(Real.log w)^2* + (1/U+9*U/(N : ℝ)) := by + have hNpos : (0 : ℝ) < N := by exact_mod_cast hN + have hUpos : 0 < U := by linarith + have hlogw : 0 < Real.log w := Real.log_pos hw + have hlogUpos : 0 < Real.log U := Real.log_pos hU + have hlo : 0 < xi*U/(16*Real.log U) := by positivity + have hn : (0 : ℝ) < n := hlo.trans_le hcount + have hni : (n : ℝ)⁻¹ ≤ 16*Real.log U/(xi*U) := by + have hh := (inv_le_inv₀ hn hlo).mpr hcount + simpa only [inv_div] using hh + have hnK : (n : ℝ)⁻¹ ≤ 16*K*Real.log w/(xi*U) := by + apply hni.trans + apply div_le_div_of_nonneg_right _ (mul_pos hxi hUpos).le + nlinarith + have hQsq : (Q : ℝ)^2 ≤ 9*U^2 := by nlinarith [show (0 : ℝ) ≤ Q from Nat.cast_nonneg Q] + calc + _ = ((4+8*Real.pi^2)*C/delta^2)*(((N : ℝ)+(Q : ℝ)^2)/(N : ℝ))*(n : ℝ)⁻¹*V⁻¹ := by + simp only [div_eq_mul_inv,mul_inv_rev] + ring + _ ≤ ((4+8*Real.pi^2)*C/delta^2)*(((N : ℝ)+9*U^2)/(N : ℝ))* + (16*K*Real.log w/(xi*U))*(2*Real.exp Real.eulerMascheroniConstant*Real.log w) := by + gcongr + _ = _ := by + simp only [div_eq_mul_inv,mul_inv_rev] + field_simp + ring + +theorem spectral_factor_bound (N : ℕ) (hN : 0 < N) (U rho : ℝ) (_hU : 0 < U) + (hrho : 0 < rho) (hrhoU : rho ≤ U) (hNlower : U*rho/4 ≤ (N : ℝ)) : + 1/U+9*U/(N : ℝ) ≤ 37/rho := by + have hNR : (0 : ℝ) < N := by exact_mod_cast hN + have h1 : 1/U ≤ 1/rho := one_div_le_one_div_of_le hrho hrhoU + have h2 : U/(N : ℝ) ≤ 4/rho := by + apply (div_le_div_iff₀ hNR hrho).mpr + nlinarith + calc + _ = 1/U+9*(U/(N : ℝ)) := by ring + _ ≤ 1/rho+9*(4/rho) := add_le_add h1 (mul_le_mul_of_nonneg_left h2 (by norm_num)) + _ = _ := by ring + +end ErdosInverseSaving + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSaving + +theorem log_square_absorption (A eps : ℝ) (hA : 0 ≤ A) (heps : 0 < eps) : + ∀ᶠ w : ℝ in atTop,A*(Real.log w)^2 ≤ w^eps := by + have hA1 : 0 < A+1 := by linarith + have hs := (isLittleO_log_rpow_rpow_atTop (2 : ℝ) heps).bound (inv_pos.mpr hA1) + filter_upwards [hs,eventually_gt_atTop (1 : ℝ)] with w hw hw1 + have hw0 : 0 < w := by linarith + have hh : (Real.log w)^2 ≤ (A+1)⁻¹*w^eps := by + simpa only [Real.norm_eq_abs,Real.rpow_two,abs_of_nonneg (sq_nonneg (Real.log w)), + abs_of_nonneg (Real.rpow_nonneg hw0.le eps)] using hw + have hp := mul_le_mul_of_nonneg_left hh hA1.le + have hcancel : (A+1)*((A+1)⁻¹*w^eps) = w^eps := by field_simp + rw [hcancel] at hp + nlinarith [sq_nonneg (Real.log w)] + +end ErdosInverseSaving + +end + +section + +namespace ErdosInverseSaving +open ErdosInverseTail ErdosInversePrimeBin + +theorem common_length_bin_lower (Y p q : ℕ) (hp : 0 < p) (hq : 0 < q) + (Qplus xi w aStar U theta : ℝ) (hqQ : (q : ℝ) ≤ Qplus) + (hQq : Qplus ≤ (1+xi)*(q : ℝ)) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hw : 1 < w) (ha : 0 < aStar) (hwU : w ≤ U) (htheta : 0 ≤ theta) + (hlarge : 4 ≤ w^(3*aStar/4)) (hne : (primeBin U theta).Nonempty) + (hlen : ∀ u ∈ primeBin U theta, + 3*aStar/4 ≤ Real.log ((Y : ℝ)/((p : ℝ)*q*u))/Real.log w) : + U*w^(3*aStar/4)/4 ≤ (commonParentLength Y p Qplus : ℝ) := by + obtain ⟨u,hu⟩ := hne + have hUpos : 0 < U := (by linarith : 0 < w).trans_le hwU + have humem := (mem_primeBin hUpos.le htheta u).mp hu + have huR : (0 : ℝ) < u := hUpos.trans humem.2.1 + have hgeo := common_length_from_log Y p q u hp hq humem.1.pos Qplus xi w aStar hqQ hQq + hxi hxi1 hw ha (hlen u hu) + rw [mul_div_assoc (2 : ℝ) (commonParentLength Y p Qplus : ℝ) (u : ℝ)] at hgeo + have hlow : w^(3*aStar/4)/4 ≤ (commonParentLength Y p Qplus : ℝ)/(u : ℝ) := by nlinarith + have hprod := (le_div_iff₀ huR).mp hlow + have hpow : 0 ≤ w^(3*aStar/4)/4 := by positivity + calc + _ = (w^(3*aStar/4)/4)*U := by ring + _ ≤ (w^(3*aStar/4)/4)*(u : ℝ) := mul_le_mul_of_nonneg_left humem.2.1.le hpow + _ ≤ _ := hprod + +end ErdosInverseSaving + +end + +section + +namespace ErdosInverseSampleCost +open ErdosInverseSampling +attribute [local instance] Classical.decEq + +noncomputable def totalCost (P U : Finset ℕ) (h M0 : ℕ) [NeZero M0] + (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) (s : Sample U h) : ℝ := + (∑ p ∈ P,primeCost U h M0 E p s)/(P.card : ℝ) + +theorem totalCost_nonneg (P U : Finset ℕ) (h M0 : ℕ) [NeZero M0] + (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) (s : Sample U h) : + 0 ≤ totalCost P U h M0 E s := by + exact div_nonneg (Finset.sum_nonneg (fun p _ => primeCost_nonneg U h M0 E p s)) (Nat.cast_nonneg _) + +theorem totalCost_average_bound (P U : Finset ℕ) (h M0 : ℕ) [NeZero M0] + (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) (R tau T : ℝ) + (hP : 0 < P.card) (hU : 0 < U.card) (hh : h ≤ U.card) (htau : 0 ≤ tau) + (hPref : (U.card : ℝ)^h/(U.card.descFactorial h : ℝ) ≤ 2) + (hMean : ∀ p ∈ P,∀ v : ZMod M0, + (∑ u : U,((E p v u).card : ℝ)/(u.val : ℝ))/(U.card : ℝ) ≤ tau) + (hR : ∀ p ∈ P,(p : ℝ) ≤ 2*R) (hCap : ∀ u : U,(u.val : ℝ) ≤ T) : + sampleAverage U h (totalCost P U h M0 E) ≤ 4*R*tau^h+(M0 : ℝ)*T^h := by + have hPnz : (P.card : ℝ) ≠ 0 := by exact_mod_cast hP.ne' + unfold totalCost + rw [sampleAverage_div,sampleAverage_sum] + calc + _ ≤ (∑ p ∈ P,(2*(p : ℝ)*tau^h+(M0 : ℝ)*T^h))/(P.card : ℝ) := + div_le_div_of_nonneg_right (Finset.sum_le_sum (fun p hp => + primeCost_average_bound U h M0 E p tau T hU hh hPref (hMean p hp) hCap)) (Nat.cast_nonneg _) + _ ≤ (∑ _p ∈ P,(4*R*tau^h+(M0 : ℝ)*T^h))/(P.card : ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + apply Finset.sum_le_sum + intro p hp + have hh := mul_le_mul_of_nonneg_right (hR p hp) (pow_nonneg htau h) + nlinarith + _ = _ := by + simp only [Finset.sum_const,nsmul_eq_mul] + field_simp + +end ErdosInverseSampleCost + +end + +section + +namespace ErdosInverseSampleCost +open ErdosInverseSampling ErdosInverseCRT +attribute [local instance] Classical.decEq + +theorem slopes_card_le_primeCost (U : Finset ℕ) (hU : ∀ u ∈ U,u.Prime) + (h M0 : ℕ) [NeZero M0] (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) + (s : Sample U h) (p q0 : ℕ) (hp : ∀ u ∈ U,p.Coprime u) (hq : ∀ u ∈ U,q0.Coprime u) + (h0 : ∀ u ∈ U,M0.Coprime u) (a : ℕ → ℤ) (b0 : ℤ) : + ((sourceTestedSlopes p q0 M0 (fun i => (s i).val) + (fun i => hp _ (s i).property) (fun i => hq _ (s i).property) a b0 + (fun v i => E p v (s i))).card : ℝ) ≤ primeCost U h M0 E p s := by + have hh := distinct_prime_sample_slope_bound U hU h s p q0 M0 hp hq h0 a b0 (fun v i => E p v (s i)) + simpa only [primeCost,Nat.cast_prod] using hh + +theorem slopes_sum_le_totalCost (P U : Finset ℕ) (hU : ∀ u ∈ U,u.Prime) + (h M0 : ℕ) [NeZero M0] (E : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val)) + (s : Sample U h) (hP : 0 < P.card) (hp : ∀ p ∈ P,∀ u ∈ U,p.Coprime u) + (h0 : ∀ u ∈ U,M0.Coprime u) (q0 : ℕ) (hq : ∀ u ∈ U,q0.Coprime u) + (a : ℕ → ℤ) (b0 : ℤ) : + (∑ p : P,((sourceTestedSlopes p.val q0 M0 (fun i => (s i).val) + (fun i => hp p.val p.property _ (s i).property) (fun i => hq _ (s i).property) a b0 + (fun v i => E p.val v (s i))).card : ℝ)) ≤ + (P.card : ℝ)*totalCost P U h M0 E s := by + have hPnz : (P.card : ℝ) ≠ 0 := by exact_mod_cast hP.ne' + calc + _ ≤ ∑ p : P,primeCost U h M0 E p.val s := + Finset.sum_le_sum (fun p _ => slopes_card_le_primeCost U hU h M0 E s p.val q0 + (hp p.val p.property) hq h0 a b0) + _ = ∑ p ∈ P,primeCost U h M0 E p s := Finset.sum_coe_sort P (fun p : ℕ => primeCost U h M0 E p s) + _ = _ := by unfold totalCost;field_simp + +end ErdosInverseSampleCost + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSaving +open NumberTheoryLean ErdosInversePrimeBin ErdosInverseFrozen ErdosInverseEuler + +noncomputable def frozenPrimeMean (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) + (delta U theta : ℝ) : ℝ := + (∑ u ∈ primeBin U theta,((frozenExceptional N w p q b v a u delta + (SmallSieveFinite.smallEuler ⌊w⌋₊)).card : ℝ)/(u : ℝ))/((primeBin U theta).card : ℝ) + +noncomputable def meanCoefficient (C K xi delta : ℝ) : ℝ := + 32*(4+8*Real.pi^2)*C*K*Real.exp Real.eulerMascheroniConstant/(xi*delta^2) + +theorem actual_mean_envelope (eta : ℝ) (heta : 0 < eta) : + ∃ C : ℝ,0 < C ∧ ∀ xi K delta : ℝ,0 < xi → xi ≤ 1 → 0 ≤ K → 0 < delta → + ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ ∀ (N : ℕ) (p q : ℕ) (b v : ℤ) (a : ℕ → ℕ) (U theta : ℝ), + w ≤ U → U ≤ w^K → xi/4 ≤ theta → theta ≤ xi → w^eta ≤ (N : ℝ) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*q).Coprime t) → + frozenPrimeMean N w p q b v a delta U theta ≤ + meanCoefficient C K xi delta*(Real.log w)^2*(1/U+9*U/(N : ℝ)) := by + obtain ⟨C,hC,w0,_hw0,hmean⟩ := frozen_exceptional_mean eta heta + refine ⟨C,hC,?_⟩ + intro xi K delta hxi hxi1 hK hd + filter_upwards [eventually_ge_atTop w0,uniform_edge_bin_count xi hxi hxi1,smallEuler_log_bounds] + with w hw hb hEuler + refine ⟨hb.1,?_⟩ + intro N p q b v a U theta hwU hUmax htlow hthigh hN hcop + have hwpos : 0 < w := by linarith [hb.1] + have hUpos : 0 < U := hwpos.trans_le hwU + have hU2 : 2 ≤ U := hb.1.trans hwU + have htpos : 0 ≤ theta := (by positivity : (0 : ℝ) ≤ xi/4).trans htlow + have ht1 : theta ≤ 1 := hthigh.trans hxi1 + have hNpos : 0 < N := by exact_mod_cast (Real.rpow_pos_of_pos hwpos eta).trans_le hN + have hlogU : Real.log U ≤ K*Real.log w := by + have hh := Real.log_le_log hUpos hUmax + rwa [Real.log_rpow hwpos] at hh + have hbin := hb.2 U theta hwU htlow hthigh + have hprimes : ∀ u ∈ primeBin U theta,u.Prime := fun u hu => ((mem_primeBin hUpos.le htpos u).mp hu).1 + have hcapped : ∀ u ∈ primeBin U theta,u ≤ edgeFrequencyCap U := + edge_prime_le_cap U theta hUpos.le htpos ht1 + have hspec := hmean N (edgeFrequencyCap U) w p q b v a (primeBin U theta) delta + hw hN hcop hprimes hcapped hbin.2 hd + exact hspec.trans (mean_envelope N (edgeFrequencyCap U) (primeBin U theta).card hNpos + w U K xi delta C (SmallSieveFinite.smallEuler ⌊w⌋₊) (by linarith [hb.1]) (by linarith) + hK hxi hd hC.le hEuler.2.1 hbin.1 hEuler.2.2.2 (edgeFrequencyCap_le U (by linarith)) hlogU) + +end ErdosInverseSaving + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSaving +open NumberTheoryLean ErdosInversePrimeBin ErdosInverseFrozen ErdosInverseEuler ErdosInverseTail + +theorem uniform_mean_power (aStar K xi delta : ℝ) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (hK : 0 ≤ K) (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hd : 0 < delta) : + ∀ᶠ w : ℝ in atTop,4 ≤ w ∧ + ∀ (Y p q q0 : ℕ) (Qplus U theta : ℝ) (b v : ℤ) (a : ℕ → ℕ), + 0 < p → 0 < q → (q : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q : ℝ) → + w ≤ U → U ≤ w^K → xi/4 ≤ theta → theta ≤ xi → + Int.ModEq (smallModulus w : ℤ) (q : ℤ) (q0 : ℤ) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*q).Coprime t) → + (∀ u ∈ primeBin U theta, + 3*aStar/4 ≤ Real.log ((Y : ℝ)/((p : ℝ)*q*u))/Real.log w) → + frozenPrimeMean (commonParentLength Y p Qplus) w p q0 b v a delta U theta ≤ w^(-aStar/2) := by + obtain ⟨C,hC,hmean⟩ := actual_mean_envelope (aStar/2) (by positivity) + have hA : 0 ≤ meanCoefficient C K xi delta := by unfold meanCoefficient;positivity + filter_upwards [hmean xi K delta hxi hxi1 hK hd,uniform_edge_bin_count xi hxi hxi1, + log_square_absorption (37*meanCoefficient C K xi delta) (aStar/4) (by positivity) (by positivity), + eventually_ge_atTop (4 : ℝ),(tendsto_rpow_atTop (by linarith : 0 < 3*aStar/4)).eventually_ge_atTop 4] + with w hm hb habs hw hlarge + refine ⟨hw,?_⟩ + intro Y p q q0 Qplus U theta b v a hp hq hqQ hQq hwU hUmax htlow hthigh hqq hcop hlog + have hwpos : 0 < w := by linarith + have hw1 : 1 ≤ w := by linarith + have hUpos : 0 < U := hwpos.trans_le hwU + have htpos : 0 ≤ theta := (by positivity : (0 : ℝ) ≤ xi/4).trans htlow + have hcard := (hb.2 U theta hwU htlow hthigh).2 + have hNlower := common_length_bin_lower Y p q hp hq Qplus xi w aStar U theta hqQ hQq + hxi.le hxi1 (by linarith) ha hwU htpos hlarge (Finset.card_pos.mp hcard) hlog + have hrho : 0 < w^(3*aStar/4) := Real.rpow_pos_of_pos hwpos _ + have hNpos : 0 < commonParentLength Y p Qplus := by + exact_mod_cast (div_pos (mul_pos hUpos hrho) (by norm_num : (0 : ℝ) < 4)).trans_le hNlower + have hrhoN : w^(3*aStar/4) ≤ (commonParentLength Y p Qplus : ℝ) := by + have hh := mul_le_mul_of_nonneg_right (hw.trans hwU) hrho.le + nlinarith + have hEta : w^(aStar/2) ≤ (commonParentLength Y p Qplus : ℝ) := + (Real.rpow_le_rpow_of_exponent_le hw1 (by linarith : aStar/2 ≤ 3*aStar/4)).trans hrhoN + have hrhoU : w^(3*aStar/4) ≤ U := by + have hh := Real.rpow_le_rpow_of_exponent_le hw1 (show 3*aStar/4 ≤ 1 by linarith) + have hwr : w^(3*aStar/4) ≤ w := by simpa only [Real.rpow_one] using hh + exact hwr.trans hwU + have hcenter : ∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*q0).Coprime t := + fun t ht htw => center_step_coprime w p q q0 t ht htw hqq (hcop t ht htw) + have hEnv := hm.2 (commonParentLength Y p Qplus) p q0 b v a U theta hwU hUmax htlow hthigh hEta hcenter + have hFactor := spectral_factor_bound (commonParentLength Y p Qplus) hNpos U (w^(3*aStar/4)) + hUpos hrho hrhoU hNlower + calc + _ ≤ meanCoefficient C K xi delta*(Real.log w)^2*(1/U+9*U/(commonParentLength Y p Qplus : ℝ)) := hEnv + _ ≤ meanCoefficient C K xi delta*(Real.log w)^2*(37/w^(3*aStar/4)) := + mul_le_mul_of_nonneg_left hFactor (mul_nonneg hA (sq_nonneg _)) + _ = (37*meanCoefficient C K xi delta*(Real.log w)^2)/w^(3*aStar/4) := by ring + _ ≤ w^(aStar/4)/w^(3*aStar/4) := div_le_div_of_nonneg_right habs hrho.le + _ = w^(-aStar/2) := by + rw [← Real.rpow_sub hwpos] + congr 1 + ring + +end ErdosInverseSaving + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSaving +open ErdosInverseBoxHeight ErdosInverseEuler ErdosInversePrimeBin ErdosInverseTail + +theorem source_mean_power (aStar K xi delta : ℝ) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (hK : 0 ≤ K) (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hd : 0 < delta) : + ∀ᶠ z : ℝ in atTop,4 ≤ sourceW z ∧ + ∀ (p q q0 : ℕ) (Qplus U theta : ℝ) (b v : ℤ) (a : ℕ → ℕ), + 0 < p → 0 < q → (q : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q : ℝ) → + sourceW z ≤ U → U ≤ (sourceW z)^K → xi/4 ≤ theta → theta ≤ xi → + Int.ModEq (smallModulus (sourceW z) : ℤ) (q : ℤ) (q0 : ℤ) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q).Coprime t) → + (∀ u ∈ primeBin U theta, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z)) → + frozenPrimeMean (commonParentLength (sourceY z) p Qplus) (sourceW z) p q0 b v a delta U theta ≤ + (sourceW z)^(-aStar/2) := by + filter_upwards [sourceW_tendsto_atTop.eventually (uniform_mean_power aStar K xi delta ha ha1 hK hxi hxi1 hd)] with z hz + exact ⟨hz.1,hz.2 (sourceY z)⟩ + +end ErdosInverseSaving + +end + +section + +namespace ErdosInverseSampleCost +open NumberTheoryLean ErdosInverseSampling ErdosInverseSaving ErdosInverseFrozen ErdosInverseTail ErdosInverseEuler ErdosInversePrimeBin +attribute [local instance] Classical.decEq + +noncomputable def actualFamily (Y : ℕ) (w Qplus : ℝ) (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ) + (delta : ℝ) (U : Finset ℕ) (M0 : ℕ) : ℕ → ZMod M0 → ∀ u : U,Finset (ZMod u.val) := + fun p v u => frozenExceptional (commonParentLength Y p Qplus) w p q0 b0 (v.val : ℤ) a u.val delta + (SmallSieveFinite.smallEuler ⌊w⌋₊) + +theorem actual_family_mean_eq (Y : ℕ) (w Qplus : ℝ) (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ) + (delta U theta : ℝ) (M0 p : ℕ) (v : ZMod M0) : + (∑ u : primeBin U theta,((actualFamily Y w Qplus q0 b0 a delta (primeBin U theta) M0 p v u).card : ℝ)/(u.val : ℝ))/ + ((primeBin U theta).card : ℝ) = + frozenPrimeMean (commonParentLength Y p Qplus) w p q0 b0 (v.val : ℤ) a delta U theta := by + unfold actualFamily frozenPrimeMean + rw [Finset.sum_coe_sort (primeBin U theta) (fun u : ℕ => + ((frozenExceptional (commonParentLength Y p Qplus) w p q0 b0 (v.val : ℤ) a u delta + (SmallSieveFinite.smallEuler ⌊w⌋₊)).card : ℝ)/(u : ℝ))] + +noncomputable def actualCost (Y : ℕ) (w Qplus R : ℝ) (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ) + (delta : ℝ) (P U : Finset ℕ) (h : ℕ) (s : Sample U h) : ℝ := by + letI : NeZero (smallModulus w) := ⟨(smallModulus_pos w).ne'⟩ + exact totalCost P U h (smallModulus w) (actualFamily Y w Qplus q0 b0 a delta U (smallModulus w)) s/R + +theorem actualCost_nonneg (Y : ℕ) (w Qplus R : ℝ) (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ) + (delta : ℝ) (P U : Finset ℕ) (h : ℕ) (s : Sample U h) (hR : 0 ≤ R) : + 0 ≤ actualCost Y w Qplus R q0 b0 a delta P U h s := by + let : NeZero (smallModulus w) := ⟨(smallModulus_pos w).ne'⟩ + unfold actualCost + exact div_nonneg (totalCost_nonneg P U h _ _ s) hR + +theorem actualCost_average_bound (Y : ℕ) (w Qplus R : ℝ) (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ) + (delta : ℝ) (P U : Finset ℕ) (h : ℕ) (tau T : ℝ) (hR0 : 0 ≤ R) + (hP : 0 < P.card) (hU : 0 < U.card) (hh : h ≤ U.card) (htau : 0 ≤ tau) + (hPref : (U.card : ℝ)^h/(U.card.descFactorial h : ℝ) ≤ 2) + (hMean : ∀ p ∈ P,∀ v : ZMod (smallModulus w), + (∑ u : U,((actualFamily Y w Qplus q0 b0 a delta U (smallModulus w) p v u).card : ℝ)/(u.val : ℝ))/(U.card : ℝ) ≤ tau) + (hR : ∀ p ∈ P,(p : ℝ) ≤ 2*R) (hCap : ∀ u : U,(u.val : ℝ) ≤ T) : + sampleAverage U h (actualCost Y w Qplus R q0 b0 a delta P U h) ≤ + (4*R*tau^h+(smallModulus w : ℝ)*T^h)/R := by + let : NeZero (smallModulus w) := ⟨(smallModulus_pos w).ne'⟩ + unfold actualCost + rw [sampleAverage_div] + exact div_le_div_of_nonneg_right (totalCost_average_bound P U h _ _ R tau T + hP hU hh htau hPref hMean hR hCap) hR0 + +end ErdosInverseSampleCost + +end + +section + +namespace ErdosInverseSampleCost +open NumberTheoryLean ErdosInverseSampling ErdosInverseCRT ErdosInverseEuler +attribute [local instance] Classical.decEq + +theorem smallModulus_coprime_largePrime (w : ℝ) (hw : 0 ≤ w) (u : ℕ) + (hu : u.Prime) (hwu : w < (u : ℝ)) : (smallModulus w).Coprime u := by + unfold smallModulus IntervalBoundingSieve.cutoffProduct + apply Nat.coprime_prod_left_iff.mpr + intro p hp + have hh := LargePrimeDeletion.mem_cutoffPrimes.mp hp + have hpw : (p : ℝ) ≤ w := (Nat.le_floor_iff hw).mp hh.2 + apply (Nat.coprime_primes hh.1 hu).mpr + intro he + subst p + linarith + +theorem actual_slopes_thin (Y : ℕ) (w Qplus R L : ℝ) (qInitial : ℕ) (bInitial : ℤ) + (a : ℕ → ℕ) (delta : ℝ) (P U : Finset ℕ) (h : ℕ) (s : Sample U h) + (hw : 0 ≤ w) (hR : 0 < R) (hP : 0 < P.card) (hU : ∀ u ∈ U,u.Prime) + (huLarge : ∀ u ∈ U,w < (u : ℝ)) (hp : ∀ p ∈ P,∀ u ∈ U,p.Coprime u) + (hcost : actualCost Y w Qplus R qInitial bInitial a delta P U h s ≤ 1/L^6) : + let M0 := smallModulus w + letI : NeZero M0 := ⟨(smallModulus_pos w).ne'⟩ + ∀ (qRef : ℕ) (bRef : ℤ) (hqRef : ∀ u ∈ U,qRef.Coprime u), + (∑ p : P,((sourceTestedSlopes p.val qRef M0 (fun i => (s i).val) + (fun i => hp p.val p.property _ (s i).property) (fun i => hqRef _ (s i).property) + (fun u => (a u : ℤ)) bRef + (fun v i => actualFamily Y w Qplus qInitial bInitial a delta U M0 p.val v (s i))).card : ℝ)) ≤ + (P.card : ℝ)*R/L^6 := by + let : NeZero (smallModulus w) := ⟨(smallModulus_pos w).ne'⟩ + dsimp only + intro qRef bRef hqRef + have h0 : ∀ u ∈ U,(smallModulus w).Coprime u := + fun u hu => smallModulus_coprime_largePrime w hw u (hU u hu) (huLarge u hu) + have htot : totalCost P U h (smallModulus w) + (actualFamily Y w Qplus qInitial bInitial a delta U (smallModulus w)) s ≤ R/L^6 := by + have hh := (div_le_iff₀ hR).mp hcost + calc + _ ≤ (1/L^6)*R := hh + _ = R/L^6 := by ring + calc + _ ≤ (P.card : ℝ)*totalCost P U h (smallModulus w) + (actualFamily Y w Qplus qInitial bInitial a delta U (smallModulus w)) s := + slopes_sum_le_totalCost P U hU h (smallModulus w) _ s hP hp h0 qRef hqRef (fun u => (a u : ℤ)) bRef + _ ≤ (P.card : ℝ)*(R/L^6) := mul_le_mul_of_nonneg_left htot (Nat.cast_nonneg _) + _ = _ := by ring + +end ErdosInverseSampleCost + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSampleCost +open NumberTheoryLean ErdosInverseSampling ErdosInverseSaving ErdosInversePrimeBin ErdosInverseEuler ErdosInverseBoxHeight + +theorem source_expected_cost (aStar K alpha xi delta beta : ℝ) (h : ℕ) + (ha : 0 < aStar) (ha1 : aStar ≤ 1) (hK : 0 ≤ K) (halpha : 0 < alpha) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hd : 0 < delta) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R thetaP U thetaU Qplus : ℝ,∀ (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ), + z^alpha ≤ R → sourceW z ≤ U → U ≤ (sourceW z)^K → + xi/4 ≤ thetaP → thetaP ≤ xi → xi/4 ≤ thetaU → thetaU ≤ xi → + 0 < q0 → (q0 : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q0 : ℝ) → + (∀ p ∈ primeBin R thetaP,∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q0).Coprime t) → + (∀ p ∈ primeBin R thetaP,∀ u ∈ primeBin U thetaU, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q0*u))/Real.log (sourceW z)) → + 0 < (primeBin R thetaP).card ∧ 0 < (primeBin U thetaU).card ∧ h ≤ (primeBin U thetaU).card ∧ + 4*(h : ℝ)/beta ≤ ((primeBin U thetaU).card : ℝ) ∧ + sampleAverage (primeBin U thetaU) h + (actualCost (sourceY z) (sourceW z) Qplus R q0 b0 a delta (primeBin R thetaP) (primeBin U thetaU) h) ≤ + (4*R*((sourceW z)^(-aStar/2))^h+(smallModulus (sourceW z) : ℝ)*(2*U)^h)/R := by + filter_upwards [source_mean_power aStar K xi delta ha ha1 hK hxi hxi1 hd, + source_sample_population xi beta h hxi hxi1,source_sample_population xi 1 0 hxi hxi1, + sourceW_le_power alpha halpha,eventually_gt_atTop (1 : ℝ)] with z hmean hpop hpopP hWR hz + refine ⟨hz,?_⟩ + intro R thetaP U thetaU Qplus q0 b0 a hR hWU hUtop hPlow hPhigh hUlow hUhigh hq0 hqQ hQq hcop hlog + have hzpos : 0 < z := by linarith + have hRpos : 0 < R := (Real.rpow_pos_of_pos hzpos alpha).trans_le hR + have hWpos : 0 < sourceW z := by linarith [hmean.1] + have hUpos : 0 < U := hWpos.trans_le hWU + have hthetaP : 0 ≤ thetaP := (by positivity : (0 : ℝ) ≤ xi/4).trans hPlow + have hthetaU : 0 ≤ thetaU := (by positivity : (0 : ℝ) ≤ xi/4).trans hUlow + have hPo := hpopP R thetaP (hWR.trans hR) hPlow hPhigh + have hUo := hpop U thetaU hWU hUlow hUhigh + refine ⟨hPo.1,hUo.1,hUo.2.1,hUo.2.2.1,?_⟩ + apply actualCost_average_bound (sourceY z) (sourceW z) Qplus R q0 b0 a delta + (primeBin R thetaP) (primeBin U thetaU) h ((sourceW z)^(-aStar/2)) (2*U) hRpos.le + hPo.1 hUo.1 hUo.2.1 (Real.rpow_nonneg hWpos.le _) hUo.2.2.2 + · intro p hp v + rw [actual_family_mean_eq] + have hprime := ((mem_primeBin hRpos.le hthetaP p).mp hp).1 + exact hmean.2 p q0 q0 Qplus U thetaU b0 (v.val : ℤ) a hprime.pos hq0 hqQ hQq hWU hUtop + hUlow hUhigh (Int.ModEq.refl _) (hcop p hp) (hlog p hp) + · intro p hp + have hh := ((mem_primeBin hRpos.le hthetaP p).mp hp).2.2 + have htheta1 := hPhigh.trans hxi1 + nlinarith + · intro u + have hh := ((mem_primeBin hUpos.le hthetaU u.val).mp u.property).2.2 + have htheta1 := hUhigh.trans hxi1 + nlinarith + +end ErdosInverseSampleCost + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSampleCost +open NumberTheoryLean ErdosInverseSampling ErdosInverseSaving ErdosInversePrimeBin ErdosInverseEuler ErdosInverseBoxHeight + +theorem source_expected_cost_small (aStar K alpha xi delta beta eps : ℝ) (h : ℕ) + (ha : 0 < aStar) (ha1 : aStar ≤ 1) (hK : 0 ≤ K) (halpha : 0 < alpha) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hd : 0 < delta) + (heps : 0 < eps) (hh : 12 < aStar*(h : ℝ)/2) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R thetaP U thetaU Qplus : ℝ,∀ (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ), + z^alpha ≤ R → sourceW z ≤ U → U ≤ (sourceW z)^K → + xi/4 ≤ thetaP → thetaP ≤ xi → xi/4 ≤ thetaU → thetaU ≤ xi → + 0 < q0 → (q0 : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q0 : ℝ) → + (∀ p ∈ primeBin R thetaP,∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q0).Coprime t) → + (∀ p ∈ primeBin R thetaP,∀ u ∈ primeBin U thetaU, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q0*u))/Real.log (sourceW z)) → + 0 < (primeBin R thetaP).card ∧ 0 < (primeBin U thetaU).card ∧ h ≤ (primeBin U thetaU).card ∧ + 4*(h : ℝ)/beta ≤ ((primeBin U thetaU).card : ℝ) ∧ + sampleAverage (primeBin U thetaU) h + (actualCost (sourceY z) (sourceW z) Qplus R q0 b0 a delta (primeBin R thetaP) (primeBin U thetaU) h) ≤ + eps/(Real.log z)^6 := by + filter_upwards [source_expected_cost aStar K alpha xi delta beta h ha ha1 hK halpha hxi hxi1 hd, + source_cost_budget aStar K alpha eps h hK halpha heps hh] with z hexp hbudget + refine ⟨hexp.1,?_⟩ + intro R thetaP U thetaU Qplus q0 b0 a hR hWU hUtop hPlow hPhigh hUlow hUhigh hq0 hqQ hQq hcop hlog + have hv := hexp.2 R thetaP U thetaU Qplus q0 b0 a hR hWU hUtop hPlow hPhigh hUlow hUhigh hq0 hqQ hQq hcop hlog + have hL : 0 < Real.log z := Real.log_pos hexp.1 + have hW : 0 ≤ sourceW z := div_nonneg hL.le (sq_nonneg _) + have hs := hbudget.2 R U hR (hW.trans hWU) hUtop + have hL6 : 0 < (Real.log z)^6 := pow_pos hL 6 + refine ⟨hv.1,hv.2.1,hv.2.2.1,hv.2.2.2.1,?_⟩ + apply (le_div_iff₀ hL6).mpr + calc + _ ≤ ((4*R*((sourceW z)^(-aStar/2))^h+(smallModulus (sourceW z) : ℝ)*(2*U)^h)/R)*(Real.log z)^6 := + mul_le_mul_of_nonneg_right hv.2.2.2.2 hL6.le + _ = (Real.log z)^6*(4*R*((sourceW z)^(-aStar/2))^h+ + (smallModulus (sourceW z) : ℝ)*(2*U)^h)/R := by ring + _ ≤ eps := hs + +end ErdosInverseSampleCost + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSampleCost +open NumberTheoryLean ErdosInverseSampling ErdosInverseSaving ErdosInversePrimeBin ErdosInverseEuler ErdosInverseBoxHeight + +noncomputable def sampleGamma (beta : ℝ) (h : ℕ) : ℝ := (beta/2)*(beta/4)^h + +theorem sampleGamma_pos (beta : ℝ) (h : ℕ) (hb : 0 < beta) : 0 < sampleGamma beta h := by + unfold sampleGamma + positivity + +theorem source_good_sample (aStar K alpha xi delta beta : ℝ) (h : ℕ) + (ha : 0 < aStar) (ha1 : aStar ≤ 1) (hK : 0 ≤ K) (halpha : 0 < alpha) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hd : 0 < delta) (hb : 0 < beta) (hb1 : beta ≤ 1) + (hh : 12 < aStar*(h : ℝ)/2) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R thetaP U thetaU Qplus S : ℝ, + ∀ (C : Finset ℕ) (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ), + z^alpha ≤ R → sourceW z ≤ U → U ≤ (sourceW z)^K → + xi/4 ≤ thetaP → thetaP ≤ xi → xi/4 ≤ thetaU → thetaU ≤ xi → + q0 ∈ C → 0 < q0 → (q0 : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q0 : ℝ) → + (∀ p ∈ primeBin R thetaP,∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q0).Coprime t) → + (∀ p ∈ primeBin R thetaP,∀ u ∈ primeBin U thetaU, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q0*u))/Real.log (sourceW z)) → + let P := primeBin R thetaP + let Uset := primeBin U thetaU + let witness := actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) (sampleGamma beta h/32) + beta*((P.product C).card : ℝ)*(Uset.card : ℝ) ≤ ((witnessPairs (P.product C) Uset witness).card : ℝ) → + ∃ s : Sample Uset h,0 < P.card ∧ 0 < Uset.card ∧ 0 < h ∧ + sampleGamma beta h/2 ≤ selectedFraction (P.product C) Uset witness h s ∧ + actualCost (sourceY z) (sourceW z) Qplus R q0 b0 a (delta/4) P Uset h s ≤ 1/(Real.log z)^6 := by + have hg := sampleGamma_pos beta h hb + have hpos : 0 < h := by + by_contra hn + have hh0 : h = 0 := by omega + rw [hh0] at hh + norm_num at hh + filter_upwards [source_expected_cost_small aStar K alpha xi (delta/4) beta (sampleGamma beta h/4) h + ha ha1 hK halpha hxi hxi1 (by positivity) (by positivity) hh] with z hz + refine ⟨hz.1,?_⟩ + intro R thetaP U thetaU Qplus S C q0 b0 a hR hWU hUtop hPlow hPhigh hUlow hUhigh + hqC hq0 hqQ hQq hcop hlog + dsimp only + intro hdense + have hv := hz.2 R thetaP U thetaU Qplus q0 b0 a hR hWU hUtop hPlow hPhigh hUlow hUhigh hq0 hqQ hQq hcop hlog + have hC : 0 < C.card := Finset.card_pos.mpr ⟨q0,hqC⟩ + have hA : 0 < ((primeBin R thetaP).product C).card := by + rw [Finset.product_eq_sprod,Finset.card_product] + exact Nat.mul_pos hv.1 hC + have hL : 0 < Real.log z := Real.log_pos hz.1 + have hzpos : 0 < z := by linarith [hz.1] + have hRpos : 0 < R := (Real.rpow_pos_of_pos hzpos alpha).trans_le hR + let witness := actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) (primeBin R thetaP) S R (sourceZ z) (sampleGamma beta h/32) + let cost := actualCost (sourceY z) (sourceW z) Qplus R q0 b0 a (delta/4) (primeBin R thetaP) (primeBin U thetaU) h + have hc : ∀ s : Sample (primeBin U thetaU) h,0 ≤ cost s := + fun s => actualCost_nonneg _ _ _ _ _ _ _ _ _ _ _ s hRpos.le + have hcost : sampleAverage (primeBin U thetaU) h cost ≤ + (((beta/2)*(beta/4)^h)*(1/(Real.log z)^6)/4) := by + calc + _ ≤ (sampleGamma beta h/4)/(Real.log z)^6 := hv.2.2.2.2 + _ = _ := by unfold sampleGamma;ring + obtain ⟨s,hs,hcs⟩ := exists_good_distinct_sample ((primeBin R thetaP).product C) (primeBin U thetaU) + witness h beta (1/(Real.log z)^6) hb hb1 (by positivity) hA hv.2.1 hdense hv.2.2.2.1 cost hc hcost + exact ⟨s,hv.1,hv.2.1,hpos,hs,hcs⟩ + +end ErdosInverseSampleCost + +end + +section + +namespace ErdosInverseRefinement +open NumberTheoryLean ErdosInverseCells ErdosInverseSampling ErdosInverseSampleCost + ErdosInverseCRT ErdosInverseEuler ErdosInverseHits ErdosInverseStructured +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def pointSlopes (Y : ℕ) (w Qplus : ℝ) (qInitial : ℕ) (bInitial : ℤ) + (a : ℕ → ℕ) (delta : ℝ) (P U : Finset ℕ) (h : ℕ) (s : Sample U h) + (hp : ∀ p ∈ P,∀ u ∈ U,p.Coprime u) (qRef : ℕ) (bRef : ℤ) + (hqRef : ∀ u ∈ U,qRef.Coprime u) (p : ℕ) : Finset ℤ := + if hpP : p ∈ P then + sourceTestedSlopes p qRef (smallModulus w) (fun i => (s i).val) + (fun i => hp p hpP _ (s i).property) (fun i => hqRef _ (s i).property) + (fun u => (a u : ℤ)) bRef + (fun v i => actualFamily Y w Qplus qInitial bInitial a delta U (smallModulus w) p v (s i)) + else ∅ + +theorem pointSlopes_eq (Y : ℕ) (w Qplus : ℝ) (qInitial : ℕ) (bInitial : ℤ) + (a : ℕ → ℕ) (delta : ℝ) (P U : Finset ℕ) (h : ℕ) (s : Sample U h) + (hp : ∀ p ∈ P,∀ u ∈ U,p.Coprime u) (qRef : ℕ) (bRef : ℤ) + (hqRef : ∀ u ∈ U,qRef.Coprime u) (p : ℕ) (hpP : p ∈ P) : + pointSlopes Y w Qplus qInitial bInitial a delta P U h s hp qRef bRef hqRef p = + sourceTestedSlopes p qRef (smallModulus w) (fun i => (s i).val) + (fun i => hp p hpP _ (s i).property) (fun i => hqRef _ (s i).property) + (fun u => (a u : ℤ)) bRef + (fun v i => actualFamily Y w Qplus qInitial bInitial a delta U (smallModulus w) p v (s i)) := by + simp only [pointSlopes,dite_eq_left hpP] + +theorem pointSlopes_thin (Y : ℕ) (w Qplus R L : ℝ) (qInitial : ℕ) (bInitial : ℤ) + (a : ℕ → ℕ) (delta : ℝ) (P U : Finset ℕ) (h : ℕ) (s : Sample U h) + (hw : 0 ≤ w) (hR : 0 < R) (hP : 0 < P.card) (hU : ∀ u ∈ U,u.Prime) + (huLarge : ∀ u ∈ U,w < (u : ℝ)) (hp : ∀ p ∈ P,∀ u ∈ U,p.Coprime u) + (hcost : actualCost Y w Qplus R qInitial bInitial a delta P U h s ≤ 1/L^6) + (qRef : ℕ) (bRef : ℤ) (hqRef : ∀ u ∈ U,qRef.Coprime u) : + (∑ p ∈ P,((pointSlopes Y w Qplus qInitial bInitial a delta P U h s hp qRef bRef hqRef p).card : ℝ)) ≤ + (P.card : ℝ)*R/L^6 := by + let : NeZero (smallModulus w) := ⟨(smallModulus_pos w).ne'⟩ + have hh := actual_slopes_thin Y w Qplus R L qInitial bInitial a delta P U h s hw hR hP hU huLarge hp hcost + qRef bRef hqRef + rw [← Finset.sum_coe_sort P (fun p : ℕ => + ((pointSlopes Y w Qplus qInitial bInitial a delta P U h s hp qRef bRef hqRef p).card : ℝ))] + simpa only [pointSlopes,dite_eq_left (Subtype.property _)] using hh + +theorem parentSlope_incidence (a : ℕ → ℕ) (T : ℕ → Finset ℤ) (p q : ℕ) [NeZero p] + (hqp : q.Coprime p) + (hs : (parentSlope p q hqp (a p) (cofactorHit q a) : ℤ) ∈ T p) : + SlopeIncidence (fun u => (a u : ℤ)) T (cofactorPoint a q) p := by + refine ⟨(parentSlope p q hqp (a p) (cofactorHit q a) : ℤ),hs,?_⟩ + have he := (ZMod.natCast_eq_natCast_iff _ _ _).mpr (parent_start_mod_p p q hqp (a p) (cofactorHit q a)) + simp only [Nat.cast_add,Nat.cast_mul] at he + change ((cofactorHit q a : ℤ) : ZMod p) = ((a p : ℤ) : ZMod p)- + ((parentSlope p q hqp (a p) (cofactorHit q a) : ℤ) : ZMod p)*((q : ℤ) : ZMod p) + simp only [Int.cast_natCast] + linear_combination he + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualRegularAdmission.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualRegularAdmission.lean new file mode 100644 index 0000000000000000000000000000000000000000..40d64f833ec6a329c5585fe8011c4848c79bc407 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualRegularAdmission.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.RegularityDefectPartition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualRegularAdmission +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualWordSelection ActualRegularBoxes +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open SafeSubsetBoxGeometry ReferenceAdmission ActualSourceTags FiniteFirstTag +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem regular_word_reference {w top xi Clen B K : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hC : 0 ≤ Clen) (hcomp : Real.log B ≤ 2*Real.log w) + (hsmall : 2*(xi/Real.log w) ≤ 6*(2*Clen*xi)) (z : Node) (ps : List ℕ) + (hp : ps ∈ regularWords hw htop hxi Clen B K z) : + ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap := by + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hp).1 + have han := regular_word_anchor hw htop hxi hC hcomp hsmall z ps hp + have hh := anchored_choice_geometry hw htop hxi hC hcomp z _ han + (wordSelection (label (zero_lt_one.trans hw) htop hxi) ps) + (wordSelection_mem hw htop hxi ps hd.2) + rw [wordSelection_recovers _ ps hd.1] at hh + exact hh.1 + +theorem regular_tag_singleton {Y w top xi Clen B K Cs eta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) (ps : List ℕ) + (hp : ps ∈ regularWords hw htop hxi Clen B K z) (a : ℕ → ℤ) + (t : Tag (binCount w top xi)) + (ht : sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a ps=some t) : + (ps.map (label (zero_lt_one.trans hw) htop hxi)).count t.bin=1 := by + obtain ⟨pre,p,tail,heq,_hidx,hbin,_hp,hsearch,_ho,_ha,_hn⟩ := + sourceTag_witness Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a ps ht + have hmem : p ∈ ps := by rw [heq]; simp + have hm : t.bin ∈ ps.map (label (zero_lt_one.trans hw) htop hxi) := + List.mem_map.mpr ⟨p,hmem,hbin.symm⟩ + have hpos := List.count_pos_iff.mpr hm + rw [← hbin] at hsearch + have hle := (Finset.mem_filter.mp hp).2.2.2.2 t.bin hsearch + omega +end NumberTheoryLean.ActualRegularAdmission + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualSourceInverse.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualSourceInverse.lean new file mode 100644 index 0000000000000000000000000000000000000000..df39395c124403bfc8735a8318687bf0beaf6765 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualSourceInverse.lean @@ -0,0 +1,177 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ActualBoxHarmonicInverse +import OAI.NumberTheory.Jacobsthal.Partitions.ActualBoxList + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseBoxApplication +open ErdosInverseCells ErdosInverseSampleCost ErdosInverseSampling ErdosInverseCounts + ErdosInverseStructured ErdosInverseAlignment ErdosPrimitiveIntercept +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def actualInverseException (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp : ℝ) (P Q U : Finset ℕ) : Finset ((ℕ × ℕ) × ℕ) := + witnessPairs (P.product Q) U (actualWitness Y small a delta V0 P S R Z cp) + +theorem mem_actualInverseException (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp : ℝ) (P Q U : Finset ℕ) (p q u : ℕ) : + ((p,q),u) ∈ actualInverseException Y small a delta V0 S R Z cp P Q U ↔ + p ∈ P ∧ q ∈ Q ∧ u ∈ U ∧ Nonstructured P (fun p => (a p : ℤ)) S R Z cp p q ∧ + WitnessingBadEdge Y small a delta V0 p q u := by + constructor + · intro hmem + obtain ⟨hprod,hWitness⟩ := Finset.mem_filter.mp hmem + obtain ⟨hpq,hu⟩ := Finset.mem_product.mp hprod + obtain ⟨hp,hq⟩ := Finset.mem_product.mp hpq + exact ⟨hp,hq,hu,hWitness.1,hWitness.2⟩ + · rintro ⟨hp,hq,hu,hNon,hBad⟩ + exact Finset.mem_filter.mpr + ⟨Finset.mem_product.mpr ⟨Finset.mem_product.mpr ⟨hp,hq⟩,hu⟩,⟨hNon,hBad⟩⟩ + +theorem actual_exception_weight (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp : ℝ) (P Q U : Finset ℕ) : + (∑ t ∈ actualInverseException Y small a delta V0 S R Z cp P Q U,tripleWeight t) = + weightedWitness P Q U (actualWitness Y small a delta V0 P S R Z cp) := rfl + +theorem normalized_exception_bound (P Q U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (sigma : ℝ) (hsigma : 0 ≤ sigma) + (h : weightedWitness P Q U witness ≤ sigma*(harmonicMass P*harmonicMass Q*harmonicMass U)) : + weightedWitness P Q U witness/(harmonicMass P*harmonicMass Q*harmonicMass U) ≤ sigma := by + have hm : 0 ≤ harmonicMass P*harmonicMass Q*harmonicMass U := + mul_nonneg (mul_nonneg (harmonicMass_nonneg P) (harmonicMass_nonneg Q)) (harmonicMass_nonneg U) + rcases hm.eq_or_lt with hm | hm + · rw [← hm,div_zero] + exact hsigma + · exact (div_le_iff₀ hm).mpr h + +theorem structured_outside_actual_exception (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp : ℝ) (P Q U : Finset ℕ) (p q u : ℕ) + (hp : p ∈ P) (hq : q ∈ Q) (hu : u ∈ U) + (hout : ((p,q),u) ∉ actualInverseException Y small a delta V0 S R Z cp P Q U) + (hbad : WitnessingBadEdge Y small a delta V0 p q u) : + ∃ t ∈ sourceRationalList P (fun p => (a p : ℤ)) S R Z cp, + aligns (fun p => (a p : ℤ)) t p ∧ + ((t.den*badPrimeProduct (fun p => (a p : ℤ)) t q : ℕ) : ℝ) ≤ R*Z^10 := by + by_contra hn + exact hout ((mem_actualInverseException Y small a delta V0 S R Z cp P Q U p q u).mpr + ⟨hp,hq,hu,hn,hbad⟩) + +end ErdosInverseBoxApplication + +end + +section + +namespace ErdosInverseBoxApplication +open ErdosInverseCells ErdosInverseSampleCost ErdosInverseSampling ErdosInverseCounts + ErdosInverseStructured ErdosInverseAlignment ErdosPrimitiveIntercept +attribute [local instance] Classical.propDecidable + +def SourceInverseConclusion (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp sigma : ℝ) (F : ℕ) (P Q U : Finset ℕ) : Prop := + (sourceRationalList P (fun p => (a p : ℤ)) S R Z cp).card ≤ F ∧ + (∀ t ∈ sourceRationalList P (fun p => (a p : ℤ)) S R Z cp, + (t.num.natAbs : ℝ) ≤ S*R*Z^10 ∧ (t.den : ℝ) ≤ R*Z^10 ∧ + cp*(P.card : ℝ) ≤ ((P.filter (aligns (fun p => (a p : ℤ)) t)).card : ℝ)) ∧ + (∑ e ∈ actualInverseException Y small a delta V0 S R Z cp P Q U,tripleWeight e)/ + (harmonicMass P*harmonicMass Q*harmonicMass U) ≤ sigma ∧ + (∀ p ∈ P,∀ q ∈ Q,∀ u ∈ U, + ((p,q),u) ∉ actualInverseException Y small a delta V0 S R Z cp P Q U → + WitnessingBadEdge Y small a delta V0 p q u → + ∃ t ∈ sourceRationalList P (fun p => (a p : ℤ)) S R Z cp, + aligns (fun p => (a p : ℤ)) t p ∧ + ((t.den*badPrimeProduct (fun p => (a p : ℤ)) t q : ℕ) : ℝ) ≤ R*Z^10) + +theorem source_inverse_conclusion_of_bounds (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp sigma : ℝ) (F : ℕ) (P Q U : Finset ℕ) + (hS : 0 ≤ S) (hR : 0 ≤ R) (hsigma : 0 ≤ sigma) + (hlist : (sourceRationalList P (fun p => (a p : ℤ)) S R Z cp).card ≤ F) + (hweight : weightedWitness P Q U (actualWitness Y small a delta V0 P S R Z cp) ≤ + sigma*(harmonicMass P*harmonicMass Q*harmonicMass U)) : + SourceInverseConclusion Y small a delta V0 S R Z cp sigma F P Q U := by + refine ⟨hlist,?_,?_,?_⟩ + · intro t ht + exact (mem_sourceRationalList P (fun p => (a p : ℤ)) hS hR t).mp ht + · rw [actual_exception_weight] + exact normalized_exception_bound P Q U _ sigma hsigma hweight + · exact fun p hp q hq u hu => structured_outside_actual_exception Y small a delta V0 S R Z cp + P Q U p q u hp hq hu + +end ErdosInverseBoxApplication + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseBoxApplication +open NumberTheoryLean ErdosCofactorChoices ErdosInverseCells ErdosInverseRefinement + ErdosInverseBoxHeight ErdosInverseEuler ErdosInverseSampleCost ErdosInverseSampling +open NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints + +theorem exists_inverse_sample_length (aStar : ℝ) (ha : 0 < aStar) : + ∃ h : ℕ,12 < aStar*(h : ℝ)/2 := by + obtain ⟨h,hh⟩ := exists_nat_gt (24/aStar) + refine ⟨h,?_⟩ + have hm := (div_lt_iff₀ ha).mp hh + nlinarith + +theorem actual_source_inverse (Clen Cparent aStar K alpha delta sigma : ℝ) + (hClen : 0 ≤ Clen) (hCparent : 0 ≤ Cparent) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (hK : 0 ≤ K) (halpha : 0 < alpha) (hd : 0 < delta) (hsigma : 0 < sigma) (hsigma1 : sigma ≤ 1) : + ∃ cp : ℝ,0 < cp ∧ ∃ F : ℕ,∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,0 < xi → xi ≤ xi0 → + ∀ᶠ z : ℝ in atTop, + ∀ (m : Fin (binCount (sourceW z) z xi) → ℕ) + (i j : Fin (binCount (sourceW z) z xi)), + i ≠ j → m i = 0 → m j = 0 → + ((∑ k,m k : ℕ) : ℝ) ≤ Clen*Real.log (sourceB z) → + ∀ a : ℕ → ℕ, + let R := lower (sourceW z) z xi i + let U := lower (sourceW z) z xi j + let P := actualBins z xi i + let Uset := actualBins z xi j + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → U ≤ (sourceW z)^K → + (∀ q ∈ Q,∀ p ∈ P, + Real.logb (sourceW z) ((sourceY z : ℝ)/((p : ℝ)*q)) ≤ Cparent) → + (∀ q ∈ Q,∀ p ∈ P,∀ u ∈ Uset, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z)) → + SourceInverseConclusion (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) S R (sourceZ z) cp sigma F P Q Uset := by + obtain ⟨h,hh⟩ := exists_inverse_sample_length aStar ha + let cp := sampleGamma (sigma/16) h/32 + have hcp : 0 < cp := div_pos (sampleGamma_pos (sigma/16) h (by positivity)) (by norm_num) + obtain ⟨xi0,hxi0,hxi01,hWeight⟩ := actual_box_nonstructured_harmonic Clen Cparent aStar K alpha delta sigma h + hClen hCparent ha ha1 hK halpha hd hsigma hsigma1 hh + refine ⟨cp,hcp,⌈2/cp^2⌉₊,xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + have hxi1 := hxib.trans hxi01 + filter_upwards [hWeight xi hxi hxib,actual_box_list_card Clen aStar alpha xi cp hClen ha halpha hxi hxi1 hcp, + source_span_geometry] with z hweight hlist hspan + intro m i j hij hmi hmj hm a + dsimp only + intro hRlo hRhi hUhi hparent hchild + have hw := hweight m i j hij hmi hmj hm a hRlo hRhi hUhi hparent hchild + have hl := hlist m i j hm a hRlo hRhi hchild + apply source_inverse_conclusion_of_bounds + · exact (actual_cofactorScale_pos hspan.1 hspan.2.1 hxi m).le + · exact (endpoint_pos hspan.1 i.1).le + · exact hsigma.le + · exact hl + · exact hw + +end ErdosInverseBoxApplication + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualUnalignedIncidence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualUnalignedIncidence.lean new file mode 100644 index 0000000000000000000000000000000000000000..6dbf7855db703a392f556fd789aec276ff9f59e3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualUnalignedIncidence.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.NormalizedCollisionSmallness +import OAI.NumberTheory.Jacobsthal.Primes.PrimeBinRationalList + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceCollision +open ErdosInversePrimeBin ErdosLineCollision ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment ErdosConvexGraph + +noncomputable def unalignedPrimes (P : Finset ℕ) (a : ℕ → ℤ) {l : PrimitiveIntegerLine} + (r : InterceptReduction l) : Finset ℕ := by + classical + exact P.filter (fun p => ¬p ∣ l.denominator ∧ ¬aligns a r.rational p) + +theorem uniform_actual_unaligned_incidence (eta alpha eps : ℝ) + (heta : 0 < eta) (halpha : 0 < alpha) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ R xi S : ℝ, + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → eta ≤ xi → xi ≤ 1 → + ∀ (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (l : PrimitiveIntegerLine) (r : InterceptReduction l) + (X : Finset (ℤ × ℤ)), (∀ v ∈ X,l.Contains v) → (∀ v ∈ X,InSquare S v) → + Set.InjOn Prod.fst (X : Set (ℤ × ℤ)) → S ≤ z^3 → z^((93 : ℝ)/100) ≤ (X.card : ℝ) → + (∑ p ∈ primeBin R xi,((T p).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/(Real.log z)^6 → + (∑ p ∈ unalignedPrimes (primeBin R xi) a r,((incidentPoints X (a p) p (T p)).card : ℝ)) ≤ + eps*((primeBin R xi).card : ℝ)*(X.card : ℝ) := by + classical + obtain ⟨R0,hR0⟩ := eventually_atTop.mp (uniform_prime_bin_count heta) + have hs := uniform_normalized_collision (3/alpha) eta eps (by positivity) heta heps + filter_upwards [hs,(tendsto_rpow_atTop halpha).eventually_ge_atTop R0] with z hz hzR + refine ⟨hz.1,?_⟩ + intro R xi S hRlo hRhi hxi hxi1 a T l r X hline hbox hinj hS hN hthin + have hb := hR0 R (hzR.trans hRlo) + have hR : 1 < R := by linarith [hb.1] + have hRpos : 0 < R := by linarith + have hlogR : 0 < Real.log R := Real.log_pos hR + have hxipos : 0 ≤ xi := heta.le.trans hxi + let P := primeBin R xi + let U := unalignedPrimes P a r + have hsub : U ⊆ P := Finset.filter_subset _ _ + have hprime (p : ℕ) (hp : p ∈ P) : Nat.Prime p := ((mem_primeBin hRpos.le hxipos p).mp hp).1 + have hplarge (p : ℕ) (hp : p ∈ P) : z^alpha ≤ (p : ℝ) := + hRlo.trans (((mem_primeBin hRpos.le hxipos p).mp hp).2.1.le) + have hcount : eta*R/(4*Real.log R) ≤ (P.card : ℝ) := by + apply (div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hxi hRpos.le) + (by positivity : 0 ≤ 4*Real.log R)).trans + exact (hb.2 xi hxi hxi1).1 + have hcollision := actual_collision_bound r U X a T hline + (fun p hp => hprime p (hsub hp)) + (fun _ hp => (Finset.mem_filter.mp hp).2.1) + (fun _ hp => (Finset.mem_filter.mp hp).2.2) + hinj S z alpha hbox hz.1 halpha (fun p hp => hplarge p (hsub hp)) hS + have hKU : (∑ p ∈ U,((T p).card : ℝ)) ≤ ∑ p ∈ P,((T p).card : ℝ) := + Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => Nat.cast_nonneg _) + have hI : (∑ p ∈ U,((incidentPoints X (a p) p (T p)).card : ℝ)) ≤ (P.card : ℝ)*(X.card : ℝ) := + (total_incidence_le_product U X a T).trans (mul_le_mul_of_nonneg_right + (Nat.cast_le.mpr (Finset.card_le_card hsub)) (Nat.cast_nonneg _)) + exact hz.2 _ _ R _ _ hR hRhi hN hcount (Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _)) + hcollision (hKU.trans hthin) hI + +end ErdosSourceCollision + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualUnitClasses.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualUnitClasses.lean new file mode 100644 index 0000000000000000000000000000000000000000..2cc3e93241830a444fa750e2a6a42c4a9a275883 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ActualUnitClasses.lean @@ -0,0 +1,354 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.RealCoprimeResidueCount + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosUnitLifts +attribute [local instance] Classical.decEq + +def radical (D : ℕ) : ℕ := ∏ t ∈ D.primeFactors, t + +theorem radical_pos (D : ℕ) : 0 < radical D := + Finset.prod_pos (fun _ ht => Nat.pos_of_mem_primeFactors ht) + +theorem radical_dvd (D : ℕ) : radical D ∣ D := Nat.prod_primeFactors_dvd D + +theorem radical_primeFactors (D : ℕ) : (radical D).primeFactors = D.primeFactors := + Nat.primeFactors_prod_primeFactors D + +theorem totient_radical (D : ℕ) : + (radical D).totient = ∏ t ∈ D.primeFactors, (t - 1) := by + rw [Nat.totient_eq_div_primeFactors_mul, radical_primeFactors] + change radical D / radical D * _ = _ + rw [Nat.div_self (radical_pos D), one_mul] + +theorem totient_lift_modulus (D : ℕ) (hD : 0 < D) : + (D * radical D).totient = D * (radical D).totient := by + rw [Nat.totient_eq_div_primeFactors_mul] + rw [Nat.primeFactors_mul hD.ne' (radical_pos D).ne', radical_primeFactors, + Finset.union_self, totient_radical] + change D * radical D / radical D * _ = _ + rw [Nat.mul_div_cancel D (radical_pos D)] + +theorem totient_lift_modulus' (D : ℕ) (hD : 0 < D) : + (D * radical D).totient = D.totient * radical D := by + rw [totient_lift_modulus D hD, totient_radical] + exact (Nat.totient_mul_prod_primeFactors D).symm + +abbrev PrimeIndex (D : ℕ) := {t // t ∈ D.primeFactors} + +theorem primeIndex_coprime (D : ℕ) : + Pairwise (fun t u : PrimeIndex D => Nat.Coprime t.val u.val) := by + intro t u hne + exact (Nat.prime_of_mem_primeFactors t.property).coprime_iff_not_dvd.mpr (by + intro h + have he := (Nat.prime_of_mem_primeFactors u.property).eq_one_or_self_of_dvd _ h + rcases he with he | he + · exact (Nat.prime_of_mem_primeFactors t.property).ne_one he + · exact hne (Subtype.ext he)) + +noncomputable def localAllowed (t : ℕ) [NeZero t] (n B a : ℤ) : Finset (ZMod t) := + Finset.univ.filter (fun x => (n : ZMod t) + B * x ≠ a) + +theorem affine_eq_iff (t : ℕ) (n B a : ℤ) (hB : IsUnit (B : ZMod t)) + (x : ZMod t) : + (n : ZMod t) + B * x = a ↔ x = (B : ZMod t)⁻¹ * (a - n) := by + constructor + · intro h + calc + x = (B : ZMod t)⁻¹ * (B * x) := by rw [← mul_assoc, ZMod.inv_mul_of_unit _ hB, one_mul] + _ = (B : ZMod t)⁻¹ * (a - n) := by congr 1; linear_combination h + · intro h + rw [h, ← mul_assoc, ZMod.mul_inv_of_unit _ hB, one_mul] + ring + +theorem localAllowed_card (t : ℕ) [NeZero t] (n B a : ℤ) + (hB : IsUnit (B : ZMod t)) : (localAllowed t n B a).card = t - 1 := by + have he : localAllowed t n B a = Finset.univ.erase ((B : ZMod t)⁻¹ * (a - n)) := by + ext x + simp [localAllowed, affine_eq_iff t n B a hB] + rw [he, Finset.card_erase_of_mem (Finset.mem_univ _)] + simp + +noncomputable def crtNat {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i, Finset (ZMod (m i))) : Finset ℕ := + (ErdosInverseCRT.crtResidues m hcop E).image ZMod.val + +theorem mem_crtNat {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i, Finset (ZMod (m i))) (hpos : 0 < ∏ i, m i) (k : ℕ) : + k ∈ crtNat m hcop E ↔ k < ∏ i, m i ∧ ∀ i, (k : ZMod (m i)) ∈ E i := by + let : NeZero (∏ i, m i) := ⟨hpos.ne'⟩ + constructor + · intro hk + obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp hk + refine ⟨ZMod.val_lt r, ?_⟩ + have hh : (r.val : ZMod (∏ i, m i)) ∈ ErdosInverseCRT.crtResidues m hcop E := by + simpa using hr + have hx := ErdosInverseCRT.intCast_mem_crtResidues m hcop E (r.val : ℤ) + simp only [Int.cast_natCast] at hx + exact hx.mp hh + · rintro ⟨hk,he⟩ + apply Finset.mem_image.mpr + refine ⟨(k : ZMod (∏ i,m i)), ?_, ZMod.val_natCast_of_lt hk⟩ + have hx := ErdosInverseCRT.intCast_mem_crtResidues m hcop E (k : ℤ) + simp only [Int.cast_natCast] at hx + exact hx.mpr he + +theorem crtNat_card {ι : Type*} [Fintype ι] (m : ι → ℕ) + (hcop : Pairwise (fun i j => Nat.Coprime (m i) (m j))) + (E : ∀ i, Finset (ZMod (m i))) (hpos : 0 < ∏ i, m i) : + (crtNat m hcop E).card = ∏ i, (E i).card := by + let : NeZero (∏ i, m i) := ⟨hpos.ne'⟩ + rw [crtNat, Finset.card_image_of_injective _ (ZMod.val_injective _), + ErdosInverseCRT.crtResidues_card] + +noncomputable def allowedK (D : ℕ) (n B : ℤ) (a : ℕ → ℤ) : Finset ℕ := + (Finset.range (radical D)).filter (fun k => ∀ t ∈ D.primeFactors, + ((n + B * k : ℤ) : ZMod t) ≠ a t) + +theorem allowedK_card (D : ℕ) (n B : ℤ) (a : ℕ → ℤ) + (hB : IsUnit (B : ZMod D)) : + (allowedK D n B a).card = (radical D).totient := by + let (t : PrimeIndex D) : NeZero t.val := ⟨(Nat.pos_of_mem_primeFactors t.property).ne'⟩ + let m := fun t : PrimeIndex D => t.val + let E := fun t : PrimeIndex D => localAllowed t.val n B (a t.val) + have hm : (∏ t : PrimeIndex D, m t) = radical D := by + exact Finset.prod_coe_sort D.primeFactors (fun t => t) + have hpos : 0 < ∏ t : PrimeIndex D, m t := hm ▸ radical_pos D + have he : allowedK D n B a = crtNat m (primeIndex_coprime D) E := by + ext k + rw [mem_crtNat m (primeIndex_coprime D) E hpos] + simp only [allowedK, Finset.mem_filter, Finset.mem_range, hm] + simp only [E, localAllowed, Finset.mem_filter, Finset.mem_univ, true_and, + Int.cast_add, Int.cast_mul, Int.cast_natCast] + apply and_congr_right + intro _ + constructor + · intro h t + exact h t.val t.property + · intro h t ht + exact h ⟨t,ht⟩ + rw [he, crtNat_card m (primeIndex_coprime D) E hpos, totient_radical] + calc + (∏ t : PrimeIndex D, (E t).card) = ∏ t : PrimeIndex D, (t.val - 1) := by + apply Finset.prod_congr rfl + intro t _ + apply localAllowed_card + have hd : t.val ∣ D := Nat.dvd_of_mem_primeFactors t.property + simpa using hB.map (ZMod.castHom hd (ZMod t.val)) + _ = _ := Finset.prod_coe_sort D.primeFactors (fun t => t - 1) + +end ErdosUnitLifts + +end + +section + +open scoped BigOperators +namespace ErdosUnitLifts +attribute [local instance] Classical.decEq + +def actualN (D : ℕ) (A B : ℤ) (p : ℕ) : ℤ := (A + B * p) / D + +noncomputable def actualClasses (D : ℕ) (A B : ℤ) (a : ℕ → ℤ) : Finset ℕ := + (Finset.range (D * radical D)).filter (fun p => + (D : ℤ) ∣ A + B * p ∧ ∀ t ∈ D.primeFactors, + (actualN D A B p : ZMod t) ≠ a t) + +noncomputable def baseResidue (D : ℕ) (A B : ℤ) : ℕ := + (-(A : ZMod D) * (B : ZMod D)⁻¹).val + +theorem baseResidue_lt (D : ℕ) (hD : 0 < D) (A B : ℤ) : baseResidue D A B < D := by + let : NeZero D := ⟨hD.ne'⟩ + exact ZMod.val_lt _ + +theorem baseResidue_integral (D : ℕ) (hD : 0 < D) (A B : ℤ) + (hB : IsUnit (B : ZMod D)) : (D : ℤ) ∣ A + B * baseResidue D A B := by + let : NeZero D := ⟨hD.ne'⟩ + apply (ZMod.intCast_zmod_eq_zero_iff_dvd _ D).mp + simp only [Int.cast_add, Int.cast_mul, Int.cast_natCast, baseResidue, ZMod.natCast_zmod_val] + calc + (A : ZMod D) + B * (-A * (B : ZMod D)⁻¹) = A - A * (B * (B : ZMod D)⁻¹) := by ring + _ = 0 := by rw [ZMod.mul_inv_of_unit _ hB]; ring + +theorem integral_iff_base_mod (D p0 : ℕ) (hp0 : p0 < D) (A B : ℤ) + (hB : IsUnit (B : ZMod D)) (h0 : (D : ℤ) ∣ A + B * p0) (p : ℕ) : + (D : ℤ) ∣ A + B * p ↔ p % D = p0 := by + have hz0 := (ZMod.intCast_zmod_eq_zero_iff_dvd _ D).mpr h0 + simp only [Int.cast_add, Int.cast_mul, Int.cast_natCast] at hz0 + have hh : (D : ℤ) ∣ A + B * p ↔ (p : ZMod D) = p0 := by + rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] + simp only [Int.cast_add, Int.cast_mul, Int.cast_natCast] + constructor + · intro hp + apply hB.mul_left_cancel + linear_combination hp - hz0 + · intro hp + simpa only [hp] using hz0 + rw [hh, ZMod.natCast_eq_natCast_iff', Nat.mod_eq_of_lt hp0] + +theorem base_coprime (D p0 : ℕ) (A B : ℤ) + (hA : IsUnit (A : ZMod D)) (h0 : (D : ℤ) ∣ A + B * p0) : + Nat.Coprime p0 D := by + apply (ZMod.isUnit_iff_coprime p0 D).mp + have hz0 := (ZMod.intCast_zmod_eq_zero_iff_dvd _ D).mpr h0 + simp only [Int.cast_add, Int.cast_mul, Int.cast_natCast] at hz0 + have he : (B : ZMod D) * p0 = -A := by linear_combination hz0 + apply isUnit_of_mul_isUnit_right (x := (B : ZMod D)) + rw [he] + exact hA.neg + +theorem actualN_lift (D : ℕ) (hD : 0 < D) (A B : ℤ) (p0 k : ℕ) : + actualN D A B (p0 + D * k) = actualN D A B p0 + B * k := by + unfold actualN + have hn : (D : ℤ) ≠ 0 := by exact_mod_cast hD.ne' + have he : A + B * (p0 + D * k : ℕ) = A + B * p0 + (B * k) * D := by push_cast; ring + rw [he, Int.add_mul_ediv_right _ _ hn] + +theorem lift_coprime (D p0 k : ℕ) (hp : Nat.Coprime p0 D) : + Nat.Coprime (p0 + D * k) (D * radical D) := by + have hd : Nat.Coprime (p0 + D * k) D := + (Nat.coprime_add_mul_left_left p0 D k).mpr hp + exact Nat.coprime_mul_iff_right.mpr ⟨hd, Nat.Coprime.coprime_dvd_right (radical_dvd D) hd⟩ + +theorem canonical_lift_iff (D p0 p : ℕ) (hD : 0 < D) (hp0 : p0 < D) : + p < D * radical D ∧ p % D = p0 ↔ + ∃ k < radical D, p0 + D * k = p := by + constructor + · rintro ⟨hp,hm⟩ + refine ⟨p / D, ?_, ?_⟩ + · exact (Nat.div_lt_iff_lt_mul hD).mpr (by simpa [Nat.mul_comm] using hp) + · simpa only [hm] using Nat.mod_add_div p D + · rintro ⟨k,hk,rfl⟩ + constructor + · calc + p0 + D * k < D + D * k := Nat.add_lt_add_right hp0 _ + _ = D * (k + 1) := by ring + _ ≤ D * radical D := Nat.mul_le_mul_left D hk + · simp only [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hp0] + +theorem actualClasses_eq_lifts (D p0 : ℕ) (hD : 0 < D) (hp0 : p0 < D) + (A B : ℤ) (a : ℕ → ℤ) (hB : IsUnit (B : ZMod D)) + (h0 : (D : ℤ) ∣ A + B * p0) : + actualClasses D A B a = + (allowedK D (actualN D A B p0) B a).image (fun k => p0 + D * k) := by + ext p + constructor + · intro hp + obtain ⟨hp,hi,ha⟩ := Finset.mem_filter.mp hp + obtain ⟨k,hk,hkp⟩ := (canonical_lift_iff D p0 p hD hp0).mp + ⟨Finset.mem_range.mp hp, (integral_iff_base_mod D p0 hp0 A B hB h0 p).mp hi⟩ + apply Finset.mem_image.mpr + refine ⟨k, Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hk, ?_⟩, hkp⟩ + intro t ht + have hh := ha t ht + rw [← hkp, actualN_lift D hD] at hh + exact hh + · intro hp + obtain ⟨k,hk,rfl⟩ := Finset.mem_image.mp hp + obtain ⟨hk,ha⟩ := Finset.mem_filter.mp hk + have hc := (canonical_lift_iff D p0 (p0 + D * k) hD hp0).mpr + ⟨k, Finset.mem_range.mp hk, rfl⟩ + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_range.mpr hc.1, ?_, ?_⟩ + · exact (integral_iff_base_mod D p0 hp0 A B hB h0 _).mpr hc.2 + · intro t ht + rw [actualN_lift D hD] + exact ha t ht + +theorem actualClasses_card (D : ℕ) (hD : 0 < D) (A B : ℤ) (a : ℕ → ℤ) + (hB : IsUnit (B : ZMod D)) : + (actualClasses D A B a).card = (radical D).totient := by + rw [actualClasses_eq_lifts D (baseResidue D A B) hD (baseResidue_lt D hD A B) + A B a hB (baseResidue_integral D hD A B hB)] + rw [Finset.card_image_of_injective] + · exact allowedK_card D (actualN D A B (baseResidue D A B)) B a hB + · intro k l h + exact Nat.eq_of_mul_eq_mul_left hD (Nat.add_left_cancel h) + +theorem actualClasses_reduced (D : ℕ) (hD : 0 < D) (A B : ℤ) (a : ℕ → ℤ) + (hA : IsUnit (A : ZMod D)) (hB : IsUnit (B : ZMod D)) + (p : ℕ) (hp : p ∈ actualClasses D A B a) : + p < D * radical D ∧ Nat.Coprime p (D * radical D) := by + have hrange := Finset.mem_range.mp (Finset.mem_filter.mp hp).1 + rw [actualClasses_eq_lifts D (baseResidue D A B) hD (baseResidue_lt D hD A B) + A B a hB (baseResidue_integral D hD A B hB)] at hp + obtain ⟨k,_,rfl⟩ := Finset.mem_image.mp hp + exact ⟨hrange, lift_coprime D _ k + (base_coprime D _ A B hA (baseResidue_integral D hD A B hB))⟩ + +theorem actualClasses_fraction (D : ℕ) (hD : 0 < D) (A B : ℤ) (a : ℕ → ℤ) + (hB : IsUnit (B : ZMod D)) : + ((actualClasses D A B a).card : ℚ) / (D * radical D).totient = 1 / (D : ℚ) := by + rw [actualClasses_card D hD A B a hB, totient_lift_modulus D hD, Nat.cast_mul] + have ht : ((radical D).totient : ℚ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (radical_pos D)).ne' + have hd : (D : ℚ) ≠ 0 := by exact_mod_cast hD.ne' + field_simp + +theorem intCast_isUnit_of_natAbs_coprime (D : ℕ) (B : ℤ) + (hB : Nat.Coprime B.natAbs D) : IsUnit (B : ZMod D) := by + have hh := (ZMod.isUnit_iff_coprime B.natAbs D).mpr hB + have ha : IsUnit ((|B| : ℤ) : ZMod D) := by + simpa only [← Int.natCast_natAbs, Int.cast_natCast] using hh + rcases le_total 0 B with hp | hn + · simpa only [abs_of_nonneg hp] using ha + · have ht : IsUnit (-(B : ZMod D)) := by simpa only [abs_of_nonpos hn, Int.cast_neg] using ha + simpa only [neg_neg] using ht.neg + +theorem actual_unit_lift_packet (D : ℕ) (hD : 0 < D) (A B : ℤ) (a : ℕ → ℤ) + (hA : Nat.Coprime A.natAbs D) (hB : Nat.Coprime B.natAbs D) : + (∀ p ∈ actualClasses D A B a, p < D * radical D ∧ Nat.Coprime p (D * radical D)) ∧ + (actualClasses D A B a).card = (radical D).totient ∧ + ((actualClasses D A B a).card : ℚ) / (D * radical D).totient = 1 / (D : ℚ) := by + have hAu := intCast_isUnit_of_natAbs_coprime D A hA + have hBu := intCast_isUnit_of_natAbs_coprime D B hB + exact ⟨fun p hp => actualClasses_reduced D hD A B a hAu hBu p hp, + actualClasses_card D hD A B a hBu, actualClasses_fraction D hD A B a hBu⟩ + +theorem actualClasses_one (A B : ℤ) (a : ℕ → ℤ) : actualClasses 1 A B a = {0} := by + simp [actualClasses, radical] + +theorem actual_lift_forbidden_iff (D : ℕ) (hD : 0 < D) (A B : ℤ) + (hB : IsUnit (B : ZMod D)) (a : ℕ → ℤ) (p0 k t : ℕ) + (ht : t ∈ D.primeFactors) : + (actualN D A B (p0 + D * k) : ZMod t) = a t ↔ + (k : ZMod t) = (B : ZMod t)⁻¹ * (a t - actualN D A B p0) := by + have hb : IsUnit (B : ZMod t) := by + simpa using hB.map (ZMod.castHom (Nat.dvd_of_mem_primeFactors ht) (ZMod t)) + rw [actualN_lift D hD] + simp only [Int.cast_add, Int.cast_mul, Int.cast_natCast] + exact affine_eq_iff t (actualN D A B p0) B (a t) hb (k : ZMod t) + +def reducedClasses (Q : ℕ) : Finset ℕ := + (Finset.range Q).filter (fun p => Nat.Coprime p Q) + +theorem reducedClasses_card (Q : ℕ) : (reducedClasses Q).card = Q.totient := by + simp only [reducedClasses, Nat.totient_eq_card_coprime, Nat.coprime_comm] + +theorem actual_unit_lift_finite_fraction (D : ℕ) (hD : 0 < D) (A B : ℤ) + (a : ℕ → ℤ) (hA : Nat.Coprime A.natAbs D) (hB : Nat.Coprime B.natAbs D) : + actualClasses D A B a ⊆ reducedClasses (D * radical D) ∧ + (actualClasses D A B a).card = ∏ t ∈ D.primeFactors, (t - 1) ∧ + ((actualClasses D A B a).card : ℚ) / (reducedClasses (D * radical D)).card = + 1 / (D : ℚ) := by + obtain ⟨hr,hc,hf⟩ := actual_unit_lift_packet D hD A B a hA hB + refine ⟨?_, hc.trans (totient_radical D), ?_⟩ + · intro p hp + obtain ⟨hpr,hpc⟩ := hr p hp + exact Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hpr, hpc⟩ + · simpa only [reducedClasses_card] using hf + +end ErdosUnitLifts + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/AdmittedHighRemoval.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/AdmittedHighRemoval.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b87bf74c21511755449b51519801101ad558063 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/AdmittedHighRemoval.lean @@ -0,0 +1,88 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ContinuousHighRemoval +import OAI.NumberTheory.Jacobsthal.Paths.FlaggedHarmonicPaths + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.AdmittedHighRemoval + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathMeasures ArrivalKernelGeometry AdmittedHarmonicPaths +open RegeneratingInverseBands FlaggedHarmonicPaths KernelMappedDomination + +theorem pow_map_state (v ell S : ℝ) (n : ℕ) (z : FlagState) : + (((FlaggedHarmonicPaths.kernel v ell S)^n) z).map Prod.fst = + ((admittedHarmonic v ell)^n) z.1 := by + exact mapped_pow_eq _ _ Prod.fst measurable_fst (kernel_map_state v ell S) n z + +theorem pow_map_coordinates_le (v S : ℝ) {ell : ℝ} (hell : 0 ≤ ell) (n : ℕ) (z : FlagState) : + (((FlaggedHarmonicPaths.kernel v ell S)^n) z).map (coordinates v) ≤ + ((ErdosPrimeInputs.HighPrefixKernel.kernel ell S)^n) (coordinates v z) := + mapped_pow_le _ _ (coordinates v) (coordinates_measurable v) + (kernel_map_coordinates_le v S hell) n z + +noncomputable def lowHighMass (v ell S : ℝ) (z : CostState) (K : ℝ) : ℝ≥0∞ := + ∑' n : ℕ, ((FlaggedHarmonicPaths.kernel v ell S)^n) (initial S z) + {y : FlagState | y.2 = true ∧ gapValue v y.1 ≤ K} + +noncomputable def reward (v c : ℝ) (y : FlagState) : ℝ≥0∞ := + if y.2 = true ∧ 0 ≤ gapValue v y.1 then ENNReal.ofReal (Real.exp (-c * gapValue v y.1)) else 0 + +noncomputable def rewardedHighMass (v ell S : ℝ) (z : CostState) (c : ℝ) : ℝ≥0∞ := + ∑' n : ℕ, ∫⁻ y, reward v c y ∂((FlaggedHarmonicPaths.kernel v ell S)^n) (initial S z) + +theorem low_mass_le_unrestricted (v S : ℝ) {ell : ℝ} (hell : 0 ≤ ell) (z : CostState) (K : ℝ) : + lowHighMass v ell S z K ≤ ErdosPrimeInputs.HighPrefixBounds.lowHighMass ell S + (currentExponent v z) (gapValue v z) K := by + unfold lowHighMass ErdosPrimeInputs.HighPrefixBounds.lowHighMass + apply ENNReal.tsum_le_tsum + intro n + let A : Set ExponentState := {y | y.2.2 = true ∧ y.2.1 ≤ K} + have hA : MeasurableSet A := by + exact ((measurable_snd.comp measurable_snd) (measurableSet_singleton true)).inter + (measurableSet_le (measurable_fst.comp measurable_snd) measurable_const) + have h := Measure.le_iff.mp (pow_map_coordinates_le v S hell n (initial S z)) A hA + rw [Measure.map_apply (coordinates_measurable v) hA, initial_coordinates] at h + exact h + +theorem reward_mass_le_unrestricted (v S : ℝ) {ell : ℝ} (hell : 0 ≤ ell) (z : CostState) (c : ℝ) : + rewardedHighMass v ell S z c ≤ ErdosPrimeInputs.HighPrefixBounds.rewardedHighMass ell S + (currentExponent v z) (gapValue v z) c := by + have h := mapped_prefix_sum_le (FlaggedHarmonicPaths.kernel v ell S) + (ErdosPrimeInputs.HighPrefixKernel.kernel ell S) (coordinates v) (coordinates_measurable v) + (kernel_map_coordinates_le v S hell) (initial S z) + (ErdosPrimeInputs.HighPrefixBounds.reward_measurable c) + rw [initial_coordinates] at h + exact h + +theorem low_gap_high_removal (K A : ℝ) : ∀ᶠ B : ℝ in atTop, + ∀ v ell : ℝ, ∀ z : CostState, 1 ≤ ell → ell ≤ B → currentExponent v z = B → + lowHighMass v ell ((Real.log B)^2) z K ≤ ENNReal.ofReal (B^(-A)) := by + filter_upwards [ErdosPrimeInputs.ContinuousHighRemoval.low_gap_high_removal K A] with B hB + intro v ell z hell hellB hexp + calc + _ ≤ ErdosPrimeInputs.HighPrefixBounds.lowHighMass ell ((Real.log B)^2) + (currentExponent v z) (gapValue v z) K := low_mass_le_unrestricted v _ (by linarith) z K + _ ≤ _ := by rw [hexp]; exact hB ell hell hellB (gapValue v z) + +theorem rewarded_high_removal (c : ℝ) (hc : 0 < c) (A : ℝ) : ∀ᶠ B : ℝ in atTop, + ∀ v ell : ℝ, ∀ z : CostState, 1 ≤ ell → ell ≤ B → currentExponent v z = B → + rewardedHighMass v ell ((Real.log B)^2) z c ≤ ENNReal.ofReal (B^(-A)) := by + filter_upwards [ErdosPrimeInputs.ContinuousHighRemoval.rewarded_high_removal c hc A] with B hB + intro v ell z hell hellB hexp + calc + _ ≤ ErdosPrimeInputs.HighPrefixBounds.rewardedHighMass ell ((Real.log B)^2) + (currentExponent v z) (gapValue v z) c := reward_mass_le_unrestricted v _ (by linarith) z c + _ ≤ _ := by rw [hexp]; exact hB ell hell hellB (gapValue v z) + +end NumberTheoryLean.AdmittedHighRemoval + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/BivariateCalculus.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BivariateCalculus.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffd42bedff60694c551399a9a0cff40c43f4c385 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BivariateCalculus.lean @@ -0,0 +1,75 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosImplicitCurvature + +abbrev Bivariate := MvPolynomial (Fin 2) ℝ + +noncomputable def peval (Q : Bivariate) (x y : ℝ) : ℝ := + MvPolynomial.eval (fun i : Fin 2 => if i = 0 then x else y) Q + +noncomputable def partialX (Q : Bivariate) : Bivariate := MvPolynomial.pderiv 0 Q +noncomputable def partialY (Q : Bivariate) : Bivariate := MvPolynomial.pderiv 1 Q + +@[simp] theorem peval_C (c x y : ℝ) : peval (MvPolynomial.C c) x y = c := by + simp [peval] +@[simp] theorem peval_add (P Q : Bivariate) (x y : ℝ) : + peval (P+Q) x y = peval P x y+peval Q x y := by simp [peval] +@[simp] theorem peval_mul (P Q : Bivariate) (x y : ℝ) : + peval (P*Q) x y = peval P x y*peval Q x y := by simp [peval] +@[simp] theorem peval_X_zero (x y : ℝ) : peval (MvPolynomial.X 0) x y = x := by simp [peval] +@[simp] theorem peval_X_one (x y : ℝ) : peval (MvPolynomial.X 1) x y = y := by simp [peval] +@[simp] theorem peval_zero (x y : ℝ) : peval 0 x y = 0 := by simp [peval] +@[simp] theorem peval_one (x y : ℝ) : peval 1 x y = 1 := by simp [peval] + +theorem mixed_partials (Q : Bivariate) : partialY (partialX Q) = partialX (partialY Q) := by + classical + ext m + simp [partialX, partialY, MvPolynomial.coeff_pderiv, + add_assoc, add_left_comm, add_comm, mul_left_comm, mul_comm] + +theorem hasDerivAt_peval (Q : Bivariate) (u v : ℝ → ℝ) (du dv x : ℝ) + (hu : HasDerivAt u du x) (hv : HasDerivAt v dv x) : + HasDerivAt (fun t => peval Q (u t) (v t)) + (peval (partialX Q) (u x) (v x)*du+peval (partialY Q) (u x) (v x)*dv) x := by + induction Q using MvPolynomial.induction_on with + | C c => simpa [partialX, partialY, MvPolynomial.pderiv_C] using hasDerivAt_const x c + | add P Q hP hQ => + have h := (hP.add hQ).congr_of_eventuallyEq + (Filter.Eventually.of_forall (fun t => peval_add P Q (u t) (v t))) + apply h.congr_deriv + simp only [partialX, partialY, map_add, peval_add] + ring + | mul_X P i hP => + fin_cases i + · have h := (hP.mul hu).congr_of_eventuallyEq + (Filter.Eventually.of_forall (fun t => show peval (P*MvPolynomial.X 0) (u t) (v t) = + peval P (u t) (v t)*u t by simp)) + apply h.congr_deriv + simp [partialX, partialY] + ring + · have h := (hP.mul hv).congr_of_eventuallyEq + (Filter.Eventually.of_forall (fun t => show peval (P*MvPolynomial.X 1) (u t) (v t) = + peval P (u t) (v t)*v t by simp)) + apply h.congr_deriv + simp [partialX, partialY] + ring + +theorem hasDerivAt_peval_graph (Q : Bivariate) (f : ℝ → ℝ) (df x : ℝ) + (hf : HasDerivAt f df x) : + HasDerivAt (fun t => peval Q t (f t)) + (peval (partialX Q) x (f x)+peval (partialY Q) x (f x)*df) x := by + simpa using hasDerivAt_peval Q id f 1 df x (hasDerivAt_id x) hf + +end ErdosImplicitCurvature + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/BivariateMonomialIndex.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BivariateMonomialIndex.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7ae1ee82e880896c321c4e8f8e2c28206d294d9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BivariateMonomialIndex.lean @@ -0,0 +1,45 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +abbrev MonomialIndex (D : ℕ) := Σ k : Fin (D+1), Fin (k.val+1) + +theorem monomialIndex_card (D : ℕ) : Fintype.card (MonomialIndex D) = (D+2).choose 2 := by + simp only [MonomialIndex,Fintype.card_sigma,Fintype.card_fin] + change (∑ i : Fin (D+1), (fun n : ℕ => n+1) i.val) = _ + rw [Fin.sum_univ_eq_sum_range (fun n : ℕ => n+1) (D+1)] + simpa only [Nat.choose_one_right,Nat.add_assoc] using Nat.sum_range_add_choose D 1 + +noncomputable def exponent {D : ℕ} (i : MonomialIndex D) : Fin 2 →₀ ℕ := + Finsupp.single 0 i.2.val + Finsupp.single 1 (i.1.val-i.2.val) + +theorem exponent_zero {D : ℕ} (i : MonomialIndex D) : exponent i 0 = i.2.val := by simp [exponent] + +theorem exponent_one {D : ℕ} (i : MonomialIndex D) : exponent i 1 = i.1.val-i.2.val := by simp [exponent] + +theorem exponent_injective (D : ℕ) : Function.Injective (@exponent D) := by + rintro ⟨k,j⟩ ⟨l,h⟩ he + have hx := congrArg (fun e : Fin 2 →₀ ℕ => e 0) he + have hy := congrArg (fun e : Fin 2 →₀ ℕ => e 1) he + simp only [exponent_zero,exponent_one] at hx hy + have hj := j.isLt + have hh := h.isLt + have hkl : k = l := Fin.ext (by omega) + subst l + have hjh : j = h := Fin.ext hx + subst h + rfl + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/BonferroniBlocks.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BonferroniBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..9bed208e58cfb231359de507f9ee894e9cc940b9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BonferroniBlocks.lean @@ -0,0 +1,337 @@ +import Mathlib.Data.Nat.Choose.Sum +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Sieve.IntervalBoundingSieve + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.BonferroniBlocks + +open scoped BigOperators + +noncomputable def alternatingChoose (m n : ℕ) : ℝ := + ∑ r ∈ Finset.range (m + 1), (-1 : ℝ) ^ r * n.choose r + +theorem alternatingChoose_zero (m : ℕ) : alternatingChoose m 0 = 1 := by + induction m with + | zero => simp [alternatingChoose] + | succ m ih => + unfold alternatingChoose at * + rw [Finset.sum_range_succ, ih] + simp + +theorem alternatingChoose_succ (m n : ℕ) : + alternatingChoose m (n + 1) = (-1 : ℝ) ^ m * n.choose m := by + unfold alternatingChoose + exact_mod_cast (Int.alternating_sum_range_choose_eq_choose (n := n) (m := m)) + +theorem alternatingChoose_even_nonneg (m n : ℕ) : 0 ≤ alternatingChoose (2 * m) n := by + cases n with + | zero => rw [alternatingChoose_zero]; norm_num + | succ n => + rw [alternatingChoose_succ] + simp only [pow_mul, neg_one_sq, one_pow, one_mul] + exact Nat.cast_nonneg _ + +theorem alternatingChoose_bounds (m n : ℕ) : + alternatingChoose (2 * m + 1) n ≤ (if n = 0 then 1 else 0 : ℝ) ∧ + (if n = 0 then 1 else 0 : ℝ) ≤ alternatingChoose (2 * m) n := by + cases n with + | zero => simp only [alternatingChoose_zero, ite_true, le_refl, and_self] + | succ n => + rw [alternatingChoose_succ, alternatingChoose_succ] + simp only [Nat.succ_ne_zero, ite_false, pow_add, pow_mul, neg_one_sq, one_pow, + pow_one, one_mul, neg_mul] + constructor + · exact neg_nonpos.mpr (Nat.cast_nonneg _) + · exact Nat.cast_nonneg _ + +theorem alternatingChoose_gap (m n : ℕ) : + alternatingChoose (2 * m) n - alternatingChoose (2 * m + 1) n = + (n.choose (2 * m + 1) : ℝ) := by + unfold alternatingChoose + rw [Finset.sum_range_succ (n := 2 * m + 1)] + simp only [pow_add, pow_mul, neg_one_sq, one_pow, pow_one, one_mul] + ring + +noncomputable def hitSet (P : Finset ℕ) (hit : ℕ → Prop) : Finset ℕ := by + classical + exact P.filter hit + +noncomputable def intersectionValue (T : Finset ℕ) (hit : ℕ → Prop) : ℝ := by + classical + exact if ∀ p ∈ T, hit p then 1 else 0 + +noncomputable def coefficientPolynomial (m : ℕ) (P : Finset ℕ) (hit : ℕ → Prop) : ℝ := + ∑ r ∈ Finset.range (m + 1), (-1 : ℝ) ^ r * + ∑ T ∈ P.powersetCard r, intersectionValue T hit + +noncomputable def survives (P : Finset ℕ) (hit : ℕ → Prop) : ℝ := by + classical + exact if ∀ p ∈ P, ¬ hit p then 1 else 0 + +theorem sum_intersectionValue_eq_choose (P : Finset ℕ) (hit : ℕ → Prop) (r : ℕ) : + (∑ T ∈ P.powersetCard r, intersectionValue T hit) = + ((hitSet P hit).card.choose r : ℝ) := by + classical + have hsets : (P.powersetCard r).filter (fun T => ∀ p ∈ T, hit p) = + (hitSet P hit).powersetCard r := by + ext T + simp only [hitSet, Finset.mem_filter, Finset.mem_powersetCard] + constructor + · rintro ⟨⟨hTP, hcard⟩, hhit⟩ + exact ⟨fun p hp => Finset.mem_filter.mpr ⟨hTP hp, hhit p hp⟩, hcard⟩ + · rintro ⟨hT, hcard⟩ + exact ⟨⟨fun p hp => (Finset.mem_filter.mp (hT hp)).1, hcard⟩, + fun p hp => (Finset.mem_filter.mp (hT hp)).2⟩ + unfold intersectionValue + rw [Finset.sum_boole, hsets, Finset.card_powersetCard] + +theorem coefficientPolynomial_eq_alternatingChoose (m : ℕ) (P : Finset ℕ) + (hit : ℕ → Prop) : + coefficientPolynomial m P hit = alternatingChoose m (hitSet P hit).card := by + unfold coefficientPolynomial alternatingChoose + apply Finset.sum_congr rfl + intro r _ + rw [sum_intersectionValue_eq_choose] + +theorem survives_eq_zero_count (P : Finset ℕ) (hit : ℕ → Prop) : + survives P hit = (if (hitSet P hit).card = 0 then 1 else 0 : ℝ) := by + classical + unfold survives + have heq : (∀ p ∈ P, ¬ hit p) ↔ (hitSet P hit).card = 0 := by + rw [hitSet, Finset.card_eq_zero, Finset.filter_eq_empty_iff] + simp only [heq] + +theorem coefficientPolynomial_bounds (m : ℕ) (P : Finset ℕ) (hit : ℕ → Prop) : + coefficientPolynomial (2 * m + 1) P hit ≤ survives P hit ∧ + survives P hit ≤ coefficientPolynomial (2 * m) P hit := by + rw [coefficientPolynomial_eq_alternatingChoose, coefficientPolynomial_eq_alternatingChoose, + survives_eq_zero_count] + exact alternatingChoose_bounds m _ + +theorem coefficientPolynomial_even_nonneg (m : ℕ) (P : Finset ℕ) (hit : ℕ → Prop) : + 0 ≤ coefficientPolynomial (2 * m) P hit := by + rw [coefficientPolynomial_eq_alternatingChoose] + exact alternatingChoose_even_nonneg _ _ + +theorem coefficientPolynomial_gap (m : ℕ) (P : Finset ℕ) (hit : ℕ → Prop) : + coefficientPolynomial (2 * m) P hit - coefficientPolynomial (2 * m + 1) P hit = + (((hitSet P hit).card).choose (2 * m + 1) : ℝ) := by + rw [coefficientPolynomial_eq_alternatingChoose, coefficientPolynomial_eq_alternatingChoose] + exact alternatingChoose_gap _ _ + +theorem coefficientPolynomial_eq_one_of_no_hits (m : ℕ) (P : Finset ℕ) + (hit : ℕ → Prop) (h : ∀ p ∈ P, ¬ hit p) : coefficientPolynomial m P hit = 1 := by + classical + have hset : hitSet P hit = ∅ := Finset.filter_eq_empty_iff.mpr h + rw [coefficientPolynomial_eq_alternatingChoose, hset, Finset.card_empty, + alternatingChoose_zero] + +noncomputable def blockUpper (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (hit : ℕ → Prop) : ℝ := + ∏ j ∈ B, coefficientPolynomial (2 * orders j) (blocks j) hit + +noncomputable def blockCorrection (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (hit : ℕ → Prop) : ℝ := + ∑ j ∈ B, + (coefficientPolynomial (2 * orders j) (blocks j) hit - + coefficientPolynomial (2 * orders j + 1) (blocks j) hit) * + ∏ i ∈ B.erase j, coefficientPolynomial (2 * orders i) (blocks i) hit + +noncomputable def blockLower (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (hit : ℕ → Prop) : ℝ := + blockUpper B blocks orders hit - blockCorrection B blocks orders hit + +theorem block_bounds (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (hit : ℕ → Prop) : + blockLower B blocks orders hit ≤ survives (B.biUnion blocks) hit ∧ + survives (B.biUnion blocks) hit ≤ blockUpper B blocks orders hit := by + classical + have hUpperNonneg : 0 ≤ blockUpper B blocks orders hit := + Finset.prod_nonneg fun j _ => coefficientPolynomial_even_nonneg _ _ _ + have hEraseNonneg : ∀ j, 0 ≤ ∏ i ∈ B.erase j, + coefficientPolynomial (2 * orders i) (blocks i) hit := by + intro j + exact Finset.prod_nonneg fun i _ => coefficientPolynomial_even_nonneg _ _ _ + have hCorrectionNonneg : ∀ j ∈ B, 0 ≤ + (coefficientPolynomial (2 * orders j) (blocks j) hit - + coefficientPolynomial (2 * orders j + 1) (blocks j) hit) * + ∏ i ∈ B.erase j, coefficientPolynomial (2 * orders i) (blocks i) hit := by + intro j _ + rw [coefficientPolynomial_gap] + exact mul_nonneg (Nat.cast_nonneg _) (hEraseNonneg j) + by_cases hgood : ∀ j ∈ B, ∀ p ∈ blocks j, ¬ hit p + · have hpoly : ∀ j ∈ B, ∀ m, + coefficientPolynomial m (blocks j) hit = 1 := by + intro j hj m + exact coefficientPolynomial_eq_one_of_no_hits m (blocks j) hit (hgood j hj) + have hupper : blockUpper B blocks orders hit = 1 := by + unfold blockUpper + apply Finset.prod_eq_one + intro j hj + exact hpoly j hj _ + have hcorr : blockCorrection B blocks orders hit = 0 := by + unfold blockCorrection + apply Finset.sum_eq_zero + intro j hj + rw [hpoly j hj _, hpoly j hj _, sub_self, zero_mul] + have hsurv : survives (B.biUnion blocks) hit = 1 := by + unfold survives + apply ite_eq_left + intro p hp + obtain ⟨j, hj, hpj⟩ := Finset.mem_biUnion.mp hp + exact hgood j hj p hpj + simp only [blockLower, hupper, hcorr, hsurv, sub_zero, le_refl, and_self] + · have hbad : ∃ j ∈ B, ∃ p ∈ blocks j, hit p := by + simpa only [not_forall, Classical.not_imp, not_not, exists_prop] using hgood + obtain ⟨j, hj, p, hp, hhit⟩ := hbad + have hsurvj : survives (blocks j) hit = 0 := by + unfold survives + exact ite_eq_right (fun h => h p hp hhit) + have hsurv : survives (B.biUnion blocks) hit = 0 := by + unfold survives + exact ite_eq_right (fun h => h p (Finset.mem_biUnion.mpr ⟨j, hj, hp⟩) hhit) + have hLj : coefficientPolynomial (2 * orders j + 1) (blocks j) hit ≤ 0 := by + simpa only [hsurvj] using (coefficientPolynomial_bounds (orders j) (blocks j) hit).1 + have hProdLe : blockUpper B blocks orders hit ≤ + (coefficientPolynomial (2 * orders j) (blocks j) hit - + coefficientPolynomial (2 * orders j + 1) (blocks j) hit) * + ∏ i ∈ B.erase j, coefficientPolynomial (2 * orders i) (blocks i) hit := by + unfold blockUpper + rw [← Finset.mul_prod_erase B _ hj] + exact mul_le_mul_of_nonneg_right (by linarith) (hEraseNonneg j) + have hSumLe : blockUpper B blocks orders hit ≤ blockCorrection B blocks orders hit := + hProdLe.trans (Finset.single_le_sum hCorrectionNonneg hj) + rw [hsurv] + exact ⟨sub_nonpos.mpr hSumLe, hUpperNonneg⟩ + +theorem weighted_block_bounds {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (hit : ℕ → α → Prop) : + (∑ x ∈ C, weight x * blockLower B blocks orders (fun p => hit p x)) ≤ + ∑ x ∈ C, weight x * survives (B.biUnion blocks) (fun p => hit p x) ∧ + (∑ x ∈ C, weight x * survives (B.biUnion blocks) (fun p => hit p x)) ≤ + ∑ x ∈ C, weight x * blockUpper B blocks orders (fun p => hit p x) := by + constructor + · apply Finset.sum_le_sum + intro x hx + exact mul_le_mul_of_nonneg_left (block_bounds B blocks orders (fun p => hit p x)).1 (hweight x hx) + · apply Finset.sum_le_sum + intro x hx + exact mul_le_mul_of_nonneg_left (block_bounds B blocks orders (fun p => hit p x)).2 (hweight x hx) + +theorem coefficient_abs (r : ℕ) : |(-1 : ℝ) ^ r| = 1 := by simp + +theorem coefficient_divisor_support (P : Finset ℕ) {v m r : ℕ} + (hv : 1 ≤ v) (hprime : ∀ p ∈ P, p.Prime) (hheight : ∀ p ∈ P, p ≤ v) + (hr : r ≤ m) {T : Finset ℕ} (hT : T ∈ P.powersetCard r) : + Squarefree (∏ p ∈ T, p) ∧ (∏ p ∈ T, p) ≤ v ^ m := by + obtain ⟨hTP, hcard⟩ := Finset.mem_powersetCard.mp hT + constructor + · exact IntervalBoundingSieve.squarefree_primeSet_product T (fun p hp => hprime p (hTP hp)) + · calc + (∏ p ∈ T, p) ≤ ∏ _p ∈ T, v := Finset.prod_le_prod (fun p hp => hheight p (hTP hp)) + _ = v ^ r := by simp only [Finset.prod_const, hcard] + _ ≤ v ^ m := Nat.pow_le_pow_right hv hr + +noncomputable def intersectionMass {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (T : Finset ℕ) : ℝ := + ∑ x ∈ C, weight x * intersectionValue T (fun p => hit p x) + +noncomputable def momentPolynomial (m : ℕ) (P : Finset ℕ) (M : Finset ℕ → ℝ) : ℝ := + ∑ r ∈ Finset.range (m + 1), (-1 : ℝ) ^ r * ∑ T ∈ P.powersetCard r, M T + +theorem weighted_polynomial_eq_moments {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (m : ℕ) (P : Finset ℕ) : + (∑ x ∈ C, weight x * coefficientPolynomial m P (fun p => hit p x)) = + momentPolynomial m P (intersectionMass C weight hit) := by + unfold coefficientPolynomial momentPolynomial intersectionMass + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro r _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro T _ + apply Finset.sum_congr rfl + intro x _ + ring + +theorem weighted_single_block_bounds {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (hit : ℕ → α → Prop) (m : ℕ) (P : Finset ℕ) : + momentPolynomial (2 * m + 1) P (intersectionMass C weight hit) ≤ + (∑ x ∈ C, weight x * survives P (fun p => hit p x)) ∧ + (∑ x ∈ C, weight x * survives P (fun p => hit p x)) ≤ + momentPolynomial (2 * m) P (intersectionMass C weight hit) := by + rw [← weighted_polynomial_eq_moments, ← weighted_polynomial_eq_moments] + constructor + · apply Finset.sum_le_sum + intro x hx + exact mul_le_mul_of_nonneg_left (coefficientPolynomial_bounds m P (fun p => hit p x)).1 (hweight x hx) + · apply Finset.sum_le_sum + intro x hx + exact mul_le_mul_of_nonneg_left (coefficientPolynomial_bounds m P (fun p => hit p x)).2 (hweight x hx) + +noncomputable def intersectionRemainder {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (X : ℝ) (g : ℕ → ℝ) (T : Finset ℕ) : ℝ := + intersectionMass C weight hit T - X * ∏ p ∈ T, g p + +theorem momentPolynomial_decomposition {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (X : ℝ) (g : ℕ → ℝ) (m : ℕ) (P : Finset ℕ) : + momentPolynomial m P (intersectionMass C weight hit) = + X * momentPolynomial m P (fun T => ∏ p ∈ T, g p) + + momentPolynomial m P (intersectionRemainder C weight hit X g) := by + unfold momentPolynomial intersectionRemainder + simp_rw [Finset.mul_sum] + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro r _ + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro T _ + ring + +theorem momentPolynomial_abs_le (m : ℕ) (P : Finset ℕ) (E : Finset ℕ → ℝ) : + |momentPolynomial m P E| ≤ + ∑ r ∈ Finset.range (m + 1), ∑ T ∈ P.powersetCard r, |E T| := by + unfold momentPolynomial + calc + _ ≤ ∑ r ∈ Finset.range (m + 1), |(-1 : ℝ) ^ r * ∑ T ∈ P.powersetCard r, E T| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ _ := by + apply Finset.sum_le_sum + intro r _ + rw [abs_mul, coefficient_abs, one_mul] + exact Finset.abs_sum_le_sum_abs _ _ + +theorem weighted_single_block_with_remainders {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (hit : ℕ → α → Prop) + (X : ℝ) (g : ℕ → ℝ) (m : ℕ) (P : Finset ℕ) : + X * momentPolynomial (2 * m + 1) P (fun T => ∏ p ∈ T, g p) - + (∑ r ∈ Finset.range (2 * m + 2), ∑ T ∈ P.powersetCard r, + |intersectionRemainder C weight hit X g T|) ≤ + (∑ x ∈ C, weight x * survives P (fun p => hit p x)) ∧ + (∑ x ∈ C, weight x * survives P (fun p => hit p x)) ≤ + X * momentPolynomial (2 * m) P (fun T => ∏ p ∈ T, g p) + + ∑ r ∈ Finset.range (2 * m + 1), ∑ T ∈ P.powersetCard r, + |intersectionRemainder C weight hit X g T| := by + have hb := weighted_single_block_bounds C weight hweight hit m P + rw [momentPolynomial_decomposition C weight hit X g, + momentPolynomial_decomposition C weight hit X g] at hb + have heven := momentPolynomial_abs_le (2 * m) P (intersectionRemainder C weight hit X g) + have hodd := momentPolynomial_abs_le (2 * m + 1) P (intersectionRemainder C weight hit X g) + have heven' := (abs_le.mp heven).2 + have hodd' := (abs_le.mp hodd).1 + constructor <;> linarith + +end NumberTheoryLean.BonferroniBlocks + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryGateSets.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryGateSets.lean new file mode 100644 index 0000000000000000000000000000000000000000..7cf0886423aba1e2ae1570144bc831756d2068dd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryGateSets.lean @@ -0,0 +1,291 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.IntegralDifferenceBound +import OAI.NumberTheory.Jacobsthal.Analysis.VariableUpperIntegral +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceWeightedQuadrature + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.MeasureTheory _root_.Set +namespace ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry + +noncomputable def boundaryTerm : ℕ → Side → ℝ → ℝ → ℝ + | 0,_,_,_ => 1 + | n+1,i,r,b => ∫ x in (1:ℝ)..upperCutoff i r b,boundaryTerm n i.flip (r-x) x/(max 1 x) + +theorem boundaryTerm_continuous (n : ℕ) (i : Side) : + Continuous (fun p : ℝ×ℝ => boundaryTerm n i p.1 p.2) := by + induction n generalizing i with + | zero => exact continuous_const + | succ n ih => + let F : (ℝ×ℝ) → ℝ → ℝ := fun p x => boundaryTerm n i.flip (p.1-x) x/(max 1 x) + have hchild : Continuous (fun q : (ℝ×ℝ)×ℝ => boundaryTerm n i.flip (q.1.1-q.2) q.2) := + (ih i.flip).comp ((continuous_fst.fst.sub continuous_snd).prodMk continuous_snd) + have hden : Continuous (fun q : (ℝ×ℝ)×ℝ => (max 1 q.2)⁻¹) := + (continuous_const.max continuous_snd).inv₀ (fun q => ne_of_gt (lt_of_lt_of_le (by norm_num : (0:ℝ)<1) (le_max_left 1 q.2))) + have hF : Continuous F.uncurry := by + have he : F.uncurry = (fun q : (ℝ×ℝ)×ℝ => boundaryTerm n i.flip (q.1.1-q.2) q.2) * + (fun q => (max 1 q.2)⁻¹) := by + funext ⟨p,x⟩ + exact div_eq_mul_inv _ _ + rw [he] + exact hchild.mul hden + exact continuous_variable_upper_integral F hF (fun p => upperCutoff i p.1 p.2) (upperCutoff_continuous i) + +theorem boundaryTerm_reciprocal (n : ℕ) (i : Side) (r b : ℝ) : + boundaryTerm (n+1) i r b = + ∫ x in (1:ℝ)..upperCutoff i r b,boundaryTerm n i.flip (r-x) x/x := by + change (∫ x in (1:ℝ)..upperCutoff i r b,boundaryTerm n i.flip (r-x) x/(max 1 x)) = _ + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (upperCutoff_bounds i r b).1] at hx + dsimp only + rw [max_eq_right hx.1] + +theorem boundaryTerm_low (n : ℕ) (i : Side) (r b : ℝ) (hb : b ≤ 1) : + boundaryTerm (n+1) i r b=0 := by + rw [boundaryTerm,upperCutoff_low hb,intervalIntegral.integral_same] + +theorem boundaryTerm_odd_small (n : ℕ) {r b : ℝ} (hr : r ≤ 4) : + boundaryTerm (n+1) .odd r b=0 := by + rw [boundaryTerm,upperCutoff_odd_small hr,intervalIntegral.integral_same] + +theorem boundaryTerm_depth_zero (n : ℕ) (i : Side) {r b : ℝ} (hr : r ≤ (n:ℝ)+1) : + boundaryTerm (n+2) i r b=0 := by + induction n generalizing i r b with + | zero => + cases i with + | odd => exact boundaryTerm_odd_small 1 (by norm_num at hr; linarith) + | even => + rw [boundaryTerm] + calc + _ = ∫ _x in (1:ℝ)..upperCutoff .even r b,(0:ℝ) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (upperCutoff_bounds .even r b).1] at hx + dsimp only [Side.flip] + rw [boundaryTerm_odd_small 0 (by norm_num at hr; linarith [hx.1]),zero_div] + _ = 0 := by simp + | succ n ih => + rw [show n+1+2=(n+2)+1 by omega,boundaryTerm] + calc + _ = ∫ _x in (1:ℝ)..upperCutoff i r b,(0:ℝ) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (upperCutoff_bounds i r b).1] at hx + dsimp only + have hchild : r-x ≤ (n:ℝ)+1 := by push_cast at hr; linarith [hx.1] + rw [ih i.flip hchild,zero_div] + _ = 0 := by simp + +end ErdosContinuousBoundary + +end + +section + +open _root_.MeasureTheory _root_.Set +namespace ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry + +noncomputable def boundaryIntegrand (n : ℕ) (i : Side) (r x : ℝ) : ℝ := + boundaryTerm n i.flip (r-x) x/(max 1 x) + +theorem boundaryIntegrand_continuous (n : ℕ) (i : Side) (r : ℝ) : + Continuous (boundaryIntegrand n i r) := by + have hc : Continuous (fun x : ℝ => boundaryTerm n i.flip (r-x) x) := + (boundaryTerm_continuous n i.flip).comp ((continuous_const.sub continuous_id).prodMk continuous_id) + have hd : Continuous (fun x : ℝ => (max 1 x)⁻¹) := + (continuous_const.max continuous_id).inv₀ (fun x => ne_of_gt (lt_of_lt_of_le (by norm_num : (0:ℝ)<1) (le_max_left 1 x))) + have he : boundaryIntegrand n i r = (fun x => boundaryTerm n i.flip (r-x) x)*(fun x => (max 1 x)⁻¹) := by + funext x + exact div_eq_mul_inv _ _ + rw [he] + exact hc.mul hd + +theorem boundaryIntegrand_integrable (n : ℕ) (i : Side) (r a b : ℝ) : + IntervalIntegrable (boundaryIntegrand n i r) volume a b := + (boundaryIntegrand_continuous n i r).intervalIntegrable a b + +theorem boundaryTerm_nonnegative (n : ℕ) (i : Side) (r b : ℝ) : 0 ≤ boundaryTerm n i r b := by + induction n generalizing i r b with + | zero => exact zero_le_one + | succ n ih => + apply intervalIntegral.integral_nonneg_of_forall (upperCutoff_bounds i r b).1 + intro x + exact div_nonneg (ih i.flip (r-x) x) (le_trans zero_le_one (le_max_left 1 x)) + +theorem boundaryTerm_abs_le_one (n : ℕ) (i : Side) (r b : ℝ) : |boundaryTerm n i r b| ≤ 1 := by + induction n generalizing i r b with + | zero => norm_num [boundaryTerm] + | succ n ih => + have hf (x : ℝ) : |boundaryTerm n i.flip (r-x) x/(max 1 x)| ≤ 1 := by + have hd : 0 < max (1:ℝ) x := lt_of_lt_of_le (by norm_num) (le_max_left _ _) + rw [abs_div,abs_of_pos hd] + exact (div_le_one hd).mpr ((ih i.flip (r-x) x).trans (le_max_left 1 x)) + have h := intervalIntegral.norm_integral_le_of_norm_le_const (a:=1) (b:=upperCutoff i r b) + (C:=1) (f:=fun x => boundaryTerm n i.flip (r-x) x/(max 1 x)) + (fun x _ => by simpa only [Real.norm_eq_abs] using hf x) + have hc := upperCutoff_bounds i r b + change |boundaryTerm (n+1) i r b| ≤ 1 + rw [Real.norm_eq_abs,one_mul,abs_of_nonneg (by linarith : 0 ≤ upperCutoff i r b-1)] at h + exact h.trans (by linarith) + +theorem boundaryIntegrand_abs_le_one (n : ℕ) (i : Side) (r x : ℝ) : + |boundaryIntegrand n i r x| ≤ 1 := by + have hd : 0 < max (1:ℝ) x := lt_of_lt_of_le (by norm_num) (le_max_left _ _) + rw [boundaryIntegrand,abs_div,abs_of_pos hd] + exact (div_le_one hd).mpr ((boundaryTerm_abs_le_one n i.flip (r-x) x).trans (le_max_left 1 x)) + +end ErdosContinuousBoundary + +end + +section + +namespace ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry + +theorem boundaryTerm_r_difference (n : ℕ) (i : Side) (b r s : ℝ) : + |boundaryTerm n i r b-boundaryTerm n i s b| ≤ (n:ℝ)*|r-s| := by + induction n generalizing i b r s with + | zero => simp [boundaryTerm] + | succ n ih => + let D : ℝ := (n:ℝ)*|r-s| + have hD : 0 ≤ D := by dsimp [D]; positivity + have hFG (x : ℝ) : |boundaryIntegrand n i r x-boundaryIntegrand n i s x| ≤ D := by + have hd : 0 < max (1:ℝ) x := lt_of_lt_of_le (by norm_num) (le_max_left _ _) + have hnum := ih i.flip x (r-x) (s-x) + have he : (r-x)-(s-x)=r-s := by ring + rw [he] at hnum + unfold boundaryIntegrand + rw [← sub_div,abs_div,abs_of_pos hd] + exact (div_le_div_of_nonneg_right hnum hd.le).trans (div_le_self hD (le_max_left 1 x)) + have h := integral_upper_difference_bound + (boundaryIntegrand n i r) (boundaryIntegrand n i s) + (boundaryIntegrand_continuous n i r) (boundaryIntegrand_continuous n i s) + (upperCutoff i r b) (upperCutoff i s b) D (upperCutoff_bounds i r b) hD hFG + (boundaryIntegrand_abs_le_one n i s) + have hc := upperCutoff_r_difference i b r s + have hh : |boundaryTerm (n+1) i r b-boundaryTerm (n+1) i s b| ≤ D+|r-s| := + h.trans (add_le_add le_rfl hc) + simpa only [D,Nat.cast_add,Nat.cast_one,add_mul,one_mul] using hh + +theorem boundaryTerm_b_difference (n : ℕ) (i : Side) (r b c : ℝ) : + |boundaryTerm n i r b-boundaryTerm n i r c| ≤ |b-c| := by + cases n with + | zero => simp [boundaryTerm] + | succ n => + have h := integral_upper_difference_bound + (boundaryIntegrand n i r) (boundaryIntegrand n i r) + (boundaryIntegrand_continuous n i r) (boundaryIntegrand_continuous n i r) + (upperCutoff i r b) (upperCutoff i r c) 0 (upperCutoff_bounds i r b) le_rfl + (by intro x; simp) (boundaryIntegrand_abs_le_one n i r) + have hh : |boundaryTerm (n+1) i r b-boundaryTerm (n+1) i r c| ≤ + |upperCutoff i r b-upperCutoff i r c| := by simpa only [zero_add] using! h + exact hh.trans (upperCutoff_b_difference i r b c) + +theorem boundaryTerm_child_lipschitz (n : ℕ) (i : Side) (r : ℝ) : + LipschitzWith ((n:NNReal)+1) (fun x => boundaryTerm n i (r-x) x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,NNReal.coe_add,NNReal.coe_natCast,NNReal.coe_one] + have h1 := boundaryTerm_r_difference n i x (r-x) (r-y) + have he : (r-x)-(r-y)=-(x-y) := by ring + rw [he,abs_neg] at h1 + have h2 := boundaryTerm_b_difference n i (r-y) x y + calc + _ = |(boundaryTerm n i (r-x) x-boundaryTerm n i (r-y) x)+ + (boundaryTerm n i (r-y) x-boundaryTerm n i (r-y) y)| := by congr 1; ring + _ ≤ |boundaryTerm n i (r-x) x-boundaryTerm n i (r-y) x|+ + |boundaryTerm n i (r-y) x-boundaryTerm n i (r-y) y| := abs_add_le _ _ + _ ≤ (n:ℝ)*|x-y|+|x-y| := add_le_add h1 h2 + _ = _ := by ring + +end ErdosContinuousBoundary + +end + +section + +open _root_.MeasureTheory _root_.Set +namespace ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceAdmission +open NumberTheoryLean.HarmonicPrimeAtomicMeasure NumberTheoryLean.HarmonicReferenceMeasure +open ErdosMonotoneQuadrature + +def boundaryGateSet (i : Side) (r b : ℝ) (closed : Bool) : Set ℝ := + {x | 1 < x ∧ x ≤ 2 ∧ (if closed then x ≤ b else x < b) ∧ childAdmitted i r x} + +theorem boundaryGateSet_closed (i : Side) (r b : ℝ) : + boundaryGateSet i r b true=Ioc 1 (upperCutoff i r b) := by + ext x + exact (mem_upperCutoff i r b x).symm + +theorem boundaryGateSet_open_inter (i : Side) (r b : ℝ) : + boundaryGateSet i r b false=Ioc 1 (upperCutoff i r b) ∩ Iio b := by + rw [← boundaryGateSet_closed] + ext x + change (1 < x ∧ x ≤ 2 ∧ x < b ∧ childAdmitted i r x) ↔ + (1 < x ∧ x ≤ 2 ∧ x ≤ b ∧ childAdmitted i r x) ∧ x < b + constructor + · rintro ⟨h1,h2,hb,hg⟩ + exact ⟨⟨h1,h2,hb.le,hg⟩,hb⟩ + · rintro ⟨⟨h1,h2,_hb,hg⟩,hb⟩ + exact ⟨h1,h2,hb,hg⟩ + +theorem boundaryGateSet_open_diff (i : Side) (r b : ℝ) : + boundaryGateSet i r b false=Ioc 1 (upperCutoff i r b) \ {b} := by + rw [← boundaryGateSet_closed] + ext x + change (1 < x ∧ x ≤ 2 ∧ x < b ∧ childAdmitted i r x) ↔ + (1 < x ∧ x ≤ 2 ∧ x ≤ b ∧ childAdmitted i r x) ∧ x ≠ b + constructor + · rintro ⟨h1,h2,hb,hg⟩ + exact ⟨⟨h1,h2,hb.le,hg⟩,ne_of_lt hb⟩ + · rintro ⟨⟨h1,h2,hb,hg⟩,hne⟩ + exact ⟨h1,h2,lt_of_le_of_ne hb hne,hg⟩ + +theorem boundaryGateSet_orderConnected (i : Side) (r b : ℝ) (closed : Bool) : + (boundaryGateSet i r b closed).OrdConnected := by + cases closed with + | false => rw [boundaryGateSet_open_inter]; exact ordConnected_Ioc.inter ordConnected_Iio + | true => rw [boundaryGateSet_closed]; exact ordConnected_Ioc + +theorem boundaryGateSet_subset (i : Side) (r b : ℝ) (closed : Bool) : + boundaryGateSet i r b closed ⊆ Icc 1 2 := fun _ hx => ⟨hx.1.le,hx.2.1⟩ + +theorem boundary_reference_integral (g : ℝ → ℝ) {J : Set ℝ} + (hJ : MeasurableSet J) (hsub : J ⊆ Icc 1 2) : + (∫ x in J,g x ∂referenceMeasure 1 2)=∫ x in J,g x/x := by + rw [referenceMeasure,reciprocalMeasure_integral _ (by norm_num : (0:ℝ)<1) _ hJ, + Measure.restrict_restrict hJ,inter_eq_left.mpr hsub] + apply setIntegral_congr_fun hJ + intro x hx + dsimp only + rw [reciprocalWeight_eq (hsub hx).1] + simp only [div_eq_mul_inv,mul_comm] + +theorem boundaryTerm_gate_integral (n : ℕ) (i : Side) (r b : ℝ) (closed : Bool) : + (∫ x in boundaryGateSet i r b closed,boundaryTerm n i.flip (r-x) x ∂referenceMeasure 1 2)= + boundaryTerm (n+1) i r b := by + rw [boundary_reference_integral _ (boundaryGateSet_orderConnected i r b closed).measurableSet + (boundaryGateSet_subset i r b closed),boundaryTerm_reciprocal, + intervalIntegral.integral_of_le (upperCutoff_bounds i r b).1] + cases closed with + | true => rw [boundaryGateSet_closed] + | false => + rw [boundaryGateSet_open_diff] + exact setIntegral_congr_set (sdiff_null_ae_eq_self (measure_singleton b)) + +end ErdosContinuousBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryRadialCoefficient.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryRadialCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..70d563e6a3bd87194858141aaedccd4760a85f46 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryRadialCoefficient.lean @@ -0,0 +1,125 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.WeightedAnomalyConvergence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosBoundaryIntegral +open ErdosContinuousBoundary ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceBenchmarkDecay +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.BuchstabBridge + +noncomputable def lowerReference (y : ℝ) : ℝ := 2*boundaryReference .even (2*y+2) 2 +noncomputable def upperReference (y : ℝ) : ℝ := 2*boundaryReference .odd (2*y+2) 2 + +theorem lower_reference_deviation (y : ℝ) : + lowerReference y-f sieveA (y+1)=2*shiftedAnomaly .even y := by + unfold lowerReference shiftedAnomaly continuousAnomaly + have he : (2*y+2)/2=y+1 := by ring + rw [he,benchmark] + ring + +theorem upper_reference_deviation (y : ℝ) : + upperReference y-F sieveA (y+1)=2*shiftedAnomaly .odd y := by + unfold upperReference shiftedAnomaly continuousAnomaly + have he : (2*y+2)/2=y+1 := by ring + rw [he,benchmark] + ring + +theorem lower_coefficient_integrable : + IntegrableOn (fun y : ℝ => (y^2-1)*(lowerReference y-f sieveA (y+1))) (Ioi 1) := by + have h0 : IntegrableOn (shiftedAnomaly .even) (Ioi 0) := by + simpa only [pow_zero,one_mul] using shifted_anomaly_moment_integrable .even 0 + have h2 := shifted_anomaly_moment_integrable .even 2 + have hh : IntegrableOn (fun y : ℝ => 2*(y^2*shiftedAnomaly .even y-shiftedAnomaly .even y)) (Ioi 1) volume := + ((h2.sub h0).mono_set (by intro y hy; change 0 < y; change 1 < y at hy; linarith)).const_mul (2:ℝ) + apply hh.congr_fun _ measurableSet_Ioi + intro y _hy + dsimp only + rw [lower_reference_deviation] + ring + +theorem upper_coefficient_integrable : + IntegrableOn (fun y : ℝ => y^2*(upperReference y-F sieveA (y+1))) (Ioi 0) := by + have hh : IntegrableOn (fun y : ℝ => 2*(y^2*shiftedAnomaly .odd y)) (Ioi 0) volume := + (shifted_anomaly_moment_integrable .odd 2).const_mul (2:ℝ) + apply hh.congr_fun _ measurableSet_Ioi + intro y _hy + dsimp only + rw [upper_reference_deviation] + ring + +noncomputable def signedCoefficientI : ℝ := + (∫ y in Ioi 1,(y^2-1)*(lowerReference y-f sieveA (y+1)))- + ∫ y in Ioi 0,y^2*(upperReference y-F sieveA (y+1)) + +theorem signedCoefficient_eq_anomaly : + signedCoefficientI = + 2*(∫ y in Ioi 1,(y^2-1)*shiftedAnomaly .even y)- + 2*(∫ y in Ioi 0,y^2*shiftedAnomaly .odd y) := by + unfold signedCoefficientI + simp_rw [lower_reference_deviation,upper_reference_deviation] + have he (y : ℝ) : (y^2-1)*(2*shiftedAnomaly .even y)=2*((y^2-1)*shiftedAnomaly .even y) := by ring + have ho (y : ℝ) : y^2*(2*shiftedAnomaly .odd y)=2*(y^2*shiftedAnomaly .odd y) := by ring + simp_rw [he,ho,integral_const_mul] + +end ErdosBoundaryIntegral + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosBoundaryIntegral +open ErdosContinuousAnomaly + +theorem boundary_affine_integral (a : ℝ) (g : ℝ → ℝ) : + (∫ r in Ioi (2*a+2),g r) = ∫ y in Ioi a,2*g (2*y+2) := by + have hd : ∀ x ∈ Ioi a,HasDerivWithinAt (fun y : ℝ => 2*y+2) 2 (Ioi a) x := by + intro x _ + convert! (((hasDerivAt_id x).const_mul 2).add_const 2).hasDerivWithinAt using 1 + simp + have hinj : InjOn (fun y : ℝ => 2*y+2) (Ioi a) := by + intro x _ y _ h + linarith + have him : (fun y : ℝ => 2*y+2) '' Ioi a=Ioi (2*a+2) := by + ext r + constructor + · rintro ⟨y,hy,rfl⟩ + change a < y at hy + change 2*a+2 < 2*y+2 + linarith + · intro hr + refine ⟨(r-2)/2,?_,by ring⟩ + change a < (r-2)/2 + change 2*a+2 < r at hr + linarith + have h := integral_image_eq_integral_abs_deriv_smul measurableSet_Ioi hd hinj g + rw [him] at h + simpa only [abs_of_pos (by norm_num : (0:ℝ)<2),smul_eq_mul] using! h + +theorem radial_coefficient_eq_twice_I : + ((∫ r in Ioi 4,r*(r/2-2)*continuousAnomaly .even r)- + ∫ r in Ioi 2,(r^2/2-2*r+2)*continuousAnomaly .odd r)=2*signedCoefficientI := by + have he := boundary_affine_integral 1 (fun r => r*(r/2-2)*continuousAnomaly .even r) + have ho := boundary_affine_integral 0 (fun r => (r^2/2-2*r+2)*continuousAnomaly .odd r) + norm_num only [mul_one,mul_zero,zero_add] at he ho + rw [he,ho,signedCoefficient_eq_anomaly] + have he' (y : ℝ) : 2*((2*y+2)*((2*y+2)/2-2)*continuousAnomaly .even (2*y+2))= + 4*((y^2-1)*shiftedAnomaly .even y) := by unfold shiftedAnomaly; ring + have ho' (y : ℝ) : 2*(((2*y+2)^2/2-2*(2*y+2)+2)*continuousAnomaly .odd (2*y+2))= + 4*(y^2*shiftedAnomaly .odd y) := by unfold shiftedAnomaly; ring + simp_rw [he',ho',integral_const_mul] + ring + +end ErdosBoundaryIntegral + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryReferenceConvergence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryReferenceConvergence.lean new file mode 100644 index 0000000000000000000000000000000000000000..34d3a3c98a7ea99027b2b4bf8877711cd94c7655 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundaryReferenceConvergence.lean @@ -0,0 +1,460 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ContinuousReference +import OAI.NumberTheory.Jacobsthal.Primes.BoundaryPrimeStep +import OAI.NumberTheory.Jacobsthal.Primes.ReferenceSourcePrimeSets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.DiscreteBoundaryTerms + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry ReferenceAdmission ReferencePruning ReferencePrefixRecurrence +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def D (n : ℕ) (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : ℝ := + ∑ ps ∈ (referencePrefixes w P i r).filter (fun ps => ps.length=n),prefixWeight ps + +theorem D_nonneg (n : ℕ) (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : 0 ≤ D n w P i r := + Finset.sum_nonneg (fun ps _ => prefixWeight_nonneg ps) + +theorem D_sum (n : ℕ) (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : + D n w P i r=∑ ps ∈ decreasingPrefixes P, + if admitted w i r ps ∧ ps.length=n then prefixWeight ps else 0 := by + rw [D,referencePrefixes,Finset.filter_filter,Finset.sum_filter] + +theorem D_zero (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : D 0 w P i r=1 := by + have he : (referencePrefixes w P i r).filter (fun ps => ps.length=0)={[]} := by + ext ps + simp only [Finset.mem_filter,List.length_eq_zero_iff,Finset.mem_singleton] + constructor + · exact fun h => h.2 + · intro hp + subst ps + refine ⟨Finset.mem_filter.mpr ⟨mem_decreasingPrefixes.mpr ⟨by simp,by simp⟩,trivial⟩,rfl⟩ + rw [D,he,Finset.sum_singleton] + simp [prefixWeight] + +theorem D_succ (n : ℕ) (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : + D (n+1) w P i r=∑ p ∈ P,if childAdmitted i r (primeExponent w p) then + (p:ℝ)⁻¹*D n w (P.filter (fun q => q simp [prefixWeight] + · simp [admitted,hc] + +end NumberTheoryLean.DiscreteBoundaryTerms + +end + +section + +namespace NumberTheoryLean.DiscreteBoundaryDepth + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry ReferenceAdmission DiscreteBoundaryTerms +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem odd_gate_impossible {w r : ℝ} {p : ℕ} (hp : 1 < primeExponent w p) (hr : r ≤ 4) : + ¬childAdmitted .odd r (primeExponent w p) := by + intro h + have hh := (le_max_right (2*primeExponent w p) (primeExponent w p+2)).trans h + nlinarith + +theorem odd_term_zero (n : ℕ) (w : ℝ) (P : Finset ℕ) {r : ℝ} + (hP : ∀ p ∈ P,1 < primeExponent w p) (hr : r ≤ 4) : D (n+1) w P .odd r=0 := by + rw [D_succ] + apply Finset.sum_eq_zero + intro p hp + rw [ite_eq_right (odd_gate_impossible (hP p hp) hr)] + +theorem D_two_zero (w : ℝ) (P : Finset ℕ) (i : Side) {r : ℝ} + (hP : ∀ p ∈ P,1 < primeExponent w p) (hr : r ≤ 1) : D 2 w P i r=0 := by + cases i with + | odd => exact odd_term_zero 1 w P hP (by linarith) + | even => + rw [show (2:ℕ)=1+1 from rfl,D_succ] + apply Finset.sum_eq_zero + intro p hp + have ht : D 1 w (P.filter (fun q => q hP q (Finset.mem_filter.mp hq).1) (by have hx := hP p hp; linarith) + simp only [childAdmitted,ite_true,Side.flip,ht,mul_zero] + +theorem D_vanish (n : ℕ) (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) + (hP : ∀ p ∈ P,1 < primeExponent w p) (hr : r ≤ (n:ℝ)+1) : D (n+2) w P i r=0 := by + induction n generalizing P i r with + | zero => exact D_two_zero w P i hP (by simpa only [Nat.cast_zero,zero_add] using hr) + | succ n ih => + rw [show n+1+2=(n+2)+1 by omega,D_succ] + apply Finset.sum_eq_zero + intro p hp + have hx := hP p hp + have hr' : r-primeExponent w p ≤ (n:ℝ)+1 := by + push_cast at hr + linarith + have hz := ih (P:=P.filter (fun q => q hP q (Finset.mem_filter.mp hq).1) hr' + simp only [hz,mul_zero,ite_self] + +theorem prefixWeight_positive {w : ℝ} {P : Finset ℕ} {ps : List ℕ} + (hP : ∀ p ∈ P,1 < primeExponent w p) (hm : ∀ p ∈ ps,p ∈ P) : 0 < prefixWeight ps := by + induction ps with + | nil => simp [prefixWeight] + | cons p ps ih => + have hp := hP p (hm p (by simp)) + have hp0 : p ≠ 0 := by + intro he + simp only [he,primeExponent,Nat.cast_zero,Real.log_zero,zero_div] at hp + linarith + have hpr : 0 < (p:ℝ) := by exact_mod_cast Nat.pos_of_ne_zero hp0 + have ht := ih (fun q hq => hm q (by simp [hq])) + simpa only [prefixWeight,List.map_cons,List.prod_cons] using mul_pos (inv_pos.mpr hpr) ht + +theorem D_positive_of_member {w r : ℝ} {P : Finset ℕ} {i : Side} {ps : List ℕ} + (hP : ∀ p ∈ P,1 < primeExponent w p) (hp : ps ∈ referencePrefixes w P i r) : + 0 < D ps.length w P i r := by + apply Finset.sum_pos' (fun qs _ => prefixWeight_nonneg qs) + refine ⟨ps,Finset.mem_filter.mpr ⟨hp,rfl⟩,?_⟩ + exact prefixWeight_positive hP (mem_decreasingPrefixes.mp (Finset.mem_filter.mp hp).1).2 + +theorem admitted_length_lt {w r : ℝ} {P : Finset ℕ} {i : Side} {N : ℕ} + (hP : ∀ p ∈ P,1 < primeExponent w p) (hN : 2 ≤ N) (hr : r ≤ (N:ℝ)-1) + {ps : List ℕ} (hp : ps ∈ referencePrefixes w P i r) : ps.length (-1:ℝ)^ps.length*prefixWeight ps) + calc + _ = ∑ n ∈ Finset.range N,∑ ps ∈ (referencePrefixes w P i r).filter (fun ps => ps.length=n), + (-1:ℝ)^ps.length*prefixWeight ps := hf.symm + _ = _ := by + apply Finset.sum_congr rfl + intro n _hn + rw [D,Finset.mul_sum] + apply Finset.sum_congr rfl + intro ps hp + rw [(Finset.mem_filter.mp hp).2] + +end NumberTheoryLean.DiscreteBoundaryExpansion + +end + +section + +namespace NumberTheoryLean.ActualDiscreteBoundaryTerms + +attribute [local instance] Classical.propDecidable + +open _root_.Finset +open FinitePathGeometry ReferenceAdmission ReferenceProductsBasics ReferenceSourcePrimeSets +open DiscreteBoundaryTerms DiscreteBoundaryDepth DiscreteBoundaryExpansion +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def actualD (n : ℕ) (w b : ℝ) (closed : Bool) (i : Side) (r : ℝ) : ℝ := + D n w (availablePrimes w (w^b) closed) i r + +theorem actualD_zero (w b : ℝ) (closed : Bool) (i : Side) (r : ℝ) : actualD 0 w b closed i r=1 := + D_zero w _ i r + +theorem selected_exponent_bounds {w : ℝ} (hw : 1 < w) (b : ℝ) (closed : Bool) {p : ℕ} + (hp : p ∈ availablePrimes w (w^b) closed) : 1 < primeExponent w p ∧ primeExponent w p ≤ b := by + obtain ⟨_hp,hlo,hcap⟩ := (sourcePrimes_membership hw b closed p).mp hp + refine ⟨hlo,?_⟩ + cases closed + · exact hcap.le + · exact hcap + +theorem selected_available_set {w : ℝ} (hw : 1 < w) (b : ℝ) (closed : Bool) {p : ℕ} + (hp : p ∈ availablePrimes w (w^b) closed) : + availablePrimes w (w^primeExponent w p) false= + (availablePrimes w (w^b) closed).filter (fun q => q (boundary_exponent_bounds hw hb1 hb2 closed p hp).1) hr + +theorem actual_reference_finite_sum {w b : ℝ} (hw : 1 < w) (hb1 : 1 ≤ b) (hb2 : b ≤ 2) + (closed : Bool) (i : Side) (r : ℝ) (N : ℕ) (hN : 2 ≤ N) (hr : r ≤ (N:ℝ)-1) : + referencePolynomial w (availablePrimes w (w^b) closed) i r= + ∑ n ∈ Finset.range N,(-1:ℝ)^n*actualD n w b closed i r := + referencePolynomial_finite_sum w _ i r N (fun p hp => (boundary_exponent_bounds hw hb1 hb2 closed p hp).1) hN hr + +end NumberTheoryLean.ActualDiscreteBoundaryTerms + +end + +section + +open _root_.MeasureTheory _root_.Set _root_.Finset +namespace ErdosContinuousBoundary +attribute [local instance] Classical.propDecidable +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceAdmission +open NumberTheoryLean.ReferenceProductsBasics NumberTheoryLean.ReferenceSourcePrimeSets +open NumberTheoryLean.ActualDiscreteBoundaryTerms NumberTheoryLean.HarmonicPrimeAtomicMeasure +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem available_boundary_subset {w b : ℝ} (hw : 1 < w) (hb : b ≤ 2) (closed : Bool) : + availablePrimes w (w^b) closed ⊆ Nat.primesLE ⌊w^(2:ℝ)⌋₊ := by + intro p hp + have hpm := (sourcePrimes_membership hw b closed p).mp hp + have hx := (selected_exponent_bounds hw b closed hp).2.trans hb + have hpReal := (exponent_le_iff hw (by exact_mod_cast hpm.1.pos)).mp hx + exact Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) 2).le).mpr hpReal,hpm.1⟩ + +theorem boundary_gate_membership {w b : ℝ} (hw : 1 < w) (hb : b ≤ 2) + (closed : Bool) (i : Side) (r : ℝ) {p : ℕ} (hp : p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊) : + primeExponent w p ∈ boundaryGateSet i r b closed ↔ + p ∈ availablePrimes w (w^b) closed ∧ childAdmitted i r (primeExponent w p) := by + have hprime := (Nat.mem_primesLE.mp hp).2 + constructor + · intro h + refine ⟨(sourcePrimes_membership hw b closed p).mpr ⟨hprime,h.1,?_⟩,h.2.2.2⟩ + exact h.2.2.1 + · rintro ⟨hP,hgate⟩ + have h := (sourcePrimes_membership hw b closed p).mp hP + have hx2 := (selected_exponent_bounds hw b closed hP).2.trans hb + exact ⟨h.2.1,hx2,h.2.2,hgate⟩ + +theorem available_gate_sum {w b : ℝ} (hw : 1 < w) (hb : b ≤ 2) + (closed : Bool) (i : Side) (r : ℝ) (F : ℕ → ℝ) : + (∑ p ∈ availablePrimes w (w^b) closed,if childAdmitted i r (primeExponent w p) then + (p:ℝ)⁻¹*F p else 0) = + ∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ boundaryGateSet i r b closed then + (p:ℝ)⁻¹*F p else 0 := by + have hsub := available_boundary_subset hw hb closed + calc + _ = ∑ p ∈ availablePrimes w (w^b) closed,if primeExponent w p ∈ boundaryGateSet i r b closed then + (p:ℝ)⁻¹*F p else 0 := by + apply Finset.sum_congr rfl + intro p hp + have he : primeExponent w p ∈ boundaryGateSet i r b closed ↔ childAdmitted i r (primeExponent w p) := by + rw [boundary_gate_membership hw hb closed i r (hsub hp)] + simp only [hp,true_and] + simp only [he] + _ = _ := Finset.sum_subset hsub (by + intro p hp hnot + apply ite_eq_right + intro hgate + exact hnot ((boundary_gate_membership hw hb closed i r hp).mp hgate).1) + +theorem actualD_succ_gate_sum (n : ℕ) {w b : ℝ} (hw : 1 < w) (hb : b ≤ 2) + (closed : Bool) (i : Side) (r : ℝ) : + actualD (n+1) w b closed i r = + ∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ boundaryGateSet i r b closed then + (p:ℝ)⁻¹*actualD n w (primeExponent w p) false i.flip (r-primeExponent w p) else 0 := by + rw [actualD_succ n hw b closed i r] + exact available_gate_sum hw hb closed i r _ + +theorem prime_gate_sum_difference (w : ℝ) (i : Side) (r b : ℝ) (closed : Bool) + (F G : ℕ → ℝ) (A : ℝ) + (hFG : ∀ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,primeExponent w p ∈ boundaryGateSet i r b closed → |F p-G p| ≤ A) : + |(∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ boundaryGateSet i r b closed then (p:ℝ)⁻¹*F p else 0)- + (∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ boundaryGateSet i r b closed then (p:ℝ)⁻¹*G p else 0)| ≤ + A*(primeMeasure w 2).real (boundaryGateSet i r b closed) := by + rw [primeMeasure_real w 2 (boundaryGateSet_orderConnected i r b closed).measurableSet,Finset.mul_sum, + ← Finset.sum_sub_distrib] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro p hp + by_cases hg : primeExponent w p ∈ boundaryGateSet i r b closed + · rw [ite_eq_left hg,ite_eq_left hg,ite_eq_left hg,← mul_sub,abs_mul,abs_of_nonneg (by positivity : 0 ≤ (p:ℝ)⁻¹)] + have h := mul_le_mul_of_nonneg_left (hFG p hp hg) (by positivity : 0 ≤ (p:ℝ)⁻¹) + simpa only [mul_comm] using h + · simp only [hg,ite_false,sub_self,abs_zero,mul_zero,le_refl] + +end ErdosContinuousBoundary + +end + +section + +open _root_.MeasureTheory _root_.Set _root_.Finset +namespace ErdosContinuousBoundary +attribute [local instance] Classical.propDecidable +open NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.ActualDiscreteBoundaryTerms NumberTheoryLean.HarmonicPrimeAtomicMeasure +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem actualD_uniform_approximation : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ (n : ℕ) (w : ℝ),w₀ ≤ w → ∀ (i : Side) (r b : ℝ) (closed : Bool), + 1 ≤ b → b ≤ 2 → + |actualD n w b closed i r-boundaryTerm n i r b| ≤ 15*(n:ℝ)^2*boundaryPrimeError c C w := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hControl⟩ := boundary_prime_step_control + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro n + induction n with + | zero => + intro w _hw i r b closed _hb1 _hb2 + rw [actualD_zero] + norm_num [boundaryTerm] + | succ n ih => + intro w hw i r b closed _hb1 hb2 + have hw1 : 1 < w := hw₀.trans_le hw + obtain ⟨hMass,hStep⟩ := hControl w hw + let E := boundaryPrimeError c C w + have hE : 0 ≤ E := by dsimp [E,boundaryPrimeError]; positivity + let A := 15*(n:ℝ)^2*E + have hA : 0 ≤ A := by dsimp [A]; positivity + let J := boundaryGateSet i r b closed + let F : ℕ → ℝ := fun p => actualD n w (primeExponent w p) false i.flip (r-primeExponent w p) + let G : ℕ → ℝ := fun p => boundaryTerm n i.flip (r-primeExponent w p) (primeExponent w p) + have hFG : ∀ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,primeExponent w p ∈ J → |F p-G p| ≤ A := by + intro p _hp hJ + exact ih w hw i.flip (r-primeExponent w p) (primeExponent w p) false hJ.1.le hJ.2.1 + have hsum := prime_gate_sum_difference w i r b closed F G A hFG + have hM : (primeMeasure w 2).real J ≤ 1 := + (measureReal_mono (boundaryGateSet_subset i r b closed)).trans hMass + have hsum' : + |(∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*F p else 0)- + (∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*G p else 0)| ≤ A := by + exact hsum.trans (by simpa only [mul_one] using mul_le_mul_of_nonneg_left hM hA) + have hstep := hStep n i r b closed + have heq := actualD_succ_gate_sum n hw1 hb2 closed i r + rw [heq] + calc + _ ≤ A+(12*(n:ℝ)+15)*E := by + have he : + (∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*F p else 0)-boundaryTerm (n+1) i r b = + ((∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*F p else 0)- + (∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*G p else 0))+ + ((∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*G p else 0)-boundaryTerm (n+1) i r b) := by ring + change |(∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*F p else 0)-boundaryTerm (n+1) i r b| ≤ _ + rw [he] + exact (abs_add_le _ _).trans (add_le_add hsum' hstep) + _ = (15*(n:ℝ)^2+(12*(n:ℝ)+15))*E := by dsimp [A]; ring + _ ≤ 15*((n+1:ℕ):ℝ)^2*E := by + apply mul_le_mul_of_nonneg_right _ hE + push_cast + nlinarith [Nat.cast_nonneg (α:=ℝ) n] + +end ErdosContinuousBoundary + +end + +section + +open _root_.MeasureTheory _root_.Set _root_.Finset _root_.Filter +open scoped Topology +namespace ErdosContinuousBoundary +attribute [local instance] Classical.propDecidable +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceAdmission +open NumberTheoryLean.ReferenceProductsBasics NumberTheoryLean.ActualDiscreteBoundaryTerms + +theorem finite_reference_error {c C w : ℝ} (hC : 0 ≤ C) (hw : 1 < w) + (hterms : ∀ (n : ℕ) (i : Side) (r b : ℝ) (closed : Bool),1 ≤ b → b ≤ 2 → + |actualD n w b closed i r-boundaryTerm n i r b| ≤ 15*(n:ℝ)^2*boundaryPrimeError c C w) + (N : ℕ) (hN : 2 ≤ N) (i : Side) (r b : ℝ) (closed : Bool) + (hr : r ≤ (N:ℝ)-1) (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + |referencePolynomial w (availablePrimes w (w^b) closed) i r-boundaryReference i r b| ≤ + 15*(N:ℝ)^3*boundaryPrimeError c C w := by + rw [actual_reference_finite_sum hw hb1 hb2 closed i r N hN hr, + boundaryReference_eq_truncated N hN i hr,truncatedReference,← Finset.sum_sub_distrib] + have hE : 0 ≤ boundaryPrimeError c C w := by unfold boundaryPrimeError; positivity + calc + _ ≤ ∑ n ∈ Finset.range N, + |(-1:ℝ)^n*actualD n w b closed i r-(-1:ℝ)^n*boundaryTerm n i r b| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _n ∈ Finset.range N,15*(N:ℝ)^2*boundaryPrimeError c C w := by + apply Finset.sum_le_sum + intro n hn + rw [← mul_sub,abs_mul,abs_pow,abs_neg,abs_one,one_pow,one_mul] + apply (hterms n i r b closed hb1 hb2).trans + have hnN : (n:ℝ) ≤ N := by exact_mod_cast (Finset.mem_range.mp hn).le + gcongr + _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul]; ring + +theorem uniform_boundary_reference_convergence (R eps : ℝ) (heps : 0 < eps) : + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ (i : Side) (r b : ℝ) (closed : Bool), + r ≤ R → 1 ≤ b → b ≤ 2 → + |referencePolynomial w (availablePrimes w (w^b) closed) i r-boundaryReference i r b| ≤ eps := by + obtain ⟨c,C,wD,hc,hC,hwD,hD⟩ := actualD_uniform_approximation + let N := referenceDepth R + have hN : 2 ≤ N := (referenceDepth_bounds R).1 + have hdepth : R ≤ (N:ℝ)-1 := (referenceDepth_bounds R).2 + have ht := (boundaryPrimeError_tendsto_zero hc C).const_mul (15*(N:ℝ)^3) + have he := ht.eventually (Iio_mem_nhds (by simpa only [mul_zero] using heps)) + obtain ⟨wE,hwE⟩ := eventually_atTop.mp he + refine ⟨max wD wE,hwD.trans_le (le_max_left _ _),?_⟩ + intro w hw i r b closed hr hb1 hb2 + have hwd : wD ≤ w := (le_max_left _ _).trans hw + have hwe := hwE w ((le_max_right _ _).trans hw) + have hh := finite_reference_error hC.le (hwD.trans_le hwd) + (fun n j s a cl ha1 ha2 => hD n w hwd j s a cl ha1 ha2) + N hN i r b closed (hr.trans hdepth) hb1 hb2 + exact hh.trans hwe.le + +theorem boundary_two_convergence (R eps : ℝ) (heps : 0 < eps) : + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ (i : Side) (r : ℝ),r ≤ R → + |referencePolynomial w (boundaryPrimes w) i r-boundaryReference i r 2| ≤ eps := by + obtain ⟨w₀,hw₀,h⟩ := uniform_boundary_reference_convergence R eps heps + refine ⟨w₀,hw₀,?_⟩ + intro w hw i r hr + simpa only [availablePrimes_closed,boundaryPrimes] using h w hw i r 2 true hr (by norm_num) le_rfl + +end ErdosContinuousBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundedLossTerms.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundedLossTerms.lean new file mode 100644 index 0000000000000000000000000000000000000000..efacbfce6b65d17e49d3639df0812a0c13ede8a2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/BoundedLossTerms.lean @@ -0,0 +1,127 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.OrderedTriangleFubini + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceAdmission + +theorem force_as_threshold (a y : ℝ) {b : ℝ} (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + omissionForce .odd (2*y+2-a) b= + ∫ t : ℝ in 1..b,if y (t^2)⁻¹) t + rw [setIntegral_indicator hm,hset] + +theorem force_high_zero (i : Side) {r b : ℝ} (hr : 6 ≤ r) : omissionForce i r b=0 := by + cases i with + | even => rfl + | odd => + have hc : upperCutoff .odd r b=baseCutoff b := by + change max 1 (min (min 2 b) ((r-2)/2))=max 1 (min 2 b) + rw [min_eq_left ((min_le_left 2 b).trans (by linarith))] + simp only [omissionForce,hc,survivorBaseline,sub_self] + +theorem iterated_force_high_zero (n : ℕ) (i : Side) {r b : ℝ} + (hr : 2*(n:ℝ)+6 ≤ r) : gateIterate n omissionForce i r b=0 := by + induction n generalizing i r b with + | zero => exact force_high_zero i (by simpa only [Nat.cast_zero,mul_zero,zero_add] using hr) + | succ n ih => + rw [gateIterate,gate] + calc + _ = ∫ _x : ℝ in 1..upperCutoff i r b,(0:ℝ) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (upperCutoff_bounds i r b).1] at hx + dsimp only + have hx2 : x ≤ 2 := hx.2.trans (upperCutoff_bounds i r b).2 + rw [ih i.flip (by push_cast at hr; linarith : 2*(n:ℝ)+6 ≤ r-x),zero_div] + _ = 0 := by simp + +theorem omissionDensity_high_zero (n : ℕ) (i : Side) {y : ℝ} (hy : (n:ℝ)+2 ≤ y) : + omissionDensity n i y=0 := by + rw [omissionDensity,iterated_force_high_zero n i (by linarith : 2*(n:ℝ)+6 ≤ 2*y+2),mul_zero] + +end ErdosOmissionBindings + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission + +theorem second_loss_bounded : omissionLossTerm 1=∫ y : ℝ in 1..3,omissionDensity 1 .even y := by + have ho : (∫ y in sourceDomain .odd,omissionDensity 1 .odd y)=0 := by + apply setIntegral_eq_zero_of_forall_eq_zero + intro y _hy + have h := (omission_wrong_parity_zero 0).2 (2*y+2) 2 + norm_num only [Nat.mul_zero,Nat.zero_add] at h + rw [omissionDensity,h,mul_zero] + have hz : (∫ y in Ioi 3,omissionDensity 1 .even y)=0 := by + apply setIntegral_eq_zero_of_forall_eq_zero + intro y hy + exact omissionDensity_high_zero 1 .even (by norm_num; change 3 k Nat.zero_le (m b)) + rw [Finset.sum_insert hnot] at hsum + unfold suffixRank + omega + +theorem suffixRank_injective_singletons {n : ℕ} (m : Fin n → ℕ) : + Set.InjOn (suffixRank m) {j | m j=1} := by + intro j hj k hk he + rcases lt_trichotomy j k with hjk | rfl | hkj + · have hh := suffixRank_strict m j k hjk (by change m j=1 at hj; omega) + omega + · rfl + · have hh := suffixRank_strict m k j hkj (by change m k=1 at hk; omega) + omega + +theorem singleton_card_le_rank {n : ℕ} (m : Fin n → ℕ) (J : Finset (Fin n)) (H : ℕ) + (hm : ∀ j ∈ J,m j=1) (hH : ∀ j ∈ J,suffixRank m j ≤ H) : J.card ≤ H := by + have hinj : Set.InjOn (suffixRank m) (J : Set (Fin n)) := + fun j hj k hk he => suffixRank_injective_singletons m (hm j hj) (hm k hk) he + have hsub : J.image (suffixRank m) ⊆ Finset.Icc 1 H := by + intro r hr + obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hr + exact Finset.mem_Icc.mpr ⟨suffixRank_pos m j,hH j hj⟩ + have hh := Finset.card_le_card hsub + rw [Finset.card_image_of_injOn hinj] at hh + simpa using hh +end NumberTheoryLean.MultiplicitySuffixRank + + + +namespace NumberTheoryLean.BoundedEdgeSuffixRank +open FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport StrongSourceFamilies +open ErdosCofactorChoices ErdosSubsetWord BoundedEdgeBins FullBoxLengthBounds BinCutSelections SelectionWordSplit +open MultiplicitySuffixRank SafeSubsetBoxGeometry RepresentativeAdmission +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem list_length_le_exponents (w : ℝ) (ps : List ℕ) (hp : ∀ p ∈ ps,1 ≤ primeExponent w p) : + (ps.length:ℝ) ≤ (ps.map (primeExponent w)).sum := by + induction ps with + | nil => simp + | cons p ps ih => + have hh := ih (fun q hq => hp q (List.mem_cons_of_mem _ hq)) + have hp1 := hp p (by simp) + simp only [List.length_cons,Nat.cast_add,Nat.cast_one,List.map_cons,List.sum_cons] + linarith + +theorem bounded_edge_rank_le {w top xi B C K a M X : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) + (hcomp : Real.log B ≤ 2*Real.log w) (ha0 : 0 ≤ a) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) + (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) + (j : Fin (binCount w top xi)) (hj : boundedEdgeBin w top xi Y m M X j) : + suffixRank m j ≤ ⌈M⌉₊ := by + obtain ⟨f,hf,u,hfu,hparent,_hx⟩ := hj + have hword := selected_word_split hw htop hxi m f hf j u hfu + have hfull := (anchored_choice_geometry hw htop hxi hC hcomp z m ha f hf).1 + have hfloor := (source_reference_transport hw htop z hs hz hg hclosed hcap _ hfull).2 + have hsource := word_source_membership hw htop hxi m f hf + have hsuffix : ∀ p ∈ u::descendingWord (belowSelection f j),1 ≤ primeExponent w p := by + intro p hp + have hpfull : p ∈ descendingWord f := by rw [hword]; exact List.mem_append_right _ hp + have hpw := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hsource p hpfull) + change 1 ≤ Real.log (p:ℝ)/Real.log w + exact ((one_lt_div (Real.log_pos hw)).mpr (Real.log_lt_log (zero_lt_one.trans hw) hpw.2.1)).le + have hlength := list_length_le_exponents w (u::descendingWord (belowSelection f j)) hsuffix + have hgap : (terminal w z (descendingWord f)).gap= + (terminal w z (descendingWord (aboveSelection f j))).gap- + ((u::descendingWord (belowSelection f j)).map (primeExponent w)).sum := by + rw [hword,terminal_append] + exact terminal_gap_sum w _ _ + have hpar := parent_length_gap hw htop hxi Y hY z hroot m f hf j + have hrank : suffixRank m j=(u::descendingWord (belowSelection f j)).length := by + rw [← below_total_rank,List.length_cons,global_word_length hw htop hxi _ _ (below_selection_mem _ m f hf j)] + omega + have hreal : (suffixRank m j:ℝ) ≤ M := by rw [hrank]; nlinarith + exact_mod_cast (hreal.trans (Nat.le_ceil M)) +end NumberTheoryLean.BoundedEdgeSuffixRank + + + +namespace NumberTheoryLean.BoundedCandidateCount +open FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport +open SafeSubsetBoxGeometry GeometricBoxImages BoundedEdgeBins BoundedEdgeSuffixRank MultiplicitySuffixRank +open LogarithmicBinScale LogarithmicBinLabels + +attribute [local instance] Classical.propDecidable + +noncomputable def candidateBins (w top xi : ℝ) (Y : ℕ) (m : Fin (binCount w top xi) → ℕ) (M X : ℝ) : + Finset (Fin (binCount w top xi)) := Finset.univ.filter (boundedEdgeBin w top xi Y m M X) + +theorem candidate_bins_card_le {w top xi B C K a M X : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) + (hcomp : Real.log B ≤ 2*Real.log w) (ha0 : 0 ≤ a) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) + (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) : + (candidateBins w top xi Y m M X).card ≤ ⌈M⌉₊ := by + apply singleton_card_le_rank m _ _ + · intro j hj + exact bounded_edge_singleton m j (Finset.mem_filter.mp hj).2 + · intro j hj + exact bounded_edge_rank_le hw htop hxi hC hcomp ha0 Y hY z hroot hs hz hg hclosed hcap m ha j (Finset.mem_filter.mp hj).2 +end NumberTheoryLean.BoundedCandidateCount + + + +namespace NumberTheoryLean.RecentReferenceSegment +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission StrongReferenceTransport StrongSourceFamilies ActualPrimeHigh +open SourceFirstCrossing WordIntervalGeometry LatePrimeRatio BoundedEdgeSuffixRank ActualReferencePrefixes +open LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem recent_reference_segment {w top B K Kstar a : ℝ} (hw : 1 < w) (htop : w < top) + (hK : 3 ≤ K) (hKstar : K+10 ≤ Kstar) (ha0 : 0 ≤ a) (ha1 : a ≤ 1) + (hB3 : 3 ≤ B) (hBlarge : 2*(Kstar+2-a) ≤ B) + (Y : ℕ) (hY : 0 < Y) (z : Node) (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (hi : z.side=.even) (h199 : 199/100 ≤ z.ratio) (hz : Consistent z) (hcut : z.cutoff=B) + (hclosed : z.closed=true) (hpower : w^B=top) (ps : List ℕ) + (hps : ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap) + (hend : (terminal w z ps).gap ≤ K) : + ∃ pre rest : List ℕ,ps=pre++rest ∧ pre ≠ [] ∧ rest ≠ [] ∧ + Kstar < wordIntervalExponent w Y pre ∧ rest.length ≤ ⌈2*Kstar+10⌉₊ ∧ + ∀ before u after,rest=before++u::after → + wordIntervalExponent w Y (pre++before) ≤ 2*Kstar+3 ∧ + a ≤ wordIntervalExponent w Y ((pre++before)++[u]) ∧ + primeExponent w u ≤ 2*Kstar+3 ∧ (terminal w z (pre++before)).gap ≤ 2*Kstar+5 := by + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB3 z hi h199 hz hcut + have hcap : w^z.cutoff=top := by rwa [hcut] + have hu := (source_reference_transport hw htop z hs hz hg hclosed hcap ps hps).1 + have hua := (mem_uncappedPrefixes hw z ps).mp hu + obtain ⟨S,_hS,ha⟩ := (uncapped_iff_exists_ceiling w 1 z ps).mp hua + have hBp : 0 < B := by linarith + let H := Kstar+2-a + have hH : 0 < H := by dsimp [H]; linarith + have htheta : H/B ≤ 1/2 := by apply (div_le_iff₀ hBp).mpr; dsimp [H]; linarith + have hthetaB : (H/B)*B=H := div_mul_cancel₀ H hBp.ne' + have he : (terminal w z ps).gap ≤ (H/B)*B := by rw [hthetaB]; dsimp [H]; linarith + obtain ⟨pre,p,tail,hpre,hword,_hbefore,hcross,_hlo⟩ := + source_gap_crossing (by norm_num) hBp htheta z hs h199 hz hcut ps ha he + rw [hthetaB] at hcross _hbefore + have hword' : ps=(pre++[p])++tail := by simpa only [List.append_assoc,List.singleton_append] using hword + have hac : allowed w 1 S z (pre++[p]) := ((allowed_append w 1 S z (pre++[p]) tail).mp (hword' ▸ ha)).1 + have hlen : 2 ≤ (pre++[p]).length := by have hh := List.length_pos_iff.mpr hpre; simp only [List.length_append,List.length_singleton]; omega + have hlate := allowed_late_gap_cutoff hw (by norm_num : (1:ℝ)≤1) z (pre++[p]) hac hlen + have hxc : (terminal w z (pre++[p])).cutoff=primeExponent w p := by simp [terminal,step] + have hrc : (terminal w z (pre++[p])).gap=(terminal w z pre).gap-primeExponent w p := by simp [terminal,step] + rw [hxc] at hlate + have hpreGap : (terminal w z pre).gap ≤ 2*H := by linarith + have hsrc := (mem_decreasingPrefixes.mp (Finset.mem_filter.mp hps).1).2 + have hpos : ∀ q∈ps,0 < q := fun q hq => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop q).mp (hsrc q hq)).1.pos + have hexp : ∀ q∈ps,1 ≤ primeExponent w q := by + intro q hq + have hqw := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop q).mp (hsrc q hq) + exact ((one_lt_div (Real.log_pos hw)).mpr (Real.log_lt_log (zero_lt_one.trans hw) hqw.2.1)).le + have hpreSub : pre ⊆ ps := by intro q hq; rw [hword]; exact List.mem_append_left _ hq + have hrestSub : p::tail ⊆ ps := by intro q hq; rw [hword]; exact List.mem_append_right _ hq + have hvpre := word_interval_gap Y hY z hroot pre (fun q hq => hpos q (hpreSub hq)) + have hVpre : wordIntervalExponent w Y pre ≤ 2*Kstar+3 := by dsimp [H] at hpreGap; linarith + have hhigh : Kstar < wordIntervalExponent w Y pre := by dsimp [H] at _hbefore; linarith + have hfloor := (source_reference_transport hw htop z hs hz hg hclosed hcap ps hps).2 + have hsum := list_length_le_exponents w (p::tail) (fun q hq => hexp q (hrestSub hq)) + have hfinalGap : (terminal w z ps).gap=(terminal w z pre).gap-((p::tail).map (primeExponent w)).sum := by + rw [hword,terminal_append] + exact RepresentativeAdmission.terminal_gap_sum w _ _ + have hrestLength : (p::tail).length ≤ ⌈2*Kstar+10⌉₊ := by + have hh : ((p::tail).length:ℝ) ≤ 2*Kstar+10 := by linarith + exact_mod_cast hh.trans (Nat.le_ceil (2*Kstar+10)) + refine ⟨pre,p::tail,hword,hpre,by simp,hhigh,hrestLength,?_⟩ + intro before u after hrest + have hparword : ps=(pre++before)++u::after := by rw [hword,hrest,List.append_assoc] + have hchildword : ps=((pre++before)++[u])++after := by simpa only [List.append_assoc,List.singleton_append] using hparword + have hparSub : pre++before ⊆ ps := by intro q hq; rw [hparword]; exact List.mem_append_left _ hq + have hchildSub : (pre++before)++[u] ⊆ ps := by intro q hq; rw [hchildword]; exact List.mem_append_left _ hq + have hbeforeSub : before ⊆ ps := fun q hq => hparSub (List.mem_append_right _ hq) + have hmono := gap_prefix_mono w z pre before (fun q hq => (hexp q (hbeforeSub hq)).trans' (by norm_num)) + have hvpar := word_interval_gap Y hY z hroot (pre++before) (fun q hq => hpos q (hparSub hq)) + have hvchild := word_interval_gap Y hY z hroot ((pre++before)++[u]) (fun q hq => hpos q (hchildSub hq)) + have hchildin : (pre++before)++[u] ∈ ps.inits := (List.mem_inits _ _).mpr ⟨after,hchildword.symm⟩ + have hchildfloor := reference_prefix_gap_floor hw htop z hs hz hg hclosed hcap ps _ hps hchildin + have huMem : u ∈ ps := by rw [hparword]; simp + have hstep := interval_exponent_step w Y hY (pre++before) u + (List.prod_pos (fun q hq => hpos q (hparSub hq))) (hpos u huMem) + refine ⟨?_,?_,?_,?_⟩ <;> linarith +end NumberTheoryLean.RecentReferenceSegment + + + +namespace NumberTheoryLean.CandidateExceptionMass +open ErdosCofactorChoices BoxWitnessFactorization CanonicalSubsetBox TwoPrimeObservableSum ParentTailPartition + +attribute [local instance] Classical.propDecidable + +noncomputable def someWitnessMass {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i : Fin n) (J : Finset (Fin n)) (W : Fin n → (ℕ × ℕ) → ℕ → Prop) : ℝ := + ∑ f ∈ (selections P m).filter (fun f => ∃ j∈J,W j (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j)), + (selectionProduct f:ℝ)⁻¹ + +theorem some_witness_mass_le_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i : Fin n) (J : Finset (Fin n)) (W : Fin n → (ℕ × ℕ) → ℕ → Prop) : + someWitnessMass P m i J W ≤ ∑ j ∈ J,selectionWitnessMass P m i j (W j) := by + simp only [someWitnessMass,selectionWitnessMass,Finset.sum_filter] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro f _hf + have hn : 0 ≤ (selectionProduct f:ℝ)⁻¹ := by positivity + by_cases hex : ∃ j∈J,W j (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j) + · rw [ite_eq_left hex] + obtain ⟨j,hj,hw⟩ := hex + have hh := Finset.single_le_sum (fun k _hk => + show 0 ≤ if W k (pickedPrime f i,selectionProduct (parentCofactorSelection f i k)) (pickedPrime f k) then (selectionProduct f:ℝ)⁻¹ else 0 from by split_ifs <;> positivity) hj + simpa only [ite_eq_left hw] using hh + · rw [ite_eq_right hex] + exact Finset.sum_nonneg (fun j _ => by split_ifs <;> positivity) + +theorem some_witness_mass_bound {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i : Fin n) (J : Finset (Fin n)) (W : Fin n → (ℕ × ℕ) → ℕ → Prop) (sigma : ℝ) + (h : ∀ j∈J,selectionWitnessMass P m i j (W j) ≤ sigma*selectionMass P m) : + someWitnessMass P m i J W ≤ (J.card:ℝ)*sigma*selectionMass P m := by + have hh := (some_witness_mass_le_sum P m i J W).trans (Finset.sum_le_sum h) + simpa only [Finset.sum_const,nsmul_eq_mul,mul_assoc] using hh + +theorem some_witness_mass_card_bound {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i : Fin n) (J : Finset (Fin n)) (W : Fin n → (ℕ × ℕ) → ℕ → Prop) (sigma : ℝ) (hsigma : 0 ≤ sigma) + (H : ℕ) (hcard : J.card ≤ H) + (h : ∀ j∈J,selectionWitnessMass P m i j (W j) ≤ sigma*selectionMass P m) : + someWitnessMass P m i J W ≤ (H:ℝ)*sigma*selectionMass P m := by + have hm : 0 ≤ selectionMass P m := Finset.sum_nonneg (fun _ _ => by positivity) + have hc : (J.card:ℝ) ≤ H := by exact_mod_cast hcard + exact (some_witness_mass_bound P m i J W sigma h).trans + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hc hsigma) hm) +end NumberTheoryLean.CandidateExceptionMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CandidateLengthBand.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CandidateLengthBand.lean new file mode 100644 index 0000000000000000000000000000000000000000..2878e791aae3c28dd19abf8213dd30be0a11e722 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CandidateLengthBand.lean @@ -0,0 +1,65 @@ +import OAI.NumberTheory.Jacobsthal.Paths.SourceStopWindow +import OAI.NumberTheory.Jacobsthal.Paths.StopLengthBandGeometry +import OAI.NumberTheory.Jacobsthal.Primes.PrimeProductLogCoordinates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CandidateLengthBand +open FinitePathGeometry PrimeHistories SourceStopPredicate SourceStopWindow PrimeProductLogCoordinates +open StopLengthBandGeometry MarkedPrefixTools LogarithmicBinScale LogarithmicBinEndpoints +open LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem candidate_whole_bin_length_band (Y : ℕ) (hY : 0 < Y) + {w top Cs eta Clen B xi b₀ b₁ alpha : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hxi1 : xi ≤ 1) + (hC : 0 ≤ Clen) (hcomp : Real.log B ≤ 2*Real.log w) (hlogw : 1 ≤ Real.log w) + (hb₀ : 401 ≤ b₀) (ha0 : 0 ≤ alpha) (ha1 : alpha ≤ 1) + (hsmall : 2*Clen*xi+(218/100)*(xi/Real.log w) ≤ (2/100)*b₀) + (residue : ℕ → ℕ) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-alpha+2) (ps : List ℕ) + (hc : stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) residue z ps) + (p₀ q : ℕ) (hq : 0 < q) (hprod : ps.prod=p₀*q) + {R zeta : ℝ} (hR : 0 < R) (hzeta : 0 ≤ zeta) (hzeta1 : zeta ≤ 1) + (hp₀ : R ≤ (p₀:ℝ) ∧ (p₀:ℝ) ≤ (1+zeta)*R) + (p : ℝ) (hp : R ≤ p ∧ p ≤ (1+zeta)*R) : + 203/100 ≤ Real.log ((Y:ℝ)/(p*(q:ℝ)))/Real.log (ps.getLastD 0:ℝ) ∧ + Real.log ((Y:ℝ)/(p*(q:ℝ)))/Real.log (ps.getLastD 0:ℝ) ≤ 219/100 := by + have hwindow := candidate_actual_window Y hw htop hxi hC hcomp hsmall residue z ps hc + have hsource := candidate_source_primes Y hw htop hxi residue z ps hc + have hpos : ∀ p ∈ ps,0 < p := fun p hp => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hsource p hp)).1.pos + have hlast : ps.getLastD 0 ∈ ps := by + have he : ps.getLastD 0=ps.getLast hc.1 := by + conv_lhs => rw [← List.dropLast_append_getLast hc.1] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hc.1 + have hprime := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop _).mp (hsource _ hlast) + have hP : 1 < ps.getLastD 0 := hprime.1.one_lt + have hstep : xi/Real.log w ≤ 1 := (div_le_self hxi.le hlogw).trans hxi1 + have hb : 400 ≤ (terminal w z ps).cutoff := by linarith [hwindow.1] + have hlogP : 200 ≤ Real.log (ps.getLastD 0:ℝ) := by + have he : Real.log (ps.getLastD 0:ℝ)=(terminal w z ps).cutoff*Real.log w := by + rw [terminal_lastD w z ps hc.1,primeExponent,div_mul_cancel₀ _ (Real.log_pos hw).ne'] + rw [he] + nlinarith + have hid := source_length_exponent_identity hw Y (ps.getLastD 0) hY hP z hroot ps hpos + rw [← terminal_lastD w z ps hc.1] at hid + have hband : 2035/1000 ≤ Real.log ((Y:ℝ)/(ps.prod:ℝ))/Real.log (ps.getLastD 0:ℝ) ∧ + Real.log ((Y:ℝ)/(ps.prod:ℝ))/Real.log (ps.getLastD 0:ℝ) ≤ 218/100 := by + rw [hid] + exact shifted_ratio_band hb ha0 ha1 hwindow.2.2.1 hwindow.2.2.2 + have he₀ : Real.log ((Y:ℝ)/((p₀:ℝ)*(q:ℝ)))/Real.log (ps.getLastD 0:ℝ)= + Real.log ((Y:ℝ)/(ps.prod:ℝ))/Real.log (ps.getLastD 0:ℝ) := by rw [hprod,Nat.cast_mul] + exact whole_bin_length_band (by exact_mod_cast hY) (by exact_mod_cast hq) hR hzeta hzeta1 hp hp₀ hlogP he₀ hband +end NumberTheoryLean.CandidateLengthBand + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCorrectionSum.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCorrectionSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..5bdde419c08f65ed18ce7c3f606f074f5dfe816f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCorrectionSum.lean @@ -0,0 +1,382 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ActualRepeatedBinStep +import OAI.NumberTheory.Jacobsthal.Paths.ActualOwnerLocalComparison +import OAI.NumberTheory.Jacobsthal.Paths.CanonicalKeyWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CanonicalKeyReplacement +open PrimeHistories CanonicalStopKey CanonicalKeyWitness ActualStopGroupFiber +open SourceStopPredicate ActualTagFreezing ActualFrozenStopFamily BinReplacementOrder +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin ErdosInverseAlignment + + +variable {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + {Y : ℕ} {Cs eta Clen B b₀ b₁ mu : ℝ} {a : ℕ → ℕ} {z : Node} + {k : Key (binCount w top xi)} (d : Witness hw htop hxi Y Cs eta Clen B b₀ b₁ mu a z k) + +include d + +theorem whole_bin_words (p : ℕ) (hp : p∈primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin)) : + (k.pre++p::k.tail).Pairwise (· > ·) ∧ + ∀ q∈k.pre++p::k.tail,q∈sourcePrimeSet w top := by + have hn := (bin_mem_iff_label (zero_lt_one.trans hw) htop hxi k.tag.bin p).mp hp + have hpS : p∈sourcePrimeSet w top := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mpr + ⟨hn.1,hn.2.1,hn.2.2.1⟩ + have hl : label (zero_lt_one.trans hw) htop hxi p=label (zero_lt_one.trans hw) htop hxi d.p₀ := hn.2.2.2.trans d.bin_eq + have hc : ((k.pre++d.p₀::k.tail).map (label (zero_lt_one.trans hw) htop hxi)).count + (label (zero_lt_one.trans hw) htop hxi d.p₀)=1 := by rw [← d.bin_eq]; exact d.singleton + have hD := (decreasing_replacement (zero_lt_one.trans hw) htop hxi k.pre k.tail d.p₀ p d.source hpS hl hc).mp d.ordered + have hS := (forall_mem_replacement_iff (fun q => q∈sourcePrimeSet w top) k.pre k.tail d.p₀ p + (d.source d.p₀ (by simp)) hpS).mp d.source + exact ⟨hD,hS⟩ + +theorem fixed_other_alignment : ∀ q∈k.pre++k.tail,aligns (sourceClass a) k.tag.rational q := by + intro q hq + apply d.aligned q + simp only [List.mem_append,List.mem_cons] at hq ⊢ + tauto + +theorem fixed_cofactor_pos : 0 < k.pre.prod*k.tail.prod := by + have hs : ∀ q∈k.pre++k.tail,0 < q := by + intro q hq + have hm : q∈k.pre++d.p₀::k.tail := by + simp only [List.mem_append,List.mem_cons] at hq ⊢ + tauto + exact ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop q).mp (d.source q hm)).1.pos + simpa only [List.prod_append] using List.prod_pos hs + +theorem aligning_word_mem (hC : 0 ≤ Clen) (p : ℕ) + (hp : p∈primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin)) + (ha : aligns (sourceClass a) k.tag.rational p) : + k.pre++p::k.tail∈family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z := + actual_stopped_replacement Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z k.pre k.tail d.p₀ p + d.mem_family d.tag d.prime_tag hp ha + +theorem search_lower : Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ lower w top xi k.tag.bin := by + have hR : 0 < lower w top xi k.tag.bin := endpoint_pos (zero_lt_one.trans hw) k.tag.bin.1 + have hs : w^((1:ℝ)/4) ≤ Real.log (lower w top xi k.tag.bin)/Real.log w := d.search + have hh := Real.exp_le_exp.mpr ((le_div_iff₀ (Real.log_pos hw)).mp hs) + simpa only [Real.exp_log hR] using hh +end NumberTheoryLean.CanonicalKeyReplacement + + + +namespace NumberTheoryLean.MovingCandidateBands +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open MovingStopBandParameters CandidateTerminalGeometry CandidateLengthBand + + +theorem moving_candidate_node_window {Clen xi K : ℝ} (hC : 0 ≤ Clen) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop,∃ hw : 1 < w,∀ top : ℝ,∀ htop : w < top, + ∀ B : ℝ,Real.log B ≤ 2*Real.log w → ∀ Y : ℕ,∀ Cs eta b₁ : ℝ, + ∀ (residue : ℕ → ℕ) (z : Node) (ps : List ℕ), + stopCandidate Y w Cs eta Clen B xi (K*(Real.log w)^2) b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) residue z ps → + K*(Real.log w)^2-xi/Real.log w ≤ (terminal w z ps).cutoff ∧ (terminal w z ps).cutoff ≤ b₁ ∧ + 204/100 ≤ (terminal w z ps).ratio ∧ (terminal w z ps).ratio ≤ 218/100 ∧ + Consistent (terminal w z ps) ∧ (terminal w z ps).closed=false ∧ + Real.exp ((K/2)*(Real.log w)^3) ≤ (ps.getLastD 0:ℝ) ∧ + w^(terminal w z ps).cutoff=(ps.getLastD 0:ℝ) := by + filter_upwards [moving_stop_band_conditions Clen xi hxi.le hK] with w hcond + obtain ⟨hw,hlog,hb₀,hsmall,hhalf⟩ := hcond + refine ⟨hw,?_⟩ + intro top htop B hcomp Y Cs eta b₁ residue z ps hc + have hstep : xi/Real.log w ≤ 1 := (div_le_self hxi.le hlog).trans hxi1 + have hpos : 0 < K*(Real.log w)^2-xi/Real.log w := by linarith + have hn := candidate_terminal_geometry Y hw htop hxi hC hcomp hpos hsmall residue z ps hc + have hP := candidate_moving_last_prime_lower Y hw htop hxi hC hcomp hsmall hhalf residue z ps hc + exact ⟨hn.1,hn.2.1,hn.2.2.1,hn.2.2.2.1,hn.2.2.2.2.1,hn.2.2.2.2.2,hP.1,hP.2⟩ + +theorem moving_candidate_J_band {Clen xi K : ℝ} (hC : 0 ≤ Clen) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop,∃ hw : 1 < w,∀ top : ℝ,∀ htop : w < top, + ∀ B : ℝ,Real.log B ≤ 2*Real.log w → ∀ Y : ℕ,0 < Y → + ∀ alpha Cs eta b₁ : ℝ,0 ≤ alpha → alpha ≤ 1 → + ∀ (residue : ℕ → ℕ) (z : Node),z.gap=Real.log (Y:ℝ)/Real.log w-alpha+2 → + ∀ ps : List ℕ, + stopCandidate Y w Cs eta Clen B xi (K*(Real.log w)^2) b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) residue z ps → + ∀ p₀ q : ℕ,0 < q → ps.prod=p₀*q → ∀ R zeta : ℝ,0 < R → 0 ≤ zeta → zeta ≤ 1 → + R ≤ (p₀:ℝ) → (p₀:ℝ) ≤ (1+zeta)*R → ∀ p : ℝ,R ≤ p → p ≤ (1+zeta)*R → + Real.exp ((K/2)*(Real.log w)^3) ≤ (ps.getLastD 0:ℝ) ∧ + 203/100 ≤ Real.log ((Y:ℝ)/(p*(q:ℝ)))/Real.log (ps.getLastD 0:ℝ) ∧ + Real.log ((Y:ℝ)/(p*(q:ℝ)))/Real.log (ps.getLastD 0:ℝ) ≤ 219/100 := by + filter_upwards [moving_stop_band_conditions Clen xi hxi.le hK] with w hcond + obtain ⟨hw,hlog,hb₀,hsmall,hhalf⟩ := hcond + refine ⟨hw,?_⟩ + intro top htop B hcomp Y hY alpha Cs eta b₁ ha0 ha1 residue z hroot ps hc p₀ q hq hprod R zeta hR hzeta hzeta1 hp₀lo hp₀hi p hplo hphi + have hBand := candidate_whole_bin_length_band Y hY hw htop hxi hxi1 hC hcomp hlog hb₀ ha0 ha1 hsmall + residue z hroot ps hc p₀ q hq hprod hR hzeta hzeta1 ⟨hp₀lo,hp₀hi⟩ p ⟨hplo,hphi⟩ + have hP := (candidate_moving_last_prime_lower Y hw htop hxi hC hcomp hsmall hhalf residue z ps hc).1 + exact ⟨hP,hBand⟩ +end NumberTheoryLean.MovingCandidateBands + + + +namespace NumberTheoryLean.CanonicalKeyBands +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories CanonicalStopKey CanonicalKeyWitness CanonicalKeyReplacement +open SourceStopPredicate TagBelowStopWindow MovingCandidateBands +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin +open scoped Topology + + +theorem last_fixed_tail (pre tail : List ℕ) (p : ℕ) (htail : tail≠[]) : + (pre++p::tail).getLastD 0=tail.getLastD 0 := by + rw [← List.dropLast_append_getLast htail,← List.cons_append,← List.append_assoc] + simp only [List.getLastD_concat] + +theorem moving_key_bands {Clen xi Kstop rho : ℝ} (hC : 0 ≤ Clen) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hK : 0 < Kstop) (_hrho : 0 < rho) : + ∀ᶠ w : ℝ in atTop,∃ hw : 1 < w,∀ top : ℝ,∀ htop : w < top, + ∀ B : ℝ,Real.log B ≤ 2*Real.log w → ∀ Y : ℕ,0 < Y → + ∀ aStar Cs eta mu : ℝ,0 ≤ aStar → aStar ≤ 1 → ∀ (a : ℕ → ℕ) (z : Node), + z.gap=Real.log (Y:ℝ)/Real.log w-aStar+2 → + ∀ k : Key (binCount w top xi), + ∀ _d : Witness hw htop hxi Y Cs eta Clen B (Kstop*(Real.log w)^2) (rho*Kstop*(Real.log w)^2) mu a z k, + Real.exp ((Kstop/2)*(Real.log w)^3) ≤ (k.tail.getLastD 0:ℝ) ∧ + (k.tail.getLastD 0:ℝ) ≤ Real.exp (rho*Kstop*(Real.log w)^3) ∧ + ∀ p∈Set.Icc (lower w top xi k.tag.bin) ((1+width w top xi k.tag.bin)*lower w top xi k.tag.bin), + 203/100 ≤ Real.log ((Y:ℝ)/(p*(k.pre.prod*k.tail.prod:ℕ)))/Real.log (k.tail.getLastD 0:ℝ) ∧ + Real.log ((Y:ℝ)/(p*(k.pre.prod*k.tail.prod:ℕ)))/Real.log (k.tail.getLastD 0:ℝ) ≤ 219/100 := by + filter_upwards [moving_candidate_J_band hC hxi hxi1 hK,moving_candidate_node_window hC hxi hxi1 hK] + with w hBand hNode + obtain ⟨hw,hBand⟩ := hBand + obtain ⟨_hwN,hNode⟩ := hNode + refine ⟨hw,?_⟩ + intro top htop B hcomp Y hY aStar Cs eta mu ha0 ha1 a z hroot k d + have hR : 0 < lower w top xi k.tag.bin := endpoint_pos (zero_lt_one.trans hw) k.tag.bin.1 + have htheta : 0 < width w top xi k.tag.bin := effectiveWidth_pos (zero_lt_one.trans hw) htop hxi + have htheta1 : width w top xi k.tag.bin ≤ 1 := + (effectiveWidth_le (zero_lt_one.trans hw) htop hxi).trans hxi1 + have hp₀ := (mem_primeBin hR.le htheta.le d.p₀).mp d.prime_bin + have hq := fixed_cofactor_pos hw htop hxi d + have hprod := replacement_product k.pre k.tail d.p₀ + have hLast := last_fixed_tail k.pre k.tail d.p₀ d.tail_nonempty + have hJ (p : ℝ) (hpL : lower w top xi k.tag.bin ≤ p) + (hpU : p ≤ (1+width w top xi k.tag.bin)*lower w top xi k.tag.bin) := + hBand top htop B hcomp Y hY aStar Cs eta (rho*Kstop*(Real.log w)^2) ha0 ha1 a z hroot + (k.pre++d.p₀::k.tail) d.candidate d.p₀ (k.pre.prod*k.tail.prod) hq hprod + (lower w top xi k.tag.bin) (width w top xi k.tag.bin) hR htheta.le htheta1 hp₀.2.1.le hp₀.2.2 p hpL hpU + have hJU : lower w top xi k.tag.bin ≤ (1+width w top xi k.tag.bin)*lower w top xi k.tag.bin := by nlinarith + have hJR := hJ (lower w top xi k.tag.bin) (le_refl _) hJU + rw [hLast] at hJR + obtain ⟨_hlo,hcut,_hrlo,_hrhi,_hcons,_hclosed,_hPlo,hpower⟩ := + hNode top htop B hcomp Y Cs eta (rho*Kstop*(Real.log w)^2) a z (k.pre++d.p₀::k.tail) d.candidate + rw [hLast] at hpower + have hUpper : (k.tail.getLastD 0:ℝ) ≤ Real.exp (rho*Kstop*(Real.log w)^3) := by + calc + _ = w^(terminal w z (k.pre++d.p₀::k.tail)).cutoff := hpower.symm + _ ≤ w^(rho*Kstop*(Real.log w)^2) := Real.rpow_le_rpow_of_exponent_le hw.le hcut + _ = _ := by rw [Real.rpow_def_of_pos (zero_lt_one.trans hw)]; congr 1; ring + refine ⟨hJR.1,hUpper,?_⟩ + intro p hp + have hh := (hJ p hp.1 hp.2).2 + rwa [hLast] at hh +end NumberTheoryLean.CanonicalKeyBands + + + +namespace ErdosStoppedArithmetic +open NumberTheoryLean NumberTheoryLean.FrozenPrimeGroup NumberTheoryLean.StoppedCountVertex + NumberTheoryLean.StoppedVertexHistory NumberTheoryLean.StoppedCountAdapters + NumberTheoryLean.LogarithmicBinPartition NumberTheoryLean.LargePrimeDeletion + NumberTheoryLean.LastPrimeModulusCount + ErdosInverseAlignment ErdosInversePrimeBin ErdosInverseCounts + +attribute [local instance] Classical.propDecidable + +theorem frozen_group_reward_sum (R theta : ℝ) (a : ℕ → ℤ) (r : ℚ) + (pre tail : List ℕ) (reward : List ℕ → ℝ) : + (∑ ps ∈ frozenGroup R theta a r pre tail,reward ps)= + ∑ p ∈ (primeBin R theta).filter (aligns a r),reward (pre++p::tail) := by + rw [frozenGroup,Finset.sum_image] + intro p _ q _ he + exact replacement_injective pre tail he + +theorem frozen_correction_eq_original (Y : ℕ) (w top R theta : ℝ) + (hw : 0 < w) (htop : w < top) (a : ℕ → ℕ) (z : PrimeHistories.Node) + (mu : ℝ) (r : ℚ) (pre tail : List ℕ) (htail : tail ≠ []) + (hWords : ∀ p ∈ (primeBin R theta).filter (aligns (fun t => (a t : ℤ)) r), + (pre++p::tail).Pairwise (· > ·) ∧ ∀ q ∈ pre++p::tail,q ∈ sourcePrimeSet w top) : + (∑ ps ∈ frozenGroup R theta (fun t => (a t : ℤ)) r pre tail, + (countSurvivors Y (cutoffPrimes ⌊w⌋₊) a + (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)- + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)))= + ∑ p ∈ (primeBin R theta).filter (aligns (fun t => (a t : ℤ)) r), + ((modulusCount Y (ErdosStoppedTagSieve.smallPrimeSet (tail.getLastD 0 : ℝ)) a + (p*(pre.prod*tail.prod)) : ℝ)- + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) (pre++p::tail))) := by + rw [frozen_group_reward_sum] + apply Finset.sum_congr rfl + intro p hp + rw [strict_smallPrimeSet_nat] + rw [frozen_survivors_eq_modulusCount Y hw htop a z mu pre tail p htail + (hWords p hp).1 (hWords p hp).2] + +end ErdosStoppedArithmetic + + + +namespace ErdosStoppedArithmetic +open _root_.Filter _root_.Erdos970.Filter NumberTheoryLean NumberTheoryLean.PrimeHistories + NumberTheoryLean.CanonicalKeyWitness NumberTheoryLean.CanonicalKeyReplacement + NumberTheoryLean.CanonicalStopKey NumberTheoryLean.SourceStopPredicate + NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints + NumberTheoryLean.LogarithmicBinPartition + ErdosInverseAlignment ErdosInversePrimeBin ErdosStoppedTagSieve ErdosHypotheticalTag + + +theorem canonical_key_arithmetic (Cs : ℝ) : ∀ᶠ w : ℝ in atTop, + ∀ top xi : ℝ,∀ hw : 1 < w,∀ htop : w < top,∀ hxi : 0 < xi, + ∀ Y : ℕ,∀ eta Clen B b₀ b₁ mu : ℝ,∀ a : ℕ → ℕ,∀ z : Node, + ∀ k : Key (binCount w top xi),Witness hw htop hxi Y Cs eta Clen B b₀ b₁ mu a z k → + (k.tail.getLastD 0).Prime ∧ 0 < k.pre.prod*k.tail.prod ∧ + (∀ t ∈ smallPrimeSet (k.tail.getLastD 0 : ℝ),(k.pre.prod*k.tail.prod).Coprime t) ∧ + ∀ p ∈ primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin), + Squarefree (p*(k.pre.prod*k.tail.prod)) ∧ k.tag.rational.den.Coprime p ∧ + p ∉ smallPrimeSet (k.tail.getLastD 0 : ℝ) ∧ + (∀ t ∈ (p*(k.pre.prod*k.tail.prod)).primeFactors,t ≠ p → + aligns (sourceClass a) k.tag.rational t) ∧ + ∀ t ∈ (p*(k.pre.prod*k.tail.prod)).primeFactors,k.tail.getLastD 0 ≤ t := by + filter_upwards [source_all_search_units Cs] with w hUnits + intro top xi hw htop hxi Y eta Clen B b₀ b₁ mu a z k d + have hFixed := fixed_other_alignment hw htop hxi d + have hPrime0 : ∀ p ∈ k.pre++d.p₀::k.tail,p.Prime := by + intro p hp + exact ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (d.source p hp)).1 + obtain ⟨hP,hq,_hsq0,_hSupport0,_hSmall0,hqCoprime,_hOther0⟩ := + fixed_tail_arithmetic k.pre k.tail d.p₀ d.tail_nonempty d.ordered hPrime0 (sourceClass a) k.tag.rational hFixed + refine ⟨hP,hq,hqCoprime,?_⟩ + intro p hp + have hWord := whole_bin_words hw htop hxi d p hp + have hPrime : ∀ t ∈ k.pre++p::k.tail,t.Prime := by + intro t ht + exact ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop t).mp (hWord.2 t ht)).1 + obtain ⟨_hP,_hq,hsq,hSupport,hSmall,_hqCo,hOther⟩ := + fixed_tail_arithmetic k.pre k.tail p d.tail_nonempty hWord.1 hPrime (sourceClass a) k.tag.rational hFixed + have hR : 0 < lower w top xi k.tag.bin := endpoint_pos (zero_lt_one.trans hw) k.tag.bin.1 + have hWidth : 0 ≤ width w top xi k.tag.bin := (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le + have hpBounds := (mem_primeBin hR.le hWidth p).mp hp + have hUnit := hUnits.2 (lower w top xi k.tag.bin) k.tag.rational p hR d.eligible.1 + d.search hpBounds.2.1.le hpBounds.1 + exact ⟨hsq,hUnit,hSmall,hOther,hSupport⟩ + +end ErdosStoppedArithmetic + + + +namespace ErdosStoppedArithmetic +open _root_.Filter _root_.Erdos970.Filter NumberTheoryLean NumberTheoryLean.PrimeHistories + NumberTheoryLean.CanonicalKeyWitness NumberTheoryLean.CanonicalKeyReplacement + NumberTheoryLean.CanonicalStopKey NumberTheoryLean.ActualStopGroupFiber + NumberTheoryLean.SourceStopPredicate NumberTheoryLean.StoppedCountVertex + NumberTheoryLean.StoppedCountAdapters NumberTheoryLean.StoppedVertexHistory + NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints + NumberTheoryLean.LogarithmicBinPartition NumberTheoryLean.LargePrimeDeletion + NumberTheoryLean.ReferenceProductsBasics + ErdosInverseAlignment ErdosInversePrimeBin ErdosStoppedTagSieve + ErdosPrimeInputs.MertensStrong +open ErdosCommonMInterval (lengthExponent) + +attribute [local instance] Classical.propDecidable + +theorem canonical_key_correction_nonnegative : + ∃ eta0 : ℝ,0 < eta0 ∧ eta0 ≤ 1/4 ∧ ∃ P0 : ℕ,2 ≤ P0 ∧ + ∀ Cs : ℝ,0 ≤ Cs → ∃ K : ℝ,0 < K ∧ ∀ rho xi : ℝ,1 < rho → ∀ hxi : 0 < xi, + ∃ w0 : ℝ,4 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → ∀ top : ℝ, + ∀ hw : 1 < w,∀ htop : w < top,∀ Y : ℕ,0 < Y → + ∀ eta Clen B b₀ b₁ mu : ℝ,0 ≤ eta → eta ≤ eta0 → + ∀ a : ℕ → ℕ,∀ z : Node,∀ k : Key (binCount w top xi), + Witness hw htop hxi Y Cs eta Clen B b₀ b₁ mu a z k → + let P := k.tail.getLastD 0 + let R := lower w top xi k.tag.bin + let theta := width w top xi k.tag.bin + let q := k.pre.prod*k.tail.prod + P0 ≤ P → Real.exp (K*(Real.log w)^3) ≤ (P : ℝ) → + (P : ℝ) ≤ Real.exp (rho*K*(Real.log w)^3) → xi/4 ≤ theta → theta ≤ 1 → + (∀ x ∈ Set.Icc R ((1+theta)*R), + 203/100 ≤ lengthExponent P Y x q ∧ lengthExponent P Y x q ≤ 219/100) → + (∀ p ∈ (primeBin R theta).filter (aligns (sourceClass a) k.tag.rational), + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) (k.pre++p::k.tail)) ≤ + (33/100 : ℝ)*primeProduct (P : ℝ)*((Y : ℝ)/((p : ℝ)*q))) → + 0 ≤ ∑ ps ∈ keyGroup w top xi a k, + (countSurvivors Y (cutoffPrimes ⌊w⌋₊) a (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)- + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)) := by + obtain ⟨eta0,heta0,heta01,P0,hP0,hOwner⟩ := actual_owner_local_comparison + refine ⟨eta0,heta0,heta01,P0,hP0,?_⟩ + intro Cs hCs + obtain ⟨K,hK,hOwner⟩ := hOwner Cs hCs + refine ⟨K,hK,?_⟩ + intro rho xi hrho hxi + obtain ⟨wA,hwA,hA⟩ := hOwner rho xi hrho hxi + obtain ⟨wU,hU⟩ := eventually_atTop.mp (canonical_key_arithmetic Cs) + refine ⟨max wA wU,hwA.trans (le_max_left _ _),?_⟩ + intro w hw top hw1 htop Y hY eta Clen B b₀ b₁ mu heta hetaU a z k d + dsimp only + intro hPsize hPl hPu hWidthLo hWidthHi hBand hRef + obtain ⟨hPrime,hq,hqSmall,hGeometry⟩ := + hU w ((le_max_right _ _).trans hw) top xi hw1 htop hxi Y eta Clen B b₀ b₁ mu a z k d + let ref : ℕ → ℝ := fun p => + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) (k.pre++p::k.tail)) + have hNum : |(k.tag.rational.num : ℝ)| ≤ (Y : ℝ)*w^(Cs+2) := by + simpa only [Nat.cast_natAbs,Int.cast_abs] using d.eligible.2 + have hMargin := hA w ((le_max_left _ _).trans hw) (k.tail.getLastD 0) hPrime hPsize + (lower w top xi k.tag.bin) (width w top xi k.tag.bin) eta hPl hPu + (search_lower hw1 htop hxi d) hWidthLo hWidthHi heta hetaU Y (k.pre.prod*k.tail.prod) + hY hq k.tag.rational a d.eligible.1 hNum hBand hqSmall hGeometry d.near_full ref hRef + have hNonneg : 0 ≤ (1/100 : ℝ)*primeProduct (k.tail.getLastD 0 : ℝ)* + (∑ p ∈ primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin), + (Y : ℝ)/((p : ℝ)*(k.pre.prod*k.tail.prod : ℕ))) := by + apply mul_nonneg (mul_nonneg (by norm_num) (actual_primeProduct_pos _).le) + exact Finset.sum_nonneg (fun p _ => by positivity) + change 0 ≤ ∑ ps ∈ NumberTheoryLean.FrozenPrimeGroup.frozenGroup + (lower w top xi k.tag.bin) (width w top xi k.tag.bin) (fun t => (a t : ℤ)) k.tag.rational k.pre k.tail,_ + rw [frozen_correction_eq_original Y w top (lower w top xi k.tag.bin) (width w top xi k.tag.bin) + (zero_lt_one.trans hw1) htop a z mu k.tag.rational k.pre k.tail d.tail_nonempty + (fun p hp => whole_bin_words hw1 htop hxi d p (Finset.mem_filter.mp hp).1)] + exact hNonneg.trans hMargin + +end ErdosStoppedArithmetic + + + +namespace ErdosStoppedArithmetic +open NumberTheoryLean NumberTheoryLean.PrimeHistories NumberTheoryLean.CanonicalStopPartition + NumberTheoryLean.ActualStopGroupFiber NumberTheoryLean.SourceStopPredicate + NumberTheoryLean.StoppedCountVertex NumberTheoryLean.StoppedCountAdapters + NumberTheoryLean.StoppedVertexHistory NumberTheoryLean.StoppedTraceSets + NumberTheoryLean.LogarithmicBinEndpoints NumberTheoryLean.LogarithmicBinLabels + NumberTheoryLean.LogarithmicBinPartition NumberTheoryLean.LargePrimeDeletion + + +theorem stopped_correction_of_key_signs (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (a : ℕ → ℕ) (z : Node) + (hKeys : ∀ k ∈ keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z, + 0 ≤ ∑ ps ∈ keyGroup w top xi a k, + (countSurvivors Y (cutoffPrimes ⌊w⌋₊) a (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)- + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps))) : + 0 ≤ ∑ ps ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) mu), + (countSurvivors Y (cutoffPrimes ⌊w⌋₊) a (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)- + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) ps)) := by + change 0 ≤ ∑ ps ∈ family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z,_ + rw [sum_over_groups Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z] + exact Finset.sum_nonneg hKeys + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCoupledHistories.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCoupledHistories.lean new file mode 100644 index 0000000000000000000000000000000000000000..7ca6cc5114a24fe84a72497c54ce101b99aacbb8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCoupledHistories.lean @@ -0,0 +1,173 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FlaggedSourceStart + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualCoupledHistories + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualFlagInvariant PersistentFailureFlag +open FlaggedSourceStart ContinuousKilledBins FiniteHistoryTransport + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +noncomputable def sourceTransition (mesh : ℝ) : + Kernel (FlagState (JointState w ell S start)) (FlagState (JointState w ell S start)) := + marked (jointKernel hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh) + (mismatch_measurable mesh) + +instance sourceTransition_markov (mesh : ℝ) : + IsMarkovKernel (sourceTransition hw hell hS0 hS hr hs hsS mesh) := by + unfold sourceTransition + infer_instance + +noncomputable def sourceHistoryLaw (mesh : ℝ) (n : ℕ) : + Measure (Hist (FlagState (JointState w ell S start)) n) := + pathKernel (sourceTransition hw hell hS0 hS hr hs hsS mesh) n + (fun _ => (sourceJoint w ell S start hs,false)) + +instance sourceHistoryLaw_probability (mesh : ℝ) (n : ℕ) : + IsProbabilityMeasure (sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh n) := by + unfold sourceHistoryLaw + infer_instance + +theorem sourceHistoryLaw_endpoint (mesh : ℝ) (n : ℕ) : + (sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh n).map (last n) = + sourceLaw hw hell hS0 hS hr hs hsS mesh n := + pathMeasure_endpoint _ n _ + +theorem sourceHistoryLaw_coordinate (mesh : ℝ) (n k : ℕ) (hk : k ≤ n) : + (sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh n).map + (fun h => h ⟨k, by simpa using hk⟩) = sourceLaw hw hell hS0 hS hr hs hsS mesh k := + pathMeasure_coordinate _ n k hk _ + +theorem sourceHistoryLaw_prime (mesh : ℝ) (n : ℕ) : + (sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh n).map + (mapHist (fun q => q.1.1) n) = + pathKernel (chain w ell S start) n (fun _ => some History.empty) := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + apply pathMeasure_mapHist _ _ (measurable_fst.comp measurable_fst) + intro q + calc + _ = ((sourceTransition hw hell hS0 hS hr hs hsS mesh q).map Prod.fst).map Prod.fst := + (Measure.map_map measurable_fst measurable_fst).symm + _ = _ := by + rw [sourceTransition, marked_map] + exact jointKernel_left hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh q.1.1 q.1.2 + +theorem sourceHistoryLaw_continuous (mesh : ℝ) (n : ℕ) : + (sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh n).map + (mapHist (fun q => q.1.2) n) = + pathKernel (continuousChain (Real.log start.gap) ell S) n + (fun _ => Sum.inl (sourceCostState hs)) := by + apply pathMeasure_mapHist _ _ (measurable_snd.comp measurable_fst) + intro q + calc + _ = ((sourceTransition hw hell hS0 hS hr hs hsS mesh q).map Prod.fst).map Prod.snd := + (Measure.map_map measurable_snd measurable_fst).symm + _ = _ := by + rw [sourceTransition, marked_map] + exact jointKernel_right hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh q.1.1 q.1.2 + +end NumberTheoryLean.ActualCoupledHistories + + + +namespace NumberTheoryLean.ActualSuccessfulHistories + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling PersistentFailureFlag +open FiniteHistoryTransport ActualCoupledHistories FullHistoryFailureFlag +open ActualFlagInvariant FlaggedSourceStart FailureFlagBounds + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistory_no_reset (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, noResetPath N h := + marked_history_no_reset _ (mismatch_measurable mesh) _ N + +theorem sourceHistory_success_good {mesh : ℝ} (hm : 0 < mesh) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + (last N h).2 = false → ∀ j : Finset.Iic N, + GoodAt (Real.log start.gap) mesh j.1 (h j).1 := by + have hcoords : ∀ j : Finset.Iic N, + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + surviving (GoodAt (Real.log start.gap) mesh j.1) (h j) := by + intro j + have hP := surviving_measurable (GoodAt_measurable (w:=w) (ell:=ell) (S:=S) (start:=start) + (Real.log start.gap) mesh j.1) + apply (ae_map_iff (measurable_pi_apply j).aemeasurable hP).mp + have hcoord := sourceHistoryLaw_coordinate hw hell hS0 hS hr hs hsS mesh N j.1 (Finset.mem_Iic.mp j.2) + rw [hcoord] + exact sourceLaw_good hw hell hS0 hS hr hs hsS hm j.1 + have hAll := ae_all_iff.mpr hcoords + filter_upwards [hAll,sourceHistory_no_reset hw hell hS0 hS hr hs hsS mesh N] with h hh hp + intro hf j + exact hh j (hp j hf) + +theorem sourceHistory_failure_probability (mesh : ℝ) (N : ℕ) : + sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N {h | (last N h).2 = true} = + sourceLaw hw hell hS0 hS hr hs hsS mesh N failed := by + rw [← sourceHistoryLaw_endpoint hw hell hS0 hS hr hs hsS mesh N, + Measure.map_apply (last_measurable N) failed_measurable] + rfl + +end NumberTheoryLean.ActualSuccessfulHistories + + + +namespace NumberTheoryLean.CanonicalCoupledHistories + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures FiniteHistoryTransport CemeteryHistoryMap +open CemeteryKernel ContinuousKilledBins LowStateHorizon ActualCoupledHistories +open FlaggedSourceStart PrimeHistories ActualProcessCoupling + +theorem canonical_killing_image (s : State) (n : ℕ) (v ell S : ℝ) : + (finitePathMeasure s n).map (killHist (lowDomain v ell S) n) = + pathKernel (continuousChain v ell S) n (fun _ => Sum.inl (s,0)) := by + exact pathMeasure_killHist costKernel (lowDomain_measurable v ell S) n (fun _ => (s,0)) + +variable {w ell S : ℝ} {start : Node} +variable (hw : PrimeKilledChain.normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistoryLaw_canonical (mesh : ℝ) (n : ℕ) : + (sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh n).map + (mapHist (fun q => q.1.2) n) = + (finitePathMeasure (typedState start.side start.ratio hs) n).map + (killHist (lowDomain (Real.log start.gap) ell S) n) := by + rw [sourceHistoryLaw_continuous,canonical_killing_image] + rfl + +theorem sourceHistoryLaw_canonical_event (mesh : ℝ) (n : ℕ) + {A : Set (Hist (Space CostState) n)} (hA : MeasurableSet A) : + sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh n + ((mapHist (fun q => q.1.2) n) ⁻¹' A) = + finitePathMeasure (typedState start.side start.ratio hs) n + ((killHist (lowDomain (Real.log start.gap) ell S) n) ⁻¹' A) := by + have h := congrArg (fun μ : Measure (Hist (Space CostState) n) => μ A) + (sourceHistoryLaw_canonical hw hell hS0 hS hr hs hsS mesh n) + rwa [Measure.map_apply (by exact mapHist_measurable (by exact measurable_snd.comp measurable_fst) n) hA, + Measure.map_apply (killHist_measurable (lowDomain_measurable _ _ _) n) hA] at h + +end NumberTheoryLean.CanonicalCoupledHistories + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCrossingTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCrossingTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8db8414e7062e3f92bb53b90a661046b630d33e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalCrossingTail.lean @@ -0,0 +1,39 @@ +import OAI.NumberTheory.Jacobsthal.Paths.CanonicalHighRatioVisit +import OAI.NumberTheory.Jacobsthal.Paths.GeometricRegularWords + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CanonicalCrossingTail +open _root_.Set _root_.Erdos970.Set _root_.Filter _root_.Erdos970.Filter +open _root_.MeasureTheory _root_.Erdos970.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures FiniteHistoryTransport FiniteHistoryOccurrence +open TransitionKernels GoodCrossingVisit CrossingBandGeometry ErdosHighRatioBandTail + + +theorem crossing_arrival_subset (v H T : ℝ) (N : ℕ) : + arrivalOccurrence (crossingHighEvent v H T) N ⊆ + positiveVisit (highBand T (crossingCenter v H) crossingWidth) N := by + intro path hp + obtain ⟨j,hj⟩ := Set.mem_iUnion.mp hp + apply (mem_positiveVisit _ _ _).mpr + refine ⟨⟨j.1+1,Finset.mem_Iic.mpr (Nat.succ_le_of_lt j.2)⟩,Nat.zero_lt_succ _,?_,?_⟩ + · exact hj.1.le + · exact hj.2 + +theorem canonical_crossing_tail (eps : ℝ) (heps : 0 < eps) : + ∃ T : ℝ,3 ≤ T ∧ ∀ v H : ℝ,∀ s : EvenState,199/100 ≤ s.1 → s.1 ≤ 23/10 → ∀ N : ℕ, + finitePathMeasure (.inl s) N (arrivalOccurrence (crossingHighEvent v H T) N) ≤ ENNReal.ofReal eps := by + obtain ⟨T,hT,hTail⟩ := exists_canonical_visit_threshold crossingWidth eps heps + refine ⟨T,hT,?_⟩ + intro v H s h199 h23 N + exact (measure_mono (crossing_arrival_subset v H T N)).trans (hTail T le_rfl (crossingCenter v H) s h199 h23 N) +end NumberTheoryLean.CanonicalCrossingTail + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalKeyReference.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalKeyReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..40994cd01d3353a965ad7b9296d48683524871ac --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalKeyReference.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FiniteBoxWordMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CanonicalKeyReference +open _root_.Filter PrimeHistories CanonicalStopKey CanonicalKeyWitness CanonicalKeyReplacement CanonicalKeyBands +open ActualStopGroupFiber StoppedCountVertex StoppedVertexHistory StoppedCountAdapters StoppedTraceSets +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin ErdosInverseAlignment ErdosPrimeInputs.MertensStrong +open scoped Topology + + +theorem moving_key_reference {Clen xi Kstop rho : ℝ} (hC : 0 ≤ Clen) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hK : 0 < Kstop) (hrho : 0 < rho) : + ∀ᶠ w : ℝ in atTop,∃ hw : 1 < w,∀ top : ℝ,∀ htop : w < top, + ∀ B : ℝ,Real.log B ≤ 2*Real.log w → ∀ Y : ℕ,∀ Cs eta : ℝ, + ∀ (a : ℕ → ℕ) (z : Node) (k : Key (binCount w top xi)), + ∀ _d : Witness hw htop hxi Y Cs eta Clen B (Kstop*(Real.log w)^2) + (rho*Kstop*(Real.log w)^2) ((Y:ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊) a z k, + ∀ p∈primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin), + aligns (SourceStopPredicate.sourceClass a) k.tag.rational p → + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) + ((Y:ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊)) (k.pre++p::k.tail)) + ≤ (33/100)*primeProduct (k.tail.getLastD 0:ℝ)* + ((Y:ℝ)/((p:ℝ)*(k.pre.prod*k.tail.prod:ℕ))) := by + filter_upwards [ErdosStoppedReferenceUpper.actual_stopped_reference_upper hC hxi hxi1 hK hrho] + with w hRef + obtain ⟨hw,hRef⟩ := hRef + refine ⟨hw,?_⟩ + intro top htop B hcomp Y Cs eta a z k d p hp ha + have hm := aligning_word_mem hw htop hxi d hC p hp ha + rw [family,ErdosInverseEuler.smallEuler_eq_primeProduct] at hm + have hh := (hRef top htop B hcomp Y Cs eta a z (k.pre++p::k.tail) hm).2 + rw [last_fixed_tail k.pre k.tail p d.tail_nonempty, + TagBelowStopWindow.replacement_product,Nat.cast_mul] at hh + rw [ErdosInverseEuler.smallEuler_eq_primeProduct] + convert hh using 1; ring +end NumberTheoryLean.CanonicalKeyReference + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalPairCylinders.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalPairCylinders.lean new file mode 100644 index 0000000000000000000000000000000000000000..ddd4ac9e1b6aa20c4d8453fe9ec00f6fd7d142bd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CanonicalPairCylinders.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.Jacobsthal.Probability.CanonicalPairHitEvents + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal + +noncomputable def pairSurvivingHistory (a n : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawHistory (a+2*n)) := + (rawExtension a (a+2*n)).restrict (noPairHits_measurable a n (a+2*n) le_rfl v H) + +noncomputable def pairStoppedHistory (a n : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawHistory (a+2*n+1)) := + (rawExtension a (a+2*n+1)).restrict (firstPairHitEvent_measurable a n (a+2*n+1) le_rfl v H) + +instance pairSurvivingHistory_isFiniteKernel (a n : ℕ) (v H : ℝ) : IsFiniteKernel (pairSurvivingHistory a n v H) := by + unfold pairSurvivingHistory + infer_instance + +instance pairStoppedHistory_isFiniteKernel (a n : ℕ) (v H : ℝ) : IsFiniteKernel (pairStoppedHistory a n v H) := by + unfold pairStoppedHistory + infer_instance + +lemma pairSurvivingHistory_zero (a : ℕ) (v H : ℝ) : pairSurvivingHistory a 0 v H=Kernel.id := by + ext h S hS + rw [pairSurvivingHistory,Kernel.restrict_apply' _ _ _ hS,noPairHits_zero,inter_univ] + simp only [Nat.mul_zero,Nat.add_zero,rawExtension,Kernel.partialTraj_self] + +lemma pairStoppedHistory_zero (a : ℕ) (v H : ℝ) : + pairStoppedHistory a 0 v H=(rawExtension a (a+1)).restrict + (pairHitTest_measurable a 0 (a+1) (by omega) v H) := by + ext h S hS + rw [pairStoppedHistory,Kernel.restrict_apply' _ _ _ hS,Kernel.restrict_apply' _ _ _ hS, + firstPairHitEvent,noPairHits_zero,univ_inter] + +theorem pairSurvivingHistory_succ (a n : ℕ) (v H : ℝ) : + pairSurvivingHistory a (n+1) v H= + ((rawExtension (a+2*n) (a+2*(n+1))).restrict + (pairHitTest_measurable a n (a+2*(n+1)) (by omega) v H).compl) ∘ₖ + pairSurvivingHistory a n v H := by + unfold pairSurvivingHistory + rw [← rawExtension_restrict_comp (show a ≤ a+2*n by omega) (show a+2*n ≤ a+2*(n+1) by omega) + (noPairHits_measurable a n (a+2*n) le_rfl v H) + (pairHitTest_measurable a n (a+2*(n+1)) (by omega) v H).compl] + congr 1 + rw [noPairHits_prefix,noPairHits_succ] + +theorem pairStoppedHistory_factor (a n : ℕ) (v H : ℝ) : + pairStoppedHistory a n v H= + ((rawExtension (a+2*n) (a+2*n+1)).restrict + (pairHitTest_measurable a n (a+2*n+1) le_rfl v H)) ∘ₖ pairSurvivingHistory a n v H := by + unfold pairStoppedHistory pairSurvivingHistory + rw [← rawExtension_restrict_comp (show a ≤ a+2*n by omega) (show a+2*n ≤ a+2*n+1 by omega) + (noPairHits_measurable a n (a+2*n) le_rfl v H) + (pairHitTest_measurable a n (a+2*n+1) le_rfl v H)] + congr 1 + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CoefficientHeightChoice.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CoefficientHeightChoice.lean new file mode 100644 index 0000000000000000000000000000000000000000..5323ca9d020153ae60c485f3ccf69dfa5ebf3d17 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CoefficientHeightChoice.lean @@ -0,0 +1,52 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +noncomputable def boxHeight (M N : ℕ) : ℕ := ⌈(M : ℝ)^((N : ℝ)⁻¹)⌉₊ + +theorem boxHeight_pos {M N : ℕ} (hM : 0 < M) : 0 < boxHeight M N := by + apply Nat.ceil_pos.mpr + exact Real.rpow_pos_of_pos (by exact_mod_cast hM) _ + +theorem boxHeight_card_strict {M N : ℕ} (hN : 0 < N) : M < (boxHeight M N+1)^N := by + have hle : (M : ℝ)^((N : ℝ)⁻¹) ≤ (boxHeight M N : ℝ) := Nat.le_ceil _ + have hlt : (M : ℝ)^((N : ℝ)⁻¹) < (boxHeight M N : ℝ)+1 := by linarith + have h := (Real.rpow_inv_lt_iff_of_pos (Nat.cast_nonneg M) + (by positivity : (0 : ℝ) ≤ (boxHeight M N : ℝ)+1) + (by exact_mod_cast hN : (0 : ℝ) < (N : ℝ))).mp hlt + rw [Real.rpow_natCast] at h + exact_mod_cast h + +theorem boxHeight_le_twice_root {M N : ℕ} (hM : 0 < M) : + (boxHeight M N : ℝ) ≤ 2*(M : ℝ)^((N : ℝ)⁻¹) := by + have hM1 : (1 : ℝ) ≤ (M : ℝ) := by exact_mod_cast (Nat.succ_le_of_lt hM) + have hroot : (1 : ℝ) ≤ (M : ℝ)^((N : ℝ)⁻¹) := Real.one_le_rpow hM1 (by positivity) + have hc := Nat.ceil_lt_add_one (Real.rpow_nonneg (Nat.cast_nonneg M) (N : ℝ)⁻¹) + change (boxHeight M N : ℝ) < (M : ℝ)^((N : ℝ)⁻¹)+1 at hc + linarith + +theorem boxHeight_log_bound {M N : ℕ} (hM : 0 < M) (_hN : 0 < N) : + Real.log (2*(boxHeight M N : ℝ)) ≤ Real.log 4+Real.log (M : ℝ)/(N : ℝ) := by + have hM0 : (0 : ℝ) < M := by exact_mod_cast hM + have hH : (0 : ℝ) < (boxHeight M N : ℝ) := by exact_mod_cast boxHeight_pos (N := N) hM + have hr : (0 : ℝ) < (M : ℝ)^((N : ℝ)⁻¹) := Real.rpow_pos_of_pos hM0 _ + have hb := boxHeight_le_twice_root (N := N) hM + calc + _ ≤ Real.log (4*((M : ℝ)^((N : ℝ)⁻¹))) := + Real.log_le_log (by positivity) (by linarith) + _ = Real.log 4+Real.log ((M : ℝ)^((N : ℝ)⁻¹)) := Real.log_mul (by norm_num) hr.ne' + _ = Real.log 4+Real.log (M : ℝ)/(N : ℝ) := by rw [Real.log_rpow hM0]; ring + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ConditionalPatternCounts.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ConditionalPatternCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..b31776235863a0a2d94e250c0735d5fa0cf4a4d6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ConditionalPatternCounts.lean @@ -0,0 +1,196 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SmallModelSourceScales + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosLargePatternLaw +open ErdosVarianceSmallModel + +attribute [local instance] Classical.propDecidable + +abbrev FullPattern (w : ℝ) (H : ℕ) := + (ZMod (divisorModulus w H))ˣ × ZMod (divisorModulus w H) × + (ZMod (coprimeModulus w H))ˣ × ZMod (coprimeModulus w H) + +noncomputable def weight (w : ℝ) (H : ℕ) : ℝ := + 1/(((divisorModulus w H).totient : ℝ)*(divisorModulus w H : ℝ)* + ((coprimeModulus w H).totient : ℝ)*(coprimeModulus w H : ℝ)) + +noncomputable def expectation (w : ℝ) (H : ℕ) (F : FullPattern w H → ℝ) : ℝ := + ∑ v,weight w H*F v + +def survives (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (j : ℕ) (v : FullPattern w H) : Prop := + (∀ t ∈ divisorPrimes w H,(v.2.1.val : ZMod t)+(v.1.val.val : ZMod t)*(j : ZMod t) ≠ beta t) ∧ + (∀ t ∈ coprimePrimes w H,(v.2.2.1.val.val : ZMod t)*(qA : ZMod t)* + ((v.2.2.2.val : ZMod t)+(H : ZMod t)*(j : ZMod t)) ≠ delta t) + +def jointCondition (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (v : FullPattern w H) : Prop := ∀ j ∈ S,survives w H qA beta delta j v + +noncomputable def indicator (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (j : ℕ) (v : FullPattern w H) : ℝ := if survives w H qA beta delta j v then 1 else 0 + +noncomputable def survivorCount (w : ℝ) (H qA J : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (v : FullPattern w H) : ℕ := ((Finset.range J).filter (fun j => survives w H qA beta delta j v)).card + +theorem pattern_card (w : ℝ) (H : ℕ) : Fintype.card (FullPattern w H) = + (divisorModulus w H).totient*divisorModulus w H*(coprimeModulus w H).totient*coprimeModulus w H := by + simp only [FullPattern,Fintype.card_prod,ZMod.card_units_eq_totient,ZMod.card] + ring + +theorem weight_positive (w : ℝ) (H : ℕ) : 0 < weight w H := by + have hT0 := divisorModulus_pos w H + have hT1 := coprimeModulus_pos w H + have hP0 := Nat.totient_pos.mpr hT0 + have hP1 := Nat.totient_pos.mpr hT1 + unfold weight + positivity + +theorem weight_sum (w : ℝ) (H : ℕ) : (∑ _v : FullPattern w H,weight w H)=1 := by + have hT0 : (divisorModulus w H : ℝ) ≠ 0 := by exact_mod_cast (divisorModulus_pos w H).ne' + have hT1 : (coprimeModulus w H : ℝ) ≠ 0 := by exact_mod_cast (coprimeModulus_pos w H).ne' + have hP0 : ((divisorModulus w H).totient : ℝ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (divisorModulus_pos w H)).ne' + have hP1 : ((coprimeModulus w H).totient : ℝ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (coprimeModulus_pos w H)).ne' + simp only [Finset.sum_const,Finset.card_univ,pattern_card,nsmul_eq_mul,Nat.cast_mul,weight] + field_simp + +theorem indicator_binary (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (j : ℕ) (v : FullPattern w H) : indicator w H qA beta delta j v=0 ∨ indicator w H qA beta delta j v=1 := by + unfold indicator + split_ifs <;> simp + +theorem count_eq_indicator_sum (w : ℝ) (H qA J : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (v : FullPattern w H) : (survivorCount w H qA J beta delta v : ℝ)= + ∑ j ∈ Finset.range J,indicator w H qA beta delta j v := by + simp only [survivorCount,Finset.card_filter,Nat.cast_sum,Nat.cast_ite,Nat.cast_one,Nat.cast_zero,indicator] + +end ErdosLargePatternLaw + + + +namespace ErdosLargePatternLaw +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceMoments + +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def projectedUnit (M t : ℕ) [NeZero M] (ht : t ∣ M) (p : (ZMod M)ˣ) : (ZMod t)ˣ := + Units.map (ZMod.castHom ht (ZMod t)).toMonoidHom p + +theorem projectedUnit_coe (M t : ℕ) [NeZero M] (ht : t ∣ M) (p : (ZMod M)ˣ) : + (projectedUnit M t ht p : ZMod t) = (p.val.val : ZMod t) := by + change ZMod.castHom ht (ZMod t) p.val = _ + calc + ZMod.castHom ht (ZMod t) p.val = + ZMod.castHom ht (ZMod t) (p.val.val : ZMod M) := + congrArg (ZMod.castHom ht (ZMod t)) (ZMod.natCast_zmod_val p.val).symm + _ = _ := map_natCast (ZMod.castHom ht (ZMod t)) p.val.val + +def divisorCondition (w : ℝ) (H : ℕ) (beta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) + (p0 : (ZMod (divisorModulus w H))ˣ) (k0 : ZMod (divisorModulus w H)) : Prop := + ∀ t ∈ divisorPrimes w H,∀ j ∈ S,(k0.val : ZMod t)+(p0.val.val : ZMod t)*(j : ZMod t) ≠ beta t + +def coprimeCondition (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) + (p1 : (ZMod (coprimeModulus w H))ˣ) (m1 : ZMod (coprimeModulus w H)) : Prop := + ∀ t ∈ coprimePrimes w H,∀ j ∈ S,(p1.val.val : ZMod t)*(qA : ZMod t)* + ((m1.val : ZMod t)+(H : ZMod t)*(j : ZMod t)) ≠ delta t + +theorem joint_condition_split (w : ℝ) (H qA : ℕ) (beta delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p0 : (ZMod (divisorModulus w H))ˣ) (k0 : ZMod (divisorModulus w H)) + (p1 : (ZMod (coprimeModulus w H))ˣ) (m1 : ZMod (coprimeModulus w H)) : + jointCondition w H qA beta delta S (p0,k0,p1,m1) ↔ + divisorCondition w H beta S p0 k0 ∧ coprimeCondition w H qA delta S p1 m1 := by + constructor + · intro h + exact ⟨fun t ht j hj => (h j hj).1 t ht,fun t ht j hj => (h j hj).2 t ht⟩ + · rintro ⟨h0,h1⟩ j hj + exact ⟨fun t ht => h0 t ht j hj,fun t ht => h1 t ht j hj⟩ + +theorem divisor_condition_card (w : ℝ) (H : ℕ) (beta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) + (p0 : (ZMod (divisorModulus w H))ˣ) : + (Finset.univ.filter (divisorCondition w H beta S p0)).card = + ∏ t ∈ divisorPrimes w H,(t-(positionResidues S t).card) := by + let u (t : ℕ) : (ZMod t)ˣ := + if ht : t ∈ divisorPrimes w H then projectedUnit (divisorModulus w H) t (Finset.dvd_prod_of_mem _ ht) p0 else 1 + have hu (t : ℕ) (ht : t ∈ divisorPrimes w H) : (u t : ZMod t)=(p0.val.val : ZMod t) := by + dsimp only [u] + rw [dite_eq_left ht] + exact projectedUnit_coe (divisorModulus w H) t (Finset.dvd_prod_of_mem _ ht) p0 + have hP (t : ℕ) (ht : t ∈ divisorPrimes w H) : t.Prime := + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1 + let : NeZero (∏ t ∈ divisorPrimes w H,t) := ⟨(divisorModulus_pos w H).ne'⟩ + have hh := prime_unit_avoidance_card (divisorPrimes w H) S hP u beta + have he : Finset.univ.filter (divisorCondition w H beta S p0) = + Finset.univ.filter (fun k0 : ZMod (divisorModulus w H) => + ∀ t ∈ divisorPrimes w H,∀ j ∈ S,(k0.val : ZMod t)+(u t : ZMod t)*(j : ZMod t) ≠ beta t) := by + apply Finset.filter_congr + intro k0 _ + unfold divisorCondition + exact forall_congr' (fun t => forall_congr' (fun ht => by rw [hu t ht])) + rw [he] + exact hh + +theorem multiply_unit_iff (t : ℕ) (u : (ZMod t)ˣ) (x c : ZMod t) : + (u : ZMod t)*x=c ↔ x=(↑(u⁻¹) : ZMod t)*c := by + constructor + · intro h + have hh := congrArg (fun y : ZMod t => (↑(u⁻¹) : ZMod t)*y) h + simpa only [← mul_assoc,Units.inv_mul,one_mul] using hh + · intro h + rw [h,← mul_assoc,Units.mul_inv,one_mul] + +theorem coprime_condition_card (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) + (p1 : (ZMod (coprimeModulus w H))ˣ) (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) : + (Finset.univ.filter (coprimeCondition w H qA delta S p1)).card = + ∏ t ∈ coprimePrimes w H,(t-(positionResidues S t).card) := by + let u (t : ℕ) : (ZMod t)ˣ := if ht : t ∈ coprimePrimes w H then + ZMod.unitOfCoprime H + (((LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1.coprime_iff_not_dvd.mpr + (Finset.mem_filter.mp ht).2).symm) else 1 + let coeff (t : ℕ) (ht : t ∈ coprimePrimes w H) : (ZMod t)ˣ := + projectedUnit (coprimeModulus w H) t (Finset.dvd_prod_of_mem _ ht) p1*ZMod.unitOfCoprime qA (hqA t ht) + let c (t : ℕ) : ZMod t := if ht : t ∈ coprimePrimes w H then (↑((coeff t ht)⁻¹) : ZMod t)*delta t else 0 + have hu (t : ℕ) (ht : t ∈ coprimePrimes w H) : (u t : ZMod t)=(H : ZMod t) := by + simp only [u,dite_eq_left ht,ZMod.coe_unitOfCoprime] + have hc (t : ℕ) (ht : t ∈ coprimePrimes w H) : + (coeff t ht : ZMod t)=(p1.val.val : ZMod t)*(qA : ZMod t) := by + simp only [coeff,Units.val_mul,ZMod.coe_unitOfCoprime] + exact congrArg (fun v : ZMod t => v*(qA : ZMod t)) + (projectedUnit_coe (coprimeModulus w H) t (Finset.dvd_prod_of_mem _ ht) p1) + have hP (t : ℕ) (ht : t ∈ coprimePrimes w H) : t.Prime := + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1 + let : NeZero (∏ t ∈ coprimePrimes w H,t) := ⟨(coprimeModulus_pos w H).ne'⟩ + have hh := prime_unit_avoidance_card (coprimePrimes w H) S hP u c + have he : Finset.univ.filter (coprimeCondition w H qA delta S p1) = + Finset.univ.filter (fun m1 : ZMod (coprimeModulus w H) => + ∀ t ∈ coprimePrimes w H,∀ j ∈ S,(m1.val : ZMod t)+(u t : ZMod t)*(j : ZMod t) ≠ c t) := by + apply Finset.filter_congr + intro m1 _ + unfold coprimeCondition + apply forall_congr' + intro t + apply forall_congr' + intro ht + rw [hu t ht] + apply forall_congr' + intro j + apply forall_congr' + intro _hj + simp only [c,dite_eq_left ht] + rw [← hc t ht] + exact not_congr (multiply_unit_iff t (coeff t ht) _ _) + rw [he] + exact hh + +end ErdosLargePatternLaw + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ConsecutivePowerProjection.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ConsecutivePowerProjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..b47b04f0faaa2e6bd948b02807dae23601da8d7f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ConsecutivePowerProjection.lean @@ -0,0 +1,206 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ConsecutivePairStop + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures + +noncomputable def historyGoodInput (a : ℕ) (v H : ℝ) : Set (RawHistory a) := + rawLast a ⁻¹' regenerativeCostWindow v H + +lemma historyGoodInput_measurable (a : ℕ) (v H : ℝ) : MeasurableSet (historyGoodInput a v H) := + (regenerativeCostWindow_measurable v H).preimage (rawLast_measurable a) + +lemma pairHitTest_first_eq (a : ℕ) (v H : ℝ) : + pairHitTest a 0 (a+1) (by omega) v H = + (rawPrefix (show a ≤ a+1 by omega) ⁻¹' historyGoodInput a v H) ∩ firstPrefixMarkEvent a true := by + ext h + change (_ ∧ _ ∧ _) ↔ ((_ ∧ _) ∧ _) + constructor + · rintro ⟨hR,hM,hW⟩ + exact ⟨⟨hR,hW⟩,hM⟩ + · rintro ⟨⟨hR,hW⟩,hM⟩ + exact ⟨hR,hM,hW⟩ + +theorem pairStoppedHistory_zero_input_filter (a : ℕ) (v H : ℝ) : + pairStoppedHistory a 0 v H= + ((rawExtension a (a+1)).restrict (firstPrefixMarkEvent_measurable a true)) ∘ₖ + stateFilter (historyGoodInput_measurable a v H) := by + rw [pairStoppedHistory_zero] + have he := restriction_comp_of_retained_prefix (Kernel.id : Kernel (RawHistory a) (RawHistory a)) + (rawExtension a (a+1)) (rawPrefix_measurable (show a ≤ a+1 by omega)) + (rawExtension_retains_prefix (show a ≤ a+1 by omega)) + (historyGoodInput_measurable a v H) (firstPrefixMarkEvent_measurable a true) + rw [Kernel.comp_id] at he + ext past S hS + have heS := congrArg (fun K : Kernel (RawHistory a) (RawHistory (a+1)) => K past S) he + rw [Kernel.restrict_apply' _ _ _ hS] at heS + rw [Kernel.restrict_apply' _ _ _ hS,pairHitTest_first_eq] + exact heS + +theorem canonical_capture_projection (a : ℕ) (v H : ℝ) (past : RawHistory a) : + (pairStoppedHistory a 0 v H past).map (rawLast (a+1))=consecutiveCapture v H (rawLast a past) := by + rw [pairStoppedHistory_zero_input_filter,stateFilter_input,consecutiveCapture,stateFilter_input] + by_cases hp : rawLast a past ∈ regenerativeCostWindow v H + · have hh : past ∈ historyGoodInput a v H := hp + rw [ite_eq_left hh,ite_eq_left hp,Kernel.restrict_apply,Kernel.restrict_apply] + change ((rawExtension a (a+1) past).restrict ((rawLast (a+1)) ⁻¹' markedArrival)).map (rawLast (a+1))=_ + rw [← Measure.restrict_map (rawLast_measurable (a+1)) markedArrival_measurable,rawExtension_last_step] + · have hh : past ∉ historyGoodInput a v H := hp + rw [ite_eq_right hh,ite_eq_right hp,Measure.map_zero] + +noncomputable def firstNoHitHistory (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawHistory (a+1)) := + (rawExtension a (a+1)).restrict (pairHitTest_measurable a 0 (a+1) (by omega) v H).compl + +instance firstNoHitHistory_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (firstNoHitHistory a v H) := by + unfold firstNoHitHistory + infer_instance + +lemma firstHistory_partition (a : ℕ) (v H : ℝ) : + pairStoppedHistory a 0 v H+firstNoHitHistory a v H=rawExtension a (a+1) := by + ext past S hS + rw [_root_.add_apply,Measure.add_apply,pairStoppedHistory_zero,firstNoHitHistory, + Kernel.restrict_apply,Kernel.restrict_apply,← Measure.add_apply, + Measure.restrict_add_restrict_compl (pairHitTest_measurable a 0 (a+1) (by omega) v H)] + +theorem canonical_first_continue_projection (a : ℕ) (v H : ℝ) (past : RawHistory a) : + (firstNoHitHistory a v H past).map (rawLast (a+1))=consecutiveFirstContinue v H (rawLast a past) := by + have hPart := congrArg (fun K : Kernel (RawHistory a) (RawHistory (a+1)) => + (K past).map (rawLast (a+1))) (firstHistory_partition a v H) + rw [_root_.add_apply,Measure.map_add _ _ (rawLast_measurable (a+1)), + canonical_capture_projection,rawExtension_last_step] at hPart + have hOther := congrArg (fun K : Kernel CostState CostState => K (rawLast a past)) (consecutive_first_partition v H) + rw [_root_.add_apply] at hOther + ext S _hS + have he := congrArg (fun μ : Measure CostState => μ S) (hPart.trans hOther.symm) + simp only [Measure.add_apply] at he + exact (ENNReal.add_right_inj (measure_ne_top (consecutiveCapture v H (rawLast a past)) S)).mp he + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures + +noncomputable def noHitPairHistory (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawHistory (a+2)) := + (rawExtension a (a+2)).restrict (pairHitTest_measurable a 0 (a+2) (by omega) v H).compl + +instance noHitPairHistory_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (noHitPairHistory a v H) := by + unfold noHitPairHistory + infer_instance + +theorem noHitPairHistory_factor (a : ℕ) (v H : ℝ) : + noHitPairHistory a v H=rawExtension (a+1) (a+2) ∘ₖ firstNoHitHistory a v H := by + unfold noHitPairHistory firstNoHitHistory + have he := rawExtension_restrict_comp (show a ≤ a+1 by omega) (show a+1 ≤ a+2 by omega) + (pairHitTest_measurable a 0 (a+1) (by omega) v H).compl MeasurableSet.univ + rw [Kernel.restrict_univ] at he + ext past S hS + have heS := congrArg (fun K : Kernel (RawHistory a) (RawHistory (a+2)) => K past S) he + rw [Kernel.restrict_apply' _ _ _ hS] at heS + rw [Kernel.restrict_apply' _ _ _ hS] + have hSet : (rawPrefix (show a+1 ≤ a+2 by omega) ⁻¹' (pairHitTest a 0 (a+1) (by omega) v H)ᶜ) ∩ univ= + (pairHitTest a 0 (a+2) (by omega) v H)ᶜ := by + rw [inter_univ,preimage_compl,pairHitTest_prefix] + rw [hSet] at heS + exact heS + +theorem canonical_pair_continue_projection (a : ℕ) (v H : ℝ) (past : RawHistory a) : + (noHitPairHistory a v H past).map (rawLast (a+2))=consecutiveContinue v H (rawLast a past) := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (rawLast_measurable (a+2)),noHitPairHistory_factor, + Kernel.lintegral_comp _ _ _ (g := fun h => F (rawLast (a+2) h)) (hF.comp (rawLast_measurable (a+2)))] + have he (h : RawHistory (a+1)) : + (∫⁻ y, F (rawLast (a+2) y) ∂rawExtension (a+1) (a+2) h)=∫⁻ z, F z ∂costKernel (rawLast (a+1) h) := by + rw [← lintegral_map (g := rawLast (a+2)) hF (rawLast_measurable (a+2)),rawExtension_last_step] + simp_rw [he] + have hG : Measurable (fun z : CostState => ∫⁻ y, F y ∂costKernel z) := hF.lintegral_kernel + rw [← lintegral_map (g := rawLast (a+1)) hG (rawLast_measurable (a+1)),canonical_first_continue_projection, + consecutiveContinue,Kernel.lintegral_comp _ _ _ hF] + +lemma shifted_pair_continue_projection (a n b : ℕ) (hb : b=(a+2*n)+2) (v H : ℝ) + (past : RawHistory (a+2*n)) : + (((rawExtension (a+2*n) b).restrict + (pairHitTest_measurable a n b (by omega) v H).compl) past).map (rawLast b)= + consecutiveContinue v H (rawLast (a+2*n) past) := by + subst b + exact canonical_pair_continue_projection (a+2*n) v H past + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures + +theorem pairSurvivingHistory_projection (a n : ℕ) (v H : ℝ) (past : RawHistory a) : + (pairSurvivingHistory a n v H past).map (rawLast (a+2*n))= + ((consecutiveContinue v H)^n) (rawLast a past) := by + have (m : ℕ) : IsSFiniteKernel ((consecutiveContinue v H)^m) := kernel_power_sfinite _ m + induction n with + | zero => + rw [pairSurvivingHistory_zero] + change (Measure.dirac past).map (rawLast a)=Measure.dirac (rawLast a past) + exact Measure.map_dirac' (rawLast_measurable a) past + | succ n ih => + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (rawLast_measurable _),pairSurvivingHistory_succ, + Kernel.lintegral_comp _ _ _ (g := fun h => F (rawLast (a+2*(n+1)) h)) (hF.comp (rawLast_measurable _))] + have he (h : RawHistory (a+2*n)) : + (∫⁻ y, F (rawLast (a+2*(n+1)) y) ∂((rawExtension (a+2*n) (a+2*(n+1))).restrict + (pairHitTest_measurable a n (a+2*(n+1)) (by omega) v H).compl) h)= + ∫⁻ z, F z ∂consecutiveContinue v H (rawLast (a+2*n) h) := by + rw [← lintegral_map (g := rawLast (a+2*(n+1))) hF (rawLast_measurable _), + shifted_pair_continue_projection a n (a+2*(n+1)) (by omega) v H h] + simp_rw [he] + have hG : Measurable (fun z : CostState => ∫⁻ y, F y ∂consecutiveContinue v H z) := hF.lintegral_kernel + rw [← lintegral_map (g := rawLast (a+2*n)) hG (rawLast_measurable _),ih,pow_succ'] + change (∫⁻ z, ∫⁻ y, F y ∂consecutiveContinue v H z ∂((consecutiveContinue v H)^n) (rawLast a past))= + ∫⁻ y, F y ∂(consecutiveContinue v H ∘ₖ ((consecutiveContinue v H)^n)) (rawLast a past) + exact (Kernel.lintegral_comp _ _ _ hF).symm + +theorem pairStoppedHistory_projection (a n : ℕ) (v H : ℝ) (past : RawHistory a) : + (pairStoppedHistory a n v H past).map (rawLast (a+2*n+1))= + (consecutiveCapture v H ∘ₖ ((consecutiveContinue v H)^n)) (rawLast a past) := by + have : IsSFiniteKernel ((consecutiveContinue v H)^n) := kernel_power_sfinite _ n + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (rawLast_measurable _),pairStoppedHistory_factor, + Kernel.lintegral_comp _ _ _ (g := fun h => F (rawLast (a+2*n+1) h)) (hF.comp (rawLast_measurable _))] + have he (h : RawHistory (a+2*n)) : + (∫⁻ y, F (rawLast (a+2*n+1) y) ∂((rawExtension (a+2*n) (a+2*n+1)).restrict + (pairHitTest_measurable a n (a+2*n+1) le_rfl v H)) h)= + ∫⁻ z, F z ∂consecutiveCapture v H (rawLast (a+2*n) h) := by + have hP := canonical_capture_projection (a+2*n) v H h + rw [pairStoppedHistory_zero] at hP + rw [← lintegral_map (g := rawLast (a+2*n+1)) hF (rawLast_measurable _)] + exact congrArg (fun μ : Measure CostState => ∫⁻ z, F z ∂μ) hP + simp_rw [he] + have hG : Measurable (fun z : CostState => ∫⁻ y, F y ∂consecutiveCapture v H z) := hF.lintegral_kernel + rw [← lintegral_map (g := rawLast (a+2*n)) hG (rawLast_measurable _), + pairSurvivingHistory_projection,Kernel.lintegral_comp _ _ _ hF] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionEnvelope.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionEnvelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..3f6b0696ee909efc93d5d61e7dbaf74aead924f5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionEnvelope.lean @@ -0,0 +1,73 @@ +import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral +import Mathlib.MeasureTheory.Function.JacobianOneDim +import OAI.NumberTheory.Jacobsthal.Harmonic.CompactAnomalyTest +import OAI.NumberTheory.Jacobsthal.Renewal.OccupationDensityIntegral + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology ENNReal +namespace ErdosCorrectionLimit +open ErdosCorrectionOccupation ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.OccupationDensityIntegral NumberTheoryLean.CompactTestMeasurable +open NumberTheoryLean.ActualCouplingUpdates + +noncomputable def fullAnomalyTest (i : Side) (x : ℝ×ℝ) : ℝ := extendedSignedAnomaly i x.1 + +theorem fullAnomalyTest_continuous (i : Side) : Continuous (fullAnomalyTest i) := + (extendedSignedAnomaly_continuous i).comp continuous_fst + +theorem rawTest_measurable {H : Side → ℝ×ℝ → ℝ} (hH : ∀ i, Continuous (H i)) : + Measurable (rawTest H) := by + have hp : Measurable (fun x : ℝ×State => (Real.exp x.1,stateRatio x.2)) := + (Real.measurable_exp.comp measurable_fst).prodMk (stateRatio_measurable.comp measurable_snd) + have hs : MeasurableSet {x : ℝ×State | stateSide x.2=.even} := + measurable_snd (side_set_measurable .even) + have he : rawTest H = fun x => if stateSide x.2=.even then H .even (Real.exp x.1,stateRatio x.2) + else H .odd (Real.exp x.1,stateRatio x.2) := by + funext x + rcases x with ⟨u,s⟩ + cases s <;> rfl + rw [he] + exact Measurable.ite hs ((hH .even).measurable.comp hp) ((hH .odd).measurable.comp hp) + +theorem full_anomaly_exponential : + ∃ C c : ℝ,0 < C ∧ 0 < c ∧ ∀ i r,|extendedSignedAnomaly i r| ≤ C*Real.exp (-c*r) := by + obtain ⟨C,c,_w,hC,hc,_hw,_hd,ha⟩ := common_anomaly_exponential + refine ⟨C,c,hC,hc,?_⟩ + intro i r + have hsign : |sideSign i|=1 := by cases i <;> norm_num [sideSign] + rw [extendedSignedAnomaly,abs_mul,hsign,one_mul] + apply (ha (max 2 r) (le_max_left _ _) i).trans + apply mul_le_mul_of_nonneg_left _ hC.le + apply Real.exp_le_exp.mpr + nlinarith [le_max_right (2:ℝ) r] + +theorem exp_gap_moment_integrable (n : ℕ) {c : ℝ} (hc : 0 < c) : + Integrable (fun u : ℝ => (Real.exp u)^(n+1)*Real.exp (-c*Real.exp u)) := by + have hg : IntegrableOn (fun r : ℝ => r^n*Real.exp (-c*r)) (Ioi 0) := by + have hh := integrableOn_rpow_mul_exp_neg_mul_rpow (s := (n:ℝ)) (p := 1) + (by have hn := Nat.cast_nonneg (α := ℝ) n; linarith) (by norm_num) hc + simpa only [Real.rpow_natCast,Real.rpow_one] using! hh + have hd : ∀ u ∈ (univ : Set ℝ), HasDerivWithinAt Real.exp (Real.exp u) univ u := + fun u _ => (Real.hasDerivAt_exp u).hasDerivWithinAt + have him : Real.exp '' (univ : Set ℝ)=Ioi 0 := by rw [image_univ,Real.range_exp] + have hh := (integrableOn_image_iff_integrableOn_abs_deriv_smul MeasurableSet.univ hd + Real.exp_injective.injOn (fun r : ℝ => r^n*Real.exp (-c*r))).mp (by rwa [him]) + have hh' : Integrable (fun u : ℝ => Real.exp u*((Real.exp u)^n*Real.exp (-c*Real.exp u))) := by + simpa only [abs_of_pos (Real.exp_pos _),smul_eq_mul,integrableOn_univ] using! hh + simpa only [pow_succ',mul_assoc] using! hh' + +end ErdosCorrectionLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionFloorRemainder.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionFloorRemainder.lean new file mode 100644 index 0000000000000000000000000000000000000000..e694474bc2020659dbe85c0d9efe09d776f3af6d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionFloorRemainder.lean @@ -0,0 +1,475 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ContinuousCorrectionLimit +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalSourceScale +import OAI.NumberTheory.Jacobsthal.Harmonic.AuxiliaryPolynomialLifting +import OAI.NumberTheory.Jacobsthal.Partitions.BoxInflation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseBoxHeight + +noncomputable def sourceW (z : ℝ) : ℝ := Real.log z/(Real.log (Real.log z))^2 +noncomputable def sourceB (z : ℝ) : ℝ := Real.log z/Real.log (sourceW z) +noncomputable def sourceY (z : ℝ) : ℕ := ⌊z^2/(Real.log z)^2⌋₊ + +theorem source_B_bounds : ∀ᶠ z : ℝ in atTop, + Real.exp 1 ≤ sourceW z ∧ 1 ≤ sourceB z ∧ sourceB z ≤ Real.log z := by + have hsmall := (isLittleO_log_rpow_rpow_atTop (2:ℝ) (by norm_num : (0:ℝ)<1)).bound (Real.exp_pos (-1)) + have hl := Real.tendsto_log_atTop.eventually hsmall + have hlarge := Real.tendsto_log_atTop.eventually_ge_atTop (Real.exp 1) + filter_upwards [hl,hlarge] with z hz hL + let L := Real.log z + have hL0 : 0 < L := (Real.exp_pos 1).trans_le hL + have hLL : 1 ≤ Real.log L := by + have h := Real.log_le_log (Real.exp_pos 1) hL + simpa only [Real.log_exp] using h + have hsq0 : 0 < (Real.log L)^2 := sq_pos_of_pos (by linarith) + have hsq1 : 1 ≤ (Real.log L)^2 := by nlinarith + have hbound : (Real.log L)^2 ≤ Real.exp (-1)*L := by + change ‖(Real.log L)^(2:ℝ)‖ ≤ Real.exp (-1)*‖L^(1:ℝ)‖ at hz + simpa only [Real.norm_eq_abs,Real.rpow_two,Real.rpow_one, + abs_of_nonneg (sq_nonneg (Real.log L)),abs_of_pos hL0] using hz + have hW : Real.exp 1 ≤ sourceW z := by + apply (le_div_iff₀ hsq0).mpr + have h := mul_le_mul_of_nonneg_left hbound (Real.exp_pos 1).le + have he : Real.exp 1*Real.exp (-1)=1 := by rw [← Real.exp_add]; norm_num + nlinarith + have hW0 : 0 < sourceW z := (Real.exp_pos 1).trans_le hW + have hlogW : 1 ≤ Real.log (sourceW z) := by + have h := Real.log_le_log (Real.exp_pos 1) hW + simpa only [Real.log_exp] using h + have hWle : sourceW z ≤ L := div_le_self hL0.le hsq1 + have hlogle : Real.log (sourceW z) ≤ L := by + have h := Real.log_le_log hW0 hWle + have h' := Real.log_le_sub_one_of_pos hL0 + linarith + refine ⟨hW,?_,?_⟩ + · exact (one_le_div (by linarith : 0 < Real.log (sourceW z))).mpr hlogle + · exact div_le_self hL0.le hlogW + +theorem sourceY_le_square {z : ℝ} (hL : 1 ≤ Real.log z) : (sourceY z : ℝ) ≤ z^2 := by + have hden : 1 ≤ (Real.log z)^2 := by nlinarith + exact (Nat.floor_le (div_nonneg (sq_nonneg z) (sq_nonneg _))).trans + (div_le_self (sq_nonneg z) hden) + +theorem source_cofactor_le_square {z p q : ℝ} (hL : 1 ≤ Real.log z) + (hp : 1 ≤ p) (hq : 0 ≤ q) (hpq : p*q ≤ (sourceY z : ℝ)) : q ≤ z^2 := by + have hmul : q ≤ p*q := by nlinarith [mul_le_mul_of_nonneg_right hp hq] + exact hmul.trans (hpq.trans (sourceY_le_square hL)) + +end ErdosInverseBoxHeight + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceLineBudget +open ErdosInverseBoxHeight + +theorem source_W_power_quarter (C : ℝ) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, 1 < sourceW z ∧ (sourceW z)^C ≤ z^((1 : ℝ)/4) := by + have hs := (isLittleO_log_rpow_rpow_atTop C (by norm_num : (0 : ℝ) < 1/4)).bound zero_lt_one + have hLL := Real.tendsto_log_atTop.eventually_ge_atTop (Real.exp 1) + filter_upwards [source_B_bounds,hs,hLL,eventually_gt_atTop (1 : ℝ)] with z hB hz hlog hz1 + have hz0 : 0 < z := by linarith + have hL0 : 0 < Real.log z := Real.log_pos hz1 + have hLL1 : 1 ≤ Real.log (Real.log z) := by + have h := Real.log_le_log (Real.exp_pos 1) hlog + simpa only [Real.log_exp] using h + have hsquare : 1 ≤ (Real.log (Real.log z))^2 := by nlinarith + have hWL : sourceW z ≤ Real.log z := div_le_self hL0.le hsquare + have hW1 : 1 < sourceW z := (Real.one_lt_exp_iff.mpr (by norm_num : (0 : ℝ) < 1)).trans_le hB.1 + refine ⟨hW1,?_⟩ + have hh : (Real.log z)^C ≤ z^((1 : ℝ)/4) := by + simpa only [Real.norm_eq_abs,abs_of_nonneg (Real.rpow_nonneg hL0.le C), + abs_of_nonneg (Real.rpow_nonneg hz0.le ((1 : ℝ)/4)),one_mul] using hz + exact (Real.rpow_le_rpow (by linarith) hWL hC).trans hh + +theorem source_Y_three_halves : + ∀ᶠ z : ℝ in atTop, z^((3 : ℝ)/2) ≤ (sourceY z : ℝ) := by + have hs := (isLittleO_log_rpow_rpow_atTop (2 : ℝ) (by norm_num : (0 : ℝ) < 1/2)).bound + (by norm_num : (0 : ℝ) < 1/2) + filter_upwards [hs,eventually_ge_atTop (2 : ℝ)] with z hz hz2 + have hz0 : 0 < z := by linarith + have hL : 0 < Real.log z := Real.log_pos (by linarith) + have hL2 : 0 < (Real.log z)^2 := sq_pos_of_pos hL + have hh : (Real.log z)^2 ≤ (1/2 : ℝ)*z^((1 : ℝ)/2) := by + simpa only [Real.norm_eq_abs,Real.rpow_two,abs_of_nonneg (sq_nonneg (Real.log z)), + abs_of_nonneg (Real.rpow_nonneg hz0.le ((1 : ℝ)/2))] using hz + have hp : z^((1 : ℝ)/2)*z^((3 : ℝ)/2) = z^2 := by + rw [← Real.rpow_add hz0] + norm_num + have hmul : 2*z^((3 : ℝ)/2)*(Real.log z)^2 ≤ z^2 := by + nlinarith [mul_le_mul_of_nonneg_right hh (Real.rpow_nonneg hz0.le ((3 : ℝ)/2))] + have hquot : 2*z^((3 : ℝ)/2) ≤ z^2/(Real.log z)^2 := (le_div_iff₀ hL2).mpr hmul + have hfloor := Nat.lt_floor_add_one (z^2/(Real.log z)^2) + have hone : 1 ≤ z^((3 : ℝ)/2) := Real.one_le_rpow (by linarith) (by norm_num) + change z^((3 : ℝ)/2) ≤ (⌊z^2/(Real.log z)^2⌋₊ : ℝ) + linarith + +end ErdosSourceLineBudget + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceLineBudget +open ErdosInverseBoxHeight + +theorem source_parent_square_lower (C : ℝ) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ p q R S : ℝ, + 0 < p → 0 < q → p ≤ 2*R → R ≤ z^((1 : ℝ)/100) → q ≤ S → + Real.logb (sourceW z) ((sourceY z : ℝ)/(p*q)) ≤ C → z ≤ S := by + have hquarter := (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 24/100)).eventually_ge_atTop 2 + filter_upwards [source_W_power_quarter C hC,source_Y_three_halves,hquarter, + eventually_gt_atTop (1 : ℝ)] with z hW hY htwo hz + have hz0 : 0 < z := by linarith + refine ⟨hz,?_⟩ + intro p q R S hp hq hpR hR hqS hlen + have hY0 : (0 : ℝ) < sourceY z := (Real.rpow_pos_of_pos hz0 _).trans_le hY + have hP : p ≤ z^((1 : ℝ)/4) := by + calc + p ≤ 2*R := hpR + _ ≤ 2*z^((1 : ℝ)/100) := mul_le_mul_of_nonneg_left hR (by norm_num) + _ ≤ z^((24 : ℝ)/100)*z^((1 : ℝ)/100) := + mul_le_mul_of_nonneg_right htwo (Real.rpow_nonneg hz0.le _) + _ = z^((1 : ℝ)/4) := by rw [← Real.rpow_add hz0];norm_num + have hratio := (Real.logb_le_iff_le_rpow hW.1 (div_pos hY0 (mul_pos hp hq))).mp hlen + have hmul : (sourceY z : ℝ) ≤ (sourceW z)^C*(p*q) := (div_le_iff₀ (mul_pos hp hq)).mp hratio + have hsmall : (sourceW z)^C*p ≤ z^((1 : ℝ)/2) := by + calc + _ ≤ z^((1 : ℝ)/4)*z^((1 : ℝ)/4) := mul_le_mul hW.2 hP hp.le + (Real.rpow_nonneg hz0.le _) + _ = _ := by rw [← Real.rpow_add hz0];norm_num + have hle : z^((3 : ℝ)/2) ≤ z^((1 : ℝ)/2)*q := by + apply hY.trans + apply hmul.trans + simpa only [mul_assoc] using mul_le_mul_of_nonneg_right hsmall hq.le + have he : z^((3 : ℝ)/2) = z^((1 : ℝ)/2)*z := by + have hh := Real.rpow_add hz0 ((1 : ℝ)/2) 1 + norm_num at hh + exact hh + rw [he] at hle + exact (le_of_mul_le_mul_left hle (Real.rpow_pos_of_pos hz0 ((1 : ℝ)/2))).trans hqS + +end ErdosSourceLineBudget + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceLineBudget +open ErdosInverseBoxHeight + +theorem source_Z_ge_two : ∀ᶠ z : ℝ in atTop, 2 ≤ sourceZ z := by + filter_upwards [Real.tendsto_log_atTop.eventually_ge_atTop (Real.exp 1)] with z hz + have hL : 0 < Real.log z := (Real.exp_pos 1).trans_le hz + have hLL : 1 ≤ Real.log (Real.log z) := by + have hh := Real.log_le_log (Real.exp_pos 1) hz + simpa only [Real.log_exp] using hh + have hLLL : Real.log (Real.log z) ≤ Real.log z := by + have hh := Real.log_le_sub_one_of_pos hL + linarith + have hratio : 1 ≤ Real.log z/Real.log (Real.log z) := + (one_le_div (by linarith)).mpr hLLL + have hexp : (2 : ℝ) ≤ Real.exp 1 := by + have hh := Real.add_one_le_exp (1 : ℝ) + norm_num at hh ⊢ + exact hh + exact hexp.trans (Real.exp_le_exp.mpr hratio) + +theorem extraction_small_power {z R S Z : ℝ} (hz : 1 < z) (hR : 0 ≤ R) (hZ : 0 ≤ Z) + (hRz : R ≤ z^((1 : ℝ)/100)) (hZz : Z ≤ z^((1 : ℝ)/100)) (hSz : z ≤ S) + (hbig : 728 < z^((19 : ℝ)/75)) : + 728*R^4*Z^4 < S^((1 : ℝ)/3) := by + have hz0 : 0 < z := by linarith + have hR4 : R^4 ≤ z^((4 : ℝ)/100) := by + calc + _ ≤ (z^((1 : ℝ)/100))^4 := by gcongr + _ = _ := by rw [← Real.rpow_mul_natCast hz0.le];norm_num + have hZ4 : Z^4 ≤ z^((4 : ℝ)/100) := by + calc + _ ≤ (z^((1 : ℝ)/100))^4 := by gcongr + _ = _ := by rw [← Real.rpow_mul_natCast hz0.le];norm_num + calc + _ ≤ 728*z^((4 : ℝ)/100)*z^((4 : ℝ)/100) := by gcongr + _ = 728*z^((2 : ℝ)/25) := by rw [mul_assoc,← Real.rpow_add hz0];norm_num + _ < z^((19 : ℝ)/75)*z^((2 : ℝ)/25) := + mul_lt_mul_of_pos_right hbig (Real.rpow_pos_of_pos hz0 _) + _ = z^((1 : ℝ)/3) := by rw [← Real.rpow_add hz0];norm_num + _ ≤ S^((1 : ℝ)/3) := Real.rpow_le_rpow hz0.le hSz (by norm_num) + +theorem minimum_line_size_power {z R S Z : ℝ} (hz : 1 < z) (hR : 0 < R) (hZ : 0 < Z) + (hRz : R ≤ z^((1 : ℝ)/100)) (hZz : Z ≤ z^((1 : ℝ)/100)) (hSz : z ≤ S) : + z^((93 : ℝ)/100) ≤ S/(R*Z^6) := by + have hz0 : 0 < z := by linarith + have hZ6 : Z^6 ≤ z^((6 : ℝ)/100) := by + calc + _ ≤ (z^((1 : ℝ)/100))^6 := by gcongr + _ = _ := by rw [← Real.rpow_mul_natCast hz0.le];norm_num + have hprod : R*Z^6 ≤ z^((7 : ℝ)/100) := by + calc + _ ≤ z^((1 : ℝ)/100)*z^((6 : ℝ)/100) := by gcongr + _ = _ := by rw [← Real.rpow_add hz0];norm_num + apply (le_div_iff₀ (mul_pos hR (pow_pos hZ 6))).mpr + calc + _ ≤ z^((93 : ℝ)/100)*z^((7 : ℝ)/100) := + mul_le_mul_of_nonneg_left hprod (Real.rpow_nonneg hz0.le _) + _ = z := by rw [← Real.rpow_add hz0];norm_num + _ ≤ S := hSz + +end ErdosSourceLineBudget + +end + +section + +namespace ErdosSourceLineBudget + +theorem finite_extraction_budget (D : ℕ) (R S Z : ℝ) (hD : (D : ℝ) ≤ R) + (hR : 0 < R) (hS : 1 ≤ S) (hZ : 2 ≤ Z) + (hsmall : 728*R^4*Z^4 < S^((1 : ℝ)/3)) : + 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+(D : ℝ)*(S/(R*Z^6)) < S/Z^4 := by + have hS0 : 0 < S := by linarith + have hZ0 : 0 < Z := by linarith + have hu : 1 ≤ S^((2 : ℝ)/3) := Real.one_le_rpow hS (by norm_num) + have hprod : S^((1 : ℝ)/3)*S^((2 : ℝ)/3) = S := by + rw [← Real.rpow_add hS0] + norm_num + have hlarge : 728*R^4*Z^4*S^((2 : ℝ)/3) < S := by + have hh := mul_lt_mul_of_pos_right hsmall (Real.rpow_pos_of_pos hS0 ((2 : ℝ)/3)) + rwa [hprod] at hh + have hnonlinear : 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3)) < S/(2*Z^4) := by + have hpower : (D : ℝ)^4 ≤ R^4 := by gcongr + have hfirst : 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3)) ≤ 364*R^4*S^((2 : ℝ)/3) := by + nlinarith [mul_nonneg (sub_nonneg.mpr hpower) (show 0 ≤ 1+S^((2 : ℝ)/3) by positivity), + mul_nonneg (pow_nonneg hR.le 4) (sub_nonneg.mpr hu)] + apply hfirst.trans_lt + apply (lt_div_iff₀ (by positivity : 0 < 2*Z^4)).mpr + nlinarith + have hlinear : (D : ℝ)*(S/(R*Z^6)) ≤ S/(2*Z^4) := by + calc + _ ≤ R*(S/(R*Z^6)) := mul_le_mul_of_nonneg_right hD (by positivity) + _ = S/Z^6 := by field_simp + _ ≤ S/(2*Z^4) := by + apply div_le_div_of_nonneg_left hS0.le (by positivity) + have hs : 2 ≤ Z^2 := by nlinarith + nlinarith [mul_nonneg (pow_nonneg hZ0.le 4) (sub_nonneg.mpr hs)] + calc + _ < S/(2*Z^4)+S/(2*Z^4) := add_lt_add_of_lt_of_le hnonlinear hlinear + _ = _ := by ring + +end ErdosSourceLineBudget + +end + +section + +namespace ErdosSourcePolynomial +open ErdosAuxiliaryPolynomial + +noncomputable def sourceDegree (z R : ℝ) : ℕ := ⌊R/(Real.log z)^2⌋₊ + +theorem sourceDegree_le {z R : ℝ} (hR : 0 ≤ R) : + (sourceDegree z R : ℝ) ≤ R/(Real.log z)^2 := + Nat.floor_le (div_nonneg hR (sq_nonneg _)) + +theorem sourceDegree_le_R {z R : ℝ} (hR : 0 ≤ R) (hL : 1 ≤ Real.log z) : + (sourceDegree z R : ℝ) ≤ R := + (sourceDegree_le hR).trans (div_le_self hR (by nlinarith)) + +theorem source_degree_factor {z R : ℝ} (hR : 0 < R) (hL : 0 < Real.log z) : + 2/((sourceDegree z R : ℝ)+2) ≤ 2*(Real.log z)^2/R := by + have hf := Nat.lt_floor_add_one (R/(Real.log z)^2) + change R/(Real.log z)^2 < (sourceDegree z R : ℝ)+1 at hf + have hden : (0 : ℝ) < (sourceDegree z R : ℝ)+2 := by positivity + have hsq : 0 < (Real.log z)^2 := sq_pos_of_pos hL + have hprod : R ≤ ((sourceDegree z R : ℝ)+2)*(Real.log z)^2 := + (div_le_iff₀ hsq).mp (by linarith) + apply (div_le_div_iff₀ hden hR).mpr + convert! (mul_le_mul_of_nonneg_left hprod (by norm_num : (0 : ℝ) ≤ 2)) using 1 + ring + +theorem dimension_le_square (D : ℕ) : ((D+2).choose 2 : ℝ) ≤ ((D : ℝ)+2)^2 := by + have h := Nat.choose_le_pow (D+2) 2 + exact_mod_cast h + +theorem source_dimension_log_bound {z R : ℝ} (hz : 2 ≤ z) (hR : 0 ≤ R) + (hRz : R ≤ z) (hL : 1 ≤ Real.log z) : + Real.log ((sourceDegree z R+2).choose 2 : ℝ) ≤ 4*Real.log z := by + have hd := sourceDegree_le_R hR hL + have hn := dimension_le_square (sourceDegree z R) + have hz0 : 0 ≤ z := by linarith + have hD2 : (sourceDegree z R : ℝ)+2 ≤ z^2 := by nlinarith + have hN : ((sourceDegree z R+2).choose 2 : ℝ) ≤ z^4 := by + apply hn.trans + calc + _ ≤ (z^2)^2 := by gcongr + _ = z^4 := by ring + have hpos : (0 : ℝ) < ((sourceDegree z R+2).choose 2 : ℝ) := by + exact_mod_cast dimension_pos (sourceDegree z R) + have h := Real.log_le_log hpos hN + simpa only [Real.log_pow,Nat.cast_ofNat] using h + +end ErdosSourcePolynomial + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceLineBudget +open ErdosInverseBoxHeight ErdosSourcePolynomial + +theorem uniform_extraction_budget (C : ℝ) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ p q R S : ℝ, + 0 < p → 0 < q → p ≤ 2*R → R ≤ z^((1 : ℝ)/100) → q ≤ S → + Real.logb (sourceW z) ((sourceY z : ℝ)/(p*q)) ≤ C → + z^((93 : ℝ)/100) ≤ S/(R*(sourceZ z)^6) ∧ 1 ≤ S/(R*(sourceZ z)^6) ∧ + 182*(sourceDegree z R : ℝ)^4*(1+S^((2 : ℝ)/3))+ + (sourceDegree z R : ℝ)*(S/(R*(sourceZ z)^6)) < S/(sourceZ z)^4 := by + have hbig := (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 19/75)).eventually_gt_atTop 728 + filter_upwards [source_parent_square_lower C hC,sourceZ_le_small_power,source_Z_ge_two,hbig, + Real.tendsto_log_atTop.eventually_ge_atTop 1] with z hparent hZ hZ2 hlarge hL + refine ⟨hparent.1,?_⟩ + intro p q R S hp hq hpR hR hqS hlen + have hSz := hparent.2 p q R S hp hq hpR hR hqS hlen + have hR0 : 0 < R := by linarith + have hS1 : 1 ≤ S := hparent.1.le.trans hSz + have hmin := minimum_line_size_power hparent.1 hR0 hZ.2.1 hR hZ.2.2 hSz + have hmin1 : 1 ≤ S/(R*(sourceZ z)^6) := + (Real.one_le_rpow hparent.1.le (by norm_num : (0 : ℝ) ≤ 93/100)).trans hmin + have hsmall := extraction_small_power hparent.1 hR0.le hZ.2.1.le hR hZ.2.2 hSz hlarge + exact ⟨hmin,hmin1,finite_extraction_budget (sourceDegree z R) R S (sourceZ z) + (sourceDegree_le_R hR0.le hL) hR0 hS1 hZ2 hsmall⟩ + +end ErdosSourceLineBudget + +end + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology +namespace ErdosCorrectionLimit +open ErdosContinuousAnomaly ErdosBoundaryIntegral +open NumberTheoryLean.DerivativeWeights NumberTheoryLean.BuchstabBridge +open NumberTheoryLean.JacobsthalSourceScale + +noncomputable def sourcePrefactor (s : ℝ) : ℝ := phiEven s/s^2 + +theorem sourcePrefactor_continuousAt : ContinuousAt sourcePrefactor 2 := by + exact (phiEven_continuousAt (by norm_num : (1:ℝ)<2)).div (continuousAt_id.pow 2) (by norm_num) + +theorem sourcePrefactor_two : sourcePrefactor 2=Real.exp Real.eulerMascheroniConstant := by + unfold sourcePrefactor + rw [phiEven_initial (s := 2) le_rfl] + norm_num [evenInitial,sieveA] + ring + +theorem sourcePrefactor_limit {s : ℝ → ℝ} (hs : Tendsto s atTop (𝓝 2)) : + Tendsto (fun L => sourcePrefactor (s L)) atTop (𝓝 (Real.exp Real.eulerMascheroniConstant)) := by + simpa only [sourcePrefactor_two] using! sourcePrefactor_continuousAt.tendsto.comp hs + +noncomputable def paperGap (a : ℝ) (e : ℝ → ℝ) (L : ℝ) : ℝ := + 2*sourceB L-a+2-2*Real.log L/Real.log (sourceW L)+e L + +theorem paper_ratio_tendsto (a : ℝ) {e : ℝ → ℝ} (he : Tendsto e atTop (𝓝 0)) : + Tendsto (fun L => paperGap a e L/sourceB L) atTop (𝓝 2) := by + have hn : Tendsto (fun L : ℝ => (-a+2+e L)/sourceB L) atTop (𝓝 0) := + ((tendsto_const_nhds.add he).div_atTop sourceB_tendsto) + have hl : Tendsto (fun L : ℝ => Real.log L/L) atTop (𝓝 0) := + Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero + have ht : Tendsto (fun L : ℝ => 2+(-a+2+e L)/sourceB L-2*(Real.log L/L)) atTop (𝓝 2) := by + simpa only [add_zero,mul_zero,sub_zero] using (tendsto_const_nhds.add hn).sub (hl.const_mul 2) + apply ht.congr' + filter_upwards [source_scale_eventually,eventually_gt_atTop (0:ℝ)] with L hs hL + have hw : Real.log (sourceW L) ≠ 0 := (Real.log_pos hs.1).ne' + unfold paperGap sourceB + field_simp + ring + +theorem paper_prefactor_tendsto (a : ℝ) {e : ℝ → ℝ} (he : Tendsto e atTop (𝓝 0)) : + Tendsto (fun L => (sourceB L)^2*phiEven (paperGap a e L/sourceB L)/(paperGap a e L)^2) + atTop (𝓝 (Real.exp Real.eulerMascheroniConstant)) := by + have ht := sourcePrefactor_limit (paper_ratio_tendsto a he) + apply ht.congr' + filter_upwards [source_scale_eventually] with L hs + unfold sourcePrefactor + field_simp + +end ErdosCorrectionLimit + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosCorrectionLimit +open NumberTheoryLean.JacobsthalSourceScale + +noncomputable def unroundedY (L : ℝ) : ℝ := Real.exp (2*L)/L^2 + +noncomputable def floorRemainder (L : ℝ) : ℝ := + (Real.log (⌊unroundedY L⌋₊ : ℝ)-(2*L-2*Real.log L))/Real.log (sourceW L) + +theorem unroundedY_tendsto : Tendsto unroundedY atTop atTop := by + simpa only [unroundedY,Real.rpow_two] using! tendsto_exp_mul_div_rpow_atTop 2 2 (by norm_num) + +theorem floor_log_error_tendsto : + Tendsto (fun L => Real.log (⌊unroundedY L⌋₊ : ℝ)-(2*L-2*Real.log L)) atTop (𝓝 0) := by + have hratio := (tendsto_nat_floor_div_atTop (R := ℝ)).comp unroundedY_tendsto + have hh := (Real.continuousAt_log (by norm_num : (1:ℝ)≠0)).tendsto.comp hratio + simp only [Real.log_one] at hh + apply hh.congr' + filter_upwards [eventually_gt_atTop (1:ℝ),unroundedY_tendsto.eventually (eventually_ge_atTop (2:ℝ))] with L hL hY + have hYpos : 0 < unroundedY L := by linarith + have hfloor : 0 < (⌊unroundedY L⌋₊ : ℝ) := by + exact_mod_cast (Nat.floor_pos.mpr (by linarith : 1 ≤ unroundedY L)) + have hL0 : L ≠ 0 := by linarith + change Real.log ((⌊unroundedY L⌋₊ : ℝ)/unroundedY L)=_ + rw [Real.log_div hfloor.ne' hYpos.ne'] + congr 1 + rw [unroundedY,Real.log_div (Real.exp_ne_zero _) (pow_ne_zero 2 hL0),Real.log_exp,Real.log_pow] + norm_num + +theorem floorRemainder_tendsto : Tendsto floorRemainder atTop (𝓝 0) := by + exact floor_log_error_tendsto.div_atTop (Real.tendsto_log_atTop.comp sourceW_tendsto) + +theorem sourceY_exp (L : ℝ) : + ErdosInverseBoxHeight.sourceY (Real.exp L)=⌊unroundedY L⌋₊ := by + unfold ErdosInverseBoxHeight.sourceY unroundedY + rw [Real.log_exp,pow_two,← Real.exp_add] + congr 2 + ring_nf + +theorem paperGap_floor_eq (a : ℝ) {L : ℝ} (hW : 1 < sourceW L) : + paperGap a floorRemainder L= + Real.log (ErdosInverseBoxHeight.sourceY (Real.exp L):ℝ)/Real.log (sourceW L)-a+2 := by + rw [sourceY_exp] + have hw0 : Real.log (sourceW L) ≠ 0 := (Real.log_pos hW).ne' + unfold paperGap floorRemainder sourceB + field_simp + ring + +end ErdosCorrectionLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionStateSections.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionStateSections.lean new file mode 100644 index 0000000000000000000000000000000000000000..cbae1ba41bbabd7a32a49abbde2225891bc6a5ac --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionStateSections.lean @@ -0,0 +1,186 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CorrectionWeightedIntegral + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology ENNReal +namespace ErdosCorrectionLimit +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.InvariantInverseWeights +open NumberTheoryLean.TransitionKernels +open Erdos970Dependency.StateKernelInvariance Erdos970Dependency.OrdinaryKernelInvariance +open Erdos970Dependency.InvariantFiniteness Erdos970Dependency.InvariantDensities +open Erdos970Dependency.RawStateCost + +theorem even_inverse_product (G : State → ℝ) (t : ℝ) : + Erdos970Dependency.InvariantDensities.evenDensity t* + (G (.inl (evenLift t))/stateWeight (.inl (evenLift t)))= + (Ici (2:ℝ)).indicator (fun t => G (.inl (evenLift t))) t := by + by_cases ht : 2 ≤ t + · have hl : (evenLift t).1=t := max_eq_right (by linarith) + have hw : stateWeight (.inl (evenLift t))=NumberTheoryLean.DerivativeWeights.phiEven t := by + change NumberTheoryLean.DerivativeWeights.phiEven (evenLift t).1=_ + rw [hl] + rw [Erdos970Dependency.InvariantDensities.evenDensity, + indicator_of_mem (show t ∈ Ici (2:ℝ) from ht), + indicator_of_mem (show t ∈ Ici (2:ℝ) from ht),hw] + field_simp [(NumberTheoryLean.DerivativeWeights.phiEven_pos (by linarith : 1 < t)).ne'] + · rw [Erdos970Dependency.InvariantDensities.evenDensity, + indicator_of_notMem (show t ∉ Ici (2:ℝ) from ht), + indicator_of_notMem (show t ∉ Ici (2:ℝ) from ht),zero_mul] + +theorem odd_inverse_product (G : State → ℝ) (t : ℝ) : + Erdos970Dependency.InvariantDensities.oddDensity t* + (G (.inr (oddLift t))/stateWeight (.inr (oddLift t)))= + (Ici (1:ℝ)).indicator (fun t => oddFactor t*G (.inr (oddLift t))) t := by + by_cases ht : 1 ≤ t + · have hl : (oddLift t).1=t := max_eq_right (by linarith) + have hw : stateWeight (.inr (oddLift t))=NumberTheoryLean.DerivativeWeights.phiOdd t := by + change NumberTheoryLean.DerivativeWeights.phiOdd (oddLift t).1=_ + rw [hl] + rw [Erdos970Dependency.InvariantDensities.oddDensity, + indicator_of_mem (show t ∈ Ici (1:ℝ) from ht), + indicator_of_mem (show t ∈ Ici (1:ℝ) from ht),hw] + field_simp [(NumberTheoryLean.DerivativeWeights.phiOdd_pos t).ne'] + · rw [Erdos970Dependency.InvariantDensities.oddDensity, + indicator_of_notMem (show t ∉ Ici (1:ℝ) from ht), + indicator_of_notMem (show t ∉ Ici (1:ℝ) from ht),zero_mul] + +theorem state_inverse_integral {G : State → ℝ} (hG : Measurable G) + (hi : Integrable (fun s => G s/stateWeight s) stateMeasure) : + (∫ s : State,G s/stateWeight s ∂stateMeasure)= + (∫ t in Ici 2,G (.inl (evenLift t)))+ + ∫ t in Ici 1,oddFactor t*G (.inr (oddLift t)) := by + have hq : Measurable (fun s => G s/stateWeight s) := hG.div stateWeight_measurable + rw [stateMeasure] at hi ⊢ + rw [integral_add_measure hi.left_of_add_measure hi.right_of_add_measure, + integral_map measurable_inl.aemeasurable hq.aestronglyMeasurable, + integral_map measurable_inr.aemeasurable hq.aestronglyMeasurable] + have he := integral_map (μ := evenMeasure) evenLift_measurable.aemeasurable + (hq.comp measurable_inl).aestronglyMeasurable + have ho := integral_map (μ := oddMeasure) oddLift_measurable.aemeasurable + (hq.comp measurable_inr).aestronglyMeasurable + simp only [Function.comp_def] at he ho + rw [evenStateMeasure,he,oddStateMeasure,ho,integral_evenMeasure,integral_oddMeasure] + simp_rw [even_inverse_product,odd_inverse_product] + rw [integral_indicator measurableSet_Ici,integral_indicator measurableSet_Ici] + +end ErdosCorrectionLimit + +end + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open scoped Topology ENNReal +namespace ErdosCorrectionLimit +open ErdosCorrectionOccupation ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.PrimeOccupationDensity NumberTheoryLean.OccupationDensityIntegral +open NumberTheoryLean.InvariantInverseWeights +open Erdos970Dependency.StateKernelInvariance Erdos970Dependency.OrdinaryKernelInvariance +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantCostBound + +noncomputable def cutoffAmplitude (L A B : ℝ) (s : State) : ℝ := + if stateRatio s < L then Sum.elim (fun _ => A) (fun _ => B) s else 0 + +theorem cutoffAmplitude_measurable (L A B : ℝ) : Measurable (cutoffAmplitude L A B) := + Measurable.ite (measurableSet_lt stateRatio_measurable measurable_const) + (measurable_const.sumElim measurable_const) measurable_const + +theorem cutoffAmplitude_integral (L A B : ℝ) + (hi : Integrable (fun s => cutoffAmplitude L A B s/stateWeight s) stateMeasure) : + (∫ s : State,cutoffAmplitude L A B s/stateWeight s ∂stateMeasure)= + A*(∫ _t : ℝ in Ico 2 L,1)+B*(∫ t : ℝ in Ico 1 L,oddFactor t) := by + rw [state_inverse_integral (cutoffAmplitude_measurable L A B) hi] + have he : (Ici (2:ℝ)).indicator (fun t => cutoffAmplitude L A B (.inl (evenLift t)))= + (Ico (2:ℝ) L).indicator (fun _ => A) := by + funext t + by_cases ht : 2 ≤ t + · have hl : stateRatio (.inl (evenLift t))=t := max_eq_right (by linarith) + by_cases hL : t < L + · simp [indicator_of_mem (show t ∈ Ici (2:ℝ) from ht), + indicator_of_mem (show t ∈ Ico (2:ℝ) L from ⟨ht,hL⟩),cutoffAmplitude,hl,hL] + · simp [indicator_of_mem (show t ∈ Ici (2:ℝ) from ht), + cutoffAmplitude,hl,hL] + · simp [indicator_of_notMem (show t ∉ Ici (2:ℝ) from ht), + indicator_of_notMem (show t ∉ Ico (2:ℝ) L from fun h => ht h.1)] + have ho : (Ici (1:ℝ)).indicator (fun t => oddFactor t*cutoffAmplitude L A B (.inr (oddLift t)))= + (Ico (1:ℝ) L).indicator (fun t => B*oddFactor t) := by + funext t + by_cases ht : 1 ≤ t + · have hl : stateRatio (.inr (oddLift t))=t := max_eq_right (by linarith) + by_cases hL : t < L + · simp [indicator_of_mem (show t ∈ Ici (1:ℝ) from ht), + indicator_of_mem (show t ∈ Ico (1:ℝ) L from ⟨ht,hL⟩),cutoffAmplitude,hl,hL,mul_comm] + · simp [indicator_of_mem (show t ∈ Ici (1:ℝ) from ht), + cutoffAmplitude,hl,hL] + · simp [indicator_of_notMem (show t ∉ Ici (1:ℝ) from ht), + indicator_of_notMem (show t ∉ Ico (1:ℝ) L from fun h => ht h.1)] + rw [← integral_indicator measurableSet_Ici,← integral_indicator measurableSet_Ici, + he,ho,integral_indicator measurableSet_Ico,integral_indicator measurableSet_Ico,integral_const_mul] + simp [mul_comm] + +theorem fullWeighted_cutoff (u : ℝ) (s : State) : + fullWeighted (u,s)=cutoffAmplitude (Real.exp u/2) + ((Real.exp u)^2/costMass*extendedSignedAnomaly .even (Real.exp u)) + ((Real.exp u)^2/costMass*extendedSignedAnomaly .odd (Real.exp u)) s/stateWeight s := by + unfold fullWeighted density rawTest fullAnomalyTest cutoffAmplitude + cases s <;> simp only [stateSide,Sum.elim_inl,Sum.elim_inr] + all_goals split_ifs <;> ring + +theorem fullWeighted_section (u : ℝ) : + (∫ s : State,fullWeighted (u,s) ∂stateMeasure)= + (Real.exp u)^2/costMass*(extendedSignedAnomaly .even (Real.exp u)*(∫ _t : ℝ in Ico 2 (Real.exp u/2),1)+ + extendedSignedAnomaly .odd (Real.exp u)*(∫ t : ℝ in Ico 1 (Real.exp u/2),oddFactor t)) := by + have hi := fullWeighted_section_integrable u + simp_rw [fullWeighted_cutoff] at hi ⊢ + rw [cutoffAmplitude_integral _ _ _ hi] + ring + +theorem even_cutoff_length (L : ℝ) : (∫ _t : ℝ in Ico 2 L,1)=if 2 < L then L-2 else 0 := by + by_cases h : 2 < L + · rw [ite_eq_left h,integral_Ico_eq_integral_Ioc,← intervalIntegral.integral_of_le h.le] + simp + · rw [ite_eq_right h,Ico_eq_empty_of_le (le_of_not_gt h)] + simp + +theorem odd_cutoff_length (L : ℝ) : + (∫ t : ℝ in Ico 1 L,oddFactor t)=if 1 < L then L+1/L-2 else 0 := by + by_cases h : 1 < L + · rw [ite_eq_left h,integral_Ico_eq_integral_Ioc,← intervalIntegral.integral_of_le h.le,integral_oddFactor h.le] + · rw [ite_eq_right h,Ico_eq_empty_of_le (le_of_not_gt h)] + simp + +noncomputable def radialNumerator (r : ℝ) : ℝ := + (if 4 < r then r*(r/2-2)*continuousAnomaly .even r else 0)- + (if 2 < r then (r^2/2-2*r+2)*continuousAnomaly .odd r else 0) + +theorem fullWeighted_section_radial (u : ℝ) : + (∫ s : State,fullWeighted (u,s) ∂stateMeasure)=Real.exp u/costMass*radialNumerator (Real.exp u) := by + rw [fullWeighted_section,even_cutoff_length,odd_cutoff_length] + have hr : 0 < Real.exp u := Real.exp_pos _ + have h4 : (2:ℝ) < Real.exp u/2 ↔ 4 < Real.exp u := by constructor <;> intro h <;> linarith + have h2 : (1:ℝ) < Real.exp u/2 ↔ 2 < Real.exp u := by constructor <;> intro h <;> linarith + simp only [h4,h2,radialNumerator] + by_cases hh2 : 2 < Real.exp u + · have he : extendedSignedAnomaly .even (Real.exp u)=continuousAnomaly .even (Real.exp u) := by + simp [extendedSignedAnomaly,max_eq_right hh2.le,sideSign] + have ho : extendedSignedAnomaly .odd (Real.exp u)=-continuousAnomaly .odd (Real.exp u) := by + simp [extendedSignedAnomaly,max_eq_right hh2.le,sideSign] + rw [he,ho,ite_eq_left hh2] + split_ifs <;> field_simp <;> ring + · have hh4 : ¬4 < Real.exp u := by linarith + simp only [ite_eq_right hh2,ite_eq_right hh4,mul_zero,add_zero,sub_zero] + +end ErdosCorrectionLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionUniformTruncation.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionUniformTruncation.lean new file mode 100644 index 0000000000000000000000000000000000000000..1491fc0e2f89a5c9373c777813333c6ef158ca38 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CorrectionUniformTruncation.lean @@ -0,0 +1,56 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CompactCorrectionLimit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Finset +namespace ErdosCorrectionLimit +open ErdosCorrectionOccupation ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.PrimeBinMembership NumberTheoryLean.ActualPrimeHigh +open NumberTheoryLean.LiteralUniformPrimeTail + +theorem uniform_compact_correction_above (Kmin ell d eps : ℝ) (hell : 2 ≤ ell) + (hd : 0 < d) (heps : 0 < eps) : + ∃ K B₀ w₀ : ℝ,3 ≤ K ∧ Kmin ≤ K ∧ 0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + B^2*|continuousBoundaryCorrection w ell start-compactCorrection K w ell start| ≤ eps := by + obtain ⟨C,c,_wA,hC,hc,_hwA,_hD,hA⟩ := common_anomaly_exponential + obtain ⟨M₀,BT,wT,hBT,hwT,hT⟩ := actual_uniform_original_prime_tail d c (eps/C) hd hc (div_pos heps hC) + obtain ⟨n,hn⟩ := exists_nat_ge Kmin + let M : ℕ := M₀+n + let K : ℝ := 3*((M:ℝ)+1) + have hK : 3 ≤ K := by dsimp [K]; have hn := Nat.cast_nonneg (α := ℝ) M; linarith + have hKmin : Kmin ≤ K := by + apply hn.trans + dsimp [K,M] + push_cast + have hn0 := Nat.cast_nonneg (α := ℝ) n + have hm0 := Nat.cast_nonneg (α := ℝ) M₀ + linarith + refine ⟨K,max BT (max 4 ell),wT,hK,hKmin,hBT.trans_le (le_max_left _ _),hwT,?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBT' : BT ≤ B := (le_max_left _ _).trans hB + have hB4 : 4 ≤ B := ((le_max_left _ _).trans (le_max_right _ _)).trans hB + have hellB : ell ≤ B := ((le_max_right _ _).trans (le_max_right _ _)).trans hB + have ht := hT M (by dsimp [M]; omega) B w hBT' hw ell (by linarith) hellB hcomp start hi h199 h23 hcons hcut + have he := compact_correction_error (K := K) (w := w) hA hB4 hell hellB start hi h199 h23 hcons hcut + have heB := mul_le_mul_of_nonneg_left he (sq_nonneg B) + have htC := mul_le_mul_of_nonneg_left ht hC.le + have hcanc : C*(eps/C)=eps := mul_div_cancel₀ eps (ne_of_gt hC) + rw [hcanc] at htC + nlinarith + +end ErdosCorrectionLimit + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CountErrorRemainder.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CountErrorRemainder.lean new file mode 100644 index 0000000000000000000000000000000000000000..30f7b1c54fd5605a73d76d71f6baf694d0e0d697 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CountErrorRemainder.lean @@ -0,0 +1,59 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CompactSmallCountErrors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CountErrorRemainder +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission +open CountErrorClassification LargeGapCountErrors CompactSmallCountErrors CountErrorFamilyMajorant +open LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem uniform_count_error_remainder (aStar d eta : ℝ) (ha : 0 < aStar) (hd : 0 < d) (heta : 0 < eta) : + ∃ Cbad K₀ : ℝ,0 < Cbad ∧ 3 ≤ K₀ ∧ ∀ K : ℝ,K₀ ≤ K → + ∃ Csmall B₀ w₀ : ℝ,0 < Csmall ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → w < top → Real.log B ≤ d*Real.log w → + ∀ Y : ℕ,0 < Y → ∀ z : Node,z.gap=Real.log (Y:ℝ)/Real.log w-aStar+2 → + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ residue : ℕ → ℕ,∀ eps : ℝ,0 ≤ eps → ∀ F : Finset (List ℕ), + F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + (B^2/((Y:ℝ)*V0))*errorSum Y small residue V0 F ≤ eta+Csmall*eps+ + Cbad*(B^2*(∑ ps∈badCompactWords w K eps Y small residue V0 z F,prefixWeight ps)) := by + obtain ⟨Cbad,WD,hCbad,hWD,hDiscard⟩ := count_error_family_majorant aStar ha + obtain ⟨K₀,BG,WG,hK₀,hBG,hWG,hLarge⟩ := uniform_large_gap_count_errors aStar d eta ha hd heta + refine ⟨Cbad,K₀,hCbad,hK₀,?_⟩ + intro K hK + obtain ⟨Csmall,BC,WC,hCsmall,hBC,hWC,hCompact⟩ := uniform_compact_small_count_errors K d (hK₀.trans hK) hd + refine ⟨Csmall,max BG BC,max WG (max WC WD),hCsmall,hBG.trans (le_max_left _ _),hWG.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw htop hcomp Y hY z hroot hi h199 h23 hz hcut hclosed hpower residue eps heps F hF + dsimp only + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + have hB3 : 3 ≤ B := hBG.trans ((le_max_left _ _).trans hB) + have hA := hLarge K B w top hK ((le_max_left _ _).trans hB) ((le_max_left _ _).trans hw) htop hcomp + Y hY z hroot hi h199 h23 hz hcut hclosed hpower residue (largeGapWords w K z F) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) (fun ps hp => (Finset.mem_filter.mp hp).2) + have hBnd := hCompact B w top ((le_max_right _ _).trans hB) ((le_trans (le_max_left _ _) (le_max_right _ _)).trans hw) + htop hcomp z hi h199 h23 hz hcut hclosed hpower Y hY residue eps heps + (smallErrorWords w K eps Y small residue V0 z F) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) (fun ps hp => (Finset.mem_filter.mp hp).2) + have hD := hDiscard B w top hB3 ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw) htop + Y hY z hroot hi h199 hz hcut hclosed hpower residue (badCompactWords w K eps Y small residue V0 z F) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) + have hPart := congrArg (fun t : ℝ => (B^2/((Y:ℝ)*V0))*t) (error_sum_partition w K eps Y small residue V0 z F) + unfold errorSum at hPart ⊢ + change (B^2/((Y:ℝ)*V0))*(∑ ps∈F,|(ErdosInverseCounts.modulusCount Y small residue ps.prod:ℝ)-((Y:ℝ)/(ps.prod:ℝ))*V0|) ≤ _ + nlinarith +end NumberTheoryLean.CountErrorRemainder + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/CoupledBoundaryBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CoupledBoundaryBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..bcd0c6cea99354ac8662efadab6a46dff2d52739 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/CoupledBoundaryBounds.lean @@ -0,0 +1,94 @@ +import OAI.NumberTheory.Jacobsthal.Probability.CouplingLabelEvents + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CoupledBoundaryBounds + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualSupportIntervals CoupledBoundaryEvents PrimeCompletedIntervalUpper +open ContinuousIntervalUpper RegeneratingInverseBands ContinuousKilledBins + +theorem prime_bad_cells_upper : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → + ∀ h : History w ell S start, ∀ mesh Lc Uc : ℝ, 0 < mesh → + let Ld := minRatio h.node.side h.node.ratio + let Ud := upperSupport S ell h.node.gap + |Ld-Lc|+mesh ≤ 1 → |Ud-Uc|+mesh ≤ 1 → + chain w ell S start (some h) (primeBadCells mesh Ld Lc Ud Uc) ≤ + ENNReal.ofReal (C*(1+S)^2*(|Ld-Lc|+|Ud-Uc|+2*mesh+ + 2*Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)))) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hbound⟩ := prime_completed_interval_upper + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw ell S start hell hr hs hsS h mesh Lc Uc hm + dsimp only + intro hL hU + let Ld := minRatio h.node.side h.node.ratio + let Ud := upperSupport S ell h.node.gap + let e := Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)) + have hwid := packet_widths hm.le Ld Lc Ud Uc + have hleft := hbound w hw ell S start hell hr hs hsS h (lowerA Ld Lc) (lowerB mesh Ld Lc) + hwid.1.1 hwid.1.2.1 (hwid.1.2.2.trans hL) + have hright := hbound w hw ell S start hell hr hs hsS h (upperA mesh Ud Uc) (upperB Ud Uc) + hwid.2.1 hwid.2.2.1 (hwid.2.2.2.trans hU) + have hM : 0 ≤ C*(1+S)^2 := by positivity + have he : 0 ≤ e := (Real.exp_pos _).le + calc + _ ≤ 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)) := + prime_bad_cell_packets h (by linarith) hr hs hsS hm Lc Uc + _ ≤ ENNReal.ofReal (C*(1+S)^2*(lowerB mesh Ld Lc-lowerA Ld Lc+e))+ + ENNReal.ofReal (C*(1+S)^2*(upperB Ud Uc-upperA mesh Ud Uc+e)) := add_le_add hleft hright + _ = ENNReal.ofReal (C*(1+S)^2*((lowerB mesh Ld Lc-lowerA Ld Lc)+ + (upperB Ud Uc-upperA mesh Ud Uc)+2*e)) := by + rw [← ENNReal.ofReal_add (mul_nonneg hM (by linarith [hwid.1.2.1])) + (mul_nonneg hM (by linarith [hwid.2.2.1]))] + congr 1 + ring + _ ≤ _ := ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left + (by linarith [hwid.1.2.2,hwid.2.2.2]) hM) + +theorem continuous_bad_cells_upper : ∃ C : ℝ, 0 < C ∧ ∀ v ell S : ℝ, ∀ z : CostState, + 0 < ell → stateRatio z.1 ≤ S → ∀ mesh Ld Ud : ℝ, 0 < mesh → + 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) ≤ + ENNReal.ofReal (C*(1+S)^2*(|Ld-Lc|+|Ud-Uc|+2*mesh)) := by + obtain ⟨C,hC,hbound⟩ := completed_interval_upper + refine ⟨C,hC,?_⟩ + intro v ell S z hell hsS mesh Ld Ud hm + dsimp only + let Lc := minRatio (stateSide z.1) (stateRatio z.1) + let Uc := upperSupport S ell (gapValue v z) + have hwid := packet_widths hm.le Ld Lc Ud Uc + have hleft := hbound v ell S (lowerA Ld Lc) (lowerB mesh Ld Lc) z hsS + have hright := hbound v ell S (upperA mesh Ud Uc) (upperB Ud Uc) z hsS + have hM : 0 ≤ C*(1+S)^2 := by positivity + rw [← ENNReal.ofReal_mul hM] at hleft hright + calc + _ ≤ 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)) := + continuous_bad_cell_packets v z hell hm Ld Ud + _ ≤ ENNReal.ofReal (C*(1+S)^2*(lowerB mesh Ld Lc-lowerA Ld Lc))+ + ENNReal.ofReal (C*(1+S)^2*(upperB Ud Uc-upperA mesh Ud Uc)) := add_le_add hleft hright + _ = ENNReal.ofReal (C*(1+S)^2*((lowerB mesh Ld Lc-lowerA Ld Lc)+ + (upperB Ud Uc-upperA mesh Ud Uc))) := by + rw [← ENNReal.ofReal_add (mul_nonneg hM (sub_nonneg.mpr hwid.1.2.1)) + (mul_nonneg hM (sub_nonneg.mpr hwid.2.2.1))] + congr 1 + ring + _ ≤ _ := ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left + (by linarith [hwid.1.2.2,hwid.2.2.2]) hM) + +end NumberTheoryLean.CoupledBoundaryBounds + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/DisjointBlockExpansion.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/DisjointBlockExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..c980f155b088e2d577da38a149a3e16bcc72b5fb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/DisjointBlockExpansion.lean @@ -0,0 +1,578 @@ +import Mathlib.Algebra.BigOperators.Ring.Finset +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Analysis.BonferroniDensity + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.DisjointBlockExpansion + +open scoped BigOperators + +noncomputable def blockChoices (B : Finset ℕ) (blocks : ℕ → Finset ℕ) : + Finset (∀ j ∈ B, Finset ℕ) := by + classical + exact B.pi fun j => (blocks j).powerset + +@[simp] theorem mem_blockChoices {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {choice : ∀ j ∈ B, Finset ℕ} : + choice ∈ blockChoices B blocks ↔ ∀ j (hj : j ∈ B), choice j hj ⊆ blocks j := by + classical + simp only [blockChoices, Finset.mem_pi, Finset.mem_powerset] + +noncomputable def selectedUnion (B : Finset ℕ) (choice : ∀ j ∈ B, Finset ℕ) : Finset ℕ := by + classical + exact B.attach.biUnion fun j => choice j.1 j.2 + +theorem selectedUnion_subset {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {choice : ∀ j ∈ B, Finset ℕ} (hc : choice ∈ blockChoices B blocks) : + selectedUnion B choice ⊆ B.biUnion blocks := by + classical + intro p hp + obtain ⟨j, _, hpj⟩ := Finset.mem_biUnion.mp hp + exact Finset.mem_biUnion.mpr ⟨j.1, j.2, (mem_blockChoices.mp hc j.1 j.2) hpj⟩ + +theorem selectedUnion_inter_block {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + {choice : ∀ j ∈ B, Finset ℕ} (hc : choice ∈ blockChoices B blocks) + (j : ℕ) (hj : j ∈ B) : selectedUnion B choice ∩ blocks j = choice j hj := by + classical + ext p + constructor + · intro hp + obtain ⟨hpu, hpj⟩ := Finset.mem_inter.mp hp + obtain ⟨i, _, hpi⟩ := Finset.mem_biUnion.mp hpu + by_cases hij : i.1 = j + · subst j + exact hpi + · exact False.elim ((Finset.disjoint_left.mp (hdis i.2 hj hij)) + ((mem_blockChoices.mp hc i.1 i.2) hpi) hpj) + · intro hp + exact Finset.mem_inter.mpr ⟨Finset.mem_biUnion.mpr + ⟨⟨j, hj⟩, Finset.mem_attach _ _, hp⟩, (mem_blockChoices.mp hc j hj) hp⟩ + +def intersectionChoices (B : Finset ℕ) (blocks : ℕ → Finset ℕ) (T : Finset ℕ) : + ∀ j ∈ B, Finset ℕ := fun j _ => T ∩ blocks j + +theorem intersectionChoices_mem (B : Finset ℕ) (blocks : ℕ → Finset ℕ) (T : Finset ℕ) : + intersectionChoices B blocks T ∈ blockChoices B blocks := by + apply mem_blockChoices.mpr + intro j _ + exact Finset.inter_subset_right + +theorem selectedUnion_intersectionChoices {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {T : Finset ℕ} (hT : T ⊆ B.biUnion blocks) : + selectedUnion B (intersectionChoices B blocks T) = T := by + classical + ext p + constructor + · intro hp + obtain ⟨j, _, hpj⟩ := Finset.mem_biUnion.mp hp + exact (Finset.mem_inter.mp hpj).1 + · intro hp + obtain ⟨j, hj, hpj⟩ := Finset.mem_biUnion.mp (hT hp) + exact Finset.mem_biUnion.mpr ⟨⟨j, hj⟩, Finset.mem_attach _ _, Finset.mem_inter.mpr ⟨hp, hpj⟩⟩ + +theorem sum_subsets_product (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (F : ℕ → Finset ℕ → ℝ) : + (∑ T ∈ (B.biUnion blocks).powerset, ∏ j ∈ B, F j (T ∩ blocks j)) = + ∏ j ∈ B, ∑ T ∈ (blocks j).powerset, F j T := by + classical + symm + rw [Finset.prod_sum] + apply Finset.sum_bij (fun choice _ => selectedUnion B choice) + · intro choice hc + exact Finset.mem_powerset.mpr (selectedUnion_subset hc) + · intro choice hc other ho heq + funext j hj + rw [← selectedUnion_inter_block hdis hc j hj, heq, + selectedUnion_inter_block hdis ho j hj] + · intro T hT + exact ⟨intersectionChoices B blocks T, intersectionChoices_mem B blocks T, + selectedUnion_intersectionChoices (Finset.mem_powerset.mp hT)⟩ + · intro choice hc + conv_rhs => rw [← Finset.prod_attach] + apply Finset.prod_congr rfl + intro j _ + rw [selectedUnion_inter_block hdis hc j.1 j.2] + +def truncatedCoefficient (m : ℕ) (T : Finset ℕ) : ℝ := + if T.card ≤ m then (-1 : ℝ) ^ T.card else 0 + +def layerCoefficient (m : ℕ) (T : Finset ℕ) : ℝ := + if T.card = m then 1 else 0 + +theorem truncatedCoefficient_sum (m : ℕ) (P : Finset ℕ) (F : Finset ℕ → ℝ) : + (∑ T ∈ P.powerset, truncatedCoefficient m T * F T) = + BonferroniBlocks.momentPolynomial m P F := by + classical + let S := P.powerset.filter fun T => T.card ≤ m + have hmap : ∀ T ∈ S, T.card ∈ Finset.range (m + 1) := by + intro T hT + exact Finset.mem_range.mpr (Nat.lt_succ_of_le (Finset.mem_filter.mp hT).2) + calc + _ = ∑ T ∈ S, (-1 : ℝ) ^ T.card * F T := by + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro T _ + unfold truncatedCoefficient + split_ifs <;> simp + _ = ∑ r ∈ Finset.range (m + 1), ∑ T ∈ S.filter (fun T => T.card = r), + (-1 : ℝ) ^ T.card * F T := + (Finset.sum_fiberwise_of_maps_to hmap _).symm + _ = _ := by + unfold BonferroniBlocks.momentPolynomial + apply Finset.sum_congr rfl + intro r hr + have hrm : r ≤ m := Nat.le_of_lt_succ (Finset.mem_range.mp hr) + have hsets : S.filter (fun T => T.card = r) = P.powersetCard r := by + ext T + simp only [S, Finset.mem_filter, Finset.mem_powerset, Finset.mem_powersetCard] + constructor + · rintro ⟨⟨hTP, _⟩, hcard⟩ + exact ⟨hTP, hcard⟩ + · rintro ⟨hTP, hcard⟩ + exact ⟨⟨hTP, by omega⟩, hcard⟩ + rw [hsets, Finset.mul_sum] + apply Finset.sum_congr rfl + intro T hT + rw [(Finset.mem_powersetCard.mp hT).2] + +theorem truncatedCoefficient_evaluation (m : ℕ) (P : Finset ℕ) (hit : ℕ → Prop) : + (∑ T ∈ P.powerset, truncatedCoefficient m T * BonferroniBlocks.intersectionValue T hit) = + BonferroniBlocks.coefficientPolynomial m P hit := + truncatedCoefficient_sum m P (fun T => BonferroniBlocks.intersectionValue T hit) + +theorem layerCoefficient_evaluation (m : ℕ) (P : Finset ℕ) (hit : ℕ → Prop) : + (∑ T ∈ P.powerset, layerCoefficient m T * BonferroniBlocks.intersectionValue T hit) = + (((BonferroniBlocks.hitSet P hit).card).choose m : ℝ) := by + classical + calc + _ = ∑ T ∈ P.powersetCard m, BonferroniBlocks.intersectionValue T hit := by + rw [Finset.powersetCard_eq_filter, Finset.sum_filter] + apply Finset.sum_congr rfl + intro T _ + unfold layerCoefficient + split_ifs <;> simp + _ = _ := BonferroniBlocks.sum_intersectionValue_eq_choose P hit m + +theorem intersectionValue_eq_product {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {T : Finset ℕ} (hT : T ⊆ B.biUnion blocks) (hit : ℕ → Prop) : + BonferroniBlocks.intersectionValue T hit = + ∏ j ∈ B, BonferroniBlocks.intersectionValue (T ∩ blocks j) hit := by + classical + by_cases hhit : ∀ p ∈ T, hit p + · have hlocal : ∀ j ∈ B, BonferroniBlocks.intersectionValue (T ∩ blocks j) hit = 1 := by + intro j _ + apply ite_eq_left + intro p hp + exact hhit p (Finset.mem_inter.mp hp).1 + unfold BonferroniBlocks.intersectionValue + rw [ite_eq_left hhit] + symm + exact Finset.prod_eq_one hlocal + · have hbad : ∃ p ∈ T, ¬ hit p := by + simpa only [not_forall, Classical.not_imp, exists_prop] using hhit + obtain ⟨p, hp, hnot⟩ := hbad + obtain ⟨j, hj, hpj⟩ := Finset.mem_biUnion.mp (hT hp) + have hlocal : BonferroniBlocks.intersectionValue (T ∩ blocks j) hit = 0 := + ite_eq_right (fun h => hnot (h p (Finset.mem_inter.mpr ⟨hp, hpj⟩))) + rw [BonferroniBlocks.intersectionValue, ite_eq_right hhit] + symm + exact Finset.prod_eq_zero hj hlocal + +noncomputable def globalCoefficient (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (localCoeff : ℕ → Finset ℕ → ℝ) (T : Finset ℕ) : ℝ := + ∏ j ∈ B, localCoeff j (T ∩ blocks j) + +theorem globalCoefficient_evaluation (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (localCoeff : ℕ → Finset ℕ → ℝ) (hit : ℕ → Prop) : + (∑ T ∈ (B.biUnion blocks).powerset, + globalCoefficient B blocks localCoeff T * BonferroniBlocks.intersectionValue T hit) = + ∏ j ∈ B, ∑ T ∈ (blocks j).powerset, localCoeff j T * BonferroniBlocks.intersectionValue T hit := by + calc + _ = ∑ T ∈ (B.biUnion blocks).powerset, + ∏ j ∈ B, localCoeff j (T ∩ blocks j) * BonferroniBlocks.intersectionValue (T ∩ blocks j) hit := by + apply Finset.sum_congr rfl + intro T hT + rw [intersectionValue_eq_product (Finset.mem_powerset.mp hT), Finset.prod_mul_distrib] + rfl + _ = _ := sum_subsets_product B blocks hdis + (fun j T => localCoeff j T * BonferroniBlocks.intersectionValue T hit) + +noncomputable def upperCoefficient (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (T : Finset ℕ) : ℝ := + globalCoefficient B blocks (fun j => truncatedCoefficient (2 * orders j)) T + +noncomputable def correctionCoefficient (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (j : ℕ) (T : Finset ℕ) : ℝ := + globalCoefficient B blocks + (fun i => if i = j then layerCoefficient (2 * orders i + 1) + else truncatedCoefficient (2 * orders i)) T + +noncomputable def lowerCoefficient (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (T : Finset ℕ) : ℝ := + upperCoefficient B blocks orders T - ∑ j ∈ B, correctionCoefficient B blocks orders j T + +theorem upperCoefficient_evaluation (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders : ℕ → ℕ) (hit : ℕ → Prop) : + (∑ T ∈ (B.biUnion blocks).powerset, + upperCoefficient B blocks orders T * BonferroniBlocks.intersectionValue T hit) = + BonferroniBlocks.blockUpper B blocks orders hit := by + unfold upperCoefficient + rw [globalCoefficient_evaluation B blocks hdis] + simp_rw [truncatedCoefficient_evaluation] + rfl + +theorem correctionCoefficient_evaluation (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders : ℕ → ℕ) (hit : ℕ → Prop) (j : ℕ) (hj : j ∈ B) : + (∑ T ∈ (B.biUnion blocks).powerset, + correctionCoefficient B blocks orders j T * BonferroniBlocks.intersectionValue T hit) = + (BonferroniBlocks.coefficientPolynomial (2 * orders j) (blocks j) hit - + BonferroniBlocks.coefficientPolynomial (2 * orders j + 1) (blocks j) hit) * + ∏ i ∈ B.erase j, BonferroniBlocks.coefficientPolynomial (2 * orders i) (blocks i) hit := by + classical + unfold correctionCoefficient + rw [globalCoefficient_evaluation B blocks hdis] + rw [← Finset.mul_prod_erase B _ hj] + simp only [ite_true] + rw [layerCoefficient_evaluation, ← BonferroniBlocks.coefficientPolynomial_gap] + congr 1 + apply Finset.prod_congr rfl + intro i hi + have hij : i ≠ j := (Finset.mem_erase.mp hi).1 + simp only [ite_eq_right hij] + exact truncatedCoefficient_evaluation _ _ _ + +theorem lowerCoefficient_evaluation (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders : ℕ → ℕ) (hit : ℕ → Prop) : + (∑ T ∈ (B.biUnion blocks).powerset, + lowerCoefficient B blocks orders T * BonferroniBlocks.intersectionValue T hit) = + BonferroniBlocks.blockLower B blocks orders hit := by + unfold lowerCoefficient BonferroniBlocks.blockLower BonferroniBlocks.blockCorrection + simp_rw [sub_mul, Finset.sum_mul] + rw [Finset.sum_sub_distrib, Finset.sum_comm, + upperCoefficient_evaluation B blocks hdis] + congr 1 + apply Finset.sum_congr rfl + intro j hj + simpa only [sub_mul] using correctionCoefficient_evaluation B blocks hdis orders hit j hj + +@[simp] theorem truncatedCoefficient_ne_zero_iff (m : ℕ) (T : Finset ℕ) : + truncatedCoefficient m T ≠ 0 ↔ T.card ≤ m := by + unfold truncatedCoefficient + split_ifs <;> simp_all + +@[simp] theorem layerCoefficient_ne_zero_iff (m : ℕ) (T : Finset ℕ) : + layerCoefficient m T ≠ 0 ↔ T.card = m := by + unfold layerCoefficient + split_ifs <;> simp_all + +theorem truncatedCoefficient_abs_le (m : ℕ) (T : Finset ℕ) : + |truncatedCoefficient m T| ≤ 1 := by + unfold truncatedCoefficient + split_ifs <;> simp + +theorem layerCoefficient_abs_le (m : ℕ) (T : Finset ℕ) : + |layerCoefficient m T| ≤ 1 := by + unfold layerCoefficient + split_ifs <;> simp + +theorem globalCoefficient_abs_le (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (localCoeff : ℕ → Finset ℕ → ℝ) (T : Finset ℕ) + (hlocal : ∀ j ∈ B, |localCoeff j (T ∩ blocks j)| ≤ 1) : + |globalCoefficient B blocks localCoeff T| ≤ 1 := by + unfold globalCoefficient + rw [Finset.abs_prod] + exact Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) hlocal + +theorem upperCoefficient_abs_le (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (T : Finset ℕ) : |upperCoefficient B blocks orders T| ≤ 1 := + globalCoefficient_abs_le B blocks _ T (fun _ _ => truncatedCoefficient_abs_le _ _) + +theorem correctionCoefficient_abs_le (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (j : ℕ) (T : Finset ℕ) : |correctionCoefficient B blocks orders j T| ≤ 1 := by + apply globalCoefficient_abs_le + intro i _ + split_ifs + · exact layerCoefficient_abs_le _ _ + · exact truncatedCoefficient_abs_le _ _ + +theorem correctionCoefficient_own_card {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {orders : ℕ → ℕ} {j : ℕ} {T : Finset ℕ} (hj : j ∈ B) + (hc : correctionCoefficient B blocks orders j T ≠ 0) : + (T ∩ blocks j).card = 2 * orders j + 1 := by + have h := Finset.prod_ne_zero_iff.mp hc j hj + simpa only [ite_true, layerCoefficient_ne_zero_iff] using h + +theorem correctionCoefficient_other_card {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {orders : ℕ → ℕ} {i j : ℕ} {T : Finset ℕ} (hi : i ∈ B) (hij : i ≠ j) + (hc : correctionCoefficient B blocks orders j T ≠ 0) : + (T ∩ blocks i).card ≤ 2 * orders i := by + have h := Finset.prod_ne_zero_iff.mp hc i hi + simpa only [ite_eq_right hij, truncatedCoefficient_ne_zero_iff] using h + +theorem correctionCoefficient_disjoint {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {orders : ℕ → ℕ} {i j : ℕ} {T : Finset ℕ} (hi : i ∈ B) (_hj : j ∈ B) (hij : i ≠ j) + (hiC : correctionCoefficient B blocks orders i T ≠ 0) : + correctionCoefficient B blocks orders j T = 0 := by + by_contra hjC + have hown := correctionCoefficient_own_card hi hiC + have hother := correctionCoefficient_other_card hi hij hjC + omega + +theorem upperCoefficient_zero_of_correction {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {orders : ℕ → ℕ} {j : ℕ} {T : Finset ℕ} (hj : j ∈ B) + (hc : correctionCoefficient B blocks orders j T ≠ 0) : upperCoefficient B blocks orders T = 0 := by + have hcard := correctionCoefficient_own_card hj hc + apply Finset.prod_eq_zero hj + change (if (T ∩ blocks j).card ≤ 2 * orders j then (-1 : ℝ) ^ (T ∩ blocks j).card else 0) = 0 + rw [ite_eq_right (by omega)] + +theorem lowerCoefficient_abs_le (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (orders : ℕ → ℕ) (T : Finset ℕ) : |lowerCoefficient B blocks orders T| ≤ 1 := by + classical + by_cases hactive : ∃ j ∈ B, correctionCoefficient B blocks orders j T ≠ 0 + · obtain ⟨j, hj, hjC⟩ := hactive + have hsum : (∑ i ∈ B, correctionCoefficient B blocks orders i T) = + correctionCoefficient B blocks orders j T := by + apply Finset.sum_eq_single_of_mem j hj + intro i hi hij + exact correctionCoefficient_disjoint hj hi hij.symm hjC + rw [lowerCoefficient, upperCoefficient_zero_of_correction hj hjC, hsum, zero_sub, abs_neg] + exact correctionCoefficient_abs_le _ _ _ _ _ + · have hsum : (∑ j ∈ B, correctionCoefficient B blocks orders j T) = 0 := by + apply Finset.sum_eq_zero + intro j hj + by_contra hjC + exact hactive ⟨j, hj, hjC⟩ + rw [lowerCoefficient, hsum, sub_zero] + exact upperCoefficient_abs_le _ _ _ _ + +theorem prod_inter_blocks {M : Type*} [CommMonoid M] (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + {T : Finset ℕ} (hT : T ⊆ B.biUnion blocks) (g : ℕ → M) : + (∏ p ∈ T, g p) = ∏ j ∈ B, ∏ p ∈ T ∩ blocks j, g p := by + classical + have hparts : (B : Set ℕ).PairwiseDisjoint (fun j => T ∩ blocks j) := by + intro i hi j hj hij + exact (hdis hi hj hij).mono Finset.inter_subset_right Finset.inter_subset_right + have hUnion : B.biUnion (fun j => T ∩ blocks j) = T := by + rw [← Finset.inter_biUnion, Finset.inter_eq_left.mpr hT] + calc + (∏ p ∈ T, g p) = ∏ p ∈ B.biUnion (fun j => T ∩ blocks j), g p := by rw [hUnion] + _ = _ := Finset.prod_biUnion hparts + +theorem globalCoefficient_density (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (localCoeff : ℕ → Finset ℕ → ℝ) (g : ℕ → ℝ) : + (∑ T ∈ (B.biUnion blocks).powerset, globalCoefficient B blocks localCoeff T * ∏ p ∈ T, g p) = + ∏ j ∈ B, ∑ T ∈ (blocks j).powerset, localCoeff j T * ∏ p ∈ T, g p := by + calc + _ = ∑ T ∈ (B.biUnion blocks).powerset, + ∏ j ∈ B, localCoeff j (T ∩ blocks j) * ∏ p ∈ T ∩ blocks j, g p := by + apply Finset.sum_congr rfl + intro T hT + rw [prod_inter_blocks B blocks hdis (Finset.mem_powerset.mp hT), Finset.prod_mul_distrib] + rfl + _ = _ := sum_subsets_product B blocks hdis (fun j T => localCoeff j T * ∏ p ∈ T, g p) + +theorem upperCoefficient_density (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders : ℕ → ℕ) (g : ℕ → ℝ) : + (∑ T ∈ (B.biUnion blocks).powerset, upperCoefficient B blocks orders T * ∏ p ∈ T, g p) = + ∏ j ∈ B, BonferroniDensity.densityPolynomial (2 * orders j) (blocks j) g := by + unfold upperCoefficient + rw [globalCoefficient_density B blocks hdis] + simp_rw [truncatedCoefficient_sum, ← BonferroniDensity.densityPolynomial_eq_momentPolynomial] + +theorem weighted_coefficient_expansion {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (Q : Finset ℕ) (coeff : Finset ℕ → ℝ) : + (∑ T ∈ Q.powerset, coeff T * BonferroniBlocks.intersectionMass C weight hit T) = + ∑ x ∈ C, weight x * ∑ T ∈ Q.powerset, coeff T * BonferroniBlocks.intersectionValue T (fun p => hit p x) := by + unfold BonferroniBlocks.intersectionMass + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro T _ + ring + +theorem global_main_remainder {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (Q : Finset ℕ) (coeff : Finset ℕ → ℝ) (X : ℝ) (g : ℕ → ℝ) : + (∑ T ∈ Q.powerset, coeff T * BonferroniBlocks.intersectionMass C weight hit T) = + X * (∑ T ∈ Q.powerset, coeff T * ∏ p ∈ T, g p) + + ∑ T ∈ Q.powerset, coeff T * BonferroniBlocks.intersectionRemainder C weight hit X g T := by + unfold BonferroniBlocks.intersectionRemainder + rw [Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro T _ + ring + +theorem supported_remainder_bound (Q : Finset ℕ) (coeff E : Finset ℕ → ℝ) + (hc : ∀ T ∈ Q.powerset, |coeff T| ≤ 1) : + |∑ T ∈ Q.powerset, coeff T * E T| ≤ + ∑ T ∈ Q.powerset.filter (fun T => coeff T ≠ 0), |E T| := by + classical + have hreindex : (∑ T ∈ Q.powerset, coeff T * E T) = + ∑ T ∈ Q.powerset.filter (fun T => coeff T ≠ 0), coeff T * E T := by + symm + apply Finset.sum_subset (Finset.filter_subset _ _) + intro T hT hnot + have hz : coeff T = 0 := by + by_contra hnz + exact hnot (Finset.mem_filter.mpr ⟨hT, hnz⟩) + rw [hz, zero_mul] + rw [hreindex] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro T hT + rw [abs_mul] + simpa only [one_mul] using mul_le_mul_of_nonneg_right (hc T (Finset.mem_filter.mp hT).1) (abs_nonneg _) + +theorem weighted_global_coefficient_bounds {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (hit : ℕ → α → Prop) + (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders : ℕ → ℕ) : + (∑ T ∈ (B.biUnion blocks).powerset, + lowerCoefficient B blocks orders T * BonferroniBlocks.intersectionMass C weight hit T) ≤ + (∑ x ∈ C, weight x * BonferroniBlocks.survives (B.biUnion blocks) (fun p => hit p x)) ∧ + (∑ x ∈ C, weight x * BonferroniBlocks.survives (B.biUnion blocks) (fun p => hit p x)) ≤ + ∑ T ∈ (B.biUnion blocks).powerset, + upperCoefficient B blocks orders T * BonferroniBlocks.intersectionMass C weight hit T := by + rw [weighted_coefficient_expansion, weighted_coefficient_expansion] + simp_rw [lowerCoefficient_evaluation B blocks hdis, upperCoefficient_evaluation B blocks hdis] + exact BonferroniBlocks.weighted_block_bounds C weight hweight B blocks orders hit + +theorem layerCoefficient_density (m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) : + (∑ T ∈ P.powerset, layerCoefficient m T * ∏ p ∈ T, g p) = + BonferroniDensity.elementarySum P g m := by + classical + unfold BonferroniDensity.elementarySum + rw [Finset.powersetCard_eq_filter, Finset.sum_filter] + apply Finset.sum_congr rfl + intro T _ + unfold layerCoefficient + split_ifs <;> simp + +theorem correctionCoefficient_density (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders : ℕ → ℕ) (g : ℕ → ℝ) (j : ℕ) (hj : j ∈ B) : + (∑ T ∈ (B.biUnion blocks).powerset, correctionCoefficient B blocks orders j T * ∏ p ∈ T, g p) = + BonferroniDensity.elementarySum (blocks j) g (2 * orders j + 1) * + ∏ i ∈ B.erase j, BonferroniDensity.densityPolynomial (2 * orders i) (blocks i) g := by + classical + unfold correctionCoefficient + rw [globalCoefficient_density B blocks hdis, ← Finset.mul_prod_erase B _ hj] + simp only [ite_true] + rw [layerCoefficient_density] + congr 1 + apply Finset.prod_congr rfl + intro i hi + have hij : i ≠ j := (Finset.mem_erase.mp hi).1 + simp only [ite_eq_right hij] + rw [truncatedCoefficient_sum] + rfl + +theorem lowerCoefficient_density (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders : ℕ → ℕ) (g : ℕ → ℝ) : + (∑ T ∈ (B.biUnion blocks).powerset, lowerCoefficient B blocks orders T * ∏ p ∈ T, g p) = + (∏ j ∈ B, BonferroniDensity.densityPolynomial (2 * orders j) (blocks j) g) - + ∑ j ∈ B, BonferroniDensity.elementarySum (blocks j) g (2 * orders j + 1) * + ∏ i ∈ B.erase j, BonferroniDensity.densityPolynomial (2 * orders i) (blocks i) g := by + unfold lowerCoefficient + simp_rw [sub_mul, Finset.sum_mul] + rw [Finset.sum_sub_distrib, Finset.sum_comm, upperCoefficient_density B blocks hdis] + congr 1 + apply Finset.sum_congr rfl + intro j hj + exact correctionCoefficient_density B blocks hdis orders g j hj + +theorem upperCoefficient_card {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {orders : ℕ → ℕ} {T : Finset ℕ} + (hc : upperCoefficient B blocks orders T ≠ 0) (j : ℕ) (hj : j ∈ B) : + (T ∩ blocks j).card ≤ 2 * orders j := by + exact (truncatedCoefficient_ne_zero_iff _ _).mp (Finset.prod_ne_zero_iff.mp hc j hj) + +theorem lowerCoefficient_card {B : Finset ℕ} {blocks : ℕ → Finset ℕ} + {orders : ℕ → ℕ} {T : Finset ℕ} + (hc : lowerCoefficient B blocks orders T ≠ 0) (j : ℕ) (hj : j ∈ B) : + (T ∩ blocks j).card ≤ 2 * orders j + 1 := by + classical + by_cases hu : upperCoefficient B blocks orders T = 0 + · have hex : ∃ i ∈ B, correctionCoefficient B blocks orders i T ≠ 0 := by + by_contra hnone + have hsum : (∑ i ∈ B, correctionCoefficient B blocks orders i T) = 0 := by + apply Finset.sum_eq_zero + intro i hi + by_contra hiC + exact hnone ⟨i, hi, hiC⟩ + apply hc + rw [lowerCoefficient, hu, hsum, sub_self] + obtain ⟨i, hi, hiC⟩ := hex + by_cases hji : j = i + · subst j + exact le_of_eq (correctionCoefficient_own_card hi hiC) + · exact (correctionCoefficient_other_card hj hji hiC).trans (Nat.le_succ _) + · exact (upperCoefficient_card hu j hj).trans (Nat.le_succ _) + +theorem prime_product_support (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (budget height : ℕ → ℕ) (hheight : ∀ j ∈ B, 1 ≤ height j) + (hprime : ∀ j ∈ B, ∀ p ∈ blocks j, p.Prime) + (hsize : ∀ j ∈ B, ∀ p ∈ blocks j, p ≤ height j) + {T : Finset ℕ} (hT : T ⊆ B.biUnion blocks) + (hcard : ∀ j ∈ B, (T ∩ blocks j).card ≤ budget j) : + Squarefree (∏ p ∈ T, p) ∧ (∏ p ∈ T, p) ≤ ∏ j ∈ B, height j ^ budget j := by + constructor + · apply IntervalBoundingSieve.squarefree_primeSet_product + intro p hp + obtain ⟨j, hj, hpj⟩ := Finset.mem_biUnion.mp (hT hp) + exact hprime j hj p hpj + · have hprod : (∏ p ∈ T, p) = ∏ j ∈ B, ∏ p ∈ T ∩ blocks j, p := by + simpa only [id_eq] using prod_inter_blocks B blocks hdis hT id + rw [hprod] + apply Finset.prod_le_prod + intro j hj + exact (BonferroniBlocks.coefficient_divisor_support (blocks j) (hheight j hj) + (hprime j hj) (hsize j hj) (hcard j hj) + (Finset.mem_powersetCard.mpr ⟨Finset.inter_subset_right, rfl⟩)).2 + +theorem lowerCoefficient_prime_support (B : Finset ℕ) (blocks : ℕ → Finset ℕ) + (hdis : (B : Set ℕ).Pairwise fun i j => Disjoint (blocks i) (blocks j)) + (orders height : ℕ → ℕ) (hheight : ∀ j ∈ B, 1 ≤ height j) + (hprime : ∀ j ∈ B, ∀ p ∈ blocks j, p.Prime) + (hsize : ∀ j ∈ B, ∀ p ∈ blocks j, p ≤ height j) + {T : Finset ℕ} (hT : T ⊆ B.biUnion blocks) (hc : lowerCoefficient B blocks orders T ≠ 0) : + Squarefree (∏ p ∈ T, p) ∧ (∏ p ∈ T, p) ≤ ∏ j ∈ B, height j ^ (2 * orders j + 1) := + prime_product_support B blocks hdis (fun j => 2 * orders j + 1) height hheight hprime hsize hT + (lowerCoefficient_card hc) + +theorem prime_product_injective (Q : Finset ℕ) (hprime : ∀ p ∈ Q, p.Prime) : + Set.InjOn (fun T : Finset ℕ => ∏ p ∈ T, p) (Q.powerset : Set (Finset ℕ)) := by + intro T hT U hU heq + have hTprod : (∏ p ∈ T, p).primeFactors = T := + Nat.primeFactors_prod (fun p hp => hprime p (Finset.mem_powerset.mp hT hp)) + have hUprod : (∏ p ∈ U, p).primeFactors = U := + Nat.primeFactors_prod (fun p hp => hprime p (Finset.mem_powerset.mp hU hp)) + change (∏ p ∈ T, p) = (∏ p ∈ U, p) at heq + rw [← hTprod, ← hUprod, heq] + +end NumberTheoryLean.DisjointBlockExpansion + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/DivisibleInflection.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/DivisibleInflection.lean new file mode 100644 index 0000000000000000000000000000000000000000..1fb2bff8927cf726f28fe3a18b122d12bf51c492 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/DivisibleInflection.lean @@ -0,0 +1,144 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.PolynomialLocalGraph +import OAI.NumberTheory.Jacobsthal.Partitions.InflectionTransport +import OAI.NumberTheory.Jacobsthal.Paths.AffineBranch + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosDivisibleInflection + +open ErdosCriticalGeometry ErdosImplicitCurvature + +noncomputable def swapVars (R : Type*) [CommSemiring R] : MV R ≃ₐ[R] MV R := + MvPolynomial.renameEquiv R (Equiv.swap (0 : Fin 2) 1) + +theorem swap_twice (R : Type*) [CommSemiring R] (Q : MV R) : + swapVars R (swapVars R Q) = Q := by + simpa [swapVars] using (MvPolynomial.renameEquiv R (Equiv.swap (0 : Fin 2) 1)).apply_symm_apply Q + +theorem nestedX_swap (R : Type*) [CommSemiring R] (Q : MV R) : + nestedX R (swapVars R Q) = nestedY R Q := rfl + +theorem nestedY_swap (R : Type*) [CommSemiring R] (Q : MV R) : + nestedY R (swapVars R Q) = nestedX R Q := by + change nestedX R (swapVars R (swapVars R Q)) = _ + rw [swap_twice] + +theorem partial_zero_swap (R : Type*) [CommSemiring R] (Q : MV R) : + MvPolynomial.pderiv 0 (swapVars R Q) = swapVars R (MvPolynomial.pderiv 1 Q) := by + apply (nestedX R).injective + rw [nestedX_partial_zero,nestedX_swap,nestedX_swap,nestedY_partial_one] + +theorem partial_one_swap (R : Type*) [CommSemiring R] (Q : MV R) : + MvPolynomial.pderiv 1 (swapVars R Q) = swapVars R (MvPolynomial.pderiv 0 Q) := by + apply (nestedY R).injective + rw [nestedY_partial_one,nestedY_swap,nestedY_swap,nestedX_partial_zero] + +theorem eval_swap (R : Type*) [CommSemiring R] (Q : MV R) (x y : R) : + MvPolynomial.eval ![x,y] (swapVars R Q) = MvPolynomial.eval ![y,x] Q := by + have h1 := eval_nestedX R (swapVars R Q) x y + rw [nestedX_swap] at h1 + exact h1.symm.trans (eval_nestedY R Q y x) + +theorem peval_swap (Q : MV ℝ) (x y : ℝ) : peval (swapVars ℝ Q) x y = peval Q y x := by + rw [peval_eq_eval_pair,peval_eq_eval_pair,eval_swap] + +theorem complexify_swap (Q : MV ℝ) : complexify (swapVars ℝ Q) = swapVars ℂ (complexify Q) := by + simp only [complexify,swapVars,MvPolynomial.renameEquiv_apply,MvPolynomial.map_rename] + +theorem mixed_partials_complex (Q : MV ℂ) : + MvPolynomial.pderiv 1 (MvPolynomial.pderiv 0 Q) = + MvPolynomial.pderiv 0 (MvPolynomial.pderiv 1 Q) := by + classical + ext m + simp [MvPolynomial.coeff_pderiv,add_assoc,add_left_comm,add_comm,mul_left_comm,mul_comm] + +theorem inflection_swap (Q : MV ℂ) : inflection (swapVars ℂ Q) = swapVars ℂ (inflection Q) := by + unfold inflection + simp only [partial_zero_swap,partial_one_swap,mixed_partials_complex,map_add,map_mul,map_pow] + have hC : swapVars ℂ (MvPolynomial.C (-2 : ℂ)) = MvPolynomial.C (-2 : ℂ) := by simp [swapVars] + rw [hC] + ring + +theorem complex_divisibility_swap (Q : MV ℝ) + (hdiv : complexify Q ∣ inflection (complexify Q)) : + complexify (swapVars ℝ Q) ∣ inflection (complexify (swapVars ℝ Q)) := by + rw [complexify_swap,inflection_swap] + exact map_dvd (swapVars ℂ).toRingHom hdiv + +end ErdosDivisibleInflection + +end + +section + +namespace ErdosDivisibleInflection + +open ErdosCriticalGeometry ErdosImplicitCurvature + +theorem no_regular_y_point (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) (hdiv : complexify Q ∣ inflection (complexify Q)) + (x y : ℝ) (hzero : peval Q x y = 0) (hy : peval (partialY Q) x y ≠ 0) : False := by + obtain ⟨a,b,f,hax,hxb,hfx,hf,hcurve,hfy⟩ := exists_local_real_graph Q x y hzero hy + have hsecond := zero_second_derivative_on_divisible_graph Q f a b hdiv hf hcurve hfy + obtain ⟨A,B,haffine⟩ := affine_of_second_derivative_zero f a b x ⟨hax,hxb⟩ hf hsecond + have hdegC : 1 < (complexify Q).totalDegree := by rwa [complexify_totalDegree] + apply no_affine_interval (complexify Q) hQ hdegC (A : ℂ) (B : ℂ) a b (hax.trans hxb) + intro t ht + have hz := hcurve t ht + rw [haffine t ht] at hz + have hc := complexify_eval Q t (A*t+B) + rw [← peval_eq_eval_pair,hz] at hc + simpa only [Complex.ofReal_mul,Complex.ofReal_add,Complex.ofReal_zero] using hc + +theorem no_regular_x_point (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) (hdiv : complexify Q ∣ inflection (complexify Q)) + (x y : ℝ) (hzero : peval Q x y = 0) (hx : peval (partialX Q) x y ≠ 0) : False := by + have hirr : Irreducible (complexify (swapVars ℝ Q)) := by + rw [complexify_swap] + exact (MulEquiv.irreducible_iff (swapVars ℂ).toMulEquiv).mpr hQ + have hd : 1 < (swapVars ℝ Q).totalDegree := by + simpa only [swapVars,MvPolynomial.totalDegree_renameEquiv] using hdeg + have hz : peval (swapVars ℝ Q) y x = 0 := by rw [peval_swap]; exact hzero + have hpart : peval (partialY (swapVars ℝ Q)) y x ≠ 0 := by + change peval (MvPolynomial.pderiv 1 (swapVars ℝ Q)) y x ≠ 0 + rw [partial_one_swap,peval_swap] + exact hx + exact no_regular_y_point (swapVars ℝ Q) hirr hd (complex_divisibility_swap Q hdiv) y x hz hpart + +theorem no_real_regular_point_of_divisible_inflection (Q : MV ℝ) + (hQ : Irreducible (complexify Q)) (hdeg : 1 < Q.totalDegree) + (hdiv : complexify Q ∣ inflection (complexify Q)) (x y : ℝ) + (hzero : peval Q x y = 0) + (hregular : peval (partialX Q) x y ≠ 0 ∨ peval (partialY Q) x y ≠ 0) : False := by + rcases hregular with hx | hy + · exact no_regular_x_point Q hQ hdeg hdiv x y hzero hx + · exact no_regular_y_point Q hQ hdeg hdiv x y hzero hy + +theorem divisible_inflection_gradient_zero (Q : MV ℝ) + (hQ : Irreducible (complexify Q)) (hdeg : 1 < Q.totalDegree) + (hdiv : complexify Q ∣ inflection (complexify Q)) (x y : ℝ) + (hzero : peval Q x y = 0) : + peval (partialX Q) x y = 0 ∧ peval (partialY Q) x y = 0 := by + constructor + · by_contra hx + exact no_regular_x_point Q hQ hdeg hdiv x y hzero hx + · by_contra hy + exact no_regular_y_point Q hQ hdeg hdiv x y hzero hy + +theorem real_divisible_inflection_gradient_zero (Q : MV ℝ) + (hQ : Irreducible (complexify Q)) (hdeg : 1 < Q.totalDegree) + (hdiv : Q ∣ inflectionPolynomial Q) (x y : ℝ) (hzero : peval Q x y = 0) : + peval (partialX Q) x y = 0 ∧ peval (partialY Q) x y = 0 := + divisible_inflection_gradient_zero Q hQ hdeg (real_divisibility_to_complex Q hdiv) x y hzero + +end ErdosDivisibleInflection + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveAvoidance.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveAvoidance.lean new file mode 100644 index 0000000000000000000000000000000000000000..06f786719dfb1570d18e829d8c497766c01b42c9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveAvoidance.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.EffectiveCoordinateUnits + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosInverseCells + +noncomputable def effectiveInteger (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) [NeZero p] + (hHp : (effectiveModulus a r qf).Coprime p) (j : ℤ) : ℤ := + (cofactorHit qf a : ℤ)+(qf : ℤ)* + ((intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ℤ)+(p : ℤ)*j) + +theorem effectiveInteger_nat_coordinate (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) [NeZero p] + (hHp : (effectiveModulus a r qf).Coprime p) (j : ℕ) : + ((effectiveBase a r qf p hHp+p*qf*j : ℕ) : ℤ) = effectiveInteger a r qf p hHp (j : ℤ) := by + simp only [effectiveBase,effectiveInteger,Nat.cast_add,Nat.cast_mul] + ring + +theorem effective_avoidance_not_dvd (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) + (t : ℕ) (ht : t.Prime) (htH : ¬t ∣ effectiveModulus a r qf) (j : ℤ) : + (effectiveInteger a r qf p hHp j : ZMod t) ≠ (a t : ZMod t) ↔ + (p : ZMod t)*(alignedCofactor (fun u => (a u : ℤ)) r qf : ZMod t)* + ((intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ZMod t)+ + (effectiveModulus a r qf : ZMod t)*(j : ZMod t)) ≠ + (r.den : ZMod t)*(a t : ZMod t)-(r.num : ZMod t) := by + let : Fact t.Prime := ⟨ht⟩ + have hDH := effective_den_coprime_prime a r qf t (ht.coprime_iff_not_dvd.mpr htH).symm + have hD0 : (r.den : ZMod t) ≠ 0 := by + intro he + exact (ht.coprime_iff_not_dvd.mp hDH.symm) ((ZMod.natCast_eq_zero_iff _ _).mp he) + have hid : (r.den : ZMod t)*(effectiveInteger a r qf p hHp j : ZMod t) = + (r.num : ZMod t)+(p : ZMod t)*(alignedCofactor (fun u => (a u : ℤ)) r qf : ZMod t)* + ((intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ZMod t)+ + (effectiveModulus a r qf : ZMod t)*(j : ZMod t)) := by + have he := congrArg (fun z : ℤ => (z : ZMod t)) (effective_progression_identity a r qf hq p hHp j) + simpa only [effectiveInteger,Int.cast_add,Int.cast_mul,Int.cast_natCast,mul_comm (p : ZMod t)] using he + apply not_congr + constructor + · intro he + rw [he] at hid + linear_combination -hid + · intro he + apply mul_left_cancel₀ hD0 + linear_combination hid+he + +theorem effective_avoidance_unit (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) [NeZero p] + (hHp : (effectiveModulus a r qf).Coprime p) (t : ℕ) (hqt : qf.Coprime t) (j : ℤ) : + (effectiveInteger a r qf p hHp j : ZMod t) ≠ (a t : ZMod t) ↔ + ((intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ℕ) : ZMod t)+ + (p : ZMod t)*(j : ZMod t) ≠ + ((a t : ZMod t)-(cofactorHit qf a : ZMod t))*(↑((ZMod.unitOfCoprime qf hqt)⁻¹) : ZMod t) := by + let v := ZMod.unitOfCoprime qf hqt + have hu : (qf : ZMod t)*(↑(v⁻¹) : ZMod t) = 1 := by + simpa only [v,ZMod.coe_unitOfCoprime] using v.mul_inv + simp only [effectiveInteger,Int.cast_add,Int.cast_mul,Int.cast_natCast] + apply not_congr + constructor + · intro he + have hh := congrArg (fun x : ZMod t => x*(↑(v⁻¹) : ZMod t)) he + linear_combination hh- + ((intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ZMod t)+(p : ZMod t)*(j : ZMod t))*hu + · intro he + have hh := congrArg (fun x : ZMod t => (qf : ZMod t)*x) he + linear_combination hh+((a t : ZMod t)-(cofactorHit qf a : ZMod t))*hu + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveNumerator.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveNumerator.lean new file mode 100644 index 0000000000000000000000000000000000000000..89cc709714088f50926f14bace3a8511eb3181ca --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveNumerator.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.AlignedCofactorSplit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosInverseAlignment ErdosPrimitiveIntercept ErdosInverseCells +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def hitNumerator (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) : ℤ := + (r.den : ℤ)*(cofactorHit qf a : ℤ)-r.num + +theorem prime_dvd_hitNumerator_iff (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) (hp : p ∈ qf.primeFactors) : + (p : ℤ) ∣ hitNumerator a r qf ↔ aligns (fun t => (a t : ℤ)) r p := by + have hclass : (cofactorHit qf a : ZMod p) = (a p : ZMod p) := + (ZMod.natCast_eq_natCast_iff _ _ _).mpr ((cofactorHit_spec qf hq a).2.2 p hp) + rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] + simp only [hitNumerator,Int.cast_sub,Int.cast_mul,Int.cast_natCast,hclass,sub_eq_zero,aligns] + +theorem alignedCofactor_dvd_hitNumerator (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ) ∣ hitNumerator a r qf := by + apply Int.natCast_dvd.mpr + rw [alignedCofactor_eq_product _ r qf hq] + apply Finset.prod_primes_dvd + · intro p hp + exact (Nat.prime_of_mem_primeFactors (Finset.mem_filter.mp hp).1).prime + · intro p hp + obtain ⟨hpf,halign⟩ := Finset.mem_filter.mp hp + exact Int.natCast_dvd.mp ((prime_dvd_hitNumerator_iff a r qf hq p hpf).mpr halign) + +theorem hitNumerator_coprime_den (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) : + (hitNumerator a r qf).natAbs.Coprime r.den := by + apply Nat.coprime_of_dvd + intro p hp hpN hpD + have hD0 : (r.den : ZMod p) = 0 := (ZMod.natCast_eq_zero_iff _ _).mpr hpD + have hN0 := (ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mpr (Int.natCast_dvd.mpr hpN) + have hA0 : (r.num : ZMod p) = 0 := by + simpa only [hitNumerator,Int.cast_sub,Int.cast_mul,Int.cast_natCast,hD0,zero_mul,zero_sub,neg_eq_zero] + using hN0 + have hpA : p ∣ r.num.natAbs := Int.natCast_dvd.mp ((ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp hA0) + have hdiv := Nat.dvd_gcd hpA hpD + rw [r.reduced.gcd_eq_one] at hdiv + exact hp.not_dvd_one hdiv + +theorem hitNumerator_coprime_bad (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (hitNumerator a r qf).natAbs.Coprime (badPrimeProduct (fun t => (a t : ℤ)) r qf) := by + apply Nat.coprime_prod_right_iff.mpr + intro p hp + obtain ⟨hpf,hnon⟩ := Finset.mem_filter.mp hp + apply Nat.Coprime.symm + apply (Nat.prime_of_mem_primeFactors hpf).coprime_iff_not_dvd.mpr + intro hdiv + exact hnon ((prime_dvd_hitNumerator_iff a r qf hq p hpf).mp (Int.natCast_dvd.mpr hdiv)) + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveProgression.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveProgression.lean new file mode 100644 index 0000000000000000000000000000000000000000..6160058ff2f6ab2396cde0748bf47e92bb218809 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveProgression.lean @@ -0,0 +1,97 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ActualCoordinateBlocks +import OAI.NumberTheory.Jacobsthal.Partitions.EffectiveCoordinates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosInverseCells ErdosInverseHits ErdosHypotheticalTag ErdosAlignedProgression + +theorem effective_den_coprime_prime (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) + (hHp : (effectiveModulus a r qf).Coprime p) : r.den.Coprime p := + hHp.of_dvd_left (dvd_mul_right _ _) + +theorem effective_initial_identity (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : + (r.den : ℤ)*((cofactorHit qf a : ℤ)+(qf : ℤ)* + (intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ℤ)) = + r.num+(alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ)*(p : ℤ)* + intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) := by + have hN := effectiveIntercept_identity a r qf hq + unfold hitNumerator at hN + have hD : (r.den : ℤ)*(qf : ℤ) = + (alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ)*(effectiveModulus a r qf : ℤ) := by + exact_mod_cast denominator_full_cofactor a r qf hq + have hm := intervalM0_identity p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) + linear_combination -hN+ + (intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ℤ)*hD- + (alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ)*hm + +theorem effective_progression_identity (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) (j : ℤ) : + (r.den : ℤ)*((cofactorHit qf a : ℤ)+(qf : ℤ)* + ((intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) : ℤ)+(p : ℤ)*j)) = + r.num+(alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ)*(p : ℤ)* + (intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf)+ + (effectiveModulus a r qf : ℤ)*j) := by + have hb := effective_initial_identity a r qf hq p hHp + have hD : (r.den : ℤ)*(qf : ℤ) = + (alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ)*(effectiveModulus a r qf : ℤ) := by + exact_mod_cast denominator_full_cofactor a r qf hq + linear_combination hb+(p : ℤ)*j*hD + +theorem effective_initial_bounds (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : + 1 ≤ cofactorHit qf a+qf*intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) ∧ + cofactorHit qf a+qf*intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) ≤ p*qf := by + have hb := cofactorHit_spec qf hq a + have hk := intervalK_lt p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) + constructor + · omega + · nlinarith [hb.2.1] + +theorem effective_initial_hypothetical_hit (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hp : p.Prime) (hHp : (effectiveModulus a r qf).Coprime p) : + Nat.ModEq p + (cofactorHit qf a+qf*intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf)) + (hypotheticalClass a r p p) := by + apply (aligned_prime_hit_iff (hypotheticalClass a r p) r p _ hp + (hypothetical_aligns a r p hp (effective_den_coprime_prime a r qf p hHp))).mpr + have he := effective_initial_identity a r qf hq p hHp + simp only [Nat.cast_add,Nat.cast_mul] + rw [he] + change (r.num+(alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ)*(p : ℤ)* + intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf))%(p : ℤ) = r.num%(p : ℤ) + simp [Int.add_emod,Int.mul_emod] + +theorem effective_k_eq_parentSlope (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hp : p.Prime) (hqp : qf.Coprime p) + (hHp : (effectiveModulus a r qf).Coprime p) : + intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) = + parentSlope p qf hqp (hypotheticalClass a r p p) (cofactorHit qf a) := by + let : Fact p.Prime := ⟨hp⟩ + have hq0 : (qf : ZMod p) ≠ 0 := by + intro he + exact (hp.coprime_iff_not_dvd.mp hqp.symm) ((ZMod.natCast_eq_zero_iff _ _).mp he) + have he := (effective_initial_hypothetical_hit a r qf hq p hp hHp).trans + (parent_start_mod_p p qf hqp (hypotheticalClass a r p p) (cofactorHit qf a)).symm + have heZ := (ZMod.natCast_eq_natCast_iff _ _ _).mpr he + simp only [Nat.cast_add,Nat.cast_mul] at heZ + have hkZ := mul_left_cancel₀ hq0 (add_left_cancel heZ) + have hk := (ZMod.natCast_eq_natCast_iff _ _ _).mp hkZ + change _%p = _%p at hk + rw [Nat.mod_eq_of_lt (intervalK_lt p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf)), + Nat.mod_eq_of_lt (parentSlope_lt p qf hqp (hypotheticalClass a r p p) (cofactorHit qf a))] at hk + exact hk + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveSurvivors.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveSurvivors.lean new file mode 100644 index 0000000000000000000000000000000000000000..1bb077329b58ea2855403772aa4ae4d915913c77 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EffectiveSurvivors.lean @@ -0,0 +1,88 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.HypotheticalCofactorHit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosInverseCells ErdosInverseHits ErdosHypotheticalTag ErdosInverseCounts ErdosInverseAlignment +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def effectiveBase (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) [NeZero p] + (hHp : (effectiveModulus a r qf).Coprime p) : ℕ := + cofactorHit qf a+qf*intervalK p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) + +noncomputable def effectiveSurvivors (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (r : ℚ) + (qf p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : Finset ℕ := + (Finset.range (hitLength Y (p*qf) (effectiveBase a r qf p hHp))).filter + (fun j => ∀ t ∈ small,(effectiveBase a r qf p hHp+p*qf*j)%t ≠ a t%t) + +theorem effectiveBase_eq_sourceParentBase (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hp : p.Prime) (hqp : qf.Coprime p) + (hHp : (effectiveModulus a r qf).Coprime p) : + effectiveBase a r qf p hHp = sourceParentBase p qf hqp hq (hypotheticalClass a r p) := by + unfold sourceParentBase + rw [← cofactorHit_eq qf hq (hypotheticalClass a r p),cofactorHit_hypothetical a r qf p hq hqp, + ← effective_k_eq_parentSlope a r qf hq p hp hqp hHp] + rfl + +theorem effectiveSurvivors_eq_parent (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (r : ℚ) + (qf : ℕ) (hq : Squarefree qf) (p : ℕ) [NeZero p] (hp : p.Prime) + (hqp : qf.Coprime p) (hHp : (effectiveModulus a r qf).Coprime p) (hps : p ∉ small) : + effectiveSurvivors Y small a r qf p hHp = + parentSurvivorCoordinates Y small (hypotheticalClass a r p) p qf hqp hq := by + unfold effectiveSurvivors parentSurvivorCoordinates + rw [effectiveBase_eq_sourceParentBase a r qf hq p hp hqp hHp] + ext j + simp only [Finset.mem_filter,Finset.mem_range] + apply and_congr_right + intro _hj + apply forall_congr' + intro t + apply forall_congr' + intro ht + rw [hypothetical_other a r p t (by intro he;subst t;exact hps ht)] + +theorem hypothetical_candidates_eq_effective_image (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (r : ℚ) + (qf : ℕ) (hq : Squarefree qf) (p : ℕ) [NeZero p] (hp : p.Prime) + (hqp : qf.Coprime p) (hHp : (effectiveModulus a r qf).Coprime p) (hps : p ∉ small) : + modulusCandidates Y small (hypotheticalClass a r p) (p*qf) = + (effectiveSurvivors Y small a r qf p hHp).image (fun j => effectiveBase a r qf p hHp+p*qf*j) := by + rw [modulusCandidates_eq_parent_image Y small (hypotheticalClass a r p) p qf hp hqp hq, + effectiveSurvivors_eq_parent Y small a r qf hq p hp hqp hHp hps, + effectiveBase_eq_sourceParentBase a r qf hq p hp hqp hHp] + +theorem hypothetical_count_eq_effective_card (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (r : ℚ) + (qf : ℕ) (hq : Squarefree qf) (p : ℕ) [NeZero p] (hp : p.Prime) + (hqp : qf.Coprime p) (hHp : (effectiveModulus a r qf).Coprime p) (hps : p ∉ small) : + modulusCount Y small (hypotheticalClass a r p) (p*qf) = + ((effectiveSurvivors Y small a r qf p hHp).card : ℤ) := by + rw [modulusCount_eq_parent_card Y small (hypotheticalClass a r p) p qf hp hqp hq, + effectiveSurvivors_eq_parent Y small a r qf hq p hp hqp hHp hps] + +theorem actual_aligned_count_eq_effective_card (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (r : ℚ) + (qf : ℕ) (hq : Squarefree qf) (p : ℕ) [NeZero p] (hp : p.Prime) + (hqp : qf.Coprime p) (hHp : (effectiveModulus a r qf).Coprime p) (hps : p ∉ small) + (halign : aligns (fun t => (a t : ℤ)) r p) : + modulusCount Y small a (p*qf) = ((effectiveSurvivors Y small a r qf p hHp).card : ℤ) := by + rw [← hypothetical_count_agrees Y small a r (p*qf) p hp halign] + exact hypothetical_count_eq_effective_card Y small a r qf hq p hp hqp hHp hps + +theorem effective_length_error (Y : ℕ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : + |(hitLength Y (p*qf) (effectiveBase a r qf p hHp) : ℝ)-(Y : ℝ)/((p : ℝ)*qf)| ≤ 1 := by + have hb := effective_initial_bounds a r qf hq p hHp + simpa only [Nat.cast_mul] using hitLength_error Y (p*qf) (effectiveBase a r qf p hHp) + (Nat.mul_pos (Nat.pos_of_ne_zero (NeZero.ne p)) (Nat.pos_of_ne_zero hq.ne_zero)) hb.1 hb.2 + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/EndpointSoftConclusion.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EndpointSoftConclusion.lean new file mode 100644 index 0000000000000000000000000000000000000000..901263f1678db3cc7a3bcb14d446e53b6c52c0e8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EndpointSoftConclusion.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.GeometricSelectionHardMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEligible +open NumberTheoryLean ErdosVarianceWeighted ErdosVarianceEffective ErdosVarianceSmallPrime ErdosInverseBoxHeight +attribute [local instance] Classical.propDecidable + +theorem soft_of_not_guarded_hard (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) + (Cs eps : ℝ) (hr : r ∈ Q) + (hH : (effectiveModulus a r qf : ℝ) ≤ R*(sourceZ z)^11) + (hRatio : effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ (sourceZ z)^12) + (hbad : p ∈ badAligningPrimes (ErdosInversePrimeBin.primeBin R theta) (sourceY z) (sourceW z) a r qf eps) + (hout : p ∉ rawHardPrimeUnion Q z R theta a qf Cs eps) : + effectiveSize a r qf R < (sourceW z)^Cs := by + by_contra! hhard + apply hout + exact (mem_rawHardPrimeUnion Q z R theta a qf Cs eps p).mpr ⟨r,hr,⟨hH,hRatio,hhard⟩,hbad⟩ + +theorem soft_guarded_point_eligible (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf p : ℕ) + (Cs eps : ℝ) (hr : r ∈ Q) (hq : Squarefree qf) (hp : p.Prime) (hR : 0 < R) + (hRp : R ≤ (p : ℝ)) (hw : 2 ≤ sourceW z) (hY : p*qf ≤ sourceY z) + (hH : (effectiveModulus a r qf : ℝ) ≤ R*(sourceZ z)^11) + (hRatio : effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ (sourceZ z)^12) + (hbad : p ∈ badAligningPrimes (ErdosInversePrimeBin.primeBin R theta) (sourceY z) (sourceW z) a r qf eps) + (hout : p ∉ rawHardPrimeUnion Q z R theta a qf Cs eps) : + (r.den : ℝ) ≤ (sourceW z)^Cs ∧ (r.num.natAbs : ℝ) ≤ (sourceY z : ℝ)*(sourceW z)^(Cs+2) ∧ + ∀ t ∈ (p*qf).primeFactors,Cs < Real.logb (sourceW z) (t : ℝ) → + ErdosInverseAlignment.aligns (fun u => (a u : ℤ)) r t := by + have hsoft := soft_of_not_guarded_hard Q z R theta a r qf p Cs eps hr hH hRatio hbad hout + have halign := ((mem_badAligningPrimes _ _ _ _ _ _ _ _).mp hbad).2.1 + exact soft_endpoint_eligible (sourceY z) a r qf hq p hp halign R (sourceW z) Cs hR hRp hw hY hsoft.le + +end ErdosVarianceEligible + +end + +section + +namespace ErdosVarianceEligible +open NumberTheoryLean ErdosVarianceWeighted ErdosVarianceEffective ErdosVarianceSmallPrime ErdosInverseBoxHeight + ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection TwoPrimeObservableSum +attribute [local instance] Classical.propDecidable + +theorem endpoint_soft_conclusion {n : ℕ} (Q : Finset ℚ) (top R theta : ℝ) (residue : ℕ → ℕ) + (f : Fin n → Finset ℕ) (i : Fin n) (r : ℚ) (Cs eps : ℝ) + (hr : r ∈ Q) (hSq : Squarefree (selectionProduct (eraseSelection f i))) + (hp : (pickedPrime f i).Prime) (hR : 0 < R) (hRp : R ≤ (pickedPrime f i : ℝ)) + (hw : 2 ≤ sourceW top) (hY : pickedPrime f i*selectionProduct (eraseSelection f i) ≤ sourceY top) + (hH : (effectiveModulus residue r (selectionProduct (eraseSelection f i)) : ℝ) ≤ R*(sourceZ top)^11) + (hRatio : effectiveSize residue r (selectionProduct (eraseSelection f i)) R/ + (effectiveModulus residue r (selectionProduct (eraseSelection f i)) : ℝ) ≤ (sourceZ top)^12) + (hbad : pickedPrime f i ∈ badAligningPrimes (ErdosInversePrimeBin.primeBin R theta) (sourceY top) (sourceW top) + residue r (selectionProduct (eraseSelection f i)) eps) + (hout : ¬hardSelection Q top R theta residue i Cs eps f) : + (r.den : ℝ) ≤ (sourceW top)^Cs ∧ (r.num.natAbs : ℝ) ≤ (sourceY top : ℝ)*(sourceW top)^(Cs+2) ∧ + ∀ t ∈ (pickedPrime f i*selectionProduct (eraseSelection f i)).primeFactors, + Cs < Real.logb (sourceW top) (t : ℝ) → ErdosInverseAlignment.aligns (fun u => (residue u : ℤ)) r t := + soft_guarded_point_eligible Q top R theta residue r (selectionProduct (eraseSelection f i)) (pickedPrime f i) + Cs eps hr hSq hp hR hRp hw hY hH hRatio hbad hout + +end ErdosVarianceEligible + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/EvenInverseBands.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EvenInverseBands.lean new file mode 100644 index 0000000000000000000000000000000000000000..e42a87bf0ebee850b511e3d7fcedc2d94b478a0a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EvenInverseBands.lean @@ -0,0 +1,750 @@ +import Mathlib.Analysis.SpecialFunctions.Exp +import OAI.NumberTheory.Jacobsthal.Analysis.DensityComparison +import OAI.NumberTheory.Jacobsthal.Partitions.BandShiftTransport + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.StateMarginalBridge +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.RegenerationTails +open Erdos970Dependency.OrdinaryKernelInvariance Erdos970Dependency.StateKernelInvariance +open Erdos970Dependency.MarginalDensityMeasures + +theorem evenReal_map_lift : evenRealKernel.map oddLift = evenToOdd.comap evenLift evenLift_measurable := by + ext s B hB + rw [Kernel.map_apply _ oddLift_measurable] + change (evenKernel (evenLift s)).map oddLift B = evenToOdd (evenLift s) B + rw [evenKernel_map_lift] + +theorem oddReal_map_lift : oddRealKernel.map evenLift = oddToEven.comap oddLift oddLift_measurable := by + ext s B hB + rw [Kernel.map_apply _ evenLift_measurable] + change (oddKernel (oddLift s)).map evenLift B = oddToEven (oddLift s) B + rw [oddKernel_map_lift] + +theorem propagate_even (mu : Measure ℝ) : + stateKernel ∘ₘ (mu.map evenLift).map Sum.inl = ((evenRealKernel ∘ₘ mu).map oddLift).map Sum.inr := by + rw [comp_map_input _ _ _ measurable_inl] + change evenBranch ∘ₘ mu.map evenLift = _ + rw [evenBranch, ← Measure.map_comp _ _ measurable_inr, + comp_map_input _ _ _ evenLift_measurable, ← evenReal_map_lift, + ← Measure.map_comp _ _ oddLift_measurable] + +theorem propagate_odd (mu : Measure ℝ) : + stateKernel ∘ₘ (mu.map oddLift).map Sum.inr = ((oddRealKernel ∘ₘ mu).map evenLift).map Sum.inl := by + rw [comp_map_input _ _ _ measurable_inr] + change oddBranch ∘ₘ mu.map oddLift = _ + rw [oddBranch, ← Measure.map_comp _ _ measurable_inl, + comp_map_input _ _ _ oddLift_measurable, ← oddReal_map_lift, + ← Measure.map_comp _ _ evenLift_measurable] + +theorem state_even_first (s : EvenState) : + stateKernel (Sum.inl s) = ((evenKernel s).map oddLift).map Sum.inr := by + change evenBranch s = _ + rw [evenBranch, Kernel.map_apply _ measurable_inr, evenKernel_map_lift] + +theorem state_odd_first (s : OddState) : + stateKernel (Sum.inr s) = ((oddKernel s).map evenLift).map Sum.inl := by + change oddBranch s = _ + rw [oddBranch, Kernel.map_apply _ measurable_inl, oddKernel_map_lift] + +theorem state_even_two (s : EvenState) : + (stateKernel ^ 2) (Sum.inl s) = ((initialTwoMeasure s).map evenLift).map Sum.inl := by + rw [pow_two] + change (stateKernel ∘ₖ stateKernel) (Sum.inl s) = _ + rw [Kernel.comp_apply, state_even_first] + exact propagate_odd (evenKernel s) + +theorem state_odd_two (s : OddState) : + (stateKernel ^ 2) (Sum.inr s) = ((evenRealKernel ∘ₘ oddKernel s).map oddLift).map Sum.inr := by + rw [pow_two] + change (stateKernel ∘ₖ stateKernel) (Sum.inr s) = _ + rw [Kernel.comp_apply, state_odd_first] + exact propagate_even (oddKernel s) + +theorem state_reg_three : + (stateKernel ^ 3) (Sum.inr regenerationState) = (regThreeMeasure.map evenLift).map Sum.inl := by + have hp : stateKernel ^ 3 = stateKernel ∘ₖ (stateKernel ^ 2) := pow_succ' stateKernel 2 + rw [hp, Kernel.comp_apply, state_odd_two] + exact propagate_odd (evenRealKernel ∘ₘ oddKernel regenerationState) + +end Erdos970Dependency.StateMarginalBridge + +end + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.InitialStateDomination +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathMeasures NumberTheoryLean.RegenerationTails +open Erdos970Dependency.OrdinaryKernelInvariance Erdos970Dependency.DensityComparison +open Erdos970Dependency.MarginalDensityMeasures Erdos970Dependency.StateMarginalBridge + +theorem initial_state_measure_le (s : EvenState) (hs : 199 / 100 ≤ s.1) (hsup : s.1 ≤ 23 / 10) : + (stateKernel ^ 2) (Sum.inl s) ≤ ENNReal.ofReal dominationConstant • + (stateKernel ^ 3) (Sum.inr regenerationState) := by + rw [state_even_two, state_reg_three] + apply Measure.le_iff.mpr + intro B hB + rw [Measure.map_apply measurable_inl hB, + Measure.map_apply evenLift_measurable (measurable_inl hB), + Measure.smul_apply, smul_eq_mul, + Measure.map_apply measurable_inl hB, + Measure.map_apply evenLift_measurable (measurable_inl hB)] + have h := Measure.le_iff.mp (initial_real_measure_le s hs hsup) + (evenLift ⁻¹' (Sum.inl ⁻¹' B)) (evenLift_measurable (measurable_inl hB)) + rw [Measure.smul_apply, smul_eq_mul] at h + exact h + +theorem initial_two_step_domination : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ s : EvenState, 199 / 100 ≤ s.1 → s.1 ≤ 23 / 10 → + (stateKernel ^ 2) (Sum.inl s) ≤ C • (stateKernel ^ 3) (Sum.inr regenerationState) := by + exact ⟨ENNReal.ofReal dominationConstant, ENNReal.ofReal_lt_top, initial_state_measure_le⟩ + +end Erdos970Dependency.InitialStateDomination + +end + +section + +namespace NumberTheoryLean.InvariantInverseWeights + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open DerivativeWeights TransitionKernels FinitePathMeasures +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantFiniteness +open Erdos970Dependency.OrdinaryKernelInvariance Erdos970Dependency.StateKernelInvariance + +noncomputable def stateWeight : State → ℝ := + Sum.elim (fun s : EvenState => phiEven s.1) (fun s : OddState => phiOdd s.1) + +theorem stateWeight_pos (s : State) : 0 < stateWeight s := by + cases s with + | inl s => exact phiEven_pos (by linarith [s.2]) + | inr s => exact phiOdd_pos s.1 + +theorem stateWeight_measurable : Measurable stateWeight := + (phiEven_measurable.comp measurable_subtype_coe).sumElim + (phiOdd_continuous.measurable.comp measurable_subtype_coe) + +noncomputable def inverseWeightCutoff (L : ℝ) : State → ℝ≥0∞ := + {s | stateRatio s < L}.indicator (fun s => (ENNReal.ofReal (stateWeight s))⁻¹) + +theorem inverseWeightCutoff_measurable (L : ℝ) : Measurable (inverseWeightCutoff L) := + (ENNReal.measurable_ofReal.comp stateWeight_measurable).inv.indicator + (measurableSet_lt stateRatio_measurable measurable_const) + +theorem even_inverse_density_le (L t : ℝ) : + ENNReal.ofReal (Erdos970Dependency.InvariantDensities.evenDensity t) * inverseWeightCutoff L (.inl (evenLift t)) ≤ + (Icc (0 : ℝ) L).indicator (fun _ => (1 : ℝ≥0∞)) t := by + by_cases ht : 2 ≤ t + · have hl : (evenLift t).1 = t := max_eq_right (by linarith) + have hw : stateWeight (.inl (evenLift t)) = phiEven t := by change phiEven (evenLift t).1 = _; rw [hl] + have hr : stateRatio (.inl (evenLift t)) = t := hl + rw [Erdos970Dependency.InvariantDensities.evenDensity, indicator_of_mem (show t ∈ Ici (2 : ℝ) from ht)] + unfold inverseWeightCutoff + by_cases hL : t < L + · rw [indicator_of_mem (show (.inl (evenLift t) : State) ∈ {s | stateRatio s < L} by simpa only [mem_ofPred_eq, hr] using hL), hw, + ENNReal.mul_inv_cancel (ENNReal.ofReal_pos.mpr (phiEven_pos (by linarith))).ne' ENNReal.ofReal_ne_top, + indicator_of_mem (show t ∈ Icc (0 : ℝ) L from ⟨by linarith, hL.le⟩)] + · rw [indicator_of_notMem (show (.inl (evenLift t) : State) ∉ {s | stateRatio s < L} by simpa only [mem_ofPred_eq, hr] using hL), mul_zero] + exact zero_le + · rw [Erdos970Dependency.InvariantDensities.evenDensity, indicator_of_notMem (show t ∉ Ici (2 : ℝ) from ht), ENNReal.ofReal_zero, zero_mul] + exact zero_le + +theorem odd_inverse_density_le (L t : ℝ) : + ENNReal.ofReal (Erdos970Dependency.InvariantDensities.oddDensity t) * inverseWeightCutoff L (.inr (oddLift t)) ≤ + (Icc (0 : ℝ) L).indicator (fun _ => (1 : ℝ≥0∞)) t := by + by_cases ht : 1 ≤ t + · have hl : (oddLift t).1 = t := max_eq_right (by linarith) + have hw : stateWeight (.inr (oddLift t)) = phiOdd t := by change phiOdd (oddLift t).1 = _; rw [hl] + have hr : stateRatio (.inr (oddLift t)) = t := hl + have hf := oddFactor_bounds ht + rw [Erdos970Dependency.InvariantDensities.oddDensity, indicator_of_mem (show t ∈ Ici (1 : ℝ) from ht), ENNReal.ofReal_mul hf.1] + unfold inverseWeightCutoff + by_cases hL : t < L + · rw [indicator_of_mem (show (.inr (oddLift t) : State) ∈ {s | stateRatio s < L} by simpa only [mem_ofPred_eq, hr] using hL), hw, + mul_assoc, ENNReal.mul_inv_cancel (ENNReal.ofReal_pos.mpr (phiOdd_pos t)).ne' ENNReal.ofReal_ne_top, mul_one, + indicator_of_mem (show t ∈ Icc (0 : ℝ) L from ⟨by linarith, hL.le⟩)] + exact (ENNReal.ofReal_le_ofReal hf.2).trans_eq ENNReal.ofReal_one + · rw [indicator_of_notMem (show (.inr (oddLift t) : State) ∉ {s | stateRatio s < L} by simpa only [mem_ofPred_eq, hr] using hL), mul_zero] + exact zero_le + · rw [Erdos970Dependency.InvariantDensities.oddDensity, indicator_of_notMem (show t ∉ Ici (1 : ℝ) from ht), ENNReal.ofReal_zero, zero_mul] + exact zero_le + +theorem inverseWeightCutoff_mass_le {L : ℝ} (hL : 0 ≤ L) : + (∫⁻ s : State, inverseWeightCutoff L s ∂stateMeasure) ≤ ENNReal.ofReal (2 * L) := by + have hQ := inverseWeightCutoff_measurable L + rw [stateMeasure, lintegral_add_measure, + lintegral_map hQ measurable_inl, lintegral_map hQ measurable_inr, + evenStateMeasure, oddStateMeasure, + lintegral_map (f := fun s : EvenState => inverseWeightCutoff L (.inl s)) (hQ.comp measurable_inl) evenLift_measurable, + lintegral_map (f := fun s : OddState => inverseWeightCutoff L (.inr s)) (hQ.comp measurable_inr) oddLift_measurable, + evenMeasure, oddMeasure, + lintegral_withDensity_eq_lintegral_mul volume + (f := fun t : ℝ => ENNReal.ofReal (Erdos970Dependency.InvariantDensities.evenDensity t)) + (g := fun t : ℝ => inverseWeightCutoff L (.inl (evenLift t))) + (ENNReal.measurable_ofReal.comp Erdos970Dependency.InvariantDensities.evenDensity_measurable) + (hQ.comp (measurable_inl.comp evenLift_measurable)), + lintegral_withDensity_eq_lintegral_mul volume + (f := fun t : ℝ => ENNReal.ofReal (Erdos970Dependency.InvariantDensities.oddDensity t)) + (g := fun t : ℝ => inverseWeightCutoff L (.inr (oddLift t))) + (ENNReal.measurable_ofReal.comp Erdos970Dependency.InvariantDensities.oddDensity_measurable) + (hQ.comp (measurable_inr.comp oddLift_measurable))] + calc + _ ≤ (∫⁻ t : ℝ, (Icc (0 : ℝ) L).indicator (fun _ => (1 : ℝ≥0∞)) t) + + (∫⁻ t : ℝ, (Icc (0 : ℝ) L).indicator (fun _ => (1 : ℝ≥0∞)) t) := + add_le_add (lintegral_mono (even_inverse_density_le L)) (lintegral_mono (odd_inverse_density_le L)) + _ = ENNReal.ofReal L + ENNReal.ofReal L := by + have hI : (∫⁻ t : ℝ, (Icc (0 : ℝ) L).indicator (fun _ => (1 : ℝ≥0∞)) t) = ENNReal.ofReal L := by + change (∫⁻ t : ℝ, (Icc (0 : ℝ) L).indicator 1 t) = _ + rw [lintegral_indicator_one measurableSet_Icc, Real.volume_Icc, sub_zero] + rw [hI] + _ = _ := by rw [← ENNReal.ofReal_add hL hL]; congr 1; ring + +end NumberTheoryLean.InvariantInverseWeights + +end + +section + +namespace NumberTheoryLean.FirstStepInverseWeight + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open DerivativeWeights WeightFutureIntegrals TransitionKernels FinitePathMeasures +open KernelDensityBridge InvariantInverseWeights + +noncomputable def firstDensityConstant : ℝ := 3 / phiEven (23 / 10) + +theorem firstDensityConstant_pos : 0 < firstDensityConstant := div_pos (by norm_num) (phiEven_pos (by norm_num)) + +theorem W_le_three {t : ℝ} (ht : (49 / 50 : ℝ) ≤ t) : W t ≤ 3 := by + have ht0 : 0 < t := by linarith + rw [W] + apply (div_le_iff₀ (sq_pos_of_pos ht0)).mpr + nlinarith [sq_nonneg (t - 49 / 50)] + +theorem first_odd_density_bound (s : EvenState) (hs : s.1 ≤ 23 / 10) (t : ℝ) : + evenDensity s t ≤ firstDensityConstant * (Ici (49 / 50 : ℝ)).indicator phiOdd t := by + have hφ := phiEven_pos (s := s.1) (by linarith [s.2]) + have hm := phiEven_pos (s := (23 / 10 : ℝ)) (by norm_num) + have hmin : phiEven (23 / 10) ≤ phiEven s.1 := + phiEven_strictAntiOn.antitoneOn (by change 1 < s.1; linarith [s.2]) (by norm_num) hs + unfold evenDensity tailDensity + by_cases ht : s.1 - 1 ≤ t + · have ht98 : (49 / 50 : ℝ) ≤ t := by linarith [s.2] + rw [indicator_of_mem (show t ∈ Ici (s.1 - 1) from ht), + indicator_of_mem (show t ∈ Ici (49 / 50 : ℝ) from ht98)] + apply (div_le_iff₀ hφ).mpr + calc + W t * phiOdd t ≤ 3 * phiOdd t := mul_le_mul_of_nonneg_right (W_le_three ht98) (phiOdd_pos t).le + _ = (firstDensityConstant * phiOdd t) * phiEven (23 / 10) := by + dsimp [firstDensityConstant] + field_simp + _ ≤ _ := mul_le_mul_of_nonneg_left hmin (mul_nonneg firstDensityConstant_pos.le (phiOdd_pos t).le) + · rw [indicator_of_notMem (show t ∉ Ici (s.1 - 1) from ht)] + by_cases h98 : (49 / 50 : ℝ) ≤ t + · rw [indicator_of_mem (show t ∈ Ici (49 / 50 : ℝ) from h98)] + exact mul_nonneg firstDensityConstant_pos.le (phiOdd_pos t).le + · rw [indicator_of_notMem (show t ∉ Ici (49 / 50 : ℝ) from h98), mul_zero] + +theorem first_odd_inverse_mass (s : EvenState) (hs : s.1 ≤ 23 / 10) {L : ℝ} (_hL : 0 ≤ L) : + (∫⁻ t : State, inverseWeightCutoff L t ∂stateKernel (.inl s)) ≤ + ENNReal.ofReal (firstDensityConstant * L) := by + classical + let G : ℝ → ℝ≥0∞ := (Iio L).indicator (fun t => (ENNReal.ofReal (phiOdd t))⁻¹) + have hG : Measurable G := (ENNReal.measurable_ofReal.comp phiOdd_continuous.measurable).inv.indicator measurableSet_Iio + have hQ := inverseWeightCutoff_measurable L + change (∫⁻ t : State, inverseWeightCutoff L t ∂evenBranch s) ≤ _ + rw [evenBranch, Kernel.map_apply _ measurable_inr, lintegral_map hQ measurable_inr] + change (∫⁻ t : OddState, G t.1 ∂evenToOdd s) ≤ _ + rw [evenToOdd_lintegral_ratio s hG, evenKernel_lintegral_density s hG] + change (∫⁻ t : ℝ, ENNReal.ofReal (evenDensity s t) * G t) ≤ _ + have hb : ∀ t : ℝ, ENNReal.ofReal (evenDensity s t) * G t ≤ + ENNReal.ofReal firstDensityConstant * (Icc (0 : ℝ) L).indicator (fun _ => (1 : ℝ≥0∞)) t := by + intro t + have hd := first_odd_density_bound s hs t + by_cases h98 : (49 / 50 : ℝ) ≤ t + · rw [indicator_of_mem (show t ∈ Ici (49 / 50 : ℝ) from h98)] at hd + by_cases htL : t < L + · rw [show G t = (ENNReal.ofReal (phiOdd t))⁻¹ by + exact indicator_of_mem (show t ∈ Iio L from htL) _, + indicator_of_mem (show t ∈ Icc (0 : ℝ) L from ⟨by linarith, htL.le⟩), mul_one] + calc + _ ≤ ENNReal.ofReal (firstDensityConstant * phiOdd t) * (ENNReal.ofReal (phiOdd t))⁻¹ := + mul_le_mul (ENNReal.ofReal_le_ofReal hd) le_rfl zero_le zero_le + _ = _ := by + rw [ENNReal.ofReal_mul firstDensityConstant_pos.le, mul_assoc, + ENNReal.mul_inv_cancel (ENNReal.ofReal_pos.mpr (phiOdd_pos t)).ne' ENNReal.ofReal_ne_top, mul_one] + · rw [show G t = 0 from indicator_of_notMem (show t ∉ Iio L from htL) _, mul_zero] + exact zero_le + · rw [indicator_of_notMem (show t ∉ Ici (49 / 50 : ℝ) from h98), mul_zero] at hd + rw [ENNReal.ofReal_eq_zero.mpr hd, zero_mul] + exact zero_le + calc + _ ≤ ∫⁻ t : ℝ, ENNReal.ofReal firstDensityConstant * (Icc (0 : ℝ) L).indicator (fun _ => (1 : ℝ≥0∞)) t := lintegral_mono hb + _ = ENNReal.ofReal firstDensityConstant * ENNReal.ofReal L := by + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + congr 1 + change (∫⁻ t : ℝ, (Icc (0 : ℝ) L).indicator 1 t) = _ + rw [lintegral_indicator_one measurableSet_Icc, Real.volume_Icc, sub_zero] + _ = _ := (ENNReal.ofReal_mul firstDensityConstant_pos.le).symm + +end NumberTheoryLean.FirstStepInverseWeight + +end + +section + +namespace NumberTheoryLean.RegeneratingInverseBands + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures PairedCostGrouping RegenerationTails OccupationDecomposition +open RegenerationBandBounds InvariantInverseWeights FirstStepInverseWeight + +noncomputable def gapValue (v : ℝ) (z : CostState) : ℝ := Real.exp (v - z.2) + +noncomputable def inverseArrivalBand (v R ell : ℝ) : CostState → ℝ≥0∞ := + {z | R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ + stateRatio z.1 < gapValue v z / ell}.indicator + (fun z => (ENNReal.ofReal (stateWeight z.1))⁻¹) + +theorem inverseArrivalBand_measurable (v R ell : ℝ) : Measurable (inverseArrivalBand v R ell) := by + have hg : Measurable (gapValue v) := Real.measurable_exp.comp (measurable_const.sub measurable_snd) + exact ((ENNReal.measurable_ofReal.comp (stateWeight_measurable.comp measurable_fst)).inv).indicator + ((measurableSet_le measurable_const hg).inter + ((measurableSet_le hg measurable_const).inter + (measurableSet_lt (stateRatio_measurable.comp measurable_fst) (hg.div_const ell)))) + +theorem stateBandReward_le (Q : State → ℝ≥0∞) (v h : ℝ) (z : CostState) : + stateBandReward Q v h z ≤ Q z.1 := by + classical + unfold stateBandReward + by_cases hz : z.2 ∈ Icc v (v + h) + · rw [indicator_of_mem (show z ∈ Prod.snd ⁻¹' Icc v (v + h) from hz)] + · rw [indicator_of_notMem (show z ∉ Prod.snd ⁻¹' Icc v (v + h) from hz)] + exact zero_le + +theorem inverseArrivalBand_le_costBand (v : ℝ) {R ell : ℝ} (hR : 0 < R) (hell : 1 ≤ ell) + (z : CostState) : + inverseArrivalBand v R ell z ≤ + stateBandReward (inverseWeightCutoff (Real.exp 1 * R)) (v - Real.log R - 1) 1 z := by + classical + by_cases hz : R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell + · have hg : 0 < gapValue v z := Real.exp_pos _ + have hl : Real.log R ≤ v - z.2 := by + have h := Real.log_le_log hR hz.1 + rwa [gapValue, Real.log_exp] at h + have hu : v - z.2 ≤ 1 + Real.log R := by + have h := Real.log_le_log hg hz.2.1 + rwa [gapValue, Real.log_exp, Real.log_mul (Real.exp_pos 1).ne' hR.ne', Real.log_exp] at h + have ht : stateRatio z.1 < Real.exp 1 * R := + lt_of_lt_of_le hz.2.2 (le_trans (div_le_self hg.le hell) hz.2.1) + have hband : z.2 ∈ Icc (v - Real.log R - 1) (v - Real.log R - 1 + 1) := by + constructor <;> linarith + unfold inverseArrivalBand stateBandReward inverseWeightCutoff + rw [indicator_of_mem (show z ∈ {z | R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell} from hz), + indicator_of_mem (show z ∈ Prod.snd ⁻¹' Icc (v - Real.log R - 1) (v - Real.log R - 1 + 1) from hband), + indicator_of_mem (show z.1 ∈ {s | stateRatio s < Real.exp 1 * R} from ht)] + · unfold inverseArrivalBand + rw [indicator_of_notMem (show z ∉ {z | R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell} from hz)] + exact zero_le + +theorem regeneration_inverse_cutoff_band (h : ℝ) : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ L : ℝ, 0 ≤ L → ∀ v : ℝ, + (∫⁻ z, stateBandReward (inverseWeightCutoff L) v h z ∂fullOccupation (embedOdd (regenerationState, 0))) ≤ + C * ENNReal.ofReal L := by + obtain ⟨C, hC, hb⟩ := regeneration_uniform_band h + refine ⟨C * 2, ENNReal.mul_lt_top hC (by norm_num), ?_⟩ + intro L hL v + calc + _ ≤ C * ∫⁻ s, inverseWeightCutoff L s ∂Erdos970Dependency.StateKernelInvariance.stateMeasure := + hb _ (inverseWeightCutoff_measurable L) v + _ ≤ C * ENNReal.ofReal (2 * L) := mul_le_mul le_rfl (inverseWeightCutoff_mass_le hL) zero_le zero_le + _ = _ := by rw [ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≤ 2), ENNReal.ofReal_ofNat, mul_assoc] + +theorem regeneration_inverse_arrival_band : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ v R ell : ℝ, 0 < R → 1 ≤ ell → + (∫⁻ z, inverseArrivalBand v R ell z ∂fullOccupation (embedOdd (regenerationState, 0))) ≤ C * ENNReal.ofReal R := by + obtain ⟨C, hC, hb⟩ := regeneration_inverse_cutoff_band 1 + refine ⟨C * ENNReal.ofReal (Real.exp 1), ENNReal.mul_lt_top hC ENNReal.ofReal_lt_top, ?_⟩ + intro v R ell hR hell + calc + _ ≤ ∫⁻ z, stateBandReward (inverseWeightCutoff (Real.exp 1 * R)) (v - Real.log R - 1) 1 z + ∂fullOccupation (embedOdd (regenerationState, 0)) := lintegral_mono (inverseArrivalBand_le_costBand v hR hell) + _ ≤ C * ENNReal.ofReal (Real.exp 1 * R) := hb _ (by positivity) _ + _ = _ := by rw [ENNReal.ofReal_mul (Real.exp_pos 1).le, mul_assoc] + +theorem first_odd_inverse_arrival_band (s : TransitionKernels.EvenState) (hs : s.1 ≤ 23 / 10) + (v : ℝ) {R ell : ℝ} (hR : 0 < R) (hell : 1 ≤ ell) : + (∫⁻ z, inverseArrivalBand v R ell z ∂costKernel (.inl s, 0)) ≤ + ENNReal.ofReal (firstDensityConstant * Real.exp 1) * ENNReal.ofReal R := by + have hQ := inverseWeightCutoff_measurable (Real.exp 1 * R) + calc + _ ≤ ∫⁻ z, inverseWeightCutoff (Real.exp 1 * R) z.1 ∂costKernel (.inl s, 0) := + lintegral_mono (fun z => le_trans (inverseArrivalBand_le_costBand v hR hell z) (stateBandReward_le _ _ _ z)) + _ = ∫⁻ t : State, inverseWeightCutoff (Real.exp 1 * R) t ∂stateKernel (.inl s) := by + rw [← Erdos970Dependency.ActualCycleOccupation.costKernel_map_state (.inl s, 0), lintegral_map hQ measurable_fst] + _ ≤ ENNReal.ofReal (firstDensityConstant * (Real.exp 1 * R)) := first_odd_inverse_mass s hs (by positivity) + _ = _ := by rw [← ENNReal.ofReal_mul (mul_pos firstDensityConstant_pos (Real.exp_pos 1)).le]; congr 1; ring + +end NumberTheoryLean.RegeneratingInverseBands + +end + +section + +namespace NumberTheoryLean.EvenBandBounds + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathMeasures RegenerationTails PairedCostGrouping +open OccupationDecomposition InitialOccupation CostPrefixTransport +open BandShiftTransport RegenerationBandBounds RegeneratingInverseBands +open Erdos970Dependency.StateKernelInvariance +open Erdos970Dependency.InitialStateDomination + +theorem even_uniform_band (h : ℝ) : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ Q : State → ℝ≥0∞, Measurable Q → ∀ v : ℝ, ∀ s : EvenState, + (199 / 100 : ℝ) ≤ s.1 → s.1 ≤ 23 / 10 → + (∫⁻ z, stateBandReward Q v h z ∂prefixOccupation 2 (.inl s, 0)) ≤ + C * ∫⁻ t : State, Q t ∂stateMeasure := by + obtain ⟨D, hD, hdom⟩ := initial_two_step_domination + obtain ⟨B, hB, hb⟩ := regeneration_uniform_band (h + 5 * Real.log 3) + refine ⟨D * B, ENNReal.mul_lt_top hD hB, ?_⟩ + intro Q hQ v s hsL hsU + have ht := prefix_band_domination hQ 2 3 (.inl s) (.inr regenerationState) (hdom s hsL hsU) v h + norm_num only [Nat.cast_ofNat] at ht + rw [show h + 2 * Real.log 3 + 3 * Real.log 3 = h + 5 * Real.log 3 by ring] at ht + calc + _ ≤ D * ∫⁻ z, stateBandReward Q (v - 2 * Real.log 3) (h + 5 * Real.log 3) z + ∂prefixOccupation 3 (.inr regenerationState, 0) := ht + _ ≤ D * ∫⁻ z, stateBandReward Q (v - 2 * Real.log 3) (h + 5 * Real.log 3) z + ∂fullOccupation (.inr regenerationState, 0) := + mul_le_mul le_rfl (lintegral_mono' (prefixOccupation_le_full 3 (by norm_num) (.inr regenerationState, 0)) le_rfl) zero_le zero_le + _ ≤ D * (B * ∫⁻ t : State, Q t ∂stateMeasure) := mul_le_mul le_rfl (hb Q hQ _) zero_le zero_le + _ = _ := (mul_assoc _ _ _).symm + +theorem prefixOccupation_two : prefixOccupation 2 = fullOccupation ∘ₖ costKernel := by + rw [prefixOccupation, pow_two] + change inclusiveOccupation ∘ₖ (costKernel ∘ₖ costKernel) = _ + rw [← Kernel.comp_assoc, inclusive_comp_step] + +theorem fullOccupation_first_and_later : fullOccupation = costKernel + prefixOccupation 2 := by + rw [prefixOccupation_two] + exact fullOccupation_unfold + +end NumberTheoryLean.EvenBandBounds + +end + +section + +namespace NumberTheoryLean.WeightedGapTail + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathMeasures PairedCostGrouping RegenerationTails OccupationDecomposition +open InvariantInverseWeights RegeneratingInverseBands + +noncomputable def tailSeries (c : ℝ) (n : ℕ) : ℝ := + ((n : ℝ) + 2) ^ 3 * Real.exp (-c * ((n : ℝ) + 1)) + +theorem tailSeries_nonneg (c : ℝ) (n : ℕ) : 0 ≤ tailSeries c n := by unfold tailSeries; positivity + +theorem tailSeries_summable {c : ℝ} (hc : 0 < c) : Summable (tailSeries c) := by + have h := (summable_nat_add_iff 2).mpr (Real.summable_pow_mul_exp_neg_nat_mul 3 hc) + have h' := h.mul_left (Real.exp c) + convert! h' using 1 + funext n + simp only [tailSeries, Nat.cast_add, Nat.cast_ofNat] + rw [mul_comm (Real.exp c), mul_assoc, ← Real.exp_add] + congr 2 + ring + +noncomputable def tailBudget (C : ℝ≥0∞) (c : ℝ) (N : ℕ) : ℝ≥0∞ := + C * ∑' k : ℕ, ENNReal.ofReal (tailSeries c (k + N)) + +theorem tailBudget_tendsto_zero {C : ℝ≥0∞} (hC : C ≠ ∞) {c : ℝ} (hc : 0 < c) : + Tendsto (tailBudget C c) atTop (𝓝 0) := by + have hs : (∑' n : ℕ, ENNReal.ofReal (tailSeries c n)) ≠ ∞ := (tailSeries_summable hc).tsum_ofReal_lt_top.ne + have h := ENNReal.tendsto_sum_nat_add (fun n => ENNReal.ofReal (tailSeries c n)) hs + change Tendsto (fun N : ℕ => C * ∑' k : ℕ, ENNReal.ofReal (tailSeries c (k + N))) atTop (𝓝 0) + simpa only [mul_zero] using (ENNReal.Tendsto.const_mul (a := C) h (Or.inr hC)) + +noncomputable def tailReward (c v ell : ℝ) (N : ℕ) : CostState → ℝ≥0∞ := + {z | (N : ℝ) + 1 ≤ gapValue v z ∧ stateRatio z.1 < gapValue v z / ell}.indicator + (fun z => ENNReal.ofReal ((gapValue v z) ^ 2 * Real.exp (-c * gapValue v z)) * + (ENNReal.ofReal (stateWeight z.1))⁻¹) + +theorem tailReward_measurable (c v ell : ℝ) (N : ℕ) : Measurable (tailReward c v ell N) := by + have hg : Measurable (gapValue v) := Real.measurable_exp.comp (measurable_const.sub measurable_snd) + exact ((ENNReal.measurable_ofReal.comp ((hg.pow_const 2).mul (Real.measurable_exp.comp (measurable_const.mul hg)))).mul + (ENNReal.measurable_ofReal.comp (stateWeight_measurable.comp measurable_fst)).inv).indicator + ((measurableSet_le measurable_const hg).inter + (measurableSet_lt (stateRatio_measurable.comp measurable_fst) (hg.div_const ell))) + +noncomputable def binCoefficient (c : ℝ) (n : ℕ) : ℝ := + ((n : ℝ) + 2) ^ 2 * Real.exp (-c * ((n : ℝ) + 1)) + +theorem tailReward_le_band_sum {c : ℝ} (hc : 0 < c) (v ell : ℝ) (N : ℕ) (z : CostState) : + tailReward c v ell N z ≤ ∑' k : ℕ, + ENNReal.ofReal (binCoefficient c (k + N)) * inverseArrivalBand v ((k + N : ℕ) + 1) ell z := by + classical + by_cases hz : (N : ℝ) + 1 ≤ gapValue v z ∧ stateRatio z.1 < gapValue v z / ell + · let r := gapValue v z + have hr : 0 < r := Real.exp_pos _ + have hn : N + 1 ≤ ⌊r⌋₊ := (Nat.le_floor_iff hr.le).mpr (by exact_mod_cast hz.1) + let k := ⌊r⌋₊ - (N + 1) + have hk : k + N + 1 = ⌊r⌋₊ := by dsimp [k]; omega + have hkR : ((k + N : ℕ) : ℝ) + 1 = (⌊r⌋₊ : ℝ) := by exact_mod_cast hk + let R : ℝ := ((k + N : ℕ) : ℝ) + 1 + have hR1 : 1 ≤ R := by dsimp [R]; have hh := Nat.cast_nonneg' (α := ℝ) (k + N); linarith + have hlow : R ≤ r := by rw [show R = (⌊r⌋₊ : ℝ) from hkR]; exact Nat.floor_le hr.le + have hhigh : r < R + 1 := by rw [show R = (⌊r⌋₊ : ℝ) from hkR]; exact Nat.lt_floor_add_one r + have he : (2 : ℝ) ≤ Real.exp 1 := by linarith [Real.add_one_le_exp (1 : ℝ)] + have hupper : r ≤ Real.exp 1 * R := by nlinarith [mul_le_mul_of_nonneg_right he (by linarith : 0 ≤ R)] + have hsq : r ^ 2 ≤ (R + 1) ^ 2 := by nlinarith + have hexp : Real.exp (-c * r) ≤ Real.exp (-c * R) := + Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_left hlow (by linarith)) + have hweight : r ^ 2 * Real.exp (-c * r) ≤ (R + 1) ^ 2 * Real.exp (-c * R) := + mul_le_mul hsq hexp (Real.exp_pos _).le (sq_nonneg _) + have hA : R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell := + ⟨hlow, hupper, hz.2⟩ + calc + _ = ENNReal.ofReal (r ^ 2 * Real.exp (-c * r)) * (ENNReal.ofReal (stateWeight z.1))⁻¹ := + by rw [tailReward, indicator_of_mem (show z ∈ {z : CostState | (N : ℝ) + 1 ≤ gapValue v z ∧ stateRatio z.1 < gapValue v z / ell} from hz)] + _ ≤ ENNReal.ofReal ((R + 1) ^ 2 * Real.exp (-c * R)) * (ENNReal.ofReal (stateWeight z.1))⁻¹ := + mul_le_mul (ENNReal.ofReal_le_ofReal hweight) le_rfl zero_le zero_le + _ = ENNReal.ofReal (binCoefficient c (k + N)) * inverseArrivalBand v ((k + N : ℕ) + 1) ell z := by + rw [inverseArrivalBand, indicator_of_mem (show z ∈ {z : CostState | R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell} from hA)] + have hcoef : (R + 1) ^ 2 * Real.exp (-c * R) = binCoefficient c (k + N) := by + dsimp [R, binCoefficient] + ring + rw [hcoef] + _ ≤ _ := by + simpa only [Nat.cast_add,Nat.cast_one] using + (ENNReal.le_tsum (f := fun k : ℕ => ENNReal.ofReal (binCoefficient c (k+N)) * + inverseArrivalBand v ((k+N : ℕ)+1) ell z) k) + · rw [tailReward, indicator_of_notMem (show z ∉ {z : CostState | (N : ℝ) + 1 ≤ gapValue v z ∧ stateRatio z.1 < gapValue v z / ell} from hz)] + exact zero_le + +theorem weighted_tail_of_inverse_bands (μ : Measure CostState) (v ell : ℝ) {C : ℝ≥0∞} + (hband : ∀ R : ℝ, 0 < R → (∫⁻ z, inverseArrivalBand v R ell z ∂μ) ≤ C * ENNReal.ofReal (R + 1)) + {c : ℝ} (hc : 0 < c) (N : ℕ) : + (∫⁻ z, tailReward c v ell N z ∂μ) ≤ tailBudget C c N := by + calc + _ ≤ ∫⁻ z, ∑' k : ℕ, ENNReal.ofReal (binCoefficient c (k + N)) * + inverseArrivalBand v ((k + N : ℕ) + 1) ell z ∂μ := lintegral_mono (tailReward_le_band_sum hc v ell N) + _ = ∑' k : ℕ, ENNReal.ofReal (binCoefficient c (k + N)) * + (∫⁻ z, inverseArrivalBand v ((k + N : ℕ) + 1) ell z ∂μ) := by + rw [lintegral_tsum (f := fun (k : ℕ) (z : CostState) => ENNReal.ofReal (binCoefficient c (k + N)) * inverseArrivalBand v (((k + N : ℕ) : ℝ) + 1) ell z) (fun k => (measurable_const.mul (inverseArrivalBand_measurable _ _ _)).aemeasurable)] + apply tsum_congr + intro k + exact lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + _ ≤ ∑' k : ℕ, ENNReal.ofReal (binCoefficient c (k + N)) * + (C * ENNReal.ofReal (((k + N : ℕ) : ℝ) + 1 + 1)) := by + apply ENNReal.tsum_le_tsum + intro k + exact mul_le_mul le_rfl (hband _ (by positivity)) zero_le zero_le + _ = tailBudget C c N := by + rw [tailBudget, ← ENNReal.tsum_mul_left] + apply tsum_congr + intro k + have hA : 0 ≤ binCoefficient c (k + N) := by unfold binCoefficient; positivity + rw [mul_left_comm, ← ENNReal.ofReal_mul hA] + congr 2 + dsimp [binCoefficient, tailSeries] + ring + +theorem regeneration_weighted_tail {c : ℝ} (hc : 0 < c) : + ∃ b : ℕ → ℝ≥0∞, Tendsto b atTop (𝓝 0) ∧ ∀ N : ℕ, ∀ v ell : ℝ, 1 ≤ ell → + (∫⁻ z, tailReward c v ell N z ∂fullOccupation (embedOdd (regenerationState, 0))) ≤ b N := by + obtain ⟨C, hC, hb⟩ := regeneration_inverse_arrival_band + refine ⟨tailBudget C c, tailBudget_tendsto_zero hC.ne hc, ?_⟩ + intro N v ell hell + apply weighted_tail_of_inverse_bands _ v ell _ hc N + intro R hR + exact le_trans (hb v R ell hR hell) + (mul_le_mul le_rfl (ENNReal.ofReal_le_ofReal (by linarith : R ≤ R + 1)) zero_le zero_le) + +end NumberTheoryLean.WeightedGapTail + +end + +section + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +namespace ErdosHighRatioBandTail +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels +open NumberTheoryLean.RegenerationBandBounds NumberTheoryLean.BandShiftTransport +open NumberTheoryLean.CostPrefixTransport NumberTheoryLean.EvenBandBounds +open Erdos970Dependency.StateKernelInvariance + +def highStates (T : ℝ) : Set State := {s | T ≤ stateRatio s} + +noncomputable def highReward (T : ℝ) : State → ℝ≥0∞ := + (highStates T).indicator (fun _ => 1) + +def highBand (T v h : ℝ) : Set CostState := + {z | T ≤ stateRatio z.1 ∧ z.2 ∈ Icc v (v+h)} + +theorem highStates_measurable (T : ℝ) : MeasurableSet (highStates T) := + measurableSet_le measurable_const stateRatio_measurable + +theorem highReward_measurable (T : ℝ) : Measurable (highReward T) := + measurable_const.indicator (highStates_measurable T) + +theorem highBand_measurable (T v h : ℝ) : MeasurableSet (highBand T v h) := + (measurableSet_le measurable_const (stateRatio_measurable.comp measurable_fst)).inter + (measurable_snd measurableSet_Icc) + +theorem highReward_integral (μ : Measure State) (T : ℝ) : + (∫⁻ s, highReward T s ∂μ) = μ (highStates T) := by + rw [highReward, lintegral_indicator (highStates_measurable T)] + simp + +theorem highBand_integral (μ : Measure CostState) (T v h : ℝ) : + (∫⁻ z, stateBandReward (highReward T) v h z ∂μ) = μ (highBand T v h) := by + have he : stateBandReward (highReward T) v h = + (highBand T v h).indicator (fun _ => (1 : ℝ≥0∞)) := by + funext z + by_cases ht : T ≤ stateRatio z.1 <;> by_cases hc : z.2 ∈ Icc v (v+h) <;> + simp_all [stateBandReward, highReward, highStates, highBand, Set.indicator_apply] + rw [he, lintegral_indicator (highBand_measurable T v h)] + simp + +theorem stateMeasure_tail_tendsto : + Tendsto (fun T : ℝ => stateMeasure (highStates T)) atTop (𝓝 0) := by + have hm : Antitone highStates := by + intro T U hTU s hs + exact hTU.trans hs + have he : (⋂ T : ℝ, highStates T) = ∅ := by + ext s + simp only [mem_iInter, highStates, Set.mem_ofPred_eq, mem_empty_iff_false, iff_false] + intro hs + have h := hs (stateRatio s+1) + linarith + have ht := tendsto_measure_iInter_atTop + (fun T => (highStates_measurable T).nullMeasurableSet (μ := stateMeasure)) hm + (show ∃ T : ℝ, stateMeasure (highStates T) ≠ ∞ from ⟨0, measure_ne_top _ _⟩) + simpa only [he, measure_empty, Function.comp_def] using ht + +theorem later_band_tail_bound (h : ℝ) : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ T v : ℝ, ∀ s : EvenState, 199/100 ≤ s.1 → s.1 ≤ 23/10 → + prefixOccupation 2 (.inl s,0) (highBand T v h) ≤ C*stateMeasure (highStates T) := by + obtain ⟨C,hC,hb⟩ := even_uniform_band h + refine ⟨C,hC,?_⟩ + intro T v s hsL hsU + have ht := hb (highReward T) (highReward_measurable T) v s hsL hsU + simpa only [highBand_integral, highReward_integral] using ht + +end ErdosHighRatioBandTail + +end + +section + +namespace NumberTheoryLean.EvenInverseBands + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open DerivativeWeights TransitionKernels FinitePathMeasures OccupationDecomposition +open CostPrefixTransport RegenerationBandBounds InvariantInverseWeights +open RegeneratingInverseBands FirstStepInverseWeight EvenBandBounds WeightedGapTail + +theorem even_inverse_arrival_from_two : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ s : EvenState, (199 / 100 : ℝ) ≤ s.1 → s.1 ≤ 23 / 10 → + ∀ v R ell : ℝ, 0 < R → 1 ≤ ell → + (∫⁻ z, inverseArrivalBand v R ell z ∂prefixOccupation 2 (.inl s, 0)) ≤ C * ENNReal.ofReal R := by + obtain ⟨B, hB, hb⟩ := even_uniform_band 1 + refine ⟨B * ENNReal.ofReal (2 * Real.exp 1), ENNReal.mul_lt_top hB ENNReal.ofReal_lt_top, ?_⟩ + intro s hsL hsU v R ell hR hell + calc + _ ≤ ∫⁻ z, stateBandReward (inverseWeightCutoff (Real.exp 1 * R)) (v - Real.log R - 1) 1 z + ∂prefixOccupation 2 (.inl s, 0) := lintegral_mono (inverseArrivalBand_le_costBand v hR hell) + _ ≤ B * ∫⁻ t : State, inverseWeightCutoff (Real.exp 1 * R) t + ∂Erdos970Dependency.StateKernelInvariance.stateMeasure := + hb _ (inverseWeightCutoff_measurable _) _ s hsL hsU + _ ≤ B * ENNReal.ofReal (2 * (Real.exp 1 * R)) := + mul_le_mul le_rfl (inverseWeightCutoff_mass_le (by positivity)) zero_le zero_le + _ = _ := by + rw [show 2 * (Real.exp 1 * R) = (2 * Real.exp 1) * R by ring, + ENNReal.ofReal_mul (by positivity : 0 ≤ 2 * Real.exp 1), mul_assoc] + +theorem even_future_inverse_arrival_band : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ s : EvenState, (199 / 100 : ℝ) ≤ s.1 → s.1 ≤ 23 / 10 → + ∀ v R ell : ℝ, 0 < R → 1 ≤ ell → + (∫⁻ z, inverseArrivalBand v R ell z ∂fullOccupation (.inl s, 0)) ≤ C * ENNReal.ofReal R := by + obtain ⟨B, hB, hb⟩ := even_inverse_arrival_from_two + refine ⟨ENNReal.ofReal (firstDensityConstant * Real.exp 1) + B, + ENNReal.add_lt_top.mpr ⟨ENNReal.ofReal_lt_top, hB⟩, ?_⟩ + intro s hsL hsU v R ell hR hell + rw [fullOccupation_first_and_later, _root_.add_apply, lintegral_add_measure] + calc + _ ≤ ENNReal.ofReal (firstDensityConstant * Real.exp 1) * ENNReal.ofReal R + B * ENNReal.ofReal R := + add_le_add (first_odd_inverse_arrival_band s hsU v hR hell) (hb s hsL hsU v R ell hR hell) + _ = _ := (add_mul _ _ _).symm + +theorem inverseArrivalBand_le_weight (v R ell : ℝ) (z : CostState) : + inverseArrivalBand v R ell z ≤ (ENNReal.ofReal (stateWeight z.1))⁻¹ := by + classical + unfold inverseArrivalBand + by_cases hz : R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell + · rw [indicator_of_mem (show z ∈ {z | R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell} from hz)] + · rw [indicator_of_notMem (show z ∉ {z | R ≤ gapValue v z ∧ gapValue v z ≤ Real.exp 1 * R ∧ stateRatio z.1 < gapValue v z / ell} from hz)] + exact zero_le + +theorem starting_inverse_weight_le (s : EvenState) (hs : s.1 ≤ 23 / 10) : + (ENNReal.ofReal (stateWeight (.inl s)))⁻¹ ≤ (ENNReal.ofReal (phiEven (23 / 10)))⁻¹ := by + apply ENNReal.inv_le_inv.mpr + apply ENNReal.ofReal_le_ofReal + exact phiEven_strictAntiOn.antitoneOn (by change 1 < s.1; linarith [s.2]) (by norm_num) hs + +theorem source_inverse_phi_band : ∃ C : ℝ≥0∞, C < ∞ ∧ + ∀ s : EvenState, (199 / 100 : ℝ) ≤ s.1 → s.1 ≤ 23 / 10 → + ∀ v R ell : ℝ, 0 < R → 1 ≤ ell → + (∫⁻ z, inverseArrivalBand v R ell z ∂inclusiveOccupation (.inl s, 0)) ≤ C * ENNReal.ofReal (R + 1) := by + obtain ⟨B, hB, hb⟩ := even_future_inverse_arrival_band + let D := (ENNReal.ofReal (phiEven (23 / 10)))⁻¹ + have hD : D < ∞ := lt_top_iff_ne_top.mpr + (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_pos.mpr (phiEven_pos (by norm_num))).ne') + refine ⟨D + B, ENNReal.add_lt_top.mpr ⟨hD, hB⟩, ?_⟩ + intro s hsL hsU v R ell hR hell + rw [inclusiveOccupation, _root_.add_apply, lintegral_add_measure, Kernel.id_apply, + lintegral_dirac' (.inl s, 0) (inverseArrivalBand_measurable v R ell)] + calc + _ ≤ D + B * ENNReal.ofReal R := add_le_add + (le_trans (inverseArrivalBand_le_weight v R ell (.inl s, 0)) (starting_inverse_weight_le s hsU)) + (hb s hsL hsU v R ell hR hell) + _ ≤ (D + B * ENNReal.ofReal R) + (D * ENNReal.ofReal R + B) := le_add_of_nonneg_right zero_le + _ = (D + B) * ENNReal.ofReal (R + 1) := by + rw [ENNReal.ofReal_add hR.le (by norm_num : (0 : ℝ) ≤ 1), ENNReal.ofReal_one] + ring + +theorem source_exponential_reward_tail {c : ℝ} (hc : 0 < c) : + ∃ b : ℕ → ℝ≥0∞, Tendsto b atTop (𝓝 0) ∧ ∀ N : ℕ, ∀ s : EvenState, + (199 / 100 : ℝ) ≤ s.1 → s.1 ≤ 23 / 10 → ∀ v ell : ℝ, 1 ≤ ell → + (∫⁻ z, tailReward c v ell N z ∂inclusiveOccupation (.inl s, 0)) ≤ b N := by + obtain ⟨C, hC, hb⟩ := source_inverse_phi_band + refine ⟨tailBudget C c, tailBudget_tendsto_zero hC.ne hc, ?_⟩ + intro N s hsL hsU v ell hell + exact weighted_tail_of_inverse_bands _ v ell (fun R hR => hb s hsL hsU v R ell hR hell) hc N + +end NumberTheoryLean.EvenInverseBands + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/EvenThresholdVolume.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EvenThresholdVolume.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d4bc87ab526ce156baaa28c7a14d0f4b8f33e10 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/EvenThresholdVolume.lean @@ -0,0 +1,75 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.EvenThresholdGeometry + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosEvenThreshold +open Set MeasureTheory NumberTheoryLean.FinitePathGeometry + +theorem cover_width_bound {R d : ℝ} (hR : 4 < R) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) : + 0 ≤ firstUpper R d-2 ∧ 0 ≤ secondUpper R d-secondLower R ∧ + (firstUpper R d-2)+(secondUpper R d-secondLower R) ≤ 20*d/R := by + have hR0 : 0 < R := by linarith + have hA : 0 < R-2 := by linarith + have hB : 0 < R-2-d := by linarith + have he : secondUpper R d-secondLower R=2*R*d/((R-2)*(R-2-d)) := by + unfold secondUpper secondLower + field_simp + ring + have hprod : R^2/8 ≤ (R-2)*(R-2-d) := by + have ha : R/2 ≤ R-2 := by linarith + have hb : R/4 ≤ R-2-d := by linarith + have hh := mul_le_mul ha hb (by linarith : 0 ≤ R/4) hA.le + nlinarith only [hh] + have hlength : secondUpper R d-secondLower R ≤ 16*d/R := by + rw [he] + apply (div_le_div_iff₀ (mul_pos hA hB) hR0).mpr + have hh := mul_le_mul_of_nonneg_left hprod (show 0 ≤ 16*d by positivity) + nlinarith only [hh] + refine ⟨?_,?_,?_⟩ + · unfold firstUpper + have hh : 0 ≤ 4*d/R := by positivity + linarith + · rw [he] + positivity + · have hf : firstUpper R d-2=4*d/R := by unfold firstUpper; ring + rw [hf] + calc + _ ≤ 4*d/R+16*d/R := add_le_add le_rfl hlength + _ = _ := by ring + +theorem thresholdStrip_measurable (R d : ℝ) : MeasurableSet (thresholdStrip R d) := by + have hx : Measurable (fun t : ℝ => nextExponent R t) := by unfold nextExponent; fun_prop + have hs : Measurable (thresholdSlack R) := by unfold thresholdSlack nextGap nextExponent; fun_prop + exact measurableSet_Ici.inter ((measurableSet_lt measurable_const hx).inter + ((measurableSet_le measurable_const hs).inter (measurableSet_le hs measurable_const))) + +theorem thresholdStrip_empty {R d : ℝ} (hR : R ≤ 4) (hd1 : d ≤ 1) : thresholdStrip R d=∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro t ht + exact (not_lt_of_ge hR) (strip_parameters hd1 ht).1 + +theorem thresholdStrip_volume {R d : ℝ} (_hR : 0 < R) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) : + volume (thresholdStrip R d) ≤ ENNReal.ofReal (20*d/R) := by + by_cases hR4 : 4 < R + · have hwidth := cover_width_bound hR4 hd0 hd1 + calc + _ ≤ volume (Icc 2 (firstUpper R d) ∪ Icc (secondLower R) (secondUpper R d)) := + measure_mono (fun _ ht => strip_mem_cover hd0 hd1 ht) + _ ≤ volume (Icc 2 (firstUpper R d))+volume (Icc (secondLower R) (secondUpper R d)) := measure_union_le _ _ + _ = ENNReal.ofReal ((firstUpper R d-2)+(secondUpper R d-secondLower R)) := by + rw [Real.volume_Icc,Real.volume_Icc,ENNReal.ofReal_add hwidth.1 hwidth.2.1] + _ ≤ _ := ENNReal.ofReal_le_ofReal hwidth.2.2 + · rw [thresholdStrip_empty (le_of_not_gt hR4) hd1,measure_empty] + exact bot_le + +end ErdosEvenThreshold + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FactorDividesAbscissa.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FactorDividesAbscissa.lean new file mode 100644 index 0000000000000000000000000000000000000000..86a530f23127c6204ab8d05b6f09704f2b4ff6cb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FactorDividesAbscissa.lean @@ -0,0 +1,465 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Harmonic.LinearPolynomialForm +import OAI.NumberTheory.Jacobsthal.Sieve.DivisorLogGrowth + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosInverseIncidence +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def bit {α β : Type*} (R : α → β → Prop) (a : α) (p : β) : ℝ := if R a p then 1 else 0 +noncomputable def degree {α β : Type*} (P : Finset β) (R : α → β → Prop) (a : α) : ℕ := + (P.filter (R a)).card +noncomputable def multiplicity {α β : Type*} (A : Finset α) (R : α → β → Prop) (p : β) : ℝ := + ∑ a ∈ A, bit R a p + +theorem bit_nonneg {α β : Type*} (R : α → β → Prop) (a : α) (p : β) : 0 ≤ bit R a p := by + unfold bit + split_ifs <;> norm_num + +theorem sum_bit {α β : Type*} (P : Finset β) (R : α → β → Prop) (a : α) : + (∑ p ∈ P,bit R a p) = (degree P R a : ℝ) := by + exact Finset.sum_boole (R a) P + +theorem sum_bit_product {α β : Type*} (P : Finset β) (R : α → β → Prop) (a b : α) : + (∑ p ∈ P,bit R a p*bit R b p) = ((P.filter (fun p => R a p ∧ R b p)).card : ℝ) := by + have h (p : β) : bit R a p*bit R b p = if R a p ∧ R b p then (1 : ℝ) else 0 := by + by_cases ha : R a p <;> by_cases hb : R b p <;> simp [bit,ha,hb] + simp_rw [h] + exact Finset.sum_boole _ _ + +theorem multiplicity_sum {α β : Type*} (A : Finset α) (P : Finset β) (R : α → β → Prop) : + (∑ p ∈ P,multiplicity A R p) = ∑ a ∈ A,(degree P R a : ℝ) := by + unfold multiplicity + rw [Finset.sum_comm] + simp_rw [sum_bit] + +theorem multiplicity_square_sum {α β : Type*} (A : Finset α) (P : Finset β) (R : α → β → Prop) : + (∑ p ∈ P,(multiplicity A R p)^2) = + ∑ a ∈ A,∑ b ∈ A,((P.filter (fun p => R a p ∧ R b p)).card : ℝ) := by + have h (p : β) : (multiplicity A R p)^2 = ∑ a ∈ A,∑ b ∈ A,bit R a p*bit R b p := by + unfold multiplicity + rw [pow_two,Finset.sum_mul] + simp_rw [Finset.mul_sum] + simp_rw [h] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_comm] + simp_rw [sum_bit_product] + +theorem multiplicity_square_upper {α β : Type*} (A : Finset α) (P : Finset β) + (R : α → β → Prop) {K : ℝ} (hK : 0 ≤ K) + (hpair : ∀ a ∈ A, ∀ b ∈ A, a ≠ b → + ((P.filter (fun p => R a p ∧ R b p)).card : ℝ) ≤ K) : + (∑ p ∈ P,(multiplicity A R p)^2) ≤ (A.card : ℝ)*(P.card : ℝ)+K*(A.card : ℝ)^2 := by + rw [multiplicity_square_sum] + calc + _ ≤ ∑ a ∈ A,∑ b ∈ A,((if b=a then (P.card : ℝ) else 0)+K) := by + apply Finset.sum_le_sum + intro a ha + apply Finset.sum_le_sum + intro b hb + by_cases hab : b=a + · rw [ite_eq_left hab] + have hc : ((P.filter (fun p => R a p ∧ R b p)).card : ℝ) ≤ P.card := by + exact_mod_cast Finset.card_filter_le P (fun p => R a p ∧ R b p) + linarith + · rw [ite_eq_right hab,zero_add] + exact hpair a ha b hb (Ne.symm hab) + _ = _ := by + simp only [Finset.sum_add_distrib,Finset.sum_ite_eq',Finset.sum_const,nsmul_eq_mul] + have he : (∑ a ∈ A,if a ∈ A then (P.card : ℝ) else 0) = (A.card : ℝ)*(P.card : ℝ) := by + simp + rw [he] + ring + +theorem dense_incidence_card_bound {α β : Type*} (A : Finset α) (P : Finset β) + (R : α → β → Prop) {c K : ℝ} (hc : 0 < c) (hK : 0 ≤ K) (hP : 0 < P.card) + (hdense : ∀ a ∈ A,c*(P.card : ℝ) ≤ (degree P R a : ℝ)) + (hpair : ∀ a ∈ A, ∀ b ∈ A, a ≠ b → + ((P.filter (fun p => R a p ∧ R b p)).card : ℝ) ≤ K) + (hlarge : 2*K ≤ c^2*(P.card : ℝ)) : (A.card : ℝ) ≤ 2/c^2 := by + let M : ℝ := A.card + let N : ℝ := P.card + have hN : 0 < N := by dsimp [N]; exact_mod_cast hP + have hM0 : 0 ≤ M := Nat.cast_nonneg _ + have hlow : M*c*N ≤ ∑ p ∈ P,multiplicity A R p := by + rw [multiplicity_sum] + calc + _ = ∑ _a ∈ A,c*N := by simp [M]; ring + _ ≤ _ := Finset.sum_le_sum hdense + have hcs : (∑ p ∈ P,multiplicity A R p)^2 ≤ N*(∑ p ∈ P,(multiplicity A R p)^2) := by + simpa only [one_mul,one_pow,Finset.sum_const,nsmul_eq_mul,mul_one] using + Finset.sum_mul_sq_le_sq_mul_sq P (fun _ => (1 : ℝ)) (multiplicity A R) + have hup := multiplicity_square_upper A P R hK hpair + have hchain : (M*c*N)^2 ≤ N*(M*N+K*M^2) := + (pow_le_pow_left₀ (by positivity) hlow 2).trans + (hcs.trans (mul_le_mul_of_nonneg_left hup hN.le)) + have hmain : M^2*c^2*N ≤ M*N+K*M^2 := by + have hscaled : (M^2*c^2*N)*N ≤ (M*N+K*M^2)*N := by + convert hchain using 1 <;> ring + exact le_of_mul_le_mul_right hscaled hN + have hKm : 2*K*M^2 ≤ c^2*N*M^2 := mul_le_mul_of_nonneg_right hlarge (sq_nonneg M) + have hMN : M^2*c^2 ≤ 2*M := by + have hscaled : (M^2*c^2)*N ≤ (2*M)*N := by nlinarith only [hmain,hKm] + exact le_of_mul_le_mul_right hscaled hN + change M ≤ 2/c^2 + by_cases hm : M=0 + · rw [hm] + positivity + · have hMp : 0 < M := lt_of_le_of_ne hM0 (Ne.symm hm) + apply (le_div_iff₀ (sq_pos_of_pos hc)).mpr + have hscaled : (M*c^2)*M ≤ 2*M := by convert hMN using 1; ring + exact le_of_mul_le_mul_right hscaled hMp + +end ErdosInverseIncidence + +end + +section + +namespace ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +noncomputable def aligns (a : ℕ → ℤ) (q : ℚ) (p : ℕ) : Prop := + (q.den : ZMod p) * (a p : ZMod p) = (q.num : ZMod p) + +theorem aligns_iff_modEq (a : ℕ → ℤ) (q : ℚ) (p : ℕ) : + aligns a q p ↔ Int.ModEq (p : ℤ) ((q.den : ℤ)*a p) q.num := by + rw [← ZMod.intCast_eq_intCast_iff] + simp only [aligns,Int.cast_mul,Int.cast_natCast] + +theorem aligned_prime_not_dvd_den (a : ℕ → ℤ) (q : ℚ) {p : ℕ} + (hp : p.Prime) (hq : aligns a q p) : ¬p ∣ q.den := by + intro hd + have hd0 : (q.den : ZMod p) = 0 := (ZMod.natCast_eq_zero_iff _ _).mpr hd + have hn0 : (q.num : ZMod p) = 0 := by + change (q.den : ZMod p)*(a p : ZMod p) = (q.num : ZMod p) at hq + simpa only [hd0,zero_mul] using hq.symm + have hn : p ∣ q.num.natAbs := Int.natCast_dvd.mp ((ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp hn0) + have hg := Nat.dvd_gcd hn hd + rw [q.reduced.gcd_eq_one] at hg + exact hp.not_dvd_one hg + +def determinant (q r : ℚ) : ℤ := q.num*(r.den : ℤ)-r.num*(q.den : ℤ) + +theorem determinant_ne_zero {q r : ℚ} (hqr : q ≠ r) : determinant q r ≠ 0 := by + intro h + apply hqr + apply Rat.eq_iff_mul_eq_mul.mpr + exact sub_eq_zero.mp h + +theorem common_alignment_dvd (a : ℕ → ℤ) (q r : ℚ) (p : ℕ) + (hq : aligns a q p) (hr : aligns a r p) : (p : ℤ) ∣ determinant q r := by + apply (ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp + have he : ((determinant q r : ℤ) : ZMod p) = + (q.num : ZMod p)*(r.den : ZMod p)-(r.num : ZMod p)*(q.den : ZMod p) := by + simp only [determinant,Int.cast_sub,Int.cast_mul,Int.cast_natCast] + rw [he,← hq,← hr] + ring + +noncomputable def commonAligners (P : Finset ℕ) (a : ℕ → ℤ) (q r : ℚ) : Finset ℕ := + P.filter (fun p => aligns a q p ∧ aligns a r p) + +theorem commonAligners_le_divisors (P : Finset ℕ) (a : ℕ → ℤ) {q r : ℚ} (hqr : q ≠ r) : + (commonAligners P a q r).card ≤ (determinant q r).natAbs.divisors.card := by + apply Finset.card_le_card + intro p hp + obtain ⟨_,hq,hr⟩ := Finset.mem_filter.mp hp + apply Nat.mem_divisors.mpr + exact ⟨Int.natCast_dvd.mp (common_alignment_dvd a q r p hq hr), + Int.natAbs_ne_zero.mpr (determinant_ne_zero hqr)⟩ + +theorem determinant_height (q r : ℚ) (HA HD : ℕ) + (hqa : q.num.natAbs ≤ HA) (hra : r.num.natAbs ≤ HA) + (hqd : q.den ≤ HD) (hrd : r.den ≤ HD) : + (determinant q r).natAbs ≤ 2*HA*HD := by + calc + _ ≤ (q.num*(r.den : ℤ)).natAbs+(r.num*(q.den : ℤ)).natAbs := Int.natAbs_sub_le _ _ + _ = q.num.natAbs*r.den+r.num.natAbs*q.den := by + rw [Int.natAbs_mul,Int.natAbs_mul,Int.natAbs_natCast,Int.natAbs_natCast] + _ ≤ HA*HD+HA*HD := add_le_add (Nat.mul_le_mul hqa hrd) (Nat.mul_le_mul hra hqd) + _ = _ := by ring + +theorem commonAligners_subpower {eps : ℝ} (heps : 0 < eps) : + ∃ B : ℝ, 0 < B ∧ ∀ (P : Finset ℕ) (a : ℕ → ℤ) (HA HD : ℕ) (q r : ℚ), + q ≠ r → q.num.natAbs ≤ HA → r.num.natAbs ≤ HA → q.den ≤ HD → r.den ≤ HD → + ((commonAligners P a q r).card : ℝ) ≤ B*((2*HA*HD : ℕ) : ℝ)^eps := by + obtain ⟨B,hB,hdiv⟩ := ErdosDivisorBounds.divisor_subpower heps + refine ⟨B,hB,?_⟩ + intro P a HA HD q r hqr hqa hra hqd hrd + have hn : 1 ≤ (determinant q r).natAbs := Nat.one_le_iff_ne_zero.mpr + (Int.natAbs_ne_zero.mpr (determinant_ne_zero hqr)) + have hh := determinant_height q r HA HD hqa hra hqd hrd + calc + _ ≤ ((determinant q r).natAbs.divisors.card : ℝ) := by exact_mod_cast commonAligners_le_divisors P a hqr + _ ≤ B*((determinant q r).natAbs : ℝ)^eps := hdiv _ hn + _ ≤ _ := mul_le_mul_of_nonneg_left + (Real.rpow_le_rpow (Nat.cast_nonneg _) (by exact_mod_cast hh) heps.le) hB.le + +end ErdosInverseAlignment + +end + +section + +namespace ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +noncomputable def heightCandidates (HA HD : ℕ) : Finset ℚ := + (((Finset.Icc (-(HA : ℤ)) (HA : ℤ)).product (Finset.Icc 1 HD)).image + (fun z : ℤ × ℕ => (z.1 : ℚ)/(z.2 : ℚ))).filter + (fun q => q.num.natAbs ≤ HA ∧ q.den ≤ HD) + +theorem mem_heightCandidates (HA HD : ℕ) (q : ℚ) : + q ∈ heightCandidates HA HD ↔ q.num.natAbs ≤ HA ∧ q.den ≤ HD := by + constructor + · intro h + exact (Finset.mem_filter.mp h).2 + · rintro ⟨ha,hd⟩ + apply Finset.mem_filter.mpr + refine ⟨?_,ha,hd⟩ + apply Finset.mem_image.mpr + refine ⟨(q.num,q.den),?_,?_⟩ + · apply Finset.mem_product.mpr + have habs : |q.num| ≤ (HA : ℤ) := by + rw [← Int.natCast_natAbs] + exact_mod_cast ha + exact ⟨Finset.mem_Icc.mpr (abs_le.mp habs), + Finset.mem_Icc.mpr ⟨q.den_pos,hd⟩⟩ + · exact q.num_div_den + +noncomputable def rationalList (P : Finset ℕ) (a : ℕ → ℤ) (HA HD : ℕ) (c : ℝ) : Finset ℚ := + (heightCandidates HA HD).filter + (fun q => c*(P.card : ℝ) ≤ ((P.filter (aligns a q)).card : ℝ)) + +theorem mem_rationalList (P : Finset ℕ) (a : ℕ → ℤ) (HA HD : ℕ) (c : ℝ) (q : ℚ) : + q ∈ rationalList P a HA HD c ↔ + q.num.natAbs ≤ HA ∧ q.den ≤ HD ∧ + c*(P.card : ℝ) ≤ ((P.filter (aligns a q)).card : ℝ) := by + simp only [rationalList,Finset.mem_filter,mem_heightCandidates,and_assoc] + +theorem rational_list_card_subpower {eps : ℝ} (heps : 0 < eps) : + ∃ B : ℝ, 0 < B ∧ ∀ (P : Finset ℕ) (a : ℕ → ℤ) (HA HD : ℕ) (c : ℝ), + 0 < c → 0 < P.card → + 2*(B*((2*HA*HD : ℕ) : ℝ)^eps) ≤ c^2*(P.card : ℝ) → + ((rationalList P a HA HD c).card : ℝ) ≤ 2/c^2 := by + obtain ⟨B,hB,hpair⟩ := commonAligners_subpower heps + refine ⟨B,hB,?_⟩ + intro P a HA HD c hc hP hlarge + apply ErdosInverseIncidence.dense_incidence_card_bound + (rationalList P a HA HD c) P (fun q p => aligns a q p) + hc (show 0 ≤ B*((2*HA*HD : ℕ) : ℝ)^eps by positivity) hP + · intro q hq + exact (mem_rationalList P a HA HD c q).mp hq |>.2.2 + · intro q hq r hr hqr + obtain ⟨hqa,hqd,_⟩ := (mem_rationalList P a HA HD c q).mp hq + obtain ⟨hra,hrd,_⟩ := (mem_rationalList P a HA HD c r).mp hr + exact hpair P a HA HD q r hqr hqa hra hqd hrd + · exact hlarge + +end ErdosInverseAlignment + +end + +section + +namespace ErdosRichLine +open ErdosCriticalGeometry + +theorem linear_y_coefficient_ne_zero (F : MV ℂ) (hdeg : F.totalDegree = 1) + (p q : ℤ × ℤ) (hx : p.1 ≠ q.1) + (hp : MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0) + (hq : MvPolynomial.eval ![(q.1 : ℂ),(q.2 : ℂ)] F = 0) : + F.coeff (Finsupp.single 1 1) ≠ 0 := by + intro ha + rw [linear_polynomial_eval F hdeg.le,ha,zero_mul,add_zero] at hp hq + have hprod : F.coeff (Finsupp.single 0 1)*((p.1 : ℂ)-(q.1 : ℂ)) = 0 := by + linear_combination hp-hq + have hdx : (p.1 : ℂ)-(q.1 : ℂ) ≠ 0 := sub_ne_zero.mpr (by exact_mod_cast hx) + have hb := (mul_eq_zero.mp hprod).resolve_right hdx + have hc : F.coeff 0 = 0 := by simpa [hb] using hp + have hF : F = 0 := by rw [linear_polynomial_form F hdeg.le,hc,hb,ha];simp + rw [hF,MvPolynomial.totalDegree_zero] at hdeg + contradiction + +theorem linear_integer_cross_product (F : MV ℂ) (hdeg : F.totalDegree = 1) + (p q : ℤ × ℤ) (hx : p.1 ≠ q.1) + (hp : MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0) + (hq : MvPolynomial.eval ![(q.1 : ℂ),(q.2 : ℂ)] F = 0) + (r : ℤ × ℤ) (hr : MvPolynomial.eval ![(r.1 : ℂ),(r.2 : ℂ)] F = 0) : + (q.1-p.1)*(r.2-p.2) = (q.2-p.2)*(r.1-p.1) := by + have ha := linear_y_coefficient_ne_zero F hdeg p q hx hp hq + rw [linear_polynomial_eval F hdeg.le] at hp hq hr + have he : ((q.1 : ℂ)-(p.1 : ℂ))*((r.2 : ℂ)-(p.2 : ℂ)) = + ((q.2 : ℂ)-(p.2 : ℂ))*((r.1 : ℂ)-(p.1 : ℂ)) := by + apply mul_left_cancel₀ ha + linear_combination ((q.1 : ℂ)-(p.1 : ℂ))*(hr-hp)- + ((r.1 : ℂ)-(p.1 : ℂ))*(hq-hp) + exact_mod_cast he + +end ErdosRichLine + +end + +section + +namespace ErdosRichLine +open ErdosCriticalGeometry + +structure PrimitiveIntegerLine where + denominator : ℕ + slope : ℤ + intercept : ℤ + denominator_pos : 0 < denominator + reduced : Nat.Coprime slope.natAbs denominator + +def PrimitiveIntegerLine.Contains (l : PrimitiveIntegerLine) (p : ℤ × ℤ) : Prop := + (l.denominator : ℤ)*p.2 = l.slope*p.1+l.intercept + +theorem primitive_line_from_cross_products (p q : ℤ × ℤ) (hx : p.1 ≠ q.1) : + ∃ l : PrimitiveIntegerLine, ∀ r : ℤ × ℤ, + (q.1-p.1)*(r.2-p.2) = (q.2-p.2)*(r.1-p.1) → l.Contains r := by + let s : ℚ := ((q.2-p.2 : ℤ) : ℚ)/((q.1-p.1 : ℤ) : ℚ) + let l : PrimitiveIntegerLine := + ⟨s.den,s.num,(s.den : ℤ)*p.2-s.num*p.1,s.den_pos,s.reduced⟩ + have hdx : q.1-p.1 ≠ 0 := sub_ne_zero.mpr (Ne.symm hx) + have hdxQ : ((q.1-p.1 : ℤ) : ℚ) ≠ 0 := by exact_mod_cast hdx + have hdQ : (s.den : ℚ) ≠ 0 := by exact_mod_cast s.den_ne_zero + have hratio : (s.num : ℚ)/(s.den : ℚ) = ((q.2-p.2 : ℤ) : ℚ)/((q.1-p.1 : ℤ) : ℚ) := + s.num_div_den + have hmulQ := (div_eq_div_iff hdQ hdxQ).mp hratio + have hmul : s.num*(q.1-p.1) = (q.2-p.2)*(s.den : ℤ) := by exact_mod_cast hmulQ + refine ⟨l,?_⟩ + intro r hr + change (s.den : ℤ)*r.2 = s.num*r.1+((s.den : ℤ)*p.2-s.num*p.1) + apply mul_left_cancel₀ hdx + linear_combination (s.den : ℤ)*hr-(r.1-p.1)*hmul + +theorem primitive_line_of_polynomial (F : MV ℂ) (hdeg : F.totalDegree = 1) + (p q : ℤ × ℤ) (hx : p.1 ≠ q.1) + (hp : MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0) + (hq : MvPolynomial.eval ![(q.1 : ℂ),(q.2 : ℂ)] F = 0) : + ∃ l : PrimitiveIntegerLine, ∀ r : ℤ × ℤ, + MvPolynomial.eval ![(r.1 : ℂ),(r.2 : ℂ)] F = 0 → l.Contains r := by + obtain ⟨l,hl⟩ := primitive_line_from_cross_products p q hx + exact ⟨l,fun r hr => hl r (linear_integer_cross_product F hdeg p q hx hp hq r hr)⟩ + +end ErdosRichLine + +end + +section + +namespace ErdosPrimitiveIntercept +open ErdosRichLine + +structure InterceptReduction (l : PrimitiveIntegerLine) where + rational : ℚ + factor : ℕ + factor_pos : 0 < factor + denominator_eq : l.denominator = factor*rational.den + intercept_eq : l.intercept = (factor : ℤ)*rational.num + +theorem exists_intercept_reduction (l : PrimitiveIntegerLine) : Nonempty (InterceptReduction l) := by + let g : ℕ := Int.gcd l.intercept (l.denominator : ℤ) + have hd : (0 : ℤ) < l.denominator := by exact_mod_cast l.denominator_pos + have hg : 0 < g := Int.gcd_pos_of_ne_zero_right _ (ne_of_gt hd) + obtain ⟨A,D,hcop,hA,hD⟩ := Int.exists_gcd_one hg + have hgZ : (0 : ℤ) < g := by exact_mod_cast hg + have hDpos : 0 < D := by nlinarith + have hDt : (D.toNat : ℤ) = D := Int.toNat_of_nonneg hDpos.le + have hDn : 0 < D.toNat := by omega + have hred : Nat.Coprime A.natAbs D.toNat := by + have hh : Int.gcd A (D.toNat : ℤ) = 1 := by rwa [hDt] + simpa only [Int.gcd_def,Int.natAbs_natCast,Nat.Coprime] using hh + let r : ℚ := Rat.mk' A D.toNat hDn.ne' hred + have hden : l.denominator = g*r.den := by + change l.denominator = g*D.toNat + have hh : (l.denominator : ℤ) = (g : ℤ)*(D.toNat : ℤ) := by rw [hDt];nlinarith [hD] + exact_mod_cast hh + have hint : l.intercept = (g : ℤ)*r.num := by + change l.intercept = (g : ℤ)*A + nlinarith [hA] + exact ⟨⟨r,g,hg,hden,hint⟩⟩ + +theorem InterceptReduction.rational_value {l : PrimitiveIntegerLine} (r : InterceptReduction l) : + r.rational = (l.intercept : ℚ)/(l.denominator : ℚ) := by + rw [r.intercept_eq,r.denominator_eq,Int.cast_mul,Nat.cast_mul] + have hg : (r.factor : ℚ) ≠ 0 := by exact_mod_cast r.factor_pos.ne' + change r.rational = (r.factor : ℚ)*(r.rational.num : ℚ)/((r.factor : ℚ)*(r.rational.den : ℚ)) + rw [mul_div_mul_left _ _ hg] + exact r.rational.num_div_den.symm + +end ErdosPrimitiveIntercept + +end + +section + +namespace ErdosRichLine +open ErdosCriticalGeometry ErdosComplexCurveFactors + +theorem exists_rich_primitive_line (P : MV ℂ) (hP : P ≠ 0) (D : ℕ) (hD : P.totalDegree ≤ D) + (S : ℝ) (hS : 0 ≤ S) (X : Finset (ℤ × ℤ)) (hX : X ⊆ complexSquarePoints P S) + (hinj : Set.InjOn Prod.fst (X : Set (ℤ × ℤ))) (M : ℝ) (hM : 1 ≤ M) + (hlarge : 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+(D : ℝ)*M < (X.card : ℝ)) : + ∃ (F : MV ℂ) (l : PrimitiveIntegerLine), + Irreducible F ∧ F ∣ P ∧ F.totalDegree = 1 ∧ + M < ((X ∩ complexSquarePoints F S).card : ℝ) ∧ + ∀ r ∈ X ∩ complexSquarePoints F S, l.Contains r := by + classical + obtain ⟨F,hF,hFP,hdeg,hcount⟩ := exists_rich_linear_factor P hP D hD S hS X hX M + (le_trans zero_le_one hM) hlarge + have htwo : 1 < (X ∩ complexSquarePoints F S).card := by exact_mod_cast lt_of_le_of_lt hM hcount + obtain ⟨p,hp,q,hq,hpq⟩ := Finset.one_lt_card.mp htwo + have hx : p.1 ≠ q.1 := fun he => hpq (hinj (Finset.mem_inter.mp hp).1 (Finset.mem_inter.mp hq).1 he) + have hpz := ((mem_complexSquarePoints F S p).mp (Finset.mem_inter.mp hp).2).2 + have hqz := ((mem_complexSquarePoints F S q).mp (Finset.mem_inter.mp hq).2).2 + obtain ⟨l,hl⟩ := primitive_line_of_polynomial F hdeg p q hx hpz hqz + refine ⟨F,l,hF,hFP,hdeg,hcount,?_⟩ + intro r hr + exact hl r (((mem_complexSquarePoints F S r).mp (Finset.mem_inter.mp hr).2).2) + +end ErdosRichLine + +end + +section + +namespace ErdosPrimitiveIntercept +open ErdosRichLine + +theorem InterceptReduction.factor_dvd_denominator {l : PrimitiveIntegerLine} (r : InterceptReduction l) : + r.factor ∣ l.denominator := ⟨r.rational.den,r.denominator_eq⟩ + +theorem InterceptReduction.factor_dvd_abscissa {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (p : ℤ × ℤ) (hp : l.Contains p) : (r.factor : ℤ) ∣ p.1 := by + have hd : (r.factor : ℤ) ∣ (l.denominator : ℤ) := by exact_mod_cast r.factor_dvd_denominator + have hb : (r.factor : ℤ) ∣ l.intercept := ⟨r.rational.num,r.intercept_eq⟩ + have hax : (r.factor : ℤ) ∣ l.slope*p.1 := by + have hh := dvd_sub (dvd_mul_of_dvd_left hd p.2) hb + have he : (l.denominator : ℤ)*p.2-l.intercept = l.slope*p.1 := by + unfold PrimitiveIntegerLine.Contains at hp + linarith + rwa [he] at hh + have hcop : Nat.Coprime r.factor l.slope.natAbs := + l.reduced.symm.of_dvd_left r.factor_dvd_denominator + have hg : Int.gcd (r.factor : ℤ) l.slope = 1 := by + simpa only [Int.gcd_def,Int.natAbs_natCast] using hcop.gcd_eq_one + exact Int.dvd_of_dvd_mul_right_of_gcd_one hax hg + +end ErdosPrimitiveIntercept + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FiniteMonotoneComparison.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FiniteMonotoneComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5fc3510d774958ce910d601c2142026ad4c7889 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FiniteMonotoneComparison.lean @@ -0,0 +1,85 @@ +import Mathlib.Data.Finset.Max +import Mathlib.MeasureTheory.Integral.Layercake +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.FiniteMonotoneComparison + +open Filter Set Finset MeasureTheory +open scoped ENNReal + + theorem finite_level_bound (μ ν : Measure ℝ) (A : Finset ℝ) (f : ℝ → ℝ) (a M t : ℝ) (E : ℝ≥0∞) + (hsupport : ∀ᵐ x ∂μ, x ∈ A) (hloc : ∀ x ∈ A, a ≤ x) + (hanti : AntitoneOn f (Ici a)) (hM : ∀ x ∈ A, f x ≤ M) + (hcdf : ∀ x ∈ A, μ (Icc a x) ≤ ν (Icc a x) + E) : + μ {x | t < f x} ≤ ν {x | t < f x} + (Iio M).indicator (fun _ => E) t := by + classical + let B := A.filter (fun x => t < f x) + by_cases hB : B.Nonempty + · let x := B.max' hB + have hxB : x ∈ B := B.max'_mem hB + have hx : x ∈ A := (Finset.mem_filter.mp hxB).1 + have htx : t < f x := (Finset.mem_filter.mp hxB).2 + have htM : t < M := htx.trans_le (hM x hx) + rw [indicator_of_mem (show t ∈ Iio M from htM)] + have hμ : μ {y | t < f y} ≤ μ (Icc a x) := by + apply measure_mono_ae + filter_upwards [hsupport] with y hy + intro hyt + exact ⟨hloc y hy, B.le_max' y (Finset.mem_filter.mpr ⟨hy,hyt⟩)⟩ + have hν : ν (Icc a x) ≤ ν {y | t < f y} := by + apply measure_mono + intro y hy + exact htx.trans_le (hanti hy.1 (hloc x hx) hy.2) + exact hμ.trans ((hcdf x hx).trans (add_le_add hν le_rfl)) + · have hz : μ {x | t < f x} = 0 := by + have hAE : ∀ᵐ x ∂μ, ¬ t < f x := by + filter_upwards [hsupport] with x hx + intro hxt + exact hB ⟨x, Finset.mem_filter.mpr ⟨hx,hxt⟩⟩ + simpa only [ae_iff, not_not] using hAE + rw [hz] + exact zero_le + +theorem level_measure_measurable (ν : Measure ℝ) (f : ℝ → ℝ) : + Measurable (fun t : ℝ => ν {x | t < f x}) := by + have h : Antitone (fun t : ℝ => ν {x | t < f x}) := by + intro s t hst + apply measure_mono + intro x hx + exact hst.trans_lt hx + exact h.measurable + +theorem finite_monotone_integral_le (μ ν : Measure ℝ) (A : Finset ℝ) (f : ℝ → ℝ) (a M : ℝ) (E : ℝ≥0∞) + (hf : Measurable f) (hsupport : ∀ᵐ x ∂μ, x ∈ A) (hloc : ∀ x ∈ A, a ≤ x) + (hnonneg : ∀ x ∈ A, 0 ≤ f x) (hνnonneg : 0 ≤ᵐ[ν] f) + (hanti : AntitoneOn f (Ici a)) (hM : ∀ x ∈ A, f x ≤ M) + (hcdf : ∀ x ∈ A, μ (Icc a x) ≤ ν (Icc a x) + E) : + (∫⁻ x, ENNReal.ofReal (f x) ∂μ) ≤ (∫⁻ x, ENNReal.ofReal (f x) ∂ν) + E * ENNReal.ofReal M := by + have hμnonneg : 0 ≤ᵐ[μ] f := hsupport.mono (fun x hx => hnonneg x hx) + rw [lintegral_eq_lintegral_meas_lt μ hμnonneg hf.aemeasurable, + lintegral_eq_lintegral_meas_lt ν hνnonneg hf.aemeasurable] + calc + _ ≤ ∫⁻ t in Ioi (0 : ℝ), ν {x | t < f x} + (Iio M).indicator (fun _ => E) t := + lintegral_mono (fun t => finite_level_bound μ ν A f a M t E hsupport hloc hanti hM hcdf) + _ = (∫⁻ t in Ioi (0 : ℝ), ν {x | t < f x}) + + ∫⁻ t in Ioi (0 : ℝ), (Iio M).indicator (fun _ => E) t := + lintegral_add_left (level_measure_measurable ν f) _ + _ = _ := by + rw [lintegral_indicator measurableSet_Iio, lintegral_const, Measure.restrict_apply_univ, + Measure.restrict_apply measurableSet_Iio] + have hi : Iio M ∩ Ioi (0 : ℝ) = Ioo 0 M := by ext t; simp only [Set.mem_inter_iff, Set.mem_Iio, Set.mem_Ioi, Set.mem_Ioo]; tauto + rw [hi, Real.volume_Ioo, sub_zero] + +end NumberTheoryLean.FiniteMonotoneComparison + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FinitePairOccurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FinitePairOccurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..75514ab453047e1a254382bd58b39741ceae6afd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FinitePairOccurrence.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Probability.FiniteHistoryPairLaw + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.FinitePairOccurrence +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open FiniteHistoryTransport FiniteHistoryOccurrence FiniteHistoryPairLaw + +variable {X : Type*} [MeasurableSpace X] + +noncomputable def pairOccurrence (E : Set (X×X)) (N : ℕ) : Set (Hist X N) := + ⋃ j : Fin N,(fun h => adjacentPair N h j) ⁻¹' E + +theorem pairOccurrence_measurable {E : Set (X×X)} (hE : MeasurableSet E) (N : ℕ) : + MeasurableSet (pairOccurrence E N) := MeasurableSet.iUnion (fun j => (adjacentPair_measurable N j) hE) + +theorem pair_occurrence_lintegral_bound (K : Kernel X X) [IsMarkovKernel K] + {E : Set (X×X)} (hE : MeasurableSet E) (N : ℕ) (h₀ : Hist X 0) : + pathKernel K N h₀ (pairOccurrence E N) ≤ + ∫⁻ h,∑ j : Fin N,pairProbability K E (atIndex N h j.castSucc) ∂pathKernel K N h₀ := by + apply (measure_iUnion_fintype_le _ (fun j : Fin N => (fun h => adjacentPair N h j) ⁻¹' E)).trans_eq + simp_rw [adjacent_pair_probability K hE N h₀] + symm + apply lintegral_finsetSum + intro j _ + have hc : Measurable (fun h : Hist X N => atIndex N h j.castSucc) := measurable_pi_apply _ + exact (pairProbability_measurable K hE).comp hc + +theorem pair_occurrence_of_budget (K : Kernel X X) [IsMarkovKernel K] + {E : Set (X×X)} (hE : MeasurableSet E) (N : ℕ) (h₀ : Hist X 0) + (g : X → ℝ) (hg : ∀ x,0 ≤ g x) (C : ℝ) + (hrow : ∀ x,pairProbability K E x ≤ ENNReal.ofReal (g x)) + (hbudget : ∀ᵐ h ∂pathKernel K N h₀,(∑ j : Fin N,g (atIndex N h j.castSucc)) ≤ C) : + pathKernel K N h₀ (pairOccurrence E N) ≤ ENNReal.ofReal C := by + calc + _ ≤ ∫⁻ h,∑ j : Fin N,pairProbability K E (atIndex N h j.castSucc) ∂pathKernel K N h₀ := + pair_occurrence_lintegral_bound K hE N h₀ + _ ≤ ∫⁻ h,ENNReal.ofReal (∑ j : Fin N,g (atIndex N h j.castSucc)) ∂pathKernel K N h₀ := by + apply lintegral_mono + intro h + change (∑ j : Fin N,pairProbability K E (atIndex N h j.castSucc)) ≤ + ENNReal.ofReal (∑ j : Fin N,g (atIndex N h j.castSucc)) + rw [ENNReal.ofReal_sum_of_nonneg (fun (j : Fin N) (_ : j ∈ Finset.univ) => hg (atIndex N h j.castSucc))] + exact Finset.sum_le_sum (fun j _ => hrow _) + _ ≤ ∫⁻ _h : Hist X N,ENNReal.ofReal C ∂pathKernel K N h₀ := + lintegral_mono_ae (hbudget.mono (fun h hh => ENNReal.ofReal_le_ofReal hh)) + _ = _ := by simp + +theorem pair_occurrence_of_uniform_row (K : Kernel X X) [IsMarkovKernel K] + {E : Set (X×X)} (hE : MeasurableSet E) (N : ℕ) (h₀ : Hist X 0) + {A : ℝ} (hA : 0 ≤ A) (hrow : ∀ x,pairProbability K E x ≤ ENNReal.ofReal A) : + pathKernel K N h₀ (pairOccurrence E N) ≤ ENNReal.ofReal ((N:ℝ)*A) := by + apply pair_occurrence_of_budget K hE N h₀ (fun _ => A) (fun _ => hA) ((N:ℝ)*A) hrow + exact Filter.Eventually.of_forall (fun _ => by simp) +end NumberTheoryLean.FinitePairOccurrence + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FiniteSampleSpace.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FiniteSampleSpace.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b1d16f3e4863c1e8211da641102689804e1e26c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FiniteSampleSpace.lean @@ -0,0 +1,71 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseSampling +attribute [local instance] Classical.decEq + +abbrev Sample {α : Type*} (U : Finset α) (h : ℕ) := Fin h ↪ U + +noncomputable def goodSamples {α : Type*} (U W : Finset α) (h : ℕ) : Finset (Sample U h) := by + classical + exact Finset.univ.filter (fun e => ∀ i, (e i).val ∈ W) + +noncomputable def goodSampleEquiv {α : Type*} (U W : Finset α) (hWU : W ⊆ U) (h : ℕ) : + (goodSamples U W h) ≃ Sample W h where + toFun e := + { toFun := fun i => ⟨(e.val i).val,(Finset.mem_filter.mp e.property).2 i⟩ + inj' := by + intro i j he + apply e.val.injective + exact Subtype.ext (congrArg (fun x : W => x.val) he) } + invFun f := + ⟨{ toFun := fun i => ⟨(f i).val,hWU (f i).property⟩ + inj' := by + intro i j he + apply f.injective + exact Subtype.ext (congrArg (fun x : U => x.val) he) },by + classical + apply Finset.mem_filter.mpr + exact ⟨Finset.mem_univ _,fun i => (f i).property⟩⟩ + left_inv e := by + apply Subtype.ext + apply Function.Embedding.ext + intro i + apply Subtype.ext + rfl + right_inv f := by + apply Function.Embedding.ext + intro i + apply Subtype.ext + rfl + +theorem sample_card {α : Type*} (U : Finset α) (h : ℕ) : + Fintype.card (Sample U h) = U.card.descFactorial h := by + classical + simp only [Sample,Fintype.card_embedding_eq,Fintype.card_fin,Fintype.card_coe] + +theorem goodSamples_card {α : Type*} (U W : Finset α) (hWU : W ⊆ U) (h : ℕ) : + (goodSamples U W h).card = W.card.descFactorial h := by + classical + have hh := Fintype.card_congr (goodSampleEquiv U W hWU h) + simpa only [Fintype.card_coe,sample_card] using hh + +noncomputable def sampleFrequency {α : Type*} (U W : Finset α) (h : ℕ) : ℝ := + ((goodSamples U W h).card : ℝ)/(Fintype.card (Sample U h) : ℝ) + +theorem sampleFrequency_eq {α : Type*} (U W : Finset α) (hWU : W ⊆ U) (h : ℕ) : + sampleFrequency U W h = (W.card.descFactorial h : ℝ)/(U.card.descFactorial h : ℝ) := by + rw [sampleFrequency,goodSamples_card U W hWU,sample_card] + +end ErdosInverseSampling + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FirstIsolatedPosition.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FirstIsolatedPosition.lean new file mode 100644 index 0000000000000000000000000000000000000000..daa35c695a8107a68f0b87e57272a88bc0462fa6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FirstIsolatedPosition.lean @@ -0,0 +1,42 @@ +import OAI.NumberTheory.Jacobsthal.Paths.GeometricRegularWords + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.FirstIsolatedPosition +open PrimeHistories GeometricRegularWords IsolatedBinGeometry +open LogarithmicBinScale LogarithmicBinLabels + + +theorem first_matching_position {α : Type*} (P : α → Prop) (ps : List α) + (hex : ∃ p ∈ ps,P p) : ∃ pre p tail,ps=pre++p::tail ∧ P p ∧ ∀ q ∈ pre,¬P q := by + classical + induction ps with + | nil => simp at hex + | cons p ps ih => + by_cases hp : P p + · exact ⟨[],p,ps,rfl,hp,by simp⟩ + · have ht : ∃ q ∈ ps,P q := by + obtain ⟨q,hq,hP⟩ := hex + rcases List.mem_cons.mp hq with rfl | hq + · exact False.elim (hp hP) + · exact ⟨q,hq,hP⟩ + obtain ⟨pre,q,tail,he,hq,hpre⟩ := ih ht + exact ⟨p::pre,q,tail,by rw [List.cons_append,he],hq,by simpa using And.intro hp hpre⟩ + +theorem geometric_first_isolated {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) (ps : List ℕ) + (hp : ps ∈ geometricWords hw htop hxi C B R L alpha beta z) : + ∃ pre p tail,ps=pre++p::tail ∧ + isolatedBin w top xi B alpha beta (label (zero_lt_one.trans hw) htop hxi p) ∧ + ∀ q ∈ pre,¬isolatedBin w top xi B alpha beta (label (zero_lt_one.trans hw) htop hxi q) := + first_matching_position _ ps (geometric_isolated_prime hw htop hxi z ps hp) +end NumberTheoryLean.FirstIsolatedPosition + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FirstOmissionAntichain.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FirstOmissionAntichain.lean new file mode 100644 index 0000000000000000000000000000000000000000..158d8f7122350ee925d8a35f20987bf00729533b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FirstOmissionAntichain.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Primes.BoundaryPrimeMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferencePruning +open FinitePathGeometry ReferenceAdmission + +theorem admitted_prefix {w r : ℝ} {i : Side} {pre whole : List ℕ} + (hpre : pre <+: whole) (hwhole : admitted w i r whole) : admitted w i r pre := by + obtain ⟨suf,he⟩ := hpre + rw [← he,admitted_append] at hwhole + exact hwhole.1 + +theorem proper_prefix_admitted {w r : ℝ} {i : Side} {pre whole : List ℕ} + (hfirst : FirstOmitted w i r whole) (hpre : pre <+: whole) + (hlen : pre.length < whole.length) : admitted w i r pre := by + obtain ⟨parent,p,he,hparent,_⟩ := hfirst + have hpar : parent <+: whole := ⟨[p],he.symm⟩ + have hlen' : pre.length ≤ parent.length := by + rw [he,List.length_append,List.length_singleton] at hlen + omega + exact admitted_prefix (List.prefix_of_prefix_length_le hpre hpar hlen') hparent + +theorem first_omission_antichain {w r : ℝ} {i : Side} {pre whole : List ℕ} + (hp : FirstOmitted w i r pre) (hq : FirstOmitted w i r whole) + (hpre : pre <+: whole) : pre = whole := by + by_contra hne + have hlenle := hpre.length_le + have hlenne : pre.length ≠ whole.length := fun h => hne (hpre.eq_of_length h) + have hlen : pre.length < whole.length := by omega + exact firstOmitted_not_admitted hp (proper_prefix_admitted hq hpre hlen) + +theorem first_omission_prefix_unique {w r : ℝ} {i : Side} {p q whole : List ℕ} + (hp : FirstOmitted w i r p) (hq : FirstOmitted w i r q) + (hpref : p <+: whole) (hqref : q <+: whole) : p = q := by + rcases List.prefix_or_prefix_of_prefix hpref hqref with h | h + · exact first_omission_antichain hp hq h + · exact (first_omission_antichain hq hp h).symm + +end NumberTheoryLean.ReferencePruning + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FrozenSuffixData.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FrozenSuffixData.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f04e0de3910ac0cb02bfe6d6497395f889c2a0e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FrozenSuffixData.lean @@ -0,0 +1,65 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualNearFullStopGroup + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.FrozenSuffixData +open PrimeHistories StoppedVertexHistory StoppedCountVertex ReferencePruning + +theorem suffixPrimes_replacement (P : Finset ℕ) (pre tail : List ℕ) (p p' : ℕ) + (htail : tail ≠ []) (hD : (pre++p::tail).Pairwise (· > ·)) + (hD' : (pre++p'::tail).Pairwise (· > ·)) : + suffixPrimes P (pre++p::tail)=suffixPrimes P (pre++p'::tail) := by + cases tail with + | nil => exact False.elim (htail rfl) + | cons u us => + have forward (p p' : ℕ) (hD' : (pre++p'::u::us).Pairwise (· > ·)) + (q : ℕ) (hA : ∀ r ∈ pre++p::u::us,q ⟨forward p p' hD' q,forward p' p hD q⟩) + +theorem after_available_replacement (w : ℝ) (v : Vertex) (pre tail : List ℕ) (p p' : ℕ) + (htail : tail ≠ []) (hD : (pre++p::tail).Pairwise (· > ·)) + (hD' : (pre++p'::tail).Pairwise (· > ·)) : + (after w v (pre++p::tail)).available=(after w v (pre++p'::tail)).available := by + rw [after_available,after_available] + exact suffixPrimes_replacement v.available pre tail p p' htail hD hD' + +theorem terminal_suffix_cutoff (w : ℝ) (z z' : Node) (tail : List ℕ) (htail : tail ≠ []) : + (terminal w z tail).cutoff=(terminal w z' tail).cutoff ∧ + (terminal w z tail).closed=false ∧ (terminal w z' tail).closed=false := by + induction tail generalizing z z' with + | nil => exact False.elim (htail rfl) + | cons p ps ih => + cases ps with + | nil => simp [terminal,step] + | cons q qs => exact ih (step w z p) (step w z' p) (by simp) + +theorem replacement_cutoff (w : ℝ) (z : Node) (pre tail : List ℕ) (p p' : ℕ) (htail : tail ≠ []) : + (terminal w z (pre++p::tail)).cutoff=(terminal w z (pre++p'::tail)).cutoff ∧ + (terminal w z (pre++p::tail)).closed=false ∧ + (terminal w z (pre++p'::tail)).closed=false := by + rw [show pre++p::tail=(pre++[p])++tail by simp,show pre++p'::tail=(pre++[p'])++tail by simp] + rw [terminal_append w z (pre++[p]) tail,terminal_append w z (pre++[p']) tail] + exact terminal_suffix_cutoff w _ _ tail htail +end NumberTheoryLean.FrozenSuffixData + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullEndpointData.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullEndpointData.lean new file mode 100644 index 0000000000000000000000000000000000000000..46b7d68cb282a31df20bd0b3e5467652a9ec0abb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullEndpointData.lean @@ -0,0 +1,434 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawBoxRationalWitness +import OAI.NumberTheory.Jacobsthal.Probability.FullBoxVarianceGeometry +import OAI.NumberTheory.Jacobsthal.Sieve.EndpointCofactorSplit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosVarianceEffective +open ErdosInverseCells + +noncomputable def effectiveSize (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (R : ℝ) : ℝ := + max (effectiveModulus a r qf : ℝ) (|(effectiveIntercept a r qf : ℝ)|/R) + +theorem effective_ratio_identity (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) (R : ℝ) : + |(effectiveIntercept a r qf : ℝ)|/(R*(effectiveModulus a r qf : ℝ)) = + |(hitNumerator a r qf : ℝ)|/(R*(r.den : ℝ)*(qf : ℝ)) := by + let qa := alignedCofactor (fun t => (a t : ℤ)) r qf + have hqa : (0 : ℝ) < qa := by exact_mod_cast alignedCofactor_pos _ r qf hq + have he : (qa : ℝ)*(effectiveIntercept a r qf : ℝ) = (hitNumerator a r qf : ℝ) := by + exact_mod_cast effectiveIntercept_identity a r qf hq + have hnum : |(hitNumerator a r qf : ℝ)| = (qa : ℝ)*|(effectiveIntercept a r qf : ℝ)| := by + rw [← he,abs_mul,abs_of_pos hqa] + have hden : R*(r.den : ℝ)*(qf : ℝ) = (qa : ℝ)*(R*(effectiveModulus a r qf : ℝ)) := by + have hh : (r.den : ℝ)*(qf : ℝ) = (qa : ℝ)*(effectiveModulus a r qf : ℝ) := by + exact_mod_cast denominator_full_cofactor a r qf hq + linear_combination R*hh + rw [hnum,hden] + exact (mul_div_mul_left _ _ hqa.ne').symm + +theorem effective_ratio_upper (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) (R : ℝ) + (hR : 0 < R) : + |(effectiveIntercept a r qf : ℝ)|/(R*(effectiveModulus a r qf : ℝ)) ≤ + 1/R+|(r.num : ℝ)|/(R*(r.den : ℝ)*(qf : ℝ)) := by + rw [effective_ratio_identity a r qf hq R] + have hD : (0 : ℝ) < r.den := by exact_mod_cast r.pos + have hqR : (0 : ℝ) < qf := by exact_mod_cast Nat.pos_of_ne_zero hq.ne_zero + have hb : (cofactorHit qf a : ℝ) ≤ qf := by exact_mod_cast (cofactorHit_spec qf hq a).2.1 + have hn : |(hitNumerator a r qf : ℝ)| ≤ (r.den : ℝ)*(qf : ℝ)+|(r.num : ℝ)| := by + have hh := abs_sub ((r.den : ℝ)*(cofactorHit qf a : ℝ)) (r.num : ℝ) + have hpos : 0 ≤ (r.den : ℝ)*(cofactorHit qf a : ℝ) := by positivity + simp only [abs_of_nonneg hpos] at hh + have hb' := mul_le_mul_of_nonneg_left hb hD.le + simpa only [hitNumerator,Int.cast_sub,Int.cast_mul,Int.cast_natCast] using + hh.trans (add_le_add hb' le_rfl) + calc + _ ≤ ((r.den : ℝ)*(qf : ℝ)+|(r.num : ℝ)|)/(R*(r.den : ℝ)*(qf : ℝ)) := + div_le_div_of_nonneg_right hn (by positivity) + _ = _ := by field_simp + +theorem effective_size_ratio_le (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hqf : Squarefree qf) + (q : ℕ) (hq : 0 < q) (hqqf : q ≤ qf) (Sq R Z : ℝ) + (_hSq : 0 ≤ Sq) (hR : 1 ≤ R) (hZ : 2 ≤ Z) + (hSqratio : Sq/(q : ℝ) ≤ Z) (hA : |(r.num : ℝ)| ≤ Sq*R*Z^10) : + effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ Z^12 := by + have hRp : 0 < R := by linarith + have hqp : (0 : ℝ) < q := by exact_mod_cast hq + have hH : (0 : ℝ) < effectiveModulus a r qf := by exact_mod_cast effectiveModulus_pos a r qf + have hD : (1 : ℝ) ≤ r.den := by exact_mod_cast r.pos + have hqqfR : (q : ℝ) ≤ qf := by exact_mod_cast hqqf + have hqD : (q : ℝ) ≤ (r.den : ℝ)*(qf : ℝ) := by + have hh := mul_le_mul_of_nonneg_right hD (Nat.cast_nonneg qf : (0 : ℝ) ≤ qf) + nlinarith + have hnum : |(r.num : ℝ)|/(R*(r.den : ℝ)*(qf : ℝ)) ≤ (Sq/(q : ℝ))*Z^10 := by + calc + _ ≤ |(r.num : ℝ)|/(R*(q : ℝ)) := div_le_div_of_nonneg_left (abs_nonneg _) + (by positivity) (by nlinarith [mul_le_mul_of_nonneg_left hqD hRp.le]) + _ ≤ (Sq*R*Z^10)/(R*(q : ℝ)) := div_le_div_of_nonneg_right hA (by positivity) + _ = _ := by field_simp + have hpow : 1 ≤ Z^11 := one_le_pow₀ (by linarith) + have hZ12 : 1+Z^11 ≤ Z^12 := by + calc + _ ≤ 2*Z^11 := by linarith + _ ≤ Z*Z^11 := mul_le_mul_of_nonneg_right hZ (by positivity) + _ = _ := by ring + have hratio : |(effectiveIntercept a r qf : ℝ)|/(R*(effectiveModulus a r qf : ℝ)) ≤ Z^12 := by + calc + _ ≤ 1/R+|(r.num : ℝ)|/(R*(r.den : ℝ)*(qf : ℝ)) := effective_ratio_upper a r qf hqf R hRp + _ ≤ 1+(Sq/(q : ℝ))*Z^10 := add_le_add (div_le_self (by norm_num) hR) hnum + _ ≤ 1+Z*Z^10 := add_le_add le_rfl (mul_le_mul_of_nonneg_right hSqratio (show 0 ≤ Z^10 by positivity)) + _ = 1+Z^11 := by ring + _ ≤ _ := hZ12 + apply (div_le_iff₀ hH).mpr + apply max_le + · have h1 : 1 ≤ Z^12 := by linarith [hZ12,pow_nonneg (by linarith : (0 : ℝ) ≤ Z) 11] + nlinarith + · have hh := (div_le_iff₀ hH).mp (show (|(effectiveIntercept a r qf : ℝ)|/R)/(effectiveModulus a r qf : ℝ) ≤ Z^12 by + simpa only [div_div] using hratio) + exact hh + +end ErdosVarianceEffective + + + +namespace ErdosVarianceEffective +open ErdosInverseAlignment ErdosPrimitiveIntercept ErdosInverseCells + +theorem denominator_le_effectiveModulus (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) : + r.den ≤ effectiveModulus a r qf := by + have hE := badPrimeProduct_pos (fun t => (a t : ℤ)) r qf + dsimp [effectiveModulus] + nlinarith + +theorem nonaligned_le_effectiveModulus (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) : + badPrimeProduct (fun t => (a t : ℤ)) r qf ≤ effectiveModulus a r qf := by + have hD := r.pos + dsimp [effectiveModulus] + nlinarith + +theorem alignedCofactor_le_full (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + alignedCofactor (fun t => (a t : ℤ)) r qf ≤ qf := by + apply Nat.le_of_dvd (Nat.pos_of_ne_zero hq.ne_zero) + exact ⟨badPrimeProduct (fun t => (a t : ℤ)) r qf,(alignedCofactor_mul_bad _ r qf hq).symm⟩ + +theorem soft_effective_bounds (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (R B : ℝ) (hR : 0 < R) + (hsoft : effectiveSize a r qf R ≤ B) : + (r.den : ℝ) ≤ B ∧ (badPrimeProduct (fun t => (a t : ℤ)) r qf : ℝ) ≤ B ∧ + |(effectiveIntercept a r qf : ℝ)| ≤ R*B := by + have hH : (effectiveModulus a r qf : ℝ) ≤ B := (le_max_left _ _).trans hsoft + have hC : |(effectiveIntercept a r qf : ℝ)|/R ≤ B := (le_max_right _ _).trans hsoft + refine ⟨?_,?_,?_⟩ + · have hh : (r.den : ℝ) ≤ effectiveModulus a r qf := by exact_mod_cast denominator_le_effectiveModulus a r qf + exact hh.trans hH + · have hh : (badPrimeProduct (fun t => (a t : ℤ)) r qf : ℝ) ≤ effectiveModulus a r qf := by + exact_mod_cast nonaligned_le_effectiveModulus a r qf + exact hh.trans hH + · have hh := (div_le_iff₀ hR).mp hC + nlinarith + +theorem large_factor_aligns_of_soft (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (R B : ℝ) (hR : 0 < R) + (hsoft : effectiveSize a r qf R ≤ B) (t : ℕ) (ht : t ∈ qf.primeFactors) (hlarge : B < (t : ℝ)) : + aligns (fun u => (a u : ℤ)) r t := by + classical + by_contra hn + have hmem : t ∈ badPrimeFactors (fun u => (a u : ℤ)) r qf := Finset.mem_filter.mpr ⟨ht,hn⟩ + have hd : t ∣ badPrimeProduct (fun u => (a u : ℤ)) r qf := Finset.dvd_prod_of_mem _ hmem + have hle := Nat.le_of_dvd (badPrimeProduct_pos _ r qf) hd + have hleR : (t : ℝ) ≤ badPrimeProduct (fun u => (a u : ℤ)) r qf := by exact_mod_cast hle + have hbound := (soft_effective_bounds a r qf R B hR hsoft).2.1 + linarith + +end ErdosVarianceEffective + + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceSmallModel +open ErdosInversePrimeBin ErdosInverseBoxHeight ErdosVarianceEffective + +theorem source_effective_point_domination (alpha : ℝ) (ha : 0 < alpha) : + ∃ C : ℝ,0 < C ∧ ∀ xi : ℝ,0 < xi → xi ≤ 1 → + ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ),Squarefree qf → + z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + (effectiveModulus a r qf : ℝ) ≤ R^((4 : ℝ)/5) → + effectiveSize a r qf R/(effectiveModulus a r qf : ℝ) ≤ (sourceZ z)^12 → + ∃ (hw : 0 ≤ sourceW z) (hP : ∀ p ∈ primeBin R theta,p.Prime) + (hlarge : ∀ p ∈ primeBin R theta,sourceW z < (p : ℝ)), + ∀ E : ModelPoint (sourceW z) (effectiveModulus a r qf) → Prop, + ((actualPrimeEvent (primeBin R theta) (sourceW z) (effectiveModulus a r qf) + (effectiveIntercept a r qf) hw hP hlarge E).card : ℝ)/((primeBin R theta).card : ℝ) ≤ + C*modelMass R xi (sourceW z) (effectiveModulus a r qf) (effectiveIntercept a r qf) E := by + obtain ⟨C,hC,hdom⟩ := source_prime_model_domination alpha ha + refine ⟨C,hC,?_⟩ + intro xi hxi hxi1 + filter_upwards [hdom xi hxi hxi1] with z hz + intro R theta a r qf hq hRlo htl htu hHsmall hRatio + exact hz R theta (effectiveModulus a r qf) (effectiveIntercept a r qf) + hRlo htl htu (effectiveModulus_pos a r qf) (effective_coordinates_gcd a r qf hq) hHsmall hRatio + +end ErdosVarianceSmallModel + +end + + +namespace ErdosVarianceEffective +open ErdosInverseCells + +theorem actual_numerator_triangle (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + |(r.num : ℝ)| ≤ (r.den : ℝ)*(qf : ℝ)+(qf : ℝ)*|(effectiveIntercept a r qf : ℝ)| := by + have hEq : (alignedCofactor (fun t => (a t : ℤ)) r qf : ℝ)*(effectiveIntercept a r qf : ℝ) = + (r.den : ℝ)*(cofactorHit qf a : ℝ)-(r.num : ℝ) := by + simpa only [hitNumerator,Int.cast_sub,Int.cast_mul,Int.cast_natCast] using + congrArg (fun x : ℤ => (x : ℝ)) (effectiveIntercept_identity a r qf hq) + have hA : (r.num : ℝ) = (r.den : ℝ)*(cofactorHit qf a : ℝ)- + (alignedCofactor (fun t => (a t : ℤ)) r qf : ℝ)*(effectiveIntercept a r qf : ℝ) := by linarith + have hb : (cofactorHit qf a : ℝ) ≤ qf := by exact_mod_cast (cofactorHit_spec qf hq a).2.1 + have hqa : (alignedCofactor (fun t => (a t : ℤ)) r qf : ℝ) ≤ qf := by + exact_mod_cast alignedCofactor_le_full a r qf hq + rw [hA] + calc + _ ≤ |(r.den : ℝ)*(cofactorHit qf a : ℝ)|+ + |(alignedCofactor (fun t => (a t : ℤ)) r qf : ℝ)*(effectiveIntercept a r qf : ℝ)| := abs_sub _ _ + _ = (r.den : ℝ)*(cofactorHit qf a : ℝ)+ + (alignedCofactor (fun t => (a t : ℤ)) r qf : ℝ)*|(effectiveIntercept a r qf : ℝ)| := by + rw [abs_of_nonneg (by positivity : 0 ≤ (r.den : ℝ)*(cofactorHit qf a : ℝ)),abs_mul, + abs_of_nonneg (Nat.cast_nonneg _)] + _ ≤ _ := add_le_add (mul_le_mul_of_nonneg_left hb (Nat.cast_nonneg _)) + (mul_le_mul_of_nonneg_right hqa (abs_nonneg _)) + +theorem soft_global_heights (Y : ℕ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) (hp : 0 < p) (R w Cs : ℝ) (hR : 0 < R) (hRp : R ≤ (p : ℝ)) + (hw : 2 ≤ w) (hY : p*qf ≤ Y) (hsoft : effectiveSize a r qf R ≤ w^Cs) : + (r.den : ℝ) ≤ w^Cs ∧ (r.num.natAbs : ℝ) ≤ (Y : ℝ)*w^(Cs+2) := by + have hb := soft_effective_bounds a r qf R (w^Cs) hR hsoft + have hw0 : 0 < w := by linarith + have hB : 0 ≤ w^Cs := Real.rpow_nonneg hw0.le _ + have hqY : (qf : ℝ) ≤ Y := by + have hh : qf ≤ Y := (by nlinarith : qf ≤ p*qf).trans hY + exact_mod_cast hh + have hRqY : R*(qf : ℝ) ≤ Y := by + have hh := mul_le_mul_of_nonneg_right hRp (Nat.cast_nonneg qf : (0 : ℝ) ≤ qf) + have hi : (p : ℝ)*(qf : ℝ) ≤ Y := by exact_mod_cast hY + exact hh.trans hi + refine ⟨hb.1,?_⟩ + have hA : |(r.num : ℝ)| ≤ 2*(Y : ℝ)*w^Cs := by + have htri := actual_numerator_triangle a r qf hq + have hDq := mul_le_mul_of_nonneg_right hb.1 (Nat.cast_nonneg qf : (0 : ℝ) ≤ qf) + have hCq := mul_le_mul_of_nonneg_left hb.2.2 (Nat.cast_nonneg qf : (0 : ℝ) ≤ qf) + have hqY' := mul_le_mul_of_nonneg_left hqY hB + have hRqY' := mul_le_mul_of_nonneg_left hRqY hB + nlinarith + have hw2 : 2 ≤ w^2 := by nlinarith + have hscale : 2*(Y : ℝ)*w^Cs ≤ (Y : ℝ)*w^(Cs+2) := by + rw [Real.rpow_add hw0,Real.rpow_two] + have hh := mul_le_mul_of_nonneg_left hw2 (mul_nonneg (Nat.cast_nonneg Y : (0 : ℝ) ≤ Y) hB) + nlinarith + simpa only [Nat.cast_natAbs,Int.cast_abs] using hA.trans hscale + +end ErdosVarianceEffective + + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceEffective +open ErdosInverseBoxHeight ErdosInverseEuler ErdosInverseCells ErdosCofactorChoices ErdosPrimitiveIntercept +open NumberTheoryLean.LogarithmicBinScale + +theorem source_effective_heights (Clen Cparent : ℝ) (hClen : 0 ≤ Clen) (hCparent : 0 ≤ Cparent) : + ∀ᶠ z : ℝ in atTop,∀ xi : ℝ,0 < xi → xi ≤ 1 → + ∀ m : Fin (binCount (sourceW z) z xi) → ℕ, + ((∑ i,m i : ℕ) : ℝ) ≤ Clen*Real.log (sourceB z) → + ∀ (a : ℕ → ℕ) (r : ℚ) (q e p : ℕ) (R : ℝ), + q ∈ cofactorChoices (actualBins z xi) m → 0 < e → 0 < p → Squarefree (q*e) → 1 ≤ R → + p*(q*e) ≤ sourceY z → + Real.logb (sourceW z) ((sourceY z : ℝ)/((p : ℝ)*q)) ≤ Cparent → + ((r.den*badPrimeProduct (fun t => (a t : ℤ)) r q : ℕ) : ℝ) ≤ R*(sourceZ z)^10 → + (r.num.natAbs : ℝ) ≤ cofactorScale z xi m*R*(sourceZ z)^10 → + (effectiveModulus a r (q*e) : ℝ) ≤ R*(sourceZ z)^11 ∧ + effectiveSize a r (q*e) R/(effectiveModulus a r (q*e) : ℝ) ≤ (sourceZ z)^12 := by + filter_upwards [source_span_geometry,source_extension_le_Z Cparent hCparent, + source_bin_factor_subpower Clen 1 hClen zero_lt_one,sourceZ_tendsto_atTop.eventually_ge_atTop 2] + with z hspan hext hfactor hZ + intro xi hxi hxi1 m hm a r q e p R hq he hp hqf hR hFinal hParent hStructure hRaw + have hqpos := actual_cofactor_positive hspan.1 hspan.2.1 hxi m q hq + have hqR : (0 : ℝ) < q := by exact_mod_cast hqpos + have heZ := hext p q e hp hqpos he hFinal hParent + refine ⟨effectiveModulus_height_of_extension a r q e hqpos he R (sourceZ z) (by linarith) + (by linarith) hStructure heZ,?_⟩ + have hrange := actual_cofactor_range hspan.1 hspan.2.1 hxi m q hq + have hratio : cofactorScale z xi m/(q : ℝ) ≤ sourceZ z := by + calc + _ ≤ (1+xi)^(∑ i,m i) := by + apply (div_le_iff₀ hqR).mpr + have hh := (div_le_iff₀ (pow_pos (by linarith : 0 < 1+xi) _)).mp hrange.1 + nlinarith + _ ≤ _ := by simpa only [Real.rpow_one] using hfactor xi (∑ i,m i) hxi hxi1 hm + have hqle : q ≤ q*e := by nlinarith + have hA : |(r.num : ℝ)| ≤ cofactorScale z xi m*R*(sourceZ z)^10 := by + simpa only [Nat.cast_natAbs,Int.cast_abs] using hRaw + exact effective_size_ratio_le a r (q*e) hqf q hqpos hqle (cofactorScale z xi m) R (sourceZ z) + (actual_cofactorScale_pos hspan.1 hspan.2.1 hxi m).le hR hZ hratio hA + +end ErdosVarianceEffective + +end + + +namespace ErdosVarianceEffective +open ErdosInverseAlignment + +theorem soft_full_factor_alignment (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) (hp : p.Prime) (halign : aligns (fun t => (a t : ℤ)) r p) + (R B : ℝ) (hR : 0 < R) (hsoft : effectiveSize a r qf R ≤ B) : + ∀ t ∈ (p*qf).primeFactors,B < (t : ℝ) → aligns (fun u => (a u : ℤ)) r t := by + intro t ht hlarge + rw [Nat.primeFactors_mul hp.ne_zero hq.ne_zero,hp.primeFactors] at ht + rcases Finset.mem_union.mp ht with ht | ht + · have he : t = p := Finset.mem_singleton.mp ht + exact he.symm ▸ halign + · exact large_factor_aligns_of_soft a r qf R B hR hsoft t ht hlarge + +theorem soft_endpoint_eligible (Y : ℕ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) (hp : p.Prime) (halign : aligns (fun t => (a t : ℤ)) r p) + (R w Cs : ℝ) (hR : 0 < R) (hRp : R ≤ (p : ℝ)) (hw : 2 ≤ w) + (hY : p*qf ≤ Y) (hsoft : effectiveSize a r qf R ≤ w^Cs) : + (r.den : ℝ) ≤ w^Cs ∧ (r.num.natAbs : ℝ) ≤ (Y : ℝ)*w^(Cs+2) ∧ + ∀ t ∈ (p*qf).primeFactors,Cs < Real.logb w (t : ℝ) → aligns (fun u => (a u : ℤ)) r t := by + have hheight := soft_global_heights Y a r qf hq p hp.pos R w Cs hR hRp hw hY hsoft + refine ⟨hheight.1,hheight.2,?_⟩ + intro t ht hlog + have htpos : (0 : ℝ) < t := by exact_mod_cast Nat.pos_of_mem_primeFactors ht + have hpow : w^Cs < (t : ℝ) := (Real.lt_logb_iff_rpow_lt (by linarith : 1 < w) htpos).mp hlog + exact soft_full_factor_alignment a r qf hq p hp halign R (w^Cs) hR hsoft t ht hpow + +end ErdosVarianceEffective + + +section + +open _root_.Filter +namespace ErdosVarianceEligible +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport + SafeSubsetBoxGeometry BoundedEdgeBins CofactorAllChoiceBounds ParentCofactorChoices ParentTailPartition BinCutSelections + StructuredWitnessOutside EndpointCofactorSplit FullIsolatedCofactor SingletonBinSelection TwoPrimeObservableSum + ErdosCofactorChoices ErdosSubsetWord ErdosVarianceWeighted ErdosVarianceEffective ErdosInverseBoxHeight + ErdosInverseCells ErdosInverseAlignment ErdosPrimitiveIntercept + LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinPartition +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem structured_endpoint_heights (C M : ℝ) (hC : 0 ≤ C) (hM : 0 ≤ M) : + ∀ᶠ top : ℝ in atTop, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → 2*C*xi ≤ 1 → + ∀ (hw : 1 < sourceW top) (htop : sourceW top < top) (K aStar X : ℝ),0 ≤ aStar → + ∀ (z : Node),0 < sourceY top → + z.gap = Real.log (sourceY top : ℝ)/Real.log (sourceW top)-aStar+2 → + Valid z.side z.ratio → Consistent z → StrongState z → z.closed = true → (sourceW top)^z.cutoff = top → + ∀ (m : Fin (binCount (sourceW top) top xi) → ℕ),SafeAnchor hw htop hxi C (sourceB top) K z m → + ∀ f ∈ selections (globalBins (sourceW top) top xi) m, + ∀ (i j : Fin (binCount (sourceW top) top xi)),j < i → m i = 1 → + boundedEdgeBin (sourceW top) top xi (sourceY top) m M X j → + ∀ (residue : ℕ → ℕ) (r : ℚ) (cp : ℝ), + r ∈ sourceRationalList (globalBins (sourceW top) top xi i) (fun t => (residue t : ℤ)) + (cofactorScale top xi (parentCofactorMultiplicity m i j)) (lower (sourceW top) top xi i) (sourceZ top) cp → + ((r.den*badPrimeProduct (fun t => (residue t : ℤ)) r (selectionProduct (parentCofactorSelection f i j)) : ℕ) : ℝ) ≤ + lower (sourceW top) top xi i*(sourceZ top)^10 → + (effectiveModulus residue r (selectionProduct (eraseSelection f i)) : ℝ) ≤ + lower (sourceW top) top xi i*(sourceZ top)^11 ∧ + effectiveSize residue r (selectionProduct (eraseSelection f i)) (lower (sourceW top) top xi i)/ + (effectiveModulus residue r (selectionProduct (eraseSelection f i)) : ℝ) ≤ (sourceZ top)^12 := by + filter_upwards [source_effective_heights C (M+1) hC (by linarith), + Real.tendsto_log_atTop.eventually JacobsthalSourceScale.source_scale_eventually] with top hheights hscale + intro xi hxi hxi1 hDelta hw htop K aStar X ha z hY hroot hs hz hg hclosed hcap m hanchor + f hf i j hji hi hj residue r cp hraw hstructure + let P := globalBins (sourceW top) top xi + let cm := parentCofactorMultiplicity m i j + let p := pickedPrime f i + let q := selectionProduct (parentCofactorSelection f i j) + let e := pickedPrime f j*selectionProduct (belowSelection f j) + let qf := selectionProduct (eraseSelection f i) + let R := lower (sourceW top) top xi i + have hcomp : Real.log (sourceB top) ≤ 2*Real.log (sourceW top) := hscale.2.2.2.2 + have hmj := bounded_edge_singleton m j hj + have hcoords := full_selection_coordinates P m f hf i j hi hmj + have hp : p ∈ P i := hcoords.1 + have hq : q ∈ cofactorChoices (actualBins top xi) cm := hcoords.2.2 + have hppos : 0 < p := (bin_prime_in_source (zero_lt_one.trans hw) htop hxi i hp).1.pos + have he : 0 < e := endpoint_extra_factor_pos hw htop hxi m f hf j hmj + have hsplit : qf = q*e := endpoint_cofactor_split hw htop hxi m f hf i j hji hmj + have hfErase := erase_selection_mem P m f hf i + have hQf := (erased_cofactor_arithmetic hw htop hxi m i (eraseSelection f i) hfErase).1 + have hQsplit : Squarefree (q*e) := hsplit ▸ hQf + have hprod : selectionProduct f = p*qf := isolated_product P m f hf i hi + have hprodPos : 0 < selectionProduct f := by + rw [hprod] + exact Nat.mul_pos hppos (Nat.pos_of_ne_zero hQf.ne_zero) + have htotal := full_box_total_length_lower hw htop hxi hC hcomp (sourceY top) hY z hroot + hs hz hg hclosed hcap m hanchor f hf + have hFinal := product_le_Y_of_length (sourceW top) aStar hw ha (sourceY top) (selectionProduct f) hY hprodPos htotal + rw [hprod,hsplit] at hFinal + have hRlow : sourceW top ≤ R := (bin_source_bounds (zero_lt_one.trans hw) htop hxi i).1 + have hR1 : 1 ≤ R := hw.le.trans hRlow + have hparent := (cofactor_all_choice_lengths hw htop hxi hC hcomp (sourceY top) hY z hroot + hs hz hg hclosed hcap m hanchor i j hji hi hj).1 q hq p hp + have hparentBound : Real.logb (sourceW top) ((sourceY top : ℝ)/((p : ℝ)*q)) ≤ M+1 := + hparent.trans (by linarith) + have hlen := anchor_total_length hw htop hxi z m hanchor + have hcm : ((∑ k,cm k : ℕ) : ℝ) ≤ C*Real.log (sourceB top) := + (Nat.cast_le.mpr (cofactor_total_le m i j)).trans hlen + have hSq := actual_cofactorScale_pos (zero_lt_one.trans hw) htop hxi cm + have hnum := ((mem_sourceRationalList (P i) (fun t => (residue t : ℤ)) hSq.le + (show 0 ≤ R by linarith) r).mp hraw).1 + have hh := hheights xi hxi hxi1 cm hcm residue r q e p R hq he hppos hQsplit hR1 hFinal + hparentBound hstructure hnum + simpa only [← hsplit] using hh + +end ErdosVarianceEligible + +end + + +namespace ErdosVarianceEligible +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport + SafeSubsetBoxGeometry ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection TwoPrimeObservableSum + FullIsolatedCofactor ErdosVarianceWeighted + LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinPartition +attribute [local instance] Classical.propDecidable + +theorem full_endpoint_data {w top xi B C K aStar : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) (ha : 0 ≤ aStar) + (hcomp : Real.log B ≤ 2*Real.log w) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap = Real.log (Y : ℝ)/Real.log w-aStar+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed = true) (hcap : w^z.cutoff = top) + (m : Fin (binCount w top xi) → ℕ) (hanchor : SafeAnchor hw htop hxi C B K z m) + (f : Fin (binCount w top xi) → Finset ℕ) (hf : f ∈ selections (globalBins w top xi) m) + (i : Fin (binCount w top xi)) (hi : m i = 1) : + Squarefree (selectionProduct (eraseSelection f i)) ∧ (pickedPrime f i).Prime ∧ + pickedPrime f i ∈ globalBins w top xi i ∧ + pickedPrime f i*selectionProduct (eraseSelection f i) ≤ Y := by + obtain ⟨p,hp,hfi,_hfill⟩ := singleton_selection_recovery _ m i hi f hf + have hpmem : pickedPrime f i ∈ globalBins w top xi i := by simpa [pickedPrime,hfi] using hp + have hprime := (bin_prime_in_source (zero_lt_one.trans hw) htop hxi i hpmem).1 + have hsq := (erased_cofactor_arithmetic hw htop hxi m i (eraseSelection f i) + (erase_selection_mem _ m f hf i)).1 + have hlen := full_box_total_length_lower hw htop hxi hC hcomp Y hY z hroot hs hz hg hclosed hcap m hanchor f hf + rw [isolated_product _ m f hf i hi] at hlen + refine ⟨hsq,hprime,hpmem,?_⟩ + exact product_le_Y_of_length w aStar hw ha Y _ hY + (Nat.mul_pos hprime.pos (Nat.pos_of_ne_zero hsq.ne_zero)) hlen + +end ErdosVarianceEligible + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullPatternSurvivors.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullPatternSurvivors.lean new file mode 100644 index 0000000000000000000000000000000000000000..1adc988ae5e6db3726717a6027ca779d69a76c31 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullPatternSurvivors.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.FullPatternCoordinates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceMoments +attribute [local instance] Classical.propDecidable + +theorem actualFullPattern_survives (P : Finset ℕ) (w : ℝ) (H qA : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (beta delta : ∀ t : ℕ,ZMod t) + (p : goodPrimes P H) (j : ℕ) : + ErdosLargePatternLaw.survives w H qA beta delta j (actualFullPattern P w H C0 hw hP hlarge p) ↔ + modelSurvives w H C0 qA beta delta j (primePoint P w H C0 hw hP hlarge p) := by + unfold ErdosLargePatternLaw.survives modelSurvives + apply and_congr + · apply forall_congr' + intro t + apply forall_congr' + intro ht + have ht0 : t ∣ divisorModulus w H := Finset.dvd_prod_of_mem _ ht + rw [full_k0_projection P w H C0 hw hP hlarge p t ht0, + full_p0_projection P w H C0 hw hP hlarge p t ht0, + primePoint_kValue P w H C0 hw hP hlarge p t ht0] + change ((primeK P H C0 hP p : ZMod t)+(p.val : ZMod t)*(j : ZMod t) ≠ beta t) ↔ + ((primeK P H C0 hP p : ZMod t)+divisorPhase C0 (primeM P H C0 hP p) t*(j : ZMod t) ≠ beta t) + rw [← prime_divisorPhase_eq P H C0 hP hC0 p t (Finset.mem_filter.mp ht).2] + · apply forall_congr' + intro t + apply forall_congr' + intro ht + have ht1 : t ∣ coprimeModulus w H := Finset.dvd_prod_of_mem _ ht + rw [full_p1_projection P w H C0 hw hP hlarge p t ht1, + full_m1_projection P w H C0 hw hP hlarge p t ht1, + primePoint_pValue P w H C0 hw hP hlarge p t ht1] + rfl + +theorem full_count_eq_common (P : Finset ℕ) (J : ℕ) (w : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) + (hq : Squarefree qf) (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (hQLarge : ∀ t ∈ qf.primeFactors,w < (t : ℝ)) (p : ℕ) [NeZero p] + (hpGood : p ∈ goodPrimes P (ErdosVarianceEffective.effectiveModulus a r qf)) : + ErdosLargePatternLaw.survivorCount w (ErdosVarianceEffective.effectiveModulus a r qf) + (ErdosVarianceEffective.alignedCofactor (fun t => (a t : ℤ)) r qf) J + (actualDivisorTarget a qf) (actualCoprimeTarget a r) + (actualFullPattern P w (ErdosVarianceEffective.effectiveModulus a r qf) + (ErdosVarianceEffective.effectiveIntercept a r qf) hw hP hlarge ⟨p,hpGood⟩) = + (ErdosVarianceCommon.commonSurvivors J w a r qf p (Finset.mem_filter.mp hpGood).2).card := by + unfold ErdosLargePatternLaw.survivorCount + apply congrArg Finset.card + ext j + simp only [Finset.mem_filter,Finset.mem_range,ErdosVarianceCommon.mem_commonSurvivors] + apply and_congr Iff.rfl + exact (actualFullPattern_survives P w _ _ _ hw hP hlarge + (ErdosVarianceEffective.effective_coordinates_gcd a r qf hq) + (actualDivisorTarget a qf) (actualCoprimeTarget a r) ⟨p,hpGood⟩ j).trans + (actual_primePoint_survives P w a r qf hq hw hP hlarge hQLarge p hpGood j) + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullReturnCylinders.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullReturnCylinders.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ef12b0fc5ea692e55768c76f3192ba3622dbc89 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FullReturnCylinders.lean @@ -0,0 +1,125 @@ +import OAI.NumberTheory.Jacobsthal.Paths.HistoryRestrictionAlgebra + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory Function Preorder +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels + +noncomputable def avoidOddReturns (a m b : ℕ) (hab : a+2*m ≤ b) : Set (RawHistory b) := + {h | ∀ j : Fin m, h ⟨a+2*(j.1+1),Finset.mem_Iic.mpr (by have hj := j.2; omega)⟩ ∉ regenerationSet} + +lemma avoidOddReturns_measurable (a m b : ℕ) (hab : a+2*m ≤ b) : + MeasurableSet (avoidOddReturns a m b hab) := by + unfold avoidOddReturns + simp only [ofPred_forall] + apply MeasurableSet.iInter + intro j + exact (regenerationSet_measurable.preimage (measurable_pi_apply _)).compl + +noncomputable def lastRegeneration (b : ℕ) : Set (RawHistory b) := + {h | h ⟨b,by simp⟩ ∈ regenerationSet} + +lemma lastRegeneration_measurable (b : ℕ) : MeasurableSet (lastRegeneration b) := + regenerationSet_measurable.preimage (measurable_pi_apply _) + +noncomputable def survivingHistory (a m : ℕ) : Kernel (RawHistory a) (RawHistory (a+2*m)) := + (rawExtension a (a+2*m)).restrict (avoidOddReturns_measurable a m (a+2*m) le_rfl) + +noncomputable def firstReturnHistory (a n : ℕ) : Kernel (RawHistory a) (RawHistory (a+2*(n+1))) := + (rawExtension a (a+2*(n+1))).restrict + ((avoidOddReturns_measurable a n (a+2*(n+1)) (by omega)).inter (lastRegeneration_measurable _)) + +instance survivingHistory_isFiniteKernel (a m : ℕ) : IsFiniteKernel (survivingHistory a m) := by + unfold survivingHistory + infer_instance + +instance firstReturnHistory_isFiniteKernel (a n : ℕ) : IsFiniteKernel (firstReturnHistory a n) := by + unfold firstReturnHistory + infer_instance + +lemma avoidOddReturns_prefix {a m b c : ℕ} (hab : a+2*m ≤ b) (hbc : b ≤ c) : + rawPrefix hbc ⁻¹' avoidOddReturns a m b hab = avoidOddReturns a m c (hab.trans hbc) := by + rfl + +lemma avoidOddReturns_succ (a n : ℕ) : + avoidOddReturns a (n+1) (a+2*(n+1)) le_rfl = + (rawPrefix (show a+2*n ≤ a+2*(n+1) by omega) ⁻¹' + avoidOddReturns a n (a+2*n) le_rfl) ∩ (lastRegeneration (a+2*(n+1)))ᶜ := by + rw [avoidOddReturns_prefix] + ext h + change (∀ j : Fin (n+1), _ ∉ regenerationSet) ↔ + (∀ j : Fin n, _ ∉ regenerationSet) ∧ _ ∉ regenerationSet + constructor + · intro hh + constructor + · intro j + exact hh j.castSucc + · exact hh (Fin.last n) + · rintro ⟨hh,hlast⟩ j + by_cases hj : j.1 < n + · exact hh ⟨j.1,hj⟩ + · have he : j.1=n := by have hjn := j.2; omega + simpa only [he] using hlast + +theorem survivingHistory_succ (a n : ℕ) : + survivingHistory a (n+1) = + ((rawExtension (a+2*n) (a+2*(n+1))).restrict (lastRegeneration_measurable _).compl) ∘ₖ + survivingHistory a n := by + unfold survivingHistory + have he := rawExtension_restrict_comp (show a ≤ a+2*n by omega) + (show a+2*n ≤ a+2*(n+1) by omega) + (avoidOddReturns_measurable a n (a+2*n) le_rfl) (lastRegeneration_measurable _).compl + rw [← he] + congr 1 + exact avoidOddReturns_succ a n + +theorem firstReturnHistory_eq_capture_after_survival (a n : ℕ) : + firstReturnHistory a n = + ((rawExtension (a+2*n) (a+2*(n+1))).restrict (lastRegeneration_measurable _)) ∘ₖ + survivingHistory a n := by + unfold firstReturnHistory survivingHistory + rw [← rawExtension_restrict_comp (show a ≤ a+2*n by omega) + (show a+2*n ≤ a+2*(n+1) by omega) + (avoidOddReturns_measurable a n (a+2*n) le_rfl) (lastRegeneration_measurable _)] + congr 1 + +lemma firstReturnHistory_ae_cylinder (a n : ℕ) (h : RawHistory a) : + ∀ᵐ z ∂firstReturnHistory a n h, + (∀ j : Fin n, z ⟨a+2*(j.1+1),Finset.mem_Iic.mpr (by have hj := j.2; omega)⟩ ∉ regenerationSet) ∧ + z ⟨a+2*(n+1),by simp⟩ ∈ regenerationSet := by + rw [firstReturnHistory,Kernel.restrict_apply] + exact ae_restrict_mem ((avoidOddReturns_measurable a n (a+2*(n+1)) (by omega)).inter (lastRegeneration_measurable _)) + +lemma firstReturnHistory_retains_past (a n : ℕ) (h : RawHistory a) : + ∀ᵐ z ∂firstReturnHistory a n h, rawPrefix (show a ≤ a+2*(n+1) by omega) z = h := by + rw [firstReturnHistory,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawExtension_retains_prefix (by omega) h) + +noncomputable def firstReturnHistoryWithFirst (a n : ℕ) {E : Set CostState} (hE : MeasurableSet E) : + Kernel (RawHistory a) (RawHistory (a+2*(n+1))) := + (firstReturnHistory a n).restrict (hE.preimage + (measurable_pi_apply (⟨a+1,Finset.mem_Iic.mpr (by omega)⟩ : Finset.Iic (a+2*(n+1))))) + +lemma firstReturnHistoryWithFirst_apply (a n : ℕ) {E : Set CostState} (hE : MeasurableSet E) + (h : RawHistory a) {S : Set (RawHistory (a+2*(n+1)))} (hS : MeasurableSet S) : + firstReturnHistoryWithFirst a n hE h S = rawExtension a (a+2*(n+1)) h + ((S ∩ {z | z ⟨a+1,Finset.mem_Iic.mpr (by omega)⟩ ∈ E}) ∩ + (avoidOddReturns a n (a+2*(n+1)) (by omega) ∩ lastRegeneration _)) := by + rw [firstReturnHistoryWithFirst,Kernel.restrict_apply' _ _ _ hS, + firstReturnHistory,Kernel.restrict_apply' _ _ _ + (hS.inter (hE.preimage (measurable_pi_apply _)))] + rfl + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/FundamentalBlockEstimate.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FundamentalBlockEstimate.lean new file mode 100644 index 0000000000000000000000000000000000000000..35c7b41359117265b043f318369d5c14781ef930 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/FundamentalBlockEstimate.lean @@ -0,0 +1,444 @@ +import Mathlib.Analysis.Complex.ExponentialBounds +import Mathlib.Analysis.SpecialFunctions.Log.Basic +import Mathlib.Analysis.SpecificLimits.Basic +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Primes.PrimeDensityBlocks + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.FundamentalBlockEstimate + +open scoped BigOperators + +theorem product_upper_estimate (B : Finset ℕ) (V U δ : ℕ → ℝ) + (hV : ∀ j ∈ B, 0 < V j) (hUlo : ∀ j ∈ B, V j ≤ U j) + (hUhi : ∀ j ∈ B, U j ≤ (1 + δ j) * V j) : + (∏ j ∈ B, V j) ≤ (∏ j ∈ B, U j) ∧ + (∏ j ∈ B, U j) ≤ (∏ j ∈ B, V j) * Real.exp (∑ j ∈ B, δ j) := by + constructor + · exact Finset.prod_le_prod₀ (fun j hj => (hV j hj).le) hUlo + · calc + (∏ j ∈ B, U j) ≤ ∏ j ∈ B, V j * Real.exp (δ j) := by + apply Finset.prod_le_prod₀ + · intro j hj + exact (hV j hj).le.trans (hUlo j hj) + · intro j hj + apply (hUhi j hj).trans + have h := Real.add_one_le_exp (δ j) + simpa only [mul_comm, add_comm] using mul_le_mul_of_nonneg_left h (hV j hj).le + _ = _ := by rw [Finset.prod_mul_distrib, ← Real.exp_sum] + +theorem correction_upper_estimate (B : Finset ℕ) (V U G δ : ℕ → ℝ) + (hV : ∀ j ∈ B, 0 < V j) (hδ : ∀ j ∈ B, 0 ≤ δ j) + (hUlo : ∀ j ∈ B, V j ≤ U j) (hUhi : ∀ j ∈ B, U j ≤ (1 + δ j) * V j) + (hGhi : ∀ j ∈ B, G j ≤ δ j * V j) : + (∑ j ∈ B, G j * ∏ i ∈ B.erase j, U i) ≤ + (∏ j ∈ B, V j) * (∑ j ∈ B, δ j) * Real.exp (∑ j ∈ B, δ j) := by + classical + have hVP : 0 < ∏ j ∈ B, V j := Finset.prod_pos hV + calc + _ ≤ ∑ j ∈ B, δ j * (∏ i ∈ B, V i) * Real.exp (∑ i ∈ B, δ i) := by + apply Finset.sum_le_sum + intro j hj + have hEraseV : ∀ i ∈ B.erase j, 0 < V i := fun i hi => hV i (Finset.mem_of_mem_erase hi) + have hEraseLo : ∀ i ∈ B.erase j, V i ≤ U i := fun i hi => hUlo i (Finset.mem_of_mem_erase hi) + have hEraseHi : ∀ i ∈ B.erase j, U i ≤ (1 + δ i) * V i := + fun i hi => hUhi i (Finset.mem_of_mem_erase hi) + have hEraseU := (product_upper_estimate (B.erase j) V U δ hEraseV hEraseLo hEraseHi).2 + have hEraseNonneg : 0 ≤ ∏ i ∈ B.erase j, U i := + Finset.prod_nonneg fun i hi => (hEraseV i hi).le.trans (hEraseLo i hi) + have hS : (∑ i ∈ B.erase j, δ i) ≤ ∑ i ∈ B, δ i := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.erase_subset _ _) (fun i hi _ => hδ i hi) + calc + G j * (∏ i ∈ B.erase j, U i) ≤ + (δ j * V j) * ((∏ i ∈ B.erase j, V i) * Real.exp (∑ i ∈ B.erase j, δ i)) := + mul_le_mul (hGhi j hj) hEraseU hEraseNonneg (mul_nonneg (hδ j hj) (hV j hj).le) + _ = δ j * (∏ i ∈ B, V i) * Real.exp (∑ i ∈ B.erase j, δ i) := by + rw [← Finset.mul_prod_erase B V hj] + ring + _ ≤ _ := mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr hS) (mul_nonneg (hδ j hj) hVP.le) + _ = _ := by rw [← Finset.sum_mul, ← Finset.sum_mul]; ring + +theorem exp_sub_one_le_self_mul_exp (S : ℝ) : Real.exp S - 1 ≤ S * Real.exp S := by + have h := mul_le_mul_of_nonneg_left (Real.add_one_le_exp (-S)) (Real.exp_pos S).le + have hexp : Real.exp S * Real.exp (-S) = 1 := by rw [← Real.exp_add]; simp + rw [hexp] at h + nlinarith + +theorem global_relative_error (B : Finset ℕ) (V U G δ : ℕ → ℝ) + (hV : ∀ j ∈ B, 0 < V j) (hδ : ∀ j ∈ B, 0 ≤ δ j) + (hUlo : ∀ j ∈ B, V j ≤ U j) (hUhi : ∀ j ∈ B, U j ≤ (1 + δ j) * V j) + (hGlo : ∀ j ∈ B, 0 ≤ G j) (hGhi : ∀ j ∈ B, G j ≤ δ j * V j) : + |(∏ j ∈ B, U j) / (∏ j ∈ B, V j) - 1| ≤ + (∑ j ∈ B, δ j) * Real.exp (∑ j ∈ B, δ j) ∧ + |((∏ j ∈ B, U j) - ∑ j ∈ B, G j * ∏ i ∈ B.erase j, U i) / + (∏ j ∈ B, V j) - 1| ≤ + (∑ j ∈ B, δ j) * Real.exp (∑ j ∈ B, δ j) := by + have hVP : 0 < ∏ j ∈ B, V j := Finset.prod_pos hV + have hS : 0 ≤ ∑ j ∈ B, δ j := Finset.sum_nonneg hδ + have hE : 0 ≤ (∑ j ∈ B, δ j) * Real.exp (∑ j ∈ B, δ j) := mul_nonneg hS (Real.exp_pos _).le + have hUpper := product_upper_estimate B V U δ hV hUlo hUhi + have hCorr := correction_upper_estimate B V U G δ hV hδ hUlo hUhi hGhi + have hCorr0 : 0 ≤ ∑ j ∈ B, G j * ∏ i ∈ B.erase j, U i := by + apply Finset.sum_nonneg + intro j hj + apply mul_nonneg (hGlo j hj) + apply Finset.prod_nonneg + intro i hi + exact (hV i (Finset.mem_of_mem_erase hi)).le.trans (hUlo i (Finset.mem_of_mem_erase hi)) + have hUpperQlo : 1 ≤ (∏ j ∈ B, U j) / (∏ j ∈ B, V j) := + (le_div_iff₀ hVP).mpr (by simpa using hUpper.1) + have hUpperQhi : (∏ j ∈ B, U j) / (∏ j ∈ B, V j) ≤ Real.exp (∑ j ∈ B, δ j) := + (div_le_iff₀ hVP).mpr (by nlinarith [hUpper.2]) + have hExp := exp_sub_one_le_self_mul_exp (∑ j ∈ B, δ j) + constructor + · rw [abs_le] + constructor <;> nlinarith + · rw [abs_le] + have hLowerQlo : 1 - (∑ j ∈ B, δ j) * Real.exp (∑ j ∈ B, δ j) ≤ + ((∏ j ∈ B, U j) - ∑ j ∈ B, G j * ∏ i ∈ B.erase j, U i) / (∏ j ∈ B, V j) := by + apply (le_div_iff₀ hVP).mpr + nlinarith [hUpper.1] + have hLowerQhi : ((∏ j ∈ B, U j) - ∑ j ∈ B, G j * ∏ i ∈ B.erase j, U i) / + (∏ j ∈ B, V j) ≤ Real.exp (∑ j ∈ B, δ j) := by + apply (div_le_iff₀ hVP).mpr + nlinarith [hUpper.2] + constructor <;> nlinarith + +noncomputable def baseError (m : ℕ) : ℝ := Real.exp (5 * 1532) / (2 : ℝ) ^ (2 * m + 1) + +theorem baseError_nonneg (m : ℕ) : 0 ≤ baseError m := by unfold baseError; positivity + +theorem baseError_add (m t : ℕ) : baseError (m + t) = baseError m * (1 / 4 : ℝ) ^ t := by + unfold baseError + have hidx : 2 * (m + t) + 1 = (2 * m + 1) + 2 * t := by omega + rw [hidx, pow_add, pow_mul, div_pow] + norm_num + field_simp + +theorem sum_scheduled_error_le (m J : ℕ) : + (∑ j ∈ Finset.range (J + 1), baseError (PrimeDensityBlocks.reverseOrder m J j)) ≤ 2 * baseError m := by + simp only [PrimeDensityBlocks.reverseOrder, baseError_add, ← Finset.mul_sum] + rw [Finset.sum_flip] + have hgeom : (∑ j ∈ Finset.range (J + 1), (1 / 4 : ℝ) ^ j) ≤ 2 := by + calc + _ ≤ ∑ j ∈ Finset.range (J + 1), (1 / 2 : ℝ) ^ j := by + apply Finset.sum_le_sum + intro j _ + exact pow_le_pow_left₀ (by norm_num) (by norm_num) j + _ ≤ _ := sum_geometric_two_le _ + simpa only [mul_comm] using mul_le_mul_of_nonneg_left hgeom (baseError_nonneg m) + +theorem six_baseError_le_exp (m : ℕ) (hm : 20000 ≤ m) : + 6 * baseError m ≤ Real.exp (-(m : ℝ) / 2) := by + have hlog2 : (1 / 2 : ℝ) ≤ Real.log 2 := by + have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 2) + norm_num at h + exact h + have hmR : (20000 : ℝ) ≤ m := by exact_mod_cast hm + have hpow : (2 : ℝ) ^ (2 * m + 1) = Real.exp (((2 * m + 1 : ℕ) : ℝ) * Real.log 2) := by + rw [Real.exp_nat_mul, Real.exp_log (by norm_num : (0 : ℝ) < 2)] + have hsix : (6 : ℝ) ≤ Real.exp 5 := by + have h := Real.add_one_le_exp 5 + norm_num at h + exact h + unfold baseError + calc + 6 * (Real.exp (5 * 1532) / (2 : ℝ) ^ (2 * m + 1)) ≤ + Real.exp 5 * (Real.exp (5 * 1532) / (2 : ℝ) ^ (2 * m + 1)) := + mul_le_mul_of_nonneg_right hsix (by positivity) + _ = Real.exp (5 + 5 * 1532 - ((2 * m + 1 : ℕ) : ℝ) * Real.log 2) := by + rw [← mul_div_assoc, ← Real.exp_add, hpow, ← Real.exp_sub] + _ ≤ _ := by + apply Real.exp_le_exp.mpr + have hmul := mul_le_mul_of_nonneg_left hlog2 (Nat.cast_nonneg (2 * m + 1)) + push_cast at hmul ⊢ + nlinarith + +theorem scheduled_global_error_le_exp (m J : ℕ) (hm : 20000 ≤ m) : + (∑ j ∈ Finset.range (J + 1), baseError (PrimeDensityBlocks.reverseOrder m J j)) * + Real.exp (∑ j ∈ Finset.range (J + 1), baseError (PrimeDensityBlocks.reverseOrder m J j)) ≤ + Real.exp (-(m : ℝ) / 2) := by + have hS := sum_scheduled_error_le m J + have hS0 : 0 ≤ ∑ j ∈ Finset.range (J + 1), baseError (PrimeDensityBlocks.reverseOrder m J j) := + Finset.sum_nonneg fun _ _ => baseError_nonneg _ + have hb := six_baseError_le_exp m hm + have he1 : Real.exp (-(m : ℝ) / 2) ≤ 1 := by + apply Real.exp_le_one_iff.mpr + have h := Nat.cast_nonneg (α := ℝ) m + linarith + have hS1 : (∑ j ∈ Finset.range (J + 1), baseError (PrimeDensityBlocks.reverseOrder m J j)) ≤ 1 := by + nlinarith [baseError_nonneg m] + have hexp : Real.exp (∑ j ∈ Finset.range (J + 1), baseError (PrimeDensityBlocks.reverseOrder m J j)) ≤ 3 := + (Real.exp_le_exp.mpr hS1).trans Real.exp_one_lt_three.le + calc + _ ≤ (2 * baseError m) * 3 := mul_le_mul hS hexp (Real.exp_pos _).le (mul_nonneg (by norm_num) (baseError_nonneg m)) + _ = 6 * baseError m := by ring + _ ≤ _ := hb + +noncomputable def blockEuler (P : Finset ℕ) (g : ℕ → ℝ) (j : ℕ) : ℝ := + ∏ p ∈ PrimeDensityBlocks.primeBlock P j, (1 - g p) + +noncomputable def blockUpperDensity (V m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) (j : ℕ) : ℝ := + BonferroniDensity.densityPolynomial (2 * PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V) j) + (PrimeDensityBlocks.primeBlock P j) g + +noncomputable def blockOverflowDensity (V m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) (j : ℕ) : ℝ := + BonferroniDensity.elementarySum (PrimeDensityBlocks.primeBlock P j) g + (2 * PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V) j + 1) + +theorem actual_local_density_inputs (V m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) + (hprime : ∀ p ∈ P, p.Prime) (hg0 : ∀ p ∈ P, 0 ≤ g p) + (hdim : ∀ p ∈ P, g p ≤ 2 / p) (htwo : 2 ∈ P → g 2 ≤ 1 / 2) (j : ℕ) : + 0 < blockEuler P g j ∧ + blockEuler P g j ≤ blockUpperDensity V m P g j ∧ + blockUpperDensity V m P g j ≤ + (1 + baseError (PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V) j)) * blockEuler P g j ∧ + 0 ≤ blockOverflowDensity V m P g j ∧ + blockOverflowDensity V m P g j ≤ + baseError (PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V) j) * blockEuler P g j := by + let Q := PrimeDensityBlocks.primeBlock P j + let t := PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V) j + have hQ0 : ∀ p ∈ Q, 0 ≤ g p := fun p hp => hg0 p (Finset.mem_inter.mp hp).1 + have hcap := BonferroniDensity.prime_density_le_two_thirds P g hprime hdim htwo + have hQ2 : ∀ p ∈ Q, g p ≤ 2 / 3 := fun p hp => hcap p (Finset.mem_inter.mp hp).1 + have hsum : (∑ p ∈ Q, g p) ≤ 1532 := PrimeDensityBlocks.primeBlock_density_sum_le P j g hdim + have heuler := BonferroniDensity.exp_neg_three_mul_le_eulerProduct Q g hQ0 hQ2 hsum + have hpos : 0 < ∏ p ∈ Q, (1 - g p) := (Real.exp_pos _).trans_le heuler + have hrel := BonferroniDensity.densityPolynomial_relative_error Q g hQ0 hQ2 (by norm_num) hsum t + have hbound := BonferroniDensity.densityPolynomial_bounds Q g hQ0 (fun p hp => by linarith [hQ2 p hp]) t + have htail := BonferroniDensity.relative_elementarySum_le_exponential Q g hQ0 hQ2 (by norm_num) hsum (2 * t + 1) + refine ⟨hpos, hbound.2, ?_, BonferroniDensity.elementarySum_nonneg Q g hQ0 _, ?_⟩ + · change BonferroniDensity.densityPolynomial (2 * t) Q g ≤ (1 + baseError t) * (∏ p ∈ Q, (1 - g p)) + apply (div_le_iff₀ hpos).mp + have h := (abs_le.mp hrel.1).2 + change BonferroniDensity.densityPolynomial (2 * t) Q g / (∏ p ∈ Q, (1 - g p)) - 1 ≤ baseError t at h + linarith + · exact (div_le_iff₀ hpos).mp htail + +noncomputable def actualUpperDensity (V m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) : ℝ := + ∑ T ∈ P.powerset, + DisjointBlockExpansion.upperCoefficient (PrimeDensityBlocks.blockIndices V) (PrimeDensityBlocks.primeBlock P) + (PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V)) T * ∏ p ∈ T, g p + +noncomputable def actualLowerDensity (V m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) : ℝ := + ∑ T ∈ P.powerset, PrimeDensityBlocks.actualLowerCoefficient V m P T * ∏ p ∈ T, g p + +theorem actual_global_density_error (V m : ℕ) (P : Finset ℕ) (g : ℕ → ℝ) + (hm : 20000 ≤ m) (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ V) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hdim : ∀ p ∈ P, g p ≤ 2 / p) + (htwo : 2 ∈ P → g 2 ≤ 1 / 2) : + |actualUpperDensity V m P g / (∏ p ∈ P, (1 - g p)) - 1| ≤ Real.exp (-(m : ℝ) / 2) ∧ + |actualLowerDensity V m P g / (∏ p ∈ P, (1 - g p)) - 1| ≤ Real.exp (-(m : ℝ) / 2) := by + let B := PrimeDensityBlocks.blockIndices V + let blocks := PrimeDensityBlocks.primeBlock P + let orders := PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V) + have hdis := PrimeDensityBlocks.primeBlock_pairwise V P + have hunion := PrimeDensityBlocks.primeBlock_union V P hprime hsize + have hloc := actual_local_density_inputs V m P g hprime hg0 hdim htwo + have hglob := global_relative_error B (blockEuler P g) (blockUpperDensity V m P g) + (blockOverflowDensity V m P g) (fun j => baseError (orders j)) + (fun j _ => (hloc j).1) (fun j _ => baseError_nonneg _) (fun j _ => (hloc j).2.1) + (fun j _ => (hloc j).2.2.1) (fun j _ => (hloc j).2.2.2.1) (fun j _ => (hloc j).2.2.2.2) + have hError := scheduled_global_error_le_exp m (PrimeDensityBlocks.lastBlock V) hm + have hEuler : (∏ j ∈ B, blockEuler P g j) = ∏ p ∈ P, (1 - g p) := by + change (∏ j ∈ B, ∏ p ∈ blocks j, (1 - g p)) = _ + rw [← Finset.prod_biUnion hdis, hunion] + have hUpper : actualUpperDensity V m P g = ∏ j ∈ B, blockUpperDensity V m P g j := by + have h := DisjointBlockExpansion.upperCoefficient_density B blocks hdis orders g + rw [hunion] at h + exact h + have hLower : actualLowerDensity V m P g = + (∏ j ∈ B, blockUpperDensity V m P g j) - + ∑ j ∈ B, blockOverflowDensity V m P g j * ∏ i ∈ B.erase j, blockUpperDensity V m P g i := by + have h := DisjointBlockExpansion.lowerCoefficient_density B blocks hdis orders g + rw [hunion] at h + exact h + rw [hUpper, hLower, ← hEuler] + exact ⟨hglob.1.trans hError, hglob.2.trans hError⟩ + +noncomputable def actualUpperCoefficient (V m : ℕ) (P : Finset ℕ) (T : Finset ℕ) : ℝ := + DisjointBlockExpansion.upperCoefficient (PrimeDensityBlocks.blockIndices V) (PrimeDensityBlocks.primeBlock P) + (PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V)) T + +theorem actualUpperCoefficient_support (V m : ℕ) (P : Finset ℕ) (hV : 2 ≤ V) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ V) + {T : Finset ℕ} (hT : T ⊆ P) (hc : actualUpperCoefficient V m P T ≠ 0) : + Squarefree (∏ p ∈ T, p) ∧ (∏ p ∈ T, p) ≤ V ^ (12 * (m + 1)) := by + have hTu : T ⊆ (PrimeDensityBlocks.blockIndices V).biUnion (PrimeDensityBlocks.primeBlock P) := by + simpa only [PrimeDensityBlocks.primeBlock_union V P hprime hsize] using hT + have hbound := DisjointBlockExpansion.prime_product_support (PrimeDensityBlocks.blockIndices V) + (PrimeDensityBlocks.primeBlock P) (PrimeDensityBlocks.primeBlock_pairwise V P) + (fun j => 2 * PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V) j + 1) + (fun j => 2 ^ (2 ^ (j + 1))) (fun j _ => Nat.one_le_pow _ _ (by norm_num)) + (fun j _ p hp => hprime p (Finset.mem_inter.mp hp).1) + (fun j _ p hp => (PrimeDensityBlocks.mem_geometricPrimes.mp (Finset.mem_inter.mp hp).2).2.1.le) + hTu (fun j hj => (DisjointBlockExpansion.upperCoefficient_card hc j hj).trans (Nat.le_succ _)) + exact ⟨hbound.1, hbound.2.trans (PrimeDensityBlocks.supportHeight_product_le V m hV)⟩ + +def levelSubsets (P : Finset ℕ) (L : ℕ) : Finset (Finset ℕ) := + P.powerset.filter fun T => (∏ p ∈ T, p) ≤ L + +theorem coefficient_remainder_level_bound (P : Finset ℕ) (L : ℕ) (coeff E : Finset ℕ → ℝ) + (hc : ∀ T ∈ P.powerset, |coeff T| ≤ 1) + (hlevel : ∀ T ∈ P.powerset, coeff T ≠ 0 → (∏ p ∈ T, p) ≤ L) : + |∑ T ∈ P.powerset, coeff T * E T| ≤ ∑ T ∈ levelSubsets P L, |E T| := by + classical + apply (DisjointBlockExpansion.supported_remainder_bound P coeff E hc).trans + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro T hT + obtain ⟨hTP, hnz⟩ := Finset.mem_filter.mp hT + exact Finset.mem_filter.mpr ⟨hTP, hlevel T hTP hnz⟩ + · intro T _ _ + exact abs_nonneg _ + +theorem additive_bounds_of_relative {D E ε : ℝ} (hE : 0 < E) (h : |D / E - 1| ≤ ε) : + E - E * ε ≤ D ∧ D ≤ E + E * ε := by + obtain ⟨hlo, hhi⟩ := abs_le.mp h + have hDlo : (1 - ε) * E ≤ D := (le_div_iff₀ hE).mp (by linarith) + have hDhi : D ≤ (1 + ε) * E := (div_le_iff₀ hE).mp (by linarith) + constructor <;> nlinarith + +theorem finite_fundamental_lemma {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (hit : ℕ → α → Prop) + (V m : ℕ) (P : Finset ℕ) (X : ℝ) (g : ℕ → ℝ) + (hV : 2 ≤ V) (hm : 20000 ≤ m) (hX : 0 ≤ X) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ V) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hdim : ∀ p ∈ P, g p ≤ 2 / p) + (htwo : 2 ∈ P → g 2 ≤ 1 / 2) : + |(∑ x ∈ C, weight x * BonferroniBlocks.survives P (fun p => hit p x)) - + X * (∏ p ∈ P, (1 - g p))| ≤ + X * (∏ p ∈ P, (1 - g p)) * Real.exp (-(m : ℝ) / 2) + + ∑ T ∈ levelSubsets P (V ^ (12 * (m + 1))), + |BonferroniBlocks.intersectionRemainder C weight hit X g T| := by + let cU := actualUpperCoefficient V m P + let cL := PrimeDensityBlocks.actualLowerCoefficient V m P + let E := BonferroniBlocks.intersectionRemainder C weight hit X g + have hcap := BonferroniDensity.prime_density_le_two_thirds P g hprime hdim htwo + have hEuler : 0 < ∏ p ∈ P, (1 - g p) := Finset.prod_pos (fun p hp => by linarith [hcap p hp]) + have hDensity := actual_global_density_error V m P g hm hprime hsize hg0 hdim htwo + have hUmain := additive_bounds_of_relative hEuler hDensity.1 + have hLmain := additive_bounds_of_relative hEuler hDensity.2 + have hRU := coefficient_remainder_level_bound P (V ^ (12 * (m + 1))) cU E + (fun T _ => DisjointBlockExpansion.upperCoefficient_abs_le _ _ _ _) + (fun T hT hnz => (actualUpperCoefficient_support V m P hV hprime hsize + (Finset.mem_powerset.mp hT) hnz).2) + have hRL := coefficient_remainder_level_bound P (V ^ (12 * (m + 1))) cL E + (fun T _ => DisjointBlockExpansion.lowerCoefficient_abs_le _ _ _ _) + (fun T hT hnz => (PrimeDensityBlocks.actualLowerCoefficient_support V m P hV hprime hsize + (Finset.mem_powerset.mp hT) hnz).2) + have hUdecomp := DisjointBlockExpansion.global_main_remainder C weight hit P cU X g + have hLdecomp := DisjointBlockExpansion.global_main_remainder C weight hit P cL X g + have hcounts := DisjointBlockExpansion.weighted_global_coefficient_bounds C weight hweight hit + (PrimeDensityBlocks.blockIndices V) (PrimeDensityBlocks.primeBlock P) + (PrimeDensityBlocks.primeBlock_pairwise V P) + (PrimeDensityBlocks.reverseOrder m (PrimeDensityBlocks.lastBlock V)) + rw [PrimeDensityBlocks.primeBlock_union V P hprime hsize] at hcounts + change (∑ T ∈ P.powerset, cL T * BonferroniBlocks.intersectionMass C weight hit T) ≤ _ ∧ + _ ≤ (∑ T ∈ P.powerset, cU T * BonferroniBlocks.intersectionMass C weight hit T) at hcounts + rw [hUdecomp, hLdecomp] at hcounts + change X * actualLowerDensity V m P g + (∑ T ∈ P.powerset, cL T * E T) ≤ _ ∧ + _ ≤ X * actualUpperDensity V m P g + (∑ T ∈ P.powerset, cU T * E T) at hcounts + have hLo := mul_le_mul_of_nonneg_left hLmain.1 hX + have hHi := mul_le_mul_of_nonneg_left hUmain.2 hX + have hRLo := (abs_le.mp hRL).1 + have hRHi := (abs_le.mp hRU).2 + rw [abs_le] + constructor <;> nlinarith + +def levelDivisors (P : Finset ℕ) (L : ℕ) : Finset ℕ := + (∏ p ∈ P, p).divisors.filter fun d => d ≤ L + +noncomputable def integerRemainder {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (X : ℝ) (g : ℕ → ℝ) (d : ℕ) : ℝ := + BonferroniBlocks.intersectionRemainder C weight hit X g d.primeFactors + +theorem remainder_sum_eq_divisors {α : Type*} (C : Finset α) (weight : α → ℝ) + (hit : ℕ → α → Prop) (X : ℝ) (g : ℕ → ℝ) (P : Finset ℕ) (L : ℕ) + (hprime : ∀ p ∈ P, p.Prime) : + (∑ T ∈ levelSubsets P L, |BonferroniBlocks.intersectionRemainder C weight hit X g T|) = + ∑ d ∈ levelDivisors P L, |integerRemainder C weight hit X g d| := by + classical + have hsq : Squarefree (∏ p ∈ P, p) := IntervalBoundingSieve.squarefree_primeSet_product P hprime + have hPfac : (∏ p ∈ P, p).primeFactors = P := Nat.primeFactors_prod hprime + apply Finset.sum_bij (fun T _ => ∏ p ∈ T, p) + · intro T hT + obtain ⟨hTP, hTL⟩ := Finset.mem_filter.mp hT + apply Finset.mem_filter.mpr + exact ⟨Nat.mem_divisors.mpr + ⟨Finset.prod_dvd_prod_of_subset T P id (Finset.mem_powerset.mp hTP), hsq.ne_zero⟩, hTL⟩ + · intro T hT U hU hEq + exact DisjointBlockExpansion.prime_product_injective P hprime + (Finset.mem_filter.mp hT).1 (Finset.mem_filter.mp hU).1 hEq + · intro d hd + obtain ⟨hdP, hdL⟩ := Finset.mem_filter.mp hd + have hdiv := Nat.dvd_of_mem_divisors hdP + have hdsq := hsq.squarefree_of_dvd hdiv + have hsub : d.primeFactors ⊆ P := by + rw [← hPfac] + exact Nat.primeFactors_mono hdiv hsq.ne_zero + have hprod : (∏ p ∈ d.primeFactors, p) = d := Nat.prod_primeFactors_of_squarefree hdsq + exact ⟨d.primeFactors, Finset.mem_filter.mpr + ⟨Finset.mem_powerset.mpr hsub, by simpa only [hprod] using hdL⟩, hprod⟩ + · intro T hT + have hTP := Finset.mem_powerset.mp (Finset.mem_filter.mp hT).1 + have hfac : (∏ p ∈ T, p).primeFactors = T := Nat.primeFactors_prod (fun p hp => hprime p (hTP hp)) + simp only [integerRemainder, hfac] + +theorem finite_fundamental_integer_level {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (hit : ℕ → α → Prop) + (V m : ℕ) (P : Finset ℕ) (X : ℝ) (g : ℕ → ℝ) + (hV : 2 ≤ V) (hm : 20000 ≤ m) (hX : 0 ≤ X) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ V) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hdim : ∀ p ∈ P, g p ≤ 2 / p) + (htwo : 2 ∈ P → g 2 ≤ 1 / 2) : + |(∑ x ∈ C, weight x * BonferroniBlocks.survives P (fun p => hit p x)) - + X * (∏ p ∈ P, (1 - g p))| ≤ + X * (∏ p ∈ P, (1 - g p)) * Real.exp (-(m : ℝ) / 2) + + ∑ d ∈ levelDivisors P (V ^ (12 * (m + 1))), |integerRemainder C weight hit X g d| := by + have h := finite_fundamental_lemma C weight hweight hit V m P X g hV hm hX hprime hsize hg0 hdim htwo + rw [remainder_sum_eq_divisors C weight hit X g P _ hprime] at h + exact h + +theorem fundamental_integer_parameter {α : Type*} (C : Finset α) (weight : α → ℝ) + (hweight : ∀ x ∈ C, 0 ≤ weight x) (hit : ℕ → α → Prop) + (V s : ℕ) (P : Finset ℕ) (X : ℝ) (g : ℕ → ℝ) + (hV : 2 ≤ V) (hs : 240012 ≤ s) (hX : 0 ≤ X) + (hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ V) + (hg0 : ∀ p ∈ P, 0 ≤ g p) (hdim : ∀ p ∈ P, g p ≤ 2 / p) + (htwo : 2 ∈ P → g 2 ≤ 1 / 2) : + |(∑ x ∈ C, weight x * BonferroniBlocks.survives P (fun p => hit p x)) - + X * (∏ p ∈ P, (1 - g p))| ≤ + X * (∏ p ∈ P, (1 - g p)) * Real.exp (-(s : ℝ) / 48) + + ∑ d ∈ levelDivisors P (V ^ s), |integerRemainder C weight hit X g d| := by + let m := s / 12 - 1 + have hm : 20000 ≤ m := by dsimp [m]; omega + have hlevel : 12 * (m + 1) ≤ s := by dsimp [m]; omega + have hms : s ≤ 24 * m := by dsimp [m]; omega + have h := finite_fundamental_integer_level C weight hweight hit V m P X g hV hm hX hprime hsize hg0 hdim htwo + apply h.trans + apply add_le_add + · have hcap := BonferroniDensity.prime_density_le_two_thirds P g hprime hdim htwo + have hEuler : 0 ≤ ∏ p ∈ P, (1 - g p) := Finset.prod_nonneg (fun p hp => by linarith [hcap p hp]) + apply mul_le_mul_of_nonneg_left _ (mul_nonneg hX hEuler) + apply Real.exp_le_exp.mpr + have hmsR : (s : ℝ) ≤ 24 * (m : ℝ) := by exact_mod_cast hms + linarith + · apply Finset.sum_le_sum_of_subset_of_nonneg + · intro d hd + obtain ⟨hdP, hdL⟩ := Finset.mem_filter.mp hd + exact Finset.mem_filter.mpr ⟨hdP, hdL.trans (Nat.pow_le_pow_right (by omega) hlevel)⟩ + · intro d _ _ + exact abs_nonneg _ + +end NumberTheoryLean.FundamentalBlockEstimate + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/GateIterates.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/GateIterates.lean new file mode 100644 index 0000000000000000000000000000000000000000..93497d9cb4671a86e5961fdd8bedcc9e30f3e8e4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/GateIterates.lean @@ -0,0 +1,165 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ContinuousReference + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.MeasureTheory _root_.Set +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +abbrev Profile := Side → ℝ → ℝ → ℝ + +def JointContinuous (H : Profile) : Prop := ∀ i,Continuous (fun p : ℝ×ℝ => H i p.1 p.2) + +noncomputable def gate (H : Profile) (i : Side) (r b : ℝ) : ℝ := + ∫ x in (1:ℝ)..upperCutoff i r b,H i.flip (r-x) x/(max 1 x) + +theorem gate_integrand_continuous {H : Profile} (hH : JointContinuous H) (i : Side) (r : ℝ) : + Continuous (fun x : ℝ => H i.flip (r-x) x/(max 1 x)) := by + have hc : Continuous (fun x : ℝ => H i.flip (r-x) x) := + (hH i.flip).comp ((continuous_const.sub continuous_id).prodMk continuous_id) + exact hc.div (continuous_const.max continuous_id) (fun x => ne_of_gt + ((by norm_num : (0:ℝ)<1).trans_le (le_max_left 1 x))) + +theorem gate_continuous {H : Profile} (hH : JointContinuous H) : JointContinuous (gate H) := by + intro i + let F : (ℝ×ℝ) → ℝ → ℝ := fun p x => H i.flip (p.1-x) x/(max 1 x) + have hc : Continuous (fun q : (ℝ×ℝ)×ℝ => H i.flip (q.1.1-q.2) q.2) := + (hH i.flip).comp ((continuous_fst.fst.sub continuous_snd).prodMk continuous_snd) + have hd : Continuous (fun q : (ℝ×ℝ)×ℝ => max 1 q.2) := continuous_const.max continuous_snd + have hF : Continuous F.uncurry := hc.div hd (fun q => ne_of_gt + ((by norm_num : (0:ℝ)<1).trans_le (le_max_left 1 q.2))) + exact continuous_variable_upper_integral F hF (fun p => upperCutoff i p.1 p.2) (upperCutoff_continuous i) + +theorem gate_add {H G : Profile} (hH : JointContinuous H) (hG : JointContinuous G) + (i : Side) (r b : ℝ) : + gate (fun j s t => H j s t+G j s t) i r b=gate H i r b+gate G i r b := by + simp only [gate,add_div] + exact intervalIntegral.integral_add + ((gate_integrand_continuous hH i r).intervalIntegrable 1 _) ((gate_integrand_continuous hG i r).intervalIntegrable 1 _) + +theorem gate_mul (c : ℝ) (H : Profile) (i : Side) (r b : ℝ) : + gate (fun j s t => c*H j s t) i r b=c*gate H i r b := by + simp only [gate,mul_div_assoc,intervalIntegral.integral_const_mul] + +theorem gate_sum (N : ℕ) (H : ℕ → Profile) (hH : ∀ n,JointContinuous (H n)) + (i : Side) (r b : ℝ) : + gate (fun j s t => ∑ n ∈ Finset.range N,H n j s t) i r b= + ∑ n ∈ Finset.range N,gate (H n) i r b := by + simp only [gate,Finset.sum_div] + exact intervalIntegral.integral_finsetSum (fun n _ => (gate_integrand_continuous (hH n) i r).intervalIntegrable 1 _) + +theorem gate_nonnegative {H : Profile} (hH : ∀ i r b,0 ≤ H i r b) (i : Side) (r b : ℝ) : + 0 ≤ gate H i r b := by + apply intervalIntegral.integral_nonneg_of_forall (upperCutoff_bounds i r b).1 + intro x + exact div_nonneg (hH i.flip (r-x) x) (zero_le_one.trans (le_max_left 1 x)) + +theorem gate_odd_small (H : Profile) {r b : ℝ} (hr : r ≤ 4) : gate H .odd r b=0 := by + rw [gate,upperCutoff_odd_small hr,intervalIntegral.integral_same] + +end ErdosContinuousOmission + +end + +section + +open _root_.MeasureTheory _root_.Set +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +noncomputable def gateIterate : ℕ → Profile → Profile + | 0,H => H + | n+1,H => gate (gateIterate n H) + +theorem gateIterate_continuous {H : Profile} (hH : JointContinuous H) (n : ℕ) : + JointContinuous (gateIterate n H) := by + induction n with + | zero => exact hH + | succ n ih => exact gate_continuous ih + +theorem gateIterate_nonnegative {H : Profile} (hH : ∀ i r b,0 ≤ H i r b) (n : ℕ) : + ∀ i r b,0 ≤ gateIterate n H i r b := by + induction n with + | zero => exact hH + | succ n ih => exact gate_nonnegative ih + +theorem gateIterate_depth_zero (H : Profile) (n : ℕ) (i : Side) {r b : ℝ} + (hr : r ≤ (n:ℝ)+1) : gateIterate (n+2) H i r b=0 := by + induction n generalizing i r b with + | zero => + cases i with + | odd => exact gate_odd_small (gateIterate 1 H) (by norm_num at hr; linarith) + | even => + change (∫ x in (1:ℝ)..upperCutoff .even r b,gate H .odd (r-x) x/(max 1 x))=0 + calc + _ = ∫ _x in (1:ℝ)..upperCutoff .even r b,(0:ℝ) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (upperCutoff_bounds .even r b).1] at hx + dsimp only + rw [gate_odd_small H (by norm_num at hr; linarith [hx.1]),zero_div] + _ = 0 := by simp + | succ n ih => + rw [show n+1+2=(n+2)+1 by omega,gateIterate,gate] + calc + _ = ∫ _x in (1:ℝ)..upperCutoff i r b,(0:ℝ) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (upperCutoff_bounds i r b).1] at hx + dsimp only + have hchild : r-x ≤ (n:ℝ)+1 := by push_cast at hr; linarith [hx.1] + rw [ih i.flip hchild,zero_div] + _ = 0 := by simp + +theorem gateIterate_zero_of_index (H : Profile) {N : ℕ} (hN : 2 ≤ N) (i : Side) + {r b : ℝ} (hr : r ≤ (N:ℝ)-1) : gateIterate N H i r b=0 := by + have he : N=(N-2)+2 := by omega + rw [he] + apply gateIterate_depth_zero + have hc : ((N-2:ℕ):ℝ)=(N:ℝ)-2 := by rw [Nat.cast_sub hN]; norm_num + linarith + +theorem gateIterate_add {H G : Profile} (hH : JointContinuous H) (hG : JointContinuous G) + (n : ℕ) (i : Side) (r b : ℝ) : + gateIterate n (fun j s t => H j s t+G j s t) i r b= + gateIterate n H i r b+gateIterate n G i r b := by + induction n generalizing i r b with + | zero => rfl + | succ n ih => + have he : gateIterate n (fun j s t => H j s t+G j s t)= + (fun j s t => gateIterate n H j s t+gateIterate n G j s t) := by funext j s t; exact ih j s t + rw [gateIterate,he] + exact gate_add (gateIterate_continuous hH n) (gateIterate_continuous hG n) i r b + +theorem gateIterate_gate (n : ℕ) (H : Profile) : gateIterate n (gate H)=gateIterate (n+1) H := by + induction n with + | zero => rfl + | succ n ih => simp only [gateIterate,ih] + +theorem finite_forcing_expansion {H F : Profile} (hH : JointContinuous H) (hF : JointContinuous F) + (heq : ∀ i r b,H i r b=F i r b+gate H i r b) (N : ℕ) (i : Side) (r b : ℝ) : + H i r b=(∑ n ∈ Finset.range N,gateIterate n F i r b)+gateIterate N H i r b := by + have hf : H=(fun j s t => F j s t+gate H j s t) := by funext j s t; exact heq j s t + have hs (n : ℕ) : gateIterate n H i r b=gateIterate n F i r b+gateIterate (n+1) H i r b := by + calc + _ = gateIterate n (fun j s t => F j s t+gate H j s t) i r b := congrArg (fun G => gateIterate n G i r b) hf + _ = gateIterate n F i r b+gateIterate n (gate H) i r b := gateIterate_add hF (gate_continuous hH) n i r b + _ = _ := by rw [gateIterate_gate] + induction N with + | zero => simp only [Finset.range_zero,Finset.sum_empty,zero_add,gateIterate] + | succ n ih => + rw [Finset.sum_range_succ,add_assoc,← hs n] + exact ih + +end ErdosContinuousOmission + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/GrowingFarTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/GrowingFarTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..9e20e4af6926df871f70872745883f66fc56d938 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/GrowingFarTail.lean @@ -0,0 +1,367 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualFlaggedCompact + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.InverseWeightGrowth +open _root_.Filter +open scoped Topology + +theorem quartic_log_scale_absorption {C kappa : ℝ} (hC : 0 ≤ C) (hkappa : 0 < kappa) : + ∀ᶠ w : ℝ in atTop, + Real.exp (C*(1+(Real.log w)^((1 : ℝ)/10))^4) * + Real.exp (-kappa*Real.sqrt (Real.log w)) ≤ + Real.exp (-(kappa/2)*Real.sqrt (Real.log w)) := by + have hk : Tendsto (fun w : ℝ => (Real.log w)^((1 : ℝ)/10)) atTop atTop := + (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 1/10)).comp Real.tendsto_log_atTop + filter_upwards [Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1 : ℝ)), + hk.eventually (eventually_ge_atTop (max 1 (32*C/kappa)))] with w hlog hcut + let k : ℝ := (Real.log w)^((1 : ℝ)/10) + have hk1 : 1 ≤ k := (le_max_left _ _).trans hcut + have hk0 : 0 ≤ k := by linarith + have hcoef : 16*C ≤ (kappa/2)*k := by + have h := (div_le_iff₀ hkappa).mp ((le_max_right _ _).trans hcut) + nlinarith + have hsqrt : Real.sqrt (Real.log w) = k^5 := by + rw [Real.sqrt_eq_rpow] + dsimp [k] + rw [← Real.rpow_mul_natCast (by linarith : 0 ≤ Real.log w)] + norm_num + have hmajor : C*(1+k)^4 ≤ (kappa/2)*Real.sqrt (Real.log w) := by + calc + _ ≤ C*(2*k)^4 := mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (by linarith) (by linarith : 1+k ≤ 2*k) 4) hC + _ = (16*C)*k^4 := by ring + _ ≤ ((kappa/2)*k)*k^4 := mul_le_mul_of_nonneg_right hcoef (pow_nonneg hk0 _) + _ = _ := by rw [hsqrt]; ring + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + change C*(1+k)^4 + -kappa*Real.sqrt (Real.log w) ≤ _ + nlinarith + +end NumberTheoryLean.InverseWeightGrowth + +end + +section + +namespace NumberTheoryLean.ModerateFailedReward + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open PrimeCompactVisits PrimeCompactWeights ActualProcessCoupling +open FlaggedOccupationBound ActualFlaggedCompact PersistentFailureFlag +open DerivativeWeights ExponentialMeshTail InverseWeightGrowth + +variable {w ell S : ℝ} {start : Node} + +noncomputable def moderateReward (c K : ℝ) : ChainState w ell S start → ℝ≥0∞ + | none => 0 + | some h => ENNReal.ofReal (h.node.gap^2*Real.exp (-c*h.node.gap)/weight h.node.side h.node.ratio)* + ENNReal.ofReal (visit K (some h)) + +theorem exponential_quartic_absorbs_linear {C K : ℝ} (hK : 0 ≤ K) : + Real.exp (C*(1+K)^4)*(K+1) ≤ Real.exp ((C+1)*(1+K)^4) := by + have hp : K ≤ (1+K)^4 := by nlinarith [pow_nonneg hK 3,pow_nonneg hK 4] + have hlin : K+1 ≤ Real.exp ((1+K)^4) := (Real.add_one_le_exp K).trans (Real.exp_le_exp.mpr hp) + calc + _ ≤ Real.exp (C*(1+K)^4)*Real.exp ((1+K)^4) := mul_le_mul_of_nonneg_left hlin (Real.exp_pos _).le + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +theorem moderate_reward_envelope : ∃ A C : ℝ,0 < A ∧ 0 < C ∧ + ∀ w ell S : ℝ,∀ start : Node,1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → + Consistent start → ell ≤ start.cutoff → ∀ c : ℝ,0 < c → ∀ K : ℝ, + ∀ z : ChainState w ell S start, + moderateReward c K z ≤ ENNReal.ofReal ((8*A/c^2)*Real.exp (C*(1+K)^4))*ENNReal.ofReal (visit K z) := by + obtain ⟨A,C,hA,hC,hbound⟩ := inverse_weight_below_cutoff + refine ⟨A,C,hA,hC,?_⟩ + intro w ell S start hell hr hs hcons hcut c hc K z + cases z with + | none => simp [moderateReward,visit] + | some h => + by_cases hh : h.node.gap ≤ K + · have hg : 0 < h.node.gap := terminal_gap_positive (by linarith) hr hs h.admissible + have hv : Valid h.node.side h.node.ratio := terminal_valid hs h.admissible + have htK := (history_ratio_le_gap hell hr hs hcons hcut h).trans hh + have hinv := hbound K h.node.side h.node.ratio hv htK + have hraw : h.node.gap^2*Real.exp (-c*h.node.gap) ≤ 8/c^2 := by + refine (quadratic_exp_majorant hc hg.le).trans ?_ + simpa only [mul_one] using mul_le_mul_of_nonneg_left + (Real.exp_le_one_iff.mpr (by nlinarith : -c*h.node.gap/2 ≤ 0)) (show 0 ≤ 8/c^2 by positivity) + have hφ := weight_pos hv + have hreal : h.node.gap^2*Real.exp (-c*h.node.gap)/weight h.node.side h.node.ratio ≤ + (8*A/c^2)*Real.exp (C*(1+K)^4) := by + calc + _ = (h.node.gap^2*Real.exp (-c*h.node.gap))*(1/weight h.node.side h.node.ratio) := by ring + _ ≤ (8/c^2)*(A*Real.exp (C*(1+K)^4)) := mul_le_mul hraw hinv (by positivity) (by positivity) + _ = _ := by ring + simp only [moderateReward,visit,ite_eq_left hh,ENNReal.ofReal_one,mul_one] + exact ENNReal.ofReal_le_ofReal hreal + · simp [moderateReward,visit,hh] + +theorem actual_moderate_failed_sum : ∃ A C : ℝ,0 < A ∧ 0 < C ∧ + ∀ w ell S : ℝ,∀ start : Node,∀ _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, + Consistent start → ell ≤ start.cutoff → ∀ c : ℝ,0 < c → ∀ K : ℝ,0 ≤ K → + ∀ mesh : ℝ,∀ N : ℕ, + (∑ n ∈ range N,∫⁻ z,selected (fun q : JointState w ell S start => moderateReward c K q.1) z + ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal ((8*A/c^2)*Real.exp (C*(1+K)^4))* + CouplingData.sourceLaw w ell S start hs mesh N failed := by + obtain ⟨A,C,hA,hC,hbound⟩ := moderate_reward_envelope + refine ⟨A,C+1,hA,by linarith,?_⟩ + intro w ell S start hw hell hS0 hS hr hs hsS hcons hcut c hc K hK mesh N + let D := (8*A/c^2)*Real.exp (C*(1+K)^4) + have hD : 0 ≤ D := by dsimp [D]; positivity + have hpoint : ∀ z : FlagState (JointState w ell S start), + selected (fun q => moderateReward c K q.1) z ≤ ENNReal.ofReal D*selected (compactVisit K) z := by + rintro ⟨q,b⟩ + cases b with + | false => simp only [selected_false,mul_zero,le_refl] + | true => + simpa only [selected_true,compactVisit] using hbound w ell S start hell hr hs hcons hcut c hc K q.1 + have hsum : (∑ n ∈ range N,∫⁻ z,selected (fun q : JointState w ell S start => moderateReward c K q.1) z + ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal D*(∑ n ∈ range N,∫⁻ z,selected (compactVisit K) z ∂CouplingData.sourceLaw w ell S start hs mesh n) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro n _hn + calc + _ ≤ ∫⁻ z,ENNReal.ofReal D*selected (compactVisit K) z ∂CouplingData.sourceLaw w ell S start hs mesh n := lintegral_mono hpoint + _ = _ := lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + have hlinear := exponential_quartic_absorbs_linear (C:=C) hK + refine hsum.trans ?_ + calc + _ ≤ ENNReal.ofReal D*(ENNReal.ofReal (K+1)*CouplingData.sourceLaw w ell S start hs mesh N failed) := + mul_le_mul_of_nonneg_left (actual_flagged_compact_visits hw hell hS0 hS hr hs hsS hK mesh N) zero_le + _ ≤ _ := by + rw [← mul_assoc,← ENNReal.ofReal_mul hD] + apply mul_le_mul_of_nonneg_right _ zero_le + apply ENNReal.ofReal_le_ofReal + dsimp [D] + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left hlinear (show 0 ≤ 8*A/c^2 by positivity) + +end NumberTheoryLean.ModerateFailedReward + +end + +section + +namespace NumberTheoryLean.SourceFarGapTail + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open PrimeGridGeometry PrimeGridKernel PrimeInverseBins PrimeExponentialTail +open SourceAllInverseBins ExponentialMesh LowStateHorizon + +theorem source_far_gap_tail : ∃ κ₀ C : ℝ,0 < κ₀ ∧ 0 < C ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ d : ℝ,0 < d → ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node, + 1 ≤ ell → ell ≤ B → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + ∀ c : ℝ,0 < c → ∀ K : ℝ, + (∀ n,1 ≤ n → n ≤ N → (∫⁻ z,tailReward c K z ∂pathLaw w ell S start n) ≤ + ENNReal.ofReal (C*(8/c^2)*(1+4/c)*Real.exp (-c*K/4))) ∧ + ((∑ n ∈ range N,∫⁻ z,tailReward c K z ∂pathLaw w ell S start (n+1)) ≤ + (N:ℝ≥0∞)*ENNReal.ofReal (C*(8/c^2)*(1+4/c)*Real.exp (-c*K/4))) := by + obtain ⟨κ₀,C,hκ₀,hC,hsource⟩ := source_all_inverse_bins + refine ⟨κ₀,C,hκ₀,hC,?_⟩ + intro κ hκ hκle d hd + obtain ⟨w₀,hw₀,hsource⟩ := hsource κ hκ hκle d hd + refine ⟨w₀,hw₀,?_⟩ + intro w hw ell B start hell hellB hB hlogB hcomp hr hi h199 h23 hcons hcut + dsimp only + intro c hc K + let S := (Real.log B)^2 + let N := sourceHorizon S B + let m := ⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊ + have hm : 1 ≤ m := Nat.ceil_pos.mpr (Real.exp_pos _) + have hh : width m ≤ 1 := mesh_le_one hκ.le w + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hb := hsource w hw ell B start hell hB hlogB hcomp hr hi h199 h23 + have hper : ∀ n,1 ≤ n → n ≤ N → (∫⁻ z,tailReward c K z ∂pathLaw w ell S start n) ≤ + ENNReal.ofReal (C*(8/c^2)*(1+4/c)*Real.exp (-c*K/4)) := by + intro n hn hnN + exact actual_tail_from_inverse_bins hc hC.le hm hh hell hr hs hcons (by rwa [hcut]) hsS n (hb n hn hnN) + refine ⟨hper,?_⟩ + change (∑ n ∈ range N,∫⁻ z,tailReward c K z ∂pathLaw w ell S start (n+1)) ≤ + (N:ℝ≥0∞)*ENNReal.ofReal (C*(8/c^2)*(1+4/c)*Real.exp (-c*K/4)) + calc + _ ≤ ∑ _n ∈ range N,ENNReal.ofReal (C*(8/c^2)*(1+4/c)*Real.exp (-c*K/4)) := by + apply Finset.sum_le_sum + intro n hn + exact hper (n+1) (by omega) (by have hh := Finset.mem_range.mp hn; omega) + _ = _ := by simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] + +end NumberTheoryLean.SourceFarGapTail + +end + +section + +namespace NumberTheoryLean.SourceModerateFailure + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualProcessCoupling PersistentFailureFlag FlaggedOccupationBound +open ModerateFailedReward SourceCouplingRate InverseWeightGrowth UniformBudgetRate +open ExponentialMesh LowStateHorizon + +noncomputable def growingCutoff (w : ℝ) : ℝ := (Real.log w)^((1:ℝ)/10) + +theorem source_moderate_failure : ∃ κ₀ A : ℝ,0 < κ₀ ∧ 0 < A ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ d : ℝ,0 < d → ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + ∀ c : ℝ,0 < c → + (∑ n ∈ range N,∫⁻ z,selected (fun q : JointState w ell S start => moderateReward c (growingCutoff w) q.1) z + ∂CouplingData.sourceLaw w ell S start hs (mesh κ w) n) ≤ + ENNReal.ofReal ((A/c^2)*Real.exp (-(κ/4)*Real.sqrt (Real.log w))) := by + obtain ⟨κ₀,hκ₀,hrate⟩ := source_coupling_rate + obtain ⟨A,C,hA,hC,hmod⟩ := actual_moderate_failed_sum + refine ⟨κ₀,8*A,hκ₀,by positivity,?_⟩ + intro κ hκ hκle d hd + obtain ⟨wF,hwF,hrate⟩ := hrate κ hκ hκle d hd + have hevent := (quartic_log_scale_absorption hC.le (show 0 < κ/2 by linarith)).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + obtain ⟨wAux,hwAux⟩ := eventually_atTop.mp hevent + refine ⟨max wF (max normalizationThreshold wAux),hwF.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hellB hB hlogB hcomp hr h23 hcons hcut + dsimp only + intro c hc + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hwe := hwAux w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw) + have hscale := source_scale_bound hwe.2 hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hlog : 0 ≤ Real.log w := (sq_nonneg d).trans hwe.2 + have hcut0 : 0 ≤ growingCutoff w := Real.rpow_nonneg hlog _ + have hsize : start.gap ≤ (23/10:ℝ)*B := by + have he : start.cutoff = start.gap/start.ratio := hcons + rw [hcut] at he + have hh := (eq_div_iff (valid_pos hs).ne').mp he + nlinarith + have hfailed := ((hrate w ((le_max_left _ _).trans hw) ell B start hs hell hB hlogB hcomp hr h23 hcons hsize).1 N le_rfl).1 + have hm := hmod w ell S start hnorm hell hS0 hscale.1 hr hs hsS hcons (by rwa [hcut]) + c hc (growingCutoff w) hcut0 (mesh κ w) N + have hcoef : 0 ≤ 8*A/c^2 := by positivity + refine hm.trans ?_ + calc + _ ≤ ENNReal.ofReal ((8*A/c^2)*Real.exp (C*(1+growingCutoff w)^4))* + ENNReal.ofReal (Real.exp (-(κ/2)*Real.sqrt (Real.log w))) := + mul_le_mul_of_nonneg_left hfailed zero_le + _ = ENNReal.ofReal ((8*A/c^2)*(Real.exp (C*(1+growingCutoff w)^4)* + Real.exp (-(κ/2)*Real.sqrt (Real.log w)))) := by + rw [← ENNReal.ofReal_mul (by positivity)] + congr 1 + ring + _ ≤ _ := by + apply ENNReal.ofReal_le_ofReal + have habsorb : Real.exp (C*(1+growingCutoff w)^4)*Real.exp (-(κ/2)*Real.sqrt (Real.log w)) ≤ + Real.exp (-(κ/4)*Real.sqrt (Real.log w)) := by + simpa only [growingCutoff,div_div,show (2:ℝ)*2 = 4 by norm_num] using hwe.1 + exact mul_le_mul_of_nonneg_left habsorb hcoef + +end NumberTheoryLean.SourceModerateFailure + +end + +section + +namespace NumberTheoryLean.GrowingFarTail + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open PrimeExponentialTail SourceFarGapTail SourceModerateFailure LowStateHorizon + +theorem growingCutoff_tendsto : Tendsto growingCutoff atTop atTop := + (tendsto_rpow_atTop (by norm_num : (0:ℝ) < 1/10)).comp Real.tendsto_log_atTop + +theorem log_cube_growing_exp_tendsto {c : ℝ} (hc : 0 < c) : + Tendsto (fun w : ℝ => (Real.log w)^3*Real.exp (-c*growingCutoff w)) atTop (𝓝 0) := by + have h : Tendsto (fun x : ℝ => x^30*Real.exp (-c*x)) atTop (𝓝 0) := by + simpa only [Real.rpow_ofNat] using tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (30:ℝ) c hc + apply Tendsto.congr' _ (h.comp growingCutoff_tendsto) + filter_upwards [Real.tendsto_log_atTop.eventually (eventually_ge_atTop (0:ℝ))] with w hw + have hp : growingCutoff w^30 = (Real.log w)^3 := by + unfold growingCutoff + rw [← Real.rpow_mul_natCast hw] + norm_num + simp only [Function.comp_apply,hp] + +noncomputable def farBudget (C c d w : ℝ) : ℝ := + (5*d^3*(C*(8/c^2)*(1+4/c)))*(Real.log w)^3*Real.exp (-(c/4)*growingCutoff w) + +theorem farBudget_tendsto_zero (C d : ℝ) {c : ℝ} (hc : 0 < c) : + Tendsto (farBudget C c d) atTop (𝓝 0) := by + have h := (log_cube_growing_exp_tendsto (show 0 < c/4 by linarith)).const_mul (5*d^3*(C*(8/c^2)*(1+4/c))) + simp only [mul_zero] at h + convert h using 1 + funext w + unfold farBudget + ring + +theorem source_horizon_comparison {B d w : ℝ} (hlogB : 2 ≤ Real.log B) + (hcomp : Real.log B ≤ d*Real.log w) : + (sourceHorizon ((Real.log B)^2) B:ℝ) ≤ 5*d^3*(Real.log w)^3 := by + have hN := source_horizon_log_cube hlogB + have hp := pow_le_pow_left₀ (by linarith : 0 ≤ Real.log B) hcomp 3 + nlinarith + +theorem source_growing_far_tail : ∃ κ₀ C : ℝ,0 < κ₀ ∧ 0 < C ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ d : ℝ,0 < d → ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node, + 1 ≤ ell → ell ≤ B → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + ∀ c : ℝ,0 < c → + (∑ n ∈ range N,∫⁻ z,tailReward c (growingCutoff w) z ∂pathLaw w ell S start (n+1)) ≤ + ENNReal.ofReal (farBudget C c d w) := by + obtain ⟨κ₀,C,hκ₀,hC,hsource⟩ := source_far_gap_tail + refine ⟨κ₀,C,hκ₀,hC,?_⟩ + intro κ hκ hκle d hd + obtain ⟨w₀,hw₀,hsource⟩ := hsource κ hκ hκle d hd + refine ⟨w₀,hw₀,?_⟩ + intro w hw ell B start hell hellB hB hlogB hcomp hr hi h199 h23 hcons hcut + dsimp only + intro c hc + have hb := (hsource w hw ell B start hell hellB hB hlogB hcomp hr hi h199 h23 hcons hcut c hc (growingCutoff w)).2 + have hN := source_horizon_comparison hlogB hcomp + refine hb.trans ?_ + rw [← ENNReal.ofReal_natCast,← ENNReal.ofReal_mul (Nat.cast_nonneg _)] + apply ENNReal.ofReal_le_ofReal + have hcst : 0 ≤ C*(8/c^2)*(1+4/c)*Real.exp (-c*growingCutoff w/4) := by positivity + have h := mul_le_mul_of_nonneg_right hN hcst + unfold farBudget + rw [show -(c/4)*growingCutoff w = -c*growingCutoff w/4 by ring] + simpa only [mul_assoc,mul_left_comm,mul_comm] using h + +end NumberTheoryLean.GrowingFarTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicChangeOfVariable.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicChangeOfVariable.lean new file mode 100644 index 0000000000000000000000000000000000000000..5d2d467882215c6ba445c08da4259e120097c614 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicChangeOfVariable.lean @@ -0,0 +1,75 @@ +import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts +import OAI.NumberTheory.Jacobsthal.Paths.FiniteHistorySupport + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.HarmonicChangeOfVariable + +open Set MeasureTheory +open FinitePathGeometry + +theorem exponent_hasDerivAt {r t : ℝ} (ht : 0 < t) : + HasDerivAt (nextExponent r) (-r / (t + 1) ^ 2) t := by + have h := (hasDerivAt_const t r).div ((hasDerivAt_id t).add_const 1) (by linarith : t + 1 ≠ 0) + convert! h using 1 + simp only [id_eq, zero_mul, zero_sub, mul_one] + +theorem inverse_exponent {r t : ℝ} (hr : 0 < r) (_ht : 0 < t) : + r / nextExponent r t - 1 = t := by + unfold nextExponent + field_simp + ring + +theorem harmonic_jacobian {r t : ℝ} (hr : 0 < r) (ht : 0 < t) : + |deriv (nextExponent r) t| / nextExponent r t = 1 / (t + 1) := by + rw [(exponent_hasDerivAt ht).deriv, abs_of_neg (div_neg_of_neg_of_pos (by linarith) + (sq_pos_of_pos (by linarith)))] + unfold nextExponent + field_simp + +theorem harmonic_substitution (H : ℝ → ℝ) {r a b : ℝ} + (hr : 0 < r) (ha : 0 < a) (hab : a ≤ b) : + (∫ x in nextExponent r b..nextExponent r a, H (r / x - 1) / x) = + ∫ t in a..b, H t / (t + 1) := by + let G : ℝ → ℝ := fun x => H (r / x - 1) / x + have hc : ContinuousOn (nextExponent r) (uIcc a b) := by + intro t ht + rw [uIcc_of_le hab] at ht + exact (exponent_hasDerivAt (r := r) (lt_of_lt_of_le ha ht.1)).continuousAt.continuousWithinAt + have hd : ∀ t ∈ Ioo (min a b) (max a b), + HasDerivAt (nextExponent r) (-r / (t + 1) ^ 2) t := by + intro t ht + rw [min_eq_left hab, max_eq_right hab] at ht + exact exponent_hasDerivAt (by linarith [ht.1]) + have hn : ∀ t ∈ Ioo (min a b) (max a b), -r / (t + 1) ^ 2 ≤ 0 := by + intro t _ + exact div_nonpos_of_nonpos_of_nonneg (by linarith) (sq_nonneg _) + have hsub := intervalIntegral.integral_comp_mul_deriv_of_deriv_nonpos (g := G) hc hd hn + have hl : (∫ t in a..b, (G ∘ nextExponent r) t * (-r / (t + 1) ^ 2)) = + -(∫ t in a..b, H t / (t + 1)) := by + calc + _ = ∫ t in a..b, -(H t / (t + 1)) := by + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hab] at ht + have ht0 : 0 < t := lt_of_lt_of_le ha ht.1 + simp only [Function.comp_apply, G, inverse_exponent hr ht0] + unfold nextExponent + field_simp + _ = _ := intervalIntegral.integral_neg + calc + _ = -(∫ x in nextExponent r a..nextExponent r b, G x) := + intervalIntegral.integral_symm _ _ + _ = _ := by rw [← hsub, hl, neg_neg] + +end NumberTheoryLean.HarmonicChangeOfVariable + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicConditioning.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicConditioning.lean new file mode 100644 index 0000000000000000000000000000000000000000..4123d57a8e198dbbea305069ada0961d2a80d8d3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicConditioning.lean @@ -0,0 +1,125 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualSampleWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseCells +open ErdosInverseSampling +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def harmonicMass (Q : Finset ℕ) : ℝ := ∑ q ∈ Q,(q : ℝ)⁻¹ + +noncomputable def tripleSpace (P Q U : Finset ℕ) : Finset ((ℕ × ℕ) × ℕ) := (P ×ˢ Q) ×ˢ U + +noncomputable def tripleWeight (x : (ℕ × ℕ) × ℕ) : ℝ := + (x.1.1 : ℝ)⁻¹*(x.1.2 : ℝ)⁻¹*(x.2 : ℝ)⁻¹ + +noncomputable def weightedWitness (P Q U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) : ℝ := + ∑ x ∈ witnessPairs (P.product Q) U witness,tripleWeight x + +noncomputable def cofactorReward (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) (q : ℕ) : ℝ := + ∑ p ∈ P,∑ u ∈ U,if witness (p,q) u then (p : ℝ)⁻¹*(u : ℝ)⁻¹ else 0 + +noncomputable def conditionalReward (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) (q : ℕ) : ℝ := + cofactorReward P U witness q/(harmonicMass P*harmonicMass U) + +theorem harmonicMass_nonneg (Q : Finset ℕ) : 0 ≤ harmonicMass Q := by unfold harmonicMass;positivity + +theorem harmonicMass_pos (Q : Finset ℕ) (hQ : Q.Nonempty) (hp : ∀ q ∈ Q,0 < q) : 0 < harmonicMass Q := by + apply Finset.sum_pos + · intro q hq + exact inv_pos.mpr (by exact_mod_cast hp q hq) + · exact hQ + +theorem tripleWeight_nonneg (x : (ℕ × ℕ) × ℕ) : 0 ≤ tripleWeight x := by unfold tripleWeight;positivity + +theorem triple_weight_sum (P Q U : Finset ℕ) : + (∑ x ∈ tripleSpace P Q U,tripleWeight x) = harmonicMass P*harmonicMass Q*harmonicMass U := by + simp only [tripleSpace,Finset.sum_product,tripleWeight,harmonicMass,mul_assoc,← Finset.mul_sum,← Finset.sum_mul] + +theorem cofactorReward_nonneg (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) (q : ℕ) : + 0 ≤ cofactorReward P U witness q := by unfold cofactorReward;positivity + +theorem cofactorReward_upper (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) (q : ℕ) : + cofactorReward P U witness q ≤ harmonicMass P*harmonicMass U := by + calc + _ ≤ ∑ p ∈ P,∑ u ∈ U,(p : ℝ)⁻¹*(u : ℝ)⁻¹ := by + apply Finset.sum_le_sum + intro p _ + apply Finset.sum_le_sum + intro u _ + split_ifs + · exact le_rfl + · positivity + _ = _ := by simp only [harmonicMass,← Finset.mul_sum,← Finset.sum_mul] + +theorem conditionalReward_bounds (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) (q : ℕ) + (hDen : 0 < harmonicMass P*harmonicMass U) : 0 ≤ conditionalReward P U witness q ∧ conditionalReward P U witness q ≤ 1 := by + refine ⟨div_nonneg (cofactorReward_nonneg P U witness q) hDen.le,?_⟩ + exact (div_le_iff₀ hDen).mpr (by simpa only [one_mul] using cofactorReward_upper P U witness q) + +theorem weightedWitness_decomposition (P Q U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) : + weightedWitness P Q U witness = ∑ q ∈ Q,(q : ℝ)⁻¹*cofactorReward P U witness q := by + unfold weightedWitness witnessPairs + simp only [Finset.sum_filter,Finset.product_eq_sprod,Finset.sum_product,tripleWeight] + have he : ∀ p q u : ℕ,(if witness (p,q) u then (p : ℝ)⁻¹*(q : ℝ)⁻¹*(u : ℝ)⁻¹ else 0) = + (q : ℝ)⁻¹*(if witness (p,q) u then (p : ℝ)⁻¹*(u : ℝ)⁻¹ else 0) := by + intro p q u + split_ifs <;> ring + simp_rw [he] + rw [Finset.sum_comm] + simp only [cofactorReward,Finset.mul_sum] + +end ErdosInverseCells + +end + +section + +namespace ErdosInverseCells + +theorem weightedWitness_conditioning (P Q U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) : + weightedWitness P Q U witness/(harmonicMass P*harmonicMass U) = + ∑ q ∈ Q,(q : ℝ)⁻¹*conditionalReward P U witness q := by + rw [weightedWitness_decomposition,Finset.sum_div] + simp only [conditionalReward,mul_div_assoc] + +theorem conditioned_reward_upper (P U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (hDen : 0 < harmonicMass P*harmonicMass U) (q : ℕ) : + (q : ℝ)⁻¹*conditionalReward P U witness q ≤ (q : ℝ)⁻¹ := by + have hh := mul_le_mul_of_nonneg_left (conditionalReward_bounds P U witness q hDen).2 + (inv_nonneg.mpr (Nat.cast_nonneg q)) + simpa only [mul_one] using hh + +theorem condition_harmonic_density (P Q U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (sigma : ℝ) (hDen : 0 < harmonicMass P*harmonicMass U) + (hBad : sigma*(harmonicMass P*harmonicMass Q*harmonicMass U) < weightedWitness P Q U witness) : + sigma*(∑ q ∈ Q,(q : ℝ)⁻¹) < ∑ q ∈ Q,(q : ℝ)⁻¹*conditionalReward P U witness q := by + rw [← weightedWitness_conditioning] + apply (lt_div_iff₀ hDen).mpr + have he : (sigma*(∑ q ∈ Q,(q : ℝ)⁻¹))*(harmonicMass P*harmonicMass U) = + sigma*(harmonicMass P*harmonicMass Q*harmonicMass U) := by unfold harmonicMass;ring + rwa [he] + +theorem uncondition_harmonic_density (P Q U : Finset ℕ) (witness : (ℕ × ℕ) → ℕ → Prop) + (sigma : ℝ) (hDen : 0 < harmonicMass P*harmonicMass U) + (hBad : sigma*(∑ q ∈ Q,(q : ℝ)⁻¹) < ∑ q ∈ Q,(q : ℝ)⁻¹*conditionalReward P U witness q) : + sigma*(harmonicMass P*harmonicMass Q*harmonicMass U) < weightedWitness P Q U witness := by + rw [← weightedWitness_conditioning] at hBad + have hh := (lt_div_iff₀ hDen).mp hBad + have he : (sigma*(∑ q ∈ Q,(q : ℝ)⁻¹))*(harmonicMass P*harmonicMass U) = + sigma*(harmonicMass P*harmonicMass Q*harmonicMass U) := by unfold harmonicMass;ring + rwa [he] at hh + +end ErdosInverseCells + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicLevelBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicLevelBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea9e6e504cc4751a8b841d3c963f9c3369b32785 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HarmonicLevelBound.lean @@ -0,0 +1,69 @@ +import Mathlib.NumberTheory.Harmonic.Bounds +import OAI.NumberTheory.Jacobsthal.Sieve.SourcePairSieve + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosVarianceLargeCount +open NumberTheoryLean ErdosHyperbolaError +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem real_level_card_bound (P : Finset ℕ) (v s : ℝ) (hD : 1 ≤ v^s) : + ((RealFundamentalSieve.levelDivisors P v s).card : ℝ) ≤ 2*(v^s) := by + have hsub : RealFundamentalSieve.levelDivisors P v s ⊆ Finset.range (⌊v^s⌋₊+1) := by + intro d hd + have hb := (Finset.mem_filter.mp hd).2 + exact Finset.mem_range.mpr (Nat.lt_succ_of_le ((Nat.le_floor_iff (by linarith)).mpr hb)) + have hc : ((RealFundamentalSieve.levelDivisors P v s).card : ℝ) ≤ ((⌊v^s⌋₊+1 : ℕ) : ℝ) := by + exact_mod_cast (Finset.card_le_card hsub).trans_eq (Finset.card_range _) + have hf := Nat.floor_le (show 0 ≤ v^s by linarith) + push_cast at hc + linarith + +theorem real_level_reciprocal_bound (P : Finset ℕ) (v s : ℝ) (hD : 1 ≤ v^s) : + (∑ d ∈ RealFundamentalSieve.levelDivisors P v s,1/(d : ℝ)) ≤ 1+Real.log (v^s) := by + have hsub : RealFundamentalSieve.levelDivisors P v s ⊆ Finset.Icc 1 ⌊v^s⌋₊ := by + intro d hd + obtain ⟨hddiv,hdlev⟩ := Finset.mem_filter.mp hd + exact Finset.mem_Icc.mpr ⟨Nat.pos_of_mem_divisors hddiv,(Nat.le_floor_iff (by linarith)).mpr hdlev⟩ + have hh := harmonic_floor_le_one_add_log (v^s) hD + have hh' : (∑ d ∈ Finset.Icc 1 ⌊v^s⌋₊,1/(d : ℝ)) ≤ 1+Real.log (v^s) := by + simpa only [harmonic_eq_sum_Icc,Rat.cast_sum,Rat.cast_inv,Rat.cast_natCast,one_div] using hh + exact (Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => by positivity)).trans hh' + +theorem hyperbolaEnvelope_nonneg (H T0 : ℕ) : 0 ≤ hyperbolaEnvelope H T0 := by + have hC := completionConstant_pos.le + dsimp [hyperbolaEnvelope] + positivity + +theorem hyperbola_level_sum_bound (H T0 : ℕ) (P : Finset ℕ) (v s U V : ℝ) + (hD : 1 ≤ v^s) (hU : 0 ≤ U) (hV : 0 ≤ V) : + (∑ d ∈ RealFundamentalSieve.levelDivisors P v s, + hyperbolaEnvelope H T0*(1+U/((d : ℝ)*((H*T0 : ℕ) : ℝ))+V/((H*T0 : ℕ) : ℝ))) ≤ + hyperbolaEnvelope H T0*(2*(v^s)*(1+V/((H*T0 : ℕ) : ℝ))+ + (U/((H*T0 : ℕ) : ℝ))*(1+Real.log (v^s))) := by + let F := RealFundamentalSieve.levelDivisors P v s + let N : ℝ := (H*T0 : ℕ) + have he (d : ℕ) : 1+U/((d : ℝ)*N)+V/N = (1+V/N)+(U/N)*(1/(d : ℝ)) := by ring + have hsum : (∑ d ∈ F,hyperbolaEnvelope H T0*(1+U/((d : ℝ)*N)+V/N)) = + hyperbolaEnvelope H T0*((F.card : ℝ)*(1+V/N)+(U/N)*(∑ d ∈ F,1/(d : ℝ))) := by + rw [← Finset.mul_sum] + simp_rw [he] + rw [Finset.sum_add_distrib,Finset.sum_const,nsmul_eq_mul,← Finset.mul_sum] + rw [hsum] + apply mul_le_mul_of_nonneg_left _ (hyperbolaEnvelope_nonneg H T0) + apply add_le_add + · exact mul_le_mul_of_nonneg_right (real_level_card_bound P v s hD) (by positivity) + · exact mul_le_mul_of_nonneg_left (real_level_reciprocal_bound P v s hD) (by positivity) + +end ErdosVarianceLargeCount + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/HeightBlockCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HeightBlockCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..3477ab72cb99cd21c1130fcc08768b78d6718442 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HeightBlockCount.lean @@ -0,0 +1,59 @@ +import OAI.NumberTheory.Jacobsthal.Primes.CanonicalTagPrimePartition + +namespace OAI + +namespace Erdos970 + + +namespace ErdosLargeHeightBlocks + +noncomputable def blockCount (C0 : ℤ) (R xi : ℝ) (H : ℕ) : ℕ := + max 1 ⌈xi*|(C0 : ℝ)|/(R*(H : ℝ))⌉₊ + +theorem blockCount_pos (C0 : ℤ) (R xi : ℝ) (H : ℕ) : 0 < blockCount C0 R xi H := by + exact lt_of_lt_of_le Nat.zero_lt_one (le_max_left _ _) + +theorem blockCount_lower (C0 : ℤ) (R xi : ℝ) (H : ℕ) : + xi*|(C0 : ℝ)|/(R*(H : ℝ)) ≤ (blockCount C0 R xi H : ℝ) := by + apply (Nat.le_ceil _).trans + unfold blockCount + exact_mod_cast le_max_right 1 ⌈xi*|(C0 : ℝ)|/(R*(H : ℝ))⌉₊ + +theorem blockCount_upper (C0 : ℤ) (R xi : ℝ) (H : ℕ) + (hR : 0 < R) (hxi : 0 ≤ xi) (hH : 0 < H) : + (blockCount C0 R xi H : ℝ) ≤ 1+xi*|(C0 : ℝ)|/(R*(H : ℝ)) := by + have hx : 0 ≤ xi*|(C0 : ℝ)|/(R*(H : ℝ)) := by positivity + have hc := Nat.ceil_lt_add_one hx + rw [blockCount,Nat.cast_max,Nat.cast_one] + apply max_le <;> linarith + +theorem blockCount_source_bound (C0 : ℤ) (R xi Z : ℝ) (H : ℕ) + (hR : 0 < R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) (hH : 0 < H) (hZ : 2 ≤ Z) + (hsize : max (H : ℝ) (|(C0 : ℝ)|/R)/(H : ℝ) ≤ Z^12) : + (blockCount C0 R xi H : ℝ) ≤ Z^13 := by + have hHr : (0 : ℝ) < H := by exact_mod_cast hH + have hc : |(C0 : ℝ)|/(R*(H : ℝ)) ≤ Z^12 := by + have h := (div_le_div_of_nonneg_right (le_max_right (H : ℝ) (|(C0 : ℝ)|/R)) hHr.le).trans hsize + simpa only [div_div] using h + have hx : xi*|(C0 : ℝ)|/(R*(H : ℝ)) ≤ Z^12 := by + have h := mul_le_mul_of_nonneg_right hxi1 (show 0 ≤ |(C0 : ℝ)|/(R*(H : ℝ)) by positivity) + have he : xi*|(C0 : ℝ)|/(R*(H : ℝ))=xi*(|(C0 : ℝ)|/(R*(H : ℝ))) := by ring + rw [he] + exact h.trans (by simpa only [one_mul] using hc) + have hz0 : 0 ≤ Z := by linarith + have hpow : 1 ≤ Z^12 := one_le_pow₀ (by linarith) + have hzstep : 1+Z^12 ≤ Z^13 := by + have hh := mul_le_mul_of_nonneg_right hZ (pow_nonneg hz0 12) + rw [show Z*Z^12=Z^13 by ring] at hh + linarith + calc + _ ≤ 1+xi*|(C0 : ℝ)|/(R*(H : ℝ)) := blockCount_upper C0 R xi H hR hxi hH + _ ≤ 1+Z^12 := by linarith + _ ≤ _ := hzstep + +end ErdosLargeHeightBlocks + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalIndividualUpper.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalIndividualUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..414184797c2499bd39a48b0c5a1d3d225dd732bf --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalIndividualUpper.lean @@ -0,0 +1,48 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueCountDifference + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosStoppedArithmetic +open NumberTheoryLean ErdosInverseCounts ErdosInverseHits ErdosModulusRelative + +theorem original_individual_upper : + ∃ C : ℝ,0 < C ∧ ∃ P0 : ℕ,2 ≤ P0 ∧ ∀ P : ℕ,P0 ≤ P → + ∀ (Y d : ℕ) (a : ℕ → ℕ),0 < Y → Squarefree d → + (∀ t ∈ d.primeFactors,P ≤ t) → (P : ℝ)^2 ≤ (Y : ℝ)/(d : ℝ) → + (modulusCount Y (LargePrimeDeletion.cutoffPrimes (P-1)) a d : ℝ) ≤ + C*((Y : ℝ)/(d : ℝ))*SmallSieveFinite.smallEuler (P-1) := by + obtain ⟨C,hC,u0,hu0,hUpper⟩ := SmallSieveUpper.progression_small_upper 2 (by norm_num) + refine ⟨C,hC,⌈u0⌉₊+3,by omega,?_⟩ + intro P hP Y d a _hY hd hlarge hJ + have hd0 : 0 < d := Nat.pos_of_ne_zero hd.ne_zero + have hP0 : 0 < P := by omega + have hU : u0 ≤ ((P-1 : ℕ) : ℝ) := by + exact (Nat.le_ceil u0).trans (by exact_mod_cast (show ⌈u0⌉₊ ≤ P-1 by omega)) + have hUp : ((P-1 : ℕ) : ℝ) < (P : ℝ) := by exact_mod_cast Nat.sub_lt hP0 (by decide : 0 < 1) + have hU0 : 0 ≤ ((P-1 : ℕ) : ℝ) := Nat.cast_nonneg _ + have hpow : ((P-1 : ℕ) : ℝ)^(2 : ℝ) ≤ (Y : ℝ)/(d : ℝ) := by + rw [Real.rpow_two] + exact (pow_le_pow_left₀ hU0 hUp.le 2).trans hJ + have hcop (t : ℕ) (ht : t.Prime) (htu : (t : ℝ) ≤ ((P-1 : ℕ) : ℝ)) : d.Coprime t := by + apply large_modulus_coprime_small ((P-1 : ℕ) : ℝ) d hd _ t ht htu + intro q hq + exact hUp.trans_le (by exact_mod_cast hlarge q hq) + have hb := primeHitRepresentative_spec d hd a + have hN := hitLength_error Y d (primeHitRepresentative d hd a) hd0 hb.1 hb.2.1 + have hh := hUpper (hitLength Y d (primeHitRepresentative d hd a)) ((P-1 : ℕ) : ℝ) + ((Y : ℝ)/(d : ℝ)) (primeHitRepresentative d hd a : ℤ) d a hU hpow hN hcop + simp only [Nat.floor_natCast] at hh + rw [modulus_count_eq_offsets Y _ a d hd,offsets_eq_progression,Int.cast_natCast] + exact hh + +end ErdosStoppedArithmetic + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalPairRows.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalPairRows.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c5589d64640b6f78eb162fc33b9b35ccc3830c1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalPairRows.lean @@ -0,0 +1,168 @@ +import OAI.NumberTheory.Jacobsthal.Primes.WeightedPrimeMultiplePairs +import OAI.NumberTheory.Jacobsthal.Sieve.HypotheticalResidues + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosHypotheticalTag +open ErdosInverseAlignment ErdosAlignedProgression ErdosInverseCounts +attribute [local instance] Classical.decEq + +theorem hypothetical_small_parameters (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d p : ℕ) [NeZero p] (hp : p ∉ small) : + parameterCandidates Y small (hypotheticalClass a r p) r d = parameterCandidates Y small a r d := by + ext m + simp only [parameterCandidates, Finset.mem_filter] + apply and_congr_right + intro _hI + apply and_congr_right + intro _hdiv + apply forall_congr' + intro s + apply forall_congr' + intro hs + have hsp : s ≠ p := by intro h; subst s; exact hp hs + rw [hypothetical_other a r p s hsp] + +theorem hypothetical_count_parameters (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d p : ℕ) [NeZero p] (hd : Squarefree d) (hp : p.Prime) + (hD : r.den.Coprime p) (hsmall : p ∉ small) + (hother : ∀ s ∈ d.primeFactors, s ≠ p → aligns (fun u => (a u : ℤ)) r s) : + modulusCount Y small (hypotheticalClass a r p) d = ((parameterCandidates Y small a r d).card : ℤ) := by + have hall : ∀ s ∈ d.primeFactors, aligns (fun u => (hypotheticalClass a r p u : ℤ)) r s := by + intro s hs + by_cases hsp : s = p + · subst s + exact hypothetical_aligns a r p hp hD + · simpa only [aligns, hypothetical_other a r p s hsp] using hother s hs hsp + rw [modulusCount_eq_parameter_card Y small (hypotheticalClass a r p) r d hd hall, + hypothetical_small_parameters Y small a r d p hsmall] + +end ErdosHypotheticalTag + + +section + +open _root_.Filter +namespace ErdosHypotheticalTag +open ErdosInverseAlignment ErdosAlignedProgression ErdosInverseCounts + +theorem source_all_search_units (Cs : ℝ) : + ∀ᶠ w : ℝ in atTop, 1 < w ∧ ∀ (R : ℝ) (r : ℚ) (p : ℕ), + 0 < R → (r.den : ℝ) ≤ w^Cs → w^((1/4 : ℝ)) ≤ Real.log R/Real.log w → + R ≤ (p : ℝ) → p.Prime → r.den.Coprime p := by + have hpow := (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 1/4)).eventually_gt_atTop Cs + filter_upwards [hpow, eventually_gt_atTop (1 : ℝ)] with w hCs hw + refine ⟨hw, ?_⟩ + intro R r p hR hden hsearch hRp hp + have hw0 : 0 < w := by linarith + have hL : 0 < Real.log w := Real.log_pos hw + have hexp : w^(w^((1/4 : ℝ))) ≤ R := by + have h := (le_div_iff₀ hL).mp hsearch + rw [Real.rpow_def_of_pos hw0] + calc + _ ≤ Real.exp (Real.log R) := Real.exp_le_exp.mpr (by nlinarith [h]) + _ = R := Real.exp_log hR + have hstrict : w^Cs < w^(w^((1/4 : ℝ))) := Real.rpow_lt_rpow_of_exponent_lt hw hCs + have hdp : r.den < p := by + exact_mod_cast hden.trans_lt (hstrict.trans_le (hexp.trans hRp)) + apply Nat.Coprime.symm + apply hp.coprime_iff_not_dvd.mpr + intro hd + exact (not_le_of_gt hdp) (Nat.le_of_dvd r.den_pos hd) + +theorem source_hypothetical_count_parameters (Cs : ℝ) : + ∀ᶠ w : ℝ in atTop, ∀ (R : ℝ) (r : ℚ) (Y : ℕ) (small : Finset ℕ) + (a : ℕ → ℕ) (d p : ℕ) [NeZero p], + 0 < R → (r.den : ℝ) ≤ w^Cs → w^((1/4 : ℝ)) ≤ Real.log R/Real.log w → + R ≤ (p : ℝ) → p.Prime → Squarefree d → p ∉ small → + (∀ s ∈ d.primeFactors, s ≠ p → aligns (fun u => (a u : ℤ)) r s) → + modulusCount Y small (hypotheticalClass a r p) d = + ((parameterCandidates Y small a r d).card : ℤ) := by + filter_upwards [source_all_search_units Cs] with w hw + intro R r Y small a d p inst hR hden hsearch hRp hp hd hsmall hother + exact hypothetical_count_parameters Y small a r d p hd hp + (hw.2 R r p hR hden hsearch hRp hp) hsmall hother + +end ErdosHypotheticalTag + +end + + +namespace ErdosStoppedArithmetic +open ErdosAlignedProgression ErdosHypotheticalTag ErdosInverseAlignment ErdosInverseCounts +attribute [local instance] Classical.propDecidable + +noncomputable def hypotheticalRowCount (Y : ℕ) (small T : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q : ℕ) (hT : ∀ p ∈ T,p.Prime) (p : T) : ℝ := + (modulusCount Y small (@hypotheticalClass a r p.val ⟨(hT p.val p.property).ne_zero⟩) (p.val*q) : ℝ) + +theorem hypothetical_row_parameters (Y : ℕ) (small T : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q : ℕ) (hT : ∀ p ∈ T,p.Prime) (p : T) + (hsf : Squarefree (p.val*q)) (hD : r.den.Coprime p.val) (hsmall : p.val ∉ small) + (hother : ∀ t ∈ (p.val*q).primeFactors,t ≠ p.val → aligns (fun u => (a u : ℤ)) r t) : + hypotheticalRowCount Y small T a r q hT p = ((parameterCandidates Y small a r (p.val*q)).card : ℝ) := by + let : NeZero p.val := ⟨(hT p.val p.property).ne_zero⟩ + unfold hypotheticalRowCount + rw [hypothetical_count_parameters Y small a r (p.val*q) p.val hsf (hT p.val p.property) hD hsmall hother, + Int.cast_natCast] + +theorem parameter_value_integer (Y : ℕ) (r : ℚ) (d : ℕ) (hd : 0 < d) (m : ℤ) + (hI : m ∈ parameterInterval Y r d) (hdiv : (r.den : ℤ) ∣ r.num+(d : ℤ)*m) : + (parameterValue r d m : ℤ)=(r.num+(d : ℤ)*m)/(r.den : ℤ) := by + have hs := parameterValue_spec Y r d hd m hI hdiv + have hD : (r.den : ℤ) ≠ 0 := by exact_mod_cast r.den_ne_zero + rw [← hs.2.2,Int.mul_ediv_cancel_left _ hD] + +theorem actual_test_mem_parameters (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d : ℕ) (hd : 0 < d) (m : ℤ) (hI : m ∈ parameterInterval Y r d) + (hdiv : (r.den : ℤ) ∣ r.num+(d : ℤ)*m) + (hAvoid : ∀ t ∈ small,¬Int.ModEq (t : ℤ) ((r.num+(d : ℤ)*m)/(r.den : ℤ)) (a t : ℤ)) : + m ∈ parameterCandidates Y small a r d := by + apply Finset.mem_filter.mpr + refine ⟨hI,hdiv,?_⟩ + intro t ht he + have hNat : Nat.ModEq t (parameterValue r d m) (a t) := he + have hInt : Int.ModEq (t : ℤ) (parameterValue r d m : ℤ) (a t : ℤ) := + (Int.natCast_modEq_iff).mpr hNat + rw [parameter_value_integer Y r d hd m hI hdiv] at hInt + exact hAvoid t ht hInt + +theorem pair_count_le_hypothetical_sum (Y : ℕ) (small T : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (q : ℕ) (hT : ∀ p ∈ T,p.Prime) (M : Finset ℤ) (good : ℕ → ℤ → Prop) + (hGeometry : ∀ p ∈ T,Squarefree (p*q) ∧ r.den.Coprime p ∧ p ∉ small ∧ + ∀ t ∈ (p*q).primeFactors,t ≠ p → aligns (fun u => (a u : ℤ)) r t) + (hCommon : ∀ p ∈ T,∀ m ∈ M,good p m → m ∈ parameterInterval Y r (p*q)) + (hGood : ∀ p ∈ T,∀ m ∈ M,good p m → + (r.den : ℤ) ∣ r.num+((p*q : ℕ) : ℤ)*m ∧ + ∀ t ∈ small,¬Int.ModEq (t : ℤ) ((r.num+((p*q : ℕ) : ℤ)*m)/(r.den : ℤ)) (a t : ℤ)) : + ((admissiblePairs T M good).card : ℝ) ≤ ∑ p : T,hypotheticalRowCount Y small T a r q hT p := by + have hRows : (admissiblePairs T M good).card ≤ + ∑ p ∈ T,(parameterCandidates Y small a r (p*q)).card := by + rw [admissible_pair_card_rows] + apply Finset.sum_le_sum + intro p hp + apply Finset.card_le_card + intro m hm + have hmM := (Finset.mem_filter.mp hm).1 + have hcond := hGood p hp m hmM (Finset.mem_filter.mp hm).2 + exact actual_test_mem_parameters Y small a r (p*q) + (Nat.pos_of_ne_zero (hGeometry p hp).1.ne_zero) m (hCommon p hp m hmM (Finset.mem_filter.mp hm).2) hcond.1 hcond.2 + calc + _ ≤ ∑ p ∈ T,((parameterCandidates Y small a r (p*q)).card : ℝ) := by exact_mod_cast hRows + _ = ∑ p : T,((parameterCandidates Y small a r (p.val*q)).card : ℝ) := (Finset.sum_coe_sort T _).symm + _ = _ := by + apply Finset.sum_congr rfl + intro p _hp + have hg := hGeometry p.val p.property + exact (hypothetical_row_parameters Y small T a r q hT p hg.1 hg.2.1 hg.2.2.1 hg.2.2.2).symm + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalSubbinLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalSubbinLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e03852d56fa92fe5a84fb17bde8270fd3055f9e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/HypotheticalSubbinLower.lean @@ -0,0 +1,91 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CommonSliceGeometry +import OAI.NumberTheory.Jacobsthal.Paths.TagPairBinding + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedArithmetic +open ErdosStoppedTagSieve Erdos970Dependency.SiegelWalfisz + Erdos970.EulerWeightedLower ErdosCommonMInterval ErdosAlignedProgression + ErdosInverseAlignment ErdosPrimeInputs.MertensStrong + +attribute [local instance] Classical.propDecidable + +theorem subbin_primality (R V : ℝ) : ∀ p ∈ intervalPrimes R V 1 0,p.Prime := by + intro p hp + exact ((mem_intervalPrimes R V 1 0 p).mp hp).1 + +theorem hypothetical_subbin_lower (Cs : ℝ) (hCs : 0 ≤ Cs) : + ∃ K : ℝ,0 < K ∧ ∀ rho xi : ℝ,1 < rho → 0 < xi → + ∃ w0 : ℝ,4 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → ∀ P R V : ℝ, + Real.exp (K*(Real.log w)^3) ≤ P → P ≤ Real.exp (rho*K*(Real.log w)^3) → + Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ R → + xi/(16*w^(2*Cs+10)) ≤ V/R → V/R ≤ w^(-(2*Cs+10)) → + ∀ Y q : ℕ,0 < Y → 0 < q → ∀ r : ℚ,∀ a : ℕ → ℕ, + (r.den : ℝ) ≤ w^Cs → |(r.num : ℝ)| ≤ (Y : ℝ)*w^(Cs+2) → + 203/100 ≤ lengthExponent P Y R q → lengthExponent P Y R q ≤ 219/100 → + (∀ t ∈ smallPrimeSet P,q.Coprime t) → + (∀ p ∈ intervalPrimes R V 1 0,Squarefree (p*q) ∧ r.den.Coprime p ∧ + p ∉ smallPrimeSet P ∧ ∀ t ∈ (p*q).primeFactors,t ≠ p → + aligns (fun u => (a u : ℤ)) r t) → + (39/100 : ℝ)*((intervalPrimes R V 1 0).card : ℝ)*referenceLength Y R q*primeProduct P ≤ + ∑ p : intervalPrimes R V 1 0, + hypotheticalRowCount Y (smallPrimeSet P) (intervalPrimes R V 1 0) a r q + (subbin_primality R V) p := by + obtain ⟨K,hK,hPairs⟩ := moving_subbin_actual_pair_lower Cs hCs + refine ⟨K,hK,?_⟩ + intro rho xi hrho hxi + obtain ⟨wA,hwA,hA⟩ := hPairs rho xi hrho hxi + obtain ⟨wC,hC⟩ := uniform_integer_common_interval Cs K (1/1000) hCs hK (by norm_num) (by norm_num) + refine ⟨max wA wC,hwA.trans (le_max_left _ _),?_⟩ + intro w hw P R V hPl hPu hR hVlo hVhi Y q hY hq r a hDen hNum hs hsU hqSmall hGeometry + have hw4 : 4 ≤ w := hwA.trans ((le_max_left _ _).trans hw) + have hw1 : 1 < w := by linarith + have hR0 : 0 < R := (Real.exp_pos _).trans_le hR + have hRatio : 0 < V/R := (div_pos hxi (by positivity)).trans_le hVlo + have hV : 0 < V := (div_pos_iff.mp hRatio).resolve_right (by intro h;linarith [h.2]) |>.1 + have hWidth : R+V ≤ (1+w^(-2*Cs-10))*R := by + have hh := (div_le_iff₀ hR0).mp hVhi + rw [show -(2*Cs+10)= -2*Cs-10 by ring] at hh + nlinarith + have hP1 : 1 < P := by + have he : 1 < Real.exp (K*(Real.log w)^3) := Real.one_lt_exp_iff.mpr + (mul_pos hK (pow_pos (Real.log_pos hw1) _)) + exact he.trans_le hPl + have hb := hC w ((le_max_right _ _).trans hw) P R (R+V) r.num r.den Y q hPl + r.den_pos hDen hY hq hR0 (by linarith) hWidth hNum (by linarith) + have hJid := reference_rpow hP1 (show (0 : ℝ) < Y by exact_mod_cast hY) hR0 + (show (0 : ℝ) < q by exact_mod_cast hq) + have hLength : (999/1000 : ℝ)*(r.den : ℝ)*P^(lengthExponent P Y R q) ≤ + upper r.num r.den Y q R (R+V)-lower r.num q R (R+V) := by + rw [hJid] + convert hb.1 using 1 + norm_num + have hHeight := common_slice_endpoint_height w Cs P R (R+V) r.num r.den Y q + hw1.le hP1 hDen hY hq hR0 hNum hb.2.2.1 + have hPair := hA w ((le_max_left _ _).trans hw) P (lengthExponent P Y R q) + (lower r.num q R (R+V)) (upper r.num r.den Y q R (R+V)) R V hPl hPu + hs hsU hR hVlo hVhi r hDen q a hqSmall hLength hHeight + rw [hJid] at hPair + apply hPair.trans + apply pair_count_le_hypothetical_sum Y (smallPrimeSet P) (intervalPrimes R V 1 0) a r q + (subbin_primality R V) _ (actualTagGood P r q a) hGeometry + · intro p hp m hm hGood + obtain ⟨d,_hd,hm⟩ := Finset.mem_biUnion.mp hm + have hEnds := (mem_primeMultiplesIn d P _ _ m).mp hm + have hpBounds := (mem_intervalPrimes R V 1 0 p).mp hp + exact common_slice_mem_parameter Y q p r R (R+V) m hq hR0 hpBounds.2.1.le + hpBounds.2.2.1 ⟨hEnds.1.le,hEnds.2.1.le⟩ + (actual_tag_original_tests P r q p a m hGood).1 + · intro p _hp m _hm hGood + exact actual_tag_original_tests P r q p a m hGood + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/InitialOddDraw.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/InitialOddDraw.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c4e660822d1566330c4bc7e665e718e527d469e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/InitialOddDraw.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.UniformCycleMoments + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.InitialOddDraw + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostProcess PairedCostGrouping +open KernelDensityBridge CycleCostMoments PairedDrift CompactExponentialMoments + +noncomputable def firstOddUpdate (t : OddState) : OddCost := (t, cost t.1) + +theorem firstOddUpdate_measurable : Measurable firstOddUpdate := + measurable_id.prodMk (cost_measurable.comp measurable_subtype_coe) + +noncomputable def firstOdd : Kernel EvenState OddCost := evenToOdd.map firstOddUpdate + +instance firstOdd_isMarkovKernel : IsMarkovKernel firstOdd := + Kernel.IsMarkovKernel.map _ firstOddUpdate_measurable + +theorem firstOdd_full_draw (s : EvenState) : + (firstOdd s).map embedOdd = costKernel (.inl s, 0) := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH embedOdd_measurable, firstOdd, Kernel.map_apply _ firstOddUpdate_measurable, + lintegral_map (f := fun z : OddCost => H (embedOdd z)) (hH.comp embedOdd_measurable) firstOddUpdate_measurable] + simpa only [embedOdd, firstOddUpdate, zero_add] using (costKernel_even_lintegral s 0 hH).symm + +theorem firstOdd_cost_bounds (s : EvenState) : ∀ᵐ z ∂firstOdd s, + 0 ≤ z.2 ∧ z.2 ≤ Real.log 3 := by + rw [firstOdd, Kernel.map_apply _ firstOddUpdate_measurable] + apply (ae_map_iff firstOddUpdate_measurable.aemeasurable + ((measurableSet_le measurable_const measurable_snd).inter (measurableSet_le measurable_snd measurable_const))).mpr + exact Eventually.of_forall fun t => + ⟨(cost_pos (by linarith [t.2])).le, draw_cost_le_log_three (by linarith [t.2])⟩ + +theorem firstOdd_drift_lintegral (s : EvenState) {D : ℝ} (hD : 0 ≤ D) : + (∫⁻ z, ENNReal.ofReal (V z.1 + D) ∂firstOdd s) = + (∫⁻ t, ENNReal.ofReal (Real.exp t) ∂evenKernel s) + ENNReal.ofReal D := by + rw [firstOdd, Kernel.map_apply _ firstOddUpdate_measurable, + lintegral_map (f := fun z : OddCost => ENNReal.ofReal (V z.1 + D)) + (ENNReal.measurable_ofReal.comp ((V_measurable.comp measurable_fst).add measurable_const)) firstOddUpdate_measurable] + change (∫⁻ t : OddState, ENNReal.ofReal (Real.exp t.1 + D) ∂evenToOdd s) = _ + rw [evenToOdd_lintegral_ratio s (H := fun t : ℝ => ENNReal.ofReal (Real.exp t + D)) + (ENNReal.measurable_ofReal.comp (Real.measurable_exp.add measurable_const))] + simp_rw [ENNReal.ofReal_add (Real.exp_pos _).le hD] + rw [lintegral_add_left (f := fun t : ℝ => ENNReal.ofReal (Real.exp t)) + (ENNReal.measurable_ofReal.comp Real.measurable_exp), lintegral_const, measure_univ, mul_one] + +theorem firstOdd_weighted_exponential (S η D : ℝ) (hη : 0 ≤ η) (hD : 0 ≤ D) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ s : EvenState, s.1 ≤ S → + (∫⁻ z, ENNReal.ofReal (Real.exp (η * z.2) * (V z.1 + D)) ∂firstOdd s) ≤ ENNReal.ofReal C := by + obtain ⟨B, hB, hb, _⟩ := kernel_compact_exponential_moments S + let C := Real.exp (η * Real.log 3) * (B + D) + have hC : 0 ≤ C := mul_nonneg (Real.exp_pos _).le (add_nonneg hB.le hD) + refine ⟨C, hC, ?_⟩ + intro s hs + calc + _ ≤ ∫⁻ z, ENNReal.ofReal (Real.exp (η * Real.log 3)) * ENNReal.ofReal (V z.1 + D) ∂firstOdd s := by + apply lintegral_mono_ae + filter_upwards [firstOdd_cost_bounds s] with z hz + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le] + exact ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_right + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hz.2 hη)) (add_nonneg (V_pos z.1).le hD)) + _ = ENNReal.ofReal (Real.exp (η * Real.log 3)) * + ((∫⁻ t, ENNReal.ofReal (Real.exp t) ∂evenKernel s) + ENNReal.ofReal D) := by + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, firstOdd_drift_lintegral s hD] + _ ≤ ENNReal.ofReal (Real.exp (η * Real.log 3)) * (ENNReal.ofReal B + ENNReal.ofReal D) := by + apply mul_le_mul le_rfl _ zero_le zero_le + apply add_le_add _ le_rfl + rw [← ofReal_integral_eq_lintegral_ofReal (hb s hs).1 (Eventually.of_forall fun t => (Real.exp_pos t).le)] + exact ENNReal.ofReal_le_ofReal (hb s hs).2 + _ = _ := by rw [← ENNReal.ofReal_add hB.le hD, ← ENNReal.ofReal_mul (Real.exp_pos _).le] + +end NumberTheoryLean.InitialOddDraw + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/InvariantFiniteness.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/InvariantFiniteness.lean new file mode 100644 index 0000000000000000000000000000000000000000..57215906018d2ba725bb86c8dbbb962bcd6c2f8e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/InvariantFiniteness.lean @@ -0,0 +1,194 @@ +import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals +import OAI.NumberTheory.Jacobsthal.Probability.FirstHitKernels + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped Topology ENNReal +namespace Erdos970Dependency.InvariantDensities +open NumberTheoryLean NumberTheoryLean.BuchstabBridge NumberTheoryLean.DerivativeWeights +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathGeometry + +noncomputable def oddFactor (s : ℝ) : ℝ := 1 - 1 / s ^ 2 +noncomputable def evenDensity (s : ℝ) : ℝ := (Ici (2 : ℝ)).indicator phiEven s +noncomputable def oddDensity (s : ℝ) : ℝ := (Ici (1 : ℝ)).indicator (fun t ↦ oddFactor t * phiOdd t) s + +theorem oddFactor_bounds {s : ℝ} (hs : 1 ≤ s) : 0 ≤ oddFactor s ∧ oddFactor s ≤ 1 := by + have hs0 : 0 < s := by linarith + have hsq : 1 ≤ s ^ 2 := by nlinarith + have hinv : 1 / s ^ 2 ≤ 1 := (div_le_one (sq_pos_of_pos hs0)).mpr hsq + have hnonneg : 0 ≤ 1 / s ^ 2 := by positivity + unfold oddFactor + constructor <;> linarith + +theorem oddFactor_pos {s : ℝ} (hs : 1 < s) : 0 < oddFactor s := by + unfold oddFactor + have hs0 : 0 < s := by linarith + have : 1 / s ^ 2 < 1 := (div_lt_one (sq_pos_of_pos hs0)).mpr (by nlinarith) + linarith + +theorem oddFactor_measurable : Measurable oddFactor := by + unfold oddFactor + fun_prop + +theorem evenDensity_measurable : Measurable evenDensity := + phiEven_measurable.indicator measurableSet_Ici + +theorem oddDensity_measurable : Measurable oddDensity := + (oddFactor_measurable.mul phiOdd_continuous.measurable).indicator measurableSet_Ici + +theorem evenDensity_nonneg (s : ℝ) : 0 ≤ evenDensity s := by + by_cases hs : 2 ≤ s + · rw [evenDensity, indicator_of_mem (show s ∈ Ici (2 : ℝ) from hs)] + exact (phiEven_pos (by linarith)).le + · rw [evenDensity, indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs)] + +theorem oddDensity_nonneg (s : ℝ) : 0 ≤ oddDensity s := by + by_cases hs : 1 ≤ s + · rw [oddDensity, indicator_of_mem (show s ∈ Ici (1 : ℝ) from hs)] + exact mul_nonneg (oddFactor_bounds hs).1 (phiOdd_pos s).le + · rw [oddDensity, indicator_of_notMem (show s ∉ Ici (1 : ℝ) from hs)] + +theorem oddFactor_hasDerivAt {s : ℝ} (hs : s ≠ 0) : + HasDerivAt (fun t : ℝ ↦ t + 1 / t) (oddFactor s) s := by + have h := (hasDerivAt_id s).add ((hasDerivAt_const s (1 : ℝ)).div (hasDerivAt_id s) hs) + convert! h using 1 + simp only [oddFactor, id_eq, zero_mul, zero_sub, mul_one] + ring + +theorem integral_oddFactor {b : ℝ} (hb : 1 ≤ b) : + (∫ s in (1 : ℝ)..b, oddFactor s) = b + 1 / b - 2 := by + have hd : ∀ s ∈ uIcc (1 : ℝ) b, + HasDerivAt (fun t : ℝ ↦ t + 1 / t) (oddFactor s) s := by + intro s hs + rw [uIcc_of_le hb] at hs + exact oddFactor_hasDerivAt (by linarith [hs.1]) + have hi : IntervalIntegrable oddFactor volume 1 b := by + apply ContinuousOn.intervalIntegrable + intro s hs + rw [uIcc_of_le hb] at hs + apply ContinuousAt.continuousWithinAt + unfold oddFactor + exact continuousAt_const.sub (continuousAt_const.div (continuousAt_id.pow 2) (by nlinarith [hs.1])) + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt hd hi + norm_num at h + simpa only [one_div] using h + +noncomputable def beta : ℝ := ∫ s in (1 : ℝ)..3, oddDensity s + +theorem beta_eq : beta = 4 * sieveA / 3 := by + unfold beta + calc + (∫ s in (1 : ℝ)..3, oddDensity s) = ∫ s in (1 : ℝ)..3, sieveA * oddFactor s := by + apply intervalIntegral.integral_congr + intro s hs + rw [uIcc_of_le (by norm_num : (1 : ℝ) ≤ 3)] at hs + rw [oddDensity, indicator_of_mem (show s ∈ Ici (1 : ℝ) from hs.1), phiOdd_initial hs.2, mul_comm] + _ = sieveA * (3 + 1 / 3 - 2) := by + rw [intervalIntegral.integral_const_mul, integral_oddFactor (by norm_num)] + _ = _ := by ring + +theorem beta_pos : 0 < beta := by + rw [beta_eq] + exact div_pos (mul_pos (by norm_num) sieveA_pos) (by norm_num) + +end Erdos970Dependency.InvariantDensities + +end + +section + +open Set Filter MeasureTheory +open scoped Topology ENNReal +namespace Erdos970Dependency.InvariantFiniteness +open NumberTheoryLean NumberTheoryLean.DerivativeWeights NumberTheoryLean.TransitionKernels +open Erdos970Dependency.InvariantDensities + +theorem integrableOn_Ici_of_exp_tail {f : ℝ → ℝ} {a : ℝ} + (hm : Measurable f) (hc : ContinuousOn f (Ici a)) (hn : ∀ s, a ≤ s → 0 ≤ f s) + {C T : ℝ} (hT : a ≤ T) (hb : ∀ s, T ≤ s → f s ≤ C * Real.exp (-s)) : + IntegrableOn f (Ici a) := by + have hcompact : IntegrableOn f (Icc a T) := + (hc.mono Icc_subset_Ici_self).integrableOn_Icc + have htail : IntegrableOn f (Ioi T) := by + apply ((integrableOn_exp_neg_Ioi T).const_mul C).mono_nonneg hm.aestronglyMeasurable + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with s hs + exact hn s (hT.trans hs.le) + · filter_upwards [ae_restrict_mem measurableSet_Ioi] with s hs + exact hb s hs.le + rw [← Icc_union_Ioi_eq_Ici hT] + exact hcompact.union htail + +theorem weights_exp_majorant : ∃ D U : ℝ, 0 < D ∧ 2 ≤ U ∧ ∀ s : ℝ, U ≤ s → + phiEven s ≤ D * Real.exp (-s) ∧ phiOdd s ≤ D * Real.exp (-s) := by + obtain ⟨c, C, hc, hC, hphi⟩ := WeightDickmanComparison.weights_dickman_bounds + obtain ⟨R, hR, T, hT, hrho⟩ := DickmanDecay.rho_exponential_majorant 1 + refine ⟨C * R * Real.exp 2, T + 2, by positivity, by linarith, ?_⟩ + intro s hs + have hs2 : 2 ≤ s := by linarith + have hr := hrho (s - 2) (by linarith) + have heq : Real.exp (-(s - 2)) = Real.exp 2 * Real.exp (-s) := by + rw [← Real.exp_add] + congr 1 + ring + rw [neg_one_mul, heq] at hr + have hbound : C * Dickman.rho (s - 2) ≤ (C * R * Real.exp 2) * Real.exp (-s) := by + have h := mul_le_mul_of_nonneg_left hr hC.le + convert! h using 1 + ring + exact ⟨(hphi s hs2).1.2.trans hbound, (hphi s hs2).2.2.trans hbound⟩ + +theorem phiEven_integrableOn : IntegrableOn phiEven (Ici (2 : ℝ)) := by + obtain ⟨D, U, _, hU, hb⟩ := weights_exp_majorant + apply integrableOn_Ici_of_exp_tail phiEven_measurable ?_ + (fun s hs ↦ (phiEven_pos (by linarith)).le) hU (fun s hs ↦ (hb s hs).1) + intro s hs + exact (phiEven_continuousAt (by change (2 : ℝ) ≤ s at hs; linarith)).continuousWithinAt + +theorem phiOdd_integrableOn : IntegrableOn phiOdd (Ici (1 : ℝ)) := by + obtain ⟨D, U, _, hU, hb⟩ := weights_exp_majorant + exact integrableOn_Ici_of_exp_tail phiOdd_continuous.measurable phiOdd_continuous.continuousOn + (fun s _ ↦ (phiOdd_pos s).le) (show (1 : ℝ) ≤ U by linarith) (fun s hs ↦ (hb s hs).2) + +theorem evenDensity_integrable : Integrable InvariantDensities.evenDensity := + (integrable_indicator_iff measurableSet_Ici).mpr phiEven_integrableOn + +theorem oddDensity_integrable : Integrable InvariantDensities.oddDensity := by + apply (integrable_indicator_iff measurableSet_Ici).mpr + apply phiOdd_integrableOn.mono_nonneg + (oddFactor_measurable.mul phiOdd_continuous.measurable).aestronglyMeasurable + · filter_upwards [ae_restrict_mem measurableSet_Ici] with s hs + exact mul_nonneg (oddFactor_bounds hs).1 (phiOdd_pos s).le + · filter_upwards [ae_restrict_mem measurableSet_Ici] with s hs + have h := mul_le_mul_of_nonneg_right (oddFactor_bounds hs).2 (phiOdd_pos s).le + convert! h using 1 + simp only [one_mul] + +noncomputable def evenMeasure : Measure ℝ := volume.withDensity (fun s ↦ ENNReal.ofReal (InvariantDensities.evenDensity s)) +noncomputable def oddMeasure : Measure ℝ := volume.withDensity (fun s ↦ ENNReal.ofReal (InvariantDensities.oddDensity s)) + +instance evenMeasure_isFiniteMeasure : IsFiniteMeasure evenMeasure := by + constructor + rw [evenMeasure, withDensity_apply _ MeasurableSet.univ, setLIntegral_univ, + ← ofReal_integral_eq_lintegral_ofReal evenDensity_integrable + (Filter.Eventually.of_forall InvariantDensities.evenDensity_nonneg)] + exact ENNReal.ofReal_lt_top + +instance oddMeasure_isFiniteMeasure : IsFiniteMeasure oddMeasure := by + constructor + rw [oddMeasure, withDensity_apply _ MeasurableSet.univ, setLIntegral_univ, + ← ofReal_integral_eq_lintegral_ofReal oddDensity_integrable + (Filter.Eventually.of_forall InvariantDensities.oddDensity_nonneg)] + exact ENNReal.ofReal_lt_top + +end Erdos970Dependency.InvariantFiniteness + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/InverseWeightGrowth.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/InverseWeightGrowth.lean new file mode 100644 index 0000000000000000000000000000000000000000..1564018f9066b946e4952ed37b88e4fbf4da4785 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/InverseWeightGrowth.lean @@ -0,0 +1,433 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FiniteHistorySupport +import OAI.NumberTheory.Jacobsthal.Renewal.WeightDickmanComparison + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.WeightTailBounds + +open Filter Set +open scoped Topology +open DerivativeWeights WeightDickmanComparison + +theorem ratio_upper_from_rho {s c C p q : ℝ} (hs : 4 ≤ s) + (hc : 0 < c) (hC : 0 < C) (hp : 0 < p) + (hpl : c * Dickman.rho (s - 2) ≤ p) (hqu : q ≤ C * Dickman.rho (s - 3)) : + q / p ≤ (4 * C / c) * s ^ 2 := by + have hr : Dickman.rho (s - 3) ≤ 4 * (s - 2) ^ 2 * Dickman.rho (s - 2) := by + convert! Dickman.rho_lower_comparison (u := s - 2) (by linarith) using 1 + congr 1 + ring + have hr' : Dickman.rho (s - 3) ≤ 4 * s ^ 2 * Dickman.rho (s - 2) := by + apply le_trans hr + exact mul_le_mul_of_nonneg_right (by nlinarith) (Dickman.rho_nonneg _) + have hρ : Dickman.rho (s - 2) ≤ p / c := (le_div_iff₀ hc).mpr (by nlinarith) + have hq : q ≤ ((4 * C / c) * s ^ 2) * p := by + calc + q ≤ C * Dickman.rho (s - 3) := hqu + _ ≤ C * (4 * s ^ 2 * Dickman.rho (s - 2)) := mul_le_mul_of_nonneg_left hr' hC.le + _ ≤ C * (4 * s ^ 2 * (p / c)) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left hρ (by positivity)) hC.le + _ = _ := by ring + exact (div_le_iff₀ hp).mpr hq + +theorem weights_ratio_bound : ∃ K : ℝ, 0 < K ∧ ∀ s : ℝ, 4 ≤ s → + phiOdd (s - 1) / phiEven s ≤ K * s ^ 2 ∧ + phiEven (s - 1) / phiOdd s ≤ K * s ^ 2 := by + obtain ⟨c, C, hc, hC, hb⟩ := weights_dickman_bounds + refine ⟨4 * C / c, by positivity, ?_⟩ + intro s hs + have hsp : 2 ≤ s - 1 := by linarith + have he := (hb (s - 1) hsp).1.2 + have ho := (hb (s - 1) hsp).2.2 + rw [show s - 1 - 2 = s - 3 by ring] at he ho + exact ⟨ratio_upper_from_rho hs hc hC (phiEven_pos (by linarith)) (hb s (by linarith)).1.1 ho, + ratio_upper_from_rho hs hc hC (phiOdd_pos s) (hb s (by linarith)).2.1 he⟩ + +theorem even_logDeriv_eq {s : ℝ} (hs : 1 < s) : + -deriv phiEven s / phiEven s = s / (s - 1) ^ 2 * (phiOdd (s - 1) / phiEven s) := by + rw [(phiEven_hasDerivAt hs).deriv] + ring + +theorem odd_logDeriv_eq {s : ℝ} (hs : 3 < s) : + -deriv phiOdd s / phiOdd s = s / (s - 1) ^ 2 * (phiEven (s - 1) / phiOdd s) := by + rw [(phiOdd_hasDerivAt hs).deriv] + ring + +theorem weights_logDeriv_upper : ∃ K : ℝ, 0 < K ∧ ∀ s : ℝ, 4 ≤ s → + (0 ≤ -deriv phiEven s / phiEven s ∧ -deriv phiEven s / phiEven s ≤ K * s ^ 3) ∧ + (0 ≤ -deriv phiOdd s / phiOdd s ∧ -deriv phiOdd s / phiOdd s ≤ K * s ^ 3) := by + obtain ⟨K, hK, hb⟩ := weights_ratio_bound + refine ⟨K, hK, ?_⟩ + intro s hs + have hs1 : 1 < s := by linarith + have hs3 : 3 < s := by linarith + rw [even_logDeriv_eq hs1, odd_logDeriv_eq hs3] + have hcoeff : s / (s - 1) ^ 2 ≤ s := by + apply (div_le_iff₀ (sq_pos_of_pos (by linarith))).mpr + nlinarith + have hcoeff0 : 0 ≤ s / (s - 1) ^ 2 := by positivity + have he0 : 0 ≤ phiOdd (s - 1) / phiEven s := + (div_pos (phiOdd_pos _) (phiEven_pos hs1)).le + have ho0 : 0 ≤ phiEven (s - 1) / phiOdd s := + (div_pos (phiEven_pos (by linarith)) (phiOdd_pos s)).le + constructor + · refine ⟨mul_nonneg hcoeff0 he0, ?_⟩ + calc + _ ≤ s * (K * s ^ 2) := mul_le_mul hcoeff (hb s hs).1 he0 (by linarith) + _ = _ := by ring + · refine ⟨mul_nonneg hcoeff0 ho0, ?_⟩ + calc + _ ≤ s * (K * s ^ 2) := mul_le_mul hcoeff (hb s hs).2 ho0 (by linarith) + _ = _ := by ring + +theorem slope_lower_from_rho {s c C p q : ℝ} (hs : 4 ≤ s) + (hc : 0 < c) (hC : 0 < C) (hp : 0 < p) + (hpu : p ≤ C * Dickman.rho (s - 2)) (hql : c * Dickman.rho (s - 3) ≤ q) : + (c / (2 * C)) * DickmanDecay.hazard (s - 2) ≤ + s / (s - 1) ^ 2 * (q / p) := by + have hnum : 0 ≤ c * Dickman.rho (s - 3) := (mul_pos hc (Dickman.rho_pos _)).le + have hratio : (c * Dickman.rho (s - 3)) / (C * Dickman.rho (s - 2)) ≤ q / p := by + calc + _ ≤ (c * Dickman.rho (s - 3)) / p := div_le_div_of_nonneg_left hnum hp hpu + _ ≤ q / p := div_le_div_of_nonneg_right hql hp.le + have hcoeff : 1 / (2 * (s - 2)) ≤ s / (s - 1) ^ 2 := by + apply (div_le_div_iff₀ (by linarith : 0 < 2 * (s - 2)) (sq_pos_of_pos (by linarith))).mpr + nlinarith + have hbase : 0 ≤ (c * Dickman.rho (s - 3)) / (C * Dickman.rho (s - 2)) := + (div_pos (mul_pos hc (Dickman.rho_pos _)) (mul_pos hC (Dickman.rho_pos _))).le + calc + _ = (1 / (2 * (s - 2))) * ((c * Dickman.rho (s - 3)) / (C * Dickman.rho (s - 2))) := by + unfold DickmanDecay.hazard + rw [show s - 2 - 1 = s - 3 by ring] + field_simp + _ ≤ _ := mul_le_mul hcoeff hratio hbase (by positivity) + +theorem weights_logDeriv_ge_hazard : ∃ k : ℝ, 0 < k ∧ ∀ s : ℝ, 4 ≤ s → + k * DickmanDecay.hazard (s - 2) ≤ -deriv phiEven s / phiEven s ∧ + k * DickmanDecay.hazard (s - 2) ≤ -deriv phiOdd s / phiOdd s := by + obtain ⟨c, C, hc, hC, hb⟩ := weights_dickman_bounds + refine ⟨c / (2 * C), by positivity, ?_⟩ + intro s hs + have hsp : 2 ≤ s - 1 := by linarith + have he := (hb (s - 1) hsp).1.1 + have ho := (hb (s - 1) hsp).2.1 + rw [show s - 1 - 2 = s - 3 by ring] at he ho + rw [even_logDeriv_eq (by linarith), odd_logDeriv_eq (by linarith)] + exact ⟨slope_lower_from_rho hs hc hC (phiEven_pos (by linarith)) (hb s (by linarith)).1.2 ho, + slope_lower_from_rho hs hc hC (phiOdd_pos s) (hb s (by linarith)).2.2 he⟩ + +theorem weights_logDeriv_growth (rate : ℝ) : ∃ U : ℝ, 4 ≤ U ∧ ∀ s : ℝ, U ≤ s → + rate ≤ -deriv phiEven s / phiEven s ∧ rate ≤ -deriv phiOdd s / phiOdd s := by + obtain ⟨k, hk, hkb⟩ := weights_logDeriv_ge_hazard + obtain ⟨T, hT, ht⟩ := DickmanDecay.exists_hazard_tail (rate / k) + refine ⟨T + 2, by linarith, ?_⟩ + intro s hs + have h : rate ≤ k * DickmanDecay.hazard (s - 2) := by + have ht' := mul_le_mul_of_nonneg_left (ht (s - 2) (by linarith)) hk.le + have heq : k * (rate / k) = rate := by field_simp + rwa [heq] at ht' + exact ⟨le_trans h (hkb s (by linarith)).1, le_trans h (hkb s (by linarith)).2⟩ + +end NumberTheoryLean.WeightTailBounds + +end + +section + +namespace NumberTheoryLean.WeightGlobalBounds + +open Filter Set +open scoped Topology +open LinearSieveFunctions BuchstabBridge DerivativeWeights WeightTailBounds + +theorem weights_global_ratio_bound : ∃ C : ℝ, 0 < C ∧ + (∀ s : ℝ, 198 / 100 ≤ s → phiOdd (s - 1) / phiEven s ≤ C * (1 + s) ^ 2) ∧ + (∀ s : ℝ, 95 / 100 ≤ s → phiEven (max 2 (s - 1)) / phiOdd s ≤ C * (1 + s) ^ 2) := by + obtain ⟨K, hK, hb⟩ := weights_ratio_bound + let E : ℝ := sieveA / phiEven 4 + let O : ℝ := phiEven 2 / phiOdd 4 + have hE : 0 < E := div_pos sieveA_pos (phiEven_pos (by norm_num)) + have hO : 0 < O := div_pos (phiEven_pos (by norm_num)) (phiOdd_pos 4) + let C := K + E + O + have hC : 0 < C := by dsimp [C]; positivity + have hKC : K ≤ C := by dsimp [C]; linarith + have hEC : E ≤ C := by dsimp [C]; linarith + have hOC : O ≤ C := by dsimp [C]; linarith + have hlarge : ∀ s : ℝ, 0 ≤ s → K * s ^ 2 ≤ C * (1 + s) ^ 2 := by + intro s hs + exact mul_le_mul hKC (by nlinarith) (sq_nonneg _) hC.le + have hsmall : ∀ s : ℝ, 0 ≤ s → C ≤ C * (1 + s) ^ 2 := by + intro s hs + nlinarith [mul_le_mul_of_nonneg_left (show (1 : ℝ) ≤ (1 + s) ^ 2 by nlinarith) hC.le] + refine ⟨C, hC, ?_, ?_⟩ + · intro s hs + have hs1 : 1 < s := by linarith + by_cases hs4 : s ≤ 4 + · have hden : phiEven 4 ≤ phiEven s := + phiEven_strictAntiOn.antitoneOn hs1 (by norm_num) hs4 + rw [phiOdd_initial (s := s - 1) (by linarith)] + exact le_trans (div_le_div_of_nonneg_left sieveA_pos.le (phiEven_pos (by norm_num)) hden) + (le_trans hEC (hsmall s (by linarith))) + · exact le_trans (hb s (le_of_not_ge hs4)).1 (hlarge s (by linarith)) + · intro s hs + by_cases hs4 : s ≤ 4 + · have hm2 : 2 ≤ max 2 (s - 1) := le_max_left _ _ + have hnum : phiEven (max 2 (s - 1)) ≤ phiEven 2 := + phiEven_strictAntiOn.antitoneOn (by norm_num) (by change 1 < max 2 (s - 1); linarith) hm2 + have hden : phiOdd 4 ≤ phiOdd s := phiOdd_antitone hs4 + have hr : phiEven (max 2 (s - 1)) / phiOdd s ≤ O := by + calc + _ ≤ phiEven 2 / phiOdd s := div_le_div_of_nonneg_right hnum (phiOdd_pos s).le + _ ≤ _ := div_le_div_of_nonneg_left (phiEven_pos (by norm_num)).le (phiOdd_pos 4) hden + exact le_trans hr (le_trans hOC (hsmall s (by linarith))) + · rw [max_eq_right (show 2 ≤ s - 1 by linarith)] + exact le_trans (hb s (le_of_not_ge hs4)).2 (hlarge s (by linarith)) + +theorem weights_global_logDeriv_bound : ∃ C : ℝ, 0 < C ∧ + (∀ s : ℝ, 198 / 100 ≤ s → + |deriv phiEven s / phiEven s| ≤ C * (1 + s) ^ 3) ∧ + (∀ s : ℝ, 3 < s → |deriv phiOdd s / phiOdd s| ≤ C * (1 + s) ^ 3) := by + obtain ⟨C, hC, he, ho⟩ := weights_global_ratio_bound + refine ⟨4 * C, by positivity, ?_, ?_⟩ + · intro s hs + have hs1 : 1 < s := by linarith + have hcoeff : s / (s - 1) ^ 2 ≤ 4 * (1 + s) := by + apply (div_le_iff₀ (sq_pos_of_pos (by linarith))).mpr + have hsq : (1 : ℝ) / 4 ≤ (s - 1) ^ 2 := by nlinarith + nlinarith [mul_le_mul_of_nonneg_left hsq (show 0 ≤ 4 * (1 + s) by linarith)] + have hr0 : 0 ≤ phiOdd (s - 1) / phiEven s := + (div_pos (phiOdd_pos _) (phiEven_pos hs1)).le + have hn : 0 ≤ -deriv phiEven s / phiEven s := by rw [even_logDeriv_eq hs1]; positivity + have habs : |deriv phiEven s / phiEven s| = -deriv phiEven s / phiEven s := by + rw [abs_of_nonpos (by rw [neg_div] at hn; linarith)] + ring + rw [habs, even_logDeriv_eq hs1] + calc + _ ≤ (4 * (1 + s)) * (C * (1 + s) ^ 2) := mul_le_mul hcoeff (he s hs) hr0 (by linarith) + _ = _ := by ring + · intro s hs + have hcoeff : s / (s - 1) ^ 2 ≤ 4 * (1 + s) := by + apply (div_le_iff₀ (sq_pos_of_pos (by linarith))).mpr + have hsq : 1 ≤ (s - 1) ^ 2 := by nlinarith + nlinarith [mul_le_mul_of_nonneg_left hsq (show 0 ≤ 4 * (1 + s) by linarith)] + have hr : phiEven (s - 1) / phiOdd s ≤ C * (1 + s) ^ 2 := by + have h := ho s (by linarith) + rwa [max_eq_right (show 2 ≤ s - 1 by linarith)] at h + have hr0 : 0 ≤ phiEven (s - 1) / phiOdd s := + (div_pos (phiEven_pos (by linarith)) (phiOdd_pos s)).le + have hn : 0 ≤ -deriv phiOdd s / phiOdd s := by rw [odd_logDeriv_eq hs]; positivity + have habs : |deriv phiOdd s / phiOdd s| = -deriv phiOdd s / phiOdd s := by + rw [abs_of_nonpos (by rw [neg_div] at hn; linarith)] + ring + rw [habs, odd_logDeriv_eq hs] + calc + _ ≤ (4 * (1 + s)) * (C * (1 + s) ^ 2) := mul_le_mul hcoeff hr hr0 (by linarith) + _ = _ := by ring + +theorem interval_abs_bound {H d : ℝ → ℝ} {a b B : ℝ} (hab : a ≤ b) + (hc : ContinuousOn H (Icc a b)) + (hd : ∀ t ∈ Ioo a b, HasDerivAt H (d t) t) + (hb : ∀ t ∈ Ioo a b, |d t| ≤ B) : |H b - H a| ≤ B * (b - a) := by + rcases eq_or_lt_of_le hab with h | h + · subst b + simp + · obtain ⟨t, ht, heq⟩ := exists_deriv_eq_slope H h hc + (fun t ht => (hd t ht).differentiableAt.differentiableWithinAt) + rw [(hd t ht).deriv] at heq + have hbound := hb t ht + rw [heq, abs_div, abs_of_pos (sub_pos.mpr h)] at hbound + exact (div_le_iff₀ (sub_pos.mpr h)).mp hbound + +theorem phiOdd_max_three (s : ℝ) : phiOdd (max 3 s) = phiOdd s := by + by_cases hs : s ≤ 3 + · rw [max_eq_left hs, phiOdd_initial le_rfl, phiOdd_initial hs] + · rw [max_eq_right (le_of_not_ge hs)] + +theorem weights_log_lipschitz : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, 3 ≤ S → + (∀ u v : ℝ, 198 / 100 ≤ u → 198 / 100 ≤ v → u ≤ S → v ≤ S → + |Real.log (phiEven u) - Real.log (phiEven v)| ≤ C * (1 + S) ^ 3 * |u - v|) ∧ + (∀ u v : ℝ, 95 / 100 ≤ u → 95 / 100 ≤ v → u ≤ S → v ≤ S → + |Real.log (phiOdd u) - Real.log (phiOdd v)| ≤ C * (1 + S) ^ 3 * |u - v|) := by + obtain ⟨C, hC, he, ho⟩ := weights_global_logDeriv_bound + refine ⟨C, hC, ?_⟩ + intro S hS + have he_ordered : ∀ u v : ℝ, 198 / 100 ≤ u → u ≤ v → v ≤ S → + |Real.log (phiEven v) - Real.log (phiEven u)| ≤ C * (1 + S) ^ 3 * (v - u) := by + intro u v hu huv hv + apply interval_abs_bound huv + · intro t ht + have ht1 : 1 < t := by linarith [ht.1] + exact ((phiEven_continuousAt ht1).log (ne_of_gt (phiEven_pos ht1))).continuousWithinAt + · intro t ht + exact ((phiEven_hasDerivAt (by linarith [ht.1])).differentiableAt.hasDerivAt.log + (ne_of_gt (phiEven_pos (by linarith [ht.1])))) + · intro t ht + have h := he t (by linarith [ht.1]) + apply le_trans h + apply mul_le_mul_of_nonneg_left _ hC.le + gcongr <;> linarith [ht.1, ht.2] + have ho_ordered : ∀ u v : ℝ, 3 ≤ u → u ≤ v → v ≤ S → + |Real.log (phiOdd v) - Real.log (phiOdd u)| ≤ C * (1 + S) ^ 3 * (v - u) := by + intro u v hu huv hv + apply interval_abs_bound huv + · intro t _ + exact (phiOdd_continuous.continuousAt.log (ne_of_gt (phiOdd_pos t))).continuousWithinAt + · intro t ht + exact ((phiOdd_hasDerivAt (by linarith [ht.1])).differentiableAt.hasDerivAt.log + (ne_of_gt (phiOdd_pos t))) + · intro t ht + have h := ho t (by linarith [ht.1]) + apply le_trans h + apply mul_le_mul_of_nonneg_left _ hC.le + gcongr <;> linarith [ht.1, ht.2] + constructor + · intro u v hu hv huS hvS + rcases le_total u v with huv | hvu + · rw [abs_sub_comm (Real.log (phiEven u)), abs_sub_comm u, abs_of_nonneg (sub_nonneg.mpr huv)] + exact he_ordered u v hu huv hvS + · rw [abs_of_nonneg (sub_nonneg.mpr hvu)] + exact he_ordered v u hv hvu huS + · have ho_clamped : ∀ u v : ℝ, u ≤ v → v ≤ S → + |Real.log (phiOdd v) - Real.log (phiOdd u)| ≤ C * (1 + S) ^ 3 * (v - u) := by + intro u v huv hvS + have hmax : max 3 u ≤ max 3 v := max_le_max_left 3 huv + have hdiff : max 3 v - max 3 u ≤ v - u := by + by_cases hu : u ≤ 3 + · rw [max_eq_left hu] + by_cases hv : v ≤ 3 + · rw [max_eq_left hv] + linarith + · rw [max_eq_right (le_of_not_ge hv)] + linarith + · rw [max_eq_right (le_of_not_ge hu), max_eq_right (show 3 ≤ v by linarith)] + have h := ho_ordered (max 3 u) (max 3 v) (le_max_left _ _) hmax (max_le hS hvS) + rw [phiOdd_max_three, phiOdd_max_three] at h + exact le_trans h (mul_le_mul_of_nonneg_left hdiff (by positivity)) + intro u v _ _ huS hvS + rcases le_total u v with huv | hvu + · rw [abs_sub_comm (Real.log (phiOdd u)), abs_sub_comm u, abs_of_nonneg (sub_nonneg.mpr huv)] + exact ho_clamped u v huv hvS + · rw [abs_of_nonneg (sub_nonneg.mpr hvu)] + exact ho_clamped v u hvu huS + +theorem even_starting_derivative {s : ℝ} (hs : 198 / 100 ≤ s) (hs2 : s < 2) : + phiEven s = s ^ 2 * deriv (startingExtension sieveA) s := by + rw [(startingExtension_hasDerivAt (by linarith : 1 < s)).deriv, phiEven_initial hs2.le] + field_simp + +theorem phiOdd_deriv_initial {s : ℝ} (hs : s ≤ 3) : deriv phiOdd s = 0 := by + by_cases hd : DifferentiableAt ℝ phiOdd s + · have h0 : HasDerivWithinAt phiOdd 0 (Iic s) s := by + apply (hasDerivAt_const s sieveA).hasDerivWithinAt.congr_of_mem + · intro t ht + exact phiOdd_initial (le_trans ht hs) + · exact self_mem_Iic + have h1 := hd.hasDerivAt.hasDerivWithinAt.derivWithin (uniqueDiffWithinAt_Iic s) + have h2 := h0.derivWithin (uniqueDiffWithinAt_Iic s) + exact h1.symm.trans h2 + · exact deriv_zero_of_not_differentiableAt hd + +theorem weights_global_logDeriv_bound_all : ∃ C : ℝ, 0 < C ∧ + (∀ s : ℝ, 198 / 100 ≤ s → |deriv phiEven s / phiEven s| ≤ C * (1 + s) ^ 3) ∧ + (∀ s : ℝ, 95 / 100 ≤ s → |deriv phiOdd s / phiOdd s| ≤ C * (1 + s) ^ 3) := by + obtain ⟨C, hC, he, ho⟩ := weights_global_logDeriv_bound + refine ⟨C, hC, he, ?_⟩ + intro s hs + by_cases hs3 : 3 < s + · exact ho s hs3 + · rw [phiOdd_deriv_initial (le_of_not_gt hs3), zero_div, abs_zero] + exact mul_nonneg hC.le (pow_nonneg (by linarith) 3) + +end NumberTheoryLean.WeightGlobalBounds + +end + +section + +namespace NumberTheoryLean.InverseWeightGrowth +open FinitePathGeometry DerivativeWeights WeightGlobalBounds + +private def reference : Side → ℝ | .even => 2 | .odd => 1 + +private theorem reference_valid (i : Side) : Valid i (reference i) := by + cases i <;> norm_num [reference,Valid] + +private theorem reference_bounds (i : Side) : 0 ≤ reference i ∧ reference i ≤ 3 := by + cases i <;> norm_num [reference] + +theorem inverse_weight_quartic : ∃ A C : ℝ, 0 < A ∧ 0 < C ∧ + ∀ i : Side, ∀ t : ℝ, Valid i t → + 1/weight i t ≤ A*Real.exp (C*(1+t)^4) := by + obtain ⟨L,hL,hlocal⟩ := weights_log_lipschitz + let A : ℝ := 1/weight .even 2 + 1/weight .odd 1 + have hE : 0 < 1/weight .even 2 := one_div_pos.mpr (weight_pos (by norm_num [Valid])) + have hO : 0 < 1/weight .odd 1 := one_div_pos.mpr (weight_pos (by norm_num [Valid])) + have hA : 0 < A := add_pos hE hO + refine ⟨A,192*L,hA,by positivity,?_⟩ + intro i t ht + have ht0 := valid_pos ht + have hr := reference_valid i + have hr0 := (reference_bounds i).1 + have hr3 := (reference_bounds i).2 + let S : ℝ := t+3 + have hS : 3 ≤ S := by dsimp [S]; linarith + have htS : t ≤ S := by dsimp [S]; linarith + have hrS : reference i ≤ S := by dsimp [S]; linarith + have hlog : |Real.log (weight i (reference i))-Real.log (weight i t)| ≤ + L*(1+S)^3*|reference i-t| := by + cases i with + | even => exact (hlocal S hS).1 _ _ hr ht hrS htS + | odd => exact (hlocal S hS).2 _ _ hr ht hrS htS + have hdist : |reference i-t| ≤ 3*(1+t) := by + calc + _ ≤ |reference i|+|t| := abs_sub _ _ + _ = reference i+t := by rw [abs_of_nonneg hr0,abs_of_nonneg ht0.le] + _ ≤ _ := by linarith + have hSbound : 1+S ≤ 4*(1+t) := by dsimp [S]; linarith + have hmajor : L*(1+S)^3*|reference i-t| ≤ (192*L)*(1+t)^4 := by + calc + _ ≤ L*(4*(1+t))^3*(3*(1+t)) := mul_le_mul + (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by linarith) hSbound 3) hL.le) + hdist (abs_nonneg _) (by positivity) + _ = _ := by ring + have hdifference : Real.log (weight i (reference i))-Real.log (weight i t) ≤ + (192*L)*(1+t)^4 := ((le_abs_self _).trans hlog).trans hmajor + have hexp := Real.exp_le_exp.mpr hdifference + rw [Real.exp_sub,Real.exp_log (weight_pos hr),Real.exp_log (weight_pos ht)] at hexp + have hreference : 1/weight i (reference i) ≤ A := by + cases i <;> dsimp [reference,A] <;> linarith + calc + _ = (1/weight i (reference i))*(weight i (reference i)/weight i t) := by + field_simp [(weight_pos hr).ne'] + _ ≤ (1/weight i (reference i))*Real.exp ((192*L)*(1+t)^4) := + mul_le_mul_of_nonneg_left hexp (one_div_nonneg.mpr (weight_pos hr).le) + _ ≤ _ := mul_le_mul_of_nonneg_right hreference (Real.exp_pos _).le + +theorem inverse_phi_quartic : ∃ A C : ℝ, 0 < A ∧ 0 < C ∧ + (∀ t : ℝ, 198/100 ≤ t → 1/phiEven t ≤ A*Real.exp (C*(1+t)^4)) ∧ + (∀ t : ℝ, 95/100 ≤ t → 1/phiOdd t ≤ A*Real.exp (C*(1+t)^4)) := by + obtain ⟨A,C,hA,hC,h⟩ := inverse_weight_quartic + exact ⟨A,C,hA,hC,h .even,h .odd⟩ + +theorem inverse_weight_below_cutoff : ∃ A C : ℝ, 0 < A ∧ 0 < C ∧ + ∀ K : ℝ, ∀ i : Side, ∀ t : ℝ, Valid i t → t ≤ K → + 1/weight i t ≤ A*Real.exp (C*(1+K)^4) := by + obtain ⟨A,C,hA,hC,h⟩ := inverse_weight_quartic + refine ⟨A,C,hA,hC,?_⟩ + intro K i t ht htK + have ht0 := valid_pos ht + exact (h i t ht).trans (mul_le_mul_of_nonneg_left + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (by linarith : 0 ≤ 1+t) (by linarith : 1+t ≤ 1+K) 4) hC.le)) hA.le) + +end NumberTheoryLean.InverseWeightGrowth + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/IsolatedPowerOrdering.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/IsolatedPowerOrdering.lean new file mode 100644 index 0000000000000000000000000000000000000000..0952f2682047f66378fd365ef2a6ef00e7cf77af --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/IsolatedPowerOrdering.lean @@ -0,0 +1,36 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.GeometricInverseGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.IsolatedPowerOrdering +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinEndpoints PrimeBinRepresentatives +open GeometricBinOrdering BoundedEdgeBins BoundedEdgePrimeRange + + +theorem source_power_before_edge {w top xi B alpha M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hpower : w^B=top) + (m : Fin (binCount w top xi) → ℕ) (i j : Fin (binCount w top xi)) + (hi : top^alpha ≤ lower w top xi i) (hj : boundedEdgeBin w top xi Y m M X j) + (hlarge : X < alpha*B) : j < i := by + have htop0 : 0 < top := (zero_lt_one.trans hw).trans htop + have hlog := Real.log_le_log (Real.rpow_pos_of_pos htop0 alpha) hi + rw [Real.log_rpow htop0] at hlog + have ht : Real.log top=B*Real.log w := by rw [← hpower,Real.log_rpow (zero_lt_one.trans hw)] + rw [ht] at hlog + have hlow : alpha*B ≤ leftExponent w (lower w top xi i) := by + apply (le_div_iff₀ (Real.log_pos hw)).mpr + nlinarith + by_contra! hle + have hh := left_exponent_mono hw htop hxi i j hle + have hb := bounded_edge_lower_exponent hw htop hxi m j hj + linarith +end NumberTheoryLean.IsolatedPowerOrdering + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/IsolatedSourceScales.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/IsolatedSourceScales.lean new file mode 100644 index 0000000000000000000000000000000000000000..e857bad5129b13158680a19d498a54d8a99df11d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/IsolatedSourceScales.lean @@ -0,0 +1,35 @@ +import OAI.NumberTheory.Jacobsthal.Primes.CrossingPrimeBin +import OAI.NumberTheory.Jacobsthal.Primes.PaperMissingPrimeWindow + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.IsolatedSourceScales +open _root_.Filter PaperMissingPrimeWindow JacobsthalSourceScale +open scoped Topology + +theorem source_isolated_search_scale {alpha : ℝ} (ha : 0 < alpha) : + ∀ᶠ L : ℝ in atTop,(sourceW L)^((1/4:ℝ)) ≤ alpha*sourceB L := by + have ht := (tendsto_rpow_atTop (show 0 < (3/4:ℝ) by norm_num)).comp sourceW_tendsto + filter_upwards [sourceW_le_sourceB_eventually,sourceW_tendsto.eventually_gt_atTop 0, + ht.eventually_ge_atTop (1/alpha)] with L hB hw hpow + change 1/alpha ≤ (sourceW L)^((3/4:ℝ)) at hpow + have hprod : (sourceW L)^((1/4:ℝ))*(sourceW L)^((3/4:ℝ))=sourceW L := by + rw [← Real.rpow_add hw] + norm_num + have hlow := mul_le_mul_of_nonneg_left hpow (Real.rpow_pos_of_pos hw (1/4:ℝ)).le + rw [hprod] at hlow + have hmain : (sourceW L)^((1/4:ℝ)) ≤ alpha*sourceW L := by + have hm := mul_le_mul_of_nonneg_left hlow ha.le + field_simp [ha.ne'] at hm + nlinarith + exact hmain.trans (mul_le_mul_of_nonneg_left hB ha.le) +end NumberTheoryLean.IsolatedSourceScales + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/JointModelCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/JointModelCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..aa745b49c6a1d7b3af73104e9df478bcb2b3f58c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/JointModelCount.lean @@ -0,0 +1,120 @@ +import OAI.NumberTheory.Jacobsthal.Primes.ActualPrimeSelectors +import OAI.NumberTheory.Jacobsthal.Sieve.CoprimePositionSieve + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceMoments +open NumberTheoryLean ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem zero_jointDensity_full_class (P S : Finset ℕ) (hP : ∀ t ∈ P,t.Prime) + (hz : jointDensity P S = 0) : ∃ t ∈ P,(positionResidues S t).card = t := by + obtain ⟨t,ht,hzero⟩ := Finset.prod_eq_zero_iff.mp hz + have htpos : (0 : ℝ) < t := by exact_mod_cast (hP t ht).pos + have he : ((positionResidues S t).card : ℝ)/(t : ℝ) = 1 := by + change 1-((positionResidues S t).card : ℝ)/(t : ℝ) = 0 at hzero + linarith + refine ⟨t,ht,?_⟩ + exact_mod_cast (div_eq_one_iff_eq htpos.ne').mp he + +theorem zero_coprimeJoint (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) + (hz : jointDensity (coprimePrimes w H) S = 0) (m : ℤ) : + ¬coprimeJoint w H qA delta S m p := by + obtain ⟨t,ht,hfull⟩ := zero_jointDensity_full_class (coprimePrimes w H) S + (fun t ht => (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1) hz + let : NeZero t := ⟨(LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1.ne_zero⟩ + have he : coprimeForbidden w H qA delta S p t ht (hqA t ht) = Finset.univ := + forbiddenClasses_full_of_card _ _ _ _ hfull + intro h + have hav := (coprimeJoint_avoidance w H qA delta S p hqA m).mp h t ht + apply hav + simp only [coprimeForbiddenFamily,dite_eq_left ht,he,Finset.mem_univ] + +theorem zero_coprimePositionSurvivors (w : ℝ) (H qA : ℕ) (delta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (p : (ZMod (coprimeModulus w H))ˣ) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) + (hz : jointDensity (coprimePrimes w H) S = 0) (b c : ℝ) : + coprimePositionSurvivors w H qA delta S p b c = ∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro m hm + exact zero_coprimeJoint w H qA delta S p hqA hz m (Finset.mem_filter.mp hm).2 + +theorem zero_divisorJoint (w : ℝ) (H : ℕ) (C0 : ℤ) (beta : ∀ t : ℕ,ZMod t) + (S : Finset ℕ) (m : ℤ) (hC0 : Int.gcd C0 (H : ℤ) = 1) (hm : m.natAbs.Coprime H) + (hz : jointDensity (divisorPrimes w H) S = 0) : + Finset.univ.filter (divisorJoint w H C0 beta S m) = ∅ := by + have hc := divisorJoint_card_real w H C0 beta S m hC0 hm + rw [hz,mul_zero,Nat.cast_eq_zero] at hc + exact Finset.card_eq_zero.mp hc + +end ErdosVarianceMoments + +end + +section + +namespace ErdosVarianceMoments +open ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem unitInterval_eq_modelUnitIntegers (R xi : ℝ) (H : ℕ) (C0 : ℤ) : + unitIntervalIntegers H (modelLeft R xi (C0 : ℝ)) (modelRight R xi (H : ℝ) (C0 : ℝ)) = + modelUnitIntegers R xi H C0 := by + ext m + simp only [unitIntervalIntegers,modelUnitIntegers,modelIntegers,Finset.mem_filter,Nat.coprime_comm] + +theorem joint_model_card (R xi w : ℝ) (H qA : ℕ) (C0 : ℤ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (hC0 : Int.gcd C0 (H : ℤ) = 1) : + ((modelUniverse R xi w H C0).filter (jointCondition w H C0 qA beta delta S)).card = + (∑ p : (ZMod (coprimeModulus w H))ˣ, + (coprimePositionSurvivors w H qA delta S p (modelLeft R xi (C0 : ℝ)) + (modelRight R xi (H : ℝ) (C0 : ℝ))).card)* + ∏ t ∈ divisorPrimes w H,(t-(positionResidues S t).card) := by + have hsplit : ((modelUniverse R xi w H C0).filter (jointCondition w H C0 qA beta delta S)).card = + ∑ m ∈ modelUnitIntegers R xi H C0, + (Finset.univ.filter (fun s : Pattern w H => jointCondition w H C0 qA beta delta S (m,s))).card := by + simp only [modelUniverse,Finset.product_eq_sprod,Finset.card_filter,Finset.sum_product] + rw [hsplit] + have hc : (∑ m ∈ modelUnitIntegers R xi H C0, + (Finset.univ.filter (fun s : Pattern w H => jointCondition w H C0 qA beta delta S (m,s))).card) = + (∑ m ∈ modelUnitIntegers R xi H C0, + (Finset.univ.filter (coprimeJoint w H qA delta S m)).card)* + ∏ t ∈ divisorPrimes w H,(t-(positionResidues S t).card) := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro m hm + exact conditional_pattern_card w H C0 qA beta delta S m hC0 (Finset.mem_filter.mp hm).2 + rw [hc] + congr 1 + simp only [coprimePositionSurvivors,unitInterval_eq_modelUnitIntegers,Finset.card_filter] + exact Finset.sum_comm + +theorem joint_model_mass (R xi w : ℝ) (H qA : ℕ) (C0 : ℤ) + (beta delta : ∀ t : ℕ,ZMod t) (S : Finset ℕ) (hC0 : Int.gcd C0 (H : ℤ) = 1) : + modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S) = + atomWeight R xi w H C0*((divisorModulus w H : ℝ)*jointDensity (divisorPrimes w H) S)* + ∑ p : (ZMod (coprimeModulus w H))ˣ, + ((coprimePositionSurvivors w H qA delta S p (modelLeft R xi (C0 : ℝ)) + (modelRight R xi (H : ℝ) (C0 : ℝ))).card : ℝ) := by + rw [modelMass_card,joint_model_card R xi w H qA C0 beta delta S hC0,Nat.cast_mul,Nat.cast_sum, + product_allowed_eq_density (divisorPrimes w H) S (fun t ht => + (NumberTheoryLean.LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1)] + change (_*((divisorModulus w H : ℝ)*jointDensity (divisorPrimes w H) S))*_ = _ + ring + +end ErdosVarianceMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/JointReturnCylinder.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/JointReturnCylinder.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce67df87a3a306356ecaf17e9d286bc9262d5e07 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/JointReturnCylinder.lean @@ -0,0 +1,455 @@ +import OAI.NumberTheory.Jacobsthal.Paths.PairCaptureProjection + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.CostReturnLaw + +lemma kernel_comp_comap {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β] + [MeasurableSpace γ] [MeasurableSpace δ] (C : Kernel β γ) (K : Kernel α β) + {f : δ → α} (hf : Measurable f) : + C ∘ₖ (K.comap f hf) = (C ∘ₖ K).comap f hf := by + ext x S hS + rw [Kernel.comp_apply' _ _ _ hS,Kernel.comap_apply,Kernel.comap_apply, + Kernel.comp_apply' _ _ _ hS] + +lemma kernelProjection_power {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + {f : α → β} (hf : Measurable f) (K : Kernel α α) (L : Kernel β β) + (hKL : K.map f=L.comap f hf) (n : ℕ) : + (K^n).map f=(L^n).comap f hf := by + induction n with + | zero => + change Kernel.id.map f = Kernel.id.comap f hf + rw [Kernel.id_map hf,Kernel.id_comap hf] + | succ n ih => + rw [pow_succ',pow_succ'] + change (K ∘ₖ (K^n)).map f=(L ∘ₖ (L^n)).comap f hf + rw [Kernel.map_comp,hKL,← Kernel.comp_map _ _ hf,ih,kernel_comp_comap] + +lemma survivingHistory_zero (a : ℕ) : survivingHistory a 0 = Kernel.id := by + ext h : 1 + rw [survivingHistory,Kernel.restrict_apply] + have hs : avoidOddReturns a 0 (a+2*0) le_rfl = univ := by ext z; simp [avoidOddReturns] + rw [hs,Measure.restrict_univ] + change rawExtension a a h = Kernel.id h + rw [rawExtension,Kernel.partialTraj_self] + +lemma rawKilledPair_kernel_projection (a n : ℕ) : + ((rawExtension (a+2*n) (a+2*(n+1))).restrict (lastRegeneration_measurable _).compl).map + (rawLast (a+2*(n+1))) = fullPairKilled.comap (rawLast (a+2*n)) (rawLast_measurable _) := by + rw [show a+2*(n+1)=(a+2*n)+2 by omega] + ext h : 1 + rw [Kernel.map_apply _ (rawLast_measurable _),Kernel.comap_apply] + exact rawKilledPair_projection (a+2*n) h + +lemma rawCapturedPair_kernel_projection (a n : ℕ) : + ((rawExtension (a+2*n) (a+2*(n+1))).restrict (lastRegeneration_measurable _)).map + (rawLast (a+2*(n+1))) = fullPairCaptured.comap (rawLast (a+2*n)) (rawLast_measurable _) := by + rw [show a+2*(n+1)=(a+2*n)+2 by omega] + ext h : 1 + rw [Kernel.map_apply _ (rawLast_measurable _),Kernel.comap_apply] + exact rawCapturedPair_projection (a+2*n) h + +lemma survivingHistory_kernel_projection (a n : ℕ) : + (survivingHistory a n).map (rawLast (a+2*n)) = + (fullPairKilled^n).comap (rawLast a) (rawLast_measurable a) := by + induction n with + | zero => + rw [survivingHistory_zero] + change Kernel.id.map (rawLast a) = Kernel.id.comap (rawLast a) (rawLast_measurable a) + rw [Kernel.id_map (rawLast_measurable a),Kernel.id_comap (rawLast_measurable a)] + | succ n ih => + rw [survivingHistory_succ,Kernel.map_comp,rawKilledPair_kernel_projection, + ← Kernel.comp_map _ _ (rawLast_measurable _),ih,kernel_comp_comap] + rw [pow_succ'] + rfl + +noncomputable def fullPairReturn (n : ℕ) : Kernel CostState CostState := + fullPairCaptured ∘ₖ (fullPairKilled ^ n) + +lemma firstReturnHistory_kernel_projection (a n : ℕ) : + (firstReturnHistory a n).map (rawLast (a+2*(n+1))) = + (fullPairReturn n).comap (rawLast a) (rawLast_measurable a) := by + rw [firstReturnHistory_eq_capture_after_survival,Kernel.map_comp,rawCapturedPair_kernel_projection, + ← Kernel.comp_map _ _ (rawLast_measurable _),survivingHistory_kernel_projection,kernel_comp_comap] + rfl + +lemma costKilled_kernel_projection : + costKilled.map embedOdd = fullPairKilled.comap embedOdd embedOdd_measurable := by + ext z : 1 + rw [Kernel.map_apply _ embedOdd_measurable,Kernel.comap_apply,costKilled_fullPair_projection] + +lemma costCaptured_kernel_projection : + costCaptured.map embedOdd = fullPairCaptured.comap embedOdd embedOdd_measurable := by + ext z : 1 + rw [Kernel.map_apply _ embedOdd_measurable,Kernel.comap_apply,costCaptured_fullPair_projection] + +lemma firstReturn_fullPair_projection (n : ℕ) (z : OddCost) : + (firstReturn n z).map embedOdd = fullPairReturn n (embedOdd z) := by + have he : (firstReturn n).map embedOdd = (fullPairReturn n).comap embedOdd embedOdd_measurable := by + rw [firstReturn,Kernel.map_comp,costCaptured_kernel_projection, + ← Kernel.comp_map _ _ embedOdd_measurable, + kernelProjection_power embedOdd_measurable _ _ costKilled_kernel_projection n,kernel_comp_comap] + rfl + rw [← Kernel.map_apply _ embedOdd_measurable,he,Kernel.comap_apply] + +theorem firstReturnHistory_endpoint (a n : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (firstReturnHistory a n h).map (rawLast (a+2*(n+1))) = (firstReturn n z).map embedOdd := by + rw [← Kernel.map_apply _ (rawLast_measurable _),firstReturnHistory_kernel_projection, + Kernel.comap_apply,hz,firstReturn_fullPair_projection] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory Function Preorder +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels + +noncomputable def returnCylinderTo (a n b : ℕ) (hab : a+2*(n+1) ≤ b) : + Kernel (RawHistory a) (RawHistory b) := + (rawExtension a b).restrict + ((avoidOddReturns_measurable a n b (by omega)).inter (lastRegeneration_measurable b)) + +lemma returnCylinderTo_exact (a n : ℕ) : + returnCylinderTo a n (a+2*(n+1)) le_rfl = firstReturnHistory a n := rfl + +lemma avoidOddReturns_first_pair (a n b : ℕ) (hab : a+2*(n+1) ≤ b) : + avoidOddReturns a (n+1) b hab = + (rawPrefix (show a+2 ≤ b by omega) ⁻¹' (lastRegeneration (a+2))ᶜ) ∩ + avoidOddReturns (a+2) n b (by omega) := by + ext h + change (∀ j : Fin (n+1), h ⟨a+2*(j.1+1),_⟩ ∉ regenerationSet) ↔ + h ⟨a+2,_⟩ ∉ regenerationSet ∧ + ∀ j : Fin n, h ⟨(a+2)+2*(j.1+1),_⟩ ∉ regenerationSet + constructor + · intro hh + constructor + · exact hh 0 + · intro j + have hj := hh j.succ + have he : (⟨a+2*(j.succ.1+1),Finset.mem_Iic.mpr (by have hj := j.2; simp; omega)⟩ : Finset.Iic b) = + ⟨(a+2)+2*(j.1+1),Finset.mem_Iic.mpr (by have hj := j.2; omega)⟩ := by + apply Subtype.ext + simp only [Fin.val_succ] + omega + rw [he] at hj + exact hj + · rintro ⟨hfirst,htail⟩ j + refine Fin.cases hfirst (fun k => ?_) j + have he : (⟨a+2*(k.succ.1+1),Finset.mem_Iic.mpr (by have hk := k.2; simp; omega)⟩ : Finset.Iic b) = + ⟨(a+2)+2*(k.1+1),Finset.mem_Iic.mpr (by have hk := k.2; omega)⟩ := by + apply Subtype.ext + simp only [Fin.val_succ] + omega + rw [he] + exact htail k + +theorem returnCylinderTo_first_pair (a n b : ℕ) (hab : a+2*(n+2) ≤ b) : + returnCylinderTo a (n+1) b (by omega) = + returnCylinderTo (a+2) n b (by omega) ∘ₖ + ((rawExtension a (a+2)).restrict (lastRegeneration_measurable (a+2)).compl) := by + unfold returnCylinderTo + rw [← rawExtension_restrict_comp (show a ≤ a+2 by omega) (show a+2 ≤ b by omega) + (lastRegeneration_measurable (a+2)).compl + ((avoidOddReturns_measurable (a+2) n b (by omega)).inter (lastRegeneration_measurable b))] + congr 1 + rw [avoidOddReturns_first_pair a n b (by omega),inter_assoc] + +lemma returnCylinderTo_retains_past (a n b : ℕ) (hab : a+2*(n+1) ≤ b) (h : RawHistory a) : + ∀ᵐ z ∂returnCylinderTo a n b hab h, rawPrefix (show a ≤ b by omega) z = h := by + rw [returnCylinderTo,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawExtension_retains_prefix (by omega) h) + +lemma returnCylinderTo_retains_coordinate (a n b : ℕ) (hab : a+2*(n+1) ≤ b) + (h : RawHistory a) (i : Finset.Iic a) : + ∀ᵐ z ∂returnCylinderTo a n b hab h, + z ⟨i.1,Finset.mem_Iic.mpr (by have hi := Finset.mem_Iic.mp i.2; omega)⟩ = h i := by + filter_upwards [returnCylinderTo_retains_past a n b hab h] with z hz + exact congrFun hz i + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.CostReturnLaw + +noncomputable def keepFirstEvenUpdate (x : FirstPairWitness × OddCost) : FirstPairWitness := (x.1.1,x.2) + +lemma keepFirstEvenUpdate_measurable : Measurable keepFirstEvenUpdate := + (measurable_fst.comp measurable_fst).prodMk measurable_snd + +noncomputable def firstEvenReturnContinuation (n : ℕ) : Kernel FirstPairWitness FirstPairWitness := + (Kernel.id ×ₖ (firstReturn n).prodMkLeft EvenState).map keepFirstEvenUpdate + +instance firstEvenReturnContinuation_isFiniteKernel (n : ℕ) : IsFiniteKernel (firstEvenReturnContinuation n) := by + unfold firstEvenReturnContinuation + infer_instance + +lemma firstEvenReturnContinuation_apply (n : ℕ) (z : FirstPairWitness) {B : Set FirstPairWitness} + (hB : MeasurableSet B) : + firstEvenReturnContinuation n z B = firstReturn n z.2 {y | (z.1,y) ∈ B} := by + rw [firstEvenReturnContinuation,Kernel.map_apply' _ keepFirstEvenUpdate_measurable _ hB, + Kernel.prod_apply' _ _ _ (keepFirstEvenUpdate_measurable hB),Kernel.id_apply,lintegral_dirac'] + · rfl + · exact measurable_measure_prodMk_left (keepFirstEvenUpdate_measurable hB) + +lemma firstEvenReturnContinuation_lintegral (n : ℕ) (z : FirstPairWitness) + {F : FirstPairWitness → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F y ∂firstEvenReturnContinuation n z) = ∫⁻ y, F (z.1,y) ∂firstReturn n z.2 := by + have he : firstEvenReturnContinuation n z = (firstReturn n z.2).map (fun y => (z.1,y)) := by + ext B hB + rw [firstEvenReturnContinuation_apply _ _ hB, + Measure.map_apply (f := fun y : OddCost => (z.1,y)) (measurable_const.prodMk measurable_id) hB] + rfl + rw [he,lintegral_map (g := fun y : OddCost => (z.1,y)) hF (measurable_const.prodMk measurable_id)] + +noncomputable def capturedFirstPair : Kernel OddCost FirstPairWitness := + pairWitnessKernel.restrict (returnSet_measurable.preimage measurable_snd) + +noncomputable def killedFirstPair : Kernel OddCost FirstPairWitness := + pairWitnessKernel.restrict (returnSet_measurable.compl.preimage measurable_snd) + +instance capturedFirstPair_isFiniteKernel : IsFiniteKernel capturedFirstPair := by + unfold capturedFirstPair + infer_instance + +instance killedFirstPair_isFiniteKernel : IsFiniteKernel killedFirstPair := by + unfold killedFirstPair + infer_instance + +noncomputable def sourceReturnTerm : ℕ → Kernel OddCost FirstPairWitness + | 0 => capturedFirstPair + | n+1 => firstEvenReturnContinuation n ∘ₖ killedFirstPair + +instance sourceReturnTerm_isFiniteKernel (n : ℕ) : IsFiniteKernel (sourceReturnTerm n) := by + cases n <;> unfold sourceReturnTerm <;> infer_instance + +lemma capturedFirstPair_forget (z : OddCost) : + (capturedFirstPair z).map Prod.snd = costCaptured z := by + rw [capturedFirstPair,Kernel.restrict_apply,← Measure.restrict_map measurable_snd returnSet_measurable, + pairWitness_forget,costCaptured,Kernel.restrict_apply] + +lemma killedFirstPair_forget (z : OddCost) : + (killedFirstPair z).map Prod.snd = costKilled z := by + rw [killedFirstPair,Kernel.restrict_apply,← Measure.restrict_map measurable_snd returnSet_measurable.compl, + pairWitness_forget,costKilled,Kernel.restrict_apply] + +lemma firstEvenReturnContinuation_forget (n : ℕ) (z : FirstPairWitness) : + (firstEvenReturnContinuation n z).map Prod.snd = firstReturn n z.2 := by + ext B hB + rw [Measure.map_apply measurable_snd hB,firstEvenReturnContinuation_apply _ _ (measurable_snd hB)] + rfl + +lemma sourceReturnTerm_forget (n : ℕ) (z : OddCost) : + (sourceReturnTerm n z).map Prod.snd = firstReturn n z := by + cases n with + | zero => + have he : firstReturn 0 = costCaptured := Kernel.comp_id _ + rw [he] + exact capturedFirstPair_forget z + | succ n => + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF measurable_snd,sourceReturnTerm, + Kernel.lintegral_comp _ _ _ (g := fun y : FirstPairWitness => F y.2) (hF.comp measurable_snd)] + have he (x : FirstPairWitness) : (∫⁻ y, F y.2 ∂firstEvenReturnContinuation n x) = + ∫⁻ y, F y ∂firstReturn n x.2 := by + rw [← firstEvenReturnContinuation_forget n x,lintegral_map hF measurable_snd] + simp_rw [he] + have hJ : Measurable (fun x : OddCost => ∫⁻ y, F y ∂firstReturn n x) := hF.lintegral_kernel + rw [← lintegral_map (g := Prod.snd) hJ measurable_snd,killedFirstPair_forget, + firstReturn_succ_comp,Kernel.lintegral_comp _ _ _ hF] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FirstHitKernels + +instance fullPairKilled_pow_isFiniteKernel (n : ℕ) : IsFiniteKernel (fullPairKilled^n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel CostState CostState); infer_instance + | succ n ih => rw [pow_succ']; change IsFiniteKernel (fullPairKilled ∘ₖ (fullPairKilled^n)); infer_instance + +instance fullPairReturn_isFiniteKernel (n : ℕ) : IsFiniteKernel (fullPairReturn n) := by + unfold fullPairReturn + infer_instance + +noncomputable def returnPairReward (n : ℕ) (F : CostState × CostState → ℝ≥0∞) (p : CostState × CostState) : ℝ≥0∞ := + ∫⁻ y, F (p.1,y) ∂fullPairReturn n p.2 + +lemma returnPairReward_measurable (n : ℕ) {F : CostState × CostState → ℝ≥0∞} (hF : Measurable F) : + Measurable (returnPairReward n F) := by + let K : Kernel (CostState × CostState) CostState := + (fullPairReturn n).comap (Prod.snd : CostState × CostState → CostState) measurable_snd + change Measurable (fun p : CostState × CostState => ∫⁻ y, F (p.1,y) ∂K p) + exact Measurable.lintegral_kernel_prod_right' (κ := K) + (f := fun x : (CostState × CostState) × CostState => F (x.1.1,x.2)) + (hF.comp ((measurable_fst.comp measurable_fst).prodMk measurable_snd)) + +lemma sourceReturnTerm_succ_reward (n : ℕ) (z : OddCost) {F : CostState × CostState → ℝ≥0∞} + (hF : Measurable F) : + (∫⁻ y, F (pairTraceOfWitness z y) ∂sourceReturnTerm (n+1) z) = + ∫⁻ p, returnPairReward n F (pairTraceOfWitness z p) ∂killedFirstPair z := by + rw [sourceReturnTerm,Kernel.lintegral_comp _ _ _ + (g := fun y : FirstPairWitness => F (pairTraceOfWitness z y)) (hF.comp (pairTraceOfWitness_measurable z))] + apply lintegral_congr + intro p + rw [firstEvenReturnContinuation_lintegral n p + (F := fun y : FirstPairWitness => F (pairTraceOfWitness z y)) (hF.comp (pairTraceOfWitness_measurable z))] + have hG : Measurable (fun y : CostState => F ((pairTraceOfWitness z p).1,y)) := + hF.comp measurable_prodMk_left + rw [returnPairReward] + change (∫⁻ y, F ((pairTraceOfWitness z p).1,embedOdd y) ∂NumberTheoryLean.CostReturnLaw.firstReturn n p.2) = + ∫⁻ y, F ((pairTraceOfWitness z p).1,y) ∂fullPairReturn n (embedOdd p.2) + rw [← firstReturn_fullPair_projection n p.2, + lintegral_map (g := embedOdd) (f := fun y : CostState => F ((pairTraceOfWitness z p).1,y)) hG embedOdd_measurable] + +lemma killedFirstPair_trace (z : OddCost) : + (killedFirstPair z).map (pairTraceOfWitness z) = + (fullPairTraceKernel (embedOdd z)).restrict (Prod.snd ⁻¹' regenerationSetᶜ) := by + rw [killedFirstPair,Kernel.restrict_apply] + change ((pairWitnessKernel z).restrict ((pairTraceOfWitness z) ⁻¹' (Prod.snd ⁻¹' regenerationSetᶜ))).map + (pairTraceOfWitness z) = _ + rw [← Measure.restrict_map (pairTraceOfWitness_measurable z) (measurable_snd regenerationSet_measurable.compl), + pairWitness_joint_full_trace] + +lemma capturedFirstPair_trace (z : OddCost) : + (capturedFirstPair z).map (pairTraceOfWitness z) = + (fullPairTraceKernel (embedOdd z)).restrict (Prod.snd ⁻¹' regenerationSet) := by + rw [capturedFirstPair,Kernel.restrict_apply] + change ((pairWitnessKernel z).restrict ((pairTraceOfWitness z) ⁻¹' (Prod.snd ⁻¹' regenerationSet))).map + (pairTraceOfWitness z) = _ + rw [← Measure.restrict_map (pairTraceOfWitness_measurable z) (measurable_snd regenerationSet_measurable), + pairWitness_joint_full_trace] + +lemma rawKilledFirstPair_trace (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + ((((rawExtension a (a+2)).restrict (lastRegeneration_measurable (a+2)).compl) h).map (nextPairEval a)) = + (killedFirstPair z).map (pairTraceOfWitness z) := by + rw [Kernel.restrict_apply] + change ((rawExtension a (a+2) h).restrict ((nextPairEval a) ⁻¹' (Prod.snd ⁻¹' regenerationSetᶜ))).map + (nextPairEval a) = _ + rw [← Measure.restrict_map (nextPairEval_measurable a) (measurable_snd regenerationSet_measurable.compl)] + have he : (rawExtension a (a+2) h).map (nextPairEval a) = fullPairTraceKernel (rawLast a h) := + conditional_pair_trace a h + rw [he,hz,killedFirstPair_trace] + +lemma rawCapturedFirstPair_trace (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + ((((rawExtension a (a+2)).restrict (lastRegeneration_measurable (a+2))) h).map (nextPairEval a)) = + (capturedFirstPair z).map (pairTraceOfWitness z) := by + rw [Kernel.restrict_apply] + change ((rawExtension a (a+2) h).restrict ((nextPairEval a) ⁻¹' (Prod.snd ⁻¹' regenerationSet))).map + (nextPairEval a) = _ + rw [← Measure.restrict_map (nextPairEval_measurable a) (measurable_snd regenerationSet_measurable)] + have he : (rawExtension a (a+2) h).map (nextPairEval a) = fullPairTraceKernel (rawLast a h) := + conditional_pair_trace a h + rw [he,hz,capturedFirstPair_trace] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping + +noncomputable def rawCyclePairEval (a b : ℕ) (hab : a+1 ≤ b) (h : RawHistory b) : CostState × CostState := + (h ⟨a+1,Finset.mem_Iic.mpr hab⟩,rawLast b h) + +lemma rawCyclePairEval_measurable (a b : ℕ) (hab : a+1 ≤ b) : Measurable (rawCyclePairEval a b hab) := + (measurable_pi_apply _).prodMk (rawLast_measurable b) + +lemma returnCylinderTo_projection (a n b : ℕ) (hab : a+2*(n+1) ≤ b) (hb : b=a+2*(n+1)) : + (returnCylinderTo a n b hab).map (rawLast b) = + (fullPairReturn n).comap (rawLast a) (rawLast_measurable a) := by + subst b + exact firstReturnHistory_kernel_projection a n + +lemma rawRemainder_pair_reward (a n b : ℕ) (hab : (a+2)+2*(n+1) ≤ b) + (hb : b=(a+2)+2*(n+1)) (h : RawHistory (a+2)) + {F : CostState × CostState → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F (rawCyclePairEval a b (by omega) y) ∂returnCylinderTo (a+2) n b hab h) = + returnPairReward n F (nextPairEval a h) := by + have hae := returnCylinderTo_retains_coordinate (a+2) n b hab h + (⟨a+1,Finset.mem_Iic.mpr (by omega)⟩ : Finset.Iic (a+2)) + have heq : (fun y => F (rawCyclePairEval a b (by omega) y)) =ᵐ[returnCylinderTo (a+2) n b hab h] + fun y => F ((nextPairEval a h).1,rawLast b y) := by + filter_upwards [hae] with y hy + change F (y ⟨a+1,_⟩,rawLast b y)=F (h ⟨a+1,_⟩,rawLast b y) + rw [hy] + rw [lintegral_congr_ae heq] + have hG : Measurable (fun y : CostState => F ((nextPairEval a h).1,y)) := hF.comp measurable_prodMk_left + rw [← lintegral_map (g := rawLast b) (f := fun y : CostState => F ((nextPairEval a h).1,y)) hG (rawLast_measurable b)] + have hp := congrArg (fun K : Kernel (RawHistory (a+2)) CostState => K h) + (returnCylinderTo_projection (a+2) n b hab hb) + rw [Kernel.map_apply _ (rawLast_measurable b),Kernel.comap_apply] at hp + rw [hp] + rfl + +theorem firstReturnHistory_joint (a n : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (firstReturnHistory a n h).map (rawCyclePairEval a (a+2*(n+1)) (by omega)) = + (sourceReturnTerm n z).map (pairTraceOfWitness z) := by + cases n with + | zero => + change (firstReturnHistory a 0 h).map (nextPairEval a) = (capturedFirstPair z).map (pairTraceOfWitness z) + rw [firstReturnHistory_zero] + exact rawCapturedFirstPair_trace a h z hz + | succ n => + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (rawCyclePairEval_measurable _ _ _), + lintegral_map hF (pairTraceOfWitness_measurable z),sourceReturnTerm_succ_reward n z hF] + have hc : firstReturnHistory a (n+1) = + returnCylinderTo a (n+1) (a+2*(n+2)) (by omega) := rfl + rw [hc,returnCylinderTo_first_pair a n (a+2*(n+2)) le_rfl, + Kernel.lintegral_comp _ _ _ + (g := fun y => F (rawCyclePairEval a (a+2*(n+2)) (by omega) y)) + (hF.comp (rawCyclePairEval_measurable a (a+2*(n+2)) (by omega)))] + have hi (y : RawHistory (a+2)) : + (∫⁻ w, F (rawCyclePairEval a (a+2*(n+2)) (by omega) w) + ∂returnCylinderTo (a+2) n (a+2*(n+2)) (by omega) y) = + returnPairReward n F (nextPairEval a y) := + rawRemainder_pair_reward a n _ (by omega) (by omega) y hF + simp_rw [hi] + rw [← lintegral_map (g := nextPairEval a) (returnPairReward_measurable n hF) (nextPairEval_measurable a), + rawKilledFirstPair_trace a h z hz, + lintegral_map (returnPairReward_measurable n hF) (pairTraceOfWitness_measurable z)] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LargeGapCountErrors.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LargeGapCountErrors.lean new file mode 100644 index 0000000000000000000000000000000000000000..746dd9d17e5c1037b888f782b7ddcb8f18bc0617 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LargeGapCountErrors.lean @@ -0,0 +1,367 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Paths.WordIntervalGeometry +import OAI.NumberTheory.Jacobsthal.Sieve.LiteralModulusEnvelope +import OAI.NumberTheory.Jacobsthal.Sieve.ReferenceExponentialTail + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.FiniteErrorTelescoping + + +theorem endpoint_difference_le (E : List ℕ → ℝ) (pre ps : List ℕ) (delta : ℝ) + (h : ∀ before p after,ps=before++p::after → + |E ((pre++before)++[p])-E (pre++before)| ≤ delta) : + |E (pre++ps)-E pre| ≤ (ps.length:ℝ)*delta := by + induction ps generalizing pre with + | nil => simp + | cons p ps ih => + have hfirst := h [] p ps rfl + simp only [List.append_nil] at hfirst + have htail : ∀ before q after,ps=before++q::after → + |E (((pre++[p])++before)++[q])-E ((pre++[p])++before)| ≤ delta := by + intro before q after he + have hh := h (p::before) q after (by rw [List.cons_append,he]) + simpa only [List.append_assoc,List.singleton_append] using hh + have hh := ih (pre++[p]) htail + have htri := abs_add_le (E ((pre++[p])++ps)-E (pre++[p])) (E (pre++[p])-E pre) + have he : (pre++[p])++ps=pre++p::ps := by simp + rw [he] at hh htri + simp only [List.length_cons,Nat.cast_add,Nat.cast_one] + have htel : E (pre++p::ps)-E (pre++[p])+(E (pre++[p])-E pre)=E (pre++p::ps)-E pre := by ring + rw [htel] at htri + nlinarith + +theorem exists_large_edge (E : List ℕ → ℝ) (pre ps : List ℕ) (delta : ℝ) + (h : (ps.length:ℝ)*delta < |E (pre++ps)-E pre|) : + ∃ before p after,ps=before++p::after ∧ delta < |E ((pre++before)++[p])-E (pre++before)| := by + by_contra! hn + have hh := endpoint_difference_le E pre ps delta hn + linarith + +theorem witness_from_endpoints (E : List ℕ → ℝ) (pre ps : List ℕ) (H : ℕ) (hH : 0 < H) + (eps : ℝ) (heps : 0 < eps) (hlen : ps.length ≤ H) + (hstart : |E pre| ≤ eps/2) (hend : eps < |E (pre++ps)|) : + ∃ before p after,ps=before++p::after ∧ eps/(4*H) < |E ((pre++before)++[p])-E (pre++before)| := by + have hHr : 0 < (H:ℝ) := by exact_mod_cast hH + have hdelta : 0 ≤ eps/(4*H) := by positivity + have hm : (ps.length:ℝ)*(eps/(4*H)) ≤ eps/4 := by + have hl : (ps.length:ℝ) ≤ H := by exact_mod_cast hlen + have hh := mul_le_mul_of_nonneg_right hl hdelta + have he : (H:ℝ)*(eps/(4*H))=eps/4 := by field_simp [hHr.ne'] + rwa [he] at hh + have htri := abs_add_le (E (pre++ps)-E pre) (E pre) + simp only [sub_add_cancel] at htri + apply exists_large_edge E pre ps (eps/(4*H)) + linarith +end NumberTheoryLean.FiniteErrorTelescoping + + + +namespace NumberTheoryLean.ActualCountErrorEdges +open ErdosInverseCounts + + +noncomputable def relativeCountError (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) (d : ℕ) : ℝ := + (modulusCount Y small a d:ℝ)/(((Y:ℝ)/(d:ℝ))*V0)-1 +noncomputable def wordCountError (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) (ps : List ℕ) : ℝ := + relativeCountError Y small a V0 ps.prod + +theorem relative_error_increment (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) + (hY : 0 < Y) (hV : 0 < V0) (d u : ℕ) (hd : 0 < d) (hu : 0 < u) : + relativeCountError Y small a V0 (d*u)-relativeCountError Y small a V0 d= + ((modulusCount Y small a (d*u):ℝ)-(modulusCount Y small a d:ℝ)/(u:ℝ))/ + ((Y:ℝ)*V0/((d:ℝ)*(u:ℝ))) := by + have hYr : (Y:ℝ) ≠ 0 := by exact_mod_cast hY.ne' + have hdr : (d:ℝ) ≠ 0 := by exact_mod_cast hd.ne' + have hur : (u:ℝ) ≠ 0 := by exact_mod_cast hu.ne' + unfold relativeCountError + rw [Nat.cast_mul] + field_simp [hYr,hdr,hur,hV.ne'] + ring + +theorem relative_large_edge_iff (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 delta : ℝ) + (hY : 0 < Y) (hV : 0 < V0) (d u : ℕ) (hd : 0 < d) (hu : 0 < u) : + delta < |relativeCountError Y small a V0 (d*u)-relativeCountError Y small a V0 d| ↔ + NodeBadEdge Y small a delta V0 d u := by + have hYr : 0 < (Y:ℝ) := by exact_mod_cast hY + have hdr : 0 < (d:ℝ) := by exact_mod_cast hd + have hur : 0 < (u:ℝ) := by exact_mod_cast hu + have hmu : 0 < (Y:ℝ)*V0/((d:ℝ)*(u:ℝ)) := by positivity + rw [relative_error_increment Y small a V0 hY hV d u hd hu,abs_div,abs_of_pos hmu] + rw [lt_div_iff₀ hmu] + unfold NodeBadEdge + simp only [mul_div_assoc,mul_assoc] + +theorem word_large_edge_iff (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 delta : ℝ) + (hY : 0 < Y) (hV : 0 < V0) (pre : List ℕ) (u : ℕ) (hd : 0 < pre.prod) (hu : 0 < u) : + delta < |wordCountError Y small a V0 (pre++[u])-wordCountError Y small a V0 pre| ↔ + NodeBadEdge Y small a delta V0 pre.prod u := by + unfold wordCountError + rw [List.prod_append,List.prod_singleton] + exact relative_large_edge_iff Y small a V0 delta hY hV pre.prod u hd hu +end NumberTheoryLean.ActualCountErrorEdges + + + +namespace NumberTheoryLean.ActualCountErrorMass +open ErdosInverseCounts ActualCountErrorEdges +open ErdosPrimeInputs.PrimePrefixMass + + +theorem count_error_identity (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) + (hY : 0 < Y) (hV : 0 < V0) (d : ℕ) (hd : 0 < d) : + |(modulusCount Y small a d:ℝ)-((Y:ℝ)/(d:ℝ))*V0|= + ((Y:ℝ)/(d:ℝ))*V0*|relativeCountError Y small a V0 d| := by + have hYr : 0 < (Y:ℝ) := by exact_mod_cast hY + have hdr : 0 < (d:ℝ) := by exact_mod_cast hd + have hmu : 0 < ((Y:ℝ)/(d:ℝ))*V0 := by positivity + have he : (modulusCount Y small a d:ℝ)-((Y:ℝ)/(d:ℝ))*V0= + (((Y:ℝ)/(d:ℝ))*V0)*relativeCountError Y small a V0 d := by + unfold relativeCountError + field_simp [hmu.ne'] + rw [he,abs_mul,abs_of_pos hmu] + +theorem word_count_error_weight (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) + (hY : 0 < Y) (hV : 0 < V0) (ps : List ℕ) (hd : 0 < ps.prod) : + |(modulusCount Y small a ps.prod:ℝ)-((Y:ℝ)/(ps.prod:ℝ))*V0|= + ((Y:ℝ)*V0)*(prefixWeight ps*|wordCountError Y small a V0 ps|) := by + rw [count_error_identity Y small a V0 hY hV ps.prod hd,StoppedVertexHistory.prefixWeight_product] + unfold wordCountError + ring + +theorem finite_count_error_weight (B : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) + (hY : 0 < Y) (hV : 0 < V0) (F : Finset (List ℕ)) (hF : ∀ ps∈F,0 < ps.prod) : + (B^2/((Y:ℝ)*V0))*(∑ ps∈F,|(modulusCount Y small a ps.prod:ℝ)-((Y:ℝ)/(ps.prod:ℝ))*V0|)= + B^2*(∑ ps∈F,prefixWeight ps*|wordCountError Y small a V0 ps|) := by + have he := Finset.sum_congr rfl (fun ps hp => word_count_error_weight Y small a V0 hY hV ps (hF ps hp)) + rw [he,← Finset.mul_sum] + have hYr : (Y:ℝ) ≠ 0 := by exact_mod_cast hY.ne' + field_simp [hYr,hV.ne'] +end NumberTheoryLean.ActualCountErrorMass + + + +namespace NumberTheoryLean.CountErrorClassification +open PrimeHistories ActualCountErrorEdges ErdosInverseCounts + +attribute [local instance] Classical.propDecidable + +noncomputable def errorSum (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) (F : Finset (List ℕ)) : ℝ := + ∑ ps∈F,|(modulusCount Y small a ps.prod:ℝ)-((Y:ℝ)/(ps.prod:ℝ))*V0| +noncomputable def largeGapWords (w K : ℝ) (z : Node) (F : Finset (List ℕ)) : Finset (List ℕ) := + F.filter (fun ps => K<(terminal w z ps).gap) +noncomputable def smallErrorWords (w K eps : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) + (z : Node) (F : Finset (List ℕ)) : Finset (List ℕ) := + F.filter (fun ps => (terminal w z ps).gap ≤ K ∧ |wordCountError Y small a V0 ps| ≤ eps) +noncomputable def badCompactWords (w K eps : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) + (z : Node) (F : Finset (List ℕ)) : Finset (List ℕ) := + F.filter (fun ps => (terminal w z ps).gap ≤ K ∧ eps < |wordCountError Y small a V0 ps|) + +theorem error_sum_partition (w K eps : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (V0 : ℝ) + (z : Node) (F : Finset (List ℕ)) : + errorSum Y small a V0 F= + errorSum Y small a V0 (largeGapWords w K z F)+ + errorSum Y small a V0 (smallErrorWords w K eps Y small a V0 z F)+ + errorSum Y small a V0 (badCompactWords w K eps Y small a V0 z F) := by + simp only [errorSum,largeGapWords,smallErrorWords,badCompactWords,Finset.sum_filter] + rw [← Finset.sum_add_distrib,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro ps _hp + by_cases hgap : K<(terminal w z ps).gap + · simp [hgap,not_le_of_gt hgap] + · have hg : (terminal w z ps).gap ≤ K := le_of_not_gt hgap + by_cases he : |wordCountError Y small a V0 ps| ≤ eps + · simp [hgap,hg,he,not_lt_of_ge he] + · simp [hgap,hg,he,lt_of_not_ge he] +end NumberTheoryLean.CountErrorClassification + + + +namespace NumberTheoryLean.LiteralCountErrorLedger +open FinitePathGeometry PrimeHistories StoppedCountVertex StoppedCountAdapters StoppedVertexHistory StoppedTraceSets +open StoppedModulusCount FlatStoppedIdentity ReferenceAdmission ErdosInverseCounts StoppedTraceAdmission + +attribute [local instance] Classical.propDecidable + +theorem negative_abs_le_signed (k : ℕ) (x : ℝ) : -|x| ≤ (-1:ℝ)^k*x := by + have hh := neg_abs_le ((-1:ℝ)^k*x) + simpa only [abs_mul,abs_pow,abs_neg,abs_one,one_pow,one_mul] using hh + +theorem literal_count_error_ledger (w : ℝ) (Y : ℕ) (small P : Finset ℕ) (residue : ℕ → ℕ) + (z : Node) (V0 : ℝ) (stop : List ℕ → Prop) (hi : z.side=.even) (hP : ∀ p∈P,p.Prime) : + ((Y:ℝ)*V0)*referencePolynomial w P z.side z.gap + + (∑ ps∈stopped w stop P.card (rootVertex z ∅ P ((Y:ℝ)*V0)), + (countSurvivors Y small residue (after w (rootVertex z ∅ P ((Y:ℝ)*V0)) ps)- + referenceValue w (after w (rootVertex z ∅ P ((Y:ℝ)*V0)) ps))) - + (∑ ps∈expanded w stop P.card (rootVertex z ∅ P ((Y:ℝ)*V0)), + |(modulusCount Y small residue ps.prod:ℝ)-((Y:ℝ)/(ps.prod:ℝ))*V0|) ≤ + countSurvivors Y small residue (rootVertex z ∅ P ((Y:ℝ)*V0)) := by + let v := rootVertex z ∅ P ((Y:ℝ)*V0) + have hRaw := actual_reference_error_lower_bound w Y small residue stop P.card v le_rfl hi + have hErr : -(∑ ps∈expanded w stop P.card v, + |(modulusCount Y small residue ps.prod:ℝ)-((Y:ℝ)/(ps.prod:ℝ))*V0|) ≤ + ∑ ps∈expanded w stop P.card v,(-1:ℝ)^ps.length*(countMass Y small residue (after w v ps)-(after w v ps).scale) := by + rw [← Finset.sum_neg_distrib] + apply Finset.sum_le_sum + intro ps hps + rw [trace_mass_eq_modulusCount w Y small P residue z ((Y:ℝ)*V0) stop P.card hP (Or.inl hps),after_scale_product] + change -|(modulusCount Y small residue ps.prod:ℝ)-((Y:ℝ)/(ps.prod:ℝ))*V0| ≤ + (-1:ℝ)^ps.length*((modulusCount Y small residue ps.prod:ℝ)-((Y:ℝ)*V0)/(ps.prod:ℝ)) + have he : ((Y:ℝ)*V0)/(ps.prod:ℝ)=((Y:ℝ)/(ps.prod:ℝ))*V0 := by ring + rw [he] + exact negative_abs_le_signed ps.length _ + change ((Y:ℝ)*V0)*referencePolynomial w P z.side z.gap+_+_ ≤ _ at hRaw + change ((Y:ℝ)*V0)*referencePolynomial w P z.side z.gap+_-_ ≤ _ + linarith + +theorem expanded_reference_subset (w : ℝ) (P : Finset ℕ) (z : Node) (V : ℝ) (stop : List ℕ → Prop) (n : ℕ) : + expanded w stop n (rootVertex z ∅ P V) ⊆ referencePrefixes w P z.side z.gap := by + intro ps hps + exact trace_reference_member w stop n (rootVertex z ∅ P V) (Or.inl hps) +end NumberTheoryLean.LiteralCountErrorLedger + + + +namespace NumberTheoryLean.ReferenceCountEnvelope +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission StrongReferenceTransport StrongSourceFamilies +open ActualCountErrorEdges WordIntervalGeometry SourcePrimeProductData LogarithmicBinPartition ErdosModulusRelative +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem reference_count_envelope (aStar : ℝ) (ha : 0 < aStar) : + ∃ C w₀ : ℝ,0 < C ∧ 1 < w₀ ∧ ∀ B w top : ℝ,3 ≤ B → w₀ ≤ w → w < top → + ∀ Y : ℕ,0 < Y → ∀ z : Node,z.gap=Real.log (Y:ℝ)/Real.log w-aStar+2 → + z.side=.even → 199/100 ≤ z.ratio → Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ residue : ℕ → ℕ,∀ ps∈referencePrefixes w (sourcePrimeSet w top) z.side z.gap, + |wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) ps| ≤ + C*Real.exp (-(1/192:ℝ)*(terminal w z ps).gap) := by + obtain ⟨C,W,hC,hW,hEnvelope⟩ := modulus_error_envelope aStar ha + refine ⟨C*Real.exp ((2-aStar)/192),W,mul_pos hC (Real.exp_pos _),hW,?_⟩ + intro B w top hB hw₀ htop Y hY z hroot hi h199 hz hcut hclosed hpower residue ps hps + have hw : 1 < w := hW.trans_le hw₀ + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB z hi h199 hz hcut + have hcap : w^z.cutoff=top := by rwa [hcut] + have hfloor := (source_reference_transport hw htop z hs hz hg hclosed hcap ps hps).2 + have hData := reference_word_product_data hw htop z.side z.gap ps hps + have hsrc := (mem_decreasingPrefixes.mp (Finset.mem_filter.mp hps).1).2 + have hpos : ∀ p∈ps,0 < p := fun p hp => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hsrc p hp)).1.pos + have hgap := word_interval_gap Y hY z hroot ps hpos + have hv : aStar ≤ wordIntervalExponent w Y ps := by linarith + have hh := hEnvelope w hw₀ Y ps.prod residue hY hData.1 hData.2.1 hData.2.2 hv + change |wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) ps| ≤ + C*Real.exp (-wordIntervalExponent w Y ps/192) at hh + rw [hgap] at hh + have he : Real.exp (-((terminal w z ps).gap+aStar-2)/192)= + Real.exp ((2-aStar)/192)*Real.exp (-(1/192:ℝ)*(terminal w z ps).gap) := by + rw [← Real.exp_add] + congr 1 + ring + simpa only [he,mul_assoc] using hh +end NumberTheoryLean.ReferenceCountEnvelope + + + +namespace NumberTheoryLean.CountErrorFamilyMajorant +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission StrongReferenceTransport StrongSourceFamilies +open ReferenceCountEnvelope ActualCountErrorMass ActualCountErrorEdges SourcePrimeProductData +open LogarithmicBinPartition ErdosInverseCounts +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + + +theorem count_error_family_majorant (aStar : ℝ) (ha : 0 < aStar) : + ∃ C w₀ : ℝ,0 < C ∧ 1 < w₀ ∧ ∀ B w top : ℝ,3 ≤ B → w₀ ≤ w → w < top → + ∀ Y : ℕ,0 < Y → ∀ z : Node,z.gap=Real.log (Y:ℝ)/Real.log w-aStar+2 → + z.side=.even → 199/100 ≤ z.ratio → Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ residue : ℕ → ℕ,∀ F : Finset (List ℕ),F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (B^2/((Y:ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊))*(∑ ps∈F, + |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue ps.prod:ℝ)- + ((Y:ℝ)/(ps.prod:ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊|) ≤ C*(B^2*(∑ ps∈F,prefixWeight ps)) := by + obtain ⟨C,W,hC,hW,hEnvelope⟩ := reference_count_envelope aStar ha + refine ⟨C,max W 2,hC,hW.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw₀ htop Y hY z hroot hi h199 hz hcut hclosed hpower residue F hF + have hw : 1 < w := hW.trans_le ((le_max_left _ _).trans hw₀) + have hw2 : 2 ≤ w := (le_max_right _ _).trans hw₀ + have hV : 0 < SmallSieveFinite.smallEuler ⌊w⌋₊ := + (inv_pos.mpr (zero_lt_one.trans hw)).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2) + have hp : ∀ ps∈F,0 < ps.prod := fun ps hps => (reference_word_product_data hw htop z.side z.gap ps (hF hps)).1 + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB z hi h199 hz hcut + have hcap : w^z.cutoff=top := by rwa [hcut] + have hErr : ∀ ps∈F,|wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) ps| ≤ C := by + intro ps hps + have hh := hEnvelope B w top hB ((le_max_left _ _).trans hw₀) htop Y hY z hroot hi h199 hz hcut hclosed hpower residue ps (hF hps) + have hfloor := (source_reference_transport hw htop z hs hz hg hclosed hcap ps (hF hps)).2 + have he : Real.exp (-(1/192:ℝ)*(terminal w z ps).gap) ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith) + exact hh.trans ((mul_le_mul_of_nonneg_left he hC.le).trans_eq (mul_one C)) + rw [finite_count_error_weight B Y _ residue _ hY hV F hp] + have hsum : (∑ ps∈F,prefixWeight ps*|wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue + (SmallSieveFinite.smallEuler ⌊w⌋₊) ps|) ≤ C*(∑ ps∈F,prefixWeight ps) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro ps hps + have hh := mul_le_mul_of_nonneg_left (hErr ps hps) (prefixWeight_nonneg ps) + nlinarith + have hh := mul_le_mul_of_nonneg_left hsum (sq_nonneg B) + nlinarith +end NumberTheoryLean.CountErrorFamilyMajorant + + + +namespace NumberTheoryLean.LargeGapCountErrors +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission +open ReferenceCountEnvelope ReferenceExponentialTail ActualCountErrorMass ActualCountErrorEdges SourcePrimeProductData +open LogarithmicBinPartition ErdosInverseCounts +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + + +theorem uniform_large_gap_count_errors (aStar d eps : ℝ) (ha : 0 < aStar) (hd : 0 < d) (heps : 0 < eps) : + ∃ K₀ B₀ w₀ : ℝ,3 ≤ K₀ ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ K B w top : ℝ,K₀ ≤ K → B₀ ≤ B → w₀ ≤ w → w < top → Real.log B ≤ d*Real.log w → + ∀ Y : ℕ,0 < Y → ∀ z : Node,z.gap=Real.log (Y:ℝ)/Real.log w-aStar+2 → + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ residue : ℕ → ℕ,∀ F : Finset (List ℕ), + F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps∈F,K < (terminal w z ps).gap) → + (B^2/((Y:ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊))*(∑ ps∈F, + |(modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue ps.prod:ℝ)- + ((Y:ℝ)/(ps.prod:ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊|) ≤ eps := by + obtain ⟨C,WE,hC,hWE,hEnvelope⟩ := reference_count_envelope aStar ha + obtain ⟨K₀,B₀,WT,hK₀,hB₀,hWT,hTail⟩ := uniform_reference_exponential_tail d (1/192) (eps/C) hd (by norm_num) (by positivity) + refine ⟨K₀,B₀,max WE (max WT 2),hK₀,hB₀,hWE.trans_le (le_max_left _ _),?_⟩ + intro K B w top hK hB hw₀ htop hcomp Y hY z hroot hi h199 h23 hz hcut hclosed hpower residue F hF hGap + have hw : 1 < w := hWE.trans_le ((le_max_left _ _).trans hw₀) + have hw2 : 2 ≤ w := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hw₀ + have hV : 0 < SmallSieveFinite.smallEuler ⌊w⌋₊ := + (inv_pos.mpr (zero_lt_one.trans hw)).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2) + have hp : ∀ ps∈F,0 < ps.prod := fun ps hps => (reference_word_product_data hw htop z.side z.gap ps (hF hps)).1 + rw [finite_count_error_weight B Y _ residue _ hY hV F hp] + have hErr : ∀ ps∈F,|wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) ps| ≤ + C*Real.exp (-(1/192:ℝ)*(terminal w z ps).gap) := by + intro ps hps + exact hEnvelope B w top (hB₀.trans hB) ((le_max_left _ _).trans hw₀) htop Y hY z hroot hi h199 hz hcut hclosed hpower residue ps (hF hps) + have hsum : (∑ ps∈F,prefixWeight ps*|wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue + (SmallSieveFinite.smallEuler ⌊w⌋₊) ps|) ≤ C*(∑ ps∈F,prefixWeight ps*Real.exp (-(1/192:ℝ)*(terminal w z ps).gap)) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro ps hps + have hh := mul_le_mul_of_nonneg_left (hErr ps hps) (prefixWeight_nonneg ps) + nlinarith + have htail := hTail K B w top hK hB ((le_trans (le_max_left _ _) (le_max_right _ _)).trans hw₀) + htop hcomp z hi h199 h23 hz hcut hclosed hpower F hF hGap + have hh := mul_le_mul_of_nonneg_left hsum (sq_nonneg B) + have ht := mul_le_mul_of_nonneg_left htail hC.le + have he : C*(eps/C)=eps := mul_div_cancel₀ eps hC.ne' + rw [he] at ht + nlinarith +end NumberTheoryLean.LargeGapCountErrors + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LatticeSpacing.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LatticeSpacing.lean new file mode 100644 index 0000000000000000000000000000000000000000..72dd9520afe831068239992e95b2a47ec09c39f5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LatticeSpacing.lean @@ -0,0 +1,76 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FactorDividesAbscissa + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRichLine + +theorem congruent_integer_set_card (A : Finset ℤ) (S : ℝ) (hS : 0 ≤ S) + (d : ℕ) (hd : 0 < d) (hbox : ∀ x ∈ A, 0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) + (hdiv : ∀ x ∈ A, ∀ y ∈ A, (d : ℤ) ∣ x-y) : + (A.card : ℝ) ≤ S/(d : ℝ)+1 := by + classical + by_cases hA : A.Nonempty + · let x0 : ℤ := A.min' hA + have hx0 : x0 ∈ A := Finset.min'_mem A hA + have hdR : (0 : ℝ) < d := by exact_mod_cast hd + have hdZ : (0 : ℤ) < d := by exact_mod_cast hd + let f : ℤ → ℤ := fun x => (x-x0)/(d : ℤ) + have he (x : ℤ) (hx : x ∈ A) : (d : ℤ)*f x = x-x0 := by + exact Int.mul_ediv_cancel' (hdiv x hx x0 hx0) + have hinj : Set.InjOn f (A : Set ℤ) := by + intro x hx y hy hxy + have hh : x-x0 = y-x0 := by rw [← he x hx,← he y hy,hxy] + omega + have hfloor : 0 ≤ ⌊S/(d : ℝ)⌋ := Int.floor_nonneg.mpr (div_nonneg hS hdR.le) + have hsubset : A.image f ⊆ Finset.Icc 0 ⌊S/(d : ℝ)⌋ := by + intro t ht + obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp ht + have hmin : x0 ≤ x := Finset.min'_le A x hx + have hf0 : 0 ≤ f x := Int.ediv_nonneg (sub_nonneg.mpr hmin) hdZ.le + have heR : (d : ℝ)*(f x : ℝ) = (x : ℝ)-(x0 : ℝ) := by exact_mod_cast he x hx + have hfS : (f x : ℝ) ≤ S/(d : ℝ) := by + apply (le_div_iff₀ hdR).mpr + have hb := hbox x hx + have hb0 := (hbox x0 hx0).1 + nlinarith + exact Finset.mem_Icc.mpr ⟨hf0,Int.le_floor.mpr hfS⟩ + have hc : A.card ≤ (Finset.Icc (0 : ℤ) ⌊S/(d : ℝ)⌋).card := by + rw [← Finset.card_image_of_injOn hinj] + exact Finset.card_le_card hsubset + have hi : ((Finset.Icc (0 : ℤ) ⌊S/(d : ℝ)⌋).card : ℝ) = + (⌊S/(d : ℝ)⌋ : ℝ)+1 := by + have hh := Int.card_Icc_of_le 0 ⌊S/(d : ℝ)⌋ (show (0 : ℤ) ≤ ⌊S/(d : ℝ)⌋+1 by omega) + simp only [sub_zero] at hh + exact_mod_cast hh + calc + (A.card : ℝ) ≤ ((Finset.Icc (0 : ℤ) ⌊S/(d : ℝ)⌋).card : ℝ) := by exact_mod_cast hc + _ = (⌊S/(d : ℝ)⌋ : ℝ)+1 := hi + _ ≤ S/(d : ℝ)+1 := add_le_add (Int.floor_le _) le_rfl + · rw [Finset.not_nonempty_iff_eq_empty.mp hA] + simp only [Finset.card_empty,Nat.cast_zero] + positivity + +theorem PrimitiveIntegerLine.denominator_dvd_x_difference (l : PrimitiveIntegerLine) + (p q : ℤ × ℤ) (hp : l.Contains p) (hq : l.Contains q) : + (l.denominator : ℤ) ∣ p.1-q.1 := by + have he : l.slope*(p.1-q.1) = (l.denominator : ℤ)*(p.2-q.2) := by + unfold Contains at hp hq + linear_combination hq-hp + have hg : Int.gcd (l.denominator : ℤ) l.slope = 1 := by + simpa [Int.gcd_def] using l.reduced.symm.gcd_eq_one + apply Int.dvd_of_dvd_mul_right_of_gcd_one (a := (l.denominator : ℤ)) (b := l.slope) + · rw [he] + exact dvd_mul_right _ _ + · exact hg + +end ErdosRichLine + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LineSubstitution.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LineSubstitution.lean new file mode 100644 index 0000000000000000000000000000000000000000..c24d3d5fbfe5e36eabba06f29edf96cac4d6f84b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LineSubstitution.lean @@ -0,0 +1,74 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.PolynomialValueBound + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +noncomputable def lineSub {R : Type*} [CommRing R] (φ : ℤ →+* R) (a s : R) : + MvPolynomial (Fin 2) ℤ →+* Polynomial R := + MvPolynomial.eval₂Hom (Polynomial.C.comp φ) + ![Polynomial.X,Polynomial.C a-Polynomial.C s*Polynomial.X] + +theorem lineSub_monomial {R : Type*} [CommRing R] (φ : ℤ →+* R) (a s : R) + {D : ℕ} (i : MonomialIndex D) (c : ℤ) : + lineSub φ a s (MvPolynomial.monomial (exponent i) c) = + Polynomial.C (φ c)*(Polynomial.X^i.2.val * + (Polynomial.C a-Polynomial.C s*Polynomial.X)^(i.1.val-i.2.val)) := by + change MvPolynomial.eval₂ (Polynomial.C.comp φ) + ![Polynomial.X,Polynomial.C a-Polynomial.C s*Polynomial.X] + (MvPolynomial.monomial (exponent i) c) = _ + rw [MvPolynomial.eval₂_monomial,Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] + simp [exponent,Fin.prod_univ_two] + +theorem affine_natDegree_le {R : Type*} [CommRing R] (a s : R) : + (Polynomial.C a-Polynomial.C s*Polynomial.X).natDegree ≤ 1 := by + apply (Polynomial.natDegree_sub_le _ _).trans + apply max_le + · simp + · have h := Polynomial.natDegree_mul_le (p := Polynomial.C s) (q := Polynomial.X) + simp only [Polynomial.natDegree_C,zero_add] at h + exact h.trans Polynomial.natDegree_X_le + +theorem lineSub_monomial_degree {R : Type*} [CommRing R] (φ : ℤ →+* R) (a s : R) + {D : ℕ} (i : MonomialIndex D) (c : ℤ) : + (lineSub φ a s (MvPolynomial.monomial (exponent i) c)).natDegree ≤ D := by + have hx : (Polynomial.X^i.2.val : Polynomial R).natDegree ≤ i.2.val := by + simpa using Polynomial.natDegree_pow_le_of_le i.2.val (Polynomial.natDegree_X_le (R := R)) + have hl : ((Polynomial.C a-Polynomial.C s*Polynomial.X)^(i.1.val-i.2.val)).natDegree ≤ i.1.val-i.2.val := by + simpa using Polynomial.natDegree_pow_le_of_le (i.1.val-i.2.val) (affine_natDegree_le a s) + rw [lineSub_monomial] + have hprod := Polynomial.natDegree_mul_le (p := (Polynomial.X : Polynomial R)^i.2.val) + (q := (Polynomial.C a-Polynomial.C s*Polynomial.X)^(i.1.val-i.2.val)) + have hC := Polynomial.natDegree_mul_le (p := Polynomial.C (φ c)) + (q := Polynomial.X^i.2.val*(Polynomial.C a-Polynomial.C s*Polynomial.X)^(i.1.val-i.2.val)) + simp only [Polynomial.natDegree_C,zero_add] at hC + have hk := i.1.isLt + have hj := i.2.isLt + exact (hC.trans (hprod.trans (Nat.add_le_add hx hl))).trans (by omega) + +theorem lineSub_encode_degree {R : Type*} [CommRing R] (φ : ℤ →+* R) (a s : R) + {D : ℕ} (v : MonomialIndex D → ℤ) : (lineSub φ a s (encode v)).natDegree ≤ D := by + rw [encode,map_sum] + exact Polynomial.natDegree_sum_le_of_forall_le _ _ (fun i _ => lineSub_monomial_degree φ a s i (v i)) + +theorem lineSub_encode_eq_zero {R : Type*} [CommRing R] (φ : ℤ →+* R) (a s : R) + {D : ℕ} (v : MonomialIndex D → ℤ) + (h : ∀ k : Fin (D+1), (lineSub φ a s (encode v)).coeff k = 0) : + lineSub φ a s (encode v) = 0 := by + ext k + rw [Polynomial.coeff_zero] + by_cases hk : k ≤ D + · exact h ⟨k,by omega⟩ + · exact Polynomial.coeff_eq_zero_of_natDegree_lt ((lineSub_encode_degree φ a s v).trans_lt (by omega)) + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LiteralSourceList.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LiteralSourceList.lean new file mode 100644 index 0000000000000000000000000000000000000000..faea3a5b9a3b4ceb87e3fd17844257bf519b7889 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LiteralSourceList.lean @@ -0,0 +1,44 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.BoxHeightBudget + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseBoxHeight +open ErdosInverseAlignment ErdosInversePrimeBin + +theorem uniform_literal_source_list (C eta α c : ℝ) + (hC : 0 ≤ C) (heta : 0 < eta) (hα : 0 < α) (hc : 0 < c) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ Sq R p q xi : ℝ, ∀ a : ℕ → ℤ, + 1 ≤ p → 0 < q → p*q ≤ (sourceY z : ℝ) → + 1 ≤ Sq/q → Sq/q ≤ (1+xi)^(C*Real.log (sourceB z)) → + z^α ≤ R → R ≤ z^((1:ℝ)/100) → eta ≤ xi → xi ≤ 1 → + (sourceRationalList (primeBin R xi) a Sq R (sourceZ z) c).card ≤ ⌈2/c^2⌉₊ := by + have hbin := uniform_source_prime_bin_list (C:=3) heta hα (by norm_num) hc + have hL := Real.tendsto_log_atTop.eventually_ge_atTop 1 + filter_upwards [uniform_box_height C hC,source_B_bounds,hbin,hL] with z hH hB hbin hL + refine ⟨hH.1,?_⟩ + intro Sq R p q xi a hp hq hpq hSqratio hinfl hRlo hRhi hxi hxi1 + have hqSq : q ≤ Sq := (one_le_div hq).mp hSqratio + have hSq : 0 ≤ Sq := hq.le.trans hqSq + have hR : 0 ≤ R := (Real.rpow_nonneg (by linarith [hH.1] : 0 ≤ z) α).trans hRlo + have hxi0 : 0 ≤ xi := heta.le.trans hxi + have hqz : q ≤ z^2 := source_cofactor_le_square hL hp hq.le hpq + have hheight := hH.2 Sq R (sourceB z) xi q hSq hR hB.2.1 hB.2.2 + hxi0 hxi1 hq hqz hinfl hRhi + apply hbin.2 R xi Sq (sourceZ z) a hRlo hxi hxi1 hSq + norm_num at hheight ⊢ + exact hheight + +end ErdosInverseBoxHeight + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LocalGraphIff.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LocalGraphIff.lean new file mode 100644 index 0000000000000000000000000000000000000000..33b5aa5350a4f7d8ab24088e0b77cd4532d077f2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LocalGraphIff.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.PolynomialLocalGraph + +namespace OAI + +namespace Erdos970 + +section + +open Filter Set +open scoped Topology ContDiff +namespace ErdosLocalFiberGraphs +open ErdosImplicitCurvature ErdosDivisibleInflection + +theorem exists_local_graph_iff (Q : Bivariate) (x y : ℝ) + (hQ : peval Q x y = 0) (hQy : peval (partialY Q) x y ≠ 0) + (V : Set ℝ) (hV : IsOpen V) (hyV : y ∈ V) : + ∃ (a b : ℝ) (W : Set ℝ) (f : ℝ → ℝ), + a < x ∧ x < b ∧ IsOpen W ∧ y ∈ W ∧ W ⊆ V ∧ f x = y ∧ + ContDiffOn ℝ 2 f (Ioo a b) ∧ + (∀ t ∈ Ioo a b, f t ∈ W) ∧ + (∀ t ∈ Ioo a b, peval (partialY Q) t (f t) ≠ 0) ∧ + (∀ t ∈ Ioo a b, ∀ z ∈ W, peval Q t z = 0 ↔ z = f t) := by + have hc : ContDiffAt ℝ 2 (planeEval Q) (x,y) := (contDiff_planeEval Q 2).contDiffAt + have hi : (fderiv ℝ (planeEval Q) (x,y) ∘L ContinuousLinearMap.inr ℝ ℝ ℝ).IsInvertible := by + rw [fderiv_planeEval_inr] + exact scalar_map_invertible _ hQy + let f := hc.implicitFunction (by norm_num) hi + have hfx : f x = y := hc.implicitFunction_apply_self (by norm_num) hi + have hcf : ContDiffAt ℝ 2 f x := hc.contDiffAt_implicitFunction (by norm_num) hi + have heq : ∀ᶠ v in 𝓝 (x,y), peval Q v.1 v.2 = 0 ↔ v.2 = f v.1 := by + have h := hc.eventually_apply_eq_iff_implicitFunction (by norm_num) hi + exact h.mono fun v hv => by simpa only [planeEval, hQ, eq_comm] using hv + obtain ⟨U,V₀,hU,hxU,hV₀,hyV₀,hUV⟩ := mem_nhds_prod_iff'.mp heq + let W := V ∩ V₀ + have hW : IsOpen W := hV.inter hV₀ + have hyW : y ∈ W := ⟨hyV,hyV₀⟩ + have hmem : ∀ᶠ t in 𝓝 x, f t ∈ W := + hcf.continuousAt.preimage_mem_nhds (hfx ▸ hW.mem_nhds hyW) + have hpair : ContinuousAt (fun t : ℝ => (t,f t)) x := + continuousAt_id.prodMk hcf.continuousAt + have hplane : ContinuousAt (planeEval (partialY Q)) (x,f x) := + (contDiff_planeEval (partialY Q) 0).continuous.continuousAt + have hcy : ContinuousAt (fun t => peval (partialY Q) t (f t)) x := by + change ContinuousAt (planeEval (partialY Q) ∘ (fun t : ℝ => (t,f t))) x + exact ContinuousAt.comp (f := fun t : ℝ => (t,f t)) hplane hpair + have hny : ∀ᶠ t in 𝓝 x, peval (partialY Q) t (f t) ≠ 0 := by + apply hcy.eventually_ne + rwa [hfx] + obtain ⟨D,hD,hfD⟩ := hcf.contDiffOn (m := 2) le_rfl (by norm_num) + have hN : U ∩ D ∩ {t | f t ∈ W} ∩ {t | peval (partialY Q) t (f t) ≠ 0} ∈ 𝓝 x := + inter_mem (inter_mem (inter_mem (hU.mem_nhds hxU) hD) hmem) hny + obtain ⟨eps,heps,hball⟩ := Metric.mem_nhds_iff.mp hN + have hs : Ioo (x-eps) (x+eps) ⊆ + U ∩ D ∩ {t | f t ∈ W} ∩ {t | peval (partialY Q) t (f t) ≠ 0} := by + simpa only [Real.ball_eq_Ioo] using hball + refine ⟨x-eps,x+eps,W,f,by linarith,by linarith,hW,hyW, + inter_subset_left,hfx,hfD.mono (fun t ht => (hs ht).1.1.2), + (fun t ht => (hs ht).1.2),(fun t ht => (hs ht).2),?_⟩ + intro t ht z hz + exact hUV (a := (t,z)) ⟨(hs ht).1.1.1,hz.2⟩ + +end ErdosLocalFiberGraphs + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LocalZeroMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LocalZeroMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..30766d070f16092c0b21f6d8b759262aca6fc5c6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LocalZeroMass.lean @@ -0,0 +1,89 @@ +import OAI.NumberTheory.Jacobsthal.Primes.DirichletZeroFree + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +theorem uniform_normalized_zero_mass : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi ≠ 1 → ∀ (t : ℝ) (S : Finset ℂ), + (∀ rho, rho ∈ S ↔ ‖rho‖ ≤ 19/20 ∧ normalizedDirichlet chi t rho = 0) → + ∑ rho ∈ S, ((analyticOrderAt (normalizedDirichlet chi t) rho).toNat:ℝ) ≤ + C*modulusHeight q t := by + classical + let D : ℝ := Real.log ((39/40:ℝ)/(19/20)) + have hD : 0 < D := Real.log_pos (by norm_num) + have hZ := one_le_absoluteZetaTwo + have hlog : 0 ≤ Real.log (4*absoluteZetaTwo) := Real.log_nonneg (by linarith) + refine ⟨(Real.log (4*absoluteZetaTwo)+1)/D, div_pos (by linarith) hD, ?_⟩ + intro q _ chi hchi t S hS + let f := normalizedDirichlet chi t + have he : _root_.Erdos970.zerosetKfR (19/20) (by norm_num) f = (S:Set ℂ) := by + ext rho + simp only [_root_.Erdos970.zerosetKfR,Set.mem_ofPred_eq,Metric.mem_closedBall,dist_zero_right,Finset.mem_coe] + exact (hS rho).symm + have hf : (_root_.Erdos970.zerosetKfR (19/20) (by norm_num) f).Finite := by rw [he]; exact S.finite_toSet + have hfin : hf.toFinset = S := by + ext rho + rw [Set.Finite.mem_toFinset,he] + rfl + have h0 : f 0 = 1 := normalizedDirichlet_zero chi t + have hn : f 0 ≠ 0 := by rw [h0]; norm_num + have hj := _root_.Erdos970.jensen_sum_bound_strict (dirichletDiskEnvelope q t) (39/40) (19/20) + (dirichletDiskEnvelope_gt_one q t) (by norm_num) (by norm_num) (by norm_num) + f (fun w _ => normalizedDirichlet_analytic chi hchi t w) hn h0 hf + (fun w hw => normalizedDirichlet_bound chi hchi t (hw.trans (by norm_num))) + rw [hfin] at hj + calc + _ ≤ Real.log (dirichletDiskEnvelope q t)/D := hj + _ ≤ ((Real.log (4*absoluteZetaTwo)+1)*modulusHeight q t)/D := + div_le_div_of_nonneg_right (log_dirichletDiskEnvelope_bound q t) hD.le + _ = _ := by ring + +theorem uniform_local_zero_estimates : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi ≠ 1 → ∀ t : ℝ, ∃ S : Finset ℂ, + (∀ rho, rho ∈ S ↔ ‖rho‖ ≤ 19/20 ∧ + DirichletCharacter.LFunction chi (dirichletDiskPoint t rho) = 0) ∧ + (∑ rho ∈ S, ((analyticOrderAt (normalizedDirichlet chi t) rho).toNat:ℝ) ≤ C*modulusHeight q t) ∧ + ∀ w : ℂ, ‖w‖ ≤ 17/20 → + DirichletCharacter.LFunction chi (dirichletDiskPoint t w) ≠ 0 → + ‖(5/2:ℂ)*(deriv (DirichletCharacter.LFunction chi) (dirichletDiskPoint t w) / + DirichletCharacter.LFunction chi (dirichletDiskPoint t w)) - + ∑ rho ∈ S, (analyticOrderAt (normalizedDirichlet chi t) rho).toNat/(w-rho)‖ ≤ + C*modulusHeight q t := by + classical + obtain ⟨C0,hC0,hlocal⟩ := uniform_dirichlet_local_log_derivative + obtain ⟨C1,hC1,hmass⟩ := uniform_normalized_zero_mass + refine ⟨max C0 C1,lt_of_lt_of_le hC0 (le_max_left _ _),?_⟩ + intro q _ chi hchi t + obtain ⟨S,hS,_,hb⟩ := hlocal q chi hchi t + have hn := LFunction_ne_zero_right chi (s := dirichletCenter t) (by simp) + have hzeros (rho:ℂ) : normalizedDirichlet chi t rho = 0 ↔ + DirichletCharacter.LFunction chi (dirichletDiskPoint t rho) = 0 := by + unfold normalizedDirichlet + exact div_eq_zero_iff.trans (or_iff_left hn) + have hSn : ∀ rho, rho ∈ S ↔ ‖rho‖ ≤ 19/20 ∧ normalizedDirichlet chi t rho = 0 := by + intro rho + rw [hzeros] + exact hS rho + have hH : 0 ≤ modulusHeight q t := zero_le_one.trans (modulusHeight_ge_one q t) + refine ⟨S,hS,?_,?_⟩ + · exact (hmass q chi hchi t S hSn).trans + (mul_le_mul_of_nonneg_right (le_max_right _ _) hH) + · intro w hw hne + exact (hb w hw hne).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) hH) + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LogSquaredDecay.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LogSquaredDecay.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0144501a902c872c021ab0aea8aef571ee72406 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LogSquaredDecay.lean @@ -0,0 +1,64 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosPrimeInputs.LogSquaredDecay + +open Filter +open scoped Topology + +lemma power_exponential_saving {c : ℝ} (hc : 0 inner2Primitive t x) (loss2Kernel t x) x := by + unfold inner2Primitive loss2Kernel + have h0 := (hasDerivAt_id x) + have h1 := (((hasDerivAt_const x (-1:ℝ)).mul (hasDerivAt_id x)).mul (hasDerivAt_const x (t^2)⁻¹)) + have h2 := (((hasDerivAt_const x (-2:ℝ)).mul (hasDerivAt_const x (t^1)⁻¹)).mul ((hasDerivAt_id x).log (by positivity))) + have h3 := (((hasDerivAt_const x (1/4:ℝ)).mul (hasDerivAt_const x (t^1)⁻¹)).mul ((hasDerivAt_id x).pow 2)) + have h4 := (((hasDerivAt_const x (1/36:ℝ)).mul (hasDerivAt_const x (t^2)⁻¹)).mul ((hasDerivAt_id x).pow 3)) + have h5 := (((hasDerivAt_const x (2/3:ℝ)).mul (hasDerivAt_const x t)).mul ((hasDerivAt_id x).log (by positivity))) + have h6 := (((hasDerivAt_const x (4/3:ℝ)).mul (hasDerivAt_const x (t^2)⁻¹)).mul ((hasDerivAt_id x).log (by positivity))) + have hd := ((((((h0.add h1).add h2).add h3).add h4).add h5).add h6) + convert! hd using 1 + simp only [id_eq,Pi.mul_apply,Pi.pow_apply] + field_simp + ring + +noncomputable def middle3Kernel (t u : ℝ) : ℝ := + (-1:ℝ) + + ((1/2:ℝ) * (t^2)⁻¹) + + ((-1:ℝ) * (Real.log u)) + + ((2:ℝ) * (t^1)⁻¹) + + ((2:ℝ) * (u^1)⁻¹) + + ((t^1)⁻¹ * (u^1)⁻¹) + + ((1/2:ℝ) * u * (t^2)⁻¹) + + ((-14/9:ℝ) * (t^2)⁻¹ * (u^1)⁻¹) + + ((-13/72:ℝ) * (t^2)⁻¹ * (u^2)) + + ((-5/4:ℝ) * u * (t^1)⁻¹) + + ((1/2:ℝ) * u * (t^1)⁻¹ * (Real.log (2:ℝ))) + + ((-2/3:ℝ) * t * (u^1)⁻¹ * (Real.log u)) + + ((-1/2:ℝ) * u * (t^1)⁻¹ * (Real.log u)) + + ((-1/12:ℝ) * (t^2)⁻¹ * (u^2) * (Real.log u)) + + ((1/12:ℝ) * (t^2)⁻¹ * (u^2) * (Real.log (2:ℝ))) + + ((2/3:ℝ) * t * (u^1)⁻¹ * (Real.log (2:ℝ))) + + (Real.log (2:ℝ)) + +noncomputable def inner3Primitive (t u x : ℝ) : ℝ := + (x * (t^1)⁻¹) + + (x * (u^1)⁻¹) + + ((1/8:ℝ) * (t^2)⁻¹ * (x^2)) + + ((1/2:ℝ) * u * (t^1)⁻¹ * (Real.log x)) + + ((-7/36:ℝ) * (t^2)⁻¹ * (u^1)⁻¹ * (x^3)) + + ((1/4:ℝ) * u * x * (t^2)⁻¹) + + ((1/4:ℝ) * (t^1)⁻¹ * (u^1)⁻¹ * (x^2)) + + ((1/12:ℝ) * (t^2)⁻¹ * (u^2) * (Real.log x)) + + ((2/3:ℝ) * t * (u^1)⁻¹ * (Real.log x)) + + (Real.log x) + +theorem inner3Primitive_deriv (t u x : ℝ) (ht : 0 < t) (hu : 0 < u) (hx : 0 < x) : + HasDerivAt (fun x : ℝ => inner3Primitive t u x) (loss3Kernel t u x) x := by + unfold inner3Primitive loss3Kernel + have h0 := ((hasDerivAt_id x).mul (hasDerivAt_const x (t^1)⁻¹)) + have h1 := ((hasDerivAt_id x).mul (hasDerivAt_const x (u^1)⁻¹)) + have h2 := (((hasDerivAt_const x (1/8:ℝ)).mul (hasDerivAt_const x (t^2)⁻¹)).mul ((hasDerivAt_id x).pow 2)) + have h3 := ((((hasDerivAt_const x (1/2:ℝ)).mul (hasDerivAt_const x u)).mul (hasDerivAt_const x (t^1)⁻¹)).mul ((hasDerivAt_id x).log (by positivity))) + have h4 := ((((hasDerivAt_const x (-7/36:ℝ)).mul (hasDerivAt_const x (t^2)⁻¹)).mul (hasDerivAt_const x (u^1)⁻¹)).mul ((hasDerivAt_id x).pow 3)) + have h5 := ((((hasDerivAt_const x (1/4:ℝ)).mul (hasDerivAt_const x u)).mul (hasDerivAt_id x)).mul (hasDerivAt_const x (t^2)⁻¹)) + have h6 := ((((hasDerivAt_const x (1/4:ℝ)).mul (hasDerivAt_const x (t^1)⁻¹)).mul (hasDerivAt_const x (u^1)⁻¹)).mul ((hasDerivAt_id x).pow 2)) + have h7 := ((((hasDerivAt_const x (1/12:ℝ)).mul (hasDerivAt_const x (t^2)⁻¹)).mul (hasDerivAt_const x (u^2))).mul ((hasDerivAt_id x).log (by positivity))) + have h8 := ((((hasDerivAt_const x (2/3:ℝ)).mul (hasDerivAt_const x t)).mul (hasDerivAt_const x (u^1)⁻¹)).mul ((hasDerivAt_id x).log (by positivity))) + have h9 := ((hasDerivAt_id x).log (by positivity)) + have hd := (((((((((h0.add h1).add h2).add h3).add h4).add h5).add h6).add h7).add h8).add h9) + convert! hd using 1 + simp only [id_eq,Pi.mul_apply,Pi.pow_apply] + field_simp + ring + +noncomputable def middle3Primitive (t u : ℝ) : ℝ := + ((2:ℝ) * (Real.log u)) + + (u * (Real.log (2:ℝ))) + + ((t^1)⁻¹ * (Real.log u)) + + ((1/2:ℝ) * u * (t^2)⁻¹) + + ((-1:ℝ) * u * (Real.log u)) + + ((2:ℝ) * u * (t^1)⁻¹) + + ((-14/9:ℝ) * (t^2)⁻¹ * (Real.log u)) + + ((-11/216:ℝ) * (t^2)⁻¹ * (u^3)) + + ((-1/2:ℝ) * (t^1)⁻¹ * (u^2)) + + ((-1/3:ℝ) * t * ((Real.log u)^2)) + + ((1/4:ℝ) * (t^2)⁻¹ * (u^2)) + + ((-1/4:ℝ) * (t^1)⁻¹ * (u^2) * (Real.log u)) + + ((-1/36:ℝ) * (t^2)⁻¹ * (u^3) * (Real.log u)) + + ((1/4:ℝ) * (t^1)⁻¹ * (u^2) * (Real.log (2:ℝ))) + + ((1/36:ℝ) * (t^2)⁻¹ * (u^3) * (Real.log (2:ℝ))) + + ((2/3:ℝ) * t * (Real.log (2:ℝ)) * (Real.log u)) + +theorem middle3Primitive_deriv (t u : ℝ) (ht : 0 < t) (hu : 0 < u) : + HasDerivAt (fun u : ℝ => middle3Primitive t u) (middle3Kernel t u) u := by + unfold middle3Primitive middle3Kernel + have h0 := ((hasDerivAt_const u (2:ℝ)).mul ((hasDerivAt_id u).log (by positivity))) + have h1 := ((hasDerivAt_id u).mul (hasDerivAt_const u (Real.log (2:ℝ)))) + have h2 := ((hasDerivAt_const u (t^1)⁻¹).mul ((hasDerivAt_id u).log (by positivity))) + have h3 := (((hasDerivAt_const u (1/2:ℝ)).mul (hasDerivAt_id u)).mul (hasDerivAt_const u (t^2)⁻¹)) + have h4 := (((hasDerivAt_const u (-1:ℝ)).mul (hasDerivAt_id u)).mul ((hasDerivAt_id u).log (by positivity))) + have h5 := (((hasDerivAt_const u (2:ℝ)).mul (hasDerivAt_id u)).mul (hasDerivAt_const u (t^1)⁻¹)) + have h6 := (((hasDerivAt_const u (-14/9:ℝ)).mul (hasDerivAt_const u (t^2)⁻¹)).mul ((hasDerivAt_id u).log (by positivity))) + have h7 := (((hasDerivAt_const u (-11/216:ℝ)).mul (hasDerivAt_const u (t^2)⁻¹)).mul ((hasDerivAt_id u).pow 3)) + have h8 := (((hasDerivAt_const u (-1/2:ℝ)).mul (hasDerivAt_const u (t^1)⁻¹)).mul ((hasDerivAt_id u).pow 2)) + have h9 := (((hasDerivAt_const u (-1/3:ℝ)).mul (hasDerivAt_const u t)).mul (((hasDerivAt_id u).log (by positivity)).pow 2)) + have h10 := (((hasDerivAt_const u (1/4:ℝ)).mul (hasDerivAt_const u (t^2)⁻¹)).mul ((hasDerivAt_id u).pow 2)) + have h11 := ((((hasDerivAt_const u (-1/4:ℝ)).mul (hasDerivAt_const u (t^1)⁻¹)).mul ((hasDerivAt_id u).pow 2)).mul ((hasDerivAt_id u).log (by positivity))) + have h12 := ((((hasDerivAt_const u (-1/36:ℝ)).mul (hasDerivAt_const u (t^2)⁻¹)).mul ((hasDerivAt_id u).pow 3)).mul ((hasDerivAt_id u).log (by positivity))) + have h13 := ((((hasDerivAt_const u (1/4:ℝ)).mul (hasDerivAt_const u (t^1)⁻¹)).mul ((hasDerivAt_id u).pow 2)).mul (hasDerivAt_const u (Real.log (2:ℝ)))) + have h14 := ((((hasDerivAt_const u (1/36:ℝ)).mul (hasDerivAt_const u (t^2)⁻¹)).mul ((hasDerivAt_id u).pow 3)).mul (hasDerivAt_const u (Real.log (2:ℝ)))) + have h15 := ((((hasDerivAt_const u (2/3:ℝ)).mul (hasDerivAt_const u t)).mul (hasDerivAt_const u (Real.log (2:ℝ)))).mul ((hasDerivAt_id u).log (by positivity))) + have hd := (((((((((((((((h0.add h1).add h2).add h3).add h4).add h5).add h6).add h7).add h8).add h9).add h10).add h11).add h12).add h13).add h14).add h15) + convert! hd using 1 + simp only [id_eq,Pi.mul_apply,Pi.pow_apply] + field_simp + ring + +noncomputable def reduced2 (t : ℝ) : ℝ := + (2:ℝ) + + ((2:ℝ) * (t^1)⁻¹) + + ((-23/18:ℝ) * t) + + ((-16/9:ℝ) * (t^2)⁻¹) + + ((-2:ℝ) * (t^1)⁻¹ * (Real.log (2:ℝ))) + + ((2:ℝ) * (t^1)⁻¹ * (Real.log t)) + + ((-4/3:ℝ) * (t^2)⁻¹ * (Real.log t)) + + ((-2/3:ℝ) * t * (Real.log t)) + + ((2/3:ℝ) * t * (Real.log (2:ℝ))) + + ((4/3:ℝ) * (t^2)⁻¹ * (Real.log (2:ℝ))) + +noncomputable def reduced3 (t : ℝ) : ℝ := + (-9/4:ℝ) + + ((-2:ℝ) * (Real.log t)) + + ((2:ℝ) * (Real.log (2:ℝ))) + + ((3/2:ℝ) * (t^1)⁻¹) + + ((43/27:ℝ) * (t^2)⁻¹) + + ((119/216:ℝ) * t) + + ((t^1)⁻¹ * (Real.log (2:ℝ))) + + ((-1:ℝ) * (t^1)⁻¹ * (Real.log t)) + + ((-23/18:ℝ) * t * (Real.log (2:ℝ))) + + ((-14/9:ℝ) * (t^2)⁻¹ * (Real.log (2:ℝ))) + + ((1/3:ℝ) * t * ((Real.log (2:ℝ))^2)) + + ((1/3:ℝ) * t * ((Real.log t)^2)) + + ((14/9:ℝ) * (t^2)⁻¹ * (Real.log t)) + + ((23/18:ℝ) * t * (Real.log t)) + + ((-2/3:ℝ) * t * (Real.log (2:ℝ)) * (Real.log t)) + +noncomputable def outer2Primitive (t : ℝ) : ℝ := + ((Real.log t)^2) + + ((2:ℝ) * t) + + ((2:ℝ) * (Real.log t)) + + ((-17/36:ℝ) * (t^2)) + + ((28/9:ℝ) * (t^1)⁻¹) + + ((-2:ℝ) * (Real.log (2:ℝ)) * (Real.log t)) + + ((-4/3:ℝ) * (t^1)⁻¹ * (Real.log (2:ℝ))) + + ((-1/3:ℝ) * (t^2) * (Real.log t)) + + ((1/3:ℝ) * (t^2) * (Real.log (2:ℝ))) + + ((4/3:ℝ) * (t^1)⁻¹ * (Real.log t)) + +theorem outer2Primitive_deriv (t : ℝ) (ht : 0 < t) : + HasDerivAt (fun t : ℝ => outer2Primitive t) (reduced2 t) t := by + unfold outer2Primitive reduced2 + have h0 := (((hasDerivAt_id t).log (by positivity)).pow 2) + have h1 := ((hasDerivAt_const t (2:ℝ)).mul (hasDerivAt_id t)) + have h2 := ((hasDerivAt_const t (2:ℝ)).mul ((hasDerivAt_id t).log (by positivity))) + have h3 := ((hasDerivAt_const t (-17/36:ℝ)).mul ((hasDerivAt_id t).pow 2)) + have h4 := ((hasDerivAt_const t (28/9:ℝ)).mul (((hasDerivAt_id t).pow 1).inv (by change t^1 ≠ 0; positivity))) + have h5 := (((hasDerivAt_const t (-2:ℝ)).mul (hasDerivAt_const t (Real.log (2:ℝ)))).mul ((hasDerivAt_id t).log (by positivity))) + have h6 := (((hasDerivAt_const t (-4/3:ℝ)).mul (((hasDerivAt_id t).pow 1).inv (by change t^1 ≠ 0; positivity))).mul (hasDerivAt_const t (Real.log (2:ℝ)))) + have h7 := (((hasDerivAt_const t (-1/3:ℝ)).mul ((hasDerivAt_id t).pow 2)).mul ((hasDerivAt_id t).log (by positivity))) + have h8 := (((hasDerivAt_const t (1/3:ℝ)).mul ((hasDerivAt_id t).pow 2)).mul (hasDerivAt_const t (Real.log (2:ℝ)))) + have h9 := (((hasDerivAt_const t (4/3:ℝ)).mul (((hasDerivAt_id t).pow 1).inv (by change t^1 ≠ 0; positivity))).mul ((hasDerivAt_id t).log (by positivity))) + have hd := (((((((((h0.add h1).add h2).add h3).add h4).add h5).add h6).add h7).add h8).add h9) + convert! hd using 1 + simp only [id_eq,Pi.mul_apply,Pi.pow_apply,Pi.inv_apply] + field_simp + ring + +noncomputable def outer3Primitive (t : ℝ) : ℝ := + ((-85/27:ℝ) * (t^1)⁻¹) + + ((-1/2:ℝ) * ((Real.log t)^2)) + + ((-1/4:ℝ) * t) + + ((3/2:ℝ) * (Real.log t)) + + ((17/432:ℝ) * (t^2)) + + ((Real.log (2:ℝ)) * (Real.log t)) + + ((-2:ℝ) * t * (Real.log t)) + + ((2:ℝ) * t * (Real.log (2:ℝ))) + + ((-17/36:ℝ) * (t^2) * (Real.log (2:ℝ))) + + ((-14/9:ℝ) * (t^1)⁻¹ * (Real.log t)) + + ((1/6:ℝ) * (t^2) * ((Real.log (2:ℝ))^2)) + + ((1/6:ℝ) * (t^2) * ((Real.log t)^2)) + + ((14/9:ℝ) * (t^1)⁻¹ * (Real.log (2:ℝ))) + + ((17/36:ℝ) * (t^2) * (Real.log t)) + + ((-1/3:ℝ) * (t^2) * (Real.log (2:ℝ)) * (Real.log t)) + +theorem outer3Primitive_deriv (t : ℝ) (ht : 0 < t) : + HasDerivAt (fun t : ℝ => outer3Primitive t) (reduced3 t) t := by + unfold outer3Primitive reduced3 + have h0 := ((hasDerivAt_const t (-85/27:ℝ)).mul (((hasDerivAt_id t).pow 1).inv (by change t^1 ≠ 0; positivity))) + have h1 := ((hasDerivAt_const t (-1/2:ℝ)).mul (((hasDerivAt_id t).log (by positivity)).pow 2)) + have h2 := ((hasDerivAt_const t (-1/4:ℝ)).mul (hasDerivAt_id t)) + have h3 := ((hasDerivAt_const t (3/2:ℝ)).mul ((hasDerivAt_id t).log (by positivity))) + have h4 := ((hasDerivAt_const t (17/432:ℝ)).mul ((hasDerivAt_id t).pow 2)) + have h5 := ((hasDerivAt_const t (Real.log (2:ℝ))).mul ((hasDerivAt_id t).log (by positivity))) + have h6 := (((hasDerivAt_const t (-2:ℝ)).mul (hasDerivAt_id t)).mul ((hasDerivAt_id t).log (by positivity))) + have h7 := (((hasDerivAt_const t (2:ℝ)).mul (hasDerivAt_id t)).mul (hasDerivAt_const t (Real.log (2:ℝ)))) + have h8 := (((hasDerivAt_const t (-17/36:ℝ)).mul ((hasDerivAt_id t).pow 2)).mul (hasDerivAt_const t (Real.log (2:ℝ)))) + have h9 := (((hasDerivAt_const t (-14/9:ℝ)).mul (((hasDerivAt_id t).pow 1).inv (by change t^1 ≠ 0; positivity))).mul ((hasDerivAt_id t).log (by positivity))) + have h10 := (((hasDerivAt_const t (1/6:ℝ)).mul ((hasDerivAt_id t).pow 2)).mul (hasDerivAt_const t ((Real.log (2:ℝ))^2))) + have h11 := (((hasDerivAt_const t (1/6:ℝ)).mul ((hasDerivAt_id t).pow 2)).mul (((hasDerivAt_id t).log (by positivity)).pow 2)) + have h12 := (((hasDerivAt_const t (14/9:ℝ)).mul (((hasDerivAt_id t).pow 1).inv (by change t^1 ≠ 0; positivity))).mul (hasDerivAt_const t (Real.log (2:ℝ)))) + have h13 := (((hasDerivAt_const t (17/36:ℝ)).mul ((hasDerivAt_id t).pow 2)).mul ((hasDerivAt_id t).log (by positivity))) + have h14 := ((((hasDerivAt_const t (-1/3:ℝ)).mul ((hasDerivAt_id t).pow 2)).mul (hasDerivAt_const t (Real.log (2:ℝ)))).mul ((hasDerivAt_id t).log (by positivity))) + have hd := ((((((((((((((h0.add h1).add h2).add h3).add h4).add h5).add h6).add h7).add h8).add h9).add h10).add h11).add h12).add h13).add h14) + convert! hd using 1 + simp only [id_eq,Pi.mul_apply,Pi.pow_apply,Pi.inv_apply] + field_simp + ring + +end ErdosBoundaryLoss + +end + +section + +open Set MeasureTheory +namespace ErdosBoundaryLoss + +theorem loss2_inner_integrable {t : ℝ} (ht : t ∈ Icc 1 2) : + IntervalIntegrable (loss2Kernel t) volume t 2 := by + have ht0 : t ≠ 0 := by have := ht.1; linarith + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le ht.2] + intro x hx + have hx0 : x ≠ 0 := by have := ht.1; have := hx.1; linarith + apply ContinuousAt.continuousWithinAt + unfold loss2Kernel + fun_prop (disch := simp_all) + +theorem loss2_inner_reduction {t : ℝ} (ht : t ∈ Icc 1 2) : + (∫ x in t..2,loss2Kernel t x)=reduced2 t := by + have htpos : 0 < t := by have := ht.1; linarith + have hd : ∀ x ∈ uIcc t 2, HasDerivAt (inner2Primitive t) (loss2Kernel t x) x := by + intro x hx + rw [uIcc_of_le ht.2] at hx + exact inner2Primitive_deriv t x htpos (lt_of_lt_of_le htpos hx.1) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd (loss2_inner_integrable ht)] + have ht0 : t ≠ 0 := ne_of_gt htpos + unfold inner2Primitive reduced2 + norm_num + field_simp + ring + +theorem loss3_inner_integrable {t u : ℝ} (ht : t ∈ Icc 1 2) (hu : u ∈ Icc t 2) : + IntervalIntegrable (loss3Kernel t u) volume u 2 := by + have ht0 : t ≠ 0 := by have := ht.1; linarith + have hu0 : u ≠ 0 := by have := ht.1; have := hu.1; linarith + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le hu.2] + intro x hx + have hx0 : x ≠ 0 := by have := ht.1; have := hu.1; have := hx.1; linarith + apply ContinuousAt.continuousWithinAt + unfold loss3Kernel + fun_prop (disch := simp_all) + +theorem loss3_inner_reduction {t u : ℝ} (ht : t ∈ Icc 1 2) (hu : u ∈ Icc t 2) : + (∫ x in u..2,loss3Kernel t u x)=middle3Kernel t u := by + have htpos : 0 < t := by have := ht.1; linarith + have hupos : 0 < u := lt_of_lt_of_le htpos hu.1 + have hd : ∀ x ∈ uIcc u 2, HasDerivAt (inner3Primitive t u) (loss3Kernel t u x) x := by + intro x hx + rw [uIcc_of_le hu.2] at hx + exact inner3Primitive_deriv t u x htpos hupos (lt_of_lt_of_le hupos hx.1) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd (loss3_inner_integrable ht hu)] + have ht0 : t ≠ 0 := ne_of_gt htpos + have hu0 : u ≠ 0 := ne_of_gt hupos + unfold inner3Primitive middle3Kernel + norm_num + field_simp + ring + +theorem loss3_middle_kernel_integrable {t : ℝ} (ht : t ∈ Icc 1 2) : + IntervalIntegrable (middle3Kernel t) volume t 2 := by + have ht0 : t ≠ 0 := by have := ht.1; linarith + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le ht.2] + intro u hu + have hu0 : u ≠ 0 := by have := ht.1; have := hu.1; linarith + apply ContinuousAt.continuousWithinAt + unfold middle3Kernel + fun_prop (disch := simp_all) + +theorem loss3_middle_reduction {t : ℝ} (ht : t ∈ Icc 1 2) : + (∫ u in t..2,∫ x in u..2,loss3Kernel t u x)=reduced3 t := by + have htpos : 0 < t := by have := ht.1; linarith + have hi : (∫ u in t..2,∫ x in u..2,loss3Kernel t u x)=∫ u in t..2,middle3Kernel t u := by + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le ht.2] at hu + exact loss3_inner_reduction ht hu + rw [hi] + have hd : ∀ u ∈ uIcc t 2, HasDerivAt (middle3Primitive t) (middle3Kernel t u) u := by + intro u hu + rw [uIcc_of_le ht.2] at hu + exact middle3Primitive_deriv t u htpos (lt_of_lt_of_le htpos hu.1) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd (loss3_middle_kernel_integrable ht)] + have ht0 : t ≠ 0 := ne_of_gt htpos + unfold middle3Primitive reduced3 + norm_num + field_simp + ring + +end ErdosBoundaryLoss + +end + +section + +open Set MeasureTheory +namespace ErdosBoundaryLoss + +theorem reduced2_integrable : IntervalIntegrable reduced2 volume 1 2 := by + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le (by norm_num : (1:ℝ) ≤ 2)] + intro t ht + have ht0 : t ≠ 0 := by have := ht.1; linarith + apply ContinuousAt.continuousWithinAt + unfold reduced2 + fun_prop (disch := simp_all) + +theorem reduced3_integrable : IntervalIntegrable reduced3 volume 1 2 := by + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le (by norm_num : (1:ℝ) ≤ 2)] + intro t ht + have ht0 : t ≠ 0 := by have := ht.1; linarith + apply ContinuousAt.continuousWithinAt + unfold reduced3 + fun_prop (disch := simp_all) + +theorem loss3_middle_integrable {t : ℝ} (ht : t ∈ Icc 1 2) : + IntervalIntegrable (fun u : ℝ => ∫ x in u..2,loss3Kernel t u x) volume t 2 := by + apply (loss3_middle_kernel_integrable ht).congr_uIoo + intro u hu + rw [uIoo_of_le ht.2] at hu + exact (loss3_inner_reduction ht ⟨hu.1.le,hu.2.le⟩).symm + +theorem loss2_outer_integrable : + IntervalIntegrable (fun t : ℝ => ∫ x in t..2,loss2Kernel t x) volume 1 2 := by + apply reduced2_integrable.congr_uIoo + intro t ht + rw [uIoo_of_le (by norm_num : (1:ℝ) ≤ 2)] at ht + exact (loss2_inner_reduction ⟨ht.1.le,ht.2.le⟩).symm + +theorem loss3_outer_integrable : + IntervalIntegrable (fun t : ℝ => ∫ u in t..2,∫ x in u..2,loss3Kernel t u x) volume 1 2 := by + apply reduced3_integrable.congr_uIoo + intro t ht + rw [uIoo_of_le (by norm_num : (1:ℝ) ≤ 2)] at ht + exact (loss3_middle_reduction ⟨ht.1.le,ht.2.le⟩).symm + +theorem L1_integrable : IntervalIntegrable (fun x : ℝ => 2*x/3) volume 1 2 := by + exact (continuous_const.mul continuous_id |>.div_const 3).intervalIntegrable 1 2 + +theorem L1_eq : L1=1 := by + unfold L1 + rw [intervalIntegral.integral_div,intervalIntegral.integral_const_mul] + norm_num + +theorem L2_eq : L2=-(35:ℝ)/36-(Real.log 2)^2+3*Real.log 2 := by + have hi : L2=∫ t in (1:ℝ)..2,reduced2 t := by + unfold L2 + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le (by norm_num : (1:ℝ) ≤ 2)] at ht + exact loss2_inner_reduction ht + rw [hi] + have hd : ∀ t ∈ uIcc (1:ℝ) 2, HasDerivAt outer2Primitive (reduced2 t) t := by + intro t ht + rw [uIcc_of_le (by norm_num : (1:ℝ) ≤ 2)] at ht + exact outer2Primitive_deriv t (by have := ht.1; linarith) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd reduced2_integrable] + unfold outer2Primitive + norm_num + ring + +theorem L3_eq : L3=(623:ℝ)/432-(19:ℝ)/12*Real.log 2+(1:ℝ)/3*(Real.log 2)^2 := by + have hi : L3=∫ t in (1:ℝ)..2,reduced3 t := by + unfold L3 + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le (by norm_num : (1:ℝ) ≤ 2)] at ht + exact loss3_middle_reduction ht + rw [hi] + have hd : ∀ t ∈ uIcc (1:ℝ) 2, HasDerivAt outer3Primitive (reduced3 t) t := by + intro t ht + rw [uIcc_of_le (by norm_num : (1:ℝ) ≤ 2)] at ht + exact outer3Primitive_deriv t (by have := ht.1; linarith) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd reduced3_integrable] + unfold outer3Primitive + norm_num + ring + +end ErdosBoundaryLoss + +end + +section + +namespace ErdosBoundaryLoss + +theorem log_two_bounds : (69:ℝ)/100 < Real.log 2 ∧ Real.log 2 < (7:ℝ)/10 := by + constructor + · linarith [Real.log_two_gt_d9] + · linarith [Real.log_two_lt_d9] + +theorem L2_lt : L2 < (64:ℝ)/100 := by + rw [L2_eq] + have h := log_two_bounds + have hp := mul_pos (sub_pos.mpr h.2) + (show 0 < 3-(7:ℝ)/10-Real.log 2 by linarith) + nlinarith + +theorem L3_lt : L3 < (51:ℝ)/100 := by + rw [L3_eq] + have h := log_two_bounds + have hp := mul_pos (sub_pos.mpr h.1) + (show 0 < (19:ℝ)/12-(Real.log 2+(69:ℝ)/100)/3 by linarith) + nlinarith + +theorem first_three_loss_lt : L1+L2+L3 < (43:ℝ)/20 := by + rw [L1_eq] + linarith [L2_lt,L3_lt] + +end ErdosBoundaryLoss + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/LowStateHorizon.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LowStateHorizon.lean new file mode 100644 index 0000000000000000000000000000000000000000..17f51f939cb146075901c7a722f8552717fcb5ec --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/LowStateHorizon.lean @@ -0,0 +1,176 @@ +import OAI.NumberTheory.Jacobsthal.Paths.AdmittedHarmonicPaths + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.LowStateHorizon + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostGrouping +open OccupationBoundaries ArrivalKernelGeometry RegeneratingInverseBands HarmonicWeightKernel + + theorem cost_ge_inv_add_one {t : ℝ} (ht : 0 < t) : 1 / (t + 1) ≤ cost t := by + have hx : 0 < 1 + 1 / t := by positivity + have h := Real.one_sub_inv_le_log_of_pos hx + have heq : 1 - (1 + 1 / t)⁻¹ = 1 / (t + 1) := by + field_simp [ht.ne', hx.ne', show t + 1 ≠ 0 by linarith] + ring + rw [heq] at h + exact h + +theorem stateRatio_ge_nineteen_twentieths (s : State) : (19 / 20 : ℝ) ≤ stateRatio s := by + cases s with + | inl s => change (19 / 20 : ℝ) ≤ s.1; linarith [s.2] + | inr s => change (19 / 20 : ℝ) ≤ s.1; linarith [s.2] + +theorem costKernel_time_update (z : CostState) : + ∀ᵐ y ∂costKernel z, y.2 = z.2 + cost (stateRatio y.1) := by + have hm : Measurable (fun s : State => (s, z.2 + cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + have hp : MeasurableSet {y : CostState | y.2 = z.2 + cost (stateRatio y.1)} := + measurableSet_eq_fun measurable_snd + (measurable_const.add (cost_measurable.comp (stateRatio_measurable.comp measurable_fst))) + rw [costKernel_eq_map] + apply (ae_map_iff hm.aemeasurable hp).mpr + exact Eventually.of_forall fun _ => rfl + +theorem harmonicKernel_time_update (z : CostState) : + ∀ᵐ y ∂harmonicKernel z, y.2 = z.2 + cost (stateRatio y.1) := + (harmonicKernel_absolutelyContinuous z).ae_le (costKernel_time_update z) + +def lowDomain (v ell S : ℝ) : Set CostState := arrivalSet v ell ∩ {z | stateRatio z.1 ≤ S} + +theorem lowDomain_measurable (v ell S : ℝ) : MeasurableSet (lowDomain v ell S) := + (arrivalSet_measurable v ell).inter (measurableSet_le (stateRatio_measurable.comp measurable_fst) measurable_const) + +noncomputable def lowKernel (K : Kernel CostState CostState) (v ell S : ℝ) : Kernel CostState CostState := + K.restrict (lowDomain_measurable v ell S) + +theorem low_step_clock (K : Kernel CostState CostState) (v ell S : ℝ) + (hTime : ∀ z, ∀ᵐ y ∂K z, y.2 = z.2 + cost (stateRatio y.1)) (z : CostState) : + ∀ᵐ y ∂lowKernel K v ell S z, z.2 + 1 / (S + 1) ≤ y.2 := by + rw [lowKernel, Kernel.restrict_apply] + filter_upwards [ae_restrict_of_ae (hTime z), ae_restrict_mem (lowDomain_measurable v ell S)] with y hy hD + have hs : stateRatio y.1 ≤ S := hD.2 + have ht := stateRatio_pos y.1 + have hc : 1 / (S + 1) ≤ cost (stateRatio y.1) := + le_trans (one_div_le_one_div_of_le (by linarith : 0 < stateRatio y.1 + 1) (by linarith)) + (cost_ge_inv_add_one ht) + linarith + +theorem low_pow_clock (K : Kernel CostState CostState) (v ell S : ℝ) + (hTime : ∀ z, ∀ᵐ y ∂K z, y.2 = z.2 + cost (stateRatio y.1)) (n : ℕ) (z : CostState) : + ∀ᵐ y ∂((lowKernel K v ell S) ^ n) z, z.2 + (n : ℝ) / (S + 1) ≤ y.2 := by + induction n with + | zero => + simp only [Nat.cast_zero] + change ∀ᵐ y ∂Measure.dirac z, z.2 + (0 : ℝ) / (S + 1) ≤ y.2 + exact (ae_dirac_iff (p := fun y : CostState => z.2 + (0 : ℝ) / (S + 1) ≤ y.2) + (measurableSet_le measurable_const measurable_snd)).mpr (by simp) + | succ n ih => + have hp : (lowKernel K v ell S) ^ (n + 1) = (lowKernel K v ell S) ∘ₖ ((lowKernel K v ell S) ^ n) := pow_succ' _ _ + rw [hp] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le measurable_const measurable_snd) + filter_upwards [ih] with y hy + filter_upwards [low_step_clock K v ell S hTime y] with t ht + calc + z.2 + ((n + 1 : ℕ) : ℝ) / (S + 1) = (z.2 + (n : ℝ) / (S + 1)) + 1 / (S + 1) := by push_cast; ring + _ ≤ y.2 + 1 / (S + 1) := add_le_add hy le_rfl + _ ≤ t.2 := ht + +theorem low_pow_terminal (K : Kernel CostState CostState) (v ell S : ℝ) (n : ℕ) (z : CostState) : + ∀ᵐ y ∂((lowKernel K v ell S) ^ (n + 1)) z, y ∈ lowDomain v ell S := by + have hp : (lowKernel K v ell S) ^ (n + 1) = (lowKernel K v ell S) ∘ₖ ((lowKernel K v ell S) ^ n) := pow_succ' _ _ + rw [hp] + apply Kernel.ae_comp_of_ae_ae (lowDomain_measurable v ell S) + apply Eventually.of_forall + intro y + rw [lowKernel, Kernel.restrict_apply] + exact ae_restrict_mem (lowDomain_measurable v ell S) + +theorem low_pow_zero_of_clock (K : Kernel CostState CostState) (v ell S : ℝ) + (hTime : ∀ z, ∀ᵐ y ∂K z, y.2 = z.2 + cost (stateRatio y.1)) + (hell : 0 < ell) (n : ℕ) (hn : 0 < n) (z : CostState) + (hclock : v - z.2 - Real.log ((19 / 20 : ℝ) * ell) ≤ (n : ℝ) / (S + 1)) : + ((lowKernel K v ell S) ^ n) z = 0 := by + have hD : ∀ᵐ y ∂((lowKernel K v ell S) ^ n) z, y ∈ lowDomain v ell S := by + cases n with + | zero => omega + | succ n => exact low_pow_terminal K v ell S n z + have hfalse : ∀ᵐ y ∂((lowKernel K v ell S) ^ n) z, False := by + filter_upwards [low_pow_clock K v ell S hTime n z, hD] with y hy hdom + have ha : ell < gapValue v y / stateRatio y.1 := hdom.1 + have hmul := (lt_div_iff₀ (stateRatio_pos y.1)).mp ha + have hgap : (19 / 20 : ℝ) * ell < gapValue v y := by + have hlow := mul_le_mul_of_nonneg_left (stateRatio_ge_nineteen_twentieths y.1) hell.le + nlinarith + have hlog := Real.log_lt_log (mul_pos (by norm_num : (0 : ℝ) < 19 / 20) hell) hgap + rw [gapValue, Real.log_exp] at hlog + linarith + apply Measure.measure_univ_eq_zero.mp + simpa only [ae_iff, not_false_eq_true, Set.ofPred_true] using hfalse + +noncomputable def sourceHorizon (S B : ℝ) : ℕ := ⌈(S + 1) * (Real.log B + 2)⌉₊ + 1 + +theorem source_low_horizon (K : Kernel CostState CostState) (v ell S B : ℝ) + (hTime : ∀ z, ∀ᵐ y ∂K z, y.2 = z.2 + cost (stateRatio y.1)) + (hell : 1 ≤ ell) (hS : 0 < S) (hB : 0 < B) (z : CostState) + (hgap : gapValue v z ≤ (23 / 10 : ℝ) * B) (n : ℕ) (hn : sourceHorizon S B ≤ n) : + ((lowKernel K v ell S) ^ n) z = 0 := by + have hell0 : 0 < ell := by linarith + have hn0 : 0 < n := by unfold sourceHorizon at hn; omega + apply low_pow_zero_of_clock K v ell S hTime hell0 n hn0 z + have hlogR := Real.log_le_log (Real.exp_pos (v - z.2)) hgap + rw [Real.log_exp, Real.log_mul (by norm_num : (23 / 10 : ℝ) ≠ 0) hB.ne'] at hlogR + have hlog23 : Real.log (23 / 10 : ℝ) ≤ 13 / 10 := by + have h := Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 23 / 10) + norm_num at h + exact h + have hlog19 : (-1 / 19 : ℝ) ≤ Real.log (19 / 20 : ℝ) := by + have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 19 / 20) + norm_num at h + linarith + have hlogell : Real.log (19 / 20 : ℝ) ≤ Real.log ((19 / 20 : ℝ) * ell) := + Real.log_le_log (by norm_num) (by nlinarith) + have hspan : v - z.2 - Real.log ((19 / 20 : ℝ) * ell) ≤ Real.log B + 2 := by linarith + have hceil := Nat.le_ceil ((S + 1) * (Real.log B + 2)) + have hN : ((⌈(S + 1) * (Real.log B + 2)⌉₊ : ℕ) : ℝ) ≤ (n : ℝ) := by + have hN' : ⌈(S + 1) * (Real.log B + 2)⌉₊ ≤ n := by unfold sourceHorizon at hn; omega + exact_mod_cast hN' + apply le_trans hspan + apply (le_div_iff₀ (by linarith : 0 < S + 1)).mpr + nlinarith + +theorem source_horizon_log_cube {B : ℝ} (hB : 2 ≤ Real.log B) : + ((sourceHorizon ((Real.log B) ^ 2) B : ℕ) : ℝ) ≤ 5 * (Real.log B) ^ 3 := by + let x := Real.log B + have hx : 2 ≤ x := hB + have hpos : 0 ≤ (x ^ 2 + 1) * (x + 2) := by positivity + have hc := (Nat.ceil_lt_add_one hpos).le + change ((⌈(x ^ 2 + 1) * (x + 2)⌉₊ + 1 : ℕ) : ℝ) ≤ 5 * x ^ 3 + push_cast + have h2 : 0 ≤ (x - 2) * x := mul_nonneg (by linarith) (by linarith) + have h3 : 0 ≤ (x - 2) * x ^ 2 := mul_nonneg (by linarith) (sq_nonneg x) + nlinarith + +theorem tilted_source_horizon (v ell S B : ℝ) (hell : 1 ≤ ell) (hS : 0 < S) (hB : 0 < B) + (z : CostState) (hgap : gapValue v z ≤ (23 / 10 : ℝ) * B) (n : ℕ) (hn : sourceHorizon S B ≤ n) : + ((lowKernel costKernel v ell S) ^ n) z = 0 := + source_low_horizon costKernel v ell S B costKernel_time_update hell hS hB z hgap n hn + +theorem harmonic_source_horizon (v ell S B : ℝ) (hell : 1 ≤ ell) (hS : 0 < S) (hB : 0 < B) + (z : CostState) (hgap : gapValue v z ≤ (23 / 10 : ℝ) * B) (n : ℕ) (hn : sourceHorizon S B ≤ n) : + ((lowKernel harmonicKernel v ell S) ^ n) z = 0 := + source_low_horizon harmonicKernel v ell S B harmonicKernel_time_update hell hS hB z hgap n hn + +end NumberTheoryLean.LowStateHorizon + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/MarginalGrowth.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MarginalGrowth.lean new file mode 100644 index 0000000000000000000000000000000000000000..0820ecdcae2260f65d8f66d80baa862be99e5ad4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MarginalGrowth.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialMesh + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.MarginalGrowth + +open _root_.Set _root_.Filter +open scoped Topology +open ExponentialMesh + +noncomputable def factor (L κ w S : ℝ) : ℝ := + (1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)))* + Real.exp (L*(1+S)^3*mesh κ w)*(1+20*mesh κ w) + +theorem factor_pos (L κ w S : ℝ) : 0 < factor L κ w S := by + have hm := mesh_pos κ w + unfold factor + positivity + +theorem factor_exp_upper (L κ w S : ℝ) : factor L κ w S ≤ + Real.exp (Real.exp (-(κ/2)*Real.sqrt (Real.log w))+L*(1+S)^3*mesh κ w+20*mesh κ w) := by + have hm := mesh_pos κ w + have h1 : 1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)) ≤ Real.exp (Real.exp (-(κ/2)*Real.sqrt (Real.log w))) := by + simpa only [add_comm] using Real.add_one_le_exp (Real.exp (-(κ/2)*Real.sqrt (Real.log w))) + have h2 : 1+20*mesh κ w ≤ Real.exp (20*mesh κ w) := by + simpa only [add_comm] using Real.add_one_le_exp (20*mesh κ w) + unfold factor + rw [Real.exp_add,Real.exp_add] + exact mul_le_mul (mul_le_mul_of_nonneg_right h1 (Real.exp_pos _).le) h2 (by positivity) (by positivity) + +theorem factor_power_bounded {A L κ : ℝ} (hA : 0 ≤ A) (hL : 0 ≤ L) (hκ : 0 < κ) : + ∀ᶠ w : ℝ in atTop, ∀ S : ℝ, 0 ≤ S → S ≤ (Real.log w)^3 → ∀ n : ℕ, + (n:ℝ) ≤ A*(Real.log w)^3 → (factor L κ w S)^n ≤ 2 := by + have ht := log_power_exp_tendsto (A*(21+8*L)) 12 (show 0 < κ/2 by positivity) + filter_upwards [ht.eventually (eventually_lt_nhds (Real.log_pos (by norm_num : (1:ℝ) < 2))), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with w hsmall hlog + intro S hS hSP n hn + let e := Real.exp (-(κ/2)*Real.sqrt (Real.log w)) + let τ := mesh κ w + let a := e+L*(1+S)^3*τ+20*τ + have hτ : 0 < τ := mesh_pos κ w + have he : 0 ≤ e := (Real.exp_pos _).le + have hτe : τ ≤ e := by + apply (mesh_upper κ w).trans + apply Real.exp_le_exp.mpr + nlinarith [Real.sqrt_nonneg (Real.log w)] + have hp3 : 1 ≤ (Real.log w)^3 := one_le_pow₀ hlog + have hp9 : 1 ≤ (Real.log w)^9 := one_le_pow₀ hlog + have he9 : e ≤ (Real.log w)^9*e := by simpa only [one_mul] using mul_le_mul_of_nonneg_right hp9 he + have hSp : 1+S ≤ 2*(Real.log w)^3 := by linarith + have hmid : L*(1+S)^3*τ ≤ 8*L*(Real.log w)^9*e := by + calc + _ ≤ (L*(2*(Real.log w)^3)^3)*e := mul_le_mul + (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by linarith) hSp 3) hL) hτe hτ.le (by positivity) + _ = _ := by ring + have ha0 : 0 ≤ a := by dsimp [a]; positivity + have ha : a ≤ (21+8*L)*(Real.log w)^9*e := by dsimp [a]; nlinarith + have hna : (n:ℝ)*a ≤ (A*(21+8*L))*(Real.log w)^12*e := by + calc + _ ≤ (A*(Real.log w)^3)*((21+8*L)*(Real.log w)^9*e) := mul_le_mul hn ha ha0 (by positivity) + _ = _ := by ring + have hpow := pow_le_pow_left₀ (factor_pos L κ w S).le (factor_exp_upper L κ w S) n + rw [← Real.exp_nat_mul] at hpow + calc + _ ≤ Real.exp ((n:ℝ)*a) := hpow + _ ≤ Real.exp (Real.log 2) := Real.exp_le_exp.mpr (hna.trans hsmall.le) + _ = _ := Real.exp_log (by norm_num) + +end NumberTheoryLean.MarginalGrowth + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/MarginalProfiles.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MarginalProfiles.lean new file mode 100644 index 0000000000000000000000000000000000000000..c454202624ef316055db4cc75c04e739f6e14616 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MarginalProfiles.lean @@ -0,0 +1,128 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.MeshStationary +import OAI.NumberTheory.Jacobsthal.Primes.PrimeGridGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.MarginalProfiles + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeSideSupport PrimeGridGeometry DerivativeWeights WeightFutureIntegrals + +noncomputable def profile (m : ℕ) : Side → ℝ → ℝ + | .even,_ => 1 + | .odd,t => 1-1/t^2+3*width m*W t + +theorem index_regular {m j : ℕ} (hm : 1 ≤ m) (i : Side) (hj : lowerIndex m i ≤ j) : + regularLower i ≤ point m j := by + cases i with + | even => simpa only [regularLower,Nat.cast_ofNat] using (threshold_le_point hm 2 j).mpr hj + | odd => simpa only [regularLower,Nat.cast_one] using (threshold_le_point hm 1 j).mpr (by simpa only [lowerIndex,one_mul] using hj) + +theorem index_valid {m j : ℕ} (hm : 1 ≤ m) (i : Side) (hj : lowerIndex m i ≤ j) : + Valid i (point m j) := by + have ht := index_regular hm i hj + cases i <;> dsimp [Valid,regularLower] at * <;> linarith + +theorem profile_nonneg (m : ℕ) {i : Side} {t : ℝ} (ht : regularLower i ≤ t) : 0 ≤ profile m i t := by + cases i with + | even => exact zero_le_one + | odd => + have ht1 : 1 ≤ t := ht + have ht0 : 0 < t := by linarith + have hinv : 1/t^2 ≤ 1 := by + simpa only [div_one] using one_div_le_one_div_of_le (by norm_num : (0:ℝ) < 1) (one_le_pow₀ ht1 : (1:ℝ) ≤ t^2) + have hW := (W_pos ht0).le + have hlead : 0 ≤ 1-1/t^2 := sub_nonneg.mpr hinv + have hw := width_nonneg m + change 0 ≤ 1-1/t^2+3*width m*W t + positivity + +theorem even_stationary_profile {m j : ℕ} (hm : 1 ≤ m) (hj : m ≤ j) : + W (point m j)*(width m*((Finset.Icc (2*m) (j+m+1)).card:ℝ)) ≤ profile m .odd (point m j) := by + have ht : (1:ℝ) ≤ point m j := by simpa only [Nat.cast_one] using (threshold_le_point hm 1 j).mpr (by simpa only [lowerIndex,one_mul] using hj) + have ht0 : 0 < point m j := by linarith + have hcount : width m*((Finset.Icc (2*m) (j+m+1)).card:ℝ) ≤ point m j-1+3*width m := by + simpa only [width,point,div_eq_mul_inv,one_mul] using + Erdos970Dependency.MeshStationary.even_row_literal m j hm hj + calc + _ ≤ W (point m j)*(point m j-1+3*width m) := mul_le_mul_of_nonneg_left hcount (W_pos ht0).le + _ = _ := by unfold profile W; field_simp; ring + +theorem odd_stationary_profile {m j : ℕ} (hm : 1 ≤ m) (hj : 2*m ≤ j) : + W (point m j)*(∑ k ∈ Finset.Icc m (j+m+1),width m*profile m .odd (point m k)) ≤ 1+20*width m := by + simpa only [width,point,profile,W,div_eq_mul_inv,one_mul,mul_assoc] using + Erdos970Dependency.MeshStationary.odd_row_literal m j hm hj + +theorem stationary_profile {m j : ℕ} (hm : 1 ≤ m) (i : Side) (hj : lowerIndex m i.flip ≤ j) : + W (point m j)*(∑ k ∈ Finset.Icc (lowerIndex m i) (j+m+1),width m*profile m i (point m k)) ≤ + (1+20*width m)*profile m i.flip (point m j) := by + cases i with + | even => + have hj' : m ≤ j := hj + have ht := index_regular hm .odd hj' + have hp := profile_nonneg m ht + have hsum : (∑ k ∈ Finset.Icc (2*m) (j+m+1),width m*profile m .even (point m k)) = + width m*((Finset.Icc (2*m) (j+m+1)).card:ℝ) := by + simp only [profile,mul_one,Finset.sum_const,nsmul_eq_mul] + ring + change W (point m j)*(∑ k ∈ Finset.Icc (2*m) (j+m+1),width m*profile m .even (point m k)) ≤ + (1+20*width m)*profile m .odd (point m j) + rw [hsum] + apply (even_stationary_profile hm hj').trans + have hw := width_nonneg m + have h := mul_nonneg (show 0 ≤ 20*width m by positivity) hp + nlinarith + | odd => + have hj' : 2*m ≤ j := hj + simpa only [lowerIndex,Side.flip,profile,mul_one] using odd_stationary_profile hm hj' + +theorem W_le_six {t : ℝ} (ht : (1/2:ℝ) ≤ t) : W t ≤ 6 := by + have ht0 : 0 < t := by linarith + unfold W + apply (div_le_iff₀ (sq_pos_of_pos ht0)).mpr + nlinarith [sq_nonneg (t-1/2)] + +theorem W_initial_cost {t : ℝ} (ht : 2 ≤ t) : W t*(t+3) ≤ 4 := by + have ht0 : 0 < t := by linarith + calc + _ = ((t+1)*(t+3))/t^2 := by unfold W; ring + _ ≤ _ := (div_le_iff₀ (sq_pos_of_pos ht0)).mpr (by nlinarith [sq_nonneg (t-2)]) + +theorem first_row_sum {m j : ℕ} (hm : 1 ≤ m) (hj : 2*m ≤ j) (I : Finset ℕ) + (hI : I ⊆ Finset.Icc 0 (j+m+1)) (hpoints : ∀ k ∈ I,(1/2:ℝ) ≤ point m k) : + W (point m j)*(∑ k ∈ I,width m*W (point m k)) ≤ 24 := by + have ht : (2:ℝ) ≤ point m j := by simpa only [Nat.cast_ofNat] using (threshold_le_point hm 2 j).mpr hj + have hW := (W_pos (show 0 < point m j by linarith)).le + have hw := width_nonneg m + have hw1 : width m ≤ 1 := Erdos970Dependency.MeshStationary.mesh_le_one m hm + have hc : I.card ≤ j+m+2 := by + have h := Finset.card_le_card hI + rw [Nat.card_Icc] at h + omega + have hcR : (I.card:ℝ) ≤ ((j+m+2:ℕ):ℝ) := by exact_mod_cast hc + have hs : (∑ k ∈ I,width m*W (point m k)) ≤ 6*(point m j+3) := by + calc + _ ≤ ∑ _k ∈ I,width m*6 := Finset.sum_le_sum (fun k hk => mul_le_mul_of_nonneg_left (W_le_six (hpoints k hk)) hw) + _ = (6*width m)*(I.card:ℝ) := by rw [Finset.sum_const,nsmul_eq_mul]; ring + _ ≤ (6*width m)*((j+m+2:ℕ):ℝ) := mul_le_mul_of_nonneg_left hcR (by positivity) + _ = 6*point m (j+m+2) := by unfold point width; ring + _ = 6*(point m j+1+2*width m) := by rw [incoming_grid_end hm j] + _ ≤ _ := by linarith + calc + _ ≤ W (point m j)*(6*(point m j+3)) := mul_le_mul_of_nonneg_left hs hW + _ = 6*(W (point m j)*(point m j+3)) := by ring + _ ≤ 6*4 := mul_le_mul_of_nonneg_left (W_initial_cost ht) (by norm_num) + _ = _ := by norm_num + +end NumberTheoryLean.MarginalProfiles + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/MinorizingCostRegularity.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MinorizingCostRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd5da3634be7ea0f3742e3cabadeb64669e2df4c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MinorizingCostRegularity.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Probability.FirstHitKernels + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.MinorizingCostRegularity + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures JointMinorization + +theorem cost_strictAntiOn : StrictAntiOn cost (Ioi 0) := by + intro t ht u hu htu + change 0 < t at ht + change 0 < u at hu + unfold cost + have hi := one_div_lt_one_div_of_lt ht htu + exact Real.log_lt_log (by positivity) (by linarith) + +theorem cost_level_null {a b k y : ℝ} (ha : 0 < a) : + volume (Icc a b ∩ {u : ℝ | k + cost u = y}) = 0 := by + apply Set.Subsingleton.measure_zero + intro u hu v hv + apply cost_strictAntiOn.injOn + (show u ∈ Ioi 0 from lt_of_lt_of_le ha hu.1.1) + (show v ∈ Ioi 0 from lt_of_lt_of_le ha hv.1.1) + have huEq : k + cost u = y := hu.2 + have hvEq : k + cost v = y := hv.2 + linarith + +theorem rectangleLaw_cost_level {L : ℝ} (hL : 3 ≤ L) (T y : ℝ) : + rectangleLaw L {x : ℝ × ℝ | (pairCost T x).2 = y} = 0 := by + have hA : MeasurableSet {x : ℝ × ℝ | (pairCost T x).2 = y} := + measurableSet_eq_fun (measurable_snd.comp (pairCost_measurable T)) measurable_const + rw [rectangleLaw, rectangle, ← Measure.prod_restrict, Measure.prod_apply hA] + apply lintegral_eq_zero_of_ae_eq_zero + apply Eventually.of_forall + intro t + change (volume.restrict (Icc (L + 1) (L + 2))) {u : ℝ | T + cost t + cost u = y} = 0 + have hF : MeasurableSet {u : ℝ | T + cost t + cost u = y} := + measurableSet_eq_fun (measurable_const.add cost_measurable) measurable_const + rw [Measure.restrict_apply hF, inter_comm] + exact cost_level_null (by linarith) + +theorem minorizingLaw_cost_level {L : ℝ} (hL : 3 ≤ L) (T y : ℝ) : + minorizingLaw L T {z : ℝ × ℝ | z.2 = y} = 0 := by + rw [minorizingLaw, Measure.map_apply (pairCost_measurable T) + (measurableSet_eq_fun measurable_snd measurable_const)] + exact rectangleLaw_cost_level hL T y + +theorem minorizingCost_nullSingletonClass {L : ℝ} (hL : 3 ≤ L) (T : ℝ) : + NullSingletonClass ((minorizingLaw L T).map Prod.snd) := by + constructor + intro y + rw [Measure.map_apply measurable_snd (measurableSet_singleton y)] + exact minorizingLaw_cost_level hL T y + +theorem minorizingCost_countable_null {L : ℝ} (hL : 3 ≤ L) (T : ℝ) + {C : Set ℝ} (hC : C.Countable) : ((minorizingLaw L T).map Prod.snd) C = 0 := by + let := minorizingCost_nullSingletonClass hL T + exact hC.measure_zero _ + +end NumberTheoryLean.MinorizingCostRegularity + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/MovingLocalReference.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MovingLocalReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..103ef6d918ec24c74390de903f8a507e80d01e5d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/MovingLocalReference.lean @@ -0,0 +1,756 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ReferenceHighIntervals + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.WeightDistantDecay + +open FinitePathGeometry DerivativeWeights WeightDickmanComparison TwoStepDensityBounds +open Dickman DickmanDecay DickmanFiniteDecay + +theorem sided_rho_bounds : ∃ c C : ℝ,0 < c ∧ 0 < C ∧ ∀ i : Side,∀ s : ℝ,2 ≤ s → + c*rho (s-2) ≤ weight i s ∧ weight i s ≤ C*rho (s-2) := by + obtain ⟨c,C,hc,hC,h⟩ := weights_dickman_bounds + refine ⟨c,C,hc,hC,?_⟩ + intro i s hs + cases i with + | even => exact (h s hs).1 + | odd => exact (h s hs).2 + +theorem compact_weight_lower : ∃ m : ℝ,0 < m ∧ ∀ i s,Valid i s → s ≤ 4 → m ≤ weight i s := by + let m := min (weight .even 4) (weight .odd 4) + have he : 0 < weight .even 4 := weight_pos (valid_of_three_le .even (by norm_num)) + have ho : 0 < weight .odd 4 := weight_pos (valid_of_three_le .odd (by norm_num)) + refine ⟨m,lt_min he ho,?_⟩ + intro i s hs hs4 + have hm : m ≤ weight i 4 := by cases i; exact min_le_left _ _; exact min_le_right _ _ + exact hm.trans (weight_antitone hs (valid_of_three_le i (by norm_num)) hs4) + +theorem rho_one_rate {a b : ℝ} (ha : 2 ≤ a) (hab : a ≤ b) : + rho b ≤ rho a*Real.exp (-(b-a)) := by + simpa only [one_mul,neg_mul] using + rho_exponential_comparison 2 1 a b le_rfl (fun t ht => hazard_ge_one ht) ha hab + +theorem relative_weight_decay : ∃ C : ℝ,0 < C ∧ ∀ i j : Side,∀ s t : ℝ, + Valid i s → s+4 ≤ t → weight j t ≤ C*weight i s*Real.exp (-(t-s)/2) := by + obtain ⟨c₀,C₀,hc₀,hC₀,hρ⟩ := sided_rho_bounds + obtain ⟨m,hm,hmLower⟩ := compact_weight_lower + let CL := C₀/c₀ + let CS := C₀*Real.exp 4/m + have hCL : 0 < CL := div_pos hC₀ hc₀ + have hCS : 0 < CS := div_pos (mul_pos hC₀ (Real.exp_pos _)) hm + refine ⟨max CL CS,hCL.trans_le (le_max_left _ _),?_⟩ + intro i j s t hs hst + have hs0 := valid_pos hs + have ht4 : 4 ≤ t := by linarith + have ht2 : 2 ≤ t := by linarith + have ht0 : 0 < t := by linarith + have hwt := (hρ j t ht2).2 + have hφ := weight_pos hs + by_cases hs4 : 4 ≤ s + · have hcomp := rho_one_rate (a:=s-2) (b:=t-2) (by linarith) (by linarith) + have hlow := (hρ i s (by linarith)).1 + have hdiv : rho (s-2) ≤ weight i s/c₀ := (le_div_iff₀ hc₀).mpr (by nlinarith) + have he : Real.exp (-((t-2)-(s-2))) ≤ Real.exp (-(t-s)/2) := Real.exp_le_exp.mpr (by linarith) + calc + _ ≤ C₀*rho (t-2) := hwt + _ ≤ C₀*(rho (s-2)*Real.exp (-((t-2)-(s-2)))) := mul_le_mul_of_nonneg_left hcomp hC₀.le + _ ≤ C₀*((weight i s/c₀)*Real.exp (-(t-s)/2)) := by + exact mul_le_mul_of_nonneg_left (mul_le_mul hdiv he (Real.exp_pos _).le (by positivity)) hC₀.le + _ = CL*weight i s*Real.exp (-(t-s)/2) := by dsimp [CL]; ring + _ ≤ _ := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (le_max_left CL CS) hφ.le) (Real.exp_pos _).le + · have hs4' : s ≤ 4 := le_of_lt (lt_of_not_ge hs4) + have hmin := hmLower i s hs hs4' + have hcomp := rho_one_rate (a:=2) (b:=t-2) le_rfl (by linarith) + have hbound : rho (t-2) ≤ Real.exp 4*Real.exp (-(t-s)/2) := by + calc + _ ≤ rho 2*Real.exp (-((t-2)-2)) := hcomp + _ ≤ Real.exp (-((t-2)-2)) := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right (rho_le_one 2) (Real.exp_pos _).le + _ ≤ _ := by rw [← Real.exp_add]; apply Real.exp_le_exp.mpr; linarith + have hcoeff : C₀*Real.exp 4 ≤ CS*weight i s := by + calc + _ = CS*m := by dsimp [CS]; field_simp + _ ≤ _ := mul_le_mul_of_nonneg_left hmin hCS.le + calc + _ ≤ C₀*rho (t-2) := hwt + _ ≤ C₀*(Real.exp 4*Real.exp (-(t-s)/2)) := mul_le_mul_of_nonneg_left hbound hC₀.le + _ ≤ CS*weight i s*Real.exp (-(t-s)/2) := by + simpa only [mul_assoc] using mul_le_mul_of_nonneg_right hcoeff (Real.exp_pos _).le + _ ≤ _ := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (le_max_right CL CS) hφ.le) (Real.exp_pos _).le + +theorem weight_exponential_majorant (rate : ℝ) : ∃ C T : ℝ,0 < C ∧ 4 ≤ T ∧ + ∀ i : Side,∀ t : ℝ,T ≤ t → weight i t ≤ C*Real.exp (-rate*t) := by + obtain ⟨_c,C₀,_hc,hC₀,hρ⟩ := sided_rho_bounds + obtain ⟨A,hA,T,hT,h⟩ := rho_exponential_majorant rate + refine ⟨C₀*A*Real.exp (2*rate),T+2,by positivity,by linarith,?_⟩ + intro i t ht + have hr := h (t-2) (by linarith) + calc + _ ≤ C₀*rho (t-2) := (hρ i t (by linarith)).2 + _ ≤ C₀*(A*Real.exp (-rate*(t-2))) := mul_le_mul_of_nonneg_left hr hC₀.le + _ = _ := by rw [show -rate*(t-2)=2*rate+(-rate*t) by ring,Real.exp_add]; ring + +end NumberTheoryLean.WeightDistantDecay + + + +namespace NumberTheoryLean.ReferenceResidualErrors + +open _root_.Finset _root_.MeasureTheory +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry ActualBoundaryDomain +open ReferenceBenchmarkDecay ReferenceDifferentiation ReferenceCancellation ReferenceWeightDomination +open ReferenceSourcePrimeSets ReferenceMertens ReferenceLocalResidual ReferenceHighIntervals +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem ratio_eq_gap_div_cutoff {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) + (hb : 0 < z.cutoff) : z.ratio=z.gap/z.cutoff := by + have he := (eq_div_iff (ne_of_gt (valid_pos hs))).mp hz + apply (eq_div_iff (ne_of_gt hb)).mpr + nlinarith + +theorem boundary_parent_eq (i : Side) {r : ℝ} (hr : BoundaryDomain i r) : + parentBenchmark i (r/2)=benchmark i (r/2) := by + cases i with + | even => exact parent_even_eq_ordinary (by change 4 ≤ r at hr; linarith) + | odd => rfl + +noncomputable def boundaryProductError (w : ℝ) (z : Node) : ℝ := + (referenceProduct w 2 true-normalization w/2)*(benchmark z.side (z.gap/2)-1) + +noncomputable def parentProductError (w : ℝ) (z : Node) : ℝ := + (referenceProduct w z.cutoff z.closed-normalization w/z.cutoff)*(parentBenchmark z.side z.ratio-1) + +noncomputable def primeProductError (w : ℝ) (z : Node) : ℝ := + ∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹* + (referenceProduct w (primeExponent w p) false-normalization w/primeExponent w p)* + (benchmark z.side.flip (childRatio w z.gap p)-1) + +noncomputable def quadratureError (w : ℝ) (z : Node) : ℝ := + (∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹* + (benchmark z.side.flip (childRatio w z.gap p)-1)/primeExponent w p)- + ∫ x in highInterval z.cutoff z.closed,(benchmark z.side.flip (z.gap/x-1)-1)/x^2 + +theorem actual_continuous_zero (w : ℝ) {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) + (hb : 2 ≤ z.cutoff) (hdom : BoundaryDomain z.side z.gap) : + (normalization w/2)*(benchmark z.side (z.gap/2)-1)- + (normalization w/z.cutoff)*(parentBenchmark z.side z.ratio-1)- + normalization w*(∫ x in highInterval z.cutoff z.closed,(benchmark z.side.flip (z.gap/x-1)-1)/x^2)=0 := by + have hr := ratio_eq_gap_div_cutoff hs hz (by linarith) + have hd : ParentDomain z.side (z.gap/z.cutoff) := by rw [← hr]; exact valid_parent_domain hs + have hc := continuous_reference_cancellation z.side hb hd + rw [boundary_parent_eq z.side hdom,← hr] at hc + rw [highInterval_integral hb] + have hm := congrArg (fun t : ℝ => normalization w*t) hc + convert! hm using 1 <;> ring + +theorem residual_error_identity (w : ℝ) {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) + (hb : 2 ≤ z.cutoff) (hdom : BoundaryDomain z.side z.gap) : + sourceResidual w z=boundaryProductError w z-parentProductError w z-primeProductError w z- + normalization w*quadratureError w z := by + have hc := actual_continuous_zero w hs hz hb hdom + have hp : (∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹*referenceProduct w (primeExponent w p) false* + (benchmark z.side.flip (childRatio w z.gap p)-1))= + primeProductError w z+normalization w*(∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹* + (benchmark z.side.flip (childRatio w z.gap p)-1)/primeExponent w p) := by + rw [primeProductError,Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _hp + ring + unfold sourceResidual boundaryProductError parentProductError quadratureError + rw [hp] + nlinarith + +end NumberTheoryLean.ReferenceResidualErrors + + + +namespace NumberTheoryLean.ReferenceProductErrorBounds + +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry +open ReferenceMertens ReferenceSourcePrimeSets ReferenceBenchmarkDecay ReferenceDifferentiation +open ReferenceWeightDomination ReferenceResidualErrors +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def primeError (c w t : ℝ) : ℝ := Real.exp (-c*Real.sqrt (t*Real.log w)) + +theorem primeError_pos (c w t : ℝ) : 0 < primeError c w t := Real.exp_pos _ + +theorem primeError_antitone {c w t s : ℝ} (hc : 0 ≤ c) (hw : 1 < w) (hts : t ≤ s) : + primeError c w s ≤ primeError c w t := by + apply Real.exp_le_exp.mpr + have h := Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_right hts (Real.log_pos hw).le) + nlinarith + +theorem divided_error_bound {c C w t : ℝ} (hc : 0 ≤ c) (hC : 0 ≤ C) (hw : 1 < w) (ht : 2 ≤ t) : + (C/t)*primeError c w t ≤ (C/2)*primeError c w 2 := by + apply mul_le_mul (div_le_div_of_nonneg_left hC (by norm_num : (0:ℝ)<2) ht) + (primeError_antitone hc hw ht) (primeError_pos _ _ _).le (by positivity) + +theorem finite_product_error_bounds {c C w : ℝ} (hc : 0 ≤ c) (hC : 0 ≤ C) (hw : 1 < w) + (hP : ∀ t : ℝ,2 ≤ t → ∀ closed : Bool, + |referenceProduct w t closed-normalization w/t| ≤ (C/t)*primeError c w t) + {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) (hb : 2 ≤ z.cutoff) : + |boundaryProductError w z| ≤ 2*C*weight z.side z.ratio*primeError c w 2 ∧ + |parentProductError w z| ≤ 2*C*weight z.side z.ratio*primeError c w 2 ∧ + |primeProductError w z| ≤ (2*C*weight z.side z.ratio*primeError c w 2)* + (∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹) := by + have hφ := weight_pos hs + have hE := primeError_pos c w 2 + have hr := ratio_eq_gap_div_cutoff hs hz (by linarith) + have hs' : Valid z.side (z.gap/z.cutoff) := by rwa [← hr] + have hD := residual_deviations_bound z.side hb hs' ⟨hb,le_rfl⟩ + rw [← hr] at hD + have hparent : |parentBenchmark z.side z.ratio-1| ≤ 4*weight z.side z.ratio := by + linarith [abs_nonneg (benchmark z.side (z.gap/2)-1),abs_nonneg (benchmark z.side.flip (z.ratio-1)-1)] + have hboundary : |benchmark z.side (z.gap/2)-1| ≤ 4*weight z.side z.ratio := by + linarith [abs_nonneg (parentBenchmark z.side z.ratio-1),abs_nonneg (benchmark z.side.flip (z.ratio-1)-1)] + have hscale : ∀ t : ℝ,2 ≤ t → ∀ closed : Bool, + |referenceProduct w t closed-normalization w/t| ≤ (C/2)*primeError c w 2 := by + intro t ht closed + exact (hP t ht closed).trans (divided_error_bound hc hC hw ht) + constructor + · unfold boundaryProductError + rw [abs_mul] + have h := mul_le_mul (hscale 2 le_rfl true) hboundary (abs_nonneg _) (by positivity) + convert! h using 1 + ring + constructor + · unfold parentProductError + rw [abs_mul] + have h := mul_le_mul (hscale z.cutoff hb z.closed) hparent (abs_nonneg _) (by positivity) + convert! h using 1 + ring + · unfold primeProductError + apply (Finset.abs_sum_le_sum_abs _ _).trans + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + obtain ⟨_hprime,hxp,hcap⟩ := (highPrimes_membership hw z.cutoff z.closed p).mp hp + have hxb : primeExponent w p ≤ z.cutoff := by + cases hcl : z.closed with + | false => have h : primeExponent w p < z.cutoff := by simpa [capGuard,hcl] using hcap + exact h.le + | true => simpa [capGuard,hcl] using hcap + have hchild0 := residual_deviations_bound z.side hb hs' ⟨hxp.le,hxb⟩ + rw [← hr] at hchild0 + have hchild : |benchmark z.side.flip (childRatio w z.gap p)-1| ≤ 4*weight z.side z.ratio := by + unfold childRatio + linarith [abs_nonneg (parentBenchmark z.side z.ratio-1),abs_nonneg (benchmark z.side (z.gap/2)-1)] + rw [abs_mul,abs_mul,abs_of_nonneg (inv_nonneg.mpr (Nat.cast_nonneg p))] + have hleft := mul_le_mul_of_nonneg_left (hscale (primeExponent w p) hxp.le false) + (inv_nonneg.mpr (Nat.cast_nonneg p)) + have h := mul_le_mul hleft hchild (abs_nonneg _) (by positivity) + convert! h using 1 + ring + +end NumberTheoryLean.ReferenceProductErrorBounds + + + +namespace NumberTheoryLean.GlobalResidualScale + +open ReferenceProductErrorBounds + +noncomputable def powerDecay (M B : ℝ) : ℝ := Real.exp (-M*Real.log B) + +theorem powerDecay_pos (M B : ℝ) : 0 < powerDecay M B := Real.exp_pos _ + +theorem primeError_le_one {c : ℝ} (hc : 0 ≤ c) (w t : ℝ) : primeError c w t ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc) (Real.sqrt_nonneg _)) + +theorem powerDecay_nat {B : ℝ} (hB : 0 < B) (n : ℕ) : powerDecay n B=(B^n)⁻¹ := by + rw [powerDecay,neg_mul,Real.exp_neg,Real.exp_nat_mul,Real.exp_log hB] + +theorem linear_log_cutoff_saving {c d M : ℝ} (hc : 0 < c) (hd : 0 < d) (hM : 0 < M) : + ∃ K : ℝ,1 ≤ K ∧ ∀ B w : ℝ,1 ≤ B → 1 < w → Real.log B ≤ d*Real.log w → + primeError c w (K*Real.log B) ≤ powerDecay M B := by + let q := M/c + let K := 1+d*q^2 + have hq : 0 < q := div_pos hM hc + have hK : 1 ≤ K := by dsimp [K]; exact le_add_of_nonneg_right (mul_nonneg hd.le (sq_nonneg q)) + have hKpos : 0 < K := zero_lt_one.trans_le hK + refine ⟨K,hK,?_⟩ + intro B w hB hw hcomp + have hL : 0 ≤ Real.log B := Real.log_nonneg hB + have hW : 0 ≤ Real.log w := (Real.log_pos hw).le + have hm := mul_le_mul_of_nonneg_left hcomp (mul_nonneg (sq_nonneg q) hL) + have hsquare : (q*Real.log B)^2 ≤ (K*Real.log B)*Real.log w := by + dsimp only [K] + nlinarith only [hm,mul_nonneg hL hW] + have harg : 0 ≤ (K*Real.log B)*Real.log w := by positivity + have hsqrt : q*Real.log B ≤ Real.sqrt ((K*Real.log B)*Real.log w) := by + nlinarith only [hsquare,Real.sq_sqrt harg,Real.sqrt_nonneg ((K*Real.log B)*Real.log w),mul_nonneg hq.le hL] + have hcq : c*q=M := by dsimp [q]; field_simp + have hpay : M*Real.log B ≤ c*Real.sqrt ((K*Real.log B)*Real.log w) := by + calc + _ = c*(q*Real.log B) := by rw [← mul_assoc,hcq] + _ ≤ _ := mul_le_mul_of_nonneg_left hsqrt hc.le + change Real.exp (-c*Real.sqrt ((K*Real.log B)*Real.log w)) ≤ Real.exp (-M*Real.log B) + exact Real.exp_le_exp.mpr (by linarith) + +theorem rebased_ratio_separation {K M L s b : ℝ} (hK : 1 ≤ K) (hM : 0 ≤ M) + (hLK : K ≤ L) (hLM : 4*M+10 ≤ L) (hs : (1/2:ℝ) ≤ s) (hb : L^4 < b) : + s+4 ≤ (b*s)/(K*L) ∧ 2*M*L ≤ (b*s)/(K*L)-s := by + have hL : 1 ≤ L := hK.trans hLK + have hK0 : 0 < K := by linarith + have hL0 : 0 < L := by linarith + have ha : 0 < K*L := mul_pos hK0 hL0 + have hcoef : (K*L)*L^2 ≤ b := by + have hh := mul_le_mul_of_nonneg_right hLK (pow_nonneg hL0.le 3) + nlinarith + have hratio : L^2 ≤ b/(K*L) := (le_div_iff₀ ha).mpr (by nlinarith) + have ht : s*L^2 ≤ (b*s)/(K*L) := by + have hh := mul_le_mul_of_nonneg_left hratio (show 0 ≤ s by linarith) + convert! hh using 1 + ring + have hdiff : (L^2-1)/2 ≤ (b*s)/(K*L)-s := by + have hh := mul_le_mul_of_nonneg_right hs (show 0 ≤ L^2-1 by nlinarith) + nlinarith + have hpoly : 2*M*L ≤ (L^2-1)/2 ∧ 4 ≤ (L^2-1)/2 := by + have hh := mul_nonneg hL0.le (show 0 ≤ L-(4*M+10) by linarith) + constructor <;> nlinarith + exact ⟨by linarith [hpoly.2],hpoly.1.trans hdiff⟩ + +theorem gap_over_linear_cutoff {K L r b : ℝ} (hK : 0 < K) (hL : 0 ≤ L) (hb : 0 < b) + (hbK : b ≤ K*L) (hr : L^2/2 ≤ r) : L/(2*K) ≤ r/b := by + apply (le_div_iff₀ hb).mpr + have hm := mul_le_mul_of_nonneg_left hbK (div_nonneg hL (by positivity : 0 ≤ 2*K)) + have he : L/(2*K)*(K*L)=L^2/2 := by field_simp + rw [he] at hm + exact hm.trans hr + +end NumberTheoryLean.GlobalResidualScale + + + +namespace NumberTheoryLean.ReferenceLogScale + +open _root_.Filter +open scoped Topology +open ReferenceProductErrorBounds ExponentialMesh + +theorem primeError_two_eq (c w : ℝ) : + primeError c w 2=Real.exp (-(c*Real.sqrt 2)*Real.sqrt (Real.log w)) := by + unfold primeError + rw [Real.sqrt_mul (by norm_num : (0:ℝ) ≤ 2)] + congr 1 + ring + +theorem log_power_primeError_tendsto (C : ℝ) (n : ℕ) {c : ℝ} (hc : 0 < c) : + Tendsto (fun w : ℝ => C*(Real.log w)^n*primeError c w 2) atTop (𝓝 0) := by + have h := log_power_exp_tendsto C n (mul_pos hc (Real.sqrt_pos.mpr (by norm_num : (0:ℝ)<2))) + simpa only [primeError_two_eq] using h + +theorem primeError_two_tendsto {c : ℝ} (hc : 0 < c) : + Tendsto (fun w : ℝ => primeError c w 2) atTop (𝓝 0) := by + simpa only [pow_zero,one_mul] using log_power_primeError_tendsto 1 0 hc + +end NumberTheoryLean.ReferenceLogScale + + + +namespace NumberTheoryLean.ReferenceResidualQuadrature + +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry +open ReferenceMertens ReferenceResidualErrors ReferenceProductErrorBounds ReferenceHighIntervals +open ReferenceWeightedQuadrature + +theorem actual_quadrature_error : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ z : Node,Valid z.side z.ratio → Consistent z → 2 ≤ z.cutoff → + |quadratureError w z| ≤ (C*weight z.side z.ratio/2)*primeError c w 2 := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := source_weighted_quadrature + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw z hs hz hb + have hw1 : 1 < w := hw₀.trans_le hw + have hr := ratio_eq_gap_div_cutoff hs hz (by linarith) + have hs' : Valid z.side (z.gap/z.cutoff) := by rwa [← hr] + have hh := h w hw 2 z.cutoff z.cutoff z.gap le_rfl hb le_rfl z.side hs' + (highInterval z.cutoff z.closed) (highInterval_orderConnected _ _) (highInterval_subset _ _) + rw [← hr] at hh + unfold quadratureError + rw [highPrime_sum hw1] + simpa only [childRatio,primeError] using hh + +end NumberTheoryLean.ReferenceResidualQuadrature + + + +namespace NumberTheoryLean.WeightPowerBounds + +open FinitePathGeometry WeightDistantDecay GlobalResidualScale + +theorem relative_weight_power : ∃ C : ℝ,0 < C ∧ ∀ M B : ℝ,∀ i j : Side,∀ s t : ℝ, + Valid i s → s+4 ≤ t → 2*M*Real.log B ≤ t-s → + weight j t ≤ C*weight i s*powerDecay M B := by + obtain ⟨C,hC,h⟩ := relative_weight_decay + refine ⟨C,hC,?_⟩ + intro M B i j s t hs hst hgap + apply (h i j s t hs hst).trans + apply mul_le_mul_of_nonneg_left _ (mul_nonneg hC.le (weight_pos hs).le) + change Real.exp (-(t-s)/2) ≤ Real.exp (-M*Real.log B) + exact Real.exp_le_exp.mpr (by linarith) + +theorem weight_power_at_ratio {K M : ℝ} (hK : 0 < K) (hM : 0 < M) : + ∃ C T : ℝ,0 < C ∧ 0 < T ∧ ∀ B : ℝ,T ≤ Real.log B → ∀ i : Side,∀ t : ℝ, + Real.log B/(2*K) ≤ t → weight i t ≤ C*powerDecay M B := by + obtain ⟨C,T,hC,hT,h⟩ := weight_exponential_majorant (2*K*M) + refine ⟨C,2*K*T,hC,mul_pos (by positivity) (by linarith),?_⟩ + intro B hB i t ht + have hTt : T ≤ t := by + have hh := (div_le_iff₀ (by positivity : 0 < 2*K)).mp ht + nlinarith + have hpay : M*Real.log B ≤ (2*K*M)*t := by + have hh := mul_le_mul_of_nonneg_left ((div_le_iff₀ (by positivity : 0 < 2*K)).mp ht) hM.le + nlinarith only [hh] + apply (h i t hTt).trans + apply mul_le_mul_of_nonneg_left _ hC.le + change Real.exp (-(2*K*M)*t) ≤ Real.exp (-M*Real.log B) + exact Real.exp_le_exp.mpr (by linarith) + +end NumberTheoryLean.WeightPowerBounds + + + +namespace NumberTheoryLean.ReferenceProductLower + +open _root_.Filter +open scoped Topology +open ReferenceProductsBasics ReferenceMertens ReferenceProductErrors ReferenceProductErrorBounds ReferenceLogScale + +theorem reference_product_lower : ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → + ∀ b : ℝ,2 ≤ b → ∀ closed : Bool,1/(4*b) ≤ referenceProduct w b closed := by + obtain ⟨c,C,wP,hc,hC,hwP,hP⟩ := reference_product_strong + have hdec : Tendsto (fun w => C*primeError c w 2) atTop (𝓝 0) := by + simpa only [mul_zero] using (primeError_two_tendsto hc).const_mul C + obtain ⟨wE,hwE⟩ := eventually_atTop.mp (hdec.eventually (eventually_le_nhds (by norm_num : (0:ℝ)<1/2))) + obtain ⟨wN,hwN⟩ := eventually_atTop.mp normalization_eventually_bounded + refine ⟨max wP (max wE wN),hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw b hb closed + have hwp : wP ≤ w := (le_max_left _ _).trans hw + have hwe : wE ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwn : wN ≤ w := ((le_max_right _ _).trans (le_max_right _ _)).trans hw + have hw1 : 1 < w := hwP.trans_le hwp + have hb0 : 0 < b := by linarith + have hD : 0 < normalization w/b := div_pos (normalization_pos hw1) hb0 + have herr : |referenceProduct w b closed/(normalization w/b)-1| ≤ 1/2 := by + apply (hP w hwp b hb closed).trans + apply le_trans (mul_le_mul_of_nonneg_left (primeError_antitone hc.le hw1 hb) hC.le) + exact hwE w hwe + have hratio : (1/2:ℝ) ≤ referenceProduct w b closed/(normalization w/b) := by + have hlow := (abs_le.mp herr).1 + linarith + have hm := (le_div_iff₀ hD).mp hratio + have hn := (hwN w hwn).1 + calc + 1/(4*b) = ((1/2:ℝ)/b)/2 := by ring + _ ≤ (normalization w/b)/2 := + div_le_div_of_nonneg_right (div_le_div_of_nonneg_right hn hb0.le) (by norm_num) + _ ≤ referenceProduct w b closed := by linarith + +end NumberTheoryLean.ReferenceProductLower + + + +namespace NumberTheoryLean.ReferenceResidualPointwise + +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualBoundaryDomain +open ReferenceSourcePrimeSets ReferenceMertens ReferenceProductErrors ReferenceLocalResidual +open ReferenceResidualErrors ReferenceProductErrorBounds ReferenceResidualQuadrature ReferenceHighIntervals + +theorem residual_abs_triangle (w : ℝ) {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) + (hb : 2 ≤ z.cutoff) (hdom : BoundaryDomain z.side z.gap) : + |sourceResidual w z| ≤ |boundaryProductError w z|+|parentProductError w z|+ + |primeProductError w z|+|normalization w*quadratureError w z| := by + rw [residual_error_identity w hs hz hb hdom] + have h1 := abs_sub (boundaryProductError w z-parentProductError w z-primeProductError w z) + (normalization w*quadratureError w z) + have h2 := abs_sub (boundaryProductError w z-parentProductError w z) (primeProductError w z) + have h3 := abs_sub (boundaryProductError w z) (parentProductError w z) + linarith + +theorem source_residual_pointwise : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ z : Node,Valid z.side z.ratio → Consistent z → 2 ≤ z.cutoff → + BoundaryDomain z.side z.gap → + |sourceResidual w z| ≤ C*weight z.side z.ratio*(1+Real.log z.cutoff)*primeError c w 2 := by + obtain ⟨cP,CP,wP,hcP,hCP,hwP,hP⟩ := reference_product_absolute + obtain ⟨cQ,CQ,wQ,hcQ,hCQ,hwQ,hQ⟩ := actual_quadrature_error + obtain ⟨CH,wH,hCH,_hwH,hH⟩ := highPrime_mass_bound + let c := min cP cQ + let C := 4*CP+2*CP*CH+CQ + have hc : 0 < c := lt_min hcP hcQ + refine ⟨c,C,max wP (max wQ wH),hc,by dsimp [C]; positivity, + hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw z hs hz hb hdom + have hwp : wP ≤ w := (le_max_left _ _).trans hw + have hwq : wQ ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwh : wH ≤ w := ((le_max_right _ _).trans (le_max_right _ _)).trans hw + have hw1 : 1 < w := hwP.trans_le hwp + obtain ⟨_hNlo,hNhi,hProd⟩ := hP w hwp + have hP' : ∀ t : ℝ,2 ≤ t → ∀ closed : Bool, + |referenceProduct w t closed-normalization w/t| ≤ (CP/t)*primeError c w t := by + intro t ht closed + have he := exp_error_mono_rate (t:=t*Real.log w) (min_le_left cP cQ) + exact (hProd t ht closed).trans (mul_le_mul_of_nonneg_left he (div_nonneg hCP.le (by linarith))) + obtain ⟨hB,hPar,hPrime⟩ := finite_product_error_bounds hc.le hCP.le hw1 hP' hs hz hb + have hφ := weight_pos hs + have hQ' : |quadratureError w z| ≤ (CQ*weight z.side z.ratio/2)*primeError c w 2 := by + have he := exp_error_mono_rate (t:=2*Real.log w) (min_le_right cP cQ) + exact (hQ w hwq z hs hz hb).trans (mul_le_mul_of_nonneg_left he (by positivity)) + have hN : |normalization w| ≤ 2 := by rw [abs_of_pos (normalization_pos hw1)]; exact hNhi + have hNQ : |normalization w*quadratureError w z| ≤ CQ*weight z.side z.ratio*primeError c w 2 := by + rw [abs_mul] + have hh := mul_le_mul hN hQ' (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 2) + convert! hh using 1 + ring + have hMass := hH w hwh z.cutoff hb z.closed + have hE := primeError_pos c w 2 + have hPrime' : |primeProductError w z| ≤ + (2*CP*weight z.side z.ratio*primeError c w 2)*(CH*(1+Real.log z.cutoff)) := + hPrime.trans (mul_le_mul_of_nonneg_left hMass (by positivity)) + have htri := residual_abs_triangle w hs hz hb hdom + have hL : 1 ≤ 1+Real.log z.cutoff := by have hh := Real.log_nonneg (show 1 ≤ z.cutoff by linarith); linarith + have hpay : (4*CP+CQ)*weight z.side z.ratio*primeError c w 2 ≤ + (4*CP+CQ)*weight z.side z.ratio*primeError c w 2*(1+Real.log z.cutoff) := + le_mul_of_one_le_right (by positivity) hL + calc + _ ≤ (4*CP+CQ)*weight z.side z.ratio*primeError c w 2+ + (2*CP*weight z.side z.ratio*primeError c w 2)*(CH*(1+Real.log z.cutoff)) := by + nlinarith only [htri,hB,hPar,hPrime',hNQ] + _ ≤ (4*CP+CQ)*weight z.side z.ratio*primeError c w 2*(1+Real.log z.cutoff)+ + (2*CP*weight z.side z.ratio*primeError c w 2)*(CH*(1+Real.log z.cutoff)) := + add_le_add_left hpay _ + _ = _ := by dsimp [C]; ring + +end NumberTheoryLean.ReferenceResidualPointwise + + + +namespace NumberTheoryLean.ReferenceResidualSum + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry ActualPrimeHigh ActualBoundaryDomain +open SourceNodeCoordinates ReferenceSourceDecomposition ReferenceResidualPointwise ReferenceProductErrorBounds +open ReferenceLocalResidual TwoStepDensityBounds +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +noncomputable def residualAbsoluteSum (w : ℝ) (start : Node) : ℝ := + ∑ ps ∈ uncappedPrefixes w 2 start,prefixWeight ps*|sourceResidual w (terminal w start ps)| + +theorem uniform_weight_bound : ∃ W : ℝ,0 < W ∧ ∀ i s,Valid i s → weight i s ≤ W := by + let W := max (weight .even (baseRatio .even)) (weight .odd (baseRatio .odd)) + refine ⟨W,(weight_pos (baseRatio_valid .even)).trans_le (le_max_left _ _),?_⟩ + intro i s hs + have h := weight_antitone (baseRatio_valid i) hs (baseRatio_le hs) + cases i with + | even => exact h.trans (le_max_left _ _) + | odd => exact h.trans (le_max_right _ _) + +theorem uncapped_cutoff_le {w : ℝ} {z : Node} {ps : List ℕ} (hp : uncappedAllowed w 2 z ps) : + (terminal w z ps).cutoff ≤ z.cutoff := by + induction ps generalizing z with + | nil => exact le_rfl + | cons p ps ih => + obtain ⟨hc,ht⟩ := hp + have hcap := (Finset.mem_filter.mp hc).2.2.1 + have hx : ErdosPrimeInputs.HarmonicPrimeMeasure.primeExponent w p ≤ z.cutoff := by + cases hcl : z.closed with + | false => have h : ErdosPrimeInputs.HarmonicPrimeMeasure.primeExponent w p < z.cutoff := by simpa [capGuard,hcl] using hcap + exact h.le + | true => simpa [capGuard,hcl] using hcap + exact (ih (z:=step w z p) ht).trans hx + +theorem summed_source_residual_bound : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ B : ℝ,4 ≤ B → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + residualAbsoluteSum w start ≤ C*B*(1+Real.log B)*primeError c w 2 := by + obtain ⟨c,CP,wP,hc,hCP,hwP,hP⟩ := source_residual_pointwise + obtain ⟨M,wM,hM,_hwM,hMass⟩ := total_prime_prefix_mass + obtain ⟨W,hW,hWeight⟩ := uniform_weight_bound + refine ⟨c,CP*W*M,max wP wM,hc,by positivity,hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw B hB start hi h199 h23 hcons hcut + have hwp : wP ≤ w := (le_max_left _ _).trans hw + have hwm : wM ≤ w := (le_max_right _ _).trans hw + have hBpos : 0 < B := by linarith + obtain ⟨hs,hr,_hgap,_hsize⟩ := source_node_bounds hBpos start hi h199 h23 hcons hcut + have hcap0 : 2 < start.cutoff := by rw [hcut]; linarith + have hE := primeError_pos c w 2 + have hL : 0 ≤ 1+Real.log B := by have h := Real.log_nonneg (show 1 ≤ B by linarith); linarith + have hpoint : ∀ ps ∈ uncappedPrefixes w 2 start, + |sourceResidual w (terminal w start ps)| ≤ CP*W*(1+Real.log B)*primeError c w 2 := by + intro ps hp + have hpA : uncappedAllowed w 2 start ps := (Finset.mem_filter.mp hp).2 + obtain ⟨U,_hU,hpU⟩ := (uncapped_iff_exists_ceiling w 2 start ps).mp hpA + have hvs := terminal_valid hs hpU + have hcs := terminal_consistent (by norm_num : (0:ℝ) ≤ 2) hr hs hcons hpU + have hdom := source_boundary_domain hB le_rfl start hi h199 h23 hcons hcut hpA + have hlow := uncapped_cutoff_gt_two hcap0 hpA + have hupp : (terminal w start ps).cutoff ≤ B := by simpa only [hcut] using uncapped_cutoff_le hpA + have hwt := hWeight _ _ hvs + have hlog := Real.log_le_log (by linarith : 0 < (terminal w start ps).cutoff) hupp + have hLt : 0 ≤ 1+Real.log (terminal w start ps).cutoff := by + have hh := Real.log_nonneg (show 1 ≤ (terminal w start ps).cutoff by linarith) + linarith + calc + _ ≤ CP*weight (terminal w start ps).side (terminal w start ps).ratio* + (1+Real.log (terminal w start ps).cutoff)*primeError c w 2 := hP w hwp _ hvs hcs hlow.le hdom + _ ≤ _ := by gcongr + have htotal : (∑ ps ∈ uncappedPrefixes w 2 start,prefixWeight ps) ≤ M*B := by + calc + _ ≤ ∑ ps ∈ decreasingPrefixes (primesBetween (w^(2:ℝ)) (w^start.cutoff)),prefixWeight ps := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun ps _ _ => prefixWeight_nonneg ps) + _ ≤ M*B := by + rw [hcut] + have hh := hMass w hwm 2 B (by norm_num) (by linarith) + nlinarith [mul_pos hM hBpos] + calc + _ ≤ ∑ ps ∈ uncappedPrefixes w 2 start,prefixWeight ps*(CP*W*(1+Real.log B)*primeError c w 2) := + Finset.sum_le_sum (fun ps hp => mul_le_mul_of_nonneg_left (hpoint ps hp) (prefixWeight_nonneg ps)) + _ = (∑ ps ∈ uncappedPrefixes w 2 start,prefixWeight ps)*(CP*W*(1+Real.log B)*primeError c w 2) := + (Finset.sum_mul _ _ _).symm + _ ≤ (M*B)*(CP*W*(1+Real.log B)*primeError c w 2) := mul_le_mul_of_nonneg_right htotal (by positivity) + _ = _ := by ring + +theorem signed_residual_le_absolute (w : ℝ) (start : Node) : + |residualCorrection w start| ≤ residualAbsoluteSum w start := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro ps _hp + simp only [abs_mul,abs_of_nonneg (prefixWeight_nonneg ps),abs_pow,abs_neg,abs_one,one_pow,one_mul] + exact le_rfl + +end NumberTheoryLean.ReferenceResidualSum + + + +namespace NumberTheoryLean.ReferenceRelativeError + +open FinitePathGeometry PrimeHistories PrimeBinMembership SourceNodeCoordinates +open ReferenceMertens ReferenceProductsBasics ReferenceProductLower ReferenceDifferentiation +open ReferenceLocalResidual ReferenceSourceDecomposition ReferenceResidualSum ReferenceProductErrorBounds +open UniformBoundaryCorrection + +theorem source_relative_reference_error (d : ℝ) (hd : 0 < d) : + ∃ c A C B₀ w₀ : ℝ,0 < c ∧ 0 < A ∧ 0 < C ∧ 0 < B₀ ∧ 1 < w₀ ∧ + ∀ w B : ℝ,w₀ ≤ w → B₀ ≤ B → Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |sourceReference w start/referenceProduct w B start.closed-parentBenchmark .even start.ratio| ≤ + A/B+C*B^2*(1+Real.log B)*primeError c w 2 := by + obtain ⟨AB,BB,wB,hAB,hBB,hwB,hBoundary⟩ := uniform_boundary_correction_div 2 d le_rfl hd + obtain ⟨c,CR,wR,hc,hCR,_hwR,hResidual⟩ := summed_source_residual_bound + obtain ⟨wV,_hwV,hV⟩ := reference_product_lower + refine ⟨c,4*AB,4*CR,max BB 4,max wB (max wR wV),hc,by positivity,by positivity, + hBB.trans_le (le_max_left _ _),hwB.trans_le (le_max_left _ _),?_⟩ + intro w B hw hB hcomp start hi h199 h23 hcons hcut + have hwB' : wB ≤ w := (le_max_left _ _).trans hw + have hwR' : wR ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwV' : wV ≤ w := ((le_max_right _ _).trans (le_max_right _ _)).trans hw + have hBB' : BB ≤ B := (le_max_left _ _).trans hB + have hB4 : 4 ≤ B := (le_max_right _ _).trans hB + have hBpos : 0 < B := by linarith + have hw1 : 1 < w := hwB.trans_le hwB' + obtain ⟨hs,hr,_hsize1,_hsize2⟩ := source_node_bounds hBpos start hi h199 h23 hcons hcut + have hbnd := hBoundary B w hBB' hwB' hcomp start hi h199 h23 hcons hcut + have hres := (signed_residual_le_absolute w start).trans (hResidual w hwR' B hB4 start hi h199 h23 hcons hcut) + have hdecomp := actual_reference_decomposition hw1 hs hr hcons (by rw [hcut]; linarith) + have hab : |sourceReference w start-nodeBenchmark w start| ≤ + AB/B^2+CR*B*(1+Real.log B)*primeError c w 2 := by + rw [hdecomp] + exact (abs_add_le _ _).trans (add_le_add hbnd hres) + have hlow := hV w hwV' B (by linarith) start.closed + have hVpos : 0 < referenceProduct w B start.closed := availableProduct_pos _ _ _ + have heq : sourceReference w start/referenceProduct w B start.closed-parentBenchmark .even start.ratio= + (sourceReference w start-nodeBenchmark w start)/referenceProduct w B start.closed := by + unfold nodeBenchmark + rw [hi,hcut] + field_simp + have hL : 0 ≤ 1+Real.log B := by have h := Real.log_nonneg (show 1 ≤ B by linarith); linarith + have hE := primeError_pos c w 2 + rw [heq,abs_div,abs_of_pos hVpos] + calc + _ ≤ (AB/B^2+CR*B*(1+Real.log B)*primeError c w 2)/referenceProduct w B start.closed := + div_le_div_of_nonneg_right hab hVpos.le + _ ≤ (AB/B^2+CR*B*(1+Real.log B)*primeError c w 2)/(1/(4*B)) := + div_le_div_of_nonneg_left (by positivity) (by positivity) hlow + _ = _ := by field_simp + +end NumberTheoryLean.ReferenceRelativeError + + + +namespace NumberTheoryLean.MovingLocalReference + +open _root_.Filter Asymptotics +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceMertens ReferenceDifferentiation +open ReferenceSourceDecomposition ReferenceProductErrorBounds ReferenceLogScale ReferenceRelativeError + +theorem log_square_le_base {K : ℝ} (hK : 0 ≤ K) : + ∀ᶠ w : ℝ in atTop,K*(Real.log w)^2 ≤ w := by + have h : (fun w : ℝ => K*(Real.log w)^2)=o[atTop](fun w => w) := by + simpa only [Real.rpow_ofNat,Real.rpow_one] using + (isLittleO_log_rpow_rpow_atTop (2:ℝ) (s:=1) (by norm_num)).const_mul_left K + filter_upwards [h.bound (by norm_num : (0:ℝ)<1),eventually_ge_atTop (0:ℝ)] with w hw hw0 + simpa only [Real.norm_eq_abs,abs_of_nonneg (mul_nonneg hK (sq_nonneg _)),abs_of_nonneg hw0,one_mul] using hw + +theorem moving_local_reference (K ε : ℝ) (hK : 0 < K) (hε : 0 < ε) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ w B : ℝ,w₀ ≤ w → B₀ ≤ B → + B ≤ K*(Real.log w)^2 → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + |sourceReference w start/referenceProduct w B start.closed-parentBenchmark .even start.ratio| ≤ ε := by + obtain ⟨c,A,C,BR,wR,hc,hA,hC,hBR,hwR,hR⟩ := source_relative_reference_error 1 (by norm_num) + obtain ⟨wS,hwS⟩ := eventually_atTop.mp (log_square_le_base hK.le) + have hdec := log_power_primeError_tendsto (2*C*K^2) 5 hc + obtain ⟨wE,hwE⟩ := eventually_atTop.mp + (hdec.eventually (eventually_le_nhds (show (0:ℝ)<ε/2 by linarith))) + let B₀ := max BR (2*A/ε) + let w₀ := max wR (max wS (max wE (Real.exp 1))) + refine ⟨B₀,w₀,hBR.trans_le (le_max_left _ _),hwR.trans_le (le_max_left _ _),?_⟩ + intro w B hw hB hscale start hi h199 h23 hcons hcut + have hwR' : wR ≤ w := (le_max_left _ _).trans hw + have hwS' : wS ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwE' : wE ≤ w := (((le_max_left _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hw + have hwExp : Real.exp 1 ≤ w := (((le_max_right _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hw + have hBR' : BR ≤ B := (le_max_left _ _).trans hB + have hBl : 2*A/ε ≤ B := (le_max_right _ _).trans hB + have hBpos : 0 < B := hBR.trans_le hBR' + have hlogw : 1 ≤ Real.log w := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 1) hwExp + have hBw : B ≤ w := hscale.trans (hwS w hwS') + have hlogs : Real.log B ≤ Real.log w := Real.log_le_log hBpos hBw + have hcomp : Real.log B ≤ (1:ℝ)*Real.log w := by simpa only [one_mul] using hlogs + have herr := hR w B hwR' hBR' hcomp start hi h199 h23 hcons hcut + have hsmall : A/B ≤ ε/2 := by + apply (div_le_iff₀ hBpos).mpr + have hh := (div_le_iff₀ hε).mp hBl + nlinarith + have hBsq : B^2 ≤ K^2*(Real.log w)^4 := by nlinarith [mul_self_le_mul_self hBpos.le hscale] + have hL : 1+Real.log B ≤ 2*Real.log w := by linarith + have hLogPos : 0 ≤ Real.log w := by linarith + have hE := primeError_pos c w 2 + have hpoly : C*B^2*(1+Real.log B)*primeError c w 2 ≤ 2*C*K^2*(Real.log w)^5*primeError c w 2 := by + have hh : B^2*(1+Real.log B) ≤ (K^2*(Real.log w)^4)*(2*Real.log w) := by + calc + _ ≤ B^2*(2*Real.log w) := mul_le_mul_of_nonneg_left hL (sq_nonneg B) + _ ≤ _ := mul_le_mul_of_nonneg_right hBsq (by positivity) + have hm := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hh hC.le) hE.le + convert! hm using 1 <;> ring + have htail := hwE w hwE' + linarith + +end NumberTheoryLean.MovingLocalReference + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/NestedDegreeBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NestedDegreeBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..895a380c020889665161615602b3fb55abd7dd42 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NestedDegreeBounds.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.NestedCoordinates + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosCriticalGeometry + +variable (R : Type*) [CommSemiring R] + +theorem unique_degree_le_totalDegree (P : MvPolynomial (Fin 1) R) : + (MvPolynomial.uniqueAlgEquiv R (Fin 1) P).natDegree ≤ P.totalDegree := by + classical + apply Polynomial.natDegree_le_iff_coeff_eq_zero.mpr + intro k hk + rw [MvPolynomial.coeff_uniqueAlgEquiv] + by_contra hc + have h := MvPolynomial.le_totalDegree (MvPolynomial.mem_support_iff.mpr hc) + simp only [Finsupp.sum_single_index] at h + exact (not_le_of_gt hk) h + +theorem nestedX_degree_le (Q : MV R) : (nestedX R Q).natDegree ≤ Q.totalDegree := by + change (Polynomial.map (MvPolynomial.uniqueAlgEquiv R (Fin 1)).toRingHom + (MvPolynomial.finSuccEquiv R 1 Q)).natDegree ≤ _ + exact Polynomial.natDegree_map_le.trans + ((MvPolynomial.natDegree_finSuccEquiv Q).le.trans (MvPolynomial.degreeOf_le_totalDegree Q 0)) + +theorem nestedX_coefficient_degree_le (Q : MV R) (k : ℕ) : + ((nestedX R Q).coeff k).natDegree ≤ Q.totalDegree := by + change ((Polynomial.map (MvPolynomial.uniqueAlgEquiv R (Fin 1)).toRingHom + (MvPolynomial.finSuccEquiv R 1 Q)).coeff k).natDegree ≤ _ + rw [Polynomial.coeff_map] + apply (unique_degree_le_totalDegree R _).trans + by_cases h : (MvPolynomial.finSuccEquiv R 1 Q).coeff k = 0 + · simp [h] + · have hb := MvPolynomial.totalDegree_coeff_finSuccEquiv_add_le Q k h + omega + +theorem nestedY_degree_le (Q : MV R) : (nestedY R Q).natDegree ≤ Q.totalDegree := by + have h := nestedX_degree_le R (MvPolynomial.renameEquiv R (Equiv.swap (0 : Fin 2) 1) Q) + simpa only [MvPolynomial.totalDegree_renameEquiv, nestedY, AlgEquiv.trans_apply] using h + +theorem nestedY_coefficient_degree_le (Q : MV R) (k : ℕ) : + ((nestedY R Q).coeff k).natDegree ≤ Q.totalDegree := by + have h := nestedX_coefficient_degree_le R (MvPolynomial.renameEquiv R (Equiv.swap (0 : Fin 2) 1) Q) k + simpa only [MvPolynomial.totalDegree_renameEquiv, nestedY, AlgEquiv.trans_apply] using h + +theorem partial_totalDegree_le (Q : MV R) (i : Fin 2) : + (MvPolynomial.pderiv i Q).totalDegree ≤ Q.totalDegree-1 := by + classical + apply Finset.sup_le + intro m hm + have hc := MvPolynomial.mem_support_iff.mp hm + rw [MvPolynomial.coeff_pderiv] at hc + have hQ := MvPolynomial.mem_support_iff.mpr (left_ne_zero_of_mul hc) + have hd := MvPolynomial.le_totalDegree hQ + rw [Finsupp.sum_add_index] at hd + · simp only [Finsupp.sum_single_index] at hd + omega + · simp + · intros + rfl + +end ErdosCriticalGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/NestedPartials.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NestedPartials.lean new file mode 100644 index 0000000000000000000000000000000000000000..ae781cc2017018487f39d326959e0144184ec97a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NestedPartials.lean @@ -0,0 +1,43 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.NestedCoordinates + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosCriticalGeometry + +variable (R : Type*) [CommSemiring R] + +theorem nestedX_partial_zero (Q : MV R) : + nestedX R (MvPolynomial.pderiv 0 Q) = (nestedX R Q).derivative := by + induction Q using MvPolynomial.induction_on with + | C c => simp + | add P Q hP hQ => simp [map_add, hP, hQ] + | mul_X P i hP => + fin_cases i + · simp [hP, Polynomial.derivative_mul] + ring + · simp [hP, Polynomial.derivative_mul] + ring + +theorem nestedY_partial_one (Q : MV R) : + nestedY R (MvPolynomial.pderiv 1 Q) = (nestedY R Q).derivative := by + induction Q using MvPolynomial.induction_on with + | C c => simp + | add P Q hP hQ => simp [map_add, hP, hQ] + | mul_X P i hP => + fin_cases i + · simp [hP, Polynomial.derivative_mul] + ring + · simp [hP, Polynomial.derivative_mul] + ring + +end ErdosCriticalGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonisolatedSelectedOccurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonisolatedSelectedOccurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..67dba68c0f93e1a47150e9006149d1a7d4f65f3d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonisolatedSelectedOccurrence.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.Jacobsthal.Paths.GeometricRegularWords + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.NonisolatedSelectedOccurrence +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain FiniteHistoryTransport +open ActualSuccessfulHistories ActualCoupledHistories CompactPrefixOccurrence SourceSelectedCompactOccupation +open NonisolatedWordOccurrence GoodCrossingVisit CrossingPrimeBin +open CompletedArrivalOccurrence PersistentFailureFlag CanonicalCoupledHistories + +variable {w ell S : ℝ} {start : Node} +variable (hwn : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +include hwn hell hS0 hS hr hsS in +theorem selected_nonisolated_probability {top xi B theta T mesh : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hB : 0 < B) (htheta : 0 < theta) (htheta1 : theta ≤ 1/2) (hT : 1 ≤ T) + (h199 : 199/100 ≤ start.ratio) (hc : PrimeBinMembership.Consistent start) (hcut : start.cutoff=B) + (hcap : w^start.cutoff=top) (hm : 0 < mesh) (hmesh : mesh ≤ 1) (N : ℕ) + (hexp : Real.exp (4*(N:ℝ)*mesh) ≤ 11/10) + (hwidth : xi/Real.log w ≤ isolatedAlpha theta (T+1)*B) (E : Set (List ℕ)) + (hE : ∀ p : History w ell S start,p.primes ∈ E → p.node.gap ≤ theta*B ∧ + noIsolatedWord hw htop hxi B (isolatedAlpha theta (T+1)) (4*theta) p.primes) : + fullSourceLaw w ell S start hs mesh N {h | occurs E N h} ≤ + FlaggedSourceStart.sourceLaw hwn hell hS0 hS hr hs hsS mesh N failed + + finitePathMeasure (FlaggedSourceStart.typedState start.side start.ratio hs) N + (FiniteHistoryOccurrence.arrivalOccurrence (crossingHighEvent (Real.log start.gap) (theta*B) T) N) := by + rw [fullSourceLaw_eq hwn hell hS0 hS hr hs hsS] + have hsub : ∀ᵐ h ∂sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N, + occurs E N h → h ∈ {h | (last N h).2=true} ∪ + ((mapHist (fun q => q.1.2) N) ⁻¹' {h | completedOccurrence (crossingHighEvent (Real.log start.gap) (theta*B) T) N h}) := by + filter_upwards [nonisolated_word_occurs hwn hell hS0 hS hr hs hsS hw htop hxi hB htheta htheta1 hT + h199 hc hcut hcap hm hmesh N hexp hwidth] with h hh + intro ho + cases hf : (last N h).2 with + | true => exact Or.inl hf + | false => + apply Or.inr + obtain ⟨j,hj⟩ := ho + let k : Finset.Iic N := ⟨j.1,Finset.mem_Iic.mpr j.isLt.le⟩ + change selectedNode E ((h k).1.1) at hj + cases hp : (h k).1.1 with + | none => rw [hp] at hj; exact False.elim hj + | some p => + rw [hp] at hj + exact hh hf k p hp (hE p hj).1 (hE p hj).2 + have hu := (measure_mono_ae hsub).trans (measure_union_le _ _) + rw [sourceHistory_failure_probability hwn hell hS0 hS hr hs hsS mesh N] at hu + exact hu.trans (add_le_add le_rfl (source_completed_occurrence_le hwn hell hS0 hS hr hs hsS mesh N + (crossingHighEvent_measurable _ _ _))) +end NumberTheoryLean.NonisolatedSelectedOccurrence + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonquadraticZeroFree.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonquadraticZeroFree.lean new file mode 100644 index 0000000000000000000000000000000000000000..d48af6725e39a3d82ae520ae5b874279fe2c9b41 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonquadraticZeroFree.lean @@ -0,0 +1,146 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.CharacterPositivity + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz + +noncomputable def modulusHeight (q : ℕ) (t : ℝ) : ℝ := Real.log (q:ℝ)+Real.log (|t|+6) + +lemma modulusHeight_ge_one (q : ℕ) [NeZero q] (t : ℝ) : 1 ≤ modulusHeight q t := by + have hq : (1:ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hlq := Real.log_nonneg hq + have ht := abs_nonneg t + have hlt : 1 < Real.log (|t|+6) := + (Real.lt_log_iff_exp_lt (by linarith)).mpr (Real.exp_one_lt_three.trans (by linarith)) + unfold modulusHeight + linarith + +lemma modulusHeight_double_le (q : ℕ) [NeZero q] (t : ℝ) : + modulusHeight q (2*t) ≤ 2 * modulusHeight q t := by + have hq : (1:ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hlq := Real.log_nonneg hq + have ht := abs_nonneg t + have htp : 0 < |t|+6 := by linarith + have h2 : Real.log 2 ≤ Real.log (|t|+6) := Real.log_le_log (by norm_num) (by linarith) + have he : |2*t| = 2*|t| := by rw [abs_mul]; norm_num + have hlog : Real.log (|2*t|+6) ≤ Real.log (2*(|t|+6)) := + Real.log_le_log (by positivity) (by rw [he]; linarith) + rw [Real.log_mul (by norm_num : (2:ℝ) ≠ 0) htp.ne'] at hlog + unfold modulusHeight + linarith + +theorem exists_nonquadratic_zero_reciprocal_bound : + ∃ K : ℝ, 0 < K ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi^2 ≠ 1 → ∀ sigma beta t : ℝ, + 1 < sigma → sigma ≤ 2 → 3/4 ≤ beta → beta < 1 → + DirichletCharacter.LFunction chi ((beta:ℂ)+(t:ℂ)*Complex.I) = 0 → + 4/(sigma-beta) ≤ 3/(sigma-1)+K*modulusHeight q t := by + obtain ⟨Cp, hCp, hp⟩ := uniform_zero_penalty + obtain ⟨Cu, hCu, hu⟩ := uniform_neg_real_log_derivative + obtain ⟨Cz, hCz, hz⟩ := _root_.Erdos970.strongPnt_triv_bound_zeta + refine ⟨3*Cz+4*Cp+2*Cu, by linarith, ?_⟩ + intro q _ chi hsq sigma beta t hs hs2 hb34 hb1 hzero + have hchi : chi ≠ 1 := by + intro h + apply hsq + rw [h, one_pow] + have hpen := hp q chi hchi sigma beta t hs hs2 hb34 hb1 hzero + have hup := hu q (chi^2) hsq sigma (2*t) hs hs2 + have hup' : (-deriv (DirichletCharacter.LFunction (chi^2)) ((sigma:ℂ)+(2*t:ℝ)*Complex.I) / + DirichletCharacter.LFunction (chi^2) ((sigma:ℂ)+(2*t:ℝ)*Complex.I)).re ≤ + 2*Cu*modulusHeight q t := by + apply hup.trans + change Cu * modulusHeight q (2*t) ≤ _ + have h := mul_le_mul_of_nonneg_left (modulusHeight_double_le q t) hCu.le + nlinarith only [h] + have hzeta := hz sigma 0 hs + simp only [Complex.ofReal_zero, zero_mul, add_zero] at hzeta + have hzeta' := (Complex.re_le_norm (-deriv riemannZeta (sigma:ℂ)/riemannZeta (sigma:ℂ))).trans hzeta + have habsorb : Cz ≤ Cz*modulusHeight q t := by + simpa only [mul_one] using mul_le_mul_of_nonneg_left (modulusHeight_ge_one q t) hCz + have hpositive := character_log_derivative_positivity chi sigma t hs + change _ ≤ Cp*modulusHeight q t-1/(sigma-beta) at hpen + rw [one_div] at hpen + simp only [div_eq_mul_inv] + nlinarith only [hpositive, hpen, hup', hzeta', habsorb] + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz + +theorem exists_nonquadratic_zero_free_region : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi^2 ≠ 1 → ∀ s : ℂ, + 1-c/modulusHeight q s.im ≤ s.re → DirichletCharacter.LFunction chi s ≠ 0 := by + obtain ⟨K, hK, hineq⟩ := exists_nonquadratic_zero_reciprocal_bound + let delta : ℝ := 1/(8*(K+1)) + have hd : 0 < delta := by dsimp [delta]; positivity + have hd8 : delta ≤ 1/8 := by + apply (div_le_iff₀ (by positivity : 0 < 8*(K+1))).mpr + nlinarith + have hKd : K*delta ≤ 1/8 := by + dsimp only [delta] + rw [mul_one_div] + apply (div_le_iff₀ (by positivity : 0 < 8*(K+1))).mpr + nlinarith + let c : ℝ := delta/4 + refine ⟨c, by dsimp only [c]; positivity, ?_⟩ + intro q _ chi hsq s hs hzero + have hchi : chi ≠ 1 := by + intro h + apply hsq + rw [h, one_pow] + have hb1 : s.re < 1 := by + by_contra! h + exact DirichletCharacter.LFunction_ne_zero_of_one_le_re chi (Or.inl hchi) h hzero + let H : ℝ := modulusHeight q s.im + have hH : 1 ≤ H := modulusHeight_ge_one q s.im + have hHp : 0 < H := by linarith + let x : ℝ := delta/H + have hxp : 0 < x := by dsimp only [x]; positivity + have hxd : x ≤ delta := by + apply (div_le_iff₀ hHp).mpr + nlinarith + have hclose : 1-s.re ≤ x/4 := by + have he : c/H = x/4 := by dsimp only [c,x]; ring + change 1-c/H ≤ s.re at hs + rw [he] at hs + linarith + have hb34 : 3/4 ≤ s.re := by linarith + have hsigma : 1 < 1+x := by linarith + have hsigma2 : 1+x ≤ 2 := by linarith + have hz : DirichletCharacter.LFunction chi ((s.re:ℂ)+(s.im:ℂ)*Complex.I) = 0 := by + simpa only [Complex.re_add_im] using hzero + have hr := hineq q chi hsq (1+x) s.re s.im hsigma hsigma2 hb34 hb1 hz + let y : ℝ := 1+x-s.re + have hyp : 0 < y := by dsimp only [y]; linarith + have hy : y ≤ (5/4)*x := by dsimp only [y]; linarith + have hKx : K*H*x ≤ 1/8 := by + have he : K*H*x = K*delta := by dsimp only [x]; field_simp + rw [he] + exact hKd + change 4/y ≤ 3/(1+x-1)+K*H at hr + rw [add_sub_cancel_left] at hr + have h := mul_le_mul_of_nonneg_right ((div_le_iff₀ hyp).mp hr) hxp.le + have he : (3/x+K*H)*y*x = 3*y+K*H*x*y := by + field_simp + rw [he] at h + have hKy := mul_le_mul_of_nonneg_right hKx hyp.le + nlinarith only [h, hKy, hy, hxp] + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonstructuredCounts.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonstructuredCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..333c1e6457fb8b02506acfe99e3a4d8365852713 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/NonstructuredCounts.lean @@ -0,0 +1,269 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.OriginalSourcePolynomial +import OAI.NumberTheory.Jacobsthal.Primes.IgnoredDenominatorPrimes +import OAI.NumberTheory.Jacobsthal.Sieve.IntegerRichLine + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceLineBudget +open ErdosInverseBoxHeight ErdosSourcePolynomial ErdosAuxiliaryPolynomial ErdosInversePrimeBin +open ErdosRichLine ErdosConvexGraph + +def RichPoint (R xi c : ℝ) (T : primeBin R xi → Finset ℤ) (a : primeBin R xi → ℤ) + (v : ℤ × ℤ) : Prop := + ∃ (I : Finset ℕ) (hIP : I ⊆ primeBin R xi), c*((primeBin R xi).card : ℝ) ≤ (I.card : ℝ) ∧ + ∀ r : I, IntegerLineIncidence (primeBin R xi) T a v.1 v.2 ⟨r.val,hIP r.property⟩ + +theorem uniform_original_rich_line (C Cparent eta alpha c : ℝ) + (hC : 0 ≤ C) (hCp : 0 ≤ Cparent) (heta : 0 < eta) (halpha : 0 < alpha) (hc : 0 < c) : + ∀ᶠ z : ℝ in atTop, 2 ≤ z ∧ ∀ S R p q xi : ℝ, + 1 ≤ p → 0 < q → p*q ≤ (sourceY z : ℝ) → + 1 ≤ S/q → S/q ≤ (1+xi)^(C*Real.log (sourceB z)) → + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → eta ≤ xi → xi ≤ 1 → p ≤ 2*R → + Real.logb (sourceW z) ((sourceY z : ℝ)/(p*q)) ≤ Cparent → + ∀ (T : primeBin R xi → Finset ℤ) (a : primeBin R xi → ℤ), + (∑ r : primeBin R xi, ((T r).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/(Real.log z)^6 → + ∀ X : Finset (ℤ × ℤ), (∀ v ∈ X, InSquare S v) → + Set.InjOn Prod.fst (X : Set (ℤ × ℤ)) → + S/(sourceZ z)^4 ≤ (X.card : ℝ) → (∀ v ∈ X, RichPoint R xi c T a v) → + ∃ (l : PrimitiveIntegerLine) (Y : Finset (ℤ × ℤ)), Y ⊆ X ∧ + S/(R*(sourceZ z)^6) < (Y.card : ℝ) ∧ (∀ v ∈ Y, l.Contains v) ∧ + (l.denominator : ℝ) ≤ 2*S/(Y.card : ℝ) ∧ + |(l.slope : ℝ)| ≤ 2*S/(Y.card : ℝ) ∧ + |(l.intercept : ℝ)| ≤ 4*S^2/(Y.card : ℝ) := by + filter_upwards [uniform_original_source_polynomial C eta alpha c hC heta halpha hc, + uniform_extraction_budget Cparent hCp] with z hz hb + refine ⟨hz.1,?_⟩ + intro S R p q xi hp hq hpq hratio hinfl hRlo hRhi hxi hxi1 hpR hlen T a hthin + X hbox hinj hcard hrich + obtain ⟨w⟩ := hz.2 S R p q xi hp hq hpq hratio hinfl hRlo hRhi hxi hxi1 T a hthin + have hp0 : 0 < p := by linarith + have hqS : q ≤ S := (one_le_div hq).mp hratio + have hS : 0 ≤ S := hq.le.trans hqS + have hbudget := hb.2 p q R S hp0 hq hpR hRhi hqS hlen + have hzero : ∀ v ∈ X, MvPolynomial.eval ![v.1,v.2] w.polynomial = 0 := by + intro v hv + obtain ⟨I,hIP,hI,hinc⟩ := hrich v hv + exact w.rich_vanishing v.1 v.2 (hbox v hv).1 (hbox v hv).2 I hIP hI hinc + exact integer_polynomial_rich_line w.polynomial w.nonzero (sourceDegree z R) w.degree_le + S hS X hbox hzero hinj (S/(R*(sourceZ z)^6)) hbudget.2.1 (hbudget.2.2.trans_le hcard) + +end ErdosSourceLineBudget + +end + +section + +namespace ErdosSourceLineBudget +open ErdosRichLine + +theorem source_line_heights (l : PrimitiveIntegerLine) (S R Z N : ℝ) + (hS : 0 ≤ S) (hR : 0 < R) (hZ : 0 < Z) (hN : 0 < N) + (hrich : S/(R*Z^6) < N) (hd : (l.denominator : ℝ) ≤ 2*S/N) + (ha : |(l.slope : ℝ)| ≤ 2*S/N) (hb : |(l.intercept : ℝ)| ≤ 4*S^2/N) : + (l.denominator : ℝ) ≤ 2*R*Z^6 ∧ |(l.slope : ℝ)| ≤ 2*R*Z^6 ∧ + |(l.intercept : ℝ)| ≤ 4*S*R*Z^6 := by + have hmul : S < N*(R*Z^6) := (div_lt_iff₀ (by positivity : 0 < R*Z^6)).mp hrich + have hratio : S/N ≤ R*Z^6 := (div_le_iff₀ hN).mpr (by nlinarith) + have htwo : 2*S/N ≤ 2*R*Z^6 := by + calc + _ = 2*(S/N) := by ring + _ ≤ 2*(R*Z^6) := mul_le_mul_of_nonneg_left hratio (by norm_num) + _ = _ := by ring + have hfour : 4*S^2/N ≤ 4*S*R*Z^6 := by + calc + _ = (4*S)*(S/N) := by ring + _ ≤ (4*S)*(R*Z^6) := mul_le_mul_of_nonneg_left hratio (by positivity) + _ = _ := by ring + exact ⟨hd.trans htwo,ha.trans htwo,hb.trans hfour⟩ + +theorem source_line_height_slack (l : PrimitiveIntegerLine) (S R Z : ℝ) + (hS : 0 ≤ S) (hR : 0 ≤ R) (hZ : 2 ≤ Z) + (hd : (l.denominator : ℝ) ≤ 2*R*Z^6) (ha : |(l.slope : ℝ)| ≤ 2*R*Z^6) + (hb : |(l.intercept : ℝ)| ≤ 4*S*R*Z^6) : + (l.denominator : ℝ) ≤ R*Z^10 ∧ |(l.slope : ℝ)| ≤ R*Z^10 ∧ + |(l.intercept : ℝ)| ≤ S*R*Z^10 := by + have hZ0 : 0 ≤ Z := by linarith + have hfour : 4 ≤ Z^4 := by nlinarith [sq_nonneg (Z^2-2)] + have htwo : 2*R*Z^6 ≤ R*Z^10 := by + nlinarith [mul_nonneg (mul_nonneg hR (pow_nonneg hZ0 6)) (show 0 ≤ Z^4-2 by linarith)] + have hfour' : 4*S*R*Z^6 ≤ S*R*Z^10 := by + nlinarith [mul_nonneg (mul_nonneg (mul_nonneg hS hR) (pow_nonneg hZ0 6)) (sub_nonneg.mpr hfour)] + exact ⟨hd.trans htwo,ha.trans htwo,hb.trans hfour'⟩ + +end ErdosSourceLineBudget + +end + +section + +namespace ErdosInverseStructured +open ErdosInverseAlignment ErdosPrimitiveIntercept ErdosRichLine ErdosInversePrimeBin ErdosConvexGraph +attribute [local instance] Classical.propDecidable + +def SlopeIncidence (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (v : ℤ × ℤ) (p : ℕ) : Prop := + ∃ s ∈ T p, (v.2 : ZMod p) = (a p : ZMod p)-(s : ZMod p)*(v.1 : ZMod p) + +def NonstructuredIncidence (P : Finset ℕ) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (S R Z cp : ℝ) (v : ℤ × ℤ) (p : ℕ) : Prop := + SlopeIncidence a T v p ∧ Nonstructured P a S R Z cp p v.1.toNat + +noncomputable def nonstructuredPrimes (P : Finset ℕ) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) + (S R Z cp : ℝ) (v : ℤ × ℤ) : Finset ℕ := + P.filter (NonstructuredIncidence P a T S R Z cp v) + +noncomputable def nonstructuredPoints (P : Finset ℕ) (X : Finset (ℤ × ℤ)) + (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (S R Z cp : ℝ) (p : ℕ) : Finset (ℤ × ℤ) := + X.filter (fun v => NonstructuredIncidence P a T S R Z cp v p) + +theorem nonstructured_richness_implies_polynomial_richness (R xi c S Z cp : ℝ) + (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (v : ℤ × ℤ) + (h : c*((primeBin R xi).card : ℝ) ≤ + ((nonstructuredPrimes (primeBin R xi) a T S R Z cp v).card : ℝ)) : + ErdosSourceLineBudget.RichPoint R xi c (fun p => T p.val) (fun p => a p.val) v := by + let I := nonstructuredPrimes (primeBin R xi) a T S R Z cp v + have hIP : I ⊆ primeBin R xi := Finset.filter_subset _ _ + refine ⟨I,hIP,h,?_⟩ + intro p + exact (Finset.mem_filter.mp p.property).2.1 + +theorem contains_nat_abscissa (l : PrimitiveIntegerLine) (v : ℤ × ℤ) + (h0 : 0 ≤ (v.1 : ℝ)) (hv : l.Contains v) : l.Contains ((v.1.toNat : ℤ),v.2) := by + have hv0 : 0 ≤ v.1 := by exact_mod_cast h0 + have he := Int.toNat_of_nonneg hv0 + simpa only [he] using hv + +end ErdosInverseStructured + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceCollision +open ErdosInversePrimeBin ErdosLineCollision ErdosInverseBoxHeight + +theorem uniform_actual_ignored_incidence (eta alpha eps : ℝ) + (heta : 0 < eta) (halpha : 0 < alpha) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ R xi : ℝ, + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → eta ≤ xi → xi ≤ 1 → + ∀ d : ℕ, 0 < d → (d : ℝ) ≤ R*(sourceZ z)^10 → + ∀ (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ), + (∑ p ∈ ignoredPrimes (primeBin R xi) d,((incidentPoints X (a p) p (T p)).card : ℝ)) ≤ + eps*((primeBin R xi).card : ℝ)*(X.card : ℝ) := by + let M : ℕ := ⌈(1/alpha)/eps⌉₊ + obtain ⟨R0,hR0⟩ := eventually_atTop.mp (uniform_prime_bin_many heta M) + filter_upwards [sourceZ_le_small_power,(tendsto_rpow_atTop halpha).eventually_ge_atTop R0] with z hz hzR + refine ⟨hz.1,?_⟩ + intro R xi hRlo hRhi hxi hxi1 d hd hdheight X a T + have hb := hR0 R (hzR.trans hRlo) + have hRpos : 0 < R := by linarith [hb.1] + have hxipos : 0 ≤ xi := heta.le.trans hxi + have hheight := source_denominator_le_z hz.1 hRpos.le hz.2.1.le hRhi hz.2.2 hdheight + have hprime (p : ℕ) (hp : p ∈ primeBin R xi) : Nat.Prime p := + ((mem_primeBin hRpos.le hxipos p).mp hp).1 + have hlarge (p : ℕ) (hp : p ∈ primeBin R xi) : z^alpha ≤ (p : ℝ) := + hRlo.trans (((mem_primeBin hRpos.le hxipos p).mp hp).2.1.le) + have hcard := ignoredPrimes_card_le (primeBin R xi) d hd hprime z alpha hz.1 halpha hlarge hheight + have hM : (M : ℝ) ≤ ((primeBin R xi).card : ℝ) := by exact_mod_cast hb.2 xi hxi hxi1 + have hceil : (1/alpha)/eps ≤ (M : ℝ) := Nat.le_ceil _ + have hsmall : 1/alpha ≤ eps*((primeBin R xi).card : ℝ) := by + have hh := (div_le_iff₀ heps).mp (hceil.trans hM) + nlinarith + calc + _ ≤ ((ignoredPrimes (primeBin R xi) d).card : ℝ)*(X.card : ℝ) := + total_incidence_le_product _ _ _ _ + _ ≤ (1/alpha)*(X.card : ℝ) := mul_le_mul_of_nonneg_right hcard (Nat.cast_nonneg _) + _ ≤ _ := mul_le_mul_of_nonneg_right hsmall (Nat.cast_nonneg _) + +end ErdosSourceCollision + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourceCollision +open ErdosInversePrimeBin ErdosLineCollision ErdosRichLine ErdosPrimitiveIntercept ErdosInverseBoxHeight ErdosConvexGraph + +theorem uniform_actual_bad_incidence (eta alpha eps : ℝ) + (heta : 0 < eta) (halpha : 0 < alpha) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ R xi S : ℝ, + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → eta ≤ xi → xi ≤ 1 → + ∀ (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (l : PrimitiveIntegerLine) (r : InterceptReduction l) + (X : Finset (ℤ × ℤ)), (∀ v ∈ X,l.Contains v) → (∀ v ∈ X,InSquare S v) → + Set.InjOn Prod.fst (X : Set (ℤ × ℤ)) → S ≤ z^3 → z^((93 : ℝ)/100) ≤ (X.card : ℝ) → + (∑ p ∈ primeBin R xi,((T p).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/(Real.log z)^6 → + (l.denominator : ℝ) ≤ R*(sourceZ z)^10 → + (∑ p ∈ unalignedPrimes (primeBin R xi) a r,((incidentPoints X (a p) p (T p)).card : ℝ))+ + (∑ p ∈ ignoredPrimes (primeBin R xi) l.denominator,((incidentPoints X (a p) p (T p)).card : ℝ)) ≤ + eps*((primeBin R xi).card : ℝ)*(X.card : ℝ) := by + filter_upwards [uniform_actual_unaligned_incidence eta alpha (eps/2) heta halpha (by positivity), + uniform_actual_ignored_incidence eta alpha (eps/2) heta halpha (by positivity)] with z hu hi + refine ⟨hu.1,?_⟩ + intro R xi S hRlo hRhi hxi hxi1 a T l r X hline hbox hinj hS hN hthin hden + have hU := hu.2 R xi S hRlo hRhi hxi hxi1 a T l r X hline hbox hinj hS hN hthin + have hI := hi.2 R xi hRlo hRhi hxi hxi1 l.denominator l.denominator_pos hden X a T + linarith + +end ErdosSourceCollision + +end + +section + +namespace ErdosInverseStructured +open ErdosLineCollision +attribute [local instance] Classical.propDecidable + +theorem nonstructured_double_count (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) + (T : ℕ → Finset ℤ) (S R Z cp : ℝ) : + (∑ v ∈ X,((nonstructuredPrimes P a T S R Z cp v).card : ℝ)) = + ∑ p ∈ P,((nonstructuredPoints P X a T S R Z cp p).card : ℝ) := by + classical + have hh := Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow + (NonstructuredIncidence P a T S R Z cp) (s := X) (t := P) + change (∑ v ∈ X,((P.filter (NonstructuredIncidence P a T S R Z cp v)).card : ℝ)) = + ∑ p ∈ P,((X.filter (fun v => NonstructuredIncidence P a T S R Z cp v p)).card : ℝ) + exact_mod_cast hh + +theorem nonstructuredPoints_subset_incident (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) + (T : ℕ → Finset ℤ) (S R Z cp : ℝ) (p : ℕ) : + nonstructuredPoints P X a T S R Z cp p ⊆ incidentPoints X (a p) p (T p) := by + intro v hv + obtain ⟨hvX,hinc,_hnon⟩ := Finset.mem_filter.mp hv + exact Finset.mem_filter.mpr ⟨hvX,hinc⟩ + +theorem nonstructured_total_lower (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) + (T : ℕ → Finset ℤ) (S R Z cp c : ℝ) + (hrich : ∀ v ∈ X,c*(P.card : ℝ) ≤ ((nonstructuredPrimes P a T S R Z cp v).card : ℝ)) : + c*(P.card : ℝ)*(X.card : ℝ) ≤ ∑ p ∈ P,((nonstructuredPoints P X a T S R Z cp p).card : ℝ) := by + rw [← nonstructured_double_count] + calc + _ = ∑ _v ∈ X,c*(P.card : ℝ) := by simp;ring + _ ≤ _ := Finset.sum_le_sum hrich + +theorem all_incidence_lower_of_nonstructured_richness (P : Finset ℕ) (X : Finset (ℤ × ℤ)) + (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (S R Z cp c : ℝ) + (hrich : ∀ v ∈ X,c*(P.card : ℝ) ≤ ((nonstructuredPrimes P a T S R Z cp v).card : ℝ)) : + c*(P.card : ℝ)*(X.card : ℝ) ≤ ∑ p ∈ P,((incidentPoints X (a p) p (T p)).card : ℝ) := by + apply (nonstructured_total_lower P X a T S R Z cp c hrich).trans + apply Finset.sum_le_sum + intro p hp + exact Nat.cast_le.mpr (Finset.card_le_card (nonstructuredPoints_subset_incident P X a T S R Z cp p)) + +end ErdosInverseStructured + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/OmissionSeries.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OmissionSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..03c6ffe1eb1cb997367b89748a52bf30292ac06b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OmissionSeries.lean @@ -0,0 +1,200 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ContinuousQRecurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.MeasureTheory _root_.Set +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +noncomputable def baseCutoff (b : ℝ) : ℝ := max 1 (min 2 b) +noncomputable def survivorBaseline (b : ℝ) : ℝ := (baseCutoff b)⁻¹ + +theorem baseCutoff_bounds (b : ℝ) : 1 ≤ baseCutoff b ∧ baseCutoff b ≤ 2 := + upperCutoff_bounds .even 0 b + +theorem baseCutoff_on {b : ℝ} (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : baseCutoff b=b := by + rw [baseCutoff,min_eq_right hb2,max_eq_right hb1] + +theorem cutoff_le_base (i : Side) (r b : ℝ) : upperCutoff i r b ≤ baseCutoff b := by + cases i with + | even => exact le_rfl + | odd => exact max_le_max le_rfl (min_le_left _ _) + +theorem survivorBaseline_continuous : Continuous survivorBaseline := + (continuous_const.max (continuous_const.min continuous_id)).inv₀ (fun b => + ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (baseCutoff_bounds b).1)) + +theorem baseline_profile_continuous : JointContinuous (fun _ _ b => survivorBaseline b) := + fun _ => survivorBaseline_continuous.comp continuous_snd + +theorem gate_survivorBaseline (i : Side) (r b : ℝ) : + gate (fun _ _ t => survivorBaseline t) i r b=1-(upperCutoff i r b)⁻¹ := by + let a := upperCutoff i r b + have ha : 1 ≤ a := (upperCutoff_bounds i r b).1 + have hne : ∀ x ∈ uIcc (1:ℝ) a,x ≠ 0 := by + intro x hx + rw [uIcc_of_le ha] at hx + linarith [hx.1] + have hc : ContinuousOn (fun x : ℝ => (x^2)⁻¹) (uIcc (1:ℝ) a) := + (continuous_id.pow 2).continuousOn.inv₀ (fun x hx => pow_ne_zero 2 (hne x hx)) + have hd : ∀ x ∈ uIcc (1:ℝ) a,HasDerivAt (fun t : ℝ => -t⁻¹) ((x^2)⁻¹) x := by + intro x hx + simpa only [neg_neg] using! (hasDerivAt_inv (hne x hx)).neg + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt hd (hc.intervalIntegrable (μ := volume)) + calc + gate (fun _ _ t => survivorBaseline t) i r b=∫ x in (1:ℝ)..a,(x^2)⁻¹ := by + unfold gate + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le ha] at hx + dsimp only + have hx2 : x ≤ 2 := hx.2.trans (upperCutoff_bounds i r b).2 + rw [survivorBaseline,baseCutoff_on hx.1 hx2,max_eq_right hx.1] + ring + _ = 1-a⁻¹ := by rw [h]; simp only [inv_one]; ring + +noncomputable def omissionForce : Profile + | .even,_,_ => 0 + | .odd,r,b => (upperCutoff .odd r b)⁻¹-survivorBaseline b + +theorem omissionForce_continuous : JointContinuous omissionForce := by + intro i + cases i with + | even => exact continuous_const + | odd => + have hc := (upperCutoff_continuous .odd).inv₀ (fun p => ne_of_gt + ((by norm_num : (0:ℝ)<1).trans_le (upperCutoff_bounds .odd p.1 p.2).1)) + exact hc.sub (survivorBaseline_continuous.comp continuous_snd) + +theorem omissionForce_nonnegative (i : Side) (r b : ℝ) : 0 ≤ omissionForce i r b := by + cases i with + | even => exact le_rfl + | odd => + apply sub_nonneg.mpr + have h := one_div_le_one_div_of_le + ((by norm_num : (0:ℝ)<1).trans_le (upperCutoff_bounds .odd r b).1) (cutoff_le_base .odd r b) + simpa only [one_div,survivorBaseline] using h + +end ErdosContinuousOmission + +end + +section + +open _root_.MeasureTheory _root_.Set +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +noncomputable def omissionDefect : Profile + | .even,r,b => survivorBaseline b-boundaryReference .even r b + | .odd,r,b => boundaryReference .odd r b-survivorBaseline b + +theorem omissionDefect_continuous : JointContinuous omissionDefect := by + intro i + cases i with + | even => exact (baseline_profile_continuous .even).sub (boundaryReference_continuous .even) + | odd => exact (boundaryReference_continuous .odd).sub (baseline_profile_continuous .odd) + +theorem gate_sub {H G : Profile} (hH : JointContinuous H) (hG : JointContinuous G) + (i : Side) (r b : ℝ) : + gate (fun j s t => H j s t-G j s t) i r b=gate H i r b-gate G i r b := by + simp only [gate,sub_div] + exact intervalIntegral.integral_sub + ((gate_integrand_continuous hH i r).intervalIntegrable 1 _) ((gate_integrand_continuous hG i r).intervalIntegrable 1 _) + +theorem gate_defect_even (r b : ℝ) : + gate omissionDefect .even r b=gate boundaryReference .even r b-gate (fun _ _ t => survivorBaseline t) .even r b := by + change gate (fun j s t => boundaryReference j s t-survivorBaseline t) .even r b=_ + exact gate_sub boundaryReference_continuous baseline_profile_continuous .even r b + +theorem gate_defect_odd (r b : ℝ) : + gate omissionDefect .odd r b=gate (fun _ _ t => survivorBaseline t) .odd r b-gate boundaryReference .odd r b := by + change gate (fun j s t => survivorBaseline t-boundaryReference j s t) .odd r b=_ + exact gate_sub baseline_profile_continuous boundaryReference_continuous .odd r b + +theorem actual_defect_forcing (i : Side) (r b : ℝ) : + omissionDefect i r b=omissionForce i r b+gate omissionDefect i r b := by + cases i with + | even => + change survivorBaseline b-boundaryReference .even r b=0+gate omissionDefect .even r b + rw [gate_defect_even,gate_survivorBaseline,boundaryReference_recurrence .even r b] + change survivorBaseline b-(1-gate boundaryReference .even r b)=0+(gate boundaryReference .even r b-(1-survivorBaseline b)) + ring + | odd => + change boundaryReference .odd r b-survivorBaseline b= + (upperCutoff .odd r b)⁻¹-survivorBaseline b+gate omissionDefect .odd r b + rw [gate_defect_odd,gate_survivorBaseline,boundaryReference_recurrence .odd r b] + ring + +theorem actual_finite_omission_expansion (N : ℕ) (hN : 2 ≤ N) (i : Side) + {r b : ℝ} (hr : r ≤ (N:ℝ)-1) : + omissionDefect i r b=∑ n ∈ Finset.range N,gateIterate n omissionForce i r b := by + have h := finite_forcing_expansion omissionDefect_continuous omissionForce_continuous actual_defect_forcing N i r b + rw [gateIterate_zero_of_index omissionDefect hN i hr,add_zero] at h + exact h + +theorem omissionDefect_nonnegative (i : Side) (r b : ℝ) : 0 ≤ omissionDefect i r b := by + rw [actual_finite_omission_expansion (referenceDepth r) (referenceDepth_bounds r).1 i (referenceDepth_bounds r).2] + apply Finset.sum_nonneg + intro n _ + exact gateIterate_nonnegative omissionForce_nonnegative n i r b + +theorem actual_reference_order {b : ℝ} (hb1 : 1 ≤ b) (hb2 : b ≤ 2) (r : ℝ) : + boundaryReference .even r b ≤ b⁻¹ ∧ b⁻¹ ≤ boundaryReference .odd r b := by + have he := omissionDefect_nonnegative .even r b + have ho := omissionDefect_nonnegative .odd r b + simp only [omissionDefect,survivorBaseline,baseCutoff_on hb1 hb2] at he ho + exact ⟨by linarith,by linarith⟩ + +theorem partial_omission_le_defect (N : ℕ) (i : Side) (r b : ℝ) : + (∑ n ∈ Finset.range N,gateIterate n omissionForce i r b) ≤ omissionDefect i r b := by + have h := finite_forcing_expansion omissionDefect_continuous omissionForce_continuous actual_defect_forcing N i r b + have hn := gateIterate_nonnegative omissionDefect_nonnegative N i r b + linarith + +end ErdosContinuousOmission + +end + +section + +open _root_.Set _root_.Filter +open scoped Topology +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +theorem omission_terms_vanish (i : Side) (r b : ℝ) : + ∀ n : ℕ,referenceDepth r ≤ n → gateIterate n omissionForce i r b=0 := by + intro n hn + apply gateIterate_zero_of_index omissionForce ((referenceDepth_bounds r).1.trans hn) i + have hh : (referenceDepth r:ℝ) ≤ (n:ℝ) := by exact_mod_cast hn + exact (referenceDepth_bounds r).2.trans (by linarith) + +theorem actual_omission_hasSum (i : Side) (r b : ℝ) : + HasSum (fun n : ℕ => gateIterate n omissionForce i r b) (omissionDefect i r b) := by + rw [actual_finite_omission_expansion (referenceDepth r) (referenceDepth_bounds r).1 i (referenceDepth_bounds r).2] + apply hasSum_sum_of_ne_finset_zero + intro n hn + apply omission_terms_vanish i r b n + exact le_of_not_gt (by simpa only [Finset.mem_range] using hn) + +theorem actual_omission_tsum (i : Side) (r b : ℝ) : + (∑' n : ℕ,gateIterate n omissionForce i r b)=omissionDefect i r b := + (actual_omission_hasSum i r b).tsum_eq + +theorem actual_omission_summable (i : Side) (r b : ℝ) : + Summable (fun n : ℕ => gateIterate n omissionForce i r b) := + (actual_omission_hasSum i r b).summable + +end ErdosContinuousOmission + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/OmissionTiltDecay.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OmissionTiltDecay.lean new file mode 100644 index 0000000000000000000000000000000000000000..2fc7b9b19f76f84f09285519e3f7ca9996b8a975 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OmissionTiltDecay.lean @@ -0,0 +1,106 @@ +import OAI.NumberTheory.Jacobsthal.Primes.BoundaryPrimeMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.OmissionTiltDecay + +open _root_.Finset +open FinitePathGeometry ReferenceAdmission VariablePrimeTilt BoundaryPrimeMass + +theorem omission_depth_lower {r : ℝ} (hr : 8 ≤ r) : + r/4 ≤ ((⌊(r-4)/2⌋₊+1:ℕ):ℝ) := by + have hf := Nat.lt_floor_add_one ((r-4)/2) + push_cast + linarith + +theorem sqrt_tilt_decay {T r : ℝ} (hT : 0 ≤ T) (hr : 8 ≤ r) + (hlog : 1 ≤ Real.log r) (hlarge : (16*T)^2 ≤ r) : + Real.exp (Real.sqrt r*T)/(Real.sqrt r)^(⌊(r-4)/2⌋₊+1) ≤ + Real.exp (-(1/32:ℝ)*r*Real.log (r+2)) := by + have hr0 : 0 < r := by linarith + have hs0 : 0 < Real.sqrt r := Real.sqrt_pos.mpr hr0 + have hs : 16*T ≤ Real.sqrt r := by + have hsq := Real.sq_sqrt hr0.le + nlinarith [Real.sqrt_nonneg r] + have hmain : Real.sqrt r*T ≤ r/16 := by + have hh := mul_le_mul_of_nonneg_right hs hs0.le + nlinarith [Real.sq_sqrt hr0.le] + have hlen := omission_depth_lower hr + have hlog0 : 0 ≤ Real.log r := by linarith + have hden : r*Real.log r/8 ≤ + ((⌊(r-4)/2⌋₊+1:ℕ):ℝ)*Real.log (Real.sqrt r) := by + rw [Real.log_sqrt hr0.le] + nlinarith [mul_le_mul_of_nonneg_right hlen hlog0] + have hlog2 : Real.log (r+2) ≤ 2*Real.log r := by + have hh : r+2 ≤ r^2 := by nlinarith + have hm := Real.log_le_log (by linarith : 0 < r+2) hh + simpa only [Real.log_pow,Nat.cast_ofNat] using hm + have hpay : r/16 ≤ r*Real.log r/16 := by + nlinarith [mul_le_mul_of_nonneg_left hlog hr0.le] + have hcompare : Real.sqrt r*T- + ((⌊(r-4)/2⌋₊+1:ℕ):ℝ)*Real.log (Real.sqrt r) ≤ + -(1/32:ℝ)*r*Real.log (r+2) := by + nlinarith [mul_le_mul_of_nonneg_left hlog2 hr0.le] + calc + _ = Real.exp (Real.sqrt r*T- + ((⌊(r-4)/2⌋₊+1:ℕ):ℝ)*Real.log (Real.sqrt r)) := by + rw [Real.exp_sub,Real.exp_nat_mul,Real.exp_log hs0] + _ ≤ _ := Real.exp_le_exp.mpr hcompare + +theorem actual_omission_decay : ∃ C w₀ : ℝ,0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ r : ℝ,2 ≤ r → ∀ i : Side, + omissionMass w r i ≤ C*Real.exp (-(1/32:ℝ)*r*Real.log (r+2)) := by + obtain ⟨T,w₀,hT,hw₀,hbound⟩ := uniform_boundary_mass + let R : ℝ := max 8 (max (Real.exp 1) ((16*T)^2)) + have hR8 : 8 ≤ R := le_max_left _ _ + have hRe : Real.exp 1 ≤ R := (le_max_left _ _).trans (le_max_right _ _) + have hRT : (16*T)^2 ≤ R := (le_max_right _ _).trans (le_max_right _ _) + let C : ℝ := max 1 (T*Real.exp ((1/32:ℝ)*R*Real.log (R+2))) + have hC1 : 1 ≤ C := le_max_left _ _ + have hCT : T*Real.exp ((1/32:ℝ)*R*Real.log (R+2)) ≤ C := le_max_right _ _ + refine ⟨C,w₀,by linarith,hw₀,?_⟩ + intro w hw r hr i + obtain ⟨hp,_hm,ho⟩ := hbound w hw + have hw1 : 1 < w := hw₀.trans_le hw + have hr0 : 0 < r := by linarith + by_cases hbig : R ≤ r + · have hr8 := hR8.trans hbig + have hl : 1 ≤ Real.log r := by + have hh := Real.log_le_log (Real.exp_pos 1) (hRe.trans hbig) + simpa using hh + have ht : 1 ≤ Real.sqrt r := (Real.one_le_sqrt).mpr (by linarith) + have hv := actual_omission_variable_tilt hw1 (by linarith : 4 ≤ r) ht i + have hnum := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hp (Real.sqrt_nonneg r)) + calc + _ ≤ Real.exp (Real.sqrt r*T)/(Real.sqrt r)^(⌊(r-4)/2⌋₊+1) := + hv.trans (div_le_div_of_nonneg_right hnum (pow_nonneg (Real.sqrt_nonneg r) _)) + _ ≤ Real.exp (-(1/32:ℝ)*r*Real.log (r+2)) := sqrt_tilt_decay hT.le hr8 hl (hRT.trans hbig) + _ ≤ _ := le_mul_of_one_le_left (Real.exp_nonneg _) hC1 + · have hrR : r ≤ R := le_of_lt (lt_of_not_ge hbig) + have hl0 : 0 ≤ Real.log (r+2) := Real.log_nonneg (by linarith) + have hlR : Real.log (r+2) ≤ Real.log (R+2) := Real.log_le_log (by linarith) (by linarith) + have hprod : r*Real.log (r+2) ≤ R*Real.log (R+2) := + mul_le_mul hrR hlR hl0 (by linarith) + have hh : (1/32:ℝ)*R*Real.log (R+2) + (-(1/32:ℝ)*r*Real.log (r+2)) ≥ 0 := by nlinarith + have he := Real.one_le_exp_iff.mpr hh + calc + _ ≤ T := ho r i + _ ≤ T*Real.exp ((1/32:ℝ)*R*Real.log (R+2)+(-(1/32:ℝ)*r*Real.log (r+2))) := + le_mul_of_one_le_right hT.le he + _ = (T*Real.exp ((1/32:ℝ)*R*Real.log (R+2)))*Real.exp (-(1/32:ℝ)*r*Real.log (r+2)) := by + rw [Real.exp_add] + ring + _ ≤ _ := mul_le_mul_of_nonneg_right hCT (Real.exp_nonneg _) + +end NumberTheoryLean.OmissionTiltDecay + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/OnePairCost.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OnePairCost.lean new file mode 100644 index 0000000000000000000000000000000000000000..6008ecdf2fc9bfbdb3e8506a71b89b764d34b70e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OnePairCost.lean @@ -0,0 +1,282 @@ +import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap +import OAI.NumberTheory.Jacobsthal.Analysis.DeficitIntegralValues +import OAI.NumberTheory.Jacobsthal.Renewal.OccupationAge + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory +namespace Erdos970Dependency.InvariantCostBound +open NumberTheoryLean NumberTheoryLean.BuchstabBridge NumberTheoryLean.DerivativeWeights +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.NormalizedDeficits NumberTheoryLean.DeficitFutureIntegrals +open Erdos970Dependency.InvariantDensities Erdos970Dependency.DeficitIntegralValues + +noncomputable def evenCost (s : ℝ) : ℝ := evenDensity s * cost s +noncomputable def oddCost (s : ℝ) : ℝ := oddDensity s * cost s +noncomputable def evenMajor : ℝ → ℝ := (Ici (2 : ℝ)).indicator (fun s ↦ lowerDeficit s + upperDeficit (s - 1)) +noncomputable def oddMajor : ℝ → ℝ := (Ici (1 : ℝ)).indicator (fun s ↦ upperDeficit s + lowerDeficit (s - 1)) + +theorem cost_le_inv {s : ℝ} (hs : 0 < s) : cost s ≤ 1 / s := by + have h := Real.log_le_sub_one_of_pos (show 0 < 1 + 1 / s by positivity) + change Real.log (1 + 1 / s) ≤ 1 / s + linarith + +theorem evenCost_nonneg (s : ℝ) : 0 ≤ evenCost s := by + by_cases hs : 2 ≤ s + · rw [evenCost, evenDensity, indicator_of_mem (show s ∈ Ici (2 : ℝ) from hs)] + exact mul_nonneg (phiEven_pos (by linarith)).le (cost_pos (by linarith)).le + · rw [evenCost, evenDensity, indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs), zero_mul] + +theorem oddCost_nonneg (s : ℝ) : 0 ≤ oddCost s := by + by_cases hs : 1 ≤ s + · rw [oddCost] + exact mul_nonneg (oddDensity_nonneg s) (cost_pos (by linarith)).le + · rw [oddCost, oddDensity, indicator_of_notMem (show s ∉ Ici (1 : ℝ) from hs), zero_mul] + +theorem evenCost_le_major (s : ℝ) : evenCost s ≤ evenMajor s := by + by_cases hs : 2 ≤ s + · rw [evenCost, evenDensity, evenMajor, + indicator_of_mem (show s ∈ Ici (2 : ℝ) from hs), indicator_of_mem (show s ∈ Ici (2 : ℝ) from hs)] + calc + phiEven s * cost s ≤ phiEven s * (1 / s) := + mul_le_mul_of_nonneg_left (cost_le_inv (by linarith)) (phiEven_pos (by linarith)).le + _ = _ := by rw [phiEven_eq_deficits hs]; field_simp + · rw [evenCost, evenDensity, evenMajor, + indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs), + indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs), zero_mul] + +theorem oddCost_le_major (s : ℝ) : oddCost s ≤ oddMajor s := by + by_cases hs : 1 ≤ s + · rw [oddCost, oddDensity, oddMajor, + indicator_of_mem (show s ∈ Ici (1 : ℝ) from hs), indicator_of_mem (show s ∈ Ici (1 : ℝ) from hs)] + have hphi : oddFactor s * phiOdd s ≤ phiOdd s := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right (oddFactor_bounds hs).2 (phiOdd_pos s).le + calc + (oddFactor s * phiOdd s) * cost s ≤ phiOdd s * cost s := + mul_le_mul_of_nonneg_right hphi (cost_pos (by linarith)).le + _ ≤ phiOdd s * (1 / s) := + mul_le_mul_of_nonneg_left (cost_le_inv (by linarith)) (phiOdd_pos s).le + _ = _ := by rw [phiOdd_eq_deficits hs]; field_simp + · rw [oddCost, oddDensity, oddMajor, + indicator_of_notMem (show s ∉ Ici (1 : ℝ) from hs), + indicator_of_notMem (show s ∉ Ici (1 : ℝ) from hs), zero_mul] + +theorem evenMajor_integrable : Integrable evenMajor := + (integrable_indicator_iff measurableSet_Ici).mpr even_majorant_integral.1 + +theorem oddMajor_integrable : Integrable oddMajor := + (integrable_indicator_iff measurableSet_Ici).mpr odd_majorant_integral.1 + +theorem evenCost_integrable : Integrable evenCost := by + apply evenMajor_integrable.mono' (evenDensity_measurable.mul cost_measurable).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun s ↦ by + change ‖evenCost s‖ ≤ evenMajor s + rw [Real.norm_of_nonneg (evenCost_nonneg s)] + exact evenCost_le_major s) + +theorem oddCost_integrable : Integrable oddCost := by + apply oddMajor_integrable.mono' (oddDensity_measurable.mul cost_measurable).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun s ↦ by + change ‖oddCost s‖ ≤ oddMajor s + rw [Real.norm_of_nonneg (oddCost_nonneg s)] + exact oddCost_le_major s) + +theorem even_cost_bound : (∫ s, evenCost s) ≤ sieveA - 1 := by + have h := integral_mono evenCost_integrable evenMajor_integrable evenCost_le_major + rw [evenMajor, integral_indicator measurableSet_Ici, even_majorant_integral.2] at h + exact h + +theorem odd_cost_bound : (∫ s, oddCost s) ≤ sieveA + 1 := by + have h := integral_mono oddCost_integrable oddMajor_integrable oddCost_le_major + rw [oddMajor, integral_indicator measurableSet_Ici, odd_majorant_integral.2] at h + exact h + +theorem even_cost_pos : 0 < ∫ s, evenCost s := by + apply (integral_pos_iff_support_of_nonneg evenCost_nonneg evenCost_integrable).mpr + have hsub : Icc (2 : ℝ) 3 ⊆ Function.support evenCost := by + intro s hs + apply ne_of_gt + rw [evenCost, evenDensity, indicator_of_mem (show s ∈ Ici (2 : ℝ) from hs.1)] + exact mul_pos (phiEven_pos (by linarith [hs.1])) (cost_pos (by linarith [hs.1])) + exact lt_of_lt_of_le (by norm_num [Real.volume_Icc] : 0 < volume (Icc (2 : ℝ) 3)) (measure_mono hsub) + +noncomputable def costMass : ℝ := (∫ s, evenCost s) + ∫ s, oddCost s + +theorem costMass_pos : 0 < costMass := + add_pos_of_pos_of_nonneg even_cost_pos (integral_nonneg oddCost_nonneg) + +theorem costMass_le : costMass ≤ 2 * sieveA := by + unfold costMass + linarith [even_cost_bound, odd_cost_bound] + +end Erdos970Dependency.InvariantCostBound + +end + +section + +open Set MeasureTheory ProbabilityTheory +namespace Erdos970Dependency.RawStateCost +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.FinitePathMeasures NumberTheoryLean.CycleCostMoments +open NumberTheoryLean.CycleOccupation +open Erdos970Dependency.InvariantDensities Erdos970Dependency.InvariantFiniteness +open Erdos970Dependency.OrdinaryKernelInvariance Erdos970Dependency.StateKernelInvariance +open Erdos970Dependency.InvariantCostBound Erdos970Dependency.ActualCycleOccupation + +noncomputable def stateCost (s : State) : ℝ := cost (stateRatio s) + +theorem stateCost_measurable : Measurable stateCost := cost_measurable.comp stateRatio_measurable + +theorem stateCost_bounds (s : State) : 0 < stateCost s ∧ stateCost s ≤ Real.log 3 := by + have hs : 1 / 2 ≤ stateRatio s := by + cases s with + | inl s => change 1 / 2 ≤ s.1; linarith [s.2] + | inr s => change 1 / 2 ≤ s.1; linarith [s.2] + exact ⟨cost_pos (by linarith), draw_cost_le_log_three hs⟩ + +theorem stateCost_integrable (mu : Measure State) [IsFiniteMeasure mu] : Integrable stateCost mu := by + apply (integrable_const (Real.log 3)).mono' stateCost_measurable.aestronglyMeasurable + exact Filter.Eventually.of_forall (fun s ↦ by + rw [Real.norm_of_nonneg (stateCost_bounds s).1.le] + exact (stateCost_bounds s).2) + +theorem integral_evenMeasure (g : ℝ → ℝ) : (∫ s, g s ∂evenMeasure) = + ∫ s, InvariantDensities.evenDensity s * g s := by + have h := integral_withDensity_eq_integral_toReal_smul (μ := (volume : Measure ℝ)) + (ENNReal.measurable_ofReal.comp InvariantDensities.evenDensity_measurable) + (Filter.Eventually.of_forall (fun _ : ℝ ↦ ENNReal.ofReal_lt_top)) g + simpa only [evenMeasure, Function.comp_def, ENNReal.toReal_ofReal (InvariantDensities.evenDensity_nonneg _), + smul_eq_mul] using h + +theorem integral_oddMeasure (g : ℝ → ℝ) : (∫ s, g s ∂oddMeasure) = + ∫ s, InvariantDensities.oddDensity s * g s := by + have h := integral_withDensity_eq_integral_toReal_smul (μ := (volume : Measure ℝ)) + (ENNReal.measurable_ofReal.comp InvariantDensities.oddDensity_measurable) + (Filter.Eventually.of_forall (fun _ : ℝ ↦ ENNReal.ofReal_lt_top)) g + simpa only [oddMeasure, Function.comp_def, ENNReal.toReal_ofReal (InvariantDensities.oddDensity_nonneg _), + smul_eq_mul] using h + +theorem even_lifted_cost (s : ℝ) : InvariantDensities.evenDensity s * cost (evenLift s).1 = evenCost s := by + by_cases hs : 2 ≤ s + · have heq : (evenLift s).1 = s := max_eq_right (by linarith) + rw [heq] + rfl + · rw [evenCost, InvariantDensities.evenDensity, + indicator_of_notMem (show s ∉ Ici (2 : ℝ) from hs), zero_mul, zero_mul] + +theorem odd_lifted_cost (s : ℝ) : InvariantDensities.oddDensity s * cost (oddLift s).1 = oddCost s := by + by_cases hs : 1 ≤ s + · have heq : (oddLift s).1 = s := max_eq_right (by linarith) + rw [heq] + rfl + · rw [oddCost, InvariantDensities.oddDensity, + indicator_of_notMem (show s ∉ Ici (1 : ℝ) from hs), zero_mul, zero_mul] + +theorem state_cost_integral : (∫ s, stateCost s ∂stateMeasure) = costMass := by + rw [stateMeasure, integral_add_measure (stateCost_integrable _) (stateCost_integrable _), + integral_map measurable_inl.aemeasurable stateCost_measurable.aestronglyMeasurable, + integral_map measurable_inr.aemeasurable stateCost_measurable.aestronglyMeasurable] + simp only [stateCost, stateRatio, Sum.elim_inl, Sum.elim_inr] + have he := integral_map (μ := evenMeasure) evenLift_measurable.aemeasurable + (cost_measurable.comp (measurable_subtype_coe : Measurable + (Subtype.val : NumberTheoryLean.TransitionKernels.EvenState → ℝ))).aestronglyMeasurable + have ho := integral_map (μ := oddMeasure) oddLift_measurable.aemeasurable + (cost_measurable.comp (measurable_subtype_coe : Measurable + (Subtype.val : NumberTheoryLean.TransitionKernels.OddState → ℝ))).aestronglyMeasurable + simp only [Function.comp_def] at he ho + rw [evenStateMeasure, he, oddStateMeasure, ho, integral_evenMeasure, integral_oddMeasure] + simp_rw [even_lifted_cost, odd_lifted_cost] + rfl + +theorem occupation_increment_integrable : + Integrable (fun y : CostState ↦ stateCost y.1) occupationMeasure := + (integrable_state_occupation_iff stateCost_measurable).mp (stateCost_integrable stateMeasure) + +theorem occupation_increment_integral : + (∫ y : CostState, stateCost y.1 ∂occupationMeasure) = costMass / beta := by + have h := (integral_state_occupation stateCost_measurable occupation_increment_integrable).2 + rw [state_cost_integral] at h + simpa only [one_div, div_eq_mul_inv, mul_comm, mul_one, one_mul] using h + +end Erdos970Dependency.RawStateCost + +end + +section + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal ProbabilityTheory +namespace Erdos970Dependency.OnePairCost +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathGeometry NumberTheoryLean.FinitePathMeasures +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw NumberTheoryLean.CycleOccupation +open Erdos970Dependency.RawStateCost + +noncomputable def pairIncrement (z : OddCost) : ℝ≥0∞ := + ∫⁻ y : CostState, ENNReal.ofReal (stateCost y.1) ∂pairVisits z + +theorem increment_test_measurable : Measurable (fun y : CostState ↦ ENNReal.ofReal (stateCost y.1)) := + ENNReal.measurable_ofReal.comp (stateCost_measurable.comp measurable_fst) + +theorem age_test_measurable : Measurable (fun y : OddCost ↦ ENNReal.ofReal y.2) := + ENNReal.measurable_ofReal.comp measurable_snd + +theorem pairIncrement_measurable : Measurable pairIncrement := increment_test_measurable.lintegral_kernel + +theorem even_increment_measurable : + Measurable (fun x : EvenState × OddState ↦ ENNReal.ofReal (cost x.1.1)) := + ENNReal.measurable_ofReal.comp (cost_measurable.comp (measurable_subtype_coe.comp measurable_fst)) + +theorem odd_increment_measurable : + Measurable (fun x : EvenState × OddState ↦ ENNReal.ofReal (cost x.2.1)) := + ENNReal.measurable_ofReal.comp (cost_measurable.comp (measurable_subtype_coe.comp measurable_snd)) + +theorem pairIncrement_formula (z : OddCost) : pairIncrement z = + ∫⁻ x : EvenState × OddState, + ENNReal.ofReal (cost x.1.1) + ENNReal.ofReal (cost x.2.1) ∂pairedDraws z.1 := by + rw [pairIncrement, pairVisits, add_apply, lintegral_add_measure, + evenVisit, sampling_map_measure _ evenVisitMap_measurable, + oddVisit, sampling_map_measure _ oddVisitMap_measurable, + lintegral_map (g := fun x : EvenState × OddState ↦ evenVisitMap (z, x)) + increment_test_measurable (evenVisitMap_measurable.comp measurable_prodMk_left), + lintegral_map (g := fun x : EvenState × OddState ↦ oddVisitMap (z, x)) + increment_test_measurable (oddVisitMap_measurable.comp measurable_prodMk_left)] + change (∫⁻ x : EvenState × OddState, ENNReal.ofReal (cost x.1.1) ∂pairedDraws z.1) + + (∫⁻ x : EvenState × OddState, ENNReal.ofReal (cost x.2.1) ∂pairedDraws z.1) = _ + exact (lintegral_add_left even_increment_measurable _).symm + +theorem paired_age_balance (z : OddCost) (hz : 0 ≤ z.2) : + (∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂pairedCostKernel z) = ENNReal.ofReal z.2 + pairIncrement z := by + have hK : pairedCostKernel = pairSampling.map pairUpdate := rfl + rw [hK, sampling_map_measure _ pairUpdate_measurable, + lintegral_map (g := fun x : EvenState × OddState ↦ pairUpdate (z, x)) age_test_measurable + (pairUpdate_measurable.comp measurable_prodMk_left)] + change (∫⁻ x : EvenState × OddState, ENNReal.ofReal (z.2 + cost x.1.1 + cost x.2.1) ∂pairedDraws z.1) = _ + have hp (x : EvenState × OddState) : + ENNReal.ofReal (z.2 + cost x.1.1 + cost x.2.1) = + ENNReal.ofReal z.2 + (ENNReal.ofReal (cost x.1.1) + ENNReal.ofReal (cost x.2.1)) := by + have he : 0 ≤ cost x.1.1 := (cost_pos (by linarith [x.1.2])).le + have ho : 0 ≤ cost x.2.1 := (cost_pos (by linarith [x.2.2])).le + rw [ENNReal.ofReal_add (add_nonneg hz he) ho, ENNReal.ofReal_add hz he, add_assoc] + simp_rw [hp] + rw [lintegral_add_left measurable_const, lintegral_const, measure_univ, mul_one, pairIncrement_formula] + +theorem captured_killed_age_balance (z : OddCost) (hz : 0 ≤ z.2) : + (∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂costCaptured z) + + (∫⁻ y : OddCost, ENNReal.ofReal y.2 ∂costKilled z) = ENNReal.ofReal z.2 + pairIncrement z := by + rw [← lintegral_add_measure] + have h := congrArg (fun K : Kernel OddCost OddCost ↦ K z) costCaptured_add_costKilled + rw [add_apply] at h + rw [h] + exact paired_age_balance z hz + +end Erdos970Dependency.OnePairCost + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/OriginalPairMembership.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OriginalPairMembership.lean new file mode 100644 index 0000000000000000000000000000000000000000..7942cbe39cff2c519b266e0131c25b0e66a4fb74 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/OriginalPairMembership.lean @@ -0,0 +1,60 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.FullPatternCongruences + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceLargeMap +open ErdosVarianceSmallModel ErdosHyperbolaError +attribute [local instance] Classical.propDecidable + +theorem mem_open_closed_integer_interval (x y : ℝ) (n : ℤ) : + n ∈ realIntervalIntegers x y false true ↔ x < (n : ℝ) ∧ (n : ℝ) ≤ y := by + simp only [realIntervalIntegers,Finset.mem_filter,Finset.mem_Icc,Int.ceil_le,Int.le_floor, + Bool.false_eq_true,ite_false,ite_true] + constructor + · exact fun h => h.2 + · exact fun h => ⟨⟨h.1.le,h.2⟩,h⟩ + +theorem mem_closed_open_integer_interval (x y : ℝ) (n : ℤ) : + n ∈ realIntervalIntegers x y true false ↔ x ≤ (n : ℝ) ∧ (n : ℝ) < y := by + simp only [realIntervalIntegers,Finset.mem_filter,Finset.mem_Icc,Int.ceil_le,Int.le_floor, + Bool.false_eq_true,ite_false,ite_true] + constructor + · exact fun h => h.2 + · exact fun h => ⟨⟨h.1,h.2.le⟩,h⟩ + +theorem original_pair_mem_sourcePairs (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) (p : goodPrimes P H) + (x0 x1 y0 y1 : ℝ) (hp : x0 < (p.val : ℝ) ∧ (p.val : ℝ) ≤ x1) + (hm : y0 ≤ (primeM P H C0 hP p : ℝ) ∧ (primeM P H C0 hP p : ℝ) < y1) : + let v := actualFullPattern P w H C0 hw hP hlarge p + ((p.val : ℤ),primeM P H C0 hP p) ∈ + sourcePairs H (divisorModulus w H) (coprimeModulus w H) C0 (v.2.1.val : ℤ) + (v.1.val.val : ℤ) (v.2.2.1.val.val : ℤ) (v.2.2.2.val : ℤ) 1 x0 x1 y0 y1 false true true false := by + dsimp only + have hres := full_pattern_residue_congruences P w H C0 hw hP hlarge p + have hprod := full_pattern_product_congruence P w H C0 hw hP hlarge p + unfold sourcePairs + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_product.mpr ⟨?_,?_⟩,by simp only [Nat.cast_one,one_dvd,true_and];exact ⟨hres.1,hres.2.1,hres.2.2,hprod⟩⟩ + · exact (mem_open_closed_integer_interval x0 x1 (p.val : ℤ)).mpr (by exact_mod_cast hp) + · exact (mem_closed_open_integer_interval y0 y1 (primeM P H C0 hP p)).mpr hm + +theorem original_prime_pair_injective (P : Finset ℕ) (H : ℕ) (C0 : ℤ) (hP : ∀ p ∈ P,p.Prime) : + Function.Injective (fun p : goodPrimes P H => ((p.val : ℤ),primeM P H C0 hP p)) := by + intro p q he + apply Subtype.ext + have hh : (p.val : ℤ) = (q.val : ℤ) := congrArg Prod.fst he + exact Int.ofNat.inj hh + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PVIdentity.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PVIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e55577b743f2ea8bd058d452e7d476879e122b1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PVIdentity.lean @@ -0,0 +1,402 @@ +/- +This file has been adapted from an external source. +An attribution header has been generated because the source file did not contain a copyright header. +The applicable license information is stated below. +-/ + +/- +Generated attribution header: the source file did not contain a copyright header. +This file is adapted from PrimeNumberTheoremAnd.IEANTN.PVIdentity. +Source: https://github.com/AlexKontorovich/PrimeNumberTheoremAnd/blob/c39a751132c88b6e8080b74c74023fd95b3d8be0/PrimeNumberTheoremAnd/IEANTN/PVIdentity.lean +License: Apache License 2.0. + +This code has been modified. +-/ + +import Mathlib.Algebra.Order.Star.Real +import Mathlib.MeasureTheory.Integral.Gamma +import Mathlib.NumberTheory.Harmonic.GammaDeriv + +namespace OAI + +namespace Erdos970 + +section + +open Real Set MeasureTheory Filter Topology Finset +open scoped NNReal ENNReal + +lemma integral_exp_div_neg_eq {ε : ℝ} (hε : 0 < ε) : + ∫ u in (-1/ε)..(-ε), exp u / u = -(∫ t in ε..(1/ε), exp (-t) / t) := by + have _ := hε + have h_subst : ∫ u in (-1 / ε)..(-ε), Real.exp u / u = ∫ t in (ε : ℝ)..1 / ε, Real.exp (-t) / (-t) := by + have h_sub : ∀ a b : ℝ, ∫ u in a..b, Real.exp u / u = ∫ t in (-b)..(-a), Real.exp (-t) / (-t) := by + norm_num [ ← intervalIntegral.integral_comp_neg ] + grind; + simpa [ div_neg ] using h_subst + +lemma integral_exp_div_split {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) : + ∫ u in a..b, exp u / u = (∫ u in a..b, (exp u - 1) / u) + (log b - log a) := by + simp +decide [ sub_div ]; + rw [ intervalIntegral.integral_sub ]; + · rw [ integral_inv_of_pos, Real.log_div ] <;> linarith; + · exact ContinuousOn.intervalIntegrable ( by exact continuousOn_of_forall_continuousAt fun u hu => ContinuousAt.div ( Real.continuous_exp.continuousAt ) continuousAt_id <| by linarith [ Set.mem_Icc.mp <| by simpa [ hab ] using hu ] ) ..; + · apply_rules [ ContinuousOn.intervalIntegrable ]; + exact continuousOn_of_forall_continuousAt fun x hx => ContinuousAt.inv₀ continuousAt_id ( by cases Set.mem_uIcc.mp hx <;> linarith ) + +lemma integrableOn_one_sub_exp_neg_div : + IntegrableOn (fun t => (1 - exp (-t)) / t) (Ioc 0 1) := by + + have h_bound : ∀ t ∈ Set.Ioc 0 1, (1 - Real.exp (-t)) / t ≤ 1 := by + exact fun t ht => by rw [ div_le_iff₀ ht.1 ] ; linarith [ Real.add_one_le_exp ( -t ) ] ; + refine' MeasureTheory.Integrable.mono' _ _ _; + exacts [ fun t => 1, by norm_num, by exact Measurable.aestronglyMeasurable ( by exact Measurable.div ( measurable_const.sub ( Real.continuous_exp.measurable.comp ( measurable_neg ) ) ) measurable_id' ), Filter.eventually_of_mem ( MeasureTheory.ae_restrict_mem measurableSet_Ioc ) fun t ht => by rw [ Real.norm_of_nonneg ( div_nonneg ( sub_nonneg.2 <| Real.exp_le_one_iff.2 <| by linarith [ ht.1, ht.2 ] ) ht.1.le ) ] ; exact h_bound t ht ] + +lemma integrableOn_exp_neg_div_Ioi : + IntegrableOn (fun t => exp (-t) / t) (Ioi 1) := by + + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => Real.exp (-t)) (Set.Ioi 1) := by + exact MeasureTheory.IntegrableOn.mono_set ( by exact MeasureTheory.integrable_of_integral_eq_one ( by simpa using integral_exp_neg_Ioi_zero ) ) ( Set.Ioi_subset_Ioi zero_le_one ); + refine' h_integrable.mono' _ _; + · exact ContinuousOn.aestronglyMeasurable ( fun t ht => ContinuousAt.continuousWithinAt ( by exact ContinuousAt.div ( ContinuousAt.rexp ( continuousAt_id.neg ) ) continuousAt_id ( by linarith [ ht.out ] ) ) ) measurableSet_Ioi; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with x hx using by rw [ Real.norm_of_nonneg ( div_nonneg ( Real.exp_pos _ |> le_of_lt ) ( by linarith [ hx.out ] ) ) ] ; exact div_le_self ( Real.exp_pos _ |> le_of_lt ) ( by linarith [ hx.out ] ) ; + +lemma integrableOn_exp_sub_one_div {y : ℝ} (hy : 0 < y) : + IntegrableOn (fun u => (exp u - 1) / u) (Ioc 0 y) := by + have _ := hy + have h_bounded : ∀ u ∈ Set.Ioc 0 y, |(Real.exp u - 1) / u| ≤ Real.exp y := by + norm_num [ abs_div ]; + intro u hu huy; rw [ abs_of_nonneg ( sub_nonneg_of_le ( Real.one_le_exp hu.le ) ), abs_of_nonneg hu.le ] ; rw [ div_le_iff₀ hu ] ; nlinarith [ Real.exp_pos u, Real.exp_le_exp.2 huy, Real.exp_neg u, mul_inv_cancel₀ ( ne_of_gt ( Real.exp_pos u ) ), Real.add_one_le_exp u, Real.add_one_le_exp ( -u ) ] ; + refine' MeasureTheory.Integrable.mono' _ _ _; + exacts [ fun u => Real.exp y, by norm_num, by exact Measurable.aestronglyMeasurable ( by exact Measurable.div ( Real.continuous_exp.measurable.sub measurable_const ) measurable_id' ), Filter.eventually_of_mem ( MeasureTheory.ae_restrict_mem measurableSet_Ioc ) fun u hu => h_bounded u hu ] + +lemma tendsto_integral_one_sub_exp_neg_div : + Tendsto (fun ε => ∫ t in ε..1, (1 - exp (-t)) / t) + (𝓝[>] (0 : ℝ)) (𝓝 (∫ t in (0:ℝ)..1, (1 - exp (-t)) / t)) := by + + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => (1 - Real.exp (-t)) / t) (Set.Ioc 0 1) := by + exact integrableOn_one_sub_exp_neg_div; + + have h_cont : ContinuousOn (fun ε => ∫ t in (ε)..1, (1 - Real.exp (-t)) / t) (Set.Icc 0 1) := by + have h_cont : ContinuousOn (fun ε => ∫ t in (1 : ℝ)..ε, (1 - Real.exp (-t)) / t) (Set.Icc 0 1) := by + intro ε hε; apply_rules [ intervalIntegral.continuousWithinAt_primitive ] ; aesop; + rw [ intervalIntegrable_iff_integrableOn_Ioc_of_le ] <;> aesop; + exact ContinuousOn.congr ( h_cont.fun_neg ) fun x hx => by rw [ ← intervalIntegral.integral_symm ] ; + have := h_cont 0 ( by norm_num ); + convert this.tendsto.mono_left _ using 2 ; norm_num [ Set.Ioi_subset_Ici_self ]; + exact nhdsWithin_mono _ <| Set.Ioi_subset_Ici_self + +lemma tendsto_integral_exp_neg_div_Ioi : + Tendsto (fun ε => ∫ t in (1:ℝ)..(1/ε), exp (-t) / t) + (𝓝[>] (0 : ℝ)) (𝓝 (∫ t in Ioi (1:ℝ), exp (-t) / t)) := by + + simp at * ; have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => Real.exp (-t) / t) (Set.Ioi 1) := by + exact integrableOn_exp_neg_div_Ioi; + apply_rules [ MeasureTheory.intervalIntegral_tendsto_integral_Ioi ]; + norm_num [ Filter.Tendsto ] + +lemma tendsto_integral_exp_sub_one_div {y : ℝ} (hy : 0 < y) : + Tendsto (fun ε => ∫ u in ε..y, (exp u - 1) / u) + (𝓝[>] (0 : ℝ)) (𝓝 (∫ u in (0:ℝ)..y, (exp u - 1) / u)) := by + + have h_integrable : MeasureTheory.IntegrableOn (fun u => (Real.exp u - 1) / u) (Set.Ioc 0 y) := by + exact integrableOn_exp_sub_one_div hy; + + obtain ⟨M, hM⟩ : ∃ M > y, True := by + exact ⟨ y + 1, by linarith, trivial ⟩; + + have h_cont : ContinuousOn (fun ε => ∫ u in ε..y, (Real.exp u - 1) / u) (Set.Icc 0 M) := by + have h_integrable_M : MeasureTheory.IntegrableOn (fun u => (Real.exp u - 1) / u) (Set.Ioc 0 M) := by + have h_integrable_M : MeasureTheory.IntegrableOn (fun u => (Real.exp u - 1) / u) (Set.Ioc y M) := by + exact ContinuousOn.integrableOn_Icc ( by exact continuousOn_of_forall_continuousAt fun u hu => ContinuousAt.div ( ContinuousAt.sub ( Real.continuous_exp.continuousAt ) continuousAt_const ) continuousAt_id <| by linarith [ hu.1 ] ) |> fun h => h.mono_set <| Set.Ioc_subset_Icc_self; + convert h_integrable.union h_integrable_M using 1 ; rw [ Set.Ioc_union_Ioc_eq_Ioc ] <;> linarith; + have h_cont : ContinuousOn (fun ε => ∫ u in (y)..ε, (Real.exp u - 1) / u) (Set.Icc 0 M) := by + intro ε hε; apply_rules [ intervalIntegral.continuousWithinAt_primitive ] ; aesop; + rw [ min_eq_right hy.le, max_eq_right hM.1.le ] ; rw [ intervalIntegrable_iff_integrableOn_Ioc_of_le ( by linarith ) ] ; aesop; + exact ContinuousOn.congr ( h_cont.fun_neg ) fun x hx => by rw [ ← intervalIntegral.integral_symm ] ; + have := h_cont 0 ⟨ by norm_num, by linarith ⟩; + convert this.tendsto.mono_left _ using 2; + norm_num [ nhdsWithin, Filter.mem_inf_principal ]; + exact Filter.eventually_of_mem ( Iio_mem_nhds <| show 0 < M by linarith ) fun x hx => fun hx' => ⟨ le_of_lt hx', le_of_lt hx ⟩ + +lemma eulerMascheroni_eq_integral : + eulerMascheroniConstant = + (∫ t in (0:ℝ)..1, (1 - exp (-t)) / t) - ∫ t in Ioi (1:ℝ), exp (-t) / t := by + + have h_gamma_deriv : Real.eulerMascheroniConstant = -∫ t in Set.Ioi 0, Real.exp (-t) * Real.log t := by + have h_gamma_deriv : deriv Real.Gamma 1 = ∫ t in Set.Ioi 0, Real.exp (-t) * Real.log t := by + + have h_gamma_deriv : deriv Real.Gamma 1 = ∫ t in Set.Ioi 0, t^0 * Real.exp (-t) * Real.log t := by + have h_def : ∀ s > 0, Real.Gamma s = ∫ t in Set.Ioi 0, t^(s-1) * Real.exp (-t) := by + exact fun s hs => by rw [ Real.Gamma_eq_integral hs ] ; congr; ext; ring; + + have h_dominated : Filter.Tendsto (fun h => ∫ t in Set.Ioi 0, (t^h - 1) / h * Real.exp (-t)) (nhdsWithin 0 (Set.Ioi 0)) (nhds (∫ t in Set.Ioi 0, Real.log t * Real.exp (-t))) := by + + have h_dominate : ∀ h ∈ Set.Ioo 0 1, ∀ t ∈ Set.Ioi 0, abs ((t^h - 1) / h * Real.exp (-t)) ≤ abs (Real.log t) * Real.exp (-t) * (t + 1) := by + intros h hh t ht + have h_abs : abs ((t^h - 1) / h) ≤ abs (Real.log t) * (t + 1) := by + + obtain ⟨c, hc⟩ : ∃ c ∈ Set.Ioo 0 h, t^h - 1 = h * t^c * Real.log t := by + + have h_mean_value : ∃ c ∈ Set.Ioo 0 h, deriv (fun x => t^x) c = (t^h - 1) / h := by + have := exists_deriv_eq_slope ( f := fun x => t ^ x ) hh.1; + simpa using this ( continuousOn_of_forall_continuousAt fun x hx => by exact ContinuousAt.rpow continuousAt_const continuousAt_id <| Or.inl <| by linarith [ ht.out ] ) ( fun x hx => by exact DifferentiableAt.differentiableWithinAt <| by exact DifferentiableAt.rpow ( differentiableAt_const _ ) differentiableAt_id <| by linarith [ ht.out ] ); + norm_num [ Real.rpow_def_of_pos ht, mul_assoc, mul_comm, mul_left_comm ] at *; + exact h_mean_value.imp fun x hx => ⟨ hx.1, by rw [ hx.2, mul_div_cancel₀ _ hh.1.ne' ] ⟩; + by_cases h_zero : h = 0 <;> simp_all +decide [ abs_mul, mul_assoc, mul_comm ]; + by_cases h₂ : t ≤ 1; + · exact mul_le_mul_of_nonneg_right ( by rw [ abs_of_nonneg ( Real.rpow_nonneg ht.le _ ) ] ; exact le_trans ( Real.rpow_le_one ht.le h₂ ( by linarith ) ) ( by linarith ) ) ( abs_nonneg _ ); + · exact mul_le_mul_of_nonneg_right ( by rw [ abs_of_nonneg ( Real.rpow_nonneg ht.le _ ) ] ; exact le_trans ( Real.rpow_le_rpow_of_exponent_le ( by linarith ) ( show c ≤ 1 by linarith ) ) ( by norm_num ) ) ( abs_nonneg _ ); + rw [ abs_mul, abs_of_nonneg ( Real.exp_pos _ |> LT.lt.le ) ] ; nlinarith [ Real.exp_pos ( -t ) ]; + + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => abs (Real.log t) * Real.exp (-t) * (t + 1)) (Set.Ioi 0) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => abs (Real.log t) * Real.exp (-t) * t) (Set.Ioi 0) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t * Real.exp (-t) * abs (Real.log t)) (Set.Ioi 0) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t * Real.exp (-t) * abs (Real.log t)) (Set.Ioc 0 1) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t * abs (Real.log t)) (Set.Ioc 0 1) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t * Real.log t) (Set.Ioc 0 1) := by + exact Continuous.integrableOn_Ioc ( Real.continuous_mul_log ); + refine' h_integrable.norm.congr _; + filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioc ] with t ht using by rw [ Real.norm_eq_abs, abs_mul, abs_of_nonneg ht.1.le ] ; + refine' h_integrable.mono' _ _; + · exact MeasureTheory.AEStronglyMeasurable.mul ( MeasureTheory.AEStronglyMeasurable.mul ( measurable_id.aestronglyMeasurable ) ( Real.continuous_exp.comp_aestronglyMeasurable ( measurable_neg.aestronglyMeasurable ) ) ) ( Real.measurable_log.norm.aestronglyMeasurable ); + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioc ] with t ht using by rw [ Real.norm_of_nonneg ( mul_nonneg ( mul_nonneg ht.1.le ( Real.exp_nonneg _ ) ) ( abs_nonneg _ ) ) ] ; exact mul_le_mul_of_nonneg_right ( mul_le_of_le_one_right ht.1.le ( Real.exp_le_one_iff.mpr ( neg_nonpos.mpr ht.1.le ) ) ) ( abs_nonneg _ ) ; + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t * Real.exp (-t) * abs (Real.log t)) (Set.Ioi 1) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t * Real.exp (-t) * t) (Set.Ioi 1) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t^2 * Real.exp (-t)) (Set.Ioi 1) := by + have h_gamma : ∫ t in Set.Ioi 0, t^2 * Real.exp (-t) = Real.Gamma 3 := by + rw [ h_def ] <;> norm_num; + exact MeasureTheory.IntegrableOn.mono_set ( by exact ( by contrapose! h_gamma; rw [ MeasureTheory.integral_undef h_gamma ] ; positivity ) ) ( Set.Ioi_subset_Ioi zero_le_one ); + exact h_integrable.congr_fun ( fun x hx => by ring ) measurableSet_Ioi; + refine' h_integrable.mono' _ _; + · exact Measurable.aestronglyMeasurable ( by exact Measurable.mul ( measurable_id.mul ( Real.continuous_exp.measurable.comp measurable_neg ) ) ( Real.measurable_log.norm ) ); + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with t ht using by rw [ Real.norm_of_nonneg ( mul_nonneg ( mul_nonneg ( by linarith [ ht.out ] ) ( Real.exp_nonneg _ ) ) ( abs_nonneg _ ) ) ] ; exact mul_le_mul_of_nonneg_left ( by rw [ abs_of_nonneg ( Real.log_nonneg ( by linarith [ ht.out ] ) ) ] ; exact le_trans ( Real.log_le_sub_one_of_pos ( by linarith [ ht.out ] ) ) ( by linarith [ ht.out ] ) ) ( mul_nonneg ( by linarith [ ht.out ] ) ( Real.exp_nonneg _ ) ) ; + convert MeasureTheory.IntegrableOn.union ‹IntegrableOn ( fun t : ℝ => t * Real.exp ( -t ) * |log t| ) ( Set.Ioc 0 1 ) volume› ‹IntegrableOn ( fun t : ℝ => t * Real.exp ( -t ) * |log t| ) ( Set.Ioi 1 ) volume› using 1 ; norm_num; + exact h_integrable.congr_fun ( fun x hx => by ring ) measurableSet_Ioi; + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => abs (Real.log t) * Real.exp (-t)) (Set.Ioi 0) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => abs (Real.log t) * Real.exp (-t)) (Set.Ioc 0 1) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => abs (Real.log t)) (Set.Ioc 0 1) := by + have h_integrable : ∫ t in Set.Ioc 0 1, abs (Real.log t) = 1 := by + rw [ MeasureTheory.setIntegral_congr_fun measurableSet_Ioc fun x hx => abs_of_nonpos ( Real.log_nonpos hx.1.le hx.2 ), ← intervalIntegral.integral_of_le ] <;> norm_num; + exact ( by contrapose! h_integrable; rw [ MeasureTheory.integral_undef h_integrable ] ; norm_num ); + refine' h_integrable.mono' _ _; + · exact MeasureTheory.AEStronglyMeasurable.mul ( h_integrable.aestronglyMeasurable ) ( Continuous.aestronglyMeasurable ( by continuity ) ); + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioc ] with t ht using by simpa [ abs_mul ] using mul_le_mul_of_nonneg_left ( Real.exp_le_one_iff.mpr <| neg_nonpos.mpr ht.1.le ) <| abs_nonneg <| Real.log t; + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => abs (Real.log t) * Real.exp (-t)) (Set.Ioi 1) := by + have h_integrable : MeasureTheory.IntegrableOn (fun t : ℝ => t * Real.exp (-t)) (Set.Ioi 1) := by + have := @integral_rpow_mul_exp_neg_rpow 1; + specialize @this 1 ; norm_num at this; + exact MeasureTheory.IntegrableOn.mono_set ( by exact ( by exact ( by exact ( by exact ( by exact ( by exact by contrapose! this; rw [ MeasureTheory.integral_undef this ] ; norm_num ) ) ) ) ) ) ( Set.Ioi_subset_Ioi zero_le_one ); + refine' h_integrable.mono' _ _; + · exact Measurable.aestronglyMeasurable ( by exact Measurable.mul ( Real.measurable_log.norm ) ( Real.continuous_exp.measurable.comp measurable_neg ) ); + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with t ht using by rw [ Real.norm_of_nonneg ( by positivity ) ] ; exact mul_le_mul_of_nonneg_right ( by rw [ abs_of_nonneg ( Real.log_nonneg ht.out.le ) ] ; exact le_trans ( Real.log_le_sub_one_of_pos ( by linarith [ ht.out ] ) ) ( by linarith [ ht.out ] ) ) ( by positivity ) ; + convert MeasureTheory.IntegrableOn.union ‹IntegrableOn ( fun t : ℝ => |Real.log t| * Real.exp ( -t ) ) ( Set.Ioc 0 1 ) volume› ‹IntegrableOn ( fun t : ℝ => |Real.log t| * Real.exp ( -t ) ) ( Set.Ioi 1 ) volume› using 1 ; norm_num; + simp_all +decide [ mul_add ]; + exact MeasureTheory.Integrable.add ‹_› ‹_›; + refine' MeasureTheory.tendsto_integral_filter_of_dominated_convergence _ _ _ _ _; + refine' fun t => |Real.log t| * Real.exp ( -t ) * ( t + 1 ); + · filter_upwards [ self_mem_nhdsWithin ] with n hn using Measurable.aestronglyMeasurable ( by exact Measurable.mul ( Measurable.div_const ( by exact Measurable.sub ( measurable_id.pow_const _ ) measurable_const ) _ ) ( Real.continuous_exp.measurable.comp measurable_neg ) ); + · filter_upwards [ Ioo_mem_nhdsGT zero_lt_one ] with h hh using Filter.eventually_of_mem ( MeasureTheory.ae_restrict_mem measurableSet_Ioi ) fun t ht => h_dominate h hh t ht; + · exact h_integrable; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with t ht; + refine' Filter.Tendsto.mul _ tendsto_const_nhds; + simpa [ div_eq_inv_mul, Real.rpow_def_of_pos ht ] using HasDerivAt.tendsto_slope_zero_right ( HasDerivAt.sub ( HasDerivAt.exp ( HasDerivAt.const_mul ( Real.log t ) ( hasDerivAt_id 0 ) ) ) ( hasDerivAt_const 0 1 ) ); + + have h_deriv : Filter.Tendsto (fun h => (Real.Gamma (1 + h) - Real.Gamma 1) / h) (nhdsWithin 0 (Set.Ioi 0)) (nhds (deriv Real.Gamma 1)) := by + have h_deriv : HasDerivAt Real.Gamma (deriv Real.Gamma 1) 1 := by + exact DifferentiableAt.hasDerivAt ( Real.differentiableAt_Gamma fun m => by linarith ); + simpa [ div_eq_inv_mul ] using h_deriv.tendsto_slope_zero_right; + + have h_gamma_def : ∀ h > 0, (Real.Gamma (1 + h) - Real.Gamma 1) / h = ∫ t in Set.Ioi 0, (t^h - 1) / h * Real.exp (-t) := by + intro h hh; rw [ h_def ( 1 + h ) ( by linarith ), h_def 1 zero_lt_one ] ; simp +decide [ sub_mul, div_mul_eq_mul_div, MeasureTheory.integral_div ] ; + rw [ MeasureTheory.integral_sub ] <;> norm_num [ integral_exp_Iic ]; + · have := @integral_rpow_mul_exp_neg_rpow 1; + exact ( by have := @this h ( by norm_num ) ( by linarith ) ; exact ( by contrapose! this; rw [ MeasureTheory.integral_undef ( by aesop ) ] ; positivity ) ); + · exact MeasureTheory.integrable_of_integral_eq_one ( by simpa using integral_exp_neg_Ioi_zero ); + simpa [ mul_assoc, mul_comm, mul_left_comm ] using tendsto_nhds_unique h_deriv ( h_dominated.congr' <| Filter.eventuallyEq_of_mem self_mem_nhdsWithin fun x hx => h_gamma_def x hx ▸ rfl ); + aesop; + rw [ ← h_gamma_deriv, Real.eulerMascheroniConstant_eq_neg_deriv ]; + + have h_split : ∫ t in Set.Ioi 0, Real.exp (-t) * Real.log t = (∫ t in Set.Ioc 0 1, Real.exp (-t) * Real.log t) + (∫ t in Set.Ioi 1, Real.exp (-t) * Real.log t) := by + rw [ ← MeasureTheory.setIntegral_union ] <;> norm_num; + · have h_integrable : MeasureTheory.IntegrableOn (fun t => Real.log t) (Set.Ioc 0 1) := by + rw [ ← intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one ]; + norm_num +zetaDelta at *; + refine' h_integrable.norm.mono' _ _; + · exact MeasureTheory.AEStronglyMeasurable.mul ( Continuous.aestronglyMeasurable ( by continuity ) ) h_integrable.aestronglyMeasurable; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioc ] with x hx using by rw [ norm_mul, Real.norm_of_nonneg ( Real.exp_pos _ |> le_of_lt ) ] ; exact mul_le_of_le_one_left ( norm_nonneg _ ) ( Real.exp_le_one_iff.mpr <| by linarith [ hx.1, hx.2 ] ) ; + · + have h_conv : MeasureTheory.IntegrableOn (fun t : ℝ => Real.exp (-t) * t) (Set.Ioi 1) := by + have h_integrable : ∫ t in Set.Ioi 0, Real.exp (-t) * t = Real.Gamma 2 := by + rw [ Real.Gamma_eq_integral ] <;> norm_num; + exact MeasureTheory.IntegrableOn.mono_set ( by exact ( by contrapose! h_integrable; rw [ MeasureTheory.integral_undef h_integrable ] ; positivity ) ) ( Set.Ioi_subset_Ioi zero_le_one ); + refine' h_conv.mono' _ _; + · exact ContinuousOn.aestronglyMeasurable ( fun t ht => ContinuousAt.continuousWithinAt ( by exact ContinuousAt.mul ( ContinuousAt.rexp ( continuousAt_id.neg ) ) ( Real.continuousAt_log ( by linarith [ ht.out ] ) ) ) ) measurableSet_Ioi; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with t ht using by rw [ Real.norm_eq_abs, abs_of_nonneg ( mul_nonneg ( Real.exp_pos _ |> le_of_lt ) ( Real.log_nonneg ht.out.le ) ) ] ; exact mul_le_mul_of_nonneg_left ( le_trans ( Real.log_le_sub_one_of_pos ( zero_lt_one.trans ht.out ) ) ( by linarith ) ) ( Real.exp_pos _ |> le_of_lt ) ; + + have h_log_zero_one : ∫ t in Set.Ioc 0 1, Real.exp (-t) * Real.log t = -∫ t in Set.Ioc 0 1, ∫ s in t..1, Real.exp (-t) / s := by + have h_log_zero_one : ∀ t ∈ Set.Ioc 0 1, Real.log t = -∫ s in t..1, 1 / s := by + intro t ht; rw [ integral_one_div_of_pos ] <;> aesop; + rw [ ← MeasureTheory.integral_neg ] ; exact MeasureTheory.setIntegral_congr_fun measurableSet_Ioc fun x hx => by rw [ h_log_zero_one x hx ] ; simp +decide [ div_eq_mul_inv, mul_comm ] ; + + have h_fubini : ∫ t in Set.Ioc 0 1, ∫ s in t..1, Real.exp (-t) / s = ∫ s in Set.Ioc 0 1, ∫ t in Set.Ioc 0 s, Real.exp (-t) / s := by + have h_fubini : ∫ t in Set.Ioc 0 1, ∫ s in t..1, Real.exp (-t) / s = ∫ t in Set.Ioc 0 1, ∫ s in Set.Ioc 0 1, (if t ≤ s then Real.exp (-t) / s else 0) := by + refine' MeasureTheory.setIntegral_congr_fun measurableSet_Ioc fun t ht => _; + rw [ ← MeasureTheory.integral_indicator ] <;> norm_num [ Set.indicator ]; + rw [ intervalIntegral.integral_of_le ht.2 ]; + rw [ ← MeasureTheory.integral_Icc_eq_integral_Ioc, ← MeasureTheory.integral_indicator ] <;> norm_num [ Set.indicator ]; + grind; + rw [ h_fubini, ← MeasureTheory.integral_integral_swap ]; + · norm_num [ ← MeasureTheory.integral_indicator, Set.indicator_apply ]; + grind +splitImp; + · rw [ MeasureTheory.integrable_prod_iff ]; + · field_simp; + constructor; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioc ] with x hx; + refine' MeasureTheory.Integrable.indicator _ _; + · exact Continuous.integrableOn_Ioc ( by exact Continuous.div_const ( Real.continuous_exp.comp <| ContinuousNeg.continuous_neg ) _ ); + · exact measurableSet_Iic; + · refine' MeasureTheory.Integrable.congr _ _; + use fun x => ∫ y in Set.Ioc 0 x, Real.exp ( -y ) / x; + · + have h_inner : ∀ x ∈ Set.Ioc 0 1, ∫ y in Set.Ioc 0 x, Real.exp (-y) / x = (1 - Real.exp (-x)) / x := by + intro x hx; rw [ ← intervalIntegral.integral_of_le hx.1.le ] ; norm_num [ intervalIntegral.integral_comp_neg ] ; + rw [ MeasureTheory.integrable_congr ( Filter.eventuallyEq_of_mem ( MeasureTheory.ae_restrict_mem measurableSet_Ioc ) fun x hx => h_inner x hx ) ]; + refine' MeasureTheory.Integrable.mono' _ _ _; + refine' fun x => 1; + · norm_num; + · exact ContinuousOn.aestronglyMeasurable ( fun x hx => ContinuousAt.continuousWithinAt ( by exact ContinuousAt.div ( continuousAt_const.sub ( Real.continuous_exp.continuousAt.comp ( ContinuousAt.neg continuousAt_id ) ) ) continuousAt_id ( ne_of_gt hx.1 ) ) ) measurableSet_Ioc; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioc ] with x hx using by rw [ Real.norm_of_nonneg ( div_nonneg ( sub_nonneg.2 <| Real.exp_le_one_iff.2 <| by linarith [ hx.1, hx.2 ] ) hx.1.le ) ] ; exact div_le_one_of_le₀ ( by linarith [ hx.1, hx.2, Real.add_one_le_exp ( -x ) ] ) hx.1.le; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioc ] with x hx; + rw [ ← MeasureTheory.integral_indicator, ← MeasureTheory.integral_indicator ] <;> norm_num [ Set.indicator ]; + congr with y ; split_ifs <;> norm_num; + · rw [ abs_of_nonneg ( div_nonneg ( Real.exp_nonneg _ ) hx.1.le ) ]; + · grind +revert; + · grind; + · aesop; + · exact Measurable.aestronglyMeasurable ( by exact Measurable.ite ( measurableSet_le measurable_snd measurable_fst ) ( by exact Measurable.div ( Real.continuous_exp.measurable.comp ( measurable_neg.comp measurable_snd ) ) measurable_fst ) measurable_const ); + + have h_log_one_infty : ∫ t in Set.Ioi 1, Real.exp (-t) * Real.log t = ∫ t in Set.Ioi 1, ∫ s in (1 : ℝ)..t, Real.exp (-t) / s := by + refine' MeasureTheory.setIntegral_congr_fun measurableSet_Ioi fun t ht => _; + norm_num [ div_eq_mul_inv, ht.out.le ]; + + have h_fubini_one_infty : ∫ t in Set.Ioi 1, ∫ s in (1 : ℝ)..t, Real.exp (-t) / s = ∫ s in Set.Ioi 1, ∫ t in Set.Ioi s, Real.exp (-t) / s := by + have h_fubini_one_infty : ∫ t in Set.Ioi 1, ∫ s in (1 : ℝ)..t, Real.exp (-t) / s = ∫ s in Set.Ioi 1, ∫ t in Set.Ioi 1, Real.exp (-t) / s * (if s ≤ t then 1 else 0) := by + rw [ ← MeasureTheory.integral_integral_swap ]; + · refine' MeasureTheory.setIntegral_congr_fun measurableSet_Ioi fun t ht => _; + rw [ intervalIntegral.integral_of_le ht.out.le, ← MeasureTheory.integral_indicator ] <;> norm_num [ Set.indicator ]; + rw [ ← MeasureTheory.integral_indicator ] <;> norm_num [ Set.indicator ]; + simp only [ ← ite_and ]; + · rw [ MeasureTheory.integrable_prod_iff ]; + · constructor; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with t ht; + + have h_integrable : MeasureTheory.IntegrableOn (fun y => Real.exp (-t) / y) (Set.Ioc 1 t) := by + exact ContinuousOn.integrableOn_Icc ( by exact continuousOn_of_forall_continuousAt fun x hx => ContinuousAt.div continuousAt_const continuousAt_id <| by linarith [ hx.1 ] ) |> fun h => h.mono_set <| Set.Ioc_subset_Icc_self; + rw [ ← MeasureTheory.integrable_indicator_iff ( measurableSet_Ioc ) ] at h_integrable; + rw [ MeasureTheory.integrable_congr ]; + convert h_integrable.restrict; + filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with y hy using by rw [ Set.indicator_apply ] ; aesop; + · refine' MeasureTheory.Integrable.congr _ _; + use fun x => ∫ y in Set.Ioc 1 x, Real.exp ( -x ) / y; + · + have h_inner : ∀ x ∈ Set.Ioi 1, ∫ y in Set.Ioc 1 x, Real.exp (-x) / y = Real.exp (-x) * Real.log x := by + intro x hx; rw [ ← intervalIntegral.integral_of_le hx.out.le ] ; norm_num [ div_eq_mul_inv, hx.out.le ] ; + rw [ MeasureTheory.integrable_congr ( Filter.eventuallyEq_of_mem ( MeasureTheory.ae_restrict_mem measurableSet_Ioi ) h_inner ) ]; + have h_integrable : MeasureTheory.IntegrableOn (fun x => Real.exp (-x) * x) (Set.Ioi 1) := by + have h_integrable : MeasureTheory.IntegrableOn (fun x => Real.exp (-x) * x) (Set.Ioi 0) := by + have h_integrable : ∫ x in Set.Ioi 0, Real.exp (-x) * x = Real.Gamma 2 := by + rw [ Real.Gamma_eq_integral ] <;> norm_num; + exact ( by contrapose! h_integrable; rw [ MeasureTheory.integral_undef h_integrable ] ; positivity ); + exact h_integrable.mono_set <| Set.Ioi_subset_Ioi zero_le_one; + refine' h_integrable.mono' _ _; + · exact MeasureTheory.AEStronglyMeasurable.mul ( Continuous.aestronglyMeasurable ( by continuity ) ) ( Real.measurable_log.aestronglyMeasurable ); + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with x hx using by rw [ Real.norm_of_nonneg ( mul_nonneg ( Real.exp_pos _ |> le_of_lt ) ( Real.log_nonneg hx.out.le ) ) ] ; exact mul_le_mul_of_nonneg_left ( le_trans ( Real.log_le_sub_one_of_pos ( zero_lt_one.trans hx.out ) ) ( by linarith ) ) ( Real.exp_pos _ |> le_of_lt ) ; + · filter_upwards [ MeasureTheory.ae_restrict_mem measurableSet_Ioi ] with x hx; + rw [ ← MeasureTheory.integral_indicator, ← MeasureTheory.integral_indicator ] <;> norm_num [ Set.indicator ]; + congr with y ; split_ifs <;> norm_num; + · rw [ abs_of_nonneg ( div_nonneg ( Real.exp_nonneg _ ) ( by linarith ) ) ]; + · linarith; + · grind +revert; + · grind +qlia; + · exact Measurable.aestronglyMeasurable ( by exact Measurable.mul ( by exact Measurable.mul ( Real.continuous_exp.measurable.comp ( measurable_neg.comp measurable_fst ) ) ( measurable_snd.inv ) ) ( by exact Measurable.ite ( measurableSet_le measurable_snd measurable_fst ) measurable_const measurable_const ) ); + rw [ h_fubini_one_infty ]; + refine' MeasureTheory.setIntegral_congr_fun measurableSet_Ioi fun s hs => _; + rw [ ← MeasureTheory.integral_indicator ( measurableSet_Ioi ), ← MeasureTheory.integral_indicator ( measurableSet_Ioi ) ]; + simp +decide [ Set.indicator ]; + rw [ ← MeasureTheory.integral_congr_ae ]; + filter_upwards [ MeasureTheory.measure_eq_zero_iff_ae_notMem.mp ( MeasureTheory.measure_singleton s ) ] with x hx using by split_ifs <;> cases lt_or_gt_of_ne hx <;> linarith [ hs.out ] ; + simp_all +decide [ div_eq_mul_inv, ← intervalIntegral.integral_of_le zero_le_one ]; + rw [ intervalIntegral.integral_of_le zero_le_one ] ; norm_num [ MeasureTheory.integral_mul_const, integral_exp_neg_Ioi ] ; ring_nf; + norm_num [ integral_exp_Iic, ← intervalIntegral.integral_of_le zero_le_one ] ; ring_nf; + rw [ intervalIntegral.integral_of_le zero_le_one ] ; rw [ MeasureTheory.setIntegral_congr_fun measurableSet_Ioc fun x hx => by rw [ ← intervalIntegral.integral_of_le hx.1.le ] ] ; norm_num [ intervalIntegral.integral_comp_neg ] ; ring_nf; + rw [ intervalIntegral.integral_of_le zero_le_one ] + +lemma pv_rewrite {y ε : ℝ} (hy : 0 < y) (hε : 0 < ε) (hε1 : ε < 1) (hεy : ε < y) : + (∫ u in (-1/ε)..(-ε), exp u / u) + (∫ u in ε..y, exp u / u) = + (∫ t in ε..1, (1 - exp (-t)) / t) - (∫ t in (1:ℝ)..(1/ε), exp (-t) / t) + + (∫ u in ε..y, (exp u - 1) / u) + log y := by + have _ := hy + have h1 : ∫ u in (-1 / ε)..(-ε), Real.exp u / u = -(∫ t in ε..1 / ε, Real.exp (-t) / t) := by + exact integral_exp_div_neg_eq hε + have h2 : ∫ u in ε..y, Real.exp u / u = (∫ v in ε..y, ((Real.exp v) - 1) / v) + Real.log y - Real.log ε := by + rw [ intervalIntegral.integral_eq_sub_of_hasDerivAt ]; + rotate_right; + use fun x => ∫ u in ε..x, ( Real.exp u - 1 ) / u + 1 / u; + · rw [ intervalIntegral.integral_add ] <;> norm_num [ hε, hεy.le ]; + · rw [ Real.log_div ] <;> linarith; + · apply_rules [ ContinuousOn.intervalIntegrable ]; + exact continuousOn_of_forall_continuousAt fun u hu => ContinuousAt.div ( ContinuousAt.sub ( Real.continuous_exp.continuousAt ) continuousAt_const ) continuousAt_id ( by cases Set.mem_uIcc.mp hu <;> linarith ); + · exact ContinuousOn.intervalIntegrable ( by exact continuousOn_of_forall_continuousAt fun x hx => ContinuousAt.div continuousAt_const continuousAt_id <| by linarith [ Set.mem_Icc.mp <| by simpa [ hε.le, hεy.le ] using hx ] ) ..; + · intro x hx; convert HasDerivAt.congr_of_eventuallyEq _ ?_ using 1; + use fun x => ∫ u in ε..x, Real.exp u / u; + · apply_rules [ intervalIntegral.integral_hasDerivAt_right ]; + · apply_rules [ ContinuousOn.intervalIntegrable ]; + exact continuousOn_of_forall_continuousAt fun u hu => ContinuousAt.div ( Real.continuous_exp.continuousAt ) continuousAt_id ( by cases Set.mem_uIcc.mp hu <;> cases Set.mem_uIcc.mp hx <;> linarith ); + · exact Measurable.stronglyMeasurable ( by exact Measurable.mul ( Real.continuous_exp.measurable ) ( measurable_id.inv ) ) |> fun h => h.stronglyMeasurableAtFilter; + · exact ContinuousAt.div ( Real.continuous_exp.continuousAt ) continuousAt_id ( by cases Set.mem_uIcc.mp hx <;> linarith ); + · filter_upwards [ lt_mem_nhds ( show x > 0 by cases Set.mem_uIcc.mp hx <;> linarith ) ] with u hu using by refine' intervalIntegral.integral_congr fun v hv => _ ; rw [ sub_div, sub_add_cancel ] ; + · apply_rules [ ContinuousOn.intervalIntegrable ]; + exact continuousOn_of_forall_continuousAt fun u hu => ContinuousAt.div ( Real.continuous_exp.continuousAt ) continuousAt_id ( by cases Set.mem_uIcc.mp hu <;> linarith ); + rw [ h1, h2 ] ; ring_nf; + rw [ intervalIntegral.integral_add ] <;> norm_num ; ring_nf; + · rw [ integral_inv_of_pos, show ( ∫ u in ( ε : ℝ )..ε⁻¹, Real.exp ( -u ) * u⁻¹ ) = ( ∫ u in ( ε : ℝ )..1, Real.exp ( -u ) * u⁻¹ ) + ( ∫ u in ( 1 : ℝ )..ε⁻¹, Real.exp ( -u ) * u⁻¹ ) from ?_ ] <;> norm_num [ hε, hε1, hεy ] ; ring; + rw [ intervalIntegral.integral_add_adjacent_intervals ] <;> apply_rules [ ContinuousOn.intervalIntegrable ] <;> exact continuousOn_of_forall_continuousAt fun u hu => ContinuousAt.mul ( ContinuousAt.rexp <| ContinuousAt.neg <| continuousAt_id ) <| ContinuousAt.inv₀ continuousAt_id <| by cases Set.mem_uIcc.mp hu <;> nlinarith [ inv_mul_cancel₀ hε.ne' ] ; + · apply_rules [ ContinuousOn.intervalIntegrable ]; + exact continuousOn_of_forall_continuousAt fun t ht => ContinuousAt.neg ( ContinuousAt.mul ( Real.continuous_exp.continuousAt.comp <| ContinuousAt.neg continuousAt_id ) <| ContinuousAt.inv₀ continuousAt_id <| by cases Set.mem_uIcc.mp ht <;> linarith ); + · exact Or.inr <| Set.notMem_uIcc_of_lt hε zero_lt_one + +theorem pv_exp_div_eq_gamma_add_log_add_integral {y : ℝ} (hy : 0 < y) : + lim ((𝓝[>] (0 : ℝ)).map (fun ε => + (∫ u in (-1/ε)..(-ε), exp u / u) + ∫ u in ε..y, exp u / u)) = + eulerMascheroniConstant + log y + ∫ u in (0 : ℝ)..y, ((exp u - 1) / u) := by + + apply lim_eq + + rw [show eulerMascheroniConstant + log y + ∫ u in (0 : ℝ)..y, ((exp u - 1) / u) = + ((∫ t in (0:ℝ)..1, (1 - exp (-t)) / t) - ∫ t in Ioi (1:ℝ), exp (-t) / t) + + (∫ u in (0:ℝ)..y, (exp u - 1) / u) + log y by + rw [← eulerMascheroni_eq_integral]; ring] + + have h_rw : Tendsto + (fun ε => (∫ t in ε..1, (1 - exp (-t)) / t) - (∫ t in (1:ℝ)..(1/ε), exp (-t) / t) + + (∫ u in ε..y, (exp u - 1) / u) + log y) + (𝓝[>] (0 : ℝ)) + (𝓝 (((∫ t in (0:ℝ)..1, (1 - exp (-t)) / t) - ∫ t in Ioi (1:ℝ), exp (-t) / t) + + (∫ u in (0:ℝ)..y, (exp u - 1) / u) + log y)) := by + exact ((tendsto_integral_one_sub_exp_neg_div.sub tendsto_integral_exp_neg_div_Ioi).add + (tendsto_integral_exp_sub_one_div hy)).add tendsto_const_nhds + + apply h_rw.congr' + have : ∀ᶠ ε in 𝓝[>] (0 : ℝ), ε < min y 1 := by + apply nhdsWithin_le_nhds + exact Iio_mem_nhds (lt_min hy one_pos) + filter_upwards [this, self_mem_nhdsWithin] with ε hε hε_pos + exact (pv_rewrite hy hε_pos (lt_of_lt_of_le hε (min_le_right _ _)) + (lt_of_lt_of_le hε (min_le_left _ _))).symm + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairCollisionCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairCollisionCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8509cea006c5e0204de76b9f13f42566d8f08d8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairCollisionCount.lean @@ -0,0 +1,374 @@ +import Mathlib.Algebra.Group.Prod +import Mathlib.Algebra.Group.Units.Equiv +import Mathlib.Algebra.GroupWithZero.Units.Fintype +import Mathlib.Analysis.SpecialFunctions.Complex.CircleAddChar +import Mathlib.Data.Nat.Totient +import Mathlib.Data.ZMod.Units +import Mathlib.GroupTheory.Index +import Mathlib.NumberTheory.GaussSum +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators ComplexConjugate + +namespace ErdosKloosterman + +attribute [local instance] Classical.decEq + +noncomputable def sum {R : Type*} [CommRing R] [Fintype R] + (ψ : AddChar R ℂ) (a b : R) : ℂ := + ∑ u : Rˣ, ψ (a * (u : R) + b * (↑u⁻¹ : R)) + +noncomputable def standardSum (N : ℕ) [NeZero N] (h k : ℤ) : ℂ := + sum ZMod.stdAddChar (h : ZMod N) (k : ZMod N) + +theorem sum_swap {R : Type*} [CommRing R] [Fintype R] + (ψ : AddChar R ℂ) (a b : R) : sum ψ a b = sum ψ b a := by + have h := Equiv.sum_comp (Equiv.inv Rˣ) (fun u : Rˣ => ψ (a * (u : R) + b * (↑u⁻¹ : R))) + simpa only [Equiv.inv_apply, inv_inv, add_comm, sum] using h.symm + +theorem sum_unit_scale {R : Type*} [CommRing R] [Fintype R] + (ψ : AddChar R ℂ) (a b : R) (c : Rˣ) : + sum ψ (a * c) (b * (↑c⁻¹ : R)) = sum ψ a b := by + have h := Equiv.sum_comp (Equiv.mulLeft c) + (fun u : Rˣ => ψ (a * (u : R) + b * (↑u⁻¹ : R))) + simpa only [sum, Equiv.coe_mulLeft, mul_inv_rev, Units.val_mul, + mul_assoc, mul_comm, mul_left_comm] using h + +theorem sum_ringEquiv {R S : Type*} [CommRing R] [Fintype R] [CommRing S] [Fintype S] + (e : R ≃+* S) (ψ : AddChar S ℂ) (a b : R) : + sum (ψ.compAddMonoidHom e.toAddMonoidHom) a b = sum ψ (e a) (e b) := by + have h := Equiv.sum_comp (Units.mapEquiv e.toMulEquiv).toEquiv + (fun u : Sˣ => ψ (e a * (u : S) + e b * (↑u⁻¹ : S))) + simpa [sum, ← map_inv] using h + +theorem sum_zero_zero {R : Type*} [CommRing R] [Fintype R] (ψ : AddChar R ℂ) : + sum ψ 0 0 = Fintype.card Rˣ := by simp [sum] + +theorem standardSum_exp (N : ℕ) [NeZero N] (h k : ℤ) : + standardSum N h k = ∑ u : (ZMod N)ˣ, + Complex.exp (2 * Real.pi * Complex.I * + ((h : ℂ) * (u.val.val : ℂ) + (k : ℂ) * (u⁻¹).val.val) / N) := by + unfold standardSum sum + refine Finset.sum_congr ?_ ?_ + · ext u; simp + intro u _ + have heq : (h : ZMod N) * u.val + (k : ZMod N) * (u⁻¹).val = + ((h * (u.val.val : ℤ) + k * ((u⁻¹).val.val : ℤ) : ℤ) : ZMod N) := by simp + rw [heq, ZMod.stdAddChar_coe] + congr 1 + push_cast + ring + +end ErdosKloosterman + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaIdentities + +attribute [local instance] Classical.decEq + +noncomputable def integerWeight (N : ℕ) [NeZero N] (I : Finset ℤ) (h : ZMod N) : ℂ := + ∑ x ∈ I, ZMod.stdAddChar (-h*(x : ZMod N)) + +noncomputable def unitClass (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) : Finset (ZMod N)ˣ := + Finset.univ.filter fun u => ZMod.unitsMap hT u = a + +noncomputable def restrictedSum (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (h k : ZMod N) : ℂ := + ∑ u ∈ unitClass N T hT a, + ZMod.stdAddChar (h*(u : ZMod N) + k*(c : ZMod N)*(↑u⁻¹ : ZMod N)) + +noncomputable def hyperbolaPairs (N T : ℕ) [NeZero N] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (I J : Finset ℤ) : Finset (ℤ × ℤ) := + (I.product J).filter fun xy => + (xy.1 : ZMod N)*(xy.2 : ZMod N) = (c : ZMod N) ∧ + (xy.1 : ZMod T) = (a : ZMod T) + +noncomputable def integerFibre (N : ℕ) (I : Finset ℤ) (u : ZMod N) : Finset ℤ := + I.filter fun x => (x : ZMod N) = u + +noncomputable def pairFibre (N : ℕ) [NeZero N] (c u : (ZMod N)ˣ) (I J : Finset ℤ) : + Finset (ℤ × ℤ) := + (integerFibre N I (u : ZMod N)).product + (integerFibre N J ((c : ZMod N)*(↑u⁻¹ : ZMod N))) + +@[simp] theorem mem_unitClass (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (u : (ZMod N)ˣ) : + u ∈ unitClass N T hT a ↔ ZMod.unitsMap hT u = a := by simp [unitClass] + +@[simp] theorem mem_integerFibre (N : ℕ) (I : Finset ℤ) (u : ZMod N) (x : ℤ) : + x ∈ integerFibre N I u ↔ x ∈ I ∧ (x : ZMod N) = u := by simp [integerFibre] + +theorem unit_class_of_int (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (u : (ZMod N)ˣ) (x : ℤ) (hx : (u : ZMod N) = (x : ZMod N)) : + ZMod.unitsMap hT u = a ↔ (x : ZMod T) = (a : ZMod T) := by + rw [← Units.val_inj] + change (ZMod.castHom hT (ZMod T)) (u : ZMod N) = (a : ZMod T) ↔ _ + rw [hx, map_intCast] + +end ErdosHyperbolaIdentities + +end + +section + +open scoped BigOperators + +namespace ErdosKloosterman + +attribute [local instance] Classical.decEq + +noncomputable def productChar {R S : Type*} [AddMonoid R] [AddMonoid S] + (ψ : AddChar R ℂ) (φ : AddChar S ℂ) : AddChar (R × S) ℂ where + toFun x := ψ x.1 * φ x.2 + map_zero_eq_one' := by simp + map_add_eq_mul' x y := by + simp only [Prod.fst_add, Prod.snd_add, AddChar.map_add_eq_mul] + ring + +theorem sum_product {R S : Type*} [CommRing R] [CommRing S] + [Fintype R] [Fintype S] (ψ : AddChar R ℂ) (φ : AddChar S ℂ) + (a b : R × S) : + sum (productChar ψ φ) a b = sum ψ a.1 b.1 * sum φ a.2 b.2 := by + let : DecidableEq (R × S) := Classical.decEq _ + let e : (R × S)ˣ ≃ Rˣ × Sˣ := + { toFun := fun u => (Units.map (RingHom.fst R S).toMonoidHom u, + Units.map (RingHom.snd R S).toMonoidHom u) + invFun := fun u => ⟨((u.1 : R),(u.2 : S)), ((↑u.1⁻¹ : R),(↑u.2⁻¹ : S)), + by ext <;> simp, by ext <;> simp⟩ + left_inv := fun u => by apply Units.ext; rfl + right_inv := fun u => by apply Prod.ext <;> apply Units.ext <;> rfl } + have h := Equiv.sum_comp e.symm + (fun u : (R × S)ˣ => productChar ψ φ (a * (u : R × S) + b * (↑u⁻¹ : R × S))) + calc + _ = ∑ u : Rˣ, ∑ v : Sˣ, + ψ (a.1 * (u : R) + b.1 * (↑u⁻¹ : R)) * + φ (a.2 * (v : S) + b.2 * (↑v⁻¹ : S)) := by + simpa [sum, Fintype.sum_prod_type, productChar, e] using! h.symm + _ = _ := by + simp only [sum, Finset.sum_mul, Finset.mul_sum] + exact Finset.sum_comm + +theorem sum_product_ringEquiv {T R S : Type*} + [CommRing T] [CommRing R] [CommRing S] [Fintype T] [Fintype R] [Fintype S] + (e : T ≃+* R × S) (ψ : AddChar R ℂ) (φ : AddChar S ℂ) (a b : T) : + sum ((productChar ψ φ).compAddMonoidHom e.toAddMonoidHom) a b = + sum ψ (e a).1 (e b).1 * sum φ (e a).2 (e b).2 := by + rw [sum_ringEquiv, sum_product] + +end ErdosKloosterman + +end + +section + +namespace ErdosKloosterman.PrimePower + +variable {R : Type*} [CommRing R] + +private theorem shift_mul_inverse (u : Rˣ) (t : R) (ht : t^2 = 0) : + ((u : R) + t) * ((↑u⁻¹ : R) - t * (↑u⁻¹ : R)^2) = 1 := by + calc + _ = (u : R) * ↑u⁻¹ + t * ↑u⁻¹ * (1 - (u : R) * ↑u⁻¹) - + t^2 * (↑u⁻¹ : R)^2 := by ring + _ = 1 := by simp [ht] + +def shiftUnit (u : Rˣ) (t : R) (ht : t^2 = 0) : Rˣ := + Units.mkOfMulEqOne ((u : R) + t) ((↑u⁻¹ : R) - t * (↑u⁻¹ : R)^2) + (shift_mul_inverse u t ht) + +@[simp] theorem shiftUnit_val (u : Rˣ) (t : R) (ht : t^2 = 0) : + (shiftUnit u t ht : R) = (u : R) + t := rfl + +@[simp] theorem shiftUnit_inv_val (u : Rˣ) (t : R) (ht : t^2 = 0) : + (↑(shiftUnit u t ht)⁻¹ : R) = (↑u⁻¹ : R) - t * (↑u⁻¹ : R)^2 := rfl + +def shiftEquiv (t : R) (ht : t^2 = 0) : Rˣ ≃ Rˣ where + toFun u := shiftUnit u t ht + invFun u := shiftUnit u (-t) (by simpa using ht) + left_inv u := by apply Units.ext; simp + right_inv u := by apply Units.ext; simp + +theorem phase_shift (a b : R) (u : Rˣ) (t : R) (ht : t^2 = 0) : + a * (shiftUnit u t ht : R) + b * (↑(shiftUnit u t ht)⁻¹ : R) = + a * (u : R) + b * (↑u⁻¹ : R) + t * (a - b * (↑u⁻¹ : R)^2) := by + rw [shiftUnit_val, shiftUnit_inv_val] + ring + +end ErdosKloosterman.PrimePower + +end + +section + +open scoped BigOperators + +namespace ErdosKloosterman + +variable {F : Type*} [Field F] + +theorem pair_eq_or_swap {u v z w : F} + (hs : u + v = z + w) (hp : u * v = z * w) : + (u = z ∧ v = w) ∨ (u = w ∧ v = z) := by + have h : (u - z) * (u - w) = 0 := by + linear_combination u * hs - hp + rcases mul_eq_zero.mp h with h | h + · left + have hu := sub_eq_zero.mp h + exact ⟨hu, by rw [hu] at hs; exact add_left_cancel hs⟩ + · right + have hu := sub_eq_zero.mp h + exact ⟨hu, by rw [hu, add_comm z w] at hs; exact add_left_cancel hs⟩ + +theorem inverse_pair_collision (u v z w : Fˣ) + (hs : (u : F) + v = z + w) + (hi : (↑u⁻¹ : F) + ↑v⁻¹ = ↑z⁻¹ + ↑w⁻¹) : + ((u : F) + v = 0 ∧ (z : F) + w = 0) ∨ + (u = z ∧ v = w) ∨ (u = w ∧ v = z) := by + by_cases hz : (u : F) + v = 0 + · exact Or.inl ⟨hz, hs.symm.trans hz⟩ + right + have hid : (u : F)⁻¹ + (v : F)⁻¹ = (z : F)⁻¹ + (w : F)⁻¹ := by + simpa only [Units.val_inv_eq_inv_val] using hi + have hp : (u : F) * v = z * w := by + have hzero : ((u : F) + v) * ((z : F) * w - (u : F) * v) = 0 := by + field_simp at hid + linear_combination hid - ((u : F) * v) * hs + have hd := (mul_eq_zero.mp hzero).resolve_left hz + exact (sub_eq_zero.mp hd).symm + rcases pair_eq_or_swap hs hp with ⟨huz, hvw⟩ | ⟨huw, hvz⟩ + · exact Or.inl ⟨Units.ext huz, Units.ext hvw⟩ + · exact Or.inr ⟨Units.ext huw, Units.ext hvz⟩ + +end ErdosKloosterman + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaIdentities + +attribute [local instance] Classical.decEq + +private theorem card_mul_fibre {A B : Type*} [Group A] [Fintype A] + [Group B] [Fintype B] (f : A →* B) (hf : Function.Surjective f) (b : B) : + Fintype.card B * ((Finset.univ : Finset A).filter fun x => f x = b).card = + Fintype.card A := by + calc + _ = ∑ _y : B, ((Finset.univ : Finset A).filter fun x => f x = b).card := by simp + _ = ∑ y : B, ((Finset.univ : Finset A).filter fun x => f x = y).card := by + apply Finset.sum_congr rfl + intro y _ + exact MonoidHom.card_fiber_eq_of_mem_range f (hf b) (hf y) + _ = _ := by + rw [Finset.sum_card_fiberwise_eq_card_filter] + simp + +theorem unitClass_card_mul_totient (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) : T.totient * (unitClass N T hT a).card = N.totient := by + let f : (ZMod N)ˣ →* (ZMod T)ˣ := ZMod.unitsMap hT + have hf : Function.Surjective f := ZMod.unitsMap_surjective hT + have hc := card_mul_fibre f hf a + simpa only [unitClass, f, ZMod.card_units_eq_totient] using hc + +theorem restrictedSum_zero (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) : + restrictedSum N T hT a c 0 0 = (unitClass N T hT a).card := by + simp [restrictedSum] + +theorem restrictedSum_zero_eq_totient_ratio (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) : + restrictedSum N T hT a c 0 0 = (N.totient : ℂ)/(T.totient : ℂ) := by + have hphi : (T.totient : ℂ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (NeZero.pos T)).ne' + rw [restrictedSum_zero] + apply (eq_div_iff hphi).mpr + have hc := unitClass_card_mul_totient N T hT a + have hcomplex : (T.totient : ℂ) * ((unitClass N T hT a).card : ℂ) = N.totient := by + exact_mod_cast hc + simpa only [mul_comm] using hcomplex + +end ErdosHyperbolaIdentities + +end + +section + +open scoped BigOperators + +namespace ErdosKloosterman + +attribute [local instance] Classical.decEq + +variable (F : Type*) [Field F] [Fintype F] + +noncomputable def pairCollisions : Finset ((Fˣ × Fˣ) × (Fˣ × Fˣ)) := + Finset.univ.filter fun x => + (x.1.1 : F) + x.1.2 = x.2.1 + x.2.2 ∧ + (↑x.1.1⁻¹ : F) + ↑x.1.2⁻¹ = ↑x.2.1⁻¹ + ↑x.2.2⁻¹ + +theorem pairCollisions_card_le : + (pairCollisions F).card ≤ 3 * (Fintype.card Fˣ) ^ 2 := by + let zeroFamily := (Finset.univ : Finset (Fˣ × Fˣ)).image + (fun p => ((p.1, -p.1), (p.2, -p.2))) + let diagonalFamily := (Finset.univ : Finset (Fˣ × Fˣ)).image (fun p => (p, p)) + let swappedFamily := (Finset.univ : Finset (Fˣ × Fˣ)).image + (fun p => (p, (p.2, p.1))) + have cover : pairCollisions F ⊆ zeroFamily ∪ diagonalFamily ∪ swappedFamily := by + rintro ⟨⟨u,v⟩,⟨z,w⟩⟩ hx + obtain ⟨hs, hi⟩ := (Finset.mem_filter.mp hx).2 + rcases inverse_pair_collision u v z w hs hi with hz | hd | he + · have hv : v = -u := by + apply Units.ext + change (v : F) = -(u : F) + linear_combination hz.1 + have hw : w = -z := by + apply Units.ext + change (w : F) = -(z : F) + linear_combination hz.2 + subst v; subst w + exact Finset.mem_union_left _ (Finset.mem_union_left _ + (Finset.mem_image.mpr ⟨(u,z), Finset.mem_univ _, rfl⟩)) + · rcases hd with ⟨huz, hvw⟩ + subst z; subst w + exact Finset.mem_union_left _ (Finset.mem_union_right _ + (Finset.mem_image.mpr ⟨(u,v), Finset.mem_univ _, rfl⟩)) + · rcases he with ⟨huw, hvz⟩ + subst w; subst z + exact Finset.mem_union_right _ + (Finset.mem_image.mpr ⟨(u,v), Finset.mem_univ _, rfl⟩) + have hz : zeroFamily.card ≤ (Fintype.card Fˣ)^2 := by + simpa only [Finset.card_univ, Fintype.card_prod, pow_two] using + (Finset.card_image_le (s := (Finset.univ : Finset (Fˣ × Fˣ))) + (f := fun p : Fˣ × Fˣ => ((p.1, -p.1), (p.2, -p.2)))) + have hd : diagonalFamily.card ≤ (Fintype.card Fˣ)^2 := by + simpa only [Finset.card_univ, Fintype.card_prod, pow_two] using + (Finset.card_image_le (s := (Finset.univ : Finset (Fˣ × Fˣ))) + (f := fun p : Fˣ × Fˣ => (p,p))) + have hs : swappedFamily.card ≤ (Fintype.card Fˣ)^2 := by + simpa only [Finset.card_univ, Fintype.card_prod, pow_two] using + (Finset.card_image_le (s := (Finset.univ : Finset (Fˣ × Fˣ))) + (f := fun p : Fˣ × Fˣ => (p,(p.2,p.1)))) + have h1 := Finset.card_union_le zeroFamily diagonalFamily + have h2 := Finset.card_union_le (zeroFamily ∪ diagonalFamily) swappedFamily + have h3 := Finset.card_le_card cover + omega + +end ErdosKloosterman + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairTraceBridge.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairTraceBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..710f6bac88273262b7d8b5a5aa4cb8cf1bb27a6f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairTraceBridge.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.SourceCycleDuration + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.CycleOccupation + +lemma pairWitness_lintegral (z : OddCost) {F : FirstPairWitness → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F y ∂pairWitnessKernel z) = + ∫⁻ t : EvenState, ∫⁻ u : OddState, F (t,(u,z.2+cost t.1+cost u.1)) ∂evenToOdd t ∂oddToEven z.1 := by + have hm : Measurable (fun x : EvenState × OddState => pairWitnessUpdate (z,x)) := + pairWitnessUpdate_measurable.comp measurable_prodMk_left + have he : pairWitnessKernel z = (pairedDraws z.1).map (fun x => pairWitnessUpdate (z,x)) := + sampling_map_measure pairWitnessUpdate pairWitnessUpdate_measurable z + rw [he,lintegral_map hF hm,pairedDraws, + Kernel.lintegral_compProd _ _ _ (f := fun x : EvenState × OddState => F (pairWitnessUpdate (z,x))) (hF.comp hm)] + rfl + +noncomputable def pairTraceOfWitness (z : OddCost) (x : FirstPairWitness) : CostState × CostState := + ((Sum.inl x.1,z.2+cost x.1.1),embedOdd x.2) + +lemma pairTraceOfWitness_measurable (z : OddCost) : Measurable (pairTraceOfWitness z) := + ((measurable_inl.comp measurable_fst).prodMk + (measurable_const.add (cost_measurable.comp (measurable_subtype_coe.comp measurable_fst)))).prodMk + (embedOdd_measurable.comp measurable_snd) + +noncomputable def fullPairTraceKernel : Kernel CostState (CostState × CostState) := + costKernel ⊗ₖ costKernel.prodMkLeft CostState + +instance fullPairTraceKernel_isMarkovKernel : IsMarkovKernel fullPairTraceKernel := by + unfold fullPairTraceKernel + infer_instance + +theorem pairWitness_joint_full_trace (z : OddCost) : + (pairWitnessKernel z).map (pairTraceOfWitness z) = fullPairTraceKernel (embedOdd z) := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (pairTraceOfWitness_measurable z), + pairWitness_lintegral z (F := fun x : FirstPairWitness => F (pairTraceOfWitness z x)) (hF.comp (pairTraceOfWitness_measurable z)),fullPairTraceKernel, + Kernel.lintegral_compProd _ _ _ hF] + change (∫⁻ t : EvenState, ∫⁻ u : OddState, + F ((Sum.inl t,z.2+cost t.1),(Sum.inr u,z.2+cost t.1+cost u.1)) ∂evenToOdd t ∂oddToEven z.1) = + ∫⁻ x : CostState, ∫⁻ y : CostState, F (x,y) ∂costKernel x ∂costKernel (embedOdd z) + have hJ : Measurable (fun x : CostState => ∫⁻ y : CostState, F (x,y) ∂costKernel x) := + hF.lintegral_kernel_prod_right' + simp only [embedOdd] + rw [costKernel_odd_lintegral z.1 z.2 hJ] + apply lintegral_congr + intro t + exact (costKernel_even_lintegral t (z.2+cost t.1) + (H := fun y : CostState => F ((Sum.inl t,z.2+cost t.1),y)) + (hF.comp measurable_prodMk_left)).symm + +theorem pairWitness_joint_event (z : OddCost) {B : Set (CostState × CostState)} (hB : MeasurableSet B) : + pairWitnessKernel z (pairTraceOfWitness z ⁻¹' B) = fullPairTraceKernel (embedOdd z) B := by + rw [← Measure.map_apply (pairTraceOfWitness_measurable z) hB,pairWitness_joint_full_trace] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedBlockContraction.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedBlockContraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..53dd54954a974e75e491932b3d975f3be412eafd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedBlockContraction.lean @@ -0,0 +1,128 @@ +import OAI.NumberTheory.Jacobsthal.Probability.PairedDrift + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.PairedBlockContraction + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open TransitionKernels PairedHitting PairedDrift + +theorem moment_add_constant (n : ℕ) (s : OddState) {D : ℝ} (hD : 0 ≤ D) : + (∫⁻ t, ENNReal.ofReal (V t + D) ∂(pairedKilled ^ n) s) = + (∫⁻ t, ENNReal.ofReal (V t) ∂(pairedKilled ^ n) s) + + ENNReal.ofReal D * (pairedKilled ^ n) s univ := by + have heq : ∀ t : OddState, ENNReal.ofReal (V t + D) = ENNReal.ofReal (V t) + ENNReal.ofReal D := + fun t => ENNReal.ofReal_add (V_pos t).le hD + rw [lintegral_congr heq, lintegral_add_left (f := fun t : OddState => ENNReal.ofReal (V t)) (ENNReal.measurable_ofReal.comp V_measurable) (fun _ => ENNReal.ofReal D), lintegral_const] + +theorem actual_block_contraction : ∃ m : ℕ, 0 < m ∧ ∃ ρ D : ℝ, + 0 < ρ ∧ ρ < 1 ∧ 0 < D ∧ ∀ s : OddState, + (∫⁻ t, ENNReal.ofReal (V t + D) ∂(pairedKilled ^ m) s) ≤ + ENNReal.ofReal (ρ * (V s + D)) := by + obtain ⟨a, B, ha, ha1, hB, hDrift⟩ := pairedKilled_iterated_drift + let M := max 4 (8 * B) + have hM : 4 ≤ M := le_max_left _ _ + obtain ⟨m0, hm0, p, hp, hp1, hHit⟩ := compact_paired_survival hM + have hpow : Tendsto (fun n : ℕ => a ^ n) atTop (𝓝 0) := + tendsto_pow_atTop_nhds_zero_of_lt_one ha.le ha1 + have hsmall : ∀ᶠ n in atTop, a ^ n < 1 / 4 := (tendsto_order.mp hpow).2 _ (by norm_num) + obtain ⟨m, hma, hm⟩ := (hsmall.and (eventually_ge_atTop m0)).exists + let D := 2 * B / p + let ρ := 1 - p / 2 + have hD : 0 < D := div_pos (by linarith) hp + have hρ : 0 < ρ := by dsimp [ρ]; linarith + have hρ1 : ρ < 1 := by dsimp [ρ]; linarith + refine ⟨m, lt_of_lt_of_le hm0 hm, ρ, D, hρ, hρ1, hD, ?_⟩ + intro s + rw [moment_add_constant m s hD.le] + have hE : 0 ≤ a ^ m * V s + B := add_nonneg (mul_nonneg (pow_nonneg ha.le _) (V_pos s).le) hB.le + by_cases hs : s.1 ≤ M + · calc + _ ≤ ENNReal.ofReal (a ^ m * V s + B) + ENNReal.ofReal D * ENNReal.ofReal (1 - p) := + add_le_add (hDrift m s) (mul_le_mul le_rfl (hHit m hm s hs) zero_le zero_le) + _ = ENNReal.ofReal (a ^ m * V s + B + D * (1 - p)) := by + rw [← ENNReal.ofReal_mul hD.le, ← ENNReal.ofReal_add hE (mul_nonneg hD.le (by linarith))] + _ ≤ _ := ENNReal.ofReal_le_ofReal (block_drift_algebra hma.le hB.le hp hp1 (V_pos s).le + (le_refl _) (show 1 - p ≤ 1 by linarith) (Or.inl le_rfl)) + · have hlarge : 8 * B ≤ V s := by + dsimp [V] + have hMb : 8 * B ≤ M := le_max_right _ _ + linarith [Real.add_one_le_exp s.1] + calc + _ ≤ ENNReal.ofReal (a ^ m * V s + B) + ENNReal.ofReal D := by + apply add_le_add (hDrift m s) + simpa only [mul_one] using mul_le_mul (le_refl (ENNReal.ofReal D)) (paired_survival_le_one m s) zero_le zero_le + _ = ENNReal.ofReal (a ^ m * V s + B + D) := (ENNReal.ofReal_add hE hD.le).symm + _ ≤ _ := by + have h := block_drift_algebra hma.le hB.le hp hp1 (V_pos s).le (le_refl _) (le_refl (1 : ℝ)) (Or.inr hlarge) + simpa only [mul_one] using ENNReal.ofReal_le_ofReal h + +theorem paired_survival_geometric : ∃ m : ℕ, 0 < m ∧ ∃ ρ D : ℝ, + 0 < ρ ∧ ρ < 1 ∧ 0 < D ∧ ∀ n : ℕ, ∀ s : OddState, + (pairedKilled ^ (m * n)) s univ ≤ ENNReal.ofReal (ρ ^ n * (V s + D)) := by + obtain ⟨m, hm, ρ, D, hρ, hρ1, hD, hblock⟩ := actual_block_contraction + have hW : Measurable (fun s : OddState => ENNReal.ofReal (V s + D)) := + ENNReal.measurable_ofReal.comp (V_measurable.add measurable_const) + have hIter : ∀ n : ℕ, ∀ s : OddState, + (∫⁻ t, ENNReal.ofReal (V t + D) ∂(pairedKilled ^ (m * n)) s) ≤ + ENNReal.ofReal (ρ ^ n * (V s + D)) := by + intro n + induction n with + | zero => + intro s + change (∫⁻ t, ENNReal.ofReal (V t + D) ∂Measure.dirac s) ≤ _ + rw [lintegral_dirac' s hW] + simp + | succ n ih => + intro s + have hp : pairedKilled ^ (m * (n + 1)) = (pairedKilled ^ m) ∘ₖ (pairedKilled ^ (m * n)) := by + rw [show m * (n + 1) = m + m * n by ring, Kernel.pow_add] + rw [hp, Kernel.lintegral_comp _ _ _ hW] + calc + _ ≤ ∫⁻ t, ENNReal.ofReal ρ * ENNReal.ofReal (V t + D) ∂(pairedKilled ^ (m * n)) s := by + apply lintegral_mono + intro t + simpa only [ENNReal.ofReal_mul hρ.le] using hblock t + _ = ENNReal.ofReal ρ * (∫⁻ t, ENNReal.ofReal (V t + D) ∂(pairedKilled ^ (m * n)) s) := + lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + _ ≤ ENNReal.ofReal ρ * ENNReal.ofReal (ρ ^ n * (V s + D)) := mul_le_mul le_rfl (ih s) zero_le zero_le + _ = _ := by rw [← ENNReal.ofReal_mul hρ.le, pow_succ]; congr 1; ring + refine ⟨m, hm, ρ, D, hρ, hρ1, hD, ?_⟩ + intro n s + calc + _ = ∫⁻ _t, (1 : ℝ≥0∞) ∂(pairedKilled ^ (m * n)) s := by simp + _ ≤ ∫⁻ t, ENNReal.ofReal (V t + D) ∂(pairedKilled ^ (m * n)) s := lintegral_mono (fun t => + by exact (ENNReal.one_le_ofReal).mpr (by linarith [V_one_le t])) + _ ≤ _ := hIter n s + +theorem paired_survival_tendsto_zero (s : OddState) : + Tendsto (fun n => (pairedKilled ^ n) s univ) atTop (𝓝 0) := by + obtain ⟨m, hm, ρ, D, hρ, hρ1, hD, hb⟩ := paired_survival_geometric + have hdiv : Tendsto (fun n : ℕ => n / m) atTop atTop := by + apply tendsto_atTop.mpr + intro b + exact eventually_atTop.mpr ⟨m * b, fun n hn => (Nat.le_div_iff_mul_le hm).mpr (by simpa [Nat.mul_comm] using hn)⟩ + have hreal : Tendsto (fun n : ℕ => ρ ^ (n / m) * (V s + D)) atTop (𝓝 0) := by + simpa only [zero_mul, Function.comp_apply] using + ((tendsto_pow_atTop_nhds_zero_of_lt_one hρ.le hρ1).comp hdiv).mul_const (V s + D) + have hlim : Tendsto (fun n : ℕ => ENNReal.ofReal (ρ ^ (n / m) * (V s + D))) atTop (𝓝 0) := by + convert! ENNReal.continuous_ofReal.continuousAt.tendsto.comp hreal using 1 + simp + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlim + (Eventually.of_forall (fun _ => show (0 : ℝ≥0∞) ≤ _ from zero_le)) + apply Eventually.of_forall + intro n + exact le_trans (paired_survival_antitone s (Nat.mul_div_le n m)) (hb (n / m) s) + +end NumberTheoryLean.PairedBlockContraction + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedCostGrouping.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedCostGrouping.lean new file mode 100644 index 0000000000000000000000000000000000000000..f4284f231071b29ce14425677b2c124f0be4acc9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedCostGrouping.lean @@ -0,0 +1,88 @@ +import OAI.NumberTheory.Jacobsthal.Probability.MarkedVisitGeometry + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.PairedCostGrouping + +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostProcess + +def embedOdd (z : OddCost) : CostState := (.inr z.1, z.2) + +theorem embedOdd_measurable : Measurable embedOdd := + (measurable_inr.comp measurable_fst).prodMk measurable_snd + +theorem costKernel_eq_map (z : CostState) : costKernel z = + (stateKernel z.1).map (fun s => (s, z.2 + cost (stateRatio s))) := by + have hm : Measurable (fun s : State => (s, z.2 + cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + ext B hB + rw [costKernel_apply _ hB, Measure.map_apply hm hB] + rfl + +theorem costKernel_odd_lintegral (s : OddState) (T : ℝ) {H : CostState → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ z, H z ∂costKernel (.inr s, T)) = + ∫⁻ t : EvenState, H (.inl t, T + cost t.1) ∂oddToEven s := by + have hm : Measurable (fun u : State => (u, T + cost (stateRatio u))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + rw [costKernel_eq_map, lintegral_map hH hm] + change (∫⁻ u, H (u, T + cost (stateRatio u)) ∂oddBranch s) = _ + rw [oddBranch, Kernel.map_apply _ measurable_inl, + lintegral_map (f := fun u : State => H (u, T + cost (stateRatio u))) (hH.comp hm) measurable_inl] + rfl + +theorem costKernel_even_lintegral (s : EvenState) (T : ℝ) {H : CostState → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ z, H z ∂costKernel (.inl s, T)) = + ∫⁻ t : OddState, H (.inr t, T + cost t.1) ∂evenToOdd s := by + have hm : Measurable (fun u : State => (u, T + cost (stateRatio u))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + rw [costKernel_eq_map, lintegral_map hH hm] + change (∫⁻ u, H (u, T + cost (stateRatio u)) ∂evenBranch s) = _ + rw [evenBranch, Kernel.map_apply _ measurable_inr, + lintegral_map (f := fun u : State => H (u, T + cost (stateRatio u))) (hH.comp hm) measurable_inr] + rfl + +theorem pairedCost_lintegral (z : OddCost) {H : OddCost → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y, H y ∂pairedCostKernel z) = + ∫⁻ t : EvenState, ∫⁻ u : OddState, H (u, z.2 + cost t.1 + cost u.1) ∂evenToOdd t ∂oddToEven z.1 := by + have hm : Measurable (fun x : EvenState × OddState => (x.2, z.2 + cost x.1.1 + cost x.2.1)) := + measurable_snd.prodMk ((measurable_const.add (cost_measurable.comp (measurable_subtype_coe.comp measurable_fst))).add + (cost_measurable.comp (measurable_subtype_coe.comp measurable_snd))) + have heq : pairedCostKernel z = (pairedDraws z.1).map (fun x => (x.2, z.2 + cost x.1.1 + cost x.2.1)) := by + ext B hB + rw [pairedCostKernel_apply _ hB, Measure.map_apply hm hB] + rfl + rw [heq, lintegral_map hH hm, pairedDraws, + Kernel.lintegral_compProd _ _ _ (f := fun x : EvenState × OddState => H (x.2, z.2 + cost x.1.1 + cost x.2.1)) (hH.comp hm)] + rfl + +theorem pairedCost_full_grouping (z : OddCost) : + (pairedCostKernel z).map embedOdd = (costKernel ^ 2) (embedOdd z) := by + apply Measure.ext_of_lintegral + intro H hH + have hp : costKernel ^ 2 = costKernel ∘ₖ costKernel := by + rw [pow_two] + rfl + rw [lintegral_map hH embedOdd_measurable, + pairedCost_lintegral z (H := fun x => H (embedOdd x)) (hH.comp embedOdd_measurable), + hp, Kernel.lintegral_comp _ _ _ hH] + have hJ : Measurable (fun y : CostState => ∫⁻ w, H w ∂costKernel y) := hH.lintegral_kernel + change (∫⁻ t : EvenState, ∫⁻ u : OddState, H (.inr u, z.2 + cost t.1 + cost u.1) ∂evenToOdd t ∂oddToEven z.1) = _ + simp only [embedOdd] + rw [costKernel_odd_lintegral z.1 z.2 (H := fun y : CostState => ∫⁻ w, H w ∂costKernel y) hJ] + apply lintegral_congr + intro t + exact (costKernel_even_lintegral t (z.2 + cost t.1) hH).symm + +end NumberTheoryLean.PairedCostGrouping + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedDeficitPositivity.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedDeficitPositivity.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ec5d280b9f2a21181e8dbd581e1569f25058858 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PairedDeficitPositivity.lean @@ -0,0 +1,208 @@ +import Mathlib.Analysis.Calculus.Deriv.MeanValue +import Mathlib.Tactic +import Mathlib.Topology.Order.IntermediateValue +import Mathlib.Topology.Order.Lattice + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.PairedDeficitPositivity + +open Filter Set +open scoped Topology + +theorem mass_lower_bound {b : ℝ → ℝ} {l u m : ℝ} (hl : 0 < l) (hlu : l ≤ u) + (hc : ContinuousOn b (Icc l u)) (hbl : m ≤ b l) + (hd : ∀ t ∈ Ioo l u, ∃ v, HasDerivAt (fun s => s * b s) v t ∧ m ≤ v) : + m ≤ b u := by + have hcM : ContinuousOn (fun s => s * b s) (Icc l u) := continuousOn_id.mul hc + have hdM : DifferentiableOn ℝ (fun s => s * b s) (interior (Icc l u)) := by + intro t ht + rw [interior_Icc] at ht + obtain ⟨v, hv, _⟩ := hd t ht + exact hv.differentiableAt.differentiableWithinAt + have hder : ∀ t ∈ interior (Icc l u), m ≤ deriv (fun s => s * b s) t := by + intro t ht + rw [interior_Icc] at ht + obtain ⟨v, hv, hm⟩ := hd t ht + simpa only [hv.deriv] using hm + have h := (convex_Icc l u).mul_sub_le_image_sub_of_le_deriv hcM hdM hder + l ⟨le_rfl, hlu⟩ u ⟨hlu, le_rfl⟩ hlu + have hbase : l * m ≤ l * b l := mul_le_mul_of_nonneg_left hbl hl.le + have hu : 0 < u := lt_of_lt_of_le hl hlu + nlinarith + +theorem feedback_lower_bound_upto {b : ℝ → ℝ} {r m : ℝ} (hr : 0 < r) + (hc : ContinuousOn b (Ici r)) + (hi : ∀ s ∈ Icc r (r + 1), m ≤ b s) + (hd : ∀ s, r + 1 < s → + ∃ v, HasDerivAt (fun t => t * b t) v s ∧ b (s - 1) ≤ v) + (n : ℕ) : ∀ s ∈ Icc r (r + 1 + n), m ≤ b s := by + induction n with + | zero => simpa using hi + | succ n ih => + intro s hs + by_cases hsn : s ≤ r + 1 + n + · exact ih s ⟨hs.1, hsn⟩ + · have hbase : r + 1 + n < s := lt_of_not_ge hsn + apply mass_lower_bound (l := r + 1 + n) (by positivity) hbase.le + · exact hc.mono (fun t ht => by change r ≤ t; linarith [ht.1]) + · exact ih _ ⟨by linarith [Nat.cast_nonneg (α := ℝ) n], le_rfl⟩ + · intro t ht + obtain ⟨v, hv, hvb⟩ := hd t (by linarith [ht.1, Nat.cast_nonneg (α := ℝ) n]) + refine ⟨v, hv, le_trans (ih (t - 1) ⟨?_, ?_⟩) hvb⟩ + · linarith [ht.1, Nat.cast_nonneg (α := ℝ) n] + · push_cast at hs + linarith [ht.2, hs.2] + +theorem feedback_lower_bound {b : ℝ → ℝ} {r m : ℝ} (hr : 0 < r) + (hc : ContinuousOn b (Ici r)) + (hi : ∀ s ∈ Icc r (r + 1), m ≤ b s) + (hd : ∀ s, r + 1 < s → + ∃ v, HasDerivAt (fun t => t * b t) v s ∧ b (s - 1) ≤ v) + {s : ℝ} (hs : r ≤ s) : m ≤ b s := by + obtain ⟨n, hn⟩ := exists_nat_ge (s - r - 1) + exact feedback_lower_bound_upto hr hc hi hd n s ⟨hs, by linarith⟩ + +theorem feedback_not_tendsto_zero {b d : ℝ → ℝ} {r : ℝ} (hr : 0 < r) + (hc : ContinuousOn b (Ici r)) (hz : b r = 0) + (hi : ∀ s ∈ Ioc r (r + 1), 0 < b s) + (hp : ∀ s, r < s → 0 < d s) + (hd : ∀ s, r + 1 < s → + HasDerivAt (fun t => t * b t) (b (s - 1) + d (s - 1)) s) : + ¬ Tendsto b atTop (𝓝 0) := by + have hder : ∀ s, r + 1 < s → + ∃ v, HasDerivAt (fun t => t * b t) v s ∧ b (s - 1) ≤ v := by + intro s hs + exact ⟨_, hd s hs, by linarith [hp (s - 1) (by linarith)]⟩ + have hn : ∀ s, r ≤ s → 0 ≤ b s := by + apply fun s hs => feedback_lower_bound hr hc ?_ hder hs + intro s hs + rcases eq_or_lt_of_le hs.1 with h | h + · simp [← h, hz] + · exact (hi s ⟨h, hs.2⟩).le + have hpos : ∀ s ∈ Icc (r + 1) (r + 2), 0 < b s := by + intro s hs + have hmono : StrictMonoOn (fun t => t * b t) (Icc (r + 1) s) := by + apply strictMonoOn_of_deriv_pos (convex_Icc _ _) + (continuousOn_id.mul (hc.mono (by intro t ht; change r ≤ t; linarith [ht.1]))) + intro t ht + rw [interior_Icc] at ht + change 0 < deriv (fun t => t * b t) t + rw [(hd t ht.1).deriv] + exact add_pos_of_nonneg_of_pos (hn _ (by linarith [ht.1])) (hp _ (by linarith [ht.1])) + have hmass : (r + 1) * b (r + 1) ≤ s * b s := + hmono.monotoneOn ⟨le_rfl, hs.1⟩ ⟨hs.1, le_rfl⟩ hs.1 + have hfirst : 0 < b (r + 1) := hi _ ⟨by linarith, le_rfl⟩ + have hstart : 0 < (r + 1) * b (r + 1) := mul_pos (by linarith) hfirst + have hspos : 0 < s := by linarith [hs.1] + nlinarith + obtain ⟨m, hm, hmin⟩ := isCompact_Icc.exists_forall_le' + (hc.mono (by intro t ht; change r ≤ t; linarith [ht.1])) hpos + have htail : ∀ s, r + 1 ≤ s → m ≤ b s := by + intro s hs + apply feedback_lower_bound (r := r + 1) (by linarith) + (hc.mono (by intro t ht; change r ≤ t; exact le_trans (by linarith) ht)) ?_ ?_ hs + · simpa only [add_assoc, one_add_one_eq_two] using hmin + · intro t ht + exact hder t (by linarith) + intro hlim + have hevent : ∀ᶠ s in atTop, b s < m := (tendsto_order.mp hlim).2 m hm + obtain ⟨s, hs, hsm⟩ := (hevent.and (eventually_ge_atTop (r + 1))).exists + exact (not_lt_of_ge (htail s hsm)) hs + +theorem first_zero_of_nonpos {z : ℝ → ℝ} (hc : ContinuousOn z (Ici 1)) + (hi : ∀ s ∈ Icc 1 2, 0 < z s) {S : ℝ} (hS : 1 ≤ S) (hzS : z S ≤ 0) : + ∃ r, 2 < r ∧ z r = 0 ∧ ∀ s ∈ Ico 1 r, 0 < z s := by + have h2 : 0 < z 2 := hi _ ⟨by norm_num, le_rfl⟩ + have hS2 : 2 < S := by + by_contra h + exact (not_lt_of_ge hzS) (hi S ⟨hS, le_of_not_gt h⟩) + let Z : Set ℝ := Icc 2 S ∩ z ⁻¹' {0} + have hcont : ContinuousOn z (Icc 2 S) := hc.mono (by intro t ht; change 1 ≤ t; linarith [ht.1]) + have hcompact : IsCompact Z := isCompact_Icc.of_isClosed_subset + (hcont.preimage_isClosed_of_isClosed isClosed_Icc isClosed_singleton) inter_subset_left + obtain ⟨t, ht, hzt⟩ := intermediate_value_Icc' hS2.le hcont ⟨hzS, h2.le⟩ + have hne : Z.Nonempty := ⟨t, ht, hzt⟩ + obtain ⟨r, hr⟩ := hcompact.exists_isLeast hne + have hr2 : 2 ≤ r := hr.1.1.1 + have hrS : r ≤ S := hr.1.1.2 + have hzr : z r = 0 := hr.1.2 + have hr2' : 2 < r := lt_of_le_of_ne hr2 (by intro h; subst r; linarith) + refine ⟨r, hr2', hzr, ?_⟩ + intro s hs + by_cases hs2 : s ≤ 2 + · exact hi s ⟨hs.1, hs2⟩ + · by_contra h + have hz : z s ≤ 0 := le_of_not_gt h + have hcs : ContinuousOn z (Icc 2 s) := hc.mono (by intro t ht; change 1 ≤ t; linarith [ht.1]) + obtain ⟨t, ht, hzt⟩ := intermediate_value_Icc' (le_of_not_ge hs2) hcs ⟨hz, h2.le⟩ + have htr : r ≤ t := hr.2 ⟨⟨ht.1, by linarith [ht.2, hs.2]⟩, hzt⟩ + linarith [ht.2, hs.2] + +theorem no_first_zero {a c : ℝ → ℝ} {r : ℝ} (hr : 2 < r) + (ha : ContinuousOn a (Ici 1)) (har : a r = 0) + (hcprev : ∀ s ∈ Ico 1 r, 0 < c s) + (hsum : ∀ s, 1 ≤ s → 0 < a s + c s) + (hd : ∀ s, 2 < s → HasDerivAt (fun t => t * a t) (-c (s - 1)) s) + (hlim : Tendsto a atTop (𝓝 0)) : False := by + let b : ℝ → ℝ := fun s => -a s + have hbc : ContinuousOn b (Ici r) := ha.neg.mono (by intro t ht; change 1 ≤ t; exact le_trans (by linarith) ht) + have hbder : ∀ s, 2 < s → HasDerivAt (fun t => t * b t) (c (s - 1)) s := by + intro s hs + convert! (hd s hs).neg using 1 <;> simp [b] + rfl + have hbi : ∀ s ∈ Ioc r (r + 1), 0 < b s := by + intro s hs + have hm : StrictMonoOn (fun t => t * b t) (Icc r s) := by + apply strictMonoOn_of_deriv_pos (convex_Icc _ _) + (continuousOn_id.mul (hbc.mono (fun _ ht => ht.1))) + intro t ht + rw [interior_Icc] at ht + change 0 < deriv (fun t => t * b t) t + rw [(hbder t (by linarith [ht.1])).deriv] + exact hcprev _ ⟨by linarith [ht.1], by linarith [ht.2, hs.2]⟩ + have hmass := hm ⟨le_rfl, hs.1.le⟩ ⟨hs.1.le, le_rfl⟩ hs.1 + have hbr : b r = 0 := by simp [b, har] + change r * b r < s * b s at hmass + rw [hbr, mul_zero] at hmass + exact (mul_pos_iff_of_pos_left (by linarith [hs.1] : 0 < s)).mp hmass + apply feedback_not_tendsto_zero (d := fun s => a s + c s) (by linarith) hbc + (by simp [b, har]) hbi (fun s hs => hsum s (by linarith)) ?_ + · simpa only [b, neg_zero] using hlim.neg + · intro s hs + convert! hbder s (by linarith) using 1 + dsimp [b] + ring + +theorem paired_pos {a c : ℝ → ℝ} + (ha : ContinuousOn a (Ici 1)) (hc : ContinuousOn c (Ici 1)) + (hai : ∀ s ∈ Icc 1 2, 0 < a s) (hci : ∀ s ∈ Icc 1 2, 0 < c s) + (hsum : ∀ s, 1 ≤ s → 0 < a s + c s) + (hda : ∀ s, 2 < s → HasDerivAt (fun t => t * a t) (-c (s - 1)) s) + (hdc : ∀ s, 2 < s → HasDerivAt (fun t => t * c t) (-a (s - 1)) s) + (hla : Tendsto a atTop (𝓝 0)) (hlc : Tendsto c atTop (𝓝 0)) : + ∀ s, 1 ≤ s → 0 < a s ∧ 0 < c s := by + intro S hS + by_contra h + have hbad : min (a S) (c S) ≤ 0 := by + exact le_of_not_gt (fun hpos => h (lt_min_iff.mp hpos)) + obtain ⟨r, hr, hzero, hpre⟩ := first_zero_of_nonpos (ha.inf hc) + (fun s hs => lt_min (hai s hs) (hci s hs)) hS hbad + by_cases harc : a r ≤ c r + · have har : a r = 0 := by simpa only [min_eq_left harc] using hzero + exact no_first_zero hr ha har (fun s hs => (lt_min_iff.mp (hpre s hs)).2) hsum hda hla + · have hcr : c r = 0 := by simpa only [min_eq_right (le_of_not_ge harc)] using hzero + exact no_first_zero hr hc hcr (fun s hs => (lt_min_iff.mp (hpre s hs)).1) + (fun s hs => by simpa only [add_comm] using hsum s hs) hdc hlc + +end NumberTheoryLean.PairedDeficitPositivity + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ParentProductReadout.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ParentProductReadout.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f9b749b9ef41f04eda612bc948af9b30b71c9d3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ParentProductReadout.lean @@ -0,0 +1,43 @@ +import OAI.NumberTheory.Jacobsthal.Paths.GeometricEdgeWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ParentProductReadout +open ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection SingletonBinProduct TwoPrimeObservableSum ParentTailPartition +open PrimeHistories BinCutSelections BinCutPrefixGeometry SelectionWordSplit GeometricEdgeWitness +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition + +attribute [local instance] Classical.propDecidable + +theorem parent_product_readout {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (f : Fin n → Finset ℕ) (hf : f ∈ selections P m) (i j : Fin n) (hji : j < i) (hi : m i=1) : + selectionProduct (aboveSelection f j)=pickedPrime f i*selectionProduct (parentCofactorSelection f i j) := by + obtain ⟨p,_hp,hfi,_⟩ := singleton_selection_recovery P m i hi f hf + have hA : aboveSelection f j i={p} := by simp [aboveSelection,hji,hfi] + have hpick : pickedPrime f i=p := by simp [pickedPrime,hfi] + have he : eraseSelection (aboveSelection f j) i i=∅ := by simp [eraseSelection] + have hh := filled_product (eraseSelection (aboveSelection f j) i) i p he + rw [fill_erase (aboveSelection f j) i p hA,← hpick] at hh + exact hh + +theorem actual_prefix_product_readout {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (i j : Fin (binCount w top xi)) (hji : j < i) (hi : m i=1) + (pre tail : List ℕ) (u : ℕ) (he : descendingWord f=pre++u::tail) (hfu : f j={u}) : + pre.prod=pickedPrime f i*selectionProduct (parentCofactorSelection f i j) ∧ pickedPrime f j=u := by + have hsplit := selected_word_split hw htop hxi m f hf j u hfu + have hpre := decreasing_edge_prefix_unique (descendingWord f) pre tail (descendingWord (aboveSelection f j)) + (descendingWord (belowSelection f j)) u (descendingWord_strict f) he hsplit + refine ⟨?_,by simp [pickedPrime,hfu]⟩ + rw [hpre,above_word_product hw htop hxi m f hf j] + exact parent_product_readout (globalBins w top xi) m f hf i j hji hi +end NumberTheoryLean.ParentProductReadout + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ParentProgression.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ParentProgression.lean new file mode 100644 index 0000000000000000000000000000000000000000..dae2349714dcccd0f758d8c97e57a7e92685d828 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ParentProgression.lean @@ -0,0 +1,56 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeHitRepresentative + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseHits + +noncomputable def parentSlope (p q : ℕ) [NeZero p] (hqp : q.Coprime p) (a b : ℕ) : ℕ := + (((a : ZMod p)-(b : ZMod p))*(↑((ZMod.unitOfCoprime q hqp)⁻¹) : ZMod p)).val + +theorem parentSlope_lt (p q : ℕ) [NeZero p] (hqp : q.Coprime p) (a b : ℕ) : + parentSlope p q hqp a b < p := ZMod.val_lt _ + +theorem parent_start_mod_p (p q : ℕ) [NeZero p] (hqp : q.Coprime p) (a b : ℕ) : + Nat.ModEq p (b+q*parentSlope p q hqp a b) a := by + apply (ZMod.natCast_eq_natCast_iff _ _ _).mp + simp only [Nat.cast_add,Nat.cast_mul,parentSlope,ZMod.natCast_zmod_val] + have hu : (q : ZMod p)*(↑((ZMod.unitOfCoprime q hqp)⁻¹) : ZMod p) = 1 := by + simpa only [ZMod.coe_unitOfCoprime] using (ZMod.unitOfCoprime q hqp).mul_inv + calc + (b : ZMod p)+(q : ZMod p)*(((a : ZMod p)-(b : ZMod p))*↑((ZMod.unitOfCoprime q hqp)⁻¹)) = + (b : ZMod p)+((a : ZMod p)-(b : ZMod p))*((q : ZMod p)*↑((ZMod.unitOfCoprime q hqp)⁻¹)) := by ring + _ = _ := by rw [hu];ring + +theorem parent_start_mod_q (p q : ℕ) [NeZero p] (hqp : q.Coprime p) (a b : ℕ) : + Nat.ModEq q (b+q*parentSlope p q hqp a b) b := by + change (b+q*parentSlope p q hqp a b)%q = b%q + simp + +theorem parent_start_bounds (p q : ℕ) [NeZero p] (hqp : q.Coprime p) (a b : ℕ) + (hb1 : 1 ≤ b) (hbq : b ≤ q) : + 1 ≤ b+q*parentSlope p q hqp a b ∧ b+q*parentSlope p q hqp a b ≤ p*q := by + have hs := parentSlope_lt p q hqp a b + constructor + · omega + · nlinarith + +theorem parent_hit_iff (p q : ℕ) [NeZero p] (hqp : q.Coprime p) (a b n : ℕ) : + (Nat.ModEq p n a ∧ Nat.ModEq q n b) ↔ + Nat.ModEq (p*q) n (b+q*parentSlope p q hqp a b) := by + rw [← Nat.modEq_and_modEq_iff_modEq_mul hqp.symm] + have hp := parent_start_mod_p p q hqp a b + have hq := parent_start_mod_q p q hqp a b + exact and_congr ⟨fun h => h.trans hp.symm,fun h => h.trans hp⟩ + ⟨fun h => h.trans hq.symm,fun h => h.trans hq⟩ + +end ErdosInverseHits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PatternCardGrowth.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PatternCardGrowth.lean new file mode 100644 index 0000000000000000000000000000000000000000..2dbe14bec216806bf87a462b076967817838ba46 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PatternCardGrowth.lean @@ -0,0 +1,37 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SourceFullEventCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceLargeCount ErdosInverseEuler ErdosInverseBoxHeight + +theorem patternCard_le_smallModulus_sq (w : ℝ) (H : ℕ) : + patternCard (divisorModulus w H) (coprimeModulus w H) ≤ (smallModulus w)^2 := by + let T0 := divisorModulus w H + let T1 := coprimeModulus w H + calc + _ = (T0*T1)*(T0.totient*T1.totient) := by unfold patternCard;ring + _ ≤ (T0*T1)*(T0*T1) := Nat.mul_le_mul_left _ (Nat.mul_le_mul (Nat.totient_le _) (Nat.totient_le _)) + _ = (smallModulus w)^2 := by rw [pattern_moduli_product,pow_two] + +theorem source_patternCard_Z : ∀ᶠ z : ℝ in atTop,∀ H : ℕ, + (patternCard (divisorModulus (sourceW z) H) (coprimeModulus (sourceW z) H) : ℝ) ≤ sourceZ z := by + filter_upwards [smallModulus_source_power 2 1 zero_lt_one] with z hz + intro H + have hh : (patternCard (divisorModulus (sourceW z) H) (coprimeModulus (sourceW z) H) : ℝ) ≤ + (smallModulus (sourceW z) : ℝ)^2 := by exact_mod_cast patternCard_le_smallModulus_sq (sourceW z) H + exact hh.trans (by simpa only [Real.rpow_one] using hz) + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PatternMainTerm.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PatternMainTerm.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d36d05dadcbe1546fc1ad1f1f583d9e8d96ccfc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PatternMainTerm.lean @@ -0,0 +1,85 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeProductOmissions +import OAI.NumberTheory.Jacobsthal.Sieve.SourcePairSieve + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosVarianceLargeCount +open NumberTheoryLean ErdosHyperbolaError ErdosPrimeInputs.PrimeProductOmissions +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +def patternCard (T0 T1 : ℕ) : ℕ := T0*T0.totient*T1*T1.totient + +theorem patternCard_pos (T0 T1 : ℕ) (hT0 : 0 < T0) (hT1 : 0 < T1) : 0 < patternCard T0 T1 := by + unfold patternCard + exact mul_pos (mul_pos (mul_pos hT0 (Nat.totient_pos.mpr hT0)) hT1) (Nat.totient_pos.mpr hT1) + +theorem sourceMain_totient_cancellation (H T0 T1 : ℕ) (hH : 0 < H) (hT0 : 0 < T0) (hT1 : 0 < T1) + (hT0H : T0 ∣ H) (hcop : H.Coprime T1) (U V : ℝ) : + sourceMain H T0 T1 U V*((H*T1 : ℕ) : ℝ)/((H*T1).totient : ℝ) = + U*(V/(H : ℝ))/(patternCard T0 T1 : ℝ) := by + have hHN : (H : ℝ) ≠ 0 := by exact_mod_cast hH.ne' + have h0N : (T0 : ℝ) ≠ 0 := by exact_mod_cast hT0.ne' + have h1N : (T1 : ℝ) ≠ 0 := by exact_mod_cast hT1.ne' + have hph : (H.totient : ℝ) ≠ 0 := by exact_mod_cast (Nat.totient_pos.mpr hH).ne' + have hp0 : (T0.totient : ℝ) ≠ 0 := by exact_mod_cast (Nat.totient_pos.mpr hT0).ne' + have hp1 : (T1.totient : ℝ) ≠ 0 := by exact_mod_cast (Nat.totient_pos.mpr hT1).ne' + unfold sourceMain patternCard + rw [source_totient_product H T0 hT0H hT0,Nat.totient_mul hcop] + push_cast + field_simp + +theorem source_main_uniform_upper : ∃ C v0 : ℝ,0 < C ∧ 2 ≤ v0 ∧ + ∀ v : ℝ,v0 ≤ v → ∀ (H T0 T1 : ℕ),0 < H → 0 < T0 → 0 < T1 → + T0 ∣ H → H.Coprime T1 → ∀ (U V s : ℝ),0 ≤ U → 0 ≤ V → V ≤ 2*(H : ℝ) → 0 ≤ s → + sourceMain H T0 T1 U V* + (∏ t ∈ reducedPrimes ⌊v⌋₊ (H*T1),(1-1/(t : ℝ)))* + (1+Real.exp (-s/96)) ≤ C*U/((patternCard T0 T1 : ℝ)*Real.log v) := by + obtain ⟨C,v0,hC,hv0,hEuler⟩ := reduced_product_upper + refine ⟨4*C,v0,by positivity,hv0,?_⟩ + intro v hv H T0 T1 hH hT0 hT1 hT0H hcop U V s hU hV hVH hs + have hv1 : 1 < v := by linarith + have hlog : 0 < Real.log v := Real.log_pos hv1 + have hHN : (0 : ℝ) < H := by exact_mod_cast hH + have hpat : (0 : ℝ) < patternCard T0 T1 := by exact_mod_cast patternCard_pos T0 T1 hT0 hT1 + have hX : 0 ≤ sourceMain H T0 T1 U V := by dsimp [sourceMain];positivity + have he := hEuler v hv (H*T1) (mul_pos hH hT1) + have hmul := mul_le_mul_of_nonneg_left he hX + have heq : sourceMain H T0 T1 U V*(C*(((H*T1 : ℕ) : ℝ)/((H*T1).totient : ℝ))/Real.log v) = + C*(U*(V/(H : ℝ))/(patternCard T0 T1 : ℝ))/Real.log v := by + rw [show sourceMain H T0 T1 U V*(C*(((H*T1 : ℕ) : ℝ)/((H*T1).totient : ℝ))/Real.log v) = + C*(sourceMain H T0 T1 U V*((H*T1 : ℕ) : ℝ)/((H*T1).totient : ℝ))/Real.log v by ring, + sourceMain_totient_cancellation H T0 T1 hH hT0 hT1 hT0H hcop] + have hEuler' : sourceMain H T0 T1 U V* + (∏ t ∈ reducedPrimes ⌊v⌋₊ (H*T1),(1-1/(t : ℝ))) ≤ + C*(U*(V/(H : ℝ))/(patternCard T0 T1 : ℝ))/Real.log v := by + simpa only [ErdosPrimeInputs.SubsetPrimeSieve.euler,one_div] using hmul.trans_eq heq + have hVdiv : V/(H : ℝ) ≤ 2 := (div_le_iff₀ hHN).mpr hVH + have hEexp : 1+Real.exp (-s/96) ≤ 2 := by + have hh : Real.exp (-s/96) ≤ 1 := Real.exp_le_one_iff.mpr (by linarith) + linarith + have hm1 := mul_le_mul_of_nonneg_right hEuler' (show 0 ≤ 1+Real.exp (-s/96) by positivity) + have hm2 := mul_le_mul_of_nonneg_left hEexp + (show 0 ≤ C*(U*(V/(H : ℝ))/(patternCard T0 T1 : ℝ))/Real.log v by positivity) + have hlast : (C*(U*(V/(H : ℝ))/(patternCard T0 T1 : ℝ))/Real.log v)*2 ≤ + (4*C)*U/((patternCard T0 T1 : ℝ)*Real.log v) := by + calc + _ = (2*C*U/((patternCard T0 T1 : ℝ)*Real.log v))*(V/(H : ℝ)) := by ring + _ ≤ (2*C*U/((patternCard T0 T1 : ℝ)*Real.log v))*2 := + mul_le_mul_of_nonneg_left hVdiv (by positivity) + _ = _ := by ring + exact hm1.trans (hm2.trans hlast) + +end ErdosVarianceLargeCount + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositionDensities.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositionDensities.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4c8b4bbf8d6bfac924ca6ef5b6dfde330d400b5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositionDensities.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Analysis.PairDensityExpansion + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosVarianceMoments +attribute [local instance] Classical.decEq + +noncomputable def positionResidues (S : Finset ℕ) (p : ℕ) : Finset (ZMod p) := S.image (fun j : ℕ => (j : ZMod p)) + +noncomputable def forbiddenClasses (S : Finset ℕ) (p : ℕ) (u : (ZMod p)ˣ) (c : ZMod p) : Finset (ZMod p) := + S.image (fun j : ℕ => c-(u : ZMod p)*(j : ZMod p)) + +theorem affine_forbidden_injective (p : ℕ) (u : (ZMod p)ˣ) (c : ZMod p) : + Function.Injective (fun x : ZMod p => c-(u : ZMod p)*x) := by + intro x y h + have hm : (u : ZMod p)*x = (u : ZMod p)*y := by linear_combination -h + have hh := congrArg (fun z : ZMod p => (↑(u⁻¹) : ZMod p)*z) hm + simpa only [← mul_assoc,u.inv_mul,one_mul] using hh + +theorem forbiddenClasses_card (S : Finset ℕ) (p : ℕ) (u : (ZMod p)ˣ) (c : ZMod p) : + (forbiddenClasses S p u c).card = (positionResidues S p).card := by + have he : forbiddenClasses S p u c = (positionResidues S p).image (fun x => c-(u : ZMod p)*x) := by + simp only [forbiddenClasses,positionResidues,Finset.image_image,Function.comp_def] + rw [he,Finset.card_image_of_injective _ (affine_forbidden_injective p u c)] + +theorem mem_forbiddenClasses (S : Finset ℕ) (p : ℕ) (u : (ZMod p)ˣ) (c x : ZMod p) : + x ∈ forbiddenClasses S p u c ↔ ∃ j ∈ S,x+(u : ZMod p)*(j : ZMod p) = c := by + simp only [forbiddenClasses,Finset.mem_image] + constructor + · rintro ⟨j,hj,he⟩ + exact ⟨j,hj,by linear_combination -he⟩ + · rintro ⟨j,hj,he⟩ + exact ⟨j,hj,by linear_combination -he⟩ + +theorem positionResidues_le_positions (S : Finset ℕ) (p : ℕ) : (positionResidues S p).card ≤ S.card := + Finset.card_image_le + +theorem positionResidues_le_modulus (S : Finset ℕ) (p : ℕ) [NeZero p] : (positionResidues S p).card ≤ p := by + have hh := Finset.card_le_univ (positionResidues S p) + simpa only [ZMod.card] using hh + +theorem forbiddenClasses_full_of_card (S : Finset ℕ) (p : ℕ) [NeZero p] + (u : (ZMod p)ˣ) (c : ZMod p) (hfull : (positionResidues S p).card = p) : + forbiddenClasses S p u c = Finset.univ := by + apply Finset.eq_of_subset_of_card_le (Finset.subset_univ _) + simp only [Finset.card_univ,ZMod.card,forbiddenClasses_card,hfull] + exact le_rfl + +end ErdosVarianceMoments + +end + +section + +namespace ErdosVarianceMoments +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def positionDensity (S : Finset ℕ) (p : ℕ) : ℝ := + ((positionResidues S p).card : ℝ)/(p : ℝ) + +noncomputable def jointDensity (P S : Finset ℕ) : ℝ := ∏ p ∈ P,(1-positionDensity S p) + +theorem positionDensity_bounds (S : Finset ℕ) (p : ℕ) [NeZero p] : + 0 ≤ positionDensity S p ∧ positionDensity S p ≤ 1 := by + have hp : (0 : ℝ) < p := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne p) + refine ⟨by dsimp [positionDensity];positivity,?_⟩ + apply (div_le_one hp).mpr + exact_mod_cast positionResidues_le_modulus S p + +theorem positionDensity_le_two (S : Finset ℕ) (hS : S.card ≤ 2) (p : ℕ) [NeZero p] : + positionDensity S p ≤ 2/(p : ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact_mod_cast (positionResidues_le_positions S p).trans hS + +theorem positionResidues_singleton (j p : ℕ) : (positionResidues {j} p).card = 1 := by + simp only [positionResidues,Finset.image_singleton,Finset.card_singleton] + +theorem positionResidues_pair (i j p : ℕ) : + (positionResidues {i,j} p).card = if Nat.ModEq p i j then 1 else 2 := by + by_cases h : Nat.ModEq p i j + · have he := (ZMod.natCast_eq_natCast_iff _ _ _).mpr h + simp only [positionResidues,Finset.image_insert,Finset.image_singleton,he,Finset.insert_eq_of_mem + (Finset.mem_singleton_self _),Finset.card_singleton,ite_eq_left h] + · have he : (i : ZMod p) ≠ (j : ZMod p) := by + intro he + exact h ((ZMod.natCast_eq_natCast_iff _ _ _).mp he) + have hnot : (i : ZMod p) ∉ ({(j : ZMod p)} : Finset (ZMod p)) := by + simpa only [Finset.mem_singleton] using he + simp only [positionResidues,Finset.image_insert,Finset.image_singleton, + Finset.card_insert_of_notMem hnot,Finset.card_singleton,ite_eq_right h] + +theorem jointDensity_singleton (P : Finset ℕ) (j : ℕ) : + jointDensity P {j} = ErdosRandomVariance.sieveProduct P := by + simp only [jointDensity,positionDensity,positionResidues_singleton,Nat.cast_one,ErdosRandomVariance.sieveProduct] + +theorem jointDensity_pair (P : Finset ℕ) (i j : ℕ) : + jointDensity P {i,j} = ErdosRandomVariance.pairKernel P i j := by + apply Finset.prod_congr rfl + intro p _hp + by_cases h : Nat.ModEq p i j + · simp only [positionDensity,positionResidues_pair,ite_eq_left h,Nat.cast_one, + ErdosRandomVariance.congruenceIndicator] + ring + · simp only [positionDensity,positionResidues_pair,ite_eq_right h,Nat.cast_ofNat, + ErdosRandomVariance.congruenceIndicator] + ring + +end ErdosVarianceMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositiveGapMajorant.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositiveGapMajorant.lean new file mode 100644 index 0000000000000000000000000000000000000000..6ca4544a2d970c9626940e14a9abd5ed51b4b9d4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositiveGapMajorant.lean @@ -0,0 +1,50 @@ +import Mathlib.Topology.UrysohnsLemma +import OAI.NumberTheory.Jacobsthal.Primes.PrimeOccupationDensity + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PositiveGapMajorant + +open _root_.Set + +theorem exists_positive_gap_majorant (K : ℝ) : ∃ H : C(ℝ×ℝ,ℝ), + HasCompactSupport H ∧ (∀ x,0 ≤ H x ∧ H x ≤ 1) ∧ + (∀ r s,2 ≤ r → r ≤ K → 0 ≤ s → s ≤ K → H (r,s)=1) ∧ + ∀ r s,r < 1 ∨ K+1 < r → H (r,s)=0 := by + let A : Set (ℝ×ℝ) := Icc (2,0) (K,K) + let Z : Set (ℝ×ℝ) := {x | x.1 ≤ 1} ∪ {x | K+1 ≤ x.1} + have hA : IsCompact A := isCompact_Icc + have hZ : IsClosed Z := (isClosed_le continuous_fst continuous_const).union + (isClosed_le continuous_const continuous_fst) + have hd : Disjoint A Z := by + apply Set.disjoint_left.mpr + intro x hx hz + have hlow : 2 ≤ x.1 := hx.1.1 + have hhigh : x.1 ≤ K := hx.2.1 + rcases hz with hz | hz + · change x.1 ≤ 1 at hz + linarith + · change K+1 ≤ x.1 at hz + linarith + obtain ⟨H,hHA,hHZ,hcompact,hbounds⟩ := exists_continuous_one_zero_of_isCompact hA hZ hd + refine ⟨H,hcompact,hbounds,?_,?_⟩ + · intro r s hr hrK hs hsK + exact hHA ⟨⟨hr,hs⟩,⟨hrK,hsK⟩⟩ + · intro r s hbad + apply hHZ + rcases hbad with h | h + · exact Or.inl h.le + · exact Or.inr h.le + +end NumberTheoryLean.PositiveGapMajorant + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositiveProgression.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositiveProgression.lean new file mode 100644 index 0000000000000000000000000000000000000000..b33cad2a62fdc6c5ed4afa7b6614eb184556eb23 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PositiveProgression.lean @@ -0,0 +1,88 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseHits + +def hitLength (Y M b : ℕ) : ℕ := (Y+M-b)/M + +theorem lt_hitLength_iff (Y M b j : ℕ) (hM : 0 < M) (hb : b ≤ M) : + j < hitLength Y M b ↔ b+M*j ≤ Y := by + unfold hitLength + rw [Nat.lt_iff_add_one_le,Nat.le_div_iff_mul_le hM, + Nat.le_sub_iff_add_le (by omega : b ≤ Y+M)] + constructor <;> intro h <;> nlinarith + +theorem exists_positive_coordinate (M b n : ℕ) (_hM : 0 < M) + (hb1 : 1 ≤ b) (hbM : b ≤ M) (hn : 1 ≤ n) (hres : Nat.ModEq M n b) : + ∃ j : ℕ,n = b+M*j := by + have hsub : Nat.ModEq M (n-1) (b-1) := by + apply Nat.ModEq.add_left_cancel' 1 + simpa only [Nat.add_sub_of_le hn,Nat.add_sub_of_le hb1] using hres + have hbsmall : b-1 < M := by omega + have hrem : (n-1)%M = b-1 := by + change (n-1)%M = (b-1)%M at hsub + simpa only [Nat.mod_eq_of_lt hbsmall] using hsub + refine ⟨(n-1)/M,?_⟩ + have heq := Nat.mod_add_div (n-1) M + rw [hrem] at heq + omega + +noncomputable def positiveHits (Y M b : ℕ) : Finset ℕ := by + classical + exact (Finset.Icc 1 Y).filter (fun n => Nat.ModEq M n b) + +theorem positiveHits_eq_image (Y M b : ℕ) (hM : 0 < M) (hb1 : 1 ≤ b) (hbM : b ≤ M) : + positiveHits Y M b = (Finset.range (hitLength Y M b)).image (fun j => b+M*j) := by + classical + ext n + simp only [positiveHits,Finset.mem_filter,Finset.mem_Icc,Finset.mem_image,Finset.mem_range] + constructor + · rintro ⟨⟨hn1,hnY⟩,hres⟩ + obtain ⟨j,rfl⟩ := exists_positive_coordinate M b n hM hb1 hbM hn1 hres + exact ⟨j,(lt_hitLength_iff Y M b j hM hbM).mpr hnY,rfl⟩ + · rintro ⟨j,hj,rfl⟩ + refine ⟨⟨by omega,(lt_hitLength_iff Y M b j hM hbM).mp hj⟩,?_⟩ + change (b+M*j)%M = b%M + simp + +theorem positiveHits_card (Y M b : ℕ) (hM : 0 < M) (hb1 : 1 ≤ b) (hbM : b ≤ M) : + (positiveHits Y M b).card = hitLength Y M b := by + rw [positiveHits_eq_image Y M b hM hb1 hbM,Finset.card_image_of_injective] + · exact Finset.card_range _ + · intro i j hij + exact Nat.eq_of_mul_eq_mul_left hM (Nat.add_left_cancel hij) + +theorem hitLength_error (Y M b : ℕ) (hM : 0 < M) (hb1 : 1 ≤ b) (hbM : b ≤ M) : + |(hitLength Y M b : ℝ)-(Y : ℝ)/M| ≤ 1 := by + have hsub : b ≤ Y+M := by omega + have hdivision := Nat.mod_add_div (Y+M-b) M + have hmod := Nat.mod_lt (Y+M-b) hM + have heq : (((Y+M-b)%M : ℕ) : ℝ)+(M : ℝ)*hitLength Y M b = (Y : ℝ)+M-b := by + simpa only [hitLength,Nat.cast_add,Nat.cast_mul,Nat.cast_sub hsub] using + congrArg (fun n : ℕ => (n : ℝ)) hdivision + have hmR : (0 : ℝ) < M := by exact_mod_cast hM + have hrR : (((Y+M-b)%M : ℕ) : ℝ) < M := by exact_mod_cast hmod + have hbR : (b : ℝ) ≤ M := by exact_mod_cast hbM + have hbR1 : (1 : ℝ) ≤ b := by exact_mod_cast hb1 + have hremR : (0 : ℝ) ≤ ((Y+M-b)%M : ℕ) := Nat.cast_nonneg _ + have hlo : (Y : ℝ)/M ≤ (hitLength Y M b : ℝ)+1 := by + apply (div_le_iff₀ hmR).mpr + nlinarith + have hhi : (hitLength Y M b : ℝ)-1 ≤ (Y : ℝ)/M := by + apply (le_div_iff₀ hmR).mpr + nlinarith + rw [abs_le] + constructor <;> linarith + +end ErdosInverseHits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrimitiveThreeQuarters.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrimitiveThreeQuarters.lean new file mode 100644 index 0000000000000000000000000000000000000000..83676608f2d305253f8cede65b2c3b5a514720ce --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrimitiveThreeQuarters.lean @@ -0,0 +1,98 @@ +import OAI.NumberTheory.Jacobsthal.Primes.TwoPrimeRoots + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman.PrimePower + +theorem quadraticUnitRoots_card_le_four_prime_power (p s : ℕ) [Fact p.Prime] + (hs : 0 < s) (a b : ZMod (p^s)) (ha : IsUnit a) : + (quadraticUnitRoots (p^s) a b).card ≤ 4 := by + by_cases hp2 : p = 2 + · subst p + exact quadraticUnitRoots_card_le_four s hs a b ha + · exact (quadraticUnitRoots_card_le_two p s hs hp2 a b ha).trans (by decide) + +theorem int_frequency_isUnit (p s : ℕ) [Fact p.Prime] (hs : 0 < s) (h : ℤ) + (hh : (h : ZMod p) ≠ 0) : IsUnit (h : ZMod (p^s)) := by + apply (isUnit_iff_primeReduction_ne_zero p s hs _).mpr + simpa only [map_intCast] using hh + +theorem primitive_half_bound (p r s : ℕ) [Fact p.Prime] (hs : 0 < s) (hsr : s ≤ r) + (h k : ℤ) (hhk : (h : ZMod p) ≠ 0 ∨ (k : ZMod p) ≠ 0) : + ‖standardSum (p^(r+s)) h k‖ ≤ 4 * (p^r : ℕ) := by + have left (h k : ℤ) (hh : (h : ZMod p) ≠ 0) : + ‖standardSum (p^(r+s)) h k‖ ≤ 4 * (p^r : ℕ) := by + have hn := standard_norm_le_stationary_card p r s hsr h k + have hc := stationary_card_le_root_card_mul (p^r) (p^s) + (h : ZMod (p^r*p^s)) (k : ZMod (p^r*p^s)) + have hr : (quadraticUnitRoots (p^s) + (reduction (p^r) (p^s) (h : ZMod (p^r*p^s))) + (reduction (p^r) (p^s) (k : ZMod (p^r*p^s)))).card ≤ 4 := by + simpa only [map_intCast] using quadraticUnitRoots_card_le_four_prime_power p s hs + (h : ZMod (p^s)) (k : ZMod (p^s)) (int_frequency_isUnit p s hs h hh) + have hc4 := hc.trans (Nat.mul_le_mul_right (p^r) hr) + have hc4real : ((stationaryUnits ((p^r : ℕ) : ZMod (p^r*p^s)) + (h : ZMod (p^r*p^s)) k).card : ℝ) ≤ 4 * (p^r : ℕ) := by + exact_mod_cast hc4 + have transport (N : ℕ) [NeZero N] (hN : N = p^r*p^s) : + ((stationaryUnits ((p^r : ℕ) : ZMod N) (h : ZMod N) k).card : ℝ) ≤ + 4 * (p^r : ℕ) := by + subst N + exact hc4real + exact hn.trans (transport (p^(r+s)) (pow_add p r s)) + rcases hhk with hh | hk + · exact left h k hh + · have he : standardSum (p^(r+s)) h k = standardSum (p^(r+s)) k h := + sum_swap ZMod.stdAddChar (h : ZMod (p^(r+s))) (k : ZMod (p^(r+s))) + rw [he] + exact left k h hk + +end ErdosKloosterman.PrimePower + +end + +section + +namespace ErdosKloosterman.PrimePower + +theorem standardSum_modulus_congr (N M : ℕ) [NeZero N] [NeZero M] + (hNM : N = M) (h k : ℤ) : standardSum N h k = standardSum M h k := by + subst M + rfl + +theorem ceiling_half_le_three_quarters (p a : ℕ) (hp : 1 ≤ p) (ha : 2 ≤ a) : + ((p^(a-a/2) : ℕ) : ℝ) ≤ ((p^a : ℕ) : ℝ)^((3 : ℝ)/4) := by + have hexp : (a-a/2)*4 ≤ a*3 := by omega + have hnat : (p^(a-a/2))^4 ≤ (p^a)^3 := by + rw [← pow_mul, ← pow_mul] + exact Nat.pow_le_pow_right hp hexp + have hreal : (((p^(a-a/2) : ℕ) : ℝ))^4 ≤ (((p^a : ℕ) : ℝ))^3 := by + exact_mod_cast hnat + have he : ((((p^a : ℕ) : ℝ))^((3 : ℝ)/4))^4 = (((p^a : ℕ) : ℝ))^3 := by + rw [← Real.rpow_mul_natCast (Nat.cast_nonneg _)] + norm_num + rw [← he] at hreal + exact (pow_le_pow_iff_left₀ (by positivity) (by positivity) (by decide : 4 ≠ 0)).mp hreal + +theorem primitive_three_quarter_bound (p a : ℕ) [Fact p.Prime] (ha : 2 ≤ a) + (h k : ℤ) (hhk : (h : ZMod p) ≠ 0 ∨ (k : ZMod p) ≠ 0) : + ‖standardSum (p^a) h k‖ ≤ 4 * ((p^a : ℕ) : ℝ)^((3 : ℝ)/4) := by + have hs : 0 < a/2 := by omega + have hsr : a/2 ≤ a-a/2 := by omega + have he : a-a/2+a/2 = a := by omega + have hhalf := primitive_half_bound p (a-a/2) (a/2) hs hsr h k hhk + rw [standardSum_modulus_congr _ (p^a) (congrArg (p^·) he)] at hhalf + exact hhalf.trans (mul_le_mul_of_nonneg_left + (ceiling_half_le_three_quarters p a (Fact.out : p.Prime).one_le ha) (by positivity)) + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrimitiveTransfer.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrimitiveTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..bbf028f7aafe1bfd5795a4159c88f5fbbf821169 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrimitiveTransfer.lean @@ -0,0 +1,415 @@ +import OAI.NumberTheory.Jacobsthal.Primes.ZetaPoleBounds + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace Erdos970Dependency.SiegelWalfisz + +theorem exists_primitive_real_zero_free_disk : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ chi : DirichletCharacter ℂ q, chi.IsPrimitive → chi ≠ 1 → + (∀ a : ZMod q, (chi a).im = 0) → ∀ z : ℂ, + ‖z - 1‖ ≤ c / Real.log (q : ℝ) → DirichletCharacter.LFunction chi z ≠ 0 := by + obtain ⟨ce, hce, hexceptional⟩ := + WeightedTorusJets.exists_classical_near_one_zero_unique_real_simple + obtain ⟨cg, hcg, hgap⟩ := WeightedTorusJets.dirichletRealZeroBound_proof + let c : ℝ := min ce (min (cg / 2) (1 / 4)) + have hc : 0 < c := lt_min hce (lt_min (by positivity) (by norm_num)) + have hce' : c ≤ ce := min_le_left _ _ + have hcg' : c ≤ cg / 2 := (min_le_right _ _).trans (min_le_left _ _) + have hc4 : c ≤ 1 / 4 := (min_le_right _ _).trans (min_le_right _ _) + refine ⟨c, hc, ?_⟩ + intro q _ hq chi hprim hchi hreal z hz hzero + have hqR : (3 : ℝ) ≤ q := by exact_mod_cast hq + have hlog : 1 < Real.log (q : ℝ) := + (Real.lt_log_iff_exp_lt (by linarith)).mpr (Real.exp_one_lt_three.trans_le hqR) + have hlogpos : 0 < Real.log (q : ℝ) := by linarith + have hz' : ‖z - 1‖ ≤ ce / Real.log (q : ℝ) := + hz.trans (div_le_div_of_nonneg_right hce' hlogpos.le) + have him : z.im = 0 := (hexceptional q hq chi hprim hchi hreal z hz' hzero).1 + have hrad : c / Real.log (q : ℝ) ≤ 1 / 4 := by + apply (div_le_iff₀ hlogpos).mpr + nlinarith + have hre : |z.re - 1| ≤ c / Real.log (q : ℝ) := by + have h := Complex.abs_re_le_norm (z - 1) + simp only [Complex.sub_re, Complex.one_re] at h + exact h.trans hz + have hrep : 0 < z.re := by + have h := (abs_le.mp (hre.trans hrad)).1 + linarith + have hrelt : z.re < 1 := by + by_contra! h + exact DirichletCharacter.LFunction_ne_zero_of_one_le_re chi (Or.inl hchi) h hzero + have hrealz : (z.re : ℂ) = z := by + apply Complex.ext <;> simp [him] + have hzeroR : DirichletCharacter.LFunction chi (z.re : ℂ) = 0 := by + rw [hrealz] + exact hzero + have hlower := hgap q hq chi hprim hchi hreal z.re ⟨hrep, hrelt, hzeroR⟩ + have hupper : (1 - z.re) * Real.log (q : ℝ) ≤ c := by + apply (le_div_iff₀ hlogpos).mp + have h := (abs_le.mp hre).1 + linarith + linarith + + + + + +lemma zetaPole_real_nonneg {s : ℂ} (hs : 1 ≤ s.re) : 0 ≤ (1/(s-1)).re := by + simpa using real_zero_term_nonneg (w := s) (rho := (1:ℂ)) 1 (by simpa using hs) + +lemma zetaPole_real_eq (s : ℂ) : + (1/(s-1)).re = (s.re-1)/((s.re-1)^2+s.im^2) := by + rw [one_div, Complex.inv_re, Complex.normSq_apply] + simp only [Complex.sub_re, Complex.sub_im, Complex.one_re, Complex.one_im, sub_zero, pow_two] + +theorem exists_zeta_all_height_real_bound : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) [NeZero q] (s : ℂ), + 1 < s.re → s.re ≤ 2 → + (-logDeriv riemannZeta s).re ≤ C*(modulusHeight q s.im)^2+(1/(s-1)).re := by + obtain ⟨C0,hC0,hsmall⟩ := exists_zeta_small_height_real_bound + obtain ⟨A,hA,C1,hC1,hlarge⟩ := _root_.Erdos970.LogDerivZetaBndUnif2 + refine ⟨C0+C1+1, by positivity, ?_⟩ + intro q _ s hs hs2 + have hH := modulusHeight_ge_one q s.im + have hHsq : 1 ≤ (modulusHeight q s.im)^2 := by nlinarith + by_cases ht : |s.im| ≤ 6 + · have h := hsmall s hs hs2 ht + have hlift := mul_le_mul_of_nonneg_left hHsq (show 0 ≤ C0+C1+1 by positivity) + have hbound : C0 ≤ (C0+C1+1)*(modulusHeight q s.im)^2 := by nlinarith only [hlift,hC1] + linarith + · have ht6 : 6 < |s.im| := lt_of_not_ge ht + have ht3 : 3 < |s.im| := by linarith + have hlog : 0 < Real.log |s.im| := Real.log_pos (by linarith) + have hr : 0 ≤ A/Real.log |s.im| := div_nonneg hA.1.le hlog.le + have hstrip : s.re ∈ Set.Ici (1-A/(Real.log |s.im|)^1) := by + change 1-A/(Real.log |s.im|)^1 ≤ s.re + rw [pow_one] + linarith + have hz := hlarge s.re s.im ht3 hstrip + have hnorm : ‖logDeriv riemannZeta s‖ ≤ C1*(Real.log |s.im|)^2 := by + simpa only [logDeriv_apply, Complex.re_add_im] using hz + have hq : (1:ℝ) ≤ q := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr (NeZero.ne q) + have hlq := Real.log_nonneg hq + have hlogle : Real.log |s.im| ≤ modulusHeight q s.im := by + have h := Real.log_le_log (by linarith : 0 < |s.im|) (by linarith : |s.im| ≤ |s.im|+6) + unfold modulusHeight + linarith + have hsq : (Real.log |s.im|)^2 ≤ (modulusHeight q s.im)^2 := by nlinarith + have hreal := (Complex.re_le_norm (-logDeriv riemannZeta s)).trans + (by simpa only [norm_neg] using hnorm) + have hmul := mul_le_mul_of_nonneg_left hsq hC1.le + have hpole := zetaPole_real_nonneg hs.le + have hlift : C1*(modulusHeight q s.im)^2 ≤ (C0+C1+1)*(modulusHeight q s.im)^2 := + mul_le_mul_of_nonneg_right (by linarith) (sq_nonneg _) + linarith only [hreal, hmul, hlift, hpole] + +theorem exists_principal_all_height_real_bound : + ∃ C : ℝ, 0 < C ∧ ∀ (q : ℕ) [NeZero q] (s : ℂ), + 1 < s.re → s.re ≤ 2 → + (-logDeriv (DirichletCharacter.LFunctionTrivChar q) s).re ≤ + C*(modulusHeight q s.im)^2+(1/(s-1)).re := by + obtain ⟨C,hC,hzeta⟩ := exists_zeta_all_height_real_bound + refine ⟨C+1, by positivity, ?_⟩ + intro q _ s hs hs2 + have h := principal_neg_real_log_derivative_le q hs + have hz := hzeta q s hs hs2 + have hH := modulusHeight_ge_one q s.im + have hlog : Real.log (q:ℝ) ≤ modulusHeight q s.im := by + have hh : 0 ≤ Real.log (|s.im|+6) := Real.log_nonneg (by have := abs_nonneg s.im; linarith) + unfold modulusHeight + linarith + nlinarith only [h, hz, hH, hlog] + + + + + +lemma real_pole_bound_away_from_zero (q : ℕ) [NeZero q] (hq : 3 ≤ q) + {c sigma t : ℝ} (hc : 0 < c) (hs : 1 < sigma) (hs2 : sigma ≤ 2) + (ht : c/(2*Real.log (q:ℝ)) ≤ |t|) : + (1/(((sigma:ℂ)+(2*t:ℝ)*Complex.I)-1)).re ≤ + (1/c^2)*(modulusHeight q t)^2 := by + have hqR : (3:ℝ) ≤ q := by exact_mod_cast hq + have hL : 0 < Real.log (q:ℝ) := Real.log_pos (by linarith) + have htpos : 0 < |t| := (div_pos hc (by positivity)).trans_le ht + have htne : t ≠ 0 := abs_pos.mp htpos + have htsq : 0 < 4*t^2 := by positivity + have hc2 : 0 < c^2 := by positivity + have hct : c ≤ 2*Real.log (q:ℝ)*|t| := by + have h := (div_le_iff₀ (show 0 < 2*Real.log (q:ℝ) by positivity)).mp ht + nlinarith only [h] + have hcSq : c^2 ≤ 4*(Real.log (q:ℝ))^2*t^2 := by + have h : c^2 ≤ (2*Real.log (q:ℝ)*|t|)^2 := by gcongr + norm_num only [mul_pow, sq_abs] at h + exact h + have hp : Real.log (q:ℝ) ≤ modulusHeight q t := by + have hh : 0 ≤ Real.log (|t|+6) := Real.log_nonneg (by have := abs_nonneg t; linarith) + unfold modulusHeight + linarith + have hsq : (Real.log (q:ℝ))^2 ≤ (modulusHeight q t)^2 := by gcongr + rw [zetaPole_real_eq] + have hr : ((sigma:ℂ)+(2*t:ℝ)*Complex.I).re = sigma := by simp + have hi : ((sigma:ℂ)+(2*t:ℝ)*Complex.I).im = 2*t := by simp + rw [hr, hi] + calc + _ ≤ 1/(4*t^2) := by + apply (div_le_div_iff₀ (by positivity : 0 < (sigma-1)^2+(2*t)^2) htsq).mpr + have h := mul_le_mul_of_nonneg_right (show sigma-1 ≤ 1 by linarith) (sq_nonneg (2*t)) + nlinarith only [h, sq_nonneg (sigma-1)] + _ ≤ (Real.log (q:ℝ))^2/c^2 := (div_le_div_iff₀ htsq hc2).mpr (by nlinarith only [hcSq]) + _ ≤ (modulusHeight q t)^2/c^2 := div_le_div_of_nonneg_right hsq hc2.le + _ = _ := by ring + +theorem exists_quadratic_zero_reciprocal_bound (c : ℝ) (hc : 0 < c) : + ∃ K : ℝ, 0 < K ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ (chi : DirichletCharacter ℂ q), chi ≠ 1 → chi^2 = 1 → + ∀ sigma beta t : ℝ, 1 < sigma → sigma ≤ 2 → 3/4 ≤ beta → beta < 1 → + c/(2*Real.log (q:ℝ)) ≤ |t| → + DirichletCharacter.LFunction chi ((beta:ℂ)+(t:ℂ)*Complex.I) = 0 → + 4/(sigma-beta) ≤ 3/(sigma-1)+K*(modulusHeight q t)^2 := by + obtain ⟨Cp,hCp,hpen⟩ := uniform_zero_penalty + obtain ⟨Cu,hCu,hprincipal⟩ := exists_principal_all_height_real_bound + obtain ⟨Cz,hCz,hzeta⟩ := _root_.Erdos970.strongPnt_triv_bound_zeta + refine ⟨3*Cz+4*Cp+4*Cu+1/c^2, by positivity, ?_⟩ + intro q _ hq chi hchi hsq sigma beta t hs hs2 hb34 hb1 ht hzero + have hH := modulusHeight_ge_one q t + have hHsq : modulusHeight q t ≤ (modulusHeight q t)^2 := by nlinarith + have hOne : 1 ≤ (modulusHeight q t)^2 := by nlinarith + have h1 := hpen q chi hchi sigma beta t hs hs2 hb34 hb1 hzero + have h1' : (-deriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I) / + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I)).re ≤ + Cp*(modulusHeight q t)^2-1/(sigma-beta) := by + have hm := mul_le_mul_of_nonneg_left hHsq hCp.le + change _ ≤ Cp*modulusHeight q t-1/(sigma-beta) at h1 + linarith only [h1,hm] + have h2 := hprincipal q ((sigma:ℂ)+(2*t:ℝ)*Complex.I) (by simpa using hs) (by simpa using hs2) + have h2H : (modulusHeight q (2*t))^2 ≤ 4*(modulusHeight q t)^2 := by + have hh := modulusHeight_double_le q t + have hH2 := modulusHeight_ge_one q (2*t) + nlinarith + have hp := real_pole_bound_away_from_zero q hq hc hs hs2 ht + have h2' : (-deriv (DirichletCharacter.LFunction (1:DirichletCharacter ℂ q)) + ((sigma:ℂ)+(2*t:ℝ)*Complex.I) / + DirichletCharacter.LFunction (1:DirichletCharacter ℂ q) ((sigma:ℂ)+(2*t:ℝ)*Complex.I)).re ≤ + (4*Cu+1/c^2)*(modulusHeight q t)^2 := by + simp only [show ((sigma:ℂ)+(2*t:ℝ)*Complex.I).im = 2*t by simp, + DirichletCharacter.LFunctionTrivChar, logDeriv_apply, ← neg_div] at h2 + have hm := mul_le_mul_of_nonneg_left h2H hCu.le + nlinarith only [h2,hp,hm] + have hz := hzeta sigma 0 hs + simp only [Complex.ofReal_zero, zero_mul, add_zero] at hz + have hz' := (Complex.re_le_norm (-deriv riemannZeta (sigma:ℂ)/riemannZeta (sigma:ℂ))).trans hz + have hCz' : Cz ≤ Cz*(modulusHeight q t)^2 := by + simpa only [mul_one] using mul_le_mul_of_nonneg_left hOne hCz + have hpos := character_log_derivative_positivity chi sigma t hs + rw [hsq] at hpos + rw [one_div] at h1' h2' + simp only [div_eq_mul_inv] + nlinarith only [hpos,h1',h2',hz',hCz'] + + + + + +theorem exists_primitive_quadratic_zero_free_region : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ (chi : DirichletCharacter ℂ q), chi.IsPrimitive → chi ≠ 1 → chi^2 = 1 → + ∀ s : ℂ, 1-c/(modulusHeight q s.im)^2 ≤ s.re → + DirichletCharacter.LFunction chi s ≠ 0 := by + obtain ⟨cd,hcd,hdisk⟩ := exists_primitive_real_zero_free_disk + obtain ⟨K,hK,hineq⟩ := exists_quadratic_zero_reciprocal_bound cd hcd + let delta : ℝ := 1/(8*(K+1)) + have hd : 0 < delta := by dsimp [delta]; positivity + have hd8 : delta ≤ 1/8 := by + apply (div_le_iff₀ (by positivity : 0 < 8*(K+1))).mpr + nlinarith + have hKd : K*delta ≤ 1/8 := by + dsimp only [delta] + rw [mul_one_div] + apply (div_le_iff₀ (by positivity : 0 < 8*(K+1))).mpr + nlinarith + let c : ℝ := min (delta/4) (cd/4) + have hc : 0 < c := lt_min (by positivity) (by positivity) + have hcδ : c ≤ delta/4 := min_le_left _ _ + have hcc : c ≤ cd/2 := by have h := min_le_right (delta/4) (cd/4); change c ≤ cd/4 at h; linarith + refine ⟨c,hc,?_⟩ + intro q _ hq chi hprim hchi hsq s hs hzero + have hb1 : s.re < 1 := by + by_contra! h + exact DirichletCharacter.LFunction_ne_zero_of_one_le_re chi (Or.inl hchi) h hzero + let H : ℝ := (modulusHeight q s.im)^2 + have hbase := modulusHeight_ge_one q s.im + have hH : 1 ≤ H := by dsimp only [H]; nlinarith + have hHp : 0 < H := by linarith + let x : ℝ := delta/H + have hxp : 0 < x := by dsimp only [x]; positivity + have hxd : x ≤ delta := by + apply (div_le_iff₀ hHp).mpr + nlinarith + have hclose : 1-s.re ≤ x/4 := by + have h : c/H ≤ (delta/4)/H := div_le_div_of_nonneg_right hcδ hHp.le + have he : (delta/4)/H = x/4 := by dsimp only [x]; ring + rw [he] at h + change 1-c/H ≤ s.re at hs + linarith + have hb34 : 3/4 ≤ s.re := by linarith + have hsigma : 1 < 1+x := by linarith + have hsigma2 : 1+x ≤ 2 := by linarith + have hz : DirichletCharacter.LFunction chi ((s.re:ℂ)+(s.im:ℂ)*Complex.I) = 0 := by + simpa only [Complex.re_add_im] using hzero + have hheight : cd/(2*Real.log (q:ℝ)) ≤ |s.im| := by + by_contra! hlow + have hqR : (3:ℝ) ≤ q := by exact_mod_cast hq + have hL : 0 < Real.log (q:ℝ) := Real.log_pos (by linarith) + have hLH : Real.log (q:ℝ) ≤ H := by + have ht : 0 ≤ Real.log (|s.im|+6) := Real.log_nonneg (by have := abs_nonneg s.im; linarith) + have hle : Real.log (q:ℝ) ≤ modulusHeight q s.im := by unfold modulusHeight; linarith + dsimp only [H] + nlinarith + have hbeta : 1-s.re ≤ cd/(2*Real.log (q:ℝ)) := by + calc + _ ≤ c/H := by change 1-c/H ≤ s.re at hs; linarith + _ ≤ c/Real.log (q:ℝ) := div_le_div_of_nonneg_left hc.le hL hLH + _ ≤ (cd/2)/Real.log (q:ℝ) := div_le_div_of_nonneg_right hcc hL.le + _ = _ := by ring + have hnorm : ‖s-1‖ ≤ cd/Real.log (q:ℝ) := by + have h := Complex.norm_le_abs_re_add_abs_im (s-1) + simp only [Complex.sub_re,Complex.sub_im,Complex.one_re,Complex.one_im,sub_zero] at h + rw [abs_of_neg (by linarith : s.re-1 < 0)] at h + have he : 2*(cd/(2*Real.log (q:ℝ))) = cd/Real.log (q:ℝ) := by ring + linarith + have hreal : ∀ a : ZMod q, (chi a).im = 0 := + (RealCharacterAnalysis.real_values_iff_quadratic chi).mpr + (MulChar.isQuadratic_iff_sq_eq_one.mpr hsq) + exact hdisk q hq chi hprim hchi hreal s hnorm hzero + have hr := hineq q hq chi hchi hsq (1+x) s.re s.im hsigma hsigma2 hb34 hb1 hheight hz + let y : ℝ := 1+x-s.re + have hyp : 0 < y := by dsimp only [y]; linarith + have hy : y ≤ (5/4)*x := by dsimp only [y]; linarith + have hKx : K*H*x ≤ 1/8 := by + have he : K*H*x = K*delta := by dsimp only [x]; field_simp + rw [he] + exact hKd + change 4/y ≤ 3/(1+x-1)+K*H at hr + rw [add_sub_cancel_left] at hr + have h := mul_le_mul_of_nonneg_right ((div_le_iff₀ hyp).mp hr) hxp.le + have he : (3/x+K*H)*y*x = 3*y+K*H*x*y := by field_simp + rw [he] at h + have hKy := mul_le_mul_of_nonneg_right hKx hyp.le + nlinarith only [h,hKy,hy,hxp] + + + + + +theorem exists_primitive_zero_free_region : + ∃ c : ℝ, 0 < c ∧ ∀ (q : ℕ) [NeZero q], 3 ≤ q → + ∀ (chi : DirichletCharacter ℂ q), chi.IsPrimitive → chi ≠ 1 → + ∀ s : ℂ, 1-c/(modulusHeight q s.im)^2 ≤ s.re → + DirichletCharacter.LFunction chi s ≠ 0 := by + obtain ⟨cn,hcn,hnonquad⟩ := exists_nonquadratic_zero_free_region + obtain ⟨cq,hcq,hquad⟩ := exists_primitive_quadratic_zero_free_region + refine ⟨min cn cq,lt_min hcn hcq,?_⟩ + intro q _ hq chi hprim hchi s hs + have hH := modulusHeight_ge_one q s.im + have hHp : 0 < modulusHeight q s.im := by linarith + by_cases hsq : chi^2 = 1 + · apply hquad q hq chi hprim hchi hsq s + have h := div_le_div_of_nonneg_right (min_le_right cn cq) + (sq_nonneg (modulusHeight q s.im)) + linarith + · apply hnonquad q chi hsq s + have h1 : min cn cq/(modulusHeight q s.im)^2 ≤ min cn cq/modulusHeight q s.im := + div_le_div_of_nonneg_left (lt_min hcn hcq).le hHp (by nlinarith) + have h2 : min cn cq/modulusHeight q s.im ≤ cn/modulusHeight q s.im := + div_le_div_of_nonneg_right (min_le_left cn cq) hHp.le + linarith + + + + +open scoped BigOperators + +lemma character_mod_two_eq_one (chi : DirichletCharacter ℂ 2) : chi = 1 := by + apply MulChar.ext' + intro a + have ha : a = 0 ∨ a = 1 := by + fin_cases a + · exact Or.inl rfl + · exact Or.inr rfl + rcases ha with rfl | rfl + · rw [chi.map_zero, (1 : DirichletCharacter ℂ 2).map_zero] + · rw [chi.map_one, (1 : DirichletCharacter ℂ 2).map_one] + +lemma primitiveCharacter_ne_one {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) : chi.primitiveCharacter ≠ 1 := by + intro h + apply hchi + calc + chi = DirichletCharacter.changeLevel chi.conductor_dvd_level chi.primitiveCharacter := + chi.changeLevel_primitiveCharacter.symm + _ = 1 := by rw [h, DirichletCharacter.changeLevel_one] + +lemma conductor_ge_three {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) : 3 ≤ chi.conductor := by + have h0 := chi.conductor_ne_zero + have h1 : chi.conductor ≠ 1 := fun h => hchi (DirichletCharacter.eq_one_iff_conductor_eq_one.mpr h) + have h2 : chi.conductor ≠ 2 := by + intro h + have haux : ∀ n : ℕ, n=2 → ∀ psi : DirichletCharacter ℂ n, psi=1 := by + intro n hn psi + subst n + exact character_mod_two_eq_one psi + exact primitiveCharacter_ne_one chi hchi (haux _ h chi.primitiveCharacter) + omega + +lemma localEulerFactor_ne_zero_of_re_pos {p : ℕ} (hp : p.Prime) {alpha s : ℂ} + (ha : ‖alpha‖ ≤ 1) (hs : 0 < s.re) : localEulerFactor alpha p s ≠ 0 := by + have hpR : (1:ℝ) < p := by exact_mod_cast hp.one_lt + have hpow : ‖(p:ℂ)^(-s)‖ < 1 := by + rw [Complex.norm_natCast_cpow_of_pos hp.pos, Complex.neg_re] + calc + _ < (p:ℝ)^(0:ℝ) := Real.rpow_lt_rpow_of_exponent_lt hpR (by linarith) + _ = _ := Real.rpow_zero _ + have hu : ‖alpha*(p:ℂ)^(-s)‖ < 1 := by + rw [norm_mul] + exact (mul_le_mul_of_nonneg_right ha (norm_nonneg _)).trans_lt (by simpa using hpow) + intro hz + have he : alpha*(p:ℂ)^(-s) = 1 := (sub_eq_zero.mp hz).symm + rw [he,norm_one] at hu + exact (lt_irrefl 1) hu + +lemma LFunction_changeLevel_ne_zero_iff {M N : ℕ} [NeZero M] [NeZero N] + (hMN : M ∣ N) (chi : DirichletCharacter ℂ M) (hchi : chi ≠ 1) + {s : ℂ} (hs : 0 < s.re) : + DirichletCharacter.LFunction (DirichletCharacter.changeLevel hMN chi) s ≠ 0 ↔ + DirichletCharacter.LFunction chi s ≠ 0 := by + rw [DirichletCharacter.LFunction_changeLevel hMN chi (Or.inl hchi), mul_ne_zero_iff] + have hp : (∏ p ∈ N.primeFactors, (1-chi p*(p:ℂ)^(-s))) ≠ 0 := by + apply Finset.prod_ne_zero_iff.mpr + intro p hp + exact localEulerFactor_ne_zero_of_re_pos (Nat.prime_of_mem_primeFactors hp) + (chi.norm_le_one p) hs + exact and_iff_left hp + +lemma LFunction_primitive_ne_zero_iff {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) {s : ℂ} (hs : 0 < s.re) : + let _ : NeZero chi.conductor := ⟨chi.conductor_ne_zero⟩ + DirichletCharacter.LFunction chi s ≠ 0 ↔ + DirichletCharacter.LFunction chi.primitiveCharacter s ≠ 0 := by + let _ : NeZero chi.conductor := ⟨chi.conductor_ne_zero⟩ + have h := LFunction_changeLevel_ne_zero_iff chi.conductor_dvd_level chi.primitiveCharacter + (primitiveCharacter_ne_one chi hchi) hs + rwa [chi.changeLevel_primitiveCharacter] at h + +end Erdos970Dependency.SiegelWalfisz + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrincipalLogPower.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrincipalLogPower.lean new file mode 100644 index 0000000000000000000000000000000000000000..ade4e34f51a44e82f983f0d33c4b957e8267b0dc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/PrincipalLogPower.lean @@ -0,0 +1,141 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrincipalPrimePowers + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma eventually_pnt_exp_le_log_power (c M : ℝ) (hc : 0 < c) (_hM : 0 < M) : + ∀ᶠ X : ℝ in atTop, + Real.exp (-c*(Real.log X)^(1/2:ℝ)) ≤ (Real.log X)^(-M) := by + have he := Real.tendsto_log_atTop.eventually (eventually_log_rpow_le_self (4:ℝ)) + have he2 := Real.tendsto_log_atTop.eventually + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (M/c))) + filter_upwards [he,he2] with X hX hsize + let L : ℝ := Real.log X + have hL : 3 ≤ L := hX.1 + have hLp : 0 < L := by linarith + have hlogL : 0 ≤ Real.log L := Real.log_nonneg (by linarith) + have h4 : (Real.log L)^4 ≤ L := by simpa only [Real.rpow_ofNat] using hX.2 + have hroot := Real.sqrt_le_sqrt h4 + rw [show (Real.log L)^4 = ((Real.log L)^2)^2 by ring,Real.sqrt_sq (sq_nonneg _)] at hroot + have hMbound : M ≤ c*Real.log L := by + have h := (div_le_iff₀ hc).mp hsize + nlinarith only [h] + have h1 := mul_le_mul_of_nonneg_right hMbound hlogL + have h2 := mul_le_mul_of_nonneg_left hroot hc.le + have hsave : M*Real.log L ≤ c*L^(1/2:ℝ) := by + rw [← Real.sqrt_eq_rpow] + nlinarith only [h1,h2] + change Real.exp (-c*L^(1/2:ℝ)) ≤ L^(-M) + conv_rhs => rw [Real.rpow_def_of_pos hLp] + apply Real.exp_le_exp.mpr + nlinarith only [hsave] + +lemma sharpSum_vonMangoldt_eq {X : ℝ} (hX : 0 ≤ X) : + sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X = (_root_.Erdos970.ChebyshevPsi X:ℂ) := by + unfold sharpSum _root_.Erdos970.ChebyshevPsi + rw [Nat.floor_add_one hX,Complex.ofReal_sum] + +theorem ordinary_psi_log_power (M : ℝ) (hM : 0 < M) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, + ‖sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X-(X:ℂ)‖ ≤ + K*X/(Real.log X)^M := by + obtain ⟨c,hc,hPNT⟩ := _root_.Erdos970.Strong_PNT + obtain ⟨K,hK,hbound⟩ := hPNT.exists_pos + refine ⟨K,hK,?_⟩ + filter_upwards [hbound.bound,eventually_pnt_exp_le_log_power c M hc hM, + eventually_ge_atTop (3:ℝ)] with X hb he hX + have hXp : 0 < X := by linarith + have hLp : 0 < Real.log X := Real.log_pos (by linarith) + have hnonneg : 0 ≤ X*Real.exp (-c*(Real.log X)^(1/2:ℝ)) := by positivity + change ‖_root_.Erdos970.ChebyshevPsi X-X‖ ≤ K*‖X*Real.exp (-c*(Real.log X)^(1/2:ℝ))‖ at hb + rw [sharpSum_vonMangoldt_eq hXp.le,← Complex.ofReal_sub,Complex.norm_real] + simp only [Real.norm_eq_abs] at hb ⊢ + rw [abs_of_nonneg hnonneg] at hb + calc + _ ≤ K*(X*Real.exp (-c*(Real.log X)^(1/2:ℝ))) := hb + _ ≤ K*(X*(Real.log X)^(-M)) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left he hXp.le) hK.le + _ = _ := by rw [Real.rpow_neg hLp.le,div_eq_mul_inv]; ring + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma principal_difference_log_power (A M : ℝ) (hA : 0 < A) (_hM : 0 < M) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q], + (q:ℝ) ≤ (Real.log X)^A → + ‖sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ K*X/(Real.log X)^M := by + have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) + refine ⟨A/Real.log 2,div_pos hA hlog2,?_⟩ + filter_upwards [eventually_log_rpow_le_self (M+2)] with X hX + intro q _ hq + obtain ⟨hX3,hpow⟩ := hX + let L : ℝ := Real.log X + have hXp : 0 < X := by linarith + have hL1 : 1 ≤ L := ((Real.lt_log_iff_exp_lt hXp).mpr (Real.exp_one_lt_three.trans_le hX3)).le + have hLp : 0 < L := by linarith + have hqpos : (0:ℝ) < q := by exact_mod_cast NeZero.pos q + have hlogq := Real.log_le_log hqpos hq + rw [Real.log_rpow hLp] at hlogq + have hlogL : Real.log L ≤ L := by linarith [Real.log_le_sub_one_of_pos hLp] + have h2eq : L^(2:ℝ) = L^2 := Real.rpow_natCast L 2 + change L^(M+2) ≤ X at hpow + rw [Real.rpow_add hLp,h2eq] at hpow + have hL2 : L^2 ≤ X/L^M := by + apply (le_div_iff₀ (Real.rpow_pos_of_pos hLp M)).mpr + calc + _ = L^M*L^2 := mul_comm _ _ + _ ≤ X := hpow + have hprod : L*Real.log L ≤ L^2 := by + have h := mul_le_mul_of_nonneg_left hlogL hLp.le + nlinarith only [h] + calc + _ ≤ (L/Real.log 2)*Real.log (q:ℝ) := norm_principal_sharp_difference_real q (by linarith) + _ ≤ (L/Real.log 2)*(A*Real.log L) := + mul_le_mul_of_nonneg_left hlogq (div_nonneg hLp.le hlog2.le) + _ = (A/Real.log 2)*(L*Real.log L) := by ring + _ ≤ (A/Real.log 2)*(X/L^M) := + mul_le_mul_of_nonneg_left (hprod.trans hL2) (div_nonneg hA.le hlog2.le) + _ = _ := by ring + +theorem principal_character_log_power (A M : ℝ) (hA : 0 < A) (hM : 0 < M) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q], + (q:ℝ) ≤ (Real.log X)^A → + ‖sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X-(X:ℂ)‖ ≤ + K*X/(Real.log X)^M := by + obtain ⟨C,hC,hDiff⟩ := principal_difference_log_power A M hA hM + obtain ⟨D,hD,hOrd⟩ := ordinary_psi_log_power M hM + refine ⟨C+D,by positivity,?_⟩ + filter_upwards [hDiff,hOrd] with X hDiff hOrd + intro q _ hq + have hd := hDiff q hq + have hn := norm_add_le + (sharpSum (fun n:ℕ => (1:DirichletCharacter ℂ q) n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X) + (sharpSum (fun n:ℕ => (ArithmeticFunction.vonMangoldt n:ℂ)) X-(X:ℂ)) + rw [sub_add_sub_cancel] at hn + apply (hn.trans (add_le_add hd hOrd)).trans_eq + ring + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ProductRestriction.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ProductRestriction.lean new file mode 100644 index 0000000000000000000000000000000000000000..26abfa5cbb70fbdbb6f6fc507e0ef9e0e9ab489c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ProductRestriction.lean @@ -0,0 +1,211 @@ +import Mathlib.Logic.Equiv.Prod +import OAI.NumberTheory.Jacobsthal.Probability.UniformMoment + +namespace OAI + +namespace Erdos970 + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +private lemma hasSum_mul_nonneg {α β : Type*} {f : α → ℝ} {g : β → ℝ} + {a b : ℝ} (hf : HasSum f a) (hg : HasSum g b) + (hfn : ∀ x, 0 ≤ f x) (hgn : ∀ y, 0 ≤ g y) : + HasSum (fun s : α × β => f s.1 * g s.2) (a * b) := + HasSum.mul hf hg (Summable.mul_of_nonneg hf.summable hg.summable hfn hgn) + +theorem hasSum_fin_product {α : Type*} {n : ℕ} (w : Fin n → α → ℝ) + (a : Fin n → ℝ) (hw : ∀ i x, 0 ≤ w i x) (hs : ∀ i, HasSum (w i) (a i)) : + HasSum (fun s : Fin n → α => ∏ i, w i (s i)) (∏ i, a i) := by + induction n with + | zero => simp + | succ n ih => + have ht : HasSum (fun s : Fin n → α => ∏ i : Fin n, w i.succ (s i)) + (∏ i : Fin n, a i.succ) := + ih (fun i => w i.succ) (fun i => a i.succ) + (fun i => hw i.succ) (fun i => hs i.succ) + have hn : ∀ s : Fin n → α, 0 ≤ ∏ i, w i.succ (s i) := by + intro s; exact Finset.prod_nonneg (fun i _ => hw i.succ (s i)) + have hprod : HasSum (fun s : α × (Fin n → α) => + w 0 s.1 * ∏ i : Fin n, w i.succ (s.2 i)) (a 0 * ∏ i : Fin n, a i.succ) := + hasSum_mul_nonneg (f := w 0) + (g := fun s : Fin n → α => ∏ i : Fin n, w i.succ (s i)) + (a := a 0) (b := ∏ i : Fin n, a i.succ) (hs 0) ht (hw 0) hn + apply (Fin.consEquiv (fun _ : Fin (n+1) => α)).hasSum_iff.mp + simpa only [Function.comp_def, Fin.consEquiv_apply, Fin.prod_univ_succ, + Fin.cons_zero, Fin.cons_succ] using hprod + +theorem hasSum_finite_product {ι α : Type*} [Fintype ι] + (w : ι → α → ℝ) (a : ι → ℝ) (hw : ∀ i x, 0 ≤ w i x) + (hs : ∀ i, HasSum (w i) (a i)) : + HasSum (fun s : ι → α => ∏ i, w i (s i)) (∏ i, a i) := by + let e := (Fintype.equivFin ι).symm + have h := hasSum_fin_product (fun i => w (e i)) (fun i => a (e i)) + (fun i => hw (e i)) (fun i => hs (e i)) + rw [e.prod_comp a] at h + apply (Equiv.piCongrLeft (fun _ : ι => α) e).hasSum_iff.mp + apply h.congr_fun + intro s + dsimp only [Function.comp_def] + rw [← e.prod_comp] + congr 1 + funext i + simp [Equiv.piCongrLeft] + +theorem product_coordinate_hasSum {ι α : Type*} [Fintype ι] + (w : ι → α → ℝ) (hw : ∀ i x, 0 ≤ w i x) + (hs : ∀ i, HasSum (w i) 1) (j : ι) (f : α → ℝ) + (hf : ∀ x, 0 ≤ f x) {b : ℝ} (hb : HasSum (fun x => w j x * f x) b) : + HasSum (fun s : ι → α => (∏ i, w i (s i)) * f (s j)) b := by + classical + have h := hasSum_finite_product + (fun i x => w i x * if i = j then f x else 1) + (fun i => if i = j then b else 1) + (by intro i x; exact mul_nonneg (hw i x) (by split_ifs; exact hf x; norm_num)) + (by intro i; by_cases hij : i = j + · subst i; simpa only [ite_true] using hb + · simpa only [ite_eq_right hij, mul_one] using hs i) + simpa only [Finset.prod_mul_distrib, Finset.prod_ite_eq', Finset.mem_univ, + ite_true] using h + +end EulerWeightedLower + + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +abbrev Outcomes (E : Finset ℕ) := E → Sample +noncomputable def productMass (E : Finset ℕ) (s : Outcomes E) : ℝ := + ∏ p : E, jointMass (p : ℝ) (s p) +noncomputable def excessLog (E : Finset ℕ) (s : Outcomes E) : ℝ := + ∑ p : E, ((upperExponent (s p) - lowerExponent (s p) : ℕ) : ℝ) * Real.log (p : ℝ) +noncomputable def eventMass (E : Finset ℕ) (A : Outcomes E → Prop) : ℝ := + ∑' s : Outcomes E, if A s then productMass E s else 0 + +variable (E : Finset ℕ) (hE : ∀ p ∈ E, 2 ≤ p) +include hE + +lemma productMass_nonneg (s : Outcomes E) : 0 ≤ productMass E s := by + apply Finset.prod_nonneg + intro p _ + exact jointMass_nonneg (by exact_mod_cast hE p p.property) (s p) + +theorem productMass_hasSum : HasSum (productMass E) 1 := by + have h := hasSum_finite_product (fun p : E => jointMass (p : ℝ)) (fun _ => (1 : ℝ)) + (fun p => jointMass_nonneg (by exact_mod_cast hE p p.property)) + (fun p => jointMass_hasSum (by exact_mod_cast hE p p.property)) + change HasSum (fun s : E → Sample => ∏ p : E, jointMass (p : ℝ) (s p)) 1 + simpa only [Finset.prod_const_one] using h + +lemma product_event_summable (A : Outcomes E → Prop) : + Summable (fun s => if A s then productMass E s else 0) := by + apply (productMass_hasSum E hE).summable.of_nonneg_of_le + · intro s; split_ifs <;> simp_all only [le_refl, productMass_nonneg E hE] + · intro s; split_ifs <;> simp_all only [le_refl, productMass_nonneg E hE] + +lemma excessLog_nonneg (s : Outcomes E) : 0 ≤ excessLog E s := by + apply Finset.sum_nonneg + intro p _ + exact mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg (by exact_mod_cast (hE p p.property).trans' (by omega : 1 ≤ 2))) + +theorem product_excess_hasSum : + HasSum (fun s => productMass E s * excessLog E s) + (∑ p ∈ E, Real.log (p : ℝ) / ((p : ℝ) - 1)^2) := by + have hlocal (p : E) : HasSum (fun s : Outcomes E => productMass E s * + (((upperExponent (s p) - lowerExponent (s p) : ℕ) : ℝ) * Real.log (p : ℝ))) + (Real.log (p : ℝ) / ((p : ℝ)-1)^2) := by + apply product_coordinate_hasSum (fun q : E => jointMass (q : ℝ)) + (fun q => jointMass_nonneg (by exact_mod_cast hE q q.property)) + (fun q => jointMass_hasSum (by exact_mod_cast hE q q.property)) p + (fun s => (((upperExponent s - lowerExponent s : ℕ) : ℝ) * Real.log (p : ℝ))) + · intro s + exact mul_nonneg (Nat.cast_nonneg _) (Real.log_nonneg (by exact_mod_cast (hE p p.property).trans' (by omega : 1 ≤ 2))) + · have hp : (2 : ℝ) ≤ (p : ℝ) := by exact_mod_cast hE p p.property + rw [← expected_log_excess hp] + simpa only [mul_assoc] using (log_excess_summable hp).hasSum + have h := hasSum_sum (s := Finset.univ) (fun p _ => hlocal p) + have he : (∑ p : E, Real.log (p : ℝ) / ((p : ℝ)-1)^2) = + ∑ p ∈ E, Real.log (p : ℝ) / ((p : ℝ)-1)^2 := by + exact Finset.sum_attach E (fun p : ℕ => Real.log (p : ℝ) / ((p : ℝ)-1)^2) + rw [he] at h + convert h using 1 + funext s + exact Finset.mul_sum _ _ _ + +theorem product_excess_mean_le : + (∑' s : Outcomes E, productMass E s * excessLog E s) ≤ uniformMomentBound := by + rw [(product_excess_hasSum E hE).tsum_eq] + exact finite_log_moment_le E + +theorem excess_tail_le {t : ℝ} (ht : 0 < t) : + eventMass E (fun s => t < excessLog E s) ≤ uniformMomentBound / t := by + apply (le_div_iff₀ ht).mpr + rw [eventMass, ← tsum_mul_right] + apply le_trans _ (product_excess_mean_le E hE) + apply Summable.tsum_le_tsum + · intro s + by_cases h : t < excessLog E s + · simp only [ite_eq_left h] + exact mul_le_mul_of_nonneg_left h.le (productMass_nonneg E hE s) + · simp only [ite_eq_right h, zero_mul] + exact mul_nonneg (productMass_nonneg E hE s) (excessLog_nonneg E hE s) + · exact (product_event_summable E hE _).mul_right t + · exact (product_excess_hasSum E hE).summable + +end EulerWeightedLower + + + +namespace EulerWeightedLower +attribute [local instance] Classical.propDecidable + +theorem finite_product_restrict {ι α : Type*} [Fintype ι] (P : ι → Prop) + (w : ι → α → ℝ) (hw : ∀ i x, 0 ≤ w i x) (hs : ∀ i, HasSum (w i) 1) + (A : ({i // P i} → α) → Prop) : + (∑' s : ι → α, if A (fun i => s i) then ∏ i, w i (s i) else 0) = + ∑' s : {i // P i} → α, if A s then ∏ i : {i // P i}, w i (s i) else 0 := by + classical + let e := Equiv.piEquivPiSubtypeProd P (fun _ => α) + have hsub := hasSum_finite_product (fun i : {i // P i} => w i) (fun _ => (1 : ℝ)) + (fun i => hw i) (fun i => hs i) + have hcomp := hasSum_finite_product (fun i : {i // ¬P i} => w i) (fun _ => (1 : ℝ)) + (fun i => hw i) (fun i => hs i) + simp only [Finset.prod_const_one] at hsub hcomp + have hn (s : {i // P i} → α) : 0 ≤ ∏ i : {i // P i}, w i (s i) := + Finset.prod_nonneg (fun i _ => hw i.val (s i)) + have hc (s : {i // ¬P i} → α) : 0 ≤ ∏ i : {i // ¬P i}, w i (s i) := + Finset.prod_nonneg (fun i _ => hw i.val (s i)) + have hA : Summable (fun s : {i // P i} → α => if A s then ∏ i : {i // P i}, w i (s i) else 0) := by + apply hsub.summable.of_nonneg_of_le + · intro s; split_ifs; exact hn s; rfl + · intro s; split_ifs; rfl; exact hn s + have hprod := hA.mul_of_nonneg hcomp.summable + (by intro s; dsimp only [Pi.zero_apply]; split_ifs; exact hn s; rfl) hc + calc + _ = ∑' z : ({i // P i} → α) × ({i // ¬P i} → α), + (if A z.1 then ∏ i : {i // P i}, w i (z.1 i) else 0) * ∏ i : {i // ¬P i}, w i (z.2 i) := by + rw [← e.symm.tsum_eq] + apply tsum_congr + intro z + have hsplit := Fintype.prod_subtype_mul_prod_subtype P (fun i => w i (e.symm z i)) + rw [← hsplit] + have hl (i : {i // P i}) : e.symm z i = z.1 i := by + simp [e, Equiv.piEquivPiSubtypeProd, i.property] + have hr (i : {i // ¬P i}) : e.symm z i = z.2 i := by + simp [e, Equiv.piEquivPiSubtypeProd, i.property] + simp only [hl, hr] + by_cases hh : A z.1 <;> simp only [hh, ite_true, ite_false, zero_mul] + _ = _ := by + rw [hprod.tsum_prod] + simp only [tsum_mul_left, hcomp.tsum_eq, mul_one] + +end EulerWeightedLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RationalCandidateSets.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RationalCandidateSets.lean new file mode 100644 index 0000000000000000000000000000000000000000..f02bad1137288daf7b2594023fa9e3a13ccfa1ae --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RationalCandidateSets.lean @@ -0,0 +1,124 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.RationalParameterInterval + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAlignedProgression +open ErdosInverseAlignment + +def parameterOf (r : ℚ) (d t : ℕ) : ℤ := ((r.den : ℤ)*(t : ℤ)-r.num)/(d : ℤ) + +theorem parameterOf_spec (a : ℕ → ℕ) (r : ℚ) (d t : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) + (ht : ∀ p ∈ d.primeFactors, t % p = a p % p) : + (r.den : ℤ)*(t : ℤ) = r.num+(d : ℤ)*parameterOf r d t := by + obtain ⟨m, hm⟩ := (required_hits_iff_parameter a r d t hd ha).mp ht + have hdiv : (d : ℤ) ∣ (r.den : ℤ)*(t : ℤ)-r.num := ⟨m, by linarith⟩ + have he := Int.mul_ediv_cancel_of_dvd hdiv + dsimp only [parameterOf] + linarith + +theorem parameterValue_parameterOf (a : ℕ → ℕ) (r : ℚ) (d t : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) + (ht : ∀ p ∈ d.primeFactors, t % p = a p % p) : + parameterValue r d (parameterOf r d t) = t := by + have he := parameterOf_spec a r d t hd ha ht + have hD : (r.den : ℤ) ≠ 0 := by exact_mod_cast r.den_ne_zero + rw [parameterValue, ← he, Int.mul_ediv_cancel_left _ hD, Int.toNat_natCast] + +theorem parameterOf_parameterValue (Y : ℕ) (r : ℚ) (d : ℕ) (hd : 0 < d) (m : ℤ) + (hm : m ∈ parameterInterval Y r d) (hdiv : (r.den : ℤ) ∣ r.num+(d : ℤ)*m) : + parameterOf r d (parameterValue r d m) = m := by + have hs := parameterValue_spec Y r d hd m hm hdiv + have hdZ : (d : ℤ) ≠ 0 := by exact_mod_cast hd.ne' + rw [parameterOf, hs.2.2, add_sub_cancel_left, Int.mul_ediv_cancel_left _ hdZ] + +end ErdosAlignedProgression + +end + +section + +namespace ErdosAlignedProgression +open ErdosInverseAlignment ErdosInverseCounts +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def parameterCandidates (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d : ℕ) : Finset ℤ := + (parameterInterval Y r d).filter (fun m => + (r.den : ℤ) ∣ r.num+(d : ℤ)*m ∧ ∀ p ∈ small, parameterValue r d m % p ≠ a p % p) + +theorem parameterOf_mem (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d t : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) + (ht : t ∈ modulusCandidates Y small a d) : + parameterOf r d t ∈ parameterCandidates Y small a r d := by + obtain ⟨ht1, htY, hhit, hsmall⟩ := (mem_modulusCandidates Y small a d t).mp ht + have he := parameterOf_spec a r d t hd ha hhit + have hD : (0 : ℤ) < r.den := by exact_mod_cast r.den_pos + have ht1Z : (1 : ℤ) ≤ t := by exact_mod_cast ht1 + have htYZ : (t : ℤ) ≤ Y := by exact_mod_cast htY + apply Finset.mem_filter.mpr + refine ⟨(mem_parameterInterval Y r d (Nat.pos_of_ne_zero hd.ne_zero) _).mpr ?_, ?_, ?_⟩ + · rw [← he] + constructor <;> nlinarith + · exact ⟨(t : ℤ), he.symm⟩ + · rw [parameterValue_parameterOf a r d t hd ha hhit] + exact hsmall + +theorem parameterValue_mem (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d : ℕ) (m : ℤ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) + (hm : m ∈ parameterCandidates Y small a r d) : + parameterValue r d m ∈ modulusCandidates Y small a d := by + obtain ⟨hI, hdiv, hsmall⟩ := Finset.mem_filter.mp hm + have hs := parameterValue_spec Y r d (Nat.pos_of_ne_zero hd.ne_zero) m hI hdiv + apply (mem_modulusCandidates Y small a d _).mpr + exact ⟨hs.1, hs.2.1, (required_hits_iff_parameter a r d _ hd ha).mpr ⟨m, hs.2.2⟩, hsmall⟩ + +theorem parameterCandidates_eq_image (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) : + parameterCandidates Y small a r d = + (modulusCandidates Y small a d).image (parameterOf r d) := by + ext m + constructor + · intro hm + have ht := parameterValue_mem Y small a r d m hd ha hm + obtain ⟨hI, hdiv, _hsmall⟩ := Finset.mem_filter.mp hm + exact Finset.mem_image.mpr ⟨parameterValue r d m, ht, + parameterOf_parameterValue Y r d (Nat.pos_of_ne_zero hd.ne_zero) m hI hdiv⟩ + · intro hm + obtain ⟨t, ht, rfl⟩ := Finset.mem_image.mp hm + exact parameterOf_mem Y small a r d t hd ha ht + +theorem parameterOf_injOn (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) : + Set.InjOn (parameterOf r d) (modulusCandidates Y small a d : Set ℕ) := by + intro t ht u hu he + have ht' := ((mem_modulusCandidates Y small a d t).mp ht).2.2.1 + have hu' := ((mem_modulusCandidates Y small a d u).mp hu).2.2.1 + calc + t = parameterValue r d (parameterOf r d t) := (parameterValue_parameterOf a r d t hd ha ht').symm + _ = parameterValue r d (parameterOf r d u) := congrArg (parameterValue r d) he + _ = u := parameterValue_parameterOf a r d u hd ha hu' + +theorem modulusCount_eq_parameter_card (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (r : ℚ) (d : ℕ) (hd : Squarefree d) + (ha : ∀ p ∈ d.primeFactors, aligns (fun s => (a s : ℤ)) r p) : + modulusCount Y small a d = ((parameterCandidates Y small a r d).card : ℤ) := by + rw [modulusCount, parameterCandidates_eq_image Y small a r d hd ha, + Finset.card_image_of_injOn (parameterOf_injOn Y small a r d hd ha)] + +end ErdosAlignedProgression + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialEven.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialEven.lean new file mode 100644 index 0000000000000000000000000000000000000000..9536bc8e660106a0ba8e87e47d02c71815091bc5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialEven.lean @@ -0,0 +1,411 @@ +import OAI.NumberTheory.Jacobsthal.Paths.BranchWordEndpoint + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess + +noncomputable def lookaheadInputCost : (w : List Bool) → (b : Bool) → + CycleWordSignature (w++[b]).length → ℝ + | [], _b, s => s.1.1 + | _c::w, b, s => lookaheadInputCost w b s.2 + +lemma lookaheadInputCost_measurable (w : List Bool) : ∀ b, Measurable (lookaheadInputCost w b) := by + induction w with + | nil => intro b; exact measurable_fst.comp measurable_fst + | cons c w ih => intro b; exact (ih b).comp measurable_snd + +lemma sourceBranchWitness_mass (b : Bool) (z : OddCost) : + sourceBranchWitnessKernel b z univ=cycleBranchKernel b z univ := by + have he := congrArg (fun μ : Measure OddCost => μ univ) (sourceBranchWitness_endpoint b z) + rw [Measure.map_apply (f := fun w : SourceCycleWitness => w.2.2) + (measurable_snd.comp measurable_snd) MeasurableSet.univ,preimage_univ] at he + exact he + +lemma sourceLookahead_lintegral (w : List Bool) (b : Bool) {F : ℝ → ℝ≥0∞} (hF : Measurable F) : ∀ z, + (∫⁻ s, F (lookaheadInputCost w b s) ∂sourceMarkedWordKernel (w++[b]) z) = + ∫⁻ y, cycleBranchKernel b y univ*F y.2 ∂branchWordKernel w z := by + have hG : Measurable (fun y : OddCost => cycleBranchKernel b y univ*F y.2) := + ((cycleBranchKernel b).measurable_coe MeasurableSet.univ).mul (hF.comp measurable_snd) + induction w with + | nil => + intro z + change (∫⁻ s : CycleWordSignature [b].length, F (lookaheadInputCost [] b s) ∂sourceMarkedWordKernel [b] z) = _ + rw [sourceMarkedWord_cons_lintegral b [] z + (F := fun s => F (lookaheadInputCost [] b s)) (hF.comp (lookaheadInputCost_measurable [] b))] + change (∫⁻ y : SourceCycleWitness, ∫⁻ _s, F z.2 ∂Measure.dirac (NumberTheoryLean.PairedCostGrouping.embedOdd y.2.2) + ∂sourceBranchWitnessKernel b z) = ∫⁻ y, cycleBranchKernel b y univ*F y.2 ∂Measure.dirac z + simp only [lintegral_const,measure_univ,mul_one] + rw [sourceBranchWitness_mass,lintegral_dirac' z hG] + exact mul_comm _ _ + | cons c w ih => + intro z + change (∫⁻ s : CycleWordSignature (c::(w++[b])).length, + F (lookaheadInputCost (c::w) b s) ∂sourceMarkedWordKernel (c::(w++[b])) z) = _ + rw [sourceMarkedWord_cons_lintegral c (w++[b]) z + (F := fun s => F (lookaheadInputCost (c::w) b s)) + (hF.comp (lookaheadInputCost_measurable (c::w) b))] + change (∫⁻ y : SourceCycleWitness, ∫⁻ s, F (lookaheadInputCost w b s) + ∂sourceMarkedWordKernel (w++[b]) y.2.2 ∂sourceBranchWitnessKernel c z) = _ + simp_rw [ih] + have hJ : Measurable (fun y : OddCost => ∫⁻ t, cycleBranchKernel b t univ*F t.2 ∂branchWordKernel w y) := + hG.lintegral_kernel + rw [← lintegral_map (g := fun y : SourceCycleWitness => y.2.2) hJ (measurable_snd.comp measurable_snd), + sourceBranchWitness_endpoint,branchWordKernel,Kernel.lintegral_comp _ _ _ hG] + +theorem sourceLookahead_cost_law (w : List Bool) (b : Bool) (z : OddCost) : + (sourceMarkedWordKernel (w++[b]) z).map (lookaheadInputCost w b) = + ((branchWordKernel w z).withDensity (fun y => cycleBranchKernel b y univ)).map Prod.snd := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (lookaheadInputCost_measurable w b),lintegral_map hF measurable_snd, + lintegral_withDensity_eq_lintegral_mul _ (g := fun y : OddCost => F y.2) ((cycleBranchKernel b).measurable_coe MeasurableSet.univ) + (hF.comp measurable_snd)] + exact sourceLookahead_lintegral w b hF z + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.PairedCostGrouping + +noncomputable def rawLookaheadCostLaw (a : ℕ) (w : List Bool) (b : Bool) (h : RawHistory a) : Measure ℝ := + (rawMarkedWordKernel a (w++[b]) h).map (fun t => + lookaheadInputCost w b (rawCycleWordSignature a (w++[b]).length t)-(rawLast a h).2) + +theorem rawLookaheadCostLaw_eq (a : ℕ) (w : List Bool) (b : Bool) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + rawLookaheadCostLaw a w b h = + ((branchWordKernel w z).withDensity (fun y => cycleBranchKernel b y univ)).map (fun y => y.2-z.2) := by + have hcost : (rawLast a h).2=z.2 := congrArg (fun s : NumberTheoryLean.FinitePathMeasures.CostState => s.2) hz + rw [rawLookaheadCostLaw,hcost] + calc + _ = (((rawMarkedWordKernel a (w++[b]) h).map (rawCycleWordSignature a (w++[b]).length)).map + (lookaheadInputCost w b)).map (fun T : ℝ => T-z.2) := by + rw [Measure.map_map (g := fun T : ℝ => T-z.2) (measurable_id.sub measurable_const) + (lookaheadInputCost_measurable w b), + Measure.map_map (g := (fun T : ℝ => T-z.2) ∘ lookaheadInputCost w b) + (f := rawCycleWordSignature a (w++[b]).length) + ((measurable_id.sub measurable_const).comp (lookaheadInputCost_measurable w b)) + (rawCycleWordSignature_measurable _ _)] + rfl + _ = (((branchWordKernel w z).withDensity (fun y => cycleBranchKernel b y univ)).map Prod.snd).map + (fun T : ℝ => T-z.2) := by + rw [rawMarkedWord_signature (w++[b]) a h z hz,sourceLookahead_cost_law] + _ = _ := by + rw [Measure.map_map (g := fun T : ℝ => T-z.2) (measurable_id.sub measurable_const) measurable_snd] + rfl + +noncomputable def rawWaitingWordTerm (a n : ℕ) (h : RawHistory a) : Measure ℝ := + rawLookaheadCostLaw a (List.replicate n false) true h + +noncomputable def rawSpacingWordTerm (a n : ℕ) (h : RawHistory a) : Measure ℝ := + markProbability⁻¹ • rawLookaheadCostLaw a (true::List.replicate n false) true h + +theorem rawWaitingWordTerm_eq (a n : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : rawWaitingWordTerm a n h=actualWaitingTerm n z := by + rw [rawWaitingWordTerm,rawLookaheadCostLaw_eq a _ true h z hz,branchWordKernel_replicate,actualWaitingTerm] + rfl + +theorem rawSpacingWordTerm_eq (a n : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : rawSpacingWordTerm a n h=actualSpacingTerm n z := by + rw [rawSpacingWordTerm,rawLookaheadCostLaw_eq a _ true h z hz, + branchWordKernel_first_replicate,actualSpacingTerm] + rfl + +noncomputable def rawWaitingCostLaw (a : ℕ) (h : RawHistory a) : Measure ℝ := + Measure.sum (fun n : ℕ => rawWaitingWordTerm a n h) + +noncomputable def rawSpacingCostLaw (a : ℕ) (h : RawHistory a) : Measure ℝ := + Measure.sum (fun n : ℕ => rawSpacingWordTerm a n h) + +theorem rawWaitingCostLaw_eq (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : rawWaitingCostLaw a h=actualWaitingLaw z := by + unfold rawWaitingCostLaw actualWaitingLaw + apply congrArg Measure.sum + funext n + exact rawWaitingWordTerm_eq a n h z hz + +theorem rawSpacingCostLaw_eq (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : rawSpacingCostLaw a h=actualSpacingLaw z := by + unfold rawSpacingCostLaw actualSpacingLaw + apply congrArg Measure.sum + funext n + exact rawSpacingWordTerm_eq a n h z hz + +theorem rawAllocatedCostLaws_mass_one (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) (hReg : z ∈ returnSet) : + rawWaitingCostLaw a h univ=1 ∧ rawSpacingCostLaw a h univ=1 := by + rw [rawWaitingCostLaw_eq a h z hz,rawSpacingCostLaw_eq a h z hz] + exact ⟨actualWaitingLaw_mass z hReg,actualSpacingLaw_mass z hReg⟩ + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.CostReturnLaw +open NumberTheoryLean.InitialRegeneration NumberTheoryLean.FirstHitKernels + +lemma sourceCycleWitness_endpoint (z : OddCost) : + (sourceCycleWitnessKernel z).map (fun w => w.2.2)=returnLaw z := by + calc + _ = ((sourceCycleWitnessKernel z).map Prod.snd).map Prod.snd := + (Measure.map_map measurable_snd measurable_snd).symm + _ = _ := by + rw [sourceCycleWitness_duration_law,NumberTheoryLean.MarkedCycleLaw.markedReturnLaw_forget] + +noncomputable def rawReturnEndpointState (a : ℕ) (r : RawReturnTrace a) : CostState := + (rawReturnSignature a r).2.2 + +lemma rawReturnEndpointState_measurable (a : ℕ) : Measurable (rawReturnEndpointState a) := + (measurable_snd.comp measurable_snd).comp (rawReturnSignature_measurable a) + +lemma rawReturnTrace_endpoint (a : ℕ) (h : RawHistory a) (z : OddCost) (hz : rawLast a h=embedOdd z) : + (rawReturnTraceKernel a h).map (rawReturnEndpointState a)=(returnLaw z).map embedOdd := by + have he := congrArg (fun μ : Measure ReturnSignature => μ.map (fun s => s.2.2)) + (rawReturnTrace_signature a h z hz) + rw [Measure.map_map (g := fun s : ReturnSignature => s.2.2) + (measurable_snd.comp measurable_snd) (rawReturnSignature_measurable a), + Measure.map_map (g := fun s : ReturnSignature => s.2.2) + (measurable_snd.comp measurable_snd) (sourceReturnSignature_measurable z)] at he + rw [← sourceCycleWitness_endpoint z, + Measure.map_map (g := embedOdd) (f := fun w : SourceCycleWitness => w.2.2) + embedOdd_measurable (measurable_snd.comp measurable_snd)] + exact he + +noncomputable def rawReturnPastState (a : ℕ) (r : RawReturnTrace a) : CostState := + r.2 ⟨a,Finset.mem_Iic.mpr (by omega)⟩ + +lemma rawReturnPastState_measurable (a : ℕ) : Measurable (rawReturnPastState a) := by + apply measurable_sigma_family + intro n + change Measurable (fun h : RawHistory (a+2*(n+1)) => h ⟨a,Finset.mem_Iic.mpr (by omega)⟩) + exact measurable_pi_apply _ + +local instance : MeasurableSingletonClass State := by + constructor + intro x + cases x with + | inl e => simpa only [image_singleton] using ((measurableSet_singleton e).inl_image : MeasurableSet (Sum.inl '' {e} : Set State)) + | inr o => simpa only [image_singleton] using ((measurableSet_singleton o).inr_image : MeasurableSet (Sum.inr '' {o} : Set State)) + +lemma rawReturnPastState_ae (a : ℕ) (h : RawHistory a) : + ∀ᵐ r ∂rawReturnTraceKernel a h, rawReturnPastState a r=rawLast a h := by + have hm : MeasurableSet {r : RawReturnTrace a | rawReturnPastState a r=rawLast a h} := + (rawReturnPastState_measurable a) (measurableSet_singleton _) + rw [rawReturnTraceKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable a n)] + apply (ae_map_iff (rawReturnTrace_mk_measurable a n).aemeasurable hm).mpr + filter_upwards [firstReturnHistory_retains_past a n h] with y hy + exact congrFun hy (⟨a,by simp⟩ : Finset.Iic a) + +lemma rawReturnTrace_input_endpoint (a : ℕ) (h : RawHistory a) (z : OddCost) (hz : rawLast a h=embedOdd z) : + (rawReturnTraceKernel a h).map (fun r => (rawReturnPastState a r,rawReturnEndpointState a r)) = + (returnLaw z).map (fun y => (embedOdd z,embedOdd y)) := by + have he : (fun r => (rawReturnPastState a r,rawReturnEndpointState a r)) =ᵐ[rawReturnTraceKernel a h] + fun r => (embedOdd z,rawReturnEndpointState a r) := by + filter_upwards [rawReturnPastState_ae a h] with r hr + exact Prod.ext (hr.trans hz) rfl + calc + _ = (rawReturnTraceKernel a h).map (fun r => (embedOdd z,rawReturnEndpointState a r)) := Measure.map_congr he + _ = ((rawReturnTraceKernel a h).map (rawReturnEndpointState a)).map (fun y => (embedOdd z,y)) := by + rw [Measure.map_map (g := fun y : CostState => (embedOdd z,y)) + (measurable_const.prodMk measurable_id) (rawReturnEndpointState_measurable a)] + rfl + _ = _ := by + rw [rawReturnTrace_endpoint a h z hz, + Measure.map_map (g := fun y : CostState => (embedOdd z,y)) + (measurable_const.prodMk measurable_id) embedOdd_measurable] + rfl + +abbrev RawContinuationTrace (a : ℕ) := RawHistory a ⊕ RawReturnTrace a + +noncomputable def rawContinuationKernel (a : ℕ) : Kernel (RawHistory a) (RawContinuationTrace a) := by + classical + exact Kernel.piecewise (lastRegeneration_measurable a) + ((Kernel.id : Kernel (RawHistory a) (RawHistory a)).map Sum.inl) + ((rawReturnTraceKernel a).map Sum.inr) + +instance rawContinuationKernel_isFiniteKernel (a : ℕ) : IsFiniteKernel (rawContinuationKernel a) := by + classical + unfold rawContinuationKernel + infer_instance + +noncomputable def rawContinuationSignature (a : ℕ) : RawContinuationTrace a → CostState × CostState := + Sum.elim (fun h => (rawLast a h,rawLast a h)) + (fun r => (rawReturnPastState a r,rawReturnEndpointState a r)) + +lemma rawContinuationSignature_measurable (a : ℕ) : Measurable (rawContinuationSignature a) := + ((rawLast_measurable a).prodMk (rawLast_measurable a)).sumElim + ((rawReturnPastState_measurable a).prodMk (rawReturnEndpointState_measurable a)) + +theorem rawContinuation_signature (a : ℕ) (h : RawHistory a) (z : OddCost) (hz : rawLast a h=embedOdd z) : + (rawContinuationKernel a h).map (rawContinuationSignature a) = + (hitOrReturn z).map (fun y => (embedOdd z,embedOdd y)) := by + classical + have hp : h ∈ lastRegeneration a ↔ z ∈ returnSet := by + change rawLast a h ∈ regenerationSet ↔ z ∈ returnSet + rw [hz] + rfl + by_cases hReg : z ∈ returnSet + · rw [rawContinuationKernel,Kernel.piecewise_apply,ite_eq_left (hp.mpr hReg), + Kernel.map_apply _ measurable_inl,Kernel.id_apply,Measure.map_dirac' measurable_inl, + Measure.map_dirac' (rawContinuationSignature_measurable a), + hitOrReturn,Kernel.piecewise_apply,ite_eq_left hReg,Kernel.id_apply, + Measure.map_dirac' (measurable_const.prodMk embedOdd_measurable)] + congr 1 + exact Prod.ext hz hz + · rw [rawContinuationKernel,Kernel.piecewise_apply,ite_eq_right (fun he => hReg (hp.mp he)), + Kernel.map_apply _ measurable_inr, + Measure.map_map (rawContinuationSignature_measurable a) measurable_inr, + hitOrReturn,Kernel.piecewise_apply,ite_eq_right hReg] + exact rawReturnTrace_input_endpoint a h z hz + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.TransitionKernels +open NumberTheoryLean.InitialOddDraw NumberTheoryLean.InitialRegeneration + +lemma rawExtension_last_step (a : ℕ) (h : RawHistory a) : + (rawExtension a (a+1) h).map (rawLast (a+1))=costKernel (rawLast a h) := by + have he := congrArg (fun K : Kernel (RawHistory a) CostState => K h) + (Kernel.map_partialTraj_succ_self (X := fun _ => CostState) (κ := historyKernel) a) + change ((rawExtension a (a+1)).map (rawLast (a+1))) h=costKernel (rawLast a h) at he + rw [Kernel.map_apply _ (rawLast_measurable (a+1))] at he + exact he + +lemma rawFirstOdd_draw_law (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + (rawExtension a (a+1) h).map (rawLast (a+1))=(firstOdd s).map embedOdd := by + rw [rawExtension_last_step,hs,firstOdd_full_draw] + +noncomputable def oddCostStates : Set CostState := Prod.fst ⁻¹' Set.range (Sum.inr : OddState → State) + +lemma oddCostStates_measurable : MeasurableSet oddCostStates := + measurableSet_range_inr.preimage measurable_fst + +lemma embedOdd_mem_oddCostStates (z : OddCost) : embedOdd z ∈ oddCostStates := ⟨z.1,rfl⟩ + +lemma embed_decodeReturnedOdd_of_oddCostStates (s : CostState) (hs : s ∈ oddCostStates) : + embedOdd (decodeReturnedOdd s)=s := by + rcases s with ⟨s,T⟩ + rcases hs with ⟨o,ho⟩ + change Sum.inr o=s at ho + subst s + rfl + +lemma rawFirstOdd_ae_odd (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + ∀ᵐ y ∂rawExtension a (a+1) h, rawLast (a+1) y ∈ oddCostStates := by + apply (ae_map_iff (rawLast_measurable (a+1)).aemeasurable oddCostStates_measurable).mp + rw [rawFirstOdd_draw_law a h s hs] + apply (ae_map_iff embedOdd_measurable.aemeasurable oddCostStates_measurable).mpr + exact Filter.Eventually.of_forall embedOdd_mem_oddCostStates + +abbrev RawInitialEvenTrace (a : ℕ) := RawContinuationTrace (a+1) + +noncomputable def rawInitialEvenKernel (a : ℕ) : Kernel (RawHistory a) (RawInitialEvenTrace a) := + rawContinuationKernel (a+1) ∘ₖ rawExtension a (a+1) + +instance rawInitialEvenKernel_isFiniteKernel (a : ℕ) : IsFiniteKernel (rawInitialEvenKernel a) := by + unfold rawInitialEvenKernel + infer_instance + +noncomputable def initialOddReturnJoint : Kernel EvenState (OddCost × OddCost) := + firstOdd ⊗ₖ hitOrReturn.prodMkLeft EvenState + +instance initialOddReturnJoint_isMarkovKernel : IsMarkovKernel initialOddReturnJoint := by + unfold initialOddReturnJoint + infer_instance + +noncomputable def embedOddPair (p : OddCost × OddCost) : CostState × CostState := (embedOdd p.1,embedOdd p.2) + +lemma embedOddPair_measurable : Measurable embedOddPair := + (embedOdd_measurable.comp measurable_fst).prodMk (embedOdd_measurable.comp measurable_snd) + +theorem rawInitialEven_joint_signature (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + (rawInitialEvenKernel a h).map (rawContinuationSignature (a+1)) = + (initialOddReturnJoint s).map embedOddPair := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (rawContinuationSignature_measurable _),rawInitialEvenKernel, + Kernel.lintegral_comp _ _ _ (g := fun r => F (rawContinuationSignature (a+1) r)) + (hF.comp (rawContinuationSignature_measurable _)), + lintegral_map hF embedOddPair_measurable,initialOddReturnJoint, + Kernel.lintegral_compProd _ _ _ (f := fun p : OddCost × OddCost => F (embedOddPair p)) + (hF.comp embedOddPair_measurable)] + let G : CostState → ℝ≥0∞ := fun c => ∫⁻ y, F (c,embedOdd y) ∂hitOrReturn (decodeReturnedOdd c) + have hG : Measurable G := by + let K : Kernel CostState OddCost := hitOrReturn.comap decodeReturnedOdd decodeReturnedOdd_measurable + change Measurable (fun c : CostState => ∫⁻ y, F (c,embedOdd y) ∂K c) + exact Measurable.lintegral_kernel_prod_right' (κ := K) + (f := fun p : CostState × OddCost => F (p.1,embedOdd p.2)) + (hF.comp (measurable_fst.prodMk (embedOdd_measurable.comp measurable_snd))) + have he : (fun y : RawHistory (a+1) => ∫⁻ r, F (rawContinuationSignature (a+1) r) ∂rawContinuationKernel (a+1) y) + =ᵐ[rawExtension a (a+1) h] fun y => G (rawLast (a+1) y) := by + filter_upwards [rawFirstOdd_ae_odd a h s hs] with y hy + let z : OddCost := decodeReturnedOdd (rawLast (a+1) y) + have hz : rawLast (a+1) y=embedOdd z := (embed_decodeReturnedOdd_of_oddCostStates _ hy).symm + rw [← lintegral_map (g := rawContinuationSignature (a+1)) hF (rawContinuationSignature_measurable _), + rawContinuation_signature (a+1) y z hz, + lintegral_map (g := fun u : OddCost => (embedOdd z,embedOdd u)) hF + (measurable_const.prodMk embedOdd_measurable)] + change (∫⁻ u, F (embedOdd z,embedOdd u) ∂hitOrReturn z) = + ∫⁻ u, F (rawLast (a+1) y,embedOdd u) ∂hitOrReturn z + apply lintegral_congr + intro u + rw [hz] + rw [lintegral_congr_ae he,← lintegral_map (g := rawLast (a+1)) hG (rawLast_measurable _), + rawFirstOdd_draw_law a h s hs,lintegral_map hG embedOdd_measurable] + rfl + +def rawInitialEvenDuration (a : ℕ) : RawInitialEvenTrace a → ℕ := + Sum.elim (fun _ => 1) (fun r => 1+2*(r.1+1)) + +lemma rawInitialEvenDuration_positive (a : ℕ) (r : RawInitialEvenTrace a) : 0 < rawInitialEvenDuration a r := by + cases r with + | inl h => exact Nat.zero_lt_one + | inr r => change 0 < 1+2*(r.1+1); omega + +theorem rawInitialEven_mass_one (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : rawInitialEvenKernel a h univ=1 := by + have he := congrArg (fun μ : Measure (CostState × CostState) => μ univ) (rawInitialEven_joint_signature a h s hs) + rw [Measure.map_apply (rawContinuationSignature_measurable _) MeasurableSet.univ, + Measure.map_apply embedOddPair_measurable MeasurableSet.univ,preimage_univ,preimage_univ] at he + exact he.trans measure_univ + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialIncreasing.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialIncreasing.lean new file mode 100644 index 0000000000000000000000000000000000000000..131f9b2bb2fa4d8cb3dfbbd112556f3a9f086849 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialIncreasing.lean @@ -0,0 +1,67 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawIncreasingPrefix + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures + +noncomputable def continuationIncreasing (a b : ℕ) : Set (RawContinuationTrace b) := + {r | Sum.elim (fun h => h ∈ increasingCosts a b) (fun r => r ∈ returnIncreasing a b) r} + +lemma continuationIncreasing_measurable (a b : ℕ) : MeasurableSet (continuationIncreasing a b) := by + apply measurableSet_sum_iff.mpr + constructor + · exact increasingCosts_measurable a b + · exact returnIncreasing_measurable a b + +lemma rawContinuation_increasing (a b : ℕ) (h : RawHistory b) (hh : h ∈ increasingCosts a b) : + ∀ᵐ r ∂rawContinuationKernel b h, r ∈ continuationIncreasing a b := by + rw [rawContinuationKernel,Kernel.piecewise_apply] + split_ifs + · rw [Kernel.map_apply _ measurable_inl] + apply (ae_map_iff measurable_inl.aemeasurable (continuationIncreasing_measurable a b)).mpr + change ∀ᵐ y ∂Measure.dirac h, y ∈ increasingCosts a b + exact (ae_dirac_iff (increasingCosts_measurable a b)).mpr hh + · rw [Kernel.map_apply _ measurable_inr] + exact (ae_map_iff measurable_inr.aemeasurable (continuationIncreasing_measurable a b)).mpr + (rawReturn_increasing a b h hh) + +noncomputable def packedIncreasing (a : ℕ) : Set (RawInitialPackedTrace a) := + {r | r.2 ∈ increasingCosts a ((a+1)+2*r.1)} + +lemma packedIncreasing_measurable (a : ℕ) : MeasurableSet (packedIncreasing a) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro k + exact increasingCosts_measurable a _ + +lemma packRawInitialEven_increasing (a : ℕ) (r : RawInitialEvenTrace a) + (hr : r ∈ continuationIncreasing a (a+1)) : packRawInitialEven a r ∈ packedIncreasing a := by + cases r with + | inl y => exact hr + | inr y => exact hr + +theorem packedInitial_increasing (a : ℕ) (h : RawHistory a) : + ∀ᵐ r ∂packedInitialKernel a h, r ∈ packedIncreasing a := by + rw [packedInitialKernel,Kernel.map_apply _ (packRawInitialEven_measurable a)] + apply (ae_map_iff (packRawInitialEven_measurable a).aemeasurable (packedIncreasing_measurable a)).mpr + have hs : ∀ᵐ r ∂rawInitialEvenKernel a h, r ∈ continuationIncreasing a (a+1) := by + rw [rawInitialEvenKernel] + apply Kernel.ae_comp_of_ae_ae (continuationIncreasing_measurable a (a+1)) + filter_upwards [rawExtension_increasingCosts a (a+1) h] with y hy + exact rawContinuation_increasing a (a+1) y hy + filter_upwards [hs] with r hr + exact packRawInitialEven_increasing a r hr + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialPacking.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialPacking.lean new file mode 100644 index 0000000000000000000000000000000000000000..7a46c147d5c164f639d9c3e311ca4069fc45451f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawInitialPacking.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Paths.QuantitativeOrdinaryHit + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.InitialRegeneration +open NumberTheoryLean.FirstHitKernels NumberTheoryLean.TransitionKernels + +abbrev RawInitialPackedTrace (a : ℕ) := Σ k : ℕ, RawHistory ((a+1)+2*k) + +def packRawInitialEven (a : ℕ) : RawInitialEvenTrace a → RawInitialPackedTrace a + | Sum.inl h => @Sigma.mk ℕ (fun k => RawHistory ((a+1)+2*k)) 0 h + | Sum.inr r => @Sigma.mk ℕ (fun k => RawHistory ((a+1)+2*k)) (r.1+1) r.2 + +lemma packRawInitialEven_measurable (a : ℕ) : Measurable (packRawInitialEven a) := by + apply Measurable.sumElim + · exact measurableSigmaMk (X := fun k : ℕ => RawHistory ((a+1)+2*k)) 0 + · apply measurable_sigma_family + intro n + exact measurableSigmaMk (X := fun k : ℕ => RawHistory ((a+1)+2*k)) (n+1) + +noncomputable def packedInitialKernel (a : ℕ) : Kernel (RawHistory a) (RawInitialPackedTrace a) := + (rawInitialEvenKernel a).map (packRawInitialEven a) + +instance packedInitialKernel_isFiniteKernel (a : ℕ) : IsFiniteKernel (packedInitialKernel a) := by + unfold packedInitialKernel + infer_instance + +noncomputable def packedInitialEndpoint (a : ℕ) (r : RawInitialPackedTrace a) : CostState := + rawLast ((a+1)+2*r.1) r.2 + +lemma packedInitialEndpoint_measurable (a : ℕ) : Measurable (packedInitialEndpoint a) := by + apply measurable_sigma_family + intro k + exact rawLast_measurable _ + +lemma packedInitialEndpoint_pack (a : ℕ) (r : RawInitialEvenTrace a) : + packedInitialEndpoint a (packRawInitialEven a r)=rawInitialEndpointState a r := by + cases r with + | inl h => rfl + | inr r => rfl + +theorem packedInitial_endpoint_law (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + (packedInitialKernel a h).map (packedInitialEndpoint a)=(delayedRegeneration s).map embedOdd := by + rw [packedInitialKernel,Kernel.map_apply _ (packRawInitialEven_measurable a), + Measure.map_map (packedInitialEndpoint_measurable a) (packRawInitialEven_measurable a)] + have he : packedInitialEndpoint a ∘ packRawInitialEven a=rawInitialEndpointState a := + funext (packedInitialEndpoint_pack a) + rw [he,rawInitialEven_endpoint a h s hs] + +lemma packedInitial_ae_regeneration (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : + ∀ᵐ r ∂packedInitialKernel a h, packedInitialEndpoint a r ∈ regenerationSet := by + apply (ae_map_iff (packedInitialEndpoint_measurable a).aemeasurable regenerationSet_measurable).mp + rw [packedInitial_endpoint_law a h s hs] + apply (ae_map_iff embedOdd_measurable.aemeasurable regenerationSet_measurable).mpr + exact delayedRegeneration_ae_regeneration s + +lemma packedInitial_mass_one (a : ℕ) (h : RawHistory a) (s : EvenState) + (hs : rawLast a h=(Sum.inl s,0)) : packedInitialKernel a h univ=1 := by + rw [packedInitialKernel,Kernel.map_apply' _ (packRawInitialEven_measurable a) _ MeasurableSet.univ,preimage_univ] + exact rawInitialEven_mass_one a h s hs + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawReturnBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawReturnBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f5ed9ee55b8392c82f6ccb6037bf3921f2110ed --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawReturnBound.lean @@ -0,0 +1,323 @@ +import OAI.NumberTheory.Jacobsthal.Paths.SourceWitnessSeries + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FinitePathGeometry + +abbrev RawReturnTrace (a : ℕ) := Σ n : ℕ, RawHistory (a+2*(n+1)) +abbrev ReturnSignature := ℕ × (CostState × CostState) + +def packRawReturnTrace (a n : ℕ) (h : RawHistory (a+2*(n+1))) : RawReturnTrace a := + @Sigma.mk ℕ (fun k => RawHistory (a+2*(k+1))) n h + +lemma rawReturnTrace_mk_measurable (a n : ℕ) : + Measurable (packRawReturnTrace a n : RawHistory (a+2*(n+1)) → RawReturnTrace a) := by + apply Measurable.of_le_map + exact iInf_le _ n + +noncomputable def rawReturnTraceKernel (a : ℕ) : Kernel (RawHistory a) (RawReturnTrace a) := + Kernel.sum (fun n : ℕ => (firstReturnHistory a n).map (packRawReturnTrace a n)) + +instance rawReturnTraceKernel_isSFiniteKernel (a : ℕ) : IsSFiniteKernel (rawReturnTraceKernel a) := by + unfold rawReturnTraceKernel + infer_instance + +noncomputable def rawReturnSignature (a : ℕ) (r : RawReturnTrace a) : ReturnSignature := + (2*(r.1+1),rawCyclePairEval a (a+2*(r.1+1)) (by omega) r.2) + +lemma rawReturnSignature_measurable (a : ℕ) : Measurable (rawReturnSignature a) := by + intro S hS + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + change MeasurableSet ((fun h : RawHistory (a+2*(n+1)) => + (2*(n+1),rawCyclePairEval a (a+2*(n+1)) (by omega) h)) ⁻¹' S) + exact (measurable_const.prodMk (rawCyclePairEval_measurable _ _ (by omega))) hS + +noncomputable def sourceReturnSignature (z : OddCost) (w : SourceCycleWitness) : ReturnSignature := + (w.2.1,((Sum.inl w.1,z.2+cost w.1.1),embedOdd w.2.2)) + +lemma sourceReturnSignature_measurable (z : OddCost) : Measurable (sourceReturnSignature z) := + (measurable_fst.comp measurable_snd).prodMk + (((measurable_inl.comp measurable_fst).prodMk + (measurable_const.add (cost_measurable.comp (measurable_subtype_coe.comp measurable_fst)))).prodMk + (embedOdd_measurable.comp (measurable_snd.comp measurable_snd))) + +lemma sourceReturnSignature_injective (z : OddCost) : Function.Injective (sourceReturnSignature z) := by + intro x y h + have hn : x.2.1=y.2.1 := congrArg (fun r : ReturnSignature => r.1) h + have he : x.1=y.1 := Sum.inl.inj (congrArg (fun r : ReturnSignature => r.2.1.1) h) + have ho : embedOdd x.2.2=embedOdd y.2.2 := congrArg (fun r : ReturnSignature => r.2.2) h + have hs : (embedOdd x.2.2).1=(embedOdd y.2.2).1 := congrArg (fun r : CostState => r.1) ho + have hc : (embedOdd x.2.2).2=(embedOdd y.2.2).2 := congrArg (fun r : CostState => r.2) ho + have hr : x.2.2=y.2.2 := Prod.ext (Sum.inr.inj hs) hc + exact Prod.ext he (Prod.ext hn hr) + +lemma rawReturnTerm_signature (a n : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (((firstReturnHistory a n).map (packRawReturnTrace a n)) h).map (rawReturnSignature a) = + (sourceWitnessTerm n z).map (sourceReturnSignature z) := by + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable a n), + Measure.map_map (rawReturnSignature_measurable a) (rawReturnTrace_mk_measurable a n), + sourceWitnessTerm,Kernel.map_apply _ (tagSourceReturn_measurable n), + Measure.map_map (sourceReturnSignature_measurable z) (tagSourceReturn_measurable n)] + have he := congrArg (fun μ : Measure (CostState × CostState) => μ.map (fun p => (2*(n+1),p))) + (firstReturnHistory_joint a n h z hz) + rw [Measure.map_map (g := fun p : CostState × CostState => (2*(n+1),p)) + (f := rawCyclePairEval a (a+2*(n+1)) (by omega)) + (measurable_const.prodMk measurable_id) (rawCyclePairEval_measurable _ _ (by omega)), + Measure.map_map (g := fun p : CostState × CostState => (2*(n+1),p)) + (f := pairTraceOfWitness z) (measurable_const.prodMk measurable_id) (pairTraceOfWitness_measurable z)] at he + exact he + +theorem rawReturnTrace_signature (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (rawReturnTraceKernel a h).map (rawReturnSignature a) = + (sourceCycleWitnessKernel z).map (sourceReturnSignature z) := by + rw [rawReturnTraceKernel,Kernel.sum_apply, + Measure.map_sum (rawReturnSignature_measurable a).aemeasurable, + sourceCycleWitness_series,Kernel.sum_apply, + Measure.map_sum (sourceReturnSignature_measurable z).aemeasurable] + apply congrArg Measure.sum + funext n + exact rawReturnTerm_signature a n h z hz + +theorem rawReturnTrace_mass_one (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : rawReturnTraceKernel a h univ=1 := by + have he := congrArg (fun μ : Measure ReturnSignature => μ univ) (rawReturnTrace_signature a h z hz) + rw [Measure.map_apply (rawReturnSignature_measurable a) MeasurableSet.univ, + Measure.map_apply (sourceReturnSignature_measurable z) MeasurableSet.univ,preimage_univ, + preimage_univ] at he + exact he.trans measure_univ + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels + +noncomputable def twoReturnHistory (a n m : ℕ) : + Kernel (RawHistory a) (RawHistory ((a+2*(n+1))+2*(m+1))) := + firstReturnHistory (a+2*(n+1)) m ∘ₖ firstReturnHistory a n + +instance twoReturnHistory_isFiniteKernel (a n m : ℕ) : IsFiniteKernel (twoReturnHistory a n m) := by + unfold twoReturnHistory + infer_instance + +noncomputable def twoReturnEvent (a n m : ℕ) : Set (RawHistory ((a+2*(n+1))+2*(m+1))) := + (rawPrefix (show a+2*(n+1) ≤ (a+2*(n+1))+2*(m+1) by omega) ⁻¹' + (avoidOddReturns a n (a+2*(n+1)) (by omega) ∩ lastRegeneration (a+2*(n+1)))) ∩ + (avoidOddReturns (a+2*(n+1)) m ((a+2*(n+1))+2*(m+1)) (by omega) ∩ + lastRegeneration ((a+2*(n+1))+2*(m+1))) + +lemma twoReturnEvent_measurable (a n m : ℕ) : MeasurableSet (twoReturnEvent a n m) := + (((avoidOddReturns_measurable a n (a+2*(n+1)) (by omega)).inter (lastRegeneration_measurable _)).preimage + (rawPrefix_measurable (by omega))).inter + ((avoidOddReturns_measurable (a+2*(n+1)) m ((a+2*(n+1))+2*(m+1)) (by omega)).inter + (lastRegeneration_measurable _)) + +theorem twoReturnHistory_eq_cylinder (a n m : ℕ) : + twoReturnHistory a n m = + (rawExtension a ((a+2*(n+1))+2*(m+1))).restrict (twoReturnEvent_measurable a n m) := by + rw [twoReturnHistory,firstReturnHistory,firstReturnHistory, + ← rawExtension_restrict_comp (show a ≤ a+2*(n+1) by omega) + (show a+2*(n+1) ≤ (a+2*(n+1))+2*(m+1) by omega) + ((avoidOddReturns_measurable a n (a+2*(n+1)) (by omega)).inter (lastRegeneration_measurable _)) + ((avoidOddReturns_measurable (a+2*(n+1)) m ((a+2*(n+1))+2*(m+1)) (by omega)).inter + (lastRegeneration_measurable _))] + rfl + +lemma twoReturnHistory_retains_past (a n m : ℕ) (h : RawHistory a) : + ∀ᵐ r ∂twoReturnHistory a n m h, + rawPrefix (show a ≤ (a+2*(n+1))+2*(m+1) by omega) r=h := by + rw [twoReturnHistory_eq_cylinder,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawExtension_retains_prefix (by omega) h) + +noncomputable def twoReturnHistoryWithFirsts (a n m : ℕ) {E F : Set CostState} + (hE : MeasurableSet E) (hF : MeasurableSet F) : + Kernel (RawHistory a) (RawHistory ((a+2*(n+1))+2*(m+1))) := + (twoReturnHistory a n m).restrict + ((hE.preimage (measurable_pi_apply (⟨a+1,Finset.mem_Iic.mpr (by omega)⟩ : + Finset.Iic ((a+2*(n+1))+2*(m+1))))).inter + (hF.preimage (measurable_pi_apply (⟨(a+2*(n+1))+1,Finset.mem_Iic.mpr (by omega)⟩ : + Finset.Iic ((a+2*(n+1))+2*(m+1)))))) + +lemma twoReturnHistoryWithFirsts_apply (a n m : ℕ) {E F : Set CostState} + (hE : MeasurableSet E) (hF : MeasurableSet F) (h : RawHistory a) + {S : Set (RawHistory ((a+2*(n+1))+2*(m+1)))} (hS : MeasurableSet S) : + twoReturnHistoryWithFirsts a n m hE hF h S = rawExtension a ((a+2*(n+1))+2*(m+1)) h + ((S ∩ ({r | r ⟨a+1,Finset.mem_Iic.mpr (by omega)⟩ ∈ E} ∩ + {r | r ⟨(a+2*(n+1))+1,Finset.mem_Iic.mpr (by omega)⟩ ∈ F})) ∩ twoReturnEvent a n m) := by + rw [twoReturnHistoryWithFirsts,Kernel.restrict_apply' _ _ _ hS,twoReturnHistory_eq_cylinder, + Kernel.restrict_apply' _ _ _ (hS.inter ((hE.preimage (measurable_pi_apply _)).inter + (hF.preimage (measurable_pi_apply _))))] + rfl + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FirstHitKernels + +abbrev RawTwoReturnTrace (a : ℕ) := + Σ n : ℕ, Σ m : ℕ, RawHistory ((a+2*(n+1))+2*(m+1)) + +def packRawTwoReturnTrace (a n m : ℕ) (h : RawHistory ((a+2*(n+1))+2*(m+1))) : RawTwoReturnTrace a := + @Sigma.mk ℕ (fun i => Σ j : ℕ, RawHistory ((a+2*(i+1))+2*(j+1))) n + (@Sigma.mk ℕ (fun j => RawHistory ((a+2*(n+1))+2*(j+1))) m h) + +lemma measurableSigmaMk {ι : Type*} {X : ι → Type*} [∀ i, MeasurableSpace (X i)] (i : ι) : + Measurable (@Sigma.mk ι X i) := Measurable.of_le_map (iInf_le _ i) + +lemma packRawTwoReturnTrace_measurable (a n m : ℕ) : Measurable (packRawTwoReturnTrace a n m) := by + exact (measurableSigmaMk (X := fun i : ℕ => Σ j : ℕ, RawHistory ((a+2*(i+1))+2*(j+1))) n).comp + (measurableSigmaMk (X := fun j : ℕ => RawHistory ((a+2*(n+1))+2*(j+1))) m) + +noncomputable def rawTwoReturnTraceKernel (a : ℕ) : Kernel (RawHistory a) (RawTwoReturnTrace a) := + Kernel.sum (fun n : ℕ => Kernel.sum (fun m : ℕ => + (twoReturnHistory a n m).map (packRawTwoReturnTrace a n m))) + +instance rawTwoReturnTraceKernel_isSFiniteKernel (a : ℕ) : IsSFiniteKernel (rawTwoReturnTraceKernel a) := by + unfold rawTwoReturnTraceKernel + infer_instance + +lemma rawReturnTrace_mass_series (a : ℕ) (h : RawHistory a) : + rawReturnTraceKernel a h univ = ∑' n : ℕ, firstReturnHistory a n h univ := by + rw [rawReturnTraceKernel,Kernel.sum_apply' _ _ MeasurableSet.univ] + apply tsum_congr + intro n + rw [Kernel.map_apply' _ (rawReturnTrace_mk_measurable a n) _ MeasurableSet.univ,preimage_univ] + +lemma rawReturnTrace_mass_at_regeneration (a : ℕ) (h : RawHistory a) + (hReg : rawLast a h ∈ regenerationSet) : rawReturnTraceKernel a h univ=1 := by + rcases he : rawLast a h with ⟨s,T⟩ + cases s with + | inl s => + rw [he] at hReg + exact False.elim (regeneration_even s T hReg) + | inr s => exact rawReturnTrace_mass_one a h (s,T) he + +lemma rawTwoReturnTrace_mass_series (a : ℕ) (h : RawHistory a) : + rawTwoReturnTraceKernel a h univ = ∑' n : ℕ, ∑' m : ℕ, twoReturnHistory a n m h univ := by + rw [rawTwoReturnTraceKernel,Kernel.sum_apply' _ _ MeasurableSet.univ] + apply tsum_congr + intro n + rw [Kernel.sum_apply' _ _ MeasurableSet.univ] + apply tsum_congr + intro m + rw [Kernel.map_apply' _ (packRawTwoReturnTrace_measurable a n m) _ MeasurableSet.univ,preimage_univ] + +theorem rawTwoReturnTrace_mass_conditioning (a : ℕ) (h : RawHistory a) : + rawTwoReturnTraceKernel a h univ = ∑' n : ℕ, + ∫⁻ y, rawReturnTraceKernel (a+2*(n+1)) y univ ∂firstReturnHistory a n h := by + rw [rawTwoReturnTrace_mass_series] + apply tsum_congr + intro n + simp_rw [twoReturnHistory,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + rw [← lintegral_tsum (f := fun (m : ℕ) (y : RawHistory (a+2*(n+1))) => + firstReturnHistory (a+2*(n+1)) m y univ) + (fun m => ((firstReturnHistory (a+2*(n+1)) m).measurable_coe MeasurableSet.univ).aemeasurable)] + apply lintegral_congr + intro y + exact (rawReturnTrace_mass_series _ y).symm + +theorem rawTwoReturnTrace_mass_one (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : rawTwoReturnTraceKernel a h univ=1 := by + rw [rawTwoReturnTrace_mass_conditioning] + have he (n : ℕ) : (∫⁻ y, rawReturnTraceKernel (a+2*(n+1)) y univ ∂firstReturnHistory a n h) = + firstReturnHistory a n h univ := by + have hae : (fun y => rawReturnTraceKernel (a+2*(n+1)) y univ) =ᵐ[firstReturnHistory a n h] fun _ => 1 := by + filter_upwards [firstReturnHistory_ae_cylinder a n h] with y hy + exact rawReturnTrace_mass_at_regeneration _ y hy.2 + rw [lintegral_congr_ae hae] + simp + simp_rw [he] + rw [← rawReturnTrace_mass_series a h,rawReturnTrace_mass_one a h z hz] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels + +lemma fullPairCaptured_add_killed : fullPairCaptured+fullPairKilled=costKernel^2 := by + ext z : 1 + rw [_root_.add_apply,fullPairCaptured,fullPairKilled,Kernel.restrict_apply,Kernel.restrict_apply] + exact Measure.restrict_add_restrict_compl regenerationSet_measurable + +lemma fullPairReturn_mass_step (n : ℕ) (z : CostState) : + fullPairReturn n z univ+(fullPairKilled^(n+1)) z univ=(fullPairKilled^n) z univ := by + have : IsMarkovKernel (costKernel^2) := by rw [pow_two]; change IsMarkovKernel (costKernel ∘ₖ costKernel); infer_instance + have hp : fullPairKilled^(n+1)=fullPairKilled ∘ₖ (fullPairKilled^n) := pow_succ' _ _ + calc + _ = ((fullPairCaptured+fullPairKilled) ∘ₖ (fullPairKilled^n)) z univ := by + rw [Kernel.comp_add_left,_root_.add_apply,Measure.add_apply,hp] + rfl + _ = ((costKernel^2) ∘ₖ (fullPairKilled^n)) z univ := by rw [fullPairCaptured_add_killed] + _ = _ := by rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ]; simp + +lemma fullPairReturn_finite_mass (n : ℕ) (z : CostState) : + (fullPairKilled^n) z univ+∑ k ∈ Finset.range n, fullPairReturn k z univ=1 := by + induction n with + | zero => change (Measure.dirac z) univ+0=1; simp + | succ n ih => + rw [Finset.sum_range_succ] + calc + _ = (∑ k ∈ Finset.range n, fullPairReturn k z univ)+ + (fullPairReturn n z univ+(fullPairKilled^(n+1)) z univ) := by ac_rfl + _ = _ := by rw [fullPairReturn_mass_step]; simpa only [add_comm] using ih + +lemma fullPairReturn_total_mass_le (z : CostState) : + (∑' n : ℕ, fullPairReturn n z univ) ≤ 1 := by + rw [ENNReal.tsum_eq_iSup_nat] + apply iSup_le + intro n + calc + _ ≤ (fullPairKilled^n) z univ+∑ k ∈ Finset.range n, fullPairReturn k z univ := le_add_left le_rfl + _ = 1 := fullPairReturn_finite_mass n z + +lemma firstReturnHistory_mass_full (a n : ℕ) (h : RawHistory a) : + firstReturnHistory a n h univ=fullPairReturn n (rawLast a h) univ := by + have he := congrArg (fun K : Kernel (RawHistory a) CostState => K h univ) + (firstReturnHistory_kernel_projection a n) + rw [Kernel.map_apply' _ (rawLast_measurable _) _ MeasurableSet.univ,preimage_univ,Kernel.comap_apply] at he + exact he + +theorem rawReturnTrace_mass_le_one (a : ℕ) (h : RawHistory a) : rawReturnTraceKernel a h univ ≤ 1 := by + rw [rawReturnTrace_mass_series] + simp_rw [firstReturnHistory_mass_full] + exact fullPairReturn_total_mass_le _ + +instance rawReturnTraceKernel_isFiniteKernel (a : ℕ) : IsFiniteKernel (rawReturnTraceKernel a) := + ⟨⟨1,by simp,rawReturnTrace_mass_le_one a⟩⟩ + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawSuppliedPast.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawSuppliedPast.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8681bb41a654dc02cd5f72a7a46ebe678e5eae8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RawSuppliedPast.lean @@ -0,0 +1,211 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawStableHistory +import OAI.NumberTheory.Jacobsthal.Probability.ArrivalKernelGeometry + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures + +variable (F : CostState → ℝ) (hF : Measurable F) +variable (hStep : ∀ z, ∀ᵐ y ∂costKernel z, F z ≤ F y) + +noncomputable def scalarHistory (b : ℕ) (h : RawHistory b) : RawHistory b := fun i => ((h i).1,F (h i)) +include hF in +lemma scalarHistory_measurable (b : ℕ) : Measurable (scalarHistory F b) := by + apply Measurable.of_eval + intro i + exact ((measurable_fst.comp (measurable_pi_apply i)).prodMk (hF.comp (measurable_pi_apply i))) + +noncomputable def scalarIncreasing (a b : ℕ) : Set (RawHistory b) := + scalarHistory F b ⁻¹' increasingCosts a b + +include hF in +lemma scalarIncreasing_measurable (a b : ℕ) : MeasurableSet (scalarIncreasing F a b) := + (increasingCosts_measurable a b).preimage (scalarHistory_measurable F hF b) + +include hF hStep in +lemma rawExtension_scalar_step (k : ℕ) (h : RawHistory k) : + ∀ᵐ y ∂rawExtension k (k+1) h, + F (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩) ≤ F (rawLast (k+1) y) := by + have hs : ∀ᵐ y ∂rawExtension k (k+1) h, F (rawLast k h) ≤ F (rawLast (k+1) y) := by + apply (ae_map_iff (rawLast_measurable (k+1)).aemeasurable + (measurableSet_le measurable_const hF)).mp + rw [rawExtension_last_step] + exact hStep _ + filter_upwards [hs,rawExtension_retains_prefix (show k ≤ k+1 by omega) h] with y hy hp + have he := congrFun hp (⟨k,by simp⟩ : Finset.Iic k) + change y ⟨k,_⟩=rawLast k h at he + rw [he] + exact hy + +include hF hStep in +lemma rawExtension_scalar_coordinate {a b k : ℕ} (hak : a ≤ k) (hkb : k < b) (h : RawHistory a) : + ∀ᵐ y ∂rawExtension a b h, + F (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩) ≤ F (y ⟨k+1,Finset.mem_Iic.mpr (by omega)⟩) := by + have hm : MeasurableSet {y : RawHistory (k+1) | + F (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩) ≤ F (rawLast (k+1) y)} := + measurableSet_le (hF.comp (measurable_pi_apply _)) (hF.comp (rawLast_measurable _)) + have he : (rawExtension a b h).map (rawPrefix (show k+1 ≤ b by omega))=rawExtension a (k+1) h := + Kernel.partialTraj_map_frestrictLe₂_apply (X := fun _ => CostState) (κ := historyKernel) h (show k+1 ≤ b by omega) + have ht : ∀ᵐ y ∂rawExtension a (k+1) h, + F (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩) ≤ F (rawLast (k+1) y) := by + have hc : rawExtension a (k+1)=rawExtension k (k+1) ∘ₖ rawExtension a k := + (Kernel.partialTraj_comp_partialTraj hak (by omega)).symm + rw [hc] + exact Kernel.ae_comp_of_ae_ae hm (Eventually.of_forall (rawExtension_scalar_step F hF hStep k)) + rw [← he] at ht + exact (ae_map_iff (rawPrefix_measurable (show k+1 ≤ b by omega)).aemeasurable hm).mp ht + +include hF hStep in +lemma rawExtension_scalarIncreasing (a b : ℕ) (h : RawHistory a) : + ∀ᵐ y ∂rawExtension a b h, y ∈ scalarIncreasing F a b := by + have hs : ∀ᵐ y ∂rawExtension a b h, ∀ k : Fin b, a ≤ k.1 → + F (y ⟨k.1,Finset.mem_Iic.mpr (by have hk:=k.2; omega)⟩) ≤ + F (y ⟨k.1+1,Finset.mem_Iic.mpr (by have hk:=k.2; omega)⟩) := by + rw [ae_all_iff] + intro k + by_cases hak : a ≤ k.1 + · filter_upwards [rawExtension_scalar_coordinate F hF hStep hak k.2 h] with y hy + exact fun _ => hy + · exact Eventually.of_forall (fun _ hy => (hak hy).elim) + filter_upwards [hs] with y hy + exact increasingCosts_of_steps (scalarHistory F b y) hy + +include hF hStep in +lemma rawExtension_preserves_scalar {a b c : ℕ} (hbc : b ≤ c) (h : RawHistory b) + (hh : h ∈ scalarIncreasing F a b) : + ∀ᵐ y ∂rawExtension b c h, y ∈ scalarIncreasing F a c := by + filter_upwards [rawExtension_scalarIncreasing F hF hStep b c h,rawExtension_retains_prefix hbc h] with y hy hp + apply increasingCosts_extend hbc (scalarHistory F b h) (scalarHistory F c y) hh hy + have he := congrArg (scalarHistory F b) hp + exact he + +include hF hStep in +theorem rawEvenHit_scalarIncreasing (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a v H h, + rawEvenFinalCycle a z ∈ selectedHistoryProperty (scalarIncreasing F a) := by + apply rawEvenHit_historyProperty (scalarIncreasing F a) (scalarIncreasing_measurable F hF a) + · intro b c hbc past hp + exact rawExtension_preserves_scalar F hF hStep hbc past hp + · exact increasingCosts_at_start a (scalarHistory F a h) + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels NumberTheoryLean.RegeneratingInverseBands +open NumberTheoryLean.ArrivalKernelGeometry + +lemma gapValue_log_eq_gapAt {r : ℝ} (hr : 0 < r) (z : CostState) : + gapValue (Real.log r) z=gapAt r z.2 := by + unfold gapValue gapAt + rw [Real.exp_sub,Real.exp_log hr,Real.exp_neg,div_eq_mul_inv] + +lemma record_currentExponent {r : ℝ} (hr : 0 < r) {c : CycleInputSignature} {tau : EvenState} + (hF : recordFirst c=(Sum.inl tau,c.1+cost tau.1)) : + currentExponent (Real.log r) (recordFirst c)=nextExponent (gapAt r c.1) tau.1 := by + unfold currentExponent + rw [gapValue_log_eq_gapAt hr,hF] + change gapAt r (c.1+cost tau.1)/tau.1=nextExponent (gapAt r c.1) tau.1 + have ht : 0 < tau.1 := by have h := tau.2; change (198/100:ℝ) ≤ tau.1 at h; linarith + rw [gapAt_add_cost r c.1 tau.1 ht,nextGap_div_ratio ht] + +theorem rawEvenHit_before_cutoff {r b0 b1 ell : ℝ} (hr : 0 < r) (hb0 : 0 < b0) + (hb1 : 0 < b1) (hell : ell < 2*b0) (a : ℕ) (h0 : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a (Real.log (r/b1)) (Real.log (b1/(10*b0))) h0, + let q := rawEvenFinalCycle a z + ∀ j : Finset.Iic (q.1+2*(q.2.1+1)), a ≤ j.1 → j.1 ≤ q.1+1 → + q.2.2 j ∈ arrivalSet (Real.log r) ell := by + have hF : Measurable (fun z => -currentExponent (Real.log r) z) := (currentExponent_measurable _).neg + have hStep (z : CostState) : ∀ᵐ y ∂costKernel z, + -currentExponent (Real.log r) z ≤ -currentExponent (Real.log r) y := by + filter_upwards [costKernel_exponent_nonincreasing (Real.log r) z] with y hy + exact neg_le_neg hy + filter_upwards [rawEvenHit_ae_geometric hr hb0 hb1 a h0, + rawEvenHit_scalarIncreasing (fun z => -currentExponent (Real.log r) z) hF hStep a + (Real.log (r/b1)) (Real.log (b1/(10*b0))) h0] with z hG hI + obtain ⟨tau,_ht0,_ht1,hFirst,_hg0,_hg1,_hx0,_hx1,hx2,_hx3,_hgap,_hratio⟩ := hG + have hX : 2*b0 ≤ currentExponent (Real.log r) (recordFirst (rawEvenHitRecord a z)) := by + rw [record_currentExponent hr hFirst] + exact hx2 + have hR := rawEvenFinalCycle_record a z + rw [hR] at hX + rcases he : rawEvenFinalCycle a z with ⟨t,n,h⟩ + rw [he] at hI hX + change ∀ i j : Finset.Iic (t+2*(n+1)), a ≤ i.1 → i.1 ≤ j.1 → + -currentExponent (Real.log r) (h i) ≤ -currentExponent (Real.log r) (h j) at hI + change 2*b0 ≤ currentExponent (Real.log r) (h ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩) at hX + change ∀ j : Finset.Iic (t+2*(n+1)), a ≤ j.1 → j.1 ≤ t+1 → h j ∈ arrivalSet (Real.log r) ell + intro j haj hj + have hle := hI j ⟨t+1,Finset.mem_Iic.mpr (by omega)⟩ haj hj + change ell < currentExponent (Real.log r) (h j) + linarith + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures + +local instance : MeasurableSingletonClass State := by + constructor + intro x + cases x with + | inl e => simpa only [image_singleton] using ((measurableSet_singleton e).inl_image : MeasurableSet (Sum.inl '' {e} : Set State)) + | inr o => simpa only [image_singleton] using ((measurableSet_singleton o).inr_image : MeasurableSet (Sum.inr '' {o} : Set State)) + +noncomputable def suppliedPastEvent (a : ℕ) (past : RawHistory a) (b : ℕ) : Set (RawHistory b) := + {h | ∃ hab : a ≤ b, rawPrefix hab h=past} + +lemma suppliedPastEvent_measurable (a : ℕ) (past : RawHistory a) (b : ℕ) : + MeasurableSet (suppliedPastEvent a past b) := by + unfold suppliedPastEvent + simp only [ofPred_exists] + apply MeasurableSet.iUnion + intro hab + exact (rawPrefix_measurable hab) (measurableSet_singleton past) + +lemma suppliedPastEvent_self (a : ℕ) (past : RawHistory a) : past ∈ suppliedPastEvent a past a := + ⟨le_rfl,rfl⟩ + +lemma rawExtension_preserves_suppliedPast (a : ℕ) (past : RawHistory a) (b c : ℕ) + (hbc : b ≤ c) (h : RawHistory b) (hh : h ∈ suppliedPastEvent a past b) : + ∀ᵐ y ∂rawExtension b c h, y ∈ suppliedPastEvent a past c := by + obtain ⟨hab,hp⟩ := hh + filter_upwards [rawExtension_retains_prefix hbc h] with y hy + refine ⟨hab.trans hbc,?_⟩ + calc + rawPrefix (hab.trans hbc) y=rawPrefix hab (rawPrefix hbc y) := rfl + _=rawPrefix hab h := congrArg (rawPrefix hab) hy + _=past := hp + +theorem rawEvenHit_retains_suppliedPast (a : ℕ) (v H : ℝ) (past : RawHistory a) : + ∀ᵐ z ∂rawEvenMarkedHitKernel a v H past, + rawEvenFinalCycle a z ∈ selectedHistoryProperty (suppliedPastEvent a past) := by + exact rawEvenHit_historyProperty (suppliedPastEvent a past) (suppliedPastEvent_measurable a past) + (rawExtension_preserves_suppliedPast a past) a v H past (suppliedPastEvent_self a past) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RealCriticalPoints.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RealCriticalPoints.lean new file mode 100644 index 0000000000000000000000000000000000000000..381dcb1126640564031d9b2c7343041f192e3fcd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RealCriticalPoints.lean @@ -0,0 +1,418 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.PrimitiveResultant +import OAI.NumberTheory.Jacobsthal.Partitions.NonlinearCoordinateDegree + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosCriticalGeometry + +open ErdosBivariateResultant + +@[simp] theorem beval_nested (Q : MV ℂ) (x y : ℂ) : + beval (nestedY ℂ Q) x y = MvPolynomial.eval ![x,y] Q := eval_nestedY ℂ Q x y + +def intersectionPoints (Q G : MV ℂ) : Set (ℂ × ℂ) := + {p | MvPolynomial.eval ![p.1,p.2] Q = 0 ∧ MvPolynomial.eval ![p.1,p.2] G = 0} + +def intersectionAbscissae (Q G : MV ℂ) : Set ℂ := Prod.fst '' intersectionPoints Q G + +theorem intersectionPoints_eq_nested (Q G : MV ℂ) : + intersectionPoints Q G = commonZeroSet (nestedY ℂ Q) (nestedY ℂ G) := by + ext p + simp only [intersectionPoints, commonZeroSet, Set.mem_ofPred_eq, beval_nested] + +theorem nonlinear_fibers_nonzero (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + ∀ x : ℂ, specialize (nestedY ℂ Q) x ≠ 0 := by + have hi : Irreducible (nestedY ℂ Q) := (MulEquiv.irreducible_iff (nestedY ℂ).toMulEquiv).mpr hQ + exact primitive_specialize_ne_zero _ (hi.isPrimitive (nonlinear_nestedY_degree_pos Q hQ hdeg).ne') + +theorem nonlinear_resultant_nonzero (Q G : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (hnd : ¬Q ∣ G) : xResultant (nestedY ℂ Q) (nestedY ℂ G) ≠ 0 := by + have hi : Irreducible (nestedY ℂ Q) := (MulEquiv.irreducible_iff (nestedY ℂ).toMulEquiv).mpr hQ + apply irreducible_resultant_ne_zero _ _ hi (nonlinear_nestedY_degree_pos Q hQ hdeg).ne' + rintro ⟨H,hH⟩ + apply hnd + refine ⟨(nestedY ℂ).symm H, ?_⟩ + apply (nestedY ℂ).injective + simpa only [map_mul, AlgEquiv.apply_symm_apply] using hH + +theorem mv_resultant_degree_le (Q G : MV ℂ) : + (xResultant (nestedY ℂ Q) (nestedY ℂ G)).natDegree ≤ 2*Q.totalDegree*G.totalDegree := by + have h := resultant_degree_from_coefficients (nestedY ℂ Q) (nestedY ℂ G) + (nestedY ℂ Q).natDegree (nestedY ℂ G).natDegree Q.totalDegree G.totalDegree + (nestedY_coefficient_degree_le ℂ Q) (nestedY_coefficient_degree_le ℂ G) + change (xResultant (nestedY ℂ Q) (nestedY ℂ G)).natDegree ≤ _ at h + calc + _ ≤ _ := h + _ ≤ Q.totalDegree*G.totalDegree+G.totalDegree*Q.totalDegree := Nat.add_le_add + (Nat.mul_le_mul_right _ (nestedY_degree_le ℂ Q)) + (Nat.mul_le_mul_right _ (nestedY_degree_le ℂ G)) + _ = _ := by ring + +theorem irreducible_intersection_bound (Q G : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (hnd : ¬Q ∣ G) : + (intersectionPoints Q G).Finite ∧ + (intersectionPoints Q G).ncard ≤ 2*Q.totalDegree^2*G.totalDegree := by + rw [intersectionPoints_eq_nested] + obtain ⟨hfin,hcard⟩ := common_zero_finite_count (nestedY ℂ Q) (nestedY ℂ G) + (nonlinear_resultant_nonzero Q G hQ hdeg hnd) (nonlinear_fibers_nonzero Q hQ hdeg) + refine ⟨hfin, hcard.trans ?_⟩ + calc + _ ≤ (2*Q.totalDegree*G.totalDegree)*Q.totalDegree := + Nat.mul_le_mul (mv_resultant_degree_le Q G) (nestedY_degree_le ℂ Q) + _ = _ := by ring + +theorem irreducible_abscissa_bound (Q G : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (hnd : ¬Q ∣ G) : + (intersectionAbscissae Q G).Finite ∧ + (intersectionAbscissae Q G).ncard ≤ 2*Q.totalDegree*G.totalDegree := by + have hR := nonlinear_resultant_nonzero Q G hQ hdeg hnd + have hF := nonlinear_fibers_nonzero Q hQ hdeg + have hsub : intersectionAbscissae Q G ⊆ + (resultantRoots (nestedY ℂ Q) (nestedY ℂ G) : Set ℂ) := by + rintro x ⟨p,hp,rfl⟩ + apply (mem_resultantRoots _ _ hR p.1).mpr + apply common_zero_resultant_zero_of_fiber _ _ p.1 p.2 (hF p.1) + · simpa only [beval_nested] using hp.1 + · simpa only [beval_nested] using hp.2 + have hfinite := (Finset.finite_toSet (resultantRoots (nestedY ℂ Q) (nestedY ℂ G))).subset hsub + refine ⟨hfinite, ?_⟩ + calc + _ ≤ (resultantRoots (nestedY ℂ Q) (nestedY ℂ G) : Set ℂ).ncard := + Set.ncard_le_ncard hsub (Finset.finite_toSet _) + _ = (resultantRoots (nestedY ℂ Q) (nestedY ℂ G)).card := Set.ncard_coe_finset _ + _ ≤ _ := (resultantRoots_card_le _ _).trans (mv_resultant_degree_le Q G) + +end ErdosCriticalGeometry + +end + +section + +namespace ErdosDivisibleInflection + +open ErdosCriticalGeometry + +noncomputable def affineLine (A B : ℂ) : MV ℂ := + MvPolynomial.X 1-(MvPolynomial.C A*MvPolynomial.X 0+MvPolynomial.C B) + +noncomputable def affineInner (A B : ℂ) : Polynomial ℂ := + Polynomial.C A*Polynomial.X+Polynomial.C B + +theorem nested_affineLine (A B : ℂ) : + nestedY ℂ (affineLine A B) = Polynomial.X-Polynomial.C (affineInner A B) := by + simp [affineLine,affineInner,map_sub,map_add,map_mul] + +theorem eval_affine_substitution (P : Nested ℂ) (A B x : ℂ) : + (P.eval (affineInner A B)).eval x = + ErdosBivariateResultant.beval P x (A*x+B) := by + have h := Polynomial.eval₂_at_apply (p := P) (Polynomial.evalRingHom x) (affineInner A B) + rw [← Polynomial.eval_map] at h + simpa [affineInner,ErdosBivariateResultant.beval_eq_specialize, + ErdosBivariateResultant.specialize] using h.symm + +theorem affine_interval_factor (Q : MV ℂ) (A B : ℂ) (a b : ℝ) (hab : a < b) + (hzero : ∀ t ∈ Set.Ioo a b, + MvPolynomial.eval ![(t : ℂ),A*(t : ℂ)+B] Q = 0) : affineLine A B ∣ Q := by + let P := nestedY ℂ Q + let R := P.eval (affineInner A B) + have hz (t : ℝ) (ht : t ∈ Set.Ioo a b) : R.eval (t : ℂ) = 0 := by + rw [show R = P.eval (affineInner A B) from rfl, eval_affine_substitution] + exact (beval_nested Q (t : ℂ) (A*(t : ℂ)+B)).trans (hzero t ht) + have hR : R = 0 := by + apply Polynomial.eq_zero_of_infinite_isRoot + apply ((Set.Ioo_infinite hab).image Complex.ofReal_injective.injOn).mono + rintro z ⟨t,ht,rfl⟩ + exact hz t ht + have hdiv : Polynomial.X-Polynomial.C (affineInner A B) ∣ P := Polynomial.dvd_iff_isRoot.mpr hR + obtain ⟨H,hH⟩ := hdiv + refine ⟨(nestedY ℂ).symm H, ?_⟩ + apply (nestedY ℂ).injective + simpa only [map_mul,AlgEquiv.apply_symm_apply,nested_affineLine] using hH + +theorem affineLine_not_unit (A B : ℂ) : ¬IsUnit (affineLine A B) := by + intro h + have hmap := h.map (nestedY ℂ).toRingHom + change IsUnit (nestedY ℂ (affineLine A B)) at hmap + rw [nested_affineLine] at hmap + exact Polynomial.not_isUnit_X_sub_C _ hmap + +theorem affineLine_degree_le (A B : ℂ) : (affineLine A B).totalDegree ≤ 1 := by + have he : affineLine A B = MvPolynomial.X 1 + + MvPolynomial.C (-A)*MvPolynomial.X 0+MvPolynomial.C (-B) := by + simp only [affineLine,map_neg] + ring + rw [he] + apply (MvPolynomial.totalDegree_add _ _).trans + apply max_le + · apply (MvPolynomial.totalDegree_add _ _).trans + apply max_le + · simp + · exact (MvPolynomial.totalDegree_mul _ _).trans (by simp) + · simp + +theorem no_affine_interval (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) + (A B : ℂ) (a b : ℝ) (hab : a < b) + (hzero : ∀ t ∈ Set.Ioo a b, + MvPolynomial.eval ![(t : ℂ),A*(t : ℂ)+B] Q = 0) : False := by + obtain ⟨H,hH⟩ := affine_interval_factor Q A B a b hab hzero + have hunit : IsUnit H := (hQ.2 hH).resolve_left (affineLine_not_unit A B) + have hD : H.totalDegree = 0 := (MvPolynomial.isUnit_iff_totalDegree_of_isReduced.mp hunit).2 + have hle : Q.totalDegree ≤ 1 := by + rw [hH] + exact (MvPolynomial.totalDegree_mul _ _).trans (by rw [hD,add_zero]; exact affineLine_degree_le A B) + omega + +end ErdosDivisibleInflection + +end + +section + +namespace ErdosCriticalGeometry + +def criticalPoints (Q : MV ℂ) : Set (ℂ × ℂ) := + intersectionPoints Q (MvPolynomial.pderiv 0 Q) ∪ intersectionPoints Q (MvPolynomial.pderiv 1 Q) + +def criticalAbscissae (Q : MV ℂ) : Set ℂ := Prod.fst '' criticalPoints Q + +theorem mem_criticalPoints (Q : MV ℂ) (p : ℂ × ℂ) : p ∈ criticalPoints Q ↔ + MvPolynomial.eval ![p.1,p.2] Q = 0 ∧ + (MvPolynomial.eval ![p.1,p.2] (MvPolynomial.pderiv 0 Q) = 0 ∨ + MvPolynomial.eval ![p.1,p.2] (MvPolynomial.pderiv 1 Q) = 0) := by + constructor + · rintro (h | h) + · exact ⟨h.1, Or.inl h.2⟩ + · exact ⟨h.1, Or.inr h.2⟩ + · rintro ⟨h, h' | h'⟩ + · exact Or.inl ⟨h,h'⟩ + · exact Or.inr ⟨h,h'⟩ + +theorem partial_intersection_bound (Q : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (i : Fin 2) : + (intersectionPoints Q (MvPolynomial.pderiv i Q)).Finite ∧ + (intersectionPoints Q (MvPolynomial.pderiv i Q)).ncard ≤ 2*Q.totalDegree^3 := by + obtain ⟨hfin,hcard⟩ := irreducible_intersection_bound Q (MvPolynomial.pderiv i Q) + hQ hdeg (nonlinear_partial_not_dvd Q hQ hdeg i) + refine ⟨hfin,hcard.trans ?_⟩ + calc + _ ≤ (2*Q.totalDegree^2)*Q.totalDegree := Nat.mul_le_mul_left _ + ((partial_totalDegree_le ℂ Q i).trans (Nat.sub_le _ _)) + _ = _ := by ring + +theorem partial_abscissa_bound (Q : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (i : Fin 2) : + (intersectionAbscissae Q (MvPolynomial.pderiv i Q)).Finite ∧ + (intersectionAbscissae Q (MvPolynomial.pderiv i Q)).ncard ≤ 2*Q.totalDegree^2 := by + obtain ⟨hfin,hcard⟩ := irreducible_abscissa_bound Q (MvPolynomial.pderiv i Q) + hQ hdeg (nonlinear_partial_not_dvd Q hQ hdeg i) + refine ⟨hfin,hcard.trans ?_⟩ + calc + _ ≤ (2*Q.totalDegree)*Q.totalDegree := Nat.mul_le_mul_left _ + ((partial_totalDegree_le ℂ Q i).trans (Nat.sub_le _ _)) + _ = _ := by ring + +theorem critical_points_bound (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + (criticalPoints Q).Finite ∧ (criticalPoints Q).ncard ≤ 4*Q.totalDegree^3 := by + obtain ⟨h0,c0⟩ := partial_intersection_bound Q hQ hdeg 0 + obtain ⟨h1,c1⟩ := partial_intersection_bound Q hQ hdeg 1 + refine ⟨h0.union h1, ?_⟩ + have h := Set.ncard_union_le (intersectionPoints Q (MvPolynomial.pderiv 0 Q)) + (intersectionPoints Q (MvPolynomial.pderiv 1 Q)) + change (criticalPoints Q).ncard ≤ _ at h + omega + +theorem critical_abscissae_bound (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + (criticalAbscissae Q).Finite ∧ (criticalAbscissae Q).ncard ≤ 4*Q.totalDegree^2 := by + obtain ⟨h0,c0⟩ := partial_abscissa_bound Q hQ hdeg 0 + obtain ⟨h1,c1⟩ := partial_abscissa_bound Q hQ hdeg 1 + have he : criticalAbscissae Q = intersectionAbscissae Q (MvPolynomial.pderiv 0 Q) ∪ + intersectionAbscissae Q (MvPolynomial.pderiv 1 Q) := Set.image_union _ _ _ + rw [he] + refine ⟨h0.union h1, ?_⟩ + have h := Set.ncard_union_le (intersectionAbscissae Q (MvPolynomial.pderiv 0 Q)) + (intersectionAbscissae Q (MvPolynomial.pderiv 1 Q)) + omega + +end ErdosCriticalGeometry + +end + +section + +namespace ErdosCriticalGeometry + +noncomputable def inflection (Q : MV ℂ) : MV ℂ := + MvPolynomial.pderiv 0 (MvPolynomial.pderiv 0 Q)*(MvPolynomial.pderiv 1 Q)^2 + + MvPolynomial.C (-2 : ℂ)*MvPolynomial.pderiv 0 (MvPolynomial.pderiv 1 Q)* + MvPolynomial.pderiv 0 Q*MvPolynomial.pderiv 1 Q + + MvPolynomial.pderiv 1 (MvPolynomial.pderiv 1 Q)*(MvPolynomial.pderiv 0 Q)^2 + +theorem inflection_degree_le (Q : MV ℂ) : (inflection Q).totalDegree ≤ 3*Q.totalDegree := by + have h1 (i : Fin 2) : (MvPolynomial.pderiv i Q).totalDegree ≤ Q.totalDegree := + (partial_totalDegree_le ℂ Q i).trans (Nat.sub_le _ _) + have h2 (i j : Fin 2) : (MvPolynomial.pderiv i (MvPolynomial.pderiv j Q)).totalDegree ≤ Q.totalDegree := + ((partial_totalDegree_le ℂ _ i).trans (Nat.sub_le _ _)).trans (h1 j) + have hp (i : Fin 2) : ((MvPolynomial.pderiv i Q)^2).totalDegree ≤ 2*Q.totalDegree := + (MvPolynomial.totalDegree_pow _ _).trans (Nat.mul_le_mul_left _ (h1 i)) + have ha : (MvPolynomial.pderiv 0 (MvPolynomial.pderiv 0 Q)*(MvPolynomial.pderiv 1 Q)^2).totalDegree ≤ + 3*Q.totalDegree := (MvPolynomial.totalDegree_mul _ _).trans (by linarith [h2 0 0,hp 1]) + have hb : (MvPolynomial.C (-2 : ℂ)*MvPolynomial.pderiv 0 (MvPolynomial.pderiv 1 Q)* + MvPolynomial.pderiv 0 Q*MvPolynomial.pderiv 1 Q).totalDegree ≤ 3*Q.totalDegree := by + have hA := MvPolynomial.totalDegree_mul (MvPolynomial.C (-2 : ℂ)) (MvPolynomial.pderiv 0 (MvPolynomial.pderiv 1 Q)) + have hB := MvPolynomial.totalDegree_mul (MvPolynomial.C (-2 : ℂ)*MvPolynomial.pderiv 0 (MvPolynomial.pderiv 1 Q)) (MvPolynomial.pderiv 0 Q) + have hC := MvPolynomial.totalDegree_mul (MvPolynomial.C (-2 : ℂ)*MvPolynomial.pderiv 0 (MvPolynomial.pderiv 1 Q)*MvPolynomial.pderiv 0 Q) (MvPolynomial.pderiv 1 Q) + simp only [MvPolynomial.totalDegree_C, zero_add] at hA + linarith [h2 0 1,h1 0,h1 1] + have hc : (MvPolynomial.pderiv 1 (MvPolynomial.pderiv 1 Q)*(MvPolynomial.pderiv 0 Q)^2).totalDegree ≤ + 3*Q.totalDegree := (MvPolynomial.totalDegree_mul _ _).trans (by linarith [h2 1 1,hp 0]) + unfold inflection + exact (MvPolynomial.totalDegree_add _ _).trans + (max_le ((MvPolynomial.totalDegree_add _ _).trans (max_le ha hb)) hc) + +theorem inflection_intersection_bounds (Q : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (hnd : ¬Q ∣ inflection Q) : + (intersectionPoints Q (inflection Q)).Finite ∧ + (intersectionPoints Q (inflection Q)).ncard ≤ 6*Q.totalDegree^3 ∧ + (intersectionAbscissae Q (inflection Q)).Finite ∧ + (intersectionAbscissae Q (inflection Q)).ncard ≤ 6*Q.totalDegree^2 := by + obtain ⟨hp,cp⟩ := irreducible_intersection_bound Q (inflection Q) hQ hdeg hnd + obtain ⟨ha,ca⟩ := irreducible_abscissa_bound Q (inflection Q) hQ hdeg hnd + refine ⟨hp,cp.trans ?_,ha,ca.trans ?_⟩ + · calc + _ ≤ (2*Q.totalDegree^2)*(3*Q.totalDegree) := Nat.mul_le_mul_left _ (inflection_degree_le Q) + _ = _ := by ring + · calc + _ ≤ (2*Q.totalDegree)*(3*Q.totalDegree) := Nat.mul_le_mul_left _ (inflection_degree_le Q) + _ = _ := by ring + +theorem inflection_zero_divisible (Q : MV ℂ) (h : inflection Q = 0) : Q ∣ inflection Q := by + rw [h] + exact dvd_zero Q + +theorem inflection_alternative (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + Q ∣ inflection Q ∨ + ((intersectionPoints Q (inflection Q)).Finite ∧ + (intersectionPoints Q (inflection Q)).ncard ≤ 6*Q.totalDegree^3 ∧ + (intersectionAbscissae Q (inflection Q)).Finite ∧ + (intersectionAbscissae Q (inflection Q)).ncard ≤ 6*Q.totalDegree^2) := by + by_cases h : Q ∣ inflection Q + · exact Or.inl h + · exact Or.inr (inflection_intersection_bounds Q hQ hdeg h) + +def exceptionalPoints (Q : MV ℂ) : Set (ℂ × ℂ) := criticalPoints Q ∪ intersectionPoints Q (inflection Q) + +def exceptionalAbscissae (Q : MV ℂ) : Set ℂ := Prod.fst '' exceptionalPoints Q + +theorem exceptional_points_bound (Q : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (hnd : ¬Q ∣ inflection Q) : + (exceptionalPoints Q).Finite ∧ (exceptionalPoints Q).ncard ≤ 10*Q.totalDegree^3 := by + obtain ⟨hc,cc⟩ := critical_points_bound Q hQ hdeg + obtain ⟨hi,ci,_,_⟩ := inflection_intersection_bounds Q hQ hdeg hnd + refine ⟨hc.union hi, ?_⟩ + have h := Set.ncard_union_le (criticalPoints Q) (intersectionPoints Q (inflection Q)) + change (exceptionalPoints Q).ncard ≤ _ at h + omega + +theorem exceptional_abscissae_bound (Q : MV ℂ) (hQ : Irreducible Q) + (hdeg : 1 < Q.totalDegree) (hnd : ¬Q ∣ inflection Q) : + (exceptionalAbscissae Q).Finite ∧ (exceptionalAbscissae Q).ncard ≤ 10*Q.totalDegree^2 := by + obtain ⟨hc,cc⟩ := critical_abscissae_bound Q hQ hdeg + obtain ⟨_,_,hi,ci⟩ := inflection_intersection_bounds Q hQ hdeg hnd + have he : exceptionalAbscissae Q = criticalAbscissae Q ∪ intersectionAbscissae Q (inflection Q) := + Set.image_union _ _ _ + rw [he] + refine ⟨hc.union hi, ?_⟩ + have h := Set.ncard_union_le (criticalAbscissae Q) (intersectionAbscissae Q (inflection Q)) + omega + +end ErdosCriticalGeometry + +end + +section + +namespace ErdosCriticalGeometry + +noncomputable def complexify (Q : MV ℝ) : MV ℂ := MvPolynomial.map (algebraMap ℝ ℂ) Q + +theorem complexify_totalDegree (Q : MV ℝ) : (complexify Q).totalDegree = Q.totalDegree := by + unfold complexify MvPolynomial.totalDegree + rw [MvPolynomial.support_map_of_injective Q (show Function.Injective (algebraMap ℝ ℂ) from + Complex.ofReal_injective)] + +theorem complexify_partial (Q : MV ℝ) (i : Fin 2) : + complexify (MvPolynomial.pderiv i Q) = MvPolynomial.pderiv i (complexify Q) := + MvPolynomial.pderiv_map.symm + +theorem complexify_eval (Q : MV ℝ) (x y : ℝ) : + MvPolynomial.eval ![(x : ℂ),(y : ℂ)] (complexify Q) = (MvPolynomial.eval ![x,y] Q : ℂ) := by + have he : (algebraMap ℝ ℂ) ∘ (![x,y] : Fin 2 → ℝ) = ![(x : ℂ),(y : ℂ)] := by + funext i + fin_cases i <;> rfl + have h := MvPolynomial.map_eval (algebraMap ℝ ℂ) ![x,y] Q + rw [he] at h + exact h.symm + +def realCriticalPoints (Q : MV ℝ) : Set (ℝ × ℝ) := + {p | MvPolynomial.eval ![p.1,p.2] Q = 0 ∧ + (MvPolynomial.eval ![p.1,p.2] (MvPolynomial.pderiv 0 Q) = 0 ∨ + MvPolynomial.eval ![p.1,p.2] (MvPolynomial.pderiv 1 Q) = 0)} + +def realCriticalAbscissae (Q : MV ℝ) : Set ℝ := Prod.fst '' realCriticalPoints Q + +def complexPoint (p : ℝ × ℝ) : ℂ × ℂ := ((p.1 : ℂ),(p.2 : ℂ)) + +theorem complexPoint_injective : Function.Injective complexPoint := by + intro p q h + apply Prod.ext + · exact Complex.ofReal_injective (congrArg Prod.fst h) + · exact Complex.ofReal_injective (congrArg Prod.snd h) + +theorem real_critical_iff (Q : MV ℝ) (p : ℝ × ℝ) : + complexPoint p ∈ criticalPoints (complexify Q) ↔ p ∈ realCriticalPoints Q := by + rw [mem_criticalPoints] + simp only [complexPoint, realCriticalPoints, Set.mem_ofPred_eq, ← complexify_partial, + complexify_eval, Complex.ofReal_eq_zero] + +theorem real_critical_points_bound (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) : + (realCriticalPoints Q).Finite ∧ (realCriticalPoints Q).ncard ≤ 4*Q.totalDegree^3 := by + have hd : 1 < (complexify Q).totalDegree := by rwa [complexify_totalDegree] + obtain ⟨hfin,hcard⟩ := critical_points_bound (complexify Q) hQ hd + have he : realCriticalPoints Q = complexPoint ⁻¹' criticalPoints (complexify Q) := by + ext p + exact (real_critical_iff Q p).symm + have hrfin : (realCriticalPoints Q).Finite := by + rw [he] + exact hfin.preimage (fun _ _ _ _ h => complexPoint_injective h) + refine ⟨hrfin, ?_⟩ + have hle := Set.ncard_le_ncard_of_injOn complexPoint + (fun p hp => (real_critical_iff Q p).mpr hp) complexPoint_injective.injOn hfin + apply hle.trans + simpa only [complexify_totalDegree] using hcard + +theorem real_critical_abscissae_bound (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) : + (realCriticalAbscissae Q).Finite ∧ (realCriticalAbscissae Q).ncard ≤ 4*Q.totalDegree^2 := by + have hd : 1 < (complexify Q).totalDegree := by rwa [complexify_totalDegree] + obtain ⟨hfin,hcard⟩ := critical_abscissae_bound (complexify Q) hQ hd + have hrfin := (real_critical_points_bound Q hQ hdeg).1.image Prod.fst + refine ⟨hrfin, ?_⟩ + have hmap : ∀ x ∈ realCriticalAbscissae Q, (x : ℂ) ∈ criticalAbscissae (complexify Q) := by + rintro x ⟨p,hp,he⟩ + exact ⟨complexPoint p,(real_critical_iff Q p).mpr hp,congrArg Complex.ofReal he⟩ + have hle := Set.ncard_le_ncard_of_injOn Complex.ofReal hmap Complex.ofReal_injective.injOn hfin + apply hle.trans + simpa only [complexify_totalDegree] using hcard + +end ErdosCriticalGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RealProgressionPoints.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RealProgressionPoints.lean new file mode 100644 index 0000000000000000000000000000000000000000..095b822d3803940264dd259ac2d80c116af1eb7c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RealProgressionPoints.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.IntervalCuts + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHyperbolaFourier + +def progressionPoint (a : ℤ) (T : ℕ) (j : ℤ) : ℤ := a + (T : ℤ)*j + +noncomputable def lowerIndex (x : ℝ) (T : ℕ) (a : ℤ) (closed : Bool) : ℤ := + lowerCut ((x-a)/T) closed + +noncomputable def upperIndex (y : ℝ) (T : ℕ) (a : ℤ) (closed : Bool) : ℤ := + upperCut ((y-a)/T) closed + +noncomputable def progressionPoints (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) : Finset ℤ := + (Finset.Ico (lowerIndex x T a lc) (upperIndex y T a rc)).image (progressionPoint a T) + +theorem progressionPoint_injective (a : ℤ) (T : ℕ) (hT : 0 < T) : + Function.Injective (progressionPoint a T) := by + intro i j hij + have hT0 : (T : ℤ) ≠ 0 := by exact_mod_cast hT.ne' + exact mul_left_cancel₀ hT0 (add_left_cancel hij) + +theorem progressionPoint_modEq (a : ℤ) (T : ℕ) (j : ℤ) : + Int.ModEq (T : ℤ) (progressionPoint a T j) a := by + apply Int.modEq_iff_dvd.mpr + exact ⟨-j, by dsimp [progressionPoint]; ring⟩ + +theorem index_mem_iff (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) (hT : 0 < T) (j : ℤ) : + j ∈ Finset.Ico (lowerIndex x T a lc) (upperIndex y T a rc) ↔ + (if lc then x ≤ (progressionPoint a T j : ℝ) else x < (progressionPoint a T j : ℝ)) ∧ + (if rc then (progressionPoint a T j : ℝ) ≤ y else (progressionPoint a T j : ℝ) < y) := by + have hTR : (0 : ℝ) < T := by exact_mod_cast hT + simp only [Finset.mem_Ico, lowerIndex, upperIndex, lowerCut_le_iff, lt_upperCut_iff] + cases lc <;> cases rc <;> + simp only [Bool.false_eq_true, ite_false, ite_true, div_le_iff₀ hTR, div_lt_iff₀ hTR, + le_div_iff₀ hTR, lt_div_iff₀ hTR, progressionPoint, Int.cast_add, Int.cast_mul, + Int.cast_natCast] <;> + constructor <;> rintro ⟨hlo, hhi⟩ <;> constructor <;> nlinarith + +theorem mem_progressionPoints_iff (x y : ℝ) (lc rc : Bool) (T : ℕ) (a z : ℤ) (hT : 0 < T) : + z ∈ progressionPoints x y lc rc T a ↔ + (if lc then x ≤ (z : ℝ) else x < (z : ℝ)) ∧ + (if rc then (z : ℝ) ≤ y else (z : ℝ) < y) ∧ Int.ModEq (T : ℤ) z a := by + constructor + · intro hz + obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hz + obtain ⟨hlo, hhi⟩ := (index_mem_iff x y lc rc T a hT j).mp hj + exact ⟨hlo, hhi, progressionPoint_modEq a T j⟩ + · rintro ⟨hlo, hhi, hmod⟩ + obtain ⟨j, hj⟩ := Int.modEq_iff_dvd.mp hmod.symm + have he : progressionPoint a T j = z := by dsimp [progressionPoint]; linarith + apply Finset.mem_image.mpr + refine ⟨j, ?_, he⟩ + apply (index_mem_iff x y lc rc T a hT j).mpr + rw [he] + exact ⟨hlo, hhi⟩ + +theorem progressionPoints_card (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) (hT : 0 < T) : + (progressionPoints x y lc rc T a).card = + (upperIndex y T a rc-lowerIndex x T a lc).toNat := by + unfold progressionPoints + rw [Finset.card_image_of_injective _ (progressionPoint_injective a T hT), Int.card_Ico] + +theorem progressionPoints_count_error (x y : ℝ) (hxy : x ≤ y) (lc rc : Bool) + (T : ℕ) (a : ℤ) (hT : 0 < T) : + |((progressionPoints x y lc rc T a).card : ℝ) - (y-x)/(T : ℝ)| ≤ 1 := by + have hTR : (0 : ℝ) < T := by exact_mod_cast hT + have hlohi : (x-a)/(T : ℝ) ≤ (y-a)/(T : ℝ) := + div_le_div_of_nonneg_right (sub_le_sub_right hxy _) hTR.le + have h := cut_count_error ((x-a)/(T : ℝ)) ((y-a)/(T : ℝ)) hlohi lc rc + rw [show (y-a)/(T : ℝ)-(x-a)/(T : ℝ) = (y-x)/(T : ℝ) by ring] at h + rw [progressionPoints_card x y lc rc T a hT] + exact h + +end ErdosHyperbolaFourier + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReciprocalEnvelope.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReciprocalEnvelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c233180c4b2aa0d5b01844538c71e12d85d3eef --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReciprocalEnvelope.lean @@ -0,0 +1,160 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosVarianceSmallModel + +noncomputable def interceptScale (R C0 : ℝ) : ℝ := |C0|/R +noncomputable def totalScale (R H C0 : ℝ) : ℝ := max H (interceptScale R C0) + +noncomputable def primeWidth (R xi H C0 : ℝ) : ℝ := + min (xi*R) (R*H/totalScale R H C0) + +noncomputable def modelLength (R xi H C0 : ℝ) : ℝ := H+xi*interceptScale R C0 + +theorem totalScale_pos (R H C0 : ℝ) (hH : 0 < H) : 0 < totalScale R H C0 := + hH.trans_le (le_max_left _ _) + +theorem primeWidth_pos (R xi H C0 : ℝ) (hR : 0 < R) (hxi : 0 < xi) (hH : 0 < H) : + 0 < primeWidth R xi H C0 := + lt_min (mul_pos hxi hR) (div_pos (mul_pos hR hH) (totalScale_pos R H C0 hH)) + +theorem primeWidth_caps (R xi H C0 : ℝ) : + primeWidth R xi H C0 ≤ xi*R ∧ primeWidth R xi H C0 ≤ R*H/totalScale R H C0 := + ⟨min_le_left _ _,min_le_right _ _⟩ + +theorem modelLength_bounds (R xi H C0 : ℝ) (hR : 0 < R) (hxi : 0 ≤ xi) + (hxi1 : xi ≤ 1) (hH : 0 < H) : + H ≤ modelLength R xi H C0 ∧ xi*totalScale R H C0 ≤ modelLength R xi H C0 := by + have hc : 0 ≤ interceptScale R C0 := div_nonneg (abs_nonneg _) hR.le + have hxiH := mul_le_mul_of_nonneg_right hxi1 hH.le + constructor + · dsimp [modelLength] + nlinarith [mul_nonneg hxi hc] + · rcases le_total H (interceptScale R C0) with h | h + · rw [totalScale,max_eq_right h] + dsimp [modelLength] + linarith + · rw [totalScale,max_eq_left h] + dsimp [modelLength] + nlinarith + +theorem small_model_area (R xi H C0 : ℝ) (hR : 0 < R) (hxi : 0 < xi) (hH : 0 < H) : + primeWidth R xi H C0*modelLength R xi H C0 ≤ 2*xi*R*H := by + have hT := totalScale_pos R H C0 hH + have hc : 0 ≤ interceptScale R C0 := div_nonneg (abs_nonneg _) hR.le + have hcT : interceptScale R C0 ≤ totalScale R H C0 := le_max_right _ _ + have hw0 := primeWidth_pos R xi H C0 hR hxi hH + have hcap := primeWidth_caps R xi H C0 + have hfirst := mul_le_mul_of_nonneg_right hcap.1 hH.le + have hsecond : primeWidth R xi H C0*interceptScale R C0 ≤ R*H := by + have hmul := (le_div_iff₀ hT).mp hcap.2 + have hmono := mul_le_mul_of_nonneg_left hcT hw0.le + linarith + have hsecond' := mul_le_mul_of_nonneg_left hsecond hxi.le + dsimp [modelLength] + nlinarith + +theorem primeWidth_lower (R xi H C0 : ℝ) (hR : 0 < R) (hxi : 0 < xi) + (hxi1 : xi ≤ 1) (hH : 0 < H) : + xi*R*H/totalScale R H C0 ≤ primeWidth R xi H C0 := by + have hT := totalScale_pos R H C0 hH + have hHT : H ≤ totalScale R H C0 := le_max_left _ _ + apply le_min + · apply (div_le_iff₀ hT).mpr + have hh := mul_le_mul_of_nonneg_left hHT (mul_pos hxi hR).le + nlinarith + · apply div_le_div_of_nonneg_right _ hT.le + have hh := mul_le_mul_of_nonneg_right hxi1 (mul_pos hR hH).le + nlinarith + +theorem primeWidth_zero_intercept (R xi H : ℝ) (hR : 0 < R) (hxi1 : xi ≤ 1) (hH : 0 < H) : + primeWidth R xi H 0 = xi*R := by + have ht : totalScale R H 0 = H := by + simp only [totalScale,interceptScale,abs_zero,zero_div,max_eq_left hH.le] + rw [primeWidth,ht,mul_div_cancel_right₀ _ hH.ne'] + exact min_eq_left (by nlinarith) + +theorem primeWidth_nonzero_intercept (R xi H C0 : ℝ) (hR : 0 < R) (hxi1 : xi ≤ 1) + (hH : 0 < H) (hC : C0 ≠ 0) : + primeWidth R xi H C0 = min (xi*R) (R^2*H/|C0|) := by + have hc : 0 < interceptScale R C0 := div_pos (abs_pos.mpr hC) hR + have he : R*H/interceptScale R C0 = R^2*H/|C0| := by + dsimp [interceptScale] + field_simp + rcases le_total H (interceptScale R C0) with h | h + · rw [primeWidth,totalScale,max_eq_right h,he] + · have hRH : R ≤ R*H/interceptScale R C0 := (le_div_iff₀ hc).mpr (by nlinarith) + have hxiR : xi*R ≤ R := by nlinarith + rw [primeWidth,totalScale,max_eq_left h,mul_div_cancel_right₀ _ hH.ne',min_eq_left hxiR] + exact (min_eq_left (hxiR.trans (hRH.trans_eq he))).symm + +end ErdosVarianceSmallModel + +end + +section + +namespace ErdosVarianceSmallModel + +noncomputable def modelLeft (R xi C0 : ℝ) : ℝ := min (C0/R) (C0/((1+xi)*R)) +noncomputable def modelRight (R xi H C0 : ℝ) : ℝ := modelLeft R xi C0+modelLength R xi H C0 + +theorem reciprocal_bin_range (R xi C0 p : ℝ) (hR : 0 < R) (_hxi : 0 ≤ xi) + (hp : R < p) (hpU : p ≤ (1+xi)*R) : + min (C0/R) (C0/((1+xi)*R)) ≤ C0/p ∧ C0/p ≤ max (C0/R) (C0/((1+xi)*R)) := by + have hpp : 0 < p := hR.trans hp + have hu : 1/((1+xi)*R) ≤ 1/p := one_div_le_one_div_of_le hpp hpU + have hl : 1/p ≤ 1/R := one_div_le_one_div_of_le hR hp.le + rcases le_total 0 C0 with hC | hC + · have h1 : C0/((1+xi)*R) ≤ C0/p := by simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hu hC + have h2 : C0/p ≤ C0/R := by simpa only [mul_one_div] using mul_le_mul_of_nonneg_left hl hC + exact ⟨(min_le_right _ _).trans h1,h2.trans (le_max_left _ _)⟩ + · have h1 : C0/p ≤ C0/((1+xi)*R) := by simpa only [mul_one_div] using mul_le_mul_of_nonpos_left hu hC + have h2 : C0/R ≤ C0/p := by simpa only [mul_one_div] using mul_le_mul_of_nonpos_left hl hC + exact ⟨(min_le_left _ _).trans h2,h1.trans (le_max_right _ _)⟩ + +theorem reciprocal_bin_spread (R xi C0 : ℝ) (hR : 0 < R) (hxi : 0 ≤ xi) : + |C0/R-C0/((1+xi)*R)| ≤ xi*interceptScale R C0 := by + have hden : 0 < (1+xi)*R := by positivity + have he : C0/R-C0/((1+xi)*R) = C0*xi/((1+xi)*R) := by field_simp;ring + rw [he,abs_div,abs_mul,abs_of_nonneg hxi,abs_of_pos hden] + calc + _ ≤ |C0| * xi/R := div_le_div_of_nonneg_left (mul_nonneg (abs_nonneg _) hxi) hR (by nlinarith) + _ = _ := by dsimp [interceptScale];ring + +theorem moving_interval_enclosure (R xi H C0 p m : ℝ) (hR : 0 < R) (hxi : 0 ≤ xi) + (hp : R < p) (hpU : p ≤ (1+xi)*R) (hm : C0/p ≤ m ∧ m < C0/p+H) : + modelLeft R xi C0 ≤ m ∧ m < modelRight R xi H C0 := by + have hr := reciprocal_bin_range R xi C0 p hR hxi hp hpU + have hs := reciprocal_bin_spread R xi C0 hR hxi + have hspread : max (C0/R) (C0/((1+xi)*R))-min (C0/R) (C0/((1+xi)*R)) ≤ xi*interceptScale R C0 := by + rw [max_sub_min_eq_abs] + simpa only [abs_sub_comm (C0/R) (C0/((1+xi)*R))] using hs + refine ⟨hr.1.trans hm.1,?_⟩ + dsimp only [modelRight,modelLeft,modelLength] + linarith [hm.2,hr.2] + +noncomputable def modelIntegers (R xi H C0 : ℝ) : Finset ℤ := + Finset.Ico ⌈modelLeft R xi C0⌉ ⌈modelRight R xi H C0⌉ + +theorem mem_modelIntegers (R xi H C0 : ℝ) (m : ℤ) : + m ∈ modelIntegers R xi H C0 ↔ modelLeft R xi C0 ≤ (m : ℝ) ∧ (m : ℝ) < modelRight R xi H C0 := by + simp only [modelIntegers,Finset.mem_Ico,Int.ceil_le,Int.lt_ceil] + +theorem moving_integer_mem (R xi H C0 p : ℝ) (m : ℤ) (hR : 0 < R) (hxi : 0 ≤ xi) + (hp : R < p) (hpU : p ≤ (1+xi)*R) (hm : C0/p ≤ (m : ℝ) ∧ (m : ℝ) < C0/p+H) : + m ∈ modelIntegers R xi H C0 := + (mem_modelIntegers R xi H C0 m).mpr (moving_interval_enclosure R xi H C0 p m hR hxi hp hpU hm) + +end ErdosVarianceSmallModel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RecoveryScale.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RecoveryScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..489ce476257c7d164257c2e5e718a31847d4b47e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RecoveryScale.lean @@ -0,0 +1,676 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.RieszMajorantIntegrals + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory _root_.Set _root_.Filter + +theorem exists_uniform_riesz_right_tails : + ∃ C : ℝ, 0 ≤ C ∧ ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), + chi ≠ 1 → ∀ X sigma T : ℝ, 0 < X → 1 < sigma → 0 < T → + ‖∫ t in Iic (-T), characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ + 4*((sigma-1)⁻¹+C)*X^sigma/T ∧ + ‖∫ t in Ici T, characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ + 4*((sigma-1)⁻¹+C)*X^sigma/T := by + obtain ⟨C,hC,hbound⟩ := uniform_log_derivative_right + refine ⟨C,hC,?_⟩ + intro q _ chi hchi X sigma T hX hs hT + let B : ℝ := (sigma-1)⁻¹+C + let D : ℝ := B*X^sigma + have hB : 0 ≤ B := by dsimp only [B]; positivity + have hD : 0 ≤ D := by dsimp only [D]; positivity + have hpoint (t:ℝ) : ‖characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ + D*((4:ℝ)/(1+t^2)) := by + have hre : ((sigma:ℂ)+(t:ℂ)*Complex.I).re = sigma := by simp + have hb : ‖logDeriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ B := by + simpa only [logDeriv_apply,hre,B] using + hbound q chi ((sigma:ℂ)+(t:ℂ)*Complex.I) (by simpa only [hre] using hs) + rw [norm_characterRieszIntegrand chi hX,hre] + calc + _ ≤ B*‖rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)‖*X^sigma := by gcongr + _ = D*‖rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ := by dsimp only [D]; ring + _ ≤ _ := mul_le_mul_of_nonneg_left (rieszKernel_norm_bound (by linarith) t) hD + have hf := integrable_characterRiesz_right chi hchi hs hX + have hg := rieszMajorant_integrable.const_mul D + have htail (S:Set ℝ) (hbudget : (∫ t in S, (4:ℝ)/(1+t^2)) ≤ 4/T) : + ‖∫ t in S, characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ + 4*((sigma-1)⁻¹+C)*X^sigma/T := by + calc + _ ≤ ∫ t in S, ‖characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ := + norm_integral_le_integral_norm _ + _ ≤ ∫ t in S, D*((4:ℝ)/(1+t^2)) := + integral_mono (μ := volume.restrict S) hf.norm.integrableOn hg.integrableOn hpoint + _ = D*(∫ t in S, (4:ℝ)/(1+t^2)) := integral_const_mul _ _ + _ ≤ D*(4/T) := mul_le_mul_of_nonneg_left hbudget hD + _ = _ := by dsimp only [D,B]; ring + exact ⟨htail (Iic (-T)) (rieszMajorant_lower_tail hT), + htail (Ici T) (rieszMajorant_upper_tail hT)⟩ + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Set _root_.Complex _root_.MeasureTheory +open scoped Interval + +lemma riesz_left_edge_bound {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + {X left right T C : ℝ} (hX : 0 < X) (hl : 1/2 ≤ left) (hlr : left ≤ right) + (hT : 0 ≤ T) (hC : 0 ≤ C) + (hb : ∀ s ∈ Icc left right ×ℂ Icc (-T) T, + ‖logDeriv (DirichletCharacter.LFunction chi) s‖ ≤ C*(modulusHeight q T)^3) + (hf : _root_.Erdos970.HolomorphicOn (characterRieszIntegrand chi X) (Icc left right ×ℂ Icc (-T) T)) : + ‖_root_.Erdos970.VIntegral (characterRieszIntegrand chi X) left (-T) T‖ ≤ + 4*Real.pi*C*(modulusHeight q T)^3*X^left := by + let B : ℝ := C*(modulusHeight q T)^3*X^left + have hH := modulusHeight_ge_one q T + have hB : 0 ≤ B := by dsimp only [B]; positivity + have hTT : -T ≤ T := by linarith + have hmaps : MapsTo (fun t:ℝ => (left:ℂ)+(t:ℂ)*Complex.I) (Icc (-T) T) + (Icc left right ×ℂ Icc (-T) T) := by + intro t ht + simp only [Complex.mem_reProdIm,show ((left:ℂ)+(t:ℂ)*Complex.I).re = left by simp, + show ((left:ℂ)+(t:ℂ)*Complex.I).im = t by simp] + exact ⟨⟨le_rfl,hlr⟩,ht⟩ + have hc : ContinuousOn (fun t:ℝ => characterRieszIntegrand chi X ((left:ℂ)+(t:ℂ)*Complex.I)) + (Icc (-T) T) := hf.continuousOn.comp (by fun_prop) hmaps + have hfi : IntervalIntegrable (fun t:ℝ => characterRieszIntegrand chi X ((left:ℂ)+(t:ℂ)*Complex.I)) + volume (-T) T := (show ContinuousOn _ (uIcc (-T) T) by simpa only [uIcc_of_le hTT] using hc).intervalIntegrable + have hg := (rieszMajorant_integrable.const_mul B).intervalIntegrable (a := -T) (b := T) + have hpoint : ∀ t ∈ Icc (-T) T, + ‖characterRieszIntegrand chi X ((left:ℂ)+(t:ℂ)*Complex.I)‖ ≤ B*((4:ℝ)/(1+t^2)) := by + intro t ht + have hlog := hb _ (hmaps ht) + rw [norm_characterRieszIntegrand chi hX,show ((left:ℂ)+(t:ℂ)*Complex.I).re = left by simp] + calc + _ ≤ (C*(modulusHeight q T)^3)*‖rieszKernel ((left:ℂ)+(t:ℂ)*Complex.I)‖*X^left := by gcongr + _ = B*‖rieszKernel ((left:ℂ)+(t:ℂ)*Complex.I)‖ := by dsimp only [B]; ring + _ ≤ _ := mul_le_mul_of_nonneg_left (rieszKernel_norm_bound hl t) hB + have hcomp := intervalIntegral.integral_mono_on hTT hfi.norm hg hpoint + rw [intervalIntegral.integral_const_mul] at hcomp + have hmajor := mul_le_mul_of_nonneg_left (rieszMajorant_interval_le T) hB + rw [norm_VIntegral_eq] + calc + _ ≤ ∫ t in (-T)..T, ‖characterRieszIntegrand chi X ((left:ℂ)+(t:ℂ)*Complex.I)‖ := + intervalIntegral.norm_integral_le_integral_norm hTT + _ ≤ B*(4*Real.pi) := hcomp.trans hmajor + _ = _ := by dsimp only [B]; ring + +lemma riesz_horizontal_edge_bound {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + {X left right T height C : ℝ} (hX : 1 ≤ X) (hl : 1/2 ≤ left) (hlr : left ≤ right) + (hr : right ≤ 2) (_hT : 0 ≤ T) (hy : |height| = T) (hC : 0 ≤ C) + (hb : ∀ s ∈ Icc left right ×ℂ Icc (-T) T, + ‖logDeriv (DirichletCharacter.LFunction chi) s‖ ≤ C*(modulusHeight q T)^3) + (hf : _root_.Erdos970.HolomorphicOn (characterRieszIntegrand chi X) (Icc left right ×ℂ Icc (-T) T)) : + ‖_root_.Erdos970.HIntegral (characterRieszIntegrand chi X) left right height‖ ≤ + 8*C*(modulusHeight q T)^3*X^right/(1+T^2) := by + have hXp : 0 < X := by linarith + let B : ℝ := C*(modulusHeight q T)^3*X^right*((4:ℝ)/(1+T^2)) + have hH := modulusHeight_ge_one q T + have hB : 0 ≤ B := by dsimp only [B]; positivity + have hmaps : MapsTo (fun x:ℝ => (x:ℂ)+(height:ℂ)*Complex.I) (Icc left right) + (Icc left right ×ℂ Icc (-T) T) := by + intro x hx + simp only [Complex.mem_reProdIm,show ((x:ℂ)+(height:ℂ)*Complex.I).re = x by simp, + show ((x:ℂ)+(height:ℂ)*Complex.I).im = height by simp] + exact ⟨hx,abs_le.mp hy.le⟩ + have hc : ContinuousOn (fun x:ℝ => characterRieszIntegrand chi X ((x:ℂ)+(height:ℂ)*Complex.I)) + (Icc left right) := hf.continuousOn.comp (by fun_prop) hmaps + have hfi : IntervalIntegrable (fun x:ℝ => characterRieszIntegrand chi X ((x:ℂ)+(height:ℂ)*Complex.I)) + volume left right := (show ContinuousOn _ (uIcc left right) by simpa only [uIcc_of_le hlr] using hc).intervalIntegrable + have hpoint : ∀ x ∈ Icc left right, + ‖characterRieszIntegrand chi X ((x:ℂ)+(height:ℂ)*Complex.I)‖ ≤ B := by + intro x hx + have hlog := hb _ (hmaps hx) + have hkernel := rieszKernel_norm_bound (hl.trans hx.1) height + have hsq : height^2 = T^2 := by rw [← sq_abs height,hy] + rw [hsq] at hkernel + have hpow := Real.rpow_le_rpow_of_exponent_le hX hx.2 + rw [norm_characterRieszIntegrand chi hXp,show ((x:ℂ)+(height:ℂ)*Complex.I).re = x by simp] + calc + _ ≤ (C*(modulusHeight q T)^3)*((4:ℝ)/(1+T^2))*X^right := by gcongr + _ = B := by dsimp only [B]; ring + have hcomp := intervalIntegral.integral_mono_on hlr hfi.norm (intervalIntegrable_const (c := B)) hpoint + rw [intervalIntegral.integral_const] at hcomp + have hwidth : right-left ≤ 2 := by linarith + have hwidthB := mul_le_mul_of_nonneg_right hwidth hB + unfold _root_.Erdos970.HIntegral + have hn := intervalIntegral.norm_integral_le_integral_norm (μ := volume) (f := fun x:ℝ => characterRieszIntegrand chi X ((x:ℂ)+(height:ℂ)*Complex.I)) hlr + have hbound : ‖∫ x in left..right, characterRieszIntegrand chi X ((x:ℂ)+(height:ℂ)*Complex.I)‖ ≤ 2*B := by + simp only [smul_eq_mul] at hcomp + linarith + apply hbound.trans_eq + dsimp only [B] + ring + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Set _root_.Complex _root_.MeasureTheory + +lemma norm_mellinFactor : ‖mellinFactor‖ = 1/(2*Real.pi) := by + unfold mellinFactor + rw [Complex.norm_real,Real.norm_eq_abs,abs_of_pos (by positivity)] + +theorem exists_uniform_riesz_contour_bound : + ∃ a : ℝ, 0 < a ∧ a ≤ 1/100 ∧ ∃ C : ℝ, 0 < C ∧ ∃ B : ℝ, 0 ≤ B ∧ + ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), chi ≠ 1 → + ∀ X sigma T : ℝ, 1 ≤ X → 1 < sigma → sigma ≤ 2 → 0 < T → + ‖rieszSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ + (1/(2*Real.pi)) * + (4*Real.pi*C*(modulusHeight q T)^3*X^(rieszContourLeft a q T) + + 16*C*(modulusHeight q T)^3*X^sigma/(1+T^2) + + 8*((sigma-1)⁻¹+B)*X^sigma/T) := by + obtain ⟨a,ha,ha100,C,hC,hrect⟩ := exists_uniform_riesz_rectangle + obtain ⟨B,hB,htails⟩ := exists_uniform_riesz_right_tails + refine ⟨a,ha,ha100,C,hC,B,hB,?_⟩ + intro q _ chi hchi X sigma T hX hs hs2 hT + have hXp : 0 < X := by linarith + obtain ⟨hl,hzero,hhol⟩ := hrect q chi hchi X sigma T hXp hs hs2 hT + let left : ℝ := rieszContourLeft a q T + have hlr : left ≤ sigma := by + have hdiv : 0 ≤ a/(modulusHeight q T)^2 := div_nonneg ha.le (sq_nonneg _) + dsimp only [left,rieszContourLeft] + linarith + have hlog : ∀ s ∈ Icc left sigma ×ℂ Icc (-T) T, + ‖logDeriv (DirichletCharacter.LFunction chi) s‖ ≤ C*(modulusHeight q T)^3 := + fun s hmem => (hzero s hmem).2 + have hleft := riesz_left_edge_bound chi hXp hl hlr hT.le hC.le hlog hhol + have hdown := riesz_horizontal_edge_bound chi (height := -T) hX hl hlr hs2 hT.le + (by rw [abs_neg,abs_of_nonneg hT.le]) hC.le hlog hhol + have hup := riesz_horizontal_edge_bound chi (height := T) hX hl hlr hs2 hT.le + (abs_of_nonneg hT.le) hC.le hlog hhol + obtain ⟨htlo,hthi⟩ := htails q chi hchi X sigma T hXp hs hT + have hshift := norm_full_vertical_shift_le (characterRieszIntegrand chi X) left sigma T hlr hT.le + hhol (integrable_characterRiesz_right chi hchi hs hXp) + let E : ℝ := 4*Real.pi*C*(modulusHeight q T)^3*X^left + + 16*C*(modulusHeight q T)^3*X^sigma/(1+T^2) + 8*((sigma-1)⁻¹+B)*X^sigma/T + have hfull : ‖_root_.Erdos970.VerticalIntegral (characterRieszIntegrand chi X) sigma‖ ≤ E := by + have hp := add_le_add (add_le_add (add_le_add (add_le_add htlo hleft) hdown) hup) hthi + apply (hshift.trans hp).trans_eq + dsimp only [E,left] + ring + rw [finite_riesz_eq_integrand chi hs hXp,norm_mul,norm_mellinFactor, + ← norm_verticalIntegral_eq (characterRieszIntegrand chi X) sigma] + exact mul_le_mul_of_nonneg_left hfull (by positivity) + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma eventually_log_cube_le (K b : ℝ) (hb : 0 < b) : + ∀ᶠ L : ℝ in atTop, 3 ≤ L ∧ K*(Real.log L)^3 ≤ b*L := by + have hbase := Real.tendsto_pow_log_div_mul_add_atTop (1:ℝ) 0 3 one_ne_zero + have hlim : Tendsto (fun L:ℝ => K*(Real.log L)^3/L) atTop (𝓝 0) := by + simpa only [one_mul,add_zero,mul_zero,mul_div_assoc] using hbase.const_mul K + filter_upwards [eventually_ge_atTop (3:ℝ),hlim.eventually (gt_mem_nhds hb)] with L hL hsmall + refine ⟨hL,?_⟩ + exact (div_le_iff₀ (by linarith : 0 < L)).mp hsmall.le + +lemma polylog_height_bound (A D : ℝ) (hD : 0 ≤ D) {L : ℝ} (hL : 3 ≤ L) + (q : ℕ) [NeZero q] (hq : (q:ℝ) ≤ L^A) : + modulusHeight q (L^D) ≤ (A+D+Real.log 7)*Real.log L := by + have hLp : 0 < L := by linarith + have hL1 : 1 ≤ L := by linarith + have hT : 1 ≤ L^D := Real.one_le_rpow hL1 hD + have hTp : 0 < L^D := Real.rpow_pos_of_pos hLp _ + have hlogL : 1 < Real.log L := + (Real.lt_log_iff_exp_lt hLp).mpr (Real.exp_one_lt_three.trans_le hL) + have hqpos : (0:ℝ) < q := by exact_mod_cast NeZero.pos q + have hlogq := Real.log_le_log hqpos hq + rw [Real.log_rpow hLp] at hlogq + have hlogT : Real.log (L^D+6) ≤ Real.log (7*(L^D)) := + Real.log_le_log (by positivity) (by nlinarith only [hT]) + rw [Real.log_mul (by norm_num : (7:ℝ) ≠ 0) hTp.ne',Real.log_rpow hLp] at hlogT + have hlog7 : 0 ≤ Real.log 7 := Real.log_nonneg (by norm_num) + have h7 := mul_le_mul_of_nonneg_left hlogL.le hlog7 + unfold modulusHeight + rw [abs_of_nonneg hTp.le] + nlinarith only [hlogq,hlogT,h7] + +lemma div_rpow_add_one {L : ℝ} (hL : 0 < L) (R : ℝ) : L/L^(R+1) = L^(-R) := by + have hn := (Real.rpow_pos_of_pos hL R).ne' + rw [Real.rpow_add hL,Real.rpow_one,Real.rpow_neg hL.le] + field_simp + +theorem eventually_polylog_contour_savings (a A R : ℝ) (ha : 0 < a) (hA : 0 < A) (hR : 0 < R) : + ∀ᶠ X : ℝ in atTop, 3 ≤ X ∧ ∀ (q : ℕ) [NeZero q], (q:ℝ) ≤ (Real.log X)^A → + let L : ℝ := Real.log X + let T : ℝ := L^(R+2) + 3 ≤ L ∧ 1 ≤ T ∧ + (modulusHeight q T)^3*Real.exp (-a*L/(modulusHeight q T)^2) ≤ L^(-R) ∧ + (modulusHeight q T)^3/(1+T^2) ≤ L^(-R) ∧ L/T ≤ L^(-R) := by + let K : ℝ := A+(R+2)+Real.log 7 + have h7 : 0 ≤ Real.log 7 := Real.log_nonneg (by norm_num) + have hK : 0 < K := by dsimp only [K]; linarith + have he1 := Real.tendsto_log_atTop.eventually (eventually_log_cube_le (K^3) 1 zero_lt_one) + have he2 := Real.tendsto_log_atTop.eventually (eventually_log_cube_le ((R+2)*K^2) a ha) + filter_upwards [eventually_ge_atTop (3:ℝ),he1,he2] with X hX h1 h2 + refine ⟨hX,?_⟩ + intro q _ hq + let L : ℝ := Real.log X + let T : ℝ := L^(R+2) + let H : ℝ := modulusHeight q T + have hL : 3 ≤ L := h1.1 + have hLp : 0 < L := by linarith + have hL1 : 1 ≤ L := by linarith + have hlogL : 0 < Real.log L := Real.log_pos (by linarith) + have hT : 1 ≤ T := Real.one_le_rpow hL1 (by linarith) + have hTp : 0 < T := by linarith + have hH : 1 ≤ H := modulusHeight_ge_one q T + have hHp : 0 < H := by linarith + have hheight : H ≤ K*Real.log L := polylog_height_bound A (R+2) (by linarith) hL q hq + have hH3 : H^3 ≤ L := by + calc + _ ≤ (K*Real.log L)^3 := by gcongr + _ = K^3*(Real.log L)^3 := by ring + _ ≤ L := by simpa only [one_mul] using h1.2 + have hH2 : H^2 ≤ K^2*(Real.log L)^2 := by + calc + _ ≤ (K*Real.log L)^2 := by gcongr + _ = _ := by ring + have hguard : (R+2)*Real.log L*H^2 ≤ a*L := by + calc + _ ≤ (R+2)*Real.log L*(K^2*(Real.log L)^2) := by gcongr + _ = ((R+2)*K^2)*(Real.log L)^3 := by ring + _ ≤ a*L := h2.2 + have hsave : (R+2)*Real.log L ≤ a*L/H^2 := (le_div_iff₀ (by positivity)).mpr hguard + have hexp : Real.exp (-a*L/H^2) ≤ L^(-(R+2)) := by + rw [Real.rpow_def_of_pos hLp] + apply Real.exp_le_exp.mpr + calc + _ = -(a*L/H^2) := by ring + _ ≤ -((R+2)*Real.log L) := neg_le_neg hsave + _ = _ := by ring + have hratio : L/T ≤ L^(-R) := by + calc + _ ≤ L/L^(R+1) := div_le_div_of_nonneg_left hLp.le (Real.rpow_pos_of_pos hLp _) + (Real.rpow_le_rpow_of_exponent_le hL1 (by linarith)) + _ = _ := div_rpow_add_one hLp R + change 3 ≤ L ∧ 1 ≤ T ∧ H^3*Real.exp (-a*L/H^2) ≤ L^(-R) ∧ H^3/(1+T^2) ≤ L^(-R) ∧ L/T ≤ L^(-R) + refine ⟨hL,hT,?_,?_,hratio⟩ + · calc + _ ≤ L*L^(-(R+2)) := mul_le_mul hH3 hexp (Real.exp_nonneg _) hLp.le + _ = L/T := by dsimp only [T]; rw [Real.rpow_neg hLp.le,div_eq_mul_inv] + _ ≤ _ := hratio + · calc + _ ≤ L/(1+T^2) := div_le_div_of_nonneg_right hH3 (by positivity) + _ ≤ L/T := div_le_div_of_nonneg_left hLp.le hTp (by nlinarith only [hT]) + _ ≤ _ := hratio + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma rpow_perron_sigma {X : ℝ} (hX : 1 < X) : + X^(1+(Real.log X)⁻¹) = X*Real.exp 1 := by + rw [Real.rpow_def_of_pos (by linarith : 0 < X),mul_add,mul_one, + mul_inv_cancel₀ (Real.log_pos hX).ne',Real.exp_add,Real.exp_log (by linarith : 0 < X)] + +lemma rpow_rieszContourLeft {X : ℝ} (hX : 0 < X) (a : ℝ) (q : ℕ) (T : ℝ) : + X^(rieszContourLeft a q T) = X*Real.exp (-a*Real.log X/(modulusHeight q T)^2) := by + rw [Real.rpow_def_of_pos hX] + have he : Real.log X*rieszContourLeft a q T = + Real.log X+(-a*Real.log X/(modulusHeight q T)^2) := by unfold rieszContourLeft; ring + rw [he,Real.exp_add,Real.exp_log hX] + +theorem riesz_character_log_power (A R : ℝ) (hA : 0 < A) (hR : 0 < R) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q] + (chi : DirichletCharacter ℂ q), chi ≠ 1 → (q:ℝ) ≤ (Real.log X)^A → + ‖rieszSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ K*X/(Real.log X)^R := by + obtain ⟨a,ha,_ha100,C,hC,B,hB,hcontour⟩ := exists_uniform_riesz_contour_bound + let P : ℝ := 4*Real.pi*C+16*C*Real.exp 1+8*(B+1)*Real.exp 1 + let K : ℝ := (1/(2*Real.pi))*P + have hP : 0 < P := by dsimp only [P]; positivity + have hK : 0 < K := by dsimp only [K]; positivity + refine ⟨K,hK,?_⟩ + filter_upwards [eventually_polylog_contour_savings a A R ha hA hR] with X hX + intro q _ chi hchi hq + obtain ⟨hX3,hSavings⟩ := hX + obtain ⟨hL3,hT1,hleft,hhor,hratio⟩ := hSavings q hq + let L : ℝ := Real.log X + let T : ℝ := L^(R+2) + let H : ℝ := modulusHeight q T + let sigma : ℝ := 1+L⁻¹ + have hXp : 0 < X := by linarith + have hX1 : 1 < X := by linarith + have hLp : 0 < L := by linarith + have hTp : 0 < T := by linarith + have hs1 : 1 < sigma := by + have hi : 0 < L⁻¹ := inv_pos.mpr hLp + dsimp only [sigma] + linarith + have hs2 : sigma ≤ 2 := by + have hinv : L⁻¹ ≤ 1 := by rw [← one_div]; exact (div_le_iff₀ hLp).mpr (by linarith) + dsimp only [sigma] + linarith + have h := hcontour q chi hchi X sigma T (by linarith) hs1 hs2 hTp + have hrightpow : X^sigma = X*Real.exp 1 := rpow_perron_sigma hX1 + have hleftpow : X^(rieszContourLeft a q T) = X*Real.exp (-a*L/H^2) := rpow_rieszContourLeft hXp a q T + have hinv : (sigma-1)⁻¹ = L := by dsimp only [sigma]; rw [add_sub_cancel_left,inv_inv] + rw [hrightpow,hleftpow,hinv] at h + change H^3*Real.exp (-a*L/H^2) ≤ L^(-R) at hleft + change H^3/(1+T^2) ≤ L^(-R) at hhor + change L/T ≤ L^(-R) at hratio + have hBL := mul_le_mul_of_nonneg_left (show 1 ≤ L by linarith) hB + have hLB : L+B ≤ (B+1)*L := by nlinarith only [hBL] + have htail : (L+B)/T ≤ (B+1)*L^(-R) := by + calc + _ ≤ ((B+1)*L)/T := div_le_div_of_nonneg_right hLB hTp.le + _ = (B+1)*(L/T) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hratio (by linarith) + have h1 := mul_le_mul_of_nonneg_left hleft (show 0 ≤ 4*Real.pi*C*X by positivity) + have h2 := mul_le_mul_of_nonneg_left hhor (show 0 ≤ 16*C*Real.exp 1*X by positivity) + have h3 := mul_le_mul_of_nonneg_left htail (show 0 ≤ 8*Real.exp 1*X by positivity) + have he : 4*Real.pi*C*H^3*(X*Real.exp (-a*L/H^2)) + + 16*C*H^3*(X*Real.exp 1)/(1+T^2)+8*(L+B)*(X*Real.exp 1)/T ≤ P*X*L^(-R) := by + calc + _ = (4*Real.pi*C*X)*(H^3*Real.exp (-a*L/H^2)) + + (16*C*Real.exp 1*X)*(H^3/(1+T^2))+(8*Real.exp 1*X)*((L+B)/T) := by ring + _ ≤ (4*Real.pi*C*X)*L^(-R)+(16*C*Real.exp 1*X)*L^(-R)+ + (8*Real.exp 1*X)*((B+1)*L^(-R)) := add_le_add (add_le_add h1 h2) h3 + _ = _ := by dsimp only [P]; ring + apply h.trans + calc + _ ≤ (1/(2*Real.pi))*(P*X*L^(-R)) := mul_le_mul_of_nonneg_left he (by positivity) + _ = K*X/(Real.log X)^R := by dsimp only [K]; rw [Real.rpow_neg hLp.le]; ring + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz + +noncomputable def rieszDifferenceWeight (delta u : ℝ) : ℝ := + (max (1+delta-u) 0-max (1-u) 0)/delta + +lemma rieszWeight_scaled {delta : ℝ} (hd : 0 < delta) (u : ℝ) : + (1+delta)*rieszWeight (u/(1+delta)) = max (1+delta-u) 0 := by + have hp : 0 < 1+delta := by linarith + by_cases hu : u ≤ 1+delta + · have hratio : u/(1+delta) ≤ 1 := (div_le_iff₀ hp).mpr (by linarith) + simp only [rieszWeight,max_eq_left (sub_nonneg.mpr hratio),max_eq_left (sub_nonneg.mpr hu)] + field_simp + · have hratio : 1 ≤ u/(1+delta) := (le_div_iff₀ hp).mpr (by linarith) + simp only [rieszWeight,max_eq_right (sub_nonpos.mpr hratio), + max_eq_right (show 1+delta-u ≤ 0 by linarith),mul_zero] + +lemma rieszDifferenceWeight_eq {delta : ℝ} (hd : 0 < delta) (u : ℝ) : + rieszDifferenceWeight delta u = + ((1+delta)*rieszWeight (u/(1+delta))-rieszWeight u)/delta := by + rw [rieszWeight_scaled hd] + rfl + +lemma rieszDifferenceWeight_nonneg {delta : ℝ} (hd : 0 < delta) (u : ℝ) : + 0 ≤ rieszDifferenceWeight delta u := by + unfold rieszDifferenceWeight + apply div_nonneg _ hd.le + exact sub_nonneg.mpr (max_le_max (by linarith) le_rfl) + +lemma rieszDifferenceWeight_le_one {delta : ℝ} (hd : 0 < delta) (u : ℝ) : + rieszDifferenceWeight delta u ≤ 1 := by + have hm : max (1+delta-u) 0 ≤ max (1-u) 0+delta := by + apply max_le + · have h := le_max_left (1-u) 0 + linarith + · have h := le_max_right (1-u) 0 + linarith + unfold rieszDifferenceWeight + exact (div_le_iff₀ hd).mpr (by linarith) + +lemma rieszDifferenceWeight_eq_one {delta u : ℝ} (hd : 0 < delta) (hu : u ≤ 1) : + rieszDifferenceWeight delta u = 1 := by + unfold rieszDifferenceWeight + rw [max_eq_left (show 0 ≤ 1+delta-u by linarith),max_eq_left (show 0 ≤ 1-u by linarith)] + have he : 1+delta-u-(1-u) = delta := by ring + rw [he,div_self hd.ne'] + +lemma rieszDifferenceWeight_eq_zero {delta u : ℝ} (hd : 0 < delta) (hu : 1+delta ≤ u) : + rieszDifferenceWeight delta u = 0 := by + simp only [rieszDifferenceWeight,max_eq_right (show 1+delta-u ≤ 0 by linarith), + max_eq_right (show 1-u ≤ 0 by linarith),sub_self,zero_div] + +lemma riesz_rescaled_difference {delta X : ℝ} (hd : 0 < delta) (_hX : 0 < X) (n : ℝ) : + ((1+delta)*rieszWeight (n/((1+delta)*X))-rieszWeight (n/X))/delta = + rieszDifferenceWeight delta (n/X) := by + rw [rieszDifferenceWeight_eq hd] + have he : n/((1+delta)*X) = (n/X)/(1+delta) := by + simp only [div_eq_mul_inv,mul_inv_rev] + ring + rw [he] + + + + +open scoped BigOperators + +noncomputable def sharpSum (f : ℕ → ℂ) (X : ℝ) : ℂ := + ∑ n ∈ Finset.range (⌊X⌋₊+1), f n +noncomputable def rieszRecovery (f : ℕ → ℂ) (X delta : ℝ) : ℂ := + (((1+delta:ℝ):ℂ)*rieszSum f ((1+delta)*X)-rieszSum f X)/(delta:ℂ) + +lemma rieszSum_extend (f : ℕ → ℂ) {X Y : ℝ} (hX : 0 < X) (hXY : X ≤ Y) : + rieszSum f X = ∑ n ∈ Finset.range (⌊Y⌋₊+1), f n*(rieszWeight ((n:ℝ)/X):ℂ) := by + rw [← tsum_riesz_eq_finite f hX] + apply tsum_eq_sum + intro n hn + have hn' : ⌊Y⌋₊ < n := by simp only [Finset.mem_range] at hn; omega + have hYn : Y < (n:ℝ) := (Nat.floor_lt (hX.le.trans hXY)).mp hn' + have hw := rieszWeight_eq_zero (x := (n:ℝ)/X) ((le_div_iff₀ hX).mpr (by linarith)) + rw [hw,Complex.ofReal_zero,mul_zero] + +lemma rieszRecovery_eq_sum (f : ℕ → ℂ) {X delta : ℝ} (hX : 0 < X) (hd : 0 < delta) : + rieszRecovery f X delta = + ∑ n ∈ Finset.range (⌊(1+delta)*X⌋₊+1), f n*(rieszDifferenceWeight delta ((n:ℝ)/X):ℂ) := by + have hXY : X ≤ (1+delta)*X := by nlinarith [mul_pos hd hX] + unfold rieszRecovery + rw [rieszSum_extend f hX hXY] + unfold rieszSum + rw [Finset.mul_sum,← Finset.sum_sub_distrib,Finset.sum_div] + apply Finset.sum_congr rfl + intro n _ + have hw := congrArg Complex.ofReal (riesz_rescaled_difference hd hX (n:ℝ)) + push_cast at hw + calc + _ = f n * ((((1+delta:ℝ):ℂ)*(rieszWeight ((n:ℝ)/((1+delta)*X)):ℂ)- + (rieszWeight ((n:ℝ)/X):ℂ))/(delta:ℂ)) := by ring + _ = _ := by push_cast; rw [hw] + +lemma rieszRecovery_sub_sharp (f : ℕ → ℂ) {X delta : ℝ} (hX : 0 < X) (hd : 0 < delta) : + rieszRecovery f X delta-sharpSum f X = + ∑ n ∈ Finset.Ico (⌊X⌋₊+1) (⌊(1+delta)*X⌋₊+1), + f n*(rieszDifferenceWeight delta ((n:ℝ)/X):ℂ) := by + have hXY : X ≤ (1+delta)*X := by nlinarith [mul_pos hd hX] + have hfloor : ⌊X⌋₊+1 ≤ ⌊(1+delta)*X⌋₊+1 := Nat.add_le_add_right (Nat.floor_mono hXY) 1 + have hprefix : (∑ n ∈ Finset.range (⌊X⌋₊+1), + f n*(rieszDifferenceWeight delta ((n:ℝ)/X):ℂ)) = sharpSum f X := by + apply Finset.sum_congr rfl + intro n hn + have hn' : n ≤ ⌊X⌋₊ := by simp only [Finset.mem_range] at hn; omega + have hnX : (n:ℝ) ≤ X := (show (n:ℝ) ≤ (⌊X⌋₊:ℝ) by exact_mod_cast hn').trans (Nat.floor_le hX.le) + rw [rieszDifferenceWeight_eq_one hd ((div_le_iff₀ hX).mpr (by linarith)),Complex.ofReal_one,mul_one] + have hs := Finset.sum_range_add_sum_Ico (fun n:ℕ => f n*(rieszDifferenceWeight delta ((n:ℝ)/X):ℂ)) hfloor + rw [hprefix] at hs + rw [rieszRecovery_eq_sum f hX hd,← hs,add_sub_cancel_left] + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +theorem norm_rieszRecovery_sub_sharp (f : ℕ → ℂ) + (hcoeff : ∀ n : ℕ, 0 < n → ‖f n‖ ≤ Real.log (n:ℝ)) + {X delta : ℝ} (hX : 1 ≤ X) (hd : 0 < delta) : + ‖rieszRecovery f X delta-sharpSum f X‖ ≤ (delta*X+1)*Real.log ((1+delta)*X) := by + have hXp : 0 < X := by linarith + let Y : ℝ := (1+delta)*X + have hXY : X ≤ Y := by dsimp only [Y]; nlinarith [mul_pos hd hXp] + have hY1 : 1 ≤ Y := hX.trans hXY + have hYp : 0 < Y := by linarith + have hfloor : ⌊X⌋₊ ≤ ⌊Y⌋₊ := Nat.floor_mono hXY + let S := Finset.Ico (⌊X⌋₊+1) (⌊Y⌋₊+1) + have hcard : (S.card:ℝ) ≤ delta*X+1 := by + dsimp only [S] + rw [Nat.card_Ico,Nat.cast_sub (Nat.add_le_add_right hfloor 1)] + push_cast + have hy := Nat.floor_le hYp.le + have hx := Nat.lt_floor_add_one X + dsimp only [Y] at hy + nlinarith + have hpoint (n:ℕ) (hn : n ∈ S) : + ‖f n*(rieszDifferenceWeight delta ((n:ℝ)/X):ℂ)‖ ≤ Real.log Y := by + have hn' := Finset.mem_Ico.mp hn + have hnp : 0 < n := by omega + have hnf : n ≤ ⌊Y⌋₊ := by omega + have hnY : (n:ℝ) ≤ Y := (show (n:ℝ) ≤ (⌊Y⌋₊:ℝ) by exact_mod_cast hnf).trans (Nat.floor_le hYp.le) + rw [norm_mul,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (rieszDifferenceWeight_nonneg hd _)] + calc + _ ≤ ‖f n‖ := by + have h := mul_le_mul_of_nonneg_left (rieszDifferenceWeight_le_one hd ((n:ℝ)/X)) (norm_nonneg (f n)) + simpa only [mul_one] using h + _ ≤ Real.log (n:ℝ) := hcoeff n hnp + _ ≤ Real.log Y := Real.log_le_log (by exact_mod_cast hnp) hnY + rw [rieszRecovery_sub_sharp f hXp hd] + change ‖∑ n ∈ S, f n*(rieszDifferenceWeight delta ((n:ℝ)/X):ℂ)‖ ≤ (delta*X+1)*Real.log Y + calc + _ ≤ ∑ n ∈ S, ‖f n*(rieszDifferenceWeight delta ((n:ℝ)/X):ℂ)‖ := norm_sum_le _ _ + _ ≤ ∑ _n ∈ S, Real.log Y := Finset.sum_le_sum hpoint + _ = (S.card:ℝ)*Real.log Y := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right hcard (Real.log_nonneg hY1) + +lemma norm_rieszRecovery_le (f : ℕ → ℂ) (X : ℝ) {delta : ℝ} (hd : 0 < delta) : + ‖rieszRecovery f X delta‖ ≤ + ((1+delta)*‖rieszSum f ((1+delta)*X)‖+‖rieszSum f X‖)/delta := by + unfold rieszRecovery + rw [norm_div,Complex.norm_real,Real.norm_eq_abs,abs_of_pos hd] + apply div_le_div_of_nonneg_right _ hd.le + calc + _ ≤ ‖((1+delta:ℝ):ℂ)*rieszSum f ((1+delta)*X)‖+‖rieszSum f X‖ := norm_sub_le _ _ + _ = _ := by rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_pos (by linarith : 0 < 1+delta)] + +theorem sharpSum_norm_le_riesz (f : ℕ → ℂ) + (hcoeff : ∀ n : ℕ, 0 < n → ‖f n‖ ≤ Real.log (n:ℝ)) + {X delta : ℝ} (hX : 1 ≤ X) (hd : 0 < delta) : + ‖sharpSum f X‖ ≤ + ((1+delta)*‖rieszSum f ((1+delta)*X)‖+‖rieszSum f X‖)/delta + + (delta*X+1)*Real.log ((1+delta)*X) := by + have he := norm_rieszRecovery_sub_sharp f hcoeff hX hd + have hr := norm_rieszRecovery_le f X hd + have ht := norm_add_le (sharpSum f X-rieszRecovery f X delta) (rieszRecovery f X delta) + rw [sub_add_cancel,norm_sub_rev] at ht + linarith + +end Erdos970Dependency.SiegelWalfisz + + + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +lemma eventually_log_rpow_le_self (k : ℝ) : + ∀ᶠ X : ℝ in atTop, 3 ≤ X ∧ (Real.log X)^k ≤ X := by + let N : ℕ := ⌈k⌉₊ + have hkN : k ≤ (N:ℝ) := Nat.le_ceil k + have hbase := Real.tendsto_pow_log_div_mul_add_atTop (1:ℝ) 0 N one_ne_zero + have hlim : Tendsto (fun X:ℝ => (Real.log X)^N/X) atTop (𝓝 0) := by + simpa only [one_mul,add_zero] using hbase + filter_upwards [eventually_ge_atTop (3:ℝ),hlim.eventually (gt_mem_nhds zero_lt_one)] with X hX hsmall + have hXp : 0 < X := by linarith + have hlog : 1 ≤ Real.log X := ((Real.lt_log_iff_exp_lt hXp).mpr (Real.exp_one_lt_three.trans_le hX)).le + have hnat : (Real.log X)^N ≤ X := by + have h := (div_le_iff₀ hXp).mp hsmall.le + simpa only [one_mul] using h + refine ⟨hX,?_⟩ + calc + _ ≤ (Real.log X)^(N:ℝ) := Real.rpow_le_rpow_of_exponent_le hlog hkN + _ = (Real.log X)^N := Real.rpow_natCast _ _ + _ ≤ X := hnat + +lemma character_vonMangoldt_norm_le {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (n : ℕ) : + ‖chi n*(ArithmeticFunction.vonMangoldt n:ℂ)‖ ≤ Real.log (n:ℝ) := by + rw [norm_mul,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (ArithmeticFunction.vonMangoldt_nonneg (n := n))] + calc + _ ≤ ArithmeticFunction.vonMangoldt n := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right (chi.norm_le_one n) + (ArithmeticFunction.vonMangoldt_nonneg (n := n)) + _ ≤ _ := ArithmeticFunction.vonMangoldt_le_log + +lemma recovery_scale_bounds (k : ℝ) (hk : 0 < k) {X : ℝ} + (hX : 3 ≤ X) (hpow : (Real.log X)^k ≤ X) : + let delta : ℝ := (Real.log X)^(-k) + let Y : ℝ := (1+delta)*X + 0 < delta ∧ delta ≤ 1 ∧ 1 ≤ delta*X ∧ X ≤ Y ∧ Y ≤ 2*X ∧ + Real.log X ≤ Real.log Y ∧ Real.log Y ≤ 2*Real.log X := by + let L : ℝ := Real.log X + let delta : ℝ := L^(-k) + let Y : ℝ := (1+delta)*X + have hXp : 0 < X := by linarith + have hL : 1 ≤ L := ((Real.lt_log_iff_exp_lt hXp).mpr (Real.exp_one_lt_three.trans_le hX)).le + have hLp : 0 < L := by linarith + have hp : 0 < L^k := Real.rpow_pos_of_pos hLp _ + have hp1 : 1 ≤ L^k := Real.one_le_rpow hL hk.le + have hd : 0 < delta := Real.rpow_pos_of_pos hLp _ + have hd1 : delta ≤ 1 := by + dsimp only [delta] + rw [Real.rpow_neg hLp.le,← one_div] + exact (div_le_iff₀ hp).mpr (by linarith) + have hprod : delta*L^k = 1 := by + dsimp only [delta] + rw [Real.rpow_neg hLp.le,inv_mul_cancel₀ hp.ne'] + have hdX : 1 ≤ delta*X := by + have h := mul_le_mul_of_nonneg_left hpow hd.le + change delta*L^k ≤ delta*X at h + rwa [hprod] at h + have hXY : X ≤ Y := by dsimp only [Y]; nlinarith + have hY2 : Y ≤ 2*X := by + have h := mul_le_mul_of_nonneg_right hd1 hXp.le + dsimp only [Y] + nlinarith + have hYp : 0 < Y := hXp.trans_le hXY + have hlogs : Real.log X ≤ Real.log Y := Real.log_le_log hXp hXY + have hlog2 : Real.log 2 ≤ Real.log X := Real.log_le_log (by norm_num) (by linarith) + have hlogY : Real.log Y ≤ 2*Real.log X := by + have h := Real.log_le_log hYp hY2 + rw [Real.log_mul (by norm_num : (2:ℝ) ≠ 0) hXp.ne'] at h + linarith + exact ⟨hd,hd1,hdX,hXY,hY2,hlogs,hlogY⟩ + +lemma recovery_power_product {L : ℝ} (hL : 0 < L) (k : ℝ) : + L^(-k)*L^(2*k) = L^k := by + rw [← Real.rpow_add hL] + congr 1 + ring + +lemma recovery_power_times_log {L : ℝ} (hL : 0 < L) (M : ℝ) : + L^(-(M+1))*L = L^(-M) := by + calc + _ = L^(-(M+1))*L^(1:ℝ) := by rw [Real.rpow_one] + _ = L^(-(M+1)+1) := (Real.rpow_add hL _ _).symm + _ = _ := by congr 1; ring + +end Erdos970Dependency.SiegelWalfisz + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReducedFractions.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReducedFractions.lean new file mode 100644 index 0000000000000000000000000000000000000000..53ed68c3354d4e7c1e6081b98804eef2bd4922eb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReducedFractions.lean @@ -0,0 +1,107 @@ +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Mathlib.Data.Nat.GCD.Basic +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +open Set +open scoped BigOperators + +namespace AdditiveLargeSieve + +def reducedFractions (Q : ℕ) : Finset (ℕ × ℕ) := + ((Finset.Icc 1 Q) ×ˢ Finset.range Q).filter fun z => z.2 < z.1 ∧ z.2.Coprime z.1 + +@[simp] theorem mem_reducedFractions {Q : ℕ} {z : ℕ × ℕ} : + z ∈ reducedFractions Q ↔ 1 ≤ z.1 ∧ z.1 ≤ Q ∧ z.2 < z.1 ∧ z.2.Coprime z.1 := by + simp only [reducedFractions, Finset.mem_filter, Finset.mem_product, Finset.mem_Icc, + Finset.mem_range] + constructor + · rintro ⟨⟨⟨hq, hQ⟩, _⟩, ha, hc⟩ + exact ⟨hq, hQ, ha, hc⟩ + · rintro ⟨hq, hQ, ha, hc⟩ + exact ⟨⟨⟨hq, hQ⟩, ha.trans_le hQ⟩, ha, hc⟩ + +noncomputable def fractionValue (z : ℕ × ℕ) : ℝ := (z.2 : ℝ) / z.1 + +theorem fractionValue_mem {Q : ℕ} {z : ℕ × ℕ} (hz : z ∈ reducedFractions Q) : + fractionValue z ∈ Ico (0 : ℝ) 1 := by + rcases mem_reducedFractions.mp hz with ⟨hq, _, ha, _⟩ + have hq' : 0 < (z.1 : ℝ) := by exact_mod_cast (show 0 < z.1 by omega) + exact ⟨div_nonneg (Nat.cast_nonneg _) hq'.le, + (div_lt_one hq').2 (by exact_mod_cast ha)⟩ + +theorem reduced_cross_injective {x y : ℕ × ℕ} + (_hx : 0 < x.1) (hy : 0 < y.1) (hcx : x.2.Coprime x.1) (hcy : y.2.Coprime y.1) + (h : x.2 * y.1 = y.2 * x.1) : x = y := by + have hxy : x.1 ∣ y.1 := hcx.symm.dvd_of_dvd_mul_left (h ▸ Nat.dvd_mul_left x.1 y.2) + have hyx : y.1 ∣ x.1 := hcy.symm.dvd_of_dvd_mul_left (h.symm ▸ Nat.dvd_mul_left y.1 x.2) + have hq : x.1 = y.1 := Nat.dvd_antisymm hxy hyx + have ha : x.2 = y.2 := by + rw [hq] at h + exact Nat.eq_of_mul_eq_mul_right hy h + exact Prod.ext hq ha + +theorem one_le_abs_cast_sub {a b : ℕ} (hab : a ≠ b) : (1 : ℝ) ≤ |(a : ℝ) - b| := by + rcases lt_or_gt_of_ne hab with h | h + · have h' : (a : ℝ) + 1 ≤ b := by exact_mod_cast (show a + 1 ≤ b by omega) + rw [abs_of_nonpos (by linarith)] + linarith + · have h' : (b : ℝ) + 1 ≤ a := by exact_mod_cast (show b + 1 ≤ a by omega) + rw [abs_of_nonneg (by linarith)] + linarith + +theorem reduced_fraction_separation {Q : ℕ} (hQ : 0 < Q) + {x y : ℕ × ℕ} (hx : x ∈ reducedFractions Q) (hy : y ∈ reducedFractions Q) (hne : x ≠ y) : + ((Q : ℝ) ^ 2)⁻¹ ≤ |fractionValue x - fractionValue y| := by + rcases mem_reducedFractions.mp hx with ⟨hx0, hxQ, _, hcx⟩ + rcases mem_reducedFractions.mp hy with ⟨hy0, hyQ, _, hcy⟩ + have hxpos : 0 < (x.1 : ℝ) := by exact_mod_cast (show 0 < x.1 by omega) + have hypos : 0 < (y.1 : ℝ) := by exact_mod_cast (show 0 < y.1 by omega) + have hQpos : 0 < (Q : ℝ) := by exact_mod_cast hQ + have hcross : x.2 * y.1 ≠ y.2 * x.1 := by + intro h + exact hne (reduced_cross_injective (by omega) (by omega) hcx hcy h) + have hnum := one_le_abs_cast_sub hcross + simp only [Nat.cast_mul] at hnum + have hformula : fractionValue x - fractionValue y = + ((x.2 : ℝ) * y.1 - y.2 * x.1) / ((x.1 : ℝ) * y.1) := by + dsimp [fractionValue] + field_simp + rw [hformula, abs_div, abs_of_pos (mul_pos hxpos hypos)] + have hprod : (x.1 : ℝ) * y.1 ≤ (Q : ℝ) ^ 2 := by + have hxQ' : (x.1 : ℝ) ≤ Q := by exact_mod_cast hxQ + have hyQ' : (y.1 : ℝ) ≤ Q := by exact_mod_cast hyQ + nlinarith + calc + ((Q : ℝ) ^ 2)⁻¹ = 1 / (Q : ℝ) ^ 2 := by rw [one_div] + _ ≤ 1 / ((x.1 : ℝ) * y.1) := one_div_le_one_div_of_le (mul_pos hxpos hypos) hprod + _ ≤ _ := div_le_div_of_nonneg_right hnum (mul_pos hxpos hypos).le + +theorem sum_reducedFractions {E : Type*} [AddCommMonoid E] (Q : ℕ) (f : ℕ × ℕ → E) : + ∑ z ∈ reducedFractions Q, f z = + ∑ q ∈ Finset.Icc 1 Q, ∑ a ∈ (Finset.range q).filter (fun a => a.Coprime q), f (q, a) := by + classical + simp only [reducedFractions, Finset.sum_filter, Finset.sum_product] + apply Finset.sum_congr rfl + intro q hq + rw [← Finset.sum_filter] + have hsets : (Finset.range Q).filter (fun a => a < q ∧ a.Coprime q) = + (Finset.range q).filter (fun a => a.Coprime q) := by + ext a + simp only [Finset.mem_filter, Finset.mem_range] + have := (Finset.mem_Icc.mp hq).2 + omega + rw [hsets, Finset.sum_filter] + +end AdditiveLargeSieve + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceCutoffRecurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceCutoffRecurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..506ea49d9424ab92d9b9813f925457c140143002 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceCutoffRecurrence.lean @@ -0,0 +1,213 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ReferencePrefixRecurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceWeightedRecurrence + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry ReferenceAdmission ReferencePruning ReferencePrefixRecurrence +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def weightedValue (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) (F : List ℕ → ℝ) : ℝ := + ∑ ps ∈ referencePrefixes w P i r,signedWeight ps*F ps + +theorem weighted_reference_recurrence (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) (F : List ℕ → ℝ) : + weightedValue w P i r F=F []- + ∑ p ∈ P,if childAdmitted i r (primeExponent w p) then + (p:ℝ)⁻¹*weightedValue w (P.filter (fun q => q F (p::ps)) else 0 := by + have h := sum_decreasing_by_first P (fun ps => if admitted w i r ps then signedWeight ps*F ps else 0) + have he : weightedValue w P i r F = + ∑ ps ∈ decreasingPrefixes P,if admitted w i r ps then signedWeight ps*F ps else 0 := by + rw [weightedValue,referencePrefixes,Finset.sum_filter] + have hnil : (if admitted w i r [] then signedWeight []*F [] else 0)=F [] := by + simp [admitted,signedWeight,prefixWeight] + rw [he,h,hnil] + have hsum : (∑ p ∈ P,∑ ps ∈ decreasingPrefixes (P.filter (fun q => q q F (p::ps)) else 0) := by + rw [← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro p _hp + by_cases hc : childAdmitted i r (primeExponent w p) + · rw [ite_eq_left hc,weightedValue,referencePrefixes,Finset.sum_filter] + rw [Finset.mul_sum,← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro ps _ + simp only [admitted,hc,true_and,signedWeight,List.length_cons,pow_succ, + prefixWeight,List.map_cons,List.prod_cons] + split_ifs <;> ring + · simp [admitted,hc] + rw [hsum] + ring + +end NumberTheoryLean.ReferenceWeightedRecurrence + +end + +section + +namespace NumberTheoryLean.ReferenceForestTelescoping + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry PrimeHistories ReferenceAdmission ReferencePruning ReferenceWeightedRecurrence +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem suffixPrimes_nil (P : Finset ℕ) : suffixPrimes P []=P := by simp [suffixPrimes] + +theorem suffixPrimes_cons (P : Finset ℕ) (p : ℕ) (ps : List ℕ) : + suffixPrimes P (p::ps)=suffixPrimes (P.filter (fun q => q G (suffixPrimes P ps) (terminal w z ps)) + +theorem forestSum_recurrence (w : ℝ) (P : Finset ℕ) (z : Node) (G : Finset ℕ → Node → ℝ) : + forestSum w P z G=G P z- + ∑ p ∈ P,if childAdmitted z.side z.gap (primeExponent w p) then + (p:ℝ)⁻¹*forestSum w (P.filter (fun q => q G (suffixPrimes P ps) (terminal w z ps)) + simpa only [forestSum,suffixPrimes_nil,terminal_nil,suffixPrimes_cons,terminal_cons,step] using h + +noncomputable def recurrenceResidual (w : ℝ) (G : Finset ℕ → Node → ℝ) (P : Finset ℕ) (z : Node) : ℝ := + G P z+∑ p ∈ P,if childAdmitted z.side z.gap (primeExponent w p) then + (p:ℝ)⁻¹*G (P.filter (fun q => q q q q q q q q q q q q q q referencePolynomial w (S∪Q) y.side y.gap-B S y) P z= + cutoffInsertion w Q B P z := by + have hrec := cutoff_polynomial_recurrence w h z.side z.gap + have hsum : (∑ p ∈ P,if childAdmitted z.side z.gap (primeExponent w p) then + (p:ℝ)⁻¹*(referencePolynomial w ((P.filter (fun q => q q q q simp [step,mul_sub] + unfold recurrenceResidual cutoffInsertion + dsimp only + rw [hsum] + linarith + +theorem finite_cutoff_decomposition (w : ℝ) {P Q : Finset ℕ} (h : Above P Q) + (B : Finset ℕ → Node → ℝ) (z : Node) : + referencePolynomial w (P∪Q) z.side z.gap-B P z= + forestSum w P z (cutoffInsertion w Q B) := by + let G : Finset ℕ → Node → ℝ := fun S y => referencePolynomial w (S∪Q) y.side y.gap-B S y + have ht := actual_forest_telescoping w G P z + change G P z=_ + rw [← ht] + unfold forestSum weightedValue + apply Finset.sum_congr rfl + intro ps _hp + have hsub : Above (suffixPrimes P ps) Q := by + intro p hp q hq + exact h p (Finset.mem_filter.mp hp).1 q hq + dsimp only + rw [show recurrenceResidual w G (suffixPrimes P ps) (terminal w z ps)= + cutoffInsertion w Q B (suffixPrimes P ps) (terminal w z ps) from difference_residual w hsub B _] + +end NumberTheoryLean.ReferenceCutoffRecurrence + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceIsolatedExclusion.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceIsolatedExclusion.lean new file mode 100644 index 0000000000000000000000000000000000000000..9027296531ff309506d973d62e9f66f57297a062 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceIsolatedExclusion.lean @@ -0,0 +1,469 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ThresholdMeshRate +import OAI.NumberTheory.Jacobsthal.Paths.WeightedIsolatedWords +import OAI.NumberTheory.Jacobsthal.Paths.WeightedRepeatedWords +import OAI.NumberTheory.Jacobsthal.Primes.LogarithmicPrimeLength + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SourceLengthExclusion +open _root_.Set _root_.Filter FinitePathGeometry ReferenceAdmission LogarithmicBinPartition LogarithmicPrimeLength +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +attribute [local instance] Classical.propDecidable + +theorem sourcePrimeSet_eq_between {w top : ℝ} (hw : 0 ≤ w) : sourcePrimeSet w top=primesBetween w top := by + ext p + simp only [sourcePrimeSet,primesBetween,Finset.mem_sdiff,Finset.mem_filter] + constructor + · rintro ⟨hp,hn⟩ + refine ⟨hp,?_⟩ + by_contra! hle + exact hn (Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff hw).mpr hle,(Nat.mem_primesLE.mp hp).2⟩) + · rintro ⟨hp,hlo⟩ + refine ⟨hp,?_⟩ + intro hsmall + exact (not_le_of_gt hlo) ((Nat.le_floor_iff hw).mp (Nat.mem_primesLE.mp hsmall).1) + +theorem uniform_source_length_exclusion (A : ℝ) : + ∃ L B₀ w₀ : ℝ,1 ≤ L ∧ 1 < B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → w^B=top → ∀ Clen : ℝ,L ≤ Clen → + ∀ F : Finset (List ℕ),F ⊆ decreasingPrefixes (sourcePrimeSet w top) → + (∀ ps ∈ F,Clen*Real.log B < (ps.length:ℝ)) → (∑ ps ∈ F,prefixWeight ps) ≤ B^(-A) := by + obtain ⟨w₀,hw₀,hTail⟩ := logarithmic_prime_length_tail + obtain ⟨L,hL,hTail⟩ := hTail A + obtain ⟨BT,hBT⟩ := eventually_atTop.mp hTail + refine ⟨L,max 2 BT,w₀,hL,lt_of_lt_of_le (by norm_num : (1:ℝ)<2) (le_max_left _ _),hw₀,?_⟩ + intro B w top hB hw htop Clen hClen F hF hLong + have hB2 : 2 ≤ B := (le_max_left _ _).trans hB + have hw1 : 1 < w := hw₀.trans_le hw + have hlog : 0 ≤ Real.log B := Real.log_nonneg (by linarith) + let m := ⌈L*Real.log B⌉₊ + have hsub : F ⊆ (decreasingPrefixes (primesBetween w (w^B))).filter (fun ps => m ≤ ps.length) := by + intro ps hp + refine Finset.mem_filter.mpr ⟨?_,?_⟩ + · simpa only [sourcePrimeSet_eq_between (zero_lt_one.trans hw1).le,← htop] using hF hp + · apply Nat.ceil_le.mpr + exact ((mul_le_mul_of_nonneg_right hClen hlog).trans_lt (hLong ps hp)).le + have hh := Finset.sum_le_sum_of_subset_of_nonneg hsub (fun ps _ _ => prefixWeight_nonneg ps) + exact hh.trans (hBT B ((le_max_right _ _).trans hB) w hw m (Nat.le_ceil _)) + +noncomputable def longReferenceWords (w top Clen B : ℝ) (i : Side) (r : ℝ) : Finset (List ℕ) := + (referencePrefixes w (sourcePrimeSet w top) i r).filter (fun ps => Clen*Real.log B < (ps.length:ℝ)) + +theorem literal_reference_length_exclusion (A : ℝ) : + ∃ L B₀ w₀ : ℝ,1 ≤ L ∧ 1 < B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → w^B=top → ∀ Clen : ℝ,L ≤ Clen → + ∀ i : Side,∀ r : ℝ,(∑ ps ∈ longReferenceWords w top Clen B i r,prefixWeight ps) ≤ B^(-A) := by + obtain ⟨L,B₀,w₀,hL,hB₀,hw₀,hBound⟩ := uniform_source_length_exclusion A + refine ⟨L,B₀,w₀,hL,hB₀,hw₀,?_⟩ + intro B w top hB hw htop Clen hClen i r + apply hBound B w top hB hw htop Clen hClen (longReferenceWords w top Clen B i r) + · intro ps hp + exact (Finset.mem_filter.mp (Finset.mem_filter.mp hp).1).1 + · intro ps hp + exact (Finset.mem_filter.mp hp).2 +end NumberTheoryLean.SourceLengthExclusion + + + +namespace NumberTheoryLean.ReferenceClearanceFailure +open FinitePathGeometry PrimeHistories ReferenceAdmission ActualPrefixClearance RepresentativeStopGeometry +open PrimePrefixRecovery ReconstructedParentCoupling MarkedPrefixTools LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass + + +theorem admitted_even_endpoint (w : ℝ) (z : Node) (ps : List ℕ) + (ha : admitted w z.side z.gap ps) (hne : ps ≠ []) (hi : (terminal w z ps).side=.even) : + sourceHeight (terminal w z ps).cutoff ≤ (terminal w z ps).gap := by + induction ps generalizing z with + | nil => exact False.elim (hne rfl) + | cons p ps ih => + cases ps with + | nil => + cases hz : z.side with + | even => simp [terminal,step,hz,Side.flip] at hi + | odd => + have hh := ha.1 + rw [hz] at hh + exact hh + | cons q qs => exact ih (step w z p) ha.2 (by simp) hi + +theorem reference_clearance_failure_prefix {w top Delta : ℝ} (hw : 1 < w) (htop : w < top) + (z : Node) (ps : List ℕ) + (hps : ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap) + (hbad : ¬actualClearance w z Delta ps) : hasNearThresholdPrefix w (10*Delta) z ps := by + classical + change ¬∀ qs ∈ ps.inits,qs ≠ [] → (terminal w z qs).side=.even → + sourceHeight (terminal w z qs).cutoff+10*Delta < (terminal w z qs).gap at hbad + push Not at hbad + obtain ⟨qs,hqs,hne,hi,hfail⟩ := hbad + obtain ⟨tail,htail⟩ := (List.mem_inits _ _).mp hqs + have ha : admitted w z.side z.gap qs := + ((admitted_append w z.gap z.side qs tail).mp (by simpa only [htail] using (Finset.mem_filter.mp hps).2)).1 + have hgate := admitted_even_endpoint w z qs ha hne hi + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hps).1 + have hlast : qs.getLastD 0 ∈ qs := by + have he : qs.getLastD 0=qs.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hne + have hlastPS : qs.getLastD 0 ∈ ps := by rw [← htail]; exact List.mem_append.mpr (Or.inl hlast) + have hprime := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop _).mp (hd.2 _ hlastPS) + have hx : 1 < primeExponent w (qs.getLastD 0) := + (one_lt_div (Real.log_pos hw)).mpr (Real.log_lt_log (zero_lt_one.trans hw) hprime.2.1) + rw [← terminal_lastD w z qs hne] at hx + exact ⟨qs,tail,htail.symm,hne,hi,hx,by linarith,by linarith⟩ +end NumberTheoryLean.ReferenceClearanceFailure + + + +namespace NumberTheoryLean.SourceThresholdRate +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualCoupledHistories SourceSelectedCompactOccupation SourceThresholdCoupling ThresholdMeshRate +open SourceCouplingRate ExponentialMesh TwoSidedThresholdKernel LowStateHorizon + + +theorem source_prime_threshold_probability : ∃ κ₀ : ℝ,0 < κ₀ ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ D eps : ℝ,0 < D → 0 < eps → + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ, + ∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ D*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.gap ≤ (23/10:ℝ)*B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + ∀ delta : ℝ,0 ≤ delta → delta ≤ 1 → + fullSourceLaw w ell S start hs (mesh κ w) N {h | primeThresholdOccurs delta N h} ≤ + ENNReal.ofReal ((8/3:ℝ)*thickConstant*delta+eps) := by + have hCpos : 0 < thickConstant := thickConstant_pos + obtain ⟨κ₀,hκ₀,hCouple⟩ := source_coupling_rate + refine ⟨κ₀,hκ₀,?_⟩ + intro κ hκ hκle D eps hD heps + obtain ⟨WC,hWC,hC⟩ := hCouple κ hκ hκle D hD + have hA : 0 ≤ 5*D^3 := by positivity + have hEvents := (threshold_mesh_controls hA thickConstant_pos.le hκ (show 0 < eps/2 by positivity)).and + (((log_power_exp_tendsto 1 0 (show 0 < κ/2 by positivity)).eventually + (eventually_le_nhds (show 0 < eps/2 by positivity))).and + (Real.tendsto_log_atTop.eventually_ge_atTop (D^2))) + obtain ⟨W,hW⟩ := eventually_atTop.mp hEvents + refine ⟨max WC (max normalizationThreshold W),hWC.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell hB hlogB hcomp hr hs23 hc hsize + dsimp only + intro delta hd0 hd1 + have hwC : WC ≤ w := (le_max_left _ _).trans hw + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hwe := hW w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw) + have hscale := UniformBudgetRate.source_scale_bound hwe.2.2 hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hcontrols := hwe.1 (sourceHorizon ((Real.log B)^2) B) hscale.2 + have hf := (hC w hwC ell B start hs hell hB hlogB hcomp hr hs23 hc hsize).1 + (sourceHorizon ((Real.log B)^2) B) le_rfl |>.1 + have hfail : Real.exp (-(κ/2)*Real.sqrt (Real.log w)) ≤ eps/2 := by + simpa only [pow_zero,mul_one,one_mul] using hwe.2.1 + have hprob := source_threshold_probability hnorm hell hS0 hscale.1 hr hs hsS hc + (mesh_pos κ w) (mesh_le_one hκ.le w) hd0 hd1 (sourceHorizon ((Real.log B)^2) B) hcontrols.1 + rw [← fullSourceLaw_eq hnorm hell hS0 hscale.1 hr hs hsS] at hprob + have he : thickConstant*((8/3:ℝ)*delta+((sourceHorizon ((Real.log B)^2) B:ℝ)+1)* + thresholdPerturbation (mesh κ w) (sourceHorizon ((Real.log B)^2) B)) ≤ + (8/3:ℝ)*thickConstant*delta+eps/2 := by nlinarith [hcontrols.2] + calc + _ ≤ _ := hprob + _ ≤ ENNReal.ofReal (eps/2)+ENNReal.ofReal ((8/3:ℝ)*thickConstant*delta+eps/2) := + add_le_add (hf.trans (ENNReal.ofReal_le_ofReal hfail)) (ENNReal.ofReal_le_ofReal he) + _ = _ := by + rw [← ENNReal.ofReal_add (by positivity : 0 ≤ eps/2) + (by positivity : 0 ≤ (8/3:ℝ)*thickConstant*delta+eps/2)] + congr 1 + ring +end NumberTheoryLean.SourceThresholdRate + + + +namespace NumberTheoryLean.WeightedNearThreshold +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership ActualPrimeHigh +open SourceSelectedCompactOccupation CompactPrefixOccurrence PrimePrefixRecovery NearPrefixOccurrence +open SourceThresholdRate UncappedCompactEvent TwoSidedThresholdKernel ExponentialMesh +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem weighted_near_threshold_prefix_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) : + ∃ C : ℝ,0 < C ∧ ∀ eps : ℝ,0 < eps → ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ ell : ℝ,∀ start : Node,∀ _hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → Real.log B ≤ D*Real.log w → + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → Consistent start → start.cutoff=B → + ∀ delta : ℝ,0 ≤ delta → delta ≤ 1 → ∀ E : Set (List ℕ), + (∀ ps ∈ uncappedPrefixes w ell start,ps ∈ E → + (terminal w start ps).gap ≤ R ∧ hasNearThresholdPrefix w delta start ps) → + B^2*(∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ C*delta+eps := by + obtain ⟨cR,WC,hcR,hWC,hCompact⟩ := uncapped_compact_event R hR D hD + obtain ⟨κ,hκ,hProb⟩ := source_prime_threshold_probability + have hCT : 0 < thickConstant := thickConstant_pos + refine ⟨cR*((8/3:ℝ)*thickConstant),by positivity,?_⟩ + intro eps heps + let eta := eps/(2*cR) + have heta : 0 < eta := by dsimp [eta]; positivity + obtain ⟨WP,hWP,hP⟩ := hProb κ hκ le_rfl D eta hD heta + obtain ⟨BC,hBC,hCbound⟩ := hCompact (3:ℝ) + let w₀ := max WC (max WP (max normalizationThreshold (Real.exp (D^2)))) + refine ⟨max BC (max (Real.exp 2) (2/eps)),w₀,hBC.trans_le (le_max_left _ _), + hWC.trans_le (le_max_left _ _),?_⟩ + intro B w hBB hw ell start hs hell hellB hcomp hi h199 h23 hc hcut delta hd0 hd1 E hE + have hB : 0 < B := hBC.trans_le ((le_max_left _ _).trans hBB) + have hExpB : Real.exp 2 ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hBB + have hlogB : 2 ≤ Real.log B := (Real.le_log_iff_exp_le hB).mpr hExpB + have hwC : WC ≤ w := (le_max_left _ _).trans hw + have hwP : WP ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hnorm : normalizationThreshold ≤ w := + (le_trans (le_max_left _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hw + have hw1 : 1 < w := normalizationThreshold_gt_one.trans_le hnorm + have hExpW : Real.exp (D^2) ≤ w := + (le_trans (le_max_right _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hw + have hlogw : D^2 ≤ Real.log w := (Real.le_log_iff_exp_le (zero_lt_one.trans hw1)).mpr hExpW + have hscale := UniformBudgetRate.source_scale_bound hlogw hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hrnode := SourceNodeCoordinates.source_node_bounds hB start hi h199 h23 hc hcut + have hHist : ∀ p : History w ell ((Real.log B)^2) start,p.primes ∈ E → + hasNearThresholdPrefix w delta start p.primes := by + intro p hp + have hu : p.primes ∈ uncappedPrefixes w ell start := + (mem_uncappedPrefixes hw1 start p.primes).mpr + ((uncapped_iff_exists_ceiling w ell start p.primes).mpr ⟨(Real.log B)^2,hsS,p.admissible⟩) + exact (hE p.primes hu hp).2 + have hOcc := near_prefix_occurrence_probability hnorm hell hS0 hscale.1 hrnode.2.1 hs hsS + (mesh κ w) delta (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) E hHist + have hProbability := hOcc.trans (hP w hwP ell B start hs hell hB hlogB hcomp hrnode.2.1 h23 hc hrnode.2.2.2 delta hd0 hd1) + have hpr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hProbability + rw [ENNReal.toReal_ofReal (show 0 ≤ (8/3:ℝ)*thickConstant*delta+eta by positivity)] at hpr + have hMass := hCbound B w ((le_max_left _ _).trans hBB) hwC ell start hs hell hellB hcomp + hi h199 h23 hc hcut (mesh κ w) E (fun ps hp hsel => (hE ps hp hsel).1) + have hMass' : (∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ + (cR/B^2)*((8/3:ℝ)*thickConstant*delta+eta)+B^(-(3:ℝ)) := + hMass.trans (add_le_add (mul_le_mul_of_nonneg_left hpr (show 0 ≤ cR/B^2 by positivity)) le_rfl) + have hlarge : 2/eps ≤ B := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hBB + have hinv : 1/B ≤ eps/2 := by + have hh := (div_le_iff₀ heps).mp hlarge + apply (div_le_iff₀ hB).mpr + nlinarith + have hcEta : cR*eta=eps/2 := by dsimp [eta]; field_simp [hcR.ne'] + have hpow : B^(-(3:ℝ))=(B^3)⁻¹ := by rw [Real.rpow_neg hB.le,Real.rpow_ofNat] + calc + _ ≤ B^2*((cR/B^2)*((8/3:ℝ)*thickConstant*delta+eta)+B^(-(3:ℝ))) := + mul_le_mul_of_nonneg_left hMass' (sq_nonneg B) + _ = cR*((8/3:ℝ)*thickConstant)*delta+cR*eta+1/B := by rw [hpow]; field_simp [hB.ne'] + _ ≤ _ := by rw [hcEta]; linarith +end NumberTheoryLean.WeightedNearThreshold + + + +namespace NumberTheoryLean.ReferenceClearanceMass +open _root_.Set _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open ReferenceAdmission ActualPrefixClearance ReferenceClearanceFailure WeightedNearThreshold +open StrongReferenceTransport StrongSourceFamilies LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem uniform_reference_clearance_failure_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) : + ∃ C : ℝ,0 < C ∧ ∀ eps : ℝ,0 < eps → ∃ B₀ w₀ : ℝ,3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → w < top → Real.log B ≤ D*Real.log w → + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ Delta : ℝ,0 ≤ Delta → 10*Delta ≤ 1 → ∀ F : Finset (List ℕ), + F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps ∈ F,(terminal w z ps).gap ≤ R ∧ ¬actualClearance w z Delta ps) → + B^2*(∑ ps ∈ F,prefixWeight ps) ≤ C*Delta+eps := by + obtain ⟨c,hc,hMass⟩ := weighted_near_threshold_prefix_mass R hR D hD + refine ⟨10*c,by positivity,?_⟩ + intro eps heps + obtain ⟨BC,w₀,_hBC,hw₀,hBound⟩ := hMass eps heps + refine ⟨max BC 3,w₀,le_max_right _ _,hw₀,?_⟩ + intro B w top hB hw htop hcomp z hi h199 h23 hz hcut hclosed hcap Delta hDel hsmall F hF hBad + have hB3 : 3 ≤ B := (le_max_right _ _).trans hB + have hw1 : 1 < w := hw₀.trans_le hw + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB3 z hi h199 hz hcut + have hcap' : w^z.cutoff=top := by rwa [hcut] + have hsub : F ⊆ uncappedPrefixes w 1 z := + fun ps hp => (source_reference_transport hw1 htop z hs hz hg hclosed hcap' ps (hF hp)).1 + have he : (uncappedPrefixes w 1 z).filter (fun ps => ps ∈ (F : Set (List ℕ)))=F := by + ext ps + simp only [Finset.mem_filter,Finset.mem_coe] + exact ⟨And.right,fun hp => ⟨hsub hp,hp⟩⟩ + have hSelected := hBound B w ((le_max_left _ _).trans hB) hw 1 z hs (by norm_num) (by linarith) + hcomp hi h199 h23 hz hcut (10*Delta) (by positivity) hsmall (F : Set (List ℕ)) + (fun ps _hp hps => ⟨(hBad ps hps).1,reference_clearance_failure_prefix hw1 htop z ps (hF hps) (hBad ps hps).2⟩) + have hSelected' : B^2*(∑ ps ∈ F,prefixWeight ps) ≤ c*(10*Delta)+eps := by + convert! hSelected using 1 + congr 1 + apply Finset.sum_congr + · ext ps + simp only [Finset.mem_filter,Finset.mem_coe] + exact ⟨fun hp => ⟨hsub hp,hp⟩,And.right⟩ + · intro ps _ + rfl + nlinarith +end NumberTheoryLean.ReferenceClearanceMass + + + +namespace NumberTheoryLean.ReferenceRepeatedExclusion +open _root_.Set _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open ReferenceAdmission RepeatedWordEvents WeightedRepeatedWords +open StrongReferenceTransport StrongSourceFamilies LogarithmicBinPartition +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem uniform_reference_repeated_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) + (L : ℝ) (hL : 0 ≤ L) (eps : ℝ) (heps : 0 < eps) : + ∃ B₀ w₀ : ℝ,3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ hw : 1 < w,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → Real.log B ≤ D*Real.log w → + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ F : Finset (List ℕ),F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps ∈ F,(terminal w z ps).gap ≤ R ∧ (searchRepeatedWord hw htop hxi ps ∨ + compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L z ps)) → + B^2*(∑ ps ∈ F,prefixWeight ps) ≤ eps := by + obtain ⟨BC,WC,hBC,hWC,hBound⟩ := weighted_repeated_word_mass R hR D hD L hL eps heps + refine ⟨max BC 3,WC,le_max_right _ _,hWC,?_⟩ + intro B w top hB hw₀ hw htop xi hxi hxi1 hcomp z hi h199 h23 hz hcut hclosed hcap F hF hBad + have hB3 : 3 ≤ B := (le_max_right _ _).trans hB + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB3 z hi h199 hz hcut + have hcap' : w^z.cutoff=top := by rwa [hcut] + have hsub : F ⊆ uncappedPrefixes w 1 z := + fun ps hp => (source_reference_transport hw htop z hs hz hg hclosed hcap' ps (hF hp)).1 + obtain ⟨hw',hSel⟩ := hBound B w ((le_max_left _ _).trans hB) hw₀ top htop xi hxi hxi1 + have hSelected := hSel 1 z hs (by norm_num) (by linarith) hcomp hi h199 h23 hz hcut hcap' + (F : Set (List ℕ)) (fun ps _hp hps => hBad ps hps) + convert! hSelected using 1 + congr 1 + apply Finset.sum_congr + · ext ps + simp only [Finset.mem_filter,Finset.mem_coe] + exact ⟨fun hp => ⟨hsub hp,hp⟩,And.right⟩ + · intro ps _ + rfl +end NumberTheoryLean.ReferenceRepeatedExclusion + + + +namespace NumberTheoryLean.BasicRegularMass +open FinitePathGeometry PrimeHistories ActualRegularBoxes ActualPrefixClearance RepeatedWordEvents +open ReferenceAdmission RegularityDefectPartition ReferenceRepeatedExclusion ReferenceClearanceMass SourceLengthExclusion +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem basic_regular_defect_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) : + ∃ L C : ℝ,1 ≤ L ∧ 0 < C ∧ ∀ Clen : ℝ,L ≤ Clen → ∀ eps : ℝ,0 < eps → + ∃ B₀ w₀ : ℝ,3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ hw : 1 < w,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → 20*Clen*xi ≤ 1 → Real.log B ≤ D*Real.log w → + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + PrimeBinMembership.Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ F : Finset (List ℕ),F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps ∈ F,(terminal w z ps).gap ≤ R) → + B^2*(∑ ps ∈ F \ regularWords hw htop hxi Clen B R z,prefixWeight ps) ≤ C*(2*Clen*xi)+eps := by + obtain ⟨L,BL,WL,hL,hBL,hWL,hLen⟩ := uniform_source_length_exclusion (3:ℝ) + obtain ⟨C,hC,hClear⟩ := uniform_reference_clearance_failure_mass R hR D hD + refine ⟨L,C,hL,hC,?_⟩ + intro Clen hClen eps heps + have hClen0 : 0 ≤ Clen := (by linarith : 0 ≤ L).trans hClen + have he : 0 < eps/3 := by positivity + obtain ⟨BC,WC,hBC,hWC,hClear⟩ := hClear (eps/3) he + obtain ⟨BR,WR,hBR,hWR,hRepeat⟩ := uniform_reference_repeated_mass R hR D hD 0 (by norm_num) (eps/3) he + refine ⟨max BL (max BC (max BR (3/eps))),max WL (max WC WR), + hBC.trans (le_trans (le_max_left _ _) (le_max_right _ _)),hWL.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw₀ hw htop xi hxi hxi1 hsmall hcomp z hi h199 h23 hz hcut hclosed hcap F hF hg + have hBlen : BL ≤ B := (le_max_left _ _).trans hB + have hBclear : BC ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hB + have hBrep : BR ≤ B := (le_trans (le_max_left _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hB + have hBsize : 3/eps ≤ B := (le_trans (le_max_right _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hB + have hBp : 0 < B := (by linarith : 0 < BL).trans_le hBlen + have hwlen : WL ≤ w := (le_max_left _ _).trans hw₀ + have hwclear : WC ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw₀ + have hwrep : WR ≤ w := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hw₀ + have hlong := hLen B w top hBlen hwlen hcap Clen hClen (F.filter (lengthFailure Clen B)) + (fun ps hp => (Finset.mem_filter.mp (hF (Finset.mem_filter.mp hp).1)).1) + (fun ps hp => (Finset.mem_filter.mp hp).2) + have hclear := hClear B w top hBclear hwclear htop hcomp z hi h199 h23 hz hcut hclosed hcap + (2*Clen*xi) (by positivity) (by nlinarith) (F.filter (clearanceFailure w (2*Clen*xi) z)) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) + (fun ps hp => ⟨hg ps (Finset.mem_filter.mp hp).1,(Finset.mem_filter.mp hp).2⟩) + have hrepeat := hRepeat B w top hBrep hwrep hw htop xi hxi hxi1 hcomp z hi h199 h23 hz hcut hclosed hcap + (F.filter (searchRepeatedWord hw htop hxi)) (fun ps hp => hF (Finset.mem_filter.mp hp).1) + (fun ps hp => ⟨hg ps (Finset.mem_filter.mp hp).1,Or.inl (Finset.mem_filter.mp hp).2⟩) + have hinv : 1/B ≤ eps/3 := by + have hh := (div_le_iff₀ heps).mp hBsize + apply (div_le_iff₀ hBp).mpr + nlinarith + have hpow : B^2*B^(-(3:ℝ))=1/B := by + rw [Real.rpow_neg hBp.le,Real.rpow_ofNat] + field_simp [hBp.ne'] + have hlong' : B^2*(∑ ps ∈ F.filter (lengthFailure Clen B),prefixWeight ps) ≤ eps/3 := + (mul_le_mul_of_nonneg_left hlong (sq_nonneg B)).trans (hpow.le.trans hinv) + have hpart := mul_le_mul_of_nonneg_left (regularity_defect_sum (C:=Clen) (B:=B) hw htop hxi z F hF hg) (sq_nonneg B) + nlinarith +end NumberTheoryLean.BasicRegularMass + + + +namespace NumberTheoryLean.ReferenceIsolatedExclusion +open _root_.Set _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open ReferenceAdmission NonisolatedWordOccurrence WeightedIsolatedWords +open StrongReferenceTransport StrongSourceFamilies LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem uniform_reference_nonisolated_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) + (theta : ℝ) (htheta : 0 < theta) (htheta1 : theta ≤ 1/2) (eps : ℝ) (heps : 0 < eps) : + ∃ alpha B₀ w₀ : ℝ,0 < alpha ∧ alpha ≤ theta ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ hw : 1 < w,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → Real.log B ≤ D*Real.log w → + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ F : Finset (List ℕ),F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps ∈ F,(terminal w z ps).gap ≤ R ∧ noIsolatedWord hw htop hxi B alpha (4*theta) ps) → + B^2*(∑ ps ∈ F,prefixWeight ps) ≤ eps := by + obtain ⟨alpha,BC,WC,ha,hath,hBC,hWC,hBound⟩ := weighted_nonisolated_mass R hR D hD theta htheta htheta1 eps heps + refine ⟨alpha,max BC 3,WC,ha,hath,le_max_right _ _,hWC,?_⟩ + intro B w top hB hw₀ hw htop xi hxi hxi1 hcomp z hi h199 h23 hz hcut hclosed hcap F hF hBad + have hB3 : 3 ≤ B := (le_max_right _ _).trans hB + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB3 z hi h199 hz hcut + have hcap' : w^z.cutoff=top := by rwa [hcut] + have hsub : F ⊆ uncappedPrefixes w 1 z := + fun ps hp => (source_reference_transport hw htop z hs hz hg hclosed hcap' ps (hF hp)).1 + have hSelected := hBound B w ((le_max_left _ _).trans hB) hw₀ hw top htop xi hxi hxi1 + 1 z hs (by norm_num) (by linarith) hcomp hi h199 h23 hz hcut hcap' + (F : Set (List ℕ)) (fun ps _hp hps => hBad ps hps) + convert! hSelected using 1 + congr 1 + apply Finset.sum_congr + · ext ps + simp only [Finset.mem_filter,Finset.mem_coe] + exact ⟨fun hp => ⟨hsub hp,hp⟩,And.right⟩ + · intro ps _ + rfl +end NumberTheoryLean.ReferenceIsolatedExclusion + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceLocalResidual.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceLocalResidual.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a23984f87e276f16537b51a84552b8f0902ce69 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceLocalResidual.lean @@ -0,0 +1,102 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.WeightedAnomalyConvergence +import OAI.NumberTheory.Jacobsthal.Sieve.ReferenceEulerRecurrence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceLocalResidual + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeTiltGeometry ReferenceAdmission ReferencePruning +open ReferenceSourcePrimeSets ReferenceEulerRecurrence ReferenceMertens ReferenceDifferentiation +open ReferenceBenchmarkDecay ReferenceCancellation BoundaryAnomaly +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def nodeBenchmark (w : ℝ) (z : Node) : ℝ := + referenceProduct w z.cutoff z.closed*parentBenchmark z.side z.ratio + +noncomputable def sourceResidual (w : ℝ) (z : Node) : ℝ := + referenceProduct w 2 true*(benchmark z.side (z.gap/2)-1)- + referenceProduct w z.cutoff z.closed*(parentBenchmark z.side z.ratio-1)- + ∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹*referenceProduct w (primeExponent w p) false* + (benchmark z.side.flip (childRatio w z.gap p)-1) + +noncomputable def sourceInsertion (w : ℝ) (z : Node) : ℝ := + referencePolynomial w (boundaryPrimes w) z.side z.gap-nodeBenchmark w z- + ∑ p ∈ highPrimes w z.cutoff z.closed,if childAdmitted z.side z.gap (primeExponent w p) then + (p:ℝ)⁻¹*nodeBenchmark w (step w z p) else 0 + +theorem admitted_child_benchmark {w : ℝ} (hw : 1 < w) (z : Node) {p : ℕ} + (hp : p ∈ highPrimes w z.cutoff z.closed) (ha : childAdmitted z.side z.gap (primeExponent w p)) : + nodeBenchmark w (step w z p)=referenceProduct w (primeExponent w p) false* + benchmark z.side.flip (childRatio w z.gap p) := by + have hxp := (highPrimes_membership hw z.cutoff z.closed p).mp hp |>.2.1 + unfold nodeBenchmark + simp only [step] + congr 1 + cases hi : z.side with + | even => rfl + | odd => + have hh : 2*primeExponent w p ≤ z.gap-primeExponent w p := by + rw [hi] at ha + exact (upper_admission_above_two hxp.le).mp ha + have hc : 2 ≤ childRatio w z.gap p := by + unfold childRatio + have hd : 3 ≤ z.gap/primeExponent w p := (le_div_iff₀ (by linarith)).mpr (by linarith) + linarith + exact parent_even_eq_ordinary hc + +theorem omitted_child_benchmark {w : ℝ} (hw : 1 < w) (z : Node) {p : ℕ} + (hp : p ∈ highPrimes w z.cutoff z.closed) (ha : ¬childAdmitted z.side z.gap (primeExponent w p)) : + benchmark z.side.flip (childRatio w z.gap p)=0 := by + have hxp := (highPrimes_membership hw z.cutoff z.closed p).mp hp |>.2.1 + cases hi : z.side with + | even => exact False.elim (ha (by rw [hi]; trivial)) + | odd => + have hh := actual_omitted_deviation_above_two hxp.le (by rwa [hi] at ha) + change benchmark .even (z.gap/primeExponent w p-1)=0 + linarith + +theorem admitted_benchmark_sum {w : ℝ} (hw : 1 < w) (z : Node) : + (∑ p ∈ highPrimes w z.cutoff z.closed,if childAdmitted z.side z.gap (primeExponent w p) then + (p:ℝ)⁻¹*nodeBenchmark w (step w z p) else 0)= + ∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹*referenceProduct w (primeExponent w p) false* + benchmark z.side.flip (childRatio w z.gap p) := by + apply Finset.sum_congr rfl + intro p hp + by_cases ha : childAdmitted z.side z.gap (primeExponent w p) + · rw [ite_eq_left ha,admitted_child_benchmark hw z hp ha] + ring + · rw [ite_eq_right ha,omitted_child_benchmark hw z hp ha,mul_zero] + +theorem source_insertion_identity {w : ℝ} (hw : 1 < w) (z : Node) (hb : 2 < z.cutoff) : + sourceInsertion w z=anomaly w z.side z.gap+sourceResidual w z := by + have hp := actual_product_cutoff_identity hw hb z.closed + have hsum : (∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹*referenceProduct w (primeExponent w p) false* + (benchmark z.side.flip (childRatio w z.gap p)-1))= + (∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹*referenceProduct w (primeExponent w p) false* + benchmark z.side.flip (childRatio w z.gap p))- + ∑ p ∈ highPrimes w z.cutoff z.closed,(p:ℝ)⁻¹*referenceProduct w (primeExponent w p) false := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro p _hp + ring + have hbase : survivorProduct (boundaryPrimes w)=referenceProduct w 2 true := by + rw [referenceProduct_eq_survivor,sourcePrimes_boundary] + unfold sourceInsertion sourceResidual anomaly + rw [admitted_benchmark_sum hw z,hsum,hbase] + unfold nodeBenchmark + linarith + +end NumberTheoryLean.ReferenceLocalResidual + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceProductErrors.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceProductErrors.lean new file mode 100644 index 0000000000000000000000000000000000000000..b45ee1d7e6ef3aa93b244369c73cfa4d785e2fae --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceProductErrors.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.Jacobsthal.Primes.ReferenceSourcePrimeSets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceProductErrors + +open _root_.Filter _root_.Erdos970.Filter +open scoped Topology +open ReferenceProductsBasics ReferenceMertens + +theorem normalization_eventually_bounded : ∀ᶠ w : ℝ in atTop,1/2 ≤ normalization w ∧ normalization w ≤ 2 := by + have h := normalization_tendsto_one.eventually + (Ioo_mem_nhds (by norm_num : (1/2:ℝ)<1) (by norm_num : (1:ℝ)<2)) + filter_upwards [h] with w hw + exact ⟨hw.1.le,hw.2.le⟩ + +theorem reference_product_absolute : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → 1/2 ≤ normalization w ∧ normalization w ≤ 2 ∧ + ∀ b : ℝ,2 ≤ b → ∀ closed : Bool, + |referenceProduct w b closed-normalization w/b| ≤ + (C/b)*Real.exp (-c*Real.sqrt (b*Real.log w)) := by + obtain ⟨c,C,wM,hc,hC,hwM,h⟩ := reference_product_strong + obtain ⟨wN,hwN⟩ := eventually_atTop.mp normalization_eventually_bounded + refine ⟨c,2*C,max wM wN,hc,by positivity,hwM.trans_le (le_max_left _ _),?_⟩ + intro w hw + have hwm : wM ≤ w := (le_max_left _ _).trans hw + have hwn := hwN w ((le_max_right _ _).trans hw) + refine ⟨hwn.1,hwn.2,?_⟩ + intro b hb closed + have hw1 : 1 < w := hwM.trans_le hwm + have hb0 : 0 < b := by linarith + have hD : 0 < normalization w/b := div_pos (normalization_pos hw1) hb0 + have hh := h w hwm b hb closed + rw [div_sub_one (ne_of_gt hD),abs_div,abs_of_pos hD] at hh + have hm := (div_le_iff₀ hD).mp hh + calc + _ ≤ (C*Real.exp (-c*Real.sqrt (b*Real.log w)))*(normalization w/b) := hm + _ ≤ (C*Real.exp (-c*Real.sqrt (b*Real.log w)))*(2/b) := + mul_le_mul_of_nonneg_left (div_le_div_of_nonneg_right hwn.2 hb0.le) (by positivity) + _ = _ := by ring + +end NumberTheoryLean.ReferenceProductErrors + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceProductsBasics.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceProductsBasics.lean new file mode 100644 index 0000000000000000000000000000000000000000..de81aabac3afd4e0952823511c593f8db0f7de06 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceProductsBasics.lean @@ -0,0 +1,279 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.OmissionPartition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open scoped BigOperators +namespace NumberTheoryLean.ReferencePruning +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +noncomputable def signedWeight (ps : List ℕ) : ℝ := (-1 : ℝ)^ps.length*prefixWeight ps +noncomputable def survivorProduct (P : Finset ℕ) : ℝ := ∏ p ∈ P,(1-(p : ℝ)⁻¹) + +theorem signedWeight_append (pre suf : List ℕ) : signedWeight (pre++suf) = signedWeight pre*signedWeight suf := by + unfold signedWeight prefixWeight + rw [List.length_append,pow_add,List.map_append,List.prod_append] + ring + +theorem sum_signedWeight (P : Finset ℕ) : + (∑ ps ∈ decreasingPrefixes P,signedWeight ps) = survivorProduct P := by + have h := sum_sorted_products P (fun p : ℕ => (-1 : ℝ)*(p : ℝ)⁻¹) + simp_rw [VariablePrimeTilt.variable_tilt_weight] at h + simpa only [signedWeight,survivorProduct,neg_one_mul,sub_eq_add_neg] using h + +theorem sum_completion_signedWeight (P : Finset ℕ) (pre : List ℕ) : + (∑ ps ∈ completions P pre,signedWeight ps) = signedWeight pre*survivorProduct (suffixPrimes P pre) := by + unfold completions + rw [Finset.sum_image] + · simp_rw [signedWeight_append] + rw [← Finset.mul_sum,sum_signedWeight] + · intro a _ b _ h + exact List.append_cancel_left h + +end NumberTheoryLean.ReferencePruning + +end + +section + +open scoped BigOperators +namespace NumberTheoryLean.ReferencePruning +attribute [local instance] Classical.propDecidable +open FinitePathGeometry ReferenceAdmission ErdosPrimeInputs.PrimePrefixMass + +theorem product_minus_reference (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : + survivorProduct P-referencePolynomial w P i r = + ∑ ps ∈ rejectedPrefixes w P i r,signedWeight ps := by + have h := Finset.sum_filter_add_sum_filter_not (decreasingPrefixes P) (admitted w i r) signedWeight + rw [sum_signedWeight] at h + have he : referencePolynomial w P i r + (∑ ps ∈ rejectedPrefixes w P i r,signedWeight ps) = + survivorProduct P := by + simpa only [referencePolynomial,referencePrefixes,rejectedPrefixes,signedWeight] using h + linarith only [he] + +theorem pruning_identity (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : + survivorProduct P-referencePolynomial w P i r = + ∑ pre ∈ firstOmissions w P i r,signedWeight pre*survivorProduct (suffixPrimes P pre) := by + rw [product_minus_reference,rejected_eq_omission_completions, + Finset.sum_biUnion (omission_completions_disjoint w P i r)] + exact Finset.sum_congr rfl (fun pre _ => sum_completion_signedWeight P pre) + +noncomputable def belowLast (P : Finset ℕ) (pre : List ℕ) : Finset ℕ := + P.filter (fun q => q < pre.getLastD 0) + +theorem suffixPrimes_eq_belowLast {w r : ℝ} {P : Finset ℕ} {i : Side} {ps : List ℕ} + (hp : ps ∈ firstOmissions w P i r) : suffixPrimes P ps = belowLast P ps := by + obtain ⟨hD,hfirst⟩ := Finset.mem_filter.mp hp + obtain ⟨pre,p,he,_,_⟩ := hfirst + rw [he] at hD ⊢ + simpa only [belowLast,List.getLastD_concat] using suffixPrimes_append_singleton hD + +theorem pruning_identity_last (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : + (∏ p ∈ P,(1-(p : ℝ)⁻¹))-referencePolynomial w P i r = + ∑ ps ∈ firstOmissions w P i r,((-1 : ℝ)^ps.length*prefixWeight ps)* + ∏ q ∈ P.filter (fun q => q < ps.getLastD 0),(1-(q : ℝ)⁻¹) := by + rw [show (∏ p ∈ P,(1-(p : ℝ)⁻¹)) = survivorProduct P from rfl,pruning_identity] + apply Finset.sum_congr rfl + intro ps hp + rw [suffixPrimes_eq_belowLast hp] + rfl + +end NumberTheoryLean.ReferencePruning + +end + +section + +open scoped BigOperators +namespace NumberTheoryLean.ReferencePruning +open FinitePathGeometry ReferenceAdmission VariablePrimeTilt +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +theorem reciprocal_le_one {p : ℕ} (hp : 1 ≤ p) : (p : ℝ)⁻¹ ≤ 1 := by + have h : (1 : ℝ) ≤ p := by exact_mod_cast hp + simpa only [one_div,inv_one] using one_div_le_one_div_of_le (by norm_num : (0 : ℝ) < 1) h + +theorem survivorProduct_bounds (P : Finset ℕ) (hP : ∀ p ∈ P,1 ≤ p) : + 0 ≤ survivorProduct P ∧ survivorProduct P ≤ 1 := by + have h0 : ∀ p ∈ P,0 ≤ 1-(p : ℝ)⁻¹ := fun p hp => sub_nonneg.mpr (reciprocal_le_one (hP p hp)) + have h1 : ∀ p ∈ P,1-(p : ℝ)⁻¹ ≤ 1 := fun p _ => + sub_le_self _ (inv_nonneg.mpr (Nat.cast_nonneg p)) + exact ⟨Finset.prod_nonneg h0,Finset.prod_le_one₀ h0 h1⟩ + +theorem abs_signedWeight (ps : List ℕ) : |signedWeight ps| = prefixWeight ps := by + simp only [signedWeight,abs_mul,abs_pow,abs_neg,abs_one,one_pow,one_mul, + abs_of_nonneg (prefixWeight_nonneg ps)] + +theorem pruning_discrepancy_bound (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) + (hP : ∀ p ∈ P,1 ≤ p) : + |referencePolynomial w P i r-survivorProduct P| ≤ + ∑ ps ∈ firstOmissions w P i r,prefixWeight ps := by + rw [abs_sub_comm,pruning_identity] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro pre _hpre + have hprod := survivorProduct_bounds (suffixPrimes P pre) + (fun p hp => hP p (Finset.mem_filter.mp hp).1) + rw [abs_mul,abs_signedWeight,abs_of_nonneg hprod.1] + simpa only [mul_one] using mul_le_mul_of_nonneg_left hprod.2 (prefixWeight_nonneg pre) + +theorem boundary_reference_discrepancy (w r : ℝ) (i : Side) : + |referencePolynomial w (boundaryPrimes w) i r- + (∏ p ∈ boundaryPrimes w,(1-(p : ℝ)⁻¹))| ≤ omissionMass w r i := by + apply pruning_discrepancy_bound w (boundaryPrimes w) i r + intro p hp + obtain ⟨hpp,_⟩ := Finset.mem_filter.mp hp + exact le_trans (by norm_num : 1 ≤ 2) (Nat.mem_primesLE.mp hpp).2.two_le + +end NumberTheoryLean.ReferencePruning + +end + +section + +namespace NumberTheoryLean.ReferenceProductsBasics + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open ReferencePruning ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.MertensStrong + +noncomputable def availablePrimes (a x : ℝ) (closed : Bool) : Finset ℕ := + (primesBetween a x).filter (fun p => closed=true ∨ (p:ℝ) prime_factor_pos (Nat.mem_primesLE.mp hp).2) + +theorem availableProduct_pos (a x : ℝ) (closed : Bool) : 0 < availableProduct a x closed := by + unfold availableProduct survivorProduct + apply Finset.prod_pos + intro p hp + exact prime_factor_pos (Nat.mem_primesLE.mp (Finset.mem_filter.mp (Finset.mem_filter.mp hp).1).1).2 + +theorem primesBetween_eq_sdiff {a x : ℝ} (ha : 0 ≤ a) : + primesBetween a x=Nat.primesLE ⌊x⌋₊ \ Nat.primesLE ⌊a⌋₊ := by + ext p + simp only [primesBetween,Finset.mem_filter,Finset.mem_sdiff,Nat.mem_primesLE] + constructor + · rintro ⟨⟨hpx,hp⟩,hap⟩ + refine ⟨⟨hpx,hp⟩,?_⟩ + intro hpa + have h : (p:ℝ) ≤ a := (Nat.le_floor_iff ha).mp hpa.1 + linarith + · rintro ⟨⟨hpx,hp⟩,hnot⟩ + refine ⟨⟨hpx,hp⟩,?_⟩ + by_contra hn + exact hnot ⟨(Nat.le_floor_iff ha).mpr (le_of_not_gt hn),hp⟩ + +theorem closed_product_ratio {a x : ℝ} (ha : 0 ≤ a) (hax : a ≤ x) : + availableProduct a x true=primeProduct x/primeProduct a := by + have hsub : Nat.primesLE ⌊a⌋₊ ⊆ Nat.primesLE ⌊x⌋₊ := by + intro p hp + obtain ⟨hpa,hp⟩ := Nat.mem_primesLE.mp hp + exact Nat.mem_primesLE.mpr ⟨hpa.trans (Nat.floor_mono hax),hp⟩ + apply (eq_div_iff (ne_of_gt (actual_primeProduct_pos a))).mpr + rw [availableProduct,availablePrimes_closed,primesBetween_eq_sdiff ha, + primeProduct_eq_survivor,primeProduct_eq_survivor] + exact Finset.prod_sdiff hsub + +theorem endpoint_card_le_one (P : Finset ℕ) (x : ℝ) : + (P.filter (fun p : ℕ => (p:ℝ)=x)).card ≤ 1 := by + apply Finset.card_le_one.mpr + intro p hp q hq + have he := (Finset.mem_filter.mp hp).2.trans (Finset.mem_filter.mp hq).2.symm + exact_mod_cast he + +theorem endpoint_product_factor {a x : ℝ} (hx : 0 ≤ x) : + availableProduct a x true = availableProduct a x false ∨ + availableProduct a x true = availableProduct a x false*(1-x⁻¹) := by + let P := primesBetween a x + have hpx : ∀ p ∈ P,(p:ℝ) ≤ x := by + intro p hp + exact (Nat.le_floor_iff hx).mp (Nat.mem_primesLE.mp (Finset.mem_filter.mp hp).1).1 + have hfilter : P.filter (fun p : ℕ => ¬(p:ℝ) (p:ℝ)=x) := by + ext p + simp only [Finset.mem_filter] + constructor + · rintro ⟨hp,hn⟩ + exact ⟨hp,le_antisymm (hpx p hp) (le_of_not_gt hn)⟩ + · rintro ⟨hp,he⟩ + exact ⟨hp,by rw [he]; exact lt_irrefl _⟩ + have hprod := Finset.prod_filter_mul_prod_filter_not P (fun p : ℕ => (p:ℝ) 1-(p:ℝ)⁻¹) + rw [hfilter] at hprod + have hbd : (∏ p ∈ P.filter (fun p : ℕ => (p:ℝ)=x),(1-(p:ℝ)⁻¹)) = + (1-x⁻¹)^(P.filter (fun p : ℕ => (p:ℝ)=x)).card := by + rw [← Finset.prod_const] + apply Finset.prod_congr rfl + intro p hp + rw [(Finset.mem_filter.mp hp).2] + rw [hbd] at hprod + have hopen : availableProduct a x false=survivorProduct (P.filter (fun p : ℕ => (p:ℝ) 4 ≤ r + | .odd, r => 2 ≤ r + +theorem child_boundary_domain {w ell : ℝ} {z : Node} {p : ℕ} (hell : 2 ≤ ell) + (heven : z.side=.even → 2 ≤ z.ratio) (hp : p ∈ uncappedChildren w ell z) : + BoundaryDomain (step w z p).side (step w z p).gap ∧ + ((step w z p).side=.even → 2 ≤ (step w z p).ratio) := by + obtain ⟨_hprime,hlo,_hcap,hmin⟩ := Finset.mem_filter.mp hp + have hx : 2 < primeExponent w p := hell.trans_lt hlo + have he : (step w z p).ratio*primeExponent w p=(step w z p).gap := by + dsimp only [step,childRatio] + field_simp [show primeExponent w p ≠ 0 by linarith] + cases hi : z.side with + | even => + have hs := heven hi + have hm : 1 ≤ (step w z p).ratio := by + change minRatio z.side z.ratio ≤ childRatio w z.gap p at hmin + rw [hi] at hmin + change z.ratio-1 ≤ (step w z p).ratio at hmin + linarith + have hside : (step w z p).side=.odd := by simp [step,hi,Side.flip] + rw [hside] + refine ⟨?_,by intro h; cases h⟩ + change 2 ≤ (step w z p).gap + nlinarith + | odd => + have hm : 2 ≤ (step w z p).ratio := by + change minRatio z.side z.ratio ≤ childRatio w z.gap p at hmin + rw [hi] at hmin + exact (le_max_left _ _).trans hmin + have hside : (step w z p).side=.even := by simp [step,hi,Side.flip] + rw [hside] + exact ⟨by change 4 ≤ (step w z p).gap; nlinarith,fun _ => hm⟩ + +theorem boundary_domain_preserved {w ell : ℝ} {z : Node} {ps : List ℕ} (hell : 2 ≤ ell) + (hdom : BoundaryDomain z.side z.gap) (heven : z.side=.even → 2 ≤ z.ratio) + (hp : uncappedAllowed w ell z ps) : + BoundaryDomain (terminal w z ps).side (terminal w z ps).gap := by + induction ps generalizing z with + | nil => exact hdom + | cons p ps ih => + obtain ⟨hc,ht⟩ := hp + obtain ⟨hd,he⟩ := child_boundary_domain hell heven hc + exact ih hd he ht + +theorem source_boundary_domain {B w ell : ℝ} (hB : 4 ≤ B) (hell : 2 ≤ ell) + (start : Node) (hi : start.side=.even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hc : Consistent start) (hcut : start.cutoff=B) {ps : List ℕ} + (hp : uncappedAllowed w ell start ps) : + BoundaryDomain (terminal w start ps).side (terminal w start ps).gap := by + obtain ⟨hs,_hr,hBgap,_hsize⟩ := source_node_bounds (by linarith : 0 < B) start hi h199 h23 hc hcut + have hgap := node_gap_eq hs hc hcut + cases ps with + | nil => simpa only [terminal_nil,hi,BoundaryDomain] using hB.trans hBgap + | cons p ps => + obtain ⟨hchild,htail⟩ := hp + obtain ⟨_hprime,_hlo,hcap,_hmin⟩ := Finset.mem_filter.mp hchild + have hxp : primeExponent w p ≤ B := by + change capGuard start.closed start.cutoff (primeExponent w p) at hcap + rw [hcut] at hcap + cases hcl : start.closed with + | false => + have h : primeExponent w p < B := by simpa [capGuard,hcl] using hcap + exact h.le + | true => simpa only [capGuard,hcl,ite_true] using hcap + have hside : (step w start p).side=.odd := by simp [step,hi,Side.flip] + have hdom : BoundaryDomain (step w start p).side (step w start p).gap := by + rw [hside] + change 2 ≤ start.gap-primeExponent w p + nlinarith + simpa only [terminal_cons] using boundary_domain_preserved (z := step w start p) hell hdom (by rw [hside]; intro h; cases h) htail + +theorem boundary_gap_ge_two {i : Side} {r : ℝ} (h : BoundaryDomain i r) : 2 ≤ r := by + cases i <;> simp only [BoundaryDomain] at h <;> linarith + +end NumberTheoryLean.ActualBoundaryDomain + +end + +section + +namespace NumberTheoryLean.UniformBoundaryCorrection + +attribute [local instance] Classical.propDecidable + +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open BoundaryAnomaly UniformExponentialOccupation ActualBoundaryDomain +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def boundaryCorrection (w ell : ℝ) (start : Node) : ℝ := + ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*((-1:ℝ)^ps.length* + anomaly w (terminal w start ps).side (terminal w start ps).gap) + +theorem uniform_boundary_correction (ell d : ℝ) (hell : 2 ≤ ell) (hd : 0 < d) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → B^2*|boundaryCorrection w ell start| ≤ C := by + obtain ⟨A,c,wA,hA,hc,hwA,hAnomaly⟩ := actual_boundary_anomaly_exponential + obtain ⟨CP,BP,wP,hCP,hBP,hwP,hOccupation⟩ := + uniform_signed_exponential_rewards ell c d (by linarith) hc hd + refine ⟨A*CP,max BP 4,max wP wA,mul_pos hA hCP,hBP.trans_le (le_max_left _ _), + hwP.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBP' : BP ≤ B := (le_max_left _ _).trans hB + have hB4 : 4 ≤ B := (le_max_right _ _).trans hB + have hwP' : wP ≤ w := (le_max_left _ _).trans hw + have hwA' : wA ≤ w := (le_max_right _ _).trans hw + apply hOccupation B w hBP' hwP' hcomp start hi h199 h23 hcons hcut A hA.le + (fun ps => (-1:ℝ)^ps.length*anomaly w (terminal w start ps).side (terminal w start ps).gap) + intro ps hp + have hpA : uncappedAllowed w ell start ps := (Finset.mem_filter.mp hp).2 + have hdom := source_boundary_domain hB4 hell start hi h199 h23 hcons hcut hpA + have hr2 := boundary_gap_ge_two hdom + rw [abs_mul,abs_pow,abs_neg,abs_one,one_pow,one_mul,positiveGapEnvelope,ite_eq_left hr2] + exact hAnomaly w hwA' _ hr2 _ + +theorem uniform_boundary_correction_div (ell d : ℝ) (hell : 2 ≤ ell) (hd : 0 < d) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → |boundaryCorrection w ell start| ≤ C/B^2 := by + obtain ⟨C,B₀,w₀,hC,hB₀,hw₀,h⟩ := uniform_boundary_correction ell d hell hd + refine ⟨C,B₀,w₀,hC,hB₀,hw₀,?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + apply (le_div_iff₀ (sq_pos_of_pos (hB₀.trans_le hB))).mpr + simpa only [mul_comm] using h B w hB hw hcomp start hi h199 h23 hcons hcut + +end NumberTheoryLean.UniformBoundaryCorrection + +end + +section + +namespace NumberTheoryLean.ReferenceSourceDecomposition + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open ReferenceAdmission ReferencePruning ReferenceWeightedRecurrence ReferenceForestTelescoping ReferenceCutoffRecurrence +open ReferenceSourcePrimeSets ReferenceEulerRecurrence ReferenceHistoryAdmission ReferenceLocalResidual +open BoundaryAnomaly UniformBoundaryCorrection +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def sourceReference (w : ℝ) (z : Node) : ℝ := + referencePolynomial w (sourcePrimes w z.cutoff z.closed) z.side z.gap + +noncomputable def residualCorrection (w : ℝ) (z : Node) : ℝ := + ∑ ps ∈ uncappedPrefixes w 2 z,prefixWeight ps*((-1:ℝ)^ps.length*sourceResidual w (terminal w z ps)) + +theorem suffix_highPrimes {w : ℝ} (hw : 1 < w) {z : Node} (hs : Valid z.side z.ratio) + (hr : 0 < z.gap) (hz : Consistent z) {ps : List ℕ} (hp : uncappedAllowed w 2 z ps) : + suffixPrimes (highPrimes w z.cutoff z.closed) ps= + highPrimes w (terminal w z ps).cutoff (terminal w z ps).closed := by + induction ps generalizing z with + | nil => simp only [suffixPrimes_nil,terminal_nil] + | cons p ps ih => + obtain ⟨hchild,htail⟩ := hp + have hpH := ((uncapped_child_iff hw hs hz p).mp hchild).1 + have hpS : p ∈ sourcePrimes w z.cutoff z.closed := (Finset.mem_filter.mp hpH).1 + obtain ⟨hvs,hrs,hzs⟩ := uncapped_child_invariants hs hr hchild + rw [suffixPrimes_cons,terminal_cons,← highPrimes_at_selected hw z.closed hpS] + exact ih (z := step w z p) hvs hrs hzs htail + +theorem uncapped_cutoff_gt_two {w : ℝ} {z : Node} (hb : 2 < z.cutoff) {ps : List ℕ} + (hp : uncappedAllowed w 2 z ps) : 2 < (terminal w z ps).cutoff := by + induction ps generalizing z with + | nil => exact hb + | cons p ps ih => + obtain ⟨hc,ht⟩ := hp + have hx : 2 < primeExponent w p := (Finset.mem_filter.mp hc).2.1 + exact ih hx ht + +theorem forest_insertion_eq_corrections {w : ℝ} (hw : 1 < w) {z : Node} (hs : Valid z.side z.ratio) + (hr : 0 < z.gap) (hz : Consistent z) (hb : 2 < z.cutoff) : + forestSum w (highPrimes w z.cutoff z.closed) z + (cutoffInsertion w (boundaryPrimes w) (fun _ y => nodeBenchmark w y))= + boundaryCorrection w 2 z+residualCorrection w z := by + unfold forestSum weightedValue boundaryCorrection residualCorrection + rw [reference_family_eq_uncapped hw hs hr hz,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro ps hp + have hpA : uncappedAllowed w 2 z ps := (Finset.mem_filter.mp hp).2 + have hsuf := suffix_highPrimes hw hs hr hz hpA + have hcap := uncapped_cutoff_gt_two hb hpA + dsimp only + rw [hsuf] + change signedWeight ps*sourceInsertion w (terminal w z ps)=_ + rw [source_insertion_identity hw _ hcap] + unfold signedWeight + ring + +theorem actual_reference_decomposition {w : ℝ} (hw : 1 < w) {z : Node} (hs : Valid z.side z.ratio) + (hr : 0 < z.gap) (hz : Consistent z) (hb : 2 < z.cutoff) : + sourceReference w z-nodeBenchmark w z=boundaryCorrection w 2 z+residualCorrection w z := by + have h := finite_cutoff_decomposition w (highPrimes_above_boundary (b:=z.cutoff) hw z.closed) + (fun _ y => nodeBenchmark w y) z + rw [← sourcePrimes_partition hw hb z.closed] at h + exact h.trans (forest_insertion_eq_corrections hw hs hr hz hb) + +theorem actual_reference_value {w : ℝ} (hw : 1 < w) {z : Node} (hs : Valid z.side z.ratio) + (hr : 0 < z.gap) (hz : Consistent z) (hb : 2 < z.cutoff) : + sourceReference w z=nodeBenchmark w z+boundaryCorrection w 2 z+residualCorrection w z := by + have h := actual_reference_decomposition hw hs hr hz hb + linarith + +end NumberTheoryLean.ReferenceSourceDecomposition + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceWeightedQuadrature.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceWeightedQuadrature.lean new file mode 100644 index 0000000000000000000000000000000000000000..e1c114f07b8253183f7b65479db1bc09efd4559e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReferenceWeightedQuadrature.lean @@ -0,0 +1,823 @@ +import OAI.NumberTheory.Jacobsthal.Primes.ActualPrimeQuadrature +import OAI.NumberTheory.Jacobsthal.Primes.PrimeRatioBins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ReferenceBenchmarkDecay + +open FinitePathGeometry LinearSieveFunctions BuchstabBridge NormalizedDeficits +open Dickman DickmanFiniteDecay + +noncomputable def benchmark : Side → ℝ → ℝ + | .even => f sieveA + | .odd => F sieveA + +@[simp] theorem benchmark_even_below_two {s : ℝ} (hs : s ≤ 2) : benchmark .even s=0 := + f_initial sieveA hs + +theorem benchmark_deviation_le_gap (i : Side) {s : ℝ} (hs : 1 ≤ s) : + |benchmark i s-1| ≤ gap s := by + obtain ⟨hl,hu⟩ := deficits_pos hs + have hsum := deficit_sum s + cases i with + | even => + have he : benchmark .even s-1 = -lowerDeficit s := by unfold benchmark lowerDeficit; ring + rw [he,abs_neg,abs_of_pos hl] + linarith + | odd => + change |upperDeficit s| ≤ gap s + rw [abs_of_pos hu] + linarith + +theorem gap_le_rho {s : ℝ} (hs : 1 ≤ s) : gap s ≤ sieveA*rho (s-1) := by + rw [gap_eq_rho hs] + exact div_le_self (mul_nonneg sieveA_pos.le (rho_nonneg _)) hs + +theorem gap_le_constant {s : ℝ} (hs : 1 ≤ s) : gap s ≤ sieveA := by + calc + _ ≤ sieveA*rho (s-1) := gap_le_rho hs + _ ≤ sieveA*1 := mul_le_mul_of_nonneg_left (rho_le_one _) sieveA_pos.le + _ = _ := mul_one _ + +theorem boundary_rho_decay {r : ℝ} (hr : 18 ≤ r) : + rho (r/2-1) ≤ Real.exp (-(1/128:ℝ)*r*Real.log (r+2)) := by + have hu : 8 ≤ r/2-1 := by linarith + have hr0 : 0 < r := by linarith + have hul : r/4 ≤ r/2-1 := by linarith + have hlog : Real.log (r+2) ≤ 2*Real.log (r/2-1+2) := by + have hp : 0 < r+2 := by linarith + have hsq : r+2 ≤ (r/2-1+2)^2 := by nlinarith + have hm := Real.log_le_log hp hsq + simpa only [Real.log_pow,Nat.cast_ofNat] using hm + have hl0 : 0 ≤ Real.log (r+2)/2 := div_nonneg (Real.log_nonneg (by linarith)) (by norm_num) + have hmul := mul_le_mul hul (show Real.log (r+2)/2 ≤ Real.log (r/2-1+2) by linarith) + hl0 (by linarith : 0 ≤ r/2-1) + calc + _ ≤ Real.exp (-(1/16:ℝ)*(r/2-1)*Real.log (r/2-1+2)) := rho_log_decay hu + _ ≤ _ := Real.exp_le_exp.mpr (by nlinarith) + +theorem boundary_benchmark_decay : ∃ C : ℝ,0 < C ∧ + ∀ r : ℝ,2 ≤ r → ∀ i : Side, + |benchmark i (r/2)-1| ≤ C*Real.exp (-(1/128:ℝ)*r*Real.log (r+2)) := by + let C : ℝ := sieveA*Real.exp ((1/128:ℝ)*18*Real.log 20) + have hC : 0 < C := mul_pos sieveA_pos (Real.exp_pos _) + have hCA : sieveA ≤ C := by + apply le_mul_of_one_le_right sieveA_pos.le + apply Real.one_le_exp_iff.mpr + positivity + refine ⟨C,hC,?_⟩ + intro r hr i + have hs : 1 ≤ r/2 := by linarith + have hb := benchmark_deviation_le_gap i hs + by_cases hlarge : 18 ≤ r + · calc + _ ≤ gap (r/2) := hb + _ ≤ sieveA*rho (r/2-1) := gap_le_rho hs + _ ≤ sieveA*Real.exp (-(1/128:ℝ)*r*Real.log (r+2)) := + mul_le_mul_of_nonneg_left (boundary_rho_decay hlarge) sieveA_pos.le + _ ≤ _ := mul_le_mul_of_nonneg_right hCA (Real.exp_nonneg _) + · have hr18 : r ≤ 18 := le_of_lt (lt_of_not_ge hlarge) + have hl : Real.log (r+2) ≤ Real.log 20 := Real.log_le_log (by linarith) (by linarith) + have hm : r*Real.log (r+2) ≤ 18*Real.log 20 := + mul_le_mul hr18 hl (Real.log_nonneg (by linarith)) (by norm_num) + have he : 1 ≤ Real.exp ((1/128:ℝ)*18*Real.log 20+(-(1/128:ℝ)*r*Real.log (r+2))) := + Real.one_le_exp_iff.mpr (by nlinarith) + calc + _ ≤ sieveA := hb.trans (gap_le_constant hs) + _ ≤ sieveA*Real.exp ((1/128:ℝ)*18*Real.log 20+(-(1/128:ℝ)*r*Real.log (r+2))) := + le_mul_of_one_le_right sieveA_pos.le he + _ = _ := by dsimp only [C]; rw [Real.exp_add]; ring + +end NumberTheoryLean.ReferenceBenchmarkDecay + + + +namespace NumberTheoryLean.ReferenceDifferentiation + +open _root_.Filter _root_.Set +open scoped Topology +open FinitePathGeometry LinearSieveFunctions BuchstabBridge ReferenceBenchmarkDecay + +noncomputable def parentBenchmark : Side → ℝ → ℝ + | .even, s => if s ≤ 2 then startingExtension sieveA s else f sieveA s + | .odd, s => F sieveA s + +def ParentDomain : Side → ℝ → Prop + | .even, s => 1 < s + | .odd, s => 0 < s + +theorem parent_even_eq_starting {s : ℝ} (hs : s ≤ 4) : + parentBenchmark .even s = startingExtension sieveA s := by + simp only [parentBenchmark] + split_ifs with h + · rfl + · exact (startingExtension_eq_f sieveA (le_of_lt (lt_of_not_ge h)) hs).symm + +theorem parent_even_eq_ordinary {s : ℝ} (hs : 2 ≤ s) : + parentBenchmark .even s = benchmark .even s := by + simp only [parentBenchmark,benchmark] + split_ifs with h + · exact startingExtension_eq_f sieveA hs (by linarith) + · rfl + +theorem parent_mass_derivative (i : Side) {s : ℝ} (hs : ParentDomain i s) : + HasDerivAt (fun t => t*parentBenchmark i t) (benchmark i.flip (s-1)) s := by + cases i with + | even => + change 1 < s at hs + by_cases hs2 : 2 < s + · have heq : (fun t => t*parentBenchmark .even t) =ᶠ[𝓝 s] (fun t => t*f sieveA t) := by + filter_upwards [Ioi_mem_nhds hs2] with t ht + rw [parent_even_eq_ordinary ht.le] + rfl + exact (mass_f_hasDerivAt sieveA hs2).congr_of_eventuallyEq heq + · have hsle : s ≤ 2 := le_of_not_gt hs2 + have heq : (fun t => t*parentBenchmark .even t) =ᶠ[𝓝 s] (fun t => sieveA*Real.log (t-1)) := by + filter_upwards [Ioo_mem_nhds hs (show s < 3 by linarith)] with t ht + rw [parent_even_eq_starting (by linarith [ht.2] : t ≤ 4)] + unfold startingExtension + field_simp [show t ≠ 0 by linarith [ht.1]] + have hd := ((((hasDerivAt_id s).sub_const 1).log (by linarith : s-1 ≠ 0)).const_mul sieveA) + have h := hd.congr_of_eventuallyEq heq + convert! h using 1 + change F sieveA (s-1) = _ + rw [F_initial sieveA (by linarith) (by linarith)] + simp only [id_eq] + ring + | odd => + change 0 < s at hs + by_cases hs2 : 2 < s + · exact mass_F_hasDerivAt sieveA hs2 + · have hsle : s ≤ 2 := le_of_not_gt hs2 + have heq : (fun t => t*parentBenchmark .odd t) =ᶠ[𝓝 s] (fun _ => sieveA) := by + filter_upwards [Ioo_mem_nhds hs (show s < 3 by linarith)] with t ht + change t*F sieveA t=sieveA + rw [F_initial sieveA ht.1 ht.2.le] + field_simp [ne_of_gt ht.1] + have hd := (hasDerivAt_const s sieveA).congr_of_eventuallyEq heq + convert! hd using 1 + change f sieveA (s-1)=0 + exact f_initial sieveA (by linarith) + +theorem reference_derivative (i : Side) {r b : ℝ} (hb : 0 < b) + (hdomain : ParentDomain i (r/b)) : + HasDerivAt (fun x => (parentBenchmark i (r/x)-1)/x) + (-(benchmark i.flip (r/b-1)-1)/b^2) b := by + have hrb : 0 < r/b := by cases i <;> simp only [ParentDomain] at hdomain <;> linarith + have hr : 0 < r := (div_pos_iff.mp hrb).resolve_right (by intro h; linarith [h.2]) |>.1 + have hmass := (parent_mass_derivative i hdomain).sub (hasDerivAt_id (r/b)) + have hcomp := hmass.comp b ((hasDerivAt_const b r).div (hasDerivAt_id b) (ne_of_gt hb)) + have h := hcomp.div_const r + have heq : (fun x => (parentBenchmark i (r/x)-1)/x) =ᶠ[𝓝 b] + (fun x => ((r/x)*parentBenchmark i (r/x)-r/x)/r) := by + filter_upwards [Ioi_mem_nhds hb] with x hx + change 0 < x at hx + field_simp [ne_of_gt hr,ne_of_gt hx] + have hh := h.congr_of_eventuallyEq heq + convert! hh using 1 + simp only [zero_mul,mul_one,zero_sub] + field_simp + +theorem omitted_lower_deviation {r x : ℝ} (hx : 0 < x) (homit : r-x < 2*x) : + benchmark .even (r/x-1)-1 = -1 := by + have hs : r/x-1 ≤ 2 := by + have hd : r/x < 3 := (div_lt_iff₀ hx).mpr (by linarith) + linarith + rw [benchmark_even_below_two hs] + ring + +end NumberTheoryLean.ReferenceDifferentiation + + + +namespace NumberTheoryLean.ReferenceAdmission + +open _root_.Finset +open FinitePathGeometry PrimeTiltPrefixes +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass + +def childAdmitted : Side → ℝ → ℝ → Prop + | .even,_,_ => True + | .odd,r,x => max (2*x) (x+2) ≤ r-x + +noncomputable def admitted (w : ℝ) : Side → ℝ → List ℕ → Prop + | _,_,[] => True + | i,r,p::ps => childAdmitted i r (primeExponent w p) ∧ admitted w i.flip (r-primeExponent w p) ps + +def endSide : Side → List ℕ → Side + | i,[] => i + | i,_::ps => endSide i.flip ps + +theorem gap_append (w r : ℝ) (ps qs : List ℕ) : + primeFinalGap w r (ps++qs)=primeFinalGap w (primeFinalGap w r ps) qs := by + induction ps generalizing r with + | nil => rfl + | cons p ps ih => exact ih (r-primeExponent w p) + +theorem endSide_append (i : Side) (ps qs : List ℕ) : endSide i (ps++qs)=endSide (endSide i ps) qs := by + induction ps generalizing i with + | nil => rfl + | cons p ps ih => exact ih i.flip + +theorem admitted_append (w r : ℝ) (i : Side) (ps qs : List ℕ) : + admitted w i r (ps++qs) ↔ admitted w i r ps ∧ admitted w (endSide i ps) (primeFinalGap w r ps) qs := by + induction ps generalizing i r with + | nil => simp only [List.nil_append,admitted,primeFinalGap,endSide,true_and] + | cons p ps ih => + simp only [List.cons_append,admitted,endSide,primeFinalGap,ih,and_assoc] + +noncomputable def FirstOmitted (w : ℝ) (i : Side) (r : ℝ) (ps : List ℕ) : Prop := + ∃ pre : List ℕ,∃ p : ℕ,ps=pre++[p] ∧ admitted w i r pre ∧ + ¬childAdmitted (endSide i pre) (primeFinalGap w r pre) (primeExponent w p) + +theorem firstOmitted_not_admitted {w r : ℝ} {i : Side} {ps : List ℕ} + (hp : FirstOmitted w i r ps) : ¬admitted w i r ps := by + rcases hp with ⟨pre,p,rfl,hpre,hfail⟩ + rw [admitted_append] + intro h + exact hfail h.2.1 + +theorem exists_first_omitted_prefix {w r : ℝ} {i : Side} {ps : List ℕ} + (hp : ¬admitted w i r ps) : + ∃ pre suf : List ℕ,ps=pre++suf ∧ FirstOmitted w i r pre := by + induction ps generalizing i r with + | nil => exact False.elim (hp trivial) + | cons p ps ih => + by_cases hchild : childAdmitted i r (primeExponent w p) + · have ht : ¬admitted w i.flip (r-primeExponent w p) ps := fun h => hp ⟨hchild,h⟩ + obtain ⟨pre,suf,he,hfirst⟩ := ih ht + rcases hfirst with ⟨pre',q,hpre',ha,hbad⟩ + refine ⟨p::pre,suf,by rw [List.cons_append,he],?_⟩ + refine ⟨p::pre',q,by rw [List.cons_append,hpre'],⟨hchild,ha⟩,?_⟩ + exact hbad + · exact ⟨[p],ps,rfl,[],p,rfl,trivial,hchild⟩ + +theorem firstOmitted_boundary_gap {w r : ℝ} {i : Side} {ps : List ℕ} + (hp : FirstOmitted w i r ps) (hupper : ∀ p ∈ ps,primeExponent w p ≤ 2) : + primeFinalGap w r ps < 4 := by + rcases hp with ⟨pre,p,rfl,_hpre,hfail⟩ + have hp2 : primeExponent w p ≤ 2 := hupper p (by simp) + rw [gap_append] + change primeFinalGap w r pre-primeExponent w p < 4 + cases he : endSide i pre with + | even => + simp only [he,childAdmitted] at hfail + exact False.elim (hfail trivial) + | odd => + rw [he] at hfail + change ¬max (2*primeExponent w p) (primeExponent w p+2) ≤ primeFinalGap w r pre-primeExponent w p at hfail + have hmax : max (2*primeExponent w p) (primeExponent w p+2)=primeExponent w p+2 := + max_eq_right (by linarith) + rw [hmax] at hfail + linarith + +theorem gap_lower_by_length {w r : ℝ} {ps : List ℕ} + (hupper : ∀ p ∈ ps,primeExponent w p ≤ 2) : + r-2*(ps.length:ℝ) ≤ primeFinalGap w r ps := by + induction ps generalizing r with + | nil => simp [primeFinalGap] + | cons p ps ih => + have hp := hupper p (by simp) + have ht := ih (r:=r-primeExponent w p) (fun q hq => hupper q (by simp [hq])) + simp only [List.length_cons,Nat.cast_add,Nat.cast_one,primeFinalGap] + linarith + +theorem firstOmitted_boundary_length {w r : ℝ} {i : Side} {ps : List ℕ} + (hp : FirstOmitted w i r ps) (hupper : ∀ p ∈ ps,primeExponent w p ≤ 2) : + (r-4)/2 < (ps.length:ℝ) := by + have hg := firstOmitted_boundary_gap hp hupper + have hl := gap_lower_by_length (r:=r) hupper + linarith + +noncomputable def referencePrefixes (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : Finset (List ℕ) := by + classical + exact (decreasingPrefixes P).filter (admitted w i r) + +noncomputable def firstOmissions (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : Finset (List ℕ) := by + classical + exact (decreasingPrefixes P).filter (FirstOmitted w i r) + +noncomputable def referencePolynomial (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : ℝ := + ∑ ps ∈ referencePrefixes w P i r,(-1:ℝ)^ps.length*prefixWeight ps + +noncomputable def boundaryPrimes (w : ℝ) : Finset ℕ := primesBetween w (w^(2:ℝ)) + +theorem boundary_prime_exponent_upper {w : ℝ} (hw : 1 < w) {p : ℕ} (hp : p ∈ boundaryPrimes w) : + primeExponent w p ≤ 2 := by + obtain ⟨hpp,_⟩ := Finset.mem_filter.mp hp + obtain ⟨hfloor,hprime⟩ := Nat.mem_primesLE.mp hpp + have hp0 : (0:ℝ) < p := by exact_mod_cast hprime.pos + apply (exponent_le_iff hw hp0).mpr + exact (Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) 2).le).mp hfloor + +theorem actual_first_omission_length {w r : ℝ} (hw : 1 < w) (i : Side) {ps : List ℕ} + (hp : ps ∈ firstOmissions w (boundaryPrimes w) i r) : (r-4)/2 < (ps.length:ℝ) := by + classical + obtain ⟨hfamily,hfirst⟩ := Finset.mem_filter.mp hp + have hmem := (mem_decreasingPrefixes.mp hfamily).2 + exact firstOmitted_boundary_length hfirst (fun p hp => boundary_prime_exponent_upper hw (hmem p hp)) + +end NumberTheoryLean.ReferenceAdmission + + +section + +open _root_.Set +namespace ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceAdmission + +noncomputable def upperCutoff : Side → ℝ → ℝ → ℝ + | .even,_,b => max 1 (min 2 b) + | .odd,r,b => max 1 (min (min 2 b) ((r-2)/2)) + +theorem upperCutoff_bounds (i : Side) (r b : ℝ) : 1 ≤ upperCutoff i r b ∧ upperCutoff i r b ≤ 2 := by + cases i + · exact ⟨le_max_left _ _,max_le (by norm_num) (min_le_left _ _)⟩ + · exact ⟨le_max_left _ _,max_le (by norm_num) ((min_le_left _ _).trans (min_le_left _ _))⟩ + +theorem upperCutoff_continuous (i : Side) : + Continuous (fun p : ℝ×ℝ => upperCutoff i p.1 p.2) := by + cases i <;> unfold upperCutoff <;> fun_prop + +theorem upperCutoff_odd_small {r b : ℝ} (hr : r ≤ 4) : upperCutoff .odd r b=1 := by + apply max_eq_left + exact (min_le_right _ _).trans (by linarith) + +theorem upperCutoff_low {i : Side} {r b : ℝ} (hb : b ≤ 1) : upperCutoff i r b=1 := by + cases i + · exact max_eq_left ((min_le_right _ _).trans hb) + · exact max_eq_left ((min_le_left _ _).trans ((min_le_right _ _).trans hb)) + +theorem strong_gate_below_two {r x : ℝ} (hx : x ≤ 2) : + childAdmitted .odd r x ↔ x ≤ (r-2)/2 := by + change max (2*x) (x+2) ≤ r-x ↔ x ≤ (r-2)/2 + rw [max_eq_right (by linarith : 2*x ≤ x+2)] + constructor <;> intro h <;> linarith + +theorem le_clipped_upper {x t : ℝ} (hx : 1 < x) : x ≤ max 1 t ↔ x ≤ t := by + rw [le_max_iff] + exact or_iff_right (not_le_of_gt hx) + +theorem mem_upperCutoff (i : Side) (r b x : ℝ) : + x ∈ Ioc 1 (upperCutoff i r b) ↔ + 1 < x ∧ x ≤ 2 ∧ x ≤ b ∧ childAdmitted i r x := by + constructor + · intro hx + cases i with + | even => + have h : x ≤ min 2 b := (le_clipped_upper hx.1).mp hx.2 + exact ⟨hx.1,(le_min_iff.mp h).1,(le_min_iff.mp h).2,trivial⟩ + | odd => + have h : x ≤ min (min 2 b) ((r-2)/2) := (le_clipped_upper hx.1).mp hx.2 + obtain ⟨hb,hgate⟩ := le_min_iff.mp h + obtain ⟨hx2,hxb⟩ := le_min_iff.mp hb + exact ⟨hx.1,hx2,hxb,(strong_gate_below_two hx2).mpr hgate⟩ + · rintro ⟨hx,hx2,hxb,hgate⟩ + refine ⟨hx,?_⟩ + cases i with + | even => exact (le_clipped_upper hx).mpr (le_min hx2 hxb) + | odd => exact (le_clipped_upper hx).mpr (le_min (le_min hx2 hxb) ((strong_gate_below_two hx2).mp hgate)) + +end ErdosContinuousBoundary + +end + + +namespace NumberTheoryLean.ReferenceCancellation + +open _root_.MeasureTheory _root_.Set +open FinitePathGeometry LinearSieveFunctions BuchstabBridge ReferenceBenchmarkDecay +open ReferenceDifferentiation ReferenceAdmission + +theorem parent_domain_mono (i : Side) {s t : ℝ} (hs : ParentDomain i s) (hst : s ≤ t) : + ParentDomain i t := by cases i <;> simp only [ParentDomain] at hs ⊢ <;> linarith + +theorem positive_gap_of_parent_domain (i : Side) {r b : ℝ} (hb : 0 < b) + (hs : ParentDomain i (r/b)) : 0 < r := by + have hrb : 0 < r/b := by cases i <;> simp only [ParentDomain] at hs <;> linarith + exact ((div_pos_iff.mp hrb).resolve_right (by intro h; linarith [h.2])).1 + +theorem parent_domain_interval (i : Side) {r b x : ℝ} (hb : 2 ≤ b) + (hs : ParentDomain i (r/b)) (hx : x ∈ Icc 2 b) : ParentDomain i (r/x) := by + have hr := positive_gap_of_parent_domain i (by linarith : 0 < b) hs + exact parent_domain_mono i hs (div_le_div_of_nonneg_left hr.le (by linarith [hx.1]) hx.2) + +theorem prospective_integrand_continuousAt (i : Side) {r x : ℝ} (hx : 0 < x) + (hs : ParentDomain i (r/x)) : + ContinuousAt (fun t => (benchmark i.flip (r/t-1)-1)/t^2) x := by + have hmap : ContinuousAt (fun t : ℝ => r/t-1) x := + (continuousAt_const.div continuousAt_id (ne_of_gt hx)).sub continuousAt_const + have hchild : ContinuousAt (fun t => benchmark i.flip (r/t-1)) x := by + cases i with + | even => + have hF : ContinuousAt (F sieveA) (r/x-1) := + F_continuousAt sieveA (by change 1 < r/x at hs; linarith) + exact hF.comp (f := fun t => r/t-1) hmap + | odd => exact (f_continuous sieveA).continuousAt.comp hmap + exact (hchild.sub continuousAt_const).div (continuousAt_id.pow 2) (pow_ne_zero 2 (ne_of_gt hx)) + +theorem prospective_interval_integrable (i : Side) {r b : ℝ} (hb : 2 ≤ b) + (hs : ParentDomain i (r/b)) : + IntervalIntegrable (fun x => (benchmark i.flip (r/x-1)-1)/x^2) volume 2 b := by + apply ContinuousOn.intervalIntegrable_of_Icc hb + intro x hx + exact (prospective_integrand_continuousAt i (by linarith [hx.1]) + (parent_domain_interval i hb hs hx)).continuousWithinAt + +theorem continuous_reference_cancellation (i : Side) {r b : ℝ} (hb : 2 ≤ b) + (hs : ParentDomain i (r/b)) : + (parentBenchmark i (r/2)-1)/2-(parentBenchmark i (r/b)-1)/b- + (∫ x in (2:ℝ)..b,(benchmark i.flip (r/x-1)-1)/x^2)=0 := by + have hderiv : ∀ x ∈ uIcc 2 b, + HasDerivAt (fun t => (parentBenchmark i (r/t)-1)/t) + (-(benchmark i.flip (r/x-1)-1)/x^2) x := by + intro x hx + rw [uIcc_of_le hb] at hx + exact reference_derivative i (by linarith [hx.1]) (parent_domain_interval i hb hs hx) + have hint : IntervalIntegrable (fun x => -(benchmark i.flip (r/x-1)-1)/x^2) volume 2 b := by + convert! (prospective_interval_integrable i hb hs).neg using 1 + funext x + exact neg_div _ _ + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt hderiv hint + simp_rw [neg_div] at h + rw [intervalIntegral.integral_neg] at h + linarith + +theorem upper_admission_above_two {r x : ℝ} (hx : 2 ≤ x) : + childAdmitted .odd r x ↔ 2*x ≤ r-x := by + change max (2*x) (x+2) ≤ r-x ↔ 2*x ≤ r-x + rw [max_eq_left (by linarith)] + +theorem actual_omitted_deviation_above_two {r x : ℝ} (hx : 2 ≤ x) + (homit : ¬childAdmitted .odd r x) : + benchmark .even (r/x-1)-1 = -1 := by + rw [upper_admission_above_two hx] at homit + exact omitted_lower_deviation (by linarith) (lt_of_not_ge homit) + +end NumberTheoryLean.ReferenceCancellation + + + +namespace ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry + +theorem upperCutoff_b_lipschitz (i : Side) (r : ℝ) : + LipschitzWith 1 (fun b => upperCutoff i r b) := by + cases i with + | even => exact (LipschitzWith.id.const_min (2:ℝ)).const_max 1 + | odd => exact ((LipschitzWith.id.const_min (2:ℝ)).min_const ((r-2)/2)).const_max 1 + +theorem upperCutoff_r_lipschitz (i : Side) (b : ℝ) : + LipschitzWith 1 (fun r => upperCutoff i r b) := by + cases i with + | even => + apply LipschitzWith.of_dist_le_mul + intro r s + simp [upperCutoff] + | odd => + have h : LipschitzWith 1 (fun r : ℝ => (r-2)/2) := by + apply LipschitzWith.of_dist_le_mul + intro r s + simp only [Real.dist_eq,NNReal.coe_one,one_mul] + have he : (r-2)/2-(s-2)/2=(r-s)/2 := by ring + rw [he,abs_div] + norm_num + exact (h.const_min (min 2 b)).const_max 1 + +theorem upperCutoff_b_difference (i : Side) (r b c : ℝ) : + |upperCutoff i r b-upperCutoff i r c| ≤ |b-c| := by + simpa only [Real.dist_eq,NNReal.coe_one,one_mul] using (upperCutoff_b_lipschitz i r).dist_le_mul b c + +theorem upperCutoff_r_difference (i : Side) (b r s : ℝ) : + |upperCutoff i r b-upperCutoff i s b| ≤ |r-s| := by + simpa only [Real.dist_eq,NNReal.coe_one,one_mul] using (upperCutoff_r_lipschitz i b).dist_le_mul r s + +end ErdosContinuousBoundary + + + +namespace NumberTheoryLean.ReferenceDeviationMonotonicity + +open _root_.Filter _root_.Set +open scoped Topology +open FinitePathGeometry LinearSieveFunctions BuchstabBridge NormalizedDeficits +open DeficitFutureIntegrals DerivativeWeights ReferenceBenchmarkDecay ReferenceDifferentiation ReferenceCancellation + +theorem lower_deficit_antitone : Antitone lowerDeficit := by + have htail : AntitoneOn lowerDeficit (Ici 2) := by + apply antitoneOn_of_deriv_nonpos (convex_Ici 2) lowerDeficit_continuous.continuousOn + · intro s hs + rw [interior_Ici] at hs + exact (lowerDeficit_hasDerivAt hs).differentiableAt.differentiableWithinAt + · intro s hs + rw [interior_Ici] at hs + change 2 < s at hs + rw [(lowerDeficit_hasDerivAt hs).deriv] + exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (phiEven_pos (by linarith)).le) (sq_nonneg _) + intro x y hxy + by_cases hy : y ≤ 2 + · simp only [lowerDeficit,f_initial sieveA hy,f_initial sieveA (hxy.trans hy),sub_zero,le_refl] + · by_cases hx : x ≤ 2 + · have hh := htail (show (2:ℝ) ∈ Ici 2 by norm_num) (le_of_not_ge hy) (le_of_not_ge hy) + simpa only [lowerDeficit,f_initial sieveA hx,f_initial sieveA (le_refl (2:ℝ)),sub_zero] using hh + · exact htail (le_of_not_ge hx) (le_of_not_ge hy) hxy + +theorem upper_deficit_pos_positive {s : ℝ} (hs : 0 < s) : 0 < upperDeficit s := by + by_cases hs1 : 1 ≤ s + · exact (deficits_pos hs1).2 + · change 0 < F sieveA s-1 + rw [F_initial sieveA hs (by linarith)] + have h : 1 < sieveA/s := (one_lt_div hs).mpr (by linarith [sieveA_gt_two]) + linarith + +theorem upper_deficit_antitone : AntitoneOn upperDeficit (Ioi 0) := by + apply antitoneOn_of_deriv_nonpos (convex_Ioi 0) + · intro s hs + exact ((F_continuousAt sieveA (ne_of_gt hs)).sub continuousAt_const).continuousWithinAt + · intro s hs + rw [interior_Ioi] at hs + exact ((F_hasDerivAt hs).sub_const 1).differentiableAt.differentiableWithinAt + · intro s hs + rw [interior_Ioi] at hs + change deriv (fun t => F sieveA t-1) s ≤ 0 + rw [((F_hasDerivAt hs).sub_const 1).deriv] + exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (phiOdd_pos s).le) (sq_nonneg _) + +theorem even_abs_deviation (s : ℝ) : |benchmark .even s-1| = lowerDeficit s := by + have he : benchmark .even s-1 = -lowerDeficit s := by unfold benchmark lowerDeficit; ring + rw [he,abs_neg,abs_of_nonneg (lowerDeficit_nonneg s)] + +theorem odd_abs_deviation {s : ℝ} (hs : 0 < s) : |benchmark .odd s-1| = upperDeficit s := + abs_of_pos (upper_deficit_pos_positive hs) + +theorem prospective_absolute_monotone (i : Side) {r u v : ℝ} (hu : 2 ≤ u) (huv : u ≤ v) + (hs : ParentDomain i (r/v)) : + MonotoneOn (fun x => |benchmark i.flip (r/x-1)-1|) (Icc u v) := by + have hv : 2 ≤ v := hu.trans huv + have hr := positive_gap_of_parent_domain i (by linarith : 0 < v) hs + intro x hx y hy hxy + have harg : r/y-1 ≤ r/x-1 := sub_le_sub_right + (div_le_div_of_nonneg_left hr.le (by linarith [hx.1]) hxy) 1 + cases i with + | even => + have hdx := parent_domain_interval .even hv hs ⟨hu.trans hx.1,hx.2⟩ + have hdy := parent_domain_interval .even hv hs ⟨hu.trans hy.1,hy.2⟩ + change 1 < r/x at hdx + change 1 < r/y at hdy + change |benchmark .odd (r/x-1)-1| ≤ |benchmark .odd (r/y-1)-1| + rw [odd_abs_deviation (by linarith),odd_abs_deviation (by linarith)] + exact upper_deficit_antitone (by change 0 < r/y-1; linarith) (by change 0 < r/x-1; linarith) harg + | odd => + change |benchmark .even (r/x-1)-1| ≤ |benchmark .even (r/y-1)-1| + rw [even_abs_deviation,even_abs_deviation] + exact lower_deficit_antitone harg + +theorem prospective_signed_monotone (i : Side) {r u v : ℝ} (hu : 2 ≤ u) (huv : u ≤ v) + (hs : ParentDomain i (r/v)) : + (i=.even → MonotoneOn (fun x => benchmark i.flip (r/x-1)-1) (Icc u v)) ∧ + (i=.odd → AntitoneOn (fun x => benchmark i.flip (r/x-1)-1) (Icc u v)) := by + have hm := prospective_absolute_monotone i hu huv hs + cases i with + | even => + refine ⟨?_,by intro h; cases h⟩ + intro _ x hx y hy hxy + have hp := hm hx hy hxy + have hxD := parent_domain_interval .even (hu.trans huv) hs ⟨hu.trans hx.1,hx.2⟩ + have hyD := parent_domain_interval .even (hu.trans huv) hs ⟨hu.trans hy.1,hy.2⟩ + change 1 < r/x at hxD + change 1 < r/y at hyD + change benchmark .odd (r/x-1)-1 ≤ benchmark .odd (r/y-1)-1 + change |benchmark .odd (r/x-1)-1| ≤ |benchmark .odd (r/y-1)-1| at hp + rw [odd_abs_deviation (by linarith),odd_abs_deviation (by linarith)] at hp + exact hp + | odd => + constructor + · intro h + cases h + intro _ x hx y hy hxy + have hp := hm hx hy hxy + change |benchmark .even (r/x-1)-1| ≤ |benchmark .even (r/y-1)-1| at hp + rw [even_abs_deviation,even_abs_deviation] at hp + change f sieveA (r/y-1)-1 ≤ f sieveA (r/x-1)-1 + unfold lowerDeficit at hp + linarith + +end NumberTheoryLean.ReferenceDeviationMonotonicity + + + +namespace NumberTheoryLean.ReferenceWeightDomination + +open FinitePathGeometry LinearSieveFunctions BuchstabBridge NormalizedDeficits +open DeficitFutureIntegrals DerivativeWeights ReferenceBenchmarkDecay ReferenceDifferentiation ReferenceCancellation +open ReferenceDeviationMonotonicity + +theorem starting_parent_nonpos {s : ℝ} (hs : 1 < s) (hs2 : s ≤ 2) : + parentBenchmark .even s ≤ 0 := by + rw [parent_even_eq_starting (by linarith)] + unfold startingExtension + exact div_nonpos_of_nonpos_of_nonneg + (mul_nonpos_of_nonneg_of_nonpos sieveA_pos.le (Real.log_nonpos (by linarith) (by linarith))) (by linarith) + +theorem even_parent_le_one {s : ℝ} (hs : 1 < s) : parentBenchmark .even s ≤ 1 := by + by_cases hs2 : 2 ≤ s + · rw [parent_even_eq_ordinary hs2] + have h := lowerDeficit_nonneg s + change 0 ≤ 1-f sieveA s at h + change f sieveA s ≤ 1 + linarith + · exact (starting_parent_nonpos hs (le_of_lt (lt_of_not_ge hs2))).trans (by norm_num) + +theorem even_parent_abs {s : ℝ} (hs : 1 < s) : + |parentBenchmark .even s-1| = 1-parentBenchmark .even s := by + rw [abs_of_nonpos (sub_nonpos.mpr (even_parent_le_one hs))] + ring + +theorem weight_deviation_identity (i : Side) {s : ℝ} (hs : ParentDomain i s) : + weight i s = s*(|parentBenchmark i s-1|+|benchmark i.flip (s-1)-1|) := by + cases i with + | even => + change 1 < s at hs + change phiEven s = s*(|parentBenchmark .even s-1|+|benchmark .odd (s-1)-1|) + rw [even_parent_abs hs,odd_abs_deviation (by linarith)] + by_cases hs2 : 2 ≤ s + · rw [phiEven_eq_deficits hs2,parent_even_eq_ordinary hs2] + rfl + · have hsle : s ≤ 2 := le_of_lt (lt_of_not_ge hs2) + rw [phiEven_initial hsle,parent_even_eq_starting (by linarith)] + unfold evenInitial startingExtension upperDeficit + rw [F_initial sieveA (by linarith) (by linarith)] + field_simp + ring + | odd => + change 0 < s at hs + change phiOdd s = s*(|benchmark .odd s-1|+|benchmark .even (s-1)-1|) + rw [odd_abs_deviation hs,even_abs_deviation] + by_cases hs1 : 1 ≤ s + · exact phiOdd_eq_deficits hs1 + · rw [phiOdd_initial (by linarith)] + unfold upperDeficit lowerDeficit + rw [F_initial sieveA hs (by linarith),f_initial sieveA (by linarith)] + field_simp + ring + +theorem valid_parent_domain {i : Side} {s : ℝ} (hs : Valid i s) : ParentDomain i s := by + cases i <;> simp only [Valid,ParentDomain] at hs ⊢ <;> linarith + +theorem source_deviation_sum {i : Side} {s : ℝ} (hs : Valid i s) : + |parentBenchmark i s-1|+|benchmark i.flip (s-1)-1| ≤ 2*weight i s := by + have hd := valid_parent_domain hs + have hpos := valid_pos hs + have he := weight_deviation_identity i hd + have hs2 : (1/2:ℝ) ≤ s := by cases i <;> simp only [Valid] at hs <;> linarith + have hsum : 0 ≤ |parentBenchmark i s-1|+|benchmark i.flip (s-1)-1| := by positivity + nlinarith + +theorem ordinary_deviation_le_parent (i : Side) {s : ℝ} (hs : ParentDomain i s) : + |benchmark i s-1| ≤ |parentBenchmark i s-1| := by + cases i with + | odd => exact le_rfl + | even => + change 1 < s at hs + rw [even_abs_deviation,even_parent_abs hs] + by_cases hs2 : 2 ≤ s + · rw [parent_even_eq_ordinary hs2] + exact le_rfl + · have hsle := le_of_lt (lt_of_not_ge hs2) + have h := starting_parent_nonpos hs hsle + simp only [lowerDeficit,f_initial sieveA hsle,sub_zero] + linarith + +theorem benchmark_absolute_antitone (i : Side) {s t : ℝ} (hs : ParentDomain i s) (hst : s ≤ t) : + |benchmark i t-1| ≤ |benchmark i s-1| := by + cases i with + | even => rw [even_abs_deviation,even_abs_deviation]; exact lower_deficit_antitone hst + | odd => + change 0 < s at hs + rw [odd_abs_deviation (hs.trans_le hst),odd_abs_deviation hs] + exact upper_deficit_antitone hs (hs.trans_le hst) hst + +theorem residual_deviations_bound (i : Side) {r b x : ℝ} (hb : 2 ≤ b) + (hs : Valid i (r/b)) (hx : x ∈ Set.Icc 2 b) : + |parentBenchmark i (r/b)-1|+|benchmark i (r/2)-1|+ + |benchmark i.flip (r/x-1)-1| ≤ 4*weight i (r/b) := by + have hd := valid_parent_domain hs + have hr := positive_gap_of_parent_domain i (by linarith : 0 < b) hd + have hratio : r/b ≤ r/2 := div_le_div_of_nonneg_left hr.le (by norm_num) hb + have hboundary := (benchmark_absolute_antitone i hd hratio).trans (ordinary_deviation_le_parent i hd) + have hmono := prospective_absolute_monotone i (u := 2) le_rfl hb hd + have hnext := hmono hx (show b ∈ Set.Icc 2 b from ⟨hb,le_rfl⟩) hx.2 + have hsum := source_deviation_sum hs + have hn := abs_nonneg (benchmark i.flip (r/b-1)-1) + linarith + +end NumberTheoryLean.ReferenceWeightDomination + + + +namespace NumberTheoryLean.ReferenceParentMonotonicity + +open _root_.Set +open FinitePathGeometry LinearSieveFunctions BuchstabBridge NormalizedDeficits DerivativeWeights +open ReferenceBenchmarkDecay ReferenceDifferentiation ReferenceCancellation ReferenceWeightDomination ReferenceDeviationMonotonicity + +theorem even_parent_deficit_antitone : AntitoneOn (fun s => 1-parentBenchmark .even s) (Ioi 1) := by + have hd : ∀ s : ℝ,1 < s → HasDerivAt (parentBenchmark .even) + ((benchmark .odd (s-1)-parentBenchmark .even s)/s) s := by + intro s hs + exact hasDerivAt_of_mass (by linarith) (parent_mass_derivative .even hs) + apply antitoneOn_of_deriv_nonpos (convex_Ioi 1) + · intro s hs + exact ((hd s hs).const_sub 1).continuousAt.continuousWithinAt + · intro s hs + rw [interior_Ioi] at hs + exact ((hd s hs).const_sub 1).differentiableAt.differentiableWithinAt + · intro s hs + rw [interior_Ioi] at hs + change 1 < s at hs + rw [((hd s hs).const_sub 1).deriv] + have hu := upper_deficit_pos_positive (s:=s-1) (by linarith) + have he := even_parent_le_one hs + have hnum : 0 ≤ benchmark .odd (s-1)-parentBenchmark .even s := by + change 0 < F sieveA (s-1)-1 at hu + change 0 ≤ F sieveA (s-1)-parentBenchmark .even s + linarith + exact neg_nonpos.mpr (div_nonneg hnum (by linarith)) + +theorem parent_absolute_antitone (i : Side) {s t : ℝ} (hs : ParentDomain i s) (hst : s ≤ t) : + |parentBenchmark i t-1| ≤ |parentBenchmark i s-1| := by + cases i with + | even => + change 1 < s at hs + rw [even_parent_abs (hs.trans_le hst),even_parent_abs hs] + exact even_parent_deficit_antitone hs (hs.trans_le hst) hst + | odd => exact benchmark_absolute_antitone .odd hs hst + +theorem interval_deviations_bound (i : Side) {r a b x : ℝ} (ha : 2 ≤ a) (hab : a ≤ b) + (hs : Valid i (r/b)) (hx : x ∈ Icc a b) : + |parentBenchmark i (r/a)-1|+|parentBenchmark i (r/b)-1|+ + |benchmark i.flip (r/x-1)-1| ≤ 4*weight i (r/b) := by + have hb : 2 ≤ b := ha.trans hab + have hd := valid_parent_domain hs + have hr := positive_gap_of_parent_domain i (by linarith : 0 < b) hd + have hrat : r/b ≤ r/a := div_le_div_of_nonneg_left hr.le (by linarith) hab + have hleft := parent_absolute_antitone i hd hrat + have hmono := prospective_absolute_monotone i (u:=2) le_rfl hb hd + have hnext := hmono ⟨ha.trans hx.1,hx.2⟩ ⟨hb,le_rfl⟩ hx.2 + have hsum := source_deviation_sum hs + linarith [abs_nonneg (benchmark i.flip (r/b-1)-1)] + +end NumberTheoryLean.ReferenceParentMonotonicity + + + +namespace NumberTheoryLean.ReferenceWeightedQuadrature + +attribute [local instance] Classical.propDecidable +open _root_.MeasureTheory _root_.Set _root_.Finset +open FinitePathGeometry ReferenceBenchmarkDecay ReferenceDifferentiation ReferenceCancellation +open ReferenceDeviationMonotonicity ReferenceWeightDomination ActualPrimeQuadrature +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem source_weighted_quadrature : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ u v b r : ℝ,2 ≤ u → u ≤ v → v ≤ b → ∀ i : Side, + Valid i (r/b) → ∀ J : Set ℝ,J.OrdConnected → J ⊆ Icc u v → + |(∑ p ∈ Nat.primesLE ⌊w^v⌋₊,if primeExponent w p ∈ J then + (p:ℝ)⁻¹*(benchmark i.flip (r/primeExponent w p-1)-1)/primeExponent w p else 0)- + ∫ x in J,(benchmark i.flip (r/x-1)-1)/x^2| ≤ + (C*weight i (r/b)/u)*Real.exp (-c*Real.sqrt (u*Real.log w)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := actual_weighted_prime_quadrature + refine ⟨c,4*C,w₀,hc,by positivity,hw₀,?_⟩ + intro w hw u v b r hu huv hvb i hs J hJ hsub + have hb : 2 ≤ b := hu.trans (huv.trans hvb) + have hparent := valid_parent_domain hs + have hvdom : ParentDomain i (r/v) := parent_domain_interval i hb hparent ⟨hu.trans huv,hvb⟩ + let g : ℝ → ℝ := fun x => benchmark i.flip (r/x-1)-1 + have hmono : MonotoneOn g (Icc u v) ∨ AntitoneOn g (Icc u v) := by + have hm := prospective_signed_monotone i hu huv hvdom + cases i with + | even => exact Or.inl (hm.1 rfl) + | odd => exact Or.inr (hm.2 rfl) + have hbound : ∀ x ∈ Icc u v,|g x| ≤ 4*weight i (r/b) := by + intro x hx + have hh := residual_deviations_bound i hb hs ⟨hu.trans hx.1,hx.2.trans hvb⟩ + have hp := abs_nonneg (parentBenchmark i (r/b)-1) + have hbnd := abs_nonneg (benchmark i (r/2)-1) + dsimp only [g] + linarith + have hq := h w hw u v hu huv (4*weight i (r/b)) (by have hp := weight_pos hs; positivity) + g hmono hbound J hJ hsub + calc + _ ≤ (C*(4*weight i (r/b))/u)*Real.exp (-c*Real.sqrt (u*Real.log w)) := hq + _ = _ := by ring + +end NumberTheoryLean.ReferenceWeightedQuadrature + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RefinedDiscardBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RefinedDiscardBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb0fee705e2c6d528480520813e6a228cce64bfb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RefinedDiscardBound.lean @@ -0,0 +1,33 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceLabelCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseRefinement +open ErdosInverseCells + +theorem refined_discard_bound (C : Finset ℕ) (a : ℕ → ℕ) (W : ℕ) [NeZero W] + (S Z gamma : ℝ) (hS : 0 ≤ S) (hZ : 0 < Z) + (hC : S/Z ≤ (C.card : ℝ)) (hW : (W : ℝ)^2 ≤ Z) (hInv : 1/Z ≤ gamma/8) : + ((discardedPoints C (refinementLabel a W) (S/Z^3)).card : ℝ) ≤ (gamma/8)*(C.card : ℝ) := by + have hh := discardedPoints_card_bound C (refinementLabel a W) (S/Z^3) (by positivity) + rw [refinementLabel_card] at hh + push_cast at hh + calc + _ ≤ (W : ℝ)^2*(S/Z^3) := hh + _ ≤ Z*(S/Z^3) := mul_le_mul_of_nonneg_right hW (by positivity) + _ = (1/Z)*(S/Z) := by field_simp + _ ≤ (1/Z)*(C.card : ℝ) := mul_le_mul_of_nonneg_left hC (by positivity) + _ ≤ _ := mul_le_mul_of_nonneg_right hInv (Nat.cast_nonneg _) + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RefinementRewardMargin.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RefinementRewardMargin.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a9a6ce70a8bbc114bc27abf44d0f32596ec1fb6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RefinementRewardMargin.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceLabelCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseRefinement +open ErdosInverseCells +attribute [local instance] Classical.decEq + +theorem dense_fiber_after_count_discard {ι : Type*} [Fintype ι] + (C : Finset ℕ) (label : ℕ → ι) (tau rho eta d : ℝ) (hC : 0 < C.card) (heta : 0 ≤ eta) + (hgap : eta+d < rho) (f : ℕ → ℝ) (hf : ∀ q ∈ C,f q ≤ 1) + (hMass : rho*(C.card : ℝ) ≤ ∑ q ∈ C,f q) + (hDiscard : ((discardedPoints C label tau).card : ℝ) ≤ d*(C.card : ℝ)) : + ∃ i : ι,tau ≤ ((labelFiber C label i).card : ℝ) ∧ + eta*((labelFiber C label i).card : ℝ) < ∑ q ∈ labelFiber C label i,f q := by + classical + by_contra hno + push Not at hno + have hcell : ∀ i : ι,(∑ q ∈ labelFiber C label i,f q) ≤ eta*((labelFiber C label i).card : ℝ)+ + (if ((labelFiber C label i).card : ℝ) < tau then ((labelFiber C label i).card : ℝ) else 0) := by + intro i + by_cases hi : ((labelFiber C label i).card : ℝ) < tau + · rw [ite_eq_left hi] + have hfi : (∑ q ∈ labelFiber C label i,f q) ≤ ((labelFiber C label i).card : ℝ) := by + simpa only [Finset.sum_const,nsmul_eq_mul,mul_one] using + Finset.sum_le_sum (fun q hq => hf q (labelFiber_subset C label i hq)) + nlinarith [show (0 : ℝ) ≤ (labelFiber C label i).card from Nat.cast_nonneg _] + · rw [ite_eq_right hi,add_zero] + exact hno i (le_of_not_gt hi) + have hcard : (∑ i : ι,((labelFiber C label i).card : ℝ)) = (C.card : ℝ) := by + simpa only [Finset.sum_const,nsmul_eq_mul,mul_one] using sum_label_fibers C label (fun _ => (1 : ℝ)) + have hsmall : (∑ i : ι,if ((labelFiber C label i).card : ℝ) < tau then ((labelFiber C label i).card : ℝ) else 0) = + ((discardedPoints C label tau).card : ℝ) := by + have hh := sum_small_fibers C label tau (fun _ => (1 : ℝ)) + simpa only [Finset.sum_const,nsmul_eq_mul,mul_one,smallLabels,Finset.sum_filter] using hh + have hsum : (∑ q ∈ C,f q) ≤ eta*(C.card : ℝ)+((discardedPoints C label tau).card : ℝ) := by + calc + _ = ∑ i : ι,∑ q ∈ labelFiber C label i,f q := (sum_label_fibers C label f).symm + _ ≤ ∑ i : ι,(eta*((labelFiber C label i).card : ℝ)+ + (if ((labelFiber C label i).card : ℝ) < tau then ((labelFiber C label i).card : ℝ) else 0)) := + Finset.sum_le_sum (fun i _ => hcell i) + _ = _ := by rw [Finset.sum_add_distrib,← Finset.mul_sum,hcard,hsmall] + have hCp : (0 : ℝ) < C.card := by exact_mod_cast hC + have hstrict := mul_lt_mul_of_pos_right hgap hCp + nlinarith + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegenerativeResolvent.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegenerativeResolvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..f2bc60b3fd8a761bdbdd59e70b545f302dccebce --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegenerativeResolvent.lean @@ -0,0 +1,92 @@ +import OAI.NumberTheory.Jacobsthal.Probability.FiniteKernelResolvent +import OAI.NumberTheory.Jacobsthal.Renewal.KernelPotential + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory ProbabilityTheory Filter +open scoped ENNReal ProbabilityTheory Topology +namespace Erdos970Dependency.RegenerativeResolvent +open NumberTheoryLean.KernelPotential FiniteKernelResolvent +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + +theorem restrict_kernel_comp (P : Kernel X X) (mu : Measure X) {R : Set X} (hR : MeasurableSet R) : + P.restrict hR ∘ₘ mu = (P ∘ₘ mu).restrict R := by + ext B hB + rw [Measure.bind_apply hB (P.restrict hR).aemeasurable, Measure.restrict_apply hB, + Measure.bind_apply (hB.inter hR) P.aemeasurable] + apply lintegral_congr + intro s + rw [Kernel.restrict_apply, Measure.restrict_apply hB] + +theorem compose_sum_measure (B : Kernel X Y) (mu : ℕ → Measure X) : + B ∘ₘ Measure.sum mu = Measure.sum (fun n ↦ B ∘ₘ mu n) := by + ext S hS + rw [Measure.bind_apply hS B.aemeasurable, lintegral_sum_measure, Measure.sum_apply _ hS] + congr 1 + funext n + exact (Measure.bind_apply hS B.aemeasurable).symm + +theorem common_on_restriction (B : Kernel X Y) (mu : Measure X) {R : Set X} + (hR : MeasurableSet R) (r : X) (hB : ∀ s ∈ R, B s = B r) : + B ∘ₘ mu.restrict R = mu R • B r := by + ext S hS + rw [Measure.bind_apply hS B.aemeasurable, Measure.smul_apply, smul_eq_mul] + calc + (∫⁻ s, B s S ∂mu.restrict R) = ∫⁻ _s, B r S ∂mu.restrict R := by + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem hR] with s hs + rw [hB s hs] + _ = _ := by simp [mul_comm] + +theorem post_power_common (B : Kernel X Y) (Q : Kernel X X) (R : Set X) (r : X) + (hB : ∀ s ∈ R, B s = B r) (hQ : ∀ s ∈ R, Q s = Q r) (n : ℕ) : + ∀ s ∈ R, (B ∘ₖ (Q ^ n)) s = (B ∘ₖ (Q ^ n)) r := by + intro s hs + cases n with + | zero => + change (B ∘ₖ Kernel.id) s = (B ∘ₖ Kernel.id) r + rw [Kernel.comp_id] + exact hB s hs + | succ n => + rw [pow_succ] + change (B ∘ₖ ((Q ^ n) ∘ₖ Q)) s = (B ∘ₖ ((Q ^ n) ∘ₖ Q)) r + rw [← Kernel.comp_assoc] + rw [Kernel.comp_apply, Kernel.comp_apply, hQ s hs] + +theorem post_resolvent (B : Kernel X Y) (Q : Kernel X X) (mu : Measure X) [IsFiniteMeasure mu] + (R : Set X) (hR : MeasurableSet R) (r : X) + (hfix : mu = mu.restrict R + Q ∘ₘ mu) + (hsub : ∀ n s, (Q ^ n) s univ ≤ 1) + (htail : ∀ s, Tendsto (fun n : ℕ ↦ (Q ^ n) s univ) atTop (𝓝 0)) + (hB : ∀ s ∈ R, B s = B r) (hQ : ∀ s ∈ R, Q s = Q r) : + B ∘ₘ mu = mu R • (potential B Q) r := by + have hresolve := fixed_point_resolvent Q mu (mu.restrict R) hfix hsub htail + calc + B ∘ₘ mu = B ∘ₘ Measure.sum (fun n : ℕ ↦ (Q ^ n) ∘ₘ mu.restrict R) := + congrArg (fun nu ↦ B ∘ₘ nu) hresolve + _ = Measure.sum (fun n : ℕ ↦ (B ∘ₖ (Q ^ n)) ∘ₘ mu.restrict R) := by + rw [compose_sum_measure] + congr 1 + funext n + exact Measure.comp_assoc + _ = Measure.sum (fun n : ℕ ↦ mu R • (B ∘ₖ (Q ^ n)) r) := by + congr 1 + funext n + exact common_on_restriction _ mu hR r (post_power_common B Q R r hB hQ n) + _ = mu R • (potential B Q) r := by + ext S hS + rw [Measure.sum_apply _ hS, Measure.smul_apply, smul_eq_mul, potential, Kernel.sum_apply' _ _ hS] + simp only [Measure.smul_apply, smul_eq_mul] + exact ENNReal.tsum_mul_left + +end Erdos970Dependency.RegenerativeResolvent + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegularImplicitArc.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegularImplicitArc.lean new file mode 100644 index 0000000000000000000000000000000000000000..14eb115f19ffd0595678ca044f097820c20a5d63 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegularImplicitArc.lean @@ -0,0 +1,731 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Analysis.ImplicitDerivatives + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosLatticeChain + +def vectorLength (v : ℕ × ℕ) : ℕ := v.1+v.2 + +def totalLength (V : Finset (ℕ × ℕ)) : ℕ := ∑ v ∈ V, vectorLength v + +def shortVectors (V : Finset (ℕ × ℕ)) (T : ℕ) : Finset (ℕ × ℕ) := + V.filter fun v => vectorLength v ≤ T + +def longVectors (V : Finset (ℕ × ℕ)) (T : ℕ) : Finset (ℕ × ℕ) := + V.filter fun v => T < vectorLength v + +def shortSquareEmbedding (V : Finset (ℕ × ℕ)) (T : ℕ) : + ↥(shortVectors V T) ↪ (Fin (T+1) × Fin (T+1)) where + toFun v := + (⟨v.1.1, by + have h := (Finset.mem_filter.mp v.2).2 + dsimp [vectorLength] at h + omega⟩, + ⟨v.1.2, by + have h := (Finset.mem_filter.mp v.2).2 + dsimp [vectorLength] at h + omega⟩) + inj' := by + intro u v h + apply Subtype.ext + apply Prod.ext + · exact congrArg (fun w : Fin (T+1) × Fin (T+1) => w.1.val) h + · exact congrArg (fun w : Fin (T+1) × Fin (T+1) => w.2.val) h + +theorem short_card_le_square (V : Finset (ℕ × ℕ)) (T : ℕ) : + (shortVectors V T).card ≤ (T+1)^2 := by + have h := Fintype.card_le_of_embedding (shortSquareEmbedding V T) + simpa [pow_two] using h + +theorem short_long_card (V : Finset (ℕ × ℕ)) (T : ℕ) : + (shortVectors V T).card+(longVectors V T).card = V.card := by + simpa only [shortVectors, longVectors, not_le] using + Finset.card_filter_add_card_filter_not (s := V) (fun v => vectorLength v ≤ T) + +theorem long_card_mul_le_length (V : Finset (ℕ × ℕ)) (T : ℕ) : + (T+1)*(longVectors V T).card ≤ totalLength V := by + calc + _ = ∑ _v ∈ longVectors V T, (T+1) := by simp [mul_comm] + _ ≤ ∑ v ∈ longVectors V T, vectorLength v := by + apply Finset.sum_le_sum + intro v hv + exact (Finset.mem_filter.mp hv).2 + _ ≤ ∑ v ∈ V, vectorLength v := Finset.sum_le_sum_of_subset + (Finset.filter_subset _ _) + _ = _ := rfl + +theorem card_le_square_add_div (V : Finset (ℕ × ℕ)) (T : ℕ) {L : ℝ} + (hL : (totalLength V : ℝ) ≤ L) : + (V.card : ℝ) ≤ ((T : ℝ)+1)^2+L/((T : ℝ)+1) := by + have hden : (0 : ℝ) < (T : ℝ)+1 := by positivity + have hs : ((shortVectors V T).card : ℝ) ≤ ((T : ℝ)+1)^2 := by + exact_mod_cast short_card_le_square V T + have hl : ((T : ℝ)+1)*((longVectors V T).card : ℝ) ≤ L := by + have h : ((T : ℝ)+1)*((longVectors V T).card : ℝ) ≤ (totalLength V : ℝ) := by + exact_mod_cast long_card_mul_le_length V T + exact h.trans hL + have hld : ((longVectors V T).card : ℝ) ≤ L/((T : ℝ)+1) := + (le_div_iff₀ hden).mpr (by nlinarith only [hl]) + have he : ((shortVectors V T).card : ℝ)+((longVectors V T).card : ℝ) = (V.card : ℝ) := by + exact_mod_cast short_long_card V T + linarith + +end ErdosLatticeChain + +end + +section + +open scoped BigOperators +namespace ErdosLatticeChain + +theorem consecutive_sum {n : ℕ} (f : Fin (n+1) → ℤ) : + (∑ i : Fin n, (f i.succ-f i.castSucc)) = f (Fin.last n)-f 0 := by + have hfirst := Fin.sum_univ_succ f + have hlast := Fin.sum_univ_castSucc f + rw [Finset.sum_sub_distrib] + linarith + +def coordinateVariation {n : ℕ} (f : Fin (n+1) → ℤ) : ℕ := + ∑ i : Fin n, (f i.succ-f i.castSucc).natAbs + +theorem variation_of_monotone {n : ℕ} (f : Fin (n+1) → ℤ) (hf : Monotone f) : + (coordinateVariation f : ℝ) = (f (Fin.last n) : ℝ)-(f 0 : ℝ) := by + have he : (coordinateVariation f : ℤ) = f (Fin.last n)-f 0 := by + unfold coordinateVariation + push_cast + rw [← consecutive_sum f] + apply Finset.sum_congr rfl + intro i _ + exact abs_of_nonneg (sub_nonneg.mpr (hf (by exact_mod_cast Nat.le_succ i.val))) + exact_mod_cast he + +theorem variation_of_antitone {n : ℕ} (f : Fin (n+1) → ℤ) (hf : Antitone f) : + (coordinateVariation f : ℝ) = (f 0 : ℝ)-(f (Fin.last n) : ℝ) := by + have he : (coordinateVariation f : ℤ) = f 0-f (Fin.last n) := by + unfold coordinateVariation + push_cast + have h := consecutive_sum f + have hneg : (∑ i : Fin n, -(f i.succ-f i.castSucc)) = f 0-f (Fin.last n) := by + rw [Finset.sum_neg_distrib, h] + ring + rw [← hneg] + apply Finset.sum_congr rfl + intro i _ + exact abs_of_nonpos (sub_nonpos.mpr (hf (by exact_mod_cast Nat.le_succ i.val))) + exact_mod_cast he + +theorem variation_le_box {n : ℕ} (f : Fin (n+1) → ℤ) (S : ℝ) + (hf : Monotone f ∨ Antitone f) (hbox : ∀ i, 0 ≤ (f i : ℝ) ∧ (f i : ℝ) ≤ S) : + (coordinateVariation f : ℝ) ≤ S := by + rcases hf with hf | hf + · rw [variation_of_monotone f hf] + linarith [(hbox 0).1, (hbox (Fin.last n)).2] + · rw [variation_of_antitone f hf] + linarith [(hbox (Fin.last n)).1, (hbox 0).2] + +end ErdosLatticeChain + +end + + +namespace ErdosLatticeChain + +theorem vector_card_bound (V : Finset (ℕ × ℕ)) {L : ℝ} (hL : 0 ≤ L) + (hlength : (totalLength V : ℝ) ≤ L) : + (V.card : ℝ) ≤ 5*(1+L^((2 : ℝ)/3)) := by + by_cases hL1 : 1 ≤ L + · have hLp : 0 < L := by linarith + let r := L^((1 : ℝ)/3) + let T := ⌊r⌋₊ + have hr : 1 ≤ r := Real.one_le_rpow hL1 (by norm_num) + have hrp : 0 < r := by linarith + have hT : (T : ℝ) ≤ r := Nat.floor_le hrp.le + have hTr : r ≤ (T : ℝ)+1 := (Nat.lt_floor_add_one r).le + have hT2 : (T : ℝ)+1 ≤ 2*r := by linarith + have hsquare : ((T : ℝ)+1)^2 ≤ 4*L^((2 : ℝ)/3) := by + calc + _ ≤ (2*r)^2 := by gcongr + _ = _ := by + dsimp [r] + rw [mul_pow, ← Real.rpow_mul_natCast hL] + norm_num + have hlong : L/((T : ℝ)+1) ≤ L^((2 : ℝ)/3) := by + calc + _ ≤ L/r := div_le_div_of_nonneg_left hL hrp hTr + _ = _ := by + dsimp [r] + rw [show (2 : ℝ)/3 = 1-1/3 by norm_num, Real.rpow_sub hLp, Real.rpow_one] + have h := card_le_square_add_div V T hlength + linarith + · have h := card_le_square_add_div V 0 hlength + have hp := Real.rpow_nonneg hL ((2 : ℝ)/3) + norm_num at h + linarith + +theorem vector_card_bound_actual (V : Finset (ℕ × ℕ)) : + (V.card : ℝ) ≤ 5*(1+(totalLength V : ℝ)^((2 : ℝ)/3)) := + vector_card_bound V (Nat.cast_nonneg _) le_rfl + +end ErdosLatticeChain + + +section + +open scoped BigOperators +namespace ErdosLatticeChain + +def earlierIndex {n : ℕ} (i : Fin (n-1)) : Fin n := ⟨i.val, by have := i.isLt; omega⟩ +def laterIndex {n : ℕ} (i : Fin (n-1)) : Fin n := ⟨i.val+1, by have := i.isLt; omega⟩ + +theorem earlier_lt_later {n : ℕ} (i : Fin (n-1)) : earlierIndex i < laterIndex i := + Nat.lt_succ_self i.val + +def consecutiveDifference {n : ℕ} (P : Fin n → ℤ × ℤ) (i : Fin (n-1)) : ℤ × ℤ := + ((P (laterIndex i)).1-(P (earlierIndex i)).1, + (P (laterIndex i)).2-(P (earlierIndex i)).2) + +def natIncrement {n : ℕ} (P : Fin n → ℤ × ℤ) (i : Fin (n-1)) : ℕ × ℕ := + ((consecutiveDifference P i).1.natAbs, (consecutiveDifference P i).2.natAbs) + +noncomputable def incrementVectors {n : ℕ} (P : Fin n → ℤ × ℤ) : Finset (ℕ × ℕ) := + Finset.univ.image (natIncrement P) + +theorem int_eq_of_natAbs_eq_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) + (h : a.natAbs = b.natAbs) : a = b := by + have hc := congrArg (fun n : ℕ => (n : ℤ)) h + simpa only [Int.natCast_natAbs, abs_of_nonneg ha, abs_of_nonneg hb] using hc + +theorem int_eq_of_natAbs_eq_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) + (h : a.natAbs = b.natAbs) : a = b := by + have hc := congrArg (fun n : ℕ => (n : ℤ)) h + have hn : -a = -b := by + simpa only [Int.natCast_natAbs, abs_of_nonpos ha, abs_of_nonpos hb] using hc + exact neg_injective hn + +theorem natIncrement_injective {n : ℕ} (P : Fin n → ℤ × ℤ) + (hx : Monotone fun i => (P i).1) + (hy : (Monotone fun i => (P i).2) ∨ (Antitone fun i => (P i).2)) + (hd : Function.Injective (consecutiveDifference P)) : Function.Injective (natIncrement P) := by + intro i j h + apply hd + apply Prod.ext + · apply int_eq_of_natAbs_eq_nonneg + (sub_nonneg.mpr (hx (earlier_lt_later i).le)) + (sub_nonneg.mpr (hx (earlier_lt_later j).le)) + exact congrArg Prod.fst h + · rcases hy with hy | hy + · apply int_eq_of_natAbs_eq_nonneg + (sub_nonneg.mpr (hy (earlier_lt_later i).le)) + (sub_nonneg.mpr (hy (earlier_lt_later j).le)) + exact congrArg Prod.snd h + · apply int_eq_of_natAbs_eq_nonpos + (sub_nonpos.mpr (hy (earlier_lt_later i).le)) + (sub_nonpos.mpr (hy (earlier_lt_later j).le)) + exact congrArg Prod.snd h + +theorem incrementVectors_card {n : ℕ} (P : Fin n → ℤ × ℤ) + (hi : Function.Injective (natIncrement P)) : (incrementVectors P).card = n-1 := by + rw [incrementVectors, Finset.card_image_of_injective _ hi, Finset.card_univ, Fintype.card_fin] + +theorem incrementVectors_length {n : ℕ} (P : Fin (n+1) → ℤ × ℤ) + (hi : Function.Injective (natIncrement P)) : + totalLength (incrementVectors P) = + coordinateVariation (fun i => (P i).1)+coordinateVariation (fun i => (P i).2) := by + unfold totalLength incrementVectors + rw [Finset.sum_image] + · change (∑ i : Fin n, (((P i.succ).1-(P i.castSucc).1).natAbs + + ((P i.succ).2-(P i.castSucc).2).natAbs)) = _ + rw [Finset.sum_add_distrib] + rfl + · exact fun i _ j _ h => hi h + +theorem consecutive_first_pos {n : ℕ} (P : Fin n → ℤ × ℤ) + (hx : StrictMono fun i => (P i).1) (i : Fin (n-1)) : + 0 < (consecutiveDifference P i).1 := sub_pos.mpr (hx (earlier_lt_later i)) + +end ErdosLatticeChain + +end + + +namespace ErdosImplicitCurvature + +noncomputable def inflectionPolynomial (Q : Bivariate) : Bivariate := + partialX (partialX Q)*(partialY Q)^2 - + 2*partialX (partialY Q)*partialX Q*partialY Q + + partialY (partialY Q)*(partialX Q)^2 + +theorem peval_inflectionPolynomial (Q : Bivariate) (x y : ℝ) : + peval (inflectionPolynomial Q) x y = + peval (partialX (partialX Q)) x y*(peval (partialY Q) x y)^2 - + 2*peval (partialX (partialY Q)) x y*peval (partialX Q) x y*peval (partialY Q) x y + + peval (partialY (partialY Q)) x y*(peval (partialX Q) x y)^2 := by + simp [inflectionPolynomial, peval] + +theorem curvature_scalar_identity {a b c d e u v : ℝ} (hb : b ≠ 0) + (h1 : a+b*u = 0) (h2 : c+2*d*u+e*u^2+b*v = 0) : + u = -a/b ∧ v = -(c*b^2-2*d*a*b+e*a^2)/b^3 := by + have hu : u = -a/b := (eq_div_iff hb).mpr (by nlinarith only [h1]) + refine ⟨hu, ?_⟩ + apply (eq_div_iff (pow_ne_zero 3 hb)).mpr + rw [hu] at h2 + field_simp at h2 + linear_combination h2 + +theorem implicit_derivatives (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hf : ContDiffOn ℝ 2 f I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) + (hQy : peval (partialY Q) x (f x) ≠ 0) : + deriv f x = -peval (partialX Q) x (f x)/peval (partialY Q) x (f x) ∧ + deriv (deriv f) x = -peval (inflectionPolynomial Q) x (f x)/(peval (partialY Q) x (f x))^3 := by + rw [peval_inflectionPolynomial] + exact curvature_scalar_identity hQy + (implicit_first_equation Q f hI (hf.differentiableOn (by norm_num)) hcurve hx) + (implicit_second_equation Q f hI hf hcurve hx) + +theorem implicit_second_derivative (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hf : ContDiffOn ℝ 2 f I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) + (hQy : peval (partialY Q) x (f x) ≠ 0) : + deriv (deriv f) x = -peval (inflectionPolynomial Q) x (f x)/(peval (partialY Q) x (f x))^3 := + (implicit_derivatives Q f hI hf hcurve hx hQy).2 + +theorem curvature_zero_iff (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hf : ContDiffOn ℝ 2 f I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) + (hQy : peval (partialY Q) x (f x) ≠ 0) : + deriv (deriv f) x = 0 ↔ peval (inflectionPolynomial Q) x (f x) = 0 := by + rw [implicit_second_derivative Q f hI hf hcurve hx hQy] + simp [div_eq_zero_iff, hQy] + +theorem curvature_ne_zero_iff (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hf : ContDiffOn ℝ 2 f I) + (hcurve : ∀ t ∈ I, peval Q t (f t) = 0) {x : ℝ} (hx : x ∈ I) + (hQy : peval (partialY Q) x (f x) ≠ 0) : + deriv (deriv f) x ≠ 0 ↔ peval (inflectionPolynomial Q) x (f x) ≠ 0 := + not_congr (curvature_zero_iff Q f hI hf hcurve hx hQy) + +end ErdosImplicitCurvature + + + +namespace ErdosLatticeChain + +theorem lattice_chain_bound {n : ℕ} (P : Fin n → ℤ × ℤ) (S : ℝ) (hS : 0 ≤ S) + (hx : StrictMono fun i => (P i).1) + (hy : (Monotone fun i => (P i).2) ∨ (Antitone fun i => (P i).2)) + (hbox : ∀ i, (0 ≤ ((P i).1 : ℝ) ∧ ((P i).1 : ℝ) ≤ S) ∧ + (0 ≤ ((P i).2 : ℝ) ∧ ((P i).2 : ℝ) ≤ S)) + (hd : Function.Injective (consecutiveDifference P)) : + (n : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := by + have hp : 0 ≤ S^((2 : ℝ)/3) := Real.rpow_nonneg hS _ + cases n with + | zero => simp only [Nat.cast_zero]; positivity + | succ n => + have hi := natIncrement_injective P hx.monotone hy hd + have hcard : (incrementVectors P).card = n := by + simpa using incrementVectors_card P hi + have hlength : (totalLength (incrementVectors P) : ℝ) ≤ 2*S := by + rw [incrementVectors_length P hi, Nat.cast_add] + have h1 := variation_le_box (fun i => (P i).1) S (Or.inl hx.monotone) (fun i => (hbox i).1) + have h2 := variation_le_box (fun i => (P i).2) S hy (fun i => (hbox i).2) + linarith + have hv := vector_card_bound (incrementVectors P) (show 0 ≤ 2*S by positivity) hlength + rw [hcard] at hv + have htwo : (2*S)^((2 : ℝ)/3) ≤ 2*S^((2 : ℝ)/3) := by + rw [Real.mul_rpow (by norm_num) hS] + apply mul_le_mul_of_nonneg_right _ hp + have h := Real.rpow_le_rpow_of_exponent_le (show (1 : ℝ) ≤ 2 by norm_num) + (show (2 : ℝ)/3 ≤ 1 by norm_num) + simpa only [Real.rpow_one] using h + simp only [Nat.cast_succ] + linarith + +noncomputable def chainPoints {n : ℕ} (P : Fin n → ℤ × ℤ) : Finset (ℤ × ℤ) := + Finset.univ.image P + +theorem lattice_chain_card_bound {n : ℕ} (P : Fin n → ℤ × ℤ) (S : ℝ) (hS : 0 ≤ S) + (hx : StrictMono fun i => (P i).1) + (hy : (Monotone fun i => (P i).2) ∨ (Antitone fun i => (P i).2)) + (hbox : ∀ i, (0 ≤ ((P i).1 : ℝ) ∧ ((P i).1 : ℝ) ≤ S) ∧ + (0 ≤ ((P i).2 : ℝ) ∧ ((P i).2 : ℝ) ≤ S)) + (hd : Function.Injective (consecutiveDifference P)) : + ((chainPoints P).card : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := by + have hi : Function.Injective P := by + intro i j h + exact hx.injective (congrArg Prod.fst h) + rw [chainPoints, Finset.card_image_of_injective _ hi, Finset.card_univ, Fintype.card_fin] + exact lattice_chain_bound P S hS hx hy hbox hd + +noncomputable def consecutiveSlope {n : ℕ} (P : Fin n → ℤ × ℤ) (i : Fin (n-1)) : ℝ := + ((consecutiveDifference P i).2 : ℝ)/((consecutiveDifference P i).1 : ℝ) + +theorem difference_injective_of_slope {n : ℕ} (P : Fin n → ℤ × ℤ) + (hs : Function.Injective (consecutiveSlope P)) : + Function.Injective (consecutiveDifference P) := by + intro i j h + apply hs + exact congrArg (fun v : ℤ × ℤ => (v.2 : ℝ)/(v.1 : ℝ)) h + +theorem lattice_chain_strict_slopes {n : ℕ} (P : Fin n → ℤ × ℤ) (S : ℝ) (hS : 0 ≤ S) + (hx : StrictMono fun i => (P i).1) + (hy : (Monotone fun i => (P i).2) ∨ (Antitone fun i => (P i).2)) + (hbox : ∀ i, (0 ≤ ((P i).1 : ℝ) ∧ ((P i).1 : ℝ) ≤ S) ∧ + (0 ≤ ((P i).2 : ℝ) ∧ ((P i).2 : ℝ) ≤ S)) + (hs : StrictMono (consecutiveSlope P) ∨ StrictAnti (consecutiveSlope P)) : + ((chainPoints P).card : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := by + apply lattice_chain_card_bound P S hS hx hy hbox + apply difference_injective_of_slope P + rcases hs with hs | hs + · exact hs.injective + · exact hs.injective + +end ErdosLatticeChain + + + +namespace ErdosConvexGraph + +open ErdosLatticeChain + +theorem convex_secants_lt {I : Set ℝ} {f : ℝ → ℝ} (hf : StrictConvexOn ℝ I f) + {a b c d : ℝ} (ha : a ∈ I) (hb : b ∈ I) (hc : c ∈ I) (hd : d ∈ I) + (hab : a < b) (hbc : b ≤ c) (hcd : c < d) : + (f b-f a)/(b-a) < (f d-f c)/(d-c) := by + rcases eq_or_lt_of_le hbc with hbc | hbc + · subst c + exact hf.slope_strict_mono_adjacent ha hd hab hcd + · exact (hf.slope_strict_mono_adjacent ha hc hab hbc).trans + (hf.slope_strict_mono_adjacent hb hd hbc hcd) + +theorem concave_secants_lt {I : Set ℝ} {f : ℝ → ℝ} (hf : StrictConcaveOn ℝ I f) + {a b c d : ℝ} (ha : a ∈ I) (hb : b ∈ I) (hc : c ∈ I) (hd : d ∈ I) + (hab : a < b) (hbc : b ≤ c) (hcd : c < d) : + (f d-f c)/(d-c) < (f b-f a)/(b-a) := by + rcases eq_or_lt_of_le hbc with hbc | hbc + · subst c + exact hf.slope_anti_adjacent ha hd hab hcd + · exact (hf.slope_anti_adjacent hb hd hbc hcd).trans + (hf.slope_anti_adjacent ha hc hab hbc) + +noncomputable def secantSlopes {n : ℕ} (f : ℝ → ℝ) (x : Fin n → ℝ) + (i : Fin (n-1)) : ℝ := + (f (x (laterIndex i))-f (x (earlierIndex i)))/(x (laterIndex i)-x (earlierIndex i)) + +theorem consecutive_intervals_ordered {n : ℕ} {i j : Fin (n-1)} (hij : i < j) : + laterIndex i ≤ earlierIndex j := Nat.succ_le_of_lt hij + +theorem convex_secantSlopes_strictMono {n : ℕ} {I : Set ℝ} {f : ℝ → ℝ} + (hf : StrictConvexOn ℝ I f) (x : Fin n → ℝ) (hx : StrictMono x) + (hdom : ∀ i, x i ∈ I) : StrictMono (secantSlopes f x) := by + intro i j hij + exact convex_secants_lt hf (hdom _) (hdom _) (hdom _) (hdom _) + (hx (earlier_lt_later i)) (hx.monotone (consecutive_intervals_ordered hij)) + (hx (earlier_lt_later j)) + +theorem concave_secantSlopes_strictAnti {n : ℕ} {I : Set ℝ} {f : ℝ → ℝ} + (hf : StrictConcaveOn ℝ I f) (x : Fin n → ℝ) (hx : StrictMono x) + (hdom : ∀ i, x i ∈ I) : StrictAnti (secantSlopes f x) := by + intro i j hij + exact concave_secants_lt hf (hdom _) (hdom _) (hdom _) (hdom _) + (hx (earlier_lt_later i)) (hx.monotone (consecutive_intervals_ordered hij)) + (hx (earlier_lt_later j)) + +theorem consecutiveSlope_eq_secantSlopes {n : ℕ} (P : Fin n → ℤ × ℤ) (f : ℝ → ℝ) + (hgraph : ∀ i, ((P i).2 : ℝ) = f ((P i).1 : ℝ)) : + consecutiveSlope P = secantSlopes f (fun i => ((P i).1 : ℝ)) := by + funext i + simp only [consecutiveSlope, consecutiveDifference, secantSlopes, Int.cast_sub, hgraph] + +end ErdosConvexGraph + + + +namespace ErdosConvexGraph + +open ErdosLatticeChain + +def OnGraph (I : Set ℝ) (f : ℝ → ℝ) (p : ℤ × ℤ) : Prop := + (p.1 : ℝ) ∈ I ∧ (p.2 : ℝ) = f (p.1 : ℝ) + +def InSquare (S : ℝ) (p : ℤ × ℤ) : Prop := + (0 ≤ (p.1 : ℝ) ∧ (p.1 : ℝ) ≤ S) ∧ (0 ≤ (p.2 : ℝ) ∧ (p.2 : ℝ) ≤ S) + +theorem graph_chain_y_monotone {n : ℕ} (P : Fin n → ℤ × ℤ) (I : Set ℝ) (f : ℝ → ℝ) + (hx : Monotone fun i => (P i).1) + (hf : MonotoneOn f I ∨ AntitoneOn f I) (hgraph : ∀ i, OnGraph I f (P i)) : + (Monotone fun i => (P i).2) ∨ (Antitone fun i => (P i).2) := by + rcases hf with hf | hf + · left + intro i j hij + have h := hf (hgraph i).1 (hgraph j).1 (show ((P i).1 : ℝ) ≤ ((P j).1 : ℝ) by + exact_mod_cast hx hij) + rw [← (hgraph i).2, ← (hgraph j).2] at h + exact_mod_cast h + · right + intro i j hij + have h := hf (hgraph i).1 (hgraph j).1 (show ((P i).1 : ℝ) ≤ ((P j).1 : ℝ) by + exact_mod_cast hx hij) + rw [← (hgraph i).2, ← (hgraph j).2] at h + exact_mod_cast h + +theorem graph_chain_slopes {n : ℕ} (P : Fin n → ℤ × ℤ) (I : Set ℝ) (f : ℝ → ℝ) + (hx : StrictMono fun i => (P i).1) + (hf : StrictConvexOn ℝ I f ∨ StrictConcaveOn ℝ I f) + (hgraph : ∀ i, OnGraph I f (P i)) : + StrictMono (consecutiveSlope P) ∨ StrictAnti (consecutiveSlope P) := by + have hxr : StrictMono fun i => ((P i).1 : ℝ) := by + intro i j hij + change ((P i).1 : ℝ) < ((P j).1 : ℝ) + exact_mod_cast (show (P i).1 < (P j).1 from hx hij) + rw [consecutiveSlope_eq_secantSlopes P f (fun i => (hgraph i).2)] + rcases hf with hf | hf + · exact Or.inl (convex_secantSlopes_strictMono hf _ hxr (fun i => (hgraph i).1)) + · exact Or.inr (concave_secantSlopes_strictAnti hf _ hxr (fun i => (hgraph i).1)) + +theorem graph_chain_bound {n : ℕ} (P : Fin n → ℤ × ℤ) (I : Set ℝ) (f : ℝ → ℝ) + (S : ℝ) (hS : 0 ≤ S) (hx : StrictMono fun i => (P i).1) + (hcurve : StrictConvexOn ℝ I f ∨ StrictConcaveOn ℝ I f) + (hmono : MonotoneOn f I ∨ AntitoneOn f I) + (hgraph : ∀ i, OnGraph I f (P i)) (hbox : ∀ i, InSquare S (P i)) : + (n : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := by + apply lattice_chain_bound P S hS hx (graph_chain_y_monotone P I f hx.monotone hmono hgraph) hbox + apply difference_injective_of_slope P + rcases graph_chain_slopes P I f hx hcurve hgraph with hs | hs + · exact hs.injective + · exact hs.injective + +theorem graph_chain_card_bound {n : ℕ} (P : Fin n → ℤ × ℤ) (I : Set ℝ) (f : ℝ → ℝ) + (S : ℝ) (hS : 0 ≤ S) (hx : StrictMono fun i => (P i).1) + (hcurve : StrictConvexOn ℝ I f ∨ StrictConcaveOn ℝ I f) + (hmono : MonotoneOn f I ∨ AntitoneOn f I) + (hgraph : ∀ i, OnGraph I f (P i)) (hbox : ∀ i, InSquare S (P i)) : + ((chainPoints P).card : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := + lattice_chain_strict_slopes P S hS hx (graph_chain_y_monotone P I f hx.monotone hmono hgraph) + hbox (graph_chain_slopes P I f hx hcurve hgraph) + +end ErdosConvexGraph + + + +namespace ErdosConvexGraph + +def graphAbscissae (G : Finset (ℤ × ℤ)) : Finset ℤ := G.image Prod.fst + +noncomputable def graphEnumeration (G : Finset (ℤ × ℤ)) (f : ℝ → ℝ) + (i : Fin (graphAbscissae G).card) : ℤ × ℤ := + ((graphAbscissae G).orderEmbOfFin rfl i, + ⌊f (((graphAbscissae G).orderEmbOfFin rfl i : ℤ) : ℝ)⌋) + +theorem onGraph_fst_injective {I : Set ℝ} {f : ℝ → ℝ} {p q : ℤ × ℤ} + (hp : OnGraph I f p) (hq : OnGraph I f q) (h : p.1 = q.1) : p = q := by + apply Prod.ext h + have he : (p.2 : ℝ) = (q.2 : ℝ) := by rw [hp.2, hq.2, h] + exact_mod_cast he + +theorem graphAbscissae_card (G : Finset (ℤ × ℤ)) (I : Set ℝ) (f : ℝ → ℝ) + (hG : ∀ p ∈ G, OnGraph I f p) : (graphAbscissae G).card = G.card := by + apply Finset.card_image_of_injOn + intro p hp q hq h + exact onGraph_fst_injective (hG p hp) (hG q hq) h + +theorem graphEnumeration_mem (G : Finset (ℤ × ℤ)) (I : Set ℝ) (f : ℝ → ℝ) + (hG : ∀ p ∈ G, OnGraph I f p) (i : Fin (graphAbscissae G).card) : + graphEnumeration G f i ∈ G := by + have hm := (graphAbscissae G).orderEmbOfFin_mem rfl i + obtain ⟨p, hp, he⟩ := Finset.mem_image.mp hm + have hpoint : graphEnumeration G f i = p := by + apply Prod.ext + · exact he.symm + · change ⌊f (((graphAbscissae G).orderEmbOfFin rfl i : ℤ) : ℝ)⌋ = p.2 + rw [← he, ← (hG p hp).2] + exact Int.floor_intCast _ + rw [hpoint] + exact hp + +theorem graphEnumeration_strictMono (G : Finset (ℤ × ℤ)) (f : ℝ → ℝ) : + StrictMono fun i => (graphEnumeration G f i).1 := + ((graphAbscissae G).orderEmbOfFin rfl).strictMono + +theorem finite_graph_set_bound (G : Finset (ℤ × ℤ)) (I : Set ℝ) (f : ℝ → ℝ) + (S : ℝ) (hS : 0 ≤ S) + (hcurve : StrictConvexOn ℝ I f ∨ StrictConcaveOn ℝ I f) + (hmono : MonotoneOn f I ∨ AntitoneOn f I) + (hgraph : ∀ p ∈ G, OnGraph I f p) (hbox : ∀ p ∈ G, InSquare S p) : + (G.card : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := by + have h := graph_chain_bound (graphEnumeration G f) I f S hS + (graphEnumeration_strictMono G f) hcurve hmono + (fun i => hgraph _ (graphEnumeration_mem G I f hgraph i)) + (fun i => hbox _ (graphEnumeration_mem G I f hgraph i)) + rwa [graphAbscissae_card G I f hgraph] at h + + + + + +attribute [local instance] Classical.propDecidable + +noncomputable def graphLatticePoints (I : Set ℝ) (f : ℝ → ℝ) (S : ℝ) : Finset (ℤ × ℤ) := + ((Finset.Icc (0 : ℤ) ⌊S⌋).product (Finset.Icc (0 : ℤ) ⌊S⌋)).filter (OnGraph I f) + +theorem mem_graphLatticePoints (I : Set ℝ) (f : ℝ → ℝ) (S : ℝ) (p : ℤ × ℤ) : + p ∈ graphLatticePoints I f S ↔ InSquare S p ∧ OnGraph I f p := by + simp only [graphLatticePoints, InSquare, Finset.mem_filter, Finset.product_eq_sprod, + Finset.mem_product, Finset.mem_Icc, Int.le_floor, Int.cast_nonneg_iff] + +theorem graph_arc_lattice_bound (I : Set ℝ) (f : ℝ → ℝ) (S : ℝ) (hS : 0 ≤ S) + (hcurve : StrictConvexOn ℝ I f ∨ StrictConcaveOn ℝ I f) + (hmono : MonotoneOn f I ∨ AntitoneOn f I) : + ((graphLatticePoints I f S).card : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := + finite_graph_set_bound _ I f S hS hcurve hmono + (fun p hp => ((mem_graphLatticePoints I f S p).mp hp).2) + (fun p hp => ((mem_graphLatticePoints I f S p).mp hp).1) + +theorem closed_graph_arc_bound (a b : ℝ) (f : ℝ → ℝ) (S : ℝ) (hS : 0 ≤ S) + (hcurve : StrictConvexOn ℝ (Set.Icc a b) f ∨ StrictConcaveOn ℝ (Set.Icc a b) f) + (hmono : MonotoneOn f (Set.Icc a b) ∨ AntitoneOn f (Set.Icc a b)) : + ((graphLatticePoints (Set.Icc a b) f S).card : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := + graph_arc_lattice_bound _ f S hS hcurve hmono + +theorem open_graph_arc_bound (a b : ℝ) (f : ℝ → ℝ) (S : ℝ) (hS : 0 ≤ S) + (hcurve : StrictConvexOn ℝ (Set.Ioo a b) f ∨ StrictConcaveOn ℝ (Set.Ioo a b) f) + (hmono : MonotoneOn f (Set.Ioo a b) ∨ AntitoneOn f (Set.Ioo a b)) : + ((graphLatticePoints (Set.Ioo a b) f S).card : ℝ) ≤ 12*(1+S^((2 : ℝ)/3)) := + graph_arc_lattice_bound _ f S hS hcurve hmono + +end ErdosConvexGraph + + + +namespace ErdosImplicitCurvature + +noncomputable def curvatureRatio (Q : Bivariate) (f : ℝ → ℝ) (x : ℝ) : ℝ := + peval (inflectionPolynomial Q) x (f x)/(peval (partialY Q) x (f x))^3 + +theorem strictConvexOn_of_curvatureRatio (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hconv : Convex ℝ I) (hf : ContDiffOn ℝ 2 f I) + (hcurve : ∀ x ∈ I, peval Q x (f x) = 0) + (hQy : ∀ x ∈ I, peval (partialY Q) x (f x) ≠ 0) + (hsign : ∀ x ∈ I, curvatureRatio Q f x < 0) : StrictConvexOn ℝ I f := by + apply strictConvexOn_of_deriv2_pos hconv hf.continuousOn + intro x hx + have hxI := interior_subset hx + change 0 < deriv (deriv f) x + rw [implicit_second_derivative Q f hI hf hcurve hxI (hQy x hxI), neg_div] + exact neg_pos.mpr (hsign x hxI) + +theorem strictConcaveOn_of_curvatureRatio (Q : Bivariate) (f : ℝ → ℝ) {I : Set ℝ} + (hI : IsOpen I) (hconv : Convex ℝ I) (hf : ContDiffOn ℝ 2 f I) + (hcurve : ∀ x ∈ I, peval Q x (f x) = 0) + (hQy : ∀ x ∈ I, peval (partialY Q) x (f x) ≠ 0) + (hsign : ∀ x ∈ I, 0 < curvatureRatio Q f x) : StrictConcaveOn ℝ I f := by + apply strictConcaveOn_of_deriv2_neg hconv hf.continuousOn + intro x hx + have hxI := interior_subset hx + change deriv (deriv f) x < 0 + rw [implicit_second_derivative Q f hI hf hcurve hxI (hQy x hxI), neg_div] + exact neg_neg_of_pos (hsign x hxI) + +theorem implicit_graph_lattice_bound (Q : Bivariate) (f : ℝ → ℝ) (a b S : ℝ) + (hS : 0 ≤ S) (hf : ContDiffOn ℝ 2 f (Set.Ioo a b)) + (hcurve : ∀ x ∈ Set.Ioo a b, peval Q x (f x) = 0) + (hQy : ∀ x ∈ Set.Ioo a b, peval (partialY Q) x (f x) ≠ 0) + (hsign : (∀ x ∈ Set.Ioo a b, curvatureRatio Q f x < 0) ∨ + (∀ x ∈ Set.Ioo a b, 0 < curvatureRatio Q f x)) + (hmono : MonotoneOn f (Set.Ioo a b) ∨ AntitoneOn f (Set.Ioo a b)) : + ((ErdosConvexGraph.graphLatticePoints (Set.Ioo a b) f S).card : ℝ) ≤ + 12*(1+S^((2 : ℝ)/3)) := by + apply ErdosConvexGraph.open_graph_arc_bound a b f S hS _ hmono + rcases hsign with hsign | hsign + · exact Or.inl (strictConvexOn_of_curvatureRatio Q f isOpen_Ioo (convex_Ioo a b) hf hcurve hQy hsign) + · exact Or.inr (strictConcaveOn_of_curvatureRatio Q f isOpen_Ioo (convex_Ioo a b) hf hcurve hQy hsign) + + + + + +theorem continuous_nonzero_fixed_sign {I : Set ℝ} {g : ℝ → ℝ} + (hI : IsPreconnected I) (hg : ContinuousOn g I) (hne : ∀ x ∈ I, g x ≠ 0) : + (∀ x ∈ I, 0 < g x) ∨ (∀ x ∈ I, g x < 0) := by + by_cases hp : ∀ x ∈ I, 0 < g x + · exact Or.inl hp + · right + push Not at hp + obtain ⟨a, ha, hga⟩ := hp + have hneg : g a < 0 := by + rcases lt_or_eq_of_le hga with h | h + · exact h + · exact (hne a ha h).elim + intro y hy + by_contra! hgy + have hz : 0 ∈ g '' I := hI.intermediate_value ha hy hg ⟨hneg.le, hgy⟩ + obtain ⟨z, hz, he⟩ := hz + exact hne z hz he + +theorem regular_implicit_monotone (Q : Bivariate) (f : ℝ → ℝ) (a b : ℝ) + (hf : ContDiffOn ℝ 2 f (Set.Ioo a b)) + (hcurve : ∀ x ∈ Set.Ioo a b, peval Q x (f x) = 0) + (hQx : ∀ x ∈ Set.Ioo a b, peval (partialX Q) x (f x) ≠ 0) + (hQy : ∀ x ∈ Set.Ioo a b, peval (partialY Q) x (f x) ≠ 0) : + MonotoneOn f (Set.Ioo a b) ∨ AntitoneOn f (Set.Ioo a b) := by + have hd : DifferentiableOn ℝ f (Set.Ioo a b) := hf.differentiableOn (by norm_num) + have hc : ContDiffOn ℝ 1 (deriv f) (Set.Ioo a b) := hf.deriv_of_isOpen isOpen_Ioo (by norm_num) + have hne : ∀ x ∈ Set.Ioo a b, deriv f x ≠ 0 := by + intro x hx + rw [implicit_first_derivative Q f isOpen_Ioo hd hcurve hx (hQy x hx)] + exact div_ne_zero (neg_ne_zero.mpr (hQx x hx)) (hQy x hx) + rcases continuous_nonzero_fixed_sign isPreconnected_Ioo hc.continuousOn hne with hp | hn + · left + exact monotoneOn_of_deriv_nonneg (convex_Ioo a b) hf.continuousOn + (hd.mono interior_subset) (fun x hx => (hp x (interior_subset hx)).le) + · right + exact antitoneOn_of_deriv_nonpos (convex_Ioo a b) hf.continuousOn + (hd.mono interior_subset) (fun x hx => (hn x (interior_subset hx)).le) + +theorem regular_implicit_convex_or_concave (Q : Bivariate) (f : ℝ → ℝ) (a b : ℝ) + (hf : ContDiffOn ℝ 2 f (Set.Ioo a b)) + (hcurve : ∀ x ∈ Set.Ioo a b, peval Q x (f x) = 0) + (hQy : ∀ x ∈ Set.Ioo a b, peval (partialY Q) x (f x) ≠ 0) + (hInf : ∀ x ∈ Set.Ioo a b, peval (inflectionPolynomial Q) x (f x) ≠ 0) : + StrictConvexOn ℝ (Set.Ioo a b) f ∨ StrictConcaveOn ℝ (Set.Ioo a b) f := by + have hc1 : ContDiffOn ℝ 1 (deriv f) (Set.Ioo a b) := hf.deriv_of_isOpen isOpen_Ioo (by norm_num) + have hc2 : ContDiffOn ℝ 0 (deriv (deriv f)) (Set.Ioo a b) := + hc1.deriv_of_isOpen isOpen_Ioo (by norm_num) + have hne : ∀ x ∈ Set.Ioo a b, deriv (deriv f) x ≠ 0 := by + intro x hx + exact (curvature_ne_zero_iff Q f isOpen_Ioo hf hcurve hx (hQy x hx)).mpr (hInf x hx) + rcases continuous_nonzero_fixed_sign isPreconnected_Ioo hc2.continuousOn hne with hp | hn + · left + apply strictConvexOn_of_deriv2_pos (convex_Ioo a b) hf.continuousOn + intro x hx + exact hp x (interior_subset hx) + · right + apply strictConcaveOn_of_deriv2_neg (convex_Ioo a b) hf.continuousOn + intro x hx + exact hn x (interior_subset hx) + +theorem regular_implicit_arc_lattice_bound (Q : Bivariate) (f : ℝ → ℝ) (a b S : ℝ) + (hS : 0 ≤ S) (hf : ContDiffOn ℝ 2 f (Set.Ioo a b)) + (hcurve : ∀ x ∈ Set.Ioo a b, peval Q x (f x) = 0) + (hQx : ∀ x ∈ Set.Ioo a b, peval (partialX Q) x (f x) ≠ 0) + (hQy : ∀ x ∈ Set.Ioo a b, peval (partialY Q) x (f x) ≠ 0) + (hInf : ∀ x ∈ Set.Ioo a b, peval (inflectionPolynomial Q) x (f x) ≠ 0) : + ((ErdosConvexGraph.graphLatticePoints (Set.Ioo a b) f S).card : ℝ) ≤ + 12*(1+S^((2 : ℝ)/3)) := + ErdosConvexGraph.open_graph_arc_bound a b f S hS + (regular_implicit_convex_or_concave Q f a b hf hcurve hQy hInf) + (regular_implicit_monotone Q f a b hf hcurve hQx hQy) + +end ErdosImplicitCurvature + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegularStripBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegularStripBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..bac80bee18fe35e61ba7c98935ef70cc4797dd61 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RegularStripBound.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.PolynomialStripPoints + +namespace OAI + +namespace Erdos970 + +section + +open Set +namespace ErdosRegularStrip +open ErdosImplicitCurvature ErdosLocalFiberGraphs ErdosGlobalFiberBranches ErdosConvexGraph + +theorem regular_strip_lattice_bound (Q : Bivariate) (a b S : ℝ) (hS : 0 ≤ S) + (hboundary : ∀ t ∈ Ioo a b, peval Q t 0 ≠ 0 ∧ peval Q t S ≠ 0) + (hregular : ∀ t ∈ Ioo a b, ∀ y ∈ Icc 0 S, peval Q t y = 0 → + peval (partialX Q) t y ≠ 0 ∧ peval (partialY Q) t y ≠ 0 ∧ + peval (inflectionPolynomial Q) t y ≠ 0) : + ((polynomialStripPoints Q a b S).card : ℝ) ≤ + 12*(Q.totalDegree : ℝ)*(1+S^((2 : ℝ)/3)) := by + classical + have hR : Ioo a b ⊆ regularParameters Q 0 S := by + intro t ht + exact ⟨(hboundary t ht).1,(hboundary t ht).2, + fun y hy => (hregular t ht y hy.1 hy.2).2.1⟩ + obtain ⟨n,hn,f,hf,_,hvals,hcover⟩ := + global_branches_on_regular_domain Q 0 S (Ioo a b) isOpen_Ioo isPreconnected_Ioo hR + have hcurve : ∀ i, ∀ t ∈ Ioo a b, peval Q t (f i t) = 0 := + fun i t ht => (hvals i t ht).2.1 + have hparts (i : Fin n) : ((graphLatticePoints (Ioo a b) (f i) S).card : ℝ) ≤ + 12*(1+S^((2 : ℝ)/3)) := by + apply regular_implicit_arc_lattice_bound Q (f i) a b S hS (hf i) (hcurve i) + · intro t ht + exact (hregular t ht (f i t) (Ioo_subset_Icc_self (hvals i t ht).1) + (hcurve i t ht)).1 + · exact fun t ht => (hvals i t ht).2.2 + · intro t ht + exact (hregular t ht (f i t) (Ioo_subset_Icc_self (hvals i t ht).1) + (hcurve i t ht)).2.2 + have hcount : (polynomialStripPoints Q a b S).card ≤ + ∑ i : Fin n, (graphLatticePoints (Ioo a b) (f i) S).card := by + rw [strip_eq_graph_union Q a b S f hcurve hcover] + exact Finset.card_biUnion_le + calc + ((polynomialStripPoints Q a b S).card : ℝ) ≤ + ∑ i : Fin n, ((graphLatticePoints (Ioo a b) (f i) S).card : ℝ) := by exact_mod_cast hcount + _ ≤ ∑ _i : Fin n, 12*(1+S^((2 : ℝ)/3)) := Finset.sum_le_sum (fun i _ => hparts i) + _ = (n : ℝ)*(12*(1+S^((2 : ℝ)/3))) := by simp + _ ≤ (Q.totalDegree : ℝ)*(12*(1+S^((2 : ℝ)/3))) := + mul_le_mul_of_nonneg_right (by exact_mod_cast hn) (by positivity) + _ = 12*(Q.totalDegree : ℝ)*(1+S^((2 : ℝ)/3)) := by ring + +end ErdosRegularStrip + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedPairRow.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedPairRow.lean new file mode 100644 index 0000000000000000000000000000000000000000..c93636bbff453e80a84d703e943027e6c8035684 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedPairRow.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RepeatedPairEvents + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedPairRow +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain ActualProcessCoupling +open ActualCoupledHistories ActualFlagInvariant PersistentFailureFlag +open RepeatedStepRowBound RepeatedPairEvents FiniteHistoryPairLaw +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels + +attribute [local instance] Classical.propDecidable + +theorem repeatBudget_nonneg {U X xi w mesh : ℝ} (hU : 0 ≤ U) (hX : 0 < X) + (hxi : 0 ≤ xi) (hw : 1 < w) (hm : 0 ≤ mesh) : 0 ≤ repeatBudget U X xi w mesh := by + have hC := repeatDensityConstant_pos + have hlog := Real.log_pos hw + unfold repeatBudget + positivity + +variable {w ell S : ℝ} {start : Node} +variable (hwn : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem repeated_pair_row_uniform {top xi U X mesh : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hU : 0 ≤ U) (hX : 0 < X) + (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hcap : w^start.cutoff=top) + (N : ℕ) (G : Set (ChainState w ell S start)) (x : FlagState (JointState w ell S start)) : + pairProbability (sourceTransition hwn hell hS0 hS hr hs hsS mesh) + (goodRepeatPair (label (zero_lt_one.trans hw) htop hxi) X U G (Real.log start.gap) mesh N) x ≤ + ENNReal.ofReal (repeatBudget U X xi w mesh) := by + let E := goodRepeatPair (label (zero_lt_one.trans hw) htop hxi) X U G (Real.log start.gap) mesh N + by_cases hmem : ((Prod.mk x) ⁻¹' E).Nonempty + · obtain ⟨y,hy⟩ := hmem + obtain ⟨h,hleft,hne,hparent,_hG⟩ := primeRepeatPair_left _ hy.2.2 + rcases x with ⟨⟨px,rx⟩,flag⟩ + change px=some h at hleft + subst px + cases rx with + | inr u => exact False.elim hy.1 + | inl z => + have hsub : ((Prod.mk ((some h,Sum.inl z),flag)) ⁻¹' E) ⊆ + goodRepeatNext (label (zero_lt_one.trans hw) htop hxi) X (Real.log start.gap) mesh N h := by + intro y' hy' + exact ⟨hy'.2.1,primeRepeatPair_next _ h y' hy'.2.2⟩ + exact (measure_mono hsub).trans + (good_repeat_next_row hwn hell hS0 hS hr hs hsS hw htop hxi hU hX hm hmesh hcap N h hne z flag hy.1 hparent) + · have he : ((Prod.mk x) ⁻¹' E)=∅ := Set.not_nonempty_iff_eq_empty.mp hmem + change sourceTransition hwn hell hS0 hS hr hs hsS mesh x ((Prod.mk x) ⁻¹' E) ≤ _ + rw [he,measure_empty] + exact zero_le + +theorem repeated_pair_row_gated {top xi U X mesh : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hU : 0 ≤ U) (hX : 0 < X) + (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hcap : w^start.cutoff=top) + (N : ℕ) (G : Set (ChainState w ell S start)) (x : FlagState (JointState w ell S start)) : + pairProbability (sourceTransition hwn hell hS0 hS hr hs hsS mesh) + (goodRepeatPair (label (zero_lt_one.trans hw) htop hxi) X U G (Real.log start.gap) mesh N) x ≤ + ENNReal.ofReal (repeatBudget U X xi w mesh*(if x.1.1 ∈ G then 1 else 0)) := by + by_cases hx : x.1.1 ∈ G + · rw [ite_eq_left hx,mul_one] + exact repeated_pair_row_uniform hwn hell hS0 hS hr hs hsS hw htop hxi hU hX hm hmesh hcap N G x + · rw [ite_eq_right hx,mul_zero,ENNReal.ofReal_zero] + let E := goodRepeatPair (label (zero_lt_one.trans hw) htop hxi) X U G (Real.log start.gap) mesh N + have he : ((Prod.mk x) ⁻¹' E)=∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro y hy + obtain ⟨h,_he,_hn,_hU,hG⟩ := primeRepeatPair_left _ hy.2.2 + exact hx hG + change sourceTransition hwn hell hS0 hS hr hs hsS mesh x ((Prod.mk x) ⁻¹' E) ≤ 0 + rw [he,measure_empty] +end NumberTheoryLean.RepeatedPairRow + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedPositionNeighbors.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedPositionNeighbors.lean new file mode 100644 index 0000000000000000000000000000000000000000..db46536b6fea4acb826b5dbc975c0d76f65a0594 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedPositionNeighbors.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SortedLabelRepetition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedPositionNeighbors + + +theorem repeated_position_neighbor {α : Type*} {n : ℕ} (f : α → Fin n) + (pre tail : List α) (p : α) + (hord : ((pre++p::tail).map f).Pairwise (· ≥ ·)) + (hcount : 2 ≤ ((pre++p::tail).map f).count (f p)) : + (∃ pre' q,pre=pre'++[q] ∧ f q=f p) ∨ (∃ q tail',tail=q::tail' ∧ f q=f p) := by + have ho : (pre.map f).Pairwise (· ≥ ·) ∧ ((p::tail).map f).Pairwise (· ≥ ·) ∧ + ∀ a ∈ pre.map f,∀ b ∈ (p::tail).map f,a ≥ b := by + simpa only [List.map_append,List.pairwise_append] using hord + by_cases hm : f p ∈ pre.map f + · have hn : pre ≠ [] := by intro he; simp [he] at hm + let q := pre.getLast hn + have hqmem : f q ∈ pre.map f := List.mem_map.mpr ⟨q,List.getLast_mem hn,rfl⟩ + have hqge : f p ≤ f q := ho.2.2 _ hqmem _ (by simp) + have hqle : f q ≤ f p := by + have hh := ho.1.rel_getLast hm + simpa only [List.getLast_map] using hh + exact Or.inl ⟨pre.dropLast,q,(List.dropLast_append_getLast hn).symm,le_antisymm hqle hqge⟩ + · have hc : 0 < (tail.map f).count (f p) := by + have hz : (pre.map f).count (f p)=0 := List.count_eq_zero.mpr hm + simpa [List.map_append,List.count_append,hz] using hcount + have ht := List.count_pos_iff.mp hc + cases tail with + | nil => simp at ht + | cons q tail => + have hqle : f q ≤ f p := (List.pairwise_cons.mp ho.2.1).1 _ (by simp) + have htail : ((q::tail).map f).Pairwise (· ≥ ·) := (List.pairwise_cons.mp ho.2.1).2 + have hqge : f p ≤ f q := by + have hh := htail.rel_head ht + simpa using hh + exact Or.inr ⟨q,tail,rfl,le_antisymm hqle hqge⟩ +end NumberTheoryLean.RepeatedPositionNeighbors + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedSelectedOccurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedSelectedOccurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..0aa751cbf783184c6a75c6eb817d49001951ee8b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedSelectedOccurrence.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RepeatedWordEvents + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedSelectedOccurrence +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry PrimeHistories PrimeKilledChain FiniteHistoryTransport +open ActualCoupledHistories RepeatedWordEvents RepeatedPairProbability RepeatedPairEvents +open FinitePairOccurrence CompactPrefixOccurrence SourceSelectedCompactOccupation +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels + +variable {w ell S : ℝ} {start : Node} +variable (hwn : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +include hwn hell hS0 hS hr hsS in +theorem selected_repetition_probability {top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hcap : w^start.cutoff=top) (L mesh : ℝ) (N : ℕ) (E : Set (List ℕ)) + (hE : ∀ p : History w ell S start,p.primes ∈ E → + searchRepeatedWord hw htop hxi p.primes ∨ + compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L start p.primes) : + fullSourceLaw w ell S start hs mesh N {h | occurs E N h} ≤ + fullSourceLaw w ell S start hs mesh N + (pairOccurrence (rawRepeatPair (label (zero_lt_one.trans hw) htop hxi) (w^((1/4:ℝ))) S Set.univ) N) + + fullSourceLaw w ell S start hs mesh N + (pairOccurrence (rawRepeatPair (label (zero_lt_one.trans hw) htop hxi) 1 L (compactParentGate L)) N) := by + rw [fullSourceLaw_eq hwn hell hS0 hS hr hs hsS] + apply le_trans (measure_mono_ae ?_) (measure_union_le _ _) + filter_upwards [search_word_pair_occurs hwn hell hS0 hS hr hs hsS hw htop hxi hcap mesh N, + compact_word_pair_occurs hwn hell hS0 hS hr hs hsS (label (zero_lt_one.trans hw) htop hxi) hw L mesh N] with h hsearch hcompact + rintro ⟨j,hj⟩ + let k : Finset.Iic N := ⟨j.1,Finset.mem_Iic.mpr j.isLt.le⟩ + change selectedNode E ((h k).1.1) at hj + cases hp : (h k).1.1 with + | none => rw [hp] at hj; exact False.elim hj + | some p => + rw [hp] at hj + rcases hE p hj with hrep | hrep + · exact Or.inl (hsearch k p hp hrep) + · exact Or.inr (hcompact k p hp hrep) +end NumberTheoryLean.RepeatedSelectedOccurrence + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedStepRowBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedStepRowBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..43a7806f8abc97a8eb1705ee4b58fa3fd794dbd2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepeatedStepRowBound.lean @@ -0,0 +1,118 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ActualRepeatedBinStep +import OAI.NumberTheory.Jacobsthal.Probability.SourceTransitionSupport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedStepRowBound +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain ActualProcessCoupling +open ActualCoupledHistories ActualFlagInvariant PersistentFailureFlag ActualCouplingUpdates +open SourceTransitionSupport CompletedParentInterval ContinuousIntervalUpper +open ContinuousKilledBins +open ActualRepeatedBinStep RepeatedBinGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +noncomputable def repeatDensityConstant : ℝ := Classical.choose completed_parent_interval_upper + +theorem repeatDensityConstant_pos : 0 < repeatDensityConstant := + (Classical.choose_spec completed_parent_interval_upper).1 + +noncomputable def repeatBudget (U X xi w mesh : ℝ) : ℝ := + repeatDensityConstant*(U+2)^2*(U*(xi/Real.log w)/X+2*mesh) + +variable {w ell S : ℝ} {start : Node} + +def nextRepeat {n : ℕ} (lab : ℕ → Fin n) (X : ℝ) (h : History w ell S start) + (y : FlagState (JointState w ell S start)) : Prop := + match y.1.1 with + | none => False + | some k => lab (h.primes.getLastD 0)=lab (k.primes.getLastD 0) ∧ X ≤ k.node.cutoff + +theorem nextRepeat_measurable {n : ℕ} (lab : ℕ → Fin n) (X : ℝ) (h : History w ell S start) : + MeasurableSet {y | nextRepeat lab X h y} := by + have hm : Measurable (fun y : FlagState (JointState w ell S start) => y.1.1) := measurable_fst.comp measurable_fst + exact hm (show MeasurableSet {q : ChainState w ell S start | match q with + | none => False + | some k => lab (h.primes.getLastD 0)=lab (k.primes.getLastD 0) ∧ X ≤ k.node.cutoff} from trivial) + +noncomputable def goodRepeatNext {n : ℕ} (lab : ℕ → Fin n) (X v mesh : ℝ) (N : ℕ) + (h : History w ell S start) : Set (FlagState (JointState w ell S start)) := + {y | GoodAt v mesh N y.1 ∧ nextRepeat lab X h y} + +theorem goodRepeatNext_measurable {n : ℕ} (lab : ℕ → Fin n) (X v mesh : ℝ) (N : ℕ) + (h : History w ell S start) : MeasurableSet (goodRepeatNext lab X v mesh N h) := + (measurable_fst (GoodAt_measurable v mesh N)).inter (nextRepeat_measurable lab X h) + +variable (hwn : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem good_repeat_next_row {top xi U X mesh : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hU : 0 ≤ U) (hX : 0 < X) + (hm : 0 < mesh) (hmesh : mesh ≤ 1) (hcap : w^start.cutoff=top) + (N : ℕ) (h : History w ell S start) (hne : h.primes ≠ []) (z : CostState) (flag : Bool) + (hgood : GoodAt (Real.log start.gap) mesh N (some h,Sum.inl z)) (hparent : h.node.ratio ≤ U) : + sourceTransition hwn hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag) + (goodRepeatNext (label (zero_lt_one.trans hw) htop hxi) X (Real.log start.gap) mesh N h) ≤ + ENNReal.ofReal (repeatBudget U X xi w mesh) := by + let a := minRatio (stateSide z.1) (stateRatio z.1) + let H := U*(xi/Real.log w)/X+2*mesh + have hh0 : 0 ≤ xi/Real.log w := div_nonneg hxi.le (Real.log_pos hw).le + have hH : 0 ≤ H := by dsimp [H]; positivity + have hzU : stateRatio z.1 ≤ U+1 := by linarith [(abs_le.mp hgood.2.2.1).1] + have hT : MeasurableSet (Sum.inl '' closedCostBin a (a+H) : Set (CemeteryKernel.Space CostState)) := + (closedCostBin_measurable a (a+H)).inl_image + have hdom : ∀ᵐ y ∂sourceTransition hwn hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag), + y ∈ goodRepeatNext (label (zero_lt_one.trans hw) htop hxi) X (Real.log start.gap) mesh N h → + y.1.2 ∈ Sum.inl '' closedCostBin a (a+H) := by + filter_upwards [sourceTransition_live_support hwn hell hS0 hS hr hs hsS mesh h z flag] with y hsupport + intro hy + rcases y with ⟨⟨py,ry⟩,fy⟩ + cases py with + | none => exact False.elim hy.2 + | some k => + cases ry with + | inr u => exact False.elim hy.1 + | inl q => + obtain ⟨p,hp,rfl⟩ := hsupport.1 + have hl : label (zero_lt_one.trans hw) htop hxi (h.primes.getLastD 0)=label (zero_lt_one.trans hw) htop hxi p := by + simpa only [History.append_primes,List.getLastD_concat] using hy.2.1 + have hx : X ≤ primeExponent w p := by simpa only [History.append_node,step] using hy.2.2 + have hslack := (actual_same_bin_slack hw htop hell hxi hr hs hcap h hne p hp hl).2 + have hupper : (h.append p hp).node.ratio-(h.node.ratio-1) ≤ U*(xi/Real.log w)/X := by + calc + _ ≤ h.node.ratio*(xi/Real.log w)/primeExponent w p := hslack + _ ≤ U*(xi/Real.log w)/primeExponent w p := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hparent hh0) (hX.trans_le hx).le + _ ≤ _ := div_le_div_of_nonneg_left (mul_nonneg hU hh0) hX hx + have hInt := matched_repeat_interval (stateSide z.1) hgood.2.2.1 hy.1.2.2.1 hupper hsupport.2 + refine ⟨q,⟨hInt.1,?_⟩,rfl⟩ + simpa only [H,add_assoc] using hInt.2 + calc + _ ≤ sourceTransition hwn hell hS0 hS hr hs hsS mesh ((some h,Sum.inl z),flag) + ((fun y => y.1.2) ⁻¹' (Sum.inl '' closedCostBin a (a+H))) := measure_mono_ae hdom + _ = continuousChain (Real.log start.gap) ell S (.inl z) (Sum.inl '' closedCostBin a (a+H)) := by + have hmR : Measurable (fun y : FlagState (JointState w ell S start) => y.1.2) := + measurable_snd.comp measurable_fst + rw [← Measure.map_apply hmR hT, + sourceTransition_right hwn hell hS0 hS hr hs hsS] + _ ≤ ENNReal.ofReal (repeatDensityConstant*(1+(U+1))^2)*ENNReal.ofReal ((a+H)-a) := + (Classical.choose_spec completed_parent_interval_upper).2 _ _ _ _ _ _ z hzU + _ = _ := by + rw [add_sub_cancel_left,← ENNReal.ofReal_mul (mul_nonneg repeatDensityConstant_pos.le (sq_nonneg _))] + congr 1 + unfold repeatBudget H + ring +end NumberTheoryLean.RepeatedStepRowBound + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepresentativeAdmission.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepresentativeAdmission.lean new file mode 100644 index 0000000000000000000000000000000000000000..1fb02ba903d1bc2f7996694e527f7aa5a0987054 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RepresentativeAdmission.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RepresentativeStopGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.RepresentativeAdmission + +open FinitePathGeometry PrimeHistories ReferenceAdmission RepresentativeStopGeometry +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def representativeGap (rep : ℕ → ℝ) (r : ℝ) (ps : List ℕ) : ℝ := + r-(ps.map rep).sum + +theorem terminal_gap_sum (w : ℝ) (z : Node) (ps : List ℕ) : + (terminal w z ps).gap = z.gap-(ps.map (primeExponent w)).sum := by + induction ps generalizing z with + | nil => simp + | cons p ps ih => + rw [terminal_cons,ih,List.map_cons,List.sum_cons] + change z.gap-primeExponent w p-(ps.map (primeExponent w)).sum = _ + ring + +theorem representativeGap_le_actual (w : ℝ) (rep : ℕ → ℝ) (z : Node) (ps : List ℕ) + (hrep : ∀ p ∈ ps,primeExponent w p ≤ rep p) : + representativeGap rep z.gap ps ≤ (terminal w z ps).gap := by + have hs : (ps.map (primeExponent w)).sum ≤ (ps.map rep).sum := by + induction ps with + | nil => simp + | cons p ps ih => + simp only [List.map_cons,List.sum_cons] + exact add_le_add (hrep p (by simp)) (ih (fun q hq => hrep q (by simp [hq]))) + rw [terminal_gap_sum] + exact sub_le_sub_left hs z.gap + +theorem admitted_of_even_prefix_safety (w : ℝ) (z : Node) (ps : List ℕ) + (hsafe : ∀ pre : List ℕ,∀ p : ℕ,∀ tail : List ℕ,ps = pre++p::tail → + (terminal w z (pre++[p])).side = .even → + sourceHeight (primeExponent w p) ≤ (terminal w z (pre++[p])).gap) : + admitted w z.side z.gap ps := by + induction ps generalizing z with + | nil => trivial + | cons p ps ih => + constructor + · cases hi : z.side with + | even => trivial + | odd => + have h := hsafe [] p ps rfl (by simp [terminal,step,hi,Side.flip]) + exact h + · apply ih (step w z p) + intro pre q tail htail hside + have he : p::ps = (p::pre)++q::tail := by rw [List.cons_append,htail] + have h := hsafe (p::pre) q tail he (by simpa only [List.cons_append,terminal_cons] using hside) + simpa only [List.cons_append,terminal_cons] using h + +theorem representative_safety_preserves_admission (w : ℝ) (rep : ℕ → ℝ) + (z : Node) (ps : List ℕ) {Delta : ℝ} (hDelta : 0 ≤ Delta) + (hrep : ∀ p ∈ ps,primeExponent w p ≤ rep p) + (hsafe : ∀ pre : List ℕ,∀ p : ℕ,∀ tail : List ℕ,ps = pre++p::tail → + (terminal w z (pre++[p])).side = .even → + sourceHeight (rep p)+3*Delta ≤ representativeGap rep z.gap (pre++[p])) : + admitted w z.side z.gap ps := by + apply admitted_of_even_prefix_safety w z ps + intro pre p tail heq hside + have hsub : ∀ q ∈ pre++[p],q ∈ ps := by + intro q hq + rw [heq] + simp only [List.mem_append,List.mem_cons] at hq ⊢ + tauto + have hg := representativeGap_le_actual w rep z (pre++[p]) (fun q hq => hrep q (hsub q hq)) + have hx : primeExponent w p ≤ rep p := hrep p (hsub p (by simp)) + exact representative_safety_admits hDelta hx hg (hsafe pre p tail heq hside) + +end NumberTheoryLean.RepresentativeAdmission + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReturnCompletionAlgebra.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReturnCompletionAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..7dddf68bbb3f1a13a07fb92dce7879440fcc0a3e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ReturnCompletionAlgebra.lean @@ -0,0 +1,82 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.RegenerationBandBounds + +namespace OAI + +namespace Erdos970 + + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.CycleRegeneration +open NumberTheoryLean.InitialRegeneration + +lemma firstReturn_succ_comp (n : ℕ) : firstReturn (n+1) = firstReturn n ∘ₖ costKilled := by + unfold firstReturn + rw [pow_succ] + exact (Kernel.comp_assoc _ _ _).symm + +lemma returnLaw_first_step : returnLaw = costCaptured + returnLaw ∘ₖ costKilled := by + have hsplit : returnLaw = firstReturn 0+Kernel.sum (fun n => firstReturn (n+1)) := by + ext z B hB + rw [returnLaw,Kernel.sum_apply' _ _ hB,add_apply,Measure.add_apply,Kernel.sum_apply' _ _ hB] + exact tsum_eq_zero_add' ENNReal.summable + calc + _ = firstReturn 0+Kernel.sum (fun n => firstReturn (n+1)) := hsplit + _ = costCaptured+(Kernel.sum firstReturn) ∘ₖ costKilled := by + congr 1 + · change costCaptured ∘ₖ (Kernel.id : Kernel OddCost OddCost) = costCaptured + exact Kernel.comp_id _ + · rw [Kernel.comp_sum_left] + apply congrArg Kernel.sum + funext n + exact firstReturn_succ_comp n + _ = _ := rfl + +lemma hitOrReturn_comp_captured : hitOrReturn ∘ₖ costCaptured = costCaptured := by + classical + have he : hitOrReturn ∘ₖ costCaptured = Kernel.id ∘ₖ costCaptured := by + ext z B hB + rw [Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB] + apply lintegral_congr_ae + have hae : ∀ᵐ y ∂costCaptured z, y ∈ returnSet := by + rw [costCaptured,Kernel.restrict_apply] + exact ae_restrict_mem returnSet_measurable + filter_upwards [hae] with y hy + rw [hitOrReturn,Kernel.piecewise_apply,ite_eq_left hy] + simpa only [Kernel.id_comp] using he + +lemma hitOrReturn_comp_killed : hitOrReturn ∘ₖ costKilled = returnLaw ∘ₖ costKilled := by + classical + ext z B hB + rw [Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB] + apply lintegral_congr_ae + have hae : ∀ᵐ y ∂costKilled z, y ∉ returnSet := by + rw [costKilled,Kernel.restrict_apply] + exact ae_restrict_mem returnSet_measurable.compl + filter_upwards [hae] with y hy + rw [hitOrReturn,Kernel.piecewise_apply,ite_eq_right hy] + +lemma complete_first_pair : hitOrReturn ∘ₖ pairedCostKernel = returnLaw := by + rw [← costCaptured_add_costKilled,Kernel.comp_add_right,hitOrReturn_comp_captured,hitOrReturn_comp_killed] + exact returnLaw_first_step.symm + +lemma hitOrReturn_translation (z : OddCost) (a : ℝ) : + (hitOrReturn z).map (shiftCost a) = hitOrReturn (shiftCost a z) := by + classical + have he : shiftCost a z ∈ returnSet ↔ z ∈ returnSet := Iff.rfl + by_cases hz : z ∈ returnSet + · rw [hitOrReturn,Kernel.piecewise_apply,ite_eq_left hz,Kernel.piecewise_apply,ite_eq_left (he.mpr hz), + Kernel.id_apply,Kernel.id_apply] + exact Measure.map_dirac' (shiftCost_measurable a) z + · rw [hitOrReturn,Kernel.piecewise_apply,ite_eq_right hz,Kernel.piecewise_apply, + ite_eq_right (fun h => hz (he.mp h))] + exact returnLaw_translation z a + +end Erdos970Dependency.MarkedVisits + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RichLineHeights.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RichLineHeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..80df7279a25ecb97b28f1383186289b9b8df3c30 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RichLineHeights.lean @@ -0,0 +1,102 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.LineCoordinateCounts + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRichLine +open ErdosConvexGraph + +theorem spacing_implies_height (N S d : ℝ) (hN : 2 ≤ N) (hd : 0 < d) + (hcount : N ≤ S/d+1) : d ≤ 2*S/N := by + have hstep : (N-1)*d ≤ S := (le_div_iff₀ hd).mp (by linarith) + have hNp : 0 < N := by linarith + apply (le_div_iff₀ hNp).mpr + nlinarith + +theorem PrimitiveIntegerLine.height_bounds (l : PrimitiveIntegerLine) + (X : Finset (ℤ × ℤ)) (S : ℝ) (hS : 0 ≤ S) (hN : 2 ≤ X.card) + (hinj : Set.InjOn Prod.fst (X : Set (ℤ × ℤ))) + (hbox : ∀ p ∈ X, InSquare S p) (hline : ∀ p ∈ X, l.Contains p) : + (l.denominator : ℝ) ≤ 2*S/(X.card : ℝ) ∧ + |(l.slope : ℝ)| ≤ 2*S/(X.card : ℝ) ∧ + |(l.intercept : ℝ)| ≤ 4*S^2/(X.card : ℝ) := by + have hNR : (2 : ℝ) ≤ X.card := by exact_mod_cast hN + have hNp : (0 : ℝ) < X.card := by linarith + have hD : (l.denominator : ℝ) ≤ 2*S/(X.card : ℝ) := + spacing_implies_height _ _ _ hNR (by exact_mod_cast l.denominator_pos) + (l.denominator_point_count X S hS hinj hbox hline) + have hA : |(l.slope : ℝ)| ≤ 2*S/(X.card : ℝ) := by + by_cases ha : l.slope = 0 + · simp only [ha,Int.cast_zero,abs_zero] + positivity + · have hh := spacing_implies_height _ _ _ hNR + (show (0 : ℝ) < l.slope.natAbs by exact_mod_cast Int.natAbs_pos.mpr ha) + (l.slope_point_count ha X S hS hbox hline) + simpa only [Nat.cast_natAbs,Int.cast_abs] using hh + obtain ⟨p,hp⟩ := Finset.card_pos.mp (show 0 < X.card by omega) + have he : (l.intercept : ℝ) = (l.denominator : ℝ)*(p.2 : ℝ)-(l.slope : ℝ)*(p.1 : ℝ) := by + have hh : l.intercept = (l.denominator : ℤ)*p.2-l.slope*p.1 := by + have hl := hline p hp + unfold Contains at hl + linarith + exact_mod_cast hh + have hb := hbox p hp + have hB : |(l.intercept : ℝ)| ≤ 4*S^2/(X.card : ℝ) := by + calc + |(l.intercept : ℝ)| ≤ |(l.denominator : ℝ)*(p.2 : ℝ)|+|(l.slope : ℝ)*(p.1 : ℝ)| := by + rw [he] + exact abs_sub _ _ + _ = (l.denominator : ℝ)*(p.2 : ℝ)+|(l.slope : ℝ)| *(p.1 : ℝ) := by + rw [abs_mul,abs_mul,abs_of_nonneg (Nat.cast_nonneg _),abs_of_nonneg hb.2.1, + abs_of_nonneg hb.1.1] + _ ≤ (2*S/(X.card : ℝ))*S+(2*S/(X.card : ℝ))*S := add_le_add + (mul_le_mul hD hb.2.2 hb.2.1 (by positivity)) + (mul_le_mul hA hb.1.2 hb.1.1 (by positivity)) + _ = 4*S^2/(X.card : ℝ) := by ring + exact ⟨hD,hA,hB⟩ + +end ErdosRichLine + +end + +section + +namespace ErdosRichLine +open ErdosCriticalGeometry ErdosComplexCurveFactors ErdosConvexGraph + +theorem exists_rich_line_with_heights (P : MV ℂ) (hP : P ≠ 0) (D : ℕ) (hD : P.totalDegree ≤ D) + (S : ℝ) (hS : 0 ≤ S) (X : Finset (ℤ × ℤ)) (hX : X ⊆ complexSquarePoints P S) + (hinj : Set.InjOn Prod.fst (X : Set (ℤ × ℤ))) (M : ℝ) (hM : 1 ≤ M) + (hlarge : 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+(D : ℝ)*M < (X.card : ℝ)) : + ∃ (F : MV ℂ) (l : PrimitiveIntegerLine) (Y : Finset (ℤ × ℤ)), + Irreducible F ∧ F ∣ P ∧ F.totalDegree = 1 ∧ + Y = X ∩ complexSquarePoints F S ∧ Y ⊆ X ∧ M < (Y.card : ℝ) ∧ + (∀ r ∈ Y, l.Contains r) ∧ + (l.denominator : ℝ) ≤ 2*S/(Y.card : ℝ) ∧ + |(l.slope : ℝ)| ≤ 2*S/(Y.card : ℝ) ∧ + |(l.intercept : ℝ)| ≤ 4*S^2/(Y.card : ℝ) := by + classical + obtain ⟨F,l,hF,hFP,hdeg,hcount,hline⟩ := exists_rich_primitive_line P hP D hD S hS X hX hinj M hM hlarge + let Y := X ∩ complexSquarePoints F S + have hsub : Y ⊆ X := Finset.inter_subset_left + have htwo : 2 ≤ Y.card := by + have hh : (1 : ℝ) < Y.card := lt_of_le_of_lt hM hcount + have hh' : 1 < Y.card := by exact_mod_cast hh + omega + have hbox : ∀ r ∈ Y, InSquare S r := fun r hr => + ((mem_complexSquarePoints F S r).mp (Finset.mem_inter.mp hr).2).1 + have hxin : Set.InjOn Prod.fst (Y : Set (ℤ × ℤ)) := + fun _ hp _ hq he => hinj (hsub hp) (hsub hq) he + obtain ⟨hden,hslope,hinter⟩ := l.height_bounds Y S hS htwo hxin hbox hline + exact ⟨F,l,Y,hF,hFP,hdeg,rfl,hsub,hcount,hline,hden,hslope,hinter⟩ + +end ErdosRichLine + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RichLinearFactor.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RichLinearFactor.lean new file mode 100644 index 0000000000000000000000000000000000000000..741a20e3a6a83ae6dd4fb9ed85a381dacfc3816d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RichLinearFactor.lean @@ -0,0 +1,343 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.ComplexComponentBound + +namespace OAI + +namespace Erdos970 + +section + +open UniqueFactorizationMonoid +namespace ErdosComplexCurveFactors +open ErdosCriticalGeometry + +@[implicit_reducible] +noncomputable def complexPolynomialNormalization : StrongNormalizationMonoid (MV ℂ) := + UniqueFactorizationMonoid.strongNormalizationMonoid + +attribute [local instance] complexPolynomialNormalization + +theorem associated_constant {F G : MV ℂ} (h : Associated F G) : + ∃ a : ℂ, a ≠ 0 ∧ G = MvPolynomial.C a * F := by + obtain ⟨u,hu⟩ := h + obtain ⟨a,ha,hua⟩ := MvPolynomial.isUnit_iff_eq_C_of_isReduced.mp u.isUnit + exact ⟨a,ha.ne_zero,by rw [← hu,hua,mul_comm]⟩ + +theorem associated_totalDegree {F G : MV ℂ} (h : Associated F G) : F.totalDegree = G.totalDegree := by + obtain ⟨a,ha,rfl⟩ := associated_constant h + exact (scalar_totalDegree a ha F).symm + +theorem associated_squarePoints {F G : MV ℂ} (h : Associated F G) (S : ℝ) : + complexSquarePoints F S = complexSquarePoints G S := by + obtain ⟨a,ha,rfl⟩ := associated_constant h + exact (complexSquare_scalar a ha F S).symm + +theorem irreducible_totalDegree_pos {F : MV ℂ} (hF : Irreducible F) : 0 < F.totalDegree := by + apply Nat.pos_of_ne_zero + intro hd + have he := MvPolynomial.totalDegree_eq_zero_iff_eq_C.mp hd + have hc : F.coeff 0 ≠ 0 := by + intro hc + apply hF.ne_zero + rw [he,hc,map_zero] + apply hF.not_isUnit + rw [he] + exact (isUnit_iff_ne_zero.mpr hc).map MvPolynomial.C + +theorem totalDegree_multiset_prod (s : Multiset (MV ℂ)) (hs : ∀ F ∈ s, F ≠ 0) : + s.prod.totalDegree = (s.map MvPolynomial.totalDegree).sum := by + induction s using Multiset.induction_on with + | empty => simp + | @cons F s ih => + have hF := hs F (Multiset.mem_cons_self _ _) + have hrest : ∀ G ∈ s, G ≠ 0 := fun G hG => hs G (Multiset.mem_cons_of_mem hG) + have hprod : s.prod ≠ 0 := Multiset.prod_ne_zero (fun h => hrest 0 h rfl) + rw [Multiset.prod_cons,MvPolynomial.totalDegree_mul_of_isDomain hF hprod, + Multiset.map_cons,Multiset.sum_cons,ih hrest] + +theorem multiset_card_le_degree_sum (s : Multiset (MV ℂ)) (hs : ∀ F ∈ s, Irreducible F) : + s.card ≤ (s.map MvPolynomial.totalDegree).sum := by + induction s using Multiset.induction_on with + | empty => simp + | @cons F s ih => + have hF := irreducible_totalDegree_pos (hs F (Multiset.mem_cons_self _ _)) + have hrest := ih (fun G hG => hs G (Multiset.mem_cons_of_mem hG)) + simp only [Multiset.card_cons,Multiset.map_cons,Multiset.sum_cons] + omega + +theorem normalizedFactors_card_le_degree (P : MV ℂ) (hP : P ≠ 0) : + (normalizedFactors P).card ≤ P.totalDegree := by + have hirr := irreducible_of_normalized_factor (a := P) + have hsum := totalDegree_multiset_prod (normalizedFactors P) (fun F hF => (hirr F hF).ne_zero) + have hassoc := associated_totalDegree (prod_normalizedFactors hP) + rw [hsum] at hassoc + exact (multiset_card_le_degree_sum (normalizedFactors P) hirr).trans hassoc.le + +noncomputable def nonlinearFactors (P : MV ℂ) : Finset (MV ℂ) := by + classical + exact (normalizedFactors P).toFinset.filter (fun F => 1 < F.totalDegree) + +theorem mem_nonlinearFactors (P F : MV ℂ) : + F ∈ nonlinearFactors P ↔ F ∈ normalizedFactors P ∧ 1 < F.totalDegree := by + classical + simp only [nonlinearFactors,Finset.mem_filter,Multiset.mem_toFinset] + +theorem nonlinearFactors_card_le_degree (P : MV ℂ) (hP : P ≠ 0) : + (nonlinearFactors P).card ≤ P.totalDegree := by + classical + exact (Finset.card_filter_le _ _).trans + ((Multiset.toFinset_card_le _).trans (normalizedFactors_card_le_degree P hP)) + +theorem nonlinearFactor_degree_le {P F : MV ℂ} (hP : P ≠ 0) (hF : F ∈ nonlinearFactors P) : + F.totalDegree ≤ P.totalDegree := + MvPolynomial.totalDegree_le_of_dvd_of_isDomain + (dvd_of_mem_normalizedFactors ((mem_nonlinearFactors P F).mp hF).1) hP + +end ErdosComplexCurveFactors + +end + +section + +open Set UniqueFactorizationMonoid +namespace ErdosComplexCurveFactors +attribute [local instance] complexPolynomialNormalization +open ErdosCriticalGeometry ErdosConvexGraph +attribute [local instance] Classical.propDecidable + +def OnNonlinearComponent (P : MV ℂ) (p : ℤ × ℤ) : Prop := + ∃ F : MV ℂ, Irreducible F ∧ F ∣ P ∧ 1 < F.totalDegree ∧ + MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0 + +noncomputable def nonlinearSquarePoints (P : MV ℂ) (S : ℝ) : Finset (ℤ × ℤ) := + ((Finset.Icc (0 : ℤ) ⌊S⌋).product (Finset.Icc (0 : ℤ) ⌊S⌋)).filter (OnNonlinearComponent P) + +theorem mem_nonlinearSquarePoints (P : MV ℂ) (S : ℝ) (p : ℤ × ℤ) : + p ∈ nonlinearSquarePoints P S ↔ InSquare S p ∧ OnNonlinearComponent P p := by + simp only [nonlinearSquarePoints,InSquare,Finset.mem_filter,Finset.product_eq_sprod, + Finset.mem_product,Finset.mem_Icc,Int.le_floor,Int.cast_nonneg_iff] + +theorem nonlinearSquare_eq_union (P : MV ℂ) (hP : P ≠ 0) (S : ℝ) : + nonlinearSquarePoints P S = (nonlinearFactors P).biUnion (fun F => complexSquarePoints F S) := by + classical + ext p + constructor + · intro hp + obtain ⟨hs,F,hF,hdiv,hdeg,hzero⟩ := (mem_nonlinearSquarePoints P S p).mp hp + obtain ⟨G,hG,hFG⟩ := exists_mem_normalizedFactors_of_dvd hP hF hdiv + have hGdeg : 1 < G.totalDegree := by rwa [← associated_totalDegree hFG] + have hpG : p ∈ complexSquarePoints G S := by + rw [← associated_squarePoints hFG S] + exact (mem_complexSquarePoints F S p).mpr ⟨hs,hzero⟩ + exact Finset.mem_biUnion.mpr ⟨G,(mem_nonlinearFactors P G).mpr ⟨hG,hGdeg⟩,hpG⟩ + · intro hp + obtain ⟨F,hF,hpF⟩ := Finset.mem_biUnion.mp hp + have hnorm := (mem_nonlinearFactors P F).mp hF + have hpoint := (mem_complexSquarePoints F S p).mp hpF + exact (mem_nonlinearSquarePoints P S p).mpr + ⟨hpoint.1,F,irreducible_of_normalized_factor F hnorm.1, + dvd_of_mem_normalizedFactors hnorm.1,hnorm.2,hpoint.2⟩ + +end ErdosComplexCurveFactors + +end + +section + +open Set UniqueFactorizationMonoid +namespace ErdosComplexCurveFactors +attribute [local instance] complexPolynomialNormalization +open ErdosCriticalGeometry + +theorem nonlinear_square_degree_four_bound (P : MV ℂ) (hP : P ≠ 0) (S : ℝ) (hS : 0 ≤ S) : + ((nonlinearSquarePoints P S).card : ℝ) ≤ + 182*(P.totalDegree : ℝ)^4*(1+S^((2 : ℝ)/3)) := by + classical + have hbound (F : MV ℂ) (hF : F ∈ nonlinearFactors P) : + ((complexSquarePoints F S).card : ℝ) ≤ + 182*(P.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3)) := by + have hm := (mem_nonlinearFactors P F).mp hF + calc + _ ≤ 182*(F.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3)) := + irreducible_complex_curve_bound F (irreducible_of_normalized_factor F hm.1) hm.2 S hS + _ ≤ _ := by + gcongr + exact_mod_cast nonlinearFactor_degree_le hP hF + have hc : (nonlinearSquarePoints P S).card ≤ + ∑ F ∈ nonlinearFactors P, (complexSquarePoints F S).card := by + rw [nonlinearSquare_eq_union P hP S] + exact Finset.card_biUnion_le + calc + ((nonlinearSquarePoints P S).card : ℝ) ≤ + ∑ F ∈ nonlinearFactors P, ((complexSquarePoints F S).card : ℝ) := by exact_mod_cast hc + _ ≤ ∑ _F ∈ nonlinearFactors P, 182*(P.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3)) := + Finset.sum_le_sum hbound + _ = ((nonlinearFactors P).card : ℝ)*(182*(P.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3))) := by simp + _ ≤ (P.totalDegree : ℝ)*(182*(P.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3))) := + mul_le_mul_of_nonneg_right (by exact_mod_cast nonlinearFactors_card_le_degree P hP) (by positivity) + _ = 182*(P.totalDegree : ℝ)^4*(1+S^((2 : ℝ)/3)) := by ring + +theorem nonlinear_square_bound_of_degree_le (P : MV ℂ) (hP : P ≠ 0) (D : ℕ) + (hD : P.totalDegree ≤ D) (S : ℝ) (hS : 0 ≤ S) : + ((nonlinearSquarePoints P S).card : ℝ) ≤ 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3)) := by + apply (nonlinear_square_degree_four_bound P hP S hS).trans + gcongr + +end ErdosComplexCurveFactors + +end + +section + +open Set +namespace ErdosComplexCurveFactors +open ErdosCriticalGeometry ErdosConvexGraph + +noncomputable def realNonlinearSquarePoints (P : MV ℝ) (S : ℝ) : Finset (ℤ × ℤ) := + nonlinearSquarePoints (complexify P) S + +theorem mem_realNonlinearSquarePoints (P : MV ℝ) (S : ℝ) (p : ℤ × ℤ) : + p ∈ realNonlinearSquarePoints P S ↔ InSquare S p ∧ + ∃ F : MV ℂ, Irreducible F ∧ F ∣ MvPolynomial.map (algebraMap ℝ ℂ) P ∧ + 1 < F.totalDegree ∧ MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0 := by + simp only [realNonlinearSquarePoints,mem_nonlinearSquarePoints,OnNonlinearComponent,complexify] + +theorem complexify_ne_zero {P : MV ℝ} (hP : P ≠ 0) : complexify P ≠ 0 := by + intro h + apply hP + apply MvPolynomial.map_injective (algebraMap ℝ ℂ) Complex.ofReal_injective + simpa only [complexify,map_zero] using h + +theorem degree_uniform_nonlinear_lattice_bound (P : MV ℝ) (hP : P ≠ 0) (D : ℕ) + (hD : P.totalDegree ≤ D) (S : ℝ) (hS : 0 ≤ S) : + ((realNonlinearSquarePoints P S).card : ℝ) ≤ 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3)) := + nonlinear_square_bound_of_degree_le (complexify P) (complexify_ne_zero hP) D + (by rwa [complexify_totalDegree]) S hS + +theorem exists_absolute_nonlinear_bound : ∃ C : ℝ, 0 < C ∧ + ∀ P : MV ℝ, P ≠ 0 → ∀ D : ℕ, 1 ≤ D → P.totalDegree ≤ D → + ∀ S : ℝ, 1 ≤ S → ((realNonlinearSquarePoints P S).card : ℝ) ≤ + C*(D : ℝ)^4*(1+S^((2 : ℝ)/3)) := by + refine ⟨182,by norm_num,?_⟩ + intro P hP D _ hD S hS + exact degree_uniform_nonlinear_lattice_bound P hP D hD S (le_trans zero_le_one hS) + +end ErdosComplexCurveFactors + +end + +section + +open UniqueFactorizationMonoid +namespace ErdosRichLine +open ErdosCriticalGeometry ErdosComplexCurveFactors ErdosConvexGraph +attribute [local instance] complexPolynomialNormalization + +noncomputable def linearFactors (P : MV ℂ) : Finset (MV ℂ) := by + classical + exact (normalizedFactors P).toFinset.filter (fun F => F.totalDegree = 1) + +theorem mem_linearFactors (P F : MV ℂ) : + F ∈ linearFactors P ↔ F ∈ normalizedFactors P ∧ F.totalDegree = 1 := by + classical + simp only [linearFactors,Finset.mem_filter,Multiset.mem_toFinset] + +theorem linearFactors_card_le_degree (P : MV ℂ) (hP : P ≠ 0) : + (linearFactors P).card ≤ P.totalDegree := by + classical + exact (Finset.card_filter_le _ _).trans + ((Multiset.toFinset_card_le _).trans (normalizedFactors_card_le_degree P hP)) + +theorem zero_mem_normalized_factor (P : MV ℂ) (hP : P ≠ 0) (p : ℤ × ℤ) + (hp : MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] P = 0) : + ∃ F ∈ normalizedFactors P, MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0 := by + classical + let ev := MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] + obtain ⟨a,ha,hprod⟩ := associated_constant (prod_normalizedFactors hP) + have hz : ev (normalizedFactors P).prod = 0 := by + have h := hp + rw [hprod,map_mul,MvPolynomial.eval_C] at h + exact (mul_eq_zero.mp h).resolve_left ha + rw [map_multiset_prod] at hz + obtain ⟨F,hF,hzF⟩ := Multiset.mem_map.mp (Multiset.prod_eq_zero_iff.mp hz) + exact ⟨F,hF,hzF⟩ + +theorem square_zero_cover (P : MV ℂ) (hP : P ≠ 0) (S : ℝ) : + complexSquarePoints P S ⊆ nonlinearSquarePoints P S ∪ + (linearFactors P).biUnion (fun F => complexSquarePoints F S) := by + classical + intro p hp + obtain ⟨hs,hzero⟩ := (mem_complexSquarePoints P S p).mp hp + obtain ⟨F,hF,hzF⟩ := zero_mem_normalized_factor P hP p hzero + have hirr := irreducible_of_normalized_factor F hF + have hpos := irreducible_totalDegree_pos hirr + by_cases hdeg : F.totalDegree = 1 + · exact Finset.mem_union_right _ (Finset.mem_biUnion.mpr + ⟨F,(mem_linearFactors P F).mpr ⟨hF,hdeg⟩, + (mem_complexSquarePoints F S p).mpr ⟨hs,hzF⟩⟩) + · exact Finset.mem_union_left _ ((mem_nonlinearSquarePoints P S p).mpr + ⟨hs,F,hirr,dvd_of_mem_normalizedFactors hF,by omega,hzF⟩) + +end ErdosRichLine + +end + +section + +namespace ErdosRichLine +open ErdosCriticalGeometry ErdosComplexCurveFactors +attribute [local instance] complexPolynomialNormalization + +theorem selected_point_cover (P : MV ℂ) (hP : P ≠ 0) (S : ℝ) (X : Finset (ℤ × ℤ)) + (hX : X ⊆ complexSquarePoints P S) : + X ⊆ nonlinearSquarePoints P S ∪ + (linearFactors P).biUnion (fun F => X ∩ complexSquarePoints F S) := by + classical + intro p hp + rcases Finset.mem_union.mp (square_zero_cover P hP S (hX hp)) with hn | hl + · exact Finset.mem_union_left _ hn + · obtain ⟨F,hF,hpF⟩ := Finset.mem_biUnion.mp hl + exact Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨F,hF,Finset.mem_inter.mpr ⟨hp,hpF⟩⟩) + +theorem selected_count_bound (P : MV ℂ) (hP : P ≠ 0) (D : ℕ) (hD : P.totalDegree ≤ D) + (S : ℝ) (hS : 0 ≤ S) (X : Finset (ℤ × ℤ)) (hX : X ⊆ complexSquarePoints P S) + (M : ℝ) (hM : 0 ≤ M) + (hsmall : ∀ F ∈ linearFactors P, ((X ∩ complexSquarePoints F S).card : ℝ) ≤ M) : + (X.card : ℝ) ≤ 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+(D : ℝ)*M := by + classical + have hc : X.card ≤ (nonlinearSquarePoints P S).card+ + ∑ F ∈ linearFactors P, (X ∩ complexSquarePoints F S).card := + (Finset.card_le_card (selected_point_cover P hP S X hX)).trans + ((Finset.card_union_le _ _).trans (Nat.add_le_add_left Finset.card_biUnion_le _)) + have hlines : ((linearFactors P).card : ℝ) ≤ (D : ℝ) := by + exact_mod_cast (linearFactors_card_le_degree P hP).trans hD + calc + (X.card : ℝ) ≤ ((nonlinearSquarePoints P S).card : ℝ)+ + ∑ F ∈ linearFactors P, ((X ∩ complexSquarePoints F S).card : ℝ) := by exact_mod_cast hc + _ ≤ 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+∑ _F ∈ linearFactors P, M := + add_le_add (nonlinear_square_bound_of_degree_le P hP D hD S hS) (Finset.sum_le_sum hsmall) + _ = 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+((linearFactors P).card : ℝ)*M := by simp + _ ≤ _ := add_le_add le_rfl (mul_le_mul_of_nonneg_right hlines hM) + +theorem exists_rich_linear_factor (P : MV ℂ) (hP : P ≠ 0) (D : ℕ) (hD : P.totalDegree ≤ D) + (S : ℝ) (hS : 0 ≤ S) (X : Finset (ℤ × ℤ)) (hX : X ⊆ complexSquarePoints P S) + (M : ℝ) (hM : 0 ≤ M) + (hlarge : 182*(D : ℝ)^4*(1+S^((2 : ℝ)/3))+(D : ℝ)*M < (X.card : ℝ)) : + ∃ F : MV ℂ, Irreducible F ∧ F ∣ P ∧ F.totalDegree = 1 ∧ + M < ((X ∩ complexSquarePoints F S).card : ℝ) := by + classical + have hex : ∃ F ∈ linearFactors P, M < ((X ∩ complexSquarePoints F S).card : ℝ) := by + by_contra h + push Not at h + exact (not_le_of_gt hlarge) (selected_count_bound P hP D hD S hS X hX M hM h) + obtain ⟨F,hF,hcard⟩ := hex + have hn := (mem_linearFactors P F).mp hF + exact ⟨F,UniqueFactorizationMonoid.irreducible_of_normalized_factor F hn.1, + UniqueFactorizationMonoid.dvd_of_mem_normalizedFactors hn.1,hn.2,hcard⟩ + +end ErdosRichLine + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszCauchy.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszCauchy.lean new file mode 100644 index 0000000000000000000000000000000000000000..bd993b283b3551564a011bd05d2b6108dd37c2e7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszCauchy.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.RieszRectangle + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Set _root_.Complex _root_.MeasureTheory + +lemma cauchy_vertical_shift (f : ℂ → ℂ) (left right T : ℝ) + (hlr : left ≤ right) (hT : 0 ≤ T) + (hf : _root_.Erdos970.HolomorphicOn f (Icc left right ×ℂ Icc (-T) T)) : + _root_.Erdos970.VIntegral f right (-T) T = _root_.Erdos970.VIntegral f left (-T) T - + _root_.Erdos970.HIntegral f left right (-T) + _root_.Erdos970.HIntegral f left right T := by + let z : ℂ := (left:ℂ)-(T:ℂ)*Complex.I + let w : ℂ := (right:ℂ)+(T:ℂ)*Complex.I + have hzr : z.re = left := by simp [z] + have hzi : z.im = -T := by simp [z] + have hwr : w.re = right := by simp [w] + have hwi : w.im = T := by simp [w] + have he : Rectangle z w = Icc left right ×ℂ Icc (-T) T := by + simp only [Rectangle,hzr,hzi,hwr,hwi,uIcc_of_le hlr,uIcc_of_le (by linarith : -T ≤ T)] + have hz := hf.vanishesOnRectangle (z := z) (w := w) (fun s hs => by simpa only [he] using hs) + simp only [_root_.Erdos970.RectangleIntegral,hzr,hzi,hwr,hwi] at hz + linear_combination hz + +lemma norm_cauchy_vertical_le (f : ℂ → ℂ) (left right T : ℝ) + (hlr : left ≤ right) (hT : 0 ≤ T) + (hf : _root_.Erdos970.HolomorphicOn f (Icc left right ×ℂ Icc (-T) T)) : + ‖_root_.Erdos970.VIntegral f right (-T) T‖ ≤ ‖_root_.Erdos970.VIntegral f left (-T) T‖ + + ‖_root_.Erdos970.HIntegral f left right (-T)‖ + ‖_root_.Erdos970.HIntegral f left right T‖ := by + rw [cauchy_vertical_shift f left right T hlr hT hf] + calc + _ ≤ ‖_root_.Erdos970.VIntegral f left (-T) T - _root_.Erdos970.HIntegral f left right (-T)‖ + + ‖_root_.Erdos970.HIntegral f left right T‖ := norm_add_le _ _ + _ ≤ _ := by gcongr; exact norm_sub_le _ _ + +lemma norm_verticalIntegral_eq (f : ℂ → ℂ) (sigma : ℝ) : + ‖_root_.Erdos970.VerticalIntegral f sigma‖ = ‖∫ t:ℝ, f ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ := by + simp only [_root_.Erdos970.VerticalIntegral,norm_smul,Complex.norm_I,one_mul] + +lemma norm_VIntegral_eq (f : ℂ → ℂ) (sigma lo hi : ℝ) : + ‖_root_.Erdos970.VIntegral f sigma lo hi‖ = ‖∫ t in lo..hi, f ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ := by + simp only [_root_.Erdos970.VIntegral,norm_smul,Complex.norm_I,one_mul] + +lemma norm_full_vertical_shift_le (f : ℂ → ℂ) (left right T : ℝ) + (hlr : left ≤ right) (hT : 0 ≤ T) + (hf : _root_.Erdos970.HolomorphicOn f (Icc left right ×ℂ Icc (-T) T)) + (hi : Integrable (fun t:ℝ => f ((right:ℂ)+(t:ℂ)*Complex.I))) : + ‖_root_.Erdos970.VerticalIntegral f right‖ ≤ + ‖∫ t in Iic (-T), f ((right:ℂ)+(t:ℂ)*Complex.I)‖ + + ‖_root_.Erdos970.VIntegral f left (-T) T‖ + ‖_root_.Erdos970.HIntegral f left right (-T)‖ + + ‖_root_.Erdos970.HIntegral f left right T‖ + + ‖∫ t in Ici T, f ((right:ℂ)+(t:ℂ)*Complex.I)‖ := by + rw [_root_.Erdos970.verticalIntegral_split_three (-T) T hi] + have h1 := norm_add_le (Complex.I • (∫ t in Iic (-T), f ((right:ℂ)+(t:ℂ)*Complex.I)) + + _root_.Erdos970.VIntegral f right (-T) T) (Complex.I • ∫ t in Ici T, f ((right:ℂ)+(t:ℂ)*Complex.I)) + have h2 := norm_add_le (Complex.I • ∫ t in Iic (-T), f ((right:ℂ)+(t:ℂ)*Complex.I)) + (_root_.Erdos970.VIntegral f right (-T) T) + simp only [norm_smul,Complex.norm_I,one_mul] at h1 h2 + have h3 := norm_cauchy_vertical_le f left right T hlr hT hf + linarith + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszIntegrand.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszIntegrand.lean new file mode 100644 index 0000000000000000000000000000000000000000..808d409e0f69c332f4d8697ea49bfd422daf896d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszIntegrand.lean @@ -0,0 +1,128 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.RieszIntegralRepresentation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory +open scoped BigOperators + +noncomputable def rieszSum (f : ℕ → ℂ) (X : ℝ) : ℂ := + ∑ n ∈ Finset.range (⌊X⌋₊+1), f n*(rieszWeight ((n:ℝ)/X):ℂ) + +lemma tsum_riesz_eq_finite (f : ℕ → ℂ) {X : ℝ} (hX : 0 < X) : + (∑' n:ℕ, f n*(rieszWeight ((n:ℝ)/X):ℂ)) = rieszSum f X := by + unfold rieszSum + apply tsum_eq_sum + intro n hn + have hn' : ⌊X⌋₊ < n := by simp only [Finset.mem_range] at hn; omega + have hXn : X < (n:ℝ) := (Nat.floor_lt hX.le).mp hn' + have hw : rieszWeight ((n:ℝ)/X) = 0 := rieszWeight_eq_zero + ((le_div_iff₀ hX).mpr (by linarith)) + rw [hw,Complex.ofReal_zero,mul_zero] + +theorem finite_character_riesz_mellin {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + {sigma X : ℝ} (hs : 1 < sigma) (hX : 0 < X) : + rieszSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X = + mellinFactor * ∫ t:ℝ, + (-deriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I) / + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I)) * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I) * (X:ℂ)^((sigma:ℂ)+(t:ℂ)*Complex.I) := by + rw [← tsum_riesz_eq_finite _ hX] + exact character_riesz_mellin chi hs hX + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory _root_.Filter +open scoped Topology + +noncomputable def characterRieszIntegrand {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (X : ℝ) (s : ℂ) : ℂ := + -logDeriv (DirichletCharacter.LFunction chi) s * rieszKernel s * (X:ℂ)^s + +lemma finite_riesz_eq_integrand {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + {sigma X : ℝ} (hs : 1 < sigma) (hX : 0 < X) : + rieszSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X = + mellinFactor * ∫ t:ℝ, characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I) := by + simpa only [characterRieszIntegrand,logDeriv_apply,neg_div] using finite_character_riesz_mellin chi hs hX + +lemma norm_characterRieszIntegrand {q : ℕ} [NeZero q] (chi : DirichletCharacter ℂ q) + {X : ℝ} (hX : 0 < X) (s : ℂ) : + ‖characterRieszIntegrand chi X s‖ = + ‖logDeriv (DirichletCharacter.LFunction chi) s‖ * ‖rieszKernel s‖ * X^s.re := by + unfold characterRieszIntegrand + rw [norm_mul,norm_mul,norm_neg,Complex.norm_cpow_eq_rpow_re_of_pos hX] + +lemma differentiableAt_rieszKernel {s : ℂ} (hs : 0 < s.re) : + DifferentiableAt ℂ rieszKernel s := by + have h0 : s ≠ 0 := by intro h; simp [h] at hs + have h1 : s+1 ≠ 0 := by + intro h + have he := congrArg Complex.re h + simp only [Complex.add_re,Complex.one_re,Complex.zero_re] at he + linarith + unfold rieszKernel + have hc : DifferentiableAt ℂ (fun _ : ℂ => (1:ℂ)) s := by fun_prop + exact hc.div (by fun_prop) (mul_ne_zero h0 h1) + +lemma differentiableAt_characterRieszIntegrand {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) {X : ℝ} (hX : 0 < X) + {s : ℂ} (hs : 0 < s.re) (hne : DirichletCharacter.LFunction chi s ≠ 0) : + DifferentiableAt ℂ (characterRieszIntegrand chi X) s := by + have hL := DirichletCharacter.differentiable_LFunction hchi + have hder : DifferentiableAt ℂ (deriv (DirichletCharacter.LFunction chi)) s := + (hL.analyticAt s).deriv.differentiableAt + have hlog : DifferentiableAt ℂ (fun z => -logDeriv (DirichletCharacter.LFunction chi) z) s := by + change DifferentiableAt ℂ (fun z => -(deriv (DirichletCharacter.LFunction chi) z / + DirichletCharacter.LFunction chi z)) s + exact (hder.div hL.differentiableAt hne).neg + have hXC : (X:ℂ) ≠ 0 := by exact_mod_cast hX.ne' + have hpow : DifferentiableAt ℂ (fun z:ℂ => (X:ℂ)^z) s := by + fun_prop (disch := exact Or.inl hXC) + exact (hlog.mul (differentiableAt_rieszKernel hs)).mul hpow + +lemma continuous_characterRiesz_right {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) {sigma X : ℝ} + (hs : 1 < sigma) (hX : 0 < X) : + Continuous (fun t:ℝ => characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + apply continuous_iff_continuousAt.mpr + intro t + have hre : ((sigma:ℂ)+(t:ℂ)*Complex.I).re = sigma := by simp + exact (differentiableAt_characterRieszIntegrand chi hchi hX (by rw [hre]; linarith) + (LFunction_ne_zero_right chi (by simpa only [hre] using hs))).continuousAt.comp (by fun_prop) + +lemma integrable_characterRiesz_right {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (hchi : chi ≠ 1) {sigma X : ℝ} + (hs : 1 < sigma) (hX : 0 < X) : + Integrable (fun t:ℝ => characterRieszIntegrand chi X ((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + obtain ⟨C,hC,hbound⟩ := uniform_log_derivative_right + have hg := (integrable_rieszKernel_line (show 1/2 ≤ sigma by linarith)).norm.const_mul + (((sigma-1)⁻¹+C)*X^sigma) + apply hg.mono' (continuous_characterRiesz_right chi hchi hs hX).aestronglyMeasurable + filter_upwards [] with t + have hre : ((sigma:ℂ)+(t:ℂ)*Complex.I).re = sigma := by simp + have hb := hbound q chi ((sigma:ℂ)+(t:ℂ)*Complex.I) (by simpa only [hre] using hs) + rw [norm_characterRieszIntegrand chi hX,hre] + change ‖logDeriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ * _ * _ ≤ _ + have hb' : ‖logDeriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ ≤ + (sigma-1)⁻¹+C := by simpa only [logDeriv_apply,hre] using hb + calc + _ ≤ ((sigma-1)⁻¹+C)*‖rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)‖*X^sigma := by gcongr + _ = _ := by ring + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszTermCalculus.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszTermCalculus.lean new file mode 100644 index 0000000000000000000000000000000000000000..70c2e20b5adeb3b5a53c4aa0d2208544a0d1b649 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RieszTermCalculus.lean @@ -0,0 +1,96 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RieszKernelBounds + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.MeasureTheory _root_.Filter +open scoped Topology + +lemma riesz_scale_cpow {n X : ℝ} (hn : 0 < n) (hX : 0 < X) (s : ℂ) : + ((n/X:ℝ):ℂ)^(-s) = (X:ℂ)^s/(n:ℂ)^s := by + have hnC : (n:ℂ) ≠ 0 := by exact_mod_cast hn.ne' + have hXC : (X:ℂ) ≠ 0 := by exact_mod_cast hX.ne' + have hrC : ((n/X:ℝ):ℂ) ≠ 0 := by exact_mod_cast (div_pos hn hX).ne' + have hl : Complex.log ((n/X:ℝ):ℂ) = Complex.log (n:ℂ)-Complex.log (X:ℂ) := by + rw [← Complex.ofReal_log (div_pos hn hX).le,Real.log_div hn.ne' hX.ne', + Complex.ofReal_sub,Complex.ofReal_log hn.le,Complex.ofReal_log hX.le] + rw [Complex.cpow_def_of_ne_zero hrC,Complex.cpow_def_of_ne_zero hXC, + Complex.cpow_def_of_ne_zero hnC,← Complex.exp_sub,hl] + congr 1 + ring + +noncomputable def rieszDirichletTerm (f : ℕ → ℂ) (sigma X : ℝ) (n : ℕ) (t : ℝ) : ℂ := + LSeries.term f ((sigma:ℂ)+(t:ℂ)*Complex.I) n * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I) * (X:ℂ)^((sigma:ℂ)+(t:ℂ)*Complex.I) + +lemma norm_rieszDirichletTerm (f : ℕ → ℂ) (sigma : ℝ) {X : ℝ} (hX : 0 < X) + (n : ℕ) (t : ℝ) : + ‖rieszDirichletTerm f sigma X n t‖ = + ‖LSeries.term f (sigma:ℂ) n‖ * X^sigma * ‖rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ := by + have hre : ((sigma:ℂ)+(t:ℂ)*Complex.I).re = sigma := by simp + have ht : ‖LSeries.term f ((sigma:ℂ)+(t:ℂ)*Complex.I) n‖ = ‖LSeries.term f (sigma:ℂ) n‖ := by + simp only [LSeries.norm_term_eq,hre,Complex.ofReal_re] + unfold rieszDirichletTerm + rw [norm_mul,norm_mul,ht,Complex.norm_cpow_eq_rpow_re_of_pos hX,hre] + ring + +lemma rieszDirichletTerm_eq_scaled (f : ℕ → ℂ) (hf0 : f 0 = 0) (sigma : ℝ) + {X : ℝ} (hX : 0 < X) (n : ℕ) (t : ℝ) : + rieszDirichletTerm f sigma X n t = f n * + (((n:ℝ)/X:ℝ):ℂ)^(-((sigma:ℂ)+(t:ℂ)*Complex.I)) * + rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I) := by + by_cases hn : n=0 + · simp [rieszDirichletTerm,hn,hf0] + · unfold rieszDirichletTerm + rw [LSeries.term_of_ne_zero hn,riesz_scale_cpow (by exact_mod_cast Nat.pos_of_ne_zero hn) hX] + simp only [div_eq_mul_inv] + push_cast + ring + +lemma continuous_rieszDirichletTerm (f : ℕ → ℂ) {sigma X : ℝ} + (hs : 1/2 ≤ sigma) (hX : 0 < X) (n : ℕ) : + Continuous (rieszDirichletTerm f sigma X n) := by + by_cases hn : n=0 + · subst n + unfold rieszDirichletTerm + simp only [LSeries.term_zero,zero_mul] + exact continuous_const + · have hnC : (n:ℂ) ≠ 0 := by exact_mod_cast hn + have hXC : (X:ℂ) ≠ 0 := by exact_mod_cast hX.ne' + have hnp : Continuous (fun t:ℝ => (n:ℂ)^((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + fun_prop (disch := exact Or.inl hnC) + have hXp : Continuous (fun t:ℝ => (X:ℂ)^((sigma:ℂ)+(t:ℂ)*Complex.I)) := by + fun_prop (disch := exact Or.inl hXC) + have hterm : Continuous (fun t:ℝ => LSeries.term f ((sigma:ℂ)+(t:ℂ)*Complex.I) n) := by + simp only [LSeries.term_of_ne_zero hn] + exact continuous_const.div hnp (fun _ => Complex.cpow_ne_zero_iff.mpr (Or.inl hnC)) + exact (hterm.mul (continuous_rieszKernel_line hs)).mul hXp + +lemma integrable_rieszDirichletTerm (f : ℕ → ℂ) {sigma X : ℝ} + (hs : 1/2 ≤ sigma) (hX : 0 < X) (n : ℕ) : + Integrable (rieszDirichletTerm f sigma X n) := by + have hg := (integrable_rieszKernel_line hs).norm.const_mul + (‖LSeries.term f (sigma:ℂ) n‖ * X^sigma) + apply hg.mono' (continuous_rieszDirichletTerm f hs hX n).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun t => (norm_rieszDirichletTerm f sigma hX n t).le) + +lemma integral_norm_rieszDirichletTerm (f : ℕ → ℂ) {sigma X : ℝ} + (hX : 0 < X) (n : ℕ) : + (∫ t:ℝ, ‖rieszDirichletTerm f sigma X n t‖) = + ‖LSeries.term f (sigma:ℂ) n‖ * X^sigma * + ∫ t:ℝ, ‖rieszKernel ((sigma:ℂ)+(t:ℂ)*Complex.I)‖ := by + simp_rw [norm_rieszDirichletTerm f sigma hX n] + exact integral_const_mul _ _ + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RootCutoffSurvivors.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RootCutoffSurvivors.lean new file mode 100644 index 0000000000000000000000000000000000000000..53231e0ac0123039d194b1d65bab5a9d5b6fba6f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RootCutoffSurvivors.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CrossingBandGeometry +import OAI.NumberTheory.Jacobsthal.Sieve.SurvivorResidueShift + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RootCutoffSurvivors +open SievePartition LargePrimeDeletion SurvivorResidueShift +open StoppedCountVertex StoppedCountAdapters LogarithmicBinPartition + +attribute [local instance] Classical.propDecidable + +theorem residue_survivors_union (Y : ℕ) (small P : Finset ℕ) (a : ℕ → ℕ) : + survivors (residueCandidates Y ∅ small a) P (residueBad a)=residueCandidates Y ∅ (small∪P) a := by + ext n + constructor + · intro hn + obtain ⟨hn,hP⟩ := mem_survivors.mp hn + obtain ⟨h1,hY,_hreq,hs⟩ := mem_residueCandidates.mp hn + refine mem_residueCandidates.mpr ⟨h1,hY,by simp,?_⟩ + intro p hp + rcases Finset.mem_union.mp hp with hp | hp + · exact hs p hp + · exact hP p hp + · intro hn + obtain ⟨h1,hY,_hreq,hboth⟩ := mem_residueCandidates.mp hn + exact mem_survivors.mpr ⟨mem_residueCandidates.mpr ⟨h1,hY,by simp, + fun p hp => hboth p (Finset.mem_union_left _ hp)⟩, + fun p hp => hboth p (Finset.mem_union_right _ hp)⟩ + +theorem cutoffPrimes_eq_primesLE (z : ℕ) : cutoffPrimes z=Nat.primesLE z := by + ext p + simp only [mem_cutoffPrimes,Nat.mem_primesLE] + exact and_comm + +theorem source_cutoff_union {w top : ℝ} (hwt : w ≤ top) : + cutoffPrimes ⌊w⌋₊∪sourcePrimeSet w top=cutoffPrimes ⌊top⌋₊ := by + rw [cutoffPrimes_eq_primesLE,cutoffPrimes_eq_primesLE,sourcePrimeSet] + have hs : Nat.primesLE ⌊w⌋₊ ⊆ Nat.primesLE ⌊top⌋₊ := by + intro p hp + obtain ⟨hbound,hprime⟩ := Nat.mem_primesLE.mp hp + exact Nat.mem_primesLE.mpr ⟨hbound.trans (Nat.floor_mono hwt),hprime⟩ + ext p + simp only [Finset.mem_union,Finset.mem_sdiff] + constructor + · rintro (hp | ⟨hp,_⟩) + · exact hs hp + · exact hp + · intro hp + by_cases hw : p∈Nat.primesLE ⌊w⌋₊ + · exact Or.inl hw + · exact Or.inr ⟨hp,hw⟩ + +theorem root_count_eq_cutoff (Y : ℕ) {w top : ℝ} (hwt : w ≤ top) + (a : ℕ → ℕ) (z : PrimeHistories.Node) (mu : ℝ) : + countSurvivors Y (cutoffPrimes ⌊w⌋₊) (successorResidues a) + (rootVertex z ∅ (sourcePrimeSet w top) mu)= + ((cutoffSurvivors Y ⌊top⌋₊ a).card:ℝ) := by + unfold countSurvivors + change ((survivors (residueCandidates Y ∅ (cutoffPrimes ⌊w⌋₊) (successorResidues a)) + (sourcePrimeSet w top) (residueBad (successorResidues a))).card:ℝ)=_ + rw [residue_survivors_union,source_cutoff_union hwt,positive_survivors_card] + +theorem cutoff_lower_of_root_lower (Y : ℕ) {w top S mu : ℝ} (hwt : w ≤ top) + (z : PrimeHistories.Node) + (hLower : ∀ a : ℕ → ℕ,S ≤ countSurvivors Y (cutoffPrimes ⌊w⌋₊) a + (rootVertex z ∅ (sourcePrimeSet w top) mu)) : + ∀ a : ℕ → ℕ,S ≤ ((cutoffSurvivors Y ⌊top⌋₊ a).card:ℝ) := by + intro a + simpa only [root_count_eq_cutoff Y hwt a z mu] using hLower (successorResidues a) +end NumberTheoryLean.RootCutoffSurvivors + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/RoughRecursion.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RoughRecursion.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e34f98799d412983507f84f775788541d5891bc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/RoughRecursion.lean @@ -0,0 +1,301 @@ +import Mathlib.Algebra.BigOperators.Group.Finset.Basic +import Mathlib.Data.Finset.Max +import Mathlib.Data.Finset.Powerset +import Mathlib.Data.Nat.Prime.Basic +import Mathlib.Data.Rat.BigOperators +import Mathlib.Basic.Real.Basic +import Mathlib.Order.Interval.Finset.Nat + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators + +namespace ErdosAverageCertificates + +def PairwiseCoprime (A : Finset ℕ) : Prop := + (A : Set ℕ).Pairwise Nat.Coprime + +def Admissible (n : ℕ) (A : Finset ℕ) : Prop := + A ⊆ Finset.Ico 1 n ∧ PairwiseCoprime A + +def shiftedWeightQ (n : ℕ) (A : Finset ℕ) : ℚ := + ∑ a ∈ A, 1 / ((n - a : ℕ) : ℚ) + +noncomputable def admissibleSets (n : ℕ) : Finset (Finset ℕ) := by + classical + exact (Finset.Ico 1 n).powerset.filter (Admissible n) + +@[simp] +theorem mem_admissibleSets {n : ℕ} {A : Finset ℕ} : + A ∈ admissibleSets n ↔ Admissible n A := by + simp [admissibleSets, Admissible] + +@[simp] +theorem empty_admissible (n : ℕ) : Admissible n ∅ := by + simp [Admissible, PairwiseCoprime] + +theorem admissibleSets_nonempty (n : ℕ) : (admissibleSets n).Nonempty := + ⟨∅, by simp⟩ + +noncomputable def attainableWeights (n : ℕ) : Finset ℚ := by + classical + exact (admissibleSets n).image (shiftedWeightQ n) + +theorem attainableWeights_nonempty (n : ℕ) : (attainableWeights n).Nonempty := by + refine ⟨0, ?_⟩ + refine Finset.mem_image.mpr ⟨∅, ?_, ?_⟩ + · exact mem_admissibleSets.mpr (empty_admissible n) + · simp [shiftedWeightQ] + +noncomputable def extremalQ (n : ℕ) : ℚ := + (attainableWeights n).max' (attainableWeights_nonempty n) + +noncomputable def extremal (n : ℕ) : ℝ := + extremalQ n + +theorem exists_extremizer (n : ℕ) : + ∃ A : Finset ℕ, Admissible n A ∧ shiftedWeightQ n A = extremalQ n := by + have hmax : extremalQ n ∈ attainableWeights n := by + exact Finset.max'_mem _ _ + obtain ⟨A, hA, hw⟩ := Finset.mem_image.mp hmax + exact ⟨A, mem_admissibleSets.mp hA, hw⟩ + +theorem shiftedWeightQ_le_extremalQ {n : ℕ} {A : Finset ℕ} + (hA : Admissible n A) : shiftedWeightQ n A ≤ extremalQ n := by + apply Finset.le_max' + exact Finset.mem_image.mpr ⟨A, mem_admissibleSets.mpr hA, rfl⟩ + +def IsRough (m y : ℕ) : Prop := + m = 1 ∨ ∀ p : ℕ, p.Prime → p ∣ m → y < p + +@[simp] +theorem one_isRough (y : ℕ) : IsRough 1 y := + Or.inl rfl + +theorem isRough_of_minFac_lt {m y : ℕ} (h : y < m.minFac) : + IsRough m y := by + right + intro p hp hpm + exact h.trans_le (Nat.minFac_le_of_dvd hp.two_le hpm) + +theorem minFac_lt_of_isRough {m y : ℕ} (hm : m ≠ 1) (h : IsRough m y) : + y < m.minFac := by + rcases h with h_one | h_divisors + · exact (hm h_one).elim + exact h_divisors m.minFac (Nat.minFac_prime hm) (Nat.minFac_dvd m) + +theorem isRough_iff_minFac {m y : ℕ} (hm : m ≠ 1) : + IsRough m y ↔ y < m.minFac := + ⟨minFac_lt_of_isRough hm, isRough_of_minFac_lt⟩ + +noncomputable def roughCount (x y : ℕ) : ℕ := by + classical + exact ((Finset.Icc 1 x).filter fun m ↦ IsRough m y).card + +noncomputable def selfRoughSet (n : ℕ) : Finset ℕ := by + classical + exact (Finset.Ico 1 n).filter fun a ↦ IsRough a (n - a) + +noncomputable def selfRoughSumQ (n : ℕ) : ℚ := + shiftedWeightQ n (selfRoughSet n) + +end ErdosAverageCertificates + +end + +section + +open scoped BigOperators + +namespace ErdosAverageCertificates + +noncomputable section + +noncomputable def roughSet (x y : ℕ) : Finset ℕ := by + classical + exact (Finset.Icc 1 x).filter fun m ↦ IsRough m y + +@[simp] +theorem mem_roughSet {x y m : ℕ} : + m ∈ roughSet x y ↔ 1 ≤ m ∧ m ≤ x ∧ IsRough m y := by + classical + simp [roughSet, and_assoc] + +theorem roughCount_eq_card (x y : ℕ) : + roughCount x y = (roughSet x y).card := by + rfl + +noncomputable def roughLayer (x y z : ℕ) : Finset ℕ := by + classical + exact (Finset.Icc 2 x).filter fun m ↦ y < m.minFac ∧ m.minFac ≤ z + +@[simp] +theorem mem_roughLayer {x y z m : ℕ} : + m ∈ roughLayer x y z ↔ + 2 ≤ m ∧ m ≤ x ∧ y < m.minFac ∧ m.minFac ≤ z := by + classical + simp [roughLayer, and_assoc] + +noncomputable def leastPrimeFiber (x p : ℕ) : Finset ℕ := by + classical + exact (Finset.Icc 2 x).filter fun m ↦ m.minFac = p + +@[simp] +theorem mem_leastPrimeFiber {x p m : ℕ} : + m ∈ leastPrimeFiber x p ↔ 2 ≤ m ∧ m ≤ x ∧ m.minFac = p := by + classical + simp [leastPrimeFiber, and_assoc] + +def layerPrimes (y z : ℕ) : Finset ℕ := + (Finset.Ioc y z).filter Nat.Prime + +@[simp] +theorem mem_layerPrimes {y z p : ℕ} : + p ∈ layerPrimes y z ↔ y < p ∧ p ≤ z ∧ p.Prime := by + simp [layerPrimes, and_assoc] + +theorem minFac_mul_eq_left_of_prime_of_rough {p k : ℕ} + (hp : p.Prime) (hk : 1 ≤ k) (hrough : IsRough k (p - 1)) : + (p * k).minFac = p := by + have hprod : p * k ≠ 1 := by + have hpk : 2 * 1 ≤ p * k := Nat.mul_le_mul hp.two_le hk + have : 2 ≤ p * k := by simpa using hpk + omega + apply le_antisymm + · exact Nat.minFac_le_of_dvd hp.two_le (dvd_mul_right p k) + · have hqprime : (p * k).minFac.Prime := Nat.minFac_prime hprod + have hqdiv : (p * k).minFac ∣ p * k := Nat.minFac_dvd (p * k) + rcases hqprime.dvd_mul.mp hqdiv with hqp | hqk + · exact le_of_eq (Nat.prime_dvd_prime_iff_eq hqprime hp |>.mp hqp).symm + · rcases hrough with hk_one | hk_divisors + · subst k + simpa using (le_of_eq hp.minFac_eq.symm) + · have := hk_divisors (p * k).minFac hqprime hqk + omega + +theorem rough_of_minFac_eq_prime {m p : ℕ} + (_hm : 2 ≤ m) (_hp : p.Prime) (hmin : m.minFac = p) : + IsRough (m / p) (p - 1) := by + right + intro q hq hqdiv + have hpdiv : p ∣ m := by simpa [hmin] using Nat.minFac_dvd m + have hrecover : p * (m / p) = m := Nat.mul_div_cancel' hpdiv + have hqdivm : q ∣ m := by + rw [← hrecover] + exact dvd_mul_of_dvd_right hqdiv p + have hle : p ≤ q := by + rw [← hmin] + exact Nat.minFac_le_of_dvd hq.two_le hqdivm + have hq2 : 2 ≤ q := hq.two_le + omega + +theorem card_leastPrimeFiber_eq_roughCount {x p : ℕ} (hp : p.Prime) : + (leastPrimeFiber x p).card = roughCount (x / p) (p - 1) := by + rw [roughCount_eq_card] + symm + apply Finset.card_bij (fun k _ ↦ p * k) + · intro k hk + rw [mem_leastPrimeFiber] + have hk' := mem_roughSet.mp hk + refine ⟨?_, ?_, minFac_mul_eq_left_of_prime_of_rough hp hk'.1 hk'.2.2⟩ + · have hpk : 2 * 1 ≤ p * k := Nat.mul_le_mul hp.two_le hk'.1 + simpa using hpk + · have hmul : k * p ≤ x := + (Nat.le_div_iff_mul_le hp.pos).mp hk'.2.1 + simpa [mul_comm] using hmul + · intro k₁ hk₁ k₂ hk₂ hmul + exact Nat.eq_of_mul_eq_mul_left hp.pos hmul + · intro m hm + have hm' := mem_leastPrimeFiber.mp hm + have hpdiv : p ∣ m := by + simpa [hm'.2.2] using Nat.minFac_dvd m + refine ⟨m / p, ?_, ?_⟩ + · rw [mem_roughSet] + refine ⟨?_, Nat.div_le_div_right hm'.2.1, + rough_of_minFac_eq_prime hm'.1 hp hm'.2.2⟩ + exact Nat.div_pos (by + rw [← hm'.2.2] + exact Nat.minFac_le (by omega)) hp.pos + · exact Nat.mul_div_cancel' hpdiv + +theorem roughSet_eq_union_layer {x y z : ℕ} (hyz : y ≤ z) : + roughSet x y = roughSet x z ∪ roughLayer x y z := by + classical + ext m + by_cases hm1 : m = 1 + · subst m + simp + have hmrough_y : IsRough m y ↔ y < m.minFac := isRough_iff_minFac hm1 + have hmrough_z : IsRough m z ↔ z < m.minFac := isRough_iff_minFac hm1 + by_cases hmx : 1 ≤ m ∧ m ≤ x + · have hm2 : 2 ≤ m := by omega + simp only [mem_roughSet, Finset.mem_union, mem_roughLayer, hmrough_y, + hmrough_z, hmx.1, hmx.2, hm2, true_and] + omega + · simp only [mem_roughSet, Finset.mem_union, mem_roughLayer, hmrough_y, + hmrough_z] + omega + +theorem roughSet_disjoint_layer (x y z : ℕ) : + Disjoint (roughSet x z) (roughLayer x y z) := by + classical + rw [Finset.disjoint_left] + intro m hmrough hmlayer + have hm1 : m ≠ 1 := by + have := (mem_roughLayer.mp hmlayer).1 + omega + have hzlt : z < m.minFac := + (isRough_iff_minFac hm1).mp (mem_roughSet.mp hmrough).2.2 + exact (not_lt_of_ge (mem_roughLayer.mp hmlayer).2.2.2) hzlt + +theorem roughCount_eq_add_layer {x y z : ℕ} (hyz : y ≤ z) : + roughCount x y = roughCount x z + (roughLayer x y z).card := by + simp only [roughCount_eq_card, roughSet_eq_union_layer hyz, + Finset.card_union_of_disjoint (roughSet_disjoint_layer x y z)] + +theorem roughLayer_mapsTo_layerPrimes {x y z : ℕ} : + (roughLayer x y z : Set ℕ).MapsTo Nat.minFac (layerPrimes y z) := by + intro m hm + have hm' := mem_roughLayer.mp hm + exact mem_layerPrimes.mpr + ⟨hm'.2.2.1, hm'.2.2.2, Nat.minFac_prime (by omega)⟩ + +theorem roughLayer_fiber_eq {x y z p : ℕ} (hp : p ∈ layerPrimes y z) : + {m ∈ roughLayer x y z | m.minFac = p} = leastPrimeFiber x p := by + classical + ext m + have hp' := mem_layerPrimes.mp hp + simp only [Finset.mem_filter, mem_roughLayer, mem_leastPrimeFiber] + constructor + · rintro ⟨⟨hm2, hmx, -, -⟩, hmin⟩ + exact ⟨hm2, hmx, hmin⟩ + · rintro ⟨hm2, hmx, hmin⟩ + exact ⟨⟨hm2, hmx, hmin ▸ hp'.1, hmin ▸ hp'.2.1⟩, hmin⟩ + +theorem card_roughLayer_eq_sum_roughCount (x y z : ℕ) : + (roughLayer x y z).card = + ∑ p ∈ layerPrimes y z, roughCount (x / p) (p - 1) := by + rw [Finset.card_eq_sum_card_fiberwise roughLayer_mapsTo_layerPrimes] + apply Finset.sum_congr rfl + intro p hp + rw [roughLayer_fiber_eq hp, card_leastPrimeFiber_eq_roughCount + (mem_layerPrimes.mp hp).2.2] + +theorem roughCount_buchstab_recursion {x y z : ℕ} (hyz : y ≤ z) : + roughCount x y = roughCount x z + + ∑ p ∈ layerPrimes y z, roughCount (x / p) (p - 1) := by + rw [roughCount_eq_add_layer hyz, card_roughLayer_eq_sum_roughCount] + +end + +end ErdosAverageCertificates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarErrorBudget.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarErrorBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..050b4db5e9b4d8d8f0ab190043bbdda6f27d4fd9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarErrorBudget.lean @@ -0,0 +1,498 @@ +import Mathlib.Data.Nat.Factorization.Induction +import Mathlib.Data.Nat.GCD.Basic +import Mathlib.NumberTheory.ArithmeticFunction.Misc +import OAI.NumberTheory.Jacobsthal.Partitions.DilationCoordinates +import OAI.NumberTheory.Jacobsthal.Primes.PrimePowerBound +import OAI.NumberTheory.Jacobsthal.Sieve.KloostermanCRT +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueGCDBounds + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman + +def frequencyGcd (N : ℕ) (h k : ℤ) : ℕ := Nat.gcd N (Int.gcd h k) + +theorem dvd_frequencyGcd_iff (d N : ℕ) (h k : ℤ) : + d ∣ frequencyGcd N h k ↔ d ∣ N ∧ (d : ℤ) ∣ h ∧ (d : ℤ) ∣ k := by + simp only [frequencyGcd, Int.gcd_def, Nat.dvd_gcd_iff, Int.natCast_dvd] + +theorem frequencyGcd_scale (N : ℕ) (c A B h k : ℤ) + (hab : (N : ℤ)*A + c*B = 1) : + frequencyGcd N (c*h) (c*k) = frequencyGcd N h k := by + apply Nat.dvd_antisymm + · obtain ⟨hdN, hdh, hdk⟩ := (dvd_frequencyGcd_iff _ _ _ _).mp + (dvd_refl (frequencyGcd N (c*h) (c*k))) + have hdN' : (frequencyGcd N (c*h) (c*k) : ℤ) ∣ N := by exact_mod_cast hdN + apply (dvd_frequencyGcd_iff _ _ _ _).mpr + refine ⟨hdN, ?_, ?_⟩ + · have hd := dvd_add (dvd_mul_of_dvd_left hdN' (A*h)) (dvd_mul_of_dvd_right hdh B) + have heq : (N : ℤ)*(A*h) + B*(c*h) = h := by + linear_combination h * hab + rwa [heq] at hd + · have hd := dvd_add (dvd_mul_of_dvd_left hdN' (A*k)) (dvd_mul_of_dvd_right hdk B) + have heq : (N : ℤ)*(A*k) + B*(c*k) = k := by + linear_combination k * hab + rwa [heq] at hd + · obtain ⟨hdN, hdh, hdk⟩ := (dvd_frequencyGcd_iff _ _ _ _).mp + (dvd_refl (frequencyGcd N h k)) + exact (dvd_frequencyGcd_iff _ _ _ _).mpr + ⟨hdN, dvd_mul_of_dvd_right hdh c, dvd_mul_of_dvd_right hdk c⟩ + +theorem frequencyGcd_coprime_mul (m n : ℕ) (hmn : m.Coprime n) (h k : ℤ) : + frequencyGcd (m*n) h k = frequencyGcd m h k * frequencyGcd n h k := by + apply Nat.dvd_antisymm + · have hg : frequencyGcd (m*n) h k ∣ m*n := Nat.gcd_dvd_left _ _ + have heq := (Nat.gcd_mul_gcd_eq_iff_dvd_mul_of_coprime hmn).mpr hg + have hd : Nat.gcd (frequencyGcd (m*n) h k) m ∣ frequencyGcd m h k := by + apply Nat.dvd_gcd (Nat.gcd_dvd_right _ _) + exact (Nat.gcd_dvd_left _ _).trans (Nat.gcd_dvd_right _ _) + have he : Nat.gcd (frequencyGcd (m*n) h k) n ∣ frequencyGcd n h k := by + apply Nat.dvd_gcd (Nat.gcd_dvd_right _ _) + exact (Nat.gcd_dvd_left _ _).trans (Nat.gcd_dvd_right _ _) + rw [← heq] + exact Nat.mul_dvd_mul hd he + · have hd : frequencyGcd m h k ∣ frequencyGcd (m*n) h k := by + apply Nat.dvd_gcd + · exact (Nat.gcd_dvd_left _ _).trans (dvd_mul_right m n) + · exact Nat.gcd_dvd_right _ _ + have he : frequencyGcd n h k ∣ frequencyGcd (m*n) h k := by + apply Nat.dvd_gcd + · exact (Nat.gcd_dvd_left _ _).trans (dvd_mul_left n m) + · exact Nat.gcd_dvd_right _ _ + exact (hmn.of_dvd (Nat.gcd_dvd_left _ _) (Nat.gcd_dvd_left _ _)).mul_dvd_of_dvd_of_dvd hd he + +end ErdosKloosterman + +end + +section + +namespace ErdosKloosterman + +noncomputable def envelope (N : ℕ) (h k : ℤ) : ℝ := + (N.divisors.card : ℝ)^2 * (N : ℝ)^((3 : ℝ)/4) * + (frequencyGcd N h k : ℝ)^((1 : ℝ)/4) + +theorem envelope_nonneg (N : ℕ) (h k : ℤ) : 0 ≤ envelope N h k := by + unfold envelope + positivity + +theorem envelope_coprime_mul (m n : ℕ) (hmn : m.Coprime n) (h k : ℤ) : + envelope (m*n) h k = envelope m h k * envelope n h k := by + unfold envelope + rw [hmn.card_divisors_mul, frequencyGcd_coprime_mul m n hmn] + push_cast + rw [Real.mul_rpow (Nat.cast_nonneg m) (Nat.cast_nonneg n), + Real.mul_rpow (Nat.cast_nonneg _) (Nat.cast_nonneg _)] + ring + +theorem envelope_scale (N : ℕ) (c A B h k : ℤ) + (hab : (N : ℤ)*A + c*B = 1) : + envelope N (c*h) (c*k) = envelope N h k := by + unfold envelope + rw [frequencyGcd_scale N c A B h k hab] + +theorem envelope_crt_scaled (m n : ℕ) (hmn : m.Coprime n) (h k : ℤ) : + envelope m (Nat.gcdB m n*h) (Nat.gcdB m n*k) * + envelope n (Nat.gcdA m n*h) (Nat.gcdA m n*k) = envelope (m*n) h k := by + have hab : (m : ℤ)*Nat.gcdA m n + (n : ℤ)*Nat.gcdB m n = 1 := by + rw [← Nat.gcd_eq_gcd_ab, hmn.gcd_eq_one] + rfl + rw [envelope_scale m (Nat.gcdB m n) (Nat.gcdA m n) n h k (by nlinarith [hab]), + envelope_scale n (Nat.gcdA m n) (Nat.gcdB m n) m h k (by nlinarith [hab]), + envelope_coprime_mul m n hmn] + +theorem standardSum_one (h k : ℤ) : standardSum 1 h k = 1 := by + let : DecidableEq (ZMod 1) := Classical.decEq _ + have h0 : (h : ZMod 1) = 0 := Subsingleton.elim _ _ + have k0 : (k : ZMod 1) = 0 := Subsingleton.elim _ _ + have hc : Fintype.card (ZMod 1)ˣ = 1 := Fintype.card_unique + simp only [standardSum, h0, k0, sum_zero_zero, hc, Nat.cast_one] + +theorem envelope_one (h k : ℤ) : envelope 1 h k = 1 := by + simp [envelope, frequencyGcd] + +def BoundAt (N : ℕ) : Prop := ∀ [NeZero N] (h k : ℤ), + ‖standardSum N h k‖ ≤ envelope N h k + +theorem boundAt_zero : BoundAt 0 := by + intro h0 h k + exact False.elim (NeZero.ne 0 rfl) + +theorem boundAt_one : BoundAt 1 := by + intro _ h k + simp [standardSum_one, envelope_one] + +theorem boundAt_coprime (m n : ℕ) (hm : 1 < m) (hn : 1 < n) (hmn : m.Coprime n) + (hbm : BoundAt m) (hbn : BoundAt n) : BoundAt (m*n) := by + let : NeZero m := ⟨by omega⟩ + let : NeZero n := ⟨by omega⟩ + intro _ h k + rw [norm_standardSum_crt m n hmn] + calc + _ ≤ envelope m (Nat.gcdB m n*h) (Nat.gcdB m n*k) * + envelope n (Nat.gcdA m n*h) (Nat.gcdA m n*k) := + mul_le_mul (hbm _ _) (hbn _ _) (norm_nonneg _) (envelope_nonneg _ _ _) + _ = _ := envelope_crt_scaled m n hmn h k + +theorem boundAt_all_of_prime_powers + (local_bound : ∀ p a : ℕ, p.Prime → 0 < a → BoundAt (p^a)) : + ∀ N : ℕ, BoundAt N := + Nat.recOnPosPrimePosCoprime local_bound boundAt_zero boundAt_one boundAt_coprime + +end ErdosKloosterman + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaIdentities + +attribute [local instance] Classical.decEq + +private theorem restricted_phase (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c u : (ZMod (H*T))ˣ) (h k : ZMod (H*T)) (j : ZMod T) : + ZMod.stdAddChar (-j*(a : ZMod T)) * + ZMod.stdAddChar ((h+(H : ZMod (H*T))*(j.val : ZMod (H*T)))*(u : ZMod (H*T)) + + (k*(c : ZMod (H*T)))*(↑u⁻¹ : ZMod (H*T))) = + ZMod.stdAddChar (h*(u : ZMod (H*T)) + k*(c : ZMod (H*T))*(↑u⁻¹ : ZMod (H*T))) * + ZMod.stdAddChar (j*((ZMod.unitsMap (dvd_mul_left T H) u : ZMod T)-(a : ZMod T))) := by + have he : (h+(H : ZMod (H*T))*(j.val : ZMod (H*T)))*(u : ZMod (H*T)) + + (k*(c : ZMod (H*T)))*(↑u⁻¹ : ZMod (H*T)) = + (h*(u : ZMod (H*T)) + k*(c : ZMod (H*T))*(↑u⁻¹ : ZMod (H*T))) + + (H : ZMod (H*T))*((j.val : ZMod (H*T))*(u : ZMod (H*T))) := by ring + rw [he, AddChar.map_add_eq_mul, ErdosKloosterman.PrimePower.standard_character_reduction] + have hred : ErdosKloosterman.PrimePower.reduction H T + ((j.val : ZMod (H*T))*(u : ZMod (H*T))) = + j*(ZMod.unitsMap (dvd_mul_left T H) u : ZMod T) := by + simp only [map_mul, map_natCast, ZMod.natCast_zmod_val, + ErdosKloosterman.PrimePower.reduction, ZMod.unitsMap_def, Units.coe_map, MonoidHom.coe_coe] + rw [hred] + have hc : ZMod.stdAddChar (-j*(a : ZMod T)) * + ZMod.stdAddChar (j*(ZMod.unitsMap (dvd_mul_left T H) u : ZMod T)) = + ZMod.stdAddChar (j*((ZMod.unitsMap (dvd_mul_left T H) u : ZMod T)-(a : ZMod T))) := by + rw [← AddChar.map_add_eq_mul] + congr 1 + ring + calc + _ = ZMod.stdAddChar (h*(u : ZMod (H*T)) + k*(c : ZMod (H*T))*(↑u⁻¹ : ZMod (H*T))) * + (ZMod.stdAddChar (-j*(a : ZMod T)) * + ZMod.stdAddChar (j*(ZMod.unitsMap (dvd_mul_left T H) u : ZMod T))) := by ring + _ = _ := by rw [hc] + +theorem restricted_average_mul (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (h k : ZMod (H*T)) : + (∑ j : ZMod T, ZMod.stdAddChar (-j*(a : ZMod T)) * + ErdosKloosterman.sum ZMod.stdAddChar + (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))) (k*(c : ZMod (H*T)))) = + (T : ℂ) * restrictedSum (H*T) T (dvd_mul_left T H) a c h k := by + unfold ErdosKloosterman.sum + simp_rw [Finset.mul_sum, restricted_phase] + rw [Finset.sum_comm] + simp_rw [← Finset.mul_sum, AddChar.sum_mulShift _ (ZMod.isPrimitive_stdAddChar T)] + have he (u : (ZMod (H*T))ˣ) : + ((ZMod.unitsMap (dvd_mul_left T H) u : ZMod T)-(a : ZMod T) = 0) ↔ + ZMod.unitsMap (dvd_mul_left T H) u = a := by rw [sub_eq_zero, Units.val_inj] + simp_rw [he] + simp [restrictedSum, unitClass, Finset.sum_filter, Finset.mul_sum, mul_comm] + apply Finset.sum_congr (by ext u; simp) + intro u _ + rfl + +theorem restricted_average (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (h k : ZMod (H*T)) : + restrictedSum (H*T) T (dvd_mul_left T H) a c h k = + (∑ j : ZMod T, ZMod.stdAddChar (-j*(a : ZMod T)) * + ErdosKloosterman.sum ZMod.stdAddChar + (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))) (k*(c : ZMod (H*T))))/(T : ℂ) := by + have hT : (T : ℂ) ≠ 0 := by exact_mod_cast NeZero.ne T + apply (eq_div_iff hT).mpr + simpa only [mul_comm] using (restricted_average_mul H T a c h k).symm + +end ErdosHyperbolaIdentities + +end + +section + +namespace ErdosKloosterman + +theorem boundAt_prime_power (p a : ℕ) (hp : p.Prime) (ha : 0 < a) : BoundAt (p^a) := by + let : Fact p.Prime := ⟨hp⟩ + intro _ h k + have hc : (p^a).divisors.card = a+1 := by + rw [← ArithmeticFunction.sigma_zero_apply, ArithmeticFunction.sigma_zero_apply_prime_pow hp] + simpa only [envelope, frequencyGcd, hc] using + PrimePower.standardSum_prime_power_bound p a ha h k + +theorem standardSum_bound (N : ℕ) [NeZero N] (h k : ℤ) : + ‖standardSum N h k‖ ≤ + (N.divisors.card : ℝ)^2 * (N : ℝ)^((3 : ℝ)/4) * + ((Nat.gcd N (Int.gcd h k) : ℕ) : ℝ)^((1 : ℝ)/4) := + boundAt_all_of_prime_powers boundAt_prime_power N h k + +theorem standardSum_bound_half_gcd (N : ℕ) [NeZero N] (h k : ℤ) : + ‖standardSum N h k‖ ≤ + (N.divisors.card : ℝ)^2 * (N : ℝ)^((3 : ℝ)/4) * + ((Nat.gcd N (Int.gcd h k) : ℕ) : ℝ)^((1 : ℝ)/2) := by + have hg : 0 < Nat.gcd N (Int.gcd h k) := Nat.gcd_pos_of_pos_left _ (NeZero.pos N) + have hg1 : (1 : ℝ) ≤ ((Nat.gcd N (Int.gcd h k) : ℕ) : ℝ) := by + exact_mod_cast (Nat.succ_le_iff.mpr hg) + exact (standardSum_bound N h k).trans (mul_le_mul_of_nonneg_left + (Real.rpow_le_rpow_of_exponent_le hg1 (by norm_num)) (by positivity)) + +end ErdosKloosterman + +end + +section + +namespace ErdosHyperbolaError + +noncomputable def completeScale (N : ℕ) : ℝ := + (N.divisors.card : ℝ)^2 * (N : ℝ)^((3 : ℝ)/4) + +theorem completeScale_nonneg (N : ℕ) : 0 ≤ completeScale N := by + unfold completeScale + positivity + +theorem sum_as_standard (N : ℕ) [NeZero N] (h k : ZMod N) : + ErdosKloosterman.sum ZMod.stdAddChar h k = + ErdosKloosterman.standardSum N (h.val : ℤ) (k.val : ℤ) := by + simp only [ErdosKloosterman.standardSum, Int.cast_natCast, ZMod.natCast_zmod_val] + +theorem norm_sum_le_sqrt_second (N : ℕ) [NeZero N] (h k : ZMod N) : + ‖ErdosKloosterman.sum ZMod.stdAddChar h k‖ ≤ + completeScale N * Real.sqrt (Nat.gcd k.val N) := by + have hb := ErdosKloosterman.standardSum_bound_half_gcd N (h.val : ℤ) (k.val : ℤ) + rw [← sum_as_standard N h k] at hb + simp only [Int.gcd_def, Int.natAbs_natCast, ← Real.sqrt_eq_rpow] at hb + have hg : (Nat.gcd N (Nat.gcd h.val k.val) : ℝ) ≤ Nat.gcd k.val N := by + exact_mod_cast gcd_three_le_second N h.val k.val (NeZero.pos N) + exact hb.trans (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hg) (completeScale_nonneg N)) + +theorem norm_sum_le_sqrt_first (N : ℕ) [NeZero N] (h k : ZMod N) : + ‖ErdosKloosterman.sum ZMod.stdAddChar h k‖ ≤ + completeScale N * Real.sqrt (Nat.gcd h.val N) := by + rw [ErdosKloosterman.sum_swap] + exact norm_sum_le_sqrt_second N k h + +end ErdosHyperbolaError + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +noncomputable def logFactor (N : ℕ) : ℝ := + ErdosHyperbola.harmonicConstant * Real.log (2*(N : ℝ)) + +noncomputable def errorBase (N T : ℕ) : ℝ := + completeScale N * (N.divisors.card : ℝ) * Real.sqrt T * (logFactor N)^2 + +theorem logFactor_one_le (N : ℕ) [NeZero N] : 1 ≤ logFactor N := by + have hm : (1 : ℕ) ∈ Finset.Icc 1 N := Finset.mem_Icc.mpr ⟨by omega, NeZero.pos N⟩ + have hh := Finset.single_le_sum (s := Finset.Icc 1 N) (f := fun n : ℕ => 1/(n : ℝ)) + (fun _ _ => by positivity) hm + have hh' : (1 : ℝ) ≤ ErdosHyperbola.harmonicWeight N := by + simpa only [Nat.cast_one, div_one, ErdosHyperbola.harmonicWeight] using hh + exact hh'.trans (ErdosHyperbola.harmonicWeight_log_le N (NeZero.pos N)) + +theorem divisorCount_one_le (N : ℕ) [NeZero N] : (1 : ℝ) ≤ N.divisors.card := by + have hp : 0 < N.divisors.card := Finset.card_pos.mpr + ⟨1, Nat.mem_divisors.mpr ⟨one_dvd N, NeZero.ne N⟩⟩ + exact_mod_cast hp + +theorem completeScale_one_le (N : ℕ) [NeZero N] : 1 ≤ completeScale N := by + have hN : (1 : ℝ) ≤ N := by exact_mod_cast NeZero.pos N + have hp : (1 : ℝ) ≤ (N : ℝ)^((3 : ℝ)/4) := Real.one_le_rpow hN (by norm_num) + have hd : (1 : ℝ) ≤ (N.divisors.card : ℝ)^2 := one_le_pow₀ (divisorCount_one_le N) + exact one_le_mul_of_one_le_of_one_le hd hp + +theorem sqrt_modulus_one_le (T : ℕ) [NeZero T] : 1 ≤ Real.sqrt T := by + have hT : (1 : ℝ) ≤ T := by exact_mod_cast NeZero.pos T + simpa using Real.sqrt_le_sqrt hT + +theorem errorBase_one_le (N T : ℕ) [NeZero N] [NeZero T] : 1 ≤ errorBase N T := by + exact one_le_mul_of_one_le_of_one_le + (one_le_mul_of_one_le_of_one_le + (one_le_mul_of_one_le_of_one_le (completeScale_one_le N) (divisorCount_one_le N)) + (sqrt_modulus_one_le T)) (one_le_pow₀ (logFactor_one_le N)) + +theorem errorBase_nonneg (N T : ℕ) : 0 ≤ errorBase N T := by + unfold errorBase + exact mul_nonneg (mul_nonneg (mul_nonneg (completeScale_nonneg N) (Nat.cast_nonneg _)) + (Real.sqrt_nonneg _)) (sq_nonneg _) + +theorem l1Norm_le_logFactor (N : ℕ) [NeZero N] (P : ProgressionInterval) (hP : P.step.Coprime N) : + l1Norm N P ≤ 2*(N : ℝ)*logFactor N := by + calc + _ ≤ _ := l1Norm_le N P hP + _ = _ := by unfold logFactor; ring + +theorem gcdL1Norm_le_logFactor (N : ℕ) [NeZero N] (P : ProgressionInterval) (hP : P.step.Coprime N) : + gcdL1Norm N P ≤ 2*(N : ℝ)*(N.divisors.card : ℝ)*logFactor N := by + calc + _ ≤ _ := gcdL1Norm_le N P hP + _ = _ := by unfold logFactor; ring + +theorem errorBase_explicit (N T : ℕ) : + errorBase N T = ErdosHyperbola.harmonicConstant^2 * (N.divisors.card : ℝ)^3 * + (Real.log (2*(N : ℝ)))^2 * (N : ℝ)^((3 : ℝ)/4) * Real.sqrt T := by + unfold errorBase logFactor completeScale + ring + +end ErdosHyperbolaError + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +theorem restrictedSum_norm_le_average (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (h k : ZMod (H*T)) : + ‖restrictedSum (H*T) T (dvd_mul_left T H) a c h k‖ ≤ + (∑ j : ZMod T, ‖ErdosKloosterman.sum ZMod.stdAddChar + (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))) (k*(c : ZMod (H*T)))‖)/(T : ℝ) := by + rw [restricted_average, norm_div] + have ht : ‖(T : ℂ)‖ = (T : ℝ) := by simp + rw [ht] + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg T) + calc + _ ≤ ∑ j : ZMod T, ‖ZMod.stdAddChar (-j*(a : ZMod T)) * + ErdosKloosterman.sum ZMod.stdAddChar + (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))) (k*(c : ZMod (H*T)))‖ := norm_sum_le _ _ + _ = _ := by + apply Finset.sum_congr rfl + intro j _ + rw [norm_mul, AddChar.norm_apply, one_mul] + +theorem restrictedSum_norm_le_second (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (h k : ZMod (H*T)) : + ‖restrictedSum (H*T) T (dvd_mul_left T H) a c h k‖ ≤ + completeScale (H*T) * Real.sqrt (Nat.gcd k.val (H*T)) := by + calc + _ ≤ _ := restrictedSum_norm_le_average H T a c h k + _ ≤ (∑ _j : ZMod T, completeScale (H*T) * Real.sqrt (Nat.gcd k.val (H*T)))/(T : ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg T) + apply Finset.sum_le_sum + intro j _ + have hb := norm_sum_le_sqrt_second (H*T) + (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))) (k*(c : ZMod (H*T))) + rw [ErdosHyperbola.gcd_mul_unit] at hb + exact hb + _ = _ := by + simp only [Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul] + have ht : (T : ℝ) ≠ 0 := by exact_mod_cast NeZero.ne T + field_simp + +theorem restrictedSum_norm_le_first (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (h k : ZMod (H*T)) : + ‖restrictedSum (H*T) T (dvd_mul_left T H) a c h k‖ ≤ + completeScale (H*T) * Real.sqrt T * Real.sqrt (Nat.gcd h.val (H*T)) := by + calc + _ ≤ _ := restrictedSum_norm_le_average H T a c h k + _ ≤ (∑ _j : ZMod T, completeScale (H*T) * Real.sqrt T * + Real.sqrt (Nat.gcd h.val (H*T)))/(T : ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg T) + apply Finset.sum_le_sum + intro j _ + have hg : (Nat.gcd (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))).val (H*T) : ℝ) ≤ + (T : ℝ) * Nat.gcd h.val (H*T) := by + exact_mod_cast shifted_gcd_le H T h j + calc + _ ≤ _ := norm_sum_le_sqrt_first (H*T) + (h+(H : ZMod (H*T))*(j.val : ZMod (H*T))) (k*(c : ZMod (H*T))) + _ ≤ completeScale (H*T) * Real.sqrt ((T : ℝ)*Nat.gcd h.val (H*T)) := + mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hg) (completeScale_nonneg _) + _ = _ := by rw [Real.sqrt_mul (Nat.cast_nonneg T)]; ring + _ = _ := by + simp only [Finset.sum_const, Finset.card_univ, ZMod.card, nsmul_eq_mul] + have ht : (T : ℝ) ≠ 0 := by exact_mod_cast NeZero.ne T + field_simp + +end ErdosHyperbolaError + +end + +section + +namespace ErdosHyperbolaError + +theorem axis_quadrant_budget (D d s t n U V : ℝ) (hD : 0 ≤ D) (hd : 0 ≤ d) + (hs : 1 ≤ s) (ht : 1 ≤ t) (hn : 1 ≤ n) (hU : 0 ≤ U) (hV : 0 ≤ V) : + D*((2*n*d*t)*(U+1)+s*(2*n*d*t)*(V+1)+(2*n*t)*(2*n*d*t))/n^2 ≤ + 8*(D*d*s*t^2)*(1+U/n+V/n) := by + have hn0 : 0 < n := lt_of_lt_of_le (by norm_num) hn + have hs0 : 0 ≤ s := le_trans (by norm_num) hs + have ht0 : 0 ≤ t := le_trans (by norm_num) ht + have ht2 : t ≤ t^2 := by nlinarith + have hst : t ≤ s*t^2 := by + calc + _ ≤ t^2 := ht2 + _ = 1*t^2 := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right hs (sq_nonneg t) + let E := D*d*s*t^2 + have hE : 0 ≤ E := by dsimp [E]; positivity + have hA : D*((2*n*d*t)*(U+1)) ≤ 2*E*n*(U+1) := by + calc + _ = (2*D*n*d)*(U+1)*t := by ring + _ ≤ (2*D*n*d)*(U+1)*(s*t^2) := mul_le_mul_of_nonneg_left hst (by positivity) + _ = _ := by dsimp [E]; ring + have hB : D*(s*(2*n*d*t)*(V+1)) ≤ 2*E*n*(V+1) := by + calc + _ = (2*D*s*n*d)*(V+1)*t := by ring + _ ≤ (2*D*s*n*d)*(V+1)*t^2 := mul_le_mul_of_nonneg_left ht2 (by positivity) + _ = _ := by dsimp [E]; ring + have hC : D*((2*n*t)*(2*n*d*t)) ≤ 4*E*n^2 := by + calc + _ = (4*D*d*n^2*t^2)*1 := by ring + _ ≤ (4*D*d*n^2*t^2)*s := mul_le_mul_of_nonneg_left hs (by positivity) + _ = _ := by dsimp [E]; ring + have hpoly : 2*n*(U+1)+2*n*(V+1)+4*n^2 ≤ 8*(n^2+n*U+n*V) := by + have hn2 : n ≤ n^2 := by nlinarith + nlinarith [mul_nonneg hn0.le hU, mul_nonneg hn0.le hV] + have hsum : D*((2*n*d*t)*(U+1)+s*(2*n*d*t)*(V+1)+(2*n*t)*(2*n*d*t)) ≤ + 8*E*(n^2+n*U+n*V) := by + calc + _ = D*((2*n*d*t)*(U+1))+D*(s*(2*n*d*t)*(V+1))+D*((2*n*t)*(2*n*d*t)) := by ring + _ ≤ 2*E*n*(U+1)+2*E*n*(V+1)+4*E*n^2 := add_le_add (add_le_add hA hB) hC + _ = E*(2*n*(U+1)+2*n*(V+1)+4*n^2) := by ring + _ ≤ E*(8*(n^2+n*U+n*V)) := mul_le_mul_of_nonneg_left hpoly hE + _ = _ := by ring + calc + _ ≤ (8*E*(n^2+n*U+n*V))/n^2 := div_le_div_of_nonneg_right hsum (sq_nonneg n) + _ = _ := by dsimp [E]; field_simp [hn0.ne'] + +theorem rounding_absorb (N T : ℕ) [NeZero N] [NeZero T] (U V : ℝ) (hU : 0 ≤ U) (hV : 0 ≤ V) : + (U+V+1)/(N : ℝ) ≤ errorBase N T*(1+U/(N : ℝ)+V/(N : ℝ)) := by + have hN : (0 : ℝ) < N := by exact_mod_cast NeZero.pos N + have hN1 : (1 : ℝ) ≤ N := by exact_mod_cast NeZero.pos N + have hshape : 0 ≤ 1+U/(N : ℝ)+V/(N : ℝ) := by positivity + calc + _ = 1/(N : ℝ)+U/(N : ℝ)+V/(N : ℝ) := by ring + _ ≤ 1+U/(N : ℝ)+V/(N : ℝ) := + add_le_add (add_le_add ((div_le_one hN).mpr hN1) le_rfl) le_rfl + _ = 1*(1+U/(N : ℝ)+V/(N : ℝ)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (errorBase_one_le N T) hshape + +end ErdosHyperbolaError + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarFreeGate.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarFreeGate.lean new file mode 100644 index 0000000000000000000000000000000000000000..628bea3f43bb390e0f068ca977fc5a235ecfcba2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarFreeGate.lean @@ -0,0 +1,520 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ActualLossDensity +import OAI.NumberTheory.Jacobsthal.Analysis.OmissionForceIntegral + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +open _root_.Filter _root_.Erdos970.Filter +namespace ErdosContinuousOmission +open NumberTheoryLean.FinitePathGeometry +open ErdosBoundaryIntegral Erdos970Dependency.StandardBoundary + +theorem omission_integral_hasSum (i : Side) : + HasSum (fun n : ℕ => ∫ y in sourceDomain i,omissionDensity n i y) + (∫ y in sourceDomain i,lossDensity i y) := by + have hmeas : MeasurableSet (sourceDomain i) := by cases i <;> exact measurableSet_Ioi + apply hasSum_integral_of_dominated_convergence (fun n y => omissionDensity n i y) + (fun n => (omissionDensity_continuous n i).aestronglyMeasurable.restrict) + · intro n + filter_upwards [ae_restrict_mem hmeas] with y hy + rw [Real.norm_eq_abs,abs_of_nonneg (omissionDensity_nonnegative n i hy)] + · exact Eventually.of_forall (fun y => (lossDensity_hasSum i y).summable) + · apply (lossDensity_integrable i).congr + exact Eventually.of_forall (fun y => (lossDensity_hasSum i y).tsum_eq.symm) + · exact Eventually.of_forall (lossDensity_hasSum i) + +noncomputable def omissionLossTerm (n : ℕ) : ℝ := + (∫ y in sourceDomain .even,omissionDensity n .even y)+ + ∫ y in sourceDomain .odd,omissionDensity n .odd y + +theorem omissionLossTerm_nonnegative (n : ℕ) : 0 ≤ omissionLossTerm n := by + unfold omissionLossTerm + apply add_nonneg + · apply integral_nonneg_of_ae + filter_upwards [ae_restrict_mem (show MeasurableSet (sourceDomain .even) from measurableSet_Ioi)] with y hy + exact omissionDensity_nonnegative n .even hy + · apply integral_nonneg_of_ae + filter_upwards [ae_restrict_mem (show MeasurableSet (sourceDomain .odd) from measurableSet_Ioi)] with y hy + exact omissionDensity_nonnegative n .odd hy + +theorem actual_signed_loss_hasSum : + HasSum omissionLossTerm (standardCoefficient-signedCoefficientI) := by + rw [actual_loss_integral] + exact (omission_integral_hasSum .even).add (omission_integral_hasSum .odd) + +theorem actual_signed_loss_series : + (8:ℝ)/3-signedCoefficientI=∑' n : ℕ,omissionLossTerm n := by + have h := actual_signed_loss_hasSum.tsum_eq + rw [standard_coefficient_eq] at h + exact h.symm + +theorem actual_loss_summable : Summable omissionLossTerm := actual_signed_loss_hasSum.summable + +theorem actual_coefficient_le_standard : signedCoefficientI ≤ (8:ℝ)/3 := by + have h : 0 ≤ (∑' n : ℕ,omissionLossTerm n) := tsum_nonneg omissionLossTerm_nonnegative + rw [← actual_signed_loss_series] at h + linarith + +end ErdosContinuousOmission + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosContinuousOmission +open NumberTheoryLean.FinitePathGeometry + +theorem gate_zero_of_side (H : Profile) (i : Side) + (hH : ∀ r b,H i.flip r b=0) (r b : ℝ) : gate H i r b=0 := by + simp only [gate,hH,zero_div,intervalIntegral.integral_zero] + +theorem omission_wrong_parity_zero (n : ℕ) : + (∀ r b,gateIterate (2*n) omissionForce .even r b=0) ∧ + (∀ r b,gateIterate (2*n+1) omissionForce .odd r b=0) := by + induction n with + | zero => + constructor + · intro r b; rfl + · intro r b + exact gate_zero_of_side omissionForce .odd (fun _ _ => rfl) r b + | succ n ih => + have hE : ∀ r b,gateIterate (2*(n+1)) omissionForce .even r b=0 := by + intro r b + rw [show 2*(n+1)=(2*n+1)+1 by omega,gateIterate] + exact gate_zero_of_side (gateIterate (2*n+1) omissionForce) .even ih.2 r b + refine ⟨hE,?_⟩ + intro r b + rw [gateIterate] + exact gate_zero_of_side (gateIterate (2*(n+1)) omissionForce) .odd hE r b + +end ErdosContinuousOmission + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +open _root_.Filter _root_.Erdos970.Filter +namespace ErdosContinuousOmission +open ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +theorem omissionDensity_integrable (n : ℕ) (i : Side) : + IntegrableOn (omissionDensity n i) (sourceDomain i) := by + have hm : MeasurableSet (sourceDomain i) := by cases i <;> exact measurableSet_Ioi + apply (lossDensity_integrable i).mono' (omissionDensity_continuous n i).aestronglyMeasurable.restrict + filter_upwards [ae_restrict_mem hm] with y hy + rw [Real.norm_eq_abs,abs_of_nonneg (omissionDensity_nonnegative n i hy)] + have h := (lossDensity_hasSum i y).summable.sum_le_tsum ({n}:Finset ℕ) + (fun k _ => omissionDensity_nonnegative k i hy) + simpa only [Finset.sum_singleton,(lossDensity_hasSum i y).tsum_eq] using h + +theorem first_odd_density_low {y : ℝ} (hy : y ≤ 1) : omissionDensity 0 .odd y=y^2 := by + have hc : upperCutoff .odd (2*y+2) 2=1 := upperCutoff_odd_small (by linarith) + norm_num [omissionDensity,sourceWeight,gateIterate,omissionForce,hc,survivorBaseline,baseCutoff] + ring + +theorem first_odd_density_middle {y : ℝ} (hy1 : 1 ≤ y) (hy2 : y ≤ 2) : + omissionDensity 0 .odd y=2*y-y^2 := by + have hc : upperCutoff .odd (2*y+2) 2=y := by + change max 1 (min (min 2 2) ((2*y+2-2)/2))=y + have he : (2*y+2-2)/2=y := by ring + rw [he,min_self,min_eq_right hy2,max_eq_right hy1] + have hn : y ≠ 0 := by linarith + norm_num [omissionDensity,sourceWeight,gateIterate,omissionForce,hc,survivorBaseline,baseCutoff] + field_simp + +theorem first_odd_density_high {y : ℝ} (hy : 2 ≤ y) : omissionDensity 0 .odd y=0 := by + have hc : upperCutoff .odd (2*y+2) 2=2 := by + change max 1 (min (min 2 2) ((2*y+2-2)/2))=2 + have he : (2*y+2-2)/2=y := by ring + rw [he,min_self,min_eq_left hy,max_eq_right (by norm_num : (1:ℝ)≤2)] + norm_num [omissionDensity,sourceWeight,gateIterate,omissionForce,hc,survivorBaseline,baseCutoff] + +theorem actual_first_loss_eq_one : omissionLossTerm 0=1 := by + have he : (∫ y in sourceDomain .even,omissionDensity 0 .even y)=0 := by + simp [omissionDensity,sourceWeight,gateIterate,omissionForce] + have hz : (∫ y in Ioi 2,omissionDensity 0 .odd y)=0 := by + apply setIntegral_eq_zero_of_forall_eq_zero + intro y hy + exact first_odd_density_high (le_of_lt hy) + have hlow : (∫ y : ℝ in 0..1,omissionDensity 0 .odd y)=(1:ℝ)/3 := by + calc + _ = ∫ y : ℝ in 0..1,y^2 := by + apply intervalIntegral.integral_congr + intro y hy + rw [uIcc_of_le (by norm_num : (0:ℝ)≤1)] at hy + exact first_odd_density_low hy.2 + _ = _ := by norm_num + have hmid : (∫ y : ℝ in 1..2,omissionDensity 0 .odd y)=(2:ℝ)/3 := by + calc + _ = ∫ y : ℝ in 1..2,2*y-y^2 := by + apply intervalIntegral.integral_congr + intro y hy + rw [uIcc_of_le (by norm_num : (1:ℝ)≤2)] at hy + exact first_odd_density_middle hy.1 hy.2 + _ = _ := by + have hl : IntervalIntegrable (fun y : ℝ => 2*y) volume 1 2 := + (continuous_const.mul continuous_id).intervalIntegrable 1 2 + have hq : IntervalIntegrable (fun y : ℝ => y^2) volume 1 2 := + (continuous_id.pow 2).intervalIntegrable 1 2 + rw [intervalIntegral.integral_sub hl hq,intervalIntegral.integral_const_mul] + norm_num + have hsplit := intervalIntegral.integral_add_adjacent_intervals + ((omissionDensity_continuous 0 .odd).intervalIntegrable (μ := volume) 0 1) + ((omissionDensity_continuous 0 .odd).intervalIntegrable (μ := volume) 1 2) + rw [hlow,hmid] at hsplit + have hall := intervalIntegral.integral_Ioi_sub_Ioi (omissionDensity_integrable 0 .odd) (by norm_num : (0:ℝ)≤2) + rw [hz,sub_zero] at hall + unfold omissionLossTerm + rw [he,zero_add] + change (∫ y in Ioi 0,omissionDensity 0 .odd y)=1 + linarith + +end ErdosContinuousOmission + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +noncomputable def freeGate (H : Profile) (i : Side) (r b : ℝ) : ℝ := + ∫ x in (1:ℝ)..baseCutoff b,H i.flip (r-x) x/(max 1 x) + +theorem freeGate_continuous {H : Profile} (hH : JointContinuous H) : JointContinuous (freeGate H) := by + intro i + let F : (ℝ×ℝ) → ℝ → ℝ := fun p x => H i.flip (p.1-x) x/(max 1 x) + have hc : Continuous (fun q : (ℝ×ℝ)×ℝ => H i.flip (q.1.1-q.2) q.2) := + (hH i.flip).comp ((continuous_fst.fst.sub continuous_snd).prodMk continuous_snd) + have hd : Continuous (fun q : (ℝ×ℝ)×ℝ => max 1 q.2) := continuous_const.max continuous_snd + have hF : Continuous F.uncurry := hc.div hd (fun q => ne_of_gt + ((by norm_num : (0:ℝ)<1).trans_le (le_max_left 1 q.2))) + have hb : Continuous (fun p : ℝ×ℝ => baseCutoff p.2) := + continuous_const.max (continuous_const.min continuous_snd) + exact continuous_variable_upper_integral F hF (fun p => baseCutoff p.2) hb + +theorem freeGate_nonnegative {H : Profile} (hH : ∀ i r b,0 ≤ H i r b) (i : Side) (r b : ℝ) : + 0 ≤ freeGate H i r b := by + apply intervalIntegral.integral_nonneg_of_forall (baseCutoff_bounds b).1 + intro x + exact div_nonneg (hH i.flip (r-x) x) (zero_le_one.trans (le_max_left 1 x)) + +theorem gate_le_freeGate {H : Profile} (hH : JointContinuous H) + (hpos : ∀ i r b,0 ≤ H i r b) (i : Side) (r b : ℝ) : gate H i r b ≤ freeGate H i r b := by + have hc := gate_integrand_continuous hH i r + have hadd := intervalIntegral.integral_add_adjacent_intervals + (hc.intervalIntegrable (μ := volume) 1 (upperCutoff i r b)) + (hc.intervalIntegrable (μ := volume) (upperCutoff i r b) (baseCutoff b)) + have hp : 0 ≤ ∫ x in upperCutoff i r b..baseCutoff b,H i.flip (r-x) x/(max 1 x) := by + apply intervalIntegral.integral_nonneg_of_forall (cutoff_le_base i r b) + intro x + exact div_nonneg (hpos i.flip (r-x) x) (zero_le_one.trans (le_max_left 1 x)) + unfold gate freeGate + linarith + +theorem gate_mono {H G : Profile} (hH : JointContinuous H) (hG : JointContinuous G) + (h : ∀ i r b,H i r b ≤ G i r b) (i : Side) (r b : ℝ) : gate H i r b ≤ gate G i r b := by + apply intervalIntegral.integral_mono_on (upperCutoff_bounds i r b).1 + ((gate_integrand_continuous hH i r).intervalIntegrable 1 _) + ((gate_integrand_continuous hG i r).intervalIntegrable 1 _) + intro x _ + exact div_le_div_of_nonneg_right (h i.flip (r-x) x) (zero_le_one.trans (le_max_left 1 x)) + +noncomputable def freeGateIterate : ℕ → Profile → Profile + | 0,H => H + | n+1,H => freeGate (freeGateIterate n H) + +theorem freeGateIterate_continuous {H : Profile} (hH : JointContinuous H) (n : ℕ) : + JointContinuous (freeGateIterate n H) := by + induction n with + | zero => exact hH + | succ n ih => exact freeGate_continuous ih + +theorem freeGateIterate_nonnegative {H : Profile} (hH : ∀ i r b,0 ≤ H i r b) (n : ℕ) : + ∀ i r b,0 ≤ freeGateIterate n H i r b := by + induction n with + | zero => exact hH + | succ n ih => exact freeGate_nonnegative ih + +theorem gateIterate_prefix_le {H : Profile} (hH : JointContinuous H) + (hpos : ∀ i r b,0 ≤ H i r b) (k n : ℕ) : + ∀ i r b,gateIterate (k+n) H i r b ≤ freeGateIterate k (gateIterate n H) i r b := by + induction k with + | zero => intro i r b; simp only [zero_add,freeGateIterate,le_refl] + | succ k ih => + intro i r b + rw [show k+1+n=(k+n)+1 by omega,gateIterate,freeGateIterate] + calc + _ ≤ gate (freeGateIterate k (gateIterate n H)) i r b := + gate_mono (gateIterate_continuous hH _) (freeGateIterate_continuous (gateIterate_continuous hH n) k) ih i r b + _ ≤ _ := gate_le_freeGate (freeGateIterate_continuous (gateIterate_continuous hH n) k) + (freeGateIterate_nonnegative (gateIterate_nonnegative hpos n) k) i r b + +theorem actual_omission_prefix_le (k : ℕ) (i : Side) (r b : ℝ) : + gateIterate (k+2) omissionForce i r b ≤ + freeGateIterate k (gateIterate 2 omissionForce) i r b := + gateIterate_prefix_le omissionForce_continuous omissionForce_nonnegative k 2 i r b + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionTail + +noncomputable def lastWindowCoefficient (S a b c : ℝ) : ℝ := + ((S+a+b+2*c)^3-(S+2*a)^3)/(12*c) + +theorem last_window_integral (S a b c : ℝ) : + (∫ y : ℝ in (S+2*a)/2..(S+a+b+2*c)/2,2*y^2/c)=lastWindowCoefficient S a b c := by + rw [intervalIntegral.integral_div,intervalIntegral.integral_const_mul,integral_pow] + norm_num + unfold lastWindowCoefficient + ring + +theorem last_window_width {S a b c : ℝ} (ha : a ≤ 2) (hb : 1 ≤ b) (hc : 1 ≤ c) (hab : b ≤ a) : + 1 ≤ (S+a+b+2*c)-(S+2*a) ∧ (S+a+b+2*c)-(S+2*a) ≤ 2*c := by + constructor <;> linarith + +theorem last_window_square_bound {S a b c : ℝ} (hS : 0 ≤ S) + (ha1 : 1 ≤ a) (ha2 : a ≤ 2) (hb1 : 1 ≤ b) (hc1 : 1 ≤ c) (hab : b ≤ a) : + lastWindowCoefficient S a b c ≤ (S+a+b+2*c)^2/2 := by + have hw := last_window_width (S := S) ha2 hb1 hc1 hab + have hU : 0 ≤ S+a+b+2*c := by linarith + have hV : 0 ≤ S+2*a := by linarith + have hUV : S+2*a ≤ S+a+b+2*c := by linarith + have hcube : (S+a+b+2*c)^3-(S+2*a)^3 ≤ + 3*(S+a+b+2*c)^2*((S+a+b+2*c)-(S+2*a)) := by + have hp := mul_nonneg (sq_nonneg ((S+a+b+2*c)-(S+2*a))) (show 0 ≤ 2*(S+a+b+2*c)+(S+2*a) by linarith) + nlinarith + have hwidth := mul_le_mul_of_nonneg_left hw.2 (mul_nonneg (by norm_num : (0:ℝ)≤3) (sq_nonneg (S+a+b+2*c))) + unfold lastWindowCoefficient + apply (div_le_iff₀ (by linarith : 0 < 12*c)).mpr + nlinarith + +theorem last_window_mean_bound (k : ℕ) {S a b c : ℝ} + (hSlo : (k:ℝ) ≤ S) (hShi : S ≤ 2*(k:ℝ)) (hSc : (k:ℝ)*c ≤ S) + (ha1 : 1 ≤ a) (ha2 : a ≤ 2) (hb1 : 1 ≤ b) (hba : b ≤ a) + (hc1 : 1 ≤ c) (hcb : c ≤ b) : + lastWindowCoefficient S a b c ≤ + (((k:ℝ)+4)^2/2)*(3*(S+a+b+c)/((k:ℝ)+3)-2) := by + let m : ℝ := (k:ℝ)+3 + let T : ℝ := S+a+b+c + have hk : 0 ≤ (k:ℝ) := Nat.cast_nonneg k + have hm : 0 < m := by dsimp [m]; linarith + have hTlo : m ≤ T := by dsimp [m,T]; linarith + have hThi : T ≤ 2*m := by dsimp [m,T]; linarith + have hTc : m*c ≤ T := by dsimp [m,T]; nlinarith + have hmean1 : 1 ≤ T/m := (one_le_div hm).mpr hTlo + have hmean2 : T/m ≤ 2 := (div_le_iff₀ hm).mpr hThi + have hmean : (T/m)^2 ≤ 3*(T/m)-2 := by + have hp := mul_nonneg (sub_nonneg.mpr hmean1) (sub_nonneg.mpr hmean2) + nlinarith + have hA : S+a+b+2*c ≤ (m+1)*(T/m) := by + rw [← mul_div_assoc] + apply (le_div_iff₀ hm).mpr + change (S+a+b+2*c)*m ≤ (m+1)*T + dsimp [T] at hTc ⊢ + nlinarith + have hA0 : 0 ≤ S+a+b+2*c := by linarith + have hsq := mul_self_le_mul_self hA0 hA + have hlin := mul_le_mul_of_nonneg_left hmean (sq_nonneg (m+1)) + have hw := last_window_square_bound (hSlo.trans' hk) ha1 ha2 hb1 hc1 hba + have hme : (k:ℝ)+4=m+1 := by dsimp [m]; ring + rw [hme] + change lastWindowCoefficient S a b c ≤ ((m+1)^2/2)*(3*T/m-2) + have hsq2 : (S+a+b+2*c)^2 ≤ (m+1)^2*(T/m)^2 := by nlinarith [hsq] + calc + _ ≤ (S+a+b+2*c)^2/2 := hw + _ ≤ ((m+1)^2*(T/m)^2)/2 := div_le_div_of_nonneg_right hsq2 (by norm_num) + _ ≤ ((m+1)^2*(3*(T/m)-2))/2 := div_le_div_of_nonneg_right hlin (by norm_num) + _ = _ := by ring + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission + +noncomputable def orderedMass : ℕ → ℝ → ℝ + | 0,_ => 1 + | n+1,b => ∫ x in (1:ℝ)..baseCutoff b,orderedMass n x/(max 1 x) + +theorem orderedMass_continuous (n : ℕ) : Continuous (orderedMass n) := by + induction n with + | zero => exact continuous_const + | succ n ih => + have hc : Continuous (fun x : ℝ => orderedMass n x/(max 1 x)) := + ih.div (continuous_const.max continuous_id) (fun x => ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _))) + exact (intervalIntegral.differentiable_integral_of_continuous hc).continuous.comp + (continuous_const.max (continuous_const.min continuous_id)) + +theorem orderedMass_nonnegative (n : ℕ) (b : ℝ) : 0 ≤ orderedMass n b := by + induction n generalizing b with + | zero => norm_num [orderedMass] + | succ n ih => + apply intervalIntegral.integral_nonneg_of_forall (baseCutoff_bounds b).1 + intro x + exact div_nonneg (ih x) (zero_le_one.trans (le_max_left _ _)) + +theorem log_power_primitive (n : ℕ) {x : ℝ} (hx : 0 < x) : + HasDerivAt (fun x : ℝ => (Real.log x)^(n+1)/((n+1).factorial:ℝ)) + ((Real.log x)^n/((n.factorial:ℝ)*x)) x := by + have hh := ((Real.hasDerivAt_log hx.ne').pow (n+1)).div_const ((n+1).factorial:ℝ) + convert! hh using 1 + simp only [Nat.add_sub_cancel_right,Nat.factorial_succ,Nat.cast_mul] + have hn : (n.factorial:ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + have hn1 : ((n+1:ℕ):ℝ) ≠ 0 := by positivity + field_simp + +theorem orderedMass_eq (n : ℕ) {b : ℝ} (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + orderedMass n b=(Real.log b)^n/(n.factorial:ℝ) := by + induction n generalizing b with + | zero => norm_num [orderedMass] + | succ n ih => + rw [orderedMass,baseCutoff_on hb1 hb2] + have he : (∫ x in (1:ℝ)..b,orderedMass n x/(max 1 x))= + ∫ x in (1:ℝ)..b,(Real.log x)^n/((n.factorial:ℝ)*x) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hb1] at hx + dsimp only + rw [ih hx.1 (hx.2.trans hb2),max_eq_right hx.1] + ring + rw [he] + have hn : (n.factorial:ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + have hc : ContinuousOn (fun x : ℝ => (Real.log x)^n/((n.factorial:ℝ)*x)) (uIcc 1 b) := by + rw [uIcc_of_le hb1] + intro x hx + have hx0 : x ≠ 0 := by linarith [hx.1] + apply ContinuousAt.continuousWithinAt + fun_prop (disch := simp_all) + have hd : ∀ x ∈ uIcc (1:ℝ) b,HasDerivAt + (fun x : ℝ => (Real.log x)^(n+1)/((n+1).factorial:ℝ)) + ((Real.log x)^n/((n.factorial:ℝ)*x)) x := by + intro x hx + rw [uIcc_of_le hb1] at hx + exact log_power_primitive n (by linarith [hx.1]) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hd (hc.intervalIntegrable (μ := volume))] + simp + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +abbrev ScalarProfile := ℝ → ℝ → ℝ +def ScalarContinuous (H : ScalarProfile) : Prop := Continuous (fun p : ℝ×ℝ => H p.1 p.2) +noncomputable def scalarFreeGate (H : ScalarProfile) (r b : ℝ) : ℝ := + ∫ x in (1:ℝ)..baseCutoff b,H (r-x) x/(max 1 x) + +noncomputable def scalarFreeIterate : ℕ → ScalarProfile → ScalarProfile + | 0,H => H + | n+1,H => scalarFreeGate (scalarFreeIterate n H) + +theorem scalarFreeGate_continuous {H : ScalarProfile} (hH : ScalarContinuous H) : + ScalarContinuous (scalarFreeGate H) := + freeGate_continuous (H := fun _ => H) (fun _ => hH) .even + +theorem scalarFreeIterate_continuous {H : ScalarProfile} (hH : ScalarContinuous H) (n : ℕ) : + ScalarContinuous (scalarFreeIterate n H) := by + induction n with + | zero => exact hH + | succ n ih => exact scalarFreeGate_continuous ih + +theorem freeGate_total {H : Profile} (hH : JointContinuous H) (r b : ℝ) : + freeGate H .even r b+freeGate H .odd r b= + scalarFreeGate (fun r b => H .even r b+H .odd r b) r b := by + have he := (gate_integrand_continuous hH .even r).intervalIntegrable (μ := volume) 1 (baseCutoff b) + have ho := (gate_integrand_continuous hH .odd r).intervalIntegrable (μ := volume) 1 (baseCutoff b) + unfold freeGate scalarFreeGate + rw [← intervalIntegral.integral_add he ho] + apply intervalIntegral.integral_congr + intro x _ + dsimp only [Side.flip] + ring + +theorem freeGateIterate_total {H : Profile} (hH : JointContinuous H) (n : ℕ) (r b : ℝ) : + freeGateIterate n H .even r b+freeGateIterate n H .odd r b= + scalarFreeIterate n (fun r b => H .even r b+H .odd r b) r b := by + induction n generalizing r b with + | zero => rfl + | succ n ih => + rw [freeGateIterate,freeGate_total (freeGateIterate_continuous hH n)] + have he : (fun r b => freeGateIterate n H .even r b+freeGateIterate n H .odd r b)= + scalarFreeIterate n (fun r b => H .even r b+H .odd r b) := by funext r b; exact ih r b + rw [he] + rfl + +noncomputable def terminalBlock (r b : ℝ) : ℝ := gateIterate 2 omissionForce .odd r b + +theorem terminalBlock_continuous : ScalarContinuous terminalBlock := + gateIterate_continuous omissionForce_continuous 2 .odd + +theorem terminalBlock_nonnegative (r b : ℝ) : 0 ≤ terminalBlock r b := + gateIterate_nonnegative omissionForce_nonnegative 2 .odd r b + +theorem actual_free_total (k : ℕ) (r b : ℝ) : + freeGateIterate k (gateIterate 2 omissionForce) .even r b+ + freeGateIterate k (gateIterate 2 omissionForce) .odd r b= + scalarFreeIterate k terminalBlock r b := by + rw [freeGateIterate_total (gateIterate_continuous omissionForce_continuous 2)] + have he : (fun r b => gateIterate 2 omissionForce .even r b+gateIterate 2 omissionForce .odd r b)=terminalBlock := by + funext r b + have hh := (omission_wrong_parity_zero 1).1 r b + norm_num only [Nat.reduceMul] at hh + rw [hh,zero_add] + rfl + rw [he] + +noncomputable def combinedDensity (n : ℕ) (y : ℝ) : ℝ := + (if 1 < y then omissionDensity n .even y else 0)+omissionDensity n .odd y + +theorem actual_combined_density_le (k : ℕ) (y : ℝ) : + combinedDensity (k+2) y ≤ 2*y^2*scalarFreeIterate k terminalBlock (2*y+2) 2 := by + have he := actual_omission_prefix_le k .even (2*y+2) 2 + have ho := actual_omission_prefix_le k .odd (2*y+2) 2 + have hpe := gateIterate_nonnegative omissionForce_nonnegative (k+2) .even (2*y+2) 2 + have hfE := freeGateIterate_nonnegative (gateIterate_nonnegative omissionForce_nonnegative 2) k .even (2*y+2) 2 + have hbE : (if 1 < y then omissionDensity (k+2) .even y else 0) ≤ + 2*y^2*freeGateIterate k (gateIterate 2 omissionForce) .even (2*y+2) 2 := by + by_cases h : 1 < y + · rw [ite_eq_left h] + have hh := mul_le_mul_of_nonneg_left he (mul_nonneg (by norm_num : (0:ℝ)≤2) (sq_nonneg y)) + unfold omissionDensity sourceWeight + nlinarith + · rw [ite_eq_right h] + exact mul_nonneg (mul_nonneg (by norm_num) (sq_nonneg y)) hfE + have hbO : omissionDensity (k+2) .odd y ≤ + 2*y^2*freeGateIterate k (gateIterate 2 omissionForce) .odd (2*y+2) 2 := + mul_le_mul_of_nonneg_left ho (mul_nonneg (by norm_num) (sq_nonneg y)) + have hh := actual_free_total k (2*y+2) 2 + unfold combinedDensity + nlinarith + +end ErdosOmissionTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarTailRecurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarTailRecurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..c81c694cf17d38eb155d7217048764967c6736c4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScalarTailRecurrence.lean @@ -0,0 +1,338 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ThresholdFubini + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission + +theorem quadratic_window_integral (l u e : ℝ) : + (∫ y : ℝ in l..u,y^2-e)=(u^3-l^3)/3-e*(u-l) := by + have hp : IntervalIntegrable (fun y : ℝ => y^2) volume l u := + (continuous_id.pow 2).intervalIntegrable l u + have hc : IntervalIntegrable (fun _y : ℝ => e) volume l u := intervalIntegrable_const + rw [intervalIntegral.integral_sub hp hc,integral_pow,intervalIntegral.integral_const] + norm_num + ring + +theorem integrated_force_window (a l Y b e : ℝ) (hl : 0 ≤ l) (hb1 : 1 ≤ b) (hb2 : b ≤ 2) + (hlT : l ≤ a/2+1) (hTY : a/2+b ≤ Y) : + (∫ y : ℝ in l..Y,(y^2-e)*omissionForce .odd (2*y+2-a) b)= + ∫ t : ℝ in 1..b,(((a/2+t)^3-l^3)/3-e*(a/2+t-l))/(t^2) := by + have hlY : l ≤ Y := by linarith + have hY : 0 ≤ Y := hl.trans hlY + have hP : Measurable (fun y : ℝ => y^2-e) := (measurable_id.pow_const 2).sub measurable_const + have hW : Measurable (fun t : ℝ => (t^2)⁻¹) := (measurable_id.pow_const 2).inv + have hT : Measurable (fun t : ℝ => a/2+t) := measurable_const.add measurable_id + have hPb : ∀ y ∈ Icc l Y,|y^2-e| ≤ Y^2+|e| := by + intro y hy + have hy0 : 0 ≤ y := hl.trans hy.1 + have hy2 : y^2 ≤ Y^2 := by nlinarith [hy.2] + calc + _ ≤ |y^2|+|e| := abs_sub _ _ + _ = y^2+|e| := by rw [abs_of_nonneg (sq_nonneg y)] + _ ≤ _ := add_le_add hy2 le_rfl + have hWb : ∀ t ∈ Icc (1:ℝ) b,|(t^2)⁻¹| ≤ 1 := by + intro t ht + have ht0 : 0 < t := by linarith [ht.1] + rw [abs_of_nonneg (inv_nonneg.mpr (sq_nonneg t))] + apply (inv_le_one₀ (sq_pos_of_pos ht0)).mpr + nlinarith [ht.1] + have hTb : ∀ t ∈ Icc (1:ℝ) b,l ≤ a/2+t ∧ a/2+t ≤ Y := by + intro t ht + exact ⟨by linarith [ht.1],by linarith [ht.2]⟩ + have h := weighted_threshold_swap hP hW hT l Y b (Y^2+|e|) 1 + (by positivity) (by norm_num) hPb hWb hTb + have hinner (y : ℝ) : + (∫ t in Icc (1:ℝ) b,if y exact hH + | succ n ih => + intro r b + apply intervalIntegral.integral_nonneg_of_forall (baseCutoff_bounds b).1 + intro x + exact div_nonneg (ih (r-x) x) (zero_le_one.trans (le_max_left _ _)) + +theorem scalarFreeIterate_high (n : ℕ) {r b : ℝ} (hr : 2*(n:ℝ)+10 ≤ r) : + scalarFreeIterate n terminalBlock r b=0 := by + induction n generalizing r b with + | zero => exact terminalBlock_high (by simpa only [Nat.cast_zero,mul_zero,zero_add] using hr) + | succ n ih => + rw [scalarFreeIterate,scalarFreeGate] + calc + _ = ∫ _x : ℝ in 1..baseCutoff b,(0:ℝ) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (baseCutoff_bounds b).1] at hx + have hx2 : x ≤ 2 := hx.2.trans (baseCutoff_bounds b).2 + dsimp only + rw [ih (by push_cast at hr; linarith : 2*(n:ℝ)+10 ≤ r-x),zero_div] + _ = 0 := by simp + +noncomputable def scalarTailIntegrand (n : ℕ) (S b y : ℝ) : ℝ := + 2*y^2*scalarFreeIterate n terminalBlock (2*y+2-S) b +noncomputable def scalarTailMass (n : ℕ) (S b : ℝ) : ℝ := + ∫ y in Ioi 0,scalarTailIntegrand n S b y + +theorem scalarTailIntegrand_continuous (n : ℕ) (S b : ℝ) : Continuous (scalarTailIntegrand n S b) := by + have hb : Continuous (fun p : ℝ×ℝ => scalarFreeIterate n terminalBlock p.1 p.2) := + scalarFreeIterate_continuous terminalBlock_continuous n + have hp : Continuous (fun y : ℝ => (2*y+2-S,b)) := by fun_prop + have hc : Continuous (fun y : ℝ => scalarFreeIterate n terminalBlock (2*y+2-S) b) := hb.comp hp + exact (continuous_const.mul (continuous_id.pow 2)).mul hc + +theorem scalarTailIntegrand_nonnegative (n : ℕ) (S b y : ℝ) : 0 ≤ scalarTailIntegrand n S b y := + mul_nonneg (mul_nonneg (by norm_num) (sq_nonneg y)) + (scalarFreeIterate_nonnegative terminalBlock_nonnegative n (2*y+2-S) b) + +theorem scalarTailIntegrand_integrable (n : ℕ) (S b : ℝ) : + IntegrableOn (scalarTailIntegrand n S b) (Ioi 0) := by + let Y : ℝ := |S|+(n:ℝ)+5 + have hY : 0 ≤ Y := by dsimp [Y]; positivity + have hc := (scalarTailIntegrand_continuous n S b).integrableOn_Icc (μ := volume) (a := 0) (b := Y) + have hz : IntegrableOn (scalarTailIntegrand n S b) (Ioi Y) := by + have hzero : IntegrableOn (fun _ : ℝ => (0:ℝ)) (Ioi Y) := integrable_zero ℝ ℝ _ + apply hzero.congr_fun _ measurableSet_Ioi + intro y hy + have hyY : Y < y := hy + have hS := le_abs_self S + have hS0 := abs_nonneg S + have hh : 2*(n:ℝ)+10 ≤ 2*y+2-S := by dsimp [Y] at hyY; linarith + simp only [scalarTailIntegrand,scalarFreeIterate_high n hh,mul_zero] + have hu := hc.union hz + rw [Icc_union_Ioi_eq_Ici hY] at hu + exact hu.mono_set Ioi_subset_Ici_self + +theorem scalarTailMass_nonnegative (n : ℕ) (S b : ℝ) : 0 ≤ scalarTailMass n S b := + integral_nonneg (scalarTailIntegrand_nonnegative n S b) + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission + +theorem evenDensity_indicator_integrable (n : ℕ) : + IntegrableOn (fun y : ℝ => if 1 < y then omissionDensity n .even y else 0) (Ioi 0) := by + change Integrable ((Ioi (1:ℝ)).indicator (omissionDensity n .even)) (volume.restrict (Ioi 0)) + rw [integrable_indicator_iff measurableSet_Ioi] + change Integrable (omissionDensity n .even) ((volume.restrict (Ioi (0:ℝ))).restrict (Ioi 1)) + rw [Measure.restrict_restrict measurableSet_Ioi,inter_eq_left.mpr (Ioi_subset_Ioi (by norm_num : (0:ℝ)≤1))] + exact omissionDensity_integrable n .even + +theorem combinedDensity_integrable (n : ℕ) : IntegrableOn (combinedDensity n) (Ioi 0) := + (evenDensity_indicator_integrable n).add (omissionDensity_integrable n .odd) + +theorem combinedDensity_integral (n : ℕ) : + (∫ y in Ioi 0,combinedDensity n y)=omissionLossTerm n := by + have he : (∫ y in Ioi (0:ℝ),if 1 < y then omissionDensity n .even y else 0)= + ∫ y in Ioi 1,omissionDensity n .even y := by + change (∫ y in Ioi (0:ℝ),(Ioi (1:ℝ)).indicator (omissionDensity n .even) y)=_ + rw [setIntegral_indicator measurableSet_Ioi, + inter_eq_right.mpr (Ioi_subset_Ioi (by norm_num : (0:ℝ)≤1))] + unfold combinedDensity + rw [integral_add (evenDensity_indicator_integrable n) (omissionDensity_integrable n .odd),he] + rfl + +theorem actual_loss_le_scalarTailMass (k : ℕ) : omissionLossTerm (k+2) ≤ scalarTailMass k 0 2 := by + rw [← combinedDensity_integral] + apply integral_mono_ae (combinedDensity_integrable (k+2)) (scalarTailIntegrand_integrable k 0 2) + exact Filter.Eventually.of_forall (fun y => by + simpa only [scalarTailIntegrand,sub_zero] using actual_combined_density_le k y) + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission ErdosContinuousBoundary NumberTheoryLean.FinitePathGeometry + +theorem omissionForce_le_one (i : Side) (r b : ℝ) : omissionForce i r b ≤ 1 := by + cases i with + | even => norm_num [omissionForce] + | odd => + have hc := (upperCutoff_bounds .odd r b).1 + have hb : 0 ≤ (baseCutoff b)⁻¹ := inv_nonneg.mpr (by linarith [(baseCutoff_bounds b).1]) + have hi : (upperCutoff .odd r b)⁻¹ ≤ 1 := + (inv_le_one₀ (by linarith : 0 < upperCutoff .odd r b)).mpr hc + unfold omissionForce survivorBaseline + linarith + +theorem freeGate_le_one {H : Profile} (hH : JointContinuous H) + (hupper : ∀ i r b,H i r b ≤ 1) (i : Side) (r b : ℝ) : freeGate H i r b ≤ 1 := by + have hc := gate_integrand_continuous hH i r + have hi := intervalIntegral.integral_mono_on (baseCutoff_bounds b).1 + (hc.intervalIntegrable (μ := volume) 1 (baseCutoff b)) + (intervalIntegrable_const : IntervalIntegrable (fun _ : ℝ => (1:ℝ)) volume 1 (baseCutoff b)) + (fun x _ => (div_le_one (by linarith [le_max_left (1:ℝ) x] : 0 < max 1 x)).mpr + ((hupper i.flip (r-x) x).trans (le_max_left _ _))) + simp only [intervalIntegral.integral_const,smul_eq_mul,mul_one] at hi + exact hi.trans (by linarith [(baseCutoff_bounds b).2]) + +theorem gateIterate_force_le_one (n : ℕ) (i : Side) (r b : ℝ) : gateIterate n omissionForce i r b ≤ 1 := by + induction n generalizing i r b with + | zero => exact omissionForce_le_one i r b + | succ n ih => + exact (gate_le_freeGate (gateIterate_continuous omissionForce_continuous n) + (gateIterate_nonnegative omissionForce_nonnegative n) i r b).trans + (freeGate_le_one (gateIterate_continuous omissionForce_continuous n) ih i r b) + +theorem terminalBlock_le_one (r b : ℝ) : terminalBlock r b ≤ 1 := gateIterate_force_le_one 2 .odd r b + +theorem scalarFreeIterate_le_one (n : ℕ) (r b : ℝ) : scalarFreeIterate n terminalBlock r b ≤ 1 := by + induction n generalizing r b with + | zero => exact terminalBlock_le_one r b + | succ n ih => + exact freeGate_le_one (H := fun _ => scalarFreeIterate n terminalBlock) + (fun _ => scalarFreeIterate_continuous terminalBlock_continuous n) (fun _ => ih) .even r b + +theorem scalar_weighted_bound (n : ℕ) (S b : ℝ) {y Y : ℝ} (hy0 : 0 ≤ y) (hyY : y ≤ Y) : + |scalarTailIntegrand n S b y| ≤ 2*Y^2 := by + rw [abs_of_nonneg (scalarTailIntegrand_nonnegative n S b y)] + have hh := scalarFreeIterate_le_one n (2*y+2-S) b + have hp := mul_le_mul_of_nonneg_left hh (mul_nonneg (by norm_num : (0:ℝ)≤2) (sq_nonneg y)) + unfold scalarTailIntegrand + nlinarith + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.Erdos970.Set _root_.Filter _root_.Erdos970.Filter _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission ErdosOmissionBindings + +theorem scalarTailMass_bounded (n : ℕ) (S b Y : ℝ) (hY : 0 ≤ Y) + (hhigh : S/2+(n:ℝ)+4 ≤ Y) : + scalarTailMass n S b=∫ y : ℝ in 0..Y,scalarTailIntegrand n S b y := by + have hz : (∫ y in Ioi Y,scalarTailIntegrand n S b y)=0 := by + apply setIntegral_eq_zero_of_forall_eq_zero + intro y hy + change Y < y at hy + have hh : 2*(n:ℝ)+10 ≤ 2*y+2-S := by linarith + simp only [scalarTailIntegrand,scalarFreeIterate_high n hh,mul_zero] + have hh := intervalIntegral.integral_Ioi_sub_Ioi (scalarTailIntegrand_integrable n S b) hY + rw [hz,sub_zero] at hh + exact hh + +theorem scalarTailMass_succ (n : ℕ) {S b : ℝ} (hS : 0 ≤ S) (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + scalarTailMass (n+1) S b=∫ x : ℝ in 1..b,scalarTailMass n (S+x) x/x := by + let Y : ℝ := S/2+(n:ℝ)+5 + have hY : 0 ≤ Y := by dsimp [Y]; positivity + let G : ℝ×ℝ → ℝ := fun p => + 2*p.1^2*scalarFreeIterate n terminalBlock (2*p.1+2-S-p.2) p.2/(max 1 p.2) + have hpmap : Continuous (fun p : ℝ×ℝ => (2*p.1+2-S-p.2,p.2)) := by fun_prop + have hphi : Continuous (fun p : ℝ×ℝ => scalarFreeIterate n terminalBlock (2*p.1+2-S-p.2) p.2) := + (scalarFreeIterate_continuous terminalBlock_continuous n).comp hpmap + have hG : Continuous G := by + apply ((continuous_const.mul (continuous_fst.pow 2)).mul hphi).div + (continuous_const.max continuous_snd) + intro p + exact ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _)) + have hbnd : ∀ y ∈ Icc (0:ℝ) Y,∀ x ∈ Icc (1:ℝ) b,|G (y,x)| ≤ 2*Y^2 := by + intro y hy x _hx + have hp := scalarFreeIterate_nonnegative terminalBlock_nonnegative n (2*y+2-S-x) x + have hu := scalarFreeIterate_le_one n (2*y+2-S-x) x + have hn : 0 ≤ 2*y^2*scalarFreeIterate n terminalBlock (2*y+2-S-x) x := by positivity + have hh := mul_le_mul_of_nonneg_left hu (mul_nonneg (by norm_num : (0:ℝ)≤2) (sq_nonneg y)) + dsimp only [G] + rw [abs_of_nonneg (div_nonneg hn (zero_le_one.trans (le_max_left _ _)))] + apply (div_le_self hn (le_max_left (1:ℝ) x)).trans + nlinarith [hy.1,hy.2] + have hswap := bounded_rectangle_swap hG.measurable 0 Y 1 b (2*Y^2) hbnd + have hswap' : (∫ y : ℝ in 0..Y,∫ x : ℝ in 1..b,G (y,x))= + ∫ x : ℝ in 1..b,∫ y : ℝ in 0..Y,G (y,x) := by + simpa only [integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le hY, + ← intervalIntegral.integral_of_le hb1] using hswap + rw [scalarTailMass_bounded (n+1) S b Y hY (by dsimp [Y]; push_cast; linarith)] + have hleft : (∫ y : ℝ in 0..Y,scalarTailIntegrand (n+1) S b y)= + ∫ y : ℝ in 0..Y,∫ x : ℝ in 1..b,G (y,x) := by + apply intervalIntegral.integral_congr + intro y _hy + simp only [scalarTailIntegrand,scalarFreeIterate,scalarFreeGate,baseCutoff_on hb1 hb2, + ← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro x _hx + dsimp only [G] + ring + rw [hleft,hswap'] + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hb1] at hx + have hx2 : x ≤ 2 := hx.2.trans hb2 + dsimp only + rw [scalarTailMass_bounded n (S+x) x Y hY (by dsimp [Y]; linarith),← intervalIntegral.integral_div] + apply intervalIntegral.integral_congr + intro y _hy + dsimp only [G,scalarTailIntegrand] + rw [max_eq_right hx.1] + have he : 2*y+2-S-x=2*y+2-(S+x) := by ring + rw [he] + +end ErdosOmissionTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScaledOriginalTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScaledOriginalTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..81f34617c2a49aac6ec51fae3adb6b23a4dfd97e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/ScaledOriginalTail.lean @@ -0,0 +1,342 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeTailSplit +import OAI.NumberTheory.Jacobsthal.Renewal.NonnegativeOriginalOccupation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceSuccessfulTail + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry FinitePathMeasures TransitionKernels PrimeHistories PrimeKilledChain +open SuccessfulTailTransport ExponentialMesh HorizonMeshSmallness UniformBudgetRate LowStateHorizon +open RegeneratingInverseBands CostPrefixTransport + +theorem even_source_cost_state {start : Node} (hs : Valid start.side start.ratio) + (hi : start.side = .even) : + ∃ s : EvenState,s.1 = start.ratio ∧ FlaggedSourceStart.sourceCostState hs = (.inl s,0) := by + cases start with + | mk i s r cap closed => + change i = .even at hi + subst i + exact ⟨⟨s,hs⟩,rfl,rfl⟩ + +theorem source_successful_tail (κ d c : ℝ) (hκ : 0 < κ) (hd : 0 < d) (hc : 0 < c) : + ∃ b : ℕ → ℝ≥0∞,Tendsto b atTop (𝓝 0) ∧ ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + let S := (Real.log B)^2 + let N := sourceHorizon S B + ∀ M : ℕ,(∑ n ∈ range N,∫⁻ q,cleanReward c (3*((M:ℝ)+1)) q + ∂CouplingData.sourceLaw w ell S start hs (mesh κ w) (n+1)) ≤ b M := by + obtain ⟨L,hL,htransport⟩ := actual_clean_tail_transport + obtain ⟨b,hb,hband⟩ := EvenInverseBands.source_exponential_reward_tail (show 0 < c/3 by linarith) + refine ⟨fun M => ENNReal.ofReal 27*b M,?_,?_⟩ + · simpa only [mul_zero] using ENNReal.Tendsto.const_mul (a:=ENNReal.ofReal 27) hb (Or.inr ENNReal.ofReal_ne_top) + let A := 5*d^3 + have hA : 0 ≤ A := by dsimp [A]; positivity + have hevent := (horizon_mesh_smallness hA hL.le hκ).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + obtain ⟨wAux,hwAux⟩ := eventually_atTop.mp hevent + refine ⟨max normalizationThreshold wAux,normalizationThreshold_gt_one.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hs hell _hB hlogB hcomp hr hi h199 h23 + dsimp only + intro M + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hnorm : normalizationThreshold ≤ w := (le_max_left _ _).trans hw + have hwe := hwAux w ((le_max_right _ _).trans hw) + have hscale := source_scale_bound hwe.2 hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hnum := hwe.1 S hS0 hscale.1 N hscale.2 + have hsum := htransport w ell S start hnorm hell hS0 hscale.1 hr hs hsS hS3 + (mesh κ w) (mesh_pos κ w) N hnum.2.1 hnum.2.2.1 M c hc + obtain ⟨s,hsv,hcost⟩ := even_source_cost_state hs hi + have htail := hband M s (by simpa only [hsv] using h199) (by simpa only [hsv] using h23) + (Real.log start.gap) ell hell + rw [hcost] at hsum + exact hsum.trans (mul_le_mul_of_nonneg_left htail zero_le) + +end NumberTheoryLean.SourceSuccessfulTail + +end + +section + +namespace NumberTheoryLean.SourceTailBudget + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open PrimeExponentialTail PrimeTailSplit InitialPrimeTail +open SourceSuccessfulTail SourceModerateFailure GrowingFarTail ExponentialMesh +open UniformBudgetRate LowStateHorizon + +noncomputable def failureBudget (A c κ w : ℝ) : ℝ := (A/c^2)*Real.exp (-(κ/4)*Real.sqrt (Real.log w)) + +theorem failureBudget_tendsto_zero (A c : ℝ) {κ : ℝ} (hκ : 0 < κ) : + Tendsto (failureBudget A c κ) atTop (𝓝 0) := by + change Tendsto (fun w : ℝ => (A/c^2)*Real.exp (-(κ/4)*Real.sqrt (Real.log w))) atTop (𝓝 0) + simpa only [pow_zero,mul_one] using log_power_exp_tendsto (A/c^2) 0 (show 0 < κ/4 by linarith) + +theorem source_tail_budget : ∃ κ₀ A C : ℝ,0 < κ₀ ∧ 0 < A ∧ 0 < C ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ d c : ℝ,0 < d → 0 < c → + ∃ b : ℕ → ℝ≥0∞,Tendsto b atTop (𝓝 0) ∧ ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node,∀ _hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + ∀ M : ℕ,(∑ n ∈ range N,∫⁻ z,tailReward c (3*((M:ℝ)+1)) z ∂pathLaw w ell S start n) ≤ + ENNReal.ofReal (2*initialBudget c B)+b M+ + ENNReal.ofReal (failureBudget A c κ w)+ENNReal.ofReal (farBudget C c d w) := by + obtain ⟨κM,A,hκM,hA,hmoderate⟩ := source_moderate_failure + obtain ⟨κF,C,hκF,hC,hfar⟩ := source_growing_far_tail + refine ⟨min κM κF,A,C,lt_min hκM hκF,hA,hC,?_⟩ + intro κ hκ hκle d c hd hc + obtain ⟨wM,hwM,hmoderate⟩ := hmoderate κ hκ (hκle.trans (min_le_left _ _)) d hd + obtain ⟨wF,hwF,hfar⟩ := hfar κ hκ (hκle.trans (min_le_right _ _)) d hd + obtain ⟨b,hb,wC,hwC,hclean⟩ := source_successful_tail κ d c hκ hd hc + obtain ⟨wScale,hwScale⟩ := eventually_atTop.mp + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + let w₀ := max (max wM wF) (max wC (max normalizationThreshold wScale)) + refine ⟨b,hb,w₀,hwM.trans_le ((le_max_left _ _).trans (le_max_left _ _)),?_⟩ + intro w hw ell B start hs hell hellB hB hlogB hcomp hr hi h199 h23 hcons hcut + dsimp only + intro M + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hwM' : wM ≤ w := (le_trans (le_max_left _ _) (le_max_left _ _)).trans hw + have hwF' : wF ≤ w := (le_trans (le_max_right _ _) (le_max_left _ _)).trans hw + have hwC' : wC ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw + have hnorm : normalizationThreshold ≤ w := + (le_trans (le_trans (le_max_left _ _) (le_max_right _ _)) (le_max_right _ _)).trans hw + have hwScale' : wScale ≤ w := + (le_trans (le_trans (le_max_right _ _) (le_max_right _ _)) (le_max_right _ _)).trans hw + have hscale := source_scale_bound (hwScale w hwScale') hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hsize : B ≤ start.gap := by + have he : start.cutoff = start.gap/start.ratio := hcons + rw [hcut] at he + have hh := (eq_div_iff (valid_pos hs).ne').mp he + nlinarith + have hsplit := actual_finite_tail_split hnorm hell hS0 hscale.1 hr hs hsS c (3*((M:ℝ)+1)) + (growingCutoff w) (mesh κ w) N + have hinitK := source_initial_tail (w:=w) (ell:=ell) (S:=S) (K:=3*((M:ℝ)+1)) hc hB hsize hi h199 h23 + have hinitT := source_initial_tail (w:=w) (ell:=ell) (S:=S) (K:=growingCutoff w) hc hB hsize hi h199 h23 + have hsuccess := hclean w hwC' ell B start hs hell hB hlogB hcomp hr hi h199 h23 M + have hfailed := hmoderate w hwM' ell B start hs hell hellB hB hlogB hcomp hr h23 hcons hcut c hc + have hfarther := hfar w hwF' ell B start hell hellB hB hlogB hcomp hr hi h199 h23 hcons hcut c hc + have hI : 0 ≤ initialBudget c B := by unfold initialBudget; have h0 := initialConstant_pos; positivity + have hIadd : ENNReal.ofReal (initialBudget c B)+ENNReal.ofReal (initialBudget c B) = + ENNReal.ofReal (2*initialBudget c B) := by + rw [← ENNReal.ofReal_add hI hI] + congr 1 + ring + have hbound := add_le_add (add_le_add (add_le_add (add_le_add hinitK hinitT) hsuccess) hfailed) hfarther + rw [hIadd] at hbound + exact hsplit.trans hbound + +end NumberTheoryLean.SourceTailBudget + +end + +section + +namespace NumberTheoryLean.SourceUniformTail + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership +open PrimeExponentialTail SourceTailBudget InitialPrimeTail GrowingFarTail LowStateHorizon + +theorem four_quarters {ε : ℝ} (hε : 0 ≤ ε) : + ENNReal.ofReal (ε/4)+ENNReal.ofReal (ε/4)+ENNReal.ofReal (ε/4)+ENNReal.ofReal (ε/4) = ENNReal.ofReal ε := by + have hq : 0 ≤ ε/4 := by positivity + rw [← ENNReal.ofReal_add hq hq,← ENNReal.ofReal_add (by positivity) hq, + ← ENNReal.ofReal_add (by positivity) hq] + congr 1 + ring + +theorem actual_uniform_inverse_tail (d c ε : ℝ) (hd : 0 < d) (hc : 0 < c) (hε : 0 < ε) : + ∃ M₀ : ℕ,∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ + ∀ M : ℕ,M₀ ≤ M → ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + ∀ ell : ℝ,1 ≤ ell → ell ≤ B → Real.log B ≤ d*Real.log w → + ∀ start : Node,start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + (∑ n ∈ range N,∫⁻ z,tailReward c (3*((M:ℝ)+1)) z ∂pathLaw w ell S start n) ≤ ENNReal.ofReal ε := by + obtain ⟨κ₀,A,C,hκ₀,hA,hC,hsource⟩ := source_tail_budget + let κ := κ₀/2 + have hκ : 0 < κ := by dsimp [κ]; positivity + have hκle : κ ≤ κ₀ := by dsimp [κ]; linarith + obtain ⟨b,hb,wP,hwP,hsource⟩ := hsource κ hκ hκle d c hd hc + have hδ : 0 < ε/4 := by positivity + obtain ⟨M₀,hM₀⟩ := eventually_atTop.mp (hb.eventually (eventually_le_nhds (ENNReal.ofReal_pos.mpr hδ))) + have hinit : Tendsto (fun B : ℝ => 2*initialBudget c B) atTop (𝓝 0) := by + simpa only [mul_zero] using (initialBudget_tendsto_zero hc).const_mul 2 + obtain ⟨Baux,hBaux⟩ := eventually_atTop.mp (hinit.eventually (eventually_le_nhds hδ)) + obtain ⟨wFail,hwFail⟩ := eventually_atTop.mp + ((failureBudget_tendsto_zero A c hκ).eventually (eventually_le_nhds hδ)) + obtain ⟨wFar,hwFar⟩ := eventually_atTop.mp + ((farBudget_tendsto_zero C d hc).eventually (eventually_le_nhds hδ)) + let B₀ := max (Real.exp 2) Baux + let w₀ := max wP (max wFail wFar) + refine ⟨M₀,B₀,w₀,(Real.exp_pos 2).trans_le (le_max_left _ _),hwP.trans_le (le_max_left _ _),?_⟩ + intro M hM B w hB hw ell hell hellB hcomp start hi h199 h23 hcons hcut + dsimp only + have hBexp : Real.exp 2 ≤ B := (le_max_left _ _).trans hB + have hBpos : 0 < B := (Real.exp_pos 2).trans_le hBexp + have hlogB : 2 ≤ Real.log B := by + simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hBexp + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hr : 0 < start.gap := by + have he : start.cutoff = start.gap/start.ratio := hcons + rw [hcut] at he + have hh := (eq_div_iff (valid_pos hs).ne').mp he + rw [← hh] + exact mul_pos hBpos (valid_pos hs) + have hbudget := hsource w ((le_max_left _ _).trans hw) ell B start hs hell hellB hBpos hlogB hcomp hr hi h199 h23 hcons hcut M + have hI := ENNReal.ofReal_le_ofReal (hBaux B ((le_max_right _ _).trans hB)) + have hF := ENNReal.ofReal_le_ofReal (hwFail w ((le_trans (le_max_left _ _) (le_max_right _ _)).trans hw)) + have hG := ENNReal.ofReal_le_ofReal (hwFar w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw)) + have hsum := add_le_add (add_le_add (add_le_add hI (hM₀ M hM)) hF) hG + rw [four_quarters hε.le] at hsum + exact hbudget.trans hsum + +end NumberTheoryLean.SourceUniformTail + +end + +section + +namespace NumberTheoryLean.ScaledOriginalTail + +open _root_.Set _root_.Filter _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership DerivativeWeights +open PrimeCompactWeights PrimeCorrectionFactor PrimeExponentialTail SourceUniformTail LowStateHorizon + +noncomputable def prefactorBound : ℝ := 2*weight .even (199/100) + +theorem prefactorBound_pos : 0 < prefactorBound := + mul_pos (by norm_num) (weight_pos (by norm_num [Valid])) + +noncomputable def scaledTail (c K w B : ℝ) {ell S : ℝ} (start : Node) : ChainState w ell S start → ℝ≥0∞ + | none => 0 + | some h => if K < h.node.gap then ENNReal.ofReal + (scaledWeight w B start (some h)*Real.exp (-c*h.node.gap)) else 0 + +theorem scaled_reward_prefactor {w ell S B c : ℝ} {start : Node} + (hB : 0 ≤ B) (hr : 0 < start.gap) (hsize : B ≤ start.gap) + (hs : Valid start.side start.ratio) (hi : start.side = .even) (h199 : 199/100 ≤ start.ratio) + (h : History w ell S start) (hcorr : (1+epsilon w)^h.primes.length ≤ 2) : + scaledWeight w B start (some h)*Real.exp (-c*h.node.gap) ≤ + prefactorBound*(h.node.gap^2*Real.exp (-c*h.node.gap)/weight h.node.side h.node.ratio) := by + have hφ := weight_pos hs + have hφg := weight_pos (terminal_valid hs h.admissible) + have hφ0 : 0 < weight .even (199/100) := weight_pos (by norm_num [Valid]) + have hinit : weight start.side start.ratio ≤ weight .even (199/100) := by + rw [hi] + exact TwoStepDensityBounds.weight_antitone (by norm_num [Valid]) (hi ▸ hs) h199 + have hrat : B/start.gap ≤ 1 := (div_le_one hr).mpr hsize + have hrat0 : 0 ≤ B/start.gap := div_nonneg hB hr.le + have hrat2 : (B/start.gap)^2 ≤ 1 := by nlinarith + have hcorr0 := pow_nonneg (normalizer_pos w).le h.primes.length + have hcoef : ((B/start.gap)^2*(1+epsilon w)^h.primes.length)*weight start.side start.ratio ≤ prefactorBound := by + have hh : (B/start.gap)^2*(1+epsilon w)^h.primes.length ≤ 2 := + (mul_le_mul hrat2 hcorr hcorr0 zero_le_one).trans_eq (one_mul 2) + exact mul_le_mul hh hinit hφ.le (by norm_num) + calc + _ = (((B/start.gap)^2*(1+epsilon w)^h.primes.length)*weight start.side start.ratio)* + (h.node.gap^2*Real.exp (-c*h.node.gap)/weight h.node.side h.node.ratio) := by + unfold scaledWeight + ring + _ ≤ _ := mul_le_mul_of_nonneg_right hcoef (by positivity) + +theorem source_scaled_tail_envelope {d w ell B c K : ℝ} {start : Node} + (hB : 0 < B) (hell : 1 ≤ ell) (hlogB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) + (hbudget : correctionBudget d w ≤ 1) + (hi : start.side = .even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hcons : Consistent start) (hcut : start.cutoff = B) + (z : ChainState w ell ((Real.log B)^2) start) : + scaledTail c K w B start z ≤ ENNReal.ofReal prefactorBound*tailReward c K z := by + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have he : B*start.ratio = start.gap := by + have hh : start.cutoff = start.gap/start.ratio := hcons + rw [hcut] at hh + exact (eq_div_iff (valid_pos hs).ne').mp hh + have hr : 0 < start.gap := by rw [← he]; exact mul_pos hB (valid_pos hs) + have hsize : B ≤ start.gap := by nlinarith + have hupper : start.gap ≤ (23/10:ℝ)*B := by nlinarith + cases z with + | none => simp [scaledTail,tailReward] + | some h => + have hcorrection : (1+epsilon w)^h.primes.length ≤ 2 := by + have hh := (history_correction hlogB hcomp hell hr hs hB hupper h).2 + linarith + have hbound := scaled_reward_prefactor (c:=c) hB.le hr hsize hs hi h199 h hcorrection + by_cases hh : K < h.node.gap + · rw [scaledTail,tailReward,ite_eq_left hh,ite_eq_left hh,← ENNReal.ofReal_mul prefactorBound_pos.le] + exact ENNReal.ofReal_le_ofReal hbound + · simp [scaledTail,tailReward,hh] + +theorem actual_uniform_scaled_tail (d c ε : ℝ) (hd : 0 < d) (hc : 0 < c) (hε : 0 < ε) : + ∃ M₀ : ℕ,∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ + ∀ M : ℕ,M₀ ≤ M → ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + ∀ ell : ℝ,1 ≤ ell → ell ≤ B → Real.log B ≤ d*Real.log w → + ∀ start : Node,start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff = B → + let S := (Real.log B)^2 + let N := sourceHorizon S B + (∑ n ∈ range N,∫⁻ z,scaledTail c (3*((M:ℝ)+1)) w B start z ∂pathLaw w ell S start n) ≤ ENNReal.ofReal ε := by + have hD := prefactorBound_pos + obtain ⟨M₀,BR,wR,hBR,hwR,hraw⟩ := actual_uniform_inverse_tail d c (ε/prefactorBound) hd hc (div_pos hε hD) + obtain ⟨wCorr,hwCorr⟩ := eventually_atTop.mp + ((correctionBudget_tendsto_zero d).eventually (eventually_le_nhds (by norm_num : (0:ℝ) < 1))) + refine ⟨M₀,max BR (Real.exp 2),max wR wCorr,hBR.trans_le (le_max_left _ _),hwR.trans_le (le_max_left _ _),?_⟩ + intro M hM B w hB hw ell hell hellB hcomp start hi h199 h23 hcons hcut + dsimp only + let S := (Real.log B)^2 + let N := sourceHorizon S B + have hBR' : BR ≤ B := (le_max_left _ _).trans hB + have hBpos : 0 < B := hBR.trans_le hBR' + have hlogB : 2 ≤ Real.log B := by + have hh : Real.exp 2 ≤ B := (le_max_right _ _).trans hB + simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hh + have hbudget := hwCorr w ((le_max_right _ _).trans hw) + have hb := hraw M hM B w hBR' ((le_max_left _ _).trans hw) ell hell hellB hcomp start hi h199 h23 hcons hcut + have hpoint := source_scaled_tail_envelope (c:=c) (K:=3*((M:ℝ)+1)) hBpos hell hlogB hcomp hbudget hi h199 h23 hcons hcut + calc + _ ≤ ∑ n ∈ range N,ENNReal.ofReal prefactorBound*(∫⁻ z,tailReward c (3*((M:ℝ)+1)) z ∂pathLaw w ell S start n) := by + apply Finset.sum_le_sum + intro n _hn + calc + _ ≤ ∫⁻ z,ENNReal.ofReal prefactorBound*tailReward c (3*((M:ℝ)+1)) z ∂pathLaw w ell S start n := lintegral_mono hpoint + _ = _ := lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + _ ≤ ENNReal.ofReal prefactorBound*ENNReal.ofReal (ε/prefactorBound) := by + rw [← Finset.mul_sum] + exact mul_le_mul_of_nonneg_left hb zero_le + _ = _ := by + rw [← ENNReal.ofReal_mul hD.le] + congr 1 + field_simp + +end NumberTheoryLean.ScaledOriginalTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SecondLossIntegration.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SecondLossIntegration.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6180fe4f948d6911e9e48ff97ad339b40e855b6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SecondLossIntegration.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SecondLossKernel + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosBoundaryLoss + +theorem secondKernel_integral {x : ℝ} (hx : x ∈ Icc (1:ℝ) 2) : + (∫ y in Icc (1:ℝ) 3,secondKernel (y,x))=∫ t : ℝ in 1..x,loss2Kernel t x := by + have hx0 : x ≠ 0 := by linarith [hx.1] + have h := integrated_force_window x 1 3 x 1 (by norm_num) hx.1 hx.2 + (by linarith [hx.1]) (by linarith [hx.2]) + have he : (fun y : ℝ => secondKernel (y,x))= + (fun y => (2/x)*((y^2-1)*omissionForce .odd (2*y+2-x) x)) := by + funext y + simp only [secondKernel,max_eq_right hx.1] + ring + rw [he,integral_const_mul,integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤3),h,← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hx.1] at ht + have ht0 : t ≠ 0 := by linarith [ht.1] + dsimp only [loss2Kernel] + field_simp + ring + +theorem second_loss_ordered_integral : + omissionLossTerm 1=∫ x : ℝ in 1..2,∫ t : ℝ in 1..x,loss2Kernel t x := by + rw [second_loss_bounded] + simp_rw [second_density_kernel] + rw [intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤3)] + simp_rw [intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤2),← integral_Icc_eq_integral_Ioc] + rw [bounded_rectangle_swap secondKernel_continuous.measurable 1 3 1 2 16 + (fun _ hy _ hx => secondKernel_bound hy hx)] + apply setIntegral_congr_fun measurableSet_Icc + intro x hx + exact secondKernel_integral hx + +end ErdosOmissionBindings + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SeparatedSampling.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SeparatedSampling.lean new file mode 100644 index 0000000000000000000000000000000000000000..9631d5e72ba969ad0604137ef7f8c977906c5ad3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SeparatedSampling.lean @@ -0,0 +1,94 @@ +import Mathlib.MeasureTheory.Integral.Bochner.Set +import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +open MeasureTheory Set +open scoped BigOperators + +namespace AdditiveLargeSieve + +theorem endpoint_sample {f f' : ℝ → ℝ} (hf : Continuous f) (hf' : Continuous f') + (hderiv : ∀ x, HasDerivAt f (f' x) x) {a δ : ℝ} (hδ : 0 < δ) : + δ * f a ≤ (∫ x in a..a + δ, f x) + δ * ∫ x in a..a + δ, |f' x| := by + have hab : a ≤ a + δ := by linarith + have hpoint (t : ℝ) (ht : t ∈ Icc a (a + δ)) : + f a ≤ f t + ∫ x in a..a + δ, |f' x| := by + have hftc := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun x _ => hderiv x) (hf'.intervalIntegrable a t) + have hnorm := intervalIntegral.abs_integral_le_integral_abs (μ := volume) (f := f') ht.1 + have hmono := intervalIntegral.integral_mono_interval (μ := volume) (f := fun x => |f' x|) + (le_refl a) ht.1 ht.2 (Filter.Eventually.of_forall fun x => abs_nonneg (f' x)) + (hf'.abs.intervalIntegrable a (a + δ)) + rw [hftc] at hnorm + have := neg_le_abs (f t - f a) + linarith + have hint := intervalIntegral.integral_mono_on hab + (intervalIntegrable_const (μ := volume) (c := f a)) + ((hf.add continuous_const).intervalIntegrable a (a + δ)) hpoint + simp only [Pi.add_apply] at hint + rw [intervalIntegral.integral_add (hf.intervalIntegrable _ _) (continuous_const.intervalIntegrable _ _), + intervalIntegral.integral_const, intervalIntegral.integral_const] at hint + simpa only [add_sub_cancel_left, smul_eq_mul] using hint + +theorem disjoint_sample_intervals {ι : Type*} {s : Finset ι} {t : ι → ℝ} {δ : ℝ} + (hsep : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → δ ≤ |t i - t j|) : + Set.Pairwise (↑s) (fun i j => Disjoint (Ioc (t i) (t i + δ)) + (Ioc (t j) (t j + δ))) := by + intro i hi j hj hij + rw [Set.disjoint_left] + intro x hxi hxj + have h := hsep i hi j hj hij + rcases le_abs.mp h with h | h <;> linarith [hxi.1, hxi.2, hxj.1, hxj.2] + +theorem sum_local_integrals_le {ι : Type*} (s : Finset ι) (t : ι → ℝ) + {δ L U : ℝ} (hδ : 0 < δ) (hLU : L ≤ U) + (hinside : ∀ i ∈ s, L ≤ t i ∧ t i + δ ≤ U) + (hsep : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → δ ≤ |t i - t j|) + {f : ℝ → ℝ} (hf : Continuous f) (hpos : ∀ x, 0 ≤ f x) : + (∑ i ∈ s, ∫ x in t i..t i + δ, f x) ≤ ∫ x in L..U, f x := by + have hle (i : ι) : t i ≤ t i + δ := by linarith + simp_rw [intervalIntegral.integral_of_le (hle _)] + rw [← integral_biUnion_finset s (fun _ _ => measurableSet_Ioc) + (disjoint_sample_intervals hsep) (fun i _ => (hf.intervalIntegrable _ _).1), + intervalIntegral.integral_of_le hLU] + apply setIntegral_mono_set (hf.intervalIntegrable L U).1 + (Filter.Eventually.of_forall hpos) + exact Filter.Eventually.of_forall fun x hx => by + rcases Set.mem_iUnion₂.mp hx with ⟨i, hi, hxi⟩ + exact ⟨lt_of_le_of_lt (hinside i hi).1 hxi.1, hxi.2.trans (hinside i hi).2⟩ + +theorem separated_sampling {ι : Type*} (s : Finset ι) (t : ι → ℝ) + {δ L U : ℝ} (hδ : 0 < δ) (hLU : L ≤ U) + (hinside : ∀ i ∈ s, L ≤ t i ∧ t i + δ ≤ U) + (hsep : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → δ ≤ |t i - t j|) + {f f' : ℝ → ℝ} (hf : Continuous f) (hf' : Continuous f') + (hderiv : ∀ x, HasDerivAt f (f' x) x) (hpos : ∀ x, 0 ≤ f x) : + (∑ i ∈ s, f (t i)) ≤ + δ⁻¹ * (∫ x in L..U, f x) + ∫ x in L..U, |f' x| := by + have hlocal := Finset.sum_le_sum (s := s) fun i _ => endpoint_sample hf hf' hderiv + (a := t i) hδ + rw [← Finset.mul_sum, Finset.sum_add_distrib, ← Finset.mul_sum] at hlocal + have hfbound := sum_local_integrals_le s t hδ hLU hinside hsep hf hpos + have hdbound := sum_local_integrals_le s t hδ hLU hinside hsep hf'.abs + (fun x => abs_nonneg (f' x)) + have hbound : δ * (∑ i ∈ s, f (t i)) ≤ + (∫ x in L..U, f x) + δ * ∫ x in L..U, |f' x| := + hlocal.trans (add_le_add hfbound (mul_le_mul_of_nonneg_left hdbound hδ.le)) + calc + (∑ i ∈ s, f (t i)) ≤ ((∫ x in L..U, f x) + + δ * ∫ x in L..U, |f' x|) / δ := (le_div_iff₀ hδ).2 (by simpa [mul_comm] using hbound) + _ = _ := by field_simp + +end AdditiveLargeSieve + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SiegelWalfisz.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SiegelWalfisz.lean new file mode 100644 index 0000000000000000000000000000000000000000..fcb9d9b00b576fad6d8604d3b9ab08e84c660c0f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SiegelWalfisz.lean @@ -0,0 +1,113 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueSqrtSplit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter _root_.MeasureTheory +open scoped Topology +open ErdosPrimeInputs.PrimeCountAbel (logarithmicIntegral) + +theorem siegel_walfisz_eventually (A M : ℝ) (hA : 0 < A) (hM : 0 < M) : + ∃ C : ℝ, 0 < C ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q] (r : ℤ), + IsUnit (r:ZMod q) → (q:ℝ) ≤ (Real.log X)^A → + |((intervalPrimes 0 X q r).card:ℝ)-logarithmicIntegral X/(q.totient:ℝ)| ≤ + C*X/(Real.log X)^M := by + obtain ⟨K,hK,hθ⟩ := residueTheta_log_power (A+1) M (by linarith) hM + obtain ⟨b,hb⟩ := eventually_atTop.mp hθ + let D : ℝ := (Real.log 4+1)/(Real.log 2)^2 + let E : ℝ := 2/Real.log 2 + have hD : 0 < D := by dsimp [D]; positivity + have hE : 0 < E := by dsimp [E]; positivity + refine ⟨E+K+D+K*(2:ℝ)^M,by positivity,?_⟩ + filter_upwards [Real.tendsto_sqrt_atTop.eventually (eventually_ge_atTop (max 3 b)), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (2*(2:ℝ)^A)), + eventually_sqrt_le_log_power M,eventually_log_rpow_le_self M] with X hs hlog hroot hpow + intro q _ r hr hq + have hs3 : 3 ≤ Real.sqrt X := (le_max_left _ _).trans hs + have hsb : b ≤ Real.sqrt X := (le_max_right _ _).trans hs + have hx3 : 3 ≤ X := hpow.1 + have hx0 : 0 < X := by linarith + have hsX : Real.sqrt X ≤ X := by nlinarith [Real.sq_sqrt hx0.le] + have hL1 : 1 ≤ Real.log X := + ((Real.lt_log_iff_exp_lt hx0).mpr (Real.exp_one_lt_three.trans_le hx3)).le + have hL : 0 < Real.log X := by linarith + have hscale : 1 ≤ X/(Real.log X)^M := (le_div_iff₀ (by positivity)).mpr (by simpa using hpow.2) + have herror : ∀ t, Real.sqrt X ≤ t → + |residueTheta (r:ZMod q) t-t/(q.totient:ℝ)| ≤ K*t/(Real.log t)^M := by + intro t ht + exact hb t (hsb.trans ht) q (r:ZMod q) hr + (modulus_admissible_above_sqrt hA hs3 hlog ht hq) + have hend : |(residueTheta (r:ZMod q) X-X/(q.totient:ℝ))/Real.log X| ≤ + K*X/(Real.log X)^M := by + rw [abs_div,abs_of_pos hL] + exact (div_le_div_of_nonneg_right (herror X hsX) hL.le).trans + (div_le_self (by positivity) hL1) + have hlo : |∫ t in 2..Real.sqrt X, residueErrorKernel (r:ZMod q) t| ≤ + D*X/(Real.log X)^M := by + calc + _ ≤ D*Real.sqrt X := residueErrorKernel_low_integral _ (by linarith) + _ ≤ D*(X/(Real.log X)^M) := mul_le_mul_of_nonneg_left hroot hD.le + _ = _ := by ring + have hhi := residueErrorKernel_high_integral (r:ZMod q) hK.le hM hs3 herror + have hsplit := intervalIntegral.integral_add_adjacent_intervals + (residueErrorKernel_integrable (r:ZMod q) (by norm_num) (by linarith : (2:ℝ)≤Real.sqrt X)) + (residueErrorKernel_integrable (r:ZMod q) (by linarith : (2:ℝ)≤Real.sqrt X) hsX) + have hint : |∫ t in 2..X, residueErrorKernel (r:ZMod q) t| ≤ + D*X/(Real.log X)^M+(K*(2:ℝ)^M)*X/(Real.log X)^M := by + rw [← hsplit] + exact (abs_add_le _ _).trans (add_le_add hlo hhi) + have hphi : (1:ℝ) ≤ q.totient := by exact_mod_cast Nat.totient_pos.mpr (NeZero.pos q) + have hconst : |2/((q.totient:ℝ)*Real.log 2)| ≤ E*X/(Real.log X)^M := by + rw [abs_of_nonneg (by positivity)] + calc + _ = E/(q.totient:ℝ) := by dsimp [E]; ring + _ ≤ E := div_le_self hE.le hphi + _ ≤ E*(X/(Real.log X)^M) := by simpa only [mul_one] using mul_le_mul_of_nonneg_left hscale hE.le + _ = _ := by ring + rw [intervalPrimes_error_eq (by linarith) q r] + calc + _ ≤ |2/((q.totient:ℝ)*Real.log 2)|+ + |(residueTheta (r:ZMod q) X-X/(q.totient:ℝ))/Real.log X|+ + |∫ t in 2..X, residueErrorKernel (r:ZMod q) t| := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ ≤ E*X/(Real.log X)^M+K*X/(Real.log X)^M+ + (D*X/(Real.log X)^M+(K*(2:ℝ)^M)*X/(Real.log X)^M) := + add_le_add (add_le_add hconst hend) hint + _ = _ := by ring + +lemma isUnit_intCast_of_isCoprime {q : ℕ} {r : ℤ} (hr : IsCoprime r (q:ℤ)) : + IsUnit (r:ZMod q) := by + obtain ⟨u,v,huv⟩ := hr + have hc : (u:ZMod q)*(r:ZMod q)+(v:ZMod q)*(q:ZMod q)=1 := by + have h := congrArg (fun z:ℤ => (z:ZMod q)) huv + push_cast at h + exact h + simp only [ZMod.natCast_self,mul_zero,add_zero] at hc + apply isUnit_of_dvd_one + exact ⟨(u:ZMod q),by simpa only [mul_comm] using hc.symm⟩ + +theorem siegel_walfisz (A M : ℝ) (hA : 0 < A) (hM : 0 < M) : + ∃ C X₀ : ℝ, 0 < C ∧ 3 ≤ X₀ ∧ ∀ X : ℝ, X₀ ≤ X → + ∀ (q : ℕ) (r : ℤ), 0 < q → IsCoprime r (q:ℤ) → + (q:ℝ) ≤ (Real.log X)^A → + |((intervalPrimes 0 X q r).card:ℝ)-logarithmicIntegral X/(q.totient:ℝ)| ≤ + C*X/(Real.log X)^M := by + obtain ⟨C,hC,h⟩ := siegel_walfisz_eventually A M hA hM + obtain ⟨b,hb⟩ := eventually_atTop.mp h + refine ⟨C,max 3 b,hC,le_max_left _ _,?_⟩ + intro X hX q r hq hr hbound + let _ : NeZero q := ⟨hq.ne'⟩ + exact hb X ((le_max_right _ _).trans hX) q r (isUnit_intCast_of_isCoprime hr) hbound + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SignedCompletedPowers.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SignedCompletedPowers.lean new file mode 100644 index 0000000000000000000000000000000000000000..96bed4c5c7d3c96c229fcee2a1f2df4e9d0dc84a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SignedCompletedPowers.lean @@ -0,0 +1,75 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CompactTestMeasurable +import OAI.NumberTheory.Jacobsthal.Renewal.ContinuousCompletedOccupation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SignedCompletedPowers + +open _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open CemeteryKernel CompactTestMeasurable + +variable {α : Type*} [MeasurableSpace α] + +theorem finite_kernel_power (K : Kernel α α) [IsFiniteKernel K] (n : ℕ) : IsFiniteKernel (K^n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel α α); infer_instance + | succ n ih => + let := ih + have hp : K^(n+1) = (K^n) ∘ₖ K := pow_succ _ _ + rw [hp] + infer_instance + +noncomputable def liftReal (F : α → ℝ) : Space α → ℝ := Sum.elim F (fun _ => 0) + +theorem liftReal_measurable {F : α → ℝ} (hF : Measurable F) : Measurable (liftReal F) := hF.sumElim measurable_const + +theorem real_power_lift (K : Kernel α α) (n : ℕ) (x : α) + [IsFiniteMeasure (((complete K)^n) (.inl x))] [IsFiniteMeasure ((K^n) x)] + {F : α → ℝ} (hF : Measurable F) {A : ℝ} (hA : 0 ≤ A) (hbound : ∀ y,|F y| ≤ A) : + (∫ y,liftReal F y ∂((complete K)^n) (.inl x)) = ∫ y,F y ∂(K^n) x := by + have hL : ∀ y : Space α,|liftReal F y| ≤ A := by + intro y + cases y with + | inl a => exact hbound a + | inr u => simpa only [liftReal,Sum.elim_inr,abs_zero] using hA + have hIl : Integrable (liftReal F) (((complete K)^n) (.inl x)) := bounded_integrable (liftReal_measurable hF) hL + have hIr : Integrable F ((K^n) x) := bounded_integrable hF hbound + rw [integral_eq_lintegral_pos_part_sub_lintegral_neg_part hIl, + integral_eq_lintegral_pos_part_sub_lintegral_neg_part hIr] + have hp : (fun y : Space α => ENNReal.ofReal (liftReal F y)) = CemeteryPowers.liftReward (fun y => ENNReal.ofReal (F y)) := by + funext y + cases y <;> simp [liftReal,CemeteryPowers.liftReward] + have hn : (fun y : Space α => ENNReal.ofReal (-liftReal F y)) = CemeteryPowers.liftReward (fun y => ENNReal.ofReal (-F y)) := by + funext y + cases y <;> simp [liftReal,CemeteryPowers.liftReward] + rw [hp,hn,CemeteryPowers.power_lift K (F:=fun y => ENNReal.ofReal (F y)) (ENNReal.measurable_ofReal.comp hF), + CemeteryPowers.power_lift K (F:=fun y => ENNReal.ofReal (-F y)) (ENNReal.measurable_ofReal.comp hF.neg)] + rfl + +open FinitePathMeasures ContinuousKilledBins LowStateHorizon + +theorem continuous_signed_power (v ell S : ℝ) (n : ℕ) (z : CostState) + {F : CostState → ℝ} (hF : Measurable F) {A : ℝ} (hA : 0 ≤ A) (hbound : ∀ y,|F y| ≤ A) : + (∫ y,liftReal F y ∂((continuousChain v ell S)^n) (.inl z)) = + ∫ y,F y ∂((lowKernel costKernel v ell S)^n) z := by + let : IsFiniteKernel (lowKernel costKernel v ell S) := by unfold lowKernel; infer_instance + let := finite_kernel_power (lowKernel costKernel v ell S) n + let := finite_kernel_power (continuousChain v ell S) n + let : IsFiniteMeasure (((complete (lowKernel costKernel v ell S))^n) (.inl z)) := by + change IsFiniteMeasure (((continuousChain v ell S)^n) (.inl z)) + infer_instance + exact real_power_lift (lowKernel costKernel v ell S) n z hF hA hbound + +end NumberTheoryLean.SignedCompletedPowers + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SingletonSubsetMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SingletonSubsetMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..33b03d8e1498b62202ce337f0538fe7b054ee668 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SingletonSubsetMass.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.FiniteWeightedChoiceBox +import OAI.NumberTheory.Jacobsthal.Primes.PrimeChoiceCoordinateMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SingletonSubsetMass +open PrimeBinAlignmentMass + +attribute [local instance] Classical.propDecidable + +noncomputable def subsetWeight (s : Finset ℕ) : ℝ := ∏ p ∈ s,(p:ℝ)⁻¹ + +theorem subsetWeight_nonnegative (s : Finset ℕ) : 0 ≤ subsetWeight s := + Finset.prod_nonneg (fun p _ => inv_nonneg.mpr (Nat.cast_nonneg p)) + +theorem singleton_total_mass (P : Finset ℕ) : + (∑ s ∈ P.powersetCard 1,subsetWeight s)=mass P := by + rw [Finset.powersetCard_one,Finset.sum_map] + simp [subsetWeight,mass] + +theorem all_filter_powerset (P : Finset ℕ) (k : ℕ) (E : ℕ → Prop) : + (P.powersetCard k).filter (fun s => ∀ p ∈ s,E p)=(P.filter E).powersetCard k := by + ext s + simp only [Finset.mem_filter,Finset.mem_powersetCard] + constructor + · rintro ⟨⟨hsub,hcard⟩,he⟩ + refine ⟨?_,hcard⟩ + intro p hp + exact Finset.mem_filter.mpr ⟨hsub hp,he p hp⟩ + · rintro ⟨hsub,hcard⟩ + refine ⟨⟨?_,hcard⟩,?_⟩ + · intro p hp + exact (Finset.mem_filter.mp (hsub hp)).1 + · intro p hp + exact (Finset.mem_filter.mp (hsub hp)).2 + +theorem some_filter_singletons (P : Finset ℕ) (E : ℕ → Prop) : + (P.powersetCard 1).filter (fun s => ∃ p ∈ s,E p)=(P.filter E).powersetCard 1 := by + rw [← all_filter_powerset P 1 E] + apply Finset.filter_congr + intro s hs + obtain ⟨p,rfl⟩ := Finset.card_eq_one.mp (Finset.mem_powersetCard.mp hs).2 + simp + +theorem singleton_all_mass (P : Finset ℕ) (E : ℕ → Prop) : + (∑ s ∈ (P.powersetCard 1).filter (fun s => ∀ p ∈ s,E p),subsetWeight s)=mass (P.filter E) := by + rw [all_filter_powerset,singleton_total_mass] + +theorem singleton_some_mass (P A : Finset ℕ) (hA : A ⊆ P) : + (∑ s ∈ (P.powersetCard 1).filter (fun s => ∃ p ∈ s,p ∈ A),subsetWeight s)=mass A := by + calc + _ = ∑ s ∈ A.powersetCard 1,subsetWeight s := by + apply Finset.sum_congr + · ext s + simp only [Finset.mem_filter,Finset.mem_powersetCard] + constructor + · rintro ⟨⟨_hSP,hcard⟩,hex⟩ + obtain ⟨p,rfl⟩ := Finset.card_eq_one.mp hcard + simp only [Finset.mem_singleton,exists_eq_left] at hex + exact ⟨Finset.singleton_subset_iff.mpr hex,by simp⟩ + · rintro ⟨hSA,hcard⟩ + obtain ⟨p,rfl⟩ := Finset.card_eq_one.mp hcard + have hpA := hSA (by simp : p ∈ ({p} : Finset ℕ)) + exact ⟨⟨fun q hq => hA (hSA hq),by simp⟩,p,by simp,hpA⟩ + · intro s _hs + rfl + _ = _ := singleton_total_mass A + +end NumberTheoryLean.SingletonSubsetMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SmallModelSourceScales.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SmallModelSourceScales.lean new file mode 100644 index 0000000000000000000000000000000000000000..7139f2d73287c6d9df0761b704593e0d9dc79a62 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SmallModelSourceScales.lean @@ -0,0 +1,520 @@ +import Mathlib.NumberTheory.Chebyshev +import OAI.NumberTheory.Jacobsthal.Estimates.CorrectionFloorRemainder +import OAI.NumberTheory.Jacobsthal.Estimates.ReciprocalEnvelope +import OAI.NumberTheory.Jacobsthal.Estimates.SourcePairRemainder +import OAI.NumberTheory.Jacobsthal.Partitions.CellLengthLower +import OAI.NumberTheory.Jacobsthal.Partitions.ParentEdgeCoordinates +import OAI.NumberTheory.Jacobsthal.Sieve.ClosedEulerIndividualUpper + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseFrozen +open NumberTheoryLean ErdosInverseHits + +noncomputable def frozenCoordinates (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) + (a : ℕ → ℕ) : Finset ℕ := + ProgressionSmallSieve.progressionSurvivors N ⌊w⌋₊ (b+(q : ℤ)*v) (p*q) a + +theorem mem_frozenCoordinates (N : ℕ) (w : ℝ) (p q : ℕ) (b v : ℤ) + (a : ℕ → ℕ) (j : ℕ) : + j ∈ frozenCoordinates N w p q b v a ↔ j < N ∧ + ∀ t ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊, + ¬Int.ModEq (t : ℤ) (b+(q : ℤ)*(v+(p : ℤ)*j)) (a t : ℤ) := by + rw [frozenCoordinates,ProgressionSmallSieve.progressionSurvivors,SievePartition.mem_survivors] + simp only [Finset.mem_range,ProgressionSmallSieve.progressionHit,Nat.cast_mul] + have heq : b+(q : ℤ)*v+(p : ℤ)*q*j = b+(q : ℤ)*(v+(p : ℤ)*j) := by ring + rw [heq] + +theorem frozenCoordinates_eq_of_modEq (N : ℕ) (w : ℝ) (p q q0 M : ℕ) + (b b0 v v0 : ℤ) (a : ℕ → ℕ) + (hM : ∀ t ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊,t ∣ M) + (hq : Int.ModEq (M : ℤ) (q : ℤ) (q0 : ℤ)) + (hb : Int.ModEq (M : ℤ) b b0) (hv : Int.ModEq (M : ℤ) v v0) : + frozenCoordinates N w p q b v a = frozenCoordinates N w p q0 b0 v0 a := by + classical + ext j + rw [mem_frozenCoordinates,mem_frozenCoordinates] + apply and_congr_right + intro _ + apply forall₂_congr + intro t ht + have heval := hb.add (hq.mul (hv.add_right ((p : ℤ)*j))) + have hdiv : (t : ℤ) ∣ (M : ℤ) := by exact_mod_cast hM t ht + have he := heval.of_dvd hdiv + exact not_congr ⟨fun h => he.symm.trans h,fun h => he.trans h⟩ + +end ErdosInverseFrozen + +end + +section + +namespace ErdosInverseEuler +open NumberTheoryLean + +noncomputable def smallModulus (w : ℝ) : ℕ := IntervalBoundingSieve.cutoffProduct ⌊w⌋₊ + +theorem smallModulus_pos (w : ℝ) : 0 < smallModulus w := by + unfold smallModulus IntervalBoundingSieve.cutoffProduct + exact Finset.prod_pos (fun p hp => (LargePrimeDeletion.mem_cutoffPrimes.mp hp).1.pos) + +theorem log_smallModulus_eq_theta (w : ℝ) : Real.log (smallModulus w : ℝ) = Chebyshev.theta w := by + have hn : ∀ p ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊,(p : ℝ) ≠ 0 := by + intro p hp + exact_mod_cast (LargePrimeDeletion.mem_cutoffPrimes.mp hp).1.ne_zero + unfold smallModulus IntervalBoundingSieve.cutoffProduct + rw [Nat.cast_prod,Real.log_prod hn,cutoffPrimes_eq_filtered_Ioc] + rfl + +theorem log_smallModulus_le (w : ℝ) (hw : 0 ≤ w) : + Real.log (smallModulus w : ℝ) ≤ Real.log 4*w := by + rw [log_smallModulus_eq_theta] + exact Chebyshev.theta_le_log4_mul_x hw + +theorem smallModulus_le_exp (w : ℝ) (hw : 0 ≤ w) : + (smallModulus w : ℝ) ≤ Real.exp (Real.log 4*w) := by + have hp : (0 : ℝ) < smallModulus w := by exact_mod_cast smallModulus_pos w + calc + (smallModulus w : ℝ) = Real.exp (Real.log (smallModulus w : ℝ)) := (Real.exp_log hp).symm + _ ≤ _ := Real.exp_le_exp.mpr (log_smallModulus_le w hw) + +end ErdosInverseEuler + +end + +section + +namespace ErdosInverseFrozen +open NumberTheoryLean ErdosInverseHits ErdosInverseEuler ErdosInverseCounts + +theorem cutoffPrime_dvd_smallModulus (w : ℝ) (t : ℕ) + (ht : t ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) : t ∣ smallModulus w := by + unfold smallModulus IntervalBoundingSieve.cutoffProduct + exact Finset.dvd_prod_of_mem id ht + +theorem parentCoordinates_eq_pattern (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) + (p q : ℕ) [NeZero p] (hqp : q.Coprime p) (hq : Squarefree q) : + parentSurvivorCoordinates Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a p q hqp hq = + frozenCoordinates (hitLength Y (p*q) (sourceParentBase p q hqp hq a)) w p q + (primeHitRepresentative q hq a) (parentSlope p q hqp (a p) (primeHitRepresentative q hq a)) a := by + classical + ext j + rw [mem_frozenCoordinates] + simp only [parentSurvivorCoordinates,Finset.mem_filter,Finset.mem_range] + apply and_congr_right + intro _ + apply forall₂_congr + intro t _ + have hpoint : ((sourceParentBase p q hqp hq a+p*q*j : ℕ) : ℤ) = + (primeHitRepresentative q hq a : ℤ)+(q : ℤ)* + ((parentSlope p q hqp (a p) (primeHitRepresentative q hq a) : ℕ)+(p : ℤ)*j) := by + unfold sourceParentBase + push_cast + ring + rw [← hpoint] + exact not_congr Int.natCast_modEq_iff.symm + +theorem parentCoordinates_eq_frozen_center (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) + (p q q0 : ℕ) [NeZero p] (hqp : q.Coprime p) (hq : Squarefree q) (b0 v : ℤ) + (hqq : Int.ModEq (smallModulus w : ℤ) (q : ℤ) (q0 : ℤ)) + (hbb : Int.ModEq (smallModulus w : ℤ) (primeHitRepresentative q hq a : ℤ) b0) + (hsv : Int.ModEq (smallModulus w : ℤ) + (parentSlope p q hqp (a p) (primeHitRepresentative q hq a) : ℤ) v) : + parentSurvivorCoordinates Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a p q hqp hq = + frozenCoordinates (hitLength Y (p*q) (sourceParentBase p q hqp hq a)) w p q0 b0 v a := by + rw [parentCoordinates_eq_pattern] + exact frozenCoordinates_eq_of_modEq _ w p q q0 (smallModulus w) _ b0 _ v a + (cutoffPrime_dvd_smallModulus w) hqq hbb hsv + +theorem actual_parent_count_frozen (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) + (p q q0 : ℕ) [NeZero p] (hp : p.Prime) (hqp : q.Coprime p) (hq : Squarefree q) (b0 v : ℤ) + (hqq : Int.ModEq (smallModulus w : ℤ) (q : ℤ) (q0 : ℤ)) + (hbb : Int.ModEq (smallModulus w : ℤ) (primeHitRepresentative q hq a : ℤ) b0) + (hsv : Int.ModEq (smallModulus w : ℤ) + (parentSlope p q hqp (a p) (primeHitRepresentative q hq a) : ℤ) v) : + modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a (p*q) = + ((frozenCoordinates (hitLength Y (p*q) (sourceParentBase p q hqp hq a)) w p q0 b0 v a).card : ℤ) := by + rw [modulusCount_eq_parent_card Y _ a p q hp hqp hq, + parentCoordinates_eq_frozen_center Y w a p q q0 hqp hq b0 v hqq hbb hsv] + +theorem actual_child_count_frozen (Y : ℕ) (w : ℝ) (a : ℕ → ℕ) + (p q q0 u : ℕ) [NeZero p] (hp : p.Prime) (hu : u.Prime) (hqp : q.Coprime p) + (hq : Squarefree q) (hpu : p.Coprime u) (hqu : q.Coprime u) (b0 v : ℤ) + (hqq : Int.ModEq (smallModulus w : ℤ) (q : ℤ) (q0 : ℤ)) + (hbb : Int.ModEq (smallModulus w : ℤ) (primeHitRepresentative q hq a : ℤ) b0) + (hsv : Int.ModEq (smallModulus w : ℤ) + (parentSlope p q hqp (a p) (primeHitRepresentative q hq a) : ℤ) v) : + modulusCount Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a (p*q*u) = + (((frozenCoordinates (hitLength Y (p*q) (sourceParentBase p q hqp hq a)) w p q0 b0 v a).filter + (fun j : ℕ => (j : ZMod u) = parentEdgeResidue p q u hqp hq hpu hqu a)).card : ℤ) := by + classical + rw [modulusCount_eq_edge_card Y _ a p q u hp hu hqp hq hpu hqu, + parentCoordinates_eq_frozen_center Y w a p q q0 hqp hq b0 v hqq hbb hsv] + +end ErdosInverseFrozen + +end + +section + +namespace ErdosVarianceSmallModel +open NumberTheoryLean ErdosInverseEuler ErdosHyperbolaError +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def divisorPrimes (w : ℝ) (H : ℕ) : Finset ℕ := + (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊).filter (fun t => t ∣ H) +noncomputable def coprimePrimes (w : ℝ) (H : ℕ) : Finset ℕ := + (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊).filter (fun t => ¬t ∣ H) +noncomputable def divisorModulus (w : ℝ) (H : ℕ) : ℕ := ∏ t ∈ divisorPrimes w H,t +noncomputable def coprimeModulus (w : ℝ) (H : ℕ) : ℕ := ∏ t ∈ coprimePrimes w H,t + +theorem divisorModulus_pos (w : ℝ) (H : ℕ) : 0 < divisorModulus w H := + Finset.prod_pos (fun _t ht => (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1.pos) + +theorem coprimeModulus_pos (w : ℝ) (H : ℕ) : 0 < coprimeModulus w H := + Finset.prod_pos (fun _t ht => (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1.pos) + +theorem pattern_moduli_product (w : ℝ) (H : ℕ) : + divisorModulus w H*coprimeModulus w H = smallModulus w := by + unfold divisorModulus coprimeModulus divisorPrimes coprimePrimes + rw [Finset.prod_filter_mul_prod_filter_not] + rfl + +theorem divisorModulus_dvd_H (w : ℝ) (H : ℕ) : divisorModulus w H ∣ H := by + apply Finset.prod_primes_dvd + · intro t ht + exact (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1.prime + · intro t ht + exact (Finset.mem_filter.mp ht).2 + +theorem coprimeModulus_coprime_H (w : ℝ) (H : ℕ) : (coprimeModulus w H).Coprime H := by + apply Nat.coprime_prod_left_iff.mpr + intro t ht + have hh := Finset.mem_filter.mp ht + exact (LargePrimeDeletion.mem_cutoffPrimes.mp hh.1).1.coprime_iff_not_dvd.mpr hh.2 + +theorem pattern_moduli_coprime (w : ℝ) (H : ℕ) : (divisorModulus w H).Coprime (coprimeModulus w H) := + (coprimeModulus_coprime_H w H).symm.of_dvd_left (divisorModulus_dvd_H w H) + +theorem effective_pattern_coprime (w : ℝ) (H : ℕ) : + (H*divisorModulus w H).Coprime (coprimeModulus w H) := + (coprimeModulus_coprime_H w H).symm.mul_left (pattern_moduli_coprime w H) + +theorem pattern_totient (w : ℝ) (H : ℕ) : + (H*divisorModulus w H*coprimeModulus w H).totient = + H.totient*divisorModulus w H*(coprimeModulus w H).totient := by + rw [Nat.totient_mul (effective_pattern_coprime w H), + source_totient_product H (divisorModulus w H) (divisorModulus_dvd_H w H) (divisorModulus_pos w H)] + ring + +theorem pattern_modulus_size (w : ℝ) (H : ℕ) : + H*divisorModulus w H*coprimeModulus w H = H*smallModulus w := by + rw [Nat.mul_assoc,pattern_moduli_product] + +theorem prime_coprime_small_pattern (w : ℝ) (hw : 0 ≤ w) (H p : ℕ) + (hp : p.Prime) (hwp : w < (p : ℝ)) : p.Coprime (coprimeModulus w H) := by + apply Nat.coprime_prod_right_iff.mpr + intro t ht + have hh := LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1 + have htw := (Nat.le_floor_iff hw).mp hh.2 + apply (Nat.coprime_primes hp hh.1).mpr + intro he + subst t + linarith + +end ErdosVarianceSmallModel + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseEuler +open ErdosInverseBoxHeight + +theorem sourceW_tendsto_atTop : Tendsto sourceW atTop atTop := by + have hs := (isLittleO_log_rpow_rpow_atTop (2 : ℝ) (by norm_num : (0 : ℝ) < 1/2)).bound zero_lt_one + have hlow : (fun z : ℝ => (Real.log z)^((1 : ℝ)/2)) ≤ᶠ[atTop] sourceW := by + filter_upwards [Real.tendsto_log_atTop.eventually hs, + Real.tendsto_log_atTop.eventually_gt_atTop 1] with z hz hL + have hL0 : 0 < Real.log z := by linarith + have hLL : 0 < Real.log (Real.log z) := Real.log_pos hL + have hh : (Real.log (Real.log z))^2 ≤ (Real.log z)^((1 : ℝ)/2) := by + simpa only [Real.norm_eq_abs,Real.rpow_two,abs_of_nonneg (sq_nonneg (Real.log (Real.log z))), + abs_of_nonneg (Real.rpow_nonneg hL0.le ((1 : ℝ)/2)),one_mul] using hz + have hp : (Real.log z)^((1 : ℝ)/2)*(Real.log z)^((1 : ℝ)/2) = Real.log z := by + rw [← Real.rpow_add hL0] + norm_num + apply (le_div_iff₀ (sq_pos_of_pos hLL)).mpr + nlinarith [mul_le_mul_of_nonneg_left hh (Real.rpow_nonneg hL0.le ((1 : ℝ)/2))] + exact tendsto_atTop_mono' atTop hlow ((tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 1/2)).comp Real.tendsto_log_atTop) + +theorem sourceZ_le_rpow (eps : ℝ) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ sourceZ z ≤ z^eps := by + have hh := (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop (max 1 (1/eps)) + filter_upwards [hh,eventually_gt_atTop (1 : ℝ)] with z hLL hz + have hL0 : 0 < Real.log z := Real.log_pos hz + have hLL1 : 1 ≤ Real.log (Real.log z) := (le_max_left _ _).trans hLL + have hLL0 : 0 < Real.log (Real.log z) := by linarith + have hpay : 1 ≤ Real.log (Real.log z)*eps := (div_le_iff₀ heps).mp ((le_max_right _ _).trans hLL) + refine ⟨hz,?_⟩ + rw [sourceZ,Real.rpow_def_of_pos (by linarith : 0 < z)] + apply Real.exp_le_exp.mpr + apply (div_le_iff₀ hLL0).mpr + nlinarith [mul_le_mul_of_nonneg_left hpay hL0.le] + +theorem smallModulus_source_power (k : ℕ) (eps : ℝ) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, (smallModulus (sourceW z) : ℝ)^k ≤ (sourceZ z)^eps := by + have hh := (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop + (max 1 ((k : ℝ)*Real.log 4/eps)) + filter_upwards [hh,Real.tendsto_log_atTop.eventually_gt_atTop 1] with z hLL hL + have hL0 : 0 < Real.log z := by linarith + have hLL1 : 1 ≤ Real.log (Real.log z) := (le_max_left _ _).trans hLL + have hLL0 : 0 < Real.log (Real.log z) := by linarith + have hW0 : 0 ≤ sourceW z := div_nonneg hL0.le (sq_nonneg _) + have hpay : (k : ℝ)*Real.log 4 ≤ Real.log (Real.log z)*eps := + (div_le_iff₀ heps).mp ((le_max_right _ _).trans hLL) + have hscale : (k : ℝ)*(Real.log 4*sourceW z) ≤ (Real.log z/Real.log (Real.log z))*eps := by + calc + _ = ((k : ℝ)*Real.log 4*Real.log z)/(Real.log (Real.log z))^2 := by unfold sourceW;ring + _ ≤ (Real.log (Real.log z)*eps*Real.log z)/(Real.log (Real.log z))^2 := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hpay hL0.le) (sq_nonneg _) + _ = _ := by field_simp + calc + _ ≤ (Real.exp (Real.log 4*sourceW z))^k := pow_le_pow_left₀ (Nat.cast_nonneg _) (smallModulus_le_exp _ hW0) k + _ = Real.exp ((k : ℝ)*(Real.log 4*sourceW z)) := (Real.exp_nat_mul _ _).symm + _ ≤ Real.exp ((Real.log z/Real.log (Real.log z))*eps) := Real.exp_le_exp.mpr hscale + _ = (sourceZ z)^eps := Real.exp_mul _ _ + +end ErdosInverseEuler + +end + +section + +namespace ErdosVarianceSmallModel + +instance (w : ℝ) (H : ℕ) : NeZero (divisorModulus w H) := ⟨(divisorModulus_pos w H).ne'⟩ +instance (w : ℝ) (H : ℕ) : NeZero (coprimeModulus w H) := ⟨(coprimeModulus_pos w H).ne'⟩ + +abbrev Pattern (w : ℝ) (H : ℕ) := (ZMod (coprimeModulus w H))ˣ × ZMod (divisorModulus w H) +abbrev ModelPoint (w : ℝ) (H : ℕ) := ℤ × Pattern w H + +theorem pattern_card (w : ℝ) (H : ℕ) : + Fintype.card (Pattern w H) = divisorModulus w H*(coprimeModulus w H).totient := by + simp only [Pattern,Fintype.card_prod,ZMod.card_units_eq_totient,ZMod.card] + ring + +end ErdosVarianceSmallModel + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseEuler +open ErdosInverseBoxHeight + +theorem exp_loglog_sq_le_sourceZ (C eps : ℝ) (hC : 0 ≤ C) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, + Real.exp (C*(Real.log (Real.log z))^2) ≤ (sourceZ z)^eps := by + have hC1 : 0 < C+1 := by linarith + have hs := (isLittleO_log_rpow_rpow_atTop (3 : ℝ) zero_lt_one).bound + (div_pos heps hC1) + filter_upwards [Real.tendsto_log_atTop.eventually hs, + (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop 1, + Real.tendsto_log_atTop.eventually_gt_atTop 1] + with z hz hLL hL + have hLL0 : 0 < Real.log (Real.log z) := by change 1 ≤ Real.log (Real.log z) at hLL;linarith + have hL0 : 0 < Real.log z := by linarith + have hcube : (Real.log (Real.log z))^3 ≤ (eps/(C+1))*Real.log z := by + simpa only [Real.norm_eq_abs,Real.rpow_ofNat,Real.rpow_one, + abs_of_nonneg (pow_nonneg hLL0.le 3),abs_of_nonneg hL0.le] using hz + have hpay : C*(Real.log (Real.log z))^3 ≤ eps*Real.log z := by + have hm := (le_div_iff₀ hC1).mp (show (Real.log (Real.log z))^3 ≤ (eps*Real.log z)/(C+1) by + simpa only [div_mul_eq_mul_div] using hcube) + nlinarith [pow_nonneg hLL0.le 3] + rw [sourceZ,← Real.exp_mul] + apply Real.exp_le_exp.mpr + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ hLL0).mpr + nlinarith only [hpay] + +theorem log_pow_le_sourceZ (r : ℕ) (eps : ℝ) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, (Real.log z)^r ≤ (sourceZ z)^eps := by + filter_upwards [exp_loglog_sq_le_sourceZ r eps (Nat.cast_nonneg _) heps, + (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop 1, + Real.tendsto_log_atTop.eventually_gt_atTop 1] + with z hz hLL hL + have hLL1 : 1 ≤ Real.log (Real.log z) := hLL + have hLL0 : 0 < Real.log (Real.log z) := by linarith + have hL0 : 0 < Real.log z := by linarith + calc + (Real.log z)^r = (Real.exp (Real.log (Real.log z)))^r := by rw [Real.exp_log hL0] + _ = Real.exp ((r : ℝ)*Real.log (Real.log z)) := (Real.exp_nat_mul _ _).symm + _ ≤ Real.exp ((r : ℝ)*(Real.log (Real.log z))^2) := by + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonneg_left (by nlinarith) (Nat.cast_nonneg _) + _ ≤ _ := hz + +theorem sourceZ_tendsto_atTop : Tendsto sourceZ atTop atTop := by + have hlow : (fun z : ℝ => Real.log z) ≤ᶠ[atTop] sourceZ := by + filter_upwards [log_pow_le_sourceZ 1 1 zero_lt_one] with z hz + simpa only [pow_one,Real.rpow_one] using hz + exact tendsto_atTop_mono' atTop hlow Real.tendsto_log_atTop + +theorem smallModulus_mul_log_power (k r : ℕ) (eps : ℝ) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, + (smallModulus (sourceW z) : ℝ)^k*(Real.log z)^r ≤ (sourceZ z)^eps := by + filter_upwards [smallModulus_source_power k (eps/2) (by positivity), + log_pow_le_sourceZ r (eps/2) (by positivity), + Real.tendsto_log_atTop.eventually_ge_atTop 0] with z hk hr hL + calc + _ ≤ (sourceZ z)^(eps/2)*(sourceZ z)^(eps/2) := + mul_le_mul hk hr (pow_nonneg hL _) (Real.rpow_nonneg (Real.exp_pos _).le _) + _ = (sourceZ z)^(eps/2+eps/2) := (Real.rpow_add (Real.exp_pos _) _ _).symm + _ = _ := by congr 1;ring + +end ErdosInverseEuler + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseTail +open ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_common_length_regime (aStar xi : ℝ) (ha : 0 < aStar) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,2 ≤ sourceW z ∧ + ∀ (Y p q u : ℕ) (Qplus : ℝ),0 < p → 0 < q → 0 < u → + (q : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q : ℝ) → + 3*aStar/4 ≤ Real.log ((Y : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z) → + 3 ≤ xi*(commonParentLength Y p Qplus : ℝ) ∧ + (sourceW z)^(aStar/2) ≤ 2*xi*(commonParentLength Y p Qplus : ℝ)/(u : ℝ) := by + have ht3 := (tendsto_rpow_atTop (by linarith : 0 < 3*aStar/4)).comp sourceW_tendsto_atTop + have htq := (tendsto_rpow_atTop (by linarith : 0 < aStar/4)).comp sourceW_tendsto_atTop + filter_upwards [sourceW_tendsto_atTop.eventually_ge_atTop 2, + ht3.eventually_ge_atTop (max 4 (12/xi)),htq.eventually_ge_atTop (2/xi)] with z hw hv hquarter + refine ⟨hw,?_⟩ + intro Y p q u Qplus hp hq hu hqQ hQq hlen + change 2/xi ≤ (sourceW z)^(aStar/4) at hquarter + have hwpos : 0 < sourceW z := by linarith + have hv4 : 4 ≤ (sourceW z)^(3*aStar/4) := (le_max_left _ _).trans hv + have hvpay : 12/xi ≤ (sourceW z)^(3*aStar/4) := (le_max_right _ _).trans hv + have hgeo := common_length_from_log Y p q u hp hq hu Qplus xi (sourceW z) aStar + hqQ hQq hxi.le hxi1 (by linarith) ha hlen + rw [mul_div_assoc (2 : ℝ) (commonParentLength Y p Qplus : ℝ) (u : ℝ)] at hgeo + have hJlow : (sourceW z)^(3*aStar/4)/4 ≤ (commonParentLength Y p Qplus : ℝ)/(u : ℝ) := by + nlinarith + have hu1 : (1 : ℝ) ≤ u := by exact_mod_cast hu + have hJup : (commonParentLength Y p Qplus : ℝ)/(u : ℝ) ≤ commonParentLength Y p Qplus := + div_le_self (Nat.cast_nonneg _) hu1 + have hJpay := mul_le_mul_of_nonneg_left hJlow hxi.le + constructor + · have hlarge := (div_le_iff₀ hxi).mp hvpay + have hmono := mul_le_mul_of_nonneg_left hJup hxi.le + nlinarith + · have hquarterpay := (div_le_iff₀ hxi).mp hquarter + have hhalf : 0 ≤ (sourceW z)^(aStar/2) := Real.rpow_nonneg hwpos.le _ + have hfactor : (sourceW z)^(aStar/2)*(sourceW z)^(aStar/4) = (sourceW z)^(3*aStar/4) := by + rw [← Real.rpow_add hwpos] + congr 1 + ring + have hm := mul_le_mul_of_nonneg_left hquarterpay hhalf + have hf := congrArg (fun x : ℝ => x*xi) hfactor + have hpaid : (sourceW z)^(aStar/2) ≤ 2*xi*((commonParentLength Y p Qplus : ℝ)/(u : ℝ)) := by + nlinarith [hf] + simpa only [mul_div_assoc] using hpaid + +end ErdosInverseTail + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceSmallModel +open ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_Z_power_R (alpha beta : ℝ) (n : ℕ) (ha : 0 < alpha) (hb : 0 < beta) (hn : 0 < n) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R : ℝ,z^alpha ≤ R → (sourceZ z)^n ≤ R^beta := by + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + filter_upwards [sourceZ_le_rpow (alpha*beta/(n : ℝ)) (by positivity)] with z hz + refine ⟨hz.1,?_⟩ + intro R hR + have hz0 : 0 < z := by linarith [hz.1] + calc + _ ≤ (z^(alpha*beta/(n : ℝ)))^n := pow_le_pow_left₀ (Real.exp_pos _).le hz.2 n + _ = z^(alpha*beta) := by + rw [← Real.rpow_natCast,← Real.rpow_mul hz0.le] + congr 1 + field_simp + _ ≤ _ := by + have hh := Real.rpow_le_rpow (Real.rpow_nonneg hz0.le alpha) hR hb.le + simpa only [← Real.rpow_mul hz0.le] using hh + +theorem primeWidth_lower_Z (R xi H C0 Z : ℝ) (hR : 0 < R) (hxi : 0 < xi) (hxi1 : xi ≤ 1) + (hH : 0 < H) (hZ : 0 < Z) (hInv : 1/Z ≤ xi) (hRatio : totalScale R H C0/H ≤ Z^12) : + R/Z^13 ≤ primeWidth R xi H C0 := by + have hT := totalScale_pos R H C0 hH + have hTbound := (div_le_iff₀ hH).mp hRatio + calc + _ = (R/Z^12)*(1/Z) := by field_simp + _ ≤ (R/Z^12)*xi := mul_le_mul_of_nonneg_left hInv (by positivity) + _ = xi*R/Z^12 := by ring + _ ≤ xi*R*H/totalScale R H C0 := by + apply (div_le_div_iff₀ (pow_pos hZ 12) hT).mpr + have hh := mul_le_mul_of_nonneg_left hTbound (mul_pos hxi hR).le + nlinarith + _ ≤ _ := primeWidth_lower R xi H C0 hR hxi hxi1 hH + +theorem source_prime_width_lower (alpha xi : ℝ) (ha : 0 < alpha) (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R H C0 : ℝ,z^alpha ≤ R → 0 < H → + totalScale R H C0/H ≤ (sourceZ z)^12 → R^((19 : ℝ)/20) ≤ primeWidth R xi H C0 := by + filter_upwards [source_Z_power_R alpha (1/20) 13 ha (by norm_num) (by decide), + sourceZ_tendsto_atTop.eventually_ge_atTop (1/xi)] with z hz hZxi + refine ⟨hz.1,?_⟩ + intro R H C0 hRlo hH hRatio + have hz0 : 0 < z := by linarith [hz.1] + have hR : 0 < R := (Real.rpow_pos_of_pos hz0 alpha).trans_le hRlo + have hZ : 0 < sourceZ z := Real.exp_pos _ + have hInv : 1/sourceZ z ≤ xi := by + apply (div_le_iff₀ hZ).mpr + have hh := (div_le_iff₀ hxi).mp hZxi + nlinarith + have hZX := primeWidth_lower_Z R xi H C0 (sourceZ z) hR hxi hxi1 hH hZ hInv hRatio + apply le_trans _ hZX + apply (le_div_iff₀ (pow_pos hZ 13)).mpr + calc + _ ≤ R^((19 : ℝ)/20)*R^((1 : ℝ)/20) := + mul_le_mul_of_nonneg_left (hz.2 R hRlo) (Real.rpow_nonneg hR.le _) + _ = R := by rw [← Real.rpow_add hR];norm_num + +theorem source_small_modulus_R (alpha : ℝ) (ha : 0 < alpha) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R : ℝ,z^alpha ≤ R → (smallModulus (sourceW z) : ℝ) ≤ R^((1 : ℝ)/20) := by + filter_upwards [smallModulus_source_power 1 1 zero_lt_one, + source_Z_power_R alpha (1/20) 1 ha (by norm_num) Nat.zero_lt_one] with z hM hR + refine ⟨hR.1,?_⟩ + intro R hRlo + have hh : (smallModulus (sourceW z) : ℝ) ≤ sourceZ z := by simpa only [pow_one,Real.rpow_one] using hM + exact hh.trans (by simpa only [pow_one] using hR.2 R hRlo) + +end ErdosVarianceSmallModel + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SortedRealGaps.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SortedRealGaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cb8c2db46176ba1ca5fc3e5554b673ad3b16938 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SortedRealGaps.lean @@ -0,0 +1,82 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +open Set +namespace ErdosMarkedStrips + +noncomputable def gapLeft (E : Finset ℝ) (i : Fin (E.card-1)) : ℝ := + E.orderEmbOfFin rfl ⟨i.val,by have h := i.isLt; omega⟩ + +noncomputable def gapRight (E : Finset ℝ) (i : Fin (E.card-1)) : ℝ := + E.orderEmbOfFin rfl ⟨i.val+1,by have h := i.isLt; omega⟩ + +theorem gapLeft_mem (E : Finset ℝ) (i : Fin (E.card-1)) : gapLeft E i ∈ E := + E.orderEmbOfFin_mem rfl _ + +theorem gapRight_mem (E : Finset ℝ) (i : Fin (E.card-1)) : gapRight E i ∈ E := + E.orderEmbOfFin_mem rfl _ + +theorem gap_lt (E : Finset ℝ) (i : Fin (E.card-1)) : gapLeft E i < gapRight E i := by + apply (E.orderEmbOfFin rfl).strictMono + change i.val < i.val+1 + omega + +theorem no_mark_in_gap (E : Finset ℝ) (i : Fin (E.card-1)) {x : ℝ} + (hx : x ∈ Ioo (gapLeft E i) (gapRight E i)) : x ∉ E := by + intro hE + obtain ⟨j,hj⟩ := (E.range_orderEmbOfFin rfl).symm.subset hE + have hl : gapLeft E i < E.orderEmbOfFin rfl j := by simpa only [hj] using hx.1 + have hh : E.orderEmbOfFin rfl j < gapRight E i := by simpa only [hj] using hx.2 + have hlo := (E.orderEmbOfFin rfl).lt_iff_lt.mp hl + have hhi := (E.orderEmbOfFin rfl).lt_iff_lt.mp hh + change i.val < j.val at hlo + change j.val < i.val+1 at hhi + omega + +theorem exists_gap_of_not_mem (E : Finset ℝ) {S x : ℝ} (h0 : 0 ∈ E) (hS : S ∈ E) + (hx : x ∈ Icc 0 S) (hxE : x ∉ E) : + ∃ i : Fin (E.card-1), x ∈ Ioo (gapLeft E i) (gapRight E i) := by + classical + let e := E.orderEmbOfFin rfl + obtain ⟨j0,hj0⟩ := (E.range_orderEmbOfFin rfl).symm.subset h0 + obtain ⟨jS,hjS⟩ := (E.range_orderEmbOfFin rfl).symm.subset hS + have hx0 : 0 < x := lt_of_le_of_ne hx.1 (fun he => hxE (he ▸ h0)) + let A := Finset.univ.filter (fun j : Fin E.card => e j < x) + have hA : A.Nonempty := ⟨j0,Finset.mem_filter.mpr + ⟨Finset.mem_univ _,by simpa only [e,hj0] using hx0⟩⟩ + let j := A.max' hA + have hjA : j ∈ A := A.max'_mem hA + have hjx : e j < x := (Finset.mem_filter.mp hjA).2 + have hjSlt : j < jS := e.lt_iff_lt.mp (hjx.trans_le (by simpa only [e,hjS] using hx.2)) + have hnext : j.val+1 < E.card := by have hj := jS.isLt; change j.val < jS.val at hjSlt; omega + let k : Fin E.card := ⟨j.val+1,hnext⟩ + have hnot : ¬e k < x := by + intro hkx + have hkA : k ∈ A := Finset.mem_filter.mpr ⟨Finset.mem_univ _,hkx⟩ + have hle : k ≤ j := A.le_max' k hkA + change j.val+1 ≤ j.val at hle + omega + have hxne : x ≠ e k := by + intro he + apply hxE + rw [he] + exact E.orderEmbOfFin_mem rfl k + let i : Fin (E.card-1) := ⟨j.val,by omega⟩ + refine ⟨i,?_,?_⟩ + · exact hjx + · exact lt_of_le_of_ne (le_of_not_gt hnot) hxne + +theorem number_of_gaps_le (E : Finset ℝ) : Fintype.card (Fin (E.card-1)) ≤ E.card := by simp + +end ErdosMarkedStrips + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceCandidateFreezing.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceCandidateFreezing.lean new file mode 100644 index 0000000000000000000000000000000000000000..48f4a883e1ea0ec948e76c488726818798e22d18 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceCandidateFreezing.lean @@ -0,0 +1,186 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualTagFreezing + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.RepresentativeTraceInvariance +open FinitePathGeometry PrimeHistories RepresentativeAdmission SourceStopPredicate + +theorem terminal_side_length (w : ℝ) (z z' : Node) (ps qs : List ℕ) + (hz : z.side = z'.side) (hlen : ps.length = qs.length) : + (terminal w z ps).side = (terminal w z' qs).side := by + induction ps generalizing qs z z' with + | nil => + have hq : qs = [] := List.length_eq_zero_iff.mp hlen.symm + subst qs + exact hz + | cons p ps ih => + cases qs with + | nil => simp at hlen + | cons q qs => + apply ih (step w z p) (step w z' q) qs + · change z.side.flip = z'.side.flip + rw [hz] + · simpa using hlen + +theorem representative_last_eq (rep : ℕ → ℝ) (ps qs : List ℕ) + (hm : ps.map rep = qs.map rep) : rep (ps.getLastD 0) = rep (qs.getLastD 0) := by + induction ps generalizing qs with + | nil => + have hq : qs = [] := List.map_eq_nil_iff.mp hm.symm + subst qs + rfl + | cons p ps ih => + cases qs with + | nil => simp at hm + | cons q qs => + have hh := List.cons.inj hm + cases ps with + | nil => + have hq : qs = [] := List.map_eq_nil_iff.mp hh.2.symm + subst qs + exact hh.1 + | cons r rs => + cases qs with + | nil => simp at hh + | cons s ss => + simpa using ih (s::ss) hh.2 + +theorem representativeWindow_map_iff (rep : ℕ → ℝ) (z : Node) (b₀ b₁ : ℝ) + (ps qs : List ℕ) (hm : ps.map rep = qs.map rep) : + representativeWindow rep z b₀ b₁ ps ↔ representativeWindow rep z b₀ b₁ qs := by + have he := representative_last_eq rep ps qs hm + simp only [representativeWindow,representativeGap,he,hm] + +theorem representativeSafe_map_iff (w : ℝ) (rep : ℕ → ℝ) (z : Node) (Delta : ℝ) + (ps qs : List ℕ) (hm : ps.map rep = qs.map rep) : + representativeSafe w rep z Delta ps ↔ representativeSafe w rep z Delta qs := by + have forward (ps qs : List ℕ) (hm : ps.map rep = qs.map rep) + (hs : representativeSafe w rep z Delta ps) : representativeSafe w rep z Delta qs := by + intro pre hpre hne hside + obtain ⟨tail,htail⟩ := (List.mem_inits pre qs).mp hpre + have hlen : ps.length = qs.length := by simpa using congrArg List.length hm + have hk : pre.length ≤ ps.length := by rw [← htail,List.length_append] at hlen; omega + have hm' : (ps.take pre.length).map rep = pre.map rep := by + rw [List.map_take,hm,← htail,List.map_append,List.take_append] + simp + have hprefix : ps.take pre.length ∈ ps.inits := + (List.mem_inits _ _).mpr ⟨ps.drop pre.length,List.take_append_drop _ _⟩ + have hlen' : (ps.take pre.length).length = pre.length := by + rw [List.length_take,Nat.min_eq_left hk] + have hne' : ps.take pre.length ≠ [] := by + intro he + have : pre.length = 0 := by rw [he] at hlen'; simpa using hlen'.symm + exact hne (List.length_eq_zero_iff.mp this) + have hside' : (terminal w z (ps.take pre.length)).side = .even := + (terminal_side_length w z z _ _ rfl hlen').trans hside + have hh := hs (ps.take pre.length) hprefix hne' hside' + have he := representative_last_eq rep _ _ hm' + simpa only [representativeGap,hm',he] using hh + exact ⟨forward ps qs hm,forward qs ps hm.symm⟩ + +theorem all_prefix_representative_tests (w : ℝ) (rep : ℕ → ℝ) (z : Node) + (Delta b₀ b₁ : ℝ) (ps qs : List ℕ) (hm : ps.map rep = qs.map rep) (k : ℕ) : + (representativeSafe w rep z Delta (ps.take k) ↔ representativeSafe w rep z Delta (qs.take k)) ∧ + (representativeWindow rep z b₀ b₁ (ps.take k) ↔ representativeWindow rep z b₀ b₁ (qs.take k)) := by + have ht : (ps.take k).map rep = (qs.take k).map rep := by rw [List.map_take,List.map_take,hm] + exact ⟨representativeSafe_map_iff w rep z Delta _ _ ht, + representativeWindow_map_iff rep z b₀ b₁ _ _ ht⟩ +end NumberTheoryLean.RepresentativeTraceInvariance + +end + +section + +namespace NumberTheoryLean.SourceCandidateFreezing +open FinitePathGeometry PrimeHistories RepresentativeAdmission SourceStopPredicate +open ActualSourceTags ActualTagFreezing FiniteFirstTag RepresentativeTraceInvariance +open ErdosInversePrimeBin ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem forall_take_replacement_iff (A : ℕ → Prop) (pre tail : List ℕ) (p p' : ℕ) + (hp : A p) (hp' : A p') (k : ℕ) : + (∀ r ∈ (pre++p::tail).take k,A r) ↔ (∀ r ∈ (pre++p'::tail).take k,A r) := by + have hm : ((pre++p::tail).take k).map A = ((pre++p'::tail).take k).map A := by + rw [List.map_take,List.map_take] + have he : A p = A p' := propext (iff_of_true hp hp') + simp only [List.map_append,List.map_cons,he] + have forward (ps qs : List ℕ) (hm : ps.map A = qs.map A) + (hh : ∀ r ∈ ps,A r) : ∀ r ∈ qs,A r := by + intro r hr + have hm' : A r ∈ ps.map A := by rw [hm]; exact List.mem_map.mpr ⟨r,hr,rfl⟩ + obtain ⟨s,hs,he⟩ := List.mem_map.mp hm' + rw [← he] + exact hh s hs + exact ⟨forward _ _ hm,forward _ _ hm.symm⟩ + +theorem prefix_tag_eq {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) (ps : List ℕ) (k : ℕ) + {t u : Tag n} (ht : firstTag F ps = some t) (hu : firstTag F (ps.take k) = some u) : u=t := by + have hh := firstTagFrom_append F 0 (ps.take k) (ps.drop k) hu + rw [List.take_append_drop] at hh + exact Option.some.inj (hh.symm.trans ht) + +theorem all_prefix_candidate_replacement {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) + (pre tail : List ℕ) (p p' : ℕ) {t : Tag n} + (ht : sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) (pre++p::tail) = some t) + (hc : tagCandidate (Y:ℝ) w Cs eta lower width label (sourceClass a) p = some (t.bin,t.rational)) + (hlabel : label p' = label p) + (hp' : p' ∈ primeBin (lower (label p')) (width (label p'))) + (ha' : aligns (sourceClass a) t.rational p') (k : ℕ) : + stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z ((pre++p::tail).take k) ↔ + stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z ((pre++p'::tail).take k) := by + have hwit := candidate_witness (Y:ℝ) w Cs eta lower width label (sourceClass a) p hc + have hp := hwit.2.1 + have ha := hwit.2.2.2.2 + have htags := all_prefix_tags_replacement (Y:ℝ) w Cs eta lower width label (sourceClass a) + pre tail p p' hc hlabel hp' ha' k + have hfull := sourceTag_replacement (Y:ℝ) w Cs eta lower width label (sourceClass a) + pre tail p p' hc hlabel hp' ha' + have ht' : sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) (pre++p'::tail) = some t := + hfull.symm.trans ht + have hlabels : ((pre++p::tail).take k).map label = ((pre++p'::tail).take k).map label := by + rw [List.map_take,List.map_take,replacement_labels label pre tail p p' hlabel] + have hrep := all_prefix_representative_tests w (representative w lower width label) z + (2*Clen*xi) b₀ b₁ _ _ (replacement_representatives w lower width label pre tail p p' hlabel) k + have hboxed := forall_take_replacement_iff + (fun r => r ∈ primeBin (lower (label r)) (width (label r))) pre tail p p' hp hp' k + have halign := forall_take_replacement_iff (aligns (sourceClass a) t.rational) pre tail p p' ha ha' k + have hlen : ((pre++p::tail).take k).length = ((pre++p'::tail).take k).length := by + simp only [List.length_take,List.length_append,List.length_cons] + have hne : ((pre++p::tail).take k ≠ []) ↔ ((pre++p'::tail).take k ≠ []) := by + rw [← List.length_pos_iff,← List.length_pos_iff,hlen] + have forward (ps qs : List ℕ) + (hps : firstTag (tagCandidate (Y:ℝ) w Cs eta lower width label (sourceClass a)) + ((pre++p::tail).take k) = sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) ps) + (htag : sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) ps = + sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) qs) + (hne : ps ≠ [] → qs ≠ []) (hlen : ps.length = qs.length) + (hb : boxed lower width label ps → boxed lower width label qs) + (hs : representativeSafe w (representative w lower width label) z (2*Clen*xi) ps → + representativeSafe w (representative w lower width label) z (2*Clen*xi) qs) + (hw : representativeWindow (representative w lower width label) z b₀ b₁ ps → + representativeWindow (representative w lower width label) z b₀ b₁ qs) + (hl : ps.map label = qs.map label) + (ha : (∀ r ∈ ps,aligns (sourceClass a) t.rational r) → ∀ r ∈ qs,aligns (sourceClass a) t.rational r) + (H : stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z ps) : + stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z qs := by + obtain ⟨hn,hlength,hbox,hsafe,hwindow,u,hu,hcount,hal⟩ := H + have hu' := hps.trans hu + have hut : u=t := prefix_tag_eq _ (pre++p::tail) k ht hu' + subst u + exact ⟨hne hn,by simpa only [← hlen] using hlength,hb hbox,hs hsafe,hw hwindow, + t,htag.symm.trans hu,by simpa only [← hl] using hcount,ha hal⟩ + exact ⟨forward _ _ rfl htags hne.mp hlen hboxed.mp hrep.1.mp hrep.2.mp hlabels halign.mp, + forward _ _ htags htags.symm hne.mpr hlen.symm hboxed.mpr hrep.1.mpr hrep.2.mpr hlabels.symm halign.mpr⟩ +end NumberTheoryLean.SourceCandidateFreezing + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceCenteredGap.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceCenteredGap.lean new file mode 100644 index 0000000000000000000000000000000000000000..d9ec217e7509e6c57955911d5d934d6d704cbe25 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceCenteredGap.lean @@ -0,0 +1,135 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.PaperContinuousCorrection + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosCorrectionLimit +open ErdosContinuousAnomaly ErdosBoundaryIntegral Erdos970Dependency.InvariantCostBound +open NumberTheoryLean.PrimeHistories NumberTheoryLean.DerivativeWeights +open NumberTheoryLean.JacobsthalSourceScale + +noncomputable def sourceRootGap (a z : ℝ) : ℝ := + Real.log (ErdosInverseBoxHeight.sourceY z : ℝ)/Real.log (ErdosInverseBoxHeight.sourceW z)-a+2 + +noncomputable def sourceRootNode (a z : ℝ) : Node where + side := .even + gap := sourceRootGap a z + ratio := sourceRootGap a z/ErdosInverseBoxHeight.sourceB z + cutoff := ErdosInverseBoxHeight.sourceB z + closed := true + +theorem sourceRoot_eq_paper (a : ℝ) {z : ℝ} (hz : 1 < z) (hW : 1 < sourceW (Real.log z)) : + sourceRootNode a z=paperStart a floorRemainder true (Real.log z) := by + have hg := paperGap_floor_eq a (L := Real.log z) hW + rw [Real.exp_log (by linarith : 0 < z)] at hg + change paperGap a floorRemainder (Real.log z)=sourceRootGap a z at hg + unfold sourceRootNode paperStart + rw [hg] + rfl + +theorem floored_source_prefactor_tendsto (a : ℝ) : + Tendsto (fun z => (ErdosInverseBoxHeight.sourceB z)^2* + phiEven (sourceRootNode a z).ratio/(sourceRootNode a z).gap^2) atTop + (𝓝 (Real.exp Real.eulerMascheroniConstant)) := by + have ht := (paper_prefactor_tendsto a floorRemainder_tendsto).comp Real.tendsto_log_atTop + apply ht.congr' + filter_upwards [Real.tendsto_log_atTop.eventually source_scale_eventually,eventually_gt_atTop (1:ℝ)] with z hs hz + rw [sourceRoot_eq_paper a hz hs.1] + rfl + +theorem floored_source_correction_tendsto (a : ℝ) : + Tendsto (fun z => (ErdosInverseBoxHeight.sourceB z)^2* + continuousBoundaryCorrection (ErdosInverseBoxHeight.sourceW z) 2 (sourceRootNode a z)) atTop + (𝓝 (Real.exp Real.eulerMascheroniConstant*(2*signedCoefficientI/costMass))) := by + have ht := paper_z_continuous_correction_tendsto a true floorRemainder_tendsto + apply ht.congr' + filter_upwards [Real.tendsto_log_atTop.eventually source_scale_eventually,eventually_gt_atTop (1:ℝ)] with z hs hz + rw [sourceRoot_eq_paper a hz hs.1] + rfl + +end ErdosCorrectionLimit + +end + +section + +open _root_.Set _root_.Filter +open scoped Topology +namespace ErdosSourceReferenceMargin +open ErdosCorrectionLimit +open NumberTheoryLean.JacobsthalSourceScale NumberTheoryLean.PrimeBinMembership + +theorem log_sourceW_div_log_tendsto : + Tendsto (fun L : ℝ => Real.log (sourceW L)/Real.log L) atTop (𝓝 1) := by + have h0 : Tendsto (fun L : ℝ => Real.log (Real.log L)/Real.log L) atTop (𝓝 0) := by + simpa only [Function.comp_def,id_eq] using! Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp Real.tendsto_log_atTop + have hh : Tendsto (fun L : ℝ => 1-2*(Real.log (Real.log L)/Real.log L)) atTop (𝓝 1) := by + simpa only [mul_zero,sub_zero] using tendsto_const_nhds.sub (h0.const_mul 2) + apply hh.congr' + filter_upwards [eventually_gt_atTop (1:ℝ)] with L hL + have hL0 : L ≠ 0 := by linarith + have hlog : Real.log L ≠ 0 := (Real.log_pos hL).ne' + rw [sourceW,Real.log_div hL0 (pow_ne_zero 2 hlog),Real.log_pow] + norm_num only [Nat.cast_ofNat] + field_simp + +theorem log_div_log_sourceW_tendsto : + Tendsto (fun L : ℝ => Real.log L/Real.log (sourceW L)) atTop (𝓝 1) := by + have hh := log_sourceW_div_log_tendsto.inv₀ (by norm_num : (1:ℝ)≠0) + simpa only [inv_one,inv_div] using! hh + +theorem centered_paper_gap_tendsto (a : ℝ) : + Tendsto (fun L => paperGap a floorRemainder L-2*sourceB L) atTop (𝓝 (-a)) := by + have hc : Tendsto (fun _ : ℝ => -a+2) atTop (𝓝 (-a+2)) := tendsto_const_nhds + have hh := (hc.sub (log_div_log_sourceW_tendsto.const_mul 2)).add floorRemainder_tendsto + convert! hh using 1 + · funext L + unfold paperGap + ring + · ring_nf + +theorem rootW_tendsto : Tendsto ErdosInverseBoxHeight.sourceW atTop atTop := by + exact sourceW_tendsto.comp Real.tendsto_log_atTop + +theorem rootB_tendsto : Tendsto ErdosInverseBoxHeight.sourceB atTop atTop := by + exact sourceB_tendsto.comp Real.tendsto_log_atTop + +theorem actual_root_eventually (a : ℝ) : ∀ᶠ z : ℝ in atTop, + 0 < ErdosInverseBoxHeight.sourceB z ∧ 1 < ErdosInverseBoxHeight.sourceW z ∧ + Real.log (ErdosInverseBoxHeight.sourceB z) ≤ 2*Real.log (ErdosInverseBoxHeight.sourceW z) ∧ + 199/100 ≤ (sourceRootNode a z).ratio ∧ (sourceRootNode a z).ratio ≤ 23/10 ∧ + 0 < (sourceRootNode a z).gap ∧ Consistent (sourceRootNode a z) := by + filter_upwards [Real.tendsto_log_atTop.eventually (paper_start_eventually a true floorRemainder_tendsto), + Real.tendsto_log_atTop.eventually source_scale_eventually,eventually_gt_atTop (1:ℝ)] with z hp hs hz + simp only [sourceRoot_eq_paper a hz hs.1] + exact hp + +theorem actual_root_ratio_tendsto (a : ℝ) : + Tendsto (fun z => (sourceRootNode a z).ratio) atTop (𝓝 2) := by + have hh := (paper_ratio_tendsto a floorRemainder_tendsto).comp Real.tendsto_log_atTop + apply hh.congr' + filter_upwards [Real.tendsto_log_atTop.eventually source_scale_eventually,eventually_gt_atTop (1:ℝ)] with z hs hz + rw [sourceRoot_eq_paper a hz hs.1] + rfl + +theorem actual_root_centered_gap_tendsto (a : ℝ) : + Tendsto (fun z => (sourceRootNode a z).gap-2*ErdosInverseBoxHeight.sourceB z) atTop (𝓝 (-a)) := by + have hh := (centered_paper_gap_tendsto a).comp Real.tendsto_log_atTop + apply hh.congr' + filter_upwards [Real.tendsto_log_atTop.eventually source_scale_eventually,eventually_gt_atTop (1:ℝ)] with z hs hz + rw [sourceRoot_eq_paper a hz hs.1] + rfl + +end ErdosSourceReferenceMargin + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceEdgeClasses.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceEdgeClasses.lean new file mode 100644 index 0000000000000000000000000000000000000000..b2fa2259224144a275df4f71c981eff305f85af9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceEdgeClasses.lean @@ -0,0 +1,122 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SlopeCellPartition + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq + +theorem product_density {ι : Type*} [Fintype ι] (u : ι → ℕ) (E : ∀ i,Finset (ZMod (u i))) : + ((∏ i,(E i).card : ℕ) : ℝ)/(∏ i,u i : ℕ) = ∏ i,((E i).card : ℝ)/(u i : ℝ) := by + push_cast + rw [Finset.prod_div_distrib] + +theorem slopeCell_normalized_upper {ι : Type*} [Fintype ι] (p M0 : ℕ) (u : ι → ℕ) (v : ZMod M0) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) (E : ∀ i,Finset (ZMod (u i))) + (hM : 0 < M0) (hU : ∀ i,0 < u i) (h0 : ∀ i,Nat.Coprime M0 (u i)) + (hu : Pairwise (fun i j => Nat.Coprime (u i) (u j))) : + ((slopeCell p M0 u v c b E).card : ℝ) ≤ + (p : ℝ)/(M0 : ℝ)*(∏ i,((E i).card : ℝ)/(u i : ℝ))+((∏ i,u i : ℕ) : ℝ) := by + have hcR : ((∏ i,(E i).card : ℕ) : ℝ) ≤ ((∏ i,u i : ℕ) : ℝ) := + Nat.cast_le.mpr (product_card_le_moduli u E hU) + calc + _ ≤ (p : ℝ)*((∏ i,(E i).card : ℕ) : ℝ)/(M0*(∏ i,u i) : ℕ)+((∏ i,(E i).card : ℕ) : ℝ) := + slopeCell_card_upper p M0 u v c b E hM hU h0 hu + _ ≤ (p : ℝ)*((∏ i,(E i).card : ℕ) : ℝ)/(M0*(∏ i,u i) : ℕ)+((∏ i,u i : ℕ) : ℝ) := + add_le_add le_rfl hcR + _ = (p : ℝ)/(M0 : ℝ)*(((∏ i,(E i).card : ℕ) : ℝ)/(∏ i,u i : ℕ))+((∏ i,u i : ℕ) : ℝ) := by + push_cast + ring + _ = _ := by rw [product_density] + +theorem sampledSlopes_card_upper {ι : Type*} [Fintype ι] (p M0 : ℕ) [NeZero M0] (u : ι → ℕ) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) + (hU : ∀ i,0 < u i) (h0 : ∀ i,Nat.Coprime M0 (u i)) + (hu : Pairwise (fun i j => Nat.Coprime (u i) (u j))) : + ((sampledSlopes p M0 u c b E).card : ℝ) ≤ + (p : ℝ)/(M0 : ℝ)*(∑ v : ZMod M0,∏ i,((E v i).card : ℝ)/(u i : ℝ))+ + (M0 : ℝ)*((∏ i,u i : ℕ) : ℝ) := by + have hM : 0 < M0 := Nat.pos_of_ne_zero (NeZero.ne M0) + calc + _ = ∑ v : ZMod M0,((slopeCell p M0 u v c b (E v)).card : ℝ) := by + exact_mod_cast sampledSlopes_card p M0 u c b E + _ ≤ ∑ v : ZMod M0,((p : ℝ)/(M0 : ℝ)*(∏ i,((E v i).card : ℝ)/(u i : ℝ))+((∏ i,u i : ℕ) : ℝ)) := + Finset.sum_le_sum (fun v _ => slopeCell_normalized_upper p M0 u v c b (E v) hM hU h0 hu) + _ = _ := by + rw [Finset.sum_add_distrib,← Finset.mul_sum] + simp only [Finset.sum_const,nsmul_eq_mul,Finset.card_univ,ZMod.card] + +end ErdosInverseCRT + +end + +section + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def sourceEdgeResidue (p q u : ℕ) (hp : Nat.Coprime p u) (hq : Nat.Coprime q u) + (a b s : ℤ) : ZMod u := + ((a : ZMod u)-(b : ZMod u)-(q : ZMod u)*(s : ZMod u))* + (↑((ZMod.unitOfCoprime p hp*ZMod.unitOfCoprime q hq)⁻¹) : ZMod u) + +noncomputable def sourceCoefficient (p u : ℕ) (hp : Nat.Coprime p u) : (ZMod u)ˣ := + -(ZMod.unitOfCoprime p hp)⁻¹ + +noncomputable def sourceShift (p q u : ℕ) (hp : Nat.Coprime p u) (hq : Nat.Coprime q u) + (a b : ℤ) : ZMod u := + ((a : ZMod u)-(b : ZMod u))*(↑((ZMod.unitOfCoprime p hp*ZMod.unitOfCoprime q hq)⁻¹) : ZMod u) + +theorem sourceEdgeResidue_eq_affine (p q u : ℕ) (hp : Nat.Coprime p u) (hq : Nat.Coprime q u) + (a b s : ℤ) : sourceEdgeResidue p q u hp hq a b s = + (sourceCoefficient p u hp : ZMod u)*(s : ZMod u)+sourceShift p q u hp hq a b := by + have hh := source_edge_class_affine (ZMod.unitOfCoprime p hp) (ZMod.unitOfCoprime q hq) + (a : ZMod u) (b : ZMod u) (s : ZMod u) + simpa only [sourceEdgeResidue,sourceCoefficient,sourceShift,ZMod.coe_unitOfCoprime] using hh + +theorem sourceEdgeResidue_of_same_cell (p q q0 u : ℕ) (hp : Nat.Coprime p u) + (hq : Nat.Coprime q u) (hq0 : Nat.Coprime q0 u) (a b b0 s : ℤ) + (hqq : (q : ZMod u) = (q0 : ZMod u)) (hbb : (b : ZMod u) = (b0 : ZMod u)) : + sourceEdgeResidue p q u hp hq a b s = sourceEdgeResidue p q0 u hp hq0 a b0 s := by + have he : ZMod.unitOfCoprime q hq = ZMod.unitOfCoprime q0 hq0 := by + apply Units.ext + simpa only [ZMod.coe_unitOfCoprime] using hqq + unfold sourceEdgeResidue + rw [hqq,hbb,he] + +theorem source_progression_edge_hit (p q u : ℕ) (hp : Nat.Coprime p u) (hq : Nat.Coprime q u) + (a b s j : ℤ) : + (((b+(q : ℤ)*(s+(p : ℤ)*j) : ℤ) : ZMod u) = (a : ZMod u)) ↔ + (j : ZMod u) = sourceEdgeResidue p q u hp hq a b s := by + unfold sourceEdgeResidue + rw [Units.eq_mul_inv_iff_mul_eq] + simp only [Int.cast_add,Int.cast_mul,Int.cast_natCast,Units.val_mul,ZMod.coe_unitOfCoprime] + constructor <;> intro h <;> linear_combination h + +noncomputable def sourceTestedSlopes {ι : Type*} [Fintype ι] (p q0 M0 : ℕ) (u : ι → ℕ) + (hp : ∀ i,Nat.Coprime p (u i)) (hq : ∀ i,Nat.Coprime q0 (u i)) (a : ℕ → ℤ) (b0 : ℤ) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) : Finset ℤ := + (Finset.Ico (0 : ℤ) (p : ℤ)).filter + (fun s => ∀ i,sourceEdgeResidue p q0 (u i) (hp i) (hq i) (a (u i)) b0 s ∈ E (s : ZMod M0) i) + +theorem sourceTestedSlopes_eq_sampledSlopes {ι : Type*} [Fintype ι] (p q0 M0 : ℕ) (u : ι → ℕ) + (hp : ∀ i,Nat.Coprime p (u i)) (hq : ∀ i,Nat.Coprime q0 (u i)) (a : ℕ → ℤ) (b0 : ℤ) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) : + sourceTestedSlopes p q0 M0 u hp hq a b0 E = sampledSlopes p M0 u + (fun i => sourceCoefficient p (u i) (hp i)) + (fun i => sourceShift p q0 (u i) (hp i) (hq i) (a (u i)) b0) E := by + ext s + simp only [sourceTestedSlopes,sampledSlopes,Finset.mem_filter,sourceEdgeResidue_eq_affine] + +end ErdosInverseCRT + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceExtensionScale.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceExtensionScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6fee958022aafc4d5282ecca03e11ce7d7ba211 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceExtensionScale.lean @@ -0,0 +1,445 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.EffectiveCoordinateUnits +import OAI.NumberTheory.Jacobsthal.Primes.PrimeEventCounting + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSampleCost +open ErdosInverseBoxHeight ErdosInverseEuler + +theorem sourceW_log_bounds : ∀ᶠ z : ℝ in atTop, + 1 < z ∧ 0 < Real.log z ∧ (Real.log z)^((1 : ℝ)/2) ≤ sourceW z ∧ sourceW z ≤ Real.log z := by + have hs := (isLittleO_log_rpow_rpow_atTop (2 : ℝ) (by norm_num : (0 : ℝ) < 1/2)).bound zero_lt_one + filter_upwards [Real.tendsto_log_atTop.eventually hs, + (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop 1, + eventually_gt_atTop (1 : ℝ)] with z hh hLL hz + have hL : 0 < Real.log z := Real.log_pos hz + have hLL1 : 1 ≤ Real.log (Real.log z) := hLL + have hLLpos : 0 < Real.log (Real.log z) := by linarith + have hbound : (Real.log (Real.log z))^2 ≤ (Real.log z)^((1 : ℝ)/2) := by + simpa only [Real.norm_eq_abs,Real.rpow_two,abs_of_nonneg (sq_nonneg (Real.log (Real.log z))), + abs_of_nonneg (Real.rpow_nonneg hL.le ((1 : ℝ)/2)),one_mul] using hh + have heq : (Real.log z)^((1 : ℝ)/2)*(Real.log z)^((1 : ℝ)/2) = Real.log z := by + rw [← Real.rpow_add hL] + norm_num + refine ⟨hz,hL,?_,?_⟩ + · apply (le_div_iff₀ (sq_pos_of_pos hLLpos)).mpr + nlinarith [mul_le_mul_of_nonneg_left hbound (Real.rpow_nonneg hL.le ((1 : ℝ)/2))] + · exact div_le_self hL.le (by nlinarith) + +theorem sourceW_le_power (alpha : ℝ) (ha : 0 < alpha) : + ∀ᶠ z : ℝ in atTop,sourceW z ≤ z^alpha := by + have hs := (isLittleO_log_rpow_rpow_atTop (1 : ℝ) ha).bound zero_lt_one + filter_upwards [sourceW_log_bounds,hs] with z hz hh + have hlog : Real.log z ≤ z^alpha := by + simpa only [Real.norm_eq_abs,Real.rpow_one,abs_of_pos hz.2.1, + abs_of_nonneg (Real.rpow_nonneg (by linarith [hz.1] : 0 ≤ z) alpha),one_mul] using hh + exact hz.2.2.2.trans hlog + +theorem source_inverse_power_log_tendsto (t : ℝ) (ht : 12 < t) : + Tendsto (fun z : ℝ => (Real.log z)^6*(sourceW z)^(-t)) atTop (𝓝 0) := by + have heps : 0 < t/2-6 := by linarith + have hT := (tendsto_rpow_neg_atTop heps).comp Real.tendsto_log_atTop + have hnonneg : ∀ᶠ z : ℝ in atTop,0 ≤ (Real.log z)^6*(sourceW z)^(-t) := by + filter_upwards [sourceW_log_bounds] with z hz + have hWpos : 0 < sourceW z := (Real.rpow_pos_of_pos hz.2.1 _).trans_le hz.2.2.1 + exact mul_nonneg (pow_nonneg hz.2.1.le 6) (Real.rpow_nonneg hWpos.le _) + have hbound : ∀ᶠ z : ℝ in atTop, + (Real.log z)^6*(sourceW z)^(-t) ≤ (Real.log z)^(-(t/2-6)) := by + filter_upwards [sourceW_log_bounds] with z hz + have hpow := Real.rpow_le_rpow_of_nonpos (Real.rpow_pos_of_pos hz.2.1 ((1 : ℝ)/2)) + hz.2.2.1 (show -t ≤ 0 by linarith) + calc + _ ≤ (Real.log z)^6*((Real.log z)^((1 : ℝ)/2))^(-t) := + mul_le_mul_of_nonneg_left hpow (pow_nonneg hz.2.1.le 6) + _ = _ := by + rw [← Real.rpow_mul hz.2.1.le,← Real.rpow_natCast (Real.log z) 6,← Real.rpow_add hz.2.1] + congr 1 + norm_num + ring + exact squeeze_zero' hnonneg hbound hT + +end ErdosInverseSampleCost + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceSmallModel +open ErdosInversePrimeBin ErdosInverseBoxHeight ErdosInverseSampleCost + +theorem source_model_population (alpha xi : ℝ) (ha : 0 < alpha) (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,∀ R theta : ℝ,z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + 1 < R ∧ sourceW z ≤ R ∧ xi*R/(16*Real.log R) ≤ ((primeBin R theta).card : ℝ) := by + obtain ⟨R0,hR0⟩ := eventually_atTop.mp (uniform_prime_bin_count (by positivity : 0 < xi/4)) + filter_upwards [(tendsto_rpow_atTop ha).eventually_ge_atTop R0,sourceW_le_power alpha ha] + with z hz hW + intro R theta hRlo htl htu + have hc := hR0 R (hz.trans hRlo) + have hRp : 0 < R := by linarith [hc.1] + have hlog : 0 < Real.log R := Real.log_pos (by linarith [hc.1]) + refine ⟨by linarith [hc.1],hW.trans hRlo,?_⟩ + calc + _ = (xi/4)*R/(4*Real.log R) := by ring + _ ≤ theta*R/(4*Real.log R) := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right htl hRp.le) (by positivity) + _ ≤ _ := (hc.2 theta htl (htu.trans hxi1)).1 + +end ErdosVarianceSmallModel + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSampleCost +open ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_rounding_log_tendsto (K alpha : ℝ) (h : ℕ) (hK : 0 ≤ K) (ha : 0 < alpha) : + Tendsto (fun z : ℝ => (Real.log z)^6*(smallModulus (sourceW z) : ℝ)* + (2*(sourceW z)^K)^h/z^alpha) atTop (𝓝 0) := by + have hcoef : 0 < (2 : ℝ)^h := by positivity + have hs := (isLittleO_log_rpow_rpow_atTop (6+K*(h : ℝ)) (by positivity : 0 < alpha/4)).bound (inv_pos.mpr hcoef) + have hbound : ∀ᶠ z : ℝ in atTop, + (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*(sourceW z)^K)^h/z^alpha ≤ z^(-(alpha/2)) := by + filter_upwards [sourceW_log_bounds,smallModulus_source_power 1 1 zero_lt_one, + sourceZ_le_rpow (alpha/4) (by positivity),hs] with z hz hM hZ hh + have hzpos : 0 < z := by linarith [hz.1] + have hWpos : 0 < sourceW z := (Real.rpow_pos_of_pos hz.2.1 _).trans_le hz.2.2.1 + have hMbound : (smallModulus (sourceW z) : ℝ) ≤ z^(alpha/4) := by + have hm : (smallModulus (sourceW z) : ℝ) ≤ sourceZ z := by simpa only [pow_one,Real.rpow_one] using hM + exact hm.trans hZ.2 + have hlogbound : (2 : ℝ)^h*(Real.log z)^(6+K*(h : ℝ)) ≤ z^(alpha/4) := by + have hsimp : (Real.log z)^(6+K*(h : ℝ)) ≤ ((2 : ℝ)^h)⁻¹*z^(alpha/4) := by + simpa only [Real.norm_eq_abs,abs_of_nonneg (Real.rpow_nonneg hz.2.1.le _), + abs_of_nonneg (Real.rpow_nonneg hzpos.le _)] using hh + have hm := mul_le_mul_of_nonneg_left hsimp hcoef.le + have heq : (2 : ℝ)^h*(((2 : ℝ)^h)⁻¹*z^(alpha/4)) = z^(alpha/4) := by field_simp + rwa [heq] at hm + have hsmall : (Real.log z)^6*(2*(sourceW z)^K)^h ≤ z^(alpha/4) := by + calc + _ ≤ (Real.log z)^6*(2*(Real.log z)^K)^h := + mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (by positivity) (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hWpos.le hz.2.2.2 hK) (by norm_num)) h) + (pow_nonneg hz.2.1.le 6) + _ = (2 : ℝ)^h*(Real.log z)^(6+K*(h : ℝ)) := by + rw [mul_pow,← Real.rpow_natCast ((Real.log z)^K) h,← Real.rpow_mul hz.2.1.le, + ← Real.rpow_natCast (Real.log z) 6] + norm_num only [Nat.cast_ofNat] + calc + _ = (2 : ℝ)^h*((Real.log z)^(6 : ℝ)*(Real.log z)^(K*(h : ℝ))) := by ring + _ = _ := by rw [← Real.rpow_add hz.2.1] + _ ≤ _ := hlogbound + calc + _ = (smallModulus (sourceW z) : ℝ)*((Real.log z)^6*(2*(sourceW z)^K)^h)/z^alpha := by ring + _ ≤ z^(alpha/4)*z^(alpha/4)/z^alpha := by + apply div_le_div_of_nonneg_right _ (Real.rpow_nonneg hzpos.le _) + exact mul_le_mul hMbound hsmall (by positivity) (Real.rpow_nonneg hzpos.le _) + _ = z^(-(alpha/2)) := by + rw [← Real.rpow_add hzpos,← Real.rpow_sub hzpos] + congr 1 + ring + have hnonneg : ∀ᶠ z : ℝ in atTop,0 ≤ + (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*(sourceW z)^K)^h/z^alpha := by + filter_upwards [sourceW_log_bounds] with z hz + have hzpos : 0 < z := by linarith [hz.1] + have hWpos : 0 < sourceW z := (Real.rpow_pos_of_pos hz.2.1 _).trans_le hz.2.2.1 + positivity + exact squeeze_zero' hnonneg hbound (tendsto_rpow_neg_atTop (by positivity : 0 < alpha/2)) + +end ErdosInverseSampleCost + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSampleCost +open ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_cost_budget (aStar K alpha eps : ℝ) (h : ℕ) (hK : 0 ≤ K) + (ha : 0 < alpha) (heps : 0 < eps) (hh : 12 < aStar*(h : ℝ)/2) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R U : ℝ,z^alpha ≤ R → 0 ≤ U → U ≤ (sourceW z)^K → + (Real.log z)^6*(4*R*((sourceW z)^(-aStar/2))^h+ + (smallModulus (sourceW z) : ℝ)*(2*U)^h)/R ≤ eps := by + have hmain := source_inverse_power_log_tendsto (aStar*(h : ℝ)/2) hh + have hround := source_rounding_log_tendsto K alpha h hK ha + have hsum : Tendsto (fun z : ℝ => 4*((Real.log z)^6*(sourceW z)^(-(aStar*(h : ℝ)/2)))+ + (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*(sourceW z)^K)^h/z^alpha) atTop (𝓝 0) := by + simpa only [mul_zero,zero_add] using (hmain.const_mul 4).add hround + have hs := (tendsto_order.mp hsum).2 eps heps + filter_upwards [hs,sourceW_log_bounds] with z hsumsmall hz + refine ⟨hz.1,?_⟩ + intro R U hR hU hUtop + have hzpos : 0 < z := by linarith [hz.1] + have hWpos : 0 < sourceW z := (Real.rpow_pos_of_pos hz.2.1 _).trans_le hz.2.2.1 + have hRpos : 0 < R := (Real.rpow_pos_of_pos hzpos alpha).trans_le hR + have htau : ((sourceW z)^(-aStar/2))^h = (sourceW z)^(-(aStar*(h : ℝ)/2)) := by + rw [← Real.rpow_natCast ((sourceW z)^(-aStar/2)) h,← Real.rpow_mul hWpos.le] + congr 1 + ring + have hURound : (2*U)^h ≤ (2*(sourceW z)^K)^h := + pow_le_pow_left₀ (by positivity) (mul_le_mul_of_nonneg_left hUtop (by norm_num)) h + have hroundle : (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*U)^h/R ≤ + (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*(sourceW z)^K)^h/z^alpha := by + calc + _ ≤ (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*(sourceW z)^K)^h/R := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hURound (by positivity)) hRpos.le + _ ≤ _ := div_le_div_of_nonneg_left (by positivity) (Real.rpow_pos_of_pos hzpos _) hR + calc + _ = 4*((Real.log z)^6*(sourceW z)^(-(aStar*(h : ℝ)/2)))+ + (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*U)^h/R := by + rw [htau] + field_simp + _ ≤ 4*((Real.log z)^6*(sourceW z)^(-(aStar*(h : ℝ)/2)))+ + (Real.log z)^6*(smallModulus (sourceW z) : ℝ)*(2*(sourceW z)^K)^h/z^alpha := + add_le_add le_rfl hroundle + _ ≤ eps := hsumsmall.le + +end ErdosInverseSampleCost + +end + +section + +namespace ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem atomWeight_totient (R xi w : ℝ) (H : ℕ) (C0 : ℤ) : + atomWeight R xi w H C0 = (H : ℝ)/ + (((H*divisorModulus w H*coprimeModulus w H).totient : ℝ)*modelLength R xi (H : ℝ) (C0 : ℝ)) := by + rw [pattern_totient] + simp only [atomWeight,Nat.cast_mul] + congr 1 + ring + +theorem prime_bound_le_atom (R xi w : ℝ) (H : ℕ) (C0 : ℤ) (n : ℕ) (C : ℝ) + (hR : 1 < R) (hxi : 0 < xi) (hH : 0 < H) (hC : 0 ≤ C) + (hPopulation : xi*R/(16*Real.log R) ≤ (n : ℝ)) : + C*primeWidth R xi (H : ℝ) (C0 : ℝ)/ + (((H*divisorModulus w H*coprimeModulus w H).totient : ℝ)*Real.log R) ≤ + (32*C*(n : ℝ))*atomWeight R xi w H C0 := by + have hRp : 0 < R := by linarith + have hlog : 0 < Real.log R := Real.log_pos hR + have hHR : (0 : ℝ) < H := by exact_mod_cast hH + have hM : 0 < H*divisorModulus w H*coprimeModulus w H := + Nat.mul_pos (Nat.mul_pos hH (divisorModulus_pos w H)) (coprimeModulus_pos w H) + have hphi : (0 : ℝ) < (H*divisorModulus w H*coprimeModulus w H).totient := by + exact_mod_cast Nat.totient_pos.mpr hM + have hY : 0 < modelLength R xi (H : ℝ) (C0 : ℝ) := by + dsimp [modelLength,interceptScale] + positivity + have hpop := (div_le_iff₀ (by positivity : 0 < 16*Real.log R)).mp hPopulation + have harea := small_model_area R xi (H : ℝ) (C0 : ℝ) hRp hxi hHR + have hpopH := mul_le_mul_of_nonneg_right hpop (show 0 ≤ 2*(H : ℝ) by positivity) + have hwidth : primeWidth R xi (H : ℝ) (C0 : ℝ)*modelLength R xi (H : ℝ) (C0 : ℝ) ≤ + 32*(n : ℝ)*Real.log R*(H : ℝ) := by nlinarith + calc + _ ≤ ((32*C*(n : ℝ))*(H : ℝ))/ + (((H*divisorModulus w H*coprimeModulus w H).totient : ℝ)*modelLength R xi (H : ℝ) (C0 : ℝ)) := by + apply (div_le_div_iff₀ (mul_pos hphi hlog) (mul_pos hphi hY)).mpr + have hh := mul_le_mul_of_nonneg_left hwidth + (mul_nonneg hC (hphi.le)) + nlinarith + _ = _ := by rw [atomWeight_totient];ring + +theorem finite_model_domination (P : Finset ℕ) (R xi w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (hR : 1 < R) (hxi : 0 < xi) (hH : 0 < H) (hC0 : Int.gcd C0 (H : ℤ) = 1) + (hbin : ∀ p ∈ P,R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) + (C : ℝ) (hC : 0 ≤ C) (hPopulation : xi*R/(16*Real.log R) ≤ (P.card : ℝ)) + (hFibre : ∀ v ∈ modelUniverse R xi w H C0, + ((primeFibre P w H C0 hw hP hlarge v).card : ℝ) ≤ + C*primeWidth R xi (H : ℝ) (C0 : ℝ)/ + (((H*divisorModulus w H*coprimeModulus w H).totient : ℝ)*Real.log R)) + (E : ModelPoint w H → Prop) : + ((actualPrimeEvent P w H C0 hw hP hlarge E).card : ℝ)/(P.card : ℝ) ≤ + (32*C)*modelMass R xi w H C0 E := by + have hRp : 0 < R := by linarith + have hlog : 0 < Real.log R := Real.log_pos hR + have hPpos : (0 : ℝ) < P.card := (by positivity : 0 < xi*R/(16*Real.log R)).trans_le hPopulation + have hatom := prime_bound_le_atom R xi w H C0 P.card C hR hxi hH hC hPopulation + apply (div_le_iff₀ hPpos).mpr + calc + _ = ∑ v ∈ (modelUniverse R xi w H C0).filter E,((primeFibre P w H C0 hw hP hlarge v).card : ℝ) := by + rw [actualPrimeEvent_card_fibres P R xi w H C0 hw hP hlarge hRp hxi.le hH hC0 hbin E,Nat.cast_sum] + _ ≤ ∑ _v ∈ (modelUniverse R xi w H C0).filter E,(32*C*(P.card : ℝ))*atomWeight R xi w H C0 := by + apply Finset.sum_le_sum + intro v hv + exact (hFibre v (Finset.mem_filter.mp hv).1).trans hatom + _ = ((32*C)*modelMass R xi w H C0 E)*(P.card : ℝ) := by + rw [← Finset.mul_sum] + change (32*C*(P.card : ℝ))*modelMass R xi w H C0 E = _ + ring + +end ErdosVarianceSmallModel + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceSmallModel +open ErdosInversePrimeBin ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_prime_model_domination (alpha : ℝ) (ha : 0 < alpha) : + ∃ C : ℝ,0 < C ∧ ∀ xi : ℝ,0 < xi → xi ≤ 1 → + ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ) (H : ℕ) (C0 : ℤ), + z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → 0 < H → Int.gcd C0 (H : ℤ) = 1 → + (H : ℝ) ≤ R^((4 : ℝ)/5) → totalScale R (H : ℝ) (C0 : ℝ)/(H : ℝ) ≤ (sourceZ z)^12 → + ∃ (hw : 0 ≤ sourceW z) (hP : ∀ p ∈ primeBin R theta,p.Prime) + (hlarge : ∀ p ∈ primeBin R theta,sourceW z < (p : ℝ)), + ∀ E : ModelPoint (sourceW z) H → Prop, + ((actualPrimeEvent (primeBin R theta) (sourceW z) H C0 hw hP hlarge E).card : ℝ)/ + ((primeBin R theta).card : ℝ) ≤ C*modelMass R xi (sourceW z) H C0 E := by + obtain ⟨C,hC,hFibres⟩ := source_residue_fibre_bound alpha ha + refine ⟨32*C,by positivity,?_⟩ + intro xi hxi hxi1 + filter_upwards [hFibres xi hxi hxi1,source_model_population alpha xi ha hxi hxi1, + sourceW_tendsto_atTop.eventually_ge_atTop 2] with z hFibre hPopulation hW + intro R theta H C0 hRlo htl htu hH hC0 hHsmall hRatio + have hpops := hPopulation R theta hRlo htl htu + have hR : 0 < R := by linarith [hpops.1] + have ht : 0 ≤ theta := (by positivity : (0 : ℝ) ≤ xi/4).trans htl + let P := primeBin R theta + have hP : ∀ p ∈ P,p.Prime := fun p hp => ((mem_primeBin hR.le ht p).mp hp).1 + have hlarge : ∀ p ∈ P,sourceW z < (p : ℝ) := + fun p hp => hpops.2.1.trans_lt ((mem_primeBin hR.le ht p).mp hp).2.1 + have hbin : ∀ p ∈ P,R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R := by + intro p hp + have hh := (mem_primeBin hR.le ht p).mp hp + refine ⟨hh.2.1,?_⟩ + have htR := mul_le_mul_of_nonneg_right htu hR.le + nlinarith [hh.2.2] + have hw : 0 ≤ sourceW z := by linarith + let : NeZero H := ⟨hH.ne'⟩ + refine ⟨hw,hP,hlarge,?_⟩ + intro E + apply finite_model_domination P R xi (sourceW z) H C0 hw hP hlarge hpops.1 hxi hH hC0 hbin C hC.le hpops.2.2 + · intro v hv + have hm := (mem_modelUniverse R xi (sourceW z) H C0 v).mp hv |>.2.2 + let M := H*divisorModulus (sourceW z) H*coprimeModulus (sourceW z) H + have hM : 0 < M := Nat.mul_pos (Nat.mul_pos hH (divisorModulus_pos _ H)) (coprimeModulus_pos _ H) + have hMbound : (M : ℝ) ≤ (H : ℝ)*(smallModulus (sourceW z) : ℝ) := by + have hh := pattern_modulus_size (sourceW z) H + have he : (M : ℝ) = (H : ℝ)*(smallModulus (sourceW z) : ℝ) := by exact_mod_cast hh + exact he.le + calc + _ ≤ ((residueFibre P (H : ℝ) (C0 : ℝ) v.1 M + (patternClass (sourceW z) H C0 hC0 v.1 hm v.2 : ℤ)).card : ℝ) := by + exact_mod_cast primeFibre_card_le_residue P (sourceW z) H C0 hw hP hlarge hC0 v hm + _ ≤ _ := hFibre.2 P R (H : ℝ) (C0 : ℝ) v.1 M + (patternClass (sourceW z) H C0 hC0 v.1 hm v.2 : ℤ) hRlo (by exact_mod_cast hH) hM + hHsmall hMbound hRatio (fun p hp => ⟨hP p hp,(hbin p hp).1,(hbin p hp).2⟩) + +end ErdosVarianceSmallModel + +end + +section + +namespace ErdosVarianceEffective +open ErdosInverseAlignment ErdosPrimitiveIntercept +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem badPrimeProduct_extension_dvd (a : ℕ → ℤ) (r : ℚ) (q e : ℕ) (hq : q ≠ 0) : + badPrimeProduct a r (q*e) ∣ badPrimeProduct a r q*e := by + apply Finset.prod_primes_dvd + · intro p hp + exact (Nat.prime_of_mem_primeFactors (Finset.mem_filter.mp hp).1).prime + · intro p hp + obtain ⟨hpf,hnon⟩ := Finset.mem_filter.mp hp + have hprime := Nat.prime_of_mem_primeFactors hpf + rcases hprime.dvd_mul.mp (Nat.dvd_of_mem_primeFactors hpf) with hpq | hpe + · have hpbad : p ∈ badPrimeFactors a r q := Finset.mem_filter.mpr + ⟨Nat.mem_primeFactors.mpr ⟨hprime,hpq,hq⟩,hnon⟩ + exact dvd_mul_of_dvd_left (Finset.dvd_prod_of_mem _ hpbad) e + · exact dvd_mul_of_dvd_right hpe _ + +theorem effectiveModulus_extension_le (a : ℕ → ℕ) (r : ℚ) (q e : ℕ) (hq : 0 < q) (he : 0 < e) : + effectiveModulus a r (q*e) ≤ + (r.den*badPrimeProduct (fun t => (a t : ℤ)) r q)*e := by + have hh := Nat.le_of_dvd (Nat.mul_pos (badPrimeProduct_pos (fun t => (a t : ℤ)) r q) he) + (badPrimeProduct_extension_dvd (fun t => (a t : ℤ)) r q e hq.ne') + simpa only [effectiveModulus,Nat.mul_assoc] using Nat.mul_le_mul_left r.den hh + +theorem effectiveModulus_height_of_extension (a : ℕ → ℕ) (r : ℚ) (q e : ℕ) (hq : 0 < q) (he : 0 < e) + (R Z : ℝ) (hR : 0 ≤ R) (_hZ : 0 ≤ Z) + (hparent : ((r.den*badPrimeProduct (fun t => (a t : ℤ)) r q : ℕ) : ℝ) ≤ R*Z^10) + (heZ : (e : ℝ) ≤ Z) : + (effectiveModulus a r (q*e) : ℝ) ≤ R*Z^11 := by + calc + _ ≤ ((r.den*badPrimeProduct (fun t => (a t : ℤ)) r q : ℕ) : ℝ)*(e : ℝ) := by + exact_mod_cast effectiveModulus_extension_le a r q e hq he + _ ≤ (R*Z^10)*Z := mul_le_mul hparent heZ (Nat.cast_nonneg _) (by positivity) + _ = _ := by ring + +end ErdosVarianceEffective + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosVarianceEffective +open ErdosInverseBoxHeight ErdosInverseEuler ErdosInverseSampleCost + +theorem sourceW_power_subpower (A eps : ℝ) (hA : 0 ≤ A) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop,(sourceW z)^A ≤ (sourceZ z)^eps := by + filter_upwards [sourceW_log_bounds, + (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop 1, + exp_loglog_sq_le_sourceZ A eps hA heps] with z hz hLL hExp + have hW : 0 < sourceW z := (Real.rpow_pos_of_pos hz.2.1 _).trans_le hz.2.2.1 + change 1 ≤ Real.log (Real.log z) at hLL + have hLLsq : Real.log (Real.log z) ≤ (Real.log (Real.log z))^2 := by nlinarith + calc + _ ≤ (Real.log z)^A := Real.rpow_le_rpow hW.le hz.2.2.2 hA + _ = Real.exp (A*Real.log (Real.log z)) := by rw [Real.rpow_def_of_pos hz.2.1];congr 1;ring + _ ≤ Real.exp (A*(Real.log (Real.log z))^2) := Real.exp_le_exp.mpr + (mul_le_mul_of_nonneg_left hLLsq hA) + _ ≤ _ := hExp + +theorem extension_le_parent_power (Y p q e : ℕ) (hp : 0 < p) (hq : 0 < q) (he : 0 < e) + (w C : ℝ) (hw : 1 < w) (hFinal : p*(q*e) ≤ Y) + (hParent : Real.logb w ((Y : ℝ)/((p : ℝ)*q)) ≤ C) : (e : ℝ) ≤ w^C := by + have hden : 0 < (p : ℝ)*q := by positivity + have hY : 0 < Y := (Nat.mul_pos hp (Nat.mul_pos hq he)).trans_le hFinal + have hratio : 0 < (Y : ℝ)/((p : ℝ)*q) := by positivity + have hbound : (e : ℝ) ≤ (Y : ℝ)/((p : ℝ)*q) := by + apply (le_div_iff₀ hden).mpr + have hh : (p : ℝ)*((q : ℝ)*(e : ℝ)) ≤ (Y : ℝ) := by exact_mod_cast hFinal + nlinarith + exact hbound.trans ((Real.logb_le_iff_le_rpow hw hratio).mp hParent) + +theorem source_extension_le_Z (C : ℝ) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop,∀ p q e : ℕ,0 < p → 0 < q → 0 < e → + p*(q*e) ≤ sourceY z → + Real.logb (sourceW z) ((sourceY z : ℝ)/((p : ℝ)*q)) ≤ C → (e : ℝ) ≤ sourceZ z := by + filter_upwards [sourceW_power_subpower C 1 hC zero_lt_one,sourceW_tendsto_atTop.eventually_ge_atTop 2] + with z hpower hW + intro p q e hp hq he hFinal hParent + have hh := extension_le_parent_power (sourceY z) p q e hp hq he (sourceW z) C (by linarith) hFinal hParent + exact hh.trans (by simpa only [Real.rpow_one] using hpower) + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceFirstCrossing.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceFirstCrossing.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee62101258574da2fbec950641cad81dd37bd6a7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceFirstCrossing.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FiniteBoxWordMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.FirstGapCrossing +open FinitePathGeometry PrimeHistories PrimeTiltGeometry ErdosSearchCount +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem first_gap_crossing {w ell S : ℝ} (hell : 0 ≤ ell) (z : Node) + (hs : Valid z.side z.ratio) (ps : List ℕ) (ha : allowed w ell S z ps) + (H : ℝ) (hstart : H < z.gap) (hend : (terminal w z ps).gap ≤ H) : + ∃ pre p tail,ps=pre++p::tail ∧ H < (terminal w z pre).gap ∧ + (terminal w z (pre++[p])).gap ≤ H ∧ H/3 < (terminal w z (pre++[p])).gap := by + induction ps generalizing z with + | nil => exact False.elim (not_lt_of_ge hend hstart) + | cons p ps ih => + obtain ⟨hp,ht⟩ := (allowed_cons w ell S z p ps).mp ha + by_cases hc : (step w z p).gap ≤ H + · have hh := child_gap_third hell hs hp + exact ⟨[],p,ps,rfl,hstart,hc,by change H/3 < (step w z p).gap; linarith⟩ + · obtain ⟨pre,q,tail,he,hpre,hend,hlo⟩ := ih (step w z p) (child_valid hs hp) ht (lt_of_not_ge hc) hend + refine ⟨p::pre,q,tail,by rw [List.cons_append,he],hpre,?_,?_⟩ + · simpa only [List.cons_append,terminal_cons] using hend + · simpa only [List.cons_append,terminal_cons] using hlo +end NumberTheoryLean.FirstGapCrossing + + + +namespace NumberTheoryLean.SourceFirstCrossing +open FinitePathGeometry PrimeHistories PrimeTiltGeometry PrimeBinMembership FirstGapCrossing +open ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +theorem source_first_above {w ell S B theta : ℝ} (hB : 0 < B) (htheta : theta ≤ 1/2) + (z : Node) (hs : 199/100 ≤ z.ratio) (hc : Consistent z) (hcut : z.cutoff=B) + {p : ℕ} (hp : p ∈ nodeChildren w ell S z) : theta*B < (step w z p).gap := by + have hcap := (Finset.mem_filter.mp hp).2.2.1 + have hx : primeExponent w p ≤ B := by + change capGuard z.closed z.cutoff (primeExponent w p) at hcap + rw [hcut] at hcap + cases h : z.closed <;> simp [capGuard,h] at hcap + · exact hcap.le + · exact hcap + have hgap : z.gap=z.ratio*B := by + have he : B=z.gap/z.ratio := hcut.symm.trans hc + have hh := (eq_div_iff (by linarith : z.ratio ≠ 0)).mp he + nlinarith + change theta*B < z.gap-primeExponent w p + rw [hgap] + nlinarith + +theorem source_gap_crossing {w ell S B theta : ℝ} (hell : 0 ≤ ell) (hB : 0 < B) + (htheta : theta ≤ 1/2) (z : Node) (hs : Valid z.side z.ratio) + (h199 : 199/100 ≤ z.ratio) (hc : Consistent z) (hcut : z.cutoff=B) + (ps : List ℕ) (ha : allowed w ell S z ps) (hend : (terminal w z ps).gap ≤ theta*B) : + ∃ pre p tail,pre ≠ [] ∧ ps=pre++p::tail ∧ theta*B < (terminal w z pre).gap ∧ + (terminal w z (pre++[p])).gap ≤ theta*B ∧ theta*B/3 < (terminal w z (pre++[p])).gap := by + have hg : z.gap=z.ratio*B := (SourceNodeCoordinates.node_gap_eq hs hc hcut).trans (mul_comm _ _) + have hstart : theta*B < z.gap := by rw [hg]; nlinarith + obtain ⟨pre,p,tail,he,hpre,hhi,hlo⟩ := first_gap_crossing hell z hs ps ha (theta*B) hstart hend + refine ⟨pre,p,tail,?_,he,hpre,hhi,hlo⟩ + intro hn + subst pre + simp only [List.nil_append] at he hhi + have hp := ((allowed_cons w ell S z p tail).mp (he ▸ ha)).1 + exact (not_lt_of_ge hhi) (source_first_above hB htheta z h199 hc hcut hp) +end NumberTheoryLean.SourceFirstCrossing + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceFullPatternDomination.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceFullPatternDomination.lean new file mode 100644 index 0000000000000000000000000000000000000000..aa6356bf715207b0b3ea513811a79946d4583aa7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceFullPatternDomination.lean @@ -0,0 +1,70 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.PatternErrorNormalization + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +open _root_.Filter +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosLargeHeightBlocks ErdosInversePrimeBin + ErdosInverseBoxHeight ErdosInverseEuler +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_full_pattern_domination (alpha : ℝ) (halpha : 0 < alpha) : + ∃ C : ℝ,0 < C ∧ ∀ xi : ℝ,0 < xi → xi ≤ 1 → ∀ eps : ℝ,0 < eps → + ∀ᶠ z : ℝ in atTop,1 < z ∧ + ∀ (R theta : ℝ),z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + ∀ (H : ℕ) (C0 : ℤ),2 ≤ H → Int.gcd C0 (H : ℤ) = 1 → + R^((4 : ℝ)/5) ≤ (H : ℝ) → (H : ℝ) ≤ R*(sourceZ z)^11 → + max (H : ℝ) (|(C0 : ℝ)|/R)/(H : ℝ) ≤ (sourceZ z)^12 → + ∃ (hw : 0 ≤ sourceW z) (hP : ∀ p ∈ primeBin R theta,p.Prime) + (hlarge : ∀ p ∈ primeBin R theta,sourceW z < (p : ℝ)), + ∀ E : ErdosLargePatternLaw.FullPattern (sourceW z) H → Prop, + ((fullPrimeEvent (primeBin R theta) (sourceW z) H C0 hw hP hlarge E).card : ℝ)/ + ((primeBin R theta).card : ℝ) ≤ C*patternEventWeight (sourceW z) H E+eps := by + obtain ⟨C,hC,hcount⟩ := source_full_event_count alpha halpha + refine ⟨16*C,by positivity,?_⟩ + intro xi hxi hxi1 eps heps + filter_upwards [hcount,source_pattern_error_normalized alpha xi eps halpha hxi hxi1 heps, + source_model_population alpha xi halpha hxi hxi1,sourceW_tendsto_atTop.eventually_ge_atTop 0] + with z hzcount hzerror hzpop hw + refine ⟨hzcount.1,?_⟩ + intro R theta hRlo hthetal hthetau H C0 hH hC0 hHlo hHhi hratio + have hpop := hzpop R theta hRlo hthetal hthetau + have hR : 0 < R := by linarith [hpop.1] + have hlog : 0 < Real.log R := Real.log_pos hpop.1 + have htheta : 0 < theta := (by positivity : (0 : ℝ) < xi/4).trans_le hthetal + have htheta1 := hthetau.trans hxi1 + have hP : ∀ p ∈ primeBin R theta,p.Prime := fun p hp => ((mem_primeBin hR.le htheta.le p).mp hp).1 + have hlarge : ∀ p ∈ primeBin R theta,sourceW z < (p : ℝ) := fun p hp => + hpop.2.1.trans_lt ((mem_primeBin hR.le htheta.le p).mp hp).2.1 + refine ⟨hw,hP,hlarge,?_⟩ + intro E + have hc := hzcount.2 R theta hRlo htheta htheta1 H C0 hH hC0 hHlo hHhi hw hP hlarge E + have he := hzerror R theta hRlo hthetal hthetau H C0 (by omega) hratio + have hlow : 0 < xi*R/(16*Real.log R) := by positivity + have hPC : 0 < ((primeBin R theta).card : ℝ) := hlow.trans_le hpop.2.2 + have hcoef : C*theta*R/Real.log R ≤ (16*C)*((primeBin R theta).card : ℝ) := by + apply (div_le_iff₀ hlog).mpr + have hb := (div_le_iff₀ (show 0 < 16*Real.log R by positivity)).mp hpop.2.2 + have hm := mul_le_mul_of_nonneg_left hb hC.le + have ht := mul_le_mul_of_nonneg_left hthetau (show 0 ≤ C*R by positivity) + nlinarith only [hm,ht] + have hmain : (C*theta*R/Real.log R*patternEventWeight (sourceW z) H E)/ + ((primeBin R theta).card : ℝ) ≤ (16*C)*patternEventWeight (sourceW z) H E := by + apply (div_le_iff₀ hPC).mpr + have hh := mul_le_mul_of_nonneg_right hcoef (patternEventWeight_nonneg (sourceW z) H E) + nlinarith only [hh] + have hd := div_le_div_of_nonneg_right hc hPC.le + rw [add_div] at hd + exact hd.trans (add_le_add hmain he) + +end ErdosVarianceLargeMap + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceGuardedHardCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceGuardedHardCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e3ee51bd730505cc781ab03cb4bb9cd0e68c72f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceGuardedHardCount.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Primes.GuardedHardPrimeSets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosVarianceWeighted +open NumberTheoryLean ErdosInverseBoxHeight ErdosInversePrimeBin ErdosVarianceEffective ErdosVarianceSmallPrime + ErdosVarianceLargePrime +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_guarded_hard_count (alpha aStar eps sigma Cmin : ℝ) + (halpha : 0 < alpha) (ha : 0 < aStar) (heps : 0 < eps) (hsigma : 0 < sigma) : + ∃ Cs : ℝ,0 < Cs ∧ Cmin ≤ Cs ∧ ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,0 < xi → xi ≤ xi0 → ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ) (a : ℕ → ℕ) (qf : ℕ),Squarefree qf → + z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + (∀ t ∈ qf.primeFactors,sourceW z < (t : ℝ)) → + (∀ p ∈ primeBin R theta,qf.Coprime p ∧ + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*qf))/Real.log (sourceW z)) → + ∀ r : ℚ,((guardedHardPrimes z R theta a r qf Cs eps).card : ℝ) ≤ + sigma*((primeBin R theta).card : ℝ) := by + obtain ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,hsource⟩ := + source_hard_bad_prime_fraction alpha aStar eps sigma Cmin halpha ha heps hsigma + refine ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + filter_upwards [hsource xi hxi hxib] with z hz + intro R theta a qf hq hRlo hthetal hthetau hQLarge hgeometry r + by_cases hg : hardCandidate z R a r qf Cs + · have hb := hz R theta a r qf hq hRlo hthetal hthetau hQLarge hgeometry hg.1 hg.2.1 hg.2.2 + rw [guardedHardPrimes,ite_eq_left hg] + exact subset_card_of_fraction _ _ (Finset.filter_subset _ _) sigma hb + · simp only [guardedHardPrimes,ite_eq_right hg,Finset.card_empty,Nat.cast_zero] + positivity + +end ErdosVarianceWeighted + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceInitialDiscard.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceInitialDiscard.lean new file mode 100644 index 0000000000000000000000000000000000000000..9309ed67dc5f4ebe883179349e334f2db1196eff --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceInitialDiscard.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Partitions.SourceLabelCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseCells + +theorem discard_coefficient_bound (S Z eps : ℝ) (n labels : ℕ) (hS : 0 < S) (hZ : 0 < Z) + (hn : S/Z^eps ≤ (n : ℝ)) (hl : (labels : ℝ) ≤ Z^eps) : + (labels : ℝ)*(S/Z)*Z^eps/(n : ℝ) ≤ Z^(3*eps-1) := by + have hZpow : 0 < Z^eps := Real.rpow_pos_of_pos hZ eps + have hn0 : (0 : ℝ) < n := (div_pos hS hZpow).trans_le hn + calc + _ ≤ Z^eps*(S/Z)*Z^eps/(n : ℝ) := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right hl (div_pos hS hZ).le) hZpow.le) hn0.le + _ ≤ Z^eps*(S/Z)*Z^eps/(S/Z^eps) := + div_le_div_of_nonneg_left (by positivity) (div_pos hS hZpow) hn + _ = (S*S⁻¹)*(Z^eps*Z^eps*Z^eps/Z) := by + simp only [div_eq_mul_inv,mul_inv_rev,inv_inv] + ring + _ = Z^eps*Z^eps*Z^eps/Z := by rw [mul_inv_cancel₀ hS.ne',one_mul] + _ = Z^(eps+eps+eps-1) := by + rw [← Real.rpow_add hZ,← Real.rpow_add hZ] + simpa only [Real.rpow_one] using (Real.rpow_sub hZ (eps+eps+eps) 1).symm + _ = Z^(3*eps-1) := by congr 1;ring + +end ErdosInverseCells + +end + +section + +namespace ErdosInverseCells +attribute [local instance] Classical.decEq + +theorem subset_weight_spread {α : Type*} (Q D : Finset α) (hD : D ⊆ Q) (hQ : 0 < Q.card) + (w : α → ℝ) (G : ℝ) (hspread : ∀ q ∈ Q,∀ r ∈ Q,w q ≤ G*w r) : + (∑ q ∈ D,w q) ≤ ((D.card : ℝ)*G/(Q.card : ℝ))*(∑ r ∈ Q,w r) := by + have hQpos : (0 : ℝ) < Q.card := by exact_mod_cast hQ + have hdouble : (Q.card : ℝ)*(∑ q ∈ D,w q) ≤ (D.card : ℝ)*G*(∑ r ∈ Q,w r) := by + calc + _ = ∑ q ∈ D,∑ _r ∈ Q,w q := by + simp only [Finset.sum_const,nsmul_eq_mul,← Finset.mul_sum] + _ ≤ ∑ q ∈ D,∑ r ∈ Q,G*w r := + Finset.sum_le_sum (fun q hq => Finset.sum_le_sum (fun r hr => hspread q (hD hq) r hr)) + _ = _ := by + simp only [← Finset.mul_sum,Finset.sum_const,nsmul_eq_mul] + ring + calc + _ ≤ ((D.card : ℝ)*G*(∑ r ∈ Q,w r))/(Q.card : ℝ) := + (le_div_iff₀ hQpos).mpr (by nlinarith [hdouble]) + _ = _ := by ring + +theorem discarded_weight_bound {ι : Type*} [Fintype ι] + (Q : Finset ℕ) (label : ℕ → ι) (tau : ℝ) (htau : 0 ≤ tau) (hQ : 0 < Q.card) + (w : ℕ → ℝ) (hw : ∀ q ∈ Q,0 ≤ w q) (G : ℝ) (hG : 0 ≤ G) + (hspread : ∀ q ∈ Q,∀ r ∈ Q,w q ≤ G*w r) : + (∑ q ∈ discardedPoints Q label tau,w q) ≤ + ((Fintype.card ι : ℝ)*tau*G/(Q.card : ℝ))*(∑ q ∈ Q,w q) := by + have hsum : 0 ≤ ∑ q ∈ Q,w q := Finset.sum_nonneg hw + have hcard := discardedPoints_card_bound Q label tau htau + calc + _ ≤ (((discardedPoints Q label tau).card : ℝ)*G/(Q.card : ℝ))*(∑ q ∈ Q,w q) := + subset_weight_spread Q _ (discardedPoints_subset Q label tau) hQ w G hspread + _ ≤ _ := mul_le_mul_of_nonneg_right + (div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hcard hG) (Nat.cast_nonneg _)) hsum + +end ErdosInverseCells + +end + +section + +open _root_.Filter _root_.Erdos970.Filter +open scoped Topology +namespace ErdosInverseCells +open ErdosCofactorChoices ErdosInverseBoxHeight ErdosInverseEuler +open NumberTheoryLean.LogarithmicBinScale + +noncomputable def initialDiscarded (Q : Finset ℕ) (a : ℕ → ℕ) (B xi : ℝ) (k : ℕ) (w Z : ℝ) : Finset ℕ := by + letI : NeZero (smallModulus w) := ⟨(smallModulus_pos w).ne'⟩ + exact discardedPoints Q (initialLabel a B xi k (smallModulus w)) (B/Z) + +theorem source_initial_discard_power (C xi eps : ℝ) (hC : 0 ≤ C) (hxi : 0 < xi) + (hxi1 : xi ≤ 1) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop,∀ (m : Fin (binCount (sourceW z) z xi) → ℕ) (a : ℕ → ℕ), + ((∑ i,m i : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + let k := ∑ i,m i + (∑ q ∈ initialDiscarded Q a S xi k (sourceW z) (sourceZ z),(q : ℝ)⁻¹) ≤ + (sourceZ z)^(3*eps-1)*(∑ q ∈ Q,(q : ℝ)⁻¹) := by + filter_upwards [source_cofactor_cell_data C xi eps hC hxi hxi1 heps, + source_initial_label_count C eps hC heps,source_cofactor_weight_variation C xi eps hC hxi hxi1 heps] + with z hc hl hw + intro m a hm + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + let k := ∑ i,m i + let : NeZero (smallModulus (sourceW z)) := ⟨(smallModulus_pos _).ne'⟩ + have hdata := hc m hm + have hZ : 0 < sourceZ z := Real.exp_pos _ + have hlabel : (Fintype.card (InitialLabel k (smallModulus (sourceW z))) : ℝ) ≤ (sourceZ z)^eps := by + rw [initialLabel_card] + exact hl k hm + have hspread : ∀ q ∈ Q,∀ r ∈ Q,(q : ℝ)⁻¹ ≤ (sourceZ z)^eps*(r : ℝ)⁻¹ := + fun q hq r hr => (hw m hm q r hq hr).2 + have hmass : 0 ≤ ∑ q ∈ Q,(q : ℝ)⁻¹ := by positivity + have hdiscard := discarded_weight_bound Q (initialLabel a S xi k (smallModulus (sourceW z))) + (S/sourceZ z) (div_pos hdata.1 hZ).le hdata.2.1 (fun q => (q : ℝ)⁻¹) + (fun _ _ => by positivity) ((sourceZ z)^eps) (Real.rpow_nonneg hZ.le _) hspread + have hcoef := discard_coefficient_bound S (sourceZ z) eps Q.card + (Fintype.card (InitialLabel k (smallModulus (sourceW z)))) hdata.1 hZ hdata.2.2.1 hlabel + exact hdiscard.trans (mul_le_mul_of_nonneg_right hcoef hmass) + +theorem source_initial_discard_small (C xi tolerance : ℝ) (hC : 0 ≤ C) (hxi : 0 < xi) + (hxi1 : xi ≤ 1) (ht : 0 < tolerance) : + ∀ᶠ z : ℝ in atTop,∀ (m : Fin (binCount (sourceW z) z xi) → ℕ) (a : ℕ → ℕ), + ((∑ i,m i : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + let k := ∑ i,m i + (∑ q ∈ initialDiscarded Q a S xi k (sourceW z) (sourceZ z),(q : ℝ)⁻¹) ≤ + tolerance*(∑ q ∈ Q,(q : ℝ)⁻¹) := by + have hT := (tendsto_rpow_neg_atTop (by norm_num : (0 : ℝ) < 5/8)).comp sourceZ_tendsto_atTop + have hs := (tendsto_order.mp hT).2 tolerance ht + filter_upwards [source_initial_discard_power C xi (1/8) hC hxi hxi1 (by norm_num),hs] with z hc hz + intro m a hm + have hh := hc m a hm + norm_num only at hh + have hz' : (sourceZ z)^(-((5 : ℝ)/8)) < tolerance := hz + have hp : (sourceZ z)^(-((5 : ℝ)/8)) ≤ tolerance := by linarith + exact hh.trans (mul_le_mul_of_nonneg_right hp (by positivity)) + +end ErdosInverseCells + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceLargePairBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceLargePairBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..8fd8a9cb8d71824ce1a81f8ba0b6390e955eb435 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceLargePairBound.lean @@ -0,0 +1,313 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.OriginalPairSieve + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosVarianceLargeCount +open NumberTheoryLean ErdosHyperbolaError ErdosPrimeInputs.PrimeProductOmissions +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem finite_large_pair_bound : ∃ C : ℝ,0 < C ∧ ∀ᶠ R : ℝ in atTop,1 < R ∧ + ∀ (H T0 T1 : ℕ),2 ≤ H → 0 < T0 → 0 < T1 → Squarefree T0 → + (∀ t : ℕ,t.Prime → t ∣ T0 → t ∣ H) → T1.Coprime (H*T0) → + ∀ (C0 k0 p0 p1 m1 : ℤ),Int.gcd C0 (H : ℤ) = 1 → Int.gcd p0 (T0 : ℤ) = 1 → + Int.gcd p1 (T1 : ℤ) = 1 → + ∀ (x0 x1 y0 y1 : ℝ),x0 ≤ x1 → y0 ≤ y1 → y1-y0 ≤ 2*(H : ℝ) → + ∀ (lcI rcI lcJ rcJ : Bool), + ((siftedSourcePairs H T0 T1 C0 k0 p0 p1 m1 x0 x1 y0 y1 lcI rcI lcJ rcJ + (reducedPrimes ⌊largeSieveCutoff R⌋₊ (H*T1))).card : ℝ) ≤ + C*(x1-x0)/((patternCard T0 T1 : ℝ)*Real.log R)+ + hyperbolaEnvelope H T0*(2*R^((1 : ℝ)/10)*(1+(y1-y0)/((H*T0 : ℕ) : ℝ))+ + ((x1-x0)/((H*T0 : ℕ) : ℝ))*(1+Real.log (R^((1 : ℝ)/10)))) := by + obtain ⟨C,hC,hmain⟩ := source_main_R_upper + refine ⟨C,hC,?_⟩ + filter_upwards [hmain] with R hR + refine ⟨hR.1,?_⟩ + intro H T0 T1 hH hT0 hT1 hSF hsupport hT1N C0 k0 p0 p1 m1 hC0 hp0 hp1 + x0 x1 y0 y1 hx hy hVH lcI rcI lcJ rcJ + have hH0 : 0 < H := by omega + have hq : 0 < H*T1 := mul_pos hH0 hT1 + let P := reducedPrimes ⌊largeSieveCutoff R⌋₊ (H*T1) + have hP (t : ℕ) (ht : t ∈ P) : t.Prime := + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_sdiff.mp ht).1).1 + have hPv (t : ℕ) (ht : t ∈ P) : (t : ℝ) ≤ largeSieveCutoff R := + (Nat.le_floor_iff (by linarith [hR.2.1])).mp + (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_sdiff.mp ht).1).2 + have hPcop (t : ℕ) (ht : t ∈ P) : t.Coprime (H*T1) := by + apply (hP t ht).coprime_iff_not_dvd.mpr + intro hdiv + exact (Finset.mem_sdiff.mp ht).2 (Nat.mem_primeFactors.mpr ⟨hP t ht,hdiv,hq.ne'⟩) + have hb := source_pair_sieve_upper H T0 T1 hH hT0 hT1 hSF hsupport hT1N C0 k0 p0 p1 m1 + hC0 hp0 hp1 P hP hPcop (largeSieveCutoff R) largeSieveLevel hR.2.1 (by norm_num [largeSieveLevel]) hPv + x0 x1 y0 y1 hx hy lcI rcI lcJ rcJ + have hT0H := source_restriction_divides H T0 hH0 hSF hsupport + have hcop : H.Coprime T1 := hT1N.symm.of_dvd_left (dvd_mul_right H T0) + have hm := hR.2.2 H T0 T1 hH0 hT0 hT1 hT0H hcop (x1-x0) (y1-y0) + (sub_nonneg.mpr hx) (sub_nonneg.mpr hy) hVH + have hD : 1 ≤ (largeSieveCutoff R)^largeSieveLevel := + Real.one_le_rpow (by linarith [hR.2.1]) (by norm_num [largeSieveLevel]) + have he := hyperbola_level_sum_bound H T0 P (largeSieveCutoff R) largeSieveLevel + (x1-x0) (y1-y0) hD (sub_nonneg.mpr hx) (sub_nonneg.mpr hy) + rw [largeSieveCutoff_level R (by linarith [hR.1])] at he + exact hb.trans (add_le_add hm he) + +end ErdosVarianceLargeCount + +end + +section + +open _root_.Filter +namespace ErdosVarianceLargeScale +open NumberTheoryLean ErdosHyperbolaError ErdosHyperbolaWeighted ErdosVarianceLargeCount + ErdosInverseBoxHeight ErdosInverseEuler ErdosVarianceSmallModel + +noncomputable def slowHyperbolaFactor (N T0 : ℕ) : ℝ := + completionConstant*(N.divisors.card : ℝ)^3*(Real.log (2*(N : ℝ)))^2*Real.sqrt T0 + +theorem hyperbolaEnvelope_factor (H T0 : ℕ) : + hyperbolaEnvelope H T0 = slowHyperbolaFactor (H*T0) T0*((H*T0 : ℕ) : ℝ)^((3 : ℝ)/4) := by + unfold hyperbolaEnvelope slowHyperbolaFactor + ring + +theorem source_hyperbola_scales (alpha : ℝ) (halpha : 0 < alpha) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ (R : ℝ),z^alpha ≤ R → + ∀ (H T0 : ℕ),1 ≤ H → 1 ≤ T0 → + (H : ℝ) ≤ R*(sourceZ z)^11 → T0 ≤ smallModulus (sourceW z) → + 1 < R ∧ ((H*T0 : ℕ) : ℝ) ≤ R^((101 : ℝ)/100) ∧ + slowHyperbolaFactor (H*T0) T0 ≤ R^((1 : ℝ)/100) := by + obtain ⟨A,hA,hdiv⟩ := divisor_log_square_subpower 3 (by norm_num : (0 : ℝ) < 1/1000) + let C := completionConstant*A + have hconst := ((tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 3/1000)).comp + (tendsto_rpow_atTop halpha)).eventually_ge_atTop C + filter_upwards [source_Z_power_R alpha (1/100) 12 halpha (by norm_num) (by decide), + source_Z_power_R alpha (1/100) 1 halpha (by norm_num) (by decide), + smallModulus_source_power 1 1 zero_lt_one,hconst] + with z hZ12 hZ1 hM hconstz + refine ⟨hZ12.1,?_⟩ + intro R hRlo H T0 hH hT0 hHhi hT0M + have hz0 : 0 < z := by linarith [hZ12.1] + have hR1 : 1 < R := (Real.one_lt_rpow hZ12.1 halpha).trans_le hRlo + have hR : 0 < R := by linarith + have hZ : 0 < sourceZ z := Real.exp_pos _ + have hMZ : (smallModulus (sourceW z) : ℝ) ≤ sourceZ z := by + simpa only [pow_one,Real.rpow_one] using hM + have hT0Z : (T0 : ℝ) ≤ sourceZ z := (by exact_mod_cast hT0M : (T0 : ℝ) ≤ smallModulus (sourceW z)).trans hMZ + have hT0R : (T0 : ℝ) ≤ R^((1 : ℝ)/100) := hT0Z.trans (by + simpa only [pow_one] using hZ1.2 R hRlo) + have hN : ((H*T0 : ℕ) : ℝ) ≤ R^((101 : ℝ)/100) := by + calc + _ = (H : ℝ)*(T0 : ℝ) := Nat.cast_mul _ _ + _ ≤ (R*(sourceZ z)^11)*sourceZ z := mul_le_mul hHhi hT0Z (Nat.cast_nonneg _) (by positivity) + _ = R*(sourceZ z)^12 := by ring + _ ≤ R*R^((1 : ℝ)/100) := mul_le_mul_of_nonneg_left (hZ12.2 R hRlo) hR.le + _ = R^(1 : ℝ)*R^((1 : ℝ)/100) := by rw [Real.rpow_one] + _ = _ := by rw [← Real.rpow_add hR];norm_num + have hN1 : 1 ≤ H*T0 := Nat.one_le_iff_ne_zero.mpr (mul_ne_zero (by omega) (by omega)) + have hN2 : ((H*T0 : ℕ) : ℝ) ≤ R^(2 : ℝ) := + hN.trans (Real.rpow_le_rpow_of_exponent_le hR1.le (by norm_num)) + have hNp : (((H*T0 : ℕ) : ℝ)^((1 : ℝ)/1000)) ≤ R^((1 : ℝ)/500) := by + calc + _ ≤ (R^(2 : ℝ))^((1 : ℝ)/1000) := Real.rpow_le_rpow (Nat.cast_nonneg _) hN2 (by norm_num) + _ = _ := by rw [← Real.rpow_mul hR.le];norm_num + have hsqrt : Real.sqrt T0 ≤ R^((1 : ℝ)/200) := by + calc + _ ≤ Real.sqrt (R^((1 : ℝ)/100)) := Real.sqrt_le_sqrt hT0R + _ = _ := by rw [Real.sqrt_eq_rpow,← Real.rpow_mul hR.le];norm_num + have hC : C ≤ R^((3 : ℝ)/1000) := + hconstz.trans (Real.rpow_le_rpow (Real.rpow_nonneg hz0.le alpha) hRlo (by norm_num)) + have hfactor : slowHyperbolaFactor (H*T0) T0 ≤ R^((1 : ℝ)/100) := by + calc + _ = completionConstant*((H*T0).divisors.card : ℝ)^3* + (Real.log (2*((H*T0 : ℕ) : ℝ)))^2*Real.sqrt T0 := rfl + _ ≤ completionConstant*(A*(((H*T0 : ℕ) : ℝ)^((1 : ℝ)/1000)))*Real.sqrt T0 := by + exact mul_le_mul_of_nonneg_right (by + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left (hdiv (H*T0) hN1) completionConstant_pos.le) + (Real.sqrt_nonneg _) + _ = C*(((H*T0 : ℕ) : ℝ)^((1 : ℝ)/1000))*Real.sqrt T0 := by dsimp [C];ring + _ ≤ R^((3 : ℝ)/1000)*R^((1 : ℝ)/500)*R^((1 : ℝ)/200) := by + exact mul_le_mul (mul_le_mul hC hNp (Real.rpow_nonneg (Nat.cast_nonneg _) _) (by positivity)) + hsqrt (Real.sqrt_nonneg _) (by positivity) + _ = _ := by rw [← Real.rpow_add hR,← Real.rpow_add hR];norm_num + exact ⟨hR1,hN,hfactor⟩ + +end ErdosVarianceLargeScale + +end + + +namespace ErdosVarianceLargeScale + +theorem large_error_algebra (R N F U V : ℝ) (hR : 1 < R) (hN : 0 < N) + (_hFlow : 0 ≤ F) (hF : F ≤ R^((1 : ℝ)/100)) + (hNlo : R^((4 : ℝ)/5) ≤ N) (hNhi : N ≤ R^((101 : ℝ)/100)) + (hU : 0 ≤ U) (hUR : U ≤ R) (hV : 0 ≤ V) (hVN : V ≤ 2*N) + (hlog : 1+Real.log (R^((1 : ℝ)/10)) ≤ 2*R^((1 : ℝ)/20)) + (hconstant : 8 ≤ R^((1 : ℝ)/40)) : + F*N^((3 : ℝ)/4)*(2*R^((1 : ℝ)/10)*(1+V/N)+(U/N)*(1+Real.log (R^((1 : ℝ)/10)))) ≤ + R^((9 : ℝ)/10) := by + have hR0 : 0 < R := by linarith + have hNp : N^((3 : ℝ)/4) ≤ R^((303 : ℝ)/400) := by + calc + _ ≤ (R^((101 : ℝ)/100))^((3 : ℝ)/4) := Real.rpow_le_rpow hN.le hNhi (by norm_num) + _ = _ := by rw [← Real.rpow_mul hR0.le];norm_num + have hVdiv : V/N ≤ 2 := (div_le_iff₀ hN).mpr hVN + have hfirst : F*N^((3 : ℝ)/4)*(2*R^((1 : ℝ)/10)*(1+V/N)) ≤ 6*R^((347 : ℝ)/400) := by + have hfac : 2*R^((1 : ℝ)/10)*(1+V/N) ≤ 6*R^((1 : ℝ)/10) := by + have hh := mul_le_mul_of_nonneg_left (show 1+V/N ≤ 3 by linarith) + (show 0 ≤ 2*R^((1 : ℝ)/10) by positivity) + nlinarith + calc + _ ≤ (R^((1 : ℝ)/100)*R^((303 : ℝ)/400))*(6*R^((1 : ℝ)/10)) := + mul_le_mul (mul_le_mul hF hNp (Real.rpow_nonneg hN.le _) (by positivity)) hfac + (by positivity) (by positivity) + _ = 6*(R^((1 : ℝ)/100)*R^((303 : ℝ)/400)*R^((1 : ℝ)/10)) := by ring + _ = _ := by rw [← Real.rpow_add hR0,← Real.rpow_add hR0];norm_num + have hNroot : R^((1 : ℝ)/5) ≤ N^((1 : ℝ)/4) := by + have hh := Real.rpow_le_rpow (Real.rpow_nonneg hR0.le _) hNlo (by norm_num : (0 : ℝ) ≤ 1/4) + rw [← Real.rpow_mul hR0.le] at hh + norm_num at hh + exact hh + have hratio : N^((3 : ℝ)/4)/N ≤ 1/R^((1 : ℝ)/5) := by + have he : N^((3 : ℝ)/4)/N = 1/N^((1 : ℝ)/4) := by + apply (div_eq_div_iff hN.ne' (Real.rpow_pos_of_pos hN _).ne').mpr + rw [← Real.rpow_add hN] + norm_num + rw [he] + exact div_le_div_of_nonneg_left zero_le_one (Real.rpow_pos_of_pos hR0 _) hNroot + have hlog0 : 0 ≤ 1+Real.log (R^((1 : ℝ)/10)) := by + have hh := Real.log_nonneg (Real.one_le_rpow hR.le (by norm_num : (0 : ℝ) ≤ 1/10)) + linarith + have hsecond : F*N^((3 : ℝ)/4)*((U/N)*(1+Real.log (R^((1 : ℝ)/10)))) ≤ 2*R^((43 : ℝ)/50) := by + calc + _ = (F*U)*(N^((3 : ℝ)/4)/N)*(1+Real.log (R^((1 : ℝ)/10))) := by ring + _ ≤ ((R^((1 : ℝ)/100)*R)*(1/R^((1 : ℝ)/5)))*(2*R^((1 : ℝ)/20)) := + mul_le_mul + (mul_le_mul (mul_le_mul hF hUR hU (by positivity)) hratio (by positivity) (by positivity)) + hlog hlog0 (by positivity) + _ = 2*((R^((1 : ℝ)/100)*R^(1 : ℝ)/R^((1 : ℝ)/5))*R^((1 : ℝ)/20)) := by + rw [Real.rpow_one] + ring + _ = _ := by rw [← Real.rpow_add hR0,← Real.rpow_sub hR0,← Real.rpow_add hR0];norm_num + have hp1 : R^((347 : ℝ)/400) ≤ R^((7 : ℝ)/8) := Real.rpow_le_rpow_of_exponent_le hR.le (by norm_num) + have hp2 : R^((43 : ℝ)/50) ≤ R^((7 : ℝ)/8) := Real.rpow_le_rpow_of_exponent_le hR.le (by norm_num) + have hsum : F*N^((3 : ℝ)/4)*(2*R^((1 : ℝ)/10)*(1+V/N)+(U/N)*(1+Real.log (R^((1 : ℝ)/10)))) ≤ + 8*R^((7 : ℝ)/8) := by + rw [mul_add] + nlinarith + apply hsum.trans + calc + _ ≤ R^((1 : ℝ)/40)*R^((7 : ℝ)/8) := mul_le_mul_of_nonneg_right hconstant (by positivity) + _ = _ := by rw [← Real.rpow_add hR0];norm_num + +end ErdosVarianceLargeScale + + +section + +open _root_.Filter +namespace ErdosVarianceLargeScale + +theorem eventual_large_error_budgets : ∀ᶠ R : ℝ in atTop,1 < R ∧ + 1+Real.log (R^((1 : ℝ)/10)) ≤ 2*R^((1 : ℝ)/20) ∧ 8 ≤ R^((1 : ℝ)/40) := by + have hlog := (isLittleO_log_rpow_rpow_atTop (1 : ℝ) (by norm_num : (0 : ℝ) < 1/20)).bound zero_lt_one + filter_upwards [hlog,(tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 1/40)).eventually_ge_atTop 8, + eventually_gt_atTop (1 : ℝ)] with R hlog hconstant hR + have hR0 : 0 < R := by linarith + have hlog0 : 0 ≤ Real.log R := (Real.log_pos hR).le + have hl : Real.log R ≤ R^((1 : ℝ)/20) := by + simpa only [Real.rpow_one,Real.norm_eq_abs,abs_of_nonneg hlog0, + abs_of_nonneg (Real.rpow_nonneg hR0.le _),one_mul] using hlog + have hone : 1 ≤ R^((1 : ℝ)/20) := Real.one_le_rpow hR.le (by norm_num) + refine ⟨hR,?_,hconstant⟩ + rw [Real.log_rpow hR0] + nlinarith + +end ErdosVarianceLargeScale + +end + +section + +open _root_.Filter +namespace ErdosVarianceLargeScale +open NumberTheoryLean ErdosHyperbolaError ErdosVarianceLargeCount + ErdosInverseBoxHeight ErdosInverseEuler ErdosVarianceSmallModel + +theorem source_large_error (alpha : ℝ) (halpha : 0 < alpha) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ (R : ℝ),z^alpha ≤ R → + ∀ (H T0 : ℕ),1 ≤ H → 1 ≤ T0 → + R^((4 : ℝ)/5) ≤ (H : ℝ) → (H : ℝ) ≤ R*(sourceZ z)^11 → T0 ≤ smallModulus (sourceW z) → + ∀ (U V : ℝ),0 ≤ U → U ≤ R → 0 ≤ V → V ≤ 2*(H : ℝ) → + hyperbolaEnvelope H T0*(2*R^((1 : ℝ)/10)*(1+V/((H*T0 : ℕ) : ℝ))+ + (U/((H*T0 : ℕ) : ℝ))*(1+Real.log (R^((1 : ℝ)/10)))) ≤ R^((9 : ℝ)/10) := by + obtain ⟨R0,hR0⟩ := eventually_atTop.mp eventual_large_error_budgets + filter_upwards [source_hyperbola_scales alpha halpha,(tendsto_rpow_atTop halpha).eventually_ge_atTop R0] + with z hscale hzR + refine ⟨hscale.1,?_⟩ + intro R hRlo H T0 hH hT0 hHlo hHhi hT0M U V hU hUR hV hVH + have hs := hscale.2 R hRlo H T0 hH hT0 hHhi hT0M + have hb := hR0 R (hzR.trans hRlo) + have hHN : (H : ℝ) ≤ ((H*T0 : ℕ) : ℝ) := by + have ht : (1 : ℝ) ≤ T0 := by exact_mod_cast hT0 + have hh := mul_le_mul_of_nonneg_left ht (Nat.cast_nonneg H) + simpa only [mul_one,Nat.cast_mul] using hh + have hN : (0 : ℝ) < ((H*T0 : ℕ) : ℝ) := by + exact_mod_cast mul_pos (show 0 < H by omega) (show 0 < T0 by omega) + have hF : 0 ≤ slowHyperbolaFactor (H*T0) T0 := by + have hc := completionConstant_pos.le + dsimp [slowHyperbolaFactor] + positivity + rw [hyperbolaEnvelope_factor] + exact large_error_algebra R ((H*T0 : ℕ) : ℝ) (slowHyperbolaFactor (H*T0) T0) U V + hs.1 hN hF hs.2.2 (hHlo.trans hHN) hs.2.1 hU hUR hV + (hVH.trans (mul_le_mul_of_nonneg_left hHN (by norm_num))) hb.2.1 hb.2.2 + +end ErdosVarianceLargeScale + +end + + +open _root_.Filter +namespace ErdosVarianceLargeScale +open NumberTheoryLean ErdosHyperbolaError ErdosVarianceLargeCount + ErdosInverseBoxHeight ErdosInverseEuler ErdosPrimeInputs.PrimeProductOmissions + +theorem source_large_pair_bound (alpha : ℝ) (halpha : 0 < alpha) : + ∃ C : ℝ,0 < C ∧ ∀ᶠ z : ℝ in atTop,1 < z ∧ + ∀ (R : ℝ),z^alpha ≤ R → ∀ (H T0 T1 : ℕ),2 ≤ H → 0 < T0 → 0 < T1 → + Squarefree T0 → (∀ t : ℕ,t.Prime → t ∣ T0 → t ∣ H) → T1.Coprime (H*T0) → + R^((4 : ℝ)/5) ≤ (H : ℝ) → (H : ℝ) ≤ R*(sourceZ z)^11 → T0 ≤ smallModulus (sourceW z) → + ∀ (C0 k0 p0 p1 m1 : ℤ),Int.gcd C0 (H : ℤ) = 1 → Int.gcd p0 (T0 : ℤ) = 1 → + Int.gcd p1 (T1 : ℤ) = 1 → + ∀ (x0 x1 y0 y1 : ℝ),x0 ≤ x1 → x1-x0 ≤ R → y0 ≤ y1 → y1-y0 ≤ 2*(H : ℝ) → + ∀ (lcI rcI lcJ rcJ : Bool), + ((siftedSourcePairs H T0 T1 C0 k0 p0 p1 m1 x0 x1 y0 y1 lcI rcI lcJ rcJ + (reducedPrimes ⌊largeSieveCutoff R⌋₊ (H*T1))).card : ℝ) ≤ + C*(x1-x0)/((patternCard T0 T1 : ℝ)*Real.log R)+R^((9 : ℝ)/10) := by + obtain ⟨C,hC,hfinite⟩ := finite_large_pair_bound + obtain ⟨R0,hR0⟩ := eventually_atTop.mp hfinite + refine ⟨C,hC,?_⟩ + filter_upwards [source_large_error alpha halpha,(tendsto_rpow_atTop halpha).eventually_ge_atTop R0] + with z herr hzR + refine ⟨herr.1,?_⟩ + intro R hRlo H T0 T1 hH hT0 hT1 hSF hsupport hT1N hHlo hHhi hT0M + C0 k0 p0 p1 m1 hC0 hp0 hp1 x0 x1 y0 y1 hx hUR hy hVH lcI rcI lcJ rcJ + have hb := (hR0 R (hzR.trans hRlo)).2 H T0 T1 hH hT0 hT1 hSF hsupport hT1N C0 k0 p0 p1 m1 + hC0 hp0 hp1 x0 x1 y0 y1 hx hy hVH lcI rcI lcJ rcJ + have he := herr.2 R hRlo H T0 (by omega) hT0 hHlo hHhi hT0M (x1-x0) (y1-y0) + (sub_nonneg.mpr hx) hUR (sub_nonneg.mpr hy) hVH + exact hb.trans (add_le_add le_rfl he) + +end ErdosVarianceLargeScale + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceLowRemoval.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceLowRemoval.lean new file mode 100644 index 0000000000000000000000000000000000000000..1667a369f14ff24d25adef64a495df8183134cc5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceLowRemoval.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CorrectedCompactTransfer + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceLowRemoval + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathMeasures TransitionKernels FinitePathGeometry DerivativeWeights +open RegeneratingInverseBands InvariantInverseWeights ArrivalKernelGeometry +open ContinuousCompactHighError OriginalHarmonicOccupation AdmittedHarmonicPaths LowStateHorizon + +noncomputable def scaleConstant : ℝ := (23/10:ℝ)^2/phiEven (23/10) + +theorem scaleConstant_pos : 0 < scaleConstant := by + unfold scaleConstant + exact div_pos (by norm_num) (phiEven_pos (by norm_num)) + +theorem source_scale_upper {v B : ℝ} (hB : 0 < B) (s : EvenState) (hs : s.1 ≤ 23/10) + (hcut : currentExponent v (.inl s,0) = B) : + (Real.exp v)^2/stateWeight (.inl s) ≤ scaleConstant*B^2 ∧ gapValue v (.inl s,0) ≤ (23/10:ℝ)*B := by + have hs0 : 0 < s.1 := by linarith [s.2] + have he : Real.exp v = B*s.1 := by + change Real.exp (v-0)/s.1 = B at hcut + rw [sub_zero] at hcut + exact (div_eq_iff hs0.ne').mp hcut + have hupper : Real.exp v ≤ (23/10:ℝ)*B := by rw [he]; nlinarith + have hsq : (Real.exp v)^2 ≤ (23/10:ℝ)^2*B^2 := by nlinarith [Real.exp_pos v] + have hφ : 0 < phiEven s.1 := phiEven_pos (by linarith [s.2]) + have hφend : 0 < phiEven (23/10) := phiEven_pos (by norm_num) + have hmono : phiEven (23/10) ≤ phiEven s.1 := + TwoStepDensityBounds.weight_antitone (i:=.even) s.2 (by norm_num [Valid]) hs + have hinv := one_div_le_one_div_of_le hφend hmono + refine ⟨?_,?_⟩ + · change (Real.exp v)^2/phiEven s.1 ≤ _ + calc + _ = (Real.exp v)^2*(1/phiEven s.1) := by ring + _ ≤ ((23/10:ℝ)^2*B^2)*(1/phiEven (23/10)) := mul_le_mul hsq hinv (by positivity) (by positivity) + _ = _ := by unfold scaleConstant; ring + · simpa only [gapValue,sub_zero] using hupper + +theorem source_low_removal {H : Side → ℝ×ℝ → ℝ} + (hH : ∀ i,Continuous (H i)) (hcompact : ∀ i,HasCompactSupport (H i)) + {K : ℝ} (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → H i (r,s)=0) : + ∃ C : ℝ,0 ≤ C ∧ ∀ᶠ B : ℝ in atTop,∀ v ell : ℝ,∀ s : EvenState, + (199/100:ℝ) ≤ s.1 → s.1 ≤ 23/10 → 1 ≤ ell → ell ≤ B → currentExponent v (.inl s,0)=B → + |(∫ z,inverseReward v H z ∂occupation (admittedTilted v ell) (.inl s,0))- + (∫ z,inverseReward v H z ∂occupation (lowKernel costKernel v ell ((Real.log B)^2)) (.inl s,0))| ≤ C/B := by + obtain ⟨A,hA,herror⟩ := compact_high_error_bound hH hcompact hsupport + refine ⟨scaleConstant*A,mul_nonneg scaleConstant_pos.le hA,?_⟩ + filter_upwards [AdmittedHighRemoval.low_gap_high_removal K 3, + eventually_ge_atTop (Real.exp 2)] with B hrem hBexp + intro v ell s _hsL hsU hell hellB hcut + have hB : 0 < B := (Real.exp_pos 2).trans_le hBexp + have hlogB : 2 ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hBexp + have hS : 0 < (Real.log B)^2 := by nlinarith + have hsS : stateRatio (.inl s) ≤ (Real.log B)^2 := by change s.1 ≤ _; nlinarith + have hscale := source_scale_upper hB s hsU hcut + have herr := herror v ell ((Real.log B)^2) B hell hS hB (.inl s) hsS hscale.2 + have hhigh := hrem v ell (.inl s,0) hell hellB hcut + have hsourceScale : ENNReal.ofReal ((Real.exp v)^2/stateWeight (.inl s)) ≤ + ENNReal.ofReal (scaleConstant*B^2) := ENNReal.ofReal_le_ofReal hscale.1 + have hscaled := mul_le_mul hsourceScale (le_refl (ENNReal.ofReal A)) zero_le zero_le + have hbound := herr.trans (mul_le_mul hscaled hhigh zero_le zero_le) + have hid : ENNReal.ofReal (scaleConstant*B^2)*ENNReal.ofReal A*ENNReal.ofReal (B^(-(3:ℝ))) = + ENNReal.ofReal ((scaleConstant*A)/B) := by + rw [← ENNReal.ofReal_mul (mul_nonneg scaleConstant_pos.le (sq_nonneg B)), + ← ENNReal.ofReal_mul (mul_nonneg (mul_nonneg scaleConstant_pos.le (sq_nonneg B)) hA)] + congr 1 + rw [Real.rpow_neg hB.le,Real.rpow_ofNat] + field_simp + rw [hid] at hbound + exact (ENNReal.ofReal_le_ofReal_iff (div_nonneg (mul_nonneg scaleConstant_pos.le hA) hB.le)).mp hbound + +end NumberTheoryLean.SourceLowRemoval + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceMarginalRate.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceMarginalRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..684ca972db14f369b6776bf037276f176c3ebcd7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceMarginalRate.lean @@ -0,0 +1,142 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.BudgetPolynomialBound +import OAI.NumberTheory.Jacobsthal.Partitions.HorizonMeshSmallness +import OAI.NumberTheory.Jacobsthal.Primes.PrimeMarginalInduction + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.UniformBudgetRate + +open _root_.Set _root_.Filter +open scoped Topology +open UniformFailureBudget ExponentialMesh BudgetPolynomialBound HorizonMeshSmallness PrimeKilledChain + +theorem uniform_budget_rate {c₁ c₂ C₁ C₂ C₃ D κ A : ℝ} + (hC₁ : 0 ≤ C₁) (hC₂ : 0 ≤ C₂) (hC₃ : 0 ≤ C₃) (hD : 0 ≤ D) (hA : 0 ≤ A) + (hκ : 0 < κ) (hc₁ : 4*κ ≤ c₁) (hc₂ : 2*κ ≤ c₂) (hκr : κ ≤ normalizationRate) : + ∀ᶠ w : ℝ in atTop, ∀ S : ℝ, 0 ≤ S → S ≤ (Real.log w)^3 → ∀ N : ℕ, + (N:ℝ) ≤ A*(Real.log w)^3 → + 2*mesh κ w ≤ 1 ∧ upperDisplacement S (mesh κ w) N+mesh κ w ≤ 1 ∧ + (N:ℝ)*stepBudget c₁ c₂ C₁ C₂ C₃ D w S (mesh κ w) N ≤ + Real.exp (-(κ/2)*Real.sqrt (Real.log w)) := by + filter_upwards [horizon_mesh_smallness hA hD hκ, + log_power_exp_absorption (A*coefficient A C₁ C₂ C₃ D) 21 hκ, + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with w hsmall hpoly hlog + intro S hS hSP N hNP + have hsm := hsmall S hS hSP N hNP + refine ⟨hsm.1,hsm.2.2.2,?_⟩ + have h := budget_polynomial_bound (P:=(Real.log w)^3) N hC₁ hC₂ hC₃ hD hA hκ.le hc₁ hc₂ hκr + (by linarith) (one_le_pow₀ hlog) hS hSP hNP hsm.2.1 hsm.2.2.1 + have hp : ((Real.log w)^3)^7 = (Real.log w)^21 := by ring + rw [hp] at h + exact h.trans hpoly + +theorem source_scale_bound {d w B : ℝ} (hW : d^2 ≤ Real.log w) + (hB : 2 ≤ Real.log B) (hcomp : Real.log B ≤ d*Real.log w) : + (Real.log B)^2 ≤ (Real.log w)^3 ∧ + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B:ℝ) ≤ 5*d^3*(Real.log w)^3 := by + have hlog : 0 ≤ Real.log w := (sq_nonneg d).trans hW + have hpow₂ := pow_le_pow_left₀ (show 0 ≤ Real.log B by linarith) hcomp 2 + have hpow₃ := pow_le_pow_left₀ (show 0 ≤ Real.log B by linarith) hcomp 3 + have hmul := mul_le_mul_of_nonneg_right hW (sq_nonneg (Real.log w)) + have hN := LowStateHorizon.source_horizon_log_cube hB + constructor <;> nlinarith + +end NumberTheoryLean.UniformBudgetRate + +end + +section + +namespace NumberTheoryLean.SourceMarginalRate + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeSideSupport PrimeGridGeometry PrimeGridKernel +open PrimeMarginalInduction MarginalProfiles SourceParentBin ExponentialMesh UniformBudgetRate +open DerivativeWeights LowStateHorizon + +theorem mesh_eventually_small {κ ε : ℝ} (hκ : 0 < κ) (hε : 0 < ε) : + ∀ᶠ w : ℝ in atTop, mesh κ w ≤ ε := by + have ht := log_power_exp_tendsto 1 0 hκ + filter_upwards [ht.eventually (eventually_lt_nhds hε)] with w hw + have he : Real.exp (-κ*Real.sqrt (Real.log w)) < ε := by simpa only [pow_zero,one_mul] using hw + exact (mesh_upper κ w).trans he.le + +theorem source_discrete_marginals : ∃ κ₀ C : ℝ, 0 < κ₀ ∧ 0 < C ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∀ d : ℝ, 0 < d → ∃ w₀ : ℝ, 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell B : ℝ, ∀ start : Node, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + let S := (Real.log B)^2 + let N := sourceHorizon S B + let m := ⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊ + (∀ n,IsProbabilityMeasure (pathLaw w ell S start n)) ∧ + (∀ j,Valid .odd (point m j) → mass w ell S start m 1 j ≤ + ENNReal.ofReal (C*width m*W (point m j)*weight .odd (point m j))) ∧ + (∀ n,2 ≤ n → n ≤ N → ∀ j,lowerIndex m (sideAfter .even n) ≤ j → mass w ell S start m n j ≤ + ENNReal.ofReal (C*width m*weight (sideAfter .even n) (point m j)*profile m (sideAfter .even n) (point m j))) := by + obtain ⟨κ₀,L,hκ₀,hL,hprofiles⟩ := finite_marginal_profiles + have hCpos := initialConstant_pos + refine ⟨κ₀,48*initialConstant,hκ₀,by positivity,?_⟩ + intro κ hκ hκle d hd + obtain ⟨wP,hwP,hprofiles⟩ := hprofiles κ hκ hκle + let A := 5*d^3 + have hA : 0 ≤ A := by dsimp [A]; positivity + have hevent := (MarginalGrowth.factor_power_bounded hA hL.le hκ).and + ((mesh_eventually_small hκ (by norm_num : (0:ℝ) < 1/100)).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2)))) + obtain ⟨W₀,hW₀⟩ := eventually_atTop.mp hevent + refine ⟨max wP W₀,hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hell _hB hlogB hcomp hr hi h199 h23 + dsimp only + let S := (Real.log B)^2 + let N := sourceHorizon S B + let m := ⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊ + have hwe := hW₀ w ((le_max_right _ _).trans hw) + have hscale := source_scale_bound hwe.2.2 hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hS : S ≤ (Real.log w)^3 := hscale.1 + have hN : (N:ℝ) ≤ A*(Real.log w)^3 := hscale.2 + have hm : 1 ≤ m := Nat.ceil_pos.mpr (Real.exp_pos _) + have hmesh : width m = mesh κ w := rfl + have hsmall : width m ≤ 1/100 := by rw [hmesh]; exact hwe.2.1 + have hp := hprofiles w ((le_max_left _ _).trans hw) ell S hS3 hS start hell hr hi h199 h23 m hm hmesh hsmall + have hC0 := initialConstant_pos.le + have hwidth := width_nonneg m + have hNpos : 1 ≤ N := by dsimp [N,sourceHorizon]; omega + have hOne : (1:ℝ) ≤ A*(Real.log w)^3 := by + have h : ((1:ℕ):ℝ) ≤ (N:ℝ) := by exact_mod_cast hNpos + simpa only [Nat.cast_one] using h.trans hN + have hG : MarginalGrowth.factor L κ w S ≤ 2 := by + simpa only [pow_one] using hwe.1 S hS0 hS 1 (by simpa only [Nat.cast_one] using hOne) + refine ⟨hp.1,?_,?_⟩ + · intro j hjV + have hb := hp.2.1 j hjV + have hWt := (WeightFutureIntegrals.W_pos (valid_pos hjV)).le + have hφ := (weight_pos hjV).le + have hC : initialConstant*MarginalGrowth.factor L κ w S ≤ 48*initialConstant := by nlinarith + exact hb.trans (ENNReal.ofReal_le_ofReal + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hC hwidth) hWt) hφ)) + · intro n hn2 hnN j hj + have hb := hp.2.2 n hn2 j hj + have hn : (n:ℝ) ≤ A*(Real.log w)^3 := (show (n:ℝ) ≤ (N:ℝ) by exact_mod_cast hnN).trans hN + have hGn := hwe.1 S hS0 hS n hn + have hφ := (weight_pos (index_valid hm (sideAfter .even n) hj)).le + have hProf := profile_nonneg m (index_regular hm (sideAfter .even n) hj) + have hC : (24*initialConstant)*(MarginalGrowth.factor L κ w S)^n ≤ 48*initialConstant := by nlinarith + exact hb.trans (ENNReal.ofReal_le_ofReal + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hC hwidth) hφ) hProf)) + +end NumberTheoryLean.SourceMarginalRate + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourcePairRemainder.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourcePairRemainder.lean new file mode 100644 index 0000000000000000000000000000000000000000..5184b50fa1ebd1ed795b6c9fbf7760eaee657caa --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourcePairRemainder.lean @@ -0,0 +1,483 @@ +import Mathlib.Data.Nat.Squarefree +import Mathlib.Data.Nat.Totient +import Mathlib.Data.ZMod.Units +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Harmonic.NormalizedSpectralError +import OAI.NumberTheory.Jacobsthal.Harmonic.ZeroFrequencyBounds +import OAI.NumberTheory.Jacobsthal.Sieve.EulerProductRatio + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHyperbolaError + +theorem source_restriction_divides (H T : ℕ) (hH : 0 < H) (hT : Squarefree T) + (hsupport : ∀ p : ℕ, p.Prime → p ∣ T → p ∣ H) : T ∣ H := by + apply (Nat.factorization_le_iff_dvd hT.ne_zero hH.ne').mp + intro p + by_cases hp : p.Prime + · by_cases hz : T.factorization p = 0 + · rw [hz] + exact Nat.zero_le _ + · have hpd : p ∣ T := (hp.dvd_iff_one_le_factorization hT.ne_zero).mpr (Nat.pos_of_ne_zero hz) + exact (hT.natFactorization_le_one p).trans + ((hp.dvd_iff_one_le_factorization hH.ne').mp (hsupport p hp hpd)) + · rw [Nat.factorization_eq_zero_of_not_prime _ hp] + exact Nat.zero_le _ + +theorem source_dilation_coprime (H T T1 l : ℕ) (hTH : T ∣ H) (hl : l.Coprime (H*T1)) : + l.Coprime (H*T) ∧ l.Coprime T1 := by + obtain ⟨hlH, hlT1⟩ := Nat.coprime_mul_iff_right.mp hl + have hlT : l.Coprime T := Nat.Coprime.of_dvd_right hTH hlH + exact ⟨hlH.mul_right hlT, hlT1⟩ + +theorem source_product_coprime (H T : ℕ) (hTH : T ∣ H) (C0 k0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) : + IsCoprime (C0+(H : ℤ)*k0) ((H*T : ℕ) : ℤ) := by + have hCH : Int.gcd (C0+(H : ℤ)*k0) (H : ℤ) = 1 := by + rw [add_comm C0, Int.gcd_mul_left_add_left] + exact hC0 + have hcop : (C0+(H : ℤ)*k0).natAbs.Coprime H := by + rw [Nat.coprime_iff_gcd_eq_one] + simpa only [Int.gcd_def, Int.natAbs_natCast] using hCH + have hdiv : H*T ∣ H^2 := by + simpa only [pow_two] using Nat.mul_dvd_mul_left H hTH + have hcopN : (C0+(H : ℤ)*k0).natAbs.Coprime (H*T) := + Nat.Coprime.of_dvd_right hdiv (hcop.pow_right 2) + apply Int.isCoprime_iff_gcd_eq_one.mpr + simpa only [Int.gcd_def, Int.natAbs_natCast] using hcopN.gcd_eq_one + +theorem source_totient_product (H T : ℕ) (hTH : T ∣ H) (hT : 0 < T) : + (H*T).totient = T*H.totient := by + have h := Nat.totient_gcd_mul_totient_mul H T + rw [Nat.gcd_eq_right_iff_dvd.mpr hTH] at h + have he : T.totient*(H*T).totient = T.totient*(T*H.totient) := by + calc + _ = H.totient*T.totient*T := h + _ = _ := by ring + exact Nat.eq_of_mul_eq_mul_left (Nat.totient_pos.mpr hT) he + +end ErdosHyperbolaError + +end + +section + +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +noncomputable def reducedProduct (N l : ℕ) (hlN : l.Coprime N) (c : (ZMod N)ˣ) : (ZMod N)ˣ := + (ZMod.unitOfCoprime l hlN)⁻¹*c + +noncomputable def reducedClass (N T l : ℕ) (hT : T ∣ N) (hlN : l.Coprime N) + (a : (ZMod T)ˣ) : (ZMod T)ˣ := + (ZMod.unitsMap hT (ZMod.unitOfCoprime l hlN))⁻¹*a + +noncomputable def dilatedPairs (N T : ℕ) [NeZero N] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (P Q : ProgressionInterval) (l : ℕ) : Finset (ℤ × ℤ) := + (hyperbolaPairs N T a c P.points Q.points).filter fun xy => (l : ℤ) ∣ xy.1 + +theorem mem_dilatePair_iff (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (P Q : ProgressionInterval) + (l : ℕ) (hl : 0 < l) (hlN : l.Coprime N) (hlP : l.Coprime P.step) (x y : ℤ) : + dilatePair l (x,y) ∈ hyperbolaPairs N T a c P.points Q.points ↔ + (x,y) ∈ hyperbolaPairs N T (reducedClass N T l hT hlN a) (reducedProduct N l hlN c) + (pulledInterval P l hlP).points Q.points := by + have hprod : (((l : ℤ)*x : ℤ) : ZMod N)*(y : ZMod N) = (c : ZMod N) ↔ + (x : ZMod N)*(y : ZMod N) = (reducedProduct N l hlN c : ZMod N) := by + simp only [Int.cast_mul, Int.cast_natCast, reducedProduct, Units.val_mul] + rw [← ZMod.coe_unitOfCoprime l hlN, mul_assoc, unit_mul_eq_iff] + have hmap : (ZMod.unitsMap hT (ZMod.unitOfCoprime l hlN) : ZMod T) = (l : ZMod T) := by + change (ZMod.castHom hT (ZMod T)) (ZMod.unitOfCoprime l hlN : ZMod N) = _ + rw [ZMod.coe_unitOfCoprime, map_natCast] + have hclass : (((l : ℤ)*x : ℤ) : ZMod T) = (a : ZMod T) ↔ + (x : ZMod T) = (reducedClass N T l hT hlN a : ZMod T) := by + simp only [Int.cast_mul, Int.cast_natCast, reducedClass, Units.val_mul] + rw [← hmap, unit_mul_eq_iff] + simp only [hyperbolaPairs, Finset.mem_filter, Finset.product_eq_sprod, Finset.mem_product, dilatePair] + rw [hprod, hclass, mem_pulledInterval_iff P l hl hlP x] + +theorem reduced_pairs_image (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (P Q : ProgressionInterval) + (l : ℕ) (hl : 0 < l) (hlN : l.Coprime N) (hlP : l.Coprime P.step) : + (hyperbolaPairs N T (reducedClass N T l hT hlN a) (reducedProduct N l hlN c) + (pulledInterval P l hlP).points Q.points).image (dilatePair l) = + dilatedPairs N T a c P Q l := by + apply Finset.Subset.antisymm + · intro xy hxy + obtain ⟨⟨x,y⟩, hred, rfl⟩ := Finset.mem_image.mp hxy + apply Finset.mem_filter.mpr + exact ⟨(mem_dilatePair_iff N T hT a c P Q l hl hlN hlP x y).mpr hred, ⟨x,rfl⟩⟩ + · rintro ⟨p,m⟩ hpm + obtain ⟨horig, hdiv⟩ := Finset.mem_filter.mp hpm + obtain ⟨x, rfl⟩ := hdiv + exact Finset.mem_image.mpr ⟨(x,m), + (mem_dilatePair_iff N T hT a c P Q l hl hlN hlP x m).mp horig, rfl⟩ + +theorem dilatedPairs_card (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (P Q : ProgressionInterval) + (l : ℕ) (hl : 0 < l) (hlN : l.Coprime N) (hlP : l.Coprime P.step) : + (dilatedPairs N T a c P Q l).card = + (hyperbolaPairs N T (reducedClass N T l hT hlN a) (reducedProduct N l hlN c) + (pulledInterval P l hlP).points Q.points).card := by + rw [← reduced_pairs_image N T hT a c P Q l hl hlN hlP, + Finset.card_image_of_injective _ (dilatePair_injective l hl)] + +end ErdosHyperbolaError + +end + +section + +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +noncomputable def realIntervalIntegers (x y : ℝ) (lc rc : Bool) : Finset ℤ := + (Finset.Icc ⌈x⌉ ⌊y⌋).filter fun z : ℤ => + (if lc then x ≤ (z : ℝ) else x < (z : ℝ)) ∧ + (if rc then (z : ℝ) ≤ y else (z : ℝ) < y) + +noncomputable def sourcePairs (H T0 T1 : ℕ) (C0 k0 p0 p1 m1 : ℤ) (l : ℕ) + (x0 x1 y0 y1 : ℝ) (lcI rcI lcJ rcJ : Bool) : Finset (ℤ × ℤ) := + ((realIntervalIntegers x0 x1 lcI rcI).product (realIntervalIntegers y0 y1 lcJ rcJ)).filter + (fun pm : ℤ × ℤ => (l : ℤ) ∣ pm.1 ∧ Int.ModEq (T0 : ℤ) pm.1 p0 ∧ + Int.ModEq (T1 : ℤ) pm.1 p1 ∧ Int.ModEq (T1 : ℤ) pm.2 m1 ∧ + Int.ModEq ((H*T0 : ℕ) : ℤ) (pm.1*pm.2) (C0+(H : ℤ)*k0)) + +def sourceInterval (x y : ℝ) (lc rc : Bool) (T : ℕ) (r : ℤ) (hT : 0 < T) : ProgressionInterval where + left := x + right := y + leftClosed := lc + rightClosed := rc + step := T + residue := r + step_pos := hT + +theorem sourceInterval_points (x y : ℝ) (lc rc : Bool) (T : ℕ) (r : ℤ) (hT : 0 < T) : + (sourceInterval x y lc rc T r hT).points = + (realIntervalIntegers x y lc rc).filter (fun z => Int.ModEq (T : ℤ) z r) := by + change ErdosHyperbolaFourier.progressionPoints x y lc rc T r = _ + rw [ErdosHyperbolaFourier.progressionPoints_eq_literal_filter x y lc rc T r hT] + simp only [realIntervalIntegers, Finset.filter_filter, and_assoc] + +theorem sourcePairs_eq_dilated (H T0 T1 : ℕ) [NeZero H] [NeZero T0] + (C0 k0 p0 p1 m1 : ℤ) (l : ℕ) (x0 x1 y0 y1 : ℝ) (lcI rcI lcJ rcJ : Bool) + (hT1 : 0 < T1) (a : (ZMod T0)ˣ) (c : (ZMod (H*T0))ˣ) + (ha : (a : ZMod T0) = (p0 : ZMod T0)) + (hc : (c : ZMod (H*T0)) = ((C0+(H : ℤ)*k0 : ℤ) : ZMod (H*T0))) : + sourcePairs H T0 T1 C0 k0 p0 p1 m1 l x0 x1 y0 y1 lcI rcI lcJ rcJ = + dilatedPairs (H*T0) T0 a c + (sourceInterval x0 x1 lcI rcI T1 p1 hT1) (sourceInterval y0 y1 lcJ rcJ T1 m1 hT1) l := by + have hprod (p m : ℤ) : (p : ZMod (H*T0))*(m : ZMod (H*T0)) = (c : ZMod (H*T0)) ↔ + Int.ModEq ((H*T0 : ℕ) : ℤ) (p*m) (C0+(H : ℤ)*k0) := by + rw [hc, ← Int.cast_mul, ZMod.intCast_eq_intCast_iff] + have hclass (p : ℤ) : (p : ZMod T0) = (a : ZMod T0) ↔ Int.ModEq (T0 : ℤ) p p0 := by + rw [ha, ZMod.intCast_eq_intCast_iff] + ext ⟨p,m⟩ + simp only [sourcePairs, dilatedPairs, hyperbolaPairs, sourceInterval_points, Finset.mem_filter, + Finset.product_eq_sprod, Finset.mem_product] + rw [hprod, hclass] + tauto + +end ErdosHyperbolaError + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +noncomputable def zeroDensity (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (P Q : ProgressionInterval) : ℝ := + (P.points.card : ℝ)*(Q.points.card : ℝ)*restrictionCount H T a/((H*T : ℕ) : ℝ)^2 + +noncomputable def mainDensity (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (P Q : ProgressionInterval) : ℝ := + (intervalLength P/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))* + restrictionCount H T a/((H*T : ℕ) : ℝ)^2 + +theorem count_minus_zero_density (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) : + ((hyperbolaPairs (H*T) T a c P.points Q.points).card : ℂ) - (zeroDensity H T a P Q : ℂ) = + ((∑ h : ZMod (H*T), ∑ k : ZMod (H*T), spectralTerm H T a c P Q h k)- + spectralTerm H T a c P Q 0 0)/((H*T : ℕ) : ℂ)^2 := by + have hc : ((hyperbolaPairs (H*T) T a c P.points Q.points).card : ℂ) = + (∑ h : ZMod (H*T), ∑ k : ZMod (H*T), spectralTerm H T a c P Q h k)/((H*T : ℕ) : ℂ)^2 := + interval_count_eq_fourier (H*T) T (dvd_mul_left T H) a c P Q + have hz : spectralTerm H T a c P Q 0 0 = + (((P.points.card : ℝ)*(Q.points.card : ℝ)*restrictionCount H T a : ℝ) : ℂ) := by + rw [spectralTerm, weight_zero_eq_count, weight_zero_eq_count, restricted_zero_eq_real] + push_cast + rfl + rw [hc, hz] + unfold zeroDensity + push_cast + ring + +theorem count_spectral_error (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) + (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) + (hPN : P.step.Coprime (H*T)) (hQN : Q.step.Coprime (H*T)) : + |((hyperbolaPairs (H*T) T a c P.points Q.points).card : ℝ)-zeroDensity H T a P Q| ≤ + 8*errorBase (H*T) T*(1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) := by + have h := normalized_spectral_error H T a c P Q hP hQ hPN hQN + have hN : ‖((H*T : ℕ) : ℂ)‖ = ((H*T : ℕ) : ℝ) := by simp + have he : ‖((hyperbolaPairs (H*T) T a c P.points Q.points).card : ℂ)- + (zeroDensity H T a P Q : ℂ)‖ = + ‖(∑ h : ZMod (H*T), ∑ k : ZMod (H*T), spectralTerm H T a c P Q h k)- + spectralTerm H T a c P Q 0 0‖/((H*T : ℕ) : ℝ)^2 := by + rw [count_minus_zero_density, norm_div, norm_pow, hN] + rw [← he] at h + simpa only [← Complex.ofReal_natCast, ← Complex.ofReal_sub, Complex.norm_real, Real.norm_eq_abs] using h + +theorem count_error_base (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) + (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) + (hPN : P.step.Coprime (H*T)) (hQN : Q.step.Coprime (H*T)) : + |((hyperbolaPairs (H*T) T a c P.points Q.points).card : ℝ)-mainDensity H T a P Q| ≤ + 16*errorBase (H*T) T*(1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) := by + have hshape : 0 ≤ 1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ) := by + have hU := intervalLength_nonneg P hP + have hV := intervalLength_nonneg Q hQ + positivity + calc + _ ≤ |((hyperbolaPairs (H*T) T a c P.points Q.points).card : ℝ)-zeroDensity H T a P Q| + + |zeroDensity H T a P Q-mainDensity H T a P Q| := abs_sub_le _ _ _ + _ ≤ 8*errorBase (H*T) T*(1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) + + (intervalLength P+intervalLength Q+1)/((H*T : ℕ) : ℝ) := + add_le_add (count_spectral_error H T a c P Q hP hQ hPN hQN) + (zero_frequency_rounding H T a P Q hP hQ) + _ ≤ 8*errorBase (H*T) T*(1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) + + errorBase (H*T) T*(1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) := + add_le_add le_rfl (rounding_absorb (H*T) T _ _ (intervalLength_nonneg P hP) (intervalLength_nonneg Q hQ)) + _ ≤ _ := by nlinarith [mul_nonneg (errorBase_nonneg (H*T) T) hshape] + +theorem mainDensity_explicit (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (P Q : ProgressionInterval) : + mainDensity H T a P Q = + (intervalLength P/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))*((H*T).totient : ℝ)/ + (((H*T : ℕ) : ℝ)^2*(T.totient : ℝ)) := by + unfold mainDensity + rw [restrictionCount_ratio] + field_simp + +noncomputable def completionConstant : ℝ := 16*ErdosHyperbola.harmonicConstant^2 + +theorem completionConstant_pos : 0 < completionConstant := by + have h := ErdosHyperbola.harmonicConstant_pos + unfold completionConstant + positivity + +theorem hyperbola_count_error (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) + (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) + (hPN : P.step.Coprime (H*T)) (hQN : Q.step.Coprime (H*T)) : + |((hyperbolaPairs (H*T) T a c P.points Q.points).card : ℝ)- + (intervalLength P/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))*((H*T).totient : ℝ)/ + (((H*T : ℕ) : ℝ)^2*(T.totient : ℝ))| ≤ + completionConstant*((H*T).divisors.card : ℝ)^3 * (Real.log (2*((H*T : ℕ) : ℝ)))^2 * + (((H*T : ℕ) : ℝ)^((3 : ℝ)/4)) * Real.sqrt T * + (1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) := by + have h := count_error_base H T a c P Q hP hQ hPN hQN + rw [mainDensity_explicit, errorBase_explicit] at h + unfold completionConstant + convert h using 1; ring + +end ErdosHyperbolaError + +end + +section + +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +theorem dilated_hyperbola_count_error (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) + (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) + (hPN : P.step.Coprime (H*T)) (hQN : Q.step.Coprime (H*T)) + (l : ℕ) (hl : 0 < l) (hlN : l.Coprime (H*T)) (hlP : l.Coprime P.step) : + |((dilatedPairs (H*T) T a c P Q l).card : ℝ)- + (intervalLength P*intervalLength Q*((H*T).totient : ℝ))/ + ((l : ℝ)*(P.step : ℝ)*(Q.step : ℝ)*((H*T : ℕ) : ℝ)^2*(T.totient : ℝ))| ≤ + completionConstant*((H*T).divisors.card : ℝ)^3 * (Real.log (2*((H*T : ℕ) : ℝ)))^2 * + (((H*T : ℕ) : ℝ)^((3 : ℝ)/4)) * Real.sqrt T * + (1+intervalLength P/((l : ℝ)*((H*T : ℕ) : ℝ))+intervalLength Q/((H*T : ℕ) : ℝ)) := by + have h := hyperbola_count_error H T + (reducedClass (H*T) T l (dvd_mul_left T H) hlN a) + (reducedProduct (H*T) l hlN c) (pulledInterval P l hlP) Q + (pulledInterval_ordered P hP l hl hlP) hQ hPN hQN + rw [← dilatedPairs_card (H*T) T (dvd_mul_left T H) a c P Q l hl hlN hlP, + pulledInterval_length] at h + change |((dilatedPairs (H*T) T a c P Q l).card : ℝ)- + (intervalLength P/(l : ℝ)/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))*((H*T).totient : ℝ)/ + (((H*T : ℕ) : ℝ)^2*(T.totient : ℝ))| ≤ + completionConstant*((H*T).divisors.card : ℝ)^3 * (Real.log (2*((H*T : ℕ) : ℝ)))^2 * + (((H*T : ℕ) : ℝ)^((3 : ℝ)/4)) * Real.sqrt T * + (1+(intervalLength P/(l : ℝ))/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) at h + have hlR : (l : ℝ) ≠ 0 := by exact_mod_cast hl.ne' + have hPR : (P.step : ℝ) ≠ 0 := by exact_mod_cast P.step_pos.ne' + have hQR : (Q.step : ℝ) ≠ 0 := by exact_mod_cast Q.step_pos.ne' + have hNR : ((H*T : ℕ) : ℝ) ≠ 0 := by exact_mod_cast NeZero.ne (H*T) + have hTR : (T.totient : ℝ) ≠ 0 := by exact_mod_cast (Nat.totient_pos.mpr (NeZero.pos T)).ne' + have hdensity : + (intervalLength P/(l : ℝ)/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))*((H*T).totient : ℝ)/ + (((H*T : ℕ) : ℝ)^2*(T.totient : ℝ)) = + (intervalLength P*intervalLength Q*((H*T).totient : ℝ))/ + ((l : ℝ)*(P.step : ℝ)*(Q.step : ℝ)*((H*T : ℕ) : ℝ)^2*(T.totient : ℝ)) := by + field_simp + rw [hdensity, div_div] at h + exact h + +theorem dilated_hyperbola_count_error_same_step (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) + (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) (hsteps : P.step = Q.step) + (hPN : P.step.Coprime (H*T)) (hQN : Q.step.Coprime (H*T)) + (l : ℕ) (hl : 0 < l) (hlN : l.Coprime (H*T)) (hlP : l.Coprime P.step) : + |((dilatedPairs (H*T) T a c P Q l).card : ℝ)- + (intervalLength P*intervalLength Q*((H*T).totient : ℝ))/ + ((l : ℝ)*(P.step : ℝ)^2*((H*T : ℕ) : ℝ)^2*(T.totient : ℝ))| ≤ + completionConstant*((H*T).divisors.card : ℝ)^3 * (Real.log (2*((H*T : ℕ) : ℝ)))^2 * + (((H*T : ℕ) : ℝ)^((3 : ℝ)/4)) * Real.sqrt T * + (1+intervalLength P/((l : ℝ)*((H*T : ℕ) : ℝ))+intervalLength Q/((H*T : ℕ) : ℝ)) := by + have h := dilated_hyperbola_count_error H T a c P Q hP hQ hPN hQN l hl hlN hlP + have he : (l : ℝ)*(P.step : ℝ)*(Q.step : ℝ)*((H*T : ℕ) : ℝ)^2*(T.totient : ℝ) = + (l : ℝ)*(P.step : ℝ)^2*((H*T : ℕ) : ℝ)^2*(T.totient : ℝ) := by + rw [← hsteps] + ring + rw [he] at h + exact h + +end ErdosHyperbolaError + +end + +section + +namespace ErdosHyperbolaError + +theorem source_hyperbola_count_error (H T0 T1 : ℕ) (hH : 2 ≤ H) (hT0 : 0 < T0) (hT1 : 0 < T1) + (hSF : Squarefree T0) (hsupport : ∀ p : ℕ, p.Prime → p ∣ T0 → p ∣ H) + (hT1N : T1.Coprime (H*T0)) (C0 k0 p0 p1 m1 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (hp0 : Int.gcd p0 (T0 : ℤ) = 1) + (_hp1 : Int.gcd p1 (T1 : ℤ) = 1) (l : ℕ) (hl : 0 < l) (hlHT1 : l.Coprime (H*T1)) + (x0 x1 y0 y1 : ℝ) (hx : x0 ≤ x1) (hy : y0 ≤ y1) (lcI rcI lcJ rcJ : Bool) : + |((sourcePairs H T0 T1 C0 k0 p0 p1 m1 l x0 x1 y0 y1 lcI rcI lcJ rcJ).card : ℝ)- + ((x1-x0)*(y1-y0)*((H*T0).totient : ℝ))/ + ((l : ℝ)*(T1 : ℝ)^2*((H*T0 : ℕ) : ℝ)^2*(T0.totient : ℝ))| ≤ + completionConstant*((H*T0).divisors.card : ℝ)^3 * (Real.log (2*((H*T0 : ℕ) : ℝ)))^2 * + (((H*T0 : ℕ) : ℝ)^((3 : ℝ)/4)) * Real.sqrt T0 * + (1+(x1-x0)/((l : ℝ)*((H*T0 : ℕ) : ℝ))+(y1-y0)/((H*T0 : ℕ) : ℝ)) := by + let : NeZero H := ⟨by omega⟩ + let : NeZero T0 := ⟨hT0.ne'⟩ + have hTH : T0 ∣ H := source_restriction_divides H T0 (by omega) hSF hsupport + obtain ⟨hlN, hlT1⟩ := source_dilation_coprime H T0 T1 l hTH hlHT1 + let a : (ZMod T0)ˣ := ZMod.unitOfIsCoprime p0 (Int.isCoprime_iff_gcd_eq_one.mpr hp0) + let c : (ZMod (H*T0))ˣ := ZMod.unitOfIsCoprime (C0+(H : ℤ)*k0) + (source_product_coprime H T0 hTH C0 k0 hC0) + have h := dilated_hyperbola_count_error_same_step H T0 a c + (sourceInterval x0 x1 lcI rcI T1 p1 hT1) (sourceInterval y0 y1 lcJ rcJ T1 m1 hT1) + hx hy rfl hT1N hT1N l hl hlN hlT1 + rw [← sourcePairs_eq_dilated H T0 T1 C0 k0 p0 p1 m1 l x0 x1 y0 y1 lcI rcI lcJ rcJ hT1 a c rfl rfl] at h + exact h + +end ErdosHyperbolaError + +end + +section + +namespace ErdosVarianceLargeCount +open NumberTheoryLean ErdosHyperbolaError +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem signed_squarefree_dvd_iff (d : ℕ) (hd : Squarefree d) (n : ℤ) : + (d : ℤ) ∣ n ↔ ∀ t ∈ d.primeFactors,(t : ℤ) ∣ n := by + simpa only [Int.natCast_dvd] using (SmallSieveFinite.squarefree_dvd_iff_primeFactors + (x := n.natAbs) hd) + +theorem sourcePairs_divisor_filter (H T0 T1 : ℕ) (C0 k0 p0 p1 m1 : ℤ) + (d : ℕ) (hd : Squarefree d) (x0 x1 y0 y1 : ℝ) (lcI rcI lcJ rcJ : Bool) : + (sourcePairs H T0 T1 C0 k0 p0 p1 m1 1 x0 x1 y0 y1 lcI rcI lcJ rcJ).filter + (fun pm => ∀ t ∈ d.primeFactors,(t : ℤ) ∣ pm.1) = + sourcePairs H T0 T1 C0 k0 p0 p1 m1 d x0 x1 y0 y1 lcI rcI lcJ rcJ := by + ext pm + simp only [sourcePairs,Finset.mem_filter,Nat.cast_one,one_dvd,true_and, + ← signed_squarefree_dvd_iff d hd] + tauto + +theorem sourcePairs_intersection_mass (H T0 T1 : ℕ) (C0 k0 p0 p1 m1 : ℤ) + (d : ℕ) (hd : Squarefree d) (x0 x1 y0 y1 : ℝ) (lcI rcI lcJ rcJ : Bool) : + BonferroniBlocks.intersectionMass + (sourcePairs H T0 T1 C0 k0 p0 p1 m1 1 x0 x1 y0 y1 lcI rcI lcJ rcJ) (fun _ => 1) + (fun t pm => (t : ℤ) ∣ pm.1) d.primeFactors = + ((sourcePairs H T0 T1 C0 k0 p0 p1 m1 d x0 x1 y0 y1 lcI rcI lcJ rcJ).card : ℝ) := by + rw [← sourcePairs_divisor_filter H T0 T1 C0 k0 p0 p1 m1 d hd x0 x1 y0 y1 lcI rcI lcJ rcJ, + Finset.card_filter,Nat.cast_sum] + simp only [BonferroniBlocks.intersectionMass,BonferroniBlocks.intersectionValue,one_mul, + Nat.cast_ite,Nat.cast_one,Nat.cast_zero] + apply Finset.sum_congr rfl + intro pm _hpm + split_ifs <;> rfl + +end ErdosVarianceLargeCount + +end + +section + +namespace ErdosVarianceLargeCount +open NumberTheoryLean ErdosHyperbolaError +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def sourceMain (H T0 T1 : ℕ) (U V : ℝ) : ℝ := + U*V*((H*T0).totient : ℝ)/ + ((T1 : ℝ)^2*((H*T0 : ℕ) : ℝ)^2*(T0.totient : ℝ)) + +noncomputable def hyperbolaEnvelope (H T0 : ℕ) : ℝ := + completionConstant*((H*T0).divisors.card : ℝ)^3*(Real.log (2*((H*T0 : ℕ) : ℝ)))^2* + (((H*T0 : ℕ) : ℝ)^((3 : ℝ)/4))*Real.sqrt T0 + +theorem source_pair_remainder_bound (H T0 T1 : ℕ) (hH : 2 ≤ H) (hT0 : 0 < T0) (hT1 : 0 < T1) + (hSF : Squarefree T0) (hsupport : ∀ t : ℕ,t.Prime → t ∣ T0 → t ∣ H) + (hT1N : T1.Coprime (H*T0)) (C0 k0 p0 p1 m1 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (hp0 : Int.gcd p0 (T0 : ℤ) = 1) + (hp1 : Int.gcd p1 (T1 : ℤ) = 1) (d : ℕ) (hd : Squarefree d) (hdHT1 : d.Coprime (H*T1)) + (x0 x1 y0 y1 : ℝ) (hx : x0 ≤ x1) (hy : y0 ≤ y1) (lcI rcI lcJ rcJ : Bool) : + |FundamentalBlockEstimate.integerRemainder + (sourcePairs H T0 T1 C0 k0 p0 p1 m1 1 x0 x1 y0 y1 lcI rcI lcJ rcJ) (fun _ => 1) + (fun t pm => (t : ℤ) ∣ pm.1) (sourceMain H T0 T1 (x1-x0) (y1-y0)) (fun t => 1/(t : ℝ)) d| ≤ + hyperbolaEnvelope H T0*(1+(x1-x0)/((d : ℝ)*((H*T0 : ℕ) : ℝ))+(y1-y0)/((H*T0 : ℕ) : ℝ)) := by + have herr := source_hyperbola_count_error H T0 T1 hH hT0 hT1 hSF hsupport hT1N + C0 k0 p0 p1 m1 hC0 hp0 hp1 d (Nat.pos_of_ne_zero hd.ne_zero) hdHT1 + x0 x1 y0 y1 hx hy lcI rcI lcJ rcJ + unfold FundamentalBlockEstimate.integerRemainder BonferroniBlocks.intersectionRemainder + have hprod : (∏ t ∈ d.primeFactors,1/(t : ℝ)) = 1/(d : ℝ) := by + simpa only [one_div] using SmallSieveFinite.reciprocal_primeFactors_product hd + rw [sourcePairs_intersection_mass H T0 T1 C0 k0 p0 p1 m1 d hd x0 x1 y0 y1 lcI rcI lcJ rcJ,hprod] + have he : sourceMain H T0 T1 (x1-x0) (y1-y0)*(1/(d : ℝ)) = + ((x1-x0)*(y1-y0)*((H*T0).totient : ℝ))/ + ((d : ℝ)*(T1 : ℝ)^2*((H*T0 : ℕ) : ℝ)^2*(T0.totient : ℝ)) := by + dsimp [sourceMain] + ring + rw [he] + exact herr + +end ErdosVarianceLargeCount + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceParentBenchmark.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceParentBenchmark.lean new file mode 100644 index 0000000000000000000000000000000000000000..805d00bc6d4e5b19d3da1ba4d974911576443a9c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceParentBenchmark.lean @@ -0,0 +1,84 @@ +import Mathlib.Analysis.Calculus.Deriv.Slope +import OAI.NumberTheory.Jacobsthal.Analysis.SourceProductLimit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Filter +open scoped Topology +namespace ErdosSourceReferenceMargin +attribute [local instance] Classical.propDecidable +open ErdosCorrectionLimit +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.BuchstabBridge +open NumberTheoryLean.DerivativeWeights NumberTheoryLean.ReferenceDifferentiation +open NumberTheoryLean.ReferenceLocalResidual NumberTheoryLean.ReferenceMertens + +theorem starting_extension_derivative_two : + HasDerivAt (startingExtension sieveA) (Real.exp Real.eulerMascheroniConstant) 2 := by + have hh := startingExtension_hasDerivAt (s := 2) (by norm_num) + convert! hh using 1 + norm_num [evenInitial,sieveA] + ring + +theorem starting_extension_two : startingExtension sieveA 2=0 := by norm_num [startingExtension] + +noncomputable def startingSlope (s : ℝ) : ℝ := + Function.update (fun t => (startingExtension sieveA t-startingExtension sieveA 2)/(t-2)) + 2 (Real.exp Real.eulerMascheroniConstant) s + +theorem startingSlope_continuousAt : ContinuousAt startingSlope 2 := + starting_extension_derivative_two.continuousAt_div + +theorem startingSlope_two : startingSlope 2=Real.exp Real.eulerMascheroniConstant := by simp [startingSlope] + +theorem starting_extension_factor (s : ℝ) : startingExtension sieveA s=startingSlope s*(s-2) := by + by_cases hs : s=2 + · subst s + simp only [starting_extension_two,sub_self,mul_zero] + · rw [startingSlope,Function.update_of_ne hs,starting_extension_two,sub_zero] + exact (div_mul_cancel₀ _ (sub_ne_zero.mpr hs)).symm + +theorem root_startingSlope_tendsto (a : ℝ) : + Tendsto (fun z => startingSlope (sourceRootNode a z).ratio) atTop + (𝓝 (Real.exp Real.eulerMascheroniConstant)) := by + simpa only [startingSlope_two] using! startingSlope_continuousAt.tendsto.comp (actual_root_ratio_tendsto a) + +theorem root_parentBenchmark_tendsto (a : ℝ) : + Tendsto (fun z => ErdosInverseBoxHeight.sourceB z*parentBenchmark .even (sourceRootNode a z).ratio) atTop + (𝓝 (-a*Real.exp Real.eulerMascheroniConstant)) := by + have hh := (root_startingSlope_tendsto a).mul (actual_root_centered_gap_tendsto a) + rw [show Real.exp Real.eulerMascheroniConstant*(-a)=-a*Real.exp Real.eulerMascheroniConstant by ring] at hh + apply hh.congr' + filter_upwards [actual_root_eventually a] with z hs + have hr4 : (sourceRootNode a z).ratio ≤ 4 := by linarith [hs.2.2.2.2.1] + rw [parent_even_eq_starting hr4,starting_extension_factor] + have hratio : (sourceRootNode a z).ratio=(sourceRootNode a z).gap/ErdosInverseBoxHeight.sourceB z := rfl + rw [hratio] + have hB0 : ErdosInverseBoxHeight.sourceB z ≠ 0 := hs.1.ne' + field_simp + +theorem root_nodeBenchmark_tendsto (a : ℝ) : + Tendsto (fun z => (ErdosInverseBoxHeight.sourceB z)^2* + nodeBenchmark (ErdosInverseBoxHeight.sourceW z) (sourceRootNode a z)) atTop + (𝓝 (-a*Real.exp Real.eulerMascheroniConstant)) := by + have hh := (root_referenceProduct_tendsto true).mul (root_parentBenchmark_tendsto a) + simp only [one_mul] at hh + apply hh.congr' + filter_upwards with z + change ErdosInverseBoxHeight.sourceB z*referenceProduct (ErdosInverseBoxHeight.sourceW z) + (ErdosInverseBoxHeight.sourceB z) true*(ErdosInverseBoxHeight.sourceB z*parentBenchmark .even (sourceRootNode a z).ratio)= + (ErdosInverseBoxHeight.sourceB z)^2*(referenceProduct (ErdosInverseBoxHeight.sourceW z) + (ErdosInverseBoxHeight.sourceB z) true*parentBenchmark .even (sourceRootNode a z).ratio) + ring + +end ErdosSourceReferenceMargin + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceReferenceRemainders.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceReferenceRemainders.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6bb0067d3ff32f3b4882454d7e0253edf697e55 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceReferenceRemainders.lean @@ -0,0 +1,624 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.RetainedNormalizedReward +import OAI.NumberTheory.Jacobsthal.Estimates.SourceCenteredGap +import OAI.NumberTheory.Jacobsthal.Partitions.ReferenceIntervalBound +import OAI.NumberTheory.Jacobsthal.Paths.ResidualHistoryGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.MovingGapHighRemoval + +open _root_.Filter +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open ErdosPrimeInputs.HighPrimeMass ErdosPrimeInputs.LongPrimePaths + +theorem growing_gap_high_removal : ∃ w₀ : ℝ,1 < w₀ ∧ ∀ M : ℝ,∀ᶠ B : ℝ in atTop, + ∀ w : ℝ,w₀ ≤ w → 2 ≤ B → ∀ z : Node,z.cutoff=B → 0 < z.gap → Valid z.side z.ratio → Consistent z → + uncappedLowGapHighMass w 2 z ((Real.log B)^2) ((Real.log B)^2/2) ≤ B^(-M) := by + obtain ⟨w₀,hw₀,h⟩ := long_prime_paths_superpolynomial + refine ⟨w₀,hw₀,?_⟩ + intro M + filter_upwards [h M] with B hB + intro w hw hB2 z hcut hr hs hz + have hw1 : 1 < w := hw₀.trans_le hw + have hlow := uncapped_low_mass_le hw1 (by norm_num : (0:ℝ) ≤ 2) hr hs hz ((Real.log B)^2) ((Real.log B)^2/2) + rw [hcut] at hlow + have htail := lowGapHighMass_le_long (r₀:=z.gap) hw1 (by norm_num : (0:ℝ)<2) hB2 + (sq_nonneg (Real.log B)) (show (Real.log B)^2/2 ≤ (Real.log B)^2*2/2 by nlinarith [sq_nonneg (Real.log B)]) + exact (hlow.trans htail).trans (hB w hw 2 (by norm_num) hB2 _ (Nat.le_ceil _)) + +end NumberTheoryLean.MovingGapHighRemoval + + + +namespace NumberTheoryLean.LargeCutoffResidual + +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualBoundaryDomain +open ReferenceLocalResidual ReferenceResidualErrors ReferenceResidualPointwise ReferenceProductErrorBounds +open ReferenceIntervalCutoff ReferenceIntervalBound GlobalResidualScale WeightPowerBounds + +theorem large_cutoff_relative_power (d M : ℝ) (hd : 0 < d) (hM : 0 < M) : + ∃ C T w₀ : ℝ,0 < C ∧ 2 ≤ T ∧ 1 < w₀ ∧ ∀ B w : ℝ,0 < B → T ≤ Real.log B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ z : Node,Valid z.side z.ratio → Consistent z → + BoundaryDomain z.side z.gap → z.cutoff ≤ B → (Real.log B)^4 < z.cutoff → + |sourceResidual w z| ≤ C*weight z.side z.ratio*(1+Real.log B)*powerDecay M B := by + obtain ⟨cP,CP,wP,hcP,hCP,hwP,hP⟩ := source_residual_pointwise + obtain ⟨cI,CI,wI,hcI,hCI,_hwI,hI⟩ := source_residual_split_bound + obtain ⟨K,hK,hSave⟩ := linear_log_cutoff_saving hcI hd hM + obtain ⟨CR,hCR,hRelative⟩ := relative_weight_power + let T := max K (4*M+10) + have hT : 2 ≤ T := by have h := le_max_right K (4*M+10); dsimp [T]; linarith + refine ⟨CP*CR+CI,T,max wP wI,by positivity,hT,hwP.trans_le (le_max_left _ _),?_⟩ + intro B w hB hBT hw hcomp z hs hz hdom hcap hbig + have hL2 : 2 ≤ Real.log B := hT.trans hBT + have hL : 0 ≤ Real.log B := by linarith + have hKL : K ≤ Real.log B := (le_max_left _ _).trans hBT + have hML : 4*M+10 ≤ Real.log B := (le_max_right _ _).trans hBT + have hB1 : 1 ≤ B := (Real.log_nonneg_iff hB).mp hL + have hKpos : 0 < K := by linarith + have hwp : wP ≤ w := (le_max_left _ _).trans hw + have hwi : wI ≤ w := (le_max_right _ _).trans hw + have hw1 : 1 < w := hwP.trans_le hwp + let a := K*Real.log B + have ha : 2 ≤ a := by dsimp [a]; nlinarith + have hab : a < z.cutoff := by + have ha2 : a ≤ (Real.log B)^2 := by dsimp [a]; nlinarith [mul_le_mul_of_nonneg_right hKL hL] + have h24 : (Real.log B)^2 ≤ (Real.log B)^4 := by + nlinarith [mul_le_mul_of_nonneg_right (show 1 ≤ (Real.log B)^2 by nlinarith) (sq_nonneg (Real.log B))] + exact (ha2.trans h24).trans_lt hbig + have hsHalf : (1/2:ℝ) ≤ z.ratio := by cases hi : z.side <;> simp only [hi,Valid] at hs <;> linarith + have he := (eq_div_iff (ne_of_gt (valid_pos hs))).mp hz + have hr : 0 < z.gap := by rw [← he]; exact mul_pos (by linarith) (valid_pos hs) + have hsep := rebased_ratio_separation hK hM.le hKL hML hsHalf hbig + rw [he] at hsep + obtain ⟨hvs,hzs⟩ := rebase_invariants hs hr hz (by linarith : 0 < a) hab.le + have hφ := weight_pos hs + have hφa := weight_pos hvs + have hWeight : weight (rebase z a).side (rebase z a).ratio ≤ CR*weight z.side z.ratio*powerDecay M B := + hRelative M B z.side z.side z.ratio (z.gap/a) hs hsep.1 hsep.2 + have hLogA : Real.log a ≤ Real.log B := Real.log_le_log (by linarith) (hab.le.trans hcap) + have hLogB : Real.log z.cutoff ≤ Real.log B := Real.log_le_log (by linarith) hcap + have hLA : 0 ≤ 1+Real.log a := by have hh := Real.log_nonneg (show 1 ≤ a by linarith); linarith + have hLb : 0 ≤ 1+Real.log z.cutoff := by have hh := Real.log_nonneg (show 1 ≤ z.cutoff by linarith); linarith + have hLB : 0 ≤ 1+Real.log B := by linarith + have hPow := powerDecay_pos M B + have hE2pos := primeError_pos cP w 2 + have hEApos := primeError_pos cI w a + have hE2 := primeError_le_one hcP.le w 2 + have hEA := hSave B w hB1 hw1 hcomp + have hLow : |sourceResidual w (rebase z a)| ≤ CP*CR*weight z.side z.ratio*(1+Real.log B)*powerDecay M B := by + have hh := hP w hwp (rebase z a) hvs hzs ha hdom + calc + _ ≤ CP*weight (rebase z a).side (rebase z a).ratio*(1+Real.log a)*primeError cP w 2 := hh + _ ≤ CP*(CR*weight z.side z.ratio*powerDecay M B)*(1+Real.log B)*1 := by gcongr + _ = _ := by ring + have hHigh : CI*weight z.side z.ratio*(1+Real.log z.cutoff)*primeError cI w a ≤ + CI*weight z.side z.ratio*(1+Real.log B)*powerDecay M B := by gcongr + have hh := hI w hwi z hs hz a ha hab + calc + _ ≤ CP*CR*weight z.side z.ratio*(1+Real.log B)*powerDecay M B+ + CI*weight z.side z.ratio*(1+Real.log B)*powerDecay M B := hh.trans (add_le_add hLow hHigh) + _ = _ := by ring + +end NumberTheoryLean.LargeCutoffResidual + + + +namespace NumberTheoryLean.HighGapResidual + +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualBoundaryDomain +open ReferenceLocalResidual ReferenceResidualErrors ReferenceResidualPointwise ReferenceProductErrorBounds +open ReferenceIntervalCutoff ReferenceIntervalBound ReferenceResidualSum GlobalResidualScale WeightPowerBounds + +theorem high_gap_residual_power (d M : ℝ) (hd : 0 < d) (hM : 0 < M) : + ∃ C T w₀ : ℝ,0 < C ∧ 2 ≤ T ∧ 1 < w₀ ∧ ∀ B w : ℝ,0 < B → T ≤ Real.log B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ z : Node,Valid z.side z.ratio → Consistent z → + BoundaryDomain z.side z.gap → 2 ≤ z.cutoff → z.cutoff ≤ B → (Real.log B)^2/2 ≤ z.gap → + |sourceResidual w z| ≤ C*(1+Real.log B)*powerDecay M B := by + obtain ⟨cP,CP,wP,hcP,hCP,hwP,hP⟩ := source_residual_pointwise + obtain ⟨cI,CI,wI,hcI,hCI,_hwI,hI⟩ := source_residual_split_bound + obtain ⟨K,hK,hSave⟩ := linear_log_cutoff_saving hcI hd hM + have hKpos : 0 < K := by linarith + obtain ⟨CA,TA,hCA,_hTA,hAbs⟩ := weight_power_at_ratio hKpos hM + obtain ⟨W,hW,hWeight⟩ := uniform_weight_bound + let T := max 2 TA + refine ⟨CP*CA+CI*W,T,max wP wI,by positivity,le_max_left _ _,hwP.trans_le (le_max_left _ _),?_⟩ + intro B w hB hBT hw hcomp z hs hz hdom hb hcap hgap + have hL2 : 2 ≤ Real.log B := (le_max_left _ _).trans hBT + have hL : 0 ≤ Real.log B := by linarith + have hLA : TA ≤ Real.log B := (le_max_right _ _).trans hBT + have hB1 : 1 ≤ B := (Real.log_nonneg_iff hB).mp hL + have hwp : wP ≤ w := (le_max_left _ _).trans hw + have hwi : wI ≤ w := (le_max_right _ _).trans hw + have hw1 : 1 < w := hwP.trans_le hwp + let a := K*Real.log B + have ha : 2 ≤ a := by dsimp [a]; nlinarith + have hr : 0 < z.gap := by nlinarith + have hφ := weight_pos hs + have hRat := ratio_eq_gap_div_cutoff hs hz (by linarith) + have hLogB : Real.log z.cutoff ≤ Real.log B := Real.log_le_log (by linarith) hcap + have hLb : 0 ≤ 1+Real.log z.cutoff := by have hh := Real.log_nonneg (show 1 ≤ z.cutoff by linarith); linarith + have hLB : 0 ≤ 1+Real.log B := by linarith + have hPow := powerDecay_pos M B + have hE2pos := primeError_pos cP w 2 + have hEApos := primeError_pos cI w a + have hE2 := primeError_le_one hcP.le w 2 + have hEA := hSave B w hB1 hw1 hcomp + by_cases hba : z.cutoff ≤ a + · have hRatio := gap_over_linear_cutoff hKpos hL (by linarith : 0 < z.cutoff) hba hgap + rw [← hRat] at hRatio + have hWt := hAbs B hLA z.side z.ratio hRatio + have hpoint := hP w hwp z hs hz hb hdom + have hBase : |sourceResidual w z| ≤ CP*CA*(1+Real.log B)*powerDecay M B := by + calc + _ ≤ CP*weight z.side z.ratio*(1+Real.log z.cutoff)*primeError cP w 2 := hpoint + _ ≤ CP*(CA*powerDecay M B)*(1+Real.log B)*1 := by gcongr + _ = _ := by ring + apply hBase.trans + apply mul_le_mul_of_nonneg_right _ hPow.le + exact mul_le_mul_of_nonneg_right (le_add_of_nonneg_right (mul_nonneg hCI.le hW.le)) hLB + · have hab : a < z.cutoff := lt_of_not_ge hba + obtain ⟨hvs,hzs⟩ := rebase_invariants hs hr hz (by linarith : 0 < a) hab.le + have hφa := weight_pos hvs + have hRatio := gap_over_linear_cutoff hKpos hL (by linarith : 0 < a) (le_refl a) hgap + have hWt := hAbs B hLA z.side (z.gap/a) hRatio + have hLogA : Real.log a ≤ Real.log B := Real.log_le_log (by linarith) (hab.le.trans hcap) + have hLa : 0 ≤ 1+Real.log a := by have hh := Real.log_nonneg (show 1 ≤ a by linarith); linarith + have hLow : |sourceResidual w (rebase z a)| ≤ CP*CA*(1+Real.log B)*powerDecay M B := by + have hpoint := hP w hwp (rebase z a) hvs hzs ha hdom + calc + _ ≤ CP*weight z.side (z.gap/a)*(1+Real.log a)*primeError cP w 2 := hpoint + _ ≤ CP*(CA*powerDecay M B)*(1+Real.log B)*1 := by gcongr + _ = _ := by ring + have hWsource := hWeight _ _ hs + have hHigh : CI*weight z.side z.ratio*(1+Real.log z.cutoff)*primeError cI w a ≤ + CI*W*(1+Real.log B)*powerDecay M B := by gcongr + have hh := hI w hwi z hs hz a ha hab + calc + _ ≤ CP*CA*(1+Real.log B)*powerDecay M B+CI*W*(1+Real.log B)*powerDecay M B := + hh.trans (add_le_add hLow hHigh) + _ = _ := by ring + +end NumberTheoryLean.HighGapResidual + + + +namespace NumberTheoryLean.LowStateResidualBound + +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualBoundaryDomain +open ReferenceLocalResidual ReferenceResidualPointwise ReferenceProductErrorBounds GlobalResidualScale LargeCutoffResidual + +theorem low_state_normalized_residual (d : ℝ) (hd : 0 < d) : + ∃ c C T w₀ : ℝ,0 < c ∧ 0 < C ∧ 2 ≤ T ∧ 1 < w₀ ∧ + ∀ B w : ℝ,0 < B → T ≤ Real.log B → w₀ ≤ w → Real.log B ≤ d*Real.log w → + ∀ z : Node,Valid z.side z.ratio → Consistent z → BoundaryDomain z.side z.gap → + 2 ≤ z.cutoff → z.cutoff ≤ B → z.gap ≤ (23/10:ℝ)*B → z.ratio ≤ (Real.log B)^2 → + (z.gap^2/weight z.side z.ratio)*|sourceResidual w z| ≤ + C*((Real.log B)^13*primeError c w 2+1/B^7) := by + obtain ⟨c,CP,wP,hc,hCP,hwP,hP⟩ := source_residual_pointwise + obtain ⟨CL,TL,wL,hCL,hTL,_hwL,hLarge⟩ := large_cutoff_relative_power d 10 hd (by norm_num) + let C := 2*CP+6*CL + have hC : 0 < C := by dsimp [C]; positivity + refine ⟨c,C,TL,max wP wL,hc,hC,hTL,hwP.trans_le (le_max_left _ _),?_⟩ + intro B w hB hT hw hcomp z hs hz hdom hb hcap hgap hratio + have hL2 : 2 ≤ Real.log B := hTL.trans hT + have hL : 0 ≤ Real.log B := by linarith + have hwp : wP ≤ w := (le_max_left _ _).trans hw + have hwL : wL ≤ w := (le_max_right _ _).trans hw + have hφ := weight_pos hs + have hr : 0 < z.gap := by have hh := boundary_gap_ge_two hdom; linarith + have hE := primeError_pos c w 2 + have hSmallC : 2*CP ≤ C := by dsimp [C]; linarith + have hLargeC : 6*CL ≤ C := by dsimp [C]; linarith + have hterm0 : 0 ≤ (Real.log B)^13*primeError c w 2 := by positivity + have hinv0 : 0 ≤ (1:ℝ)/B^7 := by positivity + by_cases hsmall : z.cutoff ≤ (Real.log B)^4 + · have he := (eq_div_iff (ne_of_gt (valid_pos hs))).mp hz + have hr6 : z.gap ≤ (Real.log B)^6 := by + have hm := mul_le_mul hsmall hratio (valid_pos hs).le (pow_nonneg hL 4) + rw [he] at hm + nlinarith + have hr12 : z.gap^2 ≤ (Real.log B)^12 := by + have hm := pow_le_pow_left₀ hr.le hr6 2 + simpa only [← pow_mul] using hm + have hlog := Real.log_le_log (by linarith : 0 < z.cutoff) hcap + have hLf : 0 ≤ 1+Real.log z.cutoff := by have hh := Real.log_nonneg (show 1 ≤ z.cutoff by linarith); linarith + have hLup : 1+Real.log z.cutoff ≤ 2*Real.log B := by linarith + have hp := hP w hwp z hs hz hb hdom + have hm := mul_le_mul_of_nonneg_left hp (div_nonneg (sq_nonneg z.gap) hφ.le) + have hn : (z.gap^2/weight z.side z.ratio)*|sourceResidual w z| ≤ + CP*z.gap^2*(1+Real.log z.cutoff)*primeError c w 2 := by + convert! hm using 1 + field_simp + calc + _ ≤ CP*z.gap^2*(1+Real.log z.cutoff)*primeError c w 2 := hn + _ ≤ CP*(Real.log B)^12*(2*Real.log B)*primeError c w 2 := by gcongr + _ = (2*CP)*((Real.log B)^13*primeError c w 2) := by ring + _ ≤ C*((Real.log B)^13*primeError c w 2) := mul_le_mul_of_nonneg_right hSmallC hterm0 + _ ≤ _ := mul_le_mul_of_nonneg_left (le_add_of_nonneg_right hinv0) hC.le + · have hlarge := hLarge B w hB hT hwL hcomp z hs hz hdom hcap (lt_of_not_ge hsmall) + have hr2 : z.gap^2 ≤ 6*B^2 := by + have hm := pow_le_pow_left₀ hr.le hgap 2 + nlinarith [sq_nonneg B] + have hLB : 1+Real.log B ≤ B := by linarith [Real.log_le_sub_one_of_pos hB] + have hLB0 : 0 ≤ 1+Real.log B := by linarith + have hPow := powerDecay_pos 10 B + have hm := mul_le_mul_of_nonneg_left hlarge (div_nonneg (sq_nonneg z.gap) hφ.le) + have hn : (z.gap^2/weight z.side z.ratio)*|sourceResidual w z| ≤ + CL*z.gap^2*(1+Real.log B)*powerDecay 10 B := by + convert! hm using 1 + field_simp + calc + _ ≤ CL*z.gap^2*(1+Real.log B)*powerDecay 10 B := hn + _ ≤ CL*(6*B^2)*B*powerDecay 10 B := by gcongr + _ = (6*CL)*(1/B^7) := by + have hpow10 := powerDecay_nat hB 10 + norm_num only [Nat.cast_ofNat] at hpow10 + rw [hpow10] + field_simp + _ ≤ C*(1/B^7) := mul_le_mul_of_nonneg_right hLargeC hinv0 + _ ≤ _ := mul_le_mul_of_nonneg_left (le_add_of_nonneg_left hterm0) hC.le + +end NumberTheoryLean.LowStateResidualBound + + + +namespace NumberTheoryLean.HighResidualSum + +attribute [local instance] Classical.propDecidable +open _root_.Filter _root_.Finset +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh ActualBoundaryDomain SourceNodeCoordinates +open ReferenceSourceDecomposition ReferenceResidualPointwise ReferenceResidualSum ReferenceLocalResidual ReferenceProductErrorBounds +open GlobalResidualScale HighGapResidual MovingGapHighRemoval ResidualHistoryGeometry +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +noncomputable def highResidualAbsoluteSum (w B : ℝ) (start : Node) : ℝ := + ∑ ps ∈ (uncappedPrefixes w 2 start).filter (actualHasHigh w ((Real.log B)^2) start), + prefixWeight ps*|sourceResidual w (terminal w start ps)| + +theorem source_residual_crude : ∃ C w₀ : ℝ,0 < C ∧ 1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → + ∀ B : ℝ,∀ z : Node,Valid z.side z.ratio → Consistent z → BoundaryDomain z.side z.gap → + 2 ≤ z.cutoff → z.cutoff ≤ B → |sourceResidual w z| ≤ C*(1+Real.log B) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := source_residual_pointwise + obtain ⟨W,hW,hWbound⟩ := uniform_weight_bound + refine ⟨C*W,w₀,by positivity,hw₀,?_⟩ + intro w hw B z hs hz hdom hb hcap + have hφ := weight_pos hs + have hwb := hWbound _ _ hs + have hlog := Real.log_le_log (by linarith : 0 < z.cutoff) hcap + have hLb : 0 ≤ 1+Real.log z.cutoff := by have hh := Real.log_nonneg (show 1 ≤ z.cutoff by linarith); linarith + have hLB : 0 ≤ 1+Real.log B := by linarith + have hEpos := primeError_pos c w 2 + have hE := primeError_le_one hc.le w 2 + calc + _ ≤ C*weight z.side z.ratio*(1+Real.log z.cutoff)*primeError c w 2 := h w hw z hs hz hb hdom + _ ≤ C*W*(1+Real.log B)*1 := by gcongr + _ = _ := by ring + +theorem high_residual_sum_bound (d : ℝ) (hd : 0 < d) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node,start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → B^2*highResidualAbsoluteSum w B start ≤ C/B^6 := by + obtain ⟨CC,wC,hCC,hwC,hCrude⟩ := source_residual_crude + obtain ⟨CH,TH,wH,hCH,hTH,_hwH,hHigh⟩ := high_gap_residual_power d 10 hd (by norm_num) + obtain ⟨wT,_hwT,hTail⟩ := growing_gap_high_removal + obtain ⟨BT,hBT⟩ := eventually_atTop.mp (hTail 10) + obtain ⟨M,wM,hM,_hwM,hMass⟩ := total_prime_prefix_mass + let B₀ := max 4 (max BT (Real.exp TH)) + let w₀ := max wC (max wH (max wT wM)) + refine ⟨CC+CH*M,B₀,w₀,by positivity,by dsimp [B₀]; have h := le_max_left (4:ℝ) (max BT (Real.exp TH)); linarith, + hwC.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hB4 : 4 ≤ B := (le_max_left _ _).trans hB + have hBT' : BT ≤ B := ((le_max_left _ _).trans (le_max_right _ _)).trans hB + have hBexp : Real.exp TH ≤ B := ((le_max_right _ _).trans (le_max_right _ _)).trans hB + have hBpos : 0 < B := by linarith + have hBTlog : TH ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos _) hBexp + have hL2 : 2 ≤ Real.log B := hTH.trans hBTlog + have hL : 0 ≤ 1+Real.log B := by linarith + have hwC' : wC ≤ w := (le_max_left _ _).trans hw + have hwH' : wH ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwT' : wT ≤ w := (((le_max_left _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hw + have hwM' : wM ≤ w := (((le_max_right _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hw + obtain ⟨hs,hr,_hstart,_hsize⟩ := source_node_bounds hBpos start hi h199 h23 hcons hcut + let S := (Real.log B)^2 + let H := (uncappedPrefixes w 2 start).filter (actualHasHigh w S start) + have hPow := powerDecay_pos 10 B + have hDecay := powerDecay_nat hBpos 10 + norm_num only [Nat.cast_ofNat] at hDecay + have hsmall : uncappedLowGapHighMass w 2 start S (S/2) ≤ powerDecay 10 B := by + have hh := hBT B hBT' w hwT' (by linarith) start hcut hr hs hcons + simpa only [S,Real.rpow_neg hBpos.le,Real.rpow_ofNat,hDecay] using hh + have htotal : (∑ ps ∈ H,prefixWeight ps) ≤ M*B := by + apply le_trans (Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun ps _ _ => prefixWeight_nonneg ps)) + calc + _ ≤ ∑ ps ∈ decreasingPrefixes (primesBetween (w^(2:ℝ)) (w^start.cutoff)),prefixWeight ps := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun ps _ _ => prefixWeight_nonneg ps) + _ ≤ M*B := by rw [hcut]; have hh := hMass w hwM' 2 B (by norm_num) (by linarith); nlinarith [mul_pos hM hBpos] + have hpoint : ∀ ps ∈ H,|sourceResidual w (terminal w start ps)| ≤ + CC*(1+Real.log B)*(if (terminal w start ps).gap ≤ S/2 then 1 else 0)+CH*(1+Real.log B)*powerDecay 10 B := by + intro ps hp + have hpA : uncappedAllowed w 2 start ps := (Finset.mem_filter.mp (Finset.mem_filter.mp hp).1).2 + obtain ⟨hvs,hcs,hdom,hlo,hup,_hrp,_hsizep⟩ := source_terminal_geometry hB4 start hi h199 h23 hcons hcut hpA + by_cases hg : (terminal w start ps).gap ≤ S/2 + · rw [ite_eq_left hg,mul_one] + exact (hCrude w hwC' B _ hvs hcs hdom hlo.le hup).trans (le_add_of_nonneg_right (by positivity)) + · rw [ite_eq_right hg,mul_zero,zero_add] + exact hHigh B w hBpos hBTlog hwH' hcomp _ hvs hcs hdom hlo.le hup (le_of_lt (lt_of_not_ge hg)) + have hlowSum : (∑ ps ∈ H,prefixWeight ps*(if (terminal w start ps).gap ≤ S/2 then 1 else 0))= + uncappedLowGapHighMass w 2 start S (S/2) := by + unfold H uncappedLowGapHighMass + simp only [Finset.sum_filter] + apply Finset.sum_congr rfl + intro ps _hp + by_cases hh : actualHasHigh w S start ps <;> + by_cases hg : (terminal w start ps).gap ≤ S/2 <;> simp [hh,hg] + have hsum : highResidualAbsoluteSum w B start ≤ + CC*(1+Real.log B)*powerDecay 10 B+CH*(1+Real.log B)*powerDecay 10 B*(M*B) := by + have hh := Finset.sum_le_sum (fun ps hp => mul_le_mul_of_nonneg_left (hpoint ps hp) (prefixWeight_nonneg ps)) + have he : (∑ ps ∈ H,prefixWeight ps*(CC*(1+Real.log B)*(if (terminal w start ps).gap ≤ S/2 then 1 else 0)+ + CH*(1+Real.log B)*powerDecay 10 B))= + CC*(1+Real.log B)*(∑ ps ∈ H,prefixWeight ps*(if (terminal w start ps).gap ≤ S/2 then 1 else 0))+ + CH*(1+Real.log B)*powerDecay 10 B*(∑ ps ∈ H,prefixWeight ps) := by + rw [Finset.mul_sum,Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro ps _hp + ring + rw [he,hlowSum] at hh + exact hh.trans (add_le_add (mul_le_mul_of_nonneg_left hsmall (by positivity)) + (mul_le_mul_of_nonneg_left htotal (by positivity))) + have hB1 : 1 ≤ B := by linarith + have hLB : 1+Real.log B ≤ B := by linarith [Real.log_le_sub_one_of_pos hBpos] + have hcrudeB : CC*(1+Real.log B)*powerDecay 10 B ≤ CC*(1+Real.log B)*powerDecay 10 B*B := + le_mul_of_one_le_right (by positivity) hB1 + have hcombined : highResidualAbsoluteSum w B start ≤ (CC+CH*M)*B*(1+Real.log B)*powerDecay 10 B := by + nlinarith only [hsum,hcrudeB] + calc + _ ≤ B^2*((CC+CH*M)*B*(1+Real.log B)*powerDecay 10 B) := mul_le_mul_of_nonneg_left hcombined (sq_nonneg B) + _ ≤ B^2*((CC+CH*M)*B*B*powerDecay 10 B) := by gcongr + _ = _ := by rw [hDecay]; field_simp + +end NumberTheoryLean.HighResidualSum + + + +namespace NumberTheoryLean.SharpRetainedResidual + +attribute [local instance] Classical.propDecidable +open _root_.Filter _root_.Finset +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeKilledChain PrimeCorrectionFactor PrimeFamilyOccupation +open LowStateHorizon UniformBudgetRate ActualPrimeHigh SourceNodeCoordinates ResidualHistoryGeometry +open ReferenceLocalResidual ReferenceProductErrorBounds LowStateResidualBound +open ErdosPrimeInputs.PrimePrefixMass ErdosRetainedRewardTransfer + +noncomputable def retainedResidualAbsoluteSum (w B : ℝ) (start : Node) : ℝ := + ∑ ps ∈ retainedPrefixes w 2 ((Real.log B)^2) start,prefixWeight ps*|sourceResidual w (terminal w start ps)| + +theorem retained_residual_sum_bound (d : ℝ) (hd : 0 < d) : + ∃ c C B₀ w₀ : ℝ,0 < c ∧ 0 < C ∧ 0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node,start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + B^2*retainedResidualAbsoluteSum w B start ≤ C*((Real.log w)^16*primeError c w 2+1/B^4) := by + obtain ⟨c,CP,T,wP,hc,hCP,hT,hwP,hP⟩ := low_state_normalized_residual d hd + obtain ⟨wBudget,hwBudget⟩ := eventually_atTop.mp + ((correctionBudget_tendsto_zero d).eventually (eventually_le_nhds (by norm_num : (0:ℝ)<1))) + let A := 5*transferConstant*CP + have hA : 0 < A := by dsimp [A]; exact mul_pos (mul_pos (by norm_num) transferConstant_positive) hCP + let C := A*(d^16+1) + let B₀ := max 4 (Real.exp T) + let w₀ := max wP (max normalizationThreshold (max wBudget (Real.exp (d^2)))) + refine ⟨c,C,B₀,w₀,hc,by dsimp [C]; positivity,by dsimp [B₀]; have hh := le_max_left (4:ℝ) (Real.exp T); linarith, + hwP.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hB4 : 4 ≤ B := (le_max_left _ _).trans hB + have hBpos : 0 < B := by linarith + have hBexp : Real.exp T ≤ B := (le_max_right _ _).trans hB + have hBT : T ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos _) hBexp + have hlogB : 2 ≤ Real.log B := hT.trans hBT + have hL : 0 ≤ Real.log B := by linarith + have hwP' : wP ≤ w := (le_max_left _ _).trans hw + have hnorm : normalizationThreshold ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwBud : wBudget ≤ w := (((le_max_left _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hw + have hwExp : Real.exp (d^2) ≤ w := (((le_max_right _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hw + have hw1 : 1 < w := hwP.trans_le hwP' + have hlogw : d^2 ≤ Real.log w := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos _) hwExp + have hS := (source_scale_bound hlogw hlogB hcomp).1 + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hbudget := hwBudget w hwBud + let delta := CP*((Real.log B)^13*primeError c w 2+1/B^7) + have hE := primeError_pos c w 2 + have hdelta : 0 ≤ delta := by dsimp [delta]; positivity + have hF : ∀ ps ∈ retainedPrefixes w 2 ((Real.log B)^2) start, + (terminal w start ps).gap^2*|sourceResidual w (terminal w start ps)|/ + weight (terminal w start ps).side (terminal w start ps).ratio ≤ delta := by + intro ps hp + have hpA := (mem_retainedPrefixes hw1 start ps).mp hp + have hpU : uncappedAllowed w 2 start ps := + (uncapped_iff_exists_ceiling w 2 start ps).mpr ⟨(Real.log B)^2,hsS,hpA⟩ + obtain ⟨hvs,hcs,hdom,hlo,hup,_hrp,hgup⟩ := source_terminal_geometry hB4 start hi h199 h23 hcons hcut hpU + have hratio := terminal_ratio_le hsS hpA + have hh := hP B w hBpos hBT hwP' hcomp _ hvs hcs hdom hlo.le hup hgup hratio + calc + _ = ((terminal w start ps).gap^2/weight (terminal w start ps).side (terminal w start ps).ratio)* + |sourceResidual w (terminal w start ps)| := by ring + _ ≤ delta := hh + have hTransfer := retained_normalized_reward_sum (d:=d) (w:=w) (ell:=2) (B:=B) (delta:=delta) (start:=start) + hnorm (by norm_num) hS hsS hBpos hlogB hcomp hbudget hi h199 h23 hcons hcut hdelta + (fun ps => sourceResidual w (terminal w start ps)) hF + have hN := source_horizon_log_cube hlogB + have hraw : B^2*retainedResidualAbsoluteSum w B start ≤ + A*((Real.log B)^16*primeError c w 2+(Real.log B)^3/B^7) := by + calc + _ ≤ transferConstant*(sourceHorizon ((Real.log B)^2) B:ℝ)*delta := hTransfer + _ ≤ transferConstant*(5*(Real.log B)^3)*delta := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hN transferConstant_positive.le) hdelta + _ = _ := by dsimp [A,delta]; ring + have hlogw0 : 0 ≤ Real.log w := (Real.log_pos hw1).le + have hpower : (Real.log B)^16 ≤ d^16*(Real.log w)^16 := by + simpa only [mul_pow] using pow_le_pow_left₀ hL hcomp 16 + have hlogB_le : Real.log B ≤ B := by linarith [Real.log_le_sub_one_of_pos hBpos] + have hfrac : (Real.log B)^3/B^7 ≤ 1/B^4 := by + calc + _ ≤ B^3/B^7 := div_le_div_of_nonneg_right (pow_le_pow_left₀ hL hlogB_le 3) (by positivity) + _ = _ := by field_simp + have hterm := mul_le_mul_of_nonneg_right hpower hE.le + have hx : 0 ≤ (Real.log w)^16*primeError c w 2 := by positivity + have hy : 0 ≤ (1:ℝ)/B^4 := by positivity + calc + _ ≤ A*((Real.log B)^16*primeError c w 2+(Real.log B)^3/B^7) := hraw + _ ≤ A*(d^16*((Real.log w)^16*primeError c w 2)+1/B^4) := by + apply mul_le_mul_of_nonneg_left _ hA.le + exact add_le_add (by simpa only [mul_assoc] using hterm) hfrac + _ ≤ _ := by + dsimp only [C] + nlinarith only [mul_nonneg hA.le hx,mul_nonneg (mul_nonneg hA.le (pow_nonneg hd.le 16)) hy] + +end NumberTheoryLean.SharpRetainedResidual + + + +namespace NumberTheoryLean.SharpGlobalResidual + +open _root_.Filter _root_.Finset +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeFamilyOccupation +open ReferenceLocalResidual ReferenceResidualSum ReferenceSourceDecomposition ReferenceLogScale +open SharpRetainedResidual HighResidualSum + +theorem actual_residual_partition {w B : ℝ} (hw : 1 < w) {start : Node} + (hsS : start.ratio ≤ (Real.log B)^2) : + residualAbsoluteSum w start=retainedResidualAbsoluteSum w B start+highResidualAbsoluteSum w B start := + uncapped_sum_partition hw hsS (fun ps => ErdosPrimeInputs.PrimePrefixMass.prefixWeight ps*|sourceResidual w (terminal w start ps)|) + +theorem sharp_source_residual_sum (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node,start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → B^2*residualAbsoluteSum w start ≤ ε := by + obtain ⟨c,CL,BL,wL,hc,hCL,hBL,hwL,hLow⟩ := retained_residual_sum_bound d hd + obtain ⟨CH,BH,wH,hCH,_hBH,_hwH,hHigh⟩ := high_residual_sum_bound d hd + have hdec := log_power_primeError_tendsto CL 16 hc + obtain ⟨wE,hwE⟩ := eventually_atTop.mp + (hdec.eventually (eventually_le_nhds (show (0:ℝ)<ε/2 by linarith))) + let B₀ := max BL (max BH (max (Real.exp 2) (2*(CL+CH)/ε))) + let w₀ := max wL (max wH wE) + refine ⟨B₀,w₀,hBL.trans_le (le_max_left _ _),hwL.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBL' : BL ≤ B := (le_max_left _ _).trans hB + have hBH' : BH ≤ B := ((le_max_left _ _).trans (le_max_right _ _)).trans hB + have hBexp : Real.exp 2 ≤ B := (((le_max_left _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hB + have hBlarge : 2*(CL+CH)/ε ≤ B := (((le_max_right _ _).trans (le_max_right _ _)).trans (le_max_right _ _)).trans hB + have hBpos : 0 < B := hBL.trans_le hBL' + have hlogB : 2 ≤ Real.log B := by simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 2) hBexp + have hB1 : 1 ≤ B := (Real.log_nonneg_iff hBpos).mp (by linarith) + have hwL' : wL ≤ w := (le_max_left _ _).trans hw + have hwH' : wH ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwE' : wE ≤ w := ((le_max_right _ _).trans (le_max_right _ _)).trans hw + have hw1 : 1 < w := hwL.trans_le hwL' + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hlow := hLow B w hBL' hwL' hcomp start hi h199 h23 hcons hcut + have hhigh := hHigh B w hBH' hwH' hcomp start hi h199 h23 hcons hcut + have hB4 : B ≤ B^4 := by simpa only [pow_one] using pow_le_pow_right₀ hB1 (show (1:ℕ) ≤ 4 by norm_num) + have hB6 : B ≤ B^6 := by simpa only [pow_one] using pow_le_pow_right₀ hB1 (show (1:ℕ) ≤ 6 by norm_num) + have htail : CL/B^4+CH/B^6 ≤ ε/2 := by + have hfrac : CL/B^4+CH/B^6 ≤ (CL+CH)/B := by + calc + _ ≤ CL/B+CH/B := add_le_add + (div_le_div_of_nonneg_left hCL.le hBpos hB4) (div_le_div_of_nonneg_left hCH.le hBpos hB6) + _ = _ := by ring + apply hfrac.trans + apply (div_le_iff₀ hBpos).mpr + have hh := (div_le_iff₀ hε).mp hBlarge + nlinarith + have hsmall := hwE w hwE' + rw [mul_add,mul_one_div] at hlow + rw [actual_residual_partition hw1 hsS,mul_add] + nlinarith only [hlow,hhigh,htail,hsmall] + +theorem sharp_signed_residual (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node,start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → B^2*|residualCorrection w start| ≤ ε := by + obtain ⟨B₀,w₀,hB₀,hw₀,h⟩ := sharp_source_residual_sum d ε hd hε + refine ⟨B₀,w₀,hB₀,hw₀,?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + exact (mul_le_mul_of_nonneg_left (signed_residual_le_absolute w start) (sq_nonneg B)).trans + (h B w hB hw hcomp start hi h199 h23 hcons hcut) + +end NumberTheoryLean.SharpGlobalResidual + + + +namespace NumberTheoryLean.GlobalReferenceApproximation + +open FinitePathGeometry PrimeHistories PrimeBinMembership SourceNodeCoordinates +open ReferenceLocalResidual ReferenceSourceDecomposition UniformBoundaryCorrection SharpGlobalResidual + +theorem global_reference_remainder (d ε : ℝ) (hd : 0 < d) (hε : 0 < ε) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node,start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + B^2*|sourceReference w start-nodeBenchmark w start-boundaryCorrection w 2 start| ≤ ε := by + obtain ⟨B₁,w₀,hB₁,hw₀,h⟩ := sharp_signed_residual d ε hd hε + refine ⟨max B₁ 4,w₀,hB₁.trans_le (le_max_left _ _),hw₀,?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hB₁' : B₁ ≤ B := (le_max_left _ _).trans hB + have hB4 : 4 ≤ B := (le_max_right _ _).trans hB + have hBpos : 0 < B := by linarith + obtain ⟨hs,hr,_h1,_h2⟩ := source_node_bounds hBpos start hi h199 h23 hcons hcut + have he := actual_reference_decomposition (hw₀.trans_le hw) hs hr hcons (by rw [hcut]; linarith) + have heq : sourceReference w start-nodeBenchmark w start-boundaryCorrection w 2 start=residualCorrection w start := by linarith + rw [heq] + exact h B w hB₁' hw hcomp start hi h199 h23 hcons hcut + +end NumberTheoryLean.GlobalReferenceApproximation + + + +open _root_.Set _root_.Filter +open scoped Topology +namespace ErdosSourceReferenceMargin +open ErdosCorrectionLimit ErdosContinuousAnomaly +open NumberTheoryLean.ReferenceSourceDecomposition NumberTheoryLean.ReferenceLocalResidual +open NumberTheoryLean.UniformBoundaryCorrection NumberTheoryLean.GlobalReferenceApproximation + +theorem root_source_remainder_tendsto (a : ℝ) : + Tendsto (fun z => (ErdosInverseBoxHeight.sourceB z)^2* + (sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode a z)- + nodeBenchmark (ErdosInverseBoxHeight.sourceW z) (sourceRootNode a z)- + boundaryCorrection (ErdosInverseBoxHeight.sourceW z) 2 (sourceRootNode a z))) atTop (𝓝 0) := by + apply Metric.tendsto_nhds.mpr + intro eps heps + obtain ⟨B₀,w₀,_hB₀,_hw₀,h⟩ := global_reference_remainder 2 (eps/2) (by norm_num) (by linarith) + filter_upwards [actual_root_eventually a,rootB_tendsto.eventually (eventually_ge_atTop B₀), + rootW_tendsto.eventually (eventually_ge_atTop w₀)] with z hs hB hw + have hh := h (ErdosInverseBoxHeight.sourceB z) (ErdosInverseBoxHeight.sourceW z) hB hw hs.2.2.1 + (sourceRootNode a z) rfl hs.2.2.2.1 hs.2.2.2.2.1 hs.2.2.2.2.2.2 rfl + rw [Real.dist_eq,sub_zero,abs_mul,abs_of_nonneg (sq_nonneg _)] + exact hh.trans_lt (by linarith) + +theorem root_anomaly_replacement_tendsto (a : ℝ) : + Tendsto (fun z => (ErdosInverseBoxHeight.sourceB z)^2* + (boundaryCorrection (ErdosInverseBoxHeight.sourceW z) 2 (sourceRootNode a z)- + continuousBoundaryCorrection (ErdosInverseBoxHeight.sourceW z) 2 (sourceRootNode a z))) atTop (𝓝 0) := by + apply Metric.tendsto_nhds.mpr + intro eps heps + obtain ⟨B₀,w₀,_hB₀,_hw₀,h⟩ := actual_anomaly_replacement 2 2 (eps/2) le_rfl (by norm_num) (by linarith) + filter_upwards [actual_root_eventually a,rootB_tendsto.eventually (eventually_ge_atTop B₀), + rootW_tendsto.eventually (eventually_ge_atTop w₀)] with z hs hB hw + have hh := h (ErdosInverseBoxHeight.sourceB z) (ErdosInverseBoxHeight.sourceW z) hB hw hs.2.2.1 + (sourceRootNode a z) rfl hs.2.2.2.1 hs.2.2.2.2.1 hs.2.2.2.2.2.2 rfl + rw [Real.dist_eq,sub_zero,abs_mul,abs_of_nonneg (sq_nonneg _)] + exact hh.trans_lt (by linarith) + +end ErdosSourceReferenceMargin + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRepeatedRates.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRepeatedRates.lean new file mode 100644 index 0000000000000000000000000000000000000000..df6143a4e92e7565019e0db2e0aa0d57a55925a1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRepeatedRates.lean @@ -0,0 +1,151 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RepeatedPairProbability + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedBudgetRate +open _root_.Filter RepeatedStepRowBound ExponentialMesh +open scoped Topology + +theorem search_repeat_budget_small {A κ : ℝ} (hA : 0 ≤ A) (hκ : 0 < κ) {eps : ℝ} (heps : 0 < eps) : + ∀ᶠ w : ℝ in atTop,∀ S xi : ℝ,0 ≤ S → S ≤ (Real.log w)^3 → 0 ≤ xi → xi ≤ 1 → + ∀ N : ℕ,(N:ℝ) ≤ A*(Real.log w)^3 → + (N:ℝ)*repeatBudget S (w^((1/4:ℝ))) xi w (mesh κ w) ≤ eps := by + have hC := repeatDensityConstant_pos + have ht : Tendsto (fun w : ℝ => (Real.log w)^12/w^((1/4:ℝ))) atTop (𝓝 0) := by + simpa only [Real.rpow_ofNat] using + (isLittleO_log_rpow_rpow_atTop (12:ℝ) (s := (1/4:ℝ)) (by norm_num)).tendsto_div_nhds_zero + have hsum : Tendsto (fun w : ℝ => 9*A*repeatDensityConstant*((Real.log w)^12/w^((1/4:ℝ)))+ + 18*A*repeatDensityConstant*(Real.log w)^9*Real.exp (-κ*Real.sqrt (Real.log w))) atTop (𝓝 0) := by + simpa only [mul_zero,zero_add] using + (ht.const_mul (9*A*repeatDensityConstant)).add (log_power_exp_tendsto (18*A*repeatDensityConstant) 9 hκ) + filter_upwards [hsum.eventually (eventually_le_nhds heps), + Real.tendsto_log_atTop.eventually_ge_atTop 1,eventually_gt_atTop (1:ℝ)] with w hbound hlog hw + intro S xi hS0 hS hxi0 hxi1 N hN + have hm : 0 ≤ mesh κ w := (mesh_pos κ w).le + have hX : 0 < w^((1/4:ℝ)) := Real.rpow_pos_of_pos (zero_lt_one.trans hw) _ + have hL3 : 1 ≤ (Real.log w)^3 := one_le_pow₀ hlog + have hSplus : S+2 ≤ 3*(Real.log w)^3 := by linarith + have hsrc : xi/Real.log w ≤ 1 := (div_le_self hxi0 hlog).trans hxi1 + have hsrc0 : 0 ≤ xi/Real.log w := div_nonneg hxi0 (Real.log_pos hw).le + have hcoef : (N:ℝ)*repeatDensityConstant*(S+2)^2 ≤ 9*A*repeatDensityConstant*(Real.log w)^9 := by + calc + _ ≤ (A*(Real.log w)^3)*repeatDensityConstant*(3*(Real.log w)^3)^2 := by gcongr + _ = _ := by ring + have hnum : S*(xi/Real.log w) ≤ (Real.log w)^3 := by nlinarith [mul_le_mul_of_nonneg_left hsrc hS0] + have hwidth : S*(xi/Real.log w)/w^((1/4:ℝ))+2*mesh κ w ≤ + (Real.log w)^3/w^((1/4:ℝ))+2*Real.exp (-κ*Real.sqrt (Real.log w)) := + add_le_add (div_le_div_of_nonneg_right hnum hX.le) (mul_le_mul_of_nonneg_left (mesh_upper κ w) (by norm_num)) + calc + _ = ((N:ℝ)*repeatDensityConstant*(S+2)^2)*(S*(xi/Real.log w)/w^((1/4:ℝ))+2*mesh κ w) := by + unfold repeatBudget + ring + _ ≤ (9*A*repeatDensityConstant*(Real.log w)^9)* + ((Real.log w)^3/w^((1/4:ℝ))+2*Real.exp (-κ*Real.sqrt (Real.log w))) := + mul_le_mul hcoef hwidth (show 0 ≤ S*(xi/Real.log w)/w^((1/4:ℝ))+2*mesh κ w by positivity) + (show 0 ≤ 9*A*repeatDensityConstant*(Real.log w)^9 by positivity) + _ = 9*A*repeatDensityConstant*((Real.log w)^12/w^((1/4:ℝ)))+ + 18*A*repeatDensityConstant*(Real.log w)^9*Real.exp (-κ*Real.sqrt (Real.log w)) := by ring + _ ≤ _ := hbound + +theorem compact_repeat_budget_small {L κ : ℝ} (hL : 0 ≤ L) (hκ : 0 < κ) {eps : ℝ} (heps : 0 < eps) : + ∀ᶠ w : ℝ in atTop,∀ xi : ℝ,0 ≤ xi → xi ≤ 1 → + repeatBudget L 1 xi w (mesh κ w)*(L+1) ≤ eps := by + have hC := repeatDensityConstant_pos + have ht : Tendsto (fun w : ℝ => 1/Real.log w) atTop (𝓝 0) := by + simpa only [one_div,Function.comp_def] using tendsto_inv_atTop_zero.comp Real.tendsto_log_atTop + have hsum : Tendsto (fun w : ℝ => repeatDensityConstant*(L+2)^2*(L+1)* + (L*(1/Real.log w)+2*Real.exp (-κ*Real.sqrt (Real.log w)))) atTop (𝓝 0) := by + have hh := ((ht.const_mul L).add (log_power_exp_tendsto 2 0 hκ)).const_mul (repeatDensityConstant*(L+2)^2*(L+1)) + simpa only [pow_zero,mul_one,mul_zero,add_zero] using hh + filter_upwards [hsum.eventually (eventually_le_nhds heps),eventually_gt_atTop (1:ℝ)] with w hw hw1 + intro xi hxi0 hxi1 + have hlog := Real.log_pos hw1 + have hxi : xi/Real.log w ≤ 1/Real.log w := div_le_div_of_nonneg_right hxi1 hlog.le + have hwidth := add_le_add (mul_le_mul_of_nonneg_left hxi hL) (mul_le_mul_of_nonneg_left (mesh_upper κ w) (by norm_num : (0:ℝ)≤2)) + calc + _ = (repeatDensityConstant*(L+2)^2*(L+1))*(L*(xi/Real.log w)+2*mesh κ w) := by unfold repeatBudget; ring + _ ≤ (repeatDensityConstant*(L+2)^2*(L+1))*(L*(1/Real.log w)+2*Real.exp (-κ*Real.sqrt (Real.log w))) := + mul_le_mul_of_nonneg_left hwidth (by positivity) + _ ≤ _ := hw +end NumberTheoryLean.RepeatedBudgetRate + + + +namespace NumberTheoryLean.SourceRepeatedRates +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open ActualCoupledHistories FlaggedSourceStart SourceSelectedCompactOccupation SourceCouplingRate +open RepeatedStepRowBound RepeatedPairEvents RepeatedPairProbability RepeatedBudgetRate +open FinitePairOccurrence ExponentialMesh LowStateHorizon PersistentFailureFlag +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels + +theorem source_repeated_pair_probabilities : ∃ κ₀ : ℝ,0 < κ₀ ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ D L eps : ℝ,0 < D → 0 ≤ L → 0 < eps → + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∃ hw : 1 < w, + ∀ top : ℝ,∀ htop : w < top,∀ ell B : ℝ, + ∀ start : Node,∀ hs : Valid start.side start.ratio, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ D*Real.log w → + 0 < start.gap → start.ratio ≤ 23/10 → Consistent start → start.gap ≤ (23/10:ℝ)*B → w^start.cutoff=top → + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → + let S := (Real.log B)^2 + let N := sourceHorizon S B + (fullSourceLaw w ell S start hs (mesh κ w) N + (pairOccurrence (rawRepeatPair (label (zero_lt_one.trans hw) htop hxi) (w^((1/4:ℝ))) S Set.univ) N) ≤ ENNReal.ofReal eps) ∧ + (fullSourceLaw w ell S start hs (mesh κ w) N + (pairOccurrence (rawRepeatPair (label (zero_lt_one.trans hw) htop hxi) 1 L (compactParentGate L)) N) ≤ ENNReal.ofReal eps) := by + obtain ⟨κ₀,hκ₀,hCouple⟩ := source_coupling_rate + refine ⟨κ₀,hκ₀,?_⟩ + intro κ hκ hκle D L eps hD hL heps + obtain ⟨WC,hWC,hC⟩ := hCouple κ hκ hκle D hD + have hA : 0 ≤ 5*D^3 := by positivity + have hEvents := (search_repeat_budget_small hA hκ (show 0 < eps/2 by positivity)).and + ((compact_repeat_budget_small hL hκ (show 0 < eps/2 by positivity)).and + (((log_power_exp_tendsto 1 0 (show 0 < κ/2 by positivity)).eventually + (eventually_le_nhds (show 0 < eps/2 by positivity))).and + (Real.tendsto_log_atTop.eventually_ge_atTop (D^2)))) + obtain ⟨W,hW⟩ := eventually_atTop.mp hEvents + refine ⟨max WC (max normalizationThreshold W),hWC.trans_le (le_max_left _ _),?_⟩ + intro w hw₀ + have hnorm : normalizationThreshold ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw₀ + have hw : 1 < w := normalizationThreshold_gt_one.trans_le hnorm + refine ⟨hw,?_⟩ + intro top htop ell B start hs hell hB hlogB hcomp hr hs23 hc hsize hcap xi hxi hxi1 + dsimp only + have hwC : WC ≤ w := (le_max_left _ _).trans hw₀ + have hwe := hW w ((le_trans (le_max_right _ _) (le_max_right _ _)).trans hw₀) + have hscale := UniformBudgetRate.source_scale_bound hwe.2.2.2 hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + let N := sourceHorizon ((Real.log B)^2) B + have hf := (hC w hwC ell B start hs hell hB hlogB hcomp hr hs23 hc hsize).1 N le_rfl |>.1 + have hfail : Real.exp (-(κ/2)*Real.sqrt (Real.log w)) ≤ eps/2 := by + simpa only [pow_zero,mul_one,one_mul] using hwe.2.2.1 + have hf' : FlaggedSourceStart.sourceLaw hnorm hell hS0 hscale.1 hr hs hsS (mesh κ w) N failed ≤ ENNReal.ofReal (eps/2) := + hf.trans (ENNReal.ofReal_le_ofReal hfail) + have hm := mesh_pos κ w + have hmesh := mesh_le_one hκ.le w + have hSearch := hwe.1 ((Real.log B)^2) xi hS0 hscale.1 hxi.le hxi1 N hscale.2 + have hCompact := hwe.2.1 xi hxi.le hxi1 + have hsum : ENNReal.ofReal (eps/2)+ENNReal.ofReal (eps/2)=ENNReal.ofReal eps := by + rw [← ENNReal.ofReal_add (by positivity : 0 ≤ eps/2) (by positivity : 0 ≤ eps/2)] + congr 1 + ring + constructor + · have hraw := raw_repeat_probability_le_good hnorm hell hS0 hscale.1 hr hs hsS + (label (zero_lt_one.trans hw) htop hxi) (w^((1/4:ℝ))) ((Real.log B)^2) Set.univ hm N + have hgood := good_repeat_probability_uniform hnorm hell hS0 hscale.1 hr hs hsS hw htop hxi hS0 + (Real.rpow_pos_of_pos (zero_lt_one.trans hw) (1/4:ℝ)) hm hmesh hcap N Set.univ + exact hraw.trans ((add_le_add hf' (hgood.trans (ENNReal.ofReal_le_ofReal hSearch))).trans_eq hsum) + · have hraw := raw_repeat_probability_compact hnorm hell hS0 hscale.1 hr hs hsS hw htop hxi hL hm hmesh hcap N + exact hraw.trans ((add_le_add hf' (ENNReal.ofReal_le_ofReal hCompact)).trans_eq hsum) +end NumberTheoryLean.SourceRepeatedRates + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRichPoints.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRichPoints.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c276a215186ad0c04ea2c5c11834dcdeba718f9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRichPoints.lean @@ -0,0 +1,336 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceRefinedCell + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseTail + +theorem commonParentLength_le_ratio (Y p q : ℕ) (hp : 0 < p) (hq : 0 < q) + (Qplus : ℝ) (hqQ : (q : ℝ) ≤ Qplus) : + (commonParentLength Y p Qplus : ℝ) ≤ (Y : ℝ)/((p : ℝ)*q) := by + have hpR : (0 : ℝ) < p := by exact_mod_cast hp + have hqR : (0 : ℝ) < q := by exact_mod_cast hq + have hQ : 0 < Qplus := hqR.trans_le hqQ + exact (Nat.floor_le (by positivity : 0 ≤ (Y : ℝ)/((p : ℝ)*Qplus))).trans + (div_le_div_of_nonneg_left (Nat.cast_nonneg _) (mul_pos hpR hqR) + (mul_le_mul_of_nonneg_left hqQ hpR.le)) + +theorem strict_deviation_transfer (A B m e u T delta : ℝ) (hu : 0 < u) + (hT : 0 ≤ T) (hd : 0 < delta) (hbad : delta*T < |B-A/u|) + (herr : |B-e|+|A-m|/u ≤ (delta/2)*T) : + (delta/4)*T < |e-m/u| := by + have htri : |B-A/u| ≤ |B-e|+|e-m/u|+|A-m|/u := by + calc + _ ≤ |B-e|+|e-A/u| := abs_sub_le B e (A/u) + _ ≤ |B-e|+(|e-m/u|+|m/u-A/u|) := add_le_add le_rfl (abs_sub_le e (m/u) (A/u)) + _ = _ := by rw [← sub_div,abs_div,abs_of_pos hu,abs_sub_comm m A];ring + nlinarith + +end ErdosInverseTail + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseTail +open NumberTheoryLean ErdosInverseHits ErdosInverseFrozen ErdosInverseEuler ErdosInverseCounts ErdosInverseBoxHeight + +theorem source_bad_edge_implies_frozen (aStar delta : ℝ) (ha : 0 < aStar) (hd : 0 < delta) : + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ ∀ xi : ℝ,0 < xi → xi ≤ xi0 → + ∀ᶠ z : ℝ in atTop,∀ (a : ℕ → ℕ) (p q q0 u : ℕ) [NeZero p] [NeZero u] + (_hp : p.Prime) (_hu : u.Prime) (hqp : q.Coprime p) (hq : Squarefree q) + (hpu : p.Coprime u) (hqu : q.Coprime u) (Qplus : ℝ) (b0 v : ℤ), + (q : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q : ℝ) → + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q*u).Coprime t) → + Int.ModEq (smallModulus (sourceW z) : ℤ) (q : ℤ) (q0 : ℤ) → + Int.ModEq (smallModulus (sourceW z) : ℤ) (primeHitRepresentative q hq a : ℤ) b0 → + Int.ModEq (smallModulus (sourceW z) : ℤ) + (parentSlope p q hqp (a p) (primeHitRepresentative q hq a) : ℤ) v → + WitnessingBadEdge (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) p q u → + parentEdgeResidue p q u hqp hq hpu hqu a ∈ + frozenExceptional (commonParentLength (sourceY z) p Qplus) (sourceW z) p q0 b0 v a u + (delta/4) (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) := by + obtain ⟨C,hC,hreplacement⟩ := source_interval_replacement aStar ha + have hden : 0 < 12*C := by positivity + refine ⟨min 1 (delta/(12*C)),lt_min zero_lt_one (div_pos hd hden),min_le_left _ _,?_⟩ + intro xi hxi hxibound + have hxi1 : xi ≤ 1 := hxibound.trans (min_le_left _ _) + have hxiBudget := (le_div_iff₀ hden).mp (hxibound.trans (min_le_right _ _)) + have hbudget : 6*C*xi ≤ delta/2 := by nlinarith + filter_upwards [hreplacement xi hxi hxi1,sourceW_tendsto_atTop.eventually_ge_atTop 2] with z hrepl hw + intro a p q q0 u instP instU hp hu hqp hq hpu hqu Qplus b0 v hqQ hQq hlog hcop hqq hbb hsv hbad + let J := commonParentLength (sourceY z) p Qplus + let V0 := SmallSieveFinite.smallEuler ⌊sourceW z⌋₊ + let A : ℝ := modulusCount (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a (p*q) + let B : ℝ := modulusCount (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a (p*q*u) + let m : ℝ := (frozenCoordinates J (sourceW z) p q0 b0 v a).card + let e : ℝ := ((frozenCoordinates J (sourceW z) p q0 b0 v a).filter + (fun j : ℕ => (j : ZMod u) = parentEdgeResidue p q u hqp hq hpu hqu a)).card + let T : ℝ := (J : ℝ)*V0/(u : ℝ) + have huR : (0 : ℝ) < u := by exact_mod_cast hu.pos + have hwpos : 0 < sourceW z := by linarith + have hV : 0 < V0 := (inv_pos.mpr hwpos).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv (sourceW z) hw) + have hT : 0 ≤ T := by dsimp [T];positivity + have herr := hrepl a p q q0 u hp hu hqp hq hpu hqu Qplus b0 v hqQ hQq hlog hcop hqq hbb hsv + change |A-m| ≤ 2*C*xi*(J : ℝ)*V0 ∧ |B-e| ≤ 4*C*xi*(J : ℝ)*V0/(u : ℝ) at herr + have hJR := commonParentLength_le_ratio (sourceY z) p q hp.pos (Nat.pos_of_ne_zero hq.ne_zero) Qplus hqQ + have hnorm : delta*T ≤ delta*(sourceY z : ℝ)*V0/((p : ℝ)*q*u) := by + calc + _ = (delta*V0/(u : ℝ))*(J : ℝ) := by dsimp [T];ring + _ ≤ (delta*V0/(u : ℝ))*((sourceY z : ℝ)/((p : ℝ)*q)) := + mul_le_mul_of_nonneg_left hJR (by positivity) + _ = _ := by simp only [div_eq_mul_inv,mul_inv_rev];ring + have hbad' : delta*(sourceY z : ℝ)*V0/((p : ℝ)*q*u) < |B-A/(u : ℝ)| := by + simpa only [WitnessingBadEdge,NodeBadEdge,Nat.cast_mul] using hbad + have herrsum : |B-e|+|A-m|/(u : ℝ) ≤ (delta/2)*T := by + calc + _ ≤ 4*C*xi*(J : ℝ)*V0/(u : ℝ)+(2*C*xi*(J : ℝ)*V0)/(u : ℝ) := + add_le_add herr.2 (div_le_div_of_nonneg_right herr.1 huR.le) + _ = (6*C*xi)*T := by dsimp [T];ring + _ ≤ _ := mul_le_mul_of_nonneg_right hbudget hT + have hdev := strict_deviation_transfer A B m e (u : ℝ) T delta huR hT hd + (hnorm.trans_lt hbad') herrsum + rw [mem_frozenExceptional] + change (delta/4)*(J : ℝ)*V0/(u : ℝ) < |e-m/(u : ℝ)| + simpa only [T,mul_div_assoc,mul_assoc] using hdev + +end ErdosInverseTail + +end + +section + +namespace ErdosInverseRefinement +open ErdosInverseCells ErdosInverseSampling ErdosInverseSampleCost ErdosInverseHits ErdosInverseStructured +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem selectedRow_subset_nonstructured (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp : ℝ) (P U : Finset ℕ) (h : ℕ) (hh : 0 < h) (s : Sample U h) + (T : ℕ → Finset ℤ) (q : ℕ) (hP : ∀ p ∈ P,p.Prime) (hqp : ∀ p ∈ P,q.Coprime p) + (htest : ∀ p ∈ P,∀ [NeZero p],∀ hcop : q.Coprime p, + p ∈ selectedRow P U (actualWitness Y small a delta V0 P S R Z cp) h s q → + (parentSlope p q hcop (a p) (cofactorHit q a) : ℤ) ∈ T p) : + selectedRow P U (actualWitness Y small a delta V0 P S R Z cp) h s q ⊆ + nonstructuredPrimes P (fun p => (a p : ℤ)) T S R Z cp (cofactorPoint a q) := by + intro p hp + have hm := Finset.mem_filter.mp hp + let : NeZero p := ⟨(hP p hm.1).ne_zero⟩ + have hn := (hm.2 ⟨0,hh⟩).1 + apply Finset.mem_filter.mpr + refine ⟨hm.1,?_⟩ + refine ⟨parentSlope_incidence a T p q (hqp p hm.1) (htest p hm.1 (hqp p hm.1) hp),?_⟩ + simpa only [cofactorPoint,Int.toNat_natCast] using hn + +theorem rich_points_incidence (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 S R Z cp gamma : ℝ) (D P U : Finset ℕ) (h : ℕ) (hh : 0 < h) (s : Sample U h) + (T : ℕ → Finset ℤ) (hP : ∀ p ∈ P,p.Prime) (hPpos : 0 < P.card) + (hqp : ∀ q ∈ D,∀ p ∈ P,q.Coprime p) + (htest : ∀ q ∈ D,∀ p ∈ P,∀ [NeZero p],∀ hcop : q.Coprime p, + p ∈ selectedRow P U (actualWitness Y small a delta V0 P S R Z cp) h s q → + (parentSlope p q hcop (a p) (cofactorHit q a) : ℤ) ∈ T p) : + ∀ v ∈ cofactorPoints (richCofactors D P U (actualWitness Y small a delta V0 P S R Z cp) h s gamma) a, + (gamma/8)*(P.card : ℝ) ≤ + ((nonstructuredPrimes P (fun p => (a p : ℤ)) T S R Z cp v).card : ℝ) := by + intro v hv + obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hv + have hqD := richCofactors_subset D P U _ h s gamma hq + calc + _ ≤ ((selectedRow P U (actualWitness Y small a delta V0 P S R Z cp) h s q).card : ℝ) := + richCofactor_row_card D P U _ h s gamma hPpos q hq + _ ≤ _ := by + exact_mod_cast Finset.card_le_card (selectedRow_subset_nonstructured Y small a delta V0 S R Z cp + P U h hh s T q hP (hqp q hqD) (htest q hqD)) + +end ErdosInverseRefinement + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseRefinement +open NumberTheoryLean ErdosInverseCells ErdosInverseSampling ErdosInverseSampleCost + ErdosInverseCRT ErdosInverseEuler ErdosInverseHits ErdosInverseStructured ErdosInverseTail + ErdosInverseBoxHeight + +theorem source_parentSlope_mem (aStar delta : ℝ) (ha : 0 < aStar) (hd : 0 < delta) : + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ ∀ xi : ℝ,0 < xi → xi ≤ xi0 → + ∀ᶠ z : ℝ in atTop,∀ (P U C : Finset ℕ) (a : ℕ → ℕ) (h : ℕ) (s : Sample U h) + (_hU : ∀ u ∈ U,u.Prime) (hpU : ∀ p ∈ P,∀ u ∈ U,p.Coprime u) + (qRef : ℕ) (hqRef : ∀ u ∈ U,qRef.Coprime u) + (j : RefinementLabel (sampleModulus U h s)) + (q p qInitial : ℕ) [NeZero p] (bInitial : ℤ) (Qplus : ℝ) + (_hp : p.Prime) (_hpP : p ∈ P) (hqp : q.Coprime p) (_hq : Squarefree q) + (_hqU : ∀ u ∈ U,q.Coprime u), + q ∈ refinementCell C a (sampleModulus U h s) j → + qRef ∈ refinementCell C a (sampleModulus U h s) j → + (q : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q : ℝ) → + (∀ u ∈ U,3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z)) → + (∀ u ∈ U,∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q*u).Coprime t) → + Int.ModEq (smallModulus (sourceW z) : ℤ) (q : ℤ) (qInitial : ℤ) → + Int.ModEq (smallModulus (sourceW z) : ℤ) (cofactorHit q a : ℤ) bInitial → + (∀ i : Fin h,ErdosInverseCounts.WitnessingBadEdge (sourceY z) + (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) p q (s i).val) → + (parentSlope p q hqp (a p) (cofactorHit q a) : ℤ) ∈ + pointSlopes (sourceY z) (sourceW z) Qplus qInitial bInitial a (delta/4) + P U h s hpU qRef (cofactorHit qRef a) hqRef p := by + obtain ⟨xi0,hxi0,hxi01,htransfer⟩ := source_bad_edge_implies_frozen aStar delta ha hd + refine ⟨xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + filter_upwards [htransfer xi hxi hxib] with z hz + intro P U C a h s hU hpU qRef hqRef j q p qInitial instP bInitial Qplus hp hpP hqp hq hqU + hqC hRefC hqQ hQq hlog hsmall hqq hbb hbad + let : NeZero (smallModulus (sourceW z)) := ⟨(smallModulus_pos _).ne'⟩ + let t : ℤ := parentSlope p q hqp (a p) (cofactorHit q a) + have ht : t ∈ Finset.Ico (0 : ℤ) (p : ℤ) := by + apply Finset.mem_Ico.mpr + refine ⟨Int.natCast_nonneg _,?_⟩ + dsimp only [t] + exact_mod_cast parentSlope_lt p q hqp (a p) (cofactorHit q a) + have hts : Int.ModEq (smallModulus (sourceW z) : ℤ) t + ((t : ZMod (smallModulus (sourceW z))).val : ℤ) := by + apply (ZMod.intCast_eq_intCast_iff _ _ _).mp + simp only [Int.cast_natCast,ZMod.natCast_zmod_val] + rw [pointSlopes_eq _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ hpP] + apply mem_sourceTestedSlopes_of_same_cell p q qRef _ (fun i => (s i).val) + (fun i => hpU p hpP _ (s i).property) (fun i => hqU _ (s i).property) + (fun i => hqRef _ (s i).property) (fun u => (a u : ℤ)) + (cofactorHit q a) (cofactorHit qRef a) t _ ht + · intro i + exact (refinement_sample_congruences C U a h s j q qRef hqC hRefC i).1 + · intro i + simpa only [Int.cast_natCast] using + (refinement_sample_congruences C U a h s j q qRef hqC hRefC i).2 + · intro i + let : NeZero (s i).val := ⟨(hU _ (s i).property).ne_zero⟩ + have hbb' : Int.ModEq (smallModulus (sourceW z) : ℤ) + (primeHitRepresentative q hq a : ℤ) bInitial := by + simpa only [cofactorHit_eq q hq a] using hbb + have hts' : Int.ModEq (smallModulus (sourceW z) : ℤ) + (parentSlope p q hqp (a p) (primeHitRepresentative q hq a) : ℤ) + ((t : ZMod (smallModulus (sourceW z))).val : ℤ) := by + simpa only [t,cofactorHit_eq q hq a] using hts + have he := hz a p q qInitial (s i).val hp (hU _ (s i).property) hqp hq + (hpU p hpP _ (s i).property) (hqU _ (s i).property) Qplus bInitial + ((t : ZMod (smallModulus (sourceW z))).val : ℤ) hqQ hQq + (hlog _ (s i).property) (hsmall _ (s i).property) hqq hbb' hts' (hbad i) + simpa only [actualFamily,parentEdgeResidue,t,cofactorHit_eq q hq a] using he + +end ErdosInverseRefinement + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseRefinement +open NumberTheoryLean ErdosInverseCells ErdosInverseSampling ErdosInverseSampleCost + ErdosInverseEuler ErdosInverseHits ErdosInverseStructured ErdosInverseTail + ErdosInverseBoxHeight ErdosInversePrimeBin ErdosConvexGraph + +theorem source_rich_points (aStar delta K gamma : ℝ) (h : ℕ) + (ha : 0 < aStar) (hd : 0 < delta) (hK : 0 ≤ K) (hg : 0 < gamma) (hh : 0 < h) : + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ ∀ xi : ℝ,0 < xi → xi ≤ xi0 → + ∀ᶠ z : ℝ in atTop,∀ (P C : Finset ℕ) (a : ℕ → ℕ) (U theta Qplus S R cp : ℝ) + (qInitial : ℕ) (bInitial : ℤ), + 0 < R → 0 < S → sourceW z ≤ U → U ≤ (sourceW z)^K → 0 ≤ theta → theta ≤ 1 → + 0 < P.card → (∀ p ∈ P,p.Prime) → + (∀ p ∈ P,∀ u ∈ primeBin U theta,p.Coprime u) → + (∀ q ∈ C,Squarefree q ∧ (q : ℝ) ≤ S) → + (∀ q ∈ C,∀ p ∈ P,q.Coprime p) → + (∀ q ∈ C,∀ u ∈ primeBin U theta,q.Coprime u) → + (∀ q ∈ C,(q : ℝ) ≤ Qplus ∧ Qplus ≤ (1+xi)*(q : ℝ)) → + (∀ q ∈ C,∀ p ∈ P,∀ u ∈ primeBin U theta, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z)) → + (∀ q ∈ C,∀ p ∈ P,∀ u ∈ primeBin U theta, + ∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q*u).Coprime t) → + (∀ q ∈ C,Int.ModEq (smallModulus (sourceW z) : ℤ) (q : ℤ) (qInitial : ℤ) ∧ + Int.ModEq (smallModulus (sourceW z) : ℤ) (cofactorHit q a : ℤ) bInitial) → + S/sourceZ z ≤ (C.card : ℝ) → + ∀ s : Sample (primeBin U theta) h, + gamma/2 ≤ selectedFraction (P.product C) (primeBin U theta) + (actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) cp) h s → + actualCost (sourceY z) (sourceW z) Qplus R qInitial bInitial a (delta/4) + P (primeBin U theta) h s ≤ 1/(Real.log z)^6 → + ∃ (T : ℕ → Finset ℤ) (D : Finset ℕ),D ⊆ C ∧ + (∀ v ∈ cofactorPoints D a,InSquare S v) ∧ + Set.InjOn Prod.fst (cofactorPoints D a : Set (ℤ × ℤ)) ∧ + S/(sourceZ z)^4 ≤ ((cofactorPoints D a).card : ℝ) ∧ + (∀ v ∈ cofactorPoints D a,∀ ell ∈ v.1.toNat.primeFactors, + (v.2 : ZMod ell) = (a ell : ZMod ell)) ∧ + (∀ v ∈ cofactorPoints D a,(gamma/8)*(P.card : ℝ) ≤ + ((nonstructuredPrimes P (fun p => (a p : ℤ)) T S R (sourceZ z) cp v).card : ℝ)) ∧ + (∑ p ∈ P,((T p).card : ℝ)) ≤ (P.card : ℝ)*R/(Real.log z)^6 := by + classical + obtain ⟨xi0,hxi0,hxi01,hparent⟩ := source_parentSlope_mem aStar delta ha hd + refine ⟨xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + filter_upwards [hparent xi hxi hxib,source_refined_cell K gamma h hK hg, + sourceZ_tendsto_atTop.eventually_ge_atTop (8/gamma),sourceW_tendsto_atTop.eventually_ge_atTop 2] + with z hparentZ hrefine hZlarge hW + intro P C a U theta Qplus S R cp qInitial bInitial hR hS hWU hUtop htheta htheta1 hPpos hP + hpU hCsq hCP hCU hCQ hlog hsmall hcong hCsize s hreward hcost + have hW0 : 0 ≤ sourceW z := by linarith + have hU0 : 0 ≤ U := hW0.trans hWU + let Uset := primeBin U theta + have hUprime : ∀ u ∈ Uset,u.Prime := fun u hu => ((mem_primeBin hU0 htheta u).mp hu).1 + have huLarge : ∀ u ∈ Uset,sourceW z < (u : ℝ) := by + intro u hu + exact hWU.trans_lt ((mem_primeBin hU0 htheta u).mp hu).2.1 + let witness := actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) cp + obtain ⟨j,hjSize,hjNonempty,hjReward⟩ := hrefine U theta hU0 hUtop htheta htheta1 s P C a + witness S hPpos hS hCsize hreward + let C' := refinementCell C a (sampleModulus Uset h s) j + have hC'C : C' ⊆ C := fun q hq => (mem_refinementCell C a _ j q).mp hq |>.1 + obtain ⟨qRef,hqRef⟩ := hjNonempty + have hRefU : ∀ u ∈ Uset,qRef.Coprime u := hCU qRef (hC'C hqRef) + let T := pointSlopes (sourceY z) (sourceW z) Qplus qInitial bInitial a (delta/4) + P Uset h s hpU qRef (cofactorHit qRef a) hRefU + let D := richCofactors C' P Uset witness h s gamma + have hDC' : D ⊆ C' := richCofactors_subset C' P Uset witness h s gamma + have hDC : D ⊆ C := hDC'.trans hC'C + have hZ : 0 < sourceZ z := Real.exp_pos _ + have hInv : 1/sourceZ z ≤ gamma/8 := by + apply (div_le_iff₀ hZ).mpr + have hmul := (div_le_iff₀ hg).mp hZlarge + nlinarith + have htests : ∀ q ∈ C',∀ p ∈ P,∀ [NeZero p],∀ hcop : q.Coprime p, + p ∈ selectedRow P Uset witness h s q → + (parentSlope p q hcop (a p) (cofactorHit q a) : ℤ) ∈ T p := by + intro q hq p hp instP hcop hselected + have hqC := hC'C hq + have hselected' := Finset.mem_filter.mp hselected + exact hparentZ P Uset C a h s hUprime hpU qRef hRefU j q p qInitial bInitial Qplus + (hP p hp) hp hcop (hCsq q hqC).1 (hCU q hqC) hq hqRef + (hCQ q hqC).1 (hCQ q hqC).2 (hlog q hqC p hp) (hsmall q hqC p hp) + (hcong q hqC).1 (hcong q hqC).2 (fun i => (hselected'.2 i).2) + refine ⟨T,D,hDC,cofactorPoints_square D a S (fun q hq => hCsq q (hDC hq)), + cofactorPoints_x_injective D a,?_,cofactorPoints_prime_hits D a (fun q hq => (hCsq q (hDC hq)).1),?_,?_⟩ + · exact rich_points_source_size C' P Uset a witness h s gamma S (sourceZ z) hg hS.le hZ hPpos + hjSize hInv hjReward.le + · exact rich_points_incidence (sourceY z) _ a delta _ S R (sourceZ z) cp gamma C' P Uset h hh s T + hP hPpos (fun q hq => hCP q (hC'C hq)) htests + · exact pointSlopes_thin (sourceY z) (sourceW z) Qplus R (Real.log z) qInitial bInitial a (delta/4) + P Uset h s hW0 hR hPpos hUprime huLarge hpU hcost qRef (cofactorHit qRef a) hRefU + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRichSetContradiction.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRichSetContradiction.lean new file mode 100644 index 0000000000000000000000000000000000000000..fff7e3676ed26a9ca311e7d964c1e900e11fda98 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRichSetContradiction.lean @@ -0,0 +1,162 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimePartitionCounts + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseStructured +open ErdosSourceCollision ErdosLineCollision ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment ErdosConvexGraph +attribute [local instance] Classical.propDecidable + +theorem nonstructuredPoints_eq_empty_of_aligned {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (S R Z cp : ℝ) + (hlist : r.rational ∈ sourceRationalList P a S R Z cp) (hden : (l.denominator : ℝ) ≤ R*Z^10) + (hline : ∀ v ∈ X,l.Contains v) (hbox : ∀ v ∈ X,InSquare S v) + (hclass : ∀ v ∈ X,∀ ell ∈ v.1.toNat.primeFactors,(v.2 : ZMod ell) = (a ell : ZMod ell)) + (p : ℕ) (halign : aligns a r.rational p) : nonstructuredPoints P X a T S R Z cp p = ∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro v hv + obtain ⟨hvX,_hslope,hnon⟩ := Finset.mem_filter.mp hv + exact hnon (structured_of_line_alignment r P a S R Z cp p v.1.toNat v.2 hlist hden + (contains_nat_abscissa l v (hbox v hvX).1.1 (hline v hvX)) (hclass v hvX) halign) + +theorem nonstructured_total_le_bad {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (S R Z cp : ℝ) + (hlist : r.rational ∈ sourceRationalList P a S R Z cp) (hden : (l.denominator : ℝ) ≤ R*Z^10) + (hline : ∀ v ∈ X,l.Contains v) (hbox : ∀ v ∈ X,InSquare S v) + (hclass : ∀ v ∈ X,∀ ell ∈ v.1.toNat.primeFactors,(v.2 : ZMod ell) = (a ell : ZMod ell)) : + (∑ p ∈ P,((nonstructuredPoints P X a T S R Z cp p).card : ℝ)) ≤ + (∑ p ∈ unalignedPrimes P a r,((incidentPoints X (a p) p (T p)).card : ℝ))+ + (∑ p ∈ ignoredPrimes P l.denominator,((incidentPoints X (a p) p (T p)).card : ℝ)) := by + have hpart := prime_sum_partition_le r P a + (fun p => ((nonstructuredPoints P X a T S R Z cp p).card : ℝ)) (fun _ _ => Nat.cast_nonneg _) + have hzero : (∑ p ∈ P.filter (aligns a r.rational), + ((nonstructuredPoints P X a T S R Z cp p).card : ℝ)) = 0 := by + apply Finset.sum_eq_zero + intro p hp + rw [nonstructuredPoints_eq_empty_of_aligned r P X a T S R Z cp hlist hden hline hbox hclass p + (Finset.mem_filter.mp hp).2,Finset.card_empty,Nat.cast_zero] + rw [hzero,add_zero] at hpart + apply hpart.trans + apply add_le_add <;> apply Finset.sum_le_sum + all_goals + intro p hp + exact Nat.cast_le.mpr (Finset.card_le_card (nonstructuredPoints_subset_incident P X a T S R Z cp p)) + +end ErdosInverseStructured + +end + +section + +namespace ErdosInverseStructured +open ErdosSourceCollision ErdosLineCollision ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment ErdosConvexGraph + +theorem no_rich_nonstructured_line {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (P : Finset ℕ) (X : Finset (ℤ × ℤ)) (a : ℕ → ℤ) (T : ℕ → Finset ℤ) (S R Z c : ℝ) + (hc : 0 < c) (hP : 0 < P.card) (hX : 0 < X.card) (hS : 0 ≤ S) (hR : 0 ≤ R) + (hline : ∀ v ∈ X,l.Contains v) (hbox : ∀ v ∈ X,InSquare S v) + (hclass : ∀ v ∈ X,∀ ell ∈ v.1.toNat.primeFactors,(v.2 : ZMod ell) = (a ell : ZMod ell)) + (hden : (l.denominator : ℝ) ≤ R*Z^10) (hnum : |(l.intercept : ℝ)| ≤ S*R*Z^10) + (hrich : ∀ v ∈ X,c*(P.card : ℝ) ≤ ((nonstructuredPrimes P a T S R Z (c/4) v).card : ℝ)) + (hbad : (∑ p ∈ unalignedPrimes P a r,((incidentPoints X (a p) p (T p)).card : ℝ))+ + (∑ p ∈ ignoredPrimes P l.denominator,((incidentPoints X (a p) p (T p)).card : ℝ)) ≤ + (c/2)*(P.card : ℝ)*(X.card : ℝ)) : False := by + classical + have hPpos : (0 : ℝ) < P.card := by exact_mod_cast hP + have hXpos : (0 : ℝ) < X.card := by exact_mod_cast hX + have htotal := all_incidence_lower_of_nonstructured_richness P X a T S R Z (c/4) c hrich + have halign := many_aligners_of_richness r P X a T c (c/2) hX htotal hbad + have hcp : (c/4)*(P.card : ℝ) ≤ ((P.filter (aligns a r.rational)).card : ℝ) := by + have hfrac : c/4 ≤ c-c/2 := by linarith + exact (mul_le_mul_of_nonneg_right hfrac hPpos.le).trans halign + have hlist := intercept_mem_fixed_list r P a S R Z (c/4) hS hR hden hnum hcp + have hlow := nonstructured_total_lower P X a T S R Z (c/4) c hrich + have hup := (nonstructured_total_le_bad r P X a T S R Z (c/4) hlist hden hline hbox hclass).trans hbad + have hpos : 0 < c*(P.card : ℝ)*(X.card : ℝ) := mul_pos (mul_pos hc hPpos) hXpos + linarith + +end ErdosInverseStructured + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseStructured +open ErdosSourceCollision ErdosLineCollision ErdosRichLine ErdosPrimitiveIntercept ErdosInverseAlignment +open ErdosInversePrimeBin ErdosInverseBoxHeight ErdosSourcePolynomial ErdosSourceLineBudget ErdosConvexGraph + +theorem uniform_no_rich_nonstructured_set (C Cparent eta alpha c : ℝ) + (hC : 0 ≤ C) (hCp : 0 ≤ Cparent) (heta : 0 < eta) (halpha : 0 < alpha) (hc : 0 < c) : + ∀ᶠ z : ℝ in atTop, 2 ≤ z ∧ ∀ S R p q xi : ℝ, + 1 ≤ p → 0 < q → p*q ≤ (sourceY z : ℝ) → + 1 ≤ S/q → S/q ≤ (1+xi)^(C*Real.log (sourceB z)) → + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → eta ≤ xi → xi ≤ 1 → p ≤ 2*R → + Real.logb (sourceW z) ((sourceY z : ℝ)/(p*q)) ≤ Cparent → + ∀ (a : ℕ → ℤ) (T : ℕ → Finset ℤ), + (∑ p ∈ primeBin R xi,((T p).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/(Real.log z)^6 → + ∀ X : Finset (ℤ × ℤ), (∀ v ∈ X,InSquare S v) → + Set.InjOn Prod.fst (X : Set (ℤ × ℤ)) → S/(sourceZ z)^4 ≤ (X.card : ℝ) → + (∀ v ∈ X,∀ ell ∈ v.1.toNat.primeFactors,(v.2 : ZMod ell) = (a ell : ZMod ell)) → + (∀ v ∈ X,c*((primeBin R xi).card : ℝ) ≤ + ((nonstructuredPrimes (primeBin R xi) a T S R (sourceZ z) (c/4) v).card : ℝ)) → False := by + classical + obtain ⟨R0,hR0⟩ := eventually_atTop.mp (uniform_prime_bin_many heta 1) + filter_upwards [uniform_original_rich_line C Cparent eta alpha c hC hCp heta halpha hc, + uniform_actual_bad_incidence eta alpha (c/2) heta halpha (by positivity), + uniform_extraction_budget Cparent hCp,uniform_source_square_scale C hC,source_Z_ge_two, + (tendsto_rpow_atTop halpha).eventually_ge_atTop R0] + with z hRich hBad hBudget hScale hZ2 hzR + refine ⟨hRich.1,?_⟩ + intro S R p q xi hp hq hpq hratio hinfl hRlo hRhi hxi hxi1 hpR hlen a T hthin + X hbox hinj hsize hclass hrich + have hcounts := hR0 R (hzR.trans hRlo) + have hR1 : 1 ≤ R := by linarith [hcounts.1] + have hRpos : 0 < R := by linarith + have hPpos : 0 < (primeBin R xi).card := by + have hh := hcounts.2 xi hxi hxi1 + omega + have hqS : q ≤ S := (one_le_div hq).mp hratio + have hS0 : 0 ≤ S := hq.le.trans hqS + have hZpos : 0 < sourceZ z := by linarith + have hbudget := hBudget.2 p q R S (by linarith) hq hpR hRhi hqS hlen + have hthin' : (∑ r : primeBin R xi,((T r.val).card : ℝ)) ≤ + ((primeBin R xi).card : ℝ)*R/(Real.log z)^6 := by + calc + _ = ∑ p ∈ primeBin R xi,((T p).card : ℝ) := + Finset.sum_coe_sort (primeBin R xi) (fun p : ℕ => ((T p).card : ℝ)) + _ ≤ _ := hthin + have hpolyRich : ∀ v ∈ X,RichPoint R xi c (fun r => T r.val) (fun r => a r.val) v := + fun v hv => nonstructured_richness_implies_polynomial_richness R xi c S (sourceZ z) (c/4) a T v (hrich v hv) + obtain ⟨l,Y,hsub,hlarge,hline,hdN,haN,hbN⟩ := hRich.2 S R p q xi hp hq hpq hratio hinfl hRlo hRhi hxi hxi1 hpR hlen + (fun r => T r.val) (fun r => a r.val) hthin' X hbox hinj hsize hpolyRich + have hYposR : (0 : ℝ) < Y.card := by linarith [hbudget.2.1] + have hYpos : 0 < Y.card := by exact_mod_cast hYposR + have hYbox : ∀ v ∈ Y,InSquare S v := fun v hv => hbox v (hsub hv) + have hYinj : Set.InjOn Prod.fst (Y : Set (ℤ × ℤ)) := fun _ hv _ hw he => hinj (hsub hv) (hsub hw) he + have hYclass : ∀ v ∈ Y,∀ ell ∈ v.1.toNat.primeFactors,(v.2 : ZMod ell) = (a ell : ZMod ell) := + fun v hv => hclass v (hsub hv) + have hYrich : ∀ v ∈ Y,c*((primeBin R xi).card : ℝ) ≤ + ((nonstructuredPrimes (primeBin R xi) a T S R (sourceZ z) (c/4) v).card : ℝ) := + fun v hv => hrich v (hsub hv) + have hYsize : z^((93 : ℝ)/100) ≤ (Y.card : ℝ) := hbudget.1.trans hlarge.le + have hSupper := hScale.2.2 S R p q xi hp hq hpq hratio hinfl hR1 hRhi (heta.le.trans hxi) hxi1 + obtain ⟨hd6,ha6,hb6⟩ := source_line_heights l S R (sourceZ z) (Y.card : ℝ) hS0 hRpos hZpos hYposR hlarge hdN haN hbN + obtain ⟨hd10,_ha10,hb10⟩ := source_line_height_slack l S R (sourceZ z) hS0 hRpos.le hZ2 hd6 ha6 hb6 + obtain ⟨r⟩ := exists_intercept_reduction l + have hbad := hBad.2 R xi S hRlo hRhi hxi hxi1 a T l r Y hline hYbox hYinj hSupper hYsize hthin hd10 + exact no_rich_nonstructured_line r (primeBin R xi) Y a T S R (sourceZ z) c hc hPpos hYpos hS0 hRpos.le + hline hYbox hYclass hd10 hb10 hYrich hbad + +end ErdosInverseStructured + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRootErrorLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRootErrorLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..d03b067ce39e3260adb6c73a0ecaf97913c727c9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRootErrorLower.lean @@ -0,0 +1,103 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.SourceCompactErrorMass +import OAI.NumberTheory.Jacobsthal.Paths.StoppedErrorReduction + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SourceRootErrorLower +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate +open SourceRootReference SourceCompactErrorMass StoppedErrorReduction CountErrorClassification +open StoppedCountVertex StoppedCountAdapters StoppedVertexHistory StoppedTraceSets +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInverseBoxHeight ErdosCorrectionLimit ErdosSourceReferenceMargin +open ErdosPrimeInputs.PrimePrefixMass +open scoped Topology +attribute [local instance] Classical.propDecidable + +theorem source_root_lower_with_stopped_correction (Cmin : ℝ) : + ∃ c Clen Cs xi₀ : ℝ,0 < c ∧ 1 ≤ Clen ∧ 0 < Cs ∧ Cmin ≤ Cs ∧ 0 < xi₀ ∧ xi₀ ≤ 1 ∧ + ∀ eta : ℝ,0 < eta → eta < 1/2 → ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ xi₀ → + ∃ rho : ℝ,10 < rho ∧ ∀ Kstop : ℝ,0 < Kstop → + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW top,∃ htop : sourceW top < top, + ∀ a : ℕ → ℕ, + let w := sourceW top + let B := sourceB top + let Y := sourceY top + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + let z := sourceRootNode (1/100) top + let P := sourcePrimeSet w top + let v := rootVertex z ∅ P ((Y:ℝ)*V0) + let stop := stopCandidate Y w Cs eta Clen B xi (Kstop*(Real.log w)^2) (rho*Kstop*(Real.log w)^2) + (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) a z + c*((Y:ℝ)*V0/B^2)+ + (∑ ps∈stopped w stop P.card v,(countSurvivors Y small a (after w v ps)-referenceValue w (after w v ps))) ≤ + countSurvivors Y small a v := by + obtain ⟨c_L,hc_L,hRef⟩ := source_root_polynomial_margin + have heighth : 0 < c_L/8 := by positivity + obtain ⟨Cbad,K,hCbad,hK,hError⟩ := stopped_error_reduction (1/100) 2 (c_L/8) (by norm_num) (by norm_num) heighth + obtain ⟨Csmall,B₀,W,hCsmall,hB₀,hW,hError⟩ := hError K (le_refl _) + let eps := c_L/(8*Csmall) + let budget := c_L/(8*Cbad) + have heps : 0 < eps := by dsimp [eps]; positivity + have hbudget : 0 < budget := by dsimp [budget]; positivity + obtain ⟨Clen,Cs,xi₀,hClen,hCs,hCsMin,hxi₀,hxi₀1,hCompact⟩ := + source_compact_error_mass K eps budget (1/100) Cmin hK heps hbudget (by norm_num) (by norm_num) + refine ⟨c_L/2,Clen,Cs,xi₀,by positivity,hClen,hCs,hCsMin,hxi₀,hxi₀1,?_⟩ + intro eta heta0 heta xi hxi hx + obtain ⟨rho,hrho,hCompact⟩ := hCompact eta heta0 heta xi hxi hx + refine ⟨rho,hrho,?_⟩ + intro Kstop hKstop + filter_upwards [hCompact Kstop hKstop,source_root_eventually_data,hRef, + rootB_tendsto.eventually_ge_atTop B₀,rootW_tendsto.eventually_ge_atTop (max W 2)] + with top hCompact hData hRef hB hwBound + obtain ⟨hw,htop,hCompact⟩ := hCompact + obtain ⟨hY,_hB3,_hw,_hwt,hcomp,h199,h23,hcons,hpower⟩ := hData + refine ⟨hw,htop,?_⟩ + intro a + dsimp only + let w := sourceW top + let B := sourceB top + let Y := sourceY top + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + let z := sourceRootNode (1/100) top + let P := sourcePrimeSet w top + let mu := (Y:ℝ)*V0 + let v := rootVertex z ∅ P mu + let stop := stopCandidate Y w Cs eta Clen B xi (Kstop*(Real.log w)^2) (rho*Kstop*(Real.log w)^2) + (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) a z + have hw2 : 2 ≤ w := (le_max_right _ _).trans hwBound + have hV0 : 0 < V0 := (inv_pos.mpr (zero_lt_one.trans hw)).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2) + have hmu : 0 < mu := mul_pos (by exact_mod_cast hY) hV0 + have hBpos : 0 < B := lt_of_lt_of_le (by norm_num : (0:ℝ)<3) (hB₀.trans hB) + have hRoot : z.gap=Real.log (Y:ℝ)/Real.log w-(1:ℝ)/100+2 := rfl + have hErr := hError B w top hB ((le_max_left _ _).trans hwBound) htop hcomp Y hY z hRoot + rfl h199 h23 hcons rfl rfl hpower a eps heps.le stop + have hBad := hCompact z a rfl h199 h23 hcons rfl rfl hRoot + dsimp only at hErr hBad + have hSmallPay : Csmall*eps=c_L/8 := by dsimp [eps]; field_simp [hCsmall.ne'] + have hBadPay : Cbad*budget=c_L/8 := by dsimp [budget]; field_simp [hCbad.ne'] + have hBadScaled := mul_le_mul_of_nonneg_left hBad hCbad.le + rw [hBadPay] at hBadScaled + rw [hSmallPay] at hErr + let correction := ∑ ps∈stopped w stop P.card v,(countSurvivors Y small a (after w v ps)-referenceValue w (after w v ps)) + have hScaled : c_L/2+(B^2/mu)*correction ≤ (B^2/mu)*countSurvivors Y small a v := by + dsimp only [correction,mu,v,P,small,V0,z,Y,w,B,stop] at * + nlinarith + have hf : 0 < B^2/mu := div_pos (sq_pos_of_pos hBpos) hmu + apply (mul_le_mul_iff_right₀ hf).mp + calc + _ = c_L/2+(B^2/mu)*correction := by + change (B^2/mu)*(c_L/2*(mu/B^2)+correction)=_ + field_simp [hmu.ne',hBpos.ne'] + _ ≤ _ := hScaled +end NumberTheoryLean.SourceRootErrorLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRootReference.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRootReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..09345a8f885d83598780a7a48ed0e38a6625395e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceRootReference.lean @@ -0,0 +1,520 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.ScalarMassContinuity +import OAI.NumberTheory.Jacobsthal.Analysis.SourceReferenceLimit +import OAI.NumberTheory.Jacobsthal.Analysis.ThirdMovingIntegrals +import OAI.NumberTheory.Jacobsthal.Probability.OrderedWindowKernel +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialTailBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosBoundaryLoss + +theorem thirdInner_integral {x u : ℝ} (hx : x ∈ Icc (1:ℝ) 2) (hu : u ∈ Icc (1:ℝ) x) : + (2/x)*(∫ y in Icc x 4,thirdInnerKernel x (y,u))= + ∫ t : ℝ in 1..u,loss3Kernel t u x := by + have hx0 : x ≠ 0 := by linarith [hx.1] + have hu0 : u ≠ 0 := by linarith [hu.1] + have hu2 : u ≤ 2 := hu.2.trans hx.2 + have h := integrated_force_window (x+u) x 4 u 0 (by linarith [hx.1]) hu.1 hu2 + (by linarith [hx.2,hu.1]) (by linarith [hx.2]) + have he : (fun y : ℝ => thirdInnerKernel x (y,u))= + (fun y => u⁻¹*(y^2*omissionForce .odd (2*y+2-(x+u)) u)) := by + funext y + have hh : 2*y+2-x-u=2*y+2-(x+u) := by ring + simp only [thirdInnerKernel,max_eq_right hu.1,hh] + ring + rw [he,integral_const_mul,integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le (by linarith [hx.2] : x≤4)] + simp only [sub_zero,zero_mul,sub_zero] at h + rw [h,← mul_assoc,← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hu.1] at ht + have ht0 : t ≠ 0 := by linarith [ht.1] + dsimp only [loss3Kernel] + field_simp + ring + +theorem thirdKernel_integral {x : ℝ} (hx : x ∈ Icc (1:ℝ) 2) : + (∫ y in Icc (0:ℝ) 4,thirdKernel (y,x))= + ∫ u : ℝ in 1..x,∫ t : ℝ in 1..u,loss3Kernel t u x := by + classical + have he : (fun y : ℝ => thirdKernel (y,x))= + (Ici x).indicator (fun y => (2/x)*(y^2*gate omissionForce .even (2*y+2-x) x)) := by + funext y + dsimp only [thirdKernel] + by_cases hh : x≤y + · rw [ite_eq_left hh,indicator_of_mem (show y ∈ Ici x from hh),max_eq_right hx.1] + ring + · rw [ite_eq_right hh,indicator_of_notMem (show y ∉ Ici x from hh)] + have hset : Icc (0:ℝ) 4 ∩ Ici x=Icc x 4 := by + ext y + constructor + · rintro ⟨hy,hxy⟩; exact ⟨hxy,hy.2⟩ + · intro hy; exact ⟨⟨by linarith [hx.1,hy.1],hy.2⟩,hy.1⟩ + rw [he,setIntegral_indicator measurableSet_Ici,hset,integral_const_mul] + simp_rw [third_even_gate _ hx,intervalIntegral.integral_of_le hx.1,← integral_Icc_eq_integral_Ioc] + rw [bounded_rectangle_swap (thirdInnerKernel_continuous x).measurable x 4 1 x 16 + (fun _ hy _ hu => thirdInnerKernel_bound hx hy hu),← integral_const_mul] + apply setIntegral_congr_fun measurableSet_Icc + intro u hu + exact thirdInner_integral hx hu + +theorem third_loss_ordered_integral : + omissionLossTerm 2=∫ x : ℝ in 1..2,∫ u : ℝ in 1..x,∫ t : ℝ in 1..u,loss3Kernel t u x := by + rw [third_loss_bounded] + simp_rw [third_density_kernel] + rw [intervalIntegral.integral_of_le (by norm_num : (0:ℝ)≤4)] + simp_rw [intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤2),← integral_Icc_eq_integral_Ioc] + rw [bounded_rectangle_swap thirdKernel_measurable 0 4 1 2 32 + (fun _ hy _ hx => thirdKernel_bound hy hx)] + exact setIntegral_congr_fun measurableSet_Icc (fun _ hx => thirdKernel_integral hx) + +end ErdosOmissionBindings + +end + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosBoundaryLoss + +theorem third_inner_rectangle_swap {u : ℝ} (hu : u ∈ Icc (1:ℝ) 2) : + (∫ x : ℝ in u..2,∫ t : ℝ in 1..u,loss3Kernel t u x)= + ∫ t : ℝ in 1..u,∫ x : ℝ in u..2,loss3Kernel t u x := by + have hm : Measurable (fun p : ℝ×ℝ => loss3Kernel p.2 u p.1) := by unfold loss3Kernel; fun_prop + have hb : ∀ x ∈ Icc u 2,∀ t ∈ Icc (1:ℝ) u,|loss3Kernel t u x| ≤ 64 := by + intro x hx t ht + exact lossThree_bound ⟨hu.1.trans hx.1,hx.2⟩ hu ⟨ht.1,ht.2.trans hu.2⟩ + have h := bounded_rectangle_swap hm u 2 1 u 64 hb + simpa only [intervalIntegral.integral_of_le hu.1,intervalIntegral.integral_of_le hu.2, + ← integral_Icc_eq_integral_Ioc] using h + +theorem third_ordered_reversal : + (∫ x : ℝ in 1..2,∫ u : ℝ in 1..x,∫ t : ℝ in 1..u,loss3Kernel t u x)=L3 := by + calc + _ = ∫ x : ℝ in 1..2,∫ u : ℝ in 1..x,thirdLowerIntegral (x,u) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le (by norm_num : (1:ℝ)≤2)] at hx + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le hx.1] at hu + exact (thirdLowerIntegral_eq hx ⟨hu.1,hu.2.trans hx.2⟩).symm + _ = ∫ u : ℝ in 1..2,∫ x : ℝ in u..2,thirdLowerIntegral (x,u) := + ordered_triangle_swap thirdLowerIntegral_continuous.measurable (by norm_num : (0:ℝ)≤64) + (fun _ _ _ _ => thirdLowerIntegral_bound _) + _ = ∫ u : ℝ in 1..2,∫ t : ℝ in 1..u,∫ x : ℝ in u..2,loss3Kernel t u x := by + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le (by norm_num : (1:ℝ)≤2)] at hu + have he : (∫ x : ℝ in u..2,thirdLowerIntegral (x,u))= + ∫ x : ℝ in u..2,∫ t : ℝ in 1..u,loss3Kernel t u x := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hu.2] at hx + exact thirdLowerIntegral_eq ⟨hu.1.trans hx.1,hx.2⟩ hu + exact he.trans (third_inner_rectangle_swap hu) + _ = ∫ u : ℝ in 1..2,∫ t : ℝ in 1..u,thirdUpperIntegral (u,t) := by + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le (by norm_num : (1:ℝ)≤2)] at hu + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hu.1] at ht + exact (thirdUpperIntegral_eq hu ⟨ht.1,ht.2.trans hu.2⟩).symm + _ = ∫ t : ℝ in 1..2,∫ u : ℝ in t..2,thirdUpperIntegral (u,t) := + ordered_triangle_swap thirdUpperIntegral_continuous.measurable (by norm_num : (0:ℝ)≤64) + (fun _ _ _ _ => thirdUpperIntegral_bound _) + _ = L3 := by + unfold L3 + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le (by norm_num : (1:ℝ)≤2)] at ht + apply intervalIntegral.integral_congr + intro u hu + rw [uIcc_of_le ht.2] at hu + exact thirdUpperIntegral_eq ⟨ht.1.trans hu.1,hu.2⟩ ht + +theorem actual_third_loss_eq_L3 : omissionLossTerm 2=L3 := + third_loss_ordered_integral.trans third_ordered_reversal + +end ErdosOmissionBindings + +end + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission + +theorem terminal_mass_affine_bound (k : ℕ) {S b : ℝ} + (hSlo : (k:ℝ) ≤ S) (hShi : S ≤ 2*(k:ℝ)) (hSb : (k:ℝ)*b ≤ S) + (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + scalarTailMass 0 S b ≤ (((k:ℝ)+4)^2/2)*orderedAffine ((k:ℝ)+3) 3 S b := by + let m : ℝ := (k:ℝ)+3 + let C : ℝ := ((k:ℝ)+4)^2/2 + have hk : 0 ≤ (k:ℝ) := Nat.cast_nonneg k + have hS : 0 ≤ S := hk.trans hSlo + have hmiddle : ∀ a ∈ Icc (1:ℝ) b,∀ u ∈ Icc (1:ℝ) a, + windowMiddle S a u ≤ C/(a*u)*orderedAffine m 1 (S+a+u) u := by + intro a ha u hu + have ha2 : a ≤ 2 := ha.2.trans hb2 + have hu2 : u ≤ 2 := hu.2.trans ha2 + have ha0 : 0 < a := by linarith [ha.1] + have hu0 : 0 < u := by linarith [hu.1] + have hpmap : Continuous (fun c : ℝ => ((a,u),c)) := by fun_prop + have hlower : Continuous (windowKernel S a u) := by + simpa only [Function.comp_def] using! (windowKernel_continuous S).comp hpmap + have hupper := (orderedAffine_shift_div_continuous m 0 (S+a+u)).const_mul (C/(a*u)) + have hh := intervalIntegral.integral_mono_on hu.1 + (hlower.intervalIntegrable (μ := volume) 1 u) (hupper.intervalIntegrable (μ := volume) 1 u) (fun c hc => by + have hc0 : 0 < c := by linarith [hc.1] + have hcb : c ≤ b := hc.2.trans (hu.2.trans ha.2) + have hSc : (k:ℝ)*c ≤ S := (mul_le_mul_of_nonneg_left hcb hk).trans hSb + have hw := last_window_mean_bound k hSlo hShi hSc ha.1 ha2 hu.1 hu.2 hc.1 hc.2 + rw [windowKernel_literal ha.1 hu.1 hc.1] + change lastWindowCoefficient S a u c/(a*u*c) ≤ C/(a*u)*(orderedAffine m 0 (S+a+u+c) c/(max 1 c)) + rw [orderedAffine_zero,max_eq_right hc.1] + have hd := div_le_div_of_nonneg_right hw (show 0 ≤ a*u*c by positivity) + convert! hd using 1; dsimp [C,m]; ring) + unfold windowMiddle + rw [baseCutoff_on hu.1 hu2] + apply hh.trans_eq + rw [intervalIntegral.integral_const_mul,orderedAffine_succ m 0 (S+a+u) u,baseCutoff_on hu.1 hu2] + have houter : ∀ a ∈ Icc (1:ℝ) b,windowOuter S a ≤ C/a*orderedAffine m 2 (S+a) a := by + intro a ha + have ha2 : a ≤ 2 := ha.2.trans hb2 + have hpmap : Continuous (fun u : ℝ => (a,u)) := by fun_prop + have hlower : Continuous (windowMiddle S a) := by + simpa only [Function.comp_def] using! (windowMiddle_continuous S).comp hpmap + have hupper := (orderedAffine_shift_div_continuous m 1 (S+a)).const_mul (C/a) + have hh := intervalIntegral.integral_mono_on ha.1 + (hlower.intervalIntegrable (μ := volume) 1 a) (hupper.intervalIntegrable (μ := volume) 1 a) (fun u hu => by + have hw := hmiddle a ha u hu + change windowMiddle S a u ≤ C/a*(orderedAffine m 1 (S+a+u) u/(max 1 u)) + rw [max_eq_right hu.1] + convert! hw using 1; ring) + unfold windowOuter + rw [baseCutoff_on ha.1 ha2] + apply hh.trans_eq + rw [intervalIntegral.integral_const_mul,orderedAffine_succ m 1 (S+a) a,baseCutoff_on ha.1 ha2] + rw [scalarTailMass_zero_eq_windowMass hS hb1 hb2,windowMass,baseCutoff_on hb1 hb2] + have hupper := (orderedAffine_shift_div_continuous m 2 S).const_mul C + have hh := intervalIntegral.integral_mono_on hb1 + ((windowOuter_continuous S).intervalIntegrable (μ := volume) 1 b) + (hupper.intervalIntegrable (μ := volume) 1 b) (fun a ha => by + have hw := houter a ha + change windowOuter S a ≤ C*(orderedAffine m 2 (S+a) a/(max 1 a)) + rw [max_eq_right ha.1] + convert! hw using 1; ring) + apply hh.trans_eq + rw [intervalIntegral.integral_const_mul,orderedAffine_succ m 2 S b,baseCutoff_on hb1 hb2] + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionBindings +open ErdosContinuousOmission ErdosBoundaryLoss + +theorem actual_second_loss_value : omissionLossTerm 1=-(35:ℝ)/36-(Real.log 2)^2+3*Real.log 2 := + actual_second_loss_eq_L2.trans L2_eq + +theorem actual_third_loss_value : omissionLossTerm 2=(623:ℝ)/432-(19:ℝ)/12*Real.log 2+(1:ℝ)/3*(Real.log 2)^2 := + actual_third_loss_eq_L3.trans L3_eq + +theorem actual_first_three_loss_lt : omissionLossTerm 0+omissionLossTerm 1+omissionLossTerm 2<(43:ℝ)/20 := by + rw [actual_first_loss_eq_one,actual_second_loss_eq_L2,actual_third_loss_eq_L3] + linarith [L2_lt,L3_lt] + +theorem actual_first_three_partial_sum_lt : (∑ n ∈ Finset.range 3,omissionLossTerm n)<(43:ℝ)/20 := by + have h := actual_first_three_loss_lt + simpa only [Finset.sum_range_succ,Finset.range_zero,Finset.sum_empty,zero_add] using h + +end ErdosOmissionBindings + +end + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission + +theorem scalarTailMass_affine_bound (n k : ℕ) {S b : ℝ} + (hSlo : (k:ℝ) ≤ S) (hShi : S ≤ 2*(k:ℝ)) (hSb : (k:ℝ)*b ≤ S) + (hb1 : 1 ≤ b) (hb2 : b ≤ 2) : + scalarTailMass n S b ≤ (((k:ℝ)+(n:ℝ)+4)^2/2)* + orderedAffine ((k:ℝ)+(n:ℝ)+3) (n+3) S b := by + induction n generalizing k S b with + | zero => + simpa only [Nat.cast_zero,add_zero,Nat.zero_add] using terminal_mass_affine_bound k hSlo hShi hSb hb1 hb2 + | succ n ih => + have hk : 0 ≤ (k:ℝ) := Nat.cast_nonneg k + have hS : 0 ≤ S := hk.trans hSlo + simp only [Nat.cast_add,Nat.cast_one] + rw [show (k:ℝ)+((n:ℝ)+1)+4=(k:ℝ)+(n:ℝ)+5 by ring, + show (k:ℝ)+((n:ℝ)+1)+3=(k:ℝ)+(n:ℝ)+4 by ring, + show (n+1)+3=(n+3)+1 by omega] + let m : ℝ := (k:ℝ)+(n:ℝ)+4 + let C : ℝ := ((k:ℝ)+(n:ℝ)+5)^2/2 + change scalarTailMass (n+1) S b ≤ C*orderedAffine m ((n+3)+1) S b + rw [scalarTailMass_succ n hS hb1 hb2,orderedAffine_succ,baseCutoff_on hb1 hb2, + ← intervalIntegral.integral_const_mul] + have hpmap : Continuous (fun x : ℝ => (S+x,x)) := by fun_prop + have hc : Continuous (fun x : ℝ => scalarTailMass n (S+x) x/(max 1 x)) := + ((scalarTailMass_continuous n).comp hpmap).div (continuous_const.max continuous_id) + (fun x => ne_of_gt ((by norm_num : (0:ℝ)<1).trans_le (le_max_left _ _))) + have hlow : IntervalIntegrable (fun x : ℝ => scalarTailMass n (S+x) x/x) volume 1 b := by + apply (hc.intervalIntegrable (μ := volume) 1 b).congr_uIoo + intro x hx + rw [uIoo_of_le hb1] at hx + simp only [max_eq_right hx.1.le] + have hupper := (orderedAffine_shift_div_continuous m (n+3) S).const_mul C + apply intervalIntegral.integral_mono_on hb1 hlow (hupper.intervalIntegrable (μ := volume) 1 b) + intro x hx + have hx2 : x ≤ 2 := hx.2.trans hb2 + have hlo : ((k+1:ℕ):ℝ) ≤ S+x := by push_cast; linarith [hx.1] + have hhi : S+x ≤ 2*((k+1:ℕ):ℝ) := by push_cast; linarith + have horder : ((k+1:ℕ):ℝ)*x ≤ S+x := by + have hh := mul_le_mul_of_nonneg_left hx.2 hk + push_cast + nlinarith + have hh := ih (k+1) hlo hhi horder hx.1 hx2 + have hm : ((k+1:ℕ):ℝ)+(n:ℝ)+3=m := by dsimp [m]; push_cast; ring + have hC : (((k+1:ℕ):ℝ)+(n:ℝ)+4)^2/2=C := by dsimp [C]; push_cast; ring + rw [hm,hC] at hh + rw [max_eq_right hx.1] + have hd := div_le_div_of_nonneg_right hh (show 0 ≤ x by linarith [hx.1]) + convert! hd using 1; ring + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.MeasureTheory +namespace ErdosOmissionTail +open ErdosContinuousOmission + +theorem actual_omission_factorial_bound (n : ℕ) : + omissionLossTerm (n+3) ≤ + (1:ℝ)/2*(3/Real.log 2-2)*weightedExpTerm (Real.log 2) (n+4) := by + have hh := scalarTailMass_affine_bound (n+1) 0 (S := 0) (b := 2) + (by norm_num) (by norm_num) (by norm_num) (by norm_num) le_rfl + norm_num only [Nat.cast_zero,zero_add] at hh + have hm : ((n+1:ℕ):ℝ)+3=((n+4:ℕ):ℝ) := by push_cast; ring + rw [hm,show (n+1)+3=n+4 by omega,show n+4=(n+3)+1 by omega,orderedAffine_at_two] at hh + have hc := (actual_loss_le_scalarTailMass (n+1)).trans hh + have he : (n+1)+2=n+3 := by omega + rw [he] at hc + convert! hc using 1 + unfold weightedExpTerm expTerm + push_cast + ring + +theorem actual_omission_tail_lt : (∑' n : ℕ,omissionLossTerm (n+3)) < (37:ℝ)/100 := by + have hl : Summable (fun n : ℕ => omissionLossTerm (n+3)) := + actual_loss_summable.comp_injective (fun _ _ h => Nat.add_right_cancel h) + have hu := weighted_log_two_tail_hasSum.summable.mul_left ((1:ℝ)/2*(3/Real.log 2-2)) + have hh := hl.tsum_le_tsum actual_omission_factorial_bound hu + rw [tsum_mul_left] at hh + exact hh.trans_lt numerical_tail_majorant_lt + +theorem actual_omission_tail_indicator_lt : + (∑' n : ℕ,if 3 ≤ n then omissionLossTerm n else 0) < (37:ℝ)/100 := by + have hl : Summable (fun n : ℕ => omissionLossTerm (n+3)) := + actual_loss_summable.comp_injective (fun _ _ h => Nat.add_right_cancel h) + have hg : HasSum (fun n : ℕ => if 3 ≤ n then omissionLossTerm n else 0) + (∑' n : ℕ,omissionLossTerm (n+3)) := by + apply (hasSum_nat_add_iff' 3).mp + have heval (n : ℕ) : (if 3 ≤ n+3 then omissionLossTerm (n+3) else 0)=omissionLossTerm (n+3) := + ite_eq_left (by omega) + simp_rw [heval] + simpa only [Finset.sum_range_succ,Finset.sum_range_zero,Finset.sum_empty, + show ¬3 ≤ 0 by omega,show ¬3 ≤ 1 by omega,show ¬3 ≤ 2 by omega,ite_false,add_zero,sub_zero] using hl.hasSum + have he := hg.tsum_eq + rw [he] + exact actual_omission_tail_lt + +end ErdosOmissionTail + +end + +section + +open _root_.Set _root_.Filter +open scoped Topology +namespace ErdosPositiveReference +open ErdosOmissionBindings ErdosOmissionTail ErdosContinuousOmission +open ErdosBoundaryIntegral ErdosBoundaryLoss +open Erdos970Dependency.InvariantCostBound +open NumberTheoryLean.BuchstabBridge + +theorem actual_I_gt_eleven_seventyfive : (11:ℝ)/75 < signedCoefficientI := by + have hfirst := actual_first_three_partial_sum_lt + have htail := actual_omission_tail_lt + have hsplit := actual_loss_summable.sum_add_tsum_nat_add 3 + have htotal := actual_signed_loss_series + linarith + +theorem actual_I_gt_source_margin : (14:ℝ)/100 < signedCoefficientI := by + linarith [actual_I_gt_eleven_seventyfive] + +theorem exp_gamma_lt_two : Real.exp Real.eulerMascheroniConstant < 2 := by + have hg : Real.eulerMascheroniConstant < Real.log 2 := by + linarith [Real.eulerMascheroniConstant_lt_two_thirds,log_two_bounds.1] + have h := Real.exp_lt_exp.mpr hg + simpa only [Real.exp_log (by norm_num : (0:ℝ)<2)] using h + +theorem costMass_lt_eight : costMass < 8 := by + have h := costMass_le + change costMass ≤ 2*(2*Real.exp Real.eulerMascheroniConstant) at h + linarith [exp_gamma_lt_two] + +theorem source_reference_coefficient_margin : + (2:ℝ)/100 < -(1:ℝ)/100+2*signedCoefficientI/costMass := by + have h : (3:ℝ)/100 < 2*signedCoefficientI/costMass := by + apply (lt_div_iff₀ costMass_pos).mpr + nlinarith [actual_I_gt_eleven_seventyfive,costMass_lt_eight] + linarith + +end ErdosPositiveReference + +end + +section + +open _root_.Set _root_.Filter +open scoped Topology +namespace ErdosSourceReferenceMargin +open ErdosCorrectionLimit ErdosBoundaryIntegral ErdosPositiveReference +open NumberTheoryLean.ReferenceSourceDecomposition +open Erdos970Dependency.InvariantCostBound + +theorem actual_reference_limit_positive : + Real.exp Real.eulerMascheroniConstant/100 < + Real.exp Real.eulerMascheroniConstant*(-(1:ℝ)/100+2*signedCoefficientI/costMass) := by + have hh := mul_lt_mul_of_pos_left source_reference_coefficient_margin (Real.exp_pos Real.eulerMascheroniConstant) + nlinarith [Real.exp_pos Real.eulerMascheroniConstant] + +theorem actual_source_reference_lower_bound : + ∃ c_L z₀ : ℝ,0 < c_L ∧ 1 < z₀ ∧ ∀ z : ℝ,z₀ ≤ z → + c_L ≤ (ErdosInverseBoxHeight.sourceB z)^2* + sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode (1/100) z) ∧ + c_L/(ErdosInverseBoxHeight.sourceB z)^2 ≤ + sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode (1/100) z) := by + let c_L : ℝ := Real.exp Real.eulerMascheroniConstant/100 + have hc : 0 < c_L := div_pos (Real.exp_pos _) (by norm_num) + have hevent := actual_sourceReference_tendsto.eventually (Ioi_mem_nhds actual_reference_limit_positive) + have he : ∀ᶠ z : ℝ in atTop, + c_L ≤ (ErdosInverseBoxHeight.sourceB z)^2* + sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode (1/100) z) ∧ + c_L/(ErdosInverseBoxHeight.sourceB z)^2 ≤ + sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode (1/100) z) := by + filter_upwards [hevent,rootB_tendsto.eventually (eventually_gt_atTop (0:ℝ))] with z hz hB + have hz' : c_L < (ErdosInverseBoxHeight.sourceB z)^2* + sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode (1/100) z) := hz + refine ⟨hz'.le,?_⟩ + apply (div_le_iff₀ (sq_pos_of_pos hB)).mpr + simpa only [mul_comm] using hz'.le + obtain ⟨z₁,hz₁⟩ := eventually_atTop.mp he + refine ⟨c_L,max 2 z₁,hc,by have h := le_max_left (2:ℝ) z₁; linarith,?_⟩ + intro z hz + exact hz₁ z ((le_max_right _ _).trans hz) + +theorem actual_source_reference_eventually_positive : + ∃ z₀ : ℝ,1 < z₀ ∧ ∀ z : ℝ,z₀ ≤ z → + 0 < sourceReference (ErdosInverseBoxHeight.sourceW z) (sourceRootNode (1/100) z) := by + obtain ⟨c_L,z₁,hc,hz₁,h⟩ := actual_source_reference_lower_bound + obtain ⟨z₂,hz₂⟩ := eventually_atTop.mp (rootB_tendsto.eventually (eventually_gt_atTop (0:ℝ))) + refine ⟨max z₁ z₂,hz₁.trans_le (le_max_left _ _),?_⟩ + intro z hz + have hB := hz₂ z ((le_max_right _ _).trans hz) + exact (div_pos hc (sq_pos_of_pos hB)).trans_le (h z ((le_max_left _ _).trans hz)).2 + +end ErdosSourceReferenceMargin + +end + + +namespace NumberTheoryLean.SourceRootReference +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open ReferenceSourceDecomposition ReferenceSourcePrimeSets ReferenceProductsBasics ReferenceAdmission +open LogarithmicBinPartition SourceNodeCoordinates +open ErdosCorrectionLimit ErdosSourceReferenceMargin ErdosInverseBoxHeight +open scoped Topology + + +theorem source_primes_eq_root_set {top : ℝ} (htop : 1 < top) (hw : 1 < sourceW top) : + sourcePrimes (sourceW top) (sourceB top) true=sourcePrimeSet (sourceW top) top := by + have hp : (sourceW top)^(sourceB top)=top := + (JacobsthalSourceScale.sourceW_pow_sourceB hw).trans (Real.exp_log (zero_lt_one.trans htop)) + rw [sourcePrimes,hp,availablePrimes_closed,primesBetween_eq_sdiff (zero_lt_one.trans hw).le] + rfl + +theorem source_reference_root_polynomial (a top : ℝ) (htop : 1 < top) (hw : 1 < sourceW top) : + sourceReference (sourceW top) (sourceRootNode a top)= + referencePolynomial (sourceW top) (sourcePrimeSet (sourceW top) top) + (sourceRootNode a top).side (sourceRootNode a top).gap := by + unfold sourceReference + change referencePolynomial _ (sourcePrimes (sourceW top) (sourceB top) true) _ _=_ + rw [source_primes_eq_root_set htop hw] + +theorem source_root_polynomial_margin : ∃ c_L : ℝ,0 < c_L ∧ ∀ᶠ top : ℝ in atTop, + c_L ≤ (sourceB top)^2*referencePolynomial (sourceW top) (sourcePrimeSet (sourceW top) top) + (sourceRootNode (1/100) top).side (sourceRootNode (1/100) top).gap := by + obtain ⟨c_L,T,hc,_hT,hMargin⟩ := actual_source_reference_lower_bound + refine ⟨c_L,hc,?_⟩ + filter_upwards [eventually_ge_atTop T,actual_root_eventually (1/100),eventually_gt_atTop (1:ℝ)] with top htop hroot ht1 + have hh := (hMargin top htop).1 + rwa [source_reference_root_polynomial (1/100) top ht1 hroot.2.1] at hh + +theorem source_root_eventually_data : ∀ᶠ top : ℝ in atTop, + 0 < sourceY top ∧ 3 ≤ sourceB top ∧ 1 < sourceW top ∧ sourceW top < top ∧ + Real.log (sourceB top) ≤ 2*Real.log (sourceW top) ∧ + 199/100 ≤ (sourceRootNode (1/100) top).ratio ∧ (sourceRootNode (1/100) top).ratio ≤ 23/10 ∧ + Consistent (sourceRootNode (1/100) top) ∧ (sourceW top)^(sourceB top)=top := by + filter_upwards [actual_root_eventually (1/100),rootB_tendsto.eventually_ge_atTop 3, + Real.tendsto_log_atTop.eventually JacobsthalSourceScale.sourceW_bounds_eventually,eventually_gt_atTop (1:ℝ)] + with top hroot hB hW ht1 + obtain ⟨_hBpos,hw,hcomp,h199,h23,_hgap,hcons⟩ := hroot + have hwt : sourceW top < top := by + have hsmall : sourceW top ≤ Real.log top := hW.2.2 + have hl := Real.log_le_sub_one_of_pos (zero_lt_one.trans ht1) + linarith + have hY : 0 < sourceY top := by + by_contra! hn + have hzero : sourceY top=0 := by omega + have hg : (sourceRootNode (1/100) top).gap=199/100 := by + change Real.log (sourceY top:ℝ)/Real.log (sourceW top)-(1:ℝ)/100+2=199/100 + rw [hzero] + norm_num + have hs : Valid (sourceRootNode (1/100) top).side (sourceRootNode (1/100) top).ratio := by + change 198/100 ≤ (sourceRootNode (1/100) top).ratio + linarith + have he := node_gap_eq hs hcons (rfl : (sourceRootNode (1/100) top).cutoff=sourceB top) + change (sourceRootNode (1/100) top).gap=sourceB top*(sourceRootNode (1/100) top).ratio at he + have hprod := mul_le_mul h199 hB (by norm_num : (0:ℝ)≤3) (by linarith : 0 ≤ (sourceRootNode (1/100) top).ratio) + nlinarith + exact ⟨hY,hB,hw,hwt,hcomp,h199,h23,hcons, + (JacobsthalSourceScale.sourceW_pow_sourceB hw).trans (Real.exp_log (zero_lt_one.trans ht1))⟩ +end NumberTheoryLean.SourceRootReference + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceSamplePopulation.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceSamplePopulation.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d8757d40f1c1db3f5a560892b2b1465a2a9b185 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceSamplePopulation.lean @@ -0,0 +1,183 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SmallModelSourceScales +import OAI.NumberTheory.Jacobsthal.Probability.FallingFactorialProbability + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseSampling +attribute [local instance] Classical.decEq + +noncomputable def sampleAverage {α : Type*} (U : Finset α) (h : ℕ) (f : Sample U h → ℝ) : ℝ := + (∑ e : Sample U h,f e)/(Fintype.card (Sample U h) : ℝ) + +theorem sample_product_sum_le {α : Type*} (U : Finset α) (h : ℕ) (t : U → ℝ) + (ht : ∀ u,0 ≤ t u) : + (∑ e : Sample U h,∏ i : Fin h,t (e i)) ≤ (∑ u : U,t u)^h := by + classical + let E : Finset (Fin h → U) := Finset.univ.image (fun e : Sample U h => (e : Fin h → U)) + have he : (∑ e : Sample U h,∏ i : Fin h,t (e i)) = ∑ f ∈ E,∏ i : Fin h,t (f i) := by + dsimp only [E] + rw [Finset.sum_image (fun _ _ _ _ he => Function.Embedding.coe_injective he)] + have hall : (∑ f : Fin h → U,∏ i : Fin h,t (f i)) = (∑ u : U,t u)^h := by + have hh := (Fintype.prod_sum (fun _i : Fin h => fun u : U => t u)).symm + simpa only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] using hh + calc + _ = ∑ f ∈ E,∏ i : Fin h,t (f i) := he + _ ≤ ∑ f : Fin h → U,∏ i : Fin h,t (f i) := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ E) + (fun f _ _ => Finset.prod_nonneg (fun i _ => ht (f i))) + _ = _ := hall + +theorem sample_product_average_le {α : Type*} (U : Finset α) (h : ℕ) (t : U → ℝ) + (ht : ∀ u,0 ≤ t u) (hU : 0 < U.card) (hh : h ≤ U.card) : + sampleAverage U h (fun e => ∏ i : Fin h,t (e i)) ≤ + ((U.card : ℝ)^h/(U.card.descFactorial h : ℝ))*((∑ u : U,t u)/(U.card : ℝ))^h := by + have hn : (0 : ℝ) < U.card := by exact_mod_cast hU + have hd : (0 : ℝ) < U.card.descFactorial h := by exact_mod_cast Nat.descFactorial_pos.mpr hh + unfold sampleAverage + rw [sample_card] + calc + _ ≤ (∑ u : U,t u)^h/(U.card.descFactorial h : ℝ) := + div_le_div_of_nonneg_right (sample_product_sum_le U h t ht) hd.le + _ = _ := by rw [div_pow];field_simp + +end ErdosInverseSampling + +end + +section + +open _root_.Filter _root_.Erdos970.Filter +open scoped Topology +namespace ErdosInverseSampling + +theorem normalized_falling_eq_product (n h : ℕ) (hh : h ≤ n) (hn : 0 < n) : + (n.descFactorial h : ℝ)/(n : ℝ)^h = ∏ i ∈ Finset.range h,(1-(i : ℝ)/(n : ℝ)) := by + rw [Nat.descFactorial_eq_prod_range,Nat.cast_prod] + have hden : (n : ℝ)^h = ∏ _i ∈ Finset.range h,(n : ℝ) := by simp + have hnR : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + rw [hden,← Finset.prod_div_distrib] + apply Finset.prod_congr rfl + intro i hi + have hin : i ≤ n := (Finset.mem_range.mp hi).le.trans hh + rw [Nat.cast_sub hin] + field_simp + +theorem normalized_falling_tendsto (h : ℕ) : + Tendsto (fun n : ℕ => (n.descFactorial h : ℝ)/(n : ℝ)^h) atTop (𝓝 1) := by + have hcast : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + have hprod : Tendsto (fun n : ℕ => ∏ i ∈ Finset.range h,(1-(i : ℝ)/(n : ℝ))) atTop (𝓝 1) := by + have hh := tendsto_finsetProd (Finset.range h) (fun i _ => + (tendsto_const_nhds : Tendsto (fun _n : ℕ => (1 : ℝ)) atTop (𝓝 1)).sub + (hcast.const_div_atTop (i : ℝ))) + simpa only [sub_zero,Finset.prod_const_one] using hh + apply hprod.congr' + filter_upwards [eventually_ge_atTop h,eventually_ge_atTop (1 : ℕ)] with n hhn hn + exact (normalized_falling_eq_product n h hhn (by omega)).symm + +theorem sampling_prefactor_tendsto (h : ℕ) : + Tendsto (fun n : ℕ => (n : ℝ)^h/(n.descFactorial h : ℝ)) atTop (𝓝 1) := by + have hh := (normalized_falling_tendsto h).inv₀ (by norm_num : (1 : ℝ) ≠ 0) + simpa only [inv_div,inv_one] using hh + +theorem sampling_prefactor_eventually_le_two (h : ℕ) : + ∀ᶠ n : ℕ in atTop,(n : ℝ)^h/(n.descFactorial h : ℝ) ≤ 2 := by + have hh := (tendsto_order.mp (sampling_prefactor_tendsto h)).2 2 (by norm_num) + exact hh.mono (fun _ hn => hn.le) + +end ErdosInverseSampling + +end + +section + +namespace ErdosInverseSampleCost +open ErdosInverseSampling +attribute [local instance] Classical.decEq + +theorem sampleAverage_mono {α : Type*} (U : Finset α) (h : ℕ) + (f g : Sample U h → ℝ) (hfg : ∀ s,f s ≤ g s) : sampleAverage U h f ≤ sampleAverage U h g := + div_le_div_of_nonneg_right (Finset.sum_le_sum (fun s _ => hfg s)) (Nat.cast_nonneg _) + +theorem sampleAverage_nonneg {α : Type*} (U : Finset α) (h : ℕ) + (f : Sample U h → ℝ) (hf : ∀ s,0 ≤ f s) : 0 ≤ sampleAverage U h f := + div_nonneg (Finset.sum_nonneg (fun s _ => hf s)) (Nat.cast_nonneg _) + +theorem sampleAverage_add {α : Type*} (U : Finset α) (h : ℕ) (f g : Sample U h → ℝ) : + sampleAverage U h (fun s => f s+g s) = sampleAverage U h f+sampleAverage U h g := by + unfold sampleAverage + rw [Finset.sum_add_distrib,add_div] + +theorem sampleAverage_mul {α : Type*} (U : Finset α) (h : ℕ) (c : ℝ) (f : Sample U h → ℝ) : + sampleAverage U h (fun s => c*f s) = c*sampleAverage U h f := by + unfold sampleAverage + rw [← Finset.mul_sum,mul_div_assoc] + +theorem sampleAverage_div {α : Type*} (U : Finset α) (h : ℕ) (c : ℝ) (f : Sample U h → ℝ) : + sampleAverage U h (fun s => f s/c) = sampleAverage U h f/c := by + unfold sampleAverage + rw [← Finset.sum_div,div_right_comm] + +theorem sampleAverage_sum {α ι : Type*} (U : Finset α) (h : ℕ) (I : Finset ι) + (f : ι → Sample U h → ℝ) : + sampleAverage U h (fun s => ∑ i ∈ I,f i s) = ∑ i ∈ I,sampleAverage U h (f i) := by + unfold sampleAverage + rw [Finset.sum_comm,Finset.sum_div] + +theorem sampleAverage_const {α : Type*} (U : Finset α) (h : ℕ) (hh : h ≤ U.card) (c : ℝ) : + sampleAverage U h (fun _ => c) = c := by + have hcard : (0 : ℝ) < Fintype.card (Sample U h) := by + exact_mod_cast Fintype.card_pos_iff.mpr (sample_nonempty_of_length U h hh) + unfold sampleAverage + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + field_simp + +theorem sampleAverage_product_bound {α : Type*} (U : Finset α) (h : ℕ) (hh : h ≤ U.card) + (t : U → ℝ) (T : ℝ) (ht : ∀ u,0 ≤ t u) (hT : ∀ u,t u ≤ T) : + sampleAverage U h (fun s => ∏ i : Fin h,t (s i)) ≤ T^h := by + have hprod : ∀ s : Sample U h,(∏ i : Fin h,t (s i)) ≤ T^h := by + intro s + have hh := Finset.prod_le_prod₀ (s := Finset.univ) (fun i _ => ht (s i)) (fun i _ => hT (s i)) + simpa only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] using hh + exact (sampleAverage_mono U h _ _ hprod).trans_eq (sampleAverage_const U h hh (T^h)) + +end ErdosInverseSampleCost + +end + +section + +open _root_.Filter _root_.Erdos970.Filter +open scoped Topology +namespace ErdosInverseSampleCost +open ErdosInverseSampling ErdosInversePrimeBin ErdosInverseEuler ErdosInverseBoxHeight + +theorem source_sample_population (xi beta : ℝ) (h : ℕ) (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,∀ U theta : ℝ,sourceW z ≤ U → xi/4 ≤ theta → theta ≤ xi → + 0 < (primeBin U theta).card ∧ h ≤ (primeBin U theta).card ∧ + 4*(h : ℝ)/beta ≤ ((primeBin U theta).card : ℝ) ∧ + ((primeBin U theta).card : ℝ)^h/((primeBin U theta).card.descFactorial h : ℝ) ≤ 2 := by + obtain ⟨n0,hn0⟩ := eventually_atTop.mp (sampling_prefactor_eventually_le_two h) + let M : ℕ := n0+h+⌈4*(h : ℝ)/beta⌉₊+1 + obtain ⟨U0,hU0⟩ := eventually_atTop.mp (uniform_prime_bin_many (by positivity : 0 < xi/4) M) + filter_upwards [sourceW_tendsto_atTop.eventually_ge_atTop U0] with z hz + intro U theta hWU htlow hthigh + have hmany := (hU0 U (hz.trans hWU)).2 theta htlow (hthigh.trans hxi1) + have hM0 : n0 ≤ M := by dsimp [M];omega + have hMh : h ≤ M := by dsimp [M];omega + have hM1 : 1 ≤ M := by dsimp [M];omega + have hMc : ⌈4*(h : ℝ)/beta⌉₊ ≤ M := by dsimp [M];omega + refine ⟨by omega,hMh.trans hmany,?_,hn0 _ (hM0.trans hmany)⟩ + exact (Nat.le_ceil (4*(h : ℝ)/beta)).trans (by exact_mod_cast hMc.trans hmany) + +end ErdosInverseSampleCost + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceSquareScale.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceSquareScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8d39114074b08a98d0d28abad2fd5570b4107f2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceSquareScale.lean @@ -0,0 +1,52 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.BoxHeightBudget + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourcePolynomial +open ErdosInverseBoxHeight + +theorem sourceZ_ge_one {z : ℝ} (hL : 1 ≤ Real.log z) : 1 ≤ sourceZ z := by + apply Real.one_le_exp_iff.mpr + exact div_nonneg (zero_le_one.trans hL) (Real.log_nonneg hL) + +theorem square_scale_of_root_height {z Sq R : ℝ} (hSq : 0 ≤ Sq) (hR : 1 ≤ R) + (hL : 1 ≤ Real.log z) (hheight : 2*Sq*R^2*(sourceZ z)^20 ≤ z^3) : Sq ≤ z^3 := by + have hR2 : 1 ≤ R^2 := one_le_pow₀ hR + have hZ20 : 1 ≤ (sourceZ z)^20 := one_le_pow₀ (sourceZ_ge_one hL) + have hm : 1 ≤ R^2*(sourceZ z)^20 := one_le_mul_of_one_le_of_one_le hR2 hZ20 + have hf : 1 ≤ 2*(R^2*(sourceZ z)^20) := by linarith + calc + Sq = Sq*1 := by ring + _ ≤ Sq*(2*(R^2*(sourceZ z)^20)) := mul_le_mul_of_nonneg_left hf hSq + _ = 2*Sq*R^2*(sourceZ z)^20 := by ring + _ ≤ z^3 := hheight + +theorem uniform_source_square_scale (C : ℝ) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, 2 ≤ z ∧ 1 ≤ Real.log z ∧ ∀ Sq R p q xi : ℝ, + 1 ≤ p → 0 < q → p*q ≤ (sourceY z : ℝ) → + 1 ≤ Sq/q → Sq/q ≤ (1+xi)^(C*Real.log (sourceB z)) → + 1 ≤ R → R ≤ z^((1 : ℝ)/100) → 0 ≤ xi → xi ≤ 1 → Sq ≤ z^3 := by + filter_upwards [uniform_box_height C hC,source_B_bounds, + Real.tendsto_log_atTop.eventually_ge_atTop 1,eventually_ge_atTop (2 : ℝ)] with z hheight hB hL hz + refine ⟨hz,hL,?_⟩ + intro Sq R p q xi hp hq hpq hSqratio hinfl hR hRhi hxi0 hxi1 + have hSq : 0 ≤ Sq := hq.le.trans ((one_le_div hq).mp hSqratio) + have hqz := source_cofactor_le_square hL hp hq.le hpq + have hh := hheight.2 Sq R (sourceB z) xi q hSq (zero_le_one.trans hR) + hB.2.1 hB.2.2 hxi0 hxi1 hq hqz hinfl hRhi + exact square_scale_of_root_height hSq hR hL hh + +end ErdosSourcePolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceValueSmallness.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceValueSmallness.lean new file mode 100644 index 0000000000000000000000000000000000000000..ddcd467e0dfcc3ac2dd552aaa2d53f06dbaf9458 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SourceValueSmallness.lean @@ -0,0 +1,61 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +open Filter +open scoped Topology +namespace ErdosSourcePolynomial + +theorem eventual_value_budget_small (alpha delta : ℝ) (ha : 0 < alpha) (hd : 0 < delta) : + ∀ᶠ z : ℝ in atTop, 2 ≤ z ∧ 1 ≤ Real.log z ∧ ∀ R : ℝ, z^alpha ≤ R → + 4*Real.log z+Real.log 4+8*R/(Real.log z)^4+3*R/Real.log z < delta*R := by + have hlo := (isLittleO_log_rpow_rpow_atTop (1 : ℝ) ha).bound (by positivity : 0 < delta/16) + have hlarge := Real.tendsto_log_atTop.eventually_ge_atTop (max 1 (44/delta)) + have hpow := (tendsto_rpow_atTop ha).eventually_ge_atTop (4*Real.log 4/delta) + filter_upwards [hlo,hlarge,hpow,eventually_ge_atTop (2 : ℝ)] with z hsmall hL hP hz + have hL1 : 1 ≤ Real.log z := (le_max_left _ _).trans hL + have hL0 : 0 < Real.log z := by linarith + have hz0 : 0 < z := by linarith + have hpow0 : 0 < z^alpha := Real.rpow_pos_of_pos hz0 _ + have hlog : Real.log z ≤ delta/16*z^alpha := by + simpa only [Real.rpow_one,Real.norm_eq_abs,abs_of_pos hL0,abs_of_pos hpow0] using hsmall + have hconst : Real.log 4 ≤ delta/4*z^alpha := by + have h := (div_le_iff₀ hd).mp hP + nlinarith only [h] + have h44 : 44/delta ≤ Real.log z := (le_max_right _ _).trans hL + have hfrac : 11/Real.log z ≤ delta/4 := by + apply (div_le_iff₀ hL0).mpr + have h := (div_le_iff₀ hd).mp h44 + nlinarith only [h] + have hLpow : Real.log z ≤ (Real.log z)^4 := by + simpa only [pow_one] using pow_le_pow_right₀ hL1 (by norm_num : (1 : ℕ) ≤ 4) + have h8 : 8/(Real.log z)^4 ≤ 8/Real.log z := + div_le_div_of_nonneg_left (by norm_num) hL0 hLpow + have hsum : 8/(Real.log z)^4+3/Real.log z ≤ delta/4 := by + calc + _ ≤ 8/Real.log z+3/Real.log z := add_le_add h8 le_rfl + _ = 11/Real.log z := by ring + _ ≤ _ := hfrac + refine ⟨hz,hL1,?_⟩ + intro R hR + have hR0 : 0 < R := hpow0.trans_le hR + have haR : 4*Real.log z ≤ delta/4*R := by + have h := mul_le_mul_of_nonneg_left hR (by positivity : 0 ≤ delta/4) + nlinarith only [h,hlog] + have hbR : Real.log 4 ≤ delta/4*R := hconst.trans (mul_le_mul_of_nonneg_left hR (by positivity)) + have hcR : 8*R/(Real.log z)^4+3*R/Real.log z ≤ delta/4*R := by + convert! mul_le_mul_of_nonneg_right hsum hR0.le using 1 + ring + nlinarith [mul_pos hd hR0] + +end ErdosSourcePolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SquarefreeHarmonic.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SquarefreeHarmonic.lean new file mode 100644 index 0000000000000000000000000000000000000000..8df527eaf8213ec472285b5f7bb1e78ef6686d25 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SquarefreeHarmonic.lean @@ -0,0 +1,647 @@ +import Mathlib.Analysis.PSeries +import Mathlib.Analysis.SpecialFunctions.Pow.NthRootLemmas +import Mathlib.NumberTheory.Harmonic.Bounds +import Mathlib.NumberTheory.SelbergSieve +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Sieve.IntervalBoundingSieve + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.SelbergOptimization + +open scoped BigOperators ArithmeticFunction.Moebius + +theorem sum_multiples_reverse (P l : ℕ) (hP : 0 < P) (hl : l ∣ P) + (G : ℕ → ℝ) : + (∑ d ∈ P.divisors, if l ∣ d then G (P / d) else 0) = + ∑ t ∈ (P / l).divisors, G t := by + have hPn : P ≠ 0 := ne_of_gt hP + have hdvd : P / l ∣ P := Nat.div_dvd_of_dvd hl + rw [← Nat.divisors_filter_dvd_of_dvd hPn hdvd, Finset.sum_filter] + rw [← Nat.sum_div_divisors P (fun d => if l ∣ d then G (P / d) else 0)] + apply Finset.sum_congr rfl + intro d hd + have hdP : d ∣ P := Nat.dvd_of_mem_divisors hd + rw [Nat.div_div_self hdP hPn] + have heq : l ∣ P / d ↔ d ∣ P / l := by + rw [Nat.dvd_div_iff_mul_dvd hdP, Nat.dvd_div_iff_mul_dvd hl, Nat.mul_comm] + simp only [heq] + +noncomputable def lowerMobius (F : ℕ → ℝ) (m : ℕ) : ℝ := + ∑ t ∈ m.divisorsAntidiagonal, (μ t.1 : ℝ) * F t.2 + +theorem sum_lowerMobius (F : ℕ → ℝ) {m : ℕ} (hm : 0 < m) : + (∑ t ∈ m.divisors, lowerMobius F t) = F m := by + apply (ArithmeticFunction.sum_eq_iff_sum_mul_moebius_eq.mpr ?_) m hm + intro n _ + rfl + +noncomputable def inverseMultiples (P : ℕ) (y : ℕ → ℝ) (d : ℕ) : ℝ := + lowerMobius (fun t => y (P / t)) (P / d) + +theorem sum_inverseMultiples (P l : ℕ) (hP : 0 < P) (hl : l ∣ P) + (y : ℕ → ℝ) : + (∑ d ∈ P.divisors, if l ∣ d then inverseMultiples P y d else 0) = y l := by + rw [show (∑ d ∈ P.divisors, if l ∣ d then inverseMultiples P y d else 0) = + ∑ t ∈ (P / l).divisors, lowerMobius (fun t => y (P / t)) t by + exact sum_multiples_reverse P l hP hl _] + have hlpos : 0 < l := Nat.pos_of_dvd_of_pos hl hP + rw [sum_lowerMobius _ (Nat.div_pos (Nat.le_of_dvd hP hl) hlpos)] + exact congrArg y (Nat.div_div_self hl (ne_of_gt hP)) + +noncomputable def normalization (s : BoundingSieve) (R : ℕ) : ℝ := + ∑ l ∈ s.prodPrimes.divisors, if l ≤ R then s.selbergTerms l else 0 + +theorem normalization_pos (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) : + 0 < normalization s R := by + have h1 : 1 ∈ s.prodPrimes.divisors := Nat.mem_divisors.mpr + ⟨one_dvd _, s.prodPrimes_squarefree.ne_zero⟩ + have hone : s.selbergTerms 1 = 1 := s.selbergTerms_isMultiplicative.1 + have hnonneg : ∀ l ∈ s.prodPrimes.divisors, + (0 : ℝ) ≤ if l ≤ R then s.selbergTerms l else 0 := by + intro l hl + split_ifs + · exact (s.selbergTerms_pos (Nat.dvd_of_mem_divisors hl)).le + · exact le_rfl + have hle : (1 : ℝ) ≤ normalization s R := by + simpa only [hR, ite_true, hone, normalization] using Finset.single_le_sum hnonneg h1 + exact lt_of_lt_of_le zero_lt_one hle + +noncomputable def diagonalTarget (s : BoundingSieve) (R l : ℕ) : ℝ := + if l ≤ R then (μ l : ℝ) * s.selbergTerms l / normalization s R else 0 + +noncomputable def optimizedWeight (s : BoundingSieve) (R d : ℕ) : ℝ := + inverseMultiples s.prodPrimes (diagonalTarget s R) d / s.nu d + +theorem nu_mul_optimizedWeight (s : BoundingSieve) (R : ℕ) {d : ℕ} + (hd : d ∣ s.prodPrimes) : + s.nu d * optimizedWeight s R d = + inverseMultiples s.prodPrimes (diagonalTarget s R) d := by + unfold optimizedWeight + exact mul_div_cancel₀ _ (s.nu_ne_zero hd) + +theorem optimized_diagonal_coordinates (s : BoundingSieve) (R : ℕ) {l : ℕ} + (hl : l ∣ s.prodPrimes) : + (∑ d ∈ s.prodPrimes.divisors, + if l ∣ d then s.nu d * optimizedWeight s R d else 0) = diagonalTarget s R l := by + have hrewrite : (∑ d ∈ s.prodPrimes.divisors, + if l ∣ d then s.nu d * optimizedWeight s R d else 0) = + ∑ d ∈ s.prodPrimes.divisors, + if l ∣ d then inverseMultiples s.prodPrimes (diagonalTarget s R) d else 0 := by + apply Finset.sum_congr rfl + intro d hd + rw [nu_mul_optimizedWeight s R (Nat.dvd_of_mem_divisors hd)] + rw [hrewrite] + exact sum_inverseMultiples s.prodPrimes l + (Nat.pos_of_ne_zero s.prodPrimes_squarefree.ne_zero) hl _ + +theorem inverseMultiples_one (P : ℕ) (hP : 0 < P) (y : ℕ → ℝ) : + inverseMultiples P y 1 = ∑ l ∈ P.divisors, (μ l : ℝ) * y l := by + unfold inverseMultiples lowerMobius + rw [Nat.div_one, Nat.sum_divisorsAntidiagonal (fun d e => (μ d : ℝ) * y (P / e))] + apply Finset.sum_congr rfl + intro l hl + rw [Nat.div_div_self (Nat.dvd_of_mem_divisors hl) (ne_of_gt hP)] + +theorem optimizedWeight_one (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) : + optimizedWeight s R 1 = 1 := by + have hP : 0 < s.prodPrimes := Nat.pos_of_ne_zero s.prodPrimes_squarefree.ne_zero + have hH : normalization s R ≠ 0 := ne_of_gt (normalization_pos s hR) + have hn1 : s.nu 1 = 1 := s.nu_mult.1 + unfold optimizedWeight + rw [hn1, div_one, inverseMultiples_one _ hP] + have hterm : ∀ l ∈ s.prodPrimes.divisors, + (μ l : ℝ) * diagonalTarget s R l = + (if l ≤ R then s.selbergTerms l else 0) / normalization s R := by + intro l hl + have hsq : (μ l : ℝ) ^ 2 = 1 := by + exact_mod_cast ArithmeticFunction.moebius_sq_eq_one_of_squarefree + (s.prodPrimes_squarefree.squarefree_of_dvd (Nat.dvd_of_mem_divisors hl)) + unfold diagonalTarget + split_ifs + · calc + (μ l : ℝ) * ((μ l : ℝ) * s.selbergTerms l / normalization s R) = + (μ l : ℝ) ^ 2 * s.selbergTerms l / normalization s R := by ring + _ = _ := by rw [hsq, one_mul] + · simp + rw [Finset.sum_congr rfl hterm, ← Finset.sum_div] + exact div_self hH + +theorem optimized_upperMoebius (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) : + BoundingSieve.IsUpperMoebius (BoundingSieve.lambdaSquared (optimizedWeight s R)) := + BoundingSieve.upperMoebius_lambdaSquared _ (optimizedWeight_one s hR) + +theorem optimized_mainSum (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) : + s.mainSum (BoundingSieve.lambdaSquared (optimizedWeight s R)) = + (normalization s R)⁻¹ := by + have hH : normalization s R ≠ 0 := ne_of_gt (normalization_pos s hR) + rw [s.mainSum_lambdaSquared_eq_sum_mul_sum_sq] + have hterm : ∀ l ∈ s.prodPrimes.divisors, + (s.selbergTerms l)⁻¹ * + (∑ d ∈ s.prodPrimes.divisors, + if l ∣ d then s.nu d * optimizedWeight s R d else 0) ^ 2 = + (if l ≤ R then s.selbergTerms l else 0) / (normalization s R) ^ 2 := by + intro l hl + have hldiv := Nat.dvd_of_mem_divisors hl + have hg : s.selbergTerms l ≠ 0 := ne_of_gt (s.selbergTerms_pos hldiv) + have hsq : (μ l : ℝ) ^ 2 = 1 := by + exact_mod_cast ArithmeticFunction.moebius_sq_eq_one_of_squarefree + (s.prodPrimes_squarefree.squarefree_of_dvd hldiv) + rw [optimized_diagonal_coordinates s R hldiv] + unfold diagonalTarget + split_ifs + · rw [div_pow, mul_pow, hsq, one_mul] + field_simp + · simp + rw [Finset.sum_congr rfl hterm, ← Finset.sum_div] + change normalization s R / (normalization s R) ^ 2 = _ + field_simp + +theorem lowerMobius_abs_le (F : ℕ → ℝ) (m : ℕ) : + |lowerMobius F m| ≤ ∑ t ∈ m.divisors, |F t| := by + unfold lowerMobius + rw [Nat.sum_divisorsAntidiagonal (fun d e => (μ d : ℝ) * F e)] + calc + |∑ d ∈ m.divisors, (μ d : ℝ) * F (m / d)| ≤ + ∑ d ∈ m.divisors, |(μ d : ℝ) * F (m / d)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ d ∈ m.divisors, |F (m / d)| := by + apply Finset.sum_le_sum + intro d _ + rw [abs_mul] + have hmu : |(μ d : ℝ)| ≤ 1 := by + exact_mod_cast (ArithmeticFunction.abs_moebius_le_one (n := d)) + simpa only [one_mul] using mul_le_mul_of_nonneg_right hmu (abs_nonneg (F (m / d))) + _ = _ := Nat.sum_div_divisors m (fun d => |F d|) + +theorem sum_abs_diagonalTarget (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) : + (∑ l ∈ s.prodPrimes.divisors, |diagonalTarget s R l|) = 1 := by + have hH : 0 < normalization s R := normalization_pos s hR + have hterm : ∀ l ∈ s.prodPrimes.divisors, + |diagonalTarget s R l| = + (if l ≤ R then s.selbergTerms l else 0) / normalization s R := by + intro l hl + have hg := s.selbergTerms_pos (Nat.dvd_of_mem_divisors hl) + have hmu : |(μ l : ℝ)| = 1 := by + exact_mod_cast ArithmeticFunction.abs_moebius_eq_one_of_squarefree + (s.prodPrimes_squarefree.squarefree_of_dvd (Nat.dvd_of_mem_divisors hl)) + unfold diagonalTarget + split_ifs + · rw [abs_div, abs_mul, hmu, one_mul, abs_of_pos hg, abs_of_pos hH] + · simp + rw [Finset.sum_congr rfl hterm, ← Finset.sum_div] + exact div_self (ne_of_gt hH) + +theorem optimizedWeight_abs_le_inv_nu (s : BoundingSieve) {R d : ℕ} + (hR : 1 ≤ R) (hd : d ∣ s.prodPrimes) : + |optimizedWeight s R d| ≤ (s.nu d)⁻¹ := by + have hnu : 0 < s.nu d := s.nu_pos_of_dvd_prodPrimes hd + have hmass : |inverseMultiples s.prodPrimes (diagonalTarget s R) d| ≤ 1 := by + unfold inverseMultiples + calc + _ ≤ ∑ t ∈ (s.prodPrimes / d).divisors, + |diagonalTarget s R (s.prodPrimes / t)| := lowerMobius_abs_le _ _ + _ ≤ ∑ t ∈ s.prodPrimes.divisors, |diagonalTarget s R (s.prodPrimes / t)| := by + apply Finset.sum_le_sum_of_subset_of_nonneg + (Nat.divisors_subset_of_dvd s.prodPrimes_squarefree.ne_zero (Nat.div_dvd_of_dvd hd)) + intro i _ _ + exact abs_nonneg _ + _ = ∑ l ∈ s.prodPrimes.divisors, |diagonalTarget s R l| := + Nat.sum_div_divisors s.prodPrimes (fun l => |diagonalTarget s R l|) + _ = 1 := sum_abs_diagonalTarget s hR + unfold optimizedWeight + rw [abs_div, abs_of_pos hnu, inv_eq_one_div] + exact div_le_div_of_nonneg_right hmass hnu.le + +theorem optimizedWeight_eq_zero_of_cutoff_lt (s : BoundingSieve) {R d : ℕ} + (hd : d ∣ s.prodPrimes) (hRd : R < d) : optimizedWeight s R d = 0 := by + unfold optimizedWeight inverseMultiples lowerMobius + suffices (∑ t ∈ (s.prodPrimes / d).divisorsAntidiagonal, + (μ t.1 : ℝ) * diagonalTarget s R (s.prodPrimes / t.2)) = 0 by + rw [this, zero_div] + apply Finset.sum_eq_zero + intro t ht + have htdiv : t.2 ∣ s.prodPrimes / d := + Nat.dvd_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal ht) + have htP : t.2 ∣ s.prodPrimes := htdiv.trans (Nat.div_dvd_of_dvd hd) + have hdq : d ∣ s.prodPrimes / t.2 := by + rw [Nat.dvd_div_iff_mul_dvd htP, Nat.mul_comm] + exact (Nat.dvd_div_iff_mul_dvd hd).mp htdiv + have hqpos : 0 < s.prodPrimes / t.2 := Nat.div_pos + (Nat.le_of_dvd (Nat.pos_of_ne_zero s.prodPrimes_squarefree.ne_zero) htP) + (Nat.pos_of_dvd_of_pos htP (Nat.pos_of_ne_zero s.prodPrimes_squarefree.ne_zero)) + have hRq : R < s.prodPrimes / t.2 := hRd.trans_le (Nat.le_of_dvd hqpos hdq) + simp only [diagonalTarget, ite_eq_right (not_le_of_gt hRq), mul_zero] + +theorem sum_lambdaSquared (P : ℕ) (w : ℕ → ℝ) : + (∑ d ∈ P.divisors, BoundingSieve.lambdaSquared w d) = + (∑ d ∈ P.divisors, w d) ^ 2 := by + unfold BoundingSieve.lambdaSquared + have henlarge : + (∑ d ∈ P.divisors, ∑ a ∈ d.divisors, ∑ b ∈ d.divisors, + if d = Nat.lcm a b then w a * w b else 0) = + ∑ d ∈ P.divisors, ∑ a ∈ P.divisors, ∑ b ∈ P.divisors, + if d = Nat.lcm a b then w a * w b else 0 := by + congr! 1 with d hd + rw [Nat.mem_divisors] at hd + suffices ∀ a b, (a ∣ d ∧ b ∣ d ∧ d = a.lcm b) = (d = a.lcm b) by + simp_rw [← Nat.divisors_filter_dvd_of_dvd hd.2 hd.1, Finset.sum_filter, + Finset.ite_sum_zero, ← ite_and, this] + simp +contextual [← and_assoc, Nat.dvd_lcm_left, Nat.dvd_lcm_right] + rw [henlarge, Finset.sum_comm] + calc + _ = ∑ a ∈ P.divisors, ∑ b ∈ P.divisors, w a * w b := by + apply Finset.sum_congr rfl + intro a ha + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b hb + have hlcm : a.lcm b ∈ P.divisors := Nat.mem_divisors.mpr + ⟨Nat.lcm_dvd (Nat.dvd_of_mem_divisors ha) (Nat.dvd_of_mem_divisors hb), + (Nat.mem_divisors.mp ha).2⟩ + rw [Finset.sum_ite_eq_of_mem' P.divisors (a.lcm b) _ hlcm] + _ = _ := by rw [sq, Finset.sum_mul]; simp only [Finset.mul_sum] + +theorem sum_abs_lambdaSquared_le (P : ℕ) (w : ℕ → ℝ) : + (∑ d ∈ P.divisors, |BoundingSieve.lambdaSquared w d|) ≤ + (∑ d ∈ P.divisors, |w d|) ^ 2 := by + have hterm : ∀ d, |BoundingSieve.lambdaSquared w d| ≤ + BoundingSieve.lambdaSquared (fun a => |w a|) d := by + intro d + unfold BoundingSieve.lambdaSquared + calc + _ ≤ ∑ a ∈ d.divisors, |∑ b ∈ d.divisors, + if d = a.lcm b then w a * w b else 0| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ a ∈ d.divisors, ∑ b ∈ d.divisors, + |if d = a.lcm b then w a * w b else 0| := + Finset.sum_le_sum fun _ _ => Finset.abs_sum_le_sum_abs _ _ + _ = _ := by simp only [abs_ite, abs_mul, abs_zero] + calc + _ ≤ ∑ d ∈ P.divisors, BoundingSieve.lambdaSquared (fun a => |w a|) d := + Finset.sum_le_sum fun d _ => hterm d + _ = _ := sum_lambdaSquared _ _ + +theorem optimizedWeight_sum_abs_le_sq (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) + (hnu : ∀ d, d ∣ s.prodPrimes → s.nu d = (d : ℝ)⁻¹) : + (∑ d ∈ s.prodPrimes.divisors, |optimizedWeight s R d|) ≤ (R : ℝ) ^ 2 := by + classical + let D := s.prodPrimes.divisors.filter fun d => d ≤ R + have hrestricted : (∑ d ∈ s.prodPrimes.divisors, |optimizedWeight s R d|) = + ∑ d ∈ D, |optimizedWeight s R d| := by + symm + apply Finset.sum_subset (Finset.filter_subset _ _) + intro d hd hnot + have hRd : R < d := by + have : ¬ d ≤ R := fun hdR => hnot (Finset.mem_filter.mpr ⟨hd, hdR⟩) + omega + rw [optimizedWeight_eq_zero_of_cutoff_lt s (Nat.dvd_of_mem_divisors hd) hRd, abs_zero] + have hDsub : D ⊆ Finset.Icc 1 R := by + intro d hd + obtain ⟨hdP, hdR⟩ := Finset.mem_filter.mp hd + exact Finset.mem_Icc.mpr ⟨Nat.pos_of_mem_divisors hdP, hdR⟩ + have hDcard : D.card ≤ R := by + simpa using Finset.card_le_card hDsub + rw [hrestricted] + calc + _ ≤ ∑ _d ∈ D, (R : ℝ) := by + apply Finset.sum_le_sum + intro d hd + obtain ⟨hdP, hdR⟩ := Finset.mem_filter.mp hd + have hpoint := optimizedWeight_abs_le_inv_nu s hR (Nat.dvd_of_mem_divisors hdP) + rw [hnu d (Nat.dvd_of_mem_divisors hdP), inv_inv] at hpoint + exact hpoint.trans (by exact_mod_cast hdR) + _ = (D.card : ℝ) * R := by simp + _ ≤ (R : ℝ) ^ 2 := by + rw [sq] + exact mul_le_mul_of_nonneg_right (by exact_mod_cast hDcard) (Nat.cast_nonneg R) + +theorem optimized_lambda_error_norm (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) + (hnu : ∀ d, d ∣ s.prodPrimes → s.nu d = (d : ℝ)⁻¹) : + (∑ d ∈ s.prodPrimes.divisors, + |BoundingSieve.lambdaSquared (optimizedWeight s R) d|) ≤ (R : ℝ) ^ 4 := by + have hsum := optimizedWeight_sum_abs_le_sq s hR hnu + have hnonneg : 0 ≤ ∑ d ∈ s.prodPrimes.divisors, |optimizedWeight s R d| := + Finset.sum_nonneg fun _ _ => abs_nonneg _ + calc + _ ≤ (∑ d ∈ s.prodPrimes.divisors, |optimizedWeight s R d|) ^ 2 := + sum_abs_lambdaSquared_le _ _ + _ ≤ (R : ℝ) ^ 4 := by nlinarith [sq_nonneg ((R : ℝ)^2 - + ∑ d ∈ s.prodPrimes.divisors, |optimizedWeight s R d|)] + +theorem siftedSum_le_optimized (s : BoundingSieve) {R : ℕ} (hR : 1 ≤ R) + (hnu : ∀ d, d ∣ s.prodPrimes → s.nu d = (d : ℝ)⁻¹) + (hrem : ∀ d ∈ s.prodPrimes.divisors, |s.rem d| ≤ 1) : + s.siftedSum ≤ s.totalMass / normalization s R + (R : ℝ) ^ 4 := by + have hs := s.siftedSum_le_mainSum_errSum_of_upperMoebius _ (optimized_upperMoebius s hR) + rw [optimized_mainSum s hR, ← div_eq_mul_inv] at hs + apply hs.trans + apply add_le_add le_rfl + calc + s.errSum (BoundingSieve.lambdaSquared (optimizedWeight s R)) ≤ + ∑ d ∈ s.prodPrimes.divisors, |BoundingSieve.lambdaSquared (optimizedWeight s R) d| := by + apply Finset.sum_le_sum + intro d hd + simpa only [mul_one] using mul_le_mul_of_nonneg_left (hrem d hd) + (abs_nonneg (BoundingSieve.lambdaSquared (optimizedWeight s R) d)) + _ ≤ (R : ℝ) ^ 4 := optimized_lambda_error_norm s hR hnu + +noncomputable def cutoffNormalization (z R : ℕ) : ℝ := + normalization (IntervalBoundingSieve.intervalSieve 0 0 + (IntervalBoundingSieve.cutoffProduct z) (IntervalBoundingSieve.cutoffProduct_squarefree z)) R + +theorem cutoffNormalization_pos (z : ℕ) {R : ℕ} (hR : 1 ≤ R) : + 0 < cutoffNormalization z R := normalization_pos _ hR + +theorem cutoffSurvivors_le_optimized (J z : ℕ) (residue : ℕ → ℕ) + {R : ℕ} (hR : 1 ≤ R) : + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + (J : ℝ) / cutoffNormalization z R + (R : ℝ) ^ 4 := by + let s := IntervalBoundingSieve.intervalSieve 0 0 + (IntervalBoundingSieve.cutoffProduct z) (IntervalBoundingSieve.cutoffProduct_squarefree z) + let muPlus := BoundingSieve.lambdaSquared (optimizedWeight s R) + have hmu : BoundingSieve.IsUpperMoebius muPlus := optimized_upperMoebius s hR + have hs := IntervalBoundingSieve.cutoffSurvivors_card_le_upperMoebius J z residue muPlus hmu + have hmain : (∑ d ∈ (IntervalBoundingSieve.cutoffProduct z).divisors, muPlus d / d) = + (cutoffNormalization z R)⁻¹ := by + change (∑ d ∈ s.prodPrimes.divisors, muPlus d / d) = (normalization s R)⁻¹ + have heq : (∑ d ∈ s.prodPrimes.divisors, muPlus d / d) = s.mainSum muPlus := by + rfl + rw [heq] + exact optimized_mainSum s hR + have herr : (∑ d ∈ (IntervalBoundingSieve.cutoffProduct z).divisors, |muPlus d|) ≤ + (R : ℝ) ^ 4 := by + apply optimized_lambda_error_norm s hR + intro d _ + rfl + rw [hmain, ← div_eq_mul_inv] at hs + exact hs.trans (add_le_add le_rfl herr) + +end NumberTheoryLean.SelbergOptimization + +end + +section + +namespace NumberTheoryLean.SquarefreeHarmonic + +open scoped BigOperators + +noncomputable def squarefreeUpTo (R : ℕ) : Finset ℕ := by + classical + exact (Finset.Icc 1 R).filter Squarefree + +@[simp] theorem mem_squarefreeUpTo {R d : ℕ} : + d ∈ squarefreeUpTo R ↔ 1 ≤ d ∧ d ≤ R ∧ Squarefree d := by + classical + simp only [squarefreeUpTo, Finset.mem_filter, Finset.mem_Icc] + tauto + +noncomputable def squarefreeHarmonic (R : ℕ) : ℝ := + ∑ d ∈ squarefreeUpTo R, (d : ℝ)⁻¹ + +theorem interval_subset_square_product (R : ℕ) : + Finset.Icc 1 R ⊆ + ((squarefreeUpTo R).product (Finset.Icc 1 R)).image + (fun t : ℕ × ℕ => t.2 ^ 2 * t.1) := by + classical + intro n hn + obtain ⟨hnpos, hnR⟩ := Finset.mem_Icc.mp hn + obtain ⟨d, a, hd, ha, heq, hsf⟩ := Nat.sq_mul_squarefree_of_pos hnpos + have hdle : d ≤ n := Nat.le_of_dvd hnpos ⟨a ^ 2, by nlinarith [heq]⟩ + have hale : a ≤ n := by + have ha2 : a ≤ a ^ 2 := by nlinarith + have hmul : a ^ 2 ≤ a ^ 2 * d := Nat.le_mul_of_pos_right _ hd + exact ha2.trans (hmul.trans_eq heq) + exact Finset.mem_image.mpr ⟨(d, a), Finset.mem_product.mpr + ⟨mem_squarefreeUpTo.mpr ⟨hd, hdle.trans hnR, hsf⟩, + Finset.mem_Icc.mpr ⟨ha, hale.trans hnR⟩⟩, heq⟩ + +theorem sum_inv_sq_le_two (R : ℕ) : + (∑ a ∈ Finset.Icc 1 R, ((a : ℝ) ^ 2)⁻¹) ≤ 2 := by + have hset : Finset.Ioo 0 (R + 1) = Finset.Icc 1 R := by + ext a + simp only [Finset.mem_Ioo, Finset.mem_Icc] + omega + simpa only [hset, Nat.cast_zero, zero_add, div_one] using + (sum_Ioo_inv_sq_le (α := ℝ) 0 (R + 1)) + +theorem harmonic_le_twice_squarefreeHarmonic (R : ℕ) : + (harmonic R : ℝ) ≤ 2 * squarefreeHarmonic R := by + classical + let T := (squarefreeUpTo R).product (Finset.Icc 1 R) + let f : ℕ × ℕ → ℕ := fun t => t.2 ^ 2 * t.1 + have hnonneg : 0 ≤ squarefreeHarmonic R := Finset.sum_nonneg fun _ _ => by positivity + calc + (harmonic R : ℝ) = ∑ n ∈ Finset.Icc 1 R, (n : ℝ)⁻¹ := by + simp only [harmonic_eq_sum_Icc, Rat.cast_sum, Rat.cast_inv, Rat.cast_natCast] + _ ≤ ∑ n ∈ T.image f, (n : ℝ)⁻¹ := by + apply Finset.sum_le_sum_of_subset_of_nonneg (interval_subset_square_product R) + intro n _ _ + positivity + _ ≤ ∑ t ∈ T, ((f t : ℕ) : ℝ)⁻¹ := + Finset.sum_image_le_of_nonneg (fun n _ => by positivity) + _ = squarefreeHarmonic R * ∑ a ∈ Finset.Icc 1 R, ((a : ℝ) ^ 2)⁻¹ := by + simp only [T, f, Nat.cast_mul, Nat.cast_pow, mul_inv_rev, squarefreeHarmonic] + rw [Finset.product_eq_sprod, Finset.sum_product' (squarefreeUpTo R) (Finset.Icc 1 R) + (fun d a => (d : ℝ)⁻¹ * ((a : ℝ)^2)⁻¹), Finset.sum_mul] + simp only [Finset.mul_sum] + _ ≤ squarefreeHarmonic R * 2 := + mul_le_mul_of_nonneg_left (sum_inv_sq_le_two R) hnonneg + _ = _ := mul_comm _ _ + +theorem log_le_twice_squarefreeHarmonic (R : ℕ) : + Real.log (R + 1) ≤ 2 * squarefreeHarmonic R := by + have hlog : Real.log ((R + 1 : ℕ) : ℝ) ≤ harmonic R := log_add_one_le_harmonic R + push_cast at hlog + exact hlog.trans (harmonic_le_twice_squarefreeHarmonic R) + +theorem nu_le_selbergTerms (s : BoundingSieve) {d : ℕ} + (hd : d ∣ s.prodPrimes) : s.nu d ≤ s.selbergTerms d := by + rw [s.selbergTerms_apply] + have hprod : (1 : ℝ) ≤ ∏ p ∈ d.primeFactors, (1 - s.nu p)⁻¹ := by + apply Finset.one_le_prod₀ + intro p hp + have hpprime := Nat.prime_of_mem_primeFactors hp + have hpP := (Nat.dvd_of_mem_primeFactors hp).trans hd + have hp0 := s.nu_pos_of_prime p hpprime hpP + have hp1 := s.nu_lt_one_of_prime p hpprime hpP + exact (one_le_inv₀ (by linarith)).mpr (by linarith) + simpa only [mul_one] using + mul_le_mul_of_nonneg_left hprod (s.nu_pos_of_dvd_prodPrimes hd).le + +theorem squarefreeUpTo_subset_cutoff_divisors {R z : ℕ} (hRz : R ≤ z) : + squarefreeUpTo R ⊆ (IntervalBoundingSieve.cutoffProduct z).divisors.filter + (fun d => d ≤ R) := by + classical + intro d hd + obtain ⟨hd0, hdR, hsf⟩ := mem_squarefreeUpTo.mp hd + have hprimeSub : d.primeFactors ⊆ LargePrimeDeletion.cutoffPrimes z := by + intro p hp + obtain ⟨hpp, hpd, _⟩ := Nat.mem_primeFactors.mp hp + exact LargePrimeDeletion.mem_cutoffPrimes.mpr + ⟨hpp, (Nat.le_of_dvd hd0 hpd).trans (hdR.trans hRz)⟩ + have hdiv : d ∣ IntervalBoundingSieve.cutoffProduct z := by + rw [← Nat.prod_primeFactors_of_squarefree hsf] + exact Finset.prod_dvd_prod_of_subset _ _ id hprimeSub + exact Finset.mem_filter.mpr + ⟨Nat.mem_divisors.mpr ⟨hdiv, (IntervalBoundingSieve.cutoffProduct_squarefree z).ne_zero⟩, + hdR⟩ + +theorem squarefreeHarmonic_le_selberg_sum {R z : ℕ} (hRz : R ≤ z) : + squarefreeHarmonic R ≤ + ∑ d ∈ (IntervalBoundingSieve.cutoffProduct z).divisors, + if d ≤ R then + (IntervalBoundingSieve.intervalSieve 0 0 (IntervalBoundingSieve.cutoffProduct z) + (IntervalBoundingSieve.cutoffProduct_squarefree z)).selbergTerms d else 0 := by + classical + let s := IntervalBoundingSieve.intervalSieve 0 0 (IntervalBoundingSieve.cutoffProduct z) + (IntervalBoundingSieve.cutoffProduct_squarefree z) + let D := s.prodPrimes.divisors.filter fun d => d ≤ R + have hsub : squarefreeUpTo R ⊆ D := squarefreeUpTo_subset_cutoff_divisors hRz + change squarefreeHarmonic R ≤ ∑ d ∈ s.prodPrimes.divisors, + if d ≤ R then s.selbergTerms d else 0 + calc + squarefreeHarmonic R = ∑ d ∈ squarefreeUpTo R, s.nu d := rfl + _ ≤ ∑ d ∈ squarefreeUpTo R, s.selbergTerms d := by + apply Finset.sum_le_sum + intro d hd + exact nu_le_selbergTerms s (Nat.dvd_of_mem_divisors (Finset.mem_filter.mp (hsub hd)).1) + _ ≤ ∑ d ∈ D, s.selbergTerms d := by + apply Finset.sum_le_sum_of_subset_of_nonneg hsub + intro d hd _ + exact (s.selbergTerms_pos (Nat.dvd_of_mem_divisors (Finset.mem_filter.mp hd).1)).le + _ = _ := Finset.sum_filter _ _ + +theorem log_le_twice_selberg_sum {R z : ℕ} (hRz : R ≤ z) : + Real.log (R + 1) ≤ + 2 * ∑ d ∈ (IntervalBoundingSieve.cutoffProduct z).divisors, + if d ≤ R then + (IntervalBoundingSieve.intervalSieve 0 0 (IntervalBoundingSieve.cutoffProduct z) + (IntervalBoundingSieve.cutoffProduct_squarefree z)).selbergTerms d else 0 := by + exact (log_le_twice_squarefreeHarmonic R).trans + (mul_le_mul_of_nonneg_left (squarefreeHarmonic_le_selberg_sum hRz) (by norm_num)) + +theorem log_le_twice_cutoffNormalization {R z : ℕ} (hRz : R ≤ z) : + Real.log (R + 1) ≤ 2 * SelbergOptimization.cutoffNormalization z R := + log_le_twice_selberg_sum hRz + +theorem cutoffSurvivors_le_log_bound (J z : ℕ) (residue : ℕ → ℕ) + {R : ℕ} (hR : 1 ≤ R) (hRz : R ≤ z) : + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + 2 * (J : ℝ) / Real.log (R + 1) + (R : ℝ) ^ 4 := by + have hH : 0 < SelbergOptimization.cutoffNormalization z R := + SelbergOptimization.cutoffNormalization_pos z hR + have hlog : 0 < Real.log (R + 1) := Real.log_pos (by exact_mod_cast Nat.succ_lt_succ hR) + have hlower := log_le_twice_cutoffNormalization hRz + have hdiv : (J : ℝ) / SelbergOptimization.cutoffNormalization z R ≤ + 2 * (J : ℝ) / Real.log (R + 1) := by + apply (div_le_div_iff₀ hH hlog).mpr + nlinarith [mul_nonneg (Nat.cast_nonneg J) (sub_nonneg.mpr hlower)] + exact (SelbergOptimization.cutoffSurvivors_le_optimized J z residue hR).trans + (add_le_add hdiv le_rfl) + +theorem cutoffSurvivors_le_seventeen_of_eighth_radius + (J z : ℕ) (residue : ℕ → ℕ) {R : ℕ} + (hR : 2 ≤ R) (hRz : R ≤ z) (hlo : R ^ 8 ≤ J) (hhi : J ≤ (R + 1) ^ 8) : + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + 17 * (J : ℝ) / Real.log J := by + have hRreal : (2 : ℝ) ≤ R := by exact_mod_cast hR + have hJlo : (R : ℝ) ^ 8 ≤ J := by exact_mod_cast hlo + have hJhi : (J : ℝ) ≤ ((R : ℝ) + 1) ^ 8 := by exact_mod_cast hhi + have hR8 : (256 : ℝ) ≤ (R : ℝ) ^ 8 := by + have := pow_le_pow_left₀ (by norm_num : (0 : ℝ) ≤ 2) hRreal 8 + norm_num at this + exact this + have hJone : (1 : ℝ) < J := by linarith + have hJpos : (0 : ℝ) < J := by linarith + have hlogJpos : 0 < Real.log (J : ℝ) := Real.log_pos hJone + have hlogRpos : 0 < Real.log ((R : ℝ) + 1) := Real.log_pos (by linarith) + have hlogupper : Real.log (J : ℝ) ≤ 8 * Real.log ((R : ℝ) + 1) := by + have h := Real.log_le_log hJpos hJhi + rw [Real.log_pow] at h + norm_num at h + exact h + have hlogRle : Real.log ((R : ℝ) + 1) ≤ R := by + have h := Real.log_le_sub_one_of_pos (show (0 : ℝ) < (R : ℝ) + 1 by positivity) + linarith + have hcube : (8 : ℝ) ≤ (R : ℝ) ^ 3 := by + have := pow_le_pow_left₀ (by norm_num : (0 : ℝ) ≤ 2) hRreal 3 + norm_num at this + exact this + have height : (8 : ℝ) * R ≤ (R : ℝ) ^ 4 := by + have h := mul_le_mul_of_nonneg_right hcube (Nat.cast_nonneg R) + nlinarith + have hlogJle : Real.log (J : ℝ) ≤ (R : ℝ) ^ 4 := by linarith + have hmain : 2 * (J : ℝ) / Real.log ((R : ℝ) + 1) ≤ + 16 * (J : ℝ) / Real.log (J : ℝ) := by + apply (div_le_div_iff₀ hlogRpos hlogJpos).mpr + nlinarith [mul_nonneg (Nat.cast_nonneg J) (sub_nonneg.mpr hlogupper)] + have herr : (R : ℝ) ^ 4 ≤ (J : ℝ) / Real.log (J : ℝ) := by + apply (le_div_iff₀ hlogJpos).mpr + calc + (R : ℝ) ^ 4 * Real.log (J : ℝ) ≤ (R : ℝ) ^ 4 * (R : ℝ) ^ 4 := + mul_le_mul_of_nonneg_left hlogJle (pow_nonneg (Nat.cast_nonneg R) _) + _ = (R : ℝ) ^ 8 := by ring + _ ≤ _ := hJlo + calc + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + 2 * (J : ℝ) / Real.log ((R : ℝ) + 1) + (R : ℝ) ^ 4 := + cutoffSurvivors_le_log_bound J z residue (by omega) hRz + _ ≤ 16 * (J : ℝ) / Real.log (J : ℝ) + (J : ℝ) / Real.log (J : ℝ) := + add_le_add hmain herr + _ = _ := by ring + +theorem cutoffSurvivors_le_seventeen (J z : ℕ) (residue : ℕ → ℕ) + (hJ : 256 ≤ J) (hz : Nat.nthRoot 8 J ≤ z) : + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + 17 * (J : ℝ) / Real.log J := by + apply cutoffSurvivors_le_seventeen_of_eighth_radius J z residue (R := Nat.nthRoot 8 J) + · apply (Nat.le_nthRoot_iff (by norm_num : 8 ≠ 0)).mpr + norm_num + exact hJ + · exact hz + · exact Nat.pow_nthRoot_le (Or.inl (by norm_num : 8 ≠ 0)) + · exact (Nat.lt_pow_nthRoot_add_one (by norm_num : 8 ≠ 0) J).le + +theorem cutoffSurvivors_le_seventeen_of_le_cutoff (J z : ℕ) (residue : ℕ → ℕ) + (hJ : 256 ≤ J) (hJz : J ≤ z) : + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + 17 * (J : ℝ) / Real.log J := by + apply cutoffSurvivors_le_seventeen J z residue hJ + exact ((Nat.le_self_pow (by norm_num : 8 ≠ 0) (Nat.nthRoot 8 J)).trans + (Nat.pow_nthRoot_le (Or.inl (by norm_num : 8 ≠ 0)))).trans hJz + +theorem cutoffSurvivors_le_uniform_log (J z : ℕ) (residue : ℕ → ℕ) (hJz : J ≤ z) : + ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ + 255 * (1 + (J : ℝ) / Real.log J) := by + have hquot : 0 ≤ (J : ℝ) / Real.log J := by + by_cases hJ0 : J = 0 + · simp [hJ0] + · apply div_nonneg (Nat.cast_nonneg J) + apply Real.log_nonneg + exact_mod_cast Nat.one_le_iff_ne_zero.mpr hJ0 + by_cases hJ : 256 ≤ J + · have hbound := cutoffSurvivors_le_seventeen_of_le_cutoff J z residue hJ hJz + calc + _ ≤ 17 * (J : ℝ) / Real.log J := hbound + _ ≤ _ := by rw [mul_div_assoc]; nlinarith + · have hsmall : J ≤ 255 := by omega + have hsubset : LargePrimeDeletion.cutoffSurvivors J z residue ⊆ Finset.range J := by + intro i hi + exact Finset.mem_range.mpr (LargePrimeDeletion.mem_cutoffSurvivors.mp hi).1 + have hcount : (LargePrimeDeletion.cutoffSurvivors J z residue).card ≤ J := by + simpa only [Finset.card_range] using Finset.card_le_card hsubset + have hcountR : ((LargePrimeDeletion.cutoffSurvivors J z residue).card : ℝ) ≤ 255 := by + exact_mod_cast hcount.trans hsmall + nlinarith + +end NumberTheoryLean.SquarefreeHarmonic + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/StandardBoundaryCoefficient.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/StandardBoundaryCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..77e607aba8c16828dca477bebd16792b15fae0ec --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/StandardBoundaryCoefficient.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Probability.StandardDeficitMoments + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory +namespace Erdos970Dependency.StandardBoundary +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.BuchstabBridge +open NumberTheoryLean.NormalizedDeficits + +noncomputable def standardCoefficient : ℝ := + (∫ y in Ioi 1,(y^2-1)*(1-f sieveA (y+1)))- + ∫ y in Ioi 0,y^2*(1-F sieveA (y+1)) + +theorem standard_coefficient_integrable : + IntegrableOn (fun y : ℝ => (y^2-1)*(1-f sieveA (y+1))) (Ioi 1) ∧ + IntegrableOn (fun y : ℝ => y^2*(1-F sieveA (y+1))) (Ioi 0) := by + have h2 := shifted_deficit_moments_integrable.1.mono_set (Ioi_subset_Ioi (by norm_num : (0:ℝ)≤1)) + constructor + · apply (h2.sub lower_deficit_shift_tail.1).congr_fun _ measurableSet_Ioi + intro y _ + change y^2*lowerDeficit (y+1)-lowerDeficit (y+1) = (y^2-1)*(1-f sieveA (y+1)) + unfold lowerDeficit + ring + · apply shifted_deficit_moments_integrable.2.neg.congr_fun _ measurableSet_Ioi + intro y _ + change -(y^2*upperDeficit (y+1))=y^2*(1-F sieveA (y+1)) + unfold upperDeficit + ring + +theorem standard_coefficient_decomposition : + standardCoefficient = sieveA-(1:ℝ)/3-(sieveA-3) := by + have h2 := shifted_deficit_moments_integrable.1.mono_set (Ioi_subset_Ioi (by norm_num : (0:ℝ)≤1)) + have he : (∫ y in Ioi 1,(y^2-1)*(1-f sieveA (y+1)))= + (∫ y in Ioi 1,y^2*lowerDeficit (y+1))-(∫ y in Ioi 1,lowerDeficit (y+1)) := by + rw [← integral_sub h2 lower_deficit_shift_tail.1] + apply setIntegral_congr_fun measurableSet_Ioi + intro y _ + dsimp only + unfold lowerDeficit + ring + have ho : (∫ y in Ioi 0,y^2*(1-F sieveA (y+1)))= + -(∫ y in Ioi 0,y^2*upperDeficit (y+1)) := by + rw [← integral_neg] + apply setIntegral_congr_fun measurableSet_Ioi + intro y _ + dsimp only + unfold upperDeficit + ring + have hu : (∫ y : ℝ in 0..1,y^2*lowerDeficit (y+1))=(1:ℝ)/3 := by + calc + _ = ∫ y : ℝ in 0..1,y^2 := by + apply intervalIntegral.integral_congr + intro y hy + rw [uIcc_of_le (by norm_num : (0:ℝ)≤1)] at hy + change y^2*(1-f sieveA (y+1))=y^2 + rw [f_initial sieveA (by linarith [hy.2]),sub_zero,mul_one] + _ = _ := by norm_num + have hsplit := intervalIntegral.integral_Ioi_sub_Ioi shifted_deficit_moments_integrable.1 (by norm_num : (0:ℝ)≤1) + rw [hu] at hsplit + unfold standardCoefficient + rw [he,ho,lower_deficit_shift_tail.2] + linarith [shifted_deficit_moment_sum] + +theorem standard_coefficient_eq : standardCoefficient=(8:ℝ)/3 := by + rw [standard_coefficient_decomposition] + ring + +theorem literal_standard_coefficient : + ((∫ y in Ioi 1,(y^2-1)*(1-f sieveA (y+1)))- + ∫ y in Ioi 0,y^2*(1-F sieveA (y+1)))=(8:ℝ)/3 := + standard_coefficient_eq + +end Erdos970Dependency.StandardBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/StrongSourceFamilies.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/StrongSourceFamilies.lean new file mode 100644 index 0000000000000000000000000000000000000000..dc10b52ba75ca7977fa969ace7e156f3d17e6bd3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/StrongSourceFamilies.lean @@ -0,0 +1,80 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.UncappedCompactMass +import OAI.NumberTheory.Jacobsthal.Partitions.StrongReferenceTransport + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.StrongSourceFamilies +open FinitePathGeometry PrimeHistories PrimeTiltGeometry PrimeBinMembership ActualPrimeHigh StrongReferenceTransport +open ReferenceAdmission LogarithmicBinPartition UncappedCompactMass +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail +attribute [local instance] Classical.propDecidable + +theorem source_reference_transport {w top : ℝ} (hw : 1 < w) (htop : w < top) (z : Node) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) (ps : List ℕ) + (hp : ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap) : + ps ∈ uncappedPrefixes w 1 z ∧ 2 ≤ (terminal w z ps).gap := by + obtain ⟨hD,ha⟩ := Finset.mem_filter.mp hp + have hDM := mem_decreasingPrefixes.mp hD + have hP : ∀ p ∈ ps,p.Prime ∧ (1:ℝ) + (source_reference_transport hw htop z hs hz hg hclosed hcap ps (hF hp)).1 + have he : (∑ ps ∈ F,prefixWeight ps)= + ∑ ps ∈ F,prefixWeight ps*(if 2 ≤ (terminal w z ps).gap ∧ (terminal w z ps).gap ≤ K then 1 else 0) := by + apply Finset.sum_congr rfl + intro ps hp + have hlo := (source_reference_transport hw htop z hs hz hg hclosed hcap ps (hF hp)).2 + rw [ite_eq_left ⟨hlo,hK ps hp⟩,mul_one] + rw [he] + exact Finset.sum_le_sum_of_subset_of_nonneg hsub (fun ps _ _ => by + split_ifs + · simpa only [mul_one] using prefixWeight_nonneg ps + · simp) + +theorem uniform_source_family_mass (K d : ℝ) (hK : 3 ≤ K) (hd : 0 < d) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → + w < top → Real.log B ≤ d*Real.log w → ∀ z : Node, + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=B → + z.closed=true → w^B=top → ∀ F : Finset (List ℕ), + F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps ∈ F,(terminal w z ps).gap ≤ K) → B^2*(∑ ps ∈ F,prefixWeight ps) ≤ C := by + obtain ⟨C,B₀,w₀,hC,_hB₀,hw₀,hbound⟩ := uniform_uncapped_compact_mass K 1 d hK (by norm_num) hd + refine ⟨C,max 3 B₀,w₀,hC,le_max_left _ _,hw₀,?_⟩ + intro B w top hB hw htop hcomp z hi h199 h23 hz hcut hclosed hcap F hF hFK + have hB3 : 3 ≤ B := (le_max_left _ _).trans hB + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB3 z hi h199 hz hcut + have hwm : 1 < w := hw₀.trans_le hw + have hmass := finite_compact_family_le hwm htop z hs hz hg hclosed (by rwa [hcut]) F hF hFK + exact (mul_le_mul_of_nonneg_left hmass (sq_nonneg B)).trans + (hbound B w ((le_max_right _ _).trans hB) hw hcomp z hi h199 h23 hz hcut) +end NumberTheoryLean.StrongSourceFamilies + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SubbinAggregation.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SubbinAggregation.lean new file mode 100644 index 0000000000000000000000000000000000000000..084ee5b0008752f124847d9da21dd300d47ffe9c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SubbinAggregation.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.Jacobsthal.Primes.CanonicalTagPrimePartition +import OAI.NumberTheory.Jacobsthal.Primes.IntervalPrimesDefinition + +namespace OAI + +namespace Erdos970 + + +namespace ErdosStoppedSubbinAggregation +open ErdosTagSubbins ErdosInversePrimeBin Erdos970Dependency.SiegelWalfisz +open scoped BigOperators +attribute [local instance] Classical.propDecidable + +theorem subbin_eq_intervalPrimes {R theta : ℝ} {N i : ℕ} + (hR : 0 < R) (ht : 0 < theta) (hN : 0 < N) : + subbin R theta N i = intervalPrimes (left R theta N i) (step R theta N) 1 0 := by + ext p + rw [mem_subbin hR ht hN,mem_intervalPrimes,right_eq_left_add] + simp [Int.ModEq] + +theorem primeBin_eq_intervalPrimes {R theta : ℝ} (hR : 0 < R) (ht : 0 < theta) : + primeBin R theta = intervalPrimes R (theta*R) 1 0 := by + ext p + rw [mem_primeBin hR.le ht.le,mem_intervalPrimes] + have he : (1+theta)*R = R+theta*R := by ring + simp [he,Int.ModEq] + +theorem aggregate_subbin_lower {R theta c V : ℝ} {N : ℕ} + (hR : 0 < R) (ht : 0 < theta) (hN : 0 < N) (hc : 0 ≤ c) (hV : 0 ≤ V) + (reward weight : ℕ → ℝ) (localWeight : Fin N → ℝ) + (hweight : ∀ i : Fin N,∀ p ∈ subbin R theta N i,weight p ≤ localWeight i) + (hlower : ∀ i : Fin N, + c*((subbin R theta N i).card : ℝ)*localWeight i*V ≤ + ∑ p ∈ subbin R theta N i,reward p) : + c*V*(∑ p ∈ primeBin R theta,weight p) ≤ ∑ p ∈ primeBin R theta,reward p := by + rw [sum_partition hR ht hN weight,sum_partition hR ht hN reward,Finset.mul_sum] + apply Finset.sum_le_sum + intro i _hi + have hsum : (∑ p ∈ subbin R theta N i,weight p) ≤ + ((subbin R theta N i).card : ℝ)*localWeight i := by + calc + _ ≤ ∑ _p ∈ subbin R theta N i,localWeight i := Finset.sum_le_sum (hweight i) + _ = _ := by simp + calc + _ ≤ c*V*(((subbin R theta N i).card : ℝ)*localWeight i) := + mul_le_mul_of_nonneg_left hsum (mul_nonneg hc hV) + _ = c*((subbin R theta N i).card : ℝ)*localWeight i*V := by ring + _ ≤ _ := hlower i + +theorem reference_length_le {Y q R p : ℝ} (hY : 0 ≤ Y) (hq : 0 < q) + (hR : 0 < R) (hp : R ≤ p) : Y/(p*q) ≤ Y/(R*q) := + div_le_div_of_nonneg_left hY (mul_pos hR hq) (mul_le_mul_of_nonneg_right hp hq.le) + +theorem aggregate_reference_lower {R theta Y q V : ℝ} {N : ℕ} + (hR : 0 < R) (ht : 0 < theta) (hN : 0 < N) + (hY : 0 ≤ Y) (hq : 0 < q) (hV : 0 ≤ V) (reward : ℕ → ℝ) + (hlower : ∀ i : Fin N, + (39/100 : ℝ)*((subbin R theta N i).card : ℝ)*(Y/(left R theta N i*q))*V ≤ + ∑ p ∈ subbin R theta N i,reward p) : + (39/100 : ℝ)*V*(∑ p ∈ primeBin R theta,Y/((p : ℝ)*q)) ≤ + ∑ p ∈ primeBin R theta,reward p := by + apply aggregate_subbin_lower hR ht hN (by norm_num) hV reward + (fun p => Y/((p : ℝ)*q)) (fun i => Y/(left R theta N i*q)) _ hlower + intro i p hp + exact reference_length_le hY hq (left_pos hR ht hN) ((mem_subbin hR ht hN).mp hp).2.1.le + +theorem aggregate_interval_reference_lower {R theta Y q V : ℝ} {N : ℕ} + (hR : 0 < R) (ht : 0 < theta) (hN : 0 < N) + (hY : 0 ≤ Y) (hq : 0 < q) (hV : 0 ≤ V) (reward : ℕ → ℝ) + (hlower : ∀ i : Fin N, + (39/100 : ℝ)*((intervalPrimes (left R theta N i) (step R theta N) 1 0).card : ℝ)* + (Y/(left R theta N i*q))*V ≤ + ∑ p ∈ intervalPrimes (left R theta N i) (step R theta N) 1 0,reward p) : + (39/100 : ℝ)*V*(∑ p ∈ intervalPrimes R (theta*R) 1 0,Y/((p : ℝ)*q)) ≤ + ∑ p ∈ intervalPrimes R (theta*R) 1 0,reward p := by + rw [← primeBin_eq_intervalPrimes hR ht] + apply aggregate_reference_lower hR ht hN hY hq hV reward + intro i + simpa only [subbin_eq_intervalPrimes hR ht hN] using hlower i + +end ErdosStoppedSubbinAggregation + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SubbinScaleInheritance.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SubbinScaleInheritance.lean new file mode 100644 index 0000000000000000000000000000000000000000..8afbb991e4a1b444d7334957b7e8a3ba2d269e5e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SubbinScaleInheritance.lean @@ -0,0 +1,45 @@ +import OAI.NumberTheory.Jacobsthal.Primes.CanonicalTagPrimePartition + +namespace OAI + +namespace Erdos970 + + +namespace ErdosStoppedSubbinAggregation +open ErdosTagSubbins ErdosInversePrimeBin + +theorem subbin_scale_inheritance {R theta w Cs xi lowerBound : ℝ} + (hw : 1 < w) (hCs : 0 ≤ Cs) (hR : 0 < R) + (hxi : 0 < xi) (htxi : xi/4 ≤ theta) (ht1 : theta ≤ 1) + (hLower : lowerBound ≤ R) (i : Fin (count w Cs)) : + 0 < left R theta (count w Cs) i ∧ 0 < step R theta (count w Cs) ∧ + lowerBound ≤ left R theta (count w Cs) i ∧ + left R theta (count w Cs) i ≤ (1+theta)*R ∧ + xi/(16*w^(2*Cs+10)) ≤ step R theta (count w Cs)/left R theta (count w Cs) i ∧ + step R theta (count w Cs)/left R theta (count w Cs) i ≤ w^(-(2*Cs+10)) ∧ + left R theta (count w Cs) i + step R theta (count w Cs) ≤ (1+theta)*R := by + have ht : 0 < theta := (div_pos hxi (by norm_num)).trans_le htxi + have hN : 0 < count w Cs := (count_bounds hw hCs).1 + refine ⟨left_pos hR ht hN,step_pos hR ht hN, + hLower.trans (left_lower (step_pos hR ht hN).le), + (left_lt_right hR ht hN).le.trans (right_upper hR ht i.isLt), + width_lower hR hxi htxi ht1 hw hCs i.isLt,?_,?_⟩ + · simpa only [width,show -2*Cs-10=-(2*Cs+10) by ring] using + (width_upper (i:=i) hR ht ht1 hw hCs) + · rw [← right_eq_left_add] + exact right_upper hR ht i.isLt + +theorem subbin_inherits_band {R theta : ℝ} {N : ℕ} (hR : 0 < R) + (ht : 0 < theta) (hN : 0 < N) (band : ℝ → Prop) + (hband : ∀ x ∈ Set.Icc R ((1+theta)*R),band x) (i : Fin N) : + band (left R theta N i) := by + apply hband + exact ⟨left_lower (step_pos hR ht hN).le, + (left_lt_right hR ht hN).le.trans (right_upper hR ht i.isLt)⟩ + +end ErdosStoppedSubbinAggregation + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/SuccessfulRewardComparison.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SuccessfulRewardComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..1322629787e9f8a9daffbd773fbd874a12037001 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/SuccessfulRewardComparison.lean @@ -0,0 +1,97 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.PrimeExponentialTail + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SuccessfulRewardComparison + +open _root_.Set _root_.MeasureTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualFlagInvariant GridWeightComparison DerivativeWeights +open RegeneratingInverseBands InvariantInverseWeights ArrivalKernelGeometry + +theorem nearby_inverse_ratio : ∃ L : ℝ,0 < L ∧ ∀ S : ℝ,3 ≤ S → + ∀ i : Side,∀ a b h : ℝ,Valid i a → Valid i b → a ≤ S → b ≤ S → + |a-b| ≤ h → L*(1+S)^3*h ≤ 1 → weight i b/weight i a ≤ 3 := by + obtain ⟨L,hL,hlocal⟩ := weight_local_ratio + refine ⟨L,hL,?_⟩ + intro S hS i a b h ha hb haS hbS hab hsmall + by_cases hba : b ≤ a + · have hah : a ≤ b+h := by linarith [(abs_le.mp hab).2] + exact (hlocal S hS i b a h hb ha haS hba hah).trans + ((Real.exp_le_exp.mpr hsmall).trans Real.exp_one_lt_three.le) + · have hmono := TwoStepDensityBounds.weight_antitone ha hb (le_of_not_ge hba) + have hratio : weight i b/weight i a ≤ 1 := (div_le_one (weight_pos ha)).mpr hmono + linarith + +theorem reward_factor_comparison {c r q φ ψ : ℝ} (hc : 0 < c) (hr : 0 < r) (hq : 0 < q) + (hφ : 0 < φ) (hψ : 0 < ψ) (hrq : r ≤ 3*q) (hqr : q ≤ 3*r) (hw : ψ/φ ≤ 3) : + r^2*Real.exp (-c*r)/φ ≤ 27*(q^2*Real.exp (-(c/3)*q)/ψ) := by + have hsq : r^2 ≤ 9*q^2 := by nlinarith [mul_nonneg (sub_nonneg.mpr hrq) (show 0 ≤ 3*q+r by linarith)] + have he : Real.exp (-c*r) ≤ Real.exp (-(c/3)*q) := Real.exp_le_exp.mpr (by nlinarith) + have hInv : 1/φ ≤ 3/ψ := by + apply (div_le_div_iff₀ hφ hψ).mpr + have hh := (div_le_iff₀ hφ).mp hw + simpa only [one_mul] using hh + calc + _ = (r^2*Real.exp (-c*r))*(1/φ) := by ring + _ ≤ ((9*q^2)*Real.exp (-(c/3)*q))*(3/ψ) := + mul_le_mul (mul_le_mul hsq he (Real.exp_pos _).le (by positivity)) hInv + (one_div_pos.mpr hφ).le (by positivity) + _ = _ := by ring + +theorem stateWeight_eq (s : State) : stateWeight s = weight (stateSide s) (stateRatio s) := by + cases s <;> rfl + +theorem actual_good_tail_comparison : ∃ L : ℝ,0 < L ∧ + ∀ w ell S : ℝ,1 ≤ ell → 3 ≤ S → ∀ start : Node, + 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → + ∀ v mesh : ℝ,∀ n M : ℕ,4*(n:ℝ)*mesh ≤ 1 → L*(1+S)^3*mesh ≤ 1 → + ∀ h : History w ell S start,∀ z : CostState, + liveGood v mesh n h z → z ∈ arrivalSet v ell → ∀ c : ℝ,0 < c → + PrimeExponentialTail.tailReward c (3*((M:ℝ)+1)) (some h) ≤ + ENNReal.ofReal 27*WeightedGapTail.tailReward (c/3) v ell M z := by + obtain ⟨L,hL,hnear⟩ := nearby_inverse_ratio + refine ⟨L,hL,?_⟩ + intro w ell S hell hS start hr hs hsS v mesh n M hclock hsmall h z hgood harr c hc + have hrg : 0 < h.node.gap := terminal_gap_positive (by linarith) hr hs h.admissible + have hqg : 0 < gapValue v z := Real.exp_pos _ + have hv : Valid h.node.side h.node.ratio := terminal_valid hs h.admissible + have hnv : Valid h.node.side (stateRatio z.1) := by rw [hgood.2.1]; exact stateRatio_valid z.1 + have hsbound : h.node.ratio ≤ S := terminal_ratio_le hsS h.admissible + have hweight := hnear S hS h.node.side h.node.ratio (stateRatio z.1) mesh hv hnv hsbound hgood.1 hgood.2.2.1 hsmall + have hrel := NearbyParentGeometry.log_gap_relative hrg hqg (hgood.2.2.2.trans hclock) + have hrq : h.node.gap ≤ 3*gapValue v z := hrel.1.trans + (mul_le_mul_of_nonneg_right Real.exp_one_lt_three.le hqg.le) + have hqr : gapValue v z ≤ 3*h.node.gap := hrel.2.trans + (mul_le_mul_of_nonneg_right Real.exp_one_lt_three.le hrg.le) + have hφ := weight_pos hv + have hψ := weight_pos hnv + have hreward := reward_factor_comparison hc hrg hqg hφ hψ hrq hqr hweight + have hstate : weight h.node.side (stateRatio z.1) = stateWeight z.1 := by rw [hgood.2.1,stateWeight_eq] + rw [hstate] at hreward + by_cases hh : 3*((M:ℝ)+1) < h.node.gap + · have hlow : (M:ℝ)+1 ≤ gapValue v z := by linarith + have harrival : stateRatio z.1 < gapValue v z/ell := by + rw [arrivalSet_eq_cutoff v (by linarith : 0 < ell)] at harr + exact harr + rw [PrimeExponentialTail.tailReward,ite_eq_left hh,WeightedGapTail.tailReward, + indicator_of_mem (show z ∈ {z : CostState | (M:ℝ)+1 ≤ gapValue v z ∧ stateRatio z.1 < gapValue v z/ell} from ⟨hlow,harrival⟩)] + rw [← div_eq_mul_inv,← ENNReal.ofReal_div_of_pos (stateWeight_pos z.1), + ← ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 27)] + exact ENNReal.ofReal_le_ofReal hreward + · rw [PrimeExponentialTail.tailReward,ite_eq_right hh] + exact zero_le + +end NumberTheoryLean.SuccessfulRewardComparison + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoPowerDivisibility.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoPowerDivisibility.lean new file mode 100644 index 0000000000000000000000000000000000000000..5f86c6fa6075c1e46933747ffc8a033f7149e951 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoPowerDivisibility.lean @@ -0,0 +1,50 @@ +import OAI.NumberTheory.Jacobsthal.Primes.OddPrimeRoots + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman.PrimePower + +theorem two_pow_dvd_of_four_not_dvd (s : ℕ) (a b : ℤ) (ha : ¬4 ∣ a) + (hab : (2 : ℤ)^(s+1) ∣ a*b) : (2 : ℤ)^s ∣ b := by + have hp : Prime (2 : ℤ) := by norm_num + by_cases htwo : (2 : ℤ) ∣ a + · obtain ⟨c, rfl⟩ := htwo + have hc : ¬(2 : ℤ) ∣ c := by + rintro ⟨d, rfl⟩ + exact ha ⟨d, by ring⟩ + have hcan : (2 : ℤ)^s ∣ c*b := by + apply (mul_dvd_mul_iff_left (by norm_num : (2 : ℤ) ≠ 0)).mp + simpa only [pow_succ', mul_assoc] using hab + exact hp.pow_dvd_of_dvd_mul_left s hc hcan + · exact (pow_dvd_pow (2 : ℤ) (Nat.le_succ s)).trans + (hp.pow_dvd_of_dvd_mul_left (s+1) htwo hab) + +theorem two_power_square_congruence (s : ℕ) (x y : ℤ) (hy : ¬(2 : ℤ) ∣ y) + (hxy : (2 : ℤ)^(s+1) ∣ x^2-y^2) : + (2 : ℤ)^s ∣ x-y ∨ (2 : ℤ)^s ∣ x+y := by + have hproduct : (2 : ℤ)^(s+1) ∣ (x-y)*(x+y) := by + convert hxy using 1; ring + by_cases hm : (4 : ℤ) ∣ x-y + · have hp : ¬(4 : ℤ) ∣ x+y := by + intro hp + have h2y : (4 : ℤ) ∣ 2*y := by + have he : (x+y)-(x-y) = 2*y := by ring + simpa only [he] using dvd_sub hp hm + apply hy + apply (mul_dvd_mul_iff_left (by norm_num : (2 : ℤ) ≠ 0)).mp + exact h2y + exact Or.inl (two_pow_dvd_of_four_not_dvd s (x+y) (x-y) hp + (by simpa only [mul_comm] using hproduct)) + · exact Or.inr (two_pow_dvd_of_four_not_dvd s (x-y) (x+y) hm hproduct) + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdHazard.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdHazard.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e35282be3023a45f41d620279908e2c201794bd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdHazard.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Probability.TwoSidedThresholdKernel + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.TwoSidedThresholdHazard +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures TransitionKernels +open TwoSidedThresholdGeometry TwoSidedThresholdKernel CanonicalGapExposure RegeneratingInverseBands +attribute [local instance] Classical.propDecidable + +noncomputable def thickHazard (R d e : ℝ) : State → ℝ + | .inl _ => 0 + | .inr s => if 3 ≤ R then + (oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' thickStrip R (d/R+e))).toReal else 0 + +theorem thickHazard_exposure (s : State) {R d e : ℝ} + (hR : 0 < R) (hd : 0 ≤ d) (he : 0 ≤ e) : + thickHazard R d e s ≤ thickConstant*d*(if 3 ≤ R ∧ stateRatio s ≤ 6 then 1/R else 0)+thickConstant*e := by + have hC := thickConstant_pos + cases s with + | inl s => + change 0 ≤ _ + split_ifs <;> positivity + | inr s => + by_cases hR3 : 3 ≤ R + · by_cases hs : s.1 ≤ 6 + · simp only [thickHazard,ite_eq_left hR3] + split_ifs with hguard + · have hh := ENNReal.toReal_mono ENNReal.ofReal_ne_top + (oddToEven_thick_bound s hR3 (show 0 ≤ d/R+e by positivity)) + rw [ENNReal.toReal_ofReal (by positivity : 0 ≤ thickConstant*(d/R+e))] at hh + calc + _ ≤ thickConstant*(d/R+e) := hh + _ = _ := by ring + · exact (hguard ⟨hR3,hs⟩).elim + · rw [thickHazard,ite_eq_left hR3,oddToEven_thick_zero_high_parent s (lt_of_not_ge hs)] + simp only [ENNReal.toReal_zero,stateRatio,Sum.elim_inr,hs,and_false,ite_false,mul_zero,zero_add] + positivity + · rw [thickHazard,ite_eq_right hR3] + simp only [hR3,false_and,ite_false,mul_zero,zero_add] + positivity + +theorem canonical_total_thick_hazard (v : ℝ) {d e : ℝ} (hd : 0 ≤ d) (he : 0 ≤ e) + (s : State) (N : ℕ) : + ∀ᵐ h ∂finitePathMeasure s N, + (∑ j : Fin (N+1),thickHazard (gapValue v (coordinate N h j)) d e (coordinate N h j).1) ≤ + thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*e) := by + filter_upwards [canonical_exposure_bound v (by norm_num : (0:ℝ)<3) (by norm_num : (0:ℝ)≤6) s N] with h hh + have hsum : (∑ j : Fin (N+1),thickHazard (gapValue v (coordinate N h j)) d e (coordinate N h j).1) ≤ + thickConstant*d*pathExposure v 3 6 N h+((N:ℝ)+1)*(thickConstant*e) := by + calc + _ ≤ ∑ j : Fin (N+1),(thickConstant*d*(if 3 ≤ gapValue v (coordinate N h j) ∧ + stateRatio (coordinate N h j).1 ≤ 6 then 1/gapValue v (coordinate N h j) else 0)+thickConstant*e) := by + apply Finset.sum_le_sum + intro j _ + exact thickHazard_exposure _ (Real.exp_pos _) hd he + _ = _ := by rw [Finset.sum_add_distrib,← Finset.mul_sum]; simp [pathExposure,Nat.cast_add,Nat.cast_one] + have hm := mul_le_mul_of_nonneg_left hh (mul_nonneg thickConstant_pos.le hd) + calc + _ ≤ thickConstant*d*((6+2)/3)+((N:ℝ)+1)*(thickConstant*e) := by linarith + _ = _ := by ring +end NumberTheoryLean.TwoSidedThresholdHazard + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdOccurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdOccurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a5ef2c7ff5f7d498a18d54b7ac044873ad4e101 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdOccurrence.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.Jacobsthal.Paths.TwoSidedThresholdArrival + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.TwoSidedThresholdOccurrence +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures FiniteHistoryTransport FiniteHistoryOccurrence +open ArrivalKernelGeometry RegeneratingInverseBands CanonicalGapExposure +open TwoSidedThresholdArrival TwoSidedThresholdHazard TwoSidedThresholdKernel + +noncomputable def thickOccurrence (v d e : ℝ) (N : ℕ) : Set (Hist CostState N) := + arrivalOccurrence (thickArrival v d e) N + +theorem thickOccurrence_measurable (v d e : ℝ) (N : ℕ) : MeasurableSet (thickOccurrence v d e N) := + arrivalOccurrence_measurable (thickArrival_measurable v d e) N + +theorem canonical_thick_occurrence_bound (v : ℝ) {d e : ℝ} (hd : 0 ≤ d) (he : 0 ≤ e) + (s : State) (N : ℕ) : + (finitePathMeasure s N).real (thickOccurrence v d e N) ≤ + thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*e) := by + let E := thickArrival v d e + have hE : MeasurableSet E := thickArrival_measurable v d e + have hu := occurrence_le_integrated_hazards costKernel hE N (fun _ => (s,0)) + change (finitePathMeasure s N).real (thickOccurrence v d e N) ≤ + ∫ h,∑ j : Fin N,(costKernel (coordinate N h j.castSucc) E).toReal ∂finitePathMeasure s N at hu + have hi : Integrable (fun h => ∑ j : Fin N,(costKernel (coordinate N h j.castSucc) E).toReal) + (finitePathMeasure s N) := by + apply integrable_finsetSum + intro j _ + exact probability_integrable costKernel hE N (fun _ => (s,0)) j.castSucc + have hb : ∀ᵐ h ∂finitePathMeasure s N, + (∑ j : Fin N,(costKernel (coordinate N h j.castSucc) E).toReal) ≤ + thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*e) := by + filter_upwards [canonical_total_thick_hazard v hd he s N] with h hh + rw [Fin.sum_univ_castSucc] at hh + have hn : 0 ≤ thickHazard (gapValue v (coordinate N h (Fin.last N))) d e (coordinate N h (Fin.last N)).1 := by + rw [thickHazard_eq_actual] + exact ENNReal.toReal_nonneg + have hsum : (∑ j : Fin N,(costKernel (coordinate N h j.castSucc) E).toReal)= + ∑ j : Fin N,thickHazard (gapValue v (coordinate N h j.castSucc)) d e (coordinate N h j.castSucc).1 := by + apply Finset.sum_congr rfl + intro j _ + exact (thickHazard_eq_actual v d e _).symm + rw [hsum] + linarith + have hh := integral_mono_ae hi (integrable_const (thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*e))) hb + have hconst : (∫ _h : Hist CostState N,thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*e) ∂finitePathMeasure s N)= + thickConstant*((8/3:ℝ)*d+((N:ℝ)+1)*e) := by simp + rw [hconst] at hh + exact hu.trans hh +end NumberTheoryLean.TwoSidedThresholdOccurrence + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdStability.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..2332320141dc73d7594fc097db757b794a4e2a95 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/TwoSidedThresholdStability.lean @@ -0,0 +1,108 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CrossingBandGeometry +import OAI.NumberTheory.Jacobsthal.Partitions.TwoSidedThresholdGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.TwoSidedThresholdStability +open FinitePathGeometry NearbyParentGeometry TwoSidedThresholdGeometry ErdosEvenThreshold + +theorem reciprocal_lipschitz_one {x y : ℝ} (hx : 1 ≤ x) (hy : 1 ≤ y) : + |1/x-1/y| ≤ |x-y| := by + have hx0 : 0 < x := by linarith + have hy0 : 0 < y := by linarith + have he : 1/x-1/y=(y-x)/(x*y) := by field_simp + rw [he,abs_div,abs_of_pos (mul_pos hx0 hy0),abs_sub_comm y x] + apply div_le_self (abs_nonneg _) + nlinarith [mul_nonneg (sub_nonneg.mpr hx) (sub_nonneg.mpr hy)] + +theorem reciprocal_log_gap_error {R Q D : ℝ} (hR : 3 ≤ R) (hQ : 3 ≤ Q) + (hlog : |Real.log R-Real.log Q| ≤ D) : |1/R-1/Q| ≤ Real.exp D-1 := by + have hR0 : 0 < R := by linarith + have hQ0 : 0 < Q := by linarith + have hD : 0 ≤ D := (abs_nonneg _).trans hlog + have hc : 1 ≤ Real.exp D := Real.one_le_exp_iff.mpr hD + have hrel := log_gap_relative hR0 hQ0 hlog + have hxy : 1/R ≤ Real.exp D*(1/Q) := by + rw [mul_one_div] + apply (div_le_div_iff₀ hR0 hQ0).mpr + simpa only [one_mul] using hrel.2 + have hyx : 1/Q ≤ Real.exp D*(1/R) := by + rw [mul_one_div] + apply (div_le_div_iff₀ hQ0 hR0).mpr + simpa only [one_mul] using hrel.1 + have hh := clipped_relative_stability (A := 1/3) (by norm_num) hc hxy hyx + have hRi : 1/R ≤ (1/3:ℝ) := one_div_le_one_div_of_le (by norm_num) hR + have hQi : 1/Q ≤ (1/3:ℝ) := one_div_le_one_div_of_le (by norm_num) hQ + rw [min_eq_right hRi,min_eq_right hQi] at hh + linarith + +theorem normalizedSlack_stability {R Q t u h G : ℝ} + (hR : 0 < R) (hQ : 0 < Q) (ht : 2 ≤ t) (hu : 2 ≤ u) + (hclose : |t-u| ≤ h) (hgap : |1/R-1/Q| ≤ G) : + |normalizedSlack R t-normalizedSlack Q u| ≤ 3*h+2*G := by + have ht0 : 0 < t+1 := by linarith + have hu0 : 0 < u+1 := by linarith + have hh0 : 0 ≤ h := (abs_nonneg _).trans hclose + have hG0 : 0 ≤ G := (abs_nonneg _).trans hgap + have hi : |1/(t+1)-1/(u+1)| ≤ h := by + have hh := reciprocal_lipschitz_one (x := t+1) (y := u+1) (by linarith) (by linarith) + have hh' : |1/(t+1)-1/(u+1)| ≤ |t-u| := by simpa only [add_sub_add_right_eq_sub] using hh + exact hh'.trans hclose + have hA : |(t-2)/(t+1)-(u-2)/(u+1)| ≤ 3*h := by + have he : (t-2)/(t+1)-(u-2)/(u+1)= -3*(1/(t+1)-1/(u+1)) := by + field_simp [ht0.ne',hu0.ne'] + ring + rw [he,abs_mul] + norm_num + simpa only [one_div] using hi + have hB : |((t-1)/(t+1)-2/R)-((u-1)/(u+1)-2/Q)| ≤ 2*h+2*G := by + have he : ((t-1)/(t+1)-2/R)-((u-1)/(u+1)-2/Q)= + -2*(1/(t+1)-1/(u+1))-2*(1/R-1/Q) := by + field_simp [ht0.ne',hu0.ne',hR.ne',hQ.ne'] + ring + rw [he] + calc + _ ≤ |-2*(1/(t+1)-1/(u+1))|+|2*(1/R-1/Q)| := abs_sub _ _ + _ = 2*|1/(t+1)-1/(u+1)|+2*|1/R-1/Q| := by rw [abs_mul,abs_mul]; norm_num + _ ≤ _ := by linarith + rw [normalizedSlack_eq_min hR ht0,normalizedSlack_eq_min hQ hu0] + exact (abs_min_sub_min_le_max _ _ _ _).trans (max_le (by linarith) (by linarith)) + +theorem coupled_near_to_thick {R Q t u d h D : ℝ} + (hQ : 0 < Q) (hu : 2 ≤ u) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) + (hnear : t ∈ nearThreshold R d) (hclose : |t-u| ≤ h) (hsmall : h ≤ 1) + (hlog : |Real.log R-Real.log Q| ≤ D) (hexp : Real.exp D ≤ 4/3) : + 3 ≤ Q ∧ u ∈ thickStrip Q (d/Q+3*h+3*(Real.exp D-1)) := by + have hs : t ∈ thresholdStrip R d := (thresholdStrip_eq_near R d).symm ▸ hnear + have hpar := strip_parameters hd1 hs + have hR0 : 0 < R := by linarith [hpar.1] + have hrel := log_gap_relative hR0 hQ hlog + have hQ3 : 3 ≤ Q := by nlinarith [hrel.1,mul_le_mul_of_nonneg_right hexp hQ.le] + have hR3 : 3 ≤ R := by linarith [hpar.1] + have hG := reciprocal_log_gap_error hR3 hQ3 hlog + have hG0 : 0 ≤ Real.exp D-1 := (abs_nonneg _).trans hG + have hstab := normalizedSlack_stability hR0 hQ hs.1 hu hclose hG + have hnorm : |normalizedSlack R t| ≤ d/R := by + rw [normalizedSlack,abs_div,abs_of_pos hR0,abs_of_nonneg hnear.2.1] + exact div_le_div_of_nonneg_right hnear.2.2 hR0.le + have hdR : d/R ≤ d/Q+(Real.exp D-1) := by + have hh := mul_le_mul_of_nonneg_left ((le_abs_self (1/R-1/Q)).trans hG) hd0 + have hc := mul_le_mul_of_nonneg_right hd1 hG0 + rw [mul_sub,mul_one_div,mul_one_div] at hh + linarith + refine ⟨hQ3,hu,by linarith [(abs_le.mp hclose).1,hpar.2],?_⟩ + have hh := abs_add_le (normalizedSlack Q u-normalizedSlack R t) (normalizedSlack R t) + rw [sub_add_cancel,abs_sub_comm (normalizedSlack Q u)] at hh + linarith +end NumberTheoryLean.TwoSidedThresholdStability + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UncappedHighRemoval.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UncappedHighRemoval.lean new file mode 100644 index 0000000000000000000000000000000000000000..92bdc96cd8cff7bd4dd3dd29574fc3ce400fb5b8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UncappedHighRemoval.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeCompactWeights + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ActualPrimeHigh +open _root_.Filter +open scoped Topology +open FinitePathGeometry PrimeHistories PrimeBinMembership + +theorem uncapped_low_gap_high_removal : ∃ w₀ : ℝ, 1 < w₀ ∧ + ∀ K : ℝ, 0 < K → ∀ A : ℝ, ∀ᶠ B : ℝ in atTop, + ∀ w : ℝ, w₀ ≤ w → ∀ ell : ℝ, 1 ≤ ell → ell ≤ B → ∀ z : Node, + z.cutoff = B → 0 < z.gap → Valid z.side z.ratio → Consistent z → + uncappedLowGapHighMass w ell z ((Real.log B)^2) K ≤ B^(-A) := by + obtain ⟨w₀,hw₀,hbound⟩ := ErdosPrimeInputs.HighPrimeRemoval.low_gap_high_removal + refine ⟨w₀,hw₀,?_⟩ + intro K hK A + filter_upwards [hbound K hK A] with B hB + intro w hw ell hell hellB z hcut hr hs hz + have h := uncapped_low_mass_le (hw₀.trans_le hw) (by linarith : 0 ≤ ell) hr hs hz + ((Real.log B)^2) K + rw [hcut] at h + exact h.trans (hB w hw ell hell hellB z.gap) + +theorem uncapped_rewarded_high_removal : ∃ M w₀ : ℝ, 0 < M ∧ 1 < w₀ ∧ + ∀ c : ℝ, 0 < c → ∀ A : ℝ, ∀ᶠ B : ℝ in atTop, + ∀ w : ℝ, w₀ ≤ w → ∀ ell : ℝ, 1 ≤ ell → ell ≤ B → ∀ z : Node, + z.cutoff = B → 0 < z.gap → Valid z.side z.ratio → Consistent z → + uncappedRewardedHighMass w ell z ((Real.log B)^2) c ≤ M*B^(-A) := by + obtain ⟨M,w₀,hM,hw₀,hbound⟩ := ErdosPrimeInputs.HighPrimeRemoval.rewarded_high_removal + refine ⟨M,w₀,hM,hw₀,?_⟩ + intro c hc A + filter_upwards [hbound c hc A] with B hB + intro w hw ell hell hellB z hcut hr hs hz + have h := uncapped_rewarded_mass_le (hw₀.trans_le hw) (by linarith : 0 ≤ ell) hr hs hz + ((Real.log B)^2) c + rw [hcut] at h + exact h.trans (hB w hw ell hell hellB z.gap) + +end NumberTheoryLean.ActualPrimeHigh + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformCollisionError.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformCollisionError.lean new file mode 100644 index 0000000000000000000000000000000000000000..918cc841beeada6536c1eb7b7ceb8146431940bb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformCollisionError.lean @@ -0,0 +1,99 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosSourceCollision + +theorem collision_error_bound (z R N n eta C : ℝ) (hz : 1 < z) (hR : 1 < R) + (hRz : R ≤ z^((1 : ℝ)/100)) (hN : z^((93 : ℝ)/100) ≤ N) + (heta : 0 < eta) (hC : 0 ≤ C) (hL : 1 ≤ Real.log z) + (hcount : eta*R/(4*Real.log R) ≤ n) : + C*R/(n*(Real.log z)^6)+R/(N*(Real.log z)^6) ≤ + 4*C/(eta*(Real.log z)^5)+1/z^((92 : ℝ)/100) := by + have hz0 : 0 < z := by linarith + have hR0 : 0 < R := by linarith + have hlogR : 0 < Real.log R := Real.log_pos hR + have hn : 0 < n := (div_pos (mul_pos heta hR0) (mul_pos (by norm_num) hlogR)).trans_le hcount + have hNp : 0 < N := (Real.rpow_pos_of_pos hz0 _).trans_le hN + have hLp : 0 < Real.log z := by linarith + have hRle : R ≤ z := by + apply hRz.trans + have hh := Real.rpow_le_rpow_of_exponent_le hz.le (by norm_num : (1 : ℝ)/100 ≤ 1) + simpa only [Real.rpow_one] using hh + have hlogs : Real.log R ≤ Real.log z := Real.log_le_log hR0 hRle + have hprim := (div_le_iff₀ (mul_pos (by norm_num : (0 : ℝ) < 4) hlogR)).mp hcount + have hratio : R/n ≤ 4*Real.log z/eta := by + apply (div_le_div_iff₀ hn heta).mpr + nlinarith [mul_le_mul_of_nonneg_right hlogs hn.le] + have hfirst : C*R/(n*(Real.log z)^6) ≤ 4*C/(eta*(Real.log z)^5) := by + calc + _ = C*(R/n)/(Real.log z)^6 := by ring + _ ≤ C*(4*Real.log z/eta)/(Real.log z)^6 := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hratio hC) (by positivity) + _ = _ := by field_simp + have hpow : 0 < z^((92 : ℝ)/100) := Real.rpow_pos_of_pos hz0 _ + have hRN : R/N ≤ 1/z^((92 : ℝ)/100) := by + apply (div_le_div_iff₀ hNp hpow).mpr + calc + R*z^((92 : ℝ)/100) ≤ z^((1 : ℝ)/100)*z^((92 : ℝ)/100) := mul_le_mul_of_nonneg_right hRz hpow.le + _ = z^((93 : ℝ)/100) := by rw [← Real.rpow_add hz0];norm_num + _ ≤ 1*N := by simpa only [one_mul] using hN + have hden : N ≤ N*(Real.log z)^6 := by + have hh := mul_le_mul_of_nonneg_left (one_le_pow₀ hL : 1 ≤ (Real.log z)^6) hNp.le + simpa only [mul_one] using hh + have hsecond : R/(N*(Real.log z)^6) ≤ 1/z^((92 : ℝ)/100) := + (div_le_div_of_nonneg_left hR0.le hNp hden).trans hRN + exact add_le_add hfirst hsecond + +end ErdosSourceCollision + +end + +section + +open Filter +open scoped Topology +namespace ErdosSourceCollision + +theorem uniform_collision_error (C eta eps : ℝ) (hC : 0 ≤ C) (heta : 0 < eta) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ 1 ≤ Real.log z ∧ ∀ R N n : ℝ, + 1 < R → R ≤ z^((1 : ℝ)/100) → z^((93 : ℝ)/100) ≤ N → + eta*R/(4*Real.log R) ≤ n → + C*R/(n*(Real.log z)^6)+R/(N*(Real.log z)^6) ≤ eps^2 := by + have hlog := Real.tendsto_log_atTop.eventually_ge_atTop (max 1 (8*C/(eta*eps^2))) + have hpow := (tendsto_rpow_atTop (by norm_num : (0 : ℝ) < 92/100)).eventually_ge_atTop (2/eps^2) + filter_upwards [hlog,hpow,eventually_gt_atTop (1 : ℝ)] with z hzL hzpow hz + have hL : 1 ≤ Real.log z := (le_max_left _ _).trans hzL + have hL0 : 0 < Real.log z := by linarith + have hz0 : 0 < z := by linarith + have he2 : 0 < eps^2 := sq_pos_of_pos heps + have hL5 : Real.log z ≤ (Real.log z)^5 := by + have hh := mul_le_mul_of_nonneg_left (one_le_pow₀ hL : 1 ≤ (Real.log z)^4) hL0.le + nlinarith + have hpay : 8*C ≤ (Real.log z)^5*(eta*eps^2) := by + have hh := (div_le_iff₀ (mul_pos heta he2)).mp ((le_max_right _ _).trans hzL) + exact hh.trans (mul_le_mul_of_nonneg_right hL5 (mul_pos heta he2).le) + have hfirst : 4*C/(eta*(Real.log z)^5) ≤ eps^2/2 := by + apply (div_le_iff₀ (by positivity : 0 < eta*(Real.log z)^5)).mpr + nlinarith + have hpower : 0 < z^((92 : ℝ)/100) := Real.rpow_pos_of_pos hz0 _ + have hsecond : 1/z^((92 : ℝ)/100) ≤ eps^2/2 := by + apply (div_le_iff₀ hpower).mpr + have hh := (div_le_iff₀ he2).mp hzpow + nlinarith + refine ⟨hz,hL,?_⟩ + intro R N n hR hRz hN hcount + apply (collision_error_bound z R N n eta C hz hR hRz hN heta hC hL hcount).trans + linarith + +end ErdosSourceCollision + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformFailureBudget.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformFailureBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..a22f6c96f9d4e0f23c14efd20f7f13ad61f459ca --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformFailureBudget.lean @@ -0,0 +1,111 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FlaggedSourceStart + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.UniformFailureBudget + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualFlagInvariant ActualCouplingUpdates ActualCouplingError +open NearbyParentGeometry ActualSupportIntervals PrimeBinMembership RegeneratingInverseBands + +noncomputable def upperDisplacement (S mesh : ℝ) (N : ℕ) : ℝ := + (S+1)*(Real.exp (4*(N:ℝ)*mesh)-1) + +noncomputable def stepBudget (c₁ c₂ C₁ C₂ C₃ D w S mesh : ℝ) (N : ℕ) : ℝ := + 2*((S/mesh+2)*(C₁*(1+S)^5*(mesh^2+Real.exp (-c₁*Real.sqrt ((1/2:ℝ)*Real.log w))))+ + epsilon w+(Real.exp (D*(1+S)^3*mesh)-1)+ + C₂*(1+S)^2*(upperDisplacement S mesh N+3*mesh+2*Real.exp (-c₂*Real.sqrt ((1/2:ℝ)*Real.log w)))+ + C₃*(1+S)^2*(upperDisplacement S mesh N+3*mesh)) + +theorem upperDisplacement_nonneg {S mesh : ℝ} (hS : 0 ≤ S+1) (hm : 0 ≤ mesh) (N : ℕ) : + 0 ≤ upperDisplacement S mesh N := by + apply mul_nonneg hS + apply sub_nonneg.mpr + apply Real.one_le_exp_iff.mpr + positivity + +theorem stepBudget_nonneg {c₁ c₂ C₁ C₂ C₃ D w S mesh : ℝ} (hC₁ : 0 ≤ C₁) (hC₂ : 0 ≤ C₂) + (hC₃ : 0 ≤ C₃) (hD : 0 ≤ D) (hS : 0 ≤ S) (hm : 0 ≤ mesh) (N : ℕ) : + 0 ≤ stepBudget c₁ c₂ C₁ C₂ C₃ D w S mesh N := by + have hS1 : 0 ≤ S+1 := by linarith + have hu := upperDisplacement_nonneg hS1 hm N + have he : 0 ≤ Real.exp (D*(1+S)^3*mesh)-1 := by + apply sub_nonneg.mpr + apply Real.one_le_exp_iff.mpr + positivity + have hEps := (epsilon_pos w).le + unfold stepBudget + positivity + +theorem uniform_actual_bad_row : ∃ c₁ c₂ C₁ C₂ C₃ D w₀ : ℝ, + 0 < c₁ ∧ 0 < c₂ ∧ 0 < C₁ ∧ 0 < C₂ ∧ 0 < C₃ ∧ 0 < D ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, ∀ v mesh : ℝ, ∀ N : ℕ, + ∀ (hnorm : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS3 : 3 ≤ S) (hS : S ≤ (Real.log w)^3) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S), + Consistent start → 0 < mesh → 2*mesh ≤ 1 → upperDisplacement S mesh N+mesh ≤ 1 → + ∀ n ≤ N, ∀ q : JointState w ell S start, GoodAt v mesh n q → + jointKernel hnorm hell (show 0 ≤ S from by linarith) hS hr hs hsS v mesh q {y | mismatch mesh y} ≤ + ENNReal.ofReal (stepBudget c₁ c₂ C₁ C₂ C₃ D w S mesh N) := by + obtain ⟨c₁,c₂,C₁,C₂,C₃,D,w₀,hc₁,hc₂,hC₁,hC₂,hC₃,hD,hw₀,hbound⟩ := actual_one_step_failure + refine ⟨c₁,c₂,C₁,C₂,C₃,D,w₀,hc₁,hc₂,hC₁,hC₂,hC₃,hD,hw₀,?_⟩ + intro w hw ell S start v mesh N hnorm hell hS3 hS hr hs hsS hcons hm hmesh hupper n hn q hq + have hS1 : 0 ≤ S+1 := by linarith + rcases q with ⟨p,z⟩ + cases p with + | none => + cases z with + | inl z => exact False.elim hq + | inr u => + cases u + have hnot : ∀ᵐ y ∂jointKernel hnorm hell (by linarith) hS hr hs hsS v mesh (none,CemeteryKernel.dead), + ¬mismatch mesh y := by + filter_upwards [joint_dead_ae hnorm hell (by linarith) hS hr hs hsS v mesh] with y hy + rw [hy] + change ¬(MeshRatioLabels.cemeteryLabel S mesh ≠ MeshRatioLabels.cemeteryLabel S mesh) + exact not_not.mpr rfl + have hzero : jointKernel hnorm hell (by linarith) hS hr hs hsS v mesh (none,CemeteryKernel.dead) + {y | mismatch mesh y} = 0 := by + simpa only [not_not] using ae_iff.mp hnot + exact hzero.le.trans zero_le + | some h => + cases z with + | inr u => exact False.elim hq + | inl z => + have hgap := terminal_gap_positive (show 0 ≤ ell by linarith) hr hs h.admissible + have hnR : (n:ℝ) ≤ (N:ℝ) := by exact_mod_cast hn + have hgapN : |Real.log h.node.gap-Real.log (gapValue v z)| ≤ 4*(N:ℝ)*mesh := + hq.2.2.2.trans (mul_le_mul_of_nonneg_right (by linarith) hm.le) + have hdl : |minRatio h.node.side h.node.ratio-minRatio (stateSide z.1) (stateRatio z.1)| ≤ mesh := by + rw [← hq.2.1] + exact (minRatio_stability _ _ _).trans hq.2.2.1 + have hdu : |upperSupport S ell h.node.gap-upperSupport S ell (gapValue v z)| ≤ upperDisplacement S mesh N := + arrival_endpoint_stability hgap (Real.exp_pos _) (by linarith) hS1 hgapN + have hp := hbound w hw ell S start h v z mesh hnorm hell hS3 hS hr hs hsS hcons hq.1 hq.2.1 hm + (by linarith) (by linarith) + refine hp.trans (ENNReal.ofReal_le_ofReal ?_) + have hD0 : 0 ≤ D*(1+S)^3 := by positivity + have hpar := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hq.2.2.1 hD0) + have hdelta : |minRatio h.node.side h.node.ratio-minRatio (stateSide z.1) (stateRatio z.1)|+ + |upperSupport S ell h.node.gap-upperSupport S ell (gapValue v z)|+2*mesh ≤ + upperDisplacement S mesh N+3*mesh := by linarith + have h2 := mul_le_mul_of_nonneg_left + (add_le_add_right hdelta (2*Real.exp (-c₂*Real.sqrt ((1/2:ℝ)*Real.log w)))) + (show 0 ≤ C₂*(1+S)^2 by positivity) + have h3 := mul_le_mul_of_nonneg_left hdelta (show 0 ≤ C₃*(1+S)^2 by positivity) + unfold stepBudget + linarith + +end NumberTheoryLean.UniformFailureBudget + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformJointModel.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformJointModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f1b71c4175826ccbb4bc7bfecdcf4f744f993de --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformJointModel.lean @@ -0,0 +1,191 @@ +import OAI.NumberTheory.Jacobsthal.Probability.MomentIndicators + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosUniformMobiusRemainder + +def cutoffExponent (M : ℝ) : ℝ := 2*M+12 + +theorem cutoffExponent_margin (M : ℝ) : 2*M+10 < cutoffExponent M := by + dsimp [cutoffExponent] + linarith + +theorem source_sqrt_lower (M xi W Y : ℝ) (hxi : 0 < xi) (hW : 0 < W) + (hY : xi*W^(cutoffExponent M) ≤ Y) : + xi^((1 : ℝ)/2)*W^(M+6) ≤ Y^((1 : ℝ)/2) := by + have hp := Real.rpow_le_rpow (show 0 ≤ xi*W^(cutoffExponent M) by positivity) hY + (by norm_num : (0 : ℝ) ≤ 1/2) + rw [Real.mul_rpow hxi.le (Real.rpow_nonneg hW.le _) ,← Real.rpow_mul hW.le] at hp + have he : cutoffExponent M*((1 : ℝ)/2)=M+6 := by dsimp [cutoffExponent];ring + rwa [he] at hp + +theorem remainder_scalar_bound (C A M xi W : ℝ) (H : ℕ) (Y : ℝ) + (hC : 0 ≤ C) (hA : 0 ≤ A) (hxi : 0 < xi) (hW : 0 < W) + (hH : 1 ≤ H) (hHY : (H : ℝ) ≤ Y) (hYscale : xi*W^(cutoffExponent M) ≤ Y) + (hdiv : (H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ)) ≤ C/Y^((1 : ℝ)/2)) : + A*(H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ))*W^M*(Real.log W)^2 ≤ + (A*C/xi^((1 : ℝ)/2))*((Real.log W)^2/W^(6 : ℝ)) := by + have hY : 0 < Y := (show (0 : ℝ) < H by exact_mod_cast hH).trans_le hHY + have hroot := source_sqrt_lower M xi W Y hxi hW hYscale + have hbase : A*(H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ)) ≤ + A*C/(xi^((1 : ℝ)/2)*W^(M+6)) := by + calc + _ = A*((H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ))) := by ring + _ ≤ A*(C/Y^((1 : ℝ)/2)) := mul_le_mul_of_nonneg_left hdiv hA + _ = A*C/Y^((1 : ℝ)/2) := by ring + _ ≤ _ := div_le_div_of_nonneg_left (mul_nonneg hA hC) (by positivity) hroot + have hf : W^(M+6)=W^M*W^(6 : ℝ) := by rw [Real.rpow_add hW] + have hmul := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right hbase (Real.rpow_nonneg hW.le M)) (sq_nonneg (Real.log W)) + have he : (A*C/(xi^((1 : ℝ)/2)*W^(M+6)))*W^M*(Real.log W)^2 = + (A*C/xi^((1 : ℝ)/2))*((Real.log W)^2/W^(6 : ℝ)) := by + rw [hf] + field_simp + exact hmul.trans_eq he + +theorem uniform_mobius_remainder (M : ℝ) (_hM : 0 ≤ M) : + ∃ Cs : ℝ,2*M+10 < Cs ∧ ∀ xi : ℝ,0 < xi → ∀ A : ℝ,0 ≤ A → + ∀ eps : ℝ,0 < eps → ∀ᶠ W : ℝ in atTop,1 < W ∧ + ∀ (H : ℕ) (Y : ℝ),1 ≤ H → (H : ℝ) ≤ Y → xi*W^Cs ≤ Y → + A*(H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ))*W^M*(Real.log W)^2 ≤ eps := by + obtain ⟨C,hC,hbound⟩ := divisor_totient_length_bound + refine ⟨cutoffExponent M,cutoffExponent_margin M,?_⟩ + intro xi hxi A hA eps heps + by_cases hA0 : A=0 + · filter_upwards [eventually_gt_atTop (1 : ℝ)] with W hW + refine ⟨hW,?_⟩ + intro H Y _ _ _ + simpa only [hA0,zero_mul,zero_div] using heps.le + have hAp : 0 < A := lt_of_le_of_ne hA (Ne.symm hA0) + let K := A*C/xi^((1 : ℝ)/2) + have hK : 0 < K := by dsimp [K]; positivity + have hlittle := (isLittleO_log_rpow_rpow_atTop (2 : ℝ) (by norm_num : (0 : ℝ) < 6)).bound (div_pos heps hK) + filter_upwards [hlittle,eventually_gt_atTop (1 : ℝ)] with W hlog hW + refine ⟨hW,?_⟩ + intro H Y hH hHY hYscale + have hW0 : 0 < W := by linarith + have hlog' : (Real.log W)^2 ≤ (eps/K)*W^(6 : ℝ) := by + simpa only [Real.rpow_two,Real.norm_eq_abs, + abs_of_nonneg (sq_nonneg (Real.log W)),abs_of_nonneg (Real.rpow_nonneg hW0.le (6 : ℝ))] using hlog + have hsmall : K*((Real.log W)^2/W^(6 : ℝ)) ≤ eps := by + have hh := (div_le_iff₀ (Real.rpow_pos_of_pos hW0 (6 : ℝ))).mpr hlog' + have hm := mul_le_mul_of_nonneg_left hh hK.le + have he : K*(eps/K)=eps := by field_simp + exact hm.trans_eq he + exact (remainder_scalar_bound C A M xi W H Y hC.le hA hxi hW0 hH hHY hYscale + (hbound H Y hH hHY)).trans hsmall + +end ErdosUniformMobiusRemainder + +end + + +namespace ErdosVarianceUniformMoments +open NumberTheoryLean ErdosVarianceMoments ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem zero_joint_model_mass (R xi w : ℝ) (H qA : ℕ) (C0 : ℤ) + (hC0 : Int.gcd C0 (H : ℤ) = 1) (beta delta : ∀ t : ℕ,ZMod t) + (hqA : ∀ t ∈ coprimePrimes w H,qA.Coprime t) (S : Finset ℕ) + (hz : jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S = 0) : + modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S) = 0 := by + have hmul : jointDensity (divisorPrimes w H) S*jointDensity (coprimePrimes w H) S = 0 := + (jointDensity_split w H S).trans hz + rw [joint_model_mass R xi w H qA C0 beta delta S hC0] + rcases mul_eq_zero.mp hmul with h0|h1 + · rw [h0,mul_zero,mul_zero,zero_mul] + · have hf (p : (ZMod (coprimeModulus w H))ˣ) : + coprimePositionSurvivors w H qA delta S p (modelLeft R xi (C0 : ℝ)) + (modelRight R xi (H : ℝ) (C0 : ℝ)) = ∅ := + zero_coprimePositionSurvivors w H qA delta S p hqA h1 _ _ + simp only [hf,Finset.card_empty,Nat.cast_zero,Finset.sum_const_zero,mul_zero] + +end ErdosVarianceUniformMoments + + + +open _root_.Filter +namespace ErdosVarianceUniformMoments +open NumberTheoryLean ErdosVarianceMoments ErdosVarianceSmallModel +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem uniform_joint_model_relative (zeta : ℝ) (hzeta : 0 < zeta) : + ∃ Cs : ℝ,0 < Cs ∧ ∀ xi : ℝ,0 < xi → ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ + ∀ (R : ℝ),0 < R → ∀ (H qA : ℕ),0 < H → ∀ (C0 : ℤ),Int.gcd C0 (H : ℤ) = 1 → + ∀ (beta delta : ∀ t : ℕ,ZMod t), + (∀ t ∈ coprimePrimes w H,qA.Coprime t) → + xi*w^Cs ≤ modelLength R xi (H : ℝ) (C0 : ℝ) → + ∀ S : Finset ℕ,S.card ≤ 2 → + |modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S)- + jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S| ≤ + zeta*jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S := by + let s := max 480024 (-96*Real.log (zeta/2)) + have hs : 480024 ≤ s := le_max_left _ _ + have hs0 : 0 ≤ s := by linarith + have hexp : Real.exp (-s/96) ≤ zeta/2 := by + have hsecond : -96*Real.log (zeta/2) ≤ s := le_max_right _ _ + calc + _ ≤ Real.exp (Real.log (zeta/2)) := Real.exp_le_exp.mpr (by linarith) + _ = _ := Real.exp_log (by positivity) + obtain ⟨Cs,hCs,hrem⟩ := ErdosUniformMobiusRemainder.uniform_mobius_remainder (2*s) (by positivity) + refine ⟨Cs,by linarith,?_⟩ + intro xi hxi + have hA : 0 ≤ 4*densityInverseConstant := mul_nonneg (by norm_num) densityInverseConstant_pos.le + filter_upwards [uniform_density_inverse,hrem xi hxi (4*densityInverseConstant) hA (zeta/2) (by positivity)] + with w hden hremw + refine ⟨hden.1,?_⟩ + intro R hR H qA hH C0 hC0 beta delta hqA hscale S hS + let K := jointDensity (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) S + change |modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S)-K| ≤ zeta*K + by_cases hzero : K = 0 + · have hm := zero_joint_model_mass R xi w H qA C0 hC0 beta delta hqA S hzero + simp only [hm,hzero,sub_zero,abs_zero,mul_zero,le_refl] + have hP (t : ℕ) (ht : t ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) : t.Prime := + (LargePrimeDeletion.mem_cutoffPrimes.mp ht).1 + have hK : 0 < K := lt_of_le_of_ne (jointDensity_nonneg _ S hP) (Ne.symm hzero) + let Y := modelLength R xi (H : ℝ) (C0 : ℝ) + let E := 4*(H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ))*(w^s)^2 + have hW : 0 < w := by linarith [hden.1] + have hYH : (H : ℝ) ≤ Y := by + dsimp [Y,modelLength,interceptScale] + exact le_add_of_nonneg_right (by positivity) + have hY : 0 < Y := (show (0 : ℝ) < H by exact_mod_cast hH).trans_le hYH + have hE : 0 ≤ E := by dsimp [E];positivity + have hbudget := hremw.2 H Y hH hYH hscale + have hp : (w^s)^2 = w^(2*s) := by + rw [← Real.rpow_two,← Real.rpow_mul hW.le] + congr 1 + ring + have hbudget' : E*(densityInverseConstant*(Real.log w)^2) ≤ zeta/2 := by + have he : E*(densityInverseConstant*(Real.log w)^2) = + (4*densityInverseConstant)*(H.divisors.card : ℝ)*(H : ℝ)/(Y*(H.totient : ℝ))* + w^(2*s)*(Real.log w)^2 := by dsimp [E];rw [hp];ring + exact he.trans_le hbudget + have hinv : E/K ≤ zeta/2 := by + calc + E/K = E*K⁻¹ := div_eq_mul_inv _ _ + _ ≤ E*(densityInverseConstant*(Real.log w)^2) := + mul_le_mul_of_nonneg_left (hden.2 S hS hzero) hE + _ ≤ _ := hbudget' + have hEbound : E ≤ (zeta/2)*K := (div_le_iff₀ hK).mp hinv + have hf := finite_joint_moment_estimate R xi w hR hxi.le hden.1 s hs H qA hH C0 hC0 beta delta hqA S hS + have heterm := mul_le_mul_of_nonneg_left hexp hK.le + change K*Real.exp (-s/96) ≤ K*(zeta/2) at heterm + change |modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S)-K| ≤ K*Real.exp (-s/96)+E at hf + change |modelMass R xi w H C0 (jointCondition w H C0 qA beta delta S)-K| ≤ zeta*K + linarith + +end ErdosVarianceUniformMoments + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc1298a36b4f380abe35758ea9849c15c046417d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UniformLower.lean @@ -0,0 +1,366 @@ +import Mathlib.NumberTheory.Harmonic.Bounds +import PrimeNumberTheoremAnd.Erdos970.MertensClassical +import OAI.NumberTheory.Jacobsthal.Probability.CouplingEvent +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentMarginals + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +noncomputable def paperWeight (E : Finset ℕ) (d : ℕ) : ℝ := + ∏ p ∈ E with ¬p ∣ d, (1 - 1 / ((p : ℝ) - 1)) +noncomputable def ordinaryProduct (E : Finset ℕ) : ℝ := + ∏ p ∈ E, (1 - 1 / (p : ℝ)) + +lemma eventMass_congr (E : Finset ℕ) {A B : Outcomes E → Prop} + (h : ∀ s, A s ↔ B s) : eventMass E A = eventMass E B := by + apply tsum_congr + intro s + simp only [h s] + +lemma eulerMass_as_weight {p : ℝ} (hp : 2 ≤ p) (j : ℕ) : + eulerMass p j = (if j = 0 then (1 - 1 / (p - 1)) else 1) / p ^ j := by + cases j with + | zero => + simp only [eulerMass, ite_true, pow_zero, div_one] + have hp1 : p - 1 ≠ 0 := by linarith + field_simp + ring + | succ j => simp [eulerMass] + +variable (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) +include hE + +theorem product_eq_iff_vector {d : ℕ} (hd : d ≠ 0) (hs : d.primeFactors ⊆ E) + (k : E → ℕ) : + integerProduct E k = d ↔ ∀ p, k p = d.factorization p := by + constructor + · intro hh p + rw [← hh, integerProduct_factorization E hE] + · intro hh + rw [show k = (fun p : E => d.factorization p) from funext hh] + exact integerProduct_factorization_reconstruct E hd hs + +theorem upper_integer_mass {d : ℕ} (hd : d ≠ 0) (hs : d.primeFactors ⊆ E) : + eventMass E (fun s => upperInteger E s = d) = paperWeight E d / (d : ℝ) := by + calc + _ = eventMass E (fun s => ∀ p, upperExponent (s p) = d.factorization p) := + eventMass_congr E (fun s => product_eq_iff_vector E hE hd hs (fun p => upperExponent (s p))) + _ = ∏ p : E, eulerMass (p : ℝ) (d.factorization p) := + upper_vector_marginal E (fun p hp => (hE p hp).two_le) _ + _ = (∏ p : E, if d.factorization p = 0 then (1-1/((p : ℝ)-1)) else 1) / + (∏ p : E, (p : ℝ) ^ d.factorization p) := by + rw [← Finset.prod_div_distrib] + apply Finset.prod_congr rfl + intro p _ + exact eulerMass_as_weight (by exact_mod_cast (hE p p.property).two_le) _ + _ = paperWeight E d / (d : ℝ) := by + congr 1 + · unfold paperWeight + rw [Finset.prod_filter] + have he : (∏ p : E, if d.factorization p = 0 then (1-1/((p : ℝ)-1)) else 1) = + ∏ p ∈ E, if d.factorization p = 0 then (1-1/((p : ℝ)-1)) else 1 := + Finset.prod_attach E (fun p : ℕ => if d.factorization p = 0 then (1-1/((p : ℝ)-1)) else 1) + rw [he] + apply Finset.prod_congr rfl + intro p hp + simp only [Nat.factorization_eq_zero_iff, hd, hE p hp, not_true_eq_false, + or_false, false_or] + · have hh := congrArg (fun n : ℕ => (n : ℝ)) (integerProduct_factorization_reconstruct E hd hs) + simpa only [integerProduct, Nat.cast_prod, Nat.cast_pow] using hh + +theorem lower_integer_mass {d : ℕ} (hd : d ≠ 0) (hs : d.primeFactors ⊆ E) : + eventMass E (fun s => lowerInteger E s = d) = ordinaryProduct E / (d : ℝ) := by + calc + _ = eventMass E (fun s => ∀ p, lowerExponent (s p) = d.factorization p) := + eventMass_congr E (fun s => product_eq_iff_vector E hE hd hs (fun p => lowerExponent (s p))) + _ = ∏ p : E, geometricMass (p : ℝ) (d.factorization p) := + lower_vector_marginal E (fun p hp => (hE p hp).two_le) _ + _ = (∏ p : E, (1 - 1 / (p : ℝ))) / (∏ p : E, (p : ℝ) ^ d.factorization p) := by + rw [← Finset.prod_div_distrib] + apply Finset.prod_congr rfl + intro p _ + simp [geometricMass, div_eq_mul_inv] + _ = ordinaryProduct E / (d : ℝ) := by + congr 1 + · exact Finset.prod_attach E (fun p : ℕ => 1 - 1 / (p : ℝ)) + · have hh := congrArg (fun n : ℕ => (n : ℝ)) (integerProduct_factorization_reconstruct E hd hs) + simpa only [integerProduct, Nat.cast_prod, Nat.cast_pow] using hh + +end EulerWeightedLower + + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +def supportedIntegers (E : Finset ℕ) (N : ℕ) : Finset ℕ := + (Finset.Icc 1 N).filter (fun d => d.primeFactors ⊆ E) +noncomputable def weightedSmallSum (E : Finset ℕ) (N : ℕ) : ℝ := + ∑ d ∈ supportedIntegers E N, paperWeight E d / (d : ℝ) +noncomputable def ordinarySmallSum (E : Finset ℕ) (N : ℕ) : ℝ := + ordinaryProduct E * ∑ d ∈ supportedIntegers E N, 1 / (d : ℝ) + +theorem eventMass_finite_values (E : Finset ℕ) (hE : ∀ p ∈ E, 2 ≤ p) + (f : Outcomes E → ℕ) (D : Finset ℕ) : + eventMass E (fun s => f s ∈ D) = ∑ d ∈ D, eventMass E (fun s => f s = d) := by + unfold eventMass + rw [← Summable.tsum_finsetSum (fun d _ => product_event_summable E hE (fun s => f s = d))] + apply tsum_congr + intro s + have he := Finset.sum_ite_eq D (f s) (fun _ : ℕ => productMass E s) + convert he.symm using 1 + all_goals first + | (apply Finset.sum_congr rfl; intro d _; split_ifs <;> rfl) + | (split_ifs <;> rfl) + +theorem product_mem_supported_iff (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) + (k : E → ℕ) (N : ℕ) : + integerProduct E k ∈ supportedIntegers E N ↔ integerProduct E k ≤ N := by + simp only [supportedIntegers, Finset.mem_filter, Finset.mem_Icc] + have hp := integerProduct_pos E hE k + have hs := integerProduct_support E hE k + exact ⟨fun h => h.1.2, fun h => ⟨⟨hp, h⟩, hs⟩⟩ + +theorem weightedSmallSum_eq_event (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) (N : ℕ) : + weightedSmallSum E N = eventMass E (fun s => upperInteger E s ≤ N) := by + unfold weightedSmallSum + simp only [upperInteger] + rw [← eventMass_congr E (fun s => product_mem_supported_iff E hE (fun p => upperExponent (s p)) N)] + rw [eventMass_finite_values E (fun p hp => (hE p hp).two_le)] + apply Finset.sum_congr rfl + intro d hd + obtain ⟨hI, hs⟩ := Finset.mem_filter.mp hd + exact (upper_integer_mass E hE (by have := (Finset.mem_Icc.mp hI).1; omega) hs).symm + +theorem ordinarySmallSum_eq_event (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) (N : ℕ) : + ordinarySmallSum E N = eventMass E (fun s => lowerInteger E s ≤ N) := by + simp only [lowerInteger] + rw [← eventMass_congr E (fun s => product_mem_supported_iff E hE (fun p => lowerExponent (s p)) N)] + rw [eventMass_finite_values E (fun p hp => (hE p hp).two_le)] + unfold ordinarySmallSum + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro d hd + obtain ⟨hI, hs⟩ := Finset.mem_filter.mp hd + have hm := lower_integer_mass E hE (d := d) (by have := (Finset.mem_Icc.mp hI).1; omega) hs + calc + _ = ordinaryProduct E / (d : ℝ) := by ring + _ = _ := hm.symm + +theorem weightedSmallSum_coupling_lower (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) + {P : ℝ} (hP : 1 < P) : + ordinarySmallSum E ⌊P ^ (94 / 100 : ℝ)⌋₊ - 100 * uniformMomentBound / Real.log P ≤ + weightedSmallSum E ⌊P ^ (95 / 100 : ℝ)⌋₊ := by + rw [ordinarySmallSum_eq_event E hE, weightedSmallSum_eq_event E hE] + have he (f : Outcomes E → ℕ) (a : ℝ) : + eventMass E (fun s => f s ≤ ⌊P ^ a⌋₊) = eventMass E (fun s => (f s : ℝ) ≤ P ^ a) := by + apply eventMass_congr E + intro s + exact Nat.le_floor_iff (Real.rpow_nonneg (by linarith) _) + rw [he, he] + exact small_product_coupling_lower E hE hP + +end EulerWeightedLower + + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw +attribute [local instance] Classical.propDecidable + +theorem finite_product_reindex {ι κ α : Type*} [Fintype ι] [Fintype κ] + (e : ι ≃ κ) (w : κ → α → ℝ) (A : (κ → α) → Prop) : + (∑' s : ι → α, if A ((Equiv.piCongrLeft (fun _ : κ => α) e) s) + then ∏ i, w (e i) (s i) else 0) = + ∑' s : κ → α, if A s then ∏ i, w i (s i) else 0 := by + rw [← (Equiv.piCongrLeft (fun _ : κ => α) e).tsum_eq] + apply tsum_congr + intro s + split_ifs + · rw [← e.prod_comp] + apply Finset.prod_congr rfl + intro i _ + simp [Equiv.piCongrLeft] + · rfl + +def restrictOutcomes {E F : Finset ℕ} (hEF : E ⊆ F) (s : Outcomes F) : Outcomes E := + fun p => s ⟨p, hEF p.property⟩ + +def retainedIndexEquiv {E F : Finset ℕ} (hEF : E ⊆ F) : + {p : F // (p : ℕ) ∈ E} ≃ E where + toFun p := ⟨p.val, p.property⟩ + invFun p := ⟨⟨p, hEF p.property⟩, p.property⟩ + left_inv _ := rfl + right_inv _ := rfl + +theorem eventMass_restrict {E F : Finset ℕ} (hEF : E ⊆ F) + (hF : ∀ p ∈ F, 2 ≤ p) (A : Outcomes E → Prop) : + eventMass F (fun s => A (restrictOutcomes hEF s)) = eventMass E A := by + let e := retainedIndexEquiv hEF + let ep := Equiv.piCongrLeft (fun _ : E => Sample) e + have h := finite_product_restrict (fun p : F => (p : ℕ) ∈ E) + (fun p : F => jointMass (p : ℝ)) + (fun p => jointMass_nonneg (by exact_mod_cast hF p p.property)) + (fun p => jointMass_hasSum (by exact_mod_cast hF p p.property)) + (fun s => A (ep s)) + have hr := finite_product_reindex e (fun p : E => jointMass (p : ℝ)) A + calc + _ = ∑' s : F → Sample, if A (ep (fun p => s p)) then ∏ p : F, jointMass (p : ℝ) (s p) else 0 := by + apply tsum_congr + intro s + have hh : ep (fun p => s p) = restrictOutcomes hEF s := by + funext p + rfl + simp only [hh, productMass] + _ = _ := h + _ = _ := by + convert hr using 1 + all_goals + apply tsum_congr + intro s + split_ifs + · apply Finset.prod_congr + · ext i; simp only [Finset.mem_univ] + · intro i _; rfl + · rfl + +theorem lowerInteger_restrict_le {E F : Finset ℕ} (hEF : E ⊆ F) + (hF : ∀ p ∈ F, Nat.Prime p) (s : Outcomes F) : + lowerInteger E (restrictOutcomes hEF s) ≤ lowerInteger F s := by + let f : ℕ → ℕ := fun p => if hp : p ∈ F then p ^ lowerExponent (s ⟨p, hp⟩) else 1 + have he : lowerInteger E (restrictOutcomes hEF s) = ∏ p ∈ E, f p := by + rw [lowerInteger, integerProduct, ← Finset.prod_attach E f] + apply Finset.prod_congr rfl + intro p _ + simp only [f, dite_eq_left (hEF p.property), restrictOutcomes] + have hf : lowerInteger F s = ∏ p ∈ F, f p := by + rw [lowerInteger, integerProduct, ← Finset.prod_attach F f] + apply Finset.prod_congr rfl + intro p _ + simp only [f, dite_eq_left p.property] + rw [he, hf] + apply Finset.prod_le_prod_of_subset_of_one_le₀ hEF + · intro p _; exact Nat.zero_le _ + · intro p hp _ + simp only [f, dite_eq_left hp] + exact one_le_pow₀ (hF p hp).pos + +theorem ordinarySmallSum_antitone {E F : Finset ℕ} (hEF : E ⊆ F) + (hF : ∀ p ∈ F, Nat.Prime p) (N : ℕ) : + ordinarySmallSum F N ≤ ordinarySmallSum E N := by + rw [ordinarySmallSum_eq_event F hF, + ordinarySmallSum_eq_event E (fun p hp => hF p (hEF hp))] + rw [← eventMass_restrict hEF (fun p hp => (hF p hp).two_le)] + apply Summable.tsum_le_tsum + · intro s + have hn := productMass_nonneg F (fun p hp => (hF p hp).two_le) s + by_cases h : lowerInteger F s ≤ N + · have hh := (lowerInteger_restrict_le hEF hF s).trans h + simp only [ite_eq_left h, ite_eq_left hh, le_refl] + · simp only [ite_eq_right h]; split_ifs <;> linarith + · exact product_event_summable F (fun p hp => (hF p hp).two_le) _ + · exact product_event_summable F (fun p hp => (hF p hp).two_le) _ + +end EulerWeightedLower + + + +namespace EulerWeightedLower +open Erdos970.EulerPrimeLaw _root_.Filter +open scoped Topology +attribute [local instance] Classical.propDecidable + +noncomputable def primesThrough (P : ℝ) : Finset ℕ := + (Finset.Ioc 0 ⌊P⌋₊).filter Nat.Prime + +lemma primesThrough_prime {P : ℝ} {p : ℕ} (hp : p ∈ primesThrough P) : Nat.Prime p := + (Finset.mem_filter.mp hp).2 + +lemma ordinaryProduct_nonneg (E : Finset ℕ) (hE : ∀ p ∈ E, Nat.Prime p) : + 0 ≤ ordinaryProduct E := by + apply Finset.prod_nonneg + intro p hp + exact sub_nonneg.mpr (reciprocal_lt_one (by exact_mod_cast (hE p hp).two_le)).le + +theorem supportedIntegers_primesThrough {P : ℝ} {N : ℕ} (hN : N ≤ ⌊P⌋₊) : + supportedIntegers (primesThrough P) N = Finset.Icc 1 N := by + apply Finset.filter_eq_self.mpr + intro d hd p hp + have hd0 : 0 < d := (Finset.mem_Icc.mp hd).1 + have hpd : p ≤ d := Nat.le_of_dvd hd0 (Nat.dvd_of_mem_primeFactors hp) + have hpr := Nat.prime_of_mem_primeFactors hp + exact Finset.mem_filter.mpr ⟨Finset.mem_Ioc.mpr ⟨hpr.pos, hpd.trans ((Finset.mem_Icc.mp hd).2.trans hN)⟩, hpr⟩ + +lemma harmonic_real_eq (N : ℕ) : + (harmonic N : ℝ) = ∑ d ∈ Finset.Icc 1 N, 1 / (d : ℝ) := by + simp only [harmonic_eq_sum_Icc, Rat.cast_sum, Rat.cast_inv, Rat.cast_natCast, one_div] + +theorem ordinarySmallSum_primesThrough {P : ℝ} {N : ℕ} (hN : N ≤ ⌊P⌋₊) : + ordinarySmallSum (primesThrough P) N = ordinaryProduct (primesThrough P) * (harmonic N : ℝ) := by + rw [ordinarySmallSum, supportedIntegers_primesThrough hN, harmonic_real_eq] + +noncomputable def uniformLowerEnvelope (P : ℝ) : ℝ := + (94 / 100 : ℝ) * Real.log P * ordinaryProduct (primesThrough P) - + 100 * uniformMomentBound / Real.log P + +theorem weightedSmallSum_uniform_lower {P : ℝ} (hP : 1 < P) + (E : Finset ℕ) (hE : E ⊆ primesThrough P) : + uniformLowerEnvelope P ≤ weightedSmallSum E ⌊P ^ (95 / 100 : ℝ)⌋₊ := by + have hpr : ∀ p ∈ primesThrough P, Nat.Prime p := fun p hp => primesThrough_prime hp + have hEs : ∀ p ∈ E, Nat.Prime p := fun p hp => hpr p (hE hp) + have hpow : P ^ (94 / 100 : ℝ) ≤ P := Real.rpow_le_self_of_one_le hP.le (by norm_num) + have hfloor := Nat.floor_mono hpow + have hm := ordinarySmallSum_antitone hE hpr ⌊P ^ (94 / 100 : ℝ)⌋₊ + rw [ordinarySmallSum_primesThrough hfloor] at hm + have hh := log_le_harmonic_floor (P ^ (94 / 100 : ℝ)) (Real.rpow_nonneg (by linarith) _) + rw [Real.log_rpow (by linarith : 0 < P)] at hh + have hl := mul_le_mul_of_nonneg_left hh (ordinaryProduct_nonneg _ hpr) + have hc := weightedSmallSum_coupling_lower E hEs hP + unfold uniformLowerEnvelope + nlinarith + +theorem uniformLowerEnvelope_limit : + Tendsto uniformLowerEnvelope atTop + (𝓝 (Real.exp (-Real.eulerMascheroniConstant) * (94 / 100 : ℝ))) := by + have he3 : Tendsto _root_.Erdos970.Mertens.E₃ atTop (𝓝 (0 : ℝ)) := + (Asymptotics.isLittleO_one_iff ℝ).mp _root_.Erdos970.Mertens.E₃.bound' + have hm : Tendsto (fun P : ℝ => Real.log P * ordinaryProduct (primesThrough P)) + atTop (𝓝 (Real.exp (-Real.eulerMascheroniConstant))) := by + have h := he3.rexp.const_mul (Real.exp (-Real.eulerMascheroniConstant)) + simp only [Real.exp_zero, mul_one] at h + apply h.congr' + filter_upwards [eventually_gt_atTop (1 : ℝ)] with P hP + rw [ordinaryProduct, primesThrough, _root_.Erdos970.Mertens.prod_one_minus_div_prime_eq hP] + field_simp [ne_of_gt (Real.log_pos hP)] + have hz : Tendsto (fun P : ℝ => 100 * uniformMomentBound / Real.log P) atTop (𝓝 0) := + Real.tendsto_log_atTop.const_div_atTop _ + convert (hm.const_mul (94 / 100 : ℝ)).sub hz using 1 + · funext P; unfold uniformLowerEnvelope; ring + · congr 1; ring + +theorem weightedSmallSum_eventually_uniform {ε : ℝ} (hε : 0 < ε) : + ∀ᶠ P : ℝ in atTop, ∀ E : Finset ℕ, E ⊆ primesThrough P → + Real.exp (-Real.eulerMascheroniConstant) * ((94 / 100 : ℝ) - ε) ≤ + weightedSmallSum E ⌊P ^ (95 / 100 : ℝ)⌋₊ := by + have hgap : Real.exp (-Real.eulerMascheroniConstant) * ((94 / 100 : ℝ) - ε) < + Real.exp (-Real.eulerMascheroniConstant) * (94 / 100 : ℝ) := by + nlinarith [Real.exp_pos (-Real.eulerMascheroniConstant)] + filter_upwards [eventually_gt_atTop (1 : ℝ), + uniformLowerEnvelope_limit.eventually (lt_mem_nhds hgap)] with P hP hbound + intro E hE + exact hbound.le.trans (weightedSmallSum_uniform_lower hP E hE) + +end EulerWeightedLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnitCyclicBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnitCyclicBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..4e0d3452883585c4eabf9785933ca33787f5e8e5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnitCyclicBounds.lean @@ -0,0 +1,237 @@ +import OAI.NumberTheory.Jacobsthal.Harmonic.CharacterChord +import OAI.NumberTheory.Jacobsthal.Sieve.DivisorHarmonic + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHyperbola + +theorem harmonicWeight_eq (N : ℕ) : harmonicWeight N = (harmonic N : ℝ) := by + simp only [harmonicWeight,harmonic_eq_sum_Icc,Rat.cast_sum,Rat.cast_inv, + Rat.cast_natCast,one_div] + +noncomputable def harmonicConstant : ℝ := 1 + 1/Real.log 2 + +theorem harmonicConstant_pos : 0 < harmonicConstant := by + have h : 0 < Real.log 2 := Real.log_pos (by norm_num) + unfold harmonicConstant + positivity + +theorem harmonicWeight_log_le (N : ℕ) (hN : 0 < N) : + harmonicWeight N ≤ harmonicConstant * Real.log (2*(N : ℝ)) := by + have hp : (0 : ℝ) < N := by exact_mod_cast hN + have hn1 : (1 : ℝ) ≤ N := by exact_mod_cast hN + have htwo : 0 < Real.log 2 := Real.log_pos (by norm_num) + have h2 : Real.log 2 ≤ Real.log (2*(N : ℝ)) := + Real.log_le_log (by norm_num) (by nlinarith) + have h1 : (1 : ℝ) ≤ Real.log (2*(N : ℝ))/Real.log 2 := + (le_div_iff₀ htwo).mpr (by simpa using h2) + have hlog : Real.log (N : ℝ) ≤ Real.log (2*(N : ℝ)) := + Real.log_le_log hp (by linarith) + calc + _ ≤ 1+Real.log (N : ℝ) := by rw [harmonicWeight_eq]; exact harmonic_le_one_add_log N + _ ≤ Real.log (2*(N : ℝ))/Real.log 2+Real.log (2*(N : ℝ)) := + add_le_add h1 hlog + _ = _ := by unfold harmonicConstant; ring + +theorem gcd_harmonic_log_le (N : ℕ) (hN : 0 < N) : + (∑ n ∈ Finset.Icc 1 N, Real.sqrt (Nat.gcd n N)/(n : ℝ)) ≤ + (N.divisors.card : ℝ)*harmonicConstant*Real.log (2*(N : ℝ)) := by + calc + _ ≤ (N.divisors.card : ℝ)*harmonicWeight N := gcd_harmonic_sum_le N hN + _ ≤ (N.divisors.card : ℝ)*(harmonicConstant*Real.log (2*(N : ℝ))) := + mul_le_mul_of_nonneg_left (harmonicWeight_log_le N hN) (Nat.cast_nonneg _) + _ = _ := by ring + +end ErdosHyperbola + +end + +section + +open scoped BigOperators + +namespace ErdosHyperbola + +open ErdosHyperbolaFourier + +attribute [local instance] Classical.decEq + +theorem cyclic_weight_sum_le (N : ℕ) [NeZero N] (w : ZMod N → ℝ) + (hw : ∀ r, 0 ≤ w r) (heven : ∀ r, w (-r) = w r) : + (∑ r : ZMod N, w r/(cyclicDistance N r : ℝ)) ≤ + 2 * ∑ r : ZMod N, w r/(r.val : ℝ) := by + have hp (r : ZMod N) : + w r/(cyclicDistance N r : ℝ) ≤ w r/(r.val : ℝ) + w (-r)/((-r).val : ℝ) := by + by_cases hr : r = 0 + · simp [hr,cyclicDistance] + have hneg : (-r).val = N-r.val := by rw [ZMod.neg_val,ite_eq_right hr] + have hdist : (cyclicDistance N r : ℝ) = min (r.val : ℝ) ((-r).val : ℝ) := by + simp only [cyclicDistance,Nat.cast_min,hneg] + rw [hdist,heven r] + rcases le_total (r.val : ℝ) ((-r).val : ℝ) with h | h + · rw [min_eq_left h] + exact le_add_of_nonneg_right (div_nonneg (hw _) (Nat.cast_nonneg _)) + · rw [min_eq_right h] + exact le_add_of_nonneg_left (div_nonneg (hw _) (Nat.cast_nonneg _)) + have hsym : (∑ r : ZMod N,w (-r)/((-r).val : ℝ)) = + ∑ r : ZMod N,w r/(r.val : ℝ) := by + have h := Equiv.sum_comp (Equiv.neg (ZMod N)) (fun r => w r/(r.val : ℝ)) + simpa only [Equiv.neg_apply] using h + calc + _ ≤ ∑ r : ZMod N,(w r/(r.val : ℝ) + w (-r)/((-r).val : ℝ)) := + Finset.sum_le_sum (fun r _ => hp r) + _ = _ := by rw [Finset.sum_add_distrib,hsym]; ring + +theorem sum_representatives_le (N : ℕ) [NeZero N] (f : ℕ → ℝ) + (hf : ∀ n, 0 ≤ f n) (hf0 : f 0 = 0) : + (∑ r : ZMod N, f r.val) ≤ ∑ n ∈ Finset.Icc 1 N, f n := by + let S := (Finset.univ : Finset (ZMod N)).filter (· ≠ 0) + have hzero : (∑ r ∈ S,f r.val) = ∑ r : ZMod N,f r.val := by + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro r _ + by_cases hr : r = 0 <;> simp [hr,hf0] + have hi : Set.InjOn (ZMod.val : ZMod N → ℕ) (S : Set (ZMod N)) := + (ZMod.val_injective N).injOn + have hsub : S.image ZMod.val ⊆ Finset.Icc 1 N := by + intro n hn + obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp hn + have hr0 := (Finset.mem_filter.mp hr).2 + have hval : 0 < r.val := Nat.pos_of_ne_zero (fun hz => hr0 ((ZMod.val_eq_zero r).mp hz)) + exact Finset.mem_Icc.mpr ⟨hval,r.val_lt.le⟩ + rw [← hzero] + calc + _ = ∑ n ∈ S.image ZMod.val,f n := by + rw [Finset.sum_image] + exact fun a ha b hb h => hi ha hb h + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg hsub (fun n _ _ => hf n) + +end ErdosHyperbola + +end + +section + +namespace ErdosHyperbolaWeighted + +theorem log_two_mul_le_power {eps x : ℝ} (heps : 0 < eps) (hx : 0 < x) : + Real.log (2*x) ≤ ((2 : ℝ)^eps/eps)*x^eps := by + have h := Real.add_one_le_exp (eps*Real.log (2*x)) + have he : Real.exp (eps*Real.log (2*x)) = (2*x)^eps := by + rw [Real.rpow_def_of_pos (by positivity)] + congr 1 + ring + rw [he, Real.mul_rpow (by norm_num) hx.le] at h + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ heps).mpr + nlinarith + +end ErdosHyperbolaWeighted + +end + +section + +open scoped BigOperators + +namespace ErdosHyperbola + +open ErdosHyperbolaFourier + +theorem gcd_val_neg (N : ℕ) [NeZero N] (r : ZMod N) : + Nat.gcd (-r).val N = Nat.gcd r.val N := by + by_cases hr : r = 0 + · simp [hr] + rw [ZMod.neg_val,ite_eq_right hr] + exact Nat.gcd_self_sub_left r.val_lt.le + +theorem cyclic_inverse_sum_le (N : ℕ) [NeZero N] : + (∑ r : ZMod N, 1/(cyclicDistance N r : ℝ)) ≤ + (2*harmonicConstant)*Real.log (2*(N : ℝ)) := by + have h := cyclic_weight_sum_le N (fun _ => 1) (fun _ => zero_le_one) (fun _ => rfl) + have hr : (∑ r : ZMod N,1/(r.val : ℝ)) ≤ harmonicWeight N := + sum_representatives_le N (fun n => 1/(n : ℝ)) (fun _ => by positivity) (by simp) + calc + _ ≤ 2*harmonicWeight N := h.trans (mul_le_mul_of_nonneg_left hr (by norm_num)) + _ ≤ 2*(harmonicConstant*Real.log (2*(N : ℝ))) := + mul_le_mul_of_nonneg_left (harmonicWeight_log_le N (NeZero.pos N)) (by norm_num) + _ = _ := by ring + +theorem sqrt_gcd_cyclic_sum_le (N : ℕ) [NeZero N] : + (∑ r : ZMod N, Real.sqrt (Nat.gcd r.val N)/(cyclicDistance N r : ℝ)) ≤ + (2*harmonicConstant)*(N.divisors.card : ℝ)*Real.log (2*(N : ℝ)) := by + have heven (r : ZMod N) : Real.sqrt (Nat.gcd (-r).val N) = Real.sqrt (Nat.gcd r.val N) := by + rw [gcd_val_neg] + have h := cyclic_weight_sum_le N (fun r => Real.sqrt (Nat.gcd r.val N)) + (fun _ => Real.sqrt_nonneg _) heven + have hr : (∑ r : ZMod N, Real.sqrt (Nat.gcd r.val N)/(r.val : ℝ)) ≤ + (N.divisors.card : ℝ)*harmonicWeight N := + (sum_representatives_le N (fun n => Real.sqrt (Nat.gcd n N)/(n : ℝ)) + (fun _ => by positivity) (by simp)).trans (gcd_harmonic_sum_le N (NeZero.pos N)) + calc + _ ≤ 2*((N.divisors.card : ℝ)*harmonicWeight N) := + h.trans (mul_le_mul_of_nonneg_left hr (by norm_num)) + _ ≤ 2*((N.divisors.card : ℝ)*(harmonicConstant*Real.log (2*(N : ℝ)))) := + mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (harmonicWeight_log_le N (NeZero.pos N)) (Nat.cast_nonneg _)) + (by norm_num) + _ = _ := by ring + +end ErdosHyperbola + +end + +section + +open scoped BigOperators + +namespace ErdosHyperbola + +open ErdosHyperbolaFourier + +def mulUnitEquiv (N : ℕ) (u : (ZMod N)ˣ) : ZMod N ≃ ZMod N where + toFun r := r*(u : ZMod N) + invFun r := r*(↑u⁻¹ : ZMod N) + left_inv r := by simp [mul_assoc] + right_inv r := by simp [mul_assoc] + +@[simp] theorem mulUnitEquiv_apply (N : ℕ) (u : (ZMod N)ˣ) (r : ZMod N) : + mulUnitEquiv N u r = r*(u : ZMod N) := rfl + +theorem gcd_mul_unit (N : ℕ) [NeZero N] (u : (ZMod N)ˣ) (r : ZMod N) : + Nat.gcd (r*(u : ZMod N)).val N = Nat.gcd r.val N := by + have hu : u.val.val.Coprime N := (ZMod.isUnit_iff_coprime u.val.val N).mp + (by simpa only [ZMod.natCast_zmod_val] using u.isUnit) + have he : r*(u : ZMod N) = ((r.val*u.val.val : ℕ) : ZMod N) := by simp + rw [he,ZMod.val_natCast,← Nat.gcd_rec,Nat.gcd_comm N,hu.gcd_mul_right_cancel] + +theorem unit_cyclic_inverse_sum_le (N : ℕ) [NeZero N] (u : (ZMod N)ˣ) : + (∑ r : ZMod N,1/(cyclicDistance N (r*(u : ZMod N)) : ℝ)) ≤ + (2*harmonicConstant)*Real.log (2*(N : ℝ)) := by + have he := Equiv.sum_comp (mulUnitEquiv N u) + (fun r => 1/(cyclicDistance N r : ℝ)) + simp only [mulUnitEquiv_apply] at he + rw [he] + exact cyclic_inverse_sum_le N + +theorem unit_sqrt_gcd_cyclic_sum_le (N : ℕ) [NeZero N] (u : (ZMod N)ˣ) : + (∑ r : ZMod N,Real.sqrt (Nat.gcd r.val N)/ + (cyclicDistance N (r*(u : ZMod N)) : ℝ)) ≤ + (2*harmonicConstant)*(N.divisors.card : ℝ)*Real.log (2*(N : ℝ)) := by + have he := Equiv.sum_comp (mulUnitEquiv N u) + (fun r => Real.sqrt (Nat.gcd r.val N)/(cyclicDistance N r : ℝ)) + simp only [mulUnitEquiv_apply,gcd_mul_unit] at he + rw [he] + exact sqrt_gcd_cyclic_sum_le N + +end ErdosHyperbola + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnlistedLocalMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnlistedLocalMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea1d04debd3ceaa24ce8515e1a498920c5db0818 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnlistedLocalMass.lean @@ -0,0 +1,46 @@ +import OAI.NumberTheory.Jacobsthal.Paths.OutsideExceptionsWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.UnlistedLocalMass +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseAlignment +open EligibleListWord EligibleBoxLists ExpandedCompactPartition ActualBinOwners FilteredBoxWordMass +open LogarithmicBinScale ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +theorem unlisted_mass_le_local_event {w top xi Cs C B K L alpha beta eps : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℕ) + (M : Finset (Fin (binCount w top xi) → ℕ)) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (m : Fin (binCount w top xi) → ℕ) (hm : m∈M) + (a : ℕ → ℕ) (z : PrimeHistories.Node) (F : Finset (List ℕ)) : + selectedWordMass (globalBins w top xi) m + (unlistedGeometric hw htop hxi Cs C B K L alpha beta a z (eligibleLists Y w Cs M Q) + (CountErrorClassification.badCompactWords w K eps Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a + (SmallSieveFinite.smallEuler ⌊w⌋₊) z F)) ≤ + ∑ f∈(selections (globalBins w top xi) m).filter (fun f => + descendingWord f∈GeometricRegularWords.geometricWords hw htop hxi C B K L alpha beta z ∧ + eps < |ActualCountErrorEdges.wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a + (SmallSieveFinite.smallEuler ⌊w⌋₊) (descendingWord f)| ∧ + ¬∃ q∈Q m,eligible Y w Cs q ∧ + ∀ p∈descendingWord f,Cs < primeExponent w p → aligns (SourceStopPredicate.sourceClass a) q p), + (selectionProduct f:ℝ)⁻¹ := by + simp only [selectedWordMass,Finset.sum_filter] + apply Finset.sum_le_sum + intro f hf + split_ifs with hU hLocal hLocal + · exact le_rfl + · exact False.elim (hLocal (unlisted_compact_selected_data hw htop hxi Y M Q m hm f hf a z F hU)) + · exact inv_nonneg.mpr (Nat.cast_nonneg _) + · exact le_rfl +end NumberTheoryLean.UnlistedLocalMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnmarkedTransform.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnmarkedTransform.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc5ccfe35dd17b82f88cf0f68cd5e2d48037da17 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/UnmarkedTransform.lean @@ -0,0 +1,69 @@ +import Mathlib.MeasureTheory.Integral.Lebesgue.DominatedConvergence +import OAI.NumberTheory.Jacobsthal.Sieve.MarkedCycleFactorization + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open NumberTheoryLean.CostReturnLaw + +lemma unmarked_mass_lt_one : unmarkedCostLaw univ < 1 := by + have he := congrArg (fun μ : Measure ℝ => μ univ) markedCostLaw_add_unmarked + have hsum : unmarkedCostLaw univ+markProbability=1 := by + simpa only [Measure.add_apply,markedCostLaw_mass,measure_univ,add_comm] using he + exact (ENNReal.lt_add_right (measure_ne_top _ _) markProbability_pos.ne').trans_eq hsum + +lemma positive_cost_of_lower {G : ℝ} (hG : Real.log (4/3) ≤ G) : 0 ≤ G := by + have h : 0 < Real.log (4/3:ℝ) := Real.log_pos (by norm_num) + linarith + +theorem exists_subcritical_unmarked_transform : ∃ eta : ℝ, 0 < eta ∧ + (∫⁻ G, ENNReal.ofReal (Real.exp (eta*G)) ∂unmarkedCostLaw) < 1 ∧ + (∫⁻ G, ENNReal.ofReal (Real.exp (eta*G)) ∂markedCostLaw) < ∞ := by + obtain ⟨eta0,heta0,hMarked,hUnmarked⟩ := source_marked_exponential_moments + let eta : ℕ → ℝ := fun n => eta0/((n:ℝ)+1) + have heta (n : ℕ) : 0 < eta n := by dsimp [eta]; positivity + have hle (n : ℕ) : eta n ≤ eta0 := by + exact div_le_self heta0.le (by have hn : (0:ℝ) ≤ n := Nat.cast_nonneg n; linarith) + have hseq : Tendsto eta atTop (𝓝 0) := by + simpa only [eta,mul_one_div,mul_zero] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul eta0 + let F : ℕ → ℝ → ℝ≥0∞ := fun n G => ENNReal.ofReal (Real.exp (eta n*G)) + let bound : ℝ → ℝ≥0∞ := fun G => ENNReal.ofReal (Real.exp (eta0*G)) + have hF (n : ℕ) : Measurable (F n) := + ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp (measurable_const.mul measurable_id)) + have hBound (n : ℕ) : F n ≤ᵐ[unmarkedCostLaw] bound := by + filter_upwards [source_unmarked_cost_lower] with G hG + exact ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr + (mul_le_mul_of_nonneg_right (hle n) (positive_cost_of_lower hG))) + have hLim : ∀ᵐ G ∂unmarkedCostLaw, Tendsto (fun n => F n G) atTop (𝓝 1) := by + apply Eventually.of_forall + intro G + have he := (ENNReal.continuous_ofReal.tendsto _).comp + ((Real.continuous_exp.tendsto _).comp (hseq.mul_const G)) + simpa only [F,Function.comp_def,zero_mul,Real.exp_zero,ENNReal.ofReal_one] using! he + have hInt := tendsto_lintegral_of_dominated_convergence bound hF hBound hUnmarked.ne hLim + have hInt' : Tendsto (fun n => ∫⁻ G, F n G ∂unmarkedCostLaw) atTop + (𝓝 (unmarkedCostLaw univ)) := by simpa only [lintegral_one] using hInt + obtain ⟨n,hn⟩ := (hInt'.eventually (gt_mem_nhds unmarked_mass_lt_one)).exists + refine ⟨eta n,heta n,hn,?_⟩ + have hm : (∫⁻ G, ENNReal.ofReal (Real.exp (eta n*G)) ∂markedCostLaw) ≤ + ∫⁻ G, ENNReal.ofReal (Real.exp (eta0*G)) ∂markedCostLaw := by + apply lintegral_mono_ae + filter_upwards [source_marked_cost_lower] with G hG + exact ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr + (mul_le_mul_of_nonneg_right (hle n) (positive_cost_of_lower hG))) + exact hm.trans_lt hMarked + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/WeightedMonotoneBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/WeightedMonotoneBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..eccfbbcc780b908f889d137a5865b106a885674b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/WeightedMonotoneBound.lean @@ -0,0 +1,306 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Partitions.BoundedOrderIntervals + +namespace OAI + +namespace Erdos970 + +section + +open MeasureTheory Set +namespace ErdosMonotoneQuadrature + +variable {α : Type*} [MeasurableSpace α] + +theorem nonnegative_layercake_discrepancy + (μ ν : Measure α) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (f : α → ℝ) (K E : ℝ) (hK : 0 ≤ K) + (hf : Measurable f) (hlo : ∀ x, 0 ≤ f x) (hhi : ∀ x, f x ≤ K) + (hd : ∀ t ∈ Ioc 0 K, |μ.real {x | t ≤ f x} - ν.real {x | t ≤ f x}| ≤ E) : + |(∫ x, f x ∂μ) - ∫ x, f x ∂ν| ≤ E*K := by + have hfm : Integrable f μ := Integrable.of_bound hf.aestronglyMeasurable K + (Filter.Eventually.of_forall fun x => by simpa only [Real.norm_eq_abs,abs_of_nonneg (hlo x)] using hhi x) + have hfn : Integrable f ν := Integrable.of_bound hf.aestronglyMeasurable K + (Filter.Eventually.of_forall fun x => by simpa only [Real.norm_eq_abs,abs_of_nonneg (hlo x)] using hhi x) + have hm : Antitone (fun t : ℝ => μ.real {x | t ≤ f x}) := by + intro s t hst + exact measureReal_mono (fun x hx => hst.trans hx) + have hn : Antitone (fun t : ℝ => ν.real {x | t ≤ f x}) := by + intro s t hst + exact measureReal_mono (fun x hx => hst.trans hx) + have him : IntegrableOn (fun t : ℝ => μ.real {x | t ≤ f x}) (Ioc 0 K) := + ((hm.antitoneOn (Icc 0 K)).integrableOn_isCompact isCompact_Icc).mono_set Ioc_subset_Icc_self + have hin : IntegrableOn (fun t : ℝ => ν.real {x | t ≤ f x}) (Ioc 0 K) := + ((hn.antitoneOn (Icc 0 K)).integrableOn_isCompact isCompact_Icc).mono_set Ioc_subset_Icc_self + rw [hfm.integral_eq_integral_Ioc_meas_le (Filter.Eventually.of_forall hlo) + (Filter.Eventually.of_forall hhi), + hfn.integral_eq_integral_Ioc_meas_le (Filter.Eventually.of_forall hlo) + (Filter.Eventually.of_forall hhi), ← integral_sub him hin] + calc + _ ≤ ∫ t in Ioc 0 K, |μ.real {x | t ≤ f x} - ν.real {x | t ≤ f x}| := + abs_integral_le_integral_abs + _ ≤ ∫ _t in Ioc 0 K, E := integral_mono_ae (him.sub hin).abs (integrable_const E) + ((ae_restrict_iff' measurableSet_Ioc).mpr (Filter.Eventually.of_forall fun t ht => hd t ht)) + _ = E*K := by simp [Real.volume_real_Ioc,max_eq_left hK,mul_comm] + +end ErdosMonotoneQuadrature + +end + +section + +open MeasureTheory Set +namespace ErdosMonotoneQuadrature + +theorem integrable_layercake_discrepancy + {α : Type*} [MeasurableSpace α] + (μ ν : Measure α) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (f : α → ℝ) (K E : ℝ) (hK : 0 ≤ K) + (hfm : Integrable f μ) (hfn : Integrable f ν) + (hloμ : 0 ≤ᵐ[μ] f) (hloν : 0 ≤ᵐ[ν] f) + (hhiμ : f ≤ᵐ[μ] (fun _ => K)) (hhiν : f ≤ᵐ[ν] (fun _ => K)) + (hd : ∀ t ∈ Ioc 0 K, |μ.real {x | t ≤ f x} - ν.real {x | t ≤ f x}| ≤ E) : + |(∫ x, f x ∂μ) - ∫ x, f x ∂ν| ≤ E*K := by + have hm : Antitone (fun t : ℝ => μ.real {x | t ≤ f x}) := by + intro s t hst + exact measureReal_mono (fun x hx => hst.trans hx) + have hn : Antitone (fun t : ℝ => ν.real {x | t ≤ f x}) := by + intro s t hst + exact measureReal_mono (fun x hx => hst.trans hx) + have him : IntegrableOn (fun t : ℝ => μ.real {x | t ≤ f x}) (Ioc 0 K) := + ((hm.antitoneOn (Icc 0 K)).integrableOn_isCompact isCompact_Icc).mono_set Ioc_subset_Icc_self + have hin : IntegrableOn (fun t : ℝ => ν.real {x | t ≤ f x}) (Ioc 0 K) := + ((hn.antitoneOn (Icc 0 K)).integrableOn_isCompact isCompact_Icc).mono_set Ioc_subset_Icc_self + rw [hfm.integral_eq_integral_Ioc_meas_le hloμ hhiμ, + hfn.integral_eq_integral_Ioc_meas_le hloν hhiν, ← integral_sub him hin] + calc + _ ≤ ∫ t in Ioc 0 K, |μ.real {x | t ≤ f x} - ν.real {x | t ≤ f x}| := + abs_integral_le_integral_abs + _ ≤ ∫ _t in Ioc 0 K, E := integral_mono_ae (him.sub hin).abs (integrable_const E) + ((ae_restrict_iff' measurableSet_Ioc).mpr (Filter.Eventually.of_forall fun t ht => hd t ht)) + _ = E*K := by simp [Real.volume_real_Ioc,max_eq_left hK,mul_comm] + +theorem monotone_level_orderConnected {f : ℝ → ℝ} {J : Set ℝ} + (hJ : J.OrdConnected) (hf : MonotoneOn f J ∨ AntitoneOn f J) (t : ℝ) : + ({x | t ≤ f x} ∩ J).OrdConnected := by + constructor + intro x hx y hy z hz + have hzJ : z ∈ J := hJ.out hx.2 hy.2 hz + refine ⟨?_,hzJ⟩ + rcases hf with hm | ha + · exact hx.1.trans (hm hx.2 hzJ hz.1) + · exact hy.1.trans (ha hzJ hy.2 hz.2) + +theorem nonnegative_monotone_integral_discrepancy + (μ ν : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (u v K E : ℝ) (hK : 0 ≤ K) (f : ℝ → ℝ) + (hf : MonotoneOn f (Icc u v) ∨ AntitoneOn f (Icc u v)) + (hlo : ∀ x ∈ Icc u v, 0 ≤ f x) (hhi : ∀ x ∈ Icc u v, f x ≤ K) + (hd : ∀ S : Set ℝ, S.OrdConnected → S ⊆ Icc u v → |μ.real S-ν.real S| ≤ E) + {J : Set ℝ} (hJ : J.OrdConnected) (hsub : J ⊆ Icc u v) : + |(∫ x in J, f x ∂μ) - ∫ x in J, f x ∂ν| ≤ E*K := by + have hfm : IntegrableOn f (Icc u v) μ := by + rcases hf with hm | ha + · exact hm.integrableOn_isCompact isCompact_Icc + · exact ha.integrableOn_isCompact isCompact_Icc + have hfn : IntegrableOn f (Icc u v) ν := by + rcases hf with hm | ha + · exact hm.integrableOn_isCompact isCompact_Icc + · exact ha.integrableOn_isCompact isCompact_Icc + have hflocal : MonotoneOn f J ∨ AntitoneOn f J := hf.elim + (fun hm => Or.inl (hm.mono hsub)) (fun ha => Or.inr (ha.mono hsub)) + apply integrable_layercake_discrepancy (μ.restrict J) (ν.restrict J) f K E hK + (hfm.mono_set hsub) (hfn.mono_set hsub) + · exact (ae_restrict_iff' hJ.measurableSet).mpr + (Filter.Eventually.of_forall fun x hx => hlo x (hsub hx)) + · exact (ae_restrict_iff' hJ.measurableSet).mpr + (Filter.Eventually.of_forall fun x hx => hlo x (hsub hx)) + · exact (ae_restrict_iff' hJ.measurableSet).mpr + (Filter.Eventually.of_forall fun x hx => hhi x (hsub hx)) + · exact (ae_restrict_iff' hJ.measurableSet).mpr + (Filter.Eventually.of_forall fun x hx => hhi x (hsub hx)) + · intro t _ht + rw [measureReal_restrict_apply' hJ.measurableSet,measureReal_restrict_apply' hJ.measurableSet] + exact hd _ (monotone_level_orderConnected hJ hflocal t) (fun x hx => hsub hx.2) + +end ErdosMonotoneQuadrature + +end + +section + +open MeasureTheory Set +namespace ErdosMonotoneQuadrature + +noncomputable def reciprocalWeight (u x : ℝ) : ℝ := (max u x)⁻¹ + +theorem reciprocalWeight_pos {u : ℝ} (hu : 0 < u) (x : ℝ) : + 0 < reciprocalWeight u x := inv_pos.mpr (hu.trans_le (le_max_left _ _)) + +theorem reciprocalWeight_le {u : ℝ} (hu : 0 < u) (x : ℝ) : + reciprocalWeight u x ≤ u⁻¹ := inv_anti₀ hu (le_max_left _ _) + +theorem reciprocalWeight_continuous {u : ℝ} (hu : 0 < u) : + Continuous (reciprocalWeight u) := + (continuous_const.max continuous_id).inv₀ (fun x => ne_of_gt (hu.trans_le (le_max_left u x))) + +theorem reciprocalWeight_antitone {u : ℝ} (hu : 0 < u) : + Antitone (reciprocalWeight u) := by + intro x y hxy + exact inv_anti₀ (hu.trans_le (le_max_left u x)) (max_le_max_left u hxy) + +theorem reciprocalWeight_eq {u x : ℝ} (hx : u ≤ x) : reciprocalWeight u x=x⁻¹ := by + simp only [reciprocalWeight,max_eq_right hx] + +noncomputable def reciprocalMeasure (μ : Measure ℝ) (u : ℝ) : Measure ℝ := + μ.withDensity (fun x => ENNReal.ofReal (reciprocalWeight u x)) + +theorem reciprocalMeasure_finite (μ : Measure ℝ) [IsFiniteMeasure μ] {u : ℝ} (hu : 0 < u) : + IsFiniteMeasure (reciprocalMeasure μ u) := by + have h : Integrable (reciprocalWeight u) μ := + Integrable.of_bound (reciprocalWeight_continuous hu).measurable.aestronglyMeasurable u⁻¹ + (Filter.Eventually.of_forall fun x => by + simpa only [Real.norm_eq_abs,abs_of_pos (reciprocalWeight_pos hu x)] using reciprocalWeight_le hu x) + exact isFiniteMeasure_withDensity_ofReal h.hasFiniteIntegral + +theorem reciprocalMeasure_integral (μ : Measure ℝ) {u : ℝ} (hu : 0 < u) + (g : ℝ → ℝ) {J : Set ℝ} (hJ : MeasurableSet J) : + (∫ x in J, g x ∂reciprocalMeasure μ u) = ∫ x in J, reciprocalWeight u x*g x ∂μ := by + have h := setIntegral_withDensity_eq_setIntegral_toReal_smul + (μ:=μ) ((reciprocalWeight_continuous hu).measurable.ennreal_ofReal) + (Filter.Eventually.of_forall fun _ => ENNReal.ofReal_lt_top) g hJ + simpa only [reciprocalMeasure,ENNReal.toReal_ofReal (reciprocalWeight_pos hu _).le,smul_eq_mul] using h + +theorem reciprocalMeasure_real (μ : Measure ℝ) {u : ℝ} (hu : 0 < u) + {J : Set ℝ} (hJ : MeasurableSet J) : + (reciprocalMeasure μ u).real J = ∫ x in J, reciprocalWeight u x ∂μ := by + simpa only [integral_const,smul_eq_mul,mul_one,measureReal_restrict_apply_univ] using + reciprocalMeasure_integral μ hu (fun _ => (1:ℝ)) hJ + +theorem reciprocalMeasure_discrepancy + (μ ν : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (u v E : ℝ) (hu : 0 < u) + (hd : ∀ S : Set ℝ, S.OrdConnected → S ⊆ Icc u v → |μ.real S-ν.real S| ≤ E) + {J : Set ℝ} (hJ : J.OrdConnected) (hsub : J ⊆ Icc u v) : + |(reciprocalMeasure μ u).real J-(reciprocalMeasure ν u).real J| ≤ E*u⁻¹ := by + rw [reciprocalMeasure_real μ hu hJ.measurableSet,reciprocalMeasure_real ν hu hJ.measurableSet] + exact nonnegative_monotone_integral_discrepancy μ ν u v u⁻¹ E (inv_nonneg.mpr hu.le) + (reciprocalWeight u) (Or.inr ((reciprocalWeight_antitone hu).antitoneOn _)) + (fun x _ => (reciprocalWeight_pos hu x).le) (fun x _ => reciprocalWeight_le hu x) hd hJ hsub + +end ErdosMonotoneQuadrature + +end + +section + +open MeasureTheory Set +namespace ErdosMonotoneQuadrature + +theorem signed_monotone_integral_discrepancy + (μ ν : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (u v D E : ℝ) (hD : 0 ≤ D) (g : ℝ → ℝ) + (hg : MonotoneOn g (Icc u v) ∨ AntitoneOn g (Icc u v)) + (hbound : ∀ x ∈ Icc u v, |g x| ≤ D) + (hd : ∀ S : Set ℝ, S.OrdConnected → S ⊆ Icc u v → |μ.real S-ν.real S| ≤ E) + {J : Set ℝ} (hJ : J.OrdConnected) (hsub : J ⊆ Icc u v) : + |(∫ x in J, g x ∂μ) - ∫ x in J, g x ∂ν| ≤ 3*E*D := by + have hgm : IntegrableOn g J μ := by + rcases hg with hm | ha + · exact (hm.integrableOn_isCompact isCompact_Icc).mono_set hsub + · exact (ha.integrableOn_isCompact isCompact_Icc).mono_set hsub + have hgn : IntegrableOn g J ν := by + rcases hg with hm | ha + · exact (hm.integrableOn_isCompact isCompact_Icc).mono_set hsub + · exact (ha.integrableOn_isCompact isCompact_Icc).mono_set hsub + have hshift : MonotoneOn (fun x => g x+D) (Icc u v) ∨ + AntitoneOn (fun x => g x+D) (Icc u v) := by + rcases hg with hm | ha + · exact Or.inl (fun x hx y hy hxy => by dsimp; linarith [hm hx hy hxy]) + · exact Or.inr (fun x hx y hy hxy => by dsimp; linarith [ha hx hy hxy]) + have hpos : ∀ x ∈ Icc u v, 0 ≤ g x+D := by + intro x hx + have h := (abs_le.mp (hbound x hx)).1 + linarith + have hhi : ∀ x ∈ Icc u v, g x+D ≤ 2*D := by + intro x hx + have h := (abs_le.mp (hbound x hx)).2 + linarith + have h := nonnegative_monotone_integral_discrepancy μ ν u v (2*D) E + (by positivity) (fun x => g x+D) hshift hpos hhi hd hJ hsub + have heq : (∫ x in J, g x ∂μ) - ∫ x in J, g x ∂ν = + ((∫ x in J, g x+D ∂μ) - ∫ x in J, g x+D ∂ν) - D*(μ.real J-ν.real J) := by + rw [integral_add hgm (integrable_const D),integral_add hgn (integrable_const D)] + simp only [integral_const,smul_eq_mul,measureReal_restrict_apply_univ] + ring + rw [heq] + calc + _ ≤ |(∫ x in J, g x+D ∂μ) - ∫ x in J, g x+D ∂ν| + |D*(μ.real J-ν.real J)| := + abs_sub _ _ + _ ≤ E*(2*D) + D*E := add_le_add h (by + rw [abs_mul,abs_of_nonneg hD] + exact mul_le_mul_of_nonneg_left (hd J hJ hsub) hD) + _ = 3*E*D := by ring + +end ErdosMonotoneQuadrature + +end + +section + +open MeasureTheory Set +namespace ErdosMonotoneQuadrature + +theorem weighted_monotone_discrepancy + (μ ν : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (u v D E : ℝ) (hu : 0 < u) (hD : 0 ≤ D) (g : ℝ → ℝ) + (hg : MonotoneOn g (Icc u v) ∨ AntitoneOn g (Icc u v)) + (hbound : ∀ x ∈ Icc u v, |g x| ≤ D) + (hd : ∀ S : Set ℝ, S.OrdConnected → S ⊆ Icc u v → |μ.real S-ν.real S| ≤ E) + {J : Set ℝ} (hJ : J.OrdConnected) (hsub : J ⊆ Icc u v) : + |(∫ x in J, g x/x ∂μ) - ∫ x in J, g x/x ∂ν| ≤ 3*E*D/u := by + let := reciprocalMeasure_finite μ hu + let := reciprocalMeasure_finite ν hu + have h := signed_monotone_integral_discrepancy (reciprocalMeasure μ u) + (reciprocalMeasure ν u) u v D (E*u⁻¹) hD g hg hbound + (fun S hS hs => reciprocalMeasure_discrepancy μ ν u v E hu hd hS hs) hJ hsub + have hm : (∫ x in J, g x ∂reciprocalMeasure μ u) = ∫ x in J, g x/x ∂μ := by + rw [reciprocalMeasure_integral μ hu g hJ.measurableSet] + apply setIntegral_congr_fun hJ.measurableSet + intro x hx + dsimp only + rw [reciprocalWeight_eq (hsub hx).1] + simp only [div_eq_mul_inv,mul_comm] + have hn : (∫ x in J, g x ∂reciprocalMeasure ν u) = ∫ x in J, g x/x ∂ν := by + rw [reciprocalMeasure_integral ν hu g hJ.measurableSet] + apply setIntegral_congr_fun hJ.measurableSet + intro x hx + dsimp only + rw [reciprocalWeight_eq (hsub hx).1] + simp only [div_eq_mul_inv,mul_comm] + rw [hm,hn] at h + convert! h using 1 + ring + +theorem weighted_from_all_endpoint_intervals + (μ ν : Measure ℝ) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (u v D E : ℝ) (hu : 0 < u) (hD : 0 ≤ D) (hE : 0 ≤ E) (g : ℝ → ℝ) + (hg : MonotoneOn g (Icc u v) ∨ AntitoneOn g (Icc u v)) + (hbound : ∀ x ∈ Icc u v, |g x| ≤ D) + (hinterval : ∀ a b : ℝ, u ≤ a → a ≤ b → b ≤ v → + |μ.real (Icc a b)-ν.real (Icc a b)| ≤ E ∧ + |μ.real (Ico a b)-ν.real (Ico a b)| ≤ E ∧ + |μ.real (Ioc a b)-ν.real (Ioc a b)| ≤ E ∧ + |μ.real (Ioo a b)-ν.real (Ioo a b)| ≤ E) + {J : Set ℝ} (hJ : J.OrdConnected) (hsub : J ⊆ Icc u v) : + |(∫ x in J, g x/x ∂μ) - ∫ x in J, g x/x ∂ν| ≤ 3*E*D/u := + weighted_monotone_discrepancy μ ν u v D E hu hD g hg hbound + (fun _ hS hs => orderConnected_measure_discrepancy μ ν u v E hE hinterval hS hs) hJ hsub + +end ErdosMonotoneQuadrature + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Estimates/WeightedTwoExceptions.lean b/lean/OAI/NumberTheory/Jacobsthal/Estimates/WeightedTwoExceptions.lean new file mode 100644 index 0000000000000000000000000000000000000000..c38ca35009ac348313238dc5cc4a7f4ce28ede4c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Estimates/WeightedTwoExceptions.lean @@ -0,0 +1,34 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosVarianceEligible +attribute [local instance] Classical.propDecidable + +theorem weighted_two_exceptions {α : Type*} (S : Finset α) (weight : α → ℝ) + (E A B : α → Prop) (hw : ∀ x ∈ S,0 ≤ weight x) + (hsub : ∀ x ∈ S,E x → A x ∨ B x) : + (∑ x ∈ S.filter E,weight x) ≤ (∑ x ∈ S.filter A,weight x)+(∑ x ∈ S.filter B,weight x) := by + simp only [Finset.sum_filter,← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro x hx + by_cases he : E x + · rcases hsub x hx he with ha|hb + · simp only [ite_eq_left he,ite_eq_left ha] + split_ifs <;> linarith [hw x hx] + · simp only [ite_eq_left he,ite_eq_left hb] + split_ifs <;> linarith [hw x hx] + · simp only [ite_eq_right he] + split_ifs <;> linarith [hw x hx] + +end ErdosVarianceEligible + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/AllCharacterLogPower.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/AllCharacterLogPower.lean new file mode 100644 index 0000000000000000000000000000000000000000..fecc6971e1e44c01aedb6b9e7e0795f417a1a61e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/AllCharacterLogPower.lean @@ -0,0 +1,42 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PrincipalLogPower + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +theorem all_character_log_power (A M : ℝ) (hA : 0 < A) (hM : 0 < M) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q] + (chi : DirichletCharacter ℂ q), (q:ℝ) ≤ (Real.log X)^A → + ‖sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X- + (if chi=1 then (X:ℂ) else 0)‖ ≤ K*X/(Real.log X)^M := by + classical + obtain ⟨C,hC,hNon⟩ := sharp_character_log_power A M hA hM + obtain ⟨D,hD,hPrin⟩ := principal_character_log_power A M hA hM + refine ⟨C+D,by positivity,?_⟩ + filter_upwards [hNon,hPrin,eventually_ge_atTop (3:ℝ)] with X hNon hPrin hX + intro q _ chi hq + have hXp : 0 < X := by linarith + have hLp : 0 < Real.log X := Real.log_pos (by linarith) + have hcb : C*X/(Real.log X)^M ≤ (C+D)*X/(Real.log X)^M := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right (by linarith) hXp.le) (Real.rpow_nonneg hLp.le _) + have hdb : D*X/(Real.log X)^M ≤ (C+D)*X/(Real.log X)^M := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right (by linarith) hXp.le) (Real.rpow_nonneg hLp.le _) + by_cases hc : chi=1 + · subst chi + simpa using! (hPrin q hq).trans hdb + · simpa [hc] using! (hNon q chi hc hq).trans hcb + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/AuxiliaryPolynomialLifting.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/AuxiliaryPolynomialLifting.lean new file mode 100644 index 0000000000000000000000000000000000000000..71d1e96b1f420d23be3b8ec0a6b51c23194daadc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/AuxiliaryPolynomialLifting.lean @@ -0,0 +1,188 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CoefficientHeightChoice +import OAI.NumberTheory.Jacobsthal.Primes.PrimeProductLifting +import OAI.NumberTheory.Jacobsthal.Sieve.LineCongruenceConstruction + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +def constraintVolume (P : Finset ℕ) (T : ∀ p : P, Finset (ZMod p.val)) (D : ℕ) : ℕ := + ∏ p : P, p.val^((D+1)*(T p).card) + +noncomputable def logarithmicCost (P : Finset ℕ) (T : ∀ p : P, Finset (ZMod p.val)) : ℝ := + ∑ p : P, ((T p).card : ℝ)*Real.log (p.val : ℝ) + +theorem constraintVolume_pos (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : ∀ p : P, Finset (ZMod p.val)) (D : ℕ) : 0 < constraintVolume P T D := by + apply Finset.prod_pos + intro p hp + exact pow_pos (hP p p.property) _ + +theorem constraintVolume_log (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : ∀ p : P, Finset (ZMod p.val)) (D : ℕ) : + Real.log (constraintVolume P T D : ℝ) = ((D : ℝ)+1)*logarithmicCost P T := by + classical + unfold constraintVolume logarithmicCost + simp only [Nat.cast_prod,Nat.cast_pow] + rw [Real.log_prod (by + intro p hp + exact pow_ne_zero _ (by exact_mod_cast (Nat.ne_of_gt (hP p p.property))))] + simp only [Real.log_pow,Nat.cast_mul,Nat.cast_add,Nat.cast_one] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro p hp + ring + +theorem dimension_pos (D : ℕ) : 0 < (D+2).choose 2 := Nat.choose_pos (by omega) + +theorem dimension_ratio (D : ℕ) : + ((D : ℝ)+1)/((D+2).choose 2 : ℝ) = 2/((D : ℝ)+2) := by + have hNat : (D+2)*(D+1) = (D+2).choose 2*2 := by + simpa only [Nat.choose_one_right,Nat.add_assoc] using Nat.add_one_mul_choose_eq (D+1) 1 + have hReal : ((D : ℝ)+2)*((D : ℝ)+1) = ((D+2).choose 2 : ℝ)*2 := by exact_mod_cast hNat + apply (div_eq_div_iff (by exact_mod_cast (dimension_pos D).ne') (by positivity)).mpr + nlinarith only [hReal] + +theorem exists_small_line_polynomial (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : ∀ p : P, Finset (ZMod p.val)) (a : ∀ p : P, ZMod p.val) (D : ℕ) : + ∃ (Q : MvPolynomial (Fin 2) ℤ) (H : ℕ), Q ≠ 0 ∧ Q.totalDegree ≤ D ∧ 0 < H ∧ + (∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) ∧ + (∀ p : P, ∀ s : T p, lineSub (Int.castRingHom (ZMod p.val)) (a p) s.val Q = 0) ∧ + Real.log (2*(H : ℝ)) ≤ Real.log 4 + 2/((D : ℝ)+2)*logarithmicCost P T := by + let M := constraintVolume P T D + let N := (D+2).choose 2 + let H := boxHeight M N + have hM : 0 < M := constraintVolume_pos P hP T D + have hN : 0 < N := dimension_pos D + obtain ⟨Q,hQ,hdegree,hcoeff,hline⟩ := exists_line_congruence_polynomial P hP T a D H + (boxHeight_card_strict hN) + refine ⟨Q,H,hQ,hdegree,boxHeight_pos hM,hcoeff,hline,?_⟩ + have hlog := boxHeight_log_bound hM hN + change Real.log (2*(H : ℝ)) ≤ Real.log 4 + Real.log (constraintVolume P T D : ℝ)/((D+2).choose 2 : ℝ) at hlog + rw [constraintVolume_log P hP T D] at hlog + have he : (((D : ℝ)+1)*logarithmicCost P T)/((D+2).choose 2 : ℝ) = + 2/((D : ℝ)+2)*logarithmicCost P T := by + calc + _ = (((D : ℝ)+1)/((D+2).choose 2 : ℝ))*logarithmicCost P T := by ring + _ = _ := by rw [dimension_ratio] + rwa [he] at hlog + +end ErdosAuxiliaryPolynomial + +end + +section + +namespace ErdosAuxiliaryPolynomial + +noncomputable def valueBudget (D H : ℕ) (S : ℝ) : ℝ := + ((D+2).choose 2 : ℝ)*(H : ℝ)*(max 1 S)^D + +noncomputable def logarithmicValueBudget (D H : ℕ) (S : ℝ) : ℝ := + Real.log ((D+2).choose 2 : ℝ)+Real.log (H : ℝ)+(D : ℝ)*Real.log (max 1 S) + +theorem valueBudget_pos (D H : ℕ) (hH : 0 < H) (S : ℝ) : 0 < valueBudget D H S := by + have hN : (0 : ℝ) < ((D+2).choose 2 : ℝ) := by exact_mod_cast dimension_pos D + have hH0 : (0 : ℝ) < H := by exact_mod_cast hH + have hM : (0 : ℝ) < max 1 S := zero_lt_one.trans_le (le_max_left _ _) + exact mul_pos (mul_pos hN hH0) (pow_pos hM D) + +theorem valueBudget_log (D H : ℕ) (hH : 0 < H) (S : ℝ) : + Real.log (valueBudget D H S) = logarithmicValueBudget D H S := by + have hN : (((D+2).choose 2 : ℕ) : ℝ) ≠ 0 := by exact_mod_cast (dimension_pos D).ne' + have hH0 : (H : ℝ) ≠ 0 := by exact_mod_cast hH.ne' + have hM : (max 1 S : ℝ) ≠ 0 := (zero_lt_one.trans_le (le_max_left _ _)).ne' + rw [valueBudget,Real.log_mul (mul_ne_zero hN hH0) (pow_ne_zero D hM), + Real.log_mul hN hH0,Real.log_pow] + rfl + +theorem prime_product_log (I : Finset ℕ) (hprime : ∀ p ∈ I, Nat.Prime p) : + Real.log ((∏ p ∈ I, p : ℕ) : ℝ) = ∑ p ∈ I, Real.log (p : ℝ) := by + rw [Nat.cast_prod] + exact Real.log_prod (fun p hp => by exact_mod_cast (hprime p hp).ne_zero) + +theorem polynomial_log_value_bound (Q : MvPolynomial (Fin 2) ℤ) (D H : ℕ) + (hD : Q.totalDegree ≤ D) (hH : ∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) (hHpos : 0 < H) + (S : ℝ) (x y : ℤ) (hx : 0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) (hy : 0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) + (hne : MvPolynomial.eval ![x,y] Q ≠ 0) : + Real.log |(MvPolynomial.eval ![x,y] Q : ℝ)| ≤ logarithmicValueBudget D H S := by + rw [← valueBudget_log D H hHpos S] + apply Real.log_le_log + · apply abs_pos.mpr + exact_mod_cast hne + · exact polynomial_value_bound Q D H hD hH S x y hx hy + +theorem value_zero_of_log_prime_budget (Q : MvPolynomial (Fin 2) ℤ) (D H : ℕ) + (hD : Q.totalDegree ≤ D) (hH : ∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) (hHpos : 0 < H) + (S : ℝ) (x y : ℤ) (hx : 0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) (hy : 0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) + (I : Finset ℕ) (hprime : ∀ p ∈ I, Nat.Prime p) (a s : ∀ p : I, ZMod p.val) + (hline : ∀ p : I, lineSub (Int.castRingHom (ZMod p.val)) (a p) (s p) Q = 0) + (hinc : ∀ p : I, (y : ZMod p.val) = a p-s p*(x : ZMod p.val)) + (hlarge : logarithmicValueBudget D H S < ∑ p ∈ I, Real.log (p : ℝ)) : + MvPolynomial.eval ![x,y] Q = 0 := by + apply value_zero_of_incident_prime_product Q D H hD hH S x y hx hy I hprime a s hline hinc + have hp : (0 : ℝ) < ((∏ p ∈ I, p : ℕ) : ℝ) := by + exact_mod_cast (Finset.prod_pos (fun p hp => (hprime p hp).pos)) + apply (Real.log_lt_log_iff (valueBudget_pos D H hHpos S) hp).mp + rw [valueBudget_log D H hHpos S,prime_product_log I hprime] + exact hlarge + +end ErdosAuxiliaryPolynomial + +end + +section + +namespace ErdosAuxiliaryPolynomial + +def LineIncidence (P : Finset ℕ) (T : ∀ p : P, Finset (ZMod p.val)) + (a : ∀ p : P, ZMod p.val) (x y : ℤ) (p : P) : Prop := + ∃ s : T p, (y : ZMod p.val) = a p-s.val*(x : ZMod p.val) + +theorem exists_auxiliary_polynomial_lifting (P : Finset ℕ) (hP : ∀ p ∈ P, Nat.Prime p) + (T : ∀ p : P, Finset (ZMod p.val)) (a : ∀ p : P, ZMod p.val) (D : ℕ) : + ∃ (Q : MvPolynomial (Fin 2) ℤ) (H : ℕ), Q ≠ 0 ∧ Q.totalDegree ≤ D ∧ 0 < H ∧ + (∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) ∧ + (∀ p : P, ∀ s : T p, lineSub (Int.castRingHom (ZMod p.val)) (a p) s.val Q = 0) ∧ + Real.log (2*(H : ℝ)) ≤ Real.log 4+2/((D : ℝ)+2)*logarithmicCost P T ∧ + ∀ (S : ℝ) (x y : ℤ), (0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) → + (0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) → + ∀ (I : Finset ℕ) (hIP : I ⊆ P), + (∀ p : I, LineIncidence P T a x y ⟨p.val,hIP p.property⟩) → + logarithmicValueBudget D H S < ∑ p ∈ I, Real.log (p : ℝ) → + MvPolynomial.eval ![x,y] Q = 0 := by + classical + obtain ⟨Q,H,hQ,hD,hH,hcoeff,hline,hlog⟩ := + exists_small_line_polynomial P (fun p hp => (hP p hp).pos) T a D + refine ⟨Q,H,hQ,hD,hH,hcoeff,hline,hlog,?_⟩ + intro S x y hx hy I hIP hinc hlarge + unfold LineIncidence at hinc + choose s hs using hinc + apply value_zero_of_log_prime_budget Q D H hD hcoeff hH S x y hx hy I + (fun p hp => hP p (hIP hp)) + (fun p : I => a ⟨p.val,hIP p.property⟩) (fun p : I => (s p).val) + · exact fun p => hline ⟨p.val,hIP p.property⟩ (s p) + · exact hs + · exact hlarge + +theorem logarithmicCost_le_budget (P : Finset ℕ) (hP : ∀ p ∈ P, 0 < p) + (T : ∀ p : P, Finset (ZMod p.val)) (K : P → ℝ) + (hK : ∀ p : P, ((T p).card : ℝ) ≤ K p) : + logarithmicCost P T ≤ ∑ p : P, K p*Real.log (p.val : ℝ) := by + apply Finset.sum_le_sum + intro p hp + apply mul_le_mul_of_nonneg_right (hK p) + apply Real.log_nonneg + exact_mod_cast Nat.succ_le_of_lt (hP p p.property) + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/BudgetPolynomialBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/BudgetPolynomialBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..207bd8ccf8cf1008cd3fe1975a1e5c0bd3e60ecd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/BudgetPolynomialBound.lean @@ -0,0 +1,132 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UniformFailureBudget +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialMesh + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + + +namespace NumberTheoryLean.BudgetPolynomialBound + +open UniformFailureBudget PrimeKilledChain + +noncomputable def coefficient (A C₁ C₂ C₃ D : ℝ) : ℝ := + 2*(224*C₁+1+24*D+4*C₂*(24*A+5)+4*C₃*(24*A+3)) + +theorem coefficient_nonneg {A C₁ C₂ C₃ D : ℝ} (hA : 0 ≤ A) (hC₁ : 0 ≤ C₁) + (hC₂ : 0 ≤ C₂) (hC₃ : 0 ≤ C₃) (hD : 0 ≤ D) : 0 ≤ coefficient A C₁ C₂ C₃ D := by + unfold coefficient + positivity + +theorem budget_polynomial_bound {c₁ c₂ C₁ C₂ C₃ D κ w S A P : ℝ} (N : ℕ) + (hC₁ : 0 ≤ C₁) (hC₂ : 0 ≤ C₂) (hC₃ : 0 ≤ C₃) (hD : 0 ≤ D) (hA : 0 ≤ A) + (hκ : 0 ≤ κ) (hc₁ : 4*κ ≤ c₁) (hc₂ : 2*κ ≤ c₂) (hκr : κ ≤ normalizationRate) + (hw : 0 ≤ Real.log w) (hP : 1 ≤ P) (hS : 0 ≤ S) (hSP : S ≤ P) (hNP : (N:ℝ) ≤ A*P) + (hclock : 4*(N:ℝ)*ExponentialMesh.mesh κ w ≤ 1) + (hparent : D*(1+S)^3*ExponentialMesh.mesh κ w ≤ 1) : + (N:ℝ)*stepBudget c₁ c₂ C₁ C₂ C₃ D w S (ExponentialMesh.mesh κ w) N ≤ + (A*coefficient A C₁ C₂ C₃ D)*P^7*Real.exp (-κ*Real.sqrt (Real.log w)) := by + let τ := ExponentialMesh.mesh κ w + let e := Real.exp (-κ*Real.sqrt (Real.log w)) + let E₁ := Real.exp (-c₁*Real.sqrt ((1/2:ℝ)*Real.log w)) + let E₂ := Real.exp (-c₂*Real.sqrt ((1/2:ℝ)*Real.log w)) + have hτ : 0 < τ := ExponentialMesh.mesh_pos κ w + have hτe : τ ≤ e := ExponentialMesh.mesh_upper κ w + have hτ1 : τ ≤ 1 := ExponentialMesh.mesh_le_one hκ w + have he : 0 ≤ e := (Real.exp_pos _).le + have hE₁ : E₁ ≤ e := ExponentialMesh.prime_error_dominated hκ (by linarith) hw + have hE₂ : E₂ ≤ e := ExponentialMesh.prime_error_dominated hκ hc₂ hw + have hEdiv : E₁/τ ≤ 2*e := ExponentialMesh.prime_error_over_mesh hκ hc₁ hw + have hP0 : 0 ≤ P := by linarith + have hS1 : 0 ≤ S+1 := by linarith + have hSp : 1+S ≤ 2*P := by linarith + have hpow2 : 1 ≤ P^2 := one_le_pow₀ hP + have hpow6 : 1 ≤ P^6 := one_le_pow₀ hP + have hpow36 : P^3 ≤ P^6 := pow_le_pow_right₀ hP (by norm_num) + have hpow46 : P^4 ≤ P^6 := pow_le_pow_right₀ hP (by norm_num) + have he2 : e ≤ P^2*e := by simpa only [one_mul] using mul_le_mul_of_nonneg_right hpow2 he + have he6 : e ≤ P^6*e := by simpa only [one_mul] using mul_le_mul_of_nonneg_right hpow6 he + have hcount : (S/τ+2)*(τ^2+E₁) ≤ 7*P*e := by + have hid : (S/τ+2)*(τ^2+E₁) = S*τ+2*τ^2+S*(E₁/τ)+2*E₁ := by + field_simp + ring + rw [hid] + have hsq : τ^2 ≤ τ := by nlinarith only [hτ.le, hτ1] + have h1 := mul_le_mul_of_nonneg_left hτe hS + have h2 := mul_le_mul_of_nonneg_left hEdiv hS + have h3 := mul_le_mul_of_nonneg_right hSP he + have h4 := mul_le_mul_of_nonneg_right hP he + nlinarith only [hsq, h1, h2, h3, h4, hE₁, hτe] + have hfirst : (S/τ+2)*(C₁*(1+S)^5*(τ^2+E₁)) ≤ 224*C₁*P^6*e := by + calc + _ = (C₁*(1+S)^5)*((S/τ+2)*(τ^2+E₁)) := by ring + _ ≤ (C₁*(2*P)^5)*(7*P*e) := mul_le_mul + (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by linarith) hSp 5) hC₁) hcount + (by positivity) (by positivity) + _ = _ := by ring + have hU : upperDisplacement S τ N ≤ 24*A*P^2*e := by + have hexp := ExponentialMesh.exp_increment (show 0 ≤ 4*(N:ℝ)*τ by positivity) hclock + have hNmul : 12*(N:ℝ)*τ ≤ 12*(A*P)*e := by + exact mul_le_mul (by nlinarith only [hNP] : 12*(N:ℝ) ≤ 12*(A*P)) hτe hτ.le (by positivity) + calc + _ ≤ (S+1)*(12*(N:ℝ)*τ) := by + unfold upperDisplacement + apply mul_le_mul_of_nonneg_left _ hS1 + nlinarith only [hexp] + _ ≤ (2*P)*(12*(A*P)*e) := mul_le_mul (by linarith) hNmul (by positivity) (by positivity) + _ = _ := by ring + have hδ : upperDisplacement S τ N+3*τ ≤ (24*A+3)*P^2*e := by + nlinarith only [hU, hτe, he2] + have hδE : upperDisplacement S τ N+3*τ+2*E₂ ≤ (24*A+5)*P^2*e := by + nlinarith only [hδ, hE₂, he2] + have hpar : Real.exp (D*(1+S)^3*τ)-1 ≤ 24*D*P^6*e := by + have hexp := ExponentialMesh.exp_increment (show 0 ≤ D*(1+S)^3*τ by positivity) hparent + have hsmall : D*(1+S)^3*τ ≤ D*(2*P)^3*e := mul_le_mul + (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by linarith) hSp 3) hD) hτe hτ.le (by positivity) + calc + _ ≤ 3*(D*(2*P)^3*e) := hexp.trans (mul_le_mul_of_nonneg_left hsmall (by norm_num)) + _ = (24*D*e)*P^3 := by ring + _ ≤ (24*D*e)*P^6 := mul_le_mul_of_nonneg_left hpow36 (by positivity) + _ = _ := by ring + have hb₂ : C₂*(1+S)^2*(upperDisplacement S τ N+3*τ+2*E₂) ≤ 4*C₂*(24*A+5)*P^6*e := by + calc + _ ≤ (C₂*(2*P)^2)*((24*A+5)*P^2*e) := mul_le_mul + (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by linarith) hSp 2) hC₂) hδE + (by have hu := upperDisplacement_nonneg hS1 hτ.le N; positivity) (by positivity) + _ = (4*C₂*(24*A+5)*e)*P^4 := by ring + _ ≤ (4*C₂*(24*A+5)*e)*P^6 := mul_le_mul_of_nonneg_left hpow46 (by positivity) + _ = _ := by ring + have hb₃ : C₃*(1+S)^2*(upperDisplacement S τ N+3*τ) ≤ 4*C₃*(24*A+3)*P^6*e := by + calc + _ ≤ (C₃*(2*P)^2)*((24*A+3)*P^2*e) := mul_le_mul + (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by linarith) hSp 2) hC₃) hδ + (by have hu := upperDisplacement_nonneg hS1 hτ.le N; positivity) (by positivity) + _ = (4*C₃*(24*A+3)*e)*P^4 := by ring + _ ≤ (4*C₃*(24*A+3)*e)*P^6 := mul_le_mul_of_nonneg_left hpow46 (by positivity) + _ = _ := by ring + have hε : epsilon w ≤ P^6*e := by + apply le_trans _ he6 + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonneg_right (neg_le_neg hκr) (Real.sqrt_nonneg (Real.log w)) + have hbudget : stepBudget c₁ c₂ C₁ C₂ C₃ D w S τ N ≤ coefficient A C₁ C₂ C₃ D*P^6*e := by + have hsum := add_le_add (add_le_add (add_le_add (add_le_add hfirst hε) hpar) hb₂) hb₃ + calc + _ ≤ 2*(224*C₁*P^6*e+P^6*e+24*D*P^6*e+4*C₂*(24*A+5)*P^6*e+4*C₃*(24*A+3)*P^6*e) := + mul_le_mul_of_nonneg_left hsum (by norm_num) + _ = _ := by unfold coefficient; ring + have hK := coefficient_nonneg hA hC₁ hC₂ hC₃ hD + calc + _ ≤ (N:ℝ)*(coefficient A C₁ C₂ C₃ D*P^6*e) := mul_le_mul_of_nonneg_left hbudget (Nat.cast_nonneg _) + _ ≤ (A*P)*(coefficient A C₁ C₂ C₃ D*P^6*e) := mul_le_mul_of_nonneg_right hNP (by positivity) + _ = _ := by ring + +end NumberTheoryLean.BudgetPolynomialBound + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterChord.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterChord.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc0faa4e274806dd687bf0a3fb94ec69a2f03f99 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterChord.lean @@ -0,0 +1,124 @@ +import Mathlib.Algebra.Ring.GeomSum +import Mathlib.Analysis.SpecialFunctions.Complex.CircleAddChar +import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosHyperbolaFourier + +noncomputable def characterProgression (N : ℕ) [NeZero N] + (start step : ZMod N) (J : ℕ) : ℂ := + ∑ j ∈ Finset.range J, ZMod.stdAddChar (start + (j : ZMod N)*step) + +theorem characterProgression_factor (N : ℕ) [NeZero N] + (start step : ZMod N) (J : ℕ) : + characterProgression N start step J = + ZMod.stdAddChar start * ∑ j ∈ Finset.range J, (ZMod.stdAddChar step)^j := by + unfold characterProgression + simp only [AddChar.map_add_eq_mul, ← nsmul_eq_mul, AddChar.map_nsmul_eq_pow, + Finset.mul_sum] + +theorem characterProgression_zero_length (N : ℕ) [NeZero N] (start step : ZMod N) : + characterProgression N start step 0 = 0 := by simp [characterProgression] + +theorem characterProgression_zero_step (N : ℕ) [NeZero N] (start : ZMod N) (J : ℕ) : + characterProgression N start 0 J = (J : ℂ) * ZMod.stdAddChar start := by + simp [characterProgression] + +theorem norm_characterProgression_zero_step (N : ℕ) [NeZero N] + (start : ZMod N) (J : ℕ) : ‖characterProgression N start 0 J‖ = J := by + rw [characterProgression_zero_step, norm_mul] + simp [AddChar.norm_apply] + +theorem norm_geom_mul_sub_le_two (z : ℂ) (hz : ‖z‖ = 1) (J : ℕ) : + ‖∑ j ∈ Finset.range J, z^j‖ * ‖1-z‖ ≤ 2 := by + rw [← norm_mul, geom_sum_mul_neg] + calc + _ ≤ ‖(1 : ℂ)‖ + ‖z^J‖ := norm_sub_le _ _ + _ = 2 := by norm_num [norm_pow, hz] + +theorem norm_characterProgression_mul_chord (N : ℕ) [NeZero N] + (start step : ZMod N) (J : ℕ) : + ‖characterProgression N start step J‖ * ‖1-ZMod.stdAddChar step‖ ≤ 2 := by + rw [characterProgression_factor, norm_mul, AddChar.norm_apply, one_mul] + exact norm_geom_mul_sub_le_two _ (AddChar.norm_apply _ _) J + +end ErdosHyperbolaFourier + +end + +section + +namespace ErdosHyperbolaFourier + +def cyclicDistance (N : ℕ) (step : ZMod N) : ℕ := min step.val (N-step.val) + +theorem cyclicDistance_pos (N : ℕ) [NeZero N] (step : ZMod N) (hs : step ≠ 0) : + 0 < cyclicDistance N step := by + have hv : 0 < step.val := Nat.pos_of_ne_zero (fun hv => hs ((ZMod.val_eq_zero step).mp hv)) + exact lt_min hv (Nat.sub_pos_of_lt step.val_lt) + +private theorem sine_half_lower (x : ℝ) (hx : 0 ≤ x) (hxhalf : x ≤ 1/2) : + 2*x ≤ Real.sin (Real.pi*x) := by + have ht : Real.pi*x ≤ Real.pi/2 := by nlinarith [Real.pi_pos] + have h := Real.mul_le_sin (mul_nonneg Real.pi_pos.le hx) ht + calc + _ = (2/Real.pi)*(Real.pi*x) := by field_simp + _ ≤ _ := h + +theorem sine_distance_lower (x : ℝ) (hx : 0 ≤ x) (hx1 : x ≤ 1) : + 2*min x (1-x) ≤ Real.sin (Real.pi*x) := by + by_cases hh : x ≤ 1/2 + · rw [min_eq_left (by linarith)] + exact sine_half_lower x hx hh + · rw [min_eq_right (by linarith)] + have h := sine_half_lower (1-x) (by linarith) (by linarith) + have he : Real.pi*(1-x) = Real.pi-Real.pi*x := by ring + simpa only [he, Real.sin_pi_sub] using h + +theorem exponential_chord_lower (x : ℝ) (hx : 0 ≤ x) (hx1 : x ≤ 1) : + 4*min x (1-x) ≤ ‖Complex.exp (Complex.I * ((2*Real.pi*x : ℝ) : ℂ))-1‖ := by + have hs := sine_distance_lower x hx hx1 + have hs0 : 0 ≤ Real.sin (Real.pi*x) := + (mul_nonneg (by norm_num) (le_min hx (sub_nonneg.mpr hx1))).trans hs + rw [Complex.norm_exp_I_mul_ofReal_sub_one, + show (2*Real.pi*x)/2 = Real.pi*x by ring, Real.norm_eq_abs, + abs_of_nonneg (mul_nonneg (by norm_num) hs0)] + nlinarith + +theorem standard_character_chord_lower (N : ℕ) [NeZero N] (step : ZMod N) : + 4*(cyclicDistance N step : ℝ)/(N : ℝ) ≤ ‖1-ZMod.stdAddChar step‖ := by + have hN : (0 : ℝ) < N := by exact_mod_cast NeZero.pos N + have hv : (step.val : ℝ) ≤ N := by exact_mod_cast step.val_lt.le + have he : ZMod.stdAddChar step = + Complex.exp (Complex.I * ((2*Real.pi*((step.val : ℝ)/N) : ℝ) : ℂ)) := by + rw [ZMod.stdAddChar_apply, ZMod.toCircle_apply] + congr 1 + push_cast + ring + have h := exponential_chord_lower ((step.val : ℝ)/N) (by positivity) + ((div_le_one hN).mpr hv) + have hsub : ((N-step.val : ℕ) : ℝ) = (N : ℝ)-step.val := by + exact Nat.cast_sub step.val_lt.le + have hmin : min ((step.val : ℝ)/N) (1-(step.val : ℝ)/N) = + (cyclicDistance N step : ℝ)/(N : ℝ) := by + rw [show 1-(step.val : ℝ)/N = ((N : ℝ)-step.val)/N by field_simp, + min_div_div_right hN.le] + simp only [cyclicDistance, Nat.cast_min, hsub] + rw [hmin] at h + rw [he, norm_sub_rev] + convert h using 1; ring + +end ErdosHyperbolaFourier + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterPositivity.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterPositivity.lean new file mode 100644 index 0000000000000000000000000000000000000000..385384d0e9de3af66773fba044babb0787bfc725 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterPositivity.lean @@ -0,0 +1,136 @@ +import OAI.NumberTheory.Jacobsthal.Primes.DirichletZeroPenalty + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped ComplexOrder + +noncomputable def characterPhase (n : ℕ) (t : ℝ) : ℂ := (n:ℂ)^(-(t:ℂ)*Complex.I) + +lemma characterPhase_norm {n : ℕ} (hn : n ≠ 0) (t : ℝ) : ‖characterPhase n t‖ = 1 := by + unfold characterPhase + rw [Complex.norm_natCast_cpow_of_pos (Nat.pos_of_ne_zero hn)] + simp + +lemma characterPhase_double {n : ℕ} (hn : n ≠ 0) (t : ℝ) : + characterPhase n (2*t) = characterPhase n t ^ 2 := by + unfold characterPhase + rw [sq, ← Complex.cpow_add _ _ (by exact_mod_cast hn : (n:ℂ) ≠ 0)] + congr 1 + push_cast + ring + +lemma twist_vonMangoldt_term_split {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (sigma t : ℝ) (n : ℕ) : + LSeries.term (fun k => chi k * (ArithmeticFunction.vonMangoldt k : ℂ)) + ((sigma:ℂ)+(t:ℂ)*Complex.I) n = + LSeries.term (fun k => (ArithmeticFunction.vonMangoldt k : ℂ)) (sigma:ℂ) n * + chi n * characterPhase n t := by + by_cases hn : n = 0 + · simp [hn] + · have hnC : (n:ℂ) ≠ 0 := by exact_mod_cast hn + rw [LSeries.term_of_ne_zero hn, LSeries.term_of_ne_zero hn, + Complex.cpow_add _ _ hnC] + unfold characterPhase + rw [neg_mul, Complex.cpow_neg] + simp only [div_eq_mul_inv, mul_inv_rev] + ring + +lemma character_positivity_polynomial (u : ℂ) (hu : ‖u‖ ≤ 1) : + 0 ≤ 3+4*u.re+(u^2).re := by + have hsq : u.re^2+u.im^2 ≤ 1 := by + have h := Complex.sq_norm u + rw [Complex.normSq_apply] at h + nlinarith [norm_nonneg u] + simp only [pow_two, Complex.mul_re] + nlinarith [sq_nonneg (1+u.re)] + +lemma vonMangoldt_three_four_one_nonneg {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (sigma t : ℝ) (n : ℕ) : + 0 ≤ (3 * LSeries.term (fun k => (ArithmeticFunction.vonMangoldt k : ℂ)) (sigma:ℂ) n + + 4 * LSeries.term (fun k => chi k * (ArithmeticFunction.vonMangoldt k : ℂ)) + ((sigma:ℂ)+(t:ℂ)*Complex.I) n + + LSeries.term (fun k => (chi^2) k * (ArithmeticFunction.vonMangoldt k : ℂ)) + ((sigma:ℂ)+(2*t:ℝ)*Complex.I) n).re := by + by_cases hn : n = 0 + · simp [hn] + · let a : ℂ := LSeries.term (fun k => (ArithmeticFunction.vonMangoldt k : ℂ)) (sigma:ℂ) n + let u : ℂ := chi n * characterPhase n t + have hu : ‖u‖ ≤ 1 := by + dsimp only [u] + rw [norm_mul, characterPhase_norm hn, mul_one] + exact chi.norm_le_one n + have ha : 0 ≤ a := LSeries.term_nonneg + (by exact_mod_cast (ArithmeticFunction.vonMangoldt_nonneg (n := n))) sigma + have ha' := Complex.nonneg_iff.mp ha + rw [twist_vonMangoldt_term_split, twist_vonMangoldt_term_split, + characterPhase_double hn] + have hp : (chi^2) n = (chi n)^2 := chi.pow_apply' (by decide) n + rw [hp] + have heq : 3*a+4*(a*chi n*characterPhase n t)+a*(chi n)^2*(characterPhase n t)^2 = + a*(3+4*u+u^2) := by dsimp [u]; ring + change 0 ≤ (3*a+4*(a*chi n*characterPhase n t)+a*(chi n)^2*(characterPhase n t)^2).re + rw [heq, Complex.mul_re, ← ha'.2] + simp only [zero_mul, sub_zero] + apply mul_nonneg ha'.1 + simpa using character_positivity_polynomial u hu + +end Erdos970Dependency.SiegelWalfisz + +end + +section + +namespace Erdos970Dependency.SiegelWalfisz +open scoped BigOperators + +lemma twisted_series_eq_actual_log_derivative {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) {s : ℂ} (hs : 1 < s.re) : + LSeries (fun n => chi n * (ArithmeticFunction.vonMangoldt n : ℂ)) s = + -deriv (DirichletCharacter.LFunction chi) s / DirichletCharacter.LFunction chi s := by + change LSeries ((fun n : ℕ => chi n) * (fun n => (ArithmeticFunction.vonMangoldt n:ℂ))) s = _ + rw [DirichletCharacter.LSeries_twist_vonMangoldt_eq chi hs, + ← DirichletCharacter.deriv_LFunction_eq_deriv_LSeries chi hs, + ← DirichletCharacter.LFunction_eq_LSeries chi hs] + +theorem character_log_derivative_positivity {q : ℕ} [NeZero q] + (chi : DirichletCharacter ℂ q) (sigma t : ℝ) (hs : 1 < sigma) : + 0 ≤ 3 * (-deriv riemannZeta (sigma:ℂ) / riemannZeta (sigma:ℂ)).re + + 4 * (-deriv (DirichletCharacter.LFunction chi) ((sigma:ℂ)+(t:ℂ)*Complex.I) / + DirichletCharacter.LFunction chi ((sigma:ℂ)+(t:ℂ)*Complex.I)).re + + (-deriv (DirichletCharacter.LFunction (chi^2)) ((sigma:ℂ)+(2*t:ℝ)*Complex.I) / + DirichletCharacter.LFunction (chi^2) ((sigma:ℂ)+(2*t:ℝ)*Complex.I)).re := by + let a := LSeries.term (fun n => (ArithmeticFunction.vonMangoldt n:ℂ)) (sigma:ℂ) + let b := LSeries.term (fun n => chi n * (ArithmeticFunction.vonMangoldt n:ℂ)) + ((sigma:ℂ)+(t:ℂ)*Complex.I) + let c := LSeries.term (fun n => (chi^2) n * (ArithmeticFunction.vonMangoldt n:ℂ)) + ((sigma:ℂ)+(2*t:ℝ)*Complex.I) + have ha : Summable a := ArithmeticFunction.LSeriesSummable_vonMangoldt (by simpa using hs) + have hb : Summable b := DirichletCharacter.LSeriesSummable_twist_vonMangoldt chi (by simpa using hs) + have hc : Summable c := DirichletCharacter.LSeriesSummable_twist_vonMangoldt (chi^2) (by simpa using hs) + have hsum := ((ha.mul_left (3:ℂ)).add (hb.mul_left (4:ℂ))).add hc + have hvalue := ((ha.hasSum.mul_left (3:ℂ)).add (hb.hasSum.mul_left (4:ℂ))).add hc.hasSum + have hpositive : 0 ≤ (∑' n:ℕ, (3*a n+4*b n+c n)).re := by + rw [Complex.re_tsum hsum] + exact tsum_nonneg (fun n => vonMangoldt_three_four_one_nonneg chi sigma t n) + rw [hvalue.tsum_eq] at hpositive + change 0 ≤ (3 * LSeries (fun n => (ArithmeticFunction.vonMangoldt n:ℂ)) (sigma:ℂ) + + 4 * LSeries (fun n => chi n * (ArithmeticFunction.vonMangoldt n:ℂ)) ((sigma:ℂ)+(t:ℂ)*Complex.I) + + LSeries (fun n => (chi^2) n * (ArithmeticFunction.vonMangoldt n:ℂ)) ((sigma:ℂ)+(2*t:ℝ)*Complex.I)).re at hpositive + rw [ArithmeticFunction.LSeries_vonMangoldt_eq_deriv_riemannZeta_div (by simpa using hs), + twisted_series_eq_actual_log_derivative chi (by simpa using hs), + twisted_series_eq_actual_log_derivative (chi^2) (by simpa using hs)] at hpositive + simpa [Complex.add_re, Complex.mul_re] using hpositive + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterReduction.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..19fbdd679e469e273e400c8e4e7c05698bcf5aa5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CharacterReduction.lean @@ -0,0 +1,49 @@ +import Mathlib.Data.ZMod.Units +import OAI.NumberTheory.Jacobsthal.Partitions.StationaryFibres + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman.PrimePower + +theorem standard_character_reduction (n d : ℕ) [NeZero n] [NeZero d] + (x : ZMod (n*d)) : + ZMod.stdAddChar ((n : ZMod (n*d)) * x) = + ZMod.stdAddChar (reduction n d x) := by + have hl : (n : ZMod (n*d)) * x = + (((n : ℤ) * (x.val : ℤ) : ℤ) : ZMod (n*d)) := by + push_cast + rw [ZMod.natCast_zmod_val] + have hr : reduction n d x = ((x.val : ℤ) : ZMod d) := by + simpa only [Int.cast_natCast] using reduction_apply_val n d x + rw [hl, hr, ZMod.stdAddChar_coe, ZMod.stdAddChar_coe] + congr 1 + push_cast + have hn : (n : ℂ) ≠ 0 := by exact_mod_cast NeZero.ne n + field_simp + +theorem scaled_phase_reduction (n d : ℕ) [NeZero n] [NeZero d] (h k : ℤ) + (u : (ZMod (n*d))ˣ) : + ZMod.stdAddChar ((((n : ℤ)*h : ℤ) : ZMod (n*d)) * (u : ZMod (n*d)) + + (((n : ℤ)*k : ℤ) : ZMod (n*d)) * (↑u⁻¹ : ZMod (n*d))) = + ZMod.stdAddChar ((h : ZMod d) * (ZMod.unitsMap (dvd_mul_left d n) u : ZMod d) + + (k : ZMod d) * (↑(ZMod.unitsMap (dvd_mul_left d n) u)⁻¹ : ZMod d)) := by + have hphase : (((n : ℤ)*h : ℤ) : ZMod (n*d)) * (u : ZMod (n*d)) + + (((n : ℤ)*k : ℤ) : ZMod (n*d)) * (↑u⁻¹ : ZMod (n*d)) = + (n : ZMod (n*d)) * ((h : ZMod (n*d))*u + (k : ZMod (n*d))*↑u⁻¹) := by + push_cast + ring + rw [hphase, standard_character_reduction] + congr 1 + simp [reduction, ZMod.unitsMap_def, ← map_inv] + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CommonFrequencyLift.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CommonFrequencyLift.lean new file mode 100644 index 0000000000000000000000000000000000000000..62a8c9f9bc616c171c076ccd132950f779695dc9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CommonFrequencyLift.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PrimitiveThreeQuarters +import OAI.NumberTheory.Jacobsthal.Partitions.UnitReductionFibres + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosKloosterman.PrimePower + +theorem common_frequency_lift_product (p s : ℕ) [Fact p.Prime] (hs : 0 < s) + (h k : ℤ) : + standardSum (p*p^s) ((p : ℤ)*h) ((p : ℤ)*k) = + (p : ℂ) * standardSum (p^s) h k := by + unfold standardSum sum + simp_rw [scaled_phase_reduction p (p^s) h k] + convert! sum_comp_unit_reduction p s hs + (fun u : (ZMod (p^s))ˣ => (ZMod.stdAddChar (N := p^s)) ((h : ZMod (p^s))*(u : ZMod (p^s)) + + (k : ZMod (p^s))*(↑u⁻¹ : ZMod (p^s)))) using 1 + · apply Finset.sum_congr (by ext u; simp) + intro u _ + rfl + · congr 1 + apply Finset.sum_congr (by ext u; simp) + intro u _ + rfl + +theorem common_frequency_lift (p s : ℕ) [Fact p.Prime] (hs : 0 < s) (h k : ℤ) : + standardSum (p^(s+1)) ((p : ℤ)*h) ((p : ℤ)*k) = + (p : ℂ) * standardSum (p^s) h k := by + rw [standardSum_modulus_congr _ (p*p^s) (pow_succ' p s)] + exact common_frequency_lift_product p s hs h k + +theorem common_frequency_gcd (p s : ℕ) (h k : ℤ) : + Nat.gcd (p^(s+1)) (Int.gcd ((p : ℤ)*h) ((p : ℤ)*k)) = + p * Nat.gcd (p^s) (Int.gcd h k) := by + rw [pow_succ', Int.gcd_mul_left, Int.natAbs_natCast, Nat.gcd_mul_left] + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CompactAnomalyTest.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CompactAnomalyTest.lean new file mode 100644 index 0000000000000000000000000000000000000000..49ca77dd373f973424c99aca123399afde46cef8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/CompactAnomalyTest.lean @@ -0,0 +1,181 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceSourceDecomposition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Finset +namespace ErdosContinuousAnomaly +attribute [local instance] Classical.propDecidable +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.PrimeBinMembership NumberTheoryLean.ActualPrimeHigh +open NumberTheoryLean.BoundaryAnomaly NumberTheoryLean.UniformBoundaryCorrection +open NumberTheoryLean.UniformExponentialOccupation NumberTheoryLean.ActualBoundaryDomain +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def continuousBoundaryCorrection (w ell : ℝ) (start : Node) : ℝ := + ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*((-1:ℝ)^ps.length* + continuousAnomaly (terminal w start ps).side (terminal w start ps).gap) + +theorem boundaryCorrection_difference (w ell : ℝ) (start : Node) : + boundaryCorrection w ell start-continuousBoundaryCorrection w ell start = + ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps*((-1:ℝ)^ps.length* + (anomaly w (terminal w start ps).side (terminal w start ps).gap- + continuousAnomaly (terminal w start ps).side (terminal w start ps).gap)) := by + simp only [boundaryCorrection,continuousBoundaryCorrection,mul_sub,Finset.sum_sub_distrib] + +theorem actual_anomaly_replacement (ell d eps : ℝ) (hell : 2 ≤ ell) + (hd : 0 < d) (heps : 0 < eps) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → + Real.log B ≤ d*Real.log w → ∀ start : Node, + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + Consistent start → start.cutoff=B → + B^2*|boundaryCorrection w ell start-continuousBoundaryCorrection w ell start| ≤ eps := by + obtain ⟨c,hc,hweighted⟩ := weighted_anomaly_convergence + obtain ⟨C,BO,wO,hC,hBO,hwO,hoccupation⟩ := + uniform_signed_exponential_rewards ell c d (by linarith) hc hd + obtain ⟨wA,hwA,hA⟩ := hweighted (eps/C) (div_pos heps hC) + refine ⟨max BO 4,max wO wA,hBO.trans_le (le_max_left _ _),hwO.trans_le (le_max_left _ _),?_⟩ + intro B w hB hw hcomp start hi h199 h23 hcons hcut + have hBO' : BO ≤ B := (le_max_left _ _).trans hB + have hB4 : 4 ≤ B := (le_max_right _ _).trans hB + have hwO' : wO ≤ w := (le_max_left _ _).trans hw + have hwA' : wA ≤ w := (le_max_right _ _).trans hw + rw [boundaryCorrection_difference] + have hs := hoccupation B w hBO' hwO' hcomp start hi h199 h23 hcons hcut + (eps/C) (div_pos heps hC).le + (fun ps => (-1:ℝ)^ps.length* + (anomaly w (terminal w start ps).side (terminal w start ps).gap- + continuousAnomaly (terminal w start ps).side (terminal w start ps).gap)) + have hp : ∀ ps ∈ uncappedPrefixes w ell start, + |(-1:ℝ)^ps.length*(anomaly w (terminal w start ps).side (terminal w start ps).gap- + continuousAnomaly (terminal w start ps).side (terminal w start ps).gap)| ≤ + (eps/C)*positiveGapEnvelope c (terminal w start ps).gap := by + intro ps hps + have hallowed : uncappedAllowed w ell start ps := (Finset.mem_filter.mp hps).2 + have hdom := source_boundary_domain hB4 hell start hi h199 h23 hcons hcut hallowed + have hr := boundary_gap_ge_two hdom + rw [abs_mul,abs_pow,abs_neg,abs_one,one_pow,one_mul,positiveGapEnvelope,ite_eq_left hr] + exact hA w hwA' _ hr _ + have hcanc : (eps/C)*C=eps := div_mul_cancel₀ eps (ne_of_gt hC) + simpa only [hcanc] using hs hp + +end ErdosContinuousAnomaly + +end + +section + +namespace ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PrimeHistories +open NumberTheoryLean.ActualPrimeHigh +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def sideSign : Side → ℝ | .even => 1 | .odd => -1 + +theorem terminal_side_sign (w : ℝ) (z : Node) (ps : List ℕ) : + sideSign (terminal w z ps).side=sideSign z.side*(-1:ℝ)^ps.length := by + induction ps generalizing z with + | nil => simp only [terminal_nil,List.length_nil,pow_zero,mul_one] + | cons p ps ih => + rw [terminal_cons,ih,List.length_cons,pow_succ] + have he : sideSign (step w z p).side = -sideSign z.side := by + cases h : z.side <;> simp [step,h,Side.flip,sideSign] + rw [he] + ring + +theorem source_parity_sign (w : ℝ) (z : Node) (hz : z.side=.even) (ps : List ℕ) : + (-1:ℝ)^ps.length=sideSign (terminal w z ps).side := by + rw [terminal_side_sign,hz,sideSign,one_mul] + +noncomputable def signedAnomaly (i : Side) (r : ℝ) : ℝ := sideSign i*continuousAnomaly i r + +theorem continuousBoundaryCorrection_eq_state_reward (w ell : ℝ) (start : Node) + (hi : start.side=.even) : + continuousBoundaryCorrection w ell start= + ∑ ps ∈ uncappedPrefixes w ell start,prefixWeight ps* + signedAnomaly (terminal w start ps).side (terminal w start ps).gap := by + unfold continuousBoundaryCorrection signedAnomaly + apply Finset.sum_congr rfl + intro ps _ + rw [source_parity_sign w start hi ps] + +end ErdosContinuousAnomaly + +end + +section + +open _root_.Set +namespace ErdosCorrectionOccupation +open ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.PositiveGapMajorant + +noncomputable def extendedSignedAnomaly (i : Side) (r : ℝ) : ℝ := + sideSign i*continuousAnomaly i (max 2 r) + +theorem extendedSignedAnomaly_continuous (i : Side) : Continuous (extendedSignedAnomaly i) := by + have h := (continuousAnomaly_continuousOn i).comp_continuous + (continuous_const.max continuous_id) (fun r => le_max_left 2 r) + exact continuous_const.mul h + +theorem extendedSignedAnomaly_eq (i : Side) {r : ℝ} (hr : 2 ≤ r) : + extendedSignedAnomaly i r=signedAnomaly i r := by + simp only [extendedSignedAnomaly,signedAnomaly,max_eq_right hr] + +noncomputable def compactCutoff (K : ℝ) : C(ℝ×ℝ,ℝ) := + Classical.choose (exists_positive_gap_majorant K) + +theorem compactCutoff_spec (K : ℝ) : + HasCompactSupport (compactCutoff K) ∧ (∀ x,0 ≤ compactCutoff K x ∧ compactCutoff K x ≤ 1) ∧ + (∀ r s,2 ≤ r → r ≤ K → 0 ≤ s → s ≤ K → compactCutoff K (r,s)=1) ∧ + ∀ r s,r < 1 ∨ K+1 < r → compactCutoff K (r,s)=0 := + Classical.choose_spec (exists_positive_gap_majorant K) + +noncomputable def compactAnomalyTest (K : ℝ) (i : Side) (x : ℝ×ℝ) : ℝ := + compactCutoff K x*extendedSignedAnomaly i x.1 + +theorem compactAnomalyTest_continuous (K : ℝ) (i : Side) : Continuous (compactAnomalyTest K i) := + (compactCutoff K).continuous.mul ((extendedSignedAnomaly_continuous i).comp continuous_fst) + +theorem compactAnomalyTest_compact (K : ℝ) (i : Side) : HasCompactSupport (compactAnomalyTest K i) := by + exact (compactCutoff_spec K).1.mul_right + +theorem compactAnomalyTest_support (K : ℝ) (i : Side) (r s : ℝ) + (hr : r < 1 ∨ K+1 < r) : compactAnomalyTest K i (r,s)=0 := by + unfold compactAnomalyTest + rw [(compactCutoff_spec K).2.2.2 r s hr,zero_mul] + +theorem compactAnomalyTest_eq (K : ℝ) (i : Side) {r s : ℝ} + (hr : 2 ≤ r) (hrK : r ≤ K) (hs : 0 ≤ s) (hsr : s ≤ r) : + compactAnomalyTest K i (r,s)=signedAnomaly i r := by + unfold compactAnomalyTest + rw [(compactCutoff_spec K).2.2.1 r s hr hrK hs (hsr.trans hrK),one_mul,extendedSignedAnomaly_eq i hr] + +theorem compactAnomalyTest_error (K : ℝ) (i : Side) {r s : ℝ} + (hr : 2 ≤ r) (hs : 0 ≤ s) (hsr : s ≤ r) : + |signedAnomaly i r-compactAnomalyTest K i (r,s)| ≤ + if K < r then |continuousAnomaly i r| else 0 := by + by_cases hrK : r ≤ K + · rw [compactAnomalyTest_eq K i hr hrK hs hsr,sub_self,abs_zero,ite_eq_right (not_lt_of_ge hrK)] + · rw [ite_eq_left (lt_of_not_ge hrK)] + have hb := (compactCutoff_spec K).2.1 (r,s) + have he : signedAnomaly i r-compactAnomalyTest K i (r,s)= + (1-compactCutoff K (r,s))*(sideSign i*continuousAnomaly i r) := by + simp only [compactAnomalyTest,extendedSignedAnomaly_eq i hr,signedAnomaly] + ring + rw [he,abs_mul,abs_of_nonneg (by linarith : 0 ≤ 1-compactCutoff K (r,s)),abs_mul] + have hsign : |sideSign i|=1 := by cases i <;> norm_num [sideSign] + rw [hsign,one_mul] + exact mul_le_of_le_one_left (abs_nonneg _) (by linarith) + +end ErdosCorrectionOccupation + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ComplexComponentBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ComplexComponentBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..4e5c860fd67e684df8ab090637b9a9b51a528038 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ComplexComponentBound.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.RealCoefficientNormalization + +namespace OAI + +namespace Erdos970 + +section + +open Set +open scoped ComplexConjugate +namespace ErdosComplexCurveFactors +open ErdosCriticalGeometry ErdosImplicitCurvature ErdosAlgebraicCurve ErdosMarkedStrips + +theorem nonreal_component_card_bound (F : MV ℂ) (hF : Irreducible F) + (hdeg : 1 < F.totalDegree) (hreal : ¬RealScalable F) (S : ℝ) : + (complexSquarePoints F S).card ≤ 2*F.totalDegree^3 := by + have hnd := nonreal_not_dvd_conjugate F hF hreal + obtain ⟨hfinite,hcard⟩ := irreducible_intersection_bound F (conjugate F) hF hdeg hnd + have hmap : ∀ p ∈ (complexSquarePoints F S : Set (ℤ × ℤ)), + complexIntPoint p ∈ intersectionPoints F (conjugate F) := by + intro p hp + have hz := ((mem_complexSquarePoints F S p).mp hp).2 + change MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0 ∧ + MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] (conjugate F) = 0 + refine ⟨hz,?_⟩ + simpa only [Complex.ofReal_intCast,hz,map_zero] using eval_conjugate_real F p.1 p.2 + have hc := ncard_le_ncard_of_injOn complexIntPoint hmap complexIntPoint_injective.injOn hfinite + simp only [ncard_coe_finset] at hc + calc + _ ≤ _ := hc + _ ≤ _ := hcard + _ = 2*F.totalDegree^3 := by rw [conjugate_totalDegree]; ring + +theorem realScalable_component_bound (F : MV ℂ) (hF : Irreducible F) + (hdeg : 1 < F.totalDegree) (hreal : RealScalable F) (S : ℝ) (hS : 0 ≤ S) : + ((complexSquarePoints F S).card : ℝ) ≤ + 182*(F.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3)) := by + obtain ⟨a,ha,R,rfl⟩ := hreal + have hR := (scalar_irreducible_iff a ha (complexify R)).mp hF + have hd : 1 < R.totalDegree := by + simpa only [scalar_totalDegree a ha,complexify_totalDegree] using hdeg + simpa only [complexSquare_scalar a ha,complexSquare_complexify,scalar_totalDegree a ha, + complexify_totalDegree] using absolutely_irreducible_curve_lattice_bound R hR hd S hS + +theorem irreducible_complex_curve_bound (F : MV ℂ) (hF : Irreducible F) + (hdeg : 1 < F.totalDegree) (S : ℝ) (hS : 0 ≤ S) : + ((complexSquarePoints F S).card : ℝ) ≤ + 182*(F.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3)) := by + by_cases hreal : RealScalable F + · exact realScalable_component_bound F hF hdeg hreal S hS + · have h := nonreal_component_card_bound F hF hdeg hreal S + have hB : 1 ≤ 1+S^((2 : ℝ)/3) := le_add_of_nonneg_right (Real.rpow_nonneg hS _) + calc + ((complexSquarePoints F S).card : ℝ) ≤ 2*(F.totalDegree : ℝ)^3 := by exact_mod_cast h + _ ≤ 182*(F.totalDegree : ℝ)^3 := by gcongr; norm_num + _ ≤ _ := le_mul_of_one_le_right (by positivity) hB + +end ErdosComplexCurveFactors + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ComplexSquareScaling.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ComplexSquareScaling.lean new file mode 100644 index 0000000000000000000000000000000000000000..c5d07422e0967f7e520aa105ffcee7566e8e27f8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ComplexSquareScaling.lean @@ -0,0 +1,169 @@ +import OAI.NumberTheory.Jacobsthal.Probability.HorizontalBoundaryMarks +import OAI.NumberTheory.Jacobsthal.Probability.RealExceptionalMarks + +namespace OAI + +namespace Erdos970 + +section + +open scoped ComplexConjugate +namespace ErdosComplexCurveFactors +open ErdosCriticalGeometry + +noncomputable def conjugateEquiv : MV ℂ ≃+* MV ℂ := + MvPolynomial.mapEquiv (Fin 2) Complex.conjAe.toRingEquiv + +noncomputable def conjugate (F : MV ℂ) : MV ℂ := MvPolynomial.map (starRingEnd ℂ) F + +theorem coeff_conjugate (F : MV ℂ) (m : Fin 2 →₀ ℕ) : + (conjugate F).coeff m = conj (F.coeff m) := MvPolynomial.coeff_map _ _ _ + +theorem conjugate_conjugate (F : MV ℂ) : conjugate (conjugate F) = F := by + ext m + rw [coeff_conjugate,coeff_conjugate] + exact star_star _ + +theorem conjugate_irreducible {F : MV ℂ} (hF : Irreducible F) : Irreducible (conjugate F) := + (MulEquiv.irreducible_iff conjugateEquiv.toMulEquiv).mpr hF + +theorem conjugate_totalDegree (F : MV ℂ) : (conjugate F).totalDegree = F.totalDegree := by + unfold conjugate MvPolynomial.totalDegree + rw [MvPolynomial.support_map_of_injective F Complex.conjAe.injective] + +theorem eval_conjugate_real (F : MV ℂ) (x y : ℝ) : + MvPolynomial.eval ![(x : ℂ),(y : ℂ)] (conjugate F) = + conj (MvPolynomial.eval ![(x : ℂ),(y : ℂ)] F) := by + have he : (starRingEnd ℂ) ∘ (![(x : ℂ),(y : ℂ)] : Fin 2 → ℂ) = ![(x : ℂ),(y : ℂ)] := by + funext i + fin_cases i <;> simp + have h := MvPolynomial.map_eval (starRingEnd ℂ) ![(x : ℂ),(y : ℂ)] F + rw [he] at h + exact h.symm + +end ErdosComplexCurveFactors + +end + +section + +open Set +namespace ErdosAlgebraicCurve +open ErdosCriticalGeometry ErdosImplicitCurvature ErdosLocalFiberGraphs ErdosMarkedStrips + +theorem exists_algebraic_marks (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) (S : ℝ) : + ∃ E : Finset ℝ, 0 ∈ E ∧ S ∈ E ∧ E.card ≤ 14*Q.totalDegree^2 ∧ + (∀ t ∈ E, verticalPolynomial Q t ≠ 0) ∧ RegularOff Q S E := by + classical + obtain ⟨B,hB,hbad⟩ := exists_bad_abscissae Q hQ hdeg + obtain ⟨hf0,hc0⟩ := boundary_abscissae_bound Q hQ hdeg 0 + obtain ⟨hfS,hcS⟩ := boundary_abscissae_bound Q hQ hdeg S + let E := B ∪ hf0.toFinset ∪ hfS.toFinset ∪ {0,S} + have hBE : B ⊆ E := fun x hx => Finset.mem_union_left _ + (Finset.mem_union_left _ (Finset.mem_union_left _ hx)) + have h0E : hf0.toFinset ⊆ E := fun x hx => Finset.mem_union_left _ + (Finset.mem_union_left _ (Finset.mem_union_right _ hx)) + have hSE : hfS.toFinset ⊆ E := fun x hx => Finset.mem_union_left _ (Finset.mem_union_right _ hx) + have hsize : E.card ≤ B.card+hf0.toFinset.card+hfS.toFinset.card+2 := by + calc + _ ≤ (B ∪ hf0.toFinset ∪ hfS.toFinset).card+({0,S} : Finset ℝ).card := Finset.card_union_le _ _ + _ ≤ ((B ∪ hf0.toFinset).card+hfS.toFinset.card)+2 := + Nat.add_le_add (Finset.card_union_le _ _) (Finset.card_le_two) + _ ≤ _ := Nat.add_le_add_right (Nat.add_le_add_right (Finset.card_union_le _ _) _) _ + have h0card : hf0.toFinset.card ≤ 2*Q.totalDegree := by rwa [← ncard_eq_toFinset_card _ hf0] + have hScard : hfS.toFinset.card ≤ 2*Q.totalDegree := by rwa [← ncard_eq_toFinset_card _ hfS] + refine ⟨E,?_,?_,?_,(fun t _ => real_vertical_nonzero Q hQ hdeg t),?_⟩ + · exact Finset.mem_union_right _ (by simp) + · exact Finset.mem_union_right _ (by simp) + · have hn : 10*Q.totalDegree^2+4*Q.totalDegree+2 ≤ 14*Q.totalDegree^2 := by nlinarith + omega + · intro t ht + have hnotB : t ∉ B := fun h => ht (hBE h) + refine ⟨⟨?_,?_⟩,?_⟩ + · exact fun hz => ht (h0E (hf0.mem_toFinset.mpr hz)) + · exact fun hz => ht (hSE (hfS.mem_toFinset.mpr hz)) + · exact fun y _ hy => hbad t hnotB y hy + +end ErdosAlgebraicCurve + +end + +section + +namespace ErdosAlgebraicCurve +open ErdosCriticalGeometry ErdosImplicitCurvature ErdosMarkedStrips + +theorem absolutely_irreducible_curve_lattice_bound (Q : MV ℝ) + (hQ : Irreducible (complexify Q)) (hdeg : 1 < Q.totalDegree) + (S : ℝ) (hS : 0 ≤ S) : + ((polynomialSquarePoints Q S).card : ℝ) ≤ + 182*(Q.totalDegree : ℝ)^3*(1+S^((2 : ℝ)/3)) := by + obtain ⟨E,h0,hSE,hcard,hfiber,hregular⟩ := exists_algebraic_marks Q hQ hdeg S + have h := marked_square_cubic_bound Q S E 14 hS h0 hSE hfiber hregular hcard + norm_num only [Nat.cast_ofNat] at h + linarith only [h] + +end ErdosAlgebraicCurve + +end + +section + +open Set +namespace ErdosComplexCurveFactors +open ErdosCriticalGeometry ErdosImplicitCurvature ErdosDivisibleInflection ErdosMarkedStrips ErdosConvexGraph +attribute [local instance] Classical.propDecidable + +noncomputable def complexSquarePoints (F : MV ℂ) (S : ℝ) : Finset (ℤ × ℤ) := + ((Finset.Icc (0 : ℤ) ⌊S⌋).product (Finset.Icc (0 : ℤ) ⌊S⌋)).filter + (fun p => MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0) + +theorem mem_complexSquarePoints (F : MV ℂ) (S : ℝ) (p : ℤ × ℤ) : + p ∈ complexSquarePoints F S ↔ InSquare S p ∧ + MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] F = 0 := by + simp only [complexSquarePoints,InSquare,Finset.mem_filter,Finset.product_eq_sprod, + Finset.mem_product,Finset.mem_Icc,Int.le_floor,Int.cast_nonneg_iff] + +theorem scalar_totalDegree (a : ℂ) (ha : a ≠ 0) (F : MV ℂ) : + (MvPolynomial.C a * F).totalDegree = F.totalDegree := by + have hs : (MvPolynomial.C a * F).support = F.support := by + ext m + simp only [MvPolynomial.mem_support_iff,MvPolynomial.coeff_C_mul,mul_ne_zero_iff] + exact ⟨fun h => h.2,fun h => ⟨ha,h⟩⟩ + unfold MvPolynomial.totalDegree + rw [hs] + +theorem complexSquare_scalar (a : ℂ) (ha : a ≠ 0) (F : MV ℂ) (S : ℝ) : + complexSquarePoints (MvPolynomial.C a * F) S = complexSquarePoints F S := by + ext p + simp only [mem_complexSquarePoints,map_mul,MvPolynomial.eval_C,mul_eq_zero,ha,false_or] + +theorem eval_complexify_int (R : MV ℝ) (p : ℤ × ℤ) : + MvPolynomial.eval ![(p.1 : ℂ),(p.2 : ℂ)] (complexify R) = (peval R p.1 p.2 : ℂ) := by + simpa only [Complex.ofReal_intCast,peval_eq_eval_pair] using complexify_eval R p.1 p.2 + +theorem complexSquare_complexify (R : MV ℝ) (S : ℝ) : + complexSquarePoints (complexify R) S = polynomialSquarePoints R S := by + ext p + simp only [mem_complexSquarePoints,mem_polynomialSquarePoints,eval_complexify_int,Complex.ofReal_eq_zero] + +theorem scalar_irreducible_iff (a : ℂ) (ha : a ≠ 0) (F : MV ℂ) : + Irreducible (MvPolynomial.C a * F) ↔ Irreducible F := + irreducible_isUnit_mul ((isUnit_iff_ne_zero.mpr ha).map MvPolynomial.C) + +def complexIntPoint (p : ℤ × ℤ) : ℂ × ℂ := ((p.1 : ℂ),(p.2 : ℂ)) + +theorem complexIntPoint_injective : Function.Injective complexIntPoint := by + intro p q hpq + have h1 : (p.1 : ℂ) = (q.1 : ℂ) := congrArg Prod.fst hpq + have h2 : (p.2 : ℂ) = (q.2 : ℂ) := congrArg Prod.snd hpq + exact Prod.ext (by exact_mod_cast h1) (by exact_mod_cast h2) + +end ErdosComplexCurveFactors + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/FourierDerivative.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/FourierDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..9927b129315cc92cbe6614b025f3b51e2f614b28 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/FourierDerivative.lean @@ -0,0 +1,200 @@ +import Mathlib.Analysis.Fourier.AddCircle +import Mathlib.Analysis.InnerProductSpace.Calculus +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.SeparatedSampling + +namespace OAI + +namespace Erdos970 + +section + +open MeasureTheory Set Complex +open scoped BigOperators ComplexConjugate + +namespace AdditiveLargeSieve + +noncomputable def monomial (n : ℤ) (x : ℝ) : ℂ := fourier n (x : AddCircle (1 : ℝ)) +noncomputable def polynomial (s : Finset ℤ) (b : ℤ → ℂ) (x : ℝ) : ℂ := + ∑ n ∈ s, b n * monomial n x + +theorem monomial_continuous (n : ℤ) : Continuous (monomial n) := + (fourier n).continuous.comp (AddCircle.continuous_mk' 1) + +theorem polynomial_continuous (s : Finset ℤ) (b : ℤ → ℂ) : Continuous (polynomial s b) := by + apply continuous_finsetSum + intro n _ + exact continuous_const.mul (monomial_continuous n) + +theorem unit_monomial_integral (n : ℤ) (a : ℝ) : + (∫ x in a..a + 1, monomial n x) = if n = 0 then 1 else 0 := by + have h := congrFun (fourierCoeff_fourier (T := (1 : ℝ)) n) 0 + rw [fourierCoeff_eq_intervalIntegral _ _ a] at h + simpa [monomial, Pi.single_apply, eq_comm] using h + +theorem monomial_conj_mul (n m : ℤ) (x : ℝ) : + conj (monomial n x) * monomial m x = monomial (m - n) x := by + simp only [monomial, ← fourier_neg, ← fourier_add] + congr 2 + omega + +theorem polynomial_square_expansion (s : Finset ℤ) (b : ℤ → ℂ) (x : ℝ) : + conj (polynomial s b x) * polynomial s b x = + ∑ n ∈ s, ∑ m ∈ s, (conj (b n) * b m) * monomial (m - n) x := by + simp only [polynomial, map_sum, map_mul, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro n _ + apply Finset.sum_congr rfl + intro m _ + rw [← monomial_conj_mul] + ring + +theorem polynomial_energy (s : Finset ℤ) (b : ℤ → ℂ) (a : ℝ) : + (∫ x in a..a + 1, ‖polynomial s b x‖ ^ 2) = ∑ n ∈ s, ‖b n‖ ^ 2 := by + have h : (∫ x in a..a + 1, conj (polynomial s b x) * polynomial s b x) = + ∑ n ∈ s, conj (b n) * b n := by + simp_rw [polynomial_square_expansion] + rw [intervalIntegral.integral_finsetSum] + · apply Finset.sum_congr rfl + intro n hn + rw [intervalIntegral.integral_finsetSum] + · simp_rw [intervalIntegral.integral_const_mul, unit_monomial_integral] + simp [sub_eq_zero, hn] + · intro m _ + exact (continuous_const.mul (monomial_continuous _)).intervalIntegrable _ _ + · intro n _ + apply Continuous.intervalIntegrable + exact continuous_finsetSum _ fun m _ => continuous_const.mul (monomial_continuous _) + apply Complex.ofReal_injective + rw [← intervalIntegral.integral_ofReal] + simpa only [← Complex.normSq_eq_norm_sq, Complex.normSq_eq_conj_mul_self, + Complex.ofReal_sum] using h + +theorem polynomial_energy_two (s : Finset ℤ) (b : ℤ → ℂ) : + (∫ x in (0 : ℝ)..2, ‖polynomial s b x‖ ^ 2) = 2 * ∑ n ∈ s, ‖b n‖ ^ 2 := by + have hc := (polynomial_continuous s b).norm.pow 2 + have hsum := intervalIntegral.integral_add_adjacent_intervals (μ := volume) + (hc.intervalIntegrable 0 1) (hc.intervalIntegrable 1 2) + simp only [Pi.pow_apply] at hsum + have h0 := polynomial_energy s b 0 + have h1 := polynomial_energy s b 1 + norm_num only [zero_add, one_add_one_eq_two] at h0 h1 + linarith + +end AdditiveLargeSieve + +end + +section + +open MeasureTheory Set Complex +open scoped BigOperators ComplexConjugate RealInnerProductSpace + +namespace AdditiveLargeSieve + +noncomputable def derivativeCoefficients (b : ℤ → ℂ) (n : ℤ) : ℂ := + (2 * Real.pi * I * n) * b n + +theorem polynomial_hasDerivAt (s : Finset ℤ) (b : ℤ → ℂ) (x : ℝ) : + HasDerivAt (polynomial s b) (polynomial s (derivativeCoefficients b) x) x := by + have h := HasDerivAt.fun_sum (u := s) fun n _ => + (hasDerivAt_fourier (1 : ℝ) n x).const_mul (b n) + convert! h using 1 + simp only [polynomial, derivativeCoefficients, Complex.ofReal_one, div_one, monomial] + apply Finset.sum_congr rfl + intro n _ + ring + +theorem derivative_coefficient_norm (b : ℤ → ℂ) (n : ℤ) : + ‖derivativeCoefficients b n‖ = 2 * Real.pi * |(n : ℝ)| * ‖b n‖ := by + simp [derivativeCoefficients, Complex.norm_intCast] + +theorem derivative_energy_le (s : Finset ℤ) (b : ℤ → ℂ) {R : ℝ} (hR : 0 < R) + (hfreq : ∀ n ∈ s, |(n : ℝ)| ≤ R) : + (∫ x in (0 : ℝ)..2, ‖polynomial s (derivativeCoefficients b) x‖ ^ 2) ≤ + 2 * (2 * Real.pi * R) ^ 2 * ∑ n ∈ s, ‖b n‖ ^ 2 := by + rw [polynomial_energy_two, mul_assoc] + apply mul_le_mul_of_nonneg_left _ (by norm_num : (0 : ℝ) ≤ 2) + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro n hn + rw [derivative_coefficient_norm] + have h : 2 * Real.pi * |(n : ℝ)| * ‖b n‖ ≤ 2 * Real.pi * R * ‖b n‖ := by + gcongr + exact hfreq n hn + have hnonneg : 0 ≤ 2 * Real.pi * |(n : ℝ)| * ‖b n‖ := by positivity + have hnonneg' : 0 ≤ 2 * Real.pi * R * ‖b n‖ := by positivity + nlinarith [sq_le_sq₀ hnonneg hnonneg' |>.2 h] + +theorem norm_square_derivative_bound (z w : ℂ) {R : ℝ} (hR : 0 < R) : + |2 * inner ℝ z w| ≤ R * ‖z‖ ^ 2 + R⁻¹ * ‖w‖ ^ 2 := by + calc + |2 * inner ℝ z w| = 2 * |inner ℝ z w| := by rw [abs_mul]; norm_num + _ ≤ 2 * (‖z‖ * ‖w‖) := mul_le_mul_of_nonneg_left (abs_real_inner_le_norm z w) (by norm_num) + _ ≤ _ := by + apply (mul_le_mul_iff_right₀ hR).mp + field_simp + nlinarith [sq_nonneg (R * ‖z‖ - ‖w‖)] + +theorem separated_polynomial_bound {ι : Type*} (samples : Finset ι) (t : ι → ℝ) + (s : Finset ℤ) (b : ℤ → ℂ) {R δ : ℝ} (hR : 0 < R) (hδ : 0 < δ) (hδ1 : δ ≤ 1) + (hpoints : ∀ i ∈ samples, t i ∈ Icc (0 : ℝ) 1) + (hsep : ∀ i ∈ samples, ∀ j ∈ samples, i ≠ j → δ ≤ |t i - t j|) + (hfreq : ∀ n ∈ s, |(n : ℝ)| ≤ R) : + (∑ i ∈ samples, ‖polynomial s b (t i)‖ ^ 2) ≤ + (4 + 8 * Real.pi ^ 2) * (R + δ⁻¹) * ∑ n ∈ s, ‖b n‖ ^ 2 := by + let F := polynomial s b + let D := polynomial s (derivativeCoefficients b) + have hF : Continuous F := polynomial_continuous s b + have hD : Continuous D := polynomial_continuous s _ + have hsample := separated_sampling samples t hδ (by norm_num : (0 : ℝ) ≤ 2) + (fun i hi => ⟨(hpoints i hi).1, by linarith [(hpoints i hi).2]⟩) hsep + (hF.norm.pow 2) ((continuous_const.mul (hF.inner hD)) : Continuous (fun x => 2 * inner ℝ (F x) (D x))) + (fun x => (polynomial_hasDerivAt s b x).norm_sq) (fun x => sq_nonneg ‖F x‖) + have hderiv : (∫ x in (0 : ℝ)..2, |2 * inner ℝ (F x) (D x)|) ≤ + R * (∫ x in (0 : ℝ)..2, ‖F x‖ ^ 2) + R⁻¹ * (∫ x in (0 : ℝ)..2, ‖D x‖ ^ 2) := by + have h := intervalIntegral.integral_mono (μ := volume) (by norm_num : (0 : ℝ) ≤ 2) + ((continuous_const.mul (hF.inner hD)).abs.intervalIntegrable 0 2) + (((continuous_const.mul (hF.norm.pow 2)).add + (continuous_const.mul (hD.norm.pow 2))).intervalIntegrable 0 2) + (fun x => norm_square_derivative_bound (F x) (D x) hR) + have hiF : IntervalIntegrable (fun x => R * ‖F x‖ ^ 2) volume 0 2 := + (continuous_const.mul (hF.norm.pow 2)).intervalIntegrable _ _ + have hiD : IntervalIntegrable (fun x => R⁻¹ * ‖D x‖ ^ 2) volume 0 2 := + (continuous_const.mul (hD.norm.pow 2)).intervalIntegrable _ _ + simp only [Pi.add_apply, Pi.mul_apply, Pi.pow_apply] at h + rw [intervalIntegral.integral_add hiF hiD, + intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at h + exact h + have hE : (∫ x in (0 : ℝ)..2, ‖F x‖ ^ 2) = 2 * ∑ n ∈ s, ‖b n‖ ^ 2 := polynomial_energy_two s b + have hDE := derivative_energy_le s b hR hfreq + have hEpos : 0 ≤ ∑ n ∈ s, ‖b n‖ ^ 2 := Finset.sum_nonneg fun n _ => sq_nonneg _ + simp only [Pi.pow_apply, Pi.mul_apply] at hsample + have hfinal := hsample.trans (add_le_add le_rfl hderiv) + rw [hE] at hfinal + have hbound := mul_le_mul_of_nonneg_left hDE (inv_nonneg.mpr hR.le) + have halgebra : δ⁻¹ * (2 * ∑ n ∈ s, ‖b n‖ ^ 2) + + (R * (2 * ∑ n ∈ s, ‖b n‖ ^ 2) + R⁻¹ * + (2 * (2 * Real.pi * R) ^ 2 * ∑ n ∈ s, ‖b n‖ ^ 2)) = + (2 * δ⁻¹ + (2 + 8 * Real.pi ^ 2) * R) * ∑ n ∈ s, ‖b n‖ ^ 2 := by + field_simp + ring + have hc : 2 * δ⁻¹ + (2 + 8 * Real.pi ^ 2) * R ≤ + (4 + 8 * Real.pi ^ 2) * (R + δ⁻¹) := by + have := mul_nonneg (sq_nonneg Real.pi) (inv_nonneg.mpr hδ.le) + have := inv_nonneg.mpr hδ.le + nlinarith + have hjoin : (∑ i ∈ samples, ‖F (t i)‖ ^ 2) ≤ + (2 * δ⁻¹ + (2 + 8 * Real.pi ^ 2) * R) * ∑ n ∈ s, ‖b n‖ ^ 2 := by + rw [← halgebra] + exact hfinal.trans (add_le_add le_rfl (add_le_add le_rfl hbound)) + exact hjoin.trans (mul_le_mul_of_nonneg_right hc hEpos) + +end AdditiveLargeSieve + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/FourierL1.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/FourierL1.lean new file mode 100644 index 0000000000000000000000000000000000000000..c052e8529dcf74439089bd5db8f316c41017cc6d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/FourierL1.lean @@ -0,0 +1,79 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UnitCyclicBounds +import OAI.NumberTheory.Jacobsthal.Partitions.IntervalHyperbolaAdapter + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators + +namespace ErdosHyperbola + +open ErdosHyperbolaFourier +attribute [local instance] Classical.decEq + +theorem intervalWeight_l1 (N : ℕ) [NeZero N] (x y : ℝ) (lc rc : Bool) + (T : ℕ) (a : ℤ) (hT : 0 < T) (hTN : T.Coprime N) : + (∑ h ∈ (Finset.univ : Finset (ZMod N)).filter (· ≠ 0), + ‖intervalWeight N h x y lc rc T a‖) ≤ + (2*harmonicConstant)*(N : ℝ)*Real.log (2*(N : ℝ)) := by + have hu : IsUnit (-(T : ZMod N)) := ((ZMod.isUnit_iff_coprime T N).mpr hTN).neg + obtain ⟨u,hu⟩ := hu + have he (h : ZMod N) : h*(u : ZMod N) = -h*(T : ZMod N) := by rw [hu]; ring + calc + _ ≤ ∑ h ∈ (Finset.univ : Finset (ZMod N)).filter (· ≠ 0), + (N : ℝ)/(cyclicDistance N (h*(u : ZMod N)) : ℝ) := by + apply Finset.sum_le_sum + intro h hh + rw [he] + exact norm_intervalWeight_le_of_coprime N h (Finset.mem_filter.mp hh).2 x y lc rc T a hT hTN + _ ≤ ∑ h : ZMod N,(N : ℝ)/(cyclicDistance N (h*(u : ZMod N)) : ℝ) := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun _ _ _ => by positivity) + _ = (N : ℝ)*∑ h : ZMod N,1/(cyclicDistance N (h*(u : ZMod N)) : ℝ) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro h _ + ring + _ ≤ (N : ℝ)*((2*harmonicConstant)*Real.log (2*(N : ℝ))) := + mul_le_mul_of_nonneg_left (unit_cyclic_inverse_sum_le N u) (Nat.cast_nonneg _) + _ = _ := by ring + +theorem intervalWeight_gcd_l1 (N : ℕ) [NeZero N] (x y : ℝ) (lc rc : Bool) + (T : ℕ) (a : ℤ) (hT : 0 < T) (hTN : T.Coprime N) : + (∑ h ∈ (Finset.univ : Finset (ZMod N)).filter (· ≠ 0), + ‖intervalWeight N h x y lc rc T a‖*Real.sqrt (Nat.gcd h.val N)) ≤ + (2*harmonicConstant)*(N : ℝ)*(N.divisors.card : ℝ)*Real.log (2*(N : ℝ)) := by + have hu : IsUnit (-(T : ZMod N)) := ((ZMod.isUnit_iff_coprime T N).mpr hTN).neg + obtain ⟨u,hu⟩ := hu + have he (h : ZMod N) : h*(u : ZMod N) = -h*(T : ZMod N) := by rw [hu]; ring + calc + _ ≤ ∑ h ∈ (Finset.univ : Finset (ZMod N)).filter (· ≠ 0), + ((N : ℝ)/(cyclicDistance N (h*(u : ZMod N)) : ℝ))*Real.sqrt (Nat.gcd h.val N) := by + apply Finset.sum_le_sum + intro h hh + rw [he] + exact mul_le_mul_of_nonneg_right + (norm_intervalWeight_le_of_coprime N h (Finset.mem_filter.mp hh).2 x y lc rc T a hT hTN) + (Real.sqrt_nonneg _) + _ ≤ ∑ h : ZMod N, + ((N : ℝ)/(cyclicDistance N (h*(u : ZMod N)) : ℝ))*Real.sqrt (Nat.gcd h.val N) := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun _ _ _ => by positivity) + _ = (N : ℝ)*∑ h : ZMod N,Real.sqrt (Nat.gcd h.val N)/ + (cyclicDistance N (h*(u : ZMod N)) : ℝ) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro h _ + ring + _ ≤ (N : ℝ)*((2*harmonicConstant)*(N.divisors.card : ℝ)*Real.log (2*(N : ℝ))) := + mul_le_mul_of_nonneg_left (unit_sqrt_gcd_cyclic_sum_le N u) (Nat.cast_nonneg _) + _ = _ := by ring + +end ErdosHyperbola + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/HyperbolaFourier.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/HyperbolaFourier.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd041e0fb4f0d6882233912df13b3cde6cb9b30b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/HyperbolaFourier.lean @@ -0,0 +1,110 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.PairFibreEnumeration + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosHyperbolaIdentities + +attribute [local instance] Classical.decEq + +theorem integerWeight_orthogonality (N : ℕ) [NeZero N] (I : Finset ℤ) (u : ZMod N) : + (∑ h : ZMod N, integerWeight N I h * ZMod.stdAddChar (h*u)) = + (N : ℂ) * (integerFibre N I u).card := by + unfold integerWeight + simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + have hterm (h : ZMod N) (x : ℤ) : + ZMod.stdAddChar (-h*(x : ZMod N)) * ZMod.stdAddChar (h*u) = + ZMod.stdAddChar (h*(u-(x : ZMod N))) := by + rw [← AddChar.map_add_eq_mul] + congr 1 + ring + simp_rw [hterm, AddChar.sum_mulShift _ (ZMod.isPrimitive_stdAddChar N)] + have he (x : ℤ) : u-(x : ZMod N) = 0 ↔ (x : ZMod N) = u := by + rw [sub_eq_zero, eq_comm] + simp_rw [he] + simp only [ZMod.card, apply_ite, Nat.cast_zero] + rw [← Finset.sum_filter] + simp only [Finset.sum_const, nsmul_eq_mul, integerFibre] + ring + +theorem integerWeight_zero (N : ℕ) [NeZero N] (I : Finset ℤ) : + integerWeight N I 0 = I.card := by simp [integerWeight] + +end ErdosHyperbolaIdentities + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaIdentities + +attribute [local instance] Classical.decEq + +theorem double_weighted_kernel (N : ℕ) [NeZero N] (I J : Finset ℤ) (u v : ZMod N) : + (∑ h : ZMod N, ∑ k : ZMod N, + integerWeight N I h * integerWeight N J k * ZMod.stdAddChar (h*u+k*v)) = + (N : ℂ)^2 * (integerFibre N I u).card * (integerFibre N J v).card := by + have he (h k : ZMod N) : + integerWeight N I h * integerWeight N J k * ZMod.stdAddChar (h*u+k*v) = + (integerWeight N I h * ZMod.stdAddChar (h*u)) * + (integerWeight N J k * ZMod.stdAddChar (k*v)) := by + rw [AddChar.map_add_eq_mul] + ring + simp_rw [he] + calc + _ = (∑ h : ZMod N, integerWeight N I h * ZMod.stdAddChar (h*u)) * + (∑ k : ZMod N, integerWeight N J k * ZMod.stdAddChar (k*v)) := by + simp only [Finset.sum_mul, Finset.mul_sum] + exact Finset.sum_comm + _ = _ := by rw [integerWeight_orthogonality, integerWeight_orthogonality]; ring + +theorem double_fourier_scaled (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (I J : Finset ℤ) : + (∑ h : ZMod N, ∑ k : ZMod N, + integerWeight N I h * integerWeight N J k * restrictedSum N T hT a c h k) = + (N : ℂ)^2 * (hyperbolaPairs N T a c I J).card := by + unfold restrictedSum + simp_rw [Finset.mul_sum] + conv_lhs => + arg 2 + ext h + rw [Finset.sum_comm] + rw [Finset.sum_comm] + have hphase (h k : ZMod N) (u : (ZMod N)ˣ) : + ZMod.stdAddChar (h*(u : ZMod N)+k*(c : ZMod N)*(↑u⁻¹ : ZMod N)) = + ZMod.stdAddChar (h*(u : ZMod N)+k*((c : ZMod N)*(↑u⁻¹ : ZMod N))) := by + congr 1 + ring + simp_rw [hphase, double_weighted_kernel] + have hc : ((hyperbolaPairs N T a c I J).card : ℂ) = + (∑ u ∈ unitClass N T hT a, + (integerFibre N I (u : ZMod N)).card * + (integerFibre N J ((c : ZMod N)*(↑u⁻¹ : ZMod N))).card : ℂ) := by + exact_mod_cast hyperbolaPairs_card_eq_fibre_sum N T hT a c I J + rw [hc, Finset.mul_sum] + apply Finset.sum_congr rfl + intro u _ + ring + +theorem count_eq_fourier (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (I J : Finset ℤ) : + ((hyperbolaPairs N T a c I J).card : ℂ) = + (∑ h : ZMod N, ∑ k : ZMod N, + integerWeight N I h * integerWeight N J k * restrictedSum N T hT a c h k)/(N : ℂ)^2 := by + have hN : (N : ℂ)^2 ≠ 0 := pow_ne_zero 2 (by exact_mod_cast NeZero.ne N) + apply (eq_div_iff hN).mpr + simpa only [mul_comm] using (double_fourier_scaled N T hT a c I J).symm + +end ErdosHyperbolaIdentities + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/KloostermanCRTCharacter.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/KloostermanCRTCharacter.lean new file mode 100644 index 0000000000000000000000000000000000000000..e643f99d393640cdbe7bcd3ef9fb9847943ced9d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/KloostermanCRTCharacter.lean @@ -0,0 +1,46 @@ +import Mathlib.Data.Int.GCD +import OAI.NumberTheory.Jacobsthal.Estimates.PairCollisionCount + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman + +theorem stdAddChar_bezout (m n : ℕ) [NeZero m] [NeZero n] + (A B z : ℤ) (hab : (m : ℤ)*A + (n : ℤ)*B = 1) : + ZMod.stdAddChar (z : ZMod (m*n)) = + ZMod.stdAddChar ((B*z : ℤ) : ZMod m) * + ZMod.stdAddChar ((A*z : ℤ) : ZMod n) := by + have hm : (m : ℂ) ≠ 0 := by exact_mod_cast NeZero.ne m + have hn : (n : ℂ) ≠ 0 := by exact_mod_cast NeZero.ne n + have hc : (m : ℂ)*(A : ℂ) + (n : ℂ)*(B : ℂ) = 1 := by exact_mod_cast hab + rw [ZMod.stdAddChar_coe, ZMod.stdAddChar_coe, ZMod.stdAddChar_coe, ← Complex.exp_add] + congr 1 + push_cast + field_simp + linear_combination -(z : ℂ) * hc + +theorem stdAddChar_crt (m n : ℕ) [NeZero m] [NeZero n] (hmn : m.Coprime n) : + (ZMod.stdAddChar : AddChar (ZMod (m*n)) ℂ) = + (productChar + (ZMod.stdAddChar.mulShift (Nat.gcdB m n : ZMod m)) + (ZMod.stdAddChar.mulShift (Nat.gcdA m n : ZMod n))).compAddMonoidHom + (ZMod.chineseRemainder hmn).toAddMonoidHom := by + have hab : (m : ℤ)*Nat.gcdA m n + (n : ℤ)*Nat.gcdB m n = 1 := by + rw [← Nat.gcd_eq_gcd_ab, hmn.gcd_eq_one] + rfl + ext x + obtain ⟨z, rfl⟩ := ZMod.intCast_surjective x + simpa [productChar, AddChar.compAddMonoidHom_apply, AddChar.mulShift_apply, + ← Int.cast_mul] using stdAddChar_bezout m n (Nat.gcdA m n) (Nat.gcdB m n) z hab + +end ErdosKloosterman + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/LinearPolynomialForm.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/LinearPolynomialForm.lean new file mode 100644 index 0000000000000000000000000000000000000000..dffa05b158adb45c1f138797e03bece66c715fda --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/LinearPolynomialForm.lean @@ -0,0 +1,77 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RichLinearFactor + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRichLine +open ErdosCriticalGeometry + +theorem exponent_sum_le_one_cases (m : Fin 2 →₀ ℕ) (hm : m.sum (fun _ n => n) ≤ 1) : + m = 0 ∨ m = Finsupp.single 0 1 ∨ m = Finsupp.single 1 1 := by + have hs : m 0+m 1 ≤ 1 := by + have he : m.sum (fun _ n => n) = m 0+m 1 := by + rw [Finsupp.sum_fintype _ _ (fun _ => rfl)] + exact Fin.sum_univ_two _ + rwa [he] at hm + by_cases h0 : m 0 = 0 + · by_cases h1 : m 1 = 0 + · left + ext i + fin_cases i <;> simp [h0,h1] + · right;right + have h1' : m 1 = 1 := by omega + ext i + fin_cases i <;> simp [h0,h1'] + · right;left + have h0' : m 0 = 1 := by omega + have h1 : m 1 = 0 := by omega + ext i + fin_cases i <;> simp [h0',h1] + +theorem linear_polynomial_form (F : MV ℂ) (hdeg : F.totalDegree ≤ 1) : + F = MvPolynomial.C (F.coeff 0)+ + MvPolynomial.C (F.coeff (Finsupp.single 0 1))*MvPolynomial.X 0+ + MvPolynomial.C (F.coeff (Finsupp.single 1 1))*MvPolynomial.X 1 := by + classical + have he0 : (Finsupp.single (0 : Fin 2) 1 : Fin 2 →₀ ℕ) ≠ 0 := by + intro h + have hh := congrArg (fun m : Fin 2 →₀ ℕ => m 0) h + simp at hh + have he1 : (Finsupp.single (1 : Fin 2) 1 : Fin 2 →₀ ℕ) ≠ 0 := by + intro h + have hh := congrArg (fun m : Fin 2 →₀ ℕ => m 1) h + simp at hh + have he01 : (Finsupp.single (0 : Fin 2) 1 : Fin 2 →₀ ℕ) ≠ Finsupp.single 1 1 := by + intro h + have hh := congrArg (fun m : Fin 2 →₀ ℕ => m 0) h + simp at hh + ext m + by_cases hm : m.sum (fun _ n => n) ≤ 1 + · rcases exponent_sum_le_one_cases m hm with rfl | rfl | rfl <;> + simp [MvPolynomial.coeff_C_mul,MvPolynomial.coeff_C, + MvPolynomial.coeff_X,he0,he1,he01,Ne.symm he0,Ne.symm he1,Ne.symm he01] + · have hm0 : m ≠ 0 := by rintro rfl; simp at hm + have hm1 : m ≠ Finsupp.single 0 1 := by rintro rfl; simp at hm + have hm2 : m ≠ Finsupp.single 1 1 := by rintro rfl; simp at hm + have hc : F.coeff m = 0 := by + by_contra hn + exact hm ((MvPolynomial.le_totalDegree (MvPolynomial.mem_support_iff.mpr hn)).trans hdeg) + simp [MvPolynomial.coeff_C_mul,MvPolynomial.coeff_C, + MvPolynomial.coeff_X,Ne.symm hm0,Ne.symm hm1,Ne.symm hm2,hc] + +theorem linear_polynomial_eval (F : MV ℂ) (hdeg : F.totalDegree ≤ 1) (x y : ℂ) : + MvPolynomial.eval ![x,y] F = F.coeff 0+F.coeff (Finsupp.single 0 1)*x+ + F.coeff (Finsupp.single 1 1)*y := by + conv_lhs => rw [linear_polynomial_form F hdeg] + simp + +end ErdosRichLine + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/NormalizedSpectralError.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/NormalizedSpectralError.lean new file mode 100644 index 0000000000000000000000000000000000000000..631c28d27fb58d6e605c6ee7e6bd57f92ea3f21d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/NormalizedSpectralError.lean @@ -0,0 +1,182 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ScalarErrorBudget + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosHyperbolaError + +theorem sum_zero_add_nonzero (N : ℕ) [NeZero N] (f : ZMod N → ℂ) : + (∑ h : ZMod N, f h) = f 0 + ∑ h ∈ nonzeroFrequencies N, f h := by + have he : nonzeroFrequencies N = (Finset.univ : Finset (ZMod N)).erase 0 := by + ext h + simp [nonzeroFrequencies] + rw [he] + exact (Finset.add_sum_erase Finset.univ f (Finset.mem_univ 0)).symm + +theorem double_sum_decomposition (N : ℕ) [NeZero N] (F : ZMod N → ZMod N → ℂ) : + (∑ h : ZMod N, ∑ k : ZMod N, F h k) = + F 0 0 + (∑ h ∈ nonzeroFrequencies N, F h 0) + + (∑ k ∈ nonzeroFrequencies N, F 0 k) + + ∑ h ∈ nonzeroFrequencies N, ∑ k ∈ nonzeroFrequencies N, F h k := by + rw [sum_zero_add_nonzero N (fun h => ∑ k : ZMod N, F h k), sum_zero_add_nonzero N (F 0)] + simp_rw [sum_zero_add_nonzero N] + rw [Finset.sum_add_distrib] + ring + +theorem double_remainder_norm_le (N : ℕ) [NeZero N] (F : ZMod N → ZMod N → ℂ) : + ‖(∑ h : ZMod N, ∑ k : ZMod N, F h k)-F 0 0‖ ≤ + (∑ h ∈ nonzeroFrequencies N, ‖F h 0‖) + + (∑ k ∈ nonzeroFrequencies N, ‖F 0 k‖) + + ∑ h ∈ nonzeroFrequencies N, ∑ k ∈ nonzeroFrequencies N, ‖F h k‖ := by + let X := ∑ h ∈ nonzeroFrequencies N, F h 0 + let Y := ∑ k ∈ nonzeroFrequencies N, F 0 k + let Z := ∑ h ∈ nonzeroFrequencies N, ∑ k ∈ nonzeroFrequencies N, F h k + rw [double_sum_decomposition] + change ‖F 0 0+X+Y+Z-F 0 0‖ ≤ _ + rw [show F 0 0+X+Y+Z-F 0 0 = X+Y+Z by ring] + have hX : ‖X‖ ≤ ∑ h ∈ nonzeroFrequencies N, ‖F h 0‖ := norm_sum_le _ _ + have hY : ‖Y‖ ≤ ∑ k ∈ nonzeroFrequencies N, ‖F 0 k‖ := norm_sum_le _ _ + have hZ : ‖Z‖ ≤ ∑ h ∈ nonzeroFrequencies N, ∑ k ∈ nonzeroFrequencies N, ‖F h k‖ := by + exact (norm_sum_le _ _).trans (Finset.sum_le_sum (fun h _ => norm_sum_le _ _)) + calc + _ ≤ ‖X+Y‖+‖Z‖ := norm_add_le _ _ + _ ≤ ‖X‖+‖Y‖+‖Z‖ := add_le_add (norm_add_le X Y) le_rfl + _ ≤ _ := add_le_add (add_le_add hX hY) hZ + +end ErdosHyperbolaError + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +noncomputable def spectralTerm (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) + (h k : ZMod (H*T)) : ℂ := + P.weight (H*T) h * Q.weight (H*T) k * restrictedSum (H*T) T (dvd_mul_left T H) a c h k + +theorem spectral_remainder_bound (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) : + ‖(∑ h : ZMod (H*T), ∑ k : ZMod (H*T), spectralTerm H T a c P Q h k)- + spectralTerm H T a c P Q 0 0‖ ≤ + ‖Q.weight (H*T) 0‖ * completeScale (H*T) * Real.sqrt T * gcdL1Norm (H*T) P + + ‖P.weight (H*T) 0‖ * completeScale (H*T) * gcdL1Norm (H*T) Q + + completeScale (H*T) * l1Norm (H*T) P * gcdL1Norm (H*T) Q := by + have hleft : (∑ h ∈ nonzeroFrequencies (H*T), ‖spectralTerm H T a c P Q h 0‖) ≤ + ‖Q.weight (H*T) 0‖ * completeScale (H*T) * Real.sqrt T * gcdL1Norm (H*T) P := by + unfold gcdL1Norm + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro h _ + rw [spectralTerm, norm_mul, norm_mul] + calc + _ ≤ (‖P.weight (H*T) h‖*‖Q.weight (H*T) 0‖) * + (completeScale (H*T)*Real.sqrt T*Real.sqrt (Nat.gcd h.val (H*T))) := + mul_le_mul_of_nonneg_left (restrictedSum_norm_le_first H T a c h 0) (by positivity) + _ = _ := by ring + have hright : (∑ k ∈ nonzeroFrequencies (H*T), ‖spectralTerm H T a c P Q 0 k‖) ≤ + ‖P.weight (H*T) 0‖ * completeScale (H*T) * gcdL1Norm (H*T) Q := by + unfold gcdL1Norm + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro k _ + rw [spectralTerm, norm_mul, norm_mul] + calc + _ ≤ (‖P.weight (H*T) 0‖*‖Q.weight (H*T) k‖) * + (completeScale (H*T)*Real.sqrt (Nat.gcd k.val (H*T))) := + mul_le_mul_of_nonneg_left (restrictedSum_norm_le_second H T a c 0 k) (by positivity) + _ = _ := by ring + have hboth : (∑ h ∈ nonzeroFrequencies (H*T), ∑ k ∈ nonzeroFrequencies (H*T), + ‖spectralTerm H T a c P Q h k‖) ≤ + completeScale (H*T)*l1Norm (H*T) P*gcdL1Norm (H*T) Q := by + have hp (h k : ZMod (H*T)) : ‖spectralTerm H T a c P Q h k‖ ≤ + completeScale (H*T)*‖P.weight (H*T) h‖ * + (‖Q.weight (H*T) k‖*Real.sqrt (Nat.gcd k.val (H*T))) := by + rw [spectralTerm, norm_mul, norm_mul] + calc + _ ≤ (‖P.weight (H*T) h‖*‖Q.weight (H*T) k‖) * + (completeScale (H*T)*Real.sqrt (Nat.gcd k.val (H*T))) := + mul_le_mul_of_nonneg_left (restrictedSum_norm_le_second H T a c h k) (by positivity) + _ = _ := by ring + calc + _ ≤ ∑ h ∈ nonzeroFrequencies (H*T), ∑ k ∈ nonzeroFrequencies (H*T), + completeScale (H*T)*‖P.weight (H*T) h‖ * + (‖Q.weight (H*T) k‖*Real.sqrt (Nat.gcd k.val (H*T))) := + Finset.sum_le_sum (fun h _ => Finset.sum_le_sum (fun k _ => hp h k)) + _ = _ := by + unfold l1Norm gcdL1Norm + simp only [Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + exact (double_remainder_norm_le (H*T) (spectralTerm H T a c P Q)).trans + (add_le_add (add_le_add hleft hright) hboth) + +end ErdosHyperbolaError + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +theorem normalized_spectral_error (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) (P Q : ProgressionInterval) + (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) + (hPN : P.step.Coprime (H*T)) (hQN : Q.step.Coprime (H*T)) : + ‖(∑ h : ZMod (H*T), ∑ k : ZMod (H*T), spectralTerm H T a c P Q h k)- + spectralTerm H T a c P Q 0 0‖/((H*T : ℕ) : ℝ)^2 ≤ + 8*errorBase (H*T) T*(1+intervalLength P/((H*T : ℕ) : ℝ)+intervalLength Q/((H*T : ℕ) : ℝ)) := by + have hD := completeScale_nonneg (H*T) + have hs := Real.sqrt_nonneg (T : ℝ) + have ht : 0 ≤ logFactor (H*T) := le_trans (by norm_num) (logFactor_one_le (H*T)) + have hU := intervalLength_nonneg P hP + have hV := intervalLength_nonneg Q hQ + have hA0 := norm_weight_zero_le (H*T) P hP + have hB0 := norm_weight_zero_le (H*T) Q hQ + have hA := l1Norm_le_logFactor (H*T) P hPN + have hAg := gcdL1Norm_le_logFactor (H*T) P hPN + have hBg := gcdL1Norm_le_logFactor (H*T) Q hQN + have hAg0 := gcdL1Norm_nonneg (H*T) P + have hBg0 := gcdL1Norm_nonneg (H*T) Q + have hApos := l1Norm_nonneg (H*T) P + have hnum : ‖(∑ h : ZMod (H*T), ∑ k : ZMod (H*T), spectralTerm H T a c P Q h k)- + spectralTerm H T a c P Q 0 0‖ ≤ + completeScale (H*T)* + ((2*((H*T : ℕ) : ℝ)*((H*T).divisors.card : ℝ)*logFactor (H*T))*(intervalLength P+1)+ + Real.sqrt T*(2*((H*T : ℕ) : ℝ)*((H*T).divisors.card : ℝ)*logFactor (H*T))*(intervalLength Q+1)+ + (2*((H*T : ℕ) : ℝ)*logFactor (H*T))* + (2*((H*T : ℕ) : ℝ)*((H*T).divisors.card : ℝ)*logFactor (H*T))) := by + calc + _ ≤ _ := spectral_remainder_bound H T a c P Q + _ ≤ (intervalLength Q+1)*completeScale (H*T)*Real.sqrt T* + (2*((H*T : ℕ) : ℝ)*((H*T).divisors.card : ℝ)*logFactor (H*T))+ + (intervalLength P+1)*completeScale (H*T)* + (2*((H*T : ℕ) : ℝ)*((H*T).divisors.card : ℝ)*logFactor (H*T))+ + completeScale (H*T)*(2*((H*T : ℕ) : ℝ)*logFactor (H*T))* + (2*((H*T : ℕ) : ℝ)*((H*T).divisors.card : ℝ)*logFactor (H*T)) := by + gcongr + _ = _ := by ring + calc + _ ≤ _ := div_le_div_of_nonneg_right hnum (sq_nonneg _) + _ ≤ _ := axis_quadrant_budget (completeScale (H*T)) ((H*T).divisors.card : ℝ) + (Real.sqrt T) (logFactor (H*T)) ((H*T : ℕ) : ℝ) (intervalLength P) (intervalLength Q) + hD (Nat.cast_nonneg _) (sqrt_modulus_one_le T) (logFactor_one_le (H*T)) + (by exact_mod_cast Nat.mul_pos (NeZero.pos H) (NeZero.pos T)) hU hV + +end ErdosHyperbolaError + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/OriginalSourcePolynomial.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/OriginalSourcePolynomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..09c7390e40c209d4b03c0e1815bddf8e8e0b2033 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/OriginalSourcePolynomial.lean @@ -0,0 +1,169 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceSquareScale +import OAI.NumberTheory.Jacobsthal.Estimates.SourceValueSmallness +import OAI.NumberTheory.Jacobsthal.Sieve.IntegerSlopeConstruction + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosSourcePolynomial +open ErdosAuxiliaryPolynomial + +theorem source_coefficient_log_bound {z R cost : ℝ} {H : ℕ} + (hR : 0 < R) (hL : 0 < Real.log z) (hcost0 : 0 ≤ cost) + (hcost : cost ≤ 4*R^2/(Real.log z)^6) + (hheight : Real.log (2*(H : ℝ)) ≤ Real.log 4+2/((sourceDegree z R : ℝ)+2)*cost) : + Real.log (2*(H : ℝ)) ≤ Real.log 4+8*R/(Real.log z)^4 := by + apply hheight.trans + apply add_le_add le_rfl + calc + _ ≤ (2*(Real.log z)^2/R)*cost := mul_le_mul_of_nonneg_right (source_degree_factor hR hL) hcost0 + _ ≤ (2*(Real.log z)^2/R)*(4*R^2/(Real.log z)^6) := + mul_le_mul_of_nonneg_left hcost (by positivity) + _ = 8*R/(Real.log z)^4 := by field_simp; ring + +theorem source_value_log_budget {z R S : ℝ} {H : ℕ} + (hz : 2 ≤ z) (hR : 0 < R) (hRz : R ≤ z) (hL : 1 ≤ Real.log z) + (hH : 0 < H) (hS : S ≤ z^3) + (hheight : Real.log (2*(H : ℝ)) ≤ Real.log 4+8*R/(Real.log z)^4) : + logarithmicValueBudget (sourceDegree z R) H S ≤ + 4*Real.log z+Real.log 4+8*R/(Real.log z)^4+3*R/Real.log z := by + have hL0 : 0 < Real.log z := by linarith + have hN := source_dimension_log_bound hz hR.le hRz hL + have hH0 : (0 : ℝ) < H := by exact_mod_cast hH + have hlogH : Real.log (H : ℝ) ≤ Real.log 4+8*R/(Real.log z)^4 := + (Real.log_le_log hH0 (by linarith : (H : ℝ) ≤ 2*(H : ℝ))).trans hheight + have hM0 : (0 : ℝ) < max 1 S := zero_lt_one.trans_le (le_max_left _ _) + have hM : max 1 S ≤ z^3 := max_le (one_le_pow₀ (by linarith : 1 ≤ z)) hS + have hlogM : Real.log (max 1 S) ≤ 3*Real.log z := by + simpa only [Real.log_pow,Nat.cast_ofNat] using Real.log_le_log hM0 hM + have hlogM0 : 0 ≤ Real.log (max 1 S) := Real.log_nonneg (le_max_left _ _) + have hprod : (sourceDegree z R : ℝ)*Real.log (max 1 S) ≤ 3*R/Real.log z := by + calc + _ ≤ (R/(Real.log z)^2)*(3*Real.log z) := + mul_le_mul (sourceDegree_le hR.le) hlogM hlogM0 (by positivity) + _ = _ := by field_simp + unfold logarithmicValueBudget + linarith + +end ErdosSourcePolynomial + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourcePolynomial +open ErdosAuxiliaryPolynomial ErdosInversePrimeBin + +structure SourcePolynomialWitness (z R xi S eta c : ℝ) + (T : primeBin R xi → Finset ℤ) (a : primeBin R xi → ℤ) where + polynomial : MvPolynomial (Fin 2) ℤ + height : ℕ + nonzero : polynomial ≠ 0 + degree_le : polynomial.totalDegree ≤ sourceDegree z R + height_pos : 0 < height + coefficient_bound : ∀ m : Fin 2 →₀ ℕ, |polynomial.coeff m| ≤ (height : ℤ) + line_vanishing : ∀ p : primeBin R xi, ∀ s ∈ T p, + lineSub (Int.castRingHom (ZMod p.val)) (a p : ZMod p.val) (s : ZMod p.val) polynomial = 0 + height_bound : Real.log (2*(height : ℝ)) ≤ Real.log 4+8*R/(Real.log z)^4 + value_budget : logarithmicValueBudget (sourceDegree z R) height S < c*eta*R/4 + rich_vanishing : ∀ (x y : ℤ), (0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) → + (0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) → ∀ (I : Finset ℕ) (hIP : I ⊆ primeBin R xi), + c*((primeBin R xi).card : ℝ) ≤ (I.card : ℝ) → + (∀ p : I, IntegerLineIncidence (primeBin R xi) T a x y ⟨p.val,hIP p.property⟩) → + MvPolynomial.eval ![x,y] polynomial = 0 + +theorem uniform_polynomial_for_bounded_square (eta alpha c : ℝ) + (heta : 0 < eta) (halpha : 0 < alpha) (hc : 0 < c) : + ∀ᶠ z : ℝ in atTop, 2 ≤ z ∧ 1 ≤ Real.log z ∧ ∀ R xi S : ℝ, + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → eta ≤ xi → xi ≤ 1 → S ≤ z^3 → + ∀ (T : primeBin R xi → Finset ℤ) (a : primeBin R xi → ℤ), + (∑ p : primeBin R xi, ((T p).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/(Real.log z)^6 → + Nonempty (SourcePolynomialWitness z R xi S eta c T a) := by + obtain ⟨R0,hR0⟩ := Filter.eventually_atTop.mp (uniform_prime_bin_budgets heta) + have hbig := (tendsto_rpow_atTop halpha).eventually_ge_atTop R0 + filter_upwards [eventual_value_budget_small alpha (c*eta/4) halpha (by positivity),hbig] + with z hsmall hbig + refine ⟨hsmall.1,hsmall.2.1,?_⟩ + intro R xi S hRlo hRhi hxi hxi1 hS T a hthin + have hbin := hR0 R (hbig.trans hRlo) + have hR : 0 < R := by linarith [hbin.1] + have hL : 0 < Real.log z := by linarith [hsmall.2.1] + have hxi0 : 0 ≤ xi := heta.le.trans hxi + have hRz : R ≤ z := by + apply hRhi.trans + simpa only [Real.rpow_one] using Real.rpow_le_rpow_of_exponent_le + (by linarith [hsmall.1] : 1 ≤ z) (by norm_num : (1 : ℝ)/100 ≤ 1) + have hprime : ∀ p ∈ primeBin R xi, Nat.Prime p := fun p hp => + ((mem_primeBin hR.le hxi0 p).mp hp).1 + obtain ⟨Q,H,hQ,hD,hH,hcoeff,hline,hheight,hlift⟩ := + exists_integer_auxiliary_polynomial_lifting (primeBin R xi) hprime T a (sourceDegree z R) + have hbudgets := hbin.2 xi hxi hxi1 + have hcost := hbudgets.1 (Real.log z) hL T hthin + have hcost0 : 0 ≤ ∑ p : primeBin R xi, ((T p).card : ℝ)*Real.log (p.val : ℝ) := by + apply Finset.sum_nonneg + intro p hp + apply mul_nonneg (Nat.cast_nonneg _) + apply Real.log_nonneg + exact_mod_cast Nat.succ_le_of_lt (hprime p p.property).pos + have hheight' := source_coefficient_log_bound hR hL hcost0 hcost hheight + have hvalue := source_value_log_budget hsmall.1 hR hRz hsmall.2.1 hH hS hheight' + have hstrict : logarithmicValueBudget (sourceDegree z R) H S < c*eta*R/4 := by + have h := hvalue.trans_lt (hsmall.2.2 R hRlo) + convert! h using 1 + ring + refine ⟨{ + polynomial := Q + height := H + nonzero := hQ + degree_le := hD + height_pos := hH + coefficient_bound := hcoeff + line_vanishing := hline + height_bound := hheight' + value_budget := hstrict + rich_vanishing := ?_ }⟩ + intro x y hx hy I hIP hrich hinc + exact hlift S x y hx hy I hIP hinc (hstrict.trans_le (hbudgets.2 c hc.le I hIP hrich)) + +end ErdosSourcePolynomial + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosSourcePolynomial +open ErdosAuxiliaryPolynomial ErdosInversePrimeBin ErdosInverseBoxHeight + +theorem uniform_original_source_polynomial (C eta alpha c : ℝ) + (hC : 0 ≤ C) (heta : 0 < eta) (halpha : 0 < alpha) (hc : 0 < c) : + ∀ᶠ z : ℝ in atTop, 2 ≤ z ∧ ∀ S R p q xi : ℝ, + 1 ≤ p → 0 < q → p*q ≤ (sourceY z : ℝ) → + 1 ≤ S/q → S/q ≤ (1+xi)^(C*Real.log (sourceB z)) → + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → eta ≤ xi → xi ≤ 1 → + ∀ (T : primeBin R xi → Finset ℤ) (a : primeBin R xi → ℤ), + (∑ r : primeBin R xi, ((T r).card : ℝ)) ≤ ((primeBin R xi).card : ℝ)*R/(Real.log z)^6 → + Nonempty (SourcePolynomialWitness z R xi S eta c T a) := by + filter_upwards [uniform_polynomial_for_bounded_square eta alpha c heta halpha hc, + uniform_source_square_scale C hC] with z hpoly hscale + refine ⟨hpoly.1,?_⟩ + intro S R p q xi hp hq hpq hratio hinfl hRlo hRhi hxi hxi1 T a hthin + have hR1 : 1 ≤ R := (Real.one_le_rpow (by linarith [hpoly.1] : 1 ≤ z) halpha.le).trans hRlo + have hxi0 : 0 ≤ xi := heta.le.trans hxi + have hS := hscale.2.2 S R p q xi hp hq hpq hratio hinfl hR1 hRhi hxi0 hxi1 + exact hpoly.2.2 R xi S hRlo hRhi hxi hxi1 hS T a hthin + +end ErdosSourcePolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialLocalGraph.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialLocalGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..5055e0b3b027d5b7b9b2f6c32d166e7ecaae9631 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialLocalGraph.lean @@ -0,0 +1,166 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RegularImplicitArc +import OAI.NumberTheory.Jacobsthal.Partitions.NestedCoordinates + +namespace OAI + +namespace Erdos970 + +section + +open Filter +open scoped Topology ContDiff +namespace ErdosDivisibleInflection + +open ErdosImplicitCurvature + +noncomputable def planeEval (Q : Bivariate) (p : ℝ × ℝ) : ℝ := peval Q p.1 p.2 + +theorem contDiff_planeEval (Q : Bivariate) (n : ℕ∞ω) : ContDiff ℝ n (planeEval Q) := by + unfold planeEval + induction Q using MvPolynomial.induction_on with + | C c => simpa [planeEval] using (contDiff_const (c := c) : ContDiff ℝ n (fun _ : ℝ × ℝ => c)) + | add P Q hP hQ => + simpa only [planeEval, peval_add] using hP.add hQ + | mul_X P i hP => + fin_cases i + · simpa [peval] using hP.mul contDiff_fst + · simpa [peval] using hP.mul contDiff_snd + +theorem fderiv_planeEval_inr (Q : Bivariate) (x y : ℝ) : + fderiv ℝ (planeEval Q) (x,y) ∘L ContinuousLinearMap.inr ℝ ℝ ℝ = + (1 : ℝ →L[ℝ] ℝ).smulRight (peval (partialY Q) x y) := by + have hF := ((contDiff_planeEval Q 1).differentiable (by norm_num) (x,y)).hasFDerivAt + have hp : HasFDerivAt (fun t : ℝ => (x,t)) (ContinuousLinearMap.inr ℝ ℝ ℝ) y := by + have hlin : HasFDerivAt (ContinuousLinearMap.inr ℝ ℝ ℝ) (ContinuousLinearMap.inr ℝ ℝ ℝ) y := + (ContinuousLinearMap.inr ℝ ℝ ℝ).hasFDerivAt + simpa using hlin.const_add (x,0) + have hc := hF.comp y hp + have hy : HasDerivAt (fun t => peval Q x t) (peval (partialY Q) x y) y := by + simpa using hasDerivAt_peval Q (fun _ => x) id 0 1 y (hasDerivAt_const y x) (hasDerivAt_id y) + exact hc.unique hy.hasFDerivAt + +theorem scalar_map_invertible (b : ℝ) (hb : b ≠ 0) : + ((1 : ℝ →L[ℝ] ℝ).smulRight b).IsInvertible := by + apply ContinuousLinearMap.IsInvertible.of_inverse + (g := (1 : ℝ →L[ℝ] ℝ).smulRight b⁻¹) + · ext + simp [ContinuousLinearMap.comp_apply, ContinuousLinearMap.smulRight_apply, smul_eq_mul, hb] + · ext + simp [ContinuousLinearMap.comp_apply, ContinuousLinearMap.smulRight_apply, smul_eq_mul, hb] + +end ErdosDivisibleInflection + +end + +section + +open Set Filter +open scoped Topology +namespace ErdosLocalFiberGraphs +open ErdosImplicitCurvature ErdosDivisibleInflection ErdosCriticalGeometry + +def boundedFiber (Q : Bivariate) (x L U : ℝ) : Set ℝ := + {y | y ∈ Icc L U ∧ peval Q x y = 0} + +noncomputable def verticalPolynomial (Q : Bivariate) (x : ℝ) : Polynomial ℝ := + (nestedY ℝ Q).map (Polynomial.evalRingHom x) + +theorem verticalPolynomial_eval (Q : Bivariate) (x y : ℝ) : + (verticalPolynomial Q x).eval y = peval Q x y := by + have hv : (fun i : Fin 2 => if i = 0 then x else y) = ![x,y] := by + funext i + fin_cases i <;> simp + have h := eval_nestedY ℝ Q x y + change (verticalPolynomial Q x).eval y = MvPolynomial.eval ![x,y] Q at h + simpa only [peval,hv] using h + +theorem boundedFiber_finite (Q : Bivariate) (x L U z : ℝ) + (hz : peval Q x z ≠ 0) : (boundedFiber Q x L U).Finite := by + have hp : verticalPolynomial Q x ≠ 0 := by + intro he + apply hz + rw [← verticalPolynomial_eval, he, Polynomial.eval_zero] + apply (Polynomial.finite_setOfPred_isRoot hp).subset + intro y hy + change (verticalPolynomial Q x).eval y = 0 + exact (verticalPolynomial_eval Q x y).trans hy.2 + +theorem boundedFiber_interior (Q : Bivariate) (x L U : ℝ) + (hL : peval Q x L ≠ 0) (hU : peval Q x U ≠ 0) : + boundedFiber Q x L U ⊆ Ioo L U := by + intro y hy + constructor + · exact lt_of_le_of_ne hy.1.1 (fun he => hL (he ▸ hy.2)) + · exact lt_of_le_of_ne hy.1.2 (fun he => hU (he ▸ hy.2)) + +theorem compact_nonzero_eventually (Q : Bivariate) (x : ℝ) (K : Set ℝ) + (hK : IsCompact K) (hne : ∀ y ∈ K, peval Q x y ≠ 0) : + ∀ᶠ t in 𝓝 x, ∀ y ∈ K, peval Q t y ≠ 0 := by + have ho : IsOpen {p : ℝ × ℝ | planeEval Q p ≠ 0} := + isOpen_ne.preimage (contDiff_planeEval Q 0).continuous + obtain ⟨A,B,hA,_,hxA,hKB,hAB⟩ := + generalized_tube_lemma isCompact_singleton hK ho (by + rintro ⟨t,y⟩ ⟨ht,hy⟩ + have ht' : t = x := ht + subst t + exact hne y hy) + filter_upwards [hA.mem_nhds (hxA (mem_singleton x))] with t ht + intro y hy + exact hAB (a := (t,y)) ⟨ht,hKB hy⟩ + +end ErdosLocalFiberGraphs + +end + +section + +open Filter +open scoped Topology ContDiff +namespace ErdosDivisibleInflection +open ErdosImplicitCurvature + +theorem exists_local_real_graph (Q : Bivariate) (x y : ℝ) + (hQ : peval Q x y = 0) (hQy : peval (partialY Q) x y ≠ 0) : + ∃ (a b : ℝ) (f : ℝ → ℝ), a < x ∧ x < b ∧ f x = y ∧ + ContDiffOn ℝ 2 f (Set.Ioo a b) ∧ + (∀ t ∈ Set.Ioo a b, peval Q t (f t) = 0) ∧ + (∀ t ∈ Set.Ioo a b, peval (partialY Q) t (f t) ≠ 0) := by + have hc : ContDiffAt ℝ 2 (planeEval Q) (x,y) := (contDiff_planeEval Q 2).contDiffAt + have hi : (fderiv ℝ (planeEval Q) (x,y) ∘L ContinuousLinearMap.inr ℝ ℝ ℝ).IsInvertible := by + rw [fderiv_planeEval_inr] + exact scalar_map_invertible _ hQy + let f := hc.implicitFunction (by norm_num) hi + have hfx : f x = y := hc.implicitFunction_apply_self (by norm_num) hi + have hcf : ContDiffAt ℝ 2 f x := hc.contDiffAt_implicitFunction (by norm_num) hi + have hcurve : ∀ᶠ t in 𝓝 x, peval Q t (f t) = 0 := by + have h := hc.eventually_apply_implicitFunction (by norm_num) hi + exact h.mono fun t ht => ht.trans hQ + have hpair : ContinuousAt (fun t : ℝ => (t,f t)) x := + continuousAt_id.prodMk hcf.continuousAt + have hplane : ContinuousAt (planeEval (partialY Q)) (x,f x) := + (contDiff_planeEval (partialY Q) 0).continuous.continuousAt + have hcy : ContinuousAt (fun t => peval (partialY Q) t (f t)) x := by + change ContinuousAt (planeEval (partialY Q) ∘ (fun t : ℝ => (t,f t))) x + exact ContinuousAt.comp (f := fun t : ℝ => (t,f t)) hplane hpair + have hny : ∀ᶠ t in 𝓝 x, peval (partialY Q) t (f t) ≠ 0 := by + apply hcy.eventually_ne + rwa [hfx] + obtain ⟨U,hU,hfU⟩ := hcf.contDiffOn (m := 2) le_rfl (by norm_num) + have hN : U ∩ {t | peval Q t (f t) = 0} ∩ {t | peval (partialY Q) t (f t) ≠ 0} ∈ 𝓝 x := + inter_mem (inter_mem hU hcurve) hny + obtain ⟨eps,heps,hball⟩ := Metric.mem_nhds_iff.mp hN + have hsub : Set.Ioo (x-eps) (x+eps) ⊆ + U ∩ {t | peval Q t (f t) = 0} ∩ {t | peval (partialY Q) t (f t) ≠ 0} := by + simpa only [Real.ball_eq_Ioo] using hball + refine ⟨x-eps,x+eps,f,by linarith,by linarith,hfx,hfU.mono ?_,?_,?_⟩ + · exact fun t ht => (hsub ht).1.1 + · exact fun t ht => (hsub ht).1.2 + · exact fun t ht => (hsub ht).2 + +end ErdosDivisibleInflection + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialStripPoints.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialStripPoints.lean new file mode 100644 index 0000000000000000000000000000000000000000..41291e3883a8c9c01b3b8d190f258cbe7bee09db --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialStripPoints.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.Jacobsthal.Paths.GlobalFiniteBranches + +namespace OAI + +namespace Erdos970 + +section + +open Set +namespace ErdosRegularStrip +open ErdosImplicitCurvature ErdosLocalFiberGraphs ErdosConvexGraph +attribute [local instance] Classical.propDecidable + +noncomputable def polynomialStripPoints (Q : Bivariate) (a b S : ℝ) : Finset (ℤ × ℤ) := + ((Finset.Icc (0 : ℤ) ⌊S⌋).product (Finset.Icc (0 : ℤ) ⌊S⌋)).filter + (fun p => (p.1 : ℝ) ∈ Ioo a b ∧ peval Q p.1 p.2 = 0) + +theorem mem_polynomialStripPoints (Q : Bivariate) (a b S : ℝ) (p : ℤ × ℤ) : + p ∈ polynomialStripPoints Q a b S ↔ + InSquare S p ∧ (p.1 : ℝ) ∈ Ioo a b ∧ peval Q p.1 p.2 = 0 := by + simp only [polynomialStripPoints,InSquare,Finset.mem_filter,Finset.product_eq_sprod, + Finset.mem_product,Finset.mem_Icc,Int.le_floor,Int.cast_nonneg_iff] + +theorem strip_eq_graph_union (Q : Bivariate) (a b S : ℝ) {n : ℕ} (f : Fin n → ℝ → ℝ) + (hcurve : ∀ i, ∀ t ∈ Ioo a b, peval Q t (f i t) = 0) + (hcover : ∀ t ∈ Ioo a b, boundedFiber Q t 0 S = range (fun i => f i t)) : + polynomialStripPoints Q a b S = + Finset.univ.biUnion (fun i => graphLatticePoints (Ioo a b) (f i) S) := by + classical + ext p + constructor + · intro hp + have h := (mem_polynomialStripPoints Q a b S p).mp hp + have hy : (p.2 : ℝ) ∈ boundedFiber Q p.1 0 S := ⟨h.1.2,h.2.2⟩ + obtain ⟨i,hi⟩ := (hcover p.1 h.2.1).subset hy + apply Finset.mem_biUnion.mpr + exact ⟨i,Finset.mem_univ i,(mem_graphLatticePoints _ _ _ p).mpr + ⟨h.1,h.2.1,hi.symm⟩⟩ + · intro hp + obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp hp + have h := (mem_graphLatticePoints (Ioo a b) (f i) S p).mp hi + apply (mem_polynomialStripPoints Q a b S p).mpr + refine ⟨h.1,h.2.1,?_⟩ + rw [h.2.2] + exact hcurve i p.1 h.2.1 + +end ErdosRegularStrip + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialValueBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialValueBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..eaec194794a3b51d7fabb615e21ad98bb28a65d0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PolynomialValueBound.lean @@ -0,0 +1,191 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.BivariateMonomialIndex + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +theorem exponent_sum {D : ℕ} (i : MonomialIndex D) : + (exponent i).sum (fun _ n => n) = i.1.val := by + rw [Finsupp.sum_fintype _ _ (fun _ => rfl)] + simp only [Fin.sum_univ_two,exponent_zero,exponent_one] + have h := i.2.isLt + omega + +noncomputable def encode {D : ℕ} (v : MonomialIndex D → ℤ) : MvPolynomial (Fin 2) ℤ := + ∑ i, MvPolynomial.monomial (exponent i) (v i) + +theorem coeff_encode {D : ℕ} (v : MonomialIndex D → ℤ) (i : MonomialIndex D) : + (encode v).coeff (exponent i) = v i := by + classical + simp [encode,MvPolynomial.coeff_monomial,(exponent_injective D).eq_iff] + +theorem encode_eq_zero_iff {D : ℕ} (v : MonomialIndex D → ℤ) : encode v = 0 ↔ v = 0 := by + constructor + · intro h + funext i + have hi := congrArg (fun P : MvPolynomial (Fin 2) ℤ => P.coeff (exponent i)) h + simpa only [coeff_encode,AddMonoidAlgebra.coeff_zero,Finsupp.zero_apply,Pi.zero_apply] using hi + · rintro rfl + simp [encode] + +theorem encode_degree_le {D : ℕ} (v : MonomialIndex D → ℤ) : (encode v).totalDegree ≤ D := by + apply (MvPolynomial.mem_restrictTotalDegree (R := ℤ) (Fin 2) D (encode v)).mp + apply Submodule.sum_mem + intro i hi + apply (MvPolynomial.mem_restrictTotalDegree (R := ℤ) (Fin 2) D _).mpr + have h := MvPolynomial.totalDegree_monomial_le (exponent i) (v i) + change (MvPolynomial.monomial (exponent i) (v i)).totalDegree ≤ (exponent i).sum (fun _ n => n) at h + rw [exponent_sum] at h + exact h.trans (Nat.le_of_lt_succ i.1.isLt) + +theorem encode_coefficient_bound {D H : ℕ} (v : MonomialIndex D → ℤ) + (hv : ∀ i, |v i| ≤ (H : ℤ)) (m : Fin 2 →₀ ℕ) : |(encode v).coeff m| ≤ (H : ℤ) := by + classical + by_cases hm : ∃ i : MonomialIndex D, exponent i = m + · obtain ⟨i,rfl⟩ := hm + rw [coeff_encode] + exact hv i + · have hz : (encode v).coeff m = 0 := by + simp only [encode,MvPolynomial.coeff_sum,MvPolynomial.coeff_monomial] + apply Finset.sum_eq_zero + intro i hi + exact ite_eq_right (fun h => hm ⟨i,h⟩) + rw [hz,abs_zero] + exact Int.natCast_nonneg H + +noncomputable def encodeHom (D : ℕ) : (MonomialIndex D → ℤ) →+ MvPolynomial (Fin 2) ℤ where + toFun := encode + map_zero' := by simp [encode] + map_add' v w := by simp [encode,Finset.sum_add_distrib] + +end ErdosAuxiliaryPolynomial + +end + +section + +namespace ErdosAuxiliaryPolynomial + +theorem exponent_representation (D : ℕ) (m : Fin 2 →₀ ℕ) + (hm : m.sum (fun _ n => n) ≤ D) : ∃ i : MonomialIndex D, exponent i = m := by + have hsum : m.sum (fun _ n => n) = m 0+m 1 := by + rw [Finsupp.sum_fintype _ _ (fun _ => rfl)] + exact Fin.sum_univ_two _ + rw [hsum] at hm + let k : Fin (D+1) := ⟨m 0+m 1,by omega⟩ + have hj : m 0 < k.val+1 := by + change m 0 < m 0+m 1+1 + omega + let i : MonomialIndex D := ⟨k,⟨m 0,hj⟩⟩ + refine ⟨i,?_⟩ + ext j + fin_cases j <;> simp [exponent,i,k] + +theorem coeff_encode_of_not_range {D : ℕ} (v : MonomialIndex D → ℤ) (m : Fin 2 →₀ ℕ) + (hm : ¬∃ i : MonomialIndex D, exponent i = m) : (encode v).coeff m = 0 := by + classical + simp only [encode,MvPolynomial.coeff_sum,MvPolynomial.coeff_monomial] + apply Finset.sum_eq_zero + intro i hi + exact ite_eq_right (fun h => hm ⟨i,h⟩) + +theorem encode_coefficients (Q : MvPolynomial (Fin 2) ℤ) (D : ℕ) (hD : Q.totalDegree ≤ D) : + encode (fun i : MonomialIndex D => Q.coeff (exponent i)) = Q := by + classical + ext m + by_cases hm : ∃ i : MonomialIndex D, exponent i = m + · obtain ⟨i,rfl⟩ := hm + exact coeff_encode _ i + · have hz : Q.coeff m = 0 := by + by_contra hc + have hd := MvPolynomial.le_totalDegree (MvPolynomial.mem_support_iff.mpr hc) + exact hm (exponent_representation D m (hd.trans hD)) + rw [coeff_encode_of_not_range _ m hm,hz] + +end ErdosAuxiliaryPolynomial + +end + +section + +namespace ErdosAuxiliaryPolynomial + +noncomputable def evalReal (Q : MvPolynomial (Fin 2) ℤ) (x y : ℝ) : ℝ := + MvPolynomial.eval₂Hom (Int.castRingHom ℝ) ![x,y] Q + +theorem evalReal_monomial {D : ℕ} (i : MonomialIndex D) (c : ℤ) (x y : ℝ) : + evalReal (MvPolynomial.monomial (exponent i) c) x y = + (c : ℝ)*(x^i.2.val*y^(i.1.val-i.2.val)) := by + change MvPolynomial.eval₂ (Int.castRingHom ℝ) ![x,y] + (MvPolynomial.monomial (exponent i) c) = _ + rw [MvPolynomial.eval₂_monomial,Finsupp.prod_fintype _ _ (fun _ => pow_zero _)] + simp [exponent,Fin.prod_univ_two] + +theorem evalReal_encode {D : ℕ} (v : MonomialIndex D → ℤ) (x y : ℝ) : + evalReal (encode v) x y = + ∑ i : MonomialIndex D, (v i : ℝ)*(x^i.2.val*y^(i.1.val-i.2.val)) := by + change (MvPolynomial.eval₂Hom (Int.castRingHom ℝ) ![x,y]) + (∑ i, MvPolynomial.monomial (exponent i) (v i)) = _ + rw [map_sum] + exact Finset.sum_congr rfl (fun i _ => evalReal_monomial i (v i) x y) + +theorem evalReal_int (Q : MvPolynomial (Fin 2) ℤ) (x y : ℤ) : + evalReal Q (x : ℝ) (y : ℝ) = (MvPolynomial.eval ![x,y] Q : ℝ) := by + have he : (Int.castRingHom ℝ) ∘ (![x,y] : Fin 2 → ℤ) = ![(x : ℝ),(y : ℝ)] := by + funext i + fin_cases i <;> rfl + have h := MvPolynomial.eval₂_comp (Int.castRingHom ℝ) ![x,y] Q + rw [he] at h + exact h.symm + +theorem evalReal_encode_bound {D H : ℕ} (v : MonomialIndex D → ℤ) + (hv : ∀ i, |v i| ≤ (H : ℤ)) (S x y : ℝ) + (hx : 0 ≤ x ∧ x ≤ S) (hy : 0 ≤ y ∧ y ≤ S) : + |evalReal (encode v) x y| ≤ ((D+2).choose 2 : ℝ)*(H : ℝ)*(max 1 S)^D := by + have hx0 := hx.1 + have hy0 := hy.1 + let M := max 1 S + have hM : 1 ≤ M := le_max_left _ _ + have hM0 : 0 ≤ M := zero_le_one.trans hM + have hxM : x ≤ M := hx.2.trans (le_max_right _ _) + have hyM : y ≤ M := hy.2.trans (le_max_right _ _) + have hterm (i : MonomialIndex D) : + |(v i : ℝ)*(x^i.2.val*y^(i.1.val-i.2.val))| ≤ (H : ℝ)*M^D := by + have hc : |(v i : ℝ)| ≤ (H : ℝ) := by exact_mod_cast hv i + have hp : x^i.2.val*y^(i.1.val-i.2.val) ≤ M^D := by + calc + _ ≤ M^i.2.val*M^(i.1.val-i.2.val) := by gcongr + _ = M^i.1.val := by + rw [← pow_add] + congr 1 + have hi := i.2.isLt + omega + _ ≤ M^D := pow_le_pow_right₀ hM (Nat.le_of_lt_succ i.1.isLt) + rw [abs_mul,abs_mul,abs_of_nonneg (pow_nonneg hx.1 _),abs_of_nonneg (pow_nonneg hy.1 _)] + exact mul_le_mul hc hp (mul_nonneg (pow_nonneg hx.1 _) (pow_nonneg hy.1 _)) (Nat.cast_nonneg H) + rw [evalReal_encode] + calc + _ ≤ ∑ i : MonomialIndex D, |(v i : ℝ)*(x^i.2.val*y^(i.1.val-i.2.val))| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _i : MonomialIndex D, (H : ℝ)*M^D := Finset.sum_le_sum (fun i _ => hterm i) + _ = (Fintype.card (MonomialIndex D) : ℝ)*((H : ℝ)*M^D) := by simp + _ = ((D+2).choose 2 : ℝ)*(H : ℝ)*(max 1 S)^D := by rw [monomialIndex_card]; ring + +theorem polynomial_value_bound (Q : MvPolynomial (Fin 2) ℤ) (D H : ℕ) + (hD : Q.totalDegree ≤ D) (hH : ∀ m : Fin 2 →₀ ℕ, |Q.coeff m| ≤ (H : ℤ)) + (S : ℝ) (x y : ℤ) (hx : 0 ≤ (x : ℝ) ∧ (x : ℝ) ≤ S) (hy : 0 ≤ (y : ℝ) ∧ (y : ℝ) ≤ S) : + |(MvPolynomial.eval ![x,y] Q : ℝ)| ≤ ((D+2).choose 2 : ℝ)*(H : ℝ)*(max 1 S)^D := by + rw [← evalReal_int,← encode_coefficients Q D hD] + exact evalReal_encode_bound _ (fun i => hH (exponent i)) S x y hx hy + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PrimeFourierSieve.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PrimeFourierSieve.lean new file mode 100644 index 0000000000000000000000000000000000000000..27a1dbce089548130b0989ef7667b87591bbabf7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PrimeFourierSieve.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.IntervalSpectrumCoefficients + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseSpectrum +attribute [local instance] Classical.decEq + +theorem prime_reduced_residues (p : ℕ) (hp : Nat.Prime p) : + (Finset.range p).erase 0 = (Finset.range p).filter (fun a => Nat.Coprime a p) := by + ext a + simp only [Finset.mem_erase,Finset.mem_range,Finset.mem_filter] + constructor + · rintro ⟨ha0,hap⟩ + refine ⟨hap,?_⟩ + apply (hp.coprime_iff_not_dvd.mpr ?_).symm + intro hd + exact (not_le_of_gt hap) (Nat.le_of_dvd (Nat.pos_of_ne_zero ha0) hd) + · rintro ⟨hap,hcop⟩ + refine ⟨?_,hap⟩ + intro ha0 + subst a + have hh : p = 1 := by simpa using hcop + exact hp.ne_one hh + +theorem prime_variance_large_sieve (P : Finset ℕ) (hP : ∀ p ∈ P,Nat.Prime p) + (Q J : ℕ) (M : ℤ) (S : Finset ℤ) (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) + (hQ : ∀ p ∈ P,p ≤ Q) : + (∑ p ∈ P,(p : ℝ)*integerResidueVariance p S) ≤ + (4+8*Real.pi^2)*((J : ℝ)+(Q : ℝ)^2)*(S.card : ℝ) := by + have hpoint (p : ℕ) (hp : p ∈ P) : + (p : ℝ)*integerResidueVariance p S = + ∑ a ∈ (Finset.range p).filter (fun a => a.Coprime p),‖exponentialSum S a p‖^2 := by + let : NeZero p := ⟨(hP p hp).ne_zero⟩ + rw [integer_variance_fourier,prime_reduced_residues p (hP p hp)] + have hsub : P ⊆ Finset.Icc 1 Q := by + intro p hp + exact Finset.mem_Icc.mpr ⟨(hP p hp).one_le,hQ p hp⟩ + have hals := AdditiveLargeSieve.additive_large_sieve Q J M (indicatorCoefficient S) + simp_rw [indicator_exponential_sum S M J hS] at hals + rw [indicator_energy S M J hS] at hals + calc + _ = ∑ p ∈ P,∑ a ∈ (Finset.range p).filter (fun a => a.Coprime p),‖exponentialSum S a p‖^2 := + Finset.sum_congr rfl hpoint + _ ≤ ∑ p ∈ Finset.Icc 1 Q,∑ a ∈ (Finset.range p).filter (fun a => a.Coprime p),‖exponentialSum S a p‖^2 := + Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + _ ≤ _ := hals + +end ErdosInverseSpectrum + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PrimitiveResultant.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PrimitiveResultant.lean new file mode 100644 index 0000000000000000000000000000000000000000..d93f6d0784c3c59fa0b693c3f757de2a7f45b024 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/PrimitiveResultant.lean @@ -0,0 +1,358 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Partitions.NestedCoordinates + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosBivariateResultant + +abbrev Bivariate := Polynomial (Polynomial ℂ) + +noncomputable def specialize (P : Bivariate) (x : ℂ) : Polynomial ℂ := + P.map (Polynomial.evalRingHom x) + +noncomputable def pointEvalHom (x y : ℂ) : Bivariate →+* ℂ := + (Polynomial.evalRingHom y).comp (Polynomial.mapRingHom (Polynomial.evalRingHom x)) + +noncomputable def beval (P : Bivariate) (x y : ℂ) : ℂ := pointEvalHom x y P + +noncomputable def xResultant (P Q : Bivariate) : Polynomial ℂ := P.resultant Q + +theorem beval_eq_specialize (P : Bivariate) (x y : ℂ) : + beval P x y = (specialize P x).eval y := rfl + +@[simp] theorem beval_add (P Q : Bivariate) (x y : ℂ) : + beval (P+Q) x y = beval P x y+beval Q x y := (pointEvalHom x y).map_add P Q +@[simp] theorem beval_mul (P Q : Bivariate) (x y : ℂ) : + beval (P*Q) x y = beval P x y*beval Q x y := (pointEvalHom x y).map_mul P Q +@[simp] theorem beval_C (p : Polynomial ℂ) (x y : ℂ) : + beval (Polynomial.C p) x y = p.eval x := by + simp [beval, pointEvalHom] + +theorem resultant_bezout (P Q : Bivariate) (hdeg : P.natDegree ≠ 0 ∨ Q.natDegree ≠ 0) : + ∃ U V : Bivariate, P*U+Q*V = Polynomial.C (xResultant P Q) := by + obtain ⟨U,V,_,_,h⟩ := Polynomial.exists_mul_add_mul_eq_C_resultant P Q le_rfl le_rfl hdeg + exact ⟨U,V,h⟩ + +theorem common_zero_resultant_zero (P Q : Bivariate) + (hdeg : P.natDegree ≠ 0 ∨ Q.natDegree ≠ 0) (x y : ℂ) + (hP : beval P x y = 0) (hQ : beval Q x y = 0) : + (xResultant P Q).eval x = 0 := by + obtain ⟨U,V,h⟩ := resultant_bezout P Q hdeg + have he := congrArg (fun R : Bivariate => beval R x y) h + simpa only [beval_add, beval_mul, beval_C, hP, hQ, zero_mul, zero_add] using he.symm + +theorem specialize_degree_le (P : Bivariate) (x : ℂ) : + (specialize P x).natDegree ≤ P.natDegree := Polynomial.natDegree_map_le + +theorem common_zero_resultant_zero_of_fiber (P Q : Bivariate) (x y : ℂ) + (hPx : specialize P x ≠ 0) (hP : beval P x y = 0) (hQ : beval Q x y = 0) : + (xResultant P Q).eval x = 0 := by + have hd : 0 < (specialize P x).natDegree := + Polynomial.natDegree_pos_of_eval₂_root hPx (RingHom.id ℂ) hP (fun z hz => hz) + have hdeg : 0 < P.natDegree := hd.trans_le (specialize_degree_le P x) + exact common_zero_resultant_zero P Q (Or.inl hdeg.ne') x y hP hQ + +end ErdosBivariateResultant + +end + +section + +open scoped BigOperators +namespace ErdosBivariateResultant + +theorem determinant_degree_le {n : Type*} [Fintype n] [DecidableEq n] + (M : Matrix n n (Polynomial ℂ)) (D : n → ℕ) + (hM : ∀ i j, (M i j).natDegree ≤ D j) : M.det.natDegree ≤ ∑ j, D j := by + classical + rw [Matrix.det_apply] + apply Polynomial.natDegree_sum_le_of_forall_le + intro sigma _ + apply (Polynomial.natDegree_smul_le (Equiv.Perm.sign sigma) _).trans + apply (Polynomial.natDegree_prod_le _ _).trans + exact Finset.sum_le_sum fun j _ => hM (sigma j) j + +theorem resultant_degree_from_coefficients (P Q : Bivariate) (m n A B : ℕ) + (hP : ∀ k, (P.coeff k).natDegree ≤ A) (hQ : ∀ k, (Q.coeff k).natDegree ≤ B) : + (P.resultant Q m n).natDegree ≤ m*B+n*A := by + let D : Fin (m+n) → ℕ := Fin.addCases (fun _ : Fin m => B) (fun _ : Fin n => A) + have hcol (i j : Fin (m+n)) : (P.sylvester Q m n i j).natDegree ≤ D j := by + induction j using Fin.addCases with + | left j => + simp only [Polynomial.sylvester, Matrix.of_apply, Fin.addCases_left, D] + split_ifs + · exact hQ _ + · simp + | right j => + simp only [Polynomial.sylvester, Matrix.of_apply, Fin.addCases_right, D] + split_ifs + · exact hP _ + · simp + have h := determinant_degree_le (P.sylvester Q m n) D hcol + change (P.resultant Q m n).natDegree ≤ _ at h + have hsum : (∑ j, D j) = m*B+n*A := by + rw [Fin.sum_univ_add] + simp [D] + rwa [hsum] at h + +noncomputable def coefficientDegree (P : Bivariate) : ℕ := + P.support.sup fun k => (P.coeff k).natDegree + +theorem coeff_degree_le (P : Bivariate) (k : ℕ) : (P.coeff k).natDegree ≤ coefficientDegree P := by + classical + by_cases hk : k ∈ P.support + · exact Finset.le_sup (f := fun k => (P.coeff k).natDegree) hk + · rw [Polynomial.notMem_support_iff.mp hk] + exact Nat.zero_le _ + +theorem xResultant_degree_le (P Q : Bivariate) : + (xResultant P Q).natDegree ≤ + P.natDegree*coefficientDegree Q+Q.natDegree*coefficientDegree P := + resultant_degree_from_coefficients P Q _ _ _ _ (coeff_degree_le P) (coeff_degree_le Q) + +theorem xResultant_degree_uniform (P Q : Bivariate) (d : ℕ) + (hPy : P.natDegree ≤ d) (hQy : Q.natDegree ≤ d) + (hPx : ∀ k, (P.coeff k).natDegree ≤ d) (hQx : ∀ k, (Q.coeff k).natDegree ≤ d) : + (xResultant P Q).natDegree ≤ 2*d^2 := by + have h := resultant_degree_from_coefficients P Q P.natDegree Q.natDegree d d hPx hQx + change (xResultant P Q).natDegree ≤ _ at h + nlinarith + +end ErdosBivariateResultant + +end + +section + +open scoped BigOperators +namespace ErdosBivariateResultant + +attribute [local instance] Classical.propDecidable + +noncomputable def resultantRoots (P Q : Bivariate) : Finset ℂ := (xResultant P Q).roots.toFinset +noncomputable def verticalRoots (P : Bivariate) (x : ℂ) : Finset ℂ := (specialize P x).roots.toFinset + +noncomputable def rootPairs (P Q : Bivariate) : Finset (ℂ × ℂ) := + (resultantRoots P Q).biUnion fun x => (verticalRoots P x).image fun y => (x,y) + +noncomputable def commonZeroFinset (P Q : Bivariate) : Finset (ℂ × ℂ) := + (rootPairs P Q).filter fun p => beval Q p.1 p.2 = 0 + +def commonZeroSet (P Q : Bivariate) : Set (ℂ × ℂ) := + {p | beval P p.1 p.2 = 0 ∧ beval Q p.1 p.2 = 0} + +theorem mem_resultantRoots (P Q : Bivariate) (hR : xResultant P Q ≠ 0) (x : ℂ) : + x ∈ resultantRoots P Q ↔ (xResultant P Q).eval x = 0 := by + simp only [resultantRoots, Multiset.mem_toFinset, Polynomial.mem_roots hR, Polynomial.IsRoot.def] + +theorem mem_verticalRoots (P : Bivariate) (x y : ℂ) (hPx : specialize P x ≠ 0) : + y ∈ verticalRoots P x ↔ beval P x y = 0 := by + simp only [verticalRoots, Multiset.mem_toFinset, Polynomial.mem_roots hPx, + Polynomial.IsRoot.def, beval_eq_specialize] + +theorem mem_rootPairs (P Q : Bivariate) (p : ℂ × ℂ) : + p ∈ rootPairs P Q ↔ p.1 ∈ resultantRoots P Q ∧ p.2 ∈ verticalRoots P p.1 := by + rcases p with ⟨a,b⟩ + simp only [rootPairs, Finset.mem_biUnion, Finset.mem_image] + constructor + · rintro ⟨x,hx,y,hy,hp⟩ + cases hp + exact ⟨hx,hy⟩ + · intro h + exact ⟨a,h.1,b,h.2,rfl⟩ + +theorem mem_commonZeroFinset (P Q : Bivariate) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, specialize P x ≠ 0) (p : ℂ × ℂ) : + p ∈ commonZeroFinset P Q ↔ p ∈ commonZeroSet P Q := by + simp only [commonZeroFinset, Finset.mem_filter, mem_rootPairs, commonZeroSet, Set.mem_ofPred_eq] + constructor + · rintro ⟨⟨_,hy⟩,hQ⟩ + exact ⟨(mem_verticalRoots P p.1 p.2 (hP p.1)).mp hy,hQ⟩ + · rintro ⟨hp,hq⟩ + refine ⟨⟨(mem_resultantRoots P Q hR p.1).mpr ?_, + (mem_verticalRoots P p.1 p.2 (hP p.1)).mpr hp⟩,hq⟩ + exact common_zero_resultant_zero_of_fiber P Q p.1 p.2 (hP p.1) hp hq + +theorem coe_commonZeroFinset (P Q : Bivariate) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, specialize P x ≠ 0) : + (commonZeroFinset P Q : Set (ℂ × ℂ)) = commonZeroSet P Q := by + ext p + exact mem_commonZeroFinset P Q hR hP p + +theorem commonZeroSet_finite (P Q : Bivariate) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, specialize P x ≠ 0) : (commonZeroSet P Q).Finite := by + rw [← coe_commonZeroFinset P Q hR hP] + exact Finset.finite_toSet _ + +theorem resultantRoots_card_le (P Q : Bivariate) : + (resultantRoots P Q).card ≤ (xResultant P Q).natDegree := + (Multiset.toFinset_card_le _).trans (Polynomial.card_roots' _) + +theorem verticalRoots_card_le (P : Bivariate) (x : ℂ) : (verticalRoots P x).card ≤ P.natDegree := + (Multiset.toFinset_card_le _).trans ((Polynomial.card_roots' _).trans (specialize_degree_le P x)) + +theorem commonZeroFinset_card_le (P Q : Bivariate) : + (commonZeroFinset P Q).card ≤ (xResultant P Q).natDegree*P.natDegree := by + calc + _ ≤ (rootPairs P Q).card := Finset.card_filter_le _ _ + _ ≤ ∑ x ∈ resultantRoots P Q, ((verticalRoots P x).image fun y => (x,y)).card := + Finset.card_biUnion_le + _ ≤ ∑ _x ∈ resultantRoots P Q, P.natDegree := by + apply Finset.sum_le_sum + intro x _ + exact Finset.card_image_le.trans (verticalRoots_card_le P x) + _ = (resultantRoots P Q).card*P.natDegree := by simp + _ ≤ _ := Nat.mul_le_mul_right _ (resultantRoots_card_le P Q) + +theorem common_zero_finite_count (P Q : Bivariate) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, specialize P x ≠ 0) : + (commonZeroSet P Q).Finite ∧ + (commonZeroSet P Q).ncard ≤ (xResultant P Q).natDegree*P.natDegree := by + refine ⟨commonZeroSet_finite P Q hR hP, ?_⟩ + rw [← coe_commonZeroFinset P Q hR hP, Set.ncard_coe_finset] + exact commonZeroFinset_card_le P Q + +theorem common_zero_count_coefficient_bound (P Q : Bivariate) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, specialize P x ≠ 0) : + (commonZeroSet P Q).ncard ≤ + (P.natDegree*coefficientDegree Q+Q.natDegree*coefficientDegree P)*P.natDegree := + (common_zero_finite_count P Q hR hP).2.trans (Nat.mul_le_mul_right _ (xResultant_degree_le P Q)) + +theorem common_zero_count_uniform (P Q : Bivariate) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, specialize P x ≠ 0) (d : ℕ) + (hPy : P.natDegree ≤ d) (hQy : Q.natDegree ≤ d) + (hPx : ∀ k, (P.coeff k).natDegree ≤ d) (hQx : ∀ k, (Q.coeff k).natDegree ≤ d) : + (commonZeroSet P Q).ncard ≤ 2*d^3 := by + calc + _ ≤ (xResultant P Q).natDegree*P.natDegree := (common_zero_finite_count P Q hR hP).2 + _ ≤ (2*d^2)*d := Nat.mul_le_mul (xResultant_degree_uniform P Q d hPy hQy hPx hQx) hPy + _ = _ := by ring + +end ErdosBivariateResultant + +end + +section + +namespace ErdosBivariateResultant + +attribute [local instance] Classical.propDecidable + +noncomputable def commonAbscissae (P Q : Bivariate) : Finset ℂ := + (commonZeroFinset P Q).image Prod.fst + +noncomputable def commonVerticalRoots (P Q : Bivariate) (x : ℂ) : Finset ℂ := + (verticalRoots P x).filter fun y => beval Q x y = 0 + +theorem mem_commonAbscissae (P Q : Bivariate) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, specialize P x ≠ 0) (x : ℂ) : + x ∈ commonAbscissae P Q ↔ ∃ y : ℂ, beval P x y = 0 ∧ beval Q x y = 0 := by + constructor + · intro hx + obtain ⟨⟨a,b⟩,hp,he⟩ := Finset.mem_image.mp hx + change a = x at he + subst a + exact ⟨b,(mem_commonZeroFinset P Q hR hP (x,b)).mp hp⟩ + · rintro ⟨y,hp,hq⟩ + exact Finset.mem_image.mpr ⟨(x,y),(mem_commonZeroFinset P Q hR hP (x,y)).mpr ⟨hp,hq⟩,rfl⟩ + +theorem commonAbscissae_card_le (P Q : Bivariate) : + (commonAbscissae P Q).card ≤ (xResultant P Q).natDegree := by + apply (Finset.card_le_card (show commonAbscissae P Q ⊆ resultantRoots P Q from ?_)).trans + (resultantRoots_card_le P Q) + intro x hx + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hx + exact ((mem_rootPairs P Q p).mp (Finset.mem_filter.mp hp).1).1 + +theorem mem_commonVerticalRoots (P Q : Bivariate) (x y : ℂ) (hPx : specialize P x ≠ 0) : + y ∈ commonVerticalRoots P Q x ↔ beval P x y = 0 ∧ beval Q x y = 0 := by + simp only [commonVerticalRoots, Finset.mem_filter, mem_verticalRoots P x y hPx] + +theorem commonVerticalRoots_card_le (P Q : Bivariate) (x : ℂ) : + (commonVerticalRoots P Q x).card ≤ P.natDegree := + (Finset.card_filter_le _ _).trans (verticalRoots_card_le P x) + +theorem coe_commonZeroFinset_on_resultant (P Q : Bivariate) + (hdeg : P.natDegree ≠ 0 ∨ Q.natDegree ≠ 0) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, (xResultant P Q).eval x = 0 → specialize P x ≠ 0) : + (commonZeroFinset P Q : Set (ℂ × ℂ)) = commonZeroSet P Q := by + ext p + simp only [commonZeroFinset, Finset.mem_coe, Finset.mem_filter, mem_rootPairs, + commonZeroSet, Set.mem_ofPred_eq] + constructor + · rintro ⟨⟨hx,hy⟩,hq⟩ + have hr := (mem_resultantRoots P Q hR p.1).mp hx + exact ⟨(mem_verticalRoots P p.1 p.2 (hP p.1 hr)).mp hy,hq⟩ + · rintro ⟨hp,hq⟩ + have hr := common_zero_resultant_zero P Q hdeg p.1 p.2 hp hq + exact ⟨⟨(mem_resultantRoots P Q hR p.1).mpr hr, + (mem_verticalRoots P p.1 p.2 (hP p.1 hr)).mpr hp⟩,hq⟩ + +theorem common_zero_finite_count_on_resultant (P Q : Bivariate) + (hdeg : P.natDegree ≠ 0 ∨ Q.natDegree ≠ 0) (hR : xResultant P Q ≠ 0) + (hP : ∀ x : ℂ, (xResultant P Q).eval x = 0 → specialize P x ≠ 0) : + (commonZeroSet P Q).Finite ∧ + (commonZeroSet P Q).ncard ≤ (xResultant P Q).natDegree*P.natDegree := by + rw [← coe_commonZeroFinset_on_resultant P Q hdeg hR hP] + exact ⟨Finset.finite_toSet _, by simpa using commonZeroFinset_card_le P Q⟩ + +end ErdosBivariateResultant + +end + +section + +namespace ErdosCriticalGeometry + +open ErdosBivariateResultant + +theorem primitive_specialize_ne_zero (P : Nested ℂ) (hP : P.IsPrimitive) (x : ℂ) : + specialize P x ≠ 0 := by + intro hz + have hcoeff (k : ℕ) : (P.coeff k).eval x = 0 := by + have h := congrArg (fun p : Polynomial ℂ => p.coeff k) hz + change (Polynomial.evalRingHom x) (P.coeff k) = 0 + simpa only [specialize, Polynomial.coeff_map, Polynomial.coeff_zero] using h + have hdiv : Polynomial.C (Polynomial.X-Polynomial.C x) ∣ P := by + apply (Polynomial.C_dvd_iff_dvd_coeff _ _).mpr + intro k + exact Polynomial.dvd_iff_isRoot.mpr (hcoeff k) + exact Polynomial.not_isUnit_X_sub_C x + ((Polynomial.isPrimitive_iff_isUnit_of_C_dvd.mp hP) _ hdiv) + + +theorem irreducible_resultant_ne_zero (P G : Nested ℂ) (hP : Irreducible P) + (hdeg : P.natDegree ≠ 0) (hnd : ¬P ∣ G) : xResultant P G ≠ 0 := by + classical + let K := FractionRing (Polynomial ℂ) + let : IsPrincipalIdealRing (Polynomial K) := by + let := Polynomial.instEuclideanDomain (R := K) + exact EuclideanDomain.instIsPrincipalIdealRing + let phi : Polynomial ℂ →+* K := algebraMap (Polynomial ℂ) K + have hphi : Function.Injective phi := IsFractionRing.injective (Polynomial ℂ) K + have hprim := hP.isPrimitive hdeg + have hirr : Irreducible (P.map phi) := + (hprim.irreducible_iff_irreducible_map_fraction_map (K := K)).mp hP + have hnd' : ¬P.map phi ∣ G.map phi := by + intro h + exact hnd (hprim.dvd_of_fraction_map_dvd_fraction_map (K := K) h) + have hcop : IsCoprime (P.map phi) (G.map phi) := + hirr.coprime_iff_not_dvd.mpr hnd' + have hres := Polynomial.resultant_ne_zero (P.map phi) (G.map phi) hcop + intro hz + apply hres + rw [Polynomial.natDegree_map_eq_of_injective hphi, Polynomial.natDegree_map_eq_of_injective hphi, + Polynomial.resultant_map_map] + simpa only [xResultant, map_zero] using congrArg phi hz + +end ErdosCriticalGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/RealAlgebraicFibers.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/RealAlgebraicFibers.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3193eed4d5d90cb6ec1048058c0c84c10ba0c6a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/RealAlgebraicFibers.lean @@ -0,0 +1,42 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.DivisibleInflection +import OAI.NumberTheory.Jacobsthal.Probability.MarkedStripTotal + +namespace OAI + +namespace Erdos970 + +section + +open Set +namespace ErdosAlgebraicCurve +open ErdosCriticalGeometry ErdosImplicitCurvature ErdosDivisibleInflection ErdosLocalFiberGraphs + +theorem finite_real_preimage (A : Set ℂ) (hA : A.Finite) : + (Complex.ofReal ⁻¹' A).Finite ∧ (Complex.ofReal ⁻¹' A).ncard ≤ A.ncard := by + refine ⟨hA.preimage Complex.ofReal_injective.injOn,?_⟩ + exact ncard_le_ncard_of_injOn Complex.ofReal (fun _ h => h) Complex.ofReal_injective.injOn hA + +theorem real_vertical_nonzero (Q : MV ℝ) (hQ : Irreducible (complexify Q)) + (hdeg : 1 < Q.totalDegree) (x : ℝ) : verticalPolynomial Q x ≠ 0 := by + intro hz + have hdegC : 1 < (complexify Q).totalDegree := by rwa [complexify_totalDegree] + let P := ErdosBivariateResultant.specialize (nestedY ℂ (complexify Q)) (x : ℂ) + have hp : P ≠ 0 := nonlinear_fibers_nonzero (complexify Q) hQ hdegC x + have hroot : ∀ y : ℝ, P.IsRoot (y : ℂ) := by + intro y + have hy : peval Q x y = 0 := by rw [← verticalPolynomial_eval,hz,Polynomial.eval_zero] + change ErdosBivariateResultant.beval (nestedY ℂ (complexify Q)) (x : ℂ) (y : ℂ) = 0 + rw [beval_nested,complexify_eval,← peval_eq_eval_pair,hy,Complex.ofReal_zero] + have hinf : (range Complex.ofReal).Infinite := infinite_range_of_injective Complex.ofReal_injective + apply hinf + apply (Polynomial.finite_setOfPred_isRoot hp).subset + rintro y ⟨z,rfl⟩ + exact hroot z + +end ErdosAlgebraicCurve + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/SharpCharacterLogPower.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/SharpCharacterLogPower.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c07ae067145694af10b8b56743bb6294d71b269 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/SharpCharacterLogPower.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RecoveryScale + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Filter +open scoped Topology + +theorem sharp_character_log_power (A M : ℝ) (hA : 0 < A) (hM : 0 < M) : + ∃ K : ℝ, 0 < K ∧ ∀ᶠ X : ℝ in atTop, ∀ (q : ℕ) [NeZero q] + (chi : DirichletCharacter ℂ q), chi ≠ 1 → (q:ℝ) ≤ (Real.log X)^A → + ‖sharpSum (fun n:ℕ => chi n*(ArithmeticFunction.vonMangoldt n:ℂ)) X‖ ≤ + K*X/(Real.log X)^M := by + let k : ℝ := M+1 + have hk : 0 < k := by dsimp only [k]; linarith + obtain ⟨C,hC,hRiesz⟩ := riesz_character_log_power A (2*k) hA (by positivity) + obtain ⟨X0,hX0⟩ := eventually_atTop.1 hRiesz + refine ⟨5*C+4,by positivity,?_⟩ + filter_upwards [eventually_ge_atTop X0,eventually_log_rpow_le_self k] with X hthreshold hscale + intro q _ chi hchi hq + obtain ⟨hX3,hpowX⟩ := hscale + let L : ℝ := Real.log X + let delta : ℝ := L^(-k) + let Y : ℝ := (1+delta)*X + let f : ℕ → ℂ := fun n => chi n*(ArithmeticFunction.vonMangoldt n:ℂ) + obtain ⟨hd,hd1,hdX,hXY,hY2,hlogs,hlogY⟩ := recovery_scale_bounds k hk hX3 hpowX + have hXp : 0 < X := by linarith + have hL1 : 1 ≤ L := ((Real.lt_log_iff_exp_lt hXp).mpr (Real.exp_one_lt_three.trans_le hX3)).le + have hLp : 0 < L := by linarith + have hYp : 0 < Y := hXp.trans_le hXY + have hlogYp : 0 < Real.log Y := hLp.trans_le hlogs + have hqY : (q:ℝ) ≤ (Real.log Y)^A := + hq.trans (Real.rpow_le_rpow hLp.le hlogs hA.le) + have hx := hX0 X hthreshold q chi hchi hq + have hy := hX0 Y (hthreshold.trans hXY) q chi hchi hqY + change ‖rieszSum f X‖ ≤ C*X/L^(2*k) at hx + have hden : 0 < L^(2*k) := Real.rpow_pos_of_pos hLp _ + have hdenY : L^(2*k) ≤ (Real.log Y)^(2*k) := Real.rpow_le_rpow hLp.le hlogs (by positivity) + have hy' : ‖rieszSum f Y‖ ≤ 2*C*X/L^(2*k) := by + calc + _ ≤ C*Y/(Real.log Y)^(2*k) := hy + _ ≤ C*Y/L^(2*k) := div_le_div_of_nonneg_left (by positivity) hden hdenY + _ ≤ C*(2*X)/L^(2*k) := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hY2 hC.le) hden.le + _ = _ := by ring + have hnum : (1+delta)*‖rieszSum f Y‖+‖rieszSum f X‖ ≤ 5*C*X/L^(2*k) := by + have h1 := mul_le_mul_of_nonneg_left hy' (show 0 ≤ 1+delta by linarith) + have h2 := mul_le_mul_of_nonneg_right (show 1+delta ≤ 2 by linarith) (show 0 ≤ 2*C*X/L^(2*k) by positivity) + apply (add_le_add (h1.trans h2) hx).trans_eq + ring + have hproduct : delta*L^(2*k) = L^k := recovery_power_product hLp k + have hterm : ((1+delta)*‖rieszSum f Y‖+‖rieszSum f X‖)/delta ≤ 5*C*X/L^M := by + calc + _ ≤ (5*C*X/L^(2*k))/delta := div_le_div_of_nonneg_right hnum hd.le + _ = 5*C*X/L^k := by rw [div_div,mul_comm (L^(2*k)) delta,hproduct] + _ ≤ _ := div_le_div_of_nonneg_left (by positivity) (Real.rpow_pos_of_pos hLp M) + (Real.rpow_le_rpow_of_exponent_le hL1 (by dsimp only [k]; linarith)) + have hdeltaL : delta*L = L^(-M) := recovery_power_times_log hLp M + have htail : (delta*X+1)*Real.log Y ≤ 4*X/L^M := by + calc + _ ≤ (2*delta*X)*(2*L) := mul_le_mul (by nlinarith only [hdX]) hlogY hlogYp.le (by positivity) + _ = 4*X*(delta*L) := by ring + _ = 4*X*L^(-M) := by rw [hdeltaL] + _ = _ := by rw [Real.rpow_neg hLp.le,div_eq_mul_inv] + have hcoeff : ∀ n : ℕ, 0 < n → ‖f n‖ ≤ Real.log (n:ℝ) := fun n _ => character_vonMangoldt_norm_le chi n + have hsharp := sharpSum_norm_le_riesz f hcoeff (show 1 ≤ X by linarith) hd + change ‖sharpSum f X‖ ≤ (5*C+4)*X/L^M + apply (hsharp.trans (add_le_add hterm htail)).trans_eq + ring + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/StationaryPhase.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/StationaryPhase.lean new file mode 100644 index 0000000000000000000000000000000000000000..af6889e73ed2c9c359414a2d46f7650089545b73 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/StationaryPhase.lean @@ -0,0 +1,75 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PairCollisionCount + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosKloosterman.PrimePower + +variable {R : Type*} [CommRing R] [Fintype R] + +attribute [local instance] Classical.decEq + +noncomputable def stationaryUnits (q a b : R) : Finset Rˣ := + Finset.univ.filter fun u => q * (a - b * (↑u⁻¹ : R)^2) = 0 + +private theorem sum_shift (ψ : AddChar R ℂ) (a b q : R) (hq : q^2 = 0) (z : R) : + sum ψ a b = ∑ u : Rˣ, + ψ (a * (u : R) + b * (↑u⁻¹ : R)) * + ψ (z * (q * (a - b * (↑u⁻¹ : R)^2))) := by + have ht : (q*z)^2 = 0 := by rw [mul_pow, hq, zero_mul] + have he := Equiv.sum_comp (shiftEquiv (q*z) ht) + (fun u : Rˣ => ψ (a * (u : R) + b * (↑u⁻¹ : R))) + unfold sum + rw [← he] + apply Finset.sum_congr rfl + intro u _ + change ψ (a * (shiftUnit u (q*z) ht : R) + + b * (↑(shiftUnit u (q*z) ht)⁻¹ : R)) = _ + rw [phase_shift, AddChar.map_add_eq_mul] + congr 1 + congr 1 + ring + +theorem stationary_phase_identity (ψ : AddChar R ℂ) (hψ : ψ.IsPrimitive) + (a b q : R) (hq : q^2 = 0) : + sum ψ a b = ∑ u ∈ stationaryUnits q a b, + ψ (a * (u : R) + b * (↑u⁻¹ : R)) := by + have hcard : (Fintype.card R : ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + apply mul_left_cancel₀ hcard + calc + (Fintype.card R : ℂ) * sum ψ a b = ∑ _z : R, sum ψ a b := by simp + _ = ∑ z : R, ∑ u : Rˣ, + ψ (a * (u : R) + b * (↑u⁻¹ : R)) * + ψ (z * (q * (a - b * (↑u⁻¹ : R)^2))) := by + apply Finset.sum_congr rfl + intro z _ + exact sum_shift ψ a b q hq z + _ = ∑ u : Rˣ, ψ (a * (u : R) + b * (↑u⁻¹ : R)) * + (∑ z : R, ψ (z * (q * (a - b * (↑u⁻¹ : R)^2)))) := by + rw [Finset.sum_comm] + simp_rw [Finset.mul_sum] + _ = _ := by + simp_rw [AddChar.sum_mulShift _ hψ] + rw [Finset.mul_sum] + simp [stationaryUnits, Finset.sum_filter, mul_comm] + +theorem norm_sum_le_stationary_card (ψ : AddChar R ℂ) (hψ : ψ.IsPrimitive) + (a b q : R) (hq : q^2 = 0) : + ‖sum ψ a b‖ ≤ (stationaryUnits q a b).card := by + rw [stationary_phase_identity ψ hψ a b q hq] + calc + _ ≤ ∑ u ∈ stationaryUnits q a b, ‖ψ (a * (u : R) + b * (↑u⁻¹ : R))‖ := + norm_sum_le _ _ + _ = _ := by simp [AddChar.norm_apply] + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/WeightedAnomalyConvergence.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/WeightedAnomalyConvergence.lean new file mode 100644 index 0000000000000000000000000000000000000000..da1d71b2648a8174294f58cc288c2e7e89563c65 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/WeightedAnomalyConvergence.lean @@ -0,0 +1,290 @@ +import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral +import OAI.NumberTheory.Jacobsthal.Analysis.BoundaryProductLimit +import OAI.NumberTheory.Jacobsthal.Estimates.BoundaryReferenceConvergence +import OAI.NumberTheory.Jacobsthal.Estimates.OmissionTiltDecay + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.BoundaryAnomaly + +open FinitePathGeometry ReferenceAdmission ReferencePruning +open VariablePrimeTilt OmissionTiltDecay ReferenceBenchmarkDecay + +noncomputable def anomaly (w : ℝ) (i : Side) (r : ℝ) : ℝ := + referencePolynomial w (boundaryPrimes w) i r- + survivorProduct (boundaryPrimes w)*benchmark i (r/2) + +theorem boundary_product_bounds (w : ℝ) : + 0 ≤ survivorProduct (boundaryPrimes w) ∧ survivorProduct (boundaryPrimes w) ≤ 1 := by + apply survivorProduct_bounds + intro p hp + obtain ⟨hpp,_⟩ := Finset.mem_filter.mp hp + exact (by norm_num : 1 ≤ 2).trans (Nat.mem_primesLE.mp hpp).2.two_le + +theorem anomaly_le_omission_and_benchmark (w r : ℝ) (i : Side) : + |anomaly w i r| ≤ omissionMass w r i+|benchmark i (r/2)-1| := by + have hp := boundary_product_bounds w + have hd := boundary_reference_discrepancy w r i + have he : anomaly w i r = + (referencePolynomial w (boundaryPrimes w) i r-survivorProduct (boundaryPrimes w))- + survivorProduct (boundaryPrimes w)*(benchmark i (r/2)-1) := by + unfold anomaly + ring + rw [he] + apply (abs_sub _ _).trans + rw [abs_mul,abs_of_nonneg hp.1] + exact add_le_add hd (by simpa only [one_mul] using mul_le_mul_of_nonneg_right hp.2 (abs_nonneg _)) + +theorem actual_boundary_anomaly_decay : ∃ C w₀ : ℝ,0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ r : ℝ,2 ≤ r → ∀ i : Side, + |anomaly w i r| ≤ C*Real.exp (-(1/128:ℝ)*r*Real.log (r+2)) := by + obtain ⟨CO,w₀,hCO,hw₀,hO⟩ := actual_omission_decay + obtain ⟨CB,hCB,hB⟩ := boundary_benchmark_decay + refine ⟨CO+CB,w₀,by positivity,hw₀,?_⟩ + intro w hw r hr i + have hr0 : 0 ≤ r := by linarith + have hl0 : 0 ≤ Real.log (r+2) := Real.log_nonneg (by linarith) + have he : Real.exp (-(1/32:ℝ)*r*Real.log (r+2)) ≤ + Real.exp (-(1/128:ℝ)*r*Real.log (r+2)) := + Real.exp_le_exp.mpr (by nlinarith [mul_nonneg hr0 hl0]) + calc + _ ≤ omissionMass w r i+|benchmark i (r/2)-1| := anomaly_le_omission_and_benchmark w r i + _ ≤ CO*Real.exp (-(1/32:ℝ)*r*Real.log (r+2))+ + CB*Real.exp (-(1/128:ℝ)*r*Real.log (r+2)) := add_le_add (hO w hw r hr i) (hB r hr i) + _ ≤ CO*Real.exp (-(1/128:ℝ)*r*Real.log (r+2))+ + CB*Real.exp (-(1/128:ℝ)*r*Real.log (r+2)) := + add_le_add_left (mul_le_mul_of_nonneg_left he hCO.le) _ + _ = _ := by ring + +theorem actual_boundary_anomaly_exponential : ∃ C c w₀ : ℝ,0 < C ∧ 0 < c ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ r : ℝ,2 ≤ r → ∀ i : Side, + |anomaly w i r| ≤ C*Real.exp (-c*r) := by + obtain ⟨C,w₀,hC,hw₀,h⟩ := actual_boundary_anomaly_decay + refine ⟨C,Real.log 4/128,w₀,hC,div_pos (Real.log_pos (by norm_num)) (by norm_num),hw₀,?_⟩ + intro w hw r hr i + have hl : Real.log 4 ≤ Real.log (r+2) := Real.log_le_log (by norm_num) (by linarith) + apply (h w hw r hr i).trans + apply mul_le_mul_of_nonneg_left _ hC.le + apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left hl (by linarith : 0 ≤ r)] + +end NumberTheoryLean.BoundaryAnomaly + +end + +section + +open _root_.MeasureTheory _root_.Set _root_.Filter +open _root_.Erdos970.MeasureTheory _root_.Erdos970.Set _root_.Erdos970.Filter +open scoped Topology +namespace ErdosContinuousAnomaly +open ErdosContinuousBoundary +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.ReferenceAdmission +open NumberTheoryLean.ReferenceBenchmarkDecay NumberTheoryLean.BoundaryAnomaly +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.BuchstabBridge + +noncomputable def continuousAnomaly (i : Side) (r : ℝ) : ℝ := + boundaryReference i r 2-(1/2)*benchmark i (r/2) + +theorem boundary_benchmark_bound (i : Side) {r : ℝ} (hr : 2 ≤ r) : + |benchmark i (r/2)| ≤ sieveA+1 := by + have hs : 1 ≤ r/2 := by linarith + have h := (benchmark_deviation_le_gap i hs).trans (gap_le_constant hs) + calc + _ = |(benchmark i (r/2)-1)+1| := by congr 1; ring + _ ≤ |benchmark i (r/2)-1|+|1| := abs_add_le _ _ + _ ≤ sieveA+1 := by simpa only [abs_one] using add_le_add h (le_refl (1:ℝ)) + +theorem continuousAnomaly_continuousOn (i : Side) : ContinuousOn (continuousAnomaly i) (Ici 2) := by + intro r hr + have hq : ContinuousAt (fun x : ℝ => boundaryReference i x 2) r := + ((boundaryReference_continuous i).comp (continuous_id.prodMk continuous_const)).continuousAt + have hb : ContinuousAt (fun x : ℝ => benchmark i (x/2)) r := by + cases i with + | even => exact (f_continuous sieveA).continuousAt.comp (continuousAt_id.div_const 2) + | odd => + have hx : r/2 ≠ 0 := by have h := hr; change 2 ≤ r at h; linarith + have hg : ContinuousAt (fun x : ℝ => x/2) r := continuousAt_id.div_const 2 + have hF : ContinuousAt (F sieveA) ((fun x : ℝ => x/2) r) := F_continuousAt sieveA hx + simpa only [Function.comp_def,benchmark] using hF.comp (f := fun x : ℝ => x/2) hg + exact (hq.sub (continuousAt_const.mul hb)).continuousWithinAt + +theorem anomaly_difference (w r : ℝ) (i : Side) : + anomaly w i r-continuousAnomaly i r = + (referencePolynomial w (boundaryPrimes w) i r-boundaryReference i r 2)- + (boundaryProduct w-1/2)*benchmark i (r/2) := by + unfold anomaly continuousAnomaly boundaryProduct + ring + +theorem uniform_anomaly_convergence (R eps : ℝ) (heps : 0 < eps) : + ∃ w₀ : ℝ,1 < w₀ ∧ ∀ w : ℝ,w₀ ≤ w → ∀ (i : Side) (r : ℝ),2 ≤ r → r ≤ R → + |anomaly w i r-continuousAnomaly i r| ≤ eps := by + let A : ℝ := sieveA+1 + have hA : 0 < A := by dsimp [A]; linarith [sieveA_pos] + obtain ⟨wQ,hwQ,hQ⟩ := boundary_two_convergence R (eps/2) (by positivity) + have ht := (boundaryProduct_tendsto_half.sub_const (1/2)).abs + have he := ht.eventually (Iio_mem_nhds (by simpa only [sub_self,abs_zero] using + (div_pos heps (by positivity : 0 < 2*A)))) + obtain ⟨wP,hwP⟩ := eventually_atTop.mp he + refine ⟨max wQ wP,hwQ.trans_le (le_max_left _ _),?_⟩ + intro w hw i r hr hrR + have hqw := hQ w ((le_max_left _ _).trans hw) i r hrR + have hpw := hwP w ((le_max_right _ _).trans hw) + have hb : |benchmark i (r/2)| ≤ A := boundary_benchmark_bound i hr + have hp : |boundaryProduct w-1/2| * |benchmark i (r/2)| ≤ (eps/(2*A))*A := by + exact mul_le_mul hpw.le hb (abs_nonneg _) (by positivity) + rw [anomaly_difference] + apply (abs_sub _ _).trans + rw [abs_mul] + calc + _ ≤ eps/2+(eps/(2*A))*A := add_le_add hqw hp + _ = eps := by field_simp [ne_of_gt hA]; ring + +end ErdosContinuousAnomaly + +end + +section + +open _root_.Set _root_.Filter _root_.Erdos970.Set _root_.Erdos970.Filter +open scoped Topology +namespace ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.BoundaryAnomaly + +theorem anomaly_tendsto (i : Side) {r : ℝ} (hr : 2 ≤ r) : + Tendsto (fun w : ℝ => anomaly w i r) atTop (𝓝 (continuousAnomaly i r)) := by + apply Metric.tendsto_atTop.mpr + intro eps heps + obtain ⟨w₀,_hw₀,h⟩ := uniform_anomaly_convergence r (eps/2) (by positivity) + refine ⟨w₀,fun w hw => ?_⟩ + rw [Real.dist_eq] + exact (h w hw i r hr le_rfl).trans_lt (by linarith) + +theorem common_anomaly_decay : ∃ C w₀ : ℝ,0 < C ∧ 1 < w₀ ∧ + (∀ w : ℝ,w₀ ≤ w → ∀ r : ℝ,2 ≤ r → ∀ i : Side, + |anomaly w i r| ≤ C*Real.exp (-(1/128:ℝ)*r*Real.log (r+2))) ∧ + (∀ r : ℝ,2 ≤ r → ∀ i : Side, + |continuousAnomaly i r| ≤ C*Real.exp (-(1/128:ℝ)*r*Real.log (r+2))) := by + obtain ⟨C,w₀,hC,hw₀,h⟩ := actual_boundary_anomaly_decay + refine ⟨C,w₀,hC,hw₀,h,?_⟩ + intro r hr i + apply le_of_tendsto (anomaly_tendsto i hr).abs + filter_upwards [eventually_ge_atTop w₀] with w hw + exact h w hw r hr i + +theorem common_anomaly_exponential : ∃ C c w₀ : ℝ,0 < C ∧ 0 < c ∧ 1 < w₀ ∧ + (∀ w : ℝ,w₀ ≤ w → ∀ r : ℝ,2 ≤ r → ∀ i : Side, + |anomaly w i r| ≤ C*Real.exp (-c*r)) ∧ + (∀ r : ℝ,2 ≤ r → ∀ i : Side, + |continuousAnomaly i r| ≤ C*Real.exp (-c*r)) := by + obtain ⟨C,c,w₀,hC,hc,hw₀,h⟩ := actual_boundary_anomaly_exponential + refine ⟨C,c,w₀,hC,hc,hw₀,h,?_⟩ + intro r hr i + apply le_of_tendsto (anomaly_tendsto i hr).abs + filter_upwards [eventually_ge_atTop w₀] with w hw + exact h w hw r hr i + +end ErdosContinuousAnomaly + +end + +section + +open _root_.Set _root_.Filter _root_.MeasureTheory +open _root_.Erdos970.Set _root_.Erdos970.Filter _root_.Erdos970.MeasureTheory +open scoped Topology +namespace ErdosBoundaryIntegral +open ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry + +noncomputable def shiftedAnomaly (i : Side) (y : ℝ) : ℝ := continuousAnomaly i (2*y+2) + +theorem shiftedAnomaly_continuousOn (i : Side) : ContinuousOn (shiftedAnomaly i) (Ici 0) := by + have hc : Continuous (fun y : ℝ => 2*y+2) := continuous_const.mul continuous_id |>.add continuous_const + exact (continuousAnomaly_continuousOn i).comp' hc.continuousOn (by + intro y hy; change 0 ≤ y at hy; change 2 ≤ 2*y+2; linarith) + +theorem shifted_anomaly_moment_integrable (i : Side) (n : ℕ) : + IntegrableOn (fun y : ℝ => y^n*shiftedAnomaly i y) (Ioi 0) := by + obtain ⟨C,c,_w₀,hC,hc,_hw₀,_hD,hA⟩ := common_anomaly_exponential + have hg : IntegrableOn (fun y : ℝ => y^n*Real.exp (-c*y)) (Ioi 0) := by + have h := integrableOn_rpow_mul_exp_neg_mul_rpow (s := (n:ℝ)) (p := 1) + (by have hn := Nat.cast_nonneg (α := ℝ) n; linarith) (by norm_num) hc + simpa only [Real.rpow_natCast,Real.rpow_one] using! h + have hcont : ContinuousOn (fun y : ℝ => y^n*shiftedAnomaly i y) (Ioi 0) := + (continuous_id.pow n).continuousOn.mul ((shiftedAnomaly_continuousOn i).mono Ioi_subset_Ici_self) + apply (hg.const_mul C).mono' (hcont.aestronglyMeasurable measurableSet_Ioi) + filter_upwards [ae_restrict_mem measurableSet_Ioi] with y hy + have hy0 : 0 < y := hy + have ha : |shiftedAnomaly i y| ≤ C*Real.exp (-c*y) := by + apply (hA (2*y+2) (by linarith) i).trans + apply mul_le_mul_of_nonneg_left _ hC.le + apply Real.exp_le_exp.mpr + nlinarith + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (pow_nonneg hy0.le n)] + calc + _ ≤ y^n*(C*Real.exp (-c*y)) := mul_le_mul_of_nonneg_left ha (pow_nonneg hy0.le n) + _ = C*(y^n*Real.exp (-c*y)) := by ring + +end ErdosBoundaryIntegral + +end + +section + +open _root_.Set _root_.Filter _root_.Erdos970.Set _root_.Erdos970.Filter +open scoped Topology +namespace ErdosContinuousAnomaly +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.BoundaryAnomaly + +theorem weighted_anomaly_convergence : ∃ c : ℝ,0 < c ∧ + ∀ eps : ℝ,0 < eps → ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ r : ℝ,2 ≤ r → ∀ i : Side, + |anomaly w i r-continuousAnomaly i r| ≤ eps*Real.exp (-c*r) := by + obtain ⟨C,c₀,wA,hC,hc₀,hwA,hdiscrete,hcontinuous⟩ := common_anomaly_exponential + let c := c₀/2 + have hc : 0 < c := by dsimp [c]; positivity + refine ⟨c,hc,?_⟩ + intro eps heps + have ht : Tendsto (fun r : ℝ => (2*C)*Real.exp (-c*r)) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (0:ℝ) c hc).const_mul (2*C) + simpa only [Real.rpow_zero,one_mul,mul_zero] using h + obtain ⟨R₁,hR₁⟩ := eventually_atTop.mp (ht.eventually (Iio_mem_nhds heps)) + let R := max 2 R₁ + obtain ⟨wQ,hwQ,hQ⟩ := uniform_anomaly_convergence R (eps*Real.exp (-c*R)) (by positivity) + refine ⟨max wA wQ,hwA.trans_le (le_max_left _ _),?_⟩ + intro w hw r hr i + have hwa : wA ≤ w := (le_max_left _ _).trans hw + have hwq : wQ ≤ w := (le_max_right _ _).trans hw + by_cases hrR : r ≤ R + · apply (hQ w hwq i r hr hrR).trans + apply mul_le_mul_of_nonneg_left _ heps.le + apply Real.exp_le_exp.mpr + nlinarith + · have htail : 2*C*Real.exp (-c*r) ≤ eps := + (hR₁ r ((le_max_right 2 R₁).trans (le_of_not_ge hrR))).le + have hbound : |anomaly w i r-continuousAnomaly i r| ≤ 2*C*Real.exp (-c₀*r) := by + calc + _ ≤ |anomaly w i r|+|continuousAnomaly i r| := abs_sub _ _ + _ ≤ C*Real.exp (-c₀*r)+C*Real.exp (-c₀*r) := + add_le_add (hdiscrete w hwa r hr i) (hcontinuous r hr i) + _ = _ := by ring + have he : -c₀*r=(-c*r)+(-c*r) := by dsimp [c]; ring + rw [he,Real.exp_add] at hbound + calc + _ ≤ 2*C*(Real.exp (-c*r)*Real.exp (-c*r)) := hbound + _ = (2*C*Real.exp (-c*r))*Real.exp (-c*r) := by ring + _ ≤ eps*Real.exp (-c*r) := mul_le_mul_of_nonneg_right htail (Real.exp_pos _).le + +end ErdosContinuousAnomaly + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ZeroFrequencyBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ZeroFrequencyBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..557c3d8d63b160f3fe7b00c30529ddd0deb190f5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Harmonic/ZeroFrequencyBounds.lean @@ -0,0 +1,95 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.DilationCoordinates + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +noncomputable def restrictionCount (H T : ℕ) [NeZero H] [NeZero T] (a : (ZMod T)ˣ) : ℝ := + (unitClass (H*T) T (dvd_mul_left T H) a).card + +theorem restrictionCount_nonneg (H T : ℕ) [NeZero H] [NeZero T] (a : (ZMod T)ˣ) : + 0 ≤ restrictionCount H T a := Nat.cast_nonneg _ + +theorem restrictionCount_le_modulus (H T : ℕ) [NeZero H] [NeZero T] (a : (ZMod T)ˣ) : + restrictionCount H T a ≤ (H*T : ℕ) := by + have hphi : 1 ≤ T.totient := Nat.succ_le_iff.mpr (Nat.totient_pos.mpr (NeZero.pos T)) + have hn : (unitClass (H*T) T (dvd_mul_left T H) a).card ≤ H*T := by + calc + _ = 1*(unitClass (H*T) T (dvd_mul_left T H) a).card := by simp + _ ≤ T.totient*(unitClass (H*T) T (dvd_mul_left T H) a).card := + Nat.mul_le_mul_right _ hphi + _ = (H*T).totient := unitClass_card_mul_totient (H*T) T (dvd_mul_left T H) a + _ ≤ H*T := Nat.totient_le _ + unfold restrictionCount + exact_mod_cast hn + +theorem restrictionCount_ratio (H T : ℕ) [NeZero H] [NeZero T] (a : (ZMod T)ˣ) : + restrictionCount H T a = ((H*T).totient : ℝ)/(T.totient : ℝ) := by + have ht : (T.totient : ℝ) ≠ 0 := by + exact_mod_cast (Nat.totient_pos.mpr (NeZero.pos T)).ne' + apply (eq_div_iff ht).mpr + have h : (T.totient : ℝ)*restrictionCount H T a = (H*T).totient := by + unfold restrictionCount + exact_mod_cast unitClass_card_mul_totient (H*T) T (dvd_mul_left T H) a + simpa only [mul_comm] using h + +theorem restricted_zero_eq_real (H T : ℕ) [NeZero H] [NeZero T] + (a : (ZMod T)ˣ) (c : (ZMod (H*T))ˣ) : + restrictedSum (H*T) T (dvd_mul_left T H) a c 0 0 = (restrictionCount H T a : ℂ) := by + simpa only [restrictionCount, Complex.ofReal_natCast] using + restrictedSum_zero (H*T) T (dvd_mul_left T H) a c + +private theorem product_approx_error (a b u v : ℝ) (ha0 : 0 ≤ a) (hv0 : 0 ≤ v) + (ha : |a-u| ≤ 1) (hb : |b-v| ≤ 1) : |a*b-u*v| ≤ u+v+1 := by + have hau : a ≤ u+1 := by have h := (abs_le.mp ha).2; linarith + calc + _ = |a*(b-v)+v*(a-u)| := by congr 1; ring + _ ≤ |a*(b-v)|+|v*(a-u)| := abs_add_le _ _ + _ = a*|b-v|+v*|a-u| := by rw [abs_mul, abs_mul, abs_of_nonneg ha0, abs_of_nonneg hv0] + _ ≤ a*1+v*1 := add_le_add (mul_le_mul_of_nonneg_left hb ha0) (mul_le_mul_of_nonneg_left ha hv0) + _ ≤ _ := by linarith + +theorem product_count_error (P Q : ProgressionInterval) (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) : + |(P.points.card : ℝ)*(Q.points.card : ℝ)- + (intervalLength P/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))| ≤ + intervalLength P+intervalLength Q+1 := by + have h := product_approx_error (P.points.card : ℝ) (Q.points.card : ℝ) + (intervalLength P/(P.step : ℝ)) (intervalLength Q/(Q.step : ℝ)) (Nat.cast_nonneg _) + (div_nonneg (intervalLength_nonneg Q hQ) (Nat.cast_nonneg _)) + (interval_count_error P hP) (interval_count_error Q hQ) + exact h.trans (by linarith [interval_average_le_length P hP, interval_average_le_length Q hQ]) + +theorem zero_frequency_rounding (H T : ℕ) [NeZero H] [NeZero T] (a : (ZMod T)ˣ) + (P Q : ProgressionInterval) (hP : P.left ≤ P.right) (hQ : Q.left ≤ Q.right) : + |(P.points.card : ℝ)*(Q.points.card : ℝ)*restrictionCount H T a/((H*T : ℕ) : ℝ)^2 - + (intervalLength P/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))* + restrictionCount H T a/((H*T : ℕ) : ℝ)^2| ≤ + (intervalLength P+intervalLength Q+1)/((H*T : ℕ) : ℝ) := by + have hN : (0 : ℝ) < (H*T : ℕ) := by exact_mod_cast Nat.mul_pos (NeZero.pos H) (NeZero.pos T) + have hz0 := restrictionCount_nonneg H T a + have hzN := restrictionCount_le_modulus H T a + have hU := intervalLength_nonneg P hP + have hV := intervalLength_nonneg Q hQ + calc + _ = |(P.points.card : ℝ)*(Q.points.card : ℝ)- + (intervalLength P/(P.step : ℝ))*(intervalLength Q/(Q.step : ℝ))| * + restrictionCount H T a/((H*T : ℕ) : ℝ)^2 := by + rw [← sub_div, ← sub_mul, abs_div, abs_mul, abs_of_nonneg hz0, abs_of_nonneg (sq_nonneg (((H*T : ℕ) : ℝ)))] + _ ≤ (intervalLength P+intervalLength Q+1)*((H*T : ℕ) : ℝ)/((H*T : ℕ) : ℝ)^2 := by + apply div_le_div_of_nonneg_right _ (sq_nonneg _) + exact mul_le_mul (product_count_error P Q hP hQ) hzN hz0 (by linarith) + _ = _ := by field_simp + +end ErdosHyperbolaError + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Main.lean b/lean/OAI/NumberTheory/Jacobsthal/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..1170813dbc662ca0b53af19f0b0924f37f627420 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Main.lean @@ -0,0 +1,2 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.QuadraticBound +import OAI.NumberTheory.Jacobsthal.Conclusions.IteratedLogBound diff --git a/lean/OAI/NumberTheory/Jacobsthal/Model.lean b/lean/OAI/NumberTheory/Jacobsthal/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..f855ae990b92fa688d08e03e597df5268822a641 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Model.lean @@ -0,0 +1,24 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +namespace NumberTheoryLean.Targets + +open Filter +open scoped Topology + +def IsJacobsthalBound (k m : ℕ) : Prop := + ∀ n : ℕ, 0 < n → n.primeFactors.card ≤ k → + ∀ a : ℤ, ∃ i : ℕ, i < m ∧ (a + i).natAbs.Coprime n + +def JacobsthalQuadratic : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ k : ℕ, 0 < k → + ∃ m : ℕ, IsJacobsthalBound k m ∧ (m : ℝ) ≤ C * (k : ℝ) ^ 2 + +end NumberTheoryLean.Targets + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxFourSum.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxFourSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..feaf5d1de2d03b7c6eeba46c1fbe505e4551ade8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxFourSum.lean @@ -0,0 +1,153 @@ +import OAI.NumberTheory.Jacobsthal.Primes.TwoPrimeObservableSum +import OAI.NumberTheory.Jacobsthal.Sieve.CofactorAllChoiceBounds + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ParentTailPartition +open ErdosCofactorChoices SingletonBinSelection TwoSingletonBins TwoPrimeObservableSum +open BinCutSelections ParentCofactorChoices PartitionedSelections + +attribute [local instance] Classical.propDecidable + +noncomputable def aboveIndexSet {n : ℕ} (j : Fin n) : Finset (Fin n) := Finset.univ.filter (fun k => j funext k <;> + simp only [restrictMultiplicity,eraseTwo,eraseMultiplicity,parentCofactorMultiplicity, + aboveMultiplicity,belowMultiplicity,aboveIndexSet,Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_compl] <;> + split_ifs <;> omega + +noncomputable def parentCofactorSelection {n : ℕ} (f : Fin n → Finset ℕ) (i j : Fin n) : Fin n → Finset ℕ := + eraseSelection (aboveSelection f j) i + +theorem filled_parent_tail {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i j : Fin n) (hji : j < i) (f g : Fin n → Finset ℕ) + (hf : f ∈ selections P (parentCofactorMultiplicity m i j)) + (hg : g ∈ selections P (belowMultiplicity m j)) (p u : ℕ) : + parentCofactorSelection (fillTwo (joinSelection (aboveIndexSet j) f g) i j p u) i j=f ∧ + belowSelection (fillTwo (joinSelection (aboveIndexSet j) f g) i j p u) j=g := by + have hfmem := (mem_selections P _ f).mp hf + have hgmem := (mem_selections P _ g).mp hg + constructor <;> funext k + · by_cases hki : k=i + · subst k + have he : f i=∅ := Finset.card_eq_zero.mp ((hfmem i).2.trans (cofactor_slots_zero m i j).1) + simp [parentCofactorSelection,eraseSelection,he] + · by_cases hjk : j + G (pickedPrime (fillTwo f i j p u) i) (pickedPrime (fillTwo f i j p u) j) + (selectionProduct (parentCofactorSelection (fillTwo f i j p u) i j)) + (selectionProduct (belowSelection (fillTwo f i j p u) j)) + change (∑ f ∈ selections P (eraseTwo m i j),((p:ℝ)⁻¹*(u:ℝ)⁻¹*(selectionProduct f:ℝ)⁻¹)*H f)=_ + calc + _ = ∑ f ∈ selections P (eraseTwo m i j),(selectionProduct f:ℝ)⁻¹*((p:ℝ)⁻¹*(u:ℝ)⁻¹*H f) := by + apply Finset.sum_congr rfl + intro f _hf + ring + _ = _ := by + rw [partitioned_weighted_sum P (eraseTwo m i j) (aboveIndexSet j)] + have he := residual_partition_multiplicity m i j hji + rw [he.1,he.2] + apply Finset.sum_congr rfl + intro f hf + apply Finset.sum_congr rfl + intro g hg + have hpick := picked_fillTwo (joinSelection (aboveIndexSet j) f g) i j hij p u + have hsplit := filled_parent_tail P m i j hji f g hf hg p u + dsimp only [H] + rw [hpick.1,hpick.2,hsplit.1,hsplit.2] + ring + +theorem four_coordinate_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hP : ∀ i,∀ p ∈ P i,p.Prime) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (i j : Fin n) (hji : j < i) (hi : m i=1) (hj : m j=1) (G : ℕ → ℕ → ℕ → ℕ → ℝ) : + (∑ f ∈ selections P m,(selectionProduct f:ℝ)⁻¹* + G (pickedPrime f i) (pickedPrime f j) (selectionProduct (parentCofactorSelection f i j)) (selectionProduct (belowSelection f j)))= + ∑ p ∈ P i,∑ u ∈ P j,∑ q ∈ cofactorChoices P (parentCofactorMultiplicity m i j),∑ d ∈ cofactorChoices P (belowMultiplicity m j), + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹*(d:ℝ)⁻¹)*G p u q d := by + rw [four_selection_sum P m i j hji hi hj] + apply Finset.sum_congr rfl + intro p _hp + apply Finset.sum_congr rfl + intro u _hu + calc + _ = ∑ f ∈ selections P (parentCofactorMultiplicity m i j),∑ d ∈ cofactorChoices P (belowMultiplicity m j), + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(selectionProduct f:ℝ)⁻¹*(d:ℝ)⁻¹)*G p u (selectionProduct f) d := by + apply Finset.sum_congr rfl + intro f _hf + exact cofactor_sum P (belowMultiplicity m j) hP hd (fun d => + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(selectionProduct f:ℝ)⁻¹*(d:ℝ)⁻¹)*G p u (selectionProduct f) d) + _ = _ := cofactor_sum P (parentCofactorMultiplicity m i j) hP hd (fun q => + ∑ d ∈ cofactorChoices P (belowMultiplicity m j),((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹*(d:ℝ)⁻¹)*G p u q d) +end NumberTheoryLean.FourCoordinateBoxSum + + + +namespace NumberTheoryLean.ActualBoxFourSum +open ErdosCofactorChoices ErdosSubsetWord FourCoordinateBoxSum TwoPrimeObservableSum ParentTailPartition +open BinCutSelections ParentCofactorChoices +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinEndpoints + + +theorem actual_box_four_coordinate_sum {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (i j : Fin (binCount w top xi)) + (hji : j < i) (hi : m i=1) (hj : m j=1) (G : ℕ → ℕ → ℕ → ℕ → ℝ) : + (∑ f ∈ selections (globalBins w top xi) m,(selectionProduct f:ℝ)⁻¹* + G (pickedPrime f i) (pickedPrime f j) (selectionProduct (parentCofactorSelection f i j)) (selectionProduct (belowSelection f j)))= + ∑ p ∈ globalBins w top xi i,∑ u ∈ globalBins w top xi j, + ∑ q ∈ cofactorChoices (globalBins w top xi) (parentCofactorMultiplicity m i j), + ∑ d ∈ cofactorChoices (globalBins w top xi) (belowMultiplicity m j), + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(q:ℝ)⁻¹*(d:ℝ)⁻¹)*G p u q d := + four_coordinate_sum (globalBins w top xi) m + (fun k _p hp => (bin_prime_in_source (zero_lt_one.trans hw) htop hxi k hp).1) + (fun k l hkl => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) i j hji hi hj G +end NumberTheoryLean.ActualBoxFourSum + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxHarmonicInverse.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxHarmonicInverse.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef90e61f0c33f04f25520c7674299faa142e2310 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxHarmonicInverse.lean @@ -0,0 +1,232 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.TripleWeightDensity +import OAI.NumberTheory.Jacobsthal.Sieve.ActualCofactorArithmetic + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseCells +open ErdosInverseSampling +attribute [local instance] Classical.decEq + +theorem retained_initial_cell (P Q U : Finset ℕ) (a : ℕ → ℕ) (B xi Z sigma : ℝ) (k M0 : ℕ) [NeZero M0] + (hB : 0 < B) (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hZ : 0 < Z) (hsigma : 0 ≤ sigma) + (hQ : ∀ q ∈ Q,B/(1+xi)^k ≤ (q : ℝ) ∧ (q : ℝ) ≤ B) + (witness : (ℕ × ℕ) → ℕ → Prop) (hPpos : 0 < harmonicMass P) (hUpos : 0 < harmonicMass U) + (hPspread : ∀ p ∈ P,∀ r ∈ P,(p : ℝ)⁻¹ ≤ (1+xi)*(r : ℝ)⁻¹) + (hUspread : ∀ u ∈ U,∀ r ∈ U,(u : ℝ)⁻¹ ≤ (1+xi)*(r : ℝ)⁻¹) + (hBad : sigma*(harmonicMass P*harmonicMass Q*harmonicMass U) < weightedWitness P Q U witness) + (hDiscard : (∑ q ∈ discardedPoints Q (initialLabel a B xi k M0) (B/Z),(q : ℝ)⁻¹) ≤ + (sigma/2)*(∑ q ∈ Q,(q : ℝ)⁻¹)) : + ∃ i : InitialLabel k M0,B/Z ≤ ((initialCell Q a B xi k M0 i).card : ℝ) ∧ + (initialCell Q a B xi k M0 i).Nonempty ∧ + (sigma/16)*((P.product (initialCell Q a B xi k M0 i)).card : ℝ)*(U.card : ℝ) ≤ + ((witnessPairs (P.product (initialCell Q a B xi k M0 i)) U witness).card : ℝ) := by + have hDen := mul_pos hPpos hUpos + have hCond := condition_harmonic_density P Q U witness sigma hDen hBad + obtain ⟨i,hlarge,hdense⟩ := exists_dense_retained_fiber Q (initialLabel a B xi k M0) (B/Z) sigma hsigma + (fun q => (q : ℝ)⁻¹) (fun q => (q : ℝ)⁻¹*conditionalReward P U witness q) + (fun _ _ => by positivity) (fun q _ => conditioned_reward_upper P U witness hDen q) hCond hDiscard + have hcardR : (0 : ℝ) < (initialCell Q a B xi k M0 i).card := (div_pos hB hZ).trans_le hlarge + have hcard : 0 < (initialCell Q a B xi k M0 i).card := by exact_mod_cast hcardR + have hne := Finset.card_pos.mp hcard + have hCpos : 0 < harmonicMass (initialCell Q a B xi k M0 i) := by + apply harmonicMass_pos _ hne + intro q hq + exact_mod_cast (initial_cell_interval Q a B xi k M0 hB hxi hQ i q hq).2.1 + have hWeighted := uncondition_harmonic_density P (initialCell Q a B xi k M0 i) U witness (sigma/2) hDen hdense + exact ⟨i,hlarge,hne,triple_weighted_to_count P (initialCell Q a B xi k M0 i) U xi sigma hxi.le hxi1 + witness hPpos hCpos hUpos hPspread + (fun q hq r hr => initial_cell_weight_spread Q a B xi k M0 hB hxi hQ i q r hq hr) hUspread hWeighted.le⟩ + +end ErdosInverseCells + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseCells +open NumberTheoryLean ErdosCofactorChoices ErdosInverseBoxHeight ErdosInverseEuler ErdosInversePrimeBin ErdosInverseSampleCost ErdosInverseSampling +open NumberTheoryLean.LogarithmicBinScale + +theorem source_dense_initial_cell (C xi sigma alpha delta cp : ℝ) (hC : 0 ≤ C) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hsigma : 0 < sigma) (halpha : 0 < alpha) : + ∀ᶠ z : ℝ in atTop,1 < z ∧ ∀ R thetaP U thetaU : ℝ, + z^alpha ≤ R → sourceW z ≤ U → xi/4 ≤ thetaP → thetaP ≤ xi → xi/4 ≤ thetaU → thetaU ≤ xi → + ∀ (m : Fin (binCount (sourceW z) z xi) → ℕ) (a : ℕ → ℕ), + ((∑ j,m j : ℕ) : ℝ) ≤ C*Real.log (sourceB z) → + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + let k := ∑ j,m j + let P := primeBin R thetaP + let Uset := primeBin U thetaU + let M0 := smallModulus (sourceW z) + let witness := actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) cp + sigma*(harmonicMass P*harmonicMass Q*harmonicMass Uset) < weightedWitness P Q Uset witness → + ∃ (i : InitialLabel k M0) (q0 : ℕ), + q0 ∈ initialCell Q a S xi k M0 i ∧ + S/sourceZ z ≤ ((initialCell Q a S xi k M0 i).card : ℝ) ∧ + (sigma/16)*((P.product (initialCell Q a S xi k M0 i)).card : ℝ)*(Uset.card : ℝ) ≤ + ((witnessPairs (P.product (initialCell Q a S xi k M0 i)) Uset witness).card : ℝ) ∧ + (initialCell Q a S xi k M0 i ⊆ Q) ∧ + ∀ q ∈ initialCell Q a S xi k M0 i, + 0 < q ∧ Squarefree q ∧ (q : ℝ) ≤ cellUpper S xi i ∧ cellUpper S xi i ≤ (1+xi)*(q : ℝ) ∧ + Int.ModEq (M0 : ℤ) (q : ℤ) (q0 : ℤ) ∧ + Int.ModEq (M0 : ℤ) (cofactorHit q a : ℤ) (cofactorHit q0 a : ℤ) := by + filter_upwards [source_initial_discard_small C xi (sigma/2) hC hxi hxi1 (by positivity), + source_cofactor_cell_data C xi 1 hC hxi hxi1 zero_lt_one,source_span_geometry, + source_sample_population xi 1 0 hxi hxi1,sourceW_le_power alpha halpha,eventually_gt_atTop (1 : ℝ)] + with z hdiscard hdata hspan hpop hWR hz + refine ⟨hz,?_⟩ + intro R thetaP U thetaU hR hWU hPlow hPhigh hUlow hUhigh m a hm + dsimp only + intro hBad + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + let k := ∑ j,m j + let P := primeBin R thetaP + let Uset := primeBin U thetaU + let M0 := smallModulus (sourceW z) + let witness := actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) cp + let : NeZero M0 := ⟨(smallModulus_pos _).ne'⟩ + have hd := hdata m hm + have hZ : 0 < sourceZ z := Real.exp_pos _ + have hzpos : 0 < z := by linarith + have hRpos : 0 < R := (Real.rpow_pos_of_pos hzpos alpha).trans_le hR + have hUpos : 0 < U := hspan.1.trans_le hWU + have hthetaP : 0 ≤ thetaP := (by positivity : (0 : ℝ) ≤ xi/4).trans hPlow + have hthetaU : 0 ≤ thetaU := (by positivity : (0 : ℝ) ≤ xi/4).trans hUlow + have hPn : P.Nonempty := Finset.card_pos.mp (hpop R thetaP (hWR.trans hR) hPlow hPhigh).1 + have hUn : Uset.Nonempty := Finset.card_pos.mp (hpop U thetaU hWU hUlow hUhigh).1 + have hPmass : 0 < harmonicMass P := harmonicMass_pos P hPn + (fun p hp => ((mem_primeBin hRpos.le hthetaP p).mp hp).1.pos) + have hUmass : 0 < harmonicMass Uset := harmonicMass_pos Uset hUn + (fun u hu => ((mem_primeBin hUpos.le hthetaU u).mp hu).1.pos) + have hQrange : ∀ q ∈ Q,S/(1+xi)^k ≤ (q : ℝ) ∧ (q : ℝ) ≤ S := + fun q hq => actual_cofactor_range hspan.1 hspan.2.1 hxi m q hq + have hDisc : (∑ q ∈ discardedPoints Q (initialLabel a S xi k M0) (S/sourceZ z),(q : ℝ)⁻¹) ≤ + (sigma/2)*(∑ q ∈ Q,(q : ℝ)⁻¹) := hdiscard m a hm + obtain ⟨i,hlarge,hne,hDense⟩ := retained_initial_cell P Q Uset a S xi (sourceZ z) sigma k M0 + hd.1 hxi hxi1 hZ hsigma.le hQrange witness hPmass hUmass + (prime_bin_weight_spread R thetaP xi hRpos hthetaP hxi.le hPhigh) + (prime_bin_weight_spread U thetaU xi hUpos hthetaU hxi.le hUhigh) hBad hDisc + obtain ⟨q0,hq0⟩ := hne + refine ⟨i,q0,hq0,hlarge,hDense,labelFiber_subset Q (initialLabel a S xi k M0) i,?_⟩ + intro q hq + have hqQ := (mem_initialCell Q a S xi k M0 i q).mp hq |>.1 + have hqs := hd.2.2.2 q hqQ + have hinterval := initial_cell_interval Q a S xi k M0 hd.1 hxi hQrange i q hq + have hcong := initial_cell_congruences Q a S xi k M0 i q q0 hq hq0 + exact ⟨hqs.1,hqs.2,hinterval.2.2.1,hinterval.2.2.2,hcong.1,hcong.2⟩ + +end ErdosInverseCells + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseBoxApplication +open NumberTheoryLean ErdosCofactorChoices ErdosInverseCells ErdosInverseRefinement + ErdosInverseBoxHeight ErdosInverseEuler ErdosInverseSampleCost ErdosInverseSampling +open NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints + +theorem actual_box_nonstructured_harmonic (Clen Cparent aStar K alpha delta sigma : ℝ) (h : ℕ) + (hClen : 0 ≤ Clen) (hCparent : 0 ≤ Cparent) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (hK : 0 ≤ K) (halpha : 0 < alpha) (hd : 0 < delta) (hsigma : 0 < sigma) (hsigma1 : sigma ≤ 1) + (hh : 12 < aStar*(h : ℝ)/2) : + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ ∀ xi : ℝ,0 < xi → xi ≤ xi0 → + ∀ᶠ z : ℝ in atTop, + ∀ (m : Fin (binCount (sourceW z) z xi) → ℕ) + (i j : Fin (binCount (sourceW z) z xi)), + i ≠ j → m i = 0 → m j = 0 → + ((∑ k,m k : ℕ) : ℝ) ≤ Clen*Real.log (sourceB z) → + ∀ a : ℕ → ℕ, + let R := lower (sourceW z) z xi i + let U := lower (sourceW z) z xi j + let P := actualBins z xi i + let Uset := actualBins z xi j + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → U ≤ (sourceW z)^K → + (∀ q ∈ Q,∀ p ∈ P, + Real.logb (sourceW z) ((sourceY z : ℝ)/((p : ℝ)*q)) ≤ Cparent) → + (∀ q ∈ Q,∀ p ∈ P,∀ u ∈ Uset, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z)) → + weightedWitness P Q Uset + (actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) (sampleGamma (sigma/16) h/32)) ≤ + sigma*(harmonicMass P*harmonicMass Q*harmonicMass Uset) := by + have hb : 0 < sigma/16 := by positivity + have hb1 : sigma/16 ≤ 1 := by linarith + obtain ⟨xi0,hxi0,hxi01,hNo⟩ := source_no_dense_cell Clen Cparent aStar K alpha delta (sigma/16) h + hClen hCparent ha ha1 hK halpha hd hb hb1 hh + refine ⟨xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + have hxi1 : xi ≤ 1 := hxib.trans hxi01 + filter_upwards [hNo xi hxi hxib, + source_dense_initial_cell Clen xi sigma alpha delta (sampleGamma (sigma/16) h/32) + hClen hxi hxi1 hsigma halpha,source_span_geometry] + with z hno hdense hspan + intro m i j hij hmi hmj hm a + dsimp only + intro hRlo hRhi hUhi hparent hchild + let R := lower (sourceW z) z xi i + let U := lower (sourceW z) z xi j + let theta := effectiveWidth (sourceW z) z xi + let P := actualBins z xi i + let Uset := actualBins z xi j + let Q := cofactorChoices (actualBins z xi) m + let S := cofactorScale z xi m + let k := ∑ t,m t + let M0 := smallModulus (sourceW z) + have hthetaLow : xi/4 ≤ theta := + effectiveWidth_ge_quarter hspan.1 hspan.2.1 hxi hxi1 (hspan.2.2 xi hxi hxi1) + have hthetaHigh : theta ≤ xi := effectiveWidth_le hspan.1 hspan.2.1 hxi + have hWU : sourceW z ≤ U := (bin_source_bounds hspan.1 hspan.2.1 hxi j).1 + by_contra hn + have hBad := lt_of_not_ge hn + obtain ⟨cell,q0,hq0,hCsize,hCount,hCQ,hdata⟩ := hdense.2 R theta U theta hRlo hWU + hthetaLow hthetaHigh hthetaLow hthetaHigh m a hm hBad + let C := initialCell Q a S xi k M0 cell + have hq0Q : q0 ∈ Q := hCQ hq0 + have hq0data := hdata q0 hq0 + have hInfl := (actual_source_cofactor_inflation hspan.1 hspan.2.1 hxi Clen m hm q0 hq0Q).2 + have hCsq : ∀ q ∈ C,Squarefree q ∧ (q : ℝ) ≤ S := by + intro q hq + exact ⟨(hdata q hq).2.1,(actual_cofactor_effective_range hspan.1 hspan.2.1 hxi m q (hCQ hq)).2⟩ + have hCvalue : ∀ q ∈ C,(q : ℝ) ≤ cellUpper S xi cell ∧ + cellUpper S xi cell ≤ (1+xi)*(q : ℝ) := fun q hq => + ⟨(hdata q hq).2.2.1,(hdata q hq).2.2.2.1⟩ + have hCP : ∀ q ∈ C,∀ p ∈ P,q.Coprime p := + fun q hq => actual_excluded_bin_coprime hspan.1 hspan.2.1 hxi m i hmi q (hCQ hq) + have hCU : ∀ q ∈ C,∀ u ∈ Uset,q.Coprime u := + fun q hq => actual_excluded_bin_coprime hspan.1 hspan.2.1 hxi m j hmj q (hCQ hq) + have hpU : ∀ p ∈ P,∀ u ∈ Uset,p.Coprime u := + actual_distinct_bins_coprime hspan.1 hspan.2.1 hxi i j hij + have hsmall : ∀ q ∈ C,∀ p ∈ P,∀ t : ℕ,t.Prime → + (t : ℝ) ≤ sourceW z → (p*q).Coprime t := + fun q hq p hp => actual_parent_small_coprime hspan.1 hspan.2.1 hxi m q (hCQ hq) i p hp + have hcong : ∀ q ∈ C,Int.ModEq (M0 : ℤ) (q : ℤ) (q0 : ℤ) ∧ + Int.ModEq (M0 : ℤ) (cofactorHit q a : ℤ) (cofactorHit q0 a : ℤ) := + fun q hq => (hdata q hq).2.2.2.2 + exact hno R theta U theta (cellUpper S xi cell) S C q0 (cofactorHit q0 a) a + hRlo hRhi hWU hUhi hthetaLow hthetaHigh hthetaLow hthetaHigh hq0 hq0data.1 hInfl + hCsq hCvalue hpU hCP hCU hsmall (fun q hq => hchild q (hCQ hq)) + (hparent q0 hq0Q) hcong hCsize hCount + +end ErdosInverseBoxApplication + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxList.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxList.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c4a02e40bbb4a45e660a2796d5467875cbe3029 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualBoxList.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LiteralSourceList +import OAI.NumberTheory.Jacobsthal.Sieve.ActualCofactorArithmetic + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseBoxApplication +open NumberTheoryLean ErdosCofactorChoices ErdosInverseCells ErdosInverseRefinement + ErdosInverseBoxHeight ErdosInverseEuler ErdosInverseSampleCost ErdosInverseAlignment +open NumberTheoryLean.LogarithmicBinScale NumberTheoryLean.LogarithmicBinEndpoints + +theorem actual_box_list_card (Clen aStar alpha xi cp : ℝ) (hClen : 0 ≤ Clen) + (ha : 0 < aStar) (halpha : 0 < alpha) (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hcp : 0 < cp) : + ∀ᶠ z : ℝ in atTop,∀ (m : Fin (binCount (sourceW z) z xi) → ℕ) + (i j : Fin (binCount (sourceW z) z xi)), + ((∑ k,m k : ℕ) : ℝ) ≤ Clen*Real.log (sourceB z) → + ∀ a : ℕ → ℕ, + z^alpha ≤ lower (sourceW z) z xi i → + lower (sourceW z) z xi i ≤ z^((1 : ℝ)/100) → + (∀ q ∈ cofactorChoices (actualBins z xi) m,∀ p ∈ actualBins z xi i,∀ u ∈ actualBins z xi j, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z)) → + (sourceRationalList (actualBins z xi i) (fun p => (a p : ℤ)) (cofactorScale z xi m) + (lower (sourceW z) z xi i) (sourceZ z) cp).card ≤ ⌈2/cp^2⌉₊ := by + filter_upwards [uniform_literal_source_list Clen (xi/4) alpha cp hClen (by positivity) halpha hcp, + source_span_geometry,source_cofactor_cell_data Clen xi 1 hClen hxi hxi1 zero_lt_one, + source_sample_population xi 1 0 hxi hxi1,sourceW_tendsto_atTop.eventually_ge_atTop 2] + with z hlist hspan hcof hpop hW + intro m i j hm a hRlo hRhi hchild + have hthetaLow := effectiveWidth_ge_quarter hspan.1 hspan.2.1 hxi hxi1 (hspan.2.2 xi hxi hxi1) + have hthetaHigh := effectiveWidth_le hspan.1 hspan.2.1 hxi + have hP := (hpop (lower (sourceW z) z xi i) (effectiveWidth (sourceW z) z xi) + (bin_source_bounds hspan.1 hspan.2.1 hxi i).1 hthetaLow hthetaHigh).1 + have hU := (hpop (lower (sourceW z) z xi j) (effectiveWidth (sourceW z) z xi) + (bin_source_bounds hspan.1 hspan.2.1 hxi j).1 hthetaLow hthetaHigh).1 + obtain ⟨p,hp⟩ := Finset.card_pos.mp hP + obtain ⟨u,hu⟩ := Finset.card_pos.mp hU + obtain ⟨q,hq⟩ := Finset.card_pos.mp (hcof m hm).2.1 + have hqpos := ((hcof m hm).2.2.2 q hq).1 + have hpp := (bin_prime_in_source hspan.1 hspan.2.1 hxi i hp).1 + have hup := (bin_prime_in_source hspan.1 hspan.2.1 hxi j hu).1 + have hpq := parent_product_le_of_child_log (sourceY z) p q u (sourceW z) aStar + hpp.pos hqpos hup.one_lt.le (by linarith) ha (hchild q hq p hp u hu) + have hrange := actual_source_cofactor_inflation hspan.1 hspan.2.1 hxi Clen m hm q hq + exact hlist.2 (cofactorScale z xi m) (lower (sourceW z) z xi i) (p : ℝ) (q : ℝ) + (effectiveWidth (sourceW z) z xi) (fun p => (a p : ℤ)) + (by exact_mod_cast hpp.one_lt.le) (by exact_mod_cast hqpos) hpq hrange.1 hrange.2 + hRlo hRhi hthetaLow (hthetaHigh.trans hxi1) + +end ErdosInverseBoxApplication + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualCoordinateBlocks.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualCoordinateBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..fcc241b2dee80a99084b0a8fb3ee1b9db0dd8f44 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualCoordinateBlocks.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Primes.OriginalPrimeBlocks + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosVarianceEffective + +noncomputable def intervalK (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) : ℕ := + ((-(C0 : ZMod p))*(↑((ZMod.unitOfCoprime H hHp)⁻¹) : ZMod p)).val + +noncomputable def intervalM0 (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) : ℤ := + (C0+(H : ℤ)*(intervalK p H hHp C0 : ℤ))/(p : ℤ) + +theorem intervalK_lt (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) : + intervalK p H hHp C0 < p := ZMod.val_lt _ + +theorem interval_numerator_dvd (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) : + (p : ℤ) ∣ C0+(H : ℤ)*(intervalK p H hHp C0 : ℤ) := by + apply (ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mp + simp only [Int.cast_add,Int.cast_mul,Int.cast_natCast,intervalK,ZMod.natCast_zmod_val] + have hu : (H : ZMod p)*(↑((ZMod.unitOfCoprime H hHp)⁻¹) : ZMod p) = 1 := by + simpa only [ZMod.coe_unitOfCoprime] using (ZMod.unitOfCoprime H hHp).mul_inv + calc + _ = (C0 : ZMod p)-(C0 : ZMod p)*((H : ZMod p)*↑((ZMod.unitOfCoprime H hHp)⁻¹)) := by ring + _ = 0 := by rw [hu];ring + +theorem intervalM0_identity (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) : + (p : ℤ)*intervalM0 p H hHp C0 = C0+(H : ℤ)*(intervalK p H hHp C0 : ℤ) := by + rw [intervalM0,mul_comm] + exact Int.ediv_mul_cancel (interval_numerator_dvd p H hHp C0) + +theorem intervalM0_modEq (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) : + Int.ModEq (H : ℤ) ((p : ℤ)*intervalM0 p H hHp C0) C0 := by + rw [intervalM0_identity] + change (C0+(H : ℤ)*(intervalK p H hHp C0 : ℤ))%(H : ℤ) = C0%(H : ℤ) + simp + +theorem intervalM0_bounds (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) (hH : 0 < H) : + (C0 : ℝ)/(p : ℝ) ≤ (intervalM0 p H hHp C0 : ℝ) ∧ + (intervalM0 p H hHp C0 : ℝ) < (C0 : ℝ)/(p : ℝ)+(H : ℝ) := by + have hp : (0 : ℝ) < p := by exact_mod_cast Nat.pos_of_ne_zero (NeZero.ne p) + have hH' : (0 : ℝ) < H := by exact_mod_cast hH + have hk0 : (0 : ℝ) ≤ intervalK p H hHp C0 := Nat.cast_nonneg _ + have hkp : (intervalK p H hHp C0 : ℝ) < p := by exact_mod_cast intervalK_lt p H hHp C0 + have he : (p : ℝ)*(intervalM0 p H hHp C0 : ℝ) = (C0 : ℝ)+(H : ℝ)*(intervalK p H hHp C0 : ℝ) := by + exact_mod_cast intervalM0_identity p H hHp C0 + have hd : (C0 : ℝ)/(p : ℝ)*(p : ℝ) = C0 := div_mul_cancel₀ _ hp.ne' + constructor + · apply (div_le_iff₀ hp).mpr + nlinarith + · have hmul := mul_lt_mul_of_pos_left hkp hH' + nlinarith + +theorem intervalM0_unique (p H : ℕ) [NeZero p] (hHp : H.Coprime p) (C0 : ℤ) (hH : 0 < H) + (x : ℤ) (hx : (C0 : ℝ)/(p : ℝ) ≤ (x : ℝ) ∧ (x : ℝ) < (C0 : ℝ)/(p : ℝ)+(H : ℝ)) + (hcong : Int.ModEq (H : ℤ) ((p : ℤ)*x) C0) : x = intervalM0 p H hHp C0 := by + have he := hcong.trans (intervalM0_modEq p H hHp C0).symm + have hem : (p : ZMod H)*(x : ZMod H) = (p : ZMod H)*(intervalM0 p H hHp C0 : ZMod H) := by + simpa only [Int.cast_mul,Int.cast_natCast] using (ZMod.intCast_eq_intCast_iff _ _ _).mpr he + let v := ZMod.unitOfCoprime p hHp.symm + have he' := congrArg (fun y : ZMod H => (↑(v⁻¹) : ZMod H)*y) hem + have hu : (↑(v⁻¹) : ZMod H)*(p : ZMod H) = 1 := by + simpa only [v,ZMod.coe_unitOfCoprime] using v.inv_mul + have hxm : (x : ZMod H) = (intervalM0 p H hHp C0 : ZMod H) := by + simpa only [← mul_assoc,hu,one_mul] using he' + have hdiv := ((ZMod.intCast_eq_intCast_iff _ _ _).mp hxm).dvd + have hm := intervalM0_bounds p H hHp C0 hH + have habs : |((intervalM0 p H hHp C0-x : ℤ) : ℝ)| < (H : ℝ) := by + rw [abs_lt] + push_cast + constructor <;> linarith + have hnat : (intervalM0 p H hHp C0-x).natAbs < (H : ℤ).natAbs := by + rw [Int.natAbs_natCast] + have hnatR : ((intervalM0 p H hHp C0-x).natAbs : ℝ) < (H : ℝ) := by + simpa only [Nat.cast_natAbs,Int.cast_abs] using habs + exact_mod_cast hnatR + have hz := Int.eq_zero_of_dvd_of_natAbs_lt_natAbs hdiv hnat + omega + +end ErdosVarianceEffective + + + +namespace ErdosLargeHeightBlocks + + +theorem actual_m0_block_interval (C0 : ℤ) (R xi : ℝ) (H i p : ℕ) [NeZero p] + (hR : 0 < R) (hxi : 0 < xi) (hH : 0 < H) (hHp : H.Coprime p) + (hp : p ∈ blockPrimes C0 R xi H i) : + (ErdosVarianceEffective.intervalM0 p H hHp C0 : ℝ) ∈ + Set.Ico (coordinateLower C0 R xi H i) (coordinateUpper C0 R xi H i) ∧ + coordinateUpper C0 R xi H i-coordinateLower C0 R xi H i ≤ 2*(H : ℝ) := by + have hb := (mem_blockPrimes C0 R xi H i p hR hxi).mp hp + have hm := ErdosVarianceEffective.intervalM0_bounds p H hHp C0 hH + exact ⟨block_coordinate_containment C0 R xi H i hR hxi p _ hb.2.1.le hb.2.2 hm.1 hm.2, + block_coordinate_width C0 R xi H i hR hxi hH⟩ + +theorem actual_large_height_blocks (C0 : ℤ) (R xi Z : ℝ) (H : ℕ) + (hR : 0 < R) (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hH : 0 < H) (hZ : 2 ≤ Z) + (hsize : max (H : ℝ) (|(C0 : ℝ)|/R)/(H : ℝ) ≤ Z^12) : + 0 < blockCount C0 R xi H ∧ (blockCount C0 R xi H : ℝ) ≤ Z^13 ∧ + (Finset.univ : Finset (Fin (blockCount C0 R xi H))).biUnion + (fun i => blockPrimes C0 R xi H i) = ErdosInversePrimeBin.primeBin R xi ∧ + Pairwise (fun i j : Fin (blockCount C0 R xi H) => + Disjoint (blockPrimes C0 R xi H i) (blockPrimes C0 R xi H j)) ∧ + (∑ i : Fin (blockCount C0 R xi H), + (blockRight C0 R xi H i-blockLeft C0 R xi H i)) = xi*R ∧ + ∀ (i : Fin (blockCount C0 R xi H)) (p : ℕ) [NeZero p] (hHp : H.Coprime p), + p ∈ blockPrimes C0 R xi H i → + (ErdosVarianceEffective.intervalM0 p H hHp C0 : ℝ) ∈ + Set.Ico (coordinateLower C0 R xi H i) (coordinateUpper C0 R xi H i) ∧ + coordinateUpper C0 R xi H i-coordinateLower C0 R xi H i ≤ 2*(H : ℝ) := by + refine ⟨blockCount_pos C0 R xi H,blockCount_source_bound C0 R xi Z H hR hxi.le hxi1 hH hZ hsize, + block_partition C0 R xi H hR hxi,block_pairwise_disjoint C0 R xi H hR hxi, + block_width_sum C0 R xi H,?_⟩ + intro i p instP hHp hp + exact actual_m0_block_interval C0 R xi H i p hR hxi hH hHp hp + +end ErdosLargeHeightBlocks + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualPatternCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualPatternCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d7a21506e852e8acdd59e730f6a3791f72fa518 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualPatternCoordinates.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Paths.WrongOwnerBoxMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosTagEvent +open NumberTheoryLean ActualSourceTags ActualBinOwners FiniteFirstTag +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open PrimeChoiceBoxMass WrongOwnerBinMass ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +noncomputable def patternBins {m : ℕ} (w top xi : ℝ) (pattern : Fin m → Fin (binCount w top xi)) : + Fin m → Finset ℕ := fun i => primeBin (lower w top xi (pattern i)) (width w top xi (pattern i)) +noncomputable def searchPositions {m : ℕ} (w top xi : ℝ) + (pattern : Fin m → Fin (binCount w top xi)) : Finset (Fin m) := + Finset.univ.filter (fun i => searchBin w (lower w top xi (pattern i))) + +noncomputable def nearFull (eta R width : ℝ) (a : ℕ → ℤ) (q : ℚ) : Prop := + (1-eta)*((primeBin R width).card:ℝ) ≤ (((primeBin R width).filter (aligns a q)).card:ℝ) + +theorem actual_choice_label {m : ℕ} {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (pattern : Fin m → Fin (binCount w top xi)) (f : Fin m → ℕ) + (hf : f ∈ choices (patternBins w top xi pattern)) (i : Fin m) : + label (zero_lt_one.trans hw) htop hxi (f i)=pattern i := by + have hp : f i ∈ primeBin (lower w top xi (pattern i)) (width w top xi (pattern i)) := + (Fintype.mem_piFinset.mp hf) i + exact ((bin_mem_iff_label (zero_lt_one.trans hw) htop hxi (pattern i) (f i)).mp hp).2.2.2 + +theorem actual_choice_coordinate {m : ℕ} {w top xi : ℝ} + (pattern : Fin m → Fin (binCount w top xi)) (f : Fin m → ℕ) + (hf : f ∈ choices (patternBins w top xi pattern)) (i : Fin m) : + f i ∈ primeBin (lower w top xi (pattern i)) (width w top xi (pattern i)) := + (Fintype.mem_piFinset.mp hf) i + +theorem first_tag_coordinate {m : ℕ} {Y w top Cs eta xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (pattern : Fin m → Fin (binCount w top xi)) (f : Fin m → ℕ) (a : ℕ → ℤ) + (hf : f ∈ choices (patternBins w top xi pattern)) + (t : Tag (binCount w top xi)) + (ht : sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (List.ofFn f)=some t) : + ∃ i ∈ searchPositions w top xi pattern,pattern i=t.bin ∧ + owner Y w Cs eta (lower w top xi (pattern i)) (width w top xi (pattern i)) a=some t.rational ∧ + aligns a t.rational (f i) := by + obtain ⟨pre,p,tail,heq,_hindex,hbin,_hp,hs,ho,ha,_hbefore⟩ := + sourceTag_witness Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (List.ofFn f) ht + have hp : p ∈ List.ofFn f := by rw [heq]; simp + obtain ⟨i,hi⟩ := List.mem_ofFn.mp hp + have hl := actual_choice_label hw htop hxi pattern f hf i + rw [← hi,hl] at hbin hs ho + rw [← hi] at ha + exact ⟨i,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hs⟩,hbin.symm,ho,ha⟩ + +end ErdosTagEvent + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualRepeatedBinStep.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualRepeatedBinStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..935bb62e409be45ea7dde54f5da011f21d8b98fc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualRepeatedBinStep.lean @@ -0,0 +1,119 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FrozenSuffixData +import OAI.NumberTheory.Jacobsthal.Paths.MovingStopBandParameters + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CandidateTerminalGeometry +open FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate SourceStopWindow +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open MovingStopBandParameters FrozenSuffixData +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem terminal_ratio_div_cutoff (w : ℝ) (z : Node) (ps : List ℕ) (hne : ps ≠ []) + (hx : (terminal w z ps).cutoff ≠ 0) : + (terminal w z ps).ratio=(terminal w z ps).gap/(terminal w z ps).cutoff := by + induction ps generalizing z with + | nil => exact False.elim (hne rfl) + | cons p ps ih => + cases ps with + | nil => + change primeExponent w p ≠ 0 at hx + change PrimeTiltGeometry.childRatio w z.gap p=(z.gap-primeExponent w p)/primeExponent w p + unfold PrimeTiltGeometry.childRatio + field_simp [hx] + | cons q qs => exact ih (step w z p) (by simp) hx + +theorem candidate_terminal_geometry (Y : ℕ) {w top Cs eta Clen B xi b₀ b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) (hpos : 0 < b₀-xi/Real.log w) + (hsmall : 2*Clen*xi+(218/100)*(xi/Real.log w) ≤ (2/100)*b₀) + (residue : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hc : stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) residue z ps) : + b₀-xi/Real.log w ≤ (terminal w z ps).cutoff ∧ (terminal w z ps).cutoff ≤ b₁ ∧ + 204/100 ≤ (terminal w z ps).ratio ∧ (terminal w z ps).ratio ≤ 218/100 ∧ + Consistent (terminal w z ps) ∧ (terminal w z ps).closed=false := by + have hwin := candidate_actual_window Y hw htop hxi hC hcomp hsmall residue z ps hc + have hx : 0 < (terminal w z ps).cutoff := hpos.trans_le hwin.1 + have hfrac := terminal_ratio_div_cutoff w z ps hc.1 hx.ne' + have hlo : 204/100 ≤ (terminal w z ps).ratio := by rw [hfrac]; exact hwin.2.2.1 + have hhi : (terminal w z ps).ratio ≤ 218/100 := by rw [hfrac]; exact hwin.2.2.2 + have hcons : Consistent (terminal w z ps) := by + apply (eq_div_iff (show (terminal w z ps).ratio ≠ 0 by linarith)).mpr + have hh := (eq_div_iff hx.ne').mp hfrac + nlinarith + exact ⟨hwin.1,hwin.2.1,hlo,hhi,hcons,(terminal_suffix_cutoff w z z ps hc.1).2.1⟩ +end NumberTheoryLean.CandidateTerminalGeometry + + + +namespace NumberTheoryLean.ActualRepeatedBinStep +open FinitePathGeometry PrimeHistories PrimeTiltGeometry PrimeBinMembership ActualPrimeHigh +open RepeatedBinGeometry CandidateTerminalGeometry MarkedPrefixTools +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem history_source_primes {w ell S top : ℝ} {start : Node} + (hw : 1 < w) (htop : w < top) (hell : 1 ≤ ell) (hcap : w^start.cutoff=top) + (h : History w ell S start) : ∀ p ∈ h.primes,p ∈ sourcePrimeSet w top := by + intro p hp + obtain ⟨hprime,hlo,hguard⟩ := allowed_prime_bounds hw h.admissible p hp + have hp0 : 0 < (p:ℝ) := by exact_mod_cast hprime.pos + have hlow : w < (p:ℝ) := by + simpa only [Real.rpow_one] using (lt_exponent_iff hw hp0).mp (hell.trans_lt hlo) + have hupper : primeExponent w p ≤ start.cutoff := by + cases he : start.closed with + | false => + simp only [capGuard,he,Bool.false_eq_true,ite_false] at hguard + exact hguard.le + | true => simpa only [capGuard,he,ite_true] using hguard + have hhigh := (exponent_le_iff hw hp0).mp hupper + rw [hcap] at hhigh + exact (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mpr ⟨hprime,hlow,hhigh⟩ + +theorem actual_same_bin_slack {w ell S top xi : ℝ} {start : Node} + (hw : 1 < w) (htop : w < top) (hell : 1 ≤ ell) (hxi : 0 < xi) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hcap : w^start.cutoff=top) + (h : History w ell S start) (hne : h.primes ≠ []) (p : ℕ) (hp : p ∈ nodeChildren w ell S h.node) + (hl : label (zero_lt_one.trans hw) htop hxi (h.primes.getLastD 0)=label (zero_lt_one.trans hw) htop hxi p) : + 0 ≤ (h.append p hp).node.ratio-(h.node.ratio-1) ∧ + (h.append p hp).node.ratio-(h.node.ratio-1) ≤ h.node.ratio*(xi/Real.log w)/primeExponent w p := by + have hLast : h.primes.getLastD 0 ∈ h.primes := by + have he : h.primes.getLastD 0=h.primes.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hne + have hsrcOld := history_source_primes hw htop hell hcap h _ hLast + have hsrcNew := history_source_primes hw htop hell hcap (h.append p hp) p (by simp [History.append_primes]) + have hdist := equal_label_exponent_distance hw htop hxi hsrcOld hsrcNew hl + have hdata := (mem_children_iff hw h.node.side h.node.closed p).mp hp + have hx : 0 < primeExponent w p := by linarith [hdata.2.1] + have hcut : primeExponent w p ≤ h.node.cutoff := by + have hh := hdata.2.2.1 + cases he : h.node.closed with + | false => + simp only [capGuard,he,Bool.false_eq_true,ite_false] at hh + exact hh.le + | true => simpa only [capGuard,he,ite_true] using hh + have hlastCut : h.node.cutoff=primeExponent w (h.primes.getLastD 0) := terminal_lastD w start h.primes hne + have hOld : 0 < primeExponent w (h.primes.getLastD 0) := by linarith [hcut] + have hratio : h.node.ratio=h.node.gap/primeExponent w (h.primes.getLastD 0) := by + have hh := terminal_ratio_div_cutoff w start h.primes hne (show h.node.cutoff ≠ 0 by linarith [hcut]) + change h.node.ratio=h.node.gap/h.node.cutoff at hh + rwa [hlastCut] at hh + have hrg : 0 < h.node.gap := terminal_gap_positive (by linarith : 0 ≤ ell) hr hs h.admissible + have hh := adjacent_ratio_slack hrg hx (show primeExponent w p ≤ primeExponent w (h.primes.getLastD 0) by linarith [hcut]) + ((le_abs_self _).trans hdist) + rw [← hratio] at hh + simpa only [History.append_node,step,childRatio] using hh +end NumberTheoryLean.ActualRepeatedBinStep + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualSafeBoxMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualSafeBoxMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad61c356365dba77b3884f27ba5f9c52158fe875 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ActualSafeBoxMass.lean @@ -0,0 +1,114 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FiniteBoxWordMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SafeSubsetBoxGeometry +open FinitePathGeometry PrimeHistories SourceStopPredicate RepresentativeAdmission RepresentativeTraceInvariance +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open ReferenceAdmission ErdosCofactorChoices ErdosSubsetWord +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +noncomputable def SafeAnchor {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Clen B K : ℝ) (z : Node) (mult : Fin (binCount w top xi) → ℕ) : Prop := + ∃ anchor ∈ selections (globalBins w top xi) mult, + ((descendingWord anchor).length:ℝ) ≤ Clen*Real.log B ∧ + representativeSafe w (representative w (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi)) z (2*Clen*xi) (descendingWord anchor) ∧ + (terminal w z (descendingWord anchor)).gap ≤ K + +theorem selection_representatives_eq {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f g : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) (hg : g ∈ selections (globalBins w top xi) mult) : + (descendingWord f).map (representative w (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi))= + (descendingWord g).map (representative w (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi)) := by + have hh := congrArg (List.map (fun b => PrimeBinRepresentatives.rightExponent w (lower w top xi b) (width w top xi b))) + (selection_label_word_eq hw htop hxi mult f g hf hg) + unfold representative + simpa only [List.map_map,Function.comp_def] using hh + +theorem anchored_choice_geometry {w top xi B Clen K : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hC : 0 ≤ Clen) (hcomp : Real.log B ≤ 2*Real.log w) (z : Node) + (mult : Fin (binCount w top xi) → ℕ) (hanchor : SafeAnchor hw htop hxi Clen B K z mult) + (f : Fin (binCount w top xi) → Finset ℕ) (hf : f ∈ selections (globalBins w top xi) mult) : + descendingWord f ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap ∧ + (terminal w z (descendingWord f)).gap ≤ K+2*Clen*xi := by + obtain ⟨g,hg,hlen,hSafe,hK⟩ := hanchor + let rep := representative w (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) + have he := selection_representatives_eq hw htop hxi mult f g hf hg + have hsf : representativeSafe w rep z (2*Clen*xi) (descendingWord f) := + (representativeSafe_map_iff w rep z (2*Clen*xi) _ _ he).mpr hSafe + have hsource := word_source_membership hw htop hxi mult f hf + have hsourceg := word_source_membership hw htop hxi mult g hg + have hadmit : admitted w z.side z.gap (descendingWord f) := by + apply finite_safe_admits w rep z (2*Clen*xi) _ (by positivity) _ hsf + intro p hp + have hh := (source_representative_error hw htop hxi (hsource p hp)).1 + change 0 ≤ rep p-primeExponent w p at hh + linarith + refine ⟨Finset.mem_filter.mpr ⟨mem_decreasingPrefixes.mpr ⟨descendingWord_strict f,hsource⟩,hadmit⟩,?_⟩ + have hlength : (descendingWord f).length=(descendingWord g).length := + (global_word_length hw htop hxi mult f hf).trans (global_word_length hw htop hxi mult g hg).symm + have hlenf : ((descendingWord f).length:ℝ) ≤ Clen*Real.log B := by rwa [hlength] + have hmf := source_prefix_movement hw htop hxi hC hcomp z (descendingWord f) hsource hlenf + have hmg := source_prefix_movement hw htop hxi hC hcomp z (descendingWord g) hsourceg hlen + have hgap : representativeGap rep z.gap (descendingWord f)=representativeGap rep z.gap (descendingWord g) := by + unfold representativeGap + rw [he] + change 0 ≤ (terminal w z (descendingWord f)).gap-representativeGap rep z.gap (descendingWord f) ∧ + (terminal w z (descendingWord f)).gap-representativeGap rep z.gap (descendingWord f) ≤ 2*Clen*xi at hmf + change 0 ≤ (terminal w z (descendingWord g)).gap-representativeGap rep z.gap (descendingWord g) ∧ + (terminal w z (descendingWord g)).gap-representativeGap rep z.gap (descendingWord g) ≤ 2*Clen*xi at hmg + rw [hgap] at hmf + linarith [hmf.2,hmg.1] +end NumberTheoryLean.SafeSubsetBoxGeometry + + + +namespace NumberTheoryLean.ActualSafeBoxMass +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open LogarithmicBinScale LogarithmicBinPartition ReferenceAdmission StrongSourceFamilies +open SafeSubsetBoxGeometry FiniteBoxWordMass CanonicalSubsetBox ErdosSubsetWord + +attribute [local instance] Classical.propDecidable + +theorem uniform_safe_box_mass (K : ℝ) (hK : 3 ≤ K) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → + ∀ (hw : 1 < w) (htop : w < top) (xi Clen : ℝ) (hxi : 0 < xi),0 ≤ Clen → + Real.log B ≤ 2*Real.log w → 2*Clen*xi ≤ 1 → ∀ z : Node, + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=B → + z.closed=true → w^B=top → ∀ M : Finset (Fin (binCount w top xi) → ℕ), + (∀ mult ∈ M,SafeAnchor hw htop hxi Clen B K z mult) → + B^2*(∑ mult ∈ M,selectionMass (globalBins w top xi) mult) ≤ C := by + obtain ⟨C,B₀,w₀,hC,hB₀,hw₀,hbound⟩ := uniform_source_family_mass (K+1) 2 (by linarith) (by norm_num) + refine ⟨C,B₀,w₀,hC,hB₀,hw₀,?_⟩ + intro B w top hB hw hw1 htop xi Clen hxi hClen hcomp hsmall z hi h199 h23 hz hcut hclosed hcap M hanchors + have hd : Pairwise (fun i j => Disjoint (globalBins w top xi i) (globalBins w top xi j)) := + fun i j hij => bins_pairwise_disjoint (zero_lt_one.trans hw1) htop hxi i j hij + let F := boxWords (globalBins w top xi) M + have hF : F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap := by + intro ps hps + obtain ⟨mult,hm,hword⟩ := Finset.mem_biUnion.mp hps + obtain ⟨f,hf,he⟩ := Finset.mem_image.mp hword + have hh := (anchored_choice_geometry hw1 htop hxi hClen hcomp z mult (hanchors mult hm) f hf).1 + rwa [he] at hh + have hFK : ∀ ps ∈ F,(terminal w z ps).gap ≤ K+1 := by + intro ps hps + obtain ⟨mult,hm,hword⟩ := Finset.mem_biUnion.mp hps + obtain ⟨f,hf,he⟩ := Finset.mem_image.mp hword + have hh := (anchored_choice_geometry hw1 htop hxi hClen hcomp z mult (hanchors mult hm) f hf).2 + rw [he] at hh + linarith + rw [total_box_mass_eq (globalBins w top xi) hd M] + exact hbound B w top hB hw htop hcomp z hi h199 h23 hz hcut hclosed hcap F hF hFK +end NumberTheoryLean.ActualSafeBoxMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/AllLabelDiscrepancy.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/AllLabelDiscrepancy.lean new file mode 100644 index 0000000000000000000000000000000000000000..1dc60c9976ff00d34d148ad35fbf5fcaff6c77b6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/AllLabelDiscrepancy.lean @@ -0,0 +1,75 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CoupledBoundaryBounds + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.AllLabelDiscrepancy + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open MeshRatioLabels MeshBoundaryGeometry ActualSupportIntervals ActualProcessCoupling +open ContinuousKilledBins PrimeBinMembership RegeneratingInverseBands KernelBinConditioning +open CommonCellSum CouplingLabelEvents CoupledBoundaryEvents CoupledBoundaryBounds + +theorem all_label_discrepancy : ∃ c₁ c₂ C₁ C₂ C₃ D w₀ : ℝ, + 0 < c₁ ∧ 0 < c₂ ∧ 0 < C₁ ∧ 0 < C₂ ∧ 0 < C₃ ∧ 0 < D ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, ∀ h : History w ell S start, + ∀ v : ℝ, ∀ z : CostState, ∀ mesh : ℝ, + normalizationThreshold ≤ w → 1 ≤ ell → 3 ≤ S → S ≤ (Real.log w)^3 → + 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → Consistent start → + stateRatio z.1 ≤ S → h.node.side = stateSide z.1 → 0 < mesh → + let Ld := minRatio h.node.side h.node.ratio + let Lc := minRatio (stateSide z.1) (stateRatio z.1) + let Ud := upperSupport S ell h.node.gap + let Uc := upperSupport S ell (gapValue v z) + |Ld-Lc|+mesh ≤ 1 → |Ud-Uc|+mesh ≤ 1 → + (∑ 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*((S/mesh+2)*(C₁*(1+S)^5*(mesh^2+Real.exp (-c₁*Real.sqrt ((1/2:ℝ)*Real.log w))))+ + epsilon w+(Real.exp (D*(1+S)^3*|h.node.ratio-stateRatio z.1|)-1)+ + C₂*(1+S)^2*(|Ld-Lc|+|Ud-Uc|+2*mesh+2*Real.exp (-c₂*Real.sqrt ((1/2:ℝ)*Real.log w)))+ + C₃*(1+S)^2*(|Ld-Lc|+|Ud-Uc|+2*mesh)) := by + classical + obtain ⟨c₁,C₁,D,w₁,hc₁,hC₁,hD,hw₁,hcommon⟩ := common_cell_sum_error + obtain ⟨c₂,C₂,w₂,hc₂,hC₂,hw₂,hprime⟩ := prime_bad_cells_upper + obtain ⟨C₃,hC₃,hcontinuous⟩ := continuous_bad_cells_upper + refine ⟨c₁,c₂,C₁,C₂,C₃,D,max w₁ w₂,hc₁,hc₂,hC₁,hC₂,hC₃,hD, + hw₁.trans_le (le_max_left _ _),?_⟩ + intro w hw ell S start h v z mesh hnorm hell hS3 hS hr hs hsS hcons hzS hside hm + dsimp only + intro hL hU + let Ld := minRatio h.node.side h.node.ratio + let Lc := minRatio (stateSide z.1) (stateRatio z.1) + let Ud := upperSupport S ell h.node.gap + let Uc := upperSupport S ell (gapValue v z) + let I := interiorLabels S mesh Ld Lc Ud Uc + let δ := |Ld-Lc|+|Ud-Uc|+2*mesh + let Bp := C₂*(1+S)^2*(δ+2*Real.exp (-c₂*Real.sqrt ((1/2:ℝ)*Real.log w))) + let Bc := C₃*(1+S)^2*δ + have hδ : 0 ≤ δ := by dsimp [δ]; positivity + have hBp : 0 ≤ Bp := by dsimp [Bp]; positivity + have hBc : 0 ≤ Bc := by dsimp [Bc]; positivity + have hi := hcommon w ((le_max_left _ _).trans hw) ell S start h v z mesh I + hell hS3 hr hs hsS hcons hzS hside hm (fun j hj => (Finset.mem_filter.mp hj).2) + have hp := hprime w ((le_max_right _ _).trans hw) ell S start hell hr hs hsS h mesh Lc Uc hm hL hU + have hc := hcontinuous v ell S z (by linarith) hzS mesh Ld Ud hm + have hpR : (chain w ell S start (some h) (primeBadCells mesh Ld Lc Ud Uc)).toReal ≤ Bp := by + have h := ENNReal.toReal_mono ENNReal.ofReal_ne_top hp + rwa [ENNReal.toReal_ofReal hBp] at h + have hcR : (continuousChain v ell S (.inl z) (continuousBadCells S mesh Ld Lc Ud Uc)).toReal ≤ Bc := by + have h := ENNReal.toReal_mono ENNReal.ofReal_ne_top hc + rwa [ENNReal.toReal_ofReal hBc] at h + have hb := actual_label_budget hnorm hell (by linarith) hS hr hs hsS h v z hm Ld Lc Ud Uc + change (∑ j,_) ≤ _ at hb + dsimp only [I,Bp,Bc,δ,Ld,Lc,Ud,Uc] at hi hpR hcR hb + linarith + +end NumberTheoryLean.AllLabelDiscrepancy + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BandShiftTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BandShiftTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..1731d94d48fc822909ef38b96c5cc469db6c3cf1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BandShiftTransport.lean @@ -0,0 +1,128 @@ +import OAI.NumberTheory.Jacobsthal.Paths.CostPrefixTransport + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.BandShiftTransport + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open FinitePathMeasures OccupationRegeneration RegenerationBandBounds CostPrefixTransport + +noncomputable def bandExpectation (Q : State → ℝ≥0∞) (v h : ℝ) (z : CostState) : ℝ≥0∞ := + ∫⁻ y, stateBandReward Q v h y ∂inclusiveOccupation z + +noncomputable def zeroBandExpectation (Q : State → ℝ≥0∞) (v h : ℝ) (s : State) : ℝ≥0∞ := + bandExpectation Q v h (s, 0) + +theorem stateBandReward_measurable {Q : State → ℝ≥0∞} (hQ : Measurable Q) (v h : ℝ) : + Measurable (stateBandReward Q v h) := + (hQ.comp measurable_fst).indicator (measurable_snd measurableSet_Icc) + +theorem bandExpectation_measurable {Q : State → ℝ≥0∞} (hQ : Measurable Q) (v h : ℝ) : + Measurable (bandExpectation Q v h) := (stateBandReward_measurable hQ v h).lintegral_kernel + +theorem zeroBandExpectation_measurable {Q : State → ℝ≥0∞} (hQ : Measurable Q) (v h : ℝ) : + Measurable (zeroBandExpectation Q v h) := + (bandExpectation_measurable hQ v h).comp (measurable_id.prodMk measurable_const) + +theorem stateBandReward_shift (Q : State → ℝ≥0∞) (v h a : ℝ) (y : CostState) : + stateBandReward Q v h (shiftFullCost a y) = stateBandReward Q (v - a) h y := by + classical + have heq : y.2 + a ∈ Icc v (v + h) ↔ y.2 ∈ Icc (v - a) (v - a + h) := by + simp only [mem_Icc] + constructor <;> rintro ⟨h₁, h₂⟩ <;> constructor <;> linarith + simp only [stateBandReward, indicator_apply, mem_preimage, shiftFullCost] + simp only [heq] + +theorem bandExpectation_translation {Q : State → ℝ≥0∞} (hQ : Measurable Q) + (v h : ℝ) (z : CostState) : + bandExpectation Q v h z = zeroBandExpectation Q (v - z.2) h z.1 := by + have hshift := inclusiveOccupation_translation (z.1, 0) z.2 + have hz : shiftFullCost z.2 (z.1, 0) = z := by simp [shiftFullCost] + rw [hz] at hshift + rw [bandExpectation, ← hshift, lintegral_map (stateBandReward_measurable hQ v h) (shiftFullCost_measurable z.2)] + apply lintegral_congr + intro y + exact stateBandReward_shift Q v h z.2 y + +theorem stateBandReward_mono (Q : State → ℝ≥0∞) {v h v' h' : ℝ} + (hsub : Icc v (v + h) ⊆ Icc v' (v' + h')) (y : CostState) : + stateBandReward Q v h y ≤ stateBandReward Q v' h' y := by + classical + unfold stateBandReward + by_cases hy : y.2 ∈ Icc v (v + h) + · rw [indicator_of_mem (show y ∈ Prod.snd ⁻¹' Icc v (v + h) from hy), + indicator_of_mem (show y ∈ Prod.snd ⁻¹' Icc v' (v' + h') from hsub hy)] + · rw [indicator_of_notMem (show y ∉ Prod.snd ⁻¹' Icc v (v + h) from hy)] + exact zero_le + +theorem bandExpectation_mono (Q : State → ℝ≥0∞) {v h v' h' : ℝ} + (hsub : Icc v (v + h) ⊆ Icc v' (v' + h')) (z : CostState) : + bandExpectation Q v h z ≤ bandExpectation Q v' h' z := + lintegral_mono (stateBandReward_mono Q hsub) + +theorem remove_prefix_cost {Q : State → ℝ≥0∞} (hQ : Measurable Q) + (v h C : ℝ) (z : CostState) (hz : 0 ≤ z.2 ∧ z.2 ≤ C) : + bandExpectation Q v h z ≤ zeroBandExpectation Q (v - C) (h + C) z.1 := by + rw [bandExpectation_translation hQ] + apply bandExpectation_mono + intro t ht + change v - z.2 ≤ t ∧ t ≤ v - z.2 + h at ht + change v - C ≤ t ∧ t ≤ v - C + (h + C) + constructor <;> linarith [ht.1, ht.2, hz.1, hz.2] + +theorem restore_prefix_cost {Q : State → ℝ≥0∞} (hQ : Measurable Q) + (v h C : ℝ) (z : CostState) (hz : 0 ≤ z.2 ∧ z.2 ≤ C) : + zeroBandExpectation Q v h z.1 ≤ bandExpectation Q v (h + C) z := by + rw [bandExpectation_translation hQ] + apply bandExpectation_mono + intro t ht + change v ≤ t ∧ t ≤ v + h at ht + change v - z.2 ≤ t ∧ t ≤ v - z.2 + (h + C) + constructor <;> linarith [ht.1, ht.2, hz.1, hz.2] + +theorem prefix_band_domination {Q : State → ℝ≥0∞} (hQ : Measurable Q) + (m n : ℕ) (x y : State) {C : ℝ≥0∞} + (hdom : (stateKernel ^ m) x ≤ C • (stateKernel ^ n) y) (v h : ℝ) : + (∫⁻ z, stateBandReward Q v h z ∂prefixOccupation m (x, 0)) ≤ + C * ∫⁻ z, stateBandReward Q (v - (m : ℝ) * Real.log 3) + (h + (m : ℝ) * Real.log 3 + (n : ℝ) * Real.log 3) z ∂prefixOccupation n (y, 0) := by + let v' := v - (m : ℝ) * Real.log 3 + let h' := h + (m : ℝ) * Real.log 3 + have hM := zeroBandExpectation_measurable hQ v' h' + have hmCost : ∀ᵐ z ∂(costKernel ^ m) (x, 0), 0 ≤ z.2 ∧ z.2 ≤ (m : ℝ) * Real.log 3 := by + simpa only [zero_add] using costKernel_pow_cost_bounds m (x, 0) + have hnCost : ∀ᵐ z ∂(costKernel ^ n) (y, 0), 0 ≤ z.2 ∧ z.2 ≤ (n : ℝ) * Real.log 3 := by + simpa only [zero_add] using costKernel_pow_cost_bounds n (y, 0) + rw [prefixOccupation, Kernel.lintegral_comp _ _ _ (stateBandReward_measurable hQ v h), + prefixOccupation, Kernel.lintegral_comp _ _ _ (stateBandReward_measurable hQ v' (h' + (n : ℝ) * Real.log 3))] + change (∫⁻ z, bandExpectation Q v h z ∂(costKernel ^ m) (x, 0)) ≤ + C * ∫⁻ z, bandExpectation Q v' (h' + (n : ℝ) * Real.log 3) z ∂(costKernel ^ n) (y, 0) + calc + _ ≤ ∫⁻ z, zeroBandExpectation Q v' h' z.1 ∂(costKernel ^ m) (x, 0) := by + apply lintegral_mono_ae + filter_upwards [hmCost] with z hz + exact remove_prefix_cost hQ v h ((m : ℝ) * Real.log 3) z hz + _ = ∫⁻ s, zeroBandExpectation Q v' h' s ∂(stateKernel ^ m) x := by + rw [← costKernel_pow_map_state m (x, 0), lintegral_map hM measurable_fst] + _ ≤ ∫⁻ s, zeroBandExpectation Q v' h' s ∂C • (stateKernel ^ n) y := lintegral_mono' hdom le_rfl + _ = C * ∫⁻ s, zeroBandExpectation Q v' h' s ∂(stateKernel ^ n) y := by rw [lintegral_smul_measure, smul_eq_mul] + _ = C * ∫⁻ z, zeroBandExpectation Q v' h' z.1 ∂(costKernel ^ n) (y, 0) := by + rw [← costKernel_pow_map_state n (y, 0), lintegral_map hM measurable_fst] + _ ≤ _ := by + apply mul_le_mul le_rfl _ zero_le zero_le + apply lintegral_mono_ae + filter_upwards [hnCost] with z hz + exact restore_prefix_cost hQ v' h' ((n : ℝ) * Real.log 3) z hz + +end NumberTheoryLean.BandShiftTransport + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BeginningWindowTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BeginningWindowTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..09ee0642cd0cc6262ab37c14fe615356fc8c4eac --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BeginningWindowTransport.lean @@ -0,0 +1,152 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.ClockWindowPassage + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ProbabilityTheory ENNReal +open NumberTheoryLean.KernelPotential + +section Projection +variable {α : Type*} [MeasurableSpace α] {f : α → ℝ} (hf : Measurable f) +include hf + +lemma costProjection_comp {K B : Kernel α α} {L C : Kernel ℝ ℝ} + (hK : ∀ z, (K z).map f = L (f z)) (hB : ∀ z, (B z).map f = C (f z)) (z : α) : + ((B ∘ₖ K) z).map f = (C ∘ₖ L) (f z) := by + ext S hS + rw [Measure.map_apply hf hS,Kernel.comp_apply' _ _ _ (hf hS),Kernel.comp_apply' _ _ _ hS] + have hi (y : α) : B y (f ⁻¹' S) = C (f y) S := by + rw [← Measure.map_apply hf hS,hB y] + simp_rw [hi] + rw [← lintegral_map (g := f) (C.measurable_coe hS) hf,hK z] + +lemma costProjection_power {K : Kernel α α} {L : Kernel ℝ ℝ} + (hK : ∀ z, (K z).map f = L (f z)) (n : ℕ) (z : α) : + ((K ^ n) z).map f = (L ^ n) (f z) := by + induction n generalizing z with + | zero => + change (Measure.dirac z).map f = Measure.dirac (f z) + exact Measure.map_dirac' hf z + | succ n ih => + rw [pow_succ',pow_succ'] + exact costProjection_comp hf (fun z => ih z) hK z + +lemma costProjection_potential {K B : Kernel α α} {L C : Kernel ℝ ℝ} + (hK : ∀ z, (K z).map f = L (f z)) (hB : ∀ z, (B z).map f = C (f z)) (z : α) : + ((potential B K) z).map f = (potential C L) (f z) := by + rw [potential,Kernel.sum_apply,Measure.map_sum (f := f) hf.aemeasurable, + potential,Kernel.sum_apply] + apply congrArg Measure.sum + funext n + exact costProjection_comp hf (costProjection_power hf hK n) hB z + +lemma costProjection_restrict {K : Kernel α α} {L : Kernel ℝ ℝ} + (hK : ∀ z, (K z).map f = L (f z)) {S : Set ℝ} (hS : MeasurableSet S) (z : α) : + ((K.restrict (s := f ⁻¹' S) (hf hS)) z).map f = (L.restrict hS) (f z) := by + rw [Kernel.restrict_apply,Kernel.restrict_apply,← Measure.restrict_map hf hS,hK z] +end Projection + +def relativeBeginningCost (t : ℝ) (z : RegCost) : ℝ := beginningCost z-t + +lemma relativeBeginningCost_measurable (t : ℝ) : Measurable (relativeBeginningCost t) := + beginningCost_measurable.sub measurable_const + +lemma beginning_relative_cost_projection (t : ℝ) (z : RegCost) : + (markedBeginningKernel z).map (relativeBeginningCost t) = + markedClockKernel (relativeBeginningCost t z) := by + rw [markedClockKernel_apply] + calc + _ = ((markedBeginningKernel z).map (fun y => beginningCost y-beginningCost z)).map + (fun G => relativeBeginningCost t z+G) := by + rw [Measure.map_map (f := fun y : RegCost => beginningCost y-beginningCost z) + (g := fun G : ℝ => relativeBeginningCost t z+G) (measurable_const.add measurable_id) + (beginningCost_measurable.sub measurable_const)] + congr 1 + funext y + dsimp [Function.comp_def,relativeBeginningCost] + ring + _ = _ := by rw [markedBeginning_increment_law] + +noncomputable def beginningBelow (t v : ℝ) : Kernel RegCost RegCost := + markedBeginningKernel.restrict (s := relativeBeginningCost t ⁻¹' Iio v) + ((relativeBeginningCost_measurable t) measurableSet_Iio) + +noncomputable def beginningWindow (t v H : ℝ) : Kernel RegCost RegCost := + markedBeginningKernel.restrict (s := relativeBeginningCost t ⁻¹' Icc v (v+H)) + ((relativeBeginningCost_measurable t) measurableSet_Icc) + +noncomputable def beginningOver (t v H : ℝ) : Kernel RegCost RegCost := + markedBeginningKernel.restrict (s := relativeBeginningCost t ⁻¹' Ioi (v+H)) + ((relativeBeginningCost_measurable t) measurableSet_Ioi) + +lemma beginningBelow_projection (t v : ℝ) (z : RegCost) : + (beginningBelow t v z).map (relativeBeginningCost t) = + clockBelow v (relativeBeginningCost t z) := + costProjection_restrict (relativeBeginningCost_measurable t) + (beginning_relative_cost_projection t) measurableSet_Iio z + +lemma beginningWindow_projection (t v H : ℝ) (z : RegCost) : + (beginningWindow t v H z).map (relativeBeginningCost t) = + clockWindow v H (relativeBeginningCost t z) := + costProjection_restrict (relativeBeginningCost_measurable t) + (beginning_relative_cost_projection t) measurableSet_Icc z + +lemma beginningOver_projection (t v H : ℝ) (z : RegCost) : + (beginningOver t v H z).map (relativeBeginningCost t) = + clockOver v H (relativeBeginningCost t z) := + costProjection_restrict (relativeBeginningCost_measurable t) + (beginning_relative_cost_projection t) measurableSet_Ioi z + +noncomputable def beginningWindowHit (z : RegCost) (v H : ℝ) : ℝ≥0∞ := + (potential (beginningWindow (beginningCost z) v H) (beginningBelow (beginningCost z) v)) z univ + +noncomputable def beginningOvershoot (z : RegCost) (v H : ℝ) : ℝ≥0∞ := + (potential (beginningOver (beginningCost z) v H) (beginningBelow (beginningCost z) v)) z univ + +lemma beginningWindowHit_eq_clock (z : RegCost) (v H : ℝ) : + beginningWindowHit z v H = clockWindowHit v H := by + have he := costProjection_potential (relativeBeginningCost_measurable (beginningCost z)) + (beginningBelow_projection (beginningCost z) v) (beginningWindow_projection (beginningCost z) v H) z + apply_fun (fun μ : Measure ℝ => μ univ) at he + rw [Measure.map_apply (relativeBeginningCost_measurable _) MeasurableSet.univ,preimage_univ] at he + simpa only [relativeBeginningCost,sub_self,beginningWindowHit,clockWindowHit] using he + +lemma beginningOvershoot_eq_clock (z : RegCost) (v H : ℝ) : + beginningOvershoot z v H = clockOvershoot v H := by + have he := costProjection_potential (relativeBeginningCost_measurable (beginningCost z)) + (beginningBelow_projection (beginningCost z) v) (beginningOver_projection (beginningCost z) v H) z + apply_fun (fun μ : Measure ℝ => μ univ) at he + rw [Measure.map_apply (relativeBeginningCost_measurable _) MeasurableSet.univ,preimage_univ] at he + simpa only [relativeBeginningCost,sub_self,beginningOvershoot,clockOvershoot] using he + +theorem beginningWindow_partition (z : RegCost) {v H : ℝ} (hv : 0 < v) (hH : 0 ≤ H) : + beginningWindowHit z v H+beginningOvershoot z v H = 1 := by + rw [beginningWindowHit_eq_clock,beginningOvershoot_eq_clock] + exact clockWindowHit_add_overshoot hv hH + +theorem beginningWindow_exponential : ∃ eta C : ℝ, 0 < eta ∧ 0 < C ∧ ∀ z : RegCost, ∀ v H : ℝ, + 0 < v → 0 ≤ H → beginningOvershoot z v H ≤ ENNReal.ofReal (C*Real.exp (-eta*H)) ∧ + 1-ENNReal.ofReal (C*Real.exp (-eta*H)) ≤ beginningWindowHit z v H := by + obtain ⟨eta,C,heta,hC,hTail⟩ := clockOvershoot_exponential + refine ⟨eta,C,heta,hC,?_⟩ + intro z v H hv hH + rw [beginningWindowHit_eq_clock,beginningOvershoot_eq_clock] + refine ⟨hTail v H hv hH,?_⟩ + apply tsub_le_iff_right.mpr + have he := clockWindowHit_add_overshoot hv hH + calc + 1 = clockWindowHit v H+clockOvershoot v H := he.symm + _ ≤ _ := add_le_add le_rfl (hTail v H hv hH) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BinCutGapMovement.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BinCutGapMovement.lean new file mode 100644 index 0000000000000000000000000000000000000000..091436cf8b5c222c22498c5f027a6af536def1a9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BinCutGapMovement.lean @@ -0,0 +1,214 @@ +import OAI.NumberTheory.Jacobsthal.Paths.GeometricRegularWords + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GeometricBoxImages +open PrimeHistories ActualWordSelection ActualRegularBoxes GeometricRegularWords +open SafeSubsetBoxGeometry ErdosSubsetWord LogarithmicBinScale LogarithmicBinLabels +attribute [local instance] Classical.propDecidable + +noncomputable def geometricBoxes {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (C B R L alpha beta : ℝ) (z : Node) : Finset (Fin (binCount w top xi) → ℕ) := + (geometricWords hw htop hxi C B R L alpha beta z).image + (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi)) + +theorem geometric_boxes_subset {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) : + geometricBoxes hw htop hxi C B R L alpha beta z ⊆ regularBoxes hw htop hxi C B R z := by + intro mult hm + obtain ⟨ps,hps,rfl⟩ := Finset.mem_image.mp hm + exact Finset.mem_image.mpr ⟨ps,(Finset.mem_filter.mp hps).1,rfl⟩ + +theorem geometric_box_anchor {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hC : 0 ≤ C) (hcomp : Real.log B ≤ 2*Real.log w) + (hsmall : 2*(xi/Real.log w) ≤ 6*(2*C*xi)) (z : Node) : + ∀ mult ∈ geometricBoxes hw htop hxi C B R L alpha beta z,SafeAnchor hw htop hxi C B R z mult := by + intro mult hm + exact regular_boxes_anchors hw htop hxi hC hcomp hsmall z mult (geometric_boxes_subset hw htop hxi z hm) + +end NumberTheoryLean.GeometricBoxImages + + + +namespace NumberTheoryLean.BinCutSelections +open ErdosCofactorChoices ErdosSubsetWord +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +attribute [local instance] Classical.propDecidable + +noncomputable def aboveMultiplicity {n : ℕ} (m : Fin n → ℕ) (j : Fin n) : Fin n → ℕ := + fun k => if j if j if k if k if j omega + +theorem above_word_length_le {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (j : Fin (binCount w top xi)) : + (descendingWord (aboveSelection f j)).length ≤ ∑ k,m k := by + rw [global_word_length hw htop hxi _ _ (above_selection_mem _ m f hf j)] + exact above_total_le m j + +theorem above_gap_movement {w top xi B C : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hC : 0 ≤ C) (hcomp : Real.log B ≤ 2*Real.log w) (z : Node) + (m : Fin (binCount w top xi) → ℕ) (hlen : ((∑ k,m k : ℕ):ℝ) ≤ C*Real.log B) + (f g : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (hg : g ∈ selections (globalBins w top xi) m) + (j : Fin (binCount w top xi)) : + |(terminal w z (descendingWord (aboveSelection f j))).gap- + (terminal w z (descendingWord (aboveSelection g j))).gap| ≤ 2*C*xi := by + have hfA := above_selection_mem _ m f hf j + have hgA := above_selection_mem _ m g hg j + have hlF : ((descendingWord (aboveSelection f j)).length:ℝ) ≤ C*Real.log B := + (Nat.cast_le.mpr (above_word_length_le hw htop hxi m f hf j)).trans hlen + have hlG : ((descendingWord (aboveSelection g j)).length:ℝ) ≤ C*Real.log B := + (Nat.cast_le.mpr (above_word_length_le hw htop hxi m g hg j)).trans hlen + have hF := source_prefix_movement hw htop hxi hC hcomp z _ (word_source_membership hw htop hxi _ _ hfA) hlF + have hG := source_prefix_movement hw htop hxi hC hcomp z _ (word_source_membership hw htop hxi _ _ hgA) hlG + have he := selection_representatives_eq hw htop hxi _ _ _ hfA hgA + have hrep : representativeGap (representative w (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi)) z.gap (descendingWord (aboveSelection f j))= + representativeGap (representative w (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi)) z.gap (descendingWord (aboveSelection g j)) := by + unfold representativeGap + rw [he] + rw [hrep] at hF + exact abs_le.mpr ⟨by linarith [hF.1,hG.2],by linarith [hF.2,hG.1]⟩ +end NumberTheoryLean.BinCutGapMovement + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedEdgeBins.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedEdgeBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..1919603a4ccff7670fd67bd841ad7e1526a8f18e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedEdgeBins.lean @@ -0,0 +1,108 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FullBoxPrefixLower + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.FullBoxLengthBounds +open FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport +open ErdosCofactorChoices ErdosSubsetWord BinCutSelections BinCutPrefixGeometry BinCutGapMovement +open SafeSubsetBoxGeometry FullBoxPrefixLower PrimeProductLogCoordinates +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition + + +noncomputable def parentLength (w : ℝ) (Y : ℕ) {n : ℕ} (f : Fin n → Finset ℕ) (j : Fin n) : ℝ := + Real.log ((Y:ℝ)/(selectionProduct (aboveSelection f j):ℝ))/Real.log w +noncomputable def childLength (w : ℝ) (Y : ℕ) {n : ℕ} (f : Fin n → Finset ℕ) (j : Fin n) (u : ℕ) : ℝ := + Real.log ((Y:ℝ)/((selectionProduct (aboveSelection f j):ℝ)*(u:ℝ)))/Real.log w + +theorem parent_length_gap {w top xi a : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (hY : 0 < Y) (z : Node) (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (j : Fin (binCount w top xi)) : + parentLength w Y f j=(terminal w z (descendingWord (aboveSelection f j))).gap+a-2 := by + have hsource := word_source_membership hw htop hxi _ _ (above_selection_mem _ m f hf j) + have hg := terminal_gap_log_quotient Y hY z hroot (descendingWord (aboveSelection f j)) + (fun p hp => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hsource p hp)).1.pos) + rw [above_word_product hw htop hxi m f hf j] at hg + unfold parentLength + linarith + +theorem child_length_gap {w top xi a : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (hY : 0 < Y) (z : Node) (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (j : Fin (binCount w top xi)) (u : ℕ) (hu : f j={u}) : + childLength w Y f j u=(terminal w z (descendingWord (aboveSelection f j)++[u])).gap+a-2 := by + have hfull := word_source_membership hw htop hxi m f hf + have hpre := (above_word_is_prefix hw htop hxi m f hf j u hu).2 + have hsub : descendingWord (aboveSelection f j)++[u] ⊆ descendingWord f := by + obtain ⟨tail,he⟩ := (List.mem_inits _ _).mp hpre + intro p hp + rw [← he] + exact List.mem_append_left _ hp + have hg := terminal_gap_log_quotient Y hY z hroot (descendingWord (aboveSelection f j)++[u]) + (fun p hp => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hfull p (hsub hp))).1.pos) + rw [List.prod_append,List.prod_singleton,above_word_product hw htop hxi m f hf j,Nat.cast_mul] at hg + unfold childLength + linarith + +theorem parent_length_movement {w top xi B C a : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hC : 0 ≤ C) (hcomp : Real.log B ≤ 2*Real.log w) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (m : Fin (binCount w top xi) → ℕ) (hlen : ((∑ k,m k : ℕ):ℝ) ≤ C*Real.log B) + (f g : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (hg : g ∈ selections (globalBins w top xi) m) + (j : Fin (binCount w top xi)) : |parentLength w Y f j-parentLength w Y g j| ≤ 2*C*xi := by + rw [parent_length_gap hw htop hxi Y hY z hroot m f hf j,parent_length_gap hw htop hxi Y hY z hroot m g hg j] + convert above_gap_movement hw htop hxi hC hcomp z m hlen f g hf hg j using 1 + congr 1 + ring + +theorem full_box_child_length_lower {w top xi B C K a : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) + (hcomp : Real.log B ≤ 2*Real.log w) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) + (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) + (f : Fin (binCount w top xi) → Finset ℕ) (hf : f ∈ selections (globalBins w top xi) m) + (j : Fin (binCount w top xi)) (u : ℕ) (hu : f j={u}) : a ≤ childLength w Y f j u := by + rw [child_length_gap hw htop hxi Y hY z hroot m f hf j u hu] + have hh := full_box_child_gap_floor hw htop hxi hC hcomp z hs hz hg hclosed hcap m ha f hf j u hu + linarith +end NumberTheoryLean.FullBoxLengthBounds + + + +namespace NumberTheoryLean.BoundedEdgeBins +open ErdosCofactorChoices ErdosSubsetWord FullBoxLengthBounds +open FinitePathGeometry PrimeHistories SafeSubsetBoxGeometry +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +noncomputable def boundedEdgeBin (w top xi : ℝ) (Y : ℕ) + (m : Fin (binCount w top xi) → ℕ) (M X : ℝ) (j : Fin (binCount w top xi)) : Prop := + ∃ f ∈ selections (globalBins w top xi) m,∃ u : ℕ,f j={u} ∧ parentLength w Y f j ≤ M ∧ primeExponent w u ≤ X + +theorem bounded_edge_singleton {w top xi M X : ℝ} {Y : ℕ} + (m : Fin (binCount w top xi) → ℕ) (j : Fin (binCount w top xi)) + (hj : boundedEdgeBin w top xi Y m M X j) : m j=1 := by + obtain ⟨f,hf,u,hfu,_⟩ := hj + have hh := ((mem_selections _ _ _).mp hf j).2 + simpa [hfu] using hh.symm + +theorem anchor_total_length {w top xi B C K : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (z : Node) (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) : + ((∑ k,m k : ℕ):ℝ) ≤ C*Real.log B := by + obtain ⟨g,hg,hlen,_⟩ := ha + rwa [global_word_length hw htop hxi m g hg] at hlen +end NumberTheoryLean.BoundedEdgeBins + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedOrderIntervals.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedOrderIntervals.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e9a7a8a3a3d5b7be57d23b4d37aec6381368273 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedOrderIntervals.lean @@ -0,0 +1,52 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +open Set MeasureTheory +namespace ErdosMonotoneQuadrature + +theorem bounded_orderConnected_interval {S : Set ℝ} {u v : ℝ} + (hS : S.OrdConnected) (hne : S.Nonempty) (hsub : S ⊆ Icc u v) : + ∃ a b : ℝ, u ≤ a ∧ a ≤ b ∧ b ≤ v ∧ + (S = Icc a b ∨ S = Ico a b ∨ S = Ioc a b ∨ S = Ioo a b) := by + have hb : BddBelow S := ⟨u,fun x hx => (hsub hx).1⟩ + have ha : BddAbove S := ⟨v,fun x hx => (hsub hx).2⟩ + have hu : u ≤ sInf S := le_csInf hne (fun x hx => (hsub hx).1) + have hv : sSup S ≤ v := csSup_le hne (fun x hx => (hsub hx).2) + obtain ⟨x,hx⟩ := hne + have hab : sInf S ≤ sSup S := (csInf_le hb hx).trans (le_csSup ha hx) + have hc : IsConnected S := ⟨⟨x,hx⟩,hS.isPreconnected⟩ + have hi := mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset + (hc.Ioo_csInf_csSup_subset hb ha) (subset_Icc_csInf_csSup hb ha) + exact ⟨sInf S,sSup S,hu,hab,hv,hi⟩ + +theorem orderConnected_measure_discrepancy (μ ν : Measure ℝ) (u v E : ℝ) + (hE : 0 ≤ E) + (hinterval : ∀ a b : ℝ, u ≤ a → a ≤ b → b ≤ v → + |μ.real (Icc a b)-ν.real (Icc a b)| ≤ E ∧ + |μ.real (Ico a b)-ν.real (Ico a b)| ≤ E ∧ + |μ.real (Ioc a b)-ν.real (Ioc a b)| ≤ E ∧ + |μ.real (Ioo a b)-ν.real (Ioo a b)| ≤ E) + {S : Set ℝ} (hS : S.OrdConnected) (hsub : S ⊆ Icc u v) : + |μ.real S-ν.real S| ≤ E := by + rcases S.eq_empty_or_nonempty with rfl | hne + · simpa using hE + obtain ⟨a,b,hu,hab,hv,he⟩ := bounded_orderConnected_interval hS hne hsub + obtain ⟨hcc,hco,hoc,hoo⟩ := hinterval a b hu hab hv + rcases he with rfl | rfl | rfl | rfl + · exact hcc + · exact hco + · exact hoc + · exact hoo + +end ErdosMonotoneQuadrature + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedRectangleFubini.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedRectangleFubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..b031a5ee87377710a4e63bd415f2e3ad4e134abc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoundedRectangleFubini.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LossBounds +import OAI.NumberTheory.Jacobsthal.Estimates.ScalarFreeGate + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Set _root_.Erdos970.Set _root_.MeasureTheory _root_.Erdos970.MeasureTheory +open _root_.Filter _root_.Erdos970.Filter +namespace ErdosOmissionBindings + +theorem bounded_rectangle_integrable {f : ℝ×ℝ → ℝ} (hf : Measurable f) + (a b c d C : ℝ) + (hbound : ∀ x ∈ Icc a b,∀ y ∈ Icc c d,|f (x,y)| ≤ C) : + Integrable f ((volume.restrict (Icc a b)).prod (volume.restrict (Icc c d))) := by + let μ : Measure ℝ := volume.restrict (Icc a b) + let ν : Measure ℝ := volume.restrict (Icc c d) + let : IsFiniteMeasure μ := ⟨by + dsimp [μ] + rw [Measure.restrict_apply_univ,Real.volume_Icc] + exact ENNReal.ofReal_lt_top⟩ + let : IsFiniteMeasure ν := ⟨by + dsimp [ν] + rw [Measure.restrict_apply_univ,Real.volume_Icc] + exact ENNReal.ofReal_lt_top⟩ + have hmem : ∀ᵐ p : ℝ×ℝ ∂μ.prod ν,p.1 ∈ Icc a b ∧ p.2 ∈ Icc c d := by + apply (Measure.ae_prod_iff_ae_ae (measurableSet_Icc.prod measurableSet_Icc)).mpr + filter_upwards [ae_restrict_mem measurableSet_Icc] with x hx + filter_upwards [ae_restrict_mem measurableSet_Icc] with y hy + exact ⟨hx,hy⟩ + apply (integrable_const C).mono' hf.aestronglyMeasurable + filter_upwards [hmem] with p hp + simpa only [Real.norm_eq_abs] using hbound p.1 hp.1 p.2 hp.2 + +theorem bounded_rectangle_swap {f : ℝ×ℝ → ℝ} (hf : Measurable f) + (a b c d C : ℝ) + (hbound : ∀ x ∈ Icc a b,∀ y ∈ Icc c d,|f (x,y)| ≤ C) : + (∫ x in Icc a b,∫ y in Icc c d,f (x,y))= + ∫ y in Icc c d,∫ x in Icc a b,f (x,y) := by + exact integral_integral_swap (bounded_rectangle_integrable hf a b c d C hbound) + +end ErdosOmissionBindings + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoxHeightBudget.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoxHeightBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ce04b0cc1e805a4bbe00b661f8a354d3671e05d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoxHeightBudget.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CorrectionFloorRemainder + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseBoxHeight + +theorem small_power_height {z Sq R Z : ℝ} (hz : 4 ≤ z) + (hSq : 0 ≤ Sq) (hR : 0 ≤ R) (hZ : 0 ≤ Z) + (hSqz : Sq ≤ z^((21:ℝ)/10)) (hRz : R ≤ z^((1:ℝ)/100)) + (hZz : Z ≤ z^((1:ℝ)/100)) : 2*Sq*R^2*Z^20 ≤ z^3 := by + have hz0 : 0 ≤ z := by linarith + have hzpos : 0 < z := by linarith + have htwo : (2:ℝ) ≤ z^((1:ℝ)/2) := by + rw [← Real.sqrt_eq_rpow] + exact (Real.le_sqrt (by norm_num) hz0).mpr (by norm_num; exact hz) + have hRp : R^2 ≤ z^((2:ℝ)/100) := by + calc + _ ≤ (z^((1:ℝ)/100))^2 := by gcongr + _ = _ := by rw [← Real.rpow_mul_natCast hz0]; norm_num + have hZp : Z^20 ≤ z^((20:ℝ)/100) := by + calc + _ ≤ (z^((1:ℝ)/100))^20 := by gcongr + _ = _ := by rw [← Real.rpow_mul_natCast hz0]; norm_num + calc + _ ≤ z^((1:ℝ)/2)*z^((21:ℝ)/10)*z^((2:ℝ)/100)*z^((20:ℝ)/100) := by gcongr + _ = z^((141:ℝ)/50) := by + rw [← Real.rpow_add hzpos,← Real.rpow_add hzpos,← Real.rpow_add hzpos] + norm_num + _ ≤ z^3 := by + have h := Real.rpow_le_rpow_of_exponent_le (by linarith : 1 ≤ z) + (by norm_num : (141:ℝ)/50 ≤ 3) + norm_num at h ⊢ + exact h + +theorem uniform_box_height (C : ℝ) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ Sq R B xi q : ℝ, + 0 ≤ Sq → 0 ≤ R → 1 ≤ B → B ≤ Real.log z → 0 ≤ xi → xi ≤ 1 → + 0 < q → q ≤ z^2 → Sq/q ≤ (1+xi)^(C*Real.log B) → R ≤ z^((1:ℝ)/100) → + 2*Sq*R^2*(sourceZ z)^20 ≤ z^3 := by + filter_upwards [uniform_bin_inflation C hC,sourceZ_le_small_power,eventually_ge_atTop (4:ℝ)] + with z hInfl hZ hz + refine ⟨hInfl.1,?_⟩ + intro Sq R B xi q hSq hR hB hBL hxi0 hxi1 hq hqz hinfl hRz + have hBpow := hInfl.2 B xi hB hBL hxi0 hxi1 + have hSqz : Sq ≤ z^((21:ℝ)/10) := by + have hSqbound := (div_le_iff₀ hq).mp (hinfl.trans hBpow) + calc + _ ≤ z^((1:ℝ)/10)*q := hSqbound + _ ≤ z^((1:ℝ)/10)*z^2 := + mul_le_mul_of_nonneg_left hqz (Real.rpow_nonneg (by linarith) _) + _ = _ := by + rw [← Real.rpow_natCast z 2,← Real.rpow_add (by linarith : 0 < z)] + norm_num + exact small_power_height hz hSq hR hZ.2.1.le hSqz hRz hZ.2.2 + +end ErdosInverseBoxHeight + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoxInflation.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoxInflation.lean new file mode 100644 index 0000000000000000000000000000000000000000..010da6e4f419100330fbc196a7948c8e9cd7be73 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/BoxInflation.lean @@ -0,0 +1,64 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +open Filter +open scoped Topology +namespace ErdosInverseBoxHeight + +theorem bin_inflation_le_power {B C xi : ℝ} (hB : 1 ≤ B) (hC : 0 ≤ C) + (hxi0 : 0 ≤ xi) (hxi1 : xi ≤ 1) : + (1+xi)^(C*Real.log B) ≤ B^C := by + have hB0 : 0 < B := by linarith + have hx0 : 0 < 1+xi := by linarith + have hlB : 0 ≤ Real.log B := Real.log_nonneg hB + have hlx : Real.log (1+xi) ≤ 1 := by + have h := Real.log_le_sub_one_of_pos hx0 + linarith + rw [Real.rpow_def_of_pos hx0,Real.rpow_def_of_pos hB0] + apply Real.exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_right hlx (mul_nonneg hC hlB)] + +theorem uniform_bin_inflation (C : ℝ) (hC : 0 ≤ C) : + ∀ᶠ z : ℝ in atTop, 1 < z ∧ ∀ B xi : ℝ, + 1 ≤ B → B ≤ Real.log z → 0 ≤ xi → xi ≤ 1 → + (1+xi)^(C*Real.log B) ≤ z^((1:ℝ)/10) := by + have hlog := (isLittleO_log_rpow_rpow_atTop C (by norm_num : (0:ℝ)<1/10)).bound zero_lt_one + filter_upwards [eventually_gt_atTop (1:ℝ),hlog] with z hz hpow + refine ⟨hz,?_⟩ + intro B xi hB hBz hxi0 hxi1 + have hz0 : 0 ≤ z := by linarith + have hL0 : 0 ≤ Real.log z := Real.log_nonneg hz.le + have hbound : (Real.log z)^C ≤ z^((1:ℝ)/10) := by + simpa only [Real.norm_eq_abs,abs_of_nonneg (Real.rpow_nonneg hL0 C), + abs_of_nonneg (Real.rpow_nonneg hz0 ((1:ℝ)/10)),one_mul] using hpow + exact (bin_inflation_le_power hB hC hxi0 hxi1).trans + ((Real.rpow_le_rpow (by linarith : 0 ≤ B) hBz hC).trans hbound) + +noncomputable def sourceZ (z : ℝ) : ℝ := Real.exp (Real.log z/Real.log (Real.log z)) + +theorem sourceZ_le_small_power : ∀ᶠ z : ℝ in atTop, + 1 < z ∧ 0 < sourceZ z ∧ sourceZ z ≤ z^((1:ℝ)/100) := by + have hlog := (Real.tendsto_log_atTop.comp Real.tendsto_log_atTop).eventually_ge_atTop 100 + filter_upwards [eventually_gt_atTop (1:ℝ),hlog] with z hz hL + dsimp only [Function.comp_apply] at hL + refine ⟨hz,Real.exp_pos _,?_⟩ + have hz0 : 0 < z := by linarith + have hlog0 : 0 ≤ Real.log z := (Real.log_pos hz).le + rw [sourceZ,Real.rpow_def_of_pos hz0] + apply Real.exp_le_exp.mpr + have h := div_le_div_of_nonneg_left hlog0 (by norm_num : (0:ℝ)<100) hL + convert! h using 1 + ring + +end ErdosInverseBoxHeight + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CanonicalCostCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CanonicalCostCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..673ad4e4a9356d39801dd89c83802a4e8f898e14 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CanonicalCostCoordinates.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LowStateHorizon +import OAI.NumberTheory.Jacobsthal.Paths.CanonicalUniformMissingVisit + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.CanonicalCostCoordinates + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures FinitePathGeometry LowStateHorizon +open Erdos970Dependency.MarkedVisits + +theorem raw_cost_step (k : ℕ) (h : RawHistory k) : + ∀ᵐ y ∂rawExtension k (k+1) h, + (rawLast (k+1) y).2 = (y ⟨k,Finset.mem_Iic.mpr k.le_succ⟩).2 + + cost (stateRatio (rawLast (k+1) y).1) := by + have hs : ∀ᵐ y ∂rawExtension k (k+1) h, + (rawLast (k+1) y).2 = (rawLast k h).2 + cost (stateRatio (rawLast (k+1) y).1) := by + apply (ae_map_iff (rawLast_measurable (k+1)).aemeasurable + (measurableSet_eq_fun measurable_snd + (measurable_const.add (cost_measurable.comp (stateRatio_measurable.comp measurable_fst))))).mp + rw [rawExtension_last_step] + exact costKernel_time_update _ + filter_upwards [hs,rawExtension_retains_prefix k.le_succ h] with y hy hp + have he := congrFun hp (⟨k,by simp⟩ : Finset.Iic k) + change y ⟨k,Finset.mem_Iic.mpr k.le_succ⟩ = rawLast k h at he + rw [he] + exact hy + +theorem raw_cost_coordinate {a b k : ℕ} (hak : a ≤ k) (hkb : k < b) (h : RawHistory a) : + ∀ᵐ y ∂rawExtension a b h, + (y ⟨k+1,Finset.mem_Iic.mpr (by omega)⟩).2 = + (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩).2 + + cost (stateRatio (y ⟨k+1,Finset.mem_Iic.mpr (by omega)⟩).1) := by + have hm : MeasurableSet {y : RawHistory (k+1) | + (rawLast (k+1) y).2 = (y ⟨k,Finset.mem_Iic.mpr k.le_succ⟩).2 + + cost (stateRatio (rawLast (k+1) y).1)} := + measurableSet_eq_fun (measurable_snd.comp (rawLast_measurable _)) + ((measurable_snd.comp (measurable_pi_apply _)).add + (cost_measurable.comp (stateRatio_measurable.comp + (measurable_fst.comp (rawLast_measurable _))))) + have he : (rawExtension a b h).map (rawPrefix (show k+1 ≤ b by omega)) = rawExtension a (k+1) h := + Kernel.partialTraj_map_frestrictLe₂_apply (X := fun _ => CostState) (κ := historyKernel) h (by omega) + have ht : ∀ᵐ y ∂rawExtension a (k+1) h, + (rawLast (k+1) y).2 = (y ⟨k,Finset.mem_Iic.mpr k.le_succ⟩).2 + + cost (stateRatio (rawLast (k+1) y).1) := by + have hc : rawExtension a (k+1) = rawExtension k (k+1) ∘ₖ rawExtension a k := + (Kernel.partialTraj_comp_partialTraj hak (by omega)).symm + rw [hc] + exact Kernel.ae_comp_of_ae_ae hm (Eventually.of_forall (raw_cost_step k)) + rw [← he] at ht + exact (ae_map_iff (rawPrefix_measurable (show k+1 ≤ b by omega)).aemeasurable hm).mp ht + +end NumberTheoryLean.CanonicalCostCoordinates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CellLengthLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CellLengthLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..4717dfa7517c64947a1ace1f5113886974e151f5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CellLengthLower.lean @@ -0,0 +1,111 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PositiveProgression + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseTail +open ErdosInverseHits + +noncomputable def commonParentLength (Y p : ℕ) (Qplus : ℝ) : ℕ := + ⌊(Y : ℝ)/((p : ℝ)*Qplus)⌋₊ + +theorem commonParentLength_le_hits (Y p q b : ℕ) (hp : 0 < p) (hq : 0 < q) + (hb : b ≤ p*q) (Qplus : ℝ) (hqQ : (q : ℝ) ≤ Qplus) : + commonParentLength Y p Qplus ≤ hitLength Y (p*q) b := by + have hpR : (0 : ℝ) < p := by exact_mod_cast hp + have hqR : (0 : ℝ) < q := by exact_mod_cast hq + have hQ : 0 < Qplus := hqR.trans_le hqQ + have hA : 0 ≤ (Y : ℝ)/((p : ℝ)*Qplus) := by positivity + have hJ : (commonParentLength Y p Qplus : ℝ) ≤ (Y : ℝ)/((p : ℝ)*Qplus) := Nat.floor_le hA + have hden : (p : ℝ)*q ≤ (p : ℝ)*Qplus := mul_le_mul_of_nonneg_left hqQ hpR.le + have hJB : (commonParentLength Y p Qplus : ℝ) ≤ (Y : ℝ)/((p : ℝ)*q) := + hJ.trans (div_le_div_of_nonneg_left (Nat.cast_nonneg _) (mul_pos hpR hqR) hden) + have hnat : commonParentLength Y p Qplus*(p*q) ≤ Y := by + exact_mod_cast (le_div_iff₀ (mul_pos hpR hqR)).mp hJB + have hdiv : commonParentLength Y p Qplus ≤ Y/(p*q) := (Nat.le_div_iff_mul_le (mul_pos hp hq)).mpr hnat + exact hdiv.trans (Nat.div_le_div_right (by omega : Y ≤ Y+p*q-b)) + +theorem actual_cell_tail_length (Y p q b : ℕ) (hp : 0 < p) (hq : 0 < q) + (hb1 : 1 ≤ b) (hb : b ≤ p*q) (Qplus xi : ℝ) + (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) (hqQ : (q : ℝ) ≤ Qplus) (hQq : Qplus ≤ (1+xi)*(q : ℝ)) : + ((hitLength Y (p*q) b-commonParentLength Y p Qplus : ℕ) : ℝ) ≤ + xi*(commonParentLength Y p Qplus : ℝ)+3 := by + have hpR : (0 : ℝ) < p := by exact_mod_cast hp + have hqR : (0 : ℝ) < q := by exact_mod_cast hq + have hQ : 0 < Qplus := hqR.trans_le hqQ + have hA : 0 ≤ (Y : ℝ)/((p : ℝ)*Qplus) := by positivity + have hJlt : (Y : ℝ)/((p : ℝ)*Qplus) < (commonParentLength Y p Qplus : ℝ)+1 := Nat.lt_floor_add_one _ + have hratio : Qplus/(q : ℝ) ≤ 1+xi := (div_le_iff₀ hqR).mpr hQq + have hB : (Y : ℝ)/((p : ℝ)*q) ≤ (1+xi)*((Y : ℝ)/((p : ℝ)*Qplus)) := by + calc + _ = ((Y : ℝ)/((p : ℝ)*Qplus))*(Qplus/(q : ℝ)) := by field_simp + _ ≤ ((Y : ℝ)/((p : ℝ)*Qplus))*(1+xi) := mul_le_mul_of_nonneg_left hratio hA + _ = _ := by ring + have herr := hitLength_error Y (p*q) b (mul_pos hp hq) hb1 hb + have hN : (hitLength Y (p*q) b : ℝ) ≤ (Y : ℝ)/((p : ℝ)*q)+1 := by + have hh := (abs_le.mp herr).2 + push_cast at hh + linarith + have hJN := commonParentLength_le_hits Y p q b hp hq hb Qplus hqQ + rw [Nat.cast_sub hJN] + have hpay := mul_le_mul_of_nonneg_left hJlt.le (by linarith : 0 ≤ 1+xi) + nlinarith + +end ErdosInverseTail + +end + +section + +namespace ErdosInverseTail + +theorem common_length_from_log (Y p q u : ℕ) (hp : 0 < p) (hq : 0 < q) (hu : 0 < u) + (Qplus xi w aStar : ℝ) (hqQ : (q : ℝ) ≤ Qplus) (hQq : Qplus ≤ (1+xi)*(q : ℝ)) + (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) (hw : 1 < w) (ha : 0 < aStar) + (hlen : 3*aStar/4 ≤ Real.log ((Y : ℝ)/((p : ℝ)*q*u))/Real.log w) : + w^(3*aStar/4) ≤ 2*(commonParentLength Y p Qplus : ℝ)/(u : ℝ)+2 := by + have hpR : (0 : ℝ) < p := by exact_mod_cast hp + have hqR : (0 : ℝ) < q := by exact_mod_cast hq + have huR : (0 : ℝ) < u := by exact_mod_cast hu + have hu1 : (1 : ℝ) ≤ u := by exact_mod_cast hu + have hQ : 0 < Qplus := hqR.trans_le hqQ + have hw0 : 0 < w := by linarith + have hlogw : 0 < Real.log w := Real.log_pos hw + have hlog := (le_div_iff₀ hlogw).mp hlen + have hlogpos : 0 < Real.log ((Y : ℝ)/((p : ℝ)*q*u)) := by nlinarith + have hR1 : 1 < (Y : ℝ)/((p : ℝ)*q*u) := (Real.log_pos_iff (by positivity)).mp hlogpos + have hpow : w^(3*aStar/4) ≤ (Y : ℝ)/((p : ℝ)*q*u) := by + rw [Real.rpow_def_of_pos hw0] + calc + _ ≤ Real.exp (Real.log ((Y : ℝ)/((p : ℝ)*q*u))) := Real.exp_le_exp.mpr (by nlinarith [hlog]) + _ = _ := Real.exp_log (by linarith) + have hA : 0 ≤ (Y : ℝ)/((p : ℝ)*Qplus) := by positivity + have hJlt : (Y : ℝ)/((p : ℝ)*Qplus) < (commonParentLength Y p Qplus : ℝ)+1 := Nat.lt_floor_add_one _ + have hratio : Qplus/(q : ℝ) ≤ 1+xi := (div_le_iff₀ hqR).mpr hQq + have hRupper : (Y : ℝ)/((p : ℝ)*q*u) ≤ 2*((commonParentLength Y p Qplus : ℝ)+1)/(u : ℝ) := by + calc + _ = ((Y : ℝ)/((p : ℝ)*Qplus))*(Qplus/(q : ℝ))/(u : ℝ) := by field_simp + _ ≤ ((Y : ℝ)/((p : ℝ)*Qplus))*(1+xi)/(u : ℝ) := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hratio hA) huR.le + _ ≤ ((commonParentLength Y p Qplus : ℝ)+1)*(1+xi)/(u : ℝ) := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hJlt.le (by linarith)) huR.le + _ ≤ 2*((commonParentLength Y p Qplus : ℝ)+1)/(u : ℝ) := by + apply div_le_div_of_nonneg_right _ huR.le + nlinarith [show (0 : ℝ) ≤ commonParentLength Y p Qplus from Nat.cast_nonneg _] + have htwo : (2 : ℝ)/(u : ℝ) ≤ 2 := (div_le_iff₀ huR).mpr (by linarith) + calc + _ ≤ (Y : ℝ)/((p : ℝ)*q*u) := hpow + _ ≤ 2*((commonParentLength Y p Qplus : ℝ)+1)/(u : ℝ) := hRupper + _ = 2*(commonParentLength Y p Qplus : ℝ)/(u : ℝ)+2/(u : ℝ) := by ring + _ ≤ _ := add_le_add le_rfl htwo + +end ErdosInverseTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CoefficientBoxCollision.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CoefficientBoxCollision.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb3eb8b89cbf4c0b08a9cb79592b3a1d249d26f6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CoefficientBoxCollision.lean @@ -0,0 +1,59 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAuxiliaryPolynomial + +def boxLift {ι : Type*} {H : ℕ} (x : ι → Fin (H+1)) : ι → ℤ := fun i => (x i).val + +theorem boxLift_injective {ι : Type*} {H : ℕ} : Function.Injective (@boxLift ι H) := by + intro x y h + funext i + apply Fin.ext + have hi : ((x i).val : ℤ) = ((y i).val : ℤ) := congrFun h i + exact_mod_cast hi + +theorem exists_bounded_kernel_vector {ι Γ : Type*} [Fintype ι] + [AddCommGroup Γ] [Fintype Γ] (φ : (ι → ℤ) →+ Γ) (H : ℕ) + (hcard : Fintype.card Γ < (H+1)^(Fintype.card ι)) : + ∃ v : ι → ℤ, v ≠ 0 ∧ (∀ i, |v i| ≤ (H : ℤ)) ∧ φ v = 0 := by + classical + let f : (ι → Fin (H+1)) → Γ := fun x => φ (boxLift x) + have hnot : ¬Function.Injective f := by + intro hinj + have hc := Fintype.card_le_of_injective f hinj + have he : Fintype.card (ι → Fin (H+1)) = (H+1)^(Fintype.card ι) := by simp + rw [he] at hc + exact (not_le_of_gt hcard) hc + unfold Function.Injective at hnot + push Not at hnot + obtain ⟨x,y,hxy,hne⟩ := hnot + let v := boxLift x - boxLift y + have hv : v ≠ 0 := by + intro hz + apply hne + apply boxLift_injective + exact sub_eq_zero.mp hz + refine ⟨v,hv,?_,?_⟩ + · intro i + have hx := (x i).isLt + have hy := (y i).isLt + change |((x i).val : ℤ) - ((y i).val : ℤ)| ≤ (H : ℤ) + rw [abs_le] + omega + · change φ (boxLift x - boxLift y) = 0 + rw [map_sub] + change φ (boxLift x) = φ (boxLift y) at hxy + rw [hxy,sub_self] + +end ErdosAuxiliaryPolynomial + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CommonCellSum.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CommonCellSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..79ae9066924b789ab836ddc4032798fd23ca2387 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CommonCellSum.lean @@ -0,0 +1,388 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeCompactWeights +import OAI.NumberTheory.Jacobsthal.Probability.ActualCouplingUpdates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ContinuousParentBins + +open _root_.Set _root_.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltBounds PrimeTiltMonotone ContinuousRatioBins +open HarmonicExponentMeasure WeightGlobalBounds + +theorem multiplier_source_ratio {i : Side} {s t : ℝ} (hs : Valid i s) (ht : Valid i t) (u : ℝ) : + multiplier i s u = (weight i t/weight i s)*multiplier i t u := by + by_cases hu : u = 0 + · simp [multiplier,hu] + · unfold multiplier + field_simp [hu,(weight_pos hs).ne',(weight_pos ht).ne'] + +theorem continuous_bin_mass_ratio {i : Side} {s t a b : ℝ} (hs : Valid i s) (ht : Valid i t) + (hsa : minRatio i s ≤ a) (hta : minRatio i t ≤ a) : + weightedRatioLaw i s (Ico a b) = ENNReal.ofReal (weight i t/weight i s) * weightedRatioLaw i t (Ico a b) := by + have hq : 0 ≤ weight i t/weight i s := (div_pos (weight_pos ht) (weight_pos hs)).le + simp only [weightedRatioLaw, withDensity_apply _ measurableSet_Ico] + rw [ratio_restrict_bin hsa, ratio_restrict_bin hta, ← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro u + rw [multiplier_source_ratio hs ht u, ENNReal.ofReal_mul hq] + +theorem continuousBin_parent_ratio {i : Side} {s t a b : ℝ} (hs : Valid i s) (ht : Valid i t) + (hsa : minRatio i s ≤ a) (hta : minRatio i t ≤ a) : + continuousBin i s a b = (weight i t/weight i s)*continuousBin i t a b := by + unfold continuousBin + rw [continuous_bin_mass_ratio hs ht hsa hta, ENNReal.toReal_mul, + ENNReal.toReal_ofReal (div_pos (weight_pos ht) (weight_pos hs)).le] + +theorem positive_ratio_error {a b d : ℝ} (ha : 0 < a) (hb : 0 < b) + (hlog : |Real.log a-Real.log b| ≤ d) : |a/b-1| ≤ Real.exp d-1 := by + have hq := div_pos ha hb + rw [← Real.log_div ha.ne' hb.ne'] at hlog + have hlo := Real.exp_le_exp.mpr (abs_le.mp hlog).1 + have hup := Real.exp_le_exp.mpr (abs_le.mp hlog).2 + rw [Real.exp_log hq] at hlo hup + have hsum : 2 ≤ Real.exp d+Real.exp (-d) := by + linarith [Real.add_one_le_exp d, Real.add_one_le_exp (-d)] + rw [abs_le] + constructor <;> linarith + +theorem continuous_parent_bin_error : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, 3 ≤ S → + ∀ i : Side, ∀ s t a b : ℝ, Valid i s → Valid i t → s ≤ S → t ≤ S → + minRatio i s ≤ a → minRatio i t ≤ a → + |continuousBin i s a b-continuousBin i t a b| ≤ + (Real.exp (C*(1+S)^3*|s-t|)-1)*continuousBin i t a b := by + obtain ⟨C,hC,hbound⟩ := weights_log_lipschitz + refine ⟨C,hC,?_⟩ + intro S hS i s t a b hs ht hsS htS hsa hta + have hlogs : |Real.log (weight i s)-Real.log (weight i t)| ≤ C*(1+S)^3*|s-t| := by + cases i with + | even => exact (hbound S hS).1 s t hs ht hsS htS + | odd => exact (hbound S hS).2 s t hs ht hsS htS + have hr := positive_ratio_error (weight_pos ht) (weight_pos hs) + ((abs_sub_comm _ _).trans_le hlogs) + have hmass : 0 ≤ continuousBin i t a b := ENNReal.toReal_nonneg + rw [continuousBin_parent_ratio hs ht hsa hta] + rw [show (weight i t/weight i s)*continuousBin i t a b-continuousBin i t a b = + (weight i t/weight i s-1)*continuousBin i t a b by ring, abs_mul, abs_of_nonneg hmass] + exact mul_le_mul_of_nonneg_right hr hmass + +end NumberTheoryLean.ContinuousParentBins + +end + +section + +namespace NumberTheoryLean.NearbyParentFullBins + +open _root_.Set _root_.MeasureTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open PrimeBinMembership ActualPrimeBins ContinuousKilledBins +open NormalizedPrimeBins ContinuousRatioBins ContinuousParentBins RegeneratingInverseBands + + theorem nearby_parent_full_bin_error : ∃ c C D w₀ : ℝ, 0 < c ∧ 0 < C ∧ 0 < D ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, ∀ h : History w ell S start, + ∀ v : ℝ, ∀ z : CostState, ∀ a b : ℝ, + 1 ≤ ell → 3 ≤ S → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → Consistent start → + stateRatio z.1 ≤ S → h.node.side = stateSide z.1 → + minRatio h.node.side h.node.ratio < a → minRatio (stateSide z.1) (stateRatio z.1) < a → + a ≤ b → b ≤ S → b ≤ h.node.gap/ell-1 → b ≤ gapValue v z/ell-1 → + |(chain w ell S start (some h) (liveBin a b)).toReal - + (continuousChain v ell S (.inl z) (Sum.inl '' ratioBinSet a b)).toReal| ≤ + C*(1+S)^5*((b-a)^2+Real.exp (-c*Real.sqrt ((1/2 : ℝ)*Real.log w))) + + epsilon w*continuousBin h.node.side h.node.ratio a b + + (Real.exp (D*(1+S)^3*|h.node.ratio-stateRatio z.1|)-1)* + continuousBin (stateSide z.1) (stateRatio z.1) a b := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hprime⟩ := normalized_bin_error + obtain ⟨D,hD,hparent⟩ := continuous_parent_bin_error + refine ⟨c,C,D,w₀,hc,hC,hD,hw₀,?_⟩ + intro w hw ell S start h v z a b hell hS hr hs hsS hcons htS hside hma hta hab hbS harrP harrC + have hw1 := hw₀.trans_le hw + have hell0 : 0 < ell := by linarith + have hnvalid := terminal_valid hs h.admissible + have hngap := terminal_gap_positive hell0.le hr hs h.admissible + have hnS := terminal_ratio_le hsS h.admissible + have hncons := history_consistent hell0.le hr hs hcons h + have htvalid : Valid h.node.side (stateRatio z.1) := by rw [hside]; exact stateRatio_valid z.1 + have hta' : minRatio h.node.side (stateRatio z.1) < a := by rwa [hside] + have ha : 0 < a := (PrimeTiltMonotone.minRatio_pos hnvalid).trans hma + have hlow : (1/2 : ℝ) ≤ h.node.gap/(b+1) := by + have h : ell ≤ h.node.gap/(b+1) := by + apply (le_div_iff₀ (by linarith : 0 < b+1)).mpr + have hm := (le_div_iff₀ hell0).mp (show b+1 ≤ h.node.gap/ell by linarith) + nlinarith + linarith + rw [chain_full_bin_real h hw1 hell0 hngap hnvalid hncons hma hab hbS harrP, + continuousChain_full_bin_real v hell0 z hbS harrC, ← hside] + exact (abs_sub_le _ (continuousBin h.node.side h.node.ratio a b) _).trans (add_le_add + (hprime w hw h.node.gap S hngap hS h.node.side h.node.ratio a b hnvalid hnS hma.le hab hbS hlow) + (hparent S hS h.node.side h.node.ratio (stateRatio z.1) a b hnvalid htvalid hnS htS hma.le hta'.le)) + +end NumberTheoryLean.NearbyParentFullBins + +end + +section + +namespace NumberTheoryLean.ActualSupportIntervals + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open PrimeTiltGeometry ActualCouplingUpdates ContinuousKilledBins LowStateHorizon +open ArrivalKernelGeometry RegeneratingInverseBands PairedCostGrouping + +noncomputable def upperSupport (S ell r : ℝ) : ℝ := min S (r/ell-1) + +theorem prime_child_interval {w ell S : ℝ} {start : Node} (h : History w ell S start) + (hell : 0 < ell) (hr : 0 < h.node.gap) (hs : Valid h.node.side h.node.ratio) + (p : ℕ) (hp : p ∈ nodeChildren w ell S h.node) : + (h.append p hp).node.ratio ∈ Icc (minRatio h.node.side h.node.ratio) (upperSupport S ell h.node.gap) := by + classical + have hp' := (Finset.mem_filter.mp hp).2 + have ht0 := valid_pos (child_valid hs hp) + have hx := hp'.1 + have heq := nextExponent_childRatio hr (child_exponent_positive hell.le hp) + have hu : childRatio w h.node.gap p < h.node.gap/ell-1 := by + rw [← heq] at hx + have hmul := (lt_div_iff₀ (by linarith : 0 < childRatio w h.node.gap p+1)).mp hx + have hdiv : childRatio w h.node.gap p+1 < h.node.gap/ell := (lt_div_iff₀ hell).mpr (by nlinarith) + linarith + rw [History.append_node] + exact ⟨hp'.2.2.1,le_min hp'.2.2.2 hu.le⟩ + +theorem prime_row_interval {w ell S : ℝ} {start : Node} (h : History w ell S start) + (hell : 0 < ell) (hr : 0 < h.node.gap) (hs : Valid h.node.side h.node.ratio) : + ∀ᵐ k ∂chain w ell S start (some h), + match k with + | none => True + | some k => k.node.ratio ∈ Icc (minRatio h.node.side h.node.ratio) (upperSupport S ell h.node.gap) := by + filter_upwards [prime_follows h] with k hk + cases k with + | none => trivial + | some k => + obtain ⟨p,hp,rfl⟩ := hk + exact prime_child_interval h hell hr hs p hp + +theorem costKernel_lower_support (z : CostState) : + ∀ᵐ y ∂costKernel z, minRatio (stateSide z.1) (stateRatio z.1) ≤ stateRatio y.1 := by + have hm : Measurable (fun s : State => (s,z.2+cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + have hP : MeasurableSet {y : CostState | minRatio (stateSide z.1) (stateRatio z.1) ≤ stateRatio y.1} := + measurableSet_le measurable_const (stateRatio_measurable.comp measurable_fst) + rw [costKernel_eq_map] + exact (ae_map_iff hm.aemeasurable hP).mpr (stateKernel_ae_minRatio z.1) + +theorem continuous_interval_measurable (v ell S : ℝ) (z : CostState) : + MeasurableSet {y : CostState | stateRatio y.1 ∈ + Icc (minRatio (stateSide z.1) (stateRatio z.1)) (upperSupport S ell (gapValue v z))} := + (stateRatio_measurable.comp measurable_fst) measurableSet_Icc + +theorem continuous_low_interval (v S : ℝ) {ell : ℝ} (hell : 0 < ell) (z : CostState) : + ∀ᵐ y ∂lowKernel costKernel v ell S z, stateRatio y.1 ∈ + Icc (minRatio (stateSide z.1) (stateRatio z.1)) (upperSupport S ell (gapValue v z)) := by + rw [lowKernel,Kernel.restrict_apply] + filter_upwards [ae_restrict_of_ae (costKernel_time_update z),ae_restrict_of_ae (costKernel_lower_support z), + ae_restrict_mem (lowDomain_measurable v ell S)] with y htime hlo hD + have hy : y = (y.1,z.2+cost (stateRatio y.1)) := Prod.ext rfl htime + have hcur : currentExponent v y = nextExponent (gapValue v z) (stateRatio y.1) := by + calc + _ = currentExponent v (y.1,z.2+cost (stateRatio y.1)) := congrArg (currentExponent v) hy + _ = _ := currentExponent_update v z y.1 + have hupper : stateRatio y.1 < gapValue v z/ell-1 := by + have hx : ell < nextExponent (gapValue v z) (stateRatio y.1) := by + rw [← hcur] + exact hD.1 + have ht0 := OccupationBoundaries.stateRatio_pos y.1 + have hmul := (lt_div_iff₀ (by linarith : 0 < stateRatio y.1+1)).mp hx + have hdiv : stateRatio y.1+1 < gapValue v z/ell := (lt_div_iff₀ hell).mpr (by nlinarith) + linarith + exact ⟨hlo,le_min hD.2 hupper.le⟩ + +theorem continuous_row_interval (v S : ℝ) {ell : ℝ} (hell : 0 < ell) (z : CostState) : + ∀ᵐ y ∂continuousChain v ell S (.inl z), liftPredicate (fun y : CostState => stateRatio y.1 ∈ + Icc (minRatio (stateSide z.1) (stateRatio z.1)) (upperSupport S ell (gapValue v z))) y := + complete_ae _ z (continuous_interval_measurable v ell S z) (continuous_low_interval v S hell z) + +end NumberTheoryLean.ActualSupportIntervals + +end + +section + +namespace NumberTheoryLean.ActualMeshBins + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualCouplingSupport ActualPrimeBins ContinuousKilledBins +open MeshRatioLabels MeshBoundaryGeometry ActualSupportIntervals PrimeBinMembership +open NearbyParentFullBins ContinuousRatioBins RegeneratingInverseBands + +variable {w ell S : ℝ} {start : Node} + +theorem prime_label_eq_bin {mesh : ℝ} (hm : 0 < mesh) (hs : Valid start.side start.ratio) + (hsS : start.ratio ≤ S) (j : Label S mesh) (hj : j ≠ cemeteryLabel S mesh) : + (primeLabel w ell S mesh start) ⁻¹' {j} = liveBin (lowerEdge j) (upperEdge j) := by + ext p + cases p with + | none => + change cemeteryLabel S mesh = j ↔ False + simp [Ne.symm hj] + | some h => + have ht := valid_pos (terminal_valid hs h.admissible) + have hS := terminal_ratio_le hsS h.admissible + exact ratioLabel_eq_iff hm ht.le hS j + +theorem continuous_label_mass_eq_bin (v ell S : ℝ) {mesh : ℝ} (hm : 0 < mesh) + (z : CostState) (j : Label S mesh) (hj : j ≠ cemeteryLabel S mesh) : + continuousChain v ell S (.inl z) ((continuousLabel S mesh) ⁻¹' {j}) = + continuousChain v ell S (.inl z) (Sum.inl '' ratioBinSet (lowerEdge j) (upperEdge j)) := by + 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 = j) ↔ ∃ x ∈ ratioBinSet (lowerEdge j) (upperEdge j), (Sum.inl x : CemeteryKernel.Space CostState) = Sum.inr u + simp [Ne.symm hj] + | inl y => + have heq := ratioLabel_eq_iff hm (OccupationBoundaries.stateRatio_pos y.1).le hy j + change (ratioLabel S mesh (stateRatio y.1) = j) ↔ ∃ x ∈ ratioBinSet (lowerEdge j) (upperEdge j), (Sum.inl x : CemeteryKernel.Space CostState) = Sum.inl y + simpa only [Set.mem_image,Sum.inl.injEq,exists_eq_right,ratioBinSet,mem_ofPred_eq,lowerEdge,upperEdge] using heq + +theorem cell_below_S_not_cemetery {S mesh : ℝ} (hm : 0 < mesh) (j : Label S mesh) + (hj : upperEdge j ≤ S) : j ≠ cemeteryLabel S mesh := by + intro heq + subst j + have hf := Nat.lt_floor_add_one (S/mesh) + have hmul : S < ((⌊S/mesh⌋₊:ℝ)+1)*mesh := (div_lt_iff₀ hm).mp hf + change (((binCount S mesh+1:ℕ):ℝ)+1)*mesh ≤ S at hj + simp only [Nat.cast_add,Nat.cast_one,binCount] at hj + nlinarith + +theorem mesh_cells_disjoint {S mesh : ℝ} (hm : 0 < mesh) : + Pairwise (fun j k : Label S mesh => Disjoint (Ico (lowerEdge j) (upperEdge j)) (Ico (lowerEdge k) (upperEdge k))) := by + intro j k hjk + apply Set.disjoint_left.mpr + intro t htj htk + have hne : j.val ≠ k.val := fun h => hjk (Fin.ext h) + rcases lt_or_gt_of_ne hne with hlt | hgt + · have hle : (j.val:ℝ)+1 ≤ (k.val:ℝ) := by exact_mod_cast Nat.succ_le_of_lt hlt + have he : upperEdge j ≤ lowerEdge k := mul_le_mul_of_nonneg_right hle hm.le + exact (htj.2.trans_le (he.trans htk.1)).false + · have hle : (k.val:ℝ)+1 ≤ (j.val:ℝ) := by exact_mod_cast Nat.succ_le_of_lt hgt + have he : upperEdge k ≤ lowerEdge j := mul_le_mul_of_nonneg_right hle hm.le + exact (htk.2.trans_le (he.trans htj.1)).false + +theorem continuous_mesh_sum_le_one {S mesh s : ℝ} {i : Side} (hm : 0 < mesh) (hs : Valid i s) + (I : Finset (Label S mesh)) : + (∑ j ∈ I,continuousBin i s (lowerEdge j) (upperEdge j)) ≤ 1 := by + let := weightedRatioLaw_probability hs + have hUnion := measure_biUnion_finset (μ:=weightedRatioLaw i s) + (s:=I) (f:=fun j => Ico (lowerEdge j) (upperEdge j)) + (fun _ _ _ _ hne => mesh_cells_disjoint hm hne) (fun _ _ => measurableSet_Ico) + have hmass : (∑ j ∈ I,weightedRatioLaw i s (Ico (lowerEdge j) (upperEdge j))) ≤ 1 := by + rw [← hUnion] + exact (measure_mono (subset_univ _)).trans_eq measure_univ + unfold continuousBin + rw [← ENNReal.toReal_sum (fun j _ => measure_ne_top (weightedRatioLaw i s) (Ico (lowerEdge j) (upperEdge j)))] + simpa only [ENNReal.toReal_one] using ENNReal.toReal_mono ENNReal.one_ne_top hmass + +theorem common_cell_error : ∃ c C D w₀ : ℝ, 0 < c ∧ 0 < C ∧ 0 < D ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, ∀ h : History w ell S start, + ∀ v : ℝ, ∀ z : CostState, ∀ mesh : ℝ, ∀ j : Label S mesh, + 1 ≤ ell → 3 ≤ S → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → Consistent start → + stateRatio z.1 ≤ S → h.node.side = stateSide z.1 → 0 < mesh → + fullCell (minRatio h.node.side h.node.ratio) (minRatio (stateSide z.1) (stateRatio z.1)) + (upperSupport S ell h.node.gap) (upperSupport S ell (gapValue v z)) j → + |(chain w ell S start (some h) ((primeLabel w ell S mesh start) ⁻¹' {j})).toReal- + (continuousChain v ell S (.inl z) ((continuousLabel S mesh) ⁻¹' {j})).toReal| ≤ + C*(1+S)^5*(mesh^2+Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)))+ + epsilon w*continuousBin h.node.side h.node.ratio (lowerEdge j) (upperEdge j)+ + (Real.exp (D*(1+S)^3*|h.node.ratio-stateRatio z.1|)-1)* + continuousBin (stateSide z.1) (stateRatio z.1) (lowerEdge j) (upperEdge j) := by + obtain ⟨c,C,D,w₀,hc,hC,hD,hw₀,hbound⟩ := nearby_parent_full_bin_error + refine ⟨c,C,D,w₀,hc,hC,hD,hw₀,?_⟩ + intro w hw ell S start h v z mesh j hell hS hr hs hsS hcons hzS hside hm hcell + have hLd := (le_max_left _ _).trans_lt hcell.1 + have hLc := (le_max_right _ _).trans_lt hcell.1 + have hUd := hcell.2.trans (min_le_left _ _) + have hUc := hcell.2.trans (min_le_right _ _) + have hbS := hUd.trans (min_le_left _ _) + have hbp := hUd.trans (min_le_right _ _) + have hbc := hUc.trans (min_le_right _ _) + have hj := cell_below_S_not_cemetery hm j hbS + rw [prime_label_eq_bin hm hs hsS j hj,continuous_label_mass_eq_bin v ell S hm z j hj] + have hab : lowerEdge j ≤ upperEdge j := by unfold lowerEdge upperEdge; nlinarith + have he := hbound w hw ell S start h v z (lowerEdge j) (upperEdge j) hell hS hr hs hsS hcons hzS hside hLd hLc hab hbS hbp hbc + have hwidth : upperEdge j-lowerEdge j = mesh := by unfold upperEdge lowerEdge; ring + rwa [hwidth] at he + +end NumberTheoryLean.ActualMeshBins + +end + +section + +namespace NumberTheoryLean.CommonCellSum + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open MeshRatioLabels MeshBoundaryGeometry ActualSupportIntervals ActualMeshBins +open ActualProcessCoupling ContinuousKilledBins PrimeBinMembership +open ContinuousRatioBins RegeneratingInverseBands KernelBinConditioning + +theorem common_cell_sum_error : ∃ c C D w₀ : ℝ, 0 < c ∧ 0 < C ∧ 0 < D ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ start : Node, ∀ h : History w ell S start, + ∀ v : ℝ, ∀ z : CostState, ∀ mesh : ℝ, ∀ I : Finset (Label S mesh), + 1 ≤ ell → 3 ≤ S → 0 < start.gap → Valid start.side start.ratio → start.ratio ≤ S → Consistent start → + stateRatio z.1 ≤ S → h.node.side = stateSide z.1 → 0 < mesh → + (∀ j ∈ I, fullCell (minRatio h.node.side h.node.ratio) (minRatio (stateSide z.1) (stateRatio z.1)) + (upperSupport S ell h.node.gap) (upperSupport S ell (gapValue v z)) j) → + (∑ j ∈ I, |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|) ≤ + (S/mesh+2)*(C*(1+S)^5*(mesh^2+Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))))+ + epsilon w+(Real.exp (D*(1+S)^3*|h.node.ratio-stateRatio z.1|)-1) := by + obtain ⟨c,C,D,w₀,hc,hC,hD,hw₀,hbound⟩ := common_cell_error + refine ⟨c,C,D,w₀,hc,hC,hD,hw₀,?_⟩ + intro w hw ell S start h v z mesh I hell hS hr hs hsS hcons hzS hside hm hcells + let A := C*(1+S)^5*(mesh^2+Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))) + let Q := Real.exp (D*(1+S)^3*|h.node.ratio-stateRatio z.1|)-1 + let P : Label S mesh → ℝ := fun j => continuousBin h.node.side h.node.ratio (lowerEdge j) (upperEdge j) + let R : Label S mesh → ℝ := fun j => continuousBin (stateSide z.1) (stateRatio z.1) (lowerEdge j) (upperEdge j) + have hS1 : 0 ≤ 1+S := by linarith + have hA : 0 ≤ A := by dsimp [A]; positivity + have hQ : 0 ≤ Q := by + apply sub_nonneg.mpr + apply Real.one_le_exp_iff.mpr + positivity + have hPsum : (∑ j ∈ I,P j) ≤ 1 := continuous_mesh_sum_le_one hm (terminal_valid hs h.admissible) I + have hRsum : (∑ j ∈ I,R j) ≤ 1 := continuous_mesh_sum_le_one hm (stateRatio_valid z.1) I + have hcard : (I.card:ℝ) ≤ S/mesh+2 := by + have h : (I.card:ℝ) ≤ (Fintype.card (Label S mesh):ℝ) := by exact_mod_cast Finset.card_le_univ I + exact h.trans (label_card_le (by linarith) hm) + calc + _ ≤ ∑ j ∈ I,(A+epsilon w*P j+Q*R j) := by + apply Finset.sum_le_sum + intro j hj + exact hbound w hw ell S start h v z mesh j hell hS hr hs hsS hcons hzS hside hm (hcells j hj) + _ = (I.card:ℝ)*A+epsilon w*(∑ j ∈ I,P j)+Q*(∑ j ∈ I,R j) := by + simp only [Finset.sum_add_distrib,Finset.sum_const,nsmul_eq_mul,← Finset.mul_sum] + _ ≤ _ := by + have h1 := mul_le_mul_of_nonneg_right hcard hA + have h2 := mul_le_mul_of_nonneg_left hPsum (epsilon_pos w).le + have h3 := mul_le_mul_of_nonneg_left hRsum hQ + dsimp only [A,Q] at h1 h3 ⊢ + linarith + +end NumberTheoryLean.CommonCellSum + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CommonSliceGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CommonSliceGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..fa1d81fb930381b11cb18acb4341247b6d48913b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CommonSliceGeometry.lean @@ -0,0 +1,545 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Estimates.HeightBlockCount +import OAI.NumberTheory.Jacobsthal.Estimates.HypotheticalPairRows + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosCommonParameterInterval + +noncomputable def commonLower (a R T : ℝ) : ℝ := max (a/R) (a/T) +noncomputable def commonUpper (b R T : ℝ) : ℝ := min (b/R) (b/T) + +theorem div_between_endpoints (a : ℝ) {R p T : ℝ} (hR : 0 < R) + (hRp : R ≤ p) (hpT : p ≤ T) : + min (a/R) (a/T) ≤ a/p ∧ a/p ≤ max (a/R) (a/T) := by + have hp : 0 < p := hR.trans_le hRp + have hT : 0 < T := hp.trans_le hpT + by_cases ha : 0 ≤ a + · exact ⟨(min_le_right _ _).trans (div_le_div_of_nonneg_left ha hp hpT), + (div_le_div_of_nonneg_left ha hR hRp).trans (le_max_left _ _)⟩ + · have han : 0 ≤ -a := by linarith + have h1 := div_le_div_of_nonneg_left han hp hpT + have h2 := div_le_div_of_nonneg_left han hR hRp + simp only [neg_div] at h1 h2 + exact ⟨(min_le_left _ _).trans (by linarith), + (show a/p ≤ a/T by linarith).trans (le_max_right _ _)⟩ + +theorem common_interval_subset (a b : ℝ) {R p T : ℝ} (hR : 0 < R) + (hRp : R ≤ p) (hpT : p ≤ T) : + Set.Ioc (commonLower a R T) (commonUpper b R T) ⊆ Set.Ioc (a/p) (b/p) := by + intro m hm + exact ⟨(div_between_endpoints a hR hRp hpT).2.trans_lt hm.1, + hm.2.trans (div_between_endpoints b hR hRp hpT).1⟩ + +theorem commonLower_error (a : ℝ) {R T : ℝ} (hR : 0 < R) (hRT : R ≤ T) : + commonLower a R T ≤ a/T+|a| *(1/R-1/T) := by + have hT : 0 < T := hR.trans_le hRT + have hd : 0 ≤ 1/R-1/T := sub_nonneg.mpr (one_div_le_one_div_of_le hR hRT) + have he : a/R=a/T+a*(1/R-1/T) := by ring + apply max_le + · rw [he] + exact add_le_add le_rfl (mul_le_mul_of_nonneg_right (le_abs_self a) hd) + · exact le_add_of_nonneg_right (mul_nonneg (abs_nonneg a) hd) + +theorem commonUpper_error (b : ℝ) {R T : ℝ} (hR : 0 < R) (hRT : R ≤ T) : + b/T-|b| *(1/R-1/T) ≤ commonUpper b R T := by + have hT : 0 < T := hR.trans_le hRT + have hd : 0 ≤ 1/R-1/T := sub_nonneg.mpr (one_div_le_one_div_of_le hR hRT) + have he : b/R=b/T+b*(1/R-1/T) := by ring + apply le_min + · rw [he] + have h := mul_le_mul_of_nonneg_right (neg_abs_le b) hd + nlinarith + · exact sub_le_self _ (mul_nonneg (abs_nonneg b) hd) + +theorem common_length_lower (a b : ℝ) {R T : ℝ} (hR : 0 < R) (hRT : R ≤ T) : + (b-a)/T-(|a|+|b|)*(1/R-1/T) ≤ commonUpper b R T-commonLower a R T := by + have hl := commonLower_error a hR hRT + have hu := commonUpper_error b hR hRT + have he : (b-a)/T-(|a|+|b|)*(1/R-1/T) = + (b/T-|b| *(1/R-1/T))-(a/T+|a| *(1/R-1/T)) := by ring + rw [he] + exact sub_le_sub hu hl + +theorem common_height_bound (a b m : ℝ) {R T : ℝ} (hR : 0 < R) + (hm : m ∈ Set.Ioc (commonLower a R T) (commonUpper b R T)) : + |m| ≤ max |a| |b|/R := by + apply abs_le.mpr + constructor + · have h1 : -(max |a| |b|) ≤ a := + (neg_le_neg (le_max_left _ _)).trans (neg_abs_le a) + have h2 := div_le_div_of_nonneg_right h1 hR.le + have h3 : a/R ≤ commonLower a R T := le_max_left _ _ + rw [neg_div] at h2 + exact h2.trans (h3.trans hm.1.le) + · have h1 : b ≤ max |a| |b| := (le_abs_self b).trans (le_max_right _ _) + have h2 := div_le_div_of_nonneg_right h1 hR.le + exact hm.2.trans ((min_le_left _ _).trans h2) + + + + + +theorem reciprocal_width_bound {R T epsilon : ℝ} (hR : 0 < R) (hRT : R ≤ T) + (hwidth : T ≤ (1+epsilon)*R) : 1/R-1/T ≤ epsilon/T := by + have hT : 0 < T := hR.trans_le hRT + have hdiv : T/R ≤ 1+epsilon := (div_le_iff₀ hR).mpr hwidth + have he : (1/R-1/T)*T=T/R-1 := by field_simp + apply (le_div_iff₀ hT).mpr + rw [he] + linarith + +theorem common_length_lower_relative (a b : ℝ) {R T epsilon : ℝ} + (hR : 0 < R) (hRT : R ≤ T) (hwidth : T ≤ (1+epsilon)*R) : + ((b-a)-epsilon*(|a|+|b|))/T ≤ commonUpper b R T-commonLower a R T := by + have hd := reciprocal_width_bound hR hRT hwidth + have hmul := mul_le_mul_of_nonneg_left hd (add_nonneg (abs_nonneg a) (abs_nonneg b)) + calc + _ = (b-a)/T-(|a|+|b|)*(epsilon/T) := by ring + _ ≤ (b-a)/T-(|a|+|b|)*(1/R-1/T) := sub_le_sub_left hmul _ + _ ≤ _ := common_length_lower a b hR hRT + +theorem affine_common_interval (A D Y q m : ℝ) {R p T : ℝ} + (hq : 0 < q) (hR : 0 < R) (hRp : R ≤ p) (hpT : p ≤ T) + (hm : m ∈ Set.Ioc (commonLower (-A/q) R T) (commonUpper ((D*Y-A)/q) R T)) : + 0 < A+p*q*m ∧ A+p*q*m ≤ D*Y := by + have hp : 0 < p := hR.trans_le hRp + have hc := common_interval_subset (-A/q) ((D*Y-A)/q) hR hRp hpT hm + simp only [div_div] at hc + have hl := (div_lt_iff₀ (mul_pos hq hp)).mp hc.1 + have hu := (le_div_iff₀ (mul_pos hq hp)).mp hc.2 + constructor <;> nlinarith + +end ErdosCommonParameterInterval + + + +namespace ErdosCommonMInterval +open ErdosCommonParameterInterval + +noncomputable def lower (A q R T : ℝ) : ℝ := commonLower (-A/q) R T + 1 +noncomputable def upper (A D Y q R T : ℝ) : ℝ := commonUpper ((D*Y-A)/q) R T +noncomputable def interval (A D Y q R T : ℝ) : Set ℝ := + Set.Icc (lower A q R T) (upper A D Y q R T) +noncomputable def referenceLength (Y R q : ℝ) : ℝ := Y/(R*q) +noncomputable def lengthExponent (P Y R q : ℝ) : ℝ := Real.log (referenceLength Y R q)/Real.log P + +theorem closed_subset (A D Y q R T : ℝ) : + interval A D Y q R T ⊆ + Set.Ioc (commonLower (-A/q) R T) (commonUpper ((D*Y-A)/q) R T) := by + intro m hm + exact ⟨by have := hm.1; dsimp [interval,lower] at this; linarith, hm.2⟩ + +theorem closed_affine {A D Y q R T m p : ℝ} + (hq : 0 < q) (hR : 0 < R) (hRp : R ≤ p) (hpT : p ≤ T) + (hm : m ∈ interval A D Y q R T) : + 0 < A+p*q*m ∧ A+p*q*m ≤ D*Y := + affine_common_interval A D Y q m hq hR hRp hpT (closed_subset A D Y q R T hm) + +theorem integer_decode {A m : ℤ} {D Y q p : ℕ} {R T : ℝ} + (hD : 0 < D) (hq : 0 < q) (hR : 0 < R) + (hRp : R ≤ (p : ℝ)) (hpT : (p : ℝ) ≤ T) + (hm : (m : ℝ) ∈ interval A D Y q R T) + (hdvd : (D : ℤ) ∣ A+(p : ℤ)*q*m) : + ∃ n : ℕ, 1 ≤ n ∧ n ≤ Y ∧ (D : ℤ)*n=A+(p : ℤ)*q*m := by + have hb := closed_affine (by exact_mod_cast hq) hR hRp hpT hm + obtain ⟨k,hk⟩ := hdvd + have he : (A : ℝ)+(p : ℝ)*q*m=(D : ℝ)*(k : ℝ) := by exact_mod_cast hk + have hDp : (0 : ℝ) < D := by exact_mod_cast hD + have hkpos : (0 : ℝ) < k := by nlinarith [hb.1] + have hkY : (k : ℝ) ≤ Y := by nlinarith [hb.2] + have hkint : 0 ≤ k := le_of_lt (by exact_mod_cast hkpos : (0 : ℤ) < k) + refine ⟨k.toNat, ?_, ?_, ?_⟩ + · have : (1 : ℤ) ≤ k := by exact_mod_cast (by exact_mod_cast hkpos : (0 : ℤ) < k) + exact_mod_cast (show (1 : ℤ) ≤ (k.toNat : ℤ) by simpa [Int.toNat_of_nonneg hkint] using this) + · have : k ≤ (Y : ℤ) := by exact_mod_cast hkY + exact_mod_cast (show (k.toNat : ℤ) ≤ (Y : ℤ) by simpa [Int.toNat_of_nonneg hkint] using this) + · simpa [Int.toNat_of_nonneg hkint] using hk.symm + +def decode (A m : ℤ) (D q p : ℕ) : ℕ := + ((A+(p : ℤ)*q*m)/(D : ℤ)).toNat + +theorem decode_spec {A m : ℤ} {D Y q p : ℕ} {R T : ℝ} + (hD : 0 < D) (hq : 0 < q) (hR : 0 < R) + (hRp : R ≤ (p : ℝ)) (hpT : (p : ℝ) ≤ T) + (hm : (m : ℝ) ∈ interval A D Y q R T) + (hdvd : (D : ℤ) ∣ A+(p : ℤ)*q*m) : + 1 ≤ decode A m D q p ∧ decode A m D q p ≤ Y ∧ + (D : ℤ)*decode A m D q p=A+(p : ℤ)*q*m := by + obtain ⟨n,hn1,hnY,hn⟩ := integer_decode hD hq hR hRp hpT hm hdvd + have hDn : (D : ℤ) ≠ 0 := by exact_mod_cast hD.ne' + have hid : decode A m D q p=n := by + unfold decode + rw [← hn,Int.mul_ediv_cancel_left _ hDn] + simp + simpa only [hid] using And.intro hn1 (And.intro hnY hn) + +theorem reference_rpow {P Y R q : ℝ} (hP : 1 < P) + (hY : 0 < Y) (hR : 0 < R) (hq : 0 < q) : + P ^ lengthExponent P Y R q = referenceLength Y R q := by + have hJ : 0 < referenceLength Y R q := div_pos hY (mul_pos hR hq) + rw [lengthExponent,Real.rpow_def_of_pos (by linarith : 0 < P)] + rw [mul_div_cancel₀ _ (Real.log_pos hP).ne'] + exact Real.exp_log hJ + +end ErdosCommonMInterval + + + +namespace ErdosCommonMInterval +open ErdosCommonParameterInterval + +theorem endpoint_magnitude {A D Y q : ℝ} (hD : 0 ≤ D) (hY : 0 ≤ Y) (hq : 0 < q) : + |-A/q|+|(D*Y-A)/q| ≤ (D*Y+2*|A|)/q := by + rw [abs_div,abs_div,abs_of_pos hq,abs_neg,← add_div] + apply div_le_div_of_nonneg_right _ hq.le + have h : |D*Y-A| ≤ |D*Y|+|A| := by + simpa only [sub_zero, zero_sub, abs_neg] using abs_sub_le (D*Y) 0 A + rw [abs_of_nonneg (mul_nonneg hD hY)] at h + linarith + +theorem closed_length_lower {A D Y q R T H e : ℝ} + (hD : 1 ≤ D) (hY : 0 < Y) (hq : 0 < q) (hR : 0 < R) (hRT : R ≤ T) + (hH : 0 ≤ H) (he : 0 ≤ e) (hwidth : T ≤ (1+e)*R) (hA : |A| ≤ Y*H) : + (1-2*e*(1+H))*D*referenceLength Y R q-1 ≤ + upper A D Y q R T-lower A q R T := by + have hT : 0 < T := hR.trans_le hRT + have hD0 : 0 < D := by linarith + have hd0 : 0 ≤ 1/R-1/T := sub_nonneg.mpr (one_div_le_one_div_of_le hR hRT) + have hd := (reciprocal_width_bound hR hRT hwidth).trans + (div_le_div_of_nonneg_left he hR hRT) + have hmag := endpoint_magnitude (A := A) hD0.le hY.le hq + have hbase : (D*Y-A)/q-(-A/q) = D*Y/q := by ring + have hnorm : D*Y/q+|-A/q|+|(D*Y-A)/q| ≤ 2*D*Y*(1+H)/q := by + have hDH : Y*H ≤ D*Y*H := by nlinarith [mul_nonneg hY.le hH] + have : (D*Y+2*|A|)/q ≤ (D*Y+2*D*Y*H)/q := + div_le_div_of_nonneg_right (by linarith) hq.le + calc + _ ≤ D*Y/q+(D*Y+2*D*Y*H)/q := by linarith + _ = _ := by ring + have hnorm0 : 0 ≤ D*Y/q+|-A/q|+|(D*Y-A)/q| := by positivity + have hprod := mul_le_mul hnorm hd hd0 (by positivity : 0 ≤ 2*D*Y*(1+H)/q) + have hf := common_length_lower (-A/q) ((D*Y-A)/q) hR hRT + rw [hbase] at hf + have heq : (D*Y/q)/T-(|-A/q|+|(D*Y-A)/q|)*(1/R-1/T) = + D*Y/(R*q)-(D*Y/q+|-A/q|+|(D*Y-A)/q|)*(1/R-1/T) := by ring + rw [heq] at hf + dsimp [upper,lower,referenceLength] + have heq2 : D*Y/(R*q)-(2*D*Y*(1+H)/q)*(e/R) = + (1-2*e*(1+H))*D*(Y/(R*q)) := by ring + linarith + +theorem closed_length_upper (A D Y q R T : ℝ) : + upper A D Y q R T-lower A q R T ≤ D*referenceLength Y R q-1 := by + have hU : upper A D Y q R T ≤ ((D*Y-A)/q)/R := min_le_left _ _ + have hL : (-A/q)/R+1 ≤ lower A q R T := by + have h : (-A/q)/R ≤ ErdosCommonParameterInterval.commonLower (-A/q) R T := le_max_left _ _ + dsimp [lower];linarith + have heq : ((D*Y-A)/q)/R-((-A/q)/R+1)=D*referenceLength Y R q-1 := by + dsimp [referenceLength];ring + linarith + +theorem closed_height {A D Y q R T H m : ℝ} + (hD : 0 ≤ D) (hY : 0 < Y) (hq : 0 < q) (hR : 0 < R) + (hA : |A| ≤ Y*H) (hm : m ∈ interval A D Y q R T) : + |m| ≤ (D+H)*referenceLength Y R q := by + have hb := common_height_bound (-A/q) ((D*Y-A)/q) m hR + (closed_subset A D Y q R T hm) + have ha : |-A/q| ≤ (D*Y+Y*H)/q := by + rw [abs_div,abs_neg,abs_of_pos hq] + exact div_le_div_of_nonneg_right (by nlinarith) hq.le + have hc : |(D*Y-A)/q| ≤ (D*Y+Y*H)/q := by + rw [abs_div,abs_of_pos hq] + apply div_le_div_of_nonneg_right _ hq.le + have h : |D*Y-A| ≤ |D*Y|+|A| := by + simpa only [sub_zero, zero_sub, abs_neg] using abs_sub_le (D*Y) 0 A + rw [abs_of_nonneg (mul_nonneg hD hY.le)] at h + linarith + calc + _ ≤ max |-A/q| |(D*Y-A)/q|/R := hb + _ ≤ ((D*Y+Y*H)/q)/R := div_le_div_of_nonneg_right (max_le ha hc) hR.le + _ = _ := by dsimp [referenceLength];ring + +end ErdosCommonMInterval + + +section + +open _root_.Filter +open scoped Topology +namespace ErdosCommonMInterval + +theorem eventual_polynomial_cutoff (B K : ℝ) (hB : 0 ≤ B) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop, 2 ≤ w ∧ w^B ≤ Real.exp (K*(Real.log w)^3) := by + filter_upwards [eventually_ge_atTop (2 : ℝ), + Real.tendsto_log_atTop.eventually_ge_atTop (max 1 (B/K))] with w hw hL + have hw0 : 0 < w := by linarith + have hL1 : 1 ≤ Real.log w := (le_max_left _ _).trans hL + have hBL : B ≤ K*Real.log w := by + have := (div_le_iff₀ hK).mp (show B/K ≤ Real.log w from (le_max_right _ _).trans hL) + nlinarith + refine ⟨hw, ?_⟩ + rw [Real.rpow_def_of_pos hw0] + apply Real.exp_le_exp.mpr + have hsq : Real.log w ≤ (Real.log w)^2 := by nlinarith + have hpow : (Real.log w)^2 ≤ (Real.log w)^3 := by nlinarith + nlinarith [mul_le_mul_of_nonneg_right hBL (by linarith : 0 ≤ Real.log w)] + +theorem subbin_loss {w C : ℝ} (hw : 1 ≤ w) (hC : 0 ≤ C) : + 2*w^(-2*C-10)*(1+w^(C+2)) ≤ 4*w^(-8 : ℝ) := by + have hw0 : 0 < w := by linarith + have hH : 1 ≤ w^(C+2) := Real.one_le_rpow hw (by linarith) + have hmul : w^(-2*C-10)*w^(C+2) = w^(-C-8) := by + rw [← Real.rpow_add hw0];congr 1;ring + have hcmp : w^(-C-8) ≤ w^(-8 : ℝ) := Real.rpow_le_rpow_of_exponent_le hw (by linarith) + have hnon : 0 ≤ w^(-2*C-10) := Real.rpow_nonneg hw0.le _ + have hle : w^(-2*C-10) ≤ w^(-2*C-10)*w^(C+2) := by nlinarith + nlinarith + +theorem height_absorption {w P C : ℝ} (hw : 2 ≤ w) + (hP : w^(50*(C+3)) ≤ P) : 2*w^(C+2) ≤ P^((2 : ℝ)/100) := by + have hw0 : 0 < w := by linarith + have h1 : 2*w^(C+2) ≤ w^(C+3) := by + have he : w^(C+3)=w*w^(C+2) := by + calc w^(C+3) = w^((1 : ℝ)+(C+2)) := by congr 1;ring + _ = w*w^(C+2) := by rw [Real.rpow_add hw0,Real.rpow_one] + rw [he] + exact mul_le_mul_of_nonneg_right hw (Real.rpow_nonneg hw0.le _) + have h2 := Real.rpow_le_rpow (Real.rpow_nonneg hw0.le (50*(C+3))) hP + (by norm_num : (0 : ℝ) ≤ 2/100) + have he : (w^(50*(C+3)))^((2 : ℝ)/100)=w^(C+3) := by + rw [← Real.rpow_mul hw0.le];congr 1;ring + exact h1.trans (by rwa [he] at h2) + +noncomputable def relativeError (w : ℝ) : ℝ := 4*w^(-8 : ℝ)+w^(-2 : ℝ) + +theorem relativeError_tends_zero : Tendsto relativeError atTop (𝓝 0) := by + have h8 := tendsto_rpow_neg_atTop (by norm_num : (0 : ℝ) < 8) + have h2 := tendsto_rpow_neg_atTop (by norm_num : (0 : ℝ) < 2) + change Tendsto (fun w : ℝ => 4*w^(-8 : ℝ)+w^(-2 : ℝ)) atTop (𝓝 0) + simpa only [mul_zero,add_zero] using (h8.const_mul 4).add h2 + +theorem uniform_common_interval (C K delta : ℝ) (hC : 0 ≤ C) (hK : 0 < K) + (hd0 : 0 < delta) (hd1 : delta < 1) : + ∃ W : ℝ, ∀ w : ℝ, W ≤ w → ∀ P A D Y q R T : ℝ, + Real.exp (K*(Real.log w)^3) ≤ P → + 1 ≤ D → D ≤ w^C → 0 < Y → 0 < q → 0 < R → R ≤ T → + T ≤ (1+w^(-2*C-10))*R → |A| ≤ Y*w^(C+2) → + 2 ≤ lengthExponent P Y R q → + (1-delta)*D*referenceLength Y R q ≤ upper A D Y q R T-lower A q R T ∧ + upper A D Y q R T-lower A q R T ≤ D*referenceLength Y R q ∧ + (interval A D Y q R T).Nonempty ∧ + ∀ m ∈ interval A D Y q R T, |m| ≤ P^(lengthExponent P Y R q+(2 : ℝ)/100) := by + have hE := relativeError_tends_zero.eventually (gt_mem_nhds hd0) + have hpoly := eventual_polynomial_cutoff (50*(C+3)) K (by positivity) hK + obtain ⟨W,hW⟩ := eventually_atTop.mp (hE.and hpoly) + refine ⟨W, ?_⟩ + intro w hw P A D Y q R T hP hD hDu hY hq hR hRT hwidth hA hs + obtain ⟨hErr,hw2,hpow⟩ := hW w hw + have hw0 : 0 < w := by linarith + have hw1 : 1 ≤ w := by linarith + have hwpow : w ≤ w^(50*(C+3)) := by + calc w = w^(1 : ℝ) := (Real.rpow_one _).symm + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le hw1 (by nlinarith) + have hwP : w ≤ P := hwpow.trans (hpow.trans hP) + have hP1 : 1 < P := by linarith + have hD0 : 0 < D := by linarith + have hJ : 0 < referenceLength Y R q := div_pos hY (mul_pos hR hq) + have hJid := reference_rpow hP1 hY hR hq + have hJlow : P^2 ≤ referenceLength Y R q := by + rw [← hJid] + simpa only [Real.rpow_ofNat] using Real.rpow_le_rpow_of_exponent_le hP1.le hs + have hJw : w^2 ≤ referenceLength Y R q := by nlinarith + have hpay : 1 ≤ w^(-2 : ℝ)*D*referenceLength Y R q := by + have hid : w^(-2 : ℝ)*w^2=1 := by + rw [← Real.rpow_ofNat,← Real.rpow_add hw0];norm_num + have hn : 0 ≤ w^(-2 : ℝ) := Real.rpow_nonneg hw0.le _ + have hm : w^2 ≤ D*referenceLength Y R q := by nlinarith + have := mul_le_mul_of_nonneg_left hm hn + nlinarith + have hraw := closed_length_lower hD hY hq hR hRT + (Real.rpow_nonneg hw0.le (C+2)) (Real.rpow_nonneg hw0.le (-2*C-10)) hwidth hA + have hcost := subbin_loss hw1 hC + have hlen : (1-delta)*D*referenceLength Y R q ≤ + upper A D Y q R T-lower A q R T := by + have hmul := mul_le_mul_of_nonneg_right hcost (mul_pos hD0 hJ).le + have herrmul := mul_le_mul_of_nonneg_right hErr.le (mul_pos hD0 hJ).le + dsimp [relativeError] at herrmul + nlinarith + refine ⟨hlen, (closed_length_upper A D Y q R T).trans (by linarith), ?_, ?_⟩ + · apply Set.nonempty_Icc.mpr + have := mul_pos (mul_pos (by linarith : 0 < 1-delta) hD0) hJ + linarith + · intro m hm + have hheight := closed_height hD0.le hY hq hR hA hm + have hDC : D ≤ w^(C+2) := hDu.trans + (Real.rpow_le_rpow_of_exponent_le hw1 (by linarith)) + have habs := height_absorption hw2 (hpow.trans hP) + have hp02 : D+w^(C+2) ≤ P^((2 : ℝ)/100) := by linarith + calc + |m| ≤ (D+w^(C+2))*referenceLength Y R q := hheight + _ ≤ P^((2 : ℝ)/100)*referenceLength Y R q := mul_le_mul_of_nonneg_right hp02 hJ.le + _ = P^(lengthExponent P Y R q+(2 : ℝ)/100) := by + rw [← hJid,← Real.rpow_add (by linarith : 0 < P)];congr 1;ring + +theorem uniform_integer_common_interval (C K delta : ℝ) (hC : 0 ≤ C) (hK : 0 < K) + (hd0 : 0 < delta) (hd1 : delta < 1) : + ∃ W : ℝ, ∀ w : ℝ, W ≤ w → ∀ P R T : ℝ, ∀ A : ℤ, ∀ D Y q : ℕ, + Real.exp (K*(Real.log w)^3) ≤ P → + 0 < D → (D : ℝ) ≤ w^C → 0 < Y → 0 < q → 0 < R → R ≤ T → + T ≤ (1+w^(-2*C-10))*R → |(A : ℝ)| ≤ (Y : ℝ)*w^(C+2) → + 2 ≤ lengthExponent P Y R q → + (1-delta)*(D : ℝ)*referenceLength Y R q ≤ upper A D Y q R T-lower A q R T ∧ + upper A D Y q R T-lower A q R T ≤ (D : ℝ)*referenceLength Y R q ∧ + (interval A D Y q R T).Nonempty ∧ + (∀ m ∈ interval A D Y q R T, |m| ≤ P^(lengthExponent P Y R q+(2 : ℝ)/100)) ∧ + ∀ p : ℕ, ∀ m : ℤ, R ≤ (p : ℝ) → (p : ℝ) ≤ T → + (m : ℝ) ∈ interval A D Y q R T → (D : ℤ) ∣ A+(p : ℤ)*q*m → + 1 ≤ decode A m D q p ∧ decode A m D q p ≤ Y ∧ + (D : ℤ)*decode A m D q p=A+(p : ℤ)*q*m := by + obtain ⟨W,hW⟩ := uniform_common_interval C K delta hC hK hd0 hd1 + refine ⟨W, ?_⟩ + intro w hw P R T A D Y q hP hD hDu hY hq hR hRT hwidth hA hs + have hb := hW w hw P A D Y q R T hP + (by exact_mod_cast (show 1 ≤ D from hD)) hDu + (by exact_mod_cast hY) (by exact_mod_cast hq) hR hRT hwidth hA hs + refine ⟨hb.1,hb.2.1,hb.2.2.1,hb.2.2.2,?_⟩ + intro p m hRp hpT hm hdvd + exact decode_spec hD hq hR hRp hpT hm hdvd + +end ErdosCommonMInterval + +end + + +namespace ErdosLargeHeightBlocks + +noncomputable def blockLeft (C0 : ℤ) (R xi : ℝ) (H i : ℕ) : ℝ := + ErdosTagSubbins.left R xi (blockCount C0 R xi H) i +noncomputable def blockRight (C0 : ℤ) (R xi : ℝ) (H i : ℕ) : ℝ := + ErdosTagSubbins.right R xi (blockCount C0 R xi H) i + +theorem block_reciprocal_variation (C0 : ℤ) (R xi : ℝ) (H i : ℕ) + (hR : 0 < R) (hxi : 0 < xi) (hH : 0 < H) : + |(C0 : ℝ)/blockLeft C0 R xi H i-(C0 : ℝ)/blockRight C0 R xi H i| ≤ (H : ℝ) := by + let N := blockCount C0 R xi H + let a := blockLeft C0 R xi H i + let b := blockRight C0 R xi H i + have hN : 0 < N := blockCount_pos C0 R xi H + have hNr : (0 : ℝ) < N := by exact_mod_cast hN + have hHr : (0 : ℝ) < H := by exact_mod_cast hH + have hs := ErdosTagSubbins.step_pos hR hxi hN + have ha : R ≤ a := ErdosTagSubbins.left_lower hs.le + have hab : a < b := ErdosTagSubbins.left_lt_right hR hxi hN + have hb : R ≤ b := ha.trans hab.le + have ha0 : 0 < a := hR.trans_le ha + have hb0 : 0 < b := hR.trans_le hb + have hd : b-a = ErdosTagSubbins.step R xi N := ErdosTagSubbins.right_sub_left R xi N i + have hden : R^2 ≤ a*b := by + simpa only [pow_two] using mul_le_mul ha hb hR.le ha0.le + have he : (C0 : ℝ)/a-(C0 : ℝ)/b=(C0 : ℝ)*(b-a)/(a*b) := by + field_simp + have hcount := (div_le_iff₀ (mul_pos hR hHr)).mp (blockCount_lower C0 R xi H) + change |(C0 : ℝ)/a-(C0 : ℝ)/b| ≤ (H : ℝ) + rw [he,abs_div,abs_mul,abs_of_nonneg (sub_nonneg.mpr hab.le),abs_of_pos (mul_pos ha0 hb0)] + calc + _ ≤ |(C0 : ℝ)| * (b-a)/R^2 := + div_le_div_of_nonneg_left (mul_nonneg (abs_nonneg _) (sub_nonneg.mpr hab.le)) (sq_pos_of_pos hR) hden + _ = xi*|(C0 : ℝ)|/(R*(N : ℝ)) := by + rw [hd] + dsimp [ErdosTagSubbins.step] + field_simp + _ ≤ _ := by + apply (div_le_iff₀ (mul_pos hR hNr)).mpr + change xi*|(C0 : ℝ)| ≤ (N : ℝ)*(R*(H : ℝ)) at hcount + nlinarith + +noncomputable def coordinateLower (C0 : ℤ) (R xi : ℝ) (H i : ℕ) : ℝ := + min ((C0 : ℝ)/blockLeft C0 R xi H i) ((C0 : ℝ)/blockRight C0 R xi H i) +noncomputable def coordinateUpper (C0 : ℤ) (R xi : ℝ) (H i : ℕ) : ℝ := + max ((C0 : ℝ)/blockLeft C0 R xi H i) ((C0 : ℝ)/blockRight C0 R xi H i)+(H : ℝ) + +theorem block_coordinate_containment (C0 : ℤ) (R xi : ℝ) (H i : ℕ) + (hR : 0 < R) (hxi : 0 < xi) (p m : ℝ) + (hpL : blockLeft C0 R xi H i ≤ p) (hpU : p ≤ blockRight C0 R xi H i) + (hmL : (C0 : ℝ)/p ≤ m) (hmU : m < (C0 : ℝ)/p+(H : ℝ)) : + m ∈ Set.Ico (coordinateLower C0 R xi H i) (coordinateUpper C0 R xi H i) := by + have hL : 0 < blockLeft C0 R xi H i := + ErdosTagSubbins.left_pos hR hxi (blockCount_pos C0 R xi H) + have hb := ErdosCommonParameterInterval.div_between_endpoints (C0 : ℝ) hL hpL hpU + refine ⟨hb.1.trans hmL,?_⟩ + dsimp only [coordinateUpper] + linarith [hb.2] + +theorem block_coordinate_width (C0 : ℤ) (R xi : ℝ) (H i : ℕ) + (hR : 0 < R) (hxi : 0 < xi) (hH : 0 < H) : + coordinateUpper C0 R xi H i-coordinateLower C0 R xi H i ≤ 2*(H : ℝ) := by + have hv := block_reciprocal_variation C0 R xi H i hR hxi hH + have he (x y : ℝ) : max x y-min x y=|x-y| := by + rw [max_sub_min_eq_abs,abs_sub_comm] + dsimp [coordinateUpper,coordinateLower] + rw [show max ((C0 : ℝ)/blockLeft C0 R xi H i) ((C0 : ℝ)/blockRight C0 R xi H i)+(H : ℝ)- + min ((C0 : ℝ)/blockLeft C0 R xi H i) ((C0 : ℝ)/blockRight C0 R xi H i) = + (max ((C0 : ℝ)/blockLeft C0 R xi H i) ((C0 : ℝ)/blockRight C0 R xi H i)- + min ((C0 : ℝ)/blockLeft C0 R xi H i) ((C0 : ℝ)/blockRight C0 R xi H i))+(H : ℝ) by ring, + he] + linarith + +end ErdosLargeHeightBlocks + + + +namespace ErdosStoppedArithmetic +open ErdosCommonMInterval ErdosAlignedProgression + +theorem common_slice_mem_parameter (Y q p : ℕ) (r : ℚ) (R T : ℝ) (m : ℤ) + (hq : 0 < q) (hR : 0 < R) (hRp : R ≤ (p : ℝ)) (hpT : (p : ℝ) ≤ T) + (hm : (m : ℝ) ∈ interval r.num r.den Y q R T) + (hdiv : (r.den : ℤ) ∣ r.num+((p*q : ℕ) : ℤ)*m) : + m ∈ parameterInterval Y r (p*q) := by + have hp : 0 < p := by exact_mod_cast hR.trans_le hRp + have hdiv' : (r.den : ℤ) ∣ r.num+(p : ℤ)*q*m := by + simpa only [Nat.cast_mul] using hdiv + obtain ⟨n,hn,hY,he⟩ := integer_decode r.den_pos hq hR hRp hpT hm hdiv' + apply (mem_parameterInterval Y r (p*q) (Nat.mul_pos hp hq) m).mpr + have hD : (0 : ℤ) ≤ r.den := Int.natCast_nonneg _ + have hn' : (1 : ℤ) ≤ n := by exact_mod_cast hn + have hY' : (n : ℤ) ≤ Y := by exact_mod_cast hY + have hlo := mul_le_mul_of_nonneg_left hn' hD + have hhi := mul_le_mul_of_nonneg_left hY' hD + simp only [mul_one,he] at hlo hhi + simpa only [Nat.cast_mul] using And.intro hlo hhi + +theorem common_slice_endpoint_height (w Cs P R T : ℝ) (A : ℤ) (D Y q : ℕ) + (hw : 1 ≤ w) (hP : 1 < P) (hDw : (D : ℝ) ≤ w^Cs) + (hY : 0 < Y) (hq : 0 < q) (hR : 0 < R) + (hA : |(A : ℝ)| ≤ (Y : ℝ)*w^(Cs+2)) + (hne : (interval A D Y q R T).Nonempty) : + max |lower A q R T| |upper A D Y q R T| ≤ + 2*w^(Cs+2)*P^(lengthExponent P Y R q) := by + have hY' : (0 : ℝ) < Y := by exact_mod_cast hY + have hq' : (0 : ℝ) < q := by exact_mod_cast hq + have hD' : (0 : ℝ) ≤ D := Nat.cast_nonneg _ + have hEnds : lower A q R T ≤ upper A D Y q R T := Set.nonempty_Icc.mp hne + have hLo := closed_height hD' hY' hq' hR hA + (show lower A q R T ∈ interval A D Y q R T from ⟨le_rfl,hEnds⟩) + have hHi := closed_height hD' hY' hq' hR hA + (show upper A D Y q R T ∈ interval A D Y q R T from ⟨hEnds,le_rfl⟩) + have hDC : (D : ℝ) ≤ w^(Cs+2) := hDw.trans + (Real.rpow_le_rpow_of_exponent_le hw (by linarith)) + have hJ : 0 ≤ referenceLength Y R q := (div_pos hY' (mul_pos hR hq')).le + have hBound := mul_le_mul_of_nonneg_right + (show (D : ℝ)+w^(Cs+2) ≤ 2*w^(Cs+2) by linarith) hJ + rw [reference_rpow hP hY' hR hq'] + exact (max_le hLo hHi).trans (by simpa only [mul_assoc] using hBound) + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompactSelectedPartition.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompactSelectedPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..59e5712f6f25f8518330add0936723678634fefa --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompactSelectedPartition.lean @@ -0,0 +1,116 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UncappedHighRemoval +import OAI.NumberTheory.Jacobsthal.Probability.RetainedCompactEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PrimeFamilyOccupation +attribute [local instance] Classical.propDecidable +open FinitePathGeometry PrimeHistories PrimeTiltGeometry +open ActualPrimeHigh + +theorem retained_no_high {w ell S : ℝ} {start : Node} {ps : List ℕ} + (hsS : start.ratio ≤ S) (hp : allowed w ell S start ps) : + ¬actualHasHigh w S start ps := by + rintro ⟨pre,suf,he,hh⟩ + have hpre := (allowed_append w ell S start pre suf).mp (he ▸ hp) |>.1 + exact (not_lt_of_ge (terminal_ratio_le hsS hpre)) hh + +theorem allowed_of_uncapped_prefix_ceiling {w ell S : ℝ} {start : Node} {ps : List ℕ} + (hp : uncappedAllowed w ell start ps) + (hbound : ∀ pre suf : List ℕ, ps = pre++suf → (terminal w start pre).ratio ≤ S) : + allowed w ell S start ps := by + classical + induction ps generalizing start with + | nil => exact allowed_nil w ell S start + | cons p ps ih => + obtain ⟨hc,ht⟩ := hp + have hpS : (step w start p).ratio ≤ S := by + simpa only [terminal_cons,terminal_nil] using hbound [p] ps rfl + have hb : ∀ pre suf : List ℕ, ps = pre++suf → + (terminal w (step w start p) pre).ratio ≤ S := by + intro pre suf he + exact hbound (p::pre) suf (by rw [List.cons_append,he]) + obtain ⟨hprime,hlo,hcap,hmin⟩ := Finset.mem_filter.mp hc + apply (allowed_cons w ell S start p ps).mpr + exact ⟨Finset.mem_filter.mpr ⟨hprime,hlo,hcap,hmin,hpS⟩,ih ht hb⟩ + +theorem allowed_iff_uncapped_no_high {w ell S : ℝ} {start : Node} (hsS : start.ratio ≤ S) + (ps : List ℕ) : allowed w ell S start ps ↔ + uncappedAllowed w ell start ps ∧ ¬actualHasHigh w S start ps := by + constructor + · intro hp + exact ⟨(uncapped_iff_exists_ceiling w ell start ps).mpr ⟨S,hsS,hp⟩,retained_no_high hsS hp⟩ + · rintro ⟨hp,hh⟩ + apply allowed_of_uncapped_prefix_ceiling hp + intro pre suf he + exact le_of_not_gt (fun h => hh ⟨pre,suf,he,h⟩) + +theorem retained_eq_nonhigh {w ell S : ℝ} (hw : 1 < w) {start : Node} (hsS : start.ratio ≤ S) : + retainedPrefixes w ell S start = + (uncappedPrefixes w ell start).filter (fun ps => ¬actualHasHigh w S start ps) := by + classical + ext ps + rw [mem_retainedPrefixes hw,Finset.mem_filter,mem_uncappedPrefixes hw] + exact allowed_iff_uncapped_no_high hsS ps + +theorem uncapped_sum_partition {w ell S : ℝ} (hw : 1 < w) {start : Node} + (hsS : start.ratio ≤ S) (F : List ℕ → ℝ) : + (∑ ps ∈ uncappedPrefixes w ell start,F ps) = + (∑ ps ∈ retainedPrefixes w ell S start,F ps) + + ∑ ps ∈ (uncappedPrefixes w ell start).filter (actualHasHigh w S start),F ps := by + classical + rw [retained_eq_nonhigh hw hsS] + exact (Finset.sum_filter_not_add_sum_filter _ _ _).symm + +end NumberTheoryLean.PrimeFamilyOccupation + +end + +section + +namespace NumberTheoryLean.CompactSelectedPartition + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeHistories PrimeFamilyOccupation ActualPrimeHigh +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +attribute [local instance] Classical.propDecidable + +theorem selected_uncapped_partition {w ell S : ℝ} (hw : 1 < w) {start : Node} + (hsS : start.ratio ≤ S) (E : Set (List ℕ)) : + (∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) = + (∑ ps ∈ (retainedPrefixes w ell S start).filter (· ∈ E),prefixWeight ps) + + ∑ ps ∈ ((uncappedPrefixes w ell start).filter (actualHasHigh w S start)).filter (· ∈ E), + prefixWeight ps := by + have h := uncapped_sum_partition (ell:=ell) hw hsS (fun ps => if ps ∈ E then prefixWeight ps else 0) + simpa only [Finset.sum_filter] using h + +theorem selected_uncapped_le {w ell S R : ℝ} (hw : 1 < w) {start : Node} + (hsS : start.ratio ≤ S) (E : Set (List ℕ)) + (hcompact : ∀ ps ∈ uncappedPrefixes w ell start,ps ∈ E → (terminal w start ps).gap ≤ R) : + (∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ + (∑ ps ∈ (retainedPrefixes w ell S start).filter (· ∈ E),prefixWeight ps) + + uncappedLowGapHighMass w ell start S R := by + rw [selected_uncapped_partition hw hsS E] + apply add_le_add le_rfl + unfold uncappedLowGapHighMass + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro ps hp + obtain ⟨hhigh,hE⟩ := Finset.mem_filter.mp hp + obtain ⟨hps,hh⟩ := Finset.mem_filter.mp hhigh + exact Finset.mem_filter.mpr ⟨hps,hcompact ps hps hE,hh⟩ + · intro ps _ _ + exact prefixWeight_nonneg ps + +end NumberTheoryLean.CompactSelectedPartition + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompactTestGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompactTestGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..337d39f3a4b0923bca474cb438f1cdefd5571b96 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompactTestGeometry.lean @@ -0,0 +1,99 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SuccessfulRewardComparison + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.CompactTestGeometry + +open _root_.Set _root_.MeasureTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualFlagInvariant RegeneratingInverseBands + +variable {w ell S : ℝ} {start : Node} + +noncomputable def primeTest (F : Side → ℝ×ℝ → ℝ) : ChainState w ell S start → ℝ + | none => 0 + | some h => F h.node.side (h.node.gap,h.node.ratio) + +noncomputable def continuousTest (v : ℝ) (F : Side → ℝ×ℝ → ℝ) : CemeteryKernel.Space CostState → ℝ + | .inr _ => 0 + | .inl z => F (stateSide z.1) (gapValue v z,stateRatio z.1) + +theorem phase_uniform_modulus (F : Side → ℝ×ℝ → ℝ) (hF : ∀ i,UniformContinuous (F i)) + {η : ℝ} (hη : 0 < η) : ∃ δ : ℝ,0 < δ ∧ ∀ i : Side,∀ x y : ℝ×ℝ, + |x.1-y.1| ≤ δ → |x.2-y.2| ≤ δ → |F i x-F i y| ≤ η := by + obtain ⟨de,hde,he⟩ := Metric.uniformContinuous_iff_le.mp (hF .even) η hη + obtain ⟨do_,hdo,ho⟩ := Metric.uniformContinuous_iff_le.mp (hF .odd) η hη + refine ⟨min de do_,lt_min hde hdo,?_⟩ + intro i x y hx hy + have hdist : dist x y ≤ min de do_ := by rw [Prod.dist_eq,Real.dist_eq,Real.dist_eq]; exact max_le hx hy + cases i with + | even => simpa only [Real.dist_eq] using he (hdist.trans (min_le_left _ _)) + | odd => simpa only [Real.dist_eq] using ho (hdist.trans (min_le_right _ _)) + +theorem compact_gap_close {K r q d : ℝ} (_hK : 0 ≤ K) (hr : 0 < r) (hq : 0 < q) + (hd : |Real.log r-Real.log q| ≤ d) (hd1 : d ≤ 1) (hcompact : r ≤ K ∨ q ≤ K) : + r ≤ 3*K ∧ q ≤ 3*K ∧ |r-q| ≤ 3*K*(Real.exp d-1) := by + have hrel := NearbyParentGeometry.log_gap_relative hr hq hd + have he3 : Real.exp d ≤ 3 := (Real.exp_le_exp.mpr hd1).trans Real.exp_one_lt_three.le + have hd0 : 0 ≤ d := (abs_nonneg _).trans hd + have he0 : 0 ≤ Real.exp d-1 := sub_nonneg.mpr (Real.one_le_exp_iff.mpr hd0) + have hrq : r ≤ 3*q := hrel.1.trans (mul_le_mul_of_nonneg_right he3 hq.le) + have hqr : q ≤ 3*r := hrel.2.trans (mul_le_mul_of_nonneg_right he3 hr.le) + have hboth : r ≤ 3*K ∧ q ≤ 3*K := by rcases hcompact with h | h <;> constructor <;> linarith + refine ⟨hboth.1,hboth.2,abs_le.mpr ⟨?_,?_⟩⟩ + · have hh := mul_le_mul_of_nonneg_right hboth.1 he0 + nlinarith + · have hh := mul_le_mul_of_nonneg_right hboth.2 he0 + nlinarith + +theorem actual_compact_test_comparison (F : Side → ℝ×ℝ → ℝ) + (hF : ∀ i,UniformContinuous (F i)) {K η : ℝ} (hK : 0 ≤ K) (hη : 0 < η) + (hsupport : ∀ i : Side,∀ r s : ℝ,K < r → F i (r,s) = 0) : + ∃ δ : ℝ,0 < δ ∧ ∀ w ell S : ℝ,∀ start : Node, + 0 ≤ ell → 0 < start.gap → Valid start.side start.ratio → + ∀ v mesh : ℝ,∀ n : ℕ,mesh ≤ δ → 4*(n:ℝ)*mesh ≤ 1 → + 3*K*(Real.exp (4*(n:ℝ)*mesh)-1) ≤ δ → + ∀ q : JointState w ell S start,GoodAt v mesh n q → + |primeTest F q.1-continuousTest v F q.2| ≤ η*PrimeCompactVisits.visit (3*K) q.1 := by + obtain ⟨δ,hδ,hmod⟩ := phase_uniform_modulus F hF hη + refine ⟨δ,hδ,?_⟩ + intro w ell S start hell hr hs v mesh n hm hd hgap q hgood + rcases q with ⟨p,y⟩ + cases p with + | none => + cases y with + | inr u => simp [primeTest,continuousTest,PrimeCompactVisits.visit] + | inl z => exact False.elim hgood + | some h => + cases y with + | inr u => exact False.elim hgood + | inl z => + have hh : liveGood v mesh n h z := hgood + have hr' : 0 < h.node.gap := terminal_gap_positive hell hr hs h.admissible + have hq' : 0 < gapValue v z := Real.exp_pos _ + by_cases hz : F h.node.side (h.node.gap,h.node.ratio) = 0 ∧ + F (stateSide z.1) (gapValue v z,stateRatio z.1) = 0 + · simp only [primeTest,continuousTest,hz.1,hz.2,sub_zero,abs_zero] + exact mul_nonneg hη.le (PrimeCompactVisits.visit_nonneg _ _) + · have hcomp : h.node.gap ≤ K ∨ gapValue v z ≤ K := by + by_contra hn + push Not at hn + exact hz ⟨hsupport _ _ _ hn.1,hsupport _ _ _ hn.2⟩ + have hclose := compact_gap_close hK hr' hq' hh.2.2.2 hd hcomp + have hvalue := hmod h.node.side (h.node.gap,h.node.ratio) (gapValue v z,stateRatio z.1) + (hclose.2.2.trans hgap) (hh.2.2.1.trans hm) + simp only [primeTest,continuousTest,PrimeCompactVisits.visit,ite_eq_left hclose.1,mul_one] + simpa only [hh.2.1] using hvalue + +end NumberTheoryLean.CompactTestGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompletedParentInterval.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompletedParentInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..7efa005b59680bbc58733b65b7e2df0ed847b6f8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CompletedParentInterval.lean @@ -0,0 +1,313 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeGridGeometry +import OAI.NumberTheory.Jacobsthal.Probability.CemeteryHistoryLaw + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ContinuousRatioBins + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry TransitionKernels PrimeTiltBounds PrimeTiltMonotone +open PrimeRatioMeasure HarmonicExponentMeasure + +noncomputable def weightedRatioLaw (i : Side) (s : ℝ) : Measure ℝ := + (ratioMeasure (minRatio i s)).withDensity (fun t => ENNReal.ofReal (multiplier i s t)) + +theorem weightedRatioLaw_eq_density {i : Side} {s : ℝ} (hs : Valid i s) : + weightedRatioLaw i s = volume.withDensity (fun t => ENNReal.ofReal (transitionDensity i s t)) := by + unfold weightedRatioLaw ratioMeasure + rw [← withDensity_mul _ (f := fun t : ℝ => ENNReal.ofReal (1/(t+1))) + (g := fun t : ℝ => ENNReal.ofReal (multiplier i s t)) + (by fun_prop : Measurable (fun t : ℝ => ENNReal.ofReal (1/(t+1)))) + (ENNReal.measurable_ofReal.comp (multiplier_measurable i s)), ← withDensity_indicator measurableSet_Ici] + apply congrArg (fun f : ℝ → ℝ≥0∞ => volume.withDensity f) + funext t + exact weighted_ratio_density_eq hs t + +theorem weightedRatioLaw_probability {i : Side} {s : ℝ} (hs : Valid i s) : + IsProbabilityMeasure (weightedRatioLaw i s) := by + constructor + rw [weightedRatioLaw, withDensity_apply _ MeasurableSet.univ, setLIntegral_univ, multiplier_ratio_integral hs] + +theorem weightedRatioLaw_even (s : EvenState) : weightedRatioLaw .even s.1 = evenKernel s := by + apply Measure.ext + intro B hB + rw [weightedRatioLaw_eq_density (i := .even) (s := s.1) s.2, withDensity_apply _ hB, evenKernel_apply] + rfl + +theorem weightedRatioLaw_odd (s : OddState) : weightedRatioLaw .odd s.1 = oddKernel s := by + apply Measure.ext + intro B hB + rw [weightedRatioLaw_eq_density (i := .odd) (s := s.1) s.2, withDensity_apply _ hB, oddKernel_apply] + rfl + +instance ratioMeasure_noAtoms (a : ℝ) : NullSingletonClass (ratioMeasure a) := by + unfold ratioMeasure + infer_instance + +theorem ratio_restrict_bin {m a b : ℝ} (hma : m ≤ a) : + (ratioMeasure m).restrict (Ico a b) = (ratioMeasure a).restrict (Ico a b) := by + simp only [ratioMeasure, restrict_withDensity measurableSet_Ico, Measure.restrict_restrict measurableSet_Ico] + rw [Set.inter_eq_left.mpr (show Ico a b ⊆ Ici m from fun _ ht => hma.trans ht.1), + Set.inter_eq_left.mpr Ico_subset_Ici_self] + +theorem ratio_bin_mass {m a b : ℝ} (ha : 0 < a) (hma : m ≤ a) (hab : a ≤ b) : + ratioMeasure m (Ico a b) = ENNReal.ofReal (Real.log (b+1)-Real.log (a+1)) := by + have h := congrArg (fun μ : Measure ℝ => μ univ) (ratio_restrict_bin (b := b) hma) + simp only [Measure.restrict_apply_univ] at h + rw [h] + have h' := congrArg (fun μ : Measure ℝ => μ univ) + (restrict_Ico_eq_restrict_Icc (μ := ratioMeasure a) (a := a) (b := b)) + simp only [Measure.restrict_apply_univ] at h' + rw [h', ratioMeasure_Icc ha hab] + +noncomputable def continuousBin (i : Side) (s a b : ℝ) : ℝ := + (weightedRatioLaw i s (Ico a b)).toReal + +theorem continuousBin_sandwich {i : Side} {s a b : ℝ} (hs : Valid i s) + (hma : minRatio i s ≤ a) (hab : a ≤ b) : + multiplier i s b * (Real.log (b+1)-Real.log (a+1)) ≤ continuousBin i s a b ∧ + continuousBin i s a b ≤ multiplier i s a * (Real.log (b+1)-Real.log (a+1)) := by + let := weightedRatioLaw_probability hs + have ha := (minRatio_pos hs).trans_le hma + have hb := ha.trans_le hab + have hma0 := (multiplier_pos hs (valid_next hs hma)).le + have hmb0 := (multiplier_pos hs (valid_next hs (hma.trans hab))).le + have hH : 0 ≤ Real.log (b+1)-Real.log (a+1) := + sub_nonneg.mpr (Real.log_le_log (by linarith) (by linarith)) + have hfinite : weightedRatioLaw i s (Ico a b) ≠ ∞ := measure_ne_top _ _ + have hu : weightedRatioLaw i s (Ico a b) ≤ + ENNReal.ofReal (multiplier i s a * (Real.log (b+1)-Real.log (a+1))) := by + rw [weightedRatioLaw, withDensity_apply _ measurableSet_Ico] + calc + _ ≤ ∫⁻ _t in Ico a b, ENNReal.ofReal (multiplier i s a) ∂ratioMeasure (minRatio i s) := by + apply lintegral_mono_ae + apply ae_restrict_of_forall_mem measurableSet_Ico + intro t ht + exact ENNReal.ofReal_le_ofReal (multiplier_antitone hs (Set.mem_Ici.mpr hma) + (Set.mem_Ici.mpr (hma.trans ht.1)) ht.1) + _ = _ := by + rw [lintegral_const, Measure.restrict_apply_univ, ratio_bin_mass ha hma hab, + ← ENNReal.ofReal_mul hma0] + have hl : ENNReal.ofReal (multiplier i s b * (Real.log (b+1)-Real.log (a+1))) ≤ + weightedRatioLaw i s (Ico a b) := by + rw [weightedRatioLaw, withDensity_apply _ measurableSet_Ico] + calc + _ = ∫⁻ _t in Ico a b, ENNReal.ofReal (multiplier i s b) ∂ratioMeasure (minRatio i s) := by + rw [lintegral_const, Measure.restrict_apply_univ, ratio_bin_mass ha hma hab, + ← ENNReal.ofReal_mul hmb0] + _ ≤ _ := by + apply lintegral_mono_ae + apply ae_restrict_of_forall_mem measurableSet_Ico + intro t ht + exact ENNReal.ofReal_le_ofReal (multiplier_antitone hs + (Set.mem_Ici.mpr (hma.trans ht.1)) (Set.mem_Ici.mpr (hma.trans hab)) ht.2.le) + constructor + · have h := ENNReal.toReal_mono hfinite hl + simpa only [continuousBin, ENNReal.toReal_ofReal (mul_nonneg hmb0 hH)] using h + · have h := ENNReal.toReal_mono ENNReal.ofReal_ne_top hu + simpa only [continuousBin, ENNReal.toReal_ofReal (mul_nonneg hma0 hH)] using h + +end NumberTheoryLean.ContinuousRatioBins + +end + +section + +namespace NumberTheoryLean.ContinuousKilledBins + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PairedCostGrouping ArrivalKernelGeometry +open LowStateHorizon RegeneratingInverseBands KernelDensityBridge ContinuousRatioBins + +noncomputable def continuousChain (v ell S : ℝ) : Kernel (CemeteryKernel.Space CostState) (CemeteryKernel.Space CostState) := + CemeteryKernel.complete (lowKernel costKernel v ell S) + +instance continuousChain_isMarkov (v ell S : ℝ) : IsMarkovKernel (continuousChain v ell S) := by + apply CemeteryKernel.complete_isMarkov + intro z + rw [lowKernel, Kernel.restrict_apply, Measure.restrict_apply_univ] + calc + _ ≤ costKernel z univ := measure_mono (subset_univ _) + _ = 1 := measure_univ + +def ratioBinSet (a b : ℝ) : Set CostState := {z | a ≤ stateRatio z.1 ∧ stateRatio z.1 < b} + +theorem ratioBinSet_measurable (a b : ℝ) : MeasurableSet (ratioBinSet a b) := + (measurableSet_le measurable_const (stateRatio_measurable.comp measurable_fst)).inter + (measurableSet_lt (stateRatio_measurable.comp measurable_fst) measurable_const) + +theorem costKernel_ratioLaw (z : CostState) : + (costKernel z).map (fun y : CostState => stateRatio y.1) = weightedRatioLaw (stateSide z.1) (stateRatio z.1) := by + have hU : Measurable (fun s : State => (s,z.2+cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + rw [costKernel_eq_map, Measure.map_map (g := fun y : CostState => stateRatio y.1) + (stateRatio_measurable.comp measurable_fst) hU] + change (stateKernel z.1).map stateRatio = _ + rcases z with ⟨s,T⟩ + cases s with + | inl s => + rw [stateKernel_even_ratio] + exact (weightedRatioLaw_even s).symm + | inr s => + rw [stateKernel_odd_ratio] + exact (weightedRatioLaw_odd s).symm + +theorem costKernel_bin (z : CostState) (a b : ℝ) : + costKernel z (ratioBinSet a b) = weightedRatioLaw (stateSide z.1) (stateRatio z.1) (Ico a b) := by + have h := congrArg (fun μ : Measure ℝ => μ (Ico a b)) (costKernel_ratioLaw z) + rw [Measure.map_apply (f := fun y : CostState => stateRatio y.1) (stateRatio_measurable.comp measurable_fst) measurableSet_Ico] at h + exact h + +theorem lowKernel_full_bin (v : ℝ) {ell S a b : ℝ} (hell : 0 < ell) (z : CostState) + (hbS : b ≤ S) (harr : b ≤ gapValue v z/ell-1) : + lowKernel costKernel v ell S z (ratioBinSet a b) = costKernel z (ratioBinSet a b) := by + rw [lowKernel, Kernel.restrict_apply, Measure.restrict_apply (ratioBinSet_measurable a b)] + apply measure_congr + filter_upwards [costKernel_time_update z] with y hy + apply propext + constructor + · exact And.left + · intro hbin + refine ⟨hbin,?_,?_⟩ + · have ht := OccupationBoundaries.stateRatio_pos y.1 + have hpair : y = (y.1,z.2+cost (stateRatio y.1)) := Prod.ext rfl hy + have hcur : currentExponent v y = nextExponent (gapValue v z) (stateRatio y.1) := by + calc + _ = currentExponent v (y.1,z.2+cost (stateRatio y.1)) := congrArg (currentExponent v) hpair + _ = _ := currentExponent_update v z y.1 + change ell < currentExponent v y + rw [hcur] + change ell < gapValue v z/(stateRatio y.1+1) + apply (lt_div_iff₀ (by linarith : 0 < stateRatio y.1+1)).mpr + have hratio : stateRatio y.1+1 < gapValue v z/ell := by + change a ≤ stateRatio y.1 ∧ stateRatio y.1 < b at hbin + linarith [hbin.2] + have hm := (lt_div_iff₀ hell).mp hratio + nlinarith + · exact hbin.2.le.trans hbS + +theorem continuousChain_full_bin (v : ℝ) {ell S a b : ℝ} (hell : 0 < ell) (z : CostState) + (hbS : b ≤ S) (harr : b ≤ gapValue v z/ell-1) : + continuousChain v ell S (.inl z) (Sum.inl '' ratioBinSet a b) = + weightedRatioLaw (stateSide z.1) (stateRatio z.1) (Ico a b) := by + rw [continuousChain, CemeteryKernel.complete_live_mass _ _ (ratioBinSet_measurable a b), + lowKernel_full_bin v hell z hbS harr, costKernel_bin] + +theorem continuousChain_full_bin_real (v : ℝ) {ell S a b : ℝ} (hell : 0 < ell) (z : CostState) + (hbS : b ≤ S) (harr : b ≤ gapValue v z/ell-1) : + (continuousChain v ell S (.inl z) (Sum.inl '' ratioBinSet a b)).toReal = + continuousBin (stateSide z.1) (stateRatio z.1) a b := by + rw [continuousChain_full_bin v hell z hbS harr] + rfl + +end NumberTheoryLean.ContinuousKilledBins + +end + +section + +namespace NumberTheoryLean.ContinuousIntervalUpper + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeTiltBounds PrimeTiltMonotone +open ContinuousRatioBins ContinuousKilledBins LowStateHorizon + +theorem transition_density_upper : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, ∀ i : Side, ∀ s : ℝ, + Valid i s → s ≤ S → ∀ t : ℝ, + ENNReal.ofReal (transitionDensity i s t) ≤ ENNReal.ofReal (C*(1+S)^2) := by + obtain ⟨C,hC,henv⟩ := multiplier_envelope + refine ⟨C,hC,?_⟩ + intro S i s hs hsS t + rw [← weighted_ratio_density_eq hs t] + by_cases ht : minRatio i s ≤ t + · rw [indicator_of_mem (show t ∈ Ici (minRatio i s) from ht)] + have ht0 := valid_pos (valid_next hs ht) + have hinv : ENNReal.ofReal (1/(t+1)) ≤ 1 := by + apply (ENNReal.ofReal_le_one).mpr + exact (div_le_iff₀ (by linarith : 0 < t+1)).mpr (by linarith) + calc + _ ≤ 1*ENNReal.ofReal (C*(1+S)^2) := mul_le_mul hinv (ENNReal.ofReal_le_ofReal (henv S i s t hs hsS ht)) zero_le zero_le + _ = _ := one_mul _ + · rw [indicator_of_notMem (show t ∉ Ici (minRatio i s) from ht)] + exact zero_le + +theorem weighted_interval_upper : ∃ C : ℝ, 0 < C ∧ ∀ S : ℝ, ∀ i : Side, ∀ s a b : ℝ, + Valid i s → s ≤ S → + weightedRatioLaw i s (Icc a b) ≤ ENNReal.ofReal (C*(1+S)^2) * ENNReal.ofReal (b-a) := by + obtain ⟨C,hC,hbound⟩ := transition_density_upper + refine ⟨C,hC,?_⟩ + intro S i s a b hs hsS + rw [weightedRatioLaw_eq_density hs,withDensity_apply _ measurableSet_Icc] + calc + _ ≤ ∫⁻ _t in Icc a b, ENNReal.ofReal (C*(1+S)^2) := lintegral_mono (hbound S i s hs hsS) + _ = _ := by rw [setLIntegral_const,Real.volume_Icc] + +def closedCostBin (a b : ℝ) : Set CostState := + {z | a ≤ stateRatio z.1 ∧ stateRatio z.1 ≤ b} + +theorem closedCostBin_measurable (a b : ℝ) : MeasurableSet (closedCostBin a b) := + (stateRatio_measurable.comp measurable_fst) measurableSet_Icc + +theorem costKernel_closedBin (z : CostState) (a b : ℝ) : + costKernel z (closedCostBin a b) = weightedRatioLaw (stateSide z.1) (stateRatio z.1) (Icc a b) := by + have h := congrArg (fun μ : Measure ℝ => μ (Icc a b)) (costKernel_ratioLaw z) + rw [Measure.map_apply (f := fun y : CostState => stateRatio y.1) (stateRatio_measurable.comp measurable_fst) measurableSet_Icc] at h + exact h + +theorem completed_interval_upper : ∃ C : ℝ, 0 < C ∧ ∀ v ell S a b : ℝ, ∀ z : CostState, + stateRatio z.1 ≤ S → + continuousChain v ell S (.inl z) (Sum.inl '' closedCostBin a b) ≤ + ENNReal.ofReal (C*(1+S)^2) * ENNReal.ofReal (b-a) := by + obtain ⟨C,hC,hbound⟩ := weighted_interval_upper + refine ⟨C,hC,?_⟩ + intro v ell S a b z hsS + rw [continuousChain,CemeteryKernel.complete_live_mass _ _ (closedCostBin_measurable a b), + lowKernel,Kernel.restrict_apply,Measure.restrict_apply (closedCostBin_measurable a b)] + calc + _ ≤ costKernel z (closedCostBin a b) := measure_mono inter_subset_left + _ = weightedRatioLaw (stateSide z.1) (stateRatio z.1) (Icc a b) := costKernel_closedBin z a b + _ ≤ _ := hbound S (stateSide z.1) (stateRatio z.1) a b (stateRatio_valid z.1) hsS + +end NumberTheoryLean.ContinuousIntervalUpper + +end + +section + +namespace NumberTheoryLean.CompletedParentInterval +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open _root_.Erdos970.Set _root_.Erdos970.MeasureTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures ContinuousIntervalUpper ContinuousRatioBins ContinuousKilledBins LowStateHorizon + +theorem completed_parent_interval_upper : ∃ C : ℝ,0 < C ∧ + ∀ v ell S U a b : ℝ,∀ z : CostState,stateRatio z.1 ≤ U → + continuousChain v ell S (.inl z) (Sum.inl '' closedCostBin a b) ≤ + ENNReal.ofReal (C*(1+U)^2)*ENNReal.ofReal (b-a) := by + obtain ⟨C,hC,hbound⟩ := weighted_interval_upper + refine ⟨C,hC,?_⟩ + intro v ell S U a b z hz + rw [continuousChain,CemeteryKernel.complete_live_mass _ _ (closedCostBin_measurable a b), + lowKernel,Kernel.restrict_apply,Measure.restrict_apply (closedCostBin_measurable a b)] + calc + _ ≤ costKernel z (closedCostBin a b) := measure_mono inter_subset_left + _ = _ := costKernel_closedBin z a b + _ ≤ _ := hbound U (stateSide z.1) (stateRatio z.1) a b (stateRatio_valid z.1) hz +end NumberTheoryLean.CompletedParentInterval + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ContinuousHighPartition.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ContinuousHighPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a883c9145c3181fb83209437fa798542293390a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ContinuousHighPartition.lean @@ -0,0 +1,100 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.AdmittedHighRemoval +import OAI.NumberTheory.Jacobsthal.Probability.SubMarkovFlagPowers + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ContinuousHighPartition + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures RegeneratingInverseBands ArrivalKernelGeometry +open AdmittedHarmonicPaths LowStateHorizon SubMarkovFlagPowers +open PersistentFailureFlag FlaggedOccupationBound + +def high (S : ℝ) (z : CostState) : Prop := S < stateRatio z.1 + +theorem high_measurable (S : ℝ) : MeasurableSet {z | high S z} := + measurableSet_lt measurable_const (stateRatio_measurable.comp measurable_fst) + +theorem good_admitted_eq_low (K : Kernel CostState CostState) (v ell S : ℝ) : + goodKernel (K.restrict (arrivalSet_measurable v ell)) (high_measurable S) = lowKernel K v ell S := by + ext z : 1 + simp only [goodKernel,lowKernel,Kernel.restrict_apply,Measure.restrict_restrict (high_measurable S).compl] + congr 1 + ext y + simp only [lowDomain,mem_inter_iff,mem_compl_iff,mem_ofPred_eq,high,not_lt] + exact and_comm + +theorem marked_harmonic_eq (v ell S : ℝ) : + marked (admittedHarmonic v ell) (high_measurable S) = FlaggedHarmonicPaths.kernel v ell S := by + ext z : 1 + rw [marked_eq_map_sfinite,FlaggedHarmonicPaths.kernel_eq_map] + congr 1 + funext y + by_cases hy : S < stateRatio y.1 <;> + cases z.2 <;> simp [FlaggedHarmonicPaths.flagUpdate,badBit,high,hy] + +noncomputable def tiltedFlagged (v ell S : ℝ) : Kernel (CostState×Bool) (CostState×Bool) := + marked (admittedTilted v ell) (high_measurable S) + +theorem harmonic_finite_partition (v ell S : ℝ) {F : CostState → ℝ≥0∞} (hF : Measurable F) + (n : ℕ) (z : CostState) (hz : stateRatio z.1 ≤ S) : + (∫⁻ y,F y ∂((admittedHarmonic v ell)^n) z) = + (∫⁻ y,F y ∂((lowKernel HarmonicWeightKernel.harmonicKernel v ell S)^n) z)+ + (∫⁻ y,selected F y ∂((FlaggedHarmonicPaths.kernel v ell S)^n) (FlaggedHarmonicPaths.initial S z)) := by + have h := finite_integral_partition (admittedHarmonic v ell) (high_measurable S) hF n z + have he : goodKernel (admittedHarmonic v ell) (high_measurable S) = + lowKernel HarmonicWeightKernel.harmonicKernel v ell S := + good_admitted_eq_low HarmonicWeightKernel.harmonicKernel v ell S + rw [he,marked_harmonic_eq] at h + simpa only [FlaggedHarmonicPaths.initial,ite_eq_right (not_lt.mpr hz)] using h + +theorem tilted_finite_partition (v ell S : ℝ) {F : CostState → ℝ≥0∞} (hF : Measurable F) + (n : ℕ) (z : CostState) : + (∫⁻ y,F y ∂((admittedTilted v ell)^n) z) = + (∫⁻ y,F y ∂((lowKernel costKernel v ell S)^n) z)+ + (∫⁻ y,selected F y ∂((tiltedFlagged v ell S)^n) (z,false)) := by + have h := finite_integral_partition (admittedTilted v ell) (high_measurable S) hF n z + have he : goodKernel (admittedTilted v ell) (high_measurable S) = lowKernel costKernel v ell S := + good_admitted_eq_low costKernel v ell S + rw [he] at h + exact h + +theorem harmonic_high_compact_bound (v ell S : ℝ) (z : CostState) {F : CostState → ℝ≥0∞} + {D : ℝ≥0∞} (hD : D ≠ ∞) {K : ℝ} (hbound : ∀ y,F y ≤ D) + (hsupport : ∀ y,K < gapValue v y → F y=0) : + (∑' n : ℕ,∫⁻ y,selected F y ∂((FlaggedHarmonicPaths.kernel v ell S)^n) (FlaggedHarmonicPaths.initial S z)) ≤ + D*AdmittedHighRemoval.lowHighMass v ell S z K := by + have hA : MeasurableSet {y : CostState×Bool | y.2=true ∧ gapValue v y.1 ≤ K} := + (measurable_snd (measurableSet_singleton true)).inter + (measurableSet_le ((gapValue_measurable v).comp measurable_fst) measurable_const) + have hpoint : ∀ y : CostState×Bool,selected F y ≤ + D*{y : CostState×Bool | y.2=true ∧ gapValue v y.1 ≤ K}.indicator (fun _ => (1:ℝ≥0∞)) y := by + rintro ⟨y,b⟩ + cases b with + | false => simp [selected,failed] + | true => + by_cases hy : gapValue v y ≤ K + · simp [selected,failed,hy,hbound y] + · simp [selected,failed,hy,hsupport y (lt_of_not_ge hy)] + unfold AdmittedHighRemoval.lowHighMass + rw [← ENNReal.tsum_mul_left] + apply ENNReal.tsum_le_tsum + intro n + calc + _ ≤ ∫⁻ y,D*{y : CostState×Bool | y.2=true ∧ gapValue v y.1 ≤ K}.indicator (fun _ => (1:ℝ≥0∞)) y + ∂((FlaggedHarmonicPaths.kernel v ell S)^n) (FlaggedHarmonicPaths.initial S z) := lintegral_mono hpoint + _ = _ := by rw [lintegral_const_mul' _ _ hD,lintegral_indicator hA,setLIntegral_const,one_mul] + +end NumberTheoryLean.ContinuousHighPartition + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CrossingBandGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CrossingBandGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac7d43610132671e53e6d3de1708181e68f73978 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CrossingBandGeometry.lean @@ -0,0 +1,671 @@ +import Mathlib.Algebra.Order.Group.MinMax +import OAI.NumberTheory.Jacobsthal.Estimates.SourceCandidateFreezing +import OAI.NumberTheory.Jacobsthal.Probability.ArrivalKernelGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.LogarithmicBinScale + + +noncomputable def binCount (w z xi : ℝ) : ℕ := ⌈Real.log (z/w)/Real.log (1+xi)⌉₊ +noncomputable def logWidth (w z xi : ℝ) : ℝ := Real.log (z/w)/(binCount w z xi:ℝ) +noncomputable def effectiveWidth (w z xi : ℝ) : ℝ := Real.exp (logWidth w z xi)-1 + +theorem span_log_pos {w z : ℝ} (hw : 0 < w) (hwz : w < z) : 0 < Real.log (z/w) := by + apply Real.log_pos + exact (lt_div_iff₀ hw).mpr (by simpa only [one_mul] using hwz) + +theorem binCount_pos {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + 0 < binCount w z xi := + Nat.ceil_pos.mpr (div_pos (span_log_pos hw hwz) (Real.log_pos (by linarith))) + +theorem logWidth_pos {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + 0 < logWidth w z xi := + div_pos (span_log_pos hw hwz) (by exact_mod_cast binCount_pos hw hwz hxi) + +theorem count_mul_logWidth {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + (binCount w z xi:ℝ)*logWidth w z xi = Real.log (z/w) := by + have hn : (binCount w z xi:ℝ) ≠ 0 := by exact_mod_cast (binCount_pos hw hwz hxi).ne' + unfold logWidth + field_simp [hn] + +theorem logWidth_le {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + logWidth w z xi ≤ Real.log (1+xi) := by + have hlog : 0 < Real.log (1+xi) := Real.log_pos (by linarith) + have hc := Nat.le_ceil (Real.log (z/w)/Real.log (1+xi)) + have hm := (div_le_iff₀ hlog).mp hc + change Real.log (z/w) ≤ (binCount w z xi:ℝ)*Real.log (1+xi) at hm + apply (div_le_iff₀ (by exact_mod_cast binCount_pos hw hwz hxi : (0:ℝ) < binCount w z xi)).mpr + exact (by nlinarith : Real.log (z/w) ≤ Real.log (1+xi)*(binCount w z xi:ℝ)) + +theorem logWidth_ge_half {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (hspan : Real.log (1+xi) ≤ Real.log (z/w)) : + Real.log (1+xi)/2 ≤ logWidth w z xi := by + have hlog : 0 < Real.log (1+xi) := Real.log_pos (by linarith) + have hc := Nat.ceil_lt_add_one (div_pos (span_log_pos hw hwz) hlog).le + have hm := mul_lt_mul_of_pos_right hc hlog + have he : (Real.log (z/w)/Real.log (1+xi)+1)*Real.log (1+xi) = + Real.log (z/w)+Real.log (1+xi) := by field_simp [hlog.ne'] + rw [he] at hm + apply (le_div_iff₀ (by exact_mod_cast binCount_pos hw hwz hxi : (0:ℝ) < binCount w z xi)).mpr + change _ ≤ Real.log (z/w) + change (binCount w z xi:ℝ)*Real.log (1+xi) < _ at hm + nlinarith + +theorem effectiveWidth_pos {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + 0 < effectiveWidth w z xi := by + exact sub_pos.mpr (Real.one_lt_exp_iff.mpr (logWidth_pos hw hwz hxi)) + +theorem effectiveWidth_le {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + effectiveWidth w z xi ≤ xi := by + have he := Real.exp_le_exp.mpr (logWidth_le hw hwz hxi) + rw [Real.exp_log (by linarith : 0 < 1+xi)] at he + exact sub_le_iff_le_add.mpr (by linarith) + +theorem effectiveWidth_ge_quarter {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hspan : Real.log (1+xi) ≤ Real.log (z/w)) : + xi/4 ≤ effectiveWidth w z xi := by + have hpos : 0 < 1+xi := by linarith + have hl := Real.one_sub_inv_le_log_of_pos hpos + have he : 1-(1+xi)⁻¹ = xi/(1+xi) := by field_simp [hpos.ne']; ring + rw [he] at hl + have hf : xi/2 ≤ xi/(1+xi) := div_le_div_of_nonneg_left hxi.le hpos (by linarith) + have hwide := logWidth_ge_half hw hwz hxi hspan + have hexp := Real.add_one_le_exp (logWidth w z xi) + unfold effectiveWidth + linarith + +end NumberTheoryLean.LogarithmicBinScale + + + +namespace NumberTheoryLean.LogarithmicBinEndpoints + +open LogarithmicBinScale PrimeBinRepresentatives ErdosInversePrimeBin + +noncomputable def endpoint (w z xi : ℝ) (k : ℕ) : ℝ := w*Real.exp ((k:ℝ)*logWidth w z xi) +noncomputable def lower (w z xi : ℝ) (i : Fin (binCount w z xi)) : ℝ := endpoint w z xi i.1 +noncomputable def width (w z xi : ℝ) (_i : Fin (binCount w z xi)) : ℝ := effectiveWidth w z xi +noncomputable def upper (w z xi : ℝ) (i : Fin (binCount w z xi)) : ℝ := + (1+width w z xi i)*lower w z xi i + +theorem endpoint_zero (w z xi : ℝ) : endpoint w z xi 0 = w := by simp [endpoint] + +theorem upper_endpoint (w z xi : ℝ) (i : Fin (binCount w z xi)) : + upper w z xi i = endpoint w z xi (i.1+1) := by + simp only [upper,width,lower,effectiveWidth,endpoint,Nat.cast_add,Nat.cast_one,add_mul,one_mul,Real.exp_add] + ring + +theorem endpoint_count {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + endpoint w z xi (binCount w z xi) = z := by + rw [endpoint,count_mul_logWidth hw hwz hxi,Real.exp_log (div_pos (hw.trans hwz) hw)] + field_simp [hw.ne'] + +theorem endpoint_pos {w z xi : ℝ} (hw : 0 < w) (k : ℕ) : 0 < endpoint w z xi k := by + exact mul_pos hw (Real.exp_pos _) + +theorem endpoint_mono {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + {k m : ℕ} (hkm : k ≤ m) : endpoint w z xi k ≤ endpoint w z xi m := by + have hc : (k:ℝ) ≤ m := by exact_mod_cast hkm + exact mul_le_mul_of_nonneg_left + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right hc (logWidth_pos hw hwz hxi).le)) hw.le + +theorem bin_source_bounds {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (i : Fin (binCount w z xi)) : w ≤ lower w z xi i ∧ lower w z xi i < upper w z xi i ∧ + upper w z xi i ≤ z := by + have hlow : w ≤ lower w z xi i := by + have h := endpoint_mono hw hwz hxi (Nat.zero_le i.1) + simpa only [endpoint_zero,lower] using h + have hstrict : lower w z xi i < upper w z xi i := by + have hp : 0 < lower w z xi i := endpoint_pos hw _ + have he : 0 < width w z xi i := effectiveWidth_pos hw hwz hxi + unfold upper + nlinarith + refine ⟨hlow,hstrict,?_⟩ + rw [upper_endpoint] + exact (endpoint_mono hw hwz hxi (Nat.succ_le_of_lt i.isLt)).trans_eq (endpoint_count hw hwz hxi) + +theorem bins_separated {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (i j : Fin (binCount w z xi)) (hij : i ≠ j) : + upper w z xi i ≤ lower w z xi j ∨ upper w z xi j ≤ lower w z xi i := by + have hne : i.1 ≠ j.1 := fun h => hij (Fin.ext h) + rcases lt_or_gt_of_ne hne with hlt | hgt + · apply Or.inl + rw [upper_endpoint] + exact endpoint_mono hw hwz hxi (by omega) + · apply Or.inr + rw [upper_endpoint] + exact endpoint_mono hw hwz hxi (by omega) + +theorem last_bin_endpoint {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (i : Fin (binCount w z xi)) (hi : i.1+1 = binCount w z xi) : upper w z xi i = z := by + rw [upper_endpoint,hi,endpoint_count hw hwz hxi] + +theorem bin_prime_in_source {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (i : Fin (binCount w z xi)) {p : ℕ} (hp : p ∈ primeBin (lower w z xi i) (width w z xi i)) : + p.Prime ∧ w < (p:ℝ) ∧ (p:ℝ) ≤ z := by + have hb := (mem_primeBin (endpoint_pos hw i.1).le (effectiveWidth_pos hw hwz hxi).le p).mp hp + have hs := bin_source_bounds hw hwz hxi i + exact ⟨hb.1,hs.1.trans_lt hb.2.1,hb.2.2.trans hs.2.2⟩ + +end NumberTheoryLean.LogarithmicBinEndpoints + + + +namespace NumberTheoryLean.LogarithmicBinLabels + +open LogarithmicBinScale LogarithmicBinEndpoints ErdosInversePrimeBin + +noncomputable def coordinate (w z xi : ℝ) (p : ℕ) : ℝ := Real.log ((p:ℝ)/w)/logWidth w z xi + +noncomputable def index (w z xi : ℝ) (p : ℕ) : ℕ := + min (binCount w z xi-1) (⌈coordinate w z xi p⌉₊-1) + +theorem coordinate_bounds {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + {p : ℕ} (hp : w < (p:ℝ) ∧ (p:ℝ) ≤ z) : + 0 < coordinate w z xi p ∧ coordinate w z xi p ≤ (binCount w z xi:ℝ) := by + have hlog : 0 < Real.log ((p:ℝ)/w) := by + apply Real.log_pos + exact (lt_div_iff₀ hw).mpr (by simpa only [one_mul] using hp.1) + have hd := logWidth_pos hw hwz hxi + refine ⟨div_pos hlog hd,?_⟩ + apply (div_le_iff₀ hd).mpr + rw [count_mul_logWidth hw hwz hxi] + exact Real.log_le_log (div_pos (hw.trans hp.1) hw) (div_le_div_of_nonneg_right hp.2 hw.le) + +theorem index_lt {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) (p : ℕ) : + index w z xi p < binCount w z xi := by + have hn := binCount_pos hw hwz hxi + have hm : index w z xi p ≤ binCount w z xi-1 := min_le_left _ _ + omega + +noncomputable def label {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (p : ℕ) : Fin (binCount w z xi) := ⟨index w z xi p,index_lt hw hwz hxi p⟩ + +theorem index_eq_ceiling {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + {p : ℕ} (hp : w < (p:ℝ) ∧ (p:ℝ) ≤ z) : index w z xi p = ⌈coordinate w z xi p⌉₊-1 := by + have hc : ⌈coordinate w z xi p⌉₊ ≤ binCount w z xi := Nat.ceil_le.mpr (coordinate_bounds hw hwz hxi hp).2 + exact min_eq_right (by omega) + +theorem label_coordinate_bounds {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + {p : ℕ} (hp : w < (p:ℝ) ∧ (p:ℝ) ≤ z) : + ((label hw hwz hxi p).1:ℝ) < coordinate w z xi p ∧ + coordinate w z xi p ≤ ((label hw hwz hxi p).1:ℝ)+1 := by + have hc := coordinate_bounds hw hwz hxi hp + have hpos : 0 < ⌈coordinate w z xi p⌉₊ := Nat.ceil_pos.mpr hc.1 + have hlow := Nat.ceil_lt_add_one hc.1.le + have hhigh := Nat.le_ceil (coordinate w z xi p) + have he : ((label hw hwz hxi p).1:ℝ) = (⌈coordinate w z xi p⌉₊:ℝ)-1 := by + change (index w z xi p:ℝ) = _ + rw [index_eq_ceiling hw hwz hxi hp,Nat.cast_sub (by omega : 1 ≤ ⌈coordinate w z xi p⌉₊)] + norm_num + rw [he] + constructor <;> linarith + +theorem label_value_bounds {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + {p : ℕ} (hp : w < (p:ℝ) ∧ (p:ℝ) ≤ z) : + lower w z xi (label hw hwz hxi p) < (p:ℝ) ∧ + (p:ℝ) ≤ upper w z xi (label hw hwz hxi p) := by + have hb := label_coordinate_bounds hw hwz hxi hp + have hd := logWidth_pos hw hwz hxi + have hpw : 0 < (p:ℝ)/w := div_pos (hw.trans hp.1) hw + have he : coordinate w z xi p*logWidth w z xi = Real.log ((p:ℝ)/w) := by + unfold coordinate + field_simp [hd.ne'] + have hlo := mul_lt_mul_of_pos_right hb.1 hd + have hhi := mul_le_mul_of_nonneg_right hb.2 hd.le + rw [he] at hlo hhi + have hExpLo := Real.exp_lt_exp.mpr hlo + have hExpHi := Real.exp_le_exp.mpr hhi + rw [Real.exp_log hpw] at hExpLo hExpHi + constructor + · have h := (lt_div_iff₀ hw).mp hExpLo + simpa only [lower,endpoint,mul_comm] using h + · rw [upper_endpoint] + have h := (div_le_iff₀ hw).mp hExpHi + simpa only [endpoint,Nat.cast_add,Nat.cast_one,mul_comm] using h + +theorem label_prime_membership {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + {p : ℕ} (hprime : p.Prime) (hp : w < (p:ℝ) ∧ (p:ℝ) ≤ z) : + p ∈ primeBin (lower w z xi (label hw hwz hxi p)) (width w z xi (label hw hwz hxi p)) := by + apply (mem_primeBin (endpoint_pos hw _).le (effectiveWidth_pos hw hwz hxi).le p).mpr + exact ⟨hprime,(label_value_bounds hw hwz hxi hp).1,(label_value_bounds hw hwz hxi hp).2⟩ + +end NumberTheoryLean.LogarithmicBinLabels + + + +namespace NumberTheoryLean.LogarithmicBinPartition + +open _root_.Set _root_.Finset +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels ErdosInversePrimeBin + +noncomputable def sourcePrimeSet (w z : ℝ) : Finset ℕ := Nat.primesLE ⌊z⌋₊ \ Nat.primesLE ⌊w⌋₊ + +theorem mem_sourcePrimeSet {w z : ℝ} (hw : 0 < w) (hwz : w < z) (p : ℕ) : + p ∈ sourcePrimeSet w z ↔ p.Prime ∧ w < (p:ℝ) ∧ (p:ℝ) ≤ z := by + constructor + · intro hp + obtain ⟨hup,hnot⟩ := Finset.mem_sdiff.mp hp + obtain ⟨hbound,hprime⟩ := Nat.mem_primesLE.mp hup + refine ⟨hprime,?_,(Nat.le_floor_iff (hw.trans hwz).le).mp hbound⟩ + by_contra! hlo + exact hnot (Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff hw.le).mpr hlo,hprime⟩) + · rintro ⟨hprime,hlo,hhi⟩ + apply Finset.mem_sdiff.mpr + refine ⟨Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff (hw.trans hwz).le).mpr hhi,hprime⟩,?_⟩ + intro hp + exact (not_le_of_gt hlo) ((Nat.le_floor_iff hw.le).mp (Nat.mem_primesLE.mp hp).1) + +theorem bin_mem_iff_label {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (i : Fin (binCount w z xi)) (p : ℕ) : + p ∈ primeBin (lower w z xi i) (width w z xi i) ↔ + p.Prime ∧ w < (p:ℝ) ∧ (p:ℝ) ≤ z ∧ label hw hwz hxi p = i := by + constructor + · intro hp + have hs := bin_prime_in_source hw hwz hxi i hp + have hI := (mem_primeBin (endpoint_pos hw _).le (effectiveWidth_pos hw hwz hxi).le p).mp hp + have hL := label_value_bounds hw hwz hxi hs.2 + refine ⟨hs.1,hs.2.1,hs.2.2,?_⟩ + by_contra hne + have hsep := bins_separated hw hwz hxi i (label hw hwz hxi p) (Ne.symm hne) + have huI : (p:ℝ) ≤ upper w z xi i := hI.2.2 + have hlI : lower w z xi i < (p:ℝ) := hI.2.1 + rcases hsep with hsep | hsep <;> linarith [hlI,hL.1,hL.2] + · rintro ⟨hprime,hlo,hhi,heq⟩ + rw [← heq] + exact label_prime_membership hw hwz hxi hprime ⟨hlo,hhi⟩ + +theorem bins_pairwise_disjoint {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (i j : Fin (binCount w z xi)) (hij : i ≠ j) : + Disjoint (primeBin (lower w z xi i) (width w z xi i)) + (primeBin (lower w z xi j) (width w z xi j)) := by + apply Finset.disjoint_left.mpr + intro p hi hj + have hpi := (bin_mem_iff_label hw hwz hxi i p).mp hi + have hpj := (bin_mem_iff_label hw hwz hxi j p).mp hj + exact hij (hpi.2.2.2.symm.trans hpj.2.2.2) + +theorem union_bins_eq_source {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) : + (Finset.univ : Finset (Fin (binCount w z xi))).biUnion + (fun i => primeBin (lower w z xi i) (width w z xi i)) = sourcePrimeSet w z := by + ext p + constructor + · intro hp + obtain ⟨i,_hi,hp⟩ := Finset.mem_biUnion.mp hp + exact (mem_sourcePrimeSet hw hwz p).mpr (bin_prime_in_source hw hwz hxi i hp) + · intro hp + have hs := (mem_sourcePrimeSet hw hwz p).mp hp + exact Finset.mem_biUnion.mpr ⟨label hw hwz hxi p,Finset.mem_univ _, + label_prime_membership hw hwz hxi hs.1 hs.2⟩ + +theorem source_sum_over_bins {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (F : ℕ → ℝ) : + (∑ p ∈ sourcePrimeSet w z,F p) = + ∑ i : Fin (binCount w z xi),∑ p ∈ primeBin (lower w z xi i) (width w z xi i),F p := by + rw [← union_bins_eq_source hw hwz hxi] + exact Finset.sum_biUnion (fun i _ j _ hij => bins_pairwise_disjoint hw hwz hxi i j hij) + +end NumberTheoryLean.LogarithmicBinPartition + + + +namespace NumberTheoryLean.NearbyParentGeometry + +open FinitePathGeometry OccupationBoundaries + +theorem minRatio_stability (i : Side) (s t : ℝ) : + |minRatio i s-minRatio i t| ≤ |s-t| := by + cases i with + | even => simp [minRatio] + | odd => + simpa only [minRatio, sub_sub_sub_cancel_right, sub_self, abs_zero, + max_eq_right (abs_nonneg (s-t))] using abs_max_sub_max_le_max (2:ℝ) (s-1) 2 (t-1) + +theorem log_stability {m x y : ℝ} (hm : 0 < m) (hx : m ≤ x) (hy : m ≤ y) : + |Real.log x-Real.log y| ≤ |x-y|/m := by + wlog hxy : y ≤ x generalizing x y + · simpa only [abs_sub_comm] using this hy hx (le_of_not_ge hxy) + have hx0 := hm.trans_le hx + have hy0 := hm.trans_le hy + rw [abs_of_nonneg (sub_nonneg.mpr (Real.log_le_log hy0 hxy)), abs_of_nonneg (sub_nonneg.mpr hxy)] + have h := Real.log_le_sub_one_of_pos (div_pos hx0 hy0) + rw [Real.log_div hx0.ne' hy0.ne'] at h + calc + Real.log x-Real.log y ≤ (x-y)/y := by + convert h using 1 + field_simp + _ ≤ (x-y)/m := div_le_div_of_nonneg_left (sub_nonneg.mpr hxy) hm hy + +theorem cost_stability {s t : ℝ} (hs : (1/2:ℝ) ≤ s) (ht : (1/2:ℝ) ≤ t) : + |cost s-cost t| ≤ 4*|s-t| := by + have hs0 : 0 < s := by linarith + have ht0 : 0 < t := by linarith + have h1 := log_stability (m:=1/2) (by norm_num) hs ht + have h2 := log_stability (m:=1/2) (x:=s+1) (y:=t+1) (by norm_num) (by linarith) (by linarith) + have heq : cost s-cost t = (Real.log (s+1)-Real.log (t+1))-(Real.log s-Real.log t) := by + linarith [cost_add_log hs0, cost_add_log ht0] + rw [heq] + calc + _ ≤ |Real.log (s+1)-Real.log (t+1)|+|Real.log s-Real.log t| := abs_sub _ _ + _ ≤ 4*|s-t| := by + simp only [add_sub_add_right_eq_sub] at h2 + linarith + +theorem clipped_relative_stability {A x y c : ℝ} (hA : 0 ≤ A) (hc : 1 ≤ c) + (hxy : x ≤ c*y) (hyx : y ≤ c*x) : + |min A x-min A y| ≤ A*(c-1) := by + have hnonneg : 0 ≤ A*(c-1) := mul_nonneg hA (by linarith) + simp only [min_def] + split_ifs <;> apply abs_le.mpr <;> constructor <;> nlinarith + +theorem log_gap_relative {r q d : ℝ} (hr : 0 < r) (hq : 0 < q) + (hd : |Real.log r-Real.log q| ≤ d) : r ≤ Real.exp d*q ∧ q ≤ Real.exp d*r := by + have h1 := Real.exp_le_exp.mpr (abs_le.mp hd).2 + have h2 := Real.exp_le_exp.mpr (show Real.log q-Real.log r ≤ d by linarith [(abs_le.mp hd).1]) + rw [Real.exp_sub,Real.exp_log hr,Real.exp_log hq] at h1 + rw [Real.exp_sub,Real.exp_log hq,Real.exp_log hr] at h2 + exact ⟨(div_le_iff₀ hq).mp h1,(div_le_iff₀ hr).mp h2⟩ + +theorem arrival_endpoint_stability {r q ell S d : ℝ} (hr : 0 < r) (hq : 0 < q) + (hell : 0 < ell) (hS : 0 ≤ S+1) (hd : |Real.log r-Real.log q| ≤ d) : + |min S (r/ell-1)-min S (q/ell-1)| ≤ (S+1)*(Real.exp d-1) := by + have hrel := log_gap_relative hr hq hd + have hd0 : 0 ≤ d := (abs_nonneg _).trans hd + have he : 1 ≤ Real.exp d := Real.one_le_exp_iff.mpr hd0 + have h1 : r/ell ≤ Real.exp d*(q/ell) := by + simpa only [mul_div_assoc] using div_le_div_of_nonneg_right hrel.1 hell.le + have h2 : q/ell ≤ Real.exp d*(r/ell) := by + simpa only [mul_div_assoc] using div_le_div_of_nonneg_right hrel.2 hell.le + have h := clipped_relative_stability hS he h1 h2 + have hu (x:ℝ) : min S (x-1) = min (S+1) x-1 := by + rw [← min_sub_sub_right] + simp + simpa only [hu,sub_sub_sub_cancel_right] using h + +theorem log_gap_step {r q s t d e : ℝ} (hr : 0 < r) (hq : 0 < q) + (hs : (1/2:ℝ) ≤ s) (ht : (1/2:ℝ) ≤ t) + (hd : |Real.log r-Real.log q| ≤ d) (he : |s-t| ≤ e) : + |Real.log (nextGap r s)-Real.log (nextGap q t)| ≤ d+4*e := by + have hs0 : 0 < s := by linarith + have ht0 : 0 < t := by linarith + rw [nextGap_eq_cost hs0,nextGap_eq_cost ht0,Real.log_mul hr.ne' (Real.exp_pos _).ne', + Real.log_mul hq.ne' (Real.exp_pos _).ne',Real.log_exp,Real.log_exp] + have ha := abs_sub (Real.log r-Real.log q) (cost s-cost t) + have hc := cost_stability hs ht + have heq : Real.log r + -cost s-(Real.log q + -cost t) = + (Real.log r-Real.log q)-(cost s-cost t) := by ring + rw [heq] + linarith + +end NumberTheoryLean.NearbyParentGeometry + + + +namespace NumberTheoryLean.LogarithmicBinMaps + +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open SourceStopPredicate PrimeBinRepresentatives RepresentativeAdmission PrimeHistories +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem source_list_boxed {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (ps : List ℕ) (hp : ∀ p ∈ ps,p ∈ sourcePrimeSet w z) : + boxed (lower w z xi) (width w z xi) (label hw hwz hxi) ps := by + intro p hps + have hs := (mem_sourcePrimeSet hw hwz p).mp (hp p hps) + exact label_prime_membership hw hwz hxi hs.1 hs.2 + +theorem source_representative_error {w z xi : ℝ} (hw : 1 < w) (hwz : w < z) (hxi : 0 < xi) + {p : ℕ} (hp : p ∈ sourcePrimeSet w z) : + 0 ≤ representative w (lower w z xi) (width w z xi) (label (by linarith : 0 < w) hwz hxi) p-primeExponent w p ∧ + representative w (lower w z xi) (width w z xi) (label (by linarith : 0 < w) hwz hxi) p-primeExponent w p ≤ xi/Real.log w := by + have hw0 : 0 < w := by linarith + have hs := (mem_sourcePrimeSet hw0 hwz p).mp hp + have hbin := label_prime_membership hw0 hwz hxi hs.1 hs.2 + have he := representative_error hw (endpoint_pos hw0 _) (effectiveWidth_pos hw0 hwz hxi).le hbin + refine ⟨he.1,he.2.trans ?_⟩ + exact div_le_div_of_nonneg_right (effectiveWidth_le hw0 hwz hxi) (Real.log_pos hw).le + +theorem source_prefix_movement {w z xi B Clen : ℝ} (hw : 1 < w) (hwz : w < z) (hxi : 0 < xi) + (hC : 0 ≤ Clen) (hcomp : Real.log B ≤ 2*Real.log w) (v : Node) (ps : List ℕ) + (hp : ∀ p ∈ ps,p ∈ sourcePrimeSet w z) (hlen : (ps.length:ℝ) ≤ Clen*Real.log B) : + 0 ≤ (terminal w v ps).gap-representativeGap + (representative w (lower w z xi) (width w z xi) (label (by linarith : 0 < w) hwz hxi)) v.gap ps ∧ + (terminal w v ps).gap-representativeGap + (representative w (lower w z xi) (width w z xi) (label (by linarith : 0 < w) hwz hxi)) v.gap ps ≤ 2*Clen*xi := by + exact source_movement_bound hw hC hxi.le hcomp _ v ps hlen + (fun p hps => source_representative_error hw hwz hxi (hp p hps)) + +theorem common_width_bounds {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hspan : (1+xi)*w ≤ z) : + 0 < effectiveWidth w z xi ∧ xi/4 ≤ effectiveWidth w z xi ∧ effectiveWidth w z xi ≤ xi ∧ + ∀ i : Fin (binCount w z xi),width w z xi i = effectiveWidth w z xi := by + have hl : Real.log (1+xi) ≤ Real.log (z/w) := + Real.log_le_log (by linarith : 0 < 1+xi) ((le_div_iff₀ hw).mpr hspan) + exact ⟨effectiveWidth_pos hw hwz hxi,effectiveWidth_ge_quarter hw hwz hxi hxi1 hl, + effectiveWidth_le hw hwz hxi,fun _ => rfl⟩ + +theorem endpoint_exponent {w z xi : ℝ} (hw : 1 < w) (k : ℕ) : + Real.log (endpoint w z xi k)/Real.log w = 1+(k:ℝ)*(logWidth w z xi/Real.log w) := by + have hw0 : 0 < w := by linarith + rw [endpoint,Real.log_mul hw0.ne' (Real.exp_pos _).ne',Real.log_exp] + field_simp [(Real.log_pos hw).ne'] + +theorem representative_exponent {w z xi : ℝ} (hw : 1 < w) (i : Fin (binCount w z xi)) : + rightExponent w (lower w z xi i) (width w z xi i) = + 1+((i.1:ℝ)+1)*(logWidth w z xi/Real.log w) := by + change Real.log (upper w z xi i)/Real.log w = _ + rw [upper_endpoint,endpoint_exponent hw] + simp only [Nat.cast_add,Nat.cast_one] + +end NumberTheoryLean.LogarithmicBinMaps + + + +namespace NumberTheoryLean.IsolatedBinGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open PrimeBinRepresentatives SourceStopPredicate +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def isolatedBin (w top xi B alpha beta : ℝ) (b : Fin (binCount w top xi)) : Prop := + alpha*B ≤ leftExponent w (lower w top xi b) ∧ rightExponent w (lower w top xi b) (width w top xi b) ≤ beta*B + +theorem source_left_error {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + {p : ℕ} (hp : p ∈ sourcePrimeSet w top) : + 0 ≤ primeExponent w p-leftExponent w (lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) ∧ + primeExponent w p-leftExponent w (lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) ≤ xi/Real.log w := by + have hp' := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp hp + have hbin := label_prime_membership (zero_lt_one.trans hw) htop hxi hp'.1 hp'.2 + have hh := bin_exponent_bounds hw (endpoint_pos (zero_lt_one.trans hw) _) (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le hbin + have hwid := bin_exponent_width (w:=w) + (R:=lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) + (xi:=width w top xi (label (zero_lt_one.trans hw) htop hxi p)) + (endpoint_pos (zero_lt_one.trans hw) _) (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le + have heff := effectiveWidth_pos (zero_lt_one.trans hw) htop hxi + have hlog : Real.log (1+effectiveWidth w top xi) ≤ xi := by + have he := Real.log_le_sub_one_of_pos (by positivity : 0 < 1+effectiveWidth w top xi) + linarith [effectiveWidth_le (zero_lt_one.trans hw) htop hxi] + refine ⟨sub_nonneg.mpr hh.1.le,?_⟩ + have hb := div_le_div_of_nonneg_right hlog (Real.log_pos hw).le + simp only [width,lower] at hwid ⊢ + linarith [hh.2] + +theorem whole_bin_of_exponent_band {w top xi B alpha beta : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + {p : ℕ} (hp : p ∈ sourcePrimeSet w top) + (hlo : alpha*B+xi/Real.log w ≤ primeExponent w p) + (hhi : primeExponent w p+xi/Real.log w ≤ beta*B) : + isolatedBin w top xi B alpha beta (label (zero_lt_one.trans hw) htop hxi p) := by + have hl := (source_left_error hw htop hxi hp).2 + have hu := (source_representative_error hw htop hxi hp).2 + change rightExponent w (lower w top xi _) (width w top xi _)-primeExponent w p ≤ _ at hu + exact ⟨by linarith,by linarith⟩ + +theorem isolated_bin_search {w top xi B alpha beta : ℝ} {b : Fin (binCount w top xi)} + (hb : isolatedBin w top xi B alpha beta b) (hscale : w^((1/4:ℝ)) ≤ alpha*B) : + ActualSourceTags.searchBin w (lower w top xi b) := hscale.trans hb.1 +end NumberTheoryLean.IsolatedBinGeometry + + + +namespace NumberTheoryLean.RepeatedBinGeometry +open _root_.Set FinitePathGeometry SourceStopPredicate +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem equal_label_exponent_distance {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + {p q : ℕ} (hp : p ∈ sourcePrimeSet w top) (hq : q ∈ sourcePrimeSet w top) + (hl : label (zero_lt_one.trans hw) htop hxi p=label (zero_lt_one.trans hw) htop hxi q) : + |primeExponent w p-primeExponent w q| ≤ xi/Real.log w := by + have hpe := source_representative_error hw htop hxi hp + have hqe := source_representative_error hw htop hxi hq + have he : representative w (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) p= + representative w (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) q := by + unfold representative + rw [hl] + rw [he] at hpe + exact abs_le.mpr ⟨by linarith [hpe.1,hpe.2,hqe.1,hqe.2],by linarith [hpe.1,hpe.2,hqe.1,hqe.2]⟩ + +theorem adjacent_ratio_slack {r x x' h : ℝ} (hr : 0 < r) (hx : 0 < x) + (hxx : x ≤ x') (hwidth : x'-x ≤ h) : + 0 ≤ (r/x-1)-(r/x'-1) ∧ (r/x-1)-(r/x'-1) ≤ (r/x')*h/x := by + have hx' : 0 < x' := hx.trans_le hxx + have he : (r/x-1)-(r/x'-1)=(r/x')*(x'-x)/x := by + field_simp [hx.ne',hx'.ne'] + ring + rw [he] + exact ⟨div_nonneg (mul_nonneg (div_pos hr hx').le (sub_nonneg.mpr hxx)) hx.le, + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hwidth (div_pos hr hx').le) hx.le⟩ + +theorem matched_repeat_interval (i : Side) {s t s' t' H mesh : ℝ} + (hs : |s-s'| ≤ mesh) (ht : |t-t'| ≤ mesh) + (hslack : t-(s-1) ≤ H) (hsupport : minRatio i s' ≤ t') : + t' ∈ Icc (minRatio i s') (minRatio i s'+H+2*mesh) := by + refine ⟨hsupport,?_⟩ + have hmin := minRatio_ge_sub_one i s' + linarith [(abs_le.mp hs).2,(abs_le.mp ht).1] +end NumberTheoryLean.RepeatedBinGeometry + + + +namespace NumberTheoryLean.BinReplacementOrder +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin + +theorem prime_order_replacement {w z xi : ℝ} (hw : 0 < w) (hwz : w < z) (hxi : 0 < xi) + (p p' q : ℕ) (hp : p ∈ sourcePrimeSet w z) (hp' : p' ∈ sourcePrimeSet w z) + (hq : q ∈ sourcePrimeSet w z) (he : label hw hwz hxi p' = label hw hwz hxi p) + (hne : label hw hwz hxi q ≠ label hw hwz hxi p) : + (p < q ↔ p' < q) ∧ (q < p ↔ q < p') := by + have bp := label_value_bounds hw hwz hxi ((mem_sourcePrimeSet hw hwz p).mp hp).2 + have bp' := label_value_bounds hw hwz hxi ((mem_sourcePrimeSet hw hwz p').mp hp').2 + have bq := label_value_bounds hw hwz hxi ((mem_sourcePrimeSet hw hwz q).mp hq).2 + rw [he] at bp' + have hs := bins_separated hw hwz hxi (label hw hwz hxi p) (label hw hwz hxi q) hne.symm + rcases hs with hs | hs + · have h1 : p < q := by exact_mod_cast (show (p:ℝ) ·) ↔ (pre++p'::tail).Pairwise (· > ·) := by + have hp := hall p (by simp) + have hother := unique_label_other (label hw hwz hxi) pre tail p hc + have hqall (q : ℕ) (hq : q ∈ pre++tail) : q ∈ sourcePrimeSet w z := by + apply hall q + simp only [List.mem_append,List.mem_cons] at hq ⊢ + tauto + have horder (q : ℕ) (hq : q ∈ pre++tail) := + prime_order_replacement hw hwz hxi p p' q hp hp' (hqall q hq) he (hother q hq) + simp only [List.pairwise_append,List.pairwise_cons] + constructor + · rintro ⟨hpre,htail,hcross⟩ + refine ⟨hpre,⟨?_,htail.2⟩,?_⟩ + · intro q hq + exact (horder q (by simp [hq])).2.mp (htail.1 q hq) + · intro q hq r hr + rcases List.mem_cons.mp hr with rfl | hr + · exact (horder q (by simp [hq])).1.mp (hcross q hq p (by simp)) + · exact hcross q hq r (by simp [hr]) + · rintro ⟨hpre,htail,hcross⟩ + refine ⟨hpre,⟨?_,htail.2⟩,?_⟩ + · intro q hq + exact (horder q (by simp [hq])).2.mpr (htail.1 q hq) + · intro q hq r hr + rcases List.mem_cons.mp hr with rfl | hr + · exact (horder q (by simp [hq])).1.mpr (hcross q hq p' (by simp)) + · exact hcross q hq r (by simp [hr]) + +theorem replacement_no_collision {n : ℕ} (label : ℕ → Fin n) (pre tail : List ℕ) (p p' : ℕ) + (hc : ((pre++p::tail).map label).count (label p) = 1) (he : label p' = label p) : + p' ∉ pre++tail := by + intro hp' + exact unique_label_other label pre tail p hc p' hp' he +end NumberTheoryLean.BinReplacementOrder + + + +namespace NumberTheoryLean.CrossingBandGeometry +open _root_.Set FinitePathGeometry FinitePathMeasures ArrivalKernelGeometry +open RegeneratingInverseBands + +noncomputable def crossingLower (H : ℝ) : ℝ := (3/10)*H +noncomputable def crossingUpper (H : ℝ) : ℝ := (11/10)*H +noncomputable def crossingWidth : ℝ := Real.log ((11:ℝ)/3) +noncomputable def crossingCenter (v H : ℝ) : ℝ := v-Real.log (crossingUpper H) + +theorem matched_gap_crossing {H r q d : ℝ} (_hH : 0 < H) (hr : 0 < r) (hq : 0 < q) + (hlo : H/3 < r) (hhi : r ≤ H) (hd : |Real.log r-Real.log q| ≤ d) + (he : Real.exp d ≤ 11/10) : q ∈ Icc (crossingLower H) (crossingUpper H) := by + have h := NearbyParentGeometry.log_gap_relative hr hq hd + have hl : r ≤ (11/10:ℝ)*q := h.1.trans (mul_le_mul_of_nonneg_right he hq.le) + have hu : q ≤ (11/10:ℝ)*r := h.2.trans (mul_le_mul_of_nonneg_right he hr.le) + exact ⟨by dsimp [crossingLower]; nlinarith,by dsimp [crossingUpper]; nlinarith⟩ + +theorem crossing_width_positive : 0 < crossingWidth := Real.log_pos (by norm_num) + +theorem crossing_cost_band {H : ℝ} (hH : 0 < H) (v : ℝ) (z : CostState) + (hz : gapValue v z ∈ Icc (crossingLower H) (crossingUpper H)) : + z.2 ∈ Icc (crossingCenter v H) (crossingCenter v H+crossingWidth) := by + have hlo : 0 < crossingLower H := by unfold crossingLower; positivity + have hhi : 0 < crossingUpper H := by unfold crossingUpper; positivity + have hl := Real.log_le_log hlo hz.1 + have hu := Real.log_le_log (Real.exp_pos (v-z.2)) hz.2 + change Real.log (crossingLower H) ≤ Real.log (Real.exp (v-z.2)) at hl + change Real.log (Real.exp (v-z.2)) ≤ Real.log (crossingUpper H) at hu + rw [Real.log_exp] at hl hu + have hwidth : Real.log (crossingUpper H)-Real.log (crossingLower H)=crossingWidth := by + unfold crossingWidth + rw [← Real.log_div hhi.ne' hlo.ne'] + congr 1 + dsimp [crossingUpper,crossingLower] + field_simp [hH.ne'] + constructor <;> dsimp [crossingCenter] <;> linarith +end NumberTheoryLean.CrossingBandGeometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/CrossingMeshRate.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CrossingMeshRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..c9469e1947d983d829235904bef7f166a99a9d62 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/CrossingMeshRate.lean @@ -0,0 +1,31 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialMesh + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CrossingMeshRate +open _root_.Filter ExponentialMesh +open scoped Topology + +theorem crossing_mesh_control {A κ : ℝ} (hA : 0 ≤ A) (hκ : 0 < κ) : + ∀ᶠ w : ℝ in atTop,∀ N : ℕ,(N:ℝ) ≤ A*(Real.log w)^3 → + Real.exp (4*(N:ℝ)*mesh κ w) ≤ 11/10 := by + have hp : 0 < Real.log (11/10:ℝ) := Real.log_pos (by norm_num) + filter_upwards [(log_power_exp_tendsto (4*A) 3 hκ).eventually (eventually_le_nhds hp), + Real.tendsto_log_atTop.eventually_ge_atTop 0] with w hh hlog + intro N hN + have hb : 4*(N:ℝ)*mesh κ w ≤ Real.log (11/10:ℝ) := by + calc + _ ≤ (4*A*(Real.log w)^3)*Real.exp (-κ*Real.sqrt (Real.log w)) := + mul_le_mul (by nlinarith) (mesh_upper κ w) (mesh_pos κ w).le (by positivity) + _ ≤ _ := hh + exact (Real.exp_le_exp.mpr hb).trans_eq (Real.exp_log (by norm_num)) +end NumberTheoryLean.CrossingMeshRate + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/DilationCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/DilationCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..03234e07b9683cbe03489821a9e8938fb41a06ef --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/DilationCoordinates.lean @@ -0,0 +1,155 @@ +import Mathlib.Data.ZMod.Units +import OAI.NumberTheory.Jacobsthal.Harmonic.FourierL1 + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +noncomputable def nonzeroFrequencies (N : ℕ) [NeZero N] : Finset (ZMod N) := + Finset.univ.filter (· ≠ 0) + +noncomputable def intervalLength (P : ProgressionInterval) : ℝ := P.right-P.left + +noncomputable def l1Norm (N : ℕ) [NeZero N] (P : ProgressionInterval) : ℝ := + ∑ h ∈ nonzeroFrequencies N, ‖P.weight N h‖ + +noncomputable def gcdL1Norm (N : ℕ) [NeZero N] (P : ProgressionInterval) : ℝ := + ∑ h ∈ nonzeroFrequencies N, ‖P.weight N h‖*Real.sqrt (Nat.gcd h.val N) + +theorem l1Norm_nonneg (N : ℕ) [NeZero N] (P : ProgressionInterval) : 0 ≤ l1Norm N P := by + unfold l1Norm + positivity + +theorem gcdL1Norm_nonneg (N : ℕ) [NeZero N] (P : ProgressionInterval) : 0 ≤ gcdL1Norm N P := by + unfold gcdL1Norm + positivity + +theorem l1Norm_le (N : ℕ) [NeZero N] (P : ProgressionInterval) (hP : P.step.Coprime N) : + l1Norm N P ≤ (2*ErdosHyperbola.harmonicConstant)*(N : ℝ)*Real.log (2*(N : ℝ)) := + ErdosHyperbola.intervalWeight_l1 N P.left P.right P.leftClosed P.rightClosed P.step P.residue P.step_pos hP + +theorem gcdL1Norm_le (N : ℕ) [NeZero N] (P : ProgressionInterval) (hP : P.step.Coprime N) : + gcdL1Norm N P ≤ (2*ErdosHyperbola.harmonicConstant)*(N : ℝ)*(N.divisors.card : ℝ)* + Real.log (2*(N : ℝ)) := + ErdosHyperbola.intervalWeight_gcd_l1 N P.left P.right P.leftClosed P.rightClosed P.step P.residue P.step_pos hP + +theorem intervalLength_nonneg (P : ProgressionInterval) (hP : P.left ≤ P.right) : + 0 ≤ intervalLength P := sub_nonneg.mpr hP + +theorem weight_zero_eq_count (N : ℕ) [NeZero N] (P : ProgressionInterval) : + P.weight N 0 = (P.points.card : ℂ) := + ErdosHyperbolaFourier.intervalWeight_zero N P.left P.right P.leftClosed P.rightClosed P.step P.residue + +theorem interval_count_error (P : ProgressionInterval) (hP : P.left ≤ P.right) : + |(P.points.card : ℝ)-intervalLength P/(P.step : ℝ)| ≤ 1 := + ErdosHyperbolaFourier.progressionPoints_count_error P.left P.right hP P.leftClosed P.rightClosed + P.step P.residue P.step_pos + +theorem interval_average_le_length (P : ProgressionInterval) (hP : P.left ≤ P.right) : + intervalLength P/(P.step : ℝ) ≤ intervalLength P := by + have hs : (0 : ℝ) < P.step := by exact_mod_cast P.step_pos + have hs1 : (1 : ℝ) ≤ P.step := by exact_mod_cast P.step_pos + apply (div_le_iff₀ hs).mpr + exact le_mul_of_one_le_right (intervalLength_nonneg P hP) hs1 + +theorem interval_count_le_length_add_one (P : ProgressionInterval) (hP : P.left ≤ P.right) : + (P.points.card : ℝ) ≤ intervalLength P+1 := by + have h := (abs_le.mp (interval_count_error P hP)).2 + have hu := interval_average_le_length P hP + linarith + +theorem norm_weight_zero_le (N : ℕ) [NeZero N] (P : ProgressionInterval) (hP : P.left ≤ P.right) : + ‖P.weight N 0‖ ≤ intervalLength P+1 := by + rw [weight_zero_eq_count] + simpa using interval_count_le_length_add_one P hP + +end ErdosHyperbolaError + +end + +section + +namespace ErdosHyperbolaError + +open ErdosHyperbolaIdentities + +theorem unit_mul_eq_iff {R : Type*} [CommRing R] (u : Rˣ) (x y : R) : + (u : R)*x = y ↔ x = (↑u⁻¹ : R)*y := by + constructor + · intro h + have hh := congrArg (fun z : R => (↑u⁻¹ : R)*z) h + rw [Units.inv_mul_cancel_left] at hh + exact hh + · intro h + rw [h, Units.mul_inv_cancel_left] + +noncomputable def inverseResidue (T l : ℕ) (hlT : l.Coprime T) (r : ℤ) : ℤ := + (((↑(ZMod.unitOfCoprime l hlT)⁻¹ : ZMod T)*(r : ZMod T)).val : ℕ) + +theorem inverseResidue_cast (T l : ℕ) [NeZero T] (hlT : l.Coprime T) (r : ℤ) : + (inverseResidue T l hlT r : ZMod T) = + (↑(ZMod.unitOfCoprime l hlT)⁻¹ : ZMod T)*(r : ZMod T) := by + simp only [inverseResidue, Int.cast_natCast, ZMod.natCast_zmod_val] + +theorem residue_dilation_iff (T l : ℕ) [NeZero T] (hlT : l.Coprime T) (r v : ℤ) : + Int.ModEq (T : ℤ) v (inverseResidue T l hlT r) ↔ Int.ModEq (T : ℤ) ((l : ℤ)*v) r := by + rw [← ZMod.intCast_eq_intCast_iff, ← ZMod.intCast_eq_intCast_iff, inverseResidue_cast, + Int.cast_mul, Int.cast_natCast, ← ZMod.coe_unitOfCoprime l hlT] + exact (unit_mul_eq_iff (ZMod.unitOfCoprime l hlT) (v : ZMod T) (r : ZMod T)).symm + +noncomputable def pulledInterval (P : ProgressionInterval) (l : ℕ) (hlT : l.Coprime P.step) : + ProgressionInterval where + left := P.left/(l : ℝ) + right := P.right/(l : ℝ) + leftClosed := P.leftClosed + rightClosed := P.rightClosed + step := P.step + residue := inverseResidue P.step l hlT P.residue + step_pos := P.step_pos + +theorem pulledInterval_length (P : ProgressionInterval) (l : ℕ) (hlT : l.Coprime P.step) : + intervalLength (pulledInterval P l hlT) = intervalLength P/(l : ℝ) := by + unfold intervalLength pulledInterval + ring + +theorem pulledInterval_ordered (P : ProgressionInterval) (hP : P.left ≤ P.right) + (l : ℕ) (hl : 0 < l) (hlT : l.Coprime P.step) : + (pulledInterval P l hlT).left ≤ (pulledInterval P l hlT).right := + div_le_div_of_nonneg_right hP (by exact_mod_cast hl.le) + +theorem mem_pulledInterval_iff (P : ProgressionInterval) (l : ℕ) (hl : 0 < l) + (hlT : l.Coprime P.step) (v : ℤ) : + v ∈ (pulledInterval P l hlT).points ↔ ((l : ℤ)*v) ∈ P.points := by + let : NeZero P.step := ⟨P.step_pos.ne'⟩ + have hlR : (0 : ℝ) < l := by exact_mod_cast hl + rw [mem_interval_points, mem_interval_points] + dsimp only [pulledInterval] + rw [residue_dilation_iff] + by_cases hlc : P.leftClosed = true <;> by_cases hrc : P.rightClosed = true <;> + simp [hlc, hrc, Int.cast_mul, Int.cast_natCast, div_le_iff₀ hlR, div_lt_iff₀ hlR, + le_div_iff₀ hlR, lt_div_iff₀ hlR, mul_comm] + +def dilatePair (l : ℕ) (xy : ℤ × ℤ) : ℤ × ℤ := ((l : ℤ)*xy.1,xy.2) + +theorem dilatePair_injective (l : ℕ) (hl : 0 < l) : Function.Injective (dilatePair l) := by + rintro ⟨x,y⟩ ⟨z,w⟩ he + have hx := congrArg Prod.fst he + have hy := congrArg Prod.snd he + apply Prod.ext + · exact mul_left_cancel₀ (by exact_mod_cast hl.ne' : (l : ℤ) ≠ 0) hx + · exact hy + +end ErdosHyperbolaError + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/EdgeBinBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EdgeBinBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..ecc8c1625d19fdec1fd62cbdb5601e2eb3a2d85e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EdgeBinBounds.lean @@ -0,0 +1,56 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeBinRationalList + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseSaving +open ErdosInversePrimeBin + +noncomputable def edgeFrequencyCap (U : ℝ) : ℕ := ⌈2*U⌉₊ + +theorem edgeFrequencyCap_le (U : ℝ) (hU : 1 ≤ U) : (edgeFrequencyCap U : ℝ) ≤ 3*U := by + have hh := Nat.ceil_lt_add_one (show 0 ≤ 2*U by linarith) + change (⌈2*U⌉₊ : ℝ) ≤ 3*U + linarith + +theorem edge_prime_le_cap (U theta : ℝ) (hU : 0 ≤ U) (htheta : 0 ≤ theta) + (htheta1 : theta ≤ 1) (u : ℕ) (hu : u ∈ primeBin U theta) : u ≤ edgeFrequencyCap U := by + have htop := ((mem_primeBin hU htheta u).mp hu).2.2 + have huR : (u : ℝ) ≤ 2*U := htop.trans (by nlinarith) + exact_mod_cast huR.trans (Nat.le_ceil (2*U)) + +theorem uniform_edge_bin_count (xi : ℝ) (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ ∀ U theta : ℝ,w ≤ U → xi/4 ≤ theta → theta ≤ xi → + xi*U/(16*Real.log U) ≤ ((primeBin U theta).card : ℝ) ∧ 0 < (primeBin U theta).card := by + obtain ⟨U0,hU0⟩ := eventually_atTop.mp (uniform_prime_bin_count (by positivity : 0 < xi/4)) + filter_upwards [eventually_ge_atTop (max 2 U0)] with w hw + have hw2 : 2 ≤ w := (le_max_left _ _).trans hw + refine ⟨hw2,?_⟩ + intro U theta hwU htlow hthigh + have hU2 : 2 ≤ U := hw2.trans hwU + have hUpos : 0 < U := by linarith + have hlog : 0 < Real.log U := Real.log_pos (by linarith) + have hc := ((hU0 U (((le_max_right _ _).trans hw).trans hwU)).2 theta htlow (hthigh.trans hxi1)).1 + have hlow : xi*U/(16*Real.log U) ≤ ((primeBin U theta).card : ℝ) := by + calc + _ = (xi/4)*U/(4*Real.log U) := by ring + _ ≤ theta*U/(4*Real.log U) := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right htlow hUpos.le) (by positivity) + _ ≤ _ := hc + refine ⟨hlow,?_⟩ + have hh : (0 : ℝ) < (primeBin U theta).card := (by positivity : 0 < xi*U/(16*Real.log U)).trans_le hlow + exact_mod_cast hh + +end ErdosInverseSaving + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCommonInterval.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCommonInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..943c739a2937444f0fe7d64cafc068910907fce0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCommonInterval.lean @@ -0,0 +1,76 @@ +import OAI.NumberTheory.Jacobsthal.Primes.SmallEffectivePrimeSplit + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceCommon +open ErdosVarianceEffective ErdosInverseTail ErdosInverseHits + +noncomputable def commonLength (Y qf : ℕ) (R xi : ℝ) : ℕ := + commonParentLength Y qf ((1+xi)*R) + +theorem bin_upper_comparison (R xi : ℝ) (_hR : 0 < R) (hxi : 0 ≤ xi) + (p : ℕ) (hbin : R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) : + (p : ℝ) ≤ (1+xi)*R ∧ (1+xi)*R ≤ (1+xi)*(p : ℝ) := + ⟨hbin.2,mul_le_mul_of_nonneg_left hbin.1.le (by linarith)⟩ + +theorem commonLength_le_effective (Y : ℕ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) + (R xi : ℝ) (hR : 0 < R) (hxi : 0 ≤ xi) + (hbin : R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) : + commonLength Y qf R xi ≤ hitLength Y (p*qf) (effectiveBase a r qf p hHp) := by + have hb := (effective_initial_bounds a r qf hq p hHp).2 + have hh := commonParentLength_le_hits Y qf p (effectiveBase a r qf p hHp) + (Nat.pos_of_ne_zero hq.ne_zero) (Nat.pos_of_ne_zero (NeZero.ne p)) (by simpa only [effectiveBase,Nat.mul_comm] using hb) + ((1+xi)*R) (bin_upper_comparison R xi hR hxi p hbin).1 + simpa only [commonLength,Nat.mul_comm] using hh + +theorem commonLength_tail_bound (Y : ℕ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) + (R xi : ℝ) (hR : 0 < R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hbin : R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) : + ((hitLength Y (p*qf) (effectiveBase a r qf p hHp)-commonLength Y qf R xi : ℕ) : ℝ) ≤ + xi*(commonLength Y qf R xi : ℝ)+3 := by + have hb := effective_initial_bounds a r qf hq p hHp + have hcomp := bin_upper_comparison R xi hR hxi p hbin + have hh := actual_cell_tail_length Y qf p (effectiveBase a r qf p hHp) + (Nat.pos_of_ne_zero hq.ne_zero) (Nat.pos_of_ne_zero (NeZero.ne p)) hb.1 + (by simpa only [effectiveBase,Nat.mul_comm] using hb.2) ((1+xi)*R) xi hxi hxi1 hcomp.1 hcomp.2 + simpa only [commonLength,Nat.mul_comm] using hh + +theorem commonLength_reference_bounds (Y qf p : ℕ) (hq : 0 < qf) (hp : 0 < p) + (R xi : ℝ) (hR : 0 < R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hbin : R < (p : ℝ) ∧ (p : ℝ) ≤ (1+xi)*R) : + (commonLength Y qf R xi : ℝ) ≤ (Y : ℝ)/((p : ℝ)*qf) ∧ + (Y : ℝ)/((p : ℝ)*qf)-(commonLength Y qf R xi : ℝ) ≤ + xi*(commonLength Y qf R xi : ℝ)+2 := by + have hqR : (0 : ℝ) < qf := by exact_mod_cast hq + have hpR : (0 : ℝ) < p := by exact_mod_cast hp + have hU : 0 < (1+xi)*R := by positivity + have hratio : 0 ≤ (Y : ℝ)/((qf : ℝ)*((1+xi)*R)) := by positivity + have hfloor : (commonLength Y qf R xi : ℝ) ≤ (Y : ℝ)/((qf : ℝ)*((1+xi)*R)) := Nat.floor_le hratio + have hfloorHi : (Y : ℝ)/((qf : ℝ)*((1+xi)*R)) < (commonLength Y qf R xi : ℝ)+1 := Nat.lt_floor_add_one _ + have hcomp := bin_upper_comparison R xi hR hxi p hbin + have hdiv : (Y : ℝ)/((qf : ℝ)*((1+xi)*R)) ≤ (Y : ℝ)/((p : ℝ)*qf) := + div_le_div_of_nonneg_left (Nat.cast_nonneg _) (by positivity) (by nlinarith) + have hinfl : (Y : ℝ)/((p : ℝ)*qf) ≤ (1+xi)*((Y : ℝ)/((qf : ℝ)*((1+xi)*R))) := by + have hf : ((1+xi)*R)/(p : ℝ) ≤ 1+xi := (div_le_iff₀ hpR).mpr hcomp.2 + calc + _ = ((Y : ℝ)/((qf : ℝ)*((1+xi)*R)))*(((1+xi)*R)/(p : ℝ)) := by field_simp + _ ≤ ((Y : ℝ)/((qf : ℝ)*((1+xi)*R)))*(1+xi) := mul_le_mul_of_nonneg_left hf hratio + _ = _ := by ring + refine ⟨hfloor.trans hdiv,?_⟩ + have hh := mul_le_mul_of_nonneg_left hfloorHi.le (show 0 ≤ 1+xi by linarith) + nlinarith + +end ErdosVarianceCommon + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCoordinateUnits.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCoordinateUnits.lean new file mode 100644 index 0000000000000000000000000000000000000000..c316c3754f8418597b326c8536adcfdefbbde2e2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCoordinateUnits.lean @@ -0,0 +1,35 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualEffectiveWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective + +theorem actual_m0_coprime (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : + (intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf)).natAbs.Coprime + (effectiveModulus a r qf) := by + apply Nat.coprime_of_dvd + intro t ht htm htH + have htm' : (t : ℤ) ∣ intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) := + Int.natCast_dvd.mpr htm + have htH' : (t : ℤ) ∣ (effectiveModulus a r qf : ℤ) := by exact_mod_cast htH + have hdiff := (intervalM0_modEq p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf)).dvd + have hC : (t : ℤ) ∣ effectiveIntercept a r qf := by + have ha := dvd_add (htH'.trans hdiff) (dvd_mul_of_dvd_right htm' (p : ℤ)) + simpa only [sub_add_cancel] using ha + have hdiv := Nat.dvd_gcd (Int.natCast_dvd.mp hC) htH + rw [(effectiveIntercept_coprime a r qf hq).gcd_eq_one] at hdiv + exact ht.not_dvd_one hdiv + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..c5c35f6ddca404f3681d1065e71212c6d155e8a6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EffectiveCoordinates.lean @@ -0,0 +1,66 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.EffectiveNumerator + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective +open ErdosInverseAlignment ErdosPrimitiveIntercept ErdosInverseCells + +noncomputable def effectiveModulus (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) : ℕ := + r.den*badPrimeProduct (fun t => (a t : ℤ)) r qf + +noncomputable def effectiveIntercept (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) : ℤ := + hitNumerator a r qf/(alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ) + +theorem effectiveModulus_pos (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) : 0 < effectiveModulus a r qf := + Nat.mul_pos r.pos (badPrimeProduct_pos _ r qf) + +theorem effectiveIntercept_identity (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ)*effectiveIntercept a r qf = hitNumerator a r qf := by + rw [effectiveIntercept,mul_comm] + exact Int.ediv_mul_cancel (alignedCofactor_dvd_hitNumerator a r qf hq) + +theorem hitNumerator_coprime_effectiveModulus (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (hitNumerator a r qf).natAbs.Coprime (effectiveModulus a r qf) := + (hitNumerator_coprime_den a r qf).mul_right (hitNumerator_coprime_bad a r qf hq) + +theorem effectiveIntercept_coprime (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (effectiveIntercept a r qf).natAbs.Coprime (effectiveModulus a r qf) := by + have hdiv : effectiveIntercept a r qf ∣ hitNumerator a r qf := by + refine ⟨(alignedCofactor (fun t => (a t : ℤ)) r qf : ℤ),?_⟩ + rw [mul_comm] + exact (effectiveIntercept_identity a r qf hq).symm + exact (hitNumerator_coprime_effectiveModulus a r qf hq).of_dvd_left + (Int.natAbs_dvd_natAbs.mpr hdiv) + +theorem effective_coordinates_gcd (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + Int.gcd (effectiveIntercept a r qf) (effectiveModulus a r qf : ℤ) = 1 := by + simpa only [Int.gcd_def,Int.natAbs_natCast] using (effectiveIntercept_coprime a r qf hq).gcd_eq_one + +theorem zero_effectiveIntercept_modulus_one (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (hzero : effectiveIntercept a r qf = 0) : effectiveModulus a r qf = 1 := by + have hh := effective_coordinates_gcd a r qf hq + simpa only [hzero,Int.gcd_zero_left,Int.natAbs_natCast] using hh + +theorem alignedCofactor_coprime_effectiveModulus (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + (alignedCofactor (fun t => (a t : ℤ)) r qf).Coprime (effectiveModulus a r qf) := + (alignedCofactor_coprime_den _ r qf hq).mul_right (alignedCofactor_coprime_bad _ r qf hq) + +theorem denominator_full_cofactor (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) : + r.den*qf = alignedCofactor (fun t => (a t : ℤ)) r qf*effectiveModulus a r qf := by + calc + _ = r.den*(alignedCofactor (fun t => (a t : ℤ)) r qf*badPrimeProduct (fun t => (a t : ℤ)) r qf) := + congrArg (fun x : ℕ => r.den*x) (alignedCofactor_mul_bad (fun t => (a t : ℤ)) r qf hq).symm + _ = _ := by unfold effectiveModulus;ring + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/EligibleBoxLists.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EligibleBoxLists.lean new file mode 100644 index 0000000000000000000000000000000000000000..915a7a71588f990621f77e4547440acdfc1120ac --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EligibleBoxLists.lean @@ -0,0 +1,46 @@ +import OAI.NumberTheory.Jacobsthal.Paths.RawBoxRationalWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.EligibleBoxLists +open ActualBinOwners LogarithmicBinScale + +attribute [local instance] Classical.propDecidable + +noncomputable def eligibleLists {n : ℕ} (Y w Cs : ℝ) (M : Finset (Fin n → ℕ)) + (Q : (Fin n → ℕ) → Finset ℚ) (m : Fin n → ℕ) : Finset ℚ := + if m∈M then (Q m).filter (eligible Y w Cs) else ∅ + +theorem mem_eligibleLists {n : ℕ} (Y w Cs : ℝ) (M : Finset (Fin n → ℕ)) + (Q : (Fin n → ℕ) → Finset ℚ) (m : Fin n → ℕ) (q : ℚ) : + q∈eligibleLists Y w Cs M Q m ↔ m∈M ∧ q∈Q m ∧ eligible Y w Cs q := by + by_cases hm : m∈M <;> simp [eligibleLists,hm] + +theorem eligibleLists_card {n : ℕ} (Y w Cs : ℝ) (M : Finset (Fin n → ℕ)) + (Q : (Fin n → ℕ) → Finset ℚ) (NQ : ℕ) (hQ : ∀ m∈M,(Q m).card ≤ NQ) : + ∀ m,(eligibleLists Y w Cs M Q m).card ≤ NQ := by + intro m + by_cases hm : m∈M + · simpa only [eligibleLists,ite_eq_left hm] using (Finset.card_filter_le (Q m) _).trans (hQ m hm) + · simp [eligibleLists,hm] + +theorem eligibleLists_eligible {n : ℕ} (Y w Cs : ℝ) (M : Finset (Fin n → ℕ)) + (Q : (Fin n → ℕ) → Finset ℚ) : + ∀ m,∀ q∈eligibleLists Y w Cs M Q m,eligible Y w Cs q := by + intro m q hq + exact ((mem_eligibleLists Y w Cs M Q m q).mp hq).2.2 + +theorem soft_witness_in_eligibleLists {n : ℕ} (Y w Cs : ℝ) (M : Finset (Fin n → ℕ)) + (Q : (Fin n → ℕ) → Finset ℚ) (m : Fin n → ℕ) (hm : m∈M) (q : ℚ) + (hq : q∈Q m) (helig : eligible Y w Cs q) : q∈eligibleLists Y w Cs M Q m := + (mem_eligibleLists Y w Cs M Q m q).mpr ⟨hm,hq,helig⟩ +end NumberTheoryLean.EligibleBoxLists + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/EvenThresholdGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EvenThresholdGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..372742c40b7052728171f04d99a892920076bf7a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/EvenThresholdGeometry.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Probability.FirstHitKernels + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosEvenThreshold +open Set NumberTheoryLean.FinitePathGeometry + +noncomputable def thresholdSlack (R t : ℝ) : ℝ := + nextGap R t-max (2*nextExponent R t) (nextExponent R t+2) +noncomputable def thresholdStrip (R d : ℝ) : Set ℝ := + {t | 2 ≤ t ∧ 1 < nextExponent R t ∧ 0 ≤ thresholdSlack R t ∧ thresholdSlack R t ≤ d} + +theorem gap_eq_exponent_mul (R t : ℝ) : nextGap R t=nextExponent R t*t := by + unfold nextGap nextExponent + ring + +theorem exponent_mul_add_one {R t : ℝ} (ht : 0 < t+1) : nextExponent R t*(t+1)=R := by + unfold nextExponent + field_simp + +theorem strip_parameters {R d t : ℝ} (hd : d ≤ 1) (ht : t ∈ thresholdStrip R d) : + 4 < R ∧ t ≤ 4 := by + obtain ⟨ht2,hx,hlo,hhi⟩ := ht + have hcons := gap_exponent_conservation (r:=R) (show 0 < t by linarith) + have hm := gap_eq_exponent_mul R t + have hlow := le_max_right (2*nextExponent R t) (nextExponent R t+2) + have hmax : max (2*nextExponent R t) (nextExponent R t+2) ≤ 3*nextExponent R t := + max_le (by linarith) (by linarith) + unfold thresholdSlack at hlo hhi + constructor + · linarith + · have hprod : nextExponent R t*t ≤ nextExponent R t*4 := by nlinarith + exact le_of_mul_le_mul_left hprod (by linarith : 0 < nextExponent R t) + +noncomputable def firstUpper (R d : ℝ) : ℝ := 2+4*d/R +noncomputable def secondLower (R : ℝ) : ℝ := (R+2)/(R-2) +noncomputable def secondUpper (R d : ℝ) : ℝ := (R+2+d)/(R-2-d) + +theorem strip_mem_cover {R d t : ℝ} (hd0 : 0 ≤ d) (hd1 : d ≤ 1) + (ht : t ∈ thresholdStrip R d) : + t ∈ Icc 2 (firstUpper R d) ∪ Icc (secondLower R) (secondUpper R d) := by + have hR := (strip_parameters hd1 ht).1 + have hR0 : 0 < R := by linarith + obtain ⟨ht2,hx,hlo,hhi⟩ := ht + have htpos : 0 < t+1 := by linarith + have hxpos : 0 < nextExponent R t := by linarith + have hm := gap_eq_exponent_mul R t + have hxR := exponent_mul_add_one (R:=R) htpos + unfold thresholdSlack at hlo hhi + by_cases hb : nextExponent R t+2 ≤ 2*nextExponent R t + · rw [max_eq_left hb] at hlo hhi + have hs : nextExponent R t*(t-2) ≤ d := by nlinarith + have ht3 : t ≤ 3 := by + have hh : nextExponent R t*t ≤ nextExponent R t*3 := by nlinarith + exact le_of_mul_le_mul_left hh hxpos + have hbound : t-2 ≤ 4*d/R := by + apply (le_div_iff₀ hR0).mpr + calc + (t-2)*R=(nextExponent R t*(t-2))*(t+1) := by + conv_lhs => rw [← hxR] + ring + _ ≤ d*(t+1) := mul_le_mul_of_nonneg_right hs htpos.le + _ ≤ d*4 := mul_le_mul_of_nonneg_left (by linarith : t+1 ≤ 4) hd0 + _ = _ := by ring + exact Or.inl ⟨ht2,by unfold firstUpper; linarith⟩ + · have hb' : 2*nextExponent R t ≤ nextExponent R t+2 := (lt_of_not_ge hb).le + rw [max_eq_right hb'] at hlo hhi + have he : (nextGap R t-nextExponent R t)*(t+1)=R*(t-1) := by + rw [hm] + calc + _ = (nextExponent R t*(t+1))*(t-1) := by ring + _ = _ := by rw [hxR] + have hlow : 2*(t+1) ≤ (nextGap R t-nextExponent R t)*(t+1) := + mul_le_mul_of_nonneg_right (by linarith) htpos.le + have hhigh : (nextGap R t-nextExponent R t)*(t+1) ≤ (2+d)*(t+1) := + mul_le_mul_of_nonneg_right (by linarith) htpos.le + rw [he] at hlow hhigh + apply Or.inr + constructor + · apply (div_le_iff₀ (show 0 < R-2 by linarith)).mpr + nlinarith + · apply (le_div_iff₀ (show 0 < R-2-d by linarith)).mpr + nlinarith + +end ErdosEvenThreshold + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiberCardinalityConstancy.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiberCardinalityConstancy.lean new file mode 100644 index 0000000000000000000000000000000000000000..b47cf3c5030fb89e552abafbf9514037b7c68da3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiberCardinalityConstancy.lean @@ -0,0 +1,299 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Estimates.LocalGraphIff +import OAI.NumberTheory.Jacobsthal.Estimates.NestedDegreeBounds + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosGlobalFiberBranches + +noncomputable def orderIsoOfNatCardEq (α β : Type*) [LinearOrder α] [LinearOrder β] + [Finite α] [Finite β] (h : Nat.card α = Nat.card β) : α ≃o β := by + letI := Fintype.ofFinite α + letI := Fintype.ofFinite β + exact (Fintype.orderIsoFinOfCardEq α rfl).symm.trans + (Fintype.orderIsoFinOfCardEq β (by simpa only [Nat.card_eq_fintype_card] using h.symm)) + +theorem finite_orderIso_unique {α β : Type*} [LinearOrder α] [LinearOrder β] + [Finite α] (f g : α ≃o β) : f = g := Subsingleton.elim f g + +noncomputable def orderIsoOfStrictMonoSurjective {α β : Type*} + [LinearOrder α] [LinearOrder β] (f : α → β) (hf : StrictMono f) + (hs : Function.Surjective f) : α ≃o β := + { Equiv.ofBijective f ⟨hf.injective,hs⟩ with map_rel_iff' := hf.le_iff_le } + +theorem orderIsoOfStrictMonoSurjective_apply {α β : Type*} + [LinearOrder α] [LinearOrder β] (f : α → β) (hf : StrictMono f) + (hs : Function.Surjective f) (a : α) : + orderIsoOfStrictMonoSurjective f hf hs a = f a := rfl + +end ErdosGlobalFiberBranches + +end + +section + +open Filter Set +open scoped Topology ContDiff +namespace ErdosLocalFiberGraphs +open ErdosImplicitCurvature + +structure FiberCharts (Q : Bivariate) (x L U : ℝ) where + a : ℝ + b : ℝ + left : a < x + right : x < b + finite_base : (boundedFiber Q x L U).Finite + graph : boundedFiber Q x L U → ℝ → ℝ + tube : boundedFiber Q x L U → Set ℝ + tube_open : ∀ r, IsOpen (tube r) + tube_base : ∀ r, (r : ℝ) ∈ tube r + tube_interior : ∀ r, tube r ⊆ Ioo L U + tube_disjoint : Pairwise fun r s => Disjoint (tube r) (tube s) + graph_base : ∀ r, graph r x = r + graph_smooth : ∀ r, ContDiffOn ℝ 2 (graph r) (Ioo a b) + graph_inside : ∀ r, ∀ t ∈ Ioo a b, graph r t ∈ tube r + graph_regular : ∀ r, ∀ t ∈ Ioo a b, peval (partialY Q) t (graph r t) ≠ 0 + zero_iff : ∀ r, ∀ t ∈ Ioo a b, ∀ y ∈ tube r, peval Q t y = 0 ↔ y = graph r t + coverage : ∀ t ∈ Ioo a b, boundedFiber Q t L U = range (fun r => graph r t) + ordered : ∀ t ∈ Ioo a b, StrictMono (fun r => graph r t) + +theorem exists_bounded_fiber_charts (Q : Bivariate) (x L U : ℝ) + (hL : peval Q x L ≠ 0) (hU : peval Q x U ≠ 0) + (hregular : ∀ y ∈ boundedFiber Q x L U, peval (partialY Q) x y ≠ 0) : + Nonempty (FiberCharts Q x L U) := by + classical + let R := boundedFiber Q x L U + have hR : R.Finite := boundedFiber_finite Q x L U L hL + let : Fintype R := hR.fintype + obtain ⟨V,hV,hsep⟩ := hR.t2_separation + have hcharts (r : R) := exists_local_graph_iff Q x r r.property.2 + (hregular r r.property) (V r ∩ Ioo L U) ((hV r).2.inter isOpen_Ioo) + ⟨(hV r).1,boundedFiber_interior Q x L U hL hU r.property⟩ + choose a b W f ha hb hWo hrW hWV hbase hC hmem hder hiff using hcharts + have hWint (r : R) : W r ⊆ Ioo L U := fun y hy => (hWV r hy).2 + have hWd : Pairwise fun r s : R => Disjoint (W r) (W s) := by + intro r s hrs + apply (hsep r.property s.property (fun he => hrs (Subtype.ext he))).mono + · exact fun y hy => (hWV r hy).1 + · exact fun y hy => (hWV s hy).1 + let K := Icc L U \ ⋃ r : R, W r + have hK : IsCompact K := isCompact_Icc.diff (isOpen_iUnion hWo) + have hKzero : ∀ y ∈ K, peval Q x y ≠ 0 := by + intro y hy hzero + have hyR : y ∈ R := ⟨hy.1,hzero⟩ + exact hy.2 (mem_iUnion.mpr ⟨⟨y,hyR⟩,hrW ⟨y,hyR⟩⟩) + have hnoextra := compact_nonzero_eventually Q x K hK hKzero + have hdomains : ∀ᶠ t in 𝓝 x, ∀ r : R, t ∈ Ioo (a r) (b r) := + eventually_all.mpr fun r => isOpen_Ioo.mem_nhds ⟨ha r,hb r⟩ + have hcont (r : R) : ContinuousAt (f r) x := + (hC r).continuousOn.continuousAt (isOpen_Ioo.mem_nhds ⟨ha r,hb r⟩) + have horder : ∀ᶠ t in 𝓝 x, ∀ r s : R, r < s → f r t < f s t := by + apply eventually_all.mpr + intro r + apply eventually_all.mpr + intro s + by_cases hrs : r < s + · have hlt : f r x < f s x := by simpa only [hbase] using (show (r : ℝ) < (s : ℝ) from hrs) + exact ((hcont r).eventually_lt (hcont s) hlt).mono fun t ht _ => ht + · exact Eventually.of_forall fun t ht => (hrs ht).elim + have hN : {t | (∀ r : R, t ∈ Ioo (a r) (b r)) ∧ + (∀ y ∈ K, peval Q t y ≠ 0) ∧ (∀ r s : R, r < s → f r t < f s t)} ∈ 𝓝 x := + hdomains.and (hnoextra.and horder) + obtain ⟨eps,heps,hball⟩ := Metric.mem_nhds_iff.mp hN + have hs : Ioo (x-eps) (x+eps) ⊆ {t | (∀ r : R, t ∈ Ioo (a r) (b r)) ∧ + (∀ y ∈ K, peval Q t y ≠ 0) ∧ (∀ r s : R, r < s → f r t < f s t)} := by + simpa only [Real.ball_eq_Ioo] using hball + refine ⟨{ + a := x-eps + b := x+eps + left := by linarith + right := by linarith + finite_base := hR, graph := f, tube := W, tube_open := hWo, tube_base := hrW, + tube_interior := hWint, tube_disjoint := hWd, graph_base := hbase, + graph_smooth := fun r => (hC r).mono (fun t ht => (hs ht).1 r), + graph_inside := fun r t ht => hmem r t ((hs ht).1 r), + graph_regular := fun r t ht => hder r t ((hs ht).1 r), + zero_iff := fun r t ht => hiff r t ((hs ht).1 r), + coverage := ?_, ordered := fun t ht => (hs ht).2.2 }⟩ + intro t ht + ext y + constructor + · intro hy + have hyW : y ∈ ⋃ r : R, W r := by + by_contra hn + exact (hs ht).2.1 y ⟨hy.1,hn⟩ hy.2 + obtain ⟨r,hyr⟩ := mem_iUnion.mp hyW + exact ⟨r,((hiff r t ((hs ht).1 r) y hyr).mp hy.2).symm⟩ + · rintro ⟨r,rfl⟩ + have hfW := hmem r t ((hs ht).1 r) + exact ⟨Ioo_subset_Icc_self (hWint r hfW), + (hiff r t ((hs ht).1 r) (f r t) hfW).mpr rfl⟩ + +end ErdosLocalFiberGraphs + +end + +section + +open Set +namespace ErdosGlobalFiberBranches +open ErdosImplicitCurvature ErdosLocalFiberGraphs + +noncomputable def chartOrderIso {Q : Bivariate} {x L U : ℝ} + (c : FiberCharts Q x L U) (t : ℝ) (ht : t ∈ Ioo c.a c.b) : + boundedFiber Q x L U ≃o boundedFiber Q t L U := by + let f : boundedFiber Q x L U → boundedFiber Q t L U := fun r => + ⟨c.graph r t,by rw [c.coverage t ht]; exact mem_range_self r⟩ + apply orderIsoOfStrictMonoSurjective f + · exact fun r s hrs => (c.ordered t ht) hrs + · intro y + have hy := (c.coverage t ht).subset y.property + obtain ⟨r,hr⟩ := hy + exact ⟨r,Subtype.ext hr⟩ + +theorem chartOrderIso_val {Q : Bivariate} {x L U : ℝ} + (c : FiberCharts Q x L U) (t : ℝ) (ht : t ∈ Ioo c.a c.b) + (r : boundedFiber Q x L U) : (chartOrderIso c t ht r : ℝ) = c.graph r t := rfl + +end ErdosGlobalFiberBranches + +end + +section + +open Set Filter +open scoped Topology +namespace ErdosLocalFiberGraphs +open ErdosImplicitCurvature ErdosCriticalGeometry + +theorem boundedFiber_card_le_degree (Q : Bivariate) (x L U z : ℝ) + (hz : peval Q x z ≠ 0) : (boundedFiber Q x L U).ncard ≤ Q.totalDegree := by + classical + have hf := boundedFiber_finite Q x L U z hz + have hp : verticalPolynomial Q x ≠ 0 := by + intro he + apply hz + rw [← verticalPolynomial_eval,he,Polynomial.eval_zero] + calc + (boundedFiber Q x L U).ncard = hf.toFinset.card := ncard_eq_toFinset_card _ hf + _ ≤ (verticalPolynomial Q x).natDegree := Polynomial.card_le_degree_of_subset_roots (by + intro y hy + apply (Polynomial.mem_roots hp).mpr + change (verticalPolynomial Q x).eval y = 0 + exact (verticalPolynomial_eval Q x y).trans (hf.mem_toFinset.mp hy).2) + _ ≤ (nestedY ℝ Q).natDegree := Polynomial.natDegree_map_le + _ ≤ Q.totalDegree := nestedY_degree_le ℝ Q + +namespace FiberCharts +variable {Q : Bivariate} {x L U : ℝ} (c : FiberCharts Q x L U) + +theorem fiber_finite {t : ℝ} (ht : t ∈ Ioo c.a c.b) : + (boundedFiber Q t L U).Finite := by + let := c.finite_base.fintype + rw [c.coverage t ht] + exact finite_range _ + +theorem fiber_card_eq {t : ℝ} (ht : t ∈ Ioo c.a c.b) : + (boundedFiber Q t L U).ncard = (boundedFiber Q x L U).ncard := by + rw [c.coverage t ht,ncard_range_of_injective (c.ordered t ht).injective, + Nat.card_coe_set_eq] + +theorem unique_root_in_tube (r : boundedFiber Q x L U) {t : ℝ} + (ht : t ∈ Ioo c.a c.b) : + ∃! y, y ∈ c.tube r ∧ peval Q t y = 0 := by + refine ⟨c.graph r t,⟨c.graph_inside r t ht,?_⟩,?_⟩ + · exact (c.zero_iff r t ht _ (c.graph_inside r t ht)).mpr rfl + · exact fun y hy => (c.zero_iff r t ht y hy.1).mp hy.2 + +theorem all_roots_regular {t : ℝ} (ht : t ∈ Ioo c.a c.b) : + ∀ y ∈ boundedFiber Q t L U, peval (partialY Q) t y ≠ 0 := by + intro y hy + rw [c.coverage t ht] at hy + obtain ⟨r,rfl⟩ := hy + exact c.graph_regular r t ht +end FiberCharts + +theorem locally_constant_fiber_card (Q : Bivariate) (x L U : ℝ) + (hL : peval Q x L ≠ 0) (hU : peval Q x U ≠ 0) + (hregular : ∀ y ∈ boundedFiber Q x L U, peval (partialY Q) x y ≠ 0) : + ∃ a b : ℝ, a < x ∧ x < b ∧ ∀ t ∈ Ioo a b, + (boundedFiber Q t L U).Finite ∧ + (boundedFiber Q t L U).ncard = (boundedFiber Q x L U).ncard := by + obtain ⟨c⟩ := exists_bounded_fiber_charts Q x L U hL hU hregular + exact ⟨c.a,c.b,c.left,c.right,fun t ht => ⟨c.fiber_finite ht,c.fiber_card_eq ht⟩⟩ + +end ErdosLocalFiberGraphs + +end + +section + +open Set Filter +open scoped Topology +namespace ErdosLocalFiberGraphs +open ErdosImplicitCurvature ErdosDivisibleInflection + +def regularParameters (Q : Bivariate) (L U : ℝ) : Set ℝ := + {x | peval Q x L ≠ 0 ∧ peval Q x U ≠ 0 ∧ + ∀ y ∈ boundedFiber Q x L U, peval (partialY Q) x y ≠ 0} + +theorem continuous_horizontal_eval (Q : Bivariate) (y : ℝ) : + Continuous (fun t => peval Q t y) := by + change Continuous (planeEval Q ∘ (fun t : ℝ => (t,y))) + exact (contDiff_planeEval Q 0).continuous.comp (continuous_id.prodMk continuous_const) + +theorem regularParameters_isOpen (Q : Bivariate) (L U : ℝ) : + IsOpen (regularParameters Q L U) := by + apply isOpen_iff_mem_nhds.mpr + intro x hx + obtain ⟨c⟩ := exists_bounded_fiber_charts Q x L U hx.1 hx.2.1 hx.2.2 + have hleft := (continuous_horizontal_eval Q L).continuousAt.eventually_ne hx.1 + have hright := (continuous_horizontal_eval Q U).continuousAt.eventually_ne hx.2.1 + filter_upwards [hleft,hright,isOpen_Ioo.mem_nhds ⟨c.left,c.right⟩] with t htL htU ht + exact ⟨htL,htU,c.all_roots_regular ht⟩ + +theorem fiber_card_eventually_eq (Q : Bivariate) (L U : ℝ) {x : ℝ} + (hx : x ∈ regularParameters Q L U) : + ∀ᶠ t in 𝓝 x, (boundedFiber Q t L U).ncard = (boundedFiber Q x L U).ncard := by + obtain ⟨a,b,ha,hb,h⟩ := locally_constant_fiber_card Q x L U hx.1 hx.2.1 hx.2.2 + filter_upwards [isOpen_Ioo.mem_nhds ⟨ha,hb⟩] with t ht + exact (h t ht).2 + +end ErdosLocalFiberGraphs + +end + +section + +open Set Filter +open scoped Topology +namespace ErdosGlobalFiberBranches +open ErdosImplicitCurvature ErdosLocalFiberGraphs + +theorem continuousOn_fiber_card (Q : Bivariate) (L U : ℝ) (I : Set ℝ) + (hI : I ⊆ regularParameters Q L U) : + ContinuousOn (fun x => (boundedFiber Q x L U).ncard) I := by + intro x hx + have he : (fun t => (boundedFiber Q t L U).ncard) =ᶠ[𝓝 x] + (fun _ => (boundedFiber Q x L U).ncard) := fiber_card_eventually_eq Q L U (hI hx) + have hc : ContinuousAt (fun t => (boundedFiber Q t L U).ncard) x := + continuousAt_const.congr he.symm + exact hc.continuousWithinAt + +theorem fiber_card_eq_on_preconnected (Q : Bivariate) (L U : ℝ) (I : Set ℝ) + (hconn : IsPreconnected I) (hI : I ⊆ regularParameters Q L U) + {x t : ℝ} (hx : x ∈ I) (ht : t ∈ I) : + (boundedFiber Q x L U).ncard = (boundedFiber Q t L U).ncard := + hconn.constant (continuousOn_fiber_card Q L U I hI) hx ht + +end ErdosGlobalFiberBranches + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteBinIntegral.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteBinIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..26cbdd802c8b581d3de5100bc28d5144cf35182c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteBinIntegral.lean @@ -0,0 +1,34 @@ +import Mathlib.MeasureTheory.Integral.Lebesgue.Add +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.FiniteBinIntegral + +open Set MeasureTheory +open scoped ENNReal + +variable {α β : Type*} [MeasurableSpace α] + +theorem integrate_bin_envelope (μ : Measure α) (I : Finset β) (B : β → Set α) + (hB : ∀ k ∈ I,MeasurableSet (B k)) (C : β → ℝ) : + (∫⁻ x,∑ k ∈ I, ENNReal.ofReal (C k)*((B k).indicator (fun _ => (1:ℝ≥0∞)) x) ∂μ) = + ∑ k ∈ I,ENNReal.ofReal (C k)*μ (B k) := by + rw [lintegral_finsetSum I (f := fun k x => ENNReal.ofReal (C k)*((B k).indicator (fun _ => (1:ℝ≥0∞)) x)) + (fun k hk => measurable_const.mul (measurable_const.indicator (hB k hk)))] + apply Finset.sum_congr rfl + intro k hk + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + lintegral_indicator (hB k hk),setLIntegral_const,one_mul] + +end NumberTheoryLean.FiniteBinIntegral + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteLabelBudget.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteLabelBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..41c8601bdcfae35e917ea018225f5940ce883df7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteLabelBudget.lean @@ -0,0 +1,61 @@ +import Mathlib.MeasureTheory.Measure.Real +import OAI.NumberTheory.Jacobsthal.Probability.ActualCouplingUpdates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.FiniteLabelBudget + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open KernelBinConditioning + +section Vectors +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +theorem total_l1_le_twice_live (a b : ι → ℝ) (c : ι) + (ha : ∑ i,a i = 1) (hb : ∑ i,b i = 1) : + ∑ i,|a i-b i| ≤ 2*(∑ i ∈ Finset.univ.erase c,|a i-b i|) := by + have hsa := Finset.sum_erase_add (s:=Finset.univ) a (Finset.mem_univ c) + have hsb := Finset.sum_erase_add (s:=Finset.univ) b (Finset.mem_univ c) + have hsd := Finset.sum_sub_distrib (s:=Finset.univ.erase c) (f:=a) (g:=b) + have heq : a c-b c = -(∑ i ∈ Finset.univ.erase c,(a i-b i)) := by rw [hsd]; linarith + have hc : |a c-b c| ≤ ∑ i ∈ Finset.univ.erase c,|a i-b i| := by + rw [heq,abs_neg] + exact Finset.abs_sum_le_sum_abs _ _ + have hse := Finset.sum_erase_add (s:=Finset.univ) (fun i => |a i-b i|) (Finset.mem_univ c) + linarith + +theorem interior_boundary_budget (a b : ι → ℝ) (c : ι) (good : ι → Prop) [DecidablePred good] + (ha0 : ∀ i,0 ≤ a i) (hb0 : ∀ i,0 ≤ b i) (ha : ∑ i,a i = 1) (hb : ∑ i,b i = 1) : + ∑ i,|a i-b i| ≤ 2*((∑ i ∈ (Finset.univ.erase c).filter good,|a i-b i|)+ + (∑ i ∈ (Finset.univ.erase c).filter (fun i => ¬good i),(a i+b i))) := by + classical + apply (total_l1_le_twice_live a b c ha hb).trans + apply mul_le_mul_of_nonneg_left _ (by norm_num) + have hsplit := Finset.sum_filter_add_sum_filter_not (s:=Finset.univ.erase c) + (p:=good) (f:=fun i => |a i-b i|) + rw [← hsplit] + apply add_le_add_right + apply Finset.sum_le_sum + intro i _ + rw [abs_le] + constructor <;> linarith [ha0 i,hb0 i] +end Vectors + +theorem selected_label_mass {α β ι : Type*} [MeasurableSpace α] [MeasurableSpace β] + [MeasurableSpace ι] [MeasurableSingletonClass ι] [Fintype ι] + (K : Kernel α β) [IsMarkovKernel K] {f : β → ι} (hf : Measurable f) + (x : α) (I : Finset ι) : + (∑ i ∈ I,labelMass K f x i) = (K x (f ⁻¹' (I:Set ι))).toReal := by + exact sum_measureReal_preimage_singleton I (fun i _ => hf (measurableSet_singleton i)) + +end NumberTheoryLean.FiniteLabelBudget + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteWeightedChoiceBox.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteWeightedChoiceBox.lean new file mode 100644 index 0000000000000000000000000000000000000000..c6c2c40c7dc4b3daac22e719344da03d84611623 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FiniteWeightedChoiceBox.lean @@ -0,0 +1,106 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.FiniteWeightedChoiceBox + +attribute [local instance] Classical.propDecidable + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {α : ι → Type*} + +noncomputable def points (P : ∀ i,Finset (α i)) : Finset (∀ i,α i) := Fintype.piFinset P +noncomputable def pointWeight (W : ∀ i,α i → ℝ) (f : ∀ i,α i) : ℝ := ∏ i,W i (f i) +noncomputable def boxMass (P : ∀ i,Finset (α i)) (W : ∀ i,α i → ℝ) : ℝ := + ∑ f ∈ points P,pointWeight W f +noncomputable def restrictedPoints (P : ∀ i,Finset (α i)) (S : Finset ι) (E : ∀ i,α i → Prop) : + Finset (∀ i,α i) := (points P).filter (fun f => ∀ i ∈ S,E i (f i)) + +theorem mass_factorizes (P : ∀ i,Finset (α i)) (W : ∀ i,α i → ℝ) : + boxMass P W=∏ i,∑ x ∈ P i,W i x := (Finset.prod_univ_sum P W).symm + +omit [DecidableEq ι] in +theorem weight_nonnegative (W : ∀ i,α i → ℝ) (hW : ∀ i x,0 ≤ W i x) (f : ∀ i,α i) : + 0 ≤ pointWeight W f := Finset.prod_nonneg (fun i _ => hW i (f i)) + +theorem restricted_eq (P : ∀ i,Finset (α i)) (S : Finset ι) (E : ∀ i,α i → Prop) : + restrictedPoints P S E=points (fun i => if i ∈ S then (P i).filter (E i) else P i) := by + ext f + simp only [restrictedPoints,points,Finset.mem_filter,Fintype.mem_piFinset] + constructor + · rintro ⟨hp,he⟩ i + by_cases hi : i ∈ S + · simpa only [ite_eq_left hi,Finset.mem_filter] using And.intro (hp i) (he i hi) + · simpa only [ite_eq_right hi] using hp i + · intro hf + constructor + · intro i + have hh := hf i + by_cases hi : i ∈ S + · rw [ite_eq_left hi] at hh; exact (Finset.mem_filter.mp hh).1 + · rwa [ite_eq_right hi] at hh + · intro i hi + have hh := hf i + rw [ite_eq_left hi] at hh + exact (Finset.mem_filter.mp hh).2 + +theorem restriction_mass_bound (P : ∀ i,Finset (α i)) (W : ∀ i,α i → ℝ) + (hW : ∀ i x,0 ≤ W i x) (S : Finset ι) (E : ∀ i,α i → Prop) (c : ℝ) + (hcoord : ∀ i ∈ S,(∑ x ∈ (P i).filter (E i),W i x) ≤ c*(∑ x ∈ P i,W i x)) : + (∑ f ∈ restrictedPoints P S E,pointWeight W f) ≤ c^S.card*boxMass P W := by + rw [restricted_eq] + change boxMass (fun i => if i ∈ S then (P i).filter (E i) else P i) W ≤ _ + rw [mass_factorizes,mass_factorizes] + calc + _ ≤ ∏ i,(if i ∈ S then c else 1)*(∑ x ∈ P i,W i x) := by + apply Finset.prod_le_prod₀ + · intro i _ + exact Finset.sum_nonneg (fun x _ => hW i x) + · intro i _ + by_cases hi : i ∈ S + · simp only [ite_eq_left hi] + exact hcoord i hi + · simp only [ite_eq_right hi,one_mul,le_refl] + _ = _ := by rw [Finset.prod_mul_distrib,Finset.prod_ite_mem_eq]; simp + +theorem coordinate_mass_bound (P : ∀ i,Finset (α i)) (W : ∀ i,α i → ℝ) + (hW : ∀ i x,0 ≤ W i x) (E : ∀ i,α i → Prop) (i : ι) (c : ℝ) + (hi : (∑ x ∈ (P i).filter (E i),W i x) ≤ c*(∑ x ∈ P i,W i x)) : + (∑ f ∈ (points P).filter (fun f => E i (f i)),pointWeight W f) ≤ c*boxMass P W := by + have hh := restriction_mass_bound P W hW {i} E c (fun j hj => by + have he : j=i := Finset.mem_singleton.mp hj + subst j + exact hi) + simpa only [restrictedPoints,Finset.mem_singleton,forall_eq,Finset.card_singleton,pow_one] using hh + +theorem union_mass_bound (P : ∀ i,Finset (α i)) (W : ∀ i,α i → ℝ) + (hW : ∀ i x,0 ≤ W i x) (S : Finset ι) (E : ∀ i,α i → Prop) (c : ℝ) + (hcoord : ∀ i ∈ S,(∑ x ∈ (P i).filter (E i),W i x) ≤ c*(∑ x ∈ P i,W i x)) : + (∑ f ∈ (points P).filter (fun f => ∃ i ∈ S,E i (f i)),pointWeight W f) ≤ + (S.card:ℝ)*c*boxMass P W := by + have hu : (∑ f ∈ (points P).filter (fun f => ∃ i ∈ S,E i (f i)),pointWeight W f) ≤ + ∑ i ∈ S,∑ f ∈ (points P).filter (fun f => E i (f i)),pointWeight W f := by + simp only [Finset.sum_filter] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro f _hf + by_cases he : ∃ i ∈ S,E i (f i) + · rw [ite_eq_left he] + obtain ⟨i,hi,hei⟩ := he + have hh := Finset.single_le_sum (s := S) (f := fun j => if E j (f j) then pointWeight W f else 0) + (fun j _ => by split_ifs; exact weight_nonnegative W hW f; rfl) hi + simpa only [ite_eq_left hei] using hh + · rw [ite_eq_right he] + exact Finset.sum_nonneg (fun j _ => by split_ifs; exact weight_nonnegative W hW f; rfl) + apply hu.trans + calc + _ ≤ ∑ _i ∈ S,c*boxMass P W := Finset.sum_le_sum (fun i hi => coordinate_mass_bound P W hW E i c (hcoord i hi)) + _ = _ := by simp [mul_assoc] +end NumberTheoryLean.FiniteWeightedChoiceBox + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullBoxTotalLength.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullBoxTotalLength.lean new file mode 100644 index 0000000000000000000000000000000000000000..2aa860428823a4fc254a7d3e2bec09372292dad5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullBoxTotalLength.lean @@ -0,0 +1,64 @@ +import OAI.NumberTheory.Jacobsthal.Paths.FullBoxPrefixLower +import OAI.NumberTheory.Jacobsthal.Sieve.ErasedCofactorGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceWeighted +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport + StrongSourceFamilies SafeSubsetBoxGeometry ActualReferencePrefixes PrimeProductLogCoordinates + ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection SingletonBinProduct + LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinEndpoints +attribute [local instance] Classical.propDecidable + +theorem full_box_total_length_lower {w top xi B C K a : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) + (hcomp : Real.log B ≤ 2*Real.log w) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap = Real.log (Y : ℝ)/Real.log w-a+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed = true) (hcap : w^z.cutoff = top) + (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) + (f : Fin (binCount w top xi) → Finset ℕ) (hf : f ∈ selections (globalBins w top xi) m) : + a ≤ Real.log ((Y : ℝ)/(selectionProduct f : ℝ))/Real.log w := by + have hfull := (anchored_choice_geometry hw htop hxi hC hcomp z m ha f hf).1 + have hprefix : descendingWord f ∈ (descendingWord f).inits := + (List.mem_inits _ _).mpr ⟨[],by simp⟩ + have hgap := reference_prefix_gap_floor hw htop z hs hz hg hclosed hcap _ _ hfull hprefix + have hsource := word_source_membership hw htop hxi m f hf + have hlog := terminal_gap_log_quotient Y hY z hroot (descendingWord f) + (fun p hp => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp (hsource p hp)).1.pos) + have hprod := descendingWord_product (globalBins w top xi) + (fun j k hjk => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi j k hjk) + f (fun j => ((mem_selections _ m f).mp hf j).1) + rw [hprod] at hlog + linarith + +theorem erased_cofactor_all_lengths {w top xi B C K a : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) + (hcomp : Real.log B ≤ 2*Real.log w) (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap = Real.log (Y : ℝ)/Real.log w-a+2) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed = true) (hcap : w^z.cutoff = top) + (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) + (i : Fin (binCount w top xi)) (hi : m i = 1) + (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) (eraseMultiplicity m i)) : + ∀ p ∈ globalBins w top xi i,a ≤ Real.log ((Y : ℝ)/((p : ℝ)*selectionProduct f))/Real.log w := by + intro p hp + have hfill := fill_selection_mem (globalBins w top xi) m i hi f hf p hp + have hh := full_box_total_length_lower hw htop hxi hC hcomp Y hY z hroot hs hz hg hclosed hcap m ha + (fillSelection f i p) hfill + rw [filled_product f i p (erased_coordinate_empty _ m i f hf),Nat.cast_mul] at hh + exact hh + +end ErdosVarianceWeighted + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullHypotheticalBinLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullHypotheticalBinLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..b872e275afadfca38b2950f16b691b8b626707a9 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullHypotheticalBinLower.lean @@ -0,0 +1,70 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SubbinAggregation +import OAI.NumberTheory.Jacobsthal.Estimates.SubbinScaleInheritance +import OAI.NumberTheory.Jacobsthal.Primes.PrimeWordArithmetic + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedArithmetic +open ErdosStoppedTagSieve Erdos970Dependency.SiegelWalfisz + ErdosCommonMInterval ErdosInverseAlignment ErdosInversePrimeBin + ErdosPrimeInputs.MertensStrong ErdosTagSubbins ErdosStoppedSubbinAggregation + NumberTheoryLean.ReferenceProductsBasics + +attribute [local instance] Classical.propDecidable + +theorem hypothetical_full_bin_lower (Cs : ℝ) (hCs : 0 ≤ Cs) : + ∃ K : ℝ,0 < K ∧ ∀ rho xi : ℝ,1 < rho → 0 < xi → + ∃ w0 : ℝ,4 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → ∀ P R theta : ℝ, + Real.exp (K*(Real.log w)^3) ≤ P → P ≤ Real.exp (rho*K*(Real.log w)^3) → + Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ R → xi/4 ≤ theta → theta ≤ 1 → + ∀ Y q : ℕ,0 < Y → 0 < q → ∀ r : ℚ,∀ a : ℕ → ℕ, + (r.den : ℝ) ≤ w^Cs → |(r.num : ℝ)| ≤ (Y : ℝ)*w^(Cs+2) → + (∀ x ∈ Set.Icc R ((1+theta)*R), + 203/100 ≤ lengthExponent P Y x q ∧ lengthExponent P Y x q ≤ 219/100) → + (∀ t ∈ smallPrimeSet P,q.Coprime t) → + (∀ p ∈ primeBin R theta,Squarefree (p*q) ∧ r.den.Coprime p ∧ + p ∉ smallPrimeSet P ∧ ∀ t ∈ (p*q).primeFactors,t ≠ p → + aligns (fun u => (a u : ℤ)) r t) → + (39/100 : ℝ)*primeProduct P*(∑ p ∈ primeBin R theta,(Y : ℝ)/((p : ℝ)*q)) ≤ + ∑ p ∈ primeBin R theta,primeHypothetical Y (smallPrimeSet P) a r q p := by + obtain ⟨K,hK,hSub⟩ := hypothetical_subbin_lower Cs hCs + refine ⟨K,hK,?_⟩ + intro rho xi hrho hxi + obtain ⟨w0,hw0,hS⟩ := hSub rho xi hrho hxi + refine ⟨w0,hw0,?_⟩ + intro w hw P R theta hPl hPu hR hThetaLo hThetaHi Y q hY hq r a hDen hNum hBand hqSmall hGeometry + have hw1 : 1 < w := by linarith [hw0.trans hw] + have hR0 : 0 < R := (Real.exp_pos _).trans_le hR + have ht : 0 < theta := (div_pos hxi (by norm_num)).trans_le hThetaLo + have hN : 0 < count w Cs := (count_bounds hw1 hCs).1 + apply aggregate_reference_lower (N:=count w Cs) hR0 ht hN (Nat.cast_nonneg Y) + (show (0 : ℝ) < q by exact_mod_cast hq) (actual_primeProduct_pos P).le + (primeHypothetical Y (smallPrimeSet P) a r q) + intro i + obtain ⟨_hLeft,_hStep,hRSub,_hLeftHi,hVlo,hVhi,_hRight⟩ := + subbin_scale_inheritance hw1 hCs hR0 hxi hThetaLo hThetaHi hR i + have hBandSub := subbin_inherits_band hR0 ht hN + (fun x => 203/100 ≤ lengthExponent P Y x q ∧ lengthExponent P Y x q ≤ 219/100) hBand i + have hGeomSub : ∀ p ∈ intervalPrimes (left R theta (count w Cs) i) + (step R theta (count w Cs)) 1 0,Squarefree (p*q) ∧ r.den.Coprime p ∧ + p ∉ smallPrimeSet P ∧ ∀ t ∈ (p*q).primeFactors,t ≠ p → aligns (fun u => (a u : ℤ)) r t := by + intro p hp + have hpSub : p ∈ subbin R theta (count w Cs) i := by + rwa [subbin_eq_intervalPrimes hR0 ht hN] + exact hGeometry p (subbin_subset hR0 ht i.isLt hpSub) + have hh := hS w hw P (left R theta (count w Cs) i) (step R theta (count w Cs)) + hPl hPu hRSub hVlo hVhi Y q hY hq r a hDen hNum hBandSub.1 hBandSub.2 hqSmall hGeomSub + rw [← primeHypothetical_sum] at hh + rw [subbin_eq_intervalPrimes hR0 ht hN] + exact hh + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullPatternCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullPatternCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..7cfbc437dd609b0a6447d67ddb45f48dd3cf9df7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/FullPatternCoordinates.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ConditionalPatternCounts +import OAI.NumberTheory.Jacobsthal.Primes.ActualPrimeSelectors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceMoments +attribute [local instance] Classical.propDecidable + +noncomputable def actualFullPattern (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) : ErdosLargePatternLaw.FullPattern w H := + (ZMod.unitOfCoprime p.val ((Finset.mem_filter.mp p.property).2.symm.of_dvd_right (divisorModulus_dvd_H w H)), + (primeK P H C0 hP p : ZMod (divisorModulus w H)), + (primePoint P w H C0 hw hP hlarge p).2.1, + (primeM P H C0 hP p : ZMod (coprimeModulus w H))) + +theorem full_p0_projection (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) (t : ℕ) (ht : t ∣ divisorModulus w H) : + ((actualFullPattern P w H C0 hw hP hlarge p).1.val.val : ZMod t) = (p.val : ZMod t) := + cast_nat_residue (divisorModulus w H) t p.val ht + +theorem full_k0_projection (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) (t : ℕ) (ht : t ∣ divisorModulus w H) : + ((actualFullPattern P w H C0 hw hP hlarge p).2.1.val : ZMod t) = (primeK P H C0 hP p : ZMod t) := + cast_nat_residue (divisorModulus w H) t (primeK P H C0 hP p) ht + +theorem full_p1_projection (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) (t : ℕ) (ht : t ∣ coprimeModulus w H) : + ((actualFullPattern P w H C0 hw hP hlarge p).2.2.1.val.val : ZMod t) = (p.val : ZMod t) := + primePoint_pValue P w H C0 hw hP hlarge p t ht + +theorem full_m1_projection (P : Finset ℕ) (w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hlarge : ∀ p ∈ P,w < (p : ℝ)) + (p : goodPrimes P H) (t : ℕ) (ht : t ∣ coprimeModulus w H) : + ((actualFullPattern P w H C0 hw hP hlarge p).2.2.2.val : ZMod t) = (primeM P H C0 hP p : ZMod t) := + cast_int_residue (coprimeModulus w H) t ht (primeM P H C0 hP p) + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricInverseGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricInverseGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..f76e9f5fff443ea23c958549eab8437409797ceb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricInverseGeometry.lean @@ -0,0 +1,120 @@ +import OAI.NumberTheory.Jacobsthal.Paths.GeometricWords + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GeometricIsolatedBin +open PrimeHistories GeometricRegularWords GeometricBoxImages GeometricWordsAudit ActualWordSelection ActualRegularBoxes +open ErdosSubsetWord SafeSubsetBoxGeometry FirstIsolatedPosition IsolatedBinGeometry IsolatedRealPrimeRange +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinEndpoints LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem geometric_box_isolated_singleton {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hpower : w^B=top) + (hsearch : w^((1/4:ℝ)) ≤ alpha*B) (z : Node) + (m : Fin (binCount w top xi) → ℕ) (hm : m ∈ geometricBoxes hw htop hxi C B R L alpha beta z) : + ∃ i : Fin (binCount w top xi),m i=1 ∧ isolatedBin w top xi B alpha beta i ∧ top^alpha ≤ lower w top xi i ∧ + upper w top xi i ≤ top^beta ∧ ActualSourceTags.searchBin w (lower w top xi i) := by + obtain ⟨ps,hps,rfl⟩ := Finset.mem_image.mp hm + obtain ⟨pre,p,tail,he,hisol,_hfirst⟩ := geometric_first_isolated hw htop hxi z ps hps + have hrange := isolated_real_range hw htop hxi hpower hisol + have hlo := hrange.1 + have hhi := hrange.2 + have hs := isolated_bin_search hisol hsearch + let i := label (zero_lt_one.trans hw) htop hxi p + have hp : p ∈ ps := by rw [he]; simp + have hreg := (Finset.mem_filter.mp hps).1 + obtain ⟨hd,_hl,_hc,_hg,hsingle⟩ := Finset.mem_filter.mp hreg + have hn : ps.Nodup := (mem_decreasingPrefixes.mp hd).1.imp (fun h => ne_of_gt h) + have hcount : 0 < (ps.map (label (zero_lt_one.trans hw) htop hxi)).count i := + List.count_pos_iff.mpr (List.mem_map.mpr ⟨p,hp,rfl⟩) + have hle := hsingle i hs + refine ⟨i,?_,hisol,hlo,hhi,hs⟩ + rw [wordMultiplicity_count _ ps hn] + omega +end NumberTheoryLean.GeometricIsolatedBin + + + +namespace NumberTheoryLean.GeometricBinOrdering +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinEndpoints PrimeBinRepresentatives +open IsolatedBinGeometry BoundedEdgeBins BoundedEdgePrimeRange + + +theorem left_exponent_mono {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (i j : Fin (binCount w top xi)) (hij : i ≤ j) : + leftExponent w (lower w top xi i) ≤ leftExponent w (lower w top xi j) := by + have hlow := endpoint_mono (zero_lt_one.trans hw) htop hxi (show i.1 ≤ j.1 from hij) + exact div_le_div_of_nonneg_right (Real.log_le_log (endpoint_pos (zero_lt_one.trans hw) i.1) hlow) (Real.log_pos hw).le + +theorem isolated_before_bounded_edge {w top xi B alpha beta M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (i j : Fin (binCount w top xi)) + (hi : isolatedBin w top xi B alpha beta i) (hj : boundedEdgeBin w top xi Y m M X j) + (hlarge : X < alpha*B) : j < i := by + by_contra! hle + have hh := left_exponent_mono hw htop hxi i j hle + have hb := bounded_edge_lower_exponent hw htop hxi m j hj + linarith [hi.1] +end NumberTheoryLean.GeometricBinOrdering + + + +namespace NumberTheoryLean.GeometricInverseGeometry +open FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport +open ErdosCofactorChoices ErdosSubsetWord GeometricBoxImages GeometricIsolatedBin +open GeometricBinOrdering BoundedEdgeBins BoundedEdgePrimeRange ParentCofactorChoices CofactorAllChoiceBounds +open SafeSubsetBoxGeometry BinCutSelections +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinEndpoints + + +theorem geometric_inverse_geometry {w top xi B C K L alpha a M X : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 1 ≤ C) (hlog : 1 ≤ Real.log w) + (hcomp : Real.log B ≤ 2*Real.log w) (hDelta : 2*C*xi ≤ 1) (hB : 3 ≤ B) + (hpower : w^B=top) (hsearch : w^((1/4:ℝ)) ≤ alpha*B) (hlarge : X < alpha*B) + (Y : ℕ) (hY : 0 < Y) (z : Node) (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (hi : z.side=.even) (h199 : 199/100 ≤ z.ratio) (hz : Consistent z) (hcut : z.cutoff=B) (hclosed : z.closed=true) + (m : Fin (binCount w top xi) → ℕ) (hm : m ∈ geometricBoxes hw htop hxi C B K L alpha (1/100) z) : + ∃ i : Fin (binCount w top xi),m i=1 ∧ top^alpha ≤ lower w top xi i ∧ lower w top xi i ≤ top^((1:ℝ)/100) ∧ + ∀ j : Fin (binCount w top xi),boundedEdgeBin w top xi Y m M X j → + i ≠ j ∧ m j=1 ∧ + parentCofactorMultiplicity m i j i=0 ∧ parentCofactorMultiplicity m i j j=0 ∧ + ((∑ k,parentCofactorMultiplicity m i j k : ℕ):ℝ) ≤ C*Real.log B ∧ + w ≤ lower w top xi j ∧ lower w top xi j ≤ w^X ∧ + (∀ q ∈ cofactorChoices (globalBins w top xi) (parentCofactorMultiplicity m i j), + ∀ p ∈ globalBins w top xi i,Real.log ((Y:ℝ)/((p:ℝ)*(q:ℝ)))/Real.log w ≤ M+1) ∧ + (∀ q ∈ cofactorChoices (globalBins w top xi) (parentCofactorMultiplicity m i j), + ∀ p ∈ globalBins w top xi i,∀ u ∈ globalBins w top xi j, + a ≤ Real.log ((Y:ℝ)/((p:ℝ)*(q:ℝ)*(u:ℝ)))/Real.log w) := by + obtain ⟨i,hmi,hisol,hilo,hihi,_hsearch⟩ := geometric_box_isolated_singleton hw htop hxi hpower hsearch z m hm + have hsmall : 2*(xi/Real.log w) ≤ 6*(2*C*xi) := by + have hh := div_le_self hxi.le hlog + nlinarith + have ha := geometric_box_anchor hw htop hxi (by linarith : 0 ≤ C) hcomp hsmall z m hm + have hlen := anchor_total_length hw htop hxi z m ha + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB z hi h199 hz hcut + have hcap : w^z.cutoff=top := by rwa [hcut] + refine ⟨i,hmi,hilo,(bin_source_bounds (zero_lt_one.trans hw) htop hxi i).2.1.le.trans hihi,?_⟩ + intro j hj + have hji := isolated_before_bounded_edge hw htop hxi m i j hisol hj hlarge + have hzero := cofactor_slots_zero m i j + have htotal : ((∑ k,parentCofactorMultiplicity m i j k : ℕ):ℝ) ≤ C*Real.log B := + (Nat.cast_le.mpr (cofactor_total_le m i j)).trans hlen + have hrange := bounded_edge_prime_range hw htop hxi m j hj + have hall := cofactor_all_choice_lengths hw htop hxi (by linarith : 0 ≤ C) hcomp Y hY z hroot + hs hz hg hclosed hcap m ha i j hji hmi hj + refine ⟨ne_of_gt hji,bounded_edge_singleton m j hj,hzero.1,hzero.2,htotal,hrange.1,hrange.2,?_,hall.2⟩ + intro q hq p hp + exact (hall.1 q hq p hp).trans (by linarith) +end NumberTheoryLean.GeometricInverseGeometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricRangeInverse.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricRangeInverse.lean new file mode 100644 index 0000000000000000000000000000000000000000..15c251ad3d65600161c344db76db41b3205a9e4e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricRangeInverse.lean @@ -0,0 +1,268 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualSourceInverse +import OAI.NumberTheory.Jacobsthal.Estimates.IsolatedPowerOrdering +import OAI.NumberTheory.Jacobsthal.Sieve.BoxWitnessFactorization + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.NormalizedBoxException +open ErdosCofactorChoices ErdosInverseCells ErdosInverseSampling CanonicalSubsetBox +open BoxWitnessFactorization ParentCofactorChoices BinCutSelections + +attribute [local instance] Classical.propDecidable + +theorem weighted_witness_le_total (P Q U : Finset ℕ) (W : (ℕ × ℕ) → ℕ → Prop) : + weightedWitness P Q U W ≤ harmonicMass P*harmonicMass Q*harmonicMass U := by + have hs : witnessPairs (P.product Q) U W ⊆ tripleSpace P Q U := Finset.filter_subset _ _ + have hh := Finset.sum_le_sum_of_subset_of_nonneg hs (fun x _ _ => tripleWeight_nonneg x) + exact hh.trans_eq (triple_weight_sum P Q U) + +theorem unnormalize_witness (P Q U : Finset ℕ) (W : (ℕ × ℕ) → ℕ → Prop) (sigma : ℝ) + (h : weightedWitness P Q U W/(harmonicMass P*harmonicMass Q*harmonicMass U) ≤ sigma) : + weightedWitness P Q U W ≤ sigma*(harmonicMass P*harmonicMass Q*harmonicMass U) := by + have hm : 0 ≤ harmonicMass P*harmonicMass Q*harmonicMass U := + mul_nonneg (mul_nonneg (harmonicMass_nonneg P) (harmonicMass_nonneg Q)) (harmonicMass_nonneg U) + rcases hm.eq_or_lt with hm | hm + · rw [← hm,mul_zero] + have hh := weighted_witness_le_total P Q U W + rwa [← hm] at hh + · exact (div_le_iff₀ hm).mp h + +theorem selection_exception_bound {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hP : ∀ i,∀ p ∈ P i,p.Prime) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (i j : Fin n) (hji : j < i) (hi : m i=1) (hj : m j=1) (W : (ℕ × ℕ) → ℕ → Prop) (sigma : ℝ) + (h : weightedWitness (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j) W/ + (harmonicMass (P i)*harmonicMass (cofactorChoices P (parentCofactorMultiplicity m i j))*harmonicMass (P j)) ≤ sigma) : + selectionWitnessMass P m i j W ≤ sigma*selectionMass P m := by + have hw := unnormalize_witness (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j) W sigma h + rw [selection_witness_factor P m hP hd i j hji hi hj,full_box_mass_factor P m hP hd i j hji hi hj] + have hh := mul_le_mul_of_nonneg_left hw (harmonicMass_nonneg (cofactorChoices P (belowMultiplicity m j))) + nlinarith +end NumberTheoryLean.NormalizedBoxException + + + +namespace NumberTheoryLean.ActualInverseFullBoxMass +open ErdosInverseSampleCost ErdosCofactorChoices ErdosInverseCells ErdosInverseSampling ErdosInverseBoxApplication +open NormalizedBoxException BoxWitnessFactorization CanonicalSubsetBox ParentCofactorChoices + + +theorem actual_inverse_full_box_mass {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hP : ∀ i,∀ p ∈ P i,p.Prime) (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (i j : Fin n) (hji : j < i) (hi : m i=1) (hj : m j=1) + (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 S R Z cp sigma : ℝ) (F : ℕ) + (hInv : SourceInverseConclusion Y small a delta V0 S R Z cp sigma F + (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j)) : + selectionWitnessMass P m i j (actualWitness Y small a delta V0 (P i) S R Z cp) ≤ sigma*selectionMass P m := by + have hh := hInv.2.2.1 + rw [actual_exception_weight] at hh + exact selection_exception_bound P m hP hd i j hji hi hj _ sigma hh +end NumberTheoryLean.ActualInverseFullBoxMass + + + +namespace NumberTheoryLean.GeometricFullBoxInverse +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open GeometricBoxImages GeometricInverseGeometry BoundedEdgeBins ParentCofactorChoices +open JacobsthalSourceScale IsolatedSourceScales SourceNodeCoordinates +open ActualInverseFullBoxMass BoxWitnessFactorization CanonicalSubsetBox IsolatedPowerOrdering ErdosInverseSampleCost +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseBoxApplication +open LogarithmicBinScale LogarithmicBinEndpoints +open scoped Topology + + +theorem geometric_full_box_inverse (C Kstar aStar alpha delta sigma : ℝ) + (hC : 1 ≤ C) (hKstar : 0 ≤ Kstar) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (halpha : 0 < alpha) (hd : 0 < delta) (hsigma : 0 < sigma) (hsigma1 : sigma ≤ 1) : + ∃ cp : ℝ,0 < cp ∧ ∃ F : ℕ,∃ xi₀ : ℝ,0 < xi₀ ∧ xi₀ ≤ 1 ∧ + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ xi₀ → ∀ᶠ top : ℝ in atTop, + ∃ hw : 1 < ErdosInverseBoxHeight.sourceW top,∃ htop : ErdosInverseBoxHeight.sourceW top < top, + ∀ R L : ℝ,∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → Consistent z → + z.cutoff=ErdosInverseBoxHeight.sourceB top → z.closed=true → + z.gap=Real.log (ErdosInverseBoxHeight.sourceY top:ℝ)/Real.log (ErdosInverseBoxHeight.sourceW top)-aStar+2 → + ∀ m ∈ geometricBoxes hw htop hxi C (ErdosInverseBoxHeight.sourceB top) R L alpha (1/100) z, + ∃ i : Fin (binCount (ErdosInverseBoxHeight.sourceW top) top xi),m i=1 ∧ + ∀ j : Fin (binCount (ErdosInverseBoxHeight.sourceW top) top xi), + boundedEdgeBin (ErdosInverseBoxHeight.sourceW top) top xi (ErdosInverseBoxHeight.sourceY top) m + (2*Kstar+3) (2*Kstar+3) j → ∀ residue : ℕ → ℕ, + j < i ∧ m j=1 ∧ + let cm := parentCofactorMultiplicity m i j + let w := ErdosInverseBoxHeight.sourceW top + SourceInverseConclusion (ErdosInverseBoxHeight.sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) + residue delta (SmallSieveFinite.smallEuler ⌊w⌋₊) (cofactorScale top xi cm) + (lower w top xi i) (ErdosInverseBoxHeight.sourceZ top) cp sigma F + (actualBins top xi i) (cofactorChoices (actualBins top xi) cm) (actualBins top xi j) ∧ + selectionWitnessMass (actualBins top xi) m i j + (actualWitness (ErdosInverseBoxHeight.sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊w⌋₊) (actualBins top xi i) (cofactorScale top xi cm) + (lower w top xi i) (ErdosInverseBoxHeight.sourceZ top) cp) ≤ sigma*selectionMass (actualBins top xi) m := by + obtain ⟨cp,hcp,F,xiI,hxiI,hxiI1,hInv⟩ := actual_source_inverse C (2*Kstar+4) aStar (2*Kstar+3) alpha delta sigma + (by linarith) (by linarith) ha ha1 (by linarith) halpha hd hsigma hsigma1 + have hC0 : 0 < C := by linarith + refine ⟨cp,hcp,F,min xiI (1/(2*C)),lt_min hxiI (by positivity),(min_le_left _ _).trans hxiI1,?_⟩ + intro xi hxi hxi₀ + have hxI := hxi₀.trans (min_le_left _ _) + have hDelta : 2*C*xi ≤ 1 := by + have hh := (le_div_iff₀ (show 0 < 2*C by positivity)).mp (hxi₀.trans (min_le_right _ _)) + nlinarith + have hWT := sourceW_tendsto.comp Real.tendsto_log_atTop + have hBT := sourceB_tendsto.comp Real.tendsto_log_atTop + have hlargeT := (hBT.const_mul_atTop halpha).eventually_gt_atTop (2*Kstar+3) + filter_upwards [hInv xi hxi hxI,ErdosCofactorChoices.source_span_geometry, + Real.tendsto_log_atTop.eventually source_scale_eventually, + Real.tendsto_log_atTop.eventually (source_isolated_search_scale halpha), + hBT.eventually_ge_atTop 3,hWT.eventually_ge_atTop (Real.exp 1),hlargeT, + eventually_gt_atTop (1:ℝ)] with top hInverse hspan hscale hsearch hB3 hWexp hlarge htop1 + change Real.exp 1 ≤ ErdosInverseBoxHeight.sourceW top at hWexp + change 3 ≤ ErdosInverseBoxHeight.sourceB top at hB3 + change 2*Kstar+3 < alpha*ErdosInverseBoxHeight.sourceB top at hlarge + have hw : 1 < ErdosInverseBoxHeight.sourceW top := hscale.1 + have htop : ErdosInverseBoxHeight.sourceW top < top := hspan.2.1 + have hlog : 1 ≤ Real.log (ErdosInverseBoxHeight.sourceW top) := by + have hh := Real.log_le_log (Real.exp_pos 1) hWexp + simpa only [Real.log_exp] using hh + have hpow : (ErdosInverseBoxHeight.sourceW top)^(ErdosInverseBoxHeight.sourceB top)=top := + (sourceW_pow_sourceB hw).trans (Real.exp_log (zero_lt_one.trans htop1)) + refine ⟨hw,htop,?_⟩ + intro R L z hi h199 hz hcut hclosed hroot m hm + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hY : 0 < ErdosInverseBoxHeight.sourceY top := by + by_contra! hn + have hzero : ErdosInverseBoxHeight.sourceY top=0 := by omega + rw [hzero,Nat.cast_zero,Real.log_zero,zero_div] at hroot + have hg := node_gap_eq hs hz hcut + nlinarith + have hgeo := geometric_inverse_geometry (M:=2*Kstar+3) (X:=2*Kstar+3) hw htop hxi hC hlog hscale.2.2.2.2 hDelta hB3 hpow hsearch hlarge + (ErdosInverseBoxHeight.sourceY top) hY z hroot hi h199 hz hcut hclosed m hm + obtain ⟨i,hmi,hilo,hihi,hgeo⟩ := hgeo + refine ⟨i,hmi,?_⟩ + intro j hj residue + obtain ⟨hij,_hmj,hzi,hzj,hlen,_hUlo,hUhi,hparent,hchild⟩ := hgeo j hj + have hji := source_power_before_edge hw htop hxi hpow m i j hilo hj hlarge + have hmj := bounded_edge_singleton m j hj + refine ⟨hji,hmj,?_⟩ + dsimp only + have hresult := hInverse (parentCofactorMultiplicity m i j) i j hij hzi hzj hlen residue hilo hihi hUhi + (by + intro q hq p hp + change Real.log ((ErdosInverseBoxHeight.sourceY top:ℝ)/((p:ℝ)*(q:ℝ)))/Real.log (ErdosInverseBoxHeight.sourceW top) ≤ _ + have hh := hparent q hq p hp + nlinarith) + (by + intro q hq p hp u hu + exact (by linarith : 3*aStar/4 ≤ aStar).trans (hchild q hq p hp u hu)) + refine ⟨hresult,?_⟩ + exact actual_inverse_full_box_mass (actualBins top xi) m + (fun k _p hp => (bin_prime_in_source (zero_lt_one.trans hw) htop hxi k hp).1) + (fun k l hkl => LogarithmicBinPartition.bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) + i j hji hmi hmj _ _ residue _ _ _ _ _ _ _ F hresult +end NumberTheoryLean.GeometricFullBoxInverse + + + +namespace NumberTheoryLean.GeometricRangeInverse +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open GeometricBoxImages GeometricInverseGeometry BoundedEdgeBins ParentCofactorChoices +open JacobsthalSourceScale IsolatedSourceScales SourceNodeCoordinates +open ActualInverseFullBoxMass BoxWitnessFactorization CanonicalSubsetBox IsolatedPowerOrdering ErdosInverseSampleCost +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseBoxApplication +open LogarithmicBinScale LogarithmicBinEndpoints +open scoped Topology + + +theorem geometric_range_inverse (C Kstar aStar alpha delta sigma : ℝ) + (hC : 1 ≤ C) (hKstar : 0 ≤ Kstar) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (halpha : 0 < alpha) (hd : 0 < delta) (hsigma : 0 < sigma) (hsigma1 : sigma ≤ 1) : + ∃ cp : ℝ,0 < cp ∧ ∃ F : ℕ,∃ xi₀ : ℝ,0 < xi₀ ∧ xi₀ ≤ 1 ∧ + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ xi₀ → ∀ᶠ top : ℝ in atTop, + ∃ hw : 1 < ErdosInverseBoxHeight.sourceW top,∃ htop : ErdosInverseBoxHeight.sourceW top < top, + ∀ R L : ℝ,∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → Consistent z → + z.cutoff=ErdosInverseBoxHeight.sourceB top → z.closed=true → + z.gap=Real.log (ErdosInverseBoxHeight.sourceY top:ℝ)/Real.log (ErdosInverseBoxHeight.sourceW top)-aStar+2 → + ∀ m ∈ geometricBoxes hw htop hxi C (ErdosInverseBoxHeight.sourceB top) R L alpha (1/100) z, + ∃ i : Fin (binCount (ErdosInverseBoxHeight.sourceW top) top xi),m i=1 ∧ + top^alpha ≤ lower (ErdosInverseBoxHeight.sourceW top) top xi i ∧ + lower (ErdosInverseBoxHeight.sourceW top) top xi i ≤ top^((1:ℝ)/100) ∧ + ∀ j : Fin (binCount (ErdosInverseBoxHeight.sourceW top) top xi), + boundedEdgeBin (ErdosInverseBoxHeight.sourceW top) top xi (ErdosInverseBoxHeight.sourceY top) m + (2*Kstar+3) (2*Kstar+3) j → ∀ residue : ℕ → ℕ, + j < i ∧ m j=1 ∧ + let cm := parentCofactorMultiplicity m i j + let w := ErdosInverseBoxHeight.sourceW top + SourceInverseConclusion (ErdosInverseBoxHeight.sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) + residue delta (SmallSieveFinite.smallEuler ⌊w⌋₊) (cofactorScale top xi cm) + (lower w top xi i) (ErdosInverseBoxHeight.sourceZ top) cp sigma F + (actualBins top xi i) (cofactorChoices (actualBins top xi) cm) (actualBins top xi j) ∧ + selectionWitnessMass (actualBins top xi) m i j + (actualWitness (ErdosInverseBoxHeight.sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊w⌋₊) (actualBins top xi i) (cofactorScale top xi cm) + (lower w top xi i) (ErdosInverseBoxHeight.sourceZ top) cp) ≤ sigma*selectionMass (actualBins top xi) m := by + obtain ⟨cp,hcp,F,xiI,hxiI,hxiI1,hInv⟩ := actual_source_inverse C (2*Kstar+4) aStar (2*Kstar+3) alpha delta sigma + (by linarith) (by linarith) ha ha1 (by linarith) halpha hd hsigma hsigma1 + have hC0 : 0 < C := by linarith + refine ⟨cp,hcp,F,min xiI (1/(2*C)),lt_min hxiI (by positivity),(min_le_left _ _).trans hxiI1,?_⟩ + intro xi hxi hxi₀ + have hxI := hxi₀.trans (min_le_left _ _) + have hDelta : 2*C*xi ≤ 1 := by + have hh := (le_div_iff₀ (show 0 < 2*C by positivity)).mp (hxi₀.trans (min_le_right _ _)) + nlinarith + have hWT := sourceW_tendsto.comp Real.tendsto_log_atTop + have hBT := sourceB_tendsto.comp Real.tendsto_log_atTop + have hlargeT := (hBT.const_mul_atTop halpha).eventually_gt_atTop (2*Kstar+3) + filter_upwards [hInv xi hxi hxI,ErdosCofactorChoices.source_span_geometry, + Real.tendsto_log_atTop.eventually source_scale_eventually, + Real.tendsto_log_atTop.eventually (source_isolated_search_scale halpha), + hBT.eventually_ge_atTop 3,hWT.eventually_ge_atTop (Real.exp 1),hlargeT, + eventually_gt_atTop (1:ℝ)] with top hInverse hspan hscale hsearch hB3 hWexp hlarge htop1 + change Real.exp 1 ≤ ErdosInverseBoxHeight.sourceW top at hWexp + change 3 ≤ ErdosInverseBoxHeight.sourceB top at hB3 + change 2*Kstar+3 < alpha*ErdosInverseBoxHeight.sourceB top at hlarge + have hw : 1 < ErdosInverseBoxHeight.sourceW top := hscale.1 + have htop : ErdosInverseBoxHeight.sourceW top < top := hspan.2.1 + have hlog : 1 ≤ Real.log (ErdosInverseBoxHeight.sourceW top) := by + have hh := Real.log_le_log (Real.exp_pos 1) hWexp + simpa only [Real.log_exp] using hh + have hpow : (ErdosInverseBoxHeight.sourceW top)^(ErdosInverseBoxHeight.sourceB top)=top := + (sourceW_pow_sourceB hw).trans (Real.exp_log (zero_lt_one.trans htop1)) + refine ⟨hw,htop,?_⟩ + intro R L z hi h199 hz hcut hclosed hroot m hm + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hY : 0 < ErdosInverseBoxHeight.sourceY top := by + by_contra! hn + have hzero : ErdosInverseBoxHeight.sourceY top=0 := by omega + rw [hzero,Nat.cast_zero,Real.log_zero,zero_div] at hroot + have hg := node_gap_eq hs hz hcut + nlinarith + have hgeo := geometric_inverse_geometry (M:=2*Kstar+3) (X:=2*Kstar+3) hw htop hxi hC hlog hscale.2.2.2.2 hDelta hB3 hpow hsearch hlarge + (ErdosInverseBoxHeight.sourceY top) hY z hroot hi h199 hz hcut hclosed m hm + obtain ⟨i,hmi,hilo,hihi,hgeo⟩ := hgeo + refine ⟨i,hmi,hilo,hihi,?_⟩ + intro j hj residue + obtain ⟨hij,_hmj,hzi,hzj,hlen,_hUlo,hUhi,hparent,hchild⟩ := hgeo j hj + have hji := source_power_before_edge hw htop hxi hpow m i j hilo hj hlarge + have hmj := bounded_edge_singleton m j hj + refine ⟨hji,hmj,?_⟩ + dsimp only + have hresult := hInverse (parentCofactorMultiplicity m i j) i j hij hzi hzj hlen residue hilo hihi hUhi + (by + intro q hq p hp + change Real.log ((ErdosInverseBoxHeight.sourceY top:ℝ)/((p:ℝ)*(q:ℝ)))/Real.log (ErdosInverseBoxHeight.sourceW top) ≤ _ + have hh := hparent q hq p hp + nlinarith) + (by + intro q hq p hp u hu + exact (by linarith : 3*aStar/4 ≤ aStar).trans (hchild q hq p hp u hu)) + refine ⟨hresult,?_⟩ + exact actual_inverse_full_box_mass (actualBins top xi) m + (fun k _p hp => (bin_prime_in_source (zero_lt_one.trans hw) htop hxi k hp).1) + (fun k l hkl => LogarithmicBinPartition.bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) + i j hji hmi hmj _ _ residue _ _ _ _ _ _ _ F hresult +end NumberTheoryLean.GeometricRangeInverse + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricSelectionHardMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricSelectionHardMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffec6a1bbb506baa018deb601e9536d1a34b8bff --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricSelectionHardMass.lean @@ -0,0 +1,152 @@ +import OAI.NumberTheory.Jacobsthal.Primes.SourceRawPrimeMass +import OAI.NumberTheory.Jacobsthal.Probability.SingletonEventMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosVarianceWeighted +open NumberTheoryLean ErdosCofactorChoices SingletonBinSelection TwoPrimeObservableSum +attribute [local instance] Classical.propDecidable + +def hardSelection {n : ℕ} (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) + (i : Fin n) (Cs eps : ℝ) (f : Fin n → Finset ℕ) : Prop := + pickedPrime f i ∈ rawHardPrimeUnion Q z R theta a (selectionProduct (eraseSelection f i)) Cs eps + +theorem hardSelection_fill {n : ℕ} (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) + (i : Fin n) (Cs eps : ℝ) (f : Fin n → Finset ℕ) (he : f i = ∅) (p : ℕ) : + hardSelection Q z R theta a i Cs eps (fillSelection f i p) ↔ + p ∈ rawHardPrimeUnion Q z R theta a (selectionProduct f) Cs eps := by + unfold hardSelection + rw [erase_fill f i p he] + simp [pickedPrime,fillSelection] + +theorem hardSelection_fibre {n : ℕ} (Q : Finset ℚ) (z R theta : ℝ) (a : ℕ → ℕ) + (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (Cs eps : ℝ) + (hPi : P i = ErdosInversePrimeBin.primeBin R theta) + (f : Fin n → Finset ℕ) (hf : f ∈ selections P (eraseMultiplicity m i)) : + (P i).filter (fun p => hardSelection Q z R theta a i Cs eps (fillSelection f i p)) = + rawHardPrimeUnion Q z R theta a (selectionProduct f) Cs eps := by + ext p + rw [Finset.mem_filter,hardSelection_fill Q z R theta a i Cs eps f (erased_coordinate_empty P m i f hf) p,hPi] + exact and_iff_right_of_imp (fun hp => rawHardPrimeUnion_subset Q z R theta a (selectionProduct f) Cs eps hp) + +end ErdosVarianceWeighted + + +section + +open _root_.Filter +namespace ErdosVarianceWeighted +open NumberTheoryLean ErdosInverseBoxHeight ErdosInversePrimeBin ErdosInverseCells ErdosCofactorChoices + SingletonBinSelection CanonicalSubsetBox +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_selection_hard_mass (alpha aStar eps tau Cmin : ℝ) (F : ℕ) + (halpha : 0 < alpha) (ha : 0 < aStar) (heps : 0 < eps) (htau : 0 < tau) : + ∃ Cs : ℝ,0 < Cs ∧ Cmin ≤ Cs ∧ ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,0 < xi → xi ≤ xi0 → ∀ᶠ z : ℝ in atTop, + ∀ (R theta : ℝ),z^alpha ≤ R → xi/4 ≤ theta → theta ≤ xi → + ∀ (a : ℕ → ℕ) (n : ℕ) (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n),m i = 1 → + P i = primeBin R theta → + (∀ f ∈ selections P (eraseMultiplicity m i),Squarefree (selectionProduct f) ∧ + (∀ t ∈ (selectionProduct f).primeFactors,sourceW z < (t : ℝ)) ∧ + (∀ p ∈ P i,(selectionProduct f).Coprime p ∧ + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*selectionProduct f))/Real.log (sourceW z))) → + ∀ Q : Finset ℚ,Q.card ≤ F → + (∑ f ∈ (selections P m).filter (hardSelection Q z R theta a i Cs eps),(selectionProduct f : ℝ)⁻¹) ≤ + tau*selectionMass P m := by + obtain ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,hsource⟩ := + source_raw_hard_prime_mass alpha aStar eps tau Cmin F halpha ha heps htau + refine ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + filter_upwards [hsource xi hxi hxib] with z hz + intro R theta hRlo hthetal hthetau a n P m i hi hPi hgeometry Q hQ + apply singleton_event_mass_bound P m i hi _ tau + intro f hf + have hg := hgeometry f hf + rw [hPi] at hg + rw [hardSelection_fibre Q z R theta a P m i Cs eps hPi f hf,hPi] + exact hz R theta a (selectionProduct f) hg.1 hRlo hthetal hthetau hg.2.1 hg.2.2 Q hQ + +end ErdosVarianceWeighted + +end + + +open _root_.Filter +namespace ErdosVarianceWeighted +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport SafeSubsetBoxGeometry + GeometricBoxImages ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection CanonicalSubsetBox + LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinPartition LogarithmicBinMaps + ErdosInverseBoxHeight ErdosInverseEuler +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem geometric_selection_hard_mass (C aStar alpha eps tau Cmin : ℝ) (F : ℕ) + (hC : 1 ≤ C) (ha : 0 < aStar) (halpha : 0 < alpha) (heps : 0 < eps) (htau : 0 < tau) : + ∃ Cs : ℝ,0 < Cs ∧ Cmin ≤ Cs ∧ ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ xi0 → ∀ᶠ top : ℝ in atTop, + ∃ hw : 1 < sourceW top,∃ htop : sourceW top < top, + ∀ (K L : ℝ) (z : Node),z.side = .even → 199/100 ≤ z.ratio → Consistent z → + z.cutoff = sourceB top → z.closed = true → + z.gap = Real.log (sourceY top : ℝ)/Real.log (sourceW top)-aStar+2 → + ∀ m ∈ geometricBoxes hw htop hxi C (sourceB top) K L alpha (1/100) z, + ∀ i : Fin (binCount (sourceW top) top xi),m i = 1 → top^alpha ≤ lower (sourceW top) top xi i → + ∀ (a : ℕ → ℕ) (Q : Finset ℚ),Q.card ≤ F → + (∑ f ∈ (selections (globalBins (sourceW top) top xi) m).filter + (hardSelection Q top (lower (sourceW top) top xi i) (width (sourceW top) top xi i) a i Cs eps), + (selectionProduct f : ℝ)⁻¹) ≤ tau*selectionMass (globalBins (sourceW top) top xi) m := by + obtain ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,hsource⟩ := + source_selection_hard_mass alpha aStar eps tau Cmin F halpha ha heps htau + refine ⟨Cs,hCs,hCmin,xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + have hxi1 := hxib.trans hxi01 + have hBT := JacobsthalSourceScale.sourceB_tendsto.comp Real.tendsto_log_atTop + filter_upwards [hsource xi hxi hxib,source_span_geometry, + Real.tendsto_log_atTop.eventually JacobsthalSourceScale.source_scale_eventually, + source_B_bounds,hBT.eventually_ge_atTop 3] with top hv hspan hscale hBounds hB3 + have hw : 1 < sourceW top := hscale.1 + have htop : sourceW top < top := hspan.2.1 + have htop0 : 0 < top := (zero_lt_one.trans hw).trans htop + have hcomp : Real.log (sourceB top) ≤ 2*Real.log (sourceW top) := hscale.2.2.2.2 + have hlog : 1 ≤ Real.log (sourceW top) := by + simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 1) hBounds.1 + have hsmall : 2*(xi/Real.log (sourceW top)) ≤ 6*(2*C*xi) := by + have hh := div_le_self hxi.le hlog + nlinarith + have hspanMul : (1+xi)*sourceW top ≤ top := by + have hh := hspan.2.2 xi hxi hxi1 + have hd : 0 < top/sourceW top := div_pos htop0 (zero_lt_one.trans hw) + have he := (Real.log_le_log_iff (by positivity : 0 < 1+xi) hd).mp hh + exact (le_div_iff₀ (zero_lt_one.trans hw)).mp he + have hwidth := common_width_bounds (zero_lt_one.trans hw) htop hxi hxi1 hspanMul + refine ⟨hw,htop,?_⟩ + intro K L z heven h199 hz hcut hclosed hroot m hm i hi hiR a Q hQ + have hs : Valid z.side z.ratio := by rw [heven];change 198/100 ≤ z.ratio;linarith + have hStrong := source_strong_state hB3 z heven h199 hz hcut + have hY : 0 < sourceY top := by + by_contra! hzero + have he : sourceY top = 0 := by omega + rw [he,Nat.cast_zero,Real.log_zero,zero_div] at hroot + linarith [hStrong.1] + have hcap : (sourceW top)^z.cutoff = top := by + rw [hcut] + exact (JacobsthalSourceScale.sourceW_pow_sourceB hw).trans (Real.exp_log htop0) + have hanchor := geometric_box_anchor hw htop hxi (by linarith : 0 ≤ C) hcomp hsmall z m hm + have hgeometry := full_box_variance_fibres hw htop hxi (by linarith : 0 ≤ C) ha.le hcomp + (sourceY top) hY z hroot hs hz hStrong hclosed hcap m hanchor i hi + have hthetal : xi/4 ≤ width (sourceW top) top xi i := by rw [hwidth.2.2.2 i];exact hwidth.2.1 + have hthetau : width (sourceW top) top xi i ≤ xi := by rw [hwidth.2.2.2 i];exact hwidth.2.2.1 + exact hv (lower (sourceW top) top xi i) (width (sourceW top) top xi i) hiR hthetal hthetau a _ + (globalBins (sourceW top) top xi) m i hi rfl hgeometry Q hQ + +end ErdosVarianceWeighted + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricTotalBoxMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricTotalBoxMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffb637936d3e7eba0d4a5f51c0694fa478f07388 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GeometricTotalBoxMass.lean @@ -0,0 +1,60 @@ +import OAI.NumberTheory.Jacobsthal.Paths.OutsideExceptionsWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GeometricTotalBoxMass +open FinitePathGeometry PrimeHistories PrimeBinMembership ActualSafeBoxMass +open GeometricBoxImages SafeSubsetBoxGeometry CanonicalSubsetBox FilteredBoxWordMass +open LogarithmicBinScale ErdosSubsetWord + + +theorem uniform_geometric_box_mass (K : ℝ) (hK : 3 ≤ K) : + ∃ C B₀ w₀ : ℝ,0 < C ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ (hw : 1 < w) (htop : w < top), + ∀ xi Clen : ℝ,∀ hxi : 0 < xi,1 ≤ Clen → Real.log B ≤ 2*Real.log w → 2*Clen*xi ≤ 1 → + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → + z.cutoff=B → z.closed=true → w^B=top → ∀ L alpha beta : ℝ, + B^2*(∑ m∈geometricBoxes hw htop hxi Clen B K L alpha beta z,selectionMass (globalBins w top xi) m) ≤ C := by + obtain ⟨C,B₀,W,hC,hB₀,hW,hTotal⟩ := uniform_safe_box_mass K hK + refine ⟨C,B₀,max W (Real.exp 1),hC,hB₀,hW.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw₀ hw htop xi Clen hxi hClen hcomp hsmall z hi h199 h23 hz hcut hclosed hpower L alpha beta + have hlog : 1 ≤ Real.log w := by + have hh := Real.log_le_log (Real.exp_pos 1) ((le_max_right _ _).trans hw₀) + simpa only [Real.log_exp] using hh + have hmesh : 2*(xi/Real.log w) ≤ 6*(2*Clen*xi) := by + have hh := div_le_self hxi.le hlog + nlinarith + exact hTotal B w top hB ((le_max_left _ _).trans hw₀) hw htop xi Clen hxi + (by linarith) hcomp hsmall z hi h199 h23 hz hcut hclosed hpower + (geometricBoxes hw htop hxi Clen B K L alpha beta z) + (geometric_box_anchor hw htop hxi (by linarith) hcomp hmesh z) + +theorem unlisted_box_transfer {w top xi Cs C B K L alpha beta sigma A : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hsigma : 0 ≤ sigma) + (a : ℕ → ℕ) (z : Node) (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (F : Finset (List ℕ)) + (hTotal : B^2*(∑ m∈geometricBoxes hw htop hxi C B K L alpha beta z,selectionMass (globalBins w top xi) m) ≤ A) + (hBox : ∀ m∈geometricBoxes hw htop hxi C B K L alpha beta z, + selectedWordMass (globalBins w top xi) m + (ExpandedCompactPartition.unlistedGeometric hw htop hxi Cs C B K L alpha beta a z Q F) + ≤ sigma*selectionMass (globalBins w top xi) m) : + B^2*(∑ ps∈ExpandedCompactPartition.unlistedGeometric hw htop hxi Cs C B K L alpha beta a z Q F, + ErdosPrimeInputs.PrimePrefixMass.prefixWeight ps) ≤ sigma*A := by + rw [unlisted_geometric_box_mass hw htop hxi a z Q F] + calc + _ ≤ B^2*(∑ m∈geometricBoxes hw htop hxi C B K L alpha beta z,sigma*selectionMass (globalBins w top xi) m) := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum hBox) (sq_nonneg B) + _ = sigma*(B^2*(∑ m∈geometricBoxes hw htop hxi C B K L alpha beta z,selectionMass (globalBins w top xi) m)) := by + rw [← Finset.mul_sum] + ring + _ ≤ _ := mul_le_mul_of_nonneg_left hTotal hsigma +end NumberTheoryLean.GeometricTotalBoxMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/GoodSampleSelection.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GoodSampleSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9f2484867fa8efc734da5df64869c25b9d48d3a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GoodSampleSelection.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.Jacobsthal.Paths.SampleWitnessAverage + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseSampling +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem exists_reward_cost_sample {Ω : Type*} (S : Finset Ω) (hS : S.Nonempty) + (reward cost : Ω → ℝ) (gamma tau : ℝ) (hg : 0 < gamma) (ht : 0 < tau) + (hr : ∀ s ∈ S,reward s ≤ 1) (hc : ∀ s ∈ S,0 ≤ cost s) + (hreward : gamma*(S.card : ℝ) ≤ ∑ s ∈ S,reward s) + (hcost : (∑ s ∈ S,cost s) ≤ (gamma*tau/4)*(S.card : ℝ)) : + ∃ s ∈ S,gamma/2 ≤ reward s ∧ cost s ≤ tau := by + by_contra h + push Not at h + have hpoint (s : Ω) (hs : s ∈ S) : reward s ≤ gamma/2+cost s/tau := by + by_cases hh : gamma/2 ≤ reward s + · have hct : tau < cost s := h s hs hh + have hone : (1 : ℝ) < cost s/tau := (lt_div_iff₀ ht).mpr (by simpa using hct) + linarith [hr s hs] + · have hcn : 0 ≤ cost s/tau := div_nonneg (hc s hs) ht.le + linarith + have hupper : (∑ s ∈ S,reward s) ≤ (S.card : ℝ)*(gamma/2)+(∑ s ∈ S,cost s)/tau := by + calc + _ ≤ ∑ s ∈ S,(gamma/2+cost s/tau) := Finset.sum_le_sum hpoint + _ = _ := by + rw [Finset.sum_add_distrib] + simp only [Finset.sum_const,nsmul_eq_mul,← Finset.sum_div] + have hsmall : (∑ s ∈ S,cost s)/tau ≤ (gamma/4)*(S.card : ℝ) := by + apply (div_le_iff₀ ht).mpr + nlinarith only [hcost] + have hN : (0 : ℝ) < S.card := by exact_mod_cast Finset.card_pos.mpr hS + have hpos : 0 < gamma*(S.card : ℝ) := mul_pos hg hN + nlinarith only [hreward,hupper,hsmall,hpos] + +theorem selectedFraction_le_one {α β : Type*} (A : Finset α) (U : Finset β) + (witness : α → β → Prop) (h : ℕ) (e : Sample U h) (hA : 0 < A.card) : + selectedFraction A U witness h e ≤ 1 := by + have hAR : (0 : ℝ) < A.card := by exact_mod_cast hA + apply (div_le_iff₀ hAR).mpr + have hh : (selectedPairs A U witness h e).card ≤ A.card := Finset.card_filter_le A _ + simpa only [one_mul] using (Nat.cast_le.mpr hh : ((selectedPairs A U witness h e).card : ℝ) ≤ A.card) + +theorem exists_good_distinct_sample {α β : Type*} (A : Finset α) (U : Finset β) + (witness : α → β → Prop) (h : ℕ) (beta tau : ℝ) (hb : 0 < beta) (hb1 : beta ≤ 1) + (ht : 0 < tau) (hA : 0 < A.card) (hU : 0 < U.card) + (hdense : beta*(A.card : ℝ)*(U.card : ℝ) ≤ ((witnessPairs A U witness).card : ℝ)) + (hsize : 4*(h : ℝ)/beta ≤ (U.card : ℝ)) (cost : Sample U h → ℝ) + (hc : ∀ e,0 ≤ cost e) + (hcost : sampleAverage U h cost ≤ (((beta/2)*(beta/4)^h)*tau/4)) : + ∃ e : Sample U h,((beta/2)*(beta/4)^h)/2 ≤ selectedFraction A U witness h e ∧ cost e ≤ tau := by + let gamma := (beta/2)*(beta/4)^h + have hg : 0 < gamma := by dsimp [gamma];positivity + have hlen := sample_length_le U.card h beta hb hb1 hsize + have hn : 0 < Fintype.card (Sample U h) := by rw [sample_card];exact Nat.descFactorial_pos.mpr hlen + have hnR : (0 : ℝ) < Fintype.card (Sample U h) := by exact_mod_cast hn + have hreward := sample_incidence_average_lower A U witness h beta hb hb1 hA hU hdense hsize + have hreward' : gamma*(Fintype.card (Sample U h) : ℝ) ≤ + ∑ e : Sample U h,selectedFraction A U witness h e := (le_div_iff₀ hnR).mp hreward + have hcost' : (∑ e : Sample U h,cost e) ≤ (gamma*tau/4)*(Fintype.card (Sample U h) : ℝ) := + (div_le_iff₀ hnR).mp hcost + obtain ⟨e,_he,her,hec⟩ := exists_reward_cost_sample (Finset.univ : Finset (Sample U h)) + (Finset.card_pos.mp (by simpa only [Finset.card_univ] using hn)) + (selectedFraction A U witness h) cost gamma tau hg ht + (fun e _ => selectedFraction_le_one A U witness h e hA) (fun e _ => hc e) + (by simpa only [Finset.card_univ] using hreward') (by simpa only [Finset.card_univ] using hcost') + exact ⟨e,her,hec⟩ + +end ErdosInverseSampling + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/GridWeightComparison.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GridWeightComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..089067a5ed763f7479905191df962ccb3fafb817 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/GridWeightComparison.lean @@ -0,0 +1,142 @@ +import OAI.NumberTheory.Jacobsthal.Primes.ConditionalPrimeBins +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialMesh + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ConditionalBinRate + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ConditionalPrimeBins ExponentialMesh DerivativeWeights WeightFutureIntegrals + + theorem relative_error_rate {c C κ : ℝ} (hC : 0 ≤ C) (hκ : 0 < κ) (hc : 4*κ ≤ c) : + ∀ᶠ w : ℝ in atTop, ∀ S : ℝ, 0 ≤ S → S ≤ (Real.log w)^3 → + C*(S+1)*Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))/mesh κ w ≤ + Real.exp (-(κ/2)*Real.sqrt (Real.log w)) := by + filter_upwards [log_power_exp_absorption (4*C) 3 hκ, + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with w hbound hlog + intro S hS0 hS + have hpow : 1 ≤ (Real.log w)^3 := one_le_pow₀ hlog + have hSp : S+1 ≤ 2*(Real.log w)^3 := by linarith + have herror := prime_error_over_mesh hκ.le hc (by linarith : 0 ≤ Real.log w) + have hm := mesh_pos κ w + calc + _ = (C*(S+1))*(Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))/mesh κ w) := by ring + _ ≤ (C*(2*(Real.log w)^3))*(2*Real.exp (-κ*Real.sqrt (Real.log w))) := mul_le_mul + (mul_le_mul_of_nonneg_left hSp hC) herror (by positivity) (by positivity) + _ = (4*C)*(Real.log w)^3*Real.exp (-κ*Real.sqrt (Real.log w)) := by ring + _ ≤ _ := hbound + +theorem actual_conditional_bin_rate : ∃ κ₀ : ℝ, 0 < κ₀ ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∃ w₀ : ℝ, 1 < w₀ ∧ ∀ w : ℝ, w₀ ≤ w → + ∀ ell S : ℝ, 0 ≤ S → S ≤ (Real.log w)^3 → ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → + ∀ g : History w ell S start, ∀ a : ℝ, Valid g.node.side.flip a → a ≤ S → + chain w ell S start (some g) (ActualPrimeBins.liveBin a (a+mesh κ w)) ≤ + ENNReal.ofReal ((1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)))* + mesh κ w*W a*(weight g.node.side.flip a/weight g.node.side g.node.ratio)) := by + obtain ⟨c,C,wR,hc,hC,hwR,hraw⟩ := actual_conditional_bin + refine ⟨c/4,by positivity,?_⟩ + intro κ hκ hκc + have hcκ : 4*κ ≤ c := by linarith + obtain ⟨W₀,hW₀⟩ := eventually_atTop.mp (relative_error_rate hC.le hκ hcκ) + refine ⟨max wR W₀,hwR.trans_le (le_max_left _ _),?_⟩ + intro w hw ell S hS0 hS start hell hr hs g a ha haS + have hm := mesh_pos κ w + have hrel := hW₀ w ((le_max_right _ _).trans hw) S hS0 hS + have hb := hraw w ((le_max_left _ _).trans hw) ell S start hell hr hs g a (mesh κ w) ha hm (mesh_le_one hκ.le w) + have hv : Valid g.node.side g.node.ratio := terminal_valid hs g.admissible + have hW := (W_pos (valid_pos ha)).le + have hratio : 0 ≤ weight g.node.side.flip a/weight g.node.side g.node.ratio := + (div_pos (weight_pos ha) (weight_pos hv)).le + have hδ : C*(a+1)*Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))/mesh κ w ≤ + Real.exp (-(κ/2)*Real.sqrt (Real.log w)) := by + apply le_trans _ hrel + apply div_le_div_of_nonneg_right _ hm.le + exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (by linarith : a+1 ≤ S+1) hC.le) (Real.exp_pos _).le + refine hb.trans (ENNReal.ofReal_le_ofReal ?_) + exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (add_le_add_right hδ 1) hm.le) hW) hratio + +end NumberTheoryLean.ConditionalBinRate + +end + +section + +namespace NumberTheoryLean.GridWeightComparison + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open WeightGlobalBounds ConditionalBinRate ExponentialMesh DerivativeWeights WeightFutureIntegrals + +theorem weight_local_ratio : ∃ L : ℝ, 0 < L ∧ ∀ S : ℝ, 3 ≤ S → ∀ i : Side, ∀ u s h : ℝ, + Valid i u → Valid i s → s ≤ S → u ≤ s → s ≤ u+h → + weight i u/weight i s ≤ Real.exp (L*(1+S)^3*h) := by + obtain ⟨L,hL,hbound⟩ := weights_log_lipschitz + refine ⟨L,hL,?_⟩ + intro S hS i u s h hu hs hsS hus hsu + have hlog : |Real.log (weight i u)-Real.log (weight i s)| ≤ L*(1+S)^3*|u-s| := by + cases i with + | even => exact (hbound S hS).1 u s hu hs (hus.trans hsS) hsS + | odd => exact (hbound S hS).2 u s hu hs (hus.trans hsS) hsS + have habs : |u-s| ≤ h := by + rw [abs_sub_comm u s,abs_of_nonneg (sub_nonneg.mpr hus)] + linarith + have hdiff : Real.log (weight i u)-Real.log (weight i s) ≤ L*(1+S)^3*h := + ((le_abs_self _).trans hlog).trans (mul_le_mul_of_nonneg_left habs (by positivity)) + have he := Real.exp_le_exp.mpr hdiff + rwa [Real.exp_sub,Real.exp_log (weight_pos hu),Real.exp_log (weight_pos hs)] at he + +theorem actual_parent_bin_upper : ∃ κ₀ L : ℝ, 0 < κ₀ ∧ 0 < L ∧ + ∀ κ : ℝ, 0 < κ → κ ≤ κ₀ → ∃ w₀ : ℝ, 1 < w₀ ∧ ∀ w : ℝ, w₀ ≤ w → + ∀ ell S : ℝ, 3 ≤ S → S ≤ (Real.log w)^3 → ∀ start : Node, + 1 ≤ ell → 0 < start.gap → Valid start.side start.ratio → + ∀ g : History w ell S start, ∀ u a : ℝ, + Valid g.node.side u → Valid g.node.side.flip a → g.node.ratio ≤ S → a ≤ S → + u ≤ g.node.ratio → g.node.ratio ≤ u+mesh κ w → + chain w ell S start (some g) (ActualPrimeBins.liveBin a (a+mesh κ w)) ≤ + ENNReal.ofReal ((1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)))* + Real.exp (L*(1+S)^3*mesh κ w)*mesh κ w*W a*(weight g.node.side.flip a/weight g.node.side u)) := by + obtain ⟨κ₀,hκ₀,hconditional⟩ := actual_conditional_bin_rate + obtain ⟨L,hL,hlocal⟩ := weight_local_ratio + refine ⟨κ₀,L,hκ₀,hL,?_⟩ + intro κ hκ hκle + obtain ⟨w₀,hw₀,hrow⟩ := hconditional κ hκ hκle + refine ⟨w₀,hw₀,?_⟩ + intro w hw ell S hS3 hS start hell hr hs g u a hu ha hgS haS hus hsu + have hgv : Valid g.node.side g.node.ratio := terminal_valid hs g.admissible + have hratio := hlocal S hS3 g.node.side u g.node.ratio (mesh κ w) hu hgv hgS hus hsu + have htarget : weight g.node.side.flip a/weight g.node.side g.node.ratio ≤ + (weight g.node.side.flip a/weight g.node.side u)*Real.exp (L*(1+S)^3*mesh κ w) := by + have heq : weight g.node.side.flip a/weight g.node.side g.node.ratio = + (weight g.node.side.flip a/weight g.node.side u)*(weight g.node.side u/weight g.node.side g.node.ratio) := by + field_simp [(weight_pos hu).ne'] + rw [heq] + exact mul_le_mul_of_nonneg_left hratio (div_pos (weight_pos ha) (weight_pos hu)).le + have hm := mesh_pos κ w + have hW := (W_pos (valid_pos ha)).le + have hM : 0 ≤ (1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)))*mesh κ w*W a := by positivity + refine (hrow w hw ell S (by linarith) hS start hell hr hs g a ha haS).trans (ENNReal.ofReal_le_ofReal ?_) + calc + _ ≤ ((1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)))*mesh κ w*W a)* + ((weight g.node.side.flip a/weight g.node.side u)*Real.exp (L*(1+S)^3*mesh κ w)) := + mul_le_mul_of_nonneg_left htarget hM + _ = _ := by ring + +end NumberTheoryLean.GridWeightComparison + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/HorizonMeshSmallness.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/HorizonMeshSmallness.lean new file mode 100644 index 0000000000000000000000000000000000000000..d1fe0a52913d66f096bdf3d3135dca50969bc13e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/HorizonMeshSmallness.lean @@ -0,0 +1,82 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.UniformFailureBudget +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialMesh + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.HorizonMeshSmallness + +open _root_.Set _root_.Filter +open scoped Topology +open UniformFailureBudget ExponentialMesh + +theorem horizon_mesh_smallness {A D κ : ℝ} (hA : 0 ≤ A) (hD : 0 ≤ D) (hκ : 0 < κ) : + ∀ᶠ w : ℝ in atTop, ∀ S : ℝ, 0 ≤ S → S ≤ (Real.log w)^3 → ∀ N : ℕ, + (N:ℝ) ≤ A*(Real.log w)^3 → + 2*mesh κ w ≤ 1 ∧ 4*(N:ℝ)*mesh κ w ≤ 1 ∧ D*(1+S)^3*mesh κ w ≤ 1 ∧ + upperDisplacement S (mesh κ w) N+mesh κ w ≤ 1 := by + filter_upwards [log_power_exp_absorption 2 0 hκ, + log_power_exp_absorption (4*A) 3 hκ, + log_power_exp_absorption (8*D) 9 hκ, + log_power_exp_absorption (24*A+1) 6 hκ, + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with w htwo hclockB hparentB hupperB hlog + intro S hS hSP N hNP + let x := Real.log w + let e := Real.exp (-κ*Real.sqrt (Real.log w)) + let τ := mesh κ w + have hx : 1 ≤ x := hlog + have hx0 : 0 ≤ x := by linarith + have hx3 : 1 ≤ x^3 := one_le_pow₀ hx + have hx6 : 1 ≤ x^6 := one_le_pow₀ hx + have hSp : S+1 ≤ 2*x^3 := by change S ≤ x^3 at hSP; linarith + have he : 0 ≤ e := (Real.exp_pos _).le + have hτ : 0 < τ := mesh_pos κ w + have hτe : τ ≤ e := mesh_upper κ w + have hsmall : Real.exp (-(κ/2)*Real.sqrt (Real.log w)) ≤ 1 := by + apply Real.exp_le_one_iff.mpr + nlinarith [Real.sqrt_nonneg (Real.log w)] + have htwo' : 2*τ ≤ 1 := by + have ht : 2*e ≤ Real.exp (-(κ/2)*Real.sqrt (Real.log w)) := by + simpa only [pow_zero,mul_one] using htwo + exact (mul_le_mul_of_nonneg_left hτe (by norm_num)).trans (ht.trans hsmall) + have hclock : 4*(N:ℝ)*τ ≤ 1 := by + calc + _ ≤ (4*(A*x^3))*e := mul_le_mul (by nlinarith : 4*(N:ℝ) ≤ 4*(A*x^3)) hτe hτ.le (by positivity) + _ = (4*A)*x^3*e := by ring + _ ≤ _ := hclockB.trans hsmall + have hparent : D*(1+S)^3*τ ≤ 1 := by + calc + _ ≤ (D*(2*x^3)^3)*e := mul_le_mul + (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (by linarith) (by linarith : 1+S ≤ 2*x^3) 3) hD) + hτe hτ.le (by positivity) + _ = (8*D)*x^9*e := by ring + _ ≤ _ := hparentB.trans hsmall + have hU : upperDisplacement S τ N ≤ 24*A*x^6*e := by + have hexp := exp_increment (show 0 ≤ 4*(N:ℝ)*τ by positivity) hclock + have hNmul : 12*(N:ℝ)*τ ≤ 12*(A*x^3)*e := + mul_le_mul (by nlinarith : 12*(N:ℝ) ≤ 12*(A*x^3)) hτe hτ.le (by positivity) + calc + _ ≤ (S+1)*(12*(N:ℝ)*τ) := by + unfold upperDisplacement + apply mul_le_mul_of_nonneg_left _ (by linarith : 0 ≤ S+1) + nlinarith + _ ≤ (2*x^3)*(12*(A*x^3)*e) := mul_le_mul hSp hNmul (by positivity) (by positivity) + _ = _ := by ring + have he6 : e ≤ x^6*e := by simpa only [one_mul] using mul_le_mul_of_nonneg_right hx6 he + have hUpper : upperDisplacement S τ N+τ ≤ 1 := by + calc + _ ≤ (24*A+1)*x^6*e := by nlinarith + _ ≤ _ := hupperB.trans hsmall + exact ⟨htwo',hclock,hparent,hUpper⟩ + +end NumberTheoryLean.HorizonMeshSmallness + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/InflectionTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/InflectionTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..4b8f060efb049d818514a889ad9482954a40f768 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/InflectionTransport.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RealCriticalPoints +import OAI.NumberTheory.Jacobsthal.Estimates.RegularImplicitArc + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosDivisibleInflection + +open ErdosImplicitCurvature ErdosCriticalGeometry + +theorem peval_eq_eval_pair (Q : MV ℝ) (x y : ℝ) : + peval Q x y = MvPolynomial.eval ![x,y] Q := by + have h : (fun i : Fin 2 => if i = 0 then x else y) = ![x,y] := by + funext i + fin_cases i <;> simp + simp only [peval,h] + +theorem complexify_inflection (Q : MV ℝ) : + complexify (inflectionPolynomial Q) = inflection (complexify Q) := by + unfold inflectionPolynomial partialX partialY inflection + simp only [complexify, map_add, map_sub, map_mul, map_pow, map_ofNat, + ← MvPolynomial.pderiv_map, map_neg] + ring + +theorem inflection_zero_of_complex_divisibility (Q : MV ℝ) + (hdiv : complexify Q ∣ inflection (complexify Q)) (x y : ℝ) + (hQ : peval Q x y = 0) : peval (inflectionPolynomial Q) x y = 0 := by + have hQC : MvPolynomial.eval ![(x : ℂ),(y : ℂ)] (complexify Q) = 0 := by + rw [complexify_eval, ← peval_eq_eval_pair, hQ] + simp + obtain ⟨H,hH⟩ := hdiv + have hIC : MvPolynomial.eval ![(x : ℂ),(y : ℂ)] (inflection (complexify Q)) = 0 := by + rw [hH, map_mul, hQC, zero_mul] + rw [← complexify_inflection, complexify_eval, Complex.ofReal_eq_zero] at hIC + rwa [peval_eq_eval_pair] + +theorem real_divisibility_to_complex (Q : MV ℝ) (hdiv : Q ∣ inflectionPolynomial Q) : + complexify Q ∣ inflection (complexify Q) := by + rw [← complexify_inflection] + exact map_dvd (MvPolynomial.map (algebraMap ℝ ℂ)) hdiv + +theorem zero_second_derivative_on_divisible_graph (Q : MV ℝ) (f : ℝ → ℝ) (a b : ℝ) + (hdiv : complexify Q ∣ inflection (complexify Q)) + (hf : ContDiffOn ℝ 2 f (Set.Ioo a b)) + (hcurve : ∀ t ∈ Set.Ioo a b, peval Q t (f t) = 0) + (hQy : ∀ t ∈ Set.Ioo a b, peval (partialY Q) t (f t) ≠ 0) : + ∀ t ∈ Set.Ioo a b, deriv (deriv f) t = 0 := by + intro t ht + apply (curvature_zero_iff Q f isOpen_Ioo hf hcurve ht (hQy t ht)).mpr + exact inflection_zero_of_complex_divisibility Q hdiv t (f t) (hcurve t ht) + +end ErdosDivisibleInflection + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalCuts.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalCuts.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb134e7e6dc4e4cc362fee2a5db5713f186f105d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalCuts.lean @@ -0,0 +1,63 @@ +import Mathlib.Data.Int.Interval +import OAI.NumberTheory.Jacobsthal.Harmonic.CharacterChord + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHyperbolaFourier + +noncomputable def lowerCut (x : ℝ) (closed : Bool) : ℤ := + if closed then ⌈x⌉ else ⌊x⌋+1 + +noncomputable def upperCut (x : ℝ) (closed : Bool) : ℤ := lowerCut x (!closed) + +theorem lowerCut_le_iff (x : ℝ) (closed : Bool) (j : ℤ) : + lowerCut x closed ≤ j ↔ if closed then x ≤ (j : ℝ) else x < (j : ℝ) := by + cases closed <;> simp [lowerCut, Int.floor_lt, Int.ceil_le] + +theorem lt_upperCut_iff (x : ℝ) (closed : Bool) (j : ℤ) : + j < upperCut x closed ↔ if closed then (j : ℝ) ≤ x else (j : ℝ) < x := by + cases closed <;> simp [upperCut, lowerCut, Int.le_floor, Int.lt_ceil] + +theorem lowerCut_bounds (x : ℝ) (closed : Bool) : + x ≤ (lowerCut x closed : ℝ) ∧ (lowerCut x closed : ℝ) ≤ x+1 := by + have hf := Int.floor_le x + have hf' := Int.lt_floor_add_one x + have hc := Int.le_ceil x + have hc' := Int.ceil_lt_add_one x + cases closed <;> simp only [lowerCut, Bool.false_eq_true, ite_false, ite_true, Int.cast_add, + Int.cast_one] <;> constructor <;> linarith + +theorem upperCut_bounds (x : ℝ) (closed : Bool) : + x ≤ (upperCut x closed : ℝ) ∧ (upperCut x closed : ℝ) ≤ x+1 := + lowerCut_bounds x (!closed) + +theorem cut_count_error (x y : ℝ) (hxy : x ≤ y) (lc rc : Bool) : + |(((upperCut y rc-lowerCut x lc).toNat : ℕ) : ℝ) - (y-x)| ≤ 1 := by + obtain ⟨hL, hL'⟩ := lowerCut_bounds x lc + obtain ⟨hU, hU'⟩ := upperCut_bounds y rc + by_cases hpos : 0 ≤ upperCut y rc-lowerCut x lc + · have hc : (((upperCut y rc-lowerCut x lc).toNat : ℕ) : ℝ) = + (upperCut y rc : ℝ)-(lowerCut x lc : ℝ) := by + have h := congrArg (fun z : ℤ => (z : ℝ)) (Int.toNat_of_nonneg hpos) + push_cast at h + exact h + rw [hc, abs_le] + constructor <;> linarith + · have hc : (upperCut y rc-lowerCut x lc).toNat = 0 := Int.toNat_of_nonpos (by omega) + have hUL : (upperCut y rc : ℝ) ≤ (lowerCut x lc : ℝ) := by exact_mod_cast (by omega : upperCut y rc ≤ lowerCut x lc) + rw [hc] + norm_num only [Nat.cast_zero, zero_sub, abs_neg] + rw [abs_of_nonneg (sub_nonneg.mpr hxy)] + linarith + +end ErdosHyperbolaFourier + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalHyperbolaAdapter.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalHyperbolaAdapter.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6243f37d85d16fb5605d0d607874f993261274a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalHyperbolaAdapter.lean @@ -0,0 +1,189 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RealProgressionPoints +import OAI.NumberTheory.Jacobsthal.Harmonic.HyperbolaFourier + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosHyperbolaFourier + +theorem norm_characterProgression_le (N : ℕ) [NeZero N] + (start step : ZMod N) (J : ℕ) (hs : step ≠ 0) : + ‖characterProgression N start step J‖ ≤ (N : ℝ)/(cyclicDistance N step : ℝ) := by + have hN : (0 : ℝ) < N := by exact_mod_cast NeZero.pos N + have hd : (0 : ℝ) < cyclicDistance N step := by + exact_mod_cast cyclicDistance_pos N step hs + have hm := (mul_le_mul_of_nonneg_left (standard_character_chord_lower N step) + (norm_nonneg (characterProgression N start step J))).trans + (norm_characterProgression_mul_chord N start step J) + have hm' : ‖characterProgression N start step J‖ * (4*(cyclicDistance N step : ℝ)) ≤ + 2*(N : ℝ) := by + apply (div_le_iff₀ hN).mp + convert hm using 1; ring + apply (le_div_iff₀ hd).mpr + nlinarith + +theorem characterProgression_modulus_one (start step : ZMod 1) (J : ℕ) : + characterProgression 1 start step J = J := by + have hs : start = 0 := Subsingleton.elim _ _ + have ht : step = 0 := Subsingleton.elim _ _ + rw [hs, ht, characterProgression_zero_step] + simp + +end ErdosHyperbolaFourier + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaFourier + +noncomputable def intervalWeight (N : ℕ) [NeZero N] (h : ZMod N) + (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) : ℂ := + ∑ z ∈ progressionPoints x y lc rc T a, ZMod.stdAddChar (-h*(z : ZMod N)) + +theorem intervalWeight_eq_progression (N : ℕ) [NeZero N] (h : ZMod N) + (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) (hT : 0 < T) : + intervalWeight N h x y lc rc T a = + characterProgression N (-h*(progressionPoint a T (lowerIndex x T a lc) : ZMod N)) + (-h*(T : ZMod N)) (upperIndex y T a rc-lowerIndex x T a lc).toNat := by + unfold intervalWeight progressionPoints + rw [Finset.sum_image] + · rw [Int.Ico_eq_finset_map, Finset.sum_map] + unfold characterProgression + apply Finset.sum_congr rfl + intro i _ + congr 1 + change -h * (((a+(T : ℤ)*(lowerIndex x T a lc+(i : ℤ)) : ℤ)) : ZMod N) = + -h * (((a+(T : ℤ)*lowerIndex x T a lc : ℤ)) : ZMod N) + + (i : ZMod N)*(-h*(T : ZMod N)) + push_cast + ring + · intro i _ j _ hij + exact progressionPoint_injective a T hT hij + +theorem intervalWeight_zero (N : ℕ) [NeZero N] (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) : + intervalWeight N 0 x y lc rc T a = (progressionPoints x y lc rc T a).card := by + simp [intervalWeight] + +theorem intervalWeight_zero_error (N : ℕ) [NeZero N] (x y : ℝ) (hxy : x ≤ y) + (lc rc : Bool) (T : ℕ) (a : ℤ) (hT : 0 < T) : + ‖intervalWeight N 0 x y lc rc T a - (((y-x)/(T : ℝ) : ℝ) : ℂ)‖ ≤ 1 := by + rw [intervalWeight_zero] + have h := progressionPoints_count_error x y hxy lc rc T a hT + simpa only [← Complex.ofReal_natCast, ← Complex.ofReal_sub, + Complex.norm_real, Real.norm_eq_abs] using h + +theorem norm_intervalWeight_le (N : ℕ) [NeZero N] (h : ZMod N) + (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) (hT : 0 < T) + (hs : -h*(T : ZMod N) ≠ 0) : + ‖intervalWeight N h x y lc rc T a‖ ≤ (N : ℝ)/(cyclicDistance N (-h*(T : ZMod N)) : ℝ) := by + rw [intervalWeight_eq_progression N h x y lc rc T a hT] + exact norm_characterProgression_le N _ _ _ hs + +theorem norm_intervalWeight_le_of_coprime (N : ℕ) [NeZero N] (h : ZMod N) (hh : h ≠ 0) + (x y : ℝ) (lc rc : Bool) (T : ℕ) (a : ℤ) (hT : 0 < T) (hTN : T.Coprime N) : + ‖intervalWeight N h x y lc rc T a‖ ≤ (N : ℝ)/(cyclicDistance N (-h*(T : ZMod N)) : ℝ) := by + have hunit : IsUnit (T : ZMod N) := (ZMod.isUnit_iff_coprime T N).mpr hTN + apply norm_intervalWeight_le N h x y lc rc T a hT + intro hs + exact hh (neg_eq_zero.mp (hunit.mul_left_eq_zero.mp hs)) + +end ErdosHyperbolaFourier + +end + +section + +namespace ErdosHyperbolaFourier + +theorem progressionPoints_eq_literal_filter (x y : ℝ) (lc rc : Bool) + (T : ℕ) (a : ℤ) (hT : 0 < T) : + progressionPoints x y lc rc T a = + (Finset.Icc ⌈x⌉ ⌊y⌋).filter (fun z : ℤ => + (if lc then x ≤ (z : ℝ) else x < (z : ℝ)) ∧ + (if rc then (z : ℝ) ≤ y else (z : ℝ) < y) ∧ Int.ModEq (T : ℤ) z a) := by + ext z + rw [mem_progressionPoints_iff x y lc rc T a z hT, Finset.mem_filter, Finset.mem_Icc, + Int.ceil_le, Int.le_floor] + have hlo : (if lc then x ≤ (z : ℝ) else x < (z : ℝ)) → x ≤ (z : ℝ) := by + cases lc with + | false => exact fun h => h.le + | true => exact id + have hhi : (if rc then (z : ℝ) ≤ y else (z : ℝ) < y) → (z : ℝ) ≤ y := by + cases rc with + | false => exact fun h => h.le + | true => exact id + constructor + · intro h + exact ⟨⟨hlo h.1, hhi h.2.1⟩, h⟩ + · exact fun h => h.2 + +theorem progressionPoints_open_singleton_empty (x : ℝ) (T : ℕ) (a : ℤ) (hT : 0 < T) : + progressionPoints x x false false T a = ∅ := by + apply Finset.eq_empty_of_forall_notMem + intro z hz + obtain ⟨hlo, hhi, _⟩ := (mem_progressionPoints_iff x x false false T a z hT).mp hz + exact (lt_asymm hlo hhi) + +theorem literal_filter_zero_weight (N : ℕ) [NeZero N] (x y : ℝ) (lc rc : Bool) + (T : ℕ) (a : ℤ) (hT : 0 < T) : + intervalWeight N 0 x y lc rc T a = + (((Finset.Icc ⌈x⌉ ⌊y⌋).filter (fun z : ℤ => + (if lc then x ≤ (z : ℝ) else x < (z : ℝ)) ∧ + (if rc then (z : ℝ) ≤ y else (z : ℝ) < y) ∧ Int.ModEq (T : ℤ) z a)).card : ℂ) := by + rw [intervalWeight_zero, progressionPoints_eq_literal_filter x y lc rc T a hT] + +end ErdosHyperbolaFourier + +end + +section + +open scoped BigOperators +namespace ErdosHyperbolaIdentities + +structure ProgressionInterval where + left : ℝ + right : ℝ + leftClosed : Bool + rightClosed : Bool + step : ℕ + residue : ℤ + step_pos : 0 < step + +noncomputable def ProgressionInterval.points (P : ProgressionInterval) : Finset ℤ := + ErdosHyperbolaFourier.progressionPoints P.left P.right P.leftClosed P.rightClosed P.step P.residue + +noncomputable def ProgressionInterval.weight (P : ProgressionInterval) (N : ℕ) [NeZero N] + (h : ZMod N) : ℂ := + ErdosHyperbolaFourier.intervalWeight N h P.left P.right P.leftClosed P.rightClosed P.step P.residue + +theorem mem_interval_points (P : ProgressionInterval) (x : ℤ) : + x ∈ P.points ↔ + (if P.leftClosed then P.left ≤ (x : ℝ) else P.left < (x : ℝ)) ∧ + (if P.rightClosed then (x : ℝ) ≤ P.right else (x : ℝ) < P.right) ∧ + Int.ModEq (P.step : ℤ) x P.residue := + ErdosHyperbolaFourier.mem_progressionPoints_iff P.left P.right P.leftClosed P.rightClosed + P.step P.residue x P.step_pos + +theorem integerWeight_interval (N : ℕ) [NeZero N] (P : ProgressionInterval) (h : ZMod N) : + integerWeight N P.points h = P.weight N h := rfl + +theorem interval_count_eq_fourier (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (P Q : ProgressionInterval) : + ((hyperbolaPairs N T a c P.points Q.points).card : ℂ) = + (∑ h : ZMod N, ∑ k : ZMod N, + P.weight N h * Q.weight N k * restrictedSum N T hT a c h k)/(N : ℂ)^2 := by + simpa only [integerWeight_interval] using count_eq_fourier N T hT a c P.points Q.points + +end ErdosHyperbolaIdentities + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalPairCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalPairCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..14c38ed0b0aceb4b41812e38300ede9f0f4cae08 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalPairCount.lean @@ -0,0 +1,59 @@ +import Mathlib.Data.Int.CardIntervalMod +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRandomVariance +attribute [local instance] Classical.propDecidable + +noncomputable def congruenceIndicator (d i j : ℕ) : ℝ := if Nat.ModEq d i j then 1 else 0 + +theorem congruenceIndicator_symm (d i j : ℕ) : + congruenceIndicator d i j = congruenceIndicator d j i := by + have he : Nat.ModEq d i j ↔ Nat.ModEq d j i := ⟨fun h => h.symm, fun h => h.symm⟩ + simp only [congruenceIndicator, he] + +theorem residue_indicator_sum (J d a : ℕ) : + (∑ i ∈ Finset.range J, congruenceIndicator d i a) = + (((Finset.range J).filter (fun i => Nat.ModEq d i a)).card : ℝ) := by + simp only [Finset.card_filter, Nat.cast_sum, Nat.cast_ite, Nat.cast_one, Nat.cast_zero, + congruenceIndicator] + +theorem residue_indicator_bound (J d a : ℕ) (hd : 0 < d) : + (∑ i ∈ Finset.range J, congruenceIndicator d i a) ≤ (J : ℝ)/d+1 := by + rw [residue_indicator_sum] + have hc : ((Finset.range J).filter (fun i => Nat.ModEq d i a)).card ≤ J/d+1 := by + rw [← Nat.count_eq_card_filter_range, Nat.count_modEq_card J hd a] + split_ifs <;> omega + have hcr : (((Finset.range J).filter (fun i => Nat.ModEq d i a)).card : ℝ) ≤ + (J/d : ℕ)+1 := by exact_mod_cast hc + have hdiv : ((J/d : ℕ) : ℝ) ≤ (J : ℝ)/d := by + apply (le_div_iff₀ (show (0 : ℝ) < d by exact_mod_cast hd)).mpr + exact_mod_cast Nat.div_mul_le_self J d + linarith + +theorem interval_pair_congruence_bound (J d : ℕ) (hd : 0 < d) : + (∑ i ∈ Finset.range J, ∑ j ∈ Finset.range J, congruenceIndicator d i j) ≤ + (J : ℝ)^2/d+J := by + calc + _ = ∑ i ∈ Finset.range J, ∑ j ∈ Finset.range J, congruenceIndicator d j i := by + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + exact congruenceIndicator_symm d i j + _ ≤ ∑ _i ∈ Finset.range J, ((J : ℝ)/d+1) := + Finset.sum_le_sum (fun i _ => residue_indicator_bound J d i hd) + _ = _ := by simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul]; ring + +end ErdosRandomVariance + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalSpectrumCoefficients.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalSpectrumCoefficients.lean new file mode 100644 index 0000000000000000000000000000000000000000..e3e5cfc4d39581602b33ed4fe2e9178ed3a8311c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/IntervalSpectrumCoefficients.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.IntegerResidueVariance + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseSpectrum +attribute [local instance] Classical.decEq + +noncomputable def intervalCoordinates (S : Finset ℤ) (M : ℤ) (J : ℕ) : Finset ℕ := + (Finset.range J).filter (fun j : ℕ => M+(j : ℤ) ∈ S) + +theorem intervalCoordinates_image (S : Finset ℤ) (M : ℤ) (J : ℕ) + (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) : + (intervalCoordinates S M J).image (fun j : ℕ => M+(j : ℤ)) = S := by + ext x + constructor + · intro hx + obtain ⟨j,hj,rfl⟩ := Finset.mem_image.mp hx + exact (Finset.mem_filter.mp hj).2 + · intro hx + have hr := Finset.mem_Ico.mp (hS hx) + let j := (x-M).toNat + have he : (j : ℤ) = x-M := Int.toNat_of_nonneg (by omega) + have hj : j < J := by + have hh : (j : ℤ) < (J : ℤ) := by rw [he];omega + exact_mod_cast hh + have hpoint : M+(j : ℤ) = x := by rw [he];ring + exact Finset.mem_image.mpr ⟨j,Finset.mem_filter.mpr ⟨Finset.mem_range.mpr hj,hpoint.symm ▸ hx⟩,hpoint⟩ + +theorem intervalCoordinates_card (S : Finset ℤ) (M : ℤ) (J : ℕ) + (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) : (intervalCoordinates S M J).card = S.card := by + have hi : Function.Injective (fun j : ℕ => M+(j : ℤ)) := + fun _ _ h => Int.ofNat_injective (add_left_cancel h) + have hc := Finset.card_image_of_injective (intervalCoordinates S M J) hi + exact hc.symm.trans (congrArg Finset.card (intervalCoordinates_image S M J hS)) + +noncomputable def indicatorCoefficient (S : Finset ℤ) (x : ℤ) : ℂ := if x ∈ S then 1 else 0 + +theorem indicator_weighted_sum (S : Finset ℤ) (M : ℤ) (J : ℕ) + (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) (f : ℤ → ℂ) : + (∑ j ∈ Finset.range J,indicatorCoefficient S (M+(j : ℤ))*f (M+(j : ℤ))) = ∑ x ∈ S,f x := by + have hi : Function.Injective (fun j : ℕ => M+(j : ℤ)) := + fun _ _ h => Int.ofNat_injective (add_left_cancel h) + simp only [indicatorCoefficient,ite_mul,one_mul,zero_mul] + rw [← Finset.sum_filter] + change (∑ j ∈ intervalCoordinates S M J,f (M+(j : ℤ))) = ∑ x ∈ S,f x + calc + _ = ∑ x ∈ (intervalCoordinates S M J).image (fun j : ℕ => M+(j : ℤ)),f x := + (Finset.sum_image hi.injOn).symm + _ = _ := congrArg (fun V : Finset ℤ => ∑ x ∈ V,f x) (intervalCoordinates_image S M J hS) + +theorem indicator_energy (S : Finset ℤ) (M : ℤ) (J : ℕ) + (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) : + (∑ j ∈ Finset.range J,‖indicatorCoefficient S (M+(j : ℤ))‖^2) = (S.card : ℝ) := by + have he (x : ℤ) : ‖indicatorCoefficient S x‖^2 = if x ∈ S then (1 : ℝ) else 0 := by + by_cases hx : x ∈ S <;> simp [indicatorCoefficient,hx] + simp_rw [he] + rw [Finset.sum_boole] + change ((intervalCoordinates S M J).card : ℝ) = S.card + rw [intervalCoordinates_card S M J hS] + +theorem indicator_exponential_sum (S : Finset ℤ) (M : ℤ) (J : ℕ) + (hS : S ⊆ Finset.Ico M (M+(J : ℤ))) (a q : ℕ) : + (∑ j ∈ Finset.range J,indicatorCoefficient S (M+(j : ℤ))* + AdditiveLargeSieve.exponential ((((M+(j : ℤ) : ℤ) : ℝ)*(a : ℝ))/(q : ℝ))) = + exponentialSum S a q := + indicator_weighted_sum S M J hS (fun x => AdditiveLargeSieve.exponential (((x : ℝ)*(a : ℝ))/(q : ℝ))) + +end ErdosInverseSpectrum + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/LineCoordinateCounts.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/LineCoordinateCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..624b96fd75e5799f1944912abf9c45a927424615 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/LineCoordinateCounts.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.LatticeSpacing + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosRichLine +open ErdosConvexGraph + +theorem coordinate_card_le_div (X : Finset (ℤ × ℤ)) (f : ℤ × ℤ → ℤ) + (hinj : Set.InjOn f (X : Set (ℤ × ℤ))) (S : ℝ) (hS : 0 ≤ S) + (d : ℕ) (hd : 0 < d) (hbox : ∀ p ∈ X, 0 ≤ (f p : ℝ) ∧ (f p : ℝ) ≤ S) + (hdiv : ∀ p ∈ X, ∀ q ∈ X, (d : ℤ) ∣ f p-f q) : + (X.card : ℝ) ≤ S/(d : ℝ)+1 := by + classical + have hh := congruent_integer_set_card (X.image f) S hS d hd + (by rintro x hx;obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hx;exact hbox p hp) + (by + intro x hx y hy + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hx + obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hy + exact hdiv p hp q hq) + rwa [Finset.card_image_of_injOn hinj] at hh + +theorem PrimitiveIntegerLine.slope_dvd_y_difference (l : PrimitiveIntegerLine) + (p q : ℤ × ℤ) (hp : l.Contains p) (hq : l.Contains q) : + (l.slope.natAbs : ℤ) ∣ p.2-q.2 := by + have he : (l.denominator : ℤ)*(p.2-q.2) = l.slope*(p.1-q.1) := by + unfold Contains at hp hq + linear_combination hp-hq + have hg : Int.gcd l.slope (l.denominator : ℤ) = 1 := by + simpa [Int.gcd_def] using l.reduced.gcd_eq_one + have hh : l.slope ∣ p.2-q.2 := Int.dvd_of_dvd_mul_right_of_gcd_one + (by rw [he];exact dvd_mul_right _ _) hg + simpa only [Int.natCast_natAbs,abs_dvd] using hh + +theorem PrimitiveIntegerLine.y_injective (l : PrimitiveIntegerLine) (ha : l.slope ≠ 0) + (X : Finset (ℤ × ℤ)) (hline : ∀ p ∈ X, l.Contains p) : + Set.InjOn Prod.snd (X : Set (ℤ × ℤ)) := by + intro p hp q hq he + have hp' := hline p hp + have hq' := hline q hq + unfold Contains at hp' hq' + have hm : l.slope*p.1 = l.slope*q.1 := by rw [he] at hp';omega + exact Prod.ext (mul_left_cancel₀ ha hm) he + +theorem PrimitiveIntegerLine.denominator_point_count (l : PrimitiveIntegerLine) + (X : Finset (ℤ × ℤ)) (S : ℝ) (hS : 0 ≤ S) + (hinj : Set.InjOn Prod.fst (X : Set (ℤ × ℤ))) + (hbox : ∀ p ∈ X, InSquare S p) (hline : ∀ p ∈ X, l.Contains p) : + (X.card : ℝ) ≤ S/(l.denominator : ℝ)+1 := + coordinate_card_le_div X Prod.fst hinj S hS l.denominator l.denominator_pos + (fun p hp => (hbox p hp).1) + (fun p hp q hq => l.denominator_dvd_x_difference p q (hline p hp) (hline q hq)) + +theorem PrimitiveIntegerLine.slope_point_count (l : PrimitiveIntegerLine) (ha : l.slope ≠ 0) + (X : Finset (ℤ × ℤ)) (S : ℝ) (hS : 0 ≤ S) + (hbox : ∀ p ∈ X, InSquare S p) (hline : ∀ p ∈ X, l.Contains p) : + (X.card : ℝ) ≤ S/(l.slope.natAbs : ℝ)+1 := + coordinate_card_le_div X Prod.snd (l.y_injective ha X hline) S hS l.slope.natAbs + (Int.natAbs_pos.mpr ha) (fun p hp => (hbox p hp).2) + (fun p hp q hq => l.slope_dvd_y_difference p q (hline p hp) (hline q hq)) + +end ErdosRichLine + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/MarginalTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/MarginalTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..974479d72ec1106960ea25eac5247dfeedfea142 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/MarginalTransport.lean @@ -0,0 +1,146 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.MarginalGrowth +import OAI.NumberTheory.Jacobsthal.Estimates.MarginalProfiles +import OAI.NumberTheory.Jacobsthal.Primes.PrimeMarginalRecursion + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + + +namespace NumberTheoryLean.MarginalTransport + +open _root_.Set _root_.Finset _root_.MeasureTheory +open scoped ENNReal +open FinitePathGeometry PrimeGridGeometry PrimeGridKernel PrimeSideSupport +open PrimeMarginalRecursion MarginalProfiles ExponentialMesh DerivativeWeights + +noncomputable def rowFactor (L κ w S : ℝ) : ℝ := + (1+Real.exp (-(κ/2)*Real.sqrt (Real.log w)))*Real.exp (L*(1+S)^3*mesh κ w) + +theorem rowFactor_pos (L κ w S : ℝ) : 0 < rowFactor L κ w S := by unfold rowFactor; positivity + +theorem factor_eq_row (L κ w S : ℝ) : + MarginalGrowth.factor L κ w S = rowFactor L κ w S*(1+20*mesh κ w) := rfl + +theorem row_le_factor (L κ w S : ℝ) : rowFactor L κ w S ≤ MarginalGrowth.factor L κ w S := by + rw [factor_eq_row] + have hm := mesh_pos κ w + have hR := rowFactor_pos L κ w S + nlinarith + +theorem entry_nonneg (L κ w S : ℝ) (m j k : ℕ) {i : Side} + (hj : Valid i.flip (point m j)) (hk : Valid i (point m k)) : 0 ≤ entry L κ w S m i j k := by + have hm := width_nonneg m + have hW := (WeightFutureIntegrals.W_pos (valid_pos hj)).le + have hr := (div_pos (weight_pos hj) (weight_pos hk)).le + unfold entry + positivity + +theorem entry_cancel (L κ w S C : ℝ) (m n j k : ℕ) (i : Side) (F : ℝ → ℝ) + (hk : Valid i (point m k)) : + entry L κ w S m i j k*(C*(MarginalGrowth.factor L κ w S)^n*width m*weight i (point m k)*F (point m k)) = + (C*(MarginalGrowth.factor L κ w S)^n*rowFactor L κ w S*width m*weight i.flip (point m j))* + W (point m j)*(width m*F (point m k)) := by + have heq : (weight i.flip (point m j)/weight i (point m k))*weight i (point m k) = weight i.flip (point m j) := + div_mul_cancel₀ _ (weight_pos hk).ne' + calc + _ = (C*(MarginalGrowth.factor L κ w S)^n*rowFactor L κ w S*width m*W (point m j)*width m*F (point m k))* + ((weight i.flip (point m j)/weight i (point m k))*weight i (point m k)) := by unfold entry rowFactor; ring + _ = _ := by rw [heq]; ring + +theorem transport_sum (L κ w S C : ℝ) (m n j : ℕ) (i : Side) (I : Finset ℕ) + (F : ℝ → ℝ) (μ : ℕ → ℝ≥0∞) (hC : 0 ≤ C) (hj : Valid i.flip (point m j)) + (hI : ∀ k ∈ I,Valid i (point m k)) (hF : ∀ k ∈ I,0 ≤ F (point m k)) + (hμ : ∀ k ∈ I,μ k ≤ ENNReal.ofReal (C*(MarginalGrowth.factor L κ w S)^n*width m*weight i (point m k)*F (point m k))) : + (∑ k ∈ I,ENNReal.ofReal (entry L κ w S m i j k)*μ k) ≤ + ENNReal.ofReal ((C*(MarginalGrowth.factor L κ w S)^n*rowFactor L κ w S*width m*weight i.flip (point m j))* + (W (point m j)*(∑ k ∈ I,width m*F (point m k)))) := by + let scale := C*(MarginalGrowth.factor L κ w S)^n*rowFactor L κ w S*width m*weight i.flip (point m j) + have hg := (MarginalGrowth.factor_pos L κ w S).le + have hr := (rowFactor_pos L κ w S).le + have hw := width_nonneg m + have hp := (weight_pos hj).le + have hWt := (WeightFutureIntegrals.W_pos (valid_pos hj)).le + have hscale : 0 ≤ scale := by dsimp [scale]; positivity + calc + _ ≤ ∑ k ∈ I,ENNReal.ofReal (scale*W (point m j)*(width m*F (point m k))) := by + apply Finset.sum_le_sum + intro k hk + calc + _ ≤ ENNReal.ofReal (entry L κ w S m i j k)* + ENNReal.ofReal (C*(MarginalGrowth.factor L κ w S)^n*width m*weight i (point m k)*F (point m k)) := + mul_le_mul_of_nonneg_left (hμ k hk) zero_le + _ = _ := by + rw [← ENNReal.ofReal_mul (entry_nonneg L κ w S m j k hj (hI k hk))] + exact congrArg ENNReal.ofReal (entry_cancel L κ w S C m n j k i F (hI k hk)) + _ = ENNReal.ofReal ((scale*W (point m j))*(∑ k ∈ I,width m*F (point m k))) := by + rw [Finset.mul_sum,ENNReal.ofReal_sum_of_nonneg (s:=I) + (f:=fun k => scale*W (point m j)*(width m*F (point m k))) + (fun k hk => mul_nonneg (mul_nonneg hscale hWt) (mul_nonneg hw (hF k hk)))] + _ = _ := by congr 1; ring + +theorem profile_step (L κ w S C : ℝ) {m : ℕ} (hm : 1 ≤ m) (hmesh : width m = mesh κ w) + (n j : ℕ) (i : Side) (μ : ℕ → ℝ≥0∞) (hC : 0 ≤ C) (hj : lowerIndex m i.flip ≤ j) + (hμ : ∀ k,lowerIndex m i ≤ k → μ k ≤ + ENNReal.ofReal (C*(MarginalGrowth.factor L κ w S)^n*width m*weight i (point m k)*profile m i (point m k))) : + (∑ k ∈ Finset.Icc (lowerIndex m i) (j+m+1),ENNReal.ofReal (entry L κ w S m i j k)*μ k) ≤ + ENNReal.ofReal (C*(MarginalGrowth.factor L κ w S)^(n+1)*width m*weight i.flip (point m j)*profile m i.flip (point m j)) := by + have hjV := index_valid hm i.flip hj + have ht := transport_sum L κ w S C m n j i (Finset.Icc (lowerIndex m i) (j+m+1)) (profile m i) μ hC hjV + (fun k hk => index_valid hm i (Finset.mem_Icc.mp hk).1) + (fun k hk => profile_nonneg m (index_regular hm i (Finset.mem_Icc.mp hk).1)) + (fun k hk => hμ k (Finset.mem_Icc.mp hk).1) + have hg := (MarginalGrowth.factor_pos L κ w S).le + have hr := (rowFactor_pos L κ w S).le + have hw := width_nonneg m + have hp := (weight_pos hjV).le + have hscale : 0 ≤ C*(MarginalGrowth.factor L κ w S)^n*rowFactor L κ w S*width m*weight i.flip (point m j) := by positivity + refine ht.trans (ENNReal.ofReal_le_ofReal ?_) + calc + _ ≤ (C*(MarginalGrowth.factor L κ w S)^n*rowFactor L κ w S*width m*weight i.flip (point m j))* + ((1+20*width m)*profile m i.flip (point m j)) := mul_le_mul_of_nonneg_left (stationary_profile hm i hj) hscale + _ = _ := by rw [pow_succ,factor_eq_row,← hmesh]; ring + +theorem first_to_second (L κ w S C : ℝ) {m : ℕ} (hm : 1 ≤ m) + (j : ℕ) (hj : 2*m ≤ j) (μ : ℕ → ℝ≥0∞) (hC : 0 ≤ C) + (hμ : ∀ k,Valid .odd (point m k) → μ k ≤ + ENNReal.ofReal (C*MarginalGrowth.factor L κ w S*width m*W (point m k)*weight .odd (point m k))) : + (∑ k ∈ weakIndices m j .odd,ENNReal.ofReal (entry L κ w S m .odd j k)*μ k) ≤ + ENNReal.ofReal ((24*C)*(MarginalGrowth.factor L κ w S)^2*width m*weight .even (point m j)) := by + classical + have hjV : Valid Side.even (point m j) := index_valid hm .even hj + have hI : ∀ k ∈ weakIndices m j .odd,Valid .odd (point m k) := by + intro k hk + exact (Finset.mem_filter.mp hk).2 + have hF : ∀ k ∈ weakIndices m j .odd,0 ≤ W (point m k) := + fun k hk => (WeightFutureIntegrals.W_pos (valid_pos (hI k hk))).le + have ht := transport_sum L κ w S C m 1 j .odd (weakIndices m j .odd) W μ hC hjV hI hF + (fun k hk => by simpa only [pow_one,mul_assoc,mul_comm,mul_left_comm] using hμ k (hI k hk)) + rw [pow_one] at ht + have hfirst := first_row_sum hm hj (weakIndices m j .odd) + (fun k hk => (Finset.mem_filter.mp hk).1) + (fun k hk => by have h := hI k hk; change 95/100 ≤ point m k at h; linarith) + have hg := (MarginalGrowth.factor_pos L κ w S).le + have hr := (rowFactor_pos L κ w S).le + have hw := width_nonneg m + have hp := (weight_pos hjV).le + have hscale : 0 ≤ C*MarginalGrowth.factor L κ w S*rowFactor L κ w S*width m*weight .even (point m j) := by positivity + refine ht.trans (ENNReal.ofReal_le_ofReal ?_) + calc + _ ≤ (C*MarginalGrowth.factor L κ w S*rowFactor L κ w S*width m*weight .even (point m j))*24 := + mul_le_mul_of_nonneg_left hfirst hscale + _ = (24*C*MarginalGrowth.factor L κ w S*width m*weight .even (point m j))*rowFactor L κ w S := by ring + _ ≤ (24*C*MarginalGrowth.factor L κ w S*width m*weight .even (point m j))*MarginalGrowth.factor L κ w S := + mul_le_mul_of_nonneg_left (row_le_factor L κ w S) (by positivity) + _ = _ := by ring + +end NumberTheoryLean.MarginalTransport + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/MeshBoundaryGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/MeshBoundaryGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b0c9f5439c1d181b0d0a1273df68a2e3b47b7f7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/MeshBoundaryGeometry.lean @@ -0,0 +1,137 @@ +import Mathlib.Algebra.Order.Group.MinMax +import Mathlib.MeasureTheory.Function.Floor +import Mathlib.SetTheory.Cardinal.Finite +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.MeshRatioLabels + +open Set MeasureTheory + +noncomputable def binCount (S h : ℝ) : ℕ := ⌊S/h⌋₊ +abbrev Label (S h : ℝ) := Fin (binCount S h+2) + +noncomputable def cemeteryLabel (S h : ℝ) : Label S h := ⟨binCount S h+1,by omega⟩ + +noncomputable def ratioLabel (S h t : ℝ) : Label S h := + if t ≤ S then Fin.ofNat (binCount S h+2) ⌊t/h⌋₊ else cemeteryLabel S h + +theorem ratioLabel_measurable (S h : ℝ) : Measurable (ratioLabel S h) := by + have hm : Measurable (fun n : ℕ => Fin.ofNat (binCount S h+2) n) := measurable_of_countable _ + exact Measurable.ite (measurableSet_le measurable_id measurable_const) + (hm.comp (Nat.measurable_floor.comp (measurable_id.div_const h))) measurable_const + +theorem ratioLabel_val {S h t : ℝ} (hh : 0 < h) (ht : t ≤ S) : + (ratioLabel S h t).val = ⌊t/h⌋₊ := by + rw [ratioLabel,ite_eq_left ht,Fin.val_ofNat] + apply Nat.mod_eq_of_lt + have hb : ⌊t/h⌋₊ ≤ binCount S h := Nat.floor_mono (div_le_div_of_nonneg_right ht hh.le) + omega + +theorem ratioLabel_ne_cemetery {S h t : ℝ} (hh : 0 < h) (ht : t ≤ S) : + ratioLabel S h t ≠ cemeteryLabel S h := by + intro heq + have he := congrArg Fin.val heq + rw [ratioLabel_val hh ht] at he + change ⌊t/h⌋₊ = binCount S h+1 at he + have hb : ⌊t/h⌋₊ ≤ binCount S h := Nat.floor_mono (div_le_div_of_nonneg_right ht hh.le) + omega + +theorem ratioLabel_eq_iff {S h t : ℝ} (hh : 0 < h) (ht0 : 0 ≤ t) (htS : t ≤ S) (j : Label S h) : + ratioLabel S h t = j ↔ (j.val : ℝ)*h ≤ t ∧ t < ((j.val : ℝ)+1)*h := by + rw [Fin.ext_iff,ratioLabel_val hh htS,Nat.floor_eq_iff (div_nonneg ht0 hh.le),le_div_iff₀ hh,div_lt_iff₀ hh] + +theorem matching_ratios_close {S h u v : ℝ} (hh : 0 < h) (hu0 : 0 ≤ u) (hv0 : 0 ≤ v) + (huS : u ≤ S) (hvS : v ≤ S) (heq : ratioLabel S h u = ratioLabel S h v) : |u-v| < h := by + have hu := (ratioLabel_eq_iff hh hu0 huS (ratioLabel S h v)).mp heq + have hv := (ratioLabel_eq_iff hh hv0 hvS (ratioLabel S h v)).mp rfl + rw [abs_lt] + constructor <;> nlinarith [hu.1,hu.2,hv.1,hv.2] + +theorem label_card_le {S h : ℝ} (hS : 0 ≤ S) (hh : 0 < h) : + (Fintype.card (Label S h) : ℝ) ≤ S/h+2 := by + have hc : Fintype.card (Label S h) = binCount S h+2 := + (Nat.card_eq_fintype_card (α := Label S h)).symm.trans (Nat.card_fin _) + rw [hc] + simp only [Nat.cast_add,Nat.cast_ofNat,binCount] + linarith [Nat.floor_le (div_nonneg hS hh.le)] + +end NumberTheoryLean.MeshRatioLabels + +end + +section + +namespace NumberTheoryLean.MeshBoundaryGeometry + +open Set MeshRatioLabels + +noncomputable def lowerEdge {S mesh : ℝ} (j : Label S mesh) : ℝ := (j.val:ℝ)*mesh +noncomputable def upperEdge {S mesh : ℝ} (j : Label S mesh) : ℝ := ((j.val:ℝ)+1)*mesh + +def fullCell {S mesh : ℝ} (Ld Lc Ud Uc : ℝ) (j : Label S mesh) : Prop := + max Ld Lc < lowerEdge j ∧ upperEdge j ≤ min Ud Uc + +noncomputable def lowerPacket (mesh Ld Lc : ℝ) : Set ℝ := Icc (min Ld Lc) (max Ld Lc+mesh) +noncomputable def upperPacket (mesh Ud Uc : ℝ) : Set ℝ := Icc (min Ud Uc-mesh) (max Ud Uc) + +theorem noninterior_in_packets {S mesh t Ld Lc Ud Uc : ℝ} (hm : 0 < mesh) + (ht0 : 0 ≤ t) (htS : t ≤ S) + (hvalid : (Ld ≤ t ∧ t ≤ Ud) ∨ (Lc ≤ t ∧ t ≤ Uc)) + (hbad : ¬fullCell Ld Lc Ud Uc (ratioLabel S mesh t)) : + t ∈ lowerPacket mesh Ld Lc ∪ upperPacket mesh Ud Uc := by + have hj := (ratioLabel_eq_iff hm ht0 htS (ratioLabel S mesh t)).mp rfl + have hlo : min Ld Lc ≤ t := hvalid.elim (fun h => (min_le_left _ _).trans h.1) + (fun h => (min_le_right _ _).trans h.1) + have hup : t ≤ max Ud Uc := hvalid.elim (fun h => h.2.trans (le_max_left _ _)) + (fun h => h.2.trans (le_max_right _ _)) + have hwidth : upperEdge (ratioLabel S mesh t) = lowerEdge (ratioLabel S mesh t)+mesh := by + unfold upperEdge lowerEdge + ring + change lowerEdge (ratioLabel S mesh t) ≤ t ∧ t < upperEdge (ratioLabel S mesh t) at hj + by_cases hl : max Ld Lc < lowerEdge (ratioLabel S mesh t) + · have hu : min Ud Uc < upperEdge (ratioLabel S mesh t) := by + exact lt_of_not_ge (fun h => hbad ⟨hl,h⟩) + exact Or.inr ⟨by linarith,hup⟩ + · exact Or.inl ⟨hlo,by linarith⟩ + +theorem lowerPacket_width (mesh Ld Lc : ℝ) : + (max Ld Lc+mesh)-min Ld Lc = |Ld-Lc|+mesh := by + rw [show max Ld Lc+mesh-min Ld Lc = max Ld Lc-min Ld Lc+mesh by ring, + max_sub_min_eq_abs,abs_sub_comm] + +theorem upperPacket_width (mesh Ud Uc : ℝ) : + max Ud Uc-(min Ud Uc-mesh) = |Ud-Uc|+mesh := by + rw [show max Ud Uc-(min Ud Uc-mesh) = max Ud Uc-min Ud Uc+mesh by ring, + max_sub_min_eq_abs,abs_sub_comm] + +theorem clipPacket {a b t : ℝ} (hab : a ≤ b) (ht : (1/2:ℝ) ≤ t) (hm : t ∈ Icc a b) : + t ∈ Icc (max (1/2) a) (max (1/2) b) ∧ + max (1/2) b-max (1/2) a ≤ b-a := by + refine ⟨⟨max_le ht hm.1,hm.2.trans (le_max_right _ _)⟩,?_⟩ + have h := abs_max_sub_max_le_abs b a (1/2:ℝ) + rw [max_comm b (1/2),max_comm a (1/2),abs_of_nonneg (sub_nonneg.mpr hab), + abs_of_nonneg (sub_nonneg.mpr (max_le_max_left _ hab))] at h + exact h + +theorem clipped_packet_width {a b mesh d : ℝ} (hab : a ≤ b) (hwidth : b-a ≤ d+mesh) : + 0 < max (1/2:ℝ) a ∧ max (1/2:ℝ) a ≤ max (1/2:ℝ) b ∧ + max (1/2:ℝ) b-max (1/2:ℝ) a ≤ d+mesh := by + refine ⟨lt_of_lt_of_le (by norm_num) (le_max_left _ _),max_le_max_left _ hab,?_⟩ + have h := abs_max_sub_max_le_abs b a (1/2:ℝ) + rw [max_comm b (1/2),max_comm a (1/2),abs_of_nonneg (sub_nonneg.mpr hab), + abs_of_nonneg (sub_nonneg.mpr (max_le_max_left _ hab))] at h + exact h.trans hwidth + +end NumberTheoryLean.MeshBoundaryGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/MeshStationary.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/MeshStationary.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5668ea2da05cb30c44afbdf4ee83c43c856d752 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/MeshStationary.lean @@ -0,0 +1,234 @@ +import Mathlib.Algebra.BigOperators.Intervals +import Mathlib.Tactic + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators + +namespace Erdos970Dependency.MeshStationary + +noncomputable def mesh (m : ℕ) : ℝ := 1/(m : ℝ) +noncomputable def point (m k : ℕ) : ℝ := (k : ℝ)*mesh m +noncomputable def weight (u : ℝ) : ℝ := (u+1)/u^2 + +theorem mesh_nonneg (m : ℕ) : 0 ≤ mesh m := by unfold mesh; positivity + +theorem mesh_pos (m : ℕ) (hm : 1 ≤ m) : 0 < mesh m := by + have h : (0 : ℝ) < m := by exact_mod_cast (show 0 < m from hm) + unfold mesh + positivity + +theorem mesh_le_one (m : ℕ) (hm : 1 ≤ m) : mesh m ≤ 1 := by + have h : (0 : ℝ) < m := by exact_mod_cast (show 0 < m from hm) + exact (div_le_one h).mpr (by exact_mod_cast hm) + +theorem mesh_mul (m : ℕ) (hm : 1 ≤ m) : (m : ℝ)*mesh m = 1 := by + have h : (m : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt (show 0 < m from hm)) + simp [mesh,h] + +theorem point_ge_one (m k : ℕ) (hm : 1 ≤ m) (hkm : m ≤ k) : 1 ≤ point m k := by + have h := mul_le_mul_of_nonneg_right (show (m : ℝ) ≤ k by exact_mod_cast hkm) (mesh_nonneg m) + rw [mesh_mul m hm] at h + exact h + +theorem point_ge_two (m j : ℕ) (hm : 1 ≤ m) (hj : 2*m ≤ j) : 2 ≤ point m j := by + have h := mul_le_mul_of_nonneg_right (show (2 : ℝ)*m ≤ j by exact_mod_cast hj) (mesh_nonneg m) + rw [mul_assoc,mesh_mul m hm,mul_one] at h + exact h + +theorem point_nonneg (m k : ℕ) : 0 ≤ point m k := + mul_nonneg (Nat.cast_nonneg _) (mesh_nonneg _) + +theorem point_succ (m k : ℕ) : point m (k+1) = point m k+mesh m := by + unfold point + push_cast + ring + +theorem weight_nonneg {u : ℝ} (hu : 0 ≤ u) : 0 ≤ weight u := by unfold weight; positivity + +theorem weight_le_two {u : ℝ} (hu : 1 ≤ u) : weight u ≤ 2 := by + unfold weight + apply (div_le_iff₀ (by positivity : 0 < u^2)).mpr + nlinarith [sq_nonneg (u-1)] + +theorem weight_cost_le_twenty {t : ℝ} (ht : 2 ≤ t) : weight t*(6*t+14) ≤ 20 := by + calc + _ = ((t+1)*(6*t+14))/t^2 := by unfold weight; ring + _ ≤ _ := (div_le_iff₀ (by positivity : 0 < t^2)).mpr (by nlinarith [sq_nonneg (t-2)]) + +theorem reciprocal_drop_le {u h : ℝ} (hu : 0 < u) (hh : 0 ≤ h) : + 1/u-1/(u+h) ≤ h/u^2 := by + have hup : 0 < u+h := by linarith + calc + _ = h/(u*(u+h)) := by field_simp; ring + _ ≤ _ := div_le_div_of_nonneg_left hh (by positivity) (by nlinarith) + +theorem reciprocal_telescope (m lo hi : ℕ) (hlohi : lo ≤ hi) : + (∑ k ∈ Finset.Icc lo hi, ((1 : ℝ) / point m k - (1 : ℝ) / point m (k+1))) = + (1 : ℝ) / point m lo - (1 : ℝ) / point m (hi+1) := by + simpa only [neg_sub_neg] using! + Finset.sum_Icc_sub hlohi (fun k => -(1/point m k)) + +theorem even_row_count (m j : ℕ) (hm : 1 ≤ m) (hj : m ≤ j) : + mesh m * ((Finset.Icc (2*m) (j+m+1)).card : ℝ) ≤ point m j-1+3*mesh m := by + have hc : (Finset.Icc (2*m) (j+m+1)).card+m = j+2 := by + rw [Nat.card_Icc] + omega + have hcr : ((Finset.Icc (2*m) (j+m+1)).card : ℝ)+(m : ℝ) = (j : ℝ)+2 := by + exact_mod_cast hc + have he := congrArg (fun x : ℝ => x*mesh m) hcr + have hmul := mesh_mul m hm + have hn := mesh_nonneg m + unfold point + nlinarith + +end Erdos970Dependency.MeshStationary + +end + +section + +open scoped BigOperators + +namespace Erdos970Dependency.MeshStationary + +theorem row_card (m j : ℕ) : (Finset.Icc m (j+m+1)).card = j+2 := by + rw [Nat.card_Icc] + omega + +theorem point_last (m j : ℕ) (hm : 1 ≤ m) : + point m (j+m+2) = point m j + 1 + 2*mesh m := by + unfold point + push_cast + nlinarith [mesh_mul m hm] + +theorem reciprocal_sum_lower (m j : ℕ) (hm : 1 ≤ m) : + (1 : ℝ) - 1 / point m (j+m+2) ≤ + ∑ k ∈ Finset.Icc m (j+m+1), mesh m / (point m k)^2 := by + have h : (∑ k ∈ Finset.Icc m (j+m+1), + ((1 : ℝ) / point m k - (1 : ℝ) / point m (k+1))) ≤ + ∑ k ∈ Finset.Icc m (j+m+1), mesh m / (point m k)^2 := by + apply Finset.sum_le_sum + intro k hk + rw [point_succ] + exact reciprocal_drop_le + (lt_of_lt_of_le zero_lt_one (point_ge_one m k hm (Finset.mem_Icc.mp hk).1)) + (mesh_nonneg m) + rw [reciprocal_telescope m m (j+m+1) (by omega)] at h + have hfirst : point m m = 1 := mesh_mul m hm + simpa only [hfirst,div_one,show j+m+1+1 = j+m+2 by omega] using h + +theorem leading_sum_le (m j : ℕ) (hm : 1 ≤ m) : + (∑ k ∈ Finset.Icc m (j+m+1), mesh m * (1 - 1 / (point m k)^2)) ≤ + (point m j)^2 / (point m j+1) + 2*mesh m := by + have ht := point_nonneg m j + have hh := mesh_nonneg m + have ht1 : 0 < point m j+1 := by linarith + have hrec := reciprocal_sum_lower m j hm + rw [point_last m j hm] at hrec + have hinv : (1 : ℝ) / (point m j+1+2*mesh m) ≤ 1 / (point m j+1) := + div_le_div_of_nonneg_left (by norm_num) ht1 (by linarith) + calc + _ = (∑ _k ∈ Finset.Icc m (j+m+1),mesh m) - + ∑ k ∈ Finset.Icc m (j+m+1), mesh m / (point m k)^2 := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + _ = point m j + 2*mesh m - + ∑ k ∈ Finset.Icc m (j+m+1), mesh m / (point m k)^2 := by + simp only [Finset.sum_const,row_card,nsmul_eq_mul,Nat.cast_add,Nat.cast_ofNat,point] + ring + _ ≤ point m j + 2*mesh m - (1 - 1 / (point m j+1+2*mesh m)) := + sub_le_sub_left hrec _ + _ ≤ point m j - 1 + 1 / (point m j+1) + 2*mesh m := by linarith + _ = _ := by field_simp; ring + +theorem correction_sum_le (m j : ℕ) (hm : 1 ≤ m) : + (∑ k ∈ Finset.Icc m (j+m+1), mesh m * (3*mesh m*weight (point m k))) ≤ + 6*mesh m*(point m j+2) := by + have hh := mesh_nonneg m + have hh1 := mesh_le_one m hm + calc + _ ≤ ∑ _k ∈ Finset.Icc m (j+m+1),mesh m*(3*mesh m*2) := by + apply Finset.sum_le_sum + intro k hk + exact mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left + (weight_le_two (point_ge_one m k hm (Finset.mem_Icc.mp hk).1)) (by positivity)) + hh + _ = 6*mesh m*(point m j+2*mesh m) := by + simp only [Finset.sum_const,row_card,nsmul_eq_mul,Nat.cast_add,Nat.cast_ofNat,point] + ring + _ ≤ _ := mul_le_mul_of_nonneg_left (by linarith) (by positivity) + +theorem full_row_sum_le (m j : ℕ) (hm : 1 ≤ m) : + (∑ k ∈ Finset.Icc m (j+m+1), + mesh m * (1 - 1 / (point m k)^2 + 3*mesh m*weight (point m k))) ≤ + (point m j)^2 / (point m j+1) + 2*mesh m + 6*mesh m*(point m j+2) := by + calc + _ = (∑ k ∈ Finset.Icc m (j+m+1),mesh m*(1 - 1 / (point m k)^2)) + + ∑ k ∈ Finset.Icc m (j+m+1),mesh m*(3*mesh m*weight (point m k)) := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + _ ≤ _ := add_le_add (leading_sum_le m j hm) (correction_sum_le m j hm) + +end Erdos970Dependency.MeshStationary + +end + +section + +open scoped BigOperators + +namespace Erdos970Dependency.MeshStationary + +theorem odd_row_weighted (m j : ℕ) (hm : 1 ≤ m) (hj : 2*m ≤ j) : + weight (point m j) * + (∑ k ∈ Finset.Icc m (j+m+1), + mesh m * (1 - 1 / (point m k)^2 + 3*mesh m*weight (point m k))) ≤ + 1 + 20*mesh m := by + have ht2 := point_ge_two m j hm hj + have ht0 : point m j ≠ 0 := by linarith + have ht1 : point m j+1 ≠ 0 := by linarith + have hW := weight_nonneg (point_nonneg m j) + calc + _ ≤ weight (point m j) * + ((point m j)^2 / (point m j+1) + 2*mesh m + 6*mesh m*(point m j+2)) := + mul_le_mul_of_nonneg_left (full_row_sum_le m j hm) hW + _ = 1 + mesh m * (weight (point m j)*(6*point m j+14)) := by + unfold weight + field_simp + ring + _ ≤ 1 + mesh m*20 := add_le_add le_rfl + (mul_le_mul_of_nonneg_left (weight_cost_le_twenty ht2) (mesh_nonneg m)) + _ = _ := by ring + +theorem even_row_literal (m j : ℕ) (hm : 1 ≤ m) (hj : m ≤ j) : + (1/(m : ℝ)) * ((Finset.Icc (2*m) (j+m+1)).card : ℝ) ≤ + (j : ℝ)/(m : ℝ) - 1 + 3/(m : ℝ) := by + simpa only [mesh,point,div_eq_mul_inv,one_mul] using even_row_count m j hm hj + +theorem odd_row_literal (m j : ℕ) (hm : 1 ≤ m) (hj : 2*m ≤ j) : + (((j : ℝ)/(m : ℝ)+1)/((j : ℝ)/(m : ℝ))^2) * + (∑ k ∈ Finset.Icc m (j+m+1), + (1/(m : ℝ)) * + (1 - 1 / ((k : ℝ)/(m : ℝ))^2 + + (3/(m : ℝ))*(((k : ℝ)/(m : ℝ)+1)/((k : ℝ)/(m : ℝ))^2))) ≤ + 1 + 20/(m : ℝ) := by + simpa only [mesh,point,weight,div_eq_mul_inv,one_mul,mul_assoc] using + odd_row_weighted m j hm hj + +end Erdos970Dependency.MeshStationary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/NestedCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/NestedCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8c006e4078b91b92111dcff77cf3b9507d958a0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/NestedCoordinates.lean @@ -0,0 +1,79 @@ +import Mathlib + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosCriticalGeometry + +variable (R : Type*) [CommSemiring R] + +abbrev MV := MvPolynomial (Fin 2) R +abbrev Nested := Polynomial (Polynomial R) + +noncomputable def nestedX : MV R ≃ₐ[R] Nested R := + (MvPolynomial.finSuccEquiv R 1).trans + (Polynomial.mapAlgEquiv (MvPolynomial.uniqueAlgEquiv R (Fin 1))) + +noncomputable def nestedY : MV R ≃ₐ[R] Nested R := + (MvPolynomial.renameEquiv R (Equiv.swap (0 : Fin 2) 1)).trans (nestedX R) + +@[simp] theorem nestedX_C (c : R) : nestedX R (MvPolynomial.C c) = Polynomial.C (Polynomial.C c) := by + simpa using (nestedX R).commutes c + +@[simp] theorem nestedX_X_zero : nestedX R (MvPolynomial.X 0) = Polynomial.X := by + simp [nestedX, Polynomial.coe_mapAlgEquiv, MvPolynomial.finSuccEquiv_X_zero] + +@[simp] theorem nestedX_X_one : nestedX R (MvPolynomial.X 1) = Polynomial.C Polynomial.X := by + change Polynomial.map (MvPolynomial.uniqueAlgEquiv R (Fin 1)).toRingHom + (MvPolynomial.finSuccEquiv R 1 (MvPolynomial.X (Fin.succ (0 : Fin 1)))) = _ + rw [MvPolynomial.finSuccEquiv_X_succ, Polynomial.map_C] + simp [MvPolynomial.uniqueAlgEquiv_apply] + +@[simp] theorem nestedY_C (c : R) : nestedY R (MvPolynomial.C c) = Polynomial.C (Polynomial.C c) := by + simp [nestedY] + +@[simp] theorem nestedY_X_zero : nestedY R (MvPolynomial.X 0) = Polynomial.C Polynomial.X := by + simp [nestedY] + +@[simp] theorem nestedY_X_one : nestedY R (MvPolynomial.X 1) = Polynomial.X := by + simp [nestedY] + +noncomputable def nestedEvalHom (x y : R) : Nested R →+* R := + (Polynomial.evalRingHom y).comp (Polynomial.mapRingHom (Polynomial.evalRingHom x)) + +@[simp] theorem nestedEvalHom_C (p : Polynomial R) (x y : R) : + nestedEvalHom R x y (Polynomial.C p) = p.eval x := by simp [nestedEvalHom] + +@[simp] theorem nestedEvalHom_X (x y : R) : + nestedEvalHom R x y Polynomial.X = y := by simp [nestedEvalHom] + +theorem eval_nestedY (Q : MV R) (x y : R) : + nestedEvalHom R x y (nestedY R Q) = MvPolynomial.eval ![x,y] Q := by + induction Q using MvPolynomial.induction_on with + | C c => simp [nestedEvalHom] + | add P Q hP hQ => simp [map_add, hP, hQ] + | mul_X P i hP => + fin_cases i + · simp [map_mul, hP] + · simp [map_mul, hP] + +theorem eval_nestedX (Q : MV R) (x y : R) : + nestedEvalHom R y x (nestedX R Q) = MvPolynomial.eval ![x,y] Q := by + induction Q using MvPolynomial.induction_on with + | C c => simp [nestedEvalHom] + | add P Q hP hQ => simp [map_add, hP, hQ] + | mul_X P i hP => + fin_cases i + · simp [map_mul, hP] + · simp [map_mul, hP] + +end ErdosCriticalGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/NonlinearCoordinateDegree.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/NonlinearCoordinateDegree.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d866d9cc51d1f04f51977a4734d904f240586cd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/NonlinearCoordinateDegree.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.NestedDegreeBounds +import OAI.NumberTheory.Jacobsthal.Estimates.NestedPartials + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosCriticalGeometry + +theorem irreducible_of_constant_polynomial (p : Polynomial ℂ) + (hp : Irreducible (Polynomial.C p : Nested ℂ)) : Irreducible p := by + refine ⟨fun h => hp.not_isUnit (Polynomial.isUnit_C.mpr h), ?_⟩ + intro a b hab + have h := hp.2 (show Polynomial.C p = Polynomial.C a*Polynomial.C b by rw [hab, map_mul]) + exact h.imp Polynomial.isUnit_C.mp Polynomial.isUnit_C.mp + +theorem nonlinear_outer_degree_pos (E : MV ℂ ≃ₐ[ℂ] Nested ℂ) (i : Fin 2) + (hXi : E (MvPolynomial.X i) = Polynomial.C Polynomial.X) + (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : 0 < (E Q).natDegree := by + have hC (c : ℂ) : E (MvPolynomial.C c) = Polynomial.C (Polynomial.C c) := by + simpa using E.commutes c + have hEQ : Irreducible (E Q) := (MulEquiv.irreducible_iff E.toMulEquiv).mpr hQ + by_contra! hzero + have he : E Q = Polynomial.C ((E Q).coeff 0) := Polynomial.eq_C_of_natDegree_le_zero hzero + have hc : Irreducible ((E Q).coeff 0) := irreducible_of_constant_polynomial _ (he ▸ hEQ) + have hlin := Polynomial.eq_X_add_C_of_degree_le_one + (IsAlgClosed.degree_eq_one_of_irreducible ℂ hc).le + let a : ℂ := ((E Q).coeff 0).coeff 1 + let b : ℂ := ((E Q).coeff 0).coeff 0 + have hQlin : Q = MvPolynomial.C a*MvPolynomial.X i+MvPolynomial.C b := by + apply E.injective + rw [map_add, map_mul, hC, hC, hXi, he, hlin] + simp only [map_add, map_mul, a, b] + have ht : Q.totalDegree ≤ 1 := by + rw [hQlin] + apply (MvPolynomial.totalDegree_add _ _).trans + apply max_le + · exact (MvPolynomial.totalDegree_mul _ _).trans (by simp) + · simp + omega + +theorem nonlinear_nestedX_degree_pos (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + 0 < (nestedX ℂ Q).natDegree := + nonlinear_outer_degree_pos (nestedX ℂ) 1 (nestedX_X_one ℂ) Q hQ hdeg + +theorem nonlinear_nestedY_degree_pos (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + 0 < (nestedY ℂ Q).natDegree := + nonlinear_outer_degree_pos (nestedY ℂ) 0 (nestedY_X_zero ℂ) Q hQ hdeg + +theorem nonlinear_partial_zero_ne (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + MvPolynomial.pderiv 0 Q ≠ 0 := by + intro hz + have hd := congrArg (nestedX ℂ) hz + rw [nestedX_partial_zero, map_zero] at hd + exact (nonlinear_nestedX_degree_pos Q hQ hdeg).ne' (Polynomial.derivative_eq_zero.mp hd) + +theorem nonlinear_partial_one_ne (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) : + MvPolynomial.pderiv 1 Q ≠ 0 := by + intro hz + have hd := congrArg (nestedY ℂ) hz + rw [nestedY_partial_one, map_zero] at hd + exact (nonlinear_nestedY_degree_pos Q hQ hdeg).ne' (Polynomial.derivative_eq_zero.mp hd) + +theorem nonlinear_partial_not_dvd (Q : MV ℂ) (hQ : Irreducible Q) (hdeg : 1 < Q.totalDegree) + (i : Fin 2) : ¬ Q ∣ MvPolynomial.pderiv i Q := by + have hn : MvPolynomial.pderiv i Q ≠ 0 := by + fin_cases i + · exact nonlinear_partial_zero_ne Q hQ hdeg + · exact nonlinear_partial_one_ne Q hQ hdeg + intro hd + have h1 := MvPolynomial.totalDegree_le_of_dvd_of_isDomain hd hn + have h2 := partial_totalDegree_le ℂ Q i + omega + +end ErdosCriticalGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/OmissionPartition.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/OmissionPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..2847fc4570066534615959f51370795c36c4c2f4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/OmissionPartition.lean @@ -0,0 +1,57 @@ +import OAI.NumberTheory.Jacobsthal.Paths.PrefixCompletions + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferencePruning +attribute [local instance] Classical.propDecidable +open FinitePathGeometry ReferenceAdmission ErdosPrimeInputs.PrimePrefixMass + +noncomputable def rejectedPrefixes (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : Finset (List ℕ) := + (decreasingPrefixes P).filter (fun ps => ¬admitted w i r ps) + +theorem rejected_eq_omission_completions (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : + rejectedPrefixes w P i r = (firstOmissions w P i r).biUnion (completions P) := by + ext ps + constructor + · intro hp + obtain ⟨hD,hnot⟩ := Finset.mem_filter.mp hp + obtain ⟨pre,suf,he,hfirst⟩ := exists_first_omitted_prefix hnot + have hjoin : pre++suf ∈ decreasingPrefixes P := by rwa [← he] + have hpre := decreasing_prefix_mem hjoin + have hsuf := (append_mem_decreasing_iff hpre).mp hjoin + apply Finset.mem_biUnion.mpr + exact ⟨pre,Finset.mem_filter.mpr ⟨hpre,hfirst⟩, + Finset.mem_image.mpr ⟨suf,hsuf,he.symm⟩⟩ + · intro hp + obtain ⟨pre,hpre,hcomplete⟩ := Finset.mem_biUnion.mp hp + obtain ⟨suf,hsuf,rfl⟩ := Finset.mem_image.mp hcomplete + obtain ⟨hD,hfirst⟩ := Finset.mem_filter.mp hpre + apply Finset.mem_filter.mpr + refine ⟨(append_mem_decreasing_iff hD).mpr hsuf,?_⟩ + intro hallowed + exact firstOmitted_not_admitted hfirst ((admitted_append w r i pre suf).mp hallowed).1 + +theorem omission_completions_disjoint (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) : + (firstOmissions w P i r : Set (List ℕ)).PairwiseDisjoint (completions P) := by + intro pre hpre other hother hne + apply Finset.disjoint_left.mpr + intro whole hp hq + obtain ⟨suf,_,he⟩ := Finset.mem_image.mp hp + obtain ⟨tail,_,hf⟩ := Finset.mem_image.mp hq + have h := first_omission_prefix_unique (Finset.mem_filter.mp hpre).2 + (Finset.mem_filter.mp hother).2 (show pre <+: whole from ⟨suf,he⟩) + (show other <+: whole from ⟨tail,hf⟩) + exact hne h + +end NumberTheoryLean.ReferencePruning + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/OriginalBinWeightRange.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/OriginalBinWeightRange.lean new file mode 100644 index 0000000000000000000000000000000000000000..002ebd3da1629fbdf07865990dde86d3d16c5d30 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/OriginalBinWeightRange.lean @@ -0,0 +1,39 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SubbinAggregation + +namespace OAI + +namespace Erdos970 + + +namespace ErdosStoppedArithmetic +open ErdosInversePrimeBin ErdosStoppedSubbinAggregation + + +theorem original_bin_weight_range (Y q R theta : ℝ) (hY : 0 ≤ Y) (hq : 0 < q) + (hR : 0 < R) (ht : 0 ≤ theta) (ht1 : theta ≤ 1) : + 0 ≤ Y/(((1+theta)*R)*q) ∧ ∀ p ∈ primeBin R theta, + Y/(((1+theta)*R)*q) ≤ Y/((p : ℝ)*q) ∧ + Y/((p : ℝ)*q) ≤ 2*(Y/(((1+theta)*R)*q)) := by + have hDen : 0 < ((1+theta)*R)*q := by positivity + have hDen0 : 0 < R*q := mul_pos hR hq + have hDenBound : ((1+theta)*R)*q ≤ 2*(R*q) := by + have hh := mul_le_mul_of_nonneg_right (show 1+theta ≤ (2 : ℝ) by linarith) hDen0.le + nlinarith only [hh] + refine ⟨div_nonneg hY hDen.le,?_⟩ + intro p hp + obtain ⟨_hp,hlo,hhi⟩ := (mem_primeBin hR.le ht p).mp hp + refine ⟨reference_length_le hY hq (hR.trans hlo) hhi,?_⟩ + calc + Y/((p : ℝ)*q) ≤ Y/(R*q) := reference_length_le hY hq hR hlo.le + _ ≤ (2*Y)/(((1+theta)*R)*q) := by + apply (div_le_div_iff₀ hDen0 hDen).mpr + have hh := mul_le_mul_of_nonneg_left hDenBound hY + nlinarith only [hh] + _ = _ := by ring + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/PairFibreEnumeration.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/PairFibreEnumeration.lean new file mode 100644 index 0000000000000000000000000000000000000000..e22b5b732b1ccaedfd6c1fb2427b311e6ed412dd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/PairFibreEnumeration.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.PairCollisionCount + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosHyperbolaIdentities + +attribute [local instance] Classical.decEq + +private theorem fibre_subset (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c u : (ZMod N)ˣ) (I J : Finset ℤ) + (hu : u ∈ unitClass N T hT a) : pairFibre N c u I J ⊆ hyperbolaPairs N T a c I J := by + rintro ⟨x,y⟩ hxy + obtain ⟨hxf, hyf⟩ := Finset.mem_product.mp hxy + obtain ⟨hxI, hxu⟩ := (mem_integerFibre _ _ _ _).mp hxf + obtain ⟨hyJ, hyu⟩ := (mem_integerFibre _ _ _ _).mp hyf + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_product.mpr ⟨hxI, hyJ⟩, ?_, ?_⟩ + · rw [hxu, hyu] + calc + _ = (c : ZMod N)*((u : ZMod N)*(↑u⁻¹ : ZMod N)) := by ring + _ = _ := by simp + · exact (unit_class_of_int N T hT a u x hxu.symm).mp ((mem_unitClass _ _ _ _ _).mp hu) + +theorem hyperbolaPairs_eq_fibres (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (I J : Finset ℤ) : + hyperbolaPairs N T a c I J = (unitClass N T hT a).biUnion (fun u => pairFibre N c u I J) := by + apply Finset.Subset.antisymm + · rintro ⟨x,y⟩ hpair + obtain ⟨hIJ, hxy, hclass⟩ := Finset.mem_filter.mp hpair + obtain ⟨hxI, hyJ⟩ := Finset.mem_product.mp hIJ + have hprod : IsUnit ((x : ZMod N)*(y : ZMod N)) := by rw [hxy]; exact c.isUnit + obtain ⟨u, hux⟩ := isUnit_of_mul_isUnit_left hprod + have hu : u ∈ unitClass N T hT a := + (mem_unitClass _ _ _ _ _).mpr ((unit_class_of_int N T hT a u x hux).mpr hclass) + have hyu : (y : ZMod N) = (c : ZMod N)*(↑u⁻¹ : ZMod N) := by + have he : (u : ZMod N)*(y : ZMod N) = (c : ZMod N) := by rw [hux]; exact hxy + have hm := congrArg (fun z : ZMod N => (↑u⁻¹ : ZMod N)*z) he + rw [Units.inv_mul_cancel_left] at hm + simpa only [mul_comm] using hm + apply Finset.mem_biUnion.mpr + refine ⟨u, hu, ?_⟩ + exact Finset.mem_product.mpr + ⟨(mem_integerFibre _ _ _ _).mpr ⟨hxI, hux.symm⟩, + (mem_integerFibre _ _ _ _).mpr ⟨hyJ, hyu⟩⟩ + · intro xy hxy + obtain ⟨u, hu, hf⟩ := Finset.mem_biUnion.mp hxy + exact fibre_subset N T hT a c u I J hu hf + +theorem pairFibres_disjoint (N : ℕ) [NeZero N] (c u v : (ZMod N)ˣ) (I J : Finset ℤ) + (huv : u ≠ v) : Disjoint (pairFibre N c u I J) (pairFibre N c v I J) := by + apply Finset.disjoint_left.mpr + rintro ⟨x,y⟩ hxu hxv + have hu := ((mem_integerFibre N I (u : ZMod N) x).mp (Finset.mem_product.mp hxu).1).2 + have hv := ((mem_integerFibre N I (v : ZMod N) x).mp (Finset.mem_product.mp hxv).1).2 + exact huv (Units.ext (hu.symm.trans hv)) + +theorem hyperbolaPairs_card_eq_fibre_sum (N T : ℕ) [NeZero N] [NeZero T] (hT : T ∣ N) + (a : (ZMod T)ˣ) (c : (ZMod N)ˣ) (I J : Finset ℤ) : + (hyperbolaPairs N T a c I J).card = + ∑ u ∈ unitClass N T hT a, + (integerFibre N I (u : ZMod N)).card * + (integerFibre N J ((c : ZMod N)*(↑u⁻¹ : ZMod N))).card := by + have hd : (↑(unitClass N T hT a) : Set (ZMod N)ˣ).PairwiseDisjoint + (fun u => pairFibre N c u I J) := by + intro u _ v _ huv + exact pairFibres_disjoint N c u v I J huv + rw [hyperbolaPairs_eq_fibres N T hT a c I J, Finset.card_biUnion hd] + simp only [pairFibre, Finset.product_eq_sprod, Finset.card_product] + +end ErdosHyperbolaIdentities + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/PaperGeometricRegularity.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/PaperGeometricRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..62c98fea22f894257f7b337d3111a2fd9b4741c7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/PaperGeometricRegularity.lean @@ -0,0 +1,273 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FirstIsolatedPosition +import OAI.NumberTheory.Jacobsthal.Estimates.IsolatedSourceScales +import OAI.NumberTheory.Jacobsthal.Estimates.LargeGapCountErrors +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceIsolatedExclusion +import OAI.NumberTheory.Jacobsthal.Paths.ExpandedHardCapture +import OAI.NumberTheory.Jacobsthal.Primes.IsolatedRealPrimeRange + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GeometricDefectPartition +open GeometricRegularWords ActualRegularBoxes RepeatedWordEvents NonisolatedWordOccurrence +open PrimeHistories LogarithmicBinLabels +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +attribute [local instance] Classical.propDecidable + +theorem geometric_defect_sum {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) (F : Finset (List ℕ)) : + (∑ ps ∈ F \ geometricWords hw htop hxi C B R L alpha beta z,prefixWeight ps) ≤ + (∑ ps ∈ F \ regularWords hw htop hxi C B R z,prefixWeight ps) + + (∑ ps ∈ F.filter (compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L z),prefixWeight ps) + + (∑ ps ∈ F.filter (noIsolatedWord hw htop hxi B alpha beta),prefixWeight ps) := by + simp only [Finset.sdiff_eq_filter,Finset.sum_filter] + rw [← Finset.sum_add_distrib,← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro ps _hp + have hn := prefixWeight_nonneg ps + by_cases hg : ps ∈ geometricWords hw htop hxi C B R L alpha beta z + · simp only [hg,not_true_eq_false,ite_false] + positivity + · have hf : ps ∉ regularWords hw htop hxi C B R z ∨ + compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L z ps ∨ + noIsolatedWord hw htop hxi B alpha beta ps := by + by_contra! hh + exact hg (Finset.mem_filter.mpr ⟨hh.1,hh.2⟩) + simp only [hg,not_false_eq_true,ite_true] + split_ifs <;> simp_all +end NumberTheoryLean.GeometricDefectPartition + + + +namespace NumberTheoryLean.GeometricRegularMass +open FinitePathGeometry PrimeHistories ActualRegularBoxes GeometricRegularWords +open RepeatedWordEvents NonisolatedWordOccurrence ReferenceAdmission GeometricDefectPartition +open BasicRegularMass ReferenceRepeatedExclusion ReferenceIsolatedExclusion +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem geometric_regular_defect_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) + (L : ℝ) (hL : 0 ≤ L) (theta : ℝ) (htheta : 0 < theta) (htheta1 : theta ≤ 1/2) : + ∃ Clen₀ C : ℝ,1 ≤ Clen₀ ∧ 0 < C ∧ ∀ Clen : ℝ,Clen₀ ≤ Clen → ∀ eps : ℝ,0 < eps → + ∃ alpha B₀ w₀ : ℝ,0 < alpha ∧ alpha ≤ theta ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ hw : 1 < w,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → 20*Clen*xi ≤ 1 → Real.log B ≤ D*Real.log w → + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + PrimeBinMembership.Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ F : Finset (List ℕ),F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps ∈ F,(terminal w z ps).gap ≤ R) → + B^2*(∑ ps ∈ F \ geometricWords hw htop hxi Clen B R L alpha (4*theta) z,prefixWeight ps) ≤ C*(2*Clen*xi)+eps := by + obtain ⟨Clen₀,C,hClen₀,hC,hBasic⟩ := basic_regular_defect_mass R hR D hD + refine ⟨Clen₀,C,hClen₀,hC,?_⟩ + intro Clen hClen eps heps + have he : 0 < eps/3 := by positivity + obtain ⟨BA,WA,hBA,hWA,hBasic⟩ := hBasic Clen hClen (eps/3) he + obtain ⟨BB,WB,hBB,hWB,hRepeat⟩ := uniform_reference_repeated_mass R hR D hD L hL (eps/3) he + obtain ⟨alpha,BC,WC,ha,hath,hBC,hWC,hIsolated⟩ := uniform_reference_nonisolated_mass R hR D hD theta htheta htheta1 (eps/3) he + refine ⟨alpha,max BA (max BB BC),max WA (max WB WC),ha,hath,hBA.trans (le_max_left _ _),hWA.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw₀ hw htop xi hxi hxi1 hsmall hcomp z hi h199 h23 hz hcut hclosed hcap F hF hg + have hBa : BA ≤ B := (le_max_left _ _).trans hB + have hBb : BB ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hB + have hBc : BC ≤ B := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hB + have hWa : WA ≤ w := (le_max_left _ _).trans hw₀ + have hWb : WB ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw₀ + have hWc : WC ≤ w := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hw₀ + have hb := hBasic B w top hBa hWa hw htop xi hxi hxi1 hsmall hcomp z hi h199 h23 hz hcut hclosed hcap F hF hg + have hr := hRepeat B w top hBb hWb hw htop xi hxi hxi1 hcomp z hi h199 h23 hz hcut hclosed hcap + (F.filter (compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L z)) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) + (fun ps hp => ⟨hg ps (Finset.mem_filter.mp hp).1,Or.inr (Finset.mem_filter.mp hp).2⟩) + have hi' := hIsolated B w top hBc hWc hw htop xi hxi hxi1 hcomp z hi h199 h23 hz hcut hclosed hcap + (F.filter (noIsolatedWord hw htop hxi B alpha (4*theta))) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) + (fun ps hp => ⟨hg ps (Finset.mem_filter.mp hp).1,(Finset.mem_filter.mp hp).2⟩) + have hp := mul_le_mul_of_nonneg_left (geometric_defect_sum (C:=Clen) (B:=B) (R:=R) (L:=L) (alpha:=alpha) + (beta:=4*theta) hw htop hxi z F) (sq_nonneg B) + nlinarith +end NumberTheoryLean.GeometricRegularMass + + + +namespace NumberTheoryLean.UniformGeometricRegularMass +open FinitePathGeometry PrimeHistories ActualRegularBoxes GeometricRegularWords +open RepeatedWordEvents NonisolatedWordOccurrence ReferenceAdmission GeometricDefectPartition +open BasicRegularMass ReferenceRepeatedExclusion ReferenceIsolatedExclusion +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem geometric_defect_uniform_in_L (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) + (theta : ℝ) (htheta : 0 < theta) (htheta1 : theta ≤ 1/2) : + ∃ Clen₀ C : ℝ,1 ≤ Clen₀ ∧ 0 < C ∧ ∀ Clen : ℝ,Clen₀ ≤ Clen → ∀ eps : ℝ,0 < eps → + ∃ alpha : ℝ,0 < alpha ∧ alpha ≤ theta ∧ ∀ L : ℝ,0 ≤ L → + ∃ B₀ w₀ : ℝ,3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ hw : 1 < w,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → 20*Clen*xi ≤ 1 → Real.log B ≤ D*Real.log w → + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + PrimeBinMembership.Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ F : Finset (List ℕ),F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (∀ ps ∈ F,(terminal w z ps).gap ≤ R) → + B^2*(∑ ps ∈ F \ geometricWords hw htop hxi Clen B R L alpha (4*theta) z,prefixWeight ps) ≤ C*(2*Clen*xi)+eps := by + obtain ⟨Clen₀,C,hClen₀,hC,hBasic⟩ := basic_regular_defect_mass R hR D hD + refine ⟨Clen₀,C,hClen₀,hC,?_⟩ + intro Clen hClen eps heps + have he : 0 < eps/3 := by positivity + obtain ⟨BA,WA,hBA,hWA,hBasic⟩ := hBasic Clen hClen (eps/3) he + obtain ⟨alpha,BC,WC,ha,hath,hBC,hWC,hIsolated⟩ := uniform_reference_nonisolated_mass R hR D hD theta htheta htheta1 (eps/3) he + refine ⟨alpha,ha,hath,?_⟩ + intro L hL + obtain ⟨BB,WB,hBB,hWB,hRepeat⟩ := uniform_reference_repeated_mass R hR D hD L hL (eps/3) he + refine ⟨max BA (max BB BC),max WA (max WB WC),hBA.trans (le_max_left _ _),hWA.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw₀ hw htop xi hxi hxi1 hsmall hcomp z hi h199 h23 hz hcut hclosed hcap F hF hg + have hBa : BA ≤ B := (le_max_left _ _).trans hB + have hBb : BB ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hB + have hBc : BC ≤ B := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hB + have hWa : WA ≤ w := (le_max_left _ _).trans hw₀ + have hWb : WB ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw₀ + have hWc : WC ≤ w := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hw₀ + have hb := hBasic B w top hBa hWa hw htop xi hxi hxi1 hsmall hcomp z hi h199 h23 hz hcut hclosed hcap F hF hg + have hr := hRepeat B w top hBb hWb hw htop xi hxi hxi1 hcomp z hi h199 h23 hz hcut hclosed hcap + (F.filter (compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L z)) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) + (fun ps hp => ⟨hg ps (Finset.mem_filter.mp hp).1,Or.inr (Finset.mem_filter.mp hp).2⟩) + have hi' := hIsolated B w top hBc hWc hw htop xi hxi hxi1 hcomp z hi h199 h23 hz hcut hclosed hcap + (F.filter (noIsolatedWord hw htop hxi B alpha (4*theta))) + (fun ps hp => hF (Finset.mem_filter.mp hp).1) + (fun ps hp => ⟨hg ps (Finset.mem_filter.mp hp).1,(Finset.mem_filter.mp hp).2⟩) + have hp := mul_le_mul_of_nonneg_left (geometric_defect_sum (C:=Clen) (B:=B) (R:=R) (L:=L) (alpha:=alpha) + (beta:=4*theta) hw htop hxi z F) (sq_nonneg B) + nlinarith +end NumberTheoryLean.UniformGeometricRegularMass + + + +namespace NumberTheoryLean.ExpandedCompactPartition +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualRegularBoxes ActualWordSelection +open StoppedCountAdapters StoppedTraceSets ExpandedHardCapture RegularStoppedEvent +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open GeometricRegularWords CountErrorClassification LiteralCountErrorLedger +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass +open ErdosPrimeInputs.PrimePrefixTail ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +noncomputable def listedWord {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Cs : ℝ) (a : ℕ → ℕ) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (ps : List ℕ) : Prop := + ∃ q∈Q (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps), + ∀ p∈ps,Cs < primeExponent w p → aligns (sourceClass a) q p + +noncomputable def unlistedGeometric {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Cs C B K L alpha beta : ℝ) + (a : ℕ → ℕ) (z : Node) (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (F : Finset (List ℕ)) : Finset (List ℕ) := + (F∩geometricWords hw htop hxi C B K L alpha beta z).filter (fun ps => ¬listedWord hw htop hxi Cs a Q ps) + +theorem expanded_geometric_mass_split {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta C B K L alpha beta b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : Node) + (H : Finset ℕ) (mu : ℝ) (n : ℕ) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (F : Finset (List ℕ)) + (hexp : F ⊆ expanded w + (stopCandidate Y w Cs eta C B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + n (rootVertex z H (sourcePrimeSet w top) mu)) : + (∑ ps∈F,prefixWeight ps) ≤ + (∑ ps∈F\geometricWords hw htop hxi C B K L alpha beta z,prefixWeight ps)+ + (∑ ps∈unlistedGeometric hw htop hxi Cs C B K L alpha beta a z Q F,prefixWeight ps)+ + ∑ ps∈uncapturedRegular hw htop hxi Y Cs eta C B K b₀ b₁ a z Q,prefixWeight ps := by + let G := geometricWords hw htop hxi C B K L alpha beta z + let T := (F∩G).filter (listedWord hw htop hxi Cs a Q) + have hTexp : T ⊆ expanded w + (stopCandidate Y w Cs eta C B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + n (rootVertex z H (sourcePrimeSet w top) mu) := + fun _ hp => hexp (Finset.mem_inter.mp (Finset.mem_filter.mp hp).1).1 + have hTreg : T ⊆ regularWords hw htop hxi C B K z := + fun _ hp => (Finset.mem_filter.mp (Finset.mem_inter.mp (Finset.mem_filter.mp hp).1).2).1 + have hTalign : ∀ ps∈T,∃ q∈Q (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps), + ∀ p∈ps,Cs < primeExponent w p → aligns (sourceClass a) q p := + fun _ hp => (Finset.mem_filter.mp hp).2 + have hbound := expanded_listed_mass_le hw htop hxi Y Cs eta C B K b₀ b₁ a z H mu n Q T hTexp hTreg hTalign + have hsplit := Finset.sum_filter_add_sum_filter_not (F∩G) (listedWord hw htop hxi Cs a Q) prefixWeight + have hgeo := Finset.sum_filter_add_sum_filter_not F (fun ps => ps∈G) prefixWeight + simp only [Finset.filter_mem_eq_inter,← Finset.sdiff_eq_filter] at hgeo + change (∑ ps∈F,prefixWeight ps) ≤ (∑ ps∈F\G,prefixWeight ps)+ + (∑ ps∈(F∩G).filter (fun ps => ¬listedWord hw htop hxi Cs a Q ps),prefixWeight ps)+_ + dsimp only [T] at hbound + linarith + +theorem bad_compact_reference_data (w top K eps : ℝ) (Y : ℕ) (a : ℕ → ℕ) + (z : Node) (stop : List ℕ → Prop) (n : ℕ) (V0 : ℝ) : + let F := badCompactWords w K eps Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a V0 z + (expanded w stop n (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*V0))) + F ⊆ ReferenceAdmission.referencePrefixes w (sourcePrimeSet w top) z.side z.gap ∧ + ∀ ps∈F,(terminal w z ps).gap ≤ K := by + dsimp only + exact ⟨fun _ hp => expanded_reference_subset w _ z _ stop n (Finset.mem_filter.mp hp).1, + fun _ hp => (Finset.mem_filter.mp hp).2.1⟩ +end NumberTheoryLean.ExpandedCompactPartition + + + +namespace NumberTheoryLean.PaperGeometricRegularity +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open JacobsthalSourceScale GeometricRegularWords GeometricRegularMass IsolatedSourceScales +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinEndpoints LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass +open scoped Topology + +attribute [local instance] Classical.propDecidable + +theorem paper_geometric_defect_mass (R : ℝ) (hR : 3 ≤ R) (L : ℝ) (hL : 0 ≤ L) : + ∃ Clen₀ C : ℝ,1 ≤ Clen₀ ∧ 0 < C ∧ ∀ Clen : ℝ,Clen₀ ≤ Clen → ∀ eps : ℝ,0 < eps → + ∃ alpha : ℝ,0 < alpha ∧ alpha ≤ 1/400 ∧ ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → 20*Clen*xi ≤ 1 → + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + (sourceW (Real.log top))^((1/4:ℝ)) ≤ alpha*sourceB (Real.log top) ∧ + ∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + Consistent z → z.cutoff=sourceB (Real.log top) → z.closed=true → + ∀ F : Finset (List ℕ),F ⊆ ReferenceAdmission.referencePrefixes (sourceW (Real.log top)) + (sourcePrimeSet (sourceW (Real.log top)) top) z.side z.gap → + (∀ ps ∈ F,(terminal (sourceW (Real.log top)) z ps).gap ≤ R) → + (sourceB (Real.log top))^2*(∑ ps ∈ F \ geometricWords hw htop hxi Clen (sourceB (Real.log top)) R L alpha (1/100) z, + prefixWeight ps) ≤ C*(2*Clen*xi)+eps := by + obtain ⟨Clen₀,C,hClen₀,hC,hBound⟩ := geometric_regular_defect_mass R hR 2 (by norm_num) L hL (1/400) (by norm_num) (by norm_num) + refine ⟨Clen₀,C,hClen₀,hC,?_⟩ + intro Clen hClen eps heps + obtain ⟨alpha,B₀,w₀,ha,hath,hB₀,hw₀,hMass⟩ := hBound Clen hClen eps heps + refine ⟨alpha,ha,hath,?_⟩ + intro xi hxi hxi1 hsmall + have hwT := sourceW_tendsto.comp Real.tendsto_log_atTop + have hBT := sourceB_tendsto.comp Real.tendsto_log_atTop + filter_upwards [hwT.eventually_ge_atTop w₀,hBT.eventually_ge_atTop B₀, + Real.tendsto_log_atTop.eventually source_scale_eventually, + Real.tendsto_log_atTop.eventually (source_isolated_search_scale ha), + eventually_gt_atTop (1:ℝ)] with top hwB hBB hscale hsearch htop1 + have hw : 1 < sourceW (Real.log top) := hscale.1 + have htop : sourceW (Real.log top) < top := by + have hpow : (sourceW (Real.log top))^(sourceB (Real.log top))=top := + (sourceW_pow_sourceB hw).trans (Real.exp_log (zero_lt_one.trans htop1)) + have hB3 : 3 ≤ sourceB (Real.log top) := hB₀.trans hBB + have hh := Real.rpow_lt_rpow_of_exponent_lt hw (show (1:ℝ) ∀ t ∈ small,(sourceParentBase p q hqp hq a+p*q*j)%t ≠ a t%t) + +theorem modulusCandidates_eq_parent_image (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (p q : ℕ) [NeZero p] (hp : p.Prime) (hqp : q.Coprime p) (hq : Squarefree q) : + modulusCandidates Y small a (p*q) = + (parentSurvivorCoordinates Y small a p q hqp hq).image + (fun j => sourceParentBase p q hqp hq a+p*q*j) := by + classical + have hM : 0 < p*q := mul_pos hp.pos (Nat.pos_of_ne_zero hq.ne_zero) + have hb := sourceParentBase_bounds p q hqp hq a + ext n + rw [mem_modulusCandidates] + simp only [parentSurvivorCoordinates,Finset.mem_image,Finset.mem_filter,Finset.mem_range] + constructor + · rintro ⟨hn1,hnY,hpr,hs⟩ + have hres := (source_parent_hits_iff p q hp hqp hq a n).mp hpr + obtain ⟨j,rfl⟩ := exists_positive_coordinate (p*q) _ n hM hb.1 hb.2 hn1 hres + exact ⟨j,⟨(lt_hitLength_iff Y (p*q) _ j hM hb.2).mpr hnY,hs⟩,rfl⟩ + · rintro ⟨j,⟨hj,hs⟩,rfl⟩ + refine ⟨by omega,(lt_hitLength_iff Y (p*q) _ j hM hb.2).mp hj,?_,hs⟩ + apply (source_parent_hits_iff p q hp hqp hq a _).mpr + change (_+p*q*j)%(p*q) = _%(p*q) + simp + +theorem modulusCount_eq_parent_card (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (p q : ℕ) [NeZero p] (hp : p.Prime) (hqp : q.Coprime p) (hq : Squarefree q) : + modulusCount Y small a (p*q) = + ((parentSurvivorCoordinates Y small a p q hqp hq).card : ℤ) := by + unfold modulusCount + rw [modulusCandidates_eq_parent_image Y small a p q hp hqp hq, + Finset.card_image_of_injective] + intro i j hij + exact Nat.eq_of_mul_eq_mul_left (mul_pos hp.pos (Nat.pos_of_ne_zero hq.ne_zero)) + (Nat.add_left_cancel hij) + +theorem source_parent_length_error (Y p q : ℕ) [NeZero p] (hp : p.Prime) + (hqp : q.Coprime p) (hq : Squarefree q) (a : ℕ → ℕ) : + |(hitLength Y (p*q) (sourceParentBase p q hqp hq a) : ℝ)-(Y : ℝ)/(p*q)| ≤ 1 := by + have hb := sourceParentBase_bounds p q hqp hq a + simpa only [Nat.cast_mul] using hitLength_error Y (p*q) (sourceParentBase p q hqp hq a) + (mul_pos hp.pos (Nat.pos_of_ne_zero hq.ne_zero)) hb.1 hb.2 + +end ErdosInverseHits + +end + +section + +namespace ErdosInverseHits +open ErdosInverseCounts NumberTheoryLean NumberTheoryLean.SievePartition ErdosInverseCRT + +noncomputable def parentEdgeResidue (p q u : ℕ) [NeZero p] (hqp : q.Coprime p) + (hq : Squarefree q) (hpu : p.Coprime u) (hqu : q.Coprime u) (a : ℕ → ℕ) : ZMod u := + sourceEdgeResidue p q u hpu hqu (a u) (primeHitRepresentative q hq a) + (parentSlope p q hqp (a p) (primeHitRepresentative q hq a)) + +theorem parent_edge_hit_iff (p q u : ℕ) [NeZero p] (hqp : q.Coprime p) + (hq : Squarefree q) (hpu : p.Coprime u) (hqu : q.Coprime u) (a : ℕ → ℕ) (j : ℕ) : + residueBad a u (sourceParentBase p q hqp hq a+p*q*j) ↔ + (j : ZMod u) = parentEdgeResidue p q u hqp hq hpu hqu a := by + change Nat.ModEq u (sourceParentBase p q hqp hq a+p*q*j) (a u) ↔ _ + rw [← ZMod.natCast_eq_natCast_iff] + have h := source_progression_edge_hit p q u hpu hqu (a u) + (primeHitRepresentative q hq a) (parentSlope p q hqp (a p) (primeHitRepresentative q hq a)) j + simpa only [sourceParentBase,parentEdgeResidue,Int.cast_add,Int.cast_mul,Int.cast_natCast, + Nat.cast_add,Nat.cast_mul,mul_add,mul_assoc,add_assoc,mul_left_comm (q : ZMod u) (p : ZMod u)] using h + +theorem modulusCandidates_eq_edge_image (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (p q u : ℕ) [NeZero p] (hp : p.Prime) (hu : u.Prime) (hqp : q.Coprime p) + (hq : Squarefree q) (hpu : p.Coprime u) (hqu : q.Coprime u) : + modulusCandidates Y small a (p*q*u) = + ((parentSurvivorCoordinates Y small a p q hqp hq).filter + (fun j : ℕ => (j : ZMod u) = parentEdgeResidue p q u hqp hq hpu hqu a)).image + (fun j => sourceParentBase p q hqp hq a+p*q*j) := by + classical + rw [Nat.mul_comm (p*q) u,modulusCandidates_prime_mul Y small a u (p*q) hu + (mul_ne_zero hp.ne_zero hq.ne_zero),modulusCandidates_eq_parent_image Y small a p q hp hqp hq] + ext n + simp only [Finset.mem_filter,Finset.mem_image] + constructor + · rintro ⟨⟨j,hj,rfl⟩,hhit⟩ + exact ⟨j,⟨hj,(parent_edge_hit_iff p q u hqp hq hpu hqu a j).mp hhit⟩,rfl⟩ + · rintro ⟨j,⟨hj,hhit⟩,rfl⟩ + exact ⟨⟨j,hj,rfl⟩,(parent_edge_hit_iff p q u hqp hq hpu hqu a j).mpr hhit⟩ + +theorem modulusCount_eq_edge_card (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (p q u : ℕ) [NeZero p] (hp : p.Prime) (hu : u.Prime) (hqp : q.Coprime p) + (hq : Squarefree q) (hpu : p.Coprime u) (hqu : q.Coprime u) : + modulusCount Y small a (p*q*u) = + (((parentSurvivorCoordinates Y small a p q hqp hq).filter + (fun j : ℕ => (j : ZMod u) = parentEdgeResidue p q u hqp hq hpu hqu a)).card : ℤ) := by + classical + unfold modulusCount + rw [modulusCandidates_eq_edge_image Y small a p q u hp hu hqp hq hpu hqu, + Finset.card_image_of_injective] + intro i j hij + exact Nat.eq_of_mul_eq_mul_left (mul_pos hp.pos (Nat.pos_of_ne_zero hq.ne_zero)) + (Nat.add_left_cancel hij) + +end ErdosInverseHits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/RationalParameterInterval.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RationalParameterInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..cfa55678228624939c2b29a07761e6820680b58f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RationalParameterInterval.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.AlignedPrimeCongruence + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosAlignedProgression +attribute [local instance] Classical.decEq + +def parameterLower (r : ℚ) (d : ℕ) : ℤ := -((r.num-(r.den : ℤ))/(d : ℤ)) +def parameterUpper (Y : ℕ) (r : ℚ) (d : ℕ) : ℤ := ((r.den : ℤ)*(Y : ℤ)-r.num)/(d : ℤ) +noncomputable def parameterInterval (Y : ℕ) (r : ℚ) (d : ℕ) : Finset ℤ := + Finset.Icc (parameterLower r d) (parameterUpper Y r d) + +theorem mem_parameterInterval (Y : ℕ) (r : ℚ) (d : ℕ) (hd : 0 < d) (m : ℤ) : + m ∈ parameterInterval Y r d ↔ + (r.den : ℤ) ≤ r.num+(d : ℤ)*m ∧ r.num+(d : ℤ)*m ≤ (r.den : ℤ)*(Y : ℤ) := by + have hdZ : (0 : ℤ) < d := by exact_mod_cast hd + rw [parameterInterval, Finset.mem_Icc] + have hl : parameterLower r d ≤ m ↔ (r.den : ℤ) ≤ r.num+(d : ℤ)*m := by + unfold parameterLower + constructor + · intro h + have hn : -m ≤ (r.num-(r.den : ℤ))/(d : ℤ) := by linarith + have hh := (Int.le_ediv_iff_mul_le hdZ).mp hn + nlinarith + · intro h + have hn : -m ≤ (r.num-(r.den : ℤ))/(d : ℤ) := by + apply (Int.le_ediv_iff_mul_le hdZ).mpr + nlinarith + linarith + have hu : m ≤ parameterUpper Y r d ↔ r.num+(d : ℤ)*m ≤ (r.den : ℤ)*(Y : ℤ) := by + unfold parameterUpper + rw [Int.le_ediv_iff_mul_le hdZ] + constructor <;> intro h <;> nlinarith + exact and_congr hl hu + +def parameterValue (r : ℚ) (d : ℕ) (m : ℤ) : ℕ := + ((r.num+(d : ℤ)*m)/(r.den : ℤ)).toNat + +theorem parameterValue_spec (Y : ℕ) (r : ℚ) (d : ℕ) (hd : 0 < d) (m : ℤ) + (hm : m ∈ parameterInterval Y r d) (hdiv : (r.den : ℤ) ∣ r.num+(d : ℤ)*m) : + 1 ≤ parameterValue r d m ∧ parameterValue r d m ≤ Y ∧ + (r.den : ℤ)*(parameterValue r d m : ℤ) = r.num+(d : ℤ)*m := by + have hb := (mem_parameterInterval Y r d hd m).mp hm + have hD : (0 : ℤ) < r.den := by exact_mod_cast r.den_pos + have hquot : (1 : ℤ) ≤ (r.num+(d : ℤ)*m)/(r.den : ℤ) := by + apply (Int.le_ediv_iff_mul_le hD).mpr + simpa only [one_mul] using hb.1 + have hcast : (parameterValue r d m : ℤ) = (r.num+(d : ℤ)*m)/(r.den : ℤ) := + Int.toNat_of_nonneg (by linarith) + have he : (r.den : ℤ)*(parameterValue r d m : ℤ) = r.num+(d : ℤ)*m := by + rw [hcast] + exact Int.mul_ediv_cancel_of_dvd hdiv + have hlo : (1 : ℤ) ≤ parameterValue r d m := by rw [hcast]; exact hquot + have hhi : (parameterValue r d m : ℤ) ≤ Y := by + have hm : (r.den : ℤ)*(parameterValue r d m : ℤ) ≤ (r.den : ℤ)*(Y : ℤ) := by + rw [he] + exact hb.2 + nlinarith + exact ⟨by exact_mod_cast hlo, by exact_mod_cast hhi, he⟩ + +end ErdosAlignedProgression + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/RealProgressionCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RealProgressionCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..60f8d3b8c2004dbc3bfd50c5621d939429850164 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RealProgressionCoordinates.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.Jacobsthal.Primes.ProgressionPrimeUpper + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosPrimeInputs.RealProgressionCoordinates + +open AffinePrimeSieve + +theorem exists_coordinates (x H : ℝ) (q : ℕ) (r : ℤ) (hq : 0 < q) (hH : 0 ≤ H) : + ∃ (N : ℕ) (a : ℤ) (index : ℤ → ℕ), + |(N:ℝ)-H/q| ≤ 1 ∧ + ∀ z : ℤ, x < (z:ℝ) → (z:ℝ) ≤ x+H → Int.ModEq (q:ℤ) z r → + index z < N ∧ value a q (index z) = z := by + have hqR : (0:ℝ) < q := by exact_mod_cast hq + let low : ℝ := (x-r)/q + let high : ℝ := (x+H-r)/q + let L : ℤ := ⌊low⌋ + let U : ℤ := ⌊high⌋ + have hLH : low ≤ high := div_le_div_of_nonneg_right (by linarith) hqR.le + have hLU : L ≤ U := Int.floor_mono hLH + let N : ℕ := (U-L).toNat + let a : ℤ := r+(q:ℤ)*(L+1) + let index : ℤ → ℕ := fun z => ((z-r)/(q:ℤ)-(L+1)).toNat + have hN : (N:ℤ)=U-L := Int.toNat_of_nonneg (sub_nonneg.mpr hLU) + have hNR : (N:ℝ)=(U:ℝ)-(L:ℝ) := by + have hh := congrArg (fun t : ℤ => (t:ℝ)) hN + push_cast at hh + exact hh + have hlength : high-low=H/q := by dsimp [high,low]; ring + have hcount : |(N:ℝ)-H/q| ≤ 1 := by + have hL := Int.floor_le low + have hL' := Int.lt_floor_add_one low + have hU := Int.floor_le high + have hU' := Int.lt_floor_add_one high + change (L:ℝ) ≤ low at hL + change low < (L:ℝ)+1 at hL' + change (U:ℝ) ≤ high at hU + change high < (U:ℝ)+1 at hU' + rw [hNR,← hlength,abs_le] + constructor <;> linarith + refine ⟨N,a,index,hcount,?_⟩ + intro z hzlo hzhi hzmod + let k : ℤ := (z-r)/(q:ℤ) + have hdiv : (q:ℤ) ∣ z-r := Int.modEq_iff_dvd.mp hzmod.symm + have hk : z=r+(q:ℤ)*k := by + have hh := Int.ediv_mul_cancel hdiv + change k*(q:ℤ)=z-r at hh + nlinarith + have hkR : (z:ℝ)=(r:ℝ)+(q:ℝ)*(k:ℝ) := by exact_mod_cast hk + have hlow : low < (k:ℝ) := by + apply (div_lt_iff₀ hqR).mpr + linarith + have hhigh : (k:ℝ) ≤ high := by + apply (le_div_iff₀ hqR).mpr + linarith + have hLk : L < k := Int.floor_lt.mpr hlow + have hkU : k ≤ U := Int.le_floor.mpr hhigh + have hnonneg : 0 ≤ k-(L+1) := by omega + have hi : (index z : ℤ)=k-(L+1) := Int.toNat_of_nonneg hnonneg + constructor + · have hh : (index z : ℤ) < (N:ℤ) := by rw [hi,hN]; omega + exact_mod_cast hh + · calc + value a q (index z) = r+(q:ℤ)*k := by + dsimp [value,a] + rw [hi] + ring + _ = z := hk.symm + +end ErdosPrimeInputs.RealProgressionCoordinates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ReferenceHighIntervals.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ReferenceHighIntervals.lean new file mode 100644 index 0000000000000000000000000000000000000000..50e9337deae77b3eaca7e908f1f74f56f9ed2c78 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ReferenceHighIntervals.lean @@ -0,0 +1,93 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceSourceDecomposition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceHighIntervals + +attribute [local instance] Classical.propDecidable +open _root_.Finset _root_.Set _root_.MeasureTheory +open FinitePathGeometry PrimeTiltGeometry ReferenceSourcePrimeSets ReferenceMertens +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimeEndpoints + +noncomputable def highInterval (b : ℝ) (closed : Bool) : Set ℝ := + {x | 2 simp only [highInterval,capGuard,Bool.false_eq_true,ite_false,ite_true] <;> measurability + +theorem highInterval_orderConnected (b : ℝ) (closed : Bool) : (highInterval b closed).OrdConnected := by + cases closed + · exact ordConnected_Ioo + · exact ordConnected_Ioc + +theorem highInterval_subset (b : ℝ) (closed : Bool) : highInterval b closed ⊆ Icc 2 b := by + intro x hx + refine ⟨hx.1.le,?_⟩ + cases closed + · exact hx.2.le + · exact hx.2 + +theorem highPrimes_eq_filter {w : ℝ} (hw : 1 < w) (b : ℝ) (closed : Bool) : + highPrimes w b closed=(Nat.primesLE ⌊w^b⌋₊).filter (fun p => primeExponent w p ∈ highInterval b closed) := by + ext p + rw [highPrimes_membership hw,Finset.mem_filter] + constructor + · rintro ⟨hp,hlo,hcap⟩ + have hup : primeExponent w p ≤ b := by + cases closed + · exact hcap.le + · exact hcap + have hpx := (exponent_le_iff hw (by exact_mod_cast hp.pos)).mp hup + have hfloor := (Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) b).le).mpr hpx + exact ⟨Nat.mem_primesLE.mpr ⟨hfloor,hp⟩,hlo,hcap⟩ + · rintro ⟨hp,hlo,hcap⟩ + exact ⟨(Nat.mem_primesLE.mp hp).2,hlo,hcap⟩ + +theorem highPrime_sum {w : ℝ} (hw : 1 < w) (b : ℝ) (closed : Bool) (F : ℕ → ℝ) : + (∑ p ∈ highPrimes w b closed,F p)= + ∑ p ∈ Nat.primesLE ⌊w^b⌋₊,if primeExponent w p ∈ highInterval b closed then F p else 0 := by + rw [highPrimes_eq_filter hw,Finset.sum_filter] + +theorem highPrime_mass_eq {w : ℝ} (hw : 1 < w) (b : ℝ) (closed : Bool) : + (∑ p ∈ highPrimes w b closed,(p:ℝ)⁻¹)=harmonicMass w false closed 2 b := by + rw [highPrime_sum hw,harmonicMass] + apply Finset.sum_congr rfl + intro p _hp + simp only [highInterval,capGuard,intervalGuard,Bool.false_eq_true,ite_false,Set.mem_ofPred_eq] + split_ifs <;> rfl + +theorem highInterval_integral {b : ℝ} (hb : 2 ≤ b) (closed : Bool) (F : ℝ → ℝ) : + (∫ x in highInterval b closed,F x)=∫ x in (2:ℝ)..b,F x := by + cases closed + · change (∫ x in Ioo 2 b,F x)=_ + rw [← integral_Ioc_eq_integral_Ioo,intervalIntegral.integral_of_le hb] + · exact (intervalIntegral.integral_of_le hb).symm + +theorem highPrime_mass_bound : ∃ C w₀ : ℝ,0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ b : ℝ,2 ≤ b → ∀ closed : Bool, + (∑ p ∈ highPrimes w b closed,(p:ℝ)⁻¹) ≤ C*(1+Real.log b) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := harmonic_prime_measure + refine ⟨C+1,w₀,by positivity,hw₀,?_⟩ + intro w hw b hb closed + have hw1 : 1 < w := hw₀.trans_le hw + rw [highPrime_mass_eq hw1] + have hh := h w hw 2 b (by norm_num) hb false closed + have he : Real.exp (-c*Real.sqrt (2*Real.log w)) ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hc.le) (Real.sqrt_nonneg _)) + have hu := (abs_le.mp hh).2 + have hlog : 0 ≤ Real.log b := Real.log_nonneg (by linarith) + have hl2 : 0 ≤ Real.log (2:ℝ) := Real.log_nonneg (by norm_num) + nlinarith [mul_le_mul_of_nonneg_left he hC.le] + +end NumberTheoryLean.ReferenceHighIntervals + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ReferenceIntervalBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ReferenceIntervalBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..cebfbf06cfccb7095a3d6056884ffeae132cf110 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ReferenceIntervalBound.lean @@ -0,0 +1,417 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.MovingLocalReference + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceIntervalCutoff + +attribute [local instance] Classical.propDecidable +open _root_.Finset _root_.Set _root_.MeasureTheory +open FinitePathGeometry PrimeHistories PrimeTiltGeometry PrimeBinMembership +open ReferenceSourcePrimeSets ReferenceMertens ReferenceLocalResidual ReferenceHighIntervals ReferenceResidualErrors +open ReferenceBenchmarkDecay ReferenceDifferentiation +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def primeInterval (a b : ℝ) (closed : Bool) : Set ℝ := + {x | a a simp only [primeInterval,capGuard,Bool.false_eq_true,ite_false,ite_true] <;> measurability + +theorem primeInterval_orderConnected (a b : ℝ) (closed : Bool) : (primeInterval a b closed).OrdConnected := by + cases closed + · exact ordConnected_Ioo + · exact ordConnected_Ioc + +theorem primeInterval_subset (a b : ℝ) (closed : Bool) : primeInterval a b closed ⊆ Icc a b := by + intro x hx + refine ⟨hx.1.le,?_⟩ + cases closed + · exact hx.2.le + · exact hx.2 + +theorem primeInterval_integral {a b : ℝ} (hab : a ≤ b) (closed : Bool) (F : ℝ → ℝ) : + (∫ x in primeInterval a b closed,F x)=∫ x in a..b,F x := by + cases closed + · change (∫ x in Ioo a b,F x)=_ + rw [← integral_Ioc_eq_integral_Ioo,intervalIntegral.integral_of_le hab] + · exact (intervalIntegral.integral_of_le hab).symm + +theorem intervalPrimes_eq_filter {w a : ℝ} (hw : 1 < w) (ha : 2 ≤ a) (b : ℝ) (closed : Bool) : + intervalPrimes w a b closed=(Nat.primesLE ⌊w^b⌋₊).filter (fun p => primeExponent w p ∈ primeInterval a b closed) := by + rw [intervalPrimes,highPrimes_eq_filter hw,Finset.filter_filter] + apply Finset.filter_congr + intro p _hp + simp only [highInterval,primeInterval,Set.mem_ofPred_eq] + constructor + · rintro ⟨⟨_h2,hcap⟩,haP⟩ + exact ⟨haP,hcap⟩ + · rintro ⟨haP,hcap⟩ + exact ⟨⟨ha.trans_lt haP,hcap⟩,haP⟩ + +theorem intervalPrime_sum {w a : ℝ} (hw : 1 < w) (ha : 2 ≤ a) (b : ℝ) (closed : Bool) (F : ℕ → ℝ) : + (∑ p ∈ intervalPrimes w a b closed,F p)= + ∑ p ∈ Nat.primesLE ⌊w^b⌋₊,if primeExponent w p ∈ primeInterval a b closed then F p else 0 := by + rw [intervalPrimes_eq_filter hw ha,Finset.sum_filter] + +theorem lowerHigh_subset {w a b : ℝ} (hw : 1 < w) (hab : a < b) (closed : Bool) : + highPrimes w a true ⊆ highPrimes w b closed := by + intro p hp + obtain ⟨hpP,h2,ha⟩ := (highPrimes_membership hw a true p).mp hp + have ha' : primeExponent w p ≤ a := ha + apply (highPrimes_membership hw b closed p).mpr + refine ⟨hpP,h2,?_⟩ + cases closed + · exact ha'.trans_lt hab + · exact ha'.trans hab.le + +theorem highPrimes_split {w a b : ℝ} (hw : 1 < w) (hab : a < b) (closed : Bool) : + highPrimes w b closed=highPrimes w a true ∪ intervalPrimes w a b closed := by + ext p + constructor + · intro hp + by_cases hx : a simp only [hi,Valid] at hs ⊢ <;> linarith + · change a=z.gap/(z.gap/a) + field_simp + +end NumberTheoryLean.ReferenceIntervalCutoff + +end + +section + +namespace NumberTheoryLean.ReferenceIntervalErrors + +open _root_.Finset _root_.Set _root_.MeasureTheory +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry +open ReferenceBenchmarkDecay ReferenceDifferentiation ReferenceCancellation ReferenceWeightDomination +open ReferenceMertens ReferenceResidualErrors ReferenceIntervalCutoff +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def lowerProductError (w : ℝ) (z : Node) (a : ℝ) : ℝ := + (referenceProduct w a true-normalization w/a)*(parentBenchmark z.side (z.gap/a)-1) + +noncomputable def intervalPrimeError (w : ℝ) (z : Node) (a : ℝ) : ℝ := + ∑ p ∈ intervalPrimes w a z.cutoff z.closed,(p:ℝ)⁻¹* + (referenceProduct w (primeExponent w p) false-normalization w/primeExponent w p)* + (benchmark z.side.flip (childRatio w z.gap p)-1) + +noncomputable def intervalQuadratureError (w : ℝ) (z : Node) (a : ℝ) : ℝ := + (∑ p ∈ intervalPrimes w a z.cutoff z.closed,(p:ℝ)⁻¹* + (benchmark z.side.flip (childRatio w z.gap p)-1)/primeExponent w p)- + ∫ x in primeInterval a z.cutoff z.closed,(benchmark z.side.flip (z.gap/x-1)-1)/x^2 + +theorem continuous_interval_cancellation (i : Side) {r a b : ℝ} (ha : 2 ≤ a) (hab : a ≤ b) + (hs : ParentDomain i (r/b)) : + (parentBenchmark i (r/a)-1)/a-(parentBenchmark i (r/b)-1)/b- + (∫ x in a..b,(benchmark i.flip (r/x-1)-1)/x^2)=0 := by + have hb : 2 ≤ b := ha.trans hab + have hi : IntervalIntegrable (fun x => (benchmark i.flip (r/x-1)-1)/x^2) volume a b := by + apply ContinuousOn.intervalIntegrable_of_Icc hab + intro x hx + exact (prospective_integrand_continuousAt i (by linarith [hx.1]) + (parent_domain_interval i hb hs ⟨ha.trans hx.1,hx.2⟩)).continuousWithinAt + have hd : ∀ x ∈ uIcc a b,HasDerivAt (fun t => (parentBenchmark i (r/t)-1)/t) + (-(benchmark i.flip (r/x-1)-1)/x^2) x := by + intro x hx + rw [uIcc_of_le hab] at hx + exact reference_derivative i (by linarith [hx.1]) (parent_domain_interval i hb hs ⟨ha.trans hx.1,hx.2⟩) + have hin : IntervalIntegrable (fun x => -(benchmark i.flip (r/x-1)-1)/x^2) volume a b := by + convert! hi.neg using 1 + funext x + exact neg_div _ _ + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt hd hin + simp_rw [neg_div] at h + rw [intervalIntegral.integral_neg] at h + linarith + +theorem normalized_interval_zero (w : ℝ) {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) + {a : ℝ} (ha : 2 ≤ a) (hab : a ≤ z.cutoff) : + (normalization w/a)*(parentBenchmark z.side (z.gap/a)-1)- + (normalization w/z.cutoff)*(parentBenchmark z.side z.ratio-1)- + normalization w*(∫ x in primeInterval a z.cutoff z.closed,(benchmark z.side.flip (z.gap/x-1)-1)/x^2)=0 := by + have hr := ratio_eq_gap_div_cutoff hs hz (by linarith) + have hd : ParentDomain z.side (z.gap/z.cutoff) := by rw [← hr]; exact valid_parent_domain hs + have hc := continuous_interval_cancellation z.side ha hab hd + rw [← hr] at hc + rw [primeInterval_integral hab] + have hm := congrArg (fun t : ℝ => normalization w*t) hc + convert! hm using 1 <;> ring + +theorem interval_error_identity (w : ℝ) {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) + {a : ℝ} (ha : 2 ≤ a) (hab : a ≤ z.cutoff) : + intervalResidual w z a=lowerProductError w z a-parentProductError w z-intervalPrimeError w z a- + normalization w*intervalQuadratureError w z a := by + have hc := normalized_interval_zero w hs hz ha hab + have hp : (∑ p ∈ intervalPrimes w a z.cutoff z.closed,(p:ℝ)⁻¹*referenceProduct w (primeExponent w p) false* + (benchmark z.side.flip (childRatio w z.gap p)-1))= + intervalPrimeError w z a+normalization w*(∑ p ∈ intervalPrimes w a z.cutoff z.closed,(p:ℝ)⁻¹* + (benchmark z.side.flip (childRatio w z.gap p)-1)/primeExponent w p) := by + rw [intervalPrimeError,Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p _hp + ring + unfold intervalResidual lowerProductError parentProductError intervalQuadratureError + rw [hp] + nlinarith + +end NumberTheoryLean.ReferenceIntervalErrors + +end + +section + +namespace NumberTheoryLean.ReferenceIntervalProductBounds + +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry +open ReferenceMertens ReferenceSourcePrimeSets ReferenceBenchmarkDecay ReferenceDifferentiation +open ReferenceResidualErrors ReferenceProductErrorBounds ReferenceIntervalCutoff ReferenceIntervalErrors ReferenceParentMonotonicity +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem finite_interval_product_bounds {c C w : ℝ} (hc : 0 ≤ c) (hC : 0 ≤ C) (hw : 1 < w) + (hP : ∀ t : ℝ,2 ≤ t → ∀ closed : Bool, + |referenceProduct w t closed-normalization w/t| ≤ (C/t)*primeError c w t) + {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) {a : ℝ} (ha : 2 ≤ a) (hab : a ≤ z.cutoff) : + |lowerProductError w z a| ≤ 2*C*weight z.side z.ratio*primeError c w a ∧ + |parentProductError w z| ≤ 2*C*weight z.side z.ratio*primeError c w a ∧ + |intervalPrimeError w z a| ≤ (2*C*weight z.side z.ratio*primeError c w a)* + (∑ p ∈ intervalPrimes w a z.cutoff z.closed,(p:ℝ)⁻¹) := by + have hφ := weight_pos hs + have hE := primeError_pos c w a + have hr := ratio_eq_gap_div_cutoff hs hz (by linarith) + have hs' : Valid z.side (z.gap/z.cutoff) := by rwa [← hr] + have hD := interval_deviations_bound z.side ha hab hs' ⟨hab,le_rfl⟩ + rw [← hr] at hD + have hparent : |parentBenchmark z.side z.ratio-1| ≤ 4*weight z.side z.ratio := by + linarith [abs_nonneg (parentBenchmark z.side (z.gap/a)-1),abs_nonneg (benchmark z.side.flip (z.ratio-1)-1)] + have hlower : |parentBenchmark z.side (z.gap/a)-1| ≤ 4*weight z.side z.ratio := by + linarith [abs_nonneg (parentBenchmark z.side z.ratio-1),abs_nonneg (benchmark z.side.flip (z.ratio-1)-1)] + have hscale : ∀ t : ℝ,a ≤ t → ∀ closed : Bool, + |referenceProduct w t closed-normalization w/t| ≤ (C/2)*primeError c w a := by + intro t ht closed + apply (hP t (ha.trans ht) closed).trans + exact mul_le_mul (div_le_div_of_nonneg_left hC (by norm_num) (ha.trans ht)) + (primeError_antitone hc hw ht) (primeError_pos _ _ _).le (by positivity) + constructor + · unfold lowerProductError + rw [abs_mul] + have h := mul_le_mul (hscale a le_rfl true) hlower (abs_nonneg _) (by positivity) + convert! h using 1 + ring + constructor + · unfold parentProductError + rw [abs_mul] + have h := mul_le_mul (hscale z.cutoff hab z.closed) hparent (abs_nonneg _) (by positivity) + convert! h using 1 + ring + · unfold intervalPrimeError + apply (Finset.abs_sum_le_sum_abs _ _).trans + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + have hpH := (Finset.mem_filter.mp hp).1 + have hxa : a ≤ primeExponent w p := (Finset.mem_filter.mp hp).2.le + obtain ⟨_hprime,_hxp,hcap⟩ := (highPrimes_membership hw z.cutoff z.closed p).mp hpH + have hxb : primeExponent w p ≤ z.cutoff := by + cases hcl : z.closed with + | false => have h : primeExponent w p < z.cutoff := by simpa [capGuard,hcl] using hcap + exact h.le + | true => simpa [capGuard,hcl] using hcap + have hchild0 := interval_deviations_bound z.side ha hab hs' ⟨hxa,hxb⟩ + rw [← hr] at hchild0 + have hchild : |benchmark z.side.flip (childRatio w z.gap p)-1| ≤ 4*weight z.side z.ratio := by + unfold childRatio + linarith [abs_nonneg (parentBenchmark z.side z.ratio-1),abs_nonneg (parentBenchmark z.side (z.gap/a)-1)] + rw [abs_mul,abs_mul,abs_of_nonneg (inv_nonneg.mpr (Nat.cast_nonneg p))] + have hleft := mul_le_mul_of_nonneg_left (hscale (primeExponent w p) hxa false) + (inv_nonneg.mpr (Nat.cast_nonneg p)) + have h := mul_le_mul hleft hchild (abs_nonneg _) (by positivity) + convert! h using 1 + ring + +end NumberTheoryLean.ReferenceIntervalProductBounds + +end + +section + +namespace NumberTheoryLean.ReferenceIntervalQuadrature + +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry +open ReferenceProductErrorBounds ReferenceResidualErrors ReferenceIntervalCutoff ReferenceIntervalErrors +open ReferenceWeightedQuadrature + +theorem actual_interval_quadrature : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ z : Node,Valid z.side z.ratio → Consistent z → + ∀ a : ℝ,2 ≤ a → a ≤ z.cutoff → + |intervalQuadratureError w z a| ≤ (C*weight z.side z.ratio/2)*primeError c w a := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := source_weighted_quadrature + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw z hs hz a ha hab + have hw1 : 1 < w := hw₀.trans_le hw + have hr := ratio_eq_gap_div_cutoff hs hz (by linarith) + have hs' : Valid z.side (z.gap/z.cutoff) := by rwa [← hr] + have hh := h w hw a z.cutoff z.cutoff z.gap ha hab le_rfl z.side hs' + (primeInterval a z.cutoff z.closed) (primeInterval_orderConnected _ _ _) (primeInterval_subset _ _ _) + rw [← hr] at hh + have hφ := weight_pos hs + have hl : C*weight z.side z.ratio/a ≤ C*weight z.side z.ratio/2 := + div_le_div_of_nonneg_left (by positivity) (by norm_num) ha + unfold intervalQuadratureError + rw [intervalPrime_sum hw1 ha] + apply le_trans (by simpa only [childRatio] using hh) + exact mul_le_mul_of_nonneg_right hl (primeError_pos _ _ _).le + +end NumberTheoryLean.ReferenceIntervalQuadrature + +end + +section + +namespace NumberTheoryLean.ReferenceIntervalBound + +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeBinMembership +open ReferenceSourcePrimeSets ReferenceMertens ReferenceProductErrors ReferenceLocalResidual ReferenceHighIntervals +open ReferenceResidualErrors ReferenceProductErrorBounds ReferenceIntervalCutoff ReferenceIntervalErrors +open ReferenceIntervalProductBounds ReferenceIntervalQuadrature + +theorem interval_abs_triangle (w : ℝ) {z : Node} (hs : Valid z.side z.ratio) (hz : Consistent z) + {a : ℝ} (ha : 2 ≤ a) (hab : a ≤ z.cutoff) : + |intervalResidual w z a| ≤ |lowerProductError w z a|+|parentProductError w z|+ + |intervalPrimeError w z a|+|normalization w*intervalQuadratureError w z a| := by + rw [interval_error_identity w hs hz ha hab] + have h1 := abs_sub (lowerProductError w z a-parentProductError w z-intervalPrimeError w z a) + (normalization w*intervalQuadratureError w z a) + have h2 := abs_sub (lowerProductError w z a-parentProductError w z) (intervalPrimeError w z a) + have h3 := abs_sub (lowerProductError w z a) (parentProductError w z) + linarith + +theorem actual_interval_residual_bound : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ z : Node,Valid z.side z.ratio → Consistent z → + ∀ a : ℝ,2 ≤ a → a ≤ z.cutoff → + |intervalResidual w z a| ≤ C*weight z.side z.ratio*(1+Real.log z.cutoff)*primeError c w a := by + obtain ⟨cP,CP,wP,hcP,hCP,hwP,hP⟩ := reference_product_absolute + obtain ⟨cQ,CQ,wQ,hcQ,hCQ,_hwQ,hQ⟩ := actual_interval_quadrature + obtain ⟨CH,wH,hCH,_hwH,hH⟩ := highPrime_mass_bound + let c := min cP cQ + let C := 4*CP+2*CP*CH+CQ + have hc : 0 < c := lt_min hcP hcQ + refine ⟨c,C,max wP (max wQ wH),hc,by dsimp [C]; positivity,hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw z hs hz a ha hab + have hwp : wP ≤ w := (le_max_left _ _).trans hw + have hwq : wQ ≤ w := ((le_max_left _ _).trans (le_max_right _ _)).trans hw + have hwh : wH ≤ w := ((le_max_right _ _).trans (le_max_right _ _)).trans hw + have hw1 : 1 < w := hwP.trans_le hwp + obtain ⟨_hNlo,hNhi,hProd⟩ := hP w hwp + have hP' : ∀ t : ℝ,2 ≤ t → ∀ closed : Bool, + |referenceProduct w t closed-normalization w/t| ≤ (CP/t)*primeError c w t := by + intro t ht closed + exact (hProd t ht closed).trans (mul_le_mul_of_nonneg_left + (exp_error_mono_rate (t:=t*Real.log w) (min_le_left cP cQ)) (by positivity)) + obtain ⟨hLow,hPar,hPrime⟩ := finite_interval_product_bounds hc.le hCP.le hw1 hP' hs hz ha hab + have hφ := weight_pos hs + have hE := primeError_pos c w a + have hQ' : |intervalQuadratureError w z a| ≤ (CQ*weight z.side z.ratio/2)*primeError c w a := by + exact (hQ w hwq z hs hz a ha hab).trans (mul_le_mul_of_nonneg_left + (exp_error_mono_rate (t:=a*Real.log w) (min_le_right cP cQ)) (by positivity)) + have hN : |normalization w| ≤ 2 := by rw [abs_of_pos (normalization_pos hw1)]; exact hNhi + have hNQ : |normalization w*intervalQuadratureError w z a| ≤ CQ*weight z.side z.ratio*primeError c w a := by + rw [abs_mul] + have hh := mul_le_mul hN hQ' (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 2) + convert! hh using 1 + ring + have hMass : (∑ p ∈ intervalPrimes w a z.cutoff z.closed,(p:ℝ)⁻¹) ≤ CH*(1+Real.log z.cutoff) := by + apply le_trans _ (hH w hwh z.cutoff (ha.trans hab) z.closed) + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun p _ _ => by positivity) + have hPrime' : |intervalPrimeError w z a| ≤ + (2*CP*weight z.side z.ratio*primeError c w a)*(CH*(1+Real.log z.cutoff)) := + hPrime.trans (mul_le_mul_of_nonneg_left hMass (by positivity)) + have htri := interval_abs_triangle w hs hz ha hab + have hL : 1 ≤ 1+Real.log z.cutoff := by + have hh := Real.log_nonneg (show 1 ≤ z.cutoff by linarith) + linarith + have hpay : (4*CP+CQ)*weight z.side z.ratio*primeError c w a ≤ + (4*CP+CQ)*weight z.side z.ratio*primeError c w a*(1+Real.log z.cutoff) := + le_mul_of_one_le_right (by positivity) hL + calc + _ ≤ (4*CP+CQ)*weight z.side z.ratio*primeError c w a+ + (2*CP*weight z.side z.ratio*primeError c w a)*(CH*(1+Real.log z.cutoff)) := by + nlinarith only [htri,hLow,hPar,hPrime',hNQ] + _ ≤ (4*CP+CQ)*weight z.side z.ratio*primeError c w a*(1+Real.log z.cutoff)+ + (2*CP*weight z.side z.ratio*primeError c w a)*(CH*(1+Real.log z.cutoff)) := add_le_add_left hpay _ + _ = _ := by dsimp [C]; ring + +theorem source_residual_split_bound : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ z : Node,Valid z.side z.ratio → Consistent z → + ∀ a : ℝ,2 ≤ a → a < z.cutoff → + |sourceResidual w z| ≤ |sourceResidual w (rebase z a)|+ + C*weight z.side z.ratio*(1+Real.log z.cutoff)*primeError c w a := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := actual_interval_residual_bound + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw z hs hz a ha hab + rw [residual_split (hw₀.trans_le hw) z hab] + exact (abs_add_le _ _).trans (add_le_add_right (h w hw z hs hz a ha hab.le) _) + +end NumberTheoryLean.ReferenceIntervalBound + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/RegularityDefectPartition.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RegularityDefectPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2dca40875054b2f6de6c456b4589cda91f4cb95 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RegularityDefectPartition.lean @@ -0,0 +1,106 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualPrefixClearance +import OAI.NumberTheory.Jacobsthal.Probability.RepeatedWordEvents + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualRegularBoxes +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualPrefixClearance ActualWordSelection +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open SafeSubsetBoxGeometry ErdosSubsetWord ErdosCofactorChoices ActualSourceTags +open ErdosPrimeInputs.PrimePrefixMass +attribute [local instance] Classical.propDecidable + +noncomputable def regularWords {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Clen B K : ℝ) (z : Node) : Finset (List ℕ) := + (decreasingPrefixes (sourcePrimeSet w top)).filter (fun ps => + (ps.length:ℝ) ≤ Clen*Real.log B ∧ actualClearance w z (2*Clen*xi) ps ∧ + (terminal w z ps).gap ≤ K ∧ ∀ b,searchBin w (lower w top xi b) → + (ps.map (label (zero_lt_one.trans hw) htop hxi)).count b ≤ 1) + +noncomputable def regularBoxes {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Clen B K : ℝ) (z : Node) : Finset (Fin (binCount w top xi) → ℕ) := + (regularWords hw htop hxi Clen B K z).image + (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi)) + +theorem regular_word_anchor {w top xi Clen B K : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hC : 0 ≤ Clen) (hcomp : Real.log B ≤ 2*Real.log w) + (hsmall : 2*(xi/Real.log w) ≤ 6*(2*Clen*xi)) (z : Node) (ps : List ℕ) + (hp : ps ∈ regularWords hw htop hxi Clen B K z) : + SafeAnchor hw htop hxi Clen B K z (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps) := by + obtain ⟨hd,hlen,hclear,hgap,_hsingle⟩ := Finset.mem_filter.mp hp + have hm := mem_decreasingPrefixes.mp hd + refine ⟨wordSelection (label (zero_lt_one.trans hw) htop hxi) ps, + wordSelection_mem hw htop hxi ps hm.2,?_⟩ + rw [wordSelection_recovers _ ps hm.1] + exact ⟨hlen,clearance_supplies_safety hw htop hxi hC hcomp hsmall z ps hm.2 hlen hclear,hgap⟩ + +theorem regular_boxes_anchors {w top xi Clen B K : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hC : 0 ≤ Clen) (hcomp : Real.log B ≤ 2*Real.log w) + (hsmall : 2*(xi/Real.log w) ≤ 6*(2*Clen*xi)) (z : Node) : + ∀ mult ∈ regularBoxes hw htop hxi Clen B K z,SafeAnchor hw htop hxi Clen B K z mult := by + intro mult hm + obtain ⟨ps,hps,rfl⟩ := Finset.mem_image.mp hm + exact regular_word_anchor hw htop hxi hC hcomp hsmall z ps hps + +theorem regular_boxes_search_singletons {w top xi Clen B K : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) : + ∀ mult ∈ regularBoxes hw htop hxi Clen B K z, + ∀ b ∈ occupiedSearch w top xi mult,mult b=1 := by + intro mult hm b hb + obtain ⟨ps,hps,rfl⟩ := Finset.mem_image.mp hm + obtain ⟨hd,_hlen,_hclear,_hgap,hsingle⟩ := Finset.mem_filter.mp hps + have hn : ps.Nodup := (mem_decreasingPrefixes.mp hd).1.imp (fun h => ne_of_gt h) + have hpos := (Finset.mem_filter.mp hb).2.2 + have hle := hsingle b (Finset.mem_filter.mp hb).2.1 + rw [wordMultiplicity_count _ ps hn] at hpos ⊢ + omega +end NumberTheoryLean.ActualRegularBoxes + + + +namespace NumberTheoryLean.RegularityDefectPartition +open FinitePathGeometry PrimeHistories ActualRegularBoxes ActualPrefixClearance RepeatedWordEvents +open ReferenceAdmission LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail +attribute [local instance] Classical.propDecidable + +noncomputable def lengthFailure (C B : ℝ) (ps : List ℕ) : Prop := C*Real.log B < (ps.length:ℝ) +noncomputable def clearanceFailure (w Delta : ℝ) (z : Node) (ps : List ℕ) : Prop := ¬actualClearance w z Delta ps + +theorem regularity_defect_sum {w top xi C B R : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (z : Node) (F : Finset (List ℕ)) + (hF : F ⊆ referencePrefixes w (sourcePrimeSet w top) z.side z.gap) + (hg : ∀ ps ∈ F,(terminal w z ps).gap ≤ R) : + (∑ ps ∈ F \ regularWords hw htop hxi C B R z,prefixWeight ps) ≤ + (∑ ps ∈ F.filter (lengthFailure C B),prefixWeight ps) + + (∑ ps ∈ F.filter (clearanceFailure w (2*C*xi) z),prefixWeight ps) + + (∑ ps ∈ F.filter (searchRepeatedWord hw htop hxi),prefixWeight ps) := by + simp only [Finset.sdiff_eq_filter,Finset.sum_filter] + rw [← Finset.sum_add_distrib,← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro ps hp + have hnonneg := prefixWeight_nonneg ps + by_cases hreg : ps ∈ regularWords hw htop hxi C B R z + · simp only [hreg,not_true_eq_false,ite_false] + positivity + · have hf : lengthFailure C B ps ∨ clearanceFailure w (2*C*xi) z ps ∨ searchRepeatedWord hw htop hxi ps := by + by_contra! hn + apply hreg + refine Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp (hF hp)).1,?_,?_,hg ps hp,?_⟩ + · exact le_of_not_gt hn.1 + · exact not_not.mp hn.2.1 + · intro b hs + by_contra hb + exact hn.2.2 ⟨b,hs,by omega⟩ + simp only [hreg,not_false_eq_true,ite_true] + split_ifs <;> simp_all +end NumberTheoryLean.RegularityDefectPartition + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/RetainedIntervalUpper.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RetainedIntervalUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..160cfba64e53b02cc108f1ad07d76a16257d13b7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RetainedIntervalUpper.lean @@ -0,0 +1,121 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeCompactWeights + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RetainedIntervalUpper + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeTiltGeometry PrimeTiltBounds PrimeTiltMonotone +open PrimeCumulativeBound PrimeRatioBins ContinuousRatioBins +open PrimeHistories PrimeKilledChain ContinuousKilledBins FinitePathMeasures +open LowStateHorizon ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def retainedInterval (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) (a b : ℝ) : Finset ℕ := by + classical + exact (children w ell S i s r cap closed).filter (fun p => a ≤ childRatio w r p ∧ childRatio w r p ≤ b) + +noncomputable def retainedIntervalTilt (w ell S : ℝ) (i : Side) (s r cap : ℝ) (closed : Bool) (a b : ℝ) : ℝ := + ∑ p ∈ retainedInterval w ell S i s r cap closed a b, primeTilt w r i s p + +theorem retained_subset_closed {w ell S s r cap a b : ℝ} {i : Side} {closed : Bool} + (hw : 1 < w) (ha : 0 < a) (hab : a ≤ b) : + retainedInterval w ell S i s r cap closed a b ⊆ closedBin w r a b := by + classical + intro p hp + rcases Finset.mem_filter.mp hp with ⟨hchild,hat,htb⟩ + have hprime := (Nat.mem_primesLE.mp (Finset.mem_filter.mp hchild).1).2 + have hint := (closed_interval_iff (r:=r) ha hab (PrimeRatioBins.primeExponent_pos hw hprime)).mp ⟨hat,htb⟩ + apply Finset.mem_filter.mpr + refine ⟨Nat.mem_primesLE.mpr ⟨?_,hprime⟩,hat,htb⟩ + have hp0 : (0:ℝ) < p := by exact_mod_cast hprime.pos + have hreal : (p:ℝ) ≤ w^(r/(a+1)) := (exponent_le_iff hw hp0).mp hint.2 + exact (Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) _).le).mpr hreal + +theorem short_interval_lower_exponent {w ell S s r cap a b : ℝ} {i : Side} {closed : Bool} + (hell : 1 ≤ ell) (hs : Valid i s) (ha : 0 < a) (hab : a ≤ b) (hwidth : b-a ≤ 1) + (hne : (retainedInterval w ell S i s r cap closed a b).Nonempty) : + (1/2:ℝ) ≤ r/(b+1) := by + classical + obtain ⟨p,hp⟩ := hne + rcases Finset.mem_filter.mp hp with ⟨hchild,hat,htb⟩ + have ht0 := valid_pos (child_valid hs hchild) + have hx : 1 < primeExponent w p := hell.trans_lt (Finset.mem_filter.mp hchild).2.1 + have hmul : (childRatio w r p+1)*primeExponent w p = r := by + unfold childRatio + field_simp + ring + have hrgt : childRatio w r p+1 < r := by nlinarith + apply (le_div_iff₀ (by linarith : 0 < b+1)).mpr + nlinarith + +theorem closed_prime_error : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ r a b : ℝ, 0 < r → 0 < a → a ≤ b → 1/2 ≤ r/(b+1) → + |closedMass w r a b-(Real.log (b+1)-Real.log (a+1))| ≤ + C*Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,hbound⟩ := harmonic_prime_measure + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw r a b hr ha hab hlow + have hw1 := hw₀.trans_le hw + have hend : r/(b+1) ≤ r/(a+1) := div_le_div_of_nonneg_left hr.le (by linarith) (by linarith) + have h := hbound w hw (r/(b+1)) (r/(a+1)) hlow hend true true + rw [← closedMass_eq_harmonic hw1 ha hab,bin_log_width hr ha hab] at h + apply h.trans + apply mul_le_mul_of_nonneg_left _ hC.le + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonpos_left (Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_right hlow (Real.log_pos hw1).le)) (by linarith) + +theorem retained_short_interval_upper : ∃ c C w₀ : ℝ, 0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ, w₀ ≤ w → ∀ ell S : ℝ, ∀ i : Side, ∀ s r cap a b : ℝ, ∀ closed : Bool, + 1 ≤ ell → 0 < r → Valid i s → s ≤ S → 0 < a → a ≤ b → b-a ≤ 1 → + retainedIntervalTilt w ell S i s r cap closed a b ≤ + C*(1+S)^2*((b-a)+Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w))) := by + classical + obtain ⟨c,C,w₀,hc,hC,hw₀,herr⟩ := closed_prime_error + obtain ⟨D,hD,henv⟩ := multiplier_envelope + refine ⟨c,D*(1+C),w₀,hc,by positivity,hw₀,?_⟩ + intro w hw ell S i s r cap a b closed hell hr hs hsS ha hab hwidth + let A := retainedInterval w ell S i s r cap closed a b + let e := Real.exp (-c*Real.sqrt ((1/2:ℝ)*Real.log w)) + by_cases hne : A.Nonempty + · have hlow := short_interval_lower_exponent hell hs ha hab hwidth hne + have herror := herr w hw r a b hr ha hab hlow + have hlog : Real.log (b+1)-Real.log (a+1) ≤ b-a := + ((bin_log_width_bounds ha hab).2).trans (div_le_self (sub_nonneg.mpr hab) (by linarith)) + have hraw : closedMass w r a b ≤ (b-a)+C*e := by linarith [(abs_le.mp herror).2] + have hsub : (∑ p ∈ A,(p:ℝ)⁻¹) ≤ closedMass w r a b := + Finset.sum_le_sum_of_subset_of_nonneg (retained_subset_closed (hw₀.trans_le hw) ha hab) + (fun p _ _ => inv_nonneg.mpr (Nat.cast_nonneg p)) + have htilt : retainedIntervalTilt w ell S i s r cap closed a b ≤ D*(1+S)^2*(∑ p ∈ A,(p:ℝ)⁻¹) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro p hp + have hchild := (Finset.mem_filter.mp hp).1 + have hm := henv S i s (childRatio w r p) hs hsS (Finset.mem_filter.mp hchild).2.2.2.1 + rw [primeTilt_eq_multiplier,mul_comm (D*(1+S)^2)] + exact mul_le_mul_of_nonneg_left hm (inv_nonneg.mpr (Nat.cast_nonneg p)) + calc + _ ≤ D*(1+S)^2*closedMass w r a b := htilt.trans (mul_le_mul_of_nonneg_left hsub (by positivity)) + _ ≤ D*(1+S)^2*((b-a)+C*e) := mul_le_mul_of_nonneg_left hraw (by positivity) + _ ≤ (D*(1+C))*(1+S)^2*((b-a)+e) := by + have hh : 0 ≤ b-a := sub_nonneg.mpr hab + have he : 0 ≤ e := (Real.exp_pos _).le + have hm := mul_nonneg (show 0 ≤ D*(1+S)^2 by positivity) + (show 0 ≤ C*(b-a)+e by positivity) + nlinarith + · have he : A = ∅ := Finset.not_nonempty_iff_eq_empty.mp hne + change ∑ p ∈ A, _ ≤ _ + rw [he,Finset.sum_empty] + have hh : 0 ≤ b-a := sub_nonneg.mpr hab + positivity + +end NumberTheoryLean.RetainedIntervalUpper + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/RieszRectangle.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RieszRectangle.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5865b9b25f329d9efd0764ae5a28dea265ef283 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/RieszRectangle.lean @@ -0,0 +1,76 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RieszIntegrand + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz +open _root_.Set _root_.Complex + +lemma modulusHeight_le_of_abs_le (q : ℕ) (T : ℝ) (hT : 0 ≤ T) {t : ℝ} (ht : |t| ≤ T) : + modulusHeight q t ≤ modulusHeight q T := by + have h := Real.log_le_log (by positivity : 0 < |t|+6) (by linarith : |t|+6 ≤ T+6) + unfold modulusHeight + rw [abs_of_nonneg hT] + linarith + +noncomputable def rieszContourLeft (a : ℝ) (q : ℕ) (T : ℝ) : ℝ := + 1-a/(modulusHeight q T)^2 +noncomputable def rieszContourRectangle (a : ℝ) (q : ℕ) (sigma T : ℝ) : Set ℂ := + Icc (rieszContourLeft a q T) sigma ×ℂ Icc (-T) T + +theorem exists_uniform_riesz_rectangle : + ∃ a : ℝ, 0 < a ∧ a ≤ 1/100 ∧ ∃ C : ℝ, 0 < C ∧ + ∀ (q : ℕ) [NeZero q] (chi : DirichletCharacter ℂ q), chi ≠ 1 → + ∀ X sigma T : ℝ, 0 < X → 1 < sigma → sigma ≤ 2 → 0 < T → + 1/2 ≤ rieszContourLeft a q T ∧ + (∀ s ∈ rieszContourRectangle a q sigma T, + DirichletCharacter.LFunction chi s ≠ 0 ∧ + ‖logDeriv (DirichletCharacter.LFunction chi) s‖ ≤ C*(modulusHeight q T)^3) ∧ + _root_.Erdos970.HolomorphicOn (characterRieszIntegrand chi X) (rieszContourRectangle a q sigma T) := by + obtain ⟨a,ha,ha100,C,hC,hstrip⟩ := exists_uniform_nonprincipal_strip_bound + refine ⟨a,ha,ha100,C,hC,?_⟩ + intro q _ chi hchi X sigma T hX _hs hs2 hT + have hH := modulusHeight_ge_one q T + have hHp : 0 < modulusHeight q T := by linarith + have hHsq : 1 ≤ (modulusHeight q T)^2 := by nlinarith + have hfrac : a/(modulusHeight q T)^2 ≤ a := by + apply (div_le_iff₀ (by positivity : 0 < (modulusHeight q T)^2)).mpr + simpa only [mul_one] using mul_le_mul_of_nonneg_left hHsq ha.le + have hleft : 1/2 ≤ rieszContourLeft a q T := by unfold rieszContourLeft; linarith + have hb : ∀ s ∈ rieszContourRectangle a q sigma T, + DirichletCharacter.LFunction chi s ≠ 0 ∧ + ‖logDeriv (DirichletCharacter.LFunction chi) s‖ ≤ C*(modulusHeight q T)^3 := by + intro s hmem + have hr := (Complex.mem_reProdIm.mp hmem).1 + have hi := (Complex.mem_reProdIm.mp hmem).2 + have hht := modulusHeight_le_of_abs_le q T hT.le (abs_le.mpr hi) + have hHs := modulusHeight_ge_one q s.im + have hHsp : 0 < modulusHeight q s.im := by linarith + have hpow : (modulusHeight q s.im)^2 ≤ (modulusHeight q T)^2 := by nlinarith + have hdiv := div_le_div_of_nonneg_left ha.le (show 0 < (modulusHeight q s.im)^2 by positivity) hpow + have hs' : 1-a/(modulusHeight q s.im)^2 ≤ s.re := by + change 1-a/(modulusHeight q T)^2 ≤ s.re ∧ s.re ≤ sigma at hr + linarith + have h := hstrip q chi hchi s.re s.im hs' (hr.2.trans hs2) + simp only [Complex.re_add_im] at h + refine ⟨h.1,?_⟩ + change ‖deriv (DirichletCharacter.LFunction chi) s / DirichletCharacter.LFunction chi s‖ ≤ _ + apply h.2.trans + gcongr + refine ⟨hleft,hb,?_⟩ + intro s hmem + have hr := (Complex.mem_reProdIm.mp hmem).1.1 + have hsp : 0 < s.re := by linarith + exact (differentiableAt_characterRieszIntegrand chi hchi hX hsp (hb s hmem).1).differentiableWithinAt + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SignedIntervalGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SignedIntervalGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea73c9f402f18559b019654482fd75c56c28f073 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SignedIntervalGeometry.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeIntervalFlags + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace Erdos970Dependency.SiegelWalfisz + +noncomputable def retainedLength (a b t : ℝ) : ℝ := if t ≤ b-a then b-a else 0 + +lemma retainedLength_nonneg {a b t : ℝ} (ht : 0 ≤ t) : 0 ≤ retainedLength a b t := by + unfold retainedLength + split_ifs with h + · linarith + · exact le_refl 0 + +lemma retainedLength_lower (a b t : ℝ) (ht : 0 ≤ t) : + max (b-a) 0-t ≤ retainedLength a b t := by + unfold retainedLength + split_ifs with h + · rw [max_eq_left (by linarith : 0 ≤ b-a)] + linarith + · have hm : max (b-a) 0 ≤ t := by apply max_le <;> linarith + linarith + +lemma signed_trim_length {x y t : ℝ} (hxy : x ≤ y) (ht : 0 ≤ t) : + y-x ≤ max (y-max x t) 0+max (-x-max (-y) t) 0+2*t := by + simp only [max_def] + split_ifs <;> linarith + +lemma signed_retained_length {x y t : ℝ} (hxy : x ≤ y) (ht : 0 ≤ t) : + y-x-4*t ≤ retainedLength (max x t) y t + retainedLength (max (-y) t) (-x) t := by + have hp := retainedLength_lower (max x t) y t ht + have hn := retainedLength_lower (max (-y) t) (-x) t ht + have htrim := signed_trim_length hxy ht + linarith + +end Erdos970Dependency.SiegelWalfisz + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SlopeCellPartition.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SlopeCellPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..06886aa9e1251ffef0a6764dcab0b16dde6ff110 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SlopeCellPartition.lean @@ -0,0 +1,57 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.AugmentedCRTCell + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosInverseCRT +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def sampledSlopes {ι : Type*} [Fintype ι] (p M0 : ℕ) (u : ι → ℕ) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) : Finset ℤ := + (Finset.Ico (0 : ℤ) (p : ℤ)).filter + (fun s => ∀ i,(c i : ZMod (u i))*(s : ZMod (u i))+b i ∈ E (s : ZMod M0) i) + +theorem sampledSlopes_partition {ι : Type*} [Fintype ι] (p M0 : ℕ) [NeZero M0] (u : ι → ℕ) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) : + sampledSlopes p M0 u c b E = Finset.univ.biUnion (fun v : ZMod M0 => slopeCell p M0 u v c b (E v)) := by + ext s + constructor + · intro hs + obtain ⟨hsp,hE⟩ := Finset.mem_filter.mp hs + exact Finset.mem_biUnion.mpr ⟨(s : ZMod M0),Finset.mem_univ _,Finset.mem_filter.mpr ⟨hsp,rfl,hE⟩⟩ + · intro hs + obtain ⟨v,hv,hcell⟩ := Finset.mem_biUnion.mp hs + obtain ⟨hsp,hsv,hE⟩ := Finset.mem_filter.mp hcell + apply Finset.mem_filter.mpr + refine ⟨hsp,?_⟩ + rwa [hsv] + +theorem slopeCells_disjoint {ι : Type*} [Fintype ι] (p M0 : ℕ) (u : ι → ℕ) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) {v w : ZMod M0} (hne : v ≠ w) : + Disjoint (slopeCell p M0 u v c b (E v)) (slopeCell p M0 u w c b (E w)) := by + apply Finset.disjoint_left.mpr + intro s hs ht + exact hne ((Finset.mem_filter.mp hs).2.1.symm.trans (Finset.mem_filter.mp ht).2.1) + +theorem sampledSlopes_card {ι : Type*} [Fintype ι] (p M0 : ℕ) [NeZero M0] (u : ι → ℕ) + (c : ∀ i,(ZMod (u i))ˣ) (b : ∀ i,ZMod (u i)) + (E : ZMod M0 → ∀ i,Finset (ZMod (u i))) : + (sampledSlopes p M0 u c b E).card = ∑ v : ZMod M0,(slopeCell p M0 u v c b (E v)).card := by + rw [sampledSlopes_partition,Finset.card_biUnion] + intro v hv w hw hne + exact slopeCells_disjoint p M0 u c b E hne + +end ErdosInverseCRT + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SortedLabelRepetition.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SortedLabelRepetition.lean new file mode 100644 index 0000000000000000000000000000000000000000..df18ef6632e6e9fa3dc40fb8696d234cde766d1d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SortedLabelRepetition.lean @@ -0,0 +1,61 @@ +import OAI.NumberTheory.Jacobsthal.Paths.ActualWordSelection + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SortedLabelRepetition +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosSubsetWord + + +theorem repeated_label_has_adjacent {α : Type*} {n : ℕ} (f : α → Fin n) (b : Fin n) + (ps : List α) (hord : (ps.map f).Pairwise (· ≥ ·)) (hcount : 2 ≤ (ps.map f).count b) : + ∃ pre p q tail,ps=pre++p::q::tail ∧ f p=b ∧ f q=b := by + induction ps with + | nil => simp at hcount + | cons p ps ih => + simp only [List.map_cons] at hord hcount + have htail := (List.pairwise_cons.mp hord).2 + by_cases hp : f p=b + · have hc : 0 < (ps.map f).count b := by simpa [hp] using hcount + have hb := List.count_pos_iff.mp hc + cases ps with + | nil => simp at hb + | cons q tail => + have hqle : f q ≤ b := by + have hh := (List.pairwise_cons.mp hord).1 (f q) (by simp) + simpa only [hp] using hh + obtain ⟨u,hu,hub⟩ := List.mem_map.mp hb + have hqge : b ≤ f q := by + rcases List.mem_cons.mp hu with rfl | hu + · exact hub.symm.le + · have hh := (List.pairwise_cons.mp htail).1 (f u) (List.mem_map.mpr ⟨u,hu,rfl⟩) + rwa [hub] at hh + exact ⟨[],p,q,tail,rfl,hp,le_antisymm hqle hqge⟩ + · have hc : 2 ≤ (ps.map f).count b := by simpa [hp,Ne.symm hp] using hcount + obtain ⟨pre,q,r,tail,he,hq,hr⟩ := ih htail hc + exact ⟨p::pre,q,r,tail,by simp only [List.cons_append,he],hq,hr⟩ + +theorem source_word_labels_ordered {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (ps : List ℕ) (hd : ps.Pairwise (· > ·)) (hsrc : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) : + (ps.map (label (zero_lt_one.trans hw) htop hxi)).Pairwise (· ≥ ·) := by + rw [List.pairwise_map] + apply hd.imp_of_mem + intro p q hp hq hpq + exact global_label_mono hw htop hxi (hsrc p hp) (hsrc q hq) hpq.le + +theorem source_repeated_label_adjacent {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (ps : List ℕ) (hd : ps.Pairwise (· > ·)) (hsrc : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) + (b : Fin (binCount w top xi)) (hcount : 2 ≤ (ps.map (label (zero_lt_one.trans hw) htop hxi)).count b) : + ∃ pre p q tail,ps=pre++p::q::tail ∧ + label (zero_lt_one.trans hw) htop hxi p=b ∧ label (zero_lt_one.trans hw) htop hxi q=b := + repeated_label_has_adjacent _ b ps (source_word_labels_ordered hw htop hxi ps hd hsrc) hcount +end NumberTheoryLean.SortedLabelRepetition + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceAllInverseBins.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceAllInverseBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..81614eb18a0ed38a8478c273b89ef0b4f6fd9838 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceAllInverseBins.lean @@ -0,0 +1,171 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeInverseBins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceInverseBinRate + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeSideSupport +open PrimeGridGeometry PrimeGridKernel PrimeInverseBins DerivativeWeights MarginalProfiles +open SourceMarginalRate ExponentialMesh UniformBudgetRate HorizonMeshSmallness LowStateHorizon + +theorem source_inverse_bins : ∃ κ₀ C : ℝ,0 < κ₀ ∧ 0 < C ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ d : ℝ,0 < d → ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + let S := (Real.log B)^2 + let N := sourceHorizon S B + let m := ⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊ + (∀ j,Valid .odd (point m j) → inverseBin w ell S start m 1 j ≤ ENNReal.ofReal (C*width m)) ∧ + (∀ n,2 ≤ n → n ≤ N → ∀ j,lowerIndex m (sideAfter .even n) ≤ j → + inverseBin w ell S start m n j ≤ ENNReal.ofReal (C*width m)) := by + obtain ⟨κ₀,C,hκ₀,hC,hsource⟩ := source_discrete_marginals + obtain ⟨L,hL,hlocal⟩ := actual_inverse_bin_local + refine ⟨κ₀,57*C,hκ₀,by positivity,?_⟩ + intro κ hκ hκle d hd + obtain ⟨wP,hwP,hsource⟩ := hsource κ hκ hκle d hd + have hevent := (horizon_mesh_smallness (A:=0) (D:=L) (by norm_num) hL.le hκ).and + (Real.tendsto_log_atTop.eventually (eventually_ge_atTop (d^2))) + obtain ⟨wAux,hwAux⟩ := eventually_atTop.mp hevent + refine ⟨max wP wAux,hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hell hB hlogB hcomp hr hi h199 h23 + dsimp only + let S := (Real.log B)^2 + let N := sourceHorizon S B + let m := ⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊ + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hwe := hwAux w ((le_max_right _ _).trans hw) + have hscale := source_scale_bound hwe.2 hlogB hcomp + have hS0 : 0 ≤ S := sq_nonneg _ + have hS3 : 3 ≤ S := by dsimp [S]; nlinarith + have hsS : start.ratio ≤ S := by linarith + have hm : 1 ≤ m := Nat.ceil_pos.mpr (Real.exp_pos _) + have hmesh : width m = mesh κ w := rfl + have hsmall := hwe.1 S hS0 hscale.1 0 (by simp) + have hh : width m ≤ 1 := by rw [hmesh]; linarith [hsmall.1] + have hE : Real.exp (L*(1+S)^3*width m) ≤ 3 := by + rw [hmesh] + exact (Real.exp_le_exp.mpr hsmall.2.2.1).trans Real.exp_one_lt_three.le + have hprofiles := hsource w ((le_max_left _ _).trans hw) ell B start hell hB hlogB hcomp hr hi h199 h23 + have hwidth := width_nonneg m + have hE0 := (Real.exp_pos (L*(1+S)^3*width m)).le + constructor + · intro j hj + have hj' : Valid (sideAfter .even 1) (point m j) := hj + have hmass : mass w ell S start m 1 j ≤ + ENNReal.ofReal (C*width m*weight (sideAfter .even 1) (point m j)*W (point m j)) := by + simpa only [sideAfter,Side.flip,mul_assoc,mul_comm,mul_left_comm] using hprofiles.2.1 j hj + have hb := cancel_inverse_bin hE0 hj' (hlocal w ell S hS3 start hs hi hsS m 1 j hj') hmass + have ht : (1:ℝ)/2 ≤ point m j := by change 95/100 ≤ point m j at hj; linarith + have hW := W_le_six ht + have hW0 := (WeightFutureIntegrals.W_pos (by linarith : 0 < point m j)).le + refine hb.trans (ENNReal.ofReal_le_ofReal ?_) + calc + _ ≤ 3*C*width m*6 := mul_le_mul + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hE hC.le) hwidth) hW hW0 (by positivity) + _ ≤ _ := by nlinarith [mul_nonneg hC.le hwidth] + · intro n hn hnN j hj + have hjV := index_valid hm (sideAfter .even n) hj + have hb := cancel_inverse_bin hE0 hjV (hlocal w ell S hS3 start hs hi hsS m n j hjV) + (hprofiles.2.2 n hn hnN j hj) + have hprof := profile_le_nineteen hh (index_regular hm (sideAfter .even n) hj) + have hp0 := profile_nonneg m (index_regular hm (sideAfter .even n) hj) + refine hb.trans (ENNReal.ofReal_le_ofReal ?_) + calc + _ ≤ 3*C*width m*19 := mul_le_mul + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hE hC.le) hwidth) hprof hp0 (by positivity) + _ = _ := by ring + +end NumberTheoryLean.SourceInverseBinRate + +end + +section + +namespace NumberTheoryLean.SourceAllInverseBins + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal Topology +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeSideSupport +open PrimeGridGeometry PrimeGridKernel PrimeInverseBins SourceInverseBinRate +open SourceMarginalRate ExponentialMesh LowStateHorizon + +variable {w ell S : ℝ} {start : Node} + +theorem inverse_bin_zero_first {m j : ℕ} (hm : 1 ≤ m) (hsmall : width m ≤ 1/100) + (hs : Valid start.side start.ratio) (hi : start.side = .even) + (hj : ¬Valid .odd (point m j)) : inverseBin w ell S start m 1 j = 0 := by + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [ae_restrict_of_ae (pathLaw_side (w:=w) (ell:=ell) (S:=S) hi 1), + ae_restrict_of_ae (pathLaw_weak hs 1 le_rfl),ae_restrict_mem (bin_measurable m j)] with z hz hweak hbin + cases z with + | none => exact False.elim hbin + | some h => + have hv := weak_bin_domain hm hsmall hweak ((mem_bin h m j).mp hbin) + have he : h.node.side = .odd := hz + rw [he] at hv + exact False.elim (hj hv) + +theorem inverse_bin_zero_lower {m n j : ℕ} (hm : 1 ≤ m) (hn : 2 ≤ n) + (hi : start.side = .even) (hj : j < lowerIndex m (sideAfter .even n)) : + inverseBin w ell S start m n j = 0 := by + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [ae_restrict_of_ae (pathLaw_side (w:=w) (ell:=ell) (S:=S) hi n), + ae_restrict_of_ae (pathLaw_regular (w:=w) (ell:=ell) (S:=S) (start:=start) n hn), + ae_restrict_mem (bin_measurable m j)] with z hz hreg hbin + cases z with + | none => exact False.elim hbin + | some h => + have hv := (regular_bin_domain hm hreg ((mem_bin h m j).mp hbin)).1 + rw [hz] at hv + omega + +theorem source_all_inverse_bins : ∃ κ₀ C : ℝ,0 < κ₀ ∧ 0 < C ∧ + ∀ κ : ℝ,0 < κ → κ ≤ κ₀ → ∀ d : ℝ,0 < d → ∃ w₀ : ℝ,1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ ell B : ℝ,∀ start : Node, + 1 ≤ ell → 0 < B → 2 ≤ Real.log B → Real.log B ≤ d*Real.log w → + 0 < start.gap → start.side = .even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → + let S := (Real.log B)^2 + let N := sourceHorizon S B + let m := ⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊ + ∀ n,1 ≤ n → n ≤ N → ∀ j,inverseBin w ell S start m n j ≤ ENNReal.ofReal (C*width m) := by + obtain ⟨κ₀,C,hκ₀,hC,hsource⟩ := source_inverse_bins + refine ⟨κ₀,C,hκ₀,hC,?_⟩ + intro κ hκ hκle d hd + obtain ⟨wP,hwP,hsource⟩ := hsource κ hκ hκle d hd + obtain ⟨wAux,hwAux⟩ := eventually_atTop.mp (mesh_eventually_small hκ (by norm_num : (0:ℝ) < 1/100)) + refine ⟨max wP wAux,hwP.trans_le (le_max_left _ _),?_⟩ + intro w hw ell B start hell hB hlogB hcomp hr hi h199 h23 + dsimp only + let m := ⌈Real.exp (κ*Real.sqrt (Real.log w))⌉₊ + have hm : 1 ≤ m := Nat.ceil_pos.mpr (Real.exp_pos _) + have hh : width m ≤ 1/100 := hwAux w ((le_max_right _ _).trans hw) + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have hb := hsource w ((le_max_left _ _).trans hw) ell B start hell hB hlogB hcomp hr hi h199 h23 + intro n hn hnN j + by_cases he : n=1 + · subst n + by_cases hj : Valid .odd (point m j) + · exact hb.1 j hj + · rw [inverse_bin_zero_first hm hh hs hi hj] + exact zero_le + · have hn2 : 2 ≤ n := by omega + by_cases hj : lowerIndex m (sideAfter .even n) ≤ j + · exact hb.2 n hn2 hnN j hj + · rw [inverse_bin_zero_lower hm hn2 hi (by omega : j < lowerIndex m (sideAfter .even n))] + exact zero_le + +end NumberTheoryLean.SourceAllInverseBins + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceBlockFibreBound.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceBlockFibreBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cb2262f965631fc3b97d8b7c25ca2eb3a6ea4ee --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceBlockFibreBound.lean @@ -0,0 +1,133 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceLargePairBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceLargeCount ErdosHyperbolaError + ErdosLargeHeightBlocks ErdosInversePrimeBin ErdosPrimeInputs.PrimeProductOmissions +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def blockPatternPrimes (R theta w : ℝ) (H : ℕ) (C0 : ℤ) + (hw : 0 ≤ w) (hP : ∀ p ∈ primeBin R theta,p.Prime) + (hlarge : ∀ p ∈ primeBin R theta,w < (p : ℝ)) + (i : Fin (blockCount C0 R theta H)) (v : ErdosLargePatternLaw.FullPattern w H) : + Finset (goodPrimes (primeBin R theta) H) := + Finset.univ.filter (fun p => p.val ∈ blockPrimes C0 R theta H i ∧ + actualFullPattern (primeBin R theta) w H C0 hw hP hlarge p = v) + +theorem blockPatternPrimes_le_pairs (R theta w : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 1 < R) (htheta : 0 < theta) (hH : 0 < H) (hw : 0 ≤ w) + (hP : ∀ p ∈ primeBin R theta,p.Prime) (hlarge : ∀ p ∈ primeBin R theta,w < (p : ℝ)) + (i : Fin (blockCount C0 R theta H)) (v : ErdosLargePatternLaw.FullPattern w H) : + (blockPatternPrimes R theta w H C0 hw hP hlarge i v).card ≤ + (siftedSourcePairs H (divisorModulus w H) (coprimeModulus w H) C0 (v.2.1.val : ℤ) + (v.1.val.val : ℤ) (v.2.2.1.val.val : ℤ) (v.2.2.2.val : ℤ) + (blockLeft C0 R theta H i) (blockRight C0 R theta H i) + (coordinateLower C0 R theta H i) (coordinateUpper C0 R theta H i) false true true false + (reducedPrimes ⌊largeSieveCutoff R⌋₊ (H*coprimeModulus w H))).card := by + apply original_prime_fibre_le_pairs (primeBin R theta) w H C0 hw hP hlarge _ v R hR + intro p hp + obtain ⟨hb,hv⟩ := (Finset.mem_filter.mp hp).2 + have hpP := (Finset.mem_filter.mp p.property).1 + have hprime := hP p hpP + let : NeZero p.val := ⟨hprime.ne_zero⟩ + have hRp : 0 < R := by linarith + have hbig := (mem_primeBin hRp.le htheta.le p).mp hpP + have hbin := (mem_blockPrimes C0 R theta H i p hRp htheta).mp hb + have hcoord := actual_m0_block_interval C0 R theta H i p hRp htheta hH + (Finset.mem_filter.mp p.property).2 hb + refine ⟨hv,hbig.2.1,hbin.2,?_⟩ + exact hcoord.1 + +theorem actual_block_rectangle_bounds (R theta : ℝ) (H : ℕ) (C0 : ℤ) + (hR : 0 < R) (htheta : 0 < theta) (htheta1 : theta ≤ 1) (hH : 0 < H) + (i : Fin (blockCount C0 R theta H)) : + blockLeft C0 R theta H i ≤ blockRight C0 R theta H i ∧ + blockRight C0 R theta H i-blockLeft C0 R theta H i ≤ R ∧ + coordinateLower C0 R theta H i ≤ coordinateUpper C0 R theta H i ∧ + coordinateUpper C0 R theta H i-coordinateLower C0 R theta H i ≤ 2*(H : ℝ) := by + have hn := blockCount_pos C0 R theta H + have hright : blockLeft C0 R theta H i < blockRight C0 R theta H i := + ErdosTagSubbins.left_lt_right hR htheta hn + refine ⟨hright.le,?_,?_,block_coordinate_width C0 R theta H i hR htheta hH⟩ + · change ErdosTagSubbins.right R theta (blockCount C0 R theta H) i- + ErdosTagSubbins.left R theta (blockCount C0 R theta H) i ≤ R + rw [ErdosTagSubbins.right_sub_left] + unfold ErdosTagSubbins.step + have hden : (1 : ℝ) ≤ blockCount C0 R theta H := by exact_mod_cast hn + have hh := div_le_self (mul_nonneg htheta.le hR.le) hden + have hnum : theta*R ≤ R := by nlinarith + simpa only [mul_comm] using hh.trans hnum + · unfold coordinateLower coordinateUpper + exact (min_le_max).trans (le_add_of_nonneg_right (Nat.cast_nonneg H)) + +end ErdosVarianceLargeMap + +end + +section + +open _root_.Filter +namespace ErdosVarianceLargeMap +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceLargeCount ErdosVarianceLargeScale + ErdosLargeHeightBlocks ErdosInversePrimeBin ErdosInverseBoxHeight ErdosInverseEuler +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_block_fibre_bound (alpha : ℝ) (halpha : 0 < alpha) : + ∃ C : ℝ,0 < C ∧ ∀ᶠ z : ℝ in atTop,1 < z ∧ + ∀ (R theta : ℝ),z^alpha ≤ R → 0 < theta → theta ≤ 1 → + ∀ (H : ℕ) (C0 : ℤ),2 ≤ H → Int.gcd C0 (H : ℤ) = 1 → + R^((4 : ℝ)/5) ≤ (H : ℝ) → (H : ℝ) ≤ R*(sourceZ z)^11 → + ∀ (hw : 0 ≤ sourceW z) (hP : ∀ p ∈ primeBin R theta,p.Prime) + (hlarge : ∀ p ∈ primeBin R theta,sourceW z < (p : ℝ)) + (i : Fin (blockCount C0 R theta H)) (v : ErdosLargePatternLaw.FullPattern (sourceW z) H), + ((blockPatternPrimes R theta (sourceW z) H C0 hw hP hlarge i v).card : ℝ) ≤ + C*(blockRight C0 R theta H i-blockLeft C0 R theta H i)/ + ((patternCard (divisorModulus (sourceW z) H) (coprimeModulus (sourceW z) H) : ℝ)*Real.log R)+ + R^((9 : ℝ)/10) := by + obtain ⟨C,hC,hbound⟩ := source_large_pair_bound alpha halpha + refine ⟨C,hC,?_⟩ + filter_upwards [hbound] with z hz + refine ⟨hz.1,?_⟩ + intro R theta hRlo htheta htheta1 H C0 hH hC0 hHlo hHhi hw hP hlarge i v + have hR1 : 1 < R := (Real.one_lt_rpow hz.1 halpha).trans_le hRlo + have hR : 0 < R := by linarith + have hH0 : 0 < H := by omega + let T0 := divisorModulus (sourceW z) H + let T1 := coprimeModulus (sourceW z) H + have hT0 : 0 < T0 := divisorModulus_pos _ _ + have hT1 : 0 < T1 := coprimeModulus_pos _ _ + have hT0M : T0 ≤ smallModulus (sourceW z) := by + have hh : T0 ≤ T0*T1 := by nlinarith + exact hh.trans_eq (pattern_moduli_product _ _) + have hSF : Squarefree T0 := IntervalBoundingSieve.squarefree_primeSet_product _ + (fun t ht => (LargePrimeDeletion.mem_cutoffPrimes.mp (Finset.mem_filter.mp ht).1).1) + have hsupport : ∀ t : ℕ,t.Prime → t ∣ T0 → t ∣ H := + fun t _ ht => ht.trans (divisorModulus_dvd_H (sourceW z) H) + have hcop : T1.Coprime (H*T0) := (effective_pattern_coprime _ _).symm + have hunit := full_pattern_units (sourceW z) H v + have hrectangle := actual_block_rectangle_bounds R theta H C0 hR htheta htheta1 hH0 i + have hpairs := hz.2 R hRlo H T0 T1 hH hT0 hT1 hSF hsupport hcop hHlo hHhi hT0M + C0 (v.2.1.val : ℤ) (v.1.val.val : ℤ) (v.2.2.1.val.val : ℤ) (v.2.2.2.val : ℤ) + hC0 hunit.1 hunit.2 + (blockLeft C0 R theta H i) (blockRight C0 R theta H i) + (coordinateLower C0 R theta H i) (coordinateUpper C0 R theta H i) + hrectangle.1 hrectangle.2.1 hrectangle.2.2.1 hrectangle.2.2.2 false true true false + have hactual := blockPatternPrimes_le_pairs R theta (sourceW z) H C0 hR1 htheta hH0 hw hP hlarge i v + exact (show ((blockPatternPrimes R theta (sourceW z) H C0 hw hP hlarge i v).card : ℝ) ≤ _ by + exact_mod_cast hactual).trans hpairs + +end ErdosVarianceLargeMap + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceCanonicalKeyGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceCanonicalKeyGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..56f2fcd66cec9b51472eee758d21a4420e6e98d4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceCanonicalKeyGeometry.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalKeyReference + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SourceCanonicalKeyGeometry +open _root_.Filter PrimeHistories CanonicalStopKey CanonicalStopPartition CanonicalKeyWitness +open CanonicalKeyBands CanonicalKeyReference SourceRootReference +open StoppedCountVertex StoppedVertexHistory StoppedCountAdapters StoppedTraceSets +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin ErdosInverseAlignment ErdosPrimeInputs.MertensStrong +open ErdosInverseBoxHeight ErdosCorrectionLimit ErdosSourceReferenceMargin +open scoped Topology + +attribute [local instance] Classical.propDecidable + +theorem source_key_geometry {Clen xi Kstop rho : ℝ} (hC : 0 ≤ Clen) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hK : 0 < Kstop) (hrho : 0 < rho) (P0 : ℕ) : + ∀ᶠ top : ℝ in atTop, + let w := sourceW top + let B := sourceB top + let Y := sourceY top + let z := sourceRootNode (1/100) top + let mu := (Y:ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊ + 0 < Y ∧ ∃ hw : 1 < w,∃ htop : w < top,∀ Cs eta : ℝ,∀ a : ℕ → ℕ, + ∀ k∈keys Y w top Cs eta Clen B xi (Kstop*(Real.log w)^2) (rho*Kstop*(Real.log w)^2) + mu hw htop hxi a z, + Nonempty (Witness hw htop hxi Y Cs eta Clen B (Kstop*(Real.log w)^2) + (rho*Kstop*(Real.log w)^2) mu a z k) ∧ + P0 ≤ k.tail.getLastD 0 ∧ + Real.exp ((Kstop/2)*(Real.log w)^3) ≤ (k.tail.getLastD 0:ℝ) ∧ + (k.tail.getLastD 0:ℝ) ≤ Real.exp (rho*Kstop*(Real.log w)^3) ∧ + xi/4 ≤ width w top xi k.tag.bin ∧ width w top xi k.tag.bin ≤ 1 ∧ + (∀ p∈Set.Icc (lower w top xi k.tag.bin) ((1+width w top xi k.tag.bin)*lower w top xi k.tag.bin), + 203/100 ≤ Real.log ((Y:ℝ)/(p*(k.pre.prod*k.tail.prod:ℕ)))/Real.log (k.tail.getLastD 0:ℝ) ∧ + Real.log ((Y:ℝ)/(p*(k.pre.prod*k.tail.prod:ℕ)))/Real.log (k.tail.getLastD 0:ℝ) ≤ 219/100) ∧ + (∀ p∈(primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin)).filter + (aligns (SourceStopPredicate.sourceClass a) k.tag.rational), + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) mu) (k.pre++p::k.tail)) + ≤ (33/100)*primeProduct (k.tail.getLastD 0:ℝ)* + ((Y:ℝ)/((p:ℝ)*(k.pre.prod*k.tail.prod:ℕ)))) := by + filter_upwards [source_root_eventually_data,ErdosCofactorChoices.source_span_geometry, + rootW_tendsto.eventually (moving_key_bands hC hxi hxi1 hK hrho), + rootW_tendsto.eventually (moving_key_reference hC hxi hxi1 hK hrho), + rootW_tendsto.eventually (TagBelowStopWindow.moving_window_below_search rho Kstop hrho hK), + rootW_tendsto.eventually_ge_atTop (P0:ℝ)] with top hData hSpan hBands hRef hWindow hP0 + dsimp only + obtain ⟨hY,_hB,hw,htop,hcomp,_hrlo,_hrhi,_hcons,_hpower⟩ := hData + obtain ⟨_hwB,hBands⟩ := hBands + obtain ⟨_hwR,hRef⟩ := hRef + refine ⟨hY,hw,htop,?_⟩ + intro Cs eta a k hk + obtain ⟨d⟩ := key_witness_exists hw htop hxi (sourceY top) Cs eta Clen (sourceB top) + (Kstop*(Real.log (sourceW top))^2) (rho*Kstop*(Real.log (sourceW top))^2) + ((sourceY top:ℝ)*SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) a + (sourceRootNode (1/100) top) hWindow k hk + have hBand := hBands top htop (sourceB top) hcomp (sourceY top) hY (1/100) Cs eta + ((sourceY top:ℝ)*SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) (by norm_num) (by norm_num) + a (sourceRootNode (1/100) top) rfl k d + have hTail : k.tail.getLastD 0∈k.tail := by + have he : k.tail.getLastD 0=k.tail.getLast d.tail_nonempty := by + conv_lhs => rw [← List.dropLast_append_getLast d.tail_nonempty] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem d.tail_nonempty + have hPsource := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop (k.tail.getLastD 0)).mp + (d.source _ (by simp only [List.mem_append,List.mem_cons]; exact Or.inr (Or.inr hTail))) + have hPsize : P0 ≤ k.tail.getLastD 0 := by exact_mod_cast hP0.trans hPsource.2.1.le + refine ⟨⟨d⟩,hPsize,hBand.1,hBand.2.1,?_,?_,hBand.2.2,?_⟩ + · exact effectiveWidth_ge_quarter (zero_lt_one.trans hw) htop hxi hxi1 (hSpan.2.2 xi hxi hxi1) + · exact (effectiveWidth_le (zero_lt_one.trans hw) htop hxi).trans hxi1 + · intro p hp + exact hRef top htop (sourceB top) hcomp (sourceY top) Cs eta a (sourceRootNode (1/100) top) k d + p (Finset.mem_filter.mp hp).1 (Finset.mem_filter.mp hp).2 +end NumberTheoryLean.SourceCanonicalKeyGeometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceDenseCellContradiction.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceDenseCellContradiction.lean new file mode 100644 index 0000000000000000000000000000000000000000..871460173a06b62b3aecd109d13b134f4ba69250 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceDenseCellContradiction.lean @@ -0,0 +1,206 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceRichPoints +import OAI.NumberTheory.Jacobsthal.Estimates.SourceRichSetContradiction + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseRefinement +open ErdosCofactorChoices +attribute [local instance] Classical.decEq + +theorem cofactor_coprime_excluded_bin {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) (hP : ∀ i,∀ p ∈ P i,p.Prime) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (i : ι) (hi : m i = 0) (q : ℕ) (hq : q ∈ cofactorChoices P m) : + ∀ p ∈ P i,q.Coprime p := by + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp hq + have hs := (mem_selections P m f).mp hf + have hz : f i = ∅ := Finset.card_eq_zero.mp ((hs i).2.trans hi) + have hrec := prime_factor_bin_recovery P m hP hd f hf i + rw [hz] at hrec + intro p hp + apply Nat.Coprime.symm + apply (hP i p hp).coprime_iff_not_dvd.mpr + intro hdiv + have hm : p ∈ (selectionProduct f).primeFactors := Nat.mem_primeFactors.mpr + ⟨hP i p hp,hdiv,(selectionProduct_pos P hP f (fun j => (hs j).1)).ne'⟩ + have he := Finset.mem_inter.mpr ⟨hm,hp⟩ + rw [hrec] at he + exact Finset.notMem_empty p he + +theorem cofactor_coprime_small {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (m : ι → ℕ) (hP : ∀ i,∀ p ∈ P i,p.Prime) + (w : ℝ) (hlarge : ∀ i,∀ p ∈ P i,w < (p : ℝ)) + (q : ℕ) (hq : q ∈ cofactorChoices P m) (t : ℕ) (ht : t.Prime) (htw : (t : ℝ) ≤ w) : + q.Coprime t := by + obtain ⟨f,hf,rfl⟩ := Finset.mem_image.mp hq + have hs := (mem_selections P m f).mp hf + apply Nat.coprime_prod_left_iff.mpr + intro i _ + apply Nat.coprime_prod_left_iff.mpr + intro p hp + apply (Nat.coprime_primes (hP i p ((hs i).1 hp)) ht).mpr + intro he + have hh := hlarge i p ((hs i).1 hp) + subst p + linarith + +theorem distinct_bins_coprime {ι : Type*} [Fintype ι] + (P : ι → Finset ℕ) (hP : ∀ i,∀ p ∈ P i,p.Prime) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) (i j : ι) (hij : i ≠ j) : + ∀ p ∈ P i,∀ u ∈ P j,p.Coprime u := by + intro p hp u hu + apply (Nat.coprime_primes (hP i p hp) (hP j u hu)).mpr + intro he + exact Finset.disjoint_left.mp (hd hij) hp (he.symm ▸ hu) + +end ErdosInverseRefinement + +end + +section + +namespace ErdosInverseRefinement + +theorem parent_product_le_of_child_log (Y p q u : ℕ) (w a : ℝ) + (hp : 0 < p) (hq : 0 < q) (hu : 1 ≤ u) (hw : 1 < w) (ha : 0 < a) + (hlog : 3*a/4 ≤ Real.log ((Y : ℝ)/((p : ℝ)*q*u))/Real.log w) : + (p : ℝ)*(q : ℝ) ≤ (Y : ℝ) := by + have hwlog : 0 < Real.log w := Real.log_pos hw + have hpositive : 0 < Real.log ((Y : ℝ)/((p : ℝ)*q*u)) := by + have hh := (le_div_iff₀ hwlog).mp hlog + have hleft : 0 < (3*a/4)*Real.log w := by positivity + exact hleft.trans_le hh + have hden : 0 < (p : ℝ)*q*u := by exact_mod_cast Nat.mul_pos (Nat.mul_pos hp hq) (lt_of_lt_of_le Nat.zero_lt_one hu) + have hrat0 : 0 ≤ (Y : ℝ)/((p : ℝ)*q*u) := div_nonneg (Nat.cast_nonneg _) hden.le + have hrat1 : 1 < (Y : ℝ)/((p : ℝ)*q*u) := (Real.log_pos_iff hrat0).mp hpositive + have hh := (lt_div_iff₀ hden).mp hrat1 + have huR : (1 : ℝ) ≤ u := by exact_mod_cast hu + have hmul := mul_le_mul_of_nonneg_left huR (show 0 ≤ (p : ℝ)*q by positivity) + nlinarith + +theorem parent_small_coprime_child (p q u : ℕ) (w : ℝ) (hu : u.Prime) (hwu : w < (u : ℝ)) + (hparent : ∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*q).Coprime t) : + ∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (p*q*u).Coprime t := by + intro t ht htw + apply (hparent t ht htw).mul_left + apply (Nat.coprime_primes hu ht).mpr + intro he + subst u + linarith + +end ErdosInverseRefinement + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseRefinement +open NumberTheoryLean ErdosInverseCells ErdosInverseSampling ErdosInverseSampleCost + ErdosInverseEuler ErdosInverseStructured ErdosInverseBoxHeight ErdosInversePrimeBin + +theorem source_no_dense_cell (Clen Cparent aStar K alpha delta beta : ℝ) (h : ℕ) + (hClen : 0 ≤ Clen) (hCparent : 0 ≤ Cparent) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (hK : 0 ≤ K) (halpha : 0 < alpha) (hd : 0 < delta) (hb : 0 < beta) (hb1 : beta ≤ 1) + (hh : 12 < aStar*(h : ℝ)/2) : + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ ∀ xi : ℝ,0 < xi → xi ≤ xi0 → + ∀ᶠ z : ℝ in atTop,∀ R thetaP U thetaU Qplus S : ℝ, + ∀ (C : Finset ℕ) (q0 : ℕ) (b0 : ℤ) (a : ℕ → ℕ), + z^alpha ≤ R → R ≤ z^((1 : ℝ)/100) → sourceW z ≤ U → U ≤ (sourceW z)^K → + xi/4 ≤ thetaP → thetaP ≤ xi → xi/4 ≤ thetaU → thetaU ≤ xi → + q0 ∈ C → 0 < q0 → + S/(q0 : ℝ) ≤ (1+thetaP)^(Clen*Real.log (sourceB z)) → + (∀ q ∈ C,Squarefree q ∧ (q : ℝ) ≤ S) → + (∀ q ∈ C,(q : ℝ) ≤ Qplus ∧ Qplus ≤ (1+xi)*(q : ℝ)) → + (∀ p ∈ primeBin R thetaP,∀ u ∈ primeBin U thetaU,p.Coprime u) → + (∀ q ∈ C,∀ p ∈ primeBin R thetaP,q.Coprime p) → + (∀ q ∈ C,∀ u ∈ primeBin U thetaU,q.Coprime u) → + (∀ q ∈ C,∀ p ∈ primeBin R thetaP,∀ t : ℕ,t.Prime → + (t : ℝ) ≤ sourceW z → (p*q).Coprime t) → + (∀ q ∈ C,∀ p ∈ primeBin R thetaP,∀ u ∈ primeBin U thetaU, + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z)) → + (∀ p ∈ primeBin R thetaP, + Real.logb (sourceW z) ((sourceY z : ℝ)/((p : ℝ)*q0)) ≤ Cparent) → + (∀ q ∈ C,Int.ModEq (smallModulus (sourceW z) : ℤ) (q : ℤ) (q0 : ℤ) ∧ + Int.ModEq (smallModulus (sourceW z) : ℤ) (cofactorHit q a : ℤ) b0) → + S/sourceZ z ≤ (C.card : ℝ) → + let P := primeBin R thetaP + let Uset := primeBin U thetaU + let witness := actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) (sampleGamma beta h/32) + beta*((P.product C).card : ℝ)*(Uset.card : ℝ) ≤ + ((witnessPairs (P.product C) Uset witness).card : ℝ) → False := by + have hhpos : 0 < h := by + by_contra hn + have hz : h = 0 := by omega + simp only [hz,Nat.cast_zero,mul_zero,zero_div] at hh + linarith + let gamma := sampleGamma beta h + have hg : 0 < gamma := sampleGamma_pos beta h hb + obtain ⟨xi0,hxi0,hxi01,hRich⟩ := source_rich_points aStar delta K gamma h ha hd hK hg hhpos + refine ⟨xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + have hxi1 : xi ≤ 1 := hxib.trans hxi01 + filter_upwards [source_good_sample aStar K alpha xi delta beta h ha ha1 hK halpha hxi hxi1 hd hb hb1 hh, + hRich xi hxi hxib, + uniform_no_rich_nonstructured_set Clen Cparent (xi/4) alpha (gamma/8) + hClen hCparent (by positivity) halpha (by positivity), + sourceW_tendsto_atTop.eventually_ge_atTop 2] with z hgood hrich hno hW + intro R thetaP U thetaU Qplus S C q0 b0 a hRlo hRhi hWU hUtop hPlow hPhigh hUlow hUhigh + hq0C hq0 hinfl hCsq hCQ hpU hCP hCU hsmall hlog hparentlog hcong hCsize + dsimp only + intro hdense + let P := primeBin R thetaP + let Uset := primeBin U thetaU + let witness := actualWitness (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a delta + (SmallSieveFinite.smallEuler ⌊sourceW z⌋₊) P S R (sourceZ z) (gamma/32) + obtain ⟨s,hPpos,hUpos,_,hreward,hcost⟩ := hgood.2 R thetaP U thetaU Qplus S C q0 b0 a + hRlo hWU hUtop hPlow hPhigh hUlow hUhigh hq0C hq0 (hCQ q0 hq0C).1 (hCQ q0 hq0C).2 + (hsmall q0 hq0C) (hlog q0 hq0C) hdense + have hzpos : 0 < z := by linarith [hgood.1] + have hR : 0 < R := (Real.rpow_pos_of_pos hzpos alpha).trans_le hRlo + have hU : 0 ≤ U := by linarith + have hthetaP : 0 ≤ thetaP := (by positivity : (0 : ℝ) ≤ xi/4).trans hPlow + have hthetaU : 0 ≤ thetaU := (by positivity : (0 : ℝ) ≤ xi/4).trans hUlow + have hPprime : ∀ p ∈ P,p.Prime := fun p hp => ((mem_primeBin hR.le hthetaP p).mp hp).1 + have hUprime : ∀ u ∈ Uset,u.Prime := fun u hu => ((mem_primeBin hU hthetaU u).mp hu).1 + have huLarge : ∀ u ∈ Uset,sourceW z < (u : ℝ) := + fun u hu => hWU.trans_lt ((mem_primeBin hU hthetaU u).mp hu).2.1 + have hS : 0 < S := (show (0 : ℝ) < q0 by exact_mod_cast hq0).trans_le (hCsq q0 hq0C).2 + have hsmallChild : ∀ q ∈ C,∀ p ∈ P,∀ u ∈ Uset,∀ t : ℕ,t.Prime → + (t : ℝ) ≤ sourceW z → (p*q*u).Coprime t := by + intro q hq p hp u hu + exact parent_small_coprime_child p q u (sourceW z) (hUprime u hu) (huLarge u hu) (hsmall q hq p hp) + obtain ⟨T,D,hDC,hbox,hinj,hsize,hclass,hinc,hthin⟩ := hrich P C a U thetaU Qplus S R (gamma/32) + q0 b0 hR hS hWU hUtop hthetaU (hUhigh.trans hxi1) hPpos hPprime hpU hCsq hCP hCU hCQ + hlog hsmallChild hcong hCsize s hreward hcost + obtain ⟨p,hp⟩ := Finset.card_pos.mp hPpos + obtain ⟨u,hu⟩ := Finset.card_pos.mp hUpos + have hp1 : (1 : ℝ) ≤ p := by exact_mod_cast (hPprime p hp).one_lt.le + have hq0R : (0 : ℝ) < q0 := by exact_mod_cast hq0 + have hpq := parent_product_le_of_child_log (sourceY z) p q0 u (sourceW z) aStar + (hPprime p hp).pos hq0 (hUprime u hu).one_lt.le (by linarith) ha (hlog q0 hq0C p hp u hu) + have hratio : 1 ≤ S/(q0 : ℝ) := (one_le_div hq0R).mpr (hCsq q0 hq0C).2 + have hpR : (p : ℝ) ≤ 2*R := by + have hh := ((mem_primeBin hR.le hthetaP p).mp hp).2.2 + have ht1 := hPhigh.trans hxi1 + nlinarith + apply hno.2 S R (p : ℝ) (q0 : ℝ) thetaP hp1 hq0R hpq hratio hinfl + hRlo hRhi hPlow (hPhigh.trans hxi1) hpR (hparentlog p hp) + (fun p => (a p : ℤ)) T hthin (cofactorPoints D a) hbox hinj hsize + · simpa only [Int.cast_natCast] using hclass + · simpa only [div_div,show (8 : ℝ)*4 = 32 by norm_num] using hinc + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceIntervalReplacement.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceIntervalReplacement.lean new file mode 100644 index 0000000000000000000000000000000000000000..90d659aa907e2326bfc359e4575b1c010d23b749 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceIntervalReplacement.lean @@ -0,0 +1,156 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SmallModelSourceScales +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueTailUpper + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseTail +open NumberTheoryLean + +theorem interval_replacement_bounds (eta : ℝ) (heta : 0 < eta) : + ∃ C : ℝ,0 < C ∧ ∃ w0 : ℝ,2 ≤ w0 ∧ + ∀ (J N u : ℕ) [NeZero u] (e : ZMod u) (w L : ℝ) (b : ℤ) (step : ℕ) (a : ℕ → ℕ), + w0 ≤ w → J ≤ N → w^eta ≤ L → w^eta ≤ L/(u : ℝ) → ((N-J : ℕ) : ℝ) ≤ L → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → step.Coprime t) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ w → (step*u).Coprime t) → + |((ProgressionSmallSieve.progressionSurvivors N ⌊w⌋₊ b step a).card : ℝ)- + ((ProgressionSmallSieve.progressionSurvivors J ⌊w⌋₊ b step a).card : ℝ)| ≤ + C*L*SmallSieveFinite.smallEuler ⌊w⌋₊ ∧ + |(((ProgressionSmallSieve.progressionSurvivors N ⌊w⌋₊ b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card : ℝ)- + (((ProgressionSmallSieve.progressionSurvivors J ⌊w⌋₊ b step a).filter (fun j : ℕ => (j : ZMod u) = e)).card : ℝ)| ≤ + 2*C*(L/(u : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊ := by + obtain ⟨C1,hC1,w1,hw1,hparent⟩ := sieve_tail_upper eta heta + obtain ⟨C2,hC2,w2,hw2,hchild⟩ := residue_tail_upper eta heta + refine ⟨C1+C2,by linarith,max w1 w2,hw1.trans (le_max_left _ _),?_⟩ + intro J N u inst e w L b step a hw hJN hL hLu hNL hcop hcopu + have hwleft : w1 ≤ w := (le_max_left _ _).trans hw + have hwright : w2 ≤ w := (le_max_right _ _).trans hw + have hw2' : 2 ≤ w := hw1.trans hwleft + have hwpos : 0 < w := by linarith + have hV : 0 ≤ SmallSieveFinite.smallEuler ⌊w⌋₊ := + ((inv_pos.mpr hwpos).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2')).le + have hLpos : 0 ≤ L := (Real.rpow_pos_of_pos hwpos eta).le.trans hL + have hLupos : 0 ≤ L/(u : ℝ) := (Real.rpow_pos_of_pos hwpos eta).le.trans hLu + constructor + · rw [survivor_count_difference J N ⌊w⌋₊ hJN b step a] + calc + _ ≤ C1*L*SmallSieveFinite.smallEuler ⌊w⌋₊ := hparent J N w L b step a hwleft hL hNL hcop + _ ≤ _ := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (by linarith : C1 ≤ C1+C2) hLpos) hV + · rw [residue_count_difference J N ⌊w⌋₊ u hJN e b step a] + calc + _ ≤ 2*C2*(L/(u : ℝ))*SmallSieveFinite.smallEuler ⌊w⌋₊ := + hchild J N u e w L b step a hwright hLu hNL hcopu + _ ≤ _ := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (by linarith : 2*C2 ≤ 2*(C1+C2)) hLupos) hV + +end ErdosInverseTail + +end + +section + +namespace ErdosInverseFrozen +open NumberTheoryLean ErdosInverseEuler + +theorem center_step_coprime (w : ℝ) (p q q0 t : ℕ) (ht : t.Prime) (htw : (t : ℝ) ≤ w) + (hqq : Int.ModEq (smallModulus w : ℤ) (q : ℤ) (q0 : ℤ)) + (hactual : (p*q).Coprime t) : (p*q0).Coprime t := by + have htmem : t ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ := + LargePrimeDeletion.mem_cutoffPrimes.mpr ⟨ht,(Nat.le_floor_iff ((Nat.cast_nonneg t).trans htw)).mpr htw⟩ + have hdiv : (t : ℤ) ∣ (smallModulus w : ℤ) := by + exact_mod_cast cutoffPrime_dvd_smallModulus w t htmem + have hqt : Nat.ModEq t q q0 := Int.natCast_modEq_iff.mp (hqq.of_dvd hdiv) + have hprod : Nat.ModEq t (p*q) (p*q0) := hqt.mul_left p + have hn := ht.coprime_iff_not_dvd.mp hactual.symm + apply Nat.Coprime.symm + apply ht.coprime_iff_not_dvd.mpr + intro hd + apply hn + change (p*q)%t = (p*q0)%t at hprod + exact Nat.dvd_of_mod_eq_zero (hprod.trans (Nat.mod_eq_zero_of_dvd hd)) + +end ErdosInverseFrozen + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseTail +open NumberTheoryLean ErdosInverseHits ErdosInverseFrozen ErdosInverseEuler ErdosInverseCounts ErdosInverseBoxHeight + +theorem source_interval_replacement (aStar : ℝ) (ha : 0 < aStar) : + ∃ C : ℝ,0 < C ∧ ∀ xi : ℝ,0 < xi → xi ≤ 1 → + ∀ᶠ z : ℝ in atTop,∀ (a : ℕ → ℕ) (p q q0 u : ℕ) [NeZero p] [NeZero u] + (_hp : p.Prime) (_hu : u.Prime) (hqp : q.Coprime p) (hq : Squarefree q) + (hpu : p.Coprime u) (hqu : q.Coprime u) (Qplus : ℝ) (b0 v : ℤ), + (q : ℝ) ≤ Qplus → Qplus ≤ (1+xi)*(q : ℝ) → + 3*aStar/4 ≤ Real.log ((sourceY z : ℝ)/((p : ℝ)*q*u))/Real.log (sourceW z) → + (∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q*u).Coprime t) → + Int.ModEq (smallModulus (sourceW z) : ℤ) (q : ℤ) (q0 : ℤ) → + Int.ModEq (smallModulus (sourceW z) : ℤ) (primeHitRepresentative q hq a : ℤ) b0 → + Int.ModEq (smallModulus (sourceW z) : ℤ) + (parentSlope p q hqp (a p) (primeHitRepresentative q hq a) : ℤ) v → + let J := commonParentLength (sourceY z) p Qplus + let V0 := SmallSieveFinite.smallEuler ⌊sourceW z⌋₊ + |(modulusCount (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a (p*q) : ℝ)- + ((frozenCoordinates J (sourceW z) p q0 b0 v a).card : ℝ)| ≤ 2*C*xi*(J : ℝ)*V0 ∧ + |(modulusCount (sourceY z) (LargePrimeDeletion.cutoffPrimes ⌊sourceW z⌋₊) a (p*q*u) : ℝ)- + (((frozenCoordinates J (sourceW z) p q0 b0 v a).filter + (fun j : ℕ => (j : ZMod u) = parentEdgeResidue p q u hqp hq hpu hqu a)).card : ℝ)| ≤ + 4*C*xi*(J : ℝ)*V0/(u : ℝ) := by + obtain ⟨C,hC,w0,hw0,hbound⟩ := interval_replacement_bounds (aStar/2) (by positivity) + refine ⟨C,hC,?_⟩ + intro xi hxi hxi1 + filter_upwards [source_common_length_regime aStar xi ha hxi hxi1, + sourceW_tendsto_atTop.eventually_ge_atTop w0] with z hreg hw + intro a p q q0 u instP instU hp hu hqp hq hpu hqu Qplus b0 v hqQ hQq hlog hcop hqq hbb hsv + let J := commonParentLength (sourceY z) p Qplus + let N := hitLength (sourceY z) (p*q) (sourceParentBase p q hqp hq a) + have hqpos : 0 < q := Nat.pos_of_ne_zero hq.ne_zero + have hlength := hreg.2 (sourceY z) p q u Qplus hp.pos hqpos hu.pos hqQ hQq hlog + have hb := sourceParentBase_bounds p q hqp hq a + have hJN : J ≤ N := commonParentLength_le_hits (sourceY z) p q _ hp.pos hqpos hb.2 Qplus hqQ + have htail : ((N-J : ℕ) : ℝ) ≤ 2*xi*(J : ℝ) := by + have hh := actual_cell_tail_length (sourceY z) p q _ hp.pos hqpos hb.1 hb.2 Qplus xi hxi.le hxi1 hqQ hQq + change ((N-J : ℕ) : ℝ) ≤ xi*(J : ℝ)+3 at hh + change 3 ≤ xi*(J : ℝ) ∧ _ at hlength + nlinarith [hlength.1] + have hLpos : 0 ≤ 2*xi*(J : ℝ) := by positivity + have hu1 : (1 : ℝ) ≤ u := by exact_mod_cast hu.pos + have hL : (sourceW z)^(aStar/2) ≤ 2*xi*(J : ℝ) := + hlength.2.trans (div_le_self hLpos hu1) + have hstep : ∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q0).Coprime t := by + intro t ht htw + exact center_step_coprime (sourceW z) p q q0 t ht htw hqq (Nat.coprime_mul_iff_left.mp (hcop t ht htw)).1 + have hstepu : ∀ t : ℕ,t.Prime → (t : ℝ) ≤ sourceW z → (p*q0*u).Coprime t := by + intro t ht htw + have hactual : ((p*u)*q).Coprime t := by simpa only [Nat.mul_assoc,Nat.mul_comm,Nat.mul_left_comm] using hcop t ht htw + have hh := center_step_coprime (sourceW z) (p*u) q q0 t ht htw hqq hactual + simpa only [Nat.mul_assoc,Nat.mul_comm,Nat.mul_left_comm] using hh + have herr := hbound J N u (parentEdgeResidue p q u hqp hq hpu hqu a) (sourceW z) + (2*xi*(J : ℝ)) (b0+(q0 : ℤ)*v) (p*q0) a hw hJN hL hlength.2 htail hstep hstepu + dsimp only + rw [actual_parent_count_frozen (sourceY z) (sourceW z) a p q q0 hp hqp hq b0 v hqq hbb hsv, + actual_child_count_frozen (sourceY z) (sourceW z) a p q q0 u hp hu hqp hq hpu hqu b0 v hqq hbb hsv] + simp only [Int.cast_natCast] + change _ ≤ _ ∧ _ ≤ _ + constructor + · calc + _ ≤ C*(2*xi*(J : ℝ))*SmallSieveFinite.smallEuler ⌊sourceW z⌋₊ := herr.1 + _ = _ := by ring + · calc + _ ≤ 2*C*((2*xi*(J : ℝ))/(u : ℝ))*SmallSieveFinite.smallEuler ⌊sourceW z⌋₊ := herr.2 + _ = _ := by ring + +end ErdosInverseTail + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceLabelCount.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceLabelCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..3cde30dc28fb199777b09ddae81ab3e88423c00a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceLabelCount.lean @@ -0,0 +1,452 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Sieve.ActualCofactorCellData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseCells +attribute [local instance] Classical.decEq + +noncomputable def labelFiber {ι : Type*} (Q : Finset ℕ) (label : ℕ → ι) (i : ι) : Finset ℕ := + Q.filter (fun q => label q = i) + +theorem mem_labelFiber {ι : Type*} (Q : Finset ℕ) (label : ℕ → ι) (i : ι) (q : ℕ) : + q ∈ labelFiber Q label i ↔ q ∈ Q ∧ label q = i := Finset.mem_filter + +theorem labelFiber_subset {ι : Type*} (Q : Finset ℕ) (label : ℕ → ι) (i : ι) : + labelFiber Q label i ⊆ Q := Finset.filter_subset _ _ + +theorem label_fibers_partition {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) : + Finset.univ.biUnion (labelFiber Q label) = Q := by + ext q + constructor + · intro hq + obtain ⟨i,_,hi⟩ := Finset.mem_biUnion.mp hq + exact labelFiber_subset Q label i hi + · intro hq + exact Finset.mem_biUnion.mpr ⟨label q,Finset.mem_univ _,Finset.mem_filter.mpr ⟨hq,rfl⟩⟩ + +theorem label_fibers_disjoint {ι : Type*} (Q : Finset ℕ) (label : ℕ → ι) (i j : ι) (hij : i ≠ j) : + Disjoint (labelFiber Q label i) (labelFiber Q label j) := by + apply Finset.disjoint_left.mpr + intro q hi hj + exact hij ((Finset.mem_filter.mp hi).2.symm.trans (Finset.mem_filter.mp hj).2) + +theorem sum_label_fibers {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) (f : ℕ → ℝ) : + (∑ i : ι,∑ q ∈ labelFiber Q label i,f q) = ∑ q ∈ Q,f q := by + calc + _ = ∑ q ∈ Finset.univ.biUnion (labelFiber Q label),f q := + (Finset.sum_biUnion (fun i _ j _ hij => label_fibers_disjoint Q label i j hij)).symm + _ = _ := by rw [label_fibers_partition] + +noncomputable def smallLabels {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) (tau : ℝ) : Finset ι := + Finset.univ.filter (fun i => ((labelFiber Q label i).card : ℝ) < tau) + +noncomputable def discardedPoints {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) (tau : ℝ) : Finset ℕ := + (smallLabels Q label tau).biUnion (labelFiber Q label) + +theorem mem_discardedPoints {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) (tau : ℝ) (q : ℕ) : + q ∈ discardedPoints Q label tau ↔ q ∈ Q ∧ ((labelFiber Q label (label q)).card : ℝ) < tau := by + constructor + · intro hq + obtain ⟨i,hi,hqi⟩ := Finset.mem_biUnion.mp hq + obtain ⟨hqQ,he⟩ := Finset.mem_filter.mp hqi + refine ⟨hqQ,?_⟩ + rw [he] + exact (Finset.mem_filter.mp hi).2 + · rintro ⟨hq,hs⟩ + exact Finset.mem_biUnion.mpr ⟨label q,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hs⟩, + Finset.mem_filter.mpr ⟨hq,rfl⟩⟩ + +theorem discardedPoints_subset {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) (tau : ℝ) : + discardedPoints Q label tau ⊆ Q := fun q hq => (mem_discardedPoints Q label tau q).mp hq |>.1 + +theorem sum_small_fibers {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) (tau : ℝ) (f : ℕ → ℝ) : + (∑ i ∈ smallLabels Q label tau,∑ q ∈ labelFiber Q label i,f q) = ∑ q ∈ discardedPoints Q label tau,f q := + (Finset.sum_biUnion (fun i _ j _ hij => label_fibers_disjoint Q label i j hij)).symm + +theorem discardedPoints_card_bound {ι : Type*} [Fintype ι] (Q : Finset ℕ) (label : ℕ → ι) + (tau : ℝ) (htau : 0 ≤ tau) : + ((discardedPoints Q label tau).card : ℝ) ≤ (Fintype.card ι : ℝ)*tau := by + calc + _ ≤ ∑ i ∈ smallLabels Q label tau,((labelFiber Q label i).card : ℝ) := by + exact_mod_cast Finset.card_biUnion_le + _ ≤ ∑ _i ∈ smallLabels Q label tau,tau := Finset.sum_le_sum (fun i hi => (Finset.mem_filter.mp hi).2.le) + _ = ((smallLabels Q label tau).card : ℝ)*tau := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast Finset.card_le_univ (smallLabels Q label tau)) htau + +end ErdosInverseCells + +end + +section + +namespace ErdosGeometricValueCells + +noncomputable def coordinate (B xi q : ℝ) : ℝ := Real.log (B/q)/Real.log (1+xi) + +noncomputable def valueIndex (B xi : ℝ) (k : ℕ) (q : ℝ) : Fin (k+1) := + ⟨min k ⌊coordinate B xi q⌋₊, Nat.lt_succ_of_le (min_le_left _ _)⟩ + +theorem coordinate_bounds {B xi q : ℝ} {k : ℕ} (hB : 0 < B) (hxi : 0 < xi) + (hlo : B/(1+xi)^k ≤ q) (hhi : q ≤ B) : + 0 < q ∧ 0 ≤ coordinate B xi q ∧ coordinate B xi q ≤ k := by + have hF : 0 < 1+xi := by linarith + have hpow : 0 < (1+xi)^k := pow_pos hF _ + have hq : 0 < q := (div_pos hB hpow).trans_le hlo + have hL : 0 < Real.log (1+xi) := Real.log_pos (by linarith) + have hrat : 1 ≤ B/q := (one_le_div hq).mpr hhi + have hratUpper : B/q ≤ (1+xi)^k := by + apply (div_le_iff₀ hq).mpr + have h := (div_le_iff₀ hpow).mp hlo + simpa only [mul_comm] using h + refine ⟨hq, div_nonneg (Real.log_nonneg hrat) hL.le, ?_⟩ + have hlog := Real.log_le_log (div_pos hB hq) hratUpper + rw [Real.log_pow] at hlog + exact (div_le_iff₀ hL).mpr hlog + +theorem valueIndex_eq_floor {B xi q : ℝ} {k : ℕ} (hB : 0 < B) (hxi : 0 < xi) + (hlo : B/(1+xi)^k ≤ q) (hhi : q ≤ B) : + (valueIndex B xi k q).val = ⌊coordinate B xi q⌋₊ := by + have hs := coordinate_bounds hB hxi hlo hhi + have hfloor : ⌊coordinate B xi q⌋₊ ≤ k := by + exact_mod_cast (Nat.floor_le hs.2.1).trans hs.2.2 + exact min_eq_right hfloor + +theorem valueIndex_interval {B xi q : ℝ} {k : ℕ} (hB : 0 < B) (hxi : 0 < xi) + (hlo : B/(1+xi)^k ≤ q) (hhi : q ≤ B) : + B/(1+xi)^((valueIndex B xi k q).val+1) < q ∧ + q ≤ B/(1+xi)^(valueIndex B xi k q).val := by + have hs := coordinate_bounds hB hxi hlo hhi + have hF : 0 < 1+xi := by linarith + have hL : 0 < Real.log (1+xi) := Real.log_pos (by linarith) + have hfloor := valueIndex_eq_floor hB hxi hlo hhi + have hl : ((valueIndex B xi k q).val : ℝ) ≤ coordinate B xi q := by + rw [hfloor] + exact Nat.floor_le hs.2.1 + have hu : coordinate B xi q < ((valueIndex B xi k q).val : ℝ)+1 := by + rw [hfloor] + exact Nat.lt_floor_add_one _ + have hlogLower := (le_div_iff₀ hL).mp hl + have hlogUpper := (div_lt_iff₀ hL).mp hu + have hpLower := Real.exp_le_exp.mpr hlogLower + rw [Real.exp_nat_mul, Real.exp_log hF, Real.exp_log (div_pos hB hs.1)] at hpLower + have hpUpper := Real.exp_lt_exp.mpr hlogUpper + have he : (((valueIndex B xi k q).val : ℝ)+1)*Real.log (1+xi) = + (((valueIndex B xi k q).val+1 : ℕ) : ℝ)*Real.log (1+xi) := by norm_num + rw [he, Real.exp_nat_mul, Real.exp_log hF, Real.exp_log (div_pos hB hs.1)] at hpUpper + constructor + · apply (div_lt_iff₀ (pow_pos hF _)).mpr + simpa only [mul_comm] using (div_lt_iff₀ hs.1).mp hpUpper + · apply (le_div_iff₀ (pow_pos hF _)).mpr + simpa only [mul_comm] using (le_div_iff₀ hs.1).mp hpLower + +end ErdosGeometricValueCells + +end + +section + +namespace ErdosInverseCells +attribute [local instance] Classical.decEq + +theorem exists_dense_retained_fiber {ι : Type*} [Fintype ι] + (Q : Finset ℕ) (label : ℕ → ι) (tau sigma : ℝ) (hsigma : 0 ≤ sigma) + (w f : ℕ → ℝ) (hw : ∀ q ∈ Q,0 ≤ w q) (hf : ∀ q ∈ Q,f q ≤ w q) + (hmass : sigma*(∑ q ∈ Q,w q) < ∑ q ∈ Q,f q) + (hdiscard : (∑ q ∈ discardedPoints Q label tau,w q) ≤ (sigma/2)*(∑ q ∈ Q,w q)) : + ∃ i : ι,tau ≤ ((labelFiber Q label i).card : ℝ) ∧ + (sigma/2)*(∑ q ∈ labelFiber Q label i,w q) < ∑ q ∈ labelFiber Q label i,f q := by + classical + by_contra hno + push Not at hno + have hcell : ∀ i : ι,(∑ q ∈ labelFiber Q label i,f q) ≤ + (sigma/2)*(∑ q ∈ labelFiber Q label i,w q)+ + (if ((labelFiber Q label i).card : ℝ) < tau then ∑ q ∈ labelFiber Q label i,w q else 0) := by + intro i + have hWi : 0 ≤ ∑ q ∈ labelFiber Q label i,w q := + Finset.sum_nonneg (fun q hq => hw q (labelFiber_subset Q label i hq)) + by_cases hi : ((labelFiber Q label i).card : ℝ) < tau + · rw [ite_eq_left hi] + have hfi := Finset.sum_le_sum (fun q hq => hf q (labelFiber_subset Q label i hq)) + have hprod := mul_nonneg (show 0 ≤ sigma/2 by positivity) hWi + linarith + · rw [ite_eq_right hi,add_zero] + exact hno i (le_of_not_gt hi) + have hsmall : (∑ i : ι,if ((labelFiber Q label i).card : ℝ) < tau then ∑ q ∈ labelFiber Q label i,w q else 0) = + ∑ q ∈ discardedPoints Q label tau,w q := by + calc + _ = ∑ i ∈ smallLabels Q label tau,∑ q ∈ labelFiber Q label i,w q := by + simp only [smallLabels,Finset.sum_filter] + _ = _ := sum_small_fibers Q label tau w + have hall : (∑ q ∈ Q,f q) ≤ (sigma/2)*(∑ q ∈ Q,w q)+∑ q ∈ discardedPoints Q label tau,w q := by + calc + _ = ∑ i : ι,∑ q ∈ labelFiber Q label i,f q := (sum_label_fibers Q label f).symm + _ ≤ ∑ i : ι,((sigma/2)*(∑ q ∈ labelFiber Q label i,w q)+ + (if ((labelFiber Q label i).card : ℝ) < tau then ∑ q ∈ labelFiber Q label i,w q else 0)) := + Finset.sum_le_sum (fun i _ => hcell i) + _ = _ := by rw [Finset.sum_add_distrib,← Finset.mul_sum,sum_label_fibers,hsmall] + linarith + +end ErdosInverseCells + +end + +section + +namespace ErdosGeometricValueCells +attribute [local instance] Classical.decEq + +theorem same_index_ratio {B xi q r : ℝ} {k : ℕ} (hB : 0 < B) (hxi : 0 < xi) + (hq0 : B/(1+xi)^k ≤ q) (hq1 : q ≤ B) + (hr0 : B/(1+xi)^k ≤ r) (hr1 : r ≤ B) + (he : valueIndex B xi k q = valueIndex B xi k r) : q/r ≤ 1+xi := by + have hq := valueIndex_interval hB hxi hq0 hq1 + have hr := valueIndex_interval hB hxi hr0 hr1 + have hrp := (coordinate_bounds hB hxi hr0 hr1).1 + have hF : 0 < 1+xi := by linarith + rw [he] at hq + have hscale : B/(1+xi)^(valueIndex B xi k r).val = + (1+xi)*(B/(1+xi)^((valueIndex B xi k r).val+1)) := by + calc + _ = (B/(1+xi)^(valueIndex B xi k r).val)*((1+xi)/(1+xi)) := by + rw [div_self hF.ne', mul_one] + _ = _ := by + rw [pow_succ] + simp only [div_eq_mul_inv, mul_inv_rev] + ring + have hh := mul_lt_mul_of_pos_left hr.1 hF + rw [← hscale] at hh + exact (div_le_iff₀ hrp).mpr (hq.2.trans hh.le) + +noncomputable def valueCell (Q : Finset ℕ) (B xi : ℝ) (k : ℕ) (i : Fin (k+1)) : Finset ℕ := + Q.filter (fun q => valueIndex B xi k q = i) + +theorem valueCells_partition (Q : Finset ℕ) (B xi : ℝ) (k : ℕ) : + Finset.univ.biUnion (valueCell Q B xi k) = Q := by + ext q + constructor + · intro hq + obtain ⟨i, _hi, hqi⟩ := Finset.mem_biUnion.mp hq + exact (Finset.mem_filter.mp hqi).1 + · intro hq + exact Finset.mem_biUnion.mpr ⟨valueIndex B xi k q, Finset.mem_univ _, + Finset.mem_filter.mpr ⟨hq, rfl⟩⟩ + +theorem valueCells_disjoint (Q : Finset ℕ) (B xi : ℝ) (k : ℕ) (i j : Fin (k+1)) (hij : i ≠ j) : + Disjoint (valueCell Q B xi k i) (valueCell Q B xi k j) := by + apply Finset.disjoint_left.mpr + intro q hi hj + exact hij ((Finset.mem_filter.mp hi).2.symm.trans (Finset.mem_filter.mp hj).2) + +theorem sum_valueCells (Q : Finset ℕ) (B xi : ℝ) (k : ℕ) (F : ℕ → ℝ) : + (∑ i : Fin (k+1), ∑ q ∈ valueCell Q B xi k i, F q) = ∑ q ∈ Q, F q := by + calc + _ = ∑ q ∈ Finset.univ.biUnion (valueCell Q B xi k), F q := + (Finset.sum_biUnion (fun i _ j _ hij => valueCells_disjoint Q B xi k i j hij)).symm + _ = _ := by rw [valueCells_partition] + +theorem valueCells_card_bound (Q : Finset ℕ) (B xi : ℝ) (k : ℕ) : + (Q.image (fun q : ℕ => valueIndex B xi k q)).card ≤ k+1 := by + simpa only [Fintype.card_fin] using Finset.card_le_univ (Q.image (fun q : ℕ => valueIndex B xi k q)) + +theorem same_cell_ratio (Q : Finset ℕ) (B xi : ℝ) (k : ℕ) (hB : 0 < B) (hxi : 0 < xi) + (hQ : ∀ q ∈ Q, B/(1+xi)^k ≤ (q : ℝ) ∧ (q : ℝ) ≤ B) + (i : Fin (k+1)) (q r : ℕ) (hq : q ∈ valueCell Q B xi k i) + (hr : r ∈ valueCell Q B xi k i) : (q : ℝ)/(r : ℝ) ≤ 1+xi := by + have hq' := Finset.mem_filter.mp hq + have hr' := Finset.mem_filter.mp hr + exact same_index_ratio hB hxi (hQ q hq'.1).1 (hQ q hq'.1).2 + (hQ r hr'.1).1 (hQ r hr'.1).2 (hq'.2.trans hr'.2.symm) + +end ErdosGeometricValueCells + +end + +section + +namespace ErdosInverseCells +open ErdosInverseHits ErdosGeometricValueCells +attribute [local instance] Classical.decEq +attribute [local instance] Classical.propDecidable + +noncomputable def cofactorHit (q : ℕ) (a : ℕ → ℕ) : ℕ := + if hq : Squarefree q then primeHitRepresentative q hq a else 0 + +theorem cofactorHit_eq (q : ℕ) (hq : Squarefree q) (a : ℕ → ℕ) : + cofactorHit q a = primeHitRepresentative q hq a := by simp only [cofactorHit,dite_eq_left hq] + +theorem cofactorHit_spec (q : ℕ) (hq : Squarefree q) (a : ℕ → ℕ) : + 1 ≤ cofactorHit q a ∧ cofactorHit q a ≤ q ∧ + ∀ p ∈ q.primeFactors,cofactorHit q a%p = a p%p := by + rw [cofactorHit_eq q hq a] + have hh := primeHitRepresentative_spec q hq a + exact ⟨hh.1,hh.2.1,(hh.2.2 _).mpr (Nat.ModEq.refl _)⟩ + +abbrev InitialLabel (k M0 : ℕ) := Fin (k+1) × ZMod M0 × ZMod M0 + +noncomputable def initialLabel (a : ℕ → ℕ) (B xi : ℝ) (k M0 q : ℕ) : InitialLabel k M0 := + ⟨valueIndex B xi k (q : ℝ),(q : ZMod M0),(cofactorHit q a : ZMod M0)⟩ + +noncomputable def initialCell (Q : Finset ℕ) (a : ℕ → ℕ) (B xi : ℝ) (k M0 : ℕ) + (i : InitialLabel k M0) : Finset ℕ := labelFiber Q (initialLabel a B xi k M0) i + +theorem initialLabel_card (k M0 : ℕ) [NeZero M0] : + Fintype.card (InitialLabel k M0) = (k+1)*M0^2 := by + simp only [InitialLabel,Fintype.card_prod,Fintype.card_fin,ZMod.card] + ring + +theorem same_initial_label (a : ℕ → ℕ) (B xi : ℝ) (k M0 q r : ℕ) + (he : initialLabel a B xi k M0 q = initialLabel a B xi k M0 r) : + valueIndex B xi k (q : ℝ) = valueIndex B xi k (r : ℝ) ∧ + Int.ModEq (M0 : ℤ) (q : ℤ) (r : ℤ) ∧ + Int.ModEq (M0 : ℤ) (cofactorHit q a : ℤ) (cofactorHit r a : ℤ) := by + have hi := congrArg (fun i : InitialLabel k M0 => i.1) he + have hq := congrArg (fun i : InitialLabel k M0 => i.2.1) he + have hb := congrArg (fun i : InitialLabel k M0 => i.2.2) he + exact ⟨hi,Int.natCast_modEq_iff.mpr ((ZMod.natCast_eq_natCast_iff q r M0).mp hq), + Int.natCast_modEq_iff.mpr ((ZMod.natCast_eq_natCast_iff (cofactorHit q a) (cofactorHit r a) M0).mp hb)⟩ + +noncomputable def cellUpper (B xi : ℝ) {k M0 : ℕ} (i : InitialLabel k M0) : ℝ := + B/(1+xi)^i.1.val + +theorem initial_cell_interval (Q : Finset ℕ) (a : ℕ → ℕ) (B xi : ℝ) (k M0 : ℕ) + (hB : 0 < B) (hxi : 0 < xi) + (hQ : ∀ q ∈ Q,B/(1+xi)^k ≤ (q : ℝ) ∧ (q : ℝ) ≤ B) + (i : InitialLabel k M0) (q : ℕ) (hq : q ∈ initialCell Q a B xi k M0 i) : + q ∈ Q ∧ 0 < (q : ℝ) ∧ (q : ℝ) ≤ cellUpper B xi i ∧ cellUpper B xi i ≤ (1+xi)*(q : ℝ) := by + have hm := (mem_labelFiber Q (initialLabel a B xi k M0) i q).mp hq + have hi : valueIndex B xi k (q : ℝ) = i.1 := congrArg (fun j : InitialLabel k M0 => j.1) hm.2 + have hinterval := valueIndex_interval hB hxi (hQ q hm.1).1 (hQ q hm.1).2 + rw [hi] at hinterval + have hqpos : 0 < (q : ℝ) := (coordinate_bounds hB hxi (hQ q hm.1).1 (hQ q hm.1).2).1 + have hlow : cellUpper B xi i/(1+xi) < (q : ℝ) := by + unfold cellUpper + rw [div_div,← pow_succ] + exact hinterval.1 + refine ⟨hm.1,hqpos,hinterval.2,?_⟩ + have hh := (div_lt_iff₀ (by linarith : 0 < 1+xi)).mp hlow + nlinarith + +end ErdosInverseCells + +end + +section + +namespace ErdosInverseCells + +theorem mem_initialCell (Q : Finset ℕ) (a : ℕ → ℕ) (B xi : ℝ) (k M0 : ℕ) + (i : InitialLabel k M0) (q : ℕ) : + q ∈ initialCell Q a B xi k M0 i ↔ q ∈ Q ∧ initialLabel a B xi k M0 q = i := + mem_labelFiber Q (initialLabel a B xi k M0) i q + +theorem initial_cell_congruences (Q : Finset ℕ) (a : ℕ → ℕ) (B xi : ℝ) (k M0 : ℕ) + (i : InitialLabel k M0) (q r : ℕ) (hq : q ∈ initialCell Q a B xi k M0 i) + (hr : r ∈ initialCell Q a B xi k M0 i) : + Int.ModEq (M0 : ℤ) (q : ℤ) (r : ℤ) ∧ + Int.ModEq (M0 : ℤ) (cofactorHit q a : ℤ) (cofactorHit r a : ℤ) := by + have hq' := (mem_initialCell Q a B xi k M0 i q).mp hq + have hr' := (mem_initialCell Q a B xi k M0 i r).mp hr + exact (same_initial_label a B xi k M0 q r (hq'.2.trans hr'.2.symm)).2 + +theorem initial_cell_weight_spread (Q : Finset ℕ) (a : ℕ → ℕ) (B xi : ℝ) (k M0 : ℕ) + (hB : 0 < B) (hxi : 0 < xi) + (hQ : ∀ q ∈ Q,B/(1+xi)^k ≤ (q : ℝ) ∧ (q : ℝ) ≤ B) + (i : InitialLabel k M0) (q r : ℕ) (hq : q ∈ initialCell Q a B xi k M0 i) + (hr : r ∈ initialCell Q a B xi k M0 i) : + (q : ℝ)⁻¹ ≤ (1+xi)*(r : ℝ)⁻¹ := by + have hq' := initial_cell_interval Q a B xi k M0 hB hxi hQ i q hq + have hr' := initial_cell_interval Q a B xi k M0 hB hxi hQ i r hr + have hratio : (r : ℝ) ≤ (1+xi)*(q : ℝ) := hr'.2.2.1.trans hq'.2.2.2 + have hh : (1 : ℝ)/(q : ℝ) ≤ (1+xi)/(r : ℝ) := + (div_le_div_iff₀ hq'.2.1 hr'.2.1).mpr (by simpa only [one_mul] using hratio) + simpa only [one_div,div_eq_mul_inv,one_mul] using hh + +end ErdosInverseCells + +end + +section + +namespace ErdosInverseRefinement +open ErdosInverseCells + +abbrev RefinementLabel (W : ℕ) := ZMod W × ZMod W + +noncomputable def refinementLabel (a : ℕ → ℕ) (W q : ℕ) : RefinementLabel W := + ⟨(q : ZMod W),(cofactorHit q a : ZMod W)⟩ + +noncomputable def refinementCell (C : Finset ℕ) (a : ℕ → ℕ) (W : ℕ) (i : RefinementLabel W) : Finset ℕ := + labelFiber C (refinementLabel a W) i + +theorem refinementLabel_card (W : ℕ) [NeZero W] : Fintype.card (RefinementLabel W) = W^2 := by + simp only [RefinementLabel,Fintype.card_prod,ZMod.card] + ring + +theorem mem_refinementCell (C : Finset ℕ) (a : ℕ → ℕ) (W : ℕ) (i : RefinementLabel W) (q : ℕ) : + q ∈ refinementCell C a W i ↔ q ∈ C ∧ refinementLabel a W q = i := + mem_labelFiber C (refinementLabel a W) i q + +theorem refinement_congruences (C : Finset ℕ) (a : ℕ → ℕ) (W : ℕ) (i : RefinementLabel W) (q r : ℕ) + (hq : q ∈ refinementCell C a W i) (hr : r ∈ refinementCell C a W i) : + Int.ModEq (W : ℤ) (q : ℤ) (r : ℤ) ∧ + Int.ModEq (W : ℤ) (cofactorHit q a : ℤ) (cofactorHit r a : ℤ) := by + have hq' := (mem_refinementCell C a W i q).mp hq + have hr' := (mem_refinementCell C a W i r).mp hr + have he := hq'.2.trans hr'.2.symm + have h1 := congrArg (fun j : RefinementLabel W => j.1) he + have h2 := congrArg (fun j : RefinementLabel W => j.2) he + exact ⟨Int.natCast_modEq_iff.mpr ((ZMod.natCast_eq_natCast_iff q r W).mp h1), + Int.natCast_modEq_iff.mpr ((ZMod.natCast_eq_natCast_iff (cofactorHit q a) (cofactorHit r a) W).mp h2)⟩ + +end ErdosInverseRefinement + +end + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseCells +open ErdosCofactorChoices ErdosInverseBoxHeight ErdosInverseEuler + +theorem source_initial_label_count (C eps : ℝ) (hC : 0 ≤ C) (heps : 0 < eps) : + ∀ᶠ z : ℝ in atTop,∀ k : ℕ,(k : ℝ) ≤ C*Real.log (sourceB z) → + (((k+1)*(smallModulus (sourceW z))^2 : ℕ) : ℝ) ≤ (sourceZ z)^eps := by + have hZ := (tendsto_rpow_atTop (by positivity : 0 < eps/2)).comp sourceZ_tendsto_atTop + filter_upwards [source_log_budget,smallModulus_mul_log_power 2 1 (eps/2) (by positivity), + hZ.eventually_ge_atTop (C+1),Real.tendsto_log_atTop.eventually_ge_atTop 1] with z hs hm hcoef hL1 + intro k hk + have hkL : (k : ℝ) ≤ C*Real.log z := by + have hh := hk.trans (mul_le_mul_of_nonneg_left hs.2.2.2.2 hC) + have hlog := Real.log_le_sub_one_of_pos hs.1 + have hL : Real.log (Real.log z) ≤ Real.log z := by linarith + exact hh.trans (mul_le_mul_of_nonneg_left hL hC) + have hk1 : (k : ℝ)+1 ≤ (C+1)*Real.log z := by nlinarith + have hM : (smallModulus (sourceW z) : ℝ)^2*Real.log z ≤ (sourceZ z)^(eps/2) := by + simpa only [pow_one] using hm + have hZpos : 0 < sourceZ z := Real.exp_pos _ + calc + _ = ((k : ℝ)+1)*(smallModulus (sourceW z) : ℝ)^2 := by push_cast;rfl + _ ≤ ((C+1)*Real.log z)*(smallModulus (sourceW z) : ℝ)^2 := + mul_le_mul_of_nonneg_right hk1 (sq_nonneg _) + _ = (C+1)*((smallModulus (sourceW z) : ℝ)^2*Real.log z) := by ring + _ ≤ (sourceZ z)^(eps/2)*(sourceZ z)^(eps/2) := + mul_le_mul hcoef hM (by positivity) (Real.rpow_nonneg hZpos.le _) + _ = (sourceZ z)^eps := by + rw [← Real.rpow_add hZpos] + congr 1 + ring + +end ErdosInverseCells + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceNodeCoordinates.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceNodeCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e46b65c989f6e7b7ef3c4f1675e9574613e4065 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceNodeCoordinates.lean @@ -0,0 +1,65 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ScaledOriginalTail +import OAI.NumberTheory.Jacobsthal.Estimates.SourceLowRemoval + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceNodeCoordinates + +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeBinMembership +open RegeneratingInverseBands ArrivalKernelGeometry SourceLowRemoval SourceSuccessfulTail +open InvariantInverseWeights DerivativeWeights + +theorem node_gap_eq {B : ℝ} {start : Node} (hs : Valid start.side start.ratio) + (hcons : Consistent start) (hcut : start.cutoff=B) : start.gap=B*start.ratio := by + have he : start.cutoff=start.gap/start.ratio := hcons + rw [hcut] at he + exact ((eq_div_iff (valid_pos hs).ne').mp he).symm + +theorem source_node_bounds {B : ℝ} (hB : 0 < B) (start : Node) + (hi : start.side=.even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hcons : Consistent start) (hcut : start.cutoff=B) : + Valid start.side start.ratio ∧ 0 < start.gap ∧ B ≤ start.gap ∧ start.gap ≤ (23/10:ℝ)*B := by + have hs : Valid start.side start.ratio := by rw [hi]; change 198/100 ≤ start.ratio; linarith + have he := node_gap_eq hs hcons hcut + refine ⟨hs,?_,?_,?_⟩ + · rw [he]; exact mul_pos hB (valid_pos hs) + · nlinarith + · nlinarith + +theorem source_currentExponent {start : Node} (hr : 0 < start.gap) + (hs : Valid start.side start.ratio) (hcons : Consistent start) : + currentExponent (Real.log start.gap) (FlaggedSourceStart.sourceCostState hs)=start.cutoff := by + unfold currentExponent + rw [FlaggedSourceStart.source_gap hr hs] + change start.gap/stateRatio (FlaggedSourceStart.typedState start.side start.ratio hs)=start.cutoff + rw [FlaggedSourceStart.typedState_ratio] + exact hcons.symm + +theorem node_scale_upper {B : ℝ} (hB : 0 < B) (start : Node) + (hi : start.side=.even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hcons : Consistent start) (hcut : start.cutoff=B) : + start.gap^2/weight start.side start.ratio ≤ scaleConstant*B^2 := by + obtain ⟨hs,hr,_,_⟩ := source_node_bounds hB start hi h199 h23 hcons hcut + obtain ⟨s,hsv,hcost⟩ := even_source_cost_state hs hi + have hcurrent := source_currentExponent hr hs hcons + rw [hcost,hcut] at hcurrent + have h := (source_scale_upper hB s (by simpa only [hsv] using h23) hcurrent).1 + have hweight : stateWeight (.inl s)=weight start.side start.ratio := by + rw [hi] + change phiEven s.1=phiEven start.ratio + rw [hsv] + rw [Real.exp_log hr,hweight] at h + exact h + +end NumberTheoryLean.SourceNodeCoordinates + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceParentBin.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceParentBin.lean new file mode 100644 index 0000000000000000000000000000000000000000..07825f875f9bc49462c4f48d9193b49efb17de91 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceParentBin.lean @@ -0,0 +1,88 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeMarginalRecursion + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceParentBin + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeSideSupport PrimeGridGeometry PrimeGridKernel +open PrimeMarginalRecursion DerivativeWeights + +noncomputable def index (m : ℕ) (start : Node) : ℕ := ⌊start.ratio*(m:ℝ)⌋₊ +noncomputable def initialConstant : ℝ := 1/phiEven (23/10) + +theorem initialConstant_pos : 0 < initialConstant := by + apply one_div_pos.mpr + exact phiEven_pos (by norm_num) + +theorem source_cell {m : ℕ} (hm : 1 ≤ m) (start : Node) (hs : 0 ≤ start.ratio) : + start.ratio ∈ Ico (point m (index m start)) (point m (index m start+1)) := by + have hm0 : (0:ℝ) < m := by exact_mod_cast (show 0 < m by omega) + have hlo := Nat.floor_le (mul_nonneg hs hm0.le) + have hhi := Nat.lt_floor_add_one (start.ratio*(m:ℝ)) + constructor + · exact (div_le_iff₀ hm0).mpr hlo + · apply (lt_div_iff₀ hm0).mpr + simpa only [Nat.cast_add,Nat.cast_one,index] using hhi + +theorem source_left_valid {m : ℕ} (hm : 1 ≤ m) (hsmall : width m ≤ 1/100) + (start : Node) (hs : (199/100:ℝ) ≤ start.ratio) : + Valid .even (point m (index m start)) := by + have hcell := source_cell hm start (by linarith) + rw [point_succ] at hcell + change 198/100 ≤ point m (index m start) + linarith [hcell.2] + +theorem source_inverse_weight {m : ℕ} (hm : 1 ≤ m) (hsmall : width m ≤ 1/100) + (start : Node) (hlo : (199/100:ℝ) ≤ start.ratio) (hhi : start.ratio ≤ 23/10) : + 1/weight .even (point m (index m start)) ≤ initialConstant := by + have hu := source_left_valid hm hsmall start hlo + have hEnd : Valid .even (23/10:ℝ) := by norm_num [Valid] + have hcell := (source_cell hm start (by linarith)).1 + have hphi := TwoStepDensityBounds.weight_antitone hu hEnd (hcell.trans hhi) + exact one_div_le_one_div_of_le (weight_pos hEnd) hphi + +variable {w ell S : ℝ} {start : Node} + +theorem source_coverage {m : ℕ} (hm : 1 ≤ m) (hsmall : width m ≤ 1/100) + (hi : start.side = .even) (hs : (199/100:ℝ) ≤ start.ratio) (j : ℕ) : + ∀ᵐ p ∂pathLaw w ell S start 0, coveredParents m j .even {index m start} p := by + change ∀ᵐ p ∂Measure.dirac (some (History.empty : History w ell S start)), coveredParents m j .even {index m start} p + apply (ae_dirac_iff (show MeasurableSet {p | coveredParents m j .even {index m start} p} from trivial)).mpr + refine ⟨hi,?_⟩ + intro _ + exact ⟨index m start,Finset.mem_singleton_self _,source_cell hm start (by linarith),source_left_valid hm hsmall start hs⟩ + +theorem source_grid_mass {m : ℕ} (hm : 1 ≤ m) (hs : 0 ≤ start.ratio) : + mass w ell S start m 0 (index m start) = 1 := by + have hcell : some (History.empty : History w ell S start) ∈ bin m (index m start) := source_cell hm start hs + change Measure.dirac (some (History.empty : History w ell S start)) (bin m (index m start)) = 1 + rw [Measure.dirac_apply' _ (bin_measurable _ _),indicator_of_mem hcell,Pi.one_apply] + +theorem bin_empty_above (hsS : start.ratio ≤ S) {m j : ℕ} (hhigh : S < point m j) : + (bin (w:=w) (ell:=ell) (S:=S) (start:=start) m j) = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro p hp + cases p with + | none => exact False.elim hp + | some g => + have hcap : g.node.ratio ≤ S := terminal_ratio_le hsS g.admissible + exact ((mem_bin g m j).mp hp).1.not_gt (hcap.trans_lt hhigh) + +theorem mass_zero_above (hsS : start.ratio ≤ S) {m j : ℕ} (hhigh : S < point m j) (n : ℕ) : + mass w ell S start m n j = 0 := by + rw [mass,bin_empty_above hsS hhigh,measure_empty] + +end NumberTheoryLean.SourceParentBin + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceRawBoxFactory.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceRawBoxFactory.lean new file mode 100644 index 0000000000000000000000000000000000000000..c604f20eda805f28da387981cc393b84f0e3138d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceRawBoxFactory.lean @@ -0,0 +1,295 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.WeightedTwoExceptions +import OAI.NumberTheory.Jacobsthal.Paths.OutsideExceptionsWitness + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GeometricCandidateCount +open FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport +open SafeSubsetBoxGeometry GeometricBoxImages BoundedCandidateCount +open LogarithmicBinScale LogarithmicBinLabels + +theorem geometric_candidate_card {w top xi B C K L alpha beta a M X : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 1 ≤ C) (hlog : 1 ≤ Real.log w) + (hcomp : Real.log B ≤ 2*Real.log w) (hB : 3 ≤ B) (ha0 : 0 ≤ a) + (Y : ℕ) (hY : 0 < Y) (z : Node) (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) + (hi : z.side=.even) (h199 : 199/100 ≤ z.ratio) (hz : Consistent z) (hcut : z.cutoff=B) (hclosed : z.closed=true) + (hpower : w^B=top) (m : Fin (binCount w top xi) → ℕ) + (hm : m ∈ geometricBoxes hw htop hxi C B K L alpha beta z) : + (candidateBins w top xi Y m M X).card ≤ ⌈M⌉₊ := by + have hsmall : 2*(xi/Real.log w) ≤ 6*(2*C*xi) := by + have hh := div_le_self hxi.le hlog + nlinarith + have hA := geometric_box_anchor hw htop hxi (by linarith : 0 ≤ C) hcomp hsmall z m hm + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hg := source_strong_state hB z hi h199 hz hcut + have hcap : w^z.cutoff=top := by rwa [hcut] + exact candidate_bins_card_le hw htop hxi (by linarith) hcomp ha0 Y hY z hroot hs hz hg hclosed hcap m hA +end NumberTheoryLean.GeometricCandidateCount + + + +namespace NumberTheoryLean.GeometricRangeCandidateUnion +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open GeometricBoxImages GeometricInverseGeometry BoundedEdgeBins ParentCofactorChoices +open JacobsthalSourceScale IsolatedSourceScales SourceNodeCoordinates +open GeometricRangeInverse GeometricCandidateCount CandidateExceptionMass BoundedCandidateCount +open ActualInverseFullBoxMass BoxWitnessFactorization CanonicalSubsetBox IsolatedPowerOrdering ErdosInverseSampleCost +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseBoxApplication +open LogarithmicBinScale LogarithmicBinEndpoints +open scoped Topology +attribute [local instance] Classical.propDecidable + +theorem geometric_range_candidate_union (C Kstar aStar alpha delta sigma : ℝ) + (hC : 1 ≤ C) (hKstar : 0 ≤ Kstar) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (halpha : 0 < alpha) (hd : 0 < delta) (hsigma : 0 < sigma) (hsigma1 : sigma ≤ 1) : + ∃ cp : ℝ,0 < cp ∧ ∃ F : ℕ,∃ xi₀ : ℝ,0 < xi₀ ∧ xi₀ ≤ 1 ∧ + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ xi₀ → ∀ᶠ top : ℝ in atTop, + ∃ hw : 1 < ErdosInverseBoxHeight.sourceW top,∃ htop : ErdosInverseBoxHeight.sourceW top < top, + ∀ R L : ℝ,∀ z : Node,z.side=.even → 199/100 ≤ z.ratio → Consistent z → + z.cutoff=ErdosInverseBoxHeight.sourceB top → z.closed=true → + z.gap=Real.log (ErdosInverseBoxHeight.sourceY top:ℝ)/Real.log (ErdosInverseBoxHeight.sourceW top)-aStar+2 → + ∀ m ∈ geometricBoxes hw htop hxi C (ErdosInverseBoxHeight.sourceB top) R L alpha (1/100) z, + ∃ i : Fin (binCount (ErdosInverseBoxHeight.sourceW top) top xi),m i=1 ∧ + top^alpha ≤ lower (ErdosInverseBoxHeight.sourceW top) top xi i ∧ + lower (ErdosInverseBoxHeight.sourceW top) top xi i ≤ top^((1:ℝ)/100) ∧ + (∀ j : Fin (binCount (ErdosInverseBoxHeight.sourceW top) top xi), + boundedEdgeBin (ErdosInverseBoxHeight.sourceW top) top xi (ErdosInverseBoxHeight.sourceY top) m + (2*Kstar+3) (2*Kstar+3) j → ∀ residue : ℕ → ℕ, + j < i ∧ m j=1 ∧ + let cm := parentCofactorMultiplicity m i j + let w := ErdosInverseBoxHeight.sourceW top + SourceInverseConclusion (ErdosInverseBoxHeight.sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) + residue delta (SmallSieveFinite.smallEuler ⌊w⌋₊) (cofactorScale top xi cm) + (lower w top xi i) (ErdosInverseBoxHeight.sourceZ top) cp sigma F + (actualBins top xi i) (cofactorChoices (actualBins top xi) cm) (actualBins top xi j) ∧ + selectionWitnessMass (actualBins top xi) m i j + (actualWitness (ErdosInverseBoxHeight.sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊w⌋₊) (actualBins top xi i) (cofactorScale top xi cm) + (lower w top xi i) (ErdosInverseBoxHeight.sourceZ top) cp) ≤ sigma*selectionMass (actualBins top xi) m ) ∧ ∀ residue : ℕ → ℕ, + someWitnessMass (actualBins top xi) m i + (candidateBins (ErdosInverseBoxHeight.sourceW top) top xi (ErdosInverseBoxHeight.sourceY top) m (2*Kstar+3) (2*Kstar+3)) + (fun j => actualWitness (ErdosInverseBoxHeight.sourceY top) + (LargePrimeDeletion.cutoffPrimes ⌊ErdosInverseBoxHeight.sourceW top⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊ErdosInverseBoxHeight.sourceW top⌋₊) (actualBins top xi i) + (cofactorScale top xi (parentCofactorMultiplicity m i j)) (lower (ErdosInverseBoxHeight.sourceW top) top xi i) + (ErdosInverseBoxHeight.sourceZ top) cp) ≤ (⌈2*Kstar+3⌉₊:ℝ)*sigma*selectionMass (actualBins top xi) m := by + obtain ⟨cp,hcp,F,xi₀,hxi₀,hxi₀1,hCore⟩ := geometric_range_inverse C Kstar aStar alpha delta sigma + hC hKstar ha ha1 halpha hd hsigma hsigma1 + refine ⟨cp,hcp,F,xi₀,hxi₀,hxi₀1,?_⟩ + intro xi hxi hx + have hBT := sourceB_tendsto.comp Real.tendsto_log_atTop + filter_upwards [hCore xi hxi hx,hBT.eventually_ge_atTop 3, + Real.tendsto_log_atTop.eventually source_scale_eventually,ErdosInverseBoxHeight.source_B_bounds] + with top hCore hB3 hscale hbounds + obtain ⟨hw,htop,hData⟩ := hCore + change 3 ≤ ErdosInverseBoxHeight.sourceB top at hB3 + have hlog : 1 ≤ Real.log (ErdosInverseBoxHeight.sourceW top) := by + have hh := Real.log_le_log (Real.exp_pos 1) hbounds.1 + simpa only [Real.log_exp] using hh + have hpow : (ErdosInverseBoxHeight.sourceW top)^(ErdosInverseBoxHeight.sourceB top)=top := + (sourceW_pow_sourceB hw).trans (Real.exp_log ((zero_lt_one.trans hw).trans htop)) + refine ⟨hw,htop,?_⟩ + intro R L z hi h199 hz hcut hclosed hroot m hm + obtain ⟨i,hmi,hilo,hihi,hStep⟩ := hData R L z hi h199 hz hcut hclosed hroot m hm + refine ⟨i,hmi,hilo,hihi,hStep,?_⟩ + intro residue + have hs : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hY : 0 < ErdosInverseBoxHeight.sourceY top := by + by_contra! hn + have hzero : ErdosInverseBoxHeight.sourceY top=0 := by omega + rw [hzero,Nat.cast_zero,Real.log_zero,zero_div] at hroot + have hg := node_gap_eq hs hz hcut + nlinarith + have hCard := geometric_candidate_card (M:=2*Kstar+3) (X:=2*Kstar+3) hw htop hxi hC hlog hscale.2.2.2.2 + hB3 ha.le (ErdosInverseBoxHeight.sourceY top) hY z hroot hi h199 hz hcut hclosed hpow m hm + apply some_witness_mass_card_bound _ _ _ _ _ sigma hsigma.le _ hCard + intro j hj + exact (hStep j (Finset.mem_filter.mp hj).2 residue).2.2.2 +end NumberTheoryLean.GeometricRangeCandidateUnion + + + +namespace ErdosVarianceEligible +open NumberTheoryLean PrimeHistories GeometricRegularWords ActualCountErrorEdges ErdosCofactorChoices ErdosSubsetWord + LogarithmicBinScale + +def unwitnessedSelection {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs C B K L alpha beta eps : ℝ) (residue : ℕ → ℕ) (z : Node) (Q : Finset ℚ) + (f : Fin (binCount w top xi) → Finset ℕ) : Prop := + descendingWord f ∈ geometricWords hw htop hxi C B K L alpha beta z ∧ + eps < |wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) (descendingWord f)| ∧ + ¬eligibleWordWitness Y w Cs residue Q (descendingWord f) + +end ErdosVarianceEligible + + + +open _root_.Filter +namespace ErdosVarianceFactory +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport + SafeSubsetBoxGeometry GeometricBoxImages GeometricCandidateCount GeometricRangeCandidateUnion + GeometricRegularWords BoundedEdgeBins BoundedCandidateCount CandidateExceptionMass + ParentCofactorChoices ParentTailPartition SingletonBinSelection TwoPrimeObservableSum CanonicalSubsetBox + RawBoxRationalWitness ErdosCofactorChoices ErdosSubsetWord ErdosVarianceWeighted ErdosVarianceEligible + ErdosInverseBoxHeight ErdosInverseEuler ErdosInverseCells ErdosInverseCounts ErdosInverseAlignment + ErdosInverseBoxApplication ErdosInverseSampleCost + LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinPartition +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem source_raw_box_factory (C K aStar alpha eps tau Cmin : ℝ) + (hC : 1 ≤ C) (hK : 3 ≤ K) (ha : 0 < aStar) (ha1 : aStar ≤ 1) + (halpha : 0 < alpha) (heps : 0 < eps) (htau : 0 < tau) : + ∃ Kstar : ℝ,K+10 < Kstar ∧ ∃ NQ : ℕ,∃ Cs : ℝ,0 < Cs ∧ Cmin ≤ Cs ∧ 2*Kstar+4 ≤ Cs ∧ + ∃ xi0 : ℝ,0 < xi0 ∧ xi0 ≤ 1 ∧ + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ xi0 → ∀ᶠ top : ℝ in atTop, + ∃ hw : 1 < sourceW top,∃ htop : sourceW top < top, + ∀ z : Node,z.side = .even → 199/100 ≤ z.ratio → Consistent z → + z.cutoff = sourceB top → z.closed = true → + z.gap = Real.log (sourceY top : ℝ)/Real.log (sourceW top)-aStar+2 → + ∀ residue : ℕ → ℕ, + ∀ m ∈ geometricBoxes hw htop hxi C (sourceB top) K (2*Kstar+5) alpha (1/100) z, + ∃ Q : Finset ℚ,Q.card ≤ NQ ∧ + (∑ f ∈ (selections (globalBins (sourceW top) top xi) m).filter + (unwitnessedSelection hw htop hxi (sourceY top) Cs C (sourceB top) K (2*Kstar+5) alpha (1/100) eps residue z Q), + (selectionProduct f : ℝ)⁻¹) ≤ tau*selectionMass (globalBins (sourceW top) top xi) m := by + obtain ⟨Kstar,B0,w0,hKs,hB0,_hw0,hrecent⟩ := geometric_selection_recent_witness K eps hK heps + have hKs0 : 0 ≤ Kstar := by linarith + let M := 2*Kstar+3 + have hM : 0 ≤ M := by dsimp [M];linarith + have hH : 0 < ⌈2*Kstar+10⌉₊ := by + have hh := Nat.le_ceil (2*Kstar+10) + by_contra! hn + have he : ⌈2*Kstar+10⌉₊ = 0 := by omega + rw [he,Nat.cast_zero] at hh + linarith + let delta := eps/(4*(⌈2*Kstar+10⌉₊ : ℝ)) + have hdelta : 0 < delta := by dsimp [delta];positivity + let sigma := min 1 (tau/(2*((⌈M⌉₊ : ℝ)+1))) + have hsigma : 0 < sigma := lt_min zero_lt_one (by positivity) + have hsigma1 : sigma ≤ 1 := min_le_left _ _ + have hsigmaBudget : (⌈M⌉₊ : ℝ)*sigma ≤ tau/2 := by + have hh := (le_div_iff₀ (show 0 < 2*((⌈M⌉₊ : ℝ)+1) by positivity)).mp + (min_le_right (1 : ℝ) (tau/(2*((⌈M⌉₊ : ℝ)+1)))) + change sigma*(2*((⌈M⌉₊ : ℝ)+1)) ≤ tau at hh + nlinarith + obtain ⟨cp,_hcp,F,xiI,hxiI,hxiI1,hInverse⟩ := geometric_range_candidate_union C Kstar aStar alpha delta sigma + hC hKs0 ha ha1 halpha hdelta hsigma hsigma1 + let NQ := ⌈M⌉₊*F + let requiredCs := max Cmin (2*Kstar+4) + obtain ⟨Cs,hCs,hCsReq,xiH,hxiH,_hxiH1,hHard⟩ := + geometric_selection_hard_mass C aStar alpha eps (tau/2) requiredCs NQ hC ha halpha heps (by positivity) + have hCsMin : Cmin ≤ Cs := (le_max_left _ _).trans hCsReq + have hCsK : 2*Kstar+4 ≤ Cs := (le_max_right _ _).trans hCsReq + have hCpos : 0 < C := by linarith + let xi0 := min xiI (min xiH (1/(2*C))) + have hxi0 : 0 < xi0 := lt_min hxiI (lt_min hxiH (by positivity)) + have hxi01 : xi0 ≤ 1 := (min_le_left _ _).trans hxiI1 + refine ⟨Kstar,hKs,NQ,Cs,hCs,hCsMin,hCsK,xi0,hxi0,hxi01,?_⟩ + intro xi hxi hxib + have hxiInv : xi ≤ xiI := hxib.trans (min_le_left _ _) + have hxiHard : xi ≤ xiH := (hxib.trans (min_le_right _ _)).trans (min_le_left _ _) + have hxiDelta : xi ≤ 1/(2*C) := (hxib.trans (min_le_right _ _)).trans (min_le_right _ _) + have hDelta : 2*C*xi ≤ 1 := by + have hh := (le_div_iff₀ (show 0 < 2*C by positivity)).mp hxiDelta + nlinarith + have hxi1 := hxib.trans hxi01 + have hBT := JacobsthalSourceScale.sourceB_tendsto.comp Real.tendsto_log_atTop + filter_upwards [hInverse xi hxi hxiInv,hHard xi hxi hxiHard, + outside_exceptions_eligible_word C M (by linarith : 0 ≤ C) hM, + hBT.eventually_ge_atTop B0,sourceW_tendsto_atTop.eventually_ge_atTop w0, + Real.tendsto_log_atTop.eventually JacobsthalSourceScale.source_scale_eventually,source_B_bounds] + with top hInvTop hHardTop hOutside hB hwMin hscale hWbounds + obtain ⟨hw,htop,hInvData⟩ := hInvTop + obtain ⟨_hwH,_htopH,hHardData⟩ := hHardTop + have hB3 : 3 ≤ sourceB top := hB0.trans hB + have hcomp : Real.log (sourceB top) ≤ 2*Real.log (sourceW top) := hscale.2.2.2.2 + have hlog : 1 ≤ Real.log (sourceW top) := by + simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos 1) hWbounds.1 + have hsmall : 2*(xi/Real.log (sourceW top)) ≤ 6*(2*C*xi) := by + have hh := div_le_self hxi.le hlog + nlinarith + have hpower : (sourceW top)^(sourceB top) = top := + (JacobsthalSourceScale.sourceW_pow_sourceB hw).trans (Real.exp_log ((zero_lt_one.trans hw).trans htop)) + refine ⟨hw,htop,?_⟩ + intro z heven h199 hz hcut hclosed hroot residue m hm + have hs : Valid z.side z.ratio := by rw [heven];change 198/100 ≤ z.ratio;linarith + have hStrong := source_strong_state hB3 z heven h199 hz hcut + have hY : 0 < sourceY top := by + by_contra! hn + have hzero : sourceY top = 0 := by omega + rw [hzero,Nat.cast_zero,Real.log_zero,zero_div] at hroot + linarith [hStrong.1] + have hcap : (sourceW top)^z.cutoff = top := by rwa [hcut] + have hanchor := geometric_box_anchor hw htop hxi (by linarith : 0 ≤ C) hcomp hsmall z m hm + obtain ⟨i,hmi,hRi,_hRiUpper,hStep,hInvMass⟩ := + hInvData K (2*Kstar+5) z heven h199 hz hcut hclosed hroot m hm + let P := globalBins (sourceW top) top xi + let J := candidateBins (sourceW top) top xi (sourceY top) m M M + let S := fun j => cofactorScale top xi (parentCofactorMultiplicity m i j) + let R := lower (sourceW top) top xi i + let Q := rawBoxList P i J residue S R (sourceZ top) cp + have hJ : ∀ j ∈ J,boundedEdgeBin (sourceW top) top xi (sourceY top) m M M j ∧ j < i := by + intro j hj + have hb := (Finset.mem_filter.mp hj).2 + exact ⟨hb,(hStep j hb residue).1⟩ + have hInv : ∀ j ∈ J,SourceInverseConclusion (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) + residue delta (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) (S j) R (sourceZ top) cp sigma F + (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j) := + fun j hj => (hStep j (hJ j hj).1 residue).2.2.1 + have hJcard : J.card ≤ ⌈M⌉₊ := geometric_candidate_card hw htop hxi hC hlog hcomp hB3 ha.le + (sourceY top) hY z hroot heven h199 hz hcut hclosed hpower m hm + have hQcard : Q.card ≤ NQ := + (raw_box_list_card P m i J (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) + residue delta (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) S R (sourceZ top) cp sigma F hInv).trans + (Nat.mul_le_mul_right F hJcard) + refine ⟨Q,hQcard,?_⟩ + let EInv := fun f => ∃ j ∈ J,actualWitness (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) (P i) (S j) R (sourceZ top) cp + (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j) + let EHard := hardSelection Q top R (width (sourceW top) top xi i) residue i Cs eps + let E := unwitnessedSelection hw htop hxi (sourceY top) Cs C (sourceB top) K (2*Kstar+5) alpha (1/100) eps residue z Q + have hsub : ∀ f ∈ selections P m,E f → EInv f ∨ EHard f := by + intro f hf hE + by_cases hEI : EInv f + · exact Or.inl hEI + by_cases hEH : EHard f + · exact Or.inr hEH + have hgeom := hE.1 + have hbad := hE.2.1 + obtain ⟨j,hjb,hEdge⟩ := hrecent (sourceB top) (sourceW top) top hB hwMin hw htop xi hxi C hC hcomp + aStar alpha (1/100) ha.le ha1 (sourceY top) hY z hroot heven h199 hz hcut hclosed hpower + residue m f hf hgeom hbad + have hjJ : j ∈ J := Finset.mem_filter.mpr ⟨Finset.mem_univ _,hjb⟩ + have hWitness := hEdge i hmi (hJ j hjJ).2 + have hEligible := hOutside xi hxi hxi1 hDelta hw htop K aStar M ha.le z hY hroot hs hz hStrong hclosed hcap + m hanchor f hf i hmi J hJ residue delta cp sigma Cs eps F hInv ⟨j,hjJ,hWitness⟩ hbad hEI hEH + exact False.elim (hE.2.2 hEligible) + have hInvBound : (∑ f ∈ (selections P m).filter EInv,(selectionProduct f : ℝ)⁻¹) ≤ + (⌈M⌉₊ : ℝ)*sigma*selectionMass P m := hInvMass residue + have hHardBound : (∑ f ∈ (selections P m).filter EHard,(selectionProduct f : ℝ)⁻¹) ≤ + (tau/2)*selectionMass P m := + hHardData K (2*Kstar+5) z heven h199 hz hcut hclosed hroot m hm i hmi hRi residue Q hQcard + have hmass0 : 0 ≤ selectionMass P m := Finset.sum_nonneg (fun _ _ => by positivity) + have hbudget := mul_le_mul_of_nonneg_right hsigmaBudget hmass0 + have hbound := weighted_two_exceptions (selections P m) (fun f => (selectionProduct f : ℝ)⁻¹) E EInv EHard + (fun _ _ => by positivity) hsub + change (∑ f ∈ (selections P m).filter E,(selectionProduct f : ℝ)⁻¹) ≤ tau*selectionMass P m + have hfI := Finset.filter_congr_decidable (selections P m) EInv (fun f => Classical.propDecidable (EInv f)) + simp only [hfI] at hbound + have hsummed := hbound.trans (add_le_add hInvBound hHardBound) + apply hsummed.trans + calc + _ ≤ (tau/2)*selectionMass P m+(tau/2)*selectionMass P m := add_le_add hbudget le_rfl + _ = _ := by ring + +end ErdosVarianceFactory + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceRefinedCell.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceRefinedCell.lean new file mode 100644 index 0000000000000000000000000000000000000000..9215c9804d7947bfb3d4326146225f5a0148bfdf --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/SourceRefinedCell.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RefinedDiscardBound +import OAI.NumberTheory.Jacobsthal.Estimates.RefinementRewardMargin +import OAI.NumberTheory.Jacobsthal.Sieve.RefinementPrimeCongruences + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +open scoped Topology +namespace ErdosInverseRefinement +open ErdosInverseCells ErdosInverseSampling ErdosInversePrimeBin ErdosInverseEuler ErdosInverseBoxHeight + +theorem source_refined_cell (K gamma : ℝ) (h : ℕ) (hK : 0 ≤ K) (hg : 0 < gamma) : + ∀ᶠ z : ℝ in atTop,∀ U theta : ℝ,0 ≤ U → U ≤ (sourceW z)^K → 0 ≤ theta → theta ≤ 1 → + ∀ (s : Sample (primeBin U theta) h) (P C : Finset ℕ) (a : ℕ → ℕ) + (witness : (ℕ × ℕ) → ℕ → Prop) (S : ℝ), + 0 < P.card → 0 < S → S/sourceZ z ≤ (C.card : ℝ) → + gamma/2 ≤ selectedFraction (P.product C) (primeBin U theta) witness h s → + ∃ i : RefinementLabel (sampleModulus (primeBin U theta) h s), + S/(sourceZ z)^3 ≤ ((refinementCell C a (sampleModulus (primeBin U theta) h s) i).card : ℝ) ∧ + (refinementCell C a (sampleModulus (primeBin U theta) h s) i).Nonempty ∧ + (gamma/4)*((refinementCell C a (sampleModulus (primeBin U theta) h s) i).card : ℝ) < + ∑ q ∈ refinementCell C a (sampleModulus (primeBin U theta) h s) i, + rowReward P (primeBin U theta) witness h s q := by + filter_upwards [source_sample_modulus_square K 1 h hK zero_lt_one, + sourceZ_tendsto_atTop.eventually_ge_atTop (8/gamma)] with z hmod hZlarge + intro U theta hU0 hUtop htheta htheta1 s P C a witness S hP hS hC hreward + let W := sampleModulus (primeBin U theta) h s + have hWpos : 0 < W := sampleModulus_pos _ h s + (fun u hu => ((mem_primeBin hU0 htheta u).mp hu).1.pos) + let : NeZero W := ⟨hWpos.ne'⟩ + have hZ : 0 < sourceZ z := Real.exp_pos _ + have hCpos : 0 < C.card := by exact_mod_cast (div_pos hS hZ).trans_le hC + have hInv : 1/sourceZ z ≤ gamma/8 := by + apply (div_le_iff₀ hZ).mpr + have hh := (div_le_iff₀ hg).mp hZlarge + nlinarith + have hWsq : (W : ℝ)^2 ≤ sourceZ z := by + simpa only [Real.rpow_one] using hmod U theta hU0 hUtop htheta htheta1 s + have hDiscard := refined_discard_bound C a W S (sourceZ z) gamma hS.le hZ hC hWsq hInv + have hMass : (gamma/2)*(C.card : ℝ) ≤ ∑ q ∈ C,rowReward P (primeBin U theta) witness h s q := by + rw [rowReward_sum P C (primeBin U theta) witness h s hP hCpos] + exact mul_le_mul_of_nonneg_right hreward (Nat.cast_nonneg _) + obtain ⟨i,hlarge,hdense⟩ := dense_fiber_after_count_discard C (refinementLabel a W) (S/(sourceZ z)^3) + (gamma/2) (gamma/4) (gamma/8) hCpos (by positivity) (by linarith) + (rowReward P (primeBin U theta) witness h s) + (fun q _ => (rowReward_bounds P (primeBin U theta) witness h s q hP).2) hMass hDiscard + have hnR : (0 : ℝ) < (refinementCell C a W i).card := + (div_pos hS (pow_pos hZ 3)).trans_le hlarge + have hn : 0 < (refinementCell C a W i).card := by exact_mod_cast hnR + exact ⟨i,hlarge,Finset.card_pos.mp hn,hdense⟩ + +end ErdosInverseRefinement + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/StationaryFibres.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/StationaryFibres.lean new file mode 100644 index 0000000000000000000000000000000000000000..25ebdbee32703578e3a972d345ae8afac8a81bc5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/StationaryFibres.lean @@ -0,0 +1,53 @@ +import OAI.NumberTheory.Jacobsthal.Sieve.ResidueFibres + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosKloosterman.PrimePower + +attribute [local instance] Classical.decEq + +theorem reduction_apply_val (n d : ℕ) [NeZero n] [NeZero d] (x : ZMod (n*d)) : + reduction n d x = (x.val : ZMod d) := by + nth_rw 1 [← x.natCast_zmod_val] + simp [reduction] + +noncomputable def quadraticUnitRoots (d : ℕ) [NeZero d] (a b : ZMod d) : Finset (ZMod d) := + Finset.univ.filter fun x => IsUnit x ∧ a * x^2 = b + +theorem mem_stationary_iff_reduction (n d : ℕ) [NeZero n] [NeZero d] + (a b : ZMod (n*d)) (u : (ZMod (n*d))ˣ) : + u ∈ stationaryUnits (n : ZMod (n*d)) a b ↔ + reduction n d (u : ZMod (n*d)) ∈ + quadraticUnitRoots d (reduction n d a) (reduction n d b) := by + have hu : IsUnit (reduction n d (u : ZMod (n*d))) := + (u.isUnit).map (reduction n d) + simp only [stationaryUnits, Finset.mem_filter, Finset.mem_univ, true_and, + quadraticUnitRoots, hu] + rw [stationary_iff_quadratic, mul_annihilator_iff n d (NeZero.pos n), + ← reduction_apply_val] + simp only [map_sub, map_mul, map_pow, sub_eq_zero] + +theorem stationary_card_le_root_card_mul (n d : ℕ) [NeZero n] [NeZero d] + (a b : ZMod (n*d)) : + (stationaryUnits (n : ZMod (n*d)) a b).card ≤ + (quadraticUnitRoots d (reduction n d a) (reduction n d b)).card * n := by + let S := quadraticUnitRoots d (reduction n d a) (reduction n d b) + rw [← reduction_preimage_card n d S] + apply Finset.card_le_card_of_injOn (fun u : (ZMod (n*d))ˣ => (u : ZMod (n*d))) + · intro u hu + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, + (mem_stationary_iff_reduction n d a b u).mp hu⟩ + · intro u _ v _ huv + exact Units.val_injective huv + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/StrongReferenceTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/StrongReferenceTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a905dd148937e05e08f9692099ed65975a0c7cb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/StrongReferenceTransport.lean @@ -0,0 +1,119 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CrossingBandGeometry +import OAI.NumberTheory.Jacobsthal.Paths.ReferenceHistoryAdmission + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.StrongReferenceTransport +open FinitePathGeometry PrimeHistories PrimeTiltGeometry PrimeBinMembership ActualPrimeHigh +open ReferenceAdmission ReferenceHistoryAdmission LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure +attribute [local instance] Classical.propDecidable + +def StrongState (z : Node) : Prop := 2 ≤ z.gap ∧ (z.side=.even → z.cutoff+2 ≤ z.gap) + +theorem strong_child_uncapped {w ell : ℝ} (hw : 1 < w) (hell : 0 ≤ ell) {z : Node} + (hs : Valid z.side z.ratio) (hz : Consistent z) (p : ℕ) (hp : p.Prime) + (hx : ell < primeExponent w p) (hcap : capGuard z.closed z.cutoff (primeExponent w p)) + (ha : childAdmitted z.side z.gap (primeExponent w p)) : p ∈ uncappedChildren w ell z := by + have hx0 : 0 < primeExponent w p := hell.trans_lt hx + have hxp : primeExponent w p ≤ z.cutoff := by + cases hcl : z.closed with + | false => have hh : primeExponent w p < z.cutoff := by simpa [capGuard,hcl] using hcap + exact hh.le + | true => simpa [capGuard,hcl] using hcap + have hp0 : (0:ℝ) < p := by exact_mod_cast hp.pos + have hpLe := (exponent_le_iff hw hp0).mp hxp + have hprime := Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff + (Real.rpow_pos_of_pos (zero_lt_one.trans hw) z.cutoff).le).mpr hpLe,hp⟩ + apply Finset.mem_filter.mpr + refine ⟨hprime,hx,hcap,?_⟩ + have hlo := cap_lower_ratio hs hz hx0 hcap + cases hi : z.side with + | even => exact hlo + | odd => + rw [hi] at ha + apply max_le + · have h2 := (le_max_left (2*primeExponent w p) (primeExponent w p+2)).trans ha + have hd : 3 ≤ z.gap/primeExponent w p := (le_div_iff₀ hx0).mpr (by linarith) + unfold childRatio + linarith + · exact hlo + +theorem strong_child_state {w : ℝ} {z : Node} {p : ℕ} (hg : StrongState z) + (hx : 0 < primeExponent w p) (hcap : capGuard z.closed z.cutoff (primeExponent w p)) + (ha : childAdmitted z.side z.gap (primeExponent w p)) : StrongState (step w z p) := by + have hxp : primeExponent w p ≤ z.cutoff := by + cases hcl : z.closed with + | false => have hh : primeExponent w p < z.cutoff := by simpa [capGuard,hcl] using hcap + exact hh.le + | true => simpa [capGuard,hcl] using hcap + cases hi : z.side with + | even => + have hh := hg.2 hi + constructor + · change 2 ≤ z.gap-primeExponent w p + linarith + · simp [step,hi,Side.flip] + | odd => + rw [hi] at ha + have hh := (le_max_right (2*primeExponent w p) (primeExponent w p+2)).trans ha + constructor + · change 2 ≤ z.gap-primeExponent w p + linarith + · intro _hside + exact hh + +theorem strong_history_transport {w ell : ℝ} (hw : 1 < w) (hell : 0 ≤ ell) + (z : Node) (ps : List ℕ) (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hD : ps.Pairwise (· > ·)) + (hP : ∀ p ∈ ps,p.Prime ∧ ell < primeExponent w p ∧ capGuard z.closed z.cutoff (primeExponent w p)) + (ha : admitted w z.side z.gap ps) : uncappedAllowed w ell z ps ∧ StrongState (terminal w z ps) := by + induction ps generalizing z with + | nil => exact ⟨trivial,hg⟩ + | cons p ps ih => + have hp := hP p (by simp) + have hc := strong_child_uncapped hw hell hs hz p hp.1 hp.2.1 hp.2.2 ha.1 + have hone : uncappedAllowed w ell z [p] := ⟨hc,trivial⟩ + obtain ⟨U,_hU,hU⟩ := (uncapped_iff_exists_ceiling w ell z [p]).mp hone + have hchild := ((allowed_cons w ell U z p []).mp hU).1 + have hr : 0 < z.gap := by linarith [hg.1] + have hvalid := child_valid hs hchild + have hcons := step_consistent hell hr hs hchild + have hstrong := strong_child_state hg (hell.trans_lt hp.2.1) hp.2.2 ha.1 + have htailP : ∀ q ∈ ps,q.Prime ∧ ell < primeExponent w q ∧ + capGuard (step w z p).closed (step w z p).cutoff (primeExponent w q) := by + intro q hq + have hh := hP q (by simp [hq]) + refine ⟨hh.1,hh.2.1,?_⟩ + have hqp : q < p := (List.pairwise_cons.mp hD).1 q hq + have hq0 : (0:ℝ) exact zero_le + | some h => + cases y with + | inr u => exact False.elim hgood + | inl z => + have hnum : 4*(n:ℝ)*mesh ≤ 1 := by + have hnR : (n:ℝ) ≤ (N:ℝ) := by exact_mod_cast hnN + exact (mul_le_mul_of_nonneg_right (by linarith : 4*(n:ℝ) ≤ 4*(N:ℝ)) hm.le).trans hclock + exact hcompare w ell S hell hS3 start hr hs hsS (Real.log start.gap) mesh n M hnum hsmall h z hgood harr c hc + · rw [cleanReward,ite_eq_right hb] + exact zero_le + have hone : ∀ n,1 ≤ n → n ≤ N → + (∫⁻ q,cleanReward c (3*((M:ℝ)+1)) q ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal 27*(∫⁻ y,liftReward F y + ∂((continuousChain (Real.log start.gap) ell S)^n) (.inl (FlaggedSourceStart.sourceCostState hs))) := by + intro n hn hnN + have he := FlaggedSourceStart.sourceLaw_continuous hw hell hS0 hS hr hs hsS mesh n + rw [CouplingData.sourceLaw_eq hw hell hS0 hS hr hs hsS] at he + calc + _ ≤ ∫⁻ q,ENNReal.ofReal 27*liftReward F q.1.2 ∂CouplingData.sourceLaw w ell S start hs mesh n := + lintegral_mono_ae (hpoint n hn hnN) + _ = _ := by + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,← he, + lintegral_map (g := fun q : FlagState (JointState w ell S start) => q.1.2) (liftReward_measurable hF) (measurable_snd.comp measurable_fst)] + calc + _ ≤ ∑ n ∈ range N,ENNReal.ofReal 27*(∫⁻ y,liftReward F y + ∂((continuousChain (Real.log start.gap) ell S)^(n+1)) (.inl (FlaggedSourceStart.sourceCostState hs))) := by + apply Finset.sum_le_sum + intro n hn + exact hone (n+1) (by omega) (by have hh := Finset.mem_range.mp hn; omega) + _ ≤ _ := by + rw [← Finset.mul_sum] + exact mul_le_mul_of_nonneg_left (positive_completed_occupation_le _ _ _ hF N _) zero_le + +end NumberTheoryLean.SuccessfulTailTransport + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/ThresholdMeshRate.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ThresholdMeshRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..e04e333669e6563f33fef40d3fadd83b98e60f4d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/ThresholdMeshRate.lean @@ -0,0 +1,59 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SourceThresholdCoupling +import OAI.NumberTheory.Jacobsthal.Sieve.ExponentialMesh + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ThresholdMeshRate +open _root_.Filter SourceThresholdCoupling ExponentialMesh +open scoped Topology + +theorem thresholdPerturbation_le {h : ℝ} (hh : 0 ≤ h) (N : ℕ) + (hsmall : 4*((N:ℝ)+1)*h ≤ 1) : thresholdPerturbation h N ≤ 39*((N:ℝ)+1)*h := by + have hexp := exp_increment (show 0 ≤ 4*((N:ℝ)+1)*h by positivity) hsmall + unfold thresholdPerturbation + nlinarith [mul_nonneg (Nat.cast_nonneg N) hh] + +theorem threshold_mesh_controls {A C κ : ℝ} (hA : 0 ≤ A) (hC : 0 ≤ C) (hκ : 0 < κ) + {eta : ℝ} (heta : 0 < eta) : + ∀ᶠ w : ℝ in atTop,∀ N : ℕ,(N:ℝ) ≤ A*(Real.log w)^3 → + Real.exp (4*((N:ℝ)+1)*mesh κ w) ≤ 4/3 ∧ + C*((N:ℝ)+1)*thresholdPerturbation (mesh κ w) N ≤ eta := by + have hlog : 0 < Real.log (4/3:ℝ) := Real.log_pos (by norm_num) + have hmin : 0 < min 1 (Real.log (4/3:ℝ)) := lt_min (by norm_num) hlog + filter_upwards [(log_power_exp_tendsto (4*(A+1)) 3 hκ).eventually (eventually_le_nhds hmin), + (log_power_exp_tendsto (39*C*(A+1)^2) 6 hκ).eventually (eventually_le_nhds heta), + Real.tendsto_log_atTop.eventually_ge_atTop 1] with w harg herr hL + intro N hN + have hm : 0 ≤ mesh κ w := (mesh_pos κ w).le + have hL3 : 1 ≤ (Real.log w)^3 := one_le_pow₀ hL + have hNp : (N:ℝ)+1 ≤ (A+1)*(Real.log w)^3 := by nlinarith + have harg' : 4*((N:ℝ)+1)*mesh κ w ≤ min 1 (Real.log (4/3:ℝ)) := by + calc + _ ≤ (4*(A+1)*(Real.log w)^3)*Real.exp (-κ*Real.sqrt (Real.log w)) := + mul_le_mul (by nlinarith) (mesh_upper κ w) hm (by positivity) + _ ≤ _ := harg + refine ⟨?_,?_⟩ + · have hh := Real.exp_le_exp.mpr (harg'.trans (min_le_right _ _)) + simpa only [Real.exp_log (by norm_num : (0:ℝ)<4/3)] using hh + · have hpert := thresholdPerturbation_le hm N (harg'.trans (min_le_left _ _)) + have hsq : ((N:ℝ)+1)^2 ≤ (A+1)^2*(Real.log w)^6 := by + have hh := sq_le_sq₀ (show 0 ≤ (N:ℝ)+1 by positivity) (show 0 ≤ (A+1)*(Real.log w)^3 by positivity) |>.mpr hNp + nlinarith + calc + _ ≤ 39*C*((N:ℝ)+1)^2*mesh κ w := by + have hh := mul_le_mul_of_nonneg_left hpert (show 0 ≤ C*((N:ℝ)+1) by positivity) + nlinarith + _ ≤ (39*C*(A+1)^2*(Real.log w)^6)*Real.exp (-κ*Real.sqrt (Real.log w)) := + mul_le_mul (by nlinarith [mul_le_mul_of_nonneg_left hsq (show 0 ≤ 39*C by positivity)]) + (mesh_upper κ w) hm (by positivity) + _ ≤ _ := herr +end NumberTheoryLean.ThresholdMeshRate + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/TwoSidedThresholdGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/TwoSidedThresholdGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..3364fbed3d7ffaaa2d756fd5c7dcb5b6f96417e5 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/TwoSidedThresholdGeometry.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Probability.EvenThresholdEvent + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.TwoSidedThresholdGeometry +open Set MeasureTheory FinitePathGeometry ErdosEvenThreshold + +noncomputable def normalizedSlack (R t : ℝ) : ℝ := thresholdSlack R t/R + +theorem normalizedSlack_eq_min {R t : ℝ} (hR : 0 < R) (ht : 0 < t+1) : + normalizedSlack R t=min ((t-2)/(t+1)) ((t-1)/(t+1)-2/R) := by + rw [normalizedSlack,thresholdSlack,← min_sub_sub_left,← min_div_div_right hR.le] + congr 1 + · unfold nextGap nextExponent + field_simp [hR.ne',ht.ne'] + · unfold nextGap nextExponent + field_simp [hR.ne',ht.ne'] + ring + +noncomputable def thickStrip (R delta : ℝ) : Set ℝ := + {t | 2 ≤ t ∧ t ≤ 5 ∧ |normalizedSlack R t| ≤ delta} + +theorem thickStrip_cover {R delta t : ℝ} (hR : 3 ≤ R) (ht : t ∈ thickStrip R delta) : + t ∈ Icc 2 (2+6*delta) ∪ Icc ((R+2)/(R-2)-18*delta) ((R+2)/(R-2)+18*delta) := by + obtain ⟨ht2,ht5,hslack⟩ := ht + have hRp : 0 < R := by linarith + have hRm : 0 < R-2 := by linarith + have htp : 0 < t+1 := by linarith + have hd : 0 ≤ delta := (abs_nonneg _).trans hslack + rw [normalizedSlack_eq_min hRp htp] at hslack + by_cases hbranch : (t-2)/(t+1) ≤ (t-1)/(t+1)-2/R + · rw [min_eq_left hbranch] at hslack + have hh := (div_le_iff₀ htp).mp ((le_abs_self _).trans hslack) + exact Or.inl ⟨ht2,by nlinarith⟩ + · rw [min_eq_right (le_of_not_ge hbranch)] at hslack + have he : t-(R+2)/(R-2)=((t-1)/(t+1)-2/R)*((t+1)*R/(R-2)) := by + field_simp [hRp.ne',hRm.ne',htp.ne'] + ring + have hfac0 : 0 ≤ (t+1)*R/(R-2) := by positivity + have hfac : (t+1)*R/(R-2) ≤ 18 := by + apply (div_le_iff₀ hRm).mpr + nlinarith + have habs : |t-(R+2)/(R-2)| ≤ 18*delta := by + rw [he,abs_mul,abs_of_nonneg hfac0] + nlinarith [mul_le_mul hslack hfac hfac0 hd] + exact Or.inr ⟨by linarith [(abs_le.mp habs).1],by linarith [(abs_le.mp habs).2]⟩ + +theorem thickStrip_measurable (R delta : ℝ) : MeasurableSet (thickStrip R delta) := by + have hs : Measurable (normalizedSlack R) := by + unfold normalizedSlack thresholdSlack nextGap nextExponent + fun_prop + exact measurableSet_Ici.inter (measurableSet_Iic.inter (measurableSet_le hs.abs measurable_const)) + +theorem thickStrip_volume {R delta : ℝ} (hR : 3 ≤ R) (hd : 0 ≤ delta) : + volume (thickStrip R delta) ≤ ENNReal.ofReal (42*delta) := by + calc + _ ≤ volume (Icc 2 (2+6*delta) ∪ Icc ((R+2)/(R-2)-18*delta) ((R+2)/(R-2)+18*delta)) := + measure_mono (fun _ ht => thickStrip_cover hR ht) + _ ≤ volume (Icc 2 (2+6*delta))+volume (Icc ((R+2)/(R-2)-18*delta) ((R+2)/(R-2)+18*delta)) := + measure_union_le _ _ + _ = ENNReal.ofReal (6*delta)+ENNReal.ofReal (36*delta) := by + rw [Real.volume_Icc,Real.volume_Icc] + congr 1 <;> congr 1 <;> ring + _ = ENNReal.ofReal (42*delta) := by + rw [← ENNReal.ofReal_add (by positivity) (by positivity)] + congr 1 + ring +end NumberTheoryLean.TwoSidedThresholdGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/TwoSingletonBins.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/TwoSingletonBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d2e9dca32c618b8e0cf5ffbff65763ef73dd1d7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/TwoSingletonBins.lean @@ -0,0 +1,437 @@ +import OAI.NumberTheory.Jacobsthal.Primes.SubsetPrimeBoxMass +import OAI.NumberTheory.Jacobsthal.Sieve.ActualCofactorCellData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SubsetBoxBookkeeping +open _root_.Filter FiniteWeightedChoiceBox SingletonSubsetMass SubsetPrimeBoxMass +open WrongOwnerBoxMass WrongOwnerBinMass ActualBinOwners ErdosInversePrimeBin + +attribute [local instance] Classical.propDecidable + +theorem subset_box_original_weight {n : ℕ} (f : Fin n → Finset ℕ) : + pointWeight (fun _ => subsetWeight) f=(((∏ i,∏ p ∈ f i,p):ℕ):ℝ)⁻¹ := by + simp [pointWeight,subsetWeight,Finset.prod_inv_distrib] + +theorem search_card_le_multiplicity {n : ℕ} (mult : Fin n → ℕ) (S : Finset (Fin n)) + (hsingle : ∀ i ∈ S,mult i=1) : S.card ≤ ∑ i,mult i := by + calc + S.card = ∑ i ∈ S,mult i := by + rw [Finset.card_eq_sum_ones] + apply Finset.sum_congr rfl + intro i hi + exact (hsingle i hi).symm + _ ≤ ∑ i,mult i := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + (fun _ _ _ => Nat.zero_le _) + +theorem length_bounded_subset_wrong_mass {Cs theta A Clen : ℝ} (hCs : 0 ≤ Cs) + (htheta : 0 < theta) (hA : 0 < A) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,∀ Y xi eta B : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → theta ≤ xi → xi ≤ 1 → + Real.log B ≤ 2*Real.log w → ∀ (n : ℕ) (R : Fin n → ℝ) (mult : Fin n → ℕ), + ((∑ i,mult i):ℝ) ≤ Clen*Real.log B → ∀ (S : Finset (Fin n)), + (∀ i ∈ S,mult i=1) → (∀ i ∈ S,w^(w^((1/4:ℝ))) ≤ R i) → + ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + (∑ f ∈ (points (fun i => (primeBin (R i) xi).powersetCard (mult i))).filter + (fun f => ∃ i ∈ S,∃ p ∈ f i,p ∈ wrongOwnerPrimes Y w Cs eta (R i) xi a q), + pointWeight (fun _ => subsetWeight) f) ≤ + w^(-A)*boxMass (fun i => (primeBin (R i) xi).powersetCard (mult i)) + (fun _ => subsetWeight) := by + filter_upwards [wrong_owner_subset_mass hCs htheta (show 0 < A+1 by linarith), + logarithmic_positions_le_w Clen hC,eventually_gt_atTop (1:ℝ)] with w hw hlength hw1 + intro Y xi eta B hY hYup hxi hxi1 hB n R mult hm S hsingle hsearch a q hq + have hraw := hw Y xi eta hY hYup hxi hxi1 n R mult S hsingle hsearch a q hq + have hcard : (S.card:ℝ) ≤ w := by + have hsmr : (S.card:ℝ) ≤ ∑ i,(mult i:ℝ) := by exact_mod_cast search_card_le_multiplicity mult S hsingle + have hmul := mul_le_mul_of_nonneg_left hB hC + nlinarith + have hw0 : 0 < w := zero_lt_one.trans hw1 + have hmul := mul_le_mul_of_nonneg_right hcard (Real.rpow_nonneg hw0.le (-(A+1))) + have he : w*w^(-(A+1))=w^(-A) := by + calc + _ = w^(1:ℝ)*w^(-(A+1)) := by rw [Real.rpow_one] + _ = w^((1:ℝ)+(-(A+1))) := (Real.rpow_add hw0 _ _).symm + _ = _ := by congr 1; ring + rw [he] at hmul + have hmass : 0 ≤ boxMass (fun i => (primeBin (R i) xi).powersetCard (mult i)) (fun _ => subsetWeight) := + Finset.sum_nonneg (fun f _ => weight_nonnegative _ (fun _ => subsetWeight_nonnegative) f) + exact hraw.trans (mul_le_mul_of_nonneg_right hmul hmass) +end NumberTheoryLean.SubsetBoxBookkeeping + + + +namespace NumberTheoryLean.CanonicalSubsetBox +open _root_.Filter FiniteWeightedChoiceBox SingletonSubsetMass SubsetPrimeBoxMass SubsetBoxBookkeeping +open WrongOwnerBinMass ActualBinOwners ErdosInversePrimeBin ErdosInverseAlignment ErdosCofactorChoices + +attribute [local instance] Classical.propDecidable + +noncomputable def selectionMass {n : ℕ} (P : Fin n → Finset ℕ) (mult : Fin n → ℕ) : ℝ := + ∑ f ∈ selections P mult,(selectionProduct f:ℝ)⁻¹ + +theorem canonical_points {n : ℕ} (P : Fin n → Finset ℕ) (mult : Fin n → ℕ) : + points (fun i => (P i).powersetCard (mult i))=selections P mult := by + ext f + simp only [points,selections,Fintype.mem_piFinset] + +theorem canonical_weight {n : ℕ} (f : Fin n → Finset ℕ) : + pointWeight (fun _ => subsetWeight) f=(selectionProduct f:ℝ)⁻¹ := subset_box_original_weight f + +theorem selectionMass_eq_weighted {n : ℕ} (P : Fin n → Finset ℕ) (mult : Fin n → ℕ) : + selectionMass P mult=boxMass (fun i => (P i).powersetCard (mult i)) (fun _ => subsetWeight) := by + rw [selectionMass,boxMass,canonical_points] + apply Finset.sum_congr rfl + intro f _hf + exact (canonical_weight f).symm + +theorem canonical_no_nearfull_mass {n : ℕ} (R : Fin n → ℝ) (w c xi eta : ℝ) (mult : Fin n → ℕ) + (hR : ∀ i,0 < R i) (hw : 1 < w) (hc : 0 < c) (hxi0 : 0 ≤ xi) (hxi1 : xi ≤ 1) + (heta0 : 0 < eta) (heta1 : eta ≤ 1) (S : Finset (Fin n)) + (hsingle : ∀ i ∈ S,mult i=1) (hcount : c*Real.log w ≤ (S.card:ℝ)) (a : ℕ → ℤ) (q : ℚ) + (hd : ∀ i ∈ S,(((primeBin (R i) xi).filter (aligns a q)).card:ℝ) ≤ + (1-eta)*((primeBin (R i) xi).card:ℝ)) : + (∑ f ∈ (selections (fun i => primeBin (R i) xi) mult).filter + (fun f => ∀ i ∈ S,∀ p ∈ f i,aligns a q p),(selectionProduct f:ℝ)⁻¹) ≤ + w^(-(c*eta/2))*selectionMass (fun i => primeBin (R i) xi) mult := by + have hh := no_nearfull_subset_power R w c xi eta mult hR hw hc hxi0 hxi1 heta0 heta1 S hsingle hcount a q hd + rw [← selectionMass_eq_weighted] at hh + simp only [restrictedPoints,canonical_points,canonical_weight] at hh + exact hh + +theorem canonical_wrong_mass {Cs theta A Clen : ℝ} (hCs : 0 ≤ Cs) + (htheta : 0 < theta) (hA : 0 < A) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,∀ Y xi eta B : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → theta ≤ xi → xi ≤ 1 → + Real.log B ≤ 2*Real.log w → ∀ (n : ℕ) (R : Fin n → ℝ) (mult : Fin n → ℕ), + ((∑ i,mult i):ℝ) ≤ Clen*Real.log B → ∀ (S : Finset (Fin n)), + (∀ i ∈ S,mult i=1) → (∀ i ∈ S,w^(w^((1/4:ℝ))) ≤ R i) → + ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + (∑ f ∈ (selections (fun i => primeBin (R i) xi) mult).filter + (fun f => ∃ i ∈ S,∃ p ∈ f i,p ∈ wrongOwnerPrimes Y w Cs eta (R i) xi a q), + (selectionProduct f:ℝ)⁻¹) ≤ + w^(-A)*selectionMass (fun i => primeBin (R i) xi) mult := by + filter_upwards [length_bounded_subset_wrong_mass hCs htheta hA hC] with w hw + intro Y xi eta B hY hYup hxi hxi1 hcomp n R mult hlen S hsingle hsearch a q hq + have hh := hw Y xi eta B hY hYup hxi hxi1 hcomp n R mult hlen S hsingle hsearch a q hq + rw [← selectionMass_eq_weighted] at hh + simp only [canonical_points,canonical_weight] at hh + exact hh +end NumberTheoryLean.CanonicalSubsetBox + + + +namespace NumberTheoryLean.SingletonBinSelection +open ErdosCofactorChoices + +attribute [local instance] Classical.propDecidable + +noncomputable def eraseMultiplicity {n : ℕ} (m : Fin n → ℕ) (i : Fin n) : Fin n → ℕ := + fun k => if k=i then 0 else m k +noncomputable def eraseSelection {n : ℕ} (f : Fin n → Finset ℕ) (i : Fin n) : Fin n → Finset ℕ := + fun k => if k=i then ∅ else f k +noncomputable def fillSelection {n : ℕ} (f : Fin n → Finset ℕ) (i : Fin n) (p : ℕ) : Fin n → Finset ℕ := + Function.update f i {p} + +theorem erase_selection_mem {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (f : Fin n → Finset ℕ) + (hf : f ∈ selections P m) (i : Fin n) : eraseSelection f i ∈ selections P (eraseMultiplicity m i) := by + apply (mem_selections _ _ _).mpr + intro k + by_cases hki : k=i + · subst k; simp [eraseSelection,eraseMultiplicity] + · simpa only [eraseSelection,eraseMultiplicity,ite_eq_right hki] using (mem_selections P m f).mp hf k + +theorem erased_coordinate_empty {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) + (f : Fin n → Finset ℕ) (hf : f ∈ selections P (eraseMultiplicity m i)) : f i=∅ := by + have hh := ((mem_selections P _ f).mp hf i).2 + simpa [eraseMultiplicity] using hh + +theorem fill_selection_mem {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) + (hmi : m i=1) (f : Fin n → Finset ℕ) (hf : f ∈ selections P (eraseMultiplicity m i)) + (p : ℕ) (hp : p ∈ P i) : fillSelection f i p ∈ selections P m := by + apply (mem_selections _ _ _).mpr + intro k + by_cases hki : k=i + · subst k; simp [fillSelection,hmi,hp] + · have hh := (mem_selections P _ f).mp hf k + simpa [fillSelection,eraseMultiplicity,hki] using hh + +theorem erase_fill {n : ℕ} (f : Fin n → Finset ℕ) (i : Fin n) (p : ℕ) (he : f i=∅) : + eraseSelection (fillSelection f i p) i=f := by + funext k + by_cases hki : k=i + · subst k; simp [eraseSelection,he] + · simp [eraseSelection,fillSelection,hki] + +theorem fill_erase {n : ℕ} (f : Fin n → Finset ℕ) (i : Fin n) (p : ℕ) (he : f i={p}) : + fillSelection (eraseSelection f i) i p=f := by + funext k + by_cases hki : k=i + · subst k; simp [fillSelection,he] + · simp [eraseSelection,fillSelection,hki] + +theorem singleton_selection_recovery {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (i : Fin n) (hmi : m i=1) (f : Fin n → Finset ℕ) (hf : f ∈ selections P m) : + ∃ p ∈ P i,f i={p} ∧ fillSelection (eraseSelection f i) i p=f := by + have hi := (mem_selections P m f).mp hf i + obtain ⟨p,hp⟩ := Finset.card_eq_one.mp (hi.2.trans hmi) + exact ⟨p,hi.1 (by rw [hp]; simp),hp,fill_erase f i p hp⟩ +end NumberTheoryLean.SingletonBinSelection + + + +namespace NumberTheoryLean.PartitionedSelections +open ErdosCofactorChoices + +attribute [local instance] Classical.propDecidable + +noncomputable def restrictMultiplicity {n : ℕ} (m : Fin n → ℕ) (S : Finset (Fin n)) : Fin n → ℕ := + fun k => if k∈S then m k else 0 +noncomputable def restrictSelection {n : ℕ} (f : Fin n → Finset ℕ) (S : Finset (Fin n)) : Fin n → Finset ℕ := + fun k => if k∈S then f k else ∅ +noncomputable def joinSelection {n : ℕ} (S : Finset (Fin n)) (f g : Fin n → Finset ℕ) : Fin n → Finset ℕ := + fun k => if k∈S then f k else g k + +theorem restricted_mem {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (f : Fin n → Finset ℕ) (hf : f ∈ selections P m) (S : Finset (Fin n)) : + restrictSelection f S ∈ selections P (restrictMultiplicity m S) := by + apply (mem_selections _ _ _).mpr + intro k + by_cases hk : k∈S + · simpa only [restrictSelection,restrictMultiplicity,ite_eq_left hk] using (mem_selections P m f).mp hf k + · simp [restrictSelection,restrictMultiplicity,hk] + +theorem restricted_empty {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (S : Finset (Fin n)) + (f : Fin n → Finset ℕ) (hf : f ∈ selections P (restrictMultiplicity m S)) + (k : Fin n) (hk : k∉S) : f k=∅ := by + have hh := ((mem_selections _ _ _).mp hf k).2 + simpa [restrictMultiplicity,hk] using hh + +theorem joined_mem {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (S : Finset (Fin n)) + (f g : Fin n → Finset ℕ) (hf : f ∈ selections P (restrictMultiplicity m S)) + (hg : g ∈ selections P (restrictMultiplicity m Sᶜ)) : joinSelection S f g ∈ selections P m := by + apply (mem_selections _ _ _).mpr + intro k + by_cases hk : k∈S + · have hh := (mem_selections _ _ _).mp hf k + simpa [restrictMultiplicity,joinSelection,hk] using hh + · have hh := (mem_selections _ _ _).mp hg k + simpa [restrictMultiplicity,joinSelection,hk] using hh + +theorem join_restrictions {n : ℕ} (f : Fin n → Finset ℕ) (S : Finset (Fin n)) : + joinSelection S (restrictSelection f S) (restrictSelection f Sᶜ)=f := by + funext k + by_cases hk : k∈S <;> simp [joinSelection,restrictSelection,hk] + +theorem restrict_join {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (S : Finset (Fin n)) + (f g : Fin n → Finset ℕ) (hf : f ∈ selections P (restrictMultiplicity m S)) + (hg : g ∈ selections P (restrictMultiplicity m Sᶜ)) : + restrictSelection (joinSelection S f g) S=f ∧ restrictSelection (joinSelection S f g) Sᶜ=g := by + constructor <;> funext k + · by_cases hk : k∈S + · simp [restrictSelection,joinSelection,hk] + · simp only [restrictSelection,ite_eq_right hk] + exact (restricted_empty P m S f hf k hk).symm + · by_cases hk : k∈S + · simp only [restrictSelection,Finset.mem_compl,not_true_eq_false,ite_false,hk] + exact (restricted_empty P m Sᶜ g hg k (by simpa using hk)).symm + · simp [restrictSelection,joinSelection,hk] +end NumberTheoryLean.PartitionedSelections + + + +namespace NumberTheoryLean.SingletonBinProduct +open ErdosCofactorChoices SingletonBinSelection + +attribute [local instance] Classical.propDecidable + +theorem filled_product {n : ℕ} (f : Fin n → Finset ℕ) (i : Fin n) (p : ℕ) (he : f i=∅) : + selectionProduct (fillSelection f i p)=p*selectionProduct f := by + have hp : ∀ k,(∏ q ∈ fillSelection f i p k,q)=(if k=i then p else 1)*(∏ q ∈ f k,q) := by + intro k + by_cases hki : k=i + · subst k; simp [fillSelection,he] + · simp [fillSelection,hki] + unfold selectionProduct + simp_rw [hp] + rw [Finset.prod_mul_distrib] + simp + +theorem filled_reciprocal {n : ℕ} (f : Fin n → Finset ℕ) (i : Fin n) (p : ℕ) (he : f i=∅) : + (selectionProduct (fillSelection f i p):ℝ)⁻¹=(p:ℝ)⁻¹*(selectionProduct f:ℝ)⁻¹ := by + rw [filled_product f i p he,Nat.cast_mul,mul_inv_rev] + ring + +end NumberTheoryLean.SingletonBinProduct + + + +namespace NumberTheoryLean.PartitionedSelectionSums +open ErdosCofactorChoices PartitionedSelections + +attribute [local instance] Classical.propDecidable + +theorem joined_product {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (S : Finset (Fin n)) + (f g : Fin n → Finset ℕ) (hf : f ∈ selections P (restrictMultiplicity m S)) + (hg : g ∈ selections P (restrictMultiplicity m Sᶜ)) : + selectionProduct (joinSelection S f g)=selectionProduct f*selectionProduct g := by + have hpoint : ∀ k,(∏ p ∈ joinSelection S f g k,p)=(∏ p ∈ f k,p)*(∏ p ∈ g k,p) := by + intro k + by_cases hk : k∈S + · have he := restricted_empty P m Sᶜ g hg k (by simpa using hk) + simp [joinSelection,hk,he] + · have he := restricted_empty P m S f hf k hk + simp [joinSelection,hk,he] + unfold selectionProduct + simp_rw [hpoint] + exact Finset.prod_mul_distrib + +theorem partitioned_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (S : Finset (Fin n)) + (G : (Fin n → Finset ℕ) → ℝ) : + (∑ f ∈ selections P m,G f)= + ∑ f ∈ selections P (restrictMultiplicity m S),∑ g ∈ selections P (restrictMultiplicity m Sᶜ),G (joinSelection S f g) := by + symm + rw [← Finset.sum_product' (selections P (restrictMultiplicity m S)) + (selections P (restrictMultiplicity m Sᶜ)) (fun f g => G (joinSelection S f g))] + apply Finset.sum_bij (fun x _ => joinSelection S x.1 x.2) + · intro x hx + exact joined_mem P m S x.1 x.2 (Finset.mem_product.mp hx).1 (Finset.mem_product.mp hx).2 + · intro x hx y hy he + have hx' := restrict_join P m S x.1 x.2 (Finset.mem_product.mp hx).1 (Finset.mem_product.mp hx).2 + have hy' := restrict_join P m S y.1 y.2 (Finset.mem_product.mp hy).1 (Finset.mem_product.mp hy).2 + exact Prod.ext (hx'.1.symm.trans ((congrArg (fun f => restrictSelection f S) he).trans hy'.1)) + (hx'.2.symm.trans ((congrArg (fun f => restrictSelection f Sᶜ) he).trans hy'.2)) + · intro f hf + exact ⟨(restrictSelection f S,restrictSelection f Sᶜ), + Finset.mem_product.mpr ⟨restricted_mem P m f hf S,restricted_mem P m f hf Sᶜ⟩,join_restrictions f S⟩ + · intro x _hx + rfl + +theorem partitioned_weighted_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (S : Finset (Fin n)) + (G : (Fin n → Finset ℕ) → ℝ) : + (∑ f ∈ selections P m,(selectionProduct f:ℝ)⁻¹*G f)= + ∑ f ∈ selections P (restrictMultiplicity m S),∑ g ∈ selections P (restrictMultiplicity m Sᶜ), + ((selectionProduct f:ℝ)⁻¹*(selectionProduct g:ℝ)⁻¹)*G (joinSelection S f g) := by + rw [partitioned_sum P m S] + apply Finset.sum_congr rfl + intro f hf + apply Finset.sum_congr rfl + intro g hg + rw [joined_product P m S f g hf hg,Nat.cast_mul,mul_inv_rev] + ring +end NumberTheoryLean.PartitionedSelectionSums + + + +namespace NumberTheoryLean.SingletonBinSum +open ErdosCofactorChoices SingletonBinSelection SingletonBinProduct + +attribute [local instance] Classical.propDecidable + +theorem singleton_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (hmi : m i=1) + (G : (Fin n → Finset ℕ) → ℝ) : + (∑ f ∈ selections P m,G f)= + ∑ p ∈ P i,∑ f ∈ selections P (eraseMultiplicity m i),G (fillSelection f i p) := by + symm + rw [← Finset.sum_product' (P i) (selections P (eraseMultiplicity m i)) (fun p f => G (fillSelection f i p))] + apply Finset.sum_bij (fun x _ => fillSelection x.2 i x.1) + · intro x hx + exact fill_selection_mem P m i hmi x.2 (Finset.mem_product.mp hx).2 x.1 (Finset.mem_product.mp hx).1 + · intro x hx y hy he + have hpx : fillSelection x.2 i x.1 i={x.1} := by simp [fillSelection] + have hpy : fillSelection y.2 i y.1 i={y.1} := by simp [fillSelection] + have hp : x.1=y.1 := by + have hh := congrFun he i + rw [hpx,hpy] at hh + exact Finset.singleton_injective hh + have hf : x.2=y.2 := by + have hh := congrArg (fun f => eraseSelection f i) he + rwa [erase_fill x.2 i x.1 (erased_coordinate_empty P m i x.2 (Finset.mem_product.mp hx).2), + erase_fill y.2 i y.1 (erased_coordinate_empty P m i y.2 (Finset.mem_product.mp hy).2)] at hh + exact Prod.ext hp hf + · intro f hf + obtain ⟨p,hp,_hfp,he⟩ := singleton_selection_recovery P m i hmi f hf + exact ⟨(p,eraseSelection f i),Finset.mem_product.mpr ⟨hp,erase_selection_mem P m f hf i⟩,he⟩ + · intro x _ + rfl + +theorem singleton_weighted_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (hmi : m i=1) + (G : (Fin n → Finset ℕ) → ℝ) : + (∑ f ∈ selections P m,(selectionProduct f:ℝ)⁻¹*G f)= + ∑ p ∈ P i,∑ f ∈ selections P (eraseMultiplicity m i), + ((p:ℝ)⁻¹*(selectionProduct f:ℝ)⁻¹)*G (fillSelection f i p) := by + rw [singleton_sum P m i hmi] + apply Finset.sum_congr rfl + intro p _hp + apply Finset.sum_congr rfl + intro f hf + rw [filled_reciprocal f i p (erased_coordinate_empty P m i f hf)] +end NumberTheoryLean.SingletonBinSum + + + +namespace NumberTheoryLean.TwoSingletonBins +open ErdosCofactorChoices SingletonBinSelection SingletonBinProduct SingletonBinSum + +attribute [local instance] Classical.propDecidable + +noncomputable def eraseTwo {n : ℕ} (m : Fin n → ℕ) (i j : Fin n) : Fin n → ℕ := + eraseMultiplicity (eraseMultiplicity m i) j +noncomputable def fillTwo {n : ℕ} (f : Fin n → Finset ℕ) (i j : Fin n) (p u : ℕ) : Fin n → Finset ℕ := + fillSelection (fillSelection f j u) i p + +theorem eraseTwo_zero {n : ℕ} (m : Fin n → ℕ) (i j : Fin n) : eraseTwo m i j i=0 ∧ eraseTwo m i j j=0 := by + simp [eraseTwo,eraseMultiplicity] + +theorem eraseTwo_le {n : ℕ} (m : Fin n → ℕ) (i j k : Fin n) : eraseTwo m i j k ≤ m k := by + simp only [eraseTwo,eraseMultiplicity] + split_ifs <;> omega + +theorem fillTwo_mem {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i j : Fin n) + (hij : i ≠ j) (hi : m i=1) (hj : m j=1) (f : Fin n → Finset ℕ) + (hf : f ∈ selections P (eraseTwo m i j)) (p u : ℕ) (hp : p ∈ P i) (hu : u ∈ P j) : + fillTwo f i j p u ∈ selections P m := by + have hmj : eraseMultiplicity m i j=1 := by simp [eraseMultiplicity,Ne.symm hij,hj] + exact fill_selection_mem P m i hi _ (fill_selection_mem P (eraseMultiplicity m i) j hmj f hf u hu) p hp + +theorem fillTwo_product {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i j : Fin n) + (hij : i ≠ j) (f : Fin n → Finset ℕ) (hf : f ∈ selections P (eraseTwo m i j)) (p u : ℕ) : + selectionProduct (fillTwo f i j p u)=p*u*selectionProduct f := by + have he := (mem_selections P _ f).mp hf + have hei : f i=∅ := Finset.card_eq_zero.mp ((he i).2.trans (eraseTwo_zero m i j).1) + have hej : f j=∅ := Finset.card_eq_zero.mp ((he j).2.trans (eraseTwo_zero m i j).2) + have hfill : fillSelection f j u i=∅ := by simp [fillSelection,hij,hei] + rw [fillTwo,filled_product _ i p hfill,filled_product f j u hej] + ring + +theorem two_singleton_weighted_sum {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i j : Fin n) + (hij : i ≠ j) (hi : m i=1) (hj : m j=1) (G : (Fin n → Finset ℕ) → ℝ) : + (∑ f ∈ selections P m,(selectionProduct f:ℝ)⁻¹*G f)= + ∑ p ∈ P i,∑ u ∈ P j,∑ f ∈ selections P (eraseTwo m i j), + ((p:ℝ)⁻¹*(u:ℝ)⁻¹*(selectionProduct f:ℝ)⁻¹)*G (fillTwo f i j p u) := by + rw [singleton_weighted_sum P m i hi] + apply Finset.sum_congr rfl + intro p _hp + have hmj : eraseMultiplicity m i j=1 := by simp [eraseMultiplicity,Ne.symm hij,hj] + have hh := singleton_weighted_sum P (eraseMultiplicity m i) j hmj + (fun f => (p:ℝ)⁻¹*G (fillSelection f i p)) + calc + _ = ∑ f ∈ selections P (eraseMultiplicity m i),(selectionProduct f:ℝ)⁻¹*((p:ℝ)⁻¹*G (fillSelection f i p)) := by + apply Finset.sum_congr rfl + intro f _ + ring + _ = _ := by + rw [hh] + apply Finset.sum_congr rfl + intro u _hu + apply Finset.sum_congr rfl + intro f _hf + dsimp only [fillTwo] + ring +end NumberTheoryLean.TwoSingletonBins + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Partitions/UnitReductionFibres.lean b/lean/OAI/NumberTheory/Jacobsthal/Partitions/UnitReductionFibres.lean new file mode 100644 index 0000000000000000000000000000000000000000..312846e0988bd0b7178fffb041736f7017792578 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Partitions/UnitReductionFibres.lean @@ -0,0 +1,64 @@ +import Mathlib.Data.Nat.Totient +import OAI.NumberTheory.Jacobsthal.Harmonic.CharacterReduction + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosKloosterman.PrimePower + +attribute [local instance] Classical.decEq + +private theorem card_mul_group_fibre {A B : Type*} [Group A] [Fintype A] + [Group B] [Fintype B] (f : A →* B) (hf : Function.Surjective f) (b : B) : + Fintype.card B * ((Finset.univ : Finset A).filter fun x => f x = b).card = + Fintype.card A := by + calc + _ = ∑ _y : B, ((Finset.univ : Finset A).filter fun x => f x = b).card := by simp + _ = ∑ y : B, ((Finset.univ : Finset A).filter fun x => f x = y).card := by + apply Finset.sum_congr rfl + intro y _ + exact MonoidHom.card_fiber_eq_of_mem_range f (hf b) (hf y) + _ = _ := by + rw [Finset.sum_card_fiberwise_eq_card_filter] + simp + +theorem unit_reduction_fibre_card (p s : ℕ) [Fact p.Prime] (hs : 0 < s) + (v : (ZMod (p^s))ˣ) : + ((Finset.univ : Finset (ZMod (p*p^s))ˣ).filter fun u => + ZMod.unitsMap (dvd_mul_left (p^s) p) u = v).card = p := by + let f : (ZMod (p*p^s))ˣ →* (ZMod (p^s))ˣ := ZMod.unitsMap (dvd_mul_left (p^s) p) + have hf : Function.Surjective f := ZMod.unitsMap_surjective (dvd_mul_left (p^s) p) + have hc := card_mul_group_fibre f hf v + have htot : Fintype.card (ZMod (p*p^s))ˣ = Fintype.card (ZMod (p^s))ˣ * p := by + rw [ZMod.card_units_eq_totient, ZMod.card_units_eq_totient, ← pow_succ', + Nat.totient_prime_pow_succ (Fact.out : p.Prime), + Nat.totient_prime_pow (Fact.out : p.Prime) hs] + have he : p^s = p^(s-1)*p := by + rw [← pow_succ] + congr 1 + omega + rw [he] + ring + rw [htot] at hc + simpa only [f] using Nat.eq_of_mul_eq_mul_left + (show 0 < Fintype.card (ZMod (p^s))ˣ from Fintype.card_pos) hc + +theorem sum_comp_unit_reduction (p s : ℕ) [Fact p.Prime] (hs : 0 < s) + (f : (ZMod (p^s))ˣ → ℂ) : + (∑ u : (ZMod (p*p^s))ˣ, f (ZMod.unitsMap (dvd_mul_left (p^s) p) u)) = + (p : ℂ) * ∑ v : (ZMod (p^s))ˣ, f v := by + rw [← Finset.sum_fiberwise' Finset.univ (ZMod.unitsMap (dvd_mul_left (p^s) p)) f] + simp only [Finset.sum_const, unit_reduction_fibre_card p s hs, nsmul_eq_mul, + ← Finset.mul_sum] + +end ErdosKloosterman.PrimePower + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualEffectiveWitness.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualEffectiveWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ede70635106105d4e93ce46e8bc23eb22c2af0c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualEffectiveWitness.lean @@ -0,0 +1,33 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.EffectiveSurvivors + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceEffective + +theorem actual_effective_unit_and_coordinate (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) (hq : Squarefree qf) + (p : ℕ) [NeZero p] (hHp : (effectiveModulus a r qf).Coprime p) : + Int.gcd (effectiveIntercept a r qf) (effectiveModulus a r qf : ℤ) = 1 ∧ + ∃! m0 : ℤ, + (effectiveIntercept a r qf : ℝ)/(p : ℝ) ≤ (m0 : ℝ) ∧ + (m0 : ℝ) < (effectiveIntercept a r qf : ℝ)/(p : ℝ)+(effectiveModulus a r qf : ℝ) ∧ + Int.ModEq (effectiveModulus a r qf : ℤ) ((p : ℤ)*m0) (effectiveIntercept a r qf) := by + refine ⟨effective_coordinates_gcd a r qf hq,?_⟩ + let m0 := intervalM0 p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) + have hbounds := intervalM0_bounds p (effectiveModulus a r qf) hHp (effectiveIntercept a r qf) + (effectiveModulus_pos a r qf) + refine ⟨m0,⟨hbounds.1,hbounds.2,intervalM0_modEq p _ hHp _⟩,?_⟩ + intro m hm + exact intervalM0_unique p _ hHp _ (effectiveModulus_pos a r qf) m ⟨hm.1,hm.2.1⟩ hm.2.2 + +end ErdosVarianceEffective + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualFirstTagExistence.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualFirstTagExistence.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7a9c101cf75854f7642914260d9dec7c06314d8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualFirstTagExistence.lean @@ -0,0 +1,218 @@ +import OAI.NumberTheory.Jacobsthal.Conclusions.JacobsthalSourceScale + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.PaperOwnerHeight +open _root_.Filter JacobsthalSourceScale + + +theorem sourceW_square_two_L : ∀ᶠ L : ℝ in atTop,2*L ≤ (sourceW L)^2 := by + have hh := (isLittleO_log_rpow_rpow_atTop (4:ℝ) (s := 1) (by norm_num)).bound + (by norm_num : (0:ℝ)<1/2) + filter_upwards [hh,eventually_gt_atTop (1:ℝ)] with L hsmall hL + have hL0 : 0 < L := zero_lt_one.trans hL + have hl : 0 < Real.log L := Real.log_pos hL + have h4 : (Real.log L)^4 ≤ L/2 := by + simpa only [Real.rpow_ofNat,Real.rpow_one,Real.norm_eq_abs, + abs_of_nonneg (pow_nonneg hl.le 4),abs_of_pos hL0,one_div,mul_comm,div_eq_mul_inv,one_mul] using hsmall + rw [sourceW,div_pow,← pow_mul] + apply (le_div_iff₀ (pow_pos hl 4)).mpr + have hm := mul_le_mul_of_nonneg_left h4 hL0.le + nlinarith + +theorem literal_source_floor_height : ∀ᶠ z : ℝ in atTop, + ((⌊z^2/(Real.log z)^2⌋₊:ℕ):ℝ) ≤ Real.exp ((sourceW (Real.log z))^2) := by + filter_upwards [Real.tendsto_log_atTop.eventually sourceW_square_two_L, + eventually_gt_atTop (1:ℝ),Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with z hW hz hlog + have hz0 : 0 < z := zero_lt_one.trans hz + have hy : ((⌊z^2/(Real.log z)^2⌋₊:ℕ):ℝ) ≤ z^2 := by + exact (Nat.floor_le (div_nonneg (sq_nonneg z) (sq_nonneg (Real.log z)))).trans + (div_le_self (sq_nonneg z) (by nlinarith : 1 ≤ (Real.log z)^2)) + have he : z^2=Real.exp (2*Real.log z) := by + rw [show 2*Real.log z=Real.log (z^2) by rw [Real.log_pow]; norm_num] + exact (Real.exp_log (sq_pos_of_pos hz0)).symm + exact hy.trans (he.trans_le (Real.exp_le_exp.mpr hW)) +end NumberTheoryLean.PaperOwnerHeight + + + +namespace NumberTheoryLean.PaperBinOwners +open _root_.Filter JacobsthalSourceScale PaperOwnerHeight CorrectSearchTags UniformSearchOwner ActualBinOwners +open ActualSourceTags LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinMaps +open ErdosInverseAlignment ErdosInversePrimeBin + +attribute [local instance] Classical.propDecidable + +theorem paper_bin_span {xi : ℝ} (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,2 ≤ sourceW (Real.log z) ∧ sourceW (Real.log z) < z ∧ + (1+xi)*sourceW (Real.log z) ≤ z := by + have hsmall := (isLittleO_log_rpow_atTop (r := 1) (by norm_num)).bound (by norm_num : (0:ℝ)<1/2) + filter_upwards [Real.tendsto_log_atTop.eventually sourceW_bounds_eventually, + (sourceW_tendsto.comp Real.tendsto_log_atTop).eventually_ge_atTop 2, + hsmall,eventually_gt_atTop (1:ℝ)] with z hW hw2 hlog hz + have hz0 : 0 < z := zero_lt_one.trans hz + have hlog0 : 0 < Real.log z := Real.log_pos hz + have hlog' : Real.log z ≤ z/2 := by + simpa only [Real.rpow_one,Real.norm_eq_abs,abs_of_pos hlog0,abs_of_pos hz0, + one_div,mul_comm,div_eq_mul_inv,one_mul] using hlog + have hspan : (1+xi)*sourceW (Real.log z) ≤ z := by + have hh := mul_le_mul_of_nonneg_right (show 1+xi ≤ 2 by linarith) (by linarith : 0 ≤ sourceW (Real.log z)) + nlinarith [hW.2.2] + have hzw : sourceW (Real.log z) < z := by + have hh := mul_pos hxi (show 0 < sourceW (Real.log z) by linarith) + nlinarith + exact ⟨hw2,hzw,hspan⟩ + +theorem paper_owner_unique {Cs eta xi : ℝ} (hCs : 0 ≤ Cs) (heta : eta < 1/2) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,∀ (Y : ℕ),Y ≤ ⌊z^2/(Real.log z)^2⌋₊ → + ∀ b : Fin (binCount (sourceW (Real.log z)) z xi), + searchBin (sourceW (Real.log z)) (lower (sourceW (Real.log z)) z xi b) → + ∀ a : ℕ → ℤ,∀ q ∈ ownerCandidates Y (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b) a, + ∀ r ∈ ownerCandidates Y (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b) a,q=r := by + have ht : 0 < xi/4 := by positivity + filter_upwards [paper_bin_span hxi hxi1,literal_source_floor_height, + (sourceW_tendsto.comp Real.tendsto_log_atTop).eventually (uniform_search_owner_unique hCs heta ht)] with z hspan hheight howner + intro Y hY b hs a + have hw : 1 < sourceW (Real.log z) := by linarith [hspan.1] + have hw0 : 0 < sourceW (Real.log z) := zero_lt_one.trans hw + have hwidth := common_width_bounds hw0 hspan.2.1 hxi hxi1 hspan.2.2 + have hYup : (Y:ℝ) ≤ Real.exp ((sourceW (Real.log z))^2) := + (show (Y:ℝ) ≤ (⌊z^2/(Real.log z)^2⌋₊:ℕ) by exact_mod_cast hY).trans hheight + exact howner.2 Y (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b) + (Nat.cast_nonneg Y) hYup (searchBin_lower hw (endpoint_pos hw0 _) hs) + hwidth.2.1 (hwidth.2.2.1.trans hxi1) a + +theorem paper_owner_identifies {Cs eta xi : ℝ} (hCs : 0 ≤ Cs) (heta : eta < 1/2) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,∀ (Y : ℕ),Y ≤ ⌊z^2/(Real.log z)^2⌋₊ → + ∀ b : Fin (binCount (sourceW (Real.log z)) z xi), + searchBin (sourceW (Real.log z)) (lower (sourceW (Real.log z)) z xi b) → + ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y (sourceW (Real.log z)) Cs q → + (1-eta)*((primeBin (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b)).card:ℝ) ≤ + (((primeBin (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b)).filter (aligns a q)).card:ℝ) → + owner Y (sourceW (Real.log z)) Cs eta (lower (sourceW (Real.log z)) z xi b) + (width (sourceW (Real.log z)) z xi b) a=some q := by + filter_upwards [paper_owner_unique hCs heta hxi hxi1,paper_bin_span hxi hxi1] with z hu hspan + intro Y hY b hs a q he hd + exact owner_eq_of_unique (Nat.cast_nonneg Y) (by linarith [hspan.1]) a (hu Y hY b hs a) q he hd +end NumberTheoryLean.PaperBinOwners + + + +namespace NumberTheoryLean.PaperCorrectTag +open _root_.Filter JacobsthalSourceScale PaperBinOwners ActualBinOwners ActualSourceTags FiniteFirstTag +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem paper_correct_candidate {Cs eta xi : ℝ} (hCs : 0 ≤ Cs) (heta : eta < 1/2) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,∀ (hw : 1 < sourceW (Real.log z)) (htop : sourceW (Real.log z) < z) + (Y : ℕ),Y ≤ ⌊z^2/(Real.log z)^2⌋₊ → ∀ (a : ℕ → ℤ) (p : ℕ) (q : ℚ), + p ∈ sourcePrimeSet (sourceW (Real.log z)) z → + let b := label (zero_lt_one.trans hw) htop hxi p + searchBin (sourceW (Real.log z)) (lower (sourceW (Real.log z)) z xi b) → + eligible Y (sourceW (Real.log z)) Cs q → + (1-eta)*((primeBin (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b)).card:ℝ) ≤ + (((primeBin (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b)).filter (aligns a q)).card:ℝ) → + aligns a q p → tagCandidate Y (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi) (width (sourceW (Real.log z)) z xi) + (label (zero_lt_one.trans hw) htop hxi) a p=some (b,q) := by + filter_upwards [paper_owner_identifies hCs heta hxi hxi1] with z hz + intro hw htop Y hY a p q hp + dsimp only + intro hs he hd ha + have hps := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp hp + have hmem := label_prime_membership (zero_lt_one.trans hw) htop hxi hps.1 hps.2 + have ho := hz Y hY (label (zero_lt_one.trans hw) htop hxi p) hs a q he hd + exact candidate_of_witness Y (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi) (width (sourceW (Real.log z)) z xi) + (label (zero_lt_one.trans hw) htop hxi) a p q hmem hs ho ha + +theorem paper_first_tag_correct {Cs eta xi : ℝ} (hCs : 0 ≤ Cs) (heta : eta < 1/2) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,∀ (hw : 1 < sourceW (Real.log z)) (htop : sourceW (Real.log z) < z) + (Y : ℕ),Y ≤ ⌊z^2/(Real.log z)^2⌋₊ → ∀ (a : ℕ → ℤ) (ps : List ℕ) + (t : Tag (binCount (sourceW (Real.log z)) z xi)) (q : ℚ), + sourceTag Y (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi) (width (sourceW (Real.log z)) z xi) + (label (zero_lt_one.trans hw) htop hxi) a ps=some t → + eligible Y (sourceW (Real.log z)) Cs q → + (1-eta)*((primeBin (lower (sourceW (Real.log z)) z xi t.bin) (width (sourceW (Real.log z)) z xi t.bin)).card:ℝ) ≤ + (((primeBin (lower (sourceW (Real.log z)) z xi t.bin) (width (sourceW (Real.log z)) z xi t.bin)).filter (aligns a q)).card:ℝ) → + t.rational=q := by + filter_upwards [paper_owner_identifies hCs heta hxi hxi1] with z hz + intro hw htop Y hY a ps t q ht he hd + obtain ⟨_pre,p,_tail,_hps,_hindex,hbin,_hp,hs,ho,_ha,_hbefore⟩ := sourceTag_witness Y (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi) (width (sourceW (Real.log z)) z xi) + (label (zero_lt_one.trans hw) htop hxi) a ps ht + rw [← hbin] at hs ho + have ho' := hz Y hY t.bin hs a q he hd + exact Option.some.inj (ho.symm.trans ho') +end NumberTheoryLean.PaperCorrectTag + + + +namespace NumberTheoryLean.SourceOwnerAudit +open _root_.Filter JacobsthalSourceScale PaperBinOwners ActualBinOwners ActualSourceTags +open LogarithmicBinScale LogarithmicBinEndpoints + + +theorem literal_floor_owner_unique {Cs eta xi : ℝ} (hCs : 0 ≤ Cs) (heta : eta < 1/2) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ z : ℝ in atTop,∀ b : Fin (binCount (sourceW (Real.log z)) z xi), + searchBin (sourceW (Real.log z)) (lower (sourceW (Real.log z)) z xi b) → + ∀ a : ℕ → ℤ, + ∀ q ∈ ownerCandidates (⌊z^2/(Real.log z)^2⌋₊:ℕ) (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b) a, + ∀ r ∈ ownerCandidates (⌊z^2/(Real.log z)^2⌋₊:ℕ) (sourceW (Real.log z)) Cs eta + (lower (sourceW (Real.log z)) z xi b) (width (sourceW (Real.log z)) z xi b) a,q=r := by + filter_upwards [paper_owner_unique hCs heta hxi hxi1] with z hz + exact hz _ le_rfl +end NumberTheoryLean.SourceOwnerAudit + + + +namespace ErdosTagEvent +open NumberTheoryLean FiniteFirstTag ActualSourceTags + + +theorem firstTagFrom_none_iff {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) (k : ℕ) (ps : List ℕ) : + firstTagFrom F k ps=none ↔ ∀ p ∈ ps,F p=none := by + induction ps generalizing k with + | nil => simp [firstTagFrom] + | cons p ps ih => + cases he : F p with + | none => simp [firstTagFrom,he,ih] + | some bq => rcases bq with ⟨b,q⟩; simp [firstTagFrom,he] + +theorem firstTag_exists_of_candidate {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) (ps : List ℕ) + {p : ℕ} {bq : Fin n × ℚ} (hp : p ∈ ps) (hc : F p=some bq) : + ∃ t,firstTag F ps=some t := by + cases ht : firstTag F ps with + | none => + have hnone := (firstTagFrom_none_iff F 0 ps).mp ht p hp + rw [hc] at hnone + contradiction + | some t => exact ⟨t,rfl⟩ + +theorem sourceTag_exists_of_candidate {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (ps : List ℕ) {p : ℕ} {b : Fin n} {q : ℚ} + (hp : p ∈ ps) (hc : tagCandidate Y w Cs eta lower width label a p=some (b,q)) : + ∃ t,sourceTag Y w Cs eta lower width label a ps=some t := + firstTag_exists_of_candidate _ ps hp hc + +end ErdosTagEvent + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualFlaggedCompact.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualFlaggedCompact.lean new file mode 100644 index 0000000000000000000000000000000000000000..7198c6a23285e157247fa62d02186992a2293d22 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualFlaggedCompact.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SourceCompactCoupling +import OAI.NumberTheory.Jacobsthal.Renewal.FlaggedOccupationBound + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ActualFlaggedCompact + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling +open PrimeCompactVisits FlaggedOccupationBound PersistentFailureFlag ActualFlagInvariant + +variable {w ell S : ℝ} {start : Node} + +noncomputable def compactVisit (K : ℝ) (z : JointState w ell S start) : ℝ≥0∞ := + ENNReal.ofReal (visit K z.1) + +noncomputable def compactPotential (K : ℝ) (z : JointState w ell S start) : ℝ≥0∞ := + ENNReal.ofReal (potential K z.1) + +theorem compactVisit_measurable (K : ℝ) : Measurable (compactVisit (w:=w) (ell:=ell) (S:=S) (start:=start) K) := + (measurable_of_countable (fun p : ChainState w ell S start => ENNReal.ofReal (visit K p))).comp measurable_fst + +theorem compactPotential_measurable (K : ℝ) : Measurable (compactPotential (w:=w) (ell:=ell) (S:=S) (start:=start) K) := + (measurable_of_countable (fun p : ChainState w ell S start => ENNReal.ofReal (potential K p))).comp measurable_fst + +variable (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) + +theorem joint_compact_drift {K : ℝ} (hK : 0 ≤ K) (v mesh : ℝ) (z : JointState w ell S start) : + compactVisit K z+(∫⁻ y,compactPotential K y ∂jointKernel hw hell hS0 hS hr hs hsS v mesh z) ≤ + compactPotential K z := by + have hmeas : Measurable (fun p : ChainState w ell S start => ENNReal.ofReal (potential K p)) := measurable_of_countable _ + have heq : (∫⁻ y,compactPotential K y ∂jointKernel hw hell hS0 hS hr hs hsS v mesh z) = + ∫⁻ p,ENNReal.ofReal (potential K p) ∂chain w ell S start z.1 := by + rw [← jointKernel_left hw hell hS0 hS hr hs hsS v mesh z.1 z.2, + lintegral_map hmeas measurable_fst] + rfl + rw [heq] + exact actual_row_drift hw hell hS0 hS hr hs hsS hK z.1 + +include hw hell hS0 hS hr hsS in + +theorem actual_flagged_compact_visits {K : ℝ} (hK : 0 ≤ K) (mesh : ℝ) (N : ℕ) : + (∑ n ∈ range N, ∫⁻ z,selected (compactVisit K) z ∂CouplingData.sourceLaw w ell S start hs mesh n) ≤ + ENNReal.ofReal (K+1)*CouplingData.sourceLaw w ell S start hs mesh N failed := by + have hbound : ∀ z : JointState w ell S start,compactPotential K z ≤ ENNReal.ofReal (K+1) := + fun z => ENNReal.ofReal_le_ofReal (potential_le hK z.1) + have h := finite_selected_occupation + (jointKernel hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh) + (mismatch_measurable mesh) (compactVisit_measurable K) (compactPotential_measurable K) + ENNReal.ofReal_ne_top hbound + (joint_compact_drift hw hell hS0 hS hr hs hsS hK (Real.log start.gap) mesh) + (FlaggedSourceStart.sourceJoint w ell S start hs) N + exact h + +end NumberTheoryLean.ActualFlaggedCompact + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualNearFullStopGroup.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualNearFullStopGroup.lean new file mode 100644 index 0000000000000000000000000000000000000000..3ff686d863501fa3ef014097aedb8a2ead9610c4 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualNearFullStopGroup.lean @@ -0,0 +1,68 @@ +import OAI.NumberTheory.Jacobsthal.Primes.FrozenPrimeGroup + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ActualNearFullStopGroup +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualSourceTags ActualBinOwners FiniteFirstTag +open StoppedCountVertex StoppedCountAdapters StoppedTraceSets ActualSourceStopBinding +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ActualFrozenStopFamily FrozenPrimeGroup TagBelowStopWindow +open ErdosInversePrimeBin ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem actual_near_full_stop_group (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (hwtop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hwindow : b₁ < w^((1/4:ℝ))) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hs : ps ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) mu)) : + ∃ pre tail : List ℕ,∃ t : Tag (binCount w top xi), + tail ≠ [] ∧ t.index=pre.length ∧ eligible (Y:ℝ) w Cs t.rational ∧ + ps ∈ frozenGroup (lower w top xi t.bin) (width w top xi t.bin) (sourceClass a) t.rational pre tail ∧ + frozenGroup (lower w top xi t.bin) (width w top xi t.bin) (sourceClass a) t.rational pre tail ⊆ + stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) mu) ∧ + (1-eta)*((primeBin (lower w top xi t.bin) (width w top xi t.bin)).card:ℝ) ≤ + (frozenGroup (lower w top xi t.bin) (width w top xi t.bin) (sourceClass a) t.rational pre tail).card := by + let lo := lower w top xi + let wi := width w top xi + let lab := label (zero_lt_one.trans hw) hwtop hxi + let P := sourcePrimeSet w top + have hf := actual_source_stops_first Y w Cs eta Clen B xi b₀ b₁ mu lo wi lab a z P hs + have hcand := hf.2.1 + obtain ⟨t,ht,_hcount,_halign⟩ := hcand.2.2.2.2.2 + obtain ⟨pre,p,tail,heq,hindex,hp,_hbefore⟩ := firstTagFrom_witness + (tagCandidate (Y:ℝ) w Cs eta lo wi lab (sourceClass a)) 0 ps ht + have hwit := candidate_witness (Y:ℝ) w Cs eta lo wi lab (sourceClass a) p hp + have ho : owner (Y:ℝ) w Cs eta (lo t.bin) (wi t.bin) (sourceClass a)=some t.rational := by + rw [hwit.1] + exact hwit.2.2.2.1 + have howner := actual_owner_witness (Nat.cast_nonneg Y) hw (sourceClass a) ho + have hmem : p ∈ primeBin (lo t.bin) (wi t.bin) := by rw [hwit.1]; exact hwit.2.1 + have htail : tail ≠ [] := source_tag_nonterminal Y w Cs eta Clen B xi b₀ b₁ lo wi lab a z pre tail p + hw (fun i => endpoint_pos (zero_lt_one.trans hw) _) (fun i => (effectiveWidth_pos (zero_lt_one.trans hw) hwtop hxi).le) + hwindow hp (by simpa only [heq] using hcand) + refine ⟨pre,tail,t,htail,by simpa only [zero_add] using hindex,howner.1,?_,?_,?_⟩ + · exact (mem_frozenGroup _ _ _ _ _ _ ps).mpr ⟨p,hmem,hwit.2.2.2.2,heq⟩ + · intro qs hqs + obtain ⟨p',hp',ha',rfl⟩ := (mem_frozenGroup _ _ _ _ _ _ qs).mp hqs + subst ps + exact actual_stopped_replacement Y w top Cs eta Clen B xi b₀ b₁ mu hw hwtop hxi hC a z pre tail p p' + hs ht hp hp' ha' + · exact frozenGroup_owner_card (Y:ℝ) w Cs eta (lo t.bin) (wi t.bin) (sourceClass a) t.rational pre tail + (Nat.cast_nonneg Y) hw ho +end NumberTheoryLean.ActualNearFullStopGroup + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualOwnerLocalComparison.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualOwnerLocalComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..1725d7683db45eba40ad646a983adaca65689093 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualOwnerLocalComparison.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Partitions.FullHypotheticalBinLower +import OAI.NumberTheory.Jacobsthal.Partitions.OriginalBinWeightRange + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedArithmetic + +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem missing_weight_bound {α : Type*} (P G : Finset α) (hGP : G ⊆ P) + (w : α → ℝ) (lo eta : ℝ) (hlo : 0 ≤ lo) (heta : 0 ≤ eta) + (hNear : (1-eta)*(P.card : ℝ) ≤ (G.card : ℝ)) + (hW : ∀ p ∈ P,lo ≤ w p ∧ w p ≤ 2*lo) : + (∑ p ∈ P \ G,w p) ≤ 2*eta*(∑ p ∈ P,w p) := by + have hcards : ((P \ G).card : ℝ)+(G.card : ℝ)=(P.card : ℝ) := by + exact_mod_cast Finset.card_sdiff_add_card_eq_card hGP + have hmissing : ((P \ G).card : ℝ) ≤ eta*(P.card : ℝ) := by nlinarith + have hsumlo : (P.card : ℝ)*lo ≤ ∑ p ∈ P,w p := by + simpa only [Finset.sum_const,nsmul_eq_mul] using Finset.sum_le_sum (fun p hp => (hW p hp).1) + calc + _ ≤ ∑ _p ∈ P \ G,2*lo := Finset.sum_le_sum (fun p hp => (hW p (Finset.mem_sdiff.mp hp).1).2) + _ = ((P \ G).card : ℝ)*(2*lo) := by rw [Finset.sum_const,nsmul_eq_mul] + _ ≤ (eta*(P.card : ℝ))*(2*lo) := mul_le_mul_of_nonneg_right hmissing (by positivity) + _ = 2*eta*((P.card : ℝ)*lo) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hsumlo (by positivity) + +theorem near_full_owner_lower {α : Type*} (P G : Finset α) (hGP : G ⊆ P) + (w T : α → ℝ) (lo eta C V : ℝ) (hlo : 0 ≤ lo) (heta : 0 ≤ eta) (hC : 0 ≤ C) (hV : 0 ≤ V) + (hNear : (1-eta)*(P.card : ℝ) ≤ (G.card : ℝ)) + (hW : ∀ p ∈ P,lo ≤ w p ∧ w p ≤ 2*lo) + (hAll : (39/100 : ℝ)*V*(∑ p ∈ P,w p) ≤ ∑ p ∈ P,T p) + (hUpper : ∀ p ∈ P,T p ≤ C*V*w p) (hBudget : 2*C*eta ≤ (1/20 : ℝ)) : + (34/100 : ℝ)*V*(∑ p ∈ P,w p) ≤ ∑ p ∈ G,T p := by + have hw0 (p : α) (hp : p ∈ P) : 0 ≤ w p := hlo.trans (hW p hp).1 + have hsum0 : 0 ≤ ∑ p ∈ P,w p := Finset.sum_nonneg hw0 + have hmiss := missing_weight_bound P G hGP w lo eta hlo heta hNear hW + have hmissT : (∑ p ∈ P \ G,T p) ≤ (1/20 : ℝ)*V*(∑ p ∈ P,w p) := by + calc + _ ≤ ∑ p ∈ P \ G,C*V*w p := Finset.sum_le_sum (fun p hp => hUpper p (Finset.mem_sdiff.mp hp).1) + _ = C*V*(∑ p ∈ P \ G,w p) := (Finset.mul_sum _ _ _).symm + _ ≤ C*V*(2*eta*(∑ p ∈ P,w p)) := mul_le_mul_of_nonneg_left hmiss (mul_nonneg hC hV) + _ = (2*C*eta)*(V*(∑ p ∈ P,w p)) := by ring + _ ≤ (1/20 : ℝ)*(V*(∑ p ∈ P,w p)) := mul_le_mul_of_nonneg_right hBudget (mul_nonneg hV hsum0) + _ = _ := by ring + have hsplit : (∑ p ∈ P \ G,T p)+(∑ p ∈ G,T p)=∑ p ∈ P,T p := Finset.sum_sdiff hGP + nlinarith + +theorem near_full_owner_comparison {α : Type*} (P G : Finset α) (hGP : G ⊆ P) + (w T reference : α → ℝ) (lo eta C V : ℝ) + (hlo : 0 ≤ lo) (heta : 0 ≤ eta) (hC : 0 ≤ C) (hV : 0 ≤ V) + (hNear : (1-eta)*(P.card : ℝ) ≤ (G.card : ℝ)) + (hW : ∀ p ∈ P,lo ≤ w p ∧ w p ≤ 2*lo) + (hAll : (39/100 : ℝ)*V*(∑ p ∈ P,w p) ≤ ∑ p ∈ P,T p) + (hUpper : ∀ p ∈ P,T p ≤ C*V*w p) (hBudget : 2*C*eta ≤ (1/20 : ℝ)) + (hReference : ∀ p ∈ G,reference p ≤ (33/100 : ℝ)*V*w p) : + (1/100 : ℝ)*V*(∑ p ∈ P,w p) ≤ ∑ p ∈ G,(T p-reference p) := by + have howner := near_full_owner_lower P G hGP w T lo eta C V hlo heta hC hV hNear hW hAll hUpper hBudget + have hw0 (p : α) (hp : p ∈ P) : 0 ≤ w p := hlo.trans (hW p hp).1 + have hsub : (∑ p ∈ G,w p) ≤ ∑ p ∈ P,w p := + Finset.sum_le_sum_of_subset_of_nonneg hGP (fun p hp _ => hw0 p hp) + have href : (∑ p ∈ G,reference p) ≤ (33/100 : ℝ)*V*(∑ p ∈ P,w p) := by + calc + _ ≤ ∑ p ∈ G,(33/100 : ℝ)*V*w p := Finset.sum_le_sum hReference + _ = (33/100 : ℝ)*V*(∑ p ∈ G,w p) := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left hsub (by positivity) + rw [Finset.sum_sub_distrib] + linarith + +end ErdosStoppedArithmetic + + + +namespace ErdosStoppedArithmetic +open ErdosStoppedTagSieve ErdosCommonMInterval ErdosInverseAlignment ErdosInversePrimeBin + ErdosPrimeInputs.MertensStrong ErdosInverseCounts + NumberTheoryLean.ReferenceProductsBasics + +attribute [local instance] Classical.propDecidable + +theorem actual_owner_local_comparison : + ∃ eta0 : ℝ,0 < eta0 ∧ eta0 ≤ 1/4 ∧ ∃ P0 : ℕ,2 ≤ P0 ∧ + ∀ Cs : ℝ,0 ≤ Cs → ∃ K : ℝ,0 < K ∧ ∀ rho xi : ℝ,1 < rho → 0 < xi → + ∃ w0 : ℝ,4 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → ∀ P : ℕ,P.Prime → P0 ≤ P → + ∀ R theta eta : ℝ, + Real.exp (K*(Real.log w)^3) ≤ (P : ℝ) → (P : ℝ) ≤ Real.exp (rho*K*(Real.log w)^3) → + Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ R → xi/4 ≤ theta → theta ≤ 1 → + 0 ≤ eta → eta ≤ eta0 → + ∀ Y q : ℕ,0 < Y → 0 < q → ∀ r : ℚ,∀ a : ℕ → ℕ, + (r.den : ℝ) ≤ w^Cs → |(r.num : ℝ)| ≤ (Y : ℝ)*w^(Cs+2) → + (∀ x ∈ Set.Icc R ((1+theta)*R), + 203/100 ≤ lengthExponent P Y x q ∧ lengthExponent P Y x q ≤ 219/100) → + (∀ t ∈ smallPrimeSet (P : ℝ),q.Coprime t) → + (∀ p ∈ primeBin R theta,Squarefree (p*q) ∧ r.den.Coprime p ∧ + p ∉ smallPrimeSet (P : ℝ) ∧ + (∀ t ∈ (p*q).primeFactors,t ≠ p → aligns (fun u => (a u : ℤ)) r t) ∧ + ∀ t ∈ (p*q).primeFactors,P ≤ t) → + (1-eta)*((primeBin R theta).card : ℝ) ≤ + (((primeBin R theta).filter (aligns (fun t => (a t : ℤ)) r)).card : ℝ) → + ∀ reference : ℕ → ℝ, + (∀ p ∈ (primeBin R theta).filter (aligns (fun t => (a t : ℤ)) r), + reference p ≤ (33/100 : ℝ)*primeProduct (P : ℝ)*((Y : ℝ)/((p : ℝ)*q))) → + (1/100 : ℝ)*primeProduct (P : ℝ)*(∑ p ∈ primeBin R theta,(Y : ℝ)/((p : ℝ)*q)) ≤ + ∑ p ∈ (primeBin R theta).filter (aligns (fun t => (a t : ℤ)) r), + ((modulusCount Y (smallPrimeSet (P : ℝ)) a (p*q) : ℝ)-reference p) := by + obtain ⟨C,eta0,hC,heta0,heta01,hBudget,P0,hP0,hUpper⟩ := primeHypothetical_uniform_upper + refine ⟨eta0,heta0,heta01,P0,hP0,?_⟩ + intro Cs hCs + obtain ⟨K,hK,hFull⟩ := hypothetical_full_bin_lower Cs hCs + refine ⟨K,hK,?_⟩ + intro rho xi hrho hxi + obtain ⟨w0,hw0,hF⟩ := hFull rho xi hrho hxi + refine ⟨w0,hw0,?_⟩ + intro w hw P hPrime hP R theta eta hPl hPu hR hThetaLo hThetaHi heta hetaU + Y q hY hq r a hDen hNum hBand hqSmall hGeometry hNear reference hReference + have hR0 : 0 < R := (Real.exp_pos _).trans_le hR + have ht : 0 < theta := (div_pos hxi (by norm_num)).trans_le hThetaLo + have hP1 : (1 : ℝ) < P := by exact_mod_cast hPrime.one_lt + have hAll := hF w hw P R theta hPl hPu hR hThetaLo hThetaHi Y q hY hq r a hDen hNum + hBand hqSmall (fun p hp => + ⟨(hGeometry p hp).1,(hGeometry p hp).2.1,(hGeometry p hp).2.2.1,(hGeometry p hp).2.2.2.1⟩) + have hWeight := original_bin_weight_range Y q R theta (Nat.cast_nonneg Y) + (show (0 : ℝ) < q by exact_mod_cast hq) hR0 ht.le hThetaHi + have hPointUpper : ∀ p ∈ primeBin R theta,primeHypothetical Y (smallPrimeSet (P : ℝ)) a r q p ≤ + C*primeProduct (P : ℝ)*((Y : ℝ)/((p : ℝ)*q)) := by + intro p hp + obtain ⟨hpPrime,hplo,hphi⟩ := (mem_primeBin hR0.le ht.le p).mp hp + have hb := hBand p ⟨hplo.le,hphi⟩ + have hid := reference_rpow hP1 (show (0 : ℝ) < Y by exact_mod_cast hY) + (hR0.trans hplo) (show (0 : ℝ) < q by exact_mod_cast hq) + have hJ : (P : ℝ)^2 ≤ (Y : ℝ)/(p*q : ℕ) := by + have hh := Real.rpow_le_rpow_of_exponent_le hP1.le (show (2 : ℝ) ≤ lengthExponent P Y p q by linarith) + rw [hid] at hh + simpa only [Real.rpow_ofNat,referenceLength,Nat.cast_mul] using hh + have hh := hUpper P hPrime hP Y q p r a hY hpPrime (hGeometry p hp).1 + (hGeometry p hp).2.2.2.2 hJ + simpa only [Nat.cast_mul,mul_assoc,mul_left_comm,mul_comm] using hh + have hBudget' : 2*C*eta ≤ (1/20 : ℝ) := + (mul_le_mul_of_nonneg_left hetaU (by positivity : 0 ≤ 2*C)).trans hBudget + have hh := near_full_owner_comparison (primeBin R theta) + ((primeBin R theta).filter (aligns (fun t => (a t : ℤ)) r)) (Finset.filter_subset _ _) + (fun p => (Y : ℝ)/((p : ℝ)*q)) (primeHypothetical Y (smallPrimeSet (P : ℝ)) a r q) + reference ((Y : ℝ)/(((1+theta)*R)*q)) eta C (primeProduct (P : ℝ)) + hWeight.1 heta hC.le (actual_primeProduct_pos _).le hNear hWeight.2 hAll hPointUpper hBudget' hReference + convert hh using 1 + apply Finset.sum_congr rfl + intro p hp + obtain ⟨hp,ha⟩ := Finset.mem_filter.mp hp + rw [primeHypothetical_agrees Y _ a r q p ((mem_primeBin hR0.le ht.le p).mp hp).1 ha] + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualPrefixClearance.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualPrefixClearance.lean new file mode 100644 index 0000000000000000000000000000000000000000..0325ea70fb5054bf5577193dd8fafdf6f3976e84 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualPrefixClearance.lean @@ -0,0 +1,62 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SourceMarkedStopping + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualPrefixClearance +open FinitePathGeometry PrimeHistories SourceStopPredicate RepresentativeAdmission RepresentativeStopGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open MarkedPrefixTools ErdosPrimeInputs.HarmonicPrimeMeasure + + +def actualClearance (w : ℝ) (z : Node) (Delta : ℝ) (ps : List ℕ) : Prop := + ∀ qs ∈ ps.inits,qs ≠ [] → (terminal w z qs).side=.even → + sourceHeight (terminal w z qs).cutoff+10*Delta < (terminal w z qs).gap + +theorem clearance_supplies_safety {w top xi Clen B : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) (hsmall : 2*(xi/Real.log w) ≤ 6*(2*Clen*xi)) + (z : Node) (ps : List ℕ) (hsource : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) + (hlen : (ps.length:ℝ) ≤ Clen*Real.log B) + (hclear : actualClearance w z (2*Clen*xi) ps) : + representativeSafe w (representative w (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi)) z (2*Clen*xi) ps := by + intro qs hqs hne hside + have hpre := (List.mem_inits _ _).mp hqs + have hsrc : ∀ p ∈ qs,p ∈ sourcePrimeSet w top := fun p hp => hsource p (hpre.subset hp) + have hlenq : (qs.length:ℝ) ≤ Clen*Real.log B := + (by exact_mod_cast hpre.length_le : (qs.length:ℝ) ≤ ps.length).trans hlen + have hlast : qs.getLastD 0 ∈ qs := by + have he : qs.getLastD 0=qs.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hne + have hx := source_representative_error hw htop hxi (hsrc _ hlast) + rw [← terminal_lastD w z qs hne] at hx + have hr := source_prefix_movement hw htop hxi hC hcomp z qs hsrc hlenq + have hxa := abs_of_nonneg hx.1 + apply le_of_lt + apply regular_margin_to_representative (Delta := 2*Clen*xi) (h := xi/Real.log w) + · rw [abs_sub_comm,abs_of_nonneg hr.1] + exact hr.2 + · rw [hxa] + exact hx.2 + · exact hsmall + · exact hclear qs hqs hne hside + +theorem source_mesh_clearance_condition {w xi Clen : ℝ} + (hw : 1 ≤ Real.log w) (hxi : 0 ≤ xi) (hC : 1 ≤ Clen) : + 2*(xi/Real.log w) ≤ 6*(2*Clen*xi) := by + have hdiv : xi/Real.log w ≤ xi := div_le_self hxi hw + have hprod : xi ≤ Clen*xi := by nlinarith + linarith +end NumberTheoryLean.ActualPrefixClearance + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualSampleWitness.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualSampleWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..7ce3006f8cad305d9412828f6c4b6b0c654f6f02 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualSampleWitness.lean @@ -0,0 +1,100 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.GoodSampleSelection + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseCounts +open NumberTheoryLean + +def NodeBadEdge (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) (m u : ℕ) : Prop := + |(modulusCount Y small a (m*u) : ℝ)-(modulusCount Y small a m : ℝ)/(u : ℝ)| > + delta*(Y : ℝ)*V0/((m : ℝ)*(u : ℝ)) + +def WitnessingBadEdge (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) (p q u : ℕ) : Prop := + NodeBadEdge Y small a delta V0 (p*q) u + +theorem modulusCount_child_mass (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (m u : ℕ) (P : Finset ℕ) (hm : m ≠ 0) (hu : Nat.Prime u) : + modulusCount Y small a (m*u) = ResidueSieveTree.mass Y small a + (ResidueSieveTree.child (m.primeFactors,P) u) := by + unfold modulusCount modulusCandidates ResidueSieveTree.mass ResidueSieveTree.child + rw [Nat.primeFactors_mul hm hu.ne_zero,hu.primeFactors,Finset.union_singleton] + +theorem nodeBadEdge_iff_tree_mass (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 : ℝ) (m u : ℕ) (P : Finset ℕ) (hm : m ≠ 0) (hu : Nat.Prime u) : + NodeBadEdge Y small a delta V0 m u ↔ + |(ResidueSieveTree.mass Y small a (ResidueSieveTree.child (m.primeFactors,P) u) : ℝ)- + (ResidueSieveTree.mass Y small a (m.primeFactors,P) : ℝ)/(u : ℝ)| > + delta*(Y : ℝ)*V0/((m : ℝ)*(u : ℝ)) := by + rw [NodeBadEdge,modulusCount_child_mass Y small a m u P hm hu,modulusCount_eq_mass Y small a m P] + +theorem literal_witnessing_bad_edge (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (delta V0 : ℝ) (p q u : ℕ) : + WitnessingBadEdge Y small a delta V0 p q u ↔ + |((NumberTheoryLean.SievePartition.residueCandidates Y (p*q*u).primeFactors small a).card : ℝ)- + ((NumberTheoryLean.SievePartition.residueCandidates Y (p*q).primeFactors small a).card : ℝ)/(u : ℝ)| > + delta*(Y : ℝ)*V0/((p : ℝ)*(q : ℝ)*(u : ℝ)) := by + simp only [WitnessingBadEdge,NodeBadEdge,modulusCount,modulusCandidates,Int.cast_natCast,Nat.cast_mul] + +end ErdosInverseCounts + +end + +section + +namespace ErdosInverseSampleCost +open NumberTheoryLean ErdosInverseStructured ErdosInverseCounts ErdosInverseSampling + +def actualWitness (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) + (P : Finset ℕ) (S R Z cp : ℝ) (pair : ℕ × ℕ) (u : ℕ) : Prop := + Nonstructured P (fun p => (a p : ℤ)) S R Z cp pair.1 pair.2 ∧ + WitnessingBadEdge Y small a delta V0 pair.1 pair.2 u + +theorem selected_actual_witness (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) + (P C U : Finset ℕ) (S R Z cp : ℝ) (h : ℕ) (s : Sample U h) (pair : ℕ × ℕ) : + pair ∈ selectedPairs (P.product C) U (actualWitness Y small a delta V0 P S R Z cp) h s ↔ + pair.1 ∈ P ∧ pair.2 ∈ C ∧ ∀ i : Fin h, + Nonstructured P (fun p => (a p : ℤ)) S R Z cp pair.1 pair.2 ∧ + WitnessingBadEdge Y small a delta V0 pair.1 pair.2 (s i).val := by + classical + rcases pair with ⟨p,q⟩ + constructor + · intro hmem + obtain ⟨hpq,htests⟩ := Finset.mem_filter.mp hmem + obtain ⟨hp,hq⟩ := Finset.mem_product.mp hpq + exact ⟨hp,hq,htests⟩ + · rintro ⟨hp,hq,htests⟩ + exact Finset.mem_filter.mpr ⟨Finset.mem_product.mpr ⟨hp,hq⟩,htests⟩ + +theorem actualWitness_iff_counts (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) + (P : Finset ℕ) (S R Z cp : ℝ) (p q u : ℕ) : + actualWitness Y small a delta V0 P S R Z cp (p,q) u ↔ + Nonstructured P (fun p => (a p : ℤ)) S R Z cp p q ∧ + |((SievePartition.residueCandidates Y (p*q*u).primeFactors small a).card : ℝ)- + ((SievePartition.residueCandidates Y (p*q).primeFactors small a).card : ℝ)/(u : ℝ)| > + delta*(Y : ℝ)*V0/((p : ℝ)*(q : ℝ)*(u : ℝ)) := by + rw [actualWitness,literal_witnessing_bad_edge] + +theorem selected_actual_witness_positive (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) + (P C U : Finset ℕ) (S R Z cp : ℝ) (h : ℕ) (hh : 0 < h) (s : Sample U h) (pair : ℕ × ℕ) : + pair ∈ selectedPairs (P.product C) U (actualWitness Y small a delta V0 P S R Z cp) h s ↔ + pair.1 ∈ P ∧ pair.2 ∈ C ∧ Nonstructured P (fun p => (a p : ℤ)) S R Z cp pair.1 pair.2 ∧ + ∀ i : Fin h,WitnessingBadEdge Y small a delta V0 pair.1 pair.2 (s i).val := by + rw [selected_actual_witness] + constructor + · rintro ⟨hp,hq,htests⟩ + exact ⟨hp,hq,(htests ⟨0,hh⟩).1,fun i => (htests i).2⟩ + · rintro ⟨hp,hq,hnon,htests⟩ + exact ⟨hp,hq,fun i => ⟨hnon,htests i⟩⟩ + +end ErdosInverseSampleCost + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualTagFreezing.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualTagFreezing.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf67f611a17894ed812f73a82c8678d463988436 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualTagFreezing.lean @@ -0,0 +1,791 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceCutoffRecurrence +import OAI.NumberTheory.Jacobsthal.Paths.CorrectSearchTags +import OAI.NumberTheory.Jacobsthal.Sieve.AlignedPrimeCongruence + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.StoppedCountVertex + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeHistories ReferenceAdmission ReferencePrefixRecurrence +open ReferenceForestTelescoping ReferencePruning SievePartition +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +structure Vertex where + node : Node + required : Finset ℕ + available : Finset ℕ + past : List ℕ + scale : ℝ + +noncomputable def child (w : ℝ) (v : Vertex) (p : ℕ) : Vertex where + node := step w v.node p + required := insert p v.required + available := v.available.filter (fun q => q < p) + past := v.past++[p] + scale := v.scale/(p:ℝ) + +noncomputable def includedPrimes (w : ℝ) (v : Vertex) : Finset ℕ := + v.available.filter fun p => childAdmitted v.node.side v.node.gap (primeExponent w p) + +theorem included_subset (w : ℝ) (v : Vertex) : includedPrimes w v ⊆ v.available := + Finset.filter_subset _ _ + +theorem included_even (w : ℝ) (v : Vertex) (hi : v.node.side = .even) : + includedPrimes w v = v.available := by simp [includedPrimes,hi,childAdmitted] + +theorem child_rank_lt (w : ℝ) (v : Vertex) {p : ℕ} (hp : p ∈ v.available) : + (child w v p).available.card < v.available.card := + Finset.card_lt_card (Finset.filter_ssubset.mpr ⟨p,hp,lt_irrefl p⟩) + +noncomputable def countMass (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : ℝ := + ((residueCandidates Y v.required small a).card : ℝ) + +noncomputable def countSurvivors (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : ℝ := + ((survivors (residueCandidates Y v.required small a) v.available (residueBad a)).card : ℝ) + +theorem countSurvivors_nonneg (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : + 0 ≤ countSurvivors Y small a v := Nat.cast_nonneg _ + +theorem count_partition (w : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : + countSurvivors Y small a v = countMass Y small a v - + ∑ p ∈ v.available,countSurvivors Y small a (child w v p) := by + have h := residue_tree_identity Y v.required small v.available a + unfold countSurvivors countMass child + exact_mod_cast h + +noncomputable def referenceValue (w : ℝ) (v : Vertex) : ℝ := + v.scale*referencePolynomial w v.available v.node.side v.node.gap + +theorem reference_partition (w : ℝ) (v : Vertex) : + referenceValue w v = v.scale - ∑ p ∈ includedPrimes w v,referenceValue w (child w v p) := by + rw [referenceValue,reference_polynomial_recurrence,mul_sub,mul_one,Finset.mul_sum, + includedPrimes,Finset.sum_filter] + congr 1 + apply Finset.sum_congr rfl + intro p _ + by_cases hp : childAdmitted v.node.side v.node.gap (primeExponent w p) + · simp only [ite_eq_left hp,referenceValue,child,step] + ring + · simp only [ite_eq_right hp,mul_zero] + +theorem count_leaf (w : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) + (hv : v.available = ∅) : countSurvivors Y small a v = countMass Y small a v := by + simpa only [hv,Finset.sum_empty,sub_zero] using count_partition w Y small a v + +theorem reference_leaf (w : ℝ) (v : Vertex) (hv : v.available = ∅) : referenceValue w v = v.scale := by + simpa only [includedPrimes,hv,Finset.filter_empty,Finset.sum_empty,sub_zero] using reference_partition w v + +end NumberTheoryLean.StoppedCountVertex + + + +namespace NumberTheoryLean.StoppedEvaluation + +open _root_.Finset +open FinitePathGeometry StoppedCountVertex +attribute [local instance] Classical.propDecidable + +def lowerStop (stop : List ℕ → Prop) (v : Vertex) : Prop := + v.node.side = .even ∧ stop v.past + +noncomputable def evaluate (w : ℝ) (stop : List ℕ → Prop) + (mass exit : Vertex → ℝ) : ℕ → Vertex → ℝ + | 0,v => if lowerStop stop v then exit v else mass v + | n+1,v => if lowerStop stop v then exit v else + mass v - ∑ p ∈ includedPrimes w v,evaluate w stop mass exit n (child w v p) + +theorem evaluate_sub (w : ℝ) (stop : List ℕ → Prop) (M₁ M₂ E₁ E₂ : Vertex → ℝ) + (n : ℕ) (v : Vertex) : + evaluate w stop (fun v => M₁ v-M₂ v) (fun v => E₁ v-E₂ v) n v = + evaluate w stop M₁ E₁ n v-evaluate w stop M₂ E₂ n v := by + induction n generalizing v with + | zero => simp only [evaluate]; split_ifs <;> rfl + | succ n ih => + simp only [evaluate] + split_ifs + · rfl + · simp only [ih,Finset.sum_sub_distrib] + ring + +theorem evaluate_add (w : ℝ) (stop : List ℕ → Prop) (M₁ M₂ E₁ E₂ : Vertex → ℝ) + (n : ℕ) (v : Vertex) : + evaluate w stop (fun v => M₁ v+M₂ v) (fun v => E₁ v+E₂ v) n v = + evaluate w stop M₁ E₁ n v+evaluate w stop M₂ E₂ n v := by + induction n generalizing v with + | zero => simp only [evaluate]; split_ifs <;> rfl + | succ n ih => + simp only [evaluate] + split_ifs + · rfl + · simp only [ih,Finset.sum_add_distrib] + ring + +theorem evaluate_reference (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (hn : v.available.card ≤ n) : + evaluate w stop Vertex.scale (referenceValue w) n v = referenceValue w v := by + induction n generalizing v with + | zero => + have hv : v.available = ∅ := Finset.card_eq_zero.mp (Nat.eq_zero_of_le_zero hn) + simp only [evaluate] + split_ifs + · rfl + · exact (reference_leaf w v hv).symm + | succ n ih => + rw [evaluate] + split_ifs + · rfl + · rw [reference_partition] + congr 1 + apply Finset.sum_congr rfl + intro p hp + apply ih + have hlt := child_rank_lt w v (included_subset w v hp) + omega + +noncomputable def stoppedCount (w : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) : ℝ := + evaluate w stop (countMass Y small a) (countSurvivors Y small a) n v + +theorem stopped_count_reference_difference (w : ℝ) (Y : ℕ) (small : Finset ℕ) + (a : ℕ → ℕ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) (hn : v.available.card ≤ n) : + stoppedCount w Y small a stop n v-referenceValue w v = + evaluate w stop (fun z => countMass Y small a z-z.scale) (fun _ => 0) n v + + evaluate w stop (fun _ => 0) (fun z => countSurvivors Y small a z-referenceValue w z) n v := by + rw [← evaluate_reference w stop n v hn] + change evaluate w stop (countMass Y small a) (countSurvivors Y small a) n v - _ = _ + rw [← evaluate_sub] + have h := evaluate_add w stop (fun z => countMass Y small a z-z.scale) (fun _ => 0) + (fun _ => 0) (fun z => countSurvivors Y small a z-referenceValue w z) n v + simpa only [add_zero,zero_add] using h + +end NumberTheoryLean.StoppedEvaluation + + + +namespace NumberTheoryLean.StoppedVertexHistory + +open _root_.Finset +open FinitePathGeometry PrimeHistories StoppedCountVertex ReferenceForestTelescoping ReferencePruning +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def after (w : ℝ) : Vertex → List ℕ → Vertex + | v,[] => v + | v,p::ps => after w (child w v p) ps + +theorem after_node (w : ℝ) (v : Vertex) (ps : List ℕ) : + (after w v ps).node = terminal w v.node ps := by + induction ps generalizing v with + | nil => rfl + | cons p ps ih => exact ih (child w v p) + +theorem after_past (w : ℝ) (v : Vertex) (ps : List ℕ) : + (after w v ps).past = v.past++ps := by + induction ps generalizing v with + | nil => simp [after] + | cons p ps ih => + change (after w (child w v p) ps).past = _ + rw [ih] + simp [child,List.append_assoc] + +theorem after_required (w : ℝ) (v : Vertex) (ps : List ℕ) : + (after w v ps).required = v.required ∪ ps.toFinset := by + induction ps generalizing v with + | nil => simp [after] + | cons p ps ih => + change (after w (child w v p) ps).required = _ + rw [ih] + ext q + simp only [child,List.toFinset_cons,Finset.mem_union,Finset.mem_insert] + tauto + +theorem after_available (w : ℝ) (v : Vertex) (ps : List ℕ) : + (after w v ps).available = suffixPrimes v.available ps := by + induction ps generalizing v with + | nil => simp [after,suffixPrimes_nil] + | cons p ps ih => + change (after w (child w v p) ps).available = _ + rw [ih,suffixPrimes_cons] + rfl + +theorem after_scale (w : ℝ) (v : Vertex) (ps : List ℕ) : + (after w v ps).scale = v.scale*prefixWeight ps := by + induction ps generalizing v with + | nil => simp [after,prefixWeight] + | cons p ps ih => + change (after w (child w v p) ps).scale = _ + rw [ih] + change (v.scale/(p:ℝ))*prefixWeight ps = v.scale*((p:ℝ)⁻¹*prefixWeight ps) + ring + +theorem prefixWeight_product (ps : List ℕ) : prefixWeight ps = ((ps.prod:ℕ):ℝ)⁻¹ := by + induction ps with + | nil => simp [prefixWeight] + | cons p ps ih => + change (p:ℝ)⁻¹*prefixWeight ps = ((p*ps.prod:ℕ):ℝ)⁻¹ + rw [ih,Nat.cast_mul,mul_inv_rev] + ring + +theorem after_scale_product (w : ℝ) (v : Vertex) (ps : List ℕ) : + (after w v ps).scale = v.scale/((ps.prod:ℕ):ℝ) := by + rw [after_scale,prefixWeight_product,div_eq_mul_inv] + +end NumberTheoryLean.StoppedVertexHistory + + + +namespace NumberTheoryLean.StoppedCountLowerBound + +open _root_.Finset +open FinitePathGeometry PrimeHistories StoppedCountVertex StoppedEvaluation +attribute [local instance] Classical.propDecidable + +theorem actual_stopped_bounds (w : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) (hn : v.available.card ≤ n) : + (v.node.side = .even → stoppedCount w Y small a stop n v ≤ countSurvivors Y small a v) ∧ + (v.node.side = .odd → countSurvivors Y small a v ≤ stoppedCount w Y small a stop n v) := by + induction n generalizing v with + | zero => + have hv : v.available = ∅ := Finset.card_eq_zero.mp (Nat.eq_zero_of_le_zero hn) + have he : stoppedCount w Y small a stop 0 v = countSurvivors Y small a v := by + rw [stoppedCount,evaluate] + split_ifs + · rfl + · exact (count_leaf w Y small a v hv).symm + rw [he] + exact ⟨fun _ => le_rfl,fun _ => le_rfl⟩ + | succ n ih => + have hRank : ∀ p ∈ v.available,(child w v p).available.card ≤ n := by + intro p hp + have hlt := child_rank_lt w v hp + omega + have hPart := count_partition w Y small a v + constructor + · intro hi + unfold stoppedCount + rw [evaluate] + split_ifs + · exact le_rfl + · rw [included_even w v hi] + have hsum : (∑ p ∈ v.available,countSurvivors Y small a (child w v p)) ≤ + ∑ p ∈ v.available,evaluate w stop (countMass Y small a) (countSurvivors Y small a) n (child w v p) := by + apply Finset.sum_le_sum + intro p hp + exact (ih (child w v p) (hRank p hp)).2 (by simp [child,step,hi,Side.flip]) + linarith + · intro hi + have hstop : ¬lowerStop stop v := by simp [lowerStop,hi] + unfold stoppedCount + rw [evaluate,ite_eq_right hstop] + have hsum : (∑ p ∈ includedPrimes w v, + evaluate w stop (countMass Y small a) (countSurvivors Y small a) n (child w v p)) ≤ + ∑ p ∈ includedPrimes w v,countSurvivors Y small a (child w v p) := by + apply Finset.sum_le_sum + intro p hp + exact (ih (child w v p) (hRank p (included_subset w v hp))).1 (by simp [child,step,hi,Side.flip]) + have hsub : (∑ p ∈ includedPrimes w v,countSurvivors Y small a (child w v p)) ≤ + ∑ p ∈ v.available,countSurvivors Y small a (child w v p) := + Finset.sum_le_sum_of_subset_of_nonneg (included_subset w v) + (fun p _ _ => countSurvivors_nonneg Y small a (child w v p)) + linarith + +theorem actual_stopped_lower_bound (w : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (stop : List ℕ → Prop) (v : Vertex) (hi : v.node.side = .even) : + stoppedCount w Y small a stop v.available.card v ≤ countSurvivors Y small a v := + (actual_stopped_bounds w Y small a stop v.available.card v le_rfl).1 hi + +end NumberTheoryLean.StoppedCountLowerBound + + + +namespace NumberTheoryLean.StoppedTraceSets + +open _root_.Set _root_.Finset +open FinitePathGeometry StoppedCountVertex StoppedEvaluation StoppedVertexHistory +attribute [local instance] Classical.propDecidable + +noncomputable def childrenTraces (P : Finset ℕ) (T : ℕ → Finset (List ℕ)) : Finset (List ℕ) := + P.biUnion (fun p => (T p).image (List.cons p)) + +theorem nil_not_childrenTraces (P : Finset ℕ) (T : ℕ → Finset (List ℕ)) : + [] ∉ childrenTraces P T := by simp [childrenTraces] + +theorem sum_childrenTraces (P : Finset ℕ) (T : ℕ → Finset (List ℕ)) (F : List ℕ → ℝ) : + (∑ ps ∈ childrenTraces P T,F ps) = ∑ p ∈ P,∑ ps ∈ T p,F (p::ps) := by + have hd : (P:Set ℕ).PairwiseDisjoint (fun p => (T p).image (List.cons p)) := by + intro p _ q _ hpq + apply Finset.disjoint_left.mpr + intro ps hp hq + obtain ⟨xp,_hxp,hxp⟩ := Finset.mem_image.mp hp + obtain ⟨xq,_hxq,hxq⟩ := Finset.mem_image.mp hq + exact hpq (List.cons.inj (hxp.trans hxq.symm)).1 + rw [childrenTraces,Finset.sum_biUnion hd] + apply Finset.sum_congr rfl + intro p _ + rw [Finset.sum_image] + intro a _ b _ heq + exact (List.cons.inj heq).2 + +noncomputable def traces (w : ℝ) (stop : List ℕ → Prop) : ℕ → Vertex → + Finset (List ℕ) × Finset (List ℕ) + | 0,v => if lowerStop stop v then (∅,{[]}) else ({[]},∅) + | n+1,v => if lowerStop stop v then (∅,{[]}) else + (insert [] (childrenTraces (includedPrimes w v) (fun p => (traces w stop n (child w v p)).1)), + childrenTraces (includedPrimes w v) (fun p => (traces w stop n (child w v p)).2)) + +noncomputable def expanded (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) : Finset (List ℕ) := + (traces w stop n v).1 + +noncomputable def stopped (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) : Finset (List ℕ) := + (traces w stop n v).2 + +theorem stopped_lower (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ stopped w stop n v) : (after w v ps).node.side = .even := by + induction n generalizing v ps with + | zero => + unfold stopped at hp + rw [traces] at hp + split_ifs at hp with hs + · have heq : ps = [] := Finset.mem_singleton.mp hp + subst ps + exact hs.1 + · exact False.elim (Finset.notMem_empty _ hp) + | succ n ih => + unfold stopped at hp + rw [traces] at hp + split_ifs at hp with hs + · have heq : ps = [] := Finset.mem_singleton.mp hp + subst ps + exact hs.1 + · obtain ⟨p,_hp,hps⟩ := Finset.mem_biUnion.mp hp + obtain ⟨tail,ht,rfl⟩ := Finset.mem_image.mp hps + exact ih (child w v p) ht + +theorem signed_childrenTraces (w : ℝ) (v : Vertex) (P : Finset ℕ) + (T : ℕ → Finset (List ℕ)) (G : Vertex → ℝ) : + (∑ ps ∈ childrenTraces P T,(-1:ℝ)^ps.length*G (after w v ps)) = + -(∑ p ∈ P,∑ ps ∈ T p,(-1:ℝ)^ps.length*G (after w (child w v p) ps)) := by + rw [sum_childrenTraces,← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro p _ + rw [← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro ps _ + simp only [List.length_cons,pow_succ,after] + ring + +end NumberTheoryLean.StoppedTraceSets + + + +namespace NumberTheoryLean.FirstStopSemantics + +open _root_.Finset +open StoppedCountVertex StoppedEvaluation StoppedVertexHistory StoppedTraceSets +attribute [local instance] Classical.propDecidable + +def FirstStop (w : ℝ) (stop : List ℕ → Prop) (v : Vertex) (ps : List ℕ) : Prop := + lowerStop stop (after w v ps) ∧ ∀ pre tail : List ℕ, + ps = pre++tail → tail ≠ [] → ¬lowerStop stop (after w v pre) + +theorem firstStop_nil (w : ℝ) (stop : List ℕ → Prop) (v : Vertex) (hs : lowerStop stop v) : + FirstStop w stop v [] := by + refine ⟨hs,?_⟩ + intro pre tail heq ht + exact False.elim (ht (List.append_eq_nil_iff.mp heq.symm).2) + +theorem stopped_first (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ stopped w stop n v) : FirstStop w stop v ps := by + induction n generalizing v ps with + | zero => + unfold stopped at hp + rw [traces] at hp + split_ifs at hp with hs + · have heq : ps = [] := Finset.mem_singleton.mp hp + subst ps + exact firstStop_nil w stop v hs + · exact False.elim (Finset.notMem_empty _ hp) + | succ n ih => + unfold stopped at hp + rw [traces] at hp + split_ifs at hp with hs + · have heq : ps = [] := Finset.mem_singleton.mp hp + subst ps + exact firstStop_nil w stop v hs + · obtain ⟨p,_hp,hps⟩ := Finset.mem_biUnion.mp hp + obtain ⟨tail,ht,rfl⟩ := Finset.mem_image.mp hps + have hfirst := ih (child w v p) ht + refine ⟨hfirst.1,?_⟩ + intro pre suffix heq hsuffix + cases pre with + | nil => exact hs + | cons q qs => + rw [List.cons_append] at heq + have hhead := (List.cons.inj heq).1 + have htail := (List.cons.inj heq).2 + subst q + exact hfirst.2 qs suffix htail hsuffix + +theorem stopped_prefix_free (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps qs : List ℕ} (hp : ps ∈ stopped w stop n v) (hq : qs ∈ stopped w stop n v) + (hpre : ∃ tail : List ℕ,qs = ps++tail) : ps = qs := by + obtain ⟨tail,heq⟩ := hpre + by_cases ht : tail = [] + · simpa only [ht,List.append_nil] using heq.symm + · exact False.elim ((stopped_first w stop n v hq).2 ps tail heq ht + (stopped_first w stop n v hp).1) + +end NumberTheoryLean.FirstStopSemantics + + + +namespace NumberTheoryLean.FlatStoppedIdentity + +open _root_.Finset +open FinitePathGeometry StoppedCountVertex StoppedEvaluation StoppedVertexHistory StoppedTraceSets +attribute [local instance] Classical.propDecidable + +theorem flat_evaluate (w : ℝ) (stop : List ℕ → Prop) (M E : Vertex → ℝ) (n : ℕ) (v : Vertex) : + evaluate w stop M E n v = + (∑ ps ∈ expanded w stop n v,(-1:ℝ)^ps.length*M (after w v ps)) + + (∑ ps ∈ stopped w stop n v,(-1:ℝ)^ps.length*E (after w v ps)) := by + induction n generalizing v with + | zero => + by_cases hs : lowerStop stop v <;> simp [evaluate,expanded,stopped,traces,hs,after] + | succ n ih => + by_cases hs : lowerStop stop v + · simp [evaluate,expanded,stopped,traces,hs,after] + · simp only [evaluate,hs,ite_false,expanded,stopped,traces] + rw [Finset.sum_insert (nil_not_childrenTraces _ _),signed_childrenTraces,signed_childrenTraces] + simp only [List.length_nil,pow_zero,after,one_mul] + have hsum : (∑ p ∈ includedPrimes w v,evaluate w stop M E n (child w v p)) = + ∑ p ∈ includedPrimes w v, + ((∑ ps ∈ expanded w stop n (child w v p),(-1:ℝ)^ps.length*M (after w (child w v p) ps)) + + (∑ ps ∈ stopped w stop n (child w v p),(-1:ℝ)^ps.length*E (after w (child w v p) ps))) := + Finset.sum_congr rfl (fun p _ => ih (child w v p)) + rw [hsum,Finset.sum_add_distrib] + simp only [expanded,stopped] + ring + +def sideSign : Side → ℝ + | .even => 1 + | .odd => -1 + +theorem sideSign_after (w : ℝ) (v : Vertex) (ps : List ℕ) : + sideSign (after w v ps).node.side = sideSign v.node.side*(-1:ℝ)^ps.length := by + induction ps generalizing v with + | nil => simp [after] + | cons p ps ih => + change sideSign (after w (child w v p) ps).node.side = _ + rw [ih] + simp only [child,PrimeHistories.step,List.length_cons,pow_succ] + cases v.node.side <;> simp only [Side.flip,sideSign] <;> ring + +theorem stopped_sign_one (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (hi : v.node.side = .even) {ps : List ℕ} (hp : ps ∈ stopped w stop n v) : + (-1:ℝ)^ps.length = 1 := by + have h := sideSign_after w v ps + rw [stopped_lower w stop n v hp,hi] at h + simpa only [sideSign,one_mul] using h.symm + +theorem literal_stopped_difference (w : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (hn : v.available.card ≤ n) (hi : v.node.side = .even) : + stoppedCount w Y small a stop n v-referenceValue w v = + (∑ ps ∈ expanded w stop n v,(-1:ℝ)^ps.length* + (countMass Y small a (after w v ps)-(after w v ps).scale)) + + (∑ ps ∈ stopped w stop n v, + (countSurvivors Y small a (after w v ps)-referenceValue w (after w v ps))) := by + rw [stopped_count_reference_difference w Y small a stop n v hn, + flat_evaluate w stop (fun z => countMass Y small a z-z.scale) (fun _ => 0), + flat_evaluate w stop (fun _ => 0) (fun z => countSurvivors Y small a z-referenceValue w z)] + simp only [mul_zero,Finset.sum_const_zero,add_zero,zero_add] + congr 1 + apply Finset.sum_congr rfl + intro ps hp + rw [stopped_sign_one w stop n v hi hp,one_mul] + +theorem actual_reference_error_lower_bound (w : ℝ) (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) + (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (hn : v.available.card ≤ n) (hi : v.node.side = .even) : + referenceValue w v + + (∑ ps ∈ expanded w stop n v,(-1:ℝ)^ps.length* + (countMass Y small a (after w v ps)-(after w v ps).scale)) + + (∑ ps ∈ stopped w stop n v, + (countSurvivors Y small a (after w v ps)-referenceValue w (after w v ps))) ≤ + countSurvivors Y small a v := by + have h := literal_stopped_difference w Y small a stop n v hn hi + have hL := (StoppedCountLowerBound.actual_stopped_bounds w Y small a stop n v hn).1 hi + linarith + +end NumberTheoryLean.FlatStoppedIdentity + + + +namespace NumberTheoryLean.StoppedTraceAdmission + +open _root_.Finset +open FinitePathGeometry PrimeHistories StoppedCountVertex StoppedTraceSets +open ReferenceAdmission ReferencePruning ReferencePrefixRecurrence +open ErdosPrimeInputs.PrimePrefixMass +attribute [local instance] Classical.propDecidable + +theorem reference_nil_mem (w : ℝ) (v : Vertex) : + [] ∈ referencePrefixes w v.available v.node.side v.node.gap := by + apply Finset.mem_filter.mpr + exact ⟨mem_decreasingPrefixes.mpr ⟨by simp,by simp⟩,trivial⟩ + +theorem reference_child_cons (w : ℝ) (v : Vertex) {p : ℕ} (hp : p ∈ includedPrimes w v) + {ps : List ℕ} (hps : ps ∈ referencePrefixes w (child w v p).available + (child w v p).node.side (child w v p).node.gap) : + p::ps ∈ referencePrefixes w v.available v.node.side v.node.gap := by + have hchild := Finset.mem_filter.mp hp + have htail := Finset.mem_filter.mp hps + have hSuf : ps ∈ decreasingPrefixes (suffixPrimes v.available [p]) := by + simpa only [suffixPrimes,List.mem_singleton,forall_eq,child] using htail.1 + have hdec := (append_mem_decreasing_iff (singleton_prefix_mem hchild.1)).mpr hSuf + apply Finset.mem_filter.mpr + refine ⟨by simpa only [List.singleton_append] using hdec,?_⟩ + exact ⟨hchild.2,htail.2⟩ + +theorem trace_reference_member (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ expanded w stop n v ∨ ps ∈ stopped w stop n v) : + ps ∈ referencePrefixes w v.available v.node.side v.node.gap := by + induction n generalizing v ps with + | zero => + by_cases hs : StoppedEvaluation.lowerStop stop v + · have heq : ps = [] := by simpa [expanded,stopped,traces,hs] using hp + subst ps + exact reference_nil_mem w v + · have heq : ps = [] := by simpa [expanded,stopped,traces,hs] using hp + subst ps + exact reference_nil_mem w v + | succ n ih => + by_cases hs : StoppedEvaluation.lowerStop stop v + · have heq : ps = [] := by simpa [expanded,stopped,traces,hs] using hp + subst ps + exact reference_nil_mem w v + · rcases hp with hExp | hStop + · simp only [expanded,traces,hs,ite_false,Finset.mem_insert] at hExp + rcases hExp with rfl | hExp + · exact reference_nil_mem w v + · obtain ⟨p,hp,hps⟩ := Finset.mem_biUnion.mp hExp + obtain ⟨tail,ht,rfl⟩ := Finset.mem_image.mp hps + exact reference_child_cons w v hp (ih (child w v p) (Or.inl ht)) + · simp only [stopped,traces,hs,ite_false] at hStop + obtain ⟨p,hp,hps⟩ := Finset.mem_biUnion.mp hStop + obtain ⟨tail,ht,rfl⟩ := Finset.mem_image.mp hps + exact reference_child_cons w v hp (ih (child w v p) (Or.inr ht)) + +theorem trace_nodup (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ expanded w stop n v ∨ ps ∈ stopped w stop n v) : ps.Nodup := by + have h := (mem_decreasingPrefixes.mp (Finset.mem_filter.mp (trace_reference_member w stop n v hp)).1).1 + exact h.imp (fun h => ne_of_gt h) + +theorem trace_primes (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (hP : ∀ p ∈ v.available,Nat.Prime p) {ps : List ℕ} + (hp : ps ∈ expanded w stop n v ∨ ps ∈ stopped w stop n v) : ∀ p ∈ ps,Nat.Prime p := by + have h := (mem_decreasingPrefixes.mp (Finset.mem_filter.mp (trace_reference_member w stop n v hp)).1).2 + intro p hps + exact hP p (h p hps) + +end NumberTheoryLean.StoppedTraceAdmission + + + +namespace NumberTheoryLean.StoppedCountAdapters + +open _root_.Finset +open FinitePathGeometry PrimeHistories StoppedCountVertex StoppedEvaluation StoppedVertexHistory +open StoppedTraceSets FlatStoppedIdentity ReferenceAdmission ReferencePruning +attribute [local instance] Classical.propDecidable + +noncomputable def rootVertex (z : Node) (H P : Finset ℕ) (mu : ℝ) : Vertex := + ⟨z,H,P,[],mu⟩ + +theorem countMass_eq_tree_mass (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : + countMass Y small a v = (ResidueSieveTree.mass Y small a (v.required,v.available) : ℝ) := by + simp only [countMass,ResidueSieveTree.mass,Int.cast_natCast] + +theorem countSurvivors_eq_tree_survivors (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (v : Vertex) : + countSurvivors Y small a v = + (ResidueSieveTree.survivorCount Y small a (v.required,v.available) : ℝ) := by + simp only [countSurvivors,ResidueSieveTree.survivorCount,Int.cast_natCast] + +theorem root_after_mass (w : ℝ) (Y : ℕ) (small H P : Finset ℕ) (a : ℕ → ℕ) + (z : Node) (mu : ℝ) (ps : List ℕ) : + countMass Y small a (after w (rootVertex z H P mu) ps) = + (ResidueSieveTree.mass Y small a (H ∪ ps.toFinset,suffixPrimes P ps) : ℝ) := by + rw [countMass_eq_tree_mass,after_required,after_available] + rfl + +theorem root_after_survivors (w : ℝ) (Y : ℕ) (small H P : Finset ℕ) (a : ℕ → ℕ) + (z : Node) (mu : ℝ) (ps : List ℕ) : + countSurvivors Y small a (after w (rootVertex z H P mu) ps) = + (ResidueSieveTree.survivorCount Y small a (H ∪ ps.toFinset,suffixPrimes P ps) : ℝ) := by + rw [countSurvivors_eq_tree_survivors,after_required,after_available] + rfl + +theorem root_after_reference (w : ℝ) (H P : Finset ℕ) (z : Node) (mu : ℝ) (ps : List ℕ) : + referenceValue w (after w (rootVertex z H P mu) ps) = + (mu/(ps.prod:ℝ))*referencePolynomial w (suffixPrimes P ps) + (terminal w z ps).side (terminal w z ps).gap := by + rw [referenceValue,after_scale_product,after_available,after_node] + rfl + +theorem literal_root_lower_comparison (w : ℝ) (Y : ℕ) (small H P : Finset ℕ) + (a : ℕ → ℕ) (z : Node) (mu : ℝ) (stop : List ℕ → Prop) (hi : z.side = .even) : + mu*referencePolynomial w P z.side z.gap + + (∑ ps ∈ expanded w stop P.card (rootVertex z H P mu),(-1:ℝ)^ps.length* + ((ResidueSieveTree.mass Y small a (H ∪ ps.toFinset,suffixPrimes P ps) : ℝ)-mu/(ps.prod:ℝ))) + + (∑ ps ∈ stopped w stop P.card (rootVertex z H P mu), + ((ResidueSieveTree.survivorCount Y small a (H ∪ ps.toFinset,suffixPrimes P ps) : ℝ)- + (mu/(ps.prod:ℝ))*referencePolynomial w (suffixPrimes P ps) + (terminal w z ps).side (terminal w z ps).gap)) ≤ + (ResidueSieveTree.survivorCount Y small a (H,P) : ℝ) := by + have h := actual_reference_error_lower_bound w Y small a stop P.card (rootVertex z H P mu) le_rfl hi + simp only [root_after_mass,root_after_survivors,root_after_reference,after_scale_product] at h + simpa only [countSurvivors_eq_tree_survivors,referenceValue,rootVertex] using h + +end NumberTheoryLean.StoppedCountAdapters + + + +namespace NumberTheoryLean.SourceStopPredicate + +open _root_.Set _root_.Finset +open FinitePathGeometry PrimeHistories ReferenceAdmission RepresentativeAdmission RepresentativeStopGeometry +open PrimeBinRepresentatives ActualSourceTags ActualBinOwners FiniteFirstTag +open ErdosInversePrimeBin ErdosInverseAlignment ErdosPrimeInputs.HarmonicPrimeMeasure +attribute [local instance] Classical.propDecidable + +def sourceClass (a : ℕ → ℕ) (p : ℕ) : ℤ := a p + +noncomputable def representative {n : ℕ} (w : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (p : ℕ) : ℝ := rightExponent w (lower (label p)) (width (label p)) + +def boxed {n : ℕ} (lower width : Fin n → ℝ) (label : ℕ → Fin n) (ps : List ℕ) : Prop := + ∀ p ∈ ps,p ∈ primeBin (lower (label p)) (width (label p)) + +def representativeSafe (w : ℝ) (rep : ℕ → ℝ) (z : Node) (Delta : ℝ) (ps : List ℕ) : Prop := + ∀ qs ∈ ps.inits,qs ≠ [] → (terminal w z qs).side = .even → + sourceHeight (rep (qs.getLastD 0))+3*Delta ≤ representativeGap rep z.gap qs + +noncomputable def representativeWindow (rep : ℕ → ℝ) (z : Node) (b₀ b₁ : ℝ) (ps : List ℕ) : Prop := + b₀ ≤ rep (ps.getLastD 0) ∧ rep (ps.getLastD 0) ≤ b₁ ∧ + 206/100 ≤ representativeGap rep z.gap ps/rep (ps.getLastD 0) ∧ + representativeGap rep z.gap ps/rep (ps.getLastD 0) ≤ 216/100 + +noncomputable def stopCandidate {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) : Prop := + ps ≠ [] ∧ (ps.length:ℝ) ≤ Clen*Real.log B ∧ boxed lower width label ps ∧ + representativeSafe w (representative w lower width label) z (2*Clen*xi) ps ∧ + representativeWindow (representative w lower width label) z b₀ b₁ ps ∧ + ∃ t : Tag n,sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) ps = some t ∧ + (ps.map label).count t.bin = 1 ∧ ∀ p ∈ ps,aligns (sourceClass a) t.rational p + +theorem empty_not_candidate {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) : + ¬stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z [] := by + simp [stopCandidate] + +theorem finite_safe_admits (w : ℝ) (rep : ℕ → ℝ) (z : Node) (Delta : ℝ) (ps : List ℕ) + (hDelta : 0 ≤ Delta) (hrep : ∀ p ∈ ps,primeExponent w p ≤ rep p) + (hs : representativeSafe w rep z Delta ps) : admitted w z.side z.gap ps := by + apply representative_safety_preserves_admission w rep z ps hDelta hrep + intro pre p tail heq hside + have hmem : pre++[p] ∈ ps.inits := by + apply (List.mem_inits _ _).mpr + exact ⟨tail,by simpa only [List.append_assoc,List.singleton_append] using heq.symm⟩ + have h := hs (pre++[p]) hmem (by simp) hside + rwa [List.getLastD_concat] at h + +theorem candidate_admitted {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hw : 1 < w) (hC : 0 ≤ Clen) (hxi : 0 ≤ xi) + (hlo : ∀ b,0 < lower b) (hwidth : ∀ b,0 ≤ width b) + (hc : stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z ps) : + admitted w z.side z.gap ps := by + apply finite_safe_admits w (representative w lower width label) z (2*Clen*xi) ps (by positivity) + · intro p hp + exact (bin_exponent_bounds hw (hlo (label p)) (hwidth (label p)) (hc.2.2.1 p hp)).2 + · exact hc.2.2.2.1 + +theorem candidate_owner_witness {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hw : 1 < w) (hc : stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z ps) : + ∃ t : Tag n,sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) ps = some t ∧ + (ps.map label).count t.bin = 1 ∧ eligible (Y:ℝ) w Cs t.rational ∧ + (1-eta)*((primeBin (lower t.bin) (width t.bin)).card:ℝ) ≤ + (((primeBin (lower t.bin) (width t.bin)).filter (aligns (sourceClass a) t.rational)).card:ℝ) ∧ + ∀ p ∈ ps,aligns (sourceClass a) t.rational p := by + obtain ⟨t,ht,hm,ha⟩ := hc.2.2.2.2.2 + obtain ⟨_pre,_p,_tail,_hps,_hidx,hbin,_hp,_hsearch,ho,_hpa,_hbefore⟩ := + sourceTag_witness (Y:ℝ) w Cs eta lower width label (sourceClass a) ps ht + have hOwner := actual_owner_witness (Nat.cast_nonneg Y) hw (sourceClass a) ho + rw [← hbin] at hOwner + exact ⟨t,ht,hm,hOwner.1,hOwner.2,ha⟩ + +end NumberTheoryLean.SourceStopPredicate + + + +namespace NumberTheoryLean.ActualTagFreezing + +open ActualSourceTags FiniteFirstTag SourceStopPredicate ErdosInversePrimeBin ErdosInverseAlignment + +theorem sourceTag_replacement {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (pre tail : List ℕ) (p p' : ℕ) {b : Fin n} {q : ℚ} + (ht : tagCandidate Y w Cs eta lower width label a p = some (b,q)) + (hlabel : label p' = label p) + (hp' : p' ∈ primeBin (lower (label p')) (width (label p'))) (ha : aligns a q p') : + sourceTag Y w Cs eta lower width label a (pre++p::tail) = + sourceTag Y w Cs eta lower width label a (pre++p'::tail) := by + have hc := candidate_replacement Y w Cs eta lower width label a p p' ht hlabel hp' ha + exact tag_replacement_invariant _ pre tail p p' hc.symm + +theorem all_prefix_tags_replacement {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (pre tail : List ℕ) (p p' : ℕ) {b : Fin n} {q : ℚ} + (ht : tagCandidate Y w Cs eta lower width label a p = some (b,q)) + (hlabel : label p' = label p) + (hp' : p' ∈ primeBin (lower (label p')) (width (label p'))) (ha : aligns a q p') (k : ℕ) : + sourceTag Y w Cs eta lower width label a ((pre++p::tail).take k) = + sourceTag Y w Cs eta lower width label a ((pre++p'::tail).take k) := by + have hc := candidate_replacement Y w Cs eta lower width label a p p' ht hlabel hp' ha + apply tag_prefix_invariant + simp only [List.map_append,List.map_cons,hc] + +theorem replacement_labels {n : ℕ} (label : ℕ → Fin n) (pre tail : List ℕ) (p p' : ℕ) + (hlabel : label p' = label p) : (pre++p::tail).map label = (pre++p'::tail).map label := by + simp only [List.map_append,List.map_cons,hlabel] + +theorem replacement_representatives {n : ℕ} (w : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (pre tail : List ℕ) (p p' : ℕ) (hlabel : label p' = label p) : + (pre++p::tail).map (representative w lower width label) = + (pre++p'::tail).map (representative w lower width label) := by + simp only [List.map_append,List.map_cons,representative,hlabel] + +theorem forall_mem_replacement_iff (A : ℕ → Prop) (pre tail : List ℕ) (p q : ℕ) + (hp : A p) (hq : A q) : + (∀ r ∈ pre++p::tail,A r) ↔ (∀ r ∈ pre++q::tail,A r) := by + have h (p q : ℕ) (hq : A q) (H : ∀ r ∈ pre++p::tail,A r) : ∀ r ∈ pre++q::tail,A r := by + intro r hr + rcases List.mem_append.mp hr with hr | hr + · exact H r (List.mem_append.mpr (Or.inl hr)) + · rcases List.mem_cons.mp hr with rfl | hr + · exact hq + · exact H r (List.mem_append.mpr (Or.inr (List.mem_cons_of_mem _ hr))) + exact ⟨h p q hq,h q p hp⟩ + +end NumberTheoryLean.ActualTagFreezing + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualThresholdArrival.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualThresholdArrival.lean new file mode 100644 index 0000000000000000000000000000000000000000..6495604f992086a2de0a3e095d91d0696ba633e0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualThresholdArrival.lean @@ -0,0 +1,433 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalCoupledHistories +import OAI.NumberTheory.Jacobsthal.Partitions.CanonicalCostCoordinates +import OAI.NumberTheory.Jacobsthal.Probability.EvenThresholdEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.LiveKilledPrefixes + +open _root_.Set Preorder +open FiniteHistoryTransport CemeteryHistoryMap CemeteryKernel + +variable {X : Type*} [MeasurableSpace X] +attribute [local instance] Classical.propDecidable + +theorem live_coordinate_original (E : Set X) (N k : ℕ) (hk : k ≤ N) + (h : Hist X N) (z : X) + (hz : killHist E N h ⟨k,Finset.mem_Iic.mpr hk⟩ = Sum.inl z) : + h ⟨k,Finset.mem_Iic.mpr hk⟩ = z ∧ + aliveThrough E k (frestrictLe₂ (π := fun _ => X) hk h) := by + rw [killHist_coordinate E N k hk h] at hz + split_ifs at hz with ha + · exact ⟨Sum.inl_injective hz,ha⟩ + · simp [dead] at hz + +theorem live_prefix_preserved (E : Set X) (N k : ℕ) (hk : k ≤ N) + (h : Hist X N) (z : X) + (hz : killHist E N h ⟨k,Finset.mem_Iic.mpr hk⟩ = Sum.inl z) + (j : ℕ) (hj : j ≤ k) : + killHist E N h ⟨j,Finset.mem_Iic.mpr (hj.trans hk)⟩ = + Sum.inl (h ⟨j,Finset.mem_Iic.mpr (hj.trans hk)⟩) := by + have ha := (live_coordinate_original E N k hk h z hz).2 + have hjA : aliveThrough E j (frestrictLe₂ (π := fun _ => X) (hj.trans hk) h) := by + intro i hi + exact ha ⟨i,Finset.mem_Iic.mpr ((Finset.mem_Iic.mp i.2).trans hj)⟩ hi + rw [killHist_coordinate E N j (hj.trans hk) h,ite_eq_left hjA] + +end NumberTheoryLean.LiveKilledPrefixes + +end + +section + +namespace NumberTheoryLean.CompletedArrivalOccurrence +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures FiniteHistoryTransport FiniteHistoryOccurrence +open CemeteryKernel CemeteryHistoryMap LiveKilledPrefixes CanonicalCoupledHistories +open PrimeHistories PrimeKilledChain ActualCoupledHistories ActualProcessCoupling + +def liveMember {X : Type*} (E : Set X) : Space X → Prop + | .inl y => y ∈ E + | .inr _ => False + +theorem liveMember_measurable {X : Type*} [MeasurableSpace X] {E : Set X} (hE : MeasurableSet E) : + MeasurableSet {y | liveMember E y} := measurableSet_sum_iff.mpr ⟨hE,MeasurableSet.empty⟩ + +def completedOccurrence {X : Type*} (E : Set X) (N : ℕ) (h : Hist (Space X) N) : Prop := + ∃ j : Fin N,liveMember E (atIndex N h j.succ) + +theorem completedOccurrence_measurable {X : Type*} [MeasurableSpace X] {E : Set X} + (hE : MeasurableSet E) (N : ℕ) : MeasurableSet {h | completedOccurrence E N h} := by + simp only [completedOccurrence,Set.ofPred_exists] + apply MeasurableSet.iUnion + intro j + have hc : Measurable (fun h : Hist (Space X) N => atIndex N h j.succ) := measurable_pi_apply _ + exact hc (liveMember_measurable hE) + +theorem kill_completed_subset {X : Type*} [MeasurableSpace X] (D E : Set X) (N : ℕ) : + (killHist D N) ⁻¹' {h | completedOccurrence E N h} ⊆ arrivalOccurrence E N := by + rintro h ⟨j,hj⟩ + cases hy : atIndex N (killHist D N h) j.succ with + | inr u => rw [hy] at hj; exact False.elim hj + | inl y => + rw [hy] at hj + have horig := (live_coordinate_original D N (j.1+1) (by have := j.isLt; omega) h y hy).1 + apply Set.mem_iUnion.mpr + refine ⟨j,?_⟩ + change atIndex N h j.succ ∈ E + rw [show atIndex N h j.succ=y from horig] + exact hj + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem source_completed_occurrence_le (mesh : ℝ) (N : ℕ) {E : Set CostState} (hE : MeasurableSet E) : + sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N + ((mapHist (fun q => q.1.2) N) ⁻¹' {h | completedOccurrence E N h}) ≤ + finitePathMeasure (FlaggedSourceStart.typedState start.side start.ratio hs) N (arrivalOccurrence E N) := by + rw [sourceHistoryLaw_canonical_event hw hell hS0 hS hr hs hsS mesh N (completedOccurrence_measurable hE N)] + exact measure_mono (kill_completed_subset _ E N) +end NumberTheoryLean.CompletedArrivalOccurrence + +end + +section + +namespace NumberTheoryLean.CanonicalGapExposure +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures FiniteGapExposure ArrivalKernelGeometry RegeneratingInverseBands +open CanonicalCostCoordinates Erdos970Dependency.MarkedVisits +attribute [local instance] Classical.propDecidable + +def coordinate (N : ℕ) (h : RawHistory N) (j : Fin (N+1)) : CostState := + h ⟨j.1,Finset.mem_Iic.mpr (Nat.le_of_lt_succ j.isLt)⟩ + +noncomputable def pathExposure (v a L : ℝ) (N : ℕ) (h : RawHistory N) : ℝ := + ∑ j : Fin (N+1),if a ≤ gapValue v (coordinate N h j) ∧ stateRatio (coordinate N h j).1 ≤ L + then 1/gapValue v (coordinate N h j) else 0 + +theorem pathExposure_measurable (v a L : ℝ) (N : ℕ) : Measurable (pathExposure v a L N) := by + unfold pathExposure + apply Finset.measurable_sum + intro j _ + have hc : Measurable (fun h : RawHistory N => coordinate N h j) := measurable_pi_apply _ + have hg := (gapValue_measurable v).comp hc + have hs := stateRatio_measurable.comp (measurable_fst.comp hc) + exact Measurable.ite ((measurableSet_le measurable_const hg).inter (measurableSet_le hs measurable_const)) + (measurable_const.div hg) measurable_const + +theorem pathExposure_nonneg (v a L : ℝ) (N : ℕ) (h : RawHistory N) : 0 ≤ pathExposure v a L N h := by + apply Finset.sum_nonneg + intro j _ + split_ifs + · exact one_div_nonneg.mpr (Real.exp_pos _).le + · exact le_rfl + +theorem canonical_gap_steps (v : ℝ) (s : State) (N : ℕ) : + ∀ᵐ h ∂finitePathMeasure s N,∀ j : Fin N, + gapValue v (coordinate N h j.succ)= + nextGap (gapValue v (coordinate N h j.castSucc)) (stateRatio (coordinate N h j.succ).1) := by + have hall : ∀ᵐ h ∂finitePathMeasure s N,∀ j : Fin N, + (coordinate N h j.succ).2=(coordinate N h j.castSucc).2+cost (stateRatio (coordinate N h j.succ).1) := by + apply ae_all_iff.mpr + intro j + exact raw_cost_coordinate (Nat.zero_le _) j.isLt (fun _ => (s,0)) + filter_upwards [hall] with h hh + intro j + have he : coordinate N h j.succ=((coordinate N h j.succ).1, + (coordinate N h j.castSucc).2+cost (stateRatio (coordinate N h j.succ).1)) := Prod.ext rfl (hh j) + calc + _ = gapValue v ((coordinate N h j.succ).1, + (coordinate N h j.castSucc).2+cost (stateRatio (coordinate N h j.succ).1)) := congrArg _ he + _ = _ := gapValue_update v (coordinate N h j.castSucc) (coordinate N h j.succ).1 + +theorem canonical_exposure_bound (v : ℝ) {a L : ℝ} (ha : 0 < a) (hL : 0 ≤ L) + (s : State) (N : ℕ) : + ∀ᵐ h ∂finitePathMeasure s N,pathExposure v a L N h ≤ (L+2)/a := by + filter_upwards [canonical_gap_steps v s N] with h hh + exact finite_all_exposure ha hL N (fun j => gapValue v (coordinate N h j)) + (fun j => stateRatio (coordinate N h j).1) (fun _ => Real.exp_pos _) + (fun j => valid_pos (stateRatio_valid _)) hh + +theorem canonical_exposure_integral (v : ℝ) {a L : ℝ} (ha : 0 < a) (hL : 0 ≤ L) + (s : State) (N : ℕ) : + Integrable (pathExposure v a L N) (finitePathMeasure s N) ∧ + (∫ h,pathExposure v a L N h ∂finitePathMeasure s N) ≤ (L+2)/a := by + have hb := canonical_exposure_bound v ha hL s N + have hi : Integrable (pathExposure v a L N) (finitePathMeasure s N) := by + apply (integrable_const ((L+2)/a)).mono' (pathExposure_measurable v a L N).aestronglyMeasurable + filter_upwards [hb] with h hh + simpa only [Real.norm_eq_abs,abs_of_nonneg (pathExposure_nonneg v a L N h)] using hh + refine ⟨hi,?_⟩ + have hh := integral_mono_ae hi (integrable_const ((L+2)/a)) hb + simpa only [integral_const,probReal_univ,one_smul] using hh +end NumberTheoryLean.CanonicalGapExposure + +end + +section + +namespace NumberTheoryLean.CanonicalEvenArrivalSupport +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures FiniteHistoryTransport FiniteHistoryOccurrence +open ActualCouplingUpdates ActualSupportIntervals CanonicalGapExposure + +def evenArrivalSupport (y : CostState) : Prop := stateSide y.1=.even → 2 ≤ stateRatio y.1 + +theorem evenArrivalSupport_measurable : MeasurableSet {y | evenArrivalSupport y} := by + have he : {y : CostState | evenArrivalSupport y}= + {y : CostState | stateSide y.1=.even}ᶜ ∪ {y | 2 ≤ stateRatio y.1} := by + ext y + simp only [evenArrivalSupport,Set.mem_ofPred_eq,Set.mem_union,Set.mem_compl_iff] + tauto + rw [he] + exact (measurable_fst (side_set_measurable .even)).compl.union + (measurableSet_le measurable_const (stateRatio_measurable.comp measurable_fst)) + +theorem costKernel_even_output (z : CostState) : ∀ᵐ y ∂costKernel z,evenArrivalSupport y := by + filter_upwards [costKernel_follows z,costKernel_lower_support z] with y hy hmin + intro he + cases hi : stateSide z.1 with + | even => + have hh := hy.2 + rw [hi,he] at hh + exact False.elim (Side.noConfusion hh) + | odd => + rw [hi] at hmin + exact (le_max_left (2:ℝ) _).trans hmin + +theorem path_arrival_support {X : Type*} [MeasurableSpace X] + (K : Kernel X X) [IsMarkovKernel K] {P : X → Prop} (hP : MeasurableSet {x | P x}) + (hOut : ∀ x,∀ᵐ y ∂K x,P y) (N : ℕ) (h₀ : Hist X 0) : + ∀ᵐ h ∂pathKernel K N h₀,∀ j : Fin N,P (atIndex N h j.succ) := by + apply ae_all_iff.mpr + intro j + have hm : Measurable (fun h : Hist X N => atIndex N h j.succ) := measurable_pi_apply _ + apply (ae_map_iff hm.aemeasurable hP).mp + rw [atIndex_law] + have he : K^(j.1+1)=K ∘ₖ (K^j.1) := by + simpa only [Nat.add_comm,pow_one] using Kernel.pow_add K 1 j.1 + change ∀ᵐ y ∂(K^(j.1+1)) (last 0 h₀),P y + rw [he] + exact Kernel.ae_comp_of_ae_ae hP (Filter.Eventually.of_forall hOut) + +theorem canonical_even_arrivals (s : State) (N : ℕ) : + ∀ᵐ h ∂finitePathMeasure s N,∀ j : Fin N, + stateSide (coordinate N h j.succ).1=.even → 2 ≤ stateRatio (coordinate N h j.succ).1 := + path_arrival_support costKernel evenArrivalSupport_measurable costKernel_even_output N (fun _ => (s,0)) +end NumberTheoryLean.CanonicalEvenArrivalSupport + +end + +section + +namespace NumberTheoryLean.ThresholdExposureBridge +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open ErdosEvenThreshold TransitionKernels FinitePathGeometry FinitePathMeasures KernelDensityBridge +open CanonicalGapExposure RegeneratingInverseBands +attribute [local instance] Classical.propDecidable + +theorem odd_threshold_zero_high_parent (s : OddState) {R d : ℝ} (hs : 5 < s.1) (hd1 : d ≤ 1) : + oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' nearThreshold R d)=0 := by + rw [← thresholdStrip_eq_near] + have he : oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' thresholdStrip R d)=oddKernel s (thresholdStrip R d) := by + rw [← oddToEven_map_ratio s,Measure.map_apply measurable_subtype_coe (thresholdStrip_measurable R d)] + rw [he,oddKernel_apply] + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [ae_restrict_mem (thresholdStrip_measurable R d)] with t ht + have ht4 := (strip_parameters hd1 ht).2 + have hn : ¬max 2 (s.1-1) ≤ t := by linarith [le_max_right (2:ℝ) (s.1-1)] + have hz : oddDensity s t=0 := by + change (if max 2 (s.1-1) ≤ t then _ else 0)=0 + exact ite_eq_right hn + simp only [hz,ENNReal.ofReal_zero,Pi.zero_apply] + +theorem odd_threshold_zero_small_gap (s : OddState) {R d : ℝ} (hR : R ≤ 4) (hd1 : d ≤ 1) : + oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' nearThreshold R d)=0 := by + rw [← thresholdStrip_eq_near,thresholdStrip_empty hR hd1] + simp + +noncomputable def thresholdHazard (R d : ℝ) : State → ℝ + | .inl _ => 0 + | .inr s => (oddToEven s ((Subtype.val : EvenState → ℝ) ⁻¹' nearThreshold R d)).toReal + +theorem thresholdHazard_exposure (s : State) {R d : ℝ} + (hR : 0 < R) (hd0 : 0 ≤ d) (hd1 : d ≤ 1) : + thresholdHazard R d s ≤ stripConstant*d*(if 4 ≤ R ∧ stateRatio s ≤ 5 then 1/R else 0) := by + have hC : 0 < stripConstant := stripConstant_pos + cases s with + | inl s => + change 0 ≤ _ + split_ifs <;> positivity + | inr s => + by_cases hR4 : 4 ≤ R + · by_cases hs : s.1 ≤ 5 + · simp only [thresholdHazard] + split_ifs with hguard + · simpa only [mul_one_div] using conditional_even_near_threshold_real s hR hd0 hd1 + · exact (hguard ⟨hR4,hs⟩).elim + · rw [thresholdHazard,odd_threshold_zero_high_parent s (lt_of_not_ge hs) hd1] + simp only [ENNReal.toReal_zero,stateRatio,Sum.elim_inr,hs,and_false,ite_false,mul_zero,le_refl] + · rw [thresholdHazard,odd_threshold_zero_small_gap s (le_of_not_ge hR4) hd1] + simp only [ENNReal.toReal_zero,hR4,false_and,ite_false,mul_zero,le_refl] + +theorem canonical_total_threshold_hazard (v : ℝ) {d : ℝ} (hd0 : 0 ≤ d) (hd1 : d ≤ 1) + (s : State) (N : ℕ) : + ∀ᵐ h ∂finitePathMeasure s N, + (∑ j : Fin (N+1),thresholdHazard (gapValue v (coordinate N h j)) d (coordinate N h j).1) ≤ + (7/4:ℝ)*stripConstant*d := by + filter_upwards [canonical_exposure_bound v (by norm_num : (0:ℝ)<4) (by norm_num : (0:ℝ)≤5) s N] with h hh + have hsum : (∑ j : Fin (N+1),thresholdHazard (gapValue v (coordinate N h j)) d (coordinate N h j).1) ≤ + stripConstant*d*pathExposure v 4 5 N h := by + rw [pathExposure,Finset.mul_sum] + apply Finset.sum_le_sum + intro j _ + exact thresholdHazard_exposure _ (Real.exp_pos _) hd0 hd1 + have hm := mul_le_mul_of_nonneg_left hh (mul_nonneg stripConstant_pos.le hd0) + calc + _ ≤ stripConstant*d*((5+2)/4) := hsum.trans hm + _ = _ := by ring +end NumberTheoryLean.ThresholdExposureBridge + +end + +section + +namespace NumberTheoryLean.CoupledEvenArrivalSupport +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures FiniteHistoryTransport CanonicalGapExposure +open FiniteHistoryOccurrence +open CanonicalEvenArrivalSupport CanonicalCoupledHistories CemeteryHistoryMap LiveKilledPrefixes +open ActualCouplingUpdates ActualCoupledHistories ActualProcessCoupling +open PrimeHistories PrimeKilledChain LowStateHorizon + +theorem killed_even_coordinate {E : Set CostState} (hE : MeasurableSet E) + (s : State) (N : ℕ) (j : Fin N) : + ∀ᵐ h ∂(finitePathMeasure s N).map (killHist E N), + liftPredicate evenArrivalSupport (atIndex N h j.succ) := by + have hP : MeasurableSet {h : Hist (CemeteryKernel.Space CostState) N | + liftPredicate evenArrivalSupport (atIndex N h j.succ)} := + (measurable_pi_apply _) (liftPredicate_measurable evenArrivalSupport_measurable) + apply (ae_map_iff (killHist_measurable hE N).aemeasurable hP).mpr + filter_upwards [canonical_even_arrivals s N] with h hh + cases hy : atIndex N (killHist E N h) j.succ with + | inr u => trivial + | inl y => + have horig := (live_coordinate_original E N (j.1+1) (by have := j.isLt; omega) h y hy).1 + change evenArrivalSupport y + rw [← horig] + exact hh j + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistory_even_arrivals (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + ∀ j : Fin N,∀ y : CostState, + (h ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩).1.2=Sum.inl y → + stateSide y.1=.even → 2 ≤ stateRatio y.1 := by + have hall : ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N,∀ j : Fin N, + liftPredicate evenArrivalSupport ((h ⟨j.1+1,Finset.mem_Iic.mpr (by have := j.isLt; omega)⟩).1.2) := by + apply ae_all_iff.mpr + intro j + have hP : MeasurableSet {h : Hist (CemeteryKernel.Space CostState) N | + liftPredicate evenArrivalSupport (atIndex N h j.succ)} := + (measurable_pi_apply _) (liftPredicate_measurable evenArrivalSupport_measurable) + have hh : ∀ᵐ h ∂(sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N).map + (mapHist (fun q => q.1.2) N),liftPredicate evenArrivalSupport (atIndex N h j.succ) := by + rw [sourceHistoryLaw_canonical hw hell hS0 hS hr hs hsS mesh N] + exact killed_even_coordinate (lowDomain_measurable _ _ _) _ N j + exact (ae_map_iff (mapHist_measurable (by exact measurable_snd.comp measurable_fst) N).aemeasurable hP).mp hh + filter_upwards [hall] with h hh + intro j y hy he + have hp := hh j + rw [hy] at hp + exact hp he +end NumberTheoryLean.CoupledEvenArrivalSupport + +end + +section + +namespace NumberTheoryLean.ActualThresholdArrival +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures ArrivalKernelGeometry RegeneratingInverseBands +open ThresholdExposureBridge ErdosEvenThreshold RepresentativeStopGeometry KernelDensityBridge +open ActualCouplingUpdates + +noncomputable def thresholdArrival (v d : ℝ) : Set CostState := + {y | stateSide y.1=.even ∧ 1 < currentExponent v y ∧ + 0 ≤ gapValue v y-sourceHeight (currentExponent v y) ∧ + gapValue v y-sourceHeight (currentExponent v y) ≤ d} + +theorem thresholdArrival_measurable (v d : ℝ) : MeasurableSet (thresholdArrival v d) := by + have hH : Measurable (fun y => sourceHeight (currentExponent v y)) := + ((measurable_const.mul (currentExponent_measurable v))).max + ((currentExponent_measurable v).add_const 2) + have hslack := (gapValue_measurable v).sub hH + exact (measurable_fst (side_set_measurable .even)).inter + ((measurableSet_lt measurable_const (currentExponent_measurable v)).inter + ((measurableSet_le measurable_const hslack).inter (measurableSet_le hslack measurable_const))) + +theorem thresholdArrival_update (v d : ℝ) (z : CostState) (s : State) : + (s,z.2+cost (stateRatio s)) ∈ thresholdArrival v d ↔ + stateSide s=.even ∧ stateRatio s ∈ nearThreshold (gapValue v z) d := by + change stateSide s=.even ∧ _ ↔ _ + rw [currentExponent_update,gapValue_update] + rfl + +theorem thresholdHazard_eq_actual (v d : ℝ) (z : CostState) : + thresholdHazard (gapValue v z) d z.1=(costKernel z (thresholdArrival v d)).toReal := by + rw [costKernel_apply z (thresholdArrival_measurable v d)] + rcases z with ⟨s,T⟩ + cases s with + | inl s => + change 0=(evenBranch s {t | (t,T+cost (stateRatio t)) ∈ thresholdArrival v d}).toReal + rw [evenBranch,Kernel.map_apply' _ measurable_inr _] + · have he : Sum.inr ⁻¹' {t : State | (t,T+cost (stateRatio t)) ∈ thresholdArrival v d}=∅ := by + ext t + change (Sum.inr t,T+cost (stateRatio (Sum.inr t))) ∈ thresholdArrival v d ↔ False + rw [thresholdArrival_update v d ((Sum.inl s),T)] + simp [stateSide] + rw [he,measure_empty,ENNReal.toReal_zero] + · exact (measurable_id.prodMk + (measurable_const.add (cost_measurable.comp stateRatio_measurable))) (thresholdArrival_measurable v d) + | inr s => + change _=(oddBranch s {t | (t,T+cost (stateRatio t)) ∈ thresholdArrival v d}).toReal + rw [oddBranch,Kernel.map_apply' _ measurable_inl _] + · have he : Sum.inl ⁻¹' {t : State | (t,T+cost (stateRatio t)) ∈ thresholdArrival v d}= + (Subtype.val : TransitionKernels.EvenState → ℝ) ⁻¹' nearThreshold (gapValue v ((Sum.inr s),T)) d := by + ext t + change (Sum.inl t,T+cost (stateRatio (Sum.inl t))) ∈ thresholdArrival v d ↔ _ + rw [thresholdArrival_update v d ((Sum.inr s),T)] + simp only [stateSide,stateRatio,Sum.elim_inl,true_and,Set.mem_preimage] + rw [he] + rfl + · exact (measurable_id.prodMk + (measurable_const.add (cost_measurable.comp stateRatio_measurable))) (thresholdArrival_measurable v d) + +theorem actualHazard_measurable (v d : ℝ) : + Measurable (fun z : CostState => thresholdHazard (gapValue v z) d z.1) := by + simp_rw [thresholdHazard_eq_actual] + exact (costKernel.measurable_coe (thresholdArrival_measurable v d)).ennreal_toReal + +theorem actualHazard_bounds (v d : ℝ) (z : CostState) : + 0 ≤ thresholdHazard (gapValue v z) d z.1 ∧ thresholdHazard (gapValue v z) d z.1 ≤ 1 := by + rw [thresholdHazard_eq_actual] + exact ⟨ENNReal.toReal_nonneg,measureReal_le_one⟩ +end NumberTheoryLean.ActualThresholdArrival + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualWordSelection.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualWordSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..56ea364aa845138f9c89ce4ce40ab414a0ce6d24 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ActualWordSelection.lean @@ -0,0 +1,59 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ActualSafeBoxMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualWordSelection +open FinitePathGeometry PrimeHistories SourceStopPredicate +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open ErdosCofactorChoices ErdosSubsetWord + +attribute [local instance] Classical.propDecidable + +noncomputable def wordSelection {n : ℕ} (lab : ℕ → Fin n) (ps : List ℕ) (b : Fin n) : Finset ℕ := + ps.toFinset.filter (fun p => lab p=b) + +noncomputable def wordMultiplicity {n : ℕ} (lab : ℕ → Fin n) (ps : List ℕ) (b : Fin n) : ℕ := + (wordSelection lab ps b).card + +theorem wordSelection_mem {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (ps : List ℕ) (hsource : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) : + wordSelection (label (zero_lt_one.trans hw) htop hxi) ps ∈ selections (globalBins w top xi) + (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps) := by + apply (mem_selections _ _ _).mpr + intro b + refine ⟨?_,rfl⟩ + intro p hp + obtain ⟨hp,hb⟩ := Finset.mem_filter.mp hp + have hh := source_list_boxed (zero_lt_one.trans hw) htop hxi ps hsource p (List.mem_toFinset.mp hp) + simpa only [globalBins,hb] using hh + +theorem wordSelection_recovers {n : ℕ} (lab : ℕ → Fin n) (ps : List ℕ) + (hd : ps.Pairwise (· > ·)) : descendingWord (wordSelection lab ps)=ps := by + apply (descendingWord_strict _).eq_of_mem_iff hd + intro p + simp only [mem_descendingWord,wordSelection,Finset.mem_filter,List.mem_toFinset] + constructor + · rintro ⟨b,hp,_hb⟩ + exact hp + · intro hp + exact ⟨lab p,hp,rfl⟩ + +theorem wordMultiplicity_count {n : ℕ} (lab : ℕ → Fin n) (ps : List ℕ) + (hn : ps.Nodup) (b : Fin n) : wordMultiplicity lab ps b=(ps.map lab).count b := by + have he : ps.toFinset.filter (fun p => lab p=b) = (ps.filter (fun p => lab p==b)).toFinset := by + ext p + simp + rw [wordMultiplicity,wordSelection,he] + rw [List.toFinset_card_of_nodup (hn.filter _)] + rw [List.count,List.countP_map,List.countP_eq_length_filter] + rfl +end NumberTheoryLean.ActualWordSelection + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/AdmittedHarmonicPaths.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/AdmittedHarmonicPaths.lean new file mode 100644 index 0000000000000000000000000000000000000000..ada744845fde0dd9ab8be234e735f8c1f577c8e2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/AdmittedHarmonicPaths.lean @@ -0,0 +1,121 @@ +import OAI.NumberTheory.Jacobsthal.Probability.ArrivalKernelGeometry + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.AdmittedHarmonicPaths + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open FinitePathMeasures RegeneratingInverseBands ArrivalKernelGeometry +open HarmonicWeightKernel KernelWeightTransform KernelExitBarrier + +noncomputable def admittedTilted (v ell : ℝ) : Kernel CostState CostState := + costKernel.restrict (arrivalSet_measurable v ell) + +noncomputable def admittedHarmonic (v ell : ℝ) : Kernel CostState CostState := + harmonicKernel.restrict (arrivalSet_measurable v ell) + +instance admittedTilted_isFiniteKernel (v ell : ℝ) : IsFiniteKernel (admittedTilted v ell) := by + unfold admittedTilted + infer_instance + +instance admittedHarmonic_isSFiniteKernel (v ell : ℝ) : IsSFiniteKernel (admittedHarmonic v ell) := by + unfold admittedHarmonic + infer_instance + +theorem admitted_weight_transform (v ell : ℝ) : + admittedHarmonic v ell = conjugate (admittedTilted v ell) harmonicWeight := + conjugate_restrict costKernel harmonicWeight (arrivalSet_measurable v ell) + +theorem admitted_tilted_final_selection (v ell : ℝ) (n : ℕ) : + (admittedTilted v ell) ^ (n + 1) = (costKernel ^ (n + 1)).restrict (arrivalSet_measurable v ell) := + restricted_pow_eq costKernel (arrivalSet_measurable v ell) (costKernel_no_reentry v ell) n + +theorem admitted_harmonic_final_selection (v ell : ℝ) (n : ℕ) : + (admittedHarmonic v ell) ^ (n + 1) = (harmonicKernel ^ (n + 1)).restrict (arrivalSet_measurable v ell) := + restricted_pow_eq harmonicKernel (arrivalSet_measurable v ell) (harmonicKernel_no_reentry v ell) n + +theorem admitted_prefix_change_of_measure (v ell : ℝ) (n : ℕ) (s : State) + {F : CostState → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F y ∂((admittedHarmonic v ell) ^ n) (s, 0)) = + ENNReal.ofReal (InvariantInverseWeights.stateWeight s) * + ∫⁻ y, ENNReal.ofReal (Real.exp (-2 * y.2) / InvariantInverseWeights.stateWeight y.1) * F y + ∂((admittedTilted v ell) ^ n) (s, 0) := by + rw [admitted_weight_transform, conjugate_pow_lintegral _ harmonicWeight n (s, 0) hF, initial_weight_inv] + rfl + +theorem admitted_tilted_future_selection (v ell : ℝ) : + Kernel.sum (fun n : ℕ => (admittedTilted v ell) ^ (n + 1)) = + OccupationDecomposition.fullOccupation.restrict (arrivalSet_measurable v ell) := + restricted_future_sum costKernel (arrivalSet_measurable v ell) (costKernel_no_reentry v ell) + +theorem admitted_harmonic_future_selection (v ell : ℝ) : + Kernel.sum (fun n : ℕ => (admittedHarmonic v ell) ^ (n + 1)) = + (Kernel.sum (fun n : ℕ => harmonicKernel ^ (n + 1))).restrict (arrivalSet_measurable v ell) := + restricted_future_sum harmonicKernel (arrivalSet_measurable v ell) (harmonicKernel_no_reentry v ell) + +theorem admitted_step_gap_bound (K : Kernel CostState CostState) (v ell : ℝ) + (hflow : ∀ z, ∀ᵐ y ∂K z, gapValue v z = gapValue v y + currentExponent v y) (z : CostState) : + ∀ᵐ y ∂K.restrict (arrivalSet_measurable v ell) z, gapValue v y ≤ gapValue v z - ell := by + rw [Kernel.restrict_apply] + filter_upwards [ae_restrict_of_ae (hflow z), ae_restrict_mem (arrivalSet_measurable v ell)] with y hy ha + change ell < currentExponent v y at ha + linarith + +theorem admitted_pow_gap_bound (K : Kernel CostState CostState) (v ell : ℝ) + (hflow : ∀ z, ∀ᵐ y ∂K z, gapValue v z = gapValue v y + currentExponent v y) + (n : ℕ) (z : CostState) : + ∀ᵐ y ∂((K.restrict (arrivalSet_measurable v ell)) ^ n) z, + gapValue v y ≤ gapValue v z - (n : ℝ) * ell := by + induction n with + | zero => + simp only [Nat.cast_zero] + change ∀ᵐ y ∂Measure.dirac z, gapValue v y ≤ gapValue v z - (0 : ℝ) * ell + exact (ae_dirac_iff (p := fun y => gapValue v y ≤ gapValue v z - (0 : ℝ) * ell) + (measurableSet_le (gapValue_measurable v) measurable_const)).mpr (by simp) + | succ n ih => + have hp : (K.restrict (arrivalSet_measurable v ell)) ^ (n + 1) = + (K.restrict (arrivalSet_measurable v ell)) ∘ₖ ((K.restrict (arrivalSet_measurable v ell)) ^ n) := pow_succ' _ _ + rw [hp] + apply Kernel.ae_comp_of_ae_ae (measurableSet_le (gapValue_measurable v) measurable_const) + filter_upwards [ih] with y hy + filter_upwards [admitted_step_gap_bound K v ell hflow y] with t ht + calc + gapValue v t ≤ gapValue v y - ell := ht + _ ≤ (gapValue v z - (n : ℝ) * ell) - ell := sub_le_sub_right hy ell + _ = _ := by push_cast; ring + +theorem admitted_pow_zero_of_height (K : Kernel CostState CostState) (v ell : ℝ) + (hflow : ∀ z, ∀ᵐ y ∂K z, gapValue v z = gapValue v y + currentExponent v y) + (n : ℕ) (z : CostState) (hn : gapValue v z ≤ (n : ℝ) * ell) : + ((K.restrict (arrivalSet_measurable v ell)) ^ n) z = 0 := by + have hf : ∀ᵐ y ∂((K.restrict (arrivalSet_measurable v ell)) ^ n) z, False := by + filter_upwards [admitted_pow_gap_bound K v ell hflow n z] with y hy + have hp : 0 < gapValue v y := Real.exp_pos _ + linarith + apply Measure.measure_univ_eq_zero.mp + simpa only [ae_iff, not_false_eq_true, Set.ofPred_true] using hf + +theorem admitted_tilted_finite_height (v : ℝ) {ell : ℝ} (hell : 0 < ell) (z : CostState) + (n : ℕ) (hn : ⌈gapValue v z / ell⌉₊ ≤ n) : ((admittedTilted v ell) ^ n) z = 0 := by + apply admitted_pow_zero_of_height costKernel v ell (costKernel_gap_flow v) n z + apply (div_le_iff₀ hell).mp + exact le_trans (Nat.le_ceil _) (by exact_mod_cast hn) + +theorem admitted_harmonic_finite_height (v : ℝ) {ell : ℝ} (hell : 0 < ell) (z : CostState) + (n : ℕ) (hn : ⌈gapValue v z / ell⌉₊ ≤ n) : ((admittedHarmonic v ell) ^ n) z = 0 := by + apply admitted_pow_zero_of_height harmonicKernel v ell (harmonicKernel_gap_flow v) n z + apply (div_le_iff₀ hell).mp + exact le_trans (Nat.le_ceil _) (by exact_mod_cast hn) + +end NumberTheoryLean.AdmittedHarmonicPaths + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/AffineBranch.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/AffineBranch.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd25795780952bd287704b87ef12d4a0ff4d79c8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/AffineBranch.lean @@ -0,0 +1,42 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RegularImplicitArc + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosDivisibleInflection + +theorem affine_of_second_derivative_zero (f : ℝ → ℝ) (a b x : ℝ) + (hx : x ∈ Set.Ioo a b) (hf : ContDiffOn ℝ 2 f (Set.Ioo a b)) + (h2 : ∀ t ∈ Set.Ioo a b, deriv (deriv f) t = 0) : + ∃ A B : ℝ, ∀ t ∈ Set.Ioo a b, f t = A*t+B := by + have hdf : ContDiffOn ℝ 1 (deriv f) (Set.Ioo a b) := hf.deriv_of_isOpen isOpen_Ioo (by norm_num) + have hdconst : Set.EqOn (deriv f) (fun _ => deriv f x) (Set.Ioo a b) := by + apply isOpen_Ioo.eqOn_of_deriv_eq (g := fun _ : ℝ => deriv f x) isPreconnected_Ioo + (hdf.differentiableOn (by norm_num)) (differentiableOn_const (deriv f x)) _ hx rfl + intro t ht + simpa only [deriv_const] using h2 t ht + let A := deriv f x + let B := f x-A*x + have hAffine (t : ℝ) : HasDerivAt (fun t => A*t+B) A t := by + simpa using ((hasDerivAt_id t).const_mul A).add_const B + have he : Set.EqOn f (fun t => A*t+B) (Set.Ioo a b) := by + apply isOpen_Ioo.eqOn_of_deriv_eq (g := fun t => A*t+B) isPreconnected_Ioo + (hf.differentiableOn (by norm_num)) (fun t _ => (hAffine t).differentiableAt.differentiableWithinAt) + _ hx _ + · intro t ht + rw [(hAffine t).deriv] + exact hdconst ht + · dsimp [A,B] + ring + exact ⟨A,B,fun t ht => he ht⟩ + +end ErdosDivisibleInflection + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/BranchWordEndpoint.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/BranchWordEndpoint.lean new file mode 100644 index 0000000000000000000000000000000000000000..a340f140d4f75452513c524ae8e8609374c3cdf6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/BranchWordEndpoint.lean @@ -0,0 +1,99 @@ +import OAI.NumberTheory.Jacobsthal.Probability.JointMarkedWord + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping + +noncomputable def wordSignatureEnd : (k : ℕ) → CycleWordSignature k → CostState + | 0, s => s + | k+1, s => wordSignatureEnd k s.2 + +lemma wordSignatureEnd_measurable (k : ℕ) : Measurable (wordSignatureEnd k) := by + induction k with + | zero => exact measurable_id + | succ k ih => exact ih.comp measurable_snd + +noncomputable def branchWordKernel : List Bool → Kernel OddCost OddCost + | [] => Kernel.id + | b::w => branchWordKernel w ∘ₖ cycleBranchKernel b + +instance branchWordKernel_isFiniteKernel (w : List Bool) : IsFiniteKernel (branchWordKernel w) := by + induction w with + | nil => change IsFiniteKernel (Kernel.id : Kernel OddCost OddCost); infer_instance + | cons b w ih => rw [branchWordKernel]; infer_instance + +lemma branchWordKernel_replicate (b : Bool) (n : ℕ) : + branchWordKernel (List.replicate n b)=cycleBranchKernel b ^ n := by + induction n with + | zero => rfl + | succ n ih => rw [List.replicate_succ,branchWordKernel,ih,pow_succ]; rfl + +lemma branchWordKernel_first_replicate (b c : Bool) (n : ℕ) : + branchWordKernel (b::List.replicate n c)=(cycleBranchKernel c ^ n) ∘ₖ cycleBranchKernel b := by + rw [branchWordKernel,branchWordKernel_replicate] + +lemma sourceMarkedWord_endpoint (w : List Bool) : ∀ z, + (sourceMarkedWordKernel w z).map (wordSignatureEnd w.length) = (branchWordKernel w z).map embedOdd := by + induction w with + | nil => + intro z + change (Measure.dirac (embedOdd z)).map id=(Measure.dirac z).map embedOdd + rw [Measure.map_id,Measure.map_dirac' embedOdd_measurable] + | cons b w ih => + intro z + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (wordSignatureEnd_measurable _),lintegral_map hF embedOdd_measurable, + sourceMarkedWord_cons_lintegral b w z + (F := fun s => F (wordSignatureEnd (b::w).length s)) (hF.comp (wordSignatureEnd_measurable _))] + have hi (y : SourceCycleWitness) : (∫⁻ s, + F (wordSignatureEnd w.length s) ∂sourceMarkedWordKernel w y.2.2) = + ∫⁻ u, F (embedOdd u) ∂branchWordKernel w y.2.2 := by + rw [← lintegral_map (g := wordSignatureEnd w.length) hF (wordSignatureEnd_measurable _),ih, + lintegral_map hF embedOdd_measurable] + change (∫⁻ y : SourceCycleWitness, ∫⁻ s, + F (wordSignatureEnd w.length s) ∂sourceMarkedWordKernel w y.2.2 ∂sourceBranchWitnessKernel b z) = _ + simp_rw [hi] + have hJ : Measurable (fun y : OddCost => ∫⁻ u, F (embedOdd u) ∂branchWordKernel w y) := + (hF.comp embedOdd_measurable).lintegral_kernel + rw [← lintegral_map (g := fun y : SourceCycleWitness => y.2.2) hJ (measurable_snd.comp measurable_snd), + sourceBranchWitness_endpoint,branchWordKernel,Kernel.lintegral_comp _ _ _ (g := fun u : OddCost => F (embedOdd u)) (hF.comp embedOdd_measurable)] + +noncomputable def rawWordReturnedOdd (a : ℕ) (w : List Bool) (t : RawCycleWordTrace a w.length) : OddCost := + decodeReturnedOdd (wordSignatureEnd w.length (rawCycleWordSignature a w.length t)) + +lemma rawWordReturnedOdd_measurable (a : ℕ) (w : List Bool) : Measurable (rawWordReturnedOdd a w) := + decodeReturnedOdd_measurable.comp ((wordSignatureEnd_measurable _).comp (rawCycleWordSignature_measurable _ _)) + +theorem rawMarkedWord_endpoint (a : ℕ) (w : List Bool) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (rawMarkedWordKernel a w h).map (rawWordReturnedOdd a w)=branchWordKernel w z := by + calc + _ = (((rawMarkedWordKernel a w h).map (rawCycleWordSignature a w.length)).map + (wordSignatureEnd w.length)).map decodeReturnedOdd := by + rw [Measure.map_map decodeReturnedOdd_measurable (wordSignatureEnd_measurable _), + Measure.map_map (decodeReturnedOdd_measurable.comp (wordSignatureEnd_measurable _)) + (rawCycleWordSignature_measurable _ _)] + rfl + _ = ((branchWordKernel w z).map embedOdd).map decodeReturnedOdd := by + rw [rawMarkedWord_signature w a h z hz,sourceMarkedWord_endpoint] + _ = _ := by + rw [Measure.map_map decodeReturnedOdd_measurable embedOdd_measurable] + have he : decodeReturnedOdd ∘ embedOdd=id := rfl + rw [he,Measure.map_id] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalHighRatioVisit.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalHighRatioVisit.lean new file mode 100644 index 0000000000000000000000000000000000000000..9aa1cf8f203d80399c8a67a16f0db0f39432de9d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalHighRatioVisit.lean @@ -0,0 +1,97 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.FullOccupationRatioTail + +namespace OAI + +namespace Erdos970 + + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +namespace ErdosHighRatioBandTail +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels +open NumberTheoryLean.FiniteHistoryTransport NumberTheoryLean.OccupationDecomposition + +def positiveVisit (E : Set CostState) (N : ℕ) : Set (∀ _ : Finset.Iic N, CostState) := + ⋃ j : Fin N, {path | path ⟨j.1+1,Finset.mem_Iic.mpr (Nat.succ_le_of_lt j.2)⟩ ∈ E} + +theorem positiveVisit_measurable {E : Set CostState} (hE : MeasurableSet E) (N : ℕ) : + MeasurableSet (positiveVisit E N) := + MeasurableSet.iUnion (fun _ => (measurable_pi_apply _) hE) + +theorem mem_positiveVisit (E : Set CostState) (N : ℕ) + (path : ∀ _ : Finset.Iic N, CostState) : + path ∈ positiveVisit E N ↔ ∃ k : Finset.Iic N, 0 < k.1 ∧ path k ∈ E := by + constructor + · intro h + obtain ⟨j,hj⟩ := mem_iUnion.mp h + exact ⟨⟨j.1+1,Finset.mem_Iic.mpr (Nat.succ_le_of_lt j.2)⟩,Nat.zero_lt_succ j.1,hj⟩ + · rintro ⟨k,hk,hE⟩ + let j : Fin N := ⟨k.1-1,by have := Finset.mem_Iic.mp k.2; omega⟩ + apply mem_iUnion.mpr + refine ⟨j,?_⟩ + have he : (⟨j.1+1,Finset.mem_Iic.mpr (Nat.succ_le_of_lt j.2)⟩ : Finset.Iic N)=k := by + apply Subtype.ext + dsimp [j] + omega + change path _ ∈ E + rwa [he] + +theorem positiveVisit_zero (E : Set CostState) : positiveVisit E 0 = ∅ := by + ext path + simp [positiveVisit] + +theorem canonical_coordinate_law (s : State) (N k : ℕ) (hk : k ≤ N) : + (finitePathMeasure s N).map (fun path => path ⟨k,Finset.mem_Iic.mpr hk⟩) = + (costKernel^k) (s,0) := by + have h := pathMeasure_coordinate costKernel N k hk (fun _ => (s,0)) + have hkernel : pastKernel costKernel = historyKernel := by + funext n + rfl + unfold pathKernel at h + rw [hkernel] at h + simpa only [finitePathMeasure, finitePathKernel, last] using h + +theorem positiveVisit_le_fullOccupation (s : State) (N : ℕ) {E : Set CostState} + (hE : MeasurableSet E) : + finitePathMeasure s N (positiveVisit E N) ≤ fullOccupation (s,0) E := by + calc + _ ≤ ∑ j : Fin N, finitePathMeasure s N + {path | path ⟨j.1+1,Finset.mem_Iic.mpr (Nat.succ_le_of_lt j.2)⟩ ∈ E} := + measure_iUnion_fintype_le (finitePathMeasure s N) _ + _ = ∑ j : Fin N, (costKernel^(j.1+1)) (s,0) E := by + apply Finset.sum_congr rfl + intro j _ + rw [← canonical_coordinate_law s N (j.1+1) (Nat.succ_le_of_lt j.2)] + have hm : Measurable (fun path : (∀ _ : Finset.Iic N, CostState) => + path ⟨j.1+1,Finset.mem_Iic.mpr (Nat.succ_le_of_lt j.2)⟩) := measurable_pi_apply _ + exact (Measure.map_apply hm hE).symm + _ ≤ ∑' k : ℕ, (costKernel^(k+1)) (s,0) E := by + rw [Fin.sum_univ_eq_sum_range (fun k : ℕ => (costKernel^(k+1)) (s,0) E) N] + exact ENNReal.sum_le_tsum (Finset.range N) + _ = fullOccupation (s,0) E := by + rw [fullOccupation, Kernel.sum_apply' _ _ hE] + +theorem uniform_canonical_visit_tail (h eps : ℝ) (heps : 0 < eps) : + ∀ᶠ T : ℝ in atTop, ∀ v : ℝ, ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → ∀ N : ℕ, + finitePathMeasure (.inl s) N (positiveVisit (highBand T v h) N) ≤ ENNReal.ofReal eps := by + filter_upwards [uniform_full_occupation_tail h eps heps] with T hT + intro v s hsL hsU N + exact (positiveVisit_le_fullOccupation (.inl s) N (highBand_measurable T v h)).trans + (hT v s hsL hsU) + +theorem exists_canonical_visit_threshold (h eps : ℝ) (heps : 0 < eps) : + ∃ T₀ : ℝ, 3 ≤ T₀ ∧ ∀ T : ℝ, T₀ ≤ T → ∀ v : ℝ, ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → ∀ N : ℕ, + finitePathMeasure (.inl s) N (positiveVisit (highBand T v h) N) ≤ ENNReal.ofReal eps := by + obtain ⟨T₀,hT₀⟩ := eventually_atTop.mp (uniform_canonical_visit_tail h eps heps) + refine ⟨max T₀ 3,le_max_right _ _,?_⟩ + intro T hT + exact hT₀ T ((le_max_left _ _).trans hT) + +end ErdosHighRatioBandTail + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalKeyWitness.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalKeyWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d7319d3cf70c5cb4116c013fa99c5e026dd0e4c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalKeyWitness.lean @@ -0,0 +1,293 @@ +import Mathlib.Data.Finset.Option +import OAI.NumberTheory.Jacobsthal.Estimates.FrozenSuffixData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.CanonicalStopKey +open ActualSourceTags ActualTagFreezing FiniteFirstTag +open SourceStopPredicate ErdosInversePrimeBin ErdosInverseAlignment + + +structure Key (n : ℕ) where + tag : Tag n + pre : List ℕ + tail : List ℕ + deriving DecidableEq + +noncomputable def stopKey {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (ps : List ℕ) : Option (Key n) := + (sourceTag Y w Cs eta lower width label a ps).map + (fun t => ⟨t,ps.take t.index,ps.drop (t.index+1)⟩) + +theorem stopKey_of_tagged_word {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (pre tail : List ℕ) (p : ℕ) {t : Tag n} + (ht : sourceTag Y w Cs eta lower width label a (pre++p::tail)=some t) + (hi : t.index=pre.length) : + stopKey Y w Cs eta lower width label a (pre++p::tail)=some ⟨t,pre,tail⟩ := by + simp [stopKey,ht,hi,List.take_append,List.drop_append] + +theorem stopKey_witness {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (ps : List ℕ) {k : Key n} + (hk : stopKey Y w Cs eta lower width label a ps=some k) : + ∃ p : ℕ,ps=k.pre++p::k.tail ∧ k.tag.index=k.pre.length ∧ + sourceTag Y w Cs eta lower width label a ps=some k.tag ∧ + tagCandidate Y w Cs eta lower width label a p=some (k.tag.bin,k.tag.rational) := by + cases ht : sourceTag Y w Cs eta lower width label a ps with + | none => simp [stopKey,ht] at hk + | some t => + obtain ⟨pre,p,tail,heq,hi,hp,_hbefore⟩ := firstTagFrom_witness + (tagCandidate Y w Cs eta lower width label a) 0 ps ht + have hi' : t.index=pre.length := by simpa only [zero_add] using hi + have hkey : stopKey Y w Cs eta lower width label a ps=some ⟨t,pre,tail⟩ := by + rw [heq] + exact stopKey_of_tagged_word Y w Cs eta lower width label a pre tail p (by simpa only [heq] using ht) hi' + have he : k=⟨t,pre,tail⟩ := Option.some.inj (hk.symm.trans hkey) + subst k + exact ⟨p,heq,hi',rfl,hp⟩ + +theorem stopKey_replacement {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (ps : List ℕ) {k : Key n} + (hk : stopKey Y w Cs eta lower width label a ps=some k) (p' : ℕ) + (hl : label p'=k.tag.bin) + (hp' : p' ∈ primeBin (lower (label p')) (width (label p'))) + (ha' : aligns a k.tag.rational p') : + stopKey Y w Cs eta lower width label a (k.pre++p'::k.tail)=some k := by + obtain ⟨p,heq,hi,ht,hp⟩ := stopKey_witness Y w Cs eta lower width label a ps hk + have hwit := candidate_witness Y w Cs eta lower width label a p hp + have he := sourceTag_replacement Y w Cs eta lower width label a k.pre k.tail p p' + hp (hl.trans hwit.1) hp' ha' + have ht' : sourceTag Y w Cs eta lower width label a (k.pre++p'::k.tail)=some k.tag := + he.symm.trans (by simpa only [heq] using ht) + have hh := stopKey_of_tagged_word Y w Cs eta lower width label a k.pre k.tail p' ht' hi + exact hh +end NumberTheoryLean.CanonicalStopKey + + + +namespace NumberTheoryLean.ActualStopGroupFiber +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualSourceTags FiniteFirstTag CanonicalStopKey +open StoppedCountAdapters StoppedTraceSets ActualSourceStopBinding ActualFrozenStopFamily +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open FrozenPrimeGroup ErdosInversePrimeBin + +attribute [local instance] Classical.propDecidable + +noncomputable def family (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (a : ℕ → ℕ) (z : Node) : Finset (List ℕ) := + stopped w (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) (sourcePrimeSet w top).card + (rootVertex z ∅ (sourcePrimeSet w top) mu) + +noncomputable def key (Y : ℕ) (w top Cs eta xi : ℝ) (hw : 1 < w) (htop : w < top) + (hxi : 0 < xi) (a : ℕ → ℕ) (ps : List ℕ) : Option (Key (binCount w top xi)) := + stopKey (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) ps + +noncomputable def keyGroup (w top xi : ℝ) (a : ℕ → ℕ) (k : Key (binCount w top xi)) : + Finset (List ℕ) := frozenGroup (lower w top xi k.tag.bin) (width w top xi k.tag.bin) + (sourceClass a) k.tag.rational k.pre k.tail + +theorem key_some_of_mem (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hps : ps ∈ family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z) : + ∃ k,key Y w top Cs eta xi hw htop hxi a ps=some k := by + have hh := actual_source_stops_first Y w Cs eta Clen B xi b₀ b₁ mu (lower w top xi) + (width w top xi) (label (zero_lt_one.trans hw) htop hxi) a z (sourcePrimeSet w top) hps + obtain ⟨t,ht,_hc,_ha⟩ := hh.2.1.2.2.2.2.2 + refine ⟨⟨t,ps.take t.index,ps.drop (t.index+1)⟩,?_⟩ + simp only [key,stopKey,ht,Option.map_some] + +theorem key_mem_group (Y : ℕ) (w top Cs eta xi : ℝ) (hw : 1 < w) (htop : w < top) + (hxi : 0 < xi) (a : ℕ → ℕ) (ps : List ℕ) {k : Key (binCount w top xi)} + (hk : key Y w top Cs eta xi hw htop hxi a ps=some k) : ps ∈ keyGroup w top xi a k := by + obtain ⟨p,heq,_hi,_ht,hp⟩ := stopKey_witness (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) ps hk + have hc := candidate_witness (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) p hp + apply (mem_frozenGroup _ _ _ _ _ _ ps).mpr + refine ⟨p,?_,hc.2.2.2.2,heq⟩ + rw [hc.1] + exact hc.2.1 + +theorem group_eq_fiber (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (a : ℕ → ℕ) (z : Node) (k : Key (binCount w top xi)) + (hpresent : ∃ ps ∈ family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z, + key Y w top Cs eta xi hw htop hxi a ps=some k) : + keyGroup w top xi a k=(family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z).filter + (fun ps => key Y w top Cs eta xi hw htop hxi a ps=some k) := by + obtain ⟨ps,hps,hk⟩ := hpresent + obtain ⟨p,heq,hi,ht,hp⟩ := stopKey_witness (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) ps hk + apply Finset.ext + intro qs + constructor + · intro hqs + obtain ⟨p',hp',ha',rfl⟩ := (mem_frozenGroup _ _ _ _ _ _ qs).mp hqs + have hnew := (bin_mem_iff_label (zero_lt_one.trans hw) htop hxi k.tag.bin p').mp hp' + have hown : p' ∈ primeBin (lower w top xi (label (zero_lt_one.trans hw) htop hxi p')) + (width w top xi (label (zero_lt_one.trans hw) htop hxi p')) := by + rw [hnew.2.2.2] + exact hp' + have hnewkey := stopKey_replacement (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) ps hk p' hnew.2.2.2 hown ha' + refine Finset.mem_filter.mpr ⟨?_,hnewkey⟩ + subst ps + exact actual_stopped_replacement Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z + k.pre k.tail p p' hps ht hp hp' ha' + · intro hqs + exact key_mem_group Y w top Cs eta xi hw htop hxi a qs (Finset.mem_filter.mp hqs).2 +end NumberTheoryLean.ActualStopGroupFiber + + + +namespace NumberTheoryLean.CanonicalStopPartition +open PrimeHistories CanonicalStopKey ActualStopGroupFiber + +attribute [local instance] Classical.propDecidable + +noncomputable def keys (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (a : ℕ → ℕ) (z : Node) : + Finset (Key (LogarithmicBinScale.binCount w top xi)) := + (family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z).biUnion + (fun ps => (key Y w top Cs eta xi hw htop hxi a ps).toFinset) + +theorem mem_keys (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (a : ℕ → ℕ) (z : Node) + (k : Key (LogarithmicBinScale.binCount w top xi)) : + k ∈ keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z ↔ + ∃ ps ∈ family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z, + key Y w top Cs eta xi hw htop hxi a ps=some k := by + simp [keys] + +theorem groups_disjoint (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) (a : ℕ → ℕ) (z : Node) + {k l : Key (LogarithmicBinScale.binCount w top xi)} + (hk : k ∈ keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z) + (hl : l ∈ keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z) (hne : k ≠ l) : + Disjoint (keyGroup w top xi a k) (keyGroup w top xi a l) := by + rw [group_eq_fiber Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z k + ((mem_keys _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ k).mp hk), + group_eq_fiber Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z l + ((mem_keys _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ l).mp hl)] + apply Finset.disjoint_left.mpr + intro ps hps hps' + exact hne (Option.some.inj ((Finset.mem_filter.mp hps).2.symm.trans (Finset.mem_filter.mp hps').2)) + +theorem groups_union (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) (a : ℕ → ℕ) (z : Node) : + (keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z).biUnion (keyGroup w top xi a)= + family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z := by + ext ps + constructor + · intro hps + obtain ⟨k,hk,hmem⟩ := Finset.mem_biUnion.mp hps + rw [group_eq_fiber Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z k + ((mem_keys _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ k).mp hk)] at hmem + exact (Finset.mem_filter.mp hmem).1 + · intro hps + obtain ⟨k,hk⟩ := key_some_of_mem Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z ps hps + exact Finset.mem_biUnion.mpr ⟨k,(mem_keys _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ k).mpr ⟨ps,hps,hk⟩, + key_mem_group Y w top Cs eta xi hw htop hxi a ps hk⟩ + +theorem sum_over_groups (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) (a : ℕ → ℕ) (z : Node) + (F : List ℕ → ℝ) : + (∑ ps ∈ family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z,F ps)= + ∑ k ∈ keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z,∑ ps ∈ keyGroup w top xi a k,F ps := by + rw [← groups_union Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z] + apply Finset.sum_biUnion + intro k hk l hl hne + exact groups_disjoint Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi hC a z hk hl hne +end NumberTheoryLean.CanonicalStopPartition + + + +namespace NumberTheoryLean.CanonicalKeyWitness +open PrimeHistories CanonicalStopKey CanonicalStopPartition ActualStopGroupFiber +open SourceStopPredicate ActualSourceTags ActualBinOwners ActualSourceStopBinding TagBelowStopWindow +open StoppedCountAdapters StoppedTraceSets StoppedTraceAdmission +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin ErdosInverseAlignment ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +structure Witness {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B b₀ b₁ mu : ℝ) (a : ℕ → ℕ) (z : Node) + (k : Key (binCount w top xi)) where + p₀ : ℕ + mem_family : k.pre++p₀::k.tail∈family Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z + candidate : stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z (k.pre++p₀::k.tail) + tag : sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) (k.pre++p₀::k.tail)=some k.tag + prime_tag : tagCandidate Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) (sourceClass a) p₀=some (k.tag.bin,k.tag.rational) + index : k.tag.index=k.pre.length + ordered : (k.pre++p₀::k.tail).Pairwise (· > ·) + source : ∀ p∈k.pre++p₀::k.tail,p∈sourcePrimeSet w top + singleton : ((k.pre++p₀::k.tail).map (label (zero_lt_one.trans hw) htop hxi)).count k.tag.bin=1 + eligible : ActualBinOwners.eligible Y w Cs k.tag.rational + near_full : (1-eta)*((primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin)).card:ℝ) ≤ + (((primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin)).filter (aligns (sourceClass a) k.tag.rational)).card:ℝ) + aligned : ∀ p∈k.pre++p₀::k.tail,aligns (sourceClass a) k.tag.rational p + prime_bin : p₀∈primeBin (lower w top xi k.tag.bin) (width w top xi k.tag.bin) + bin_eq : k.tag.bin=label (zero_lt_one.trans hw) htop hxi p₀ + search : searchBin w (lower w top xi k.tag.bin) + owner : ActualBinOwners.owner Y w Cs eta (lower w top xi k.tag.bin) (width w top xi k.tag.bin) (sourceClass a)=some k.tag.rational + tail_nonempty : k.tail≠[] + +theorem key_witness_exists {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B b₀ b₁ mu : ℝ) (a : ℕ → ℕ) (z : Node) + (hwindow : b₁ < w^((1/4:ℝ))) (k : Key (binCount w top xi)) + (hk : k∈keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z) : + Nonempty (Witness hw htop hxi Y Cs eta Clen B b₀ b₁ mu a z k) := by + obtain ⟨ps,hps,hkey⟩ := (mem_keys Y w top Cs eta Clen B xi b₀ b₁ mu hw htop hxi a z k).mp hk + let lo := lower w top xi + let wi := width w top xi + let lab := label (zero_lt_one.trans hw) htop hxi + let P := sourcePrimeSet w top + let stop := stopCandidate Y w Cs eta Clen B xi b₀ b₁ lo wi lab a z + obtain ⟨p₀,heq,hindex,htag,hptag⟩ := stopKey_witness (Y:ℝ) w Cs eta lo wi lab (sourceClass a) ps hkey + have hstop := actual_source_stops_first Y w Cs eta Clen B xi b₀ b₁ mu lo wi lab a z P hps + have href := trace_reference_member w stop P.card (rootVertex z ∅ P mu) (Or.inr hps) + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp href).1 + obtain ⟨t,ht,hsingle,helig,hnear,halign⟩ := candidate_owner_witness Y w Cs eta Clen B xi b₀ b₁ lo wi lab a z ps hw hstop.2.1 + have he : t=k.tag := Option.some.inj (ht.symm.trans htag) + subst t + subst ps + have hp := candidate_witness (Y:ℝ) w Cs eta lo wi lab (sourceClass a) p₀ hptag + have htail := source_tag_nonterminal (t:=k.tag) Y w Cs eta Clen B xi b₀ b₁ lo wi lab a z k.pre k.tail p₀ + hw (fun b => endpoint_pos (zero_lt_one.trans hw) b.1) + (fun _ => (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le) hwindow hptag hstop.2.1 + refine ⟨{ + p₀ := p₀ + mem_family := hps + candidate := hstop.2.1 + tag := htag + prime_tag := hptag + index := hindex + ordered := hd.1 + source := hd.2 + singleton := hsingle + eligible := helig + near_full := hnear + aligned := halign + prime_bin := ?_ + bin_eq := hp.1 + search := ?_ + owner := ?_ + tail_nonempty := htail }⟩ + · simpa only [← hp.1] using hp.2.1 + · simpa only [← hp.1] using hp.2.2.1 + · simpa only [← hp.1] using hp.2.2.2.1 +end NumberTheoryLean.CanonicalKeyWitness + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalPairVisitCompletion.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalPairVisitCompletion.lean new file mode 100644 index 0000000000000000000000000000000000000000..22c9b9f49c3f761a22cdcf8d897f3a3fbb11adde --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalPairVisitCompletion.lean @@ -0,0 +1,51 @@ +import OAI.NumberTheory.Jacobsthal.Probability.CanonicalPairVisitLaw + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical + +theorem canonicalPairVisit_completion (a N : ℕ) (v H : ℝ) : + extendFinitePrefix N ∘ₖ canonicalPairVisitKernel a v H= + (rawExtension a N).restrict (anyPairHit_measurable a N v H) := by + rw [canonicalPairVisitKernel,Kernel.comp_sum_right,← completedPairHit_sum] + apply congrArg Kernel.sum + funext n + rw [extendFinitePrefix_comp_map] + by_cases hn : a+2*n+1 ≤ N + · rw [ite_eq_left hn,completedPairHit_eq_extension hn] + · rw [ite_eq_right hn] + ext past S hS + rw [completedPairHit,Kernel.restrict_apply' _ _ _ hS,boundedPairCylinder, + dite_eq_right hn,inter_empty] + simp + +theorem canonicalPairVisit_completion_le (a N : ℕ) (v H : ℝ) (past : RawHistory a) : + (extendFinitePrefix N ∘ₖ canonicalPairVisitKernel a v H) past ≤ rawExtension a N past := by + rw [canonicalPairVisit_completion,Kernel.restrict_apply] + exact Measure.restrict_le_self + +theorem canonicalPairVisit_bounded_mass (a N : ℕ) (v H : ℝ) (past : RawHistory a) : + canonicalPairVisitKernel a v H past {q | q.1 ≤ N}=rawExtension a N past (anyPairHit a N v H) := by + have he := congrArg (fun K : Kernel (RawHistory a) (RawHistory N) => K past univ) + (canonicalPairVisit_completion a N v H) + rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ,Kernel.restrict_apply' _ _ _ MeasurableSet.univ,univ_inter] at he + have hi : (fun q : FiniteRawHistory => extendFinitePrefix N q univ)= + {q : FiniteRawHistory | q.1 ≤ N}.indicator (fun _ => (1:ℝ≥0∞)) := by + funext q + by_cases hq : q.1 ≤ N <;> simp [extendFinitePrefix,hq] + rw [hi,lintegral_indicator (measurableSet_le finiteRawLength_measurable measurable_const)] at he + simpa only [lintegral_const,one_mul,Measure.restrict_apply MeasurableSet.univ,univ_inter] using he + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalUniformMissingVisit.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalUniformMissingVisit.lean new file mode 100644 index 0000000000000000000000000000000000000000..430b663030e5c92b10db33be08bc7aee723f9194 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalUniformMissingVisit.lean @@ -0,0 +1,401 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualOddPairLink + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.InitialRegeneration +open NumberTheoryLean.KernelPotential + +lemma oddConsecutiveContinue_power_embed (v H : ℝ) (n : ℕ) (z : OddCost) : + (((oddConsecutiveContinue v H)^n) z).map embedOdd= + ((consecutiveContinue v H)^n) (embedOdd z) := by + exact supported_projection_power (oddConsecutiveContinue v H) (consecutiveContinue v H) + (S := univ) MeasurableSet.univ (fun _ => Eventually.of_forall (fun _ => mem_univ _)) embedOdd_measurable + (fun z _ => oddConsecutiveContinue_embed v H z) n z (mem_univ _) + +theorem consecutiveMarkedHit_odd_mass (v H : ℝ) (z : OddCost) : + consecutiveMarkedHit v H (embedOdd z) univ=oddConsecutiveHit v H z univ := by + have (n : ℕ) : IsSFiniteKernel ((consecutiveContinue v H)^n) := kernel_power_sfinite _ n + have (n : ℕ) : IsSFiniteKernel ((oddConsecutiveContinue v H)^n) := kernel_power_sfinite _ n + rw [consecutiveMarkedHit,oddConsecutiveHit,potential,potential,Kernel.sum_apply' _ _ MeasurableSet.univ, + Kernel.sum_apply' _ _ MeasurableSet.univ] + apply tsum_congr + intro n + rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ,Kernel.comp_apply' _ _ _ MeasurableSet.univ, + ← oddConsecutiveContinue_power_embed v H n z, + lintegral_map ((consecutiveCapture v H).measurable_coe MeasurableSet.univ) embedOdd_measurable] + apply lintegral_congr + intro y + exact (oddConsecutiveCapture_mass_embed v H y).symm + +theorem consecutiveMarkedHit_after_regeneration (v H : ℝ) (z : OddCost) : + consecutiveMarkedHit v H (embedOdd z) univ= + ∫⁻ y, ordinaryMarkedHit v H y univ ∂hitOrReturn z := by + rw [consecutiveMarkedHit_odd_mass,oddConsecutiveHit_eq_cycles,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.TransitionKernels +open NumberTheoryLean.InitialOddDraw NumberTheoryLean.InitialRegeneration + +noncomputable def canonicalEvenPairVisitKernel (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) FiniteRawHistory := + canonicalPairVisitKernel (a+1) v H ∘ₖ rawExtension a (a+1) + +instance canonicalEvenPairVisitKernel_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (canonicalEvenPairVisitKernel a v H) := by + unfold canonicalEvenPairVisitKernel + infer_instance + +theorem canonicalEvenPairVisit_completion (a N : ℕ) (v H : ℝ) : + extendFinitePrefix N ∘ₖ canonicalEvenPairVisitKernel a v H= + (rawExtension a N).restrict (anyPairHit_measurable (a+1) N v H) := by + rw [canonicalEvenPairVisitKernel,← Kernel.comp_assoc,canonicalPairVisit_completion,Kernel.comp_restrict] + have he : rawExtension (a+1) N ∘ₖ rawExtension a (a+1)=rawExtension a N := + Kernel.partialTraj_comp_partialTraj' (X := fun _ => CostState) (κ := historyKernel) N (show a ≤ a+1 by omega) + rw [he] + +theorem canonicalEvenPairVisit_mass (a : ℕ) (v H : ℝ) (past : RawHistory a) (s : EvenState) + (hs : rawLast a past=(Sum.inl s,0)) : + canonicalEvenPairVisitKernel a v H past univ=ordinaryInitialHitMass s v H := by + rw [canonicalEvenPairVisitKernel,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + simp_rw [canonicalPairVisit_mass] + have hG : Measurable (fun z : CostState => consecutiveMarkedHit v H z univ) := + (consecutiveMarkedHit v H).measurable_coe MeasurableSet.univ + rw [← lintegral_map (g := rawLast (a+1)) hG (rawLast_measurable (a+1)), + rawFirstOdd_draw_law a past s hs,lintegral_map hG embedOdd_measurable] + simp_rw [consecutiveMarkedHit_after_regeneration] + rw [ordinaryInitialHitMass,delayedRegeneration,Kernel.lintegral_comp _ _ _ + ((ordinaryMarkedHit v H).measurable_coe MeasurableSet.univ)] + +theorem canonicalEvenPairVisit_exponential (S : ℝ) : ∃ eta C eta0 B : ℝ, + 0 < eta ∧ 0 < C ∧ 0 < eta0 ∧ 0 ≤ B ∧ ∀ (a : ℕ) (past : RawHistory a) (s : EvenState), + rawLast a past=(Sum.inl s,0) → s.1 ≤ S → ∀ v H : ℝ, 0 ≤ H → + 1-canonicalEvenPairVisitKernel a v H past univ ≤ + ENNReal.ofReal (C*Real.exp (-eta*H)+B*Real.exp (-eta0*v)) := by + obtain ⟨eta,C,eta0,B,heta,hC,heta0,hB,h⟩ := ordinaryInitialHit_exponential S + refine ⟨eta,C,eta0,B,heta,hC,heta0,hB,?_⟩ + intro a past s hs hS v H hH + rw [canonicalEvenPairVisit_mass a v H past s hs] + exact h s hS v H hH + +theorem moving_canonical_even_visit {eps : ℝ} (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → ∀ (a : ℕ) (past : RawHistory a) (s : EvenState), + rawLast a past=(Sum.inl s,0) → 199/100 ≤ s.1 → s.1 ≤ 23/10 → + 1-canonicalEvenPairVisitKernel a (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) past univ ≤ + ENNReal.ofReal eps := by + obtain ⟨rho,hrho,hMoving⟩ := moving_ordinary_marked_hit heps + refine ⟨rho,hrho,?_⟩ + intro K hK + filter_upwards [hMoving K hK] with w hw + refine ⟨hw.1,?_⟩ + intro r hr a past s hs hs0 hs1 + rw [canonicalEvenPairVisit_mass a _ _ past s hs] + exact hw.2 r hr s hs0 hs1 + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels + +lemma extendFinitePrefix_total {α : Type*} [MeasurableSpace α] (N : ℕ) + (K : Kernel α FiniteRawHistory) (x : α) : + (extendFinitePrefix N ∘ₖ K) x univ=K x {q | q.1 ≤ N} := by + rw [Kernel.comp_apply' _ _ _ MeasurableSet.univ] + have hi : (fun q : FiniteRawHistory => extendFinitePrefix N q univ)= + {q : FiniteRawHistory | q.1 ≤ N}.indicator (fun _ => (1:ℝ≥0∞)) := by + funext q + by_cases hq : q.1 ≤ N <;> simp [extendFinitePrefix,hq] + rw [hi,lintegral_indicator (measurableSet_le finiteRawLength_measurable measurable_const)] + simp only [lintegral_const,one_mul,Measure.restrict_apply MeasurableSet.univ,univ_inter] + +theorem canonicalEvenPairVisit_bounded_mass (a N : ℕ) (v H : ℝ) (past : RawHistory a) : + canonicalEvenPairVisitKernel a v H past {q | q.1 ≤ N}= + rawExtension a N past (anyPairHit (a+1) N v H) := by + rw [← extendFinitePrefix_total N (canonicalEvenPairVisitKernel a v H) past, + canonicalEvenPairVisit_completion,Kernel.restrict_apply' _ _ _ MeasurableSet.univ,univ_inter] + +lemma finite_history_length_exhausts (μ : Measure FiniteRawHistory) : + Tendsto (fun N : ℕ => μ {q | q.1 ≤ N}) atTop (𝓝 (μ univ)) := by + have hm : Monotone (fun N : ℕ => {q : FiniteRawHistory | q.1 ≤ N}) := by + intro N M hNM q hq + exact hq.trans hNM + have hu : (⋃ N : ℕ, {q : FiniteRawHistory | q.1 ≤ N})=univ := by + apply eq_univ_of_forall + intro q + exact mem_iUnion.mpr ⟨q.1,(show q.1 ≤ q.1 from le_rfl)⟩ + have ht := tendsto_measure_iUnion_atTop (μ := μ) hm + rwa [hu] at ht + +theorem canonical_even_hit_probability_limit (a : ℕ) (v H : ℝ) (past : RawHistory a) (s : EvenState) + (hs : rawLast a past=(Sum.inl s,0)) : + Tendsto (fun N : ℕ => rawExtension a N past (anyPairHit (a+1) N v H)) atTop + (𝓝 (ordinaryInitialHitMass s v H)) := by + have ht := finite_history_length_exhausts (canonicalEvenPairVisitKernel a v H past) + simp_rw [canonicalEvenPairVisit_bounded_mass,canonicalEvenPairVisit_mass a v H past s hs] at ht + exact ht + +theorem finitePathMeasure_marked_hit_limit (s : EvenState) (v H : ℝ) : + Tendsto (fun N : ℕ => finitePathMeasure (Sum.inl s) N (anyPairHit 1 N v H)) atTop + (𝓝 (ordinaryInitialHitMass s v H)) := by + exact canonical_even_hit_probability_limit 0 v H (fun _ => (Sum.inl s,0)) s rfl + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels +open NumberTheoryLean.ArrivalKernelGeometry NumberTheoryLean.OccupationBoundaries + +lemma pair_no_future_hit_of_bad_inputs (a N M : ℕ) (hNM : N ≤ M) (v H : ℝ) + (past : RawHistory N) (hNo : past ∉ anyPairHit a N v H) + (hBad : ∀ᵐ y ∂rawExtension N M past, ∀ i : Finset.Iic M, N ≤ i.1 → + y i ∉ regenerativeCostWindow v H) : + ∀ᵐ y ∂rawExtension N M past, y ∉ anyPairHit a M v H := by + filter_upwards [hBad,rawExtension_retains_prefix hNM past] with y hy hp + intro hHit + obtain ⟨k,hk,hT⟩ := hHit + by_cases hj : a+2*k+1 ≤ N + · have hSmall : rawPrefix hNM y ∈ pairHitTest a k N hj v H := by + change y ∈ rawPrefix hNM ⁻¹' pairHitTest a k N hj v H + rw [pairHitTest_prefix] + exact hT + rw [hp] at hSmall + exact hNo ⟨k,hj,hSmall⟩ + · exact hy ⟨a+2*k,Finset.mem_Iic.mpr (by omega)⟩ (show N ≤ a+2*k by omega) ⟨hT.1,hT.2.2⟩ + +lemma regeneration_ratio_le_three (z : CostState) (hz : z ∈ regenerationSet) : stateRatio z.1 ≤ 3 := by + rcases z with ⟨s,T⟩ + cases s with + | inl e => exact False.elim (regeneration_even e T hz) + | inr o => exact hz + +lemma eligible_input_large_exponent {r b0 b1 : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + (z : CostState) (hz : z ∈ regenerativeCostWindow (Real.log (r/b1)) (Real.log (b1/(10*b0)))) : + 2*b0 < currentExponent (Real.log r) z := by + have hGap := (marked_cost_window hr hb0 hb1 z.2).mpr hz.2 + have hRatio := regeneration_ratio_le_three z hz.1 + unfold currentExponent + rw [gapValue_log_eq_gapAt hr] + apply (lt_div_iff₀ (stateRatio_pos z.1)).mpr + have hm := mul_le_mul_of_nonneg_left hRatio (show 0 ≤ 2*b0 by positivity) + nlinarith [hGap.1] + +theorem low_gap_no_future_pair_hit {r b0 b1 : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + (a N M : ℕ) (hNM : N ≤ M) (past : RawHistory N) + (hNo : past ∉ anyPairHit a N (Real.log (r/b1)) (Real.log (b1/(10*b0)))) + (hLow : gapAt r (rawLast N past).2 < 10*b0) : + ∀ᵐ y ∂rawExtension N M past, y ∉ anyPairHit a M (Real.log (r/b1)) (Real.log (b1/(10*b0))) := by + apply pair_no_future_hit_of_bad_inputs a N M hNM _ _ past hNo + filter_upwards [rawExtension_increasingCosts N M past,rawExtension_retains_prefix hNM past] with y hI hp + have he := congrFun hp (⟨N,by simp⟩ : Finset.Iic N) + change y ⟨N,Finset.mem_Iic.mpr hNM⟩=rawLast N past at he + intro i hNi hGood + have hCost := hI ⟨N,Finset.mem_Iic.mpr hNM⟩ i le_rfl hNi + have hGap := gapAt_antitone_cost hr.le hCost + rw [he] at hGap + have hWindow := (marked_cost_window hr hb0 hb1 (y i).2).mpr hGood.2 + exact (not_lt_of_ge (hWindow.1.trans hGap)) hLow + +theorem cutoff_no_future_pair_hit {r b0 b1 ell : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + (hell : ell < 2*b0) (a N M : ℕ) (hNM : N ≤ M) (past : RawHistory N) + (hNo : past ∉ anyPairHit a N (Real.log (r/b1)) (Real.log (b1/(10*b0)))) + (hCut : currentExponent (Real.log r) (rawLast N past) ≤ ell) : + ∀ᵐ y ∂rawExtension N M past, y ∉ anyPairHit a M (Real.log (r/b1)) (Real.log (b1/(10*b0))) := by + apply pair_no_future_hit_of_bad_inputs a N M hNM _ _ past hNo + have hF : Measurable (fun z => -currentExponent (Real.log r) z) := (currentExponent_measurable _).neg + have hStep (z : CostState) : ∀ᵐ y ∂costKernel z, -currentExponent (Real.log r) z ≤ -currentExponent (Real.log r) y := by + filter_upwards [costKernel_exponent_nonincreasing (Real.log r) z] with y hy + exact neg_le_neg hy + filter_upwards [rawExtension_scalarIncreasing (fun z => -currentExponent (Real.log r) z) hF hStep N M past, + rawExtension_retains_prefix hNM past] with y hI hp + change ∀ i j : Finset.Iic M, N ≤ i.1 → i.1 ≤ j.1 → + -currentExponent (Real.log r) (y i) ≤ -currentExponent (Real.log r) (y j) at hI + have he := congrFun hp (⟨N,by simp⟩ : Finset.Iic N) + change y ⟨N,Finset.mem_Iic.mpr hNM⟩=rawLast N past at he + intro i hNi hGood + have hX := hI ⟨N,Finset.mem_Iic.mpr hNM⟩ i le_rfl hNi + rw [he] at hX + have hLarge := eligible_input_large_exponent hr hb0 hb1 (y i) hGood + linarith + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels +open NumberTheoryLean.ArrivalKernelGeometry + +noncomputable def closedNoHitEvent (a N : ℕ) (r b0 b1 ell : ℝ) : Set (RawHistory N) := + (anyPairHit a N (Real.log (r/b1)) (Real.log (b1/(10*b0))))ᶜ ∩ + {past | gapAt r (rawLast N past).2 < 10*b0 ∨ currentExponent (Real.log r) (rawLast N past) ≤ ell} + +lemma closedNoHitEvent_measurable (a N : ℕ) (r b0 b1 ell : ℝ) : + MeasurableSet (closedNoHitEvent a N r b0 b1 ell) := by + have hGap : Measurable (fun h : RawHistory N => gapAt r (rawLast N h).2) := + measurable_const.mul (Real.measurable_exp.comp ((measurable_snd.comp (rawLast_measurable N)).neg)) + exact (anyPairHit_measurable a N _ _).compl.inter + ((measurableSet_lt hGap measurable_const).union + (measurableSet_le ((currentExponent_measurable _).comp (rawLast_measurable N)) measurable_const)) + +lemma closedNoHitEvent_future {r b0 b1 ell : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + (hell : ell < 2*b0) (a N M : ℕ) (hNM : N ≤ M) (past : RawHistory N) + (hp : past ∈ closedNoHitEvent a N r b0 b1 ell) : + ∀ᵐ y ∂rawExtension N M past, + y ∉ anyPairHit a M (Real.log (r/b1)) (Real.log (b1/(10*b0))) := by + rcases hp.2 with hLow | hCut + · exact low_gap_no_future_pair_hit hr hb0 hb1 a N M hNM past hp.1 hLow + · exact cutoff_no_future_pair_hit hr hb0 hb1 hell a N M hNM past hp.1 hCut + +theorem closedNoHitEvent_mass_future {r b0 b1 ell : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + (hell : ell < 2*b0) (s a N M : ℕ) (hsN : s ≤ N) (hNM : N ≤ M) (past : RawHistory s) : + rawExtension s N past (closedNoHitEvent a N r b0 b1 ell) ≤ + rawExtension s M past (anyPairHit a M (Real.log (r/b1)) (Real.log (b1/(10*b0))))ᶜ := by + let E := closedNoHitEvent a N r b0 b1 ell + let C := (anyPairHit a M (Real.log (r/b1)) (Real.log (b1/(10*b0))))ᶜ + have hE : MeasurableSet E := closedNoHitEvent_measurable a N r b0 b1 ell + have hC : MeasurableSet C := (anyPairHit_measurable a M _ _).compl + have he : rawExtension N M ∘ₖ rawExtension s N=rawExtension s M := + Kernel.partialTraj_comp_partialTraj hsN hNM + change rawExtension s N past E ≤ rawExtension s M past C + rw [← he,Kernel.comp_apply' _ _ _ hC] + calc + _ = ∫⁻ h, E.indicator (fun _ => (1:ℝ≥0∞)) h ∂rawExtension s N past := by + rw [lintegral_indicator hE] + simp + _ ≤ _ := by + apply lintegral_mono + intro h + by_cases hh : h ∈ E + · have hStay := closedNoHitEvent_future hr hb0 hb1 hell a N M hNM h hh + have hMass := (ae_mem_iff_measure_eq hC.nullMeasurableSet).mp hStay + rw [measure_univ] at hMass + rw [indicator_of_mem hh] + change 1 ≤ rawExtension N M h C + exact hMass.symm.le + · rw [indicator_of_notMem hh] + exact zero_le + +theorem canonical_closed_nohit_le_failure {r b0 b1 ell : ℝ} (hr : 0 < r) (hb0 : 0 < b0) (hb1 : 0 < b1) + (hell : ell < 2*b0) (s : EvenState) (N : ℕ) : + finitePathMeasure (Sum.inl s) N (closedNoHitEvent 1 N r b0 b1 ell) ≤ + 1-ordinaryInitialHitMass s (Real.log (r/b1)) (Real.log (b1/(10*b0))) := by + let C := finitePathMeasure (Sum.inl s) N (closedNoHitEvent 1 N r b0 b1 ell) + let I := ordinaryInitialHitMass s (Real.log (r/b1)) (Real.log (b1/(10*b0))) + have hLimit := (finitePathMeasure_marked_hit_limit s (Real.log (r/b1)) (Real.log (b1/(10*b0)))).const_add C + have hTail : ∀ᶠ M : ℕ in atTop, + C+finitePathMeasure (Sum.inl s) M (anyPairHit 1 M (Real.log (r/b1)) (Real.log (b1/(10*b0)))) ≤ 1 := by + filter_upwards [eventually_ge_atTop N] with M hNM + have hle := closedNoHitEvent_mass_future hr hb0 hb1 hell 0 1 N M (Nat.zero_le _) hNM + (fun _ => (Sum.inl s,0)) + calc + _ ≤ finitePathMeasure (Sum.inl s) M (anyPairHit 1 M (Real.log (r/b1)) (Real.log (b1/(10*b0))))ᶜ+ + finitePathMeasure (Sum.inl s) M (anyPairHit 1 M (Real.log (r/b1)) (Real.log (b1/(10*b0)))) := + add_le_add hle le_rfl + _ = 1 := by + rw [add_comm,measure_add_measure_compl (anyPairHit_measurable 1 M _ _),measure_univ] + have hAdd : C+I ≤ 1 := le_of_tendsto hLimit hTail + have hI : I ≠ ∞ := ne_top_of_le_ne_top (by simp : (1:ℝ≥0∞) ≠ ∞) (ordinaryInitialHitMass_le_one s _ _) + exact ENNReal.le_sub_of_add_le_right hI hAdd + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels + +theorem canonical_closed_nohit_exponential (S : ℝ) : ∃ eta C eta0 B : ℝ, + 0 < eta ∧ 0 < C ∧ 0 < eta0 ∧ 0 ≤ B ∧ + ∀ (r b0 b1 ell : ℝ), 0 < r → 0 < b0 → 0 < b1 → 10*b0 ≤ b1 → ell < 2*b0 → + ∀ (s : EvenState), s.1 ≤ S → ∀ N : ℕ, + finitePathMeasure (Sum.inl s) N (closedNoHitEvent 1 N r b0 b1 ell) ≤ + ENNReal.ofReal (C*Real.exp (-eta*Real.log (b1/(10*b0)))+ + B*Real.exp (-eta0*Real.log (r/b1))) := by + obtain ⟨eta,C,eta0,B,heta,hC,heta0,hB,hBound⟩ := ordinaryInitialHit_exponential S + refine ⟨eta,C,eta0,B,heta,hC,heta0,hB,?_⟩ + intro r b0 b1 ell hr hb0 hb1 hWindow hell s hS N + have hRatio : 1 ≤ b1/(10*b0) := (le_div_iff₀ (by positivity : 0 < 10*b0)).mpr (by linarith) + exact (canonical_closed_nohit_le_failure hr hb0 hb1 hell s N).trans + (hBound s hS _ _ (Real.log_nonneg hRatio)) + +lemma moving_cutoff_one {K : ℝ} (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ 1 < 2*(K*(Real.log w)^2) := by + filter_upwards [eventually_ge_atTop (max (3:ℝ) (Real.exp (1+1/K)))] with w hw + have hw3 : 3 ≤ w := (le_max_left _ _).trans hw + have hw0 : 0 < w := by linarith + have hL : 1+1/K ≤ Real.log w := (Real.le_log_iff_exp_le hw0).mpr ((le_max_right _ _).trans hw) + have hOne : 1 ≤ Real.log w := by have hi : 0 < 1/K := one_div_pos.mpr hK; linarith + have hMul := mul_le_mul_of_nonneg_left hL hK.le + have hEq : K*(1+1/K)=K+1 := by field_simp [hK.ne'] + rw [hEq] at hMul + have hSq : Real.log w ≤ (Real.log w)^2 := by nlinarith + have hMulSq := mul_le_mul_of_nonneg_left hSq hK.le + refine ⟨hw3,?_⟩ + nlinarith + +theorem moving_canonical_missing_visit {eps : ℝ} (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → ∀ N : ℕ, + finitePathMeasure (Sum.inl s) N + (closedNoHitEvent 1 N r (K*(Real.log w)^2) (rho*K*(Real.log w)^2) 1) ≤ ENNReal.ofReal eps := by + obtain ⟨rho,hrho,hMoving⟩ := moving_ordinary_marked_hit heps + refine ⟨rho,hrho,?_⟩ + intro K hK + filter_upwards [hMoving K hK,moving_cutoff_one hK] with w hw hCut + refine ⟨hw.1,?_⟩ + intro r hr s hs0 hs1 N + have hw0 : 0 < w := by linarith [hw.1] + have hr0 : 0 < r := hw0.trans_le hr + have hlog : 0 < Real.log w := Real.log_pos (by linarith [hw.1]) + let b0 := K*(Real.log w)^2 + have hb0 : 0 < b0 := by dsimp [b0]; positivity + have hrho0 : 0 < rho := by linarith + have hb1 : 0 < rho*b0 := mul_pos hrho0 hb0 + have he : rho*b0=rho*K*(Real.log w)^2 := by dsimp [b0]; ring + have hBound := canonical_closed_nohit_le_failure hr0 hb0 hb1 hCut.2 s N + rw [proportional_window_width hrho0 hb0,he] at hBound + exact hBound.trans (hw.2 r hr s hs0 hs1) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalWordPrefix.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalWordPrefix.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c01ee7e7e497a2d43a3ca6f0a4ca2280e530432 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/CanonicalWordPrefix.lean @@ -0,0 +1,76 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RawFirstPrefixLaw + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal + +noncomputable def sigmaInputKernel {ι : Type*} {X : ι → Type*} {Z : Type*} + [∀ i, MeasurableSpace (X i)] [MeasurableSpace Z] (K : ∀ i, Kernel (X i) Z) : Kernel (Σ i, X i) Z where + toFun r := K r.1 r.2 + measurable' := measurable_sigma_family (fun i => (K i).measurable) + +lemma sigmaInputKernel_isFinite_of_bound {ι : Type*} {X : ι → Type*} {Z : Type*} + [∀ i, MeasurableSpace (X i)] [MeasurableSpace Z] (K : ∀ i, Kernel (X i) Z) + {B : ℝ≥0∞} (hB : B < ∞) (hK : ∀ i x, K i x univ ≤ B) : IsFiniteKernel (sigmaInputKernel K) := + ⟨⟨B,hB,fun r => hK r.1 r.2⟩⟩ + +noncomputable def canonicalWordFirstPrefix : (a : ℕ) → List Bool → Bool → Kernel (RawHistory a) FiniteRawHistory + | a, [], b => ((rawExtension a (a+1)).restrict (firstPrefixMarkEvent_measurable a b)).map + (@Sigma.mk ℕ RawHistory (a+1)) + | a, c::w, b => sigmaInputKernel (fun n : ℕ => canonicalWordFirstPrefix (a+2*(n+1)) w b) ∘ₖ + rawBranchReturnKernel a c + +lemma canonicalWordFirstPrefix_bound (w : List Bool) : ∀ a b, + IsFiniteKernel (canonicalWordFirstPrefix a w b) ∧ ∀ h, canonicalWordFirstPrefix a w b h univ ≤ 1 := by + induction w with + | nil => + intro a b + constructor + · unfold canonicalWordFirstPrefix + infer_instance + · intro h + rw [canonicalWordFirstPrefix,Kernel.map_apply' _ (measurableSigmaMk (a+1)) _ MeasurableSet.univ, + preimage_univ,Kernel.restrict_apply] + exact (Measure.restrict_le_self univ).trans_eq measure_univ + | cons c w ih => + intro a b + let (n : ℕ) : IsFiniteKernel (canonicalWordFirstPrefix (a+2*(n+1)) w b) := (ih _ b).1 + have : IsFiniteKernel (sigmaInputKernel (fun n : ℕ => canonicalWordFirstPrefix (a+2*(n+1)) w b)) := + sigmaInputKernel_isFinite_of_bound _ (B := 1) (by simp) (fun n h => (ih (a+2*(n+1)) b).2 h) + constructor + · unfold canonicalWordFirstPrefix + infer_instance + · intro h + rw [canonicalWordFirstPrefix,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + calc + _ ≤ ∫⁻ _r, (1:ℝ≥0∞) ∂rawBranchReturnKernel a c h := lintegral_mono (fun r => (ih _ b).2 r.2) + _ = rawBranchReturnKernel a c h univ := by simp + _ ≤ 1 := rawBranchReturn_mass_le_one a c h + +instance canonicalWordFirstPrefix_isFiniteKernel (a : ℕ) (w : List Bool) (b : Bool) : + IsFiniteKernel (canonicalWordFirstPrefix a w b) := (canonicalWordFirstPrefix_bound w a b).1 + +instance canonicalWordContinuation_isFiniteKernel (a : ℕ) (w : List Bool) (b : Bool) : + IsFiniteKernel (sigmaInputKernel (fun n : ℕ => canonicalWordFirstPrefix (a+2*(n+1)) w b)) := + sigmaInputKernel_isFinite_of_bound _ (B := 1) (by simp) + (fun n h => (canonicalWordFirstPrefix_bound w (a+2*(n+1)) b).2 h) + +noncomputable def wordFirstPrefix (a : ℕ) (w : List Bool) (b : Bool) : + RawCycleWordTrace a (w++[b]).length → FiniteRawHistory := selectedVisitPrefix ∘ lastRawCycle a w b + +lemma wordFirstPrefix_measurable (a : ℕ) (w : List Bool) (b : Bool) : Measurable (wordFirstPrefix a w b) := + selectedVisitPrefix_measurable.comp (lastRawCycle_measurable w a b) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ConsecutivePairStop.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ConsecutivePairStop.lean new file mode 100644 index 0000000000000000000000000000000000000000..eda647d03325fafa8a75478880b5401c7e01ff09 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ConsecutivePairStop.lean @@ -0,0 +1,225 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalPairCylinders + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical + +noncomputable def boundedPairCylinder (a N n : ℕ) (v H : ℝ) : Set (RawHistory N) := + if hn : a+2*n+1 ≤ N then firstPairHitEvent a n N hn v H else ∅ + +lemma boundedPairCylinder_measurable (a N n : ℕ) (v H : ℝ) : MeasurableSet (boundedPairCylinder a N n v H) := by + unfold boundedPairCylinder + split_ifs with hn + · exact firstPairHitEvent_measurable a n N hn v H + · exact MeasurableSet.empty + +lemma boundedPairCylinder_disjoint (a N : ℕ) (v H : ℝ) : + Pairwise (fun n m : ℕ => Disjoint (boundedPairCylinder a N n v H) (boundedPairCylinder a N m v H)) := by + intro n m hnm + unfold boundedPairCylinder + split_ifs with hn hm + · exact firstPairHitEvent_disjoint hn hm hnm v H + all_goals simp + +noncomputable def anyPairHit (a N : ℕ) (v H : ℝ) : Set (RawHistory N) := + {h | ∃ n : ℕ, ∃ hn : a+2*n+1 ≤ N, h ∈ pairHitTest a n N hn v H} + +lemma anyPairHit_measurable (a N : ℕ) (v H : ℝ) : MeasurableSet (anyPairHit a N v H) := by + unfold anyPairHit + simp only [ofPred_exists] + apply MeasurableSet.iUnion + intro n + apply MeasurableSet.iUnion + intro hn + exact pairHitTest_measurable a n N hn v H + +theorem firstPairHit_union_eq_any (a N : ℕ) (v H : ℝ) : + (⋃ n ∈ Finset.range (N+1), boundedPairCylinder a N n v H)=anyPairHit a N v H := by + ext h + constructor + · intro hh + obtain ⟨n,hh⟩ := mem_iUnion.mp hh + obtain ⟨_hn,hh⟩ := mem_iUnion.mp hh + by_cases hn : a+2*n+1 ≤ N + · rw [boundedPairCylinder,dite_eq_left hn] at hh + exact ⟨n,hn,hh.2⟩ + · simp [boundedPairCylinder,hn] at hh + · intro hh + have hex : ∃ n : ℕ, ∃ hn : a+2*n+1 ≤ N, h ∈ pairHitTest a n N hn v H := hh + obtain ⟨hn,hHit⟩ := Nat.find_spec hex + have hNo : h ∈ noPairHits a (Nat.find hex) N (by omega) v H := by + intro k hk + exact (Nat.find_min hex k.2) ⟨(by have h:=k.2; omega),hk⟩ + refine mem_iUnion.mpr ⟨Nat.find hex,mem_iUnion.mpr ⟨?_,?_⟩⟩ + · exact Finset.mem_range.mpr (by omega) + · rw [boundedPairCylinder,dite_eq_left hn] + exact ⟨hNo,hHit⟩ + +theorem canonical_first_hit_measure (a N : ℕ) (v H : ℝ) (past : RawHistory a) : + rawExtension a N past (anyPairHit a N v H)= + ∑ n ∈ Finset.range (N+1), rawExtension a N past (boundedPairCylinder a N n v H) := by + rw [← firstPairHit_union_eq_any] + exact measure_biUnion_finset (fun n _hn m _hm hnm => boundedPairCylinder_disjoint a N v H hnm) + (fun n _hn => boundedPairCylinder_measurable a N n v H) + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical + +noncomputable def completedPairHit (a N n : ℕ) (v H : ℝ) : Kernel (RawHistory a) (RawHistory N) := + (rawExtension a N).restrict (boundedPairCylinder_measurable a N n v H) + +instance completedPairHit_isFiniteKernel (a N n : ℕ) (v H : ℝ) : IsFiniteKernel (completedPairHit a N n v H) := by + unfold completedPairHit + infer_instance + +theorem completedPairHit_eq_extension {a N n : ℕ} (hn : a+2*n+1 ≤ N) (v H : ℝ) : + completedPairHit a N n v H=rawExtension (a+2*n+1) N ∘ₖ pairStoppedHistory a n v H := by + unfold completedPairHit pairStoppedHistory + have hB := firstPairHitEvent_measurable a n (a+2*n+1) le_rfl v H + have he := rawExtension_restrict_comp (show a ≤ a+2*n+1 by omega) hn hB MeasurableSet.univ + rw [Kernel.restrict_univ] at he + have hc : boundedPairCylinder a N n v H= + rawPrefix hn ⁻¹' firstPairHitEvent a n (a+2*n+1) le_rfl v H ∩ univ := by + rw [boundedPairCylinder,dite_eq_left hn,inter_univ,firstPairHitEvent_prefix] + ext past S hS + have heS := congrArg (fun K : Kernel (RawHistory a) (RawHistory N) => K past S) he + rw [Kernel.restrict_apply' _ _ _ hS] at heS + rw [Kernel.restrict_apply' _ _ _ hS,hc] + exact heS + +lemma completedPairHit_le (a N n : ℕ) (v H : ℝ) (past : RawHistory a) : + completedPairHit a N n v H past ≤ rawExtension a N past := by + rw [completedPairHit,Kernel.restrict_apply] + exact Measure.restrict_le_self + +lemma boundedPairCylinder_empty {a N n : ℕ} (hn : N < a+2*n+1) (v H : ℝ) : + boundedPairCylinder a N n v H=∅ := by + rw [boundedPairCylinder,dite_eq_right (not_le_of_gt hn)] + +lemma firstPairHit_iUnion_eq_any (a N : ℕ) (v H : ℝ) : + (⋃ n : ℕ, boundedPairCylinder a N n v H)=anyPairHit a N v H := by + rw [← firstPairHit_union_eq_any] + apply Subset.antisymm + · intro h hh + obtain ⟨n,hC⟩ := mem_iUnion.mp hh + have hn : a+2*n+1 ≤ N := by + by_contra hn + simp [boundedPairCylinder,hn] at hC + exact mem_iUnion.mpr ⟨n,mem_iUnion.mpr ⟨Finset.mem_range.mpr (by omega),hC⟩⟩ + · intro h hh + obtain ⟨n,hh⟩ := mem_iUnion.mp hh + obtain ⟨_hn,hC⟩ := mem_iUnion.mp hh + exact mem_iUnion.mpr ⟨n,hC⟩ + +theorem completedPairHit_sum (a N : ℕ) (v H : ℝ) : + Kernel.sum (fun n : ℕ => completedPairHit a N n v H)= + (rawExtension a N).restrict (anyPairHit_measurable a N v H) := by + ext past S hS + rw [Kernel.sum_apply' _ _ hS,Kernel.restrict_apply] + have he := Measure.restrict_iUnion (μ := rawExtension a N past) + (boundedPairCylinder_disjoint a N v H) (fun n => boundedPairCylinder_measurable a N n v H) + rw [firstPairHit_iUnion_eq_any] at he + rw [he,Measure.sum_apply _ hS] + apply tsum_congr + intro n + rw [completedPairHit,Kernel.restrict_apply] + +theorem completedPairHit_sum_le (a N : ℕ) (v H : ℝ) (past : RawHistory a) : + (Kernel.sum (fun n : ℕ => completedPairHit a N n v H)) past ≤ rawExtension a N past := by + rw [completedPairHit_sum,Kernel.restrict_apply] + exact Measure.restrict_le_self + +lemma completedPairHit_sum_mass_le_one (a N : ℕ) (v H : ℝ) (past : RawHistory a) : + (Kernel.sum (fun n : ℕ => completedPairHit a N n v H)) past univ ≤ 1 := + (completedPairHit_sum_le a N v H past univ).trans_eq measure_univ + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels +open NumberTheoryLean.KernelPotential + +noncomputable def regenerativeCostWindow (v H : ℝ) : Set CostState := + regenerationSet ∩ (Prod.snd ⁻¹' Icc v (v+H)) + +lemma regenerativeCostWindow_measurable (v H : ℝ) : MeasurableSet (regenerativeCostWindow v H) := + regenerationSet_measurable.inter (measurableSet_Icc.preimage measurable_snd) + +noncomputable def markedArrival : Set CostState := {z | firstArrivalMark z=true} +lemma markedArrival_measurable : MeasurableSet markedArrival := firstArrivalMark_measurable (measurableSet_singleton true) + +noncomputable def consecutiveCapture (v H : ℝ) : Kernel CostState CostState := + (costKernel.restrict markedArrival_measurable) ∘ₖ stateFilter (regenerativeCostWindow_measurable v H) + +noncomputable def consecutiveFirstContinue (v H : ℝ) : Kernel CostState CostState := + Kernel.piecewise (regenerativeCostWindow_measurable v H) + (costKernel.restrict markedArrival_measurable.compl) costKernel + +noncomputable def consecutiveContinue (v H : ℝ) : Kernel CostState CostState := + costKernel ∘ₖ consecutiveFirstContinue v H + +instance consecutiveCapture_isFiniteKernel (v H : ℝ) : IsFiniteKernel (consecutiveCapture v H) := by + unfold consecutiveCapture + infer_instance + +instance consecutiveFirstContinue_isFiniteKernel (v H : ℝ) : IsFiniteKernel (consecutiveFirstContinue v H) := by + unfold consecutiveFirstContinue + infer_instance + +instance consecutiveContinue_isFiniteKernel (v H : ℝ) : IsFiniteKernel (consecutiveContinue v H) := by + unfold consecutiveContinue + infer_instance + +theorem consecutive_first_partition (v H : ℝ) : + consecutiveCapture v H+consecutiveFirstContinue v H=costKernel := by + ext z S hS + rw [_root_.add_apply,Measure.add_apply,consecutiveCapture,stateFilter_input, + consecutiveFirstContinue,Kernel.piecewise_apply] + by_cases hz : z ∈ regenerativeCostWindow v H + · rw [ite_eq_left hz,ite_eq_left hz,Kernel.restrict_apply,Kernel.restrict_apply, + ← Measure.add_apply,Measure.restrict_add_restrict_compl markedArrival_measurable] + · rw [ite_eq_right hz,ite_eq_right hz] + simp + +instance consecutive_stop_isMarkov (v H : ℝ) : IsMarkovKernel (consecutiveCapture v H+consecutiveContinue v H) := by + constructor + intro z + constructor + rw [_root_.add_apply,Measure.add_apply,consecutiveContinue,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + have hm : (∫⁻ y, costKernel y univ ∂consecutiveFirstContinue v H z)=consecutiveFirstContinue v H z univ := by + simp + rw [hm,← Measure.add_apply,← _root_.add_apply,consecutive_first_partition] + exact measure_univ + +noncomputable def consecutiveMarkedHit (v H : ℝ) : Kernel CostState CostState := + potential (consecutiveCapture v H) (consecutiveContinue v H) + +lemma consecutiveMarkedHit_mass_le_one (v H : ℝ) (z : CostState) : consecutiveMarkedHit v H z univ ≤ 1 := + capturePotential_mass_le_one _ _ z + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ContinuousArrivalSupport.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ContinuousArrivalSupport.lean new file mode 100644 index 0000000000000000000000000000000000000000..5eee4cf32e2e09dffa2d0458eaf388754108c3a3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ContinuousArrivalSupport.lean @@ -0,0 +1,84 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SourceCompactCoupling +import OAI.NumberTheory.Jacobsthal.Renewal.ContinuousCompletedOccupation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ContinuousArrivalSupport + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ContinuousKilledBins CemeteryKernel LowStateHorizon ArrivalKernelGeometry + +def arrivalSupported (v ell : ℝ) : Space CostState → Prop + | .inl z => z ∈ arrivalSet v ell + | .inr _ => True + +theorem arrivalSupported_measurable (v ell : ℝ) : MeasurableSet {z | arrivalSupported v ell z} := by + apply measurableSet_sum_iff.mpr + exact ⟨arrivalSet_measurable v ell,MeasurableSet.univ⟩ + +theorem unsupported_eq (v ell : ℝ) : + {z : Space CostState | ¬arrivalSupported v ell z} = Sum.inl '' (arrivalSet v ell)ᶜ := by + ext z + cases z <;> simp [arrivalSupported] + +theorem continuous_row_arrival (v ell S : ℝ) (q : Space CostState) : + ∀ᵐ y ∂continuousChain v ell S q,arrivalSupported v ell y := by + apply ae_iff.mpr + rw [unsupported_eq] + cases q with + | inl z => + rw [continuousChain,complete_live_mass _ _ (arrivalSet_measurable v ell).compl, + lowKernel,Kernel.restrict_apply,Measure.restrict_apply (arrivalSet_measurable v ell).compl] + have he : (arrivalSet v ell)ᶜ ∩ lowDomain v ell S = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro y hy + exact hy.1 hy.2.1 + rw [he,measure_empty] + | inr u => + cases u + change Measure.dirac (dead : Space CostState) (Sum.inl '' (arrivalSet v ell)ᶜ) = 0 + rw [Measure.dirac_apply' _ (arrivalSet_measurable v ell).compl.inl_image, + indicator_of_notMem (by simp [dead])] + +theorem continuous_power_arrival (v ell S : ℝ) (q : Space CostState) (n : ℕ) (hn : 1 ≤ n) : + ∀ᵐ y ∂((continuousChain v ell S)^n) q,arrivalSupported v ell y := by + cases n with + | zero => omega + | succ n => + have hp : (continuousChain v ell S)^(n+1) = continuousChain v ell S ∘ₖ ((continuousChain v ell S)^n) := pow_succ' _ _ + rw [hp] + apply Kernel.ae_comp_of_ae_ae (arrivalSupported_measurable v ell) + exact Filter.Eventually.of_forall (continuous_row_arrival v ell S) + +variable {w ell S : ℝ} {start : Node} +variable (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) + +include hw hell hS0 hS hr hsS in + +theorem source_arrival (mesh : ℝ) (n : ℕ) (hn : 1 ≤ n) : + ∀ᵐ q ∂CouplingData.sourceLaw w ell S start hs mesh n, + arrivalSupported (Real.log start.gap) ell q.1.2 := by + have he := FlaggedSourceStart.sourceLaw_continuous hw hell hS0 hS hr hs hsS mesh n + rw [CouplingData.sourceLaw_eq hw hell hS0 hS hr hs hsS] at he + have h : ∀ᵐ y ∂(CouplingData.sourceLaw w ell S start hs mesh n).map (fun q => q.1.2), + arrivalSupported (Real.log start.gap) ell y := by + rw [he] + exact continuous_power_arrival _ _ _ _ n hn + exact (ae_map_iff (measurable_snd.comp measurable_fst).aemeasurable + (arrivalSupported_measurable _ _)).mp h + +end NumberTheoryLean.ContinuousArrivalSupport + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/CorrectSearchTags.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/CorrectSearchTags.lean new file mode 100644 index 0000000000000000000000000000000000000000..7758d3f75ce2a41a39631a5636d99f21bafad960 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/CorrectSearchTags.lean @@ -0,0 +1,490 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import OAI.NumberTheory.Jacobsthal.Primes.PrimeBinRationalList +import OAI.NumberTheory.Jacobsthal.Primes.PrimeBinRepresentatives + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ActualBinOwners + +open _root_.Erdos970.Set _root_.Erdos970.Finset +open ErdosInversePrimeBin ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +def eligible (Y w Cs : ℝ) (q : ℚ) : Prop := + (q.den:ℝ) ≤ w^Cs ∧ (q.num.natAbs:ℝ) ≤ Y*w^(Cs+2) + +noncomputable def ownerCandidates (Y w Cs eta R xi : ℝ) (a : ℕ → ℤ) : Finset ℚ := + sourceRationalList (primeBin R xi) a (Y*w^2) (w^Cs) 1 (1-eta) + +theorem mem_ownerCandidates {Y w Cs eta R xi : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) + (a : ℕ → ℤ) (q : ℚ) : + q ∈ ownerCandidates Y w Cs eta R xi a ↔ eligible Y w Cs q ∧ + (1-eta)*((primeBin R xi).card:ℝ) ≤ (((primeBin R xi).filter (aligns a q)).card:ℝ) := by + have hw0 : 0 < w := by linarith + rw [ownerCandidates,mem_sourceRationalList _ _ (by positivity) (Real.rpow_nonneg hw0.le Cs)] + have he : Y*w^2*w^Cs = Y*w^(Cs+2) := by + rw [Real.rpow_add hw0,Real.rpow_ofNat] + ring + simp only [one_pow,mul_one,he,eligible] + tauto + +noncomputable def chooseOwner (C : Finset ℚ) : Option ℚ := + if h : C.Nonempty then some (C.min' h) else none + +noncomputable def owner (Y w Cs eta R xi : ℝ) (a : ℕ → ℤ) : Option ℚ := + chooseOwner (ownerCandidates Y w Cs eta R xi a) + +theorem chooseOwner_mem (C : Finset ℚ) {q : ℚ} (h : chooseOwner C = some q) : q ∈ C := by + by_cases hC : C.Nonempty + · rw [chooseOwner,dite_eq_left hC] at h + have he := Option.some.inj h + exact he ▸ Finset.min'_mem C hC + · simp [chooseOwner,hC] at h + +theorem chooseOwner_exists_iff (C : Finset ℚ) : (∃ q,chooseOwner C = some q) ↔ C.Nonempty := by + constructor + · rintro ⟨q,hq⟩ + exact ⟨q,chooseOwner_mem C hq⟩ + · intro hC + exact ⟨C.min' hC,by simp [chooseOwner,hC]⟩ + +theorem chooseOwner_of_unique (C : Finset ℚ) (q : ℚ) (hq : q ∈ C) + (hunique : ∀ r ∈ C,r = q) : chooseOwner C = some q := by + have hC : C.Nonempty := ⟨q,hq⟩ + have hm := hunique (C.min' hC) (Finset.min'_mem C hC) + simp [chooseOwner,hC,hm] + +theorem actual_owner_witness {Y w Cs eta R xi : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) + (a : ℕ → ℤ) {q : ℚ} (ho : owner Y w Cs eta R xi a = some q) : + eligible Y w Cs q ∧ (1-eta)*((primeBin R xi).card:ℝ) ≤ + (((primeBin R xi).filter (aligns a q)).card:ℝ) := + (mem_ownerCandidates hY hw a q).mp (chooseOwner_mem _ ho) + +theorem actual_owner_exists {Y w Cs eta R xi : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) (a : ℕ → ℤ) : + (∃ q,owner Y w Cs eta R xi a = some q) ↔ + ∃ q,eligible Y w Cs q ∧ (1-eta)*((primeBin R xi).card:ℝ) ≤ + (((primeBin R xi).filter (aligns a q)).card:ℝ) := by + rw [owner,chooseOwner_exists_iff] + constructor + · rintro ⟨q,hq⟩ + exact ⟨q,(mem_ownerCandidates hY hw a q).mp hq⟩ + · rintro ⟨q,hq⟩ + exact ⟨q,(mem_ownerCandidates hY hw a q).mpr hq⟩ + +end NumberTheoryLean.ActualBinOwners + +end + +section + +namespace NumberTheoryLean.FiniteFirstTag + + +structure Tag (n : ℕ) where + index : ℕ + bin : Fin n + rational : ℚ + deriving DecidableEq + +def firstTagFrom {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) : ℕ → List ℕ → Option (Tag n) + | _,[] => none + | k,p::ps => match F p with + | none => firstTagFrom F (k+1) ps + | some (b,q) => some ⟨k,b,q⟩ + +def firstTag {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) (ps : List ℕ) : Option (Tag n) := + firstTagFrom F 0 ps + +theorem firstTagFrom_witness {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) (k : ℕ) (ps : List ℕ) + {t : Tag n} (ht : firstTagFrom F k ps = some t) : + ∃ pre : List ℕ,∃ p : ℕ,∃ tail : List ℕ, ps = pre++p::tail ∧ + t.index = k+pre.length ∧ F p = some (t.bin,t.rational) ∧ ∀ q ∈ pre,F q = none := by + induction ps generalizing k with + | nil => simp [firstTagFrom] at ht + | cons p ps ih => + cases hp : F p with + | none => + rw [firstTagFrom,hp] at ht + obtain ⟨pre,q,tail,hps,hindex,hq,hpre⟩ := ih (k+1) ht + refine ⟨p::pre,q,tail,?_,?_,hq,?_⟩ + · rw [List.cons_append,hps] + · simp only [List.length_cons] + omega + · intro r hr + rcases List.mem_cons.mp hr with rfl | hr + · exact hp + · exact hpre r hr + | some bq => + rcases bq with ⟨b,q⟩ + rw [firstTagFrom,hp] at ht + have he : (⟨k,b,q⟩ : Tag n) = t := Option.some.inj ht + subst t + exact ⟨[],p,ps,rfl,by simp,hp,by simp⟩ + +theorem firstTagFrom_append {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) (k : ℕ) (ps qs : List ℕ) + {t : Tag n} (ht : firstTagFrom F k ps = some t) : firstTagFrom F k (ps++qs) = some t := by + induction ps generalizing k with + | nil => simp [firstTagFrom] at ht + | cons p ps ih => + cases hp : F p with + | none => + simp only [List.cons_append,firstTagFrom,hp] at ht ⊢ + exact ih (k+1) ht + | some bq => + simpa only [List.cons_append,firstTagFrom,hp] using ht + +theorem firstTagFrom_map_invariant {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) + (k : ℕ) (ps qs : List ℕ) (hmap : ps.map F = qs.map F) : + firstTagFrom F k ps = firstTagFrom F k qs := by + induction ps generalizing k qs with + | nil => + have hq : qs = [] := List.map_eq_nil_iff.mp hmap.symm + subst qs + rfl + | cons p ps ih => + cases qs with + | nil => simp at hmap + | cons q qs => + have hh := List.cons.inj hmap + simp only [firstTagFrom,hh.1] + cases hq : F q with + | none => exact ih (k+1) qs hh.2 + | some bq => rfl + +theorem tag_replacement_invariant {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) + (pre tail : List ℕ) (p q : ℕ) (hpq : F p = F q) : + firstTag F (pre++p::tail) = firstTag F (pre++q::tail) := by + apply firstTagFrom_map_invariant + simp only [List.map_append,List.map_cons,hpq] + +theorem tag_prefix_invariant {n : ℕ} (F : ℕ → Option (Fin n × ℚ)) + (ps qs : List ℕ) (hmap : ps.map F = qs.map F) (k : ℕ) : + firstTag F (ps.take k) = firstTag F (qs.take k) := by + apply firstTagFrom_map_invariant + rw [List.map_take,List.map_take,hmap] + +end NumberTheoryLean.FiniteFirstTag + +end + +section + +namespace NumberTheoryLean.OwnerUniquenessFinite +open ActualBinOwners ErdosInverseAlignment ErdosInversePrimeBin +attribute [local instance] Classical.propDecidable + +theorem common_dense_lower (P : Finset ℕ) (a : ℕ → ℤ) (q r : ℚ) (eta : ℝ) + (hq : (1-eta)*(P.card:ℝ) ≤ ((P.filter (aligns a q)).card:ℝ)) + (hr : (1-eta)*(P.card:ℝ) ≤ ((P.filter (aligns a r)).card:ℝ)) : + (1-2*eta)*(P.card:ℝ) ≤ ((commonAligners P a q r).card:ℝ) := by + let A := P.filter (aligns a q) + let B := P.filter (aligns a r) + have hsub : A ∪ B ⊆ P := Finset.union_subset (Finset.filter_subset _ _) (Finset.filter_subset _ _) + have hu := Finset.card_le_card hsub + have hi : A ∩ B=commonAligners P a q r := by ext p; simp [A,B,commonAligners]; tauto + have hh := Finset.card_union_add_card_inter A B + rw [hi] at hh + have hhr : ((A ∪ B).card:ℝ)+((commonAligners P a q r).card:ℝ)=(A.card:ℝ)+(B.card:ℝ) := by exact_mod_cast hh + have hur : ((A ∪ B).card:ℝ) ≤ (P.card:ℝ) := by exact_mod_cast hu + change (1-eta)*(P.card:ℝ) ≤ (A.card:ℝ) at hq + change (1-eta)*(P.card:ℝ) ≤ (B.card:ℝ) at hr + nlinarith + +theorem eligible_determinant_height {Y w Cs : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) + (q r : ℚ) (hq : eligible Y w Cs q) (hr : eligible Y w Cs r) : + ((determinant q r).natAbs:ℝ) ≤ 2*Y*w^(2*Cs+2) := by + have hw0 : 0 < w := zero_lt_one.trans hw + have hnat : (determinant q r).natAbs ≤ q.num.natAbs*r.den+r.num.natAbs*q.den := by + simpa only [determinant,Int.natAbs_mul,Int.natAbs_natCast] using + (Int.natAbs_sub_le (q.num*(r.den:ℤ)) (r.num*(q.den:ℤ))) + have hh : ((determinant q r).natAbs:ℝ) ≤ + (q.num.natAbs:ℝ)*(r.den:ℝ)+(r.num.natAbs:ℝ)*(q.den:ℝ) := by exact_mod_cast hnat + calc + _ ≤ _ := hh + _ ≤ (Y*w^(Cs+2))*w^Cs+(Y*w^(Cs+2))*w^Cs := + add_le_add (mul_le_mul hq.2 hr.1 (Nat.cast_nonneg _) (by positivity)) + (mul_le_mul hr.2 hq.1 (Nat.cast_nonneg _) (by positivity)) + _ = 2*Y*(w^(Cs+2)*w^Cs) := by ring + _ = _ := by rw [← Real.rpow_add hw0]; congr 2; ring + +theorem owner_candidates_unique {Y w Cs eta R xi C : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) + (hR : 1 < R) (hxi : 0 ≤ xi) (a : ℕ → ℤ) + (hheight : 2*Y*w^(2*Cs+2) ≤ R^C) + (hcount : C < (1-2*eta)*((primeBin R xi).card:ℝ)) : + ∀ q ∈ ownerCandidates Y w Cs eta R xi a,∀ r ∈ ownerCandidates Y w Cs eta R xi a,q=r := by + intro q hq r hr + by_contra hne + have hq' := (mem_ownerCandidates hY hw a q).mp hq + have hr' := (mem_ownerCandidates hY hw a r).mp hr + have hd := (eligible_determinant_height hY hw q r hq'.1 hr'.1).trans hheight + have hP : ∀ p ∈ primeBin R xi,p.Prime := fun p hp => + ((mem_primeBin (zero_lt_one.trans hR).le hxi p).mp hp).1 + have hlarge : ∀ p ∈ primeBin R xi,R^(1:ℝ) ≤ (p:ℝ) := by + intro p hp + rw [Real.rpow_one] + exact ((mem_primeBin (zero_lt_one.trans hR).le hxi p).mp hp).2.1.le + have hu := common_primes_power_height_bound (primeBin R xi) a hne hP hR (by norm_num : (0:ℝ)<1) hlarge hd + rw [div_one] at hu + exact (not_le_of_gt hcount) ((common_dense_lower (primeBin R xi) a q r eta hq'.2 hr'.2).trans hu) + +theorem owner_unique_of_exp_height {Y w Cs eta R xi H : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) + (hR : 1 < R) (hxi : 0 ≤ xi) (a : ℕ → ℤ) + (hheight : 2*Y*w^(2*Cs+2) ≤ Real.exp H) + (hcount : H < (1-2*eta)*((primeBin R xi).card:ℝ)*Real.log R) : + ∀ q ∈ ownerCandidates Y w Cs eta R xi a,∀ r ∈ ownerCandidates Y w Cs eta R xi a,q=r := by + apply owner_candidates_unique hY hw hR hxi a (C := H/Real.log R) + · have he : R^(H/Real.log R)=Real.exp H := by + rw [Real.rpow_def_of_pos (zero_lt_one.trans hR)] + congr 1 + field_simp [(Real.log_pos hR).ne'] + rw [he] + exact hheight + · exact (div_lt_iff₀ (Real.log_pos hR)).mpr hcount +end NumberTheoryLean.OwnerUniquenessFinite + +end + +section + +namespace NumberTheoryLean.OwnerSearchBounds + +theorem height_exp_square {Y w Cs : ℝ} (_hY : 0 ≤ Y) (hw : 1 ≤ w) (hCs : 0 ≤ Cs) + (hlarge : 2*Cs+3 ≤ w) (hYup : Y ≤ Real.exp (w^2)) : + 2*Y*w^(2*Cs+2) ≤ Real.exp (2*w^2) := by + have hw0 : 0 < w := zero_lt_one.trans_le hw + have hA : 0 ≤ 2*Cs+2 := by linarith + have hlog : Real.log w ≤ w := (Real.log_le_sub_one_of_pos hw0).trans (by linarith) + have hlog2 : Real.log 2 ≤ 1 := by + have hh := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + linarith + have hh := mul_le_mul_of_nonneg_left hlog hA + have hbound : w^2+(2*Cs+2)*Real.log w+Real.log 2 ≤ 2*w^2 := by nlinarith + have he : Real.exp (w^2+(2*Cs+2)*Real.log w+Real.log 2)=2*Real.exp (w^2)*w^(2*Cs+2) := by + rw [Real.exp_add,Real.exp_add,Real.exp_log (by norm_num : (0:ℝ)<2),Real.rpow_def_of_pos hw0] + rw [mul_comm (2*Cs+2) (Real.log w)] + ring + calc + _ ≤ 2*Real.exp (w^2)*w^(2*Cs+2) := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hYup (by norm_num)) (Real.rpow_nonneg hw0.le _) + _ = Real.exp (w^2+(2*Cs+2)*Real.log w+Real.log 2) := he.symm + _ ≤ _ := Real.exp_le_exp.mpr hbound + +theorem search_ge_fourth {w R : ℝ} (hw : 1 ≤ w) (hp : 4 ≤ w^((1/4:ℝ))) + (hR : w^(w^((1/4:ℝ))) ≤ R) : w^4 ≤ R := by + have hh := Real.rpow_le_rpow_of_exponent_le hw hp + have hh' : w^4 ≤ w^(w^((1/4:ℝ))) := by simpa only [Real.rpow_ofNat] using hh + exact hh'.trans hR + +theorem le_fourth {w : ℝ} (hw : 1 ≤ w) : w ≤ w^4 := by + have h2 : 1 ≤ w^2 := by nlinarith + nlinarith [sq_nonneg (w^2-1)] + +theorem quadratic_lt_scaled_fourth {beta w : ℝ} (hb : 0 < beta) (hw : 1 ≤ w) + (hlarge : 4/beta ≤ w) : 2*w^2 < beta*w^4 := by + have hw0 : 0 < w := zero_lt_one.trans_le hw + have hbw : 4 ≤ beta*w := by nlinarith [(div_le_iff₀ hb).mp hlarge] + have hb2 : 4 ≤ beta*w^2 := by + have hh := mul_le_mul_of_nonneg_right hbw hw0.le + nlinarith + have hh := mul_pos (show 0 < beta*w^2-2 by linarith) (sq_pos_of_pos hw0) + nlinarith +end NumberTheoryLean.OwnerSearchBounds + +end + +section + +namespace NumberTheoryLean.UniformSearchOwner +open _root_.Filter _root_.Erdos970.Filter ActualBinOwners OwnerSearchBounds OwnerUniquenessFinite +open ErdosInversePrimeBin ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +theorem uniform_search_owner_unique {Cs eta theta : ℝ} (hCs : 0 ≤ Cs) + (heta : eta < 1/2) (htheta : 0 < theta) : + ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ ∀ Y R xi : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → + w^(w^((1/4:ℝ))) ≤ R → theta ≤ xi → xi ≤ 1 → ∀ a : ℕ → ℤ, + ∀ q ∈ ownerCandidates Y w Cs eta R xi a,∀ r ∈ ownerCandidates Y w Cs eta R xi a,q=r := by + let beta : ℝ := (1-2*eta)*theta/4 + have hcoef : 0 < 1-2*eta := by linarith + have hbeta : 0 < beta := by dsimp [beta]; positivity + obtain ⟨R₀,hR₀⟩ := eventually_atTop.mp (uniform_prime_bin_count htheta) + have hquarter : ∀ᶠ w : ℝ in atTop,4 ≤ w^((1/4:ℝ)) := + (tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/4)).eventually_ge_atTop 4 + filter_upwards [eventually_ge_atTop (2:ℝ),eventually_ge_atTop R₀, + eventually_ge_atTop (2*Cs+3),eventually_ge_atTop (4/beta),hquarter] with w hw2 hwR hwCs hwBeta hwPow + refine ⟨hw2,?_⟩ + intro Y R xi hY hYup hsearch hxi hxi1 a + have hw1 : 1 ≤ w := by linarith + have hw0 : 0 < w := by linarith + have hfour := search_ge_fourth hw1 hwPow hsearch + have hwR' : w ≤ R := (le_fourth hw1).trans hfour + have hcount := hR₀ R (hwR.trans hwR') + have hR1 : 1 < R := by linarith [hcount.1] + have hR0 : 0 < R := zero_lt_one.trans hR1 + have hlog : 0 < Real.log R := Real.log_pos hR1 + have hc := (hcount.2 xi hxi hxi1).1 + have hcm : xi*R/4 ≤ ((primeBin R xi).card:ℝ)*Real.log R := by + have hh := (div_le_iff₀ (show 0 < 4*Real.log R by positivity)).mp hc + nlinarith + have hlower : beta*R ≤ (1-2*eta)*((primeBin R xi).card:ℝ)*Real.log R := by + calc + beta*R=(1-2*eta)*(theta*R/4) := by dsimp [beta]; ring + _ ≤ (1-2*eta)*(xi*R/4) := by gcongr + _ ≤ (1-2*eta)*(((primeBin R xi).card:ℝ)*Real.log R) := + mul_le_mul_of_nonneg_left hcm hcoef.le + _ = _ := by ring + have hsize : 2*w^2 < (1-2*eta)*((primeBin R xi).card:ℝ)*Real.log R := + (quadratic_lt_scaled_fourth hbeta hw1 hwBeta).trans_le + ((mul_le_mul_of_nonneg_left hfour hbeta.le).trans hlower) + exact owner_unique_of_exp_height hY (by linarith) hR1 (htheta.le.trans hxi) a + (height_exp_square hY hw1 hCs hwCs hYup) hsize + +theorem owner_eq_of_unique {Y w Cs eta R xi : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) (a : ℕ → ℤ) + (hu : ∀ q ∈ ownerCandidates Y w Cs eta R xi a,∀ r ∈ ownerCandidates Y w Cs eta R xi a,q=r) + (q : ℚ) (he : eligible Y w Cs q) + (hd : (1-eta)*((primeBin R xi).card:ℝ) ≤ (((primeBin R xi).filter (aligns a q)).card:ℝ)) : + owner Y w Cs eta R xi a=some q := by + have hq := (mem_ownerCandidates hY hw a q).mpr ⟨he,hd⟩ + exact chooseOwner_of_unique _ q hq (fun r hr => hu r hr q hq) +end NumberTheoryLean.UniformSearchOwner + +end + +section + +namespace NumberTheoryLean.ActualSourceTags + +open _root_.Erdos970.Set _root_.Erdos970.Finset +open ActualBinOwners FiniteFirstTag PrimeBinRepresentatives ErdosInversePrimeBin ErdosInverseAlignment +attribute [local instance] Classical.propDecidable + +def searchBin (w R : ℝ) : Prop := w^((1/4:ℝ)) ≤ leftExponent w R + +noncomputable def tagCandidate {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (p : ℕ) : Option (Fin n × ℚ) := + if p ∈ primeBin (lower (label p)) (width (label p)) ∧ searchBin w (lower (label p)) then + match owner Y w Cs eta (lower (label p)) (width (label p)) a with + | none => none + | some q => if aligns a q p then some (label p,q) else none + else none + +theorem candidate_witness {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (p : ℕ) {b : Fin n} {q : ℚ} + (ht : tagCandidate Y w Cs eta lower width label a p = some (b,q)) : + b = label p ∧ p ∈ primeBin (lower (label p)) (width (label p)) ∧ + searchBin w (lower (label p)) ∧ owner Y w Cs eta (lower (label p)) (width (label p)) a = some q ∧ + aligns a q p := by + by_cases hgood : p ∈ primeBin (lower (label p)) (width (label p)) ∧ searchBin w (lower (label p)) + · rw [tagCandidate,ite_eq_left hgood] at ht + cases ho : owner Y w Cs eta (lower (label p)) (width (label p)) a with + | none => simp [ho] at ht + | some r => + rw [ho] at ht + dsimp only at ht + by_cases ha : aligns a r p + · rw [ite_eq_left ha] at ht + have hh := Prod.mk.inj (Option.some.inj ht) + rcases hh with ⟨hb,hq⟩ + subst r + exact ⟨hb.symm,hgood.1,hgood.2,rfl,ha⟩ + · simp [ha] at ht + · simp [tagCandidate,hgood] at ht + +theorem candidate_of_witness {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (p : ℕ) (q : ℚ) + (hp : p ∈ primeBin (lower (label p)) (width (label p))) (hs : searchBin w (lower (label p))) + (ho : owner Y w Cs eta (lower (label p)) (width (label p)) a = some q) (ha : aligns a q p) : + tagCandidate Y w Cs eta lower width label a p = some (label p,q) := by + simp only [tagCandidate,hp,hs,and_self,ite_true,ho,ha] + +noncomputable def sourceTag {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (ps : List ℕ) : Option (Tag n) := + firstTag (tagCandidate Y w Cs eta lower width label a) ps + +theorem sourceTag_witness {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (ps : List ℕ) {t : Tag n} + (ht : sourceTag Y w Cs eta lower width label a ps = some t) : + ∃ pre : List ℕ,∃ p : ℕ,∃ tail : List ℕ, ps = pre++p::tail ∧ t.index = pre.length ∧ + t.bin = label p ∧ p ∈ primeBin (lower (label p)) (width (label p)) ∧ + searchBin w (lower (label p)) ∧ owner Y w Cs eta (lower (label p)) (width (label p)) a = some t.rational ∧ + aligns a t.rational p ∧ ∀ q ∈ pre,tagCandidate Y w Cs eta lower width label a q = none := by + obtain ⟨pre,p,tail,hps,hindex,hp,hpre⟩ := firstTagFrom_witness + (tagCandidate Y w Cs eta lower width label a) 0 ps ht + have hc := candidate_witness Y w Cs eta lower width label a p hp + exact ⟨pre,p,tail,hps,by simpa only [zero_add] using hindex,hc.1,hc.2.1,hc.2.2.1, + hc.2.2.2.1,hc.2.2.2.2,hpre⟩ + +theorem candidate_replacement {n : ℕ} (Y w Cs eta : ℝ) (lower width : Fin n → ℝ) + (label : ℕ → Fin n) (a : ℕ → ℤ) (p p' : ℕ) {b : Fin n} {q : ℚ} + (ht : tagCandidate Y w Cs eta lower width label a p = some (b,q)) + (hlabel : label p' = label p) + (hp' : p' ∈ primeBin (lower (label p')) (width (label p'))) (ha : aligns a q p') : + tagCandidate Y w Cs eta lower width label a p' = tagCandidate Y w Cs eta lower width label a p := by + have hc := candidate_witness Y w Cs eta lower width label a p ht + have hs : searchBin w (lower (label p')) := by rw [hlabel]; exact hc.2.2.1 + have ho : owner Y w Cs eta (lower (label p')) (width (label p')) a = some q := by + rw [hlabel] + exact hc.2.2.2.1 + rw [candidate_of_witness Y w Cs eta lower width label a p' q hp' hs ho ha,ht,hlabel,← hc.1] + +end NumberTheoryLean.ActualSourceTags + +end + +section + +namespace NumberTheoryLean.CorrectSearchTags +open _root_.Filter _root_.Erdos970.Filter ActualBinOwners ActualSourceTags UniformSearchOwner PrimeBinRepresentatives +open ErdosInverseAlignment ErdosInversePrimeBin +attribute [local instance] Classical.propDecidable + +theorem searchBin_lower {w R : ℝ} (hw : 1 < w) (hR : 0 < R) (hs : searchBin w R) : + w^(w^((1/4:ℝ))) ≤ R := by + have hlog : 0 < Real.log w := Real.log_pos hw + have hh := (le_div_iff₀ hlog).mp hs + calc + _ = Real.exp (Real.log w*w^((1/4:ℝ))) := Real.rpow_def_of_pos (zero_lt_one.trans hw) _ + _ ≤ Real.exp (Real.log R) := Real.exp_le_exp.mpr (by nlinarith only [hh]) + _ = R := Real.exp_log hR + +theorem uniform_correct_owner {Cs eta theta : ℝ} (hCs : 0 ≤ Cs) + (heta : eta < 1/2) (htheta : 0 < theta) : + ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ ∀ Y R xi : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → + 0 < R → searchBin w R → theta ≤ xi → xi ≤ 1 → ∀ (a : ℕ → ℤ) (q : ℚ), + eligible Y w Cs q → + (1-eta)*((primeBin R xi).card:ℝ) ≤ (((primeBin R xi).filter (aligns a q)).card:ℝ) → + owner Y w Cs eta R xi a=some q := by + filter_upwards [uniform_search_owner_unique hCs heta htheta] with w hw + refine ⟨hw.1,?_⟩ + intro Y R xi hY hYup hR hs hxi hxi1 a q he hd + have hw1 : 1 < w := by linarith [hw.1] + exact owner_eq_of_unique hY hw1 a + (hw.2 Y R xi hY hYup (searchBin_lower hw1 hR hs) hxi hxi1 a) q he hd + +theorem uniform_correct_search_candidate {Cs eta theta : ℝ} (hCs : 0 ≤ Cs) + (heta : eta < 1/2) (htheta : 0 < theta) : + ∀ᶠ w : ℝ in atTop,2 ≤ w ∧ ∀ Y : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → + ∀ (n : ℕ) (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℤ) (p : ℕ) (q : ℚ), + 0 < lower (label p) → searchBin w (lower (label p)) → + theta ≤ width (label p) → width (label p) ≤ 1 → + p ∈ primeBin (lower (label p)) (width (label p)) → eligible Y w Cs q → + (1-eta)*((primeBin (lower (label p)) (width (label p))).card:ℝ) ≤ + (((primeBin (lower (label p)) (width (label p))).filter (aligns a q)).card:ℝ) → + aligns a q p → tagCandidate Y w Cs eta lower width label a p=some (label p,q) := by + filter_upwards [uniform_correct_owner hCs heta htheta] with w hw + refine ⟨hw.1,?_⟩ + intro Y hY hYup n lower width label a p q hlo hs hwidth hwidth1 hp he hd ha + have ho := hw.2 Y (lower (label p)) (width (label p)) hY hYup hlo hs hwidth hwidth1 a q he hd + exact candidate_of_witness Y w Cs eta lower width label a p q hp hs ho ha +end NumberTheoryLean.CorrectSearchTags + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/CostPrefixTransport.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/CostPrefixTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a8c6ae1e343d49818e198c054deb3216d4911df --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/CostPrefixTransport.lean @@ -0,0 +1,142 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.RegenerationBandBounds + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.CostPrefixTransport + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry FinitePathMeasures PairedCostGrouping +open OccupationBoundaries CycleCostMoments OccupationDecomposition OccupationRegeneration +open InitialOccupation FullOccupationCovariance KernelPotential + +instance costKernel_pow_markov (n : ℕ) : IsMarkovKernel (costKernel ^ n) := by + induction n with + | zero => change IsMarkovKernel (Kernel.id : Kernel CostState CostState); infer_instance + | succ n ih => + have hp : costKernel ^ (n + 1) = costKernel ∘ₖ (costKernel ^ n) := pow_succ' _ _ + rw [hp] + infer_instance + +noncomputable def stateProjection : Kernel CostState State := Kernel.deterministic Prod.fst measurable_fst + +theorem projection_intertwines : stateProjection ∘ₖ costKernel = stateKernel ∘ₖ stateProjection := by + rw [stateProjection, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] + ext z : 1 + rw [Kernel.map_apply _ measurable_fst, Kernel.comap_apply] + exact Erdos970Dependency.ActualCycleOccupation.costKernel_map_state z + +theorem projection_intertwines_pow (n : ℕ) : + stateProjection ∘ₖ (costKernel ^ n) = (stateKernel ^ n) ∘ₖ stateProjection := by + induction n with + | zero => + change stateProjection ∘ₖ (Kernel.id : Kernel CostState CostState) = Kernel.id ∘ₖ stateProjection + rw [Kernel.comp_id, Kernel.id_comp] + | succ n ih => + have hp : costKernel ^ (n + 1) = (costKernel ^ n) ∘ₖ costKernel := pow_succ _ _ + have hq : stateKernel ^ (n + 1) = (stateKernel ^ n) ∘ₖ stateKernel := pow_succ _ _ + rw [hp, hq, ← Kernel.comp_assoc, ih, Kernel.comp_assoc, projection_intertwines, ← Kernel.comp_assoc] + +theorem costKernel_pow_map_state (n : ℕ) (z : CostState) : + ((costKernel ^ n) z).map Prod.fst = (stateKernel ^ n) z.1 := by + have h := projection_intertwines_pow n + rw [stateProjection, Kernel.deterministic_comp_eq_map, Kernel.comp_deterministic_eq_comap] at h + have hz := congrArg (fun K : Kernel CostState State => K z) h + rwa [Kernel.map_apply _ measurable_fst, Kernel.comap_apply] at hz + +theorem stateRatio_ge_half (s : State) : (1 / 2 : ℝ) ≤ stateRatio s := by + cases s with + | inl s => change (1 / 2 : ℝ) ≤ s.1; linarith [s.2] + | inr s => change (1 / 2 : ℝ) ≤ s.1; linarith [s.2] + +theorem costKernel_cost_bounds (z : CostState) : + ∀ᵐ y ∂costKernel z, z.2 ≤ y.2 ∧ y.2 ≤ z.2 + Real.log 3 := by + have hm : Measurable (fun s : State => (s, z.2 + cost (stateRatio s))) := + measurable_id.prodMk (measurable_const.add (cost_measurable.comp stateRatio_measurable)) + rw [costKernel_eq_map] + apply (ae_map_iff hm.aemeasurable + ((measurableSet_le measurable_const measurable_snd).inter (measurableSet_le measurable_snd measurable_const))).mpr + apply Eventually.of_forall + intro s + have hp := cost_pos (stateRatio_pos s) + have hu := draw_cost_le_log_three (stateRatio_ge_half s) + change z.2 ≤ z.2 + cost (stateRatio s) ∧ z.2 + cost (stateRatio s) ≤ z.2 + Real.log 3 + constructor <;> linarith + +theorem costKernel_pow_cost_bounds (n : ℕ) (z : CostState) : + ∀ᵐ y ∂(costKernel ^ n) z, z.2 ≤ y.2 ∧ y.2 ≤ z.2 + (n : ℝ) * Real.log 3 := by + induction n with + | zero => + simp only [Nat.cast_zero] + change ∀ᵐ y ∂Measure.dirac z, z.2 ≤ y.2 ∧ y.2 ≤ z.2 + (0 : ℝ) * Real.log 3 + have hpred : MeasurableSet {y : CostState | z.2 ≤ y.2 ∧ y.2 ≤ z.2 + (0 : ℝ) * Real.log 3} := + (measurableSet_le measurable_const measurable_snd).inter (measurableSet_le measurable_snd measurable_const) + exact (ae_dirac_iff (p := fun y : CostState => z.2 ≤ y.2 ∧ y.2 ≤ z.2 + (0 : ℝ) * Real.log 3) hpred).mpr + ⟨le_rfl, by simp⟩ + | succ n ih => + have hp : costKernel ^ (n + 1) = costKernel ∘ₖ (costKernel ^ n) := pow_succ' _ _ + rw [hp] + apply Kernel.ae_comp_of_ae_ae + ((measurableSet_le measurable_const measurable_snd).inter (measurableSet_le measurable_snd measurable_const)) + filter_upwards [ih] with y hy + filter_upwards [costKernel_cost_bounds y] with w hw + refine ⟨le_trans hy.1 hw.1, ?_⟩ + calc + w.2 ≤ y.2 + Real.log 3 := hw.2 + _ ≤ (z.2 + (n : ℝ) * Real.log 3) + Real.log 3 := add_le_add hy.2 le_rfl + _ = _ := by push_cast; ring + +noncomputable def inclusiveOccupation : Kernel CostState CostState := Kernel.id + fullOccupation + +instance inclusiveOccupation_isSFiniteKernel : IsSFiniteKernel inclusiveOccupation := by + unfold inclusiveOccupation + infer_instance + +theorem inclusiveOccupation_translation (z : CostState) (a : ℝ) : + (inclusiveOccupation z).map (shiftFullCost a) = inclusiveOccupation (shiftFullCost a z) := by + rw [inclusiveOccupation, _root_.add_apply, Measure.map_add _ _ (shiftFullCost_measurable a), + Kernel.id_apply, Measure.map_dirac' (shiftFullCost_measurable a), fullOccupation_translation, + _root_.add_apply, Kernel.id_apply] + +theorem inclusive_comp_step : inclusiveOccupation ∘ₖ costKernel = fullOccupation := by + rw [inclusiveOccupation, Kernel.comp_add_left, Kernel.id_comp] + exact fullOccupation_unfold.symm + +noncomputable def prefixOccupation (n : ℕ) : Kernel CostState CostState := inclusiveOccupation ∘ₖ (costKernel ^ n) + +instance prefixOccupation_isSFiniteKernel (n : ℕ) : IsSFiniteKernel (prefixOccupation n) := by + unfold prefixOccupation + infer_instance + +theorem full_comp_step_le : fullOccupation ∘ₖ costKernel ≤ fullOccupation := by + calc + _ ≤ costKernel + fullOccupation ∘ₖ costKernel := le_add_of_nonneg_left bot_le + _ = _ := fullOccupation_unfold.symm + +theorem full_comp_pow_le (n : ℕ) : fullOccupation ∘ₖ (costKernel ^ n) ≤ fullOccupation := by + induction n with + | zero => change fullOccupation ∘ₖ Kernel.id ≤ fullOccupation; rw [Kernel.comp_id] + | succ n ih => + have hp : costKernel ^ (n + 1) = (costKernel ^ n) ∘ₖ costKernel := pow_succ _ _ + rw [hp, ← Kernel.comp_assoc] + exact le_trans (compose_mono_left ih costKernel) full_comp_step_le + +theorem prefixOccupation_le_full (n : ℕ) (hn : 0 < n) : prefixOccupation n ≤ fullOccupation := by + cases n with + | zero => omega + | succ n => + have hp : costKernel ^ (n + 1) = costKernel ∘ₖ (costKernel ^ n) := pow_succ' _ _ + rw [prefixOccupation, hp, ← Kernel.comp_assoc, inclusive_comp_step] + exact full_comp_pow_le n + +end NumberTheoryLean.CostPrefixTransport + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ExpandedHardCapture.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ExpandedHardCapture.lean new file mode 100644 index 0000000000000000000000000000000000000000..fac36a8c8c640b762f2c2a0aa67b2a0aebe8c223 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ExpandedHardCapture.lean @@ -0,0 +1,264 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RegularStoppedEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RegularStoppedMass +open FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate ActualWordSelection ActualRegularBoxes +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ActualRegularAdmission ActualPrefixClearance RegularBadTagWords SourceMarkedStopping +open StoppedTraceSets StoppedCountAdapters PriorPrimeWindow MissingWindowPrimeMass +open StrongReferenceTransport StrongSourceFamilies ActualPrimeHigh ReferenceAdmission +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosInverseAlignment +open RegularStoppedEvent + +attribute [local instance] Classical.propDecidable + +theorem uncaptured_mass_le_exceptions {w top xi Cs eta Clen B K b₀ b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) (hmesh : 2*(xi/Real.log w) ≤ 6*(2*Clen*xi)) + (hb₀ : 0 < b₀) (hCs : Cs < 2*b₀) (hsearch : b₁ < w^((1/4:ℝ))) + (hh : xi/Real.log w ≤ b₀) (hsmall : 2*Clen*xi+(206/100)*(xi/Real.log w) ≤ (4/100)*b₀) + (Y : ℕ) (a : ℕ → ℕ) (z : Node) (hs : Valid z.side z.ratio) (hz : Consistent z) + (hg : StrongState z) (hclosed : z.closed=true) (hcap : w^z.cutoff=top) (hroot : b₁/2 < z.cutoff) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) : + (∑ ps ∈ uncapturedRegular hw htop hxi Y Cs eta Clen B K b₀ b₁ a z Q,prefixWeight ps) ≤ + (∑ ps ∈ regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen B K z Q (sourceClass a),prefixWeight ps) + + (∑ ps ∈ missingWindowPrefixes w 1 K b₀ b₁ z,prefixWeight ps) := by + have hsub := uncaptured_subset_exceptions (eta := eta) (K := K) hw htop hxi hC hcomp hmesh hb₀ hCs hsearch hh hsmall + Y a z hs hz hg hclosed hcap hroot Q + apply (Finset.sum_le_sum_of_subset_of_nonneg hsub (fun ps _ _ => prefixWeight_nonneg ps)).trans + have he : + (∑ ps ∈ regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen B K z Q (sourceClass a) ∪ + missingWindowPrefixes w 1 K b₀ b₁ z,prefixWeight ps) + + (∑ ps ∈ regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen B K z Q (sourceClass a) ∩ + missingWindowPrefixes w 1 K b₀ b₁ z,prefixWeight ps) = _ := Finset.sum_union_inter + have hn : 0 ≤ ∑ ps ∈ regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen B K z Q (sourceClass a) ∩ + missingWindowPrefixes w 1 K b₀ b₁ z,prefixWeight ps := Finset.sum_nonneg (fun ps _ => prefixWeight_nonneg ps) + linarith +end NumberTheoryLean.RegularStoppedMass + + + +namespace NumberTheoryLean.StoppedGeometryInvariance +open FinitePathGeometry StoppedCountVertex StoppedCountAdapters StoppedEvaluation StoppedTraceSets +open RegularStoppedEvent SourceStopPredicate LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open LogarithmicBinPartition +open PrimeHistories + +attribute [local instance] Classical.propDecidable + +theorem traces_eq_of_geometry (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v v' : Vertex) + (hn : v.node=v'.node) (hp : v.past=v'.past) (ha : v.available=v'.available) : + traces w stop n v=traces w stop n v' := by + induction n generalizing v v' with + | zero => + simp only [traces] + apply ite_cond_congr + simp only [lowerStop,hn,hp] + | succ n ih => + have hstop : lowerStop stop v ↔ lowerStop stop v' := by simp only [lowerStop,hn,hp] + have hinc : includedPrimes w v=includedPrimes w v' := by simp only [includedPrimes,hn,ha] + have hchild : ∀ p,traces w stop n (child w v p)=traces w stop n (child w v' p) := by + intro p + exact ih (child w v p) (child w v' p) (by simp only [child,hn]) + (by simp only [child,hp]) (by simp only [child,ha]) + simp only [traces,hstop,hinc,hchild] + +theorem root_stopped_independent (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (z : Node) + (P H H' : Finset ℕ) (mu mu' : ℝ) : + stopped w stop n (rootVertex z H P mu)=stopped w stop n (rootVertex z H' P mu') := + congrArg Prod.snd (traces_eq_of_geometry w stop n _ _ rfl rfl rfl) + +theorem hasSourceStop_iff_original_root {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (H : Finset ℕ) (mu : ℝ) : + hasSourceStop hw htop hxi Y Cs eta Clen B b₀ b₁ a z ps ↔ + ∃ pre tail : List ℕ,ps=pre++tail ∧ pre ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z H (sourcePrimeSet w top) mu) := by + unfold hasSourceStop + rw [root_stopped_independent w _ _ z (sourcePrimeSet w top) ∅ H 1 mu] +end NumberTheoryLean.StoppedGeometryInvariance + + + +namespace NumberTheoryLean.ExpandedNoStop +open StoppedCountVertex StoppedEvaluation StoppedVertexHistory StoppedTraceSets FirstStopSemantics +open FinitePathGeometry StoppedCountAdapters RegularStoppedEvent StoppedGeometryInvariance +open SourceStopPredicate LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition + +attribute [local instance] Classical.propDecidable + +theorem expanded_no_lower_stop (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ expanded w stop n v) : + ∀ pre tail : List ℕ,ps=pre++tail → ¬lowerStop stop (after w v pre) := by + induction n generalizing v ps with + | zero => + unfold expanded at hp + rw [traces] at hp + split_ifs at hp with hs + · exact False.elim (Finset.notMem_empty _ hp) + · have he : ps=[] := Finset.mem_singleton.mp hp + subst ps + intro pre tail heq + have hpre := (List.append_eq_nil_iff.mp heq.symm).1 + simpa only [hpre,after] using hs + | succ n ih => + unfold expanded at hp + rw [traces] at hp + split_ifs at hp with hs + · exact False.elim (Finset.notMem_empty _ hp) + · rcases Finset.mem_insert.mp hp with he | hp + · subst ps + intro pre tail heq + have hpre := (List.append_eq_nil_iff.mp heq.symm).1 + simpa only [hpre,after] using hs + · obtain ⟨p,_hinc,hps⟩ := Finset.mem_biUnion.mp hp + obtain ⟨qs,hqs,rfl⟩ := Finset.mem_image.mp hps + intro pre tail heq + cases pre with + | nil => exact hs + | cons q pre => + rw [List.cons_append] at heq + obtain ⟨he,htail⟩ := List.cons.inj heq + subst q + exact ih (child w v p) hqs pre tail htail + +theorem expanded_no_stopped_prefix (w : ℝ) (stop : List ℕ → Prop) (n N : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ expanded w stop n v) : + ¬∃ pre tail : List ℕ,ps=pre++tail ∧ pre∈stopped w stop N v := by + rintro ⟨pre,tail,he,hstop⟩ + exact expanded_no_lower_stop w stop n v hp pre tail he (stopped_first w stop N v hstop).1 + +theorem expanded_no_source_stop {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : PrimeHistories.Node) + (H : Finset ℕ) (mu : ℝ) (n : ℕ) {ps : List ℕ} + (hp : ps∈expanded w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + n (rootVertex z H (sourcePrimeSet w top) mu)) : + ¬hasSourceStop hw htop hxi Y Cs eta Clen B b₀ b₁ a z ps := by + rw [hasSourceStop_iff_original_root hw htop hxi Y Cs eta Clen B b₀ b₁ a z ps H mu] + exact expanded_no_stopped_prefix w _ n _ _ hp +end NumberTheoryLean.ExpandedNoStop + + + +namespace NumberTheoryLean.PaperRegularStopping +open _root_.Filter FinitePathGeometry PrimeHistories PrimeBinMembership SourceStopPredicate SourceNodeCoordinates +open JacobsthalSourceScale PaperMissingPrimeWindow ActualRegularBoxes ActualPrefixClearance +open RegularStoppedEvent RegularStoppedMass PaperRegularTagCapture MovingStopMargins +open ActualBinOwners StrongReferenceTransport LogarithmicBinScale + +attribute [local instance] Classical.propDecidable + +theorem paper_regular_uncaptured_mass {R Clen Cs eta xi : ℝ} (hR : 3 ≤ R) (hC : 1 ≤ Clen) (hCs : 0 ≤ Cs) + (heta0 : 0 < eta) (heta : eta < 1/2) (hxi : 0 < xi) (hxi1 : xi ≤ 1) + (hDelta : 2*Clen*xi ≤ 1) (H : ℕ) (epsilon : ℝ) (hepsilon : 0 < epsilon) : + ∃ rho : ℝ,10 < rho ∧ ∀ K : ℝ,0 < K → + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ Y : ℕ,Y ≤ ⌊top^2/(Real.log top)^2⌋₊ → ∀ (z : Node) (a : ℕ → ℕ), + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=sourceB (Real.log top) → z.closed=true → + ∀ Q : (Fin (binCount (sourceW (Real.log top)) top xi) → ℕ) → Finset ℚ, + (∀ mult ∈ regularBoxes hw htop hxi Clen (sourceB (Real.log top)) R z,(Q mult).card ≤ H) → + (∀ mult ∈ regularBoxes hw htop hxi Clen (sourceB (Real.log top)) R z, + ∀ q ∈ Q mult,eligible Y (sourceW (Real.log top)) Cs q) → + (sourceB (Real.log top))^2 * + (∑ ps ∈ uncapturedRegular hw htop hxi Y Cs eta Clen (sourceB (Real.log top)) R + (K*(Real.log (sourceW (Real.log top)))^2) + (rho*K*(Real.log (sourceW (Real.log top)))^2) a z Q, + ErdosPrimeInputs.PrimePrefixMass.prefixWeight ps) ≤ epsilon := by + obtain ⟨rho,hrho,hK⟩ := paper_missing_prime_window_mass R (epsilon/2) hR (by positivity) + refine ⟨rho,hrho,?_⟩ + intro K hKpos + obtain ⟨L₀,_hL₀,hmiss⟩ := hK K hKpos + have hwT := sourceW_tendsto.comp Real.tendsto_log_atTop + have hBT := sourceB_tendsto.comp Real.tendsto_log_atTop + filter_upwards [paper_regular_bad_tag_mass hR hC hCs heta0 heta hxi hxi1 hDelta H (epsilon/2) (by positivity), + hwT.eventually (moving_stop_margins Cs Clen xi hxi (by linarith : 0 < rho) hKpos), + Real.tendsto_log_atTop.eventually source_scale_eventually, + Real.tendsto_log_atTop.eventually sourceW_le_sourceB_eventually, + hBT.eventually_ge_atTop 3,Real.tendsto_log_atTop.eventually_ge_atTop L₀, + eventually_gt_atTop (1:ℝ)] with top htag hmargin hscale hWB hB3 hL htop1 + obtain ⟨hw,htop,htag⟩ := htag + obtain ⟨_hw,hlog,hb₀,hCsWin,hsearch,hh,hsmall,hbelow⟩ := hmargin + refine ⟨hw,htop,?_⟩ + intro Y hY z a hi h199 h23 hz hcut hclosed Q hcard helig + have hs := (source_node_bounds hscale.2.1 z hi h199 h23 hz hcut).1 + have hg := source_strong_state hB3 z hi h199 hz hcut + have hcap : (sourceW (Real.log top))^z.cutoff=top := by + rw [hcut] + exact (sourceW_pow_sourceB hw).trans (Real.exp_log (zero_lt_one.trans htop1)) + have hroot : (rho*K*(Real.log (sourceW (Real.log top)))^2)/2 < z.cutoff := by + rw [hcut] + exact hbelow _ hWB + have hm := uncaptured_mass_le_exceptions (eta := eta) (K := R) hw htop hxi (by linarith : 0 ≤ Clen) hscale.2.2.2.2 + (source_mesh_clearance_condition hlog hxi.le hC) hb₀ hCsWin hsearch hh hsmall + Y a z hs hz hg hclosed hcap hroot Q + have htagmass := htag Y hY z (sourceClass a) hi h199 h23 hz hcut hclosed Q hcard helig + have hmissmass := hmiss (Real.log top) hL 1 (by norm_num) (by norm_num) z hi h199 h23 hz hcut + have hm' := mul_le_mul_of_nonneg_left hm (sq_nonneg (sourceB (Real.log top))) + rw [mul_add] at hm' + simp only [Function.comp_def] at hm' + linarith +end NumberTheoryLean.PaperRegularStopping + + + +namespace NumberTheoryLean.ExpandedHardCapture +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualRegularBoxes ActualWordSelection +open StoppedCountAdapters StoppedTraceSets RegularStoppedEvent ExpandedNoStop +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail +open ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem expanded_listed_subset_uncaptured {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B K b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : Node) + (H : Finset ℕ) (mu : ℝ) (n : ℕ) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (F : Finset (List ℕ)) + (hexp : F ⊆ expanded w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + n (rootVertex z H (sourcePrimeSet w top) mu)) + (hreg : F ⊆ regularWords hw htop hxi Clen B K z) + (halign : ∀ ps∈F,∃ q∈Q (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps), + ∀ p∈ps,Cs < primeExponent w p → aligns (sourceClass a) q p) : + F ⊆ uncapturedRegular hw htop hxi Y Cs eta Clen B K b₀ b₁ a z Q := by + intro ps hp + exact Finset.mem_filter.mpr ⟨hreg hp,halign ps hp, + expanded_no_source_stop hw htop hxi Y Cs eta Clen B b₀ b₁ a z H mu n (hexp hp)⟩ + +theorem expanded_listed_mass_le {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Y : ℕ) (Cs eta Clen B K b₀ b₁ : ℝ) (a : ℕ → ℕ) (z : Node) + (H : Finset ℕ) (mu : ℝ) (n : ℕ) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (F : Finset (List ℕ)) + (hexp : F ⊆ expanded w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z) + n (rootVertex z H (sourcePrimeSet w top) mu)) + (hreg : F ⊆ regularWords hw htop hxi Clen B K z) + (halign : ∀ ps∈F,∃ q∈Q (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps), + ∀ p∈ps,Cs < primeExponent w p → aligns (sourceClass a) q p) : + (∑ ps∈F,prefixWeight ps) ≤ + ∑ ps∈uncapturedRegular hw htop hxi Y Cs eta Clen B K b₀ b₁ a z Q,prefixWeight ps := + Finset.sum_le_sum_of_subset_of_nonneg + (expanded_listed_subset_uncaptured hw htop hxi Y Cs eta Clen B K b₀ b₁ a z H mu n Q F hexp hreg halign) + (fun ps _ _ => prefixWeight_nonneg ps) +end NumberTheoryLean.ExpandedHardCapture + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteBoxWordMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteBoxWordMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..12730e84b1ad433f88b04f1ee4056bbaaede9cd1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteBoxWordMass.lean @@ -0,0 +1,727 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.CanonicalCorrectionSum +import OAI.NumberTheory.Jacobsthal.Partitions.TwoSingletonBins +import OAI.NumberTheory.Jacobsthal.Primes.StoppedReferencePrimes +import OAI.NumberTheory.Jacobsthal.Probability.PaperTagEventInclusion + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosSubsetWord +open ErdosCofactorChoices + +attribute [local instance] Classical.decEq + +noncomputable def descendingWord {ι : Type*} [Fintype ι] (f : ι → Finset ℕ) : List ℕ := + (selectionPrimes f).sort (· ≥ ·) + +theorem mem_descendingWord {ι : Type*} [Fintype ι] (f : ι → Finset ℕ) (p : ℕ) : + p ∈ descendingWord f ↔ ∃ i,p ∈ f i := by + simp [descendingWord,selectionPrimes] + +theorem descendingWord_nodup {ι : Type*} [Fintype ι] (f : ι → Finset ℕ) : + (descendingWord f).Nodup := Finset.sort_nodup _ _ + +theorem descendingWord_strict {ι : Type*} [Fintype ι] (f : ι → Finset ℕ) : + (descendingWord f).Pairwise (· > ·) := (Finset.sortedGT_sort _).pairwise + +theorem descendingWord_toFinset {ι : Type*} [Fintype ι] (f : ι → Finset ℕ) : + (descendingWord f).toFinset=selectionPrimes f := Finset.sort_toFinset _ _ + +theorem descendingWord_length {ι : Type*} [Fintype ι] (P : ι → Finset ℕ) (mult : ι → ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) (f : ι → Finset ℕ) + (hf : f ∈ selections P mult) : (descendingWord f).length=∑ i,mult i := by + have hmem := (mem_selections P mult f).mp hf + rw [descendingWord,Finset.length_sort,selectionPrimes,Finset.card_biUnion] + · exact Finset.sum_congr rfl (fun i _ => (hmem i).2) + · intro i _ j _ hij + exact selection_disjoint P hd f (fun b => (hmem b).1) hij + +theorem descendingWord_product {ι : Type*} [Fintype ι] (P : ι → Finset ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) (f : ι → Finset ℕ) + (hf : ∀ i,f i ⊆ P i) : (descendingWord f).prod=selectionProduct f := by + rw [selectionProduct_eq_union P hd f hf,← descendingWord_toFinset] + simpa only [List.map_id'] using (List.prod_toFinset (fun p : ℕ => p) (descendingWord_nodup f)).symm + +theorem descendingWord_primes {ι : Type*} [Fintype ι] (P : ι → Finset ℕ) (mult : ι → ℕ) + (hP : ∀ i,∀ p ∈ P i,Nat.Prime p) (f : ι → Finset ℕ) (hf : f ∈ selections P mult) : + ∀ p ∈ descendingWord f,Nat.Prime p := by + intro p hp + obtain ⟨i,hi⟩ := (mem_descendingWord f p).mp hp + exact hP i p (((mem_selections P mult f).mp hf i).1 hi) + +end ErdosSubsetWord + + + +namespace ErdosSearchCount +open NumberTheoryLean FinitePathGeometry PrimeTiltGeometry PrimeHistories +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +noncomputable def selectedCount (P : ℕ → Bool) (ps : List ℕ) : ℕ := (ps.filter P).length +noncomputable def remainderSum (w : ℝ) (P : ℕ → Bool) (ps : List ℕ) : ℝ := + ((ps.filter (fun p => !(P p))).map (primeExponent w)).sum + +theorem valid_half {i : Side} {s : ℝ} (hs : Valid i s) : (1:ℝ)/2 ≤ s := by + cases i <;> dsimp [Valid] at hs <;> linarith + +theorem child_gap_third {w ell S : ℝ} {z : Node} {p : ℕ} + (hell : 0 ≤ ell) (hs : Valid z.side z.ratio) + (hp : p ∈ nodeChildren w ell S z) : z.gap ≤ 3*(step w z p).gap := by + have hx := child_exponent_positive hell hp + have ht := valid_half (child_valid hs hp) + change (1:ℝ)/2 ≤ z.gap/primeExponent w p-1 at ht + have hh : (3:ℝ)/2 ≤ z.gap/primeExponent w p := by linarith + have hm := (le_div_iff₀ hx).mp hh + change z.gap ≤ 3*(z.gap-primeExponent w p) + linarith + +theorem initial_gap_le_search_power (w ell S : ℝ) (P : ℕ → Bool) (z : Node) + (ps : List ℕ) (hell : 0 ≤ ell) (hs : Valid z.side z.ratio) + (ha : allowed w ell S z ps) : + z.gap ≤ (3:ℝ)^(selectedCount P ps)*((terminal w z ps).gap+remainderSum w P ps) := by + induction ps generalizing z with + | nil => simp [selectedCount,remainderSum] + | cons p ps ih => + obtain ⟨hp,ht⟩ := (allowed_cons w ell S z p ps).mp ha + have htail := ih (step w z p) (child_valid hs hp) ht + have hx := (child_exponent_positive hell hp).le + have hpow : (1:ℝ) ≤ 3^(selectedCount P ps) := one_le_pow₀ (by norm_num) + cases he : P p with + | true => + have hh := child_gap_third hell hs hp + simp [selectedCount,remainderSum,he] at * + rw [pow_succ] + nlinarith + | false => + simp [selectedCount,remainderSum,he] at * + change z.gap-primeExponent w p ≤ _ at htail + nlinarith [mul_nonneg (sub_nonneg.mpr hpow) hx] + +end ErdosSearchCount + + + +namespace ErdosSearchCount +open NumberTheoryLean PrimeHistories PrimeBinRepresentatives ActualSourceTags +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +noncomputable def searchFlag {n : ℕ} (w : ℝ) (lower : Fin n → ℝ) + (label : ℕ → Fin n) (p : ℕ) : Bool := decide (searchBin w (lower (label p))) +noncomputable def searchCount {n : ℕ} (w : ℝ) (lower : Fin n → ℝ) + (label : ℕ → Fin n) (ps : List ℕ) : ℕ := selectedCount (searchFlag w lower label) ps + +theorem searchCount_labels {n : ℕ} (w : ℝ) (lower : Fin n → ℝ) + (label : ℕ → Fin n) (ps : List ℕ) : + searchCount w lower label ps=(ps.map label).countP (fun b => decide (searchBin w (lower b))) := by + rw [searchCount,selectedCount,← List.countP_eq_length_filter,List.countP_map] + rfl + +theorem searchCount_label_invariant {n : ℕ} (w : ℝ) (lower : Fin n → ℝ) + (label : ℕ → Fin n) (ps qs : List ℕ) (he : ps.map label=qs.map label) : + searchCount w lower label ps=searchCount w lower label qs := by + rw [searchCount_labels,searchCount_labels,he] + +theorem nonsearch_exponent_bound {w top xi : ℝ} (hw : 1 < w) (htop : w < top) + (hxi : 0 < xi) {p : ℕ} (hp : p ∈ sourcePrimeSet w top) + (hn : searchFlag w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi) p=false) : + primeExponent w p ≤ w^((1/4:ℝ))+xi/Real.log w := by + have hlo : leftExponent w (lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) < w^((1/4:ℝ)) := by + have hh : ¬searchBin w (lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) := by + simpa only [searchFlag,decide_eq_false_iff_not] using hn + exact lt_of_not_ge hh + have hsource := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp hp + have hmem := label_prime_membership (zero_lt_one.trans hw) htop hxi hsource.1 hsource.2 + have hupper := (bin_exponent_bounds hw (endpoint_pos (zero_lt_one.trans hw) _) + (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le hmem).2 + have hwidth := bin_exponent_width (w:=w) + (R:=lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) + (xi:=width w top xi (label (zero_lt_one.trans hw) htop hxi p)) + (endpoint_pos (zero_lt_one.trans hw) _) + (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le + have hlog : Real.log (1+width w top xi (label (zero_lt_one.trans hw) htop hxi p)) ≤ xi := by + have hpos := effectiveWidth_pos (zero_lt_one.trans hw) htop hxi + have he := Real.log_le_sub_one_of_pos (show 0 < 1+effectiveWidth w top xi by linarith) + have hle := effectiveWidth_le (zero_lt_one.trans hw) htop hxi + change Real.log (1+effectiveWidth w top xi) ≤ xi + linarith + have hd := div_le_div_of_nonneg_right hlog (Real.log_pos hw).le + change primeExponent w p ≤ rightExponent w + (lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) + (width w top xi (label (zero_lt_one.trans hw) htop hxi p)) at hupper + linarith + +theorem remainderSum_le_length_mul (w : ℝ) (P : ℕ → Bool) (ps : List ℕ) {A : ℝ} + (hA : 0 ≤ A) (hbound : ∀ p ∈ ps,P p=false → primeExponent w p ≤ A) : + remainderSum w P ps ≤ (ps.length:ℝ)*A := by + induction ps with + | nil => simp [remainderSum] + | cons p ps ih => + have ht := ih (fun q hq => hbound q (by simp [hq])) + cases he : P p with + | true => simp [remainderSum,he] at *; linarith + | false => + have hp := hbound p (by simp) he + simp [remainderSum,he] at * + linarith + +theorem source_remainder_bound {w top xi B Clen : ℝ} (hw : 1 < w) (htop : w < top) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hlog : 1 ≤ Real.log w) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) (ps : List ℕ) + (hp : ∀ p ∈ ps,p ∈ sourcePrimeSet w top) (hlen : (ps.length:ℝ) ≤ Clen*Real.log B) : + remainderSum w (searchFlag w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi)) ps ≤ + 2*Clen*Real.log w*(w^((1/4:ℝ))+1) := by + have hxdiv : xi/Real.log w ≤ 1 := (div_le_one (Real.log_pos hw)).mpr (hxi1.trans hlog) + have hA : 0 ≤ w^((1/4:ℝ))+1 := by positivity + have hm := remainderSum_le_length_mul w + (searchFlag w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi)) ps hA + (fun p hps hn => (nonsearch_exponent_bound hw htop hxi (hp p hps) hn).trans (by linarith)) + have hl : (ps.length:ℝ) ≤ 2*Clen*Real.log w := by + have hh := mul_le_mul_of_nonneg_left hcomp hC + nlinarith + exact hm.trans (mul_le_mul_of_nonneg_right hl hA) + +end ErdosSearchCount + + + +namespace ErdosSearchCount +open _root_.Filter _root_.Erdos970.Filter NumberTheoryLean FinitePathGeometry PrimeHistories +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition + + +theorem nonsearch_budget_le (K Clen epsilon : ℝ) (hC : 0 ≤ Clen) (hepsilon : 0 < epsilon) : + ∀ᶠ w : ℝ in atTop,K+2*Clen*Real.log w*(w^((1/4:ℝ))+1) ≤ epsilon*w^((1/2:ℝ)) := by + let eps : ℝ := epsilon/(8*(Clen+1)) + have heps : 0 < eps := by dsimp [eps]; positivity + have hlog := (isLittleO_log_rpow_atTop (r := (1/4:ℝ)) (by norm_num)).bound heps + have hpow : ∀ᶠ w : ℝ in atTop,2*K/epsilon ≤ w^((1/2:ℝ)) := + (tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/2)).eventually_ge_atTop (2*K/epsilon) + filter_upwards [hlog,hpow,eventually_gt_atTop (1:ℝ)] with w hlog hK hw + have hw0 : 0 < w := zero_lt_one.trans hw + have hL : 0 < Real.log w := Real.log_pos hw + have hp : 0 < w^((1/4:ℝ)) := Real.rpow_pos_of_pos hw0 _ + have hp1 : 1 ≤ w^((1/4:ℝ)) := Real.one_le_rpow hw.le (by norm_num) + have hlog' : Real.log w ≤ eps*w^((1/4:ℝ)) := by + simpa only [Real.norm_eq_abs,abs_of_pos hL,abs_of_pos hp] using hlog + have he : w^((1/4:ℝ))*w^((1/4:ℝ))=w^((1/2:ℝ)) := by + rw [← Real.rpow_add hw0]; norm_num + have hb : 4*Clen*eps ≤ epsilon/2 := by + dsimp [eps] + apply (le_div_iff₀ (by norm_num : (0:ℝ)<2)).mpr + have hden : 0 < 8*(Clen+1) := by positivity + field_simp + nlinarith + have hs : 2*Clen*Real.log w*(w^((1/4:ℝ))+1) ≤ epsilon*w^((1/2:ℝ))/2 := by + calc + _ ≤ 4*Clen*Real.log w*w^((1/4:ℝ)) := by nlinarith [mul_nonneg (mul_nonneg hC hL.le) (sub_nonneg.mpr hp1)] + _ ≤ 4*Clen*(eps*w^((1/4:ℝ)))*w^((1/4:ℝ)) := by gcongr + _ = (4*Clen*eps)*w^((1/2:ℝ)) := by rw [← he]; ring + _ ≤ (epsilon/2)*w^((1/2:ℝ)) := mul_le_mul_of_nonneg_right hb (Real.rpow_nonneg hw0.le _) + _ = _ := by ring + have hK' := (div_le_iff₀ hepsilon).mp hK + nlinarith + +theorem nonsearch_budget_small (K Clen : ℝ) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,K+2*Clen*Real.log w*(w^((1/4:ℝ))+1) ≤ w^((1/2:ℝ)) := by + simpa only [one_mul] using nonsearch_budget_le K Clen 1 hC (by norm_num) + +theorem logarithmic_count_of_power {w R : ℝ} {k : ℕ} (hw : 1 < w) + (hgap : w ≤ (3:ℝ)^k*R) (hsmall : R ≤ w^((1/2:ℝ))) : + Real.log w/(2*Real.log 3) ≤ (k:ℝ) := by + have hw0 : 0 < w := zero_lt_one.trans hw + have hpow : 0 < (3:ℝ)^k := by positivity + have hm := hgap.trans (mul_le_mul_of_nonneg_left hsmall hpow.le) + have hl := Real.log_le_log hw0 hm + rw [Real.log_mul hpow.ne' (Real.rpow_pos_of_pos hw0 _).ne',Real.log_pow, + Real.log_rpow hw0] at hl + apply (div_le_iff₀ (show 0 < 2*Real.log 3 by positivity)).mpr + nlinarith + +theorem actual_search_count (K Clen : ℝ) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,∀ (top B xi ell S : ℝ) (hw : 1 < w) (htop : w < top) + (hxi : 0 < xi),xi ≤ 1 → Real.log B ≤ 2*Real.log w → 1 ≤ ell → + ∀ (z : Node) (ps : List ℕ),Valid z.side z.ratio → w ≤ z.gap → + allowed w ell S z ps → (terminal w z ps).gap ≤ K → + (ps.length:ℝ) ≤ Clen*Real.log B → (∀ p ∈ ps,p ∈ sourcePrimeSet w top) → + Real.log w/(2*Real.log 3) ≤ + (searchCount w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi) ps:ℝ) := by + filter_upwards [nonsearch_budget_small K Clen hC, + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with w hsmall hlog + intro top B xi ell S hw htop hxi hxi1 hcomp hell z ps hs hstart ha hK hlen hp + have hr := source_remainder_bound hw htop hxi hxi1 hlog hC hcomp ps hp hlen + have hi := initial_gap_le_search_power w ell S + (searchFlag w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi)) z ps + (by linarith : 0 ≤ ell) hs ha + apply logarithmic_count_of_power hw (hstart.trans hi) + exact (add_le_add hK hr).trans hsmall + +noncomputable def searchConstant : ℝ := 1/(4*Real.log 3) +theorem searchConstant_pos : 0 < searchConstant := by unfold searchConstant; positivity + +theorem actual_search_count_uniform (K Clen : ℝ) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,∀ (top B xi ell S : ℝ) (hw : 1 < w) (htop : w < top) + (hxi : 0 < xi),xi ≤ 1 → Real.log B ≤ 2*Real.log w → 1 ≤ ell → + ∀ (z : Node) (ps : List ℕ),Valid z.side z.ratio → w ≤ z.gap → + allowed w ell S z ps → (terminal w z ps).gap ≤ K → + (ps.length:ℝ) ≤ Clen*Real.log B → (∀ p ∈ ps,p ∈ sourcePrimeSet w top) → + searchConstant*Real.log w ≤ + (searchCount w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi) ps:ℝ) := by + filter_upwards [actual_search_count K Clen hC] with w hwcount + intro top B xi ell S hw htop hxi hxi1 hcomp hell z ps hs hstart ha hK hlen hp + have hh := hwcount top B xi ell S hw htop hxi hxi1 hcomp hell z ps hs hstart ha hK hlen hp + have hL : 0 < Real.log 3 := Real.log_pos (by norm_num) + have hwL : 0 ≤ Real.log w := (Real.log_pos hw).le + apply le_trans _ hh + unfold searchConstant + field_simp + nlinarith + +end ErdosSearchCount + + + +namespace ErdosSearchCount +open _root_.Filter _root_.Erdos970.Filter NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership JacobsthalSourceScale +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition + + +theorem paper_incoming_geometry : ∀ᶠ L : ℝ in atTop, + 1 < sourceW L ∧ sourceW L < Real.exp L ∧ Real.log (sourceB L) ≤ 2*Real.log (sourceW L) ∧ + ∀ z : Node,z.side=.even → Valid z.side z.ratio → Consistent z → z.cutoff=sourceB L → + sourceW L ≤ z.gap := by + filter_upwards [sourceW_bounds_eventually,source_scale_eventually,eventually_gt_atTop (1:ℝ), + Real.tendsto_log_atTop.eventually (eventually_ge_atTop (1:ℝ))] with L hW hscale hL hlog + have hLp : 0 < L := by linarith + have hlogW : 0 < Real.log (sourceW L) := Real.log_pos hW.1 + have hd : Real.log (sourceW L) ≤ (Real.log L)^2 := by + have hh := Real.log_le_log (zero_lt_one.trans hW.1) hW.2.2 + nlinarith + have hWB : sourceW L ≤ sourceB L := div_le_div_of_nonneg_left hLp.le hlogW hd + have htop : sourceW L < Real.exp L := hW.2.2.trans_lt (by linarith [Real.add_one_le_exp L]) + refine ⟨hW.1,htop,hscale.2.2.2.2,?_⟩ + intro z hi hs hc hcut + have hr : 1 ≤ z.ratio := by rw [hi] at hs; change 198/100 ≤ z.ratio at hs; linarith + have heq : sourceB L*z.ratio=z.gap := by + have hh : z.cutoff=z.gap/z.ratio := hc + rw [hcut] at hh + exact (eq_div_iff (valid_pos hs).ne').mp hh + exact hWB.trans (by nlinarith [hscale.2.1]) + +theorem paper_search_count (K Clen : ℝ) (hC : 0 ≤ Clen) : + ∀ᶠ L : ℝ in atTop,∃ hw : 1 < sourceW L,∃ htop : sourceW L < Real.exp L, + ∀ (xi ell S : ℝ) (hxi : 0 < xi),xi ≤ 1 → 1 ≤ ell → ∀ (z : Node) (ps : List ℕ), + z.side=.even → Valid z.side z.ratio → Consistent z → z.cutoff=sourceB L → + allowed (sourceW L) ell S z ps → (terminal (sourceW L) z ps).gap ≤ K → + (ps.length:ℝ) ≤ Clen*Real.log (sourceB L) → + (∀ p ∈ ps,p ∈ sourcePrimeSet (sourceW L) (Real.exp L)) → + searchConstant*Real.log (sourceW L) ≤ + (searchCount (sourceW L) (lower (sourceW L) (Real.exp L) xi) + (label (zero_lt_one.trans hw) htop hxi) ps:ℝ) := by + filter_upwards [paper_incoming_geometry,sourceW_tendsto.eventually (actual_search_count_uniform K Clen hC)] + with L hg hcount + refine ⟨hg.1,hg.2.1,?_⟩ + intro xi ell S hxi hxi1 hell z ps hi hs hc hcut ha hK hlen hp + exact hcount (Real.exp L) (sourceB L) xi ell S hg.1 hg.2.1 hxi hxi1 hg.2.2.1 hell z ps hs + (hg.2.2.2 z hi hs hc hcut) ha hK hlen hp + +theorem literal_source_search_count (K Clen : ℝ) (hC : 0 ≤ Clen) : + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ (xi ell S : ℝ) (hxi : 0 < xi),xi ≤ 1 → 1 ≤ ell → ∀ (z : Node) (ps : List ℕ), + z.side=.even → Valid z.side z.ratio → Consistent z → z.cutoff=sourceB (Real.log top) → + allowed (sourceW (Real.log top)) ell S z ps → (terminal (sourceW (Real.log top)) z ps).gap ≤ K → + (ps.length:ℝ) ≤ Clen*Real.log (sourceB (Real.log top)) → + (∀ p ∈ ps,p ∈ sourcePrimeSet (sourceW (Real.log top)) top) → + searchConstant*Real.log (sourceW (Real.log top)) ≤ + (searchCount (sourceW (Real.log top)) (lower (sourceW (Real.log top)) top xi) + (label (zero_lt_one.trans hw) htop hxi) ps:ℝ) := by + filter_upwards [Real.tendsto_log_atTop.eventually paper_incoming_geometry, + (sourceW_tendsto.comp Real.tendsto_log_atTop).eventually (actual_search_count_uniform K Clen hC), + eventually_gt_atTop (0:ℝ)] with top hg hcount htopp + have htop : sourceW (Real.log top) < top := by simpa only [Real.exp_log htopp] using hg.2.1 + refine ⟨hg.1,htop,?_⟩ + intro xi ell S hxi hxi1 hell z ps hi hs hc hcut ha hK hlen hp + exact hcount top (sourceB (Real.log top)) xi ell S hg.1 htop hxi hxi1 hg.2.2.1 hell z ps hs + (hg.2.2.2 z hi hs hc hcut) ha hK hlen hp + +end ErdosSearchCount + + + +namespace ErdosSearchCount +open _root_.Filter _root_.Erdos970.Filter NumberTheoryLean ActualSourceTags + +attribute [local instance] Classical.propDecidable + +theorem nonsearch_error_littleO (Clen : ℝ) (hC : 0 ≤ Clen) : + Asymptotics.IsLittleO atTop (fun w : ℝ => 2*Clen*Real.log w*(w^((1/4:ℝ))+1)) + (fun w : ℝ => w^((1/2:ℝ))) := by + apply Asymptotics.isLittleO_iff.mpr + intro c hc + filter_upwards [nonsearch_budget_le 0 Clen c hC hc,eventually_gt_atTop (1:ℝ)] with w hb hw + have hf : 0 ≤ 2*Clen*Real.log w*(w^((1/4:ℝ))+1) := by + have hlog := (Real.log_pos hw).le + positivity + have hg : 0 ≤ w^((1/2:ℝ)) := Real.rpow_nonneg (by linarith) _ + simpa only [zero_add,Real.norm_eq_abs,abs_of_nonneg hf,abs_of_nonneg hg] using hb + +theorem selectedCount_eq_sum (P : ℕ → Bool) (ps : List ℕ) : + selectedCount P ps=(ps.map (fun p => if P p then (1:ℕ) else 0)).sum := by + induction ps with + | nil => rfl + | cons p ps ih => cases he : P p <;> simp [selectedCount,he] at * <;> omega + +noncomputable def searchIndexSet {m n : ℕ} (w : ℝ) (lower : Fin n → ℝ) + (label : ℕ → Fin n) (f : Fin m → ℕ) : Finset (Fin m) := + Finset.univ.filter (fun i => searchBin w (lower (label (f i)))) + +theorem searchCount_ofFn {m n : ℕ} (w : ℝ) (lower : Fin n → ℝ) + (label : ℕ → Fin n) (f : Fin m → ℕ) : + searchCount w lower label (List.ofFn f)=(searchIndexSet w lower label f).card := by + rw [searchCount,selectedCount_eq_sum,List.map_ofFn,List.sum_ofFn] + rw [searchIndexSet,Finset.card_eq_sum_ones,Finset.sum_filter] + simp only [searchFlag,decide_eq_true_eq,Function.comp_def] + +end ErdosSearchCount + + + +namespace ErdosStoppedReferenceUpper +open _root_.Filter _root_.Erdos970.Filter +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership +open ReferenceAdmission ReferencePruning ReferenceProductsBasics ReferenceSourcePrimeSets +open SourceStopPredicate StoppedCountVertex StoppedVertexHistory StoppedCountAdapters StoppedTraceSets +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open MovingCandidateBands MovingStopBandParameters MarkedSourceSmallness +open ErdosPrimeInputs.MertensStrong + +theorem actual_stopped_reference_upper {Clen xi K rho : ℝ} (hC : 0 ≤ Clen) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hK : 0 < K) (hrho : 0 < rho) : + ∀ᶠ w : ℝ in atTop,∃ hw : 1 < w,∀ top : ℝ,∀ htop : w < top, + ∀ B : ℝ,Real.log B ≤ 2*Real.log w → ∀ Y : ℕ,∀ Cs eta : ℝ, + ∀ (residue : ℕ → ℕ) (z : Node) (ps : List ℕ), + ps ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi (K*(Real.log w)^2) (rho*K*(Real.log w)^2) + (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) residue z) + (sourcePrimeSet w top).card + (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*primeProduct w)) → + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*primeProduct w)) ps) + ≤ (33/100)*((Y:ℝ)/(ps.prod:ℝ))*strictEuler (ps.getLastD 0:ℝ) ∧ + referenceValue w (after w (rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*primeProduct w)) ps) + ≤ (33/100)*((Y:ℝ)/(ps.prod:ℝ))*primeProduct (ps.getLastD 0:ℝ) := by + obtain ⟨B₀,w₀,hB₀,_hw₀,hR⟩ := moving_vertex_reference_upper (rho*K) (mul_pos hrho hK) + filter_upwards [moving_candidate_node_window hC hxi hxi1 hK, + moving_stop_band_conditions Clen xi hxi.le hK,moving_compact_gap_small (12*B₀) hK, + eventually_ge_atTop w₀,eventually_ge_atTop (100:ℝ)] with w hwin hcond hlarge hw₀ hw100 + obtain ⟨hw,hwin⟩ := hwin + refine ⟨hw,?_⟩ + intro top htop B hcomp Y Cs eta residue z ps hp + let bins := label (zero_lt_one.trans hw) htop hxi + let v := rootVertex z ∅ (sourcePrimeSet w top) ((Y:ℝ)*primeProduct w) + have hf := ActualSourceStopBinding.actual_source_stops_first Y w Cs eta Clen B xi + (K*(Real.log w)^2) (rho*K*(Real.log w)^2) ((Y:ℝ)*primeProduct w) + (lower w top xi) (width w top xi) bins residue z (sourcePrimeSet w top) hp + have hn := hwin top htop B hcomp Y Cs eta (rho*K*(Real.log w)^2) residue z ps hf.2.1 + obtain ⟨hlo,hhi,hrlo,hrhi,hcons,hclosed,_hPlower,hpower⟩ := hn + have hhalf := hcond.2.2.2.2 + have hcut : B₀ ≤ (terminal w z ps).cutoff := by nlinarith + have hcutscale : (terminal w z ps).cutoff ≤ (rho*K)*(Real.log w)^2 := hhi + have hJ : 0 ≤ (Y:ℝ)/(ps.prod:ℝ) := div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) + have hd := actual_stopped_vertex_data Y w top Cs eta Clen B xi + (K*(Real.log w)^2) (rho*K*(Real.log w)^2) (zero_lt_one.trans hw) htop + (lower w top xi) (width w top xi) bins residue z ps hp + have hav : (after w v ps).available=sourcePrimes w (terminal w z ps).cutoff false := by + rw [sourcePrimes,hpower] + exact hd.2.2.2 + have hvnode : (after w v ps).node=terminal w z ps := after_node w v ps + have href := hR w (terminal w z ps).cutoff ((Y:ℝ)/(ps.prod:ℝ)) hw₀ hcut hcutscale hJ + (after w v ps) (by rw [hvnode]; exact hf.1) (by rw [hvnode]; linarith) + (by rw [hvnode]; exact hrhi) (by rw [hvnode]; exact hcons) (by rw [hvnode]) + (by rw [hvnode]; exact hclosed) hav (after_original_scale w Y z (sourcePrimeSet w top) ps) + rw [hpower] at href + have hP100 : 100 ≤ (ps.getLastD 0:ℝ) := by + have hsource := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop _).mp + ((SourceStopWindow.candidate_source_primes Y hw htop hxi residue z ps hf.2.1) (ps.getLastD 0) + (by + have he : ps.getLastD 0=ps.getLast hf.2.1.1 := by + conv_lhs => rw [← List.dropLast_append_getLast hf.2.1.1] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hf.2.1.1)) + exact hw100.trans hsource.2.1.le + have hstrict : 0 ≤ ((Y:ℝ)/(ps.prod:ℝ))*strictEuler (ps.getLastD 0:ℝ) := + mul_nonneg hJ (availableProduct_pos 0 _ false).le + exact ⟨by dsimp [v] at href; nlinarith,reference_strict_to_closed hJ hP100 href⟩ + +theorem floored_source_stopped_reference_upper {Clen xi K rho : ℝ} (hC : 0 ≤ Clen) + (hxi : 0 < xi) (hxi1 : xi ≤ 1) (hK : 0 < K) (hrho : 0 < rho) : + ∀ᶠ top : ℝ in atTop, + let w := ErdosInverseBoxHeight.sourceW top + let B := ErdosInverseBoxHeight.sourceB top + let Y := ErdosInverseBoxHeight.sourceY top + ∃ hw : 1 < w,∃ htop : w < top,∀ alpha Cs eta : ℝ, + ∀ (residue : ℕ → ℕ) (ps : List ℕ), + ps ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi (K*(Real.log w)^2) (rho*K*(Real.log w)^2) + (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) + residue (ErdosCorrectionLimit.sourceRootNode alpha top)) + (sourcePrimeSet w top).card + (rootVertex (ErdosCorrectionLimit.sourceRootNode alpha top) ∅ + (sourcePrimeSet w top) ((Y:ℝ)*primeProduct w)) → + referenceValue w (after w (rootVertex (ErdosCorrectionLimit.sourceRootNode alpha top) ∅ + (sourcePrimeSet w top) ((Y:ℝ)*primeProduct w)) ps) + ≤ (33/100)*((Y:ℝ)/(ps.prod:ℝ))*strictEuler (ps.getLastD 0:ℝ) ∧ + referenceValue w (after w (rootVertex (ErdosCorrectionLimit.sourceRootNode alpha top) ∅ + (sourcePrimeSet w top) ((Y:ℝ)*primeProduct w)) ps) + ≤ (33/100)*((Y:ℝ)/(ps.prod:ℝ))*primeProduct (ps.getLastD 0:ℝ) := by + have ht : Tendsto ErdosInverseBoxHeight.sourceW atTop atTop := + JacobsthalSourceScale.sourceW_tendsto.comp Real.tendsto_log_atTop + filter_upwards [ht.eventually (actual_stopped_reference_upper hC hxi hxi1 hK hrho), + Real.tendsto_log_atTop.eventually ErdosSearchCount.paper_incoming_geometry, + eventually_gt_atTop (1:ℝ)] with top hbound hgeometry htop1 + dsimp only + obtain ⟨hw,hbound⟩ := hbound + have htop : ErdosInverseBoxHeight.sourceW top < top := by + simpa only [JacobsthalSourceScale.sourceW,ErdosInverseBoxHeight.sourceW, + Real.exp_log (zero_lt_one.trans htop1)] using hgeometry.2.1 + have hcomp : Real.log (ErdosInverseBoxHeight.sourceB top) ≤ + 2*Real.log (ErdosInverseBoxHeight.sourceW top) := hgeometry.2.2.1 + refine ⟨hw,htop,?_⟩ + intro alpha Cs eta residue ps hp + exact hbound top htop (ErdosInverseBoxHeight.sourceB top) hcomp + (ErdosInverseBoxHeight.sourceY top) Cs eta residue (ErdosCorrectionLimit.sourceRootNode alpha top) ps hp + +end ErdosStoppedReferenceUpper + + + +namespace ErdosSubsetWord +open ErdosCofactorChoices ErdosSearchCount ErdosTagEvent +open NumberTheoryLean ActualSourceTags +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosInversePrimeBin + +attribute [local instance] Classical.propDecidable + +noncomputable def globalBins (w top xi : ℝ) : Fin (binCount w top xi) → Finset ℕ := + fun b => primeBin (lower w top xi b) (width w top xi b) +noncomputable def occupiedSearch (w top xi : ℝ) (mult : Fin (binCount w top xi) → ℕ) : + Finset (Fin (binCount w top xi)) := + Finset.univ.filter (fun b => searchBin w (lower w top xi b) ∧ 0 < mult b) + +theorem selected_prime_label {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) (b : Fin (binCount w top xi)) + {p : ℕ} (hp : p ∈ f b) : label (zero_lt_one.trans hw) htop hxi p=b := by + have hmem := ((mem_selections _ mult f).mp hf b).1 hp + exact ((bin_mem_iff_label (zero_lt_one.trans hw) htop hxi b p).mp hmem).2.2.2 + +theorem global_word_length {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) : (descendingWord f).length=∑ b,mult b := + descendingWord_length _ mult + (fun i j hij => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi i j hij) f hf + +theorem word_source_membership {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) : + ∀ p ∈ descendingWord f,p ∈ sourcePrimeSet w top := by + intro p hp + obtain ⟨b,hb⟩ := (mem_descendingWord f p).mp hp + have hbin := ((mem_selections _ mult f).mp hf b).1 hb + exact (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mpr + (bin_prime_in_source (zero_lt_one.trans hw) htop hxi b hbin) + +theorem word_search_count {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) : + searchCount w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi) (descendingWord f)= + ∑ b,if searchBin w (lower w top xi b) then mult b else 0 := by + have hmem := (mem_selections _ mult f).mp hf + have hd : Pairwise (fun i j => Disjoint (globalBins w top xi i) (globalBins w top xi j)) := + fun i j hij => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi i j hij + rw [searchCount,selectedCount_eq_sum,← List.sum_toFinset _ (descendingWord_nodup f), + descendingWord_toFinset,selectionPrimes,Finset.sum_biUnion] + · apply Finset.sum_congr rfl + intro b _ + calc + _ = ∑ _p ∈ f b,if searchBin w (lower w top xi b) then (1:ℕ) else 0 := by + apply Finset.sum_congr rfl + intro p hp + have hl := selected_prime_label hw htop hxi mult f hf b hp + simp [searchFlag,hl] + _ = _ := by split_ifs <;> simp [(hmem b).2] + · intro i _ j _ hij + exact selection_disjoint _ hd f (fun b => (hmem b).1) hij + +theorem word_search_count_eq_occupied {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) + (hone : ∀ b ∈ occupiedSearch w top xi mult,mult b=1) : + searchCount w (lower w top xi) (label (zero_lt_one.trans hw) htop hxi) (descendingWord f)= + (occupiedSearch w top xi mult).card := by + rw [word_search_count hw htop hxi mult f hf,occupiedSearch,Finset.card_eq_sum_ones,Finset.sum_filter] + apply Finset.sum_congr rfl + intro b _ + by_cases hs : searchBin w (lower w top xi b) + · by_cases hm : 0 < mult b + · have hh := hone b (Finset.mem_filter.mpr ⟨Finset.mem_univ _,hs,hm⟩) + simp [hs,hh] + · have hz : mult b=0 := by omega + simp [hs,hz] + · simp [hs] + +end ErdosSubsetWord + + + +namespace ErdosSubsetWord +open ErdosCofactorChoices ErdosSearchCount +open NumberTheoryLean +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition + +attribute [local instance] Classical.propDecidable + +theorem global_label_mono {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + {p q : ℕ} (hp : p ∈ sourcePrimeSet w top) (hq : q ∈ sourcePrimeSet w top) (hqp : q ≤ p) : + label (zero_lt_one.trans hw) htop hxi q ≤ label (zero_lt_one.trans hw) htop hxi p := by + have hpb := label_value_bounds (zero_lt_one.trans hw) htop hxi ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp hp).2 + have hqb := label_value_bounds (zero_lt_one.trans hw) htop hxi ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop q).mp hq).2 + by_contra hn + have hlt : label (zero_lt_one.trans hw) htop hxi p < label (zero_lt_one.trans hw) htop hxi q := lt_of_not_ge hn + have he : upper w top xi (label (zero_lt_one.trans hw) htop hxi p) ≤ + lower w top xi (label (zero_lt_one.trans hw) htop hxi q) := by + rw [upper_endpoint] + exact endpoint_mono (zero_lt_one.trans hw) htop hxi (Nat.succ_le_of_lt hlt) + have hreal : (q:ℝ) ≤ p := by exact_mod_cast hqp + linarith + +theorem word_label_count {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) (b : Fin (binCount w top xi)) : + ((descendingWord f).map (label (zero_lt_one.trans hw) htop hxi)).count b=mult b := by + have hmem := (mem_selections _ mult f).mp hf + have hd : Pairwise (fun i j => Disjoint (globalBins w top xi i) (globalBins w top xi j)) := + fun i j hij => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi i j hij + rw [List.count_eq_countP,List.countP_map,List.countP_eq_length_filter] + change selectedCount (fun p => label (zero_lt_one.trans hw) htop hxi p == b) (descendingWord f)=mult b + rw [selectedCount_eq_sum,← List.sum_toFinset _ (descendingWord_nodup f), + descendingWord_toFinset,selectionPrimes,Finset.sum_biUnion] + · calc + _ = ∑ i,if i=b then mult i else 0 := by + apply Finset.sum_congr rfl + intro i _ + calc + _ = ∑ _p ∈ f i,if i=b then (1:ℕ) else 0 := by + apply Finset.sum_congr rfl + intro p hp + have hl := selected_prime_label hw htop hxi mult f hf i hp + simp [hl] + _ = _ := by split_ifs <;> simp [(hmem i).2] + _ = _ := by simp + · intro i _ j _ hij + exact selection_disjoint _ hd f (fun i => (hmem i).1) hij + +theorem word_labels_ordered {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) : + ((descendingWord f).map (label (zero_lt_one.trans hw) htop hxi)).Pairwise (· ≥ ·) := by + rw [List.pairwise_map] + apply (descendingWord_strict f).imp_of_mem + intro p q hp hq hpq + exact global_label_mono hw htop hxi (word_source_membership hw htop hxi mult f hf p hp) + (word_source_membership hw htop hxi mult f hf q hq) hpq.le + +theorem selection_label_word_eq {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f g : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) (hg : g ∈ selections (globalBins w top xi) mult) : + (descendingWord f).map (label (zero_lt_one.trans hw) htop hxi)= + (descendingWord g).map (label (zero_lt_one.trans hw) htop hxi) := by + have hp : ((descendingWord f).map (label (zero_lt_one.trans hw) htop hxi)).Perm + ((descendingWord g).map (label (zero_lt_one.trans hw) htop hxi)) := by + apply List.perm_iff_count.mpr + intro b + rw [word_label_count hw htop hxi mult f hf,word_label_count hw htop hxi mult g hg] + exact List.Perm.eq_of_pairwise' (word_labels_ordered hw htop hxi mult f hf) + (word_labels_ordered hw htop hxi mult g hg) hp + +theorem selection_prefix_labels_eq {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (f g : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) mult) (hg : g ∈ selections (globalBins w top xi) mult) + (k : ℕ) : + ((descendingWord f).take k).map (label (zero_lt_one.trans hw) htop hxi)= + ((descendingWord g).take k).map (label (zero_lt_one.trans hw) htop hxi) := by + rw [List.map_take,List.map_take,selection_label_word_eq hw htop hxi mult f g hf hg] + +end ErdosSubsetWord + + + +namespace NumberTheoryLean.FiniteBoxWordMass +open ErdosCofactorChoices ErdosSubsetWord CanonicalSubsetBox +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem word_injective {n : ℕ} (P : Fin n → Finset ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) (f g : Fin n → Finset ℕ) + (hf : ∀ i,f i ⊆ P i) (hg : ∀ i,g i ⊆ P i) (he : descendingWord f=descendingWord g) : f=g := by + have hu : selectionPrimes f=selectionPrimes g := by + rw [← descendingWord_toFinset f,← descendingWord_toFinset g,he] + funext i + rw [← recover_bin P hd f hf i,← recover_bin P hd g hg i,hu] + +noncomputable def wordBox {n : ℕ} (P : Fin n → Finset ℕ) (mult : Fin n → ℕ) : Finset (List ℕ) := + (selections P mult).image descendingWord + +theorem wordBox_mass {n : ℕ} (P : Fin n → Finset ℕ) (mult : Fin n → ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) : + (∑ ps ∈ wordBox P mult,prefixWeight ps)=selectionMass P mult := by + rw [wordBox,Finset.sum_image] + · apply Finset.sum_congr rfl + intro f hf + rw [StoppedVertexHistory.prefixWeight_product, + descendingWord_product P hd f (fun i => ((mem_selections P mult f).mp hf i).1)] + · intro f hf g hg he + exact word_injective P hd f g (fun i => ((mem_selections P mult f).mp hf i).1) + (fun i => ((mem_selections P mult g).mp hg i).1) he + +theorem wordBoxes_disjoint {n : ℕ} (P : Fin n → Finset ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) (mult mult' : Fin n → ℕ) (hne : mult ≠ mult') : + Disjoint (wordBox P mult) (wordBox P mult') := by + apply Finset.disjoint_left.mpr + intro ps hp hp' + obtain ⟨f,hf,hef⟩ := Finset.mem_image.mp hp + obtain ⟨g,hg,heg⟩ := Finset.mem_image.mp hp' + have hfP := (mem_selections P mult f).mp hf + have hgP := (mem_selections P mult' g).mp hg + have he := word_injective P hd f g (fun i => (hfP i).1) (fun i => (hgP i).1) (hef.trans heg.symm) + subst g + apply hne + funext i + exact (hfP i).2.symm.trans (hgP i).2 + +noncomputable def boxWords {n : ℕ} (P : Fin n → Finset ℕ) (M : Finset (Fin n → ℕ)) : Finset (List ℕ) := + M.biUnion (wordBox P) + +theorem total_box_mass_eq {n : ℕ} (P : Fin n → Finset ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) (M : Finset (Fin n → ℕ)) : + (∑ mult ∈ M,selectionMass P mult) = ∑ ps ∈ boxWords P M,prefixWeight ps := by + rw [boxWords,Finset.sum_biUnion (fun i _ j _ hij => wordBoxes_disjoint P hd i j hij)] + apply Finset.sum_congr rfl + intro mult _hm + exact (wordBox_mass P mult hd).symm +end NumberTheoryLean.FiniteBoxWordMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteHistorySupport.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteHistorySupport.lean new file mode 100644 index 0000000000000000000000000000000000000000..de0dca1ab429a7ea1fcf30f02585908363d01e38 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteHistorySupport.lean @@ -0,0 +1,817 @@ +import Mathlib.Probability.Kernel.Composition.IntegralCompProd +import Mathlib.Probability.Kernel.IonescuTulcea.PartialTraj +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Probability.TransitionKernels + +namespace OAI + +namespace Erdos970 + + +namespace NumberTheoryLean.FinitePathGeometry + +open Set +open DerivativeWeights TransitionKernels + +inductive Side | even | odd deriving DecidableEq + +def Side.flip : Side → Side | .even => .odd | .odd => .even + +noncomputable def weight : Side → ℝ → ℝ | .even => phiEven | .odd => phiOdd + +def Valid : Side → ℝ → Prop + | .even, s => 198 / 100 ≤ s + | .odd, s => 95 / 100 ≤ s + +noncomputable def minRatio : Side → ℝ → ℝ + | .even, s => s - 1 + | .odd, s => max 2 (s - 1) + +noncomputable def transitionDensity (i : Side) (s : ℝ) : ℝ → ℝ := + tailDensity (minRatio i s) (weight i s) (fun t => W t * weight i.flip t) + +def Admissible : Side → ℝ → List ℝ → Prop + | _, _, [] => True + | i, s, t :: ts => minRatio i s ≤ t ∧ Admissible i.flip t ts + +noncomputable def nextExponent (r t : ℝ) : ℝ := r / (t + 1) +noncomputable def nextGap (r t : ℝ) : ℝ := r * t / (t + 1) +noncomputable def cost (t : ℝ) : ℝ := Real.log (1 + 1 / t) + +noncomputable def finalGap : ℝ → List ℝ → ℝ + | r, [] => r + | r, t :: ts => finalGap (nextGap r t) ts + +def finalRatio : ℝ → List ℝ → ℝ + | s, [] => s + | _, t :: ts => finalRatio t ts + +def finalSide : Side → List ℝ → Side + | i, [] => i + | i, _ :: ts => finalSide i.flip ts + +noncomputable def pathCost : List ℝ → ℝ + | [] => 0 + | t :: ts => cost t + pathCost ts + +noncomputable def harmonicDensity : List ℝ → ℝ + | [] => 1 + | t :: ts => (1 / (t + 1)) * harmonicDensity ts + +noncomputable def tiltedDensity : Side → ℝ → List ℝ → ℝ + | _, _, [] => 1 + | i, s, t :: ts => transitionDensity i s t * tiltedDensity i.flip t ts + +def AllExponentsAbove (ell : ℝ) : ℝ → List ℝ → Prop + | _, [] => True + | r, t :: ts => ell < nextExponent r t ∧ AllExponentsAbove ell (nextGap r t) ts + +theorem valid_pos {i : Side} {s : ℝ} (hs : Valid i s) : 0 < s := by + cases i <;> dsimp [Valid] at hs <;> linarith + +theorem weight_pos {i : Side} {s : ℝ} (hs : Valid i s) : 0 < weight i s := by + cases i with + | even => exact phiEven_pos (by dsimp [Valid] at hs; linarith) + | odd => exact phiOdd_pos s + +theorem valid_next {i : Side} {s t : ℝ} (hs : Valid i s) (ht : minRatio i s ≤ t) : + Valid i.flip t := by + cases i with + | even => dsimp [Valid, minRatio, Side.flip] at *; linarith + | odd => + change 198 / 100 ≤ t + change max 2 (s - 1) ≤ t at ht + linarith [le_max_left (2 : ℝ) (s - 1)] + +theorem minRatio_ge_sub_one (i : Side) (s : ℝ) : s - 1 ≤ minRatio i s := by + cases i with + | even => exact le_rfl + | odd => exact le_max_right _ _ + +theorem transitionDensity_even (s : EvenState) : transitionDensity .even s = evenDensity s := rfl +theorem transitionDensity_odd (s : OddState) : transitionDensity .odd s = oddDensity s := rfl + +theorem nextGap_pos {r t : ℝ} (hr : 0 < r) (ht : 0 < t) : 0 < nextGap r t := by + unfold nextGap + positivity + +theorem nextExponent_pos {r t : ℝ} (hr : 0 < r) (ht : 0 < t) : 0 < nextExponent r t := by + unfold nextExponent + positivity + +theorem gap_exponent_conservation {r t : ℝ} (ht : 0 < t) : + nextGap r t + nextExponent r t = r := by + unfold nextGap nextExponent + field_simp + +theorem nextGap_div_ratio {r t : ℝ} (ht : 0 < t) : nextGap r t / t = nextExponent r t := by + unfold nextGap nextExponent + field_simp + +theorem nextRatio_identity {r t : ℝ} (hr : 0 < r) (ht : 0 < t) : + nextGap r t / nextExponent r t = t := by + unfold nextGap nextExponent + field_simp + +theorem exponent_le_cutoff {i : Side} {s t r : ℝ} + (hs : Valid i s) (ht : minRatio i s ≤ t) (hr : 0 < r) : nextExponent r t ≤ r / s := by + have hs0 := valid_pos hs + have ht0 := valid_pos (valid_next hs ht) + have hst : s ≤ t + 1 := by linarith [minRatio_ge_sub_one i s] + exact div_le_div_of_nonneg_left hr.le hs0 hst + +theorem upper_standard_admission {s t r : ℝ} (ht : minRatio .odd s ≤ t) (hr : 0 < r) : + 2 * nextExponent r t ≤ nextGap r t := by + have ht2 : 2 ≤ t := le_trans (le_max_left _ _) ht + unfold nextExponent nextGap + have h := mul_le_mul_of_nonneg_left ht2 hr.le + have ht1 : 0 < t + 1 := by linarith + apply (le_div_iff₀ ht1).mpr + field_simp + nlinarith + +theorem step_weight_identity {i : Side} {s t r : ℝ} + (hs : Valid i s) (ht : minRatio i s ≤ t) (hr : 0 < r) : + 1 / (t + 1) = transitionDensity i s t * (nextGap r t / r) ^ 2 * + (weight i s / weight i.flip t) := by + have hv := valid_next hs ht + have ht0 := valid_pos hv + have hw := weight_pos hs + have hw' := weight_pos hv + unfold transitionDensity tailDensity + rw [indicator_of_mem (show t ∈ Ici (minRatio i s) from ht)] + unfold W nextGap + field_simp + +theorem valid_final {i : Side} {s : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) : Valid (finalSide i ts) (finalRatio s ts) := by + induction ts generalizing i s with + | nil => exact hs + | cons t ts ih => exact ih (valid_next hs ht.1) ht.2 + +theorem finalGap_pos {i : Side} {s r : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) (hr : 0 < r) : 0 < finalGap r ts := by + induction ts generalizing i s r with + | nil => exact hr + | cons t ts ih => + have hv := valid_next hs ht.1 + exact ih hv ht.2 (nextGap_pos hr (valid_pos hv)) + +theorem telescoping_path_weight {i : Side} {s r : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) (hr : 0 < r) : + harmonicDensity ts = tiltedDensity i s ts * (finalGap r ts / r) ^ 2 * + (weight i s / weight (finalSide i ts) (finalRatio s ts)) := by + induction ts generalizing i s r with + | nil => + have hw := weight_pos hs + simp only [harmonicDensity, tiltedDensity, finalGap, finalSide, finalRatio] + field_simp + | cons t ts ih => + have hv := valid_next hs ht.1 + have ht0 := valid_pos hv + have hn := nextGap_pos hr ht0 + have hw := weight_pos hs + have hw' := weight_pos hv + have hew := weight_pos (valid_final hv ht.2) + simp only [harmonicDensity, tiltedDensity, finalGap, finalSide, finalRatio] + rw [step_weight_identity hs ht.1 hr, ih hv ht.2 hn] + field_simp + +theorem cost_pos {t : ℝ} (ht : 0 < t) : 0 < cost t := by + unfold cost + exact Real.log_pos (by have h : 0 < 1 / t := one_div_pos.mpr ht; linarith) + +theorem nextGap_eq_cost {r t : ℝ} (ht : 0 < t) : nextGap r t = r * Real.exp (-cost t) := by + have hx : 0 < 1 + 1 / t := by positivity + unfold cost nextGap + rw [Real.exp_neg, Real.exp_log hx] + field_simp + +theorem finalGap_eq_cost {i : Side} {s r : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) : + finalGap r ts = r * Real.exp (-pathCost ts) := by + induction ts generalizing i s r with + | nil => simp [finalGap, pathCost] + | cons t ts ih => + have hv := valid_next hs ht.1 + rw [finalGap, ih hv ht.2, nextGap_eq_cost (valid_pos hv), pathCost, + neg_add, Real.exp_add] + ring + +theorem final_gap_ratio_le_cutoff {i : Side} {s r : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) (hr : 0 < r) : + finalGap r ts / finalRatio s ts ≤ r / s := by + induction ts generalizing i s r with + | nil => exact le_rfl + | cons t ts ih => + have hv := valid_next hs ht.1 + have ht0 := valid_pos hv + have h := ih hv ht.2 (nextGap_pos hr ht0) + rw [nextGap_div_ratio ht0] at h + exact le_trans h (exponent_le_cutoff hs ht.1 hr) + +theorem all_exponents_iff_final {i : Side} {s r ell : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) (hr : 0 < r) (hne : ts ≠ []) : + AllExponentsAbove ell r ts ↔ ell < finalGap r ts / finalRatio s ts := by + induction ts generalizing i s r with + | nil => exact (hne rfl).elim + | cons t ts ih => + have hv := valid_next hs ht.1 + have ht0 := valid_pos hv + have hn := nextGap_pos hr ht0 + cases ts with + | nil => + simp only [AllExponentsAbove, finalGap, finalRatio, and_true] + rw [nextGap_div_ratio ht0] + | cons u us => + have hb := final_gap_ratio_le_cutoff hv ht.2 hn + rw [nextGap_div_ratio ht0] at hb + change (ell < nextExponent r t ∧ AllExponentsAbove ell (nextGap r t) (u :: us)) ↔ + ell < finalGap (nextGap r t) (u :: us) / finalRatio t (u :: us) + rw [ih hv ht.2 hn (by simp)] + exact ⟨fun h => h.2, fun h => ⟨lt_of_lt_of_le h hb, h⟩⟩ + +theorem arrival_cutoff {i : Side} {s r ell : ℝ} {ts : List ℝ} + (hs : Valid i s) (ht : Admissible i s ts) (hr : 0 < r) + (hell : 0 < ell) (hne : ts ≠ []) : + AllExponentsAbove ell r ts ↔ finalRatio s ts < finalGap r ts / ell := by + rw [all_exponents_iff_final hs ht hr hne] + have hratio := valid_pos (valid_final hs ht) + rw [lt_div_iff₀ hratio, lt_div_iff₀ hell, mul_comm] + +end NumberTheoryLean.FinitePathGeometry + + + +namespace NumberTheoryLean.FinitePathMeasures + +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathGeometry + +abbrev State := EvenState ⊕ OddState +abbrev CostState := State × ℝ + +noncomputable def evenToOdd : Kernel EvenState OddState := + evenKernel.comapRight (MeasurableEmbedding.subtype_coe measurableSet_Ici) + +noncomputable def oddToEven : Kernel OddState EvenState := + oddKernel.comapRight (MeasurableEmbedding.subtype_coe measurableSet_Ici) + +instance evenToOdd_isMarkovKernel : IsMarkovKernel evenToOdd := by + apply Kernel.IsMarkovKernel.comapRight + intro s + have h := (ae_mem_iff_measure_eq (μ := evenKernel s) + (s := Ici (95 / 100 : ℝ)) measurableSet_Ici.nullMeasurableSet).mp (evenKernel_ae_odd_domain s) + rw [measure_univ] at h + convert! h using 1 + congr 1 + ext t + simp + rfl + +instance oddToEven_isMarkovKernel : IsMarkovKernel oddToEven := by + apply Kernel.IsMarkovKernel.comapRight + intro s + have h := (ae_mem_iff_measure_eq (μ := oddKernel s) + (s := Ici (198 / 100 : ℝ)) measurableSet_Ici.nullMeasurableSet).mp (oddKernel_ae_even_domain s) + rw [measure_univ] at h + convert! h using 1 + congr 1 + ext t + simp + rfl + +noncomputable def evenBranch : Kernel EvenState State := evenToOdd.map Sum.inr +noncomputable def oddBranch : Kernel OddState State := oddToEven.map Sum.inl + +instance evenBranch_isMarkovKernel : IsMarkovKernel evenBranch := + Kernel.IsMarkovKernel.map _ measurable_inr + +instance oddBranch_isMarkovKernel : IsMarkovKernel oddBranch := + Kernel.IsMarkovKernel.map _ measurable_inl + +noncomputable def stateKernel : Kernel State State where + toFun := Sum.elim evenBranch oddBranch + measurable' := evenBranch.measurable.sumElim oddBranch.measurable + +instance stateKernel_isMarkovKernel : IsMarkovKernel stateKernel := by + constructor + intro s + cases s with + | inl s => change IsProbabilityMeasure (evenBranch s); infer_instance + | inr s => change IsProbabilityMeasure (oddBranch s); infer_instance + +def stateRatio : State → ℝ := Sum.elim Subtype.val Subtype.val +def stateSide : State → Side := Sum.elim (fun _ => .even) (fun _ => .odd) + +theorem stateRatio_valid (s : State) : Valid (stateSide s) (stateRatio s) := by + cases s with + | inl s => exact s.2 + | inr s => exact s.2 + +theorem stateRatio_measurable : Measurable stateRatio := + measurable_subtype_coe.sumElim measurable_subtype_coe + +theorem cost_measurable : Measurable cost := by + unfold cost + exact Real.measurable_log.comp (measurable_const.add (measurable_const.div measurable_id)) + +noncomputable def addCost (z : CostState × State) : CostState := + (z.2, z.1.2 + cost (stateRatio z.2)) + +theorem addCost_measurable : Measurable addCost := + measurable_snd.prodMk ((measurable_snd.comp measurable_fst).add + (cost_measurable.comp (stateRatio_measurable.comp measurable_snd))) + +noncomputable def costKernel : Kernel CostState CostState := + (Kernel.id ×ₖ stateKernel.prodMkRight ℝ).map addCost + +instance costKernel_isMarkovKernel : IsMarkovKernel costKernel := + Kernel.IsMarkovKernel.map _ addCost_measurable + +theorem costKernel_apply (z : CostState) {B : Set CostState} (hB : MeasurableSet B) : + costKernel z B = stateKernel z.1 {s | (s, z.2 + cost (stateRatio s)) ∈ B} := by + rw [costKernel, Kernel.map_apply' _ addCost_measurable _ hB, + Kernel.prod_apply' _ _ _ (addCost_measurable hB), Kernel.id_apply] + rw [lintegral_dirac'] + · rfl + · exact measurable_measure_prodMk_left (addCost_measurable hB) + +noncomputable def historyKernel (n : ℕ) : + Kernel (∀ _ : Finset.Iic n, CostState) CostState := + costKernel.comap (fun h => h ⟨n, by simp⟩) (measurable_pi_apply (⟨n, by simp⟩ : Finset.Iic n)) + +instance historyKernel_isMarkovKernel (n : ℕ) : IsMarkovKernel (historyKernel n) := by + unfold historyKernel + infer_instance + +noncomputable def finitePathKernel (n : ℕ) : + Kernel (∀ _ : Finset.Iic (0 : ℕ), CostState) (∀ _ : Finset.Iic n, CostState) := + Kernel.partialTraj (X := fun _ => CostState) historyKernel 0 n + +instance finitePathKernel_isMarkovKernel (n : ℕ) : IsMarkovKernel (finitePathKernel n) := by + unfold finitePathKernel + infer_instance + +noncomputable def finitePathMeasure (s : State) (n : ℕ) : Measure (∀ _ : Finset.Iic n, CostState) := + finitePathKernel n (fun _ => (s, 0)) + +instance finitePathMeasure_isProbabilityMeasure (s : State) (n : ℕ) : + IsProbabilityMeasure (finitePathMeasure s n) := by + unfold finitePathMeasure + infer_instance + +theorem finite_history_factorization {a b c : ℕ} (hab : a ≤ b) (hbc : b ≤ c) : + Kernel.partialTraj (X := fun _ => CostState) historyKernel b c ∘ₖ Kernel.partialTraj (X := fun _ => CostState) historyKernel a b = + Kernel.partialTraj (X := fun _ => CostState) historyKernel a c := + Kernel.partialTraj_comp_partialTraj hab hbc + +end NumberTheoryLean.FinitePathMeasures + + + +namespace NumberTheoryLean.ReciprocalGapExposure +open FinitePathGeometry +attribute [local instance] Classical.propDecidable + +noncomputable def potential (a r : ℝ) : ℝ := min (1/r) (1/a) + +theorem potential_step_mono {a r t : ℝ} (hr : 0 < r) (ht : 0 < t) : + potential a r ≤ potential a (nextGap r t) := by + have hn := nextGap_pos hr ht + have hle : nextGap r t ≤ r := by linarith [gap_exponent_conservation (r := r) ht,nextExponent_pos hr ht] + exact min_le_min_right _ (one_div_le_one_div_of_le hn hle) + +theorem selected_step_exposure {a L r t : ℝ} (ha : 0 < a) (hL : 0 ≤ L) (hr : 0 < r) (ht : 0 < t) : + (if a ≤ nextGap r t ∧ t ≤ L then 1/nextGap r t else 0) ≤ + (L+1)*(potential a (nextGap r t)-potential a r) := by + have hn := nextGap_pos hr ht + have hmono := potential_step_mono (a := a) hr ht + split_ifs with hs + · have hnr : nextGap r t ≤ r := by linarith [gap_exponent_conservation (r := r) ht,nextExponent_pos hr ht] + have hpnext : potential a (nextGap r t)=1/nextGap r t := + min_eq_left (one_div_le_one_div_of_le ha hs.1) + have hpr : potential a r=1/r := min_eq_left (one_div_le_one_div_of_le ha (hs.1.trans hnr)) + rw [hpnext,hpr] at hmono ⊢ + have he : (t+1)*(1/nextGap r t-1/r)=1/nextGap r t := by + unfold nextGap + field_simp [hr.ne',ht.ne',show t+1 ≠ 0 by positivity] + ring + have hm := mul_le_mul_of_nonneg_right (show t+1 ≤ L+1 by linarith) (sub_nonneg.mpr hmono) + rw [he] at hm + exact hm + · exact mul_nonneg (by linarith) (sub_nonneg.mpr hmono) + +noncomputable def exposure (a L : ℝ) : ℝ → List ℝ → ℝ + | _,[] => 0 + | r,t::ts => (if a ≤ nextGap r t ∧ t ≤ L then 1/nextGap r t else 0)+exposure a L (nextGap r t) ts + +theorem exposure_potential {a L r : ℝ} (ha : 0 < a) (hL : 0 ≤ L) (hr : 0 < r) + (ts : List ℝ) (ht : ∀ t ∈ ts,0 < t) : + exposure a L r ts ≤ (L+1)*(potential a (finalGap r ts)-potential a r) := by + induction ts generalizing r with + | nil => simp [exposure,finalGap] + | cons t ts ih => + have hp := ht t (by simp) + have hs := selected_step_exposure ha hL hr hp + have hh := ih (nextGap_pos hr hp) (fun u hu => ht u (by simp [hu])) + change _+exposure a L (nextGap r t) ts ≤ _ + change _ ≤ (L+1)*(potential a (finalGap (nextGap r t) ts)-potential a r) + linarith + +theorem exposure_bound {a L r : ℝ} (ha : 0 < a) (hL : 0 ≤ L) (hr : 0 < r) + (ts : List ℝ) (ht : ∀ t ∈ ts,0 < t) : exposure a L r ts ≤ (L+1)/a := by + have hh := exposure_potential ha hL hr ts ht + have hn : 0 ≤ potential a r := le_min (by positivity) (by positivity) + have hu : potential a (finalGap r ts) ≤ 1/a := min_le_right _ _ + have hm := mul_le_mul_of_nonneg_left (show potential a (finalGap r ts)-potential a r ≤ 1/a by linarith) + (show 0 ≤ L+1 by linarith) + exact hh.trans (by simpa only [mul_one_div] using hm) + +theorem admissible_exposure_bound {a L r s : ℝ} {i : Side} + (ha : 0 < a) (hL : 0 ≤ L) (hr : 0 < r) (hs : Valid i s) + (ts : List ℝ) (had : Admissible i s ts) : exposure a L r ts ≤ (L+1)/a := by + apply exposure_bound ha hL hr ts + induction ts generalizing i s with + | nil => simp + | cons t ts ih => + have hnext := valid_next hs had.1 + intro u hu + rcases List.mem_cons.mp hu with he | hu + · subst u + exact valid_pos hnext + · exact ih hnext had.2 u hu +end NumberTheoryLean.ReciprocalGapExposure + + + +namespace NumberTheoryLean.FiniteHistoryTransport + +open Set MeasureTheory ProbabilityTheory MeasurableEquiv +open scoped ENNReal + +abbrev Hist (X : Type*) (n : ℕ) := ∀ _ : Finset.Iic n, X + +def last {X : Type*} (n : ℕ) (h : Hist X n) : X := h ⟨n, by simp⟩ + +def mapHist {X Y : Type*} (f : X → Y) (n : ℕ) (h : Hist X n) : Hist Y n := + fun k => f (h k) + +noncomputable def extend {X : Type*} [MeasurableSpace X] (n : ℕ) + (h : Hist X n) (x : X) : Hist X (n+1) := + _root_.IicProdIoc (X := fun _ => X) n (n+1) (h, piSingleton (X := fun _ => X) n x) + +theorem mapHist_measurable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + {f : X → Y} (hf : Measurable f) (n : ℕ) : Measurable (mapHist f n) := by + exact Measurable.of_eval (fun k => hf.comp (measurable_pi_apply k)) + +theorem extend_measurable {X : Type*} [MeasurableSpace X] (n : ℕ) : + Measurable (fun p : Hist X n × X => extend n p.1 p.2) := by + exact (measurable_IicProdIoc (X := fun _ => X) (m := n) (n := n+1)).comp + (measurable_fst.prodMk ((piSingleton (X := fun _ => X) n).measurable.comp measurable_snd)) + +theorem mapHist_extend {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (f : X → Y) (n : ℕ) (h : Hist X n) (x : X) : + mapHist f (n+1) (extend n h x) = extend n (mapHist f n h) (f x) := by + ext k + simp only [mapHist, extend, IicProdIoc_def, piSingleton, + MeasurableEquiv.coe_mk, Equiv.coe_fn_mk] + split_ifs <;> simp + +private theorem last_measurable_for_comap {X : Type*} [MeasurableSpace X] (n : ℕ) : + Measurable (last (X := X) n) := measurable_pi_apply _ + +noncomputable def pastKernel {X : Type*} [MeasurableSpace X] + (K : Kernel X X) (n : ℕ) : Kernel (Hist X n) X := + K.comap (last n) (last_measurable_for_comap n) + +instance pastKernel_sfinite {X : Type*} [MeasurableSpace X] + (K : Kernel X X) [IsSFiniteKernel K] (n : ℕ) : IsSFiniteKernel (pastKernel K n) := by + unfold pastKernel + infer_instance + +noncomputable def pathKernel {X : Type*} [MeasurableSpace X] + (K : Kernel X X) (n : ℕ) : Kernel (Hist X 0) (Hist X n) := + Kernel.partialTraj (X := fun _ => X) (pastKernel K) 0 n + +instance pathKernel_sfinite {X : Type*} [MeasurableSpace X] + (K : Kernel X X) [IsSFiniteKernel K] (n : ℕ) : IsSFiniteKernel (pathKernel K n) := by + unfold pathKernel + infer_instance + +theorem lintegral_pathKernel_succ {X : Type*} [MeasurableSpace X] + (K : Kernel X X) [IsSFiniteKernel K] (n : ℕ) (h₀ : Hist X 0) + {F : Hist X (n+1) → ℝ≥0∞} (hF : Measurable F) : + ∫⁻ h, F h ∂pathKernel K (n+1) h₀ = + ∫⁻ h, ∫⁻ x, F (extend n h x) ∂K (last n h) ∂pathKernel K n h₀ := by + rw [pathKernel, Kernel.partialTraj_succ_of_le (Nat.zero_le n), + Kernel.lintegral_map _ (measurable_IicProdIoc (X := fun _ => X) (m := n) (n := n+1)) _ hF, + Kernel.lintegral_comp _ _ _ (by exact hF.comp measurable_IicProdIoc)] + congr 1 + funext h + rw [Kernel.lintegral_id_prod (by exact hF.comp measurable_IicProdIoc), + Kernel.lintegral_map _ (piSingleton (X := fun _ => X) n).measurable _ + (by exact (hF.comp measurable_IicProdIoc).comp measurable_prodMk_left)] + rw [pastKernel, Kernel.comap_apply] + rfl + +end NumberTheoryLean.FiniteHistoryTransport + + + +namespace NumberTheoryLean.FiniteGapExposure +open FinitePathGeometry ReciprocalGapExposure +attribute [local instance] Classical.propDecidable + +theorem finite_potential_telescope (N : ℕ) (f : Fin (N+1) → ℝ) : + (∑ j : Fin N,(f j.succ-f j.castSucc))=f (Fin.last N)-f 0 := by + have h₁ := Fin.sum_univ_succ f + have h₂ := Fin.sum_univ_castSucc f + rw [Finset.sum_sub_distrib] + linarith + +theorem finite_arrival_exposure {a L : ℝ} (ha : 0 < a) (hL : 0 ≤ L) + (N : ℕ) (r : Fin (N+1) → ℝ) (t : Fin N → ℝ) + (hr : ∀ j,0 < r j) (ht : ∀ j,0 < t j) + (hflow : ∀ j,r j.succ=nextGap (r j.castSucc) (t j)) : + (∑ j : Fin N,if a ≤ r j.succ ∧ t j ≤ L then 1/r j.succ else 0) ≤ (L+1)/a := by + have hsum : (∑ j : Fin N,if a ≤ r j.succ ∧ t j ≤ L then 1/r j.succ else 0) ≤ + ∑ j : Fin N,(L+1)*(potential a (r j.succ)-potential a (r j.castSucc)) := by + apply Finset.sum_le_sum + intro j _ + rw [hflow j] + exact selected_step_exposure ha hL (hr j.castSucc) (ht j) + rw [← Finset.mul_sum,finite_potential_telescope N (fun j => potential a (r j))] at hsum + have hn : 0 ≤ potential a (r 0) := le_min (one_div_nonneg.mpr (hr 0).le) (by positivity) + have hu : potential a (r (Fin.last N)) ≤ 1/a := min_le_right _ _ + have hm := mul_le_mul_of_nonneg_left (show potential a (r (Fin.last N))-potential a (r 0) ≤ 1/a by linarith) + (show 0 ≤ L+1 by linarith) + exact hsum.trans (by simpa only [mul_one_div] using hm) + +theorem finite_all_exposure {a L : ℝ} (ha : 0 < a) (hL : 0 ≤ L) + (N : ℕ) (r s : Fin (N+1) → ℝ) + (hr : ∀ j,0 < r j) (hs : ∀ j,0 < s j) + (hflow : ∀ j : Fin N,r j.succ=nextGap (r j.castSucc) (s j.succ)) : + (∑ j : Fin (N+1),if a ≤ r j ∧ s j ≤ L then 1/r j else 0) ≤ (L+2)/a := by + have hh := finite_arrival_exposure ha hL N r (fun j => s j.succ) hr (fun j => hs j.succ) hflow + rw [Fin.sum_univ_succ] + have hinit : (if a ≤ r 0 ∧ s 0 ≤ L then 1/r 0 else 0) ≤ 1/a := by + split_ifs with h + · exact one_div_le_one_div_of_le ha h.1 + · positivity + have he : (L+2)/a=1/a+(L+1)/a := by ring + rw [he] + exact add_le_add hinit hh +end NumberTheoryLean.FiniteGapExposure + + + +namespace NumberTheoryLean.FiniteHistoryTransport + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] +variable (K : Kernel X X) (L : Kernel Y Y) [IsSFiniteKernel K] [IsSFiniteKernel L] +variable {f : X → Y} (hf : Measurable f) +variable (hstep : ∀ x, (K x).map f = L (f x)) + +include hf hstep + +theorem lintegral_mapHist (n : ℕ) (h₀ : Hist X 0) + {F : Hist Y n → ℝ≥0∞} (hF : Measurable F) : + ∫⁻ h, F (mapHist f n h) ∂pathKernel K n h₀ = + ∫⁻ h, F h ∂pathKernel L n (mapHist f 0 h₀) := by + induction n with + | zero => + simp only [pathKernel, Kernel.partialTraj_self, Kernel.id_apply] + rw [lintegral_dirac' _ (by exact hF.comp (mapHist_measurable hf 0)), lintegral_dirac' _ hF] + | succ n ih => + rw [lintegral_pathKernel_succ K n h₀ (by exact hF.comp (mapHist_measurable hf (n+1))), + lintegral_pathKernel_succ L n (mapHist f 0 h₀) hF] + have hG : Measurable (fun h : Hist Y n => + ∫⁻ y, F (extend n h y) ∂L (last n h)) := by + have hm : Measurable (Function.uncurry (fun h : Hist Y n => fun y : Y => + F (extend n h y))) := hF.comp (extend_measurable n) + simpa only [pastKernel, Kernel.comap_apply] using + (hm.lintegral_kernel_prod_right (κ := pastKernel L n)) + calc + _ = ∫⁻ h, ∫⁻ y, F (extend n (mapHist f n h) y) + ∂L (last n (mapHist f n h)) ∂pathKernel K n h₀ := by + apply lintegral_congr + intro h + simp only [mapHist_extend] + change (∫⁻ x, F (extend n (mapHist f n h) (f x)) ∂K (last n h)) = + ∫⁻ y, F (extend n (mapHist f n h) y) ∂L (f (last n h)) + rw [← hstep (last n h), lintegral_map] + · exact hF.comp ((extend_measurable n).comp measurable_prodMk_left) + · exact hf + _ = _ := ih hG + +theorem pathKernel_mapHist (n : ℕ) : + (pathKernel K n).map (mapHist f n) = + (pathKernel L n).comap (mapHist f 0) (mapHist_measurable hf 0) := by + apply Kernel.ext_fun + intro h₀ F hF + rw [Kernel.lintegral_map _ (mapHist_measurable hf n) _ hF, Kernel.comap_apply] + exact lintegral_mapHist K L hf hstep n h₀ hF + +theorem pathMeasure_mapHist (n : ℕ) (h₀ : Hist X 0) : + (pathKernel K n h₀).map (mapHist f n) = + pathKernel L n (mapHist f 0 h₀) := by + rw [← Kernel.map_apply _ (mapHist_measurable hf n), pathKernel_mapHist K L hf hstep, + Kernel.comap_apply] + +end NumberTheoryLean.FiniteHistoryTransport + + + +namespace NumberTheoryLean.FiniteHistoryTransport + +open Set MeasureTheory ProbabilityTheory Preorder +open scoped ENNReal + +variable {X : Type*} [MeasurableSpace X] + +theorem extend_last (n : ℕ) (h : Hist X n) (x : X) : last (n+1) (extend n h x) = x := by + simp [last, extend, IicProdIoc_def, MeasurableEquiv.piSingleton] + +instance pastKernel_markov (K : Kernel X X) [IsMarkovKernel K] (n : ℕ) : + IsMarkovKernel (pastKernel K n) := by + unfold pastKernel + infer_instance + +instance pathKernel_markov (K : Kernel X X) [IsMarkovKernel K] (n : ℕ) : + IsMarkovKernel (pathKernel K n) := by + unfold pathKernel + infer_instance + +theorem last_measurable (n : ℕ) : Measurable (last (X := X) n) := + measurable_pi_apply _ + +variable (K : Kernel X X) [IsSFiniteKernel K] + +theorem lintegral_endpoint (n : ℕ) (h₀ : Hist X 0) {F : X → ℝ≥0∞} (hF : Measurable F) : + ∫⁻ h, F (last n h) ∂pathKernel K n h₀ = ∫⁻ x, F x ∂(K^n) (last 0 h₀) := by + induction n generalizing F with + | zero => + change (∫⁻ h, F (last 0 h) ∂Kernel.id h₀) = ∫⁻ x, F x ∂Kernel.id (last 0 h₀) + simp only [Kernel.id_apply] + rw [lintegral_dirac' _ (by exact hF.comp (measurable_pi_apply _)), lintegral_dirac' _ hF] + | succ n ih => + rw [lintegral_pathKernel_succ K n h₀ (by exact hF.comp (measurable_pi_apply _))] + simp only [extend_last] + have hp : K^(n+1) = K ∘ₖ (K^n) := by + simpa only [Nat.add_comm, pow_one] using Kernel.pow_add K 1 n + rw [hp, Kernel.lintegral_comp _ _ _ hF] + exact ih (hF.lintegral_kernel (κ := K)) + +theorem pathKernel_endpoint (n : ℕ) : + (pathKernel K n).map (last n) = (K^n).comap (last 0) (last_measurable 0) := by + apply Kernel.ext_fun + intro h₀ F hF + rw [Kernel.lintegral_map _ (last_measurable n) _ hF, Kernel.comap_apply] + exact lintegral_endpoint K n h₀ hF + +theorem pathMeasure_endpoint (n : ℕ) (h₀ : Hist X 0) : + (pathKernel K n h₀).map (last n) = (K^n) (last 0 h₀) := by + rw [← Kernel.map_apply _ (last_measurable n), pathKernel_endpoint, Kernel.comap_apply] + +theorem pathMeasure_coordinate [IsMarkovKernel K] (n k : ℕ) (hk : k ≤ n) (h₀ : Hist X 0) : + (pathKernel K n h₀).map (fun h => h ⟨k, by simpa using hk⟩) = + (K^k) (last 0 h₀) := by + have hrestriction : (pathKernel K n h₀).map (frestrictLe₂ (π := fun _ => X) hk) = pathKernel K k h₀ := + Kernel.partialTraj_map_frestrictLe₂_apply (X := fun _ => X) (κ := pastKernel K) h₀ hk + calc + _ = ((pathKernel K n h₀).map (frestrictLe₂ (π := fun _ => X) hk)).map (last k) := by + rw [Measure.map_map (last_measurable k) (measurable_frestrictLe₂ hk)] + rfl + _ = _ := by rw [hrestriction, pathMeasure_endpoint] + +end NumberTheoryLean.FiniteHistoryTransport + + + +namespace NumberTheoryLean.FiniteHistoryOccurrence +open Set MeasureTheory ProbabilityTheory FiniteHistoryTransport +variable {X : Type*} [MeasurableSpace X] + +def atIndex (N : ℕ) (h : Hist X N) (j : Fin (N+1)) : X := + h ⟨j.1,Finset.mem_Iic.mpr (Nat.le_of_lt_succ j.isLt)⟩ + +noncomputable def arrivalOccurrence (E : Set X) (N : ℕ) : Set (Hist X N) := + ⋃ j : Fin N,{h | atIndex N h j.succ ∈ E} + +theorem arrivalOccurrence_measurable {E : Set X} (hE : MeasurableSet E) (N : ℕ) : + MeasurableSet (arrivalOccurrence E N) := by + apply MeasurableSet.iUnion + intro j + exact (measurable_pi_apply _) hE + +theorem atIndex_law (K : Kernel X X) [IsMarkovKernel K] (N : ℕ) (h₀ : Hist X 0) (j : Fin (N+1)) : + (pathKernel K N h₀).map (fun h => atIndex N h j)=(K^j.1) (last 0 h₀) := + pathMeasure_coordinate K N j.1 (Nat.le_of_lt_succ j.isLt) h₀ + +theorem probability_integrable (K : Kernel X X) [IsMarkovKernel K] + {E : Set X} (hE : MeasurableSet E) (N : ℕ) (h₀ : Hist X 0) (j : Fin (N+1)) : + Integrable (fun h => (K (atIndex N h j) E).toReal) (pathKernel K N h₀) := by + have hc : Measurable (fun h : Hist X N => atIndex N h j) := measurable_pi_apply _ + have hm := (K.measurable_coe hE).ennreal_toReal.comp hc + apply (integrable_const (1:ℝ)).mono' hm.aestronglyMeasurable + exact Filter.Eventually.of_forall (fun h => by + change ‖(K (atIndex N h j) E).toReal‖ ≤ 1 + have hb : (K (atIndex N h j) E).toReal ≤ 1 := measureReal_le_one + simpa only [Real.norm_eq_abs,abs_of_nonneg ENNReal.toReal_nonneg] using hb) + +theorem next_probability_identity (K : Kernel X X) [IsMarkovKernel K] + {E : Set X} (hE : MeasurableSet E) (N : ℕ) (h₀ : Hist X 0) (j : Fin N) : + (pathKernel K N h₀).real {h | atIndex N h j.succ ∈ E}= + ∫ h,(K (atIndex N h j.castSucc) E).toReal ∂pathKernel K N h₀ := by + have hn := atIndex_law K N h₀ j.succ + have hp := atIndex_law K N h₀ j.castSucc + simp only [Fin.val_succ] at hn + simp only [Fin.val_castSucc] at hp + have hcn : Measurable (fun h : Hist X N => atIndex N h j.succ) := measurable_pi_apply _ + have hcp : Measurable (fun h : Hist X N => atIndex N h j.castSucc) := measurable_pi_apply _ + have he : (K^(j.1+1)) (last 0 h₀) E = ∫⁻ x,K x E ∂(K^j.1) (last 0 h₀) := by + have hh := Kernel.pow_add_apply_eq_lintegral K j.1 1 (last 0 h₀) hE + simpa only [pow_one] using hh + calc + _ = ((K^(j.1+1)) (last 0 h₀) E).toReal := by + rw [← hn,Measure.map_apply hcn hE] + rfl + _ = (∫⁻ x,K x E ∂(K^j.1) (last 0 h₀)).toReal := congrArg ENNReal.toReal he + _ = ∫ x,(K x E).toReal ∂(K^j.1) (last 0 h₀) := + (integral_toReal (K.measurable_coe hE).aemeasurable + (Filter.Eventually.of_forall (fun x => measure_lt_top (K x) E))).symm + _ = _ := by + rw [← hp,integral_map_of_stronglyMeasurable hcp + (K.measurable_coe hE).ennreal_toReal.stronglyMeasurable] + +theorem occurrence_le_integrated_hazards (K : Kernel X X) [IsMarkovKernel K] + {E : Set X} (hE : MeasurableSet E) (N : ℕ) (h₀ : Hist X 0) : + (pathKernel K N h₀).real (arrivalOccurrence E N) ≤ + ∫ h,∑ j : Fin N,(K (atIndex N h j.castSucc) E).toReal ∂pathKernel K N h₀ := by + apply (measureReal_iUnion_fintype_le (fun j : Fin N => {h | atIndex N h j.succ ∈ E})).trans_eq + simp_rw [next_probability_identity K hE N h₀] + symm + apply integral_finsetSum + intro j _ + exact probability_integrable K hE N h₀ j.castSucc +end NumberTheoryLean.FiniteHistoryOccurrence + + + +namespace NumberTheoryLean.FiniteHistoryTransport + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal + +variable {X : Type*} [MeasurableSpace X] + +theorem ae_pathKernel_succ (K : Kernel X X) [IsSFiniteKernel K] + (n : ℕ) (h₀ : Hist X 0) {P : Hist X (n+1) → Prop} + (hP : MeasurableSet {h | P h}) + (hstep : ∀ᵐ h ∂pathKernel K n h₀, ∀ᵐ x ∂K (last n h), P (extend n h x)) : + ∀ᵐ h ∂pathKernel K (n+1) h₀, P h := by + classical + rw [ae_iff] + change pathKernel K (n+1) h₀ ({h | P h}ᶜ) = 0 + rw [← lintegral_indicator_one hP.compl, + lintegral_pathKernel_succ K n h₀ (by exact measurable_const.indicator hP.compl)] + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [hstep] with h hh + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [hh] with x hx + simp [hx] + +noncomputable def pathSum (F : X → ℝ) (n : ℕ) (h : Hist X n) : ℝ := + ∑ j : Fin n, F (h ⟨j,by exact Finset.mem_Iic.mpr j.isLt.le⟩) + +theorem pathSum_measurable {F : X → ℝ} (hF : Measurable F) (n : ℕ) : + Measurable (pathSum F n) := by + unfold pathSum + fun_prop + +theorem extend_previous (n : ℕ) (h : Hist X n) (x : X) (k : Finset.Iic n) : + extend n h x ⟨k,by exact Finset.mem_Iic.mpr ((Finset.mem_Iic.mp k.2).trans n.le_succ)⟩ = h k := by + simp [extend,IicProdIoc_def,show (k:ℕ) ≤ n from Finset.mem_Iic.mp k.2] + +theorem pathSum_extend (F : X → ℝ) (n : ℕ) (h : Hist X n) (x : X) : + pathSum F (n+1) (extend n h x) = pathSum F n h + F (last n h) := by + rw [pathSum,Fin.sum_univ_castSucc] + congr 1 + · apply Finset.sum_congr rfl + intro j _ + congr 1 + exact extend_previous n h x ⟨j,by exact Finset.mem_Iic.mpr j.isLt.le⟩ + · congr 1 + exact extend_previous n h x ⟨n,by simp⟩ + +end NumberTheoryLean.FiniteHistoryTransport + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteVisitMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteVisitMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..d6da12934dfa172f0200c4e383deb00837317dd1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FiniteVisitMass.lean @@ -0,0 +1,257 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RawSuppliedPast + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.TransitionKernels + +abbrev FiniteRawHistory := Σ n : ℕ, RawHistory n + +def selectedVisitPrefix (q : Σ t : ℕ, RawReturnTrace t) : FiniteRawHistory := + ⟨q.1+1,rawPrefix (show q.1+1 ≤ q.1+2*(q.2.1+1) by omega) q.2.2⟩ + +lemma selectedVisitPrefix_measurable : Measurable selectedVisitPrefix := by + apply measurable_sigma_family + intro t + apply measurable_sigma_family + intro n + exact (measurableSigmaMk (t+1)).comp (rawPrefix_measurable (show t+1 ≤ t+2*(n+1) by omega)) + +noncomputable def rawVisitPrefix (a : ℕ) : RawEvenMarkedHitTrace a → FiniteRawHistory := + selectedVisitPrefix ∘ rawEvenFinalCycle a + +lemma rawVisitPrefix_measurable (a : ℕ) : Measurable (rawVisitPrefix a) := + selectedVisitPrefix_measurable.comp (rawEvenFinalCycle_measurable a) + +noncomputable def finiteRawLast (h : FiniteRawHistory) : CostState := rawLast h.1 h.2 + +lemma finiteRawLast_measurable : Measurable finiteRawLast := by + apply measurable_sigma_family + intro n + exact rawLast_measurable n + +lemma rawVisitPrefix_length (a : ℕ) (z : RawEvenMarkedHitTrace a) : a+1 < (rawVisitPrefix a z).1 := by + have h := rawEvenFinalCycle_anchor_gt a z + change a+1 < (rawEvenFinalCycle a z).1+1 + omega + +lemma rawVisitPrefix_last (a : ℕ) (z : RawEvenMarkedHitTrace a) : + finiteRawLast (rawVisitPrefix a z)=recordFirst (rawEvenHitRecord a z) := by + rw [rawEvenFinalCycle_record] + change finiteRawLast (selectedVisitPrefix (rawEvenFinalCycle a z))= + recordFirst (rawReturnInputSignature (rawEvenFinalCycle a z).1 (rawEvenFinalCycle a z).2) + rcases he : rawEvenFinalCycle a z with ⟨t,n,h⟩ + rfl + +noncomputable def rawVisitPrefixKernel (a : ℕ) (v H : ℝ) : Kernel (RawHistory a) FiniteRawHistory := + (rawEvenMarkedHitKernel a v H).map (rawVisitPrefix a) + +instance rawVisitPrefixKernel_isFiniteKernel (a : ℕ) (v H : ℝ) : IsFiniteKernel (rawVisitPrefixKernel a v H) := by + unfold rawVisitPrefixKernel + infer_instance + +theorem rawVisitPrefix_mass (a : ℕ) (v H : ℝ) (past : RawHistory a) : + rawVisitPrefixKernel a v H past univ=rawEvenMarkedHitKernel a v H past univ := by + rw [rawVisitPrefixKernel,Kernel.map_apply' _ (rawVisitPrefix_measurable a) _ MeasurableSet.univ,preimage_univ] + +theorem rawVisitPrefix_mass_eq_ordinaryHit (a : ℕ) (v H : ℝ) (past : RawHistory a) (s : EvenState) + (hs : rawLast a past=(Sum.inl s,0)) : + rawVisitPrefixKernel a v H past univ=ordinaryInitialHitMass s v H := by + rw [rawVisitPrefix_mass,rawEvenMarkedHit_mass a v H past s hs] + +theorem rawVisitPrefix_last_law (a : ℕ) (v H : ℝ) (past : RawHistory a) : + (rawVisitPrefixKernel a v H past).map finiteRawLast= + (rawEvenMarkedHitKernel a v H past).map (fun z => recordFirst (rawEvenHitRecord a z)) := by + rw [rawVisitPrefixKernel,Kernel.map_apply _ (rawVisitPrefix_measurable a), + Measure.map_map finiteRawLast_measurable (rawVisitPrefix_measurable a)] + congr 1 + funext z + exact rawVisitPrefix_last a z + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FirstHitKernels +open NumberTheoryLean.FinitePathGeometry + +noncomputable def finiteRawPrevious (h : FiniteRawHistory) : CostState := + h.2 ⟨h.1-1,Finset.mem_Iic.mpr (Nat.sub_le _ _)⟩ + +lemma finiteRawPrevious_measurable : Measurable finiteRawPrevious := by + apply measurable_sigma_family + intro n + change Measurable (fun h : RawHistory n => h ⟨n-1,Finset.mem_Iic.mpr (Nat.sub_le _ _)⟩) + exact measurable_pi_apply _ + +lemma finiteRawLength_measurable : Measurable (fun q : FiniteRawHistory => q.1) := by + apply measurable_sigma_family + intro n + exact measurable_const + +lemma rawVisitPrefix_previous (a : ℕ) (z : RawEvenMarkedHitTrace a) : + finiteRawPrevious (rawVisitPrefix a z)=rawEvenHitAnchor a z := by + change finiteRawPrevious (selectedVisitPrefix (rawEvenFinalCycle a z))= + selectedCycleAnchor (rawEvenFinalCycle a z) + rcases rawEvenFinalCycle a z with ⟨t,n,h⟩ + simp only [finiteRawPrevious,selectedVisitPrefix,Nat.add_sub_cancel] + rfl + +lemma rawEvenHitAnchor_cost (a : ℕ) (z : RawEvenMarkedHitTrace a) : + (rawEvenHitAnchor a z).2=(rawEvenHitRecord a z).1 := by + rw [rawEvenFinalCycle_record] + rfl + +noncomputable def finiteSuppliedPast (a : ℕ) (past : RawHistory a) : Set FiniteRawHistory := + {q | q.2 ∈ suppliedPastEvent a past q.1} + +lemma finiteSuppliedPast_measurable (a : ℕ) (past : RawHistory a) : MeasurableSet (finiteSuppliedPast a past) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + exact suppliedPastEvent_measurable a past n + +lemma selectedVisitPrefix_past (a : ℕ) (past : RawHistory a) (q : Σ t : ℕ, RawReturnTrace t) + (ha : a ≤ q.1+1) (hq : q ∈ selectedHistoryProperty (suppliedPastEvent a past)) : + selectedVisitPrefix q ∈ finiteSuppliedPast a past := by + obtain ⟨hab,hp⟩ := hq + exact ⟨ha,hp⟩ + +theorem rawVisitPrefix_ae_past (a : ℕ) (v H : ℝ) (past : RawHistory a) : + ∀ᵐ q ∂rawVisitPrefixKernel a v H past, q ∈ finiteSuppliedPast a past := by + rw [rawVisitPrefixKernel,Kernel.map_apply _ (rawVisitPrefix_measurable a)] + apply (ae_map_iff (rawVisitPrefix_measurable a).aemeasurable (finiteSuppliedPast_measurable a past)).mpr + filter_upwards [rawEvenHit_retains_suppliedPast a v H past] with z hz + exact selectedVisitPrefix_past a past (rawEvenFinalCycle a z) + (by have ha:=rawEvenFinalCycle_anchor_gt a z; omega) hz + +noncomputable def finitePrefixSourceEvent (a : ℕ) (v H : ℝ) : Set FiniteRawHistory := + {q | a+1 < q.1 ∧ finiteRawPrevious q ∈ regenerationSet ∧ + firstArrivalMark (finiteRawLast q)=true ∧ + (finiteRawLast q).2=(finiteRawPrevious q).2+cost (stateRatio (finiteRawLast q).1) ∧ + (finiteRawPrevious q).2 ∈ Icc v (v+H)} + +lemma finitePrefixSourceEvent_measurable (a : ℕ) (v H : ℝ) : MeasurableSet (finitePrefixSourceEvent a v H) := + (measurableSet_lt measurable_const finiteRawLength_measurable).inter + ((regenerationSet_measurable.preimage finiteRawPrevious_measurable).inter + (((firstArrivalMark_measurable.comp finiteRawLast_measurable) (measurableSet_singleton true)).inter + ((measurableSet_eq_fun (measurable_snd.comp finiteRawLast_measurable) + ((measurable_snd.comp finiteRawPrevious_measurable).add + (cost_measurable.comp (stateRatio_measurable.comp (measurable_fst.comp finiteRawLast_measurable))))).inter + (measurableSet_Icc.preimage (measurable_snd.comp finiteRawPrevious_measurable))))) + +theorem rawVisitPrefix_ae_source (a : ℕ) (v H : ℝ) (past : RawHistory a) : + ∀ᵐ q ∂rawVisitPrefixKernel a v H past, q ∈ finitePrefixSourceEvent a v H := by + rw [rawVisitPrefixKernel,Kernel.map_apply _ (rawVisitPrefix_measurable a)] + apply (ae_map_iff (rawVisitPrefix_measurable a).aemeasurable (finitePrefixSourceEvent_measurable a v H)).mpr + filter_upwards [rawEvenHit_anchor_regenerates a v H past,rawEvenHit_ae_physical a v H past] with z hA hP + refine ⟨rawVisitPrefix_length a z,?_,?_,?_,?_⟩ + · rw [rawVisitPrefix_previous] + exact hA + · rw [rawVisitPrefix_last] + exact hP.1.1 + · rw [rawVisitPrefix_last,rawVisitPrefix_previous,rawEvenHitAnchor_cost] + exact hP.1.2 + · rw [rawVisitPrefix_previous,rawEvenHitAnchor_cost] + exact hP.2 + +theorem rawVisitPrefix_witness_mass (a : ℕ) (v H : ℝ) (past : RawHistory a) : + rawVisitPrefixKernel a v H past (finiteSuppliedPast a past ∩ finitePrefixSourceEvent a v H)= + rawEvenMarkedHitKernel a v H past univ := by + have hm := (finiteSuppliedPast_measurable a past).inter (finitePrefixSourceEvent_measurable a v H) + have hA : ∀ᵐ q ∂rawVisitPrefixKernel a v H past, q ∈ finiteSuppliedPast a past ∩ finitePrefixSourceEvent a v H := by + filter_upwards [rawVisitPrefix_ae_past a v H past,rawVisitPrefix_ae_source a v H past] with q hp hs + exact ⟨hp,hs⟩ + rw [(ae_mem_iff_measure_eq hm.nullMeasurableSet).mp hA,rawVisitPrefix_mass] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Topology +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels + +lemma finitePrefixSourceEvent_even_witness {a : ℕ} {v H : ℝ} {q : FiniteRawHistory} + (hq : q ∈ finitePrefixSourceEvent a v H) : + ∃ tau : EvenState, 209/100 ≤ tau.1 ∧ tau.1 ≤ 213/100 ∧ + finiteRawLast q=(Sum.inl tau,(finiteRawPrevious q).2+NumberTheoryLean.FinitePathGeometry.cost tau.1) := by + let c : CycleInputSignature := ((finiteRawPrevious q).2,(q.1,(finiteRawLast q,finiteRawLast q))) + have hc : c ∈ physicalMarkedRecord := ⟨hq.2.2.1,hq.2.2.2.1⟩ + exact physicalMarkedRecord_witness hc + +noncomputable def visitHorizonEvent (a : ℕ) (v H : ℝ) (past : RawHistory a) (N : ℕ) : Set FiniteRawHistory := + (finiteSuppliedPast a past ∩ finitePrefixSourceEvent a v H) ∩ {q | q.1 ≤ N} + +lemma visitHorizonEvent_measurable (a : ℕ) (v H : ℝ) (past : RawHistory a) (N : ℕ) : + MeasurableSet (visitHorizonEvent a v H past N) := + ((finiteSuppliedPast_measurable a past).inter (finitePrefixSourceEvent_measurable a v H)).inter + (measurableSet_le finiteRawLength_measurable measurable_const) + +theorem finite_visit_horizon_mass (a : ℕ) (v H : ℝ) (past : RawHistory a) : + Tendsto (fun N : ℕ => rawVisitPrefixKernel a v H past (visitHorizonEvent a v H past N)) atTop + (𝓝 (rawEvenMarkedHitKernel a v H past univ)) := by + have hm : Monotone (visitHorizonEvent a v H past) := by + intro N M hNM q hq + exact ⟨hq.1,hq.2.trans hNM⟩ + have hu : (⋃ N : ℕ, visitHorizonEvent a v H past N)= + finiteSuppliedPast a past ∩ finitePrefixSourceEvent a v H := by + ext q + constructor + · intro hq + obtain ⟨N,hN⟩ := mem_iUnion.mp hq + exact hN.1 + · intro hq + exact mem_iUnion.mpr ⟨q.1,hq,(show q.1 ≤ q.1 from le_rfl)⟩ + have ht := tendsto_measure_iUnion_atTop (μ := rawVisitPrefixKernel a v H past) hm + rw [hu,rawVisitPrefix_witness_mass] at ht + exact ht + +theorem finite_visit_exponential (S : ℝ) : ∃ eta C eta0 B : ℝ, + 0 < eta ∧ 0 < C ∧ 0 < eta0 ∧ 0 ≤ B ∧ ∀ (a : ℕ) (past : RawHistory a) (s : EvenState), + rawLast a past=(Sum.inl s,0) → s.1 ≤ S → ∀ v H : ℝ, 0 ≤ H → + 1-rawVisitPrefixKernel a v H past (finiteSuppliedPast a past ∩ finitePrefixSourceEvent a v H) ≤ + ENNReal.ofReal (C*Real.exp (-eta*H)+B*Real.exp (-eta0*v)) := by + obtain ⟨eta,C,eta0,B,heta,hC,heta0,hB,h⟩ := rawEvenMarkedHit_exponential S + refine ⟨eta,C,eta0,B,heta,hC,heta0,hB,?_⟩ + intro a past s hs hS v H hH + rw [rawVisitPrefix_witness_mass] + exact h a past s hs hS v H hH + +theorem moving_finite_visit {eps : ℝ} (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → ∀ (a : ℕ) (past : RawHistory a) (s : EvenState), + rawLast a past=(Sum.inl s,0) → 199/100 ≤ s.1 → s.1 ≤ 23/10 → + 1-rawVisitPrefixKernel a (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) past + (finiteSuppliedPast a past ∩ finitePrefixSourceEvent a + (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10))) ≤ ENNReal.ofReal eps := by + obtain ⟨rho,hrho,hMoving⟩ := moving_raw_even_marked_hit heps + refine ⟨rho,hrho,?_⟩ + intro K hK + filter_upwards [hMoving K hK] with w hw + refine ⟨hw.1,?_⟩ + intro r hr a past s hs hs0 hs1 + rw [rawVisitPrefix_witness_mass] + exact hw.2 r hr a past s hs hs0 hs1 + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FirstVisitRatioTail.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FirstVisitRatioTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e6d78973c15d8b7d5224d93deebe52a3d2f1bb0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FirstVisitRatioTail.lean @@ -0,0 +1,55 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.EvenInverseBands + +namespace OAI + +namespace Erdos970 + + +open Filter Set MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +namespace ErdosHighRatioBandTail +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.TransitionKernels +open NumberTheoryLean.KernelDensityBridge NumberTheoryLean.CompactExponentialMoments + +theorem costKernel_highStates (s : State) (c T : ℝ) : + costKernel (s,c) (Prod.fst ⁻¹' highStates T) = stateKernel s (highStates T) := by + rw [costKernel_apply _ (measurable_fst (highStates_measurable T))] + rfl + +theorem even_state_high (s : EvenState) (T : ℝ) : + stateKernel (.inl s) (highStates T) = evenKernel s (Ici T) := by + rw [← stateKernel_even_ratio s, Measure.map_apply stateRatio_measurable measurableSet_Ici] + rfl + +theorem first_band_tail_bound : ∃ U : ℝ, 4 ≤ U ∧ + ∀ T : ℝ, U ≤ T → ∀ v h : ℝ, ∀ s : EvenState, s.1 ≤ 23/10 → + costKernel (.inl s,0) (highBand T v h) ≤ + ENNReal.ofReal (Real.exp (-2*(T-(U-1)))) := by + obtain ⟨U,hU,he,_ho⟩ := kernel_uniform_upper_tails + refine ⟨U,hU,?_⟩ + intro T hT v h s hs + have ht := he U le_rfl s (by linarith) (T-(U-1)) (by linarith) + rw [show U-1+(T-(U-1))=T by ring] at ht + calc + _ ≤ costKernel (.inl s,0) (Prod.fst ⁻¹' highStates T) := + measure_mono (fun _ hz => hz.1) + _ = evenKernel s (Ici T) := by rw [costKernel_highStates, even_state_high] + _ ≤ _ := ht + +theorem exponential_tail_tendsto (U : ℝ) : + Tendsto (fun T : ℝ => ENNReal.ofReal (Real.exp (-2*(T-(U-1))))) atTop (𝓝 0) := by + have hsub : Tendsto (fun T : ℝ => T-(U-1)) atTop atTop := by + simpa only [sub_eq_add_neg, id_eq] using + tendsto_atTop_add_const_right atTop (-(U-1)) (tendsto_id : Tendsto (fun T : ℝ => T) atTop atTop) + have hlin : Tendsto (fun T : ℝ => 2*(T-(U-1))) atTop atTop := + hsub.const_mul_atTop (by norm_num) + have he := Real.tendsto_exp_neg_atTop_nhds_zero.comp hlin + have hh := (ENNReal.continuous_ofReal.tendsto 0).comp he + simpa only [Function.comp_def, neg_mul, ENNReal.ofReal_zero] using hh + +end ErdosHighRatioBandTail + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FlagMeasurePartition.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlagMeasurePartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f6c6d1aff7dd9f5e5c57be4cb6f9f53eaabe444 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlagMeasurePartition.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.CompactTestMeasurable +import OAI.NumberTheory.Jacobsthal.Probability.SubMarkovFlagPowers + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.FlagMeasurePartition + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open PersistentFailureFlag FlaggedOccupationBound SubMarkovFlagPowers + +variable {α : Type*} [MeasurableSpace α] + +noncomputable def highPart (K : Kernel α α) {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (n : ℕ) (x : α) : Measure α := + ((((marked K hBad)^n) (x,false)).restrict failed).map Prod.fst + +theorem power_measure_partition (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (n : ℕ) (x : α) : + (K^n) x = ((goodKernel K hBad)^n) x+highPart K hBad n x := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_add_measure,highPart,lintegral_map hF measurable_fst, + ← lintegral_indicator failed_measurable] + exact finite_integral_partition K hBad hF n x + +theorem signed_power_difference (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (n : ℕ) (x : α) {F : α → ℝ} + (hF : Measurable F) (hI : Integrable F ((K^n) x)) : + ENNReal.ofReal |(∫ y,F y ∂(K^n) x)-(∫ y,F y ∂((goodKernel K hBad)^n) x)| ≤ + ∫⁻ y,selected (fun a => ENNReal.ofReal |F a|) y ∂((marked K hBad)^n) (x,false) := by + have he := power_measure_partition K hBad n x + have hl : ((goodKernel K hBad)^n) x ≤ (K^n) x := by rw [he]; exact Measure.le_add_right le_rfl + have hh : highPart K hBad n x ≤ (K^n) x := by rw [he]; exact Measure.le_add_left le_rfl + have hIl := hI.mono_measure hl + have hIh := hI.mono_measure hh + have hid : (∫ y,F y ∂(K^n) x)-(∫ y,F y ∂((goodKernel K hBad)^n) x) = ∫ y,F y ∂highPart K hBad n x := by + rw [he,integral_add_measure hIl hIh] + ring + rw [hid] + have h := enorm_integral_le_lintegral_enorm (μ:=highPart K hBad n x) F + simp only [Real.enorm_eq_ofReal_abs] at h + rw [highPart,lintegral_map (f:=fun a => ENNReal.ofReal |F a|) (ENNReal.measurable_ofReal.comp hF.abs) measurable_fst, + ← lintegral_indicator failed_measurable] at h + exact h + +theorem signed_finite_difference (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (N : ℕ) (x : α) {F : α → ℝ} + (hF : Measurable F) (hI : ∀ n ∈ range N,Integrable F ((K^n) x)) : + ENNReal.ofReal |(∑ n ∈ range N,∫ y,F y ∂(K^n) x)- + (∑ n ∈ range N,∫ y,F y ∂((goodKernel K hBad)^n) x)| ≤ + ∑ n ∈ range N,∫⁻ y,selected (fun a => ENNReal.ofReal |F a|) y ∂((marked K hBad)^n) (x,false) := by + rw [← Finset.sum_sub_distrib] + refine (ENNReal.ofReal_le_ofReal (Finset.abs_sum_le_sum_abs _ _)).trans ?_ + rw [ENNReal.ofReal_sum_of_nonneg (fun _ _ => abs_nonneg _)] + exact Finset.sum_le_sum (fun n hn => signed_power_difference K hBad n x hF (hI n hn)) + +end NumberTheoryLean.FlagMeasurePartition + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedHarmonicPaths.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedHarmonicPaths.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc3b948de6b60e20dc0ccba6e05437cea08f8fa7 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedHarmonicPaths.lean @@ -0,0 +1,124 @@ +import OAI.NumberTheory.Jacobsthal.Probability.HighPrefixKernel +import OAI.NumberTheory.Jacobsthal.Sieve.AdmittedExponentMarginal + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.FlaggedHarmonicPaths + +open Set MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures PairedCostGrouping ArrivalKernelGeometry +open AdmittedHarmonicPaths AdmittedExponentMarginal RegeneratingInverseBands + +abbrev FlagState := CostState × Bool +abbrev ExponentState := ErdosPrimeInputs.HighPrefixState.State + +noncomputable def flagUpdate (S : ℝ) (b : Bool) (y : CostState) : FlagState := + (y, if b = true ∨ S < stateRatio y.1 then true else false) + +theorem flagUpdate_joint_measurable (S : ℝ) : + Measurable (fun p : FlagState × CostState => flagUpdate S p.1.2 p.2) := by + have hb : Measurable (fun p : FlagState × CostState => p.1.2) := by fun_prop + have hr : Measurable (fun p : FlagState × CostState => stateRatio p.2.1) := stateRatio_measurable.comp (measurable_fst.comp measurable_snd) + exact measurable_snd.prodMk (Measurable.ite + ((hb (measurableSet_singleton true)).union (measurableSet_lt measurable_const hr)) + measurable_const measurable_const) + +theorem flagUpdate_measurable (S : ℝ) (b : Bool) : Measurable (flagUpdate S b) := by + have hr : Measurable (fun y : CostState => stateRatio y.1) := stateRatio_measurable.comp measurable_fst + have hb : Measurable (fun _ : CostState => b) := measurable_const + exact measurable_id.prodMk (Measurable.ite + ((hb (measurableSet_singleton true)).union (measurableSet_lt measurable_const hr)) + measurable_const measurable_const) + +noncomputable def kernel (v ell S : ℝ) : Kernel FlagState FlagState := + ((Kernel.id : Kernel FlagState FlagState).prod + ((admittedHarmonic v ell).comap (fun z : FlagState => z.1) measurable_fst)).map + (fun p => flagUpdate S p.1.2 p.2) + +instance kernel_isSFinite (v ell S : ℝ) : IsSFiniteKernel (kernel v ell S) := by + unfold kernel + infer_instance + +theorem kernel_eq_map (v ell S : ℝ) (z : FlagState) : + kernel v ell S z = (admittedHarmonic v ell z.1).map (flagUpdate S z.2) := by + apply Measure.ext_of_lintegral + intro f hf + rw [kernel, Kernel.map_apply _ (flagUpdate_joint_measurable S), + lintegral_map hf (flagUpdate_joint_measurable S)] + calc + _ = ∫⁻ y, f (flagUpdate S z.2 y) ∂admittedHarmonic v ell z.1 := + Kernel.lintegral_id_prod (f := fun p : FlagState × CostState => f (flagUpdate S p.1.2 p.2)) + (hf.comp (flagUpdate_joint_measurable S)) _ z + _ = _ := (lintegral_map hf (flagUpdate_measurable S z.2)).symm + +theorem kernel_map_state (v ell S : ℝ) (z : FlagState) : + (kernel v ell S z).map Prod.fst = admittedHarmonic v ell z.1 := by + rw [kernel_eq_map, Measure.map_map measurable_fst (flagUpdate_measurable S z.2)] + change (admittedHarmonic v ell z.1).map id = _ + exact Measure.map_id + +noncomputable def coordinates (v : ℝ) (z : FlagState) : ExponentState := + (currentExponent v z.1, gapValue v z.1, z.2) + +theorem coordinates_measurable (v : ℝ) : Measurable (coordinates v) := + ((currentExponent_measurable v).comp measurable_fst).prodMk + (((gapValue_measurable v).comp measurable_fst).prodMk measurable_snd) + +noncomputable def initial (S : ℝ) (z : CostState) : FlagState := + (z, if S < stateRatio z.1 then true else false) + +theorem gap_div_currentExponent (v : ℝ) (z : CostState) : + gapValue v z / currentExponent v z = stateRatio z.1 := by + unfold currentExponent + have hr : gapValue v z ≠ 0 := (Real.exp_pos _).ne' + field_simp + +theorem initial_coordinates (v S : ℝ) (z : CostState) : + coordinates v (initial S z) = ErdosPrimeInputs.HighPrefixState.initial S + (currentExponent v z) (gapValue v z) := by + simp only [coordinates, initial, ErdosPrimeInputs.HighPrefixState.initial, gap_div_currentExponent] + +theorem coordinates_update (v S : ℝ) (z : FlagState) (y : CostState) + (hflow : gapValue v z.1 = gapValue v y + currentExponent v y) : + coordinates v (flagUpdate S z.2 y) = + ErdosPrimeInputs.HighPrefixState.update S (coordinates v z) (currentExponent v y) := by + have hrem : gapValue v z.1 - currentExponent v y = gapValue v y := by linarith + have hratio : (gapValue v z.1 - currentExponent v y) / currentExponent v y = stateRatio y.1 := by + rw [hrem, gap_div_currentExponent] + simp only [coordinates, flagUpdate, ErdosPrimeInputs.HighPrefixState.update, hrem] + rw [gap_div_currentExponent] + +theorem kernel_map_coordinates (v ell S : ℝ) (z : FlagState) : + (kernel v ell S z).map (coordinates v) = + ((admittedHarmonic v ell z.1).map (currentExponent v)).map + (ErdosPrimeInputs.HighPrefixState.update S (coordinates v z)) := by + rw [kernel_eq_map, Measure.map_map (coordinates_measurable v) (flagUpdate_measurable S z.2), + Measure.map_map (ErdosPrimeInputs.HighPrefixKernel.update_at_measurable S (coordinates v z)) + (currentExponent_measurable v)] + apply Measure.map_congr + have hflow : ∀ᵐ y ∂admittedHarmonic v ell z.1, + gapValue v z.1 = gapValue v y + currentExponent v y := by + rw [admittedHarmonic, Kernel.restrict_apply] + exact ae_restrict_of_ae (harmonicKernel_gap_flow v z.1) + filter_upwards [hflow] with y hy + exact coordinates_update v S z y hy + +theorem kernel_map_coordinates_le (v S : ℝ) {ell : ℝ} (hell : 0 ≤ ell) (z : FlagState) : + (kernel v ell S z).map (coordinates v) ≤ + ErdosPrimeInputs.HighPrefixKernel.kernel ell S (coordinates v z) := by + rw [kernel_map_coordinates, ErdosPrimeInputs.HighPrefixKernel.kernel_eq_map] + exact Measure.map_mono (admitted_exponent_marginal_le v hell z.1) + (ErdosPrimeInputs.HighPrefixKernel.update_at_measurable S (coordinates v z)) + +end NumberTheoryLean.FlaggedHarmonicPaths + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedHarmonicTransform.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedHarmonicTransform.lean new file mode 100644 index 0000000000000000000000000000000000000000..c28a674c1b1884ef04ee90afc59a50f3d6287ed0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedHarmonicTransform.lean @@ -0,0 +1,133 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.FiniteAdmittedOccupation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.FlagWeightConjugation +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open KernelWeightTransform PersistentFailureFlag SubMarkovFlagPowers FlaggedOccupationBound + +variable {α : Type*} [MeasurableSpace α] + +def flagWeight (w : PositiveWeight α) : PositiveWeight (FlagState α) where + value z := w z.1 + measurable_value := w.measurable_value.comp measurable_fst + ne_zero z := w.ne_zero z.1 + ne_top z := w.ne_top z.1 + +theorem marked_conjugate (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (w : PositiveWeight α) : + marked (conjugate K w) hBad = conjugate (marked K hBad) (flagWeight w) := by + ext z : 1 + apply Measure.ext_of_lintegral + intro F hF + have hRow := row_update_measurable hBad z.2 + rw [marked_eq_map_sfinite,lintegral_map hF hRow, + conjugate_lintegral K w z.1 (F := fun y => F (y,z.2 || badBit Bad y)) (hF.comp hRow), + conjugate_lintegral (marked K hBad) (flagWeight w) z hF, + marked_eq_map_sfinite, + lintegral_map (f := fun b : FlagState α => flagWeight w b / flagWeight w z * F b) + (((flagWeight w).measurable_value.div measurable_const).mul hF) hRow] + rfl + +theorem marked_conjugate_power (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (w : PositiveWeight α) (n : ℕ) : + (marked (conjugate K w) hBad)^n = conjugate ((marked K hBad)^n) (flagWeight w) := by + rw [marked_conjugate] + exact conjugate_pow (marked K hBad) (flagWeight w) n + +theorem marked_conjugate_power_integral (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (w : PositiveWeight α) (n : ℕ) (z : FlagState α) + {F : FlagState α → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y,F y ∂((marked (conjugate K w) hBad)^n) z) = + (w z.1)⁻¹*(∫⁻ y,w y.1*F y ∂((marked K hBad)^n) z) := by + rw [marked_conjugate] + exact conjugate_pow_lintegral (marked K hBad) (flagWeight w) n z hF + +theorem selected_inverse_reward (K : Kernel α α) [IsSFiniteKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (w : PositiveWeight α) (n : ℕ) (z : FlagState α) + {F : α → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y,selected (fun a => F a / w a) y ∂((marked (conjugate K w) hBad)^n) z) = + (w z.1)⁻¹*(∫⁻ y,selected F y ∂((marked K hBad)^n) z) := by + rw [marked_conjugate_power_integral K hBad w n z + (F := selected (fun a => F a / w a)) (selected_measurable (hF.div w.measurable_value))] + congr 1 + apply lintegral_congr + rintro ⟨a,b⟩ + cases b with + | false => simp only [selected_false,mul_zero] + | true => + simp only [selected_true,div_eq_mul_inv] + rw [mul_left_comm,ENNReal.mul_inv_cancel (w.ne_zero a) (w.ne_top a),mul_one] + +end NumberTheoryLean.FlagWeightConjugation + +end + +section + +namespace NumberTheoryLean.FlaggedHarmonicTransform + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathMeasures AdmittedHarmonicPaths HarmonicWeightKernel +open KernelWeightTransform FlagWeightConjugation PersistentFailureFlag +open FlaggedOccupationBound ContinuousHighPartition OriginalHarmonicOccupation + +instance tiltedFlagged_sfinite (v ell S : ℝ) : IsSFiniteKernel (tiltedFlagged v ell S) := by + unfold tiltedFlagged + infer_instance + +theorem actual_marked_transform (v ell S : ℝ) : + FlaggedHarmonicPaths.kernel v ell S = conjugate (tiltedFlagged v ell S) (flagWeight harmonicWeight) := by + rw [← marked_harmonic_eq,admitted_weight_transform,marked_conjugate] + rfl + +theorem scaled_high_integral (v ell S : ℝ) (s : State) (b : Bool) (n : ℕ) + {F : CostState → ℝ≥0∞} (hF : Measurable F) : + ENNReal.ofReal ((Real.exp v)^2/InvariantInverseWeights.stateWeight s)* + (∫⁻ y,selected F y ∂((FlaggedHarmonicPaths.kernel v ell S)^n) ((s,0),b)) = + ∫⁻ y,selected (fun z => gapSquaredWeight v z*F z) y ∂((tiltedFlagged v ell S)^n) ((s,0),b) := by + rw [actual_marked_transform,conjugate_pow,conjugate_lintegral _ (flagWeight harmonicWeight) _ (selected_measurable hF), + ← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + rintro ⟨z,b'⟩ + cases b' with + | false => simp only [selected_false,mul_zero] + | true => + simp only [selected_true] + change ENNReal.ofReal ((Real.exp v)^2/InvariantInverseWeights.stateWeight s)* + ((harmonicWeight z/harmonicWeight (s,0))*F z) = gapSquaredWeight v z*F z + rw [← mul_assoc,scaled_ratio] + +theorem high_inverse_compact_le (v ell S : ℝ) (s : State) + {F : CostState → ℝ≥0∞} (hF : Measurable F) {D : ℝ≥0∞} (hD : D ≠ ∞) {K : ℝ} + (hbound : ∀ z,F z ≤ D) (hsupport : ∀ z,K < RegeneratingInverseBands.gapValue v z → F z=0) : + (∑' n : ℕ,∫⁻ y,selected (fun z => gapSquaredWeight v z*F z) y + ∂((tiltedFlagged v ell S)^n) (FlaggedHarmonicPaths.initial S (s,0))) ≤ + ENNReal.ofReal ((Real.exp v)^2/InvariantInverseWeights.stateWeight s)*D* + AdmittedHighRemoval.lowHighMass v ell S (s,0) K := by + have he : (∑' n : ℕ,∫⁻ y,selected (fun z => gapSquaredWeight v z*F z) y + ∂((tiltedFlagged v ell S)^n) (FlaggedHarmonicPaths.initial S (s,0))) = + ENNReal.ofReal ((Real.exp v)^2/InvariantInverseWeights.stateWeight s)* + (∑' n : ℕ,∫⁻ y,selected F y ∂((FlaggedHarmonicPaths.kernel v ell S)^n) + (FlaggedHarmonicPaths.initial S (s,0))) := by + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro n + exact (scaled_high_integral v ell S s (if S < stateRatio s then true else false) n hF).symm + rw [he,mul_assoc] + exact mul_le_mul_of_nonneg_left (harmonic_high_compact_bound v ell S (s,0) hD hbound hsupport) zero_le + +end NumberTheoryLean.FlaggedHarmonicTransform + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedSourceStart.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedSourceStart.lean new file mode 100644 index 0000000000000000000000000000000000000000..d0e78ad5f6635fba111bf449f4aedf4558fa9591 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FlaggedSourceStart.lean @@ -0,0 +1,516 @@ +import OAI.NumberTheory.Jacobsthal.Probability.ActualCouplingError + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.PersistentFailureFlag + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open ActualCouplingFinite + +variable {α : Type*} [MeasurableSpace α] + +abbrev FlagState (α : Type*) := α × Bool + +noncomputable def badBit (Bad : α → Prop) (x : α) : Bool := by + classical + exact if Bad x then true else false + +theorem badBit_measurable {Bad : α → Prop} (hBad : MeasurableSet {x | Bad x}) : Measurable (badBit Bad) := by + classical + exact Measurable.ite hBad measurable_const measurable_const + +noncomputable def update (Bad : α → Prop) (z : FlagState α × α) : FlagState α := + (z.2,z.1.2 || badBit Bad z.2) + +theorem update_measurable {Bad : α → Prop} (hBad : MeasurableSet {x | Bad x}) : Measurable (update Bad) := by + have hor : Measurable (fun p : Bool × Bool => p.1 || p.2) := measurable_of_countable _ + exact measurable_snd.prodMk (hor.comp ((measurable_snd.comp measurable_fst).prodMk + ((badBit_measurable hBad).comp measurable_snd))) + +noncomputable def marked (K : Kernel α α) {Bad : α → Prop} (_hBad : MeasurableSet {x | Bad x}) : + Kernel (FlagState α) (FlagState α) := + (Kernel.id ×ₖ (K.comap Prod.fst measurable_fst)).map (update Bad) + +instance marked_isMarkov (K : Kernel α α) [IsMarkovKernel K] + {Bad : α → Prop} (hBad : MeasurableSet {x | Bad x}) : IsMarkovKernel (marked K hBad) := by + unfold marked + exact Kernel.IsMarkovKernel.map _ (update_measurable hBad) + +theorem marked_apply (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (z : FlagState α) {B : Set (FlagState α)} (hB : MeasurableSet B) : + marked K hBad z B = K z.1 {y | (y,z.2 || badBit Bad y) ∈ B} := by + rw [marked,Kernel.map_apply' _ (update_measurable hBad) _ hB, + Kernel.prod_apply' _ _ _ ((update_measurable hBad) hB),Kernel.id_apply] + rw [lintegral_dirac'] + · rfl + · exact measurable_measure_prodMk_left ((update_measurable hBad) hB) + +theorem row_update_measurable {Bad : α → Prop} (hBad : MeasurableSet {x | Bad x}) (b : Bool) : + Measurable (fun y : α => (y,b || badBit Bad y)) := by + have hor : Measurable (fun p : Bool × Bool => p.1 || p.2) := measurable_of_countable _ + exact measurable_id.prodMk (hor.comp (measurable_const.prodMk (badBit_measurable hBad))) + +theorem marked_eq_map (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (z : FlagState α) : + marked K hBad z = (K z.1).map (fun y => (y,z.2 || badBit Bad y)) := by + apply Measure.ext + intro B hB + rw [marked_apply K hBad z hB,Measure.map_apply (row_update_measurable hBad z.2) hB] + rfl + +theorem marked_map (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (z : FlagState α) : (marked K hBad z).map Prod.fst = K z.1 := by + rw [marked_eq_map K hBad z,Measure.map_map (f:=fun y => (y,z.2 || badBit Bad y)) + (g:=Prod.fst) measurable_fst (row_update_measurable hBad z.2)] + exact Measure.map_id + +def failed : Set (FlagState α) := {z | z.2 = true} + +theorem failed_measurable : MeasurableSet (failed (α:=α)) := + measurable_snd (measurableSet_singleton true) + +theorem marked_failed_true (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (x : α) : marked K hBad (x,true) failed = 1 := by + rw [marked_apply K hBad (x,true) failed_measurable] + simp [failed] + +theorem marked_failed_false (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (x : α) : marked K hBad (x,false) failed = K x {y | Bad y} := by + classical + rw [marked_apply K hBad (x,false) failed_measurable] + congr 1 + ext y + simp [failed,badBit] + +instance marked_pow_markov (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (n : ℕ) : IsMarkovKernel ((marked K hBad)^n) := by + induction n with + | zero => change IsMarkovKernel (Kernel.id : Kernel (FlagState α) (FlagState α)); infer_instance + | succ n ih => + let := ih + have hp : (marked K hBad)^(n+1) = (marked K hBad) ∘ₖ ((marked K hBad)^n) := pow_succ' _ _ + rw [hp] + infer_instance + +theorem marked_power_map (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (n : ℕ) (z : FlagState α) : + (((marked K hBad)^n) z).map Prod.fst = (K^n) z.1 := + map_power_of_step (marked K hBad) K measurable_fst (marked_map K hBad) n z + +noncomputable def law (K : Kernel α α) {Bad : α → Prop} (hBad : MeasurableSet {x | Bad x}) + (x : α) (n : ℕ) : Measure (FlagState α) := ((marked K hBad)^n) (x,false) + +instance law_probability (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (x : α) (n : ℕ) : IsProbabilityMeasure (law K hBad x n) := by + unfold law + infer_instance + +end NumberTheoryLean.PersistentFailureFlag + + + +namespace NumberTheoryLean.FailureFlagBounds + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open PersistentFailureFlag + +variable {α : Type*} [MeasurableSpace α] + +def surviving (Good : α → Prop) (z : FlagState α) : Prop := z.2 = false → Good z.1 + +theorem surviving_measurable {Good : α → Prop} (hGood : MeasurableSet {x | Good x}) : + MeasurableSet {z | surviving Good z} := + (measurable_snd (measurableSet_singleton false)).imp (measurable_fst hGood) + +theorem surviving_step (K : Kernel α α) [IsMarkovKernel K] {Bad P Q : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (hQ : MeasurableSet {x | Q x}) + (hstep : ∀ x,P x → ∀ᵐ y ∂K x, ¬Bad y → Q y) (z : FlagState α) (hz : surviving P z) : + ∀ᵐ y ∂marked K hBad z, surviving Q y := by + classical + rw [marked_eq_map K hBad z] + apply (ae_map_iff (row_update_measurable hBad z.2).aemeasurable (surviving_measurable hQ)).mpr + rcases z with ⟨x,b⟩ + cases b with + | false => + filter_upwards [hstep x (hz rfl)] with y hy + intro hf + apply hy + simpa [badBit] using hf + | true => + exact Eventually.of_forall (fun y => by + intro hf + have hf' : (true || badBit Bad y) = false := hf + simp at hf') + +theorem law_survives (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (Good : ℕ → α → Prop) + (hGood : ∀ n,MeasurableSet {x | Good n x}) + (hstep : ∀ n x,Good n x → ∀ᵐ y ∂K x, ¬Bad y → Good (n+1) y) + (x : α) (hx : Good 0 x) (n : ℕ) : + ∀ᵐ z ∂law K hBad x n, surviving (Good n) z := by + induction n with + | zero => + change ∀ᵐ z ∂Measure.dirac (x,false), surviving (Good 0) z + exact (ae_dirac_iff (surviving_measurable (hGood 0))).mpr (fun _ => hx) + | succ n ih => + have hp : (marked K hBad)^(n+1) = (marked K hBad) ∘ₖ ((marked K hBad)^n) := pow_succ' _ _ + change ∀ᵐ z ∂((marked K hBad)^(n+1)) (x,false), surviving (Good (n+1)) z + rw [hp] + apply Kernel.ae_comp_of_ae_ae (surviving_measurable (hGood (n+1))) + filter_upwards [ih] with z hz + exact surviving_step K hBad (hGood (n+1)) (hstep n) z hz + +theorem marked_failure_row_bound (K : Kernel α α) [IsMarkovKernel K] {Bad Good : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (η : ℝ≥0∞) + (hrow : ∀ x,Good x → K x {y | Bad y} ≤ η) (z : FlagState α) (hz : surviving Good z) : + marked K hBad z failed ≤ failed.indicator (fun _ => (1:ℝ≥0∞)) z+η := by + classical + rcases z with ⟨x,b⟩ + cases b with + | false => + rw [marked_failed_false,indicator_of_notMem (show (x,false) ∉ (failed:Set (FlagState α)) by change ¬(false=true); decide),zero_add] + exact hrow x (hz rfl) + | true => + rw [marked_failed_true,indicator_of_mem (show (x,true) ∈ (failed:Set (FlagState α)) from rfl)] + exact le_add_of_nonneg_right zero_le + +theorem law_failure_step (K : Kernel α α) [IsMarkovKernel K] {Bad Good : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (x : α) (n : ℕ) (η : ℝ≥0∞) + (hgood : ∀ᵐ z ∂law K hBad x n, surviving Good z) + (hrow : ∀ y,Good y → K y {z | Bad z} ≤ η) : + law K hBad x (n+1) failed ≤ law K hBad x n failed+η := by + have hp : (marked K hBad)^(n+1) = (marked K hBad) ∘ₖ ((marked K hBad)^n) := pow_succ' _ _ + calc + _ = ∫⁻ z,marked K hBad z failed ∂law K hBad x n := by + change ((marked K hBad)^(n+1)) (x,false) failed = _ + rw [hp,Kernel.comp_apply' _ _ _ failed_measurable] + rfl + _ ≤ ∫⁻ z,(failed.indicator (fun _ => (1:ℝ≥0∞)) z+η) ∂law K hBad x n := by + apply lintegral_mono_ae + filter_upwards [hgood] with z hz + exact marked_failure_row_bound K hBad η hrow z hz + _ = _ := by + rw [lintegral_add_left (measurable_const.indicator failed_measurable), + lintegral_indicator failed_measurable,setLIntegral_const,one_mul,lintegral_const,measure_univ,mul_one] + +theorem failure_probability_le (K : Kernel α α) [IsMarkovKernel K] {Bad : α → Prop} + (hBad : MeasurableSet {x | Bad x}) (Good : ℕ → α → Prop) + (hGood : ∀ n,MeasurableSet {x | Good n x}) + (hstep : ∀ n x,Good n x → ∀ᵐ y ∂K x, ¬Bad y → Good (n+1) y) + (x : α) (hx : Good 0 x) (η : ℝ≥0∞) (N : ℕ) + (hrow : ∀ n < N, ∀ y,Good n y → K y {z | Bad z} ≤ η) + (n : ℕ) (hn : n ≤ N) : law K hBad x n failed ≤ (n:ℝ≥0∞)*η := by + classical + induction n with + | zero => + rw [Nat.cast_zero,zero_mul] + change Measure.dirac (x,false) failed ≤ 0 + rw [Measure.dirac_apply' _ failed_measurable] + change (if (x,false) ∈ (failed:Set (FlagState α)) then 1 else 0) ≤ 0 + simp [failed] + | succ n ih => + calc + _ ≤ law K hBad x n failed+η := law_failure_step K hBad x n η + (law_survives K hBad Good hGood hstep x hx n) (hrow n (by omega)) + _ ≤ (n:ℝ≥0∞)*η+η := add_le_add (ih (by omega)) le_rfl + _ = _ := by rw [Nat.cast_add,Nat.cast_one,add_mul,one_mul] + +end NumberTheoryLean.FailureFlagBounds + + + +namespace NumberTheoryLean.FullHistoryFailureFlag + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FiniteHistoryTransport PersistentFailureFlag + +variable {X : Type*} [MeasurableSpace X] + +def noResetPath (n : ℕ) (h : Hist (FlagState X) n) : Prop := + ∀ j : Finset.Iic n, (last n h).2 = false → (h j).2 = false + +theorem noResetPath_measurable (n : ℕ) : MeasurableSet {h : Hist (FlagState X) n | noResetPath n h} := by + simp only [noResetPath,Set.ofPred_forall] + apply MeasurableSet.iInter + intro j + exact ((measurable_snd.comp (last_measurable n)) (measurableSet_singleton false)).imp + ((measurable_snd.comp (measurable_pi_apply j)) (measurableSet_singleton false)) + +theorem noResetPath_extend (n : ℕ) (h : Hist (FlagState X) n) (y : FlagState X) + (hh : noResetPath n h) (hy : y.2 = false → (last n h).2 = false) : + noResetPath (n+1) (extend n h y) := by + intro ⟨j,hj⟩ hflag + rw [extend_last] at hflag + have hj' := Finset.mem_Iic.mp hj + by_cases hle : j ≤ n + · rw [extend_previous n h y ⟨j,Finset.mem_Iic.mpr hle⟩] + exact hh _ (hy hflag) + · have heq : j = n+1 := by omega + subst j + change (last (n+1) (FiniteHistoryTransport.extend n h y)).2 = false + rw [extend_last] + exact hflag + +theorem marked_no_reset (K : Kernel X X) [IsMarkovKernel K] {Bad : X → Prop} + (hBad : MeasurableSet {x | Bad x}) (z : FlagState X) : + ∀ᵐ y ∂marked K hBad z, y.2 = false → z.2 = false := by + have hP : MeasurableSet {y : FlagState X | y.2 = false → z.2 = false} := + (measurable_snd (measurableSet_singleton false)).imp (by by_cases hz : z.2 = false <;> simp [hz]) + rw [marked_eq_map K hBad z] + apply (ae_map_iff (row_update_measurable hBad z.2).aemeasurable hP).mpr + apply Filter.Eventually.of_forall + intro y + cases z.2 <;> simp + +theorem marked_history_no_reset (K : Kernel X X) [IsMarkovKernel K] {Bad : X → Prop} + (hBad : MeasurableSet {x | Bad x}) (x : X) (N : ℕ) : + ∀ᵐ h ∂pathKernel (marked K hBad) N (fun _ => (x,false)), noResetPath N h := by + induction N with + | zero => + change ∀ᵐ h ∂Measure.dirac (fun _ => (x,false)), noResetPath 0 h + exact (ae_dirac_iff (noResetPath_measurable 0)).mpr (fun _ _ => rfl) + | succ N ih => + apply ae_pathKernel_succ _ N _ (noResetPath_measurable (N+1)) + filter_upwards [ih] with h hh + filter_upwards [marked_no_reset K hBad (last N h)] with y hy + exact noResetPath_extend N h y hh hy + +end NumberTheoryLean.FullHistoryFailureFlag + + + +namespace NumberTheoryLean.ActualFlagInvariant + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualCouplingSupport ActualCouplingUpdates ActualCouplingFinite +open PersistentFailureFlag FailureFlagBounds RegeneratingInverseBands ArrivalKernelGeometry + +variable {w ell S : ℝ} {start : Node} + +def mismatch (mesh : ℝ) (q : JointState w ell S start) : Prop := + primeLabel w ell S mesh start q.1 ≠ continuousLabel S mesh q.2 + +theorem mismatch_measurable (mesh : ℝ) : MeasurableSet {q : JointState w ell S start | mismatch mesh q} := by + let D : Set (MeshRatioLabels.Label S mesh × MeshRatioLabels.Label S mesh) := {p | p.1 ≠ p.2} + have hD : MeasurableSet D := (Set.to_countable D).measurableSet + exact (((primeLabel_measurable w ell S mesh start).comp measurable_fst).prodMk + ((continuousLabel_measurable S mesh).comp measurable_snd)) hD + +def liveGood (v mesh : ℝ) (n : ℕ) (h : History w ell S start) (z : CostState) : Prop := + stateRatio z.1 ≤ S ∧ h.node.side = stateSide z.1 ∧ |h.node.ratio-stateRatio z.1| ≤ mesh ∧ + |Real.log h.node.gap-Real.log (gapValue v z)| ≤ 4*(n:ℝ)*mesh + +def GoodAt (v mesh : ℝ) (n : ℕ) : JointState w ell S start → Prop + | (none,.inr _) => True + | (some h,.inl z) => liveGood v mesh n h z + | _ => False + +theorem liveGood_measurable (v mesh : ℝ) (n : ℕ) (h : History w ell S start) : + MeasurableSet {z | liveGood v mesh n h z} := by + have hside : MeasurableSet {z : CostState | h.node.side = stateSide z.1} := by + have heq : {z : CostState | h.node.side = stateSide z.1} = {z : CostState | stateSide z.1 = h.node.side} := by + ext z + exact eq_comm + rw [heq] + exact measurable_fst (side_set_measurable h.node.side) + exact (measurableSet_le (stateRatio_measurable.comp measurable_fst) measurable_const).inter + (hside.inter ((measurableSet_le + (measurable_const.sub (stateRatio_measurable.comp measurable_fst)).abs measurable_const).inter + (measurableSet_le (measurable_const.sub (Real.measurable_log.comp (gapValue_measurable v))).abs measurable_const))) + +theorem GoodAt_measurable (v mesh : ℝ) (n : ℕ) : + MeasurableSet {q : JointState w ell S start | GoodAt v mesh n q} := by + apply Measurable.setOf + apply measurable_from_prod_countable_right + intro p + cases p with + | none => exact measurable_const.sumElim measurable_const + | some h => exact (measurableSet_setOfPred.mp (liveGood_measurable v mesh n h)).sumElim measurable_const + +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) +variable (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem joint_dead_ae (v mesh : ℝ) : + ∀ᵐ q ∂jointKernel hw hell hS0 hS hr hs hsS v mesh (none,CemeteryKernel.dead), + q = (none,CemeteryKernel.dead) := by + have hL : ∀ᵐ p ∂(jointKernel hw hell hS0 hS hr hs hsS v mesh (none,CemeteryKernel.dead)).map Prod.fst, p = none := by + rw [jointKernel_left hw hell hS0 hS hr hs hsS,chain_none] + exact (ae_dirac_iff (measurableSet_singleton _)).mpr rfl + have hdead : MeasurableSet {y : CemeteryKernel.Space CostState | y = CemeteryKernel.dead} := by + apply measurableSet_sum_iff.mpr + constructor + · have hp : (Sum.inl : CostState → CemeteryKernel.Space CostState) ⁻¹' {y | y = CemeteryKernel.dead} = ∅ := by + ext x + change ((Sum.inl x : CemeteryKernel.Space CostState) = Sum.inr ()) ↔ False + simp + rw [hp] + exact MeasurableSet.empty + · simp [CemeteryKernel.dead] + have hR : ∀ᵐ y ∂(jointKernel hw hell hS0 hS hr hs hsS v mesh (none,CemeteryKernel.dead)).map Prod.snd, + y = CemeteryKernel.dead := by + rw [jointKernel_right hw hell hS0 hS hr hs hsS] + change ∀ᵐ y ∂Measure.dirac (CemeteryKernel.dead : CemeteryKernel.Space CostState), y = CemeteryKernel.dead + exact (ae_dirac_iff hdead).mpr rfl + have hl := (ae_map_iff measurable_fst.aemeasurable (measurableSet_singleton _)).mp hL + have hr' := (ae_map_iff measurable_snd.aemeasurable hdead).mp hR + filter_upwards [hl,hr'] with q hq hq' + exact Prod.ext hq hq' + +theorem actual_good_step (v : ℝ) {mesh : ℝ} (hm : 0 < mesh) (n : ℕ) + (q : JointState w ell S start) (hq : GoodAt v mesh n q) : + ∀ᵐ y ∂jointKernel hw hell hS0 hS hr hs hsS v mesh q, + ¬mismatch mesh y → GoodAt v mesh (n+1) y := by + rcases q with ⟨p,z⟩ + cases p with + | none => + cases z with + | inl z => exact False.elim hq + | inr u => + cases u + filter_upwards [joint_dead_ae hw hell hS0 hS hr hs hsS v mesh] with y hy + intro _ + rw [hy] + trivial + | some h => + cases z with + | inr u => exact False.elim hq + | inl z => + filter_upwards [joint_follows hw hell hS0 hS hr hs hsS v mesh h z, + joint_matching_control hw hell hS0 hS hr hs hsS v hm (some h) (.inl z), + joint_continuous_supported hw hell hS0 hS hr hs hsS v mesh (some h) (.inl z)] with y hy hmatch hSup + intro hnot + have heq : primeLabel w ell S mesh start y.1 = continuousLabel S mesh y.2 := not_ne_iff.mp hnot + have hmout := hmatch heq + rcases y with ⟨p,y⟩ + cases p with + | none => + cases y with + | inl y => exact False.elim hmout + | inr u => trivial + | some k => + cases y with + | inr u => exact False.elim hmout + | inl y => + have hup := matched_live_update hell hr hs h k z y hy.1 hy.2 hq.2.1 hq.2.2.2 + (show |k.node.ratio-stateRatio y.1| ≤ mesh from hmout.le) + refine ⟨hSup,hup.1,hmout.le,?_⟩ + have he : 4*(n:ℝ)*mesh+4*mesh = 4*((n+1:ℕ):ℝ)*mesh := by push_cast; ring + exact hup.2.trans_eq he + +noncomputable def flaggedKernel (v mesh : ℝ) : + Kernel (FlagState (JointState w ell S start)) (FlagState (JointState w ell S start)) := + marked (jointKernel hw hell hS0 hS hr hs hsS v mesh) (mismatch_measurable mesh) + +instance flaggedKernel_markov (v mesh : ℝ) : + IsMarkovKernel (flaggedKernel hw hell hS0 hS hr hs hsS v mesh) := by + unfold flaggedKernel + infer_instance + +theorem actual_flagged_invariant (v : ℝ) {mesh : ℝ} (hm : 0 < mesh) + (q : JointState w ell S start) (hq : GoodAt v mesh 0 q) (n : ℕ) : + ∀ᵐ y ∂law (jointKernel hw hell hS0 hS hr hs hsS v mesh) (mismatch_measurable mesh) q n, + y.2 = false → GoodAt v mesh n y.1 := + law_survives _ (mismatch_measurable mesh) (GoodAt v mesh) (GoodAt_measurable v mesh) + (actual_good_step hw hell hS0 hS hr hs hsS v hm) q hq n + +end NumberTheoryLean.ActualFlagInvariant + + + +namespace NumberTheoryLean.FlaggedSourceStart + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain +open ActualProcessCoupling ActualCouplingFinite ActualFlagInvariant PersistentFailureFlag +open RegeneratingInverseBands ContinuousKilledBins + +def typedState : (i : Side) → (s : ℝ) → Valid i s → State + | .even,s,hs => .inl ⟨s,hs⟩ + | .odd,s,hs => .inr ⟨s,hs⟩ + +theorem typedState_side (i : Side) (s : ℝ) (hs : Valid i s) : stateSide (typedState i s hs) = i := by + cases i <;> rfl + +theorem typedState_ratio (i : Side) (s : ℝ) (hs : Valid i s) : stateRatio (typedState i s hs) = s := by + cases i <;> rfl + +variable {w ell S : ℝ} {start : Node} + +def sourceCostState (hs : Valid start.side start.ratio) : CostState := + (typedState start.side start.ratio hs,0) + +def sourceJoint (w ell S : ℝ) (start : Node) (hs : Valid start.side start.ratio) : JointState w ell S start := + (some History.empty,.inl (sourceCostState hs)) + +theorem source_gap (hr : 0 < start.gap) (hs : Valid start.side start.ratio) : + gapValue (Real.log start.gap) (sourceCostState hs) = start.gap := by + simp [gapValue,sourceCostState,Real.exp_log hr] + +theorem source_good {mesh : ℝ} (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) (hm : 0 ≤ mesh) : + GoodAt (Real.log start.gap) mesh 0 (sourceJoint w ell S start hs) := by + change liveGood (Real.log start.gap) mesh 0 History.empty (sourceCostState hs) + refine ⟨?_,?_,?_,?_⟩ + · simpa only [sourceCostState,typedState_ratio] using hsS + · change start.side = stateSide (typedState start.side start.ratio hs) + exact (typedState_side _ _ _).symm + · change |start.ratio-stateRatio (typedState start.side start.ratio hs)| ≤ mesh + rw [typedState_ratio,sub_self,abs_zero] + exact hm + · rw [Nat.cast_zero,mul_zero,zero_mul] + change |Real.log start.gap-Real.log (gapValue (Real.log start.gap) (sourceCostState hs))| ≤ 0 + simp [gapValue,sourceCostState] + +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) (hS : S ≤ (Real.log w)^3) +variable (hr : 0 < start.gap) (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +noncomputable def sourceLaw (mesh : ℝ) (n : ℕ) : Measure (FlagState (JointState w ell S start)) := + law (jointKernel hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh) (mismatch_measurable mesh) + (sourceJoint w ell S start hs) n + +instance sourceLaw_probability (mesh : ℝ) (n : ℕ) : + IsProbabilityMeasure (sourceLaw hw hell hS0 hS hr hs hsS mesh n) := by + unfold sourceLaw + infer_instance + +theorem sourceLaw_joint (mesh : ℝ) (n : ℕ) : + (sourceLaw hw hell hS0 hS hr hs hsS mesh n).map Prod.fst = + jointPathLaw hw hell hS0 hS hr hs hsS (Real.log start.gap) mesh (sourceCostState hs) n := + marked_power_map _ (mismatch_measurable mesh) n (sourceJoint w ell S start hs,false) + +theorem sourceLaw_prime (mesh : ℝ) (n : ℕ) : + (sourceLaw hw hell hS0 hS hr hs hsS mesh n).map (fun q => q.1.1) = pathLaw w ell S start n := by + calc + _ = ((sourceLaw hw hell hS0 hS hr hs hsS mesh n).map Prod.fst).map Prod.fst := + (Measure.map_map (f:=Prod.fst) (g:=Prod.fst) measurable_fst measurable_fst).symm + _ = _ := by rw [sourceLaw_joint,jointPathLaw_prime] + +theorem sourceLaw_continuous (mesh : ℝ) (n : ℕ) : + (sourceLaw hw hell hS0 hS hr hs hsS mesh n).map (fun q => q.1.2) = + ((continuousChain (Real.log start.gap) ell S)^n) (.inl (sourceCostState hs)) := by + calc + _ = ((sourceLaw hw hell hS0 hS hr hs hsS mesh n).map Prod.fst).map Prod.snd := + (Measure.map_map (f:=Prod.fst) (g:=Prod.snd) measurable_snd measurable_fst).symm + _ = _ := by rw [sourceLaw_joint,jointPathLaw_continuous] + +theorem sourceLaw_good {mesh : ℝ} (hm : 0 < mesh) (n : ℕ) : + ∀ᵐ q ∂sourceLaw hw hell hS0 hS hr hs hsS mesh n, + q.2 = false → GoodAt (Real.log start.gap) mesh n q.1 := + actual_flagged_invariant hw hell hS0 hS hr hs hsS (Real.log start.gap) hm + (sourceJoint w ell S start hs) (source_good hs hsS hm.le) n + +end NumberTheoryLean.FlaggedSourceStart + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FullBoxPrefixLower.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FullBoxPrefixLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a35ab69070385531418728276e32c66f5210b63 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FullBoxPrefixLower.lean @@ -0,0 +1,143 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.BinCutGapMovement + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.ActualReferencePrefixes +open FinitePathGeometry PrimeHistories ReferenceAdmission StrongSourceFamilies StrongReferenceTransport +open PrimeBinMembership LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass +attribute [local instance] Classical.propDecidable + +theorem reference_prefix_mem (w : ℝ) (P : Finset ℕ) (i : Side) (r : ℝ) (ps pre : List ℕ) + (hp : ps ∈ referencePrefixes w P i r) (hpre : pre ∈ ps.inits) : pre ∈ referencePrefixes w P i r := by + obtain ⟨tail,he⟩ := (List.mem_inits pre ps).mp hpre + obtain ⟨hd,ha⟩ := Finset.mem_filter.mp hp + obtain ⟨horder,hmem⟩ := mem_decreasingPrefixes.mp hd + rw [← he] at horder ha + apply Finset.mem_filter.mpr + refine ⟨mem_decreasingPrefixes.mpr ⟨(List.pairwise_append.mp horder).1,?_⟩, + ((admitted_append w r i pre tail).mp ha).1⟩ + intro p hp + exact hmem p (by rw [← he]; exact List.mem_append_left _ hp) + +theorem reference_prefix_gap_floor {w top : ℝ} (hw : 1 < w) (htop : w < top) (z : Node) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) (ps pre : List ℕ) + (hp : ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap) (hpre : pre ∈ ps.inits) : + 2 ≤ (terminal w z pre).gap := + (source_reference_transport hw htop z hs hz hg hclosed hcap pre (reference_prefix_mem w _ _ _ ps pre hp hpre)).2 +end NumberTheoryLean.ActualReferencePrefixes + + + +namespace NumberTheoryLean.SelectionWordSplit +open ErdosCofactorChoices ErdosSubsetWord BinCutSelections SourceLabelStrictOrder +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition + +theorem selected_word_split {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (j : Fin (binCount w top xi)) + (u : ℕ) (hfu : f j={u}) : + descendingWord f=descendingWord (aboveSelection f j)++u::descendingWord (belowSelection f j) := by + have hu : u ∈ f j := by rw [hfu]; simp + have hul := selected_prime_label hw htop hxi m f hf j hu + have humem : u ∈ descendingWord f := (mem_descendingWord f u).mpr ⟨j,hu⟩ + have hsource := word_source_membership hw htop hxi m f hf + have hsmaller : ∀ p ∈ descendingWord (belowSelection f j),p ·) := by + rw [List.pairwise_append,List.pairwise_cons] + refine ⟨descendingWord_strict _,⟨hsmaller,descendingWord_strict _⟩,?_⟩ + intro a ha b hb + rcases List.mem_cons.mp hb with rfl | hb + · exact hgreater a ha + · exact (hsmaller b hb).trans (hgreater a ha) + apply (descendingWord_strict f).eq_of_mem_iff hright + intro p + constructor + · intro hp + obtain ⟨k,hpk⟩ := (mem_descendingWord f p).mp hp + have hpl := selected_prime_label hw htop hxi m f hf k hpk + rcases lt_trichotomy k j with hlt | rfl | hgt + · exact List.mem_append_right _ (List.mem_cons_of_mem _ ((below_word_membership hw htop hxi m f hf j p).mpr ⟨hp,by rwa [hpl]⟩)) + · have he : p=u := by simpa only [hfu,Finset.mem_singleton] using hpk + subst p + simp + · exact List.mem_append_left _ ((above_word_membership hw htop hxi m f hf j p).mpr ⟨hp,by rwa [hpl]⟩) + · intro hp + rcases List.mem_append.mp hp with hp | hp + · exact ((above_word_membership hw htop hxi m f hf j p).mp hp).1 + · rcases List.mem_cons.mp hp with rfl | hp + · exact humem + · exact ((below_word_membership hw htop hxi m f hf j p).mp hp).1 +end NumberTheoryLean.SelectionWordSplit + + + +namespace NumberTheoryLean.BinCutPrefixGeometry +open ErdosCofactorChoices ErdosSubsetWord BinCutSelections SelectionWordSplit +open PrimeHistories PrimeProductLogCoordinates +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition + +theorem above_word_is_prefix {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (j : Fin (binCount w top xi)) + (u : ℕ) (hfu : f j={u}) : + descendingWord (aboveSelection f j) ∈ (descendingWord f).inits ∧ + descendingWord (aboveSelection f j)++[u] ∈ (descendingWord f).inits := by + have he := selected_word_split hw htop hxi m f hf j u hfu + constructor + · exact (List.mem_inits _ _).mpr ⟨u::descendingWord (belowSelection f j),he.symm⟩ + · apply (List.mem_inits _ _).mpr + refine ⟨descendingWord (belowSelection f j),?_⟩ + simpa only [List.append_assoc,List.singleton_append] using he.symm + +theorem above_word_product {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (j : Fin (binCount w top xi)) : + (descendingWord (aboveSelection f j)).prod=selectionProduct (aboveSelection f j) := by + apply descendingWord_product (globalBins w top xi) + (fun i k hik => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi i k hik) + intro k + exact ((mem_selections _ _ _).mp (above_selection_mem _ m f hf j) k).1 +end NumberTheoryLean.BinCutPrefixGeometry + + + +namespace NumberTheoryLean.FullBoxPrefixLower +open FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport StrongSourceFamilies +open ErdosCofactorChoices ErdosSubsetWord SafeSubsetBoxGeometry ActualReferencePrefixes BinCutSelections BinCutPrefixGeometry +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition + +theorem full_box_child_gap_floor {w top xi B C K : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ C) + (hcomp : Real.log B ≤ 2*Real.log w) (z : Node) + (hs : Valid z.side z.ratio) (hz : Consistent z) (hg : StrongState z) + (hclosed : z.closed=true) (hcap : w^z.cutoff=top) + (m : Fin (binCount w top xi) → ℕ) (ha : SafeAnchor hw htop hxi C B K z m) + (f : Fin (binCount w top xi) → Finset ℕ) (hf : f ∈ selections (globalBins w top xi) m) + (j : Fin (binCount w top xi)) (u : ℕ) (hu : f j={u}) : + 2 ≤ (terminal w z (descendingWord (aboveSelection f j)++[u])).gap := by + have hfull := (anchored_choice_geometry hw htop hxi hC hcomp z m ha f hf).1 + have hprefix := (above_word_is_prefix hw htop hxi m f hf j u hu).2 + exact reference_prefix_gap_floor hw htop z hs hz hg hclosed hcap _ _ hfull hprefix +end NumberTheoryLean.FullBoxPrefixLower + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FullPathCompactSelection.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FullPathCompactSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..6228e75c67adf69820bbf6f9ee601e9ace17c57d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FullPathCompactSelection.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeHistoryCompactCount +import OAI.NumberTheory.Jacobsthal.Renewal.NonnegativeOriginalOccupation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.FullPathCompactSelection + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling PersistentFailureFlag +open FiniteHistoryTransport ActualCoupledHistories PrimeHistoryCompactCount +open PrimeCompactVisits PrimeCompactWeights SourceCompactOccupation + +variable {w ell S B : ℝ} {start : Node} + +noncomputable def fullCompactReward (R w B : ℝ) {ell S : ℝ} (start : Node) (N : ℕ) + (h : Hist (FlagState (JointState w ell S start)) N) : ℝ≥0∞ := + ∑ j : Fin N, compactReward R w B start (h ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩).1.1 + +theorem fullCompactReward_measurable (R w B : ℝ) {ell S : ℝ} (start : Node) (N : ℕ) : + Measurable (fullCompactReward R w B (ell:=ell) (S:=S) start N) := by + unfold fullCompactReward + apply Finset.measurable_sum + intro j _ + exact (measurable_of_countable (compactReward R w B start)).comp + ((measurable_fst.comp measurable_fst).comp (measurable_pi_apply _)) + +theorem fullCompactReward_envelope {R D : ℝ} + (hbound : ∀ h : History w ell S start, h.node.gap ≤ R → scaledWeight w B start (some h) ≤ D) + (N : ℕ) (h : Hist (FlagState (JointState w ell S start)) N) : + fullCompactReward R w B start N h ≤ + ENNReal.ofReal D * ENNReal.ofReal (pathSum (visit R) N (mapHist (fun q => q.1.1) N h)) := by + unfold fullCompactReward pathSum mapHist + rw [ENNReal.ofReal_sum_of_nonneg (fun _ _ => visit_nonneg _ _),Finset.mul_sum] + apply Finset.sum_le_sum + intro j _ + exact compact_reward_envelope hbound _ + +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem selected_compact_history_bound {R D : ℝ} (hR : 0 ≤ R) (hD : 0 ≤ D) + (hbound : ∀ h : History w ell S start, h.node.gap ≤ R → scaledWeight w B start (some h) ≤ D) + (mesh : ℝ) (N : ℕ) {A : Set (Hist (FlagState (JointState w ell S start)) N)} + (hA : MeasurableSet A) : + (∫⁻ h, A.indicator (fullCompactReward R w B start N) h + ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N) ≤ + ENNReal.ofReal (D*(R+1)) * sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N A := by + calc + _ ≤ ∫⁻ h, A.indicator (fun _ => ENNReal.ofReal (D*(R+1))) h + ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N := by + apply lintegral_mono_ae + filter_upwards [sourceHistory_compact_count hw hell hS0 hS hr hs hsS hR mesh N] with h hh + apply Set.indicator_le_indicator + refine (fullCompactReward_envelope hbound N h).trans ?_ + rw [ENNReal.ofReal_mul hD] + exact mul_le_mul_of_nonneg_left (ENNReal.ofReal_le_ofReal hh) zero_le + _ = _ := lintegral_indicator_const hA _ + +end NumberTheoryLean.FullPathCompactSelection + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/FullWordHighAlignment.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/FullWordHighAlignment.lean new file mode 100644 index 0000000000000000000000000000000000000000..b63b1304566cd62665a487053491cdc1ed5ac770 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/FullWordHighAlignment.lean @@ -0,0 +1,576 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.ActualBoxFourSum +import OAI.NumberTheory.Jacobsthal.Primes.BoundedEdgeHighPrimes +import OAI.NumberTheory.Jacobsthal.Primes.PaperMissingPrimeWindow +import OAI.NumberTheory.Jacobsthal.Probability.PaperSubsetTagEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.SubsetTagFailureMass +open ErdosCofactorChoices ErdosSubsetWord ErdosTagEvent ActualSourceTags ActualBinOwners +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels CanonicalSubsetBox +open WrongOwnerBinMass ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +noncomputable def badSelections {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : Finset (Fin (binCount w top xi) → Finset ℕ) := + (selections (globalBins w top xi) mult).filter (fun f => + (∀ b ∈ occupiedSearch w top xi mult,∀ p ∈ f b,aligns a q p) ∧ + ¬∃ t,sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (descendingWord f)=some t ∧ t.rational=q) + +noncomputable def badMass {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : ℝ := + ∑ f ∈ badSelections (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q,(selectionProduct f:ℝ)⁻¹ + +theorem bad_mass_le_alignment {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : + badMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q ≤ + ∑ f ∈ (selections (globalBins w top xi) mult).filter + (fun f => ∀ b ∈ occupiedSearch w top xi mult,∀ p ∈ f b,aligns a q p),(selectionProduct f:ℝ)⁻¹ := by + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro f hf + obtain ⟨hf,ha,hbad⟩ := Finset.mem_filter.mp hf + exact Finset.mem_filter.mpr ⟨hf,ha⟩ + · intro f _ _ + exact inv_nonneg.mpr (Nat.cast_nonneg _) + +theorem bad_mass_le_wrong {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) + (howner : ∀ b ∈ occupiedSearch w top xi mult, + nearFull eta (lower w top xi b) (width w top xi b) a q → + owner Y w Cs eta (lower w top xi b) (width w top xi b) a=some q) + (hnear : ∃ b ∈ occupiedSearch w top xi mult, + nearFull eta (lower w top xi b) (width w top xi b) a q) : + badMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q ≤ + ∑ f ∈ (selections (globalBins w top xi) mult).filter + (fun f => ∃ b ∈ occupiedSearch w top xi mult,∃ p ∈ f b, + p ∈ wrongOwnerPrimes Y w Cs eta (lower w top xi b) (width w top xi b) a q),(selectionProduct f:ℝ)⁻¹ := by + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro f hf + obtain ⟨hf,halign,hbad⟩ := Finset.mem_filter.mp hf + have hh := subset_bad_tag_inclusion hw htop hxi mult f a q hf howner halign hbad + rcases hh with hnone | hwrong + · obtain ⟨b,hb,hn⟩ := hnear + exact False.elim (hnone b hb hn) + · exact Finset.mem_filter.mpr ⟨hf,hwrong⟩ + · intro f _ _ + exact inv_nonneg.mpr (Nat.cast_nonneg _) +end NumberTheoryLean.SubsetTagFailureMass + + + +namespace NumberTheoryLean.HardTagBoxMass +open SubsetTagFailureMass ActualSourceTags ActualBinOwners +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels PrimeBinRepresentatives +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseAlignment +open ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +noncomputable def hardBadSelections {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : Finset (Fin (binCount w top xi) → Finset ℕ) := + (selections (globalBins w top xi) mult).filter (fun f => + (∀ p ∈ descendingWord f,Cs < primeExponent w p → aligns a q p) ∧ + ¬∃ t,sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a (descendingWord f)=some t ∧ t.rational=q) + +noncomputable def hardBadMass {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : ℝ := + ∑ f ∈ hardBadSelections (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q,(selectionProduct f:ℝ)⁻¹ + +theorem hardBad_subset_bad {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hsearch : Cs ≤ w^((1/4:ℝ))) (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : + hardBadSelections (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q ⊆ + badSelections (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q := by + intro f hf + obtain ⟨hf,halign,hbad⟩ := Finset.mem_filter.mp hf + refine Finset.mem_filter.mpr ⟨hf,?_,hbad⟩ + intro b hb p hp + have hbin := ((mem_selections _ mult f).mp hf b).1 hp + have hx := (bin_exponent_bounds hw (endpoint_pos (zero_lt_one.trans hw) _) + (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le hbin).1 + have hs := (Finset.mem_filter.mp hb).2.1 + change w^((1/4:ℝ)) ≤ leftExponent w (lower w top xi b) at hs + exact halign p ((mem_descendingWord f p).mpr ⟨b,hp⟩) (hsearch.trans hs |>.trans_lt hx) + +theorem hardBadMass_le_badMass {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hsearch : Cs ≤ w^((1/4:ℝ))) (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : + hardBadMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q ≤ + badMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q := by + exact Finset.sum_le_sum_of_subset_of_nonneg (hardBad_subset_bad hw htop hxi hsearch mult a q) + (fun f _ _ => inv_nonneg.mpr (Nat.cast_nonneg _)) +end NumberTheoryLean.HardTagBoxMass + + + +namespace NumberTheoryLean.SafeAnchorSearchCount +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership ActualPrimeHigh +open StrongReferenceTransport StrongSourceFamilies SafeSubsetBoxGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open ErdosCofactorChoices ErdosSubsetWord ErdosSearchCount + + +theorem safe_anchor_search_count (K Clen : ℝ) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,∀ (top B xi : ℝ) (hw : 1 < w) (htop : w < top) (hxi : 0 < xi), + xi ≤ 1 → Real.log B ≤ 2*Real.log w → ∀ z : Node, + Valid z.side z.ratio → Consistent z → StrongState z → z.closed=true → w^z.cutoff=top → w ≤ z.gap → + ∀ mult : Fin (binCount w top xi) → ℕ,SafeAnchor hw htop hxi Clen B K z mult → + (∀ b ∈ occupiedSearch w top xi mult,mult b=1) → + searchConstant*Real.log w ≤ ((occupiedSearch w top xi mult).card:ℝ) ∧ + (∑ b,(mult b:ℝ)) ≤ Clen*Real.log B := by + filter_upwards [actual_search_count_uniform K Clen hC] with w hcount + intro top B xi hw htop hxi hxi1 hcomp z hs hz hstrong hclosed hcap hstart mult ha hsingle + obtain ⟨f,hf,hlen,hsafe,hK⟩ := ha + have ha' : SafeAnchor hw htop hxi Clen B K z mult := ⟨f,hf,hlen,hsafe,hK⟩ + have href := (anchored_choice_geometry hw htop hxi hC hcomp z mult ha' f hf).1 + have htransport := source_reference_transport hw htop z hs hz hstrong hclosed hcap (descendingWord f) href + obtain ⟨U,_hU,hallowed⟩ := (uncapped_iff_exists_ceiling w 1 z (descendingWord f)).mp + ((mem_uncappedPrefixes hw z (descendingWord f)).mp htransport.1) + have hsource := word_source_membership hw htop hxi mult f hf + have hc := hcount top B xi 1 U hw htop hxi hxi1 hcomp (by norm_num) z (descendingWord f) + hs hstart hallowed hK hlen hsource + rw [word_search_count_eq_occupied hw htop hxi mult f hf hsingle] at hc + refine ⟨hc,?_⟩ + have hl : ((descendingWord f).length:ℝ)=∑ b,(mult b:ℝ) := by + exact_mod_cast global_word_length hw htop hxi mult f hf + rwa [← hl] +end NumberTheoryLean.SafeAnchorSearchCount + + + +namespace NumberTheoryLean.HardTagWordFamily +open HardTagBoxMass FiniteBoxWordMass ErdosCofactorChoices ErdosSubsetWord +open LogarithmicBinScale LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +attribute [local instance] Classical.propDecidable + +private theorem finite_union_mass_le {α β : Type*} [DecidableEq α] [DecidableEq β] + (M : Finset β) (T : β → Finset α) (W : α → ℝ) (hW : ∀ x,0 ≤ W x) : + (∑ x ∈ M.biUnion T,W x) ≤ ∑ b ∈ M,∑ x ∈ T b,W x := by + induction M using Finset.induction_on with + | empty => simp + | @insert b M hb ih => + rw [Finset.biUnion_insert,Finset.sum_insert hb] + have he : (∑ x ∈ T b ∪ M.biUnion T,W x)+(∑ x ∈ T b ∩ M.biUnion T,W x)= + (∑ x ∈ T b,W x)+(∑ x ∈ M.biUnion T,W x) := Finset.sum_union_inter + have hn : 0 ≤ ∑ x ∈ T b ∩ M.biUnion T,W x := Finset.sum_nonneg (fun x _ => hW x) + linarith + +noncomputable def hardBadWords {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : Finset (List ℕ) := + (hardBadSelections (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q).image descendingWord + +theorem hardBadWords_mass {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (mult : Fin (binCount w top xi) → ℕ) (a : ℕ → ℤ) (q : ℚ) : + (∑ ps ∈ hardBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q,prefixWeight ps)= + hardBadMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q := by + have hd : Pairwise (fun i j => Disjoint (globalBins w top xi i) (globalBins w top xi j)) := + fun i j hij => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi i j hij + rw [hardBadWords,Finset.sum_image] + · apply Finset.sum_congr rfl + intro f hf + have hs := (Finset.mem_filter.mp hf).1 + rw [StoppedVertexHistory.prefixWeight_product,descendingWord_product (globalBins w top xi) hd f + (fun i => ((mem_selections _ mult f).mp hs i).1)] + · intro f hf g hg he + exact word_injective (globalBins w top xi) hd f g + (fun i => ((mem_selections _ mult f).mp (Finset.mem_filter.mp hf).1 i).1) + (fun i => ((mem_selections _ mult g).mp (Finset.mem_filter.mp hg).1 i).1) he + +noncomputable def hardWordFamily {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (M : Finset (Fin (binCount w top xi) → ℕ)) (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (a : ℕ → ℤ) : Finset (List ℕ) := + M.biUnion (fun mult => (Q mult).biUnion (fun q => hardBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q)) + +theorem hardWordFamily_mass_le {Y w top Cs eta xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (M : Finset (Fin (binCount w top xi) → ℕ)) (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (a : ℕ → ℤ) : + (∑ ps ∈ hardWordFamily (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi M Q a,prefixWeight ps) ≤ + ∑ mult ∈ M,∑ q ∈ Q mult,hardBadMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q := by + apply (finite_union_mass_le M _ prefixWeight prefixWeight_nonneg).trans + apply Finset.sum_le_sum + intro mult _hm + have hh := finite_union_mass_le (Q mult) + (fun q => hardBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q) prefixWeight prefixWeight_nonneg + simpa only [hardBadWords_mass] using hh +end NumberTheoryLean.HardTagWordFamily + + + +namespace NumberTheoryLean.SafeBoxTagRate +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport +open SafeSubsetBoxGeometry SafeAnchorSearchCount SubsetTagFailureMass CanonicalSubsetBox +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinMaps +open CorrectSearchTags UniformSearchOwner ActualBinOwners ActualSourceTags +open ErdosCofactorChoices ErdosSubsetWord ErdosTagEvent ErdosSearchCount +open ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +theorem safe_box_tag_rate {K Clen Cs eta xi : ℝ} (hC : 0 ≤ Clen) (hCs : 0 ≤ Cs) + (heta0 : 0 < eta) (heta : eta < 1/2) (hxi : 0 < xi) (hxi1 : xi ≤ 1) : + ∀ᶠ w : ℝ in atTop,∀ (B top : ℝ) (hw : 1 < w) (htop : w < top),3 ≤ B → + Real.log B ≤ 2*Real.log w → ∀ Y : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → ∀ z : Node, + z.side=.even → 199/100 ≤ z.ratio → Consistent z → z.cutoff=B → z.closed=true → w^B=top → w ≤ z.gap → + ∀ mult : Fin (binCount w top xi) → ℕ,SafeAnchor hw htop hxi Clen B K z mult → + (∀ b ∈ occupiedSearch w top xi mult,mult b=1) → ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + badMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q ≤ + (w^(-(searchConstant*eta/2))+w^(-1:ℝ))*selectionMass (globalBins w top xi) mult := by + have htheta : 0 < xi/4 := by positivity + have hwrong := canonical_wrong_mass (Cs := Cs) (theta := xi/4) (A := 1) (Clen := Clen) + hCs htheta (by norm_num) hC + filter_upwards [safe_anchor_search_count K Clen hC,uniform_correct_owner hCs heta htheta,hwrong] with w hcount howner hwrong + intro B top hw htop hB hcomp Y hY hYup z hi h199 hz hcut hclosed hcap hstart mult hanchor hsingle a q hq + have hw0 : 0 < w := zero_lt_one.trans hw + have hspan : (1+xi)*w ≤ top := by + have hp : w^3 ≤ top := by + have hh := Real.rpow_le_rpow_of_exponent_le hw.le hB + rw [hcap] at hh + simpa only [Real.rpow_ofNat] using hh + have hw2 : 2 ≤ w := howner.1 + have hm := mul_nonneg hw0.le (show 0 ≤ w^2-2 by nlinarith) + nlinarith + have hwidth := common_width_bounds hw0 htop hxi hxi1 hspan + have hvalid : Valid z.side z.ratio := by rw [hi]; change 198/100 ≤ z.ratio; linarith + have hstrong := source_strong_state hB z hi h199 hz hcut + have hcounts := hcount top B xi hw htop hxi hxi1 hcomp z hvalid hz hstrong hclosed + (by rwa [hcut]) hstart mult hanchor hsingle + let I := occupiedSearch w top xi mult + let R := lower w top xi + have hidentify : ∀ b ∈ I,nearFull eta (R b) (width w top xi b) a q → + owner Y w Cs eta (R b) (width w top xi b) a=some q := by + intro b hb hnear + exact howner.2 Y (R b) (width w top xi b) hY hYup (endpoint_pos hw0 _) + (Finset.mem_filter.mp hb).2.1 hwidth.2.1 (hwidth.2.2.1.trans hxi1) a q hq hnear + have hwm := hwrong Y (effectiveWidth w top xi) eta B hY hYup hwidth.2.1 + (hwidth.2.2.1.trans hxi1) hcomp (binCount w top xi) R mult hcounts.2 I hsingle + (fun b hb => searchBin_lower hw (endpoint_pos hw0 _) (Finset.mem_filter.mp hb).2.1) a q hq + have hmass : 0 ≤ selectionMass (globalBins w top xi) mult := + Finset.sum_nonneg (fun f _ => inv_nonneg.mpr (Nat.cast_nonneg _)) + by_cases hnone : ∀ b ∈ I,¬nearFull eta (R b) (width w top xi b) a q + · have hno := canonical_no_nearfull_mass R w searchConstant (effectiveWidth w top xi) eta mult + (fun b => endpoint_pos hw0 _) hw searchConstant_pos hwidth.1.le (hwidth.2.2.1.trans hxi1) + heta0 (by linarith) I hsingle hcounts.1 a q (fun b hb => (nonnearfull_card_lt _ _ _ _ _ (hnone b hb)).le) + have hh := (bad_mass_le_alignment (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q).trans hno + exact hh.trans (mul_le_mul_of_nonneg_right + (le_add_of_nonneg_right (Real.rpow_nonneg hw0.le (-1))) hmass) + · push Not at hnone + have hh := (bad_mass_le_wrong (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q hidentify hnone).trans hwm + exact hh.trans (mul_le_mul_of_nonneg_right + (le_add_of_nonneg_left (Real.rpow_nonneg hw0.le (-(searchConstant*eta/2)))) hmass) +end NumberTheoryLean.SafeBoxTagRate + + + +namespace NumberTheoryLean.RegularBadTagWords +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualWordSelection ActualRegularBoxes +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosSubsetWord ErdosCofactorChoices HardTagWordFamily HardTagBoxMass ActualSourceTags +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +noncomputable def badWordTest {Y w top xi Cs eta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (a : ℕ → ℤ) (ps : List ℕ) : Prop := + ∃ q ∈ Q (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps), + (∀ p ∈ ps,Cs < primeExponent w p → aligns a q p) ∧ + ¬∃ t,sourceTag Y w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a ps=some t ∧ t.rational=q + +noncomputable def regularBadWords {Y w top xi Cs eta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Clen B K : ℝ) (z : Node) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (a : ℕ → ℤ) : Finset (List ℕ) := + (regularWords hw htop hxi Clen B K z).filter (badWordTest (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Q a) + +theorem regularBadWords_subset {Y w top xi Cs eta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Clen B K : ℝ) (z : Node) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (a : ℕ → ℤ) : + regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen B K z Q a ⊆ + hardWordFamily (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi + (regularBoxes hw htop hxi Clen B K z) Q a := by + intro ps hp + obtain ⟨hr,q,hq,ha,hbad⟩ := Finset.mem_filter.mp hp + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hr).1 + let lab := label (zero_lt_one.trans hw) htop hxi + have hrec := wordSelection_recovers lab ps hd.1 + apply Finset.mem_biUnion.mpr + refine ⟨wordMultiplicity lab ps,Finset.mem_image.mpr ⟨ps,hr,rfl⟩,?_⟩ + apply Finset.mem_biUnion.mpr + refine ⟨q,hq,Finset.mem_image.mpr ⟨wordSelection lab ps,?_,hrec⟩⟩ + apply Finset.mem_filter.mpr + refine ⟨wordSelection_mem hw htop hxi ps hd.2,?_⟩ + simpa only [hrec] using (show (∀ p ∈ ps,Cs < primeExponent w p → aligns a q p) ∧ + ¬∃ t,sourceTag Y w Cs eta (lower w top xi) (width w top xi) lab a ps=some t ∧ t.rational=q from ⟨ha,hbad⟩) + +theorem regularBadWords_mass_le {Y w top xi Cs eta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Clen B K : ℝ) (z : Node) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (a : ℕ → ℤ) : + (∑ ps ∈ regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen B K z Q a,prefixWeight ps) ≤ + ∑ ps ∈ hardWordFamily (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi + (regularBoxes hw htop hxi Clen B K z) Q a,prefixWeight ps := + Finset.sum_le_sum_of_subset_of_nonneg (regularBadWords_subset hw htop hxi Clen B K z Q a) + (fun ps _ _ => prefixWeight_nonneg ps) +end NumberTheoryLean.RegularBadTagWords + + + +namespace NumberTheoryLean.GlobalSafeTagCapture +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open SafeSubsetBoxGeometry SafeBoxTagRate ActualSafeBoxMass SubsetTagFailureMass CanonicalSubsetBox +open LogarithmicBinScale ActualBinOwners ErdosSubsetWord ErdosSearchCount + +attribute [local instance] Classical.propDecidable + +private theorem finite_candidate_sum {β : Type*} (M : Finset β) (Q : β → Finset ℚ) + (H : ℕ) (r : ℝ) (hr : 0 ≤ r) (F : β → ℝ) (hF : ∀ b ∈ M,0 ≤ F b) + (G : β → ℚ → ℝ) (hG : ∀ b ∈ M,∀ q ∈ Q b,G b q ≤ r*F b) + (hQ : ∀ b ∈ M,(Q b).card ≤ H) : + (∑ b ∈ M,∑ q ∈ Q b,G b q) ≤ (H:ℝ)*r*(∑ b ∈ M,F b) := by + calc + _ ≤ ∑ b ∈ M,∑ _q ∈ Q b,r*F b := Finset.sum_le_sum (fun b hb => Finset.sum_le_sum (fun q hq => hG b hb q hq)) + _ = ∑ b ∈ M,((Q b).card:ℝ)*(r*F b) := by simp + _ ≤ ∑ b ∈ M,(H:ℝ)*(r*F b) := Finset.sum_le_sum (fun b hb => + mul_le_mul_of_nonneg_right (by exact_mod_cast hQ b hb) (mul_nonneg hr (hF b hb))) + _ = _ := by rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro b _; ring + +theorem global_bad_tag_mass_small {K Clen Cs eta xi : ℝ} (hK : 3 ≤ K) (hC : 0 ≤ Clen) (hCs : 0 ≤ Cs) + (heta0 : 0 < eta) (heta : eta < 1/2) (hxi : 0 < xi) (hxi1 : xi ≤ 1) + (hDelta : 2*Clen*xi ≤ 1) (H : ℕ) (epsilon : ℝ) (hepsilon : 0 < epsilon) : + ∃ B₀ w₀ : ℝ,3 ≤ B₀ ∧ 1 < w₀ ∧ ∀ (B w top : ℝ) (hw : 1 < w) (htop : w < top), + B₀ ≤ B → w₀ ≤ w → Real.log B ≤ 2*Real.log w → ∀ Y : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → + ∀ (z : Node) (a : ℕ → ℤ),z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → + Consistent z → z.cutoff=B → z.closed=true → w^B=top → w ≤ z.gap → + ∀ (M : Finset (Fin (binCount w top xi) → ℕ)) (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ), + (∀ mult ∈ M,SafeAnchor hw htop hxi Clen B K z mult) → + (∀ mult ∈ M,∀ b ∈ occupiedSearch w top xi mult,mult b=1) → + (∀ mult ∈ M,(Q mult).card ≤ H) → (∀ mult ∈ M,∀ q ∈ Q mult,eligible Y w Cs q) → + B^2*(∑ mult ∈ M,∑ q ∈ Q mult,badMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q) ≤ epsilon := by + obtain ⟨C,B₀,wbox,hCpos,hB₀,hwbox,hboxes⟩ := uniform_safe_box_mass K hK + have hd : 0 < searchConstant*eta/2 := by have hc := searchConstant_pos; positivity + have hrate : Tendsto (fun w : ℝ => (H:ℝ)*C*(w^(-(searchConstant*eta/2))+w^(-1:ℝ))) atTop (nhds 0) := by + have hh := ((tendsto_rpow_neg_atTop hd).add (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1))).const_mul ((H:ℝ)*C) + simpa only [zero_add,mul_zero] using hh + have hsmall : ∀ᶠ w : ℝ in atTop,(H:ℝ)*C*(w^(-(searchConstant*eta/2))+w^(-1:ℝ)) ≤ epsilon := + ((tendsto_order.mp hrate).2 epsilon hepsilon).mono (fun _ h => h.le) + have htag := safe_box_tag_rate (K := K) (Clen := Clen) (Cs := Cs) (eta := eta) (xi := xi) hC hCs heta0 heta hxi hxi1 + obtain ⟨w₁,hw₁⟩ := eventually_atTop.mp (htag.and (hsmall.and (eventually_ge_atTop wbox))) + refine ⟨B₀,max 2 w₁,hB₀,by have hh := le_max_left (2:ℝ) w₁; linarith,?_⟩ + intro B w top hw htop hB hW hcomp Y hY hYup z a hi h199 h23 hz hcut hclosed hcap hstart M Q hanchor hsingle hcard helig + have hgood := hw₁ w ((le_max_right _ _).trans hW) + have hB3 := hB₀.trans hB + let r := w^(-(searchConstant*eta/2))+w^(-1:ℝ) + have hw0 : 0 < w := zero_lt_one.trans hw + have hr : 0 ≤ r := add_nonneg (Real.rpow_nonneg hw0.le _) (Real.rpow_nonneg hw0.le _) + have hm := finite_candidate_sum M Q H r hr (selectionMass (globalBins w top xi)) + (fun mult _ => Finset.sum_nonneg (fun f _ => inv_nonneg.mpr (Nat.cast_nonneg _))) + (fun mult q => badMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q) + (fun mult hmult q hq => hgood.1 B top hw htop hB3 hcomp Y hY hYup z hi h199 hz hcut hclosed hcap hstart + mult (hanchor mult hmult) (hsingle mult hmult) a q (helig mult hmult q hq)) hcard + have hbox := hboxes B w top hB hgood.2.2 hw htop xi Clen hxi hC hcomp hDelta z hi h199 h23 hz hcut hclosed hcap M hanchor + calc + _ ≤ B^2*((H:ℝ)*r*(∑ mult ∈ M,selectionMass (globalBins w top xi) mult)) := mul_le_mul_of_nonneg_left hm (sq_nonneg B) + _ = (H:ℝ)*r*(B^2*(∑ mult ∈ M,selectionMass (globalBins w top xi) mult)) := by ring + _ ≤ (H:ℝ)*r*C := mul_le_mul_of_nonneg_left hbox (mul_nonneg (Nat.cast_nonneg _) hr) + _ = (H:ℝ)*C*r := by ring + _ ≤ epsilon := hgood.2.1 +end NumberTheoryLean.GlobalSafeTagCapture + + + +namespace NumberTheoryLean.PaperSafeTagCapture +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership SourceNodeCoordinates +open JacobsthalSourceScale PaperMissingPrimeWindow PaperOwnerHeight PaperBinOwners +open SafeSubsetBoxGeometry GlobalSafeTagCapture HardTagBoxMass ActualBinOwners +open LogarithmicBinScale ErdosSubsetWord + +attribute [local instance] Classical.propDecidable + +theorem paper_safe_hard_tag_capture {K Clen Cs eta xi : ℝ} (hK : 3 ≤ K) (hC : 0 ≤ Clen) (hCs : 0 ≤ Cs) + (heta0 : 0 < eta) (heta : eta < 1/2) (hxi : 0 < xi) (hxi1 : xi ≤ 1) + (hDelta : 2*Clen*xi ≤ 1) (H : ℕ) (epsilon : ℝ) (hepsilon : 0 < epsilon) : + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ Y : ℕ,Y ≤ ⌊top^2/(Real.log top)^2⌋₊ → ∀ (z : Node) (a : ℕ → ℤ), + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=sourceB (Real.log top) → z.closed=true → + ∀ (M : Finset (Fin (binCount (sourceW (Real.log top)) top xi) → ℕ)) + (Q : (Fin (binCount (sourceW (Real.log top)) top xi) → ℕ) → Finset ℚ), + (∀ mult ∈ M,SafeAnchor hw htop hxi Clen (sourceB (Real.log top)) K z mult) → + (∀ mult ∈ M,∀ b ∈ occupiedSearch (sourceW (Real.log top)) top xi mult,mult b=1) → + (∀ mult ∈ M,(Q mult).card ≤ H) → + (∀ mult ∈ M,∀ q ∈ Q mult,eligible Y (sourceW (Real.log top)) Cs q) → + (sourceB (Real.log top))^2 * + (∑ mult ∈ M,∑ q ∈ Q mult,hardBadMass (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi mult a q) ≤ epsilon := by + obtain ⟨B₀,w₀,_hB₀,_hw₀,hbound⟩ := global_bad_tag_mass_small hK hC hCs heta0 heta hxi hxi1 hDelta H epsilon hepsilon + have hwT := sourceW_tendsto.comp Real.tendsto_log_atTop + have hBT := sourceB_tendsto.comp Real.tendsto_log_atTop + have hsearch : ∀ᶠ top : ℝ in atTop,Cs ≤ (sourceW (Real.log top))^((1/4:ℝ)) := + ((tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/4)).comp hwT).eventually_ge_atTop Cs + filter_upwards [paper_bin_span hxi hxi1,Real.tendsto_log_atTop.eventually source_scale_eventually, + Real.tendsto_log_atTop.eventually sourceW_le_sourceB_eventually,literal_source_floor_height, + hwT.eventually_ge_atTop w₀,hBT.eventually_ge_atTop B₀,eventually_gt_atTop (1:ℝ),hsearch] + with top hspan hscale hWB hheight hwBound hBBound htop1 hsearch + have hw : 1 < sourceW (Real.log top) := by linarith [hspan.1] + refine ⟨hw,hspan.2.1,?_⟩ + intro Y hY z a hi h199 h23 hz hcut hclosed M Q hanchors hsingle hcard helig + have hYup : (Y:ℝ) ≤ Real.exp ((sourceW (Real.log top))^2) := + (show (Y:ℝ) ≤ (⌊top^2/(Real.log top)^2⌋₊:ℕ) by exact_mod_cast hY).trans hheight + have hcap : (sourceW (Real.log top))^(sourceB (Real.log top))=top := + (sourceW_pow_sourceB hw).trans (Real.exp_log (zero_lt_one.trans htop1)) + have hgap := (source_node_bounds hscale.2.1 z hi h199 h23 hz hcut).2.2.1 + have hstart := hWB.trans hgap + have hh := hbound (sourceB (Real.log top)) (sourceW (Real.log top)) top hw hspan.2.1 hBBound hwBound + hscale.2.2.2.2 Y (Nat.cast_nonneg Y) hYup z a hi h199 h23 hz hcut hclosed hcap hstart M Q hanchors hsingle hcard helig + apply le_trans _ hh + apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) + apply Finset.sum_le_sum + intro mult _hm + apply Finset.sum_le_sum + intro q _hq + exact hardBadMass_le_badMass hw hspan.2.1 hxi hsearch mult a q +end NumberTheoryLean.PaperSafeTagCapture + + + +namespace NumberTheoryLean.PaperSafeWordCapture +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open JacobsthalSourceScale SafeSubsetBoxGeometry HardTagWordFamily ActualBinOwners +open LogarithmicBinScale ErdosSubsetWord PaperSafeTagCapture + +attribute [local instance] Classical.propDecidable + +theorem paper_safe_hard_word_capture {K Clen Cs eta xi : ℝ} (hK : 3 ≤ K) (hC : 0 ≤ Clen) (hCs : 0 ≤ Cs) + (heta0 : 0 < eta) (heta : eta < 1/2) (hxi : 0 < xi) (hxi1 : xi ≤ 1) + (hDelta : 2*Clen*xi ≤ 1) (H : ℕ) (epsilon : ℝ) (hepsilon : 0 < epsilon) : + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ Y : ℕ,Y ≤ ⌊top^2/(Real.log top)^2⌋₊ → ∀ (z : Node) (a : ℕ → ℤ), + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=sourceB (Real.log top) → z.closed=true → + ∀ (M : Finset (Fin (binCount (sourceW (Real.log top)) top xi) → ℕ)) + (Q : (Fin (binCount (sourceW (Real.log top)) top xi) → ℕ) → Finset ℚ), + (∀ mult ∈ M,SafeAnchor hw htop hxi Clen (sourceB (Real.log top)) K z mult) → + (∀ mult ∈ M,∀ b ∈ occupiedSearch (sourceW (Real.log top)) top xi mult,mult b=1) → + (∀ mult ∈ M,(Q mult).card ≤ H) → + (∀ mult ∈ M,∀ q ∈ Q mult,eligible Y (sourceW (Real.log top)) Cs q) → + (sourceB (Real.log top))^2 * + (∑ ps ∈ hardWordFamily (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi M Q a,ErdosPrimeInputs.PrimePrefixMass.prefixWeight ps) ≤ epsilon := by + filter_upwards [paper_safe_hard_tag_capture hK hC hCs heta0 heta hxi hxi1 hDelta H epsilon hepsilon] with top htopData + obtain ⟨hw,htop,hbound⟩ := htopData + refine ⟨hw,htop,?_⟩ + intro Y hY z a hi h199 h23 hz hcut hclosed M Q hanchors hsingle hcard helig + have hh := hbound Y hY z a hi h199 h23 hz hcut hclosed M Q hanchors hsingle hcard helig + exact (mul_le_mul_of_nonneg_left (hardWordFamily_mass_le (Y := Y) (Cs := Cs) (eta := eta) + hw htop hxi M Q a) (sq_nonneg (sourceB (Real.log top)))).trans hh +end NumberTheoryLean.PaperSafeWordCapture + + + +namespace NumberTheoryLean.PaperRegularTagCapture +open _root_.Filter _root_.Erdos970.Filter FinitePathGeometry PrimeHistories PrimeBinMembership +open JacobsthalSourceScale ActualRegularBoxes ActualPrefixClearance RegularBadTagWords +open PaperSafeWordCapture ActualBinOwners LogarithmicBinScale + +attribute [local instance] Classical.propDecidable + +theorem paper_regular_bad_tag_mass {K Clen Cs eta xi : ℝ} (hK : 3 ≤ K) (hC : 1 ≤ Clen) (hCs : 0 ≤ Cs) + (heta0 : 0 < eta) (heta : eta < 1/2) (hxi : 0 < xi) (hxi1 : xi ≤ 1) + (hDelta : 2*Clen*xi ≤ 1) (H : ℕ) (epsilon : ℝ) (hepsilon : 0 < epsilon) : + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW (Real.log top),∃ htop : sourceW (Real.log top) < top, + ∀ Y : ℕ,Y ≤ ⌊top^2/(Real.log top)^2⌋₊ → ∀ (z : Node) (a : ℕ → ℤ), + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=sourceB (Real.log top) → z.closed=true → + ∀ Q : (Fin (binCount (sourceW (Real.log top)) top xi) → ℕ) → Finset ℚ, + (∀ mult ∈ regularBoxes hw htop hxi Clen (sourceB (Real.log top)) K z,(Q mult).card ≤ H) → + (∀ mult ∈ regularBoxes hw htop hxi Clen (sourceB (Real.log top)) K z, + ∀ q ∈ Q mult,eligible Y (sourceW (Real.log top)) Cs q) → + (sourceB (Real.log top))^2 * + (∑ ps ∈ regularBadWords (Y := Y) (Cs := Cs) (eta := eta) hw htop hxi Clen + (sourceB (Real.log top)) K z Q a,ErdosPrimeInputs.PrimePrefixMass.prefixWeight ps) ≤ epsilon := by + have hC0 : 0 ≤ Clen := by linarith + have hwT := sourceW_tendsto.comp Real.tendsto_log_atTop + filter_upwards [paper_safe_hard_word_capture hK hC0 hCs heta0 heta hxi hxi1 hDelta H epsilon hepsilon, + Real.tendsto_log_atTop.eventually source_scale_eventually, + (Real.tendsto_log_atTop.comp hwT).eventually_ge_atTop 1] with top hbound hscale hlog + obtain ⟨hw,htop,hbound⟩ := hbound + refine ⟨hw,htop,?_⟩ + intro Y hY z a hi h199 h23 hz hcut hclosed Q hcard helig + have hsmall := source_mesh_clearance_condition hlog hxi.le hC + have hh := hbound Y hY z a hi h199 h23 hz hcut hclosed + (regularBoxes hw htop hxi Clen (sourceB (Real.log top)) K z) Q + (regular_boxes_anchors hw htop hxi hC0 hscale.2.2.2.2 hsmall z) + (regular_boxes_search_singletons hw htop hxi z) hcard helig + exact (mul_le_mul_of_nonneg_left (regularBadWords_mass_le (Y := Y) (Cs := Cs) (eta := eta) + hw htop hxi Clen (sourceB (Real.log top)) K z Q a) (sq_nonneg _)).trans hh +end NumberTheoryLean.PaperRegularTagCapture + + + +namespace NumberTheoryLean.FullWordHighAlignment +open ErdosSubsetWord ErdosCofactorChoices ErdosInverseAlignment +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinEndpoints +open ParentTailPartition ParentCofactorChoices BinCutSelections SingletonBinSelection +open TwoPrimeObservableSum BoundedEdgeBins BoundedEdgeHighPrimes +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem parent_prime_factors {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (i j : Fin (binCount w top xi)) : + (selectionProduct (parentCofactorSelection f i j)).primeFactors= + selectionPrimes (parentCofactorSelection f i j) := by + have hc := erase_selection_mem _ _ _ (above_selection_mem _ m f hf j) i + exact selectionProduct_primeFactors (globalBins w top xi) + (fun k _p hp => (bin_prime_in_source (zero_lt_one.trans hw) htop hxi k hp).1) + (fun k l hkl => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) + (parentCofactorSelection f i j) (fun k => ((mem_selections _ _ _).mp hc k).1) + +theorem full_word_high_alignment {w top xi Cs M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hCs : X+xi/Real.log w ≤ Cs) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (i j : Fin (binCount w top xi)) + (hi : m i=1) (hj : boundedEdgeBin w top xi Y m M X j) + (a : ℕ → ℤ) (q : ℚ) (hiso : aligns a q (pickedPrime f i)) + (hparent : ∀ p∈(selectionProduct (parentCofactorSelection f i j)).primeFactors, + Cs < primeExponent w p → aligns a q p) : + ∀ p∈descendingWord f,Cs < primeExponent w p → aligns a q p := by + intro p hp hhigh + obtain ⟨k,hpk⟩ := (mem_descendingWord f p).mp hp + by_cases hki : k=i + · subst k + obtain ⟨p0,_hp0,hfi,_hfill⟩ := singleton_selection_recovery _ m i hi f hf + have he : p=p0 := by simpa only [hfi,Finset.mem_singleton] using hpk + simpa [pickedPrime,hfi,he] using hiso + · have hjk : j < k := by + by_contra! hkj + have hpbin := ((mem_selections _ _ _).mp hf k).1 hpk + exact (not_le_of_gt hhigh) ((bounded_edge_descendant_exponent hw htop hxi m j k hj hkj hpbin).trans hCs) + apply hparent p _ hhigh + rw [parent_prime_factors hw htop hxi m f hf i j] + apply Finset.mem_biUnion.mpr + exact ⟨k,Finset.mem_univ _,by simpa [parentCofactorSelection,eraseSelection,aboveSelection,hki,hjk] using hpk⟩ + +theorem full_word_high_alignment_fixed_cutoff {w top xi Cs M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hlog : 1 ≤ Real.log w) (hxi1 : xi ≤ 1) (hCs : X+1 ≤ Cs) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (i j : Fin (binCount w top xi)) + (hi : m i=1) (hj : boundedEdgeBin w top xi Y m M X j) + (a : ℕ → ℤ) (q : ℚ) (hiso : aligns a q (pickedPrime f i)) + (hparent : ∀ p∈(selectionProduct (parentCofactorSelection f i j)).primeFactors, + Cs < primeExponent w p → aligns a q p) : + ∀ p∈descendingWord f,Cs < primeExponent w p → aligns a q p := by + apply full_word_high_alignment hw htop hxi _ m f hf i j hi hj a q hiso hparent + have hh : xi/Real.log w ≤ 1 := (div_le_one (Real.log_pos hw)).mpr (hxi1.trans hlog) + linarith +end NumberTheoryLean.FullWordHighAlignment + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricEdgeWitness.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricEdgeWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..89f4bcbcaa0a88b2c867a89777bc80e5aa478835 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricEdgeWitness.lean @@ -0,0 +1,76 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CandidateExceptionMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GeometricEdgeWitness +open PrimeHistories GeometricRegularWords SourceCompactSingletons ActualWordSelection +open ErdosCofactorChoices ErdosSubsetWord BoundedCandidateCount BoundedEdgeBins FullBoxLengthBounds +open BinCutSelections BinCutPrefixGeometry SelectionWordSplit +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +theorem decreasing_edge_prefix_unique (ps pre tail pre' tail' : List ℕ) (u : ℕ) + (hd : ps.Pairwise (· > ·)) (he : ps=pre++u::tail) (he' : ps=pre'++u::tail') : pre=pre' := by + have hno : u ∉ pre := by + intro hu + have hh := hd + rw [he,List.pairwise_append] at hh + exact (lt_irrefl u) (hh.2.2 u hu u (by simp)) + have hno' : u ∉ pre' := by + intro hu + have hh := hd + rw [he',List.pairwise_append] at hh + exact (lt_irrefl u) (hh.2.2 u hu u (by simp)) + have hidx : ps.idxOf u=pre.length := by rw [he,List.idxOf_append_of_notMem hno]; simp + have hidx' : ps.idxOf u=pre'.length := by rw [he',List.idxOf_append_of_notMem hno']; simp + have hlen : pre.length=pre'.length := hidx.symm.trans hidx' + calc + pre=ps.take pre.length := by rw [he]; simp + _=ps.take pre'.length := by rw [hlen] + _=pre' := by rw [he']; simp + +theorem geometric_word_bounded_edge {w top xi C B R L alpha beta M X : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℕ) (z : Node) (ps : List ℕ) + (hp : ps ∈ geometricWords hw htop hxi C B R L alpha beta z) + (pre tail : List ℕ) (u : ℕ) (he : ps=pre++u::tail) + (hgap : (terminal w z pre).gap ≤ L) + (hM : Real.log ((Y:ℝ)/(pre.prod:ℝ))/Real.log w ≤ M) (hX : primeExponent w u ≤ X) : + boundedEdgeBin w top xi Y (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps) M X + (label (zero_lt_one.trans hw) htop hxi u) := by + have hreg := (Finset.mem_filter.mp hp).1 + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hreg).1 + have hn : ps.Nodup := hd.1.imp (fun h => ne_of_gt h) + let lab := label (zero_lt_one.trans hw) htop hxi + let m := wordMultiplicity lab ps + let f := wordSelection lab ps + let j := lab u + have hf : f ∈ selections (globalBins w top xi) m := wordSelection_mem hw htop hxi ps hd.2 + have hsingle := GeometricRegularWords.geometric_compact_singleton hw htop hxi z ps hp pre tail u he hgap + have hcard : (f j).card=1 := (wordMultiplicity_count lab ps hn j).trans hsingle + have hu : u ∈ f j := by + change u ∈ ps.toFinset.filter (fun p => lab p=j) + simp [he,j] + obtain ⟨v,hfv⟩ := Finset.card_eq_one.mp hcard + have huv : u=v := by simpa only [hfv,Finset.mem_singleton] using hu + have hfu : f j={u} := by rwa [← huv] at hfv + have hword := wordSelection_recovers lab ps hd.1 + have hsplit := selected_word_split hw htop hxi m f hf j u hfu + rw [hword] at hsplit + have hpre := decreasing_edge_prefix_unique ps pre tail (descendingWord (aboveSelection f j)) + (descendingWord (belowSelection f j)) u hd.1 he hsplit + refine ⟨f,hf,u,hfu,?_,hX⟩ + unfold parentLength + rw [← above_word_product hw htop hxi m f hf j,← hpre] + exact hM +end NumberTheoryLean.GeometricEdgeWitness + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricRegularWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricRegularWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..613c26a5e68e262e103dd87321dfdd7f96f2f26d --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricRegularWords.lean @@ -0,0 +1,143 @@ +import OAI.NumberTheory.Jacobsthal.Analysis.SourceCompactSingletons +import OAI.NumberTheory.Jacobsthal.Estimates.SourceFirstCrossing +import OAI.NumberTheory.Jacobsthal.Partitions.RegularityDefectPartition +import OAI.NumberTheory.Jacobsthal.Primes.CrossingPrimeBin + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GoodCrossingVisit +open _root_.Set _root_.MeasureTheory FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeTiltGeometry +open RegeneratingInverseBands ArrivalKernelGeometry ActualFlagInvariant CrossingPrimeBin CrossingBandGeometry +open IsolatedBinGeometry LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels + +noncomputable def crossingHighEvent (v H T : ℝ) : Set CostState := + {y | T < stateRatio y.1 ∧ y.2 ∈ Icc (crossingCenter v H) (crossingCenter v H+crossingWidth)} + +theorem crossingHighEvent_measurable (v H T : ℝ) : MeasurableSet (crossingHighEvent v H T) := + (measurableSet_lt measurable_const (stateRatio_measurable.comp measurable_fst)).inter + (measurable_snd measurableSet_Icc) + +theorem good_crossing_visit {w top xi ell S theta T B v mesh : ℝ} {N : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hell : 1 ≤ ell) + (htheta : 0 < theta) (hT : 1 ≤ T) (hB : 0 < B) (hm : mesh ≤ 1) + (he : Real.exp (4*(N:ℝ)*mesh) ≤ 11/10) + (z : Node) (hs : Valid z.side z.ratio) (hcap : w^z.cutoff=top) + (p : History w ell S z) (hne : p.primes ≠ []) (y : CostState) + (hg : liveGood v mesh N p y) + (hlo : theta*B/3 < p.node.gap) (hhi : p.node.gap ≤ theta*B) + (hwidth : xi/Real.log w ≤ isolatedAlpha theta (T+1)*B) + (hno : ¬isolatedBin w top xi B (isolatedAlpha theta (T+1)) (4*theta) + (label (zero_lt_one.trans hw) htop hxi (p.primes.getLastD 0))) : + y ∈ crossingHighEvent v (theta*B) T := by + have hratio : T < stateRatio y.1 := by + by_contra! hr + have hpT : p.node.ratio ≤ T+1 := by linarith [(abs_le.mp hg.2.2.1).2] + exact hno (actual_crossing_bin hw htop hxi hell htheta (by linarith) hB z hs hcap p hne hlo hhi hpT hwidth) + have hp0 : 0 < p.node.gap := by nlinarith + have hband := matched_gap_crossing (mul_pos htheta hB) hp0 (Real.exp_pos _) hlo hhi hg.2.2.2 he + exact ⟨hratio,crossing_cost_band (mul_pos htheta hB) v y hband⟩ +end NumberTheoryLean.GoodCrossingVisit + + + +namespace NumberTheoryLean.NonisolatedWordOccurrence +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain FiniteHistoryTransport +open ActualSuccessfulHistories ActualCoupledHistories PrimePrefixRecovery ActualFlagInvariant RepeatedPairEvents +open SourceFirstCrossing GoodCrossingVisit CrossingPrimeBin IsolatedBinGeometry +open CompletedArrivalOccurrence LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open PersistentFailureFlag + +noncomputable def noIsolatedWord {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (B alpha beta : ℝ) (ps : List ℕ) : Prop := + ∀ p ∈ ps,¬isolatedBin w top xi B alpha beta (label (zero_lt_one.trans hw) htop hxi p) + +variable {w ell S : ℝ} {start : Node} +variable (hwn : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem nonisolated_word_occurs {top xi B theta T mesh : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (hB : 0 < B) (htheta : 0 < theta) (htheta1 : theta ≤ 1/2) (hT : 1 ≤ T) + (h199 : 199/100 ≤ start.ratio) (hc : PrimeBinMembership.Consistent start) (hcut : start.cutoff=B) + (hcap : w^start.cutoff=top) (hm : 0 < mesh) (hmesh : mesh ≤ 1) (N : ℕ) + (hexp : Real.exp (4*(N:ℝ)*mesh) ≤ 11/10) + (hwidth : xi/Real.log w ≤ isolatedAlpha theta (T+1)*B) : + ∀ᵐ h ∂sourceHistoryLaw hwn hell hS0 hS hr hs hsS mesh N, + (last N h).2=false → ∀ j : Finset.Iic N,∀ p : History w ell S start,(h j).1.1=some p → + p.node.gap ≤ theta*B → noIsolatedWord hw htop hxi B (isolatedAlpha theta (T+1)) (4*theta) p.primes → + completedOccurrence (crossingHighEvent (Real.log start.gap) (theta*B) T) N + (mapHist (fun q => q.1.2) N h) := by + filter_upwards [sourceHistory_success_good hwn hell hS0 hS hr hs hsS hm N, + sourceHistory_recovers_prefix hwn hell hS0 hS hr hs hsS mesh N] with h hgood hprefix + intro hf j p hp hend hno + obtain ⟨pre,a,tail,hpre,he,_hbefore,hhi,hlo⟩ := + source_gap_crossing (by linarith) hB htheta1 start hs h199 hc hcut p.primes p.admissible hend + have hword : p.primes=(pre++[a])++tail := by simpa only [List.append_assoc,List.singleton_append] using he + obtain ⟨hk,q,hq,hqword⟩ := hprefix j p hp (pre++[a]) tail hword + have hn : (pre++[a]).length ≠ 0 := by simp + let i : Finset.Iic N := ⟨(pre++[a]).length,Finset.mem_Iic.mpr hk⟩ + let k : Fin N := ⟨(pre++[a]).length-1,by omega⟩ + have hkval : k.1+1=(pre++[a]).length := by dsimp [k]; omega + have hg := goodAt_enlarge hm.le hk _ (hgood hf i) + change GoodAt (Real.log start.gap) mesh N ((h i).1.1,(h i).1.2) at hg + rw [hq] at hg + cases hy : (h i).1.2 with + | inr u => rw [hy] at hg; exact False.elim hg + | inl y => + rw [hy] at hg + have hqne : q.primes ≠ [] := by rw [hqword]; simp + have hqhi : q.node.gap ≤ theta*B := by change (terminal w start q.primes).gap ≤ _; rwa [hqword] + have hqlo : theta*B/3 < q.node.gap := by change _ < (terminal w start q.primes).gap; rwa [hqword] + have ha : a ∈ p.primes := by rw [he]; simp + have hlast : q.primes.getLastD 0=a := by rw [hqword]; exact List.getLastD_concat + have hno' : ¬isolatedBin w top xi B (isolatedAlpha theta (T+1)) (4*theta) + (label (zero_lt_one.trans hw) htop hxi (q.primes.getLastD 0)) := by rw [hlast]; exact hno a ha + have hv := good_crossing_visit hw htop hxi hell htheta hT hB hmesh hexp start hs hcap q hqne y hg hqlo hqhi hwidth hno' + refine ⟨k,?_⟩ + change liveMember _ ((h ⟨k.1+1,Finset.mem_Iic.mpr (by have := k.isLt; omega)⟩).1.2) + have hy' : (h ⟨k.1+1,Finset.mem_Iic.mpr (by have := k.isLt; omega)⟩).1.2=Sum.inl y := by + simpa only [hkval] using hy + rw [hy'] + exact hv +end NumberTheoryLean.NonisolatedWordOccurrence + + + +namespace NumberTheoryLean.GeometricRegularWords +open FinitePathGeometry PrimeHistories ActualRegularBoxes RepeatedWordEvents NonisolatedWordOccurrence +open SourceCompactSingletons IsolatedBinGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +attribute [local instance] Classical.propDecidable + +noncomputable def geometricWords {w top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (Clen B R L alpha beta : ℝ) (z : Node) : Finset (List ℕ) := + (regularWords hw htop hxi Clen B R z).filter (fun ps => + ¬compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L z ps ∧ + ¬noIsolatedWord hw htop hxi B alpha beta ps) + +theorem geometric_isolated_prime {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) (ps : List ℕ) + (hp : ps ∈ geometricWords hw htop hxi C B R L alpha beta z) : + ∃ p ∈ ps,isolatedBin w top xi B alpha beta (label (zero_lt_one.trans hw) htop hxi p) := by + have h := (Finset.mem_filter.mp hp).2.2 + simpa only [noIsolatedWord,not_forall,not_not,exists_prop] using h + +theorem geometric_compact_singleton {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) (ps : List ℕ) + (hp : ps ∈ geometricWords hw htop hxi C B R L alpha beta z) + (pre tail : List ℕ) (p : ℕ) (he : ps=pre++p::tail) (hgap : (terminal w z pre).gap ≤ L) : + (ps.map (label (zero_lt_one.trans hw) htop hxi)).count (label (zero_lt_one.trans hw) htop hxi p)=1 := by + have hr := Finset.mem_filter.mp hp + have hd := ErdosPrimeInputs.PrimePrefixMass.mem_decreasingPrefixes.mp (Finset.mem_filter.mp hr.1).1 + exact source_compact_singleton hw htop hxi L z ps hd.1 hd.2 hr.2.1 pre tail p he hgap +end NumberTheoryLean.GeometricRegularWords + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..39def76c595ae6436266bd74ec1e96c792ba4283 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/GeometricWords.lean @@ -0,0 +1,37 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.PaperGeometricRegularity + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.GeometricWordsAudit +open PrimeHistories GeometricRegularWords FirstIsolatedPosition IsolatedRealPrimeRange +open IsolatedBinGeometry LogarithmicBinScale LogarithmicBinLabels LogarithmicBinEndpoints + + +theorem geometric_nonempty {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (z : Node) (ps : List ℕ) + (hp : ps ∈ geometricWords hw htop hxi C B R L alpha beta z) : ps ≠ [] := by + obtain ⟨p,hp,_⟩ := geometric_isolated_prime hw htop hxi z ps hp + exact List.ne_nil_of_mem hp + +theorem geometric_isolated_range {w top xi C B R L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hpower : w^B=top) (z : Node) (ps : List ℕ) + (hp : ps ∈ geometricWords hw htop hxi C B R L alpha beta z) + (hsearch : w^((1/4:ℝ)) ≤ alpha*B) : + ∃ pre p tail,ps=pre++p::tail ∧ + top^alpha ≤ lower w top xi (label (zero_lt_one.trans hw) htop hxi p) ∧ + upper w top xi (label (zero_lt_one.trans hw) htop hxi p) ≤ top^beta ∧ + ActualSourceTags.searchBin w (lower w top xi (label (zero_lt_one.trans hw) htop hxi p)) ∧ + ∀ q ∈ pre,¬isolatedBin w top xi B alpha beta (label (zero_lt_one.trans hw) htop hxi q) := by + obtain ⟨pre,p,tail,he,hisol,hfirst⟩ := geometric_first_isolated hw htop hxi z ps hp + have hrange := isolated_real_range hw htop hxi hpower hisol + exact ⟨pre,p,tail,he,hrange.1,hrange.2,isolated_bin_search hisol hsearch,hfirst⟩ +end NumberTheoryLean.GeometricWordsAudit + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/GlobalFiniteBranches.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/GlobalFiniteBranches.lean new file mode 100644 index 0000000000000000000000000000000000000000..3526667a30ab9ad7e6d728ee6baf9ce24cdfe965 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/GlobalFiniteBranches.lean @@ -0,0 +1,196 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.FiberCardinalityConstancy + +namespace OAI + +namespace Erdos970 + +section + +open Set +open scoped Topology +namespace ErdosGlobalFiberBranches +open ErdosImplicitCurvature ErdosLocalFiberGraphs + +structure RegularDomain (Q : Bivariate) (x L U : ℝ) (I : Set ℝ) : Prop where + isOpen : IsOpen I + isPreconnected : IsPreconnected I + base_mem : x ∈ I + regular : I ⊆ regularParameters Q L U + +namespace RegularDomain +variable {Q : Bivariate} {x L U : ℝ} {I : Set ℝ} (d : RegularDomain Q x L U I) +include d + +theorem fiber_finite {t : ℝ} (ht : t ∈ I) : (boundedFiber Q t L U).Finite := + boundedFiber_finite Q t L U L (d.regular ht).1 + +noncomputable def transport (t : ℝ) (ht : t ∈ I) : + boundedFiber Q x L U ≃o boundedFiber Q t L U := by + letI := (d.fiber_finite d.base_mem).fintype + letI := (d.fiber_finite ht).fintype + exact orderIsoOfNatCardEq _ _ (fiber_card_eq_on_preconnected Q L U I + d.isPreconnected d.regular d.base_mem ht) + +noncomputable def branch (r : boundedFiber Q x L U) (t : ℝ) : ℝ := by + classical + exact if ht : t ∈ I then (d.transport t ht r : ℝ) else r + +theorem branch_eq_transport (r : boundedFiber Q x L U) {t : ℝ} (ht : t ∈ I) : + d.branch r t = (d.transport t ht r : ℝ) := by simp only [branch,dite_eq_left ht] + +theorem transport_base : d.transport x d.base_mem = OrderIso.refl (boundedFiber Q x L U) := by + let := (d.fiber_finite d.base_mem).fintype + exact finite_orderIso_unique _ _ + +theorem branch_base (r : boundedFiber Q x L U) : d.branch r x = r := by + rw [d.branch_eq_transport r d.base_mem,d.transport_base] + rfl + +theorem branch_mem (r : boundedFiber Q x L U) {t : ℝ} (ht : t ∈ I) : + d.branch r t ∈ boundedFiber Q t L U := by + rw [d.branch_eq_transport r ht] + exact (d.transport t ht r).property + +theorem branch_ordered {t : ℝ} (ht : t ∈ I) : StrictMono (fun r => d.branch r t) := by + intro r s hrs + change d.branch r t < d.branch s t + rw [d.branch_eq_transport r ht,d.branch_eq_transport s ht] + exact (d.transport t ht).strictMono hrs + +theorem branch_coverage {t : ℝ} (ht : t ∈ I) : + boundedFiber Q t L U = range (fun r => d.branch r t) := by + ext y + constructor + · intro hy + obtain ⟨r,hr⟩ := (d.transport t ht).surjective ⟨y,hy⟩ + refine ⟨r,?_⟩ + change d.branch r t = y + rw [d.branch_eq_transport r ht] + exact congrArg Subtype.val hr + · rintro ⟨r,rfl⟩ + exact d.branch_mem r ht + +theorem branch_interior (r : boundedFiber Q x L U) {t : ℝ} (ht : t ∈ I) : + d.branch r t ∈ Ioo L U := + boundedFiber_interior Q t L U (d.regular ht).1 (d.regular ht).2.1 (d.branch_mem r ht) + +end RegularDomain + +end ErdosGlobalFiberBranches + +end + +section + +open Set Filter +open scoped Topology ContDiff +namespace ErdosGlobalFiberBranches +open ErdosImplicitCurvature ErdosLocalFiberGraphs +namespace RegularDomain +variable {Q : Bivariate} {x L U : ℝ} {I : Set ℝ} (d : RegularDomain Q x L U I) + +theorem transport_chart {t s : ℝ} (ht : t ∈ I) (hs : s ∈ I) + (c : FiberCharts Q t L U) (hsc : s ∈ Ioo c.a c.b) : + d.transport s hs = (d.transport t ht).trans (chartOrderIso c s hsc) := by + let := (d.fiber_finite d.base_mem).fintype + exact finite_orderIso_unique _ _ + +theorem branch_eq_chart (r : boundedFiber Q x L U) {t s : ℝ} + (ht : t ∈ I) (hs : s ∈ I) (c : FiberCharts Q t L U) (hsc : s ∈ Ioo c.a c.b) : + d.branch r s = c.graph (d.transport t ht r) s := by + rw [d.branch_eq_transport r hs,d.transport_chart ht hs c hsc] + exact chartOrderIso_val c s hsc (d.transport t ht r) + +theorem branch_smooth (r : boundedFiber Q x L U) : ContDiffOn ℝ 2 (d.branch r) I := by + apply d.isOpen.contDiffOn_iff.mpr + intro t ht + obtain ⟨c⟩ := exists_bounded_fiber_charts Q t L U + (d.regular ht).1 (d.regular ht).2.1 (d.regular ht).2.2 + have hc : ContDiffAt ℝ 2 (c.graph (d.transport t ht r)) t := + (c.graph_smooth _).contDiffAt (isOpen_Ioo.mem_nhds ⟨c.left,c.right⟩) + apply hc.congr_of_eventuallyEq + filter_upwards [d.isOpen.mem_nhds ht,isOpen_Ioo.mem_nhds ⟨c.left,c.right⟩] with s hsI hsC + exact d.branch_eq_chart r ht hsI c hsC + +theorem branch_derivatives (r : boundedFiber Q x L U) {t : ℝ} (ht : t ∈ I) : + deriv (d.branch r) t = + -peval (partialX Q) t (d.branch r t)/peval (partialY Q) t (d.branch r t) ∧ + deriv (deriv (d.branch r)) t = + -peval (inflectionPolynomial Q) t (d.branch r t)/(peval (partialY Q) t (d.branch r t))^3 := + implicit_derivatives Q (d.branch r) d.isOpen (d.branch_smooth r) + (fun _ hs => (d.branch_mem r hs).2) ht ((d.regular ht).2.2 _ (d.branch_mem r ht)) + +end RegularDomain + +end ErdosGlobalFiberBranches + +end + +section + +open Set +open scoped Topology ContDiff +namespace ErdosGlobalFiberBranches +open ErdosImplicitCurvature ErdosLocalFiberGraphs + +theorem global_finite_ordered_branches (Q : Bivariate) (x L U : ℝ) (I : Set ℝ) + (hopen : IsOpen I) (hconn : IsPreconnected I) (hx : x ∈ I) + (hregular : I ⊆ regularParameters Q L U) : + ∃ n : ℕ, n = (boundedFiber Q x L U).ncard ∧ n ≤ Q.totalDegree ∧ + ∃ f : Fin n → ℝ → ℝ, + (∀ i, ContDiffOn ℝ 2 (f i) I) ∧ + (∀ t ∈ I, StrictMono (fun i => f i t)) ∧ + (∀ i, ∀ t ∈ I, f i t ∈ Ioo L U ∧ peval Q t (f i t) = 0 ∧ + peval (partialY Q) t (f i t) ≠ 0) ∧ + (∀ t ∈ I, boundedFiber Q t L U = range (fun i => f i t)) := by + classical + let d : RegularDomain Q x L U I := ⟨hopen,hconn,hx,hregular⟩ + let := (d.fiber_finite hx).fintype + let n := (boundedFiber Q x L U).ncard + let e : Fin n ≃o boundedFiber Q x L U := + Fintype.orderIsoFinOfCardEq _ (fintypeCard_eq_ncard _) + refine ⟨n,rfl,boundedFiber_card_le_degree Q x L U L (hregular hx).1, + (fun i => d.branch (e i)),(fun i => d.branch_smooth (e i)),?_,?_,?_⟩ + · exact fun t ht => (d.branch_ordered ht).comp e.strictMono + · intro i t ht + exact ⟨d.branch_interior (e i) ht,(d.branch_mem (e i) ht).2, + (hregular ht).2.2 _ (d.branch_mem (e i) ht)⟩ + · intro t ht + rw [d.branch_coverage ht] + ext y + constructor + · rintro ⟨r,hr⟩ + obtain ⟨i,rfl⟩ := e.surjective r + exact ⟨i,hr⟩ + · rintro ⟨i,hi⟩ + exact ⟨e i,hi⟩ + +theorem global_branches_on_regular_domain (Q : Bivariate) (L U : ℝ) (I : Set ℝ) + (hopen : IsOpen I) (hconn : IsPreconnected I) + (hregular : I ⊆ regularParameters Q L U) : + ∃ n ≤ Q.totalDegree, ∃ f : Fin n → ℝ → ℝ, + (∀ i, ContDiffOn ℝ 2 (f i) I) ∧ + (∀ t ∈ I, StrictMono (fun i => f i t)) ∧ + (∀ i, ∀ t ∈ I, f i t ∈ Ioo L U ∧ peval Q t (f i t) = 0 ∧ + peval (partialY Q) t (f i t) ≠ 0) ∧ + (∀ t ∈ I, boundedFiber Q t L U = range (fun i => f i t)) := by + classical + by_cases hI : I.Nonempty + · obtain ⟨x,hx⟩ := hI + obtain ⟨n,_,hn,f,hf⟩ := global_finite_ordered_branches Q x L U I hopen hconn hx hregular + exact ⟨n,hn,f,hf⟩ + · have hempty : I = ∅ := not_nonempty_iff_eq_empty.mp hI + subst I + refine ⟨0,Nat.zero_le _,Fin.elim0,?_,?_,?_,?_⟩ + · exact fun i => Fin.elim0 i + · simp + · simp + · simp + +end ErdosGlobalFiberBranches + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/HighPrefixBounds.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/HighPrefixBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..e045a0dbb88c7feaaabeb4e74637507c634ba903 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/HighPrefixBounds.lean @@ -0,0 +1,112 @@ +import OAI.NumberTheory.Jacobsthal.Probability.HighPrefixKernel + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosPrimeInputs.HighPrefixBounds + +open Set Filter MeasureTheory ProbabilityTheory +open scoped ENNReal +open WeightedKernelMass HarmonicLongPrefixes HighPrefixState +open HighPrefixKernel + +noncomputable def lowHighMass (ell S B R K : ℝ) : ℝ≥0∞ := + ∑' n : ℕ, (kernel ell S ^ n) (initial S B R) {z | z.2.2=true ∧ z.2.1≤K} + +noncomputable def reward (c : ℝ) (z : State) : ℝ≥0∞ := + if z.2.2=true ∧ 0≤z.2.1 then ENNReal.ofReal (Real.exp (-c*z.2.1)) else 0 + +lemma reward_measurable (c : ℝ) : Measurable (reward c) := by + have hf : Measurable (fun z : State => z.2.2) := measurable_snd.comp measurable_snd + have hr : Measurable (fun z : State => z.2.1) := measurable_fst.comp measurable_snd + have hs : MeasurableSet {z : State | z.2.2=true ∧ 0≤z.2.1} := by + have hz : MeasurableSet {z : State | (0:ℝ)≤z.2.1} := measurableSet_le measurable_const hr + exact (hf (measurableSet_singleton true)).inter hz + exact Measurable.ite hs (ENNReal.measurable_ofReal.comp + (Real.measurable_exp.comp (measurable_const.mul hr))) measurable_const + +noncomputable def rewardedHighMass (ell S B R c : ℝ) : ℝ≥0∞ := + ∑' n : ℕ, ∫⁻ z, reward c z ∂(kernel ell S ^ n) (initial S B R) + +lemma reward_le_one {c : ℝ} (hc : 0≤c) (z : State) : reward c z ≤ 1 := by + unfold reward + split_ifs with hz + · calc + _ ≤ ENNReal.ofReal 1 := ENNReal.ofReal_le_ofReal (Real.exp_le_one_iff.mpr (by nlinarith [hz.2])) + _ = 1 := by simp + · exact zero_le + +lemma low_high_zero {ell S B R K : ℝ} (hell : 0 mass (kernel ell S) n (initial S B R)) m := by + apply ENNReal.tsum_le_tsum + intro n + by_cases hn : m≤n + · rw [ite_eq_left hn] + exact measure_mono (subset_univ _) + · rw [ite_eq_right hn,low_high_zero hell hB n m hm (Nat.lt_of_not_ge hn) hK] + exact htail.trans (weighted_tail_bound _ m (weighted_mass hell hB S R)) + +lemma short_reward_bound {ell S B R c : ℝ} (hell : 0 mass (kernel ell S) n (initial S B R) + let E := ENNReal.ofReal (Real.exp (-c*(S*ell/2))) + have hp : ∀ n : ℕ, (∫⁻ z, reward c z ∂(kernel ell S ^ n) (initial S B R)) ≤ + (if m≤n then a n else 0) + E*a n := by + intro n + by_cases hn : m≤n + · rw [ite_eq_left hn] + have hle : (∫⁻ z, reward c z ∂(kernel ell S ^ n) (initial S B R)) ≤ a n := by + simpa only [lintegral_const,one_mul,a,mass] using! lintegral_mono (fun z => reward_le_one hc z) + exact hle.trans (le_add_of_nonneg_right zero_le) + · rw [ite_eq_right hn,zero_add] + exact short_reward_bound hell hB hc n m hm (Nat.lt_of_not_ge hn) + calc + _ ≤ ∑' n : ℕ, ((if m≤n then a n else 0) + E*a n) := ENNReal.tsum_le_tsum hp + _ = tailMass a m + E*(∑' n : ℕ, a n) := by rw [ENNReal.tsum_add,ENNReal.tsum_mul_left]; rfl + _ ≤ _ := add_le_add (weighted_tail_bound _ m (weighted_mass hell hB S R)) + (mul_le_mul le_rfl (total_mass hell hB S R) zero_le zero_le) + +end ErdosPrimeInputs.HighPrefixBounds + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/HighPrefixState.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/HighPrefixState.lean new file mode 100644 index 0000000000000000000000000000000000000000..7be57768e15821ab87833de237ca06e0dae56a72 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/HighPrefixState.lean @@ -0,0 +1,218 @@ +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 z)).map pathPairEval = fullPairTraceKernel z := by + apply Measure.ext_of_lintegral + intro F hF + let G : (ℕ → CostState) → ℝ≥0∞ := fun x => F (x 1,x 2) + have hG : Measurable G := hF.comp ((measurable_pi_apply 1).prodMk (measurable_pi_apply 2)) + have he : (∫⁻ h, F (pathPairEval h) ∂finitePathKernel 2 (fun _ => z)) = + Kernel.lmarginalPartialTraj historyKernel 0 2 G (fun _ => z) := by + unfold Kernel.lmarginalPartialTraj finitePathKernel + apply lintegral_congr + intro h + simp [G,pathPairEval,Function.updateFinset] + rw [lintegral_map hF pathPairEval_measurable,he] + have hc := congrFun (Kernel.lmarginalPartialTraj_self (κ := historyKernel) + (show (0:ℕ) ≤ 1 by decide) (show (1:ℕ) ≤ 2 by decide) hG) (fun _ => z) + rw [← hc,Kernel.lmarginalPartialTraj_succ 0 + (Kernel.measurable_lmarginalPartialTraj 1 2 hG)] + have hi (t : CostState) : Kernel.lmarginalPartialTraj historyKernel 1 2 G + (Function.update (fun _ => z) 1 t) = ∫⁻ u, F (t,u) ∂costKernel t := by + rw [Kernel.lmarginalPartialTraj_succ 1 hG] + simp [G,historyKernel,Kernel.comap_apply,frestrictLe,Function.update] + simp_rw [hi] + rw [fullPairTraceKernel,Kernel.lintegral_compProd _ _ _ hF] + rfl + +theorem sourcePair_canonical_history (z : OddCost) : + (pairWitnessKernel z).map (pairTraceOfWitness z) = + ((finitePathKernel 2) (fun _ => embedOdd z)).map pathPairEval := by + rw [pairWitness_joint_full_trace,finitePath_two_trace] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory Function Preorder +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping + +noncomputable def nextPairEval (n : ℕ) (h : ∀ _ : Finset.Iic (n+2), CostState) : CostState × CostState := + (h ⟨n+1,by simp⟩,h ⟨n+2,by simp⟩) + +lemma nextPairEval_measurable (n : ℕ) : Measurable (nextPairEval n) := + (measurable_pi_apply (⟨n+1,by simp⟩ : Finset.Iic (n+2))).prodMk + (measurable_pi_apply (⟨n+2,by simp⟩ : Finset.Iic (n+2))) + +lemma conditional_pair_trace_extension (n : ℕ) (x0 : ℕ → CostState) : + ((Kernel.partialTraj (X := fun _ => CostState) historyKernel n (n+2)) (frestrictLe n x0)).map (nextPairEval n) = + fullPairTraceKernel (x0 n) := by + apply Measure.ext_of_lintegral + intro F hF + let G : (ℕ → CostState) → ℝ≥0∞ := fun x => F (x (n+1),x (n+2)) + have hG : Measurable G := hF.comp ((measurable_pi_apply (n+1)).prodMk (measurable_pi_apply (n+2))) + have he : (∫⁻ h, F (nextPairEval n h) ∂Kernel.partialTraj (X := fun _ => CostState) historyKernel n (n+2) (frestrictLe n x0)) = + Kernel.lmarginalPartialTraj historyKernel n (n+2) G x0 := by + unfold Kernel.lmarginalPartialTraj + apply lintegral_congr + intro h + simp [G,nextPairEval,Function.updateFinset] + rw [lintegral_map hF (nextPairEval_measurable n),he] + have hc := congrFun (Kernel.lmarginalPartialTraj_self (κ := historyKernel) + (show n ≤ n+1 by omega) (show n+1 ≤ n+2 by omega) hG) x0 + rw [← hc,Kernel.lmarginalPartialTraj_succ n + (Kernel.measurable_lmarginalPartialTraj (n+1) (n+2) hG)] + have hi (t : CostState) : Kernel.lmarginalPartialTraj historyKernel (n+1) (n+2) G + (Function.update x0 (n+1) t) = ∫⁻ u, F (t,u) ∂costKernel t := by + rw [Kernel.lmarginalPartialTraj_succ (n+1) hG] + simp [G,historyKernel,Kernel.comap_apply,frestrictLe,Function.update] + simp_rw [hi] + rw [fullPairTraceKernel,Kernel.lintegral_compProd _ _ _ hF] + rfl + +theorem conditional_pair_trace (n : ℕ) (h : ∀ _ : Finset.Iic n, CostState) : + ((Kernel.partialTraj (X := fun _ => CostState) historyKernel n (n+2)) h).map (nextPairEval n) = + fullPairTraceKernel (h ⟨n,by simp⟩) := by + let x0 : ℕ → CostState := fun i => if hi : i ≤ n then h ⟨i,Finset.mem_Iic.mpr hi⟩ else h ⟨n,by simp⟩ + have he : frestrictLe n x0 = h := by + funext i + simp only [frestrictLe_apply,x0,dite_eq_left (Finset.mem_Iic.mp i.2)] + have hn : x0 n = h ⟨n,by simp⟩ := by simp [x0] + simpa only [he,hn] using conditional_pair_trace_extension n x0 + +theorem sourcePair_after_history (n : ℕ) (h : ∀ _ : Finset.Iic n, CostState) + (z : OddCost) (hz : h ⟨n,by simp⟩ = embedOdd z) : + ((Kernel.partialTraj (X := fun _ => CostState) historyKernel n (n+2)) h).map (nextPairEval n) = + (pairWitnessKernel z).map (pairTraceOfWitness z) := by + rw [conditional_pair_trace,hz,pairWitness_joint_full_trace] + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory Function Preorder +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures + +lemma restriction_comp_of_retained_prefix {α β γ : Type*} + [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] + (K : Kernel α β) (L : Kernel β γ) {r : γ → β} (hr : Measurable r) + (hPast : ∀ y, ∀ᵐ z ∂L y, r z=y) {B : Set β} {C : Set γ} + (hB : MeasurableSet B) (hC : MeasurableSet C) : + (L ∘ₖ K).restrict ((hr hB).inter hC) = (L.restrict hC) ∘ₖ (K.restrict hB) := by + ext x S hS + rw [Kernel.restrict_apply' _ _ _ hS,Kernel.comp_apply' _ _ _ (hS.inter ((hr hB).inter hC)), + Kernel.comp_apply' _ _ _ hS,Kernel.restrict_apply] + simp_rw [Kernel.restrict_apply' _ _ _ hS] + rw [← lintegral_indicator hB] + apply lintegral_congr + intro y + by_cases hy : y ∈ B + · rw [indicator_of_mem hy] + apply measure_congr + filter_upwards [hPast y] with z hz + apply propext + change (z ∈ S ∧ (r z ∈ B ∧ z ∈ C)) ↔ (z ∈ S ∧ z ∈ C) + simp only [hz,hy,true_and] + · rw [indicator_of_notMem hy] + calc + _ = L y ∅ := by + apply measure_congr + filter_upwards [hPast y] with z hz + apply propext + change (z ∈ S ∧ (r z ∈ B ∧ z ∈ C)) ↔ False + simp only [hz,hy,false_and,and_false] + _ = 0 := measure_empty + +abbrev RawHistory (n : ℕ) := ∀ _ : Finset.Iic n, CostState + +def rawPrefix {a b : ℕ} (hab : a ≤ b) : RawHistory b → RawHistory a := + frestrictLe₂ (π := fun _ => CostState) hab + +lemma rawPrefix_measurable {a b : ℕ} (hab : a ≤ b) : Measurable (rawPrefix hab) := + measurable_frestrictLe₂ (X := fun _ => CostState) hab + +noncomputable def rawExtension (a b : ℕ) : Kernel (RawHistory a) (RawHistory b) := + Kernel.partialTraj (X := fun _ => CostState) historyKernel a b + +instance rawExtension_isMarkovKernel (a b : ℕ) : IsMarkovKernel (rawExtension a b) := by + unfold rawExtension + infer_instance + +local instance : MeasurableSingletonClass State := by + constructor + intro x + cases x with + | inl e => + simpa only [image_singleton] using ((measurableSet_singleton e).inl_image : + MeasurableSet (Sum.inl '' {e} : Set State)) + | inr o => + simpa only [image_singleton] using ((measurableSet_singleton o).inr_image : + MeasurableSet (Sum.inr '' {o} : Set State)) + +lemma rawExtension_retains_prefix {b c : ℕ} (hbc : b ≤ c) (h : RawHistory b) : + ∀ᵐ z ∂rawExtension b c h, rawPrefix hbc z = h := by + have he : (rawExtension b c h).map (rawPrefix hbc) = Measure.dirac h := by + rw [rawExtension,rawPrefix,Kernel.partialTraj_map_frestrictLe₂_apply (X := fun _ => CostState) (κ := historyKernel) h hbc,Kernel.partialTraj_self,Kernel.id_apply] + have hd : ∀ᵐ y ∂(rawExtension b c h).map (rawPrefix hbc), y=h := by + rw [he] + exact ae_eq_dirac' measurable_id + exact (ae_map_iff (rawPrefix_measurable hbc).aemeasurable (measurableSet_singleton h)).mp hd + +theorem rawExtension_restrict_comp {a b c : ℕ} (hab : a ≤ b) (hbc : b ≤ c) + {B : Set (RawHistory b)} {C : Set (RawHistory c)} + (hB : MeasurableSet B) (hC : MeasurableSet C) : + (rawExtension a c).restrict (((rawPrefix_measurable hbc) hB).inter hC) = + ((rawExtension b c).restrict hC) ∘ₖ ((rawExtension a b).restrict hB) := by + rw [← restriction_comp_of_retained_prefix _ _ (rawPrefix_measurable hbc) + (rawExtension_retains_prefix hbc) hB hC] + have he : rawExtension b c ∘ₖ rawExtension a b = rawExtension a c := + Kernel.partialTraj_comp_partialTraj hab hbc + rw [he] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/MovingStopBandParameters.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/MovingStopBandParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..99deecb030375a9b52093171a3c4098dcd40af03 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/MovingStopBandParameters.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CandidateLengthBand + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.MovingStopBandParameters +open _root_.Filter FinitePathGeometry PrimeHistories SourceStopPredicate SourceStopWindow +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open MarkedPrefixTools MarkedSourceSmallness ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem moving_stop_band_conditions (Clen xi : ℝ) (hxi : 0 ≤ xi) {K : ℝ} (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop,1 < w ∧ 1 ≤ Real.log w ∧ 401 ≤ K*(Real.log w)^2 ∧ + 2*Clen*xi+(218/100)*(xi/Real.log w) ≤ (2/100)*(K*(Real.log w)^2) ∧ + xi/Real.log w ≤ (K*(Real.log w)^2)/2 := by + let M := max 401 (max (2*xi) (50*(2*Clen*xi+(218/100)*xi)+1)) + filter_upwards [moving_compact_gap_small (6*M) hK, + Real.tendsto_log_atTop.eventually_ge_atTop 1,eventually_gt_atTop (1:ℝ)] with w hm hlog hw + have hb : M < K*(Real.log w)^2 := by linarith + have h₁ : (401:ℝ) ≤ M := le_max_left _ _ + have h₂ : 2*xi ≤ M := (le_max_left _ _).trans (le_max_right _ _) + have h₃ : 50*(2*Clen*xi+(218/100)*xi)+1 ≤ M := (le_max_right _ _).trans (le_max_right _ _) + have hd := div_le_self hxi hlog + exact ⟨hw,hlog,by linarith,by linarith,by linarith⟩ + +theorem last_prime_cutoff_power {w : ℝ} (hw : 1 < w) (z : Node) (ps : List ℕ) + (hne : ps ≠ []) (hP : 0 < (ps.getLastD 0:ℝ)) : + w^(terminal w z ps).cutoff=(ps.getLastD 0:ℝ) := by + rw [Real.rpow_def_of_pos (zero_lt_one.trans hw),terminal_lastD w z ps hne,primeExponent] + have he : Real.log w*(Real.log (ps.getLastD 0:ℝ)/Real.log w)=Real.log (ps.getLastD 0:ℝ) := by + field_simp [(Real.log_pos hw).ne'] + rw [he,Real.exp_log hP] + +theorem candidate_moving_last_prime_lower (Y : ℕ) {w top Cs eta Clen B xi K b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) + (hsmall : 2*Clen*xi+(218/100)*(xi/Real.log w) ≤ (2/100)*(K*(Real.log w)^2)) + (hhalf : xi/Real.log w ≤ (K*(Real.log w)^2)/2) + (residue : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hc : stopCandidate Y w Cs eta Clen B xi (K*(Real.log w)^2) b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) residue z ps) : + Real.exp ((K/2)*(Real.log w)^3) ≤ (ps.getLastD 0:ℝ) ∧ + w^(terminal w z ps).cutoff=(ps.getLastD 0:ℝ) := by + have hwindow := candidate_actual_window Y hw htop hxi hC hcomp hsmall residue z ps hc + have hsource := candidate_source_primes Y hw htop hxi residue z ps hc + have hlast : ps.getLastD 0 ∈ ps := by + have he : ps.getLastD 0=ps.getLast hc.1 := by + conv_lhs => rw [← List.dropLast_append_getLast hc.1] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hc.1 + have hprime := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop _).mp (hsource _ hlast) + have hP : 0 < (ps.getLastD 0:ℝ) := by exact_mod_cast hprime.1.pos + refine ⟨?_,last_prime_cutoff_power hw z ps hc.1 hP⟩ + have hcut : (K*(Real.log w)^2)/2 ≤ (terminal w z ps).cutoff := by linarith [hwindow.1] + have hlogP : Real.log (ps.getLastD 0:ℝ)=(terminal w z ps).cutoff*Real.log w := by + rw [terminal_lastD w z ps hc.1,primeExponent,div_mul_cancel₀ _ (Real.log_pos hw).ne'] + rw [← Real.exp_log hP] + apply Real.exp_le_exp.mpr + calc + _ = ((K*(Real.log w)^2)/2)*Real.log w := by ring + _ ≤ (terminal w z ps).cutoff*Real.log w := mul_le_mul_of_nonneg_right hcut (Real.log_pos hw).le + _ = _ := hlogP.symm +end NumberTheoryLean.MovingStopBandParameters + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/MovingStopMargins.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/MovingStopMargins.lean new file mode 100644 index 0000000000000000000000000000000000000000..f4f70a41535ea54c4b9cae2c141660037a0a19b1 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/MovingStopMargins.lean @@ -0,0 +1,471 @@ +import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics +import OAI.NumberTheory.Jacobsthal.Sieve.LastPrimeModulusCount + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ActualSourceStopBinding + +open _root_.Finset +open FinitePathGeometry PrimeHistories SourceStopPredicate StoppedCountVertex StoppedEvaluation +open StoppedVertexHistory StoppedTraceSets StoppedCountAdapters StoppedModulusCount FlatStoppedIdentity +open ReferenceAdmission ReferencePruning ErdosInverseCounts +attribute [local instance] Classical.propDecidable + +theorem actual_source_stops_first {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ mu : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) (P : Finset ℕ) + {ps : List ℕ} + (hp : ps ∈ stopped w (stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) + P.card (rootVertex z ∅ P mu)) : + (terminal w z ps).side = .even ∧ + stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z ps ∧ + ∀ pre tail : List ℕ,ps = pre++tail → tail ≠ [] → + ¬((terminal w z pre).side = .even ∧ + stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z pre) := by + have h := FirstStopSemantics.stopped_first w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) P.card (rootVertex z ∅ P mu) hp + simpa only [FirstStopSemantics.FirstStop,lowerStop,after_node,after_past,rootVertex,List.nil_append,and_assoc] using h + +theorem actual_source_stopped_lower {n : ℕ} (Y : ℕ) (small P : Finset ℕ) + (w Cs eta Clen B xi b₀ b₁ mu : ℝ) (lower width : Fin n → ℝ) (label : ℕ → Fin n) + (a : ℕ → ℕ) (z : Node) (hi : z.side = .even) : + stoppedCount w Y small a (stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) + P.card (rootVertex z ∅ P mu) ≤ (ResidueSieveTree.survivorCount Y small a (∅,P):ℝ) := by + have h := StoppedCountLowerBound.actual_stopped_lower_bound w Y small a + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) (rootVertex z ∅ P mu) hi + simpa only [countSurvivors_eq_tree_survivors,rootVertex] using h + +theorem actual_source_stopped_comparison {n : ℕ} (Y : ℕ) (small P : Finset ℕ) + (w Cs eta Clen B xi b₀ b₁ mu : ℝ) (lower width : Fin n → ℝ) (label : ℕ → Fin n) + (a : ℕ → ℕ) (z : Node) (hi : z.side = .even) (hP : ∀ p ∈ P,Nat.Prime p) : + let stop := stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z + let v := rootVertex z ∅ P mu + stoppedCount w Y small a stop P.card v-mu*referencePolynomial w P z.side z.gap = + (∑ ps ∈ expanded w stop P.card v,(-1:ℝ)^ps.length* + ((modulusCount Y small a ps.prod:ℝ)-mu/(ps.prod:ℝ))) + + (∑ ps ∈ stopped w stop P.card v, + ((ResidueSieveTree.survivorCount Y small a (ps.prod.primeFactors,suffixPrimes P ps):ℝ)- + (mu/(ps.prod:ℝ))*referencePolynomial w (suffixPrimes P ps) + (terminal w z ps).side (terminal w z ps).gap)) := by + dsimp only + let stop := stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z + let v := rootVertex z ∅ P mu + change stoppedCount w Y small a stop P.card v-referenceValue w v = _ + rw [literal_stopped_difference w Y small a stop P.card v le_rfl hi] + congr 1 + · apply Finset.sum_congr rfl + intro ps hp + rw [trace_mass_eq_modulusCount w Y small P a z mu stop P.card hP (Or.inl hp),after_scale_product] + rfl + · apply Finset.sum_congr rfl + intro ps hp + rw [trace_survivors_eq_product_node w Y small P a z mu stop P.card hP (Or.inr hp),root_after_reference] + +end NumberTheoryLean.ActualSourceStopBinding + +end + +section + +namespace NumberTheoryLean.FirstStopFreezing +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualSourceTags FiniteFirstTag +open SourceCandidateFreezing RepresentativeTraceInvariance +open StoppedCountVertex StoppedVertexHistory StoppedEvaluation StoppedCountAdapters FirstStopSemantics +open ErdosInversePrimeBin ErdosInverseAlignment + +theorem firstStop_iff_takes (w : ℝ) (stop : List ℕ → Prop) (v : Vertex) (ps : List ℕ) : + FirstStop w stop v ps ↔ lowerStop stop (after w v ps) ∧ + ∀ k < ps.length,¬lowerStop stop (after w v (ps.take k)) := by + constructor + · intro h + refine ⟨h.1,?_⟩ + intro k hk + apply h.2 (ps.take k) (ps.drop k) (List.take_append_drop k ps).symm + intro hz + have hh := congrArg List.length hz + simp only [List.length_drop,List.length_nil] at hh + omega + · rintro ⟨h,hs⟩ + refine ⟨h,?_⟩ + intro pre tail heq htail + have htpos : 0 < tail.length := List.length_pos_iff.mpr htail + have hlen : pre.length < ps.length := by rw [heq,List.length_append]; omega + have hh := hs pre.length hlen + simpa only [heq,List.take_append,List.take_length,Nat.sub_self,List.take_zero,List.append_nil] using hh + +theorem first_source_stop_replacement {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ mu : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) (P : Finset ℕ) + (pre tail : List ℕ) (p p' : ℕ) {t : Tag n} + (ht : sourceTag (Y:ℝ) w Cs eta lower width label (sourceClass a) (pre++p::tail) = some t) + (hc : tagCandidate (Y:ℝ) w Cs eta lower width label (sourceClass a) p = some (t.bin,t.rational)) + (hlabel : label p' = label p) + (hp' : p' ∈ primeBin (lower (label p')) (width (label p'))) + (ha' : aligns (sourceClass a) t.rational p') : + FirstStop w (stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) + (rootVertex z ∅ P mu) (pre++p::tail) ↔ + FirstStop w (stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z) + (rootVertex z ∅ P mu) (pre++p'::tail) := by + let stop := stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z + let v := rootVertex z ∅ P mu + have hlen : (pre++p::tail).length = (pre++p'::tail).length := by simp + have he (k : ℕ) : lowerStop stop (after w v ((pre++p::tail).take k)) ↔ + lowerStop stop (after w v ((pre++p'::tail).take k)) := by + have hside := terminal_side_length w z z ((pre++p::tail).take k) ((pre++p'::tail).take k) rfl + (by simp only [List.length_take,hlen]) + have hh := all_prefix_candidate_replacement Y w Cs eta Clen B xi b₀ b₁ lower width label a z + pre tail p p' ht hc hlabel hp' ha' k + simp only [lowerStop,after_node,after_past,v,rootVertex,List.nil_append,hside] + exact and_congr_right (fun _ => hh) + have hlast := he (pre++p::tail).length + simp only [List.take_length] at hlast + rw [hlen,List.take_length] at hlast + rw [firstStop_iff_takes,firstStop_iff_takes] + change (lowerStop stop (after w v (pre++p::tail)) ∧ _) ↔ + (lowerStop stop (after w v (pre++p'::tail)) ∧ _) + rw [hlast] + apply and_congr_right + intro _ + apply forall_congr' + intro k + rw [hlen,he k] +end NumberTheoryLean.FirstStopFreezing + +end + +section + +namespace NumberTheoryLean.StoppedTraceMembership +open FinitePathGeometry PrimeHistories StoppedCountVertex StoppedVertexHistory StoppedEvaluation +open StoppedTraceSets StoppedTraceAdmission FirstStopSemantics ReferenceAdmission ReferencePruning +open ReferencePrefixRecurrence ErdosPrimeInputs.PrimePrefixMass +attribute [local instance] Classical.propDecidable + +theorem reference_cons_iff (w : ℝ) (v : Vertex) (p : ℕ) (ps : List ℕ) : + p::ps ∈ referencePrefixes w v.available v.node.side v.node.gap ↔ + p ∈ includedPrimes w v ∧ ps ∈ referencePrefixes w (child w v p).available + (child w v p).node.side (child w v p).node.gap := by + constructor + · intro h + obtain ⟨hD,hA⟩ := Finset.mem_filter.mp h + have hp := (mem_decreasingPrefixes.mp hD).2 p (by simp) + have htail := (append_mem_decreasing_iff (singleton_prefix_mem hp)).mp hD + refine ⟨Finset.mem_filter.mpr ⟨hp,hA.1⟩,Finset.mem_filter.mpr ⟨?_,hA.2⟩⟩ + simpa only [suffixPrimes,List.mem_singleton,forall_eq,child] using htail + · rintro ⟨hp,hps⟩ + exact reference_child_cons w v hp hps + +theorem stopped_length (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + {ps : List ℕ} (hp : ps ∈ stopped w stop n v) : ps.length ≤ n := by + induction n generalizing v ps with + | zero => + by_cases hs : lowerStop stop v + · have he : ps=[] := by simpa only [stopped,traces,hs,ite_true,Finset.mem_singleton] using hp + simp [he] + · simp [stopped,traces,hs] at hp + | succ n ih => + by_cases hs : lowerStop stop v + · have he : ps=[] := by simpa only [stopped,traces,hs,ite_true,Finset.mem_singleton] using hp + simp [he] + · simp only [stopped,traces,hs,ite_false] at hp + obtain ⟨p,_hp,hps⟩ := Finset.mem_biUnion.mp hp + obtain ⟨tail,ht,rfl⟩ := Finset.mem_image.mp hps + exact Nat.succ_le_succ (ih (child w v p) ht) + +theorem stopped_of_reference_first (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (ps : List ℕ) (hlen : ps.length ≤ n) + (href : ps ∈ referencePrefixes w v.available v.node.side v.node.gap) + (hf : FirstStop w stop v ps) : ps ∈ stopped w stop n v := by + induction ps generalizing n v with + | nil => + have hs : lowerStop stop v := hf.1 + cases n <;> simp [stopped,traces,hs] + | cons p ps ih => + obtain ⟨hp,ht⟩ := (reference_cons_iff w v p ps).mp href + have hroot : ¬lowerStop stop v := hf.2 [] (p::ps) rfl (by simp) + have hfirst : FirstStop w stop (child w v p) ps := by + refine ⟨hf.1,?_⟩ + intro pre tail heq htail + exact hf.2 (p::pre) tail (by simp only [List.cons_append,heq]) htail + cases n with + | zero => simp at hlen + | succ n => + have hh := ih n (child w v p) (by simpa using hlen) ht hfirst + simp only [stopped,traces,hroot,ite_false] + exact Finset.mem_biUnion.mpr ⟨p,hp,Finset.mem_image.mpr ⟨ps,hh,rfl⟩⟩ + +theorem stopped_iff_reference_first (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) + (ps : List ℕ) : ps ∈ stopped w stop n v ↔ ps.length ≤ n ∧ + ps ∈ referencePrefixes w v.available v.node.side v.node.gap ∧ FirstStop w stop v ps := by + exact ⟨fun h => ⟨stopped_length w stop n v h, + trace_reference_member w stop n v (Or.inr h),stopped_first w stop n v h⟩, + fun h => stopped_of_reference_first w stop n v ps h.1 h.2.1 h.2.2⟩ +end NumberTheoryLean.StoppedTraceMembership + +end + +section + +namespace NumberTheoryLean.TagBelowStopWindow +open _root_.Filter FinitePathGeometry PrimeHistories SourceStopPredicate ActualSourceTags FiniteFirstTag +open PrimeBinRepresentatives ErdosInversePrimeBin ErdosInverseAlignment + +theorem source_tag_nonterminal {n : ℕ} (Y : ℕ) (w Cs eta Clen B xi b₀ b₁ : ℝ) + (lower width : Fin n → ℝ) (label : ℕ → Fin n) (a : ℕ → ℕ) (z : Node) + (pre tail : List ℕ) (p : ℕ) {t : Tag n} + (hw : 1 < w) (hlo : ∀ b,0 < lower b) (hwidth : ∀ b,0 ≤ width b) + (hwindow : b₁ < w^((1/4:ℝ))) + (hc : tagCandidate (Y:ℝ) w Cs eta lower width label (sourceClass a) p = some (t.bin,t.rational)) + (hs : stopCandidate Y w Cs eta Clen B xi b₀ b₁ lower width label a z (pre++p::tail)) : + tail ≠ [] := by + intro ht + subst tail + have hh := candidate_witness (Y:ℝ) w Cs eta lower width label (sourceClass a) p hc + have hb := bin_exponent_bounds hw (hlo (label p)) (hwidth (label p)) hh.2.1 + have hr : representative w lower width label p ≤ b₁ := by + have hx := hs.2.2.2.2.1.2.1 + simpa only [List.getLastD_concat] using hx + have hsearch := hh.2.2.1 + change w^((1/4:ℝ)) ≤ leftExponent w (lower (label p)) at hsearch + change rightExponent w (lower (label p)) (width (label p)) ≤ b₁ at hr + linarith + +theorem moving_window_below_search (rho K : ℝ) (hrho : 0 < rho) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop,rho*K*(Real.log w)^2 < w^((1/4:ℝ)) := by + have hC : 0 < rho*K := mul_pos hrho hK + have hh := (isLittleO_log_rpow_rpow_atTop (s := (1/4:ℝ)) 2 (by norm_num)).bound + (by positivity : (0:ℝ)<1/(2*(rho*K))) + filter_upwards [hh,eventually_gt_atTop (0:ℝ)] with w hw hw0 + have hp : 0 < w^((1/4:ℝ)) := Real.rpow_pos_of_pos hw0 _ + rw [Real.rpow_two,Real.norm_eq_abs,Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _),abs_of_pos hp] at hw + have hm := mul_le_mul_of_nonneg_left hw hC.le + have he : (rho*K)*(1/(2*(rho*K))*w^((1/4:ℝ))) = w^((1/4:ℝ))/2 := by field_simp + rw [he] at hm + exact hm.trans_lt (by linarith) + +theorem replacement_product (pre tail : List ℕ) (p : ℕ) : + (pre++p::tail).prod=p*(pre.prod*tail.prod) := by + rw [List.prod_append,List.prod_cons] + ac_rfl + +theorem replacement_last_and_scale (w : ℝ) (v : StoppedCountVertex.Vertex) + (pre middle : List ℕ) (p u : ℕ) : + (pre++p::(middle++[u])).getLastD 0=u ∧ + (StoppedVertexHistory.after w v (pre++p::(middle++[u]))).scale = + v.scale/((p:ℝ)*(pre.prod*(middle++[u]).prod:ℕ)) := by + constructor + · simpa only [List.cons_append,List.append_assoc] using + (show ((pre++p::middle)++[u]).getLastD 0=u from List.getLastD_concat) + · rw [StoppedVertexHistory.after_scale_product,replacement_product,Nat.cast_mul] +end NumberTheoryLean.TagBelowStopWindow + +end + +section + +namespace NumberTheoryLean.StoppedPrefixExistence +open StoppedCountVertex StoppedVertexHistory StoppedEvaluation StoppedTraceSets StoppedTraceMembership +open ReferenceAdmission ErdosPrimeInputs.PrimePrefixMass +attribute [local instance] Classical.propDecidable + +theorem reference_length_le_card (w : ℝ) (v : Vertex) (ps : List ℕ) + (hp : ps ∈ referencePrefixes w v.available v.node.side v.node.gap) : ps.length ≤ v.available.card := by + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hp).1 + have hn : ps.Nodup := hd.1.imp (fun h => ne_of_gt h) + have hsub : ps.toFinset ⊆ v.available := fun p hp => hd.2 p (List.mem_toFinset.mp hp) + have hh := Finset.card_le_card hsub + simpa only [List.toFinset_card_of_nodup hn] using hh + +theorem exists_stopped_prefix (w : ℝ) (stop : List ℕ → Prop) (n : ℕ) (v : Vertex) (ps : List ℕ) + (hlen : ps.length ≤ n) (href : ps ∈ referencePrefixes w v.available v.node.side v.node.gap) + (hhit : ∃ pre tail : List ℕ,ps=pre++tail ∧ lowerStop stop (after w v pre)) : + ∃ pre tail : List ℕ,ps=pre++tail ∧ pre ∈ stopped w stop n v := by + induction ps generalizing n v with + | nil => + obtain ⟨pre,tail,heq,hs⟩ := hhit + have hp : pre=[] := (List.append_eq_nil_iff.mp heq.symm).1 + subst pre + refine ⟨[],[],rfl,?_⟩ + cases n <;> simp [stopped,traces,show lowerStop stop v from hs] + | cons p ps ih => + by_cases hs : lowerStop stop v + · refine ⟨[],p::ps,rfl,?_⟩ + cases n <;> simp [stopped,traces,hs] + · obtain ⟨hp,htail⟩ := (reference_cons_iff w v p ps).mp href + have hchildHit : ∃ pre tail : List ℕ,ps=pre++tail ∧ lowerStop stop (after w (child w v p) pre) := by + obtain ⟨pre,tail,heq,hstop⟩ := hhit + cases pre with + | nil => exact False.elim (hs hstop) + | cons q pre => + rw [List.cons_append] at heq + have he := List.cons.inj heq + have hehead := he.1 + subst q + exact ⟨pre,tail,he.2,hstop⟩ + cases n with + | zero => simp at hlen + | succ n => + obtain ⟨pre,tail,heq,hpre⟩ := ih n (child w v p) (by simpa using hlen) htail hchildHit + refine ⟨p::pre,tail,by simp only [List.cons_append,heq],?_⟩ + simp only [stopped,traces,hs,ite_false] + exact Finset.mem_biUnion.mpr ⟨p,hp,Finset.mem_image.mpr ⟨pre,hpre,rfl⟩⟩ + +theorem reference_candidate_forces_stop (w : ℝ) (stop : List ℕ → Prop) (v : Vertex) (ps : List ℕ) + (href : ps ∈ referencePrefixes w v.available v.node.side v.node.gap) + (hhit : ∃ pre tail : List ℕ,ps=pre++tail ∧ lowerStop stop (after w v pre)) : + ∃ pre tail : List ℕ,ps=pre++tail ∧ pre ∈ stopped w stop v.available.card v := + exists_stopped_prefix w stop v.available.card v ps (reference_length_le_card w v ps href) href hhit +end NumberTheoryLean.StoppedPrefixExistence + +end + +section + +namespace NumberTheoryLean.ActualFrozenStopFamily +open FinitePathGeometry PrimeHistories SourceStopPredicate ActualSourceTags FiniteFirstTag +open StoppedCountVertex StoppedVertexHistory StoppedEvaluation StoppedCountAdapters StoppedTraceSets +open FirstStopSemantics StoppedTraceAdmission StoppedTraceMembership FirstStopFreezing +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open BinReplacementOrder ReferenceAdmission ActualSourceStopBinding ErdosInversePrimeBin ErdosInverseAlignment +open ErdosPrimeInputs.PrimePrefixMass +attribute [local instance] Classical.propDecidable + +theorem actual_stopped_replacement (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (hwtop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (a : ℕ → ℕ) (z : Node) (pre tail : List ℕ) (p p' : ℕ) + {t : Tag (binCount w top xi)} + (hs : pre++p::tail ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) mu)) + (ht : sourceTag (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) (sourceClass a) (pre++p::tail) = some t) + (hc : tagCandidate (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) (sourceClass a) p = some (t.bin,t.rational)) + (hp' : p' ∈ primeBin (lower w top xi t.bin) (width w top xi t.bin)) + (ha' : aligns (sourceClass a) t.rational p') : + pre++p'::tail ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) mu) := by + let lo := lower w top xi + let wi := width w top xi + let lab := label (zero_lt_one.trans hw) hwtop hxi + let P := sourcePrimeSet w top + let stop := stopCandidate Y w Cs eta Clen B xi b₀ b₁ lo wi lab a z + let v := rootVertex z ∅ P mu + have hw0 : 0 < w := zero_lt_one.trans hw + have htag := candidate_witness (Y:ℝ) w Cs eta lo wi lab (sourceClass a) p hc + have hnew := (bin_mem_iff_label hw0 hwtop hxi t.bin p').mp hp' + have hlabel : lab p' = lab p := hnew.2.2.2.trans htag.1 + have hp'own : p' ∈ primeBin (lo (lab p')) (wi (lab p')) := by + change p' ∈ primeBin (lower w top xi (lab p')) (width w top xi (lab p')) + have hnewlabel : lab p' = t.bin := hnew.2.2.2 + rw [hnewlabel] + exact hp' + have hp'S : p' ∈ P := (mem_sourcePrimeSet hw0 hwtop p').mpr ⟨hnew.1,hnew.2.1,hnew.2.2.1⟩ + have href := trace_reference_member w stop P.card v (Or.inr hs) + have hD := mem_decreasingPrefixes.mp (Finset.mem_filter.mp href).1 + have hall : ∀ q ∈ pre++p::tail,q ∈ P := hD.2 + have hf := stopped_first w stop P.card v hs + have hcand : stop (pre++p::tail) := by + have hh := hf.1.2 + simpa only [after_past,v,rootVertex,List.nil_append] using hh + have hcount : ((pre++p::tail).map lab).count (lab p)=1 := by + obtain ⟨u,hu,huCount,_huAlign⟩ := hcand.2.2.2.2.2 + have hut : u=t := Option.some.inj (hu.symm.trans ht) + subst u + rw [← htag.1] + exact huCount + have hdec := (decreasing_replacement hw0 hwtop hxi pre tail p p' hall hp'S hlabel hcount).mp hD.1 + have hfirst : FirstStop w stop v (pre++p'::tail) := + (first_source_stop_replacement Y w Cs eta Clen B xi b₀ b₁ mu lo wi lab a z P pre tail p p' + ht hc hlabel hp'own ha').mp hf + have hnewCand : stop (pre++p'::tail) := by + have hh := hfirst.1.2 + simpa only [after_past,v,rootVertex,List.nil_append] using hh + have hadmit := candidate_admitted Y w Cs eta Clen B xi b₀ b₁ lo wi lab a z (pre++p'::tail) + hw hC hxi.le (fun i => endpoint_pos hw0 _) (fun i => (effectiveWidth_pos hw0 hwtop hxi).le) hnewCand + have hmem : ∀ q ∈ pre++p'::tail,q ∈ P := + (ActualTagFreezing.forall_mem_replacement_iff (fun q => q ∈ P) pre tail p p' + (hall p (by simp)) hp'S).mp hall + apply stopped_of_reference_first w stop P.card v (pre++p'::tail) + · have hl := stopped_length w stop P.card v hs + simpa only [List.length_append,List.length_cons] using hl + · exact Finset.mem_filter.mpr ⟨mem_decreasingPrefixes.mpr ⟨hdec,hmem⟩,hadmit⟩ + · exact hfirst + +theorem stopped_has_full_frozen_group (Y : ℕ) (w top Cs eta Clen B xi b₀ b₁ mu : ℝ) + (hw : 1 < w) (hwtop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hs : ps ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) mu)) : + ∃ pre tail : List ℕ,∃ p : ℕ,∃ t : Tag (binCount w top xi), + ps=pre++p::tail ∧ t.index=pre.length ∧ + sourceTag (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) (sourceClass a) ps=some t ∧ + ∀ p' ∈ primeBin (lower w top xi t.bin) (width w top xi t.bin), + aligns (sourceClass a) t.rational p' → + pre++p'::tail ∈ stopped w + (stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) a z) + (sourcePrimeSet w top).card (rootVertex z ∅ (sourcePrimeSet w top) mu) := by + have hfull := actual_source_stops_first Y w Cs eta Clen B xi b₀ b₁ mu (lower w top xi) + (width w top xi) (label (zero_lt_one.trans hw) hwtop hxi) a z (sourcePrimeSet w top) hs + obtain ⟨t,ht,_hc,_ha⟩ := hfull.2.1.2.2.2.2.2 + obtain ⟨pre,p,tail,heq,hindex,hcand,_hpre⟩ := firstTagFrom_witness + (tagCandidate (Y:ℝ) w Cs eta (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) hwtop hxi) (sourceClass a)) 0 ps ht + refine ⟨pre,tail,p,t,heq,by simpa using hindex,ht,?_⟩ + intro p' hp' ha' + subst ps + exact actual_stopped_replacement Y w top Cs eta Clen B xi b₀ b₁ mu hw hwtop hxi hC a z pre tail p p' + hs ht hcand hp' ha' +end NumberTheoryLean.ActualFrozenStopFamily + +end + +section + +namespace NumberTheoryLean.MovingStopMargins +open _root_.Filter MarkedSourceSmallness TagBelowStopWindow + +theorem moving_stop_margins (Cs Clen xi : ℝ) (hxi : 0 < xi) + {rho K : ℝ} (hrho : 0 < rho) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop,1 < w ∧ 1 ≤ Real.log w ∧ + 0 < K*(Real.log w)^2 ∧ Cs < 2*(K*(Real.log w)^2) ∧ + rho*K*(Real.log w)^2 < w^((1/4:ℝ)) ∧ + xi/Real.log w ≤ K*(Real.log w)^2 ∧ + 2*Clen*xi+(206/100)*(xi/Real.log w) ≤ (4/100)*(K*(Real.log w)^2) ∧ + ∀ B : ℝ,w ≤ B → (rho*K*(Real.log w)^2)/2 < B := by + let M := max xi (max (Cs+1) (max 1 (25*(2*Clen*xi+(206/100)*xi)+1))) + filter_upwards [moving_compact_gap_small (6*M) hK, + moving_window_below_search rho K hrho hK, + Real.tendsto_log_atTop.eventually_ge_atTop 1,eventually_gt_atTop (1:ℝ)] with w hm hs hlog hw + have hb : M < K*(Real.log w)^2 := by linarith + have hxiM : xi ≤ M := le_max_left _ _ + have hCsM : Cs+1 ≤ M := (le_max_left _ _).trans (le_max_right _ _) + have hOneM : 1 ≤ M := (le_max_left _ _).trans ((le_max_right _ _).trans (le_max_right _ _)) + have hNumM : 25*(2*Clen*xi+(206/100)*xi)+1 ≤ M := + (le_max_right _ _).trans ((le_max_right _ _).trans (le_max_right _ _)) + have hdiv : xi/Real.log w ≤ xi := div_le_self hxi.le hlog + refine ⟨hw,hlog,by linarith,by linarith,hs,by linarith,by linarith,?_⟩ + intro B hB + have hpow : w^((1/4:ℝ)) ≤ w := by + calc + _ ≤ w^(1:ℝ) := Real.rpow_le_rpow_of_exponent_le hw.le (by norm_num) + _ = w := Real.rpow_one w + have hb₁ : 0 < rho*K*(Real.log w)^2 := by positivity + linarith +end NumberTheoryLean.MovingStopMargins + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/NearPrefixOccurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/NearPrefixOccurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..9fb59101f09bad51e2489d6b788abbdeee5b4e2e --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/NearPrefixOccurrence.lean @@ -0,0 +1,126 @@ +import OAI.NumberTheory.Jacobsthal.Primes.AdjacentPrimeRecovery +import OAI.NumberTheory.Jacobsthal.Primes.FullHistoryPrimeOccupation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.CompactPrefixOccurrence + +open _root_.Set _root_.Finset _root_.MeasureTheory ProbabilityTheory +open scoped ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling PersistentFailureFlag +open FiniteHistoryTransport ActualCoupledHistories SourceSelectedCompactOccupation +open FullHistoryPrimeOccupation FullPathCompactSelection SourceCompactOccupation +open PrimeCompactWeights PrimeCompactVisits PrimeFamilyOccupation + +attribute [local instance] Classical.propDecidable + +variable {w ell S B R : ℝ} {start : Node} + +def selectedNode (E : Set (List ℕ)) : ChainState w ell S start → Prop + | none => False + | some h => h.primes ∈ E + +def occurs (E : Set (List ℕ)) (N : ℕ) + (h : Hist (FlagState (JointState w ell S start)) N) : Prop := + ∃ j : Fin N, selectedNode E (h ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩).1.1 + +theorem occurs_measurable (E : Set (List ℕ)) (N : ℕ) : + MeasurableSet {h : Hist (FlagState (JointState w ell S start)) N | occurs E N h} := by + simp only [occurs,Set.ofPred_exists] + apply MeasurableSet.iUnion + intro j + have hm : Measurable (fun h : Hist (FlagState (JointState w ell S start)) N => + (h ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩).1.1) := by fun_prop + exact hm (show MeasurableSet {z : ChainState w ell S start | selectedNode E z} from by trivial) + +noncomputable def listSelection (E : Set (List ℕ)) (ps : List ℕ) : ℝ := + if ps ∈ E then 1 else 0 + +theorem listSelection_nonneg (E : Set (List ℕ)) (ps : List ℕ) : 0 ≤ listSelection E ps := by + unfold listSelection + split_ifs <;> norm_num + +theorem selected_node_compact (E : Set (List ℕ)) + (hcompact : ∀ h : History w ell S start,h.primes ∈ E → h.node.gap ≤ R) + (z : ChainState w ell S start) : + ENNReal.ofReal (scaledWeight w B start z*listReward (listSelection E) z) ≤ + compactReward R w B start z := by + cases z with + | none => simp [scaledWeight,listReward,compactReward,visit] + | some h => + by_cases he : h.primes ∈ E + · simp [listReward,listSelection,he,compactReward,visit,hcompact h he] + · simp [listReward,listSelection,he] + +theorem full_selected_le_occurrence (E : Set (List ℕ)) + (hcompact : ∀ h : History w ell S start,h.primes ∈ E → h.node.gap ≤ R) + (N : ℕ) (h : Hist (FlagState (JointState w ell S start)) N) : + fullListReward w B start (listSelection E) N h ≤ + {h | occurs E N h}.indicator (fullCompactReward R w B start N) h := by + by_cases ho : occurs E N h + · rw [Set.indicator_of_mem (show h ∈ {h | occurs E N h} from ho)] + exact Finset.sum_le_sum (fun j _ => selected_node_compact E hcompact _) + · rw [Set.indicator_of_notMem (show h ∉ {h | occurs E N h} from ho)] + apply le_of_eq + unfold fullListReward + apply Finset.sum_eq_zero + intro j _ + have hj : ¬selectedNode E (h ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩).1.1 := + fun hj => ho ⟨j,hj⟩ + cases hz : (h ⟨j,Finset.mem_Iic.mpr j.isLt.le⟩).1.1 with + | none => simp [scaledWeight,listReward] + | some p => + rw [hz] at hj + change p.primes ∉ E at hj + simp [listReward,listSelection,hj] + +end NumberTheoryLean.CompactPrefixOccurrence + +end + +section + +namespace NumberTheoryLean.NearPrefixOccurrence +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry PrimeHistories PrimeKilledChain FiniteHistoryTransport +open ActualCoupledHistories PrimePrefixRecovery SourceThresholdCoupling +open CompactPrefixOccurrence SourceSelectedCompactOccupation + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem selected_near_prefix_occurs (mesh delta : ℝ) (N : ℕ) (E : Set (List ℕ)) + (hE : ∀ p : History w ell S start,p.primes ∈ E → hasNearThresholdPrefix w delta start p.primes) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + occurs E N h → primeThresholdOccurs delta N h := by + filter_upwards [recovered_near_prefix_occurs hw hell hS0 hS hr hs hsS mesh delta N] with h hh + rintro ⟨j,hj⟩ + let k : Finset.Iic N := ⟨j.1,Finset.mem_Iic.mpr j.isLt.le⟩ + change selectedNode E ((h k).1.1) at hj + cases hp : (h k).1.1 with + | none => rw [hp] at hj; exact False.elim hj + | some p => + rw [hp] at hj + exact hh k p hp (hE p hj) + +include hw hell hS0 hS hr hsS in +theorem near_prefix_occurrence_probability (mesh delta : ℝ) (N : ℕ) (E : Set (List ℕ)) + (hE : ∀ p : History w ell S start,p.primes ∈ E → hasNearThresholdPrefix w delta start p.primes) : + fullSourceLaw w ell S start hs mesh N {h | occurs E N h} ≤ + fullSourceLaw w ell S start hs mesh N {h | primeThresholdOccurs delta N h} := by + rw [fullSourceLaw_eq hw hell hS0 hS hr hs hsS] + exact measure_mono_ae (selected_near_prefix_occurs hw hell hS0 hS hr hs hsS mesh delta N E hE) +end NumberTheoryLean.NearPrefixOccurrence + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/OneStepHistoryReconstruction.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/OneStepHistoryReconstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..50dc22f4bd95698b2f30d8dd18690ec8f711aa58 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/OneStepHistoryReconstruction.lean @@ -0,0 +1,60 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.CompletedCycleFirstArrival + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures + +def appendRawState (a : ℕ) (past : RawHistory a) (s : CostState) : RawHistory (a+1) := + fun i => if hi : i.1 ≤ a then past ⟨i.1,Finset.mem_Iic.mpr hi⟩ else s + +lemma appendRawState_measurable (a : ℕ) (past : RawHistory a) : Measurable (appendRawState a past) := by + apply Measurable.of_eval + intro i + by_cases hi : i.1 ≤ a + · simp only [appendRawState,dite_eq_left hi] + exact measurable_const + · simp only [appendRawState,dite_eq_right hi] + exact measurable_id + +lemma appendRawState_reconstruct (a : ℕ) (past : RawHistory a) (h : RawHistory (a+1)) + (hp : rawPrefix (show a ≤ a+1 by omega) h=past) : appendRawState a past (rawLast (a+1) h)=h := by + funext i + by_cases hi : i.1 ≤ a + · rw [appendRawState,dite_eq_left hi] + exact (congrFun hp (⟨i.1,Finset.mem_Iic.mpr hi⟩ : Finset.Iic a)).symm + · rw [appendRawState,dite_eq_right hi] + have hin : i.1=a+1 := by have := Finset.mem_Iic.mp i.2; omega + have he : i=⟨a+1,by simp⟩ := Subtype.ext hin + rw [he] + rfl + +theorem oneStep_measure_reconstruct (a : ℕ) (past : RawHistory a) (μ : Measure (RawHistory (a+1))) + (hp : ∀ᵐ h ∂μ, rawPrefix (show a ≤ a+1 by omega) h=past) : + μ=(μ.map (rawLast (a+1))).map (appendRawState a past) := by + rw [Measure.map_map (appendRawState_measurable a past) (rawLast_measurable (a+1))] + have he : appendRawState a past ∘ rawLast (a+1) =ᵐ[μ] id := by + filter_upwards [hp] with h hh + exact appendRawState_reconstruct a past h hh + rw [Measure.map_congr he,Measure.map_id] + +lemma oneStep_measure_eq_of_last (a : ℕ) (past : RawHistory a) + (μ ν : Measure (RawHistory (a+1))) + (hμ : ∀ᵐ h ∂μ, rawPrefix (show a ≤ a+1 by omega) h=past) + (hν : ∀ᵐ h ∂ν, rawPrefix (show a ≤ a+1 by omega) h=past) + (he : μ.map (rawLast (a+1))=ν.map (rawLast (a+1))) : μ=ν := by + rw [oneStep_measure_reconstruct a past μ hμ,oneStep_measure_reconstruct a past ν hν,he] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/OutsideExceptionsWitness.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/OutsideExceptionsWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..04bf2061697d5f545fb4ca5c0d508bf950a7c14f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/OutsideExceptionsWitness.lean @@ -0,0 +1,363 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.EndpointSoftConclusion +import OAI.NumberTheory.Jacobsthal.Partitions.EligibleBoxLists + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.FilteredBoxWordMass +open ErdosCofactorChoices ErdosSubsetWord FiniteBoxWordMass +open ErdosPrimeInputs.PrimePrefixMass +open GeometricBoxImages ExpandedCompactPartition GeometricRegularWords ActualWordSelection +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +attribute [local instance] Classical.propDecidable + +noncomputable def selectedWordMass {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (F : Finset (List ℕ)) : ℝ := + ∑ f∈(selections P m).filter (fun f => descendingWord f∈F),(selectionProduct f:ℝ)⁻¹ + +theorem filtered_word_box_mass {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) (F : Finset (List ℕ)) : + (∑ ps∈(wordBox P m).filter (fun ps => ps∈F),prefixWeight ps)=selectedWordMass P m F := by + have he : (wordBox P m).filter (fun ps => ps∈F)= + ((selections P m).filter (fun f => descendingWord f∈F)).image descendingWord := by + ext ps + simp only [wordBox,Finset.mem_filter,Finset.mem_image] + constructor + · rintro ⟨⟨f,hf,rfl⟩,hF⟩ + exact ⟨f,⟨hf,hF⟩,rfl⟩ + · rintro ⟨f,⟨hf,hF⟩,rfl⟩ + exact ⟨⟨f,hf,rfl⟩,hF⟩ + rw [he,Finset.sum_image] + · apply Finset.sum_congr rfl + intro f hf + rw [StoppedVertexHistory.prefixWeight_product, + descendingWord_product P hd f (fun k => ((mem_selections _ _ _).mp (Finset.mem_filter.mp hf).1 k).1)] + · intro f hf g hg heq + exact word_injective P hd f g + (fun k => ((mem_selections _ _ _).mp (Finset.mem_filter.mp hf).1 k).1) + (fun k => ((mem_selections _ _ _).mp (Finset.mem_filter.mp hg).1 k).1) heq + +theorem filtered_box_mass {n : ℕ} (P : Fin n → Finset ℕ) + (hd : Pairwise (fun i j => Disjoint (P i) (P j))) + (M : Finset (Fin n → ℕ)) (F : Finset (List ℕ)) (hF : F ⊆ boxWords P M) : + (∑ ps∈F,prefixWeight ps)=∑ m∈M,selectedWordMass P m F := by + have he : F=M.biUnion (fun m => (wordBox P m).filter (fun ps => ps∈F)) := by + ext ps + constructor + · intro hp + obtain ⟨m,hm,hps⟩ := Finset.mem_biUnion.mp (hF hp) + exact Finset.mem_biUnion.mpr ⟨m,hm,Finset.mem_filter.mpr ⟨hps,hp⟩⟩ + · intro hp + obtain ⟨_m,_hm,hps⟩ := Finset.mem_biUnion.mp hp + exact (Finset.mem_filter.mp hps).2 + calc + _ = ∑ ps∈M.biUnion (fun m => (wordBox P m).filter (fun ps => ps∈F)),prefixWeight ps := by rw [← he] + _ = ∑ m∈M,∑ ps∈(wordBox P m).filter (fun ps => ps∈F),prefixWeight ps := by + apply Finset.sum_biUnion + intro m _hm m' _hm' hne + exact (wordBoxes_disjoint P hd m m' hne).mono (Finset.filter_subset _ _) (Finset.filter_subset _ _) + _ = _ := Finset.sum_congr rfl (fun m _ => filtered_word_box_mass P m hd F) + +theorem unlisted_geometric_box_mass {w top xi Cs C B K L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (a : ℕ → ℕ) (z : PrimeHistories.Node) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (F : Finset (List ℕ)) : + let U := unlistedGeometric hw htop hxi Cs C B K L alpha beta a z Q F + (∑ ps∈U,prefixWeight ps)=∑ m∈geometricBoxes hw htop hxi C B K L alpha beta z, + selectedWordMass (globalBins w top xi) m U := by + dsimp only + apply filtered_box_mass _ (fun k l hkl => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) + intro ps hp + have hg := (Finset.mem_inter.mp (Finset.mem_filter.mp hp).1).2 + have hr := (Finset.mem_filter.mp hg).1 + have hd := mem_decreasingPrefixes.mp (Finset.mem_filter.mp hr).1 + apply Finset.mem_biUnion.mpr + refine ⟨wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps, + Finset.mem_image.mpr ⟨ps,hg,rfl⟩,?_⟩ + exact Finset.mem_image.mpr ⟨wordSelection (label (zero_lt_one.trans hw) htop hxi) ps, + wordSelection_mem hw htop hxi ps hd.2,wordSelection_recovers _ ps hd.1⟩ +end NumberTheoryLean.FilteredBoxWordMass + + + +namespace NumberTheoryLean.SoftWitnessCapture +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseAlignment +open ActualWordSelection FiniteBoxWordMass FullIsolatedCofactor EligibleBoxLists +open ExpandedCompactPartition ActualBinOwners SingletonBinSelection TwoPrimeObservableSum +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure +attribute [local instance] Classical.propDecidable + +theorem word_selection_descending {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) : + wordSelection (label (zero_lt_one.trans hw) htop hxi) (descendingWord f)=f := by + have hrec := wordSelection_mem hw htop hxi (descendingWord f) (word_source_membership hw htop hxi m f hf) + apply word_injective (globalBins w top xi) + (fun k l hkl => bins_pairwise_disjoint (zero_lt_one.trans hw) htop hxi k l hkl) + _ f (fun k => ((mem_selections _ _ _).mp hrec k).1) (fun k => ((mem_selections _ _ _).mp hf k).1) + exact wordSelection_recovers _ _ (descendingWord_strict f) + +theorem word_multiplicity_descending {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) : + wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) (descendingWord f)=m := by + funext k + unfold wordMultiplicity + rw [word_selection_descending hw htop hxi m f hf] + exact ((mem_selections _ _ _).mp hf k).2 + +theorem soft_full_word_listed {w top xi Cs : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℝ) + (M : Finset (Fin (binCount w top xi) → ℕ)) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (m : Fin (binCount w top xi) → ℕ) (hm : m∈M) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (i : Fin (binCount w top xi)) (hi : m i=1) + (a : ℕ → ℕ) (q : ℚ) (hq : q∈Q m) (helig : eligible Y w Cs q) + (ha : ∀ p∈(pickedPrime f i*selectionProduct (eraseSelection f i)).primeFactors, + Cs < primeExponent w p → aligns (SourceStopPredicate.sourceClass a) q p) : + listedWord hw htop hxi Cs a (eligibleLists Y w Cs M Q) (descendingWord f) := by + unfold listedWord + rw [word_multiplicity_descending hw htop hxi m f hf] + exact ⟨q,soft_witness_in_eligibleLists Y w Cs M Q m hm q hq helig, + full_cofactor_alignment_word hw htop hxi m f hf i hi _ q ha⟩ + +theorem unlisted_has_no_soft_witness {w top xi Cs C B K L alpha beta : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℝ) + (M : Finset (Fin (binCount w top xi) → ℕ)) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (m : Fin (binCount w top xi) → ℕ) (hm : m∈M) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (i : Fin (binCount w top xi)) (hi : m i=1) + (a : ℕ → ℕ) (z : PrimeHistories.Node) (F : Finset (List ℕ)) + (hu : descendingWord f∈unlistedGeometric hw htop hxi Cs C B K L alpha beta a z (eligibleLists Y w Cs M Q) F) + (q : ℚ) (hq : q∈Q m) : + ¬(eligible Y w Cs q ∧ + ∀ p∈(pickedPrime f i*selectionProduct (eraseSelection f i)).primeFactors, + Cs < primeExponent w p → aligns (SourceStopPredicate.sourceClass a) q p) := by + rintro ⟨helig,ha⟩ + exact (Finset.mem_filter.mp hu).2 (soft_full_word_listed hw htop hxi Y M Q m hm f hf i hi a q hq helig ha) +end NumberTheoryLean.SoftWitnessCapture + + + +namespace ErdosVarianceEligible +open NumberTheoryLean ErdosCofactorChoices ErdosSubsetWord SingletonBinSelection TwoPrimeObservableSum + FullIsolatedCofactor ActualBinOwners SourceStopPredicate ActualCountErrorEdges + ErdosVarianceSmallPrime ErdosVarianceCommon ErdosInverseAlignment + LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure +attribute [local instance] Classical.propDecidable + +def eligibleWordWitness (Y : ℕ) (w Cs : ℝ) (residue : ℕ → ℕ) (Q : Finset ℚ) (ps : List ℕ) : Prop := + ∃ r ∈ Q,eligible (Y : ℝ) w Cs r ∧ + ∀ p ∈ ps,Cs < primeExponent w p → aligns (sourceClass residue) r p + +theorem eligible_word_witness_of_endpoint {w top xi Cs : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℕ) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (i : Fin (binCount w top xi)) (hi : m i = 1) + (residue : ℕ → ℕ) (Q : Finset ℚ) (r : ℚ) (hr : r ∈ Q) + (hsoft : (r.den : ℝ) ≤ w^Cs ∧ (r.num.natAbs : ℝ) ≤ (Y : ℝ)*w^(Cs+2) ∧ + ∀ t ∈ (pickedPrime f i*selectionProduct (eraseSelection f i)).primeFactors, + Cs < Real.logb w (t : ℝ) → aligns (fun u => (residue u : ℤ)) r t) : + eligibleWordWitness Y w Cs residue Q (descendingWord f) := by + refine ⟨r,hr,⟨hsoft.1,hsoft.2.1⟩,?_⟩ + apply full_cofactor_alignment_word hw htop hxi m f hf i hi (sourceClass residue) r + intro p hp hhigh + exact hsoft.2.2 p hp hhigh + +theorem word_error_bad_aligning_prime {w top xi : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℕ) + (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f ∈ selections (globalBins w top xi) m) (i : Fin (binCount w top xi)) (hi : m i = 1) + (residue : ℕ → ℕ) (r : ℚ) (eps : ℝ) (halign : aligns (sourceClass residue) r (pickedPrime f i)) + (hbad : eps < |wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue + (SmallSieveFinite.smallEuler ⌊w⌋₊) (descendingWord f)|) : + pickedPrime f i ∈ badAligningPrimes (globalBins w top xi i) Y w residue r + (selectionProduct (eraseSelection f i)) eps := by + obtain ⟨p,hp,hfi,_hfill⟩ := singleton_selection_recovery _ m i hi f hf + have hpmem : pickedPrime f i ∈ globalBins w top xi i := by simpa [pickedPrime,hfi] using hp + have hprod := full_word_isolated_product hw htop hxi m f hf i hi + apply (mem_badAligningPrimes _ _ _ _ _ _ _ _).mpr + refine ⟨hpmem,halign,?_⟩ + simpa only [wordCountError,relativeCountError,hprod,Nat.cast_mul,referenceCount] using hbad + +end ErdosVarianceEligible + + + +namespace NumberTheoryLean.EligibleListWord +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseAlignment +open ActualWordSelection SoftWitnessCapture EligibleBoxLists ExpandedCompactPartition ActualBinOwners +open LogarithmicBinScale LogarithmicBinLabels +open ErdosPrimeInputs.HarmonicPrimeMeasure +attribute [local instance] Classical.propDecidable + +theorem listed_word_eligible_iff {w top xi Cs : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℝ) + (M : Finset (Fin (binCount w top xi) → ℕ)) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) (a : ℕ → ℕ) (ps : List ℕ) : + listedWord hw htop hxi Cs a (eligibleLists Y w Cs M Q) ps ↔ + wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps∈M ∧ + ∃ q∈Q (wordMultiplicity (label (zero_lt_one.trans hw) htop hxi) ps),eligible Y w Cs q ∧ + ∀ p∈ps,Cs < primeExponent w p → aligns (SourceStopPredicate.sourceClass a) q p := by + unfold listedWord + constructor + · rintro ⟨q,hq,ha⟩ + obtain ⟨hm,hq,he⟩ := (mem_eligibleLists _ _ _ _ _ _ _).mp hq + exact ⟨hm,q,hq,he,ha⟩ + · rintro ⟨hm,q,hq,he,ha⟩ + exact ⟨q,(mem_eligibleLists _ _ _ _ _ _ _).mpr ⟨hm,hq,he⟩,ha⟩ + +theorem listed_selection_eligible_iff {w top xi Cs : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℝ) + (M : Finset (Fin (binCount w top xi) → ℕ)) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (m : Fin (binCount w top xi) → ℕ) (hm : m∈M) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (a : ℕ → ℕ) : + listedWord hw htop hxi Cs a (eligibleLists Y w Cs M Q) (descendingWord f) ↔ + ∃ q∈Q m,eligible Y w Cs q ∧ + ∀ p∈descendingWord f,Cs < primeExponent w p → aligns (SourceStopPredicate.sourceClass a) q p := by + rw [listed_word_eligible_iff hw htop hxi Y M Q a,word_multiplicity_descending hw htop hxi m f hf] + exact and_iff_right hm + +theorem unlisted_compact_selected_data {w top xi Cs C B K L alpha beta eps : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (Y : ℕ) + (M : Finset (Fin (binCount w top xi) → ℕ)) + (Q : (Fin (binCount w top xi) → ℕ) → Finset ℚ) + (m : Fin (binCount w top xi) → ℕ) (hm : m∈M) (f : Fin (binCount w top xi) → Finset ℕ) + (hf : f∈selections (globalBins w top xi) m) (a : ℕ → ℕ) (z : PrimeHistories.Node) + (F : Finset (List ℕ)) + (hu : descendingWord f∈unlistedGeometric hw htop hxi Cs C B K L alpha beta a z (eligibleLists Y w Cs M Q) + (CountErrorClassification.badCompactWords w K eps Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a + (SmallSieveFinite.smallEuler ⌊w⌋₊) z F)) : + descendingWord f∈GeometricRegularWords.geometricWords hw htop hxi C B K L alpha beta z ∧ + eps < |ActualCountErrorEdges.wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) a + (SmallSieveFinite.smallEuler ⌊w⌋₊) (descendingWord f)| ∧ + ¬∃ q∈Q m,eligible Y w Cs q ∧ + ∀ p∈descendingWord f,Cs < primeExponent w p → aligns (SourceStopPredicate.sourceClass a) q p := by + obtain ⟨hmem,hnot⟩ := Finset.mem_filter.mp hu + have hh := Finset.mem_inter.mp hmem + refine ⟨hh.2,(Finset.mem_filter.mp hh.1).2.2,?_⟩ + exact fun hwit => hnot ((listed_selection_eligible_iff hw htop hxi Y M Q m hm f hf a).mpr hwit) +end NumberTheoryLean.EligibleListWord + + + +namespace ErdosVarianceEligible +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership ActualCountErrorEdges + GeometricRecentWitness GeometricRegularWords BoundedEdgeBins + ErdosCofactorChoices ErdosSubsetWord ErdosInverseCounts TwoPrimeObservableSum ParentTailPartition + LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition +attribute [local instance] Classical.propDecidable + +theorem geometric_selection_recent_witness (K eps : ℝ) (hK : 3 ≤ K) (heps : 0 < eps) : + ∃ Kstar B0 w0 : ℝ,K+10 < Kstar ∧ 3 ≤ B0 ∧ 1 < w0 ∧ + ∀ (B w top : ℝ),B0 ≤ B → w0 ≤ w → ∀ (hw : 1 < w) (htop : w < top), + ∀ (xi : ℝ) (hxi : 0 < xi) (C : ℝ),1 ≤ C → Real.log B ≤ 2*Real.log w → + ∀ (aStar alpha beta : ℝ),0 ≤ aStar → aStar ≤ 1 → ∀ Y : ℕ,0 < Y → ∀ z : Node, + z.gap = Real.log (Y : ℝ)/Real.log w-aStar+2 → z.side = .even → 199/100 ≤ z.ratio → + Consistent z → z.cutoff = B → z.closed = true → w^B = top → + ∀ (residue : ℕ → ℕ) (m : Fin (binCount w top xi) → ℕ) (f : Fin (binCount w top xi) → Finset ℕ), + f ∈ selections (globalBins w top xi) m → + descendingWord f ∈ geometricWords hw htop hxi C B K (2*Kstar+5) alpha beta z → + eps < |wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) (descendingWord f)| → + ∃ j : Fin (binCount w top xi),boundedEdgeBin w top xi Y m (2*Kstar+3) (2*Kstar+3) j ∧ + ∀ i : Fin (binCount w top xi),m i = 1 → j < i → + WitnessingBadEdge Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue + (eps/(4*(⌈2*Kstar+10⌉₊ : ℝ))) (SmallSieveFinite.smallEuler ⌊w⌋₊) + (pickedPrime f i) (selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j) := by + obtain ⟨Kstar,B0,w0,hKs,hB0,hw0,hcore⟩ := geometric_recent_witness K eps hK heps + refine ⟨Kstar,B0,w0,hKs,hB0,hw0,?_⟩ + intro B w top hB hw0' hw htop xi hxi C hC hcomp aStar alpha beta ha0 ha1 Y hY z hroot + heven h199 hz hcut hclosed hpower residue m f hf hgeom hbad + have hh := hcore B w top hB hw0' hw htop xi hxi C hC hcomp aStar alpha beta ha0 ha1 Y hY z hroot + heven h199 hz hcut hclosed hpower residue (descendingWord f) hgeom hbad + simpa only [SoftWitnessCapture.word_multiplicity_descending hw htop hxi m f hf, + SoftWitnessCapture.word_selection_descending hw htop hxi m f hf] using hh + +end ErdosVarianceEligible + + + +open _root_.Filter +namespace ErdosVarianceEligible +open NumberTheoryLean FinitePathGeometry PrimeHistories PrimeBinMembership StrongReferenceTransport + SafeSubsetBoxGeometry BoundedEdgeBins ParentCofactorChoices ParentTailPartition + RawBoxRationalWitness SingletonBinSelection TwoPrimeObservableSum ActualCountErrorEdges + ErdosCofactorChoices ErdosSubsetWord ErdosVarianceWeighted ErdosVarianceEffective ErdosInverseBoxHeight + ErdosInverseCells ErdosInverseAlignment ErdosInverseBoxApplication ErdosInverseSampleCost ErdosInverseCounts + LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinPartition +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem outside_exceptions_eligible_word (C M : ℝ) (hC : 0 ≤ C) (hM : 0 ≤ M) : + ∀ᶠ top : ℝ in atTop, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → 2*C*xi ≤ 1 → + ∀ (hw : 1 < sourceW top) (htop : sourceW top < top) (K aStar X : ℝ),0 ≤ aStar → + ∀ z : Node,0 < sourceY top → + z.gap = Real.log (sourceY top : ℝ)/Real.log (sourceW top)-aStar+2 → + Valid z.side z.ratio → Consistent z → StrongState z → z.closed = true → (sourceW top)^z.cutoff = top → + ∀ m : Fin (binCount (sourceW top) top xi) → ℕ,SafeAnchor hw htop hxi C (sourceB top) K z m → + ∀ f ∈ selections (globalBins (sourceW top) top xi) m, + ∀ i : Fin (binCount (sourceW top) top xi),m i = 1 → + ∀ J : Finset (Fin (binCount (sourceW top) top xi)), + (∀ j ∈ J,boundedEdgeBin (sourceW top) top xi (sourceY top) m M X j ∧ j < i) → + ∀ (residue : ℕ → ℕ) (delta cp sigma Cs eps : ℝ) (F : ℕ), + (∀ j ∈ J,SourceInverseConclusion (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) + residue delta (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) + (cofactorScale top xi (parentCofactorMultiplicity m i j)) (lower (sourceW top) top xi i) (sourceZ top) cp sigma F + (globalBins (sourceW top) top xi i) + (cofactorChoices (globalBins (sourceW top) top xi) (parentCofactorMultiplicity m i j)) (globalBins (sourceW top) top xi j)) → + (∃ j ∈ J,WitnessingBadEdge (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) (pickedPrime f i) + (selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j)) → + eps < |wordCountError (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) residue + (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) (descendingWord f)| → + (¬∃ j ∈ J,actualWitness (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) (globalBins (sourceW top) top xi i) + (cofactorScale top xi (parentCofactorMultiplicity m i j)) (lower (sourceW top) top xi i) (sourceZ top) cp + (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j)) → + let Q := rawBoxList (globalBins (sourceW top) top xi) i J residue + (fun j => cofactorScale top xi (parentCofactorMultiplicity m i j)) (lower (sourceW top) top xi i) (sourceZ top) cp + ¬hardSelection Q top (lower (sourceW top) top xi i) (width (sourceW top) top xi i) residue i Cs eps f → + eligibleWordWitness (sourceY top) (sourceW top) Cs residue Q (descendingWord f) := by + filter_upwards [structured_endpoint_heights C M hC hM, + ErdosInverseEuler.sourceW_tendsto_atTop.eventually_ge_atTop 2, + Real.tendsto_log_atTop.eventually JacobsthalSourceScale.source_scale_eventually] + with top hheight hw2 hscale + intro xi hxi hxi1 hDelta hw htop K aStar X ha z hY hroot hs hz hg hclosed hcap m hanchor + f hf i hi J hJ residue delta cp sigma Cs eps F hInv hbadEdge hbadWord hnoInv + dsimp only + intro hnoHard + let P := globalBins (sourceW top) top xi + let S := fun j => cofactorScale top xi (parentCofactorMultiplicity m i j) + let R := lower (sourceW top) top xi i + let Q := rawBoxList P i J residue S R (sourceZ top) cp + have hj : ∀ j ∈ J,m j = 1 := fun j hj => bounded_edge_singleton m j (hJ j hj).1 + obtain ⟨j,hjJ,r,hrQ,hrLocal,halign,hstructure⟩ := raw_box_witness P m i J f hf hi hj + (sourceY top) (LargePrimeDeletion.cutoffPrimes ⌊sourceW top⌋₊) residue delta + (SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) S R (sourceZ top) cp sigma F hInv hbadEdge hnoInv + have hbounds := hheight xi hxi hxi1 hDelta hw htop K aStar X ha z hY hroot hs hz hg hclosed hcap + m hanchor f hf i j (hJ j hjJ).2 hi (hJ j hjJ).1 residue r cp hrLocal hstructure + have hcomp : Real.log (sourceB top) ≤ 2*Real.log (sourceW top) := hscale.2.2.2.2 + have hdata := full_endpoint_data hw htop hxi hC ha hcomp (sourceY top) hY z hroot hs hz hg hclosed hcap + m hanchor f hf i hi + have hR : 0 < R := (zero_lt_one.trans hw).trans_le (bin_source_bounds (zero_lt_one.trans hw) htop hxi i).1 + have hwidth : 0 ≤ width (sourceW top) top xi i := (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le + have hRp := ((ErdosInversePrimeBin.mem_primeBin hR.le hwidth (pickedPrime f i)).mp hdata.2.2.1).2.1.le + have hbad := word_error_bad_aligning_prime hw htop hxi (sourceY top) m f hf i hi residue r eps halign hbadWord + have hsoft := endpoint_soft_conclusion Q top R (width (sourceW top) top xi i) residue f i r Cs eps + hrQ hdata.1 hdata.2.1 hR hRp hw2 hdata.2.2.2 hbounds.1 hbounds.2 hbad hnoHard + exact eligible_word_witness_of_endpoint hw htop hxi (sourceY top) m f hf i hi residue Q r hrQ hsoft + +end ErdosVarianceEligible + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/PairBranchFullProjection.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/PairBranchFullProjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..7b8b9be1d777df9ee9e3aef37f88a3f5861982d0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/PairBranchFullProjection.lean @@ -0,0 +1,135 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.RegenerationInputPotential + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.InitialRegeneration + +noncomputable def pairBranchKernel (b : Bool) : Kernel OddCost OddCost := + (markedPairKernel.restrict (measurable_fst (measurableSet_singleton b))).map Prod.snd + +instance pairBranchKernel_isFiniteKernel (b : Bool) : IsFiniteKernel (pairBranchKernel b) := by + unfold pairBranchKernel + infer_instance + +lemma markedKernel_branch_lintegral (K : Kernel OddCost MarkedOddCost) (b : Bool) (z : OddCost) + {F : OddCost → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F y ∂((K.restrict (measurable_fst (measurableSet_singleton b))).map Prod.snd) z)= + ∫⁻ y, (if y.1=b then F y.2 else 0) ∂K z := by + rw [Kernel.map_apply _ measurable_snd,Kernel.restrict_apply,lintegral_map hF measurable_snd, + ← lintegral_indicator (measurable_fst (measurableSet_singleton b))] + apply lintegral_congr + intro y + simp only [Set.indicator_apply,mem_preimage,mem_singleton_iff] + +lemma markContinuation_measure (z : MarkedOddCost) : + markContinuation z=(hitOrReturn z.2).map (Prod.mk z.1) := by + ext S hS + rw [markContinuation_apply _ hS,Measure.map_apply measurable_prodMk_left hS] + rfl + +theorem cycleBranch_completion (b : Bool) : cycleBranchKernel b=hitOrReturn ∘ₖ pairBranchKernel b := by + ext z : 1 + apply Measure.ext_of_lintegral + intro F hF + let G : MarkedOddCost → ℝ≥0∞ := fun y => if y.1=b then F y.2 else 0 + have hG : Measurable G := Measurable.ite (measurable_fst (measurableSet_singleton b)) + (hF.comp measurable_snd) measurable_const + have hJ : Measurable (fun y : OddCost => ∫⁻ t, F t ∂hitOrReturn y) := hF.lintegral_kernel + rw [cycleBranchKernel,markedKernel_branch_lintegral _ b z hF] + change (∫⁻ y, G y ∂completedMarkedKernel z)=_ + rw [completedMarkedKernel,Kernel.lintegral_comp _ _ _ hG,Kernel.lintegral_comp _ _ _ hF, + pairBranchKernel,markedKernel_branch_lintegral _ b z hJ] + apply lintegral_congr + intro y + rw [markContinuation_measure,lintegral_map hG measurable_prodMk_left] + by_cases hy : y.1=b <;> simp [G,hy] + +lemma pairBranch_sum : pairBranchKernel true+pairBranchKernel false=NumberTheoryLean.PairedCostProcess.pairedCostKernel := by + ext z : 1 + rw [_root_.add_apply] + unfold pairBranchKernel + rw [Kernel.map_apply _ measurable_snd,Kernel.map_apply _ measurable_snd,Kernel.restrict_apply,Kernel.restrict_apply] + change ((markedPairKernel z).restrict {y | y.1=true}).map Prod.snd+ + ((markedPairKernel z).restrict {y | y.1=false}).map Prod.snd=_ + rw [false_mark_set] + change ((markedPairKernel z).restrict sourceMarkSet).map Prod.snd+ + ((markedPairKernel z).restrict sourceMarkSetᶜ).map Prod.snd=_ + rw [← Measure.map_add _ _ measurable_snd,Measure.restrict_add_restrict_compl sourceMarkSet_measurable,markedPair_forget] + +lemma nextMarkWeight_pair_mass (z : OddCost) : nextMarkWeight z=pairBranchKernel true z univ := by + rw [nextMarkWeight,cycleBranch_completion,Kernel.comp_apply' _ _ _ MeasurableSet.univ] + simp + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping + +lemma pairBranch_full_lintegral (b : Bool) (z : OddCost) {F : CostState → ℝ≥0∞} (hF : Measurable F) : + (∫⁻ y, F (embedOdd y) ∂pairBranchKernel b z)= + ∫⁻ s, (if firstArrivalMark s=b then ∫⁻ t, F t ∂costKernel s else 0) ∂costKernel (embedOdd z) := by + let G : MarkedOddCost → ℝ≥0∞ := fun y => if y.1=b then F (embedOdd y.2) else 0 + have hG : Measurable G := Measurable.ite (measurable_fst (measurableSet_singleton b)) + (hF.comp (embedOdd_measurable.comp measurable_snd)) measurable_const + let J : CostState × CostState → ℝ≥0∞ := fun y => if firstArrivalMark y.1=b then F y.2 else 0 + have hJ : Measurable J := Measurable.ite ((firstArrivalMark_measurable.comp measurable_fst) (measurableSet_singleton b)) + (hF.comp measurable_snd) measurable_const + rw [pairBranchKernel,markedKernel_branch_lintegral _ b z (F := fun y => F (embedOdd y)) (hF.comp embedOdd_measurable)] + change (∫⁻ y, G y ∂markedPairKernel z)=_ + rw [← pairWitness_projection z,lintegral_map hG firstPairProjection_measurable] + calc + _ = ∫⁻ y, J y ∂fullPairTraceKernel (embedOdd z) := by + rw [← pairWitness_joint_full_trace z,lintegral_map hJ (pairTraceOfWitness_measurable z)] + rfl + _ = _ := by + rw [fullPairTraceKernel,Kernel.lintegral_compProd _ _ _ hJ] + apply lintegral_congr + intro s + by_cases hs : firstArrivalMark s=b <;> simp [J,hs] + +lemma pairBranch_full_projection (b : Bool) (z : OddCost) : + (pairBranchKernel b z).map embedOdd= + (costKernel ∘ₖ costKernel.restrict (firstArrivalMark_measurable (measurableSet_singleton b))) (embedOdd z) := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF embedOdd_measurable,pairBranch_full_lintegral b z hF, + Kernel.lintegral_comp _ _ _ hF,Kernel.restrict_apply, + ← lintegral_indicator (firstArrivalMark_measurable (measurableSet_singleton b))] + apply lintegral_congr + intro s + simp only [Set.indicator_apply,mem_preimage,mem_singleton_iff] + +lemma false_arrival_set : {s : CostState | firstArrivalMark s=false}=markedArrivalᶜ := by + ext s + cases he : firstArrivalMark s <;> simp [markedArrival,he] + +lemma pairBranch_marked_first_mass (z : OddCost) : + pairBranchKernel true z univ=(costKernel (embedOdd z)) markedArrival := by + have he := congrArg (fun μ : Measure CostState => μ univ) (pairBranch_full_projection true z) + rw [Measure.map_apply embedOdd_measurable MeasurableSet.univ,preimage_univ, + Kernel.comp_apply' _ _ _ MeasurableSet.univ] at he + simp only [measure_univ,lintegral_const,one_mul] at he + rw [Kernel.restrict_apply' _ _ _ MeasurableSet.univ,univ_inter] at he + exact he + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/PairCaptureProjection.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/PairCaptureProjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..c2fb38338471cb3e674cc31c29e2f4112e8d3cd0 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/PairCaptureProjection.lean @@ -0,0 +1,103 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FullReturnCylinders + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory Function Preorder +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FirstHitKernels +open NumberTheoryLean.CostReturnLaw + +def rawLast (n : ℕ) (h : RawHistory n) : CostState := h ⟨n,by simp⟩ + +lemma rawLast_measurable (n : ℕ) : Measurable (rawLast n) := measurable_pi_apply _ + +lemma rawExtension_last_pair (n : ℕ) (h : RawHistory n) : + (rawExtension n (n+2) h).map (rawLast (n+2)) = (costKernel ^ 2) (rawLast n h) := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (rawLast_measurable _)] + have he := congrArg (fun μ : Measure (CostState × CostState) => ∫⁻ p, F p.2 ∂μ) + (conditional_pair_trace n h) + rw [lintegral_map (f := fun p : CostState × CostState => F p.2) (hF.comp measurable_snd) + (nextPairEval_measurable n),fullPairTraceKernel, + Kernel.lintegral_compProd _ _ _ (f := fun p : CostState × CostState => F p.2) (hF.comp measurable_snd)] at he + rw [pow_two] + change (∫⁻ z, F (rawLast (n+2) z) ∂rawExtension n (n+2) h) = + ∫⁻ y, F y ∂(costKernel ∘ₖ costKernel) (rawLast n h) + rw [Kernel.lintegral_comp _ _ _ hF] + exact he + +lemma rawExtension_restricted_last_pair (n : ℕ) (h : RawHistory n) + {E : Set CostState} (hE : MeasurableSet E) : + (((rawExtension n (n+2)).restrict (hE.preimage (rawLast_measurable (n+2)))) h).map (rawLast (n+2)) = + ((costKernel ^ 2) (rawLast n h)).restrict E := by + rw [Kernel.restrict_apply,← Measure.restrict_map (rawLast_measurable _) hE,rawExtension_last_pair] + +noncomputable def fullPairCaptured : Kernel CostState CostState := + (costKernel ^ 2).restrict regenerationSet_measurable + +noncomputable def fullPairKilled : Kernel CostState CostState := + (costKernel ^ 2).restrict regenerationSet_measurable.compl + +instance fullPairCaptured_isFiniteKernel : IsFiniteKernel fullPairCaptured := by + have : IsFiniteKernel (costKernel ^ 2) := by rw [pow_two]; change IsFiniteKernel (costKernel ∘ₖ costKernel); infer_instance + unfold fullPairCaptured + infer_instance + +instance fullPairKilled_isFiniteKernel : IsFiniteKernel fullPairKilled := by + have : IsFiniteKernel (costKernel ^ 2) := by rw [pow_two]; change IsFiniteKernel (costKernel ∘ₖ costKernel); infer_instance + unfold fullPairKilled + infer_instance + +lemma embedOdd_regeneration_preimage : embedOdd ⁻¹' regenerationSet = returnSet := rfl + +lemma costCaptured_fullPair_projection (z : OddCost) : + (costCaptured z).map embedOdd = fullPairCaptured (embedOdd z) := by + rw [costCaptured,Kernel.restrict_apply,fullPairCaptured,Kernel.restrict_apply, + ← embedOdd_regeneration_preimage,← Measure.restrict_map embedOdd_measurable regenerationSet_measurable, + pairedCost_full_grouping] + +lemma costKilled_fullPair_projection (z : OddCost) : + (costKilled z).map embedOdd = fullPairKilled (embedOdd z) := by + rw [costKilled,Kernel.restrict_apply,fullPairKilled,Kernel.restrict_apply, + ← embedOdd_regeneration_preimage,← preimage_compl, + ← Measure.restrict_map embedOdd_measurable regenerationSet_measurable.compl,pairedCost_full_grouping] + +lemma rawCapturedPair_projection (n : ℕ) (h : RawHistory n) : + ((((rawExtension n (n+2)).restrict (lastRegeneration_measurable (n+2))) h).map (rawLast (n+2))) = + fullPairCaptured (rawLast n h) := by + exact rawExtension_restricted_last_pair n h regenerationSet_measurable + +lemma rawKilledPair_projection (n : ℕ) (h : RawHistory n) : + ((((rawExtension n (n+2)).restrict (lastRegeneration_measurable (n+2)).compl) h).map (rawLast (n+2))) = + fullPairKilled (rawLast n h) := by + exact rawExtension_restricted_last_pair n h regenerationSet_measurable.compl + +lemma firstReturnHistory_zero (a : ℕ) : + firstReturnHistory a 0 = (rawExtension a (a+2)).restrict (lastRegeneration_measurable (a+2)) := by + ext h : 1 + rw [firstReturnHistory,Kernel.restrict_apply,Kernel.restrict_apply] + congr 1 + ext z + simp [avoidOddReturns] + +theorem firstReturnHistory_zero_projection (a : ℕ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (firstReturnHistory a 0 h).map (rawLast (a+2)) = (firstReturn 0 z).map embedOdd := by + rw [firstReturnHistory_zero,rawCapturedPair_projection,hz,← costCaptured_fullPair_projection] + have he : firstReturn 0 = costCaptured := Kernel.comp_id _ + rw [he] + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/PairedHitting.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/PairedHitting.lean new file mode 100644 index 0000000000000000000000000000000000000000..e92095fec1ddb73833b061d9454ebd8dbd59b303 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/PairedHitting.lean @@ -0,0 +1,188 @@ +import Mathlib.Probability.Kernel.Composition.KernelLemmas +import OAI.NumberTheory.Jacobsthal.Probability.FirstHitKernels + +namespace OAI + +namespace Erdos970 + +section + +namespace NumberTheoryLean.PairedHitting + +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open TransitionKernels FinitePathMeasures KernelDensityBridge GoodPairTransitions + +noncomputable def pairedOdd : Kernel OddState OddState := evenToOdd ∘ₖ oddToEven + +instance pairedOdd_isMarkovKernel : IsMarkovKernel pairedOdd := by unfold pairedOdd; infer_instance + +theorem pairedOdd_map_ratio (s : OddState) : + (pairedOdd s).map (Subtype.val : OddState → ℝ) = (oddTwoStep s).map Prod.snd := by + have hm : Measurable (fun x : EvenState × OddState => (x.1.1, x.2.1)) := + (measurable_subtype_coe.comp measurable_fst).prodMk (measurable_subtype_coe.comp measurable_snd) + rw [pairedOdd, Kernel.comp_eq_snd_compProd, Kernel.snd_apply, oddTwoStep, + Kernel.map_apply _ hm, Measure.map_map measurable_snd hm, + Measure.map_map measurable_subtype_coe measurable_snd] + rfl + +theorem pairedOdd_progress {M : ℝ} (hM : 4 ≤ M) (s : OddState) (hs : s.1 ≤ M) : + ENNReal.ofReal (goodPairProbability M) ≤ + pairedOdd s {t : OddState | t.1 ≤ max (3 / 2) (s.1 - 3 / 2)} := by + have heq := congrArg (fun μ : Measure ℝ => μ (Iic (max (3 / 2) (s.1 - 3 / 2)))) (pairedOdd_map_ratio s) + rw [Measure.map_apply measurable_subtype_coe measurableSet_Iic, + Measure.map_apply measurable_snd measurableSet_Iic] at heq + change pairedOdd s {t : OddState | t.1 ≤ max (3 / 2) (s.1 - 3 / 2)} = + oddTwoStep s {x : ℝ × ℝ | x.2 ≤ max (3 / 2) (s.1 - 3 / 2)} at heq + rw [heq] + exact odd_terminal_progress hM s hs + +def pairedRegeneration : Set OddState := {s | s.1 ≤ 3} + +theorem pairedRegeneration_measurable : MeasurableSet pairedRegeneration := + measurableSet_le measurable_subtype_coe measurable_const + +noncomputable def pairedKilled : Kernel OddState OddState := + pairedOdd.restrict pairedRegeneration_measurable.compl + +instance pairedKilled_isFiniteKernel : IsFiniteKernel pairedKilled := by unfold pairedKilled; infer_instance + +instance pairedKilled_pow_isFiniteKernel (n : ℕ) : IsFiniteKernel (pairedKilled ^ n) := by + induction n with + | zero => change IsFiniteKernel (Kernel.id : Kernel OddState OddState); infer_instance + | succ n ih => + rw [pow_succ'] + change IsFiniteKernel (pairedKilled ∘ₖ (pairedKilled ^ n)) + infer_instance + +noncomputable def hitBy : ℕ → OddState → ℝ≥0∞ + | 0, _ => 0 + | n + 1, s => ∫⁻ t, if t.1 ≤ 3 then 1 else hitBy n t ∂pairedOdd s + +theorem hitBy_measurable (n : ℕ) : Measurable (hitBy n) := by + induction n with + | zero => exact measurable_const + | succ n ih => + exact (Measurable.ite pairedRegeneration_measurable measurable_const ih).lintegral_kernel + +theorem paired_survival_balance (n : ℕ) (s : OddState) : + (pairedKilled ^ n) s univ + hitBy n s = 1 := by + induction n generalizing s with + | zero => + change (Measure.dirac s) univ + 0 = 1 + simp + | succ n ih => + have hp : pairedKilled ^ (n + 1) = (pairedKilled ^ n) ∘ₖ pairedKilled := pow_succ pairedKilled n + rw [hp, Kernel.comp_apply' _ _ _ MeasurableSet.univ, pairedKilled, Kernel.restrict_apply] + rw [← lintegral_indicator pairedRegeneration_measurable.compl] + change (∫⁻ t, pairedRegenerationᶜ.indicator (fun t => (pairedKilled ^ n) t univ) t ∂pairedOdd s) + + (∫⁻ t, if t.1 ≤ 3 then 1 else hitBy n t ∂pairedOdd s) = 1 + rw [← lintegral_add_left ((Kernel.measurable_coe (pairedKilled ^ n) MeasurableSet.univ).indicator + pairedRegeneration_measurable.compl)] + have heq : ∀ t : OddState, pairedRegenerationᶜ.indicator (fun t => (pairedKilled ^ n) t univ) t + + (if t.1 ≤ 3 then 1 else hitBy n t) = 1 := by + intro t + by_cases ht : t.1 ≤ 3 + · rw [ite_eq_left ht, indicator_of_notMem (show t ∉ pairedRegenerationᶜ from not_not_intro ht), zero_add] + · rw [ite_eq_right ht, indicator_of_mem (show t ∈ pairedRegenerationᶜ from ht)] + exact ih t + rw [lintegral_congr heq] + simp + +theorem hitBy_le_one (n : ℕ) (s : OddState) : hitBy n s ≤ 1 := by + calc + _ ≤ (pairedKilled ^ n) s univ + hitBy n s := le_add_of_nonneg_left zero_le + _ = 1 := paired_survival_balance n s + +theorem hitBy_lower {M : ℝ} (hM : 4 ≤ M) (n : ℕ) (hn : 0 < n) + (s : OddState) (hsM : s.1 ≤ M) (hsn : s.1 ≤ 3 + (3 / 2) * (n : ℝ)) : + (ENNReal.ofReal (goodPairProbability M)) ^ n ≤ hitBy n s := by + induction n generalizing s with + | zero => omega + | succ n ih => + let q : ℝ≥0∞ := ENNReal.ofReal (goodPairProbability M) + let B : Set OddState := {t | t.1 ≤ max (3 / 2) (s.1 - 3 / 2)} + have hB : MeasurableSet B := measurableSet_le measurable_subtype_coe measurable_const + have hq1 : q ≤ 1 := by + change ENNReal.ofReal (goodPairProbability M) ≤ 1 + exact (ENNReal.ofReal_le_one).mpr (goodPairProbability_le_one M) + have hpoint : ∀ t ∈ B, q ^ n ≤ (if t.1 ≤ 3 then 1 else hitBy n t) := by + intro t ht + have htbound : t.1 ≤ max (3 / 2) (s.1 - 3 / 2) := ht + have htM : t.1 ≤ M := le_trans htbound (max_le (by linarith) (by linarith)) + have htn : t.1 ≤ 3 + (3 / 2) * (n : ℝ) := by + apply le_trans htbound + apply max_le + · nlinarith [Nat.cast_nonneg (α := ℝ) n] + · push_cast at hsn + linarith + by_cases htR : t.1 ≤ 3 + · rw [ite_eq_left htR] + exact pow_le_one₀ zero_le hq1 + · rw [ite_eq_right htR] + have hn0 : 0 < n := by + by_contra h + have hnz : n = 0 := Nat.eq_zero_of_not_pos h + subst n + norm_num at htn + exact htR htn + exact ih hn0 t htM htn + change q ^ (n + 1) ≤ _ + calc + q ^ (n + 1) = q ^ n * q := pow_succ q n + _ ≤ q ^ n * pairedOdd s B := mul_le_mul le_rfl (pairedOdd_progress hM s hsM) zero_le zero_le + _ = ∫⁻ t in B, q ^ n ∂pairedOdd s := (setLIntegral_const _ _).symm + _ ≤ ∫⁻ t in B, (if t.1 ≤ 3 then 1 else hitBy n t) ∂pairedOdd s := by + apply lintegral_mono_ae + filter_upwards [self_mem_ae_restrict hB] with t ht + exact hpoint t ht + _ ≤ ∫⁻ t, (if t.1 ≤ 3 then 1 else hitBy n t) ∂pairedOdd s := setLIntegral_le_lintegral _ _ + _ = hitBy (n + 1) s := rfl + +theorem compact_paired_hit {M : ℝ} (hM : 4 ≤ M) : ∃ n : ℕ, 0 < n ∧ ∃ p : ℝ, 0 < p ∧ p ≤ 1 ∧ + ∀ s : OddState, s.1 ≤ M → ENNReal.ofReal p ≤ hitBy n s := by + obtain ⟨n, hn⟩ := exists_nat_ge M + refine ⟨n + 1, by omega, goodPairProbability M ^ (n + 1), + pow_pos (goodPairProbability_pos hM) _, pow_le_one₀ (goodPairProbability_pos hM).le (goodPairProbability_le_one M), ?_⟩ + intro s hs + rw [ENNReal.ofReal_pow (goodPairProbability_pos hM).le] + apply hitBy_lower hM (n + 1) (by omega) s hs + push_cast + nlinarith [Nat.cast_nonneg (α := ℝ) n] + +theorem paired_survival_le_one (n : ℕ) (s : OddState) : (pairedKilled ^ n) s univ ≤ 1 := by + calc + _ ≤ (pairedKilled ^ n) s univ + hitBy n s := le_add_of_nonneg_right zero_le + _ = 1 := paired_survival_balance n s + +theorem paired_survival_antitone (s : OddState) : Antitone (fun n => (pairedKilled ^ n) s univ) := by + apply antitone_nat_of_succ_le + intro n + have hp : pairedKilled ^ (n + 1) = pairedKilled ∘ₖ (pairedKilled ^ n) := pow_succ' pairedKilled n + rw [hp, Kernel.comp_apply' _ _ _ MeasurableSet.univ] + calc + _ ≤ ∫⁻ _t, (1 : ℝ≥0∞) ∂(pairedKilled ^ n) s := lintegral_mono (fun t => by + simpa only [pow_one] using paired_survival_le_one 1 t) + _ = _ := by simp + +theorem compact_paired_survival {M : ℝ} (hM : 4 ≤ M) : ∃ n : ℕ, 0 < n ∧ ∃ p : ℝ, 0 < p ∧ p ≤ 1 ∧ + ∀ m : ℕ, n ≤ m → ∀ s : OddState, s.1 ≤ M → + (pairedKilled ^ m) s univ ≤ ENNReal.ofReal (1 - p) := by + obtain ⟨n, hn, p, hp, hp1, hh⟩ := compact_paired_hit hM + refine ⟨n, hn, p, hp, hp1, ?_⟩ + intro m hnm s hs + have hsum : ENNReal.ofReal p + (pairedKilled ^ n) s univ ≤ 1 := by + calc + _ ≤ hitBy n s + (pairedKilled ^ n) s univ := add_le_add (hh s hs) le_rfl + _ = 1 := by rw [add_comm]; exact paired_survival_balance n s + have hQ := ENNReal.le_sub_of_add_le_left ENNReal.ofReal_ne_top hsum + rw [← ENNReal.ofReal_one, ← ENNReal.ofReal_sub 1 hp.le] at hQ + exact le_trans (paired_survival_antitone s hnm) hQ + +end NumberTheoryLean.PairedHitting + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/PrefixCompletions.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/PrefixCompletions.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2b3c4845fac764d1c77bebfaeab87f3a75e4c67 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/PrefixCompletions.lean @@ -0,0 +1,73 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FirstOmissionAntichain + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferencePruning +attribute [local instance] Classical.propDecidable +open ErdosPrimeInputs.PrimePrefixMass + +noncomputable def suffixPrimes (P : Finset ℕ) (pre : List ℕ) : Finset ℕ := + P.filter (fun q => ∀ p ∈ pre,q < p) + +theorem decreasing_prefix_mem {P : Finset ℕ} {pre suf : List ℕ} + (h : pre++suf ∈ decreasingPrefixes P) : pre ∈ decreasingPrefixes P := by + obtain ⟨hp,hm⟩ := mem_decreasingPrefixes.mp h + exact mem_decreasingPrefixes.mpr ⟨(List.pairwise_append.mp hp).1, + fun p hpre => hm p (List.mem_append.mpr (Or.inl hpre))⟩ + +theorem append_mem_decreasing_iff {P : Finset ℕ} {pre suf : List ℕ} + (hpre : pre ∈ decreasingPrefixes P) : + pre++suf ∈ decreasingPrefixes P ↔ suf ∈ decreasingPrefixes (suffixPrimes P pre) := by + obtain ⟨hpp,hpm⟩ := mem_decreasingPrefixes.mp hpre + constructor + · intro h + obtain ⟨hp,hm⟩ := mem_decreasingPrefixes.mp h + obtain ⟨_,hs,hcross⟩ := List.pairwise_append.mp hp + apply mem_decreasingPrefixes.mpr + refine ⟨hs,?_⟩ + intro q hq + apply Finset.mem_filter.mpr + exact ⟨hm q (List.mem_append.mpr (Or.inr hq)),fun p hp => hcross p hp q hq⟩ + · intro h + obtain ⟨hs,hm⟩ := mem_decreasingPrefixes.mp h + apply mem_decreasingPrefixes.mpr + refine ⟨List.pairwise_append.mpr ⟨hpp,hs,?_⟩,?_⟩ + · intro p hp q hq + exact (Finset.mem_filter.mp (hm q hq)).2 p hp + · intro p hp + rcases List.mem_append.mp hp with hp | hp + · exact hpm p hp + · exact (Finset.mem_filter.mp (hm p hp)).1 + +theorem suffixPrimes_append_singleton {P : Finset ℕ} {pre : List ℕ} {p : ℕ} + (hp : pre++[p] ∈ decreasingPrefixes P) : + suffixPrimes P (pre++[p]) = P.filter (fun q => q < p) := by + have hcross := (List.pairwise_append.mp (mem_decreasingPrefixes.mp hp).1).2.2 + ext q + simp only [suffixPrimes,Finset.mem_filter] + constructor + · rintro ⟨hq,hall⟩ + exact ⟨hq,hall p (by simp)⟩ + · rintro ⟨hq,hqp⟩ + refine ⟨hq,?_⟩ + intro a ha + rcases List.mem_append.mp ha with ha | ha + · exact hqp.trans (hcross a ha p (by simp)) + · have he : a = p := by simpa only [List.mem_singleton] using ha + simpa only [he] using hqp + +noncomputable def completions (P : Finset ℕ) (pre : List ℕ) : Finset (List ℕ) := + (decreasingPrefixes (suffixPrimes P pre)).image (fun suf => pre++suf) + +end NumberTheoryLean.ReferencePruning + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/QuantitativeOrdinaryHit.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/QuantitativeOrdinaryHit.lean new file mode 100644 index 0000000000000000000000000000000000000000..be79cc4870ef332c9da007d086284db04637df7f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/QuantitativeOrdinaryHit.lean @@ -0,0 +1,94 @@ +import OAI.NumberTheory.Jacobsthal.Probability.MarkedCostHitReduction + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.TransitionKernels NumberTheoryLean.KernelPotential + +lemma absoluteBeginningWindow_mass_cost (z : RegCost) (v H : ℝ) : + potential (beginningWindow 0 v H) (beginningBelow 0 v) z univ = + potential (clockWindow v H) (clockBelow v) (beginningCost z) univ := by + have he := costProjection_potential (relativeBeginningCost_measurable 0) + (beginningBelow_projection 0 v) (beginningWindow_projection 0 v H) z + apply_fun (fun μ : Measure ℝ => μ univ) at he + rw [Measure.map_apply (relativeBeginningCost_measurable 0) MeasurableSet.univ,preimage_univ] at he + simpa only [relativeBeginningCost,sub_zero] using he + +lemma markedWindowSuccess_le_cost_hit (z : RegCost) (v H : ℝ) : + markedWindowSuccess v H z ≤ costCurrentHit v H (beginningCost z) univ := by + rw [markedWindowSuccess] + by_cases hz : beginningCost z < v + · rw [ite_eq_left hz,absoluteBeginningWindow_mass_cost] + have hsub : Iio v ⊆ (Icc v (v+H))ᶜ := by + intro x hx hs + exact (not_lt_of_ge hs.1) hx + exact restricted_crossing_le_current_hit markedClockKernel + (S := Icc v (v+H)) (T := Iio v) measurableSet_Icc measurableSet_Iio hsub _ hz + · rw [ite_eq_right hz] + split_ifs with hin + · exact currentHit_inside markedClockKernel (S := Icc v (v+H)) measurableSet_Icc + (beginningCost z) ⟨le_of_not_gt hz,hin⟩ + · exact zero_le + +theorem initialMarkedWindowSuccess_le_ordinaryHit (s : EvenState) (v H : ℝ) : + initialMarkedWindowSuccess s v H ≤ ordinaryInitialHitMass s v H := by + rw [ordinaryInitialHit_cost_law,initialMarkedWindowSuccess] + calc + _ ≤ ∫⁻ z, costCurrentHit v H (beginningCost z) univ ∂initialBeginningReg s := + lintegral_mono (fun z => markedWindowSuccess_le_cost_hit z v H) + _ = ∫⁻ T, costCurrentHit v H T univ ∂(initialBeginningReg s).map beginningCost := by + rw [lintegral_map ((costCurrentHit v H).measurable_coe MeasurableSet.univ) beginningCost_measurable] + _ = _ := by rw [initialBeginningReg_cost_law] + +theorem ordinaryInitialHit_exponential (S : ℝ) : ∃ eta C eta0 B : ℝ, + 0 < eta ∧ 0 < C ∧ 0 < eta0 ∧ 0 ≤ B ∧ ∀ s : EvenState, s.1 ≤ S → ∀ v H : ℝ, + 0 ≤ H → 1-ordinaryInitialHitMass s v H ≤ + ENNReal.ofReal (C*Real.exp (-eta*H)+B*Real.exp (-eta0*v)) := by + obtain ⟨eta,C,eta0,B,heta,hC,heta0,hB,hBound⟩ := initialMarkedWindow_exponential S + refine ⟨eta,C,eta0,B,heta,hC,heta0,hB,?_⟩ + intro s hs v H hH + apply tsub_le_iff_right.mpr + have he : 1 ≤ ordinaryInitialHitMass s v H+ + ENNReal.ofReal (C*Real.exp (-eta*H)+B*Real.exp (-eta0*v)) := by + calc + 1 = initialMarkedWindowSuccess s v H+initialMarkedWindowFailure s v H := + (initialMarkedWindow_partition s v H hH).symm + _ ≤ _ := add_le_add (initialMarkedWindowSuccess_le_ordinaryHit s v H) (hBound s hs v H hH) + simpa only [add_comm] using he + +theorem moving_ordinary_marked_hit {eps : ℝ} (heps : 0 < eps) : + ∃ rho : ℝ, 10 < rho ∧ ∀ K : ℝ, 0 < K → + ∀ᶠ w : ℝ in atTop, 3 ≤ w ∧ ∀ r : ℝ, w ≤ r → ∀ s : EvenState, + 199/100 ≤ s.1 → s.1 ≤ 23/10 → + 1-ordinaryInitialHitMass s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) ≤ ENNReal.ofReal eps := by + obtain ⟨rho,hrho,hMoving⟩ := moving_marked_window_capture heps + refine ⟨rho,hrho,?_⟩ + intro K hK + filter_upwards [hMoving K hK] with w hw + refine ⟨hw.1,?_⟩ + intro r hr s hs0 hs1 + have hOld := hw.2 r hr s hs0 hs1 + have hWidth : 0 ≤ Real.log (rho/10) := Real.log_nonneg (by linarith) + apply tsub_le_iff_right.mpr + have he : 1 ≤ ordinaryInitialHitMass s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10))+ + ENNReal.ofReal eps := by + calc + 1 = initialMarkedWindowSuccess s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10))+ + initialMarkedWindowFailure s (Real.log (r/(rho*K*(Real.log w)^2))) (Real.log (rho/10)) := + (initialMarkedWindow_partition _ _ _ hWidth).symm + _ ≤ _ := add_le_add (initialMarkedWindowSuccess_le_ordinaryHit _ _ _) hOld.1 + simpa only [add_comm] using he + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RawBoxRationalWitness.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawBoxRationalWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..3eadd9caebe9730105ac85e24d28bac7b0eb8f10 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawBoxRationalWitness.lean @@ -0,0 +1,260 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ParentProductReadout + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RecentCountWitness +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission ActualReferencePrefixes +open WordIntervalGeometry RecentReferenceSegment ActualCountErrorEdges FiniteErrorTelescoping SourcePrimeProductData +open LogarithmicBinPartition ErdosInverseCounts ErdosModulusRelative +open ErdosPrimeInputs.HarmonicPrimeMeasure + +attribute [local instance] Classical.propDecidable + +theorem recent_count_witness (K eps : ℝ) (hK : 3 ≤ K) (heps : 0 < eps) : + ∃ Kstar B₀ w₀ : ℝ,K+10 < Kstar ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ _hw : 1 < w,∀ _htop : w < top, + ∀ aStar : ℝ,0 ≤ aStar → aStar ≤ 1 → ∀ Y : ℕ,0 < Y → ∀ z : Node, + z.gap=Real.log (Y:ℝ)/Real.log w-aStar+2 → z.side=.even → 199/100 ≤ z.ratio → + Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ residue : ℕ → ℕ,∀ ps : List ℕ, + ps ∈ referencePrefixes w (sourcePrimeSet w top) z.side z.gap → + (terminal w z ps).gap ≤ K → + eps < |wordCountError Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue (SmallSieveFinite.smallEuler ⌊w⌋₊) ps| → + ∃ before u after,ps=before++u::after ∧ (u::after).length ≤ ⌈2*Kstar+10⌉₊ ∧ + NodeBadEdge Y (LargePrimeDeletion.cutoffPrimes ⌊w⌋₊) residue + (eps/(4*(⌈2*Kstar+10⌉₊:ℝ))) (SmallSieveFinite.smallEuler ⌊w⌋₊) before.prod u ∧ + wordIntervalExponent w Y before ≤ 2*Kstar+3 ∧ aStar ≤ wordIntervalExponent w Y (before++[u]) ∧ + primeExponent w u ≤ 2*Kstar+3 ∧ (terminal w z before).gap ≤ 2*Kstar+5 := by + obtain ⟨K0,W,hK0,hW,hSmall⟩ := uniform_modulus_small_relative (eps/2) (by positivity) + let Kstar := max (K+11) K0 + have hKstar : K+10 < Kstar := (by linarith : K+10 (a p:ℤ)) S R Z cp, + aligns (fun p => (a p:ℤ)) t (pickedPrime f i) ∧ + ((t.den*badPrimeProduct (fun p => (a p:ℤ)) t (selectionProduct (parentCofactorSelection f i j)):ℕ):ℝ) ≤ R*Z^10 := by + have hc := full_selection_coordinates P m f hf i j hi hj + have hnot : ((pickedPrime f i,selectionProduct (parentCofactorSelection f i j)),pickedPrime f j) ∉ + actualInverseException Y small a delta V0 S R Z cp (P i) + (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j) := by + intro he + have hh := (mem_actualInverseException Y small a delta V0 S R Z cp _ _ _ _ _ _).mp he + exact hout ⟨hh.2.2.2.1,hh.2.2.2.2⟩ + exact hInv.2.2.2 _ hc.1 _ hc.2.2 _ hc.2.1 hnot hbad +end NumberTheoryLean.StructuredWitnessOutside + + + +namespace NumberTheoryLean.RawBoxRationalWitness +open ErdosCofactorChoices ErdosSubsetWord ErdosInverseCounts ErdosInverseBoxApplication ErdosInverseSampleCost +open ErdosInverseAlignment ErdosInverseStructured ErdosPrimitiveIntercept +open StructuredWitnessOutside TwoPrimeObservableSum ParentTailPartition ParentCofactorChoices + +attribute [local instance] Classical.propDecidable + +noncomputable def rawBoxList {n : ℕ} (P : Fin n → Finset ℕ) (i : Fin n) (J : Finset (Fin n)) + (a : ℕ → ℕ) (S : Fin n → ℝ) (R Z cp : ℝ) : Finset ℚ := + J.biUnion (fun j => sourceRationalList (P i) (fun p => (a p:ℤ)) (S j) R Z cp) + +theorem raw_box_list_card {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (J : Finset (Fin n)) + (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) (S : Fin n → ℝ) (R Z cp sigma : ℝ) (F : ℕ) + (hInv : ∀ j∈J,SourceInverseConclusion Y small a delta V0 (S j) R Z cp sigma F + (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j)) : + (rawBoxList P i J a S R Z cp).card ≤ J.card*F := by + have hh := (Finset.card_biUnion_le : (rawBoxList P i J a S R Z cp).card ≤ + ∑ j∈J,(sourceRationalList (P i) (fun p => (a p:ℤ)) (S j) R Z cp).card) + exact hh.trans ((Finset.sum_le_sum (fun j hj => (hInv j hj).1)).trans_eq (by simp)) + +theorem raw_box_witness {n : ℕ} (P : Fin n → Finset ℕ) (m : Fin n → ℕ) (i : Fin n) (J : Finset (Fin n)) + (f : Fin n → Finset ℕ) (hf : f ∈ selections P m) (hi : m i=1) (hj : ∀ j∈J,m j=1) + (Y : ℕ) (small : Finset ℕ) (a : ℕ → ℕ) (delta V0 : ℝ) (S : Fin n → ℝ) (R Z cp sigma : ℝ) (F : ℕ) + (hInv : ∀ j∈J,SourceInverseConclusion Y small a delta V0 (S j) R Z cp sigma F + (P i) (cofactorChoices P (parentCofactorMultiplicity m i j)) (P j)) + (hbad : ∃ j∈J,WitnessingBadEdge Y small a delta V0 (pickedPrime f i) + (selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j)) + (hout : ¬∃ j∈J,actualWitness Y small a delta V0 (P i) (S j) R Z cp + (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j)) : + ∃ j∈J,∃ t∈rawBoxList P i J a S R Z cp, + t ∈ sourceRationalList (P i) (fun p => (a p:ℤ)) (S j) R Z cp ∧ + aligns (fun p => (a p:ℤ)) t (pickedPrime f i) ∧ + ((t.den*badPrimeProduct (fun p => (a p:ℤ)) t (selectionProduct (parentCofactorSelection f i j)):ℕ):ℝ) ≤ R*Z^10 := by + obtain ⟨j,hjJ,hb⟩ := hbad + have hno : ¬actualWitness Y small a delta V0 (P i) (S j) R Z cp + (pickedPrime f i,selectionProduct (parentCofactorSelection f i j)) (pickedPrime f j) := + fun h => hout ⟨j,hjJ,h⟩ + obtain ⟨t,ht,ha,hd⟩ := structured_full_selection P m f hf i j hi (hj j hjJ) Y small a delta V0 (S j) R Z cp sigma F + (hInv j hjJ) hb hno + exact ⟨j,hjJ,t,Finset.mem_biUnion.mpr ⟨j,hjJ,ht⟩,ht,ha,hd⟩ +end NumberTheoryLean.RawBoxRationalWitness + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RawFullHitIncreasing.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawFullHitIncreasing.lean new file mode 100644 index 0000000000000000000000000000000000000000..926341bea963b2eb34da68e6c959eb0d46ba0d31 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawFullHitIncreasing.lean @@ -0,0 +1,72 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RawInitialIncreasing + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures + +noncomputable def hitIncreasing (a b : ℕ) : Set (RawMarkedHitTrace b) := + {r | lastRawCycle b (List.ofFn r.2.1) true r.2.2 ∈ selectedIncreasing a} + +lemma hitIncreasing_measurable (a b : ℕ) : MeasurableSet (hitIncreasing a b) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + apply MeasurableSpace.measurableSet_iInf.mpr + intro f + exact (selectedIncreasing_measurable a).preimage (lastRawCycle_measurable (List.ofFn f) b true) + +lemma rawFirstHit_increasing (a b : ℕ) (v H : ℝ) (h : RawHistory b) (hh : h ∈ increasingCosts a b) : + ∀ᵐ r ∂rawMarkedFirstHitKernel b v H h, r ∈ hitIncreasing a b := by + rw [rawMarkedFirstHitKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.sum_apply,Measure.ae_sum_iff] + intro f + rw [Kernel.map_apply _ (packRawMarkedHitTrace_measurable b n f)] + apply (ae_map_iff (packRawMarkedHitTrace_measurable b n f).aemeasurable (hitIncreasing_measurable a b)).mpr + rw [rawHitWordKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (lastRawCycle_increasing a (List.ofFn f) b true h hh) + +lemma rawRegFirstHit_increasing (a b : ℕ) (v H : ℝ) (h : RawHistory b) (hh : h ∈ increasingCosts a b) : + ∀ᵐ r ∂rawRegMarkedFirstHitKernel b v H h, r ∈ hitIncreasing a b := by + rw [rawRegMarkedFirstHitKernel,stateFilter_input] + split_ifs + · exact rawFirstHit_increasing a b v H h hh + · simp + +noncomputable def evenHitIncreasing (a : ℕ) : Set (RawEvenMarkedHitTrace a) := + {r | rawEvenFinalCycle a r ∈ selectedIncreasing a} + +lemma evenHitIncreasing_measurable (a : ℕ) : MeasurableSet (evenHitIncreasing a) := + (selectedIncreasing_measurable a).preimage (rawEvenFinalCycle_measurable a) + +theorem rawEvenHit_increasing (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ r ∂rawEvenMarkedHitKernel a v H h, r ∈ evenHitIncreasing a := by + rw [rawEvenMarkedHitKernel] + apply Kernel.ae_comp_of_ae_ae (evenHitIncreasing_measurable a) + filter_upwards [packedInitial_increasing a h] with r hr + rcases r with ⟨k,y⟩ + rw [rawEvenHitContinuation,sigmaFamilyKernel_apply] + apply (ae_map_iff (measurableSigmaMk k).aemeasurable (evenHitIncreasing_measurable a)).mpr + have he : ((Kernel.id : Kernel (RawHistory ((a+1)+2*k)) (RawHistory ((a+1)+2*k))) ×ₖ + rawRegMarkedFirstHitKernel ((a+1)+2*k) v H) y = + (rawRegMarkedFirstHitKernel ((a+1)+2*k) v H y).map (Prod.mk y) := by + ext S hS + rw [Kernel.id_prod_apply' _ _ hS,Measure.map_apply measurable_prodMk_left hS] + rw [he] + exact (ae_map_iff measurable_prodMk_left.aemeasurable + ((evenHitIncreasing_measurable a).preimage (measurableSigmaMk k))).mpr + (rawRegFirstHit_increasing a _ v H y hr) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RawIncreasingPrefix.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawIncreasingPrefix.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e303b9d13bfbde29e0bf48dbd12a81f5c2af5c2 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawIncreasingPrefix.lean @@ -0,0 +1,204 @@ +import OAI.NumberTheory.Jacobsthal.Renewal.RawHitRegeneration + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.TransitionKernels + +lemma actualCostKernel_strict (z : CostState) : ∀ᵐ y ∂costKernel z, z.2 < y.2 := by + have hm : MeasurableSet {y : CostState | z.2 < y.2} := measurableSet_lt measurable_const measurable_snd + apply (ae_mem_iff_measure_eq hm.nullMeasurableSet).mpr + rw [costKernel_apply z hm] + have he : {s : State | z.2 < (s,z.2+cost (stateRatio s)).2}=univ := by + apply eq_univ_of_forall + intro s + have hp := cost_pos (valid_pos (stateRatio_valid s)) + exact lt_add_of_pos_right z.2 hp + simp only [mem_ofPred_eq] + rw [he] + simp + +lemma rawExtension_strict_step (k : ℕ) (h : RawHistory k) : + ∀ᵐ y ∂rawExtension k (k+1) h, + (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩).2 < (rawLast (k+1) y).2 := by + have hs : ∀ᵐ y ∂rawExtension k (k+1) h, (rawLast k h).2 < (rawLast (k+1) y).2 := by + apply (ae_map_iff (rawLast_measurable (k+1)).aemeasurable + (measurableSet_lt measurable_const measurable_snd)).mp + rw [rawExtension_last_step] + exact actualCostKernel_strict _ + filter_upwards [hs,rawExtension_retains_prefix (show k ≤ k+1 by omega) h] with y hy hp + have he := congrFun hp (⟨k,by simp⟩ : Finset.Iic k) + change y ⟨k,_⟩=rawLast k h at he + rw [he] + exact hy + +lemma rawExtension_strict_coordinate {a b k : ℕ} (hak : a ≤ k) (hkb : k < b) (h : RawHistory a) : + ∀ᵐ y ∂rawExtension a b h, + (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩).2 < + (y ⟨k+1,Finset.mem_Iic.mpr (by omega)⟩).2 := by + have hm : MeasurableSet {y : RawHistory (k+1) | + (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩).2 < (rawLast (k+1) y).2} := + measurableSet_lt (measurable_snd.comp (measurable_pi_apply _)) + (measurable_snd.comp (rawLast_measurable _)) + have he : (rawExtension a b h).map (rawPrefix (show k+1 ≤ b by omega))=rawExtension a (k+1) h := + Kernel.partialTraj_map_frestrictLe₂_apply (X := fun _ => CostState) (κ := historyKernel) h (show k+1 ≤ b by omega) + have ht : ∀ᵐ y ∂rawExtension a (k+1) h, + (y ⟨k,Finset.mem_Iic.mpr (by omega)⟩).2 < (rawLast (k+1) y).2 := by + have hc : rawExtension a (k+1)=rawExtension k (k+1) ∘ₖ rawExtension a k := + (Kernel.partialTraj_comp_partialTraj hak (by omega)).symm + rw [hc] + exact Kernel.ae_comp_of_ae_ae hm (Eventually.of_forall (rawExtension_strict_step k)) + rw [← he] at ht + exact (ae_map_iff (rawPrefix_measurable (show k+1 ≤ b by omega)).aemeasurable hm).mp ht + +noncomputable def increasingCosts (a b : ℕ) : Set (RawHistory b) := + {h | ∀ i j : Finset.Iic b, a ≤ i.1 → i.1 ≤ j.1 → (h i).2 ≤ (h j).2} + +lemma increasingCosts_measurable (a b : ℕ) : MeasurableSet (increasingCosts a b) := by + unfold increasingCosts + simp only [ofPred_forall] + apply MeasurableSet.iInter + intro i + apply MeasurableSet.iInter + intro j + apply MeasurableSet.iInter + intro _hi + apply MeasurableSet.iInter + intro _hij + exact measurableSet_le (measurable_snd.comp (measurable_pi_apply i)) + (measurable_snd.comp (measurable_pi_apply j)) + +lemma increasingCosts_of_steps {a b : ℕ} (h : RawHistory b) + (hs : ∀ k : Fin b, a ≤ k.1 → + (h ⟨k.1,Finset.mem_Iic.mpr (by have hk:=k.2; omega)⟩).2 ≤ + (h ⟨k.1+1,Finset.mem_Iic.mpr (by have hk:=k.2; omega)⟩).2) : + h ∈ increasingCosts a b := by + intro i j hai hij + have aux : ∀ m, i.1 ≤ m → ∀ hm : m ≤ b, (h i).2 ≤ (h ⟨m,Finset.mem_Iic.mpr hm⟩).2 := by + intro m him + induction m,him using Nat.le_induction with + | base => intro hm; exact le_rfl + | succ m him ih => + intro hmb + have hmb' : m < b := by omega + exact (ih (by omega)).trans (hs ⟨m,hmb'⟩ (hai.trans him)) + exact aux j.1 hij (Finset.mem_Iic.mp j.2) + +theorem rawExtension_increasingCosts (a b : ℕ) (h : RawHistory a) : + ∀ᵐ y ∂rawExtension a b h, y ∈ increasingCosts a b := by + have hs : ∀ᵐ y ∂rawExtension a b h, ∀ k : Fin b, a ≤ k.1 → + (y ⟨k.1,Finset.mem_Iic.mpr (by have hk:=k.2; omega)⟩).2 < + (y ⟨k.1+1,Finset.mem_Iic.mpr (by have hk:=k.2; omega)⟩).2 := by + rw [ae_all_iff] + intro k + by_cases hak : a ≤ k.1 + · filter_upwards [rawExtension_strict_coordinate hak k.2 h] with y hy + exact fun _ => hy + · exact Eventually.of_forall (fun _ hy => (hak hy).elim) + filter_upwards [hs] with y hy + exact increasingCosts_of_steps y (fun k hk => (hy k hk).le) + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures + +lemma increasingCosts_at_start (a : ℕ) (h : RawHistory a) : h ∈ increasingCosts a a := by + intro i j hai hij + have hi : i.1=a := by have := Finset.mem_Iic.mp i.2; omega + have hj : j.1=a := by have := Finset.mem_Iic.mp j.2; omega + have he : i=j := Subtype.ext (hi.trans hj.symm) + rw [he] + +lemma increasingCosts_extend {a b c : ℕ} (hbc : b ≤ c) (h : RawHistory b) (y : RawHistory c) + (hOld : h ∈ increasingCosts a b) (hNew : y ∈ increasingCosts b c) (hp : rawPrefix hbc y=h) : + y ∈ increasingCosts a c := by + intro i j hai hij + have hv (k : Finset.Iic b) : y ⟨k.1,Finset.mem_Iic.mpr ((Finset.mem_Iic.mp k.2).trans hbc)⟩=h k := + congrFun hp k + by_cases hjb : j.1 ≤ b + · have hib : i.1 ≤ b := hij.trans hjb + have he := hOld ⟨i.1,Finset.mem_Iic.mpr hib⟩ ⟨j.1,Finset.mem_Iic.mpr hjb⟩ hai hij + simpa only [← hv] using he + · by_cases hib : b ≤ i.1 + · exact hNew i j hib hij + · have hib' : i.1 ≤ b := by omega + have h1 := hOld ⟨i.1,Finset.mem_Iic.mpr hib'⟩ ⟨b,by simp⟩ hai hib' + have h2 := hNew ⟨b,Finset.mem_Iic.mpr hbc⟩ j le_rfl (show b ≤ j.1 by omega) + have h1' : (y i).2 ≤ (y ⟨b,Finset.mem_Iic.mpr hbc⟩).2 := by + simpa only [← hv] using h1 + exact h1'.trans h2 + +lemma rawExtension_preserves_increasing {a b c : ℕ} (hbc : b ≤ c) (h : RawHistory b) + (hh : h ∈ increasingCosts a b) : + ∀ᵐ y ∂rawExtension b c h, y ∈ increasingCosts a c := by + filter_upwards [rawExtension_increasingCosts b c h,rawExtension_retains_prefix hbc h] with y hy hp + exact increasingCosts_extend hbc h y hh hy hp + +noncomputable def returnIncreasing (a b : ℕ) : Set (RawReturnTrace b) := + {r | r.2 ∈ increasingCosts a (b+2*(r.1+1))} + +lemma returnIncreasing_measurable (a b : ℕ) : MeasurableSet (returnIncreasing a b) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + exact increasingCosts_measurable a (b+2*(n+1)) + +lemma rawReturn_increasing (a b : ℕ) (h : RawHistory b) (hh : h ∈ increasingCosts a b) : + ∀ᵐ r ∂rawReturnTraceKernel b h, r ∈ returnIncreasing a b := by + rw [rawReturnTraceKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable b n)] + apply (ae_map_iff (rawReturnTrace_mk_measurable b n).aemeasurable (returnIncreasing_measurable a b)).mpr + rw [firstReturnHistory,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawExtension_preserves_increasing (by omega) h hh) + +lemma rawBranchReturn_increasing (a b : ℕ) (c : Bool) (h : RawHistory b) (hh : h ∈ increasingCosts a b) : + ∀ᵐ r ∂rawBranchReturnKernel b c h, r ∈ returnIncreasing a b := by + rw [rawBranchReturnKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawReturn_increasing a b h hh) + +noncomputable def selectedIncreasing (a : ℕ) : Set (Σ t : ℕ, RawReturnTrace t) := + {r | r.2 ∈ returnIncreasing a r.1} + +lemma selectedIncreasing_measurable (a : ℕ) : MeasurableSet (selectedIncreasing a) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro b + exact returnIncreasing_measurable a b + +lemma lastRawCycle_increasing (a : ℕ) (w : List Bool) : ∀ b c h, + h ∈ increasingCosts a b → + ∀ᵐ r ∂rawMarkedWordKernel b (w++[c]) h, lastRawCycle b w c r ∈ selectedIncreasing a := by + induction w with + | nil => + intro b c h hh + apply rawMarkedWord_cons_ae b c [] h + ((selectedIncreasing_measurable a).preimage (lastRawCycle_measurable [] b c)) + filter_upwards [rawBranchReturn_increasing a b c h hh] with r hr + exact Eventually.of_forall (fun _ => hr) + | cons d w ih => + intro b c h hh + apply rawMarkedWord_cons_ae b d (w++[c]) h + ((selectedIncreasing_measurable a).preimage (lastRawCycle_measurable (d::w) b c)) + filter_upwards [rawBranchReturn_increasing a b d h hh] with r hr + exact ih _ c r.2 hr + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RawPhysicalHit.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawPhysicalHit.lean new file mode 100644 index 0000000000000000000000000000000000000000..963ab4acd14951c697072efc4608cbb1bdccedbe --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawPhysicalHit.lean @@ -0,0 +1,111 @@ +import OAI.NumberTheory.Jacobsthal.Probability.PhysicalMarkedRecord + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.TransitionKernels + +noncomputable def rawHitRecord (a : ℕ) (r : RawMarkedHitTrace a) : CycleInputSignature := + lastCycleRecord (List.ofFn r.2.1) true + (rawCycleWordSignature a (List.ofFn r.2.1++[true]).length r.2.2) + +lemma rawHitRecord_measurable (a : ℕ) : Measurable (rawHitRecord a) := by + apply measurable_sigma_family + intro n + apply measurable_sigma_family + intro f + exact (lastCycleRecord_measurable (List.ofFn f) true).comp (rawCycleWordSignature_measurable _ a) + +lemma rawWord_last_physical (a : ℕ) (w : List Bool) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + ∀ᵐ s ∂rawMarkedWordKernel a (w++[true]) h, + lastCycleRecord w true (rawCycleWordSignature a (w++[true]).length s) ∈ physicalMarkedRecord := by + have hP : MeasurableSet {s | lastCycleRecord w true s ∈ physicalMarkedRecord} := + physicalMarkedRecord_measurable.preimage (lastCycleRecord_measurable w true) + apply (ae_map_iff (rawCycleWordSignature_measurable _ a).aemeasurable hP).mp + rw [rawMarkedWord_signature (w++[true]) a h z hz] + exact sourceLastRecord_ae_physical w z + +lemma rawFirstHit_ae_physical (a : ℕ) (v H : ℝ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + ∀ᵐ r ∂rawMarkedFirstHitKernel a v H h, rawHitRecord a r ∈ physicalMarkedRecord := by + rw [rawMarkedFirstHitKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.sum_apply,Measure.ae_sum_iff] + intro f + rw [Kernel.map_apply _ (packRawMarkedHitTrace_measurable a n f)] + apply (ae_map_iff (packRawMarkedHitTrace_measurable a n f).aemeasurable + (physicalMarkedRecord_measurable.preimage (rawHitRecord_measurable a))).mpr + rw [rawHitWordKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawWord_last_physical a (List.ofFn f) h z hz) + +lemma rawFirstHit_ae_input_window (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ r ∂rawMarkedFirstHitKernel a v H h, (rawHitRecord a r).1 ∈ Icc v (v+H) := by + filter_upwards [rawMarkedFirstHit_ae_event a v H h] with r hr + exact hitWordEvent_last_cost (List.ofFn r.2.1) v H _ hr + +noncomputable def rawPhysicalHitEvent (a : ℕ) (v H : ℝ) : Set (RawMarkedHitTrace a) := + {r | rawHitRecord a r ∈ physicalMarkedRecord ∧ (rawHitRecord a r).1 ∈ Icc v (v+H)} + +lemma rawPhysicalHitEvent_measurable (a : ℕ) (v H : ℝ) : MeasurableSet (rawPhysicalHitEvent a v H) := + (physicalMarkedRecord_measurable.preimage (rawHitRecord_measurable a)).inter + (measurableSet_Icc.preimage (measurable_fst.comp (rawHitRecord_measurable a))) + +lemma rawRegFirstHit_ae_physical (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ r ∂rawRegMarkedFirstHitKernel a v H h, r ∈ rawPhysicalHitEvent a v H := by + rw [rawRegMarkedFirstHitKernel,stateFilter_input] + by_cases hr : h ∈ lastRegeneration a + · rw [ite_eq_left hr] + let z := decodeReturnedOdd (rawLast a h) + have hz : rawLast a h=embedOdd z := (embed_decodeReturnedOdd_of_regeneration _ hr).symm + filter_upwards [rawFirstHit_ae_physical a v H h z hz,rawFirstHit_ae_input_window a v H h] with r hP hW + exact ⟨hP,hW⟩ + · simp [hr] + +noncomputable def rawEvenHitRecord (a : ℕ) (r : RawEvenMarkedHitTrace a) : CycleInputSignature := + rawHitRecord ((a+1)+2*r.1) r.2.2 + +lemma rawEvenHitRecord_measurable (a : ℕ) : Measurable (rawEvenHitRecord a) := by + apply measurable_sigma_family + intro k + exact (rawHitRecord_measurable _).comp measurable_snd + +noncomputable def rawEvenPhysicalHitEvent (a : ℕ) (v H : ℝ) : Set (RawEvenMarkedHitTrace a) := + {r | rawEvenHitRecord a r ∈ physicalMarkedRecord ∧ (rawEvenHitRecord a r).1 ∈ Icc v (v+H)} + +lemma rawEvenPhysicalHitEvent_measurable (a : ℕ) (v H : ℝ) : MeasurableSet (rawEvenPhysicalHitEvent a v H) := + (physicalMarkedRecord_measurable.preimage (rawEvenHitRecord_measurable a)).inter + (measurableSet_Icc.preimage (measurable_fst.comp (rawEvenHitRecord_measurable a))) + +theorem rawEvenHit_ae_physical (a : ℕ) (v H : ℝ) (h : RawHistory a) : + ∀ᵐ r ∂rawEvenMarkedHitKernel a v H h, r ∈ rawEvenPhysicalHitEvent a v H := by + rw [rawEvenMarkedHitKernel] + apply Kernel.ae_comp_of_ae_ae (rawEvenPhysicalHitEvent_measurable a v H) + apply Eventually.of_forall + rintro ⟨k,y⟩ + rw [rawEvenHitContinuation,sigmaFamilyKernel_apply] + apply (ae_map_iff (measurableSigmaMk k).aemeasurable (rawEvenPhysicalHitEvent_measurable a v H)).mpr + have he : ((Kernel.id : Kernel (RawHistory ((a+1)+2*k)) (RawHistory ((a+1)+2*k))) ×ₖ + rawRegMarkedFirstHitKernel ((a+1)+2*k) v H) y = + (rawRegMarkedFirstHitKernel ((a+1)+2*k) v H y).map (Prod.mk y) := by + ext S hS + rw [Kernel.id_prod_apply' _ _ hS,Measure.map_apply measurable_prodMk_left hS] + rw [he] + apply (ae_map_iff measurable_prodMk_left.aemeasurable + ((rawEvenPhysicalHitEvent_measurable a v H).preimage (measurableSigmaMk k))).mpr + exact rawRegFirstHit_ae_physical _ v H y + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RawStableHistory.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawStableHistory.lean new file mode 100644 index 0000000000000000000000000000000000000000..27580121906d82bc6d9344d99c9a407d113d934a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawStableHistory.lean @@ -0,0 +1,161 @@ +import OAI.NumberTheory.Jacobsthal.Probability.GenuineMarkedVisit + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical + +variable (P : (n : ℕ) → Set (RawHistory n)) (hP : ∀ n, MeasurableSet (P n)) +variable (hExt : ∀ b c, b ≤ c → ∀ h ∈ P b, ∀ᵐ y ∂rawExtension b c h, y ∈ P c) + +noncomputable def returnHistoryProperty (b : ℕ) : Set (RawReturnTrace b) := + {r | r.2 ∈ P (b+2*(r.1+1))} + +include hP in +lemma returnHistoryProperty_measurable (b : ℕ) : MeasurableSet (returnHistoryProperty P b) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + exact hP _ + +include hP hExt in +lemma rawReturn_historyProperty (b : ℕ) (h : RawHistory b) (hh : h ∈ P b) : + ∀ᵐ r ∂rawReturnTraceKernel b h, r ∈ returnHistoryProperty P b := by + rw [rawReturnTraceKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable b n)] + apply (ae_map_iff (rawReturnTrace_mk_measurable b n).aemeasurable (returnHistoryProperty_measurable P hP b)).mpr + rw [firstReturnHistory,Kernel.restrict_apply] + exact ae_restrict_of_ae (hExt _ _ (by omega) h hh) + +noncomputable def selectedHistoryProperty : Set (Σ t : ℕ, RawReturnTrace t) := + {r | r.2 ∈ returnHistoryProperty P r.1} + +include hP in +lemma selectedHistoryProperty_measurable : MeasurableSet (selectedHistoryProperty P) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro b + exact returnHistoryProperty_measurable P hP b + +include hP hExt in +lemma lastRawCycle_historyProperty (w : List Bool) : ∀ b c h, h ∈ P b → + ∀ᵐ r ∂rawMarkedWordKernel b (w++[c]) h, lastRawCycle b w c r ∈ selectedHistoryProperty P := by + have hBranch (b : ℕ) (c : Bool) (h : RawHistory b) (hh : h ∈ P b) : + ∀ᵐ r ∂rawBranchReturnKernel b c h, r ∈ returnHistoryProperty P b := by + rw [rawBranchReturnKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawReturn_historyProperty P hP hExt b h hh) + induction w with + | nil => + intro b c h hh + apply rawMarkedWord_cons_ae b c [] h + ((selectedHistoryProperty_measurable P hP).preimage (lastRawCycle_measurable [] b c)) + filter_upwards [hBranch b c h hh] with r hr + exact Eventually.of_forall (fun _ => hr) + | cons d w ih => + intro b c h hh + apply rawMarkedWord_cons_ae b d (w++[c]) h + ((selectedHistoryProperty_measurable P hP).preimage (lastRawCycle_measurable (d::w) b c)) + filter_upwards [hBranch b d h hh] with r hr + exact ih _ c r.2 hr + +noncomputable def continuationHistoryProperty (b : ℕ) : Set (RawContinuationTrace b) := + {r | Sum.elim (fun h => h ∈ P b) (fun r => r ∈ returnHistoryProperty P b) r} + +include hP in +lemma continuationHistoryProperty_measurable (b : ℕ) : MeasurableSet (continuationHistoryProperty P b) := + measurableSet_sum_iff.mpr ⟨hP b,returnHistoryProperty_measurable P hP b⟩ + +include hP hExt in +lemma rawContinuation_historyProperty (b : ℕ) (h : RawHistory b) (hh : h ∈ P b) : + ∀ᵐ r ∂rawContinuationKernel b h, r ∈ continuationHistoryProperty P b := by + rw [rawContinuationKernel,Kernel.piecewise_apply] + split_ifs + · rw [Kernel.map_apply _ measurable_inl] + apply (ae_map_iff measurable_inl.aemeasurable (continuationHistoryProperty_measurable P hP b)).mpr + change ∀ᵐ y ∂Measure.dirac h, y ∈ P b + exact (ae_dirac_iff (hP b)).mpr hh + · rw [Kernel.map_apply _ measurable_inr] + exact (ae_map_iff measurable_inr.aemeasurable (continuationHistoryProperty_measurable P hP b)).mpr + (rawReturn_historyProperty P hP hExt b h hh) + +noncomputable def packedHistoryProperty (a : ℕ) : Set (RawInitialPackedTrace a) := + {r | r.2 ∈ P ((a+1)+2*r.1)} + +include hP in +lemma packedHistoryProperty_measurable (a : ℕ) : MeasurableSet (packedHistoryProperty P a) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro k + exact hP _ + +include hP hExt in +lemma packedInitial_historyProperty (a : ℕ) (h : RawHistory a) (hh : h ∈ P a) : + ∀ᵐ r ∂packedInitialKernel a h, r ∈ packedHistoryProperty P a := by + rw [packedInitialKernel,Kernel.map_apply _ (packRawInitialEven_measurable a)] + apply (ae_map_iff (packRawInitialEven_measurable a).aemeasurable (packedHistoryProperty_measurable P hP a)).mpr + have hs : ∀ᵐ r ∂rawInitialEvenKernel a h, r ∈ continuationHistoryProperty P (a+1) := by + rw [rawInitialEvenKernel] + apply Kernel.ae_comp_of_ae_ae (continuationHistoryProperty_measurable P hP (a+1)) + filter_upwards [hExt a (a+1) (by omega) h hh] with y hy + exact rawContinuation_historyProperty P hP hExt (a+1) y hy + filter_upwards [hs] with r hr + cases r with + | inl y => exact hr + | inr y => exact hr + +noncomputable def hitHistoryProperty (b : ℕ) : Set (RawMarkedHitTrace b) := + {r | lastRawCycle b (List.ofFn r.2.1) true r.2.2 ∈ selectedHistoryProperty P} + +include hP in +lemma hitHistoryProperty_measurable (b : ℕ) : MeasurableSet (hitHistoryProperty P b) := by + apply MeasurableSpace.measurableSet_iInf.mpr + intro n + apply MeasurableSpace.measurableSet_iInf.mpr + intro f + exact (selectedHistoryProperty_measurable P hP).preimage (lastRawCycle_measurable (List.ofFn f) b true) + +include hP hExt in +lemma rawRegFirstHit_historyProperty (b : ℕ) (v H : ℝ) (h : RawHistory b) (hh : h ∈ P b) : + ∀ᵐ r ∂rawRegMarkedFirstHitKernel b v H h, r ∈ hitHistoryProperty P b := by + rw [rawRegMarkedFirstHitKernel,stateFilter_input] + split_ifs + · rw [rawMarkedFirstHitKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.sum_apply,Measure.ae_sum_iff] + intro f + rw [Kernel.map_apply _ (packRawMarkedHitTrace_measurable b n f)] + apply (ae_map_iff (packRawMarkedHitTrace_measurable b n f).aemeasurable (hitHistoryProperty_measurable P hP b)).mpr + rw [rawHitWordKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (lastRawCycle_historyProperty P hP hExt (List.ofFn f) b true h hh) + · simp + +include hP hExt in +theorem rawEvenHit_historyProperty (a : ℕ) (v H : ℝ) (h : RawHistory a) (hh : h ∈ P a) : + ∀ᵐ r ∂rawEvenMarkedHitKernel a v H h, rawEvenFinalCycle a r ∈ selectedHistoryProperty P := by + have hm : MeasurableSet {r | rawEvenFinalCycle a r ∈ selectedHistoryProperty P} := + (selectedHistoryProperty_measurable P hP).preimage (rawEvenFinalCycle_measurable a) + rw [rawEvenMarkedHitKernel] + apply Kernel.ae_comp_of_ae_ae hm + filter_upwards [packedInitial_historyProperty P hP hExt a h hh] with r hr + rcases r with ⟨k,y⟩ + rw [rawEvenHitContinuation,sigmaFamilyKernel_apply] + apply (ae_map_iff (measurableSigmaMk k).aemeasurable hm).mpr + have he : ((Kernel.id : Kernel (RawHistory ((a+1)+2*k)) (RawHistory ((a+1)+2*k))) ×ₖ + rawRegMarkedFirstHitKernel ((a+1)+2*k) v H) y = + (rawRegMarkedFirstHitKernel ((a+1)+2*k) v H y).map (Prod.mk y) := by + ext S hS + rw [Kernel.id_prod_apply' _ _ hS,Measure.map_apply measurable_prodMk_left hS] + rw [he] + exact (ae_map_iff measurable_prodMk_left.aemeasurable (hm.preimage (measurableSigmaMk k))).mpr + (rawRegFirstHit_historyProperty P hP hExt _ v H y hr) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RawWordBridgeInputs.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawWordBridgeInputs.lean new file mode 100644 index 0000000000000000000000000000000000000000..c3cb417c1cda342898a486fe41de0a5779bca426 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawWordBridgeInputs.lean @@ -0,0 +1,86 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RawMarkedWords +import OAI.NumberTheory.Jacobsthal.Probability.SourceMarkedWords + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FirstHitKernels +open NumberTheoryLean.RegenerationTails + +lemma rawReturnInputCost_ae (a : ℕ) (h : RawHistory a) : + ∀ᵐ r ∂rawReturnTraceKernel a h, rawReturnInputCost a r=(rawLast a h).2 := by + have hm : MeasurableSet {r : RawReturnTrace a | rawReturnInputCost a r=(rawLast a h).2} := + measurableSet_eq_fun (rawReturnInputCost_measurable a) measurable_const + rw [rawReturnTraceKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable a n)] + apply (ae_map_iff (rawReturnTrace_mk_measurable a n).aemeasurable hm).mpr + filter_upwards [firstReturnHistory_retains_past a n h] with y hy + have he := congrFun hy (⟨a,by simp⟩ : Finset.Iic a) + exact congrArg (fun s : CostState => s.2) he + +lemma rawBranchReturnInputCost_ae (a : ℕ) (b : Bool) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : ∀ᵐ r ∂rawBranchReturnKernel a b h, rawReturnInputCost a r=z.2 := by + rw [rawBranchReturnKernel,Kernel.restrict_apply] + filter_upwards [ae_restrict_of_ae (rawReturnInputCost_ae a h)] with r hr + simpa only [hz,embedOdd] using hr + +theorem rawBranchReturn_input_signature (a : ℕ) (b : Bool) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (rawBranchReturnKernel a b h).map (rawReturnInputSignature a) = + (sourceBranchWitnessKernel b z).map (sourceCycleInputSignature z) := by + have he : rawReturnInputSignature a =ᵐ[rawBranchReturnKernel a b h] + fun r => (z.2,rawReturnSignature a r) := by + filter_upwards [rawBranchReturnInputCost_ae a b h z hz] with r hr + exact Prod.ext hr rfl + calc + _ = (rawBranchReturnKernel a b h).map (fun r => (z.2,rawReturnSignature a r)) := Measure.map_congr he + _ = ((rawBranchReturnKernel a b h).map (rawReturnSignature a)).map (fun s => (z.2,s)) := by + rw [Measure.map_map (g := fun s : ReturnSignature => (z.2,s)) + (measurable_const.prodMk measurable_id) (rawReturnSignature_measurable a)] + rfl + _ = ((sourceBranchWitnessKernel b z).map (sourceReturnSignature z)).map (fun s => (z.2,s)) := by + rw [rawBranchReturn_signature a b h z hz] + _ = _ := by + rw [Measure.map_map (g := fun s : ReturnSignature => (z.2,s)) + (measurable_const.prodMk measurable_id) (sourceReturnSignature_measurable z)] + rfl + +def decodeReturnedOdd (s : CostState) : OddCost := + (Sum.elim (fun _ => regenerationState) id s.1,s.2) + +lemma decodeReturnedOdd_measurable : Measurable decodeReturnedOdd := + ((measurable_const.sumElim measurable_id).comp measurable_fst).prodMk measurable_snd + +lemma decodeReturnedOdd_embed (z : OddCost) : decodeReturnedOdd (embedOdd z)=z := rfl + +lemma embed_decodeReturnedOdd_of_regeneration (s : CostState) (hs : s ∈ regenerationSet) : + embedOdd (decodeReturnedOdd s)=s := by + rcases s with ⟨s,T⟩ + cases s with + | inl s => exact False.elim (regeneration_even s T hs) + | inr s => rfl + +lemma decode_source_signature (z : OddCost) (w : SourceCycleWitness) : + decodeReturnedOdd (sourceReturnSignature z w).2.2=w.2.2 := rfl + +lemma rawBranchReturn_endpoint_supported (a : ℕ) (b : Bool) (h : RawHistory a) : + ∀ᵐ r ∂rawBranchReturnKernel a b h, + rawLast (a+2*(r.1+1)) r.2 = embedOdd (decodeReturnedOdd (rawReturnSignature a r).2.2) := by + filter_upwards [rawBranchReturn_ae_regeneration a b h] with r hr + exact (embed_decodeReturnedOdd_of_regeneration _ hr).symm + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RawWordSpaces.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawWordSpaces.lean new file mode 100644 index 0000000000000000000000000000000000000000..32eb7881a8aacb0598d13af5b67ddfc1e74bbc9c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RawWordSpaces.lean @@ -0,0 +1,191 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SigmaFamilyKernel + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.PairedCostGrouping NumberTheoryLean.FirstHitKernels +open NumberTheoryLean.CostReturnLaw + +noncomputable def firstArrivalMark (s : CostState) : Bool := Sum.elim sourceMark (fun _ => false) s.1 + +lemma firstArrivalMark_measurable : Measurable firstArrivalMark := + (sourceMark_measurable.sumElim measurable_const).comp measurable_fst + +noncomputable def returnSignatureMark (s : ReturnSignature) : Bool := firstArrivalMark s.2.1 + +lemma returnSignatureMark_measurable : Measurable returnSignatureMark := + firstArrivalMark_measurable.comp (measurable_fst.comp measurable_snd) + +noncomputable def rawReturnMark (a : ℕ) (r : RawReturnTrace a) : Bool := returnSignatureMark (rawReturnSignature a r) + +lemma rawReturnMark_measurable (a : ℕ) : Measurable (rawReturnMark a) := + returnSignatureMark_measurable.comp (rawReturnSignature_measurable a) + +lemma sourceReturnSignature_mark (z : OddCost) (w : SourceCycleWitness) : + returnSignatureMark (sourceReturnSignature z w)=sourceMark w.1 := rfl + +noncomputable def rawBranchReturnKernel (a : ℕ) (b : Bool) : Kernel (RawHistory a) (RawReturnTrace a) := + (rawReturnTraceKernel a).restrict ((rawReturnMark_measurable a) (measurableSet_singleton b)) + +instance rawBranchReturnKernel_isFiniteKernel (a : ℕ) (b : Bool) : IsFiniteKernel (rawBranchReturnKernel a b) := by + unfold rawBranchReturnKernel + infer_instance + +noncomputable def sourceBranchWitnessKernel (b : Bool) : Kernel OddCost SourceCycleWitness := + sourceCycleWitnessKernel.restrict ((sourceMark_measurable.comp measurable_fst) (measurableSet_singleton b)) + +instance sourceBranchWitnessKernel_isFiniteKernel (b : Bool) : IsFiniteKernel (sourceBranchWitnessKernel b) := by + unfold sourceBranchWitnessKernel + infer_instance + +theorem rawBranchReturn_signature (a : ℕ) (b : Bool) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (rawBranchReturnKernel a b h).map (rawReturnSignature a) = + (sourceBranchWitnessKernel b z).map (sourceReturnSignature z) := by + have hm : MeasurableSet {s : ReturnSignature | returnSignatureMark s=b} := + returnSignatureMark_measurable (measurableSet_singleton b) + rw [rawBranchReturnKernel,sourceBranchWitnessKernel,Kernel.restrict_apply,Kernel.restrict_apply] + change ((rawReturnTraceKernel a h).restrict ((rawReturnSignature a) ⁻¹' {s | returnSignatureMark s=b})).map + (rawReturnSignature a) = + ((sourceCycleWitnessKernel z).restrict ((sourceReturnSignature z) ⁻¹' {s | returnSignatureMark s=b})).map + (sourceReturnSignature z) + rw [← Measure.restrict_map (rawReturnSignature_measurable a) hm, + ← Measure.restrict_map (sourceReturnSignature_measurable z) hm,rawReturnTrace_signature a h z hz] + +lemma sourceBranchWitness_markCost (b : Bool) (z : OddCost) : + (sourceBranchWitnessKernel b z).map sourceWitnessProjection = + (completedMarkedKernel z).restrict {y | y.1=b} := by + have hm : MeasurableSet {y : MarkedOddCost | y.1=b} := measurable_fst (measurableSet_singleton b) + rw [sourceBranchWitnessKernel,Kernel.restrict_apply] + change ((sourceCycleWitnessKernel z).restrict (sourceWitnessProjection ⁻¹' {y : MarkedOddCost | y.1=b})).map + sourceWitnessProjection = _ + rw [← Measure.restrict_map sourceWitnessProjection_measurable hm,sourceCycleWitness_projection] + +lemma sourceBranchWitness_endpoint (b : Bool) (z : OddCost) : + (sourceBranchWitnessKernel b z).map (fun w => w.2.2) = cycleBranchKernel b z := by + calc + _ = ((sourceBranchWitnessKernel b z).map sourceWitnessProjection).map Prod.snd := + (Measure.map_map measurable_snd sourceWitnessProjection_measurable).symm + _ = _ := by + rw [sourceBranchWitness_markCost,cycleBranchKernel,Kernel.map_apply _ measurable_snd,Kernel.restrict_apply] + rfl + +lemma rawBranchReturn_endpoint (a : ℕ) (b : Bool) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : + (rawBranchReturnKernel a b h).map (fun r => (rawReturnSignature a r).2.2) = + (cycleBranchKernel b z).map embedOdd := by + have he := congrArg (fun μ : Measure ReturnSignature => μ.map (fun s => s.2.2)) + (rawBranchReturn_signature a b h z hz) + rw [Measure.map_map (g := fun s : ReturnSignature => s.2.2) + (measurable_snd.comp measurable_snd) (rawReturnSignature_measurable a), + Measure.map_map (g := fun s : ReturnSignature => s.2.2) + (measurable_snd.comp measurable_snd) (sourceReturnSignature_measurable z)] at he + rw [← sourceBranchWitness_endpoint b z, + Measure.map_map (g := embedOdd) (f := fun w : SourceCycleWitness => w.2.2) + embedOdd_measurable (measurable_snd.comp measurable_snd)] + exact he + +lemma rawBranchReturn_mass_le_one (a : ℕ) (b : Bool) (h : RawHistory a) : + rawBranchReturnKernel a b h univ ≤ 1 := by + rw [rawBranchReturnKernel,Kernel.restrict_apply] + exact (Measure.restrict_le_self univ).trans (rawReturnTrace_mass_le_one a h) + +lemma rawReturnTrace_ae_regeneration (a : ℕ) (h : RawHistory a) : + ∀ᵐ r ∂rawReturnTraceKernel a h, (rawReturnSignature a r).2.2 ∈ regenerationSet := by + have hm : MeasurableSet {r : RawReturnTrace a | (rawReturnSignature a r).2.2 ∈ regenerationSet} := + regenerationSet_measurable.preimage ((measurable_snd.comp measurable_snd).comp (rawReturnSignature_measurable a)) + rw [rawReturnTraceKernel,Kernel.sum_apply,Measure.ae_sum_iff] + intro n + rw [Kernel.map_apply _ (rawReturnTrace_mk_measurable a n)] + apply (ae_map_iff (rawReturnTrace_mk_measurable a n).aemeasurable hm).mpr + filter_upwards [firstReturnHistory_ae_cylinder a n h] with y hy + exact hy.2 + +lemma rawBranchReturn_ae_regeneration (a : ℕ) (b : Bool) (h : RawHistory a) : + ∀ᵐ r ∂rawBranchReturnKernel a b h, (rawReturnSignature a r).2.2 ∈ regenerationSet := by + rw [rawBranchReturnKernel,Kernel.restrict_apply] + exact ae_restrict_of_ae (rawReturnTrace_ae_regeneration a h) + +end Erdos970Dependency.MarkedVisits + +end + +section + +namespace Erdos970Dependency.MarkedVisits +open Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.FinitePathMeasures + +@[reducible] def RawCycleWordTrace : ℕ → ℕ → Type + | a, 0 => RawHistory a + | a, k+1 => Σ n : ℕ, RawHistory (a+2*(n+1)) × RawCycleWordTrace (a+2*(n+1)) k + +@[reducible] noncomputable def rawCycleWordMeasurable : (a k : ℕ) → MeasurableSpace (RawCycleWordTrace a k) + | a, 0 => inferInstanceAs (MeasurableSpace (RawHistory a)) + | a, k+1 => by + letI : ∀ n : ℕ, MeasurableSpace (RawCycleWordTrace (a+2*(n+1)) k) := + fun n => rawCycleWordMeasurable (a+2*(n+1)) k + exact inferInstanceAs (MeasurableSpace (Σ n : ℕ, RawHistory (a+2*(n+1)) × RawCycleWordTrace (a+2*(n+1)) k)) + +noncomputable instance (a k : ℕ) : MeasurableSpace (RawCycleWordTrace a k) := rawCycleWordMeasurable a k + +abbrev CycleInputSignature := ℝ × ReturnSignature + +@[reducible] def CycleWordSignature : ℕ → Type + | 0 => CostState + | k+1 => CycleInputSignature × CycleWordSignature k + +@[reducible] noncomputable def cycleWordSignatureMeasurable : (k : ℕ) → MeasurableSpace (CycleWordSignature k) + | 0 => inferInstanceAs (MeasurableSpace CostState) + | k+1 => by + letI : MeasurableSpace (CycleWordSignature k) := cycleWordSignatureMeasurable k + exact inferInstanceAs (MeasurableSpace (CycleInputSignature × CycleWordSignature k)) + +noncomputable instance (k : ℕ) : MeasurableSpace (CycleWordSignature k) := cycleWordSignatureMeasurable k + +noncomputable def rawReturnInputCost (a : ℕ) (r : RawReturnTrace a) : ℝ := + (r.2 ⟨a,Finset.mem_Iic.mpr (by omega)⟩).2 + +lemma rawReturnInputCost_measurable (a : ℕ) : Measurable (rawReturnInputCost a) := by + apply measurable_sigma_family + intro n + change Measurable (fun h : RawHistory (a+2*(n+1)) => (h ⟨a,Finset.mem_Iic.mpr (by omega)⟩).2) + exact measurable_snd.comp (measurable_pi_apply (⟨a,Finset.mem_Iic.mpr (by omega)⟩ : Finset.Iic (a+2*(n+1)))) + +noncomputable def rawReturnInputSignature (a : ℕ) (r : RawReturnTrace a) : CycleInputSignature := + (rawReturnInputCost a r,rawReturnSignature a r) + +lemma rawReturnInputSignature_measurable (a : ℕ) : Measurable (rawReturnInputSignature a) := + (rawReturnInputCost_measurable a).prodMk (rawReturnSignature_measurable a) + +noncomputable def rawCycleWordSignature : (a k : ℕ) → RawCycleWordTrace a k → CycleWordSignature k + | a, 0, h => rawLast a h + | a, k+1, r => (rawReturnInputSignature a (packRawReturnTrace a r.1 r.2.1), + rawCycleWordSignature (a+2*(r.1+1)) k r.2.2) + +lemma rawCycleWordSignature_measurable (k : ℕ) : ∀ a, Measurable (rawCycleWordSignature a k) := by + induction k with + | zero => intro a; exact rawLast_measurable a + | succ k ih => + intro a + apply measurable_sigma_family + intro n + exact ((rawReturnInputSignature_measurable a).comp + ((rawReturnTrace_mk_measurable a n).comp measurable_fst)).prodMk + ((ih (a+2*(n+1))).comp measurable_snd) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ReferenceHistoryAdmission.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ReferenceHistoryAdmission.lean new file mode 100644 index 0000000000000000000000000000000000000000..99c9cac5ba0ac3af96490ace7cbd6594a07b326b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ReferenceHistoryAdmission.lean @@ -0,0 +1,139 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceLocalResidual +import OAI.NumberTheory.Jacobsthal.Primes.PrimeCompactWeights + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferenceHistoryAdmission + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry PrimeHistories PrimeTiltGeometry PrimeBinMembership ActualPrimeHigh +open ReferenceAdmission ReferencePruning ReferencePrefixRecurrence ReferenceSourcePrimeSets ReferenceEulerRecurrence +open ReferenceCancellation +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem cap_lower_ratio {w : ℝ} {z : Node} {p : ℕ} (hs : Valid z.side z.ratio) (hz : Consistent z) + (hx : 0 < primeExponent w p) (hcap : capGuard z.closed z.cutoff (primeExponent w p)) : + z.ratio-1 ≤ childRatio w z.gap p := by + have hxp : primeExponent w p ≤ z.cutoff := by + cases hcl : z.closed with + | false => have h : primeExponent w p < z.cutoff := by simpa [capGuard,hcl] using hcap + exact h.le + | true => simpa [capGuard,hcl] using hcap + have he := (eq_div_iff (ne_of_gt (valid_pos hs))).mp hz + have hm := mul_le_mul_of_nonneg_right hxp (valid_pos hs).le + have hd : z.ratio ≤ z.gap/primeExponent w p := (le_div_iff₀ hx).mpr (by nlinarith) + unfold childRatio + linarith + +theorem uncapped_child_iff {w : ℝ} (hw : 1 < w) {z : Node} (hs : Valid z.side z.ratio) + (hz : Consistent z) (p : ℕ) : + p ∈ uncappedChildren w 2 z ↔ p ∈ highPrimes w z.cutoff z.closed ∧ + childAdmitted z.side z.gap (primeExponent w p) := by + constructor + · intro hp + obtain ⟨hprime,hx,hcap,hmin⟩ := Finset.mem_filter.mp hp + have hpP := (Nat.mem_primesLE.mp hprime).2 + refine ⟨(highPrimes_membership hw z.cutoff z.closed p).mpr ⟨hpP,hx,hcap⟩,?_⟩ + cases hi : z.side with + | even => trivial + | odd => + rw [hi] at hmin + apply (upper_admission_above_two hx.le).mpr + have h2 : 2 ≤ childRatio w z.gap p := (le_max_left _ _).trans hmin + have hdiv : 3 ≤ z.gap/primeExponent w p := by unfold childRatio at h2; linarith + have hm := (le_div_iff₀ (by linarith : 0 < primeExponent w p)).mp hdiv + linarith + · rintro ⟨hp,ha⟩ + obtain ⟨hpP,hx,hcap⟩ := (highPrimes_membership hw z.cutoff z.closed p).mp hp + have hx0 : 0 < primeExponent w p := by linarith + have hxp : primeExponent w p ≤ z.cutoff := by + cases hcl : z.closed with + | false => have h : primeExponent w p < z.cutoff := by simpa [capGuard,hcl] using hcap + exact h.le + | true => simpa [capGuard,hcl] using hcap + have hpLe := (exponent_le_iff hw (by exact_mod_cast hpP.pos)).mp hxp + have hprime := Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff (Real.rpow_pos_of_pos (by linarith : 0 < w) z.cutoff).le).mpr hpLe,hpP⟩ + apply Finset.mem_filter.mpr + refine ⟨hprime,hx,hcap,?_⟩ + have hlo := cap_lower_ratio hs hz hx0 hcap + cases hi : z.side with + | even => exact hlo + | odd => + rw [hi] at ha + apply max_le + · have hh := (upper_admission_above_two hx.le).mp ha + unfold childRatio + have hd : 3 ≤ z.gap/primeExponent w p := (le_div_iff₀ hx0).mpr (by linarith) + linarith + · exact hlo + +theorem uncapped_child_invariants {w : ℝ} {z : Node} {p : ℕ} + (hs : Valid z.side z.ratio) (hr : 0 < z.gap) (hp : p ∈ uncappedChildren w 2 z) : + Valid (step w z p).side (step w z p).ratio ∧ 0 < (step w z p).gap ∧ Consistent (step w z p) := by + have hone : uncappedAllowed w 2 z [p] := ⟨hp,trivial⟩ + obtain ⟨U,_hU,hU⟩ := (uncapped_iff_exists_ceiling w 2 z [p]).mp hone + have hc := ((allowed_cons w 2 U z p []).mp hU).1 + exact ⟨child_valid hs hc,child_gap_positive (by norm_num) hr hs hc,step_consistent (by norm_num) hr hs hc⟩ + +theorem decreasing_cons_iff (P : Finset ℕ) (p : ℕ) (ps : List ℕ) : + p::ps ∈ decreasingPrefixes P ↔ p ∈ P ∧ ps ∈ decreasingPrefixes (P.filter (fun q => q q simp [referencePrefixes,mem_decreasingPrefixes,admitted,uncappedAllowed] + | cons p ps ih => + rw [referencePrefixes_cons_iff] + constructor + · rintro ⟨hp,ha,ht⟩ + have hpU := (uncapped_child_iff hw hs hz p).mpr ⟨hp,ha⟩ + obtain ⟨hvs,hrs,hzs⟩ := uncapped_child_invariants hs hr hpU + have hpS : p ∈ sourcePrimes w z.cutoff z.closed := (Finset.mem_filter.mp hp).1 + have he := highPrimes_at_selected hw z.closed hpS + rw [← he] at ht + exact ⟨hpU,(ih hvs hrs hzs).mp ht⟩ + · rintro ⟨hpU,htU⟩ + obtain ⟨hp,ha⟩ := (uncapped_child_iff hw hs hz p).mp hpU + obtain ⟨hvs,hrs,hzs⟩ := uncapped_child_invariants hs hr hpU + have ht := (ih hvs hrs hzs).mpr htU + have hpS : p ∈ sourcePrimes w z.cutoff z.closed := (Finset.mem_filter.mp hp).1 + have he := highPrimes_at_selected hw z.closed hpS + change ps ∈ referencePrefixes w (highPrimes w (primeExponent w p) false) z.side.flip (z.gap-primeExponent w p) at ht + rw [he] at ht + exact ⟨hp,ha,ht⟩ + +theorem reference_family_eq_uncapped {w : ℝ} (hw : 1 < w) {z : Node} (hs : Valid z.side z.ratio) + (hr : 0 < z.gap) (hz : Consistent z) : + referencePrefixes w (highPrimes w z.cutoff z.closed) z.side z.gap=uncappedPrefixes w 2 z := by + ext ps + rw [reference_history_iff hw hs hr hz,mem_uncappedPrefixes hw] + +end NumberTheoryLean.ReferenceHistoryAdmission + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ReferencePrefixRecurrence.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ReferencePrefixRecurrence.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f8c9dddd47bd38b84a21f3b5244b7aa37b7eacb --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ReferencePrefixRecurrence.lean @@ -0,0 +1,117 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceProductsBasics + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ReferencePrefixRecurrence + +attribute [local instance] Classical.propDecidable +open _root_.Finset +open FinitePathGeometry ReferenceAdmission ReferencePruning +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def nonemptyPrefixes (P : Finset ℕ) : Finset (List ℕ) := + (decreasingPrefixes P).filter (fun ps => ps ≠ []) + +theorem singleton_prefix_mem {P : Finset ℕ} {p : ℕ} (hp : p ∈ P) : [p] ∈ decreasingPrefixes P := by + apply mem_decreasingPrefixes.mpr + exact ⟨by simp,by intro q hq; simpa using List.mem_singleton.mp hq ▸ hp⟩ + +theorem nonempty_eq_first_completions (P : Finset ℕ) : + nonemptyPrefixes P=P.biUnion (fun p => completions P [p]) := by + ext ps + constructor + · intro hp + obtain ⟨hpD,hne⟩ := Finset.mem_filter.mp hp + cases ps with + | nil => exact False.elim (hne rfl) + | cons p ps => + have hpP : p ∈ P := (mem_decreasingPrefixes.mp hpD).2 p (by simp) + have ht := (append_mem_decreasing_iff (singleton_prefix_mem hpP)).mp hpD + exact Finset.mem_biUnion.mpr ⟨p,hpP,Finset.mem_image.mpr ⟨ps,ht,rfl⟩⟩ + · intro hp + obtain ⟨p,hpP,hps⟩ := Finset.mem_biUnion.mp hp + obtain ⟨tail,htail,rfl⟩ := Finset.mem_image.mp hps + exact Finset.mem_filter.mpr ⟨(append_mem_decreasing_iff (singleton_prefix_mem hpP)).mpr htail,by simp⟩ + +theorem first_completions_disjoint (P : Finset ℕ) : + (P:Set ℕ).PairwiseDisjoint (fun p => completions P [p]) := by + intro p _hp q _hq hne + apply Finset.disjoint_left.mpr + intro ps hp hq + obtain ⟨sp,_hsp,he⟩ := Finset.mem_image.mp hp + obtain ⟨sq,_hsq,hf⟩ := Finset.mem_image.mp hq + have hh := he.trans hf.symm + simp only [List.singleton_append] at hh + exact hne (List.cons.inj hh).1 + +theorem sum_decreasing_by_first (P : Finset ℕ) (F : List ℕ → ℝ) : + (∑ ps ∈ decreasingPrefixes P,F ps)=F []+ + ∑ p ∈ P,∑ ps ∈ decreasingPrefixes (P.filter (fun q => q ps=[])= {[]} := by + ext ps + simp only [Finset.mem_filter,Finset.mem_singleton] + constructor + · exact fun h => h.2 + · intro h + subst ps + exact ⟨mem_decreasingPrefixes.mpr ⟨by simp,by simp⟩,rfl⟩ + have hs := Finset.sum_filter_add_sum_filter_not (decreasingPrefixes P) (fun ps => ps=[]) F + rw [he,Finset.sum_singleton] at hs + change F []+(∑ ps ∈ nonemptyPrefixes P,F ps)=(∑ ps ∈ decreasingPrefixes P,F ps) at hs + rw [← hs,nonempty_eq_first_completions,Finset.sum_biUnion (first_completions_disjoint P)] + congr 1 + apply Finset.sum_congr rfl + intro p hp + unfold completions + rw [Finset.sum_image] + · have hsuf : suffixPrimes P [p]=P.filter (fun q => q q if admitted w i r ps then signedWeight ps else 0) + have he : referencePolynomial w P i r = + ∑ ps ∈ decreasingPrefixes P,if admitted w i r ps then signedWeight ps else 0 := by + rw [referencePolynomial,referencePrefixes,Finset.sum_filter] + rfl + have hnil : (if admitted w i r [] then signedWeight [] else 0)=1 := by + simp [admitted,signedWeight,prefixWeight] + rw [he,h,hnil] + have hsum : (∑ p ∈ P,∑ ps ∈ decreasingPrefixes (P.filter (fun q => q q ring + · simp [admitted,hc] + rw [hsum] + ring + +end NumberTheoryLean.ReferencePrefixRecurrence + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RepeatedWordData.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RepeatedWordData.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc0ea6dc96265280bf9ff53ae651a99790628abc --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RepeatedWordData.lean @@ -0,0 +1,90 @@ +import OAI.NumberTheory.Jacobsthal.Probability.RepeatedPairProbability + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.RepeatedWordData +open _root_.Set FinitePathGeometry PrimeHistories PrimeKilledChain PrimeTiltGeometry ActualPrimeHigh +open ActualRepeatedBinStep CandidateTerminalGeometry MarkedPrefixTools +open RepeatedPairEvents RepeatedPairProbability ActualSourceTags PrimeBinRepresentatives +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +variable {w ell S : ℝ} {start : Node} + +theorem history_last_mem (h : History w ell S start) (hne : h.primes ≠ []) : h.primes.getLastD 0 ∈ h.primes := by + have he : h.primes.getLastD 0=h.primes.getLast hne := by + conv_lhs => rw [← List.dropLast_append_getLast hne] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hne + +theorem history_nonempty_cutoff_gt (hw : 1 < w) (h : History w ell S start) (hne : h.primes ≠ []) : + ell < h.node.cutoff := by + have hh := (allowed_prime_bounds hw h.admissible _ (history_last_mem h hne)).2.1 + rwa [← terminal_lastD w start h.primes hne] at hh + +theorem history_nonempty_ratio_le_gap (hw : 1 < w) (hell : 1 ≤ ell) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (h : History w ell S start) (hne : h.primes ≠ []) : h.node.ratio ≤ h.node.gap := by + have hx := history_nonempty_cutoff_gt hw h hne + have hcut : 1 ≤ h.node.cutoff := hell.trans hx.le + have hh := terminal_ratio_div_cutoff w start h.primes hne (by linarith : h.node.cutoff ≠ 0) + change h.node.ratio=h.node.gap/h.node.cutoff at hh + rw [hh] + exact div_le_self (terminal_gap_positive (by linarith : 0 ≤ ell) hr hs h.admissible).le hcut + +theorem search_prime_exponent {top xi : ℝ} (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + {p : ℕ} (hp : p ∈ sourcePrimeSet w top) + (hsearch : searchBin w (lower w top xi (label (zero_lt_one.trans hw) htop hxi p))) : + w^((1/4:ℝ)) ≤ primeExponent w p := by + have hp' := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp hp + have hbin := label_prime_membership (zero_lt_one.trans hw) htop hxi hp'.1 hp'.2 + have hx := (bin_exponent_bounds hw (endpoint_pos (zero_lt_one.trans hw) _) + (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le hbin).1 + exact hsearch.trans hx.le + +theorem adjacent_search_pair_data {top xi : ℝ} (hw : 1 < w) (htop : w < top) (hell : 1 ≤ ell) (hxi : 0 < xi) + (hsS : start.ratio ≤ S) (hcap : w^start.cutoff=top) + (pre : List ℕ) (p q : ℕ) (a b : History w ell S start) + (ha : a.primes=pre++[p]) (hb : b.primes=(pre++[p])++[q]) + (hl : label (zero_lt_one.trans hw) htop hxi p=label (zero_lt_one.trans hw) htop hxi q) + (hsearch : searchBin w (lower w top xi (label (zero_lt_one.trans hw) htop hxi q))) : + primeRepeatPair (label (zero_lt_one.trans hw) htop hxi) (w^((1/4:ℝ))) S Set.univ (some a,some b) := by + have hna : a.primes ≠ [] := by rw [ha]; simp + have hnb : b.primes ≠ [] := by rw [hb]; simp + have hla : a.primes.getLastD 0=p := by rw [ha]; exact List.getLastD_concat + have hlb : b.primes.getLastD 0=q := by rw [hb]; exact List.getLastD_concat + have hsrc := history_source_primes hw htop hell hcap b q (by rw [hb]; simp) + have hx := search_prime_exponent hw htop hxi hsrc hsearch + have hcut : b.node.cutoff=primeExponent w q := by + change (terminal w start b.primes).cutoff=primeExponent w q + rw [terminal_lastD w start b.primes hnb,hlb] + refine ⟨hna,terminal_ratio_le hsS a.admissible,Set.mem_univ _,?_,?_⟩ + · rw [hla,hlb] + exact hl + · rwa [hcut] + +theorem adjacent_compact_pair_data {n : ℕ} (lab : ℕ → Fin n) (hw : 1 < w) (hell : 1 ≤ ell) + (hr : 0 < start.gap) (hs : Valid start.side start.ratio) + (L : ℝ) (pre : List ℕ) (p q : ℕ) (a b : History w ell S start) + (ha : a.primes=pre++[p]) (hb : b.primes=(pre++[p])++[q]) + (hl : lab p=lab q) (hgap : (terminal w start (pre++[p])).gap ≤ L) : + primeRepeatPair lab 1 L (compactParentGate L) (some a,some b) := by + have hna : a.primes ≠ [] := by rw [ha]; simp + have hnb : b.primes ≠ [] := by rw [hb]; simp + have hla : a.primes.getLastD 0=p := by rw [ha]; exact List.getLastD_concat + have hlb : b.primes.getLastD 0=q := by rw [hb]; exact List.getLastD_concat + have hga : a.node.gap ≤ L := by change (terminal w start a.primes).gap ≤ L; rwa [ha] + have hratio := (history_nonempty_ratio_le_gap hw hell hr hs a hna).trans hga + exact ⟨hna,hratio,hga,by rwa [hla,hlb],hell.trans (history_nonempty_cutoff_gt hw b hnb).le⟩ +end NumberTheoryLean.RepeatedWordData + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/RepresentativeStopGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/RepresentativeStopGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..94199482b72a2d2ec749ea59024710ff0ca189ec --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/RepresentativeStopGeometry.lean @@ -0,0 +1,88 @@ +import Mathlib.Tactic +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceWeightedQuadrature + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.RepresentativeStopGeometry + +open NumberTheoryLean.ReferenceAdmission + +def sourceHeight (x : ℝ) : ℝ := max (2*x) (x+2) + +theorem sourceHeight_mono {x y : ℝ} (hxy : x ≤ y) : sourceHeight x ≤ sourceHeight y := by + exact max_le_max (by linarith) (by linarith) + +theorem sourceHeight_error {x y d : ℝ} (hxy : |x-y| ≤ d) : sourceHeight x ≤ sourceHeight y+2*d := by + have hd : 0 ≤ d := (abs_nonneg _).trans hxy + apply max_le + · have hy := le_max_left (2*y) (y+2) + change 2*y ≤ sourceHeight y at hy + linarith [(abs_le.mp hxy).2] + · have hy := le_max_right (2*y) (y+2) + change y+2 ≤ sourceHeight y at hy + linarith [(abs_le.mp hxy).2] + +theorem sourceHeight_lipschitz (x y : ℝ) : |sourceHeight x-sourceHeight y| ≤ 2*|x-y| := by + have hxy := sourceHeight_error (x:=x) (y:=y) (le_rfl : |x-y| ≤ |x-y|) + have hyx := sourceHeight_error (x:=y) (y:=x) (le_rfl : |y-x| ≤ |y-x|) + rw [abs_sub_comm y x] at hyx + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +theorem representative_safety_admits {r rrep x xrep Delta : ℝ} + (hDelta : 0 ≤ Delta) (hx : x ≤ xrep) (hr : rrep ≤ r) + (hsafe : sourceHeight xrep+3*Delta ≤ rrep) : sourceHeight x ≤ r := by + have hH := sourceHeight_mono hx + linarith + +theorem regular_margin_to_representative {r rrep x xrep Delta h : ℝ} + (hr : |rrep-r| ≤ Delta) (hx : |xrep-x| ≤ h) + (hsmall : 2*h ≤ 6*Delta) (hmargin : sourceHeight x+10*Delta < r) : + sourceHeight xrep+3*Delta < rrep := by + have hH := sourceHeight_error hx + linarith [(abs_le.mp hr).1] + +theorem representative_to_actual_window {b₀ b₁ r rrep x xrep Delta h : ℝ} + (hx : 0 < x) (hxr : x ≤ xrep) (hxh : xrep ≤ x+h) + (hr : rrep ≤ r) (hrD : r ≤ rrep+Delta) + (hb₀ : b₀ ≤ xrep) (hb₁ : xrep ≤ b₁) + (hs₀ : 206/100 ≤ rrep/xrep) (hs₁ : rrep/xrep ≤ 216/100) + (hsmall : Delta+(218/100)*h ≤ (2/100)*b₀) : + b₀-h ≤ x ∧ x ≤ b₁ ∧ 204/100 ≤ r/x ∧ r/x ≤ 218/100 := by + have hxp : 0 < xrep := hx.trans_le hxr + have hlow := (le_div_iff₀ hxp).mp hs₀ + have hhigh := (div_le_iff₀ hxp).mp hs₁ + refine ⟨by linarith,hxr.trans hb₁,?_,?_⟩ + · apply (le_div_iff₀ hx).mpr + nlinarith + · apply (div_le_iff₀ hx).mpr + nlinarith + +theorem actual_mark_to_representative_window {b₀ b₁ r rrep x xrep Delta h : ℝ} + (hb₀ : 0 < b₀) (hx₀ : 2*b₀ ≤ x) (hx₁ : x ≤ b₁/2) + (hxr : x ≤ xrep) (hxh : xrep ≤ x+h) + (hr : rrep ≤ r) (hrD : r ≤ rrep+Delta) + (hs₀ : 208/100 ≤ r/x) (hs₁ : r/x ≤ 214/100) + (hh : h ≤ b₀) (hsmall : Delta+(206/100)*h ≤ (4/100)*b₀) : + b₀ ≤ xrep ∧ xrep ≤ b₁ ∧ 206/100 ≤ rrep/xrep ∧ rrep/xrep ≤ 216/100 := by + have hx : 0 < x := by linarith + have hxp : 0 < xrep := hx.trans_le hxr + have hlow := (le_div_iff₀ hx).mp hs₀ + have hhigh := (div_le_iff₀ hx).mp hs₁ + refine ⟨by linarith,by linarith,?_,?_⟩ + · apply (le_div_iff₀ hxp).mpr + nlinarith + · apply (div_le_iff₀ hxp).mpr + nlinarith + +end NumberTheoryLean.RepresentativeStopGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/ResidualHistoryGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/ResidualHistoryGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..5cc67c6b928e87c6d8b989294ec61aedf0516970 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/ResidualHistoryGeometry.lean @@ -0,0 +1,49 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.MovingLocalReference + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.ResidualHistoryGeometry + +attribute [local instance] Classical.propDecidable +open FinitePathGeometry PrimeHistories PrimeBinMembership PrimeTiltGeometry ActualPrimeHigh ActualBoundaryDomain +open SourceNodeCoordinates ReferenceResidualSum ReferenceSourceDecomposition +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem uncapped_gap_le {w : ℝ} {z : Node} {ps : List ℕ} (hp : uncappedAllowed w 2 z ps) : + (terminal w z ps).gap ≤ z.gap := by + induction ps generalizing z with + | nil => exact le_rfl + | cons p ps ih => + obtain ⟨hc,ht⟩ := hp + have hx : 2 < primeExponent w p := (Finset.mem_filter.mp hc).2.1 + calc + _ ≤ (step w z p).gap := ih (z:=step w z p) ht + _ ≤ z.gap := sub_le_self _ (by linarith) + +theorem source_terminal_geometry {B w : ℝ} (hB : 4 ≤ B) (start : Node) + (hi : start.side=.even) (h199 : 199/100 ≤ start.ratio) (h23 : start.ratio ≤ 23/10) + (hc : Consistent start) (hcut : start.cutoff=B) {ps : List ℕ} (hp : uncappedAllowed w 2 start ps) : + Valid (terminal w start ps).side (terminal w start ps).ratio ∧ + Consistent (terminal w start ps) ∧ BoundaryDomain (terminal w start ps).side (terminal w start ps).gap ∧ + 2 < (terminal w start ps).cutoff ∧ (terminal w start ps).cutoff ≤ B ∧ + 0 < (terminal w start ps).gap ∧ (terminal w start ps).gap ≤ (23/10:ℝ)*B := by + obtain ⟨hs,hr,_hBstart,hsize⟩ := source_node_bounds (by linarith : 0 < B) start hi h199 h23 hc hcut + obtain ⟨U,_hU,hpU⟩ := (uncapped_iff_exists_ceiling w 2 start ps).mp hp + refine ⟨terminal_valid hs hpU,terminal_consistent (by norm_num) hr hs hc hpU, + source_boundary_domain hB le_rfl start hi h199 h23 hc hcut hp, + uncapped_cutoff_gt_two (by rw [hcut]; linarith) hp,?_,uncapped_gap_positive (by norm_num) hr hs hp, + (uncapped_gap_le hp).trans hsize⟩ + simpa only [hcut] using uncapped_cutoff_le hp + +end NumberTheoryLean.ResidualHistoryGeometry + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/SampleWitnessAverage.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/SampleWitnessAverage.lean new file mode 100644 index 0000000000000000000000000000000000000000..66b7cf0fef3badba2453cc205a5e26a7d2c56023 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/SampleWitnessAverage.lean @@ -0,0 +1,129 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceSamplePopulation + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosInverseSampling +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +theorem many_large_weights {α : Type*} (A : Finset α) (f : α → ℝ) (beta : ℝ) + (hb : 0 ≤ beta) (hf : ∀ a ∈ A,f a ≤ 1) (hmean : beta*(A.card : ℝ) ≤ ∑ a ∈ A,f a) : + (beta/2)*(A.card : ℝ) ≤ ((A.filter (fun a => beta/2 ≤ f a)).card : ℝ) := by + have hup : (∑ a ∈ A,f a) ≤ + ((A.filter (fun a => beta/2 ≤ f a)).card : ℝ)+(A.card : ℝ)*(beta/2) := by + calc + _ ≤ ∑ a ∈ A,((if beta/2 ≤ f a then (1 : ℝ) else 0)+beta/2) := by + apply Finset.sum_le_sum + intro a ha + by_cases hh : beta/2 ≤ f a + · rw [ite_eq_left hh] + linarith [hf a ha] + · rw [ite_eq_right hh,zero_add] + exact (lt_of_not_ge hh).le + _ = _ := by + rw [Finset.sum_add_distrib,Finset.sum_boole] + simp + linarith + +noncomputable def witnessPairs {α β : Type*} (A : Finset α) (U : Finset β) (witness : α → β → Prop) : + Finset (α × β) := + (A.product U).filter (fun v => witness v.1 v.2) + +theorem witnessPairs_card {α β : Type*} (A : Finset α) (U : Finset β) (witness : α → β → Prop) : + (witnessPairs A U witness).card = ∑ a ∈ A,(U.filter (witness a)).card := by + simp only [witnessPairs,Finset.card_eq_sum_ones,Finset.sum_filter] + exact Finset.sum_product A U (fun v : α × β => if witness v.1 v.2 then (1 : ℕ) else 0) + +end ErdosInverseSampling + +end + +section + +namespace ErdosInverseSampling +attribute [local instance] Classical.propDecidable +attribute [local instance] Classical.decEq + +noncomputable def selectedPairs {α β : Type*} (A : Finset α) (U : Finset β) + (witness : α → β → Prop) (h : ℕ) (e : Sample U h) : Finset α := + A.filter (fun a => ∀ i,witness a (e i).val) + +noncomputable def selectedFraction {α β : Type*} (A : Finset α) (U : Finset β) + (witness : α → β → Prop) (h : ℕ) (e : Sample U h) : ℝ := + ((selectedPairs A U witness h e).card : ℝ)/(A.card : ℝ) + +theorem goodSamples_filter {β : Type*} (U : Finset β) (good : β → Prop) (h : ℕ) : + goodSamples U (U.filter good) h = Finset.univ.filter (fun e : Sample U h => ∀ i,good (e i).val) := by + ext e + simp only [goodSamples,Finset.mem_filter,Finset.mem_univ,true_and] + exact ⟨fun he i => (he i).2,fun he i => ⟨(e i).property,he i⟩⟩ + +theorem sample_incidence_average_eq {α β : Type*} (A : Finset α) (U : Finset β) + (witness : α → β → Prop) (h : ℕ) : + sampleAverage U h (selectedFraction A U witness h) = + (∑ a ∈ A,sampleFrequency U (U.filter (witness a)) h)/(A.card : ℝ) := by + have hh := Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow + (fun e : Sample U h => fun a : α => ∀ i,witness a (e i).val) (s := Finset.univ) (t := A) + have hc : (∑ e : Sample U h,((selectedPairs A U witness h e).card : ℝ)) = + ∑ a ∈ A,((goodSamples U (U.filter (witness a)) h).card : ℝ) := by + have hn : (∑ e : Sample U h,(selectedPairs A U witness h e).card) = + ∑ a ∈ A,(goodSamples U (U.filter (witness a)) h).card := by + simpa only [selectedPairs,Finset.bipartiteAbove,Finset.bipartiteBelow,goodSamples_filter] using hh + exact_mod_cast hn + unfold sampleAverage selectedFraction sampleFrequency + simp_rw [← Finset.sum_div] + rw [hc] + ring + +theorem sample_incidence_average_lower {α β : Type*} (A : Finset α) (U : Finset β) + (witness : α → β → Prop) (h : ℕ) (beta : ℝ) (hb : 0 < beta) (hb1 : beta ≤ 1) + (hA : 0 < A.card) (hU : 0 < U.card) + (hdense : beta*(A.card : ℝ)*(U.card : ℝ) ≤ ((witnessPairs A U witness).card : ℝ)) + (hsize : 4*(h : ℝ)/beta ≤ (U.card : ℝ)) : + (beta/2)*(beta/4)^h ≤ sampleAverage U h (selectedFraction A U witness h) := by + have hAR : (0 : ℝ) < A.card := by exact_mod_cast hA + have hUR : (0 : ℝ) < U.card := by exact_mod_cast hU + let f : α → ℝ := fun a => ((U.filter (witness a)).card : ℝ)/(U.card : ℝ) + let G := A.filter (fun a => beta/2 ≤ f a) + have hf (a : α) (_ha : a ∈ A) : f a ≤ 1 := by + apply (div_le_iff₀ hUR).mpr + simpa only [one_mul] using (Nat.cast_le.mpr (Finset.card_filter_le U (witness a)) : + ((U.filter (witness a)).card : ℝ) ≤ U.card) + have hmean : beta*(A.card : ℝ) ≤ ∑ a ∈ A,f a := by + change beta*(A.card : ℝ) ≤ ∑ a ∈ A,((U.filter (witness a)).card : ℝ)/(U.card : ℝ) + rw [← Finset.sum_div] + apply (le_div_iff₀ hUR).mpr + have he : ((witnessPairs A U witness).card : ℝ) = ∑ a ∈ A,((U.filter (witness a)).card : ℝ) := by + exact_mod_cast witnessPairs_card A U witness + rwa [← he] + have hG : (beta/2)*(A.card : ℝ) ≤ (G.card : ℝ) := many_large_weights A f beta hb.le hf hmean + have hfreq (a : α) (ha : a ∈ G) : (beta/4)^h ≤ sampleFrequency U (U.filter (witness a)) h := by + have hh := (Finset.mem_filter.mp ha).2 + have hgood : (beta/2)*(U.card : ℝ) ≤ ((U.filter (witness a)).card : ℝ) := (le_div_iff₀ hUR).mp hh + exact sampleFrequency_lower U (U.filter (witness a)) (Finset.filter_subset _ _) h beta hb hb1 hgood hsize + have hnonneg (a : α) : 0 ≤ sampleFrequency U (U.filter (witness a)) h := by + unfold sampleFrequency + positivity + rw [sample_incidence_average_eq] + apply (le_div_iff₀ hAR).mpr + calc + _ ≤ (G.card : ℝ)*(beta/4)^h := by + have hh := mul_le_mul_of_nonneg_right hG (show 0 ≤ (beta/4)^h by positivity) + nlinarith only [hh] + _ = ∑ _a ∈ G,(beta/4)^h := by simp + _ ≤ ∑ a ∈ G,sampleFrequency U (U.filter (witness a)) h := Finset.sum_le_sum hfreq + _ ≤ ∑ a ∈ A,sampleFrequency U (U.filter (witness a)) h := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun a _ _ => hnonneg a) + +end ErdosInverseSampling + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceStopWindow.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceStopWindow.lean new file mode 100644 index 0000000000000000000000000000000000000000..d232a7cbfd60d8821734bc93eb708688a90d6285 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceStopWindow.lean @@ -0,0 +1,63 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SourceMarkedStopping + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.SourceStopWindow +open FinitePathGeometry PrimeHistories SourceStopPredicate RepresentativeAdmission RepresentativeStopGeometry +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinMaps +open MarkedPrefixTools ErdosInversePrimeBin ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem candidate_source_primes (Y : ℕ) {w top Cs eta Clen B xi b₀ b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hc : stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z ps) : + ∀ p ∈ ps,p ∈ sourcePrimeSet w top := by + intro p hp + exact (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mpr + (bin_prime_in_source (zero_lt_one.trans hw) htop hxi _ (hc.2.2.1 p hp)) + +theorem candidate_actual_window (Y : ℕ) {w top Cs eta Clen B xi b₀ b₁ : ℝ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) (hC : 0 ≤ Clen) + (hcomp : Real.log B ≤ 2*Real.log w) + (hsmall : 2*Clen*xi+(218/100)*(xi/Real.log w) ≤ (2/100)*b₀) + (a : ℕ → ℕ) (z : Node) (ps : List ℕ) + (hc : stopCandidate Y w Cs eta Clen B xi b₀ b₁ (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z ps) : + b₀-xi/Real.log w ≤ (terminal w z ps).cutoff ∧ (terminal w z ps).cutoff ≤ b₁ ∧ + 204/100 ≤ (terminal w z ps).gap/(terminal w z ps).cutoff ∧ + (terminal w z ps).gap/(terminal w z ps).cutoff ≤ 218/100 := by + let rep := representative w (lower w top xi) (width w top xi) (label (zero_lt_one.trans hw) htop hxi) + have hsource := candidate_source_primes Y hw htop hxi a z ps hc + have hlast : ps.getLastD 0 ∈ ps := by + have he : ps.getLastD 0=ps.getLast hc.1 := by + conv_lhs => rw [← List.dropLast_append_getLast hc.1] + exact List.getLastD_concat + rw [he] + exact List.getLast_mem hc.1 + have hp := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop _).mp (hsource _ hlast) + have hx1 : 1 < primeExponent w (ps.getLastD 0) := + (one_lt_div (Real.log_pos hw)).mpr (Real.log_lt_log (zero_lt_one.trans hw) hp.2.1) + have hx := source_representative_error hw htop hxi (hsource _ hlast) + change 0 ≤ rep (ps.getLastD 0)-primeExponent w (ps.getLastD 0) ∧ + rep (ps.getLastD 0)-primeExponent w (ps.getLastD 0) ≤ xi/Real.log w at hx + rw [← terminal_lastD w z ps hc.1] at hx hx1 + have hr := source_prefix_movement hw htop hxi hC hcomp z ps hsource hc.2.1 + change 0 ≤ (terminal w z ps).gap-representativeGap rep z.gap ps ∧ + (terminal w z ps).gap-representativeGap rep z.gap ps ≤ 2*Clen*xi at hr + have hwin := hc.2.2.2.2.1 + exact representative_to_actual_window (r := (terminal w z ps).gap) + (rrep := representativeGap rep z.gap ps) (x := (terminal w z ps).cutoff) (xrep := rep (ps.getLastD 0)) + (Delta := 2*Clen*xi) (h := xi/Real.log w) (by linarith) (by linarith [hx.1]) (by linarith [hx.2]) + (by linarith [hr.1]) (by linarith [hr.2]) hwin.1 hwin.2.1 hwin.2.2.1 hwin.2.2.2 hsmall +end NumberTheoryLean.SourceStopWindow + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceStoppedCorrection.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceStoppedCorrection.lean new file mode 100644 index 0000000000000000000000000000000000000000..a440959eb7c911c289098da7753b3c0c946afbac --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceStoppedCorrection.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.SourceCanonicalKeyGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace Erdos970Final +open _root_.Filter NumberTheoryLean NumberTheoryLean.PrimeHistories + NumberTheoryLean.SourceCanonicalKeyGeometry NumberTheoryLean.CanonicalStopPartition + NumberTheoryLean.SourceStopPredicate NumberTheoryLean.StoppedCountVertex + NumberTheoryLean.StoppedCountAdapters NumberTheoryLean.StoppedVertexHistory + NumberTheoryLean.StoppedTraceSets NumberTheoryLean.LogarithmicBinEndpoints + NumberTheoryLean.LogarithmicBinLabels NumberTheoryLean.LogarithmicBinPartition + NumberTheoryLean.LargePrimeDeletion + ErdosInverseBoxHeight ErdosCorrectionLimit ErdosSourceReferenceMargin ErdosStoppedArithmetic + +attribute [local instance] Classical.propDecidable + +theorem source_stopped_correction : + ∃ eta0 : ℝ,0 < eta0 ∧ eta0 ≤ 1/4 ∧ ∀ Cs : ℝ,0 ≤ Cs → + ∃ K : ℝ,0 < K ∧ ∀ Clen : ℝ,0 ≤ Clen → ∀ eta : ℝ,0 ≤ eta → eta ≤ eta0 → + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → ∀ rho : ℝ,1 < rho → + ∀ᶠ top : ℝ in atTop,∃ hw : 1 < sourceW top,∃ htop : sourceW top < top, + ∀ a : ℕ → ℕ, + let w := sourceW top + let B := sourceB top + let Y := sourceY top + let mu := (Y : ℝ)*SmallSieveFinite.smallEuler ⌊w⌋₊ + let z := sourceRootNode (1/100) top + let P := sourcePrimeSet w top + let v := rootVertex z ∅ P mu + let stop := stopCandidate Y w Cs eta Clen B xi ((2*K)*(Real.log w)^2) + (rho*(2*K)*(Real.log w)^2) (lower w top xi) (width w top xi) + (label (zero_lt_one.trans hw) htop hxi) a z + 0 ≤ ∑ ps ∈ stopped w stop P.card v, + (countSurvivors Y (cutoffPrimes ⌊w⌋₊) a (after w v ps)-referenceValue w (after w v ps)) := by + obtain ⟨eta0,heta0,heta01,P0,_hP0,hArithmetic⟩ := canonical_key_correction_nonnegative + refine ⟨eta0,heta0,heta01,?_⟩ + intro Cs hCs + obtain ⟨K,hK,hArithmetic⟩ := hArithmetic Cs hCs + refine ⟨K,hK,?_⟩ + intro Clen hClen eta heta hetaU xi hxi hxi1 rho hrho + have hKstop : 0 < 2*K := by positivity + obtain ⟨W,_hW,hArithmetic⟩ := hArithmetic (2*rho) xi (by linarith) hxi + have hGeometry := source_key_geometry hClen hxi hxi1 hKstop (by linarith : 0 < rho) P0 + filter_upwards [hGeometry,rootW_tendsto.eventually_ge_atTop W] with top hGeometry hW + dsimp only at hGeometry + obtain ⟨hY,hw,htop,hGeometry⟩ := hGeometry + refine ⟨hw,htop,?_⟩ + intro a + dsimp only + apply stopped_correction_of_key_signs (sourceY top) (sourceW top) top Cs eta Clen + (sourceB top) xi ((2*K)*(Real.log (sourceW top))^2) (rho*(2*K)*(Real.log (sourceW top))^2) + ((sourceY top : ℝ)*SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) hw htop hxi hClen a + (sourceRootNode (1/100) top) + intro k hk + obtain ⟨⟨d⟩,hPsize,hPl,hPu,hWidthLo,hWidthHi,hBand,hRef⟩ := hGeometry Cs eta a k hk + have hPl' : Real.exp (K*(Real.log (sourceW top))^3) ≤ (k.tail.getLastD 0 : ℝ) := by + simpa only [show (2*K)/2=K by ring] using hPl + have hPu' : (k.tail.getLastD 0 : ℝ) ≤ Real.exp ((2*rho)*K*(Real.log (sourceW top))^3) := by + convert hPu using 1 + congr 1 + ring + apply hArithmetic (sourceW top) hW top hw htop (sourceY top) hY eta Clen (sourceB top) + ((2*K)*(Real.log (sourceW top))^2) (rho*(2*K)*(Real.log (sourceW top))^2) + ((sourceY top : ℝ)*SmallSieveFinite.smallEuler ⌊sourceW top⌋₊) heta hetaU a + (sourceRootNode (1/100) top) k d hPsize hPl' hPu' hWidthLo hWidthHi + · simpa only [ErdosCommonMInterval.lengthExponent,ErdosCommonMInterval.referenceLength] using hBand + · exact hRef + +end Erdos970Final + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceWitnessSeries.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceWitnessSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed2d17f7b4f3d95d6904ee4ed521f30df6603bd8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/SourceWitnessSeries.lean @@ -0,0 +1,137 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.JointReturnCylinder + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal +open NumberTheoryLean.TransitionKernels NumberTheoryLean.PairedCostProcess +open NumberTheoryLean.CostReturnLaw NumberTheoryLean.MarkedCycleLaw + +noncomputable def tagSourceReturn (n : ℕ) (z : FirstPairWitness) : SourceCycleWitness := + (z.1,(2*(n+1),z.2)) + +lemma tagSourceReturn_measurable (n : ℕ) : Measurable (tagSourceReturn n) := + measurable_fst.prodMk (measurable_const.prodMk measurable_snd) + +noncomputable def sourceWitnessTerm (n : ℕ) : Kernel OddCost SourceCycleWitness := + (sourceReturnTerm n).map (tagSourceReturn n) + +instance sourceWitnessTerm_isFiniteKernel (n : ℕ) : IsFiniteKernel (sourceWitnessTerm n) := by + unfold sourceWitnessTerm + infer_instance + +noncomputable def witnessRemaining : Kernel FirstPairWitness SourceCycleWitness := + Kernel.sum (fun n : ℕ => (firstEvenReturnContinuation n).map (tagSourceReturn (n+1))) + +instance witnessRemaining_isSFiniteKernel : IsSFiniteKernel witnessRemaining := by + unfold witnessRemaining + infer_instance + +lemma witnessContinuation_measure (z : FirstPairWitness) : + witnessContinuation z = (durationHitOrReturn z.2).map (fun d => continueWitnessUpdate (z,d)) := by + ext B hB + rw [witnessContinuation_apply _ hB, + Measure.map_apply (f := fun d : ℕ × OddCost => continueWitnessUpdate (z,d)) + (continueWitnessUpdate_measurable.comp measurable_prodMk_left) hB] + rfl + +lemma witnessContinuation_at_return (z : FirstPairWitness) (hz : z.2 ∈ returnSet) : + witnessContinuation z = Measure.dirac (tagSourceReturn 0 z) := by + classical + rw [witnessContinuation_measure,durationHitOrReturn,Kernel.piecewise_apply,ite_eq_left hz, + Kernel.deterministic_apply,Measure.map_dirac' (f := fun d : ℕ × OddCost => continueWitnessUpdate (z,d)) (continueWitnessUpdate_measurable.comp measurable_prodMk_left)] + rfl + +lemma witnessContinuation_outside_return (z : FirstPairWitness) (hz : z.2 ∉ returnSet) : + witnessContinuation z = witnessRemaining z := by + classical + rw [witnessContinuation_measure,durationHitOrReturn,Kernel.piecewise_apply,ite_eq_right hz, + NumberTheoryLean.MarkedCycleLaw.markedReturnLaw,Kernel.sum_apply, + Measure.map_sum (f := fun d : ℕ × OddCost => continueWitnessUpdate (z,d)) + (continueWitnessUpdate_measurable.comp measurable_prodMk_left).aemeasurable, + witnessRemaining,Kernel.sum_apply] + apply congrArg Measure.sum + funext n + have he : firstEvenReturnContinuation n z = (firstReturn n z.2).map (fun y => (z.1,y)) := by + ext B hB + rw [firstEvenReturnContinuation_apply _ _ hB, + Measure.map_apply (f := fun y : OddCost => (z.1,y)) (measurable_const.prodMk measurable_id) hB] + rfl + rw [firstMarkedReturn,Kernel.map_apply _ (markReturn_measurable n), + Measure.map_map (g := fun d : ℕ × OddCost => continueWitnessUpdate (z,d)) (f := markReturn n) (continueWitnessUpdate_measurable.comp measurable_prodMk_left) (markReturn_measurable n), + Kernel.map_apply _ (tagSourceReturn_measurable (n+1)),he, + Measure.map_map (g := tagSourceReturn (n+1)) (f := fun y : OddCost => (z.1,y)) (tagSourceReturn_measurable (n+1)) (measurable_const.prodMk measurable_id)] + apply congrArg (fun f => (firstReturn n z.2).map f) + funext y + apply Prod.ext + · rfl + · apply Prod.ext + · dsimp [Function.comp_def,continueWitnessUpdate,markReturn,tagSourceReturn] + omega + · rfl + +lemma firstPairs_partition : capturedFirstPair+killedFirstPair=pairWitnessKernel := by + ext z : 1 + rw [_root_.add_apply,capturedFirstPair,killedFirstPair,Kernel.restrict_apply,Kernel.restrict_apply] + simpa only [preimage_compl] using + Measure.restrict_add_restrict_compl (μ := pairWitnessKernel z) (returnSet_measurable.preimage measurable_snd) + +lemma witnessContinuation_comp_captured : + witnessContinuation ∘ₖ capturedFirstPair = sourceWitnessTerm 0 := by + let D : Kernel FirstPairWitness SourceCycleWitness := Kernel.deterministic (tagSourceReturn 0) (tagSourceReturn_measurable 0) + have he : witnessContinuation ∘ₖ capturedFirstPair = D ∘ₖ capturedFirstPair := by + ext z B hB + rw [Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB] + apply lintegral_congr_ae + have hae : ∀ᵐ y ∂capturedFirstPair z, y.2 ∈ returnSet := by + rw [capturedFirstPair,Kernel.restrict_apply] + exact ae_restrict_mem (returnSet_measurable.preimage measurable_snd) + filter_upwards [hae] with y hy + rw [witnessContinuation_at_return y hy] + rfl + rw [he] + exact Kernel.deterministic_comp_eq_map _ _ + +lemma witnessContinuation_comp_killed : witnessContinuation ∘ₖ killedFirstPair = + Kernel.sum (fun n : ℕ => sourceWitnessTerm (n+1)) := by + have he : witnessContinuation ∘ₖ killedFirstPair = witnessRemaining ∘ₖ killedFirstPair := by + ext z B hB + rw [Kernel.comp_apply' _ _ _ hB,Kernel.comp_apply' _ _ _ hB] + apply lintegral_congr_ae + have hae : ∀ᵐ y ∂killedFirstPair z, y.2 ∉ returnSet := by + rw [killedFirstPair,Kernel.restrict_apply] + exact ae_restrict_mem (returnSet_measurable.compl.preimage measurable_snd) + filter_upwards [hae] with y hy + rw [witnessContinuation_outside_return y hy] + rw [he,witnessRemaining,Kernel.comp_sum_left] + apply congrArg Kernel.sum + funext n + rw [sourceWitnessTerm,sourceReturnTerm,Kernel.map_comp] + +theorem sourceCycleWitness_series : + sourceCycleWitnessKernel = Kernel.sum sourceWitnessTerm := by + rw [sourceCycleWitnessKernel,← firstPairs_partition,Kernel.comp_add_right, + witnessContinuation_comp_captured,witnessContinuation_comp_killed] + ext z B hB + rw [_root_.add_apply,Measure.add_apply,Kernel.sum_apply' _ _ hB,Kernel.sum_apply' _ _ hB] + exact (tsum_eq_zero_add' (f := fun n : ℕ => sourceWitnessTerm n z B) ENNReal.summable).symm + +lemma sourceWitnessTerm_duration (n : ℕ) (z : OddCost) : + ∀ᵐ y ∂sourceWitnessTerm n z, y.2.1=2*(n+1) := by + rw [sourceWitnessTerm,Kernel.map_apply _ (tagSourceReturn_measurable n)] + apply (ae_map_iff (tagSourceReturn_measurable n).aemeasurable + (measurableSet_eq_fun (measurable_fst.comp measurable_snd) measurable_const)).mpr + exact Eventually.of_forall (fun _ => rfl) + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/StopLengthBandGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/StopLengthBandGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..698e51c11c53981e1216c45137947cd159ab107a --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/StopLengthBandGeometry.lean @@ -0,0 +1,58 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.CrossingBandGeometry + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.StopLengthBandGeometry +open NearbyParentGeometry + +theorem shifted_ratio_band {r b a : ℝ} (hb : 400 ≤ b) (ha0 : 0 ≤ a) (ha1 : a ≤ 1) + (hlo : 204/100 ≤ r/b) (hhi : r/b ≤ 218/100) : + 2035/1000 ≤ r/b+(a-2)/b ∧ r/b+(a-2)/b ≤ 218/100 := by + have hbp : 0 < b := by linarith + have hshift : -(1/200:ℝ) ≤ (a-2)/b := (le_div_iff₀ hbp).mpr (by nlinarith) + have hshift0 : (a-2)/b ≤ 0 := div_nonpos_of_nonpos_of_nonneg (by linarith) hbp.le + constructor <;> linarith + +theorem bin_log_length_stability {Y q P R xi p p₀ : ℝ} + (hY : 0 < Y) (hq : 0 < q) (hR : 0 < R) (_hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hp : R ≤ p ∧ p ≤ (1+xi)*R) (hp₀ : R ≤ p₀ ∧ p₀ ≤ (1+xi)*R) + (hlogP : 200 ≤ Real.log P) : + |Real.log (Y/(p*q))/Real.log P-Real.log (Y/(p₀*q))/Real.log P| ≤ 1/200 := by + have hp0 := hR.trans_le hp.1 + have hp00 := hR.trans_le hp₀.1 + have hden : 0 < Real.log P := by linarith + have habs : |p-p₀| ≤ xi*R := abs_le.mpr ⟨by nlinarith,by nlinarith⟩ + have hlog : |Real.log p-Real.log p₀| ≤ xi := by + have hh := log_stability hR hp.1 hp₀.1 + have hd := div_le_div_of_nonneg_right habs hR.le + rw [mul_div_cancel_right₀ xi hR.ne'] at hd + exact hh.trans hd + have he : Real.log (Y/(p*q))-Real.log (Y/(p₀*q))=Real.log p₀-Real.log p := by + rw [Real.log_div hY.ne' (mul_pos hp0 hq).ne',Real.log_div hY.ne' (mul_pos hp00 hq).ne', + Real.log_mul hp0.ne' hq.ne',Real.log_mul hp00.ne' hq.ne'] + ring + rw [← sub_div,he,abs_div,abs_of_pos hden,abs_sub_comm (Real.log p₀)] + calc + _ ≤ xi/Real.log P := div_le_div_of_nonneg_right hlog hden.le + _ ≤ 1/Real.log P := div_le_div_of_nonneg_right hxi1 hden.le + _ ≤ 1/200 := one_div_le_one_div_of_le (by norm_num) hlogP + +theorem whole_bin_length_band {Y q P R xi p p₀ s₀ : ℝ} + (hY : 0 < Y) (hq : 0 < q) (hR : 0 < R) (hxi : 0 ≤ xi) (hxi1 : xi ≤ 1) + (hp : R ≤ p ∧ p ≤ (1+xi)*R) (hp₀ : R ≤ p₀ ∧ p₀ ≤ (1+xi)*R) + (hlogP : 200 ≤ Real.log P) (hs₀ : Real.log (Y/(p₀*q))/Real.log P=s₀) + (hband : 2035/1000 ≤ s₀ ∧ s₀ ≤ 218/100) : + 203/100 ≤ Real.log (Y/(p*q))/Real.log P ∧ Real.log (Y/(p*q))/Real.log P ≤ 219/100 := by + have hh := bin_log_length_stability hY hq hR hxi hxi1 hp hp₀ hlogP + rw [hs₀] at hh + constructor <;> linarith [(abs_le.mp hh).1,(abs_le.mp hh).2] +end NumberTheoryLean.StopLengthBandGeometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/StoppedErrorReduction.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/StoppedErrorReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..48b4926cae0a729dda4a783eda6a996e64f527f6 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/StoppedErrorReduction.lean @@ -0,0 +1,71 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.CountErrorRemainder + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.StoppedErrorReduction +open FinitePathGeometry PrimeHistories PrimeBinMembership ReferenceAdmission +open CountErrorRemainder CountErrorClassification LiteralCountErrorLedger +open StoppedCountVertex StoppedCountAdapters StoppedVertexHistory StoppedTraceSets +open LogarithmicBinPartition +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem stopped_error_reduction (aStar d eta : ℝ) (ha : 0 < aStar) (hd : 0 < d) (heta : 0 < eta) : + ∃ Cbad K₀ : ℝ,0 < Cbad ∧ 3 ≤ K₀ ∧ ∀ K : ℝ,K₀ ≤ K → + ∃ Csmall B₀ w₀ : ℝ,0 < Csmall ∧ 3 ≤ B₀ ∧ 1 < w₀ ∧ + ∀ B w top : ℝ,B₀ ≤ B → w₀ ≤ w → w < top → Real.log B ≤ d*Real.log w → + ∀ Y : ℕ,0 < Y → ∀ z : Node,z.gap=Real.log (Y:ℝ)/Real.log w-aStar+2 → + z.side=.even → 199/100 ≤ z.ratio → z.ratio ≤ 23/10 → Consistent z → z.cutoff=B → z.closed=true → w^B=top → + ∀ residue : ℕ → ℕ,∀ eps : ℝ,0 ≤ eps → ∀ stop : List ℕ → Prop, + let P := sourcePrimeSet w top + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + let v := rootVertex z ∅ P ((Y:ℝ)*V0) + B^2*referencePolynomial w P z.side z.gap+ + (B^2/((Y:ℝ)*V0))*(∑ ps∈stopped w stop P.card v, + (countSurvivors Y small residue (after w v ps)-referenceValue w (after w v ps))) - + eta-Csmall*eps-Cbad*(B^2*(∑ ps∈badCompactWords w K eps Y small residue V0 z (expanded w stop P.card v),prefixWeight ps)) ≤ + (B^2/((Y:ℝ)*V0))*countSurvivors Y small residue v := by + obtain ⟨Cbad,K₀,hCbad,hK₀,hReduction⟩ := uniform_count_error_remainder aStar d eta ha hd heta + refine ⟨Cbad,K₀,hCbad,hK₀,?_⟩ + intro K hK + obtain ⟨Csmall,B₀,W,hCsmall,hB₀,hW,hError⟩ := hReduction K hK + refine ⟨Csmall,B₀,max W 2,hCsmall,hB₀,hW.trans_le (le_max_left _ _),?_⟩ + intro B w top hB hw₀ htop hcomp Y hY z hroot hi h199 h23 hz hcut hclosed hpower residue eps heps stop + dsimp only + let P := sourcePrimeSet w top + let small := LargePrimeDeletion.cutoffPrimes ⌊w⌋₊ + let V0 := SmallSieveFinite.smallEuler ⌊w⌋₊ + let v := rootVertex z ∅ P ((Y:ℝ)*V0) + have hw : 1 < w := hW.trans_le ((le_max_left _ _).trans hw₀) + have hw2 : 2 ≤ w := (le_max_right _ _).trans hw₀ + have hV : 0 < V0 := (inv_pos.mpr (zero_lt_one.trans hw)).trans_le (SmallSieveFinite.smallEuler_floor_ge_inv w hw2) + have hYr : 0 < (Y:ℝ) := by exact_mod_cast hY + have hmu : 0 < (Y:ℝ)*V0 := mul_pos hYr hV + have hErrorBound := hError B w top hB ((le_max_left _ _).trans hw₀) htop hcomp Y hY z hroot + hi h199 h23 hz hcut hclosed hpower residue eps heps (expanded w stop P.card v) + (expanded_reference_subset w P z ((Y:ℝ)*V0) stop P.card) + have hPrime : ∀ p∈P,p.Prime := fun p hp => ((mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mp hp).1 + have hLedger := literal_count_error_ledger w Y small P residue z V0 stop hi hPrime + have hScaled := mul_le_mul_of_nonneg_left hLedger (show 0 ≤ B^2/((Y:ℝ)*V0) by positivity) + have hCancel : (B^2/((Y:ℝ)*V0))*(((Y:ℝ)*V0)*referencePolynomial w P z.side z.gap)= + B^2*referencePolynomial w P z.side z.gap := by field_simp [hmu.ne'] + dsimp only at hErrorBound + unfold errorSum at hErrorBound + change B^2*referencePolynomial w P z.side z.gap+ + (B^2/((Y:ℝ)*V0))*(∑ ps∈stopped w stop P.card v, + (countSurvivors Y small residue (after w v ps)-referenceValue w (after w v ps))) - + eta-Csmall*eps-Cbad*(B^2*(∑ ps∈badCompactWords w K eps Y small residue V0 z (expanded w stop P.card v),prefixWeight ps)) ≤ + (B^2/((Y:ℝ)*V0))*countSurvivors Y small residue v + nlinarith +end NumberTheoryLean.StoppedErrorReduction + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/StoppedReferenceFinite.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/StoppedReferenceFinite.lean new file mode 100644 index 0000000000000000000000000000000000000000..dcf3cdbeb4b08357309a35efeadcd53bd61faca8 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/StoppedReferenceFinite.lean @@ -0,0 +1,149 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.SourceRootReference + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosStoppedReferenceUpper +open NumberTheoryLean.FinitePathGeometry NumberTheoryLean.BuchstabBridge +open NumberTheoryLean.LinearSieveFunctions NumberTheoryLean.ReferenceDifferentiation + +theorem log_near_two_upper {s : ℝ} (hs : 2 ≤ s) : + Real.log (s-1) ≤ 1/10+(10/11)*(s-21/10) := by + have hpos : 0 < s-1 := by linarith + have hlog := Real.log_le_sub_one_of_pos (div_pos hpos (by norm_num : (0:ℝ)<11/10)) + rw [Real.log_div (ne_of_gt hpos) (by norm_num : (11/10:ℝ)≠0)] at hlog + have ht := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<11/10) + linarith + +theorem parent_benchmark_le_32 {s : ℝ} (hs : 2 ≤ s) (hu : s ≤ 218/100) : + parentBenchmark .even s ≤ 32/100 := by + rw [parent_even_eq_starting (by linarith : s ≤ 4)] + unfold startingExtension + have hlog := log_near_two_upper hs + have hnonneg : 0 ≤ Real.log (s-1) := Real.log_nonneg (by linarith) + have hA : sieveA ≤ 4 := by + unfold sieveA + linarith [ErdosPositiveReference.exp_gamma_lt_two] + have hm := mul_le_mul_of_nonneg_right hA hnonneg + apply (div_le_iff₀ (by linarith : 0 (z:ZMod t)) hn + simp only [Int.cast_mul,Int.cast_add,Int.cast_natCast] at hh + have hu : IsUnit (D:ZMod t) := (ZMod.isUnit_iff_coprime _ _).mpr + (ht.coprime_iff_not_dvd.mpr htD).symm + constructor + · intro he + rw [he] at hh + linear_combination -hh + · intro he + apply hu.mul_left_cancel + rw [hh,he] + ring + +lemma mul_forbidden_iff (D t : ℕ) (A B : ℤ) (residue : ℕ → ℤ) (p : ℕ) + (hB : IsUnit (B:ZMod t)) : + (B:ZMod t)*(p:ZMod t)=(D:ZMod t)*(residue t)-A ↔ + (p:ZMod t)=forbiddenClass D A B residue t := by + have hh := affine_eq_iff t 0 B ((D:ℤ)*(residue t)-A) hB (p:ZMod t) + simpa only [Int.cast_zero,zero_add,Int.cast_sub,Int.cast_mul,Int.cast_natCast,sub_zero,forbiddenClass] using hh + +lemma prime_cast_ne_zero_of_large (P : ℝ) (p t : ℕ) (hp : p.Prime) (hPp : P ≤ (p:ℝ)) + (ht : t∈smallPrimeSet P) : (p:ZMod t)≠0 := by + obtain ⟨htp,htP⟩ := (mem_smallPrimeSet P t).mp ht + intro hz + have hd := (ZMod.natCast_eq_zero_iff p t).mp hz + rcases hp.eq_one_or_self_of_dvd t hd with he | he + · exact htp.ne_one he + · have her : (t:ℝ)=p := by exact_mod_cast he + linarith + +theorem all_small_avoidance_iff (P : ℝ) (D : ℕ) (hD : 0 < D) (hDP : (D:ℝ) (D:ℤ)∣A+B*p ∧ + ∀ t∈smallPrimeSet P,(actualN D A B p:ZMod t)≠residue t) + +theorem actualSurvivorPrimes_eq_sieve (P R V : ℝ) (hPR : P ≤ R) + (D : ℕ) (hD : 0 < D) (hDP : (D:ℝ) B*y^3*Real.exp (-(c/2)*y)) atTop (𝓝 0) := by + simpa [mul_assoc] using + (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (3:ℝ) (c/2) (by positivity)).const_mul B + obtain ⟨y₀,hy₀⟩ := eventually_atTop.mp (ht.eventually (gt_mem_nhds heps)) + have hp : ∀ᶠ w : ℝ in atTop,y₀ ≤ w^((1:ℝ)/12) := + (tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/12)).eventually (eventually_ge_atTop y₀) + filter_upwards [hdom,hp] with w hw hwy + refine ⟨hw.1,?_⟩ + intro P R hP hPcap hR + have hRw : w ≤ R := (moving_lower_ge_self (by linarith [hw.1])).trans hR + have hR1 : 1 ≤ R := by linarith [hw.1] + have hlog : 0 ≤ Real.log R := Real.log_nonneg hR1 + have he := hw.2 P R hP hPcap hR + have hprod := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left he hB) hlog) + (Real.exp_pos (-c*cubeHeight R)).le + have hrate := hy₀ (cubeHeight R) (hwy.trans (cubeHeight_moving_lower hw.1 hR)) + have hEq : B*Real.exp ((c/2)*cubeHeight R)*Real.log R*Real.exp (-c*cubeHeight R)= + B*(cubeHeight R)^3*Real.exp (-(c/2)*cubeHeight R) := by + rw [cubeHeight_pow_three hR1] + have hh : Real.exp ((c/2)*cubeHeight R)*Real.exp (-c*cubeHeight R)=Real.exp (-(c/2)*cubeHeight R) := by + rw [← Real.exp_add] + congr 1 + ring + calc + _ = B*Real.log R*(Real.exp ((c/2)*cubeHeight R)*Real.exp (-c*cubeHeight R)) := by ring + _ = _ := by rw [hh] + rw [hEq] at hprod + have hleft : B*w^A*P^b*Real.log R*Real.exp (-c*cubeHeight R)= + B*(w^A*P^b)*Real.log R*Real.exp (-c*cubeHeight R) := by ring + rw [hleft] + exact hprod.trans hrate.le + +end ErdosStoppedTagSieve + + + +namespace ErdosStoppedTagSieve +open _root_.Filter +open scoped Topology +open Erdos970Dependency.SiegelWalfisz + +lemma eventually_cutoff_dominates (a K : ℝ) (hK : 0 < K) : + ∀ᶠ w : ℝ in atTop,3 ≤ w ∧ w^a < Real.exp (K*(Real.log w)^3) := by + filter_upwards [eventually_ge_atTop (3:ℝ),Real.tendsto_log_atTop.eventually + (eventually_ge_atTop (max 1 ((a+1)/K)))] with w hw hL + refine ⟨hw,?_⟩ + have hw0 : 0 < w := by linarith + have hL1 : 1 ≤ Real.log w := (le_max_left _ _).trans hL + have haK : (a+1)/K ≤ Real.log w := (le_max_right _ _).trans hL + have hKL : a+1 ≤ K*Real.log w := by + have hh := (div_le_iff₀ hK).mp haK + nlinarith + have hLsq : Real.log w ≤ (Real.log w)^2 := by nlinarith + have hKsq : a+1 ≤ K*(Real.log w)^2 := hKL.trans (mul_le_mul_of_nonneg_left hLsq hK.le) + have hcube : (a+1)*Real.log w ≤ K*(Real.log w)^3 := by + calc + _ ≤ (K*(Real.log w)^2)*Real.log w := mul_le_mul_of_nonneg_right hKsq (by linarith) + _ = _ := by ring + rw [Real.rpow_def_of_pos hw0] + apply Real.exp_lt_exp.mpr + nlinarith + +lemma eventually_cutoff_le_subbin (K : ℝ) : + ∀ᶠ w : ℝ in atTop,3 ≤ w ∧ ∀ P R : ℝ, + P ≤ Real.exp (K*(Real.log w)^3) → Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ R → P ≤ R := by + have hp := Real.tendsto_log_atTop.eventually + (eventually_polynomial_le_exp K 3 (by norm_num : (0:ℝ)<1/4)) + filter_upwards [eventually_ge_atTop (3:ℝ),hp] with w hw hpw + refine ⟨hw,?_⟩ + intro P R hP hR + have hw0 : 0 < w := by linarith + have he : Real.exp ((1/4:ℝ)*Real.log w)=w^((1:ℝ)/4) := by + rw [Real.rpow_def_of_pos hw0] + congr 1 + ring + have hpoly : K*(Real.log w)^3 ≤ w^((1:ℝ)/4) := by simpa only [he] using hpw.2 + have hlog := hpw.1 + have hpow : 0 ≤ w^((1:ℝ)/4) := Real.rpow_nonneg hw0.le _ + have hh : K*(Real.log w)^3 ≤ w^((1:ℝ)/4)*Real.log w := by + nlinarith [mul_nonneg hpow (sub_nonneg.mpr hlog)] + exact (hP.trans (Real.exp_le_exp.mpr hh)).trans hR + +end ErdosStoppedTagSieve + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/TagIntersectionError.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagIntersectionError.lean new file mode 100644 index 0000000000000000000000000000000000000000..d5dfb8ff8155863a233dcc538ced5399b238a80c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagIntersectionError.lean @@ -0,0 +1,78 @@ +import OAI.NumberTheory.Jacobsthal.Primes.TagPrimePartition + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace ErdosStoppedTagSieve + +open scoped BigOperators +open Erdos970Dependency.SiegelWalfisz + +lemma inverse_totient_intersection (Q : ℕ) (T : Finset ℕ) + (hT : ∀ t∈T,t.Prime) (hQT : ∀ t∈T,Q.Coprime t) : + (1:ℝ)/((Q*(∏ t∈T,t)).totient:ℝ)= + (1/(Q.totient:ℝ))*(∏ t∈T,1/((t:ℝ)-1)) := by + rw [totient_intersection_modulus Q T hT hQT,Nat.cast_mul,Nat.cast_prod] + have he : (∏ t∈T,((t-1:ℕ):ℝ))=∏ t∈T,((t:ℝ)-1) := by + apply Finset.prod_congr rfl + intro t ht + rw [Nat.cast_sub (hT t ht).one_le,Nat.cast_one] + rw [he] + simp only [one_div,mul_inv_rev,Finset.prod_inv_distrib] + ring + +theorem intersection_prime_error : + ∃ c C X₀ : ℝ,0 < c ∧ 0 < C ∧ 3 ≤ X₀ ∧ + ∀ R V : ℝ,X₀ ≤ R → 0 ≤ V → V ≤ R → ∀ Q : ℕ,0 < Q → + ∀ T A : Finset ℕ,∀ rho : (t : ℕ) → ZMod t, + (∀ t∈T,t.Prime) → (∀ t∈T,Q.Coprime t) → + (∀ a∈A,a (hT t ht).pos)) + have hB : B.card=A.card := intersectionResidues_card Q hQ T A rho hT hQT hA + have hbound : ∀ a∈B,|((intervalPrimes R V M (a:ℤ)).card:ℝ)-N/(M.totient:ℝ)| ≤ + C*R*Real.exp (-c*cubeHeight R) := by + intro a ha + have hred := (intersectionResidues_reduced Q hQ T A rho hT hQT hA hAc hrho a ha).2 + exact hAP R V hR hV hVR M (a:ℤ) hM hred.isCoprime hmod + have hmean : (∑ _a∈B,N/(M.totient:ℝ))= + (N*(A.card:ℝ)/(Q.totient:ℝ))*(∏ t∈T,1/((t:ℝ)-1)) := by + rw [Finset.sum_const,nsmul_eq_mul,hB] + have hd := inverse_totient_intersection Q T hT hQT + change 1/(M.totient:ℝ)=_ at hd + calc + _ = N*(A.card:ℝ)*(1/(M.totient:ℝ)) := by ring + _ = _ := by rw [hd]; ring + have hsum : (∑ a∈B,(((intervalPrimes R V M (a:ℤ)).card:ℝ)-N/(M.totient:ℝ)))= + ((intersectionPrimes R V Q T A rho).card:ℝ)- + (N*(A.card:ℝ)/(Q.totient:ℝ))*(∏ t∈T,1/((t:ℝ)-1)) := by + rw [Finset.sum_sub_distrib,hmean,← Nat.cast_sum] + congr 1 + exact_mod_cast (intersectionPrimes_card R V Q hQ T A rho hT hQT hA).symm + change |((intersectionPrimes R V Q T A rho).card:ℝ)- + (N*(A.card:ℝ)/(Q.totient:ℝ))*(∏ t∈T,1/((t:ℝ)-1))| ≤ _ + rw [← hsum] + calc + _ ≤ ∑ a∈B,|((intervalPrimes R V M (a:ℤ)).card:ℝ)-N/(M.totient:ℝ)| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _a∈B,C*R*Real.exp (-c*cubeHeight R) := Finset.sum_le_sum hbound + _ = _ := by rw [Finset.sum_const,nsmul_eq_mul,hB]; ring + +end ErdosStoppedTagSieve + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/TagPairBinding.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagPairBinding.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ed8e24b2d7662560143c2646ead28c93f0e50cd --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagPairBinding.lean @@ -0,0 +1,211 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.HypotheticalPairRows +import OAI.NumberTheory.Jacobsthal.Sieve.ClosedEulerIndividualUpper +import OAI.NumberTheory.Jacobsthal.Sieve.TagPrimeSieveLower + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.Filter +namespace ErdosStoppedArithmetic +open NumberTheoryLean ErdosPrimeInputs.MertensStrong ReferenceProductsBasics ReferenceMertens + + +theorem eventual_closed_euler_lower_scale (eps : ℝ) (heps : 0 < eps) : + ∀ᶠ P : ℝ in atTop,1 < P ∧ + (1-eps)*primeProduct P ≤ Real.exp (-Real.eulerMascheroniConstant)/Real.log P := by + have hn := normalization_tendsto_one.eventually (lt_mem_nhds (by linarith : 1-eps < (1 : ℝ))) + filter_upwards [hn,eventually_gt_atTop (1 : ℝ)] with P hn hP + have hlog := Real.log_pos hP + have hV := actual_primeProduct_pos P + have hnorm : 1-eps ≤ Real.exp (-Real.eulerMascheroniConstant)/(Real.log P*primeProduct P) := hn.le + have hh := (le_div_iff₀ (mul_pos hlog hV)).mp hnorm + refine ⟨hP,?_⟩ + apply (le_div_iff₀ hlog).mpr + nlinarith + +theorem stopped_pair_coefficient (N J H D L V E S : ℝ) + (hN : 0 ≤ N) (hJ : 0 ≤ J) (hD : 0 < D) (hL : 0 < L) + (hV : 0 ≤ V) (hE : 0 ≤ E) (hS : 0 < S) (hSup : S ≤ (111/50 : ℝ)) + (hH : (999/1000 : ℝ)*D*J ≤ H) + (hNorm : (999/1000 : ℝ)*V ≤ E/L) : + (39/100 : ℝ)*N*J*V ≤ + ((999/1000 : ℝ)*H/(S*L))*((19/20 : ℝ)*N/D)*(E*(939/1000 : ℝ)) := by + let a : ℝ := 999/1000 + let b : ℝ := 19/20 + let c : ℝ := 939/1000 + have hConst : (39/100 : ℝ) ≤ (a^3*b*c)/(111/50 : ℝ) := by norm_num [a,b,c] + have hHJ : a*J ≤ H/D := by + apply (le_div_iff₀ hD).mpr + dsimp [a] + nlinarith + have hNorm' : a*V ≤ E/L := hNorm + have hEL : 0 ≤ E/L := div_nonneg hE hL.le + calc + _ ≤ ((a^3*b*c)/(111/50 : ℝ))*(N*J*V) := by + have hh := mul_le_mul_of_nonneg_right hConst (mul_nonneg (mul_nonneg hN hJ) hV) + nlinarith only [hh] + _ = (a^2*b*c*N*J*(a*V))/(111/50 : ℝ) := by ring + _ ≤ (a^2*b*c*N*J*(E/L))/(111/50 : ℝ) := by + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hNorm' + (by dsimp [a,b,c];positivity)) (by norm_num) + _ ≤ (a^2*b*c*N*J*(E/L))/S := + div_le_div_of_nonneg_left (by dsimp [a,b,c];positivity) hS hSup + _ = (a*b*c*N*(a*J)*(E/L))/S := by ring + _ ≤ (a*b*c*N*(H/D)*(E/L))/S := by + have hh := mul_le_mul_of_nonneg_left hHJ (show 0 ≤ a*b*c*N by dsimp [a,b,c];positivity) + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hh hEL) hS.le + _ = _ := by + dsimp [a,b,c] + simp only [div_eq_mul_inv,mul_inv_rev] + ring + +end ErdosStoppedArithmetic + +end + +section + +open _root_.Filter +namespace ErdosStoppedArithmetic +open Erdos970Dependency.SiegelWalfisz Erdos970.EulerWeightedLower + NumberTheoryLean.ReferenceProductsBasics ErdosPrimeInputs.MertensStrong + +attribute [local instance] Classical.propDecidable + +theorem moving_subbin_pair_lower (Cs : ℝ) (hCs : 0 ≤ Cs) : + ∃ K : ℝ,0 < K ∧ ∀ rho : ℝ,1 < rho → ∃ w0 : ℝ,4 ≤ w0 ∧ + ∀ w : ℝ,w0 ≤ w → ∀ P s x y : ℝ, + Real.exp (K*(Real.log w)^3) ≤ P → P ≤ Real.exp (rho*K*(Real.log w)^3) → + 203/100 ≤ s → s ≤ 219/100 → + ∀ D : ℕ,0 < D → (999/1000 : ℝ)*(D : ℝ)*P^s ≤ y-x → + max |x| |y| ≤ 2*w^(Cs+2)*P^s → + ∀ (E T : Finset ℕ) (good : ℕ → ℤ → Prop),E ⊆ primesThrough P → + (∀ d ∈ supportedIntegers E ⌊P^(95/100 : ℝ)⌋₊,∀ m ∈ primeMultiplesIn d P x y, + ((19/20 : ℝ)*(T.card : ℝ)/(D : ℝ))*paperWeight E d ≤ + ((T.filter (fun p => good p m)).card : ℝ)) → + (39/100 : ℝ)*(T.card : ℝ)*P^s*primeProduct P ≤ + ((admissiblePairs T ((supportedIntegers E ⌊P^(95/100 : ℝ)⌋₊).biUnion + (fun d => primeMultiplesIn d P x y)) good).card : ℝ) := by + obtain ⟨K,hK,hPairs⟩ := moving_weighted_pair_lower Cs hCs + refine ⟨K,hK,?_⟩ + intro rho hrho + obtain ⟨wS,hwS,hS⟩ := hPairs rho hrho (1/1000) (by norm_num) (by norm_num) + obtain ⟨P0,hP0⟩ := eventually_atTop.mp (eventual_closed_euler_lower_scale (1/1000) (by norm_num)) + obtain ⟨wG,hwG⟩ := eventually_atTop.mp ((exponential_log_cube_tendsto hK).eventually_ge_atTop (max 2 P0)) + refine ⟨max wS wG,hwS.trans (le_max_left _ _),?_⟩ + intro w hw P s x y hPlower hPupper hs hsupper D hD hCommon hHeight E T good hE hTag + have hLarge : max 2 P0 ≤ P := (hwG w ((le_max_right _ _).trans hw)).trans hPlower + have hP2 : 2 ≤ P := (le_max_left _ _).trans hLarge + have hP : 1 < P := by linarith + have hPpos : 0 < P := by linarith + have hPs : 0 < P^s := Real.rpow_pos_of_pos hPpos _ + have hDr : 0 < (D : ℝ) := by exact_mod_cast hD + have hD1 : (1 : ℝ) ≤ D := by exact_mod_cast hD + have hWidth : P^s/2 ≤ y-x := by + have hh := mul_le_mul_of_nonneg_right hD1 (show 0 ≤ (999/1000 : ℝ)*P^s by positivity) + nlinarith + have hB : 0 ≤ (19/20 : ℝ)*(T.card : ℝ)/(D : ℝ) := by positivity + have hResult := hS w ((le_max_left _ _).trans hw) P s x y hPlower hPupper hs hsupper + hWidth hHeight E T good ((19/20 : ℝ)*(T.card : ℝ)/(D : ℝ)) hE hB hTag + have hNorm := (hP0 P ((le_max_right _ _).trans hLarge)).2 + have heps : (1 : ℝ)-1/1000=999/1000 := by norm_num + have hweight : (94/100 : ℝ)-1/1000=939/1000 := by norm_num + rw [heps] at hNorm + rw [heps,hweight] at hResult + have hCoeff := stopped_pair_coefficient (T.card : ℝ) (P^s) (y-x) (D : ℝ) (Real.log P) + (primeProduct P) (Real.exp (-Real.eulerMascheroniConstant)) (s+1/50) + (Nat.cast_nonneg _) hPs.le hDr (Real.log_pos hP) (actual_primeProduct_pos P).le + (Real.exp_pos _).le (by linarith) (by linarith) hCommon hNorm + exact hCoeff.trans hResult + +end ErdosStoppedArithmetic + +end + + +namespace ErdosStoppedArithmetic +open ErdosStoppedTagSieve Erdos970Dependency.SiegelWalfisz + Erdos970.EulerWeightedLower ErdosUnitLifts + NumberTheoryLean.ReferenceProductsBasics ErdosPrimeInputs.MertensStrong + +attribute [local instance] Classical.propDecidable + +def actualTagGood (P : ℝ) (r : ℚ) (q : ℕ) (a : ℕ → ℕ) (p : ℕ) (m : ℤ) : Prop := + (r.den : ℤ) ∣ r.num+(q : ℤ)*m*p ∧ + ∀ t ∈ smallPrimeSet P, + (actualN r.den r.num ((q : ℤ)*m) p : ZMod t) ≠ (a t : ℤ) + +theorem unaligned_subset_primesThrough (P : ℝ) (D : ℕ) (A : ℤ) (residue : ℕ → ℤ) : + unalignedPrimes P D A residue ⊆ primesThrough P := by + intro t ht + obtain ⟨htp,htP⟩ := (mem_smallPrimeSet P t).mp (Finset.mem_filter.mp ht).1 + have hP0 : 0 ≤ P := (Nat.cast_nonneg t).trans htP.le + apply Finset.mem_filter.mpr + exact ⟨Finset.mem_Ioc.mpr ⟨htp.pos,(Nat.le_floor_iff hP0).mpr htP.le⟩,htp⟩ + +theorem actual_restricted_weight (P : ℝ) (D : ℕ) (A : ℤ) (residue : ℕ → ℤ) (d : ℕ) : + paperWeight (unalignedPrimes P D A residue) d = + eulerWeight (restrictedPrimes P D A residue d) := rfl + +theorem actual_tag_filter (P R V : ℝ) (r : ℚ) (q : ℕ) (a : ℕ → ℕ) (m : ℤ) : + (intervalPrimes R V 1 0).filter (fun p => actualTagGood P r q a p m) = + actualSurvivorPrimes P R V r.den r.num ((q : ℤ)*m) (fun t => (a t : ℤ)) := by + ext p + simp only [actualTagGood,actualSurvivorPrimes,Finset.mem_filter,Int.cast_natCast] + +theorem actual_tag_original_tests (P : ℝ) (r : ℚ) (q p : ℕ) (a : ℕ → ℕ) (m : ℤ) + (h : actualTagGood P r q a p m) : + (r.den : ℤ) ∣ r.num+((p*q : ℕ) : ℤ)*m ∧ + ∀ t ∈ smallPrimeSet P, + ¬Int.ModEq (t : ℤ) ((r.num+((p*q : ℕ) : ℤ)*m)/(r.den : ℤ)) (a t : ℤ) := by + have he : r.num+((p*q : ℕ) : ℤ)*m = r.num+(q : ℤ)*m*p := by push_cast;ring + rw [he] + refine ⟨h.1,?_⟩ + intro t ht hh + exact h.2 t ht ((ZMod.intCast_eq_intCast_iff _ _ t).mpr hh) + +theorem moving_subbin_actual_pair_lower (Cs : ℝ) (hCs : 0 ≤ Cs) : + ∃ K : ℝ,0 < K ∧ ∀ rho xi : ℝ,1 < rho → 0 < xi → + ∃ w0 : ℝ,4 ≤ w0 ∧ ∀ w : ℝ,w0 ≤ w → ∀ P s x y R V : ℝ, + Real.exp (K*(Real.log w)^3) ≤ P → P ≤ Real.exp (rho*K*(Real.log w)^3) → + 203/100 ≤ s → s ≤ 219/100 → + Real.exp (w^((1:ℝ)/4)*Real.log w) ≤ R → + xi/(16*w^(2*Cs+10)) ≤ V/R → V/R ≤ w^(-(2*Cs+10)) → + ∀ r : ℚ,(r.den : ℝ) ≤ w^Cs → ∀ q : ℕ,∀ a : ℕ → ℕ, + (∀ t ∈ smallPrimeSet P,q.Coprime t) → + (999/1000 : ℝ)*(r.den : ℝ)*P^s ≤ y-x → + max |x| |y| ≤ 2*w^(Cs+2)*P^s → + (39/100 : ℝ)*((intervalPrimes R V 1 0).card : ℝ)*P^s*primeProduct P ≤ + ((admissiblePairs (intervalPrimes R V 1 0) + ((supportedIntegers (unalignedPrimes P r.den r.num (fun t => (a t : ℤ))) + ⌊P^(95/100 : ℝ)⌋₊).biUnion (fun d => primeMultiplesIn d P x y)) + (actualTagGood P r q a)).card : ℝ) := by + obtain ⟨K,hK,hPair⟩ := moving_subbin_pair_lower Cs hCs + refine ⟨K,hK,?_⟩ + intro rho xi hrho hxi + obtain ⟨wP,hwP,hP⟩ := hPair rho hrho + obtain ⟨wT,_hwT,hT⟩ := tag_prime_sieve_lower Cs K rho xi (1/20) hCs hK hrho hxi (by norm_num) + refine ⟨max wP wT,hwP.trans (le_max_left _ _),?_⟩ + intro w hw P s x y R V hPl hPu hs hsU hR hVlo hVhi r hD q a hq hLength hHeight + apply hP w ((le_max_left _ _).trans hw) P s x y hPl hPu hs hsU r.den r.den_pos + hLength hHeight _ _ _ (unaligned_subset_primesThrough P r.den r.num _) + intro d hd m hm + have hd' := Finset.mem_filter.mp hd + obtain ⟨ell,hell,hellP,hAbs⟩ := prime_multiple_natAbs d P x y m hm + have hh := hT w P R V ((le_max_right _ _).trans hw) hPl hPu hR hVlo hVhi + r.den r.den_pos hD r.num r.reduced (fun t => (a t : ℤ)) q d ell m hq + (Finset.mem_Icc.mp hd'.1).1 hd'.2 hell hellP hAbs + rw [actual_tag_filter,actual_restricted_weight] + convert hh using 1 + ring + +end ErdosStoppedArithmetic + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/TagRelativeAlgebra.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagRelativeAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..2bc39ce75ae733a0f436a8b6801e77b9ab801372 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagRelativeAlgebra.lean @@ -0,0 +1,69 @@ +import OAI.NumberTheory.Jacobsthal.Primes.TagSmallPrimeData + +namespace OAI + +namespace Erdos970 + + +namespace ErdosStoppedTagSieve + +open ErdosUnitLifts + +lemma actualClasses_fraction_real (D : ℕ) (hD : 0 < D) (A B : ℤ) (a : ℕ → ℤ) + (hB : IsUnit (B:ZMod D)) : + ((actualClasses D A B a).card:ℝ)/((D*radical D).totient:ℝ)=1/(D:ℝ) := by + rw [actualClasses_card D hD A B a hB,totient_lift_modulus D hD,Nat.cast_mul] + have hd : (D:ℝ)≠0 := by exact_mod_cast hD.ne' + have ht : ((radical D).totient:ℝ)≠0 := by exact_mod_cast (Nat.totient_pos.mpr (radical_pos D)).ne' + field_simp + +lemma actualClasses_card_le (D : ℕ) (hD : 0 < D) (A B : ℤ) (a : ℕ → ℤ) + (hB : IsUnit (B:ZMod D)) : (actualClasses D A B a).card ≤ D := by + rw [actualClasses_card D hD A B a hB] + exact (Nat.totient_le _).trans (Nat.le_of_dvd hD (radical_dvd D)) + +lemma lift_modulus_bound {w Cs : ℝ} (hw : 0 < w) {D : ℕ} (hD : 0 < D) + (hDw : (D:ℝ) ≤ w^Cs) : (D*radical D:ℕ) ≤ w^(2*Cs) := by + have hrad : (radical D:ℝ) ≤ D := by exact_mod_cast Nat.le_of_dvd hD (radical_dvd D) + rw [Nat.cast_mul] + calc + _ ≤ w^Cs*w^Cs := mul_le_mul hDw (hrad.trans hDw) (Nat.cast_nonneg _) (Real.rpow_nonneg hw.le _) + _ = _ := by rw [← Real.rpow_add hw]; congr 1; ring + +lemma relative_remainder_bound (A D B N W Z P L R C u e xi : ℝ) + (_hA0 : 0 ≤ A) (hAD : A ≤ D) (hD : 0 < D) (hDB : D ≤ B) + (hZ : 0 < Z) (hP : 0 < P) (hL : 0 < L) (hR : 0 < R) + (hC : 0 ≤ C) (hu : 0 ≤ u) (he : 0 ≤ e) (hxi : 0 < xi) + (hN : xi*R/(64*Z*L) ≤ N) (hW : 1/P ≤ W) : + A*C*R*u*e ≤ (N/D)*W*((64*C/xi)*B^2*Z*P*u*L*e) := by + have hN0 : 0 < N := (by positivity : 0 < xi*R/(64*Z*L)).trans_le hN + have hB : 0 < B := hD.trans_le hDB + have hAD' : A*D ≤ B^2 := by + have hh := mul_le_mul (hAD.trans hDB) hDB hD.le hB.le + simpa only [pow_two] using hh + have hN' : xi*R ≤ 64*Z*L*N := by + have hh := (div_le_iff₀ (show 0 < 64*Z*L by positivity)).mp hN + nlinarith + have hW' : 1 ≤ P*W := by + have hh := (div_le_iff₀ hP).mp hW + simpa only [mul_comm] using hh + have hChain : A*D*(xi*R) ≤ B^2*(64*Z*L*N)*(P*W) := by + calc + _ ≤ B^2*(xi*R) := mul_le_mul_of_nonneg_right hAD' (by positivity) + _ ≤ B^2*(64*Z*L*N) := mul_le_mul_of_nonneg_left hN' (sq_nonneg B) + _ ≤ _ := le_mul_of_one_le_right (by positivity) hW' + have hh := mul_le_mul_of_nonneg_right hChain (mul_nonneg (mul_nonneg hC hu) he) + apply (mul_le_mul_iff_left₀ (mul_pos hD hxi)).mp + have hleft : (A*C*R*u*e)*(D*xi)=(A*D*(xi*R))*(C*u*e) := by ring + have hright : ((N/D)*W*((64*C/xi)*B^2*Z*P*u*L*e))*(D*xi)= + (B^2*(64*Z*L*N)*(P*W))*(C*u*e) := by + field_simp + rw [hleft,hright] + exact hh + +end ErdosStoppedTagSieve + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/TagSubbinWidths.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagSubbinWidths.lean new file mode 100644 index 0000000000000000000000000000000000000000..e124ee39aa040bcf5fec0c1819a0178dae7be075 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/TagSubbinWidths.lean @@ -0,0 +1,188 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeBinCounting + +namespace OAI + +namespace Erdos970 + +section + +open scoped BigOperators +namespace ErdosTagSubbins + +noncomputable def count (w Cs : ℝ) : ℕ := ⌈w ^ (2 * Cs + 10)⌉₊ +noncomputable def step (R theta : ℝ) (N : ℕ) : ℝ := R * theta / N +noncomputable def left (R theta : ℝ) (N i : ℕ) : ℝ := R + i * step R theta N +noncomputable def right (R theta : ℝ) (N i : ℕ) : ℝ := R + (i + 1 : ℕ) * step R theta N +noncomputable def width (R theta : ℝ) (N i : ℕ) : ℝ := step R theta N / left R theta N i + +theorem count_bounds {w Cs : ℝ} (hw : 1 < w) (hCs : 0 ≤ Cs) : + 1 ≤ count w Cs ∧ w ^ (2 * Cs + 10) ≤ (count w Cs : ℝ) ∧ + (count w Cs : ℝ) ≤ 2 * w ^ (2 * Cs + 10) := by + have hp : 1 ≤ w ^ (2 * Cs + 10) := Real.one_le_rpow hw.le (by linarith) + refine ⟨Nat.one_le_ceil_iff.mpr (by linarith), Nat.le_ceil _, ?_⟩ + have h := Nat.ceil_lt_add_one (le_trans (by norm_num) hp) + dsimp [count] + linarith + +theorem step_pos {R theta : ℝ} {N : ℕ} (hR : 0 < R) (ht : 0 < theta) + (hN : 0 < N) : 0 < step R theta N := by unfold step; positivity + +theorem left_lower {R theta : ℝ} {N i : ℕ} (hs : 0 ≤ step R theta N) : + R ≤ left R theta N i := by unfold left; exact le_add_of_nonneg_right (mul_nonneg (Nat.cast_nonneg _) hs) + +theorem right_sub_left (R theta : ℝ) (N i : ℕ) : + right R theta N i - left R theta N i = step R theta N := by + simp only [right, left, Nat.cast_add, Nat.cast_one]; ring + +theorem right_eq_left_add (R theta : ℝ) (N i : ℕ) : + right R theta N i = left R theta N i + step R theta N := by + linarith [right_sub_left R theta N i] + +theorem total_step {R theta : ℝ} {N : ℕ} (hN : 0 < N) : + (N : ℝ) * step R theta N = R * theta := by + unfold step; field_simp + +theorem right_upper {R theta : ℝ} {N i : ℕ} (hR : 0 < R) (ht : 0 < theta) + (hi : i < N) : right R theta N i ≤ (1 + theta) * R := by + have hN : 0 < N := Nat.zero_lt_of_lt hi + have hs := step_pos hR ht hN + have hi' : ((i + 1 : ℕ) : ℝ) ≤ N := by exact_mod_cast hi + have h := mul_le_mul_of_nonneg_right hi' hs.le + rw [total_step hN] at h + dsimp [right]; nlinarith only [h] + +theorem left_pos {R theta : ℝ} {N i : ℕ} (hR : 0 < R) (ht : 0 < theta) + (hN : 0 < N) : 0 < left R theta N i := + hR.trans_le (left_lower (step_pos hR ht hN).le) + +theorem left_lt_right {R theta : ℝ} {N i : ℕ} (hR : 0 < R) (ht : 0 < theta) + (hN : 0 < N) : left R theta N i < right R theta N i := by + rw [right_eq_left_add]; linarith [step_pos hR ht hN] + +theorem width_pos {R theta : ℝ} {N i : ℕ} (hR : 0 < R) (ht : 0 < theta) + (hN : 0 < N) : 0 < width R theta N i := + div_pos (step_pos hR ht hN) (left_pos hR ht hN) + +theorem local_endpoint {R theta : ℝ} {N i : ℕ} (hR : 0 < R) (ht : 0 < theta) + (hN : 0 < N) : (1 + width R theta N i) * left R theta N i = right R theta N i := by + have hl := ne_of_gt (left_pos (i := i) hR ht hN) + rw [width, add_mul, one_mul, div_mul_cancel₀ _ hl, right_eq_left_add] + +theorem endpoints_ordered {R theta : ℝ} {N i j : ℕ} (hR : 0 < R) (ht : 0 < theta) + (hN : 0 < N) (hij : i < j) : right R theta N i ≤ left R theta N j := by + have hij' : ((i + 1 : ℕ) : ℝ) ≤ j := by exact_mod_cast hij + unfold right left + exact add_le_add_right (mul_le_mul_of_nonneg_right hij' (step_pos hR ht hN).le) R + +theorem exists_unique_index {R theta x : ℝ} {N : ℕ} (hR : 0 < R) + (ht : 0 < theta) (hN : 0 < N) (hx : R < x) (hx' : x ≤ (1 + theta) * R) : + ∃! i : Fin N, left R theta N i < x ∧ x ≤ right R theta N i := by + let u := (x - R) / step R theta N + have hs := step_pos hR ht hN + have hu : 0 < u := div_pos (sub_pos.mpr hx) hs + have hceil : 1 ≤ ⌈u⌉₊ := Nat.one_le_ceil_iff.mpr hu + have huN : u ≤ N := by + apply (div_le_iff₀ hs).mpr + rw [total_step hN] + nlinarith only [hx'] + have hkN : ⌈u⌉₊ ≤ N := Nat.ceil_le.mpr huN + let i : Fin N := ⟨⌈u⌉₊ - 1, by omega⟩ + have hki : (i : ℕ) + 1 = ⌈u⌉₊ := by dsimp [i]; omega + have hceil0 : ⌈u⌉₊ ≠ 0 := by omega + have hlo := ((Nat.ceil_eq_iff hceil0).mp rfl).1 + have hhi := Nat.le_ceil u + have himem : left R theta N i < x ∧ x ≤ right R theta N i := by + constructor + · have h := (lt_div_iff₀ hs).mp hlo + change R + (↑(⌈u⌉₊ - 1) : ℝ) * step R theta N < x + linarith only [h] + · have h := (div_le_iff₀ hs).mp hhi + dsimp [right] + rw [hki] + linarith only [h] + refine ⟨i, himem, ?_⟩ + intro j hj + apply Fin.ext + by_contra hne + rcases lt_or_gt_of_ne hne with hjlt | hilt + · have h := endpoints_ordered hR ht hN hjlt + linarith only [h, himem.1, hj.2] + · have h := endpoints_ordered hR ht hN hilt + linarith only [h, himem.2, hj.1] + +end ErdosTagSubbins + +end + +section + +namespace ErdosTagSubbins + +theorem width_le_theta_div {R theta : ℝ} {N i : ℕ} (hR : 0 < R) + (ht : 0 < theta) (hN : 0 < N) : width R theta N i ≤ theta / N := by + have hl := left_lower (i := i) (step_pos hR ht hN).le + have hs := step_pos hR ht hN + calc + width R theta N i ≤ step R theta N / R := div_le_div_of_nonneg_left hs.le hR hl + _ = theta / N := by unfold step; field_simp + +theorem width_upper {R theta w Cs : ℝ} {i : ℕ} (hR : 0 < R) + (ht : 0 < theta) (ht1 : theta ≤ 1) (hw : 1 < w) (hCs : 0 ≤ Cs) : + width R theta (count w Cs) i ≤ w ^ (-2 * Cs - 10) := by + have hb := count_bounds hw hCs + have hN : 0 < count w Cs := hb.1 + have hq : 0 < w ^ (2 * Cs + 10) := Real.rpow_pos_of_pos (by linarith) _ + calc + _ ≤ theta / (count w Cs : ℝ) := width_le_theta_div hR ht hN + _ ≤ 1 / (count w Cs : ℝ) := div_le_div_of_nonneg_right ht1 (by positivity) + _ ≤ 1 / w ^ (2 * Cs + 10) := div_le_div_of_nonneg_left (by norm_num) hq hb.2.1 + _ = w ^ (-2 * Cs - 10) := by + rw [show -2 * Cs - 10 = -(2 * Cs + 10) by ring, Real.rpow_neg (by linarith : 0 ≤ w)] + exact one_div _ + +theorem width_lower {R theta w Cs xi : ℝ} {i : ℕ} (hR : 0 < R) + (hxi : 0 < xi) (htxi : xi / 4 ≤ theta) (ht1 : theta ≤ 1) + (hw : 1 < w) (hCs : 0 ≤ Cs) (hi : i < count w Cs) : + xi / (16 * w ^ (2 * Cs + 10)) ≤ width R theta (count w Cs) i := by + have ht : 0 < theta := (div_pos hxi (by norm_num)).trans_le htxi + have hb := count_bounds hw hCs + have hN : 0 < count w Cs := hb.1 + have hNr : (0 : ℝ) < count w Cs := by exact_mod_cast hN + have hq : 0 < w ^ (2 * Cs + 10) := Real.rpow_pos_of_pos (by linarith) _ + have hl := left_pos (i := i) hR ht hN + have hlu : left R theta (count w Cs) i ≤ 2 * R := by + have h := (left_lt_right (i := i) hR ht hN).le.trans (right_upper hR ht hi) + nlinarith only [h, mul_le_mul_of_nonneg_right ht1 hR.le] + calc + xi / (16 * w ^ (2 * Cs + 10)) ≤ theta / (4 * w ^ (2 * Cs + 10)) := by + apply (div_le_div_iff₀ (by positivity) (by positivity)).mpr + have h := mul_le_mul_of_nonneg_right htxi (show 0 ≤ 16 * w ^ (2 * Cs + 10) by positivity) + nlinarith only [h] + _ ≤ theta / (2 * (count w Cs : ℝ)) := by + apply div_le_div_of_nonneg_left ht.le (by positivity) + linarith only [hb.2.2] + _ = step R theta (count w Cs) / (2 * R) := by unfold step; field_simp + _ ≤ width R theta (count w Cs) i := div_le_div_of_nonneg_left + (step_pos hR ht hN).le hl hlu + +theorem local_common_interval_geometry {R theta w Cs : ℝ} {i : ℕ} + (hR : 0 < R) (ht : 0 < theta) (ht1 : theta ≤ 1) (hw : 1 < w) + (hCs : 0 ≤ Cs) (hi : i < count w Cs) : + 0 < left R theta (count w Cs) i ∧ + left R theta (count w Cs) i < right R theta (count w Cs) i ∧ + right R theta (count w Cs) i ≤ + (1 + w ^ (-2 * Cs - 10)) * left R theta (count w Cs) i ∧ + right R theta (count w Cs) i ≤ (1 + theta) * R := by + have hN : 0 < count w Cs := (count_bounds hw hCs).1 + have hl := left_pos (i := i) hR ht hN + refine ⟨hl, left_lt_right hR ht hN, ?_, right_upper hR ht hi⟩ + rw [← local_endpoint hR ht hN] + exact mul_le_mul_of_nonneg_right (add_le_add_right (width_upper hR ht ht1 hw hCs) 1) hl.le + +end ErdosTagSubbins + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/TwoSidedThresholdArrival.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/TwoSidedThresholdArrival.lean new file mode 100644 index 0000000000000000000000000000000000000000..b08c127a37d199a5a4c40d547ac158920fdb5b83 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/TwoSidedThresholdArrival.lean @@ -0,0 +1,99 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.TwoSidedThresholdHazard + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.TwoSidedThresholdArrival +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures TransitionKernels ArrivalKernelGeometry RegeneratingInverseBands +open TwoSidedThresholdGeometry TwoSidedThresholdKernel TwoSidedThresholdHazard +open RepresentativeStopGeometry ActualCouplingUpdates + +noncomputable def reconstructedParent (v : ℝ) (y : CostState) : ℝ := gapValue v y+currentExponent v y + +theorem reconstructedParent_measurable (v : ℝ) : Measurable (reconstructedParent v) := + (gapValue_measurable v).add (currentExponent_measurable v) + +theorem reconstructedParent_update (v : ℝ) (z : CostState) (s : State) : + reconstructedParent v (s,z.2+cost (stateRatio s))=gapValue v z := by + rw [reconstructedParent,gapValue_update,currentExponent_update] + exact gap_exponent_conservation (valid_pos (stateRatio_valid s)) + +theorem reconstructed_geometry (v : ℝ) (y : CostState) : + nextExponent (reconstructedParent v y) (stateRatio y.1)=currentExponent v y ∧ + nextGap (reconstructedParent v y) (stateRatio y.1)=gapValue v y := by + have ht := valid_pos (stateRatio_valid y.1) + constructor + · unfold nextExponent reconstructedParent currentExponent + field_simp [ht.ne',show stateRatio y.1+1 ≠ 0 by positivity] + · unfold nextGap reconstructedParent currentExponent + field_simp [ht.ne',show stateRatio y.1+1 ≠ 0 by positivity] + +noncomputable def thickArrival (v d e : ℝ) : Set CostState := + {y | stateSide y.1=.even ∧ 3 ≤ reconstructedParent v y ∧ + stateRatio y.1 ∈ thickStrip (reconstructedParent v y) (d/reconstructedParent v y+e)} + +theorem thickArrival_measurable (v d e : ℝ) : MeasurableSet (thickArrival v d e) := by + have hr := reconstructedParent_measurable v + have ht : Measurable (fun y : CostState => stateRatio y.1) := stateRatio_measurable.comp measurable_fst + have hs : Measurable (fun y : CostState => normalizedSlack (reconstructedParent v y) (stateRatio y.1)) := by + unfold normalizedSlack ErdosEvenThreshold.thresholdSlack nextGap nextExponent + exact (((hr.mul ht).div (ht.add_const 1)).sub + (((measurable_const.mul (hr.div (ht.add_const 1)))).max ((hr.div (ht.add_const 1)).add_const 2))).div hr + exact (measurable_fst (side_set_measurable .even)).inter + ((measurableSet_le measurable_const hr).inter + ((measurableSet_le measurable_const ht).inter ((measurableSet_le ht measurable_const).inter + (measurableSet_le hs.abs ((measurable_const.div hr).add_const e))))) + +theorem thickArrival_update (v d e : ℝ) (z : CostState) (s : State) : + (s,z.2+cost (stateRatio s)) ∈ thickArrival v d e ↔ stateSide s=.even ∧ + 3 ≤ gapValue v z ∧ stateRatio s ∈ thickStrip (gapValue v z) (d/gapValue v z+e) := by + change stateSide s=.even ∧ _ ↔ _ + rw [reconstructedParent_update] + +theorem thickHazard_eq_actual (v d e : ℝ) (z : CostState) : + thickHazard (gapValue v z) d e z.1=(costKernel z (thickArrival v d e)).toReal := by + rw [costKernel_apply z (thickArrival_measurable v d e)] + rcases z with ⟨s,T⟩ + cases s with + | inl s => + change 0=(evenBranch s {t | (t,T+cost (stateRatio t)) ∈ thickArrival v d e}).toReal + rw [evenBranch,Kernel.map_apply' _ measurable_inr _] + · have he : Sum.inr ⁻¹' {t : State | (t,T+cost (stateRatio t)) ∈ thickArrival v d e}=∅ := by + ext t + change (Sum.inr t,T+cost (stateRatio (Sum.inr t))) ∈ thickArrival v d e ↔ False + rw [thickArrival_update v d e ((Sum.inl s),T)] + simp [stateSide] + rw [he,measure_empty,ENNReal.toReal_zero] + · exact (measurable_id.prodMk + (measurable_const.add (cost_measurable.comp stateRatio_measurable))) (thickArrival_measurable v d e) + | inr s => + change _=(oddBranch s {t | (t,T+cost (stateRatio t)) ∈ thickArrival v d e}).toReal + rw [oddBranch,Kernel.map_apply' _ measurable_inl _] + · by_cases hR : 3 ≤ gapValue v ((Sum.inr s),T) + · have he : Sum.inl ⁻¹' {t : State | (t,T+cost (stateRatio t)) ∈ thickArrival v d e}= + (Subtype.val : EvenState → ℝ) ⁻¹' thickStrip (gapValue v ((Sum.inr s),T)) (d/gapValue v ((Sum.inr s),T)+e) := by + ext t + change (Sum.inl t,T+cost (stateRatio (Sum.inl t))) ∈ thickArrival v d e ↔ _ + rw [thickArrival_update v d e ((Sum.inr s),T)] + simp only [stateSide,stateRatio,Sum.elim_inl,hR,true_and,Set.mem_preimage] + rw [he,thickHazard,ite_eq_left hR] + · have he : Sum.inl ⁻¹' {t : State | (t,T+cost (stateRatio t)) ∈ thickArrival v d e}=∅ := by + ext t + change (Sum.inl t,T+cost (stateRatio (Sum.inl t))) ∈ thickArrival v d e ↔ False + rw [thickArrival_update v d e ((Sum.inr s),T)] + simp only [hR,false_and,and_false] + rw [he,measure_empty,ENNReal.toReal_zero,thickHazard,ite_eq_right hR] + · exact (measurable_id.prodMk + (measurable_const.add (cost_measurable.comp stateRatio_measurable))) (thickArrival_measurable v d e) +end NumberTheoryLean.TwoSidedThresholdArrival + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/WeightedIsolatedWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/WeightedIsolatedWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6ccc83bb7b4ea0e9f20d880d5bfc4e9fa48ff15 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/WeightedIsolatedWords.lean @@ -0,0 +1,81 @@ +import OAI.NumberTheory.Jacobsthal.Probability.SourceIsolatedProbability +import OAI.NumberTheory.Jacobsthal.Probability.UncappedCompactEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.WeightedIsolatedWords +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership ActualPrimeHigh +open SourceSelectedCompactOccupation CompactPrefixOccurrence NonisolatedWordOccurrence +open SourceIsolatedProbability UncappedCompactEvent ExponentialMesh +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem weighted_nonisolated_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) + (theta : ℝ) (htheta : 0 < theta) (htheta1 : theta ≤ 1/2) (eps : ℝ) (heps : 0 < eps) : + ∃ alpha B₀ w₀ : ℝ,0 < alpha ∧ alpha ≤ theta ∧ 0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ hw : 1 < w,∀ top : ℝ,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → ∀ ell : ℝ,∀ start : Node, + ∀ _hs : Valid start.side start.ratio,1 ≤ ell → ell ≤ B → Real.log B ≤ D*Real.log w → + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → Consistent start → start.cutoff=B → + w^start.cutoff=top → ∀ E : Set (List ℕ), + (∀ ps ∈ uncappedPrefixes w ell start,ps ∈ E → (terminal w start ps).gap ≤ R ∧ + noIsolatedWord hw htop hxi B alpha (4*theta) ps) → + B^2*(∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ eps := by + obtain ⟨cR,WC,hcR,hWC,hCompact⟩ := uncapped_compact_event R hR D hD + let eta := eps/(2*cR) + have heta : 0 < eta := by dsimp [eta]; positivity + obtain ⟨κ,alpha,BP,WP,_hκ,ha,hath,hBP,hWP,hP⟩ := source_nonisolated_probability D theta eta hD htheta htheta1 heta + obtain ⟨BC,hBC,hC⟩ := hCompact (3:ℝ) + refine ⟨alpha,max BC (max BP (max (Real.exp 2) (max (R/theta) (2/eps)))),max WC WP, + ha,hath,hBC.trans_le (le_max_left _ _),hWC.trans_le (le_max_left _ _),?_⟩ + intro B w hBB hw₀ hw top htop xi hxi hxi1 ell start hs hell hellB hcomp hi h199 h23 hc hcut hcap E hE + have hB : 0 < B := hBC.trans_le ((le_max_left _ _).trans hBB) + have hBC' : BC ≤ B := (le_max_left _ _).trans hBB + have hBP' : BP ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hBB + have hExpB : Real.exp 2 ≤ B := (le_trans (le_max_left _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hBB + have hlogB : 2 ≤ Real.log B := (Real.le_log_iff_exp_le hB).mpr hExpB + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hRB : R/theta ≤ B := (le_trans (le_max_left _ _) + (le_trans (le_max_right _ _) (le_trans (le_max_right _ _) (le_max_right _ _)))).trans hBB + have hRtheta : R ≤ theta*B := by have hh := (div_le_iff₀ htheta).mp hRB; nlinarith + have hHist : ∀ p : History w ell ((Real.log B)^2) start,p.primes ∈ E → p.node.gap ≤ theta*B ∧ + noIsolatedWord hw htop hxi B alpha (4*theta) p.primes := by + intro p hp + have hu : p.primes ∈ uncappedPrefixes w ell start := + (mem_uncappedPrefixes hw start p.primes).mpr + ((uncapped_iff_exists_ceiling w ell start p.primes).mpr ⟨(Real.log B)^2,hsS,p.admissible⟩) + exact ⟨(hE p.primes hu hp).1.trans hRtheta,(hE p.primes hu hp).2⟩ + have hProb := hP B w hBP' ((le_max_right _ _).trans hw₀) hw top htop xi hxi hxi1 ell start hs + hell hcomp hi h199 h23 hc hcut hcap E hHist + have hpr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hProb + rw [ENNReal.toReal_ofReal heta.le] at hpr + have hMass := hC B w hBC' ((le_max_left _ _).trans hw₀) ell start hs hell hellB hcomp + hi h199 h23 hc hcut (mesh κ w) E (fun ps hp hsel => (hE ps hp hsel).1) + have hMass' : (∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ + (cR/B^2)*eta+B^(-(3:ℝ)) := + hMass.trans (add_le_add (mul_le_mul_of_nonneg_left hpr (show 0 ≤ cR/B^2 by positivity)) le_rfl) + have hlarge : 2/eps ≤ B := (le_trans (le_max_right _ _) + (le_trans (le_max_right _ _) (le_trans (le_max_right _ _) (le_max_right _ _)))).trans hBB + have hinv : 1/B ≤ eps/2 := by + have hh := (div_le_iff₀ heps).mp hlarge + apply (div_le_iff₀ hB).mpr + nlinarith + have hcEta : cR*eta=eps/2 := by dsimp [eta]; field_simp [hcR.ne'] + have hpow : B^(-(3:ℝ))=(B^3)⁻¹ := by rw [Real.rpow_neg hB.le,Real.rpow_ofNat] + calc + _ ≤ B^2*((cR/B^2)*eta+B^(-(3:ℝ))) := mul_le_mul_of_nonneg_left hMass' (sq_nonneg B) + _ = cR*eta+1/B := by rw [hpow]; field_simp [hB.ne'] + _ ≤ eps := by rw [hcEta]; linarith +end NumberTheoryLean.WeightedIsolatedWords + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/WeightedRepeatedWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/WeightedRepeatedWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..47b9c5f7e932557945ee763098f42118b0df8e8b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/WeightedRepeatedWords.lean @@ -0,0 +1,101 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.RepeatedSelectedOccurrence +import OAI.NumberTheory.Jacobsthal.Estimates.SourceRepeatedRates +import OAI.NumberTheory.Jacobsthal.Probability.UncappedCompactEvent + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.WeightedRepeatedWords +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open scoped Topology ENNReal +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeBinMembership ActualPrimeHigh +open SourceSelectedCompactOccupation CompactPrefixOccurrence RepeatedSelectedOccurrence RepeatedWordEvents +open SourceRepeatedRates UncappedCompactEvent ExponentialMesh +open LogarithmicBinScale LogarithmicBinEndpoints LogarithmicBinLabels +open ErdosPrimeInputs.PrimePrefixMass + +attribute [local instance] Classical.propDecidable + +theorem weighted_repeated_word_mass (R : ℝ) (hR : 3 ≤ R) (D : ℝ) (hD : 0 < D) + (L : ℝ) (hL : 0 ≤ L) (eps : ℝ) (heps : 0 < eps) : + ∃ B₀ w₀ : ℝ,0 < B₀ ∧ 1 < w₀ ∧ + ∀ B w : ℝ,B₀ ≤ B → w₀ ≤ w → ∀ top : ℝ,∀ htop : w < top, + ∀ xi : ℝ,∀ hxi : 0 < xi,xi ≤ 1 → ∃ hw : 1 < w, + ∀ ell : ℝ,∀ start : Node,∀ _hs : Valid start.side start.ratio, + 1 ≤ ell → ell ≤ B → Real.log B ≤ D*Real.log w → + start.side=.even → 199/100 ≤ start.ratio → start.ratio ≤ 23/10 → Consistent start → start.cutoff=B → + w^start.cutoff=top → ∀ E : Set (List ℕ), + (∀ ps ∈ uncappedPrefixes w ell start,ps ∈ E → + (terminal w start ps).gap ≤ R ∧ (searchRepeatedWord hw htop hxi ps ∨ + compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L start ps)) → + B^2*(∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ eps := by + obtain ⟨cR,WC,hcR,hWC,hCompact⟩ := uncapped_compact_event R hR D hD + obtain ⟨κ,hκ,hProb⟩ := source_repeated_pair_probabilities + let eta := eps/(4*cR) + have heta : 0 < eta := by dsimp [eta]; positivity + obtain ⟨WP,hWP,hP⟩ := hProb κ hκ le_rfl D L eta hD hL heta + obtain ⟨BC,hBC,hCbound⟩ := hCompact (3:ℝ) + let w₀ := max WC (max WP (max normalizationThreshold (Real.exp (D^2)))) + refine ⟨max BC (max (Real.exp 2) (2/eps)),w₀,hBC.trans_le (le_max_left _ _), + hWC.trans_le (le_max_left _ _),?_⟩ + intro B w hBB hw₀ top htop xi hxi hxi1 + have hB : 0 < B := hBC.trans_le ((le_max_left _ _).trans hBB) + have hExpB : Real.exp 2 ≤ B := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hBB + have hlogB : 2 ≤ Real.log B := (Real.le_log_iff_exp_le hB).mpr hExpB + have hwC : WC ≤ w := (le_max_left _ _).trans hw₀ + have hwP : WP ≤ w := (le_trans (le_max_left _ _) (le_max_right _ _)).trans hw₀ + have hnorm : normalizationThreshold ≤ w := + (le_trans (le_max_left _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hw₀ + have hw : 1 < w := normalizationThreshold_gt_one.trans_le hnorm + refine ⟨hw,?_⟩ + intro ell start hs hell hellB hcomp hi h199 h23 hc hcut hcap E hE + have hExpW : Real.exp (D^2) ≤ w := + (le_trans (le_max_right _ _) (le_trans (le_max_right _ _) (le_max_right _ _))).trans hw₀ + have hlogw : D^2 ≤ Real.log w := (Real.le_log_iff_exp_le (zero_lt_one.trans hw)).mpr hExpW + have hscale := UniformBudgetRate.source_scale_bound hlogw hlogB hcomp + have hS0 : 0 ≤ (Real.log B)^2 := sq_nonneg _ + have hsS : start.ratio ≤ (Real.log B)^2 := by nlinarith + have hrnode := SourceNodeCoordinates.source_node_bounds hB start hi h199 h23 hc hcut + have hHist : ∀ p : History w ell ((Real.log B)^2) start,p.primes ∈ E → + searchRepeatedWord hw htop hxi p.primes ∨ compactAdjacentWord w (label (zero_lt_one.trans hw) htop hxi) L start p.primes := by + intro p hp + have hu : p.primes ∈ uncappedPrefixes w ell start := + (mem_uncappedPrefixes hw start p.primes).mpr + ((uncapped_iff_exists_ceiling w ell start p.primes).mpr ⟨(Real.log B)^2,hsS,p.admissible⟩) + exact (hE p.primes hu hp).2 + have hOcc := selected_repetition_probability hnorm hell hS0 hscale.1 hrnode.2.1 hs hsS + hw htop hxi hcap L (mesh κ w) (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) E hHist + obtain ⟨hw',hProbs⟩ := hP w hwP + have hp := hProbs top htop ell B start hs hell hB hlogB hcomp hrnode.2.1 h23 hc hrnode.2.2.2 hcap xi hxi hxi1 + have hProbability : fullSourceLaw w ell ((Real.log B)^2) start hs (mesh κ w) + (LowStateHorizon.sourceHorizon ((Real.log B)^2) B) {h | occurs E _ h} ≤ ENNReal.ofReal (2*eta) := by + have hh := hOcc.trans (add_le_add hp.1 hp.2) + rw [← ENNReal.ofReal_add heta.le heta.le] at hh + simpa only [two_mul] using hh + have hpr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hProbability + rw [ENNReal.toReal_ofReal (by positivity : 0 ≤ 2*eta)] at hpr + have hMass := hCbound B w ((le_max_left _ _).trans hBB) hwC ell start hs hell hellB hcomp + hi h199 h23 hc hcut (mesh κ w) E (fun ps hp hsel => (hE ps hp hsel).1) + have hMass' : (∑ ps ∈ (uncappedPrefixes w ell start).filter (· ∈ E),prefixWeight ps) ≤ + (cR/B^2)*(2*eta)+B^(-(3:ℝ)) := + hMass.trans (add_le_add (mul_le_mul_of_nonneg_left hpr (show 0 ≤ cR/B^2 by positivity)) le_rfl) + have hlarge : 2/eps ≤ B := (le_trans (le_max_right _ _) (le_max_right _ _)).trans hBB + have hinv : 1/B ≤ eps/2 := by + have hh := (div_le_iff₀ heps).mp hlarge + apply (div_le_iff₀ hB).mpr + nlinarith + have hcEta : cR*(2*eta)=eps/2 := by dsimp [eta]; field_simp [hcR.ne']; ring + have hpow : B^(-(3:ℝ))=(B^3)⁻¹ := by rw [Real.rpow_neg hB.le,Real.rpow_ofNat] + calc + _ ≤ B^2*((cR/B^2)*(2*eta)+B^(-(3:ℝ))) := mul_le_mul_of_nonneg_left hMass' (sq_nonneg B) + _ = cR*(2*eta)+1/B := by rw [hpow]; field_simp [hB.ne'] + _ ≤ eps := by rw [hcEta]; linarith +end NumberTheoryLean.WeightedRepeatedWords + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/WindowHitWords.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/WindowHitWords.lean new file mode 100644 index 0000000000000000000000000000000000000000..de37b25e67a682671feaa969c798c7f27973861f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/WindowHitWords.lean @@ -0,0 +1,105 @@ +import OAI.NumberTheory.Jacobsthal.Probability.OrdinaryMarkedWindow + +namespace OAI + +namespace Erdos970 + +section + +namespace Erdos970Dependency.MarkedVisits +open Filter Set MeasureTheory ProbabilityTheory +open scoped ProbabilityTheory ENNReal Classical +open NumberTheoryLean.PairedCostProcess NumberTheoryLean.PairedCostGrouping + +noncomputable def allowedCycleCosts (b : Bool) (v H : ℝ) : Set ℝ := + if b then (Icc v (v+H))ᶜ else univ + +lemma allowedCycleCosts_measurable (b : Bool) (v H : ℝ) : MeasurableSet (allowedCycleCosts b v H) := by + cases b <;> simp [allowedCycleCosts] + +noncomputable def hitWordEvent : (w : List Bool) → (v H : ℝ) → Set (CycleWordSignature (w++[true]).length) + | [], v, H => {s | s.1.1 ∈ Icc v (v+H)} + | b::w, v, H => {s | s.1.1 ∈ allowedCycleCosts b v H ∧ s.2 ∈ hitWordEvent w v H} + +lemma hitWordEvent_measurable (w : List Bool) : ∀ v H, MeasurableSet (hitWordEvent w v H) := by + induction w with + | nil => intro v H; exact measurableSet_Icc.preimage (measurable_fst.comp measurable_fst) + | cons b w ih => + intro v H + exact ((allowedCycleCosts_measurable b v H).preimage (measurable_fst.comp measurable_fst)).inter + ((ih v H).preimage measurable_snd) + +noncomputable def sourceHitWordMass (w : List Bool) (v H : ℝ) (z : OddCost) : ℝ≥0∞ := + sourceMarkedWordKernel (w++[true]) z (hitWordEvent w v H) + +lemma sourceHitWordMass_measurable (w : List Bool) (v H : ℝ) : Measurable (sourceHitWordMass w v H) := + (sourceMarkedWordKernel (w++[true])).measurable_coe (hitWordEvent_measurable w v H) + +lemma sourceHitWordMass_nil (v H : ℝ) (z : OddCost) : + sourceHitWordMass [] v H z=ordinaryWindowCapture v H z univ := by + have he := congrArg (fun μ : Measure ℝ => μ (Icc v (v+H))) (sourceLookahead_cost_law [] true z) + rw [Measure.map_apply (lookaheadInputCost_measurable [] true) measurableSet_Icc, + Measure.map_apply measurable_snd measurableSet_Icc] at he + change sourceHitWordMass [] v H z = _ at he + have hc : ordinaryWindowCapture v H z univ = + ((branchWordKernel [] z).withDensity (fun y => cycleBranchKernel true y univ)) + (Prod.snd ⁻¹' Icc v (v+H)) := by + rw [ordinaryWindowCapture,Kernel.restrict_apply' _ _ _ MeasurableSet.univ,univ_inter, + markInputWeightKernel,Kernel.withDensity_apply _ (f := fun _ z : OddCost => nextMarkWeight z) + (nextMarkWeight_measurable.comp measurable_snd),Kernel.id_apply] + rfl + exact he.trans hc.symm + +lemma sourceHitWordMass_indicator (w : List Bool) (v H : ℝ) (z : OddCost) : + sourceHitWordMass w v H z = + ∫⁻ s, (hitWordEvent w v H).indicator (fun _ => (1:ℝ≥0∞)) s ∂sourceMarkedWordKernel (w++[true]) z := by + rw [lintegral_indicator (hitWordEvent_measurable w v H)] + simp [sourceHitWordMass] + +lemma sourceHitWordMass_cons (b : Bool) (w : List Bool) (v H : ℝ) (z : OddCost) : + sourceHitWordMass (b::w) v H z = + if z.2 ∈ allowedCycleCosts b v H then ∫⁻ y, sourceHitWordMass w v H y ∂cycleBranchKernel b z else 0 := by + rw [sourceHitWordMass_indicator] + change (∫⁻ s : CycleWordSignature (b::(w++[true])).length, + (hitWordEvent (b::w) v H).indicator (fun _ => (1:ℝ≥0∞)) s ∂sourceMarkedWordKernel (b::(w++[true])) z) = _ + rw [sourceMarkedWord_cons_lintegral b (w++[true]) z + (F := (hitWordEvent (b::w) v H).indicator (fun _ => (1:ℝ≥0∞))) + (measurable_const.indicator (hitWordEvent_measurable (b::w) v H))] + by_cases hz : z.2 ∈ allowedCycleCosts b v H + · rw [ite_eq_left hz] + have hi (y : SourceCycleWitness) (s : CycleWordSignature (w++[true]).length) : + (hitWordEvent (b::w) v H).indicator (fun _ => (1:ℝ≥0∞)) (sourceCycleInputSignature z y,s) = + (hitWordEvent w v H).indicator (fun _ => (1:ℝ≥0∞)) s := by + simp only [Set.indicator_apply,hitWordEvent,mem_ofPred_eq,sourceCycleInputSignature,hz,true_and] + simp_rw [hi,← sourceHitWordMass_indicator] + rw [← lintegral_map (g := fun y : SourceCycleWitness => y.2.2) (sourceHitWordMass_measurable w v H) + (measurable_snd.comp measurable_snd),sourceBranchWitness_endpoint] + · rw [ite_eq_right hz] + have hi (y : SourceCycleWitness) (s : CycleWordSignature (w++[true]).length) : + (hitWordEvent (b::w) v H).indicator (fun _ => (1:ℝ≥0∞)) (sourceCycleInputSignature z y,s) = 0 := by + simp only [Set.indicator_apply,hitWordEvent,mem_ofPred_eq,sourceCycleInputSignature,hz,false_and,ite_false] + simp_rw [hi,lintegral_zero] + +noncomputable def rawHitWordKernel (a : ℕ) (w : List Bool) (v H : ℝ) : + Kernel (RawHistory a) (RawCycleWordTrace a (w++[true]).length) := + (rawMarkedWordKernel a (w++[true])).restrict + ((hitWordEvent_measurable w v H).preimage (rawCycleWordSignature_measurable _ a)) + +instance rawHitWordKernel_isFiniteKernel (a : ℕ) (w : List Bool) (v H : ℝ) : IsFiniteKernel (rawHitWordKernel a w v H) := by + unfold rawHitWordKernel + infer_instance + +theorem rawHitWord_mass (a : ℕ) (w : List Bool) (v H : ℝ) (h : RawHistory a) (z : OddCost) + (hz : rawLast a h=embedOdd z) : rawHitWordKernel a w v H h univ=sourceHitWordMass w v H z := by + rw [rawHitWordKernel,Kernel.restrict_apply' _ _ _ MeasurableSet.univ,univ_inter, + ← Measure.map_apply (rawCycleWordSignature_measurable _ a) (hitWordEvent_measurable w v H), + rawMarkedWord_signature (w++[true]) a h z hz] + rfl + +end Erdos970Dependency.MarkedVisits + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/WordIntervalGeometry.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/WordIntervalGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..c830ab60f11fb9d1c1f0826d30a1e5779b76cca3 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/WordIntervalGeometry.lean @@ -0,0 +1,47 @@ +import OAI.NumberTheory.Jacobsthal.Primes.SourcePrimeProductData + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.WordIntervalGeometry +open FinitePathGeometry PrimeHistories PrimeProductLogCoordinates RepresentativeAdmission +open ErdosPrimeInputs.HarmonicPrimeMeasure + +noncomputable def wordIntervalExponent (w : ℝ) (Y : ℕ) (ps : List ℕ) : ℝ := + Real.log ((Y:ℝ)/(ps.prod:ℝ))/Real.log w + +theorem word_interval_gap {w a : ℝ} (Y : ℕ) (hY : 0 < Y) (z : Node) + (hroot : z.gap=Real.log (Y:ℝ)/Real.log w-a+2) (ps : List ℕ) (hp : ∀ p∈ps,0 < p) : + wordIntervalExponent w Y ps=(terminal w z ps).gap+a-2 := by + have hh := terminal_gap_log_quotient Y hY z hroot ps hp + unfold wordIntervalExponent + linarith + +theorem gap_prefix_mono (w : ℝ) (z : Node) (pre tail : List ℕ) + (hp : ∀ p∈tail,0 ≤ primeExponent w p) : + (terminal w z (pre++tail)).gap ≤ (terminal w z pre).gap := by + rw [terminal_append,terminal_gap_sum] + have hh : 0 ≤ (tail.map (primeExponent w)).sum := List.sum_nonneg (fun x hx => by + obtain ⟨p,hp',rfl⟩ := List.mem_map.mp hx + exact hp p hp') + linarith + +theorem interval_exponent_step (w : ℝ) (Y : ℕ) (hY : 0 < Y) (pre : List ℕ) (u : ℕ) + (hp : 0 < pre.prod) (hu : 0 < u) : + wordIntervalExponent w Y (pre++[u])=wordIntervalExponent w Y pre-primeExponent w u := by + have hYr : (Y:ℝ) ≠ 0 := by exact_mod_cast hY.ne' + have hpr : (pre.prod:ℝ) ≠ 0 := by exact_mod_cast hp.ne' + have hur : (u:ℝ) ≠ 0 := by exact_mod_cast hu.ne' + unfold wordIntervalExponent primeExponent + rw [List.prod_append,List.prod_singleton,Nat.cast_mul,Real.log_div hYr (mul_ne_zero hpr hur), + Real.log_div hYr hpr,Real.log_mul hpr hur] + ring +end NumberTheoryLean.WordIntervalGeometry + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Paths/WrongOwnerBoxMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Paths/WrongOwnerBoxMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..6db642b305d41f238d77cc09638f3ba34763fb7b --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Paths/WrongOwnerBoxMass.lean @@ -0,0 +1,246 @@ +import OAI.NumberTheory.Jacobsthal.Primes.PrimeChoiceCoordinateMass + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.WrongOwnerBinMass +open PrimeBinAlignmentMass ActualBinOwners OwnerUniquenessFinite OwnerSearchBounds +open ErdosInversePrimeBin ErdosInverseAlignment + +attribute [local instance] Classical.propDecidable + +noncomputable def wrongOwnerPrimes (Y w Cs eta R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) : Finset ℕ := + (primeBin R xi).filter (fun p => aligns a q p ∧ ∃ r, + owner Y w Cs eta R xi a=some r ∧ r ≠ q ∧ aligns a r p) + +theorem wrongOwnerPrimes_none (Y w Cs eta R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) + (ho : owner Y w Cs eta R xi a=none) : wrongOwnerPrimes Y w Cs eta R xi a q=∅ := by + ext p + simp [wrongOwnerPrimes,ho] + +theorem wrongOwnerPrimes_self (Y w Cs eta R xi : ℝ) (a : ℕ → ℤ) (q : ℚ) + (ho : owner Y w Cs eta R xi a=some q) : wrongOwnerPrimes Y w Cs eta R xi a q=∅ := by + ext p + simp [wrongOwnerPrimes,ho] + +theorem wrongOwnerPrimes_eq_common (Y w Cs eta R xi : ℝ) (a : ℕ → ℤ) (q r : ℚ) + (ho : owner Y w Cs eta R xi a=some r) (hne : r ≠ q) : + wrongOwnerPrimes Y w Cs eta R xi a q=commonAligners (primeBin R xi) a q r := by + ext p + simp [wrongOwnerPrimes,ho,hne,commonAligners] + +theorem wrong_owner_mass_bound {Y w Cs eta R xi : ℝ} (hY : 0 ≤ Y) (hw : 1 < w) + (hCs : 0 ≤ Cs) (hwlarge : 2*Cs+3 ≤ w) (hYup : Y ≤ Real.exp (w^2)) + (hR : 1 < R) (hxi : 0 ≤ xi) (a : ℕ → ℤ) (q : ℚ) (hq : eligible Y w Cs q) : + mass (wrongOwnerPrimes Y w Cs eta R xi a q) ≤ 2*w^2/(R*Real.log R) := by + have hRp0 : 0 < R := zero_lt_one.trans hR + have hlog0 : 0 < Real.log R := Real.log_pos hR + have hnon : 0 ≤ 2*w^2/(R*Real.log R) := by positivity + cases ho : owner Y w Cs eta R xi a with + | none => simpa only [wrongOwnerPrimes_none Y w Cs eta R xi a q ho,mass,Finset.sum_empty] using hnon + | some r => + by_cases he : r=q + · subst r + simpa only [wrongOwnerPrimes_self Y w Cs eta R xi a q ho,mass,Finset.sum_empty] using hnon + · rw [wrongOwnerPrimes_eq_common Y w Cs eta R xi a q r ho he] + have hr := (actual_owner_witness hY hw a ho).1 + have hd := (eligible_determinant_height hY hw q r hq hr).trans + (height_exp_square hY hw.le hCs hwlarge hYup) + have hRp : 0 < R := zero_lt_one.trans hR + have hlog : 0 < Real.log R := Real.log_pos hR + have hheight : ((determinant q r).natAbs:ℝ) ≤ R^(2*w^2/Real.log R) := by + have hh : R^(2*w^2/Real.log R)=Real.exp (2*w^2) := by + rw [Real.rpow_def_of_pos hRp] + congr 1 + field_simp [hlog.ne'] + rwa [hh] + have hp : ∀ p ∈ primeBin R xi,p.Prime := fun p hp => ((mem_primeBin hRp.le hxi p).mp hp).1 + have hlarge : ∀ p ∈ primeBin R xi,R^(1:ℝ) ≤ (p:ℝ) := by + intro p hp + rw [Real.rpow_one] + exact ((mem_primeBin hRp.le hxi p).mp hp).2.1.le + have hc := common_primes_power_height_bound (primeBin R xi) a (Ne.symm he) hp hR + (by norm_num : (0:ℝ)<1) hlarge hheight + rw [div_one] at hc + calc + _ ≤ ((commonAligners (primeBin R xi) a q r).card:ℝ)/R := + (subset_mass_bounds hRp hxi _ (Finset.filter_subset _ _)).2 + _ ≤ (2*w^2/Real.log R)/R := div_le_div_of_nonneg_right hc hRp.le + _ = _ := by rw [div_div,mul_comm (Real.log R) R] +end NumberTheoryLean.WrongOwnerBinMass + + + +namespace NumberTheoryLean.WrongOwnerFraction +open _root_.Filter PrimeBinAlignmentMass WrongOwnerBinMass ActualBinOwners +open ErdosInversePrimeBin ErdosInverseAlignment + + +theorem uniform_bin_mass_lower {theta : ℝ} (htheta : 0 < theta) : + ∀ᶠ R : ℝ in atTop,2 ≤ R ∧ ∀ xi : ℝ,theta ≤ xi → xi ≤ 1 → + theta/(8*Real.log R) ≤ mass (primeBin R xi) := by + filter_upwards [uniform_prime_bin_count htheta] with R hR + refine ⟨hR.1,?_⟩ + intro xi hxi hxi1 + have hRp : 0 < R := by linarith [hR.1] + have hlog : 0 < Real.log R := Real.log_pos (by linarith [hR.1]) + have hxi0 : 0 ≤ xi := htheta.le.trans hxi + have hden : 0 < (1+xi)*R := by positivity + have hc : theta/8 ≤ xi/(4*(1+xi)) := by + apply (le_div_iff₀ (by positivity : 0 < 4*(1+xi))).mpr + have hh := mul_le_mul_of_nonneg_left hxi1 htheta.le + nlinarith + have hm := (div_le_div_of_nonneg_right (hR.2 xi hxi hxi1).1 hden.le).trans + (subset_mass_bounds hRp hxi0 (primeBin R xi) (fun _ h => h)).1 + calc + _ = (theta/8)/Real.log R := by rw [div_div] + _ ≤ (xi/(4*(1+xi)))/Real.log R := div_le_div_of_nonneg_right hc hlog.le + _ = (xi*R/(4*Real.log R))/((1+xi)*R) := by + field_simp [hRp.ne',hlog.ne',(by positivity : (1+xi:ℝ) ≠ 0)] + _ ≤ _ := hm + +theorem uniform_wrong_owner_fraction {theta : ℝ} (htheta : 0 < theta) : + ∀ᶠ R : ℝ in atTop,2 ≤ R ∧ ∀ Y w Cs eta xi : ℝ, + 0 ≤ Y → 1 < w → 0 ≤ Cs → 2*Cs+3 ≤ w → Y ≤ Real.exp (w^2) → + theta ≤ xi → xi ≤ 1 → ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + mass (wrongOwnerPrimes Y w Cs eta R xi a q) ≤ + (16*w^2/(theta*R))*mass (primeBin R xi) := by + filter_upwards [uniform_bin_mass_lower htheta] with R hR + refine ⟨hR.1,?_⟩ + intro Y w Cs eta xi hY hw hCs hwlarge hYup hxi hxi1 a q hq + have hRp : 0 < R := by linarith [hR.1] + have hR1 : 1 < R := by linarith [hR.1] + have hlog : 0 < Real.log R := Real.log_pos hR1 + have habs := wrong_owner_mass_bound (eta := eta) hY hw hCs hwlarge hYup hR1 (htheta.le.trans hxi) a q hq + have hm := mul_le_mul_of_nonneg_left (hR.2 xi hxi hxi1) + (show 0 ≤ 16*w^2/(theta*R) by positivity) + have he : (16*w^2/(theta*R))*(theta/(8*Real.log R))=2*w^2/(R*Real.log R) := by + field_simp [hRp.ne',hlog.ne',htheta.ne'] + norm_num + rw [he] at hm + exact habs.trans hm +end NumberTheoryLean.WrongOwnerFraction + + + +namespace NumberTheoryLean.WrongOwnerSearchTail +open _root_.Filter PrimeBinAlignmentMass WrongOwnerBinMass WrongOwnerFraction ActualBinOwners OwnerSearchBounds +open ErdosInversePrimeBin + + +theorem search_fraction_factor {theta A : ℝ} (_htheta : 0 < theta) (_hA : 0 < A) : + ∀ᶠ w : ℝ in atTop,∀ R : ℝ,w^(w^((1/4:ℝ))) ≤ R → + 16*w^2/(theta*R) ≤ w^(-A) := by + have hquarter : ∀ᶠ w : ℝ in atTop,A+3 ≤ w^((1/4:ℝ)) := + (tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/4)).eventually_ge_atTop (A+3) + filter_upwards [eventually_ge_atTop (2:ℝ),eventually_ge_atTop (16/theta),hquarter] with w hw2 hwC hwPow + intro R hR + have hw1 : 1 ≤ w := by linarith + have hw0 : 0 < w := by linarith + have hRa : w^(A+3) ≤ R := (Real.rpow_le_rpow_of_exponent_le hw1 hwPow).trans hR + have hden : 0 < w^(A+3) := Real.rpow_pos_of_pos hw0 _ + have hRp : 0 < R := hden.trans_le hRa + have hnum : (16/theta)*w^2 ≤ w^3 := by + have hh := mul_le_mul_of_nonneg_right hwC (sq_nonneg w) + nlinarith + calc + _ = ((16/theta)*w^2)/R := by simp only [div_eq_mul_inv,mul_inv_rev]; ring + _ ≤ w^3/R := div_le_div_of_nonneg_right hnum hRp.le + _ ≤ w^3/w^(A+3) := div_le_div_of_nonneg_left (pow_nonneg hw0.le 3) hden hRa + _ = w^(-A) := by + rw [show w^3=w^(3:ℝ) by norm_num,← Real.rpow_sub hw0] + congr 1 + ring + +theorem actual_wrong_search_mass {Cs theta A : ℝ} (hCs : 0 ≤ Cs) + (htheta : 0 < theta) (hA : 0 < A) : + ∀ᶠ w : ℝ in atTop,∀ Y R xi eta : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → + w^(w^((1/4:ℝ))) ≤ R → theta ≤ xi → xi ≤ 1 → + ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + mass (wrongOwnerPrimes Y w Cs eta R xi a q) ≤ w^(-A)*mass (primeBin R xi) := by + obtain ⟨R₀,hR₀⟩ := eventually_atTop.mp (uniform_wrong_owner_fraction htheta) + have hquarter : ∀ᶠ w : ℝ in atTop,4 ≤ w^((1/4:ℝ)) := + (tendsto_rpow_atTop (by norm_num : (0:ℝ)<1/4)).eventually_ge_atTop 4 + filter_upwards [search_fraction_factor htheta hA,eventually_ge_atTop (2:ℝ),eventually_ge_atTop R₀, + eventually_ge_atTop (2*Cs+3),hquarter] with w hfactor hw2 hwR hwCs hwPow + intro Y R xi eta hY hYup hsearch hxi hxi1 a q hq + have hw1 : 1 ≤ w := by linarith + have hRlarge : R₀ ≤ R := hwR.trans ((le_fourth hw1).trans (search_ge_fourth hw1 hwPow hsearch)) + have hh := (hR₀ R hRlarge).2 Y w Cs eta xi hY (by linarith) hCs hwCs hYup hxi hxi1 a q hq + exact hh.trans (mul_le_mul_of_nonneg_right (hfactor R hsearch) (mass_nonnegative _)) +end NumberTheoryLean.WrongOwnerSearchTail + + + +namespace NumberTheoryLean.WrongOwnerBoxMass +open _root_.Filter PrimeChoiceBoxMass PrimeChoiceCoordinateMass PrimeChoiceAlignmentDecay +open PrimeBinAlignmentMass WrongOwnerBinMass WrongOwnerSearchTail ActualBinOwners +open ErdosInversePrimeBin + +attribute [local instance] Classical.propDecidable + +theorem wrong_owner_box_mass {Cs theta A : ℝ} (hCs : 0 ≤ Cs) (htheta : 0 < theta) (hA : 0 < A) : + ∀ᶠ w : ℝ in atTop,∀ Y xi eta : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → theta ≤ xi → xi ≤ 1 → + ∀ (m : ℕ) (R : Fin m → ℝ) (S : Finset (Fin m)), + (∀ i ∈ S,w^(w^((1/4:ℝ))) ≤ R i) → ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + (∑ f ∈ someCoordinateEvent (fun i => primeBin (R i) xi) S + (fun i => wrongOwnerPrimes Y w Cs eta (R i) xi a q),weight f) ≤ + (S.card:ℝ)*w^(-A)*boxMass (fun i => primeBin (R i) xi) := by + filter_upwards [actual_wrong_search_mass hCs htheta hA] with w hw + intro Y xi eta hY hYup hxi hxi1 m R S hsearch a q hq + apply some_coordinate_mass_bound + · intro i _hi + exact Finset.filter_subset _ _ + · intro i hi + exact hw Y (R i) xi eta hY hYup (hsearch i hi) hxi hxi1 a q hq + +theorem logarithmic_positions_le_w (Clen : ℝ) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,2*Clen*Real.log w ≤ w := by + have hD : 0 < 2*Clen+1 := by linarith + have hh := (isLittleO_log_rpow_atTop (r := 1) (by norm_num)).bound + (show 0 < 1/(2*Clen+1) by positivity) + filter_upwards [hh,eventually_gt_atTop (1:ℝ)] with w hsmall hw + have hw0 : 0 < w := zero_lt_one.trans hw + have hlog0 : 0 < Real.log w := Real.log_pos hw + have hs : Real.log w ≤ w/(2*Clen+1) := by + simpa only [Real.rpow_one,Real.norm_eq_abs,abs_of_pos hlog0,abs_of_pos hw0, + one_div,mul_comm,div_eq_mul_inv,one_mul] using hsmall + have hm := (le_div_iff₀ hD).mp hs + nlinarith + +theorem length_bounded_wrong_box_mass {Cs theta A Clen : ℝ} (hCs : 0 ≤ Cs) + (htheta : 0 < theta) (hA : 0 < A) (hC : 0 ≤ Clen) : + ∀ᶠ w : ℝ in atTop,∀ Y xi eta B : ℝ,0 ≤ Y → Y ≤ Real.exp (w^2) → theta ≤ xi → xi ≤ 1 → + Real.log B ≤ 2*Real.log w → ∀ (m : ℕ),(m:ℝ) ≤ Clen*Real.log B → + ∀ (R : Fin m → ℝ) (S : Finset (Fin m)), + (∀ i ∈ S,w^(w^((1/4:ℝ))) ≤ R i) → ∀ (a : ℕ → ℤ) (q : ℚ),eligible Y w Cs q → + (∑ f ∈ someCoordinateEvent (fun i => primeBin (R i) xi) S + (fun i => wrongOwnerPrimes Y w Cs eta (R i) xi a q),weight f) ≤ + w^(-A)*boxMass (fun i => primeBin (R i) xi) := by + filter_upwards [wrong_owner_box_mass hCs htheta (show 0 < A+1 by linarith), + logarithmic_positions_le_w Clen hC,eventually_gt_atTop (1:ℝ)] with w hw hlength hw1 + intro Y xi eta B hY hYup hxi hxi1 hB m hm R S hsearch a q hq + have hraw := hw Y xi eta hY hYup hxi hxi1 m R S hsearch a q hq + have hcard : (S.card:ℝ) ≤ w := by + have hsm : S.card ≤ m := by simpa using Finset.card_le_univ S + have hsmr : (S.card:ℝ) ≤ (m:ℝ) := by exact_mod_cast hsm + have hmul := mul_le_mul_of_nonneg_left hB hC + nlinarith + have hw0 : 0 < w := zero_lt_one.trans hw1 + have hmul := mul_le_mul_of_nonneg_right hcard (Real.rpow_nonneg hw0.le (-(A+1))) + have he : w*w^(-(A+1))=w^(-A) := by + calc + _ = w^(1:ℝ)*w^(-(A+1)) := by rw [Real.rpow_one] + _ = w^((1:ℝ)+(-(A+1))) := (Real.rpow_add hw0 _ _).symm + _ = _ := by congr 1; ring + rw [he] at hmul + exact hraw.trans (mul_le_mul_of_nonneg_right hmul (boxMass_nonnegative _)) +end NumberTheoryLean.WrongOwnerBoxMass + + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/ActualPrimeQuadrature.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/ActualPrimeQuadrature.lean new file mode 100644 index 0000000000000000000000000000000000000000..566b119c4a930619e4fc35409d6edf5351bda737 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/ActualPrimeQuadrature.lean @@ -0,0 +1,229 @@ +import Mathlib +import OAI.NumberTheory.Jacobsthal.Analysis.HarmonicReferenceMeasure +import OAI.NumberTheory.Jacobsthal.Analysis.LipschitzMeasureQuadrature + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.HarmonicPrimeAtomicMeasure + +attribute [local instance] Classical.propDecidable +open _root_.MeasureTheory _root_.Set _root_.Finset +open ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimeEndpoints + +noncomputable def primeAtom (w : ℝ) (p : ℕ) : Measure ℝ := + ENNReal.ofReal ((p:ℝ)⁻¹) • Measure.dirac (primeExponent w p) + +noncomputable def primeMeasure (w V : ℝ) : Measure ℝ := + ∑ p ∈ Nat.primesLE ⌊w^V⌋₊,primeAtom w p + +instance primeAtom_finite (w : ℝ) (p : ℕ) : IsFiniteMeasure (primeAtom w p) := by + constructor + simp [primeAtom,Measure.smul_apply] + +instance primeMeasure_finite (w V : ℝ) : IsFiniteMeasure (primeMeasure w V) := by + unfold primeMeasure + infer_instance + +theorem integrable_primeAtom (w : ℝ) (p : ℕ) (F : ℝ → ℝ) : Integrable F (primeAtom w p) := by + unfold primeAtom + exact (integrable_dirac (by finiteness)).smul_measure ENNReal.ofReal_ne_top + +theorem primeMeasure_integral (w V : ℝ) (F : ℝ → ℝ) : + (∫ x,F x ∂primeMeasure w V)=∑ p ∈ Nat.primesLE ⌊w^V⌋₊,(p:ℝ)⁻¹*F (primeExponent w p) := by + unfold primeMeasure + rw [integral_finsetSum_measure (fun p _ => integrable_primeAtom w p F)] + apply Finset.sum_congr rfl + intro p _hp + rw [primeAtom,integral_smul_measure,integral_dirac,ENNReal.toReal_ofReal (by positivity)] + rfl + +theorem primeMeasure_setIntegral (w V : ℝ) (F : ℝ → ℝ) {J : Set ℝ} (hJ : MeasurableSet J) : + (∫ x in J,F x ∂primeMeasure w V)= + ∑ p ∈ Nat.primesLE ⌊w^V⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹*F (primeExponent w p) else 0 := by + rw [← integral_indicator hJ,primeMeasure_integral] + apply Finset.sum_congr rfl + intro p _hp + by_cases hp : primeExponent w p ∈ J <;> simp [hp] + +theorem primeMeasure_real (w V : ℝ) {J : Set ℝ} (hJ : MeasurableSet J) : + (primeMeasure w V).real J= + ∑ p ∈ Nat.primesLE ⌊w^V⌋₊,if primeExponent w p ∈ J then (p:ℝ)⁻¹ else 0 := by + have h := primeMeasure_setIntegral w V (fun _ => (1:ℝ)) hJ + simpa only [integral_const,smul_eq_mul,measureReal_restrict_apply_univ,mul_one] using h + +theorem intervalGuard_measurable (lc rc : Bool) (a b : ℝ) : + MeasurableSet {x | intervalGuard lc rc a b x} := by + cases lc <;> cases rc <;> simp only [intervalGuard,ite_true,Bool.false_eq_true,ite_false] <;> measurability + +theorem primeMeasure_interval {w a b V : ℝ} (hw : 1 < w) (hbV : b ≤ V) (lc rc : Bool) : + (primeMeasure w V).real {x | intervalGuard lc rc a b x}=harmonicMass w lc rc a b := by + rw [primeMeasure_real w V (intervalGuard_measurable lc rc a b),harmonicMass] + have hw0 : 0 < w := by linarith + have hpow : w^b ≤ w^V := Real.rpow_le_rpow_of_exponent_le hw.le hbV + have hsub : Nat.primesLE ⌊w^b⌋₊ ⊆ Nat.primesLE ⌊w^V⌋₊ := by + intro p hp + obtain ⟨hpB,hprime⟩ := Nat.mem_primesLE.mp hp + exact Nat.mem_primesLE.mpr ⟨hpB.trans (Nat.floor_mono hpow),hprime⟩ + symm + apply Finset.sum_subset hsub + intro p hpV hpB + have hprime := (Nat.mem_primesLE.mp hpV).2 + have hp0 : 0 < (p:ℝ) := by exact_mod_cast hprime.pos + have hnot : ¬intervalGuard lc rc a b (primeExponent w p) := by + intro hguard + have hxp : primeExponent w p ≤ b := by + have hh := hguard.2 + cases rc with + | false => exact hh.le + | true => exact hh + have hpx := (exponent_le_iff hw hp0).mp hxp + exact hpB (Nat.mem_primesLE.mpr ⟨(Nat.le_floor_iff (Real.rpow_pos_of_pos hw0 b).le).mpr hpx,hprime⟩) + exact ite_eq_right hnot + +end NumberTheoryLean.HarmonicPrimeAtomicMeasure + +end + +section + +open _root_.MeasureTheory _root_.Set _root_.Filter +open scoped Topology +namespace ErdosContinuousBoundary +open ErdosMonotoneQuadrature ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimeEndpoints +open NumberTheoryLean.HarmonicPrimeAtomicMeasure NumberTheoryLean.HarmonicReferenceMeasure + +noncomputable def boundaryPrimeError (c C w : ℝ) : ℝ := C*Real.exp (-c*Real.sqrt (Real.log w)) + +theorem boundaryPrimeError_tendsto_zero {c : ℝ} (hc : 0 < c) (C : ℝ) : + Tendsto (boundaryPrimeError c C) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (0:ℝ) c hc).const_mul C + have h' : Tendsto (fun x : ℝ => C*Real.exp (-c*x)) atTop (𝓝 0) := by + simpa only [Real.rpow_zero,one_mul,mul_zero] using h + exact h'.comp (Real.tendsto_sqrt_atTop.comp Real.tendsto_log_atTop) + +theorem boundary_interval_discrepancy : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ J : Set ℝ,J.OrdConnected → J ⊆ Icc 1 2 → + |(primeMeasure w 2).real J-(referenceMeasure 1 2).real J| ≤ boundaryPrimeError c C w := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := harmonic_prime_measure + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw J hJ hsub + have hw1 : 1 < w := hw₀.trans_le hw + apply orderConnected_measure_discrepancy (primeMeasure w 2) (referenceMeasure 1 2) 1 2 + (boundaryPrimeError c C w) (by unfold boundaryPrimeError; positivity) _ hJ hsub + intro a b ha hab hb + have hall (lc rc : Bool) : + |(primeMeasure w 2).real {x | intervalGuard lc rc a b x}- + (referenceMeasure 1 2).real {x | intervalGuard lc rc a b x}| ≤ boundaryPrimeError c C w := by + rw [primeMeasure_interval hw1 hb,referenceMeasure_interval (by norm_num : (0:ℝ)<1) ha hab hb] + have hh := h w hw a b (by linarith) hab lc rc + have hs : Real.sqrt (Real.log w) ≤ Real.sqrt (a*Real.log w) := by + apply Real.sqrt_le_sqrt + have hlog := (Real.log_pos hw1).le + nlinarith + have he : Real.exp (-c*Real.sqrt (a*Real.log w)) ≤ Real.exp (-c*Real.sqrt (Real.log w)) := + Real.exp_le_exp.mpr (by nlinarith) + exact hh.trans (mul_le_mul_of_nonneg_left he hC.le) + exact ⟨hall true true,hall true false,hall false true,hall false false⟩ + +theorem reference_unit_interval_mass : (referenceMeasure 1 2).real (Icc 1 2)=Real.log 2 := by + have h := referenceMeasure_interval (u:=1) (v:=2) (a:=1) (b:=2) + (by norm_num) le_rfl (by norm_num) le_rfl true true + simpa only [intervalGuard,ite_true,Real.log_one,sub_zero] using! h + +theorem boundary_measure_control : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → + (primeMeasure w 2).real (Icc 1 2) ≤ 1 ∧ + ∀ J : Set ℝ,J.OrdConnected → J ⊆ Icc 1 2 → + |(primeMeasure w 2).real J-(referenceMeasure 1 2).real J| ≤ boundaryPrimeError c C w := by + obtain ⟨c,C,wH,hc,hC,hwH,h⟩ := boundary_interval_discrepancy + have hlog : Real.log 2 < 1 := by + have hh := Real.log_lt_sub_one_of_pos (by norm_num : (0:ℝ)<2) (by norm_num : (2:ℝ)≠1) + norm_num at hh + exact hh + have he := (boundaryPrimeError_tendsto_zero hc C).eventually + (Iio_mem_nhds (by linarith : (0:ℝ)<1-Real.log 2)) + obtain ⟨wE,hwE⟩ := eventually_atTop.mp he + refine ⟨c,C,max wH wE,hc,hC,hwH.trans_le (le_max_left _ _),?_⟩ + intro w hw + have hwh : wH ≤ w := (le_max_left _ _).trans hw + have hwe := hwE w ((le_max_right _ _).trans hw) + refine ⟨?_,h w hwh⟩ + have hm := h w hwh (Icc 1 2) ordConnected_Icc (subset_refl _) + rw [reference_unit_interval_mass] at hm + have hmass := (abs_le.mp hm).2 + change boundaryPrimeError c C w < 1-Real.log 2 at hwe + linarith + +end ErdosContinuousBoundary + +end + +section + +namespace NumberTheoryLean.ActualPrimeQuadrature + +attribute [local instance] Classical.propDecidable +open _root_.MeasureTheory _root_.Set _root_.Finset +open ErdosMonotoneQuadrature ErdosPrimeInputs.HarmonicPrimeMeasure ErdosPrimeInputs.PrimeEndpoints +open HarmonicPrimeAtomicMeasure HarmonicReferenceMeasure + +theorem actual_interval_discrepancy : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ u v : ℝ,2 ≤ u → u ≤ v → ∀ a b : ℝ,u ≤ a → a ≤ b → b ≤ v → + ∀ lc rc : Bool, + |(primeMeasure w v).real {x | intervalGuard lc rc a b x}- + (referenceMeasure u v).real {x | intervalGuard lc rc a b x}| ≤ + C*Real.exp (-c*Real.sqrt (u*Real.log w)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := harmonic_prime_measure + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw u v hu _huv a b hua hab hbv lc rc + have hw1 : 1 < w := hw₀.trans_le hw + have hu0 : 0 < u := by linarith + rw [primeMeasure_interval hw1 hbv,referenceMeasure_interval hu0 hua hab hbv] + have hh := h w hw a b (by linarith) hab lc rc + have hm : Real.exp (-c*Real.sqrt (a*Real.log w)) ≤ Real.exp (-c*Real.sqrt (u*Real.log w)) := by + apply Real.exp_le_exp.mpr + have hs := Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_right hua (Real.log_pos hw1).le) + nlinarith + exact hh.trans (mul_le_mul_of_nonneg_left hm hC.le) + +theorem actual_weighted_prime_quadrature : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → ∀ u v : ℝ,2 ≤ u → u ≤ v → ∀ D : ℝ,0 ≤ D → ∀ g : ℝ → ℝ, + (MonotoneOn g (Icc u v) ∨ AntitoneOn g (Icc u v)) → + (∀ x ∈ Icc u v,|g x| ≤ D) → ∀ J : Set ℝ,J.OrdConnected → J ⊆ Icc u v → + |(∑ p ∈ Nat.primesLE ⌊w^v⌋₊,if primeExponent w p ∈ J then + (p:ℝ)⁻¹*g (primeExponent w p)/primeExponent w p else 0)- + ∫ x in J,g x/x^2| ≤ (C*D/u)*Real.exp (-c*Real.sqrt (u*Real.log w)) := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := actual_interval_discrepancy + refine ⟨c,3*C,w₀,hc,by positivity,hw₀,?_⟩ + intro w hw u v hu huv D hD g hg hbound J hJ hsub + have hu0 : 0 < u := by linarith + let := referenceMeasure_finite (v:=v) hu0 + let E := C*Real.exp (-c*Real.sqrt (u*Real.log w)) + have hinter : ∀ a b : ℝ,u ≤ a → a ≤ b → b ≤ v → + |(primeMeasure w v).real (Icc a b)-(referenceMeasure u v).real (Icc a b)| ≤ E ∧ + |(primeMeasure w v).real (Ico a b)-(referenceMeasure u v).real (Ico a b)| ≤ E ∧ + |(primeMeasure w v).real (Ioc a b)-(referenceMeasure u v).real (Ioc a b)| ≤ E ∧ + |(primeMeasure w v).real (Ioo a b)-(referenceMeasure u v).real (Ioo a b)| ≤ E := by + intro a b hua hab hbv + have hh := h w hw u v hu huv a b hua hab hbv + exact ⟨hh true true,hh true false,hh false true,hh false false⟩ + have hq := weighted_from_all_endpoint_intervals (primeMeasure w v) (referenceMeasure u v) + u v D E hu0 hD (by dsimp [E]; positivity) g hg hbound hinter hJ hsub + rw [primeMeasure_setIntegral w v _ hJ.measurableSet, + referenceMeasure_weightedIntegral hu0 g hJ.measurableSet hsub] at hq + calc + _ ≤ 3*E*D/u := by simpa only [mul_div_assoc] using hq + _ = _ := by dsimp [E]; ring + +end NumberTheoryLean.ActualPrimeQuadrature + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/ActualPrimeSelectors.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/ActualPrimeSelectors.lean new file mode 100644 index 0000000000000000000000000000000000000000..d9cb4f9f2605ec583639c6e8dfba08018b424017 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/ActualPrimeSelectors.lean @@ -0,0 +1,92 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ActualModelTargets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace ErdosVarianceMoments +open NumberTheoryLean ErdosVarianceSmallModel ErdosVarianceEffective ErdosVarianceCommon + ErdosInverseCells +attribute [local instance] Classical.propDecidable + +theorem actual_primePoint_survives (P : Finset ℕ) (w : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) + (hq : Squarefree qf) (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hPLarge : ∀ p ∈ P,w < (p : ℝ)) + (hQLarge : ∀ t ∈ qf.primeFactors,w < (t : ℝ)) (p : ℕ) [NeZero p] + (hpGood : p ∈ goodPrimes P (effectiveModulus a r qf)) (j : ℕ) : + actualModelSurvives w a r qf j + (primePoint P w (effectiveModulus a r qf) (effectiveIntercept a r qf) hw hP hPLarge ⟨p,hpGood⟩) ↔ + ∀ t ∈ LargePrimeDeletion.cutoffPrimes ⌊w⌋₊, + (effectiveInteger a r qf p (Finset.mem_filter.mp hpGood).2 (j : ℤ) : ZMod t) ≠ (a t : ZMod t) := by + let H := effectiveModulus a r qf + let C0 := effectiveIntercept a r qf + let qA := alignedCofactor (fun t => (a t : ℤ)) r qf + let v := primePoint P w H C0 hw hP hPLarge ⟨p,hpGood⟩ + have hC0 : Int.gcd C0 (H : ℤ) = 1 := effective_coordinates_gcd a r qf hq + have hHp : H.Coprime p := (Finset.mem_filter.mp hpGood).2 + have h0 (t : ℕ) (ht : t ∈ divisorPrimes w H) : + (patternKValue w H v.2 t+divisorPhase C0 v.1 t*(j : ZMod t) ≠ actualDivisorTarget a qf t) ↔ + (effectiveInteger a r qf p hHp (j : ℤ) : ZMod t) ≠ (a t : ZMod t) := by + have htt := (Finset.mem_filter.mp ht).1 + have hprime := (LargePrimeDeletion.mem_cutoffPrimes.mp htt).1 + have htw := (Nat.le_floor_iff hw).mp (LargePrimeDeletion.mem_cutoffPrimes.mp htt).2 + have hqt := full_cofactor_coprime_small qf hq w hQLarge t hprime htw + have ht0 : t ∣ divisorModulus w H := Finset.dvd_prod_of_mem _ ht + dsimp only [v] + rw [primePoint_kValue P w H C0 hw hP hPLarge ⟨p,hpGood⟩ t ht0] + change ((primeK P H C0 hP ⟨p,hpGood⟩ : ZMod t) + + divisorPhase C0 (primeM P H C0 hP ⟨p,hpGood⟩) t * (j : ZMod t) ≠ _) ↔ _ + rw [← prime_divisorPhase_eq P H C0 hP hC0 ⟨p,hpGood⟩ t (Finset.mem_filter.mp ht).2] + have hh := effective_avoidance_unit a r qf p hHp t hqt (j : ℤ) + simpa [H,C0,primeK,actualDivisorTarget,ZMod.unitOfCoprime] using hh.symm + have h1 (t : ℕ) (ht : t ∈ coprimePrimes w H) : + (patternPValue w H v.2 t*(qA : ZMod t)*((v.1 : ZMod t)+(H : ZMod t)*(j : ZMod t)) ≠ actualCoprimeTarget a r t) ↔ + (effectiveInteger a r qf p hHp (j : ℤ) : ZMod t) ≠ (a t : ZMod t) := by + have htt := (Finset.mem_filter.mp ht).1 + have hprime := (LargePrimeDeletion.mem_cutoffPrimes.mp htt).1 + have ht1 : t ∣ coprimeModulus w H := Finset.dvd_prod_of_mem _ ht + dsimp only [v] + rw [primePoint_pValue P w H C0 hw hP hPLarge ⟨p,hpGood⟩ t ht1] + have hh := effective_avoidance_not_dvd a r qf hq p hHp t hprime (Finset.mem_filter.mp ht).2 (j : ℤ) + simpa only [H,C0,qA,primePoint,primeM,actualCoprimeTarget,Int.cast_natCast] using hh.symm + change modelSurvives w H C0 qA (actualDivisorTarget a qf) (actualCoprimeTarget a r) j v ↔ _ + constructor + · intro hv t ht + by_cases hdiv : t ∣ H + · have ht0 : t ∈ divisorPrimes w H := Finset.mem_filter.mpr ⟨ht,hdiv⟩ + exact (h0 t ht0).mp (hv.1 t ht0) + · have ht1 : t ∈ coprimePrimes w H := Finset.mem_filter.mpr ⟨ht,hdiv⟩ + exact (h1 t ht1).mp (hv.2 t ht1) + · intro hv + refine ⟨?_,?_⟩ + · intro t ht + exact (h0 t ht).mpr (hv t (Finset.mem_filter.mp ht).1) + · intro t ht + exact (h1 t ht).mpr (hv t (Finset.mem_filter.mp ht).1) + +theorem common_card_eq_model_sum (P : Finset ℕ) (J : ℕ) (w : ℝ) (a : ℕ → ℕ) (r : ℚ) (qf : ℕ) + (hq : Squarefree qf) (hw : 0 ≤ w) (hP : ∀ p ∈ P,p.Prime) (hPLarge : ∀ p ∈ P,w < (p : ℝ)) + (hQLarge : ∀ t ∈ qf.primeFactors,w < (t : ℝ)) (p : ℕ) [NeZero p] + (hpGood : p ∈ goodPrimes P (effectiveModulus a r qf)) : + ((commonSurvivors J w a r qf p (Finset.mem_filter.mp hpGood).2).card : ℝ) = + ∑ j ∈ Finset.range J,actualModelIndicator w a r qf j + (primePoint P w (effectiveModulus a r qf) (effectiveIntercept a r qf) hw hP hPLarge ⟨p,hpGood⟩) := by + classical + let v := primePoint P w (effectiveModulus a r qf) (effectiveIntercept a r qf) hw hP hPLarge ⟨p,hpGood⟩ + have he : commonSurvivors J w a r qf p (Finset.mem_filter.mp hpGood).2 = + (Finset.range J).filter (fun j => actualModelSurvives w a r qf j v) := by + ext j + simp only [mem_commonSurvivors,Finset.mem_filter,Finset.mem_range] + exact and_congr Iff.rfl (actual_primePoint_survives P w a r qf hq hw hP hPLarge hQLarge p hpGood j).symm + rw [he,Finset.natCast_card_filter] + rfl + +end ErdosVarianceMoments + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/AdjacentPrimeRecovery.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/AdjacentPrimeRecovery.lean new file mode 100644 index 0000000000000000000000000000000000000000..38e9af03943b18f461d54c22b078272db3a77f2f --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/AdjacentPrimeRecovery.lean @@ -0,0 +1,298 @@ +import OAI.NumberTheory.Jacobsthal.Probability.FiniteHistoryPairLaw +import OAI.NumberTheory.Jacobsthal.Probability.SourceThresholdCoupling +import OAI.NumberTheory.Jacobsthal.Probability.SuccessfulMarkedCoordinates + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.PrimeHistoryPrefixOrder + +open _root_.Set _root_.Filter _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualCouplingUpdates +open FiniteHistoryTransport ActualCoupledHistories + +variable {w ell S : ℝ} {start : Node} + +def prefixRel : ChainState w ell S start → ChainState w ell S start → Prop + | _,none => True + | none,some _ => False + | some a,some b => ∃ tail : List ℕ,b.primes = a.primes++tail + +theorem prefixRel_refl (p : ChainState w ell S start) : prefixRel p p := by + cases p with + | none => trivial + | some p => exact ⟨[],by simp⟩ + +theorem prefixRel_trans {p q r : ChainState w ell S start} (hp : prefixRel p q) (hq : prefixRel q r) : + prefixRel p r := by + cases r with + | none => trivial + | some r => + cases q with + | none => exact False.elim hq + | some q => + cases p with + | none => exact False.elim hp + | some p => + obtain ⟨u,hu⟩ := hp + obtain ⟨v,hv⟩ := hq + exact ⟨u++v,by rw [hv,hu,List.append_assoc]⟩ + +theorem actual_row_prefixRel (p : ChainState w ell S start) : + ∀ᵐ q ∂chain w ell S start p, prefixRel p q := by + cases p with + | none => + rw [chain_none] + exact (ae_dirac_iff (by trivial)).mpr trivial + | some p => + filter_upwards [prime_follows p] with q hq + cases q with + | none => trivial + | some q => + obtain ⟨a,ha,rfl⟩ := hq + exact ⟨[a],rfl⟩ + +def orderedPast (N : ℕ) (h : Hist (ChainState w ell S start) N) : Prop := + ∀ i j : Finset.Iic N, i.1 ≤ j.1 → prefixRel (h i) (h j) + +theorem orderedPast_measurable (N : ℕ) : + MeasurableSet {h : Hist (ChainState w ell S start) N | orderedPast N h} := + (Set.to_countable _).measurableSet + +theorem orderedPast_extend (N : ℕ) (h : Hist (ChainState w ell S start) N) + (q : ChainState w ell S start) (hp : orderedPast N h) (hq : prefixRel (last N h) q) : + orderedPast (N+1) (FiniteHistoryTransport.extend N h q) := by + intro ⟨i,hi⟩ ⟨j,hj⟩ hij + have hi' := Finset.mem_Iic.mp hi + have hj' := Finset.mem_Iic.mp hj + by_cases hjN : j ≤ N + · have hiN : i ≤ N := hij.trans hjN + rw [extend_previous N h q ⟨i,Finset.mem_Iic.mpr hiN⟩, + extend_previous N h q ⟨j,Finset.mem_Iic.mpr hjN⟩] + exact hp _ _ hij + · have hjEq : j = N+1 := by omega + subst j + change prefixRel _ (last (N+1) (FiniteHistoryTransport.extend N h q)) + rw [extend_last] + by_cases hiN : i ≤ N + · rw [extend_previous N h q ⟨i,Finset.mem_Iic.mpr hiN⟩] + exact prefixRel_trans (hp ⟨i,Finset.mem_Iic.mpr hiN⟩ ⟨N,by simp⟩ hiN) hq + · have hiEq : i = N+1 := by omega + subst i + change prefixRel (last (N+1) (FiniteHistoryTransport.extend N h q)) q + rw [extend_last] + exact prefixRel_refl q + +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +include hw hell hS0 hS hr hs hsS + +theorem actual_history_ordered (N : ℕ) : + ∀ᵐ h ∂pathKernel (chain w ell S start) N (fun _ => some History.empty), orderedPast N h := by + let := chain_isMarkov hw hell hS0 hS hr hs hsS + induction N with + | zero => + change ∀ᵐ h ∂Measure.dirac (fun _ => some History.empty), orderedPast 0 h + exact (ae_dirac_iff (orderedPast_measurable 0)).mpr (fun _ _ _ => prefixRel_refl _) + | succ N ih => + apply ae_pathKernel_succ _ N _ (orderedPast_measurable (N+1)) + filter_upwards [ih] with h hh + filter_upwards [actual_row_prefixRel (last N h)] with q hq + exact orderedPast_extend N h q hh hq + +end NumberTheoryLean.PrimeHistoryPrefixOrder + +end + +section + +namespace NumberTheoryLean.PriorPrimeWindow + +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry FinitePathMeasures PrimeHistories PrimeKilledChain PrimeBinMembership +open FiniteHistoryTransport ActualCoupledHistories PrimeHistoryPrefixOrder +open ActualProcessCoupling ActualSuccessfulHistories SuccessfulMarkedCoordinates ArrivalKernelGeometry + +def hasPrimeWindow (w b₀ b₁ : ℝ) (start : Node) (ps : List ℕ) : Prop := + ∃ pre tail : List ℕ, ps = pre++tail ∧ primeWindow b₀ b₁ (terminal w start pre) + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistory_ordered (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + orderedPast N (mapHist (fun q => q.1.1) N h) := by + have hm := orderedPast_measurable (w:=w) (ell:=ell) (S:=S) (start:=start) N + have hp : ∀ᵐ h ∂(sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N).map + (mapHist (fun q => q.1.1) N), orderedPast N h := by + rw [sourceHistoryLaw_prime] + exact actual_history_ordered hw hell hS0 hS hr hs hsS N + exact (ae_map_iff (mapHist_measurable (by exact measurable_fst.comp measurable_fst) N).aemeasurable hm).mp hp + +theorem sourceHistory_prior_live (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + ∀ i j : Finset.Iic N, i.1 ≤ j.1 → ∀ p : History w ell S start, + (h j).1.1 = some p → ∃ q : History w ell S start, + (h i).1.1 = some q ∧ ∃ tail : List ℕ,p.primes = q.primes++tail := by + filter_upwards [sourceHistory_ordered hw hell hS0 hS hr hs hsS mesh N] with h hh + intro i j hij p hp + have hrel := hh i j hij + change prefixRel (h i).1.1 (h j).1.1 at hrel + rw [hp] at hrel + cases hq : (h i).1.1 with + | none => rw [hq] at hrel; exact False.elim hrel + | some q => + rw [hq] at hrel + exact ⟨q,rfl,hrel⟩ + +theorem sourceHistory_prior_mark (hc : Consistent start) + {mesh : ℝ} (hm : 0 < mesh) (hmesh : mesh ≤ 1/100) (N : ℕ) + (herror : 4*(N:ℝ)*mesh ≤ Real.log (11/10)) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + (last N h).2 = false → ∀ i j : Finset.Iic N, i.1 ≤ j.1 → + ∀ p : History w ell S start, (h j).1.1 = some p → ∀ z : CostState, + (h i).1.2 = Sum.inl z → ∀ b₀ b₁ : ℝ, 0 < b₀ → + stateSide z.1 = .even → 209/100 ≤ stateRatio z.1 → stateRatio z.1 ≤ 213/100 → + 10*b₀/(313/100) ≤ currentExponent (Real.log start.gap) z → + currentExponent (Real.log start.gap) z ≤ b₁/(309/100) → + hasPrimeWindow w b₀ b₁ start p.primes := by + filter_upwards [sourceHistory_prior_live hw hell hS0 hS hr hs hsS mesh N, + sourceHistory_transports_marked_window hw hell hS0 hS hr hs hsS hc hm hmesh N herror] with h hp hmks + intro hflag i j hij p hpj z hzi b₀ b₁ hb₀ heven ht₀ ht₁ hx₀ hx₁ + obtain ⟨q,hqi,hwin⟩ := hmks hflag i z hzi b₀ b₁ hb₀ heven ht₀ ht₁ hx₀ hx₁ + obtain ⟨q',hqi',tail,happend⟩ := hp i j hij p hpj + have heq : q' = q := Option.some.inj (hqi'.symm.trans hqi) + subst q' + exact ⟨q.primes,tail,happend,hwin⟩ + +end NumberTheoryLean.PriorPrimeWindow + +end + +section + +namespace NumberTheoryLean.PrimePrefixRecovery +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry PrimeHistories PrimeKilledChain PrimeChainHorizon +open FiniteHistoryTransport ActualCoupledHistories FlaggedSourceStart ActualProcessCoupling +open PriorPrimeWindow SourceThresholdCoupling ReconstructedParentCoupling + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistory_stages (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N,∀ j : Finset.Iic N, + stage j.1 (h j).1.1 := by + apply ae_all_iff.mpr + intro j + have hP : MeasurableSet {q : PersistentFailureFlag.FlagState (JointState w ell S start) | stage j.1 q.1.1} := + (measurable_fst.comp measurable_fst) (stage_measurable j.1) + have hc : Measurable (fun h : Hist (PersistentFailureFlag.FlagState (JointState w ell S start)) N => h j) := + measurable_pi_apply j + apply (ae_map_iff hc.aemeasurable hP).mp + rw [sourceHistoryLaw_coordinate hw hell hS0 hS hr hs hsS mesh N j.1 (Finset.mem_Iic.mp j.2)] + have hh : ∀ᵐ p ∂(sourceLaw hw hell hS0 hS hr hs hsS mesh j.1).map (fun q => q.1.1),stage j.1 p := by + rw [sourceLaw_prime hw hell hS0 hS hr hs hsS mesh j.1] + exact pathLaw_stage j.1 + exact (ae_map_iff (measurable_fst.comp measurable_fst).aemeasurable (stage_measurable j.1)).mp hh + +theorem sourceHistory_recovers_prefix (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + ∀ j : Finset.Iic N,∀ p : History w ell S start,(h j).1.1=some p → + ∀ pre tail : List ℕ,p.primes=pre++tail → + ∃ hk : pre.length ≤ N,∃ q : History w ell S start, + (h ⟨pre.length,Finset.mem_Iic.mpr hk⟩).1.1=some q ∧ q.primes=pre := by + filter_upwards [sourceHistory_stages hw hell hS0 hS hr hs hsS mesh N, + sourceHistory_prior_live hw hell hS0 hS hr hs hsS mesh N] with h hstage hprior + intro j p hp pre tail hword + have hlen : p.primes.length=j.1 := by + have hh := hstage j + rw [hp] at hh + exact hh + have hprej : pre.length ≤ j.1 := by rw [hword,List.length_append] at hlen; omega + have hpreN := hprej.trans (Finset.mem_Iic.mp j.2) + let i : Finset.Iic N := ⟨pre.length,Finset.mem_Iic.mpr hpreN⟩ + obtain ⟨q,hq,suf,hsuf⟩ := hprior i j hprej p hp + have hqlen : q.primes.length=pre.length := by + have hh := hstage i + rw [hq] at hh + exact hh + have htakeP : p.primes.take pre.length=pre := by rw [hword]; simp + have htakeQ : p.primes.take q.primes.length=q.primes := by rw [hsuf]; simp + rw [hqlen] at htakeQ + exact ⟨hpreN,q,hq,htakeQ.symm.trans htakeP⟩ + +def hasNearThresholdPrefix (w d : ℝ) (start : Node) (ps : List ℕ) : Prop := + ∃ pre tail : List ℕ,ps=pre++tail ∧ pre ≠ [] ∧ primeNearThreshold d (terminal w start pre) + +theorem recovered_near_prefix_occurs (mesh d : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + ∀ j : Finset.Iic N,∀ p : History w ell S start,(h j).1.1=some p → + hasNearThresholdPrefix w d start p.primes → primeThresholdOccurs d N h := by + filter_upwards [sourceHistory_recovers_prefix hw hell hS0 hS hr hs hsS mesh N] with h hh + intro j p hp hnear + obtain ⟨pre,tail,hword,hne,hbad⟩ := hnear + obtain ⟨hk,q,hq,hqpre⟩ := hh j p hp pre tail hword + have hlen : 1 ≤ pre.length := List.length_pos_iff.mpr hne + let k : Fin N := ⟨pre.length-1,by omega⟩ + refine ⟨k,?_⟩ + have he : k.1+1=pre.length := by dsimp [k]; omega + change nearPrimeNode d ((h ⟨k.1+1,Finset.mem_Iic.mpr (by have := k.isLt; omega)⟩).1.1) + have hcoord : (h ⟨k.1+1,Finset.mem_Iic.mpr (by have := k.isLt; omega)⟩).1.1=some q := by + simpa only [he] using hq + rw [hcoord] + change primeNearThreshold d (terminal w start q.primes) + rw [hqpre] + exact hbad +end NumberTheoryLean.PrimePrefixRecovery + +end + +section + +namespace NumberTheoryLean.AdjacentPrimeRecovery +open _root_.Set _root_.MeasureTheory ProbabilityTheory +open FinitePathGeometry PrimeHistories PrimeKilledChain ActualProcessCoupling +open FiniteHistoryTransport FiniteHistoryOccurrence FiniteHistoryPairLaw ActualCoupledHistories +open PrimePrefixRecovery PersistentFailureFlag + +variable {w ell S : ℝ} {start : Node} +variable (hw : normalizationThreshold ≤ w) (hell : 1 ≤ ell) (hS0 : 0 ≤ S) +variable (hS : S ≤ (Real.log w)^3) (hr : 0 < start.gap) +variable (hs : Valid start.side start.ratio) (hsS : start.ratio ≤ S) + +theorem sourceHistory_recovers_adjacent (mesh : ℝ) (N : ℕ) : + ∀ᵐ h ∂sourceHistoryLaw hw hell hS0 hS hr hs hsS mesh N, + ∀ j : Finset.Iic N,∀ p : History w ell S start,(h j).1.1=some p → + ∀ pre : List ℕ,∀ a b : ℕ,∀ tail : List ℕ,p.primes=pre++a::b::tail → + ∃ k : Fin N,∃ q r : History w ell S start, + (atIndex N h k.castSucc).1.1=some q ∧ (atIndex N h k.succ).1.1=some r ∧ + q.primes=pre++[a] ∧ r.primes=(pre++[a])++[b] := by + filter_upwards [sourceHistory_recovers_prefix hw hell hS0 hS hr hs hsS mesh N] with h hh + intro j p hp pre a b tail hword + have hparent : p.primes=(pre++[a])++(b::tail) := by simpa only [List.append_assoc,List.singleton_append,List.cons_append,List.nil_append] using hword + have hchild : p.primes=((pre++[a])++[b])++tail := by simpa only [List.append_assoc,List.singleton_append,List.cons_append,List.nil_append] using hword + obtain ⟨hqN,q,hq,hqword⟩ := hh j p hp (pre++[a]) (b::tail) hparent + obtain ⟨hrN,r,hr,hrword⟩ := hh j p hp ((pre++[a])++[b]) tail hchild + have hlen : ((pre++[a])++[b]).length=(pre++[a]).length+1 := by simp + let k : Fin N := ⟨(pre++[a]).length,by omega⟩ + refine ⟨k,q,r,hq,?_,hqword,hrword⟩ + change (h ⟨(pre++[a]).length+1,Finset.mem_Iic.mpr (by omega)⟩).1.1=some r + simpa only [hlen] using hr +end NumberTheoryLean.AdjacentPrimeRecovery + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/BadPrimeProduct.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/BadPrimeProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea8dbc5c7a8dea5fadc175a931a4e1dc78a2e604 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/BadPrimeProduct.lean @@ -0,0 +1,83 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.FactorDividesAbscissa + +namespace OAI + +namespace Erdos970 + +section + +namespace ErdosPrimitiveIntercept +open ErdosRichLine ErdosInverseAlignment + +theorem InterceptReduction.prime_alignment {l : PrimitiveIntegerLine} (r : InterceptReduction l) + (a : ℕ → ℤ) (p : ℤ × ℤ) (hp : l.Contains p) (ell : ℕ) (hell : Nat.Prime ell) + (hx : (ell : ℤ) ∣ p.1) (hclass : (p.2 : ZMod ell) = (a ell : ZMod ell)) + (hfactor : ¬ell ∣ r.factor) : aligns a r.rational ell := by + let : Fact (Nat.Prime ell) := ⟨hell⟩ + have hg : (r.factor : ZMod ell) ≠ 0 := (ZMod.natCast_eq_zero_iff _ _).not.mpr hfactor + have hx0 : (p.1 : ZMod ell) = 0 := (ZMod.intCast_zmod_eq_zero_iff_dvd _ _).mpr hx + unfold PrimitiveIntegerLine.Contains at hp + rw [r.denominator_eq,r.intercept_eq] at hp + have hh := congrArg (fun n : ℤ => (n : ZMod ell)) hp + have he : (r.factor : ZMod ell)*((r.rational.den : ZMod ell)*(a ell : ZMod ell)) = + (r.factor : ZMod ell)*(r.rational.num : ZMod ell) := by + simpa only [Int.cast_mul,Int.cast_add,Int.cast_natCast,Nat.cast_mul,hx0, + mul_zero,zero_add,hclass,mul_assoc] using hh + exact mul_left_cancel₀ hg he + +theorem InterceptReduction.nonaligned_prime_dvd_factor {l : PrimitiveIntegerLine} + (r : InterceptReduction l) (a : ℕ → ℤ) (p : ℤ × ℤ) (hp : l.Contains p) + (ell : ℕ) (hell : Nat.Prime ell) (hx : (ell : ℤ) ∣ p.1) + (hclass : (p.2 : ZMod ell) = (a ell : ZMod ell)) (hna : ¬aligns a r.rational ell) : + ell ∣ r.factor := by + by_contra hh + exact hna (r.prime_alignment a p hp ell hell hx hclass hh) + +end ErdosPrimitiveIntercept + +end + +section + +namespace ErdosPrimitiveIntercept +open ErdosRichLine ErdosInverseAlignment + +noncomputable def badPrimeFactors (a : ℕ → ℤ) (t : ℚ) (q : ℕ) : Finset ℕ := by + classical + exact q.primeFactors.filter (fun ell => ¬aligns a t ell) + +noncomputable def badPrimeProduct (a : ℕ → ℤ) (t : ℚ) (q : ℕ) : ℕ := + ∏ ell ∈ badPrimeFactors a t q, ell + +theorem InterceptReduction.bad_product_dvd_factor {l : PrimitiveIntegerLine} + (r : InterceptReduction l) (a : ℕ → ℤ) (q : ℕ) (b : ℤ) + (hp : l.Contains ((q : ℤ),b)) + (hclass : ∀ ell ∈ q.primeFactors, (b : ZMod ell) = (a ell : ZMod ell)) : + badPrimeProduct a r.rational q ∣ r.factor := by + classical + apply Finset.prod_primes_dvd r.factor + · intro ell hell + exact (Nat.prime_of_mem_primeFactors (Finset.mem_filter.mp hell).1).prime + · intro ell hell + obtain ⟨hfactor,hna⟩ := Finset.mem_filter.mp hell + have he := Nat.mem_primeFactors.mp hfactor + exact r.nonaligned_prime_dvd_factor a ((q : ℤ),b) hp ell he.1 + (by change (ell : ℤ) ∣ (q : ℤ);exact_mod_cast he.2.1) (hclass ell hfactor) hna + +theorem InterceptReduction.structure_bound {l : PrimitiveIntegerLine} + (r : InterceptReduction l) (a : ℕ → ℤ) (q : ℕ) (b : ℤ) + (hp : l.Contains ((q : ℤ),b)) + (hclass : ∀ ell ∈ q.primeFactors, (b : ZMod ell) = (a ell : ZMod ell)) : + r.rational.den*badPrimeProduct a r.rational q ≤ l.denominator := by + have hle := Nat.le_of_dvd r.factor_pos (r.bad_product_dvd_factor a q b hp hclass) + calc + _ ≤ r.rational.den*r.factor := Nat.mul_le_mul_left _ hle + _ = l.denominator := by rw [r.denominator_eq,mul_comm] + +end ErdosPrimitiveIntercept + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundaryPrimeMass.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundaryPrimeMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..487966a766e6b9be9a917c4cbf4e8e4bd8dcebff --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundaryPrimeMass.lean @@ -0,0 +1,128 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.ReferenceWeightedQuadrature + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +namespace NumberTheoryLean.VariablePrimeTilt + +open _root_.Finset +open ReferenceAdmission FinitePathGeometry +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +theorem variable_tilt_weight (t : ℝ) (ps : List ℕ) : + (ps.map (fun p : ℕ => t*(p:ℝ)⁻¹)).prod=t^ps.length*prefixWeight ps := by + induction ps with + | nil => simp [prefixWeight] + | cons p ps ih => + simp only [List.map_cons,List.prod_cons,List.length_cons,pow_succ,prefixWeight] at ih ⊢ + rw [ih] + ring + +theorem long_prefix_variable_tilt (P : Finset ℕ) (m : ℕ) {t : ℝ} (ht : 1 ≤ t) : + longPrefixMass P m ≤ Real.exp (t*∑ p ∈ P,(p:ℝ)⁻¹)/t^m := by + have ht0 : 0 < t := by linarith + apply (le_div_iff₀ (pow_pos ht0 m)).mpr + rw [mul_comm,longPrefixMass,Finset.mul_sum] + calc + _ ≤ ∑ ps ∈ (decreasingPrefixes P).filter (fun ps => m ≤ ps.length),t^ps.length*prefixWeight ps := by + apply Finset.sum_le_sum + intro ps hp + exact mul_le_mul_of_nonneg_right (pow_le_pow_right₀ ht (Finset.mem_filter.mp hp).2) (prefixWeight_nonneg ps) + _ ≤ ∑ ps ∈ decreasingPrefixes P,t^ps.length*prefixWeight ps := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + intro ps _ _ + exact mul_nonneg (pow_nonneg ht0.le _) (prefixWeight_nonneg ps) + _ = ∏ p ∈ P,(1+t*(p:ℝ)⁻¹) := by + simp_rw [← variable_tilt_weight t] + exact sum_sorted_products P _ + _ ≤ ∏ p ∈ P,Real.exp (t*(p:ℝ)⁻¹) := by + apply Finset.prod_le_prod₀ + · intro p _hp + positivity + · intro p _hp + simpa only [add_comm] using Real.add_one_le_exp (t*(p:ℝ)⁻¹) + _ = _ := by rw [← Real.exp_sum,← Finset.mul_sum] + +noncomputable def omissionMass (w r : ℝ) (i : Side) : ℝ := + ∑ ps ∈ firstOmissions w (boundaryPrimes w) i r,prefixWeight ps + +theorem omission_mass_le_long {w r : ℝ} (hw : 1 < w) (hr : 4 ≤ r) (i : Side) : + omissionMass w r i ≤ longPrefixMass (boundaryPrimes w) (⌊(r-4)/2⌋₊+1) := by + classical + unfold omissionMass longPrefixMass + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro ps hp + have hlen := actual_first_omission_length hw i hp + have hf : ((⌊(r-4)/2⌋₊:ℕ):ℝ) < (ps.length:ℝ) := + (Nat.floor_le (by linarith : 0 ≤ (r-4)/2)).trans_lt hlen + have hn : ⌊(r-4)/2⌋₊+1 ≤ ps.length := by + have hh : ⌊(r-4)/2⌋₊ < ps.length := by exact_mod_cast hf + omega + exact Finset.mem_filter.mpr ⟨(Finset.mem_filter.mp hp).1,hn⟩ + · intro ps _ _ + exact prefixWeight_nonneg ps + +theorem actual_omission_variable_tilt {w r t : ℝ} (hw : 1 < w) (hr : 4 ≤ r) (ht : 1 ≤ t) (i : Side) : + omissionMass w r i ≤ Real.exp (t*∑ p ∈ boundaryPrimes w,(p:ℝ)⁻¹)/t^(⌊(r-4)/2⌋₊+1) := + (omission_mass_le_long hw hr i).trans (long_prefix_variable_tilt _ _ ht) + +end NumberTheoryLean.VariablePrimeTilt + +end + +section + +namespace NumberTheoryLean.BoundaryPrimeMass + +open _root_.Finset +open FinitePathGeometry ReferenceAdmission VariablePrimeTilt +open ErdosPrimeInputs.PrimePrefixMass ErdosPrimeInputs.PrimePrefixTail + +theorem prime_sum_le_prefix_mass (P : Finset ℕ) : + (∑ p ∈ P,(p:ℝ)⁻¹) ≤ ∑ ps ∈ decreasingPrefixes P,prefixWeight ps := by + classical + have hsub : P.image (fun p => [p]) ⊆ decreasingPrefixes P := by + intro ps hps + obtain ⟨p,hp,rfl⟩ := Finset.mem_image.mp hps + apply mem_decreasingPrefixes.mpr + constructor + · simp + · intro q hq + simpa using List.mem_singleton.mp hq ▸ hp + have h := Finset.sum_le_sum_of_subset_of_nonneg hsub + (fun ps _ _ => prefixWeight_nonneg ps) + have he : (∑ ps ∈ P.image (fun p => [p]),prefixWeight ps) = ∑ p ∈ P,(p:ℝ)⁻¹ := by + rw [Finset.sum_image] + · simp [prefixWeight] + · intro p _ q _ hpq + simpa using hpq + rwa [he] at h + +theorem uniform_boundary_mass : ∃ T w₀ : ℝ,0 < T ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → + (∑ p ∈ boundaryPrimes w,(p:ℝ)⁻¹) ≤ T ∧ + (∑ ps ∈ decreasingPrefixes (boundaryPrimes w),prefixWeight ps) ≤ T ∧ + ∀ r i,omissionMass w r i ≤ T := by + classical + obtain ⟨M,w₀,hM,hw₀,h⟩ := total_prime_prefix_mass + refine ⟨2*M,w₀,by positivity,hw₀,?_⟩ + intro w hw + have hmass : (∑ ps ∈ decreasingPrefixes (boundaryPrimes w),prefixWeight ps) ≤ 2*M := by + simpa [boundaryPrimes,Real.rpow_one,mul_comm] using h w hw 1 2 le_rfl (by norm_num) + refine ⟨(prime_sum_le_prefix_mass _).trans hmass,hmass,?_⟩ + intro r i + apply le_trans _ hmass + unfold omissionMass firstOmissions + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun ps _ _ => prefixWeight_nonneg ps) + +end NumberTheoryLean.BoundaryPrimeMass + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundaryPrimeStep.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundaryPrimeStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..b63e0eb468d4f56e9f9ebe583f170cedf86cbb4c --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundaryPrimeStep.lean @@ -0,0 +1,48 @@ +import OAI.NumberTheory.Jacobsthal.Estimates.BoundaryGateSets + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + +section + +open _root_.MeasureTheory _root_.Set _root_.Finset +namespace ErdosContinuousBoundary +attribute [local instance] Classical.propDecidable +open NumberTheoryLean.FinitePathGeometry +open NumberTheoryLean.HarmonicPrimeAtomicMeasure NumberTheoryLean.HarmonicReferenceMeasure +open ErdosPrimeInputs.HarmonicPrimeMeasure + +theorem boundary_prime_step_control : ∃ c C w₀ : ℝ,0 < c ∧ 0 < C ∧ 1 < w₀ ∧ + ∀ w : ℝ,w₀ ≤ w → (primeMeasure w 2).real (Icc 1 2) ≤ 1 ∧ + ∀ (n : ℕ) (i : Side) (r b : ℝ) (closed : Bool), + |(∑ p ∈ Nat.primesLE ⌊w^(2:ℝ)⌋₊,if primeExponent w p ∈ boundaryGateSet i r b closed then + (p:ℝ)⁻¹*boundaryTerm n i.flip (r-primeExponent w p) (primeExponent w p) else 0)- + boundaryTerm (n+1) i r b| ≤ (12*(n:ℝ)+15)*boundaryPrimeError c C w := by + obtain ⟨c,C,w₀,hc,hC,hw₀,h⟩ := boundary_measure_control + refine ⟨c,C,w₀,hc,hC,hw₀,?_⟩ + intro w hw + obtain ⟨hmass,hdiscr⟩ := h w hw + refine ⟨hmass,?_⟩ + intro n i r b closed + have hJ := boundaryGateSet_orderConnected i r b closed + have hsub := boundaryGateSet_subset i r b closed + let := referenceMeasure_finite (u:=1) (v:=2) (by norm_num) + have hq := lipschitz_measure_discrepancy (primeMeasure w 2) (referenceMeasure 1 2) + (fun x => boundaryTerm n i.flip (r-x) x) ((n:NNReal)+1) 1 (boundaryPrimeError c C w) + (by norm_num) (boundaryTerm_child_lipschitz n i.flip r).lipschitzOnWith + (fun x _ => boundaryTerm_abs_le_one n i.flip (r-x) x) hdiscr hJ hsub + rw [primeMeasure_setIntegral w 2 _ hJ.measurableSet,boundaryTerm_gate_integral] at hq + simp only [NNReal.coe_add,NNReal.coe_natCast,NNReal.coe_one] at hq + calc + _ ≤ 3*boundaryPrimeError c C w*(1+4*((n:ℝ)+1)) := hq + _ = _ := by ring + +end ErdosContinuousBoundary + +end + +end Erdos970 + +end OAI diff --git a/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundedEdgeHighPrimes.lean b/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundedEdgeHighPrimes.lean new file mode 100644 index 0000000000000000000000000000000000000000..2fee91b92b2be0a6a997cebca3200a582c67f220 --- /dev/null +++ b/lean/OAI/NumberTheory/Jacobsthal/Primes/BoundedEdgeHighPrimes.lean @@ -0,0 +1,91 @@ +import OAI.NumberTheory.Jacobsthal.Partitions.BoundedEdgeBins + +namespace OAI + +namespace Erdos970 +open scoped _root_.Erdos970 + + +namespace NumberTheoryLean.BoundedEdgePrimeRange +open ErdosCofactorChoices ErdosSubsetWord BoundedEdgeBins +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinEndpoints PrimeBinRepresentatives +open ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem bounded_edge_lower_exponent {w top xi M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (j : Fin (binCount w top xi)) + (hj : boundedEdgeBin w top xi Y m M X j) : leftExponent w (lower w top xi j) ≤ X := by + obtain ⟨f,hf,u,hfu,_hm,hx⟩ := hj + have hu : u ∈ globalBins w top xi j := ((mem_selections _ _ _).mp hf j).1 (by rw [hfu]; simp) + have hh := bin_exponent_bounds hw (endpoint_pos (zero_lt_one.trans hw) j.1) + (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le hu + exact hh.1.le.trans hx + +theorem bounded_edge_prime_range {w top xi M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (j : Fin (binCount w top xi)) + (hj : boundedEdgeBin w top xi Y m M X j) : + w ≤ lower w top xi j ∧ lower w top xi j ≤ w^X := by + refine ⟨(bin_source_bounds (zero_lt_one.trans hw) htop hxi j).1,?_⟩ + have hx := bounded_edge_lower_exponent hw htop hxi m j hj + have hh : Real.log (lower w top xi j) ≤ X*Real.log w := (div_le_iff₀ (Real.log_pos hw)).mp hx + apply (Real.log_le_log_iff (endpoint_pos (zero_lt_one.trans hw) j.1) (Real.rpow_pos_of_pos (zero_lt_one.trans hw) X)).mp + rwa [Real.log_rpow (zero_lt_one.trans hw)] +end NumberTheoryLean.BoundedEdgePrimeRange + + + +namespace NumberTheoryLean.BoundedEdgeHighPrimes +open ErdosSubsetWord ErdosCofactorChoices BoundedEdgeBins BoundedEdgePrimeRange +open LogarithmicBinScale LogarithmicBinLabels LogarithmicBinPartition LogarithmicBinEndpoints +open PrimeBinRepresentatives SourceLabelStrictOrder ErdosPrimeInputs.HarmonicPrimeMeasure + + +theorem bounded_edge_all_exponents {w top xi M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (j : Fin (binCount w top xi)) + (hj : boundedEdgeBin w top xi Y m M X j) {p : ℕ} + (hp : p ∈ globalBins w top xi j) : primeExponent w p ≤ X+xi/Real.log w := by + have hR : 0 < lower w top xi j := endpoint_pos (zero_lt_one.trans hw) j.1 + have he := (effectiveWidth_pos (zero_lt_one.trans hw) htop hxi).le + have hb := (bin_exponent_bounds hw hR he hp).2 + have hl := bounded_edge_lower_exponent hw htop hxi m j hj + have hwidth := bin_exponent_width (w:=w) hR he + have hlog : Real.log (1+effectiveWidth w top xi) ≤ xi := + (Real.log_le_sub_one_of_pos (by positivity)).trans (by + have hh := effectiveWidth_le (zero_lt_one.trans hw) htop hxi + linarith) + have hdiv := div_le_div_of_nonneg_right hlog (Real.log_pos hw).le + change primeExponent w p ≤ rightExponent w (lower w top xi j) (effectiveWidth w top xi) at hb + linarith + +theorem bounded_edge_descendant_exponent {w top xi M X : ℝ} {Y : ℕ} + (hw : 1 < w) (htop : w < top) (hxi : 0 < xi) + (m : Fin (binCount w top xi) → ℕ) (j k : Fin (binCount w top xi)) + (hj : boundedEdgeBin w top xi Y m M X j) (hkj : k ≤ j) {p : ℕ} + (hp : p ∈ globalBins w top xi k) : primeExponent w p ≤ X+xi/Real.log w := by + rcases hkj.eq_or_lt with heq | hlt + · subst k + exact bounded_edge_all_exponents hw htop hxi m j hj hp + · obtain ⟨f,hf,u,hfu,_hM,huX⟩ := hj + have hu : u ∈ globalBins w top xi j := ((mem_selections _ _ _).mp hf j).1 (by rw [hfu]; simp) + have hpS := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop p).mpr + (bin_prime_in_source (zero_lt_one.trans hw) htop hxi k hp) + have huS := (mem_sourcePrimeSet (zero_lt_one.trans hw) htop u).mpr + (bin_prime_in_source (zero_lt_one.trans hw) htop hxi j hu) + have hpl := ((bin_mem_iff_label (zero_lt_one.trans hw) htop hxi k p).mp hp).2.2.2 + have hul := ((bin_mem_iff_label (zero_lt_one.trans hw) htop hxi j u).mp hu).2.2.2 + have hpu := prime_lt_of_label_lt hw htop hxi hpS huS (by rwa [hpl,hul]) + have hp0 : (0:ℝ)