[sage-devel] Re: Suspiciously sorted sets

2009-09-21 Thread Simon King

Hi Rob!

On Sep 21, 2:15 am, Rob Beezer goo...@beezer.cotse.net wrote:
 sage: g = Graph()
 sage: g.add_vertices(Subsets(3,2))
 sage: g.vertices()
 [{2, 3}, {1, 2}, {1, 3}]
 sage: sorted(g.vertices())
 [{1, 3}, {1, 2}, {2, 3}]
 sage: Subsets(3,2).list()
 [{1, 2}, {1, 3}, {2, 3}]
 sage: sorted(Subsets(3,2).list())
 [{2, 3}, {1, 3}, {1, 2}]

I think the problem is that there is no proper ordering defined for
sage.sets.set.Set_object_enumerated:
  sage: S = Subsets(3,2).list()[0]
  sage: T = Subsets(3,2).list()[1]
  sage: S
  {1, 2}
  sage: T
  {1, 3}
  sage: type(S)
  class 'sage.sets.set.Set_object_enumerated'
  sage: S  T
  True
  sage: T  S
  True
  sage: S==T
  False

So, unless someone implements __cmp__ (or similar) methods for
Set_object_enumerated, you can't expect to get anything meaningful out
of the sorting.

Best regards,
Simon

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sage-devel] Re: Suspiciously sorted sets

2009-09-21 Thread Simon King

Hi!

On Sep 21, 10:22 am, Simon King simon.k...@nuigalway.ie wrote:
[...]
 So, unless someone implements __cmp__ (or similar) methods for
 Set_object_enumerated, you can't expect to get anything meaningful out
 of the sorting.

If your question is just about getting *some* unique result (say, for
a doc test): You can sort the elements of your list first, and then
you have a list of list (rather than a list of sets) that you can sort
in a unique way.

  sage: g = Graph()
  sage: g.add_vertices(Subsets(3,2))
  sage: g.vertices()
  [{2, 3}, {1, 2}, {1, 3}]
  sage: sorted([sorted(list(V)) for V in g.vertices()])
  [[1, 2], [1, 3], [2, 3]]
  sage: Subsets(3,2).list()
  [{1, 2}, {1, 3}, {2, 3}]
  sage: sorted([sorted(list(V)) for V in Subsets(3,2)])
  [[1, 2], [1, 3], [2, 3]]

Cheers,
Simon

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sage-devel] Re: Suspiciously sorted sets

2009-09-21 Thread Rob Beezer

Hi Simon,

Thanks for the explanation and isolating the problem, plus the
workaround for getting a unique result.  I did have doctesting in the
back of my mind, even though it is not necessary at the moment for the
patch in question.

I'll likely add to Trac a ticket about the need for a comparison
method on sets later today when I get a chance.

Rob
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sage-devel] Re: Suspiciously sorted sets

2009-09-21 Thread Nick Alexander

 I'll likely add to Trac a ticket about the need for a comparison
 method on sets later today when I get a chance.

Just for the record, sorted sets make very little sense.  It is  
important to be able to have a set containing anything that is  
hashable (in the python sense) but not necessarily sortable (again in  
the python sense).  If you can't sort the elements, how can you order  
the sets themselves?

Nick

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sage-devel] Re: Suspiciously sorted sets

2009-09-21 Thread Simon King

Hi Nick,

On 22 Sep., 00:02, Nick Alexander ncalexan...@gmail.com wrote:
 Just for the record, sorted sets make very little sense.  

Sure. When I said unless something implements a __cmp__ method... I
did not mean that one *should* implement it; I just wanted to explain
sorted(...) relies on a __cmp__ method, so if in some context one
wants sorted to work then __cmp__ must be implemented.

In the case of sets, I totally agree that the user should transform
the set into a list and then proceed with that, if s/he wants some
orderable object.

Best regards
Simon

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---