## `isprime` -- primality test

#### Introduction

`isprime(`n`)` checks whether `n` is a prime number.

#### Call(s)

`isprime(n)`

#### Parameters

`n` | - | an arithmetical expression representing an integer

#### Returns

either `TRUE` or `FALSE`, or a symbolic `isprime` call.

#### Related Functions

`factor`, `ifactor`, `igcd`, `ilcm`, `irreducible`, `ithprime`, `nextprime`, `numlib::primedivisors`, `numlib::prevprime`, `numlib::proveprime`

#### Details

- `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`.
- If `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 1

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)

#### Background

- Reference: Michael O. Rabin, Probabilistic algorithms, in J. F. Traub, ed., Algorithms and Complexity, Academic Press, New York, 1976, pp. 21-39.

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000