Post Reply 
HP-42S (Free42, DM-42) mini-challenge – Wallis Product
07-11-2020, 06:43 PM
Post: #26
RE: HP-42S (Free42, DM-42) mini-challenge – Wallis Product
(07-06-2020 02:31 AM)Gerson W. Barbosa Wrote:  I have a 141-byte, 81-step program that gives 12 digits of \(\pi\) in less than seven seconds on the real HP-42s and 34 digits instantly on my smartphone: 3.141592653589793238462643383279504 (the last digit should be a ‘3’), using the Wallis Product as a basis.

Down to 135 bytes and 74 steps, including LBL and END. It might be optimized even more by HP-41 programmers who usually avoid using too many recall arithmetic as I do. Anyway, on the 42S I tend to value number of steps over byte count. Right now I have 5906 free bytes on the 42S and 1773076480 on Free42, way more memory than I’ll ever need :-)

Code:

00 { 135-Byte Prgm }
01▸LBL "W"
02 STO 01
03 2
04 STO 02
05 MOD
06 ENTER
07 STO+ ST X
08 1
09 -
10 4
11 STO 04
12 RCL× 01
13 1
14 RCL- ST T
15 ×
16 RCL+ ST Z
17 RCL+ ST Z
18 1
19 RCL+ 01
20 X<> 03
21 CLX
22 3
23 RCL× ST T
24 STO- 03
25 STO+ ST X
26 STO- 04
27 R↓
28 4
29 RCL× 01
30 RCL- ST Y
31 RCL+ 02
32 RCL 03
33 RCL- 04
34 RCL+ 02
35 RCL× ST T
36 RCL÷ ST Z
37 R↓
38▸LBL 00
39 STO+ ST T
40 R↓
41 R↓
42 +/-
43 STO× ST T
44 ×
45 RCL 03
46 X<>Y
47 ÷
48 STO ST T
49 R↓
50 RCL 01
51 STO+ ST X
52 X↑2
53 STO× 02
54 DSE ST X
55 STO÷ 02
56 R↓
57 RCL ST Y
58 SIGN
59 X<> ST Z
60 ABS
61 X<> 04
62 +/-
63 STO+ 03
64 NOT
65 +/-
66 NOT
67 +/-
68 X<> 04
69 DSE 01
70 GTO 00
71 R↑
72 RCL- ST T
73 RCL× 02
74 END

HP-75C program:

Code:

10 INPUT N
15 T=MOD(N,2)
20 S=2*T-1
25 L=N+1-3*T
30 M=4-6*T
35 E=4*N*(1-T)+2*T
40 D=4*N-E+2
45 C=S*(L-M+2)/E
50 W=1
55 FOR I=1 TO N
60 S=-S
65 T=4*I*I
70 W=W*T/(T-1)
75 C=S*L/(C+D)
80 L=L-M @ M=2-M
85 T=D @ D=E @ E=T
90 NEXT I
95 DISP 2*W*(C+1)

Register usage on 42S/Free42:

N, I: R01
W: R02
L: R03
M: R04
C, D, E, S, T: Stack
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP-42S (Free42, DM-42) mini-challenge – Wallis Product - Gerson W. Barbosa - 07-11-2020 06:43 PM



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