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 , 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: 14 14 sure it is immutable. Made :meth:`SimplicialComplex.remove_face()` into a 15 15 mutator. Deprecated the ``vertex_set`` parameter. 16 16 17 - Christian Stump (2011-06) - implementation of is_cohen_macaulay 18 17 19 This module implements the basic structure of finite simplicial 18 20 complexes. Given a set `V` of "vertices", a simplicial complex on `V` 19 21 is a collection `K` of subsets of `V` satisfying the condition that if … … class Simplex(SageObject): 608 610 answer.append(Simplex(new)) 609 611 return answer 610 612 611 612 613 def __cmp__(self, other): 613 614 """ 614 615 Return ``True`` iff this simplex is the same as ``other``: that … … class Simplex(SageObject): 675 676 """ 676 677 return latex(self.__tuple) 677 678 678 679 679 class SimplicialComplex(GenericCellComplex): 680 680 r""" 681 681 Define a simplicial complex. … … class SimplicialComplex(GenericCellCompl 1067 1067 self._faces[subcomplex] = Faces 1068 1068 return self._faces[subcomplex] 1069 1069 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 1070 1095 cells = faces 1071 1096 1072 1097 def n_faces(self, n, subcomplex=None): … … class SimplicialComplex(GenericCellCompl 2121 2146 faces.append(Simplex(list(f.set().difference(s.set())))) 2122 2147 return SimplicialComplex(faces, is_mutable=is_mutable) 2123 2148 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 2124 2219 def effective_vertices(self): 2125 2220 """ 2126 2221 The set of vertices belonging to some face. Returns the list of … … class SimplicialComplex(GenericCellCompl 2687 2782 print " looping through %s facets" % len(faces) 2688 2783 for f in faces: 2689 2784 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 ) 2693 2786 intersection = SimplicialComplex(int_facets) 2694 2787 if not intersection._facets[0].is_empty(): 2695 2788 if (len(intersection._facets) == 1 or … … class SimplicialComplex(GenericCellCompl 2781 2874 cube.append([0,1]) 2782 2875 cubes.append(cube) 2783 2876 return CubicalComplex(cubes) 2784 2877 2785 2878 def category(self): 2786 2879 """ 2787 2880 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: 176 176 177 177 # Send "kill -9" signal to workers that are left. 178 178 if len(workers) > 0: 179 print "Killing any remaining workers..." 179 if self.verbose: 180 print "Killing any remaining workers..." 180 181 sys.stdout.flush() 181 182 for pid in workers.keys(): 182 183 try: