import Mathlib.NumberTheory.FactorisationProperties import Mathlib.NumberTheory.ArithmeticFunction.Misc /-! # Partial Machine-Checked Results for Erdős Problem #470 Formalizes verified partial theorems supporting our investigation of Erdős #470 (existence of odd weird numbers): 1. `weird_of_abundance_lt_min_prime` & `weird_of_odd_abundance_two`: If `n` is abundant with `2 ≤ δ(n) < p_min(n)` (in particular, `n` odd and `δ(n) = 2`), then `n` is weird. 2. `not_abundant_kravitz_base` & `not_weird_kravitz_base`: Kravitz-type `m * Q * R` obstruction: if `2 * m - σ(m) ≥ 2` and `R > Q > σ(m)` are primes coprime to `m`, then `m * Q * R` is deficient (hence not weird). 3. `not_abundant_odd_sqfree_omega_le_four` & `not_weird_odd_sqfree_omega_le_four`: Every odd squarefree `n` with `ω(n) ≤ 4` is not abundant (hence not weird). 4. `abundant_945`, `pseudoperfect_945`, `not_weird_945`: The smallest odd abundant number `945` is pseudoperfect, hence not weird. -/ open Finset namespace Erdos470Partial /-! ## 1. Sufficient condition for weirdness via small abundance -/ lemma sum_properDivisors_sdiff {n : ℕ} {s : Finset ℕ} (hs : s ⊆ n.properDivisors) (hsum : ∑ i ∈ s, i = n) : ∑ i ∈ (n.properDivisors \ s), i = (∑ i ∈ n.properDivisors, i) - n := by have h := Finset.sum_sdiff (f := fun i : ℕ => i) hs omega /-- If `n > 0` has abundance `δ = σ(n) - 2n` with `1 < δ` and every prime factor `p ∣ n` satisfies `δ < p`, then `n` is weird. -/ theorem weird_of_abundance_lt_min_prime {n δ : ℕ} (hn : 0 < n) (hδ : 1 < δ) (hmin : ∀ p, p.Prime → p ∣ n → δ < p) (hsum : ∑ i ∈ n.properDivisors, i = n + δ) : n.Weird := by refine ⟨?_, ?_⟩ · unfold Nat.Abundant omega · rintro ⟨_, s, hs, hsn⟩ set t := n.properDivisors \ s have htsum : ∑ i ∈ t, i = δ := by have h := sum_properDivisors_sdiff hs hsn change ∑ i ∈ (n.properDivisors \ s), i = δ omega have ht_sub : t ⊆ ({1} : Finset ℕ) := by intro d hd rw [Finset.mem_singleton] have hd_prop : d ∈ n.properDivisors := (Finset.mem_sdiff.mp hd).1 have hd_dvd : d ∣ n := (Nat.mem_properDivisors.mp hd_prop).1 have hd_pos : 0 < d := Nat.pos_of_ne_zero fun h => by subst h rw [zero_dvd_iff] at hd_dvd exact hn.ne' hd_dvd have hd_le : d ≤ δ := by calc d ≤ ∑ i ∈ t, i := Finset.single_le_sum (f := fun i : ℕ => i) (fun _ _ => Nat.zero_le _) hd _ = δ := htsum by_contra hd_ne_one have hp : d.minFac.Prime := Nat.minFac_prime hd_ne_one have hp_dvd : d.minFac ∣ n := (Nat.minFac_dvd d).trans hd_dvd have hδ_lt : δ < d.minFac := hmin d.minFac hp hp_dvd have hmf_le : d.minFac ≤ d := Nat.minFac_le hd_pos omega have hle1 : ∑ i ∈ t, i ≤ 1 := by calc ∑ i ∈ t, i ≤ ∑ i ∈ ({1} : Finset ℕ), i := Finset.sum_le_sum_of_subset_of_nonneg ht_sub (fun _ _ _ => Nat.zero_le _) _ = 1 := by simp omega /-- Any odd `n` with `σ(n) = 2n + 2` (i.e., abundance `2`) is weird. -/ theorem weird_of_odd_abundance_two {n : ℕ} (hodd : Odd n) (hsum : ∑ i ∈ n.properDivisors, i = n + 2) : n.Weird := by have hn : 0 < n := Nat.pos_of_ne_zero (by rintro rfl; simp at hodd) refine weird_of_abundance_lt_min_prime hn (by decide) ?_ hsum intro p hp hpn have hp2 : p ≠ 2 := by rintro rfl exact (Nat.not_odd_iff_even.mpr (even_iff_two_dvd.mpr hpn)) hodd have hp_ge2 : 2 ≤ p := hp.two_le omega /-! ## 2. Theorem 2: Obstruction to Kravitz-type `m * Q * R` constructions -/ /-- If `m ≥ 1` is deficient with `2 * m - σ(m) ≥ 2`, and `R > Q > σ(m)` are primes coprime to `m`, then `m * Q * R` is not abundant (in fact deficient). -/ theorem not_abundant_kravitz_base {m Q R : ℕ} (hm : 0 < m) (hdef : ∑ d ∈ m.divisors, d + 2 ≤ 2 * m) (hQ : Q.Prime) (hR : R.Prime) (hmQ : m.Coprime Q) (hmR : m.Coprime R) (hσQ : ∑ d ∈ m.divisors, d < Q) (hQR : Q < R) : ¬ (m * Q * R).Abundant := by have hQR_ne : Q ≠ R := hQR.ne have hQR_cop : Q.Coprime R := (Nat.coprime_primes hQ hR).mpr hQR_ne have hmQ_R : (m * Q).Coprime R := hmR.mul_left hQR_cop have hσ_mul : ∑ d ∈ (m * Q * R).divisors, d = (∑ d ∈ m.divisors, d) * (Q + 1) * (R + 1) := by rw [hmQ_R.sum_divisors_mul, hmQ.sum_divisors_mul, hR.sum_divisors, hQ.sum_divisors] have hN_pos : 0 < m * Q * R := Nat.mul_pos (Nat.mul_pos hm hQ.pos) hR.pos unfold Nat.Abundant rw [← Nat.add_lt_add_iff_right (k := m * Q * R), ← Nat.sum_divisors_eq_sum_properDivisors_add_self] rw [hσ_mul] set S := ∑ d ∈ m.divisors, d have hm_ge1 : 1 ≤ S := by have h1 : 1 ∈ m.divisors := Nat.one_mem_divisors.mpr hm.ne' exact Finset.single_le_sum (f := fun i : ℕ => i) (fun _ _ => Nat.zero_le _) h1 have hm_ge2 : 2 ≤ m := by omega have hm_le_S : m + 1 ≤ S := by have hsub : ({1, m} : Finset ℕ) ⊆ m.divisors := by intro x hx simp only [Finset.mem_insert, Finset.mem_singleton] at hx rcases hx with rfl | hxm · exact Nat.one_mem_divisors.mpr hm.ne' · rw [hxm]; exact Nat.mem_divisors.mpr ⟨dvd_refl m, hm.ne'⟩ have hne : (1 : ℕ) ≠ m := by omega calc m + 1 = ∑ x ∈ ({1, m} : Finset ℕ), x := by rw [Finset.sum_pair hne]; omega _ ≤ S := Finset.sum_le_sum_of_subset_of_nonneg hsub (fun _ _ _ => Nat.zero_le _) have hQ_ne2 : Q ≠ 2 := by omega have hR_ne2 : R ≠ 2 := by omega have hQ_odd : Q % 2 = 1 := (Nat.Prime.eq_two_or_odd hQ).resolve_left hQ_ne2 have hR_odd : R % 2 = 1 := (Nat.Prime.eq_two_or_odd hR).resolve_left hR_ne2 have hR_ge : Q + 2 ≤ R := by omega have h1 : S * (Q + 1) + Q < 2 * m * Q := by nlinarith have h2 : S * (Q + 1) < Q * R := by nlinarith nlinarith /-- Under the hypotheses of `not_abundant_kravitz_base`, `m * Q * R` is not weird. -/ theorem not_weird_kravitz_base {m Q R : ℕ} (hm : 0 < m) (hdef : ∑ d ∈ m.divisors, d + 2 ≤ 2 * m) (hQ : Q.Prime) (hR : R.Prime) (hmQ : m.Coprime Q) (hmR : m.Coprime R) (hσQ : ∑ d ∈ m.divisors, d < Q) (hQR : Q < R) : ¬ (m * Q * R).Weird := fun hw => not_abundant_kravitz_base hm hdef hQ hR hmQ hmR hσQ hQR hw.1 /-! ## 3. Theorem 1 (r ≤ 4): No odd squarefree number with `ω(n) ≤ 4` is abundant -/ private lemma sqfree_sum_divisors_eq_prod {n : ℕ} (hn : n ≠ 0) (hsq : Squarefree n) : ∑ d ∈ n.divisors, d = ∏ p ∈ n.primeFactors, (p + 1) := by rw [Nat.sum_divisors hn] refine Finset.prod_congr rfl fun p hp => ?_ have hfac : n.factorization p = 1 := by have hle := hsq.natFactorization_le_one p have hpos : 0 < n.factorization p := Nat.Prime.factorization_pos_of_dvd (Nat.prime_of_mem_primeFactors hp) hn (Nat.dvd_of_mem_primeFactors hp) omega rw [hfac] simp [Finset.sum_range_succ, add_comm] private lemma odd_prime_ge_13_of_not_mem {p : ℕ} (hp : p.Prime) (hodd : Odd p) (hnot : p ∉ ({3, 5, 7, 11} : Finset ℕ)) : 13 ≤ p := by simp only [Finset.mem_insert, Finset.mem_singleton, not_or] at hnot have hp2 : p ≠ 2 := by rintro rfl revert hodd decide have hp_ge2 : 2 ≤ p := hp.two_le have hne4 : p ≠ 4 := fun h => by subst h; revert hp; decide have hne6 : p ≠ 6 := fun h => by subst h; revert hp; decide have hne8 : p ≠ 8 := fun h => by subst h; revert hp; decide have hne9 : p ≠ 9 := fun h => by subst h; revert hp; decide have hne10 : p ≠ 10 := fun h => by subst h; revert hp; decide have hne12 : p ≠ 12 := fun h => by subst h; revert hp; decide omega private lemma prod_abundancy_odd_le_four {S : Finset ℕ} (hS_prime : ∀ p ∈ S, p.Prime) (hS_odd : ∀ p ∈ S, Odd p) (hS_card : S.card ≤ 4) : ∏ p ∈ S, ((p + 1 : ℚ) / p) < 2 := by set P₀ : Finset ℕ := {3, 5, 7, 11} have hP₀_card : P₀.card = 4 := by decide have hcard_split : (S ∩ P₀).card + (S \ P₀).card = S.card := Finset.card_inter_add_card_sdiff S P₀ have hcard_split2 : (P₀ ∩ S).card + (P₀ \ S).card = P₀.card := Finset.card_inter_add_card_sdiff P₀ S have hcard_le : (S \ P₀).card ≤ (P₀ \ S).card := by rw [Finset.inter_comm] at hcard_split2 omega have h1 : ∏ p ∈ S \ P₀, ((p + 1 : ℚ) / p) ≤ (12 / 11 : ℚ) ^ (S \ P₀).card := by calc ∏ p ∈ S \ P₀, ((p + 1 : ℚ) / p) ≤ ∏ _p ∈ S \ P₀, (12 / 11 : ℚ) := by refine Finset.prod_le_prod (fun p hp => by positivity) (fun p hp => ?_) have hp_mem : p ∈ S := (Finset.mem_sdiff.mp hp).1 have hp_not : p ∉ P₀ := (Finset.mem_sdiff.mp hp).2 have hp13 : 13 ≤ p := odd_prime_ge_13_of_not_mem (hS_prime p hp_mem) (hS_odd p hp_mem) hp_not have hpq : (13 : ℚ) ≤ (p : ℚ) := by exact_mod_cast hp13 rw [div_le_div_iff₀ (by positivity) (by positivity)] linarith _ = (12 / 11 : ℚ) ^ (S \ P₀).card := by rw [Finset.prod_const] have h2 : (12 / 11 : ℚ) ^ (S \ P₀).card ≤ (12 / 11 : ℚ) ^ (P₀ \ S).card := pow_le_pow_right₀ (by norm_num) hcard_le have h3 : (12 / 11 : ℚ) ^ (P₀ \ S).card ≤ ∏ p ∈ P₀ \ S, ((p + 1 : ℚ) / p) := by calc (12 / 11 : ℚ) ^ (P₀ \ S).card = ∏ _p ∈ P₀ \ S, (12 / 11 : ℚ) := by rw [Finset.prod_const] _ ≤ ∏ p ∈ P₀ \ S, ((p + 1 : ℚ) / p) := by refine Finset.prod_le_prod (fun _ _ => by norm_num) (fun p hp => ?_) have hp_mem : p ∈ P₀ := (Finset.mem_sdiff.mp hp).1 fin_cases hp_mem <;> norm_num have h_main : ∏ p ∈ S, ((p + 1 : ℚ) / p) ≤ ∏ p ∈ P₀, ((p + 1 : ℚ) / p) := by rw [← Finset.prod_inter_mul_prod_sdiff S P₀, ← Finset.prod_inter_mul_prod_sdiff P₀ S, Finset.inter_comm P₀ S] refine mul_le_mul_of_nonneg_left (h1.trans (h2.trans h3)) ?_ exact Finset.prod_nonneg (fun p _ => by positivity) have hP₀_val : ∏ p ∈ P₀, ((p + 1 : ℚ) / p) < 2 := by norm_num [P₀] exact h_main.trans_lt hP₀_val /-- Every odd squarefree `n` with `ω(n) ≤ 4` is not abundant. -/ theorem not_abundant_odd_sqfree_omega_le_four {n : ℕ} (hodd : Odd n) (hsq : Squarefree n) (hcard : n.primeFactors.card ≤ 4) : ¬ n.Abundant := by have hn0 : n ≠ 0 := by rintro rfl; simp at hodd have hσ : ∑ d ∈ n.divisors, d = ∏ p ∈ n.primeFactors, (p + 1) := sqfree_sum_divisors_eq_prod hn0 hsq have hn_prod : n = ∏ p ∈ n.primeFactors, p := (Nat.prod_primeFactors_of_squarefree hsq).symm have hS_prime : ∀ p ∈ n.primeFactors, p.Prime := fun _ hp => Nat.prime_of_mem_primeFactors hp have hS_odd : ∀ p ∈ n.primeFactors, Odd p := fun p hp => hodd.of_dvd_nat (Nat.dvd_of_mem_primeFactors hp) have hlt : ∏ p ∈ n.primeFactors, ((p + 1 : ℚ) / p) < 2 := prod_abundancy_odd_le_four hS_prime hS_odd hcard have hprod_pos : (0 : ℚ) < ∏ p ∈ n.primeFactors, (p : ℚ) := Finset.prod_pos fun p hp => by exact_mod_cast (hS_prime p hp).pos have hσ_rat : (∑ d ∈ n.divisors, (d : ℚ)) = ∏ p ∈ n.primeFactors, ((p : ℚ) + 1) := by have h : ((∑ d ∈ n.divisors, d : ℕ) : ℚ) = ((∏ p ∈ n.primeFactors, (p + 1) : ℕ) : ℚ) := by exact_mod_cast hσ simpa only [Nat.cast_sum, Nat.cast_prod, Nat.cast_add, Nat.cast_one] using h have hn_rat : (n : ℚ) = ∏ p ∈ n.primeFactors, (p : ℚ) := by have h : (n : ℚ) = ((∏ p ∈ n.primeFactors, p : ℕ) : ℚ) := by exact_mod_cast hn_prod simpa only [Nat.cast_prod] using h have hlt_mul : (∑ d ∈ n.divisors, (d : ℚ)) < 2 * (n : ℚ) := by calc (∑ d ∈ n.divisors, (d : ℚ)) = ∏ p ∈ n.primeFactors, ((p : ℚ) + 1) := hσ_rat _ = (∏ p ∈ n.primeFactors, ((p + 1 : ℚ) / p)) * (∏ p ∈ n.primeFactors, (p : ℚ)) := by rw [← Finset.prod_mul_distrib] refine Finset.prod_congr rfl fun p hp => ?_ have hp0 : (p : ℚ) ≠ 0 := by exact_mod_cast (hS_prime p hp).ne_zero rw [div_mul_cancel₀ _ hp0] _ < 2 * (∏ p ∈ n.primeFactors, (p : ℚ)) := mul_lt_mul_of_pos_right hlt hprod_pos _ = 2 * (n : ℚ) := by rw [← hn_rat] have hlt_nat : ∑ d ∈ n.divisors, d < 2 * n := by have h : ((∑ d ∈ n.divisors, d : ℕ) : ℚ) < ((2 * n : ℕ) : ℚ) := by simpa only [Nat.cast_sum, Nat.cast_mul, Nat.cast_ofNat] using hlt_mul exact_mod_cast h unfold Nat.Abundant rw [← Nat.add_lt_add_iff_right (k := n), ← Nat.sum_divisors_eq_sum_properDivisors_add_self] omega /-- Every odd squarefree `n` with `ω(n) ≤ 4` is not weird. -/ theorem not_weird_odd_sqfree_omega_le_four {n : ℕ} (hodd : Odd n) (hsq : Squarefree n) (hcard : n.primeFactors.card ≤ 4) : ¬ n.Weird := fun hw => not_abundant_odd_sqfree_omega_le_four hodd hsq hcard hw.1 /-! ## 4. Smallest odd abundant number 945 is pseudoperfect, hence not weird -/ theorem abundant_945 : Nat.Abundant 945 := by decide +kernel theorem pseudoperfect_945 : Nat.Pseudoperfect 945 := by refine ⟨by decide, ({1, 5, 7, 9, 15, 21, 35, 45, 63, 105, 135, 189, 315} : Finset ℕ), by decide, by decide⟩ theorem not_weird_945 : ¬ Nat.Weird 945 := fun hw => hw.2 pseudoperfect_945 /-! ## 5. Lemma 3: Odd Divisor Gap-Free Coverage -/ /-- Inductive gap-free coverage: if `d 0 = 1`, `d 1 = 3`, `d 2 = 5`, `d` is strictly increasing on `range m` (with `3 ≤ m`), and for every `3 ≤ k < m`, `d k ≤ S k - 2` and `d k ≠ S k - 4` (where `S k = ∑ i ∈ range k, d i`), then every `x ≤ S m` with `x ≠ 2` and `x ≠ S m - 2` is a subset sum of `(range m).image d`. -/ theorem odd_divisor_gap_free_coverage {d : ℕ → ℕ} {m : ℕ} (hm : 3 ≤ m) (hd0 : d 0 = 1) (hd1 : d 1 = 3) (hd2 : d 2 = 5) (hmono : ∀ i j, i < j → j < m → d i < d j) (hstep : ∀ k, 3 ≤ k → k < m → d k ≤ (∑ i ∈ Finset.range k, d i) - 2 ∧ d k ≠ (∑ i ∈ Finset.range k, d i) - 4) : ∀ x ≤ ∑ i ∈ Finset.range m, d i, x ≠ 2 → x ≠ (∑ i ∈ Finset.range m, d i) - 2 → ∃ s ⊆ (Finset.range m).image d, ∑ i ∈ s, i = x := by suffices h : ∀ k, 3 ≤ k → k ≤ m → 9 ≤ ∑ i ∈ Finset.range k, d i ∧ ∀ x ≤ ∑ i ∈ Finset.range k, d i, x ≠ 2 → x ≠ (∑ i ∈ Finset.range k, d i) - 2 → ∃ s ⊆ (Finset.range k).image d, ∑ i ∈ s, i = x from (h m hm le_rfl).2 intro k hk3 hkm induction k, hk3 using Nat.le_induction with | base => have hS3 : ∑ i ∈ Finset.range 3, d i = 9 := by simp [Finset.sum_range_succ, hd0, hd1, hd2] rw [hS3] refine ⟨le_rfl, fun x hx hne2 hne7 => ?_⟩ have hD3 : ({1, 3, 5} : Finset ℕ) ⊆ (Finset.range 3).image d := by intro y hy simp only [Finset.mem_insert, Finset.mem_singleton] at hy rcases hy with rfl | rfl | rfl · exact Finset.mem_image.mpr ⟨0, by decide, hd0⟩ · exact Finset.mem_image.mpr ⟨1, by decide, hd1⟩ · exact Finset.mem_image.mpr ⟨2, by decide, hd2⟩ rcases (by omega : x = 0 ∨ x = 1 ∨ x = 3 ∨ x = 4 ∨ x = 5 ∨ x = 6 ∨ x = 8 ∨ x = 9) with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl · exact ⟨∅, Finset.empty_subset _, by decide⟩ · exact ⟨{1}, Finset.Subset.trans (by decide) hD3, by decide⟩ · exact ⟨{3}, Finset.Subset.trans (by decide) hD3, by decide⟩ · exact ⟨{1, 3}, Finset.Subset.trans (by decide) hD3, by decide⟩ · exact ⟨{5}, Finset.Subset.trans (by decide) hD3, by decide⟩ · exact ⟨{1, 5}, Finset.Subset.trans (by decide) hD3, by decide⟩ · exact ⟨{3, 5}, Finset.Subset.trans (by decide) hD3, by decide⟩ · exact ⟨{1, 3, 5}, hD3, by decide⟩ | succ k hk3 ih => obtain ⟨hSk9, hIH⟩ := ih (Nat.le_of_succ_le hkm) have hkm_lt : k < m := hkm obtain ⟨hle, hne4⟩ := hstep k hk3 hkm_lt have hdk_ge5 : 5 ≤ d k := by have h2k : d 2 < d k := hmono 2 k (by omega) hkm_lt omega have hSk1 : ∑ i ∈ Finset.range (k + 1), d i = (∑ i ∈ Finset.range k, d i) + d k := Finset.sum_range_succ d k have hdk_not_mem : d k ∉ (Finset.range k).image d := by intro hmem rw [Finset.mem_image] at hmem obtain ⟨j, hj, hjd⟩ := hmem rw [Finset.mem_range] at hj have := hmono j k hj hkm_lt omega refine ⟨by omega, fun x hx hne2 hne_top => ?_⟩ rw [hSk1] at hx hne_top have hD_sub : (Finset.range k).image d ⊆ (Finset.range (k + 1)).image d := Finset.image_subset_image (Finset.range_mono (Nat.le_succ k)) have hdk_mem : d k ∈ (Finset.range (k + 1)).image d := Finset.mem_image.mpr ⟨k, Finset.mem_range.mpr (Nat.lt_succ_self k), rfl⟩ by_cases hx_le : x ≤ ∑ i ∈ Finset.range k, d i · by_cases hx_sub2 : x = (∑ i ∈ Finset.range k, d i) - 2 · set y := (∑ i ∈ Finset.range k, d i) - 2 - d k have hy_le : y ≤ ∑ i ∈ Finset.range k, d i := by omega have hy_ne2 : y ≠ 2 := by omega have hy_ne_top : y ≠ (∑ i ∈ Finset.range k, d i) - 2 := by omega obtain ⟨s, hs, hsum⟩ := hIH y hy_le hy_ne2 hy_ne_top have hdk_notin_s : d k ∉ s := fun h => hdk_not_mem (hs h) refine ⟨insert (d k) s, Finset.insert_subset_iff.mpr ⟨hdk_mem, hs.trans hD_sub⟩, ?_⟩ rw [Finset.sum_insert hdk_notin_s, hsum] omega · obtain ⟨s, hs, hsum⟩ := hIH x hx_le hne2 hx_sub2 exact ⟨s, hs.trans hD_sub, hsum⟩ · set y := x - d k have hy_le : y ≤ ∑ i ∈ Finset.range k, d i := by omega have hy_ne2 : y ≠ 2 := by omega have hy_ne_top : y ≠ (∑ i ∈ Finset.range k, d i) - 2 := by omega obtain ⟨s, hs, hsum⟩ := hIH y hy_le hy_ne2 hy_ne_top have hdk_notin_s : d k ∉ s := fun h => hdk_not_mem (hs h) refine ⟨insert (d k) s, Finset.insert_subset_iff.mpr ⟨hdk_mem, hs.trans hD_sub⟩, ?_⟩ rw [Finset.sum_insert hdk_notin_s, hsum] omega /-- Consequently, if `n` is abundant with `A(n) = (∑ i ∈ n.properDivisors, i) - n` covered by `(range m).image d ⊆ n.properDivisors` (with `A(n) ≤ S_m`, `A(n) ∉ {2, S_m - 2}`), then `n` is pseudoperfect, hence not weird. -/ theorem not_weird_of_gap_free_coverage {n : ℕ} {d : ℕ → ℕ} {m : ℕ} (hm : 3 ≤ m) (hsub : (Finset.range m).image d ⊆ n.properDivisors) (hd0 : d 0 = 1) (hd1 : d 1 = 3) (hd2 : d 2 = 5) (hmono : ∀ i j, i < j → j < m → d i < d j) (hstep : ∀ k, 3 ≤ k → k < m → d k ≤ (∑ i ∈ Finset.range k, d i) - 2 ∧ d k ≠ (∑ i ∈ Finset.range k, d i) - 4) (hab : n.Abundant) (hle : (∑ i ∈ n.properDivisors, i) - n ≤ ∑ i ∈ Finset.range m, d i) (hne2 : (∑ i ∈ n.properDivisors, i) - n ≠ 2) (hnetop : (∑ i ∈ n.properDivisors, i) - n ≠ (∑ i ∈ Finset.range m, d i) - 2) : ¬ n.Weird := by obtain ⟨s, hs, hsum⟩ := odd_divisor_gap_free_coverage hm hd0 hd1 hd2 hmono hstep ((∑ i ∈ n.properDivisors, i) - n) hle hne2 hnetop have hs_prop : s ⊆ n.properDivisors := hs.trans hsub have hcomp_sum : ∑ i ∈ (n.properDivisors \ s), i = n := by have h := Finset.sum_sdiff (f := fun i : ℕ => i) hs_prop unfold Nat.Abundant at hab omega have hpseudo : n.Pseudoperfect := ⟨hab.pos, n.properDivisors \ s, Finset.sdiff_subset, hcomp_sum⟩ exact fun hw => hw.2 hpseudo end Erdos470Partial