Extended Precision e III

About the program

:fn id=hpmod.More about the accuracy of the HP-41 MOD function can be found in Appendix\B.:efn

This program calculates "e" to 870 places, but it does not print the result. The program was originally written by Ron Knapp and his version appeared in the newsletter of PPC, the HP users club, in 1982. [PPC Calculator Journal V8N6P12-13]

The version presented here has been adapted for use on a TI-59. A result of the adaptation is a program that is both longer and slower than the HP-41 version, primarily caused by the fact that the HP-41 has a builtin MOD function. This builtin MOD function is shorter, faster and, it may be hard to believe, more accurate than a synthesized MOD function on a TI-59.:fnref refid=hpmod

Method Used

The method used in this program is, as could be expected, basically the same as in EPe1 and EPe2, but it is implemented in a much smarter way. An excellent explanation is given by Ron Knapp: :lq. .sk .ce HP-41 computes "e" to 2900D

The result of such a computation is of little use to anyone. The challenge imposed by the thought of such a computation is almost overwhelming. Consider the equation: .sk .ce "e" = 2 + 1/2! + 1/3! + 1/4! + 1/5! + 1/6! + 1/7! + .....

This could be handeled by a 10-digit machine up to the term 1/13!, but how do you continue? Multiple divisions for each term would prolong the computation beyond all reason. Let's reverse the series and gather two terms together into one term: .sk .ce ..... 1/7! + 1/6! + 1/5! + 1/4! + 1/3! + 1/2! + 2 = "e" .sk .ce ..... (7 + 1)/7! + (5 + 1)/5! + (3 + 1)/3! + 2 = "e"

Now factor: .sk .ce ..... (7 + 1)]/(7.6) + (5 + 1)]/(5.4) + (3 + 1)]/(3.2) + 2 = "e"

Look what we have accomplished! We can now compute two terms at a time and our largest divisor is 42\(7.6) instead of 5040\(7!). At term 15, it would be 210 instead of 1,307,674,368,000. Also the addition becomes simple, 7\+\1 instead of adding each term after it has been calculated out to the full number of places desired.

The equation has become so simple that we can ask ourselves, "Can we do more than two terms at a time?" .sk .ce ..... 7(6 + 1) + 1]/(7.6.5) + 4(3 + 1) + 1]/(4.3.2) + 2 (three) .sk .ce ..... 7(6(5(4(3 + 1) + 1) + 1) + 1) + 1]/(7.6.5.4.3.2) + 2 (six)

This equation for six term at a time gives exactly the same result as the original 6-term equation. By continuing this same reasoning to 12 terms, we find: .sk .ce 13(12(11(10(9(8(7(6(5(4(3 + 1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+1

is equal to 4,472,755,886 and: .sk .ce 1 / (13.12.11.10.9.8.7.6.5.4.3.2) equals 1 / 6,227,020,800

Now, 4,472,755,886 divided by 6,227,020,800 equals .7182818284. Add 2 to obtain "e" correct to 10 decimal places, accomplished in just one multi-term operation. As the term-number increases in size, the number of terms which can be multiplied together without exceeding our 10-digit machine capacity, decreases. If the term number is above 100, we can compute only 4 terms at a time. Above 316 reduces us to 3 terms at a time.

Our problem then, is to program the machine to shift gears from 3 to 4 to 5 to .... terms at a time as appropriate. [...\...]

There is a second way of saving a great amount of time. Since our equation now calls for an extended precision division in each multi-term by a divisor as large as is possible without exceeding the 10-digit limitation, is is obvious that any error from one loop will be reduced by a factor approaching 10,000,000,000 by the next division. The program therefore, calculates the first loop to 10 places (one register) and the second loop to 20 places. In addition, it uses R02 to keep a continuous record of accuracy attained and does not add another register to the calculation until needed. [...\...]

This procedure cuts running time almost in half. The first multi-term loop requires only a few seconds and each succeeding term takes one or two additional seconds. [...\...] :elq

The most important difference between the HP-41 and the TI-59 program is the fact that the HP-41 program can calculate terms up to 1.E10, but that the TI-59 program can only calculate terms up to 1.E8! An attempt to calculate terms to 1.E10 on a TI-59 failed, because a synthesized MOD function is not accurate enough.

The TI-59[/PC-100] Version

User Instructions

The user instructions for this program are once again very simple:

  1. Enter the program.
  2. Press A. The program will stop with a flashing\1 in the display.
  3. Now press 7 EE to start the program in Fast Mode.
  4. When the program has ended, you recall the result by pressing E, repeatedly followed by R/S. The read-out is complete when a flashing zero appears. (If you have a PC-100, you can of course change step 205 into PRT)

Listing of the TI-59[/PC-100] Version

000  92 RTN         060  82 HIR         120  00  00         180  08  8
001  01  1          061  04  04         121  82 HIR         181  07  7
002  82 HIR         062  22 INV         122  45  45         182  77 XòT
003  05  05         063  64 PD*         123  53  (          183  01  01
004  82 HIR         064  00  00         124  82 HIR         184  87  87
005  06  06         065  82 HIR         125  16  16         185  82 HIR
006  44 SUM         066  45  45         126  65  x          186  08  08
007  89  89         067  32 X:T         127  53  (          187  97 DSZ
008  52 EE          068  53  (          128  35 1/X         188  89  89
009  08  8          069  53  (          129  65  x          189  00  00
010  32 X:T         070  82 HIR         130  82 HIR         190  01  01
011  02  2          071  15  15         131  15  15         191  25 CLR
012  94 +/-         072  55  ö          132  54  )          192  81 RST
013  42 STO         073  82 HIR         133  59 INT         193  76 LBL
014  00  00         074  16  16         134  74 SM*         194  15  E
015  43 RCL         075  54  )          135  00  00         195  82 HIR
016  89  89         076  59 INT         136  54  )          196  18  18
017  82 HIR         077  65  x          137  82 HIR         197  48 EXC
018  46  46         078  82 HIR         138  55  55         198  89  89
019  69 OP          079  16  16         139  82 HIR         199  42 STO
020  20  20         080  54  )          140  14  14         200  00  00
021  82 HIR         081  82 HIR         141  82 HIR         201  69 OP
022  16  16         082  55  55         142  35  35         202  20  20
023  77 XòT         083  53  (          143  97 DSZ         203  73 RC*
024  00  00         084  82 HIR         144  88  88         204  00  00
025  33  33         085  11  11         145  00  00         205  91 R/S
026  97 DSZ         086  22 INV         146  55  55         206  97 DSZ
027  89  89         087  77 XòT         147  53  (          207  89  89
028  00  00         088  01  01         148  82 HIR         208  02  02
029  15  15         089  07  07         149  15  15         209  01  01
030  01  1          090  75  -          150  55  ö          210  00  0
031  44 SUM         091  53  (          151  82 HIR         211  69 OP
032  89  89         092  69 OP          152  16  16         212  68  68
033  53  (          093  30  30         153  82 HIR         213  92 RTN
034  43 RCL         094  55  ö          154  47  47         214  76 LBL
035  89  89         095  32 X:T         155  85  +          215  11  A
036  82 HIR         096  54  )          156  93  .          216  22 INV
037  66  66         097  59 INT         157  05  5          217  57 ENG
038  85  +          098  74 SM*         158  54  )          218  22 INV
039  02  2          099  00  00         159  59 INT         219  58 FIX
040  85  +          100  65  x          160  74 SM*         220  09  9
041  82 HIR         101  82 HIR         161  00  00         221  69 OP
042  45  45         102  14  14         162  82 HIR         222  17  17
043  01  1          103  54  )          163  17  17         223  47 CMS
044  82 HIR         104  53  (          164  32 X:T         224  04  4
045  35  35         105  69 OP          165  01  1          225  00  0
046  97 DSZ         106  20  20         166  77 XòT         226  00  0
047  00  00         107  63 EX*         167  01  01         227  42 STO
048  00  00         108  00  00         168  87  87         228  89  89
049  40  40         109  75  -          169  82 HIR         229  01  1
050  54  )          110  59 INT         170  38  38         230  82 HIR
051  82 HIR         111  82 HIR         171  52 EE          231  07  07
052  18  18         112  35  35         172  01  1          232  82 HIR
053  42 STO         113  54  )          173  00  0          233  08  08
054  88  88         114  82 HIR         174  94 +/-         234  60 DEG
055  69 OP          115  44  44         175  82 HIR         235  04  4
056  20  20         116  01  1          176  47  47         236  05  5
057  01  1          117  52 EE          177  82 HIR         237  30 TAN
058  52 EE          118  05  5          178  18  18         238  33 Xý
059  05  5          119  64 PD*         179  32 X:T         239  86 STF
<\pre>

The TI-58 Version

User Instructions

The instructions for this program are exactly the same as those for the TI-59 version.

Listing of the TI-58 Version

To obtain the TI-58 version of the program, you first key in the TI-59[/PC-100] version. Next you make the following modifications in the indicated order:

  1. Change step 007 into "29".
  2. Change step 016 into "29".
  3. Change step 027 into "29".
  4. Change step 032 into "29".
  5. Change step 035 into "29".
  6. Change step 054 into "28".
  7. Change step 144 into "28".
  8. Change step 180 into "2".
  9. Change step 188 into "29".
  10. Change step 198 into "29".
  11. Change step 207 into "29".
  12. Change steps 224-226 into "1" "5" "4".
  13. Change step 228 into "29".
  14. Delete steps 220-222.
  15. Insert three zeroes after step 213.

Instead of first entering the TI-59[/PC-100] version, it is of course also possible to make the above changes directly while keying in the program.

Some last notes about the programs