Examples of infinite enumerated sets

sage.categories.examples.infinite_enumerated_sets.Example
alias of NonNegativeIntegers
class sage.categories.examples.infinite_enumerated_sets.NonNegativeIntegers

Bases: sage.structure.unique_representation.UniqueRepresentation, sage.structure.parent.Parent

An example of infinite enumerated set: the non negative integers

This class provides a minimal implementation of an infinite enumerated set.

EXAMPLES:

sage: NN = InfiniteEnumeratedSets().example()
sage: NN
An example of an infinite enumerated set: the non negative integers
sage: NN.cardinality()
+Infinity
sage: NN.list()
...
NotImplementedError: infinite list
sage: NN.element_class
<type 'sage.rings.integer.Integer'>
sage: it = iter(NN)
sage: [it.next(), it.next(), it.next(), it.next(), it.next()]
[0, 1, 2, 3, 4]
sage: x = it.next(); type(x)
<type 'sage.rings.integer.Integer'>
sage: x.parent()
Integer Ring
sage: x+3
8
sage: NN(15)
15
sage: NN.first()
0

This checks that the different methods of NN return consistent results:

sage: TestSuite(NN).run(verbose = True)
running ._test_an_element() . . . pass
running ._test_category() . . . pass
running ._test_elements() . . .
  Running the test suite of self.an_element()
  running ._test_category() . . . pass
  running ._test_eq() . . . pass
  running ._test_not_implemented_methods() . . . pass
  running ._test_pickling() . . . pass
  pass
running ._test_elements_eq() . . . pass
running ._test_enumerated_set_contains() . . . pass
running ._test_enumerated_set_iter_cardinality() . . . pass
running ._test_enumerated_set_iter_list() . . . pass
running ._test_eq() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . pass
running ._test_some_elements() . . . pass
Element
alias of Integer
an_element()

EXAMPLES:

sage: InfiniteEnumeratedSets().example().an_element()
42
next(o)

EXAMPLES:

sage: NN = InfiniteEnumeratedSets().example()
sage: NN.next(3)
4

Previous topic

Examples of algebras with basis

Next topic

Examples of monoids

This Page