Skip to content
This repository was archived by the owner on Sep 24, 2026. It is now read-only.

Honest partial-order support + explicit empty ranges - #10

Merged
adriendellagaspera merged 1 commit into
masterfrom
partial-rcmp
May 31, 2026
Merged

adriendellagaspera merged 1 commit into
masterfrom
partial-rcmp

Conversation

@adriendellagaspera

@adriendellagaspera adriendellagaspera commented Nov 8, 2023 •

Copy link
Copy Markdown
Member

Motivation

This PR started as "introduce range comparison for PartialOrd (partial_rcmp)". While
reviewing it, two issues surfaced:

  1. Empty ranges were handled dishonestly by rcmp: the result was an arbitrary,
    representation-dependent Below/Above (e.g. 30.rcmp(45..35) → Below but
    30.rcmp(25..15) → Above).
  2. The proposed partial_rcmp -> Option<RangeOrdering> is leaky: Below/Inside/Above
    is a total-order notion. Over a poset, a value can be incomparable with one or both
    bounds, and Option collapses "incomparable with the whole range" together with
    "comparable with one bound, incomparable with the other" — losing information and
    sometimes giving a misleading partial answer.

Both problems are solved by a single idea: represent a value's position as the pair of
its relationships to the lower and upper bounds
.

Changes

  • New core types
    • BoundOrdering — Within / Outside / Incomparable (the last only occurs for
      PartialOrd types).
    • RangePosition — the { lower, upper } pair, with:
      • ordering() -> Option<RangeOrdering> to collapse into a simple verdict when both
        bounds are comparable;
      • is_inside().
  • Empty ranges: RangeOrdering gains an Empty variant. rcmp (for Ord) now
    detects empty ranges from their bounds and returns Empty, and never falsely returns
    Inside for an empty range. Emptiness is judged from the bounds, not the population of
    the type (so ..0u32 stays a regular range).
  • Partial orders: new PartialRangeOrd trait with
    partial_rcmp -> RangePosition for every PartialOrd type, preserving per-bound
    information instead of discarding it in an Option.
  • Tests: the partial suite is converted to the new type, the previously-empty test
    stubs are filled in, and the comparable-to-one-bound-only cases (the ones the old
    Option design lost) are added explicitly.
  • Docs: README/lib examples updated; fixed the pre-existing name drift between the
    README (RangeComparable/range_cmp) and the code (RangeOrd/rcmp).

Notes

  • Breaking change → version bumped to 0.3.0. RangeOrdering gaining Empty breaks
    exhaustive matches (intentional: it forces callers to consider emptiness).
  • Asymmetry by design: rcmp (total order) detects emptiness explicitly, whereas
    partial_rcmp does not attempt it — over a poset, "is this range empty?" can be
    undecidable (the bounds themselves may be incomparable). For the partial case, Empty
    only surfaces via the (Outside, Outside) witness through ordering().

https://claude.ai/code/session_01CTKxSkrLTyauoiGSFo2dVS

@adriendellagaspera
adriendellagaspera force-pushed the partial-rcmp branch 2 times, most recently from f9d5c9f to bd07b70 Compare November 8, 2023 12:56
The crate previously returned an arbitrary, representation-dependent answer
for empty ranges, and PR10's `partial_rcmp -> Option<RangeOrdering>` collapsed
a poset position into a single ambiguous verdict, conflating "incomparable
with the whole range" with "comparable with one bound, incomparable with the
other".

Both issues are addressed with a single core idea: represent a value's
position as the *pair* of its relationships to the lower and upper bounds.

- Add `BoundOrdering` (Within / Outside / Incomparable) and `RangePosition`
  (the lower/upper pair), with `RangePosition::ordering()` collapsing to a
  simple verdict when both bounds are comparable, and `is_inside()`.
- `RangeOrdering` gains an `Empty` variant. `rcmp` (Ord) now detects empty
  ranges from their bounds and reports `Empty` instead of a bogus
  Below/Above, and never falsely reports `Inside` for an empty range.
- Introduce `PartialRangeOrd::partial_rcmp -> RangePosition` for `PartialOrd`
  types, preserving per-bound information instead of losing it in an `Option`.
- Tests: convert the partial suite to the new type, complete the previously
  empty stubs, and add the comparable-to-one-bound-only cases that the old
  design lost. Fix the README/code name drift (`RangeComparable`/`range_cmp`).

This is a breaking change; bump to 0.3.0.

https://claude.ai/code/session_01CTKxSkrLTyauoiGSFo2dVS
@adriendellagaspera adriendellagaspera changed the title Introduce range comparison for PartialOrd Honest partial-order support + explicit empty ranges May 31, 2026
@adriendellagaspera
adriendellagaspera marked this pull request as ready for review May 31, 2026 22:58
@adriendellagaspera
adriendellagaspera merged commit 5570da5 into master May 31, 2026
2 checks passed
@adriendellagaspera
adriendellagaspera deleted the partial-rcmp branch May 31, 2026 22:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants