Post Reply 
Calculation of pi on many machines
11-25-2020, 01:10 PM (This post was last modified: 12-04-2020 11:17 AM by Gerson W. Barbosa.)
Post: #18
RE: Calculation of pi on many machines
This is an RPL version of the HP-42S program above:

Code:

« PUSH RAD -105 CF -3 CF DUP 10 * 21 / 1 + CEIL 0 2 ROT 8 OVER * 
PICK3 + UNROT 1
  FOR i i DUP + DUP 1 - UNROT * OVER / SWAP SQ 4 ROLL 4 PICK + / 
UNROT -1
  STEP SQ UNROT 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
»

# 8F62h, 258 bytes

51 decimal digits: 10.502 s
85 decimal digits: 32.557 s
153 decimal digits: 160.952 s
357 decimal digits: 4393.037 s

(HP 50g)

———

PS:

Actually, the RPL program above is based on one of my older formulae. The following program is slower, but it is in accordance with the formula I used in the RPN program:

Code:

« PUSH RAD -105 CF -3 CF R→I DUP 12 * 25 / CEIL DUPDUP 8 * 4 + DUP 
8 - ROT SQ 4 * 1 - 2 0 UNROT 1 7 ROLL
  START OVER 1 + * OVER / UNROT DUP ROT 6 PICK + / UNROT 4 ROLL 
SWAP OVER - UNROT 8 - 4 ROLLD
  NEXT NIP 2 ROT 5 ROLL + 1 - / 1 + * NIP 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
»

# 5CB1h, 301.5 bytes

51 decimal digits: 12.344 s
85 decimal digits: 42.373 s
153 decimal digits: 308.168 s

(HP 50g)

1000 decimal digits: 2988.379 s

(iPhone7, emulated HP 49g+, m48+)

Algorithm:

Code:

input digits ; number of decimal digits 
n := ceil(12*digits/25)
c := 0
d := 8*n + 4
e := d - 8
m := 4*n*n - 1
w := 2
i := n
repeat
  w := w*(m + 1)/m
  c := m/(c + d)
  m := m - e
  e := e - 8
  i := i - 1
until i = 0
c := 2/(c + d - 1) + 1
p := c*w
output p

———

PPS:

This is a longer version of the previous program, but it’s significantly faster for larger numbers of decimal digits (and even faster than the first program). Also, as in the previous program, all decimal digits are correct (actual digits, no roundings).

Code:

« PUSH RAD -105 CF -3 CF R→I DUP 12 * 25 / CEIL DUPDUP DUP + 1 + 
OVER 8 * 4 + DUP 8 - 0 5 ROLL SQ 4 * 1 - 5 PICK 1 DUP 9 ROLL 
  START OVER 2 - UNROT OVER 1 - ROT / * PICK3 6 PICK - UNROT 4 ROLL 
5 ROLL 7 PICK + / 4 ROLLD 5 ROLL 8 - 5 ROLLD
  NEXT SQ 7 ROLL * 4 5 ROLL 7 ROLL + 1 - / 2 + * 4 ROLLD 3 DROPN 
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
»

# E567h, 354 bytes

51 decimal digits: 10.355 s
85 decimal digits: 31.200 s
153 decimal digits: 157.039 s
357 decimal digits: 3820.207 s

(HP 50g)

1000 decimal digits: 2588.102 s

(iPhone7, emulated HP 49g+, m48+)

Algorithm:

Code:

input digits ; number of decimal digits 
n := ceil(12*digits/25)
a := 2*n + 1
b := a
c := 0
d := 8*n + 4
e := d - 8
m := 4*n*n - 1
w := 1
i := n
repeat
  w := w*(a - 1)/a
  c := m/(c + d)
  a := a - 2
  m := m - e
  e := e - 8
  i := i - 1
until i = 0
c := 4/(c + d - 1) + 2
p := b*c*w*w
output p
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Calculation of pi on many machines - Gerson W. Barbosa - 11-25-2020 01:10 PM



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