Ticket #11523: trac_11523-cohen_macaulay_complex-cs-jhp-review-ts.patch

File trac_11523-cohen_macaulay_complex-cs-jhp-review-ts.patch, 6.4 KB (added by tscrim, 10 years ago)
  • sage/homology/simplicial_complex.py

    # HG changeset patch
    # User Christian Stump <christian.stump at gmail.com>
    # Date 1317076886 25200
    # Node ID e2f76a3ee410d57c44e511620d248a3cecf0865d
    # Parent 16d173622125361b328ecabc43f4ad76899ad32a
    #11523 implementation of Cohen-Macaulay test for simplicial complexes
    
    diff --git a/sage/homology/simplicial_complex.py b/sage/homology/simplicial_complex.py
    a b AUTHORS: 
    1414  sure it is immutable. Made :meth:`SimplicialComplex.remove_face()` into a
    1515  mutator. Deprecated the ``vertex_set`` parameter.
    1616
     17- Christian Stump (2011-06) - implementation of is_cohen_macaulay
     18
    1719This module implements the basic structure of finite simplicial
    1820complexes. Given a set `V` of "vertices", a simplicial complex on `V`
    1921is a collection `K` of subsets of `V` satisfying the condition that if
    class Simplex(SageObject): 
    608610            answer.append(Simplex(new))
    609611        return answer
    610612
    611 
    612613    def __cmp__(self, other):
    613614        """
    614615        Return ``True`` iff this simplex is the same as ``other``: that
    class Simplex(SageObject): 
    675676        """
    676677        return latex(self.__tuple)
    677678
    678    
    679679class SimplicialComplex(GenericCellComplex):
    680680    r"""
    681681    Define a simplicial complex.
    class SimplicialComplex(GenericCellCompl 
    10671067            self._faces[subcomplex] = Faces
    10681068        return self._faces[subcomplex]
    10691069
     1070    def face_iterator(self, increasing=True):
     1071        """
     1072        An iterator for the faces in this simplicial complex.
     1073
     1074        INPUTS:
     1075
     1076        - ``increasing`` -- (optional, default ``True``) if ``True``, return
     1077          faces in increasing order of dimension, thus starting with
     1078          the empty face. Otherwise it returns faces in decreasing order of
     1079          dimension.
     1080
     1081        EXAMPLES::
     1082
     1083            sage: S1 = simplicial_complexes.Sphere(1)
     1084            sage: [f for f in S1.face_iterator()]
     1085            [(), (2,), (0,), (1,), (1, 2), (0, 2), (0, 1)]
     1086        """
     1087        Fs = self.faces()
     1088        dim_index = xrange(-1,self.dimension()+1)
     1089        if not increasing:
     1090            dim_index = reversed(dim_index)
     1091        for i in dim_index:
     1092            for F in Fs[i]:
     1093                yield F
     1094
    10701095    cells = faces
    10711096
    10721097    def n_faces(self, n, subcomplex=None):
    class SimplicialComplex(GenericCellCompl 
    21212146                faces.append(Simplex(list(f.set().difference(s.set()))))
    21222147        return SimplicialComplex(faces, is_mutable=is_mutable)
    21232148
     2149    def is_cohen_macaulay(self, ncpus=0):
     2150        r"""
     2151        Returns True if ``self`` is Cohen-Macaulay, i.e., if
     2152        `\tilde{H}_i(\operatorname{lk}_\Delta(F);\ZZ) = 0` for all
     2153        `F \in \Delta` and `i < \operatorname{dim}\operatorname{lk}_\Delta(F)`.
     2154        Here, `\Delta` is ``self``, and `\operatorname{lk}` denotes the
     2155        link operator on ``self``.
     2156
     2157        INPUT:
     2158
     2159        - ``ncpus`` -- (default: 0) number of cpus used for the
     2160          computation. If this is 0, determine the number of cpus
     2161          automatically based on the hardware being used.
     2162
     2163        For finite simplicial complexes, this is equivalent to the
     2164        statement that the Stanley-Reisner ring of ``self`` is
     2165        Cohen-Macaulay.
     2166
     2167        .. NOTE ::
     2168
     2169            This method, especially when it returns ``False``, may
     2170            print a message like ::
     2171
     2172                Exception OSError: (10, 'No child processes') in <generator object __call__ at 0x10c8e3af0>     ignored
     2173
     2174            This may be ignored.
     2175
     2176        EXAMPLES:
     2177
     2178        Spheres are Cohen-Macaulay::
     2179
     2180            sage: S = SimplicialComplex([[1,2],[2,3],[3,1]])
     2181            sage: S.is_cohen_macaulay(ncpus=3)
     2182            True
     2183
     2184        The following example is taken from Bruns, Herzog - Cohen-Macaulay
     2185        rings, Figure 5.3::
     2186
     2187            sage: S = SimplicialComplex([[1,2,3],[1,4,5]])
     2188            sage: S.is_cohen_macaulay(ncpus=3)
     2189            ...
     2190            False
     2191        """
     2192        from sage.parallel.decorate import parallel
     2193        from sage.rings.rational_field import QQ
     2194
     2195        if ncpus == 0:
     2196            import os
     2197            try:
     2198                ncpus = int(os.environ['SAGE_NUM_THREADS'])
     2199            except KeyError:
     2200                ncpus = 1
     2201
     2202        facs = [ x for x in self.face_iterator() ]
     2203        n = len(facs)
     2204        facs_divided = [ [] for i in range(ncpus) ]
     2205        for i in range(n):
     2206            facs_divided[i%ncpus].append(facs[i])
     2207
     2208        def all_homologies_vanish(F):
     2209            S = self.link(F)
     2210            H = S.homology(base_ring=QQ)
     2211            return all( H[j].dimension() == 0 for j in xrange(S.dimension()) )
     2212
     2213        @parallel(ncpus=ncpus)
     2214        def all_homologies_in_list_vanish(Fs):
     2215            return all( all_homologies_vanish(F) for F in Fs )
     2216
     2217        return all( answer[1] for answer in all_homologies_in_list_vanish(facs_divided) )
     2218
    21242219    def effective_vertices(self):
    21252220        """
    21262221        The set of vertices belonging to some face. Returns the list of
    class SimplicialComplex(GenericCellCompl 
    26872782                print "  looping through %s facets" % len(faces)
    26882783            for f in faces:
    26892784                f_set = f.set()
    2690                 int_facets = []
    2691                 for a in new_facets:
    2692                     int_facets.append(a.set().intersection(f_set))
     2785                int_facets = set( a.set().intersection(f_set) for a in new_facets )
    26932786                intersection = SimplicialComplex(int_facets)
    26942787                if not intersection._facets[0].is_empty():
    26952788                    if (len(intersection._facets) == 1 or
    class SimplicialComplex(GenericCellCompl 
    27812874                        cube.append([0,1])
    27822875                cubes.append(cube)
    27832876        return CubicalComplex(cubes)
    2784  
     2877
    27852878    def category(self):
    27862879        """
    27872880        Return the category to which this chain complex belongs: the
  • sage/parallel/use_fork.py

    diff --git a/sage/parallel/use_fork.py b/sage/parallel/use_fork.py
    a b class p_iter_fork: 
    176176
    177177            # Send "kill -9" signal to workers that are left.
    178178            if len(workers) > 0:
    179                 print "Killing any remaining workers..."
     179                if self.verbose:
     180                    print "Killing any remaining workers..."
    180181                sys.stdout.flush()
    181182                for pid in workers.keys():
    182183                    try: