| | @@ -0,0 +1,61 @@ |
| 1 | +import Mathlib.Algebra.Group.Pointwise.Set.Basic |
| 2 | +import Mathlib.Data.Finset.Sym |
| 3 | +import Mathlib.Order.Interval.Finset.Nat |
| 4 | +import Mathlib.Data.Set.Card |
| 5 | + |
| 6 | +/-! |
| 7 | +# Counting for Erdős Problem 28 |
| 8 | + |
| 9 | +Each represented natural number up to `N` is the sum of an unordered pair, with repetition |
| 10 | +allowed, from the initial segment of the basis. |
| 11 | +-/ |
| 12 | + |
| 13 | +open scoped Pointwise |
| 14 | + |
| 15 | +namespace ErdosSwarm.Erdos28 |
| 16 | + |
| 17 | +/-- The initial segment of a cofinite additive basis has enough unordered pairs to cover all |
| 18 | +integers up to `N`, after subtracting the total number of exceptions. -/ |
| 19 | +theorem initialSegment_choose_bound (A : Set ℕ) (h : (A + A)ᶜ.Finite) (N : ℕ) : |
| 20 | + N + 1 ≤ ((A ∩ Set.Iic N).ncard + 1).choose 2 + (A + A)ᶜ.ncard := by |
| 21 | + classical |
| 22 | + have hfinite : (A ∩ Set.Iic N).Finite := (Set.finite_Iic N).subset Set.inter_subset_right |
| 23 | + let segment := hfinite.toFinset |
| 24 | + let pairSum : Sym2 ℕ → ℕ := Sym2.lift ⟨(· + ·), Nat.add_comm⟩ |
| 25 | + have hcover : Finset.range (N + 1) ⊆ segment.sym2.image pairSum ∪ h.toFinset := by |
| 26 | + intro n hn |
| 27 | + have hnN : n ≤ N := Nat.le_of_lt_succ (Finset.mem_range.mp hn) |
| 28 | + rw [Finset.mem_union] |
| 29 | + by_cases hmem : n ∈ A + A |
| 30 | + · obtain ⟨a, ha, b, hb, rfl⟩ := Set.mem_add.mp hmem |
| 31 | + left |
| 32 | + apply Finset.mem_image.mpr |
| 33 | + refine ⟨s(a, b), Finset.mk_mem_sym2_iff.mpr ⟨?_, ?_⟩, rfl⟩ |
| 34 | + · exact hfinite.mem_toFinset.mpr ⟨ha, Nat.le_trans (Nat.le_add_right _ _) hnN⟩ |
| 35 | + · exact hfinite.mem_toFinset.mpr ⟨hb, Nat.le_trans (Nat.le_add_left _ _) hnN⟩ |
| 36 | + · exact Or.inr (h.mem_toFinset.mpr hmem) |
| 37 | + calc |
| 38 | + N + 1 = (Finset.range (N + 1)).card := (Finset.card_range _).symm |
| 39 | + _ ≤ (segment.sym2.image pairSum ∪ h.toFinset).card := Finset.card_le_card hcover |
| 40 | + _ ≤ (segment.sym2.image pairSum).card + h.toFinset.card := Finset.card_union_le _ _ |
| 41 | + _ ≤ segment.sym2.card + h.toFinset.card := Nat.add_le_add_right Finset.card_image_le _ |
| 42 | + _ = ((A ∩ Set.Iic N).ncard + 1).choose 2 + (A + A)ᶜ.ncard := by |
| 43 | + rw [Finset.card_sym2, Set.ncard_eq_toFinset_card _ hfinite, Set.ncard_eq_toFinset_card _ h] |
| 44 | + |
| 45 | +/-- The square of the size of the initial segment plus the total number of exceptions bounds |
| 46 | +the number of integers up to `N`. -/ |
| 47 | +theorem initialSegment_sq_bound (A : Set ℕ) (h : (A + A)ᶜ.Finite) (N : ℕ) : |
| 48 | + N + 1 ≤ (A ∩ Set.Iic N).ncard ^ 2 + (A + A)ᶜ.ncard := by |
| 49 | + have choose_le_sq (m : ℕ) : (m + 1).choose 2 ≤ m ^ 2 := by |
| 50 | + rcases m with _ | m |
| 51 | + · decide |
| 52 | + rw [Nat.choose_two_right, Nat.add_sub_cancel] |
| 53 | + apply Nat.div_le_of_le_mul |
| 54 | + rw [pow_two] |
| 55 | + calc |
| 56 | + (m + 1 + 1) * (m + 1) ≤ (2 * (m + 1)) * (m + 1) := |
| 57 | + Nat.mul_le_mul_right _ (by omega) |
| 58 | + _ = 2 * ((m + 1) * (m + 1)) := by ac_rfl |
| 59 | + exact (initialSegment_choose_bound A h N).trans (Nat.add_le_add_right (choose_le_sq _) _) |
| 60 | + |
| 61 | +end ErdosSwarm.Erdos28 |