1. Introduction
Dijkstra’s weakest precondition predicate transformer (wppt for short) (Dijkstra Reference Dijkstra1975) computes, for an imperative program f and a predicate
$\psi$
on memory configurations, the weakest predicate
$\mathrm{wp}(\,f,\psi)$
on memory configurations such that, for any memory configuration x satisfying
$\mathrm{wp}(\,f,\psi)$
, the execution of f from x yields a memory configuration satisfying
$\psi$
. When the imperative program f always terminates and only updates memory configurations deterministically, the behavior of f can be modeled as an endofunction
$[\![ f]\!]$
over the set M of memory configurations, and
$\mathrm{wp}(\,f,\psi)$
is defined so that
$[\![ \mathrm{wp}(\,f,\psi)]\!]$
becomes the inverse image of
$[\![ \psi]\!]\subseteq M$
along
$[\![ f]\!]$
. One of the key properties of predicate transformers that make them suitable for program verification is composability: the weakest precondition
$\mathrm{wp}(\,f;\;g,\psi)$
of a composite program
$f;\;g$
is equivalent to the composition of the weakest preconditions of its components, that is,
$\mathrm{wp}(\,f,\mathrm{wp}(g,\psi))$
. This allows us to inductively compute the weakest precondition predicate transformer of programs.
Following Dijkstra’s seminal work, wppts and their variants have been applied to program verification in different manners, such as computing expected values over outputs of probabilistic programs McIver and Morgan (Reference McIver and Morgan2005), estimating runtime Kaminski et al. (Reference Kaminski, Katoen, Matheja and Olmedo2016), or estimating tail bounds of rewards over control-flow graphs Kura et al. (Reference Kura, Urabe and Hasuo2019). The motivation of this paper is to identify a mathematical structure behind these variations of wppt-like semantics. Toward this goal, in this paper we set out to study wppts and their composability using fibrations. Roughly speaking, a fibration is a functor
$p:\mathbb{P}\rightarrow\mathbb{C}$
that exposes a relationship between a category
$\mathbb{P}$
of predicates and an underlying category
$\mathbb{C}$
modeling computation - when
$p P= X$
holds, we regard
$ P\in\mathbb{P}$
as a predicate over
$ X\in\mathbb{C}$
; this viewpoint is shared with the categorical study of logical relations (
Reference Hermida
Hermida 1993
) and refinement types (Melliès and Zeilberger Reference Melliès and Zeilberger2015). Fibrations are especially suited to interpret predicate transformers and their composability thanks to the Cartesian lifting property, which allows us to take the “inverse image” of
$ Q\in\mathbb{P}$
along a morphism
$f: X\to Y$
in
$\mathbb{C}$
, resulting an object
$f^* Q\in\mathbb{P}$
such that
$p(\,f^* Q)= X$
. This is a categorical abstraction of the inverse image operation.
The main challenge we address in this paper is to develop a categorical theory of weakest precondition predicate transformer under the presence of computational effects modeled by monads.
Footnote 1
The main technical vehicle of this development is the lifting of a monad
$\mathsf{T}$
along a fibration
$p:\mathbb{P}\rightarrow\mathbb{C}$
– it is a monad
${\dot {\mathsf{T}}}$
on
$\mathbb{P}$
such that p strictly preserves the monad structure to
$\mathsf{T}$
. We then regard a morphism
${f: P\to {\dot {\mathsf{T}}} Q}$
in
$\mathbb{P}$
as a Hoare triple
$ P\{f\} Q$
. This induces a natural wppt
$\mathrm{wp}(\,f, P)\mathbin{\triangleq} f^*(\dot T P)$
that characterizes the Hoare triple, but it does not satisfy composability in general. This raises the question of when monadic computations do induce compositional weakest precondition predicate transformers. In this paper, we answer to this question by introducing the property called Cartesian-ness on monad liftings, and contribute to its understanding as follows:
-
(1) We show that the wppt defined by a monad lifting is composable if and only if the monad lifting is Cartesian. This result establishes the tight connection between the composability of wppts in monadic setting and the Cartesian-ness of liftings. This result tells us what kind of formal structures are needed when giving compositional wppt-like semantics to imperative programming languages.
-
(2) We relate strongest postcondition predicate transformers (sppts for short) as left adjoints to wppts, and discuss when they are available and composable.
-
(3) We study Cartesian liftings of monads along domain fibrations (see Section 4.2) from lax slice categories, which have as objects morphisms from an object of the base category to an object
$\Omega$
of generalized truth values. For this class of fibrations, there is a bijective correspondence between Cartesian liftings of a monad
$\mathsf{T}$
and Eilenberg-Moore monotone algebras of
$\mathsf{T}$
; this is exhibited through a 2-categorical embedding of the 2-category of categories with ordered objects to the 2-category of fibrations. The correspondence result simplifies the task of exploring Cartesian liftings of monads along such fibrations and makes it possible to enumerate all Cartesian liftings of some monads. We show examples of Cartesian liftings of the following monads: the maybe monad, the nonempty powerset monad, the counting monad, the distribution monad, and the indexed distribution monad and some combinations of them. The wppts derived from Cartesian liftings of monads coincide with weakest pre-expectation (McIver and Morgan Reference McIver and Morgan2005) and the higher moment transformer (Kura et al. Reference Kura, Urabe and Hasuo2019). -
(4) Computational effects are often modeled by monads composed via distributive laws. We extend the correspondence given in (3) to the one between Cartesian liftings of composite monads and pairs of Eilenberg-Moore monotone algebras satisfying an extra coherence law given in Beck (Reference Beck1969), Manes and Mulry (Reference Manes and Mulry2007). This correspondence provides a modular method to compute Cartesian liftings of composite monads.
-
(5) To compute the wppts of the programs containing effectful commands (such as probabilistic choice and counting), we study the interaction between Plotkin and Power’s algebraic operations (Plotkin and Power Reference Plotkin, Power, Brooks and Mislove2001), which are a categorical models of effectful commands, and wppts studied in (3).
-
(6) Apart from domain fibrations, we illustrate a few examples of Cartesian liftings of monads along relational fibrations. They are outside of the framework presented in Hasuo (Reference Hasuo2015) and Hino et al. (Reference Hino, Kobayashi, Hasuo and Jacobs2016). These examples are derived from a general construction of the change-of-base of fibrations with (Cartesian) monad liftings.
-
(7) We demonstrate that categorical wppts can be used to derive predicate transformer semantics. The derivation takes two steps: (1) we compose a categorical wppt wp and the standard monadic semantics
$[\![ P]\!]:M\to TM$
of an imperative language and then (2) we represent the composite as an inductive definition over programs. The derived inductive definition gives a predicate-transformer semantics of the language. We illustrate this story by deriving Kaminski et al.’s expected runtime transformer (Kaminski et al. Reference Kaminski, Katoen, Matheja and Olmedo2016) for the loop-free fragment of a probabilistic programming language.
Differences with respect to conference version. This paper is an extension of an MFPS conference paper of the same title (Aguirre and Katsumata Reference Aguirre and Katsumata2020). The increments with respect to the conference paper are the following:
We generalize our results from posetal fibrations to
$\mathbb{K}$
-fibrations, for an arbitrary subcategory
$\mathbb{K}$
of the category of posets.We give a 2-categorical perspective of the lax slice construction in Section 4.2.
We study liftings of strong monads and give sufficient and necessary conditions for the liftings to be strong.
We identify a general principle behind our presentation of liftings along relational fibrations and show that (Cartesian) liftings of monads can be pulled back along a change-of-base with monad opfunctors Street (Reference Street1972, Section 4).
We study continuity properties of weakest precondition transformers and apply it to the computation of the weakest precondition of while loops.
We provide more extensive explanations and details of the proofs.
2. Preliminaries
Composition of functors and whiskering (Whiskering https://ncatlab.org/nlab/show/whiskering) of functors and natural transformations are denoted by juxtaposition. The vertical and horizontal compositions of natural transformations are denoted by
$\mathbin{\star}$
and
$\mathbin{*}$
, respectively. We write Pos for the category of posets and monotone functions between them. The forgetful functor from Pos to Set is denoted by U. Subcategories of Pos are ranged over
$\mathbb K$
. A morphism
$f: X\to Y$
in
$\mathbb K$
is called a right adjoint if there is a monotone function
$g\in{\bf Pos}( Y, X)$
such that
$g(y)\le x\iff y\le f(x)$
holds for any
$x\in X,y\in Y$
.
2.1 Monads and Distributive Laws
We briefly recall here some definitions about monads. For a more detailed account see e.g. MacLane (Reference MacLane1998, Section VI). Let
$\mathbb{C}$
be a category. A monad is a triple
$(\mathsf{T},\eta,\mu)$
of a functor
$\mathsf{T} \colon \mathbb{C} \to \mathbb{C}$
and two natural transformations
$\eta\colon {\rm Id} \Rightarrow \mathsf{T}$
(the unit) and
$\mu\colon \mathsf{T}^2 \Rightarrow \mathsf{T}$
(the multiplication) such that
$\mu \mathbin{\star} \eta\mathsf{T} = {\rm id}_\mathsf{T} = \mu \mathbin{\star} \mathsf{T}\eta $
and
$\mu \mathbin{\star} \mu\mathsf{T} = \mu \mathbin{\star} \mathsf{T}\mu$
.
The Kleisli lifting of
$f: X\rightarrow \mathsf{T} Y$
is a morphism
$f^{\#}\colon \mathsf{T} X \rightarrow \mathsf{T} Y$
defined as
$f^{\#}\mathbin{\triangleq}\mu_ Y\circ \mathsf{T} f$
. A monad may be equivalently given by a triple
$(\mathsf{T},\eta,(\_)^{\#})$
, replacing the multiplication with the Kleisli lifting
$(\_)^{\#}:\mathbb{C}( X,\mathsf{T} Y)\to \mathbb{C}(\mathsf{T} X,\mathsf{T} Y)$
; see Moggi (Reference Moggi1991).
The Kleisli category
$\mathbb{C}_\mathsf{T}$
of a monad
$(\mathsf{T},\eta,\mu)$
is a category whose objects are the objects of
$\mathbb{C}$
and whose homsets are defined by
$\mathbb{C}_\mathsf{T}( X, Y)\mathbin{\triangleq} \mathbb{C}( X,\mathsf{T} Y)$
. The composition of morphisms in
$\mathbb{C}_\mathsf{T}$
is denoted by
$\bullet$
and is defined from the composition
$\circ$
in
$\mathbb{C}$
as
$g \bullet f \mathbin{\triangleq} g^{\#} \circ f$
. Following Moggi (Reference Moggi1991), we regard morphisms in
$\mathbb{C}_\mathsf{T}$
as abstract representations of programs causing computational effects. There exists an adjunction
$L \dashv R \colon \mathbb{C} \to \mathbb{C}_\mathsf{T}$
such that
$R \circ L = T$
, called the Kleisli resolution of
$\mathsf{T}$
.
An Eilenberg–Moore (EM for short) algebra of a monad
$(\mathsf{T},\eta,\mu)$
is a pair (X,o) of an object
$ X\in\mathbb{C}$
and a morphism
$o \colon \mathsf{T} X \to X$
such that
$o \circ \eta_ X = {\rm id}_ X$
and
$o \circ To = o \circ \mu_ X$
.
Let
$(\mathsf{T},\eta^\mathsf{T},\mu^\mathsf{T})$
and
$(\mathsf{S},\eta^\mathsf{S},\mu^\mathsf{S})$
be monads on
$\mathbb{C}$
. A distributive law (Beck Reference Beck1969) of
$\mathsf{S}$
over
$\mathsf{T}$
is a natural transformation
$\alpha:\mathsf{S}\mathsf{T}\rightarrow \mathsf{T} \mathsf{S}$
such that
The distributive law yields the monad
$\left(\mathsf{T}\mathsf{S},\eta^\mathsf{T}\mathbin{*}\eta^\mathsf{S},\left(\mu^\mathsf{T}\mathbin{*}\mu^\mathsf{S})\mathbin{\star} (\mathsf{T}\alpha \mathsf{S}\right)\right)$
over the composite functor. We denote this monad by
$\mathsf{T}\circ_\alpha \mathsf{S}$
.
2.2 Fibrations
Dijkstra’s weakest precondition predicate transformer manipulates predicates over memory configurations. In the abstract study of predicate transformers, however, it is convenient to extend the concept of predicates so that they can be defined over arbitrary objects on a category. For this abstract and general treatment of predicates, we leverage the notions of fibered category theory (see e.g. Jacobs Reference Jacobs1999). Before introducing these concepts, we give an informal account of them.
Given a category
$\mathbb{C}$
(with objects ranging over X, Y, Z and morphisms ranging over f,g,h) we aim to define predicates over its objects by introducing a category
$\mathbb{P}$
(with objects ranging over P, Q, R and morphisms ranging over dotted letters
${\dot f},\dot g,\dot h$
) and a functor
$p:\mathbb{P}\rightarrow\mathbb{C}$
. We understand this general situation as follows:
An object in
$\mathbb{P}$
is a predicate over some object in
$\mathbb{C}$
, which is recorded by the functor
$p:\mathbb{P}\rightarrow\mathbb{C}$
. That is,
$p P= X$
means that
$ P\in\mathbb{P}$
is a predicate over
$ X\in\mathbb{C}$
.A morphism
${\dot f}: \to P\to Q$
in
$\mathbb{P}$
is a witness of the fact that the underlying morphism
$p{\dot f}:p P\rightarrow p Q$
in
$\mathbb{C}$
“preserves” these predicates, that is,
$p{\dot f}$
maps elements satisfying the predicate P to those satisfying the predicate Q. In particular, if
${\dot f} : P\rightarrow Q$
satisfies
$p{\dot f}={\rm id}_ X$
, then
${\dot f}$
witnesses that P implies Q.
The inverse image of an object
$ X\in\mathbb{C}$
under the functor
$p:\mathbb{P}\rightarrow\mathbb{C}$
forms a category denoted by
$\mathbb{P}_ X$
, known as the fiber category above X. Formally, an object of
$\mathbb{P}_ X$
is a
$\mathbb{P}$
-object P such that
$p P= X$
, and a morphism from P to Q in
$\mathbb{P}_ X$
is a morphism
${\dot f}: P\to Q$
in
$\mathbb{P}$
such that
$p{\dot f}={\rm id}_ X$
. Intuitively, objects of this category are predicates over X, and morphisms of this category represent implication relations between them.
When defining weakest precondition predicate transformers, the strength of predicates is compared by an order relation, so we focus our attention on posetal fibrations. Recall that the weakest precondition predicate transformer collects all the memory configurations that entail the postcondition. Set-theoretically, this operation is called inverse image, and fibrations offer a more general and flexible treatment of the inverse image operation. Roughly speaking, a fibration is a functor
$p:\mathbb{P}\rightarrow\mathbb{C}$
such that for any morphism
$f: X\to Y$
in
$\mathbb{C}$
and
$ P\in\mathbb{P}_ Y$
, we can find the inverse image
$f^* P\in\mathbb{P}_ X$
of P along f. The formal definition of a posetal fibration follows.
For objects
$ P, Q\in \mathbb{P}$
and a morphism
$f:p P\to p Q$
in
$\mathbb{C}$
, we define the set
$\mathbb{P}_f( P, Q)$
of morphisms in
$\mathbb{P}$
above f by
$\mathbb{P}_f( P, Q)\triangleq \{{\dot f}\in\mathbb{P}( P, Q)~|~p{\dot f}=f\}$
.A morphism
${\dot f}: P\to Q$
in
$\mathbb{P}$
is Cartesian if for any
$ R \in \mathbb{P}$
and morphism
$h:p R\to p P$
in
$\mathbb{C}$
, the postcomposition of
${\dot f}$
, regarded as a function of type
$\mathbb{P}_h( R, P)\rightarrow\mathbb{P}_{p{\dot f}\circ h}( R, Q)$
, is a bijection. This is the universal property of Cartesian morphisms. A Cartesian morphism
${\dot f}: P\to Q$
in
$\mathbb{P}$
abstractly represents the situation that P is an inverse image of Q along
$p{\dot f}$
.A functor
$p:\mathbb{P}\rightarrow\mathbb{C}$
is a fibration if for any morphism
$f: X\to Y$
in
$\mathbb{C}$
and
$ Q\in\mathbb{P}_ Y$
, there is an object
$ P\in\mathbb{P}_ X$
and a Cartesian morphism
${\dot f}: P\to Q$
in
$\mathbb{P}_f$
called the Cartesian lifting of f with Q.A fibration
$p:\mathbb{P}\rightarrow\mathbb{C}$
is posetal if each fiber category
$\mathbb{P}_ X$
is a poset. In any posetal fibration, the Cartesian lifting of a morphism
$f: X\to Y$
in
$\mathbb{C}$
with
$ Q\in\mathbb{P}_ Y$
uniquely exists; we therefore denote it by
$\overline f Q$
and its domain by
$f^* Q$
. We note that posetal fibrations are faithful. Therefore, a morphism
${\dot f}: P\to Q$
in
$\mathbb{P}$
is Cartesian if and only if
$ P=(p{\dot f})^* Q$
.In a posetal fibration
$p:\mathbb{P}\rightarrow\mathbb{C}$
, the assignment
$ Q\mapsto f^* Q\in\mathbb{P}_ P$
for a morphism
$f: X\to Y$
in
$\mathbb{C}$
extends to a monotone function of type
$\mathbb{P}_ Y\rightarrow\mathbb{P}_ X$
, which we call the reindexing functor (we use the word functor for the compatibility with the existing terminology). The assignment
$f\mapsto f^*$
furthermore satisfies
$({\rm id}_ X)^*={\rm id}_{\mathbb{P}_ X}$
and
$(g\circ f)^*=f^* g^*$
.Let
$\mathbb K$
be a subcategory of Pos. A functor
$p:\mathbb{P}\rightarrow\mathbb{C}$
is a
$\mathbb K$
-fibration if each fiber category
$\mathbb{P}_ X$
belongs to
$\mathbb K$
, and each reindexing functor
$f^*$
belongs to
$\mathbb K$
as a morphism.
A convenient way to obtain
$\mathbb K$
-fibrations is by the Grothendieck construction (in fact every
$\mathbb K$
-fibration is isomorphic to one obtained in this way). Let
$F:\mathbb{C}^{op}\rightarrow\mathbb K$
be a functor. The Grothendieck construction applied to F yields a category
$\int F$
defined by the data below:
An object is a pair (X,x) of an object
$ X\in\mathbb{C}$
and an element
$x\in F X$
.A morphism from (X,x) to (Y,y) is a morphism
$f: X\to Y$
in
$\mathbb{C}$
such that
$x\le Ff(y)$
in the poset F X belonging to
$\mathbb K$
.
The forgetful functor
$G_{F}:\int F\to \mathbb{C}$
defined by
$G_{F}( X,x)\mathbin{\triangleq} X$
and
$G_{F}(\,f)\mathbin{\triangleq} f$
is a
$\mathbb K$
-fibration; see e.g. Jacobs (Reference Jacobs1999).
Toward defining the 2-category of
$\mathbb K$
-fibrations, we introduce a few concepts. Let
$p:\mathbb{P}\to\mathbb{C}$
and
$q:\mathbb Q\to\mathbb D$
be
$\mathbb K$
-fibrations.
A
$\mathbb K$
-functor is a pair of functors
$(F:\mathbb{C}\to\mathbb D,\dot F:\mathbb{P}\to\mathbb Q)$
such that
$Fp=q\dot F$
, and the restriction of
$\dot F$
to each fiber, written
$\dot F_ X:\mathbb{P}_ X\to\mathbb Q_{F X}$
, belongs to
$\mathbb K$
. It is called fibered if
$\dot F$
preserves Cartesian morphisms; this requirement is equivalent to requiring that the equality
$\dot F(\,f^* P)=(Ff)^*(\dot F P)$
holds for any object
$ P\in\mathbb{P}$
and morphism
$f: X\to p P$
in
$\mathbb{C}$
.Let
$(F,\dot F),(G,\dot G):p\to q$
be
$\mathbb K$
-functors. A natural transformation from the former to the latter is a pair of natural transformations
$\alpha:F\to G$
and
$\dot\alpha:\dot F\to\dot G$
such that
$\alpha p=q\dot\alpha$
. It is called Cartesian if
$\dot\alpha_{ P}$
is a Cartesian morphism above
$\alpha_{p P}$
for each
$ P\in\mathbb{P}$
.
Definition 1. We define a chain of 2-categories
${\mathbb K}\text{-}{\bf Fib}_0 \supset{\mathbb K}\text{-}{\bf Fib}\supset {\mathbb K}\text{-}{\bf Fib}_c$
by the following table.

The following lemma characterizes (Cartesian) natural transformations between (fibered)
$\mathbb K$
-functors.
Lemma 2. Let
$p:\mathbb{P}\to\mathbb{C}$
and
$q:\mathbb Q\to\mathbb D$
be
$\mathbb K$
-fibrations. Then the mapping
$(\alpha,\dot\alpha)\mapsto \alpha$
gives the following bijections:
We write
$\Xi,\Xi_c$
for the above bijections from left to right, respectively. We will use them later in Section 4.1.
Proof. We show (1); (2) is proved similarly. Let
$\alpha:F\to G$
be a natural transformation such that
$\dot F P\le\alpha_{p P}^*(\dot G P)$
. It suffices to exhibit a unique natural transformation
$\dot\alpha:\dot F\to\dot G$
such that
$\alpha p=q\dot\alpha$
. Define
$\dot\alpha_ P$
by
It routine to check that
$\dot\alpha$
is a natural transformation satisfying
$\alpha p=q\dot\alpha$
. Moreover, the faithfulness of q guarantees its uniqueness.
3. Dijkstra Structures and Weakest Precondition Predicate Transformers
A fibration
$p \colon \mathbb{P} \to \mathbb{C}$
allows us to define an abstract form of inverse images for morphisms in
$\mathbb{C}$
. However, effectful computations are instead modeled as morphisms
$f\colon X \to \mathsf{T} Y$
for some monad
$\mathsf{T}$
, following Moggi (Reference Moggi1991). To write logical specifications for such computations, we will lift
$\mathsf{T}$
to a monad
${\dot {\mathsf{T}}}$
over
$\mathbb{P}$
, which will map predicates over Y to predicates over
$\mathsf{T} Y$
. We will call such a triple
$(p\colon \mathbb{P} \to \mathbb{C}, \mathsf{T}, {\dot {\mathsf{T}}})$
a Dijkstra structure.
In this section, we present Dijkstra Structures and show how to use them to define an abstract notion of weakest precondition transformer for effectful computations (Section 3.1). We will then identify the subclass of Dijkstra Structures for which the transformer composes exactly (Section 3.2). We then study how Dijskstra Structures behave under change-of-base (Section 3.3). Then we define a variant of Dijkstra structures for strong monads (Section 3.4), which allows us to prove soundness of frame-like rules. Finally, we study the dual situation of strongest postconditions (Section 3.5).
3.1 Dijkstra Structures
Let
$\mathbb{C}$
be a category and
$\mathsf{T}$
a monad over it. We aim to model the statement that a computation represented as a morphism
$f: X\to Y$
in the Kleisli category
$\mathbb{C}_\mathsf{T}$
satisfies a specification given by a precondition and a postcondition, which are predicates over X and Y, respectively. Since the codomain of f is
$\mathsf{T} Y$
, we first need to construct a predicate over
$\mathsf{T} Y$
from a predicate over Y. For this purpose, we define a lifting of
$\mathsf{T}$
into a monad
${\dot {\mathsf{T}}}$
over
$\mathbb{P}$
.
Definition 3. Let
$p:\mathbb{P}\rightarrow\mathbb{C}$
be a
$\mathbb K$
-fibration and
$(\mathsf{T},\eta,\mu)$
be a monad on
$\mathbb{C}$
. A monad
$({\dot {\mathsf{T}}},\dot\eta,\dot\mu)$
on
$\mathbb{P}$
is called a
$\mathbb K$
-lifting of
$\mathsf{T}$
(along p) if
$(\mathsf{T},{\dot {\mathsf{T}}})$
is a
$\mathbb K$
-functor from p to p, and
$p{\dot {\mathsf{T}}} =\mathsf{T} p, p\dot \eta =\eta p$
and
$ p\dot \mu =\mu p $
holds. We say that the
$\mathbb K$
-lifting is Cartesian if
$(\mathsf{T},{\dot {\mathsf{T}}})$
is a fibered
$\mathbb K$
-functor from p to p, and
$\dot\eta_ P$
and
$\dot\mu_ P$
are respectively Cartesian above
$\eta_{p P}$
and
$\mu_{p P}$
for any
$ P\in\mathbb{P}$
. This is equivalent to having that
$ P=\eta_{p P}^*({\dot {\mathsf{T}}} P)$
and
${\dot {\mathsf{T}}}{\dot {\mathsf{T}}} P=\mu^*_{p P}{\dot {\mathsf{T}}} P$
for any object
$ P\in\mathbb{P}$
.
The concept of monad lifting is not new; it appeared as a semantic counterpart of logical relations for monads (Filinski Reference Filinski1996; Filinski Reference Filinski2007; Goubault-Larrecq et al. Reference Goubault-Larrecq, Lasota and Nowak2008; Katsumata Reference Katsumata2005; Katsumata et al. Reference Katsumata, Sato and Uustalu2018). Hermida considered the comonadic case earlier than these works Hermida (Reference Hermida1993), Chapter 5. The definition of Cartesian lifting of monad makes sense when p is a non-posetal fibration. When
$\mathbb{C}$
is a category with pullbacks, a monad
$\mathsf{T}$
on
$\mathbb{C}$
is Cartesian (see e.g. Leinster Reference Leinster2004, Section 4.1) if and only if the evident lifting
$\mathsf{T}^\rightarrow:\mathbb{C}^\rightarrow\rightarrow\mathbb{C}^\rightarrow$
of
$\mathsf{T}$
to the arrow category
$\mathbb{C}^\rightarrow$
along the codomain fibration
${\rm cod}:\mathbb{C}^\rightarrow\rightarrow\mathbb{C}$
is Cartesian.
The tuple consisting of a
$\mathbb K$
-fibration p, a monad
$\mathsf{T}$
, and its
$\mathbb K$
-lifting
${\dot {\mathsf{T}}}$
along p provides us a setting in which we can define the Hoare triple and the weakest precondition predicate transformer (wppt for short) associated to it. In this paper, we package these data into one, and call it a Dijkstra structure.
Definition 4 (Dijkstra Structure). For a subcategory
$\mathbb K$
of Pos, a (resp. Cartesian)
${\mathbb K}$
-Dijkstra structure is a tuple
$(p,\mathsf{T},{\dot {\mathsf{T}}})$
of a
$\mathbb K$
-fibration
$p:\mathbb{P}\rightarrow\mathbb{C}$
, a monad
$\mathsf{T}$
on
$\mathbb{C}$
and a (resp. Cartesian)
$\mathbb K$
-lifting
${\dot {\mathsf{T}}}$
of
$\mathsf{T}$
along p. When
$\mathbb K={\bf Pos}$
, we simply call it a Dijkstra structure.
A (resp. Cartesian)
${\mathbb K}$
-Dijkstra structure is precisely a monad in
${\mathbb K}\text{-}{\bf Fib}_0$
(resp.
${\mathbb K}\text{-}{\bf Fib}_c$
).
Definition 5. Let
$(p:\mathbb{P}\rightarrow\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
be a
${\mathbb K}$
-Dijkstra structure. Below X, Y range over
$\mathbb{C}$
-objects.
-
(1) For a morphism
$f: X\to \mathsf{T} Y$
in
$\mathbb{C}$
and objects
$ P\in\mathbb{P}_ X, Q\in\mathbb{P}_ Y$
, we define the Hoare triple
$ P \{ f \} Q$
by (3)Such
\begin{equation}P\{f\} Q\mathbin{\triangleq} \exists{\dot f\in\mathbb{P}( P,{\dot {\mathsf{T}}} Q)}~.~p\dot f=f. \end{equation}
$\dot f$
is unique because p is faithful.
-
(2) For a morphism
$f: X\to \mathsf{T} Y$
in
$\mathbb{C}$
, we define the weakest precondition predicate transformer
$\mathrm{wp}(\,f,-)\in\mathbb K(\mathbb{P}_ Y,\mathbb{P}_ X)$
by (4)
\begin{equation}\mathrm{wp}(f, Q) \mathbin{\triangleq} f^*({\dot {\mathsf{T}}} Q).\end{equation}
Since p is a fibration, Hoare triples and the wppt are linked by the following equivalence:
We remark that for each morphism f,
$\mathrm{wp}(\,f,\_)$
is a morphism in
$\mathbb K$
. Therefore, if morphisms in
$\mathbb K$
are required to preserve order-theoretic structures, so does
$\mathrm{wp}(\,f,\_)$
. For instance, when
$\mathbb K$
is the category
${\bf CLat}_\wedge$
of complete lattices and functions preserving all meets, the wppt of a Dijkstra structure
${{\bf CLat}_\wedge}$
preserves arbitrary meets in its second argument:
$\mathrm{wp}(f,\bigwedge_i P_i) = \bigwedge_i\mathrm{wp}(f, P_i)$
. In the context of program verification, such a wppt is called conjunctive.
3.2 Composability of the Weakest Precondition Predicate Transformers
The Hoare triple and the wppt in our categorical setting are more general than the standard ones since we can supply any
$\mathbb{P}$
-object and
$\mathbb{C}_\mathsf{T}$
-morphism to the wppt. This liberation allows us to relate the composability of the wppt and the Cartesian-ness of
${\dot {\mathsf{T}}}$
. Since wp takes a Kleisli morphism as an argument, the composability should be discussed with respect to the Kleisli composition.
Theorem 6. Let
$(p:\mathbb{P}\to\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
be a
${\mathbb K}$
-Dijkstra structure. We have inequalities
for any f,g, P of appropriate type; here,
$\eta$
and
$\bullet$
are the unit and the Kleisli composition of
$\mathsf{T}$
, respectively. Moreover, inequalties in (5) become equalities if and only if the
${\mathbb K}$
-Dijkstra structure is Cartesian.
Proof. Let
$(p:\mathbb{P}\to\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
be a
${\mathbb K}$
-Dijkstra structure. Then the unit
$\dot\eta_ P: P\rightarrow{\dot {\mathsf{T}}} P$
of
${\dot {\mathsf{T}}}$
is above
$\eta_{p P}$
. Therefore
If
$\dot\eta_ P$
is Cartesian, this inequality becomes an equality. Next, the multiplication
$\dot\mu_ P:{\dot {\mathsf{T}}}{\dot {\mathsf{T}}} P\rightarrow{\dot {\mathsf{T}}} P$
of
${\dot {\mathsf{T}}}$
is above
$\mu_{p P}$
. Therefore
${\dot {\mathsf{T}}}{\dot {\mathsf{T}}} P\le\mu^*_{p P}{\dot {\mathsf{T}}} P$
holds; this becomes an equality if
$\dot\mu_ P$
is Cartesian. Moreover, for any object
$ X\in\mathbb{C}, P\in\mathbb{P}$
and morphism
$f: X\to p P$
in
$\mathbb{C}$
, we have
${\dot {\mathsf{T}}}(\,f^* P)\le (\mathsf{T} f)^*({\dot {\mathsf{T}}} P)$
; this becomes an equality if
${\dot {\mathsf{T}}}$
is fibered. From these, we obtain the following inequality, which becomes an equality if
$\dot\mu_ P$
is Cartesian and
${\dot {\mathsf{T}}}$
is fibered.
We have thus proved inequalities (5), and if the assumed
${\mathbb K}$
-Dijkstra structure is Cartesian, these inequalities become equalities.
We conversely assume
Below let
$ X=p P$
. (6) implies that
$\dot\eta_{ P}$
is Cartesian. By putting
$g = {{\mathrm{id}}}_{T T X}$
and
$f = {{\mathrm{id}}}_{T X}$
in (7), we obtain
$ {\dot {\mathsf{T}}} {\dot {\mathsf{T}}} P = \mu_ X^* ({\dot {\mathsf{T}}} P)$
, hence
$\dot\mu_{ P}$
is Cartesian. Let
$h: Y\to X$
be a morphism in
$\mathbb{C}$
. By putting
$g = {{\mathrm{id}}}_{T X}$
and
$f = \eta_ X \circ h: Y\to T X$
in (7), we obtain
${\dot {\mathsf{T}}} (h^* P) = {\dot {\mathsf{T}}} (h^* \eta_ X^* {\dot {\mathsf{T}}} P) = (\mathsf{T} h)^* ({\dot {\mathsf{T}}} P)$
, hence
${\dot {\mathsf{T}}}$
is fibered.
Therefore, for a Cartesian
${\mathbb K}$
-Dijkstra structure
$(p:\mathbb{P}\rightarrow\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
, the following assignments of posets in
$\mathbb K$
and monotone functions in
$\mathbb K$
become a functor
$\mathrm{Wp}:(\mathbb{C}_\mathsf{T})^{op}\rightarrow\mathbb K$
:
Then the Grothendieck construction G applied to Wp yields the
$\mathbb K$
-fibration that is isomorphic to the evident functor from
$\mathbb{P}_{\dot {\mathsf{T}}}$
to
$\mathbb{C}_\mathsf{T}$
.
Theorem 7. Let
$(p:\mathbb{P}\to\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
be a Cartesian
${\mathbb K}$
-Dijkstra Structure. We take Kleisli resolutions
$(L\dashv R:\mathbb{C}_\mathsf{T}\rightarrow\mathbb{C},\eta,\varepsilon)$
of
$\mathsf{T}$
and
$(\dot L\dashv\dot R:\mathbb{P}_{{\dot {\mathsf{T}}}}\rightarrow\mathbb{P},\dot\eta,\dot\varepsilon)$
of
${\dot {\mathsf{T}}}$
. We define the functor
$p_{\mathsf{T}, \dot{\mathsf{T}}} : \mathbb{P}_{{\dot {\mathsf{T}}}}\rightarrow \mathbb{C}_\mathsf{T}$
by
-
(1) We have an isomorphism
$p_{\mathsf{T},{\dot {\mathsf{T}}}}\cong G_{\mathrm{Wp}}$
in
${\mathbb K}\text{-}{\bf Fib}_c$
. -
(2) We have an isomorphism
$p\cong G_{\mathrm{Wp}\circ L}$
in
${\mathbb K}\text{-}{\bf Fib}_c$
. -
(3)
$((L,\dot L),(R,\dot R),(\eta,\dot\eta),(\varepsilon,\dot\varepsilon))$
is an adjunction in
${\mathbb K}\text{-}{\bf Fib}_c$
.
Proof. (1, 2) Routine. We note that the reindexing functor of the fibration
$p_{\mathsf{T},{\dot {\mathsf{T}}}}$
is
$\mathrm{wp}(\,f,\_)$
. (3) We first show that
$(L,\dot L),(R,\dot R)$
are 1-cells in
${\mathbb K}\text{-}{\bf Fib}_c$
. A) Equations
$p_{\mathsf{T},{\dot {\mathsf{T}}}}\dot L=L p$
and
$p \dot R=R p_{\mathsf{T},{\dot {\mathsf{T}}}}$
easily follow from
${\dot {\mathsf{T}}}$
being a lifting of
$\mathsf{T}$
along p. B) We show the fiberedness of
$\dot L$
and
$\dot R$
, that is,
$ \dot L(\,f^* P)=\mathrm{wp}(Lf,\dot L P)$
and
$\dot R(\mathrm{wp}(\,f, P))=(Rf)^*(\dot R P)$
. By the Cartesianness of
${\dot{\mathsf{T}}}$
, we have
(C) We show that the restrictions of
$\dot L,\dot R$
to fibers belong to
$\mathbb K$
. The restriction
$\dot L_ X:\mathbb{P}_ X\to (\mathbb{P}_{{\dot {\mathsf{T}}}})_{L X}$
is the identity morphism, hence belongs to
$\mathbb K$
. The restriction
$\dot R_ Y:(\mathbb{P}_{{\dot {\mathsf{T}}}})_{ Y}\rightarrow \mathbb{P}_{R Y}$
coincides with
$\dot T_ Y$
, which belongs to
$\mathbb K$
.
We next show that
$(\eta,\dot\eta)$
and
$(\varepsilon,\dot\varepsilon)$
are 2-cells in
${\mathbb K}\text{-}{\bf Fib}_c$
. The proof proceeds as follows:
It is routine to check that
$((L,\dot L),(R,\dot R),(\eta,\dot\eta),(\varepsilon,\dot\varepsilon))$
forms an adjunction in
${\mathbb K}\text{-}{\bf Fib}_c$
.
Recent work (Aguirre et al. Reference Aguirre, Barthe, Hsu, Kaminski, Katoen and Matheja2021) presents a noncomposable predicate transformer to reason about relational pre-expectations of probabilistic programs. This noncomposability can be associated to the fact that the monad lifting used in the work is not Cartesian. Their relational pre-expectation operator coincides with our categorical wppt in the Dijkstra structure
$(p : {\bf EPMet} \rightarrow {\bf Set}, \mathsf{D_\omega}, \mathsf{K})$
, where p is the forgetful functor from the category of extended pseudometric spaces, which is a posetal fibration,
$\mathsf{D_\omega}$
is the countable probability distribution monad (see Example 40 for the finite case), and
$\mathsf{K}$
is the Kantorovich metric construction:
Here
$\Gamma(\mu_1,\mu_2)$
is the set of probabilistic couplings between
$\mu_1,\mu_2$
, and E denotes the expectation; see Aguirre et al. (Reference Aguirre, Barthe, Hsu, Kaminski, Katoen and Matheja2021, Definition 2.2) for details. Since it fails to satisfy the composability, we conclude that the Dijkstra structure is not Cartesian.
3.3 Change-of-base of Dijkstra Structures
In fibrational category theory, the change-of-base is a convenient method to introduce a fibration over a category. This method takes a fibration
$p:\mathbb{P}\rightarrow\mathbb{C}$
and a functor
$F:\mathbb D\rightarrow\mathbb{C}$
as parameters and performs the following pullback in the (large) category CAT of categories and functors:

We explicitly specify the pullback category
$F^*\mathbb{P}$
as follows: an object is a pair
$( X\in\mathbb D, P\in\mathbb{P})$
of objects such that
$F X=p P$
, and a morphism from (X, P) to (Y, Q) is a pair of morphisms
$(\,f,\dot f)\in\mathbb D( X, Y)\times\mathbb{P}( P, Q)$
such that
$Ff=p\dot f$
. The first projection functor
$F^*p$
is called the change-of-base of p along F and is again a fibration Jacobs (Reference Jacobs1999, Lemma 1.5.1). The inverse image of
$( Y, Q)\in F^*\mathbb{P}$
along a morphism
$f: X\to Y$
in
$\mathbb D$
is given by
$( X,(Ff)^* Q)$
. When
$p:\mathbb{P}\to\mathbb{C}$
is a
$\mathbb K$
-fibration, so is
$F^*p:F^*\mathbb{P}\to\mathbb D$
, and each homset of
$F^*\mathbb{P}$
satisfies
We therefore replace homsets of
$F^*\mathbb{P}$
with the right-hand side when p is a
$\mathbb K$
-fibration.
Example 8. Let
${\bf Pred}({\bf Set})$
be the category of predicates over Set. This has as objects pairs (P,X) of sets such that
$P \subseteq X$
, and as morphisms from (P,X) to (Q,Y) functions
$f \colon X \to Y$
such that for every
$x \in P$
,
$f(x) \in Q$
. The evident forgetful functor p mapping (P,X) to X defines a posetal fibration known sometimes as the subobject fibration.
Now consider the functor
$\times \colon {\bf Set}^2 \to {\bf Set}$
. The change-of-base construction induced by p and
$\times$
constructs a fibration with total category
${\bf BRel}({\bf Set})$
, defined by the data below:
Objects are triples
$(P,X_1,X_2)$
of sets such that
$P \subseteq X_1\times X_2$
.Morphisms from
$(P,X_1,X_2)$
to
$(Q,Y_1,Y_2)$
are pairs of morphisms
$f_1\colon X_1 \to Y_1$
,
$f_2\colon X_2\to Y_2$
such that for all
$(x_1,x_2) \in P$
,
$(\,f_1(x_1),f_2(x_2))\in Q$
.
The fibration is given by the forgetful functor
$(\!\times\!)^\ast p$
mapping
$(P,X_1,X_2)$
to
$(X_1,X_2)$
.
In Section 10 we will see a generalization of this construction for a general base category
$\mathbb{C}$
and a general truth-value object
$\Omega$
.
We now apply the change-of-base method to Dijkstra structures. Since Dijkstra structures are fibrations with monads, we naturally expect that the functor, along which we take a pullback, interacts with the monad of a Dijkstra structure. We describe this interaction by the monad opfunctor axioms given by Street Street (Reference Street1972, Section 4).
Definition 9. A monad morphism from a monad
$(\mathsf{S},\eta^\mathsf{S},\mu^\mathsf{S})$
on
$\mathbb D$
to a monad
$(\mathsf{T},\eta^\mathsf{T},\mu^\mathsf{T})$
on
$\mathbb{C}$
is a pair of a functor
$F:\mathbb D\rightarrow \mathbb{C}$
and a natural transformation
$\alpha:F \mathsf{S}\rightarrow \mathsf{T} F$
satisfying the following axioms:
The following theorem extends the change-of-base method to Dijkstra structures along monad morphism. It preserves Cartesianness of Dijkstra structures.
Theorem 10. Let
$(p:\mathbb{P}\rightarrow \mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
be a (resp. Cartesian)
${\mathbb K}$
-Dijkstra structure,
$\mathsf{S} $
be a monad on a category
$\mathbb D$
and
$(F:\mathbb D\rightarrow\mathbb{C},\alpha:F \mathsf{S} \rightarrow \mathsf{T} F)$
be a monad morphism from
$\mathsf{S} $
to
$\mathsf{T}$
. We define a monad
$({\dot {\mathsf{S}}},\eta^{\dot {\mathsf{S}}},\mu^{\dot {\mathsf{S}}})$
on
$F^*\mathbb{P}$
by
Then the tuple
$(F^*p:F^*\mathbb{P}\rightarrow\mathbb D, \mathsf{S} , {\dot {\mathsf{S}}} )$
is a (resp. Cartesian)
${\mathbb K}$
-Dijkstra structure.
Proof. Let
$(p:\mathbb{P}\to\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
be a
${\mathbb K}$
-Dijkstra structure and
$F^*p:F^*\mathbb{P}\rightarrow\mathbb D$
be the
$\mathbb K$
-fibration obtained by the change-of-base of p along F.
We first verify that
$f\in F^*\mathbb{P}(( X, P),( Y, Q))$
implies
$\dot Sf\in F^*\mathbb{P}({\dot {\mathsf{S}}}( X, P),{\dot {\mathsf{S}}}( Y, Q))$
.
We next verify that
$\eta^{\dot {\mathsf{S}}}_{( X, P)}\in F^*\mathbb{P}(( X, P),{\dot {\mathsf{S}}}( X, P))$
and
$\mu^{\dot {\mathsf{S}}}_{( X, P)}\in F^*\mathbb{P}({\dot {\mathsf{S}}}({\dot {\mathsf{S}}}( X, P)),{\dot {\mathsf{S}}}( X, P))$
.
Now assume that the
${\mathbb K}$
-Dijkstra structure
$(p,\mathsf{T},{\dot {\mathsf{T}}})$
is Cartesian. Then the last two inequalities become equalities. Moreover,
Therefore
${\dot {\mathsf{S}}}$
is fibered. The functor
${\dot {\mathsf{S}}}$
is a
$\mathbb K$
-lifting of
$\mathsf{S}$
, because its restriction
${\dot {\mathsf{S}}}_ X:F^*\mathbb{P}_ X\to F^*\mathbb{P}_{\mathsf{S} X}$
to the fiber over
$ X\in\mathbb D$
is the composite of
$\alpha_ X^*$
and
${\dot {\mathsf{T}}}_ X^*$
, both of which belong to
$\mathbb K$
. This concludes that
$(F^*p,\mathsf{S},{\dot {\mathsf{S}}})$
is a Cartesian
${\mathbb K}$
-Dijkstra structure.
We will see examples of change-of-base of Dijkstra structures in Section 10.
3.4 Dijkstra Structures with Strengths 60
In Moggi’s theory of monadic models of computational effects (Moggi Reference Moggi1991), monad strengths are an important ingredient, since they allow us to sequence effectful computations with a common context. Below we discuss an extension of Dijkstra structures with strengths.
Let
$(\mathbb{C},1,\times)$
be a category with finite products and
$(\mathsf{T},\eta,\mu)$
be a monad on it. We first recall the concept of strength on
$\mathsf{T}$
Moggi (Reference Moggi1991, Definition 3.2). It is a natural transformation
$\theta_{ X, Y}: X\times \mathsf{T} Y\to\mathsf{T}( X\times Y)$
satisfying four axioms (below
$\alpha_{ X, Y, Z}:( X\times Y)\times Z\to X\times( Y\times Z)$
is the associator):
Let
$f: X\to \mathsf{T} Y$
be a morphism in
$\mathbb{C}$
and
$ Z\in\mathbb{C}$
be an object. The strength allows us to extend the domain and codomain of the effectful computation represented by f with Z. The extension is given as follows:
Intuitively, the morphism
$ Z\cdot_\theta f$
takes an input (z,x) from the extended input space
$ Z\times X$
, applies the effectful computation f to x, and returns the result (z,v), where v is the value part of the computation f(x). The input z is directly forwarded to the output.
To extend the concept of strength to Dijkstra structures, we first set-up the concept of finite products on Dijkstra structures. We define finite products on a posetal fibration
$p:\mathbb{P}\to\mathbb{C}$
to be the following data:
-
(1) a pair of terminal objects 1 in
$\mathbb{C}$
and
$\dot 1$
in
$\mathbb{P}$
such that
$p\dot 1=1$
, and -
(2) a pair of binary product functors
$(\!\times\!):\mathbb{C}^2\to\mathbb{C}$
and
$(\!\mathbin{\dot\times}\!):\mathbb{P}^2\to\mathbb{P}$
such that
$(\!\mathbin{\dot\times}\!)$
preserves Cartesian morphisms and p strictly preserves binary products in the following sense:
\begin{align*} (\,f\times g)^*( P\mathbin{\dot\times} Q)&=f^* P\mathbin{\dot\times} g^* Q & p( P\mathbin{\dot\times} Q)&=p P\times p Q,& p\pi_i^{ P, Q}&=\pi_i^{p P,p Q}. \end{align*}
A pair of a posetal fibration and finite products on it is denoted by
$p:(\mathbb{P},\dot 1,\mathbin{\dot\times})\to(\mathbb{C},1,\times)$
. We remark that every fiber of p has finite meets, and reindexing functors preserve these meets.
Footnote 2
The top element of
$\mathbb{P}_ X$
is
$!_ X^*\dot {1}\in\mathbb{P}_ X$
, and the meet of
$ P, Q\in\mathbb{P}_ X$
is given by
$ P\wedge Q\mathbin{\triangleq}\langle{\rm id}_ X,{\rm id}_ X\rangle^*\circ( P\mathbin{\dot\times} Q)$
, and the binary product
$(\!\mathbin{\dot\times}\!)$
satisfies
$ P\mathbin{\dot\times} Q=\pi_1^* P\wedge\pi_2^* Q$
. A logical analogy of the binary product
$(\!\mathbin{\dot\times}\!)$
on
$\mathbb{P}$
is to take the conjunction
$\phi(i)\wedge\psi(j)$
of unary predicates
$\phi(i)$
and
$\psi(j)$
and regard it as a binary predicate.
We define a Dijkstra structure with finite products to be a tuple of a Dijkstra structure
$(p,\mathsf{T},{\dot {\mathsf{T}}})$
and a finite product
$(1,\dot 1,\times,\mathbin{\dot\times})$
on p. We write
$(p:(\mathbb{P},\dot 1,\mathbin{\dot\times})\to(\mathbb{C},1,\times),\mathsf{T},{\dot {\mathsf{T}}})$
for such a tuple.
Definition 11. A strength on a Dijkstra structure
$(p:(\mathbb{P},\dot 1,\mathbin{\dot\times})\to(\mathbb{C},1,\times),\mathsf{T},{\dot {\mathsf{T}}})$
with finite products is a pair
$(\theta,\dot\theta)$
of a strength
$\theta$
on
$\mathsf{T}$
and a strength
$\dot\theta$
on
${\dot {\mathsf{T}}}$
such that
$p\dot\theta_{ P, Q}=\theta_{p P,p Q}$
holds for any
$ P, Q\in\mathbb{P}$
. We say that the strength
$(\theta,\dot\theta)$
is Cartesian if each component of
$\dot\theta$
is Cartesian.
Again, Dijkstra structures with strengths are considered in the context of logical relations for strong monads (Filinski 1996; Reference Filinski2007; Goubault-Larrecq et al. Reference Goubault-Larrecq, Lasota and Nowak2008; Katsumata Reference Katsumata2005; Katsumata et al. Reference Katsumata, Sato and Uustalu2018). Since we are considering posetal fibrations, a natural transformation
$\dot\theta$
is a strength on
${\dot {\mathsf{T}}}$
if it is above a strength on
$\mathsf{T}$
. We formally state this property as follows.
Lemma 12. Let
$(p:(\mathbb{P},\dot 1,\mathbin{\dot\times})\to(\mathbb{C},1,\times),\mathsf{T},{\dot {\mathsf{T}}})$
be a Dijkstra structure with finite products. Then A strength
$(\theta,\dot\theta)$
on
$(p,\mathsf{T},{\dot {\mathsf{T}}})$
bijectively corresponds to a strength
$\theta$
on
$\mathsf{T}$
satisfying the inequality
$ P\mathbin{\dot\times}{\dot {\mathsf{T}}} Q \le \theta_{p P,p Q}^*{\dot {\mathsf{T}}}( P\mathbin{\dot\times} Q)$
. Moreover, when the strength is Cartesian, the inequality becomes the equality.
A strength on a Dijkstra structure with finite products is related to the reasoning principle behind the frame rule, which we informally explain below. Let f be an imperative program over a program variable context
$\Gamma$
, and suppose that it satisfies a Hoare triple
$\Gamma\vdash\phi\{f\}\psi$
; it is explicitly annotated with the context
$\Gamma$
for the program f and pre/post conditions
$\phi,\psi$
. Let
$\rho$
be another assertion over a program variable context
$\Delta$
that is disjoint from
$\Gamma$
. Then the frame rule allows us to derive a Hoare triple on the program f when executed in the extended program variable context
$\Gamma,\Delta$
:
The frame rule can be expressed in a general Dijkstra structure with finite products (see item (2) below) whose base monad has a strength. We show that the soundness of the frame rule is equivalent to the existence of a strength on the Dijkstra structure with finite products.
Proposition 13. Let
$(p:(\mathbb{P},\dot 1,\mathbin{\dot\times})\to(\mathbb{C},1,\times),\mathsf{T},{\dot {\mathsf{T}}})$
be a Dijkstra structure with finite products and
$\theta$
be a strength of
$\mathsf{T}$
. The following are equivalent:
-
(1) There exists a strength
$\dot\theta$
on
${\dot {\mathsf{T}}}$
such that
$(\theta,\dot\theta)$
is a strength of the Dijkstra structure. -
(2)
$ P\{f\} Q$
implies
$( R\mathbin{\dot\times} P)\{p R\cdot_\theta f\}( R\mathbin{\dot\times} Q)$
for any
$ P, Q, R\in\mathbb{P}$
and morphism
$f:p P\to \mathsf{T} p Q$
in
$\mathbb{C}$
. -
(3)
$ R\mathbin{\dot\times} \mathrm{wp}(\,f, Q)\leq \mathrm{wp}(p R\cdot_\theta f,( R\mathbin{\dot\times} Q))$
holds for any
$ P, Q, R\in\mathbb{P}$
and morphism
$f:p P\to \mathsf{T} p Q$
in
$\mathbb{C}$
.
Furthermore,
$(\theta,\dot\theta)$
in (1) is Cartesian if and only if the inequality in (3) is an equality.
Proof. Assume
$f \colon X \to \mathsf{T} Y$
. We first prove (1) implies (3). Let
$Z=p R$
. Note that
$\dot\theta \colon R \mathbin{\dot\times} {\dot {\mathsf{T}}} Q \to {\dot {\mathsf{T}}} ( R \mathbin{\dot\times} Q)$
is above
$\theta_{Z,Y} \colon Z \times \mathsf{T} Y \to \mathsf{T} (Z \times Y)$
. Therefore,
$ R \mathbin{\dot\times} \mathsf{T} Q \leq \theta_{Z,Y}^\ast({\dot {\mathsf{T}}}( R \mathbin{\dot\times} Q))$
, and we have an equality if
$\dot\theta$
is Cartesian. Then
We then show that (3) implies (1). By definition,
$ \mathrm{wp}( Z\cdot_\theta {\rm id}_{\mathsf{T} Y},( R\mathbin{\dot\times} Q)) = \theta_{Z,Y}^\ast {\dot {\mathsf{T}}}( R\mathbin{\dot\times} Q)$
and by (3) we have an inclusion
$ R \mathbin{\dot\times} \mathrm{wp}({\rm id}_{\mathsf{T} Y}, Q) = R \mathbin{\dot\times} {\dot {\mathsf{T}}} Q \leq \theta_{Z,Y}^\ast {\dot {\mathsf{T}}}( R\mathbin{\dot\times} Q) $
in the fiber above
$Z\times \mathsf{T} Y$
. From Lemma 12, we obtain a strength
$(\theta,\dot\theta)$
for the Dijkstra structure. If
$ R \mathbin{\dot\times} {\dot {\mathsf{T}}} Q = \theta_{Z,Y}^\ast {\dot {\mathsf{T}}}( R\mathbin{\dot\times} Q)$
, then the strength
$(\theta,\dot\theta)$
is Cartesian.
We now show that (3) implies (2). From (3), we get
$ ( R\mathbin{\dot\times} \mathrm{wp}(\,f, Q))\{ Z\cdot_\theta f\}( R\mathbin{\dot\times} Q) $
By assumption, also
$ P\{f\} Q$
, so
$P \leq \mathrm{wp}(\,f, Q)$
. From all this, it follows that
$ ( R\mathbin{\dot\times} P)\{ Z\cdot_\theta f\}( R\mathbin{\dot\times} Q) $
Finally, we show that (2) implies (3). By definition,
3.5 Strongest Postcondition Predicate Transformers
We turn our attention to strongest postcondition predicate transformers. In Hoare logic, the strongest postcondition with respect to a program f and a precondition
$\phi$
is a formula
$\psi$
such that (1)
$\phi\{f\}\psi$
holds, and (2) if
$\phi\{f\}\xi$
holds, then
$\psi$
must entail
$\xi$
.
We formulate the concept of strongest postcondition in a
${\mathbb K}$
-Dijkstra structure
$(p:\mathbb{P}\rightarrow\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
. The strongest postcondition with respect to a morphism
$f: X\to \mathsf{T} Y$
in
$\mathbb{C}$
and an object
$ P\in\mathbb{P}_ X$
is an object
$S\in\mathbb{P}_{ Y}$
such that for any
$ Q\in\mathbb{P}_ Y$
,
$S\le Q$
if and only if
$ P\{f\} Q$
. If such S exists, it is uniquely determined by f and P, hence we write it by
$\mathrm{sp}(\,f, P)$
. To summarize, we obtain the three-way equivalence:
This exhibits that the sppt corresponds to the left adjoint of the wppt, leading us to the following definition.
Definition 14. We say that a
${\mathbb K}$
-Dijkstra structure
$(p:\mathbb{P}\to\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
admits the strongest postcondition predicate transformer (sppt for short) if for any morphism
$f: X\to \mathsf{T} Y$
in
$\mathbb{C}$
,
$\mathrm{wp}(\,f,\_)\in\mathbb K(\mathbb{P}_ Y,\mathbb{P}_ X)$
is a right adjoint. Its associated left adjoint is denoted by
$\mathrm{sp}(\,f,\_)\in{\bf Pos}(\mathbb{P}_ X,\mathbb{P}_ Y)$
.
We note that the sppt
$\mathrm{sp}(\,f,\_)$
does not need to belong to
$\mathbb K$
. From this definition, if
$\mathbb K$
is a subcategory of Pos such that every morphism in
$\mathbb K$
is a right adjoint, then any
${\mathbb K}$
-Dijkstra structure admits the sppt. A typical example of such
$\mathbb K$
is the subcategory
${\bf CLat}_\wedge$
of Pos consisting of complete lattices and meet-preserving functions. Since every morphism in
${\bf CLat}_\wedge$
is a right adjoint, any Dijkstra structure
${{\bf CLat}_\wedge}$
admits the sppt.
Like the case of wppts, sppts in general do not satisfy the composability. They do so if and only if the
${\mathbb K}$
-Dijkstra structure is Cartesian:
Theorem 15. Let
$(p:\mathbb{P}\to\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
be a
${\mathbb K}$
-Dijkstra structure admitting the sppt. We have inequalities
for any f,g, P of appropriate type. Moreover, both inequalities in (10) become equalities if and only if the
${\mathbb K}$
-Dijkstra structure is Cartesian.
Proof. (10) easily follows by taking the adjoint mate of (5) in Theorem 6. Next, assume that inequalities in (10) are equalities. We show that inequalities in (5) become equalities. From the assumption, we obtain
and
which implies
$\mathrm{wp}(\,f\bullet g, P)\le \mathrm{wp}(g,\mathrm{wp}(\,f, P))$
. These are the other direction of (5), hence proved. The converse is proven similarly.
Therefore, for a Cartesian Dijkstra structure
$(p:\mathbb{P}\to\mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
admitting sppts, the functor
$p_{\mathsf{T},{\dot {\mathsf{T}}}}:\mathbb{P}_{\dot {\mathsf{T}}}\to\mathbb{C}_\mathsf{T}$
between Kleisli categories defined in Theorem 7 is a posetal bifibration (a posetal fibration such that each reindexing functor is a right adjoint; see Jacobs (Reference Jacobs1999, Definition 9.1.1) for the definition).
4. Dijkstra Structures on Lax Slice Categories
In the setting of an arbitrary posetal fibration, we are unaware of a general way of constructing Cartesian liftings of monads. However, in the specific case of a domain fibration from a lax slice category (introduced in Section 4.2), there is a recipe for constructing Cartesian liftings. We discuss this construction in this section, and visit examples in Sections 5–9.
A lax slice category is constructed from an object
$\Omega$
in a category
$\mathbb{C}$
and a partial order
$\le_X$
given to each homset
$\mathbb{C}(X,\Omega)$
. We call the pair
$(\Omega,\le\!)$
an ordered object in
$\mathbb{C}$
(Definition 16). Then the lax slice category
${\mathbb{C}/_{\!\mathrm{\ell}}\Omega}$
is defined by the following data: an object is a morphism into
$\Omega$
, and a morphism from f to g is a morphism
$h:{\rm dom}(\,f)\to {\rm dom}(g)$
with the following inequality:

The domain functor extracting the domain part of this diagram, which is denoted by
$d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C}$
, becomes a posetal fibration; we hence call it a domain fibration.
Footnote 3
In Theorem 26, we show that a Cartesian lifting of a monad T on
$\mathbb{C}$
along
$d^{{\mathbb{C}},{\Omega}}$
bijectively corresponds to an Eilenberg–Moore monotone algebra on
$\Omega$
. This correspondence significantly reduces the search space for Cartesian liftings. Specially, when
$\mathbb{C}={\bf Set}$
and
$\Omega$
and
$T\Omega$
are both finite, it is possible to enumerate all such algebras. We carry out this enumeration for some monads in Section 5.
We also seek for a principle behind the correspondence between structures on
$d^{{\mathbb{C}},{\Omega}}$
and structures on
$\Omega$
. We present it as a biequivalence result (Theorem 25) between the 2-category
${\bf CO}(\mathbb K)$
of ordered objects (Definition 21) and the 2-category
${\mathbb K}\text{-}{\bf Fib}_{g}$
of
$\mathbb K$
-fibrations with split generic objects (Definition 24), the latter of which is a full sub-2-category of
${\mathbb K}\text{-}{\bf Fib}$
(the left of (11)). A similar result holds when 2-cells of
${\mathbb K}\text{-}{\bf Fib}_{g}$
and
${\mathbb K}\text{-}{\bf Fib}$
are restricted to Cartesian ones; 2-cells of
${\bf CO}(\mathbb K)$
are also restricted accordingly (the right of (11)).
This biequivalence is working behind the proof of lifting-algebra correspondence (Theorem 25). The same proof strategy is employed for establishing a correspondence between (1) liftings of distributive laws and distributive laws satisfying certain axioms with respect to Eilenberg–Moore monotone algebra pairs (Theorem 27) and (2) liftings of monad strengths and strengths satisfying a certain inequality with respect to an Eilenberg–Moore monotone algebras (Theorem 29).
In Section 4.4, we discuss the interaction between wppts of a Cartesian Dijkstra structure of the form
$(d^{{\Omega},{\mathbb{C}}},\mathsf{T},{\dot {\mathsf{T}}})$
and algebraic operations of
$\mathsf{T}$
in the sense of Plotkin and Power (Reference Plotkin, Power, Brooks and Mislove2001).
4.1 Ordered Objects
With the goal of having fibers with a partial order structure, we consider slices over ordered objects, defined below:
Definition 16. An ordered object in a category
$\mathbb{C}$
is a pair of an object
$\Omega$
and an assignment of a partial order
$\le_ X$
to the homset
$\mathbb{C}( X,\Omega)$
for each
$ X\in\mathbb{C}$
. These partial orders should be such that, for any morphism
$f: Y\to X$
in
$\mathbb{C}$
,
$i\le_ X j$
implies
$i\circ f\le_ Y j\circ f$
.
Equivalently, an ordered object is a pair of an object
$\Omega$
and a functor
$A:\mathbb{C}^{op}\rightarrow{\bf Pos}$
such that
$U\circ A=\mathbb{C}(\_,\Omega)$
, where
$U:{\bf Pos}\rightarrow{\bf Set}$
is the forgetful functor. The object
$\Omega$
corresponds to the set of truth values, and a morphism
$i: X\to \Omega$
in
$\mathbb{C}$
corresponds to an
$\Omega$
-valued predicate on X. The order
$\le_ X$
compares the strength of predicates:
$i\le_ X j$
means that i implies j.
To impose further conditions on the partial order, we parameterize Definition 16 by a subcategory
$\mathbb K$
of Pos.
Definition 17. We say that an ordered object
$(\Omega,\le\!)$
in a category
$\mathbb{C}$
belongs to
$\mathbb K$
if each poset
$(\mathbb{C}( X,\Omega),\le_ X\!)$
belongs to
$\mathbb K$
, and for any morphism
$f: X\to Y$
in
$\mathbb{C}$
, the function
$\_\circ f$
is a morphism from
$(\mathbb{C}( Y,\Omega),\le_ Y\!)$
to
$(\mathbb{C}( X,\Omega),\le_ X\!))$
in
$\mathbb K$
.
Example 18. A typical way to give an ordered object in Set is to take a poset
$(\Omega,\le\!)$
and define the partial order
$\le_ X$
on the homset
${\bf Set}( X,\Omega)$
to be the pointwise order. Examples in Sections 5–8 all use domain fibrations arising from this kind of ordered object. Moreover, if the poset
$(\Omega,\le\!)$
belongs to a subcategory
$\mathbb K$
of Pos, and
$\mathbb K$
has small powers
Footnote 4
of
$(\Omega,\le\!)$
, then the ordered object
$(\Omega,\le_{ X}\!)$
belongs to
$\mathbb K$
.
Example 19. Generalizing the previous example, let
$\mathbb{C}$
be a category with finite limits. An internal partial order is a monomorphism
$m:R\rightarrowtail\Omega\times\Omega$
satisfying reflexivity, transitivity, and antisymmetry expressed diagrammatically; see Lane and Moerdijk (Reference Lane and Moerdijk1994, Section IV.8). For each
$ X\in\mathbb{C}$
, the following binary relation
$\le_ X$
over
$\mathbb{C}( X,\Omega)$
becomes a partial order:
Then
$(\Omega,\le_{ X}\!)$
becomes an ordered object in
$\mathbb{C}$
. To summarize, an internal partial order in
$\mathbb{C}$
induces an ordered object in
$\mathbb{C}$
.
Example 20. Not every ordered object arises in the way given in Example 19. In categories without finite limits (such as Kleisli categories of monads), we cannot have an internal partial order, but we can still have ordered objects. For example, the Kleisli category of the finite probability distribution monad
$\mathsf{D}$
(Example 40) over Set does not have finite products, but there is an ordered object
$\{\bot,\top\}$
(a two-point set) whose order is defined by
When
$\mathbb{C}$
comes with a Pos-enrichment, that is, an assignment of a partial order
$\sqsubseteq_{ X, Y}$
to each homset
$\mathbb{C}( X, Y)$
making the composition monotone, any object
$\Omega\in\mathbb{C}$
determines an ordered object
$(\Omega,\sqsubseteq_{\_,\Omega})$
. However, it is not desirable to restrict our attention to such ordered objects in Pos-enriched categories, because there can be cases where the order
$\sqsubseteq_{ X,\Omega}$
is not adequate for comparing strength of predicates on X. For instance, the category Set may be seen as a Pos-enriched category by considering the discrete order on each homset. However, the ordered object
$(\Omega,=_{\_,\Omega})$
based on this enrichment only gives the discrete order on
$\Omega$
-valued predicates, which is not very useful. Therefore we need freedom to give an ordered object independently from the Pos-enrichment on a category.
4.2 Lax Slice Construction 60
Let
$\mathbb{C}$
be a category and
$(\Omega,\le\!)$
be an ordered object in
$\mathbb{C}$
belonging to a subcategory
$\mathbb K$
of Pos. We define the lax slice category
${\mathbb{C}/_{\!\mathrm{\ell}}\Omega}$
by the following data:
An object is a morphism in
$\mathbb{C}$
whose codomain is
$\Omega$
.A morphism from i to j is a morphism
$h:{\rm dom}(i)\to {\rm dom}(j)$
in
$\mathbb{C}$
such that
$i\le_{{\rm dom}(i)} j\circ h$
.
The domain functor
$d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C}$
is defined by
It is a
$\mathbb K$
-fibration, and the fiber category
$({\mathbb{C}/_{\!\mathrm{\ell}}\Omega})_ X$
at
$ X\in\mathbb{C}$
is the poset
$(\mathbb{C}( X,\Omega),\le_ X\!)$
. The pullback of
$i: X\rightarrow\Omega$
along
$h: Y\rightarrow X$
is given by
$h^*i=i\circ h$
.
We further investigate the 2-categorical nature of the construction of lax slice categories. We introduce the following 2-categories
${\bf CO}(\mathbb K)$
and
${\bf CO}_c(\mathbb K)$
whose 0-cells are categories with ordered objects belonging to a subcategory
$\mathbb K$
of Pos.
Definition 21. Let
$\mathbb K$
be a subcategory of Pos. The 2-category
${\bf CO}(\mathbb K)$
is defined by the following data.
A 0-cell is a tuple
$(\mathbb{C},\Omega,\le\!)$
consisting of a category
$\mathbb{C}$
and an ordered object
$(\Omega,\le\!)$
in
$\mathbb{C}$
belonging to
$\mathbb K$
.A 1-cell from
$(\mathbb{C},\Omega,\le\!)$
to
$(\mathbb D,\Pi,\le\!)$
is a pair of a functor
$F:\mathbb{C}\to\mathbb D$
and a morphism
$o:F\Omega\to \Pi$
in
$\mathbb D$
such that
$o\circ F\_$
is a monotone function belonging to
$\mathbb K$
in the following sense: (12)The identity 1-cell and the composition of 1-cells are defined by
\begin{equation} \forall{ X\in\mathbb{C}}~.~ o\circ F\_ \in\mathbb K((\mathbb{C}( X,\Omega),\le_ X\!),(\mathbb D(F X,\Pi),\le_{F X}\!)). \end{equation}
\begin{align*} {\rm id}_{(\mathbb{C},\Omega,\le\!)}&\mathbin{\triangleq}({\rm Id}_\mathbb{C},{\rm id}_\Omega), & (F,o)\circ (G,o')&\mathbin{\triangleq}(F\circ G,o\circ Fo'). \end{align*}
For 1-cells
$(F,o),(G,o'):(\mathbb{C},\Omega,\le\!)\to(\mathbb D,\Pi,\le\!)$
, a 2-cell from the former to the latter is a natural transformation
$\alpha:F\to G$
such that
$o\le o'\circ\alpha_\Omega$
.
Definition 22. We define a subcategory
${\bf CO}_c(\mathbb K)$
of
${\bf CO}(\mathbb K)$
by restricting 2-cells from (F,o) to (G,o’) to natural transformations
$\alpha:F\to G$
such that
$o= o'\circ\alpha\Omega$
.
We extend the lax slice construction to 2-functors. We first mention a few facts:
For a 1-cell
$(F,o)\in{\bf CO}(\mathbb K)((\mathbb{C},\Omega,\le\!),(\mathbb D,\Pi,\le\!))$
, let
$F_o:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\to{\mathbb D/_{\!\mathrm{\ell}}\Pi}$
be the functor defined by From (12) it follows that
\begin{align*}F_o(i) & \mathbin{\triangleq} o\circ F i, & \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,F_o(\,f) & \mathbin{\triangleq} F f.\end{align*}
$(F,F_o)$
is a fibered
$\mathbb K$
-functor from
$d^{{\mathbb{C}},{\Omega}}$
to
$d^{{\mathbb D},{\Pi}}$
.
There is a bijective correspondence between 2-cells in
${\bf CO}(\mathbb K)$
and
${\mathbb K}\text{-}{\bf Fib}$
: (13)
\begin{align} &{\bf CO}(\mathbb K)((\mathbb{C},\Omega,\le\!),(\mathbb D,\Pi,\le\!))((F,o),(G,o'))\end{align}
(14)
\begin{align} &=\{\alpha:F\to G~|~o\le o'\circ \alpha_\Pi\}\end{align}
(15)
\begin{align} &=\{\alpha:F\to G~|~\forall{i}~.~F_oi\le \alpha_{{\rm dom}(i)}^*(G_{o'}i)\} \end{align}
(16)The equality between (14) and (15) is by
\begin{align} &\cong{\mathbb K}\text{-}{\bf Fib}(d^{{\mathbb{C}},{\Omega}},d^{{\mathbb D},{\Pi}})((F,F_o),(G,G_o)) . \end{align}
and the bijection from (15) to (16) is
\begin{align*} (\forall{i}~.~F_oi\le \alpha_{{\rm dom}(i)}^*(G_{o'}i)) & \iff (\forall{i}~.~o\circ Fi\le o'\circ Gi\circ \alpha_{{\rm dom}(i)}=o'\circ \alpha_\Pi\circ Fi)\\ & \iff o\le o'\circ \alpha_\Pi, \end{align*}
$\Xi^{-1}$
given in (1). A similar bijective correspondence between 2-cells of
${\bf CO}_c(\mathbb K)$
and
${\mathbb K}\text{-}{\bf Fib}_c$
also holds by using
$\Xi^{-1}_c$
instead of
$\Xi^{-1}$
:
\begin{align*} &{\bf CO}_c(\mathbb K)((\mathbb{C},\Omega,\le\!),(\mathbb D,\Pi,\le\!))((F,o),(G,o'))\\ &\cong{\mathbb K}\text{-}{\bf Fib}_c(d^{{\mathbb{C}},{\Omega}},d^{{\mathbb D},{\Pi}})((F,F_o),(G,G_o)). \end{align*}
From these, we define 2-functors
$L_{\mathbb K}:{\bf CO}(\mathbb K)\to{\mathbb K}\text{-}{\bf Fib}$
and
$L_{\mathbb K,c}:{\bf CO}_c(\mathbb K)\to{\mathbb K}\text{-}{\bf Fib}_c$
by
The verification of this being a 2-functor is routine, and omitted.
Theorem 23. Let
$\mathbb K$
be a subcategory of Pos. The 2-functors
$L_{\mathbb K}$
and
$L_{\mathbb K,c}$
are local isomorphisms, that is, each hom-functor is an isomorphism.
Proof. We first prove the case of
$L_{\mathbb K}$
; the proof of the case
$L_{\mathbb K,c}$
is similar. It suffices to show that each hom-functor:
is bijective on objects, because full faithfulness is already guaranteed by (13)–(16). Let
$(F,\dot F):d^{{\mathbb{C}},{\Omega}}\to d^{{\mathbb D},{\Pi}}$
be a 1-cell in
${\mathbb K}\text{-}{\bf Fib}$
. We show that
$(F,\dot F({\rm id}_\Omega))\in{\bf CO}(\mathbb K)$
is the unique 1-cell yielding
$(F,\dot F)$
. We first show the functor equality
$F_{\dot F({\rm id}_\Omega)}=\dot F:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\to{\mathbb D/_{\!\mathrm{\ell}}\Pi}$
.
\begin{align*} F_{\dot F({\rm id}_\Omega)}i&= \dot F({\rm id}_\Omega)\circ Fi =(F i)^*(\dot F({\rm id}_\Omega)) =\dot F(i^*({\rm id}_\Omega)) =\dot Fi,\\ F_{\dot F({\rm id}_\Omega)}h&=Fh=\dot Fh. \end{align*}
Therefore,
$(F,\dot F({\rm id}_\Omega))$
is a 1-cell in
${\bf CO}(\mathbb K)$
. Next, let
$(F,o)\in{\bf CO}(\mathbb K)$
be a 1-cell such that
$(F,F_o)=(F,\dot F)$
. Then
$\dot F({\rm id}_\Omega)=F_o({\rm id}_\Omega)=o$
, hence
$(F,o)=(F,\dot F({\rm id}_\Omega))$
. This proves that
$L_{\mathbb K}$
is bijective on objects.
We characterize the image of
$L_{\mathbb K}$
and
$L_{\mathbb K,c}$
. Let
$p:\mathbb{P}\to\mathbb{C}$
be a
$\mathbb K$
-fibration. A split generic object
$\Omega\in\mathbb{P}$
is such that for any object
$ P\in\mathbb{P}$
, there exists a unique morphism
$\chi:\to p P$
in
$p\Omega$
${\mathbb{P}}$
such that
$ P=\chi^*\Omega$
Jacobs (Reference Jacobs1999, Definition 5.2.1). Note that split generic objects are mutually isomorphic.
Definition 24. We write
${\mathbb K}\text{-}{\bf Fib}_{g}$
(resp.
${\mathbb K}\text{-}{\bf Fib}_{c,g}$
) for the 2-category obtained by restricting 0-cells of
${\mathbb K}\text{-}{\bf Fib}$
(resp.
${\mathbb K}\text{-}{\bf Fib}_c$
) to
$\mathbb K$
-fibrations having split generic objects.
Theorem 25. For any replete subcategory
$\mathbb K$
of Pos,
${\bf CO}(\mathbb K)$
(resp.
${\bf CO}_c(\mathbb K)$
) is biequivalent to
${\mathbb K}\text{-}{\bf Fib}_{g}$
(resp.
${\mathbb K}\text{-}{\bf Fib}_{c,g}$
).
Proof. We first show that
$L_{\mathbb K}$
is essentially surjective on 0-cells. Let
$p:\mathbb{P}\to\mathbb{C}$
be a
$\mathbb K$
-fibration with a split generic object
$\Omega\in\mathbb{P}$
. We first extract an ordered object in
$\mathbb{C}$
belonging to
$\mathbb K$
. From the definition of split generic object, the function
$(\!-\!)3^*\Omega:\mathbb{C}( X,p\Omega)\to {\bf Obj}(\mathbb{P}_ X)$
is a bijection; we write
$\Psi_ X$
for its inverse. We put a partial order on
$\mathbb{C}( X,p\Omega)$
by:
$f\le_ X g\iff f^*\Omega\le g^*\Omega$
. Then the bijection becomes an isomorphism between
$(\mathbb{C}( X,p\Omega),\le_ X\!)$
and
$\mathbb{P}_ X$
in Pos, which further becomes an isomorphism in
$\mathbb K$
because
$\mathbb K$
is replete. Then for any morphism
$f: X\to Y$
in
$\mathbb{C}$
, the composite of the following morphisms in
$\mathbb K$
is equal to
$\_\circ f$
:
Therefore,
$p\Omega$
is an ordered object in
$\mathbb{C}$
belonging to
$\mathbb K$
. It is then routine to show that
$d^{{\mathbb{C}},{p\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}p\Omega}\rightarrow \mathbb{C}$
is isomorphic to
$p:\mathbb{P}\to\mathbb{C}$
in
${\mathbb K}\text{-}{\bf Fib}_{g}$
. The case of
$L_{\mathbb K,c}$
is proved similarly.
4.3 Characterizing
${\mathbb K}$
-Dijkstra Structures on Domain Fibrations
Recall that a Cartesian
${\mathbb K}$
-Dijkstra structure is precisely a monad in
${\mathbb K}\text{-}{\bf Fib}_c$
. The local isomorphism theorem (Theorem 23) implies the following characterization of Cartesian
${\mathbb K}$
-Dijkstra structures on domain fibrations.
Theorem 26. Let
$(\mathbb{C},\Omega,\le\!)\in{\bf CO}_c(\mathbb K)$
be a 0-cell. Then there is a bijective correspondence between
-
(1) A Cartesian
${\mathbb K}$
-Dijkstra structure whose
$\mathbb K$
-fibration is
$d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C}$
. -
(2) A pair of a monad
$\mathsf{T}$
on
$\mathbb{C}$
and an EM monotone
$\mathsf{T}$
-algebra
$(o,\Omega)$
belonging to
$\mathbb K$
(when
$\mathbb K={\bf Pos}$
, we omit “belonging to
$\mathbb K$
”), that is, an EM algebra such that
$o\circ\mathsf{T}\_$
satisfies (12).
Proof. Let
$(\mathbb{C},\Omega,\le\!)\in{\bf CO}_c(\mathbb K)$
be a 0-cell and
$(\mathsf{T},{\dot {\mathsf{T}}}),(\mu,\dot\mu),(\eta,\dot\eta)$
be a monad on
$d^{{\mathbb{C}},{\Omega}}$
in the 2-category
${\mathbb K}\text{-}{\bf Fib}_c$
. From Theorem 23, there exists a unique 1-cell
$(\mathsf{T},o)$
and 2-cells
$\eta,\mu$
in
${\bf CO}_c(\mathbb K)$
whose images by
$L_{\mathbb K,c}$
coincide with
$(\mathsf{T},{\dot {\mathsf{T}}}),(\mu,\dot\mu),(\eta,\dot\eta)$
, respectively. It is then routine to check that
$((\mathsf{T},o),\eta,\mu)$
is a monad on
$(\mathbb{C},\Omega,\le\!)$
in
${\bf CO}_c(\mathbb K)$
. By unraveling the definition, the monad consists of an ordinary monad
$(\mathsf{T},\eta,\mu)$
on
$\mathbb{C}$
and an EM
$\mathsf{T}$
-algebra
$o:\mathsf{T}\Omega\to\Omega$
such that
$o\circ \mathsf{T}\_$
belongs to
$\mathbb K$
in the sense of (12).
In many situations, monads for modeling computational effects are composites of simpler monads through distributive laws. We extend our lifting theory of monads to composite monads. Let
$\mathsf{T},\mathsf{S}$
be monads on
$\mathbb{C}$
and
$\alpha:\mathsf{S} \mathsf{T}\rightarrow \mathsf{T} \mathsf{S}$
be a distributive law (see Section 2). We are interested in EM monotone
$\mathsf{T}\circ_\alpha \mathsf{S}$
-algebras, which give Cartesian liftings of
$\mathsf{T}\circ_\alpha \mathsf{S}$
. EM algebras of composite monads are studied in Beck (Reference Beck1969, Section 2), Manes and Mulry (Reference Manes and Mulry2007, Theorem 2.4.3). Below we mildly extend these results.
Theorem 27. Let
$(\mathbb{C},\Omega,\le\!)\in{\bf CO}_c(\mathbb K)$
be a 0-cell,
$\mathsf{T},\mathsf{S}$
be monads on
$\mathbb{C}$
and
$\alpha:\mathsf{S} \mathsf{T}\rightarrow \mathsf{T} \mathsf{S}$
be a distributive law. There is a bijective correspondence between each two of:
-
(1) An EM monotone
$\mathsf{T}\circ_\alpha \mathsf{S}$
-algebra
$(o,\Omega)$
belonging to
$\mathbb K$
. -
(2) A pair of an EM monotone
$\mathsf{T}$
-algebra
$(t,\Omega)$
belonging to
$\mathbb K$
and an EM monotone
$\mathsf{S}$
-algebra
$(s,\Omega)$
belonging to
$\mathbb K$
satisfying (17)
\begin{equation} s\circ \mathsf{S} t=t\circ \mathsf{T} s\circ\alpha_\Omega. \end{equation}
-
(3) A triple
$(\dot{\mathsf{T}},\dot{\mathsf{S}},\dot\alpha)$
where
${\dot {\mathsf{T}},\dot{\mathsf{S}}}$
are, respectively, Cartesian liftings of
$\mathsf{T},\mathsf{S}$
along
$d^{{\mathbb{C}},{\Omega}}$
, and
${\dot\alpha:\dot {\mathsf{S}}\dot {\mathsf{T}}\rightarrow\dot {\mathsf{T}}\dot {\mathsf{S}}}$
is a distributive law above
$\alpha$
whose components are Cartesian.
Proof. The bijection between (2) and (3) is proved in the same way as Theorem 26. We show a bijective correspondence between (1) and (2). Let
$(o,\Omega)$
be an EM monotone
$\mathsf{T}\circ_\alpha\mathsf{S}$
-algebra belonging to
$\mathbb K$
. Then it is routine to show that
$t\mathbin{\triangleq} o\circ T\eta^\mathsf{S}_\Omega:\mathsf{T}\Omega\to\Omega$
and
$s\mathbin{\triangleq} o\circ \eta^\mathsf{T}_{\mathsf{S}\Omega}:\mathsf{S}\Omega\to\Omega$
are both EM algebras. To show that t,s are monotone and belong to
$\mathbb K$
, observe that functions on the left-hand side below are equal to composite monotone functions on the right-hand side belonging to
$\mathbb K$
:

Conversely, let
$t:\mathsf{T}\Omega\to\Omega,s:\mathsf{S}\Omega\to\Omega$
be EM monotone algebras belonging to
$\mathbb K$
. Then it is routine to show that
$o\mathbin{\triangleq} t\circ \mathsf{T} s$
is an EM
$\mathsf{T}\circ_\alpha\mathsf{S}$
-algebra, provided that t,s satisfies (17). Moreover, o is a monotone and belongs to
$\mathbb K$
because the function on the left-hand side below is the composite monotone function on the right-hand side, which belongs to
$\mathbb K$
:
We note that the condition (17) appears in Beck (Reference Beck1969, Section 2). This theorem says that to identify a lifting of
$\mathsf{T}\circ_\alpha \mathsf{S}$
, it suffices to identify a pair of EM monotone
$\mathsf{T}$
- and
$\mathsf{S}$
-algebras satisfying (17).
We next apply the local isomorphism theorem (Theorem 23) to characterize strengths on Cartesian Dijkstra structures whose fibrations are domain fibrations. We first identify the situation when domain fibrations have finite products.
Proposition 28. Let
$(\mathbb{C},\Omega,\le\!)\in{\bf CO}_c({\bf Pos})$
be a 0-cell. The following are equivalent:
-
(1) The domain fibration
$d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C}$
has finite products
$(1,\dot 1,\times,\mathbin{\dot\times})$
. -
(2)
$\mathbb{C}$
has finite products
$(1,\times)$
, and there are morphisms
$\top:1\to\Omega, m:\Omega^2\to \Omega$
such that
$\top\circ !_ X$
and
$m\circ\langle \_,\_\rangle$
give finite meets in the poset
$(\mathbb{C}( X,\Omega),\le_ X\!)$
.
Theorem 29. Let
$(\mathbb{C},\Omega,\le\!)\in{\bf CO}_c({\bf Pos})$
be a 0-cell, and suppose that
$d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C}$
has finite products
$(1,\dot 1,\times,\mathbin{\dot\times})$
. We write
$m:\Omega^2\to\Omega$
for the meet morphism that exists by Proposition 28. Let
$(d^{{\mathbb{C}},{\Omega}},\mathsf{T},{\dot {\mathsf{T}}})$
be a Cartesian Dijkstra structure and let
$o:\mathsf{T}\Omega\to\Omega$
be the EM monotone
$\mathsf{T}$
-algebra corresponding to
${\dot {\mathsf{T}}}$
. There is a bijective correspondence between:
-
(1) a strength on the Cartesian Dijkstra structure, and
-
(2) a strength
$\theta$
on
$\mathsf{T}$
such that
$m\circ({\rm id}\times o)\le o\circ \mathsf{T}m\circ\theta_{\Omega,\Omega}$
.
Proof. Let
$(\theta,\dot\theta)$
be a strength on a Cartesian Dijkstra structure. From Lemma 12, and the assumption that both
$\mathbin{\dot\times}$
and
$\mathsf{T}$
are fibered, the strength bijectively corresponds to the 2-cell
$(\theta,\dot\theta)$
in
${{\bf Pos}}\text{-}{\bf Fib}$
such that
$\theta$
is a strength on
$\mathsf{T}$
.

By the local isomorphism theorem, such a 2-cell bijectively corresponds to a 2-cell in
${\bf CO}({\bf Pos})$
(see the right diagram above) where
$\theta$
is a strength of
$\mathsf{T}$
. This is equivalent to that
$\theta$
is a strength on
$\mathsf{T}$
satisfying
$m\circ({\rm id}\times o)\le o\circ \mathsf{T} m \circ\theta.$
4.4 Algebraic Operations and Weakest Precondition Predicate Transformer
Various program constructs that cause computational effects can be naturally modeled by Plotkin and Power’s algebraic operations (Plotkin and Power Reference Plotkin, Power, Brooks and Mislove2001). They frequently occur in the monadic semantics of effectful programs. In this section, we give a wppt semantics of algebraic operations in the Cartesian Dijkstra structures whose fibrations are domain fibrations.
In this section we fix a Cartesian category
$(\mathbb{C},1,\times)$
, an ordered object
$(\Omega,\le\!)$
in
$\mathbb{C}$
belonging to a subcategory
$\mathbb K$
of Pos, and a strong monad
$(\mathsf{T},\eta,\mu,\theta)$
.
Definition 30. A morphism
$g: \to A$
in
$\mathsf{T} B$
${\mathbb{C}}$
is called generic effect (Plotkin and Power Reference Plotkin, Power, Brooks and Mislove2001). For an EM
$\mathsf{T}$
-algebra
$o:\mathsf{T} X\rightarrow X$
, we define the following operation
${{\mathrm{op}}}\!(o,g):\mathbb{C}( Y,A)\times \mathbb{C}( Y\times B, X)\to\mathbb{C}( Y, X)$
by
We specifically write
$\alpha(g)_ X$
for
${{\mathrm{op}}}\!(\mu_ X,g)$
and call it the algebraic operation corresponding to g.
The first and second arguments of
${{\mathrm{op}}}\!(o,g)$
are, respectively, called a parameter and an argument. The above definition of algebraic operation is different from the original one presented in Plotkin and Power (Reference Plotkin, Power, Brooks and Mislove2001). Originally, an algebraic operation corresponding to a generic effect
$g:A\to\mathsf{T} B$
is a certain natural transformation
$\alpha_ X:A\times (B\Rightarrow \mathsf{T} X)\to\mathsf{T} X$
. In this paper, we present it as an operation on morphisms in a Cartesian category.
Proposition 31. Let
$o:\mathsf{T}\Omega\to\Omega$
be an EM monotone
$\mathsf{T}$
-algebra belonging to
$\mathbb K$
. Then for any generic effect
$g:A\to\mathsf{T} B$
and morphism
$a: Y\to A$
, we have
Proof. Notice that
${{\mathrm{op}}}\!(o,g)(a,\_)$
is the composite of the following morphisms in
$\mathbb K$
:
The following theorem helps us (in Section 7) to compute the wppt of programs involving algebraic operations:
Theorem 32. Let
$o:\mathsf{T}\Omega\rightarrow\Omega$
be an EM monotone
$\mathsf{T}$
-algebra belonging to
$\mathbb K$
and
$(d^{{\mathbb{C}},{\Omega}},\mathsf{T},\mathsf{T}_o)$
be the corresponding Cartesian
${\mathbb K}$
-Dijkstra structure. Then the following equality holds for any generic effect
$g:A\to\mathsf{T} B$
and morphism
$a: Y\to A,b: Y\times B\to\mathsf{T} X,i: X\to\Omega$
:
Proof. The equation easily follows from the EM axiom
$o\circ\mu_\Omega=o\circ \mathsf{T} o$
:
\begin{align*} \mathrm{wp} (\alpha (g)_ X (a, b), i) & = o \circ \mathsf{T} i \circ \mu_ X \circ \mathsf{T} (b) \circ \theta \circ \langle {{\mathrm{id}}}, g \circ a \rangle\\ & = o \circ \mu_{\Omega} \circ \mathsf{T}^2 i \circ \mathsf{T} (b) \circ \theta \circ \langle {{\mathrm{id}}}, g \circ a \rangle\\ & = o \circ \mathsf{T} o \circ \mathsf{T}^2 i \circ \mathsf{T} (b) \circ \theta \circ \langle {{\mathrm{id}}}, g \circ a \rangle\\ & = {{\mathrm{op}}}\!(o, g) (a, \mathrm{wp} (b, i)) . \end{align*}
When
$\mathbb{C}$
has distributive finite coproducts, we can make algebraic operations to take tuples of morphisms as arguments. Below we look at the case
$n=2$
. We write 2 for the coproduct
$1+1$
. For the setting above, it is useful to define an operator
$\beta \colon \mathbb{C}( X, Y) \times \mathbb{C}( X, Y) \to \mathbb{C}( X\times 2, Y)$
:
where
$r_{ X} : X\times 1 \to X$
is the right unitor and
$\mathrm{dist}_{X,Y,Z} \circ X\times(Y+Z) \to X\times Y + X\times Z$
is the distributive law of the product over the coproduct. Then we can show:
Corollary 33. Let
$o:\mathsf{T}\Omega\rightarrow\Omega$
be an EM monotone
$\mathsf{T}$
-algebra belonging to
$\mathbb K$
and
$(d^{{\mathbb{C}},{\Omega}},\mathsf{T},\mathsf{T}_o)$
be the corresponding Cartesian
${\mathbb K}$
-Dijkstra structure. For any generic effect
$g:A\to\mathsf{T} 2$
and morphism
$a: Y\to A,b_1,b_2: Y\to\mathsf{T} X,i: X\to\Omega$
, the following equality holds:
Proof. The key step is checking that
$\mathrm{wp}(\beta(b_1,b_2),i) = \beta(\mathrm{wp}(b_1,i),\mathrm{wp}(b_2,i))$
. Indeed,
\begin{align*} \mathrm{wp}(\beta(b_1,b_2),i) &= o \circ \mathsf{T} i \circ [b_1\circ r, b_2\circ r] \circ\mathrm{dist} \\ &= [o \circ \mathsf{T} i \circ b_1\circ r, o \circ \mathsf{T} i \circ b_2\circ r] \circ\mathrm{dist} \\ &= \beta(\mathrm{wp}(b_1,i),\mathrm{wp}(b_2,i)). \end{align*}
5. Dijkstra Structures on
$d^{{{\bf Set}},{{\bf 2}}}$
We apply the techniques developed in the previous sections to concrete settings. We first consider the lax slice category with the poset
${\bf 2}=\{\bot\le\top\}$
, viewed as an ordered object in Set (Example 18). We identify an object
$i: X\rightarrow{\bf 2}$
in
${{\bf Set}/_{\!\mathrm{\ell}}{\bf 2}}$
as a pair (X, P) of sets such that
$ P\subseteq X$
. The fibration
$d^{{{\bf Set}},{{\bf 2}}}:{{\bf Set}/_{\!\mathrm{\ell}}{\bf 2}}\rightarrow {\bf Set}$
is isomorphic to the subobject fibration (see e.g. Jacobs Reference Jacobs1999, Chapter 0) of Set.
Example 34. Hasuo (Reference Hasuo2015, Section 2.3) As a warm-up exercise, we consider Cartesian liftings of the maybe monad (a.k.a. partiality monad)
$\mathsf{M}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. Its functor part is defined by
$\mathsf{M} X\mathbin{\triangleq} X+\{*\}$
, where
$\{*\}$
denotes the singleton set. In this example, we leave implicit the coproduct injection
$\iota_i: X_i\to X_1+ X_2$
to improve readability.
There are exactly two EM monotone
$\mathsf{M}$
-algebras
$\mathrm{tot},\mathrm{par}$
over
${\bf 2}$
:
They induce Cartesian liftings
$\mathsf{M}_{\mathrm{tot}},\mathsf{M}_{\mathrm{par}}$
of
$\mathsf{M}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. The following table describes how the liftings are defined on objects and how the Hoare triple statements are interpreted in the corresponding Cartesian Dijkstra structures using these liftings:

The Cartesian Dijkstra structures associated to these Cartesian liftings offer the total and partial correctness interpretations of Hoare triples.
Example 35. Generalizing Example 34, we consider Cartesian liftings of the exception monad
$\mathsf{E}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. Its functor part is defined by
$\mathsf{E} X\mathbin{\triangleq} X+E$
, where E is a fixed set. We can easily verify that an EM monotone
$\mathsf{E}$
-algebras over
${\bf 2}$
bijectively corresponds to a subset of E. For a subset
$A\subseteq E$
, the corresponding algebra
$\mathrm{exc}_A:\mathsf{E}{\bf 2}\to{\bf 2}$
is
Let us write
$\mathsf{E}_{\mathrm{exc}_A}$
for the associated Cartesian lifting of
$\mathsf{E}$
. Its object part is given by
and the Hoare triple
$( X, P)\{f\}( Y, Q)\text{ in }(d^{{{\bf Set}},{{\bf 2}}},\mathsf{E},\mathsf{E}_{\mathrm{exc}_A})$
is equivalent to
This statement says that f returns a value satisfying Y, or raise an exception belonging to A.
Example 36. Hino et al. (Reference Hino, Kobayashi, Hasuo and Jacobs2016, Example 3.3) We next consider the Cartesian liftings of the nonempty powerset monad
${\mathsf{P}^+}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. Its functor part is defined by
$ {\mathsf{P}^+} X\triangleq\{U\subseteq X~|~U\neq\emptyset\}. $
There are exactly two EM monotone
${\mathsf{P}^+}$
-algebras
$\mathrm{may},\mathrm{must}$
over
${\bf 2}$
:
They induce two Cartesian liftings
${\mathsf{P}^+}_{\mathrm{may}},{\mathsf{P}^+}_{\mathrm{must}}$
of
${\mathsf{P}^+}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. The Dijkstra structures with these Cartesian liftings of
${\mathsf{P}^+}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
offer the may and must correctness interpretations of Hoare triples.

Example 37. We consider again the monad
$\mathsf{P}^+$
of the previous example, but now we regard
$d^{{{\bf Set}},{{\bf 2}}}$
as a
${\bf CLat_\wedge}$
-fibration. Then must above is the only EM monotone
$\mathsf{P}^+$
-algebra over
${\bf 2}$
belonging to
${\bf CLat_\wedge}$
. Therefore the must correctness interpretation of the Hoare triple has the composable strongest postcondition predicate transformer (see Section 3.5).
Example 38. We consider the state monad
$\mathsf{S}$
, whose functor part is defined by
$\mathsf{S}\ X = S \Rightarrow( X \times S)$
; here S is the set of states. Recall that a computation
$f \colon X \to \mathsf{S} Y$
can be seen as a procedure from X to Y that has access to an external memory device with states in S. However, the two-point set
${\bf 2}$
is too small to remember stored values when
$|S|\ge 2$
. Indeed,
Theorem 39. When
$|S|\ge 2$
, there is no EM monotone
$\mathsf{S}$
-algebra over
${\bf 2}$
.
Proof. Plotkin and Power (Reference Plotkin, Power, Brooks and Mislove2001) observed that algebras of the set monad correspond bijectively to mnemoids, sets that satisfy the algebraic theory of update-lookup. For the carrier 2, these operations have the types:
and satisfy the equations below:
The algebraic theory implies that if
${\it update}(s,b) = 1$
for any s and b, then
${\it update}(t,1) = 1$
for all t, since
by Equation 20. An analogous reasoning can be done when
${\it update}(s,b) = 0$
. This leaves two cases, either
${\it update}(t,0) = 0$
and
${\it update}(t,1) = 1$
for all t, or
${\it update}(t,0) = {\it update}(t,1)$
for all t.
In the second case, we derive a contradiction easily:
where the first and last equalities are given by Equation (19).
For the first case, we need a further subcase distinction. Let s be a state and
$f_s \in 2^S$
the function that returns 1 on s and 0 otherwise. Either
${\it lookup}(\,f_s) = 0$
or
${\it lookup}(\,f_s) = 1$
. If it is 0, then
Here, the second equality comes from applying Equation (21).
The subcase
${\it lookup}(\,f_s) = 1$
is analogous. This completes the proof.
When we replace the slicing object
${\bf 2}$
with
$S\Rightarrow{\bf 2}$
(with the pointwise order), we find that it carries an EM monotone
$\mathsf{S}$
-algebra
$o(k)\triangleq\lambda{s}~.~\pi_1(k~s)(\pi_2(k~s))$
; see also Pitts (Reference Pitts, van Rijsbergen and Birtwistle1991, Example 3.4.2) and Maillard et al. (Reference Maillard, Ahman, Atkey, Martnez, Hritcu, Rivas and Tanter2019, Section 4.4). The corresponding Cartesian lifting of
$\mathsf{S}$
along
$d^{{{\bf Set}},{(S\Rightarrow {\bf 2})}}:{{\bf Set}/_{\!\mathrm{\ell}}(S\Rightarrow {\bf 2})}\rightarrow {\bf Set}$
and the derived wppt satisfies
By using the uncurrying i’ and f’ of i and f, respectively, wppt can be simplified:
$ \mathrm{wp}(f, )i(x)=\lambda{s}~.~i'(\,f'(x,s))$
. The Hoare triple
$( X,i)\{f\}( Y,j)$
is valid iff for all
$x\in X$
and
$s\in S$
, i(x,s) implies
$j(\,f(x,s))$
.
In this setting, the strength cannot be lifted to the slice category. The following counterexample Kura (Reference Kura2022, Example 3.4.11) shows that the conditions of Theorem 29 are not satisfied. Let
$s_1,s_2$
be distinct states,
$x \triangleq \lambda s. (s=s_1) \colon S\Rightarrow{\bf 2} $
and
$t \triangleq \lambda s. \langle (\lambda s'. (s'=s_2)), s_2 \rangle \colon \mathsf{S}(S\Rightarrow{\bf 2})$
. Then,
$x \wedge o(t) = \lambda s. (s=s_1) \not\leq \lambda s. \bot = (o \circ \mathsf{S}(\wedge) \circ \theta^\mathsf{S})(x,t)$
.
Example 40. Finally, we consider the finite probability distribution monad
$\mathsf{D}$
. A finite probability distribution on a set X is a function
$\mu: X\rightarrow[0,1]$
such that
$\mu$
is nonzero at finitely many elements in X, and
$\sum_{i\in X}\mu(i)=1$
. The functor part of the monad
$\mathsf{D}$
is defined by
The unit
$\eta^\mathsf{D}(x)$
is the Dirac distribution at x, which has value 1 at x and 0 everywhere else, and the Kleisli lifting
$f^\#$
for
$f: X\to\mathsf{D} Y$
is given by
$f^\#(\mu)(y)\mathbin{\triangleq} \sum_{x\in X} f(x)(y)\mu(x)$
. Given
$x_1,x_2\in X$
and
$\rho\in(0,1)$
, the convex combination
$(x_1 \oplus_\rho x_2)$
is the probability distribution with value
$\rho$
on
$x_1$
,
$(1-\rho)$
on
$x_2$
and 0 everywhere else.
Theorem 41. There are exactly two EM monotone
$\mathsf{D}$
-algebras over
${\bf 2}$
, given by
Proof. Let
$h: \mathsf{D}2 \to 2$
be a
$\mathsf{D}$
-algebra. Then it must satisfy:
Assume
$h(p)=1$
for some
$p \in (0,1)$
. Then, by the third and second conditions we have, for every
$\alpha \in [0,1]$
,
In other words, for every
$q \in [p, 1]$
,
$f(q) = 1$
.
On the other hand, also by the third and first conditions
With these two results combined, we get that
$f(q) = 1$
for every
$q \in [0,1]$
.
They induce two Cartesian liftings
$\mathsf{D}_{\mathrm{pmay}},\mathsf{D}_{\mathrm{pmust}}$
of
$\mathsf{D}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. The predicate transformers associated to them generalize the may and must correctness of nondeterministic programs to the probabilistic setting.

Here the notation
${\sf Pr}_{y\sim f(x)}[y\in Q]$
denotes the probability of
$y\in Q$
when sampling y from f(x). Explicitly, this is defined as
where
$\mathbf{1}_Q$
is the characteristic function of Q.
We note that Cartesian liftings are rather rare, compared to arbitrary liftings. We look at the case of the powerset monad
$\mathsf{P}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. For each regular cardinal
$\lambda$
,
$\mathsf{P}_{\lambda} ( P \subseteq X) \mathbin{\triangleq} \{ U \subseteq P~|~| U | <\lambda \}$
gives a lifting of the powerset monad
$\mathsf{P}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. On the other hand (a modification of), Example 36 shows that there are only two Cartesian liftings of
$\mathsf{P}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. Example 38 also shows that there is no Cartesian lifting of the nontrivial state monad along
$d^{{{\bf Set}},{{\bf 2}}}$
.
We end this section with a discussion about strengths on Dijkstra structures of the form
$(d^{{{\bf Set}},{{\bf 2}}},\mathsf{T},{\dot {\mathsf{T}}})$
. First, the fibration
$d^{{{\bf Set}},{{\bf 2}}}:{{\bf Set}/_{\!\mathrm{\ell}}{\bf 2}}\rightarrow {\bf Set}$
has finite products
$(1,\dot 1,\times,\mathbin{\dot\times})$
. Second, every monad
$(\mathsf{T},\eta,\mu)$
on Set has a unique strength
$\theta$
given by
see Moggi (Reference Moggi1991). We then obtain the following:
Proposition 42. Every Dijkstra structure
$(d^{{{\bf Set}},{{\bf 2}}},\mathsf{T},{\dot {\mathsf{T}}})$
has a unique strength
$(\theta,\dot\theta)$
.
Proof. From Theorem 29, it suffices to show
$x\wedge o(c)\le o\circ T(\lambda y.x\wedge y)(c)$
for any
$x\in{\bf 2}$
and
$c\in \mathsf{T}{\bf 2}$
. It suffices to check whether this holds for
$x=\bot$
and
$x=\top$
; both cases trivially hold.
6. Dijkstra Structures on
$d^{{{\bf Set}},{[0,\infty]}}$
We next replace the poset
${\bf 2}=\{\bot\le\top\}$
with the poset
$[0,\infty]$
of nonnegative extended reals, with the usual numerical order. It is a completely distributive lattice, and the domain fibration
$d^{{{\bf Set}},{[0,\infty]}}:{{\bf Set}/_{\!\mathrm{\ell}}[0,\infty]}\rightarrow {\bf Set}$
has a rich structure (in fact it is a tripos Pitts Reference Pitts1999, Example 2.2). An object of
${{\bf Set}/_{\!\mathrm{\ell}}[0,\infty]}$
is a function
$i: X\rightarrow[0,\infty]$
.
Example 43. We consider the counting monad
$\mathsf{C}$
over Set, whose functor part is given by
$ \mathsf{C} X\mathbin{\triangleq}\mathbb N\times X$
. This is identical to the writer monad over a single alphabet (
$\mathbb N\cong 1^*$
). Each monotone function
$f:[0,\infty]\rightarrow [0,\infty]$
(bijectively) determines an EM monotone
$\mathsf{C}$
-algebra
${o(f)}(n,x)\triangleq f^{n}(x)$
, and the corresponding Cartesian lifting
$\mathsf{C}_{{o(f)}}$
of
$\mathsf{C}$
along
$d^{{{\bf Set}},{[0,\infty]}}$
is given by
$ \mathsf{C}_{{o(f)}}(i)(n,x)=f^n(i(x)). $
The standard choice of
$f:[0,\infty]\rightarrow[0,\infty]$
is the successor function
$s(x)=x+1$
. In this case, the lifting becomes
$ \mathsf{C}_{{o(s)}}i=\lambda{(n,x)}~.~n+i(x). $
Example 44. We consider Cartesian liftings of the nonempty powerset monad
${\mathsf{P}^+}$
along
$d^{{{\bf Set}},{[0,\infty]}}$
. There are at least two EM monotone
${\mathsf{P}^+}$
-algebras
$\mathrm{sup},\mathrm{inf}:{\mathsf{P}^+}[0,\infty]\rightarrow[0,\infty]$
. They induce two Cartesian liftings:
\begin{align*} {\mathsf{P}^+}_{\mathrm{sup}}(i)&=\lambda{U}~.~\sup_{x\in U}i(x) \qquad\qquad (i: X\rightarrow[0,\infty])\\ {\mathsf{P}^+}_{\mathrm{inf}}(i)&=\lambda{U}~.~\inf_{x\in U}i(x) \qquad\qquad (i: X\rightarrow[0,\infty]) \end{align*}
These Cartesian liftings can be seen as quantitative generalizations of the may and must liftings from Example 36.
Example 45. We can view objects in
${{\bf Set}/_{\!\mathrm{\ell}}[0,\infty]}$
as random variables. The expected value of a random variable
$i: X\rightarrow[0,\infty]$
over a finite probability distribution
$\mu\in \mathsf{D} X$
, denoted by
${E_{x\sim }[\mu]} {i(x)}$
, is computed as
$\mathrm{E}\circ \mathsf{D} i(\mu)$
, where
$\mathrm{E}:\mathsf{D}[0,\infty]\rightarrow[0,\infty]$
is the expected value function on
$[0,\infty]$
. It is easy to check that E is an EM monotone
$\mathsf{D}$
-algebra over
$[0,\infty]$
. Therefore, the expected value is a Cartesian lifting of
$\mathsf{D}$
along
$d^{{{\bf Set}},{[0,\infty]}}$
:
The wppt of the Cartesian Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}},\mathsf{D},\mathsf{D}_{\mathrm{E}})$
computes the weakest pre-expectation (McIver and Morgan Reference McIver and Morgan2005):
We point out that the Cartesian Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}},\mathsf{D},\mathsf{D}_{\mathrm{E}})$
does not have a strength, since the strength for the finite probability distribution monad does not satisfy the conditions of Theorem 29. The strength
$\theta^\mathsf{D}_{X,Y}$
is defined as
\begin{equation*} \theta^\mathsf{D}_{X,Y}(x,\nu)(x',y) = \begin{cases} \nu(y) \qquad &x'=x \\ 0 \qquad &\text{otherwise}. \end{cases} \end{equation*}
The conditions of the Theorem require that for every
$x\in[0,\infty]$
and every
$\nu\in\mathsf{D}([0,\infty])$
,
$\min\!(x,\mathrm{E}(\nu)) \leq \mathrm{E}_{y\sim\nu}[\!\min\!(x,y)]$
. However, we can find a counterexample (see also Kura Reference Kura2022, Example 3.4.10) by setting
$x=1$
and
$\nu$
such that
$\nu(0)=\nu(2)=\frac{1}{2}$
. Then, we have
$\min\!(1,\mathrm{E}(\nu))= 1 \not\leq \frac{1}{2} = \mathrm{E}_{y\sim\nu}[\!\min\!(1,y)]$
.
Example 46. When modeling a programming language with both nondeterministic choice and probabilistic choice, we might want to combine
${\mathsf{P}^+}$
and
$\mathsf{D}$
via a distributive law
$\mathsf{D}\circ {\mathsf{P}^+}\rightarrow {\mathsf{P}^+}\circ \mathsf{D}$
. However, Plotkin showed that there is no such distributive law (Varacca and Winskel Reference Varacca and Winskel2006). To remedy this, Varacca and Winskel introduced the indexed valuation monad (Varacca and Winskel Reference Varacca and Winskel2006), which does have a distributive law with
${\mathsf{P}^+}$
.
In this paper, we employ its finite variant called finite indexed distribution monad (Sato Reference Sato2011). A finite indexed distribution over a set X is a finite multiset of pairs (p,x) where
$p\in(0,1]$
and
$x\in X$
, and moreover, the sum of ps in the multiset is 1. We define
The probabilistic sum of finite indexed distributions is defined as follows (below
$@$
denotes multiset union):
\begin{equation*} [\cdots(p_i,x_i)\cdots]\oplus_p[\cdots(q_j,y_j)\cdots]\mathbin{\triangleq} \left\{\begin{array}{ll} {}[\cdots(q_j,y_j)\cdots] & (p=0) \\ {}[\cdots(p\cdot p_i,x_i)\cdots] @[\cdots((1-p) q_j,y_j)\cdots] & p\in(0,1) \\ {}[\cdots(p_i,x_i)\cdots] & (p=1) \end{array}\right.\end{equation*}
Every finite probability distribution may be regarded as a finite indexed distribution; we write the inclusion map by
$\iota_ X:\mathsf{D}( X)\rightarrow\mathsf{{I}}( X)$
. We can extend
$\mathsf{{I}}$
to a monad on Set called the finite indexed distribution monad. The concept of expectation can also be extended to finite indexed distributions. First, the function
$\mathrm{IE}:\mathsf{{I}}([0,\infty])\rightarrow[0,\infty]$
defined below gives an EM monotone
$\mathsf{{I}}$
-algebra over
$[0,\infty]$
:
We write
${IE_{x\sim }[\nu]} {i(x)}$
to mean
$\mathrm{IE}\circ(\mathsf{{I}}(i)(\nu))$
. We note that
$\mathrm{E}=\mathrm{IE}\circ \iota$
. The corresponding Cartesian lifting of
$\mathsf{{I}}$
along
$d^{{{\bf Set}},{[0,\infty]}}$
, and the wppt within the derived Cartesian Dijkstra structure is
6.1 Dijkstra Structures for Composite Monads
We next visit examples of liftings of composite monads via distributive laws.
Example 47. We have seen all the Cartesian liftings of the Maybe monad
$\mathsf{M}$
(Example 34) and the nonempty powerset monad
${\mathsf{P}^+}$
(Example 36) along
$d^{{{\bf Set}},{{\bf 2}}}$
. We next derive Cartesian liftings of the composite monad
${\mathsf{P}^+}\circ_\beta \mathsf{M}$
via the distributive law
$\beta:\mathsf{M}\circ {\mathsf{P}^+} \rightarrow {\mathsf{P}^+} \circ \mathsf{M}$
given by
$\beta(\!*\!)=\{*\}$
and
$\beta(U)=U$
. The composite monad can model the computational effects of both nondeterministic choice and diverging computations. To give Cartesian liftings of
${\mathsf{P}^+} \circ_\beta \mathsf{M}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
, it suffices to show (17) for all the four combinations of EM monotone
${\mathsf{P}^+}$
- and
$\mathsf{M}$
-algebras. They all satisfy (17).
Theorem 48. There are exactly four Cartesian liftings of
${\mathsf{P}^+} \circ_\beta \mathsf{M}$
along
$d^{{{\bf Set}},{{\bf 2}}}$
. Let us denote these liftings by
${\mathsf{P}^+}_a\circ_\beta \mathsf{M}_b$
, where (a,b) range over the four-point set
$\{\mathrm{may},\mathrm{must}\}\times \{\mathrm{tot},\mathrm{par}\}$
. Each lifting is explicitly described as follows:
\begin{equation*} {\mathsf{P}^+}_a\circ_\beta \mathsf{M}_b(I,X)=\left( {\mathsf{P}^+}(\mathsf{M}(I)), \left\{\begin{array}{ll} \{U~|~U\cap X\neq\emptyset\} & (a=\mathrm{may},b=\mathrm{tot}) \\ \{U~|~U\subseteq X\} & (a=\mathrm{must},a=\mathrm{tot}) \\ \{U~|~U\cap(X+\{*\})\neq\emptyset\} & (a=\mathrm{may},b=\mathrm{par}) \\ \{U~|~U\subseteq X+\{*\}\} & (a=\mathrm{must},b=\mathrm{par}) \end{array}\right. \right)\end{equation*}
Next, we look at examples of composite monads with the counting monad
$\mathsf{C}$
in Example 43. The counting monad is useful for measuring various intensional quantities of program executions. The distributive law of any Set-monad
$\mathsf{T}$
over the counting monad
$\mathsf{C}$
exists and is provided by the unique strength
$\theta_{ X, Y}: X\times \mathsf{T} Y\rightarrow \mathsf{T}( X\times Y)$
of
$\mathsf{T}$
given as (22). Here we discuss giving a Cartesian lifting of
$\mathsf{T}\circ_\theta \mathsf{C}$
.
Theorem 49. Let
$o:\mathsf{T}[0,\infty]\rightarrow[0,\infty]$
be an EM monotone
$\mathsf{T}$
-algebra and
$f:[0,\infty]\rightarrow[0,\infty]$
be a monotone function. Then o and o(f) (the EM monotone
$\mathsf{C}$
-algebra associated to f; see Example 43) satisfy (17) if and only if
$o\circ \mathsf{T} f=f\circ o$
, that is, f is a
$\mathsf{T}$
-algebra endomorphism over o.
Example 50. We consider the instance of Theorem 49 where
$\mathsf{T}$
is the finite probability distribution monad
$\mathsf{D}$
. The composite monad
$\mathsf{D}\circ_\theta \mathsf{C}$
is suitable for modeling probabilistic programs that report cost counting during their executions. We will see this in Section 7. The EM monotone
$\mathsf{D}$
-algebra
$\mathrm{E}:\mathsf{D}[0,\infty]\rightarrow[0,\infty]$
and the successor function
$s:[0,\infty]\rightarrow[0,\infty]$
evidently satisfies the equality condition of Theorem 49:
Therefore, E and o(s) satisfy (17) by Theorem 49. The composite
$\mathsf{D}_{\mathrm{E}}\circ \mathsf{C}_{{o(s)}}$
is a Cartesian lifting of
$\mathsf{D}\circ_\theta\mathsf{C}$
along
$d^{{{\bf Set}},{[0,\infty]}}$
and is computed as
$\mathsf{D}_{\mathrm{E}}\circ \mathsf{C}_{{o(s)}}(i) = \lambda{\mu}~.~{E_{(c,x)\sim \mu}[c+i(x)]}. $
The wppt in the Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}},\mathsf{D}\circ_\theta\mathsf{C},\mathsf{D}_{\mathrm{E}}\circ \mathsf{C}_{{o(s)}})$
is
Example 51. The nonempty powerset monad
$\mathsf{P}^+$
distributes over the finite indexed distribution monad
$\mathsf{{I}}$
. The distributive law
$\gamma:\mathsf{{I}}\circ{\mathsf{P}^+}\rightarrow {\mathsf{P}^+}\circ\mathsf{{I}}$
is given by
It is easy to check that the expectation function
$\mathrm{IE}:\mathsf{{I}}[0,\infty]\rightarrow[0,\infty]$
(Example 46) distributes over
$\mathrm{sup}:{\mathsf{P}^+}[0,\infty]\rightarrow[0,\infty]$
(Example 44). Therefore, the wppt in the Cartesian Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}},{\mathsf{P}^+}\circ_\gamma\mathsf{{I}},{{\mathsf{P}^+}_{\mathrm{sup}}}\circ\mathsf{{I}}_{\mathrm{IE}})$
is
This wppt performs angelic choice. We can also derive the one performing demonic choice by replacing
$\sup$
with
$\inf$
in this argument. Finally, we compose it with the counting monad
$\mathsf{C}$
. This yields the Cartesian Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}},({\mathsf{P}^+}\circ_\gamma\mathsf{{I}})\circ_\theta \mathsf{C}, {\mathsf{P}^+}_{\mathrm{sup}}\circ\mathsf{{I}}_{\mathrm{IE}}\circ \mathsf{C}_{{o(s)}})$
, whose wppt is:
Recently some new approaches to monadic models of nondeterministic and probabilistic branching have been proposed. Moggi et al. construct a monad structure on the composite functor
${\mathsf{P}^+}\circ \mathsf{T}$
for any monad
$\mathsf{T}$
over Set (Moggi et al. Reference Moggi, Taha and Thunberg2020). This is not given by distributive law. Goy and Petrisan employ a weaker notion of distributive law to combine the powerset monad and the probability distribution monad (Goy and Petrisan Reference Goy and Petrisan2020). We leave it to a future work to study wppts for the monads arising from these approaches.
7. Expected Runtime as Weakest Precondition
So far we have been studying abstract wppts formulated in fibered category theory. One might wonder how they are useful for giving a concrete wppt semantics of an actual imperative programming language. An intended use of the fibrational wppt is the following.
Suppose that an imperative programming language L and its monadic denotational semantics
$[\![ \_]\!]$
are given. The semantics
$[\![ \_]\!]$
interprets a program C as a memory transformer
$[\![ C]\!]:M\to \mathsf{T} M$
. To derive a wppt semantics of L, we prepare a Cartesian Dijkstra structure
$(d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C},\mathsf{T},{\dot {\mathsf{T}}})$
, then define the wppt semantics W(C) of a program C as
When the semantics
$[\![ \_]\!]$
consists of the standard monadic constructs, such as the Kleisli composition and algebraic operations, we may derive an inductive definition of W by using the composability of wp and the commutativity of wp with algebraic operations (Proposition 31).
We illustrate this story by deriving Kaminski et al’s expected runtime transformer (ert for short) (Kaminski et al. Reference Kaminski, Katoen, Matheja and Olmedo2016). Kaminski et al. showed that the expected runtime of probabilistic programs can be computed using a predicate transformer-like operator. We apply our theory of Dijkstra structures to derive their ert operator from a fibrational wppt and a monadic denotational semantics with cost counting program transformation (Theorem 52).
The language we consider here is a loop-free fragment of Kaminski et al.’s language (we will discuss languages with loops in Section 9). Fix sets
${{\mathrm{Var}}}, {{\mathrm{Exp}}}, {{\mathrm{Bool}}}$
of variables, probabilistic expressions and probabilistic Boolean expressions, respectively. The syntax of the language is defined by the following BNF grammar (below
$x \in {{\mathrm{Var}}}, e \in {{\mathrm{Exp}}}, b \in {{\mathrm{Bool}}}$
):
The command
$x:\sim e$
samples a value from a probabilistic expression e. The box operator
$\{C\}\Box\{C'\}$
nondeterministically chooses C or C’ and executes the chosen program. The conditional expression
${{\mathrm{if}}}(b)\{C\}\{C'\}$
, samples a bit from a Bernoulli distribution with bias given by an expression b, then runs C if the sample is 1; otherwise runs C’. This conditional expression thus combines both probabilistic choice and deterministic conditionals.
Before introducing the expected runtime transformer, we prepare some interpretations of primitives. We fix a set V of values and let
$M = V^{{{\mathrm{Var}}}}$
be the set of memory configurations. We give interpretations of
$e\in{{\mathrm{Exp}}}$
and
$b\in{{\mathrm{Bool}}}$
by functions
$[\![ e ]\!] : M \rightarrow \mathsf{D} V$
and
$[\![ b ]\!] : M \rightarrow [0, 1]$
, respectively. We also assume that the memory configuration update function
${{\mathrm{upd}}}_x : M \times V \rightarrow M$
is suitably defined for each variable
$x \in {{\mathrm{Var}}}$
. The expected runtime transformer
${{\mathrm{ert}}} : {{\mathrm{Prog}}}\times{\bf Set}(M,[0,\infty])\rightarrow{\bf Set}(M,[0,\infty])$
is inductively defined as follows (below
$i:M\to[0,\infty]$
and
$\rho\in M$
):
\begin{align*} \mathrm{ert}(\!{{\mathrm{empty}}},i)\rho &= i(\rho)\\ \mathrm{ert}({{\mathrm{tick}}},i)\rho &= 1 + i(\rho)\\ \mathrm{ert}(C_1 ;\; C_2,i)\rho &= \mathrm{ert}(C_1, \mathrm{ert}(C_2, i)) \rho\\ \mathrm{ert}(\{ C_1 \} \Box \{C_2 \},i)\rho &= \max\!(\mathrm{ert}(C_1, i) \rho, \mathrm{ert}(C_2, i) \rho)\\ \mathrm{ert}(x : \sim e,i)\rho &= 1 + {E_{v\sim [\![ e]\!]\rho}[i (\!{{\mathrm{upd}}}_x\!(\rho, v))]}\\ \mathrm{ert}({{\mathrm{if}}} (b) \{ C_1 \} \{ C_2 \},i)\rho &= 1 + \mathrm{ert}(C_1, i)\rho \oplus_{[\![ b ]\!] \rho} \mathrm{ert}(C_2, i)\rho\end{align*}
To derive the ert in our framework, we first give a monadic semantics of the language using the composite monad
$\mathsf{T}\triangleq (\mathsf{P}^{+_{}} \circ_{\gamma} \mathsf{{I}}) \circ_{\theta} \mathsf{C}$
in Example 51. We interpret effectful commands and conditional commands using the following generic effects (Section 4.4) t,u,c for counter tick, nondeterministic choice and probabilistic choice, respectively.
\begin{align*} t &\colon 1 \to \mathsf{T} 1 & t(\!*\!) & = \{ [(1, (1, \ast))] \} \\ u &\colon 1 \to \mathsf{T} 2 & u(\!*\!) & = \{ [(1, (0, \top))], [(1, (0, \bot))] \} \\ c &\colon [0, 1] \to \mathsf{T} 2 & c(p) & = \{ [(p, (0, \top)), (1 - p, (0, \bot))] \}\end{align*}
They induce the following algebraic operations:
\begin{align*} \alpha(t)_ X(!_ Y,f) &= \lambda{y\in Y}~.~\{ \mathsf{{I}} (\lambda{x}~.~x+1)(\nu) | \nu \in f(y,*) \} \\ \alpha(u)_ X(!_ Y,\beta(\,f_1,f_2)) &= \lambda{y\in Y}~.~ f_1(y) \cup f_2(y) \\ \alpha(c)_ X(p,\beta(\,f_1,f_2)) &= \lambda{y\in Y}~.~\{ \nu \oplus_{p(y)} \mu | \nu \in f_1(y), \mu \in f_2(y)\}\end{align*}
Using these algebraic operations, we define our denotational semantics:
\begin{align*} [\![ {{\mathrm{\!empty\!}}}]\!] & = \eta^\mathsf{T}_M \\ [\![ {{\mathrm{\!tick\!}}}]\!] & = \alpha(t)_M(!_M,\eta_M^\mathsf{T}\circ r_M)\quad (r_M:M\times 1\to M) \\ [\![ C_1 ;\; C_2]\!] & = [\![ C_2 ]\!] \bullet [\![ C_1 ]\!] \\ [\![ \{ C_1 \} \Box \{ C_2 \}]\!] & =\alpha(u)_M(!_M,\beta([\![ C_1 ]\!], [\![ C_2 ]\!])) \\ [\![ x : \sim e]\!] & = \mathsf{T} (\!{{\mathrm{upd}}}_x\!) \circ \theta_{M, V} \circ \langle {{\mathrm{id}}}_M, \iota_M \circ [\![ e ]\!] \rangle\\ [\![ {{\mathrm{if}}} (b) \{ C_1 \} \{ C_2 \}]\!] &= \alpha(c)_M([\![ b]\!], \beta([\![ C_1 ]\!], [\![ C_2 ]\!]))\end{align*}
Here
$\iota_M:\mathsf{D} M\to\mathsf{{I}} M$
is the inclusion (Example 46).
Recall that in Example 51, we obtained a Cartesian lifting
$\dot {\mathsf{T}}\triangleq{\mathsf{P}^+}_{\mathrm{sup}} \circ \mathsf{{I}}_{\mathrm{IE}} \circ \mathsf{C}_{{o(s)}}$
of
$\mathsf{T}$
along
$d^{{{\bf Set}},{[0,\infty]}}$
. In the Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}}, \mathsf{T},\dot {\mathsf{T}})$
,
${{\mathrm{wp}}} ([\![ C ]\!], i)$
satisfies
\begin{align*} \mathrm{wp}([\![ {{\mathrm{\!empty\!}}}]\!],i)\rho & = i(\rho)\\ \mathrm{wp}([\![ {{\mathrm{\!tick\!}}}]\!],i)\rho & = 1 + i(\rho)\\ \mathrm{wp}([\![ C_1 ;\; C_2]\!],i)\rho & = {{\mathrm{wp\!}}}([\![ C_1 ]\!], {{\mathrm{wp}}}\!([\![ C_2 ]\!], i)) \rho\\ \mathrm{wp}([\![ \{ C_1 \} \Box \{ C_2 \}]\!],i)\rho & = \max\!(\!{{\mathrm{wp}}}\!([\![ C_1 ]\!], i) \rho, {{\mathrm{wp}}} ([\![ C_2 ]\!], i) \rho)\\ \mathrm{wp}([\![ x : \sim e]\!],i)\rho & = {E_{v\sim [\![ e ]\!] \rho}[i (\!{{\mathrm{upd}}}_x(\rho, v))]}\\ \mathrm{wp}([\![ {{\mathrm{if}}} (b) \{ C_1 \} \{ C_2 \}]\!],i)\rho & = {{\mathrm{wp}}}\!([\![ C_1 ]\!], i) \rho \oplus_{[\![ b ]\!] \rho} {{\mathrm{wp}}}\!([\![ C_2 ]\!], i) \rho\end{align*}
This is already very close to Kaminski et al’s expected runtime transformer. The major difference between wp and ert is that the latter adds 1 to reflect the time consumption by probabilistic assignments and probabilistic conditionals. This difference can be resolved by an accounting transformation A defined below. It inserts a tick command before time-consuming instructions:
Theorem 52. Under the Cartesian Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}}, \mathsf{T}, \dot {\mathsf{T}})$
, we have
8. Dijkstra Structures on
$d^{{\bf Set},[0,\infty]^n}$
As our final example, we consider an example of predicates that take values over
$[0,\infty]^n$
, based on Kura et al. (Reference Kura, Urabe and Hasuo2019). They study the problem of computing bounds on tail probabilities to answer questions of the form “what is the probability that a program takes more than n steps before terminating?”. Their technique is based on using concentration bounds, for which one needs to compute higher moments of the form
$E[T^n]$
, where T is a random variable expressing the runtime of the execution of a program. To compute these, they carry a vector
$(E[T], E[T^2],\dots, E[T^n])$
containing the current estimations for the higher order moments. When the program takes a step, this vector can be used to compute the updated
$(E[T+1], E[(T+1)^2], \dots, E[(T+1)^n])$
. For instance, for the second moment, we have
$E[(T+1)^2] = E[T^2] + 2E[T] + 1$
.
We derive this computation as a wppt in a suitable Cartesian Dijkstra structure on a domain fibration (unlike Kura et al. Reference Kura, Urabe and Hasuo2019 here we do not consider the nondeterministic computations). Consider again the composite
$\mathsf{D}\circ_\theta \mathsf{C}$
of the counter monad and the finite probability distribution monad considered in Example 50. We first introduce EM monotone algebras for
$\mathsf{C}$
and
$\mathsf{D}$
as follows:
We define an algebraic operation
$\mathrm{tick}_n \colon [0,\infty]^n \rightarrow [0,\infty]^n$
that simulates letting one unit of time pass: Here the inputs are taken to be the moments of T, where
\begin{align*} \mathrm{tick}_n (r_1,\dots,r_n) &= (\mathrm{tick}_n^1(r_1,\dots,r_n), \dots, \mathrm{tick}_n^n(r_1,\dots,r_n)) \\ \text{where}~ \mathrm{tick}_n^k (r_1,\dots,r_n) &= 1 + \sum_{i=1}^k \binom{k}{i} r_i \qquad\qquad{(1 \leq k \leq n)} \end{align*}
$r_i$
represents
$E[T^i]$
, and
$\mathrm{tick}_n^i$
computes
$E[(T+1)^i]$
from them. This coincides with the elapse function defined in Kura et al. (Reference Kura, Urabe and Hasuo2019). This operation induces an EM monotone
$\mathsf{C}$
-algebra
${o(\mathrm{tick}_n)}\colon \mathsf{C}[0,\infty]^n \rightarrow [0,\infty]^n$
for each n.
For
$\mathsf{D}$
we take the product of n-fold copies of the expected value
$\mathrm{E}:\mathsf{D}[0,\infty]\rightarrow[0,\infty]$
which is an EM monotone
$\mathsf{D}$
-algebra as shown in Example 45. This product is itself an EM monotone
$\mathsf{D}$
-algebra
$\mathrm{E}^n \colon \mathsf{D}[0,\infty]^n \rightarrow [0,\infty]^n$
.
It follows from affinity of
$\mathrm{tick}_n$
and linearity of the expected value that
$\mathrm{tick}_n$
is a
$\mathsf{D}$
-algebra endomorphism over
$\mathrm{E}^n$
. From Theorem 49, we obtain the Cartesian lifting
$\mathsf{D}_{\mathrm{E}^n}\circ \mathsf{C}_{{o(\mathrm{tick}_n)}}$
of
$\mathsf{D}\circ_\theta\mathsf{C}$
along
$d^{{{\bf Set}},{[0,\infty]^n}}:{{\bf Set}/_{\!\mathrm{\ell}}[0,\infty]^n}\rightarrow {\bf Set}$
. In the Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]^n}},\mathsf{D}\circ_\theta\mathsf{C},\mathsf{D}_{\mathrm{E}^n}\circ \mathsf{C}_{{o(\mathrm{tick}_n)}})$
, the wppt satisfies the definition below:
\begin{align*} \mathrm{wp}(\,f,p)(j) & \mathbin{\triangleq} (\mathrm{wp}_1(\,f,p)(j), \dots , \mathrm{wp}_n(\,f,p)(j)), \qquad(\,f: X\rightarrow \mathsf{D}\circ_\theta\mathsf{C}( Y),p: Y\rightarrow[0,\infty]^n) \\ \text{where}&{}\quad\mathrm{wp}_k(\,f,p)(j) \mathbin{\triangleq} \mathrm{E}_{(c,i)\sim f(j)}\left[ c^k + \sum_{l=1}^k \binom{k}{l} c^{k-l} p_l(i) \right]\end{align*}
Here f represents an effectful computation, and p is a function that maps final states of f to the vector of moments for the runtime of some continuation of f. The wp operator then computes the vector of moments for the runtime of f followed by its continuation. In particular, this coincides with the
$F_n$
operator from Kura et al. (Reference Kura, Urabe and Hasuo2019).
9. Continuity and Fixed Points
For a
${\mathbb K}$
-Dijkstra structure
$(p,\mathsf{T},{\dot {\mathsf{T}}})$
, its associated wppt
$\mathrm{wp}(\,f,\_)$
is a monotone function belonging to
$\mathbb K$
(Definition 5-(2)); this means that it obeys the constraint imposed by the subcategory
$\mathbb K$
of Pos. For example, the wppt of an Dijkstra structure
${{\bf \omega CPO}}$
is continuous on its second argument. For practical applications, it is also interesting to consider continuity of wppts on their first argument. This is useful for defining the wppt of an unbounded loop program in closed form via a fixpoint equation, such as it is done in other calculi (Kaminski et al. Reference Kaminski, Katoen, Matheja and Olmedo2016; McIver and Morgan Reference McIver and Morgan2005). In this section we introduce the concept of enrichment on Kleisli categories and discuss the continuity of wppts on their first argument. We then show that under a certain condition, the wppt of a while loop program can be computed by the least fixpoint of the wppt of the loop body.
Throughout this section, we fix a category
$\mathbb{C}$
and a monad
$(\mathsf{T},\eta,\mu)$
on
$\mathbb{C}$
. Recall that an
$\omega$
-complete partial order (
$\omega$
CPO) is a CPO
$(X, \sqsubseteq_X)$
in which every
$\omega$
-chain
$x_0 \sqsubseteq_X x_1 \sqsubseteq_X \dots$
has a least upper bound
$\sqcup_{i\in\omega} x_i$
. We define
${\bf \omega CPO}$
to be the category of
$\omega$
CPO s (which may not have the least element) and continuous functions (i.e. functions that preserve least upper bounds) between them.
9.1 Continuity of Weakest Precondition Predicate Transformers on Morphisms
To discuss the continuity of wppts in their first argument, we first introduce the concept of enrichment of Kleisli categories by the Cartesian category
$({\bf \omega CPO},1,\times)$
.
Proposition 53. Let
$\{\sqsubseteq_{ X, Y}\}_{ X, Y\in\mathbb{C}}$
be a family such that each
$\sqsubseteq_{ X, Y}$
is an
$\omega$
CPO on the homset
$\mathbb{C}( X,\mathsf{T} Y)$
. Then the following are equivalent (below
$f_n,g_n$
are
$\omega$
-chains of morphisms of appropriate type):
-
(1) The Kleisli composition
$(\!\bullet\!)$
is monotone and continuous in the following sense:
\begin{equation*} (\!\bullet\!)\in {\bf \omega CPO}((\mathbb{C}(Y,\mathsf{T} Z),\mathbin{\sqsubseteq_{Y,Z}})\times(\mathbb{C}(X,\mathsf{T} Y),\mathbin{\sqsubseteq_{X,Y}}),(\mathbb{C}(X,\mathsf{T} Z),\mathbin{\sqsubseteq_{X,Z}})). \end{equation*}
-
(2) The Kleisli composition
$(\!\bullet\!)$
is monotone and continuous in each argument. -
(3) Precomposition
$\_\circ g$
, the Kleisli lifting operation
$(\!-\!)^\#$
, and the postcomposition
$f\bullet\_$
are all monotone and continuous.
The proof of this proposition is easy and omitted.
Definition 54. An
${\bf \omega CPO}$
-enrichment of the Kleisli category
$\mathbb{C}_\mathsf{T}$
is a family
$\{\sqsubseteq_{ X, Y}\}_{ X, Y\in\mathbb{C}}$
such that each
$\sqsubseteq_{ X, Y}$
is an
$\omega$
CPO on the homset
$\mathbb{C}( X,\mathsf{T} Y)$
, and moreover one of the equivalent conditions in Proposition 53 hold.
We now seek for the condition for wppts to be continuous in their first argument.
Proposition 55. Let
$\{\sqsubseteq_{ X, Y}\}_{ X, Y\in\mathbb{C}}$
be an
${\bf \omega CPO}$
-enrichment of
$\mathbb{C}_\mathsf{T}$
,
$(\Omega,\le\!)$
be an ordered object in
$\mathbb{C}$
belonging to
${\bf \omega CPO}$
, and
$o:\mathsf{T}\Omega\to\Omega$
be an EM monotone algebra. Consider the wppt wp of the Dijkstra structure
$(d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C},\mathsf{T},\mathsf{T}_o)$
. Then the following are equivalent:
-
(1)
$o \circ \_\in{\bf \omega CPO}((\mathbb{C}( X,\mathsf{T}\Omega),\mathbin{\sqsubseteq_{ X,\Omega}}),(\mathbb{C}( X,\Omega),\le_ X\!))$
for every
$ X\in\mathbb{C}$
. -
(2)
$\mathrm{wp}(\_,i)\in{\bf \omega CPO}((\mathbb{C}( X,\mathsf{T} Y),\mathbin{\sqsubseteq_{ X, Y}}),(\mathbb{C}( X,\Omega),\le_ X\!))$
for every
$ X, Y\in\mathbb{C}$
and
$i: Y\to\Omega$
.
Proof. (1)
$\implies$
(2) Since
$\{\sqsubseteq_{ X, Y}\}_{ X, Y\in\mathbb{C}}$
is an
${\bf \omega CPO}$
-enrichment, the postcomposition
$T i\circ\_=(\eta\circ i)^\#\circ -$
is monotone and continuous by Proposition 53. Thus, we obtain the following diagram in
${\bf \omega CPO}$
, and the composition coincides with
$\mathrm{wp}(\_,i)=o\circ Ti\circ \_$
. This concludes the monotonicity and continuity of
$\mathrm{wp}(\_,i)$
.
(2)
$\implies$
(1) Immediate from
$o\circ \_=\mathrm{wp}(\_,{\rm id}_\Omega)$
.
Definition 56. Let
$\{\sqsubseteq_{ X, Y}\}_{ X, Y\in\mathbb{C}}$
be an
${\bf \omega CPO}$
-enrichment of
$\mathbb{C}_\mathsf{T}$
,
$(\Omega,\le\!)$
be an ordered object in
$\mathbb{C}$
belonging to
${\bf \omega CPO}$
, and
$o:\mathsf{T}\Omega\to\Omega$
be an EM monotone algebra. We say that o is compatible with the
${\bf \omega CPO}$
-enrichment if one of the equivalent conditions in Proposition 55 holds.
In any Kleisli category
$\mathbb{C}_\mathsf{T}$
with an
${\bf \omega CPO}$
-enrichment, each free algebra is monotone, belonging to
${\bf \omega CPO}$
, and is compatible with the enrichment.
Proposition 57. Let
$\{\sqsubseteq_{ X, Y}\}_{ X, Y\in\mathbb{C}}$
be an
${\bf \omega CPO}$
-enrichment on
$\mathbb{C}_\mathsf{T}$
and
$\Omega\in\mathbb{C}$
be an object. Then
$(\mathsf{T}\Omega,\mathbin{\sqsubseteq_{\_,\Omega}})$
is an ordered object in
$\mathbb{C}$
belonging to
${\bf \omega CPO}$
, and
$\mu_\Omega:\mathsf{T}\mathsf{T}\Omega\rightarrow\mathsf{T}\Omega$
is an EM monotone
$\mathsf{T}$
-algebra belonging to
${\bf \omega CPO}$
that is compatible with the
${\bf \omega CPO}$
-enrichment.
Example 58. In the category Set with a monad
$\mathsf{T}$
, it is sometimes enough to equip
$\mathsf{T} Y$
with an
$\omega$
CPO
$\sqsubseteq_ Y$
for every set Y, then extend it to an
$\omega$
CPO on the homset
${\bf Set}( X, \mathsf{T} Y)$
by the pointwise order. This is the case of:
The maybe monad
$\mathsf{M}$
in Example 34, where the
$\omega$
CPO
$\sqsubseteq_ Y$
on
$\mathsf{M} Y$
is the flat order making
$\{*\}$
the least element. We then extend this order to the pointwise order
$\mathbin{\sqsubseteq_{ X, Y}}$
on
${\bf Set}( X,\mathsf{M} Y)$
. This is an
${\bf \omega CPO}$
-enrichment on
${\bf Set}_\mathsf{M}$
. Among EM monotone
$\mathsf{M}$
-algebras
$\mathrm{tot},\mathrm{par}$
in Example 34, only tot belongs to
${\bf \omega CPO}$
and is compatible with the
${\bf \omega CPO}$
-enrichment.The nonempty powerset monad
${\mathsf{P}^+} X\mathbin{\triangleq}\{U\subseteq X~|~U\neq\emptyset\}$
in Example 36, where the
$\omega$
CPO
$\sqsubseteq_ Y$
on
${\mathsf{P}^+} Y$
is given by set inclusion. We then extend this order to the pointwise order
$\mathbin{\sqsubseteq_{ X, Y}}$
on
${\bf Set}( X,{\mathsf{P}^+} Y)$
. This is an
${\bf \omega CPO}$
-enrichment on
${\bf Set}_{\mathsf{P}^+}$
. Among EM monotone
${\mathsf{P}^+}$
-algebras
$\mathrm{may},\mathrm{must}$
in Example 36, only may belongs to
${\bf \omega CPO}$
and is compatible with the
${\bf \omega CPO}$
-enrichment.The subdistribution monad
$\mathsf{{SD}}$
, which assigns to
$ X\in{\bf Set}$
the set of probability subdistributions over X, i.e., functions
$\nu \colon X\to[0,1]$
such that
$\nu$
is nonzero at countably many points and
$\sum_{x\in X} \nu(x) \leq 1$
. This is a variant of the finite probability distribution monad
$\mathsf{D}$
in Example 40. Given
$\mu_1,\mu_2\in\mathsf{{SD}}( X)$
, we define the order
$\mu_1\sqsubseteq\mu_2$
by
$\mu_1(x)\leq\mu_2(x)$
for every
$x\in X$
. We extend this order to the pointwise order
$\mathbin{\sqsubseteq_{ X, Y}}$
on
${\bf Set}( X,\mathsf{{SD}} Y)$
. This is an
${\bf \omega CPO}$
-enrichment on
$\mathsf{{SD}}$
. The expectation function
$\mathrm{E}:\mathsf{{SD}}[0,\infty]\rightarrow [0,\infty]$
given by
$\mathrm{E}(\mu)=\sum_{x\in X} x\mu(x)$
is the EM monotone
$\mathsf{{SD}}$
-algebra belonging to
${\bf \omega CPO}$
that is compatible with the
${\bf \omega CPO}$
-enrichment.
We end this section by updating Theorem 32 with an
${\bf \omega CPO}$
enrichment. Let
$(1,\times)$
be finite products on
$\mathbb{C}$
and
$\theta$
be a strength for
$\mathsf{T}$
,
$\{\mathbin{\sqsubseteq_{ X, Y}}\}_{ X, Y\in\mathbb{C}}$
be an
${\bf \omega CPO}$
-enrichment on
$\mathbb{C}_\mathsf{T}$
,
$(\Omega,\le\!)$
be an ordered object in
$\mathbb{C}$
belonging to
${\bf \omega CPO}$
, and
$o:\mathsf{T}\Omega\to\Omega$
be an EM monotone
$\mathsf{T}$
-algebra belonging to
${\bf \omega CPO}$
and compatible with the
${\bf \omega CPO}$
-enrichment. Then for any generic effect
$g:A\to\mathsf{T} B$
and
$ X, Y\in\mathbb{C}$
, we obtain the following commutative diagram in
${\bf \omega CPO}$
:

Theorem 32 guarantees the commutativity of the diagram. It remains to verify that morphisms in the above diagram are inhabitants of
${\bf \omega CPO}$
:
-
(1) From Proposition 57,
$(\mathsf{T} X,\mathbin{\sqsubseteq_{\_, X}})$
is an ordered object in
$\mathbb{C}$
belonging to
${\bf \omega CPO}$
, and
$\mu_ X$
is an EM monotone
$\mathsf{T}$
-algebra belonging to
${\bf \omega CPO}$
. Therefore, the operation
$\alpha(g)_ X(a,\_)$
belongs to
${\bf \omega CPO}$
by Proposition 31. -
(2) Since
$(\Omega,\le\!)$
and
$o:\mathsf{T}\Omega\to\Omega$
belongs to
${\bf \omega CPO}$
,
${{\mathrm{op}}}\!(o,g)(a,\_)$
belongs to
${\bf \omega CPO}$
by Proposition 31. -
(3) Since o is compatible with the
${\bf \omega CPO}$
-enrichment,
$\mathrm{wp}(\_,i)$
belongs to
${\bf \omega CPO}$
by Proposition 55.
9.2 Application: Semantics of While Loops
We use the theory developed in the previous section to study the weakest precondition of while loops in imperative languages. This is carried out in the Dijkstra structure
$(d^{{\mathbb{C}},{\Omega}},\mathsf{T},\mathsf{T}_o)$
specified by the following data:
$\mathbb{C}$
is a category with finite products
$(1,\times)$
and finite coproducts
$(0,+)$
, with a distributive law (Section 4.4).
$(\mathsf{T},\eta,\mu,\theta)$
is a strong monad on
$\mathbb{C}$
, and
$\{\sqsubseteq_{ X, Y}\}_{ X, Y\in\mathbb{C}}$
is an
${\bf \omega CPO}$
-enrichment on
$\mathbb{C}_\mathsf{T}$
. We assume that each order
$\sqsubseteq_{ X, Y}$
admits the least element
$\bot_{ X, Y}$
, and the cotupling
$[-,-]$
of the coproduct is an isomorphism in
${\bf \omega CPO}$
: (23)
\begin{equation} [-,-]: (\mathbb{C}( X,\mathsf{T} Z),\mathbin{\sqsubseteq_{ X, Z}})\times (\mathbb{C}( Y,\mathsf{T} Z),\mathbin{\sqsubseteq_{ Y, Z}})\cong (\mathbb{C}( X+ Y,\mathsf{T} Z),\mathbin{\sqsubseteq_{ X+ Y, Z}}). \end{equation}
$(\Omega,\le\!)$
is an ordered object in
$\mathbb{C}$
belonging to
${\bf \omega CPO}$
. We assume that each order
$\le_ X$
admits the least element
$\bot_ X$
, and the cotupling of the coproduct is an isomorphism in
${\bf \omega CPO}$
: (24)
\begin{equation} [-,-]: (\mathbb{C}( X,\Omega),\le_ X\!)\times (\mathbb{C}( Y,\Omega),\le_ Y\!)\cong (\mathbb{C}( X+ Y,\Omega),\le_{ X+ Y}\!). \end{equation}
$o:\mathsf{T}\Omega\to\Omega$
is an EM monotone
$\mathsf{T}$
-algebra belonging to
${\bf \omega CPO}$
that is compatible with the
${\bf \omega CPO}$
-enrichment. Moreover,
$o\circ \mathsf{T} i\circ\bot_{ X, Y}=\bot_{ X}$
holds for any object
$ X, Y\in\mathbb{C}$
and morphism
$i: Y\to\Omega$
. This guarantees that the wppt wp of the Dijkstra structure
$(d^{{{\bf Set}},{\Omega}},\mathsf{T},\mathsf{T}_o)$
is not only continuous but also strict in its first argument.
We assume that a program C is interpreted as a memory transformer
$[\![ C]\!]\colon M \to \mathsf{T} M$
, where M is the object representing the collection of memory configurations. We also assume that a Boolean expression b is interpreted as a function
$[\![ b]\!] \colon M \to 2$
, where 2 is the coproduct
$1+1$
. We represent true and false by the left and right injections, respectively. To interpret a while loop of an imperative language as a morphism
$[\![ {{\mathrm{\!while}}} (b) \{ C \}]\!]\colon M\to\mathsf{T} M$
, we first define the following family of partial iterations:
\begin{align*} W_{b,C,0} &\triangleq \bot_{M,M} \\ W_{b,C,n+1} &\triangleq \alpha(\eta_2)_M([\![ b]\!], \beta(W_{b,C,n}\bullet[\![ C]\!], \eta_M))\\ &=[(W_{b,C,n}\bullet[\![ C]\!])\circ r_M,\eta_M\circ r_M]\circ \mathrm{dist}_{M,1,1}\circ\langle{\rm id}_M,[\![ b]\!]\rangle\end{align*}
where
$W_{b,C,n}$
executes n iterations of the loop and returns the bottom element in the traces that have not terminated. For the definition of
$\beta$
, see (18). The right-hand side of
$W_{b,C,n+1}$
is the denotation of the conditional command
${{\mathrm{if}}}(b)\{C;W_{b,C,n}\}$
. We can see that
$W_{b,C,n} = \Phi_{b,C}^n(\bot_{M,M})$
where
$\Phi_{b,C} \colon \mathbb{C}(M,\mathsf{T} M) \to \mathbb{C}(M,\mathsf{T} M)$
is an operator defined as
It is a continuous function with respect to the
$\omega$
CPO given by the enrichment:
Lemma 59.
$\Phi_{b,C}\in{\bf \omega CPO}((\mathbb{C}(M,\mathsf{T} M),\mathbin{\sqsubseteq_{M,M}}),(\mathbb{C}(M,\mathsf{T} M),\mathbin{\sqsubseteq_{M,M}}))$
.
Proof. This is immediate because
$\alpha(\eta_2)_M([\![ b]\!],\_)$
is continuous by Proposition 31, and the mapping
$f\mapsto \beta(\,f\bullet[\![ C]\!],\eta_M)=[(\,f\bullet[\![ C]\!])\circ r,\eta_M\circ r]\circ\mathrm{dist}$
is continuous from the property of
${\bf \omega CPO}$
-enrichment and the assumption (23) on cotupling.
We then take the least fixpoint of
$\Phi_{b,C}$
and employ it as the denotation of the while program
${{\mathrm{while}}}(b)\{C\}$
:
We want to compute the weakest precondition
$\mathrm{wp}([\![ {{\mathrm{while}}}(b)\{ C \}]\!],j)$
of the while loop at a morphism
$j:M\to\Omega$
. By Corollary 33, for all n:
We thus let
$\Psi_{b,C,j}\colon \mathbb{C}(M,\Omega)\to\mathbb{C}(M,\Omega)$
be another operator
This operation is also continuous:
Lemma 60. For any morphism
$j: \to M$
in
$\Omega$
${\mathbb{C}}$
, we have
Proof. Let
$j: \to M$
be a morphism in
$\Omega$
${\mathbb{C}}$
. Notice that
$\Psi_{b,C,j}$
can be factored as
Then
${{\mathrm{op}}}\!(o,\eta_2)([\![ b]\!],\_)$
and
$\mathrm{wp}([\![ C]\!],\_)$
are continuous because o belongs to
${\bf \omega CPO}$
by Proposition 31. Also,
$\beta(\_,j)=[\_\circ r,j\circ r]\circ\mathrm{dist}$
is continuous because o is an ordered object and cotupling is continuous by (24).
Proposition 61. For any morphism
$j: \to M$
in
$\Omega$
${\mathbb{C}}$
, we have the following commutative diagram in
${\bf \omega CPO}$
:

Proof. Since the EM monotone
$\mathsf{T}$
-algebra o is compatible with the
${\bf \omega CPO}$
-enrichment,
$\mathrm{wp}(\_,j)$
belongs to
${\bf \omega CPO}$
by Proposition 55. We next show the commutativity. Let
$f:M\to \mathsf{T} M$
and
$j:M\to\Omega$
be morphisms in
$\mathbb{C}$
. We have
\begin{align*}\mathrm{wp}(\Phi_{b,C}(\,f),j) &= \mathrm{wp}(\alpha(\eta_2)_M([\![ b]\!],\beta(\,f \bullet [\![ C]\!],\eta_M)), j) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{(definition)} \\ &= {{\mathrm{op}}}\!(o,\eta_2)([\![ b]\!],\beta(\!{{\mathrm{wp}}}\!([\![ C]\!],{{\mathrm{wp}}}\!(\,f,j)), j)) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{ (Corollary}\ \text{33)} \\ &= \Psi_{b,C,j}(\mathrm{wp}(\,f,j)). \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{(definition)}\end{align*}
Theorem 62. For any morphism
$j: \to M$
in
$\Omega$
${\mathbb{C}}$
,
$\Phi_{b,C}$
and
$\Psi_{b,C,j}$
defined as above satisfy
Proof. From the strictness assumption and continuity of
$\mathrm{wp}(\_,j)$
, plus Proposition 61 and Scott induction, we conclude the equation.
10. Cartesian Dijkstra Structures Arising from Change-of-Base
In Section 3.3, we have seen the change-of-base construction of Dijkstra structures. In this section, we present some examples of this construction to derive Cartesian Dijkstra structures over relational fibrations.
We first present an example of the change-of-base to obtain fibrations whose total category contains binary relations as objects (Bonchi et al. Reference Bonchi, König and Petrisan2018; Jacobs Reference Jacobs1999).
Example 63. Let
$(\mathbb{C},{\bf I},\otimes)$
be a monoidal category and
$(\Omega,\le\!)$
be an ordered object in
$\mathbb{C}$
. We take the change-of-base of
$d^{{\mathbb{C}},{\Omega}}:{\mathbb{C}/_{\!\mathrm{\ell}}\Omega}\rightarrow \mathbb{C}$
along the tensor product functor
$(\!\otimes\!):\mathbb{C}^2\rightarrow\mathbb{C}$
. We write the resulting fibration
$r^{{\mathbb{C}},{\Omega}}:{\bf BRel}(\mathbb{C},\Omega)\rightarrow \mathbb{C}^2$
.

The concrete description of
${\bf BRel}(\mathbb{C},\Omega)$
is the following: objects are triples
$( X, Y, i : X \otimes Y \rightarrow \Omega)$
of two objects and a morphism in
$\mathbb{C}$
, and a morphism from (X, Y, i) to (X’, Y’, i’) is a pair of
$\mathbb{C}$
-morphisms
$f : X \rightarrow X'$
and
$g : Y \rightarrow Y'$
such that
$i \le_{ X \otimes Y} i' \circ (\,f \otimes g)$
. Intuitively,
${\bf BRel}(\mathbb{C},\Omega)$
is the category of
$\Omega$
-valued binary relations between
$\mathbb{C}$
-objects. In the fibration
$r^{{\mathbb{C}},{\Omega}}:{\bf BRel}(\mathbb{C},\Omega)\rightarrow \mathbb{C}^2$
, the pullback is given by
$(\,f, g)^{*} ( X', Y', i') = i' \circ (\,f \otimes g)$
. Example 8 is an instance of this construction where
$\mathbb{C}={\bf Set}$
and
$\Omega={\bf 2}$
and the tensor product functor
$(\!\otimes\!)$
is the binary product functor
$(\!\times\!)$
.
Example 64. Let
$(\mathbb{C},{\bf I},\otimes)$
be a monoidal category and
$(\mathsf{T},\eta,\mu)$
be a monad on
$\mathbb{C}$
. Then
$(\otimes,m)$
is a monad opfunctor from
$\mathsf{T}^2$
(the product monad on
$\mathbb{C}^2$
) to
$\mathsf{T}$
if and only if
$m_{ X, Y}:\mathsf{T} X\otimes \mathsf{T} Y\rightarrow \mathsf{T}( X\otimes Y)$
is a natural transformation satisfying

This is exactly the tensor product part of the data to make
$\mathsf{T}$
a monoidal functor.
Specially, for any commutative monad
$(\mathsf{T},\eta,\mu,\theta_{ X, Y})$
on a symmetric monoidal category
$(\mathbb{C},{\bf I},\otimes)$
, put
$\theta'_{ X, Y}$
the symmetric version of the strength
$\theta$
. Then the following double strength Jacobs (Reference Jacobs1994, Definition 3.4) satisfies (25).
This is shown in Theorem 2.3 in Kock (Reference Kock1970). Therefore
$((\!\otimes\!),\mathrm{dst}^{\mathsf{T}})$
is a monad opfunctor from
$\mathsf{T}^2$
to
$\mathsf{T}$
.
Example 65. The nonempty powerset monad
${\mathsf{P}^+}$
is commutative over the Cartesian category
$({\bf Set},1,\times)$
. Its double strength
$\mathrm{dst}^{{\mathsf{P}^+}}_{ X, Y}:{\mathsf{P}^+} X\times{\mathsf{P}^+} Y\rightarrow {\mathsf{P}^+}( X\times Y)$
satisfies
From Example 64, the pair
$((\!\times\!),\mathrm{dst}^{{\mathsf{P}^+}})$
becomes a monad opfunctor from
$({\mathsf{P}^+})^2$
to
${\mathsf{P}^+}$
.
We use this monad opfunctor to take the change-of-base of two Cartesian Dijkstra structures
$(d^{{{\bf Set}},{{\bf 2}}},{\mathsf{P}^+},{\mathsf{P}^+}_\mathrm{may})$
and
$(d^{{{\bf Set}},{{\bf 2}}},{\mathsf{P}^+},{\mathsf{P}^+}_\mathrm{must})$
in Example 36. The resulting Cartesian Dijkstra structures are denoted by
$ (r^{{{\bf Set}},{{\bf 2}}},({\mathsf{P}^+})^2,\mathsf{T}_\mathrm{may})$
and
$(r^{{{\bf Set}},{{\bf 2}}},({\mathsf{P}^+})^2,\mathsf{T}_\mathrm{must})$
, respectively. The behavior of the liftings
$\mathsf{T}_\mathrm{may},\mathsf{T}_\mathrm{must}$
is described as follows. We first represent each object in
${\bf BRel}({\bf Set},{\bf 2})$
by a triple of sets (X, Y, R) such that
$R \subseteq X \times Y$
. Then liftings
$\mathsf{T}_\mathrm{may},\mathsf{T}_\mathrm{must}$
act on
${\bf BRel}({\bf Set},{\bf 2})$
-objects as follows:
Example 66. The finite probability distribution monad
$\mathsf{D}$
is also commutative over the Cartesian category
$({\bf Set},1,\times)$
; its double strength
$\mathrm{dst}^{\mathsf{D}}_{ X, Y}:\mathsf{D} X\times\mathsf{D} Y\rightarrow\mathsf{D}( X\times Y)$
takes the product of two probability distributions:
From Example 64, the pair
$((\!\times\!),\mathrm{dst}^{\mathsf{D}})$
becomes a monad opfunctor from
$\mathsf{D}^2$
to
$\mathsf{D}$
.
We use this monad opfunctor to take the change-of-base of the Cartesian Dijkstra structure
$(d^{{{\bf Set}},{[0,\infty]}},\mathsf{D},\mathsf{D}_\mathrm{E})$
in Example 45. The resulting Cartesian Dijkstra structure
$(r^{{{\bf Set}},{[0,\infty]}},\mathsf{D}^2,\mathsf{T}_\mathrm{E})$
has the lifting whose object part behaves as
11. Related Work
One of the earliest studies on a logic for a monadic programming language is Pitts’ evaluation logic (Pitts Reference Pitts, van Rijsbergen and Birtwistle1991). The logic has an evaluation modality
$[x\Leftarrow E]\phi(x)$
, internalizing the wppt in the predicate logic. The semantics of the evaluation modality is given by a T-modality
$\Box_{X,Y}$
Pitts (Reference Pitts, van Rijsbergen and Birtwistle1991), Definition 3.3.1, which is an extension of monad lifting with an extra parameter, but axiomatized differently from (Cartesian) monad liftings. Later, Moggi gave a semantics of evaluation logic in the framework of dominance (Moggi Reference Moggi1995). Some examples of T-modalities are also given in Pitts (Reference Pitts, van Rijsbergen and Birtwistle1991), Moggi (Reference Moggi1995), overlapping with examples in Section 5. A precise relationship between T-modalities and Cartesian liftings is yet to be studied. We currently know that in a Dijkstra structure
$(p,\mathsf{T},{\dot {\mathsf{T}}})$
with a strength
$\theta$
for
$\mathsf{T}$
, the operator
$\Box_{X,Y}(P)\mathbin{\triangleq}\theta_{X,Y}^*{\dot {\mathsf{T}}}(P)$
satisfies the T-modality axioms. Conversely, any T-modality induces a Cartesian lifting of the underlying monad in a suitable fibration.
The interpretation of Hoare logic has also been pursued using other structures than fibrations. Abramsky et al. introduce specification structures as a loose framework for general Hoare logic (Abramsky et al. Reference Abramsky, Gay and Nagarajan1996). It is easy to see that a Dijkstra structure in our setting determines a specification structure. Specification structures themselves do not provide wppts, and computational effects are not explicitly modeled.
Martin et al. (Reference Martin, Mathiesen and Oliva2006) give a categorical framework for Hoare logic using certain functors of type
$H:S\rightarrow{\bf PreOrd}$
. They correspond to opfibrations, hence they offer strongest postconditions predicate transformers instead. Computational effects are not explicitly modeled. One unique feature of Martin et al. (Reference Martin, Mathiesen and Oliva2006) is that their Hoare logic supports trace operators in the sense of Joyal et al. (Reference Joyal, Street and Verity1996).
In Goncharov and Schröder (Reference Goncharov and Schröder2013), Goncharov et al. constructed semantics of Hoare logic from a pair
$(\mathcal{P},\mathcal{T})$
of an order-enriched monad
$\mathcal{T}$
, and an innocent submonad
$\mathcal{P}$
of
$\mathcal{T}$
. They showed that
$\mathcal{P}1$
is a frame, and used this fact to interpret Hoare logic predicates by morphisms of type
$X\rightarrow \mathcal{P}1$
. They introduced the wppt using the join of
$\mathcal{P}1$
in Goncharov and Schröder (Reference Goncharov and Schröder2013), and called its composability sequential compatibility. Later they showed the wppt induced from the pair
$(\mathcal{P},\mathcal{T})$
is sequentially compatible if and only if the canonical morphism
$\mathcal{T}\mathcal{P}1\to\mathcal{P}1$
is an EM algebra Rauch et al. (Reference Rauch, Goncharov and Schröder2016, Remark 11). This fact bridges the work (Goncharov and Schröder Reference Goncharov and Schröder2013; Rauch et al. Reference Rauch, Goncharov and Schröder2016) and the following approach studied by Hasuo.
In Hasuo (Reference Hasuo2015), Hasuo introduced PT situations to construct composable wppts. A PT situation is a tuple of an order-enriched monad
$(\mathsf{T},\le\!)$
(in a different sense from Goncharov and Schröder Reference Goncharov and Schröder2013), an object
$\Omega \in \mathbb{C}$
and an EM
$\mathsf{T}$
-algebra
$\tau$
on
$\mathsf{T} \Omega$
, satisfying certain conditions. Each PT situation induces a functor
$\mathbb{P}^{Kl}(\tau):(\mathbb{C}_\mathsf{T})^{op}\rightarrow {\bf Pos}$
embodying a wppt. The construction of
$\mathbb{P}^{Kl}$
can be accounted for by the recipe given in Section 4. Let
$(\mathsf{T},\le,\Omega,\tau)$
be a PT situation. It determines an ordered object
$(\mathsf{T} \Omega, \leqslant)$
in
$\mathbb{C}$
, and
$\tau$
is monotone Hasuo (Reference Hasuo2015, Definition 2.4). Using the recipe in Section 4, it determines a Cartesian lifting
$\mathsf{T}_{\tau}$
of
$\mathsf{T}$
along
$d^{\mathbb{C}, \mathsf{T} \Omega} : \mathbb{C}/ \mathsf{T} \Omega \rightarrow \mathbb{C}$
. Then the wppt wp in the Cartesian Dijkstra structure
$(d^{\mathbb{C}, \mathsf{T} \Omega}, \mathsf{T}, \mathsf{T}_{\tau})$
coincides with
$\mathbb{P}^{Kl}(\tau)$
. This demonstrates that the recipe in Section 4 generalizes the construction of
$\mathbb{P}^{Kl}(\tau)$
given in Hasuo (Reference Hasuo2015). Especially, our recipe does not demand order enrichment on
$\mathsf{T}$
and allows us to take arbitrary ordered object (not limited to the form
$\mathsf{T}\Omega$
) as the basis of the lax slice construction. Examples 36, 38, 40 are benefited from this generalization.
Hino et al. (Reference Hino, Kobayashi, Hasuo and Jacobs2016) introduced another construction of wppts using relative algebras. A relative algebra is a monad morphism of type
$\mathsf{T} \rightarrow \mathbb D (\Omega^-, \Omega)$
, where
$\mathsf{T}$
is a Set-monad and
$\mathbb D$
is a category with powers
$\Omega^I$
MacLane (Reference MacLane1998, Section X.4 (4)) of a fixed
$\mathbb D$
-object
$\Omega$
. They construct wppts by composing the comparison functor
${\bf Set}_\mathsf{T} \rightarrow {\bf Set}^\mathsf{T}$
MacLane (Reference MacLane1998, Theorem VI.3) and the functor
${\bf Set}^\mathsf{T} \rightarrow \mathbb D^{{{\mathrm{op}}}}$
induced by a relative algebra Hino et al. (Reference Hino, Kobayashi, Hasuo and Jacobs2016, Theorem 4.8). When
$\mathbb D={\bf Pos}$
, their wppts coincide with those of Cartesian liftings of
$\mathsf{T}$
along the posetal fibration
$d^{{\bf Set}, \Omega}$
in Section 4. Therefore examples in Section 5–8 are also covered by the relative-algebra based wppts. On the other hand, the interaction between generic effects and wppts discussed in Section 4.4 is new compared to Hino et al. (Reference Hino, Kobayashi, Hasuo and Jacobs2016). It is the key in the semantic analysis of Kaminski’s ert in Section 7.
Example 47 is inspired by the four qualification modes introduced by Unno et al. (Reference Unno, Satake and Terauchi2018). They consider a functional programming language supporting nondeterministic choice and recursion and design a refinement-type system to analyze the behavior of programs. Their refinement-type system introduces qualified types for various modal properties of nondeterministic and diverging computations. The qualified type is annotated with a mode index
$Q_1Q_2\in\{\forall,\exists\}^2$
. The index
$Q_1$
specifies whether the return value of a program always (
$Q_1=\forall$
) or sometimes (
$Q_1=\exists$
) satisfy the refinement. The index
$Q_2$
is about the partial (
$Q_2=\forall$
) or total (
$Q_2=\exists$
) correctness of a program execution. We find a striking similarity with qualified types and the above four liftings of
${\mathsf{P}^+}_a\circ_\beta\mathsf{M}_b$
. Applying these liftings to a sound semantics of Unno et. al.’s refinement-type system would be an interesting future work.
The concept of EM monotone algebra appears in Voorneveld’s program logic for a call-by-push-value language (Voorneveld Reference Voorneveld2019). The logic can have multiple modalities to make assertions about effectful programs, and these modalities are interpreted by endofunctor algebras of the monad
$T_\Sigma$
of possibly infinite and partial
$\Sigma$
-terms. He introduces two conditions on such endofunctor algebras: leaf-monotonicity Voorneveld (Reference Voorneveld2019, Definition 4.5) and sequentiality Voorneveld (Reference Voorneveld2019, Definition 4.10). They are, respectively, equivalent to monotonicity (12) and the EM algebra axiom.
Recent work by Wolter et al. (Reference Wolter, Martini and Häusler2020) study the fibrational structure of Hoare logic and predicate transformers in the setting of imperative languages, for partial correctness. Their approach starts by defining indexed categories of programs, syntactic predicates, and semantic predicates and then use Grothendieck constructors to obtain fibrations from them. The relations between these fibrations are used to discuss notions such as soundness and completeness of Hoare logic. Similarly to us, they identify Hoare triples with Cartesian arrows. However, their framework does not cover other side-effects.
While preparing this paper, Batz et al. published a paper about a weakest preweighting semantics of an imperative programming language with a weighting effect and branching effect (Batz et al. Reference Batz, Gallus, Kaminski, Katoen and Winkler2022). They point out that their preweighting semantics can be an instance of the fibrational wppt semantics of this paper.
Our categorical framework is designed to provide an underlying semantic structure for the Hoare logic where formulas can only examine memory configurations. On the other hand, several extensions of program logics are introduced for the languages with exception (Leino and van de Snepscheut Reference Leino and van de Snepscheut1994; Maillard et al. Reference Maillard, Ahman, Atkey, Martnez, Hritcu, Rivas and Tanter2019; Sekerinski Reference Sekerinski2012). In these extensions, formulas in the logic can also examine exceptions raised by programs – for instance, in Sekerinski (Reference Sekerinski2012), the Hoare logic is extended so that we can specify two postconditions for normal and exceptional termination. It is an interesting challenge to understand these extended Hoare logic within our fibrational framework.
Turning our eyes to functional programming languages, a series of recent papers (Ahman et al. Reference Ahman, Hritcu, Maillard, Martnez, Plotkin, Protzenko, Rastogi and Swamy2017; Maillard et al. Reference Maillard, Ahman, Atkey, Martnez, Hritcu, Rivas and Tanter2019, Reference Maillard, Hritcu, Rivas and Van Muylder2020) develop Dijkstra monads for the verification of effectful programs in dependent-type theories. The main task of a Dijkstra monad is to take a type A and a specification
$w\in\mathsf{W} A$
written in the language of a specification monad
$\mathsf{W}$
and collect computations that satisfy w. In Maillard et al. (Reference Maillard, Ahman, Atkey, Martnez, Hritcu, Rivas and Tanter2019), Section 5, they establish an equivalence between Dijkstra monads and monad morphisms into ordered monads. Dijkstra monads intersect with our categorical wppts when the former arise from monad morphisms of type
$\mathsf{T}\rightarrow \mathsf{W}^{\mathrm{pure}}$
, where
$\mathsf{W}^{\mathrm{pure}}$
is an ordered continuation monad (see Maillard et al. Reference Maillard, Ahman, Atkey, Martnez, Hritcu, Rivas and Tanter2019, Section 4.1 for detail). In this situation, such a monad morphism bijectively corresponds to an EM monotone
$\mathsf{T}$
-algebra o over the return type of
$\mathsf{W}^{\mathrm{pure}}$
Maillard et al. (Reference Maillard, Ahman, Atkey, Martnez, Hritcu, Rivas and Tanter2019, Section 4.4). The corresponding Dijkstra monad then collects all the computations
$c\in\mathsf{T} A$
such that the predicate transformer
$\mathrm{wp}(-,c)$
induced from o is below the specification
$w\in\mathsf{W}^{\mathrm{pure}} A$
. This is the only relationship we know between Dijkstra monads and our fibrational theory of wppts, and we leave exploring further relationships between them as future work.
In this paper, we only considered posetal fibrations, because when verifying program properties, we do not care very much about proof terms. However, in principle, it is also possible to consider proof terms during the verification of program properties. Non-posetal fibrations will then be used for modeling such proof-relevant Hoare logic and wppts. It is an interesting future work to see how much of this paper’s results extend to non-posetal fibrations.
12. Conclusion
We have presented a fibrational and monadic semantics of Hoare triples and weakest precondition predicate transformers. The key fact is that the composability of wppts is equivalent to the Cartesianness of the monad lifting. We next studied the Cartesian liftings of monads along domain fibrations; they bijectively correspond to EM monotone algebras, giving a fibrational view of Hasuo (Reference Hasuo2015). Despite examples presented here being within the framework of Hasuo (Reference Hasuo2015), Hino et al. (Reference Hino, Kobayashi, Hasuo and Jacobs2016), we studied new examples, in which we have revealed the monads behind wppt-like operators used to compute expected run-time (Kaminski et al. Reference Kaminski, Katoen, Matheja and Olmedo2016) and higher moments (Kura et al. Reference Kura, Urabe and Hasuo2019).
Acknowledgements
This paper was first submitted while the first author was affiliated to the Imdea Software Institute. The authors are grateful to Mayuko Kori for spotting a mistake in the example in Section 8.
Financial support
This research was supported by ERATO HASUO Metamathematics for Systems Design Project (No. JPMJER1603), JST. This research was conducted during the first author’s visit to the National Institute of Informatics.
Conflicts of interest
The authors declare none.



