Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/homology/simplicial_complex_homset.py
4108 views
1
r"""
2
Homsets between simplicial complexes
3
4
EXAMPLES:
5
6
::
7
8
sage: S = simplicial_complexes.Sphere(1)
9
sage: T = simplicial_complexes.Sphere(2)
10
sage: H = Hom(S,T)
11
sage: f = {0:0,1:1,2:3}
12
sage: x = H(f)
13
sage: x
14
Simplicial complex morphism {0: 0, 1: 1, 2: 3} from Simplicial complex with vertex set (0, 1, 2) and facets {(1, 2), (0, 2), (0, 1)} to Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)}
15
sage: x.is_injective()
16
True
17
sage: x.is_surjective()
18
False
19
sage: x.image()
20
Simplicial complex with vertex set (0, 1, 3) and facets {(1, 3), (0, 3), (0, 1)}
21
sage: from sage.homology.simplicial_complex import Simplex
22
sage: s = Simplex([1,2])
23
sage: x(s)
24
(1, 3)
25
26
TESTS::
27
28
sage: S = simplicial_complexes.Sphere(1)
29
sage: T = simplicial_complexes.Sphere(2)
30
sage: H = Hom(S,T)
31
sage: loads(dumps(H))==H
32
True
33
34
"""
35
36
#*****************************************************************************
37
# Copyright (C) 2009 D. Benjamin Antieau <[email protected]>
38
#
39
# Distributed under the terms of the GNU General Public License (GPL)
40
#
41
# This code is distributed in the hope that it will be useful,
42
# but WITHOUT ANY WARRANTY; without even the implied warranty
43
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
44
#
45
# See the GNU General Public License for more details; the full text
46
# is available at:
47
#
48
# http://www.gnu.org/licenses/
49
#
50
#*****************************************************************************
51
52
import sage.categories.homset
53
import sage.homology.simplicial_complex_morphism as simplicial_complex_morphism
54
55
def is_SimplicialComplexHomset(x):
56
"""
57
Return True if and only if x is a simplicial complex homspace.
58
59
EXAMPLES::
60
61
sage: H = Hom(SimplicialComplex(2),SimplicialComplex(3))
62
sage: H
63
Set of Morphisms from Simplicial complex with vertex set (0, 1, 2) and facets {()} to Simplicial complex with vertex set (0, 1, 2, 3) and facets {()} in Category of simplicial complexes
64
sage: from sage.homology.simplicial_complex_homset import is_SimplicialComplexHomset
65
sage: is_SimplicialComplexHomset(H)
66
True
67
"""
68
return isinstance(x, SimplicialComplexHomset)
69
70
class SimplicialComplexHomset(sage.categories.homset.Homset):
71
def __call__(self, f):
72
"""
73
INPUT:
74
f -- a dictionary with keys exactly the vertices of the domain and values vertices of the codomain
75
76
EXAMPLE::
77
78
sage: S = simplicial_complexes.Sphere(3)
79
sage: T = simplicial_complexes.Sphere(2)
80
sage: f = {0:0,1:1,2:2,3:2,4:2}
81
sage: H = Hom(S,T)
82
sage: x = H(f)
83
sage: x
84
Simplicial complex morphism {0: 0, 1: 1, 2: 2, 3: 2, 4: 2} from Simplicial complex with vertex set (0, 1, 2, 3, 4) and 5 facets to Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)}
85
86
87
"""
88
return simplicial_complex_morphism.SimplicialComplexMorphism(f,self.domain(),self.codomain())
89
90
def diagonal_morphism(self,rename_vertices=True):
91
"""
92
Returns the diagonal morphism in Hom(S,SxS).
93
94
EXAMPLES::
95
96
sage: S = simplicial_complexes.Sphere(2)
97
sage: H = Hom(S,S.product(S))
98
sage: d = H.diagonal_morphism()
99
sage: d
100
Simplicial complex morphism {0: 'L0R0', 1: 'L1R1', 2: 'L2R2', 3: 'L3R3'} from Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)} to Simplicial complex with 16 vertices and 96 facets
101
102
sage: T = SimplicialComplex(3)
103
sage: U = T.product(T,rename_vertices = False)
104
sage: G = Hom(T,U)
105
sage: e = G.diagonal_morphism(rename_vertices = False)
106
sage: e
107
Simplicial complex morphism {0: (0, 0), 1: (1, 1), 2: (2, 2), 3: (3, 3)} from Simplicial complex with vertex set (0, 1, 2, 3) and facets {()} to Simplicial complex with 16 vertices and facets {()}
108
109
"""
110
111
if self._codomain == self._domain.product(self._domain,rename_vertices=rename_vertices):
112
X = self._domain.product(self._domain,rename_vertices=rename_vertices)
113
f = dict()
114
if rename_vertices:
115
for i in self._domain.vertices().set():
116
f[i] = "L"+str(i)+"R"+str(i)
117
else:
118
for i in self._domain.vertices().set():
119
f[i] = (i,i)
120
return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,X)
121
else:
122
raise TypeError, "Diagonal morphism is only defined for Hom(X,XxX)."
123
124
def identity(self):
125
"""
126
Returns the identity morphism of Hom(S,S).
127
128
EXAMPLES::
129
130
sage: S = simplicial_complexes.Sphere(2)
131
sage: H = Hom(S,S)
132
sage: i = H.identity()
133
sage: i.is_identity()
134
True
135
136
sage: T = SimplicialComplex(3,[[0,1]])
137
sage: G = Hom(T,T)
138
sage: G.identity()
139
Simplicial complex morphism {0: 0, 1: 1, 2: 2, 3: 3} from Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1)} to Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1)}
140
141
"""
142
if self.is_endomorphism_set():
143
f = dict()
144
for i in self._domain.vertices().set():
145
f[i]=i
146
return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,self._codomain)
147
else:
148
raise TypeError, "Identity map is only defined for endomorphism sets."
149
150
def an_element(self):
151
"""
152
Returns a (non-random) element of self.
153
154
EXAMPLES::
155
156
sage: S = simplicial_complexes.KleinBottle()
157
sage: T = simplicial_complexes.Sphere(5)
158
sage: H = Hom(S,T)
159
sage: x = H.an_element()
160
sage: x
161
Simplicial complex morphism {0: 0, 1: 0, 2: 0, 'R3': 0, 'L4': 0, 'L5': 0, 'L3': 0, 'R5': 0, 'R4': 0} from Simplicial complex with 9 vertices and 18 facets to Simplicial complex with vertex set (0, 1, 2, 3, 4, 5, 6) and 7 facets
162
163
"""
164
X_vertices = self._domain.vertices().set()
165
try:
166
i = self._codomain.vertices().set().__iter__().next()
167
except StopIteration:
168
if len(X_vertices) == 0:
169
return dict()
170
else:
171
raise TypeError, "There are no morphisms from a non-empty simplicial complex to an empty simplicial comples."
172
f = dict()
173
for x in X_vertices:
174
f[x]=i
175
return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,self._codomain)
176
177