Bernoulli numbers and large factorials
|
02-09-2014, 04:59 PM
Post: #1
|
|||
|
|||
Bernoulli numbers and large factorials
In December Namir posted a program that evaluates the Bernoulli numbers on the HP-41. It can be found in the HP-41C Software Library. In January I suggested another version based on the same approach:
\( B_n = 2 n! {(2\pi)^{-n}} \sum\limits_{i=1}^{\infty}i^{-n} \) For large n the sum rapidly approaches 1 so that at some point it may be omitted. On the other hand, for n as low as 10 only a few terms are required for the usual 10 or 12 digit precision. \(B_{0...8}\), which would require a substantial number of terms, may be given directly. So this is the easy part. Both Namir's and my solution suffer from a limitation due to overflow in the factorial function. For HP's 10-digit calculators with working range up to 9,999...E99 the limit is 69!, while most 12-digit devices with their upper limit at 9.999...E499 will work up to 253!. However, this is significantly less than the largest possible n that returns a Bernoulli number within the working range. Here, results up to \(B_{116}\) resp. \(B_{372}\) would be possible. There is an elegant way to overcome this problem if the calculator offers a permutation function (nPr). The essential idea is to split n! into two factors a and b which both fall within the calculator's working range. If factorials up to 253! are possible (the largest value below 9,999...E499) this can be done as follows: \( \begin{align*} n! &= \frac{n!}{253!} · 253!\\ &= \frac{n!}{(n - (n - 253))!} · 253!\\ &= Perm(n, n - 253) · 253! \end{align*} \) If n is less than 253, this constant is simply replaced with 0: \( Perm(n, n - 0) · 0! = n! · 1 = n!\) This method may also be written as follows: let r = max(0, n - 253) let a = Perm(n, r) let b = (n-r)! Then n! = a · b This way the factor \(2 n! {(2\pi)^{-n}}\) can be evaluated as \(2 a {(2\pi)^{-n} b}\) to avoid overflow. On calculators with a limit at 9,999...E99, for instance the 15C, simply use 69 instead of 253. Here is a complete program for the HP-35s. It evaluates all Bernoulli numbers within the working rage, i.e. from \(B_0\) to \(B_{372}\). Code: B001 LBL B The adjustment in line 051...056 tries to reduce the error in \((2\pi)^{-n}\). On the 35s I could not find errors larger than some units in the last place. Other calculators may require a different correction, or it may even be omitted completely if a somewhat larger error is acceptable. Usage: Enter n [XEQ] B [ENTER] => display shows n and Bn. Execution time: within approx. 3 seconds (at n = 10). Examples: 4 [XEQ] B [ENTER] => -0,333333333333 32 [XEQ] B [ENTER] => -15.116.315.767,1 100 [XEQ] B [ENTER] => 2,83322495708 E+78 372 [XEQ] B [ENTER] => -5,58475372908 E+499 Up to n = 26 the result may also be viewed in fraction mode. If no limitations are set (Flag 8 and 9 clear, /c ≥ 2730) the display shows the exact representation of the respective Bernoulli number: 22 [XEQ] B [ENTER] => 6.192,12318839 [FDISP] => 6192 17 / 138 ' exact result is \(6192 \frac{17}{138}\) or \(\frac{854513}{138}\) [RND] ' round to exact result [FDISP] => 6.192,12318841 Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Bernoulli numbers and large factorials - Dieter - 02-09-2014 04:59 PM
RE: Bernoulli numbers and large factorials - Tugdual - 02-09-2014, 07:47 PM
RE: Bernoulli numbers and large factorials - Marcus von Cube - 02-09-2014, 08:01 PM
RE: Bernoulli numbers and large factorials - Dieter - 02-09-2014, 09:26 PM
RE: Bernoulli numbers and large factorials - Dieter - 02-09-2014, 08:43 PM
RE: Bernoulli numbers and large factorials - Bunuel66 - 02-09-2014, 08:42 PM
RE: Bernoulli numbers and large factorials - Paul Dale - 02-09-2014, 09:44 PM
RE: Bernoulli numbers and large factorials - Dieter - 02-12-2014, 08:56 PM
|
User(s) browsing this thread: 1 Guest(s)