Path: blob/master/sage/homology/simplicial_complex_homset.py
4108 views
r"""1Homsets between simplicial complexes23EXAMPLES:45::67sage: S = simplicial_complexes.Sphere(1)8sage: T = simplicial_complexes.Sphere(2)9sage: H = Hom(S,T)10sage: f = {0:0,1:1,2:3}11sage: x = H(f)12sage: x13Simplicial 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)}14sage: x.is_injective()15True16sage: x.is_surjective()17False18sage: x.image()19Simplicial complex with vertex set (0, 1, 3) and facets {(1, 3), (0, 3), (0, 1)}20sage: from sage.homology.simplicial_complex import Simplex21sage: s = Simplex([1,2])22sage: x(s)23(1, 3)2425TESTS::2627sage: S = simplicial_complexes.Sphere(1)28sage: T = simplicial_complexes.Sphere(2)29sage: H = Hom(S,T)30sage: loads(dumps(H))==H31True3233"""3435#*****************************************************************************36# Copyright (C) 2009 D. Benjamin Antieau <[email protected]>37#38# Distributed under the terms of the GNU General Public License (GPL)39#40# This code is distributed in the hope that it will be useful,41# but WITHOUT ANY WARRANTY; without even the implied warranty42# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.43#44# See the GNU General Public License for more details; the full text45# is available at:46#47# http://www.gnu.org/licenses/48#49#*****************************************************************************5051import sage.categories.homset52import sage.homology.simplicial_complex_morphism as simplicial_complex_morphism5354def is_SimplicialComplexHomset(x):55"""56Return True if and only if x is a simplicial complex homspace.5758EXAMPLES::5960sage: H = Hom(SimplicialComplex(2),SimplicialComplex(3))61sage: H62Set 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 complexes63sage: from sage.homology.simplicial_complex_homset import is_SimplicialComplexHomset64sage: is_SimplicialComplexHomset(H)65True66"""67return isinstance(x, SimplicialComplexHomset)6869class SimplicialComplexHomset(sage.categories.homset.Homset):70def __call__(self, f):71"""72INPUT:73f -- a dictionary with keys exactly the vertices of the domain and values vertices of the codomain7475EXAMPLE::7677sage: S = simplicial_complexes.Sphere(3)78sage: T = simplicial_complexes.Sphere(2)79sage: f = {0:0,1:1,2:2,3:2,4:2}80sage: H = Hom(S,T)81sage: x = H(f)82sage: x83Simplicial 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)}848586"""87return simplicial_complex_morphism.SimplicialComplexMorphism(f,self.domain(),self.codomain())8889def diagonal_morphism(self,rename_vertices=True):90"""91Returns the diagonal morphism in Hom(S,SxS).9293EXAMPLES::9495sage: S = simplicial_complexes.Sphere(2)96sage: H = Hom(S,S.product(S))97sage: d = H.diagonal_morphism()98sage: d99Simplicial 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 facets100101sage: T = SimplicialComplex(3)102sage: U = T.product(T,rename_vertices = False)103sage: G = Hom(T,U)104sage: e = G.diagonal_morphism(rename_vertices = False)105sage: e106Simplicial 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 {()}107108"""109110if self._codomain == self._domain.product(self._domain,rename_vertices=rename_vertices):111X = self._domain.product(self._domain,rename_vertices=rename_vertices)112f = dict()113if rename_vertices:114for i in self._domain.vertices().set():115f[i] = "L"+str(i)+"R"+str(i)116else:117for i in self._domain.vertices().set():118f[i] = (i,i)119return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,X)120else:121raise TypeError, "Diagonal morphism is only defined for Hom(X,XxX)."122123def identity(self):124"""125Returns the identity morphism of Hom(S,S).126127EXAMPLES::128129sage: S = simplicial_complexes.Sphere(2)130sage: H = Hom(S,S)131sage: i = H.identity()132sage: i.is_identity()133True134135sage: T = SimplicialComplex(3,[[0,1]])136sage: G = Hom(T,T)137sage: G.identity()138Simplicial 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)}139140"""141if self.is_endomorphism_set():142f = dict()143for i in self._domain.vertices().set():144f[i]=i145return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,self._codomain)146else:147raise TypeError, "Identity map is only defined for endomorphism sets."148149def an_element(self):150"""151Returns a (non-random) element of self.152153EXAMPLES::154155sage: S = simplicial_complexes.KleinBottle()156sage: T = simplicial_complexes.Sphere(5)157sage: H = Hom(S,T)158sage: x = H.an_element()159sage: x160Simplicial 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 facets161162"""163X_vertices = self._domain.vertices().set()164try:165i = self._codomain.vertices().set().__iter__().next()166except StopIteration:167if len(X_vertices) == 0:168return dict()169else:170raise TypeError, "There are no morphisms from a non-empty simplicial complex to an empty simplicial comples."171f = dict()172for x in X_vertices:173f[x]=i174return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,self._codomain)175176177