On Mar 12, 2009, at 11:23 AM, Carl Witty wrote:

> On Thu, Mar 12, 2009 at 12:57 AM, Florent Hivert
> <florent.hiv...@univ-rouen.fr> wrote:
>>
>>      Dear Robert,
>>
>>> The issue here is that comparison is useful outside of the purely
>>> mathematical context--for example if one wants to sort a list (for
>>> printing or searching) or use elements in sets or as keys in
>>> dictionaries or simply throw an error on an illegal value like 0.
>>
>> Sure. But if python allows for it, I'd rather not to mix  
>> mathematics and
>> implementation detail. Is there a way to have a different order.  
>> In MuPAD we
>> had a function sysorder. Let me quote the doc:
> ...
>> Nevertheless I retain the idea of two orders one which is  
>> mathematically sound
>> and the other one which is use for internal. Of course I'd rather  
>> keeping the
>> usual < <= notation for the mathematical one. My dream is that the  
>> internal
>> one is just an extension of the mathematical one when the later  
>> has no
>> meaning, but this is too mush asking. Ideed, the mathematical  
>> sound < can be
>> very time consuming to compute. Whereas for most data structure  
>> applications
>> you require that it is fast to compute. Is there any low level python
>> data structures using search trees on something equivalent ?
>
> +1 for having < refer to mathematical orderings (so it raises an
> exception where no standard mathematical ordering is defined), and for
> having a separate sysorder comparison for the somewhat-rare cases when
> you really want to sort.

I could actually go for this as well. Python provides richcmp (used  
for < and friends) and cmp, and I think the later could be the  
"sysorder" (which would hopefully be less arbitrary than a memory  
address, specifically respect the mathematical notions of equality at  
least) and the former the mathematical order. On the other hand, I  
would rather GF(5)(1) == pi return False than raise an error. I would  
also still advocate using coercions, so GF(5)(1) == 1 returns True  
(though the argument that RealField(20)(pi) == RealField(50)(pi)  
returns False is a good one.)

> I've think I've voted the other way in previous discussions of this
> topic.  I changed my mind because:
>
> 1) I've seen a lot more mathematicians be confused/annoyed by having
> defined orderings between mathematically-unordered objects since then
>
> 2) I used to think that Python more-or-less required that all objects
> be ordered.  I don't remember where I got that idea, but it's wrong;
> somebody pointed out that Python-native complex numbers are unordered.
>
> The standard low-level Python data structures are the list and the
> dictionary; neither depends on orderings.  (Dictionaries are hash
> tables, so they use hashes and equality.)  I don't know of any
> contexts where Python implicitly depends on orderings.
>
> This has been discussed before; for example, see
> http://groups.google.com/group/sage-devel/browse_thread/thread/ 
> fa1c998160d41f62/bc550ad42bc08cc0?lnk=gst#bc550ad42bc08cc0
>
> My suggestion in that thread of using "cmp" for sysorder is possible,
> but I doubt if it's a good idea... it makes it easy to make
> implementation mistakes, because by default cmp() and < use the same
> code.

This could be changed, and probably would be a good thing (though a  
lot of work--I don't know how much depends on the current semantics).  
The cmp code isn't the prettiest right now. But I think this is a  
distinct topic than whether or not to use coercions in comparison.

- Robert



--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to