MyNixOS website logo
Description

Axiomata & lemmata for easier use of Data.Type.Ord.

When using Data.Type.Ord, there are many facts one intuitively expects to hold that GHC is not clever enough to infer. We rectify this situation with a TotalOrder typeclass providing axiomata with which such facts may be proven to GHC.

ord-axiomata

When using Data.Type.Ord, there are many facts one intuitively expects to hold that GHC is not clever enough to infer.

We rectify this situation with TotalOrder and related typeclasses that not only enable comparison of singletons, but also provide axiomata allowing one to safely prove such facts to GHC.

Axiomata

Due to GHC/Haskell specific details and the expression of equivalence and ordering in terms of Compare, the phrasing of the axiomata is a little different than usual—many are reduced to consistency conditions with ~ and the following definitions.

$$ \begin{alignat*}{3} &a < b &&\iff &&\mathrm{Compare} \kern3pt a \kern3pt b \sim \mathrm{LT} \\ &a = b &&\iff &&\mathrm{Compare} \kern3pt a \kern3pt b \sim \mathrm{EQ} \\ &a > b &&\iff &&\mathrm{Compare} \kern3pt a \kern3pt b \sim \mathrm{GT} \
&a \leq b &&\iff &&a < b \lor a = b \\ &a \neq b &&\iff &&a < b \lor a > b \
&a \geq b &&\iff &&a = b \lor a > b \end{alignat*} $$

Equivalence

$$ \begin{alignat*}{3} &\text{decidability} \quad\quad\quad && \forall a, b. \kern6pt && a = b \lor a \neq b \
&\text{reflexivity} \quad\quad\quad && \forall a, b. \kern6pt && a \sim b \implies a = b \
&\text{substitutability} \quad\quad\quad && \forall a, b. \kern6pt && a = b \implies a \sim b \
\end{alignat*} $$

Total Ordering

$$ \begin{alignat*}{3} &\text{connectivity} \quad\quad\quad && \forall a, b. \kern6pt && a < b \lor a = b \lor a > b \
&\text{anti-symmetry of $\lt$/$\gt$} \quad\quad\quad && \forall a, b. \kern6pt && a < b \iff b > a \
&\text{transitivity of $\leq$} \quad\quad\quad && \forall a, b, c. \kern6pt && a \leq b \land b \leq c \implies a \leq c \
\end{alignat*} $$

Bounding

$$ \begin{alignat*}{3} &\text{bounded below} \quad\quad\quad && \exists b_l \forall a. \kern6pt && b_l \leq a \
&\text{bounded above} \quad\quad\quad && \exists b_u \forall a. \kern6pt && a \leq b_u \
\end{alignat*} $$

Lemmata

With the above at our disposal, we can prove general, reusable facts.

Equivalence

$$ \begin{alignat*}{3} &\text{symmetry of $=$} \quad\quad\quad && \forall a, b. \kern6pt && a = b \iff b = a \
&\text{symmetry of $\neq$} \quad\quad\quad && \forall a, b. \kern6pt && a \neq b \iff b \neq a \
&\text{transitivity of $=$} \quad\quad\quad && \forall a, b, c. \kern6pt && a = b \land b = c \implies a = c \
\end{alignat*} $$

Ordering

Reflection

$$ \begin{alignat*}{3} &\text{anti-symmetry of $\leq$/$\geq$} \quad\quad\quad && \forall a, b. \kern6pt && a \leq b \iff b \geq a \end{alignat*} $$

Transitivity

$$ \begin{alignat*}{3} &\text{transitivity of $\lt$} \quad\quad\quad && \forall a, b, c. \kern6pt && a \lt b \land b \lt c \implies a \lt c \
&\text{transitivity of $\gt$} \quad\quad\quad && \forall a, b, c. \kern6pt && a \gt b \land b \gt c \implies a \gt c \
&\text{transitivity of $\geq$} \quad\quad\quad && \forall a, b, c. \kern6pt && a \geq b \land b \geq c \implies a \geq c \
\end{alignat*} $$

Properties of Minimum

$$ \begin{alignat*}{3} &\text{deflationary} \quad\quad\quad && \forall a, b. \kern6pt && \mathrm{min} \kern3pt a \kern3pt b \leq a, b \
&\text{monotonicity} \quad\quad\quad && \forall a, b, c, d. \kern6pt && a \leq c \land b \leq d \implies \mathrm{min} \kern3pt a \kern3pt b \leq \mathrm{min} \kern3pt c \kern3pt d \
&\text{symmetry} \quad\quad\quad && \forall a, b. \kern6pt && \mathrm{min} \kern3pt a \kern3pt b \sim \mathrm{min} \kern3pt b \kern3pt a \
\end{alignat*} $$

Properties of Maximum

$$ \begin{alignat*}{3} &\text{inflationary} \quad\quad\quad && \forall a, b. \kern6pt && a, b \leq \mathrm{max} \kern3pt a \kern3pt b \
&\text{monotonicity} \quad\quad\quad && \forall a, b, c, d. \kern6pt && a \leq c \land b \leq d \implies \mathrm{max} \kern3pt a \kern3pt b \leq \mathrm{max} \kern3pt c \kern3pt d \
&\text{symmetry} \quad\quad\quad && \forall a, b. \kern6pt && \mathrm{max} \kern3pt a \kern3pt b \sim \mathrm{max} \kern3pt b \kern3pt a \
\end{alignat*} $$

Metadata

Version

0.1.0.0

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows