maths.freeCategory Theory › Structures › Monad (category theory)

Monad (category theory)

In category theory, a branch of mathematics, a monad is a triple consisting of a functor T from a category to itself and two natural transformations that satisfy versions of the associativity and unitality axioms.

Monad (category theory)

In category theory, a branch of mathematics, a monad is a triple \((T, \eta, \mu)\) consisting of a functor T from a category to itself and two natural transformations \(\eta, \mu\) that satisfy versions of the associativity and unitality axioms. Equivalently, a monad is a monoid in the category of endofunctors of some fixed category (an endofunctor is a functor mapping a category to itself).

For example, if \(F, G\) are functors adjoint to each other, then \(T = G \circ F\) together with \(\eta, \mu\) determined by the adjoint relation is a monad.

According to mathematician John Baez, a monad can be considered at least in two ways:

  1. A monad as a generalized monoid; this is clear since a monad is a monoid in a certain category,
  2. A monad as a tool for studying algebraic gadgets; for example, a group can be described by a certain monad.

Monads are used in the theory of pairs of adjoint functors, and they generalize closure operators on partially ordered sets to arbitrary categories. Monads are also useful in the theory of datatypes, the denotational semantics of imperative programming languages, and in functional programming languages, allowing languages without mutable state to do things such as simulate for-loops; see Monad (functional programming).

A monad is also called, especially in old literature, a triple, triad, standard construction and fundamental construction.

Introduction and definition

A monad is a certain type of endofunctor. For example, if \(F\) and \(G\) are a pair of adjoint functors, with \(F\) left adjoint to \(G\), then the composition \(G \circ F\) is a monad. If \(F\) and \(G\) are inverse to each other, the corresponding monad is the identity functor. In general, adjunctions are not equivalences, they relate categories of different natures. The monad theory matters as part of the effort to capture what it is that adjunctions 'preserve'. The other half of the theory, of what can be learned likewise from consideration of \(F \circ G\), is discussed under the dual theory of comonads.

Formal definition

Throughout this article, \(C\) denotes a category. A monad on \(C\) consists of an endofunctor \(T \colon C \to C\) together with two natural transformations: \(\eta \colon 1_{C} \to T\) (where \(1_{C}\) denotes the identity functor on \(C\)) and \(\mu \colon T^{2} \to T\) (where \(T^{2}\) is the functor \(T \circ T\) from \(C\) to \(C\)). These are required to fulfill the following conditions (sometimes called coherence conditions):

  • \(\mu \circ T\mu = \mu \circ \mu T\) (as natural transformations \(T^{3} \to T\)); here \(T\mu\) and \(\mu T\) are formed by "horizontal composition".
  • \(\mu \circ T \eta = \mu \circ \eta T = 1_{T}\) (as natural transformations \(T \to T\); here \(1_{T}\) denotes the identity transformation from \(T\) to \(T\)).

We can rewrite these conditions using the following commutative diagrams:

See the article on natural transformations for the explanation of the notations \(T\mu\) and \(\mu T\), or see below the commutative diagrams not using these notions:

The first axiom is akin to the associativity in monoids if we think of \(\mu\) as the monoid's binary operation, and the second axiom is akin to the existence of an identity element (which we think of as given by \(\eta\)). Indeed, a monad on \(C\) can alternatively be defined as a monoid in the category \(\mathbf{End}_{C}\) whose objects are the endofunctors of \(C\) and whose morphisms are the natural transformations between them, with the monoidal structure induced by the composition of endofunctors.

The power set monad

The power set monad is a monad \(\mathcal{P}\) on the category \(\mathbf{Set}\): For a set \(A\) let \(T(A)\) be the power set of \(A\) and for a function \(f \colon A \to B\) let \(T(f)\) be the function between the power sets induced by taking direct images under \(f\). For every set \(A\), we have a map \(\eta_{A} \colon A \to T(A)\), which assigns to every \(a\in A\) the singleton \(\{a\}\). The function

\(\mu_{A} \colon T(T(A)) \to T(A)\)

takes a set of sets to its union. These data describe a monad.

Remarks

The axioms of a monad are formally similar to the monoid axioms. In fact, monads are a type of monoid object; they are precisely the monoids among endofunctors \(\operatorname{End}(C)\), with the multiplication given by composition of endofunctors.

Composition of monads is not, in general, a monad. For example, the double power set functor \(\mathcal{P} \circ \mathcal{P}\) does not admit any monad structure.

Comonads

The categorical dual definition is a formal definition of a comonad (or cotriple); this can be said quickly in the terms that a comonad for a category \(C\) is a monad for the opposite category \(C^{\mathrm{op}}\). It is therefore a functor \(U\) from \(C\) to itself, with a set of axioms for counit and comultiplication that come from reversing the arrows everywhere in the definition just given.

Monads are to monoids as comonads are to comonoids. Every set is a comonoid in a unique way, so comonoids are less familiar in abstract algebra than monoids; however, comonoids in the category of vector spaces with its usual tensor product are important and widely studied under the name of coalgebras.

Terminological history

The notion of monad was invented by Roger Godement in 1958 under the name "standard construction". Monad has been called "dual standard construction", "triple", "monoid" and "triad". The term "monad" is used at latest 1967, by Jean Bénabou.

Monads arising from adjunctions

Any adjunction

\(F: C \rightleftarrows D : G\)

gives rise to a monad on C. This very widespread construction works as follows: the endofunctor is the composite

\(T = G \circ F.\)

This endofunctor is quickly seen to be a monad, where the unit map stems from the unit map \(\operatorname{id}_C \to G \circ F\) of the adjunction, and the multiplication map is constructed using the counit map of the adjunction:

\(T^2 = G \circ F \circ G \circ F \xrightarrow{G \circ \text{counit} \circ F} G \circ F = T.\)

In fact, any monad can be found as an explicit adjunction of functors using the Eilenberg-Moore category \(C^T\) (the category of \(T\)-algebras).

Codensity monads

Under mild conditions, functors not admitting a left adjoint also give rise to a monad, the so-called codensity monad. For example, the inclusion

\(\mathbf{FinSet} \subset \mathbf{Set}\)

does not admit a left adjoint. Its codensity monad is the monad on sets sending any set X to the set of ultrafilters on X. This and similar examples are discussed in Leinster (2013).

Monads used in denotational semantics

The following monads over the category of sets are used in denotational semantics of imperative programming languages, and analogous constructions are used in functional programming.

Algebras for a monad

Given a monad \((T,\eta,\mu)\) on a category \(C\), it is natural to consider \(T\)-algebras, i.e., objects of \(C\) acted upon by \(T\) in a way which is compatible with the unit and multiplication of the monad. More formally, a \(T\)-algebra \((x,h)\) is an object \(x\) of \(C\) together with an arrow \(h\colon Tx\to x\) of \(C\) called the structure map of the algebra such that the diagrams

commute.

A morphism \(f\colon (x,h)\to(x',h')\) of \(T\)-algebras is an arrow \(f\colon x\to x'\) of \(C\) such that the diagram

commutes. \(T\)-algebras form a category called the Eilenberg-Moore category and denoted by \(C^T\).

Monads and adjunctions

As was mentioned above, any adjunction gives rise to a monad. Conversely, every monad arises from some adjunction, namely the free, forgetful adjunction

\(T(-) : C \rightleftarrows C^T : \text{forget}\)

whose left adjoint sends an object X to the free T-algebra T(X). However, there are usually several distinct adjunctions giving rise to a monad: let \(\mathbf{Adj}(C,T)\) be the category whose objects are the adjunctions \((F,G,e,\varepsilon)\) such that \((GF, e, G\varepsilon F)=(T,\eta,\mu)\) and whose arrows are the morphisms of adjunctions that are the identity on \(C\). Then the above free, forgetful adjunction involving the Eilenberg-Moore category \(C^T\) is a terminal object in \(\mathbf{Adj}(C,T)\). An initial object is the Kleisli category, which is by definition the full subcategory of \(C^T\) consisting only of free T-algebras, i.e., T-algebras of the form \(T(x)\) for some object x of C.

Monadic adjunctions

Given any adjunction \((F : C \to D,G : D \to C,\eta,\varepsilon)\) with associated monad T, the functor G can be factored as

\(D \overset{\widetilde{G}}\longrightarrow C^T \xrightarrow{\text{forget}} C,\)

i.e., G(Y) can be naturally endowed with a T-algebra structure for any Y in D. The adjunction is called a monadic adjunction if the first functor \(\tilde G\) yields an equivalence of categories between D and the Eilenberg-Moore category \(C^T\). By extension, a functor \(G\colon D\to C\) is said to be monadic if it has a left adjoint F forming a monadic adjunction. For example, the free, forgetful adjunction between groups and sets is monadic, since algebras over the associated monad are groups, as was mentioned above. In general, knowing that an adjunction is monadic allows one to reconstruct objects in D out of objects in C and the T-action.

Beck's monadicity theorem

Beck's monadicity theorem gives a necessary and sufficient condition for an adjunction to be monadic. A simplified version of this theorem states that G is monadic if and only if it is conservative (or G reflects isomorphisms, i.e., a morphism in D is an isomorphism if and only if its image under G is an isomorphism in C) and G preserves coequalizers.

For example, the forgetful functor from the category of compact Hausdorff spaces to sets is monadic. However the forgetful functor from all topological spaces to sets is not conservative since there are continuous bijective maps (between non-compact or non-Hausdorff spaces) that fail to be homeomorphisms. Thus, this forgetful functor is not monadic. The dual version of Beck's theorem, characterizing comonadic adjunctions, is relevant in different fields such as topos theory and topics in algebraic geometry related to descent. A first example of a comonadic adjunction is the adjunction

\(- \otimes_A B : \mathbf{Mod}_A \rightleftarrows \mathbf{Mod}_B : \operatorname{forget}\)

for a ring homomorphism \(A \to B\) between commutative rings. This adjunction is comonadic, by Beck's theorem, if and only if B is faithfully flat as an A-module. It thus allows to descend B-modules, equipped with a descent datum (i.e., an action of the comonad given by the adjunction) to A-modules. The resulting theory of faithfully flat descent is widely applied in algebraic geometry.

आता तुम्ही हे गणित कोणतेही कॅल्क्युलेटर सोडवू शकत नाही, पण त्याचे भाग गणितीय आहेत. खालीलपैकी एकचा प्रयत्न करा किंवा स्वतःचे टाइप करा.

स्वतःचे कार्य चालू ठेवा

मोफत खाते प्रत्येक शिकवणी वर टिपण्णी जोडते, तुम्ही पूर्ण केलेल्या गोष्टीचा नोंदवही, तुमच्या सोडविलेल्या समस्या एका ठिकाणी, आणि या पानाच्या विषयी तुम्ही विचारू शकता अशा शिक्षकाला. गणित स्वतःच सर्वांसाठी खुले आहे, दाखलन झालेले असो किंवा नसो.

नोंदणी करा दाखलन

येथे वापरलेले चिन्ह

Tap any symbol for the full definition, a picture, and what every letter in it means.

लोक विचारतात ते प्रश्न

What is a functor?

A map between categories that sends objects to objects and arrows to arrows while respecting composition. Taking the fundamental group of a space is a functor from spaces to groups.

या योजनेचे मुख्य उद्दिष्ट म्हणजे. Wikipedia (CC BY-SA 4.0). नंतर ते पुन्हा स्थिरावले आणि तेथेच ते स्थिरावले; म्हणजेच तेथेच ते स्थिरावले.

अधिक माहिती Category Theory