mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Miscellaneous Math (https://www.mersenneforum.org/forumdisplay.php?f=56)
-   -   Wheel factorization: Efficient? (https://www.mersenneforum.org/showthread.php?t=13609)

CRGreathouse 2010-07-22 13:11

[QUOTE=3.14159;222408].. I can't code it altogether. It has to be done in separate tests for the original.[/QUOTE]

OK. Can you make the fixes I (and sm88) suggested to your test?

3.14159 2010-07-22 13:14

[QUOTE]OK. Can you make the fixes I (and sm88) suggested to your test?[/QUOTE]

Okay. Fixing code, then running some tests. It works.

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

CRGreathouse 2010-07-22 13:22

Let's see the code! I'll post my version and we can compare.

3.14159 2010-07-22 13:24

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
};[/code]

I forgot to add the base component. It fails for pseudoprimes that pass trial division.

CRGreathouse 2010-07-22 13:29

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).");[/code]

science_man_88 2010-07-22 13:30

[QUOTE=3.14159;222414]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
};[/code][/QUOTE]

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.

3.14159 2010-07-22 13:33

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

CRGreathouse 2010-07-22 13:40

[QUOTE=3.14159;222418]The test keeps in all the damn pseudoprimes :no: [/QUOTE]

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))[/code]
after the Fermat test.

Also, as you already know but probably don't realize (:smile:), 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)[/code]
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)[/code]

3.14159 2010-07-22 13:44

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.

CRGreathouse 2010-07-22 13:51

pseudo(n) =!isprime(n)&isSPRP[COLOR="Red"](n)[/COLOR], surely?

I'll just leave this link to Sloane's [url=http://oeis.org/classic/A001262]A001262[/url] here in case you need it.

3.14159 2010-07-22 13:54

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

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.


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

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