Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

r""" 

Infinite Enumerated Sets 

 

AUTHORS: 

 

- Florent Hivert (2009-11): initial revision. 

 

""" 

#***************************************************************************** 

# Copyright (C) 2009 Florent Hivert <Florent.Hivert@univ-rouen.fr> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# http://www.gnu.org/licenses/ 

#****************************************************************************** 

 

 

from sage.categories.category_with_axiom import CategoryWithAxiom 

 

class InfiniteEnumeratedSets(CategoryWithAxiom): 

""" 

The category of infinite enumerated sets 

 

An infinite enumerated sets is a countable set together with a 

canonical enumeration of its elements. 

 

EXAMPLES:: 

 

sage: InfiniteEnumeratedSets() 

Category of infinite enumerated sets 

sage: InfiniteEnumeratedSets().super_categories() 

[Category of enumerated sets, Category of infinite sets] 

sage: InfiniteEnumeratedSets().all_super_categories() 

[Category of infinite enumerated sets, 

Category of enumerated sets, 

Category of infinite sets, 

Category of sets, 

Category of sets with partial maps, 

Category of objects] 

 

TESTS:: 

 

sage: C = InfiniteEnumeratedSets() 

sage: TestSuite(C).run() 

""" 

 

class ParentMethods: 

 

def random_element(self): 

""" 

Returns an error since self is an infinite enumerated set. 

 

EXAMPLES:: 

 

sage: NN = InfiniteEnumeratedSets().example() 

sage: NN.random_element() 

Traceback (most recent call last): 

... 

NotImplementedError: infinite set 

 

TODO: should this be an optional abstract_method instead? 

""" 

raise NotImplementedError("infinite set") 

 

def list(self): 

""" 

Returns an error since self is an infinite enumerated set. 

 

EXAMPLES:: 

 

sage: NN = InfiniteEnumeratedSets().example() 

sage: NN.list() 

Traceback (most recent call last): 

... 

NotImplementedError: cannot list an infinite set 

""" 

raise NotImplementedError("cannot list an infinite set") 

_list_default = list # needed by the check system. 

 

def _test_enumerated_set_iter_cardinality(self, **options): 

""" 

Check that the methods :meth:`.cardinality` and 

:meth:`.__iter__` are consistent. 

 

See also :class:`TestSuite`. 

 

For infinite enumerated sets: 

 

* :meth:`.cardinality` is supposed to return `infinity` 

 

* :meth:`.list` is supposed to raise a ``NotImplementedError``. 

 

EXAMPLES:: 

 

sage: NN = InfiniteEnumeratedSets().example() 

sage: NN._test_enumerated_set_iter_cardinality() 

""" 

tester = self._tester(**options) 

from sage.rings.infinity import infinity 

tester.assertEqual(self.cardinality(), infinity) 

tester.assertRaises(NotImplementedError, self.list)