-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix prime_pi errors and make primecount standard #24960
Comments
comment:1
Could you add timings in the ticket description? Did you check with PARI/GP? First step would be to make primecount a proper optional package and interface it. In a second time it can be discussed whether this needs to be a standard package (ie coming with default Sage installation). As a parallel task, the fact that |
Dependencies: #24966 |
comment:2
See #24966 for actually packaging primecount. |
comment:3
I changed the description of the ticket adding execution times. I did not try using Pari/GP because Pari primepi function is very very slow (at least until the latest release, there is some minor improvement in the development code). It works by enumerating one by one all prime numbers, together with a table of pre-computed values. Just to give an example, although primepi(200000000507)=8007105083 is pre-computed. computing primepi(251000000000) requires 372 seconds, while SageMath and primecount only take less than a second. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:4
Added some context information to the ticket description. |
comment:5
When I wrote the current |
comment:6
Fixed typos. |
This comment has been minimized.
This comment has been minimized.
comment:8
I can confirm the behavior of the last example
and thanks to #24966 this can be checked with
|
comment:9
Since primecount has been an optional package for several years, maybe it would be a good idea to upgrade it to standard and just call it? |
comment:10
Or if nobody has time to work on this, maybe somebody could replace the message ""computation of prime_pi for |
comment:11
Replying to @miguelmarco:
Of course, in that case we should reconsider #32412 |
comment:12
I think we should upgrade |
comment:13
See #32412 comment:7 for how to do the primecount Cython interfaces properly |
comment:15
Replying to @miguelmarco:
No, that's outdated. |
comment:16
Replying to @mkoeppe:
So we should move the current cython code to a pip package, and then instruct sage to pip-install it instead of using a sage SPKG? |
comment:17
Yes, either the current cython code should become a pip-installable package; or switch to using https://pypi.org/project/primecount/ (but see hearot/primecount-python#3). The pip-installable package can then become an SPKG. |
comment:18
I think it's more urgent to provide a bug-free |
comment:19
It's 10 minutes of work to package it. |
comment:20
if you know what to do, yes. |
comment:21
In this case, one copies and adjusts something that works, such as https://github.com/sagemath/memory_allocator |
comment:22
I've posted some not yet complete thing on #25009 |
Changed keywords from primes prime_pi to primes prime_pi primecount |
comment:28
should |
This comment has been minimized.
This comment has been minimized.
comment:30
comment:21. |
comment:31
I finally built and tested this on a 32-bit host, the only one test error there, it is due to a different error message, Needs some dots to be added. |
comment:32
Replying to @mkoeppe:
I don't understand, do you mean that |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:34
Do we also need --- a/build/pkgs/sagelib/dependencies
+++ b/build/pkgs/sagelib/dependencies
@@ -1,4 +1,4 @@
-FORCE $(SCRIPTS) arb boost_cropped $(BLAS) brial cliquer cypari cysignals cython ecl eclib ecm flint libgd gap giac givaro glpk gmpy2 gsl iml jinja2 jupyter_core lcalc lrcalc libbraiding libhomfly libpng linbox m4ri m4rie memory_allocator mpc mpfi mpfr $(MP_LIBRARY) ntl numpy pari pip pkgconfig planarity ppl pplpy pycygwin $(PYTHON) ratpoints rw sage_conf singular symmetrica zn_poly $(PCFILES) | $(PYTHON_TOOLCHAIN) sage_setup
+FORCE $(SCRIPTS) arb boost_cropped $(BLAS) brial cliquer cypari cysignals cython ecl eclib ecm flint libgd gap giac givaro glpk gmpy2 gsl iml jinja2 jupyter_core lcalc lrcalc libbraiding libhomfly libpng linbox m4ri m4rie memory_allocator mpc mpfi mpfr $(MP_LIBRARY) ntl numpy pari pip pkgconfig planarity ppl pplpy primecount pycygwin $(PYTHON) ratpoints rw sage_conf singular symmetrica zn_poly $(PCFILES) | $(PYTHON_TOOLCHAIN) sage_setup
----------
All lines of this file are ignored except the first.
diff --git a/src/pyproject.toml.m4 b/src/pyproject.toml.m4
index 125da7ac1c..6b6402884a 100644
--- a/src/pyproject.toml.m4
+++ b/src/pyproject.toml.m4
@@ -18,6 +18,7 @@ requires = [
numpy \
pkgconfig \
pplpy \
+ primecount \
memory_allocator \
')]
build-backend = "setuptools.build_meta" to avoid possible races? Still, this does not seem to be relevant for the issue in comment:28. |
comment:35
Replying to @dimpase:
You were asking how to do dependencies right. The answer is: The bindings need to go into a separate Python package -- that will look just like |
comment:36
I think we're talking about different issues. I saw an error during docbuild stage which came from |
comment:37
As I have explained, |
comment:38
I asked you whether it's the only Cython file out there left that should not be a part of sagelib. I don't have mental capacity now to learn the ideal modern design, I just want this ticket done in the most direct way. |
comment:39
I was relieved today from teaching computer graphics next term, so I have some spare mental capacity now :-) Note that What does not rely on sagelib (or on Sage at all) is The latter indeed can be spun off, modelling on |
Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:
|
This comment has been minimized.
This comment has been minimized.
comment:41
we will proceed with this on #32894, which includes commits on this ticket's branch. |
Changed author from Dima Pasechnik to none |
The prime_pi function sometimes computes a wrong result. In particular, I found the following errors:
returns 408351706116074, it should be 408351706116078
returns 161319877461134, it should be 161319877461136
returns 19439675999018, it should be 19439675999019
The correct countings are computed using Kim Walisch's primecount library, with different algorithms: Deleglise-Rivat, Lagarias-Miller-Odlyzko and Lehmer's formula. All of them return the same result.
Note that while the arguments to prime_pi in the first two examples exceed the value 2!^50, causing the appearance of a warning ("computation of prime_pi for x >= 2!^50 has not been as thoroughly tested as for smaller values"), the argument of the last example is within the range of inputs considered to be safe.
Actually, instead of fixing the current code, it could be easier to rewrite the prime_pi function and let it use the primecount library. This would have the additional advantage of being much faster than the current code. The table below compares the execution times (in seconds) of primecount with Deleglise-Rivat, primecount with Lagarias-Miller-Odlyzko and SageMath prime_pi function.
All results have been obtained with an Intel i5-2500K. For primecount, a single thread has been used.
| ||| argument |
|-|||:----------:|
| algorithm | 642763101936913 | 5685979153167559 | 14783545363230719 |
| primecount | 2.99| 11.168| 20.052|
| primecount --lmo | 5.287| 21.883| 41.286|
| prime_pi | 331| 2489| 6083|
Here we take the route of replacing Cython code in
sage.functions.prime_pi
with calls to functions in
sage.interface.primecount
Will be fixed by #32894
Depends on #25009
CC: @slel
Component: number theory
Keywords: primes prime_pi primecount
Branch/Commit: u/dimpase/functions/prime_pi-fix @
4f77073
Issue created by migration from https://trac.sagemath.org/ticket/24960
The text was updated successfully, but these errors were encountered: