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