Post Reply 
Happy Pi Day!
03-14-2020, 02:08 AM (This post was last modified: 03-14-2020 01:35 PM by Gerson W. Barbosa.)
Post: #1
Happy Pi Day!
Let's celebrate it by computing the first two hundred digits of pi using a very unusual formula 
for that purpose, the Wallis Product. Normally it would not be suitable for this application, as
one million terms yield only five decimal digits of pi. However, a correction term in continued
fraction form will handle that nicely:


                                  /                                         \
       256 196 144 100 64 36 16 4 |                      -1                 |
pi ~ 2.---.---.---.---.--.--.--.-.| 1 - ----------------------------------- |
       255 195 143  99 63 35 15 3 |                         3               |
                                  |     32 + ------------------------------ |
                                  |                           1             |
                                  |          2 - -------------------------- |
                                  |                             5           |
                                  |              32 + --------------------- |
                                  |                               3         |
                                  |                   2 - ----------------- |
                                  |                                 7       |
                                  |                       32 + ------------ |
                                  |                                   5     |
                                  |                            2 - -------- |
                                  |                                     9   |
                                  |                               32 + ---  |
                                  |                                     2   |
                                  \                                         /



      349075614466048
pi ~ ----------------- ~ 3.1415926535(708367)
      111114219110895

Since we have 8 terms of the Wallis Product one of the constants in the continued fraction is 32, that is,

4 times 8. The other constant is always 2. The alternate numerators follow a simple pattern (-1, 1, 3, 5...
and 3, 5, 7, 9...). 

For 200 digits, we will need only 150 terms of the Wallis Products plus another 150 terms of the continued
fraction.


It will take about 9 and half minutes on the real HP 50g:

200

%%HP: T(3)A(R)F(.);
\<< PUSH RAD -105 CF -3 CF DUP 3 * 4 + 8 IDIV2 DROP DUP + DUP 4 OVER * SWAP 1 + DUP 4 - 0 1 \-> d n1 n2 c p
  \<< 2 / 1 SWAP
    FOR i i DUP 1 - OVER 256 * * 64 + DUP PICK3 SQ * UNROT 32 - OVER * 16 + * 3 - / p * 'p' STO n2 d n1 2 c 
      - / + / 'c' STO 'n2' 2 STO- 'n1' 2 STO-
    NEXT p 1 c - * 2 * EXPAND
  \>> FXND DUP SIZE R\->I ALOG OVER - PICK3 * SWAP IQUOT + \->STR DUP HEAD 0 I\->R \->STR TAIL + SWAP TAIL + 
  1 ROT 2 + SUB POP
\>>

EVAL ->

3.14159265358979323846264338327950288419716939937510
  58209749445923078164062862089986280348253421170679
  82148086513282306647093844609550582231725359408128
  48111745028410270193852110555964462294895493038196



Notice the continued fraction correction factor has been obtained empirically, so no proof is available.

Edited to fix a typo.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Happy Pi Day! - Gerson W. Barbosa - 03-14-2020 02:08 AM
RE: Happy Pi Day! - pinkman - 03-14-2020, 06:19 AM
RE: Happy Pi Day! - Gerson W. Barbosa - 03-14-2020, 02:53 PM
RE: Happy Pi Day! - rprosperi - 03-14-2020, 05:04 PM
RE: Happy Pi Day! - Jim Horn - 03-14-2020, 05:15 PM
RE: Happy Pi Day! - Gerson W. Barbosa - 03-14-2020, 12:17 PM
RE: Happy Pi Day! - Dave Britten - 03-14-2020, 12:47 PM
RE: Happy Pi Day! - BruceH - 03-15-2020, 11:32 AM
RE: Happy Pi Day! - Eddie W. Shore - 03-15-2020, 07:29 PM
RE: Happy Pi Day! - DM48 - 12-12-2021, 06:44 PM
RE: Happy Pi Day! - Albert Chan - 12-12-2021, 11:04 PM
RE: Happy Pi Day! - Gerson W. Barbosa - 12-13-2021, 12:41 AM
RE: Happy Pi Day! - DM48 - 12-13-2021, 01:54 AM
RE: Happy Pi Day! - Gil - 12-13-2021, 01:21 AM
RE: Happy Pi Day! - Gerson W. Barbosa - 12-13-2021, 03:57 AM



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