On Sat, Nov 7, 2009 at 8:29 PM, Alex Ghitza <aghi...@gmail.com> wrote:
>
>
> This is a bit disconcerting:
>
> sage: Set(['a', 'b', 'c'])
> {'a', 'c', 'b'}
> sage: Set(['a', 'b', 'c', 'd'])
> {'a', 'c', 'b', 'd'}
> sage: Set(['a', 'b', 'c', 'd', 'e'])
> {'a', 'c', 'b', 'e', 'd'}
>
> Bug?  It doesn't seem to happen with lists of numbers.

Just a quick remark.  In Sage there is set (the builton Python type)
and Set (the Sage type, which wraps the builtin one):

sage: set(['a','b','c'])
set(['a', 'b', 'c'])
sage: Set(['a','b','c'])
{'a', 'c', 'b'}

My intention in introducting Set in addition to set, was to make
something that would have much more mathematical printing and
semantics than Python sets, in addition to allowing for infinite sets,
etc.  The underlying data structure for finite enumerated sets is just
a normal Python set:

sage: type(x._Set_object__object)
<type 'frozenset'>

I think it would be reasonable to change the _repr_ method to output
the elements in some natural order *if possible*. Right now, it just
does this:

    def _repr_(self):
        r"""
        Return the string representation of ``self``.

        EXAMPLES::

            sage: S = EnumeratedSet(GF(2))
            sage: S
            {0, 1}
        """
        s = repr(self.set())
        return "{" + s[5:-2] + "}"

This is in sage/sets/set.py

I think I would be OK with you changing this function to do something more like

   s = repr(sorted(list(self.set())))

or something like that.   Obviously, there will be sets where elements
can't be compared, so sorting will raise an error -- this needs to be
caught.  There will also be a performance penalty, but we pay this
only for printing.

William

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

Reply via email to