mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Miscellaneous Math

Reply
 
Thread Tools
Old 2010-07-22, 00:54   #155
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

What is this supposed to return?
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 01:25   #156
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
What is this supposed to return?
If prime, the number itself. If it fails trial division, the smallest prime factor.
3.14159 is offline   Reply With Quote
Old 2010-07-22, 01:48   #157
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
If prime, the number itself. If it fails trial division, the smallest prime factor.
Then you need to change the last line of the program (other than the "};" of course). And what's it supposed to return if the number is composite without a known factor?
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 04:16   #158
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Then you need to change the last line of the program (other than the "};" of course). And what's it supposed to return if the number is composite without a known factor?
It returns zero if it's a composite that passes. So there are no pseudoprimes.

Testing for c100: 317305983867984894552374513880330942325323897104138220309522782479794265138440652957829496038865542387
Result = 31 ms.

c200: 47 ms.
c400: 78 ms.
c800: 218 ms.
c1600: 702 ms.

p200: 47 ms.
p400: 94 ms.
p800: 219 ms.

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

3×1,993 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
It returns zero if it's a composite that passes. So there are no pseudoprimes.
I'm not sure what that has to do with what I said. You wrote of the program:

Quote:
Originally Posted by 3.14159 View Post
If prime, the number itself. If it fails trial division, the smallest prime factor.
But for 101 it returns 1, not 101.
CRGreathouse is offline   Reply With Quote
Old 2010-07-22, 04:25   #160
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Quote:
But for 101 it returns 1, not 101.
Ah. I figured that one out. It only returns the number itself whenever you specify a base. Pretty much, the prime test can handle anything that's ≤ 1k digits in a few seconds. For larger primes, Proth will do to generate such numbers.

≈ 2000 digits: Approximately 1 second.
≈ 1000 digits: About 0.28 seconds.
≈ 3000 digits: About 2.65 seconds.

Testing the second largest prime I have ever found: 94.25 seconds.

Great. It's suitable for small primes and mid-sized primes.

Also: It may return either: Mod(1, n), or Mod(n-1, n) for primes.

Params set: SPRP = Trial division + Miller-Rabin test (Primality confirmation: Perform here. Be warned: 900+ digits, it uses Miller-Rabin as a test, use this only for small integers. For larger cases, use PARI's isprime(n) function.)

WPRP = Fermat's primality test"

Hey: I thought of something:
I'm going to code the original 7-step test, and see by how much it is slower, in the long run. Tips?

Here's my long-winded guess:
Code:
primetest(n) = {
if(ispower(n) == 1,print(1));
forprime(p=2,nextprime(500),
if(n%p==0,return(p))
);
if(Mod(b, n)^(n-1) == 1,print(n));
my(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
};

Last fiddled with by 3.14159 on 2010-07-22 at 04:59
3.14159 is offline   Reply With Quote
Old 2010-07-22, 10:03   #161
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Ah. I figured that one out. It only returns the number itself whenever you specify a base. Pretty much, the prime test can handle anything that's ≤ 1k digits in a few seconds. For larger primes, Proth will do to generate such numbers.

≈ 2000 digits: Approximately 1 second.
≈ 1000 digits: About 0.28 seconds.
≈ 3000 digits: About 2.65 seconds.

Testing the second largest prime I have ever found: 94.25 seconds.

Great. It's suitable for small primes and mid-sized primes.

Also: It may return either: Mod(1, n), or Mod(n-1, n) for primes.

Params set: SPRP = Trial division + Miller-Rabin test (Primality confirmation: Perform here. Be warned: 900+ digits, it uses Miller-Rabin as a test, use this only for small integers. For larger cases, use PARI's isprime(n) function.)

WPRP = Fermat's primality test"

Hey: I thought of something:
I'm going to code the original 7-step test, and see by how much it is slower, in the long run. Tips?

Here's my long-winded guess:
Code:
primetest(n) = {
if(ispower(n) == 1,print(1));
forprime(p=2,nextprime(500),
if(n%p==0,return(p))
);
if(Mod(b, n)^(n-1) == 1,print(n));
my(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
};
I may no nothing about the test but I'm pretty sure you don't have to have the ==1 part for ispower as it should just check it itself.

Last fiddled with by science_man_88 on 2010-07-22 at 10:04
science_man_88 is offline   Reply With Quote
Old 2010-07-22, 12:18   #162
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

32208 Posts
Default

Testing.. Dammit. I have a syntax error. The error reads:
Code:
 *** Mod: incorrect type in Rg_to_Fl.

Last fiddled with by 3.14159 on 2010-07-22 at 12:19
3.14159 is offline   Reply With Quote
Old 2010-07-22, 12:48   #163
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Testing.. Dammit. I have a syntax error. The error reads:
Code:
 *** Mod: incorrect type in Rg_to_Fl.
you also have what I pointed out with something extra than what's needed. I can't spot much else but I'm not good with PARI(especially the new stuff).
science_man_88 is offline   Reply With Quote
Old 2010-07-22, 13:01   #164
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

175B16 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
Hey: I thought of something:
I'm going to code the original 7-step test, and see by how much it is slower, in the long run. Tips?
1. Don't print 1 when a power is found, instead return 0.
2. You can't raise b to a power mod n unless you know what b is. (I suggest adding an optional argument for b.)
3. Don't print n when Mod(b, n)^(n-1) == 1, instead return n.
4. Change the line n == -1 to an if statement returning either 0 or n.

I see four steps, not seven (power, trial division, Fermat test, M-R test). Also I suggest adding an addhelp explaining how the function works: you wouldn't want someone doing
Code:
if(primetest(n), print(n" is prime"))
the way you've written it.

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

69016 Posts
Default

.. I can't code it altogether. It has to be done in separate tests for the original.

Last fiddled with by 3.14159 on 2010-07-22 at 13:13
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:16 UTC 2021 up 14 days, 16:32, 1 user, load averages: 2.75, 2.77, 2.69

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.