![]() |
What is this supposed to return?
|
[QUOTE]What is this supposed to return?[/QUOTE]
If prime, the number itself. If it fails trial division, the smallest prime factor. |
[QUOTE=3.14159;222373]If prime, the number itself. If it fails trial division, the smallest prime factor.[/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? |
[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?[/QUOTE]
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. |
[QUOTE=3.14159;222381]It returns zero if it's a composite that passes. So there are no pseudoprimes.[/QUOTE]
I'm not sure what that has to do with what I said. You wrote of the program: [QUOTE=3.14159;222373]If prime, the number itself. If it fails trial division, the smallest prime factor.[/QUOTE] But for 101 it returns 1, not 101. |
[QUOTE]But for 101 it returns 1, not 101.[/QUOTE]
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: [URL="http://www.alpertron.com.ar/ECM.HTM"]Perform here[/URL]. 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 };[/code] |
[QUOTE=3.14159;222383]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: [URL="http://www.alpertron.com.ar/ECM.HTM"]Perform here[/URL]. 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 };[/code][/QUOTE] 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. |
Testing.. Dammit. I have a syntax error. The error reads:
[code] *** Mod: incorrect type in Rg_to_Fl.[/code] |
[QUOTE=3.14159;222400]Testing.. Dammit. I have a syntax error. The error reads:
[code] *** Mod: incorrect type in Rg_to_Fl.[/code][/QUOTE] 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). |
[QUOTE=3.14159;222383]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?[/QUOTE] 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"))[/code] the way you've written it. |
.. I can't code it altogether. It has to be done in separate tests for the original.
|
| All times are UTC. The time now is 22:06. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.