Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upShould PartialOrd require irreflexivity over <? #50230
Comments
This comment has been minimized.
This comment has been minimized.
|
In the RFC thread for Irreflexivity is implied by said notational axiom and the semantics of Thus, instead of adding the axiom of Irreflexivity to the docs, one could also add the notational axiom (which we probably want to add anyway). The docs are also unclear or plain wrong in regards to the provided methods
This implies that one has to manually implement |
kennytm
added
C-enhancement
T-doc
labels
Apr 25, 2018
This comment has been minimized.
This comment has been minimized.
|
@RalfJung mentioned on IRC:
That is, the docs should state that |
This comment has been minimized.
This comment has been minimized.
Agreed. This is stated explicitly for PartialEq, it seems it as forgotten here.
I think that's the wrong way to think about it: PartialOrd is only a single operation, |
This comment has been minimized.
This comment has been minimized.
Yeah that sounds pretty reasonable. I'd express this as "> is the dual to <", I think that's the common terminology in maths. I briefly wondered how this relates to antisymmetry... but antisymmetry is a strange axiom in this context. In fact, antisymmetry is impossible to violate! If (EDIT: This assume |
This comment has been minimized.
This comment has been minimized.
Wouldn't we then need to require that if EDIT: I see this as just trading one axiom for another. We probably should document the axioms both in term of the comparisons |
This comment has been minimized.
This comment has been minimized.
That's the "notational" (or "duality") axiom: |
This comment has been minimized.
This comment has been minimized.
Aha! Yeah if we add that axiom then we don't need anti-symmetry. Nice! The wikipedia page on strict partial orders actually mentions this, that one axiom follows from the other two:
(just note that we don't require irreflexivity yet) |
This comment has been minimized.
This comment has been minimized.
|
So to make a more concrete proposal. We currently have
Including all feedback above, we could change that to (strawman):
I am not sure if everything does indeed follow properly from |
This comment has been minimized.
This comment has been minimized.
|
@gnzlbg Awesome, thank you! A few things though: (1.)
Are you sure? I don't think transitivity (" (2.)
I would change this to "Strict partial ordering relationS." as the trait adds (3.)Maybe we want to explicitly state that (4.)
I don't think you only need duality and transitivity of
|
This comment has been minimized.
This comment has been minimized.
I was talking here about
So when I wrote the axioms in term of
Yes you are correct, I ninja edited the post.
Step by step: "if
The only requirement of |
This comment has been minimized.
This comment has been minimized.
Mhh, yes that's tricky :/ But as far as I understand it, In fact, I think that Maybe the first paragraph of
I'd say so.
I'm not sure about your first step: you say "
So we still have two possibilities: either
This only requires everything to be comparable with itself, which doesn't help us because But again, maybe I'm missing something. |
This comment has been minimized.
This comment has been minimized.
|
@gnzlbg nice first strawman! I overall like it. I think before stating any axioms, however, we should define
As @LukasKalbertodt pointed out, these statements are not well-typed:
I'd add "and from the definition of
This is some kind of congruence statement: Essentially, we demand that So maybe, instead of what I said above, the real meaning of "
However, these may be too strong for irreflexive equalities? Can we derive one of these axioms from the other? Or find one nicer axiom that implies both of them? |
This comment has been minimized.
This comment has been minimized.
|
So, I've only been half-following this. I'm afraid I'll really only just be adding to the noise; but here's how I feel inclined to look at it:
|
steveklabnik
added
T-lang
and removed
T-doc
labels
May 28, 2018
This comment has been minimized.
This comment has been minimized.
|
Tagging with @rust-lang/lang; they need to make a call before we can write docs. |
This comment has been minimized.
This comment has been minimized.
|
Seems reasonable. The docs in this comment seem plausible to me. Would it make sense to use rfcbot to gather consensus asynchronously? |
This comment has been minimized.
This comment has been minimized.
|
Is there a recommended way to put up a documment that we could quickly edit for this collaboratively? It appears to me that after @LukasKalbertodt and @RalfJung comments we are 95 % there, we just need to finish it, and for that it might be better if we would just have something that's "uptodate" and that we can quickly eidt. |
This comment has been minimized.
This comment has been minimized.
|
@gnzlbg I don't know if that's what you had in mind, but I created a HackMD document from your comment. Everyone can login via GitHub and edit. But it might be better to have a tiny repository where we submit the documentation as PR and we can leave line comments? |
This comment has been minimized.
This comment has been minimized.
|
@LukasKalbertodt thanks! I worked a bit on it there and this is how it looks now (it would be cool if the tool could create diffs, so maybe a github repo would be better for something like this in the future):
|
This comment has been minimized.
This comment has been minimized.
Yes, diffs and PR-comments would be nice. I created a temporary repository and submitted the current documentation as PR. I'd suggest we could discuss everything there. I already left a few comments on the PR. I also gave you push access to the repo, so feel free to change things as you like. |
This comment has been minimized.
This comment has been minimized.
|
(small note: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Looks like C++ went with something a bit more complex. |
This comment has been minimized.
This comment has been minimized.
|
@eddyb The latest paper is P0515r3. The most relevant section for this discussion is probably "Section 2: Design" which defines the following comparison categories as types:
The values of the equality categories are:
This is very similar to rust: interpret The orderings are also pretty similar:
The paper is a bit light on math details; maybe some of this is covered in Stepanov's "From Mathematics to Generic Programming" or "Elements of Programming, worth checking this out. Basically, the paper says that a type should implement The most interesting examples are:
|
This comment has been minimized.
This comment has been minimized.
|
Another related concern I have with how the current traits work is that there is no way to express that some impl PartialOrd<Foo> for Bar { ... }there is no way to implement |
This comment has been minimized.
This comment has been minimized.
|
I am confused, of course you can implement |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung I've filled an issue in the rfc repo: rust-lang/rfcs#2511 Maybe the explanation there is more clear? |
This comment has been minimized.
This comment has been minimized.
|
Yes, I understand now where you are coming from. Thanks. |
gnzlbg commentedApr 25, 2018
•
edited
Why doesn't
PartialOrdrequire irreflexivity!(a < a)over<? AFAICTPartialOrddoes not actually express any kind of ordering relation for<. For:<: we needPartialOrd+Irreflexivity<=: we needPartialOrd+Eqsince==must be reflexive.PartialOrd + Eq + TotalIs this an oversight? If not, we should document that
PartialOrdrequires:!(a < a)as well. That would make
PartialOrd's<denote a strict partial order on<.AFAICT this is actually what was intended, since all the discussions I can find online about
PartialOrdtalk about floats, and floats are strictly partially ordered under<, but not non-strictly partially ordered under<=, which would fit our current model that floats don't implementEq.Also, the docs of
PartialOrddo not say whatle(<=) andge(>=) actually mean. AFAICT they mean nothing forPartialOrdin isolation. From reading the source the default implementation isa < b || a == b, which would denote a non-strict total ordering over<=whenEqis implemented. But sinceEqis not required forPartialOrd, I'd guess that those overriding these implementations are allowed to do something else as long as they don't implementEq. It is unclear to me what that "something else" might mean, but the docs should probably say something about this.Also, I haven't been able to find any document explaining why things are the way they are, but the fact that
PartialOrdrequiresPartialEqmakes no sense to me, and it doesn't make much sense either thatPartialOrdexposesle(<=) andge(>=) methods, since as mentioned above, withoutEq,leandgedo not express any meaningful ordering relation. It seems that these traits, like all other "operators" traits, mix operator overloading with mathematical semantics: in some cases they are used to express mathematical concepts, like a strict partial ordering relation under<, and in some other cases they are used "to provide <= for floats". If anybody has any links to any discussions / documentation about why things are the way they are I'd like to read them, and maybe we should add rationale sections to the docs.