sorting with +nan.0 ?

30 views
Skip to first unread message

'John Clements' via dev-redirect

unread,
Nov 24, 2015, 7:36:40 AM11/24/15
to dev
Currently, a +nan.0 does an interesting thing to sorting:

#lang racket

(sort '(1 3 5 +nan.0 2 4 6) >)

yields

'(5 3 1 +nan.0 6 4 2)

Is this the answer we want?

signature.asc

Robby Findler

unread,
Nov 24, 2015, 7:39:40 AM11/24/15
to John Clements, dev
Unfortunately, nan is defined to not be less than or greater than any
number and sorting works only when you supply a transitive predicate
and it seems difficult to change either of these things.

Robby
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/675231ca-96b0-4039-94e4-7a744278c586%40mtasv.net.
> For more options, visit https://groups.google.com/d/optout.

'John Clements' via dev-redirect

unread,
Nov 24, 2015, 12:56:55 PM11/24/15
to Robby Findler, dev

> On Nov 24, 2015, at 4:39 AM, Robby Findler <ro...@eecs.northwestern.edu> wrote:
>
> Unfortunately, nan is defined to not be less than or greater than any
> number and sorting works only when you supply a transitive predicate
> and it seems difficult to change either of these things.

In my mind, the alternative would be to signal an error; I’m having a very hard time imagining the programmer who would be legitimately unhappy about getting an error here. Or perhaps the concern is adding time to inner inner inner loops?

John

>
> Robby
>
>
> On Sat, Nov 21, 2015 at 3:10 AM, 'John Clements' via dev-redirect
> <d...@plt-scheme.org> wrote:
>> Currently, a +nan.0 does an interesting thing to sorting:
>>
>> #lang racket
>>
>> (sort '(1 3 5 +nan.0 2 4 6) >)
>>
>> yields
>>
>> '(5 3 1 +nan.0 6 4 2)
>>
>> Is this the answer we want?
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
>> To post to this group, send email to racke...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/675231ca-96b0-4039-94e4-7a744278c586%40mtasv.net.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAL3TdOM3%3D%2BTJGkAZFKAagfN5OiekC8c%2BtNpmt%3DrQZJS8ovtWHA%40mail.gmail.com.

Jay McCarthy

unread,
Nov 24, 2015, 2:08:20 PM11/24/15
to John Clements, Robby Findler, dev
I believe that Robby is referring to IEEE 754's rules about NaN, which
does not order NaN unless you use the special total order predicate,
which is not typically used in PLs. I think that most Racket users
would want < to be what the hardware does, modulo conversions, rather
than an ordering unique to Racket.

Jay

On Tue, Nov 24, 2015 at 12:56 PM, 'John Clements' via dev-redirect
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/a8b0aa6e-8994-4885-8b5d-c945c0162376%40mtasv.net.
> For more options, visit https://groups.google.com/d/optout.



--
Jay McCarthy
Associate Professor
PLT @ CS @ UMass Lowell
http://jeapostrophe.github.io

"Wherefore, be not weary in well-doing,
for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
- D&C 64:33

Robby Findler

unread,
Nov 24, 2015, 2:15:26 PM11/24/15
to Jay McCarthy, John Clements, dev
Yes: I would say that we cannot change < in #lang racket, but a new
design of a number system that does something different isn't out of
the possibility. There is a lot of tricky design issues, tho.

Robby

'John Clements' via dev-redirect

unread,
Nov 24, 2015, 2:30:13 PM11/24/15
to Robby Findler, Jay McCarthy, dev

> On Nov 24, 2015, at 11:15 AM, Robby Findler <ro...@eecs.northwestern.edu> wrote:
>
> Yes: I would say that we cannot change < in #lang racket, but a new
> design of a number system that does something different isn't out of
> the possibility. There is a lot of tricky design issues, tho.

Sorry, I’m not proposing any change at all to … ah, I see, sorting is parameterized over the predicate, so this is necessarily a discussion about <, not a discussion about sort.

Sorry for the noise,

John



Robby Findler

unread,
Nov 24, 2015, 2:35:55 PM11/24/15
to John Clements, Jay McCarthy, dev
It's definitely a mess and a very unfriendly behavior!!

Maybe worth a note in teh docs for 'sort'? With the example you posted?

Robby
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/d7a85ef0-09be-4595-a532-e6e0b38155b5%40mtasv.net.

'John Clements' via dev-redirect

unread,
Nov 24, 2015, 3:24:52 PM11/24/15
to Robby Findler, Jay McCarthy, dev

> On Nov 24, 2015, at 11:35 AM, Robby Findler <ro...@eecs.northwestern.edu> wrote:
>
> It's definitely a mess and a very unfriendly behavior!!
>
> Maybe worth a note in teh docs for 'sort'? With the example you posted?

I shortened it up to a single sentence & made a pull request.

Thanks for your help,

John

>
> Robby
>
> On Tue, Nov 24, 2015 at 1:30 PM, 'John Clements' via dev-redirect
> <d...@plt-scheme.org> wrote:
>>
>>> On Nov 24, 2015, at 11:15 AM, Robby Findler <ro...@eecs.northwestern.edu> wrote:
>>>
>>> Yes: I would say that we cannot change < in #lang racket, but a new
>>> design of a number system that does something different isn't out of
>>> the possibility. There is a lot of tricky design issues, tho.
>>
>> Sorry, I’m not proposing any change at all to … ah, I see, sorting is parameterized over the predicate, so this is necessarily a discussion about <, not a discussion about sort.
>>
>> Sorry for the noise,
>>
>> John
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
>> To post to this group, send email to racke...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/d7a85ef0-09be-4595-a532-e6e0b38155b5%40mtasv.net.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAL3TdOPgoZ_X63Bk-FgwghML%2BTNjnn7Onb2Bo%3DC8VpJRFhqCjQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages