Positive Integers - Sets

Skip to content
Back to top
View this page
Edit this page

# Positive Integers

class sage.sets.positive_integers.PositiveIntegers

  Bases: `IntegerRangeInfinite`

  The enumerated set of positive integers. To fix the ideas, we mean \(\{1, 2, 3, 4, 5, \dots \}\).

  This class implements the set of positive integers, as an enumerated set (see `InfiniteEnumeratedSets`).

  This set is an integer range set. The construction is therefore done by IntegerRange (see `IntegerRange`).

  EXAMPLES:

  Sage

      sage: PP = PositiveIntegers()
      sage: PP
      Positive integers
      sage: PP.cardinality()
      +Infinity
      sage: TestSuite(PP).run()
      sage: PP.list()
      Traceback (most recent call last):
      ...
      NotImplementedError: cannot list an infinite set
      sage: it = iter(PP)
      sage: (next(it), next(it), next(it), next(it), next(it))
      (1, 2, 3, 4, 5)
      sage: PP.first()
      1

  Python

      >>> from sage.all import *
      >>> PP = PositiveIntegers()
      >>> PP
      Positive integers
      >>> PP.cardinality()
      +Infinity
      >>> TestSuite(PP).run()
      >>> PP.list()
      Traceback (most recent call last):
      ...
      NotImplementedError: cannot list an infinite set
      >>> it = iter(PP)
      >>> (next(it), next(it), next(it), next(it), next(it))
      (1, 2, 3, 4, 5)
      >>> PP.first()
      1

  an_element()

    Return an element of `self`.

    EXAMPLES:

    Sage

        sage: PositiveIntegers().an_element()
        42

    Python

        >>> from sage.all import *
        >>> PositiveIntegers().an_element()
        42