(DM 42) Bernoulli and tangent numbers - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (DM 42) Bernoulli and tangent numbers (/thread-19688.html) |
(DM 42) Bernoulli and tangent numbers - Gjermund Skailand - 03-20-2023 08:06 PM B2n, Tn: Fast calculation of Bernoulli numbers based on Tangent numbers Input: n output: result in register 0 to n, even Bernoulli numbers b2n note b1= +/-0.5, all other odd numbers=0. For b1 the latest definition is +0.5 can also provide Tangent numbers depending on flag 00 flag 00 cancelled: Calculate even Bernoulli numbers B2n flag 00 set : calculate tangent numbers Tn flag is reset after each run runs in standard 4 stack mode, uses registers 0-n and flag 00 Calculates Bn60 (n=0..30) in less than a second on batteries. On USB power, calculates up to n=999, i.e. the 0-1998th Bernoulli numbers in about 5min 40 seconds. Ref "Fast computation of Bernoulli, Tangent and Secant Numbers. " Richard P. Brent and David Harvey 6 Algorithms based three-term recurrences arXiv:1108.0286v3 [math.CO] 5 Sep 2011 The algorithm is stable, and should return Bernoulli numbers accurate to 31-32 digits 2022-03-20 DM-42 version Gjermund Skailand 00 { 126-Byte Prgm } 01▸LBL "Tn" 02 SF 00 03▸LBL "B2n" 04 1ᴇ3 05 ÷ 06 2 07 + 08 ENTER 09 ENTER 10 1 11 STO 01 12 1 13▸LBL 00 14 × 15 STO IND ST Y 16 RCL ST Y 17 IP 18 ISG ST Z 19 GTO 00 20 R^ 21▸LBL 01 22 ENTER 23 ENTER 24 ENTER 25 1 26 - 27 R↓ 28 RCL IND ST T 29▸LBL 02 30 RCL ST Y 31 RCL- ST T 32 × 33 2 34 RCL+ ST L 35 RCL× IND ST Z 36 + 37 STO IND ST Y 38 ISG ST Y 39 GTO 02 40 R↓ 41 R↓ 42 ISG ST X 43 GTO 01 44 FP 45 1 46 STO 00 47 + 48 FS?C 00 49 RTN 50▸LBL 03 51 ENTER 52 IP 53 RCL× IND ST X 54 2 55 LASTX 56 STO+ ST X 57 DSE ST X 58 Y^X 59 ÷ 60 LASTX 61 STO+ ST X 62 1 63 - 64 ÷ 65 FS? 00 66 +/- 67 FC?C 00 68 SF 00 69 STO IND ST Y 70 R↓ 71 ISG ST X 72 GTO 03 73 CF 00 74 END RE: (DM 42) Bernoulli and tangent numbers - Werner - 03-22-2023 08:46 AM The same, but using a matrix to store the numbers, so you can easily go beyond 999 ;-) Also, I prefer not to use flags. input 30 XEQ "B2n" runs in 0.57 seconds on batteries. Code: 00 { 121-Byte Prgm } Cheers, Werner RE: (DM 42) Bernoulli and tangent numbers - Gjermund Skailand - 03-22-2023 11:45 AM Hi Werner, shorter and nicer (as usual), and you found a nice way to avoid the loop limit of 999. PS I wasn't happy about the flag use either :-) br Gjermund |