A Fibrational Tale of Operational Logical Relations: Pure, Effectful and Differential

Logical relations built on top of an operational semantics are one of the most successful proof methods in programming language semantics. In recent years, more and more expressive notions of operationally-based logical relations have been designed and applied to specific families of languages. However, a unifying abstract framework for operationally-based logical relations is still missing. We show how fibrations can provide a uniform treatment of operational logical relations, using as reference example a lambda-calculus with generic effects endowed with a novel, abstract operational semantics defined on a large class of categories. Moreover, this abstract perspective allows us to give a solid mathematical ground also to differential logical relations -- a recently introduced notion of higher-order distance between programs -- both pure and effectful, bringing them back to a common picture with traditional ones.


Introduction
Logical relations [Rey83] are one of the most successful proof techniques in logic and programming language semantics.Introduced in proof theory [Tai67,GLT89] in their unary form, logical relations quickly became a main tool in programming language semantics.In fact, starting with the seminal work by Reynolds [Rey83], Plotkin [Plo73], and Statman [Sta85], logical relations have been extensively used to study both the denotational and operational behaviour of programs. 1 Logical relations (and predicates) mostly come in two flavours, depending on whether they are defined relying on the operational or denotational semantics of a language.We refer to logical relations of the first kind as operational logical relations and to logical relations of the second kind as denotational logical relations.Due to their link with denotational semantics, denotational logical relations have been extensively studied in the last decades, both for specific programming languages and in the abstract, this way leading to beautiful general theories of (logical) predicates and relations on program denotations.In particular, starting with the work by Reynolds and Ma [MR91], Mitchell and Scedrov [MS92], and Hermida [Her93], researchers have started to investigate notions of (logical) predicates and relations in a general categorical setting, this way giving rise to an abstract understanding of relations over (the denotational semantics of) programs centered around the notions of fibrations [Her93, GJF + 15, SJ18, KSU18, Kat13, Kat14,Kat05b] reflexive graphs [OT95, RR94, DR04, HRR14], and factorisation systems [KM18,HJ02,GLN08].The byproduct of all of that is a general, highly modular theory of denotational logical relations that has been successfully applied to a large array of language features, ranging from parametricity and polymorphism [GJF + 15, SJ18, DR04] to computational effects [KSU18, Kat13, Kat14, Kat05b, Lei17, KM18, GLN08].
On the operational side, researchers have focused more on the development and applications of expressive notions of logical relations for specific (families of) languages, rather than on their underlying theory.In fact, operational logical relations being based on operational semantics, they can be easily defined for languages for which finding the right denotational model is difficult, this way making operational logical relations a handy and lightweight technique, especially when compared to its denotational counterpart.As a paradigmatic example, consider the case of stochastic λ-calculi and their operational techniques [BDLGS16,DLG19b,WCGC18] which can be (easily) defined relying on the category of measurable spaces and measurable functions, but whose denotational semantics have required the introduction of highly nontrivial mathematical structures [SYW + 16, Sta17, VKS19, EPT18], since the category of measurable spaces (and measurable functions) is not closed [Aum61].
The wide applicability of operational logical relations, however, has also prevented the latter to organise as a uniform corpus of techniques with a common underlying theory.Operational logical relations result in a mosaic of powerful techniques applied to a variety of languages -including higher-order, functional, imperative, and concurrent languages [DAB11, Ahm06, TTA + 13, AM01, CH07, DNB12]; both pure and (co)effectful [JSV10, DLG22a, AB20, BJST16, Hof15, BHN14, BPPS18, BB15] -whose relationship, however, is unclear.This may not be a prime concern of the semanticist interested in somehow conventional program behaviours, such as termination, extensional equivalence, cost, etc.2However, it becomes so when one faces logical relations for program behaviours that are not yet fully understood, such as those akin to metric [RP10,Pis21] and differential properties of programs [DLGY19,DLG20,DLG21a,DLG22a].In those cases, in fact, logical relations lose their relational core and are modelled through more articulated structures that may go significantly far from classic relations and generalisations thereof.
A paradigmatic case is the one of the so-called differential logical relations [DLGY19, DLG20, DLG21a, DLG22a], a recently introduced foundational framework for differential (higher-order) program semantics.Differential logical relations relate pairs of programs with so-called higher-order distances, namely notions of distances that can interact with the related programs in a parameter-passing fashion.For instance, differential logical relations measure the distance between functional programs P , Q not as a number, as in ordinary metric reasoning, but as a (possibly higher-order) function δ; and the 'logical' behaviour of δ prescribes that on any pair of inputs V, W with (higher-order) distance ε, the distance between P V and QW is given by δ(V, ε).That is, the distance δ is itself a function that, given two inputs and a distance between them, produce an input-dependent distance between outputs.

Vol. 20:2 A FIBRATIONAL TALE OF OPERATIONAL LOGICAL RELATIONS 1:3
Differential logical relations indeed share some commonalities with traditional logical relations, but it is not mathematically clear what is the exact relationship between those two worlds: for instance, are differential logical relations indeed logical relations?(And, if so, in which sense?) Is the so-called fundamental lemma of differential logical relations a true instance of the classic fundamental lemma of logical relations?And, more generally, how much of the theory of ordinary logical relations can be exported to the realm of differential logical relations, and vice versa?All those questions become even harder to answer if one considers effectful extensions of differential logical relations [DLG22a].Such extensions, in fact, mix traditional monadic reasoning à la Moggi [Mog89] together with the novel notion of a differential extension.The mathematical status of such a notion is currently unknown, in the sense that it is not known whether a differential extension could be seen as a relational extension [Bar70, KV16,Thi96,CKS84] generalised to a differential setting, nor whether the 'canonical' differential extension used to concretely define effectful logical relations is indeed canonical; not to mention the status of the fundamental lemma of effectful differential logical relations.
Answering those questions is not only a crucial step towards the development of a solid theory of differential semantics throughout (effectful) differential logical relations, but it is also key to improving the applicability of the latter.In fact, when reasoning about differential behaviours, such as input-dependent cost analysis or approximate correctness, it appears useful to mix differential and non-differential reasoning [DLG22a], so that it is desirable to view non-differential reasoning as a collapsed form of differential one.Concretely, that means recovering traditional logical relations as differential ones with rather trivial (higher-order) distances.However, the current theory of differential logical relations does not allow one to do that, unless one shows from scratch how to encode a specific family of logical relations as differential logical relations.
In this paper, we find a remedy for all of that and show that (effectful) differential logical relations are a form of operational logical relations in a very precise mathematical sense.We do more, actually.In fact, to prove the aforementioned result, we first need a general definition of what an operational logical relation is, something that, as already remarked, seems unavailable in the literature.We fix that by taking a fibrational foundation of operational logical relations, hence showing that much in the same way denotational logical relations can be uniformly understood in terms of fibrations, it is possible to give a uniform account of operational logical relations relying on the language of fibrations.Armed with such a fibrational understanding, we then show how differential logical relationsboth pure and effectful -can be seen as a suitable instance of our fibrational framework.Remarkably, the level of abstraction offered by fibrations allows us to come up with a general fundamental lemma of logical relations that covers both traditional and differential instances of the homonymous result.
1.1.Contribution.The main contribution of this paper is twofold, covering both the general theory of operational logical relations and the specific theory of pure and effectful differential logical relations.
1.1.1.Operational Logical Relations, Fibrationally.Our first contribution is the development of a general, abstract notion of an operational logical relation in terms of fibrations for a λ-calculus with generic effects.Fibrations are a mainstream formalism for general, categorical notions of predicates/relations.More precisely, a fibration is a suitable functor from a category of (abstract) predicates -the domain of the fibration -to a category of arguments -usually called the base category.In denotational logical relations, predicates usually apply to program denotations rather than to programs themselves, with the main consequence that the base category is usually required to be cartesian closed.In this paper, we follow a different path and work with base categories describing the operational (and interactive) behaviour of programs, rather than their denotations.To do so, we introduce the novel notion of an operational structure, the latter being a cartesian category with arrows describing (monadic) evaluation semantics [PP01,DLGL17] and satisfying suitable coherence conditions encoding the base dynamics of program evaluation.This way, we give not only an abstract account of traditional set-based evaluation semantics, but also of evaluation semantics going beyond the category of sets and functions, the prime example being the evaluation semantics of stochastic λ-calculi, which is defined as a stochastic kernel [DLG19b,WCGC18].
On top of our abstract operational semantics, we give a general notion of an operational logical relation in terms of (logical) fibrations and prove a general result (which we call the fundamental lemma of logical relations, following the standard nomenclature of concrete, operational logical relations) stating that programs behave as arrows in the domain of the fibration.Remarkably, our general fundamental lemma subsumes several concrete instances of the fundamental lemma of logical relations appearing in the literature.Additionally, the operational nature of our framework immediately results in a wide applicability of our results, especially if compared with fibrational accounts of denotational logical relations.In particular, since our logical relations build upon operational structures, they can be instantiated to non-cartesian-closed categories, this way reflecting at a general level the wider applicability of operational techniques with respect to denotational ones.As a prime example of that, we obtain operational logical relations (and their fundamental lemma) for stochastic λ-calculi for free, something that is simply not achievable denotationally, due to the failure of cartesian closedness of the category of measurable spaces.
1.1.2.Fibrational Differential Reasoning.Our second, main contribution is to show that our framework goes beyond traditional relational reasoning, as it gives a novel mathematical account of the recently introduced differential logical relations [DLGY19, DLG20, DLG21a, DLG22a] (DLRs, for short), both pure and effectful.DLRs are a new form of logical relations introduced to define higher-order distances between programs, such distances being abstract notions reflecting the interactive complexity of the programs compared.DLRs have been studied operationally and on specific calculi only, oftentimes introducing new notions -such as the one of a differential extension of a monad [DLG22a] -whose mathematical status is still not well understood.The main consequence of that is that a general, structural account of pure and effectful DLRs is still missing.In this paper, we show how DLRs are a specific instance of our abstract operational logical relations and how the fundamental lemma of DLRs is an instance of our general fundamental lemma.We do so by introducing the novel construction of a fibration of differential relations and showing how the latter precisely captures the essence of DLRs, bringing them back to a common framework with traditional logical relations.Additionally, we show how our fibrational account sheds new light on the mathematical status of effectful DLRs.In particular, we show that differential extensions of monads are precisely liftings of monads to the fibration of differential relations, and that the so-called coupling-based differential extension [DLG22a] -whose canonicity has been left as an open problem -is an instance of a general monadic lifting to the fibration of differential relations: remarkably, such a lifting is the extension of the well-known Barr lifting [Bar70] to a differential setting.
1.1.3.Source of the material.This is an extended and revised version of a paper that appears in the proceedings of FSCD 2022 [DG22].The present version provides more background on Differential Logical Relations to better frame the work in the literature, includes all proofs of our results and reports some new examples.
1.2.Related Work.Starting with the seminal work by Hermida [Her93], fibrations have been used to give categorical notions of (logical) predicates and relations, and to model denotational logical relations [GJF + 15, SJ18, KSU18, Kat13, Kat14, Kat05b], as they provide a formal way to relate the denotational semantics of a programming language and a logic for reasoning about it.Other categorical approaches to denotational logical relations have been given in terms of reflexive graphs [OT95, RR94, DR04, HRR14] and factorisation systems [KM18,HJ02,GLN08].
On the operational side, fibrations have been used to give abstract accounts to induction and coinduction [HJ98], both in the setting of initial algebra-final coalgebra semantics [GJF13, GJF12, GJF10] and in the setting of up-to techniques [BPPR14,BKP18].To the best of the authors' knowledge, however, none of these approaches has been applied to operational reasoning for higher-order programming languages.Concerning the latter, general operational accounts of logical relations both for effectful [JSV10] and combined effectful and coeffectful languages [AB20,DLG22b] have been given in terms of relational reasoning.These approaches, however, are tailored to specific operational semantics and notions of relations, and thus they cannot be considered truly general.Finally, DLRs have been studied mostly operationally [DLGY19, DLG20, DLG21a, DLG22a], although some general denotational accounts of DLRs have been proposed [DLGY19,Pis21].Even if not dealing with operational aspects of DLRs, the latter proposals can cope with pure DLRs only, and are too restrictive to incorporate computational effects.

The Anatomy of an Operational Semantics
To define a general notion of an operational logical relation, we first need to define a general notion of an operational semantics.This is precisely the purpose of this section.In particular, we introduce the notion of an operational structure on a category with finite products endowed with a strong monad as an axiomatisation of a general evaluation semantics.Operational structures prescribe the existence of basic interaction arrows (the latter describing basic program interactions as given by the usual reduction rules) and define program execution as a Kleisli arrow (this way giving monadic evaluation) satisfying suitable coherence laws reflecting evaluation dynamics.Remarkably, operational structures turn out to be more liberal -hence widely applicable -than categories used in denotational semantics (the latter being required to be cartesian closed).

2.1.
A Calculus with Generic Effects.Our target calculus is a simply-typed fine-grained call-by-value [LPT03] λ-calculus, denoted by Λ, enriched with generic effects [PP01,PP03].The syntax of Λ is given in Figure 1: to explain that, we need to recall some preliminary notions.
We assume familiarity with monads and algebraic effects [Mog89,PP01].In particular, we use the notation T = (T, η, µ, st) for strong monads on cartesian categories, recalling that the latter notion is equivalent to the one of a strong Kleisli triple T = (T, η, >>=), where for an arrow f : X × Y → T Z in a cartesian category C , we denote by >>=f : X × T Y → T Z the strong Kleisli extension of f .We tacitly use strong monads and strong Kleisli triples interchangeably, and write f † : T X → T Y for the Kleisli extension of f : X → T Y . 3Given a strong monad T = (T, η, >>=) on a cartesian category C , a generic effect [PP03, PP01] of arity A, with A an object of C , is an arrow γ : 1 → T A. Standard examples of generic effects are obtained by taking C = Set and A equal to a finite set giving the arity of the effect.For instance, one models nondeterministic (resp.fair) coins as elements of P(2) (resp.D(2)), where P (resp.D) is the powerset (resp.distribution) monad.Other examples of generic effects include primitives for input-output, memory updates, exceptions, etc.Here, we assume we have a collection of generic effect symbols γ, each with an associated type σ γ .We leave the interpretation of γ as an actual generic effect γ to the operational semantics.
Armed with these notions, we give the syntax and static semantics of Λ in Figure 1, where ζ ranges over base types and c over constants of type ζ (for ease of exposition, we do not include operations on base types, although those can be easily added).The notation used for the static semantics is mostly standard: a typing judgment is an expression of the form Γ ⊢ t : σ or Γ ⊢ v : σ, where Γ is an environment, i.e. a set of pairs x : σ of variables and types such that if both x : σ and x : τ belongs to Γ, the σ = τ , and v and t are a value and a computation, respectively.Indeed, expressions of Λ are divided into two (disjoint) classes: values (notation v, w, . ..) and computations (notation t, s, . ..), the former being the result of a computation, and the latter being an expression that once evaluated may produce a value (the evaluation process might not terminate) as well as side effects.When the distinction between values and computations is not relevant, we generically refer to terms (and still denote them as t, s, . ..).We adopt standard syntactic conventions [Bar84] and identify terms up to renaming of bound variables: we say that a term is closed if it has no free variables and write V σ , Λ σ for the sets of closed values and computations of type σ, respectively.We write t[v 1 , . . ., v n /x 1 , . . ., x n ] (and similarly for values) for the capture-avoiding (simultaneous) substitution of the values v 1 , . . ., v n for all free occurrences of x 1 , . . ., x n in t.Oftentimes, we will use the notation − → ϕ for a sequence ϕ 1 , . . ., ϕ n of symbols ϕ i , for i ∈ {1, . . ., n}.
When dealing with denotational logical relations, one often organises Λ as a syntactic category having types as objects and (open) terms modulo the usual βη-equations as arrows.Operationally, however, terms are purely syntactic objects and cannot be taken modulo βη-equality.For that reason, we consider a syntactic graph rather than a syntactic category. 4  Definition 2.1.The objects of the syntactic graph Syn are environments Γ, types σ, and expressions σ, for σ a type.Arrows are defined thus: hom(Γ, σ) consists of values Γ ⊢ v : σ, whereas hom(Γ, σ) consists of terms Γ ⊢ t : σ; otherwise, the hom-set is empty.
The definition of Syn reflects the call-by-value nature of Λ: to each type σ we associate two objects, representing the type σ on values and on computations.Moreover, there is no arrow having environments as codomains nor having objects σ as domain: this reflects that in call-by-value calculi variables are placeholders for values, not for computations.

Operational Semantics:
The Theoretical Minimum.Having defined the syntax of Λ, we move to its operational semantics.Among the many styles of operational semantics (small-step, big-step, etc.), evaluation semantics turns out to be a convenient choice for our goals.Evaluation semantics are usually defined as monadic functions e : Λ σ → T (V σ ), with T a monad encoding the possible effects produced during program evaluation (e.g., divergence or nondeterminism) [DLGL17, PP01, JSV10].To clarify the concept, let us consider an example from [DLGL17].
Notice that according to the fine-grained methodology, evaluation is indeed defined only on computations (i.e.not on values).
Example 2.2 defines evaluation semantics as an arrow in the category Set of sets and functions relying on two main ingredients: the monad T and its algebraic operations; and primitive functions implementing the basic mechanism of β-reductions, viz.application/substitution and projections.The very same recipe has been used to define specific evaluation semantics beyond Set , a prime example being kernel-like evaluation semantics 4 Recall that a graph is defined by removing from the definition of a category the axioms prescribing the existence of identity and composition.A diagram is a map from graphs to graphs (a diagram being defined by removing from the definition of a functor the clauses on identity and composition).Since any category is a graph, we use the word diagram also to denote maps from graphs to categories.
5 It is worth remarking that termination is not an issue for our general notion of an evaluation semantics (Definition 2.3 below).In fact, the results presented in this paper simply require having an evaluation map satisfying suitable coherence conditions.Consequently, we could rephrase this example as to ignore termination by requiring the monad to be enriched in a ω-complete partial order [AJ94] and defining evaluation semantics as the least fixed point of a suitable map, as it is customary in monadic evaluation semantics [DLGL17].
for stochastic λ-calculi [DLG19b, WCGC18, VKS19, EPT18, BCDLG22], where evaluation semantics are defined as Kleisli arrows on suitable categories of measurable spaces (see Example 2.5 below for details).Here, we propose a general notion of an operational semantics for Λ in an arbitrary cartesian category B and with respect to a monad T. We call the resulting notion a (Syn -)operational structure.
Definition 2.3.Given a strong monad T on a cartesian category B, a (Syn -)operational structure consists of a diagram S : Syn → B satisfying S( −−→ x : σ) = − → Sσ, together with the following (interaction) arrows (notice that γ ranges over generic effects) and satisfying the coherence laws in Figure 2.
Notice how the first four coherence laws in Figure 2 ensure the intended behaviour of the arrows β, ι, p i , c, whereas the remaining laws abstractly describe the main dynamics of program execution.Notice also that Definition 2.3 prescribes the existence of an evaluation arrow e: it would be interesting to find conditions on B (probably a domain-like enrichment [Kel05] or partial additivity [MA86]) ensuring the existence of e.We can now instantiate Definition 2.3 to recover standard Set -based evaluation semantics as well as operational semantics on richer categories.In particular, since B need not be closed, we can give Λ an operational semantics in the category Meas of measurable spaces and measurable functions.Example 2.4.Let B = Set and define S : Syn → Set thus: We obtain an operational structure by defining the maps β, p 1 , p 2 , and ι in the obvious way (e.g., Finally, given a monad T with generic effects γ ∈ T V σγ for each effect symbol γ, we define e as the evaluation map of Example 2.2.1:9 Example 2.5 (Stochastic λ-calculus).Let us consider the instance of Λ with a base type R for real numbers, constants c r for each real number r, and the generic effect symbol U standing for the uniform distribution over the unit interval.Recall that Meas has countable products and coproducts (but not exponentials [Aum61]).To define the diagram S : Syn → Meas, we rely on the well-known fact [EPT18, SYW + 16, BDLGS16] that both V σ and Λ σ can be endowed with a σ-algebra making them measurable (actually Borel) spaces in such a way that V R ∼ = R and that the substitution map is measurable.We write Σ σ and Σ σ for the σ-algebras associated to V σ and Λ σ , respectively.We thus define S : Syn → Meas as follows: We obtain an operational structure by observing that the maps β, p 1 , p 2 , and ι of the previous example extend to Meas, in the sense that they are all measurable functions.Next, we consider the Giry monad [Gir82] G = (G, η, µ) with G : Meas → Meas mapping each measurable space to the space of probability measures on it.By Fubini-Tonelli theorem, G is strong.Let U be the Lebesgue measure on [0, 1], which we regard as an arrow , and thus as a generic effect in Meas.We then define [DLG19b] e : Λ σ → G(V σ ) as in Example 2.2.Alternatively, we can define a finer operational structure by exploiting the observation that V σ and Λ σ are Borel spaces and move from Meas to its full subcategory Pol whose objects are standard Borel spaces (notice that arrows in Pol are measurable functions).Indeed, all the construction seen so far actually gives standard Borel spaces.In particular, the Giry monad gives a monad on Pol [Kec95] and the operational structure thus obtained coincides with the stochastic operational semantics in [BCDLG22].

Operational Logical Relations, Fibrationally
Having defined what an operational semantics for Λ is, we now focus on operational reasoning.In this section, we propose a general notion of an operational logical relation in terms of fibrations over (the underlying category of) an operational structure and prove that a general version of the fundamental lemma of logical relations holds for our operational logical relations.But before that, let us recall some preliminary notions on (bi)fibrations (we refer to [Her93, Jac01, Str18] for more details).
3.1.Preliminaries on Fibrations.Let p : E → B be a functor and f : there is a unique arrow g : Y → Z such that p(g) = v and h = g • f .We say that f is vertical if u is an identity.
A fibration is a functor p : E → B such that, for every object X in E and every arrow u : I → p(X) in B, the exists a cartesian arrow over u with codomain X. Dually, an opfibration is a functor p : E → B such that for every object X in E and every arrow f : p(X) → I in B, the exists a cocartesian arrow over u with domain X.A bifibration is a functor which is both a fibration and an opfibration.We refer to E and B as the domain and the base of the (bi/op)fibration.A (op)fibration is cloven if it comes together with a choice of (co)cartesian liftings: for an object X in E, we denote by u X : u * X → X the 1:10 chosen cartesian arrow over u : I → p(X) and by u X : X → u !X the chosen cocartesian arrow over u : p(X) → I.A bifibration is cloven if it has choices both for cartesian and cocartesian liftings.From now on, we assume all (bi/op)fibrations to be cloven.
Let p : E → B be a functor and I an object in B. The fibre over I is the category E I where objects are objects X in E such that p(X) = I and arrows are arrows f : X → Y in E such that p(f ) = id I , namely, vertical arrows over I.Then, for every arrow u : I → J, the following hold: • if p is a fibration, we have a functor u * : E J → E I called reindexing along u; • if p is an opfibration, we have a functor u !: E I → E J called image along u; • if p is a bifibration, we have an adjunction u !⊣ u * .
Example 3.1.Let us consider the category p(Set ) of homogeneous n-ary predicates over sets.Its objects are pairs of sets (X, A) with A ⊆ X n as objects and arrows f : There is an obvious functor Pred Set : p(Set ) → Set mapping an n-ary predicate (X, A) to its underlying set X and an arrow f : (X, A) → (Y, B) to its underlying function f : X → Y .The functor Pred Set is a bifibration where the cartesian and cocartesian liftings of a function f : X → Y are given by inverse and direct images along f , respectively.Special instances of Pred Set are obtained for n = 1 (unary predicates) and n = 2 (binary relations).In those cases, we specialise the notation and write Sub Set : s(Set ) → Set and Rel Set : r(Set ) → Set .
Example 3.2.Starting from Rel Set : r(Set ) → Set , we obtain a (bi)fibration of relations Rel Meas : r(Meas ) → Meas on measurable spaces simply by considering the category r(Meas ) -whose objects are triples (X, Σ, R), with (X, Σ) a measurable space and R a relation on X -and forgetting about the measurable space structure, hence mapping (X, Σ, R) to (X, R).
C .Therefore, we have that, for every arrow f : I → J in C and every object (I, [α]), the image along f is f !(I, [α]) = (J, [f • α]), and, for every object (J, [β]), the reindexing along Ψ C is a bifibration. 6Finally, observe that the bifibrations Ψ Set and Sub Set are equivalent in the sense that there is a functor U : Sub Set → ws(Set ) which is an equivalence satisfying Ψ Set • U = Sub Set and preserving (co)cocartesian arrows.The functor U maps (X, A) to (X, [ι A ]) where ι A : A → X is the inclusion function, and it is the identity on arrows.
Example 3.4 (Information Flow).We now define a (bi)fibration of classified relations [Kav19] in terms of presheaves.Fixed a lattice L of security levels (such as the two-elements lattice {private ≤ public}) regarded as a category, we consider the functor category Set L and the category r(Set L ) whose objects are pairs (X, R) with X : L → Set and R mapping each ℓ ∈ L to a binary endorelation R ℓ on X(ℓ) such that ℓ 1 ≤ ℓ 2 implies R ℓ 1 ⊆ R ℓ 2 , and whose arrows are natural transformations preserving relations.As usual, there is an obvious forgetful functor from r(Set L ) to Set L mapping (X, R) to X, which gives rise to a fibration.Such a fibration naturally supports relational reasoning about information flow as follows [ABHR99,DLG22a].Starting with the Set -based operational structure of λ-terms, we embed such a structure in Set L by considering the constant functor mapping each ℓ to the (constant) set of λ-terms.Moving to r(Set L ), we then obtain relations on λ-terms that depend on security levels, and we think about them as giving program equivalence for observers with security levels (or permissions) in L.
Example 3.5 (Simple fibration).Let C be a category with finite products.We consider a category s(C ) defined as follows.Objects are pairs (I, X) of objects of C and an arrow (u, f ) : (I, X) → (J, Y ) consists of a pair of arrows u : I → J and f : The composition of (u, g) : (I, X) → (J, Y ) and (v, g) , where π 1 : I × X → I is the first projection and ⟨u • π 1 , f ⟩ : I × X → J × Y is the pairing of u • π 1 and f given by the universal property of the product J × Y .The identity on (I, X) is the arrow (id X , π 2 ) : (I, X) → (I, X), where π 2 : I × X → X is the second projection.There is an obvious functor σ C : s(C ) → C , which maps an object (I, X) to the first component I and acts similarly on arrows.This functor is a fibration known as the simple fibration [Jac01], where, for every arrow u : I → J in C and object (J, X) in s(C ), the cartesian lifting of u is the arrow u (J,X) = (u, π 2 ) : (I, X) → (J, X).
Fibrations nicely carry a logical content: logical operations, in fact, can be described as categorical structures on the fibration.We now define the logical structure underlying logical relations, namely conjunctions, implications, and universal quantifiers.Recall that a fibration p : E → B has finite products if E and B have finite products and p preserves them.We denote by × and 1 finite products in E and recall that in a fibration p : E → B with finite products every fibre E I has finite products ∧ I and ⊤ I 7 preserved by reindexing functors.

Additionally, we have the isomorphisms
This follows essentially because ×, being a right adjoint, preserves cartesian arrows (cf.[Jac01, Exercise 1.8.5]).Definition 3.6.A fibration p : E → B with finite products is a logical fibration if it is fibred cartesian closed and has universal quantifiers, where: (1) p is fibred cartesian closed if every fibre E I has exponentials, denoted by X ⇒ Y , and reindexing preserves them.
(2) p has universal quantifiers if, for every projection π : I × J → I in B, the reindexing functor π * : E I → E I×J has a right adjoint Note that in a fibration with universal quantifiers, we have right adjoints along any tuple of distinct projections ⟨π i 1 , . . ., π i k ⟩ : I 1 ×. ..×I n → I i 1 ×. ..×I i k , where i 1 , . . ., i k ∈ {1, . . ., n} are all distinct.We denote such a right adjoint by A ⟨π i 1 ,...,π i k ⟩ .The following propositions shows under which conditions the fibration of weak subobjects and the simple fibration are logical fibrations.Example 3.9.Since Set is locally cartesian closed, Proposition 3.7 implies that both Ψ Set and Sub Set , being equivalent as noticed in Example 3.3, are logical fibrations.Also Rel Set is a logical fibration, as it can be obtained from Sub Set by pulling back along the product-preserving functor X → X × X : Set → Set .
A 2-category of (bi)fibrations.Fibrations can be organised in a 2-category.This is important because many standard categorical concepts can be internalised in any 2-category, thus providing us with an easy way to define them also for fibrations.In particular, we will be interested in (strong) monads on a fibration, as they will allow us to define effectful logical relations.
We consider the 2-category Fib of fibrations defined as follows.Objects are fibrations p : E → B. A 1-arrow F : p → q between fibrations p : E → B and q : D → C is a pair of functors (F , Ḟ ) where F : B → C and Ḟ : E → D and F • p = q • Ḟ . 8A 2-arrow ϕ : F ⇒ G between 1-arrows F, G : p → q is a pair of natural transformations (ϕ, φ) where ϕ : F .→ G and φ : Ḟ .→ Ġ and ϕp = q φ.Compositions and identities are defined componentwise.The 2-category biFib of bifibrations is the full 2-subcategory of Fib whose objects are bifibrations.A 1-arrow F : p → q in biFib is said to be cartesian if Ḟ preserves cartesian arrows; it is said to be cocartesian if Ḟ preserves cocartesian arrows.Example 3.10.Given a monad T = (T, η, µ) on Set , we obtain a lifting of T along Rel Set : r(Set ) → Set via the so-called Barr extension [Bar70] of T. Looking at a relation When the functor T preserves weak pullbacks, then T extends T to an ordered functor on Rel , the ordered category of sets and relations, making η and µ lax natural transformations [Bar70].Consequently, mapping objects (X, R) of r(Set ) to (T X, T R) and arrows f : (X, R) → (Y, S) to T f : (T X, T R) → (T Y, T S), we obtain the desired lifting.Note that preservation of weak pullbacks is only needed to force T to strictly preserve relational composition.Thus, since we do not consider composition, restricting ourselves to endorelations, we can avoid this assumption.
Example 3.11.Let us consider the Giry monad G = (G, η, µ) and the fibration Rel Meas : r(Meas ) → Meas.Since relations in r(Meas ) are defined as set-theoretic relations, we can consider the Barr extension of the Giry monad as in the previous example.Unfortunately, that does not work in general [KSU18,Kat13], although it does when we restrict objects of r(Meas ) to structure (X, Σ, R) such that R is reflexive.This obviously gives a fibration, and the Barr extension of G provides the desired lifting as in the previous example [DLG19b].
Example 3.12.Let us consider the fibration Rel Set L : r(Set L ) → Set L of information flow.To model information hiding, we consider the identity monad ID on Set L .Intuitively, information hiding does not directly act on programs, but rather on the way an external observer can inspect them.Consequently, the actual information-hiding operation will be modelled by the lifting of ID along Rel Set L , which ultimately means specifying how ID acts on relations.For simplicity, let us consider the lattice private ≤ public.Thinking about a relation R(ℓ) as program equivalence for an observer with security permission ℓ, we define the masking operation as obscuring private programs, that is making them inaccessible to an external observer, so that private programs will be regarded as equivalent.Formally, define !R(public) = R(public) and !R(private) = X(private) × X(private).The assignment (X, R) to (X, !R) then gives the desired lifting.
3.2.Operational Logical Relations and Their Fundamental Lemma.We are now ready to define a general notion of an operational logical relation.Let us consider an operational structure S over a cartesian category B with a strong monad T on B, as in Definition 2.3.Let p : E → B be a logical fibration (cf.Definition 3.6) and Ṫ be a lifting of T to p. Definition 3.13.A logical relation is a mapping R from objects of Syn to objects of E such that p(Rx) = Sx, for any object x of Syn, 9 and the following hold.
Notice that giving a logical relation essentially amounts to specifying the action of R on basic types, since the action of R on complex types is given by Definition 3.13.The defining clauses of a logical relation exploit both the logic of a (logical) fibration and the operational semantics of Λ.The reader should have recognised in Definition 3.13 the usual definition of a logical relation, properly generalised to rely on the logic of a fibration only.For instance, Rσ intuitively relates computations whose evaluations are related by the lifting of the monad.Notice also that the clause of arrow types has a higher logical complexity than other clauses, as it involves two logical connectives, viz.implication and universal quantification.
Operational logical relations come with their so-called fundamental lemma, which states that (open) terms map (via substitution) related values to related terms.In our abstract framework, the fundamental lemma states that to any term t we can associate a suitable arrow Rt in E lying above St.To prove our general version of the fundamental theorem, we have to assume it for the parameters of our calculus (constants of basic types and generic effects).Accordingly, we say that a logical relation R is (Λ-)stable if: (i) for every constant c of a base type ζ, we have an arrow ċ : 1 → Rζ above c; (ii) we have an arrow γ : 1 → Ṫ (Rσ) above γ.
Theorem 3.14 (Fundamental Lemma).Let R be a stable logical relation.The map R extends to a diagram R : Syn → E such that p • R = S.In particular, for any term Γ ⊢ t : σ, there is an arrow Rt : RΓ → Rσ in E above St (similarly, for values).
Proof.Given Γ ⊢ t : σ, we construct the desired arrow Rt by induction on t.The case for values lifts commutative triangles in Figure 2 using the universal property of cartesian liftings of interaction arrows and then constructs the desired arrow using the logical structure of p and Rσ.For the case of terms, we just lift the commutative diagrams in Figure 2 We choose h as R(t to x.s).
We can now instantiate Theorem 3.14 with the operational structures and fibrations seen so far to recover traditional logical relations (and their fundamental lemmas).For instance, the operational structure of Example 2.5 and the fibration obtained by pulling back Rel Set along the forgetful functor from Meas to Set (together with the lifting of the Giry monad) give operational logical relations for stochastic λ-calculi, whereas considering 1:15 the fibration Rel Set L and the lifting of the identity monad for information hiding gives logical relations for non-interference.Theorem 3.14 then gives compositionality (i.e.congruence and substitutivity) of the logical relation.But that is not the end of the story.In fact, our general results go beyond the realm of traditional logical relations.

The fibration of differential relations
In this section, we describe the construction of the fibration of differential relations, which can serve as a fibrational foundation of differential logical relations [DLGY19, DLG20, DLG21a, DLG22a] (DLRs, for short), a recently introduced form of logical relations defining higher-order distances between programs.DLRs are ternary relations relating pairs of terms with elements representing distances between them: such distances, however, need not be numbers.More precisely, with each type σ one associates a set σ of (higher-order) distances between terms of type σ, and then defines DLRs as relating terms of type σ with distances in σ between them.Elements of σ reflect the interactive complexity of programs, the latter being given by the type σ.Ignoring effects, 10 we can give a simple inductive definition of σ as follows, where ζ 0 is a fixed set of distances for base types: Notice that the definition of σ → τ stipulates that the distance between programs of type σ → τ is not just a number, but a function dt : V σ × σ → τ that morally maps a value v and an error/perturbation dv to an error/perturbation dt(v, dv).
As an example, consider the basic type R of real numbers (we employ the same notation as Example 2.5), and two values λx.t and λx.s of type R → R. As expected, we define R as [0, ∞], so that elements in R → R are functions dt : V R × [0, ∞] → [0, ∞].Now, not all such functions qualify as valid distances between λx.t and λx.s, and the purpose of a differential logical relation is precisely to tell us when dt indeed acts as a valid distance between λx.t and λx.s.Accordingly, DLRs are defined as type-indexed ternary relations following the rationale that related inputs give related outputs.But what does that mean in a differential setting?
On base types, we need to fix the defining conditions of a DLR in advance.For instance, a natural choice in our example is to stipulate The heart of DLRs is given by the inductive cases, and in particular by the one of function types.
10 Without much of a surprise, effects are handled using monads on higher-order distances.This, however, becomes clearer when employing generalised distance spaces, which will be introduced soon.

1:16
We see that dt is a valid distance between the aforementioned values λx.t and λx.s if whenever we have two values v, w at distance dv ∈ [0, ∞], then t[v/x] and s[w/x] are at distance dt(v, dv).If, for instance, we take 11 λx.x and λx.c 2 * x, then we see that the map dt(c r , ε) = |2ε − r| gives a valid distance between λx.x and λx.c 2 * x.
Notice that in DLRs distances are highly interactive and input-dependent, this way going quite far from traditional logical relations.An example of that is witnessed by the observation that programs usually have non-null self-distances.The identity combinator λx.x, for instance, has self-distance dI(v, dv) = dv, meaning that λx.x propagates distances between its inputs to its outputs. 12Nevertheless, the meta-theory of DLRs has also several similarities with the theory of traditional logical relations.The so-called fundamental lemma of DLR [DLGY19], for example, states that terms always have a valid self-distance and thus somehow resembles the (traditional) fundamental lemma of logical relations, the latter stating that any program is logically related with itself.Besides, both these fundamental lemmas are key to compositional reasoning about programs, and thus play the same role in their respective frameworks.
The just sketched theory of DLRs is rather syntactic and not very well-suited neither for meta-theoretical developments nor for extensions to richer languages, in primis those involving computational effects.For those reasons, generalised distance spaces [DLGY19,DLG22a] have been introduced as a semantic counterpart of DLRs with categorical operations between them, such as product and exponential, replacing the inductive constructions used for type constructs in the definition of a DLR.
A generalised distance space is defined as a relational structure (X, X , δ X ) with δ X ⊆ X × X × X acting as the semantic counterpart of a DLR.Such spaces form a category with morphisms between (X, X , δ X ) and (Y, Y , δ Y ) given by pairs of functions (d, df ), where f : X → Y and df : X × X → Y , such that δ X (x, dx, x ′ ) =⇒ δ Y (f (x), df (x, dx), f (x ′ )).Given this definition of arrows between generalised distance spaces, it is straightforward to define products and exponentials between such spaces.This way, we indeed see that generalised distance spaces give a semantic counterpart of DLRs.Furthermore, generalised distance spaces ease the understanding of effectful extensions of DLRs.In fact, once we have fixed a monad T on the category of sets and functions, we simply need to lift T (in the categorical sense) to the category of generalised distance spaces.
In [DLG22a] this strategy has been put into practice to define DLRs on languages with algebraic effects.The resulting notion -called a differential extension -however, is not quite a monadic lifting (not apparently, at least), as one needs to relax the latter notion to cover interesting concrete examples.Even if theoretically unsatisfactory, the notion of a differential extension seems interesting in itself, as one can extend the well-known construction of a relational extension by Barr [Bar70] to differential extensions, and the result thus obtained has a canonical flavour.
All of that suggests that differential extensions may be instances of a more general and structural construction, and that their associated notion of a Barr-like extension (also called coupling-based extension) is indeed canonical in some suitable sense.These problems have been left open in [DLG22a].Here, we show how our general notion of an operational logical 11 For readability, we use traditional λ-calculus notation rather than the fine-grained one, hence writing, e.g., λx.v in place of val (λx.val x) and λx.val x.
12 The reader familiar with program metric may have noticed some similarities between self-distances and program sensitivity [RP10].There is indeed a link, as self-distances can be seen as notions of higher-order sensitivity [DLG22a].
relation subsumes the one of a DLR (and, consequently, that the fundamental lemma of DLRs is an instance of Theorem 3.14).Additionally, we show how differential extensions are precisely liftings of monads to the fibration of differential relations and how the so-called coupling-based differential extension [DLG22a] is an instance of a general monadic lifting to such a fibration, viz. the well-known Barr lifting properly fitted to a differential setting.
4.1.Going Differential, Fibrationally.Let p : E → B be a fibration where B has finite products.We define the category dr(p) of differential relations in p as follows: objects: are triples X = (|X|, X , δ X ), where |X| and X are objects in B and δ X is an object in the fibre E |X|× X ×|X| ; It is immediate to see that dr(p) is a category.Moreover, we have three functors from dr(p) to B: Then, the arrow f can be equivalently specified by replacing Df with df .This alternative characterisation matches exactly the notion of morphism of generalised distance spaces [DLG22a], but we prefer using the other one, as it is lighter to manage.
Example 4.2.For the fibration Sub Set : s(Set ) → Set of Example 3.1, the category dr(Sub Set ) is the category of generalised distance spaces [DLG22a].An object in dr(Sub Set ) is essentially a triple (X, V, R) consisting of a set X of points, a set V of distance values, and a ternary relation R ⊆ X × V × X specifying at which distance two elements of X are related, that is, (x, v, y) ∈ R means that x and y are related at distance v or up to an error v.For instance, a metric d : X × X → [0, ∞] on X can be seen as a ternary relation This follows immediately from [Jac01, Proposition 9.2.4].We can now prove our result.
Proof of Proposition 4.6.By Remark 4.5, we know that DRel p is the composite σ B • p ′ , where p ′ is obtained by pulling back p along ∇ s : s(B) → B, where ∇ s preserves products.
For Item 1, since s(B) has finite products and p has finite products, p ′ has finite products as well.Then, since B has finite products, σ B has finite products, thus the composition σ B • p ′ has finite products too.
For Item 2, since p is a logical fibration and ∇ s preserves finite products, p ′ is a logical fibration as well.Since B is cartesian closed, by Proposition 3.8 σ B is a logical fibration.
Therefore, by Proposition 4.7, both s(B) and dr(p) are cartesian closed categories, and both σ B and p ′ preserve products and exponentials, thus the composition σ B • p ′ preserves products and exponentials as well.Hence, it remains to show that p is fibred cartesian closed.
To this end, let us fix an object I in B and consider the functor p ′ I : dr(p) → s(B) I obtained by restricting and corestricting p ′ .It is easy to see that p ′ I is a fibration that is fibred cartesian closed, as fibres and reindexing are those of p ′ .More precisely, the fibre over (I, X) in p ′ I is essentially the fibre over I × X × I in p and reindexing along an arrow (id I , f ) is given by rendixing in p along the arrow ∇ s (id I , f ) = ⟨id I , f ⟩ × id I .Therefore, given a projection (id I , π 2 ) : (I, X × Y ) → (I, X), reinexing along it is reindexing along ⟨π 1 , π 2 , π 4 ⟩ : I × X × Y × I → I × X × I in p, which has a right adjoint because p has universal quantifiers.Furthermore, this right adjoint satisfies the Beck-Chevalley condition, as ∇ s preserves pullbacks along projections.This shows that p ′ I is a logical fibration and, since s(B) I is cartesian closed as it is a fibre of σ B which is fibred cartesian closed, by Proposition 4.7, we get that dr(p) I is cartesian closed as well.
To conclude, we have to prove that the cartesian closed structure is preserved by reindexing in DRel p = σ B • p ′ .Let u : I → J be an arrow in B. Since the cartesian closed structure in the fibres dr(p) I and dr(p) J is built from the logical structure of p ′ I and p ′ J and the cartesian closed structure of s(B) I and s(B) J , to get our result it suffices to give a 1-arrow (F u , F ′ u ) : p ′ J → p ′ I where F u preserves the cartesian closed structure and F ′ u preserves the logical structure as well as cartesian arrows.We let F u : s(B) J → s(B) I be the reindexing functor along u in σ B , which maps (J, X) to (I, X).Since σ B is fibred cartesian closed, F u preserves the cartesian closed structure.The functor F ′ u : dr(p) J → dr(p) I is the reindexing functor along u in DRel p = σ B • p ′ , thus, it follows that and F ′ u preserves cartesian arrow (see [Str18] for details).More explicitly, we have F ′ u X = (I, X , u × id X × u * δ X ), for all X in dr(p) J .Therefore, the restriction of F ′ u to the fibre of p ′ J over (J, X) is essentially given by reindexing along u × id X × u in p, thus it preserves the cartesian closed structure of the fibres, as p is fibred cartesian closed.Finally, F ′ u preserves universal quantifiers thanks to the Beck-Chevalley condition in p, since the following diagram is a pullback.
We report below the explicit definition of the logical structure on DRel p .In the following, for I, J objects in the base category of p, we will write [I, J] for their exponential and ev I J : [I, J] × I → J for the associated evaluation arrow.Let X, Y, Z be objects in dr(p) with |X| = |Y| = I and |Z| = I × J, then we have: Example 4.8.Let us consider the fibration DRel Sub Set : dr(Sub Set ) → Set of set-theoretic differential relations and instantiate the above constructions in this case.The terminal object over a set X is ⊤ X = (X, 1, X × 1 × X); that is, ⊤ X has just one distance value and all elements of X are related at that value.Consider now objects X = (X, V, R) and Y = (X, U, S) in dr(Sub Set ) over the same set X.Then, their product and exponential over X are given by X ∧Y = (X, V × U, R ⊓ S) and X ⇒Y = (X, [V, U ], R → S), where That is, two elements x and y are related in R ⊓ S at a distance (v, u) if and only if x and y are at distance v in R and u in S. By contrast, x and y are related in R → S at a distance f , which transforms distances in V into distances in U , iff, whenever x and y are at distance v in R, they are at distance f (v) in S.
Finally, if Z = (X × Y, V, R) is an object in dr(Sub Set ]) over the set X × Y , then the universal quantifier on Y is given by A , where (x, f, x ′ ) ∈ Y → R, iff for all y, y ′ ∈ Y , ((x, y), f (y), (x ′ , y ′ )) ∈ R.That is, elements x and x ′ are related by Y → R at a distance f , which returns for every element of Y a distance in V , if and only if R relates (x, y) and (x ′ , y ′ ) at distance f (y), for each y, y ′ ∈ Y .
We now extend the construction of the fibration of differential relations to 1-and 2arrows.To do so, we work with bifibrations whose bases have finite products.This restriction to bifibration is not specific to our differential setting.Indeed, besides the differential flavour, our construction turns fibrations of (unary) predicates into fibrations of (ternary) relations, viewed as predicates over a product.Then, in order to accordingly transform 1-arrows, we need these assumptions to avoid requiring 1-arrows to preserve products in the base, which is a quite strong condition, especially for monads.
Let p : E → B and q : F → C be bifibrations where B and C have finite products and let K : B → C be a functor.For every object X in dr(p), we can consider the arrow pr splitting K(∇X) into three components using the images along K of certain projections.
Using cocartesian liftings of such arrows, we can split arrows in F whose image along q connects two domains of such splitting arrows.More precisely, given functors K, K ′ : B → C and objects X, Y of dr(p), for every arrow α in F and every arrow β in C such that the diagram on the right below commutes, we have a unique arrow υ β (α) in F above β making 1:21 the diagram on the left below commute as well.
Therefore, the diagram on the left lies above the one on the right through the bifibration q and the arrow υ β (α) is well-defined and uniquely determined thanks to the universal property of the cocartesian arrow pr K X A . In the following, to lighten the notation, we omit the superscript of υ β (α) when it is clear from the context.The operator υ(-) has the following key property.
Proposition 4.9.υ id (id) = id and υ Proof.This is immediate by the universal property of cocartesian arrows.Indeed, id and υ β (α) • υ β ′ (α ′ ) make the diagram on the left above commute when id and α • α ′ replace the leftmost arrow in the same diagram, respectively.
Let us now consider a 1-arrow F : p → q in biFib.We define a functor F : dr(p) → dr(q) as follows: for X an object in dr(p), we set where υ( Ḟ φ f ) is obtained as above using the following diagrams: Notice that cocartesian liftings are essential to appropriately define F on the relational part of X and f , as we do not assume any compatibility with products for F .
Proof.The equation F • DRel p = DRel q • F trivially holds by definition of F .Hence, to conclude the proof, we only have to check that F is indeed a functor from dr(p) to dr(q).Note that F (id X ) = (F id |X| , F id |X| × F id DX , υ( Ḟ id δ X )), which by functoriality of F and Ḟ and Proposition 4.9, is the identity on F X. Preservation of composition follows from a similar argument.
Similarly, let us consider a 2-arrow ϕ : F ⇒ G between 1-arrows F, G : p → q.We define a natural transformation ϕ : F .→ G as follows: for every object X in DRel p , we set where υ( φδ X ) is obtained as above using the following diagrams Proof.The fact that ϕDRel p = DRel q ϕ trivially holds by construction of ϕ.Hence, we have only to check that ϕ : F .→ G is indeed a natural transformation.To this end, let f : X → Y be an arrow in dr(p).We have to verify that ϕ Y The first two equations hold by naturality of ϕ.The third one holds because, by Proposition 4.9, both sides of the equation are equal to υ β (α) defined by the diagrams below.
The construction of ϕ respects vertical composition and identities of 2-arrows, as the following proposition shows Proposition 4.12.Let p and q be bifibrations with finite products in the base.
(1) For every 1-arrow F : p → q, we have that id : F .→ F is the identity natural transformation.
(2) For 1-arrows F, G, H : p → q and 2-arrows ϕ : F ⇒ G and ψ : G ⇒ H, we have ψϕ = ψ ϕ.A differential extension of T along the fibration p is thus a monad on the category dr(p) of differential relations in p which is above T with respect to the fibration DRel p .We now describe a way to build differential extensions of monads starting from a usual monadic extension.This is an immediate consequence of Theorem 4.13, since DR : biFib c → Fib is a lax functor and thus it preserves monads.Given a monad T = (T, µη) on a bifibration Proof.The key observation is that monads in a 2-category K can be seen as lax functors from the trivial 2-category (it has one object, one 1-arrow, and one 2-arrow) into K.Then the action of a lax functor F : K → H on a monad in K is given by composition of lax functors, which leads to the definition of DR(T).
Extending also the strength of a strong monad to differential relations is less trivial.To this end, we need to further assume that the bifibration p has finite products, so that, from Proposition 4.6(1), the fibration DRel p has finite products as well, which are necessary to talk about strong monads.We also have to assume that the product functor × on the total category of p preserves cocartesian arrows, as often happens when dealing with monoidal bifibrations [Shu08,MZ16]. 13This is a sensible requirement as the action of DR on 1-arrows heavily relies on cocartesian liftings.From a more abstract perspective, this assumption ensures that the bifibrations we are considering are precisely the cartesian objects in biFib c , thus in the following we will refer to them just as bifibrations with finite products.Then, we can prove the following result.
Theorem 4.16.Let p : E → B be a bifibration with finite products and T = (T, µ, η, st) be a strong monad on p in biFib c .Then, DR(T) is a strong monad on DRel p in Fib.
Proof.First, we notice that the lax functor DR preserves 2-products, that is, DR(p ⊗ q) is a 2-product of DR(p) and DR(q), where we use ⊗ to denote 2-products to avoid confusion with usual products.Recall from Proposition 4.6(1) that DRel p has finite products and that, for objects X, Y in dr(p), we have |X ×Y| = |X|×|Y|, X ×Y = X × Y and δ X ×Y = σ * X,Y (δ X ×δ Y ), where σ X,Y = ⟨π 1 , π 3 , π 5 , π 2 , π 4 , π 6 ⟩ is a canonical isomorphism from ∇(X ×Y) to ∇(X)×∇(Y), natural in X and Y.Note also that, δ X ×Y is vertically isomorphic to σ ′ X,Y !(δ X ×δ Y ) where σ ′ X,Y = ⟨π 1 , π 4 , π 2 , π 5 , π 3 , π 6 ⟩ is the inverse of σ X,Y .Now, given a 1-arrow T : p → p we can define 1-arrows F T , G T : p ⊗ p → p given by Then, a strength st for T in biFib c is a 2-arrow st : F T ⇒ G T in biFib c and so (st, st) : (F T , F T ) ⇒ (G T , G T ) is a 2-arrow in Fib.However, this is not a strength for (T , T ) in Fib, In other words, these results provide us with a tool for building a differential extension of a (strong) monad T on the base category of a bifibration p starting from a usual extension Ṫ along p which preserves cocartesian arrows.Therefore, to build a differential extension of T, we can use existing techniques to lift it, obtaining a monad on the bifibration p, and then apply our construction.
We conclude this section by instantiating this technique to a special class of bifibrations, namely, bifibrations of weak subobjects as defined in Example 3.3.The resulting construction applies to (strong) monads on categories with finite products and weak pullbacks, and provides a differential version of the Barr extension, that we dub a differential Barr extension.
First, we show that the construction of the bifibration of weak subobjects extends to a (strict) 2-functor.14Let us denote by Cat cwp the 2-category of categories with finite products and weak pullbacks, functors, and natural transformations. 15Given a functor

Figure 1 :
Figure 1: Syntax and static semantics of Λ Example 3.3 (Weak subobjects).Let C be a category with weak pullbacks.We define the bifibration Ψ C : ws(C ) → C of weak subobjects in C [Gra00, MR13].Let I be an object of C and denote by C /I the slice over I, that is, objects of C /I are arrows α : X → I in C and an arrow f : α → β, where α : X → I and β : Y → I are objects of C /I, is an arrow f : X → Y such that α = β • f .For α, β objects in C /I, we write α ≤ β if there exists an arrow f : α → β in C /I.This is a preorder on the objects of C /I and, like any preorder, induces an equivalence on the objects of C /I defined as follows: α ≡ β if and only if α ≤ β and β ≤ α, that is, if and only if there are arrows f : α → β and g : β → α in C /I.Then, the category ws(C ) is given as follows.Objects of ws(C ) are pairs (I, [α]) where I is an object of C and [α] is an equivalence class of objects of C /I modulo ≡ and an arrow f : (I, [α]) → (J, [β]) is an arrow f : I → J in C such that f • α ≤ β or, more explicitly, f • α = β • g for some arrow g in C .It is easy to check that this definition does not depend on the choice of representatives.Finally, composition and identities in ws(C ) are those of C .The functor Ψ C maps (I, [α]) to I and is the identity on arrows.It is easy to check that, an arrow f : Proposition 3.7 [MPR21, Prop.7.6].Let C be a category with finite products and weak pullbacks.If C is slicewise weakly cartesian closed, then the fibration of weak subobjects Ψ C is a logical fibration.Proposition 3.8 [Jac01, Exercise 1.3.2,Prop.1.9.3].If C is cartesian closed, then the simple fibration σ C is a logical fibration.

Following [ Str72a ]
, we can define (strong) monads on fibrations as (strong) monads in the 2-category Fib.That is, a monad T on a fibration p : E → B consists of the following data: • a 1-arrow T : p → p and • two 2-arrows µ : T 2 ⇒ T and η : Id ⇒ T and • such that T = (T , µ, η) is a monad on B and Ṫ = ( Ṫ , μ, η) is a monad on E. The monad Ṫ is called a lifting of the monad T along the fibration p.If p : E → B has finite products, a strong monad on p is a pair (T, st) where T = (T, µ, η) is a monad on p and (st) : (-× T -, -× Ṫ -) ⇒ (T (-× -), Ṫ (-×-)) is a 2-arrow such that (T, st) is a strong monad on B and ( Ṫ, ṡt) is a strong monad on E.

1: 25
Definition 4.14.Let p : E → B be a fibration where B has finite products, and let T = (T, µ, η) be a monad on B. A differential extension of T along p is a lifting Ṫ = ( Ṫ , μ, η) of T along the fibration DRel p : dr(p) → B.