import Mathlib /-! # Exact Equivalence Between OEIS A215926 and the Non-Power-of-2 Almost-Perfect Number Conjecture Sources: - `FormalConjectures/OEIS/215926.lean` (`@[category research open, AMS 11]`, `conjecture_1` and `conjecture_2`) - `FormalConjectures/Wikipedia/AlmostPerfectNumbers.lean` (`@[category research open, question, AMS 11]`, `exists_almost_perfect_not_power_of_two`) ## Main Results Let `a(n)` be the smallest deficient number `k` such that `k * n` is non-deficient (perfect or abundant), and let `nextPrimeTwoPow m` be the smallest prime strictly greater than `2^m`. 1. **Exact Logical Equivalence** (`a215926_conjecture1_iff_no_nonpow2_almost_perfect`): `(∀ n ≥ 2, a n = 1 ∨ a n = 3 ∨ (a n).isPowerOfTwo)` `↔ ¬ ∃ k : ℕ, AlmostPerfect k ∧ ¬ ∃ r : ℕ, k = 2 ^ r`. - *(⇐)* If `2 ∣ n` then `6 ∣ 3n` gives `a(n) ≤ 3`; if `3 ∣ n` then `6 ∣ 2n` gives `a(n) ≤ 2`. For odd `n` and any deficient non-power-of-2 `k ≥ 5` with `2^r < k < 2^{r+1}`, absence of non-power-of-2 almost-perfect numbers forces `σ(k) ≤ 2k - 2`, whence `σ(k)/k ≤ 2 - 2/k < 2 - 1/2^r = σ(2^r)/2^r`. By submultiplicativity of `σ(·)/(·)` and coprimality `gcd(2^r, n) = 1`, `σ(kn)/(kn) < σ(2^r n)/(2^r n)`, so `2^r` always beats `k`. - *(⇒)* If a non-power-of-2 almost-perfect number exists, let `k` be the least one (`k ≥ 5`, `2^r < k < 2^{r+1}`). Every deficient `m < k` satisfies `σ(m)/m ≤ 2 - 1/2^r < 2 - 1/k = σ(k)/k`. Using Euler's divergence `∑_{p prime} 1/p = ∞` (`Nat.Primes.not_summable_one_div`), we build a squarefree product `n` of primes `> 2k` with `σ(n)/n ∈ [2k/(2k-1), 2^{r+1}/(2^{r+1}-1))`, forcing `a(n) = k ∉ {1, 3} ∪ {2^j}`. 2. **Unconditional Resolution of the Minimality & Upper-Bound Halves of `conjecture_2`**: - `a_nextPrimeTwoPow_le`: Unconditionally, for all `m ≥ 1`, `a (nextPrimeTwoPow m) ≤ 2 ^ m` (via Bertrand's postulate). - `a_ne_two_pow_of_lt_nextPrimeTwoPow`: Unconditionally, for all `m ≥ 1` and `2 ≤ n < nextPrimeTwoPow m`, `a n ≠ 2 ^ m` (via `σ(n) ≥ n + √n + 1` for composite odd `n ∈ (2^m, 2^{m+1})`). - `conjecture2_of_no_nonpow2_almost_perfect`: Absence of non-power-of-2 almost-perfect numbers implies full `OeisA215926.conjecture_2` for every `m ≥ 1`. -/ open scoped BigOperators ArithmeticFunction.sigma open Nat Finset namespace AutoDiscovery.A215926AlmostPerfect section Definitions /-- Verbatim from `FormalConjectures/Wikipedia/AlmostPerfectNumbers.lean`: A number is almost perfect if `1 + σ(n) = 2n`. -/ def AlmostPerfect (n : ℕ) : Prop := 1 + σ 1 n = 2 * n /-- Verbatim from `FormalConjectures/OEIS/215926.lean`: Smallest deficient number `k` such that `k * n` is non-deficient (perfect or abundant). -/ noncomputable def a (n : ℕ) : ℕ := sInf {k : ℕ | k.Deficient ∧ ((k * n).Perfect ∨ (k * n).Abundant)} /-- Verbatim from `FormalConjectures/OEIS/215926.lean`: The smallest prime strictly greater than `2^m` (OEIS A014210). -/ noncomputable def nextPrimeTwoPow (m : ℕ) : ℕ := sInf {p : ℕ | 2 ^ m < p ∧ p.Prime} /-- Shorthand for non-deficiency (perfect or abundant). -/ def NonDeficient (n : ℕ) : Prop := n.Perfect ∨ n.Abundant end Definitions section SigmaLemmas lemma sigma_one_eq_sum_divisors (n : ℕ) : σ 1 n = ∑ d ∈ n.divisors, d := by simp [ArithmeticFunction.sigma_apply] lemma sigma_one_eq_proper_add (n : ℕ) (_hn : 0 < n) : σ 1 n = (∑ d ∈ n.properDivisors, d) + n := by rw [sigma_one_eq_sum_divisors, ← Nat.sum_divisors_eq_sum_properDivisors_add_self] lemma deficient_iff_sigma {n : ℕ} : n.Deficient ↔ 0 < n ∧ σ 1 n < 2 * n := by unfold Nat.Deficient constructor · intro h have hpos : 0 < n := by by_contra h0 have hn0 : n = 0 := by omega subst hn0; simp at h refine ⟨hpos, ?_⟩ rw [sigma_one_eq_proper_add n hpos] omega · rintro ⟨hpos, hlt⟩ rw [sigma_one_eq_proper_add n hpos] at hlt omega lemma nonDeficient_iff_sigma {n : ℕ} : NonDeficient n ↔ 0 < n ∧ 2 * n ≤ σ 1 n := by unfold NonDeficient Nat.Perfect Nat.Abundant constructor · rintro (⟨heq, hpos⟩ | hgt) · refine ⟨hpos, ?_⟩ rw [sigma_one_eq_proper_add n hpos] omega · have hpos : 0 < n := by by_contra h0 have hn0 : n = 0 := by omega subst hn0; simp at hgt refine ⟨hpos, ?_⟩ rw [sigma_one_eq_proper_add n hpos] omega · rintro ⟨hpos, hge⟩ rw [sigma_one_eq_proper_add n hpos] at hge by_cases heq : ∑ i ∈ n.properDivisors, i = n · exact Or.inl ⟨heq, hpos⟩ · exact Or.inr (by omega) lemma almostPerfect_pos {k : ℕ} (hk : AlmostPerfect k) : 0 < k := by unfold AlmostPerfect at hk omega lemma almostPerfect_deficient {k : ℕ} (hk : AlmostPerfect k) : k.Deficient := by rw [deficient_iff_sigma] have hpos := almostPerfect_pos hk unfold AlmostPerfect at hk exact ⟨hpos, by omega⟩ /-- Submultiplicativity of `σ₁`: for all positive `x, y`, `σ₁(x * y) ≤ σ₁(x) * σ₁(y)`. -/ lemma sigma_one_mul_le (x y : ℕ) (hx : 0 < x) (hy : 0 < y) : σ 1 (x * y) ≤ σ 1 x * σ 1 y := by rw [sigma_one_eq_sum_divisors, sigma_one_eq_sum_divisors, sigma_one_eq_sum_divisors] have hsub : (x * y).divisors ⊆ (x.divisors ×ˢ y.divisors).image (fun p => p.1 * p.2) := by intro d hd rw [Nat.mem_divisors] at hd obtain ⟨d₁, d₂, hd₁, hd₂, rfl⟩ := Nat.dvd_mul.mp hd.1 exact Finset.mem_image.mpr ⟨(d₁, d₂), Finset.mem_product.mpr ⟨Nat.mem_divisors.mpr ⟨hd₁, hx.ne'⟩, Nat.mem_divisors.mpr ⟨hd₂, hy.ne'⟩⟩, rfl⟩ calc ∑ d ∈ (x * y).divisors, d ≤ ∑ d ∈ (x.divisors ×ˢ y.divisors).image (fun p => p.1 * p.2), d := Finset.sum_le_sum_of_subset hsub _ ≤ ∑ p ∈ x.divisors ×ˢ y.divisors, p.1 * p.2 := Finset.sum_image_le_of_nonneg (fun _ _ => Nat.zero_le _) _ = (∑ d₁ ∈ x.divisors, d₁) * (∑ d₂ ∈ y.divisors, d₂) := by rw [Finset.sum_product, Finset.sum_mul] refine Finset.sum_congr rfl fun d₁ _ => ?_ rw [Finset.mul_sum] /-- Multiplicativity of `σ₁` on coprime inputs. -/ lemma sigma_one_mul_coprime {x y : ℕ} (h : Nat.Coprime x y) : σ 1 (x * y) = σ 1 x * σ 1 y := ArithmeticFunction.isMultiplicative_sigma.map_mul_of_coprime h /-- `σ₁(2^r) = 2^{r+1} - 1`. -/ lemma sigma_one_two_pow (r : ℕ) : σ 1 (2 ^ r) = 2 ^ (r + 1) - 1 := by rw [sigma_one_eq_sum_divisors, Nat.divisors_prime_pow Nat.prime_two] rw [Finset.sum_map] simp only [Function.Embedding.coeFn_mk] have hgeom : (∑ i ∈ Finset.range (r + 1), 2 ^ i) + 1 = 2 ^ (r + 1) := by induction r with | zero => simp | succ k ih => rw [Finset.sum_range_succ] have : 2 ^ (k + 1 + 1) = 2 ^ (k + 1) + 2 ^ (k + 1) := by ring omega omega lemma two_pow_deficient (r : ℕ) : (2 ^ r).Deficient := by rw [deficient_iff_sigma, sigma_one_two_pow] have hpos : 0 < 2 ^ r := by positivity have h2 : 2 ^ (r + 1) = 2 * 2 ^ r := by ring omega lemma one_deficient : (1 : ℕ).Deficient := by simpa using two_pow_deficient 0 lemma three_deficient : (3 : ℕ).Deficient := by rw [deficient_iff_sigma] refine ⟨by norm_num, ?_⟩ rw [sigma_one_eq_sum_divisors] decide /-- Every positive multiple of a non-deficient number is non-deficient. -/ lemma nonDeficient_mul_of_nonDeficient {x y : ℕ} (hx : NonDeficient x) (hy : 0 < y) : NonDeficient (x * y) := by rw [nonDeficient_iff_sigma] at hx ⊢ obtain ⟨hxpos, hsig⟩ := hx refine ⟨Nat.mul_pos hxpos hy, ?_⟩ -- Injection `d ↦ d * y` from `x.divisors` into `(x * y).divisors`. have hle : σ 1 x * y ≤ σ 1 (x * y) := by rw [sigma_one_eq_sum_divisors, sigma_one_eq_sum_divisors] rw [Finset.sum_mul] have hsub : x.divisors.image (· * y) ⊆ (x * y).divisors := by intro z hz rcases Finset.mem_image.mp hz with ⟨d, hd, rfl⟩ rw [Nat.mem_divisors] at hd ⊢ exact ⟨mul_dvd_mul_right hd.1 y, (Nat.mul_pos hxpos hy).ne'⟩ calc ∑ d ∈ x.divisors, d * y = ∑ z ∈ x.divisors.image (· * y), z := by symm exact Finset.sum_image fun a _ b _ hab => Nat.eq_of_mul_eq_mul_right hy hab _ ≤ ∑ z ∈ (x * y).divisors, z := Finset.sum_le_sum_of_subset hsub calc 2 * (x * y) = (2 * x) * y := by ring _ ≤ σ 1 x * y := Nat.mul_le_mul_right y hsig _ ≤ σ 1 (x * y) := hle lemma six_nonDeficient : NonDeficient 6 := by rw [nonDeficient_iff_sigma] refine ⟨by norm_num, ?_⟩ rw [sigma_one_eq_sum_divisors] decide lemma sigma_one_ge_add_one {n : ℕ} (hn : 2 ≤ n) : n + 1 ≤ σ 1 n := by rw [sigma_one_eq_sum_divisors] have hsub : ({1, n} : Finset ℕ) ⊆ n.divisors := by intro d hd simp only [Finset.mem_insert, Finset.mem_singleton] at hd rw [Nat.mem_divisors] rcases hd with rfl | rfl · exact ⟨one_dvd n, by omega⟩ · exact ⟨dvd_refl d, by omega⟩ have hsum : ∑ d ∈ ({1, n} : Finset ℕ), d = n + 1 := by rw [Finset.sum_pair (by omega)]; omega rw [← hsum] exact Finset.sum_le_sum_of_subset hsub lemma sigma_one_prime {p : ℕ} (hp : p.Prime) : σ 1 p = p + 1 := by rw [sigma_one_eq_sum_divisors, hp.divisors, Finset.sum_pair hp.ne_one.symm] omega /-- For every `n ≥ 2`, the set of deficient multipliers making `k * n` non-deficient is nonempty. -/ lemma multiplier_set_nonempty {n : ℕ} (hn : 2 ≤ n) : {k : ℕ | k.Deficient ∧ NonDeficient (k * n)}.Nonempty := by by_cases h2 : 2 ∣ n · obtain ⟨m, rfl⟩ := h2 have hm : 0 < m := by omega refine ⟨3, three_deficient, ?_⟩ have heq : 3 * (2 * m) = 6 * m := by ring rw [heq] exact nonDeficient_mul_of_nonDeficient six_nonDeficient hm · -- `n` is odd: pick `r` with `n < 2 ^ (r + 1)` (e.g. `r = n`). refine ⟨2 ^ n, two_pow_deficient n, ?_⟩ rw [nonDeficient_iff_sigma] have hcop : Nat.Coprime (2 ^ n) n := Nat.Coprime.pow_left n (Nat.prime_two.coprime_iff_not_dvd.mpr h2) have hpow : n < 2 ^ (n + 1) := lt_trans (Nat.lt_two_pow_self) (by have : 2 ^ n < 2 ^ (n + 1) := Nat.pow_lt_pow_right (by norm_num) (by omega) exact this) refine ⟨Nat.mul_pos (by positivity) (by omega), ?_⟩ rw [sigma_one_mul_coprime hcop, sigma_one_two_pow] have hsig_n : n + 1 ≤ σ 1 n := sigma_one_ge_add_one hn have h1 : (2 ^ (n + 1) - 1) * (n + 1) ≤ (2 ^ (n + 1) - 1) * σ 1 n := Nat.mul_le_mul_left _ hsig_n have h2pow : 2 ^ (n + 1) = 2 * 2 ^ n := by ring have hpos2 : 1 ≤ 2 ^ (n + 1) := Nat.one_le_pow _ _ (by norm_num) zify [hpos2] at h1 ⊢ nlinarith lemma a_mem {n : ℕ} (hn : 2 ≤ n) : (a n).Deficient ∧ NonDeficient (a n * n) := Nat.sInf_mem (multiplier_set_nonempty hn) lemma a_le_of_mem {n k : ℕ} (hk : k.Deficient) (hkn : NonDeficient (k * n)) : a n ≤ k := Nat.sInf_le ⟨hk, hkn⟩ lemma a_le_three_of_even {n : ℕ} (hn : 2 ≤ n) (h2 : 2 ∣ n) : a n ≤ 3 := by obtain ⟨m, rfl⟩ := h2 refine a_le_of_mem three_deficient ?_ have heq : 3 * (2 * m) = 6 * m := by ring rw [heq] exact nonDeficient_mul_of_nonDeficient six_nonDeficient (by omega) lemma a_le_two_of_dvd_three {n : ℕ} (hn : 2 ≤ n) (h3 : 3 ∣ n) : a n ≤ 2 := by obtain ⟨m, rfl⟩ := h3 refine a_le_of_mem (by simpa using two_pow_deficient 1) ?_ have heq : 2 * (3 * m) = 6 * m := by ring rw [heq] exact nonDeficient_mul_of_nonDeficient six_nonDeficient (by omega) lemma isPowerOfTwo_iff_exists (k : ℕ) : k.isPowerOfTwo ↔ ∃ r : ℕ, k = 2 ^ r := by unfold Nat.isPowerOfTwo exact Iff.rfl end SigmaLemmas section BackwardDirection /-- If there is no non-power-of-2 almost-perfect number, then `OeisA215926.conjecture_1` holds: for every `n ≥ 2`, `a n = 1 ∨ a n = 3 ∨ (a n).isPowerOfTwo`. -/ theorem conjecture1_of_no_nonpow2_almost_perfect (hno : ¬ ∃ k : ℕ, AlmostPerfect k ∧ ¬ ∃ r : ℕ, k = 2 ^ r) (n : ℕ) (hn : 2 ≤ n) : a n = 1 ∨ a n = 3 ∨ (a n).isPowerOfTwo := by have ⟨hk_def, hk_nd⟩ := a_mem hn have hk_pos : 0 < a n := (deficient_iff_sigma.mp hk_def).1 by_cases h2 : 2 ∣ n · have hle3 := a_le_three_of_even hn h2 have hcases : a n = 1 ∨ a n = 2 ∨ a n = 3 := by omega rcases hcases with h | h | h · exact Or.inl h · exact Or.inr (Or.inr (by rw [h, isPowerOfTwo_iff_exists]; exact ⟨1, rfl⟩)) · exact Or.inr (Or.inl h) · by_cases h3 : 3 ∣ n · have hle2 := a_le_two_of_dvd_three hn h3 have hcases : a n = 1 ∨ a n = 2 := by omega rcases hcases with h | h · exact Or.inl h · exact Or.inr (Or.inr (by rw [h, isPowerOfTwo_iff_exists]; exact ⟨1, rfl⟩)) · -- `n` is odd and not divisible by 3. Show `a n` MUST be a power of 2! by_contra hnot push Not at hnot obtain ⟨hne1, hne3, hnotpow⟩ := hnot have hnot_ex : ¬ ∃ r : ℕ, a n = 2 ^ r := (isPowerOfTwo_iff_exists (a n)).not.mp hnotpow -- Since `a n` is not a power of 2, `a n` is not almost perfect. have hnot_ap : ¬ AlmostPerfect (a n) := fun hap => hno ⟨a n, hap, hnot_ex⟩ have hsig_k : σ 1 (a n) + 2 ≤ 2 * a n := by have hlt := (deficient_iff_sigma.mp hk_def).2 unfold AlmostPerfect at hnot_ap omega -- Let `r = Nat.log 2 (a n)`: since `a n` is not a power of 2, `2 ^ r < a n < 2 ^ (r + 1)`. let k := a n let r := Nat.log 2 k have hr_le : 2 ^ r ≤ k := Nat.pow_log_le_self 2 hk_pos.ne' have hr_lt : 2 ^ r < k := lt_of_le_of_ne hr_le fun h => hnot_ex ⟨r, h.symm⟩ have hk_lt : k < 2 ^ (r + 1) := Nat.lt_pow_succ_log_self (by norm_num) k -- Key inequality: `σ₁(k) * 2^r < k * (2^{r+1} - 1)`. have hkey : σ 1 k * 2 ^ r < k * (2 ^ (r + 1) - 1) := by have h2pow : 2 ^ (r + 1) = 2 * 2 ^ r := by ring have hpos1 : 1 ≤ 2 ^ (r + 1) := Nat.one_le_pow _ _ (by norm_num) zify [hpos1] have hsig_z : (σ 1 k : ℤ) + 2 ≤ 2 * (k : ℤ) := by exact_mod_cast hsig_k have hk_z : (k : ℤ) < (2 ^ (r + 1) : ℤ) := by exact_mod_cast hk_lt have h2p_z : (2 ^ (r + 1) : ℤ) = 2 * (2 ^ r : ℤ) := by exact_mod_cast h2pow nlinarith -- Now show `2^r * n` is non-deficient, contradicting `a n = k > 2^r`! have h2rn_nd : NonDeficient (2 ^ r * n) := by rw [nonDeficient_iff_sigma] refine ⟨Nat.mul_pos (by positivity) (by omega), ?_⟩ have hcop : Nat.Coprime (2 ^ r) n := Nat.Coprime.pow_left r (Nat.prime_two.coprime_iff_not_dvd.mpr h2) rw [sigma_one_mul_coprime hcop, sigma_one_two_pow] have hkn_sig : 2 * (k * n) ≤ σ 1 (k * n) := (nonDeficient_iff_sigma.mp hk_nd).2 have hsubmul : σ 1 (k * n) ≤ σ 1 k * σ 1 n := sigma_one_mul_le k n hk_pos (by omega) have hsig_n_pos : 0 < σ 1 n := by have := sigma_one_ge_add_one hn; omega have h1 : 2 * (k * n) * 2 ^ r ≤ σ 1 k * σ 1 n * 2 ^ r := Nat.mul_le_mul_right (2 ^ r) (le_trans hkn_sig hsubmul) have h2_ineq : σ 1 k * 2 ^ r * σ 1 n < k * (2 ^ (r + 1) - 1) * σ 1 n := Nat.mul_lt_mul_of_pos_right hkey hsig_n_pos have h3_ineq : k * (2 * (2 ^ r * n)) < k * ((2 ^ (r + 1) - 1) * σ 1 n) := by calc k * (2 * (2 ^ r * n)) = 2 * (k * n) * 2 ^ r := by ring _ ≤ σ 1 k * σ 1 n * 2 ^ r := h1 _ = σ 1 k * 2 ^ r * σ 1 n := by ring _ < k * (2 ^ (r + 1) - 1) * σ 1 n := h2_ineq _ = k * ((2 ^ (r + 1) - 1) * σ 1 n) := by ring exact le_of_lt (Nat.lt_of_mul_lt_mul_left h3_ineq) have hle_r : a n ≤ 2 ^ r := a_le_of_mem (two_pow_deficient r) h2rn_nd omega end BackwardDirection section ForwardDirection /-- Partial sums of `1 / p` over primes `> M` are unbounded above (from Euler's divergence `Nat.Primes.not_summable_one_div`). -/ lemma exists_finset_primes_gt_sum_ge (M : ℕ) (L : ℝ) : ∃ Q : Finset ℕ, (∀ p ∈ Q, p.Prime ∧ M < p) ∧ L ≤ ∑ p ∈ Q, (1 : ℝ) / (p : ℝ) := by by_contra hnot push Not at hnot -- Then `fun p : Nat.Primes => (1 : ℝ) / (p : ℝ)` is summable! -- First, the tail `{p : Nat.Primes | M < p}` has all finite partial sums bounded by `L`. have hsum_tail : Summable (fun p : Nat.Primes => if M < (p : ℕ) then (1 : ℝ) / (p : ℝ) else 0) := by refine summable_of_sum_le (c := max L 0) (fun p => by split_ifs <;> positivity) ?_ intro s let Q : Finset ℕ := (s.filter (fun p : Nat.Primes => M < (p : ℕ))).image Subtype.val have hQ : ∀ q ∈ Q, q.Prime ∧ M < q := by intro q hq rcases Finset.mem_image.mp hq with ⟨p, hp, rfl⟩ exact ⟨p.prop, (Finset.mem_filter.mp hp).2⟩ have hsum_eq : ∑ p ∈ s, (if M < (p : ℕ) then (1 : ℝ) / (p : ℝ) else 0) = ∑ q ∈ Q, (1 : ℝ) / (q : ℝ) := by rw [← Finset.sum_filter] symm exact Finset.sum_image fun a _ b _ hab => Subtype.ext hab rw [hsum_eq] exact le_trans (le_of_lt (hnot Q hQ)) (le_max_left L 0) -- The remaining finite set `{p : Nat.Primes | (p : ℕ) ≤ M}` is trivially summable! have hfin_supp : (Function.support (fun p : Nat.Primes => if (p : ℕ) ≤ M then (1 : ℝ) / (p : ℝ) else 0)).Finite := by refine Set.Finite.subset ((Set.finite_Iic M).preimage (Subtype.val_injective.injOn)) ?_ intro p hp change (if (p : ℕ) ≤ M then (1 : ℝ) / (p : ℝ) else 0) ≠ 0 at hp by_cases h : (p : ℕ) ≤ M · exact h · rw [if_neg h] at hp exact (hp rfl).elim have hsum_head : Summable (fun p : Nat.Primes => if (p : ℕ) ≤ M then (1 : ℝ) / (p : ℝ) else 0) := summable_of_ne_finset_zero (s := hfin_supp.toFinset) fun p hp => by by_contra hne exact hp (hfin_supp.mem_toFinset.mpr hne) have hsum_all : Summable (fun p : Nat.Primes => (1 : ℝ) / (p : ℝ)) := by have hadd := hsum_head.add hsum_tail convert hadd using 1 ext p by_cases h : (p : ℕ) ≤ M · have h' : ¬ M < (p : ℕ) := by omega simp [h, h'] · have h' : M < (p : ℕ) := by omega simp [h, h'] exact Nat.Primes.not_summable_one_div hsum_all /-- Elementary lower bound: for nonnegative `f`, `1 + ∑_{i ∈ s} f i ≤ ∏_{i ∈ s} (1 + f i)`. -/ lemma one_add_sum_le_prod_one_add {ι : Type*} (s : Finset ι) (f : ι → ℝ) (hf : ∀ i ∈ s, 0 ≤ f i) : 1 + ∑ i ∈ s, f i ≤ ∏ i ∈ s, (1 + f i) := by classical induction s using Finset.induction_on with | empty => simp | @insert a s ha ih => rw [Finset.sum_insert ha, Finset.prod_insert ha] have hfa : 0 ≤ f a := hf a (Finset.mem_insert_self a s) have hfs : ∀ i ∈ s, 0 ≤ f i := fun i hi => hf i (Finset.mem_insert_of_mem hi) have hsum_nn : 0 ≤ ∑ i ∈ s, f i := Finset.sum_nonneg hfs have hih := ih hfs nlinarith /-- Given `1 < A < B` and a threshold `M`, there exists a finite set `P` of primes `> M` such that `A ≤ ∏ p ∈ P, (1 + 1 / p) < B`. -/ lemma exists_finset_primes_prod_in_Ico (M : ℕ) {A B : ℝ} (hA : 1 < A) (hAB : A < B) : ∃ P : Finset ℕ, (∀ p ∈ P, p.Prime ∧ M < p) ∧ A ≤ ∏ p ∈ P, (1 + (1 : ℝ) / (p : ℝ)) ∧ ∏ p ∈ P, (1 + (1 : ℝ) / (p : ℝ)) < B := by -- Choose threshold `M' ≥ M` so that every `p > M'` satisfies `1 + 1 / p < B / A`. have hgap : 0 < B / A - 1 := by rw [sub_pos, one_lt_div (by linarith)] exact hAB obtain ⟨K, hK⟩ := exists_nat_gt (1 / (B / A - 1)) let M' := max M K have hstep : ∀ p : ℕ, M' < p → 1 + (1 : ℝ) / (p : ℝ) < B / A := by intro p hp have hpK : (K : ℝ) < (p : ℝ) := by exact_mod_cast lt_of_le_of_lt (le_max_right M K) hp have hp_pos : (0 : ℝ) < (p : ℝ) := by have : (0 : ℝ) ≤ (K : ℝ) := Nat.cast_nonneg K linarith have h1 : 1 / (B / A - 1) < (p : ℝ) := lt_trans hK hpK have h2 : (1 : ℝ) / (p : ℝ) < B / A - 1 := by rw [div_lt_iff₀ hp_pos] rw [div_lt_iff₀ hgap] at h1 linarith linarith -- Pick a finite set `Q` of primes `> M'` with `∑_{p ∈ Q} 1/p ≥ A`, so `∏ (1 + 1/p) ≥ 1 + A > A`. obtain ⟨Q, hQ, hQsum⟩ := exists_finset_primes_gt_sum_ge M' A have hQprod : A ≤ ∏ p ∈ Q, (1 + (1 : ℝ) / (p : ℝ)) := by have h1 := one_add_sum_le_prod_one_add Q (fun p => (1 : ℝ) / (p : ℝ)) (fun p _ => by positivity) linarith -- Shrink `Q` by strong induction on `Q.card` until `∏ (1 + 1/p) < B`. suffices hshrink : ∀ (c : ℕ) (S : Finset ℕ), S.card = c → (∀ p ∈ S, p.Prime ∧ M' < p) → A ≤ ∏ p ∈ S, (1 + (1 : ℝ) / (p : ℝ)) → ∃ P : Finset ℕ, (∀ p ∈ P, p.Prime ∧ M' < p) ∧ A ≤ ∏ p ∈ P, (1 + (1 : ℝ) / (p : ℝ)) ∧ ∏ p ∈ P, (1 + (1 : ℝ) / (p : ℝ)) < B by obtain ⟨P, hP, hPA, hPB⟩ := hshrink Q.card Q rfl hQ hQprod exact ⟨P, fun p hp => ⟨(hP p hp).1, lt_of_le_of_lt (le_max_left M K) (hP p hp).2⟩, hPA, hPB⟩ intro c induction c using Nat.strong_induction_on with | h c ih => intro S hScard hS hSA by_cases hSB : ∏ p ∈ S, (1 + (1 : ℝ) / (p : ℝ)) < B · exact ⟨S, hS, hSA, hSB⟩ · push Not at hSB -- `S` must be nonempty because `1 < A ≤ B ≤ ∏ ...`. have hSne : S.Nonempty := by by_contra hempty rw [Finset.not_nonempty_iff_eq_empty] at hempty rw [hempty, Finset.prod_empty] at hSA linarith obtain ⟨p₀, hp₀⟩ := hSne let S' := S.erase p₀ have hS'card : S'.card < c := by rw [← hScard, Finset.card_erase_of_mem hp₀] have := Finset.card_pos.mpr ⟨p₀, hp₀⟩; omega have hS' : ∀ p ∈ S', p.Prime ∧ M' < p := fun p hp => hS p (Finset.mem_of_mem_erase hp) have hprod_split : ∏ p ∈ S, (1 + (1 : ℝ) / (p : ℝ)) = (1 + (1 : ℝ) / (p₀ : ℝ)) * ∏ p ∈ S', (1 + (1 : ℝ) / (p : ℝ)) := (Finset.mul_prod_erase S (fun p => 1 + (1 : ℝ) / (p : ℝ)) hp₀).symm have hf_pos : 0 < 1 + (1 : ℝ) / (p₀ : ℝ) := by positivity have hf_lt : 1 + (1 : ℝ) / (p₀ : ℝ) < B / A := hstep p₀ (hS p₀ hp₀).2 have hS'A : A ≤ ∏ p ∈ S', (1 + (1 : ℝ) / (p : ℝ)) := by have hBA : A * (1 + (1 : ℝ) / (p₀ : ℝ)) ≤ B := by have := mul_lt_mul_of_pos_left hf_lt (by linarith : (0 : ℝ) < A) have hA_ne : A ≠ 0 := by linarith rw [mul_div_cancel₀ B hA_ne] at this linarith have hmul : A * (1 + (1 : ℝ) / (p₀ : ℝ)) ≤ (1 + (1 : ℝ) / (p₀ : ℝ)) * ∏ p ∈ S', (1 + (1 : ℝ) / (p : ℝ)) := by rw [← hprod_split]; exact le_trans hBA hSB nlinarith exact ih S'.card hS'card S' rfl hS' hS'A /-- For a finite set of distinct primes `P`, `σ₁(∏ P) = ∏_{p ∈ P} (p + 1)`. -/ lemma sigma_one_prod_primes (P : Finset ℕ) (hP : ∀ p ∈ P, p.Prime) : σ 1 (∏ p ∈ P, p) = ∏ p ∈ P, (p + 1) := by classical induction P using Finset.induction_on with | empty => simp | @insert p s hps ih => rw [Finset.prod_insert hps, Finset.prod_insert hps] have hp : p.Prime := hP p (Finset.mem_insert_self p s) have hs : ∀ q ∈ s, q.Prime := fun q hq => hP q (Finset.mem_insert_of_mem hq) have hcop : Nat.Coprime p (∏ q ∈ s, q) := by refine Nat.Coprime.prod_right fun q hq => ?_ have hq' := hs q hq have hne : p ≠ q := fun h => hps (h ▸ hq) exact (Nat.coprime_primes hp hq').mpr hne rw [sigma_one_mul_coprime hcop, sigma_one_prime hp, ih hs] /-- If `OeisA215926.conjecture_1` holds, then NO non-power-of-2 almost-perfect number exists! -/ theorem no_nonpow2_almost_perfect_of_conjecture1 (hconj : ∀ n : ℕ, 2 ≤ n → a n = 1 ∨ a n = 3 ∨ (a n).isPowerOfTwo) : ¬ ∃ k : ℕ, AlmostPerfect k ∧ ¬ ∃ r : ℕ, k = 2 ^ r := by classical rintro hex -- Let `k` be the SMALLEST non-power-of-2 almost-perfect number. let k := Nat.find hex have hk_spec : AlmostPerfect k ∧ ¬ ∃ r : ℕ, k = 2 ^ r := Nat.find_spec hex have hk_min : ∀ m < k, ¬ (AlmostPerfect m ∧ ¬ ∃ r : ℕ, m = 2 ^ r) := fun m hm => Nat.find_min hex hm obtain ⟨hk_ap, hk_notpow⟩ := hk_spec have hk_pos : 0 < k := almostPerfect_pos hk_ap -- Show `5 ≤ k` (eliminate `k ∈ {1, 2, 3, 4}`). have hk_ge5 : 5 ≤ k := by by_contra hlt have hcases : k = 1 ∨ k = 2 ∨ k = 3 ∨ k = 4 := by omega rcases hcases with h | h | h | h · exact hk_notpow ⟨0, h⟩ · exact hk_notpow ⟨1, h⟩ · have h3 : σ 1 3 = 4 := by rw [sigma_one_prime Nat.prime_three] unfold AlmostPerfect at hk_ap; rw [h, h3] at hk_ap; omega · exact hk_notpow ⟨2, h⟩ let r := Nat.log 2 k have hr_le : 2 ^ r ≤ k := Nat.pow_log_le_self 2 hk_pos.ne' have hr_lt : 2 ^ r < k := lt_of_le_of_ne hr_le fun h => hk_notpow ⟨r, h.symm⟩ have hk_lt : k < 2 ^ (r + 1) := Nat.lt_pow_succ_log_self (by norm_num) k -- Every deficient `m < k` satisfies `σ₁(m) * 2^r ≤ m * (2^{r+1} - 1)`. have hm_bound : ∀ m < k, m.Deficient → σ 1 m * 2 ^ r ≤ m * (2 ^ (r + 1) - 1) := by intro m hmk hm_def by_cases hmpow : ∃ j : ℕ, m = 2 ^ j · obtain ⟨j, rfl⟩ := hmpow rw [sigma_one_two_pow] have hjr : j ≤ r := by by_contra hgt have h1 : 2 ^ (r + 1) ≤ 2 ^ j := Nat.pow_le_pow_right (by norm_num) (by omega) omega have hpow_le : 2 ^ j ≤ 2 ^ r := Nat.pow_le_pow_right (by norm_num) hjr have h1 : 1 ≤ 2 ^ (j + 1) := Nat.one_le_pow _ _ (by norm_num) have h2 : 1 ≤ 2 ^ (r + 1) := Nat.one_le_pow _ _ (by norm_num) zify [h1, h2] have hjp : (2 ^ (j + 1) : ℤ) = 2 * (2 ^ j : ℤ) := by ring have hrp : (2 ^ (r + 1) : ℤ) = 2 * (2 ^ r : ℤ) := by ring have hle_z : (2 ^ j : ℤ) ≤ (2 ^ r : ℤ) := by exact_mod_cast hpow_le nlinarith · have hm_not_ap : ¬ AlmostPerfect m := fun hap => hk_min m hmk ⟨hap, hmpow⟩ have hsig_m : σ 1 m + 2 ≤ 2 * m := by have hlt := (deficient_iff_sigma.mp hm_def).2 unfold AlmostPerfect at hm_not_ap omega have hm_lt : m < 2 ^ (r + 1) := lt_trans hmk hk_lt have h2 : 1 ≤ 2 ^ (r + 1) := Nat.one_le_pow _ _ (by norm_num) zify [h2] have hsig_z : (σ 1 m : ℤ) + 2 ≤ 2 * (m : ℤ) := by exact_mod_cast hsig_m have hmlt_z : (m : ℤ) < (2 ^ (r + 1) : ℤ) := by exact_mod_cast hm_lt have hrp : (2 ^ (r + 1) : ℤ) = 2 * (2 ^ r : ℤ) := by ring nlinarith -- Construct `n = ∏ p ∈ P, p` with `p > 2 * k` and `σ(n)/n ∈ [A, B)`. let A : ℝ := (2 * (k : ℝ)) / (2 * (k : ℝ) - 1) let B : ℝ := ((2 ^ (r + 1) : ℕ) : ℝ) / (((2 ^ (r + 1) : ℕ) : ℝ) - 1) have h2k_gt1 : (1 : ℝ) < 2 * (k : ℝ) := by have : (5 : ℝ) ≤ (k : ℝ) := by exact_mod_cast hk_ge5 linarith have hA_gt1 : 1 < A := by dsimp only [A] rw [one_lt_div (by linarith)] linarith have hAB : A < B := by dsimp only [A, B] have h2r_lt_2k : ((2 ^ (r + 1) : ℕ) : ℝ) < 2 * (k : ℝ) := by have : 2 ^ (r + 1) < 2 * k := by have : 2 ^ (r + 1) = 2 * 2 ^ r := by ring omega exact_mod_cast this have h2r_gt1 : (1 : ℝ) < ((2 ^ (r + 1) : ℕ) : ℝ) := by have : 1 < 2 ^ (r + 1) := by have : 2 ^ 1 ≤ 2 ^ (r + 1) := Nat.pow_le_pow_right (by norm_num) (by omega) omega exact_mod_cast this rw [div_lt_div_iff₀ (by linarith) (by linarith)] nlinarith obtain ⟨P, hP, hPA, hPB⟩ := exists_finset_primes_prod_in_Ico (2 * k) hA_gt1 hAB let n : ℕ := ∏ p ∈ P, p have hPne : P.Nonempty := by by_contra hempty rw [Finset.not_nonempty_iff_eq_empty] at hempty rw [hempty, Finset.prod_empty] at hPA linarith have hn_ge2 : 2 ≤ n := by obtain ⟨p₀, hp₀⟩ := hPne have hp₀_ge2 : 2 ≤ p₀ := (hP p₀ hp₀).1.two_le have hprod_pos : 1 ≤ ∏ p ∈ P.erase p₀, p := Finset.one_le_prod' fun p hp => (hP p (Finset.mem_of_mem_erase hp)).1.one_le have hsplit : n = p₀ * ∏ p ∈ P.erase p₀, p := (Finset.mul_prod_erase P id hp₀).symm rw [hsplit] calc 2 ≤ p₀ := hp₀_ge2 _ = p₀ * 1 := (mul_one p₀).symm _ ≤ p₀ * ∏ p ∈ P.erase p₀, p := Nat.mul_le_mul_left p₀ hprod_pos have hn_pos : 0 < n := by omega have hcop_kn : Nat.Coprime k n := by refine Nat.Coprime.prod_right fun p hp => ?_ have hp_prime := (hP p hp).1 have hp_gt : k < p := by have := (hP p hp).2; omega exact (hp_prime.coprime_iff_not_dvd.mpr (Nat.not_dvd_of_pos_of_lt hk_pos hp_gt)).symm have hsig_n_eq : σ 1 n = ∏ p ∈ P, (p + 1) := sigma_one_prod_primes P fun p hp => (hP p hp).1 have hratio : (σ 1 n : ℝ) / (n : ℝ) = ∏ p ∈ P, (1 + (1 : ℝ) / (p : ℝ)) := by rw [hsig_n_eq] have hn_cast : (n : ℝ) = ∏ p ∈ P, (p : ℝ) := by simp [n] rw [hn_cast, Nat.cast_prod, ← Finset.prod_div_distrib] refine Finset.prod_congr rfl fun p hp => ?_ have hp_ne : (p : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (hP p hp).1.ne_zero push_cast field_simp -- Step A: `k * n` is non-deficient! have hkn_nd : NonDeficient (k * n) := by rw [nonDeficient_iff_sigma] refine ⟨Nat.mul_pos hk_pos hn_pos, ?_⟩ rw [sigma_one_mul_coprime hcop_kn] have hsig_k_eq : σ 1 k = 2 * k - 1 := by unfold AlmostPerfect at hk_ap; omega rw [hsig_k_eq] have hA_le : (2 * (k : ℝ)) / (2 * (k : ℝ) - 1) ≤ (σ 1 n : ℝ) / (n : ℝ) := hratio ▸ hPA have hn_rpos : (0 : ℝ) < (n : ℝ) := by exact_mod_cast hn_pos rw [div_le_div_iff₀ (by linarith) hn_rpos] at hA_le have hcast : ((2 * (k * n) : ℕ) : ℝ) ≤ (((2 * k - 1) * σ 1 n : ℕ) : ℝ) := by have h1 : 1 ≤ 2 * k := by omega push_cast [Nat.cast_sub h1] linarith exact_mod_cast hcast -- Step B: For every deficient `m < k`, `m * n` is deficient (so NOT non-deficient)! have hmin_k : ∀ m < k, ¬ (m.Deficient ∧ NonDeficient (m * n)) := by intro m hmk ⟨hm_def, hmn_nd⟩ have hm_pos : 0 < m := (deficient_iff_sigma.mp hm_def).1 have hmn_sig : 2 * (m * n) ≤ σ 1 (m * n) := (nonDeficient_iff_sigma.mp hmn_nd).2 have hsub := sigma_one_mul_le m n hm_pos hn_pos have hmb := hm_bound m hmk hm_def have hB_gt : (σ 1 n : ℝ) / (n : ℝ) < ((2 ^ (r + 1) : ℕ) : ℝ) / (((2 ^ (r + 1) : ℕ) : ℝ) - 1) := hratio ▸ hPB have hn_rpos : (0 : ℝ) < (n : ℝ) := by exact_mod_cast hn_pos have h2r_gt1 : (1 : ℝ) < ((2 ^ (r + 1) : ℕ) : ℝ) := by have : 1 < 2 ^ (r + 1) := by have : 2 ^ 1 ≤ 2 ^ (r + 1) := Nat.pow_le_pow_right (by norm_num) (by omega) omega exact_mod_cast this rw [div_lt_div_iff₀ hn_rpos (by linarith)] at hB_gt -- Real arithmetic: `2 * m * n * 2^r ≤ σ(m) * 2^r * σ(n) ≤ m * (2^{r+1} - 1) * σ(n) < m * 2^{r+1} * n`! have h1_r : (2 : ℝ) * (m : ℝ) * (n : ℝ) * ((2 ^ r : ℕ) : ℝ) ≤ (σ 1 m : ℝ) * ((2 ^ r : ℕ) : ℝ) * (σ 1 n : ℝ) := by have hnat : 2 * (m * n) * 2 ^ r ≤ σ 1 m * 2 ^ r * σ 1 n := by calc 2 * (m * n) * 2 ^ r ≤ σ 1 (m * n) * 2 ^ r := Nat.mul_le_mul_right _ hmn_sig _ ≤ (σ 1 m * σ 1 n) * 2 ^ r := Nat.mul_le_mul_right _ hsub _ = σ 1 m * 2 ^ r * σ 1 n := by ring have hcast : ((2 * (m * n) * 2 ^ r : ℕ) : ℝ) ≤ ((σ 1 m * 2 ^ r * σ 1 n : ℕ) : ℝ) := by exact_mod_cast hnat simp only [Nat.cast_mul, Nat.cast_ofNat] at hcast linarith have h2_r : (σ 1 m : ℝ) * ((2 ^ r : ℕ) : ℝ) ≤ (m : ℝ) * (((2 ^ (r + 1) : ℕ) : ℝ) - 1) := by have hpos1 : 1 ≤ 2 ^ (r + 1) := Nat.one_le_pow _ _ (by norm_num) have hcast : ((σ 1 m * 2 ^ r : ℕ) : ℝ) ≤ ((m * (2 ^ (r + 1) - 1) : ℕ) : ℝ) := by exact_mod_cast hmb rw [Nat.cast_mul, Nat.cast_mul, Nat.cast_sub hpos1, Nat.cast_one] at hcast exact hcast have hsig_nn : (0 : ℝ) ≤ (σ 1 n : ℝ) := Nat.cast_nonneg _ have hm_rpos : (0 : ℝ) < (m : ℝ) := by exact_mod_cast hm_pos have h2pow_r : ((2 ^ (r + 1) : ℕ) : ℝ) = 2 * ((2 ^ r : ℕ) : ℝ) := by have : 2 ^ (r + 1) = 2 * 2 ^ r := by ring exact_mod_cast this have h3_r : (σ 1 m : ℝ) * ((2 ^ r : ℕ) : ℝ) * (σ 1 n : ℝ) ≤ (m : ℝ) * (((2 ^ (r + 1) : ℕ) : ℝ) - 1) * (σ 1 n : ℝ) := mul_le_mul_of_nonneg_right h2_r hsig_nn have h4_r : (m : ℝ) * (((2 ^ (r + 1) : ℕ) : ℝ) - 1) * (σ 1 n : ℝ) < (m : ℝ) * ((2 ^ (r + 1) : ℕ) : ℝ) * (n : ℝ) := by have := mul_lt_mul_of_pos_left hB_gt hm_rpos linarith rw [h2pow_r] at h3_r h4_r linarith -- Therefore `a n = k`! have ha_eq : a n = k := by apply le_antisymm · exact a_le_of_mem (almostPerfect_deficient hk_ap) hkn_nd · by_contra hlt push Not at hlt exact hmin_k (a n) hlt (a_mem hn_ge2) -- Contradiction with `hconj n hn_ge2`! rcases hconj n hn_ge2 with h1 | h3 | hpow · omega · omega · rw [ha_eq, isPowerOfTwo_iff_exists] at hpow exact hk_notpow hpow /-- **MAIN THEOREM 1 (Exact Equivalence of Two Open Research Conjectures)**: `OeisA215926.conjecture_1` holds if and only if there is no non-power-of-2 almost-perfect number (`¬ AlmostPerfectNumbers.exists_almost_perfect_not_power_of_two`). -/ theorem a215926_conjecture1_iff_no_nonpow2_almost_perfect : (∀ n : ℕ, 2 ≤ n → a n = 1 ∨ a n = 3 ∨ (a n).isPowerOfTwo) ↔ ¬ ∃ k : ℕ, AlmostPerfect k ∧ ¬ ∃ r : ℕ, k = 2 ^ r := ⟨no_nonpow2_almost_perfect_of_conjecture1, conjecture1_of_no_nonpow2_almost_perfect⟩ end ForwardDirection section Conjecture2Results /-- By Bertrand's postulate, `nextPrimeTwoPow m` is prime and satisfies `2^m < p < 2^{m+1}`. -/ lemma nextPrimeTwoPow_spec (m : ℕ) (hm : 1 ≤ m) : 2 ^ m < nextPrimeTwoPow m ∧ (nextPrimeTwoPow m).Prime ∧ nextPrimeTwoPow m < 2 ^ (m + 1) ∧ ∀ q, 2 ^ m < q → q.Prime → nextPrimeTwoPow m ≤ q := by have h2m_ne : 2 ^ m ≠ 0 := by positivity obtain ⟨p, hp_prime, hp_gt, hp_le⟩ := Nat.exists_prime_lt_and_le_two_mul (2 ^ m) h2m_ne have hne : {q : ℕ | 2 ^ m < q ∧ q.Prime}.Nonempty := ⟨p, hp_gt, hp_prime⟩ have hmem : 2 ^ m < nextPrimeTwoPow m ∧ (nextPrimeTwoPow m).Prime := Nat.sInf_mem hne have hle_p : nextPrimeTwoPow m ≤ p := Nat.sInf_le ⟨hp_gt, hp_prime⟩ have h2pow : 2 * 2 ^ m = 2 ^ (m + 1) := by ring have hlt_pow : nextPrimeTwoPow m < 2 ^ (m + 1) := by have hle2 : nextPrimeTwoPow m ≤ 2 ^ (m + 1) := by omega refine lt_of_le_of_ne hle2 fun heq => ?_ have hprime_pow : (2 ^ (m + 1)).Prime := heq ▸ hmem.2 have hdvd : 2 ∣ 2 ^ (m + 1) := dvd_pow_self 2 (by omega) rcases hprime_pow.eq_one_or_self_of_dvd 2 hdvd with h | h · omega · have : 4 ≤ 2 ^ (m + 1) := by calc 4 = 2 ^ 2 := by norm_num _ ≤ 2 ^ (m + 1) := Nat.pow_le_pow_right (by norm_num) (by omega) omega exact ⟨hmem.1, hmem.2, hlt_pow, fun q hq1 hq2 => Nat.sInf_le ⟨hq1, hq2⟩⟩ /-- **Unconditional Upper Bound for `OeisA215926.conjecture_2`**: For every `m ≥ 1`, `a (nextPrimeTwoPow m) ≤ 2 ^ m`. -/ theorem a_nextPrimeTwoPow_le (m : ℕ) (hm : 1 ≤ m) : a (nextPrimeTwoPow m) ≤ 2 ^ m := by obtain ⟨hp_gt, hp_prime, hp_lt, _⟩ := nextPrimeTwoPow_spec m hm let p := nextPrimeTwoPow m refine a_le_of_mem (two_pow_deficient m) ?_ rw [nonDeficient_iff_sigma] refine ⟨Nat.mul_pos (by positivity) hp_prime.pos, ?_⟩ have hp_odd : ¬ 2 ∣ p := by intro h2 rcases hp_prime.eq_one_or_self_of_dvd 2 h2 with h | h · omega · have : 2 ≤ 2 ^ m := Nat.le_self_pow (by omega) 2 omega have hcop : Nat.Coprime (2 ^ m) p := Nat.Coprime.pow_left m (Nat.prime_two.coprime_iff_not_dvd.mpr hp_odd) rw [sigma_one_mul_coprime hcop, sigma_one_two_pow, sigma_one_prime hp_prime] have h2pow : 2 ^ (m + 1) = 2 * 2 ^ m := by ring have hpos1 : 1 ≤ 2 ^ (m + 1) := Nat.one_le_pow _ _ (by norm_num) zify [hpos1] have hlt_z : (p : ℤ) < (2 ^ (m + 1) : ℤ) := by exact_mod_cast hp_lt have h2p_z : (2 ^ (m + 1) : ℤ) = 2 * (2 ^ m : ℤ) := by exact_mod_cast h2pow nlinarith /-- **Unconditional Minimality Half of `OeisA215926.conjecture_2`**: For every `m ≥ 1` and every `2 ≤ n < nextPrimeTwoPow m`, we have `a n ≠ 2 ^ m`. -/ theorem a_ne_two_pow_of_lt_nextPrimeTwoPow (m : ℕ) (hm : 1 ≤ m) (n : ℕ) (hn2 : 2 ≤ n) (hnlt : n < nextPrimeTwoPow m) : a n ≠ 2 ^ m := by obtain ⟨hp_gt, hp_prime, hp_lt, hp_min⟩ := nextPrimeTwoPow_spec m hm by_cases hm1 : m = 1 · subst hm1 have hp3 : nextPrimeTwoPow 1 = 3 := by have h1 : 2 < nextPrimeTwoPow 1 := by simpa using hp_gt have h2 : nextPrimeTwoPow 1 ≤ 3 := hp_min 3 (by norm_num) Nat.prime_three omega have hn_eq2 : n = 2 := by omega subst hn_eq2 -- Show `a 2 ≠ 2` because `2 * 2 = 4` is deficient! intro ha2 have h4_nd : NonDeficient 4 := by have h := (a_mem (by norm_num : 2 ≤ 2)).2 rw [ha2] at h simpa using h have h4_def : (4 : ℕ).Deficient := by simpa using two_pow_deficient 2 have h1 := (nonDeficient_iff_sigma.mp h4_nd).2 have h2 := (deficient_iff_sigma.mp h4_def).2 omega · by_cases hm2 : m = 2 · subst hm2 have hp5 : nextPrimeTwoPow 2 = 5 := by have h1 : 4 < nextPrimeTwoPow 2 := by simpa using hp_gt have h2 : nextPrimeTwoPow 2 ≤ 5 := hp_min 5 (by norm_num) (by decide) omega have hcases : n = 2 ∨ n = 3 ∨ n = 4 := by omega rcases hcases with rfl | rfl | rfl · have := a_le_three_of_even (n := 2) (by norm_num) (by decide); omega · have := a_le_two_of_dvd_three (n := 3) (by norm_num) (by decide); omega · have := a_le_three_of_even (n := 4) (by norm_num) (by decide); omega · -- Now `m ≥ 3` (so `2 ^ m ≥ 8` and `3 < 2 ^ m`). have hm3 : 3 ≤ m := by omega by_cases h2 : 2 ∣ n · have hle3 := a_le_three_of_even hn2 h2 have h8 : 8 ≤ 2 ^ m := by calc 8 = 2 ^ 3 := by norm_num _ ≤ 2 ^ m := Nat.pow_le_pow_right (by norm_num) hm3 omega · -- `n` is odd. Show `a n ≤ 2 ^ (m - 1) < 2 ^ m`! have h2m_lt : 2 ^ (m - 1) < 2 ^ m := Nat.pow_lt_pow_right (by norm_num) (by omega) suffices hle : a n ≤ 2 ^ (m - 1) by omega refine a_le_of_mem (two_pow_deficient (m - 1)) ?_ rw [nonDeficient_iff_sigma] refine ⟨Nat.mul_pos (by positivity) (by omega), ?_⟩ have hcop : Nat.Coprime (2 ^ (m - 1)) n := Nat.Coprime.pow_left (m - 1) (Nat.prime_two.coprime_iff_not_dvd.mpr h2) rw [sigma_one_mul_coprime hcop, sigma_one_two_pow] have hm_sub : m - 1 + 1 = m := by omega rw [hm_sub] have h2pow : 2 * (2 ^ (m - 1) * n) = 2 ^ m * n := by have : 2 * 2 ^ (m - 1) = 2 ^ m := by calc 2 * 2 ^ (m - 1) = 2 ^ (m - 1 + 1) := by ring _ = 2 ^ m := by rw [hm_sub] calc 2 * (2 ^ (m - 1) * n) = (2 * 2 ^ (m - 1)) * n := by ring _ = 2 ^ m * n := by rw [this] rw [h2pow] by_cases hn_lt_pow : n < 2 ^ m · -- `n < 2^m`: `σ(n) ≥ n + 1` already suffices! have hsig := sigma_one_ge_add_one hn2 have h1 : (2 ^ m - 1) * (n + 1) ≤ (2 ^ m - 1) * σ 1 n := Nat.mul_le_mul_left _ hsig have hpos1 : 1 ≤ 2 ^ m := Nat.one_le_pow _ _ (by norm_num) zify [hpos1] at h1 ⊢ nlinarith · -- `2^m < n < nextPrimeTwoPow m < 2^{m+1}`: `n` is odd, hence `n ≠ 2^m`, and `n` is COMPOSITE! have hn_gt_pow : 2 ^ m < n := by refine lt_of_le_of_ne (by omega) fun heq => h2 ?_ rw [← heq] exact dvd_pow_self 2 (by omega) have hn_not_prime : ¬ n.Prime := fun hnp => not_le_of_gt hnlt (hp_min n hn_gt_pow hnp) -- Since `n ≥ 2` is composite, let `q = n.minFac`: `2 ≤ q`, `q * q ≤ n`, `q ∣ n`. let q := n.minFac have hq_prime : q.Prime := Nat.minFac_prime (by omega) have hq_dvd : q ∣ n := Nat.minFac_dvd n have hq_sq : q * q ≤ n := by simpa [sq] using Nat.minFac_sq_le_self (by omega) hn_not_prime let b := n / q have hqb : q * b = n := Nat.mul_div_cancel' hq_dvd have hb_dvd : b ∣ n := ⟨q, by rw [mul_comm, hqb]⟩ have h1_lt_b : 1 < b := by by_contra hb1 have hbq : b ≤ 1 := by omega have hle : n ≤ q := by nlinarith have : 2 ≤ q := hq_prime.two_le nlinarith have hb_lt_n : b < n := by have : 2 ≤ q := hq_prime.two_le nlinarith have hn_le_b2 : n ≤ b * b := by have hqb_le : q ≤ b := by nlinarith nlinarith have hsig_comp : n + b + 1 ≤ σ 1 n := by rw [sigma_one_eq_sum_divisors] have hsub : ({1, b, n} : Finset ℕ) ⊆ n.divisors := by intro d hd simp only [Finset.mem_insert, Finset.mem_singleton] at hd rw [Nat.mem_divisors] rcases hd with rfl | rfl | rfl · exact ⟨one_dvd n, by omega⟩ · exact ⟨hb_dvd, by omega⟩ · exact ⟨dvd_refl d, by omega⟩ have hsum3 : ∑ d ∈ ({1, b, n} : Finset ℕ), d = n + b + 1 := by rw [Finset.sum_insert (by simp; omega), Finset.sum_pair (by omega)] omega rw [← hsum3] exact Finset.sum_le_sum_of_subset hsub have h8 : 8 ≤ 2 ^ m := by calc 8 = 2 ^ 3 := by norm_num _ ≤ 2 ^ m := Nat.pow_le_pow_right (by norm_num) hm3 have hn_lt_2m1 : n < 2 * 2 ^ m := by have : 2 ^ (m + 1) = 2 * 2 ^ m := by ring omega have hsq_bound : n < (2 ^ m - 1) * (2 ^ m - 1) := by have h1 : 2 * 2 ^ m ≤ 4 * (2 ^ m - 1) := by omega have h2 : 4 * (2 ^ m - 1) ≤ (2 ^ m - 1) * (2 ^ m - 1) := Nat.mul_le_mul_right _ (by omega) omega have hn_le_prod : n ≤ (2 ^ m - 1) * b := by by_contra hgt push Not at hgt have h1 : (2 ^ m - 1) * b < n := hgt have hsq : ((2 ^ m - 1) * b) * ((2 ^ m - 1) * b) < n * n := Nat.mul_lt_mul'' h1 h1 have hge : n * n ≤ ((2 ^ m - 1) * (2 ^ m - 1)) * (b * b) := Nat.mul_le_mul (le_of_lt hsq_bound) hn_le_b2 have heq : ((2 ^ m - 1) * b) * ((2 ^ m - 1) * b) = ((2 ^ m - 1) * (2 ^ m - 1)) * (b * b) := by ring omega have hmul := Nat.mul_le_mul_left (2 ^ m - 1) hsig_comp have hsplit : 2 ^ m * n = (2 ^ m - 1) * n + n := by have : 2 ^ m = (2 ^ m - 1) + 1 := by omega calc 2 ^ m * n = ((2 ^ m - 1) + 1) * n := by rw [← this] _ = (2 ^ m - 1) * n + n := by ring have hstep1 : (2 ^ m - 1) * n + n ≤ (2 ^ m - 1) * (n + b + 1) := by calc (2 ^ m - 1) * n + n ≤ (2 ^ m - 1) * n + (2 ^ m - 1) * b := Nat.add_le_add_left hn_le_prod _ _ ≤ (2 ^ m - 1) * n + (2 ^ m - 1) * b + (2 ^ m - 1) := Nat.le_add_right _ _ _ = (2 ^ m - 1) * (n + b + 1) := by ring exact le_trans (le_of_eq hsplit) (le_trans hstep1 hmul) /-- **Conditional Full Resolution of `OeisA215926.conjecture_2`**: Absence of non-power-of-2 almost-perfect numbers implies `OeisA215926.conjecture_2` for all `m ≥ 1`. -/ theorem conjecture2_of_no_nonpow2_almost_perfect (hno : ¬ ∃ k : ℕ, AlmostPerfect k ∧ ¬ ∃ r : ℕ, k = 2 ^ r) (m : ℕ) (hm : 1 ≤ m) : IsLeast {n : ℕ | 2 ≤ n ∧ a n = 2 ^ m} (nextPrimeTwoPow m) := by obtain ⟨hp_gt, hp_prime, hp_lt, _⟩ := nextPrimeTwoPow_spec m hm let p := nextPrimeTwoPow m have hp_ge2 : 2 ≤ p := hp_prime.two_le have ha_eq : a p = 2 ^ m := by apply le_antisymm (a_nextPrimeTwoPow_le m hm) -- By `conjecture1_of_no_nonpow2_almost_perfect`, `a p` is `1`, `3`, or `2^r`. -- Actually even simpler: for ANY deficient `k < 2^m`, `k * p` is deficient! by_contra hlt push Not at hlt have ⟨hk_def, hk_nd⟩ := a_mem hp_ge2 have hk_pos : 0 < a p := (deficient_iff_sigma.mp hk_def).1 have hcop : Nat.Coprime (a p) p := (hp_prime.coprime_iff_not_dvd.mpr (Nat.not_dvd_of_pos_of_lt hk_pos (lt_trans hlt hp_gt))).symm have hsig_kp : 2 * (a p * p) ≤ σ 1 (a p * p) := (nonDeficient_iff_sigma.mp hk_nd).2 rw [sigma_one_mul_coprime hcop, sigma_one_prime hp_prime] at hsig_kp by_cases hpow : ∃ r : ℕ, a p = 2 ^ r · obtain ⟨r, hr⟩ := hpow rw [hr] at hlt hsig_kp have hr_lt : r < m := by by_contra hge have : 2 ^ m ≤ 2 ^ r := Nat.pow_le_pow_right (by norm_num) (by omega) omega have h2r_le : 2 ^ (r + 1) ≤ 2 ^ m := Nat.pow_le_pow_right (by norm_num) (by omega) rw [sigma_one_two_pow] at hsig_kp have hpos1 : 1 ≤ 2 ^ (r + 1) := Nat.one_le_pow _ _ (by norm_num) have h2p : 2 ^ (r + 1) = 2 * 2 ^ r := by ring zify [hpos1] at hsig_kp have h2r_z : (2 ^ (r + 1) : ℤ) ≤ (2 ^ m : ℤ) := by exact_mod_cast h2r_le have hp_z : (2 ^ m : ℤ) < (p : ℤ) := by exact_mod_cast hp_gt have h2p_z : (2 ^ (r + 1) : ℤ) = 2 * (2 ^ r : ℤ) := by exact_mod_cast h2p nlinarith · have hnot_ap : ¬ AlmostPerfect (a p) := fun hap => hno ⟨a p, hap, hpow⟩ have hsig_k : σ 1 (a p) + 2 ≤ 2 * a p := by have := (deficient_iff_sigma.mp hk_def).2 unfold AlmostPerfect at hnot_ap; omega -- `(2 * a p - 2) * (p + 1) < 2 * a p * p` because `a p < 2^m < p`! have hk_lt_p : a p < p := lt_trans hlt hp_gt nlinarith refine ⟨⟨hp_ge2, ha_eq⟩, ?_⟩ intro n ⟨hn2, han⟩ by_contra hlt push Not at hlt exact a_ne_two_pow_of_lt_nextPrimeTwoPow m hm n hn2 hlt han end Conjecture2Results #print axioms a215926_conjecture1_iff_no_nonpow2_almost_perfect #print axioms a_nextPrimeTwoPow_le #print axioms a_ne_two_pow_of_lt_nextPrimeTwoPow #print axioms conjecture2_of_no_nonpow2_almost_perfect end AutoDiscovery.A215926AlmostPerfect