/-
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.
-/modulepublicimportFormalConjecturesUtil
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.
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$).
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)$.
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.
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.
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 ℕ.