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
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
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
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
There is nothing to initialize for the set of primes.
EXAMPLES:
sage: P = Primes()
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
Representation of the set of primes.
EXAMPLES:
sage: P = Primes(); P
Set of all prime numbers: 2, 3, 5, 7, ...
There is no largest prime number, so we say the set has infinite cardinality.
EXAMPLES:
sage: P = Primes()
sage: P.cardinality()
+Infinity