#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 rohana):
An update:
v4: added a table of `prime_pi` values that can be stored in a byte --
using this with the `__cached_primes` method gave a giant speedup. Since
the sum at the beginning of `__phi` (and `__phi32`) differs from
`16*(x/77)` by a small factor that only depends on `x%2310`, so adding a
table with these factors results in another large speedup. These tables
take a total of ~4kB.
v5: the tables introduced a significant initialization time for
`prime_pi`, and William asked me to fix this, so `prime_pi` (and
legendres_formula) only initialize these tables on an initial call -- so
initialization time is now ~650ns:
{{{
sage: timeit('sage.functions.prime_pi.PrimePi()')
625 loops, best of 3: 627 ns per loop
}}}
Both Yann and I have tested `9.75*10^15` again and got the correct result,
I also did `10^16`. We both ran it on 64-bit GNU/Linux systems. So the
issue I was encountering may have been due to boundary issues with the
`__cached_primes` method (which have been rewritten over the course of the
patches). I kept the limit in since I haven't yet tested this thoroughly.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11475#comment:19>
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.