Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max is not stable for preorders #8825

Closed
jech opened this issue Oct 27, 2014 · 3 comments
Closed

max is not stable for preorders #8825

jech opened this issue Oct 27, 2014 · 3 comments

Comments

@jech
Copy link

jech commented Oct 27, 2014

In a preorder, min of two equivalent elements should return the first parameter, and max should return the second. This makes the following properties true:

  • (min(x,y), max(x,y)) is either (x,y) or (y,x);
  • (x,y)->(min(x,y), max(x,y)) is a stable sort.

The definition of max at operators.jl:56 is wrong — it returns the first argument for equivalent arguments:

import Base: isless

type Twain
    a :: Int
    b :: Int
end

isless(x :: Twain, y :: Twain) = x.a < y.a

# max(Twain(2,3), Twain(2,4))

You'll find a more detailed discussion in Chapter 7 of https://www.stepanovpapers.com/notes.pdf .

@jiahao jiahao changed the title max is wrong for preorders max is not stable for preorders Oct 27, 2014
@jiahao
Copy link
Member

jiahao commented Oct 27, 2014

"Wrong" is too strong a statement: max is not wrong to the extent that it provides no guarantee of stability.

I changed the title of this issue to reflect your primary concern.

@StefanKarpinski
Copy link
Sponsor Member

These seem like good identities to respect, but I agree, calling this wrong is too strong.

@jech
Copy link
Author

jech commented Oct 27, 2014

Agreed.

stevengj added a commit that referenced this issue Oct 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants