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:
This PR is inspired by forprime control structure in PARI/GP and provides an
Enum
instance forPrime
.One of the most ubiquitous tasks in number theory is generating lists of primes. Current API of
arithmoi
(represented byMath.NumberTheory.Primes.Sieve
) is sufficient, but burdens users with too many choices. Should I useprimes
orsieveFrom
orprimeList
? Or maybe it is faster just to filter a short interval withisPrime
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:
Generate primes from the given interval:
Generate infinite list of primes:
Generate primes from the given interval of form p = 6k+5:
Get next prime:
Get previous prime:
Count primes less than a given number:
Get 25-th prime number:
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.