isprime
-- primality testisprime(
n)
checks whether n
is a prime number.
isprime(n)
n |
- | an arithmetical expression representing an integer |
either TRUE
or
FALSE
, or a symbolic
isprime
call.
factor
, ifactor
, igcd
, ilcm
, irreducible
, ithprime
, nextprime
, numlib::primedivisors
,
numlib::prevprime
,
numlib::proveprime
isprime
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.The 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)