Gerson's Pi Program
|
03-11-2022, 04:29 PM
(This post was last modified: 12-19-2022 03:35 PM by Gerson W. Barbosa.)
Post: #21
|
|||
|
|||
RE: Gerson's Pi Program
(03-11-2022 12:42 PM)EdS2 Wrote: Other changes which can be beneficial: Very good work! Thank you. 5E-6 was added to avoid errors due to binary representation. For instance, I notice a number that looked like 4482 on the BBC Micro, but its integer part was 4481. When I took its fractional part the result was 0.9999996185. So, INT(4481 + 0.999999 + 0.000005) will return 4482 as it should. Of course, this can be fixed by working with integer variables and functions whenever possible. One hundred digits in 42 minutes is quite good, considering I estimate it will take twice as long on the MSX computer (Z80 @ 3.57 Mhz). Perhaps I should improve mine also. The multiprecision program is basically equivalent to the obfuscated one in the card, except that the expression for π is 4*W*(1/(C+D-1)+1/2) instead of W*(2/(C+D-1)+1). Also, long divisions are performed by multiplying by the inverse (for example M/(C + D) = M*1/(C + D). I wrote the LMULT routine (multiply two n-digit numbers giving an n-digit result) many years ago. Usually if I can do something by hand I don't have trouble programming it. But when I tried to do a long division by hand, I discovered I don't remember how to do it anymore. As LDIVIDE was needed, I did 1/y using Newton's method: xₙ = xₙ₋₁(2 - xₙ₋₁.y). The initial guess, x₀, is given with the first few exact digits to ensure a faster convergence (lines 440 and 450 in the HP-75C program below). ADD, MULT and DIVID were taken from Katie Wasserman's program. HP-75C program: Code:
The digits of π are written to a BASIC file with DATA lines suitable for occasional further processing (like insertion of the missing zeros at left, for example). 1 DATA 3 2 DATA 141592 3 DATA 653589 4 DATA 793238 5 DATA 462643 6 DATA 383279 7 DATA 502884 8 DATA 197169 9 DATA 399375 10 DATA 105820 11 DATA 974944 12 DATA 592307 13 DATA 816406 14 DATA 286208 15 DATA 998628 16 DATA 34825 17 DATA 342117 18 DATA 67967 19 DATA '8083.154 s' 100 correct digits in 135 minutes, but a really competent HP-75C programmer can surely improve on that. P.S.: Here's a QBASIC version based on you port. The number of digits is forced to the next multiple of 4. All digits are supposed to be exact, no rounding in the last one. Because of the choice for 32-bit integers, the number of digits is limited to 480. One hundred digits in 71 seconds (DOSBox with default settings). 480 digits in about 27 minutes (when compiled). I would like to try it on my HP-200LX, but its screen has gone dark. Code:
|
|||
03-14-2022, 01:33 AM
(This post was last modified: 03-23-2022 04:29 PM by Gerson W. Barbosa.)
Post: #22
|
|||
|
|||
RE: Gerson's Pi Program
(03-11-2022 12:42 PM)EdS2 Wrote: On the MSX LOG is the natural logarithm whereas on the BBC Micro it is the decimal logarithm. This won't change the result for M% in line 85 above, but it can be simplified to 85 M%=10/3*LOG(ND) Also, matrices are initialized to zero on both the MSX and the BBC micro. Thus, we can eliminate the lines 120 through 140 and edit the line 110 to 110 W%(1)=4 My mistake, especially because more matrices must be initiliazed to zero as you can see from the HP-75C listing above. It's already Pi Day in countries which use MM/DD date format, so I decided to turn on my old MSX computer after 15 years to check the running time for 100 digits. The 2-byte system variable TIME allows for timings up to 1092 seconds only, but this limitation can be overcome by using an interruption to updated a timing variable every 10 seconds. Same results on the BlueMSX emulator, in one tenth of the time. Code:
The matrices are dimensioned for 300 digits or so, but G will overflow for ND around 180, unless the line 60 is changed to 60 DEFINT D,E,H-N In this case, the constant in line 10 below should be changed to 1000. Code:
——— PS. Sure 86 minutes for just the first 100 digits is no big deal, but considering the most powerful supercomputer of the late eighties wouldn’t do it in even 100 years using the plain Wallis Product, this looks great. The HP-49G calculator, released in 1999, does it in 137.3 seconds. In the picture, the slightly more recent HP 50g computes 100 decimal digits of \(\pi\) in one third of that time using an equivalent User-RPL program: Edited to fix a couple of elusive typos. |
|||
03-15-2022, 07:44 AM
Post: #23
|
|||
|
|||
RE: Gerson's Pi Program
Very nice to run it on a real machine!
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)