/- 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. -/ 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:

namespace 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

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

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