import FiniteCoreTargets import Mathlib.Tactic namespace IncidenceMoments open scoped BigOperators open KKFiniteCoreDraft /-- The exact incidence product D(n) in manuscript §4, equation (12). -/ def incidence (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (n : ℕ) : ℕ := ∏ p ∈ S.filter (fun p => n % p ∈ Ω p), p /-- The original positive interval, without auxiliary samples or axiomatic weights. -/ def interval (X : ℕ) : Finset ℕ := Finset.Ioc 0 X def support (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) : Finset ℕ := (interval X).image (incidence S Ω) def weight (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (t : ℕ) : ℕ := ((interval X).filter (fun n => incidence S Ω n = t)).card /-- Pushforward counting weights satisfy every predicate moment exactly. -/ theorem weight_predicate_moment (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (Q : ℕ → Prop) [DecidablePred Q] : (∑ t ∈ support X S Ω, if Q t then weight X S Ω t else 0) = ((interval X).filter (fun n => Q (incidence S Ω n))).card := by rw [← Finset.sum_filter] simp only [support, weight] rw [Finset.sum_card_fiberwise_eq_card_filter] congr 1 ext n simp only [Finset.mem_filter] constructor · rintro ⟨hn, _, hq⟩ exact ⟨hn, hq⟩ · rintro ⟨hn, hq⟩ exact ⟨hn, Finset.mem_image_of_mem _ hn, hq⟩ /-- Exact divisor moment from the manuscript's literal counting weights. -/ theorem divisor_moment (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (d : ℕ) : (∑ t ∈ support X S Ω, if d ∣ t then weight X S Ω t else 0) = ((interval X).filter (fun n => d ∣ incidence S Ω n)).card := weight_predicate_moment X S Ω (fun t => d ∣ t) /-- The weights vanish outside a finite, explicitly defined support. -/ theorem weight_eq_zero_of_not_mem (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (t : ℕ) (ht : t ∉ support X S Ω) : weight X S Ω t = 0 := by apply Finset.card_eq_zero.mpr apply Finset.eq_empty_iff_forall_notMem.mpr intro n hn obtain ⟨hn, heq⟩ := Finset.mem_filter.mp hn apply ht exact Finset.mem_image.mpr ⟨n, hn, heq⟩ /-- No sign assumption is imported: these real weights are cardinalities. -/ theorem weight_nonnegative (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (t : ℕ) : (0 : ℝ) ≤ weight X S Ω t := Nat.cast_nonneg _ /-- Incidence labels always divide the original prime product. -/ theorem incidence_dvd_period (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (n : ℕ) : incidence S Ω n ∣ period S := by exact Finset.prod_dvd_prod_of_subset _ _ _ (Finset.filter_subset _ _) theorem prime_dvd_incidence_iff (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (hS : PrimeFamily S) (p n : ℕ) (hp : p ∈ S) : p ∣ incidence S Ω n ↔ n % p ∈ Ω p := by rw [incidence, Prime.dvd_finsetProd_iff (Nat.prime_iff.mp (hS p hp))] constructor · rintro ⟨q, hq, hpq⟩ obtain ⟨hqS, hqΩ⟩ := Finset.mem_filter.mp hq have heq : p = q := (Nat.dvd_prime (hS q hqS)).mp hpq |>.resolve_left (hS p hp).ne_one simpa [heq] using hqΩ · intro h exact ⟨p, Finset.mem_filter.mpr ⟨hp, h⟩, dvd_rfl⟩ /-- Coprimality of D(n) with P is precisely absence of all forbidden hits. -/ theorem incidence_coprime_iff_survivor (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (hS : PrimeFamily S) (n : ℕ) : Nat.Coprime (incidence S Ω n) (period S) ↔ ∀ p ∈ S, n % p ∉ Ω p := by change Nat.Coprime (incidence S Ω n) (∏ p ∈ S, p) ↔ _ rw [Nat.coprime_prod_right_iff] apply forall₂_congr intro p hp rw [Nat.coprime_comm, (hS p hp).coprime_iff_not_dvd, prime_dvd_incidence_iff S Ω hS p n hp] /-- The sifted weighted sum is the actual interval survivor count. -/ theorem sifted_moment (X : ℕ) (S : Finset ℕ) (Ω : ℕ → Finset ℕ) (hS : PrimeFamily S) : (∑ t ∈ support X S Ω, if Nat.Coprime t (period S) then weight X S Ω t else 0) = ((interval X).filter (fun n => ∀ p ∈ S, n % p ∉ Ω p)).card := by rw [weight_predicate_moment] congr 1 ext n simp only [Finset.mem_filter, incidence_coprime_iff_survivor S Ω hS n] #print axioms weight_predicate_moment #print axioms divisor_moment #print axioms weight_eq_zero_of_not_mem #print axioms weight_nonnegative #print axioms incidence_dvd_period #print axioms prime_dvd_incidence_iff #print axioms incidence_coprime_iff_survivor #print axioms sifted_moment end IncidenceMoments