mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Miscellaneous Math (https://www.mersenneforum.org/forumdisplay.php?f=56)
-   -   Goldbach's Conjecture (https://www.mersenneforum.org/showthread.php?t=7592)

science_man_88 2010-07-25 01:00

[QUOTE=CRGreathouse;222708]Please post both scripts so I can compare![/QUOTE]

[CODE]Goldbach(n)={
my(nn=n+n);
forprime(x=2,n,if(isprime(nn-x),return(x)));
0
};
GoldbachMax(n)={
my(nn=n+n);
forprime(x=2,default(primelimit),if(isprime(nn-x),return(x)));
error("Ran out of primes at "n)
};
test(lim,startAt=2)={
my(breakpoint=min(lim\2,default(primelimit)));
startAt=floor(startAt);
for(n=startAt,breakpoint,
if(Goldbach(n),print1(2*n,","))
);
for(n=max(startAt,breakpoint+1),lim\2,
if(GoldbachMax(n),print1(2*n,","))
)
}; [/CODE]took 24000 by the way if it prints everything.

[CODE]Gold(n)={
forprime(x=2,n/2,
f=floor((.5*n-x)+(.5*n));
if(isprime(f),
print(x","f","n);
return();
);
)
};

forstep(n=2,400,2,Gold(n))[/CODE] if i did math right took more

and

mine = for(c=2,500,for(n=0,c-3,if(isprime(c-n) && isprime(c+n),print(c","n);break()))) originally from what I just posted on.

and my best improvement is:

for(c=2,500,if(c%2==0,forstep(n=1,c-3,[2],if(isprime(c-n) && isprime(c+n),print(c","n);break())));if(c%2==1,forstep(n=2,c-3,[2],if(isprime(c-n) && isprime(c+n),print(c","n);break()))))<- double checking the time for.
I messed it up as I swear it said 4000 last time but it says 50,000 now anyone willing to test it ?

CRGreathouse 2010-07-25 01:08

Printing takes a lot of time -- remove the print statements if you want to compare!

The second piece of code you posted, Gold(n), is just my cleaned-up version of your code; it's not fast. The first one, apart from the print instructions, is fast. In my test it's more than ten times faster than yours -- 2.7 seconds to get to a million vs. 47 seconds for your old version or 40 seconds for your new version.

[code]Goldbach(n)={
my(nn=n+n);
forprime(x=2,n,if(isprime(nn-x),return(0)));
1
};
GoldbachMax(n)={
my(nn=n+n);
forprime(x=2,default(primelimit),if(isprime(nn-x),return(0)));
error("Ran out of primes at "n)
};
test(lim,startAt=2)={
my(breakpoint=min(lim\2,default(primelimit)));
startAt=floor(startAt);
for(n=startAt,breakpoint,
if(Goldbach(n),print1(2*n,","))
);
for(n=max(startAt,breakpoint+1),lim\2,
if(GoldbachMax(n),print1(2*n,","))
)
};


sm88(lim)={
for(c=2,lim,for(n=0,c-3,if(isprime(c-n)&&isprime(c+n),break)))
};


sm88a(lim)={
for(c=2,lim,
if(c%2==0,
forstep(n=1,c-3,[2],if(isprime(c-n) && isprime(c+n),break))
);
if(c%2==1,
forstep(n=2,c-3,[2],if(isprime(c-n) && isprime(c+n),break))
)
)
};[/code]

3.14159 2010-07-25 01:53

Cheesehead. Do you also visit the kook section regularly?

CRGreathouse 2010-07-25 03:40

Actually, the numbers I posted above were bad (comparing the wrong things). Running my test to 2e6 is the proper comparison to running yours to 1e6, so my time is 5.9 seconds; 6 or 7 times faster than yours, not "more than 10 times".

science_man_88 2010-08-08 21:19

[QUOTE=CRGreathouse;222719]Actually, the numbers I posted above were bad (comparing the wrong things). Running my test to 2e6 is the proper comparison to running yours to 1e6, so my time is 5.9 seconds; 6 or 7 times faster than yours, not "more than 10 times".[/QUOTE]

well any combination of 6n-1,6n+1 will give a even number so it comes down to the probability of 2 aligning within x-3 either side of the given number such that both are prime.

science_man_88 2010-08-09 11:57

[CODE]for(x=4,2^30,if(isprime(x) && nextprime(x)-x>(x-3),print(x)))[/CODE] my way to check for one that would break Goldbach's conjecture is there a faster way to find out when the gap between primes is x-3 for a given x ?

CRGreathouse 2010-08-09 12:47

[QUOTE=science_man_88;224537][CODE]for(x=4,2^30,if(isprime(x) && nextprime(x)-x>(x-3),print(x)))[/CODE] my way to check for one that would break Goldbach's conjecture is there a faster way to find out when the gap between primes is x-3 for a given x ?[/QUOTE]

For x >= [url=http://oeis.org/classic/A104272]A104272[/url](2) + 1 = 12, nextprime(x) - x <= x-3. Numerical verification shows it holds for x > 2. So you don't need to test this one.

Ramanujan proved this in [url=http://www.imsc.res.in/~rao/ramanujan/CamUnivCpapers/Cpaper24/page1.htm]1919[/url] and possibly earlier.

science_man_88 2010-08-09 13:09

[QUOTE=CRGreathouse;224540]For x >= [url=http://oeis.org/classic/A104272]A104272[/url](2) + 1 = 12, nextprime(x) - x <= x-3. Numerical verification shows it holds for x > 2. So you don't need to test this one.

Ramanujan proved this in [url=http://www.imsc.res.in/~rao/ramanujan/CamUnivCpapers/Cpaper24/page1.htm]1919[/url] and possibly earlier.[/QUOTE]

theres only one in my image that skips any 6n+1 6n-1 numbers at all from the first one below I don't get why it couldn't have been solved.

CRGreathouse 2010-08-09 13:24

[QUOTE=science_man_88;224543]theres only one in my image that skips any 6n+1 6n-1 numbers at all from the first one below I don't get why it couldn't have been solved.[/QUOTE]

I don't understand your post. My only point was to show that the code
[code]for(x=4,N,if(isprime(x) && nextprime(x)-x>(x-3),print(x)))[/code]
will not print anything, regardless of the value of N used.

science_man_88 2010-08-09 13:31

[QUOTE=CRGreathouse;224545]I don't understand your post. My only point was to show that the code
[code]for(x=4,N,if(isprime(x) && nextprime(x)-x>(x-3),print(x)))[/code]
will not print anything, regardless of the value of N used.[/QUOTE]

I know that's what you meant as only one part of my image doesn't hit every 6n+1/-1 number either direction last I checked it should be simple to prove Goldbach's conjecture

CRGreathouse 2010-08-09 14:16

[QUOTE=science_man_88;224546]I know that's what you meant as only one part of my image doesn't hit every 6n+1/-1 number either direction last I checked it should be simple to prove Goldbach's conjecture[/QUOTE]

I don't understand the first part of your post. For the second part, I don't think that it is simple to prove the GC. :razz:


All times are UTC. The time now is 04:47.

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