OFFSET
0,3
COMMENTS
Ternary modular function with three cases based on residue modulo 3.
The function defines a dynamical system with multiple periodic attractors.
Fixed point at 1: a(1) = 1.
From Miquel Cerda, Aug 06 2025: (Start)
Every nonnegative integer k appears at least once as a value in the sequence.
Inverse formulas (for possible preimages):
If k is even: one preimage is n = 3*k/2.
If k is odd: one preimage is n = (3*k - 1)/2.
If k == 5 (mod 7): there is an additional preimage: n = 3*(k - 5)/7 + 2. (End)
LINKS
Index entries for linear recurrences with constant coefficients, signature (0,0,2,0,0,-1).
FORMULA
G.f.: x*(1+5*x+2*x^2+x^3+2*x^4) / ( (x-1)^2*(1+x+x^2)^2 ). - R. J. Mathar, Jul 30 2025
EXAMPLE
a(0) = 2*0/3 = 0. a(1) = (2*1+1)/3 = 1. a(2) = (7*2+1)/3 = 5. a(3) = 2*3/3 = 2.
MATHEMATICA
a[x_] := Which[Mod[x, 3] == 0, 2*x/3, Mod[x, 3] == 1, (2*x + 1)/3, Mod[x, 3] == 2, (7*x + 1)/3]; Table[a[n], {n, 0, 50}]
PROG
(PARI) a(n) = if(n%3==0, 2*n/3, if(n%3==1, (2*n+1)/3, (7*n+1)/3))
(Python)
def A385938(n):
q, r = divmod(n, 3)
return (q<<1)+r if r<2 else 7*q+5 # Chai Wah Wu, Jul 17 2025
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Miquel Cerda, Jul 13 2025
STATUS
approved
