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 b  
    1212   sage/homology/simplicial_complex_homset
    1313   sage/homology/chain_complex
    1414   sage/homology/chain_complex_morphism
    15    sage/homology/chain_complex_homset
     15   sage/homology/chain_complex_homspace
    1616   sage/homology/examples
  • sage/categories/category_types.py

    diff -r e5f49948e667 -r 3fd8b455bb0d sage/categories/category_types.py
    a b  
    13111311    GroupAlgebras          : [MonoidAlgebras, Algebras, Sets],\
    13121312    MatrixAlgebras         : [Algebras, Sets],\
    13131313    RingModules            : [AbelianGroups, Sets],\
    1314     ChainComplexes         : [],\
     1314    ChainComplexes         : [RingModules, AbelianGroups, Sets],\
    13151315    FreeModules            : [RingModules, AbelianGroups, Sets],\
    13161316    VectorSpaces           : [FreeModules, RingModules, AbelianGroups, Sets],\
    13171317    HeckeModules           : [FreeModules, RingModules, AbelianGroups, Sets],\
  • sage/homology/chain_complex.py

    diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/chain_complex.py
    a b  
    338338    EXAMPLES::
    339339
    340340        sage: ChainComplex()
    341         Chain complex with at most 0 nonzero terms over Integer Ring.
     341        Chain complex with at most 0 nonzero terms over Integer Ring
    342342        sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])})
    343343        sage: C
    344         Chain complex with at most 2 nonzero terms over Integer Ring.
     344        Chain complex with at most 2 nonzero terms over Integer Ring
    345345        sage: D = ChainComplex([matrix(ZZ, 2, 2, [0, 1, 0, 0]), matrix(ZZ, 2, 2, [0, 1, 0, 0])], base_ring=GF(2)); D
    346         Chain complex with at most 3 nonzero terms over Finite Field of size 2.
     346        Chain complex with at most 3 nonzero terms over Finite Field of size 2
    347347        sage: D == loads(dumps(D))
    348348        True
    349349
     
    361361    Defining the base ring implicitly::
    362362
    363363        sage: ChainComplex([matrix(QQ, 3, 1), matrix(ZZ, 4, 3)])
    364         Chain complex with at most 2 nonzero terms over Rational Field.
     364        Chain complex with at most 2 nonzero terms over Rational Field
    365365        sage: ChainComplex([matrix(GF(125, 'a'), 3, 1), matrix(ZZ, 4, 3)])
    366         Chain complex with at most 2 nonzero terms over Finite Field in a of size 5^3.
     366        Chain complex with at most 2 nonzero terms over Finite Field in a of size 5^3
    367367
    368368    If the matrices are defined over incompatible rings, an error results::
    369369
     
    389389        EXAMPLES::
    390390
    391391            sage: C = ChainComplex(); C
    392             Chain complex with at most 0 nonzero terms over Integer Ring.
     392            Chain complex with at most 0 nonzero terms over Integer Ring
    393393            sage: D = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])})
    394394            sage: D
    395             Chain complex with at most 2 nonzero terms over Integer Ring.
     395            Chain complex with at most 2 nonzero terms over Integer Ring
    396396        """
    397397        try:
    398398            deg = grading_group(degree)
     
    882882
    883883            sage: C = ChainComplex({0: matrix(ZZ, 2, 3, [3, 0, 0, 0, 0, 0])})
    884884            sage: C._repr_()
    885             'Chain complex with at most 2 nonzero terms over Integer Ring.'
     885            'Chain complex with at most 2 nonzero terms over Integer Ring'
    886886        """
    887887        diffs = filter(lambda mat: mat.nrows() + mat.ncols() > 0,
    888888                       self._diff.values())
    889889        string1 = "Chain complex with at most"
    890         string2 = " %s nonzero terms over %s." % (len(diffs),
     890        string2 = " %s nonzero terms over %s" % (len(diffs),
    891891                                                  self._base_ring)
    892892        return string1 + string2
    893893
  • sage/homology/chain_complex_homspace.py

    diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/chain_complex_homspace.py
    a b  
    1616    sage: D = T.chain_complex(augmented=True,cochain=True)
    1717    sage: G = Hom(C,D)
    1818    sage: G
    19     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
     19    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
    2020
    2121    sage: S = simplicial_complexes.ChessboardComplex(3,3)
    2222    sage: H = Hom(S,S)
    2323    sage: i = H.identity()
    2424    sage: x = i.associated_chain_complex_morphism(augmented=True)
    2525    sage: x
    26     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.
     26    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
    2727    sage: x._matrix_dictionary
    2828    {0: [1 0 0 0 0 0 0 0 0]
    2929    [0 1 0 0 0 0 0 0 0]
     
    6262    sage: i = A.identity()
    6363    sage: x = i.associated_chain_complex_morphism()
    6464    sage: x
    65     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.
     65    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
    6666    sage: y = x*4
    6767    sage: z = y*y
    6868    sage: (y+z)
    69     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.
     69    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
    7070    sage: f = x._matrix_dictionary
    7171    sage: C = S.chain_complex()
    7272    sage: G = Hom(C,C)
     
    122122        sage: C = T.chain_complex(augmented=True,cochain=True)
    123123        sage: G = Hom(C,C)
    124124        sage: G
    125         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
     125        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
    126126
    127127    """
    128128    def __call__(self, f):
  • sage/homology/chain_complex_morphism.py

    diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/chain_complex_morphism.py
    a b  
    55
    66- Benjamin Antieau <d.ben.antieau@gmail.com> (2009.06)
    77
    8 This module implements morphisms of simplicial complexes. The input is a dictionary whose
     8This module implements morphisms of chain complexes. The input is a dictionary whose
    99keys are in the grading group of the chain complex and whose values are matrix morphisms.
    1010
    1111EXAMPLES::
     
    2323    sage: G = Hom(C,C)
    2424    sage: x = G(f)
    2525    sage: x
    26     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.
     26    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
    2727    sage: x._matrix_dictionary
    2828    {0: [0 0 0]
    2929    [0 0 0]
     
    6969        sage: i = H.identity()
    7070        sage: x = i.associated_chain_complex_morphism()
    7171        sage: x # indirect doctest
    72         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.
     72        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
    7373        sage: is_ChainComplexMorphism(x)
    7474        True
    7575
     
    9999            sage: G = Hom(C,C)
    100100            sage: x = G(f)
    101101            sage: x
    102             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.
     102            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
    103103            sage: x._matrix_dictionary
    104104            {0: [0 0 0]
    105105            [0 0 0]
     
    225225        Returns self*x if self and x are composable morphisms or if x is an element of the base_ring.
    226226
    227227        EXAMPLES::
     228
    228229            sage: S = simplicial_complexes.Sphere(2)
    229230            sage: H = Hom(S,S)
    230231            sage: i = H.identity()
     
    270271                raise TypeError, "Multiplication is not defined."
    271272            f = dict()
    272273            for i in self._matrix_dictionary.keys():
    273                 f[i] = y * self._matrix_dictionary[i]
     274                f[i] = self._matrix_dictionary[i] * y
    274275            return ChainComplexMorphism(f,self._domain,self._codomain)
    275276        f = dict()
    276277        for i in self._matrix_dictionary.keys():
    277278            f[i] = x._matrix_dictionary[i]*self._matrix_dictionary[i]
    278279        return ChainComplexMorphism(f,self._domain,x._codomain)
    279280
     281    def __rmul__(self,x):
     282        """
     283        Returns x*self if x is an element of the base_ring.
     284
     285        EXAMPLES::
     286
     287            sage: S = simplicial_complexes.Sphere(2)
     288            sage: H = Hom(S,S)
     289            sage: i = H.identity()
     290            sage: x = i.associated_chain_complex_morphism()
     291            sage: 2*x == x*2
     292            True
     293            sage: 3*x == x*2
     294            False
     295        """
     296        try:
     297            y = self._domain.base_ring()(x)
     298        except TypeError:
     299            raise TypeError, "Multiplication is not defined."
     300        f = dict()
     301        for i in self._matrix_dictionary.keys():
     302            f[i] = y * self._matrix_dictionary[i]
     303        return ChainComplexMorphism(f,self._domain,self._codomain)
     304
    280305    def __sub__(self,x):
    281306        """
    282307        Returns self-x.
     
    318343            sage: i = H.identity()
    319344            sage: x = i.associated_chain_complex_morphism()
    320345            sage: x
    321             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.
     346            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
    322347            sage: f = x._matrix_dictionary
    323348            sage: C = S.chain_complex()
    324349            sage: G = Hom(C,C)
     
    343368            sage: i = H.identity()
    344369            sage: x = i.associated_chain_complex_morphism()
    345370            sage: x
    346             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.
     371            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
    347372            sage: x._repr_()
    348             '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.'
     373            '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'
    349374
    350375        """
    351376        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 b  
    11791179
    11801180            sage: circle = SimplicialComplex(2, [[0,1], [1,2], [0, 2]])
    11811181            sage: circle.chain_complex()
    1182             Chain complex with at most 2 nonzero terms over Integer Ring.
     1182            Chain complex with at most 2 nonzero terms over Integer Ring
    11831183            sage: circle.chain_complex()._latex_()
    11841184            '\\Bold{Z}^{3} \\xrightarrow{d_{1}} \\Bold{Z}^{3}'
    11851185            sage: circle.chain_complex(base_ring=QQ, augmented=True)
    1186             Chain complex with at most 3 nonzero terms over Rational Field.
     1186            Chain complex with at most 3 nonzero terms over Rational Field
    11871187        """
    11881188        # initialize subcomplex
    11891189        if subcomplex is None:
     
    17501750
    17511751    def generated_subcomplex(self,sub_vertex_set):
    17521752        """
    1753         Returns the largest sub SimplicialComplex of self containing exactly the sub_vertex_set as vertices.
     1753        Returns the largest sub-simplicial complex of self containing
     1754        exactly ``sub_vertex_set`` as vertices.
    17541755
    17551756        EXAMPLES::
    17561757
  • sage/homology/simplicial_complex_morphism.py

    diff -r e5f49948e667 -r 3fd8b455bb0d sage/homology/simplicial_complex_morphism.py
    a b  
    9494import sage.categories.category_types as category_types
    9595from sage.rings.integer_ring import ZZ
    9696from sage.homology.chain_complex_morphism import ChainComplexMorphism
     97from sage.combinat.permutation import Permutation
     98from sage.algebras.steenrod_algebra_element import convert_perm
    9799
    98100def is_SimplicialComplexMorphism(x):
    99101    """
     
    193195        else:
    194196            return True
    195197
    196     def __call__(self,x):
     198    def __call__(self,x,orientation=False):
    197199        """
    198200        Input is a simplex of the domain. Output is the image simplex.
     201        If optional argument ``orientation`` is True, return a pair
     202        ``(image simplex, oriented)`` where ``oriented`` is 1 or `-1`
     203        depending on whether the map preserves or reverses the
     204        orientation of the image simplex.
    199205       
    200206        EXAMPLES::
    201207
     
    212218            sage: x(Simplex([0,2,3]))
    213219            (0, 2, 3)
    214220
     221        An orientation-reversing example::
     222
     223            sage: X = SimplicialComplex(1, [[0,1]])
     224            sage: g = Hom(X,X)({0:1, 1:0})
     225            sage: g(Simplex([0,1]))
     226            (0, 1)
     227            sage: g(Simplex([0,1]), orientation=True)
     228            ((0, 1), -1)
    215229        """
    216230        dim = self._domain.dimension()
    217231        if not isinstance(x,simplicial_complex.Simplex) or x.dimension() > dim or not x in self._domain.faces()[x.dimension()]:
     
    220234        fx=[]
    221235        for j in tup:
    222236            fx.append(self._vertex_dictionary[j])
    223         return simplicial_complex.Simplex(set(fx))
     237        if orientation:
     238            if len(set(fx)) == len(tup):
     239                oriented = Permutation(convert_perm(fx)).signature()
     240            else:
     241                oriented = 1
     242            return (simplicial_complex.Simplex(set(fx)), oriented)
     243        else:
     244            return simplicial_complex.Simplex(set(fx))
    224245
    225246    def _repr_(self):
    226247        """
     
    255276            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)}
    256277            sage: a = x.associated_chain_complex_morphism()
    257278            sage: a
    258             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.
     279            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
    259280            sage: a._matrix_dictionary
    260281            {0: [0 0 0]
    261282            [0 1 0]
     
    269290            [0 0 1],
    270291             2: []}
    271292            sage: x.associated_chain_complex_morphism(augmented=True)
    272             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.
     293            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
    273294            sage: x.associated_chain_complex_morphism(cochain=True)
    274             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.
     295            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
    275296            sage: x.associated_chain_complex_morphism(augmented=True,cochain=True)
    276             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.
     297            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
    277298            sage: x.associated_chain_complex_morphism(base_ring=GF(11))
    278             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.
     299            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
    279300
     301        Some simplicial maps which reverse the orientation of a few simplices::
     302
     303            sage: g = {0:1, 1:2, 2:0}
     304            sage: H(g).associated_chain_complex_morphism()._matrix_dictionary
     305            {0: [0 0 0]
     306             [1 0 0]
     307             [0 1 0]
     308             [0 0 1], 1: [ 0  0  0]
     309             [-1  0  0]
     310             [ 0  0  0]
     311             [ 0  0  1]
     312             [ 0  0  0]
     313             [ 0 -1  0], 2: []}
     314
     315            sage: X = SimplicialComplex(1, [[0, 1]])
     316            sage: Hom(X,X)({0:1, 1:0}).associated_chain_complex_morphism()._matrix_dictionary
     317            {0: [0 1]
     318             [1 0], 1: [-1]}
    280319        """
    281320        max_dim = max(self._domain.dimension(),self._codomain.dimension())
    282321        min_dim = min(self._domain.dimension(),self._codomain.dimension())
     
    294333            num_faces_Y = len(Y_faces)
    295334            mval = [0 for i in range(num_faces_X*num_faces_Y)]
    296335            for i in X_faces:
    297                 y = self(i)
     336                y, oriented = self(i, orientation=True)
    298337                if y.dimension() < dim:
    299338                    pass
    300339                else:
    301                     mval[X_faces.index(i)+(Y_faces.index(y)*num_faces_X)] = 1
     340                    mval[X_faces.index(i)+(Y_faces.index(y)*num_faces_X)] = oriented
    302341            m = matrix.Matrix(base_ring,num_faces_Y,num_faces_X,mval,sparse=True)
    303342            if not cochain:
    304343                matrices[dim] = m