Why is this deterministic variant of Miller-Rabin not working?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am using this paper as a reference.
The Miller-Rabin test, as classically formulated, is non-deterministic -- you pick a base $b$, check if your number $n$ is a $b$-strong probable prime ($b$-SPRP), and if it is, your number is probably prime (repeat until "confident.")
A deterministic variant, assuming your number $n$ is below some bound (say $n<2^64$), is to pick a small number of bases $b$, and check if $n$ is a $b$-SPRB relative to each of those bases. There seems to be a bit of a sport to finding very small sets of bases, so as to make this process as fast as possible.
In particular, the cited reference declares a theorem of Jaeschke and Sinclair, that
If $n < 2^64$ is a $b$-SPRP for $bin2, 325, 9375, 28178, 450775,
9780504, 1795265022$, then $n$ is a prime.
It doesn't state any extra hypotheses on $n$, or on what it means to be a $b$-SPRP. However, the classical formulation of Miller-Rabin only talks about $n$ being a $b$-SPRP when $bleq n-2$, whereas the theorem above seems to allow $n<b$.
In particular, I have found (purely by accident) that $n=13$ does not satisfy the above criterion, meaning that as stated it gives wrong answers, and I don't know why (so I can't predict more of them).
So the question: Is this a shortened form of a proper theorem, where I should only be checking the values of $b$ where $bleq n-2$? Is this an error in the paper? Am I just crazy?
For sake of completeness, the definition of $b$-SPRB I am using is the one given in the paper:
Factor $n$ as $2^sd$, where $s$ and $d$ are nonnegative integers and $d$ is odd. Then $n$ is a $b$-SPRB iff $b^dequiv 1 (mod n)$ or, for some $r$ with $0leq r < s$, $left(b^dright)^2^requiv -1 (mod n)$.
Not a duplicate of: Bases required for prime-testing with Miller-Rabin up to $2^63-1$ seems to lead to the same questions (they don't address the issue of when $n<b$; it's just irrelevant there) and uses bases so small it doesn't matter.
primality-test pseudoprimes
add a comment |Â
up vote
1
down vote
favorite
I am using this paper as a reference.
The Miller-Rabin test, as classically formulated, is non-deterministic -- you pick a base $b$, check if your number $n$ is a $b$-strong probable prime ($b$-SPRP), and if it is, your number is probably prime (repeat until "confident.")
A deterministic variant, assuming your number $n$ is below some bound (say $n<2^64$), is to pick a small number of bases $b$, and check if $n$ is a $b$-SPRB relative to each of those bases. There seems to be a bit of a sport to finding very small sets of bases, so as to make this process as fast as possible.
In particular, the cited reference declares a theorem of Jaeschke and Sinclair, that
If $n < 2^64$ is a $b$-SPRP for $bin2, 325, 9375, 28178, 450775,
9780504, 1795265022$, then $n$ is a prime.
It doesn't state any extra hypotheses on $n$, or on what it means to be a $b$-SPRP. However, the classical formulation of Miller-Rabin only talks about $n$ being a $b$-SPRP when $bleq n-2$, whereas the theorem above seems to allow $n<b$.
In particular, I have found (purely by accident) that $n=13$ does not satisfy the above criterion, meaning that as stated it gives wrong answers, and I don't know why (so I can't predict more of them).
So the question: Is this a shortened form of a proper theorem, where I should only be checking the values of $b$ where $bleq n-2$? Is this an error in the paper? Am I just crazy?
For sake of completeness, the definition of $b$-SPRB I am using is the one given in the paper:
Factor $n$ as $2^sd$, where $s$ and $d$ are nonnegative integers and $d$ is odd. Then $n$ is a $b$-SPRB iff $b^dequiv 1 (mod n)$ or, for some $r$ with $0leq r < s$, $left(b^dright)^2^requiv -1 (mod n)$.
Not a duplicate of: Bases required for prime-testing with Miller-Rabin up to $2^63-1$ seems to lead to the same questions (they don't address the issue of when $n<b$; it's just irrelevant there) and uses bases so small it doesn't matter.
primality-test pseudoprimes
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using this paper as a reference.
The Miller-Rabin test, as classically formulated, is non-deterministic -- you pick a base $b$, check if your number $n$ is a $b$-strong probable prime ($b$-SPRP), and if it is, your number is probably prime (repeat until "confident.")
A deterministic variant, assuming your number $n$ is below some bound (say $n<2^64$), is to pick a small number of bases $b$, and check if $n$ is a $b$-SPRB relative to each of those bases. There seems to be a bit of a sport to finding very small sets of bases, so as to make this process as fast as possible.
In particular, the cited reference declares a theorem of Jaeschke and Sinclair, that
If $n < 2^64$ is a $b$-SPRP for $bin2, 325, 9375, 28178, 450775,
9780504, 1795265022$, then $n$ is a prime.
It doesn't state any extra hypotheses on $n$, or on what it means to be a $b$-SPRP. However, the classical formulation of Miller-Rabin only talks about $n$ being a $b$-SPRP when $bleq n-2$, whereas the theorem above seems to allow $n<b$.
In particular, I have found (purely by accident) that $n=13$ does not satisfy the above criterion, meaning that as stated it gives wrong answers, and I don't know why (so I can't predict more of them).
So the question: Is this a shortened form of a proper theorem, where I should only be checking the values of $b$ where $bleq n-2$? Is this an error in the paper? Am I just crazy?
For sake of completeness, the definition of $b$-SPRB I am using is the one given in the paper:
Factor $n$ as $2^sd$, where $s$ and $d$ are nonnegative integers and $d$ is odd. Then $n$ is a $b$-SPRB iff $b^dequiv 1 (mod n)$ or, for some $r$ with $0leq r < s$, $left(b^dright)^2^requiv -1 (mod n)$.
Not a duplicate of: Bases required for prime-testing with Miller-Rabin up to $2^63-1$ seems to lead to the same questions (they don't address the issue of when $n<b$; it's just irrelevant there) and uses bases so small it doesn't matter.
primality-test pseudoprimes
I am using this paper as a reference.
The Miller-Rabin test, as classically formulated, is non-deterministic -- you pick a base $b$, check if your number $n$ is a $b$-strong probable prime ($b$-SPRP), and if it is, your number is probably prime (repeat until "confident.")
A deterministic variant, assuming your number $n$ is below some bound (say $n<2^64$), is to pick a small number of bases $b$, and check if $n$ is a $b$-SPRB relative to each of those bases. There seems to be a bit of a sport to finding very small sets of bases, so as to make this process as fast as possible.
In particular, the cited reference declares a theorem of Jaeschke and Sinclair, that
If $n < 2^64$ is a $b$-SPRP for $bin2, 325, 9375, 28178, 450775,
9780504, 1795265022$, then $n$ is a prime.
It doesn't state any extra hypotheses on $n$, or on what it means to be a $b$-SPRP. However, the classical formulation of Miller-Rabin only talks about $n$ being a $b$-SPRP when $bleq n-2$, whereas the theorem above seems to allow $n<b$.
In particular, I have found (purely by accident) that $n=13$ does not satisfy the above criterion, meaning that as stated it gives wrong answers, and I don't know why (so I can't predict more of them).
So the question: Is this a shortened form of a proper theorem, where I should only be checking the values of $b$ where $bleq n-2$? Is this an error in the paper? Am I just crazy?
For sake of completeness, the definition of $b$-SPRB I am using is the one given in the paper:
Factor $n$ as $2^sd$, where $s$ and $d$ are nonnegative integers and $d$ is odd. Then $n$ is a $b$-SPRB iff $b^dequiv 1 (mod n)$ or, for some $r$ with $0leq r < s$, $left(b^dright)^2^requiv -1 (mod n)$.
Not a duplicate of: Bases required for prime-testing with Miller-Rabin up to $2^63-1$ seems to lead to the same questions (they don't address the issue of when $n<b$; it's just irrelevant there) and uses bases so small it doesn't matter.
primality-test pseudoprimes
primality-test pseudoprimes
asked Aug 31 '17 at 12:30
Richard Rast
1,021616
1,021616
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
2
down vote
accepted
As stated the theorem is fine, because it only says if $n$ is a $b$-SPRB for all these $b$ then it is prime; it does not say "if and only if".
A prime $p$ will be a $b$-SPRB for any base $b$ which is not a multiple of $p$. So every prime will pass the test except for primes dividing one of the bases listed. Those primes are $2, 3, 5, 13, 19, 73, 193, 407521$ and $299210837$.
Thank you for the clarification.
â Richard Rast
Aug 31 '17 at 14:39
add a comment |Â
up vote
1
down vote
If you look at Best known SPRP base sets, you can see the remark "Depending on your Miller-Rabin implementation, you may need to take a â a mod n." and "When the witness a equals 0, the test should return that n is prime." The latter is saying we skip that test when n divides the base.
This is especially critical for making sense of the smaller base sets which generally have very large bases.
add a comment |Â
up vote
0
down vote
Sometimes the definition of SPRB includes the condition $gcd(b,n)=1$.
Anyway, if $b$ is a multiple of $n$ you have $b^dequiv 0 pmod n$ and $n$ cannot be a b-SPRB. So your implementation of the test is not correct, because $325 = 25times13.$
And you should always do the simple test $gcd(n,b)=1,$ if it fails you know $n$ is composite.
add a comment |Â
up vote
0
down vote
The deterministic version requires a modification as to how base values are handled. The base b
is reduced mod n
, and the test skipped (e.g., 'passed') in the event that b mod n = 0
. More details here.
I have a working implementation here.
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
As stated the theorem is fine, because it only says if $n$ is a $b$-SPRB for all these $b$ then it is prime; it does not say "if and only if".
A prime $p$ will be a $b$-SPRB for any base $b$ which is not a multiple of $p$. So every prime will pass the test except for primes dividing one of the bases listed. Those primes are $2, 3, 5, 13, 19, 73, 193, 407521$ and $299210837$.
Thank you for the clarification.
â Richard Rast
Aug 31 '17 at 14:39
add a comment |Â
up vote
2
down vote
accepted
As stated the theorem is fine, because it only says if $n$ is a $b$-SPRB for all these $b$ then it is prime; it does not say "if and only if".
A prime $p$ will be a $b$-SPRB for any base $b$ which is not a multiple of $p$. So every prime will pass the test except for primes dividing one of the bases listed. Those primes are $2, 3, 5, 13, 19, 73, 193, 407521$ and $299210837$.
Thank you for the clarification.
â Richard Rast
Aug 31 '17 at 14:39
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
As stated the theorem is fine, because it only says if $n$ is a $b$-SPRB for all these $b$ then it is prime; it does not say "if and only if".
A prime $p$ will be a $b$-SPRB for any base $b$ which is not a multiple of $p$. So every prime will pass the test except for primes dividing one of the bases listed. Those primes are $2, 3, 5, 13, 19, 73, 193, 407521$ and $299210837$.
As stated the theorem is fine, because it only says if $n$ is a $b$-SPRB for all these $b$ then it is prime; it does not say "if and only if".
A prime $p$ will be a $b$-SPRB for any base $b$ which is not a multiple of $p$. So every prime will pass the test except for primes dividing one of the bases listed. Those primes are $2, 3, 5, 13, 19, 73, 193, 407521$ and $299210837$.
answered Aug 31 '17 at 13:52
Especially Lime
19.7k22353
19.7k22353
Thank you for the clarification.
â Richard Rast
Aug 31 '17 at 14:39
add a comment |Â
Thank you for the clarification.
â Richard Rast
Aug 31 '17 at 14:39
Thank you for the clarification.
â Richard Rast
Aug 31 '17 at 14:39
Thank you for the clarification.
â Richard Rast
Aug 31 '17 at 14:39
add a comment |Â
up vote
1
down vote
If you look at Best known SPRP base sets, you can see the remark "Depending on your Miller-Rabin implementation, you may need to take a â a mod n." and "When the witness a equals 0, the test should return that n is prime." The latter is saying we skip that test when n divides the base.
This is especially critical for making sense of the smaller base sets which generally have very large bases.
add a comment |Â
up vote
1
down vote
If you look at Best known SPRP base sets, you can see the remark "Depending on your Miller-Rabin implementation, you may need to take a â a mod n." and "When the witness a equals 0, the test should return that n is prime." The latter is saying we skip that test when n divides the base.
This is especially critical for making sense of the smaller base sets which generally have very large bases.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
If you look at Best known SPRP base sets, you can see the remark "Depending on your Miller-Rabin implementation, you may need to take a â a mod n." and "When the witness a equals 0, the test should return that n is prime." The latter is saying we skip that test when n divides the base.
This is especially critical for making sense of the smaller base sets which generally have very large bases.
If you look at Best known SPRP base sets, you can see the remark "Depending on your Miller-Rabin implementation, you may need to take a â a mod n." and "When the witness a equals 0, the test should return that n is prime." The latter is saying we skip that test when n divides the base.
This is especially critical for making sense of the smaller base sets which generally have very large bases.
answered Sep 1 '17 at 17:15
DanaJ
2,2511916
2,2511916
add a comment |Â
add a comment |Â
up vote
0
down vote
Sometimes the definition of SPRB includes the condition $gcd(b,n)=1$.
Anyway, if $b$ is a multiple of $n$ you have $b^dequiv 0 pmod n$ and $n$ cannot be a b-SPRB. So your implementation of the test is not correct, because $325 = 25times13.$
And you should always do the simple test $gcd(n,b)=1,$ if it fails you know $n$ is composite.
add a comment |Â
up vote
0
down vote
Sometimes the definition of SPRB includes the condition $gcd(b,n)=1$.
Anyway, if $b$ is a multiple of $n$ you have $b^dequiv 0 pmod n$ and $n$ cannot be a b-SPRB. So your implementation of the test is not correct, because $325 = 25times13.$
And you should always do the simple test $gcd(n,b)=1,$ if it fails you know $n$ is composite.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Sometimes the definition of SPRB includes the condition $gcd(b,n)=1$.
Anyway, if $b$ is a multiple of $n$ you have $b^dequiv 0 pmod n$ and $n$ cannot be a b-SPRB. So your implementation of the test is not correct, because $325 = 25times13.$
And you should always do the simple test $gcd(n,b)=1,$ if it fails you know $n$ is composite.
Sometimes the definition of SPRB includes the condition $gcd(b,n)=1$.
Anyway, if $b$ is a multiple of $n$ you have $b^dequiv 0 pmod n$ and $n$ cannot be a b-SPRB. So your implementation of the test is not correct, because $325 = 25times13.$
And you should always do the simple test $gcd(n,b)=1,$ if it fails you know $n$ is composite.
edited Aug 31 '17 at 13:56
answered Aug 31 '17 at 13:30
gammatester
16k21529
16k21529
add a comment |Â
add a comment |Â
up vote
0
down vote
The deterministic version requires a modification as to how base values are handled. The base b
is reduced mod n
, and the test skipped (e.g., 'passed') in the event that b mod n = 0
. More details here.
I have a working implementation here.
add a comment |Â
up vote
0
down vote
The deterministic version requires a modification as to how base values are handled. The base b
is reduced mod n
, and the test skipped (e.g., 'passed') in the event that b mod n = 0
. More details here.
I have a working implementation here.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The deterministic version requires a modification as to how base values are handled. The base b
is reduced mod n
, and the test skipped (e.g., 'passed') in the event that b mod n = 0
. More details here.
I have a working implementation here.
The deterministic version requires a modification as to how base values are handled. The base b
is reduced mod n
, and the test skipped (e.g., 'passed') in the event that b mod n = 0
. More details here.
I have a working implementation here.
answered Sep 5 at 9:29
Brett Hale
1136
1136
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2412168%2fwhy-is-this-deterministic-variant-of-miller-rabin-not-working%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password