#11475: improve prime_pi (speedup + small fixes)
-----------------------------+----------------------------------------------
Reporter: rohana | Owner: was
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-4.7.1
Component: number theory | Keywords: primes, prime counting, prime_pi
Work_issues: | Upstream: N/A
Reviewer: | Author: R. Andrew Ohana
Merged: | Dependencies:
-----------------------------+----------------------------------------------
Comment(by ylchapuy):
> A lot of the speed of this algorithm relies on the __cached_count
method, which is essentially a binary search (with a simple adjustment in
the beginning that takes advantage of the density of the primes)
Something like this should give you a 10% speedup for big inputs.
{{{
if p < 200:
pos = p>>2
size = 5
else:
size = self.__numPrimes>>1
# Use the expected density of primes for expected inputs to
make an
# educated guess
if p>>3 < size:
size = p>>3
pos = size
}}}
(beware to make sure there are enough primes cached for small inputs)
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11475#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.