import Mathlib.NumberTheory.ArithmeticFunction.Miscimport Mathlib.NumberTheory.Harmonic.Boundsimport Mathlib.Analysis.SpecialFunctions.Log.Summableimport Mathlib.Analysis.SpecialFunctions.Pow.NNRealimport Mathlib.Analysis.Normed.Ring.InfiniteSumimport Mathlib.Analysis.PSeriesimport Mathlib.Tactic/-!# Unitary-primitive pairs with equal divisor sumsThe maximum-coordinate counting exponent for all coprime equal-divisor-sumpairs equals that for pairs admitting no nontrivial unitary divisor collision.Theorem `upper_exponents_equal` compares the upper counting exponents.Theorem `eventually_superpolylog_primitive` gives a uniform lower bound undera uniform near-quadratic hypothesis. Both work in any divisor-closed class ofintegers, including squarefree integers.-/namespace Erdos824Primitiveopen ArithmeticFunctiondef EqualPair (a b : ℕ) : Prop :=1 < a ∧ 1 < b ∧ a.Coprime b ∧ sigma 1 a = sigma 1 b/-- A nontrivial unitary divisor in each coordinate, with equal divisor sums. -/def Splits (a b : ℕ) : Prop :=∃ u v c d : ℕ, 1 < u ∧ 1 < v ∧ 1 < c ∧ 1 < d ∧ a = u*c ∧ b = v*d ∧u.Coprime c ∧ v.Coprime d ∧ sigma 1 u = sigma 1 vtheorem splits_iff_unitary_divisors (a b : ℕ) :Splits a b ↔ ∃ u v : ℕ, 1 < u ∧ u < a ∧ u ∣ a ∧ 1 < v ∧ v < b ∧ v ∣ b ∧u.Coprime (a/u) ∧ v.Coprime (b/v) ∧ sigma 1 u = sigma 1 v := byconstructor· rintro ⟨u, v, c, d, hu, hv, hc, hd, rfl, rfl, huc, hvd, hsig⟩refine ⟨u, v, hu, by nlinarith, dvd_mul_right _ _, hv, by nlinarith,dvd_mul_right _ _, ?_, ?_, hsig⟩· simpa [Nat.mul_div_cancel_left _ (by omega : 0 < u)] using huc· simpa [Nat.mul_div_cancel_left _ (by omega : 0 < v)] using hvd· rintro ⟨u, v, hu, hua, ⟨c, rfl⟩, hv, hvb, ⟨d, rfl⟩, huc, hvd, hsig⟩have hc : 1 < c := by by_contra! h; interval_cases c <;> simp_allhave hd : 1 < d := by by_contra! h; interval_cases d <;> simp_allrefine ⟨u, v, c, d, hu, hv, hc, hd, rfl, rfl, ?_, ?_, hsig⟩· simpa [Nat.mul_div_cancel_left _ (by omega : 0 < u)] using huc· simpa [Nat.mul_div_cancel_left _ (by omega : 0 < v)] using hvddef Primitive (p : ℕ × ℕ) : Prop :=EqualPair p.1 p.2 ∧ ¬ Splits p.1 p.2abbrev AtomFamily (A : ℕ → Prop) :={p : ℕ × ℕ // Primitive p ∧ A p.1 ∧ A p.2}abbrev PairFamily (A : ℕ → Prop) :={p : ℕ × ℕ // EqualPair p.1 p.2 ∧ A p.1 ∧ A p.2}theorem factorization (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u)(a b : ℕ) (hit : EqualPair a b) (ha : A a) (hb : A b) :∃ S : Finset (AtomFamily A), (∏ p ∈ S, p.val.1) = a ∧ (∏ p ∈ S, p.val.2) = b := byclassicalinduction a using Nat.strong_induction_on generalizing b with| h a ih =>by_cases hs : Splits a b· obtain ⟨u, v, c, d, hu, hv, hc, hd, rfl, rfl, huc, hvd, huv⟩ := hsobtain ⟨_, _, hcop, heq⟩ := hithave hcu : 0 < sigma 1 u := sigma_pos_iff.mpr (by omega)rw [isMultiplicative_sigma.map_mul_of_coprime huc,isMultiplicative_sigma.map_mul_of_coprime hvd, ← huv] at heqhave hcd : sigma 1 c = sigma 1 d := Nat.eq_of_mul_eq_mul_left hcu heqhave hu_lt : u < u*c := by nlinarithhave hc_lt : c < u*c := by nlinarithhave hu_dvd : u ∣ u*c := dvd_mul_right _ _have hv_dvd : v ∣ v*d := dvd_mul_right _ _have hc_dvd : c ∣ u*c := dvd_mul_left _ _have hd_dvd : d ∣ v*d := dvd_mul_left _ _obtain ⟨L, hL, hLp⟩ := ih u hu_lt v⟨hu, hv, Nat.Coprime.of_dvd hu_dvd hv_dvd hcop, huv⟩(closed hu_dvd ha) (closed hv_dvd hb)obtain ⟨R, hR, hRp⟩ := ih c hc_lt d⟨hc, hd, Nat.Coprime.of_dvd hc_dvd hd_dvd hcop, hcd⟩(closed hc_dvd ha) (closed hd_dvd hb)have hdis : Disjoint L R := byapply Finset.disjoint_left.mprintro p hpL hpRhave hpu := Finset.dvd_prod_of_mem (fun q : AtomFamily A ↦ q.val.1) hpLhave hpc := Finset.dvd_prod_of_mem (fun q : AtomFamily A ↦ q.val.1) hpRrw [hL] at hpurw [hR] at hpcexact p.property.1.1.1.ne' (Nat.eq_one_of_dvd_coprimes huc hpu hpc)exact ⟨L ∪ R, by rw [Finset.prod_union hdis, hL, hR],by rw [Finset.prod_union hdis, hLp, hRp]⟩· let q : AtomFamily A := ⟨(a,b), ⟨hit, hs⟩, ha, hb⟩exact ⟨{q}, by simp [q], by simp [q]⟩/-- The positive Dirichlet weight at exponent s, using the product of the two coordinates. -/noncomputable def weight (s : ℝ) (p : ℕ × ℕ) : ℝ := ((p.1 * p.2 : ℕ) : ℝ) ^ (-s)private theorem weight_prod (A : ℕ → Prop) (s : ℝ) (S : Finset (AtomFamily A)) :(∏ p ∈ S, weight s p.val) = weight s ((∏ p ∈ S, p.val.1), (∏ p ∈ S, p.val.2)) := byclassicalinduction S using Finset.induction_on with| empty => simp [weight]| insert p S hp ih =>simp only [Finset.prod_insert hp]rw [ih]simp only [weight, Nat.cast_mul]rw [← Real.mul_rpow (mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))(mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _))]congr 1ringprivate theorem representations (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u) :∃ rep : PairFamily A → Finset (AtomFamily A), Function.Injective rep ∧(∀ p, (∏ q ∈ rep p, q.val.1) = p.val.1) ∧ (∀ p, (∏ q ∈ rep p, q.val.2) = p.val.2) := byclassicalhave reps (p : PairFamily A) := factorization A closed p.val.1 p.val.2p.property.1 p.property.2.1 p.property.2.2choose rep hfst hsnd using repshave hinj : Function.Injective rep := byintro p q hpqapply Subtype.extapply Prod.ext· rw [← hfst p, hpq, hfst q]· rw [← hsnd p, hpq, hsnd q]exact ⟨rep, hinj, hfst, hsnd⟩set_option maxHeartbeats 600000 in/-- Primitive pairs and all admissible pairs have the same Dirichlet convergence set. -/theorem summable_iff_primitive (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u) (s : ℝ) :Summable (fun p : PairFamily A ↦ weight s p.val) ↔Summable (fun p : AtomFamily A ↦ weight s p.val) := byclassicalconstructor· intro hslet incl : AtomFamily A → PairFamily A := fun p ↦ ⟨p.val, p.property.1.1, p.property.2⟩have hi : Function.Injective incl := fun _ _ h ↦Subtype.ext (congrArg (fun q : PairFamily A ↦ q.val) h)have hiSum := hs.comp_injective hiexact hiSum· intro hsobtain ⟨rep, hinj, hfst, hsnd⟩ := representations A closedhave hn (p : AtomFamily A) : 0 ≤ weight s p.val := by unfold weight; positivityhave hh := (summable_finsetProd_of_summable_nonneg hn hs).comp_injective hinjapply hh.congrintro pchange (∏ q ∈ rep p, weight s q.val) = weight s p.valrw [weight_prod, hfst, hsnd]private theorem sigma_le (n : ℕ) :(sigma 1 n : ℝ) ≤ n * (1 + Real.log n) := bycalc(sigma 1 n : ℝ) = ∑ d ∈ n.divisors, (↑(n / d) : ℝ) := bysimp only [sigma_eq_sum_div, pow_one, Nat.cast_sum]_ = ∑ d ∈ n.divisors, (n : ℝ) * (d : ℝ)⁻¹ := byapply Finset.sum_congr rflintro d hdrw [Nat.cast_div (Nat.mem_divisors.mp hd).1 (by exact_mod_cast (Nat.pos_of_mem_divisors hd).ne'), div_eq_mul_inv]_ = n * (∑ d ∈ n.divisors, (d : ℝ)⁻¹) := (Finset.mul_sum ..).symm_ ≤ n * (harmonic n : ℝ) := byapply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg n)simp only [harmonic_eq_sum_Icc, Rat.cast_sum, Rat.cast_inv, Rat.cast_natCast]apply Finset.sum_le_sum_of_subset_of_nonneg _ (by intros; positivity)intro d hdexact Finset.mem_Icc.mpr ⟨Nat.pos_of_mem_divisors hd,Nat.le_of_dvd (Nat.pos_of_ne_zero (Nat.mem_divisors.mp hd).2) (Nat.mem_divisors.mp hd).1⟩_ ≤ n * (1 + Real.log n) := mul_le_mul_of_nonneg_left (harmonic_le_one_add_log n) (Nat.cast_nonneg _)private theorem self_le_sigma (n : ℕ) (hn : 0 < n) : n ≤ sigma 1 n := byrw [sigma_one_apply]exact Finset.single_le_sum (f := id) (fun _ _ ↦ Nat.zero_le _) (Nat.mem_divisors_self n hn.ne')/-- Converting between the maximum-coordinate and product cutoffs costs only a logarithm. -/theorem height_bound (a b : ℕ) (hit : EqualPair a b) :(max (a : ℝ) b)^2 ≤ (a*b : ℕ) * (1 + Real.log (max (a : ℝ) b)) := byobtain ⟨ha, hb, _, hsig⟩ := hithave aux (u v : ℕ) (hv : 0 < v) (hu : 0 < u) (huv : u ≤ v) (hσ : sigma 1 u = sigma 1 v) :(v : ℝ)^2 ≤ ((u*v : ℕ) : ℝ) * (1 + Real.log v) := byhave hlog := Real.log_le_log (by exact_mod_cast hu) (by exact_mod_cast huv : (u : ℝ) ≤ v)have h1 : (v : ℝ) ≤ (u : ℝ) * (1 + Real.log v) := bycalc (v : ℝ) ≤ sigma 1 v := by exact_mod_cast self_le_sigma v hv_ = (sigma 1 u : ℝ) := by rw [hσ]_ ≤ _ := (sigma_le u).trans (mul_le_mul_of_nonneg_left (by linarith) (Nat.cast_nonneg u))push_castnlinarith [mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg v)]rcases le_total a b with hab | hba· rw [max_eq_right (by exact_mod_cast hab)]exact aux a b (by omega) (by omega) hab hsig· rw [max_eq_left (by exact_mod_cast hba), Nat.mul_comm a b]exact aux b a (by omega) (by omega) hba hsig.symmnoncomputable def high (p : ℕ × ℕ) : ℝ := max (p.1 : ℝ) p.2private theorem high_weight_le (t : ℝ) (ht : 0 ≤ t) (p : ℕ × ℕ) (hp : EqualPair p.1 p.2) :high p ^ (-(2*t)) ≤ weight t p := bylet m := high phave hm : 0 < m := lt_of_lt_of_le (by exact_mod_cast (show 0 < p.1 by have := hp.1; omega))(le_max_left _ _)have hw : 0 < ((p.1*p.2 : ℕ) : ℝ) := byhave := hp.1; have := hp.2.1; exact_mod_cast Nat.mul_pos (by omega) (by omega)have hwm : ((p.1*p.2 : ℕ) : ℝ) ≤ m^2 := byrw [Nat.cast_mul, sq]; exact mul_le_mul (le_max_left _ _) (le_max_right _ _) (Nat.cast_nonneg _) hm.lechange m ^ (-(2*t)) ≤ _rw [show -(2*t) = 2 * (-t) by ring, Real.rpow_mul hm.le]simpa only [Real.rpow_two, weight] using Real.rpow_le_rpow_of_nonpos hw hwm (neg_nonpos.mpr ht)private theorem weight_domination (t r : ℝ) (ht : 0 < t) (hr : r < 2*t) :∃ C : ℝ, 0 < C ∧ ∀ p : ℕ × ℕ, EqualPair p.1 p.2 →weight t p ≤ C * high p ^ (-r) := bylet δ := (2*t-r)/thave hδ : 0 < δ := div_pos (sub_pos.mpr hr) htlet K := 1 + 1/δhave hK : 0 < K := by dsimp [K]; positivityrefine ⟨K^t, Real.rpow_pos_of_pos hK _, ?_⟩intro p hplet m := high plet w : ℝ := (p.1*p.2 : ℕ)have hm1 : 1 ≤ m := le_trans (by exact_mod_cast hp.1.le) (le_max_left _ _)have hm : 0 < m := zero_lt_one.trans_le hm1have hw : 0 < w := bydsimp [w]have := hp.1; have := hp.2.1; exact_mod_cast Nat.mul_pos (by omega) (by omega)have hδm : 1 ≤ m^δ := Real.one_le_rpow hm1 hδ.lehave hlog : 1 + Real.log m ≤ K * m^δ := bycalc 1 + Real.log m ≤ m^δ + m^δ / δ := add_le_add hδm (Real.log_le_rpow_div hm.le hδ)_ = K * m^δ := by dsimp [K]; ringhave hbound : m^(2-δ) ≤ w*K := byapply (mul_le_mul_iff_left₀ (Real.rpow_pos_of_pos hm δ)).mpcalc m^(2-δ) * m^δ = m^2 := by rw [← Real.rpow_add hm, sub_add_cancel, Real.rpow_two]_ ≤ w * (1 + Real.log m) := height_bound _ _ hp_ ≤ w * (K * m^δ) := mul_le_mul_of_nonneg_left hlog hw.le_ = _ := by ringhave hexp : (2-δ)*t = r := by dsimp [δ]; field_simp; ringhave hkey := Real.rpow_le_rpow (Real.rpow_nonneg hm.le _) hbound ht.lerw [← Real.rpow_mul hm.le, hexp, Real.mul_rpow hw.le hK.le] at hkeychange w^(-t) ≤ K^t * m^(-r)rw [Real.rpow_neg hw.le, Real.rpow_neg hm.le, ← div_eq_mul_inv, le_div_iff₀ (Real.rpow_pos_of_pos hm _)]rw [inv_mul_eq_div, div_le_iff₀ (Real.rpow_pos_of_pos hw _)]linarith only [hkey, mul_comm (w^t) (K^t)]/-- Convergence at one maximum-coordinate exponent for primitive pairs impliesconvergence at every larger positive exponent for all pairs. -/theorem high_summable_transfer (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u){r s : ℝ} (hs : 0 < s) (hrs : r < s)(h : Summable (fun p : AtomFamily A ↦ high p.val ^ (-r))) :Summable (fun p : PairFamily A ↦ high p.val ^ (-s)) := bylet t := s/2have ht : 0 < t := half_pos hshave htwo : 2*t = s := by dsimp [t]; ringobtain ⟨C, _, hC⟩ := weight_domination t r ht (by simpa only [htwo] using hrs)have hatom : Summable (fun p : AtomFamily A ↦ weight t p.val) :=(h.mul_left C).of_nonneg_of_le (by intro p; unfold weight; positivity)(fun p ↦ hC p.val p.property.1.1)have hall := (summable_iff_primitive A closed t).mpr hatomapply hall.of_nonneg_of_le· intro p; apply Real.rpow_nonneg; exact (Nat.cast_nonneg p.val.1).trans (le_max_left _ _)· intro p; simpa only [htwo] using high_weight_le t ht.le p.val p.property.1/-- Uniform polynomial bound on all finite subsets of a height cutoff. -/def PowerBound {ι : Type*} (M : ι → ℕ) (r : ℝ) : Prop :=∃ C : ℝ, 0 < C ∧ ∀ X : ℕ, 0 < X → ∀ T : Finset ι,(∀ p ∈ T, M p ≤ X) → (T.card : ℝ) ≤ C * (X : ℝ)^rtheorem powerBound_of_summable {ι : Type*} (M : ι → ℕ) (pos : ∀ p, 0 < M p){s : ℝ} (hs : 0 ≤ s) (h : Summable (fun p ↦ (M p : ℝ)^(-s))) : PowerBound M s := bylet C := max 1 (∑' p, (M p : ℝ)^(-s))refine ⟨C, zero_lt_one.trans_le (le_max_left _ _), ?_⟩intro X hX T hThave hx : 0 < (X : ℝ) := by exact_mod_cast hXhave bound : (T.card : ℝ) * (X : ℝ)^(-s) ≤ C := bycalc _ = ∑ _p ∈ T, (X : ℝ)^(-s) := by simp_ ≤ ∑ p ∈ T, (M p : ℝ)^(-s) := byapply Finset.sum_le_sumintro p hpexact Real.rpow_le_rpow_of_nonpos (by exact_mod_cast pos p) (by exact_mod_cast hT p hp) (by linarith)_ ≤ _ := (h.sum_le_tsum T (by intro i _; positivity)).trans (le_max_right _ _)rw [Real.rpow_neg hx.le, ← div_eq_mul_inv] at boundexact (div_le_iff₀ (Real.rpow_pos_of_pos hx _)).mp boundprivate lemma dyadic_rpow (k : ℕ) (r : ℝ) : ((2 : ℝ)^k)^r = ((2 : ℝ)^r)^k := byrw [← Real.rpow_natCast_mul (by norm_num), mul_comm, Real.rpow_mul_natCast (by norm_num)]theorem summable_of_powerBound {ι : Type*} (M : ι → ℕ) (pos : ∀ p, 0 < M p){r t : ℝ} (hr : 0 ≤ r) (hrt : r < t) (h : PowerBound M r) :Summable (fun p ↦ (M p : ℝ)^(-t)) := byclassicalobtain ⟨C, hC, hcount⟩ := hlet band (p : ι) := Nat.log 2 (M p)let q := (2 : ℝ)^(r-t)have hq : 0 < q := Real.rpow_pos_of_pos (by norm_num) _have hq1 : q < 1 := Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) (sub_neg.mpr hrt)have hseries : Summable (fun k : ℕ ↦ (C * (2 : ℝ)^r) * q^k) :=(summable_geometric_of_lt_one hq.le hq1).mul_left _apply summable_of_sum_le (c := ∑' k : ℕ, (C * (2 : ℝ)^r)*q^k) (by intro p; positivity)intro Scalc ∑ p ∈ S, (M p : ℝ)^(-t)= ∑ k ∈ S.image band, ∑ p ∈ S.filter (fun p ↦ band p = k), (M p : ℝ)^(-t) :=(Finset.sum_fiberwise_of_maps_to (fun p hp ↦ Finset.mem_image_of_mem band hp) _).symm_ ≤ ∑ k ∈ S.image band, (C * (2 : ℝ)^r)*q^k := byapply Finset.sum_le_sumintro k _let V := S.filter (fun p ↦ band p = k)have hk (p : ι) (hp : p ∈ V) : Nat.log 2 (M p) = k := (Finset.mem_filter.mp hp).2have hN := hcount (2^(k+1)) (by positivity) V (fun p hp ↦ byhave hlt := Nat.lt_pow_succ_log_self (by decide : 1 < 2) (M p)rw [hk p hp] at hltexact hlt.le)change ∑ p ∈ V, (M p : ℝ)^(-t) ≤ _calc ∑ p ∈ V, (M p : ℝ)^(-t) ≤ ∑ _p ∈ V, ((2 : ℝ)^k)^(-t) := byapply Finset.sum_le_sumintro p hphave hlow := Nat.pow_log_le_self 2 (pos p).ne'rw [hk p hp] at hlowexact Real.rpow_le_rpow_of_nonpos (by positivity) (by exact_mod_cast hlow) (by linarith)_ = (V.card : ℝ) * ((2 : ℝ)^k)^(-t) := by simp_ ≤ (C * ((2 : ℝ)^(k+1))^r) * ((2 : ℝ)^k)^(-t) :=mul_le_mul_of_nonneg_right (by exact_mod_cast hN) (by positivity)_ = _ := byrw [dyadic_rpow (k+1) r, dyadic_rpow k (-t), pow_succ]dsimp [q]rw [sub_eq_add_neg, Real.rpow_add (by norm_num : (0 : ℝ) < 2), mul_pow]ring_ ≤ _ := hseries.sum_le_tsum _ (by intro k _; positivity)def maxCoordinate (p : ℕ × ℕ) : ℕ := max p.1 p.2private theorem cast_maxCoordinate (p : ℕ × ℕ) : (maxCoordinate p : ℝ) = high p :=Nat.cast_max _ _private theorem maxCoordinate_pos {p : ℕ × ℕ} (h : EqualPair p.1 p.2) : 0 < maxCoordinate p :=(zero_lt_one.trans h.1).trans_le (le_max_left _ _)/-- A polynomial bound for primitive pairs gives every strictly weaker polynomialbound for all pairs. The cutoff is the maximum of the two coordinates. -/theorem powerBound_transfer (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u){r s : ℝ} (hr : 0 ≤ r) (hrs : r < s)(h : PowerBound (fun p : AtomFamily A ↦ maxCoordinate p.val) r) :PowerBound (fun p : PairFamily A ↦ maxCoordinate p.val) s := bylet t := (r+s)/2have hrt : r < t := by dsimp [t]; linarithhave hts : t < s := by dsimp [t]; linarithhave hA := summable_of_powerBound _ (fun p ↦ maxCoordinate_pos p.property.1.1) hr hrt hsimp only [cast_maxCoordinate] at hAhave hP := high_summable_transfer A closed (hr.trans_lt hrs) hts hAapply powerBound_of_summable _ (fun p ↦ maxCoordinate_pos p.property.1) (hr.trans hrs.le)simpa only [cast_maxCoordinate] using hP/-- The nonnegative upper counting exponents, expressed by uniform polynomialbounds at every strictly larger exponent, agree for primitive and all pairs. -/theorem upper_exponents_equal (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u) :{r : ℝ | 0 ≤ r ∧ ∀ s, r < s → PowerBound (fun p : PairFamily A ↦ maxCoordinate p.val) s} ={r : ℝ | 0 ≤ r ∧ ∀ s, r < s → PowerBound (fun p : AtomFamily A ↦ maxCoordinate p.val) s} := byclassicalext rconstructor· rintro ⟨hr, h⟩refine ⟨hr, fun s hs ↦ ?_⟩obtain ⟨C, hC, hc⟩ := h s hslet incl : AtomFamily A → PairFamily A := fun p ↦ ⟨p.val, p.property.1.1, p.property.2⟩have hi : Function.Injective incl := fun _ _ he ↦ Subtype.ext (congrArg (fun q : PairFamily A ↦ q.val) he)refine ⟨C, hC, ?_⟩intro X hX T hThave hinc (p : PairFamily A) (hp : p ∈ T.image incl) : maxCoordinate p.val ≤ X := byobtain ⟨a, ha, rfl⟩ := Finset.mem_image.mp hpexact hT a hasimpa only [Finset.card_image_of_injective _ hi] using hc X hX (T.image incl) hinc· rintro ⟨hr, h⟩refine ⟨hr, fun s hs ↦ ?_⟩let t := (r+s)/2have hrt : r < t := by dsimp [t]; linarithhave hts : t < s := by dsimp [t]; linarithexact powerBound_transfer A closed (hr.trans hrt.le) hts (h t hrt)/-- For either orientation there are at most (X+1)^2 pairs below a cutoff. -/private theorem cutoff_bound (A : ℕ → Prop) (T : Finset (AtomFamily A)) (X : ℕ)(hX : ∀ p ∈ T, maxCoordinate p.val ≤ X) : T.card ≤ (X+1)^2 := byclassicalhave hh : T.image Subtype.val ⊆ (Finset.range (X+1)) ×ˢ (Finset.range (X+1)) := byintro p hpobtain ⟨q, hq, rfl⟩ := Finset.mem_image.mp hphave hu := le_max_left q.val.1 q.val.2have hv := le_max_right q.val.1 q.val.2have h := hX q hqchange max q.val.1 q.val.2 ≤ X at hexact Finset.mem_product.mpr ⟨Finset.mem_range.mpr (by omega), Finset.mem_range.mpr (by omega)⟩simpa only [Finset.card_image_of_injective _ Subtype.coe_injective, Finset.card_product,Finset.card_range, sq] using Finset.card_le_card hh/-- If all coprime equal-divisor-sum pairs have no uniform polynomial bound atexponent s, then arbitrarily large maximum-coordinate cutoffs admit more thanX^r primitive pairs for each nonnegative r strictly below s. Both orientationsare counted. The result also applies inside any divisor-closed class A. -/theorem frequently_many_primitive (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u){r s : ℝ} (hr : 0 ≤ r) (hrs : r < s)(large : ¬ PowerBound (fun p : PairFamily A ↦ maxCoordinate p.val) s) (N : ℕ) :∃ X : ℕ, N ≤ X ∧ ∃ T : Finset (AtomFamily A),(∀ p ∈ T, maxCoordinate p.val ≤ X) ∧ (X : ℝ)^r < T.card := byclassicalby_contra! happly largeapply powerBound_transfer A closed hr hrslet C : ℝ := ((N+1 : ℕ) : ℝ)^2have hc : 1 ≤ C := by dsimp [C]; push_cast; nlinarith [Nat.cast_nonneg (α := ℝ) N, sq_nonneg (N : ℝ)]refine ⟨C, zero_lt_one.trans_le hc, ?_⟩intro X hX T hThave hx : 1 ≤ (X : ℝ)^r := Real.one_le_rpow (by exact_mod_cast hX) hrby_cases hn : N ≤ X· exact (h X hn T hT).trans (le_mul_of_one_le_left (zero_le_one.trans hx) hc)· have hh : (T.card : ℝ) ≤ C := bydsimp [C]exact_mod_cast (cutoff_bound A T X hT).trans (Nat.pow_le_pow_left (by omega : X+1 ≤ N+1) 2)exact hh.trans (le_mul_of_one_le_right (zero_le_one.trans hc) hx)private theorem primitive_high_series (A : ℕ → Prop) {t : ℝ} (ht : 1 < t) :Summable (fun p : AtomFamily A ↦ weight t p.val) := byhave hn := Real.summable_nat_rpow.mpr (by linarith : -t < -1)have hp := hn.mul_of_nonneg hn (fun i ↦ Real.rpow_nonneg (Nat.cast_nonneg i) _)(fun i ↦ Real.rpow_nonneg (Nat.cast_nonneg i) _)have hu := hp.comp_injective (Subtype.coe_injective (p := fun p : ℕ × ℕ ↦ Primitive p ∧ A p.1 ∧ A p.2))apply hu.congrintro psimp only [Function.comp_apply, weight, Nat.cast_mul, Real.mul_rpow (Nat.cast_nonneg _) (Nat.cast_nonneg _)]private theorem finite_weight_bound (A : ℕ → Prop) {s t : ℝ} (hs : 0 < s) (hst : s < t) (ht : 1 < t) :∃ C : ℝ, 0 < C ∧ ∀ S : Finset (AtomFamily A),∑ a ∈ S, weight s a.val ≤ C * (S.card : ℝ)^(t-s) := byclassicalhave hsum := primitive_high_series A htlet Z := ∑' a : AtomFamily A, weight t a.valhave hz : 0 ≤ Z := tsum_nonneg (fun a ↦ Real.rpow_nonneg (Nat.cast_nonneg _) _)refine ⟨Z+1, by linarith, ?_⟩intro Sby_cases hempty : S = ∅· subst S; simp [show t-s ≠ 0 by linarith]let n : ℝ := S.cardhave hn1 : 1 ≤ n := bydsimp [n]; exact_mod_cast (show 1 ≤ S.card from Finset.card_pos.mpr (Finset.nonempty_iff_ne_empty.mpr hempty))have hn : 0 < n := zero_lt_one.trans_le hn1have point (p : AtomFamily A) : weight s p.val ≤ n^(t-s)*weight t p.val + n^(-s) := bylet w : ℝ := (p.val.1 * p.val.2 : ℕ)have hw : 0 < w := bydsimp [w]; have h1 := p.property.1.1.1; have h2 := p.property.1.1.2.1exact_mod_cast Nat.mul_pos (by omega) (by omega)change w^(-s) ≤ n^(t-s) * w^(-t) + n^(-s)by_cases h : w ≤ n· have hfac : w^(-s) = w^(t-s)*w^(-t) := by rw [← Real.rpow_add hw]; congr 1; ringrw [hfac]apply le_trans (mul_le_mul_of_nonneg_right (Real.rpow_le_rpow hw.le h (by linarith)) (Real.rpow_nonneg hw.le _))exact le_add_of_nonneg_right (Real.rpow_nonneg hn.le _)· apply (Real.rpow_le_rpow_of_nonpos hn (le_of_not_ge h) (neg_nonpos.mpr hs.le)).transexact le_add_of_nonneg_left (mul_nonneg (Real.rpow_nonneg hn.le _) (Real.rpow_nonneg hw.le _))calc ∑ a ∈ S, weight s a.val ≤ ∑ a ∈ S, (n^(t-s)*weight t a.val + n^(-s)) :=Finset.sum_le_sum (fun a _ ↦ point a)_ = n^(t-s)*(∑ a ∈ S, weight t a.val) + n*n^(-s) := bysimp [Finset.sum_add_distrib, Finset.mul_sum, n]_ ≤ n^(t-s)*Z + n^(1-s) := byapply add_le_add· exact mul_le_mul_of_nonneg_left (hsum.sum_le_tsum _ (by intro a _; unfold weight; positivity)) (Real.rpow_nonneg hn.le _)· rw [sub_eq_add_neg, Real.rpow_add hn, Real.rpow_one]_ ≤ n^(t-s)*Z + n^(t-s) := add_le_add le_rfl (Real.rpow_le_rpow_of_exponent_le hn1 (show 1-s ≤ t-s by linarith))_ = _ := by change _ = (Z+1)*n^(t-s); ring/-- At each cutoff a sufficiently large collection of equal-sum pairs forcesmany primitive pairs at the very same cutoff. -/theorem finite_count_bound (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u){s t : ℝ} (hs : 0 < s) (hst : s < t) (ht : 1 < t) :∃ C : ℝ, 0 < C ∧ ∀ X : ℕ, 0 < X → ∀ T : Finset (PairFamily A),(∀ p ∈ T, maxCoordinate p.val ≤ X) → ∃ S : Finset (AtomFamily A),(∀ p ∈ S, maxCoordinate p.val ≤ X) ∧(T.card : ℝ) ≤ (X : ℝ)^(2*s) * Real.exp (C * (S.card : ℝ)^(t-s)) := byclassicalobtain ⟨C, hC, hsum⟩ := finite_weight_bound A hs hst htobtain ⟨rep, hinj, hfst, hsnd⟩ := representations A closedrefine ⟨C, hC, ?_⟩intro X hX T hTlet S := T.biUnion rephave hx : 0 < (X : ℝ) := by exact_mod_cast hXhave hn (p : AtomFamily A) : 0 ≤ weight s p.val := Real.rpow_nonneg (Nat.cast_nonneg _) _refine ⟨S, ?_, ?_⟩· intro p hpobtain ⟨q, hq, hpq⟩ := Finset.mem_biUnion.mp hphave hu := Finset.dvd_prod_of_mem (fun a : AtomFamily A ↦ a.val.1) hpqhave hv := Finset.dvd_prod_of_mem (fun a : AtomFamily A ↦ a.val.2) hpqrw [hfst] at hurw [hsnd] at hvhave h1 := q.property.1.1; have h2 := q.property.1.2.1exact (max_le_max (Nat.le_of_dvd (by omega) hu) (Nat.le_of_dvd (by omega) hv)).trans (hT q hq)· have hEuler : (T.card : ℝ) * (X : ℝ)^(-(2*s)) ≤ Real.exp (C*(S.card : ℝ)^(t-s)) := bycalc _ = ∑ _p ∈ T, (X : ℝ)^(-(2*s)) := by simp_ ≤ ∑ p ∈ T, weight s p.val := byapply Finset.sum_le_sumintro p hphave hm := maxCoordinate_pos p.property.1have hmR : 0 < high p.val := by rw [← cast_maxCoordinate]; exact_mod_cast hmapply (Real.rpow_le_rpow_of_nonpos hmR _ (by linarith : -(2*s) ≤ 0)).trans(high_weight_le s hs.le p.val p.property.1)rw [← cast_maxCoordinate]; exact_mod_cast hT p hp_ = ∑ R ∈ T.image rep, ∏ a ∈ R, weight s a.val := byrw [Finset.sum_image (fun _ _ _ _ h ↦ hinj h)]apply Finset.sum_congr rflintro p _rw [weight_prod, hfst, hsnd]_ ≤ ∑ R ∈ S.powerset, ∏ a ∈ R, weight s a.val := byapply Finset.sum_le_sum_of_subset_of_nonneg _ (by intro R _ _; exact Finset.prod_nonneg (fun a _ ↦ hn a))intro R hRobtain ⟨p, hp, rfl⟩ := Finset.mem_image.mp hRexact Finset.mem_powerset.mpr (Finset.subset_biUnion_of_mem rep hp)_ = ∏ a ∈ S, (1 + weight s a.val) := (Finset.prod_one_add _).symm_ ≤ Real.exp (∑ a ∈ S, weight s a.val) := Real.prod_one_add_le_exp_sum _ hn_ ≤ _ := Real.exp_le_exp.mpr (hsum S)rw [Real.rpow_neg hx.le, ← div_eq_mul_inv, div_le_iff₀ (Real.rpow_pos_of_pos hx _)] at hEulersimpa only [mul_comm] using hEuleropen Filter in/-- A near-quadratic lower bound at every large cutoff for all pairs givesmore than every fixed power of the logarithm in primitive pairs at everylarge cutoff. The hypothesis and conclusion use the same height. -/theorem eventually_superpolylog_primitive (A : ℕ → Prop) (closed : ∀ ⦃u n⦄, u ∣ n → A n → A u)(dense : ∀ ε : ℝ, 0 < ε → ∀ᶠ X : ℕ in atTop, ∃ T : Finset (PairFamily A),(∀ p ∈ T, maxCoordinate p.val ≤ X) ∧ (X : ℝ)^(2-ε) < T.card)(K : ℝ) (hK : 0 ≤ K) :∀ᶠ X : ℕ in atTop, ∃ S : Finset (AtomFamily A),(∀ p ∈ S, maxCoordinate p.val ≤ X) ∧ (Real.log X)^K < S.card := bylet δ := 1 / (4*(K+1))have hd : 0 < δ := by dsimp [δ]; positivityhave hd1 : δ < 1 := bydsimp [δ]; rw [div_lt_one (by positivity)]; linarithlet s := 1-δlet t := 1+δhave hs : 0 < s := by dsimp [s]; linarithhave hst : s < t := by dsimp [s,t]; linarithhave ht : 1 < t := by dsimp [t]; linarithhave hex : K*(t-s) ≤ 1/2 := bydsimp [s,t,δ]field_simplinarithobtain ⟨C,hC,hbound⟩ := finite_count_bound A closed hs hst hthave hlarge : Tendsto (fun X : ℕ ↦ Real.log (X : ℝ)) atTop atTop :=Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTopfilter_upwards [dense δ hd, hlarge.eventually_ge_atTop (max 1 ((C/δ)^2+1)), eventually_ge_atTop 1] with X hT hL hXobtain ⟨T, hm, hcard⟩ := hTobtain ⟨S, hS, hCS⟩ := hbound X hX T hmrefine ⟨S,hS,?_⟩let L := Real.log (X : ℝ)have hL1 : 1 ≤ L := (le_max_left _ _).trans hLhave hLpos : 0 < L := zero_lt_one.trans_le hL1have hLbig : (C/δ)^2 < L := byhave := (le_max_right _ _).trans hLdsimp [L]; linarithhave hsqrt := (Real.lt_sqrt (div_nonneg hC.le hd.le)).mpr hLbighave hroot : C < Real.sqrt L * δ := (div_lt_iff₀ hd).mp hsqrthave hsqrtpos := Real.sqrt_pos.mpr hLposhave hstrict : C * Real.sqrt L < δ*L := byhave h := mul_lt_mul_of_pos_right hroot hsqrtposnlinarith [Real.sq_sqrt hLpos.le]have hx : 0 < (X : ℝ) := by exact_mod_cast hXhave hlogs := Real.log_lt_log (Real.rpow_pos_of_pos hx _) (hcard.trans_le hCS)rw [Real.log_mul (Real.rpow_pos_of_pos hx _).ne' (Real.exp_pos _).ne',Real.log_rpow hx, Real.log_rpow hx, Real.log_exp] at hlogshave hgain : δ*L < C*(S.card : ℝ)^(t-s) := bydsimp [s,L] at hlogs ⊢linarithby_contra! hsmallhave hsml : (S.card : ℝ)^(t-s) ≤ Real.sqrt L := bycalc _ ≤ (L^K)^(t-s) := Real.rpow_le_rpow (Nat.cast_nonneg _) hsmall (sub_pos.mpr hst).le_ = L^(K*(t-s)) := (Real.rpow_mul hLpos.le _ _).symm_ ≤ L^(1/2 : ℝ) := Real.rpow_le_rpow_of_exponent_le hL1 hex_ = _ := (Real.sqrt_eq_rpow L).symmlinarith [mul_le_mul_of_nonneg_left hsml hC.le]#print axioms eventually_superpolylog_primitive#print axioms finite_count_bound#print axioms frequently_many_primitive#print axioms upper_exponents_equalend Erdos824Primitive