# The set of prime numbers¶

AUTHORS:

• William Stein (2005): original version

• Florent Hivert (2009-11): adapted to the category framework. The following methods were removed:

• cardinality, __len__, __iter__: provided by EnumeratedSets
• __cmp__(self, other): __eq__ is provided by UniqueRepresentation and seems to do as good a job (all test pass)
class sage.sets.primes.Primes(proof)

The set of prime numbers.

EXAMPLES:

sage: P = Primes(); P
Set of all prime numbers: 2, 3, 5, 7, ...


We show various operations on the set of prime numbers:

sage: P.cardinality()
+Infinity
sage: R = Primes()
sage: P == R
True
sage: 5 in P
True
sage: 100 in P
False

sage: len(P)          # note: this used to be a TypeError
Traceback (most recent call last):
...
NotImplementedError: infinite list

first()

Returns the first prime number.

EXAMPLES:

sage: P = Primes()
sage: P.first()
2

next(pr)

Returns the next prime number.

EXAMPLES:

sage: P = Primes()
sage: P.next(5)
7

unrank(n)

Returns the n-th prime number.

EXAMPLES::
sage: P = Primes() sage: P.unrank(0) 2 sage: P.unrank(5) 13 sage: P.unrank(42) 191

#### Previous topic

Non Negative Integers

#### Next topic

Totally Ordered Finite Sets