mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2011-06-27, 10:48   #1
JohnFullspeed
 
May 2011
France

7×23 Posts
Default Erastho

To work on PN(Primes Number) the first thing is to have le primes list
Eratosthenes sieve is The solution

We fifind nf any where the logc (Wiky ,MartWord...)
Before to see if my results can be interested I try to have performances of the classic sieves

Asking at one author i have this remark: my version have 3200 lines.
Mine only 20. The question is what I forget.
What xxx does in the 3180 other lines.
XXX is a senior programmer of this forum not a beginner.

I compute with my Eratosthenes ALL the primes less <32 bits 210 000 000
I control them with the division method: Of course they are all prime

Remark;

On the Forum sometimes QS is use for Quadratic Sieve It's wrong QS means Quick Sort. So I link for exemple to Jasonp makiing the mistake: I don't understand where a QS is use in a quadrartic sieve,
Like we say in Frarnce on appelle chat un chat pas chien

John
JohnFullspeed is offline   Reply With Quote
Old 2011-06-27, 11:20   #2
ET_
Banned
 
ET_'s Avatar
 
"Luigi"
Aug 2002
Team Italia

10010110100112 Posts
Default

Let's call the A.A.A.A.

Association Against Acronym Abuse.

Luigi
ET_ is offline   Reply With Quote
Old 2011-06-27, 12:03   #3
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by JohnFullspeed View Post
To work on PN(Primes Number) the first thing is to have le primes list
Eratosthenes sieve is The solution

We fifind nf any where the logc (Wiky ,MartWord...)
Before to see if my results can be interested I try to have performances of the classic sieves

Asking at one author i have this remark: my version have 3200 lines.
Mine only 20. The question is what I forget.
What xxx does in the 3180 other lines.
XXX is a senior programmer of this forum not a beginner.

I compute with my Eratosthenes ALL the primes less <32 bits 210 000 000
I control them with the division method: Of course they are all prime

Remark;

On the Forum sometimes QS is use for Quadratic Sieve It's wrong QS means Quick Sort. So I link for exemple to Jasonp makiing the mistake: I don't understand where a QS is use in a quadrartic sieve,
Like we say in Frarnce on appelle chat un chat pas chien

John

To work on PN(Primes Number) the first thing is to have le primes list
Eratosthenes sieve is The solution

We fifind nf any where the logc (Wiky ,MartWord...)
Before to see if my results can be interested I try to have performances of the classic sieves

Asking at one author i have this remark: my version have 3200 lines.
Mine only 20. The question is what I forget.
What xxx does in the 3180 other lines.
XXX is a senior programmer of this forum not a beginner.

I compute with my Eratosthenes ALL the primes less <32 bits 210 000 000
I control them with the division method: Of course they are all prime

Remark;

On the Forum sometimes QS is use for Quadratic Sieve It's wrong QS means Quick Sort. So I link for exemple to Jasonp makiing the mistake: I don't understand where a QS is use in a quadrartic sieve,
Like we say in Frarnce on appelle chat un chat pas chien

these are your errors in spelling ( bold ) and grammar(underline). Also, if you write better in french I have no problem dealing with you in that language I have ways of translating it.

Last fiddled with by science_man_88 on 2011-06-27 at 12:06
science_man_88 is offline   Reply With Quote
Old 2011-06-27, 14:48   #4
bsquared
 
bsquared's Avatar
 
"Ben"
Feb 2007

2·3·587 Posts
Default

Quote:
Originally Posted by JohnFullspeed View Post
I compute with my Eratosthenes ALL the primes less <32 bits 210 000 000
I control them with the division method: Of course they are all prime
There are 203,280,221 primes less than 2^32.

And if the goal is to produce the shortest program to compute them, then 20 lines is doing ok. In 10 min of work I came up with a 16 liner, and a more motivated person could probably halve that.

Code:
int main(int argc, char **argv) {
 unsigned char *list;
 unsigned int i, j, p, c = 1, limit = strtoul(argv[1],NULL,10);
 list = (unsigned char *)calloc(limit/2, sizeof(unsigned char));
 printf("prime 0 = 2\n");
 for (i = 1; i < sqrt((double)(limit/2)); i++) {
    p = 2 * i + 1; 
    if (list[i] == 0) {
       printf("prime %d = %u\n",c++,p);
       for (j = i+p; j < limit/2; j+=p) list[j] = 1;
    }
 }
 for (; i < limit/2; i++) if (list[i] == 0) printf("prime %d = %u\n",c++,2 * i + 1);
 printf("found %d primes\n",c);
 free(list);
}
Unfortunately, it takes 75 seconds to compute all primes less than 2^32. To go faster would require more code.

Last fiddled with by bsquared on 2011-06-27 at 14:48 Reason: fixed formatting
bsquared is offline   Reply With Quote
Old 2011-06-27, 15:20   #5
bsquared
 
bsquared's Avatar
 
"Ben"
Feb 2007

1101110000102 Posts
Default

While waiting for Real Work to compile, I played a bit more.

The following is both faster and almost half the lines of the previous attempt. Note there is only one ';' per line (not counting the for loop header stuff).

Code:

int main(int argc, char **argv) {
 unsigned int i, j, p, c = 1, *list, limit = strtoul(argv[1],NULL,10);
 list = (unsigned int *)calloc(limit/16, sizeof(unsigned int));
 printf("prime 0 = 2\n");
 for (i = 1; i < sqrt((double)(limit/2)); i++) if ((list[i>>5] & (1 << (i & 31))) == 0) for (j = i+(2 * i + 1); j < limit/2; j+=(2 * i + 1)) list[j>>5] |= (1 << (j & 31));
 for (i = 1; i < limit/2; i++) if ((list[i>>5] & (1 << (i & 31))) == 0) printf("prime %d = %u\n",c++,2 * i + 1);
 printf("found %d primes\n",c);
 free(list);
}
bsquared is offline   Reply With Quote
Old 2011-06-27, 15:40   #6
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by bsquared View Post
While waiting for Real Work to compile, I played a bit more.

The following is both faster and almost half the lines of the previous attempt. Note there is only one ';' per line (not counting the for loop header stuff).

Code:

int main(int argc, char **argv) {
 unsigned int i, j, p, c = 1, *list, limit = strtoul(argv[1],NULL,10);
 list = (unsigned int *)calloc(limit/16, sizeof(unsigned int));
 printf("prime 0 = 2\n");
 for (i = 1; i < sqrt((double)(limit/2)); i++) if ((list[i>>5] & (1 << (i & 31))) == 0) for (j = i+(2 * i + 1); j < limit/2; j+=(2 * i + 1)) list[j>>5] |= (1 << (j & 31));
 for (i = 1; i < limit/2; i++) if ((list[i>>5] & (1 << (i & 31))) == 0) printf("prime %d = %u\n",c++,2 * i + 1);
 printf("found %d primes\n",c);
 free(list);
}
in PARI ( john it's a math console) I can get it to :

Code:
a=vector(<number to check up to>,n,if(isprime(n),n,0));a=vecsort(a,,8);a=vector(#a-1,n,a[n+1]);a
science_man_88 is offline   Reply With Quote
Old 2011-06-27, 15:43   #7
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
in PARI ( john it's a math console) I can get it to :

Code:
a=vector(<number to check up to>,n,if(isprime(n),n,0));a=vecsort(a,,8);a=vector(#a-1,n,a[n+1]);a
okay yeah I forgot vectors can only be so long, dang.
science_man_88 is offline   Reply With Quote
Old 2011-06-27, 16:13   #8
Christenson
 
Christenson's Avatar
 
Dec 2010
Monticello

5×359 Posts
Default

Quote:
Originally Posted by ET_ View Post
Let's call the A.A.A.A.

Association Against Acronym Abuse.

Luigi
Sorry, that's not a TLA, I don't understand!
Christenson is offline   Reply With Quote
Old 2011-06-27, 16:22   #9
Christenson
 
Christenson's Avatar
 
Dec 2010
Monticello

5×359 Posts
Default

Quote:
Originally Posted by JohnFullspeed View Post
Asking at one author i have this remark: my version have 3200 lines.
Mine only 20. The question is what I forget.
What xxx does in the 3180 other lines.
XXX is a senior programmer of this forum not a beginner.

John
As you see above, there are distinct tradeoffs between size of program and its speed, and different ways of counting lines. I can tell you that using GWNUM (from Prime95) will definitely increase the size of a program, but it will allow it to work with really large numbers.

Your author may have been liberal with the use of whitespace in his program, too. Maybe you should ask him/her for source code?

As SM88 suggested, it is probably better for you to write in French first, then post the translation below.
Christenson is offline   Reply With Quote
Old 2011-06-27, 16:24   #10
jasonp
Tribal Bullet
 
jasonp's Avatar
 
Oct 2004

354310 Posts
Default

Quote:
Originally Posted by JohnFullspeed View Post
On the Forum sometimes QS is use for Quadratic Sieve It's wrong QS means Quick Sort. So I link for exemple to Jasonp makiing the mistake: I don't understand where a QS is use in a quadrartic sieve,
So the universe only has 26*26=676 things whose name has two words?

(Google queries with 'nfs' get huge numbers of hits for a game called 'need for speed' :)

Last fiddled with by jasonp on 2011-06-27 at 16:24
jasonp is offline   Reply With Quote
Old 2011-06-27, 16:38   #11
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by Christenson View Post
As you see above, there are distinct tradeoffs between size of program and its speed, and different ways of counting lines. I can tell you that using GWNUM (from Prime95) will definitely increase the size of a program, but it will allow it to work with really large numbers.

Your author may have been liberal with the use of whitespace in his program, too. Maybe you should ask him/her for source code?

As SM88 suggested, it is probably better for you to write in French first, then post the translation below.
they told me in a french PM that from what I can make out enough to get a rough translation says they have Alzheimer's or Parkinson's .
science_man_88 is offline   Reply With Quote
Reply



All times are UTC. The time now is 22:41.


Fri Aug 6 22:41:30 UTC 2021 up 14 days, 17:10, 1 user, load averages: 4.22, 4.02, 3.66

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.