Skip to content

Add structures/bundles for pairs of strict and non-strict orders #1179

Open

Description

@MatthewDaggitt

Currently, whenever we have a generic proof that involves both a non-strict and a strict order we translate from one to the other using Relation.Binary.Construct.NonStrictToStrict/StrictToNonStrict. This works fine for generic data, but runs into serious problems when dealing with data where the non-strict and strict orders exploit some structure of the data and are therefore not defined in that way. The most common examples are our numeric datatypes.

Currently we've been getting around this by adding specialised modules for each of the numeric datatypes, e.g. Data.List.Extrema.Nat, but this doesn't scale very well as it requires a module for each problematic datatype.

I propose adding some additional relational structures/bundles to the library along the following lines (names are definitely open for discussion!):

record IsStrictNonStrictPair (_≤_ : Rel A ℓ₂) (_<_ : Rel A ℓ₃) : Set (a ⊔ ℓ ⊔ ℓ₂ ⊔ ℓ₃) where
   field
    <⇒≉    : _<_ ⇒ _≉_
    <⇒≤    : _<_ ⇒ _≤_
    ≤∧≉⇒<  : ∀ {x y} → x ≤ y → x ≉ y → x < y
record IsTotalOrderPair (_≤_ : Rel A ℓ₂) (_<_ : Rel A ℓ₃) : Set (a ⊔ ℓ ⊔ ℓ₂ ⊔ ℓ₃) where
  field
    isTotalOrder          : IsTotalOrder _≤_
    isStrictTotalOrder    : IsStrictTotalOrder _<_
    isStrictNonStrictPair : IsStrictNonStrictPair _≤_ _<_

This would then allow us to prove these properties once, rather than having a specialisation for each datatype.

Activity

  1. gallais commented on Apr 29, 2020

    @gallais
    Member

    Is _≉_ from a setoid? So it's more like a triple than a pair then.

  2. added this to the v2.0 milestone on Jul 11, 2021
  3. modified the milestones: v2.0, v3.0 on Sep 12, 2022
  4. jamesmckinna commented on Jul 9, 2026

    @jamesmckinna
    Collaborator

    Is _≉_ from a setoid? So it's more like a triple than a pair then.

    Well, our methodology, when it's working, sees ...Structures parametrised on the ambient _ ≈_, for which it is indeed canonical that _≉_ be defined as its negation, either locally in-place, or else a defintional extension of the underlying RawRelation/RawSetoid defined by _≈_. Cf. #2274 .

    Relative to such parameterisation (and see #3053 for a higher-level view of the design issues involved), I think it would still make sense to think of these as 'pair'ed' rather than 'triple'd... but agree that a better name is required! And that the proposal is, on its face, a good one. Devils in the details?

  5. JacquesCarette commented on Jul 9, 2026

    @JacquesCarette
    Collaborator

    Oh, I've looked for this too! I definitely have a need for IsTotalOrderPair.

    I agree that it a bit odd to call it a pair as it is a predicate on the parameters, of which there are 3 (or even 4 if you count the carrier separately). However, I think that since much of the library is "relative to a given Setoid", it makes a certain amount of sense to not count it.

    Looking up synonyms: we could go with 'Duo' or 'Dyad' for the relative case? [I'm fine with 'Pair', but would prefer a fulsome discussion.]

  6. jamesmckinna commented on Jul 9, 2026

    @jamesmckinna
    Collaborator

    And... given such a structure/bundle, there should be a 'unified' Reasoning syntax for all the various relational steps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions