Abstract 1 Introduction 2 From Logical Relations to Differential Logical Relations 3 Quasi-Quasi-Metric Spaces 4 Differential Logical Relations as Qq-Metrics 5 The Fundamental Lemma 6 Quasi-Metric Logical Relations 7 Partial Metric Logical Relations 8 A Quantitative Equational Theory 9 A Lattice of Qq-Metrics? 10 Related Work 11 Conclusion References Appendix A Proofs for Section 3 Appendix B Details of Cartesian Closed Structure Appendix D Proofs for Section 6 Appendix E Proofs and Observations for Section 7 Appendix F Proofs for Section 8

On the Metric Nature
of (Differential) Logical Relations

Ugo Dal Lago ORCID University of Bologna, Italy
INRIA Sophia Antipolis, France
Naohiko Hoshino ORCID Sojo University, Kumamoto, Japan Paolo Pistone ORCID Université Claude Bernard Lyon 1, France
Abstract

Differential logical relations are a method to measure distances between higher-order programs. They differ from standard methods based on program metrics in that differences between functional programs are themselves functions, relating errors in input with errors in output, this way providing a more fine grained, contextual, information. The aim of this paper is to clarify the metric nature of differential logical relations. While previous work has shown that these do not give rise, in general, to (quasi-)metric spaces nor to partial metric spaces, we show that the distance functions arising from such relations, that we call quasi-quasi-metrics, can be related to both quasi-metrics and partial metrics, the latter being also captured by suitable relational definitions. Moreover, we exploit such connections to deduce some new compositional reasoning principles for program differences.

Keywords and phrases:
Differential Logical Relations, Quantales, Quasi-Metrics, Partial Metrics
Copyright and License:
[Uncaptioned image] © Ugo Dal Lago, Naohiko Hoshino, and Paolo Pistone; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Program semantics
; Theory of computation Equational logic and rewriting
Editors:
Maribel Fernández

1 Introduction

Program equivalence is a crucial concept in program semantics, and ensures that different implementations of a program produce exactly the same results under the same conditions, i.e., in any environment. This concept is fundamental in program verification, code optimization, and for enabling reliable refactoring: by proving that two programs are equivalent, developers and compiler designers can confidently replace one with the other, knowing that the behavior and outcomes will remain consistent. In this respect, guaranteeing that the underlying notion of program equality is a congruence is of paramount importance.

In the research communities mentioned above, however, it is known that comparing programs through a notion of equivalence without providing the possibility of measuring the distance between non-equivalent programs makes it impossible to validate many interesting and useful program transformations [28]. All this has generated interest around the concepts of program metrics and more generally around the study of techniques through which to quantitatively compare non-equivalent programs, so as, e.g., to validate those program transformations which do not introduce too much of an error [31, 27].

What corresponds, in a quantitative context, to the concept of congruence? Once differences are measured by some (pseudo-)metric, a natural answer to this question is to require that any language construct does not increase distances, that is, that they are non-expansive. Along with this, the standard properties of (pseudo-)metrics, like the triangle inequality d(x,z)+d(z,y)d(x,y), provide general principles that are very useful in metric reasoning, replacing standard qualitative principles (e.g., in this case, transitivity eq(x,z)eq(z,y)eq(x,y)).

Still, as already observed in many occasions [11, 9], the restriction to language constructs that are non-expansive with respect to some purely numerical metric turns out too severe in practice. On the one hand, the literature focusing on higher-order languages has mostly restricted its attention to linear or graded languages [31, 2], due to well-known difficulties in constructing metric models for full “simply-typed” languages [12]. On the other hand, even if one restricts to a linear language, the usual metrics defined over functional types are hardly useful in practice, as they assign distances to functions f,g via a comparison of their values in the worst case: for instance, as shown in [11], the two maps λx.x,λx.sin(x):𝖱𝖾𝖺𝗅𝖱𝖾𝖺𝗅, although behaving very closely around 0, are typically assigned the distance , since their values grow arbitrarily far from each other in the worst case.

The differential logical relations [11, 9, 29, 10] have been introduced as a solution to the aforementioned problems. In this setting, which natively works for unrestricted higher-order languages, the distance between two programs is not necessarily given as a single number: for instance, two programs of functional type are far apart according to a function itself, which measures how the error in the output depends on the error in the input, but also on the value of the input itself. This way the notion of distance becomes sufficiently expressive, at the same time guaranteeing the possibility of compositional reasoning. This paradigm also scales to languages with duplication, recursion [9] and works even in presence of effects [10].

In the literature on program metrics, it has become common to consider metrics valued on arbitrary quantales [22, 36]. This means that, as for the differential logical relations, the distance between two points needs not be a non-negative real, but can belong to any suitable algebra of “quantities”. This has led to the study of different classes of quantale-valued metrics, each characterized by a particular formulation of the triangular law. Among this, quasi-metrics [19] and partial metrics [4, 23] have been explored for the study of domains, even for higher-order languages [17, 26]. While the first obey the usual triangular inequality, or transitivity, the second obey a stronger transitivity condition, also taking into account the replacement of standard reflexivity d(x,x)=0 by a weaker quasi-reflexivity condition d(x,x)d(x,y), implying that a point need not be at distance zero from itself.

A natural question is thus: do the distances between programs that are obtained via differential logical relations constitute some form of (quantale-valued) metric? In particular, what forms do transitivity and reflexivity do these relations support? The original paper [11] defined symmetric differential logical relations and gave a very weak form of triangle inequality. Subsequent works, relating to the more natural asymmetric case, have either ignored the metric question [9, 10] or shown that the distances produced must violate both the reflexivity of quasi-metric and the strong transitivity of partial metrics [17, 29].

This paper aims at providing a bridge between current methods for higher-order program differences and the well-established literature on quantale-valued metrics. More specifically, we show that the distances produced by differential logical relations, that we call quasi-quasi-metrics (or qq-metric), satisfy the quasi-reflexivity of partial metrics and the standard transitivity of quasi-metrics. Such metrics thus sit somehow in between quasi-metrics and partial metrics. We will establish precise connections between all those. We also exploit these results to deduce some new principles of compositional reasoning about program differences arising from the different forms of transitivity at play. Finally, we introduce a deductive system, inspired from the quantitative equational theories of Mardare et al. [27], to derive upper bounds on differences between programs.

Contributions.

Our contributions can be summarized as follows:

  • We introduce a new class of quantale-valued metrics, called qq-metrics. We show that each such metric gives rise to two observational quasi-metrics over programs, and can be seen as a relaxation of partial quasi-metrics [24]. This is in Section 3;

  • we establish the equivalence of the cartesian closed structure of qq-metrics with the standard definition of differential logical relations. We also show that observational quasi-metrics as well as partial quasi-metrics can be captured by suitable families of logical relations. We exploit all such definitions to deduce some new compositional reasoning principles for program differences. This spans through Sections 4-7;

  • finally, we introduce an equational theory for program differences via a syntactic presentation of differential logical relations and we formulate two conjectures about the comparison of the different notions of program distances introduced. This is in Sections 8 and 9.

We give proof details in appendices.

2 From Logical Relations to Differential Logical Relations

In this section we recall how differential logical relations can be seen as a quantitative generalization of standard logical relations, at the same time highlighting the metric counterparts of qualitative notions like equivalences and preorders. Moreover, we introduce quasi-quasi-metrics as the metric counterpart of quasi-reflexive and transitive relations. For simplicity, we identify lambda terms using the standard β-equalities throughout this section.

Logical Relations.

The theory of logical relations is well-known and has been exploited in various directions to establish qualitative properties of type systems, like e.g. termination [18], bisimulation [33] or parametricity [30, 21]. The idea is to start from some basic binary relation ρoo×o over the terms of some ground type o. The relation ρo can then be lifted to a family of binary relations ρ𝖠𝖠×𝖠, where 𝖠 varies over all simple types constructed starting from o (indeed, one may consider recursive [14], polymorphic [32, 30] or monadic [20] types as well, but we here limit our discussion to simple types). The lifting is defined inductively by:

(𝗍,𝗍)ρ𝖠×𝖡 (𝖿𝗌𝗍(𝗍),𝖿𝗌𝗍(𝗍))ρ𝖠and(𝗌𝗇𝖽(𝗍),𝗌𝗇𝖽(𝗍))ρ𝖡, ()
(𝗍,𝗍)ρ𝖠𝖡 (𝗌,𝗌𝖠)(𝗌,𝗌)ρ𝖠(𝗍𝗌,𝗍𝗌)ρ𝖡. ()

Typically, one wishes to establish a so-called fundamental lemma, stating that well-typed programs x:𝖠𝗍:𝖡 preserve relations. This means that, for any choice of a family of logical relations ρ𝖠 defined as above, one can prove

(𝗌,𝗌𝖠)(𝗌,𝗌)ρ𝖠(𝗍[𝗌/𝗑],𝗍[𝗌/𝗑])ρ𝖡. (Fundamental Lemma)

Notice that this is equivalent to the instance of reflexivity (λ𝗑.𝗍,λ𝗑.𝗍)ρ𝖠𝖡.

Of particular interest are the equivalence relations (that is, those which are reflexive, symmetric and transitive) and the preorders (that is, the reflexive and transitive ones). We here focus on the latter, as we will not consider symmetry in this paper (see Remark 3). A fundamental observation is that the logical relation lifting preserves preorders (and indeed, equivalences): if ρ𝖠 and ρ𝖡 are reflexive and transitive, then ρ𝖠×𝖡 and ρ𝖠𝖡 can be shown reflexive and transitive as well. The case of the function space crucially relies on the fact that all programs of type 𝖠𝖡 must preserve relations (or, in other words, that the fundamental lemma holds): as we observed above, the reflexivity condition (𝗍,𝗍)ρ𝖠𝖡 coincides with the fact that the function 𝗍 is relation-preserving; transitivity, instead, can be proved by combining relation-preservation, the reflexivity of ρ𝖠 and the transitivity of ρ𝖡.

Any logical relation ρ𝖠×𝖠 induces an equivalence ρ, called the observational equivalence, where 𝗍ρ𝗎 iff for all 𝗌𝖠, (𝗌,𝗍)ρ iff (𝗌,𝗎)ρ. Intuitively, two terms 𝗍,𝗎 are equivalent if the relation ρ cannot distinguish them. For example, if the definition of ρo on basic types only depends on the values 𝗍𝗏 produced by terms, one can usually deduce that terms are indistinguishable from their associated values, that is 𝗍ρ𝗏. In the absence of symmetry, one obtains two observational preorders ρl,ρr𝖠×𝖠 defined by:

𝗌ρl𝗍 (𝗎𝖠)(𝗍,𝗎)ρ(𝗌,𝗎)ρ,
𝗌ρr𝗍 (𝗎𝖠)(𝗎,𝗌)ρ(𝗎,𝗍)ρ.

These preorders satisfy the following useful and easily provable properties:

Proposition 1.

For any binary relation ρ𝖠×𝖠 and c{l,r},

  1. (i.)

    ρcρ iff ρ is transitive;

  2. (ii.)

    ρcρ iff ρ is reflexive;

  3. (iii.)

    ρc=ρ iff ρ is a preorder;

  4. (iv.)

    The following hold:

(𝗌,𝗍,𝗎𝖠)𝗌ρl𝗍(𝗍,𝗎)ρ(𝗌,𝗎)ρ, (left transitivity)
(𝗌,𝗍,𝗎𝖠)(𝗌,𝗍)ρ𝗍ρr𝗎(𝗌,𝗎)ρ. (right transitivity)

The reason why we delve into these basic properties of preorders is that we will soon explore their (less trivial!) quantitative counterparts, that arise naturally in the theory of differential logical relations. In particular, the left and right transitivity conditions will correspond to stronger variants of the triangular inequality for metric spaces.

Beyond preorders, we are interested in the following weaker notion:

Definition 2 (Quasi-Preorder).

A relation 𝖠×𝖠 is called a quasi-preorder if it is transitive and (left-)quasi-reflexive, that is, 𝗍𝗎𝗍𝗍.

Quasi-preorders are obtained by weakening the reflexivity condition of preorders: intuitively, only the points which are smaller than someone are smaller than themselves. One can easily develop a theory of logical relations for quasi-preorders. The sole delicate point is that, in order to let such relations lift to function spaces, one has to slightly modify the relation lifting as follows:

(𝗍,𝗍)ρ𝖠𝖡 (𝗌,𝗌𝖠)(𝗌,𝗌)ρ𝖠(𝗍𝗌,𝗍𝗌)ρ𝖡(𝗍𝗌,𝗍𝗌)ρ𝖡. (q)

Compared to (2), (q) includes a second clause (𝗍𝗌,𝗍𝗌)ρ𝖡 relating the action of 𝗍 on both 𝗌 and 𝗌. With this definition, one can easily check that if ρ𝖠,ρ𝖡 are quasi-preorders, and the fundamental lemma holds, then ρ𝖠×𝖡 and ρ𝖠𝖡 are quasi-preorders as well.

Differential Logical Relations.

We now have all elements to discuss what happens when extending logical relations to a quantitative setting. Rather than considering binary relations ρ𝖠×𝖠 expressing that a certain property holds for two terms 𝗌,𝗍 or not, we will consider ternary relations ρ𝖠×𝒬𝖠×𝖠, where (𝗌,a,𝗍)ρ indicates that a certain relation holds of 𝗌,𝗍 to a certain extent, quantified via a𝒬𝖠. Here 𝒬𝖠 is a quantale, an algebraic structure (recalled in the next section) that captures several properties of quantities as expressed by e.g. non-negative real numbers.

In fact, just like for standard logical relations, a differential logical relation ρoo×𝒬o×o on a ground type can be lifted to a family of binary relations ρ𝖠𝖠×𝒬𝖠×𝖠 over simple types. First, we define, by induction, the quantales 𝒬𝖠×𝖡=𝒬𝖠×𝒬𝖡 and 𝒬𝖠𝖡=𝖠(𝒬𝖠𝒬𝖡), where 𝒬𝖠𝒬𝖡 is the quantale of monotone functions, and 𝖠𝒬𝖠𝒬𝖡 is the quantale of functions from the set of closed terms of type 𝖠 to 𝒬𝖠𝒬𝖡 equipped with the pointwise order. We then define the lifting of ρo by:

((𝗍,𝗎),(a,b),(𝗍,𝗎))ρ𝖠×𝖡 (𝗍,a,𝗍)ρ𝖠and(𝗎,b,𝗎)ρ𝖠,
(𝗍,f,𝗍)ρ𝖠𝖡 (𝗌,𝗌𝖠,a𝒬𝖠) if (𝗌,a,𝗌)ρ𝖠, then
(𝗍𝗌,f(𝗌)(a),𝗍𝗌)ρ𝖡 and (𝗍𝗌,f(𝗌)(a),𝗍𝗌)ρ𝖡.

Notice that the definition of ρ𝖠𝖡 closely imitates the clause (q) for quasi-preorders. Also observe that the quantale 𝒬𝖠𝖡 for the function type is itself a set of functions relating terms of type 𝖠 and quantities in 𝒬𝖠 with quantities in 𝒬𝖡. As we show in Section 5, this definition gives rise to an interpretation of the simply typed λ-calculus where a fundamental lemma holds under the following form: for all terms x:𝖠𝗍:𝖡 and choice of a family of differential logical relations ρ𝖠 as above, there exists a map 𝗍:𝖠(𝒬𝖠𝒬𝖡) such that

(𝗌,𝗌𝖠,a𝒬𝖠)(𝗌,a,𝗌)ρ𝖠(𝗍𝗌,𝗍(𝗌)(a),𝗍𝗌)ρ𝖡. (fundamental lemma)

The function 𝗍 behaves like some sort of derivative of 𝗍: it relates errors in input with errors in output. This connection is investigated in more detail in [9, 29].

So far, everything works just as in the standard, qualitative, case. However, the quantitative setting is well visible when we consider the corresponding notions of equivalences and preorders. Recall that an (integral) quantale is, in particular, an ordered monoid (𝒬,+,0,) of which 0 is the minimum element. For a differential logical relation ρ𝖠×𝒬𝖠×𝖠, reflexivity, symmetry and transitivity translate into the following conditions:

(𝗍𝖠) (𝗍,0,𝗍)ρ, (reflexivity)
(𝗍,𝗎𝖠,a𝒬𝖠) (𝗍,a,𝗎)ρ(𝗎,a,𝗍)ρ, (symmetry)
(𝗌,𝗍,𝗎𝖠,a,b𝒬𝖠) (𝗌,a,𝗍)ρ(𝗍,b,𝗎)ρ(𝗌,a+b,𝗎)ρ. (transitivity)

It is clear then that equivalence relations translate, in the quantitative setting, into some kind of metric space. Similarly, the quantitative counterpart of preorders are the so-called quasi-metric spaces [19], essentially, metrics without a symmetry condition, indeed a very well-studied class of metrics. In particular, we will show that, similarly to preorders, any ternary relation ρ𝖠×𝒬𝖠×𝖠 gives rise to left and right observational quasi-metrics ρl,ρr:𝖠×𝖠𝒬𝖠 satisfying properties analogous to those of Proposition 1.

 Remark 3.

While in the original definition [11] differential logical relations were symmetric, symmetry was abandoned in all subsequent works. The first reason is that several interesting notions of program difference, like e.g. those arising from incremental computing [9, 6, 1], are not symmetric. A second reason is that the cartesian closure is problematic in presence of both quasi-reflexivity and symmetry [29].

There is, however, an important point on which differential logical relations differ from standard logical relations: while the former lift preorders well to all simple types, their quantitative counterpart, the quasi-metrics, are not preserved by the higher-order lifting of differential logical relations. Indeed, we observed that an essential ingredient in the lifting of the reflexivity property is the fundamental lemma; yet, in the framework of differential logical relations, the fundamental lemma produces, for any term 𝗍:𝖠𝖡, the “reflexivity” condition (𝗍,𝗍,𝗍)ρ𝖠𝖡, which differs from standard reflexivity in that the distance is 𝗍 and not the minimum element 0. This means that the metric structure arising from differential logical relation cannot be that of standard (quasi-)metric spaces. Rather, it must be something close to the partial metric spaces [4, 23], that is, metric spaces in which the condition d(x,x)=0 is replaced by the quasi-reflexivity condition d(x,x)d(x,y). We will discuss the connections with partial metric spaces in the next sections.

By replacing reflexivity with quasi-reflexivity, we obtain the quantitative counterpart of quasi-preorders, that we call qq-metrics (being “quasi” both in the sense of quasi-metrics, i.e. the rejection of symmetry, and of quasi-preorders, i.e. the weakening of reflexivity).

Definition 4.

For a set X and a quantale 𝒬, a relation ρX×𝒬×X is called quasi-quasi-metric (or more concisely qq-metric) if it is transitive and satisfies the condition

(x,yX,a𝒬)(x,a,y)ρ(x,a,x)ρ. (quasi-reflexivity)

As shown in Section 4, the qq-metrics capture the properties of distances which are preserved by differential logical relations: indeed, the argument showing that the quasi-preorders lift to all simple types scales well to the quantitative setting, showing that a qq-metric on the base types gives rise to qq-metrics on all simple types.

The obvious question, however, is: what are these qq-metrics? How are they related to the more standard quasi-metrics and partial metrics? This is what we are going to do in the following section.

3 Quasi-Quasi-Metric Spaces

In this section we use the language of quantale-valued relations to explore the connections between the qq-metrics introduced in the previous section and the more well-established notions of quasi-metric and partial quasi-metric spaces.

Quantale-Valued Relations.

Let us recall that a quantale 𝒬 is a complete lattice (𝒬,) endowed with a continuous monoidal operation , with unit 1. Here, being continuous means that both x() and ()x preserve arbitrary suprema for all xQ. A quantale 𝒬 is integral (cf. [22], p. 148) when 1= and commutative when is commutative. Suppose 𝒬 is commutative. Given x,y𝒬, their residual is defined as xy:={z𝒬zxy} where is the partial order of 𝒬. Notice that zxy iff zxy, and that (xy)xyx(yx). A commutative quantale 𝒬 is divisible [23] if for all x,y𝒬, xy holds iff y(yx)=x. Equivalently, 𝒬 is divisible iff, whenever xy, there exists z such that x=yz. In the following we will use 𝒬 to refer to a commutative, integral and divisible quantale.

Example 5.

The Lawvere quantale is formed by the non-negative extended reals [0,+] with the reversed order xy:=xy, and with addition as monoidal operation. Notice that the ordering of quantales is reversed with respect to usual metric intuitions: the “0” element is the , joins correspond to taking infs, etc.

Given a quantale 𝒬 and sets X,Y, a 𝒬-relation over X,Y is a map s:X×Y𝒬, which can be visualized as a matrix with values in 𝒬. For 𝒬-relations s,t:X×Y𝒬, we write st when s(x,y)t(x,y) for all xX and yY. Given 𝒬-relations s:X×Y𝒬, t:Y×Z𝒬 and u:X×Z𝒬, w:Z×Y𝒬, we define the 𝒬-relations st:X×Z𝒬 and us:Z×Y𝒬 and sw:X×Z𝒬 via the two operations:

(st)(x,z) =yYs(x,y)t(y,z),
(us)(z,y) =xXu(x,z)s(x,y),(sw)(x,z)=yYw(z,y)s(x,y).

The monoidal product and the residuals , of 𝒬-relations satisfy properties analogous to residuals in 𝒬, e.g. s(st)t, (ts)st. It is well-known that 𝒬-relations form a category 𝒬Rel whose objects are sets and such that 𝒬Rel(X,Y) are the 𝒬-relations from X to Y. The operation st is the composition operator of this category, while the identities are the relations defined as 𝟏X(x,x)=1= and 𝟏X(x,yx)=.

Finally, for any relation s𝒬𝐑𝐞𝐥(X,X), define the relations Δ1s,Δ2s𝒬𝐑𝐞𝐥(X,X) by Δ1s=sΔπ1 and Δ2s=sΔπ2, that is, Δ1s(x,y):=s(x,x), Δ2s(x,y)=s(y,y).

Qq- and Quasi-Metric Spaces.

For a relation s𝒬Rel(X,X), reflexivity s(x,x)=1 and transitivity s(x,z)s(z,y)s(x,y) can be written more concisely as s𝟏X and sss. A relation s satisfying both such properties is called a quasi-(pseudo)metric (or a hemi-metric) over X (with values in 𝒬). The “pseudo” prefix stands for the fact that the usual separation property s(x,y)=1x=y needs not hold. As we do not investigate separation here, all metric notions discussed in the rest of the paper are to be understood as implicitly “pseudo”.

The following construction generalizes the observational preorders to 𝒬-relations:

Proposition 6.

For all s𝒬𝐑𝐞𝐥(X,X), the relations sl:=ss,sr:=ss𝒬𝐑𝐞𝐥(X,X) are quasi-metrics and, for c{l,r}, the following hold:

  1. (i.)

    scs iff s is transitive;

  2. (ii.)

    scs iff s is reflexive;

  3. (iii.)

    sc=s iff s is a quasi-metric;

  4. (iv.)

    slss and ssrs, that is, the following hold:

(x,y,zX)sl(x,z)s(z,y) s(x,y), (left transitivity)
(x,y,zX)s(x,z)sr(z,y) s(x,y). (right transitivity)

We call the quasi-metrics sl,sr the left and right observational quasi-metric of s.

Qq-metrics correspond to 𝒬-relations s𝒬𝐑𝐞𝐥(X,X) satisfying transitivity sss and quasi-reflexivity sΔ1s (i.e. s(x,y)s(x,x)). From transitivity, we deduce that, for a qq-metric s, both sl,srs hold, that is, the observational quasi-metrics yield tighter distances than s. This implies that left and right transitivity read as stronger forms of the triangular inequality. In particular, the following alternative characterization of qq-metrics holds:

Proposition 7.

For any quasi-reflexive s𝒬𝐑𝐞𝐥(X,X), s is a qq-metric iff there exists a quasi-metric qs such that either sqs or qss holds. Furthermore, when s is a qq-metric, both sl and sr are quasi-metrics.

Qq- and Partial Metric Spaces.

Let us now discuss the connection with partial metric spaces. We here consider the non-symmetric variant of the partial metric spaces from [4], called partial quasi-metric spaces (PQM) [24]. As we anticipated, these are metrics p for which the usual reflexivity condition p(x,x)=1 is replaced by the weaker quasi-reflexivity condition p(x,x)p(x,y). However, unlike the qq-metrics just discussed, PQMs satisfy a stronger transitivity condition. When 𝒬=[0,+] is the Lawvere quantale, this condition reads as

p(x,z)+p(z,y)p(z,z)p(x,y). (strong transitivity in [0,+])

The idea is that the self-distance of the central term z is “subtracted”. For a general quantale 𝒬, this becomes:

p(x,z)(p(z,z)p(z,y))p(x,y). (strong transitivity)

Define the relations Θsl,Θsr𝒬𝐑𝐞𝐥(X,X) by Θsl(x,y)=s(y,y)s(x,y) and Θsr(x,y)=s(x,x)s(x,y). A PQM can be thus more concisely be defined as a relation s𝒬𝐑𝐞𝐥(X,X) satisfying sΔ1s and sΘsrs. Notice that strong transitivity sΘsrs looks similar to the right transitivity sqsrs. Indeed, the following result relates the relations Θsc and sc:

Proposition 8.

For all s𝒬𝐑𝐞𝐥(X,X) and c{l,r}, scΘsc. Moreover, if s is quasi-reflexive, Θscsc holds iff Θsc is a quasi-metric iff s is a partial quasi-metric.

The result above suggests that the partial quasi-metrics can be seen as limit cases of the qq-metrics, namely those for which the quasi-metric sr(x,y) can be written under the simpler form Θsr(x,y)=s(x,x)s(x,y).

Unfortunately, while the standard definition of differential logical relations preserves qq-metrics, it does not preserve partial quasi-metrics: [17, 29] show that the function space constructions lifts PQMs into PQMs only when the monoidal product of the underlying quantales is idempotent (one talks in this case of a partial ultra-metric, since strong transitivity becomes p(x,z)p(z,y)p(x,y)). Nevertheless, we will show in Section 7 how one can capture PQMs via a suitable family of logical relations.

4 Differential Logical Relations as Qq-Metrics

In this section we provide a semantic presentation of differential logical relations by defining a cartesian closed category of qq-metrics, this way highlighting the close correspondence between these two notions.

From 𝓠-Relations to Ternary Relations.

While in the previous section we discussed 𝒬-relations, that is, binary relations valued in a quantale 𝒬, the theory of differential logical relations is expressed in terms of ternary relations ρX×𝒬×X. In fact, any such relation ρX×𝒬×X induces a 𝒬-relation ρ^𝒬𝐑𝐞𝐥(X,X) defined by

ρ^(x,y)={a𝒬(x,a,y)ρ}.

Intuitively, ρ^(x,y) is the smallest (recall the inversion of the order) distance between x and y. This correspondence can be made more precise as follows: a ternary relation ρX×𝒬×X be said to be 𝒬-closed when the following hold:

  • (x,a,y)ρ and aa implies (x,a,y)ρ;

  • if (x,ai,y)ρ, for all iI, then (x,iIai,y)ρ.

We will use 𝒬-closedness to derive results in Section 6.

In Appendix A (Lemma 21), we show that the map ρρ^ defines a bijection between the 𝒬-closed relations ρX×𝒬×X and 𝒬𝐑𝐞𝐥(X,X). In the sequel, we will identify metrics with their corresponding 𝒬-closed relations.

A Cartesian Closed Category of Qq-Metrics.

We now define a category of qq-metrics. Let us recall notations from Section 2. For sets A and B, we denote the set of functions from A to B by AB; for quantales 𝒬 and , we denote the set of monotone functions from 𝒬 to by 𝒬. Below, we write fx for the application of f:AB to xA, and we suppose that ()() is left-associative, i.e., fxy is an abbreviation of (fx)y.

The category 𝐐𝐪𝐦 of qq-metrics is defined as follows:

  • objects are triples X=(𝒬X,|X|,ρX) consisting of a quantale 𝒬X, a set |X| and a qq-metric ρX|X|×𝒬X×|X|;

  • morphisms from X to Y are triples (f,a,f) consisting of functions f,f:|X||Y| and a:|X|(𝒬X𝒬Y) such that for all (x,b,x)ρX, we have (fx,axb,fx)ρY and (fx,axb,fx)ρY.

The identity morphism on an object X is (idX,iX,idX) consisting of the identity function idX on |X| and a function iX:|X|(𝒬X𝒬X) given by iXxa=a. The composition of (f,a,f):XY and (g,b,g):YZ is (gf,c,gf) where c:|X|(𝒬X𝒬Z) is given by cx=(b(fx))(ax).

Proposition 9.

The category 𝐐𝐪𝐦 is cartesian closed.

The cartesian closed structure closely matches the construction of differential logical relations in Section 2. The terminal object is ({},{},ρ) where ρ={(,,)}, and the product of X and Y is X×Y=(𝒬X×𝒬Y,|X|×|Y|,ρX×Y), where ρX×Y is given by

((x,y),(a,b),(x,y))ρX×Y(x,a,x)ρX and (y,b,y)ρY.

The exponential XY is given by (|X|(𝒬X𝒬Y),|X||Y|,ρXY) where

(f,a,f)ρXYfor all (x,b,x)ρX and g{f,f},(fx,axb,gx)ρY.

Here, the quantale structure of 𝒬X×Y and 𝒬XY are given by the pointwise manner. We give details of the cartesian closed structure in Appendix B.

Example 10.

We define an object R𝐐𝐪𝐦 to be (,[0,+],ρR), where

(x,a,x)ρR|xx|a.

Observe that the distance ρ^R:×[0,+] is just the Euclidean distance ρ^R(x,y)=|yx|. For functions f,g:, an element a𝒬RR satisfies (f,a,g)ρRR if and only if we have axb|xy|b|fxgy|, i.e., a bounds gaps between outputs of f and g. In particular, we have (f,,f)ρRR if and only if f is a constant function. We note that the largest element 𝒬RR is given by xb=0.

5 The Fundamental Lemma

In this section we establish the fundamental lemma of differential logical relations for a simply typed lambda calculus Λ𝖱𝖾𝖺𝗅, by relying on the cartesian closed category 𝐐𝐪𝐦 of qq-metrics. We then apply this result to measure differences between functions.

Syntax and Set-theoretic Semantics.

Our language Λ𝖱𝖾𝖺𝗅 comprises a type of real numbers and first order functions on . Let 𝖵𝖺𝗋 be a countably infinite set of variables. We define types and terms as follows:

(type) 𝖠,𝖡 𝖱𝖾𝖺𝗅𝖠×𝖡𝖠𝖡,
(term) 𝗍,𝗌 𝗑𝖵𝖺𝗋r¯ϕ(𝗍1,,𝗍n)𝗍𝗌λ𝗑:𝖠.𝗍𝗍,𝗌𝖿𝗌𝗍(𝗍)𝗌𝗇𝖽(𝗌).

Here, r varies over , and ϕ varies over the set of multi-arity functions on , namely, ϕ is a function from n to for some n. We call n the arity of ϕ, and we denote the arity of ϕ by ar(ϕ). We adopt the standard typing rules given in Figure 1. Below, we denote the set of types by 𝐓𝐲𝐩𝐞 and the set of closed terms of type 𝖠 by 𝐓𝖠.

Figure 1: Typing Rules.

We denote the standard set theoretic interpretation of Λ𝖱𝖾𝖺𝗅 by . (See [25] for example.) To be concrete, the interpretation 𝖠 of a type 𝖠 is a set inductively defined by

𝖱𝖾𝖺𝗅=,𝖠×𝖡=𝖠×𝖡,𝖠𝖡=𝖠𝖡;

and we interpret a term 𝗑1:𝖠1,,𝗑n:𝖠n𝗍:𝖡 as a function 𝗍 from 𝖠1××𝖠n to 𝖡. We give the definition of 𝗍 in Appendix C.

The Fundamental Lemma.

We inductively define a qq-metric space 𝖠 by

𝖱𝖾𝖺𝗅=R,𝖠×𝖡=𝖠×𝖡,𝖠𝖡=𝖠𝖡.

Here, R is the qq-metric given in Example 10. Below, we simply denote the structure of an object 𝖠 by (𝒬𝖠,|𝖠|,ρ𝖠). It is straightforward to check that for every type 𝖠, we have |𝖠|=𝖠. The qq-metrics 𝖠 are the categorical interpretation of types 𝖠, and the following fundamental lemma is derived from the categorical interpretation of Λ𝖱𝖾𝖺𝗅-terms in 𝐐𝐪𝐦.

Theorem 11 (Fundamental Lemma).

Let Γ=(𝗑1:𝖠1,,𝗑n:𝖠n) be a typing context. For every term Γ𝗍:𝖠, and for every (x,a,x)ρ𝖠1××𝖠n, we have

(𝗍x,{|𝗍|}xa,𝗍x)ρ𝖠

where we inductively define {|𝗍|}𝒬𝖠1××𝖠n𝖡 as follows:

  • We define {|𝗑i|}(x1,,xn)(a1,,an) to be ai.

  • We define {|r¯|}xa to be 0¯.

  • We define {|ϕ(𝗍1,,𝗍n)|}xa to be ϕd(𝗍1x,,𝗍nx,{|𝗍1|}xa,,{|𝗍n|}xa) where we define ϕd:n×[0,+]n[0,+] by

    ϕd(y1,,yn,b1,,bn)=|y1z1|b1|ynzn|bn|ϕ(y1,,yn)ϕ(z1,,zn)|.
  • We define {|𝗍𝗌|}xa to be {|𝗍|}xa(𝗌x)({|𝗌|}xa).

  • We define {|λ𝗑:𝖠.𝗍|}(x1,,xn)(a1,,an)yb to be {|𝗍|}(x1,,xn,y)(a1,,an,b).

  • We define {|𝗍,𝗌|}xa to be ({|𝗍|}xa,{|𝗌|}xa).

  • We define {|𝖿𝗌𝗍(𝗍)|}xa to be the first component of {|𝗍|}xa.

  • We define {|𝗌𝗇𝖽(𝗍)|}xa to be the second component of {|𝗍|}xa.

The fundamental lemma is a way to compositionally reason about distances.

Example 12.

Let us fix a positive real number ϵ. We define Dϵ:()() by

Dϵ=λ𝖿:𝖱𝖾𝖺𝗅𝖱𝖾𝖺𝗅.λ𝗑:𝖱𝖾𝖺𝗅.dfϵ(f(adϵ(𝗑)),f(𝗑))

where dfϵ(x,y)=xyϵ and adϵ(x)=x+ϵ. For f: and x, Dϵfx calculates an approximation of the derivative of f at x:

Dϵfx=f(x+ϵ)f(x)ϵ.

By the fundamental lemma, we obtain (Dϵ,Eϵ,Dϵ)ρ(RR)(RR) where Eϵ is a function from |RR| to 𝒬RR𝒬RR given by

Eϵfa=λx:.λb:[0,+].a(x+ϵ)b+axbϵ.

We note that Eϵ depends on our choice of term denoting Dϵ. In Example 15, we will observe that (id,a,sin) is an element of ρRR where id is the identity function on , and a𝒬RR is given by axb=|xsin(x)|+b. By applying (Dϵ,Eϵ,Dϵ) to (id,a,sin), we obtain (Dϵid,a,Dϵsin)ρR where

axb=|x+ϵsin(x+ϵ)|+|xsin(x)|+2bϵ.

From this, we see that the distance between Dϵid0 and Dϵsin0 is bounded by |ϵsin(ϵ)|ϵ. We note that a is not the exact distance between Dϵid and Dϵsin. For example, while |D0.1id0D0.1sin0.1|0.01, we have a00.12. This gap stems in the fact that (Dϵ,Eϵ,Dϵ) takes all functions into account and cannot exploit continuity of specific functions.

6 Quasi-Metric Logical Relations

As described in Section 3, any qq-metric gives rise to left and right observational quasi-metrics. In this section, we introduce a class of logical relations γ𝖠 that capture the left observational quasi-metric associated to ρ𝖠. We will then show how such relations can be used to derive over-approximations of distances between functions.

For a type 𝖠, we define γ𝖠|𝖠|×𝒬𝖠×|𝖠| by induction on 𝖠 as follows:

(x,a,x)γ𝖱𝖾𝖺𝗅 |xx|a,
(f,a,f)γ𝖠𝖡 for all (x,b,x)ρ𝖠,(fx,axb,fx)γ𝖡, and
for all (f,b,f)ρ𝖠𝖡,(f,ab,f)ρ𝖠𝖡,
((x,y),(a,b),(x,y))γ𝖠×𝖡 (x,a,x)γ𝖠 and (y,b,y)γ𝖡.

We give some explanation on the definition of γ𝖠𝖡. The definition consists of two conditions. The first condition means that, if (f,a,f) is an element of γ𝖠𝖡, then the distance axb over-approximates the distance between f and f at the same point x (rather than on distinct points, as is the case for the relation ρ𝖠𝖡). The second condition means that a also over-approximates the gap between the self-distance of f and the self-distance of f.

Recall that ρ𝖠l is the quasi-metric representing the left observational quasi-metrics associated with the qq-metric ρ𝖠. In Appendix D, we give some auxiliary lemmas and proofs for Proposition 13 and Theorem 14.

Proposition 13.

For every type 𝖠, we have ρ𝖠l=γ𝖠.

We can use Proposition 13 to over-approximate ρ-distances in terms of γ-distances and the left observational quasi-metric. Let us sketch our idea. First, thanks to Proposition 13 and Proposition 6, we can exploit left-transitivity to pass from a γ-distance between 𝗍 and 𝗌 and a self-ρ-distance of 𝗌 to a ρ-distance between 𝗍 and 𝗌:

(𝗍,a,𝗌)γ𝖠and(𝗌,b,𝗌)ρ𝖠(𝗍,ab,𝗌)ρ𝖠. (left transitivity)

Second, thanks to the fundamental lemma, we can always obtain a ρ-distance by summing a γ-distance with the self-distance {|𝗌|}:

(𝗍,a,𝗌)γ𝖠(𝗍,a{|𝗌|},𝗌)ρ𝖠. (ργ self-ρ)

The following result exploits this last idea to bound the distance between two functions f and g by summing the “vertical distance” between f and g (that is, the distance of f(x) and g(x) for some fixed x) with an approximation of the self-distances of f and g:

Theorem 14.

Let 𝖠 be a type. For any f,f|𝖠𝖱𝖾𝖺𝗅| and any a,a𝒬𝖠𝖱𝖾𝖺𝗅, if

  • |fxfx|axb for all (x,b,x)ρ𝖠; and

  • (f,a,f)ρ𝖠𝖱𝖾𝖺𝗅 and (f,a,f)ρ𝖠𝖱𝖾𝖺𝗅,

then (f,aa,f)ρ𝖠𝖱𝖾𝖺𝗅.

Example 15.

Let id be the identity function on . By the fundamental lemma with a simple calculation, we obtain (id,a,id)ρRR and (sin,a,sin)ρRR where axb=b. By Theorem 14, a𝒬RR given by axb=|xsin(x)| satisfies (id,aa,sin)ρRR. To be concrete, (aa)xb=|xsin(x)|+b, which means that the distance between x and sin(y) is small when x and y are close to 0.

 Remark 16.

Due to asymmetry in the definition of the exponential XY in 𝐐𝐪𝐦, it is not clear how to capture the right observational quasi-metrics in a similar manner. However, we will see that right observational quasi-metrics can be captured by partial metric logical relations introduced in the next section.

7 Partial Metric Logical Relations

As discussed in Section 3, the qq-metrics ρ𝖠 are not, in general, partial metrics. In this section we introduce a family of differential logical relations (η𝖠)𝖠𝖳𝗒𝗉𝖾𝗌 that defines a class of partial quasi-metrics over Λ𝖱𝖾𝖺𝗅. The fundamental (indeed, the only) difference with respect to the family ρ𝖠 is, as it may be expected, in the case of the function type.

For any type 𝖠, we define η𝖠|𝖠|×𝒬𝖠×|𝖠| by induction on 𝖠 as follows:

(x,a,x)η𝖱𝖾𝖺𝗅 |xx|a,
(f,a,f)η𝖠𝖡 there are a1,a2𝒬𝖠𝖡 such that a1a2a and
for all (x,b,x)η𝖠,(fx,a1xb,fx)η𝖡 and
(fx,a2xb,fx)η𝖡,
((x,y),(a,b),(x,y))η𝖠×𝖡 (x,a,x)η𝖠 and (y,b,y)η𝖡.

The idea of the definition of η𝖠𝖡 is that if (f,a,f)η𝖠𝖡, then a must be larger than or equal to the sum of the self-distance of f and of the “vertical” distances between f and f. The following result shows that the relations η𝖠 define partial quasi-metrics on all types.

For (f,a,f)η𝖠𝖡, we call a pair a1,a2𝒬𝖠𝖡 satisfying the condition in the definition of (f,a,f)η𝖠𝖡 a decomposition of (f,a,f)η𝖠𝖡.

Proposition 17.

For all types 𝖠:

  • For any type 𝖠, the relation ρ𝖠 is 𝒬-closed. In particular, for all (x,a,x)η𝖠, the set of decompositions of (x,a,x)η𝖠 is a complete lattice.

  • If (x,a,x)η𝖠, then (x,a,x)η𝖠.

  • If (x,a,z)η𝖠 and (z,b,y)η𝖠, then there exists c1,c2𝒬𝖠 such that abc1c2, (z,c1,z)η𝖠 and (x,c2,y)η𝖠. In particular, (x,a(c1b),y)η𝖠.

By adapting the definition of γ𝖠 from Section 6, we can capture the left observational quasi-metrics ρ𝖠l associated with the partial quasi-metrics η𝖠. Moreover, by Proposition 8, the right observational quasi-metric ρ𝖠r satisfies (x,η^𝖠(x,x)a,y)ρ𝖠r(x,a,y)η𝖠. Thanks to this, we can capture this quasi-metrics via the logical relations δ𝖠|𝖠|×𝒬𝖠×|𝖠| defined by induction on 𝖠, letting the base and product case being defined as for γ𝖠, and the function case being as follows:

(f,a,f)δ𝖠𝖡 for all (f,b,f)η𝖠𝖡,(f,ab,f)η𝖠𝖡.
Proposition 18.

For every type 𝖠, we have ρ𝖠r=δ𝖠.

8 A Quantitative Equational Theory

The goal of this section is to introduce an equational theory to formally deduce differences between programs. To this end, we first give a syntactic presentation of differential logical relations internally to the language of Λ𝖱𝖾𝖺𝗅, and then introduce a deductive system to deduce program differences.

While our idea is inspired by the quantitative equational theories of Mardare et al. [27], it differs in two respects: first, distances need not be real numbers, but are presented as arbitrary Λ𝖱𝖾𝖺𝗅-programs; second, non-expansiveness is replaced by the condition corresponding to the fundamental lemma of differential logical relations.

Preparation.

Before we go into construction, we prepare some syntactic counter parts of constructions in the fundamental lemma for 𝐐𝐪𝐦. We first inductively define a type 𝖠 by

𝖱𝖾𝖺𝗅=𝖱𝖾𝖺𝗅,(𝖠𝖡)=𝖠𝖠𝖡,(𝖠×𝖡)=𝖠×𝖡.

This is a syntactic counter part of quantales 𝒬𝖠. The reason that we define 𝖱𝖾𝖺𝗅 to be 𝖱𝖾𝖺𝗅 even though 𝖱𝖾𝖺𝗅 should be a type of non-negative extended real numbers is to keep the syntax of Λ𝖱𝖾𝖺𝗅 simple. It is possible to extend Λ𝖱𝖾𝖺𝗅 with a type 𝖱𝖾𝖺𝗅0 of non-negative extended real numbers and types 𝖠𝖡 of monotone functions. We next give a syntactic counter part of {|𝗍|}. For this purpose, we suppose that there is a partition 𝖵𝖺𝗋=𝖵𝖺𝗋0𝖵𝖺𝗋1, i.e., there are mutually disjoint subsets 𝖵𝖺𝗋0,𝖵𝖺𝗋1𝖵𝖺𝗋 such that 𝖵𝖺𝗋 is equal to 𝖵𝖺𝗋0𝖵𝖺𝗋1. Furthermore, we suppose that there is a bijection ()˙:𝖵𝖺𝗋0𝖵𝖺𝗋1. In the sequel, we denote variables in 𝖵𝖺𝗋1 by dotted symbols 𝗑˙,𝗒˙,𝗓˙,, and we denote variables in 𝖵𝖺𝗋0 by 𝗑,𝗒,𝗓,. Based on this convention, for a typing context Γ=(𝗑1:𝖠1,,𝗑n:𝖠n), we define a typing context Γ by Γ=(𝗑˙1:𝖠1,,𝗑˙n:𝖠n). Now, for a term Γ𝗍:𝖠, we define a term Γ,Γ𝗍:𝖠, which we call the derivative of 𝗍, in Figure 2. The definition of 𝗍 corresponds to the definition of {|𝗍|}, and we can find the same construction in [9].

Figure 2: Derivative of Term.

Syntactic Differential Logical Relations.

By adopting the structure of 𝐐𝐪𝐦, we define a type-indexed family {δ𝖠log𝐓𝖠×𝐓𝖠×𝐓𝖠}𝖠𝐓𝐲𝐩𝐞 of ternary predicates as follows:

(𝗍,𝖺,𝗍)δ𝖱𝖾𝖺𝗅log there are r,r and s[0,+] such that |rr|s and
𝗍=r¯:𝖱𝖾𝖺𝗅 and 𝖺=s¯:𝖱𝖾𝖺𝗅 and 𝗍=r¯:𝖱𝖾𝖺𝗅,
(𝗍,𝖺,𝗍)δ𝖠𝖡log for any (𝗌,𝖻,𝗌)δ𝖠log,(𝗍𝗌,𝖺𝗌𝖻,𝗍𝗌)δ𝖡log and (𝗍𝗌,𝖺𝗌𝖻,𝗍𝗌)δ𝖡log,
(𝗍,𝖺,𝗍)δ𝖠×𝖡log (𝖿𝗌𝗍(𝗍),𝖿𝗌𝗍(𝖺),𝖿𝗌𝗍(𝗍))δ𝖠log and (𝗌𝗇𝖽(𝗍),𝗌𝗇𝖽(𝖺),𝗌𝗇𝖽(𝗍))δ𝖡log

where we write Γ𝗍=𝗌:𝖠 when the equality between Γ𝗍:𝖠 and Γ𝗌:𝖠 is derivable from the standard equational theory consisting of βη-equalities extended with the following axiom for every multi-arity function ϕ:

Γϕ(r1¯,,rar(ϕ)¯)=ϕ(r1,,rar(ϕ))¯:𝖱𝖾𝖺𝗅.

Although 𝐓𝖠 is not a quantale in general, we can show that δ𝖠log satisfies “left quasi-reflexivity”, “transitivity” and a fundamental lemma in the following form.

Proposition 19.

Let 𝖠 be a type.

  • If (𝗍,𝖺,𝗍)δ𝖠log, then (𝗍,𝖺,𝗍)δ𝖠log.

  • If (𝗍,𝖺,𝗍)δ𝖠log and (𝗍,𝖺,𝗍′′)δ𝖠log, then (𝗍,𝖺𝖽𝖽𝖠𝖺𝖺,𝗍′′)δ𝖠log where 𝖺𝖽𝖽𝖱𝖾𝖺𝗅𝐓𝖱𝖾𝖺𝗅𝖱𝖾𝖺𝗅𝖱𝖾𝖺𝗅 is the binary addition, and 𝖺𝖽𝖽𝖠𝐓𝖠𝖠𝖠 for arbitrary type 𝖠 is inductively given by

    𝖺𝖽𝖽𝖠𝖡 =λ𝗑𝗒:𝖠𝖡.λ𝗓:𝖠.𝖺𝖽𝖽𝖡(𝗑𝗓)(𝗒𝗓),
    𝖺𝖽𝖽𝖠×𝖡 =λ𝗑𝗒:𝖠×𝖡.𝖺𝖽𝖽𝖠𝖿𝗌𝗍(𝗑)𝖿𝗌𝗍(𝗒),𝖺𝖽𝖽𝖡𝗌𝗇𝖽(𝗑)𝗌𝗇𝖽(𝗒).
  • For any term 𝗑1:𝖠1,,𝗑n:𝖠n𝗍:𝖠, and for any family {(𝗌i,𝖺i,𝗌i)δ𝖠ilog}1in,

    (𝗍[𝗌1/𝗑1,,𝗌n/𝗑n],𝗍[𝗌1/𝗑1,,𝗌n/𝗑n,𝖺1/𝗑˙1,,𝖺n/𝗑˙n],𝗍[𝗌1/𝗑1,,𝗌n/𝗑n])δ𝖠log.
  • If (𝗍,𝖺,𝗍)δ𝖠log and 𝗍=𝗌:𝖠 and 𝖺=𝖻:𝖠 and 𝗍=𝗌:𝖠, then (𝗌,𝖻,𝗌)δ𝖠log.

Equational Metric.

We introduce a formal system to infer δlog-distances between terms. For terms Γ𝗍:𝖠 and Γ,Γ𝖺:𝖠 and Γ𝗍:𝖠, we write Γ(𝗍,𝖺,𝗍):𝖠 when we can derive this judgment from the rules given in Figure 3 where in the derivation rule for an n-ary function ϕ on , D(ϕ) is a set of 2n-ary functions on given by ψD(ϕ) if and only if for all triples of reals (ri,ri,si)1in, if |riri|si for any i{1,,n}, then |ϕ(r1,,rn)ϕ(r1,,rn)|ψ(r1,,rn,s1,,sn). The last rule in Figure 3 makes the judgement compatible with the equational theory for terms. Then, we define a type-indexed ternary predicate {δ𝖠eq𝐓𝖠×𝐓𝖠×𝐓𝖠}𝖠𝐓𝐲𝐩𝐞 by

(𝗍,𝖺,𝗍)δ𝖠eq(𝗍,𝖺,𝗍):𝖠.

We note that quasi-reflexivity and transitivity for arbitrary 𝖠 follows from left quasi-reflexivity and transitivity for 𝖱𝖾𝖺𝗅. We can also show that δeq is subsumed by δlog. We can check the following proposition by induction on types.

Proposition 20.

Let 𝖠 be a type.

  • If (𝗍,𝖺,𝗍)δ𝖠eq, then (𝗍,𝖺,𝗍)δ𝖠eq.

  • If (𝗍,𝖺,𝗍)δ𝖠eq and (𝗍,𝖺,𝗍′′)δ𝖠eq, then (𝗍,𝖺𝖽𝖽𝖠𝖺𝖺,𝗍′′)δ𝖠eq.

  • For any term 𝗑1:𝖠1,,𝗑n:𝖠n𝗍:𝖠, and for any family {(𝗌i,𝖺i,𝗌i)δ𝖠ieq}1in,

    (𝗍[𝗌1/𝗑1,,𝗌n/𝗑n],𝗍[𝗌1/𝗑1,,𝗌n/𝗑n,𝖺1/𝗑˙1,,𝖺n/𝗑˙n],𝗍[𝗌1/𝗑1,,𝗌n/𝗑n])δ𝖠eq.
  • If (𝗍,𝖺,𝗍)δ𝖠eq, then (𝗍,𝖺,𝗍)δ𝖠log.

Figure 3: Derivation Rules.

9 A Lattice of Qq-Metrics?

We conclude our presentation with a few open questions about the relations holding between the different notions of program difference introduced in this paper. It is well-known that different notions of program equivalence for a given language can be compared, with one equivalence being coarser than another one when it identifies more programs than the other. Under this ordering, program equivalences do indeed form a complete lattice, with observational equivalences usually being the coarsest ones, and those arising from syntactic equational theories being the finest ones.

In the last sections we have introduced various notions of program differences, all defined in terms of some form of differential logical relations. Could it be possible to compare such program differences similarly to what can be done for program equivalences? Notably, the following two natural questions can be raised:

  • Does the type indexed family δlog give rise to the “coarsest family of qq-metrics”?

  • Does the type indexed family δeq give rise to the “finest family of qq-metrics”?

We note that, although such differences are defined over 𝐓𝖠, which is not a quantale, we can easily associate δlog and δeq with qq-metrics valued on the quantale 𝒫𝐓𝖠 of subsets of 𝐓𝖠, letting e.g. (𝗍,a,𝗍)δ~𝖠logfor all 𝖺a,(𝗍,𝖺,𝗍)δ𝖠log, and similarly for δ𝖠eq.

Unfortunately, it is not straightforward to tackle these questions because of two main obstacles. First, while two qq-metrics valued over the same quantale can be easily compared, it is not clear how to compare two qq-metrics defined over different quantales. Second, while in the case of logical relations, the argument that logical equivalence is the coarsest one relies on the notion of observational equivalence, it is not clear how to define a similar notion of observational qq-metric for Λ𝖱𝖾𝖺𝗅: since differences between programs describe relationships between differences of inputs and differences of outputs, when we measure differences between programs, we should observe differences between outputs of programs with respect to different contexts. Therefore, we should define a notion of difference between contexts before we define observational qq-metric for Λ𝖱𝖾𝖺𝗅. How can we define differences between contexts?

10 Related Work

Differential logical relations for a simply typed language were introduced in [11], and later extended to languages with monads [10], and related to incremental computing [9]. Moreover, a unified framework for operationally-based logical relations, subsuming differential logical relations, was introduced in [7]. The connections with metric spaces and partial metric spaces have been explored already in [17, 29], on the one hand providing a series of negative results that motivate the present work, and on the other hand producing a class of metric and partial metric models based on a different relational construction.

The literature on the interpretation of linear or graded lambda-calculi in the category of metric spaces and non-expansive functions is ample [31, 15, 2, 16, 13]. A related approach is that of quantitative algebraic theories [27], which aims at capturing metrics over algebras via an equational presentation. These have been extended both to quantale-valued metrics [8] and to the simply typed (i.e. non graded) languages [12], although in the last case the non-expansivity condition makes the construction of interesting algebras rather challenging.

The literature on partial metric spaces is vast, as well. Introduced by Matthews [4], they have been largely explored for the metrization of domain theory [5, 34, 35] and, more recently, of λ-theories [26]. An elegant categorical description of partial metrics via the quantaloid of diagonals is introduced in [23]. As this construction is obviously related to the notion of quasi-reflexivity here considered, it would be interesting to look for analogous categorical descriptions of the qq-metrics here introduced.

11 Conclusion

In this paper we have explored the connections between the notions of program distance arising from differential logical relations and those defined via quasi-metrics and partial quasi-metrics. As discussed in Section 9, our results suggest natural and important questions concerning the comparison of all the notions of distance considered in this paper. At the same time, our results provide a conceptual bridge that could be used to exploit methods and results from the vast area of research on quantale-valued relations [22, 36] for the study of program distances in higher-order programming languages. For instance, natural directions are the characterization of limits and, more generally, of topological properties via logical relations, as suggested by recent work [3], although in a qualitative setting.

While we here focused on non-symmetric differential logical relations, understanding the metric structure of the symmetric case, as in [11], would be interesting as well. Notice that this would require to abandon quasi-reflexivity, cf. Remark 3.

Finally, while in this paper we only considered simple types, the notion of qq-metric is robust enough to account for other constructions like e.g. monadic types as in [10]. It is thus natural to explore the application of methods arising from quasi-metrics or partial quasi-metrics for the study of languages with effects like e.g. probabilistic choice.

References

  • [1] Mario Alvarez-Picallo, Alex Eyers-Taylor, Michael Peyton Jones, and C.-H. Luke Ong. Fixing incremental computation. In Luís Caires, editor, Proc. of ESOP 2019, pages 525–552. Springer, 2019.
  • [2] Arthur Azevedo de Amorim, Marco Gaboardi, Justin Hsu, Shin-ya Katsumata, and Ikram Cherigui. A semantic account of metric preservation. In Proc. of POPL 2017, pages 545–556. ACM, 2017. doi:10.1145/3009837.3009890.
  • [3] Gilles Barthe, Raphaëlle Crubillé, Ugo Dal Lago, and Francesco Gavazzo. On Feller continuity and full abstraction. Proc. ACM Program. Lang., 6(ICFP), August 2022. doi:10.1145/3547651.
  • [4] Michael Bukatin, Ralph Kopperman, Steve Matthews, and Homeira Pajoohesh. Partial metric spaces. American Mathematical Monthly, 116:708–718, October 2009. doi:10.4169/193009709X460831.
  • [5] Michael A. Bukatin and Joshua S. Scott. Towards computing distances between programs via Scott domains. In Sergei Adian and Anil Nerode, editors, Proc. of LFCS 1997, pages 33–43. Springer, 1997. doi:10.1007/3-540-63045-7_4.
  • [6] Yufei Cai, Paolo G. Giarrusso, Tillmann Rendel, and Klaus Ostermann. A theory of changes for higher-order languages: incrementalizing λ-calculi by static differentiation. In Proc. of PLDI 2014, pages 145–155. ACM, 2014. doi:10.1145/2594291.2594304.
  • [7] Francesco Dagnino and Francesco Gavazzo. A fibrational tale of operational logical relations: Pure, effectful and differential. Logical Methods in Computer Science, 20(2), April 2024. doi:10.46298/lmcs-20(2:1)2024.
  • [8] Fredrik Dahlqvist and Renato Neves. A complete v-equational system for graded lambda-calculus. In Marie Kerjean and Paul Blain Levy, editors, Proc. of MFPS XXXIX, volume 3 of EPTICS, 2023. doi:10.46298/ENTICS.12299.
  • [9] Ugo Dal Lago and Francesco Gavazzo. Differential logical relations, Part II increments and derivatives. Theoretical Computer Science, 895:34–47, 2021. doi:10.1016/J.TCS.2021.09.027.
  • [10] Ugo Dal Lago and Francesco Gavazzo. Effectful program distancing. Proc. ACM Program. Lang., 6(POPL), January 2022. doi:10.1145/3498680.
  • [11] Ugo Dal Lago, Francesco Gavazzo, and Akira Yoshimizu. Differential logical relations, part I: the simply-typed case. In Proc. of ICALP 2019, volume 132 of LIPIcs, pages 111:1–111:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2019. doi:10.4230/LIPICS.ICALP.2019.111.
  • [12] Ugo Dal Lago, Furio Honsell, Marina Lenisa, and Paolo Pistone. On Quantitative Algebraic Higher-Order Theories. In Proc. of FSCD 2022, volume 228 of LIPIcs, pages 4:1–4:18, Dagstuhl, Germany, 2022. doi:10.4230/LIPIcs.FSCD.2022.4.
  • [13] Ugo Dal Lago, Naohiko Hoshino, and Paolo Pistone. On the Lattice of Program Metrics. In Proc. of FSCD 2023, volume 260 of LIPIcs, pages 20:1–20:19, Dagstuhl, Germany, 2023. doi:10.4230/LIPIcs.FSCD.2023.20.
  • [14] Derek Dreyer, Amal Ahmed, and Lars Birkedal. Logical step-indexed logical relations. In Proc. of LICS 2009, pages 71–80. IEEE, 2009. doi:10.1109/LICS.2009.34.
  • [15] Marco Gaboardi, Andreas Haeberlen, Justin Hsu, Arjun Narayan, and Benjamin C. Pierce. Linear dependent types for differential privacy. SIGPLAN Not., 48(1):357–370, January 2013. doi:10.1145/2480359.2429113.
  • [16] Francesco Gavazzo. Quantitative behavioural reasoning for higher-order effectful programs: Applicative distances. In Proc. of LICS 2018, pages 452–461. ACM, 2018. doi:10.1145/3209108.3209149.
  • [17] Guillaume Geoffroy and Paolo Pistone. A partial metric semantics of higher-order types and approximate program transformations. In Proc. of CSL 2021, volume 183 of LIPIcs, pages 35:1–35:18, 2021. doi:10.4230/LIPIcs.CSL.2021.23.
  • [18] Jean-Yves Girard, Yves Lafont, and Paul Taylor. Proofs and Types, volume 7 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 1989.
  • [19] Jean Goubault-Larrecq. Non-Hausdorff Topology and Domain Theory: Selected Topics in Point-Set Topology. New Mathematical Monographs. Cambridge University Press, 2013.
  • [20] Jean Goubault-Larrecq, Slawomir Lasota, and David Nowak. Logical relations for monadic types. In Proc. of CSL 2002, pages 553–568. Springer, 2002. doi:10.1007/3-540-45793-3_37.
  • [21] Claudio Hermida, Uday S. Reddy, and Edmund P. Robinson. Logical relations and parametricity - A Reynolds programme for category theory and programming languages. In Proc. of WACT 2013, volume 303 of ENTCS, pages 149–180. Elsevier, 2014. doi:10.1016/J.ENTCS.2014.02.008.
  • [22] Dirk Hofmann, Gavin J Seal, and W Tholen. Monoidal Topology: a Categorical Approach to Order, Metric and Topology. Cambridge University Press, New York, 2014.
  • [23] Dirk Hofmann and Isar Stubbe. Topology from enrichment: the curious case of partial metrics. Cahiers de Topologie et Géométrie Différentielle Catégorique, LIX, 4:307–353, 2018.
  • [24] H.-P.A. Künzi, H. Pajoohesh, and M.P. Schellekens. Partial quasi-metrics. Theoretical Computer Science, 365(3):237–246, 2006. doi:10.1016/j.tcs.2006.07.050.
  • [25] Roy L.Crole. Categories for Types. Cambridge University Press, 1993.
  • [26] Valentin Maestracci and Paolo Pistone. The Lambda Calculus Is Quantifiable. In Proc. of CSL 2025, volume 326 of LIPIcs, pages 34:1–34:23. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. doi:10.4230/LIPIcs.CSL.2025.34.
  • [27] Radu Mardare, Prakash Panangaden, and Gordon Plotkin. Quantitative algebraic reasoning. In Proc. of LICS 2016. IEEE Computer Society, 2016.
  • [28] Sparsh Mittal. A survey of techniques for approximate computing. ACM Comput. Surv., 48(4), March 2016. doi:10.1145/2893356.
  • [29] Paolo Pistone. On generalized metric spaces for the simply typed lambda-calculus. In Proc. of LICS 2021, pages 1–14. IEEE, 2021. doi:10.1109/LICS52264.2021.9470696.
  • [30] Gordon Plotkin and Martin Abadi. A logic for parametric polymorphism. In Proc. of TLCA 1993, volume 664 of LNCS, pages 361–375. Springer, 1993. doi:10.1007/BFB0037118.
  • [31] Jason Reed and Benjamin C. Pierce. Distance makes the types grow stronger. Proc. of ICFP 2010, pages 157–168, 2010.
  • [32] John C. Reynolds. Types, abstraction and parametric polymorphism. In R.E.A. Mason, editor, Information Processing ’83, pages 513–523. North-Holland, 1983.
  • [33] Davide Sangiorgi, Naoki Kobayashi, and Eijiro Sumii. Logical bisimulations and functional languages. In Farhad Arbab and Marjan Sirjani, editors, Proc. of FSEN 2007, pages 364–379. Springer, 2007. doi:10.1007/978-3-540-75698-9_24.
  • [34] Michel P. Schellekens. A characterization of partial metrizability: domains are quantifiable. Theoretical Computer Science, 305(1-3):409–432, 2003. doi:10.1016/S0304-3975(02)00705-3.
  • [35] Michael B. Smyth. The constructive maximal point space and partial metrizability. Ann. Pure Appl. Log., 137(1-3):360–379, 2006. doi:10.1016/j.apal.2005.05.032.
  • [36] Isar Stubbe. An introduction to quantaloid-enriched categories. Fuzzy Sets and Systems, 256:95–116, 2014. doi:10.1016/j.fss.2013.08.009.

Appendix A Proofs for Section 3

Proof of Proposition 7.

Suppose there exists a quasi-metric qs such that sqs holds. Then sssqs, so s is transitive. A similar argument works if q is such that qss. Conversely, if s is a qq-metric it is enough to let q:=sr and use Proposition 6 (iv).

Proof of Proposition 8.

We only argue for c=r, the other case being similar. From sr(x,y)=zs(z,x)s(z,y)s(x,x)s(x,y)=(Θsr)(x,y) we deduce that srΘsr. The converse direction srΘsr corresponds to showing that s(z,x)(s(x,x)s(x,y))s(z,y), which holds iff s is a partial quasi-metric. We have thus shown that s is a PQM iff Θsr=sr. This also implies that, if s is a PWM, Θsr is a quasi-metric. Finally, suppose Θsr is a quasi-metric. By quasi-reflexivity, and the divisibility of 𝒬, we have that s(x,z)=s(x,x)(s(x,x)s(x,z)). We then have s(x,z)(s(z,z)s(z,y))=s(x,x)(s(x,x)s(x,z))(s(z,z)s(z,y))s(x,y), so s is a partial quasi-metric.

Lemma 21.

The map ρρ^ defines a bijection between the 𝒬-closed relations ρX×𝒬×X and 𝒬𝐑𝐞𝐥(X,X).

Proof.

Let ρ,τ be closed and let ρ^(x,y)=τ^(x,y). Observe that, for all x,yX, by 𝒬-closure we have (x,ρ^(x,y),y)ρ. Suppose now that (x,a,y)τ, then aτ^(x,y)=ρ^(x,y), and from (x,ρ^(x,y),y)ρ and aρ^(x,y) we deduce (x,a,y)ρ. By a similar argument we can also prove that (x,a,y)ρ implies (x,a,y)τ, so in the end ρ=τ. We conclude then that the map ρρ^ is injective. For surjectivity, observe that any s𝒬𝐑𝐞𝐥(X,X) induces a relation (x,a,y)ρs iff as(x,y), so that s=ρs^.

Appendix B Details of Cartesian Closed Structure

The first projection from X×Y to Y is given by (projX,Y,ϖX,Y,projX,Y) consisting of the first projection projX,Y:|X|×|Y||X| and ϖX,Y:|X|×|Y|(𝒬X×𝒬Y𝒬X) given by ϖX,Y(x,y)(a,b)=a. The second projection is given in the same manner. The tupling of (f,a,f):ZX and (g,b,g):ZY is (f,g,a,b,f,g) where f,g:|Z||X|×|Y| and a,b:|Z|(𝒬Z𝒬X×𝒬Y) are the tupling of f,g and a,b respectively, that is, f,gz is defined to be (fz,gz), and a,bzc is defined to be (azc,azc). The currying of (f,a,f):Z×XY is (f,a,f) where f:|Z|(|X||Y|) and f:|Z|(|X||Y|) are the currying of f:|Z|×|X||Y| and f:|Z|×|X||Y|, and a:|Z|(𝒬Z𝒬XY) is the currying of a:|Z|×|X|(𝒬Z×X𝒬Y), namely, azaxb is defined to be a(z,x)(a,b). The evaluation morphism (evalX,Y,εX,Y,evalX,Y):(XY)×XY consists of the evaluation function evalX,Y:(|X||Y|)×|X||Y| and εX,Y is given by εX,Y(a,b)(f,x)=axb.

Appendix C Definitions and Proofs for Section 5

In Figure 4, we define the function 𝗍 by induction on the type derivation of t.

𝗑i(x1,,xn) =xi,
r¯(x1,,xn) =r,
ϕ(𝗍1,,𝗍ar(ϕ))(x1,,xn) =ϕ(𝗍1(x1,,xn),,𝗍ar(ϕ)(x1,,xn)),
𝗍𝗌(x1,,xn) =𝗍(x1,,xn)(𝗌(x1,,xn)),
λ𝗑:𝖠.𝗍(x1,,xn)y =𝗍(x1,,xn,y),
𝖿𝗌𝗍(𝗍)(x1,,xn) =the first component of 𝗍(x1,,xn),
𝗌𝗇𝖽(𝗍)(x1,,xn) =the second component of 𝗍(x1,,xn),
𝗍,𝗌(x1,,xn) =(𝗍(x1,,xn),𝗌(x1,,xn)).
Figure 4: Set Theoretic Denotation of Terms.

Proof of Theorem 11.

The triple (𝗍,{|𝗍|},𝗍) is the interpretation of Γ𝗍:𝖠 in the cartesian closed category 𝐐𝐪𝐦 where we interpret Γϕ(𝗍1,,𝗍n) by

𝖠1××𝖠n𝗍1,,𝗍nR××R(ϕ,ϕd,ϕ)R.

The statement follows from that (𝗍,{|𝗍|},𝗍) is a morphism from 𝖠1××𝖠n to 𝖠 in 𝐐𝐪𝐦.

Appendix D Proofs for Section 6

Let us introduce a notation. For a type 𝖠 and x|𝖠|, we write x𝒬𝖠 for ρ𝖠^(x,x), i.e., x is equal to sup{a𝒬𝖠(x,a,x)ρ𝖠}. Since ρ𝖠 is closed under supremum, for any x|𝖠|, we have (x,x,x)ρ𝖠.

Lemma 22.

For every type 𝖠 and for every x,x|𝖠|, if (x,x,x)ρ𝖠, then x=x.

Proof.

By induction on 𝖠. It is straightforward to check the case 𝖱𝖾𝖺𝗅 and the case 𝖠×𝖡. For the case 𝖠𝖡, if (f,f,f)ρ𝖠𝖡, then for any x|𝖠|, we have

(fx,fxx,fx)ρ𝖠.

Here, by the induction hypothesis,

fxx =sup{a𝒬𝖡for all (x,x,x)ρ𝖠,(fx,a,fx)ρ𝖡}
=sup{a𝒬𝖡(fx,a,fx)ρ𝖡}=fx.

Hence, fx=fx.

Lemma 23.

For any type 𝖠 and 𝖡, if f|𝖠𝖡| and x|𝖠|, then fxx=fx.

Proof.

This is shown in the proof of Lemma 22.

Lemma 24.

For every type 𝖠, if (x,ax,x)ρ𝖠, then (x,a,x)γ𝖠.

Proof.

By induction on 𝖠. The only non-trivial case is 𝖠𝖡. If (f,af,f)ρ𝖠𝖡, then for any (x,b,x)ρ𝖠, since (x,bx,x)ρ𝖠, we obtain

(fx,(ax(bx))(fx(bx)),fx)ρ𝖡.

It follows from monotonicity of a and Lemma 23 that we have

(fx,(axb)(fxx),fx)=(fx,(axb)fx,fx)ρ𝖡.

By the induction hypothesis, we conclude (fx,axb,fx)γ𝖡. For any (f,b,f)ρ𝖠𝖡, since bf, it follows from (f,af,f)ρ𝖠𝖡 that (f,ab,f)ρ𝖠𝖡. By left-quasi-reflexivity, we obtain (f,ab,f)ρ𝖠𝖡.

Proof of Proposition 13.

We first show that γ𝖠 is a subset of ρ𝖠l by induction on 𝖠. It is straightforward to check the case 𝖱𝖾𝖺𝗅 and the case 𝖠×𝖡. We check the case 𝖠𝖡. Let (f,a,f) be an element of γ𝖠𝖡, and let (f,a,f′′) be an element of ρ𝖠𝖡. We show that (f,aa,f′′) is an element of ρ𝖠𝖡. For any (x,b,x)ρ𝖠, since (x,b,x)ρ𝖠, we have

(fx,axb,fx)γ𝖡,(fx,axb,f′′x)ρ𝖡.

Hence, by the induction hypothesis, we see that (fx,(aa)xb,f′′x) is an element of ρ𝖡. It remains to check that (fx,(aa)xb,fx) is an element of ρ𝖡. Since (f,a,f′′)ρ𝖠𝖡, we have (f,a,f)ρ𝖠𝖡. Then, by the definition of γ𝖠𝖡, we obtain (f,aa,f)ρ𝖠𝖡. Hence, (fx,(aa)xb,fx) is an element of ρ𝖡. We next show that ρ𝖠l is a subset of γ𝖠. Again, it is straightforward to check the case 𝖱𝖾𝖺𝗅 and the case 𝖠×𝖡. We check the case 𝖠𝖡. Let (f,a,f) be an element of ρ𝖠𝖡l, and let (x,b,x) be an element of ρ𝖠. Since (f,af,f)ρ𝖠𝖡 and (x,x,x)ρ𝖠, we obtain

(fx,(axx)(fxx),fx)=(fx,(axx)fx,fx)ρ𝖡

Hence, by Lemma 24, (fx,axx,fx) is an element of ρ𝖡. Since a is monotone, for any (x,b,x)ρ𝖠, we have (fx,axb,fx)ρ𝖡. If (f,b,f)ρ𝖠𝖡, then by the definition of ρ𝖠𝖡l, we obtain (f,ab,f)ρ𝖠𝖡.

Proof of Theorem 14.

By the definition of γ𝖠𝖱𝖾𝖺𝗅, we obtain

(f,a(ff),f)γ𝖠𝖱𝖾𝖺𝗅.

Therefore, it follows from Proposition 13 that

(f,a(ff)f,f)ρ𝖠𝖱𝖾𝖺𝗅.

Since (f,a,f)ρ𝖠𝖱𝖾𝖺𝗅 and (f,a,f)ρ𝖠𝖱𝖾𝖺𝗅, we have a(ff)f. Hence, (f,aa,f)ρ𝖠𝖱𝖾𝖺𝗅.

Appendix E Proofs and Observations for Section 7

Proof of Proposition 17.

We can check the first clause and the second clause by induction on 𝖠. We only prove the third, more delicate, statement. By induction on 𝖠, we show that there is a map φ𝖠:𝒬𝖠×𝒬𝖠𝒬𝖠×𝒬𝖠 such that if (x,a,z)η𝖠 and (z,b,y)η𝖠, then (c1,c2)=φ𝖠(a,b) satisfies the required conditions. For the base case, we define φ𝖱𝖾𝖺𝗅(a,b)=(0,a+b). For the case 𝖠=(𝖡𝖢), let (a1,a2)𝒬𝖡𝖢×𝒬𝖡𝖢 and (b1,b2)𝒬𝖡𝖢×𝒬𝖡𝖢 be the greatest decompositions of a and b, respectively. We define φ𝖡𝖢(a,b) by

φ𝖡𝖢(a,b)=(a1k,b1l)

where (kwd,lwd)=φ𝖢(a2wd,b2wd). Below, we write (c1,c2) for φ𝖡𝖢(a,b). Let us check that φ𝖡𝖢 is a witness.

  • We first show that (z,c1,z)η𝖡𝖢. For any (w,d,w)η𝖡, we have

    (xw,a2wd,zw)η𝖢, (1)
    (zw,b1wd,zw)η𝖢, (2)
    (zw,b2wd,yw)η𝖢. (3)

    Then, by applying the induction hypothesis to (1) and (3), we obtain

    (zw,kwd,zw)η𝖢. (4)

    By (2) and (4), we obtain (z,c1,z)η𝖡𝖢.

  • We next show that (x,c2,y)η𝖡𝖢. For any (w,d,w)η𝖡, we have

    (xw,a1wd,xw)η𝖢, (5)
    (xw,a2wd,zw)η𝖢, (6)
    (zw,b2wd,yw)η𝖢. (7)

    By applying the induction hypothesis to (6) and (7), we obtain

    (xw,lwd,yw)η𝖢. (8)

    By (5) and (8), we obtain (x,c2,y)η𝖡𝖢.

  • Finally, we have

    (c1wd)(c2wd) =(a1wd)(kwd)(b1wd)(lwd)
    (a1wd)(a2wd)(b1wd)(b2we)
    (awd)(bwd).

Proof of Proposition 18.

The only interesting case is that of a function type 𝖠=𝖡𝖢. By Proposition 8, (f,a,f)ρ𝖠r holds iff for all aq^𝖠r(f,f)=q^𝖠r(f,f)q^𝖠r(f,f), which is in turn equivalent to aq^𝖠r(f,f)q^𝖠r(f,f). This implies then that (f,a,f)ρ𝖠r iff for all (f,b,f)ρ𝖠r (i.e. for all bq^𝖠r(f,f)), (f,ab,f)ρ𝖠r (i.e. abq^𝖠r(f,f)), that is, iff (f,a,f)δ𝖠.

Appendix F Proofs for Section 8

Proof of Proposition 19.

We prove the statement by induction on 𝖠. We only check the case 𝖠𝖡. It is straightforward to derive “left-quasi-reflexivity” from the definition of δ𝖠𝖡log. This is why we modify the definition of differential logical relation given in [11]. For transitivity, we shall show that for any (𝗍,𝖺,𝗍)δ𝖠log, (𝗍,𝖺,𝗍′′)δ𝖠log and (𝗌,𝖻,𝗌)δ𝖠log, we have (𝗍𝗌,(𝖺+𝖺)𝖻𝗌,𝗍′′𝗌)δ𝖡log. By the induction hypothesis, we obtain (𝗌,𝖻,𝗌)δ𝖠log. Therefore,

(𝗍𝗌,𝖺𝖻𝗌,𝗍𝗌)δ𝖡log,(𝗍𝗌,𝖺𝖻𝗌,𝗍′′𝗌)δ𝖡log.

Then, by transitivity of δ𝖡log, we obtain (𝗍𝗌,(𝖺+𝖺)𝖻𝗌,𝗍′′𝗌)δ𝖡log. We can prove the fundamental lemma by induction on the derivation of Γ𝗍:𝖡.