-
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
Sum up a function over primes #97
Comments
I've been messing around with this on a branch, and there are some really nice implementations that fall out of this approach.
It's still quite messy, but it's extremely fast once it has warmed up.
I'll probably meditate on this and see if I can reimplement in terms of |
@jhenahan
|
@CarlEdman Thanks very much for the fairly critical point about the summatory function. :) That would absolutely defeat the purpose. I'll have to think on it more, in that case. |
@jhenahan My pleasure. Let me know if I can help. |
With regards to |
@Bodigrim I think that unboxing could be a big win. For starters, it ought to reduce GC time to just about 0. The reason I didn't use unboxed arrays was that for my problem I needed more than 64-bit int precision, so I had to go with Integers which can't really be unboxed. Given how large some of the summatory function results can be, I think keeping Integers available for |
Would you have any suggested literature on “useful” summatory functions? While I’m thinking on it, it couldn’t hurt to build in more special cases like |
I don't really have a literature, but a few pointers:
|
@jhenahan any news? Feel free to ping me, if you need to discuss anything. |
Nothing yet, but I’ll be setting aside some time to look into it further next week. Work’s been eating my OSS time. |
Math.NumberTheory.Primes.Counting.Impl.primeCount
implements an algorithm to compute π(n), which is number of primes below n, in O(n^0.7) time and O(n^1/2) space. One can view π(n) as a sum off p = 1
over primep
belown
.As it was pointed by @CarlEdman in #60 (
primeLucy
), this approach allows a generalization for any functionf
with the same time and space requirements. Moreover, there is a (difficult) way to improve its time complexity to O(n^2/3).That said, it seems desirable to productionalize
primeLucy
, provide a nice API, write decent tests and benchmarks, and then expressprimeCount
as a special case.Additional resources:
https://en.wikipedia.org/wiki/Meissel–Lehmer_algorithm
http://sweet.ua.pt/tos/bib/5.4.pdf
https://projecteuler.net/thread=10;page=5#111677
The text was updated successfully, but these errors were encountered: