Examples of infinite enumerated sets#
- sage.categories.examples.infinite_enumerated_sets.Example[source]#
alias of
NonNegativeIntegers
- class sage.categories.examples.infinite_enumerated_sets.NonNegativeIntegers[source]#
Bases:
UniqueRepresentation
,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() Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set sage: NN.element_class <class 'sage.rings.integer.Integer'> sage: it = iter(NN) sage: [next(it), next(it), next(it), next(it), next(it)] [0, 1, 2, 3, 4] sage: x = next(it); type(x) <class 'sage.rings.integer.Integer'> sage: x.parent() Integer Ring sage: x+3 8 sage: NN(15) 15 sage: NN.first() 0
>>> from sage.all import * >>> NN = InfiniteEnumeratedSets().example() >>> NN An example of an infinite enumerated set: the non negative integers >>> NN.cardinality() +Infinity >>> NN.list() Traceback (most recent call last): ... NotImplementedError: cannot list an infinite set >>> NN.element_class <class 'sage.rings.integer.Integer'> >>> it = iter(NN) >>> [next(it), next(it), next(it), next(it), next(it)] [0, 1, 2, 3, 4] >>> x = next(it); type(x) <class 'sage.rings.integer.Integer'> >>> x.parent() Integer Ring >>> x+Integer(3) 8 >>> NN(Integer(15)) 15 >>> 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_cardinality() . . . pass running ._test_category() . . . pass running ._test_construction() . . . pass running ._test_elements() . . . Running the test suite of self.an_element() running ._test_category() . . . pass running ._test_eq() . . . pass running ._test_new() . . . pass running ._test_nonzero_equal() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass pass running ._test_elements_eq_reflexive() . . . pass running ._test_elements_eq_symmetric() . . . pass running ._test_elements_eq_transitive() . . . pass running ._test_elements_neq() . . . 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_new() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass running ._test_some_elements() . . . pass
>>> from sage.all import * >>> TestSuite(NN).run(verbose = True) running ._test_an_element() . . . pass running ._test_cardinality() . . . pass running ._test_category() . . . pass running ._test_construction() . . . pass running ._test_elements() . . . Running the test suite of self.an_element() running ._test_category() . . . pass running ._test_eq() . . . pass running ._test_new() . . . pass running ._test_nonzero_equal() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass pass running ._test_elements_eq_reflexive() . . . pass running ._test_elements_eq_symmetric() . . . pass running ._test_elements_eq_transitive() . . . pass running ._test_elements_neq() . . . 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_new() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass running ._test_some_elements() . . . pass