-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#125] Implement Hurwitz zeta function #126
Conversation
@Bodigrim is it worth it to implement the Hurwitz zeta function with both real arguments? It'll take some more work as it'll require the gamma function, which I don't think is implemented. The Riemann zeta and Dirichlet beta will only need an integral first argument, so for a first step that will be sufficient. |
Gamma function is available in I think as a first stab we may keep the first argument integer. |
Yikes, that won't do. I'll look into submitting a PR to change that, although I don't know if it'll happen. For now, as you agreed, first integer is |
@Bodigrim I refactored the code to instead use a simple implementation of the ideas mentioned in the thesis (formula 4.8.9 of linked page) I mentioned while working on #120. The Hurwitz zeta function is now stabler, but there are some issues with the precision tests for the Riemann zeta and Dirichlet beta tests. Will delete them if they no longer make sense for Hurwitz zeta. |
Math/NumberTheory/Zeta/Hurwitz.hs
Outdated
-- from the <https://dlmf.nist.gov/25.11#iii Digital Library of Mathematical Functions> | ||
-- by the <https://www.nist.gov/ National Institute of Standards and Technology (NIST)>, | ||
-- formula 25.11.5. | ||
zeta :: forall a b . (Floating a, Ord a, Integral b) => a -> b -> a -> a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us name it zetaHurwitz
or something else, different from zeta
. Just to avoid confusion with Riemann zeta.
|
@Bodigrim I think the reason the tests fail is that with 4.8.5 is because in the "Evaluating the error bound" section, it is stated that
However, the current method (disregard the comments, outdated. Will fix.) to set I think my next step will be to implement the error bounding described in Theorem 4.8.1, and from this bounding derive better |
It looks to me that tests fail for |
@Bodigrim You're right. It's not worth asking for precision greater than However, I'll still look into this issue with error bounding, and also the way and order the sums are calculated in. The previous implementation also received such high precisions in this test (i.e. |
@Bodigrim now that the Hurwitz zeta function is working for integer arguments, I'm going to try extending it to real arguments, first and then complex. This requires the |
Good! I looked at |
@Bodigrim there are other issues, such as the relative complexity of the implementation and it's lack of documentation. I'm sure there are a lot of very clever tricks used throughout, but without an explanation it's hard to maintain them. |
@Bodigrim Apologies, I made an incorrect statement: it is not necessary to use the gamma function for an extended version of However, turning the integer argument into a floating argument reduces precision by default, simple tests like There's one more matter I'd like to discuss. While the |
Yeah, dealing with numerical stability is tough. With regards to As a zero step, one can add I typically write to maintainers privately, asking if they have any plans of future development, explaining my intention to contribute and to help with life cycling. People usually like when someone finds their abandoned code useful and is willing to continue development. |
I'm not sure I understand the idea here. Can you explain what your plan for the |
AFAIU from skimming through If one will be able to run As you noted above, we do not need this at the moment for |
@Bodigrim sorry, my question was more about: you said something about moving some code to |
I meant "migrate |
Oh, I understand - you meant to migrate the matrix dependency the module relies on, not the module itself. |
By the way, I'm awaiting a reply on It'll be difficult to make the Hurwitz zeta function numerically stable on real inputs, that can be a patch for a different occasion. For now I'll keep the first argument integral. I'll push what I have now regardless for future reference, same as what I did with the Eisenstein integer |
@Bodigrim I've been An idea I've been considering lately is to create implement ball arithmetic types in GHC (in the Prelude, alongside In any case, this PR is good to go on my end. |
@Bodigrim by the way, when you're working on your PRs, how do you generate documentation locally to see how it's rendered in Hackage? I just noticed that the documentation I wrote for the Eisenstein integers module looks pretty bad, I should check that sort of stuff before PRs get merged. |
I use
Good. I'll take a look during the next week. |
Please rebase atop latest master. What I am worried about is that benchmarks of zeta/beta functions (kinda "sum first 20 values of Riemann zeta function) became significantly slower. This may be connected not only to possibly worse convergence properties, but also to the fact that |
@Bodigrim that's probably because I implemented EDIT: If I recall correctly, it's because
|
The previous version of 'zeta' was incorrect as it returned a list of successively improving approximations of the zeta function for its arguments instead of the final one.
In `betasProperty2/zetasProperty2`, sometimes a precision greater than `2e-53` was generated, and because the tests use `Double`, this lead to incorrect results with `NaN` values and improper test cases. The tests have been changed to avoid generating a precision greater than `2e-53`.
* The Hurwitz `zeta` function has been renamed to `zetaHurwitz` to avoid confusion with the Riemann `zetas` recurrence * The `betasProperty2` test now compares more terms of the Dirichlet beta function because the new implementation of `betasEven` is more numerically stable
…mpared in precision test
The Hurwitz zeta function is now a recurrence over its first argument, beginning with `0, 1, 2 ..`.
In `zetasOdd` and `betasEven`, there were incorrect bounds when using the `zetaHurwitz` recurrence because the first element of each of those recurrences is already defined (at indices `1` and `0`, respectively), yet that same index from `zetaHurwitz` is not ignored, leading to an additional incorrect term in ´zetas´ and `betas`, causing the comparison tests to fail due to wrong results.
@Bodigrim I have returned to fix the issue with I'll try benchmarking it now, but I'll be slightly skeptical about the numbers (running WSL). |
From
Current code (hurwitz as a recurrence):
Previous code (hurwitz as a function):
|
Went from 10x slower to 2x, I guess that's barely acceptable. There might be room for improvement, @Bodigrim can you review the PR once more? |
It is certainly acceptable, good job! Overall it looks good to me, but I am wondering: do you know what exactly improved performance 5x? My expectation was that Hurwitz zeta functions on consequent integers do not share much, so I am quite surprised. |
@Bodigrim Here's a short explanation:
This means the only variable that iterates is |
I should also add that although there is still a performance penalty, there is a precision increase: see 4804b57. Doing this with the current code causes the code to fail, which means the current implementation offers higher precision for higher indices of the It might get even better after dmcclean/exact-pi#8 gets merged, although I don't think think it's going to happen for a while. |
Haddock comments for `zetas,betas,zetaHurwitz` now have paragraphs for better readability. Plus, the stability and portability Haddock module comment fields for the Hurwitz module have been removed.
Remembered to fix Haddock, unlike with the |
Thanks for awesome work! |
@Bodigrim No problem. I should also thank you for taking so much of your time to review my PRs, give advice and merge code 👍 . |
Closes #125. Still a WIP.