Post Reply 
Programming Exercise (HP-15C, 15C LE - and others)
03-17-2014, 07:14 AM (This post was last modified: 03-18-2014 02:32 AM by Gerson W. Barbosa.)
Post: #5
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-16-2014 05:23 AM)Thomas Klemm Wrote:  I'm lazy and just leave a link to the HP-15C Mini-challenge: Speeding it up !

Hello Thomas,

Sorry for yet another reply to the same part of your post, but it just happens I finally understood what you meant by being "lazy" (I am sometimes rather slow at understanding such things). You must have thought this was just a re-post of Valentin's mini-challenge in disguise, so it was not worth any effort of your part or anyone else's (hence your posting of the above link), mustn't you?

The fact is that I found the above problem in one of my old text-books and decided to check the sums on a 10-digit RPN calculator. At first I used an HP-12C. A very simple problem indeed, 21 or 22 steps in my first attempt. But I thought trying to use the least number of steps would be an interesting exercise. For this task I switched to the HP-15C, because of DSE and recall arithmetic and managed to save a few steps. Then I decided to search for correct term or factor. The first thing I tried worked nicely:


30 f A CHS --> 0.676758138 ; sum of the first 30 terms
CHS 2 LN + 1/x --> 61.01637576 ; this means the first term of the cont'd fraction is 61
f FRAC 1/x --> 61.06586809 ; the second term of the cont'd fraction is also 61

That is,

Ln(2) ~ Sum(1..30,(-1)^(n - 1)/n) + 1/(61 + 1/61) = 0.693147176

Further tests have finally allowed for the generalization

Ln(2) ~ Sum(1..N,(-1)^(n - 1)/n) + 1/((2*N + 1) + 1/(2*N + 1))

At this point I remembered of an old challenge or mini-challenge by Valentin on the acceleration of a slowly convergent series for pi. As I said, it took me quite a while to find it (I was searching for acceleration instead of speeding-up). I read briefly through his commented solution but failed to notice it was essentially the same thing. He had noticed many matching digits of the constant for certain N, which I did not, and found suitable correction terms based on his observations. Also, I didn't notice his mention of other constants like Ln(2) at the end. As I had used a different approach, I thought this would be a valid exercise and decided not to included the link to Valentin's mini-challenge, as it prevent the solutions I was expecting to appear. But again, no problem!

As I am at it, I decided to apply the same approach to Valentin's problem. The continued fraction correction term is even more simple and easy to implement using a few steps:

1/(N + 1/(4*N))

Valentin's original program (two correction terms) can be rewritten using the same number of steps:

Code:

# --------------------------------------------
# HEWLETT·PACKARD 15C Simulator program
# Created with version 3.3.00
# --------------------------------------------
# --------------------------------------------

   000 {             } 
   001 {    42 21 11 } f LBL A
   002 {          36 } ENTER
   003 {       44 25 } STO I
   004 {    44 40 25 } STO + I
   005 {           4 } 4
   006 {       44  0 } STO 0
   007 {          20 } ×
   008 {          15 } 1/x
   009 {          40 } +
   010 {          15 } 1/x
   011 {           0 } 0
   012 {    42 21  0 } f LBL 0
   013 {    42  5 25 } f DSE I
   014 {       45  0 } RCL 0
   015 {          16 } CHS
   016 {       44  0 } STO 0
   017 {    45 10 25 } RCL ÷ I
   018 {          40 } +
   019 {    42  5 25 } f DSE I
   020 {       22  0 } GTO 0
   021 {          40 } +
   022 {       43 32 } g RTN

# --------------------------------------------

Like the program for Ln(2), 66 terms are required for the best 10-digit result for pi, 3.141592654.

Just for the record, here are my programs (Dropbox link)

Again, it was not my intention to consciously re-post an old third-party problem. At least in one occasion I tried to solve a problem I didn't had solved at the time, but then I would make it explicitly clear (as in message #20 of this thread)

Best regards,

Gerson.

P.S.: This correction term will give 10 correct digits for only 22 terms of the series for pi, same as in Paul Dale's non-published HP-42S program:

1/(88 + 1/(22 + 1/22))

The first terms of the continued fraction term for the series for pi appear to be:

1/(4*N + 1/(N + 1/(N + (9/(4*N + 16/N)))))

For N = 1000, this correction term will give 30+ correct digits.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Exercise (HP-15C, 15C LE - and others) - Gerson W. Barbosa - 03-17-2014 07:14 AM



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