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)
Values
pub fn alpha(
p: cat.Pair(a, cat.Pair(b, c)),
) -> cat.Pair(cat.Pair(a, b), c)
Associativity up to isomorphism
of nested Pairs.
a * (b * c) = (a * b) * c
pub fn alpha_inv(
p: cat.Pair(cat.Pair(a, b), c),
) -> cat.Pair(a, cat.Pair(b, c))
Inverse associativity up to isomorphism
of nested Pairs.
(a * b) * c = a * (b * c)
pub fn beta(
e1: cat.Either(a, cat.Either(b, c)),
) -> cat.Either(cat.Either(a, b), c)
Associativity up to isomorphism
of nested Eithers.
a + (b + c) = (a + b) + c
pub fn beta_inv(
e1: cat.Either(cat.Either(a, b), c),
) -> cat.Either(a, cat.Either(b, c))
Inverse associativity up to isomorphism
of nested Eithers.
(a + b) + c = a + (b + c)
pub fn composition(
p: cat.Pair(fn(a) -> b, fn(b) -> cat.Void),
) -> fn(a) -> cat.Void
Modus Tollens
.
(a -> b) ∧ ¬b -> ¬a
pub fn delta(e: cat.Either(a, a)) -> cat.Pair(Bool, a)
Morphism from Either(a, a)
to Pair(Bool, a)
.
a + a = 2 * a
pub fn delta_inv(p: cat.Pair(Bool, a)) -> cat.Either(a, a)
Morphism from Pair(Bool, a)
to Either(a, a)
.
2 * a = a + a
pub fn epsilon(
f: fn(cat.Either(b, c)) -> a,
) -> cat.Pair(fn(b) -> a, fn(c) -> a)
Exponentials of Sums
.
a ^ (b + c) = (a ^ b) * (a ^ c)
pub fn epsilon_inv(
p: cat.Pair(fn(b) -> a, fn(c) -> a),
) -> fn(cat.Either(b, c)) -> a
Inverse Exponentials of Sums
.
(a ^ b) * (a ^ c) = a ^ (b + c)
pub fn gamma(
m: cat.Maybe(b),
) -> cat.Either(cat.Const(Nil, a), cat.Identity(b))
Morphism from Maybe b
to Either (Const () a) (Identity b)
.
pub fn gamma_inv(
e: cat.Either(cat.Const(Nil, a), cat.Identity(b)),
) -> cat.Maybe(b)
Inverse morphism from Either (Const () a) (Idenity b)
to Maybe b
.
pub fn omega(m: cat.Maybe(a)) -> cat.Either(Nil, a)
Morphism from Maybe(a)
to Either(Nil, a)
.
1 + a
pub fn omega_inv(e: cat.Either(Nil, a)) -> cat.Maybe(a)
Inverse morphism from Either(Nil, a)
to Maybe(a)
.
1 + a
pub fn omicron(f: fn(c) -> fn(b) -> a) -> fn(cat.Pair(b, c)) -> a
Exponentials of Exponentials
.
(a ^ b) ^ c = a ^ (b * c)
pub fn omicron_inv(
g: fn(cat.Pair(b, c)) -> a,
) -> fn(c) -> fn(b) -> a
Inverse Exponentials of Exponentials
.
(a ^ b) ^ c = a ^ (b * c)
pub fn product_to_sum(
p: cat.Pair(a, cat.Either(b, c)),
) -> cat.Either(cat.Pair(a, b), cat.Pair(a, c))
Distributivity up to isomorphism
.
a * (b + c) = a * b + a * c
pub fn psi_inv(x: a) -> cat.Either(a, cat.Void)
Inverse morphism from a
to Either(a, Void)
.
a = a + 0
pub fn sum_to_product(
e: cat.Either(cat.Pair(a, b), cat.Pair(a, c)),
) -> cat.Pair(a, cat.Either(b, c))
Inverse distributivity up to isomorphism
.
a * b + a * c = a * (b + c)
pub fn swap(p: cat.Pair(a, b)) -> cat.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: cat.Either(a, b)) -> cat.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: cat.Pair(fn(a) -> b, fn(b) -> c),
) -> fn(a) -> c
Chain Rule
.
(a -> b) ∧ (b -> c) -> (a -> c)
pub fn upsilon(
f: fn(c) -> cat.Pair(a, b),
) -> cat.Pair(fn(c) -> a, fn(c) -> b)
Exponentials over Products
.
(a * b) ^ c = (a ^ c) * (b ^ c)