| | @@ -0,0 +1,68 @@ |
| 1 | +import FormalConjecturesForMathlib.Combinatorics.Basic |
| 2 | +import Mathlib.Data.Finset.Prod |
| 3 | +import Mathlib.Data.Set.Card |
| 4 | + |
| 5 | +/-! # Forbidden extensions of finite Sidon sets for Erdős Problem 39 -/ |
| 6 | + |
| 7 | +namespace ErdosSwarm.Erdos39 |
| 8 | + |
| 9 | +/-- The positive new elements whose insertion destroys the Sidon property. -/ |
| 10 | +def forbiddenExtensions (S : Finset ℕ) : Set ℕ := |
| 11 | + {x | 0 < x ∧ x ∉ S ∧ ¬ IsSidon (insert x (S : Set ℕ))} |
| 12 | + |
| 13 | +/-- A finite Sidon set has at most `S.card ^ 3 + S.card ^ 2` |
| 14 | +forbidden extensions. -/ |
| 15 | +theorem forbiddenExtensions_finite_ncard_le {S : Finset ℕ} (hS : IsSidon (S : Set ℕ)) : |
| 16 | + (forbiddenExtensions S).Finite ∧ |
| 17 | + (forbiddenExtensions S).ncard ≤ S.card ^ 3 + S.card ^ 2 := by |
| 18 | + let triples := (S ×ˢ (S ×ˢ S)).image fun (a, b, c) => b + c - a |
| 19 | + let pairs := (S ×ˢ S).image fun (b, c) => (b + c) / 2 |
| 20 | + have hsubset : forbiddenExtensions S ⊆ (↑(triples ∪ pairs) : Set ℕ) := by |
| 21 | + intro x hx |
| 22 | + obtain ⟨_, _, hbad⟩ := hx |
| 23 | + by_contra houtside |
| 24 | + have ruleOutSingle {a b c : ℕ} (ha : a ∈ S) (hb : b ∈ S) (hc : c ∈ S) |
| 25 | + (heq : x + a = b + c) : False := by |
| 26 | + apply houtside |
| 27 | + apply Finset.mem_union_left |
| 28 | + refine Finset.mem_image.mpr ⟨(a, b, c), by simp [ha, hb, hc], ?_⟩ |
| 29 | + change b + c - a = x |
| 30 | + omega |
| 31 | + have ruleOutDouble {b c : ℕ} (hb : b ∈ S) (hc : c ∈ S) (heq : x + x = b + c) : False := by |
| 32 | + apply houtside |
| 33 | + apply Finset.mem_union_right |
| 34 | + refine Finset.mem_image.mpr ⟨(b, c), by simp [hb, hc], ?_⟩ |
| 35 | + change (b + c) / 2 = x |
| 36 | + omega |
| 37 | + apply hbad |
| 38 | + intro a ha b hb c hc d hd heq |
| 39 | + rcases Set.mem_insert_iff.mp ha with hax | ha <;> |
| 40 | + rcases Set.mem_insert_iff.mp hb with hbx | hb <;> |
| 41 | + rcases Set.mem_insert_iff.mp hc with hcx | hc <;> |
| 42 | + rcases Set.mem_insert_iff.mp hd with hdx | hd |
| 43 | + -- All-old sums use hS, and a shared x cancels. Otherwise use the images above. |
| 44 | + all_goals |
| 45 | + try subst a |
| 46 | + try subst b |
| 47 | + try subst c |
| 48 | + try subst d |
| 49 | + first |
| 50 | + | exact hS a ha b hb c hc d hd heq |
| 51 | + | omega |
| 52 | + | exfalso; apply ruleOutDouble hb hd; omega |
| 53 | + | exfalso; apply ruleOutDouble ha hc; omega |
| 54 | + | exfalso; apply ruleOutSingle ha hb hd; omega |
| 55 | + | exfalso; apply ruleOutSingle hc hb hd; omega |
| 56 | + | exfalso; apply ruleOutSingle hb ha hc; omega |
| 57 | + | exfalso; apply ruleOutSingle hd ha hc; omega |
| 58 | + refine ⟨(triples ∪ pairs).finite_toSet.subset hsubset, ?_⟩ |
| 59 | + calc |
| 60 | + (forbiddenExtensions S).ncard ≤ (triples ∪ pairs).card := by |
| 61 | + simpa only [Set.ncard_coe_finset] using |
| 62 | + Set.ncard_le_ncard hsubset (triples ∪ pairs).finite_toSet |
| 63 | + _ ≤ triples.card + pairs.card := Finset.card_union_le _ _ |
| 64 | + _ ≤ (S ×ˢ (S ×ˢ S)).card + (S ×ˢ S).card := |
| 65 | + Nat.add_le_add Finset.card_image_le Finset.card_image_le |
| 66 | + _ = S.card ^ 3 + S.card ^ 2 := by simp [pow_succ, Nat.mul_assoc] |
| 67 | + |
| 68 | +end ErdosSwarm.Erdos39 |