(35S) spigot algorithm for the digits of PI
05-30-2015, 05:03 PM (This post was last modified: 06-15-2017 01:20 PM by Gene.)
Post: #1
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
(35S) spigot algorithm for the digits of PI
Program:
Code:
P001 LBL P      P018 FS? 0      P035 INT÷ P002 STO N      P019 GTO P022   P036 DSE J P003 4          P020 RCL(J)     P037 GTO P017 P004 INT÷       P021 GTO P023   P038 ENTER P005 STO I      P022 2E3        P039 CF 0 P006 CLx        P023 RCL× F     P040 RCL F P007 STO D      P024 +          P041 INT÷ P008 STO E      P025 1          P042 RCL+ E P009 1E4        P026 RCL J      P043 STO P P010 STO F      P027 ENTER      P044 VIEW P P011 SF 0       P028 +          P045 x<>y P012 14         P029 x<>y       P046 RCL F P013 RCL× I     P030 −          P047 RMDR P014 STO J      P031 RMDR       P048 STO D P015 DSE J      P032 STO(J)     P049 STO E P016 RCL D      P033 x<>y       P050 DSE I P017 RCL× J     P034 LASTx      P051 GTO P012

Usage:
Calculate the first 40 digits of $$\pi$$: 3.141592653589793238462643383279502884197

40 XEQ P001

For the next digits to appear just keep hitting the [R/S] button:
Code:
P=       3141       5926       5358       9793       2384       6264       3383       2795        288     <<< mind the missing 0       4197

This is a translation of the C-program from:
Pi Unleashed.
Jörg Arndt, Christoph Hänel

Rediscovered in: A Sigma Function in the 35s Solver!
05-30-2015, 09:33 PM (This post was last modified: 05-30-2015 09:40 PM by Steve Simpkin.)
Post: #2
 Steve Simpkin Senior Member Posts: 389 Joined: Dec 2013
RE: (HP-35s) spigot algorithm for the digits of $$\pi$$
Thanks for the fun program!

A couple of notes:

Set display format to ALL for best results.

On my HP35s, 40 XEQ P001 takes about 33 seconds to execute. The next press of R/S takes about 26 seconds. The execution time of each subsequent press of R/S gets progressively smaller with about 3 seconds for the final calculation.

Do not press R/S after the final calculation. The execution time will be very long.
05-31-2015, 03:11 AM
Post: #3
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: (HP-35s) spigot algorithm for the digits of $$\pi$$
Instead of 4 digits a time we can display 5 or 6 digits together.
For this the magic numbers have to be adjusted accordingly.

5 digits:
Code:
P003 5 P009 1E5 P012 17 P022 2E4

6 digits:
Code:
P003 6 P009 1E6 P012 21 P022 2E5

Make sure the GTO-commands still point to the correct lines after changing the program.
05-31-2015, 03:39 AM
Post: #4
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: (HP-35s) spigot algorithm for the digits of $$\pi$$
(05-30-2015 09:33 PM)Steve Simpkin Wrote:  The execution time of each subsequent press of R/S gets progressively smaller with about 3 seconds for the final calculation.

Quote:   The second improvement is really a textbook tip which, however,
was evidently forgotten in the original formulation of the spigot algo-
rithm. Namely, with a radix conversion, after each result place, one can
shorten the remainder that still has to be converted, by the number of
bits or the result place. Hence after each calculation of one place con-
sisting of 4 decimal digits, the length of f[] field can be reduced
by $$\left \lfloor 10 \cdot 4 / 3 + 1 \right \rfloor = 14$$ places. This improvement speeds up the program
by an additional factor of 2.
Pi - Unleashed, p. 83
03-24-2017, 10:25 PM
Post: #5
 pbnelson Junior Member Posts: 4 Joined: Mar 2017
RE: (HP-35s) spigot algorithm for the digits of $$\pi$$
This was a lot of fun. I used it to compute the first 100 digits of PI in about 15 minutes. It in fact returned 105 digits, the first 103 being correct, and the 104th & 105th digits being wrong (according to Google). I am pretty well flabbergasted that such a small program can give 103 digits of PI correctly in only 15 minutes. Thanks for putting this together.
 « Next Oldest | Next Newest »

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