Post Reply 
OEIS A167390: Cumbersome formula
08-28-2022, 10:39 AM
Post: #1
OEIS A167390: Cumbersome formula
Some years ago I came up with a formula to calculate the elements of this series

https://oeis.org/A167390

& while the formula gives correct answers I am uncomfortable with it & fail to find a more economic replacement.

I am interested to see if any members here can suggest a more elegant solution.

On my HP 33s the programme has

LN = 155 CK = 7D43
Find all posts by this user
Quote this message in a reply
08-28-2022, 11:52 AM
Post: #2
RE: OEIS A167390: Cumbersome formula
Code:

a(14)=1+2+4+3...

Interesting problem, at first I though this wasn't a useful sequence, but after some more review, I believe
you've found a very dangerous generating sequence from the Book of Armaments!

If you are so inclined with difficult, but not useful problems (as many of us are!) rather than obtuse sequences from OEIS, may I suggest some of the problems from Project Euler?

Unlike the dusty corners of integer sequences, many Euler Problems are of practical use, and are FAR more pedagogically useful (even if some can't be done on the hand held), many can.

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
08-28-2022, 07:52 PM (This post was last modified: 08-28-2022 08:38 PM by Allen.)
Post: #3
RE: OEIS A167390: Cumbersome formula
It's probably more comprehensible to understand the function NOT through the OEIS description, but by looking a the derivative of the integer sequence..

[0,1,2,4,3,9,5,16,6,25,7,36,8,49,10,64 ]

so the general pseudo code is:
Code:

loop x over input n 
  if x is odd:
       tally += ((x+1)/2)^2
  else:
       if x is the next highest perfect square:
           small counter += 1
           square counter += 1
       small counter += 1 
       tally+=small counter
recall tally


This lends itself well to loops in RPN rather than a closed form solution (not optimized for size- probably missing some obvious byte savings):


(NOTE: Unlike the original OEIS sequence, I assume f(0)==0 so there is no offset to contend with.)

Code:

00 { 63-Byte Prgm }
01 STO 00   // 00 is the input value
02 SIGN     // put 1 on stack
03 STO 02   // 02 is the small counter
04 STO 03   // 03 is the skip ( n^2) counter
05 STO 04   // 04 increment counter from 1 to n
06 0
07 STO 01   // running tally ( starting with f(0)==0 ) 
08▸LBL 00   // <-------------------- main loop
09 RCL 04
10 2
11 MOD
12 X≠0?     // if counter is odd go to LBL 01
13 GTO 01   // \\ x is even 
14 RCL 03
15 1
16 +
17 X↑2
18 RCL 02
19 1
20 +
21 X≠Y?      //  check to see if the counter+1 is the next perfect square
22 GTO 03
23 ISG 02    // advance the small counter by 1 (extra)
24 ENTER
25 ISG 03    // advance the skip counter by 1 (to skip the next square)
26▸LBL 03    // x is NOT the next square.. only 
27 ISG 02    // advance the small counter by 1 (defult)
28 ENTER     // NOP
29 RCL 02
30 STO+ 01   // add the small counter to the tally
31 GTO 04
32▸LBL 01   // x is odd
33 1
34 RCL+ 04
35 2
36 ÷        // add ((x+1)/2)^2 to the tally
37 X↑2
38 STO+ 01
39▸LBL 04   //  end of loop
40 ISG 04   // increment the counter
41 ENTER
42 DSE 00   // check the outer loop counter
43 GTO 00
44 RCL 01   //recall result to X
45 .END.

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
Post Reply 




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