| | @@ -0,0 +1,103 @@ |
| 1 | +import FormalConjectures.ErdosProblems.«859» |
| 2 | +import ErdosSwarm.Erdos929 |
| 3 | + |
| 4 | +/-! |
| 5 | +# Erdős Problem 859: `DivisorSumSet t` has positive density |
| 6 | + |
| 7 | +A representation `t = ∑ i ∈ s, i` with `s ⊆ divisors n` only uses divisors `i ≤ t`, and each such |
| 8 | +`i` divides `t!`. So for `n ≥ 1`, membership of `n` only depends on `n` modulo `t!`; adding `0` |
| 9 | +makes the set exactly periodic with period `t!`. A periodic set has density `count / period` |
| 10 | +(`ErdosSwarm.Erdos929.hasDensity_of_periodic`), positive here as the set contains `0`, and |
| 11 | +removing the single point `0` does not change the density. |
| 12 | +-/ |
| 13 | + |
| 14 | +open Filter Topology _root_.Erdos859 |
| 15 | + |
| 16 | +namespace ErdosSwarm.Erdos859 |
| 17 | + |
| 18 | +lemma mem_iff_add_factorial (t n : ℕ) (hn : n ≠ 0) : |
| 19 | + n ∈ DivisorSumSet t ↔ n + t.factorial ∈ DivisorSumSet t := by |
| 20 | + have key : ∀ m m' : ℕ, m ≠ 0 → m' ≠ 0 → (∀ i, 0 < i → i ≤ t → (i ∣ m ↔ i ∣ m')) → |
| 21 | + m ∈ DivisorSumSet t → m' ∈ DivisorSumSet t := by |
| 22 | + rintro m m' hm hm' hdiv ⟨s, hs, rfl⟩ |
| 23 | + refine ⟨s, fun i hi => ?_, rfl⟩ |
| 24 | + have hi' := hs hi |
| 25 | + rw [Nat.mem_divisors] at hi' ⊢ |
| 26 | + have hpos : 0 < i := Nat.pos_of_dvd_of_pos hi'.1 (Nat.pos_of_ne_zero hm) |
| 27 | + have hle : i ≤ ∑ j ∈ s, j := Finset.single_le_sum (f := fun j => j) (fun _ _ => Nat.zero_le _) hi |
| 28 | + exact ⟨(hdiv i hpos hle).1 hi'.1, hm'⟩ |
| 29 | + have hdiv : ∀ i, 0 < i → i ≤ t → (i ∣ n ↔ i ∣ n + t.factorial) := fun i hi hit => |
| 30 | + (Nat.dvd_add_left (Nat.dvd_factorial hi hit)).symm |
| 31 | + exact ⟨key _ _ hn (by positivity) hdiv, |
| 32 | + key _ _ (by positivity) hn (fun i hi hit => (hdiv i hi hit).symm)⟩ |
| 33 | + |
| 34 | +theorem positive_density (t : ℕ) : (DivisorSumSet t).HasPosDensity := by |
| 35 | + classical |
| 36 | + set M := t.factorial with hMdef |
| 37 | + have hM : 0 < M := Nat.factorial_pos t |
| 38 | + let p : ℕ → Prop := fun n => n = 0 ∨ n ∈ DivisorSumSet t |
| 39 | + have hp : Function.Periodic p M := by |
| 40 | + intro n |
| 41 | + simp only [p] |
| 42 | + rcases Nat.eq_zero_or_pos n with rfl | hn |
| 43 | + · simp only [zero_add, true_or] |
| 44 | + refine eq_true (Or.inr ?_) |
| 45 | + exact ⟨({t} : Finset ℕ).filter (· ≠ 0), by |
| 46 | + intro i hi |
| 47 | + simp only [Finset.mem_filter, Finset.mem_singleton] at hi |
| 48 | + obtain ⟨rfl, hi0⟩ := hi |
| 49 | + exact Nat.mem_divisors.2 ⟨Nat.dvd_factorial (Nat.pos_of_ne_zero hi0) le_rfl, |
| 50 | + (Nat.factorial_pos _).ne'⟩, by |
| 51 | + rcases Nat.eq_zero_or_pos t with rfl | ht |
| 52 | + · simp [Finset.filter_singleton] |
| 53 | + · simp [Finset.filter_singleton, ht.ne']⟩ |
| 54 | + · have h1 : n + M ≠ 0 := by omega |
| 55 | + simp only [h1, false_or, hn.ne', mem_iff_add_factorial t n hn.ne'] |
| 56 | + try rfl |
| 57 | + have hc : 0 < Nat.count p M := lt_of_lt_of_le |
| 58 | + (by rw [Nat.count_one, if_pos (Or.inl rfl)]; norm_num) (Nat.count_monotone p hM) |
| 59 | + have hd := ErdosSwarm.Erdos929.hasDensity_of_periodic hM hp |
| 60 | + refine ⟨(Nat.count p M : ℝ) / M, by positivity, ?_⟩ |
| 61 | + by_cases ht : t = 0 |
| 62 | + · subst ht |
| 63 | + have : {n : ℕ | p n} = DivisorSumSet 0 := by |
| 64 | + ext n; simp [p, Erdos859.erdos_859.variants.trivial_case] |
| 65 | + convert hd using 1 |
| 66 | + exact this.symm |
| 67 | + -- `0 ∉ DivisorSumSet t` for `t ≠ 0`, so it is `{n | p n}` minus one point. |
| 68 | + have h0 : (0 : ℕ) ∉ DivisorSumSet t := by |
| 69 | + rintro ⟨s, hs, hsum⟩ |
| 70 | + simp only [Nat.divisors_zero, Finset.subset_empty] at hs |
| 71 | + subst hs; simp at hsum; exact ht hsum |
| 72 | + have hcard : ∀ b : ℕ, 0 < b → |
| 73 | + ((DivisorSumSet t ∩ Set.univ ∩ Set.Iio b).ncard : ℝ) = |
| 74 | + ({n : ℕ | p n} ∩ Set.univ ∩ Set.Iio b).ncard - 1 := by |
| 75 | + intro b hb |
| 76 | + have hset : {n : ℕ | p n} ∩ Set.univ ∩ Set.Iio b = |
| 77 | + insert 0 (DivisorSumSet t ∩ Set.univ ∩ Set.Iio b) := by |
| 78 | + ext n |
| 79 | + simp only [p, Set.mem_inter_iff, Set.mem_ofPred_eq, Set.mem_univ, and_true, Set.mem_Iio, |
| 80 | + Set.mem_insert_iff] |
| 81 | + constructor |
| 82 | + · rintro ⟨rfl | h, hb'⟩ |
| 83 | + · exact Or.inl rfl |
| 84 | + · exact Or.inr ⟨h, hb'⟩ |
| 85 | + · rintro (rfl | ⟨h, hb'⟩) |
| 86 | + · exact ⟨Or.inl rfl, hb⟩ |
| 87 | + · exact ⟨Or.inr h, hb'⟩ |
| 88 | + have hfin : (DivisorSumSet t ∩ Set.univ ∩ Set.Iio b).Finite := |
| 89 | + (Set.finite_Iio b).subset Set.inter_subset_right |
| 90 | + rw [hset, Set.ncard_insert_of_notMem (fun h => h0 h.1.1) hfin] |
| 91 | + push_cast; ring |
| 92 | + unfold Set.HasDensity at hd ⊢ |
| 93 | + have hinv : Tendsto (fun b : ℕ => (1 : ℝ) / ((Set.univ : Set ℕ) ∩ Set.Iio b).ncard) atTop |
| 94 | + (𝓝 0) := by |
| 95 | + refine tendsto_one_div_atTop_nhds_zero_nat.congr' ?_ |
| 96 | + filter_upwards with b |
| 97 | + simp [Set.ncard_Iio_nat] |
| 98 | + have := hd.sub hinv |
| 99 | + rw [sub_zero] at this |
| 100 | + refine this.congr' ?_ |
| 101 | + filter_upwards [eventually_gt_atTop 0] with b hb |
| 102 | + simp only [Set.partialDensity] |
| 103 | + rw [hcard b hb, sub_div] |