I just want to confirm my intuition about this method. Consider the code below.
long knownPrime = // some large known prime
int certainty = // some integer greater than 0
BigInteger b = BigInteger.valueOf(knownPrime);
boolean isPrime = b.isProbablePrime(certainty);
For a large known prime, and for any certainty > 0, is it accurate to say that b.isProbablePrime(certainty)
will always return true?
Or are there any cases where the method "guesses" that a known prime number is composite?
BigInteger isProbablePrime() Method in Java with ExamplesThis method checks for prime or composite upon the current BigInteger by which this method is called and returns a boolean value. It returns true if this BigInteger is probably prime, false if it's definitely composite. If certainty is <= 0, true is returned.
certainty Int32. a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 - 1/2<sup> certainty </sup>). The execution time of this method is proportional to the value of this parameter.
The isProbablePrime() method of Java BigInteger class is used to determine if the given number is prime or not. For certainty =1, this method returns true if this BigInteger is prime and false if this BigInteger is composite.
The BigInteger class allows you to create and manipulate integer numbers of any size. The BigInteger class stores a number as an array of unsigned, 32-bit integer "digits" with a radix, or base, of 4294967296.
For a large known prime, and for any certainty > 0, is it accurate to say that b.isProbablePrime(certainty) will always return true?
Yes. The documentation says it will return false
only if it is certain that the number is composite.
Returns: true if this BigInteger is probably prime, false if it's definitely composite.
So the certainty
parameter will influence only on the chance of a false-positive: saying a composite number is prime, when it really is not.
For a large known prime b
, and for any certainty
, b.isProbablePrime(certainty)
returns true
.
isProbablePrime
can only err by returning true
when the input is not prime (an example is b=6
, certainty=0
, which returns true
), never the other way (because the Rabin-Miller test, which isProbablePrime
uses, can only fail in this direction).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With