[VA] SRC #012c - Then and Now: Sum
|
12-05-2022, 05:05 PM
Post: #40
|
|||
|
|||
RE: [VA] SRC #012c - Then and Now: Sum
.. and a last, ultimate contribution.
improvements: - new stopping criterion S+H/F = S - stops on the 42S when C=33 instead of 38 ;-) - choice between H(n) definition and approximation is made in a machine-independent way, so Free42 now calculates the result to (near?) 34-digit precision ;-) and the exact same program can be used in the 42S. Had to rewrite H(n) so that the definition code used 2 counters so that large n could be handled on Free42 - started the summation from C=2, as in Albert's code. Made it ever so slightly shorter - but I added the 1/4 at the end, not at the beginning, gaining 1 digit of accuracy ;-) - shortened F(n) on the 42S, max C=33 and S=2.08637766501 in 36 seconds Free42, C=105 and S=2.086377665005988716089755856734133 and yes, I can shave off a few more bytes here and there.. eg 1 ENTER LN1+X i.o. 1 2 LN but that would be less readable. These are not 'mini challenges', after all ;-) 00 { 167-Byte Prgm } 01▸LBL "VA3" 02 2 03 STO "C" 04 CLX 05 STO "S" 06▸LBL 10 @ main loop 07 RCL "C" 08 XEQ H 09 1 10 RCL "C" 11 XEQ F 12 ÷ 13 RCL+ "S" 14 ENTER 15 X<> "S" 16 X≠Y? 17 ISG "C" 18 X≠Y? @ aff 19 GTO 10 20 4 @ wrap-up 21 1/X 22 RCL+ "S" 23 1 24 2 25 LN 26 - 27 ÷ 28 1 29 + 30 RTN 31▸LBL D @ binary digits of an integer 32 CLA 33 BINM 34 ARCL ST X 35 CLX 36 ALENG 37 EXITALL 38 RTN 39▸LBL 04 40 R↓ 41 XEQ D 42▸LBL F @ F(n), call with 1 n 43 STO× ST Y 44 3 45 X≤Y? 46 GTO 04 47 R↓ 48 R↓ 49 RTN 50▸LBL H @ H(2^N-1) - H(2^(N-1)-1) - LN(2), input N 51 2 52 X<>Y 53 Y^X 54 RCL ST X @ if 1/2^n + (2^n)^-10 = 1/2^n then use approximate formula 55 -9 56 Y^X 57 1 58 STO+ ST Y 59 - 60 X=0? 61 GTO 00 62 R↓ 63 50 64 % 65 0 66▸LBL 02 @ 1/(n-1) + 1/(n-2) + .. + 1/(n/2) 67 DSE ST Z 68 RCL ST Z 69 1/X 70 + 71 DSE ST Y 72 GTO 02 73 2 74 LN 75 - 76 RTN 77▸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) 78 R↓ 79 STO+ ST X 80 X^2 81 LASTX 82 1/X 83 272 84 RCL÷ ST Z 85 16 86 - 87 R^ 88 ÷ 89 2 90 + 91 R^ 92 ÷ 93 1 94 - 95 R^ 96 ÷ 97 - 98 END Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 9 Guest(s)