import Mathlib.Algebra.Order.Chebyshevimport Mathlib.NumberTheory.ArithmeticFunction.Miscimport Mathlib.Tacticnamespace Erdos824Fibersopen ArithmeticFunction/-- A prime complementary shift gives a squarefree semiprime at a prescribedcommon divisor sum. The exact deficit also locates the preimage. -/theorem complementary_shift {q p c M n : ℕ} (hq : q.Prime) (hp : p.Prime) (hqp : q<p)(hM : (q+1)*c=M) (hpv : p+1=c*n) :sigma 1 (q*p)=M*n ∧ Squarefree (q*p) ∧ M*n-q*p=q+p+1 := byhave hc := (Nat.coprime_primes hq hp).mpr hqp.nehave prime_sigma : ∀ {l : ℕ}, l.Prime → sigma 1 l=l+1 := byintro l hlsimpa [Finset.sum_range_succ,add_comm] using sigma_one_apply_prime_pow (i:=1) hlhave hprod : (q+1)*(p+1)=M*n := by rw [hpv,←Nat.mul_assoc,hM]refine ⟨?_,(Nat.squarefree_mul hc).mpr ⟨hq.squarefree,hp.squarefree⟩,?_⟩· simpa only [isMultiplicative_sigma.map_mul_of_coprime hc,prime_sigma hq,prime_sigma hp] using hprod· have hh : M*n=q*p+(q+p+1) := by rw [←hprod]; ringomega/-- If the mean degree is at least twice the threshold, large fibers carryenough mass that a second moment bounds their number from below. -/theorem many_heavy_fibers {ι : Type*} (S : Finset ι) (f : ι → ℕ) (H : ℕ)(hmean : 2*(S.card:ℝ)*H ≤ ∑ i ∈ S, (f i:ℝ)) :(∑ i ∈ S, (f i:ℝ))^2 ≤4*((S.filter (fun i ↦ H≤f i)).card:ℝ)*(∑ i ∈ S, (f i:ℝ)^2) := byclassicallet G := S.filter (fun i ↦ H≤f i)let B := S.filter (fun i ↦ ¬ H≤f i)have hsplit : (∑ i ∈ G, (f i:ℝ))+(∑ i ∈ B,(f i:ℝ))=∑ i ∈ S,(f i:ℝ) :=Finset.sum_filter_add_sum_filter_not _ _ _have blo : (∑ i ∈ B,(f i:ℝ)) ≤ (S.card:ℝ)*H := bycalc_ ≤ ∑ _i ∈ B,(H:ℝ) := byapply Finset.sum_le_sumintro i hihave h := (Finset.mem_filter.mp hi).2exact_mod_cast (show f i≤H by omega)_ = (B.card:ℝ)*H := by simp_ ≤ _ := byexact mul_le_mul_of_nonneg_right (by exact_mod_cast Finset.card_le_card (Finset.filter_subset _ S)) (by positivity)have hh : (∑ i ∈ S, (f i:ℝ)) ≤ 2*(∑ i ∈ G, (f i:ℝ)) := by linarithhave hsq := sq_sum_le_card_mul_sum_sq (s:=G) (f:=fun i ↦ (f i:ℝ))have hsub : (∑ i ∈ G,(f i:ℝ)^2) ≤ ∑ i ∈ S,(f i:ℝ)^2 :=Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ S) (by intros; positivity)change _ ≤ 4*(G.card:ℝ)*_calc_ ≤ (2*(∑ i ∈ G,(f i:ℝ)))^2 := pow_le_pow_left₀ (by positivity) hh 2_ = 4*(∑ i ∈ G,(f i:ℝ))^2 := by ring_ ≤ 4*((G.card:ℝ)*∑ i ∈ G,(f i:ℝ)^2) := by linarith_ ≤ _ := byconvert mul_le_mul_of_nonneg_left hsub (by positivity : 0≤4*(G.card:ℝ)) using 1 <;> ring#print axioms complementary_shift#print axioms many_heavy_fibersend Erdos824Fibers