-
Notifications
You must be signed in to change notification settings - Fork 0
Initial documentation #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
`PartialOrd` Documentation | ||
========================== | ||
|
||
[Strict partial ordering relation](https://en.wikipedia.org/wiki/Partially_ordered_set#Strict_and_non-strict_partial_orders). | ||
|
||
This trait extends the partial equivalence relation provided by `PartialEq` (`==`) with `partial_cmp(a, b) -> Option<Ordering>`, which is a [trichotomy](https://en.wikipedia.org/wiki/Trichotomy_(mathematics)) of the ordering relation when its result is `Some`: | ||
|
||
* if `a < b` then `partial_cmp(a, b) == Some(Less)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why state these as one-way implications? If anything, it should be the other way around: If
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. |
||
* if `a > b` then `partial_cmp(a, b) == Some(Greater)` | ||
* if `a == b` then `partial_cmp(a, b) == Some(Equal)` | ||
|
||
and the absence of an ordering between `a` and `b` when `partial_cmp(a, b) == None`. Furthermore, this trait defines `<=` as `a < b || a == b` and `>=` as `a > b || a == b`. | ||
|
||
The comparisons must satisfy, for all `a`, `b`, and `c`: | ||
|
||
- _transitivity_: if `a < b` and `b < c` then `a < c` | ||
- _duality_: if `a < b` then `b > a` | ||
|
||
The `lt` (`<`), `le` (`<=`), `gt` (`>`), and `ge` (`>=`) methods are implemented in terms of `partial_cmp` according to these rules. The default implementations can be overridden for performance reasons, but manual implementations must satisfy the rules above. | ||
|
||
From these rules it follows that `PartialOrd` must be implemented symmetrically and transitively: if `T: PartialOrd<U>` and `U: PartialOrd<V>` then `U: PartialOrd<T>` and `T: PartialOrd<V>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not technically false, but from " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also state this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RalfJung noticed on IRC that this condition is not enough. If That is, if Iff the user then adds an implementation of |
||
|
||
The following corollaries follow from transitivity of `<`, duality, and from the definition of `<` et al. in terms of | ||
the same `partial_cmp`: | ||
|
||
- irreflexivity of `<`: `!(a < a)` | ||
- transitivity of `>`: if `a > b` and `b > c` then `a > c` | ||
- asymmetry of `<`: if `a < b` then `!(b < a)` | ||
- antisymmetry of `<`: if `a < b` then `!(a > b)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this not be "if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, one bullet says asymmetry while the other says antisymmetry There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Antisymmetry is wrong and should be deleted. Asymmetry is the correct one. Antisymmetry is a property of total order only, and is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel the above list could be organized better. It currently requires a bit of staring to realize that one of the properties is for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. And why state irreflexivity and others nit also for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, antisymmetry is defined as "if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line with antisymmetry is wrong and should be removed. @RalfJung is correct about how antisymmetry is defined, and that's a property of total orders, not strict partial orders. |
||
|
||
Stronger ordering relations can be expressed by using the `Eq` and `Ord` traits, where the `PartialOrd` methods provide: | ||
|
||
- a [non-strict partial ordering relation](https://en.wikipedia.org/wiki/Partially_ordered_set#Strict_and_non-strict_partial_orders) if `T: PartialOrd + Eq` | ||
- a [total ordering relation](https://en.wikipedia.org/wiki/Total_order) if `T: Ord` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have the problem that
PartialOrd
is not a "strict partial ordering relation". The trait defines multiple ones. I'd also add a note about operator overloading because that's what most interesting to most users, I think.Maybe something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general: I think the first two paragraph are a bit too technical for most users. I think it would be a bit better if we first describe the trait in easy terms for the common user. For example, add something like this in the beginning:
(this is just a rough sketch to illustrate what kind of information and in what kind of formulation I mean)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be worth it to re-state here that these operators always return
bool
.