/- Copyright 2026 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

Prime-th recurrence with reversal at each step

$$a(n) = \operatorname{reversal}(p_{a(n-1)})$$ with $a(0)=1$, where $p_k$ is the $k$-th prime number.

References:

@[expose] public sectionnamespace OeisA100475open Nat List

Reverses the base 10 digits of a natural number.

def reverseDigits (k : ) : := Nat.ofDigits 10 (Nat.digits 10 k |>.reverse)

The primary defining sequence a. a n is the Prime-th recurrence with reversal at each step. $a(n) = \operatorname{reversal}(p_{a(n-1)})$ with $a(0)=1$, where $p_k$ is the $k$-th prime number (i.e., $p_1=2, p_2=3, \dots$).

noncomputable def a : | 0 => 1 | n + 1 => let k := a n if k = 0 then 0 else reverseDigits (Nat.nth Nat.Prime (k - 1))@[category API, AMS 11] lemma a_succ (n : ) : a (n + 1) = if a n = 0 then 0 else reverseDigits (Nat.nth Nat.Prime (a n - 1)) := n:a (n + 1) = if a n = 0 then 0 else reverseDigits (nth Nat.Prime (a n - 1)) All goals completed! 🐙

Term theorems verifying the first few values of the sequence against the official OEIS b-file

@[category test, AMS 11] theorem a_0 : a 0 = 1 := a 0 = 1 All goals completed! 🐙(if 1 = 0 then 0 else reverseDigits (nth Nat.Prime (1 - 1))) = 2 All goals completed! 🐙(if 2 = 0 then 0 else reverseDigits (nth Nat.Prime (2 - 1))) = 3 All goals completed! 🐙(if 3 = 0 then 0 else reverseDigits (nth Nat.Prime (3 - 1))) = 5 All goals completed! 🐙(if 5 = 0 then 0 else reverseDigits (nth Nat.Prime (5 - 1))) = 11 ofDigits 10 [1, 1] = 11 All goals completed! 🐙

Definition of the generalized sequence starting at x.

noncomputable def aStartAt (x : ) : | 0 => x | n + 1 => let k := aStartAt x n if k = 0 then 0 else reverseDigits (Nat.nth Nat.Prime (k - 1))

A sequence $f : \mathbb{N} \to \mathbb{N}$ is ultimately periodic if there exist $N, P \in \mathbb{N}$, with $P>0$, such that for all $n \ge N$, $f(n+P) = f(n)$.

def IsUltimatelyPeriodic (f : ) : Prop := N P, P > 0 n, n N f (n + P) = f n

The totalized recurrence stays at zero when initialized at zero. The OEIS recurrence itself uses one-based prime indices, so this is a boundary behavior of the formalization rather than a term of the original sequence.

@[category API, AMS 11] lemma aStartAt_zero (n : ) : aStartAt 0 n = 0 := n:aStartAt 0 n = 0 induction n with aStartAt 0 0 = 0 All goals completed! 🐙 n:ih:aStartAt 0 n = 0aStartAt 0 (n + 1) = 0 All goals completed! 🐙

If zero is admitted as a starting value, then a start other than $1$ does go into a loop: the sequence starting at zero is constant. This records the degenerate answer created by totalizing the one-based prime recurrence at index zero.

All goals completed! 🐙 (∃ x, x 1 IsUltimatelyPeriodic (aStartAt x)) True a✝: x, x 1 IsUltimatelyPeriodic (aStartAt x)True All goals completed! 🐙

Starting at a positive value other than $a(0) = 1$, does this sequence ever go into a loop?

The positivity hypothesis is required because the source recurrence uses the one-based prime index p₁ = 2; the x = 0 branch above is only an artifact of making aStartAt total on .

@[category research open, AMS 11] theorem conjecture : answer(sorry) x : , 0 < x x 1 IsUltimatelyPeriodic (aStartAt x) := True x, 0 < x x 1 IsUltimatelyPeriodic (aStartAt x) All goals completed! 🐙end OeisA100475