mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Miscellaneous Math

Reply
 
Thread Tools
Old 2010-07-22, 13:11   #166
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
.. I can't code it altogether. It has to be done in separate tests for the original.
OK. Can you make the fixes I (and sm88) suggested to your test?

Last fiddled with by CRGreathouse on 2010-07-22 at 13:11
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 13:14   #167
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
OK. Can you make the fixes I (and sm88) suggested to your test?
Okay. Fixing code, then running some tests. It works.

Results: It lets all the pseudoprimes in. (Tested the well-known example, 1373653)

Last fiddled with by 3.14159 on 2010-07-22 at 13:18
3.14159 is offline   Reply With Quote
Old 2010-07-22, 13:22   #168
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

Let's see the code! I'll post my version and we can compare.
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 13:24   #169
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Here you go:
Code:
primetest(n, b=2) = {
if(ispower(n) == 1,return(0));
forprime(p=2,nextprime(500),
if(n%p==0,return(p))
);
if(Mod(b, n)^(n-1) == 1,return(n));
my(s=valuation(n-1,2),d=n>>s);
n = Mod(b, n)^d;
if (n == 1, return(n-1));
while(s--,
if (n == -1, return(n));
n = n^2;
);
n == -1
};
I forgot to add the base component. It fails for pseudoprimes that pass trial division.

Last fiddled with by 3.14159 on 2010-07-22 at 13:32
3.14159 is offline   Reply With Quote
Old 2010-07-22, 13:29   #170
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

I haven't run yours, but it will fail on any prime larger than nextprime(501), since you haven't defined your base.

I have
Code:
primetest(n:int,b:int=2) = {
	my(s,d);
	if(ispower(n),return(0));
	forprime(p=2,500,
		if(n%p==0,return(p))
	);
	if(Mod(b, n)^(n-1) == 1, return(n));
	s=valuation(n-1,2);
	d=n>>s;
	n = Mod(b, n)^d;
	if (n == 1, return(1));
	while(s--,
		if (n == -1, return(1));
		n = n^2;
	);
	n == -1
};
addhelp(primetest, "primetest(n, {b=2}): Returns the smallest prime factor of n, if one is found. Otherwise, returns 0 if the number is composite and 1 if the number passes all tests (in which case it may be prime or pseudoprime).");
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 13:30   #171
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Here you go:
Code:
primetest(n) = {
if(ispower(n) == 1,return(0));
forprime(p=2,nextprime(500),
if(n%p==0,return(p))
);
if(Mod(b, n)^(n-1) == 1,return(n));
my(s=valuation(n-1,2),d=n>>s);
n = Mod(b, n)^d;
if (n == 1, return(n-1));
while(s--,
if (n == -1, return(n));
n = n^2;
);
n == -1
};
not sure you need the ==1 one part for ispower as if(ispower(n) means if it returns 1 anyways if(!ispower(n) would return 1 if it was false but if !ispower is true when declaring ispower(n) would declare it flase and stop the execution anyways.
science_man_88 is offline   Reply With Quote
Old 2010-07-22, 13:33   #172
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

The test keeps in all the damn pseudoprimes Also: Code fixed, == 1 was removed from nth power check. New code = if(ispower(n), return(0));

Last fiddled with by 3.14159 on 2010-07-22 at 13:35
3.14159 is offline   Reply With Quote
Old 2010-07-22, 13:40   #173
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
The test keeps in all the damn pseudoprimes
Sure. IF you don't want that, you'll need some re-coding. Split isSPRP into its own function, then do
Code:
if(!isSPRP(n), return(0));
if(isprime(n), return(n), return(0))
after the Fermat test.

Also, as you already know but probably don't realize (), the last result of the program is simply returned. So my code snippet can be simplified to
Code:
if(!isSPRP(n), return(0));
if(isprime(n), n, 0)
since you won't be doing anything after that. And actually, since an omitted isFalse part of the if statement returns 0 by default, it could even be
Code:
if(!isSPRP(n), return(0));
if(isprime(n), n)
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 13:44   #174
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

110100100002 Posts
Default

I'm going to check if the SPRP test I implemented as any pseudoprime numbers:

pseudo(n) =!isprime(n)&isSPRP

forstep(n=3,1e8,2,if(pseudo(n),print(n))

It just prints me every odd number. Damned thing never does anything right.

Let's try:

if(pseudo(n),print(n))

Meh. Manual search.

Last fiddled with by 3.14159 on 2010-07-22 at 13:47
3.14159 is offline   Reply With Quote
Old 2010-07-22, 13:51   #175
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

pseudo(n) =!isprime(n)&isSPRP(n), surely?

I'll just leave this link to Sloane's A001262 here in case you need it.

Last fiddled with by CRGreathouse on 2010-07-22 at 13:53
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 13:54   #176
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
I'll just leave this link to Sloane's A001262 here in case you need it.
No, dammit. Those all fail the TD test. A pseudoprime to my test = Passes TD to 1000003 + Passes SPRP test (No base specified)

Pseudoprime number found: 58398839626753 = 5403649 * 10807297. (Base 2 only)

Wait.. To weed out pseudoprimes
I should change b to (random(n)).

Success: Now, random bases are tested.

Now, to test the same integer length range I did yesterday, to compare timings:
≈ 1000 digits: 312 ms.
≈ 2000 digits: 1.28 seconds
≈ 3000 digits: 3.41 seconds
≈ 13000 digits (second largest prime I've ever found): 134.97 seconds.

Last fiddled with by 3.14159 on 2010-07-22 at 14:19
3.14159 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wheel Factorization a1call Factoring 11 2017-06-19 14:04
Efficient Test paulunderwood Computer Science & Computational Number Theory 5 2017-06-09 14:02
LL tests more credit-efficient than P-1? ixfd64 Software 3 2011-02-20 16:24
A Wheel storm5510 Puzzles 7 2010-06-25 10:29
Most efficient way to LL hj47 Software 11 2009-01-29 00:45

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


Fri Aug 6 22:03:21 UTC 2021 up 14 days, 16:32, 1 user, load averages: 2.93, 2.80, 2.70

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.