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

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

r""" 

Finite combinatorial classes 

""" 

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

# Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>, 

# 

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

# 

# This code is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 

# General Public License for more details. 

# 

# The full text of the GPL is available at: 

# 

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

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

from __future__ import absolute_import 

from six.moves import range 

 

from .combinat import CombinatorialClass 

from sage.misc.superseded import deprecation 

 

 

class FiniteCombinatorialClass(CombinatorialClass): 

""" 

This class is deprecated, and will disappear as soon as all derived 

classes in Sage's library will have been fixed. Please derive 

directly from Parent and use the category :class:`FiniteEnumeratedSets`. 

 

INPUT: 

 

- l a list or iterable 

 

Returns l, wrapped as a combinatorial class 

 

EXAMPLES:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: F.list() 

[1, 2, 3] 

sage: F.cardinality() 

3 

sage: F.random_element() 

1 

sage: F.first() 

1 

sage: F.last() 

3 

""" 

def __init__(self, l): 

""" 

TESTS:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: F == loads(dumps(F)) 

True 

""" 

deprecation(13552, "Please use FiniteEnumeratedSets instead.") 

self.l = list(l) # Probably would be better to use a tuple 

 

def _element_constructor_(self, x): 

""" 

EXAMPLES:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: F._element_constructor_(1) 

1 

sage: F(1) 

1 

""" 

return x 

 

def __repr__(self): 

""" 

TESTS:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: repr(F) 

'Combinatorial class with elements in [1, 2, 3]' 

""" 

return "Combinatorial class with elements in %s"%self.l 

 

def __contains__(self, x): 

""" 

EXAMPLES:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: 1 in F 

True 

sage: 2 in F 

True 

sage: 4 in F 

False 

sage: ZZ in F 

False 

""" 

return x in self.l 

 

def list(self): 

""" 

TESTS:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: F.list() 

[1, 2, 3] 

""" 

return self.l 

 

def cardinality(self): 

""" 

EXAMPLES:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: F.cardinality() 

3 

""" 

return len(self.l) 

 

 

def __getitem__(self, i): # TODO: optimize 

""" 

EXAMPLES:: 

 

sage: F = FiniteCombinatorialClass(["a", "b", "c"]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: F[2] 

'c' 

""" 

return self.l[i] 

 

def keys(self): 

""" 

EXAMPLES:: 

 

sage: F = FiniteCombinatorialClass([1,2,3]) 

doctest:warning...: 

DeprecationWarning: Please use FiniteEnumeratedSets instead. 

See http://trac.sagemath.org/13552 for details. 

sage: F.keys() 

[0, 1, 2] 

""" 

return list(range(len(self.l))) 

 

# Backward compatibility pointer 

# Needed for unpickling. 

FiniteCombinatorialClass_l = FiniteCombinatorialClass