Post Reply 
(33s) OEIS A2516: EARLIEST SEQUENCE WITH A(A(N)) = 2N
07-31-2022, 08:14 AM (This post was last modified: 10-23-2022 07:42 AM by C.Ret.)
Post: #2
RE: (33s): OEIS A2516 EARLIEST SEQUENCE WITH A(A(N)) = 2N
Hello,

First of all, thank you for sharing this subject, curious by nature, I am glad to discover a type of sequence that I did not know before.

Unfortunately, I am not an HP-33s user, but if I interpret the code correctly, the calculation of the n-th element of the sequence is done by recurrence. Which explains the limitation to 2^7 due to the limited number of nested calls.

I propose below a code for HP-41C, which I hope will be easily adapted for HP-33s, based on an iterative calculation. A loop make it easy to calculate all the elements of the sequence without any limitation as long as their values ​​or index can be represented without rounding.

The principle of this calculation is based on the observation of the structure of the formulas making it possible to calculate each \( u_n \) in the form \( u_n=p\times \left ( a.k+b \right ) \).
The calculation loop runs as long as the indices to be calculated are even. This loop doubles the coefficient \( p \) and halves the indice \( k \).
If the index is odd, the coefficients \( a \) and \( b \) are calculated according to the value of \( ( k \mod 4 ) \).

\( u_n = p\times\left ( a.k+b \right )=\left\{\begin{matrix}
u_{4k }&=&2\times& &u_{2k}&&(m=0)&\textit{even}&:&p&\leftarrow& 2.p&k&\leftarrow& k/2 &\textit{loop} \\
u_{4k+1}&=&& 4.k& + &3&(m=1)&\textit{odd}&:&a&\leftarrow& 4 &b&\leftarrow& 3 &\textit{terminate}\\
u_{4k+2}&=&2\times& &u_{2k+1} & &(m=2)&\textit{even}&:&p&\leftarrow& 2.p&k&\leftarrow& k/2 &\textit{loop} \\
u_{4k+3}&=& & 8.k& + &2&(m=3)&\textit{odd}&:&a&\leftarrow& 8 &b&\leftarrow& 2 &\textit{terminate}\\
\end{matrix}\right. \)

The code only use register R00.

01 LBL"OEIS002516
02   STO 00  1  2  GTO 02       // Initialization
06   LBL 01                  // *** Even loop  
07     RDN  ST* 00  ST* Y       //     p←2p    i←i/2
10     LBL 02                //   loop entrance
11     RCL 00  X=0?  RTN        //     u(0) = 0 STOP  
14     4  ST/ 00  MOD         //     k← i/4    M← i MOD 4
17     X≠Y?  X=0?  GTO 01       //     loop while M in { 0 ; 2 } 
20   X<>Y                   // *** Odd termination  M in { 1 ; 3 }
21   ST* Y  +                // compute a ← 2.M+2 
24   ENTER^  CHS  4  ST/ Y  +    // compute b ← 4-a/4
28   X<>Y  RCL 00  INT  *  +  *  // compute u(n) ← p*(a.k+b)
34 END                     // u(n) so that u(u(n))=2n (OEIS002516)


Usage:
Enter indice n and press [R/S].
The value of u(n) is calculated and left in the display register X:. This makes it easy to verify that u(u(n))=2n; simply press [R/S] again.

Example:
2147483648 [R/S] 6442450944. [R/S] 4294967296.
835584 [R/S] 1605632.000 [R/S] 1671168.000
75861 [R/S] 75863.0000 [R/S] 151722.0000
1024 [R/S] 3072.0000 [R/S] 2048.0000
30 [R/S] 52.0000 [R/S] 60.0000
2 [R/S] 6.0000 [R/S] 4.0000
1 [R/S] 3.0000 [R/S] 2.0000
0 [R/S] 0.0000


Finally, just to satisfy my curiosity, what is a "real integer"?
I know the integers, the real, the rational and the irrational,... as well as the natural integers, the relative integers, positive or negative integers...
Is there any unreal integers ?

Numerous editions to correct broken english and typos.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (33s): OEIS A2516 EARLIEST SEQUENCE WITH A(A(N)) = 2N - C.Ret - 07-31-2022 08:14 AM



User(s) browsing this thread: 6 Guest(s)