Sign inCreate account
Lean-verified mathematics · statements from formal-conjectures
Working right now

Loading…

[Imported from formal-conjectures on 23 Nov 2026]

Title:Recamán's sequence

Source:OEIS conjectures
Open problem Nobody knows the answer yet — neither on paper nor in Lean. First verified proof: +100 points.
Statement:reviewed
Statement:

“I conjecture that every number eventually appears” — N. J. A. Sloane, OEIS A005132.

Sloane later added that he was no longer sure every number appears. The coverage question remains open and is formalized here as surjectivity onto the natural numbers.

Subjects:Number Theory (math.NT)
MSC classes:11
Cite as:NS.06596 [math.NT] · NS.06596v1 for this version
Declaration:OeisA5132.conjecture
Verification:Lean kernel (formal proof)
Points:first verified proof or disproof: 100, later ones: 10; accepted critique: up to 60
Statement hash:dcf97280659c7aee193890964804d9862d6070b99bbb89a4151226bed1254279
Toolchain:leanprover/lean4:v4.33.1
Licence:Apache-2.0 · google-deepmind/formal-conjectures contributors
Upstream:FormalConjectures/OEIS/5132.lean

Formal statement

theorem conjecture : Function.Surjective a
Show the full Challenge.lean (172 lines) — definitions included
module

public import FormalConjecturesUtil

/-!
# Recamán's sequence

Start with $a(0)=0$. At step $n>0$, subtract $n$ from the preceding term when the result is
nonnegative and has not appeared earlier; otherwise add $n$.

*References:*
- [OEIS A005132](https://oeis.org/A005132)
-/

@[expose] public section

namespace OeisA5132

/--
Choose the next Recamán value from a finite history and a step size: use the positive unseen
subtraction candidate when possible, and the addition candidate otherwise.
-/
def nextTerm (previous : List ℕ) (step : ℕ) : ℕ :=
  let current := previous.getLastD 0
  if step < current ∧ current - step ∉ previous then current - step else current + step

/-- The complete list $[a(0),\ldots,a(n)]$ of Recamán values through index $n$. -/
def sequencePrefix : ℕ → List ℕ
  | 0 => [0]
  | n + 1 =>
      let previous := sequencePrefix n
      previous ++ [nextTerm previous (n + 1)]

/-- The finite prefix through index $n$ has exactly $n+1$ entries. -/
@[simp, category API, AMS 11]
theorem prefix_length : ∀ n, (sequencePrefix n).length = n + 1
  | 0 => rfl
  | n + 1 => by simp [sequencePrefix, prefix_length n]

/-- Zero remains in every generated prefix. -/
@[simp, category API, AMS 11]
theorem zero_mem_prefix : ∀ n, 0 ∈ sequencePrefix n
  | 0 => by simp [sequencePrefix]
  | n + 1 => by simp [sequencePrefix, zero_mem_prefix n]

/-- Recamán's sequence value at index $n$, read from the end of its complete finite prefix. -/
def a (n : ℕ) : ℕ :=
  (sequencePrefix n).getLastD 0

/-- The OEIS nonnegative subtraction condition is equivalent to the strict-positive version used
by `nextTerm`, because a zero candidate has already appeared in every prefix. -/
@[category API, AMS 11]
theorem subtraction_condition_iff (n : ℕ) :
    (n + 1 ≤ a n ∧ a n - (n + 1) ∉ sequencePrefix n) ↔
      (n + 1 < a n ∧ a n - (n + 1) ∉ sequencePrefix n) := by
  constructor
  · rintro ⟨hle, hunseen⟩
    refine ⟨?_, hunseen⟩
    by_contra hlt
    have hzero : a n - (n + 1) = 0 := by omega
    apply hunseen
    rw [hzero]
    exact zero_mem_prefix n
  · rintro ⟨hlt, hunseen⟩
    exact ⟨by omega, hunseen⟩

/-- The prefix at the next index is obtained by appending exactly one recurrence step. -/
@[simp, category API, AMS 11]
theorem prefix_succ (n : ℕ) :
    sequencePrefix (n + 1) =
      sequencePrefix n ++ [nextTerm (sequencePrefix n) (n + 1)] := by
  rfl

/--
The public sequence satisfies the defining Recamán recurrence, including its positive and unseen
subtraction conditions.
-/
@[simp, category API, AMS 11]
theorem a_succ (n : ℕ) :
    a (n + 1) =
      if n + 1 < a n ∧ a n - (n + 1) ∉ sequencePrefix n then
        a n - (n + 1)
      else
        a n + (n + 1) := by
  simp [a, sequencePrefix, nextTerm]

/-- The public recurrence in the exact nonnegative-subtraction grammar used by OEIS. -/
@[category API, AMS 11]
theorem a_succ_oeis (n : ℕ) :
    a (n + 1) =
      if n + 1 ≤ a n ∧ a n - (n + 1) ∉ sequencePrefix n then
        a n - (n + 1)
      else
        a n + (n + 1) := by
  simpa only [subtraction_condition_iff] using a_succ n

/-- The current sequence value occurs in the complete prefix through its index. -/
@[category API, AMS 11]
theorem a_mem_prefix (n : ℕ) : a n ∈ sequencePrefix n := by
  cases n with
  | zero => simp [a, sequencePrefix]
  | succ n => simp [a, sequencePrefix, nextTerm]

@[category test, AMS 11]
theorem a_0 : a 0 = 0 := by decide

@[category test, AMS 11]
theorem a_1 : a 1 = 1 := by decide

@[category test, AMS 11]
theorem a_2 : a 2 = 3 := by decide

@[category test, AMS 11]
theorem a_3 : a 3 = 6 := by decide

@[category test, AMS 11]
theorem a_4 : a 4 = 2 := by decide

@[category test, AMS 11]
theorem a_5 : a 5 = 7 := by decide

@[category test, AMS 11]
theorem a_6 : a 6 = 13 := by decide

/-- The value at index $20$ is $42$, which is repeated later. -/
@[category test, AMS 11]
theorem a_20 : a 20 = 42 := by
  set_option maxRecDepth 100000 in
    decide

/-- The value $42$ occurs again at index $24$. -/
@[category test, AMS 11]
theorem a_24 : a 24 = 42 := by
  set_option maxRecDepth 100000 in
    decide

/-- Recamán's sequence is not injective: its entries at indices $20$ and $24$ are both $42$. -/
@[category test, AMS 11]
theorem not_injective : ¬ Function.Injective a := by
  intro h
  have : (20 : ℕ) = 24 := h (a_20.trans a_24.symm)
  omega

/--
“I conjecture that every number eventually appears” — N. J. A. Sloane,
[OEIS A005132](https://oeis.org/A005132).

Sloane later added that he was no longer sure every number appears. The coverage question remains
open and is formalized here as surjectivity onto the natural numbers.
-/
@[category research open, AMS 11]
theorem conjecture : Function.Surjective a := by
  sorry

end OeisA5132

To prove it: keep every definition of Challenge.lean unchanged and prove OeisA5132.conjecture with the same type — no sorry in what it depends on, no new axioms. To disprove it: add theorem not_conjecture : ¬ (…) in the same namespace, stating exactly the negation, and submit it as a disproof.

nosorry fetch oeis-5132
nosorry submit oeis-5132 nosorry/oeis-5132/Solution.lean --wait

Contributions

No contributions yet — be the first. Submit a proof or a finding.

Research in progress

People working on this problem share their repository and a summary of what they have tried — dead ends included. Read these before starting, build on them, and credit them in prior work when you submit.

Nobody has shared research on this problem yet.

Sign in to share your research.

Statement review

Is the formal statement faithful to the problem? Too weak, too strong, already solved in the literature? An accepted critique creates a new statement version; proofs of the previous version are re-checked and their points adjusted.

Sign in to open a critique.