-
-
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
primesieve spkg #7539
Comments
comment:1
It is appropriate to give credit to the sources I used in making the tables of offsets between prime_pi and a logarithmic integral approximation. I used an asymptotic approximation to the logarithmic integral provided by Fredrik Johansson and the tables of prime_pi from http://www.primefan.ru/stuff/primes/table.html. And the idea of combining a table of values of prime_pi and sieving for fast computation of the prime_pi was provided by the nth prime page at http://primes.utm.edu/nthprime/ The primefan tables are extensive, and are from a combined effort of several individuals, including Andrey V. Kulsha, Anatoly F. Selevich, and Tomás Oliveira e Silva. It is likely that the total computation time required to generate these tables was many processor years. As processor time (for the developer), hard-drive storage (for the client), and Internet bandwidth (for the client) become cheaper and more available, I would like to see published tables of prime_pi to expand (and to see resources put toward such computation). It would be nice for the number of values in the prime_pi tables in Sage to increase every few years as the computation of the tables becomes easier for the developer and the download and storage of the tables becomes easier for the client. Maybe several table sizes could be offered. A standard table could be the default for most users, but for those who are studying the distribution of prime numbers and desire speed over extra storage space on their hard-drive (and for bragging rights for Sage), larger tables could be offered. A web-service could even be offered to query a very large table of values of the prime counting function (the additional sieving could be done either on the server or client). Of course, it would be very important to have redundancy in such large calculations (the generation of the prime_pi tables), as there have been incorrect values of the prime counting function published several times in the past. Kevin Stueve |
comment:2
Leif Leonhardy sent some very useful contributions over the past days. Following is our correspondence. *Friday December 4, 2009: I've made some changes to [your version of] TOS's prime_sieve.c, making The original version also contains an overflow bug on large intervals If you intend to build a library rather than a stand-alone program the Note that TOS's implementation, as he stated, was created mainly for The default values for sieve (segment) and bucket size were appropriate I've attached your version of prime_sieve.c ("Silva.c.orig", 09/04/09), Have fun, *My reply, December 4th 2009 On a Macbook pro, I have found that dualthreaded (simply calling TOS *From Leif, December 4th 2009 I've just found another little 64bit-pointer bug in get_memory(), -Leif *From Leif, December 5th, 2009 I've fixed the modulo-64 (or modulo-128 for 64-bit sieve words) The majority of "#ifdef SIEVE_BASETYPE_U64"s has also been removed in -Leif P.S.: By "many sieving threads" (currently: processes) I meant more than |
Provided by Leif Leonhardy in his first email |
Attachment: Leif_attachment1.zip Attachment: Silva.c.additional.diff.gz Provided by Leif Leonhardy in his second email |
Provided by Leif Leonhardy in his third email |
Attachment: Leif_attachment3.zip Attachment: Silva.c.orig.gz original version of Silva.c |
comment:3
From IRC:
The attachments look confusing to me. So I have attached what I think is the sequence of patches to apply on top of the original C code version
After applying the above three patches on top of |
Attachment: 01_Silva.patch.gz first patch of Leif_attachment1.zip, i.e. Silva.c.diff0 |
Leif_attachment1.zip, patch Silva.c.diff: apply all changes in Silva.c.diff that are not in Silva.c.diff0 |
Attachment: 02_Silva.patch.gz add changes from Silva.c.additional.diff |
Attachment: 03_Silva.patch.gz Attachment: 04_Silva.patch.gz add changes from Silva.c.bounds-restriction-removed.diff |
Attachment: Silva.c.gz version of Silva.c after applying the previous 4 patches |
comment:4
From IRC:
I have deleted the previous 3 patches. In their place I attached 4 patches which correspond to the diff's contained in the attachments kevin.stueve. Starting from Silva.c.orig, apply the 4 patches in this order:
After applying the above four patches on top of Silva.c.orig, you get the file Silva.c. I hope my attachments would resolve some of the confusion. |
comment:5
|
comment:7
One of the aspects of TOS's prime_sieve.c is that it has an initialization phase for an interval. I'm not sure if the code already does this, but we should make sure to think about not repeating initialization more than needed. Leif, I think you understand TOS's prime_sieve.c code better than me, what do you think? Kevin Stueve |
comment:9
WARNING: Do not use the current version of "Silva.c" to count primes in intervals beyond approx. 18302910352e9 (assuming a sieve segment size of 2MB, i.e. sieve_bits_log2=24; with lower segment sizes, overflows occur later). Unfortunately, these early overflows do not lead to run-time errors (e.g. segmentation faults) but unsuspiciously wrong results. Note also that you currently must not use 1 as the interval's upper bound or (little worse) 2 as its lower bound, because prime counts will be wrong by one (1 is treated as prime while 2 is not). Nevertheless, Happy New Decade... -Leif |
comment:10
I think I've now fixed all overflow conditions (I did find yet another one) such that it works up to 264-1 under all circumstances. Going to clean up the code and then perhaps release a final stand-alone version... There's currently some overflow checking overhead which could be reduced for "safe" intervals but I'll most probably not remove it before writing a library version (which will be optimized for other special cases, too). Anyway, the improved version is faster than the original... :) |
comment:11
An initial portable version of LMOnew/findn runs on x86_64 in 64-bit native mode. Now going to extend its domain further up to 264-1... [It could be helpful to have confirmed values of pi(x) between 1844e16 and 264. Anyone?] -Leif |
comment:12
Thomas R. Nicely's table of pi(x) at http://sage.math.washington.edu/home/kstueve/T_R_NICELY/ has a granularity of 1e10 up to 2e16. So you really only need values between 2e16 and 264. |
comment:13
Correction: 1e10 or better |
comment:14
Replying to @sagetrac-kevin-stueve:
Only? There was no decimal point missing in 1844... ;-) |
comment:15
Sorry. Right now you have the values: x pi(x) 18440 00000 00000 00000 : 425 50425 77541 37607 18446 74407 37095 51616 : 425 65628 40352 17743 18450 00000 00000 00000 : 425 72967 93423 72554 from http://www.primefan.ru/stuff/primes/table.html and http://www.ieeta.pt/~tos/bib/5.4.pdf. You could sieve part of this interval for more values. You could contact one of the authors of one of the variants of combinatorial method asking for other values (Such as Gourdon, TOS, etc). Another possibility is using a O(x1/2 log(x)) algorithm that computes the parity (even or odd) of the prime counting function, for a limited amount of verification of values of the prime counting function. This algorithm is described by Terence Tao and others at the polymath project at http://michaelnielsen.org/polymath1/index.php?title=Prime_counting_function Gourdon, an author of a variant of the combinatorial prime_pi method links to this page at http://numbers.computation.free.fr/Constants/Primes/countingPrimes.html, however Gourdon's link to Henri Lifchitz's page is dead and you have to use the wayback machine. At Lifchitz's page is his paper on calculating the parity of prime_pi and a program that works up to (unfortunately only) 1e19, and seems to be a little slow. Gourdon has a pix program released at http://numbers.computation.free.fr/Constants/Primes/Pix/contributepixtable.html that he used for his distributed pix project. I'm not sure what range is allowed, how long computation takes, or if the code is open source. But it might work for you. There is also a table of 7702/9001 values of pi(x) computed in the range 1000e14 -> 10000e14 available from Gourdon's pix project at http://numbers.computation.free.fr/Constants/Primes/Pix/resultstable.php. Not the range you were asking for, but still worth noting. Take this data and program with a grain of salt- although Gourdon is surely a better programmer and mathematician than myself, he had to halt his pix program when he found his code was off by one in the global checks for prime_pi(1023) TOS will probably release more values of prime_pi up to 4e18 after his Golbach conjecture verification project is complete, but since these aren't in the range you need, I would recommend contacting Gourdon or TOS directly asking for values for verification. Kevin Stueve |
comment:16
Replying to @nexttime:
Happy validating... ;-) "You just need a computer with a pentium or equivalent chip, turning on windows 95, 98 or NT. ..." [Xavier Gourdon about his "fastpix11"] (Still cleaning up the code.) -Leif |
comment:17
Important update: We need to check our data. |
This comment has been minimized.
This comment has been minimized.
Changed author from ohanar to Kim Walisch |
comment:22
Attachment: 02_primesieve-sage-main.patch.gz I've reviewed this code while Kim was writing it, so other than the following questions/concerns, it has a positive review from me.
P.S. Kim, would you please update the list of developers on trac's homepage so people know who you are. |
Reviewer: R. Andrew Ohana |
comment:24
No, it cannot be BSD licensed as primesieve.pyx includes Sage headers that are GPL licensed. I relicensed the primesieve.pyx and primesieve.pxd files to GPL. The corresponding patch is 03_primesieve-sage-main.patch.
Slightly off topic: primesieve is highly portable, its Makefile is Posix compatible and primesieve builds without any issues on Linux, Mac OS X, BSD and Cygwin and runs on both little and big endian CPUs. Also primesieve has no dependencies on other libraries.
Yes, this makes sense. On the other hand the size of the compressed spkg package is only 120 kilobytes and removing this directory makes packaging new primesieve releases a little more difficult. |
Same as 02_primesieve-sage-main.patch but uses GPL instead of BSD license. |
comment:25
Attachment: 03_primesieve-sage-main.patch.gz |
Changed reviewer from R. Andrew Ohana to none |
Changed author from Kim Walisch to none |
comment:28
Happening now in #25009. |
comment:29
Collective apologies to Kim Walisch for allowing this to bitrot. |
Reviewer: Dima Pasechnik |
This ticket was split away from #7013:
The goal of this ticket is to create an spkg for primesieve (http://primesieve.googlecode.com) which provides the functionality of primesieve is a shared library.
The followup ticket is #25009
Installation instructions:
CC: @sagetrac-kevin-stueve @robertwb @williamstein @sagetrac-victor @nexttime @dimpase
Component: number theory
Reviewer: Dima Pasechnik
Issue created by migration from https://trac.sagemath.org/ticket/7539
The text was updated successfully, but these errors were encountered: