cat/algebra
Isomorphisms
(morphisms that are invertible) describing various equations.
Algebra on Types (Void = 0, Nil = 1, Bool = 2, Either(a, b) = a + b, Pair(a, b) = a * b, Maybe(a) = 1 + a, Isomorphism = ==, Function fn(a) -> b = Exponential b ^ 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 composition(
p: Pair(fn(a) -> b, fn(b) -> Void),
) -> fn(a) -> Void
Modus Tollens
.
(a -> b) ∧ ¬b -> ¬a
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 epsilon(
f: fn(Either(a, b)) -> c,
) -> Pair(fn(a) -> c, fn(b) -> c)
Exponentials of Sums
.
a ^ (b + c) = (a ^ b) * (a ^ c)
pub fn epsilon_inv(
p: Pair(fn(a) -> b, fn(c) -> b),
) -> fn(Either(a, c)) -> b
Inverse Exponentials of Sums
.
(a ^ b) * (a ^ c) = a ^ (b + c)
pub fn gamma(m: Maybe(a)) -> Either(Const(Nil, b), Identity(a))
Morphism from Maybe b
to Either (Const () a) (Identity b)
.
pub fn gamma_inv(
e: Either(Const(Nil, a), Identity(b)),
) -> Maybe(b)
Inverse morphism from Either (Const () a) (Idenity b)
to Maybe b
.
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 omicron(f: fn(a) -> fn(b) -> c) -> fn(Pair(b, a)) -> c
Exponentials of Exponentials
.
(a ^ b) ^ c = a ^ (b * c)
pub fn omicron_inv(g: fn(Pair(a, b)) -> c) -> fn(b) -> fn(a) -> c
Inverse Exponentials of Exponentials
.
(a ^ b) ^ c = a ^ (b * c)
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_inv(x: a) -> Either(a, Void)
Inverse morphism from a
to Either(a, Void)
.
a = a + 0
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")
pub fn transitivity(
p: Pair(fn(a) -> b, fn(b) -> c),
) -> fn(a) -> c
Chain Rule
.
(a -> b) ∧ (b -> c) -> (a -> c)
pub fn upsilon(
f: fn(a) -> Pair(b, c),
) -> Pair(fn(a) -> b, fn(a) -> c)
Exponentials over Products
.
(a * b) ^ c = (a ^ c) * (b ^ c)
pub fn upsilon_inv(
g: Pair(fn(a) -> b, fn(a) -> c),
) -> fn(a) -> Pair(b, c)
Inverse Exponentials over Products
.
(a ^ c) * (b ^ c) = (a * b) ^ c