I don't know... To my mind, if we are going to support working with primes, the minimum API is:
- is_prime(n)
- next_prime(n)
- prev_prime(n)
- factorise(n)
- generate_primes(start=0)
(I trust the names are self-explanatory.)
There are various other interesting prime-related factors which can be built on top of those, but the above five are, in my opinion, a minimal useful set.
Factorising negative numbers is simple: just include a factor of -1 with the prime factors. We would probably want to also support factorising 0 and 1 even though they don't have prime factors. The alternative is to raise an exception, which I expect would be more annoying than useful. |