cat/algebra

This module contains various isomorphisms (morphisms that are invertible). Algebra on Types (Void = 0, Nil = 1, Bool = 2, Either(a, b) = a + b, Pair(a, b) = a * b, Maybe(a) = 1 + a)

Functions

pub fn alpha(p: Pair(a, Pair(b, c))) -> Pair(Pair(a, b), c)

Associativity up to isomorphism of nested Pairs.
a * (b * c) = (a * b) * c

pub fn alpha_inv(p: Pair(Pair(a, b), c)) -> Pair(a, Pair(b, c))

Inverse associativity up to isomorphism of nested Pairs.
(a * b) * c = a * (b * c)

pub fn beta(
  e1: Either(a, Either(b, c)),
) -> Either(Either(a, b), c)

Associativity up to isomorphism of nested Eithers.
a + (b + c) = (a + b) + c

pub fn beta_inv(
  e1: Either(Either(a, b), c),
) -> Either(a, Either(b, c))

Inverse associativity up to isomorphism of nested Eithers.
(a + b) + c = a + (b + c)

pub fn delta(e: Either(a, a)) -> Pair(Bool, a)

Morphism from Either(a, a) to Pair(Bool, a).
a + a = 2 * a

pub fn delta_inv(p: Pair(Bool, a)) -> Either(a, a)

Morphism from Pair(Bool, a) to Either(a, a).
2 * a = a + a

pub fn omega(m: Maybe(a)) -> Either(Nil, a)

Morphism from Maybe(a) to Either(Nil, a).
1 + a

pub fn omega_inv(e: Either(Nil, a)) -> Maybe(a)

Inverse morphism from Either(Nil, a) to Maybe(a).
1 + a

pub fn product_to_sum(
  p: Pair(a, Either(b, c)),
) -> Either(Pair(a, b), Pair(a, c))

Distributivity up to isomorphism.
a * (b + c) = a * b + a * c

pub fn psi(e: Either(a, Void)) -> a

Morphism from Either(a, Void) to a.
a + 0 = a

pub fn psi_inv(x: a) -> Either(a, Void)

Inverse morphism from a to Either(a, Void).
a = a + 0

pub fn rho(p: Pair(a, Nil)) -> a

Morphism from (a, ()) to a.
a * 1 = a

pub fn rho_inv(x: a) -> Pair(a, Nil)

Inverse morphism from a to (a, ()).
a = a * 1

pub fn sum_to_product(
  e: Either(Pair(a, b), Pair(a, c)),
) -> Pair(a, Either(b, c))

Inverse distributivity up to isomorphism.
a * b + a * c = a * (b + c)

pub fn swap(p: Pair(a, b)) -> Pair(b, a)

Commutativity up to isomorphism for Pair.
a * b = b * a

Examples

swap(Pair(5, "abc"))
// -> Pair("abc", 5)
pub fn switch(e: Either(a, b)) -> Either(b, a)

Commutativity up to isomorphism for Either.
a + b = b + a

Examples

swap(Left(5))
// -> Right(5)
swap(Right("abc"))
// -> Left("abc")
Search Document