Ticket #12587: trac_12587-simplicial_complex_hash-ts.patch

File trac_12587-simplicial_complex_hash-ts.patch, 163.8 KB (added by tscrim, 9 years ago)
  • sage/combinat/posets/posets.py

    # HG changeset patch
    # User Travis Scrimshaw <tscrim@ucdavis.edu>
    # Date 1352773572 28800
    # Node ID 1746d8f3f09b29a9f84ef4d699c4a3efaf2dbc6f
    # Parent ed4766d73d2331becd99980f6557a5af90ce090c
    Trac #12587 - Fixed __hash__() for SimplicialComplex by giving immutable option
    
    diff --git a/sage/combinat/posets/posets.py b/sage/combinat/posets/posets.py
    a b class FinitePoset(UniqueRepresentation,  
    27792779        from sage.homology.simplicial_complex import SimplicialComplex
    27802780        L = self.list()
    27812781        if on_ints:
    2782             vertices = range(len(L))
    2783             iso = dict( [ (L[i],i) for i in vertices ] )
    2784         else:
    2785             vertices = self._elements
     2782            iso = dict( [ (L[i],i) for i in range(len(L)) ] )
    27862783
    27872784        facets = []
    27882785        for f in self.maximal_chains():
    class FinitePoset(UniqueRepresentation,  
    27952792            else:
    27962793                facets.append([a.element for a in f])
    27972794
    2798         return SimplicialComplex(vertices, facets)
     2795        return SimplicialComplex(facets)
    27992796
    28002797    def promotion(self, i=1):
    28012798        r"""
  • sage/geometry/polyhedron/base.py

    diff --git a/sage/geometry/polyhedron/base.py b/sage/geometry/polyhedron/base.py
    a b class Polyhedron_base(SageObject): 
    19321932            This method is deprecated. Use triangulate() instead.
    19331933            See http://trac.sagemath.org/11634 for details.
    19341934            sage: sc
    1935             Simplicial complex with 13 vertices and 20 facets
     1935            Simplicial complex with 12 vertices and 20 facets
    19361936        """
    19371937        from sage.misc.superseded import deprecation
    19381938        deprecation(11634, 'This method is deprecated. Use triangulate().simplicial_complex() instead.')
    19391939        from sage.homology.simplicial_complex import SimplicialComplex
    1940         return SimplicialComplex(vertex_set = self.n_vertices(),
    1941                                  maximal_faces = [x[1] for x in self.triangulated_facial_incidences()])
     1940        return SimplicialComplex([x[1] for x in self.triangulated_facial_incidences()])
    19421941
    19431942    def __add__(self, other):
    19441943        """
  • sage/geometry/triangulation/element.py

    diff --git a/sage/geometry/triangulation/element.py b/sage/geometry/triangulation/element.py
    a b class Triangulation(Element): 
    601601            {0: 0, 1: 0, 2: 0, 3: 0}
    602602        """
    603603        from sage.homology.simplicial_complex import SimplicialComplex
    604         from sage.misc.all import flatten
    605         vertex_set = set(flatten(self))
    606         return SimplicialComplex(vertex_set = vertex_set,
    607                                  maximal_faces = self)
     604        return SimplicialComplex(self)
    608605
    609606
    610607    @cached_method
  • sage/graphs/graph.py

    diff --git a/sage/graphs/graph.py b/sage/graphs/graph.py
    a b class Graph(GenericGraph): 
    46644664        if self.is_directed() or self.has_loops() or self.has_multiple_edges():
    46654665            raise ValueError("Self must be an undirected simple graph to have a clique complex.")
    46664666        import sage.homology.simplicial_complex
    4667         C = sage.homology.simplicial_complex.SimplicialComplex(self.vertices(),self.cliques_maximal(),maximality_check=True)
     4667        C = sage.homology.simplicial_complex.SimplicialComplex(self.cliques_maximal(), maximality_check=True)
    46684668        C._graph = self
    46694669        return C
    46704670
  • sage/homology/cell_complex.py

    diff --git a/sage/homology/cell_complex.py b/sage/homology/cell_complex.py
    a b is meant as a base class from which othe 
    1313such, most of its properties are not implemented.  It is meant for use
    1414by developers producing new classes, not casual users.
    1515
    16 .. note::
     16.. NOTE::
    1717
    18     Keywords for :meth:`GenericCellComplex.chain_complex`,
    19     :meth:`GenericCellComplex.homology`, etc.: any keywords given to
     18    Keywords for :meth:`~GenericCellComplex.chain_complex`,
     19    :meth:`~GenericCellComplex.homology`, etc.: any keywords given to
    2020    the :meth:`~GenericCellComplex.homology` method get passed on to
    2121    the :meth:`~GenericCellComplex.chain_complex` method and also to
    2222    the constructor for chain complexes in
    class GenericCellComplex(SageObject): 
    8989        """
    9090        The cells of this cell complex, in the form of a dictionary:
    9191        the keys are integers, representing dimension, and the value
    92         associated to an integer d is the set of d-cells.  If the
     92        associated to an integer `d` is the set of `d`-cells.  If the
    9393        optional argument ``subcomplex`` is present, then return only
    9494        the faces which are *not* in the subcomplex.
    9595
    class GenericCellComplex(SageObject): 
    120120        The dimension of this cell complex: the maximum
    121121        dimension of its cells.
    122122
    123         .. warning::
     123        .. WARNING::
    124124
    125125          If the :meth:`cells` method calls :meth:`dimension`,
    126126          then you'll get an infinite loop.  So either don't use
    class GenericCellComplex(SageObject): 
    143143
    144144    def n_cells(self, n, subcomplex=None):
    145145        """
    146         List of cells of dimension n of this cell complex.
     146        List of cells of dimension ``n`` of this cell complex.
    147147        If the optional argument ``subcomplex`` is present, then
    148148        return the ``n``-dimensional faces which are *not* in the
    149149        subcomplex.
    class GenericCellComplex(SageObject): 
    152152        :type n: non-negative integer
    153153        :param subcomplex: a subcomplex of this cell complex. Return
    154154           the cells which are not in this subcomplex.
    155         :type subcomplex: optional, default None
     155        :type subcomplex: optional, default ``None``
    156156
    157157        EXAMPLES::
    158158
    class GenericCellComplex(SageObject): 
    592592        except that :meth:`homology` accepts a ``cohomology`` key
    593593        word, while this function does not: ``cohomology`` is
    594594        automatically true here.  Indeed, this function just calls
    595         :meth:`homology` with ``cohomology`` set to True.
     595        :meth:`homology` with ``cohomology`` set to ``True``.
    596596
    597597        :param dim:
    598598        :param base_ring:
    class GenericCellComplex(SageObject): 
    602602
    603603        EXAMPLES::
    604604
    605             sage: circle = SimplicialComplex(2, [[0,1], [1,2], [0, 2]])
     605            sage: circle = SimplicialComplex([[0,1], [1,2], [0, 2]])
    606606            sage: circle.cohomology(0)
    607607            0
    608608            sage: circle.cohomology(1)
    609609            Z
    610             sage: P2 = SimplicialComplex(5, [[0,1,2], [0,2,3], [0,1,5], [0,4,5], [0,3,4], [1,2,4], [1,3,4], [1,3,5], [2,3,5], [2,4,5]])   # projective plane
     610            sage: P2 = SimplicialComplex([[0,1,2], [0,2,3], [0,1,5], [0,4,5], [0,3,4], [1,2,4], [1,3,4], [1,3,5], [2,3,5], [2,4,5]])   # projective plane
    611611            sage: P2.cohomology(2)
    612612            C2
    613613            sage: P2.cohomology(2, base_ring=GF(2))
    class GenericCellComplex(SageObject): 
    620620
    621621        Relative cohomology::
    622622
    623             sage: T = SimplicialComplex(1, [[0,1]])
    624             sage: U = SimplicialComplex(1, [[0], [1]])
     623            sage: T = SimplicialComplex([[0,1]])
     624            sage: U = SimplicialComplex([[0], [1]])
    625625            sage: T.cohomology(1, subcomplex=U)
    626626            Z
    627627
    class GenericCellComplex(SageObject): 
    639639        (or a single Betti number, if only one dimension is given):
    640640        the ith Betti number is the rank of the ith homology group.
    641641
    642         :param dim: If None, then return every Betti number, as
     642        :param dim: If ``None``, then return every Betti number, as
    643643           a dictionary with keys the non-negative integers.  If
    644644           ``dim`` is an integer or list, return the Betti number for
    645645           each given dimension.  (Actually, if ``dim`` is a list,
    646646           return the Betti numbers, as a dictionary, in the range
    647647           from ``min(dim)`` to ``max(dim)``.  If ``dim`` is a number,
    648648           return the Betti number in that dimension.)
    649         :type dim: integer or list of integers or None; optional,
    650            default None
     649        :type dim: integer or list of integers or ``None``; optional,
     650           default ``None``
    651651        :param subcomplex: a subcomplex of this cell complex.  Compute
    652            the Betti numbers of the homology relative to this
    653            subcomplex.
    654         :type subcomplex: optional, default None
     652           the Betti numbers of the homology relative to this subcomplex.
     653        :type subcomplex: optional, default ``None``
    655654
    656         EXAMPLES: Build the two-sphere as a three-fold join of a
     655        EXAMPLES:
     656
     657        Build the two-sphere as a three-fold join of a
    657658        two-point space with itself::
    658659       
    659             sage: S = SimplicialComplex(1, [[0], [1]])
     660            sage: S = SimplicialComplex([[0], [1]])
    660661            sage: (S*S*S).betti()
    661662            {0: 1, 1: 0, 2: 1}
    662663            sage: (S*S*S).betti([1,2])
    class GenericCellComplex(SageObject): 
    704705
    705706        EXAMPLES::
    706707
    707             sage: P = SimplicialComplex(3, [[0, 1], [1,2], [2,3]]).face_poset(); P
     708            sage: P = SimplicialComplex([[0, 1], [1,2], [2,3]]).face_poset(); P
    708709            Finite poset containing 7 elements
    709710            sage: P.list()
    710711            [(3,), (2,), (2, 3), (1,), (0,), (0, 1), (1, 2)]
  • sage/homology/chain_complex.py

    diff --git a/sage/homology/chain_complex.py b/sage/homology/chain_complex.py
    a b from sage.rings.all import GF, prime_ran 
    4848def dhsw_snf(mat, verbose=False):
    4949    """
    5050    Preprocess a matrix using the "Elimination algorithm" described by
    51     Dumas et al., and then call ``elementary_divisors`` on the
     51    Dumas et al. [DHSW]_, and then call ``elementary_divisors`` on the
    5252    resulting (smaller) matrix.
    5353
    54     'dhsw' stands for 'Dumas, Heckenbach, Saunders, Welker,' and 'snf'
    55     stands for 'Smith Normal Form.'
     54    .. NOTE::
     55
     56        'snf' stands for 'Smith Normal Form.'
    5657
    5758    INPUT:
    5859
    59     -  ``mat`` - an integer matrix, either sparse or dense.
     60    -  ``mat`` -- an integer matrix, either sparse or dense.
    6061
    6162    (They use the transpose of the matrix considered here, so they use
    6263    rows instead of columns.)
    def dhsw_snf(mat, verbose=False): 
    6465    Algorithm: go through ``mat`` one column at a time.  For each
    6566    column, add multiples of previous columns to it until either
    6667
    67       - it's zero, in which case it should be deleted.
    68 
    69       - its first nonzero entry is 1 or -1, in which case it should be kept.
    70 
    71       - its first nonzero entry is something else, in which case it is
    72         deferred until the second pass.
     68    - it's zero, in which case it should be deleted.
     69    - its first nonzero entry is 1 or -1, in which case it should be kept.
     70    - its first nonzero entry is something else, in which case it is
     71      deferred until the second pass.
    7372
    7473    Then do a second pass on the deferred columns.
    7574
    def dhsw_snf(mat, verbose=False): 
    9493
    9594    REFERENCES:
    9695
    97     - Dumas, Heckenbach, Saunders, Welker, "Computing simplicial
    98       homology based on efficient Smith normal form algorithms," in
    99       "Algebra, geometry, and software systems" (2003), 177-206.
     96    .. [DHSW] Dumas, Heckenbach, Saunders, Welker, "Computing simplicial
     97        homology based on efficient Smith normal form algorithms," in
     98        "Algebra, geometry, and software systems" (2003), 177-206.
    10099    """
    101100    ring = mat.base_ring()
    102101    rows = mat.nrows()
    def _latex_module(R, m): 
    239238
    240239    INPUT:
    241240
    242     - ``R`` - a commutative ring
    243     - ``m`` - non-negative integer
     241    - ``R`` -- a commutative ring
     242    - ``m`` -- non-negative integer
    244243
    245244    This is used by the ``_latex_`` method for chain complexes.
    246245
    def _latex_module(R, m): 
    260259        return str(latex(FreeModule(R, m)))
    261260
    262261class ChainComplex(SageObject):
    263     """
     262    r"""
    264263    Define a chain complex.
    265264   
    266265    INPUT:
    267266
    268     -  ``data`` - the data defining the chain complex; see below for
     267    -  ``data`` -- the data defining the chain complex; see below for
    269268       more details.
    270269
    271     -  ``base_ring`` - a commutative ring (optional), the ring over
     270    -  ``base_ring`` -- a commutative ring (optional), the ring over
    272271       which the chain complex is defined. If this is not specified,
    273272       it is determined by the data defining the chain complex.
    274273
    275     -  ``grading_group`` - a free abelian group (optional, default
    276        ZZ), the group over which the chain complex is indexed.
     274    -  ``grading_group`` -- a free abelian group (optional, default
     275       ``ZZ``), the group over which the chain complex is indexed.
    277276
    278     -  ``degree`` - element of grading_group (optional, default 1),
     277    -  ``degree`` -- element of grading_group (optional, default 1),
    279278       the degree of the differential.
    280279
    281     -  ``check_products`` - boolean (optional, default True).  If True,
    282        check that each consecutive pair of differentials are
     280    -  ``check_products`` -- boolean (optional, default ``True``). If
     281       ``True``, check that each consecutive pair of differentials are
    283282       composable and have composite equal to zero.
    284283
    285284    OUTPUT: a chain complex
    286285
    287     .. warning::
     286    .. WARNING::
    288287
    289288       Right now, homology calculations will only work if the base
    290        ring is either ZZ or a field, so please take this into account
     289       ring is either `\ZZ` or a field, so please take this into account
    291290       when defining a chain complex.
    292291
    293292    Use data to define the chain complex.  This may be in any of the
    294293    following forms.
    295294
    296295    1. a dictionary with integers (or more generally, elements of
    297        grading_group) for keys, and with data[n] a matrix representing
     296       grading_group) for keys, and with ``data[n]`` a matrix representing
    298297       (via left multiplication) the differential coming from degree
    299298       `n`.  (Note that the shape of the matrix then determines the
    300299       rank of the free modules `C_n` and `C_{n+d}`.)
    class ChainComplex(SageObject): 
    302301    2. a list or tuple of the form `[C_0, d_0, C_1, d_1, C_2, d_2,
    303302       ...]`, where each `C_i` is a free module and each `d_i` is a
    304303       matrix, as above.  This only makes sense if ``grading_group``
    305        is `\\ZZ` and ``degree`` is 1.
     304       is `\ZZ` and ``degree`` is 1.
    306305
    307306    3. a list or tuple of the form `[r_0, d_0, r_1, d_1, r_2, d_2,
    308307       ...]`, where `r_i` is the rank of the free module `C_i` and
    309308       each `d_i` is a matrix, as above.  This only makes sense if
    310        ``grading_group`` is `\\ZZ` and ``degree`` is 1.
     309       ``grading_group`` is `\ZZ` and ``degree`` is 1.
    311310             
    312311    4. a list or tuple of the form `[d_0, d_1, d_2, ...]` where each
    313312       `d_i` is a matrix, as above.  This only makes sense if
    314        ``grading_group`` is `\\ZZ` and ``degree`` is 1.
     313       ``grading_group`` is `\ZZ` and ``degree`` is 1.
    315314
    316     .. note::
     315    .. NOTE::
    317316
    318317       In fact, the free modules `C_i` in case 2 and the ranks `r_i`
    319318       in case 3 are ignored: only the matrices are kept, and from
    class ChainComplex(SageObject): 
    386385
    387386    def __init__(self, data=None, **kwds):
    388387        """
    389         See ``ChainComplex`` for full documentation.
     388        See :mod:`ChainComplex` for full documentation.
    390389
    391390        EXAMPLES::
    392391
    class ChainComplex(SageObject): 
    495494        INPUT:
    496495
    497496        -  ``dim`` - element of the grading group (optional, default
    498            None).  If this is None, return a dictionary of all of the
    499            differentials.  If this is a single element, return the
     497           ``None``).  If this is ``None``, return a dictionary of all
     498           of the differentials.  If this is a single element, return the
    500499           differential starting in that dimension.
    501500
    502501        OUTPUT: either a dictionary of all of the differentials or a single
    class ChainComplex(SageObject): 
    578577   
    579578    def __cmp__(self, other):
    580579        """
    581         Return True iff this chain complex is the same as other: that
     580        Return ``True`` iff this chain complex is the same as other: that
    582581        is, if the base rings and the matrices of the two are the
    583582        same.
    584583
    class ChainComplex(SageObject): 
    607606        return -1
    608607
    609608    def homology(self, dim=None, **kwds):
    610         """
     609        r"""
    611610        The homology of the chain complex in the given dimension.
    612611       
    613612        INPUT:
    614613
    615         -  ``dim`` - an element of the grading group for the chain
    616            complex (optional, default None): the degree in which to
    617            compute homology. If this is None, return the homology in
     614        -  ``dim`` -- an element of the grading group for the chain
     615           complex (optional, default ``None``): the degree in which to
     616           compute homology. If this is ``None``, return the homology in
    618617           every dimension in which the chain complex is possibly
    619618           nonzero.
    620619
    621         -  ``base_ring`` - a commutative ring (optional, default is the
     620        -  ``base_ring`` -- a commutative ring (optional, default is the
    622621           base ring for the chain complex).  Must be either the
    623            integers `\\ZZ` or a field.
     622           integers `\ZZ` or a field.
    624623
    625         -  ``generators`` - boolean (optional, default False).  If
     624        -  ``generators`` -- boolean (optional, default False).  If
    626625           True, return generators for the homology groups along with
    627            the groups.  NOTE: this is only implemented if the CHomP
    628            package is available.
     626           the groups.
    629627
    630         -  ``verbose`` - boolean (optional, default False).  If True,
    631            print some messages as the homology is computed.
     628           .. NOTE::
    632629
    633         -  ``algorithm`` - string (optional, default 'auto').  The
    634            options are 'auto', 'dhsw', 'pari' or 'no_chomp'.  See
    635            below for descriptions.
     630               This is only implemented if the CHomP package is available.
     631
     632        -  ``verbose`` - boolean (optional, default ``False``).  If
     633           ``True``, print some messages as the homology is computed.
     634
     635        -  ``algorithm`` - string (optional, default ``'auto'``).  The
     636           options are ``'auto'``, ``'dhsw'``, ``'pari'`` or ``'no_chomp'``.
     637           See below for descriptions.
    636638
    637639        OUTPUT: if dim is specified, the homology in dimension dim.
    638640        Otherwise, the homology in every dimension as a dictionary
    class ChainComplex(SageObject): 
    640642
    641643        ALGORITHM:
    642644
    643         If ``algorithm`` is set to 'auto' (the default), then use
     645        If ``algorithm`` is set to ``'auto'`` (the default), then use
    644646        CHomP if available.  (CHomP is available at the web page
    645647        http://chomp.rutgers.edu/.  It is also an experimental package
    646648        for Sage.)
    class ChainComplex(SageObject): 
    660662        dimensions of the homology groups as vector spaces.  Over the
    661663        integers, compute Smith normal form of the boundary matrices
    662664        defining the chain complex according to the value of
    663         ``algorithm``.  If ``algorithm`` is 'auto' or 'no_chomp', then
    664         for each relatively small matrix, use the standard Sage
     665        ``algorithm``.  If ``algorithm`` is ``'auto'`` or ``'no_chomp'``,
     666        then for each relatively small matrix, use the standard Sage
    665667        method, which calls the Pari package.  For any large matrix,
    666668        reduce it using the Dumas, Heckenbach, Saunders, and Welker
    667         elimination algorithm: see
    668         :func:`sage.homology.chain_complex.dhsw_snf` for details.
     669        elimination algorithm [DHSW]_: see
     670        :func:`~sage.homology.chain_complex.dhsw_snf` for details.
    669671
    670         Finally, ``algorithm`` may also be 'pari' or 'dhsw', which
     672        Finally, ``algorithm`` may also be ``'pari'`` or ``'dhsw'``, which
    671673        forces the named algorithm to be used regardless of the size
    672674        of the matrices and regardless of whether CHomP is available.
    673675
    674676        As of this writing, CHomP is by far the fastest option,
    675         followed by the 'auto' or 'no_chomp' setting of using the
     677        followed by the ``'auto'`` or ``'no_chomp'`` setting of using the
    676678        Dumas, Heckenbach, Saunders, and Welker elimination algorithm
    677         for large matrices and Pari for small ones.
     679        [DHSW]_ for large matrices and Pari for small ones.
    678680
    679         .. warning::
     681        .. WARNING::
    680682
    681683           This only works if the base ring is the integers or a
    682684           field.  Other values will return an error.
    class ChainComplex(SageObject): 
    876878       
    877879        INPUT:
    878880
    879         -  ``dim`` - an element of the grading group for the chain
    880            complex or None (optional, default None).  If None, then
    881            return every Betti number, as a dictionary indexed by
     881        -  ``dim`` -- an element of the grading group for the chain
     882           complex or None (optional, default ``None``).  If ``None``,
     883           then return every Betti number, as a dictionary indexed by
    882884           degree.  If an element of the grading group, then return
    883885           the Betti number in that dimension.
    884886
    885         -  ``base_ring`` - a commutative ring (optional, default is the
     887        -  ``base_ring`` -- a commutative ring (optional, default is the
    886888           base ring for the chain complex).  Compute homology with
    887889           these coefficients.  Must be either the integers or a
    888890           field.
    class ChainComplex(SageObject): 
    917919            raise NotImplementedError, "Not implemented: unable to compute Betti numbers if the base ring is not ZZ or a field."
    918920
    919921    def torsion_list(self, max_prime, min_prime=2):
    920         """
     922        r"""
    921923        Look for torsion in this chain complex by computing its mod `p`
    922924        homology for a range of primes `p`.
    923925
    924926        INPUT:
    925927
    926         -  ``max_prime`` - prime number: search for torsion mod `p` for
     928        -  ``max_prime`` -- prime number: search for torsion mod `p` for
    927929           all `p` strictly less than this number.
    928930       
    929         -  ``min_prime`` - prime (optional, default 2): search for
     931        -  ``min_prime`` -- prime (optional, default 2): search for
    930932           torsion mod `p` for primes at least as big as this.
    931933
    932934        Return a list of pairs (`p`, ``dims``) where `p` is a prime at
    class ChainComplex(SageObject): 
    940942        ``max_prime``.  Compute the mod `P` homology of `C`, and use
    941943        this as the base-line computation: the assumption is that this
    942944        is isomorphic to the integral homology tensored with
    943         `\\GF{P}`.  Then compute the mod `p` homology for a range of
     945        `\GF{P}`.  Then compute the mod `p` homology for a range of
    944946        primes `p`, and record whenever the answer differs from the
    945947        base-line answer.
    946948
    class ChainComplex(SageObject): 
    10241026    def _flip_(self):
    10251027        """
    10261028        Flip chain complex upside down (degree `n` gets changed to
    1027         degree `-n`), thus turning a chain complex into a cochain
    1028         complex without changing the homology (except for flipping it,
    1029         too).
     1029        degree `-n`), thus turning a chain complex into a cochain complex
     1030        without changing the homology (except for flipping it, too).
    10301031
    10311032        EXAMPLES::
    10321033
    class ChainComplex(SageObject): 
    10501051
    10511052    def _chomp_repr_(self):
    10521053        r"""
    1053         String representation of self suitable for use by the CHomP
     1054        String representation of ``self`` suitable for use by the CHomP
    10541055        program.
    10551056
    10561057        Since CHomP can only handle chain complexes, not cochain
    class ChainComplex(SageObject): 
    11781179class HomologyGroup_class(AdditiveAbelianGroup_fixed_gens):
    11791180    """
    11801181    Abelian group on `n` generators. This class inherits from
    1181     ``AdditiveAbelianGroup``; see that for more documentation. The main
     1182    :class:`AdditiveAbelianGroup`; see that for more documentation. The main
    11821183    difference between the classes is in the print representation.
    11831184
    11841185    EXAMPLES::
    class HomologyGroup_class(AdditiveAbelia 
    11991200    """
    12001201    def __init__(self, n, invfac):
    12011202        """
    1202         See ``HomologyGroup`` for full documentation.
     1203        See :func:`HomologyGroup` for full documentation.
    12031204
    12041205        EXAMPLES::
    12051206
    class HomologyGroup_class(AdditiveAbelia 
    12881289
    12891290def HomologyGroup(n, invfac=None):
    12901291    """
    1291     Abelian group on `n` generators. This class inherits from
    1292     ``AdditiveAbelianGroup``; see that for more documentation.  The main
    1293     difference between the classes is in the print representation.
     1292    Abelian group on `n` generators.
    12941293
    12951294    EXAMPLES::
    12961295
  • sage/homology/chain_complex_homspace.py

    diff --git a/sage/homology/chain_complex_homspace.py b/sage/homology/chain_complex_homspace.py
    a b Homspaces between chain complexes 
    44Note that some significant functionality is lacking. Namely, the homspaces
    55are not actually modules over the base ring. It will be necessary to
    66enrich some of the structure of chain complexes for this to be naturally
    7 available. On other hand, there are various overloaded operators. __mul__
    8 acts as composition. One can __add__, and one can __mul__ with a ring element
    9 on the right.
     7available. On other hand, there are various overloaded operators. ``__mul__``
     8acts as composition. One can ``__add__``, and one can ``__mul__`` with a ring
     9element on the right.
    1010
    1111EXAMPLES::
    1212
    EXAMPLES:: 
    7171    sage: C = S.chain_complex()
    7272    sage: G = Hom(C,C)
    7373    sage: w = G(f)
    74     sage: w==x
     74    sage: w == x
    7575    True
    7676
    7777"""
    import sage.homology.chain_complex_morph 
    9797
    9898def is_ChainComplexHomspace(x):
    9999    """
    100     Returns True if and only if x is a morphism of chain complexes.
     100    Returns ``True`` if and only if ``x`` is a morphism of chain complexes.
    101101
    102102    EXAMPLES::
    103103
    104104        sage: from sage.homology.chain_complex_homspace import is_ChainComplexHomspace
    105         sage: T = SimplicialComplex(17,[[1,2,3,4],[7,8,9]])
    106         sage: C = T.chain_complex(augmented=True,cochain=True)
     105        sage: T = SimplicialComplex([[1,2,3,4],[7,8,9]])
     106        sage: C = T.chain_complex(augmented=True, cochain=True)
    107107        sage: G = Hom(C,C)
    108108        sage: is_ChainComplexHomspace(G)
    109109        True
    class ChainComplexHomspace(sage.categori 
    117117   
    118118    EXAMPLES::
    119119
    120         sage: T = SimplicialComplex(17,[[1,2,3,4],[7,8,9]])
    121         sage: C = T.chain_complex(augmented=True,cochain=True)
     120        sage: T = SimplicialComplex([[1,2,3,4],[7,8,9]])
     121        sage: C = T.chain_complex(augmented=True, cochain=True)
    122122        sage: G = Hom(C,C)
    123123        sage: G
    124124        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
    class ChainComplexHomspace(sage.categori 
    126126    """
    127127    def __call__(self, f):
    128128        """
    129         f is a dictionary of matrices in the basis of the chain complex.
     129        `f` is a dictionary of matrices in the basis of the chain complex.
    130130
    131131        EXAMPLES::
    132132
    class ChainComplexHomspace(sage.categori 
    138138            sage: x = i.associated_chain_complex_morphism()
    139139            sage: f = x._matrix_dictionary
    140140            sage: y = G(f)
    141             sage: x==y
     141            sage: x == y
    142142            True
    143143
    144144        """
  • sage/homology/chain_complex_morphism.py

    diff --git a/sage/homology/chain_complex_morphism.py b/sage/homology/chain_complex_morphism.py
    a b AUTHORS: 
    55
    66- Benjamin Antieau <d.ben.antieau@gmail.com> (2009.06)
    77
    8 This module implements morphisms of chain complexes. The input is a dictionary whose
    9 keys are in the grading group of the chain complex and whose values are matrix morphisms.
     8- Travis Scrimshaw (2012-08-18): Made all simplicial complexes immutable to
     9  work with the homset cache.
     10
     11This module implements morphisms of chain complexes. The input is a dictionary
     12whose keys are in the grading group of the chain complex and whose values are
     13matrix morphisms.
    1014
    1115EXAMPLES::
    1216
    from sage.rings.integer_ring import ZZ 
    5559
    5660def is_ChainComplexMorphism(x):
    5761    """
    58     Returns True if and only if x is a chain complex morphism.
     62    Returns ``True`` if and only if ``x`` is a chain complex morphism.
    5963
    6064    EXAMPLES::
    6165
    class ChainComplexMorphism(SageObject): 
    160164 
    161165    def __neg__(self):
    162166        """
    163         Returns -x.
     167        Returns ``-x``.
    164168
    165169        EXAMPLES::
    166170
    class ChainComplexMorphism(SageObject): 
    193197
    194198    def __add__(self,x):
    195199        """
    196         Returns self+x.
     200        Returns ``self + x``.
    197201
    198202        EXAMPLES::
    199203
    class ChainComplexMorphism(SageObject): 
    228232
    229233    def __mul__(self,x):
    230234        """
    231         Returns self*x if self and x are composable morphisms or if x is an element of the base_ring.
     235        Returns ``self * x`` if ``self`` and ``x`` are composable morphisms
     236        or if ``x`` is an element of the base ring.
    232237
    233238        EXAMPLES::
    234239
    class ChainComplexMorphism(SageObject): 
    286291
    287292    def __rmul__(self,x):
    288293        """
    289         Returns x*self if x is an element of the base_ring.
     294        Returns ``x * self`` if ``x`` is an element of the base ring.
    290295
    291296        EXAMPLES::
    292297
    class ChainComplexMorphism(SageObject): 
    310315
    311316    def __sub__(self,x):
    312317        """
    313         Returns self-x.
     318        Returns ``self - x``.
    314319
    315320        EXAMPLES::
    316321
    class ChainComplexMorphism(SageObject): 
    340345
    341346    def __eq__(self,x):
    342347        """
    343         Returns True if and only if self==x.
     348        Returns ``True`` if and only if ``self == x``.
    344349
    345350        EXAMPLES::
    346351
    347             sage: S = SimplicialComplex(3)
     352            sage: S = SimplicialComplex(is_mutable=False)
    348353            sage: H = Hom(S,S)
    349354            sage: i = H.identity()
    350355            sage: x = i.associated_chain_complex_morphism()
    class ChainComplexMorphism(SageObject): 
    354359            sage: C = S.chain_complex()
    355360            sage: G = Hom(C,C)
    356361            sage: y = G(f)
    357             sage: x==y
     362            sage: x == y
    358363            True
    359364
    360365        """
    class ChainComplexMorphism(SageObject): 
    365370
    366371    def _repr_(self):
    367372        """
    368         Returns the string representation of self.
     373        Returns the string representation of ``self``.
    369374
    370375        EXAMPLES::
    371376
    372             sage: S = SimplicialComplex(3)
     377            sage: S = SimplicialComplex(is_mutable=False)
    373378            sage: H = Hom(S,S)
    374379            sage: i = H.identity()
    375380            sage: x = i.associated_chain_complex_morphism()
  • sage/homology/examples.py

    diff --git a/sage/homology/examples.py b/sage/homology/examples.py
    a b These provide examples of large simplici 
    2323simplices.
    2424
    2525All of these examples are accessible by typing
    26 "simplicial_complexes.NAME", where "NAME" is the name of the example.
    27 You can get a list by typing "simplicial_complexes." and hitting the
     26``simplicial_complexes.NAME``, where ``NAME`` is the name of the example.
     27You can get a list by typing ``simplicial_complexes.`` and hitting the
    2828TAB key::
    2929
    3030   simplicial_complexes.ChessboardComplex
    from sage.combinat.subset import Subsets 
    5454import sage.misc.prandom as random
    5555
    5656def matching(A, B):
    57     """
    58     List of maximal matchings between the sets A and B: a matching
    59     is a set of pairs (a,b) in A x B where each a, b appears in at
    60     most one pair.  A maximal matching is one which is maximal
    61     with respect to inclusion of subsets of A x B.
     57    r"""
     58    List of maximal matchings between the sets ``A`` and ``B``.
     59
     60    A matching is a set of pairs `(a,b) \in A \times B` where each `a` and
     61    `b` appears in at most one pair.  A maximal matching is one which is
     62    maximal with respect to inclusion of subsets of `A \times B`.
    6263
    6364    INPUT:
    6465
    65     -  ``A``, ``B`` - list, tuple, or indeed anything which can be
     66    -  ``A``, ``B`` -- list, tuple, or indeed anything which can be
    6667       converted to a set.
    6768
    6869    EXAMPLES::
    69    
     70
    7071        sage: from sage.homology.examples import matching
    7172        sage: matching([1,2], [3,4])
    7273        [set([(1, 3), (2, 4)]), set([(2, 3), (1, 4)])]
    def matching(A, B): 
    8788def facets_for_RP4():
    8889    """
    8990    Return the list of facets for a minimal triangulation of 4-dimensional
    90     real projective space. We use vertices numbered 1 through 16, define two
    91     facets, and define a certain subgroup `G` of the symmetric group `S_{16}`.
    92     Then the set of all facets is the `G`-orbit of the two given facets.
     91    real projective space.
     92
     93    We use vertices numbered 1 through 16, define two facets, and define
     94    a certain subgroup `G` of the symmetric group `S_{16}`. Then the set
     95    of all facets is the `G`-orbit of the two given facets.
     96
    9397    See the description in Example 3.12 in Datta [Da2007]_.
    9498
    9599    EXAMPLES::
    def facets_for_RP4(): 
    119123
    120124def facets_for_K3():
    121125    """
    122     Returns the facets for a minimal triangulation of the K3
    123     surface. This is a pure simplicial complex of dimension 4 with 16
     126    Returns the facets for a minimal triangulation of the K3 surface.
     127
     128    This is a pure simplicial complex of dimension 4 with 16
    124129    vertices and 288 facets. The facets are obtained by constructing a
    125130    few facets and a permutation group `G`, and then computing the
    126     `G`-orbit of those facets. See Casella and Kühnel in [CK2001]_ and
    127     Spreer and Kühnel [SK2011]_; the construction here uses the
    128     labeling from Spreer and Kühnel.
     131    `G`-orbit of those facets.
     132
     133    See Casella and Kühnel in [CK2001]_ and Spreer and Kühnel [SK2011]_;
     134    the construction here uses the labeling from Spreer and Kühnel.
    129135
    130136    EXAMPLES::
    131137
    class SimplicialComplexExamples(): 
    149155    Some examples of simplicial complexes.
    150156
    151157    Here are the available examples; you can also type
    152     "simplicial_complexes."  and hit tab to get a list::
     158    ``simplicial_complexes.``  and hit tab to get a list::
    153159
    154         ChessboardComplex
    155         ComplexProjectivePlane
    156         K3Surface
    157         KleinBottle
    158         MatchingComplex
    159         MooreSpace
    160         NotIConnectedGraphs
    161         PoincareHomologyThreeSphere
    162         RandomComplex
    163         RealProjectivePlane
    164         RealProjectiveSpace
    165         Simplex
    166         Sphere
    167         SurfaceOfGenus
    168         Torus
     160    - :meth:`ChessboardComplex`
     161    - :meth:`ComplexProjectivePlane`
     162    - :meth:`K3Surface`
     163    - :meth:`KleinBottle`
     164    - :meth:`MatchingComplex`
     165    - :meth:`MooreSpace`
     166    - :meth:`NotIConnectedGraphs`
     167    - :meth:`PoincareHomologyThreeSphere`
     168    - :meth:`RandomComplex`
     169    - :meth:`RealProjectivePlane`
     170    - :meth:`RealProjectiveSpace`
     171    - :meth:`Simplex`
     172    - :meth:`Sphere`
     173    - :meth:`SurfaceOfGenus`
     174    - :meth:`Torus`
    169175
    170176    EXAMPLES::
    171177
    class SimplicialComplexExamples(): 
    183189
    184190    def Sphere(self,n):
    185191        """
    186         A minimal triangulation of the n-dimensional sphere.
     192        A minimal triangulation of the `n`-dimensional sphere.
    187193       
    188194        INPUT:
    189195
    190         -  ``n`` - positive integer
     196        -  ``n`` -- positive integer
    191197
    192198        EXAMPLES::
    193199
    class SimplicialComplexExamples(): 
    207213        """
    208214        S = Simplex(n+1)
    209215        facets = S.faces()
    210         S = SimplicialComplex(n+1, facets)
    211         return S
     216        return SimplicialComplex(facets, is_mutable=False)
    212217
    213218    def Simplex(self, n):
    214219        """
    class SimplicialComplexExamples(): 
    216221
    217222        INPUT:
    218223
    219         -  ``n`` - a non-negative integer
     224        -  ``n`` -- a non-negative integer
    220225
    221226        OUTPUT: the simplicial complex consisting of the `n`-simplex
    222227        on vertices `(0, 1, ..., n)` and all of its faces.
    class SimplicialComplexExamples(): 
    228233            sage: simplicial_complexes.Simplex(5).euler_characteristic()
    229234            1
    230235        """
    231         S = Simplex(n)
    232         return SimplicialComplex(n, list(S))
    233        
     236        return SimplicialComplex([Simplex(n)], is_mutable=False)
    234237
    235238    def Torus(self):
    236239        """
    class SimplicialComplexExamples(): 
    241244            sage: simplicial_complexes.Torus().homology(1)
    242245            Z x Z
    243246        """
    244         return SimplicialComplex(6, [[0,1,2], [1,2,4], [1,3,4], [1,3,6],
    245                                      [0,1,5], [1,5,6], [2,3,5], [2,4,5],
    246                                      [2,3,6], [0,2,6], [0,3,4], [0,3,5],
    247                                      [4,5,6], [0,4,6]])
     247        return SimplicialComplex([[0,1,2], [1,2,4], [1,3,4], [1,3,6],
     248                                  [0,1,5], [1,5,6], [2,3,5], [2,4,5],
     249                                  [2,3,6], [0,2,6], [0,3,4], [0,3,5],
     250                                  [4,5,6], [0,4,6]],
     251                                 is_mutable=False)
    248252
    249253    def RealProjectivePlane(self):
    250254        """
    class SimplicialComplexExamples(): 
    265269            sage: P.cohomology(2, base_ring=GF(2))
    266270            Vector space of dimension 1 over Finite Field of size 2
    267271        """
    268         return SimplicialComplex(5, [[0,1,2], [0,2,3], [0,1,5], [0,4,5],
    269                                      [0,3,4], [1,2,4], [1,3,4], [1,3,5],
    270                                      [2,3,5], [2,4,5]])
     272        return SimplicialComplex([[0,1,2], [0,2,3], [0,1,5], [0,4,5],
     273                                  [0,3,4], [1,2,4], [1,3,4], [1,3,5],
     274                                  [2,3,5], [2,4,5]],
     275                                 is_mutable=False)
    271276
    272277    ProjectivePlane = RealProjectivePlane
    273278
    class SimplicialComplexExamples(): 
    290295        return SimplicialComplex([[2,3,7], [1,2,3], [1,3,5], [1,5,7],
    291296                                  [1,4,7], [2,4,6], [1,2,6], [1,6,0],
    292297                                  [1,4,0], [2,4,0], [3,4,7], [3,4,6],
    293                                   [3,5,6], [5,6,0], [2,5,0], [2,5,7]])
     298                                  [3,5,6], [5,6,0], [2,5,0], [2,5,7]],
     299                                 is_mutable=False)
    294300
    295301    def SurfaceOfGenus(self, g, orientable=True):
    296302        """
    297         A surface of genus g.
     303        A surface of genus `g`.
    298304
    299305        INPUT:
    300306
    301         -  ``g`` - a non-negative integer.  The desired genus
     307        -  ``g`` -- a non-negative integer.  The desired genus
    302308
    303         -  ``orientable`` - boolean (optional, default True). If True,
    304            return an orientable surface, and if False, return a
    305            non-orientable surface.
     309        -  ``orientable`` -- boolean (optional, default ``True``). If
     310           ``True``, return an orientable surface, and if ``False``,
     311           return a non-orientable surface.
    306312
    307313        In the orientable case, return a sphere if `g` is zero, and
    308         otherwise return a `g`-fold connected sum of a torus with
    309         itself.
     314        otherwise return a `g`-fold connected sum of a torus with itself.
    310315
    311316        In the non-orientable case, raise an error if `g` is zero.  If
    312317        `g` is positive, return a `g`-fold connected sum of a
    class SimplicialComplexExamples(): 
    330335            T = simplicial_complexes.RealProjectivePlane()
    331336        S = T
    332337        for i in range(g-1):
    333             S = S.connected_sum(T)
     338            S = S.connected_sum(T, is_mutable=False)
    334339        return S
    335340
    336341    def MooreSpace(self, q):
    337342        """
    338         Triangulation of the mod q Moore space.
     343        Triangulation of the mod `q` Moore space.
    339344
    340345        INPUT:
    341346
    342         -  ``q`` - integer, at least 2
     347        -  ``q`` -0 integer, at least 2
    343348
    344349        This is a simplicial complex with simplices of dimension 0, 1,
    345350        and 2, such that its reduced homology is isomorphic to
    class SimplicialComplexExamples(): 
    368373            Simplicial complex with 19 vertices and 54 facets
    369374        """
    370375        if q <= 1:
    371             raise ValueError, "The mod q Moore space is only defined if q is at least 2"
     376            raise ValueError("The mod q Moore space is only defined if q is at least 2")
    372377        if q == 2:
    373             return simplicial_complexes.RealProjectivePlane()
    374         vertices = [1, 2, 3]
     378            return RealProjectivePlane()
    375379        facets = []
    376380        for i in range(q):
    377381            Ai = "A" + str(i)
    378382            Aiplus = "A" + str((i+1)%q)
    379383            Bi = "B" + str(i)
    380             vertices.append(Ai)
    381             vertices.append(Bi)
    382384            facets.append([1, 2, Ai])
    383385            facets.append([2, 3, Ai])
    384386            facets.append([3, 1, Bi])
    class SimplicialComplexExamples(): 
    389391            Ai = "A" + str(i)
    390392            Aiplus = "A" + str((i+1)%q)
    391393            facets.append(["A0", Ai, Aiplus])
    392         return SimplicialComplex(vertices, facets)
     394        return SimplicialComplex(facets, is_immutable=True)
    393395
    394396    def ComplexProjectivePlane(self):
    395397        """
    class SimplicialComplexExamples(): 
    425427             [7, 8, 1, 2, 3], [8, 9, 2, 3, 1], [9, 7, 3, 1, 2],
    426428             [7, 8, 1, 2, 6], [8, 9, 2, 3, 4], [9, 7, 3, 1, 5],
    427429             [8, 9, 3, 1, 6], [9, 7, 1, 2, 4], [7, 8, 2, 3, 5],
    428              [9, 7, 2, 3, 6], [7, 8, 3, 1, 4], [8, 9, 1, 2, 5]])
     430             [9, 7, 2, 3, 6], [7, 8, 3, 1, 4], [8, 9, 1, 2, 5]],
     431            is_mutable=False)
    429432
    430433    def PoincareHomologyThreeSphere(self):
    431434        """
    class SimplicialComplexExamples(): 
    473476             [7, 8, 11, 15], [7, 8, 14, 15], [7, 9, 14, 15], [8, 12, 14, 15],
    474477             [9, 10, 11, 12], [9, 10, 11, 16], [9, 10, 15, 16], [9, 11, 14, 16],
    475478             [9, 14, 15, 16], [10, 11, 13, 16], [10, 13, 15, 16],
    476              [11, 13, 14, 16], [12, 13, 14, 15], [13, 14, 15, 16]])
     479             [11, 13, 14, 16], [12, 13, 14, 15], [13, 14, 15, 16]],
     480            is_mutable=False)
    477481
    478482    def RealProjectiveSpace(self, n):
    479483        r"""
    class SimplicialComplexExamples(): 
    481485
    482486        INPUT:
    483487
    484         - ``n`` - integer, the dimension of the real projective space
     488        - ``n`` -- integer, the dimension of the real projective space
    485489          to construct
    486490
    487491        The first few cases are pretty trivial:
    class SimplicialComplexExamples(): 
    576580        but if you have CHomP installed, Sage will use that and the
    577581        computation should only take a second or two.  (You can
    578582        download CHomP from http://chomp.rutgers.edu/, or you can
    579         install it as a Sage package using "sage -i chomp"). ::
     583        install it as a Sage package using ``sage -i chomp``). ::
    580584
    581585            sage: P5.homology()  # long time # optional - CHomP
    582586            {0: 0, 1: C2, 2: 0, 3: C2, 4: 0, 5: Z}
    class SimplicialComplexExamples(): 
    608612                 [4, 5, 6, 11], [1, 3, 5, 10], [1, 5, 6, 11], [2, 4, 8, 10],
    609613                 [3, 4, 8, 9], [4, 5, 7, 9], [1, 3, 5, 11], [1, 5, 8, 10],
    610614                 [2, 5, 7, 8], [3, 5, 9, 10], [4, 6, 7, 10], [1, 3, 7, 10],
    611                  [1, 6, 8, 9], [2, 5, 7, 9], [3, 6, 7, 8], [5, 6, 7, 8]])
     615                 [1, 6, 8, 9], [2, 5, 7, 9], [3, 6, 7, 8], [5, 6, 7, 8]],
     616                is_mutable=False)
    612617        if n == 4:
    613618            return SimplicialComplex(
    614619                [(1, 3, 8, 12, 13), (2, 7, 8, 13, 16), (4, 8, 9, 12, 14),
    class SimplicialComplexExamples(): 
    660665                    (4, 7, 8, 12, 15), (2, 3, 5, 10, 15), (2, 6, 8, 10, 16),
    661666                    (3, 4, 10, 15, 16), (1, 5, 6, 14, 16), (2, 3, 5, 14, 15),
    662667                    (2, 3, 7, 9, 16), (2, 7, 9, 13, 14), (3, 4, 6, 7, 15),
    663                     (4, 8, 10, 14, 16), (3, 4, 7, 15, 16), (2, 8, 10, 15, 16)])
     668                    (4, 8, 10, 14, 16), (3, 4, 7, 15, 16), (2, 8, 10, 15, 16)],
     669                 is_mutable=False)
    664670        if n >= 5:
    665671            # Use the construction given by Datta in Example 3.21.
    666672            V = set(range(0, n+2))
    class SimplicialComplexExamples(): 
    675681                    else:
    676682                        new.append(v)
    677683                facets.add(tuple(new))
    678             return SimplicialComplex(list(facets))
     684            return SimplicialComplex(list(facets), is_mutable=False)
    679685
    680686    def K3Surface(self):
    681687        """
    682         Returns a minimal triangulation of the K3 surface. This is
    683         a pure simplicial complex of dimension 4 with 16 vertices
     688        Returns a minimal triangulation of the K3 surface.
     689
     690        This is a pure simplicial complex of dimension 4 with 16 vertices
    684691        and 288 facets. It was constructed by Casella and Kühnel
    685692        in [CK2001]_. The construction here uses the labeling from
    686693        Spreer and Kühnel [SK2011]_.
    class SimplicialComplexExamples(): 
    803810                (6, 9, 10, 13, 16), (2, 4, 9, 13, 16), (1, 6, 7, 8, 13),
    804811                (1, 4, 12, 13, 15), (2, 4, 7, 10, 11), (1, 4, 9, 11, 13),
    805812                (6, 7, 11, 14, 16), (1, 4, 9, 11, 16), (1, 4, 12, 15, 16),
    806                 (1, 2, 4, 7, 15), (2, 3, 7, 8, 16), (1, 4, 5, 6, 10)])
     813                (1, 2, 4, 7, 15), (2, 3, 7, 8, 16), (1, 4, 5, 6, 10)],
     814             is_mutable=False)
    807815
    808816    ###############################################################
    809817    # examples from graph theory:
    810818
    811819    def NotIConnectedGraphs(self, n, i):
    812820        """
    813         The simplicial complex of all graphs on n vertices which are
    814         not i-connected.
     821        The simplicial complex of all graphs on `n` vertices which are
     822        not `i`-connected.
    815823
    816824        Fix an integer `n>0` and consider the set of graphs on `n`
    817825        vertices.  View each graph as its set of edges, so it is a
    class SimplicialComplexExamples(): 
    828836
    829837        INPUT:
    830838
    831         -  ``n``, ``i`` - non-negative integers with `i` at most `n`
     839        -  ``n``, ``i`` -- non-negative integers with `i` at most `n`
    832840
    833         See Dumas et al. [DHSW2003]_ for information on computing its homology by
    834         computer, and see Babson et al. [BBLSW1999]_ for theory.  For example,
    835         Babson et al. show that when `i=2`, the reduced homology of
     841        See Dumas et al. [DHSW2003]_ for information on computing its homology
     842        by computer, and see Babson et al. [BBLSW1999]_ for theory.  For
     843        example, Babson et al. show that when `i=2`, the reduced homology of
    836844        this complex is nonzero only in dimension `2n-5`, where it is
    837845        free abelian of rank `(n-2)!`.
    838846
    class SimplicialComplexExamples(): 
    874882                            bad_edge = (min(v,w), max(v,w))
    875883                            facet = facet.difference(Set([bad_edge]))
    876884                    facets.append(facet)
    877         return SimplicialComplex(E_list, facets)
     885        return SimplicialComplex(facets, is_mutable=False)
    878886               
    879887    def MatchingComplex(self, n):
    880888        """
    881         The matching complex of graphs on n vertices.
     889        The matching complex of graphs on `n` vertices.
    882890
    883891        Fix an integer `n>0` and consider a set `V` of `n` vertices.
    884892        A 'partial matching' on `V` is a graph formed by edges so that
    class SimplicialComplexExamples(): 
    892900
    893901        INPUT:
    894902
    895         -  ``n`` - positive integer.
     903        -  ``n`` -- positive integer.
    896904   
    897         See Dumas et al. [DHSW2003]_ for information on computing its homology by
    898         computer, and see Wachs [Wa2003]_ for an expository article about the
    899         theory.  For example, the homology of these complexes seems to
     905        See Dumas et al. [DHSW2003]_ for information on computing its homology
     906        by computer, and see Wachs [Wa2003]_ for an expository article about
     907        the theory.  For example, the homology of these complexes seems to
    900908        have only mod 3 torsion, and this has been proved for the
    901         bottom non-vanishing homology group for the matching complex
    902         `M_n`.
     909        bottom non-vanishing homology group for the matching complex `M_n`.
    903910
    904911        EXAMPLES::
    905912
    class SimplicialComplexExamples(): 
    920927           345-385)
    921928        """
    922929        G_vertices = Set(range(1,n+1))
    923         E_list = []
    924         for w in G_vertices:
    925             for v in range(1,w):
    926                 E_list.append((v,w))
    927930        facets = []
    928931        if is_even(n):
    929932            half = int(n/2)
    class SimplicialComplexExamples(): 
    958961                        for pair in M:
    959962                            facet.append(tuple(sorted(pair)))
    960963                        facets.append(facet)
    961         return SimplicialComplex(E_list, facets)
     964        return SimplicialComplex(facets, is_mutable=False)
    962965               
    963966    def ChessboardComplex(self, n, i):
    964967        r"""
    965         The chessboard complex for an n by i chessboard.
     968        The chessboard complex for an `n \times i` chessboard.
    966969
    967970        Fix integers `n, i > 0` and consider sets `V` of `n` vertices
    968971        and `W` of `i` vertices.  A 'partial matching' between `V` and
    class SimplicialComplexExamples(): 
    980983
    981984        INPUT:
    982985
    983         -  ``n, i`` - positive integers.
     986        -  ``n, i`` -- positive integers.
    984987   
    985988        See Dumas et al. [DHSW2003]_ for information on computing its homology
    986989        by computer, and see Wachs [Wa2003]_ for an expository article about
    class SimplicialComplexExamples(): 
    10021005            for w in B:
    10031006                E_dict[(v,w)] = index
    10041007                index += 1
    1005         E = range(n*i)
    10061008        facets = []
    10071009        for M in matching(A, B):
    10081010            facet = []
    10091011            for pair in M:
    10101012                facet.append(E_dict[pair])
    10111013            facets.append(facet)
    1012         return SimplicialComplex(E, facets)
     1014        return SimplicialComplex(facets, is_mutable=False)
    10131015
    10141016    def RandomComplex(self, n, d, p=0.5):
    10151017        """
    1016         A random ``d``-dimensional simplicial complex on ``n``
    1017         vertices.
     1018        A random ``d``-dimensional simplicial complex on ``n`` vertices.
    10181019
    10191020        INPUT:
    10201021
    1021         - ``n`` - number of vertices
    1022         - ``d`` - dimension of the complex
    1023         -  ``p`` - floating point number between 0 and 1
     1022        - ``n`` -- number of vertices
     1023
     1024        - ``d`` -- dimension of the complex
     1025
     1026        -  ``p`` -- floating point number between 0 and 1
    10241027           (optional, default 0.5)
    10251028
    10261029        A random `d`-dimensional simplicial complex on `n` vertices,
    10271030        as defined for example by Meshulam and Wallach [MW2009]_, is
    10281031        constructed as follows: take `n` vertices and include all of
    10291032        the simplices of dimension strictly less than `d`, and then for each
    1030         possible simplex of dimension `d`, include it with probability
    1031         `p`.
     1033        possible simplex of dimension `d`, include it with probability `p`.
    10321034
    10331035        EXAMPLES::
    10341036
    class SimplicialComplexExamples(): 
    10561058            facets = Subsets(vertices, d).list()
    10571059            maybe = Subsets(vertices, d+1)
    10581060            facets.extend([f for f in maybe if random.random() <= p])
    1059             return SimplicialComplex(n-1, facets)
     1061            return SimplicialComplex(facets, is_mutable=False)
    10601062
    10611063simplicial_complexes = SimplicialComplexExamples()
  • sage/homology/simplicial_complex.py

    diff --git a/sage/homology/simplicial_complex.py b/sage/homology/simplicial_complex.py
    a b AUTHORS: 
    99  remove_facet, and is_flag_complex methods;
    1010  cached the output of the graph() method.
    1111
     12- Travis Scrimshaw (2012-08-17): Made :class:`SimplicialComplex` have an
     13  immutable option, and added ``__hash__()`` function which checks to make
     14  sure it is immutable. Made :meth:`SimplicialComplex.remove_face()` into a
     15  mutator. Deprecated the ``vertex_set`` parameter.
     16
    1217This module implements the basic structure of finite simplicial
    1318complexes. Given a set `V` of "vertices", a simplicial complex on `V`
    1419is a collection `K` of subsets of `V` satisfying the condition that if
    tuple, or set, or it can be a non-negati 
    4348the vertex set is `(0, ..., n)`.  Also specify the facets: the maximal
    4449faces.
    4550
    46 .. note::
     51.. NOTE::
    4752
    4853   The elements of the vertex set are not automatically contained in
    4954   the simplicial complex: each one is only included if and only if it
    5055   is a vertex of at least one of the specified facets.
    5156
    52 .. note::
     57.. NOTE::
    5358
    5459   This class derives from
    5560   :class:`~sage.homology.cell_complex.GenericCellComplex`, and so
    faces. 
    5964
    6065EXAMPLES::
    6166
    62     sage: SimplicialComplex([1, 3, 7], [[1], [3, 7]])
     67    sage: SimplicialComplex([[1], [3, 7]])
    6368    Simplicial complex with vertex set (1, 3, 7) and facets {(3, 7), (1,)}
    64     sage: SimplicialComplex(2)   # the empty simplicial complex
    65     Simplicial complex with vertex set (0, 1, 2) and facets {()}
    66     sage: X = SimplicialComplex(3, [[0,1], [1,2], [2,3], [3,0]])
     69    sage: SimplicialComplex()   # the empty simplicial complex
     70    Simplicial complex with vertex set () and facets {()}
     71    sage: X = SimplicialComplex([[0,1], [1,2], [2,3], [3,0]])
    6772    sage: X
    6873    Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2), (2, 3), (0, 3), (0, 1)}   
    6974    sage: X.stanley_reisner_ring()
    EXAMPLES:: 
    7479Sage can perform a number of operations on simplicial complexes, such
    7580as the join and the product, and it can also compute homology::
    7681
    77     sage: S = SimplicialComplex(2, [[0,1], [1,2], [0,2]]) # circle
     82    sage: S = SimplicialComplex([[0,1], [1,2], [0,2]]) # circle
    7883    sage: T = S.product(S)  # torus
    7984    sage: T
    8085    Simplicial complex with 9 vertices and 18 facets
    as the join and the product, and it can  
    8691Sage knows about some basic combinatorial data associated to a
    8792simplicial complex::
    8893
    89     sage: X = SimplicialComplex(3, [[0,1], [1,2], [2,3], [0,3]])
     94    sage: X = SimplicialComplex([[0,1], [1,2], [2,3], [0,3]])
    9095    sage: X.f_vector()
    9196    [1, 4, 4]
    9297    sage: X.face_poset()
    9398    Finite poset containing 8 elements
    9499    sage: X.stanley_reisner_ring()
    95100    Quotient of Multivariate Polynomial Ring in x0, x1, x2, x3 over Integer Ring by the ideal (x1*x3, x0*x2)
     101
     102Mutability (see :trac:`12587`)::
     103
     104    sage: S = SimplicialComplex([[1,4], [2,4]])
     105    sage: S.add_face([1,3])
     106    sage: S.remove_face([1,3]); S
     107    Simplicial complex with vertex set (1, 2, 3, 4) and facets {(2, 4), (1, 4), (3,)}
     108    sage: hash(S)
     109    Traceback (most recent call last):
     110    ...
     111    ValueError: This simplicial complex must be immutable. Call set_immutable().
     112    sage: S = SimplicialComplex([[1,4], [2,4]])
     113    sage: S.set_immutable()
     114    sage: S.add_face([1,3])
     115    Traceback (most recent call last):
     116    ...
     117    ValueError: This simplicial complex is not mutable
     118    sage: S.remove_face([1,3])
     119    Traceback (most recent call last):
     120    ...
     121    ValueError: This simplicial complex is not mutable
     122    sage: hash(S)
     123    264071120            # 32-bit
     124    -3244381654768326704 # 64-bit
     125
     126    sage: S2 = SimplicialComplex([[1,4], [2,4]], is_mutable=False)
     127    sage: hash(S2) == hash(S)
     128    True
    96129"""
    97130
    98131# possible future directions for SimplicialComplex:
    def lattice_paths(t1, t2, length=None): 
    128161
    129162    :param t1: labeling for vertices
    130163    :param t2: labeling for vertices
    131     :param length: if not None, then an integer, the length of the desired path.
    132     :type length: integer or None; optional, default None
     164    :param length: if not ``None``, then an integer, the length of the desired
     165        path.
     166    :type length: integer or ``None``; optional, default ``None``
    133167    :type t1: tuple, list, other iterable
    134168    :type t2: tuple, list, other iterable
    135169    :return: list of lists of vertices making up the paths as described above
    def lattice_paths(t1, t2, length=None): 
    225259                   
    226260def rename_vertex(n, keep, left = True):
    227261    """
    228     Rename a vertex: the vertices from the list 'keep' get
     262    Rename a vertex: the vertices from the list ``keep`` get
    229263    relabeled 0, 1, 2, ..., in order.  Any other vertex (e.g. 4) gets
    230264    renamed to by prepending an 'L' or an 'R' (thus to either 'L4' or
    231     'R4'), depending on whether the argument left is True or False.
     265    'R4'), depending on whether the argument left is ``True`` or ``False``.
    232266
    233267    :param n: a 'vertex': either an integer or a string
    234268    :param keep: a list of three vertices
    235     :param left: if True, rename for use in left factor
    236     :type left: boolean; optional, default True
    237 
    238     This is used by the ``connected_sum`` method for simplicial
    239     complexes.
     269    :param left: if ``True``, rename for use in left factor
     270    :type left: boolean; optional, default ``True``
     271
     272    This is used by the :meth:`~SimplicialComplex.connected_sum` method for
     273    simplicial complexes.
    240274
    241275    EXAMPLES::
    242276
    class Simplex(SageObject): 
    277311    vertex must be hashable, so it should be a number, a string, or a
    278312    tuple, for instance, but not a list.
    279313
    280     .. warning::
     314    .. WARNING::
    281315
    282316       The vertices should be distinct, and no error checking is done
    283317       to make sure this is the case.
    class Simplex(SageObject): 
    305339
    306340    def __init__(self, X):
    307341        """
    308         Define a simplex.  See ``Simplex`` for full documentation.
     342        Define a simplex.  See :class:`Simplex` for full documentation.
    309343       
    310344        EXAMPLES::
    311345
    class Simplex(SageObject): 
    353387
    354388    def is_face(self, other):
    355389        """
    356         Return True iff this simplex is a face of other.
     390        Return ``True`` iff this simplex is a face of other.
    357391
    358392        EXAMPLES::
    359393
    class Simplex(SageObject): 
    368402
    369403    def __contains__(self, x):
    370404        """
    371         Return True iff ``x`` is a vertex of this simplex.
     405        Return ``True`` iff ``x`` is a vertex of this simplex.
    372406
    373407        EXAMPLES::
    374408
    class Simplex(SageObject): 
    381415
    382416    def __getitem__(self, n):
    383417        """
    384         Return the nth vertex in this simplex.
     418        Return the `n`-th vertex in this simplex.
    385419
    386420        EXAMPLES::
    387421
    class Simplex(SageObject): 
    423457
    424458        :param n: an integer between 0 and the dimension of this simplex
    425459        :type n: integer
    426         :return: the simplex obtained by removing the nth vertex from this simplex
     460        :return: the simplex obtained by removing the ``n``-th vertex from this
     461            simplex
    427462
    428463        EXAMPLES::
    429464
    class Simplex(SageObject): 
    454489
    455490    def dimension(self):
    456491        """
    457         The dimension of this simplex: the number of vertices minus 1.
     492        The dimension of this simplex.
     493
     494        The dimension of a simplex is the number of vertices minus 1.
    458495
    459496        EXAMPLES::
    460497
    class Simplex(SageObject): 
    467504
    468505    def is_empty(self):
    469506        """
    470         Return True iff this simplex is the empty simplex.
     507        Return ``True`` iff this simplex is the empty simplex.
    471508
    472509        EXAMPLES::
    473510
    class Simplex(SageObject): 
    485522
    486523        :param right: the other simplex (the right-hand factor)
    487524
    488         :param rename_vertices: If this is True, the vertices in the
     525        :param rename_vertices: If this is ``True``, the vertices in the
    489526            join will be renamed by this formula: vertex "v" in the
    490527            left-hand factor --> vertex "Lv" in the join, vertex "w"
    491528            in the right-hand factor --> vertex "Rw" in the join.  If
    class Simplex(SageObject): 
    493530            renaming the vertices; this may cause problems if the two
    494531            factors have any vertices with names in common.
    495532
    496         :type rename_vertices: boolean; optional, default True
     533        :type rename_vertices: boolean; optional, default ``True``
    497534
    498535        EXAMPLES::
    499536
    class Simplex(SageObject): 
    512549        return Simplex(vertex_set)
    513550
    514551    def product(self, other, rename_vertices=True):
    515         """
     552        r"""
    516553        The product of this simplex with another one, as a list of simplices.
    517554
    518555        :param other: the other simplex
    519556
    520         :param rename_vertices: If this is False, then the vertices in
     557        :param rename_vertices: If this is ``False``, then the vertices in
    521558            the product are the set of ordered pairs `(v,w)` where `v`
    522559            is a vertex in the left-hand factor (``self``) and `w` is
    523560            a vertex in the right-hand factor (``other``). If this is
    524             True, then the vertices are renamed as "LvRw" (e.g., the
     561            ``True``, then the vertices are renamed as "LvRw" (e.g., the
    525562            vertex (1,2) would become "L1R2").  This is useful if you
    526563            want to define the Stanley-Reisner ring of the complex:
    527564            vertex names like (0,1) are not suitable for that, while
    528565            vertex names like "L0R1" are.
    529566
    530         :type rename-vertices: boolean; optional, default True
    531 
    532         Algorithm: see Hatcher, p. 277-278 (who in turn refers to
    533         Eilenberg-Steenrod, p. 68): given ``Simplex(m)`` and
    534         ``Simplex(n)``, then ``Simplex(m)`` x ``Simplex(n)`` can be
     567        :type rename-vertices: boolean; optional, default ``True``
     568
     569        Algorithm: see Hatcher, p. 277-278 [Hat]_ (who in turn refers to
     570        Eilenberg-Steenrod, p. 68): given ``S = Simplex(m)`` and
     571        ``T = Simplex(n)``, then `S \times T` can be
    535572        triangulated as follows: for each path `f` from `(0,0)` to
    536573        `(m,n)` along the integer grid in the plane, going up or right
    537574        at each lattice point, associate an `(m+n)`-simplex with
    class Simplex(SageObject): 
    543580        where `v` is a vertex in the left-hand factor and `w`
    544581        is a vertex in the right-hand factor.
    545582
    546         .. note::
    547 
    548            This produces a list of simplices -- not a ``Simplex``, not
    549            a ``SimplicialComplex``.
     583        .. NOTE::
     584
     585           This produces a list of simplices -- not a :class:`Simplex`, not
     586           a :class:`SimplicialComplex`.
    550587
    551588        EXAMPLES::
    552589
    class Simplex(SageObject): 
    559596
    560597        REFERENCES:
    561598
    562         - A. Hatcher, "Algebraic Topology", Cambridge University Press
    563           (2002).
     599        .. [Hat] A. Hatcher, "Algebraic Topology", Cambridge University Press
     600           (2002).
    564601        """
    565602        if not rename_vertices:
    566603            return [Simplex(x) for x in lattice_paths(self.tuple(), other.tuple())]
    class Simplex(SageObject): 
    574611
    575612    def __cmp__(self, other):
    576613        """
    577         Return True iff this simplex is the same as ``other``: that
     614        Return ``True`` iff this simplex is the same as ``other``: that
    578615        is, if the vertices of the two are the same, even with a
    579616        different ordering
    580617
    class SimplicialComplex(GenericCellCompl 
    643680    r"""
    644681    Define a simplicial complex.
    645682
    646     :param vertex_set: set of vertices
    647683    :param maximal_faces: set of maximal faces
    648     :param vertex_check: see below
    649     :type vertex_check: boolean; optional, default True
    650684    :param maximality_check: see below
    651     :type maximality_check: boolean; optional, default True
     685    :type maximality_check: boolean; optional, default ``True``
    652686    :param sort_facets: see below
    653     :type sort_facets: boolean; optional, default True
     687    :type sort_facets: boolean; optional, default ``True``
    654688    :param name_check: see below
    655     :type name_check: boolean; optional, default False
     689    :type name_check: boolean; optional, default ``False``
     690    :param is_mutable: Set to ``False`` to make this immutable
     691    :type is_mutable: boolean; optional, default ``True``
    656692    :return: a simplicial complex
    657693
    658     ``vertex_set`` may be a non-negative integer `n` (in which case
    659     the simplicial complex will have `n+1` vertices `\{0, 1, ...,
    660     n\}`), or it may be anything which may be converted to a tuple.
    661     Call the elements of this 'vertices'.
    662 
    663694    ``maximal_faces`` should be a list or tuple or set (indeed,
    664695    anything which may be converted to a set) whose elements are lists
    665696    (or tuples, etc.) of vertices.  Maximal faces are also known as
    666697    'facets'.
    667698
    668     If ``vertex_check`` is True, check to see that each given maximal
    669     face is a subset of the vertex set. Raise an error for any bad
    670     face.
    671 
    672     If ``maximality_check`` is True, check that each maximal face is,
     699    If ``maximality_check`` is ``True``, check that each maximal face is,
    673700    in fact, maximal. In this case, when producing the internal
    674701    representation of the simplicial complex, omit those that are not.
    675     It is highly recommended that this be True; various methods for
     702    It is highly recommended that this be ``True``; various methods for
    676703    this class may fail if faces which are claimed to be maximal are
    677704    in fact not.
    678705
    679     If ``sort_facets`` is True, sort the vertices in each facet.  If
     706    If ``sort_facets`` is ``True``, sort the vertices in each facet.  If
    680707    the vertices in different facets are not ordered compatibly (e.g.,
    681     if you have facets (1, 3, 5) and (5, 3, 8)), then homology
     708    if you have facets ``(1, 3, 5)`` and ``(5, 3, 8)``), then homology
    682709    calculations may have unpredictable results.
    683710
    684     If ``name_check`` is True, check the names of the vertices to see
     711    If ``name_check`` is ``True``, check the names of the vertices to see
    685712    if they can be easily converted to generators of a polynomial ring
    686713    -- use this if you plan to use the Stanley-Reisner ring for the
    687714    simplicial complex.
    688715
    689     .. note::
    690 
    691        The elements of ``vertex_set`` are not automatically in the
    692        simplicial complex: each one is only included if it is a vertex
    693        of at least one of the specified facets.
    694 
    695716    EXAMPLES::
    696717
    697         sage: SimplicialComplex(4, [[1,2], [1,4]])
    698         Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {(1, 2), (1, 4)}
    699         sage: SimplicialComplex(3, [[0,2], [0,3], [0]])
    700         Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2), (0, 3)}
    701         sage: SimplicialComplex(3, [[0,2], [0,3], [0]], maximality_check=False)
    702         Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2), (0, 3), (0,)}
    703         sage: S = SimplicialComplex(['a', 'b', 'c'], (('a', 'b'), ('a', 'c'), ('b', 'c')))
     718        sage: SimplicialComplex([[1,2], [1,4]])
     719        Simplicial complex with vertex set (1, 2, 4) and facets {(1, 2), (1, 4)}
     720        sage: SimplicialComplex([[0,2], [0,3], [0]])
     721        Simplicial complex with vertex set (0, 2, 3) and facets {(0, 2), (0, 3)}
     722        sage: SimplicialComplex([[0,2], [0,3], [0]], maximality_check=False)
     723        Simplicial complex with vertex set (0, 2, 3) and facets {(0, 2), (0, 3), (0,)}
     724        sage: S = SimplicialComplex((('a', 'b'), ['a', 'c'], ('b', 'c')))
    704725        sage: S
    705726        Simplicial complex with vertex set ('a', 'b', 'c') and facets {('b', 'c'), ('a', 'c'), ('a', 'b')}
    706727
    class SimplicialComplex(GenericCellCompl 
    731752
    732753    TESTS::
    733754
    734         sage: S = SimplicialComplex(['a', 'b', 'c'], (('a', 'b'), ('a', 'c'), ('b', 'c')))
     755        sage: S = SimplicialComplex((('a', 'b'), ('a', 'c'), ('b', 'c')))
    735756        sage: S == loads(dumps(S))
    736757        True
    737758        """
    738     def __init__(self, vertex_set=[], maximal_faces=[], **kwds):
     759    def __init__(self, vertex_set=None, maximal_faces=None, **kwds):
    739760        """
    740761        Define a simplicial complex.  See ``SimplicialComplex`` for more
    741762        documentation.
    742763
     764        .. WARNING::
     765
     766            We are deprecating the option ``vertex_set`` in :trac:`12587`.
     767
    743768        EXAMPLES::
    744769
    745             sage: SimplicialComplex(3, [[0,2], [0,3], [0]])
    746             Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2), (0, 3)}
    747             sage: SimplicialComplex(['a', 'b', 'c'], (('a', 'b'), ('a', 'c'), ('b', 'c')))
    748             Simplicial complex with vertex set ('a', 'b', 'c') and facets {('b', 'c'), ('a', 'c'), ('a', 'b')}           
     770            sage: SimplicialComplex([[0,2], [0,3], [0]])
     771            Simplicial complex with vertex set (0, 2, 3) and facets {(0, 2), (0, 3)}
     772            sage: SimplicialComplex((('a', 'b'), ('a', 'c'), ('b', 'c')))
     773            Simplicial complex with vertex set ('a', 'b', 'c') and facets {('b', 'c'), ('a', 'c'), ('a', 'b')}
     774
     775        TESTS::
     776
     777            sage: S = SimplicialComplex([[1,4], [2,4]])
     778            sage: S2 = SimplicialComplex([[1,4], [2,4]], is_mutable=False)
     779            sage: S == S2
     780            True
     781            sage: S3 = SimplicialComplex(maximal_faces=[[1,4], [2,4]])
     782            sage: S == S3
     783            True
    749784        """
    750785        from sage.misc.misc import union
    751786        # process kwds
    752787        sort_facets = kwds.get('sort_facets', True)
    753         vertex_check = kwds.get('vertex_check', True)
    754788        maximality_check = kwds.get('maximality_check', True)
    755789        name_check = kwds.get('name_check', False)
    756         # done with kwds
    757         #
    758         # if there are no maximal faces, perhaps the vertex_set was
    759         # omitted.  Check to see if it is a list (or tuple) of lists
    760         # (or tuples or simplices) , and if so, use that for
    761         # 'maximal_faces', and use the union of all of the vertices for
    762         # 'vertex_set'.
    763         if maximal_faces == []:
    764             C = None
    765             if isinstance(vertex_set, (list, tuple)) and isinstance(vertex_set[0], (list, tuple, Simplex)):
    766                 maximal_faces = vertex_set
    767                 vertex_set = reduce(union, vertex_set)
    768             elif isinstance(vertex_set, SimplicialComplex):
    769                 C = vertex_set
    770             else:
    771                 try:
    772                     C = vertex_set._simplicial_()
    773                 except AttributeError:
    774                     pass
    775             if C is not None:
    776                 self._vertex_set = copy(C.vertices())
    777                 self._facets = list(C.facets())
    778                 self._faces = copy(C._faces)
    779                 self._gen_dict = copy(C._gen_dict)
    780                 self._complex = copy(C._complex)
    781                 self.__contractible = copy(C.__contractible)
    782                 self.__enlarged = copy(C.__enlarged)
    783                 self._graph = copy(C._graph)
    784                 self._numeric = C._numeric
    785                 self._numeric_translation = copy(C._numeric_translation)
    786                 return
     790        # done with kwds except mutability
     791
     792        # For deprecation #12587
     793        if maximal_faces is None:
     794            maximal_faces = vertex_set
     795        elif vertex_set is not None:
     796            # We've passed in both vertex_set and maximal_faces
     797            from sage.misc.superseded import deprecation
     798            deprecation(12587, "vertex_set is deprecated.")
     799
     800        if 'vertex_check' in kwds:
     801            from sage.misc.superseded import deprecation
     802            deprecation(12587, "vertex_check is deprecated.")
     803
     804        C = None
     805        if maximal_faces is None:
     806            vertex_set = []
     807            maximal_faces = []
     808        elif isinstance(maximal_faces, SimplicialComplex):
     809            C = maximal_faces
     810        else:
     811            try:
     812                C = maximal_faces._simplicial_()
     813            except AttributeError:
     814                if not isinstance(maximal_faces, (list, tuple, Simplex)):
     815                    # Convert it into a list (in case it is an iterable)
     816                    maximal_faces = list(maximal_faces)
     817                if len(maximal_faces) != 0:
     818                    vertex_set = reduce(union, maximal_faces)
     819        if C is not None:
     820            self._vertex_set = copy(C.vertices())
     821            self._facets = list(C.facets())
     822            self._faces = copy(C._faces)
     823            self._gen_dict = copy(C._gen_dict)
     824            self._complex = copy(C._complex)
     825            self.__contractible = copy(C.__contractible)
     826            self.__enlarged = copy(C.__enlarged)
     827            self._graph = copy(C._graph)
     828            self._numeric = C._numeric
     829            self._numeric_translation = copy(C._numeric_translation)
     830            self._is_mutable = C._is_mutable
     831            return
    787832
    788833        if sort_facets:
    789834            try:  # vertex_set is an iterable
    class SimplicialComplex(GenericCellCompl 
    812857        good_faces = []
    813858        maximal_simplices = [Simplex(f) for f in maximal_faces]
    814859        for face in maximal_simplices:
    815             # check whether vertices of each face are contained in vertex set
    816             if vertex_check:
    817                 if not face.is_face(vertices):
    818                     raise ValueError, "The face %s is not a subset of the vertex set." % face
    819860            # check whether each given face is actually maximal
    820861            face_is_maximal = True
    821862            if maximality_check:
    class SimplicialComplex(GenericCellCompl 
    872913            d = zip(vertices, range(len(tuple(vertices))))
    873914        self._numeric = numeric
    874915        self._numeric_translation = d
     916       
     917        # Handle mutability keywords
     918        self._is_mutable = True
     919        if not kwds.get('is_mutable', True) or kwds.get('is_immutable', False):
     920            self.set_immutable()
     921
     922    def __hash__(self):
     923        """
     924        Compute the hash value of ``self``.
     925
     926        If this simplicial complex is immutable, it computes the hash value
     927        based upon the facets. Otherwise it raises a ``ValueError``.
     928
     929        EXAMPLES::
     930
     931            sage: S = SimplicialComplex([[1,4], [2,4]])
     932            sage: hash(S)
     933            Traceback (most recent call last):
     934            ...
     935            ValueError: This simplicial complex must be immutable. Call set_immutable().
     936            sage: S.set_immutable()
     937            sage: hash(S) == hash(S)
     938            True
     939            sage: S2 = SimplicialComplex([[1,4], [2,4]], is_mutable=False)
     940            sage: S == S2
     941            True
     942            sage: hash(S) == hash(S2)
     943            True
     944        """
     945        if self._is_mutable:
     946            raise ValueError("This simplicial complex must be immutable. Call set_immutable().")
     947        return hash(self._facets)
    875948
    876949    def __cmp__(self,right):
    877950        """
    class SimplicialComplex(GenericCellCompl 
    880953
    881954        EXAMPLES::
    882955
    883             sage: SimplicialComplex(4, [[1,2], [2,3], [4]]) == SimplicialComplex(4, [[4], [2,3], [3], [2,1]])
     956            sage: SimplicialComplex([[1,2], [2,3], [4]]) == SimplicialComplex([[4], [2,3], [3], [2,1]])
    884957            True
    885             sage: X = SimplicialComplex(4)
     958            sage: X = SimplicialComplex()
    886959            sage: X.add_face([1,3])
    887             sage: X == SimplicialComplex(4, [[1,3]])
     960            sage: X == SimplicialComplex([[1,3]])
    888961            True
    889962        """
    890         if (self.vertices() == right.vertices() and
    891             set(self._facets) == set(right._facets)):
     963        if set(self._facets) == set(right._facets):
    892964            return 0
    893965        else:
    894966            return -1
    class SimplicialComplex(GenericCellCompl 
    899971
    900972        EXAMPLES::
    901973
    902             sage: S = SimplicialComplex(15, [[0,1], [1,2]])
     974            sage: S = SimplicialComplex([[i] for i in range(16)] + [[0,1], [1,2]])
    903975            sage: S
    904             Simplicial complex with 16 vertices and facets {(1, 2), (0, 1)}
     976            Simplicial complex with 16 vertices and 15 facets
    905977            sage: S.vertices()
    906978            (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
    907979
    class SimplicialComplex(GenericCellCompl 
    922994
    923995        EXAMPLES::
    924996
    925             sage: Y = SimplicialComplex(5, [[0,2], [1,4]])
     997            sage: Y = SimplicialComplex([[0,2], [1,4]])
    926998            sage: Y.maximal_faces()
    927999            {(1, 4), (0, 2)}
    9281000
    9291001        ``facets`` is a synonym for ``maximal_faces``::
    9301002
    931             sage: S = SimplicialComplex(2, [[0,1], [0,1,2]])
     1003            sage: S = SimplicialComplex([[0,1], [0,1,2]])
    9321004            sage: S.facets()
    9331005            {(0, 1, 2)}
    9341006        """
    class SimplicialComplex(GenericCellCompl 
    9461018        :param subcomplex: a subcomplex of this simplicial complex.
    9471019            Return faces which are not in this subcomplex.
    9481020
    949         :type subcomplex: optional, default None
     1021        :type subcomplex: optional, default ``None``
    9501022
    9511023        EXAMPLES::
    9521024
    953             sage: Y = SimplicialComplex(5, [[1,2], [1,4]])
     1025            sage: Y = SimplicialComplex([[1,2], [1,4]])
    9541026            sage: Y.faces()
    9551027            {0: set([(4,), (2,), (1,)]), 1: set([(1, 2), (1, 4)]), -1: set([()])}
    956             sage: L = SimplicialComplex(5, [[1,2]])
     1028            sage: L = SimplicialComplex([[1,2]])
    9571029            sage: Y.faces(subcomplex=L)
    9581030            {0: set([(4,)]), 1: set([(1, 4)]), -1: set([])}
    9591031        """
     1032        # Make the subcomplex immutable if it is not
     1033        if subcomplex is not None and subcomplex._is_mutable:
     1034            subcomplex = SimplicialComplex(subcomplex._facets, maximality_check=False,
     1035                                           sort_facets=False, is_mutable=False)
     1036
    9601037        if subcomplex not in self._faces:
    9611038            # Faces is the dictionary of faces in self but not in
    9621039            # subcomplex, indexed by dimension
    class SimplicialComplex(GenericCellCompl 
    9941071
    9951072    def n_faces(self, n, subcomplex=None):
    9961073        """
    997         The set of simplices of dimension n of this simplicial complex.
     1074        The set of simplices of dimension ``n`` of this simplicial complex.
    9981075        If the optional argument ``subcomplex`` is present, then
    9991076        return the ``n``-dimensional faces which are *not* in the
    10001077        subcomplex.
    class SimplicialComplex(GenericCellCompl 
    10031080        :param subcomplex: a subcomplex of this simplicial complex.
    10041081           Return ``n``-dimensional faces which are not in this
    10051082           subcomplex.
    1006         :type subcomplex: optional, default None
     1083        :type subcomplex: optional, default ``None``
    10071084
    10081085        EXAMPLES::
    10091086
    10101087            sage: S = Set(range(1,5))
    1011             sage: Z = SimplicialComplex(S, S.subsets())
     1088            sage: Z = SimplicialComplex(S.subsets())
    10121089            sage: Z
    10131090            Simplicial complex with vertex set (1, 2, 3, 4) and facets {(1, 2, 3, 4)}
    10141091            sage: Z.n_faces(2)
    10151092            set([(1, 3, 4), (1, 2, 3), (2, 3, 4), (1, 2, 4)])
    1016             sage: K = SimplicialComplex(S, [[1,2,3], [2,3,4]])
     1093            sage: K = SimplicialComplex([[1,2,3], [2,3,4]])
    10171094            sage: Z.n_faces(2, subcomplex=K)
    10181095            set([(1, 3, 4), (1, 2, 4)])
    10191096        """
    class SimplicialComplex(GenericCellCompl 
    10241101
    10251102    def is_pure(self):
    10261103        """
    1027         True iff this simplicial complex is pure: a simplicial complex
    1028         is pure iff all of its maximal faces have the same dimension.
    1029 
    1030         .. warning::
    1031        
     1104        Return ``True`` iff this simplicial complex is pure.
     1105
     1106        A simplicial complex is pure if and only if all of its maximal faces
     1107        have the same dimension.
     1108
     1109        .. WARNING::
     1110
    10321111           This may give the wrong answer if the simplicial complex
    1033            was constructed with ``maximality_check`` set to False.
     1112           was constructed with ``maximality_check`` set to ``False``.
    10341113
    10351114        EXAMPLES::
    10361115
    1037             sage: U = SimplicialComplex(5, [[1,2], [1, 3, 4]])
     1116            sage: U = SimplicialComplex([[1,2], [1, 3, 4]])
    10381117            sage: U.is_pure()
    10391118            False
    1040             sage: X = SimplicialComplex(3, [[0,1], [0,2], [1,2]])
     1119            sage: X = SimplicialComplex([[0,1], [0,2], [1,2]])
    10411120            sage: X.is_pure()
    10421121            True
     1122
     1123        Demonstration of the warning::
     1124
     1125            sage: S = SimplicialComplex([[0,1], [0]], maximality_check=False)
     1126            sage: S.is_pure()
     1127            False
    10431128        """
    10441129        dims = [face.dimension() for face in self._facets]
    10451130        return max(dims) == min(dims)
    class SimplicialComplex(GenericCellCompl 
    10531138        empy simplex), then the `h`-vector `(h_0, h_1, ..., h_d,
    10541139        h_{d+1})` is defined by
    10551140
    1056         .. math::
     1141        .. MATH::
    10571142
    10581143           \sum_{i=0}^{d+1} h_i x^{d+1-i} = \sum_{i=0}^{d+1} f_{i-1} (x-1)^{d+1-i}.
    10591144
    10601145        Alternatively,
    10611146
    1062         .. math::
     1147        .. MATH::
    10631148
    10641149           h_j = \sum_{i=-1}^{j-1} (-1)^{j-i-1} \binom{d-i}{j-i-1} f_i.
    10651150
    class SimplicialComplex(GenericCellCompl 
    11731258        g = Graph([V,E])
    11741259        return g.is_connected()
    11751260
    1176     def product(self, right, rename_vertices=True):
     1261    def product(self, right, rename_vertices=True, is_mutable=True):
    11771262        """
    11781263        The product of this simplicial complex with another one.
    11791264
    class SimplicialComplex(GenericCellCompl 
    11831268        :param rename_vertices: If this is False, then the vertices in
    11841269           the product are the set of ordered pairs `(v,w)` where `v`
    11851270           is a vertex in ``self`` and `w` is a vertex in
    1186            ``right``. If this is True, then the vertices are renamed
     1271           ``right``. If this is ``True``, then the vertices are renamed
    11871272           as "LvRw" (e.g., the vertex (1,2) would become "L1R2").
    11881273           This is useful if you want to define the Stanley-Reisner
    11891274           ring of the complex: vertex names like (0,1) are not
    11901275           suitable for that, while vertex names like "L0R1" are.
    11911276
    1192         :type rename_vertices: boolean; optional, default True
     1277        :type rename_vertices: boolean; optional, default ``True``
     1278
     1279        :param is_mutable: Determines if the output is mutable
     1280        :type is_mutable: boolean; optional, default ``True``
    11931281
    11941282        The vertices in the product will be the set of ordered pairs
    11951283        `(v,w)` where `v` is a vertex in self and `w` is a vertex in
    11961284        right.
    11971285
    1198         .. warning::
     1286        .. WARNING::
    11991287
    12001288           If ``X`` and ``Y`` are simplicial complexes, then ``X*Y``
    12011289           returns their join, not their product.
    12021290
    12031291        EXAMPLES::
    12041292
    1205             sage: S = SimplicialComplex(3, [[0,1], [1,2], [0,2]]) # circle
    1206             sage: K = SimplicialComplex(1, [[0,1]])   # edge
     1293            sage: S = SimplicialComplex([[0,1], [1,2], [0,2]]) # circle
     1294            sage: K = SimplicialComplex([[0,1]])   # edge
    12071295            sage: S.product(K).vertices()  # cylinder
    1208             ('L0R0', 'L0R1', 'L1R0', 'L1R1', 'L2R0', 'L2R1', 'L3R0', 'L3R1')
     1296            ('L0R0', 'L0R1', 'L1R0', 'L1R1', 'L2R0', 'L2R1')
    12091297            sage: S.product(K, rename_vertices=False).vertices()
    1210             ((0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1), (3, 0), (3, 1))
     1298            ((0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1))
    12111299            sage: T = S.product(S)  # torus
    12121300            sage: T
    1213             Simplicial complex with 16 vertices and 18 facets
     1301            Simplicial complex with 9 vertices and 18 facets
    12141302            sage: T.homology()
    12151303            {0: 0, 1: Z x Z, 2: Z}
    12161304
    class SimplicialComplex(GenericCellCompl 
    12231311            sage: T.product(K)      # long time: 5 or 6 seconds
    12241312            Simplicial complex with 56 vertices and 1344 facets
    12251313        """
    1226         vertices = []
    1227         for v in self.vertices():
    1228             for w in right.vertices():
    1229                 if rename_vertices:
    1230                     vertices.append("L" + str(v) + "R" + str(w))
    1231                 else:
    1232                     vertices.append((v,w))
    12331314        facets = []
    12341315        for f in self._facets:
    12351316            for g in right._facets:
    12361317                facets.extend(f.product(g, rename_vertices))
    1237         return SimplicialComplex(vertices, facets)
    1238 
    1239     def join(self, right, rename_vertices=True):
     1318        return SimplicialComplex(facets, is_mutable=is_mutable)
     1319
     1320    def join(self, right, rename_vertices=True, is_mutable=True):
    12401321        """
    12411322        The join of this simplicial complex with another one.
    12421323
    class SimplicialComplex(GenericCellCompl 
    12551336           the vertices; this will cause problems if the two factors
    12561337           have any vertices with names in common.
    12571338
    1258         :type rename_vertices: boolean; optional, default True
     1339        :type rename_vertices: boolean; optional, default ``True``
     1340
     1341        :param is_mutable: Determines if the output is mutable
     1342        :type is_mutable: boolean; optional, default ``True``
    12591343
    12601344        EXAMPLES::
    12611345       
    1262             sage: S = SimplicialComplex(1, [[0], [1]])
    1263             sage: T = SimplicialComplex([2, 3], [[2], [3]])
     1346            sage: S = SimplicialComplex([[0], [1]])
     1347            sage: T = SimplicialComplex([[2], [3]])
    12641348            sage: S.join(T)
    12651349            Simplicial complex with vertex set ('L0', 'L1', 'R2', 'R3') and 4 facets
    12661350            sage: S.join(T, rename_vertices=False)
    class SimplicialComplex(GenericCellCompl 
    12731357            sage: S * S * S * S * S * S * S * S
    12741358            Simplicial complex with 16 vertices and 256 facets
    12751359        """
    1276         if rename_vertices:
    1277             vertex_set = (["L" + str(v) for v in self.vertices()]
    1278                           + ["R" + str(w) for w in right.vertices()])
    1279         else:
    1280             vertex_set = tuple(self._vertex_set) + tuple(right.vertices())
    12811360        facets = []
    12821361        for f in self._facets:
    12831362            for g in right._facets:
    12841363                facets.append(f.join(g, rename_vertices))
    1285         return SimplicialComplex(vertex_set, facets)
     1364        return SimplicialComplex(facets, is_mutable=is_mutable)
    12861365
    12871366    # Use * to mean 'join':
    12881367    __mul__ = join
    12891368
    1290     def cone(self):
     1369    def cone(self, is_mutable=True):
    12911370        """
    12921371        The cone on this simplicial complex.
    12931372
     1373        :param is_mutable: Determines if the output is mutable
     1374        :type is_mutable: boolean; optional, default ``True``
     1375
    12941376        The cone is the simplicial complex formed by adding a new
    12951377        vertex `C` and simplices of the form `[C, v_0, ..., v_k]` for
    12961378        every simplex `[v_0, ..., v_k]` in the original simplicial
    class SimplicialComplex(GenericCellCompl 
    12981380        complex with a one-point simplicial complex.
    12991381
    13001382        EXAMPLES::
    1301        
    1302             sage: S = SimplicialComplex(1, [[0], [1]])
     1383
     1384            sage: S = SimplicialComplex([[0], [1]])
    13031385            sage: S.cone()
    13041386            Simplicial complex with vertex set ('L0', 'L1', 'R0') and facets {('L0', 'R0'), ('L1', 'R0')}
    13051387        """
    1306         return self.join(SimplicialComplex(["0"], [["0"]]),
     1388        return self.join(SimplicialComplex([["0"]], is_mutable=is_mutable),
    13071389                         rename_vertices = True)
    13081390
    1309     def suspension(self, n=1):
     1391    def suspension(self, n=1, is_mutable=True):
    13101392        r"""
    13111393        The suspension of this simplicial complex.
    13121394
    class SimplicialComplex(GenericCellCompl 
    13141396
    13151397        :type n: optional, default 1
    13161398
     1399        :param is_mutable: Determines if the output is mutable
     1400        :type is_mutable: boolean; optional, default ``True``
     1401
    13171402        The suspension is the simplicial complex formed by adding two
    13181403        new vertices `S_0` and `S_1` and simplices of the form `[S_0,
    13191404        v_0, ..., v_k]` and `[S_1, v_0, ..., v_k]` for every simplex
    class SimplicialComplex(GenericCellCompl 
    13401425
    13411426        EXAMPLES::
    13421427
    1343             sage: S0 = SimplicialComplex(1, [[0], [1]])
     1428            sage: S0 = SimplicialComplex([[0], [1]])
    13441429            sage: S0.suspension() == simplicial_complexes.Sphere(1)
    13451430            True
    13461431            sage: S3 = S0.suspension(3)  # the 3-sphere
    class SimplicialComplex(GenericCellCompl 
    13801465                    new_facets.append(f.join(w, rename_vertices=False))
    13811466                return SimplicialComplex(new_facets)
    13821467            else:
    1383                 return self.join(SimplicialComplex(["0", "1"], [["0"], ["1"]]),
     1468                return self.join(SimplicialComplex(["0", "1"], [["0"], ["1"]], is_mutable=is_mutable),
    13841469                                 rename_vertices = True)
    1385         return self.suspension().suspension(int(n-1))
    1386 
    1387     def disjoint_union(self, right, rename_vertices=True):
     1470        return self.suspension(is_mutable).suspension(int(n-1), is_mutable)
     1471
     1472    def disjoint_union(self, right, rename_vertices=True, is_mutable=True):
    13881473        """
    13891474        The disjoint union of this simplicial complex with another one.
    13901475
    class SimplicialComplex(GenericCellCompl 
    14081493            sage: S1.disjoint_union(S2).homology()
    14091494            {0: Z, 1: Z, 2: Z}
    14101495        """
    1411         if rename_vertices:
    1412             vertex_set = (["L" + str(v) for v in self.vertices()]
    1413                           + ["R" + str(w) for w in right.vertices()])
    1414         else:
    1415             vertex_set = tuple(self._vertex_set) + tuple(right.vertices())
    14161496        facets = []
    14171497        for f in self._facets:
    14181498            facets.append(tuple(["L" + str(v) for v in f]))
    14191499        for f in right._facets:
    14201500            facets.append(tuple(["R" + str(v) for v in f]))
    1421         return SimplicialComplex(vertex_set, facets)
    1422 
    1423     def wedge(self, right, rename_vertices=True):
     1501        return SimplicialComplex(facets, is_mutable=is_mutable)
     1502
     1503    def wedge(self, right, rename_vertices=True, is_mutable=True):
    14241504        """
    14251505        The wedge (one-point union) of this simplicial complex with
    14261506        another one.
    14271507
    14281508        :param right: the other simplicial complex (the right-hand factor)
    14291509
    1430         :param rename_vertices: If this is True, the vertices in the
     1510        :param rename_vertices: If this is ``True``, the vertices in the
    14311511           wedge will be renamed by the formula: first vertex in each
    14321512           are glued together and called "0".  Otherwise, each vertex
    14331513           "v" in the left-hand factor --> vertex "Lv" in the wedge,
    14341514           vertex "w" in the right-hand factor --> vertex "Rw" in the
    1435            wedge.  If this is false, this tries to construct the wedge
     1515           wedge.  If this is ``False``, this tries to construct the wedge
    14361516           without renaming the vertices; this will cause problems if
    14371517           the two factors have any vertices with names in common.
    14381518
    1439         :type rename_vertices: boolean; optional, default True
    1440 
    1441         .. note::
     1519        :type rename_vertices: boolean; optional, default ``True``
     1520
     1521        :param is_mutable: Determines if the output is mutable
     1522        :type is_mutable: boolean; optional, default ``True``
     1523
     1524        .. NOTE::
    14421525
    14431526            This operation is not well-defined if ``self`` or
    14441527            ``other`` is not path-connected.
    1445        
     1528
    14461529        EXAMPLES::
    14471530
    14481531            sage: S1 = simplicial_complexes.Sphere(1)
    class SimplicialComplex(GenericCellCompl 
    14571540        left_dict = {left_0: 0}
    14581541        right_dict = {right_0: 0}
    14591542        if rename_vertices:
    1460             vertex_set = ([0] + ["L" + str(v) for v in left_vertices]
    1461                           + ["R" + str(w) for w in right_vertices])
     1543            facets = []
    14621544            for v in left_vertices:
    14631545                left_dict[v] = "L" + str(v)
    14641546            for v in right_vertices:
    14651547                right_dict[v] = "R" + str(v)
    1466         else:
    1467             vertex_set = (0,) + tuple(left_vertices) + tuple(right_vertices)
    1468         if rename_vertices:
    1469             facets = []
     1548
    14701549            for f in self._facets:
    14711550                facets.append(tuple([left_dict[v] for v in f]))
    14721551            for f in right._facets:
    14731552                facets.append(tuple([right_dict[v] for v in f]))
    14741553        else:
    14751554            facets = self._facets + right._facets
    1476         return SimplicialComplex(vertex_set, facets)
     1555        return SimplicialComplex(facets, is_mutable=is_mutable)
    14771556
    14781557    def chain_complex(self, **kwds):
    14791558        """
    14801559        The chain complex associated to this simplicial complex.
    14811560
    1482         :param dimensions: if None, compute the chain complex in all
     1561        :param dimensions: if ``None``, compute the chain complex in all
    14831562           dimensions.  If a list or tuple of integers, compute the
    14841563           chain complex in those dimensions, setting the chain groups
    14851564           in all other dimensions to zero.
    14861565        :param base_ring: commutative ring
    1487         :type base_ring: optional, default ZZ
     1566        :type base_ring: optional, default ``ZZ``
    14881567        :param subcomplex: a subcomplex of this simplicial complex.
    14891568           Compute the chain complex relative to this subcomplex.
    14901569        :type subcomplex: optional, default empty
    1491         :param augmented: If True, return the augmented chain complex
     1570        :param augmented: If ``True``, return the augmented chain complex
    14921571           (that is, include a class in dimension `-1` corresponding
    14931572           to the empty cell).  This is ignored if ``dimensions`` is
    14941573           specified.
    1495         :type augmented: boolean; optional, default False
    1496         :param cochain: If True, return the cochain complex (that is,
     1574        :type augmented: boolean; optional, default ``False``
     1575        :param cochain: If ``True``, return the cochain complex (that is,
    14971576           the dual of the chain complex).
    1498         :type cochain: boolean; optional, default False
    1499         :param verbose: If True, print some messages as the chain
     1577        :type cochain: boolean; optional, default ``False``
     1578        :param verbose: If ``True``, print some messages as the chain
    15001579           complex is computed.
    1501         :type verbose: boolean; optional, default False
    1502         :param check_diffs: If True, make sure that the chain complex
     1580        :type verbose: boolean; optional, default ``False``
     1581        :param check_diffs: If ``True``, make sure that the chain complex
    15031582           is actually a chain complex: the differentials are
    15041583           composable and their product is zero.
    1505         :type check_diffs: boolean; optional, default False
    1506 
    1507         .. note::
     1584        :type check_diffs: boolean; optional, default ``False``
     1585
     1586        .. NOTE::
    15081587
    15091588           If subcomplex is nonempty, then the argument ``augmented``
    15101589           has no effect: the chain complex relative to a nonempty
    class SimplicialComplex(GenericCellCompl 
    15121591
    15131592        EXAMPLES::
    15141593
    1515             sage: circle = SimplicialComplex(2, [[0,1], [1,2], [0, 2]])
     1594            sage: circle = SimplicialComplex([[0,1], [1,2], [0, 2]])
    15161595            sage: circle.chain_complex()
    15171596            Chain complex with at most 2 nonzero terms over Integer Ring
    15181597            sage: circle.chain_complex()._latex_()
    class SimplicialComplex(GenericCellCompl 
    15301609
    15311610        # initialize subcomplex
    15321611        if subcomplex is None:
    1533             subcomplex = SimplicialComplex(self.vertices())
     1612            subcomplex = SimplicialComplex(is_mutable=False)
    15341613        else:
    15351614            # subcomplex is not empty, so don't augment the chain complex
    15361615            augmented = False
     1616            # Use an immutable copy of the subcomplex
     1617            if not subcomplex._is_mutable:
     1618                subcomplex = SimplicialComplex(subcomplex._facets, maximality_check=False,
     1619                                               sort_facets=False, is_mutable=False)
    15371620        # now construct the range of dimensions in which to compute
    15381621        if dimensions is None:
    15391622            dimensions = range(0, self.dimension()+1)
    class SimplicialComplex(GenericCellCompl 
    16341717        """
    16351718        The reduced homology of this simplicial complex.
    16361719
    1637         :param dim: If None, then return the homology in every
     1720        :param dim: If ``None``, then return the homology in every
    16381721           dimension.  If ``dim`` is an integer or list, return the
    16391722           homology in the given dimensions.  (Actually, if ``dim`` is
    16401723           a list, return the homology in the range from ``min(dim)``
    16411724           to ``max(dim)``.)
    16421725
    1643         :type dim: integer or list of integers or None; optional,
    1644                    default None
    1645 
    1646         :param base_ring: commutative ring. Must be ZZ or a field.
     1726        :type dim: integer or list of integers or ``None``; optional,
     1727                   default ``None``
     1728
     1729        :param base_ring: commutative ring. Must be ``ZZ`` or a field.
    16471730       
    1648         :type base_ring: optional, default ZZ
     1731        :type base_ring: optional, default ``ZZ``
    16491732
    16501733        :param subcomplex: a subcomplex of this simplicial complex.
    16511734           Compute homology relative to this subcomplex.
    16521735
    1653         :type subcomplex: optional, default None
    1654 
    1655         :param cohomology: If True, compute cohomology rather than
     1736        :type subcomplex: optional, default ``None``
     1737
     1738        :param cohomology: If ``True``, compute cohomology rather than
    16561739           homology.
    16571740
    1658         :type cohomology: boolean; optional, default False
    1659 
    1660         :param enlarge: If True, find a new subcomplex homotopy
     1741        :type cohomology: boolean; optional, default ``False``
     1742
     1743        :param enlarge: If ``True``, find a new subcomplex homotopy
    16611744           equivalent to, and probably larger than, the given one.
    16621745
    1663         :type enlarge: boolean; optional, default True
    1664 
    1665         :param algorithm: The options are 'auto', 'dhsw', 'pari' or
    1666            'no_chomp'.  If 'auto', first try CHomP, then use the
    1667            Dumas, Heckenbach, Saunders, and Welker elimination
     1746        :type enlarge: boolean; optional, default ``True``
     1747
     1748        :param algorithm: The options are ``'auto'``, ``'dhsw'``,
     1749           ``'pari'`` or  ``'no_chomp'``.  If ``'auto'``, first try CHomP,
     1750           then use the Dumas, Heckenbach, Saunders, and Welker elimination
    16681751           algorithm for large matrices, Pari for small ones.  If
    1669            'no_chomp', then don't try CHomP, but behave the same
    1670            otherwise.  If 'pari', then compute elementary divisors
    1671            using Pari.  If 'dhsw', then use the DHSW algorithm to
     1752           ``'no_chomp'``, then don't try CHomP, but behave the same
     1753           otherwise.  If ``'pari'``, then compute elementary divisors
     1754           using Pari.  If ``'dhsw'``, then use the DHSW algorithm to
    16721755           compute elementary divisors.  (As of this writing, CHomP is
    1673            by far the fastest option, followed by the 'auto' or
    1674            'no_chomp' setting of using DHSW for large matrices and
     1756           by far the fastest option, followed by the ``'auto'`` or
     1757           ``'no_chomp'`` setting of using DHSW for large matrices and
    16751758           Pari for small ones.)
    16761759
    1677         :type algorithm: string; optional, default 'auto'
     1760        :type algorithm: string; optional, default ``'auto'``
    16781761       
    1679         :param verbose: If True, print some messages as the homology
     1762        :param verbose: If ``True``, print some messages as the homology
    16801763           is computed.
    16811764
    1682         :type verbose: boolean; optional, default False
    1683 
    1684         Algorithm: if ``subcomplex`` is None, replace it with a facet
     1765        :type verbose: boolean; optional, default ``False``
     1766
     1767        Algorithm: if ``subcomplex`` is ``None``, replace it with a facet
    16851768        -- a contractible subcomplex of the original complex.  Then no
    16861769        matter what ``subcomplex`` is, replace it with a subcomplex
    16871770        `L` which is homotopy equivalent and as large as possible.
    class SimplicialComplex(GenericCellCompl 
    16911774
    16921775        EXAMPLES::
    16931776
    1694             sage: circle = SimplicialComplex(2, [[0,1], [1,2], [0, 2]])
     1777            sage: circle = SimplicialComplex([[0,1], [1,2], [0, 2]])
    16951778            sage: circle._homology_()
    16961779            {0: 0, 1: Z}
    1697             sage: disk = SimplicialComplex(3, [[0,1,2,3]])
    1698             sage: sphere = disk.remove_face([0,1,2,3])
     1780            sage: sphere = SimplicialComplex([[0,1,2,3]])
     1781            sage: sphere.remove_face([0,1,2,3])
    16991782            sage: sphere
    17001783            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)}
    17011784            sage: sphere._homology_()
    class SimplicialComplex(GenericCellCompl 
    17041787        Another way to get a two-sphere: take a two-point space and take its
    17051788        three-fold join with itself::
    17061789       
    1707             sage: S = SimplicialComplex(1, [[0], [1]])
     1790            sage: S = SimplicialComplex([[0], [1]])
    17081791            sage: (S*S*S)._homology_(dim=2, cohomology=True)
    17091792            Z
    17101793
    17111794        Relative homology::
    17121795
    1713             sage: T = SimplicialComplex(2, [[0,1,2]])
    1714             sage: U = SimplicialComplex(2, [[0,1], [1,2], [0,2]])
     1796            sage: T = SimplicialComplex([[0,1,2]])
     1797            sage: U = SimplicialComplex([[0,1], [1,2], [0,2]])
    17151798            sage: T._homology_(subcomplex=U)
    17161799            {0: 0, 1: 0, 2: Z}
    17171800        """
    class SimplicialComplex(GenericCellCompl 
    17471830                    print "Done finding contractible subcomplex."
    17481831                    vec = [len(self.n_faces(n-1, subcomplex=L)) for n in range(self.dimension()+2)]
    17491832                    print "The difference between the f-vectors is:"
    1750                     print "  %s" % vec                   
     1833                    print "  %s" % vec
    17511834            else:
    1752                 L = SimplicialComplex(self.vertices(), [[self.vertices().tuple()[0]]])
     1835                L = SimplicialComplex([[self.vertices().tuple()[0]]])
    17531836        else:
    17541837            if enlarge:
    17551838                if verbose:
    class SimplicialComplex(GenericCellCompl 
    17591842                    print "Done enlarging subcomplex:"
    17601843            else:
    17611844                L = subcomplex
     1845        L.set_immutable()
     1846
    17621847        if verbose:
    17631848            print "Computing the chain complex..."
    17641849        kwds['subcomplex']=L
    class SimplicialComplex(GenericCellCompl 
    18051890
    18061891        EXAMPLES::
    18071892
    1808             sage: X = SimplicialComplex(2, [[0,1], [0,2]])
     1893            sage: X = SimplicialComplex([[0,1], [0,2]])
    18091894            sage: X.add_face([0,1,2,]); X
    18101895            Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}
    1811             sage: Y = SimplicialComplex(3); Y
    1812             Simplicial complex with vertex set (0, 1, 2, 3) and facets {()}
     1896            sage: Y = SimplicialComplex(); Y
     1897            Simplicial complex with vertex set () and facets {()}
    18131898            sage: Y.add_face([0,1])
    18141899            sage: Y.add_face([1,2,3])
    18151900            sage: Y
    class SimplicialComplex(GenericCellCompl 
    18201905            sage: Y.add_face([1,3]); Y
    18211906            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1)}
    18221907        """
     1908        if not self._is_mutable:
     1909            raise ValueError("This simplicial complex is not mutable")
     1910
    18231911        new_face = Simplex(face)
    1824         if not new_face.is_face(self.vertices()):
    1825             raise ValueError, "The face to be added is not a subset of the vertex set."
    1826         else:
    1827             face_is_maximal = True
    1828             for other in self._facets:
    1829                 if face_is_maximal:
    1830                     face_is_maximal = not new_face.is_face(other)
     1912
     1913        face_is_maximal = True
     1914        for other in self._facets:
    18311915            if face_is_maximal:
    1832                 # remove any old facets which are no longer maximal
    1833                 Facets = list(self._facets)
    1834                 for old_face in self._facets:
    1835                     if old_face.is_face(new_face):
    1836                         Facets.remove(old_face)
    1837                 # add new_face to facet list
    1838                 Facets.append(new_face)
    1839                 self._facets = Facets
    1840                 # update self._faces if necessary
    1841                 if None in self._faces:
    1842                     all_new_faces = SimplicialComplex(self.vertices(),
    1843                                                       [new_face]).faces()
    1844                     for dim in range(0, new_face.dimension()+1):
    1845                         if dim in self._faces[None]:
    1846                             self._faces[None][dim] = self._faces[None][dim].union(all_new_faces[dim])
    1847                         else:
    1848                             self._faces[None][dim] = all_new_faces[dim]
    1849                 # update self._graph if necessary
    1850                 if self._graph is None:
    1851                     pass
    1852                 else:
    1853                     d = new_face.dimension()+1
    1854                     for i in range(d):
    1855                         for j in range(i+1,d):
    1856                             self._graph.add_edge(new_face[i],new_face[j])
    1857             return None
     1916                face_is_maximal = not new_face.is_face(other)
     1917        if face_is_maximal:
     1918            # remove any old facets which are no longer maximal
     1919            Facets = list(self._facets)
     1920            for old_face in self._facets:
     1921                if old_face.is_face(new_face):
     1922                    Facets.remove(old_face)
     1923            # add new_face to facet list
     1924            Facets.append(new_face)
     1925            self._facets = Facets
     1926
     1927            # Update the vertex set
     1928            from sage.misc.misc import union
     1929            self._vertex_set = Simplex(reduce(union, [self._vertex_set, new_face]))
     1930
     1931            # update self._faces if necessary
     1932            if None in self._faces:
     1933                all_new_faces = SimplicialComplex([new_face]).faces()
     1934                for dim in range(0, new_face.dimension()+1):
     1935                    if dim in self._faces[None]:
     1936                        self._faces[None][dim] = self._faces[None][dim].union(all_new_faces[dim])
     1937                    else:
     1938                        self._faces[None][dim] = all_new_faces[dim]
     1939            # update self._graph if necessary
     1940            if self._graph is not None:
     1941                d = new_face.dimension()+1
     1942                for i in range(d):
     1943                    for j in range(i+1,d):
     1944                        self._graph.add_edge(new_face[i],new_face[j])
    18581945
    18591946    def remove_face(self, face):
    18601947        """
    class SimplicialComplex(GenericCellCompl 
    18631950
    18641951        :param face: a face of the simplicial complex
    18651952
    1866         Algorithm: the facets of the new simplicial complex are
     1953        This *changes* the simplicial complex.
     1954
     1955        ALGORITHM:
     1956
     1957        The facets of the new simplicial complex are
    18671958        the facets of the original complex not containing ``face``,
    18681959        together with those of ``link(face)*boundary(face)``.
    18691960
    18701961        EXAMPLES::
    18711962
    18721963            sage: S = range(1,5)
    1873             sage: Z = SimplicialComplex(S, [S]); Z
     1964            sage: Z = SimplicialComplex([S]); Z
    18741965            Simplicial complex with vertex set (1, 2, 3, 4) and facets {(1, 2, 3, 4)}
    1875             sage: Z2 = Z.remove_face([1,2])
    1876             sage: Z2
     1966            sage: Z.remove_face([1,2])
     1967            sage: Z
    18771968            Simplicial complex with vertex set (1, 2, 3, 4) and facets {(1, 3, 4), (2, 3, 4)}
    18781969
    1879             sage: S = SimplicialComplex(4,[[0,1,2],[2,3]])
     1970            sage: S = SimplicialComplex([[0,1,2],[2,3]])
    18801971            sage: S
    1881             Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {(0, 1, 2), (2, 3)}
    1882             sage: S2 = S.remove_face([0,1,2])
    1883             sage: S2
    1884             Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {(1, 2), (2, 3), (0, 2), (0, 1)}
     1972            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (2, 3)}
     1973            sage: S.remove_face([0,1,2])
     1974            sage: S
     1975            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2), (2, 3), (0, 2), (0, 1)}
    18851976        """
     1977        if not self._is_mutable:
     1978            raise ValueError("This simplicial complex is not mutable")
     1979
    18861980        simplex = Simplex(face)
    18871981        facets = self.facets()
    18881982        if all([not simplex.is_face(F) for F in facets]):
    class SimplicialComplex(GenericCellCompl 
    18941988            for g in link.facets():
    18951989                join_facets.append(f.join(g, rename_vertices=False))
    18961990        # join_facets is the list of facets in the join bdry(face) * link(face)
    1897         other_facets = [elem for elem in facets if not simplex.is_face(elem)]
    1898         return SimplicialComplex(self.vertices(), join_facets + other_facets)
    1899 
    1900     def connected_sum(self, other):
     1991        remaining = join_facets + [elem for elem in facets if not simplex.is_face(elem)]
     1992
     1993        # Check to see if there are any non-maximial faces
     1994        # build set of facets
     1995        self._facets = []
     1996        for f in remaining:
     1997            face = Simplex(f)
     1998            face_is_maximal = True
     1999            faces_to_be_removed = []
     2000            for other in self._facets:
     2001                if other.is_face(face):
     2002                    faces_to_be_removed.append(other)
     2003                elif face_is_maximal:
     2004                    face_is_maximal = not face.is_face(other)
     2005            for x in faces_to_be_removed:
     2006                self._facets.remove(x)
     2007            face = Simplex(sorted(face.tuple()))
     2008            if face_is_maximal:
     2009                self._facets.append(face)
     2010        # if no maximal faces, add the empty face as a facet
     2011        if len(remaining) == 0:
     2012            self._facets.append(Simplex(-1))
     2013
     2014        # Recreate the vertex set
     2015        from sage.misc.misc import union
     2016        self._vertex_set = Simplex(reduce(union, self._facets))
     2017
     2018        # Update self._faces and self._graph if necessary
     2019        if None in self._faces:
     2020            self._faces = {}
     2021            self.faces()
     2022        if self._graph is not None:
     2023            # Only if removing a 1 or 2 dim face will the graph be affected
     2024            if len(face) == 1:
     2025                self._graph.delete_vertex(face[0])
     2026                self._graph.add_vertex(face[0])
     2027            elif len(face) == 2:
     2028                self._graph.delete_edge(face[0], face[1])
     2029
     2030    def connected_sum(self, other, is_mutable=True):
    19012031        """
    19022032        The connected sum of this simplicial complex with another one.
    1903        
     2033
    19042034        :param other: another simplicial complex
     2035        :param is_mutable: Determines if the output is mutable
     2036        :type is_mutable: boolean; optional, default ``True``
    19052037        :return: the connected sum ``self # other``
    19062038
    1907         .. warning::
    1908 
    1909            This does not check that self and other are manifolds, only
    1910            that their facets all have the same dimension.  Since a
     2039        .. WARNING::
     2040
     2041           This does not check that ``self`` and ``other`` are manifolds,
     2042           only that their facets all have the same dimension.  Since a
    19112043           (more or less) random facet is chosen from each complex and
    19122044           then glued together, this method may return random
    19132045           results if applied to non-manifolds, depending on which
    class SimplicialComplex(GenericCellCompl 
    19312063            Simplicial complex with 9 vertices and 18 facets
    19322064
    19332065        The notation '+' may be used for connected sum, also::
    1934        
     2066
    19352067            sage: P + P    # the Klein bottle
    19362068            Simplicial complex with 9 vertices and 18 facets
    19372069            sage: (P + P).homology()[1]
    class SimplicialComplex(GenericCellCompl 
    19472079        # construct the set of vertices:
    19482080        left = set(self.vertices()).difference(set(keep_left))
    19492081        right = set(other.vertices()).difference(set(keep_right))
    1950         vertex_set = (range(dim+1) + ["L" + str(v) for v in left]
    1951                       + ["R" + str(v) for v in right])
    19522082        # construct the set of facets:
    19532083        left = set(self._facets).difference(set([keep_left]))
    19542084        right = set(other._facets).difference(set([keep_right]))
    class SimplicialComplex(GenericCellCompl 
    19572087                     + [[rename_vertex(v, keep=list(keep_right), left=False)
    19582088                         for v in face] for face in right])
    19592089        # return the new surface
    1960         return SimplicialComplex(vertex_set, facet_set)
     2090        return SimplicialComplex(facet_set, is_mutable=is_mutable)
    19612091
    19622092    __add__ = connected_sum
    19632093
    1964     def link(self, simplex):
     2094    def link(self, simplex, is_mutable=True):
    19652095        """
    19662096        The link of a simplex in this simplicial complex.
    19672097
    class SimplicialComplex(GenericCellCompl 
    19702100        \cup G` is a simplex.
    19712101
    19722102        :param simplex: a simplex in this simplicial complex.
     2103        :param is_mutable: Determines if the output is mutable
     2104        :type is_mutable: boolean; optional, default ``True``
    19732105
    19742106        EXAMPLES::
    19752107
    1976             sage: X = SimplicialComplex(4, [[0,1,2], [1,2,3]])
     2108            sage: X = SimplicialComplex([[0,1,2], [1,2,3]])
    19772109            sage: X.link(Simplex([0]))
    1978             Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {(1, 2)}
     2110            Simplicial complex with vertex set (1, 2) and facets {(1, 2)}
    19792111            sage: X.link([1,2])
    1980             Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {(3,), (0,)}
    1981             sage: Y = SimplicialComplex(3, [[0,1,2,3]])
     2112            Simplicial complex with vertex set (0, 3) and facets {(3,), (0,)}
     2113            sage: Y = SimplicialComplex([[0,1,2,3]])
    19822114            sage: Y.link([1])
    1983             Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3)}
     2115            Simplicial complex with vertex set (0, 2, 3) and facets {(0, 2, 3)}
    19842116        """
    19852117        faces = []
    19862118        s = Simplex(simplex)
    19872119        for f in self._facets:
    19882120            if s.is_face(f):
    19892121                faces.append(Simplex(list(f.set().difference(s.set()))))
    1990         return SimplicialComplex(self.vertices(), faces)
     2122        return SimplicialComplex(faces, is_mutable=is_mutable)
    19912123
    19922124    def effective_vertices(self):
    19932125        """
    1994         The set of vertices belonging to some face. Returns a Simplex.
     2126        The set of vertices belonging to some face. Returns the list of
     2127        vertices.
    19952128
    19962129        EXAMPLES::
    19972130
    1998             sage: S = SimplicialComplex(15)
     2131            sage: S = SimplicialComplex([[0,1,2,3],[6,7]])
    19992132            sage: S
    2000             Simplicial complex with 16 vertices and facets {()}
     2133            Simplicial complex with vertex set (0, 1, 2, 3, 6, 7) and facets {(6, 7), (0, 1, 2, 3)}
    20012134            sage: S.effective_vertices()
    2002             ()
    2003 
    2004             sage: S = SimplicialComplex(15,[[0,1,2,3],[6,7]])
    2005             sage: S
    2006             Simplicial complex with 16 vertices and facets {(6, 7), (0, 1, 2, 3)}
    2007             sage: S.effective_vertices()
     2135            doctest:1: DeprecationWarning: effective_vertices is deprecated. Use vertices instead
     2136            See http://trac.sagemath.org/12587 for details.
    20082137            (0, 1, 2, 3, 6, 7)
    2009 
    2010             sage: type(S.effective_vertices())
    2011             <class 'sage.homology.simplicial_complex.Simplex'>
    2012 
    20132138        """
    2014         try:
    2015             v = self.faces()[0]
    2016         except KeyError:
    2017             return Simplex(-1)
    2018         f = []
    2019         for i in v:
    2020             f.append(i[0])
    2021         return Simplex(set(f))
    2022 
    2023     def generated_subcomplex(self,sub_vertex_set):
     2139        from sage.misc.superseded import deprecation
     2140        deprecation(12587, "effective_vertices is deprecated. Use vertices instead")
     2141        return self._vertex_set
     2142
     2143    def generated_subcomplex(self,sub_vertex_set, is_mutable=True):
    20242144        """
    2025         Returns the largest sub-simplicial complex of self containing
     2145        Returns the largest sub-simplicial complex of ``self`` containing
    20262146        exactly ``sub_vertex_set`` as vertices.
    20272147
     2148        :param sub_vertex_set: The sub-vertex set.
     2149        :param is_mutable: Determines if the output is mutable
     2150        :type is_mutable: boolean; optional, default ``True``
     2151
    20282152        EXAMPLES::
    20292153
    20302154            sage: S = simplicial_complexes.Sphere(2)
    class SimplicialComplex(GenericCellCompl 
    20352159
    20362160        """
    20372161        if not self.vertices().set().issuperset(sub_vertex_set):
    2038             raise TypeError, "input must be a subset of the vertex set."
     2162            raise ValueError, "input must be a subset of the vertex set."
    20392163        faces = []
    20402164        for i in range(self.dimension()+1):
    20412165            for j in self.faces()[i]:
    20422166                if j.set().issubset(sub_vertex_set):
    20432167                    faces.append(j)
    2044         return SimplicialComplex(sub_vertex_set,faces,maximality_check=True)
     2168        return SimplicialComplex(faces, maximality_check=True,
     2169                                 is_mutable=is_mutable)
    20452170
    20462171    def _complement(self, simplex):
    20472172        """
    class SimplicialComplex(GenericCellCompl 
    20582183
    20592184        EXAMPLES::
    20602185
    2061             sage: X = SimplicialComplex(5)
     2186            sage: X = SimplicialComplex([[0,1,2,3,4,5]])
    20622187            sage: X._complement([1,2,3])
    20632188            (0, 4, 5)
    20642189            sage: X._complement([0,1,3,4])
    class SimplicialComplex(GenericCellCompl 
    20972222
    20982223        EXAMPLES::
    20992224
    2100             sage: X = SimplicialComplex(5)
     2225            sage: X = SimplicialComplex()
    21012226            sage: X._transpose_simplices([1,2])
    21022227            [(1,), (2,)]
    21032228            sage: X._transpose_simplices([1,2], [3,4])
    21042229            [(1, 3), (1, 4), (2, 3), (2, 4)]
    21052230
    21062231        In the following example, one can construct the simplices
    2107         (1,2) and (1,3), but you can also construct (1,1) = (1,),
     2232        ``(1,2)`` and ``(1,3)``, but you can also construct ``(1,1) = (1,)``,
    21082233        which is a face of both of the others.  So the answer omits
    2109         (1,2) and (1,3)::
     2234        ``(1,2)`` and ``(1,3)``::
    21102235       
    21112236            sage: X._transpose_simplices([1,2], [1,3])
    21122237            [(1,), (2, 3)]
    class SimplicialComplex(GenericCellCompl 
    21542279        ones.  (The last two steps are taken care of by the
    21552280        ``_transpose_simplices`` routine.)
    21562281
    2157         This is used in computing the Stanley-Reisner ring and the
    2158         Alexander dual.
     2282        This is used in computing the
     2283        :meth:`Stanley-Reisner ring<stanley_reisner_ring>` and the
     2284        :meth:`Alexander dual<alexander_dual>`.
    21592285
    21602286        EXAMPLES::
    21612287
    2162             sage: X = SimplicialComplex(4)
     2288            sage: X = SimplicialComplex([[1,3],[1,2]])
    21632289            sage: X.minimal_nonfaces()
    2164             {(4,), (2,), (3,), (0,), (1,)}           
    2165             sage: X.add_face([1,2])
    2166             sage: X.add_face([1,3])
    2167             sage: X.minimal_nonfaces()
    2168             {(4,), (2, 3), (0,)}
    2169             sage: Y = SimplicialComplex(3, [[0,1], [1,2], [2,3], [3,0]])
     2290            {(2, 3)}
     2291            sage: Y = SimplicialComplex([[0,1], [1,2], [2,3], [3,0]])
    21702292            sage: Y.minimal_nonfaces()
    21712293            {(1, 3), (0, 2)}
    21722294        """
    class SimplicialComplex(GenericCellCompl 
    21792301        quotient.
    21802302
    21812303        :param base_ring: a commutative ring
    2182         :type base_ring: optional, default ZZ
     2304        :type base_ring: optional, default ``ZZ``
    21832305        :return: a polynomial algebra with coefficients in base_ring,
    21842306          with one generator for each vertex in the simplicial complex.
    21852307
    2186         See the documentation for ``stanley_reisner_ring`` for a
     2308        See the documentation for :meth:`stanley_reisner_ring` for a
    21872309        warning about the names of the vertices.
    21882310
    21892311        EXAMPLES::
    21902312
    2191             sage: X = SimplicialComplex(3, [[1,2], [0]])
     2313            sage: X = SimplicialComplex([[1,2], [0], [3]])
    21922314            sage: X._stanley_reisner_base_ring()
    21932315            Multivariate Polynomial Ring in x0, x1, x2, x3 over Integer Ring
    2194             sage: Y = SimplicialComplex(['a', 'b', 'c'])
     2316            sage: Y = SimplicialComplex([['a', 'b', 'c']])
    21952317            sage: Y._stanley_reisner_base_ring(base_ring=QQ)
    21962318            Multivariate Polynomial Ring in a, c, b over Rational Field
    21972319        """
    class SimplicialComplex(GenericCellCompl 
    22022324        The Stanley-Reisner ring of this simplicial complex.
    22032325       
    22042326        :param base_ring: a commutative ring
    2205         :type base_ring: optional, default ZZ
     2327        :type base_ring: optional, default ``ZZ``
    22062328        :return: a quotient of a polynomial algebra with coefficients
    22072329           in ``base_ring``, with one generator for each vertex in the
    22082330           simplicial complex, by the ideal generated by the products
    class SimplicialComplex(GenericCellCompl 
    22112333        Thus the ideal is generated by the products corresponding to
    22122334        the minimal nonfaces of the simplicial complex.
    22132335
    2214         .. warning::
     2336        .. WARNING::
    22152337
    22162338           This may be quite slow!
    22172339       
    22182340           Also, this may behave badly if the vertices have the
    22192341           'wrong' names. To avoid this, define the simplicial complex
    2220            at the start with the flag ``name_check`` set to True.
     2342           at the start with the flag ``name_check`` set to ``True``.
    22212343
    22222344           More precisely, this is a quotient of a polynomial ring
    22232345           with one generator for each vertex.  If the name of a
    22242346           vertex is a non-negative integer, then the corresponding
    2225            polynomial generator is named 'x' followed by that integer
    2226            (e.g., 'x2', 'x3', 'x5', ...).  Otherwise, the polynomial
    2227            generators are given the same names as the vertices.  Thus
    2228            if the vertex set is (2, 'x2'), there will be problems.
     2347           polynomial generator is named ``'x'`` followed by that integer
     2348           (e.g., ``'x2'``, ``'x3'``, ``'x5'``, ...).  Otherwise, the
     2349           polynomial generators are given the same names as the vertices.
     2350           Thus if the vertex set is ``(2, 'x2')``, there will be problems.
    22292351
    22302352        EXAMPLES::
    22312353
    2232             sage: X = SimplicialComplex(3, [[0,1], [1,2], [2,3], [0,3]])
     2354            sage: X = SimplicialComplex([[0,1], [1,2], [2,3], [0,3]])
    22332355            sage: X.stanley_reisner_ring()
    22342356            Quotient of Multivariate Polynomial Ring in x0, x1, x2, x3 over Integer Ring by the ideal (x1*x3, x0*x2)
    2235             sage: Y = SimplicialComplex(4); Y
    2236             Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {()}
    2237             sage: Y.stanley_reisner_ring()
    2238             Quotient of Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Integer Ring by the ideal (x4, x2, x3, x0, x1)
     2357            sage: Y = SimplicialComplex([[0,1,2,3,4]]); Y
     2358            Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {(0, 1, 2, 3, 4)}
    22392359            sage: Y.add_face([0,1,2,3,4])
    22402360            sage: Y.stanley_reisner_ring(base_ring=QQ)
    22412361            Quotient of Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Rational Field by the ideal (0)           
    class SimplicialComplex(GenericCellCompl 
    22492369            products.append(prod)
    22502370        return R.quotient(products)
    22512371
    2252     def alexander_dual(self):
     2372    def alexander_dual(self, is_mutable=True):
    22532373        """
    22542374        The Alexander dual of this simplicial complex: according to
    22552375        the Macaulay2 documentation, this is the simplicial complex
    class SimplicialComplex(GenericCellCompl 
    22582378        Thus find the minimal nonfaces and take their complements to
    22592379        find the facets in the Alexander dual.
    22602380
     2381        :param is_mutable: Determines if the output is mutable
     2382        :type is_mutable: boolean; optional, default ``True``
     2383
    22612384        EXAMPLES::
    22622385
    2263             sage: Y = SimplicialComplex(4); Y
    2264             Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {()}
     2386            sage: Y = SimplicialComplex([[i] for i in range(5)]); Y
     2387            Simplicial complex with vertex set (0, 1, 2, 3, 4) and facets {(4,), (2,), (3,), (0,), (1,)}
    22652388            sage: Y.alexander_dual()
    2266             Simplicial complex with vertex set (0, 1, 2, 3, 4) and 5 facets
    2267             sage: X = SimplicialComplex(3, [[0,1], [1,2], [2,3], [3,0]])
     2389            Simplicial complex with vertex set (0, 1, 2, 3, 4) and 10 facets
     2390            sage: X = SimplicialComplex([[0,1], [1,2], [2,3], [3,0]])
    22682391            sage: X.alexander_dual()
    22692392            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 3), (0, 2)}
    22702393        """
    22712394        nonfaces = self.minimal_nonfaces()
    2272         return SimplicialComplex(self.vertices(), [self._complement(f) for f in nonfaces])
     2395        return SimplicialComplex([self._complement(f) for f in nonfaces], is_mutable=is_mutable)
    22732396                           
    22742397    def barycentric_subdivision(self):
    22752398        """
    class SimplicialComplex(GenericCellCompl 
    22802403
    22812404        EXAMPLES::
    22822405
    2283             sage: triangle = SimplicialComplex(2, [[0,1], [1,2], [0, 2]])
     2406            sage: triangle = SimplicialComplex([[0,1], [1,2], [0, 2]])
    22842407            sage: hexagon = triangle.barycentric_subdivision()
    22852408            sage: hexagon
    22862409            Simplicial complex with 6 vertices and 6 facets
    class SimplicialComplex(GenericCellCompl 
    23032426        """
    23042427        The 1-skeleton of this simplicial complex, as a graph.
    23052428
    2306         .. warning::
     2429        .. WARNING::
    23072430       
    23082431           This may give the wrong answer if the simplicial complex
    2309            was constructed with ``maximality_check`` set to False.
     2432           was constructed with ``maximality_check`` set to ``False``.
    23102433
    23112434        EXAMPLES::
    23122435
    2313             sage: S = SimplicialComplex(3, [[0,1,2,3]])
     2436            sage: S = SimplicialComplex([[0,1,2,3]])
    23142437            sage: G = S.graph(); G
    23152438            Graph on 4 vertices
    23162439            sage: G.edges()
    23172440            [(0, 1, None), (0, 2, None), (0, 3, None), (1, 2, None), (1, 3, None), (2, 3, None)]
    23182441
    2319             sage: S = SimplicialComplex(3,[[1,2,3],[1]],maximality_check=False)
     2442            sage: S = SimplicialComplex([[1,2,3],[1]],maximality_check=False)
    23202443            sage: G = S.graph()
    23212444            sage: G.is_connected()
    23222445            False
    class SimplicialComplex(GenericCellCompl 
    23502473        is essentially identical to the simplicial complex: it has
    23512474        same simplices with the same boundaries.
    23522475
    2353         :param sort_simplices: if True, sort the list of simplices in
     2476        :param sort_simplices: if ``True``, sort the list of simplices in
    23542477          each dimension
    2355         :type sort_simplices: boolean; optional, default False
     2478        :type sort_simplices: boolean; optional, default ``False``
    23562479
    23572480        EXAMPLES::
    23582481
    class SimplicialComplex(GenericCellCompl 
    23812504
    23822505    def is_flag_complex(self):
    23832506        """
    2384         Returns True if and only if self is a flag complex.
    2385 
    2386         A flag complex is a simplicial complex that is the largest simplicial complex on
    2387         its 1-skeleton. Thus a flag complex is the clique complex of its graph.
     2507        Returns ``True`` if and only if ``self`` is a flag complex.
     2508
     2509        A flag complex is a simplicial complex that is the largest simplicial
     2510        complex on its 1-skeleton. Thus a flag complex is the clique complex
     2511        of its graph.
    23882512
    23892513        EXAMPLES::
    23902514
    class SimplicialComplex(GenericCellCompl 
    23992523            sage: X.is_flag_complex()
    24002524            True
    24012525        """
    2402         return self==self.graph().clique_complex()
     2526        return self == self.graph().clique_complex()
    24032527
    24042528    def is_connected(self):
    24052529        """
    2406         Returns True if and only if self is connected.
    2407 
    2408         .. warning::
     2530        Returns ``True`` if and only if ``self`` is connected.
     2531
     2532        .. WARNING::
    24092533       
    24102534           This may give the wrong answer if the simplicial complex
    2411            was constructed with ``maximality_check`` set to False.
     2535           was constructed with ``maximality_check`` set to ``False``.
    24122536           See the final example.
    24132537
    24142538        EXAMPLES::
    24152539
    2416             sage: V = SimplicialComplex([0,1,2,3],[[0,1,2],[3]])
     2540            sage: V = SimplicialComplex([[0,1,2],[3]])
    24172541            sage: V
    24182542            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (3,)}
    24192543            sage: V.is_connected()
    24202544            False
    24212545
    2422             sage: X = SimplicialComplex([0,1,2,3],[[0,1,2]])
     2546            sage: X = SimplicialComplex([[0,1,2]])
    24232547            sage: X.is_connected()
    24242548            True
    24252549
    class SimplicialComplex(GenericCellCompl 
    24312555            sage: W.is_connected()
    24322556            True
    24332557
    2434             sage: S = SimplicialComplex(4,[[0,1],[2,3]])
     2558            sage: S = SimplicialComplex([[0,1],[2,3]])
    24352559            sage: S.is_connected()
    24362560            False
    24372561
    2438             sage: S = SimplicialComplex(2,[[0,1],[1],[0]],maximality_check=False)
     2562            sage: S = SimplicialComplex([[0,1],[1],[0]],maximality_check=False)
    24392563            sage: S.is_connected()
    24402564            False
    24412565        """
    class SimplicialComplex(GenericCellCompl 
    24432567
    24442568    def n_skeleton(self, n):
    24452569        """
    2446         The `n`-skeleton of this simplicial complex: the simplicial
    2447         complex obtained by discarding all of the simplices in
    2448         dimensions larger than `n`.
     2570        The `n`-skeleton of this simplicial complex.
     2571
     2572        The `n`-skeleton of a simplicial complex is obtained by discarding
     2573        all of the simplices in dimensions larger than `n`.
    24492574
    24502575        :param n: non-negative integer
    24512576
    24522577        EXAMPLES::
    24532578
    2454             sage: X = SimplicialComplex(3, [[0,1], [1,2,3], [0,2,3]])
     2579            sage: X = SimplicialComplex([[0,1], [1,2,3], [0,2,3]])
    24552580            sage: X.n_skeleton(1)
    24562581            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(2, 3), (0, 2), (1, 3), (1, 2), (0, 3), (0, 1)}
     2582            sage: X.set_immutable()
    24572583            sage: X.n_skeleton(2)
    24582584            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1)}
    24592585        """
    2460         facets = filter(lambda f: f.dimension()<n, self._facets)
     2586        # make sure it's a list (it will be a tuple if immutable)
     2587        facets = list(filter(lambda f: f.dimension()<n, self._facets))
    24612588        facets.extend(self.n_faces(n))
    2462         return SimplicialComplex(self.vertices(), facets)       
     2589        return SimplicialComplex(facets, is_mutable=self._is_mutable)
    24632590
    24642591    def _contractible_subcomplex(self, verbose=False):
    24652592        """
    24662593        Find a contractible subcomplex `L` of this simplicial complex,
    24672594        preferably one which is as large as possible.
    24682595
    2469         :param verbose: If True, print some messages as the simplicial
     2596        :param verbose: If ``True``, print some messages as the simplicial
    24702597           complex is computed.
    2471         :type verbose: boolean; optional, default False
     2598        :type verbose: boolean; optional, default ``False``
    24722599
    24732600        Motivation: if `K` is the original complex and if `L` is
    24742601        contractible, then the relative homology `H_*(K,L)` is
    class SimplicialComplex(GenericCellCompl 
    24772604        than the augmented chain complex for `K`, and this leads to a
    24782605        speed improvement for computing the homology of `K`.
    24792606
    2480         This just passes a subcomplex consisting of a facet to the
     2607        This just passes an immutable subcomplex consisting of a facet to the
    24812608        method ``_enlarge_subcomplex``.
    24822609
    2483         .. note::
     2610        .. NOTE::
    24842611       
    24852612           Thus when the simplicial complex is empty, so is the
    24862613           resulting 'contractible subcomplex', which is therefore not
    class SimplicialComplex(GenericCellCompl 
    24892616
    24902617        EXAMPLES::
    24912618
    2492             sage: disk = SimplicialComplex(3, [[0,1,2,3]])
    2493             sage: sphere = disk.remove_face([0,1,2,3])
     2619            sage: sphere = SimplicialComplex([[0,1,2,3]])
     2620            sage: sphere.remove_face([0,1,2,3])
    24942621            sage: sphere
    24952622            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)}
    24962623            sage: L = sphere._contractible_subcomplex(); L
    class SimplicialComplex(GenericCellCompl 
    25002627        """
    25012628        vertices = self.vertices()
    25022629        facets = [self._facets[0]]
    2503         return self._enlarge_subcomplex(SimplicialComplex(vertices, facets), verbose=verbose)
     2630        return self._enlarge_subcomplex(SimplicialComplex(facets, is_mutable=False), verbose=verbose)
    25042631
    25052632    def _enlarge_subcomplex(self, subcomplex, verbose=False):
    25062633        """
    class SimplicialComplex(GenericCellCompl 
    25122639        `H_{*}(K,S)`, so the computations should be faster.
    25132640
    25142641        :param subcomplex: a subcomplex of this simplicial complex
    2515         :param verbose: If True, print some messages as the simplicial
     2642        :param verbose: If ``True``, print some messages as the simplicial
    25162643           complex is computed.
    2517         :type verbose: boolean; optional, default False
     2644        :type verbose: boolean; optional, default ``False``
    25182645        :return: a complex `L` containing ``subcomplex`` and contained
    25192646           in ``self``, homotopy equivalent to ``subcomplex``.
    25202647
    class SimplicialComplex(GenericCellCompl 
    25312658
    25322659        Inside the torus, define a subcomplex consisting of a loop::
    25332660       
    2534             sage: S = SimplicialComplex(T.vertices(), [[0,1], [1,2], [0,2]])
     2661            sage: S = SimplicialComplex([[0,1], [1,2], [0,2]], is_mutable=False)
    25352662            sage: S.homology()
    25362663            {0: 0, 1: Z}
    25372664            sage: L = T._enlarge_subcomplex(S)
    class SimplicialComplex(GenericCellCompl 
    25422669            sage: L.homology()[1]
    25432670            Z
    25442671        """
     2672        # Make the subcomplex immutable if not
     2673        if subcomplex is not None and subcomplex._is_mutable:
     2674            old = subcomplex
     2675            subcomplex = SimplicialComplex(subcomplex._facets, maximality_check=False,
     2676                                           sort_facets=False, is_mutable=False)
     2677
    25452678        if subcomplex in self.__enlarged:
    25462679            return self.__enlarged[subcomplex]
    2547         faces = filter(lambda x: x not in subcomplex._facets, self._facets)
     2680        faces = filter(lambda x: x not in subcomplex._facets, list(self._facets))
    25482681        done = False
    25492682        new_facets = list(subcomplex._facets)
    25502683        while not done:
    class SimplicialComplex(GenericCellCompl 
    25572690                int_facets = []
    25582691                for a in new_facets:
    25592692                    int_facets.append(a.set().intersection(f_set))
    2560                 intersection = SimplicialComplex(self.vertices(), int_facets)
     2693                intersection = SimplicialComplex(int_facets)
    25612694                if not intersection._facets[0].is_empty():
    25622695                    if (len(intersection._facets) == 1 or
    25632696                        intersection == intersection._contractible_subcomplex()):
    class SimplicialComplex(GenericCellCompl 
    25702703                faces.remove(f)
    25712704        if verbose:
    25722705            print "  now constructing a simplicial complex with %s vertices and %s facets" % (self.vertices().dimension()+1, len(new_facets))
    2573         L = SimplicialComplex(self.vertices(), new_facets, maximality_check=False,
    2574                               vertex_check=False, sort_facets=False)
     2706        L = SimplicialComplex(new_facets, maximality_check=False,
     2707                              sort_facets=False, is_mutable=self._is_mutable)
    25752708        self.__enlarged[subcomplex] = L
    25762709        return L
    25772710
    25782711    def _cubical_(self):
    25792712        r"""
    2580         Cubical complex constructed from self.
     2713        Cubical complex constructed from ``self``.
    25812714
    25822715        ALGORITHM:
    25832716
    class SimplicialComplex(GenericCellCompl 
    25872720        ..., m\}`; then each face of `I^m` has the following form, for
    25882721        subsets `I \subset J \subset [m]`:
    25892722
    2590         .. math::
     2723        .. MATH::
    25912724
    25922725            F_{I \subset J} = \{ (y_1,...,y_m) \in I^m \,:\, y_i =0 \text{
    25932726            for } i \in I, y_j = 1 \text{ for } j \not \in J\}.
    class SimplicialComplex(GenericCellCompl 
    25972730        Then we associate to `K` the cubical subcomplex of `I^m` with
    25982731        faces
    25992732
    2600         .. math::
     2733        .. MATH::
    26012734
    26022735            \{F_{I \subset J} \,:\, J \in K, I \neq \emptyset \}
    26032736
    class SimplicialComplex(GenericCellCompl 
    26072740
    26082741        REFERENCES:
    26092742
    2610         - V. M. Bukhshtaber and T. E. Panov, "Moment-angle complexes
    2611           and combinatorics of simplicial manifolds," *Uspekhi
    2612           Mat. Nauk* 55 (2000), 171--172.
    2613 
    2614         - M. A. Shtan'ko and and M. I. Shtogrin, "Embedding cubic
    2615           manifolds and complexes into a cubic lattice", *Uspekhi
    2616           Mat. Nauk* 47 (1992), 219-220.
     2743        .. [BP2000] V. M. Bukhshtaber and T. E. Panov, "Moment-angle complexes
     2744           and combinatorics of simplicial manifolds," *Uspekhi
     2745           Mat. Nauk* 55 (2000), 171--172.
     2746
     2747        .. [SS1992] M. A. Shtan'ko and and M. I. Shtogrin, "Embedding cubic
     2748           manifolds and complexes into a cubic lattice", *Uspekhi
     2749           Mat. Nauk* 47 (1992), 219-220.
    26172750
    26182751        EXAMPLES::
    26192752
    class SimplicialComplex(GenericCellCompl 
    26562789       
    26572790        EXAMPLES::
    26582791
    2659             sage: SimplicialComplex(5, [[0,1], [1,2,3,4,5]]).category()
     2792            sage: SimplicialComplex([[0,1], [1,2,3,4,5]]).category()
    26602793            Category of simplicial complexes
    26612794        """
    26622795        import sage.categories.all
    class SimplicialComplex(GenericCellCompl 
    26842817
    26852818    def _chomp_repr_(self):
    26862819        r"""
    2687         String representation of self suitable for use by the CHomP
     2820        String representation of ``self`` suitable for use by the CHomP
    26882821        program.  This lists each facet on its own line, and makes
    26892822        sure vertices are listed as numbers.
    26902823
    class SimplicialComplex(GenericCellCompl 
    26972830
    26982831        A simplicial complex whose vertices are tuples, not integers::
    26992832
    2700         ::
    2701 
    27022833            sage: S = SimplicialComplex([[(0,1), (1,2), (3,4)]])
    27032834            sage: S._chomp_repr_()
    27042835            '(0, 1, 2)\n'
    class SimplicialComplex(GenericCellCompl 
    27242855    # because it lists the maximal faces, not the total number of faces.
    27252856    def _repr_(self):
    27262857        """
    2727         Print representation. If there are only a few vertices or
    2728         faces, they are listed.  If there are lots, the number is
    2729         given.
     2858        Print representation.
     2859
     2860        If there are only a few vertices or faces, they are listed. If
     2861        there are lots, the number is given.
    27302862
    27312863        EXAMPLES::
    27322864
    2733             sage: X = SimplicialComplex(3, [[0,1], [1,2]])
     2865            sage: X = SimplicialComplex([[0,1], [1,2]])
    27342866            sage: X._repr_()
    2735             'Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2), (0, 1)}'
    2736             sage: SimplicialComplex(15)
    2737             Simplicial complex with 16 vertices and facets {()}
     2867            'Simplicial complex with vertex set (0, 1, 2) and facets {(1, 2), (0, 1)}'
     2868            sage: SimplicialComplex([[i for i in range(16)]])
     2869            Simplicial complex with 16 vertices and 1 facets
    27382870        """
    27392871        vertex_limit = 45
    27402872        facet_limit = 55
    class SimplicialComplex(GenericCellCompl 
    27472879        if len(facet_string) > facet_limit:
    27482880            facet_string = "%s facets" % len(facets)
    27492881        return "Simplicial complex " + vertex_string + " and " + facet_string
     2882
     2883    def set_immutable(self):
     2884        """
     2885        Make this simplicial complex immutable.
     2886
     2887        EXAMPLES::
     2888
     2889            sage: S = SimplicialComplex([[1,4], [2,4]])
     2890            sage: S.is_mutable()
     2891            True
     2892            sage: S.set_immutable()
     2893            sage: S.is_mutable()
     2894            False
     2895        """
     2896        self._is_mutable = False
     2897        self._facets = tuple(self._facets)
     2898
     2899    def is_mutable(self):
     2900        """
     2901        Return ``True`` if mutable.
     2902
     2903        EXAMPLES::
     2904
     2905            sage: S = SimplicialComplex([[1,4], [2,4]])
     2906            sage: S.is_mutable()
     2907            True
     2908            sage: S.set_immutable()
     2909            sage: S.is_mutable()
     2910            False
     2911            sage: S2 = SimplicialComplex([[1,4], [2,4]], is_mutable=False)
     2912            sage: S2.is_mutable()
     2913            False
     2914            sage: S3 = SimplicialComplex([[1,4], [2,4]], is_mutable=False)
     2915            sage: S3.is_mutable()
     2916            False
     2917        """
     2918        return self._is_mutable
     2919
     2920    def is_immutable(self):
     2921        """
     2922        Return ``True`` if immutable.
     2923
     2924        EXAMPLES::
     2925
     2926            sage: S = SimplicialComplex([[1,4], [2,4]])
     2927            sage: S.is_immutable()
     2928            False
     2929            sage: S.set_immutable()
     2930            sage: S.is_immutable()
     2931            True
     2932        """
     2933        return not self._is_mutable
     2934
  • sage/homology/simplicial_complex_homset.py

    diff --git a/sage/homology/simplicial_complex_homset.py b/sage/homology/simplicial_complex_homset.py
    a b  
    11r"""
    22Homsets between simplicial complexes
    33
     4AUTHORS:
     5
     6- Travis Scrimshaw (2012-08-18): Made all simplicial complexes immutable to
     7  work with the homset cache.
     8
    49EXAMPLES:
    510
    611::
    import sage.homology.simplicial_complex_ 
    5459
    5560def is_SimplicialComplexHomset(x):
    5661    """
    57     Return True if and only if x is a simplicial complex homspace.
     62    Return ``True`` if and only if ``x`` is a simplicial complex homspace.
    5863
    5964    EXAMPLES::
    6065
    61         sage: H = Hom(SimplicialComplex(2),SimplicialComplex(3))
     66        sage: S = SimplicialComplex(is_mutable=False)
     67        sage: T = SimplicialComplex(is_mutable=False)
     68        sage: H = Hom(S, T)
    6269        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
     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
    6471        sage: from sage.homology.simplicial_complex_homset import is_SimplicialComplexHomset
    6572        sage: is_SimplicialComplexHomset(H)
    6673        True
    class SimplicialComplexHomset(sage.categ 
    7178    def __call__(self, f):
    7279        """
    7380        INPUT:
    74             f -- a dictionary with keys exactly the vertices of the domain and values vertices of the codomain
    7581
    76         EXAMPLE::
     82        - ``f`` -- a dictionary with keys exactly the vertices of the domain
     83           and values vertices of the codomain
     84
     85        EXAMPLES::
    7786
    7887            sage: S = simplicial_complexes.Sphere(3)
    7988            sage: T = simplicial_complexes.Sphere(2)
    class SimplicialComplexHomset(sage.categ 
    8291            sage: x = H(f)
    8392            sage: x
    8493            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            
    8794        """
    8895        return simplicial_complex_morphism.SimplicialComplexMorphism(f,self.domain(),self.codomain())
    8996
    9097    def diagonal_morphism(self,rename_vertices=True):
    91         """
    92         Returns the diagonal morphism in Hom(S,SxS).
     98        r"""
     99        Returns the diagonal morphism in `Hom(S, S \times S)`.
    93100
    94101        EXAMPLES::
    95102
    96103            sage: S = simplicial_complexes.Sphere(2)
    97             sage: H = Hom(S,S.product(S))
     104            sage: H = Hom(S,S.product(S, is_mutable=False))
    98105            sage: d = H.diagonal_morphism()
    99106            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
     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
    101110       
    102             sage: T = SimplicialComplex(3)
    103             sage: U = T.product(T,rename_vertices = False)
     111            sage: T = SimplicialComplex([[0], [1]], is_mutable=False)
     112            sage: U = T.product(T,rename_vertices = False, is_mutable=False)
    104113            sage: G = Hom(T,U)
    105114            sage: e = G.diagonal_morphism(rename_vertices = False)
    106115            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 
     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),)}
    109119        """
    110120
    111121        if self._codomain == self._domain.product(self._domain,rename_vertices=rename_vertices):
    class SimplicialComplexHomset(sage.categ 
    117127            else:
    118128                for i in self._domain.vertices().set():
    119129                    f[i] = (i,i)
    120             return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,X)
     130            return simplicial_complex_morphism.SimplicialComplexMorphism(f, self._domain,X)
    121131        else:
    122132            raise TypeError, "Diagonal morphism is only defined for Hom(X,XxX)."
    123133       
    124134    def identity(self):
    125135        """
    126         Returns the identity morphism of Hom(S,S).
     136        Returns the identity morphism of `Hom(S,S)`.
    127137
    128138        EXAMPLES::
    129139
    class SimplicialComplexHomset(sage.categ 
    133143            sage: i.is_identity()
    134144            True
    135145
    136             sage: T = SimplicialComplex(3,[[0,1]])
     146            sage: T = SimplicialComplex([[0,1]], is_mutable=False)
    137147            sage: G = Hom(T,T)
    138148            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 
     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)}
    141152        """
    142153        if self.is_endomorphism_set():
    143154            f = dict()
    class SimplicialComplexHomset(sage.categ 
    145156                f[i]=i
    146157            return simplicial_complex_morphism.SimplicialComplexMorphism(f,self._domain,self._codomain)
    147158        else:
    148             raise TypeError, "Identity map is only defined for endomorphism sets."
     159            raise TypeError("Identity map is only defined for endomorphism sets.")
    149160
    150161    def an_element(self):
    151162        """
    152         Returns a (non-random) element of self.
     163        Returns a (non-random) element of ``self``.
    153164
    154165        EXAMPLES::
    155166
  • sage/homology/simplicial_complex_morphism.py

    diff --git a/sage/homology/simplicial_complex_morphism.py b/sage/homology/simplicial_complex_morphism.py
    a b AUTHORS: 
    55
    66- Benjamin Antieau <d.ben.antieau@gmail.com> (2009.06)
    77
     8- Travis Scrimshaw (2012-08-18): Made all simplicial complexes immutable to
     9  work with the homset cache.
     10
    811This module implements morphisms of simplicial complexes. The input is given
    9 by a dictionary on the vertex set or the effective vertex set of a simplicial complex.
    10 The initialization checks that faces are sent to faces.
     12by a dictionary on the vertex set of a simplicial complex. The initialization
     13checks that faces are sent to faces.
    1114
    12 There is also the capability to create the fiber product of two morphisms with the same codomain.
     15There is also the capability to create the fiber product of two morphisms with
     16the same codomain.
    1317
    1418EXAMPLES::
    1519
    16     sage: S = SimplicialComplex(5,[[0,2],[1,5],[3,4]])
    17     sage: H = Hom(S,S.product(S))
     20    sage: S = SimplicialComplex([[0,2],[1,5],[3,4]], is_mutable=False)
     21    sage: H = Hom(S,S.product(S, is_mutable=False))
    1822    sage: H.diagonal_morphism()
    1923    Simplicial complex morphism {0: 'L0R0', 1: 'L1R1', 2: 'L2R2', 3: 'L3R3', 4: 'L4R4', 5: 'L5R5'} from Simplicial complex with vertex set (0, 1, 2, 3, 4, 5) and facets {(3, 4), (1, 5), (0, 2)} to Simplicial complex with 36 vertices and 18 facets
    2024
    21     sage: S = SimplicialComplex(5,[[0,2],[1,5],[3,4]])
    22     sage: T = SimplicialComplex(4,[[0,2],[1,3]])
     25    sage: S = SimplicialComplex([[0,2],[1,5],[3,4]], is_mutable=False)
     26    sage: T = SimplicialComplex([[0,2],[1,3]], is_mutable=False)
    2327    sage: f = {0:0,1:1,2:2,3:1,4:3,5:3}
    2428    sage: H = Hom(S,T)
    2529    sage: x = H(f)
    2630    sage: x.image()
    2731    Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 3), (0, 2)}
    2832    sage: x.is_surjective()
    29     False
     33    True
    3034    sage: x.is_injective()
    3135    False
    3236    sage: x.is_identity()
    EXAMPLES:: 
    5256    Simplicial complex morphism {'L1R1': 1, 'L3R3': 3, 'L2R2': 2, 'L0R0': 0} from Simplicial complex with 4 vertices and 4 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)}
    5357
    5458    sage: S = simplicial_complexes.Sphere(2)
    55     sage: T = S.product(SimplicialComplex(1,[[0,1]]),rename_vertices = False)
     59    sage: T = S.product(SimplicialComplex([[0,1]]), rename_vertices = False, is_mutable=False)
    5660    sage: H = Hom(T,S)
    5761    sage: T
    5862    Simplicial complex with 8 vertices and 12 facets
    EXAMPLES:: 
    6973    sage: z = y.fiber_product(x)
    7074    sage: z                                     # this is the mapping path space
    7175    Simplicial complex morphism {'L2R(2, 0)': 2, 'L2R(2, 1)': 2, 'L0R(0, 0)': 0, 'L0R(0, 1)': 0, 'L1R(1, 0)': 1, 'L1R(1, 1)': 1} from Simplicial complex with 6 vertices and 6 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)}
    72 
    73 
    7476"""
    7577
    7678#*****************************************************************************
    from sage.algebras.steenrod.steenrod_alg 
    99101
    100102def is_SimplicialComplexMorphism(x):
    101103    """
    102     Returns True if and only if x is a morphism of simplicial complexes.
     104    Returns ``True`` if and only if ``x`` is a morphism of simplicial complexes.
    103105
    104106    EXAMPLES::
    105107
    106108        sage: from sage.homology.simplicial_complex_morphism import is_SimplicialComplexMorphism
    107         sage: S = SimplicialComplex(5,[[0,1],[3,4]])
     109        sage: S = SimplicialComplex([[0,1],[3,4]], is_mutable=False)
    108110        sage: H = Hom(S,S)
    109         sage: f = {0:0,1:1,2:2,3:3,4:4,5:5}
     111        sage: f = {0:0,1:1,3:3,4:4}
    110112        sage: x = H(f)
    111113        sage: is_SimplicialComplexMorphism(x)
    112114        True
    class SimplicialComplexMorphism(SageObje 
    120122    """
    121123    def __init__(self,f,X,Y):
    122124        """
    123         Input is a dictionary f, the domain, and the codomain.
     125        Input is a dictionary ``f``, the domain ``X``, and the codomain ``Y``.
    124126
    125         One can define the dictionary either on the vertices of X or on the effective vertices of X (X.effective_vertices()). Note that this
    126         difference does matter. For instance, it changes the result of the image method, and hence it changes the result of the is_surjective method as well.
    127         This is because two SimplicialComplexes with the same faces but different vertex sets are not equal.
     127        One can define the dictionary on the vertices of `X`.
    128128
    129129        EXAMPLES::
    130130
    131             sage: S = SimplicialComplex(5,[[0,1],[3,4]])
     131            sage: S = SimplicialComplex([[0,1],[2],[3,4],[5]], is_mutable=False)
    132132            sage: H = Hom(S,S)
    133133            sage: f = {0:0,1:1,2:2,3:3,4:4,5:5}
    134             sage: g = {0:0,1:1,3:3,4:4}
     134            sage: g = {0:0,1:1,2:0,3:3,4:4,5:0}
    135135            sage: x = H(f)
    136136            sage: y = H(g)
    137             sage: x==y
     137            sage: x == y
    138138            False
    139139            sage: x.image()
    140             Simplicial complex with vertex set (0, 1, 2, 3, 4, 5) and facets {(3, 4), (0, 1)}
     140            Simplicial complex with vertex set (0, 1, 2, 3, 4, 5) and facets {(3, 4), (5,), (2,), (0, 1)}
    141141            sage: y.image()
    142142            Simplicial complex with vertex set (0, 1, 3, 4) and facets {(3, 4), (0, 1)}
    143             sage: x.image()==y.image()
     143            sage: x.image() == y.image()
    144144            False
    145 
    146145        """
    147146        if not isinstance(X,simplicial_complex.SimplicialComplex) or not isinstance(Y,simplicial_complex.SimplicialComplex):
    148             raise ValueError, "X and Y must be SimplicialComplexes."
    149         if not set(f.keys())==X._vertex_set.set() and not set(f.keys())==X.effective_vertices().set():
    150             raise ValueError, "f must be a dictionary from the vertex set of X to single values in the vertex set of Y."
     147            raise ValueError("X and Y must be SimplicialComplexes.")
     148        if not set(f.keys()) == X._vertex_set.set():
     149            raise ValueError("f must be a dictionary from the vertex set of X to single values in the vertex set of Y.")
    151150        dim = X.dimension()
    152151        Y_faces = Y.faces()
    153152        for k in range(dim+1):
    class SimplicialComplexMorphism(SageObje 
    158157                    fi.append(f[j])
    159158                v = simplicial_complex.Simplex(set(fi))
    160159            if not v in Y_faces[v.dimension()]:
    161                 raise ValueError, "f must be a dictionary from the vertices of X to the vertices of Y."
     160                raise ValueError("f must be a dictionary from the vertices of X to the vertices of Y.")
    162161        self._vertex_dictionary = f
    163162        self._domain = X
    164163        self._codomain = Y
    165164   
    166165    def __eq__(self,x):
    167166        """
    168         Returns True if and only if self == x.
     167        Returns ``True`` if and only if ``self == x``.
    169168       
    170169        EXAMPLES::
    171170
    class SimplicialComplexMorphism(SageObje 
    179178            sage: i==j
    180179            False
    181180           
    182             sage: T = SimplicialComplex(3,[[1,2]])
     181            sage: T = SimplicialComplex([[1,2]], is_mutable=False)
    183182            sage: T
    184             Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2)}
     183            Simplicial complex with vertex set (1, 2) and facets {(1, 2)}
    185184            sage: G = Hom(T,T)
    186185            sage: k = G.identity()
    187             sage: g = {0:0,1:1,2:2,3:3}
     186            sage: g = {1:1,2:2}
    188187            sage: l = G(g)
    189             sage: k==l
     188            sage: k == l
    190189            True
    191190
    192191        """
    class SimplicialComplexMorphism(SageObje 
    199198        """
    200199        Input is a simplex of the domain. Output is the image simplex.
    201200       
    202         If optional argument ``orientation`` is True, return a pair
    203         ``(image simplex, oriented)`` where ``oriented`` is 1 or `-1`
    204         depending on whether the map preserves or reverses the
    205         orientation of the image simplex.
     201        If the optional argument ``orientation`` is ``True``, then this
     202        returns a pair ``(image simplex, oriented)`` where ``oriented``
     203        is 1 or `-1` depending on whether the map preserves or reverses
     204        the orientation of the image simplex.
    206205
    207206        EXAMPLES::
    208207
    class SimplicialComplexMorphism(SageObje 
    221220
    222221        An orientation-reversing example::
    223222
    224             sage: X = SimplicialComplex(1, [[0,1]])
     223            sage: X = SimplicialComplex([[0,1]], is_mutable=False)
    225224            sage: g = Hom(X,X)({0:1, 1:0})
    226225            sage: g(Simplex([0,1]))
    227226            (0, 1)
    class SimplicialComplexMorphism(SageObje 
    246245
    247246    def _repr_(self):
    248247        """
    249         Print representation
     248        Return a string representation of ``self``.
    250249
    251250        EXAMPLES::
    252251
    class SimplicialComplexMorphism(SageObje 
    257256            Simplicial complex morphism {0: 0, 1: 1, 2: 2, 3: 3} 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 vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)}
    258257            sage: i._repr_()
    259258            'Simplicial complex morphism {0: 0, 1: 1, 2: 2, 3: 3} 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 vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3), (0, 1, 3)}'
    260  
    261 
    262259        """
    263260        return "Simplicial complex morphism " + str(self._vertex_dictionary) + " from " + self._domain._repr_() + " to " + self._codomain._repr_()
    264261
    265262    def associated_chain_complex_morphism(self,base_ring=ZZ,augmented=False,cochain=False):
    266263        """
    267         Returns the associated chain complex morphism of self.
     264        Returns the associated chain complex morphism of ``self``.
    268265
    269266        EXAMPLES::
    270267
    class SimplicialComplexMorphism(SageObje 
    313310             [ 0  0  0]
    314311             [ 0 -1  0], 2: []}
    315312
    316             sage: X = SimplicialComplex(1, [[0, 1]])
     313            sage: X = SimplicialComplex([[0, 1]], is_mutable=False)
    317314            sage: Hom(X,X)({0:1, 1:0}).associated_chain_complex_morphism()._matrix_dictionary
    318315            {0: [0 1]
    319316             [1 0], 1: [-1]}
    class SimplicialComplexMorphism(SageObje 
    371368       
    372369    def image(self):
    373370        """
    374         Computes the image simplicial complex of f.
     371        Computes the image simplicial complex of `f`.
    375372       
    376373        EXAMPLES::
    377374
    378             sage: S = SimplicialComplex(3,[[0,1],[2,3]])
    379             sage: T = SimplicialComplex(1,[[0,1]])
     375            sage: S = SimplicialComplex([[0,1],[2,3]], is_mutable=False)
     376            sage: T = SimplicialComplex([[0,1]], is_mutable=False)
    380377            sage: f = {0:0,1:1,2:0,3:1}
    381378            sage: H = Hom(S,T)
    382379            sage: x = H(f)
    383380            sage: x.image()
    384381            Simplicial complex with vertex set (0, 1) and facets {(0, 1)}
    385382
    386             sage: S = SimplicialComplex(2)
     383            sage: S = SimplicialComplex(is_mutable=False)
    387384            sage: H = Hom(S,S)
    388385            sage: i = H.identity()
    389386            sage: i.image()
    390             Simplicial complex with vertex set (0, 1, 2) and facets {()}
     387            Simplicial complex with vertex set () and facets {()}
    391388            sage: i.is_surjective()
    392389            True
    393             sage: S = SimplicialComplex(5,[[0,1]])
    394             sage: T = SimplicialComplex(3,[[0,1]])
     390            sage: S = SimplicialComplex([[0,1]], is_mutable=False)
     391            sage: T = SimplicialComplex([[0,1], [0,2]], is_mutable=False)
    395392            sage: f = {0:0,1:1}
    396             sage: g = {0:0,1:1,2:2,3:3,4:4,5:5}
     393            sage: g = {0:0,1:1}
     394            sage: k = {0:0,1:2}
    397395            sage: H = Hom(S,T)
    398396            sage: x = H(f)
    399397            sage: y = H(g)
     398            sage: z = H(k)
    400399            sage: x == y
     400            True
     401            sage: x == z
    401402            False
    402403            sage: x.image()
    403404            Simplicial complex with vertex set (0, 1) and facets {(0, 1)}
    404405            sage: y.image()
    405             Simplicial complex with vertex set (0, 1, 2, 3, 4, 5) and facets {(0, 1)}
     406            Simplicial complex with vertex set (0, 1) and facets {(0, 1)}
     407            sage: z.image()
     408            Simplicial complex with vertex set (0, 2) and facets {(0, 2)}
    406409
    407410        """
    408411        fa = [self(i) for i in self._domain.facets()]
    409         return simplicial_complex.SimplicialComplex(set(self._vertex_dictionary.values()),fa,maximality_check=True)
     412        return simplicial_complex.SimplicialComplex(fa, maximality_check=True)
    410413
    411414    def domain(self):
    412415        """
    class SimplicialComplexMorphism(SageObje 
    414417
    415418        EXAMPLES::
    416419
    417             sage: S = SimplicialComplex(3,[[0,1],[2,3]])
    418             sage: T = SimplicialComplex(1,[[0,1]])
     420            sage: S = SimplicialComplex([[0,1],[2,3]], is_mutable=False)
     421            sage: T = SimplicialComplex([[0,1]], is_mutable=False)
    419422            sage: f = {0:0,1:1,2:0,3:1}
    420423            sage: H = Hom(S,T)
    421424            sage: x = H(f)
    422425            sage: x.domain()
    423426            Simplicial complex with vertex set (0, 1, 2, 3) and facets {(2, 3), (0, 1)}
    424 
    425427        """
    426428        return self._domain
    427429
    class SimplicialComplexMorphism(SageObje 
    431433
    432434        EXAMPLES::
    433435
    434             sage: S = SimplicialComplex(3,[[0,1],[2,3]])
    435             sage: T = SimplicialComplex(1,[[0,1]])
     436            sage: S = SimplicialComplex([[0,1],[2,3]], is_mutable=False)
     437            sage: T = SimplicialComplex([[0,1]], is_mutable=False)
    436438            sage: f = {0:0,1:1,2:0,3:1}
    437439            sage: H = Hom(S,T)
    438440            sage: x = H(f)
    class SimplicialComplexMorphism(SageObje 
    444446       
    445447    def is_surjective(self):
    446448        """
    447         Returns True if and only if self is surjective.
     449        Returns ``True`` if and only if ``self`` is surjective.
    448450
    449451        EXAMPLES::
    450452
    451             sage: S = SimplicialComplex(3,[(0,1,2)])
     453            sage: S = SimplicialComplex([(0,1,2)], is_mutable=False)
    452454            sage: S
    453             Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2)}
    454             sage: T = SimplicialComplex(2,[(0,1)])
     455            Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}
     456            sage: T = SimplicialComplex([(0,1)], is_mutable=False)
    455457            sage: T
    456             Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1)}
     458            Simplicial complex with vertex set (0, 1) and facets {(0, 1)}
    457459            sage: H = Hom(S,T)
    458             sage: x = H({0:0,1:1,2:1,3:2})
     460            sage: x = H({0:0,1:1,2:1})
    459461            sage: x.is_surjective()
    460462            True
    461463
    462             sage: S = SimplicialComplex(3,[[0,1],[2,3]])
    463             sage: T = SimplicialComplex(1,[[0,1]])
     464            sage: S = SimplicialComplex([[0,1],[2,3]], is_mutable=False)
     465            sage: T = SimplicialComplex([[0,1]], is_mutable=False)
    464466            sage: f = {0:0,1:1,2:0,3:1}
    465467            sage: H = Hom(S,T)
    466468            sage: x = H(f)
    467469            sage: x.is_surjective()
    468470            True
    469 
    470         """   
     471        """
    471472        return self._codomain == self.image()
    472473       
    473474    def is_injective(self):
    474475        """
    475         Returns True if and only if self is injective.
     476        Returns ``True`` if and only if ``self`` is injective.
    476477
    477478        EXAMPLES::
    478479
    class SimplicialComplexMorphism(SageObje 
    499500
    500501    def is_identity(self):
    501502        """
    502         If x is an identity morphism, returns True. Otherwise, False.
     503        If ``self`` is an identity morphism, returns ``True``.
     504        Otherwise, ``False``.
    503505
    504506        EXAMPLES::
    505507
    class SimplicialComplexMorphism(SageObje 
    526528            return False
    527529        else:
    528530            f = dict()
    529             for i in self._domain.vertices().set():
     531            for i in self._domain._vertex_set.set():
    530532                f[i] = i
    531533            if self._vertex_dictionary != f:
    532534                return False
    533535            else:
    534536                return True
    535537
    536     def fiber_product(self,other,rename_vertices = True):
     538    def fiber_product(self, other, rename_vertices = True):
    537539        """
    538         Fiber product of self and other. Both morphisms should have the same codomain. The method returns a morphism of simplicial complexes, which
    539         is the morphism from the space of the fiber product to the codomain.
     540        Fiber product of ``self`` and ``other``. Both morphisms should have
     541        the same codomain. The method returns a morphism of simplicial
     542        complexes, which is the morphism from the space of the fiber product
     543        to the codomain.
    540544
    541545        EXAMPLES::
    542546           
    543             sage: S = SimplicialComplex(2,[[0,1],[1,2]])
    544             sage: T = SimplicialComplex(2,[[0,2]])
    545             sage: U = SimplicialComplex(1,[[0,1]])
     547            sage: S = SimplicialComplex([[0,1],[1,2]], is_mutable=False)
     548            sage: T = SimplicialComplex([[0,2],[1]], is_mutable=False)
     549            sage: U = SimplicialComplex([[0,1],[2]], is_mutable=False)
    546550            sage: H = Hom(S,U)
    547551            sage: G = Hom(T,U)
    548552            sage: f = {0:0,1:1,2:0}
    class SimplicialComplexMorphism(SageObje 
    551555            sage: y = G(g)
    552556            sage: z = x.fiber_product(y)
    553557            sage: z
    554             Simplicial complex morphism {'L1R2': 1, 'L2R0': 0, 'L0R0': 0} from Simplicial complex with vertex set ('L0R0', 'L1R2', 'L2R0') and facets {('L2R0',), ('L0R0', 'L1R2')} to Simplicial complex with vertex set (0, 1) and facets {(0, 1)}
    555 
     558            Simplicial complex morphism {'L1R2': 1, 'L1R1': 1, 'L2R0': 0, 'L0R0': 0}
     559            from Simplicial complex with 4 vertices and facets
     560            {('L2R0',), ('L1R1',), ('L0R0', 'L1R2')} to Simplicial complex
     561            with vertex set (0, 1, 2) and facets {(2,), (0, 1)}
    556562        """
    557563        if self._codomain != other._codomain:
    558             raise ValueError, "self and other must have the same codomain."
     564            raise ValueError("self and other must have the same codomain.")
    559565        X = self._domain.product(other._domain,rename_vertices = rename_vertices)
    560566        v = []
    561567        f = dict()
    562         eff1 = self._domain.effective_vertices()
    563         eff2 = other._domain.effective_vertices()
     568        eff1 = self._domain._vertex_set
     569        eff2 = other._domain._vertex_set
    564570        for i in eff1:
    565571            for j in eff2:
    566572                if self(simplicial_complex.Simplex([i])) == other(simplicial_complex.Simplex([j])):
    class SimplicialComplexMorphism(SageObje 
    570576                    else:
    571577                        v.append((i,j))
    572578                        f[(i,j)] = self._vertex_dictionary[i]
    573         return SimplicialComplexMorphism(f,X.generated_subcomplex(v),self._codomain)
     579        return SimplicialComplexMorphism(f, X.generated_subcomplex(v), self._codomain)
  • sage/schemes/toric/divisor.py

    diff --git a/sage/schemes/toric/divisor.py b/sage/schemes/toric/divisor.py
    a b class ToricDivisor_generic(Divisor_gener 
    15011501            sage: D = -D0 + 2*D2 - D3
    15021502            sage: M = dP6.fan().dual_lattice()
    15031503            sage: D._sheaf_complex( M(1,0) )
    1504             Simplicial complex with vertex set (0, 1, 2, 3, 4, 5)
    1505             and facets {(3,), (0, 1)}
     1504            Simplicial complex with vertex set (0, 1, 3) and facets {(3,), (0, 1)}
    15061505        """
    15071506        fan = self.parent().scheme().fan()
    15081507        ray_is_negative = [ m*ray + self.coefficient(i) < 0
    class ToricDivisor_generic(Divisor_gener 
    15121511                return False
    15131512            return all(ray_is_negative[i] for i in cone.ambient_ray_indices())
    15141513        negative_cones = filter(cone_is_negative, flatten(fan.cones()))
    1515         return SimplicialComplex(fan.nrays() - 1, [c.ambient_ray_indices()
    1516                                                    for c in negative_cones])
     1514        return SimplicialComplex([c.ambient_ray_indices() for c in negative_cones])
    15171515
    15181516    def _sheaf_cohomology(self, cplx):
    15191517        """
    class ToricDivisor_generic(Divisor_gener 
    15341532     
    15351533            sage: dP6 = toric_varieties.dP6()
    15361534            sage: D = dP6.divisor(1)
    1537             sage: D._sheaf_cohomology( SimplicialComplex([1],[]) )
     1535            sage: D._sheaf_cohomology( SimplicialComplex() )
    15381536            (1, 0, 0)
    1539             sage: D._sheaf_cohomology( SimplicialComplex([1,2,3],[[1,2],[2,3],[3,1]]) )
     1537            sage: D._sheaf_cohomology( SimplicialComplex([[1,2],[2,3],[3,1]]) )
    15401538            (0, 0, 1)
    15411539
    15421540        A more complicated example to test that trac #10731 is fixed::