Documentation

Hale.Base.Data.Ord

structure Data.Down (α : Type u) :

Down α reverses the ordering of α.

If $a \leq b$ in α, then $\text{Down}(b) \leq \text{Down}(a)$. Useful for sorting in descending order without custom comparators. $$\text{compare}_{\text{Down}}(x, y) = \text{compare}(y, x)$$

  • getDown : α

    Unwrap the reversed-order value.

Instances For
    def Data.instReprDown.repr {α✝ : Type u_1} [Repr α✝] :
    Down α✝NatStd.Format
    Equations
    Instances For
      @[implicit_reducible]
      instance Data.instReprDown {α✝ : Type u_1} [Repr α✝] :
      Repr (Down α✝)
      Equations
      def Data.instHashableDown.hash {α✝ : Type u_1} [Hashable α✝] :
      Down α✝UInt64
      Equations
      Instances For
        @[implicit_reducible]
        instance Data.instHashableDown {α✝ : Type u_1} [Hashable α✝] :
        Hashable (Down α✝)
        Equations
        @[implicit_reducible]
        instance Data.Down.instBEq {α : Type u_1} [BEq α] :
        BEq (Down α)
        Equations
        @[implicit_reducible]
        instance Data.Down.instOrd {α : Type u_1} [Ord α] :
        Ord (Down α)

        Reversed ordering: compares in the opposite direction.

        Equations
        @[implicit_reducible]
        instance Data.Down.instToString {α : Type u_1} [ToString α] :
        Equations
        theorem Data.Down.get_mk {α : Type u_1} (a : α) :
        { getDown := a }.getDown = a

        Wrapping and unwrapping Down is identity. $$\text{getDown}(\text{Down}(x)) = x$$

        theorem Data.Down.compare_reverse {α : Type u_1} [Ord α] (a b : Down α) :

        Down comparison reverses the arguments.

        @[inline]
        def Data.comparing {β : Type u_1} {α : Sort u_2} [Ord β] (f : αβ) (x y : α) :

        Compare two values by first applying a projection function. $$\text{comparing}(f, x, y) = \text{compare}(f(x), f(y))$$

        Useful with sorting: list.mergeSort (comparing SomeStruct.field)

        Equations
        Instances For
          def Data.clamp {α : Type u_1} [LE α] [DecidableRel fun (x1 x2 : α) => x1 x2] (x lo hi : α) (hle : lo hi) (refl : ∀ (a : α), a a) (total : ∀ (a b : α), ¬a bb a) :
          { y : α // lo y y hi }

          Clamp a value to the interval $[\text{lo}, \text{hi}]$.

          Returns a subtype proving the result lies within bounds: $$\text{clamp}(x, lo, hi) = \begin{cases} lo & \text{if } x \leq lo \\ hi & \text{if } x \geq hi \\ x & \text{otherwise} \end{cases}$$

          Precondition: lo ≤ hi (provided as proof). Guarantee: The returned value y satisfies lo ≤ y ∧ y ≤ hi.

          Equations
          Instances For