feature: Add function to calculate Bernoulli numbers#3551
Conversation
|
Oops, I just realized that since the index is an integer, bigint input should be allowed as well, in which case it just returns the exact fraction (same as Fraction input), and that I should test the illegal arguments as well, All should be well now for review. Thanks. |
259fed4 to
aa90404
Compare
|
OK, I think that should do it. |
|
Thanks, that did work out nicely! Two small things:
|
|
Of course, will do. Is it OK if I add a '*~' to the .gitignore for Emacs backup files? I've been dealing with combing them out of my commits for a couple of years now, and this is the first time I have tripped up, sorry, but it would save me a lot of pain if mathjs could just gitignore such files... |
|
(OK I have done all those things including adding to .gitignore, feel free to back out the change to .gitignore if you prefer not to have it.) |
Shows how natural is in the eye of the beholder. When I open the code, I like to see the actual algorithm over the window dressing ;-) but of course am fine with either order. |
|
Eh, yeah, that's true, the order of functions in a file is quite subjective and a matter of personal preference. Thanks for updating the code! |
|
Published now in |
I am working on #3532. I thought it was a quick fix, but diving into the details reveals that there were other accuracy issues, e.g. with zeta(bignumber(-7)). Fixing these means more use of the reflection formula, which in turn means that the inability to compute the gamma and/or lgamma functions for non-integer BigNumbers will be more restrictive (since the reflection formula uses gamma).
So my plan now is to implement the gamma function to BigNumber precision (hopefully; there are some articles on this but I don't have all the details worked out). The leading method seems to be the Stirling formula, which in turn makes use of the Bernoulli numbers. Hence this PR provides an implementation of a function
bernoulli(n)for computing the nth Bernoulli number, whethernis a number, BigNumber, or Fraction (returning the same type as its argument).This is a self-contained, independently valuable addition as the Bernoulli numbers appear in multiple different mathematical contexts.