| | @@ -0,0 +1,61 @@ |
| 1 | +import FormalConjectures.ErdosProblems.«588» |
| 2 | + |
| 3 | +/-! |
| 4 | +# Erdős Problem 588: the pair-counting upper bound |
| 5 | + |
| 6 | +The argument follows Daniel Veljjanoski's |
| 7 | +[pair-counting proof](https://github.com/veljjanoski/formal-conjectures-proofs/blob/a199537b29d77124f8e1ea0d816a881e96f0cc0f/FcProofs/Erdos588.lean). |
| 8 | +-/ |
| 9 | + |
| 10 | +open EuclideanGeometry |
| 11 | +open scoped Finset |
| 12 | + |
| 13 | +namespace ErdosSwarm.Erdos588 |
| 14 | + |
| 15 | +private theorem linesWithPointsFor_finite (k : ℕ) {S : Set ℝ²} (hS : S.Finite) : |
| 16 | + (linesWithPointsFor k S).Finite := by |
| 17 | + refine (hS.image2 (fun p q ↦ affineSpan ℝ {p, q}) hS).subset ?_ |
| 18 | + rintro L ⟨⟨p, hp, q, hq, -, rfl⟩, -⟩ |
| 19 | + exact ⟨p, hp, q, hq, rfl⟩ |
| 20 | + |
| 21 | +/-- Each line containing exactly `k` points accounts for `k * (k - 1)` distinct ordered |
| 22 | +pairs of points of `S`. A pair determines its line, so these contributions are disjoint. -/ |
| 23 | +theorem ncard_linesWithPointsFor_mul_le (k : ℕ) {S : Set ℝ²} (hS : S.Finite) : |
| 24 | + (linesWithPointsFor k S).ncard * (k * (k - 1)) ≤ S.ncard * (S.ncard - 1) := by |
| 25 | + classical |
| 26 | + let points := hS.toFinset |
| 27 | + have finiteLines := linesWithPointsFor_finite k hS |
| 28 | + let lines := finiteLines.toFinset |
| 29 | + let onLine (L : AffineSubspace ℝ ℝ²) := points.filter (· ∈ L) |
| 30 | + let pairs (L : AffineSubspace ℝ ℝ²) := (onLine L).offDiag |
| 31 | + have cardOnLine (L) (hL : L ∈ lines) : #(onLine L) = k := by |
| 32 | + have hmem : L ∈ linesWithPointsFor k S := by simpa only [lines, Set.Finite.mem_toFinset] using hL |
| 33 | + have coeOnLine : (↑(onLine L) : Set ℝ²) = (L : Set ℝ²) ∩ S := by |
| 34 | + ext p |
| 35 | + simp [onLine, points, and_comm] |
| 36 | + rw [← Set.ncard_coe_finset, coeOnLine, hmem.2] |
| 37 | + have cardPairs (L) (hL : L ∈ lines) : #(pairs L) = k * (k - 1) := by |
| 38 | + change #((onLine L).offDiag) = _ |
| 39 | + rw [Finset.offDiag_card, cardOnLine L hL, Nat.mul_sub_one] |
| 40 | + have spanOfPair (L) (hL : L ∈ lines) {p q : ℝ²} (hpq : (p, q) ∈ pairs L) : |
| 41 | + affineSpan ℝ {p, q} = L := by |
| 42 | + have hmem : L ∈ linesWithPointsFor k S := by simpa only [lines, Set.Finite.mem_toFinset] using hL |
| 43 | + obtain ⟨⟨a, -, b, -, -, rfl⟩, -⟩ := hmem |
| 44 | + simp only [pairs, onLine, Finset.mem_offDiag, Finset.mem_filter] at hpq |
| 45 | + exact affineSpan_pair_eq_of_mem_of_mem_of_ne hpq.1.2 hpq.2.1.2 hpq.2.2 |
| 46 | + have disjointPairs : ∀ L ∈ lines, ∀ M ∈ lines, L ≠ M → Disjoint (pairs L) (pairs M) := by |
| 47 | + intro L hL M hM hne |
| 48 | + rw [Finset.disjoint_left] |
| 49 | + rintro ⟨p, q⟩ hpqL hpqM |
| 50 | + exact hne ((spanOfPair L hL hpqL).symm.trans (spanOfPair M hM hpqM)) |
| 51 | + have allPairs : lines.biUnion pairs ⊆ points.offDiag := by |
| 52 | + apply Finset.biUnion_subset.mpr |
| 53 | + intro L _ pq hpq |
| 54 | + simp only [pairs, onLine, Finset.mem_offDiag, Finset.mem_filter] at hpq ⊢ |
| 55 | + exact ⟨hpq.1.1, hpq.2.1.1, hpq.2.2⟩ |
| 56 | + have bound := Finset.card_le_card allPairs |
| 57 | + rw [Finset.card_biUnion disjointPairs, Finset.sum_congr rfl cardPairs, Finset.sum_const, |
| 58 | + smul_eq_mul, Finset.offDiag_card, ← Nat.mul_sub_one] at bound |
| 59 | + simpa only [Set.ncard_eq_toFinset_card _ finiteLines, Set.ncard_eq_toFinset_card _ hS] using bound |
| 60 | + |
| 61 | +end ErdosSwarm.Erdos588 |