{
  "id": "1735",
  "ident": "NS.01735",
  "slug": "erdos-338",
  "title": "Erdős Problem 338",
  "status": "open",
  "statement_status": "reviewed",
  "statement_md": "The restricted order of a basis $A$ is the least integer $t$ (if it exists) such that every large\ninteger is the sum of at most $t$ distinct summands from $A$. What are necessary and sufficient\nconditions that this exists?\n\nA solution must fill in `Erdos338.erdos_338.answer` with the condition and prove the\nequivalence. Whether a condition is a satisfactory answer is up to human judgement.",
  "subjects": [
    "math.NT",
    "msc:11"
  ],
  "tags": [
    "question"
  ],
  "collection": "erdos",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "Erdos338.erdos_338",
  "statement_lean": "theorem erdos_338 :\n    ∀ A : Set ℕ, (∃ h, HasOrder A h) → ((∃ t, HasRestrictedOrder A t) ↔ erdos_338.answer A)",
  "challenge_source": "/-\nCopyright 2026 The Formal Conjectures Authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    https://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-/\nmodule\n\npublic import FormalConjecturesUtil\n\n/-!\n# Erdős Problem 338\n\n*References:*\n- [erdosproblems.com/338](https://www.erdosproblems.com/338)\n- [ErGr80] Erdős, P. and Graham, R., *Old and new problems and results in combinatorial number\n  theory*. Monographies de L'Enseignement Mathematique (1980).\n- [ErGr80b] Erdős, P. and Graham, R. L., *On bases with an exact order*. Acta Arith. (1980),\n  201-207.\n- [HHP07] Hegyvári, Norbert and Hennecart, François and Plagne, Alain, *Answer to a question by\n  Burr and Erdős on restricted addition, and related results*. Combin. Probab. Comput. (2007),\n  747--756.\n- [He05] Hennecart, François, *On the restricted order of asymptotic bases of order two*.\n  Ramanujan J. (2005), 123--130.\n- [Ke57] Kelly, John B., *Restricted bases*. Amer. J. Math. (1957), 258-264.\n- [Pa33] Pall, Gordon, *On Sums of Squares*. Amer. Math. Monthly (1933), 10-18.\n- [Sc54] Schinzel, A., *Sur la décomposition des nombres naturels en sommes de nombres\n  triangulaires distincts*. Bull. Acad. Polon. Sci. Cl. III. (1954), 409-410.\n-/\n\n@[expose] public section\n\nnamespace Erdos338\n\nopen Filter\n\n/-- `HasOrder A h` means that $A$ is a basis of order $h$: every sufficiently large natural number\nis a sum of at most $h$ elements of $A$, with repetition allowed.\n\nThe summands form a `Multiset`, so repetition is allowed. Allowing at most $h$ summands makes the\nnotion independent of whether $0 \\in A$. With exactly $h$ summands, as in\n`Set.IsAsymptoticAddBasisOfOrder`, this notion is `(insert 0 A).IsAsymptoticAddBasisOfOrder h`. -/\ndef HasOrder (A : Set ℕ) (h : ℕ) : Prop :=\n  ∀ᶠ m in atTop, ∃ S : Multiset ℕ, (∀ x ∈ S, x ∈ A) ∧ S.card ≤ h ∧ S.sum = m\n\n/-- `HasRestrictedOrder A t` means that every sufficiently large natural number is a sum of at most\n$t$ distinct elements of $A$.\n\nThe summands form a `Finset`, so they are distinct. A summand $0$ never helps, so the notion does\nnot depend on whether $0 \\in A$. -/\ndef HasRestrictedOrder (A : Set ℕ) (t : ℕ) : Prop :=\n  ∀ᶠ m in atTop, ∃ S : Finset ℕ, (∀ x ∈ S, x ∈ A) ∧ S.card ≤ t ∧ ∑ x ∈ S, x = m\n\n/-- The order of $A$: the least $h$ with `HasOrder A h`, or `⊤` if $A$ is not a basis. -/\nnoncomputable def basisOrder (A : Set ℕ) : ℕ∞ :=\n  ⨅ (h : ℕ) (_ : HasOrder A h), (h : ℕ∞)\n\n/-- The restricted order of $A$: the least $t$ with `HasRestrictedOrder A t`, or `⊤` if no such\n$t$ exists. -/\nnoncomputable def restrictedOrder (A : Set ℕ) : ℕ∞ :=\n  ⨅ (t : ℕ) (_ : HasRestrictedOrder A t), (t : ℕ∞)\n\ndef erdos_338.answer : Set ℕ → Prop := sorry\n\n/--\nThe restricted order of a basis $A$ is the least integer $t$ (if it exists) such that every large\ninteger is the sum of at most $t$ distinct summands from $A$. What are necessary and sufficient\nconditions that this exists?\n\nA solution must fill in `Erdos338.erdos_338.answer` with the condition and prove the\nequivalence. Whether a condition is a satisfactory answer is up to human judgement.\n-/\n@[category research open, question value, AMS 11]\ntheorem erdos_338 :\n    ∀ A : Set ℕ, (∃ h, HasOrder A h) → ((∃ t, HasRestrictedOrder A t) ↔ erdos_338.answer A) := by\n  sorry\n\n/--\nCan the restricted order of a basis be bounded (when it exists) in terms of the order of the\nbasis?\n\n`HasOrder A h` only says that the order of $A$ is at most $h$. This gives the same question,\nsince $f$ can be replaced by its running maximum. Kelly [Ke57] showed that $f(2) = 4$ works, and\nHennecart [He05] showed that $4$ is optimal. Hegyvári, Hennecart and Plagne [HHP07] showed that\nany such $f$ has $f(k) \\geq 2^{k-2}+k-1$ for $k \\geq 3$.\n-/\n@[category research open, question, AMS 11]\ntheorem erdos_338.variants.bounded_by_order :\n    ∃ f : ℕ → ℕ, ∀ (A : Set ℕ) (h : ℕ), HasOrder A h →\n      (∃ t, HasRestrictedOrder A t) → HasRestrictedOrder A (f h) := by\n  sorry\n\ndef erdos_338.variants.eq_order.answer : Set ℕ → Prop := sorry\n\n/--\nWhat are necessary and sufficient conditions that the restricted order of a basis $A$ is equal to\nthe order of $A$?\n\nFor a basis, `basisOrder A` is finite, so the equality also says that the restricted order exists.\nThe condition is `Erdos338.erdos_338.variants.eq_order.answer`, as in `Erdos338.erdos_338`.\n-/\n@[category research open, question value, AMS 11]\ntheorem erdos_338.variants.eq_order :\n    ∀ A : Set ℕ, (∃ h, HasOrder A h) →\n      (restrictedOrder A = basisOrder A ↔ erdos_338.variants.eq_order.answer A) := by\n  sorry\n\n/--\nIs it true that if $A \\setminus F$ is a basis for all finite sets $F$ then $A$ must have a\nrestricted order?\n-/\n@[category research open, question, AMS 11]\ntheorem erdos_338.variants.basis_after_finite_removal :\n    ∀ A : Set ℕ, (∀ F : Set ℕ, F.Finite → ∃ h, HasOrder (A \\ F) h) →\n      ∃ t, HasRestrictedOrder A t := by\n  sorry\n\n/--\nIs it true that if the sets $A \\setminus F$, for all finite sets $F$, are bases of the same order,\nthen $A$ must have a restricted order?\n\nWe read \"the same order\" literally: every $A \\setminus F$ has the same exact order $h$. This is\nequivalent to asking that the orders of the sets $A \\setminus F$ are bounded. Removing elements can\nonly raise the order, so if the orders are bounded, their maximum is attained at some $F_0$, and\n$A \\setminus F_0 \\subseteq A$ satisfies the literal hypothesis.\n-/\n@[category research open, question, AMS 11]\ntheorem erdos_338.variants.same_order_after_finite_removal :\n    ∀ A : Set ℕ,\n      (∃ h : ℕ, ∀ F : Set ℕ, F.Finite → basisOrder (A \\ F) = (h : ℕ∞)) →\n      ∃ t, HasRestrictedOrder A t := by\n  sorry\n\n/--\nIf $A \\setminus F$ is a basis for every finite set $F$ and $A$ has positive lower density, then\n$A$ has a restricted order. So `Erdos338.erdos_338.variants.basis_after_finite_removal` has a\npositive answer for sets of positive lower density.\n\nThis was shown by Daniel Veljjanoski on the\n[forum](https://www.erdosproblems.com/forum/thread/338#post-9251) (1 October 2026), with the\nbound $3\\lceil 8/\\delta^2\\rceil - 2$ on the restricted order, where $\\delta$ is the lower density\nof $A$. The linked formalisation proves the existence of a restricted order, not this bound.\n-/\n@[category research solved, AMS 11, formal_proof using lean4 at\n  \"https://palomar-registry.org/entry.html?id=PALOMAR-2026-11-03-000016\"]\ntheorem erdos_338.variants.lowerDensity_pos :\n    ∀ A : Set ℕ, (∀ F : Set ℕ, F.Finite → ∃ h, HasOrder (A \\ F) h) → 0 < A.lowerDensity →\n      ∃ t, HasRestrictedOrder A t := by\n  sorry\n\n/--\nBateman observed that for $h \\geq 3$ the set $A = \\{1\\} \\cup \\{x > 0 : h \\mid x\\}$ is a basis of\norder $h$ with no restricted order.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_338.variants.bateman (h : ℕ) (hh : 3 ≤ h) :\n    basisOrder (insert 1 {x : ℕ | 0 < x ∧ h ∣ x}) = h ∧\n      ¬ ∃ t, HasRestrictedOrder (insert 1 {x : ℕ | 0 < x ∧ h ∣ x}) t := by\n  sorry\n\n/--\nKelly [Ke57] showed that any basis of order $2$ has restricted order at most $4$.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_338.variants.kelly (A : Set ℕ) (hA : HasOrder A 2) : HasRestrictedOrder A 4 := by\n  sorry\n\n/--\nKelly [Ke57] showed that any basis of order $2$ with positive lower density has restricted order\nat most $3$.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_338.variants.kelly_lowerDensity (A : Set ℕ) (hA : HasOrder A 2)\n    (hd : 0 < A.lowerDensity) : HasRestrictedOrder A 3 := by\n  sorry\n\nsection KellyConjecture\n\n/-- `Ternary01 a` means that all base-$3$ digits of $a$ are $0$ or $1$. -/\nprivate inductive Ternary01 : ℕ → Prop\n  | zero : Ternary01 0\n  | three {a : ℕ} : Ternary01 a → Ternary01 (3 * a)\n  | three_add_one {a : ℕ} : Ternary01 a → Ternary01 (3 * a + 1)\n\n/-- The last base-$3$ digit of `a` is $0$ or $1$, and removing it gives a `Ternary01` number. -/\n@[category API, AMS 11]\nprivate lemma Ternary01.mod_div {a : ℕ} (h : Ternary01 a) : a % 3 ≤ 1 ∧ Ternary01 (a / 3) := by\n  cases h with\n  | zero => exact ⟨by norm_num, by rw [Nat.zero_div]; exact .zero⟩\n  | @three a h => exact ⟨by omega, by rwa [show 3 * a / 3 = a by omega]⟩\n  | @three_add_one a h => exact ⟨by omega, by rwa [show (3 * a + 1) / 3 = a by omega]⟩\n\n/-- Every natural number is `a + b` with `a` and `b` in `Ternary01`. -/\n@[category API, AMS 11]\nprivate lemma Ternary01.exists_add (k : ℕ) : ∃ a b, Ternary01 a ∧ Ternary01 b ∧ a + b = k := by\n  induction k using Nat.strong_induction_on with\n  | _ k ih =>\n    rcases Nat.eq_zero_or_pos k with rfl | hk\n    · exact ⟨0, 0, .zero, .zero, rfl⟩\n    obtain ⟨a, b, ha, hb, hab⟩ := ih (k / 3) (by omega)\n    rcases (by omega : k % 3 = 0 ∨ k % 3 = 1 ∨ k % 3 = 2) with h | h | h\n    · exact ⟨3 * a, 3 * b, ha.three, hb.three, by omega⟩\n    · exact ⟨3 * a + 1, 3 * b, ha.three_add_one, hb.three, by omega⟩\n    · exact ⟨3 * a + 1, 3 * b + 1, ha.three_add_one, hb.three_add_one, by omega⟩\n\n/-- Every natural number is `a + 2 * c` with `a` and `c` in `Ternary01`. -/\n@[category API, AMS 11]\nprivate lemma Ternary01.exists_add_two_mul (k : ℕ) :\n    ∃ a c, Ternary01 a ∧ Ternary01 c ∧ a + 2 * c = k := by\n  induction k using Nat.strong_induction_on with\n  | _ k ih =>\n    rcases Nat.eq_zero_or_pos k with rfl | hk\n    · exact ⟨0, 0, .zero, .zero, rfl⟩\n    obtain ⟨a, c, ha, hc, hac⟩ := ih (k / 3) (by omega)\n    rcases (by omega : k % 3 = 0 ∨ k % 3 = 1 ∨ k % 3 = 2) with h | h | h\n    · exact ⟨3 * a, 3 * c, ha.three, hc.three, by omega⟩\n    · exact ⟨3 * a + 1, 3 * c, ha.three_add_one, hc.three, by omega⟩\n    · exact ⟨3 * a, 3 * c + 1, ha.three, hc.three_add_one, by omega⟩\n\n/-- If `a`, `b` and `c` are in `Ternary01` and `a + b + 2 * c = 3 ^ j - 1`, then `a = b`. All\nbase-$3$ digits of $3^j-1$ are $2$, and comparing last digits shows that `a` and `b` have the\nsame last digit. -/\n@[category API, AMS 11]\nprivate lemma Ternary01.eq_of_add {a b c : ℕ} (ha : Ternary01 a) (hb : Ternary01 b)\n    (hc : Ternary01 c) (j : ℕ) (h : a + b + 2 * c + 1 = 3 ^ j) : a = b := by\n  induction j generalizing a b c with\n  | zero => rw [pow_zero] at h; omega\n  | succ j ih =>\n    obtain ⟨ha3, ha'⟩ := ha.mod_div\n    obtain ⟨hb3, hb'⟩ := hb.mod_div\n    obtain ⟨hc3, hc'⟩ := hc.mod_div\n    rw [pow_succ] at h\n    have := ih ha' hb' hc' (by omega)\n    omega\n\n/-- The numbers `2 * a + 1` and `4 * a` with `a` in `Ternary01`. -/\nprivate def ternaryBasis : Set ℕ := {m | ∃ a, Ternary01 a ∧ (m = 2 * a + 1 ∨ m = 4 * a)}\n\n@[category API, AMS 11]\nprivate lemma mem_ternaryBasis {m : ℕ} :\n    m ∈ ternaryBasis ↔ ∃ a, Ternary01 a ∧ (m = 2 * a + 1 ∨ m = 4 * a) :=\n  Iff.rfl\n\n/-- Every positive integer is a sum of at most two elements of `ternaryBasis`. -/\n@[category API, AMS 11]\nprivate lemma hasOrder_ternaryBasis : HasOrder ternaryBasis 2 := by\n  unfold HasOrder\n  refine eventually_atTop.2 ⟨1, fun m hm ↦ ?_⟩\n  obtain ⟨k, rfl | rfl⟩ := Nat.even_or_odd' m\n  · obtain ⟨a, b, ha, hb, hab⟩ := Ternary01.exists_add (k - 1)\n    refine ⟨{2 * a + 1, 2 * b + 1}, ?_, by simp, ?_⟩\n    · simp only [Multiset.insert_eq_cons, Multiset.mem_cons, Multiset.mem_singleton]\n      rintro x (rfl | rfl)\n      exacts [mem_ternaryBasis.2 ⟨a, ha, .inl rfl⟩, mem_ternaryBasis.2 ⟨b, hb, .inl rfl⟩]\n    · simp only [Multiset.insert_eq_cons, Multiset.sum_cons, Multiset.sum_singleton]\n      omega\n  · obtain ⟨a, c, ha, hc, rfl⟩ := Ternary01.exists_add_two_mul k\n    refine ⟨{2 * a + 1, 4 * c}, ?_, by simp, ?_⟩\n    · simp only [Multiset.insert_eq_cons, Multiset.mem_cons, Multiset.mem_singleton]\n      rintro x (rfl | rfl)\n      exacts [mem_ternaryBasis.2 ⟨a, ha, .inl rfl⟩, mem_ternaryBasis.2 ⟨c, hc, .inr rfl⟩]\n    · simp only [Multiset.insert_eq_cons, Multiset.sum_cons, Multiset.sum_singleton]\n      omega\n\n/-- `ternaryBasis` has no restricted order $3$: no number `2 * 3 ^ j` is a sum of at most three\ndistinct elements of `ternaryBasis`. -/\n@[category API, AMS 11]\nprivate lemma not_hasRestrictedOrder_ternaryBasis : ¬ HasRestrictedOrder ternaryBasis 3 := by\n  intro hR\n  unfold HasRestrictedOrder at hR\n  obtain ⟨N, hN⟩ := eventually_atTop.1 hR\n  obtain ⟨S, hSA, hS3, hSsum⟩ :=\n    hN (2 * 3 ^ N) (by have := Nat.lt_pow_self (n := N) (by norm_num : 1 < 3); omega)\n  have hP : 3 ^ N % 2 = 1 := Nat.odd_iff.1 (Odd.pow (by decide))\n  interval_cases h : S.card\n  · rw [Finset.card_eq_zero.1 h, Finset.sum_empty] at hSsum\n    omega\n  · obtain ⟨x, rfl⟩ := Finset.card_eq_one.1 h\n    rw [Finset.sum_singleton] at hSsum\n    obtain ⟨a, ha, rfl | rfl⟩ := mem_ternaryBasis.1 (hSA x (by simp)) <;> omega\n  · obtain ⟨x, y, hxy, rfl⟩ := Finset.card_eq_two.1 h\n    rw [Finset.sum_pair hxy] at hSsum\n    obtain ⟨a, ha, rfl | rfl⟩ := mem_ternaryBasis.1 (hSA x (by simp)) <;>\n      obtain ⟨b, hb, rfl | rfl⟩ := mem_ternaryBasis.1 (hSA y (by simp)) <;>\n      first\n      | omega\n      | (have := ha.eq_of_add hb .zero N (by omega); omega)\n  · obtain ⟨x, y, z, hxy, hxz, hyz, rfl⟩ := Finset.card_eq_three.1 h\n    rw [Finset.sum_insert (by simp [hxy, hxz]), Finset.sum_pair hyz] at hSsum\n    obtain ⟨a, ha, rfl | rfl⟩ := mem_ternaryBasis.1 (hSA x (by simp)) <;>\n      obtain ⟨b, hb, rfl | rfl⟩ := mem_ternaryBasis.1 (hSA y (by simp)) <;>\n      obtain ⟨c, hc, rfl | rfl⟩ := mem_ternaryBasis.1 (hSA z (by simp)) <;>\n      first\n      | omega\n      | (have := ha.eq_of_add hb hc N (by omega); omega)\n      | (have := ha.eq_of_add hc hb N (by omega); omega)\n      | (have := hb.eq_of_add hc ha N (by omega); omega)\n\nend KellyConjecture\n\n/--\nKelly [Ke57] conjectured that any basis of order $2$ has restricted order at most $3$.\n\nThis was disproved by Hennecart [He05], who constructed a basis of order $2$ with restricted\norder $4$.\n-/\n@[category research solved, question, AMS 11]\ntheorem erdos_338.variants.kelly_conjecture :\n    ¬ ∀ A : Set ℕ, HasOrder A 2 → HasRestrictedOrder A 3 :=\n  fun h ↦ not_hasRestrictedOrder_ternaryBasis (h _ hasOrder_ternaryBasis)\n\n/--\nThe set of squares has order $4$ and restricted order $5$ (see [Pa33]).\n\nHere $0$ is a square. The order is $4$ by Lagrange's four-square theorem, and is not $3$ because\nno integer $\\equiv 7 \\pmod 8$ is a sum of three squares.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_338.variants.squares :\n    basisOrder (Set.range fun k : ℕ ↦ k ^ 2) = 4 ∧\n      restrictedOrder (Set.range fun k : ℕ ↦ k ^ 2) = 5 := by\n  sorry\n\n/--\nThe set of triangular numbers has order $3$ and restricted order $3$ (see [Sc54]).\n\nHere $0$ is a triangular number.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_338.variants.triangular :\n    basisOrder (Set.range fun k : ℕ ↦ k * (k + 1) / 2) = 3 ∧\n      restrictedOrder (Set.range fun k : ℕ ↦ k * (k + 1) / 2) = 3 := by\n  sorry\n\n/--\nHegyvári, Hennecart and Plagne [HHP07] showed that for all $k \\geq 2$ there exists a basis of\norder $k$ which has restricted order at least $2^{k-2}+k-1$.\n\nThe basis built in the proof of Theorem 4 of [HHP07] (for $k \\geq 3$) has order exactly $k$ and a\nfinite restricted order, equal to $2^{k-2}+k-1$. The finiteness matters: without it, Bateman's\nexample `Erdos338.erdos_338.variants.bateman` would already give the bound. For $k = 2$ the bound\nis $2$, and $A = \\{1\\} \\cup \\{x : 2 \\mid x\\}$ works.\n-/\n@[category research solved, AMS 11]\ntheorem erdos_338.variants.hegyvari_hennecart_plagne :\n    ∀ k : ℕ, 2 ≤ k → ∃ A : Set ℕ,\n      basisOrder A = k ∧ restrictedOrder A = (2 ^ (k - 2) + k - 1 : ℕ) := by\n  sorry\n\nend Erdos338\n",
  "statement_hash": "f5bcf0c2d619951fd80da83f079fd6cef6914a2b06c452a4c56107972031cb62",
  "toolchain": "leanprover/lean4:v4.33.1",
  "upstream_commit": "f9b3868d5ca994a7bf95039bcec05338c0c21e2f",
  "workspace": "formal-conjectures",
  "field": "math",
  "formalization": "formal",
  "verification": "lean-kernel",
  "license": "Apache-2.0",
  "attribution": "google-deepmind/formal-conjectures contributors",
  "metric_name": null,
  "metric_direction": null,
  "critiques": [],
  "public_partial_proofs": [],
  "research_threads": [],
  "instructions": "Read research_threads first: other people's public repositories and what they already tried. Write Solution.lean starting from challenge_source. Keep every definition identical, prove decl_name with exactly the same type, no sorry in its dependency closure, no new axioms, no native_decide, no metaprogramming. Submit with POST /api/v1/submissions."
}