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

""" 

Examples of CW complexes 

""" 

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

# Copyright (C) 2015 Travis Scrimshaw <tscrim at ucdavis.edu> 

# 

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

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

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

 

from sage.structure.parent import Parent 

from sage.structure.unique_representation import UniqueRepresentation 

from sage.structure.element import Element 

from sage.categories.cw_complexes import CWComplexes 

from sage.rings.integer import Integer 

from sage.rings.all import QQ 

from sage.sets.family import Family 

 

class Surface(UniqueRepresentation, Parent): 

r""" 

An example of a CW complex: a (2-dimensional) surface. 

 

This class illustrates a minimal implementation of a CW complex. 

 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example(); X 

An example of a CW complex: the surface given by the boundary map (1, 2, 1, 2) 

 

sage: X.category() 

Category of finite finite dimensional CW complexes 

 

We conclude by running systematic tests on this manifold:: 

 

sage: TestSuite(X).run() 

""" 

def __init__(self, bdy=(1, 2, 1, 2)): 

r""" 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example((1, 2)); X 

An example of a CW complex: the surface given by the boundary map (1, 2) 

 

TESTS:: 

 

sage: TestSuite(X).run() 

""" 

self._bdy = bdy 

self._edges = frozenset(bdy) 

Parent.__init__(self, category=CWComplexes().Finite()) 

 

def _repr_(self): 

r""" 

TESTS:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: CWComplexes().example() 

An example of a CW complex: the surface given by the boundary map (1, 2, 1, 2) 

""" 

return "An example of a CW complex: the surface given by the boundary map {}".format(self._bdy) 

 

def cells(self): 

""" 

Return the cells of ``self``. 

 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example() 

sage: C = X.cells() 

sage: sorted((d, C[d]) for d in C.keys()) 

[(0, (0-cell v,)), 

(1, (0-cell e1, 0-cell e2)), 

(2, (2-cell f,))] 

""" 

d = {0: (self.element_class(self, 0, 'v'),)} 

d[1] = tuple([self.element_class(self, 0, 'e'+str(e)) for e in self._edges]) 

d[2] = (self.an_element(),) 

return Family(d) 

 

def an_element(self): 

r""" 

Return an element of the CW complex, as per 

:meth:`Sets.ParentMethods.an_element`. 

 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example() 

sage: X.an_element() 

2-cell f 

""" 

return self.element_class(self, 2, 'f') 

 

class Element(Element): 

""" 

A cell in a CW complex. 

""" 

def __init__(self, parent, dim, name): 

""" 

Initialize ``self``. 

 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example() 

sage: f = X.an_element() 

sage: TestSuite(f).run() 

""" 

Element.__init__(self, parent) 

self._dim = dim 

self._name = name 

 

def _repr_(self): 

""" 

Return a string representation of ``self``. 

 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example() 

sage: X.an_element() 

2-cell f 

""" 

return "{}-cell {}".format(self._dim, self._name) 

 

def __eq__(self, other): 

""" 

Check equality. 

 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example() 

sage: f = X.an_element() 

sage: f == X(2, 'f') 

True 

sage: e1 = X(1, 'e1') 

sage: e1 == f 

False 

""" 

return (isinstance(other, Surface.Element) 

and self.parent() is other.parent() 

and self._dim == other._dim 

and self._name == other._name) 

 

def dimension(self): 

""" 

Return the dimension of ``self``. 

 

EXAMPLES:: 

 

sage: from sage.categories.cw_complexes import CWComplexes 

sage: X = CWComplexes().example() 

sage: f = X.an_element() 

sage: f.dimension() 

2 

""" 

return self._dim 

 

Example = Surface