import ManuscriptResidues import Mathlib.Algebra.BigOperators.Finprod namespace SieveInterface noncomputable section open scoped BigOperators open KKFiniteCoreDraft IncidenceMoments ManuscriptResidues /-- The real weight's actual function support is the literal finite incidence image. -/ theorem realWeight_support (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) : Function.support (realWeight X S Ω) = (support X S Ω : Set ℕ) := by ext t change realWeight X S Ω t ≠ 0 ↔ t ∈ support X S Ω constructor · intro ht by_contra hn exact ht (real_weight_zero_outside X S Ω t hn) · intro ht obtain ⟨n, hn, heq⟩ := Finset.mem_image.mp ht have hpos : 0 < weight X S Ω t := Finset.card_pos.mpr ⟨n, Finset.mem_filter.mpr ⟨hn, heq⟩⟩ have hr : (0 : ℝ) < realWeight X S Ω t := by change (0 : ℝ) < (weight X S Ω t : ℝ) exact_mod_cast hpos exact hr.ne' theorem realWeight_finite_support (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) : (Function.support (realWeight X S Ω)).Finite := by rw [realWeight_support] exact (support X S Ω).finite_toSet /-- Every predicate-restricted weight still has support inside the literal finite image. -/ theorem masked_support_subset (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (Q : ℕ → Prop) [DecidablePred Q] : Function.support (fun t => if Q t then realWeight X S Ω t else 0) ⊆ (support X S Ω : Set ℕ) := by intro t ht change (if Q t then realWeight X S Ω t else 0) ≠ 0 at ht by_contra hn have hz := real_weight_zero_outside X S Ω t hn apply ht simp only [hz, ite_self] theorem masked_finite_support (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (Q : ℕ → Prop) [DecidablePred Q] : (Function.support (fun t => if Q t then realWeight X S Ω t else 0)).Finite := (support X S Ω).finite_toSet.subset (masked_support_subset X S Ω Q) /-- The all-label finsum is proved equal to the checked finite sum, not assumed. -/ theorem finsum_predicate_eq_finite (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (Q : ℕ → Prop) [DecidablePred Q] : (∑ᶠ t : ℕ, if Q t then realWeight X S Ω t else 0) = ∑ t ∈ support X S Ω, if Q t then realWeight X S Ω t else 0 := finsum_eq_finsetSum_of_support_subset _ (masked_support_subset X S Ω Q) theorem finite_real_predicate_eq_cast (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (Q : ℕ → Prop) [DecidablePred Q] : (∑ t ∈ support X S Ω, if Q t then realWeight X S Ω t else 0) = ((∑ t ∈ support X S Ω, if Q t then weight X S Ω t else 0 : ℕ) : ℝ) := by rw [Nat.cast_sum] apply Finset.sum_congr rfl intro t _ split_ifs <;> simp [realWeight] /-- Full all-label pushforward identity for the actual counting weights. -/ theorem finsum_predicate_moment (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (Q : ℕ → Prop) [DecidablePred Q] : (∑ᶠ t : ℕ, if Q t then realWeight X S Ω t else 0) = (((interval X).filter (fun n => Q (incidence S Ω n))).card : ℝ) := by rw [finsum_predicate_eq_finite, finite_real_predicate_eq_cast, weight_predicate_moment] /-- Exact mass over all natural labels, with the original positive interval endpoint. -/ theorem total_mass (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) : (∑ᶠ t : ℕ, realWeight X S Ω t) = (X : ℝ) := by simpa [interval] using finsum_predicate_moment X S Ω (fun _ => True) theorem all_divisor_identity (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (d : ℕ) : (∑ᶠ t : ℕ, if d ∣ t then realWeight X S Ω t else 0) = (((Finset.Ioc 0 X).filter (fun n => d ∣ incidence S Ω n)).card : ℝ) := finsum_predicate_moment X S Ω (fun t => d ∣ t) /-- No spurious zero label contributes to the manuscript's positive-label weights. -/ theorem real_weight_at_zero (X : ℕ) (S : Finset ℕ) (hS : PrimeFamily S) (Ω : ℕ → Finset ℕ) : realWeight X S Ω 0 = 0 := by apply real_weight_zero_outside intro hz obtain ⟨n, _, heq⟩ := Finset.mem_image.mp hz exact DivisorMoments.divisor_nonzero S hS (incidence S Ω n) (incidence_dvd_period S Ω n) heq /-- Real remainder for all-label divisor sums over the actual real sqrt cutoff and eq15 sets. -/ theorem actual_all_divisor_remainder (X : ℕ) (y z0 z1 : ℝ) (d : ℕ) (hd : d ∣ period (paperPrimes y)) : |(∑ᶠ t : ℕ, if d ∣ t then realWeight X (paperPrimes y) (omegaSet z0 z1) t else 0) - ((X : ℝ) / d) * (DivisorMoments.localG (omegaSet z0 z1) d : ℝ)| ≤ (DivisorMoments.localG (omegaSet z0 z1) d : ℝ) := by rw [finsum_predicate_eq_finite] exact paper_real_moment X y z0 z1 d hd theorem finsum_sifted_interval (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (hS : PrimeFamily S) : (∑ᶠ t : ℕ, if Nat.Coprime t (period S) then realWeight X S Ω t else 0) = (((Finset.Ioc 0 X).filter (fun n => ∀ p ∈ S, n % p ∉ Ω p)).card : ℝ) := by rw [finsum_predicate_eq_finite, finite_real_predicate_eq_cast, sifted_moment X S Ω hS] simp only [interval] /-- Literal manuscript survivor count: all prime classes use ZMod membership. -/ def survivorCount (X : ℕ) (y z0 z1 : ℝ) : ℕ := ((Finset.Ioc 0 X).filter (fun n => ∀ p ∈ paperPrimes y, (n : ZMod p) ∉ paperSet z0 z1 p)).card /-- Equation (7)'s all-label sifted sum is exactly the actual manuscript survivor count. -/ theorem actual_all_sifted_count (X : ℕ) (y z0 z1 : ℝ) : (∑ᶠ t : ℕ, if Nat.Coprime t (period (paperPrimes y)) then realWeight X (paperPrimes y) (omegaSet z0 z1) t else 0) = (survivorCount X y z0 z1 : ℝ) := by have heq : ((Finset.Ioc 0 X).filter (fun n => ∀ p ∈ paperPrimes y, n % p ∉ omegaSet z0 z1 p)) = ((Finset.Ioc 0 X).filter (fun n => ∀ p ∈ paperPrimes y, (n : ZMod p) ∉ paperSet z0 z1 p)) := by ext n simp only [Finset.mem_filter] apply and_congr_right intro _ apply forall₂_congr intro p hp exact not_congr (omega_mem_iff_paper z0 z1 p ((mem_paperPrimes y p).mp hp).1 n) simpa only [heq, survivorCount] using finsum_sifted_interval X (paperPrimes y) (omegaSet z0 z1) (paperPrimeFamily y) #print axioms realWeight_support #print axioms realWeight_finite_support #print axioms masked_support_subset #print axioms masked_finite_support #print axioms finsum_predicate_eq_finite #print axioms finite_real_predicate_eq_cast #print axioms finsum_predicate_moment #print axioms total_mass #print axioms all_divisor_identity #print axioms real_weight_at_zero #print axioms actual_all_divisor_remainder #print axioms finsum_sifted_interval #print axioms actual_all_sifted_count end end SieveInterface