-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
math/big: Comment for Int.ProbablyPrime() is inaccurate #12274
Comments
The original comment says to the reader that Your comment says that the function is always right on prime numbers, but it could be fooled (with small probability) by composite numbers. This is correct, but why is it "more accurate"? Your proposed comment does not say what a |
The statement "if x is not prime, it returns false with probability at least 1 - 1/4^n" is true, but it does not imply the different statement "if it returns true, x is prime with probability 1 - 1/4^n"; it's the figure of "1 - 1/4^n" that is inaccurate. If you wanted to keep the original wording, you could say something like:
|
@ALTree (For some reason, GitHub isn't showing your latest comment so I'm quoting it here.) Edit: Just realized you probably just deleted it. Leaving this up in case anyone else reading is unsure.
Sorry, I wasn't clear. The original statement states the bound incorrectly. My first suggestion replaced it with the correct statement of the bound. The Wikipedia link explains this also, but it's easier to see with symbols. Let X be the event "x is prime", and Y be the event "ProbablyPrime returns true". The correct statement of the bound is this: P(not Y | not X) >= 1 - 4^{-n} The original comment is saying P(X | Y) = 1 - 4^{-n} which does not follow, even if you replace = with >=. You need to use Bayes rule to compute that probability, which in general depends on the number x and the density of primes around it. So the best you can say in general is that P(X | Y) increases as n does. |
Thinking about it a bit more, I have a third suggestion:
(see https://en.wikipedia.org/wiki/Bayes%27_rule#Frequentist_example for where this comes from.) It preserves the form of the original comment and is less vague than my second suggestion. Not sure how many people are familiar with likelihood ratios, though. |
@akalin Yeah I deleted it because after re-reading your comment I understood the point you were making. I have a comment. You wrote that "So the best you can say in general is that P(X | Y) increases as n does.". Is this true? I mean: maybe
I'm not a bayesian, but is there a way to express the statement
|
@ALTree You can say more, if you're willing to talk about the prior probability of x being prime. Maybe something like:
Not as simple an expression, I'm afraid. |
Thanks all. I'm suggesting https://go-review.googlesource.com/#/c/14052 as the fix for this. |
CL https://golang.org/cl/14052 mentions this issue. |
It says:
But this is backwards. It should be more like:
See https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Accuracy_of_the_test for a detailed explanation.
Also, the comment for nat.probablyPrime() needs to be changed similarly.
The text was updated successfully, but these errors were encountered: