Bodigrim / arithmoi

Number theory: primes, arithmetic functions, modular computations, special sequences
http://hackage.haskell.org/package/arithmoi
MIT License
147 stars 40 forks source link

Primes sequence #153

Closed Bodigrim closed 5 years ago

Bodigrim commented 5 years ago

This PR is inspired by forprime control structure in PARI/GP and provides an Enum instance for Prime.

One of the most ubiquitous tasks in number theory is generating lists of primes. Current API of arithmoi (represented by Math.NumberTheory.Primes.Sieve) is sufficient, but burdens users with too many choices. Should I use primes or sieveFrom or primeList? Or maybe it is faster just to filter a short interval with isPrime and do not bother with sieves? Frankly speaking, even I was never able to remember all subtleties.

Well, Haskell has a well established and handy notation for list generation and enumeratable data. And now it is available for primes:

I wanted to implement this API for ages and first drafts are at least two years old. But it took a lot of time to mature.

Bodigrim commented 5 years ago

Now it is ready.

@rockbmb @b-mehta @CarlEdman could someone please review?