isprime -- primality test
Introductionisprime(n) checks whether n
is a prime number.
Call(s)isprime(n)
Parametersn |
- | an arithmetical expression representing an integer |
Returnseither TRUE or
FALSE, or a symbolic
isprime call.
Related
Functionsfactor, ifactor, igcd, ilcm, irreducible, ithprime, nextprime, numlib::primedivisors,
numlib::prevprime,
numlib::proveprime
Detailsisprime is a fast probabilistic prime number test
(Miller-Rabin test). The function returns TRUE when the positive integer n is either a prime number or a
strong pseudo-prime for 10 independently and randomly chosen
bases. Otherwise, isprime returns FALSE.n is positive and isprime returns
FALSE, then
n is guaranteed to be composite. If n is
positive and isprime returns TRUE, then n is prime with
a very high probability.
Use numlib::proveprime for a prime
number test that always returns the correct answer. Note, however, that
it is usually much slower than isprime.
isprime(0) and
isprime(1) return FALSE. isprime returns
always FALSE if
n is a negative integer.isprime returns an error message if its argument is a
number but not an integer.
isprime returns a symbolic isprime call if
the argument is not a number.isprime is a function of the system kernel.
Example
1The number 989999 is prime:
>> isprime(989999)
TRUE
>> ifactor(989999)
989999
In contrast to ifactor, isprime can
handle large numbers:
>> isprime(2^(2^11) + 1)
FALSE
isprime(0) and
isprime(1) return FALSE:
>> isprime(0), isprime(1)
FALSE, FALSE
Negative numbers yield FALSE as well:
>> isprime(-13)
FALSE
For non-numeric arguments, a symbolic
isprime call is returned:
>> delete n: isprime(n)
isprime(n)
Background