Use a faster series for calculating the Riemann R function #144
+198
−387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use the Gram series
$$R(x) = 1 + \sum_{k=1}^\infty \frac{(\ln x)^k}{\zeta(k + 1) \cdot k \cdot k! }$$ $\zeta(k+1)$ . Since this is (almost?) as fast as the series for $\text{li}(x)$ , I took the liberty to just use $R(x)$ everywhere.
to calculate the Riemann R function. I used a precalculated table for
I also updated the Newton iteration to use$R'(x)$ instead of the approximation $\frac1{\ln x}$ . This guarantees quadratic convergence and reduces the number of iterations needed, so it should outweigh the cost of calculating $R'(x)$ . The derivative $R'(x)$ can be calculated as
$$R'(x) = \frac1{x \ln x} \sum_{k=1}^\infty \frac{(\ln x)^k}{\zeta(k + 1) \cdot k!}.$$ $x$ (see https://www.desmos.com/calculator/4jm9ulxsvh).
For the initial guess, I used the Cesaro formula (see https://en.wikipedia.org/wiki/Prime_number_theorem#Approximations_for_the_nth_prime_number) with some modifications that make it work better with smaller values of