/- Copyright 2025 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import FormalConjecturesUtil

Erdős Problem 422

References:

@[expose] public sectionnamespace Erdos422open Filteropen scoped Topology

IsHofstadterQ f means that $f$ is Hofstadter's $Q$-sequence (OEIS A005185): $f(1) = f(2) = 1$ and for $n > 2$ $$ f(n) = f(n - f(n - 1)) + f(n - f(n - 2)), $$ where the recurrence requires $f(n - 1) < n$ and $f(n - 2) < n$, so that both arguments on the right-hand side are positive integers. The sequence begins $1, 1, 2, 3, 3, 4, \ldots$.

At most one function satisfies this predicate. Some function satisfies it if and only if $f(n)$ is well-defined for all $n$, which is not known.

def IsHofstadterQ (f : ℕ+ → ℕ+) : Prop := f 1 = 1 ∧ f 2 = 1 ∧ ∀ n : ℕ+, 2 < n → f (n - 1) < n ∧ f (n - 2) < n ∧ f n = f (n - f (n - 1)) + f (n - f (n - 2))

The third term of Hofstadter's $Q$-sequence is $f(3) = f(2) + f(2) = 2$.

f:ℕ+ → ℕ+h1:f 1 = 1h2:f 2 = 1h:∀ (n : ℕ+), 2 < n → f (n - 1) < n ∧ f (n - 2) < n ∧ f n = f (n - f (n - 1)) + f (n - f (n - 2))h3:f 3 = f (3 - f (3 - 1)) + f (3 - f (3 - 2))⊢ f 3 = 2 f:ℕ+ → ℕ+h1:f 1 = 1h2:f 2 = 1h:∀ (n : ℕ+), 2 < n → f (n - 1) < n ∧ f (n - 2) < n ∧ f n = f (n - f (n - 1)) + f (n - f (n - 2))h3:f 3 = f (3 - f (3 - 1)) + f (3 - f (3 - 2))⊢ 1 + 1 = 2 All goals completed! 🐙

The fourth term of Hofstadter's $Q$-sequence is $f(4) = f(2) + f(3) = 3$.

f:ℕ+ → ℕ+h3:f 3 = 2h1:f 1 = 1h2:f 2 = 1h:∀ (n : ℕ+), 2 < n → f (n - 1) < n ∧ f (n - 2) < n ∧ f n = f (n - f (n - 1)) + f (n - f (n - 2))h4:f 4 = f (4 - f (4 - 1)) + f (4 - f (4 - 2))⊢ f 4 = 3 f:ℕ+ → ℕ+h3:f 3 = 2h1:f 1 = 1h2:f 2 = 1h:∀ (n : ℕ+), 2 < n → f (n - 1) < n ∧ f (n - 2) < n ∧ f n = f (n - f (n - 1)) + f (n - f (n - 2))h4:f 4 = f (4 - f (4 - 1)) + f (4 - f (4 - 2))⊢ 1 + 2 = 3 All goals completed! 🐙

Let $f(1) = f(2) = 1$ and for $n > 2$ $$ f(n) = f(n - f(n - 1)) + f(n - f(n - 2)). $$ Does $f(n)$ miss infinitely many integers?

@[category research open, question, AMS 11] theorem erdos_422 : ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → Set.Infinite {n | ∀ x, f x ≠ n} := ⊢ ∀ (f : ℕ+ → ℕ+), IsHofstadterQ f → {n | ∀ (x : ℕ+), f x ≠ n}.Infinite All goals completed! 🐙

Is $f$ surjective?

@[category research open, question, AMS 11] theorem erdos_422.variants.surjective : ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → f.Surjective := ⊢ ∀ (f : ℕ+ → ℕ+), IsHofstadterQ f → Function.Surjective f All goals completed! 🐙def erdos_422.variants.growth_rate.answer : ℕ+ → ℝ := sorry

How does $f$ grow?

@[category research open, question value, AMS 11] theorem erdos_422.variants.growth_rate : ∀ f : ℕ+ → ℕ+, IsHofstadterQ f → (fun n ↦ (f n : ℝ)) =O[atTop] erdos_422.variants.growth_rate.answer := ⊢ ∀ (f : ℕ+ → ℕ+), IsHofstadterQ f → (fun n ↦ ↑↑(f n)) =O[atTop] growth_rate.answer All goals completed! 🐙

Hofstadter's $Q$-sequence is not eventually constant: if $f(n) = c$ for all large $n$, then the recurrence gives $c = f(n - c) + f(n - c) = 2c$.

f:ℕ+ → ℕ+hf:∀ (n : ℕ+), 2 < n → f (n - 1) < n ∧ f (n - 2) < n ∧ f n = f (n - f (n - 1)) + f (n - f (n - 2))h:EventuallyConst f atTopc:ℕ+hc:f =ᶠ[atTop] fun x ↦ cN:ℕ+hN:∀ (b : ℕ+), N ≤ b → f b = (fun x ↦ c) bhc0:0 < ↑ckey:∀ (k : ℕ+), ↑k ≤ ↑c + 1 → f (N + c + 2 - k) = chn:f (N + c + 2) = chrec:c = c + c⊢ False All goals completed! 🐙

Does $f$ become stationary at some point?

No: see IsHofstadterQ.not_eventuallyConst. The statement is existential, so the answer does not depend on whether $f(n)$ is well-defined for all $n$.

@[category textbook, AMS 11] theorem erdos_422.variants.eventually_const : ¬ ∃ f : ℕ+ → ℕ+, IsHofstadterQ f ∧ EventuallyConst f atTop := fun ⟨_, hf, h⟩ ↦ hf.not_eventuallyConst h

Is $f(n)$ well-defined for all $n$?

@[category research open, question, AMS 11] theorem erdos_422.variants.well_defined : ∃ f : ℕ+ → ℕ+, IsHofstadterQ f := ⊢ ∃ f, IsHofstadterQ f All goals completed! 🐙end Erdos422