Opened 6 years ago
Last modified 5 years ago
#18298 new enhancement
prime_range vs primes
Reported by: | vdelecroix | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-6.7 |
Component: | number theory | Keywords: | |
Cc: | leif | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
There is currently a prime_range
function in sage.rings.fast_arith
which return a list of prime in a given range {0, ..., n-1}
and a function primes
in sage.rings.arith
which return an iterator.
We should have only one entry point and the answer would better be an iterator.
Change History (7)
comment:1 Changed 6 years ago by
comment:2 Changed 6 years ago by
I do care about newcomers and this is one motivation for this ticket. But currently primes
return an iterator while prime_powers
return a list! On the other hand, my choice was motivated by Python 3 where even range
would return an iterator. If you feel like we should have both functions (one returning a list and one returning an iterator) please tell me.
comment:3 Changed 6 years ago by
Hmm, not sure. My personal preference would be to have default return a list, with a flag to return an iterator, but that will probably not be popular for most others.
comment:4 Changed 6 years ago by
- Cc leif added
comment:5 Changed 5 years ago by
I found this ticket and the next one, and wonder if they are going to be worked on?
My current beef is that the docstring for primes is wrong. The only argument with no default is "start" and it says that this is a lower bound (as the name suggests) but in fact it is an upper bound unless "stop" is also set! ALso there is no way at present (I think) to get an open-ended iterator with only one parameter, you have to use primes(2,infinity). You can also use Primes() as in "for p in Primes(): ..." but I have no idea how efficient that is.
comment:6 follow-up: ↓ 7 Changed 5 years ago by
I don't get what Vincent intends to do. Merge both functions into a single one (with an even more complicated interface)?
Both have pretty different applications, and the functions' docstrings refer to each other.
In the long run, we could of course implement something better...
Make sure that it's still easy to use for newcomers - my concern is that it might be non-obvious what to do with an iterator as opposed to a list, which is very clear. This is the sort of thing that someone with zero programming experience is most likely to use - hey, get a list of the primes less than 1000! Maybe that's even an argument for keeping both, or maybe not. But at any rate it should be clear what to do, plus deprecation issues.