Skip to content
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

Implement the sieve of Atkin #157

Open
Bodigrim opened this issue Jan 7, 2019 · 0 comments · May be fixed by #172
Open

Implement the sieve of Atkin #157

Bodigrim opened this issue Jan 7, 2019 · 0 comments · May be fixed by #172

Comments

@Bodigrim
Copy link
Owner

Bodigrim commented Jan 7, 2019

Our implementation of Eratosthenes sieve is notoriously difficult to read. It has been heavily optimized long time ago and I have no clue if these patterns still make sense for modern GHCs and modern PCs. It is also quite possible that bugs are lurking in dark corners. I tried to disentangle it a couple of times, but always retreated in horror. Basically, it is too easy to introduce an off-by-one error, which will manifest itself only for a small portion of cases, possibly very large ones.

Maybe there is a better path: reimplement prime sieves altogether using the sieve of Atkin. It has better performance characteristics and the relevant paper is super clear.


Note on containers. Current implementation represents sieves by UArray Int Bool. This is clearly the wrong level of abstraction: since we do not employ fancy indexing via Ix typeclass, we'd rather stick either to low-level arrays from primitive or to full-fledged vectors from vector. The arrays in question are quite long and we "grow" them in growCache, so Vector is the right choice.

Unfortunately, vanilla Vector does not support dense bit arrays (64 bits per Word64). See also haskell/primitive#42. There is bitvec package, which aims to provide Vector interface to dense bitmaps, but it is abandoned: known issues are open for two years and the test suite does not build anymore. So for the time being there is no other choice but continue using UArray Int Bool.

@Bodigrim Bodigrim linked a pull request Sep 24, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant