{
  "id": "2087",
  "ident": "NS.02087",
  "slug": "erdos-422",
  "title": "Erdős Problem 422",
  "status": "open",
  "statement_status": "reviewed",
  "statement_md": "Let $f(1) = f(2) = 1$ and for $n > 2$\n$$\nf(n) = f(n - f(n - 1)) + f(n - f(n - 2)).\n$$\nDoes $f(n)$ miss infinitely many integers?",
  "subjects": [
    "math.NT",
    "msc:11"
  ],
  "tags": [
    "question"
  ],
  "collection": "erdos",
  "source_url": null,
  "solved_on_platform": false,
  "needs_answer": false,
  "version": 1,
  "decl_name": "Erdos422.erdos_422",
  "statement_lean": "theorem erdos_422 :\n    ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → Set.Infinite {n | ∀ x, f x ≠ n}",
  "challenge_source": "/-\nCopyright 2025 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 422\n\n*References:*\n- [erdosproblems.com/422](https://www.erdosproblems.com/422)\n- [OEIS A005185](https://oeis.org/A005185)\n-/\n\n@[expose] public section\n\nnamespace Erdos422\n\nopen Filter\nopen scoped Topology\n\n/--\n`IsHofstadterQ f` means that $f$ is Hofstadter's $Q$-sequence (OEIS A005185): $f(1) = f(2) = 1$\nand for $n > 2$\n$$\nf(n) = f(n - f(n - 1)) + f(n - f(n - 2)),\n$$\nwhere the recurrence requires $f(n - 1) < n$ and $f(n - 2) < n$, so that both arguments on the\nright-hand side are positive integers. The sequence begins $1, 1, 2, 3, 3, 4, \\ldots$.\n\nAt most one function satisfies this predicate. Some function satisfies it if and only if $f(n)$ is\nwell-defined for all $n$, which is not known.\n-/\ndef IsHofstadterQ (f : ℕ+ → ℕ+) : Prop :=\n  f 1 = 1 ∧ f 2 = 1 ∧\n  ∀ n : ℕ+, 2 < n →\n    f (n - 1) < n ∧ f (n - 2) < n ∧ f n = f (n - f (n - 1)) + f (n - f (n - 2))\n\n/-- The third term of Hofstadter's $Q$-sequence is $f(3) = f(2) + f(2) = 2$. -/\n@[category test, AMS 11]\ntheorem erdos_422.test.f3 : ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → f 3 = 2 := by\n  intro f ⟨h1, h2, h⟩\n  obtain ⟨-, -, h3⟩ := h 3 (by decide)\n  simp only [h3, show (3 : ℕ+) - 1 = 2 from rfl, show (3 : ℕ+) - 2 = 1 from rfl, h1, h2]\n  rfl\n\n/-- The fourth term of Hofstadter's $Q$-sequence is $f(4) = f(2) + f(3) = 3$. -/\n@[category test, AMS 11]\ntheorem erdos_422.test.f4 : ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → f 4 = 3 := by\n  intro f hf\n  have h3 := erdos_422.test.f3 f hf\n  obtain ⟨h1, h2, h⟩ := hf\n  obtain ⟨-, -, h4⟩ := h 4 (by decide)\n  simp only [h4, show (4 : ℕ+) - 1 = 3 from rfl, show (4 : ℕ+) - 2 = 2 from rfl, h2, h3]\n  rfl\n\n/--\nLet $f(1) = f(2) = 1$ and for $n > 2$\n$$\nf(n) = f(n - f(n - 1)) + f(n - f(n - 2)).\n$$\nDoes $f(n)$ miss infinitely many integers?\n-/\n@[category research open, question, AMS 11]\ntheorem erdos_422 :\n    ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → Set.Infinite {n | ∀ x, f x ≠ n} := by\n  sorry\n\n/--\nIs $f$ surjective?\n-/\n@[category research open, question, AMS 11]\ntheorem erdos_422.variants.surjective :\n    ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → f.Surjective := by\n  sorry\n\ndef erdos_422.variants.growth_rate.answer : ℕ+ → ℝ := sorry\n\n/--\nHow does $f$ grow?\n-/\n@[category research open, question value, AMS 11]\ntheorem erdos_422.variants.growth_rate :\n    ∀ f : ℕ+ → ℕ+, IsHofstadterQ f →\n    (fun n ↦ (f n : ℝ)) =O[atTop] erdos_422.variants.growth_rate.answer := by\n  sorry\n\n/--\nHofstadter's $Q$-sequence is not eventually constant: if $f(n) = c$ for all large $n$, then the\nrecurrence gives $c = f(n - c) + f(n - c) = 2c$.\n-/\n@[category API, AMS 11]\ntheorem IsHofstadterQ.not_eventuallyConst {f : ℕ+ → ℕ+} (hf : IsHofstadterQ f) :\n    ¬ EventuallyConst f atTop := by\n  obtain ⟨-, -, hf⟩ := hf\n  intro h\n  obtain ⟨c, hc⟩ := eventuallyConst_iff_exists_eventuallyEq.mp h\n  obtain ⟨N, hN⟩ := eventually_atTop.mp hc\n  have hc0 := c.pos\n  -- Subtracting `k ≤ c + 1` from `n = N + c + 2` leaves an index that is still at least `N`.\n  have key (k : ℕ+) (hk : (k : ℕ) ≤ c + 1) : f (N + c + 2 - k) = c := hN _ <| by\n    have hlt : k < N + c + 2 := by\n      rw [← PNat.coe_lt_coe]; push_cast; omega\n    rw [← PNat.coe_le_coe, PNat.sub_coe, if_pos hlt]\n    push_cast; omega\n  have hn : f (N + c + 2) = c := hN _ <| by\n    rw [← PNat.coe_le_coe]; push_cast; omega\n  obtain ⟨-, -, hrec⟩ := hf (N + c + 2) (PNat.lt_add_left 2 (N + c))\n  -- The recurrence at `n` now reads `c = c + c`.\n  rw [hn, key 1 (Nat.le_add_left 1 c), key 2 (by push_cast; omega), key c (by omega)] at hrec\n  exact (PNat.lt_add_right c c).ne hrec\n\n/--\nDoes $f$ become stationary at some point?\n\nNo: see `IsHofstadterQ.not_eventuallyConst`. The statement is existential, so the answer does\nnot depend on whether $f(n)$ is well-defined for all $n$.\n-/\n@[category textbook, AMS 11]\ntheorem erdos_422.variants.eventually_const :\n    ¬ ∃ f : ℕ+ → ℕ+, IsHofstadterQ f ∧ EventuallyConst f atTop :=\n  fun ⟨_, hf, h⟩ ↦ hf.not_eventuallyConst h\n\n/--\nIs $f(n)$ well-defined for all $n$?\n-/\n@[category research open, question, AMS 11]\ntheorem erdos_422.variants.well_defined : ∃ f : ℕ+ → ℕ+, IsHofstadterQ f := by\n  sorry\n\nend Erdos422\n",
  "statement_hash": "d6d426493f28fed460017655716c8dbad59333693452cb53cf6a345cf6a2e682",
  "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."
}