Abstract 1 Introduction 2 Related work 3 Monadic containers 4 Distributive laws 5 Composing with distributive laws 6 Mixed distributive laws 7 A no-go theorem 8 Conclusion References Appendix A Appendix Appendix B Appendix

Distributive Laws of Monadic Containers

Chris Purdy ORCID Royal Holloway University of London, Egham, UK Stefania Damato ORCID School of Computer Science, University of Nottingham, UK
Abstract

Containers are used to carve out a class of strictly positive data types in terms of shapes and positions. They can be interpreted via a fully-faithful functor into endofunctors on Set. Monadic containers are those containers whose interpretation as a Set functor carries a monad structure. The category of containers is closed under container composition and is a monoidal category, whereas monadic containers do not in general compose.

In this paper, we develop a characterisation of distributive laws of monadic containers. Distributive laws were introduced as a sufficient condition for the composition of the underlying functors of two monads to also carry a monad structure. Our development parallels Ahman and Uustalu’s characterisation of distributive laws of directed containers, i.e. containers whose Set functor interpretation carries a comonad structure. Furthermore, by combining our work with theirs, we construct characterisations of mixed distributive laws (i.e. of directed containers over monadic containers and vice versa), thereby completing the “zoo” of container characterisations of (co)monads and their distributive laws. We have found these characterisations amenable to development of existence and uniqueness proofs of distributive laws, particularly in the mechanised setting of Cubical Agda, in which most of the theory of this paper has been formalised.

Keywords and phrases:
distributive laws, monadic containers, monads, dependent types, cubical agda
Copyright and License:
[Uncaptioned image] © Chris Purdy and Stefania Damato; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Categorical semantics
; Theory of computation Type structures
Acknowledgements:
The authors would like to thank Thorsten Altenkirch, Dan Marsden, Stiéphen Pradal, and Reuben Rowe for helpful discussions on this work, Tom de Jong for inspiring our use of the  symbol for formalised statements, and the anonymous reviewers for their suggestions.
Editors:
Corina Cîrstea and Alexander Knapp

1 Introduction

Containers, introduced by Abbott et al. [3], give an algebraic presentation of a wide class of strictly positive data types. Often, reasoning about strictly positive data types in terms of their container representation is simpler than their functorial representation – for example, transformations between container functors constructed from container morphisms are automatically natural.

Monads have received a lot of attention in functional programming [18] and denotational semantics for their ability to model a wide range of programmatic side-effects [25]. In practice, it is rare for side-effects to appear individually – developing a way of composing monads is useful for situations where multiple effects are interleaved. In general, however, the composition of two monads need not result in another monad. Distributive laws [11] were developed as a sufficient condition for such a composition to form a monad, thereby ensuring that the corresponding side-effects are interleaved in a coherent way. Constructing distributive laws is known to be quite difficult due to the complexities involved in checking their axioms, besides the fact that some monads, even if they are composable, do not admit a distributive law in the first place [34, Remark 4.19]. As a result, various work has been done on different approaches for constructing distributive laws [23, 24], and for identifying cases where there are none [34, 20].

In this paper, we develop a characterisation of distributive laws of monadic containers [31], i.e. containers whose interpretation carries a monad structure, with the goal of providing an algebraic way of reasoning about distributive laws between strictly positive data types. We build on similar characterisations in the literature; Ahman, Chapman, and Uustalu develop directed containers [5], i.e. containers whose interpretation carries a comonad structure, and the first and last authors provide a characterisation of their distributive laws [6]. Uustalu also develops monadic containers [31], but to our knowledge, no work has been done on characterising their distributive laws. Our work parallels the development in [6] for monadic containers and therefore closes this gap. Furthermore, by combining our work with [6], we construct characterisations of mixed distributive laws (i.e. of directed containers over monadic containers and vice versa), thereby completing the “zoo” of container characterisations of (co)monads and their distributive laws.

Formalisation

Since our representation of distributive laws involves a list of highly dependent equalities, it lends itself well to formalisation in a proof assistant such as Cubical Agda [32], in which we have formalised our characterisations as well as those in [5, 6]. The formalised statements are annotated by a  symbol, which is a clickable link to the corresponding statement in the formalisation. The code can be found at github.com/chrisjpurdy/distr-laws-of-monadic-containers, and an HTML rendered version can be found at stefaniatadama.com/distr-law-mnd-cont-html/. While the aformentioned code implicitly assumes that we are dealing with h-sets throughout, we are currently working on a version of this code that makes this explicit and uses definitions from the Cubical library [29]. This version can be found at github.com/stefaniatadama/cubical/tree/distr-laws.

Setting of our work & Notation

We work in cubical type theory [14, 32] but our work holds in any intensional Martin-Löf type theory by assuming extensionality principles that are provable in cubical type theory, namely function extensionality (in particular, we do not use univalence). Throughout the paper, we use several type-theoretic notations made explicit below.

  • We use a:ABa for dependent sums and a:ABa for dependent products, their non-dependent counterparts represented as A×B and AB respectively. A+B denotes the sum type of A and B. The notation (a,b) refers to an element of a product type, λx.fx an element of a function type, and 𝗂𝗇𝗅a and 𝗂𝗇𝗋b elements of a sum. π1 and π2 are the first and second projections out of a product type.

  • The symbol refers to definitional equality, = refers to propositional equality, and refers to isomorphism of types.

  • The empty type is denoted by and the unit type by with element . 𝖥𝗂𝗇n is the type of finite sets of size n.

  • The category whose objects are (small) sets and whose morphisms are functions is denoted by Set, while 𝖲𝖾𝗍 denotes the universe of homotopy-sets (h-sets), or 0-types.

  • The category of endofunctors on Set is denoted by [Set,Set].

  • A few times we mention that an equality “holds up to” another equality, by which we mean that we have a heterogenous equality, or a path “lying over” another path. For more details on this, see [30, Section 2.3].

Organisation of the paper

The paper is organised as follows. After mentioning some related work in Section 2, we briefly review containers and monadic containers in Section 3. In Section 4, we characterise distributive laws of monadic containers and provide some examples using this characterisation, and in Section 5 we look at compatible composites of monadic containers. In Section 6, we use an existing characterisation of distributive laws of directed containers to characterise mixed distributive laws. In Section 7 we provide a starting point for using this characterisation to prove no-go theorems for monadic containers, before concluding in Section 8.

2 Related work

Containers are related to polynomial functors, as studied by Gambino and Hyland [15]. Specifically, polynomial functors on the LCCC of 𝖲𝖾𝗍s are equivalent to indexed container functors, and in a special case we get (ordinary) container functors (when the object I in [15, Section 5] is the terminal object). Polynomial monads (polynomial functors equipped with cartesian monad maps) have been studied by Gambino and Kock [16], but to our knowledge there is no characterisation of when polynomial monads can be composed via a distributive law or otherwise. Monadic containers fail to be a special case of polynomial monads, as monadic containers are not required to be cartesian. However, we do have that cartesian monadic containers, referred to as Σ-universes by Altenkirch and Pinyo [9], are special cases of polynomial monads. Awodey first mentions the connection between lax Σ-universes and a monad structure on polynomial functors in [10, Remark 13].

Manes and Mulry [23, 24] have developed general theorems concerning the existence of distributive laws. Zwart and Marsden [34, 33] have developed “no-go theorems” for monads that can be represented as algebraic theories, filling many holes in an extended version of the Boom hierarchy [13]. Algebraic theories are disjoint from monadic containers in the sense that all monads representable by algebraic theories are finitary. On the other hand, the container λ_.A can be uniquely equipped with monadic container data, and the extension of this container is not finitary if A is non-finite [21]. Ahman, Chapman, and Uustalu’s characterisation of directed containers [5] has been used by Karamlou and Shah to develop no-go theorems relevant to finite model theory [20].

Directed containers and certain theorems in [5] have already been formalised in vanilla Agda [4], but to our knowledge their distributive laws have not. We formalise directed containers and their distributive laws alongside our own developments in Cubical Agda, but do not recreate all proofs included in [4].

3 Monadic containers

In this section, we briefly review containers and their functor representation, we state the definition of monadic containers we will be using, and provide some examples of both.

3.1 Containers

The purpose of containers [3, 2, 1, 8] is to provide a uniform way to represent strictly positive data types. By a “strictly positive type” we roughly mean a type X whose constructors are only allowed to have X appear in input types that are arrows if it appears on their right. Allowing non-strictly positive types in our theories can be problematic and potentially lead to contradictions [30, Section 5.6]. In this sense, containers carve out a class of nicely behaved types, and they express the fact that any such type can be fully represented by a set of “shapes” S and a family of “positions” P over those shapes, at which data can be stored.

Definition 1.

A container is given by a type S:𝖲𝖾𝗍 and a family of types P:S𝖲𝖾𝗍, which we write as SP.

Example 2 ( ).

The container representation of the maybe type, which can either contain a value or indicate that there is no value, is the following.

+λ{𝗂𝗇𝗅𝗂𝗇𝗋

The shape + represents a choice between having a value or not. If the shape is 𝗂𝗇𝗅, this represents the absence of a value, so the type of positions is as there is no more data to supply. If the shape is 𝗂𝗇𝗋, we do have a value, so the type of positions is since there is one position for a singular piece of data.

Example 3 ( ).

The container representation of the list type is 𝖥𝗂𝗇. The shape of a list is a natural number n representing its length, and there are n-many positions for data to be stored in a list of length n, represented by the set 𝖥𝗂𝗇n.

Containers together with the following morphisms form a category Cont.

Definition 4.

A container morphism (SP)(TQ) is a pair

u :ST
f :s:SQ(us)Ps

written as uf.

Example 5.

There is a container morphism 𝖥𝗂𝗇(+)λx.{𝗂𝗇𝗅𝗂𝗇𝗋n𝖥𝗂𝗇n that “takes the tail” of a list container, given by

u 0 𝗂𝗇𝗅
u(n+1) 𝗂𝗇𝗋nf(n+1)pp+1

The function u describes the change to the length of the list (“failing” if the list is empty), and f maps positions in the tail of the list to positions in the original list.

Every container has a functorial interpretation in the category [Set,Set].

Definition 6.

The container functor associated to a container SP is the functor denoted by SP:𝖲𝖾𝗍𝖲𝖾𝗍, with the following actions on objects and morphisms.

  • Given an X:𝖲𝖾𝗍,SPXs:S(PsX).

  • Given X,Y:𝖲𝖾𝗍 and a morphism f:XY, for s:S and g:PsX,

    SPf(s,g)(s,fg).

The map _:Cont[Set,Set] is extended to a fully-faithful functor by taking uf(s,g):=(us,gf) as the action on container morphisms. Crucially for us, the category Cont is monoidal, with the composition of containers as the monoidal product and λ_. as the unit.

Definition 7.

Given containers SP and TQ, their composite, denoted (SP)(TQ), is defined as the container

(SP)(TQ):=[[SP]]T(λ(s,f).p:PsQ(fp))

The functor _ is monoidal, i.e. it preserves monoidal multiplication and unit.

3.2 Monadic containers

Monadic containers were developed by Uustalu [31] as a characterisation of monads whose underlying functors are container functors. We adopt conventions used by Altenkirch and Pinyo in [9], referring to them as monadic containers (rather than mnd-containers) and using their presentation as lax Σ-universes.

Definition 8 ( ).

Let SP be a container. A monadic container on SP is a tuple (SP,ι,σ,𝗉𝗋) where

ι:S
σ:s:S(PsS)S
𝗉𝗋:{s:S}{f:PsS}P(σsf)p:PsP(fp)

satisfying the following equations:

σι(λ_.s) =s σs(λ_.ι) =s
𝗉𝗋2{ι}{λ_.s}p =p 𝗉𝗋1{s}{λ_.ι}p =p
σs(λp.σ(fp)(g(p,)))=σ(σsf)(g𝗉𝗋)
𝗉𝗋1{s}{λp.σ(fp)(g(p,))}p=𝗉𝗋1{s}{f}(𝗉𝗋1{σsf}{g𝗉𝗋}p)
𝗉𝗋1{f(𝗉𝗋1p)}{λp.g(𝗉𝗋1p,p)}(𝗉𝗋2{s}{λp.σ(fp)(g(p,))}p)=
𝗉𝗋2{s}{f}(𝗉𝗋1{σsf}{g𝗉𝗋}p)
𝗉𝗋2{f(𝗉𝗋1p)}{λp.g(𝗉𝗋1p,p)}(𝗉𝗋2{s}{λp.σ(fp)(g(p,))}p)=𝗉𝗋2{σsf}{g𝗉𝗋}p

where we use the shorthands 𝗉𝗋i:=πi𝗉𝗋, and (p,):=λp.(p,p). The equalities for 𝗉𝗋 hold up to the corresponding equalities for σ above them.

For clarity we include all implicit arguments in grey in the equations above, but we will often omit them when they can be inferred from the context. For example, given p:P(σ(σsf)(g𝗉𝗋)), we can write the last three equalities for 𝗉𝗋 as

𝗉𝗋1p =𝗉𝗋1(𝗉𝗋1p) 𝗉𝗋1(𝗉𝗋2p) =𝗉𝗋2(𝗉𝗋1p) 𝗉𝗋2(𝗉𝗋2p) =𝗉𝗋2p

Abusing notation, we will refer to a monadic container (SP,ι,σ,𝗉𝗋) by its container SP, when ι,σ and 𝗉𝗋 are clear from the context.

Monadic containers can be thought of as containers whose sets of shapes are pointed, and closed under taking “container-fulls” of shapes, in the sense that any element (s,f):SPS gives a new shape σsf:S. The role of 𝗉𝗋 is to specify how positions p:P(σsf) map to positions p1:Ps and p2:P(fp1).

Every monadic container can be interpreted as a monad on Set, this interpretation being an extension of the usual interpretation of containers as functors.

Definition 9.

The monad interpretation of a monadic container (SP,ι,σ,𝗉𝗋) is defined as the monad (SP,η,μ) on Set, denoted by SP,ι,σ,𝗉𝗋mc, or simply SPmc when the monadic container structure is clear from the context, where

η:IdSP μ:SPSPSP
ηAa:=(ι,λ_.a) μA(s,f):=(σs(π1f),λp.π2(f(𝗉𝗋1p))(𝗉𝗋2p))

Monadic containers can also be seen as lax versions of (Tarski-style) type universes closed under singleton and dependent sum types [9]. Shapes are interpreted as codes for types, and the position family is the map that interprets each code as a concrete type. ι is the code for the singleton type, and σ constructs codes for Σ-types.

Definition 10.

A Σ-universe (SP,ι,𝗎𝗇,σ,𝗉𝗋) is given by a monadic container (SP,ι,σ,𝗉𝗋) with the isomorphisms

𝗎𝗇:Pι
𝗉𝗋:{s:S}{f:PsS}P(σsf)p:PsP(fp)

i.e. where for all s and f, 𝗉𝗋{s}{f} is an isomorphism, and Pι is isomorphic to .

The container examples we describe at the start of this section can each be equipped with monadic container structure.

Example 11.

The list container 𝖥𝗂𝗇 can be extended to a monadic container by taking

ι :=1
σnf :=f 0++f(n1)
𝗉𝗋1{n}{f}p :=max{i[0..n)|f 0++f(i1)p}
𝗉𝗋2{n}{f}p :=p(f 0++f((𝗉𝗋1{n}{f}p)1)).

This is also an example of a Σ-universe. The monad interpretation of this container is isomorphic to the list monad with concatenation.

Example 12 ( ).

Given some set S, the container (SS)λ_.S can be extended to a monadic container by taking

ι :=λx.x
σfg :=λx.gx(fx)
𝗉𝗋{f}x :=(x,fx).

The monad interpretation of this is the well-known state monad from functional programming.

Example 13 ( ).

The container (+E)Tr of coproducts with E, where

Tr(𝗂𝗇𝗅)
Tr(𝗂𝗇𝗋e)

can be extended to a monadic container by taking

ι :=𝗂𝗇𝗅
σ(𝗂𝗇𝗅)f f
σ(𝗂𝗇𝗋e)_ 𝗂𝗇𝗋e
𝗉𝗋{𝗂𝗇𝗅} :=(,).

This is another example of a Σ-universe. The monad interpretation of this is known to the functional programming community as the exception monad.

Example 14 ( ).

Given a monoid (A,,e), the container Aλ_. can be extended to a monadic container by taking

ι :=e
σaf :=af
𝗉𝗋 :=(,).

The monadic container equalities hold as a consequence of the monoid equalities. We call this the writer monadic container. Monadic containers on Aλ_. are in bijection with monoids on A. The monad interpretation of this is typically called the writer monad.

We recall the definition of directed containers [5], for use in later sections of the paper.

Definition 15 ( ).

Let SP be a container. A directed container on SP is a tuple (SP,o,,) where

o:{s:S}Ps:s:SPsS:{s:S}p:PsP(sp)Psso=ss(pp)=(sp)ppo=pop=p(pp)p′′=p(pp′′). (1)

4 Distributive laws

The question of whether two monads compose has applications in many areas. In functional programming and denotational semantics of effectful languages, for example, one might consider composition of two (or more) notions of side effect. As remarked in [34, Remark 1.1], distributive laws provide a particularly nice way to compose monads, that imbue the resulting composite monad with a variety of desirable properties.

Distributive laws were first introduced by Beck [11] as a sufficient condition for the composition of the underlying functors of two monads to carry a monad structure.

Definition 16.

Let 𝐒=(S,ηS,μS) and 𝐓=(T,ηT,μT) be monads. A distributive law of 𝐒 over 𝐓 is a natural transformation γ:TSST such that the following diagrams commute.

In our approach, we specialise Definition 16 to the case when S and T are container functors, making 𝐒 and 𝐓 monads on container functors. We rely on the fact that both the container interpretation functor _:Cont[Set,Set] and the monadic container interpretation functor _mc:MContMonad(Set) are fully-faithful [3, 31], as well as monoidality of Cont and _. This lets us directly interpret the diagrams in Definition 16 as diagrams in Cont, and gives us that each monadic container distributive law of SP over TQ corresponds to a unique monad distributive law of SPmc over TQmc.

Definition 17 ( ).

Let (SP,ιS,σS,𝗉𝗋S) and (TQ,ιT,σT,𝗉𝗋T) be monadic containers. A monadic container distributive law of TQ over111The ordering of the monadic containers in this terminology follows that used by Beck. SP is given by the data

u1:s:S(PsT)T
u2:s:Sf:PsTQ(u1sf)S
v1:{s:S}{f:PsT}q:Q(u1sf)P(u2sfq)Ps
v2:{s:S}{f:PsT}q:Q(u1sf)p:P(u2sfq)Q(f(v1qp))

which satisfy the following equalities.

u1ιS(λ_.t) =t (unit-ιS-s1)
u2ιS(λ_.t) =λ_.ιS (unit-ιS-s2)
v1{ιS}{λ_.t}qp =p (unit-ιS-p1)
v2{ιS}{λ_.t}qp =q (unit-ιS-p2)
u1s(λ_.ιT) =ιT (unit-ιT-s1)
u2s(λ_.ιT) =λ_.s (unit-ιT-s2)
v1{s}{λ_.ιT}qp =p (unit-ιT-p1)
v2{s}{λ_.ιT}qp =q (unit-ιT-p2)
u1(σSsf)(g𝗉𝗋S) =u1s(λp.u1(fp)(g(p,))) (mul-S-s1)
u2(σSsf)(g𝗉𝗋S)q =σS(u2s(λp.u1(fp)(g(p,)))q)
(λp.u2(f(v1qp))(g(v1qp,))(v2qp)) (mul-S-s2)
𝗉𝗋1S(v1qp) =v1q(𝗉𝗋1Sp) (mul-S-p1)
𝗉𝗋2S(v1qp) =v1(v2q(𝗉𝗋1Sp))(𝗉𝗋2Sp) (mul-S-p21)
v2qp =v2(v2q(𝗉𝗋1Sp))(𝗉𝗋2Sp) (mul-S-p22)
u1s(λp.σT(fp)(g(p,))) =σT(u1sf)(λq.u1(u2sfq)(gvq)) (mul-T-s1)
u2s(λp.σT(fp)(g(p,)))q =u2(u2sf(𝗉𝗋1Tq))(gvq)(𝗉𝗋2Tq) (mul-T-s2)
v1(𝗉𝗋1Tq)(v1(𝗉𝗋2Tq)p) =v1qp (mul-T-p1)
v2(𝗉𝗋1Tq)(v1(𝗉𝗋2Tq)p) =𝗉𝗋1T(v2qp) (mul-T-p21)
v2(𝗉𝗋2Tq)p =𝗉𝗋2T(v2qp) (mul-T-p22)

We will use the shorthands

usf (u1sf,u2sf)
v{s}{f}qp (v1{s}{f}qp,v2{s}{f}qp),

primarily to simplify stating examples of distributive laws.

We refer to equalities whose names end in s1 or s2 collectively as “shape” equalities. The ones ending with names in p1, p2, p21, or p22 are referred to collectively as “position” equalities.

These may seem rather unwieldy, but often in applications of this characterisation many of the equations simplify considerably. For example, when constructing a distributive law, if we define a u1,u2 such that we can take v1{s}{f}qp=p and v2{s}{f}qp=q, then all the position equalities hold definitionally, and only the shape equalities must be proven (like in Example 18). The distributive law uniqueness lemmas (Lemmas 19, 21, and 31) and no-go theorem in Section 7 only require consideration of a few of these equalities.

While Definition 16 is a concise way of stating what a distributive law is, expanding this definition to check the naturality of γ and commutativity of the 4 diagrams turns out to be cumbersome in practice. Further, our phrasing of distributive laws lends itself to formalisation in a proof assistant. In Cubical Agda, the dependencies between equations can be explicitly stated in terms of dependent paths, and we can prove properties of distributive laws without descending into “transport hell”.

Example 18 ( ).

There is a monadic container distributive law of SP over (+E)Tr, for any E, S, and P, given by

u(𝗂𝗇𝗅)f (f,λ_.𝗂𝗇𝗅)
u(𝗂𝗇𝗋e)_ (ιS,λ_.𝗂𝗇𝗋e)
v{𝗂𝗇𝗅}{f}p (,p).

In fact, this is the only monadic container distributive law of this type, and the characterisation in Definition 17 offers a succinct proof of this:

Lemma 19 ( ).

The distributive law in Example 18 is the unique one of SP over (+E)Tr for any E, S, and P.

Proof.

We first note that (S)S, and that S is contractible ((S), since it has a point λ_.ιS). Using these facts and the equalities unit-ιS-s1, unit-ιS-s2, unit-ιT-s1, and unit-ιT-s2, u is uniquely specified up to function extensionality. We can use the same reasoning and laws unit-ιS-p1 and unit-ιS-p2 to see that v is also uniquely specified up to function extensionality.

Example 20 ( ).

There is a monadic container distributive law of λ_.A over SP for any A, S, and P given by

usf (,λ_.s)
vap (p,a).
Lemma 21 ( ).

The distributive law in Example 20 is the unique one of λ_.A over SP for any A, S, and P.

Proof.

Follows from the isomorphisms (Ps) for any s:S, and the unit-ιT- equalities for monadic container distributive laws.

Ahman and Uustalu in [6] noticed that distributive laws of directed containers generalise matching pairs of monoid actions, and the composition of directed containers via a distributive law generalises the Zappa-Szép product of monoids [12]. The following example shows how distributive laws and composition of monadic containers generalise the same constructions, but in a slightly different way, which is unsurprising but nice to see.

Example 22.

Given monoids (A,A,ιA) and (B,B,ιB), and a matching pair of monoid actions (α:A×BA,β:A×BB), there is a distributive law of Bλ_. over Aλ_. given by

uab (β(a,b),λ_.α(a,b))
v (,)

where the distributive law equalities follow from the equalities for the matching pair of monoid actions (up to the isomorphism (B)B). Conversely, any distributive law of this type specifies a matching pair of monoid actions for the relevant monoids.

5 Composing with distributive laws

Along with distributive laws, Beck also introduced the equivalent notion of compatible composites [11], as a way to specify when a given monad can be considered a composite of two others. In this section, we characterise these in terms of monadic containers. Often, we will use the shorthand QP:=λ(s,f).p:PsQ(fp) to simplify the presentation of nested Σ-types.

Definition 23 ( ).

A compatible composite monadic container of (SP,ιS,σS,𝗉𝗋S) over (TQ,ιT,σT,𝗉𝗋T) is a pair of maps

σ:x:[[SP]]T(QPx[[SP]]T)[[SP]]T
𝗉𝗋:{x:[[SP]]T}{f:QPx[[SP]]T}QP(σxf)p:QPxQP(fp)

where:

  • ((SP)(TQ),(ιS,λ_.ιT),σ,𝗉𝗋) is a monadic container

  • the container morphisms λs.(s,λ_.ιT)π1 and λt.(ιS,λ_.t)π2 are monadic container morphisms, as defined in [31]

  • the middle unitary laws hold:

    (s,f) =σ(s,λ_.ιT)(λp.(ιS,λ_.f(π1p)))
    (q,p) =(π1(𝗉𝗋1(q,p)),π2(𝗉𝗋2(q,p)))

    where the second equality is dependent on the first.

Distributive laws of monadic containers and their interpreting monads are in bijection due to _:Cont[Set,Set] being full and faithful. Compatible composite monadic containers and their interpreting monads are also in bijection, since σ𝗉𝗋 is a container morphism, the collection of which is in bijection with natural transformations between container functors, again by _ being full and faithful. Therefore, Beck’s result that in the monad setting distributive laws and compatible composites are equivalent also immediately implies that they are equivalent in the monadic container setting. However, we would still like to give a direct construction of the compatible composite monadic container we obtain from a monadic container distributive law, and vice versa.

Proposition 24 (Compatible composite from a distributive law, partially formalised ).

Given monadic containers (SP,ιS,σS,𝗉𝗋S) and (TQ,ιT,σT,𝗉𝗋T), and a monadic container distributive law (u1,u2,v1,v2) of SP over TQ, we have a compatible composite monadic container given by

σ(s,f)g ( σSs(λp.u1(fp)(g1(p,))),
λp.σT(u2(f(𝗉𝗋1Sp))(g1(𝗉𝗋1Sp,))(𝗉𝗋2Sp))
(λq.g2(𝗉𝗋1Sp,v1(𝗉𝗋2Sp)q)(v2(𝗉𝗋2Sp)q)))
𝗉𝗋(p,q) ( (𝗉𝗋1Sp,v1(𝗉𝗋2Sp)(𝗉𝗋1Tq)),
(v2(𝗉𝗋2Sp)(𝗉𝗋1Tq),𝗉𝗋2Tq))

where giπig.

Proof.

Derivations of the “associativity” equalities are in Appendix A. Proofs of the remaining equalities are included in the Cubical Agda formalisation.

Proposition 25 (Distributive law from a compatible composite).

Given monadic containers (SP,ιS,σS,𝗉𝗋S) and (TQ,ιT,σT,𝗉𝗋T), and a compatible composite monadic container (σ,𝗉𝗋) of SP over TQ, then we have a monadic container distributive law given by

usf σ(ιT,λ_.s)(λp.(f(π2p),λ_.ιS))
vqp (π2(𝗉𝗋1(q,p)),π1(𝗉𝗋2(q,p))).

To see that Proposition 24 generalises the Zappa-Szép product of monoids, we consider the case in Example 22 of a distributive law between two writer monadic containers Aλ_. and Bλ_.. The resulting compatible composite monadic container (constructed using Proposition 24) is again a writer monadic container (A×B)λ_., whose corresponding monoid is a Zappa-Szép product of the monoids corresponding to Aλ_. and Bλ_..

Example 26.

Given a set A and monadic container (SP,ιS,σS,𝗉𝗋S), the compatible composite monadic container of λ_.A over SP arising from the distributive law in Example 20 is given by

σ(,f)g (,λa.σS(fa)(λp.π2(g(a,p)a)))
𝗉𝗋(a,p) ((a,𝗉𝗋1Sp),(a,𝗉𝗋2Sp)).

On a different note, composite monadic containers can be useful for considering extensions of (1,Σ) type universes (modelled by Σ-universes [9]). As an example, we consider how to augment a Σ-universe (𝒰El,ι𝒰,𝗎𝗇𝒰,σ𝒰,𝗉𝗋𝒰) with codes for refinement types [19]. This can be done by considering compatible composites of 𝒰El over the “Maybe” Σ-universe (Example 13 where E=).

Example 27.

Given a Σ-universe (𝒰El,ι𝒰,𝗎𝗇𝒰,σ𝒰,𝗉𝗋𝒰), the composite monadic container corresponding to Example 18 when E= is

ι (ι𝒰,λ_.true)
σ(s,f)g (σ𝒰s(λp.{g1(p,)if fp=trueι𝒰otherwise),λp.{g2(𝗉𝗋1𝒰p,)(𝗉𝗋2𝒰p)if f(𝗉𝗋1𝒰p)=truefalseotherwise)
𝗉𝗋(p,) ((𝗉𝗋1𝒰p,),(𝗉𝗋2𝒰p,))

where true:=𝗂𝗇𝗅 and false:=𝗂𝗇𝗋. This composite monadic container is also a Σ-universe, as 𝗉𝗋 is an isomorphism (since 𝗉𝗋𝒰 is an iso) and we have that TrElι (since 𝗎𝗇𝒰 is an iso).

To see how shapes in the above composite encode refinement types, consider a shape (s,f):s:𝒰Els(+). The shape s is a code for the type Els, and we can see f as a predicate on elements of Els. The type that (s,f) encodes is TrEl(s,f)x:ElsTr(fx), whose elements are essentially the elements of Els for which the predicate f holds.

This is an “augmentation” in the sense that all types encoded by 𝒰 have unique codes in the composite universe. Given a shape s:𝒰, the composite shape (s,λ_.true) codes for the type with elements from Els that satisfy the “always true” predicate – this is clearly isomorphic to the type Els.

6 Mixed distributive laws

By combining our characterisation of monadic container distributive laws with Ahman and Uustalu’s directed container distributive laws [6, Section 4] ( ), it is straightforward to obtain a characterisation of mixed container distributive laws.

Definition 28 ( ).

Let (TQ,ι,σ,𝗉𝗋) be a monadic container and (SP,o,,) be a directed container. We define a monadic-directed container distributive law of TQ over SP as the data

u1:s:S(PsT)T
u2:s:Sf:PsTQ(u1sf)S
v1:{s:S}{f:PsT}q:Q(u1sf)P(u2sfq)Ps
v2:{s:S}{f:PsT}q:Q(u1sf)p:P(u2sfq)Q(f(v1qp))

which satisfy the following equalities.

u1sf =f(o{s}) (unit-oS-s)
v1{s}{f}q(o{u2sfq}) =o{s} (unit-oS-p1)
v2{s}{f}q(o{u2sfq}) =q (unit-oS-p2)
u2sfqp =u2(sv1qp)(λp.f(v1qpp))(v2qp) (mul-S-s3)
v1q(pp) =v1qpv1(v2qp)p (mul-S-p1)
v2q(pp) =v2(v2qp)p (mul-S-p2)
u2s(λ_.ιT) =λ_.s (unit-ιT-s2)
v1{s}{λ_.ιT}qp =p (unit-ιT-p1)
v2{s}{λ_.ιT}qp =q (unit-ιT-p2)
u2s(λp.σT(fp)(g(p,)))q =u2(u2sf(𝗉𝗋1Tq))(gvq)(𝗉𝗋2Tq) (mul-T-s2)
v1(𝗉𝗋1Tq)(v1(𝗉𝗋2Tq)p) =v1qp (mul-T-p1)
v2(𝗉𝗋1Tq)(v1(𝗉𝗋2Tq)p) =𝗉𝗋1T(v2qp) (mul-T-p21)
v2(𝗉𝗋2Tq)p =𝗉𝗋2T(v2qp) (mul-T-p22)

Notice that the first six equations are taken from directed container distributive laws, and the remaining equations from monadic container distributive laws. As in directed container distributive laws, the unit-oS-s equality fully determines u1.

Directed-monadic container distributive laws (of a directed container over a monadic container) can be derived in a similar fashion.

Definition 29 ( ).

Let (SP,ι,σ,𝗉𝗋) be a monadic container and (TQ,o,,) be a directed container. We define a directed-monadic container distributive law of TQ over SP as the data

u1:s:S(PsT)T
u2:s:Sf:PsTQ(u1sf)S
v1:{s:S}{f:PsT}q:Q(u1sf)P(u2sfq)Ps
v2:{s:S}{f:PsT}q:Q(u1sf)p:P(u2sfq)Q(f(v1qp))

which satisfy the following equalities.

u1ιS(λ_.t) =t (unit-ιS-s1)
u2ιS(λ_.t) =λ_.ιS (unit-ιS-s2)
v1{ιS}{λ_.t}qp =p (unit-ιS-p1)
v2{ιS}{λ_.t}qp =q (unit-ιS-p2)
u1(σSsf)(g𝗉𝗋S) =u1s(λp.u1(fp)(g(p,))) (mul-S-s1)
u2(σSsf)(g𝗉𝗋S)q =σS(u2s(λp.u1(fp)(g(p,)))q)
(λp.u2(f(v1qp))(g(v1qp,))(v2qp)) (mul-S-s2)
𝗉𝗋1S(v1qp) =v1q(𝗉𝗋1Sp) (mul-S-p1)
𝗉𝗋2S(v1qp) =v1(v2q(𝗉𝗋1Sp))(𝗉𝗋2Sp) (mul-S-p21)
v2qp =v2(v2q(𝗉𝗋1Sp))(𝗉𝗋2Sp) (mul-S-p22)
u2sf(o{u1sf}) =s (unit-oT-s)
v1(o{u1sf})p =p (unit-oT-p1)
v2(o{u1sf})p =o{s} (unit-oT-p2)
u1sfq =u1(u2sfq)(λp.f(v1qp)v2qp) (mul-T-s1)
u2sf(qq) =u2(u2sfq)(λp.f(v1qp)v2qp)q (mul-T-s2)
v1(qq)p =v1q(v1qp) (mul-T-p1)
v2(qq)p =v2q(v1qp)v2qp (mul-T-p2)
Example 30 ( ).

There is a monadic-directed distributive law of the reader monadic container λ_.B over the writer directed container Aλ_. for any sets A and B, given by

uaf:=(,λ_.a)
vb:=(,b).
Lemma 31 ( ).

The mixed distributive law in Example 30 is the unique one of λ_.B over Aλ_..

Proof.

Follows from the isomorphism () and then directly from the unit-ιT equations of monadic-directed distributive laws.

It is thematically appropriate to check if these mixed distributive laws correspond to any known constructions on monoids.

For monadic-directed distributive laws, we can do this by specialising the mixed distributive law to the case of Bλ_. over λ_.A, where λ_.A is the reader directed container for a monoid (A,eA,A), and Bλ_. is the writer monadic container for a monoid (B,eB,B). u2 and v2 trivialise, u1 is uniquely defined as u1sf=feA, and the only parameter we are left with is

v1:{:}{f:AB}:a:AA.

Possible values of v1 in this case are in bijection with functions α:(AB)AA, satisfying the equations:

αfeA =eA
αf(aAa) =αfaAα(λx.f(αfaAx))a
α(λ_.eB)a =a
α(λx.fxBgx)a =αf(α(λx.g(αfx))a).

Counterintuitively, we do not end up with a matching pair of monoid actions! Instead we have something that we could call a “functional monoid action” ( ) of the function space AB on the monoid A. We have not come across this construction in the literature, but we would not be surprised if it was already known to algebraists.

Despite this, when we specialise directed-monadic container distributive laws to those between writer monadic containers and reader directed containers, we find that they are in bijection with matching pairs of monoid actions.

In summary, by restricting distributive laws to those between certain monadic and directed containers (those that are in bijection with monoids), we obtain corresponding constructions on monoids. The table below records the constructions obtained by considering distributive laws of each row container over each column container.

Writer monadic container Reader directed container
Writer monadic container Matching pairs Functional monoid actions
Reader directed container Matching pairs Matching pairs

This highlights an interesting asymmetry, however the reason for this asymmetry is not immediately obvious to us.

7 A no-go theorem

To show that our characterisation in Definition 17 is amenable to developing theorems concerning non-existence of distributive laws, we look to Zwart and Marsden [34] for approaches to developing no-go theorems that we may be able to emulate.

To do this, we first need to translate properties of and statements about algebraic theories, into those for monadic containers. Our strategy for this translation was to very loosely view aspects of a monadic container as analogous to aspects of an algebraic theory:

  • shapes are “terms”

  • positions are “variables within a term”

  • σ is the “substitution operator”

  • ι is a “variable placeholder”

  • 𝗉𝗋 is a map from “variable positions in a term resulting from a substitution” to “variable positions in the terms that were involved in that substitution”.

The point of this is not to form a rigorous connection between monadic containers and algebraic theories, but to see if there are common patterns that can be quickly taken advantage of. As it turns out, this loose perspective provides sufficient intuition to emulate the “too many constants” theorem about non-existence of certain composite algebraic theories in [34, Theorem 4.6] in our setting.

Definition 32 ( ).

Given a monadic container (SP,ι,σ,𝗉𝗋) we call any shape s:S where Ps a constant shape.

Definition 33 ( ).

A monadic container (SP,ι,σ,𝗉𝗋) satisfies the (S3) property if there exist s:S and f:PsS such that Ps is non-empty, equality on Ps is decidable, and for any p:Ps

σsfp=ι

and for any p:P(σsfp) we have

𝗉𝗋1{s}{fp}p=p

where we use the notation

fp:=λp.{ιif p=pfpotherwise

The name of this property is taken from the analogous property of algebraic theories in [34, Section 4]. In particular, the list monadic container 𝖥𝗂𝗇 satisfies (S3) by taking any n: except 0, and taking f:=λ_.0. Since you can pick any n: where 𝖥𝗂𝗇n is non-empty, this container actually satisfies a stronger property, directly analogous to (S4) in [34, Section 4]. An interesting almost-example is the state monadic container (SS)λ_.S for S with decidable equality, which satisfies the shape equation of (S3) by taking s:=λx.x and f:=λxy.y, but not the position equation (unless S is trivial).

Lemma 34 (Composite (S3), ).

Let (SP,ιS,σS,𝗉𝗋S) be a monadic container satisfying (S3) for some s:S and f:PsS, and (TQ,ιT,σT,𝗉𝗋T) be a monadic container. Assume we have a monadic container distributive law (u1,u2,v1,v2) of SP over TQ. Then, for any t:T and p:Ps,

u1s(λp.{tif p=pιTotherwise)=t.

Proof.

Proof included in Appendix B.

Theorem 35 (Too many constants, ).

Let (SP,ιS,σS,𝗉𝗋S) be a monadic container satisfying (S3) for some s:S and f:PsS, such that we have two distinct positions p,p:Ps, and let (TQ,ιT,σT,𝗉𝗋T) be a monadic container. Assume we have a monadic container distributive law (u1,u2,v1,v2) of SP over TQ. Then TQ cannot have more than one distinct constant shape.

Proof.

Proof included in Appendix B.

With this theorem we can obtain the known result that there are no distributive laws of the list monad over the coproduct monad.

Example 36.

Let E be a set with at least two elements e1,e2:E such that e1e2. By Theorem 35, there is no monadic container distributive law of the list monadic container 𝖥𝗂𝗇 over the coproduct monadic container (+E)Tr.

The scope of this theorem is slightly different to Zwart and Marsden’s theorem of the same name, as it concerns a different class of monads – those presentable as monadic containers, rather than algebraic theories. It is possible to represent any monad on Set as a generalised algebraic theory [22], but it is not immediately clear how to transfer no-go theorems for compositions of algebraic theories into that setting.

8 Conclusion

We have characterised monadic, monadic-directed, and directed-monadic container distributive laws, and have motivated their use for development of uniqueness and existence proofs. Further, we have shown such proofs to be amenable to mechanisation in a proof assistant.

Looking at the constructions on monoids that each of these distributive laws generalise, we note a curious asymmetry. Monadic-directed container distributive laws correspond to the notion of “functional monoid action”, as opposed to matching pairs of monoid actions, which all other kinds of distributive law we consider correspond to.

Our work dualises that of Ahman and Uustalu in [6], completing the set of characterisations for container (co)monads and their distributive laws, but there are clearly further directions to explore. All of our characterisations and those in [5, 6, 31] could be extended to symmetric (or groupoid) containers [17], or further to categorified containers [17, 7] to describe a larger class of (co)monads and their distributive laws. For example, it seems possible to represent the finite multiset monad using groupoid containers. We intend to explore this direction in future work.

In Example 27, we touch on the connection between type universes and monadic containers. This perspective could be further explored, using this work as a starting point. For example, one could consider developing a notion of composition for type universes with not only codes for and Σ, but also for Π types.

References

  • [1] Michael Abbott, Thorsten Altenkirch, and Neil Ghani. Categories of containers. In Andrew D. Gordon, editor, Foundations of Software Science and Computation Structures, pages 23–38, Berlin, Heidelberg, 2003. Springer Berlin Heidelberg.
  • [2] Michael Abbott, Thorsten Altenkirch, and Neil Ghani. Representing nested inductive types using W-types. In Automata, Languages and Programming, 31st International Colloqium (ICALP), pages 59–71, 2004. doi:10.1007/978-3-540-27836-8_8.
  • [3] Michael Abbott, Thorsten Altenkirch, and Neil Ghani. Containers: Constructing strictly positive types. Theoretical Computer Science, 342(1):3–27, September 2005. doi:10.1016/j.tcs.2005.06.002.
  • [4] Danel Ahman. An Agda formalisation of the theory of directed containers. https://github.com/danelahman/Directed-Containers, 2011. Online.
  • [5] Danel Ahman, James Chapman, and Tarmo Uustalu. When is a container a comonad? In Lars Birkedal, editor, Foundations of Software Science and Computational Structures, pages 74–88, Berlin, Heidelberg, 2012. Springer. doi:10.1007/978-3-642-28729-9_5.
  • [6] Danel Ahman and Tarmo Uustalu. Distributive laws of directed containers. Progress in Informatics, (10):3–18, March 2013. doi:10.2201/NiiPi.2013.10.2.
  • [7] Thorsten Altenkirch. Quotient inductive types as categorified containers. https://hott-uf.github.io/2024/abstracts/HoTTUF_2024_paper_10.pdf, 2024. HoTT/UF 2024 abstract.
  • [8] Thorsten Altenkirch and Peter Morris. Indexed containers. In 2009 24th Annual IEEE Symposium on Logic In Computer Science, pages 277–285, 2009. doi:10.1109/LICS.2009.33.
  • [9] Thorsten Altenkirch and Gun Pinyo. Monadic containers and Σ-universes. https://types2017.elte.hu/proc.pdf#page=28, https://people.cs.nott.ac.uk/psztxa/talks/types-17-cont.pdf, 2017. TYPES 2017 abstract and slides.
  • [10] Steve Awodey. Natural models of homotopy type theory. Math. Struct. Comput. Sci., 28(2):241–286, 2018. doi:10.1017/S0960129516000268.
  • [11] Jon Beck. Distributive laws. In B. Eckmann, editor, Seminar on Triples and Categorical Homology Theory, pages 119–140, Berlin, Heidelberg, 1969. Springer Berlin Heidelberg. doi:10.1007/BFb0083084.
  • [12] Matthew G. Brin. On the Zappa-Szép Product. Communications in Algebra, 33(2):393–424, February 2005. doi:10.1081/agb-200047404.
  • [13] Alexander Bunkenburg. The Boom Hierarchy, pages 1–8. Springer London, London, 1994. doi:10.1007/978-1-4471-3236-3_1.
  • [14] Cyril Cohen, Thierry Coquand, Simon Huber, and Anders Mörtberg. Cubical Type Theory: A Constructive Interpretation of the Univalence Axiom. In Tarmo Uustalu, editor, 21st International Conference on Types for Proofs and Programs (TYPES 2015), volume 69 of Leibniz International Proceedings in Informatics (LIPIcs), pages 5:1–5:34, Dagstuhl, Germany, 2018. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.TYPES.2015.5.
  • [15] Nicola Gambino and Martin Hyland. Wellfounded trees and dependent polynomial functors. In Stefano Berardi, Mario Coppo, and Ferruccio Damiani, editors, Types for Proofs and Programs, pages 210–225, Berlin, Heidelberg, 2004. Springer Berlin Heidelberg. doi:10.1007/978-3-540-24849-1_14.
  • [16] Nicola Gambino and Joachim Kock. Polynomial functors and polynomial monads. Mathematical Proceedings of the Cambridge Philosophical Society, 154(1):153–192, January 2013. arXiv:0906.4931 [math]. doi:10.1017/S0305004112000394.
  • [17] Håkon Robbestad Gylterud. Symmetric containers. Master’s thesis, University of Oslo, 2011.
  • [18] Paul Hudak, Simon Peyton Jones, Philip Wadler, Brian Boutel, Jon Fairbairn, Joseph Fasel, María M. Guzmán, Kevin Hammond, John Hughes, Thomas Johnsson, Dick Kieburtz, Rishiyur Nikhil, Will Partain, and John Peterson. Report on the programming language haskell: a non-strict, purely functional language version 1.2. SIGPLAN Not., 27(5):1–164, May 1992. doi:10.1145/130697.130699.
  • [19] Ranjit Jhala and Niki Vazou. Refinement types: A tutorial, 2020. arXiv:2010.07763.
  • [20] Amin Karamlou and Nihil Shah. No go theorems: Directed containers that do not distribute over distribution monads. In Proceedings of the 39th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS ’24, pages 1–13, New York, NY, USA, July 2024. Association for Computing Machinery. doi:10.1145/3661814.3662137.
  • [21] Joachim Kock. Notes on polynomial functors, 2009. Unpublished notes.
  • [22] E.G. Manes. Algebraic Theories. Springer Science & Business Media, 2012. doi:10.1007/978-1-4612-9860-1.
  • [23] Ernie Manes and Philip Mulry. Monad compositions I: General constructions and recursive distributive laws. Theory and Applications of Categories, 18:172–208, 2007.
  • [24] Ernie Manes and Philip Mulry. Monad compositions II: Kleisli strength. Mathematical Structures in Computer Science, 18(3):613–643, June 2008. doi:10.1017/S0960129508006695.
  • [25] Eugenio Moggi. Notions of computation and monads. Information and Computation, 93(1):55–92, 1991. Selections from 1989 IEEE Symposium on Logic in Computer Science. doi:10.1016/0890-5401(91)90052-4.
  • [26] Chris Purdy and Stefania Damato. chrisjpurdy/distr-laws-of-monadic-containers. Software, swhId: swh:1:dir:8d906ffab8f8a03982b563930c72ea835fd9d64a (visited on 2025-07-21). URL: https://github.com/chrisjpurdy/distr-laws-of-monadic-containers, doi:10.4230/artifacts.24062.
  • [27] Chris Purdy and Stefania Damato. chrisjpurdy/distr-laws-of-monadic-containers HTML rendering. Software (visited on 2025-07-21). URL: https://stefaniatadama.com/distr-law-mnd-cont-html/, doi:10.4230/artifacts.24064.
  • [28] Chris Purdy and Stefania Damato. stefaniatadama/cubical. Software (visited on 2025-07-21). URL: https://github.com/stefaniatadama/cubical/tree/distr-laws, doi:10.4230/artifacts.24065.
  • [29] The Agda Community. Cubical Agda Library, May 2025. URL: https://github.com/agda/cubical.
  • [30] The Univalent Foundations Program. Homotopy Type Theory: Univalent Foundations of Mathematics. https://homotopytypetheory.org/book, Institute for Advanced Study, 2013.
  • [31] Tarmo Uustalu. Container combinatorics: Monads and lax monoidal functors. In Mohammad Reza Mousavi and Jiří Sgall, editors, Topics in Theoretical Computer Science, pages 91–105, Cham, 2017. Springer International Publishing. doi:10.1007/978-3-319-68953-1_8.
  • [32] Andrea Vezzosi, Anders Mörtberg, and Andreas Abel. Cubical agda: a dependently typed programming language with univalence and higher inductive types. Proc. ACM Program. Lang., 3(ICFP), July 2019. doi:10.1145/3341691.
  • [33] Maaike Zwart. On the Non-Compositionality of Monads via Distributive Laws. PhD thesis, University of Oxford, 2020.
  • [34] Maaike Zwart and Dan Marsden. No-go theorems for distributive laws. Logical Methods in Computer Science, Volume 18, Issue 1:6253, January 2022. doi:10.46298/lmcs-18(1:13)2022.

Appendix A Appendix

Associativity proofs of Proposition 24.

Almost all parts of Proposition 24 have been formalised and can be found here: , aside from the associativity equalities (for technical reasons), which we prove below instead. Sub-expressions with the same colour were rewritten by applying the same position equality.

Appendix B Appendix

The proofs in this appendix are for Section 7.

Proof of Lemma 34.

By the chain of equalities:

Proof of Theorem 35.

Assume we have two distinct constant shapes t0,t1:T. We first have the chain of equalities:

Using the same steps, we can derive:

and by composing these two equalities, we get that t0=t1. This contradicts our assumption that t0 and t1 were distinct.

Proof that the list monadic container in Example 11 satisfies the (S3) property (Definition 33), for any n: where f=λ_.0.

Proof.

First notice that σnfp=1 for any p:𝖥𝗂𝗇n. This means that the shape equality is satisfied, and also that we only have to consider p=0 for the position equality.

The sum fp 0++fp(i1) becomes 1 exactly when i=p, which gives us that max{i[0..n)|fp 0++fp(i1)0}=p. Therefore, by definition, we have 𝗉𝗋1{n}{fp}p=p.