## `ithprime` -- the i-th prime number

#### Introduction

`ithprime(`i`)` returns the i-th prime number.

#### Call(s)

`ithprime(i)`

#### Parameters

`i` | - | an arithmetical expression

#### Returns

a prime number or an unevaluated call to `ithprime`

#### Related Functions

`ifactor`, `igcd`, `ilcm`, `isprime`, `nextprime`, `numlib::prevprime`

#### Details

- If the argument `i` is a positive integer, then `ithprime` returns the i-th prime number. An unevaluated call is returned, if the argument is not of type `Type::Numeric`. An error occurs if the argument is a number that is not a positive integer.
- The first prime number `ithprime(`1`)` is 2.
- If the i-th prime number is contained in the system's internal prime number table (see the help page for `ifactor`), then it is returned by a fast kernel function. Otherwise, MuPAD iteratively calls `nextprime`, using some suitable pre-computed value of `ithprime` as starting point. This is still reasonably fast for i <= 1000000. If i exceeds this value, however, then the run time grows exponentially with the number of digits of i.

#### Example 1

The first 10 prime numbers:

    >> ithprime(i) $ i = 1..10

                        2, 3, 5, 7, 11, 13, 17, 19, 23, 29

A larger prime:

    >> ithprime(123456)

                                      1632899

Symbolic arguments lead to an unevaluated call:

    >> ithprime(i)

                                    ithprime(i)

#### Changes

- no changes

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