Why is this deterministic variant of Miller-Rabin not working?

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|cite|improve this question

























    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.










    share|cite|improve this question























      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.










      share|cite|improve this question













      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






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Aug 31 '17 at 12:30









      Richard Rast

      1,021616




      1,021616




















          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$.






          share|cite|improve this answer




















          • Thank you for the clarification.
            – Richard Rast
            Aug 31 '17 at 14:39

















          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.






          share|cite|improve this answer



























            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.






            share|cite|improve this answer





























              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.






              share|cite|improve this answer




















                Your Answer




                StackExchange.ifUsing("editor", function ()
                return StackExchange.using("mathjaxEditing", function ()
                StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
                StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
                );
                );
                , "mathjax-editing");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "69"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: true,
                noModals: false,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                noCode: true, onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                 

                draft saved


                draft discarded


















                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






























                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$.






                share|cite|improve this answer




















                • Thank you for the clarification.
                  – Richard Rast
                  Aug 31 '17 at 14:39














                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$.






                share|cite|improve this answer




















                • Thank you for the clarification.
                  – Richard Rast
                  Aug 31 '17 at 14:39












                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$.






                share|cite|improve this answer












                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$.







                share|cite|improve this answer












                share|cite|improve this answer



                share|cite|improve this answer










                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
















                • 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










                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.






                share|cite|improve this answer
























                  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.






                  share|cite|improve this answer






















                    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.






                    share|cite|improve this answer












                    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.







                    share|cite|improve this answer












                    share|cite|improve this answer



                    share|cite|improve this answer










                    answered Sep 1 '17 at 17:15









                    DanaJ

                    2,2511916




                    2,2511916




















                        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.






                        share|cite|improve this answer


























                          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.






                          share|cite|improve this answer
























                            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.






                            share|cite|improve this answer














                            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.







                            share|cite|improve this answer














                            share|cite|improve this answer



                            share|cite|improve this answer








                            edited Aug 31 '17 at 13:56

























                            answered Aug 31 '17 at 13:30









                            gammatester

                            16k21529




                            16k21529




















                                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.






                                share|cite|improve this answer
























                                  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.






                                  share|cite|improve this answer






















                                    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.






                                    share|cite|improve this answer












                                    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.







                                    share|cite|improve this answer












                                    share|cite|improve this answer



                                    share|cite|improve this answer










                                    answered Sep 5 at 9:29









                                    Brett Hale

                                    1136




                                    1136



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        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













































































                                        這個網誌中的熱門文章

                                        How to combine Bézier curves to a surface?

                                        Mutual Information Always Non-negative

                                        Why am i infinitely getting the same tweet with the Twitter Search API?