On Aug 10, 8:41 pm, Rafael Villarroel <rvf0...@gmail.com> wrote: > Hello all, > > Under friendly advice by Fidel Barrera, I have been trying to use Sage > for my research since about two monts ago. I work with graphs and posets > and simplicial complexes coming from them, and I had used GAP + GRAPE + > SimplicialHomology for that. With Sage, I like mostly the fact that one > can get pretty drawings of posets and graps "out of the box", and that > there seems to be active work on simplicial complexes. > > Since before using Sage I knew no Python, I have been put off by all the > different types of objects when using simplicial complexes in Sage. I > have defined the following functions that seem to work, and I would > appreciate any comments you may have that would help me improve when > working with Sage.
Sorry, I was on vacation when you first posted this. I'm a topologist, so I haven't seen these ideas before, but your functions seem good to me. Some comments: first, in general, these functions would be better as "methods", so that they would be called as S.is_free_face(s) S.free_face_removed() S.collapsed_complex() That is, they would be included in simplicial_complex.py, like "remove_face", etc. > # a free face is one that is contained properly in exactly one maximal face > def is_free_face (S,s): To turn into a method, change the previous line to "def is_free_face (self, s):", and in general replace "S" with "self". > def f(x): return set(s)<=set(x) > return not (Simplex(s) in S.facets()) and len(filter(f,S.facets()))==1 > > # we find (if it exists) a free face of the smallest dimension, and remove it > def free_face_removed ( S ): > i = -1 If this becomes part of the library code (appended to simplicial_complex.py), then you also need from copy import deepcopy here. > S1 = deepcopy( S ) > found = false Should be False > dim = S1.dimension() > faces = S1.faces() > while i < dim and not found: > j = 0 > ifaces = list(faces[i]) > while j < len(ifaces) and not found: > if is_free_face( S1 , ifaces[j] ): > found = True > print "removing ",ifaces[j] > S1.remove_face( ifaces[j] ) > else: > j = j+1 > i = i+1 > return S1 I wonder if it would be faster to scan through the faces of the facets. If I'm thinking of it correctly, a d-dimensional free face is a face either of a (d+1)-dimensional facet or of a (d+1)-dimensional free face. There may be lots of low-dimensional faces to scan through with your method, but relatively few high-dimensional free faces. Once you have working code for both choices, you can do sage: S = SimplicialComplex(...) sage: timeit('S.free_face_removed_version1()') # these timings are completely made up 25 loops, best of 3: 22.7 ms per loop sage: timeit('S.free_face_removed_version2()') 25 loops, best of 3: 43 ms per loop and then you can tell whether version 1 or version 2 is faster. > # remove all free faces > def collapsed_complex ( S ): > S1 = S > S2 = free_face_removed( S ) > while S1 <> S2: > S1 = S2 > S2 = free_face_removed( S1 ) > return S2 Otherwise, this looks fine to me. If you want it be part of the Sage library for everyone to use, then you should include documentation, including examples illustrating what the function does and why it's interesting. Here's a minimal version: def collapsed_complex (self): """ Remove all free faces from self. Could probably say more here. EXAMPLES:: sage: S = SimplicialComplex(...) # need to fill in the details here sage: S.homology(1) == sage: S.collapsed_complex().homology(1) True sage: # could use more examples down here """ S1 = S S2 = free_face_removed( S ) while S1 <> S2: S1 = S2 S2 = free_face_removed( S1 ) return S2 Post here or send me email if you have other questions or more code. Regards, John Palmieri --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---