Post Reply 
[VA] SRC #012c - Then and Now: Sum
12-01-2022, 08:27 AM (This post was last modified: 12-01-2022 08:33 AM by Werner.)
Post: #20
RE: [VA] SRC #012c - Then and Now: Sum
Using the original asymptotic series H(n) = ln(n) + gamma + 1/(2*n) - 1/(12*n^2) + 1/(120*n^4) - ... results in:
H(n-1)-H(n/2-1) - ln(2) = 1/(2n) + 1/(4n^2) - 1/(8n^4) + 1/(4n^6) - 17/(16n^8) + .. (thanks^2, Albert!).
This formula is so accurate that my stopping criterion needed to be changed to 1+x = 1 ;-) But now, I need the definition only for n<32 instead of 128, and the running time on a real 42S went down to 36 seconds.

00 { 180-Byte Prgm }
01▸LBL "VA3"
02 3
03 STO "C"
04 CLX
05 STO "S"
06▸LBL 10
07 RCL "C"
08 XEQ H
09 1
10 ENTER
11 RCL+ ST Z
12 X=Y?
13 GTO 00
14 R↓ @ X contains 1
15 RCL "C"
16 XEQ F
17 ÷
18 STO+ "S"
19 ISG "C"
20 X<>Y
21 GTO 10
22▸LBL 00
23 10
24 512
25 LN
26 -
27 6
28 ÷
29 RCL+ "S"
30 1
31 2
32 LN
33 -
34 ÷
35 RTN
36▸LBL D
37 CLA
38 BINM
39 ARCL ST X
40 CLX
41 ALENG
42 EXITALL
43 RTN
44▸LBL F
45 3
46 X>Y?
47 GTO 00
48 R↓
49 STO× ST Y
50 XEQ D
51 GTO F
52▸LBL 00
53 R↓
54 ×
55 RTN
56▸LBL H @ H(2^N-1) - H(2^(N-1)-1) - LN(2), input N
57 2
58 X<>Y
59 Y^X
60 32 @ 128 on Free42 gives 18 digits of accuracy
61 X≤Y?
62 GTO 00
63 CLX
64 2
65 -
66 0.05
67 %
68 +
69 1
70 + @ n-1,n/2-1
71 0
72▸LBL 02 @ 1/(n-1) + 1/(n-2) + .. + 1/(n/2)
73 RCL ST Y
74 IP
75 1/X
76 +
77 DSE ST Y
78 GTO 02
79 2
80 LN
81 -
82 RTN
83▸LBL 00 @ H(n-1) - H(n/2-1) - ln(2) ~= 1/(2n) + 1/(4n^2) - 1/(8n^4) + 1/(4n^6) - 17/(16n^8)
84 R↓
85 STO+ ST X
86 X^2
87 LASTX
88 1/X
89 272
90 RCL÷ ST Z
91 16
92 -
93 R^
94 ÷
95 2
96 +
97 R^
98 ÷
99 1
100 -
101 R^
102 ÷
103 -
104 END

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #012c - Then and Now: Sum - Werner - 12-01-2022 08:27 AM



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