Chris, On Mon, Jul 12, 2010 at 7:49 PM, Chris Godsil <cgod...@uwaterloo.ca> wrote: > ... its the complicated vertices that are causing the problem, I expect.
The problem is that the comparison operators in Python for sets implement the subset notion, and thus do not provide a proper sorting of a list of sets: http://docs.python.org/library/sets.html#set-objects IMHO, these would be better as .is_subset() methods, etc. Sage's adjacency matrix command uses vertices(), which uses comparison operators to give an ordering of the vertices. However, since "subset" does not define a total ordering, it does not give a good way of sorting vertices. One good short term solution is to use tuples instead, which are ordered lexicographically. Some possible solutions: 1. Sage graphs should have a way of specifying a user-defined comparison function for sorting vertices. Any time you use sets as vertices, you would also do something like sage: def cmp(foo, bar): ... # some total ordering on foo and bar... sage: G.set_cmp_verts(cmp) sage: G.vertices() [consistently sorted list of vertices] Or even easier: sage: G.set_cmp_verts(sets=True) 2. We could be a bit smarter and provide some alternative sort function in the vertices() command, but it would seem as if no matter which function we wrote, a user could come up with another object which would implement < etc in such a way as to still break it. Thoughts? Python gurus, is there a set object which has the right kind of __cmp__ for this use? -- Robert L. Miller http://www.rlmiller.org/ -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org