# Ticket #6099: trac_6099-part2.patch

File trac_6099-part2.patch, 19.3 KB (added by jhpalmieri, 9 years ago)

apply on top of 6099-merged.patch

• ## doc/en/reference/homology.rst

```# HG changeset patch
# User J. H. Palmieri <palmieri@math.washington.edu>
# Date 1257896204 28800
# Node ID 3fd8b455bb0dda45d8859f01af291fc1e3074ac0
# Parent  e5f49948e6673f928ed062b69389dc31cdb2082d
ref patch for #6099

diff -r e5f49948e667 -r 3fd8b455bb0d doc/en/reference/homology.rst```
 a sage/homology/simplicial_complex_homset sage/homology/chain_complex sage/homology/chain_complex_morphism sage/homology/chain_complex_homset sage/homology/chain_complex_homspace sage/homology/examples
• ## sage/categories/category_types.py

`diff -r e5f49948e667 -r 3fd8b455bb0d sage/categories/category_types.py`
 a GroupAlgebras          : [MonoidAlgebras, Algebras, Sets],\ MatrixAlgebras         : [Algebras, Sets],\ RingModules            : [AbelianGroups, Sets],\ ChainComplexes         : [],\ ChainComplexes         : [RingModules, AbelianGroups, Sets],\ FreeModules            : [RingModules, AbelianGroups, Sets],\ VectorSpaces           : [FreeModules, RingModules, AbelianGroups, Sets],\ HeckeModules           : [FreeModules, RingModules, AbelianGroups, Sets],\
• ## sage/homology/chain_complex.py

`diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/chain_complex.py`
 a EXAMPLES:: sage: ChainComplex() Chain complex with at most 0 nonzero terms over Integer Ring. Chain complex with at most 0 nonzero terms over Integer Ring sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) sage: C Chain complex with at most 2 nonzero terms over Integer Ring. Chain complex with at most 2 nonzero terms over Integer Ring sage: D = ChainComplex([matrix(ZZ, 2, 2, [0, 1, 0, 0]), matrix(ZZ, 2, 2, [0, 1, 0, 0])], base_ring=GF(2)); D Chain complex with at most 3 nonzero terms over Finite Field of size 2. Chain complex with at most 3 nonzero terms over Finite Field of size 2 sage: D == loads(dumps(D)) True Defining the base ring implicitly:: sage: ChainComplex([matrix(QQ, 3, 1), matrix(ZZ, 4, 3)]) Chain complex with at most 2 nonzero terms over Rational Field. Chain complex with at most 2 nonzero terms over Rational Field sage: ChainComplex([matrix(GF(125, 'a'), 3, 1), matrix(ZZ, 4, 3)]) Chain complex with at most 2 nonzero terms over Finite Field in a of size 5^3. Chain complex with at most 2 nonzero terms over Finite Field in a of size 5^3 If the matrices are defined over incompatible rings, an error results:: EXAMPLES:: sage: C = ChainComplex(); C Chain complex with at most 0 nonzero terms over Integer Ring. Chain complex with at most 0 nonzero terms over Integer Ring sage: D = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) sage: D Chain complex with at most 2 nonzero terms over Integer Ring. Chain complex with at most 2 nonzero terms over Integer Ring """ try: deg = grading_group(degree) sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])}) sage: C._repr_() 'Chain complex with at most 2 nonzero terms over Integer Ring.' 'Chain complex with at most 2 nonzero terms over Integer Ring' """ diffs = filter(lambda mat: mat.nrows() + mat.ncols() > 0, self._diff.values()) string1 = "Chain complex with at most" string2 = " %s nonzero terms over %s." % (len(diffs), string2 = " %s nonzero terms over %s" % (len(diffs), self._base_ring) return string1 + string2
• ## sage/homology/chain_complex_homspace.py

`diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/chain_complex_homspace.py`
 a sage: D = T.chain_complex(augmented=True,cochain=True) sage: G = Hom(C,D) sage: G Set of Morphisms from Chain complex with at most 4 nonzero terms over Integer Ring. to Chain complex with at most 4 nonzero terms over Integer Ring. in Category of chain complexes over Integer Ring Set of Morphisms from Chain complex with at most 4 nonzero terms over Integer Ring to Chain complex with at most 4 nonzero terms over Integer Ring in Category of chain complexes over Integer Ring sage: S = simplicial_complexes.ChessboardComplex(3,3) sage: H = Hom(S,S) sage: i = H.identity() sage: x = i.associated_chain_complex_morphism(augmented=True) sage: x Chain complex morphism from Chain complex with at most 4 nonzero terms over Integer Ring. to Chain complex with at most 4 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 4 nonzero terms over Integer Ring to Chain complex with at most 4 nonzero terms over Integer Ring sage: x._matrix_dictionary {0: [1 0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0 0] sage: i = A.identity() sage: x = i.associated_chain_complex_morphism() sage: x Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring. to Chain complex with at most 3 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring to Chain complex with at most 3 nonzero terms over Integer Ring sage: y = x*4 sage: z = y*y sage: (y+z) Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring. to Chain complex with at most 3 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring to Chain complex with at most 3 nonzero terms over Integer Ring sage: f = x._matrix_dictionary sage: C = S.chain_complex() sage: G = Hom(C,C) sage: C = T.chain_complex(augmented=True,cochain=True) sage: G = Hom(C,C) sage: G Set of Morphisms from Chain complex with at most 5 nonzero terms over Integer Ring. to Chain complex with at most 5 nonzero terms over Integer Ring. in Category of chain complexes over Integer Ring Set of Morphisms from Chain complex with at most 5 nonzero terms over Integer Ring to Chain complex with at most 5 nonzero terms over Integer Ring in Category of chain complexes over Integer Ring """ def __call__(self, f):
• ## sage/homology/chain_complex_morphism.py

`diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/chain_complex_morphism.py`
 a - Benjamin Antieau (2009.06) This module implements morphisms of simplicial complexes. The input is a dictionary whose This module implements morphisms of chain complexes. The input is a dictionary whose keys are in the grading group of the chain complex and whose values are matrix morphisms. EXAMPLES:: sage: G = Hom(C,C) sage: x = G(f) sage: x Chain complex morphism from Chain complex with at most 2 nonzero terms over Integer Ring. to Chain complex with at most 2 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 2 nonzero terms over Integer Ring to Chain complex with at most 2 nonzero terms over Integer Ring sage: x._matrix_dictionary {0: [0 0 0] [0 0 0] sage: i = H.identity() sage: x = i.associated_chain_complex_morphism() sage: x # indirect doctest Chain complex morphism from Chain complex with at most 7 nonzero terms over Integer Ring. to Chain complex with at most 7 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 7 nonzero terms over Integer Ring to Chain complex with at most 7 nonzero terms over Integer Ring sage: is_ChainComplexMorphism(x) True sage: G = Hom(C,C) sage: x = G(f) sage: x Chain complex morphism from Chain complex with at most 2 nonzero terms over Integer Ring. to Chain complex with at most 2 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 2 nonzero terms over Integer Ring to Chain complex with at most 2 nonzero terms over Integer Ring sage: x._matrix_dictionary {0: [0 0 0] [0 0 0] Returns self*x if self and x are composable morphisms or if x is an element of the base_ring. EXAMPLES:: sage: S = simplicial_complexes.Sphere(2) sage: H = Hom(S,S) sage: i = H.identity() raise TypeError, "Multiplication is not defined." f = dict() for i in self._matrix_dictionary.keys(): f[i] = y * self._matrix_dictionary[i] f[i] = self._matrix_dictionary[i] * y return ChainComplexMorphism(f,self._domain,self._codomain) f = dict() for i in self._matrix_dictionary.keys(): f[i] = x._matrix_dictionary[i]*self._matrix_dictionary[i] return ChainComplexMorphism(f,self._domain,x._codomain) def __rmul__(self,x): """ Returns x*self if x is an element of the base_ring. EXAMPLES:: sage: S = simplicial_complexes.Sphere(2) sage: H = Hom(S,S) sage: i = H.identity() sage: x = i.associated_chain_complex_morphism() sage: 2*x == x*2 True sage: 3*x == x*2 False """ try: y = self._domain.base_ring()(x) except TypeError: raise TypeError, "Multiplication is not defined." f = dict() for i in self._matrix_dictionary.keys(): f[i] = y * self._matrix_dictionary[i] return ChainComplexMorphism(f,self._domain,self._codomain) def __sub__(self,x): """ Returns self-x. sage: i = H.identity() sage: x = i.associated_chain_complex_morphism() sage: x Chain complex morphism from Chain complex with at most 0 nonzero terms over Integer Ring. to Chain complex with at most 0 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 0 nonzero terms over Integer Ring to Chain complex with at most 0 nonzero terms over Integer Ring sage: f = x._matrix_dictionary sage: C = S.chain_complex() sage: G = Hom(C,C) sage: i = H.identity() sage: x = i.associated_chain_complex_morphism() sage: x Chain complex morphism from Chain complex with at most 0 nonzero terms over Integer Ring. to Chain complex with at most 0 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 0 nonzero terms over Integer Ring to Chain complex with at most 0 nonzero terms over Integer Ring sage: x._repr_() 'Chain complex morphism from Chain complex with at most 0 nonzero terms over Integer Ring. to Chain complex with at most 0 nonzero terms over Integer Ring.' 'Chain complex morphism from Chain complex with at most 0 nonzero terms over Integer Ring to Chain complex with at most 0 nonzero terms over Integer Ring' """ return "Chain complex morphism from " + self._domain._repr_() + " to " + self._codomain._repr_()
• ## sage/homology/simplicial_complex.py

`diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/simplicial_complex.py`
 a sage: circle = SimplicialComplex(2, [[0,1], [1,2], [0, 2]]) sage: circle.chain_complex() Chain complex with at most 2 nonzero terms over Integer Ring. Chain complex with at most 2 nonzero terms over Integer Ring sage: circle.chain_complex()._latex_() '\\Bold{Z}^{3} \\xrightarrow{d_{1}} \\Bold{Z}^{3}' sage: circle.chain_complex(base_ring=QQ, augmented=True) Chain complex with at most 3 nonzero terms over Rational Field. Chain complex with at most 3 nonzero terms over Rational Field """ # initialize subcomplex if subcomplex is None: def generated_subcomplex(self,sub_vertex_set): """ Returns the largest sub SimplicialComplex of self containing exactly the sub_vertex_set as vertices. Returns the largest sub-simplicial complex of self containing exactly ``sub_vertex_set`` as vertices. EXAMPLES::
• ## sage/homology/simplicial_complex_morphism.py

`diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/simplicial_complex_morphism.py`
 a import sage.categories.category_types as category_types from sage.rings.integer_ring import ZZ from sage.homology.chain_complex_morphism import ChainComplexMorphism from sage.combinat.permutation import Permutation from sage.algebras.steenrod_algebra_element import convert_perm def is_SimplicialComplexMorphism(x): """ else: return True def __call__(self,x): def __call__(self,x,orientation=False): """ Input is a simplex of the domain. Output is the image simplex. If optional argument ``orientation`` is True, return a pair ``(image simplex, oriented)`` where ``oriented`` is 1 or `-1` depending on whether the map preserves or reverses the orientation of the image simplex. EXAMPLES:: sage: x(Simplex([0,2,3])) (0, 2, 3) An orientation-reversing example:: sage: X = SimplicialComplex(1, [[0,1]]) sage: g = Hom(X,X)({0:1, 1:0}) sage: g(Simplex([0,1])) (0, 1) sage: g(Simplex([0,1]), orientation=True) ((0, 1), -1) """ dim = self._domain.dimension() if not isinstance(x,simplicial_complex.Simplex) or x.dimension() > dim or not x in self._domain.faces()[x.dimension()]: fx=[] for j in tup: fx.append(self._vertex_dictionary[j]) return simplicial_complex.Simplex(set(fx)) if orientation: if len(set(fx)) == len(tup): oriented = Permutation(convert_perm(fx)).signature() else: oriented = 1 return (simplicial_complex.Simplex(set(fx)), oriented) else: return simplicial_complex.Simplex(set(fx)) def _repr_(self): """ Simplicial complex morphism {0: 0, 1: 1, 2: 2} 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)} sage: a = x.associated_chain_complex_morphism() sage: a Chain complex morphism from Chain complex with at most 2 nonzero terms over Integer Ring. to Chain complex with at most 3 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 2 nonzero terms over Integer Ring to Chain complex with at most 3 nonzero terms over Integer Ring sage: a._matrix_dictionary {0: [0 0 0] [0 1 0] [0 0 1], 2: []} sage: x.associated_chain_complex_morphism(augmented=True) Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring. to Chain complex with at most 4 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring to Chain complex with at most 4 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(cochain=True) Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring. to Chain complex with at most 2 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 3 nonzero terms over Integer Ring to Chain complex with at most 2 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(augmented=True,cochain=True) Chain complex morphism from Chain complex with at most 4 nonzero terms over Integer Ring. to Chain complex with at most 3 nonzero terms over Integer Ring. Chain complex morphism from Chain complex with at most 4 nonzero terms over Integer Ring to Chain complex with at most 3 nonzero terms over Integer Ring sage: x.associated_chain_complex_morphism(base_ring=GF(11)) Chain complex morphism from Chain complex with at most 2 nonzero terms over Finite Field of size 11. to Chain complex with at most 3 nonzero terms over Finite Field of size 11. Chain complex morphism from Chain complex with at most 2 nonzero terms over Finite Field of size 11 to Chain complex with at most 3 nonzero terms over Finite Field of size 11 Some simplicial maps which reverse the orientation of a few simplices:: sage: g = {0:1, 1:2, 2:0} sage: H(g).associated_chain_complex_morphism()._matrix_dictionary {0: [0 0 0] [1 0 0] [0 1 0] [0 0 1], 1: [ 0  0  0] [-1  0  0] [ 0  0  0] [ 0  0  1] [ 0  0  0] [ 0 -1  0], 2: []} sage: X = SimplicialComplex(1, [[0, 1]]) sage: Hom(X,X)({0:1, 1:0}).associated_chain_complex_morphism()._matrix_dictionary {0: [0 1] [1 0], 1: [-1]} """ max_dim = max(self._domain.dimension(),self._codomain.dimension()) min_dim = min(self._domain.dimension(),self._codomain.dimension()) num_faces_Y = len(Y_faces) mval = [0 for i in range(num_faces_X*num_faces_Y)] for i in X_faces: y = self(i) y, oriented = self(i, orientation=True) if y.dimension() < dim: pass else: mval[X_faces.index(i)+(Y_faces.index(y)*num_faces_X)] = 1 mval[X_faces.index(i)+(Y_faces.index(y)*num_faces_X)] = oriented m = matrix.Matrix(base_ring,num_faces_Y,num_faces_X,mval,sparse=True) if not cochain: matrices[dim] = m