The set of prime numbers

sage.sets.primes.Primes()

Return the set of prime numbers.

EXAMPLES:

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

We show various methods about the primes:

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

The set of prime numbers.

EXAMPLES:

sage: P = Primes(); P
Set of all prime numbers: 2, 3, 5, 7, ...
sage: loads(P.dumps()) == P
True
__cmp__(right)

The set of primes can be compared to various things, but is only equal to itself.

EXAMPLES:

sage: P = Primes()
sage: R = Primes()
sage: P.__cmp__(R)
0
sage: P == R
True
sage: P != R
False
sage: Q=[1,2,3]
sage: Q != P        # indirect doctest
True
sage: R.<x>=ZZ[]
sage: P!=x^2+x
True
__contains__(x)

Checks whether an object is a prime number. If it is not an integer, returns False.

EXAMPLES:

sage: P = Primes()
sage: 5 in P
True
sage: 100 in P
False
sage: 1.5 in P
False
sage: e in P
False
__init__()

There is nothing to initialize for the set of primes.

EXAMPLES:

sage: P = Primes()
__iter__()

Iterator for the set of primes. This is an infinite set, so USE WITH CAUTION! That is, do not do things like [p for p in Primes()].

EXAMPLES:

sage: P = Primes()
sage: iter(P).next()
2
__repr__()

Representation of the set of primes.

EXAMPLES:

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

There is no largest prime number, so we say the set has infinite cardinality.

EXAMPLES:

sage: P = Primes()
sage: P.cardinality()
+Infinity

Previous topic

Sets

Next topic

Families

This Page