Monads¶
A monad has a unit that inserts ordinary values into a
computation and a multiplication that flattens one level of nested computation
(Moggi, 1991; Wadler, 1992). For lists, the unit makes a singleton list and the
multiplication concatenates. For distributions, the multiplication averages inner distributions by
the outer probabilities
(monads and handlers).
The module gives FuzzyPowersetMonad and KleisliCategory. FuzzyPowersetMonad requires an
IdempotentSemiring: its Kleisli category is the category of relations valued in that semiring
(Hofmann et al., 2014), its unit and multiplication are identities on finite sets, and its Kleisli
composition is the matrix product (fuzzy powerset monad).
monads
¶
Concrete monad instances on V-enriched FinSet.
The Monad typeclass itself lives in
quivers.monadic.typeclasses; this module provides two concrete
monad instances together with the KleisliCategory adapter.
FuzzyPowersetMonad: the fuzzy powerset monad over an idempotent semiring, whose Kleisli category is the category of V-relations.KleisliCategory— wraps anyMonadinstance for composition.
Both concrete monads subclass Monad and implement the
required fmap_obj / fmap / pure / join operations.
apply is inherited from Applicative and raises when the
internal-hom construction is not supplied per-instance.
FuzzyPowersetMonad
¶
FuzzyPowersetMonad(algebra: IdempotentSemiring)
Bases: Monad
The fuzzy powerset monad for an idempotent semiring V.
The V-powerset monad on sets sends A to V^A, the
V-valued fuzzy subsets of A; its Kleisli category is the
category V-Rel of V-valued relations, with Kleisli
composition the matrix composition ⋁_b f(a, b) ⊗ g(b, c) and
Kleisli identities the identity matrices [Hofmann, Seal and Tholen
(2014)]. This class works directly in that Kleisli category: an
object A stands for A, a morphism A → B over V
stands for the Kleisli arrow A → V^B, and so T(A) = A,
fmap(f) = f and η_A = μ_A = id_A.
The monad laws, and associativity of Kleisli composition, need
V-Rel to be a category, which holds when V is a semiring.
The powerset reading further needs ⋁ to be idempotent, so that
a fuzzy subset is a join of its points; on the finite carriers used
here an IdempotentSemiring is what a quantale restricts to. The
constructor therefore requires an IdempotentSemiring, such as
BOOLEAN (the ordinary powerset monad), GODEL or
TROPICAL. PRODUCT_FUZZY is refused: product does not
distribute over noisy-OR, so its Kleisli composition depends on
bracketing.
| PARAMETER | DESCRIPTION |
|---|---|
algebra
|
The enrichment algebra
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
References
Hofmann, D., Seal, G. J., and Tholen, W. (Eds.) (2014). Monoidal Topology: A Categorical Approach to Order, Metric, and Topology. Cambridge University Press. doi:10.1017/CBO9781107517288
Source code in src/quivers/monadic/monads.py
unit
¶
multiply
¶
kleisli_compose
¶
Kleisli composition, the matrix composition of V-Rel.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
A Kleisli arrow
TYPE:
|
g
|
A Kleisli arrow
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
The composite |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/monadic/monads.py
KleisliCategory
¶
KleisliCategory(monad: Monad)
The Kleisli category of a monad.
Objects are the same as the base category. Morphisms A → B in
the Kleisli category are morphisms A → T(B) in the base
category. Composition uses the underlying monad's
Monad.join, falling through to a closed-form
kleisli_compose method on the monad when available.
| PARAMETER | DESCRIPTION |
|---|---|
monad
|
The underlying monad instance.
TYPE:
|
Source code in src/quivers/monadic/monads.py
identity
¶
compose
¶
Kleisli composition.
For f : A → T(B) and g : B → T(C), returns
A → T(C) via the monad's bind / join construction.
Source code in src/quivers/monadic/monads.py
Cited sources¶
Eugenio Moggi. Notions of Computation and Monads. Information and Computation, 93(1):55–92, 1991. URL: https://www.sciencedirect.com/science/article/pii/0890540191900524, doi:10.1016/0890-5401(91)90052-4.
Philip Wadler. The Essence of Functional Programming. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1–14. ACM, 1992. URL: https://doi.org/10.1145/143165.143169, doi:10.1145/143165.143169.
Dirk Hofmann, Gavin J. Seal, and Walter Tholen, editors. Monoidal Topology: A Categorical Approach to Order, Metric, and Topology. Cambridge University Press, 2014. doi:10.1017/CBO9781107517288.