Monads¶
Monad definitions with units, multiplications, and monad laws.
monads
¶
Monads and Kleisli categories on V-enriched FinSet.
A monad (T, η, μ) consists of an endofunctor T, a unit η: Id ⇒ T, and a multiplication μ: T² ⇒ T satisfying:
μ ∘ T(μ) = μ ∘ μ_T (associativity)
μ ∘ η_T = id (left unit)
μ ∘ T(η) = id (right unit)
The Kleisli category of a monad has the same objects but morphisms A → B are morphisms A → T(B) in the base category, composed via:
f >=> g = μ_C ∘ T(g) ∘ f
This module provides:
Monad (abstract)
├── FuzzyPowersetMonad — Kleisli category = FuzzyRel
└── FreeMonoidMonad — Kleisli category = string-valued relations
KleisliCategory — wraps a monad for composition
Monad
¶
Bases: ABC
Abstract monad (T, η, μ) on V-enriched FinSet.
Subclasses must implement endofunctor, unit, and multiply. Kleisli composition is derived.
unit
abstractmethod
¶
The unit component η_A: A → T(A).
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object A.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
The unit morphism η_A. |
Source code in src/quivers/monadic/monads.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
multiply
abstractmethod
¶
The multiplication component μ_A: T(T(A)) → T(A).
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object A.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
The multiplication morphism μ_A. |
Source code in src/quivers/monadic/monads.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
kleisli_compose
¶
Kleisli composition: f >=> g = μ_C ∘ T(g) ∘ f.
For f: A → T(B) and g: B → T(C), produces A → T(C).
| PARAMETER | DESCRIPTION |
|---|---|
f
|
Left Kleisli morphism A → T(B).
TYPE:
|
g
|
Right Kleisli morphism B → T(C).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
Composed Kleisli morphism A → T(C). |
Source code in src/quivers/monadic/monads.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
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.
| PARAMETER | DESCRIPTION |
|---|---|
monad
|
The underlying monad.
TYPE:
|
Source code in src/quivers/monadic/monads.py
123 124 | |
identity
¶
Kleisli identity at object A: η_A: A → T(A).
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object A.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
The Kleisli identity morphism. |
Source code in src/quivers/monadic/monads.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
compose
¶
Kleisli composition: f >=> g.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
Left morphism A → T(B).
TYPE:
|
g
|
Right morphism B → T(C).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Morphism
|
Composed morphism A → T(C). |
Source code in src/quivers/monadic/monads.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
FuzzyPowersetMonad
¶
FuzzyPowersetMonad(quantale: Quantale | None = None)
Bases: Monad
The fuzzy powerset monad with a given quantale.
At the set level, T(A) = A because fuzzy subsets are represented as membership function tensors, not as elements of a powerset. The unit η_A = identity(A) and the multiplication μ_A = identity(A).
The Kleisli composition f >=> g reduces to quantale.compose(f, g), which is exactly the >> operator on morphisms.
| PARAMETER | DESCRIPTION |
|---|---|
quantale
|
The enrichment algebra. Defaults to PRODUCT_FUZZY.
TYPE:
|
Source code in src/quivers/monadic/monads.py
180 181 | |
unit
¶
η_A = identity(A): Kronecker delta.
Source code in src/quivers/monadic/monads.py
193 194 195 | |
multiply
¶
μ_A = identity(A): union of fuzzy sets.
Source code in src/quivers/monadic/monads.py
197 198 199 | |
kleisli_compose
¶
Kleisli composition = V-enriched composition via >>.
Source code in src/quivers/monadic/monads.py
201 202 203 | |
FreeMonoidMonad
¶
FreeMonoidMonad(max_length: int)
Bases: Monad
The free monoid monad, truncated to max_length.
T(A) = FreeMonoid(generators=A, max_length=max_length) = 1 + A + A² + ... + A^max_length. η_A: A → A embeds each element as a length-1 word. μ_A: (A) → A flattens nested words by concatenation (truncated to max_length).
| PARAMETER | DESCRIPTION |
|---|---|
max_length
|
Maximum string length for the truncated free monoid.
TYPE:
|
Source code in src/quivers/monadic/monads.py
226 227 228 | |
unit
¶
η_A: A → A* embeds each element as a length-1 word.
The tensor has shape (|A|, |A*|) with 1 at positions (a, offset_1 + a) and 0 elsewhere.
Source code in src/quivers/monadic/monads.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
multiply
¶
μ_A: (A) → A* flattens nested words by concatenation.
A word in (A) at stratum k is a k-tuple of words in A*. Flattening concatenates them. If the total length exceeds max_length, the entry is 0 (truncation).
Source code in src/quivers/monadic/monads.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
kleisli_compose
¶
Kleisli composition: f >=> g = μ_C ∘ T(g) ∘ f.
Source code in src/quivers/monadic/monads.py
288 289 290 291 292 293 | |