# Erdős problem #340: evidence on A−A of the Mian–Chowla sequence

> Source: <https://gist.github.com/royallight1999-jpg/3fcee547c88a0b7af24e5dc52bcc0ccd>
> Published: 2026-11-26 16:49:50+00:00

**Key takeaway:** Growth-rate bounds alone cannot resolve Erdős problem #340: for every monotone f there exists a Sidon set A with A − A containing all positive integers yet at most 2N elements below f(N).

|  | /- | 
|  | A Sidon set whose difference set is ALL positive integers, | 
|  | and which is nevertheless as sparse as we like. | 
|  |  | 
|  | Context: Erdős problem #340 asks whether the difference set A − A of the | 
|  | greedy Sidon sequence (Mian–Chowla) has positive density. This file proves | 
|  | that growth information alone cannot settle such a question: for every | 
|  | monotone f there is a Sidon set A with A − A ⊇ {1,2,3,...} and at most 2N | 
|  | elements below f(N). | 
|  |  | 
|  | Core Lean 4 only (no Mathlib). Written with Claude Opus 5.5 (Anthropic). | 
|  | -/ | 
|  |  | 
|  | /-- A is a Sidon set: a + b = c + e forces {a,b} = {c,e}. -/ | 
|  | def IsSidon (A : Nat → Prop) : Prop := | 
|  | ∀ a b c e, A a → A b → A c → A e → a + b = c + e → | 
|  | (a = c ∧ b = e) ∨ (a = e ∧ b = c) | 
|  |  | 
|  | def mx : List Nat → Nat | 
|  | \| [] => 0 | 
|  | \| a :: l => max a (mx l) | 
|  |  | 
|  | theorem le_mx (S : List Nat) : ∀ s, s ∈ S → s ≤ mx S := by | 
|  | induction S with | 
|  | \| nil => intro s h; simp at h | 
|  | \| cons a l ih => | 
|  | intro s h | 
|  | simp only [List.mem_cons] at h | 
|  | simp only [mx] | 
|  | rcases h with h \| h | 
|  | · subst h; exact Nat.le_max_left _ _ | 
|  | · exact Nat.le_trans (ih s h) (Nat.le_max_right _ _) | 
|  |  | 
|  | /-- Where the new pair goes at step k: far beyond everything so far. -/ | 
|  | def nxt (f : Nat → Nat) (k : Nat) (S : List Nat) : Nat := | 
|  | 2 * mx S + (k + 1) + f k + 1 | 
|  |  | 
|  | /-- Step k makes sure the difference k+1 occurs. -/ | 
|  | def step (f : Nat → Nat) (k : Nat) (S : List Nat) : List Nat := | 
|  | if ∃ s ∈ S, s + (k + 1) ∈ S then S | 
|  | else nxt f k S :: (nxt f k S + (k + 1)) :: S | 
|  |  | 
|  | def st (f : Nat → Nat) : Nat → List Nat | 
|  | \| 0 => [] | 
|  | \| k + 1 => step f k (st f k) | 
|  |  | 
|  | theorem step_pos (f : Nat → Nat) (k : Nat) (S : List Nat) | 
|  | (hc : ∃ s ∈ S, s + (k + 1) ∈ S) : step f k S = S := by | 
|  | unfold step; exact if_pos hc | 
|  |  | 
|  | theorem step_neg (f : Nat → Nat) (k : Nat) (S : List Nat) | 
|  | (hc : ¬ ∃ s ∈ S, s + (k + 1) ∈ S) : | 
|  | step f k S = nxt f k S :: (nxt f k S + (k + 1)) :: S := by | 
|  | unfold step; exact if_neg hc | 
|  |  | 
|  | theorem mem_aux {S : List Nat} {d x z : Nat} | 
|  | (hx : ∀ s, s ∈ S → 2 * s + d < x) (h : z ∈ x :: (x + d) :: S) : | 
|  | z = x ∨ z = x + d ∨ (z ∈ S ∧ 2 * z + d < x) := by | 
|  | simp only [List.mem_cons] at h | 
|  | rcases h with h \| h \| h | 
|  | · exact Or.inl h | 
|  | · exact Or.inr (Or.inl h) | 
|  | · exact Or.inr (Or.inr ⟨h, hx z h⟩) | 
|  |  | 
|  | /-- Key lemma: adding a far-away pair {x, x+d} to a Sidon set keeps it Sidon, | 
|  | provided d was not already a difference. -/ | 
|  | theorem sidon_add_pair (S : List Nat) (d x : Nat) | 
|  | (hS : IsSidon (· ∈ S)) (hd0 : 0 < d) | 
|  | (hd : ¬ ∃ s ∈ S, s + d ∈ S) | 
|  | (hx : ∀ s, s ∈ S → 2 * s + d < x) : | 
|  | IsSidon (· ∈ x :: (x + d) :: S) := by | 
|  | have hd' : ∀ s, s ∈ S → s + d ∈ S → False := fun s h1 h2 => hd ⟨s, h1, h2⟩ | 
|  | intro a b c e ha hb hc he h | 
|  | change a ∈ x :: (x + d) :: S at ha | 
|  | change b ∈ x :: (x + d) :: S at hb | 
|  | change c ∈ x :: (x + d) :: S at hc | 
|  | change e ∈ x :: (x + d) :: S at he | 
|  | rcases mem_aux hx ha with ha \| ha \| ⟨ha, ba⟩ <;> | 
|  | rcases mem_aux hx hb with hb \| hb \| ⟨hb, bb⟩ <;> | 
|  | rcases mem_aux hx hc with hc \| hc \| ⟨hc, bc⟩ <;> | 
|  | rcases mem_aux hx he with he \| he \| ⟨he, be⟩ | 
|  | all_goals first | 
|  | \| omega | 
|  | \| exact hS a b c e ha hb hc he h | 
|  | \| exact (hd' a ha (by rw [show a + d = b by omega]; exact hb)).elim | 
|  | \| exact (hd' a ha (by rw [show a + d = c by omega]; exact hc)).elim | 
|  | \| exact (hd' a ha (by rw [show a + d = e by omega]; exact he)).elim | 
|  | \| exact (hd' b hb (by rw [show b + d = a by omega]; exact ha)).elim | 
|  | \| exact (hd' b hb (by rw [show b + d = c by omega]; exact hc)).elim | 
|  | \| exact (hd' b hb (by rw [show b + d = e by omega]; exact he)).elim | 
|  | \| exact (hd' c hc (by rw [show c + d = a by omega]; exact ha)).elim | 
|  | \| exact (hd' c hc (by rw [show c + d = b by omega]; exact hb)).elim | 
|  | \| exact (hd' c hc (by rw [show c + d = e by omega]; exact he)).elim | 
|  | \| exact (hd' e he (by rw [show e + d = a by omega]; exact ha)).elim | 
|  | \| exact (hd' e he (by rw [show e + d = b by omega]; exact hb)).elim | 
|  | \| exact (hd' e he (by rw [show e + d = c by omega]; exact hc)).elim | 
|  |  | 
|  | theorem step_sup (f : Nat → Nat) (k : Nat) (S : List Nat) (n : Nat) | 
|  | (h : n ∈ S) : n ∈ step f k S := by | 
|  | by_cases hc : ∃ s ∈ S, s + (k + 1) ∈ S | 
|  | · rw [step_pos f k S hc]; exact h | 
|  | · rw [step_neg f k S hc]; simp [h] | 
|  |  | 
|  | theorem sidon_step (f : Nat → Nat) (k : Nat) (S : List Nat) | 
|  | (hS : IsSidon (· ∈ S)) : IsSidon (· ∈ step f k S) := by | 
|  | by_cases hc : ∃ s ∈ S, s + (k + 1) ∈ S | 
|  | · rw [step_pos f k S hc]; exact hS | 
|  | · rw [step_neg f k S hc] | 
|  | apply sidon_add_pair S (k + 1) (nxt f k S) hS (Nat.succ_pos k) hc | 
|  | intro s hs | 
|  | have := le_mx S s hs | 
|  | unfold nxt | 
|  | omega | 
|  |  | 
|  | theorem sidon_st (f : Nat → Nat) : ∀ k, IsSidon (· ∈ st f k) | 
|  | \| 0 => by | 
|  | intro a b c e ha | 
|  | change a ∈ ([] : List Nat) at ha | 
|  | simp at ha | 
|  | \| k + 1 => sidon_step f k (st f k) (sidon_st f k) | 
|  |  | 
|  | theorem st_mono (f : Nat → Nat) {k : Nat} : | 
|  | ∀ K, k ≤ K → ∀ n, n ∈ st f k → n ∈ st f K := by | 
|  | intro K | 
|  | induction K with | 
|  | \| zero => | 
|  | intro hk n h | 
|  | have : k = 0 := by omega | 
|  | subst this; exact h | 
|  | \| succ K ih => | 
|  | intro hk n h | 
|  | rcases Nat.lt_or_ge k (K + 1) with hlt \| hge | 
|  | · exact step_sup f K (st f K) n (ih (by omega) n h) | 
|  | · have : k = K + 1 := by omega | 
|  | subst this; exact h | 
|  |  | 
|  | /-- The union of all stages is a Sidon set. -/ | 
|  | theorem sidon_A (f : Nat → Nat) : IsSidon (fun n => ∃ k, n ∈ st f k) := by | 
|  | rintro a b c e ⟨ka, ha⟩ ⟨kb, hb⟩ ⟨kc, hc⟩ ⟨ke, he⟩ h | 
|  | exact sidon_st f (ka + kb + kc + ke) a b c e | 
|  | (st_mono f _ (by omega) a ha) (st_mono f _ (by omega) b hb) | 
|  | (st_mono f _ (by omega) c hc) (st_mono f _ (by omega) e he) h | 
|  |  | 
|  | /-- Every positive integer is a difference of two elements. -/ | 
|  | theorem covers (f : Nat → Nat) (d : Nat) (hd : 0 < d) : | 
|  | ∃ a, (∃ k, a ∈ st f k) ∧ (∃ k, a + d ∈ st f k) := by | 
|  | obtain ⟨k, rfl⟩ : ∃ k, d = k + 1 := ⟨d - 1, by omega⟩ | 
|  | by_cases hc : ∃ s ∈ st f k, s + (k + 1) ∈ st f k | 
|  | · obtain ⟨s, hs1, hs2⟩ := hc | 
|  | exact ⟨s, ⟨k, hs1⟩, ⟨k, hs2⟩⟩ | 
|  | · refine ⟨nxt f k (st f k), ⟨k + 1, ?_⟩, ⟨k + 1, ?_⟩⟩ | 
|  | · show _ ∈ step f k (st f k) | 
|  | rw [step_neg f k _ hc]; simp | 
|  | · show _ ∈ step f k (st f k) | 
|  | rw [step_neg f k _ hc]; simp | 
|  |  | 
|  | theorem small_in (f : Nat → Nat) (hf : ∀ a b, a ≤ b → f a ≤ f b) (N : Nat) : | 
|  | ∀ j n, n ∈ st f (N + j) → n < f N → n ∈ st f N := by | 
|  | intro j | 
|  | induction j with | 
|  | \| zero => intro n h _; exact h | 
|  | \| succ j ih => | 
|  | intro n h hn | 
|  | have h' : n ∈ step f (N + j) (st f (N + j)) := h | 
|  | by_cases hc : ∃ s ∈ st f (N + j), s + (N + j + 1) ∈ st f (N + j) | 
|  | · rw [step_pos f _ _ hc] at h' | 
|  | exact ih n h' hn | 
|  | · rw [step_neg f _ _ hc] at h' | 
|  | simp only [List.mem_cons] at h' | 
|  | have hfj := hf N (N + j) (by omega) | 
|  | rcases h' with h' \| h' \| h' | 
|  | · unfold nxt at h'; omega | 
|  | · unfold nxt at h'; omega | 
|  | · exact ih n h' hn | 
|  |  | 
|  | /-- Every element below f N already lies in stage N. -/ | 
|  | theorem sparse (f : Nat → Nat) (hf : ∀ a b, a ≤ b → f a ≤ f b) (N : Nat) : | 
|  | ∀ n, (∃ k, n ∈ st f k) → n < f N → n ∈ st f N := by | 
|  | rintro n ⟨k, hk⟩ hn | 
|  | rcases Nat.le_total k N with h \| h | 
|  | · exact st_mono f N h n hk | 
|  | · obtain ⟨j, rfl⟩ : ∃ j, k = N + j := ⟨k - N, by omega⟩ | 
|  | exact small_in f hf N j n hk hn | 
|  |  | 
|  | /-- Stage N has at most 2N elements. -/ | 
|  | theorem len_st (f : Nat → Nat) : ∀ N, (st f N).length ≤ 2 * N | 
|  | \| 0 => by simp [st] | 
|  | \| N + 1 => by | 
|  | have ih := len_st f N | 
|  | show (step f N (st f N)).length ≤ 2 * (N + 1) | 
|  | by_cases hc : ∃ s ∈ st f N, s + (N + 1) ∈ st f N | 
|  | · rw [step_pos f _ _ hc]; omega | 
|  | · rw [step_neg f _ _ hc]; simp only [List.length_cons]; omega | 
|  |  | 
|  | /-- MAIN THEOREM. For every monotone f : ℕ → ℕ there is a Sidon set A ⊆ ℕ such that | 
|  | every positive integer d is a difference a' − a of two elements of A, while | 
|  | A has at most 2N elements below f(N). Taking f fast-growing makes A | 
|  | arbitrarily sparse. -/ | 
|  | theorem sparse_sidon_with_all_differences (f : Nat → Nat) | 
|  | (hf : ∀ a b, a ≤ b → f a ≤ f b) : | 
|  | ∃ A : Nat → Prop, | 
|  | IsSidon A ∧ | 
|  | (∀ d, 0 < d → ∃ a, A a ∧ A (a + d)) ∧ | 
|  | (∀ N, ∃ T : List Nat, T.length ≤ 2 * N ∧ ∀ n, A n → n < f N → n ∈ T) := | 
|  | ⟨fun n => ∃ k, n ∈ st f k, sidon_A f, covers f, | 
|  | fun N => ⟨st f N, len_st f N, sparse f hf N⟩⟩ | 
|  |  | 
|  | #print axioms sparse_sidon_with_all_differences |
