Cost-sensitive computational adequacy of higher-order recursion in synthetic domain theory

Yue Niu    Jonathan Sterling    Robert Harper Computer Science Department
Carnegie Mellon University
Pittsburgh, USA
Department of Computer Science and Technology
University of Cambridge
Cambridge, United Kingdom
Abstract

We study a cost-aware programming language for higher-order recursion dubbed PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in the setting of synthetic domain theory (SDT). Our main contribution relates the denotational cost semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT to its computational cost semantics, a new kind of dynamic semantics for program execution that serves as a mathematically natural alternative to operational semantics in SDT. In particular we prove an internal, cost-sensitive version of Plotkin’s computational adequacy theorem, giving a precise correspondence between the denotational and computational semantics for complete programs at base type. The constructions and proofs of this paper take place in the internal dependent type theory of an SDT topos extended by a phase distinction in the sense of Sterling and Harper. By controlling the interpretation of cost structure via the phase distinction in the denotational semantics, we show that PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT programs also evince a noninterference property of cost and behavior. We verify the axioms of the type theory by means of a model construction based on relative sheaf models of SDT.

keywords:
compositional cost analysis, domain theory, synthetic domain theory, type theory, PCF
volume: NNjournal: Electronic Notes in Theoretical Informatics and Computer Sciencevolume: NNthanks: Email: \normalshape[email protected]thanks: Email: \normalshape[email protected]thanks: Email: \normalshape[email protected]

Acknowledgements. This work was funded by the United States Air Force Office of Scientific Research under grants FA9550-23-1-0728111Dr. Tristan Nguyen, Program Manager, MURI FA9550-21-0009Footnote 1, FA9550-21-1-0385Footnote 1 and the National Science Foundation under grant CCF-1901381. We thank Tristan Nguyen at AFOSR for support. Yue Niu was supported by the Air Force Research Laboratory through the NDSEG fellowship. Views and opinions expressed are however those of the authors only and do not necessarily reflect those of AFOSR, AFRL, or NSF.

1 Introduction

In 1977 Plotkin [22] introduced a programming language for higher-order recursion, PCF, and defined computational adequacy, a fundamental notion relating the denotational and operational semantics of a programming language in terms of the computational behavior of closed programs of ground type. Since Plotkin’s seminal work, computational adequacy has been developed and refined to tailor various programming features and is an important property in the context of denotational approaches to program verification, enabling one to bring familiar mathematical structures and equational reasoning to bear on problems regarding program behavior. One refinement takes place in both the arrangement and metatheory of the semantics. In one direction, when the ambient category in which the model is defined has sufficient logical structure, one may view the object programming language from an internal perspective, a situation that was first thoroughly developed in the context of synthetic domain theory [11, 20]. In the other direction, one may move to a constructive metatheory such as the internal languages of generic elementary topoi or guarded type theory. The transition to these constructive, internal versions of computational adequacy has several benefits. First, by working inside topoi or type theories, one is automatically equipped with a powerful logical language to reason directly about domains and the denotational semantics, which was one of the original motivations for the development of synthetic domain theory. Second, the constructive nature of the metatheory means that one can argue that computationally adequate denotational semantics can be directly executed, as observed by De Jong [2] in his work on constructive domain theory.

Computational adequacy in cost analysis. More recently, Niu and Harper [17] identified another application of internal adequacy in the context of cost analysis in calf [18], a type theory in which cost is reified as a computational effect and cost analysis takes the form of equational reasoning. A natural question in this setting is the relationship between the abstract cost bounds specified and proved in calf and the concrete bounds derived with respect to traditional operationally-based cost models. Viewing calf as a semantic universe for internal denotational semantics, Niu and Harper [17] determined a criterion justifying the adequacy of an abstract calf cost model with respect to operational semantics by means of a cost-sensitive refinement of computational adequacy, which they instantiate using a variant of the Algol programming language, which featured higher-order (total) functions, first-order store and while loops.

1.1 Motivations

The aim of the present work is to extend the results of Niu and Harper [17] to full higher-order recursion by combining their ideas with synthetic domain theory, culminating in a type theory for computing with generalized spaces that support cost instrumentation alongside an information order for recursion.

1.1.1 Types as generalized spaces

The type theoretic philosophy is to study a real phenomenon in terms of abstract interfaces rendered as types; type theoretic terms, then, correspond precisely to constructions in this discourse that preserve the geometrical and topological structure at play. For example, in synthetic domain theory (SDT), types have an intrinsic topology with respect to which all functions are continuous. By adhering to an abstract interface, the type-theoretic viewpoint brings to the fore the essential logical/geometric structure of underlying objects of interest and suppresses ill-defined objects and transformations, which makes it possible to define and reason about the domain of discourse in a conceptually simple manner that is completely rigorous.

Orthogonal to the topological and order-theoretic aspects of types as spaces in synthetic domain theory, we shall impose a different kind of geometric structure called a phase distinction. Originating in the theory of program modules and logical relations [9, 31], a phase distinction can generally refer to any situation in which types represent indexed structures. For example, a program module can be represented as a family of dynamic runtime components whose “shape” is determined/indexed by a static module signature; similarly, a logical relation of a type theory can be represented as a family of computability data indexed in a syntactic type. In this work, we are concerned with a similar kind of phase distinction called the intension-extension phase distinction, introduced by Niu et al. [18] to enable simultaneous reasoning about both the cost and extensional behavior of programs.

The geometric aspect of phase distinctions emerges through two operations, restriction and sealing, that manipulate types to either trivialize the fibers or the base of the indexed structure represented by a given type. In the present case, these two operations are used to implement a form of cost profiling semantics for programs that can be easily “stripped away” via restriction, enabling one to simultaneously and faithfully carry out cost analysis in one framework; we shall describe this in mathematical terms in Section 1.2.1.

In this paper we combine the intension-extension phase distinction of Niu et al. [18] with the domain-theoretic structure of SDT to obtain an intrinsically cost-sensitive theory of higher-order recursion in type theory. There are two main motivations for this combination. First, building on the work of Niu et al. [18, 17] we obtain an account of cost analysis in type theory that is compatible with general recursive programs, which we anticipate will enable more natural programming and verification techniques. Second, we will use the resulting type theory to define and study the internal denotational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT, a cost-aware version of PCF, and prove a cost-sensitive internal computational adequacy theorem in the sense of op. cit. We explain what this entails in the following section.

1.1.2 Internal denotational semantics

By internal denotational semantics, we mean to specify the syntax and semantics of a given programming language \mathcal{L}caligraphic_L called the object language as constructions internal to type theory. Typically, one may define the syntax of the object language by means of a first-order encoding in terms of (indexed) inductive data types in which we have a type 𝗍𝗉:𝒰:𝗍𝗉𝒰\mathsf{tp}:\mathcal{U}sansserif_tp : caligraphic_U of object-level types and a type family 𝗍𝗆:𝗍𝗉𝒰:𝗍𝗆𝗍𝗉𝒰\mathsf{tm}:\mathsf{tp}\to\mathcal{U}sansserif_tm : sansserif_tp → caligraphic_U of object-level terms. A denotational model of \mathcal{L}caligraphic_L is given by a pair of maps 0:𝗍𝗉𝒰\llbracket-\rrbracket_{0}:\mathsf{tp}\to\mathcal{U}⟦ - ⟧ start_POSTSUBSCRIPT 0 end_POSTSUBSCRIPT : sansserif_tp → caligraphic_U and 1:(A:𝗍𝗉)𝗍𝗆(A)A\llbracket-\rrbracket_{1}:(A:\mathsf{tp})\to\mathsf{tm}(A)\to\llbracket A\rrbracket⟦ - ⟧ start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : ( italic_A : sansserif_tp ) → sansserif_tm ( italic_A ) → ⟦ italic_A ⟧ sending types to semantic domains and terms to elements of semantic domains. Usually we will use delimited-⟦⟧\llbracket-\rrbracket⟦ - ⟧ to refer to either map when the context is unambiguous. Similarly, one may define an internal operational semantics of \mathcal{L}caligraphic_L as a type family :(A:𝗍𝗉)𝗍𝗆(A)𝗍𝗆(A)𝒰{\Downarrow}:(A:\mathsf{tp})\to\mathsf{tm}(A)\to\mathsf{tm}(A)\to\mathcal{U}⇓ : ( italic_A : sansserif_tp ) → sansserif_tm ( italic_A ) → sansserif_tm ( italic_A ) → caligraphic_U such that the type ev𝑒𝑣e\Downarrow vitalic_e ⇓ italic_v (viewed as a proposition) holds just when e𝑒eitalic_e evaluates to v𝑣vitalic_v.

Computational adequacy, first introduced in Plotkin [22], is a statement that relates the operational and denotational semantics of \mathcal{L}caligraphic_L at the type of booleans (or any other observable type): a denotational semantics is computationally adequate when e=b\llbracket e\rrbracket=b⟦ italic_e ⟧ = italic_b just when eb¯𝑒¯𝑏e\Downarrow\overline{b}italic_e ⇓ over¯ start_ARG italic_b end_ARG, where b¯¯𝑏\overline{b}over¯ start_ARG italic_b end_ARG is the object-level boolean denoted a semantic boolean b𝑏bitalic_b. In the context of program verification, computational adequacy is a desirable property because the agreement of both semantics at observable types can be used to justify semantic reasoning with respect to operational behavior. In the context of cost analysis, the significance of this property is made explicit in the work of Niu and Harper [17], where the authors illustrate how a cost-sensitive refinement of internal computational adequacy can serve as the basis for validating user-defined cost models and program cost instrumentations. At a high level, results of this kind serve to ground the abstract reasoning supported by type theory to “reality” as given by operational semantics; we defer to op. cit. for a deeper discussion.

In this paper we will generalize the result of Niu and Harper [17] to higher-order recursion. In contrast to op. cit., in this paper we prefer to work with a version of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT whose execution model is given by a computational semantics (see Section 7). We will elaborate on the relationship between this new kind of dynamic semantics and traditional operational semantics in Section 10.

1.2 Mathematical techniques

In constructing a model for the type theory supporting both a phase distinction and recursion, we employ mathematical tools that deserve some explication, which we summarise below.

1.2.1 Cost as a phase distinction

The writer monad on a monoid is a well-established way to express the computational effect of incurring and accumulating the cost of program execution. However, as pointed out by Niu et al. [18], this arrangement does not faithfully model the semantics of cost profiling because it allows functions to branch on the cost component of their inputs. Thus, semantic functions lack a coherent underlying behavior independent of the profiling, which is indispensable for stating behavioral or correctness specifications of algorithms.

In the calf type theory of Niu et al. [18] this problem is resolved by means of the intension-extension phase distinction, as discussed in Section 1.1.1. Mathematically, a type-theoretic phase is simply a distinguished proposition \P whose associated open and closed modalities [26] generate subuniverses for classifying purely extensional and purely intensional types, respectively. A purely extensional type A𝐴Aitalic_A does not detect the presence of the phase proposition in the sense that the map A(A)𝐴𝐴A\to(\P\to A)italic_A → ( ¶ → italic_A ) sending a𝑎aitalic_a to the constant map A𝐴\P\to A¶ → italic_A determined by a𝑎aitalic_a is an isomorphism; in other words a purely extensional type classifies only the behavior of programs. By contrast, a purely intensional type A𝐴Aitalic_A “collapses” extensionally in the sense that (A)1𝐴1(\P\to A)\cong 1( ¶ → italic_A ) ≅ 1. Given any type A𝐴Aitalic_A, one may extract from A𝐴Aitalic_A the purely extensional and purely intensional part of A𝐴Aitalic_A by means of idempotent monadic modalities. The extensional/restriction modality is simply defined as the function space out of the proposition: A𝐴\P\to A¶ → italic_A (i.e. the reader monad on \P). The intensional/sealing modality \P\vee-¶ ∨ - is defined as the following pushout/quotient inductive type (QIT) [4]: A×𝐴A\times\Pitalic_A × ¶A𝐴Aitalic_Aπ1subscript𝜋1\pi_{1}italic_π start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT\PA𝐴\P\vee A¶ ∨ italic_Aπ2subscript𝜋2\pi_{2}italic_π start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT inductiveA:𝖲𝖾𝗍where:inductive𝐴𝖲𝖾𝗍where\textbf{inductive}~{}\P\vee A:\mathsf{Set}~{}\textbf{where}inductive ¶ ∨ italic_A : sansserif_Set where η:AA:subscript𝜂limit-from𝐴𝐴\eta_{\P\vee-}:A\to\P\vee Aitalic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT : italic_A → ¶ ∨ italic_A :A\ast:\P\to\P\vee A∗ : ¶ → ¶ ∨ italic_A _:(a:A)(u:)η(a)=(u)\_:(a:A)\to(u:\P)\to\eta_{\P\vee-}(a)=\ast(u)_ : ( italic_a : italic_A ) → ( italic_u : ¶ ) → italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_a ) = ∗ ( italic_u ) The universal property of the sealing monad can be phrased in terms of a unique extension property: for any map AB𝐴𝐵A\to Bitalic_A → italic_B into a purely intensional type B𝐵Bitalic_B, there is a unique extension AB𝐴𝐵\P\vee A\to B¶ ∨ italic_A → italic_B along the unit of the sealing monad η:AA:subscript𝜂limit-from𝐴𝐴\eta_{\P\vee-}:A\to\P\vee Aitalic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT : italic_A → ¶ ∨ italic_A. One can use the phase proposition \P to exhibit a form of noninterference in the sense of information flow: any map A(B)𝐴𝐵A\to(\P\to B)italic_A → ( ¶ → italic_B ) from a purely intensional type A𝐴Aitalic_A to the extensional part of B𝐵Bitalic_B must be constant. Therefore in calf one achieves a semantically faithful instrumentation of cost by programming against the writer monad on a purely intensional cost monoid.

From an external point of view, calf’s types can be modeled as presheaves on the interval 𝕀={𝖾𝗑𝗍𝗂𝗇𝗍}𝕀square-image-of-or-equals𝖾𝗑𝗍𝗂𝗇𝗍\mathbb{I}={\left\{\mathsf{ext}\sqsubseteq\mathsf{int}\right\}}blackboard_I = { sansserif_ext ⊑ sansserif_int }; in the terminology of Sterling and Harper [32], such a presheaf encodes a set varying in the intension-extension “security poset” 𝕀𝕀\mathbb{I}blackboard_I whose presheaf restriction action redacts intensional cost structure. The phase proposition \P is given by the “intermediate” proposition 01010\to 10 → 1 corresponding to the representable 𝗒𝕀(𝖾𝗑𝗍)subscript𝗒𝕀𝖾𝗑𝗍\mathsf{y}_{\mathbb{I}}(\mathsf{ext})sansserif_y start_POSTSUBSCRIPT blackboard_I end_POSTSUBSCRIPT ( sansserif_ext ).

1.2.2 Synthetic domain theory

Synthetic domain theory (SDT) as a field started when Dana Scott conjectured that one ought to be able to reason about domains as if they were just sets provided that one employs a constructive ambient metalanguage. In technical terms, this metalanguage can be construed as the internal languages of a topos, i.e. an extensional dependent type theory. In general it is difficult to reconcile the domain-theoretic structure with the rich logical structure of dependent type theory, so the quest for SDT was in essence about constructing full subcategories of topoi that supported domain-theoretic constructions. Fullness is a critical property — it means that every map definable in type-theoretic language is a domain morphism, which absolves one from checking onerous side conditions when working internally. There are two well-known ways to obtain models of synthetic domain theory: one based on realizability (Hyland [11], Phoa [20], Reus [24]) and one based on sheaf topoi (Rosolini [27], Fiore and Rosolini [7], Fiore and Plotkin [5], Matache et al. [16]). In this paper we will construct a sheaf model of SDT, so we take a moment to recall the basic ideas, mainly drawing from the work of Fiore and Plotkin [5].

Sheaf models of SDT. The intuition behind (pre)sheaf models of synthetic domain theory is to use the Yoneda embedding to embed a category of predomains as a full subcategory of an ambient category whose internal language is dependent type theory. Thus given a (small222The fact that natural categories of predomains are rarely small can be overcome by means of Grothendieck universes or a small dense subcategory (e.g. {ω}fullωCPOfull𝜔𝜔CPO\{\omega\}\xhookrightarrow{\text{full}}\omega\textbf{CPO}{}{ italic_ω } start_ARROW overfull ↪ end_ARROW italic_ω CPO).) category of predomains G𝐺Gitalic_G, the category of presheaves on G𝐺Gitalic_G presents the original category of predomains as a full subcategory, which constitutes a simple model of SDT. However there are some strange properties of this model from an internal perspective. For example, because the \emptyset is the initial object in G𝐺Gitalic_G, it is a sub-predomain of every other predomain. But because the embedding does not preserve colimits, the subcategory of predomains does not contain an initial object from the perspective of G^^𝐺\widehat{G}over^ start_ARG italic_G end_ARG; in other words, this means that while the empty set is a subset of every predomain, it is not a sub-predomain, which obstructs the use of the ambient logic to reason about (pre)domains. We may repair the model by imposing a nontrivial Grothendieck topology on G𝐺Gitalic_G that ensures that the empty predomain is preserved by the embedding into the category of sheaves on G𝐺Gitalic_G. In practice one may choose to preserve additional colimits as the application demands — for instance in Section 9 we will construct a model of SDT in which discrete finite predomains are preserved.

1.2.3 Predomains and the intrinsic order

Contrary to classical domain theory, ordering on predomains is a derived notion in synthetic domain theory. Nonetheless one may equip a synthetic predomain with an intrinsic preorder that is analogous to the information order of ordinary predomains. By default the intrinsic/synthetic preorder is not very well-behaved: it is not pointwise on limits of predomains, and it is not even a partial order in general. In this paper we shall define and base our constructions on a notion of synthetic predomains for which the intrinsic preorder is extremely well-behaved: it is pointwise, partially ordered, and closed under synthetic ω𝜔\omegaitalic_ω-chains, which is the counterpart to closure under {\mathbb{N}}blackboard_N-chains for classic ω𝜔\omegaitalic_ω-cpos.

Aside from intrinsic interest, we are motivated by two practical incentives for considering and developing the theory of the synthetic preorder. First, we would like to connect our work to the type theory for cost analysis developed by Grodin et al. [8]. In that setting one works with a cost ordering on programs in which eesquare-image-of-or-equals𝑒superscript𝑒e\sqsubseteq e^{\prime}italic_e ⊑ italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT represents a proof of the fact that esuperscript𝑒e^{\prime}italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is an upper bound of e𝑒eitalic_e with respect to computational cost. We expect that one may extend the work of op. cit. to account for recursive programs by the methods we develop in this paper, and the information/intrinsic preorder appears to be the correct theoretical framework for describing the interaction of cost and partiality [13, Section 8]. Second, the advantages of the synthetic point of view outlined Section 1.2.2 do not detract from the benefits of the language of classical domain theory. The intrinsic preorder integrates the advantages of both the synthetic and classical perspective by providing an intuitively appealing language for reasoning about domains that automatically complies with well-definedness conditions such as monotonicity and continuity.

1.2.4 Synthetic predomains from orthogonality

From an internal perspective, predomains in a model of SDT [5, 25, 32] are often defined in terms of (internal) orthogonality conditions. Intuitively, an orthogonality condition can be thought of as a way of specifying a closure property with respect to a given figure shape XY𝑋𝑌X\to Yitalic_X → italic_Y. A type A𝐴Aitalic_A is orthogonal to a map f:XY:𝑓𝑋𝑌f:X\to Yitalic_f : italic_X → italic_Y when Af:AYAX:superscript𝐴𝑓superscript𝐴𝑌superscript𝐴𝑋A^{f}:A^{Y}\to A^{X}italic_A start_POSTSUPERSCRIPT italic_f end_POSTSUPERSCRIPT : italic_A start_POSTSUPERSCRIPT italic_Y end_POSTSUPERSCRIPT → italic_A start_POSTSUPERSCRIPT italic_X end_POSTSUPERSCRIPT is invertible. In other words A𝐴Aitalic_A is orthogonal to f𝑓fitalic_f when A𝐴Aitalic_A “thinks” f𝑓fitalic_f is an isomorphism. For instance, an ω𝜔\omegaitalic_ω-cpo is a poset P𝑃Pitalic_P that is orthogonal to the figure shape {01}{01}square-image-of-or-equals01square-image-of-or-equalssquare-image-of-or-equals01square-image-of-or-equalssquare-image-of-or-equals\{0\sqsubseteq 1\sqsubseteq\dots\}\hookrightarrow\{0\sqsubseteq 1\sqsubseteq% \dots\sqsubseteq\infty\}{ 0 ⊑ 1 ⊑ … } ↪ { 0 ⊑ 1 ⊑ … ⊑ ∞ }, i.e. when P𝑃Pitalic_P is closed under joins of {\mathbb{N}}blackboard_N-chains. In Section 3 we define predomains by means of multiple such orthogonality conditions. The benefit of this general approach to synthetic domain theory is that subcategories defined by (internal) orthogonality conditions are automatically (internally) reflective — this closes the predomains under structures necessary for day-to-day denotational semantics such as product and function types. Moreover, limits of predomains are preserved by the inclusion into the ambient SDT topos, which allows one to reason about the denotational semantics in a straightforward way using the internal language. Note that colimits of predomains always exist by virtue of the reflection, but they are usually not preserved by inclusion; in some situations this may be calibrated by ensuring a precise correspondence between the original domain-theoretic site and the subcategory of predomains (e.g. the internal characterization of ω𝜔\omegaitalic_ω-cpos of Fiore and Rosolini [6]).

1.3 Contributions

The contribution of our work is summarized as follows:

  1. \normalshape(1)

    An axiomatization of a type theory based on SDT that incorporates both a phase distinction and a subuniverse of predomains whose intrinsic order structure is well-behaved (Section 2).

  2. \normalshape(2)

    A denotational semantics for PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT exhibiting noninterference between cost and behavior (Section 6).

  3. \normalshape(3)

    A dynamic semantics for PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in which execution is modeled directly as computation (Section 7).

  4. \normalshape(4)

    An internal cost-sensitive adequacy theorem identifying the two semantics at base type (Section 8).

  5. \normalshape(5)

    A relative sheaf model of SDT justifying the axioms of the type theory (Section 9).

2 A type theory for cost-sensitive synthetic domain theory

We work in an extensional dependent type theory combining synthetic domain theory with the intension-extension phase distinction of Niu et al. [18]; the semantics and model construction of this theory is developed in Section 3 and Section 9. Here we outline the language furnished by this combination. Following Niu et al. [18], we assume an indeterminate proposition \P{} representing the phase distinction. We assume a (reflective) subuniverse of predomains 𝒰𝗉𝗋𝖾𝖽𝗈𝗆subscript𝒰𝗉𝗋𝖾𝖽𝗈𝗆\mathcal{U}_{\mathsf{predom}}caligraphic_U start_POSTSUBSCRIPT sansserif_predom end_POSTSUBSCRIPT. Every predomain is equipped with a synthetic ω𝜔\omegaitalic_ω-complete partial order structure, which we explain in Section 4.3. The significance of synthetic ω𝜔\omegaitalic_ω-completeness is that they can be used to construct the join of rational chains ({\mathbb{N}}blackboard_N-chains arising from the iterates of an endomap), the critical component in the interpretation of fixed-points in both classical and synthetic domain theory.

By a domain we shall mean a predomain X𝑋Xitalic_X equipped with a least element. Equivalently this may be characterized as an algebra for the lifting monad 𝕃=(𝖫,η,μ)𝕃𝖫𝜂𝜇\mathbb{L}=(\mathsf{L},\eta,\mu)blackboard_L = ( sansserif_L , italic_η , italic_μ ), which freely adjoins a least element to a predomain. There is a special domain Σ𝖫1ΩΣ𝖫1Ω\Sigma\cong\mathsf{L}1\hookrightarrow\Omegaroman_Σ ≅ sansserif_L 1 ↪ roman_Ω spanned by propositions called the Sierpiński space or dominance; propositions in ΣΣ\Sigmaroman_Σ should be thought of as the support of partial maps, and a map XΣ𝑋ΣX\to\Sigmaitalic_X → roman_Σ can be thought of as a “computational” or “observable” subset of a predomain X𝑋Xitalic_X. Moreover, because we use the sealing modality (see Section 1.2.1) associated with the phase proposition \P to define the denotational cost semantics of PCF, we require that predomains are closed under the sealing modality. Lastly, we assume that the subuniverse 𝒰𝗉𝗋𝖾𝖽𝗈𝗆subscript𝒰𝗉𝗋𝖾𝖽𝗈𝗆\mathcal{U}_{\mathsf{predom}}caligraphic_U start_POSTSUBSCRIPT sansserif_predom end_POSTSUBSCRIPT is closed under lifting.

2.1 Denotational semantics of cost-sensitive PCF

We aim to prove the computational adequacy property for a cost-sensitive version of PCF called PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in which cost and partiality are treated as a single call-by-push-value effect. We spell out the details of the language in Section 5, but the basic idea is to separate pure values and effectful computations at both the term and type level, resulting in a class of value types A𝐴Aitalic_A and a class of computation types X𝑋Xitalic_X. The type structure of the language is generated by a pair of type operators 𝖥,𝖴𝖥𝖴\mathsf{F},\mathsf{U}sansserif_F , sansserif_U in which 𝖥(A)𝖥𝐴\mathsf{F}(A)sansserif_F ( italic_A ) represents the partial cost-aware computations of type A𝐴Aitalic_A and 𝖴(X)𝖴𝑋\mathsf{U}(X)sansserif_U ( italic_X ) represents the value type whose underlying set of points are computations of type X𝑋Xitalic_X. In contrast to call-by-value languages, call-by-push-value function types are computations and take the form AX𝐴𝑋A\to Xitalic_A → italic_X. As an example, the ordinary call-by-value PCF function type 𝗇𝖺𝗍𝗇𝖺𝗍𝗇𝖺𝗍𝗇𝖺𝗍\mathsf{nat}\to\mathsf{nat}sansserif_nat → sansserif_nat corresponds to the type 𝖴(𝗇𝖺𝗍𝖥(𝗇𝖺𝗍))𝖴𝗇𝖺𝗍𝖥𝗇𝖺𝗍\mathsf{U}(\mathsf{nat}\to\mathsf{F}(\mathsf{nat}))sansserif_U ( sansserif_nat → sansserif_F ( sansserif_nat ) ) in the call-by-push-value setting — here the codomain type 𝖥(𝗇𝖺𝗍)𝖥𝗇𝖺𝗍\mathsf{F}(\mathsf{nat})sansserif_F ( sansserif_nat ) records both the cost incurred and the possibility of divergence, and the outer 𝖴()𝖴\mathsf{U}(-)sansserif_U ( - ) corresponds to the fact that functions are values in a call-by-value setting.

The denotational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT is based on the adjunction models of call-by-push-value [14] in which 𝖥(A)delimited-⟦⟧𝖥𝐴\llbracket\mathsf{F}(A)\rrbracket⟦ sansserif_F ( italic_A ) ⟧ is defined to be the lift of ×A\mathbb{C}\times\llbracket A\rrbracketblackboard_C × ⟦ italic_A ⟧ for a purely intensional cost monoid \mathbb{C}blackboard_C in the sense of Section 1.2.1. By using a purely intensional type for the cost semantics, we may prove a cost-sensitive computational adequacy theorem that can be restricted to an extensional adequacy result for PCF. Moreover, by interpreting the cost this way, the resulting denotational cost semantics evinces a form of information flow security when viewing cost and behavior as security levels:

Proposition 2.1.

For any purely extensional type B𝐵Bitalic_B, every map f:𝖫B:𝑓𝖫𝐵f:\mathbb{C}\to\mathsf{L}Bitalic_f : blackboard_C → sansserif_L italic_B is weakly constant in the sense that for any inputs x,y::𝑥𝑦x,y:\mathbb{C}italic_x , italic_y : blackboard_C, we have that fx𝑓𝑥f~{}xitalic_f italic_x and fy𝑓𝑦f~{}yitalic_f italic_y are equal whenever they are both defined.

As an application of computational adequacy, we can immediately transfer this intrinsic denotational security property to functions of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT.

Remark 2.2.

As mentioned in Section 1.1.2, we will define both the syntax and semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT as objects and functions in the internal type theory of a synthetic domain theory topos. In a more traditional approach to denotational cost semantics, one may instead define a model of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in the category ωCPO𝜔superscriptCPO\omega\textbf{CPO}^{\to}italic_ω CPO start_POSTSUPERSCRIPT → end_POSTSUPERSCRIPT of families of ω𝜔\omegaitalic_ω-cpos, which is semantically simpler in comparison to models of synthetic domain theory. In this paper we pursue an approach based on the latter in order to unify two strands of prior work — cost-sensitive programming and verification in dependent type theory [18] and internal denotational semantics [19, 17] — and synthetic domain theory provides the means for smoothly integrating higher-order recursion into dependent type theory.

3 Cost-sensitive predomains in synthetic domain theory

As mentioned in the Section 1.2.3, the purpose of this section is to define a notion of predomains in synthetic domain theory such that the intrinsic preorder on predomains is partially ordered, defined pointwise on function spaces, and is closed under suprema of synthetic ω𝜔\omegaitalic_ω-chains. We will use these properties to define and reason about admissible subsets of domains. We define the basic notions of synthetic domain theory, and give an axiomatization of the rest of the paper in terms of SDT models of the intension-extension phase distinction, culminating in a category of predomains satisfying the properties laid out above.

3.1 Partial maps, dominance, and lifting

In a category with pullbacks, a partial map AB𝐴𝐵A\rightharpoonup Bitalic_A ⇀ italic_B is a span ADB𝐴𝐷𝐵A\hookleftarrow D\to Bitalic_A ↩ italic_D → italic_B consisting of a subset DA𝐷𝐴D\hookrightarrow Aitalic_D ↪ italic_A on which AB𝐴𝐵A\rightharpoonup Bitalic_A ⇀ italic_B is defined. In synthetic domain theory, only certain monomorphisms correspond to domains of definitions of partial maps. In the terminology of Rosolini [27] such a collection is called a dominion:

Definition 3.1.

A pullback-stable collection of monomorphisms is a called a dominion when it is closed under identity and composition.

Definition 3.2.

Let \mathscr{E}script_E be an elementary topos equipped with a subobject ΣΩΣΩ\Sigma\hookrightarrow\Omegaroman_Σ ↪ roman_Ω such that Σ\top\in\Sigma⊤ ∈ roman_Σ. A monomorphism is classified by ΣΣ\Sigmaroman_Σ if and only if its characteristic map factors through ΣΩΣΩ\Sigma\hookrightarrow\Omegaroman_Σ ↪ roman_Ω. A dominance is a subobject ΣΩΣΩ\Sigma\hookrightarrow\Omegaroman_Σ ↪ roman_Ω such that the class of monos classified by ΣΣ\Sigmaroman_Σ is a dominion. We call a proposition (resp., predicate) factoring through ΣΣ\Sigmaroman_Σ a ΣΣ\Sigmaroman_Σ-proposition (resp., ΣΣ\Sigmaroman_Σ-predicate).

In the internal language, this means that ΣΣ\Sigmaroman_Σ contains the true proposition top\top and is closed under dependent sums, which we write as ϕfitalic-ϕ𝑓\phi\mathbin{\angle}fitalic_ϕ ∠ italic_f given ϕ:Σ:italic-ϕΣ\phi:\Sigmaitalic_ϕ : roman_Σ and f:ϕΣ:𝑓italic-ϕΣf:\phi\to\Sigmaitalic_f : italic_ϕ → roman_Σ. These structures ensure that the dominance determines a lifting monad 𝕃=(𝖫,η,μ)𝕃𝖫𝜂𝜇\mathbb{L}=(\mathsf{L},\eta,\mu)blackboard_L = ( sansserif_L , italic_η , italic_μ ) whose action on points are defined as follows:

Definition 3.3.

The lift of a type A𝐴Aitalic_A relative to a dominance ΣΣ\Sigmaroman_Σ is defined as 𝖫A=Σϕ:Σ.ϕAformulae-sequence𝖫𝐴subscriptΣ:italic-ϕΣitalic-ϕ𝐴\mathsf{L}A=\Sigma_{\phi:\Sigma}.~{}\phi\to Asansserif_L italic_A = roman_Σ start_POSTSUBSCRIPT italic_ϕ : roman_Σ end_POSTSUBSCRIPT . italic_ϕ → italic_A.

The lifting monad is also called the partial map classifier because every partial map ADB𝐴𝐷𝐵A\hookleftarrow D\to Bitalic_A ↩ italic_D → italic_B with D𝐷Ditalic_D a ΣΣ\Sigmaroman_Σ-subobject of A𝐴Aitalic_A appears as the pullback of ηB:B𝖫B:subscript𝜂𝐵𝐵𝖫𝐵\eta_{B}:B\to\mathsf{L}Bitalic_η start_POSTSUBSCRIPT italic_B end_POSTSUBSCRIPT : italic_B → sansserif_L italic_B for a unique A𝖫B𝐴𝖫𝐵A\to\mathsf{L}Bitalic_A → sansserif_L italic_B.

Notation 1

Given a partial element e:𝖫A:𝑒𝖫𝐴e:\mathsf{L}Aitalic_e : sansserif_L italic_A, we write e:Σe{\downarrow}:\Sigmaitalic_e ↓ : roman_Σ for its support, i.e. -{\downarrow}- ↓ is the first projection 𝖫(A)Σ𝖫𝐴Σ\mathsf{L}(A)\to\Sigmasansserif_L ( italic_A ) → roman_Σ. When it is known that e𝑒absente{\downarrow}italic_e ↓ holds, we may write e:A:𝑒𝐴e:Aitalic_e : italic_A for the defined element.

3.2 Complete types

In synthetic domain theory the structure of predomains is generated not from consideration of {\mathbb{N}}blackboard_N-indexed chains but rather a new notion of chains called a synthetic ω𝜔\omegaitalic_ω-chain, which is defined simply to be a map out of ω𝜔\omegaitalic_ω. The difference between the two notions of chain is elucidated by the fact that {\mathbb{N}}blackboard_N is the initial lifting algebra for the dominance of decidable propositions, whereas ω𝜔\omegaitalic_ω is the initial algebra for a larger dominance.

Definition 3.4.

A synthetic ω𝜔\omegaitalic_ω-chain is a map ωA𝜔𝐴\omega\to Aitalic_ω → italic_A from the initial 𝖫𝖫\mathsf{L}sansserif_L-algebra or lift algebra ω𝜔\omegaitalic_ω.

The closure properties of synthetic ω𝜔\omegaitalic_ω-chains can be captured by considering an orthogonality condition relative to the figure shape ωω¯𝜔¯𝜔\omega\hookrightarrow\overline{\omega}italic_ω ↪ over¯ start_ARG italic_ω end_ARG induced by the inclusion of the initial lift algebra in the final lift coalgebra ω¯¯𝜔\overline{\omega}over¯ start_ARG italic_ω end_ARG. As we alluded to in Section 1.2.4, orthogonality is a way to identify types that “think” certain maps are isomorphisms:

Definition 3.5.

A type A𝐴Aitalic_A is orthogonal to f:XY:𝑓𝑋𝑌f:X\to Yitalic_f : italic_X → italic_Y when there is a unique extension of any map g:XA:𝑔𝑋𝐴g:X\to Aitalic_g : italic_X → italic_A to a map g¯:YA:¯𝑔𝑌𝐴\overline{g}:Y\to Aover¯ start_ARG italic_g end_ARG : italic_Y → italic_A such that g=g¯f𝑔¯𝑔𝑓g=\overline{g}\circ fitalic_g = over¯ start_ARG italic_g end_ARG ∘ italic_f.

Definition 3.6.

A type A𝐴Aitalic_A is called complete when it is orthogonal to the figure shape ωω¯𝜔¯𝜔\omega\hookrightarrow\overline{\omega}italic_ω ↪ over¯ start_ARG italic_ω end_ARG, and well-complete when 𝖫A𝖫𝐴\mathsf{L}Asansserif_L italic_A is complete.

Complete types [11, 20] are the synthetic counterpart to ω𝜔\omegaitalic_ω-cpos in classic domain theory. The class of well complete types was introduced in Longley and Simpson [15] as the least restrictive possible notion of predomain that is closed under lifting. In this paper we consider the dual most restrictive class of predomain, the replete types [11], in order to obtain a sharper characterisation of the intrinsic order relation (see Section 3.3) on predomains.

Definition 3.7.

A map f:XY:𝑓𝑋𝑌f:X\to Yitalic_f : italic_X → italic_Y is called ΣΣ\Sigmaroman_Σ-equable or a ΣΣ\Sigmaroman_Σ-isomorphism when ΣΣ\Sigmaroman_Σ is orthogonal to f𝑓fitalic_f.

Definition 3.8.

A type is replete when it is orthogonal to every ΣΣ\Sigmaroman_Σ-iso. A predomain is a replete type.

In other words, a predomain respects every ΣΣ\Sigmaroman_Σ-isomorphism; we will use this fact to easily transfer properties that hold of ΣΣ\Sigmaroman_Σ to every predomain in Section 4.

3.3 The intrinsic order

For every type A𝐴Aitalic_A, the dominance ΣΣ\Sigmaroman_Σ induces an intrinsic preorder Asubscriptsuperscriptsquare-image-of-or-equals𝐴\sqsubseteq^{\circ}_{A}⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT on A𝐴Aitalic_A analogous to the specialization preorder on a topological space: xAysubscriptsuperscriptsquare-image-of-or-equals𝐴𝑥𝑦x\sqsubseteq^{\circ}_{A}yitalic_x ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_y if and only if fx𝑓𝑥f~{}xitalic_f italic_x implies fy𝑓𝑦f~{}yitalic_f italic_y for every f:AΣ:𝑓𝐴Σf:A\to\Sigmaitalic_f : italic_A → roman_Σ. Viewing f:AΣ:𝑓𝐴Σf:A\to\Sigmaitalic_f : italic_A → roman_Σ as a computational or observable property of A𝐴Aitalic_A, xAysubscriptsuperscriptsquare-image-of-or-equals𝐴𝑥𝑦x\sqsubseteq^{\circ}_{A}yitalic_x ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_y holds whenever y𝑦yitalic_y satisfies every observable property of x𝑥xitalic_x. By default the intrinsic preorder is relatively unconstrained — for instance, it need not be a partial order in general and on the dominance ΣΣ\Sigmaroman_Σ it need not coincide with the implication order on propositions. The purpose of this section is to axiomatize some constraints on ΣΣ\Sigmaroman_Σ that will make intrinsic preorder coincide with the implication order on ΣΣ\Sigmaroman_Σ; this is used in the characterization of the intrinsic order of lifting in Section 4. To this end, we introduce an intermediate path relation on types:

Definition 3.9.

A path in a type A𝐴Aitalic_A is a map ΣAΣ𝐴\Sigma\to Aroman_Σ → italic_A. The boundary of a path f:ΣA:𝑓Σ𝐴f:\Sigma\to Aitalic_f : roman_Σ → italic_A is the pair f=(f,f)𝑓limit-from𝑓bottomlimit-from𝑓top\partial f=(f~{}\bot,f~{}\top)∂ italic_f = ( italic_f ⊥ , italic_f ⊤ ). We write xA𝗉ysubscriptsuperscriptsquare-image-of-or-equals𝗉𝐴𝑥𝑦x\sqsubseteq^{\mathsf{p}}_{A}yitalic_x ⊑ start_POSTSUPERSCRIPT sansserif_p end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_y when there exists a path whose boundary is (x,y)𝑥𝑦(x,y)( italic_x , italic_y ).

The path relation is an alternative way to surface the order structure of predomains, studied in much more detail by Fiore [3]; the path relation is also used by Grodin et al. [8] to obtain a theory of synthetic preorders for cost analysis. In this paper one can view the path relation as an auxiliary notion that ultimately coincides with the intrinsic preorder on predomains. In general we call types for which this holds linked, following Phoa [20]:

Definition 3.10.

A type is called linked when the intrinsic preorder coincides with the path relation.

The fact that the intrinsic order on ΣΣ\Sigmaroman_Σ coincides with the implication order follows if ΣΣ\Sigmaroman_Σ is linked. This latter property holds when ΣΣ\Sigmaroman_Σ satisfies one of the fundamental axioms of synthetic domain theory:

Definition 3.11.

The dominance ΣΣ\Sigmaroman_Σ satisfies Phoa’s principle when the boundary evaluation map :ΣΣΣ×Σ:superscriptΣΣΣΣ\partial:\Sigma^{\Sigma}\to\Sigma\times\Sigma∂ : roman_Σ start_POSTSUPERSCRIPT roman_Σ end_POSTSUPERSCRIPT → roman_Σ × roman_Σ factors as an isomorphism followed by an inclusion: ΣΣ{(ϕ,ψ)ϕψ}Σ×ΣsuperscriptΣΣconditional-setitalic-ϕ𝜓italic-ϕ𝜓ΣΣ\Sigma^{\Sigma}\cong\{(\phi,\psi)\mid\phi\to\psi\}\hookrightarrow\Sigma\times\Sigmaroman_Σ start_POSTSUPERSCRIPT roman_Σ end_POSTSUPERSCRIPT ≅ { ( italic_ϕ , italic_ψ ) ∣ italic_ϕ → italic_ψ } ↪ roman_Σ × roman_Σ.

Phoa’s principle expresses the fact that the path space of ΣΣ\Sigmaroman_Σ is fully characterized by ordered pairs of ΣΣ\Sigmaroman_Σ-propositions (with respect to implication). Because the negation of an observable property is not in general observable, Phoa’s principle may be seen as an explicit statement of the constructive/observable nature of ΣΣ\Sigmaroman_Σ-propositions, i.e. there is no map ΣΣΣΣ\Sigma\to\Sigmaroman_Σ → roman_Σ sending ϕitalic-ϕ\phiitalic_ϕ to ¬ϕitalic-ϕ\neg\phi¬ italic_ϕ.

Proposition 3.12.

Assuming Phoa’s principle, the dominance ΣΣ\Sigmaroman_Σ is linked.

Corollary 3.13.

Assuming Phoa’s principle, the intrinsic order on ΣΣ\Sigmaroman_Σ is the implication order.

Moreover, the path in ΣΣ\Sigmaroman_Σ associated to every implication ϕψitalic-ϕ𝜓\phi\to\psiitalic_ϕ → italic_ψ is unique in the following sense:

Definition 3.14.

A type A𝐴Aitalic_A is boundary separated when any two paths in A𝐴Aitalic_A sharing a boundary are equal.

Proposition 3.15.

Assuming Phoa’s principle, ΣΣ\Sigmaroman_Σ is boundary separated.

3.4 Axioms of the phase distinction in SDT and predomains

Having developed the axiomatics of the ordinary synthetic domain theoretic components of our work, we now introduce the intension-extension phase distinction as discussed in Section 1.2.1. The meeting point of the domain-theoretic and the cost-sensitive aspects of our work is simply expressed by the requirement that the phase proposition \P is a ΣΣ\Sigmaroman_Σ-proposition. This allows us to manufacture a purely intensional monoid from a standard cost monoid that we will use to define a denotational semantics for PCF that exhibits the natural information flow security properties with respect to cost and behavior as outlined in Section 2.1.

More specifically, we may use the fact that \P is a ΣΣ\Sigmaroman_Σ-proposition to define the sealing monad \P\vee-¶ ∨ - mentioned in Section 1.2.1 that can be seen as the canonical way of making a predomain purely intensional. When defining the denotational semantics, we may then take as an input to the model construction any ordinary monoid (in the subuniverse of predomains) and apply the sealing monad to obtain a purely intensional monoid. Lastly, to exhibit the kind of noninterference property of cost and behavior as discussed in Section 1.2.1, we require that there is a purely extensional base predomain. These considerations lead us to the following axiomatization of our synthetic domain theory topos:

Definition 3.16.

An SDT model of the intension-extension phase distinction is an elementary topos \mathscr{E}script_E equipped with a dominance ΣΣ\Sigmaroman_Σ satisfying Phoa’s principle such that ΣΣ\Sigmaroman_Σ is complete, and a distinguished ΣΣ\Sigmaroman_Σ-proposition \P such that the type of booleans 2222 is an extensional predomain.

For the rest of the paper we assume a given SDT model of the intension-extension phase distinction 𝒟𝒟\mathscr{D}script_D. All constructions are all carried out in the internal language of \mathscr{E}script_E.

4 Properties of predomains

We now establish the expected characterizations of the intrinsic preorder (Section 3.3) on predomains:

  1. \normalshape(1)

    The intrinsic preorder is pointwise on products, functions, and liftings of predomains.

  2. \normalshape(2)

    The intrinsic preorder on a predomain is a synthetic ω𝜔\omegaitalic_ω-complete partial order.

  3. \normalshape(3)

    The synthetic ω𝜔\omegaitalic_ω-complete partial order structure of predomains is defined componentwise for products and functions between predomains.

The general properties of the intrinsic preorder and link relation in SDT have been investigated in several prior works [20, 24, 15]. Here we recall just a few important properties that we will need.

Proposition 4.1.

Any predomain A𝐴Aitalic_A enjoys the following properties:

  1. \normalshape(1)

    Completeness: A𝐴Aitalic_A is orthogonal to ωω¯𝜔¯𝜔\omega\hookrightarrow\overline{\omega}italic_ω ↪ over¯ start_ARG italic_ω end_ARG.

  2. \normalshape(2)

    Anti-symmetry: the intrinsic preorder on A𝐴Aitalic_A is a partial order.

  3. \normalshape(3)

    Boundary separation: maps ΣAΣ𝐴\Sigma\to Aroman_Σ → italic_A with equal boundary are equal.

  4. \normalshape(4)

    Linkedness: the intrinsic preorder and the link relation on A𝐴Aitalic_A coincide.

In addition, because predomains are defined in terms of orthogonality conditions, they are closed under (internal) limits and have all colimits, i.e. limits of predomains are computed in the same way as limits of general types. The rest of the section is dedicated to proving the desired properties on the intrinsic order on predomains. Because the intrinsic order superscriptsquare-image-of-or-equals\sqsubseteq^{\circ}⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT and 𝗉superscriptsquare-image-of-or-equals𝗉\sqsubseteq^{\mathsf{p}}⊑ start_POSTSUPERSCRIPT sansserif_p end_POSTSUPERSCRIPT are the same for predomains, we may speak of the synthetic order of predomains and write square-image-of-or-equals\sqsubseteq for this relation in the rest of the paper.

4.1 Discrete predomains

We shall assume that the cost structure of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT is given as a discrete type in the following sense:

Definition 4.2.

A type A𝐴Aitalic_A is called flat or discrete when xysuperscriptsquare-image-of-or-equals𝑥𝑦x\sqsubseteq^{\circ}yitalic_x ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT italic_y implies x=y𝑥𝑦x=yitalic_x = italic_y.

Definition 4.3.

A type has ΣΣ\Sigmaroman_Σ-equality when its equality relation is valued in ΣΣ\Sigmaroman_Σ-propositions.

Proposition 4.4.

Any type with ΣΣ\Sigmaroman_Σ-equality is discrete.

Proof 4.5.

Let f:AΣ:𝑓𝐴Σf:A\to\Sigmaitalic_f : italic_A → roman_Σ be the characteristic map that sends a𝑎aitalic_a to a=x𝑎𝑥a=xitalic_a = italic_x, which by assumption is a ΣΣ\Sigmaroman_Σ-proposition. Since xAysubscriptsquare-image-of-or-equals𝐴𝑥𝑦x\sqsubseteq_{A}yitalic_x ⊑ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_y on the specialization order and f(x)𝑓𝑥f(x)italic_f ( italic_x ) holds, we have that f(y)𝑓𝑦f(y)italic_f ( italic_y ) holds as well.

The category of predomains possesses a natural numbers type 𝖯subscript𝖯{\mathbb{N}}_{\mathsf{P}}blackboard_N start_POSTSUBSCRIPT sansserif_P end_POSTSUBSCRIPT with ΣΣ\Sigmaroman_Σ-equality, which means it is also discrete. Note that it is not necessarily the same as the ambient natural numbers type {\mathbb{N}}blackboard_N, and we will not assume that it is the case in our constructions. From a logical perspective, this difference means that 𝖯subscript𝖯{\mathbb{N}}_{\mathsf{P}}blackboard_N start_POSTSUBSCRIPT sansserif_P end_POSTSUBSCRIPT has a universal mapping-out property whose motive is valued in predomains rather than arbitrary types.

In Section 6 we will require the cost structure of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT to be both discrete and purely intensional in the sense of Section 1.2.1; here we show that these are compatible requirements by giving sufficient conditions to obtain a purely intensional discrete type (for instance, \P\vee{\mathbb{N}}¶ ∨ blackboard_N will be discrete).

Proposition 4.6.

If A𝐴Aitalic_A has ΣΣ\Sigmaroman_Σ-equality, then so does A𝐴\P\vee A¶ ∨ italic_A.

4.2 Characterization of the synthetic order

As mentioned at the beginning of this section, one of the primary motives of using replete types as predomains is to give a compositional characterization of the synthetic order. Roughly this means that the order relation on composite predomains can be defined in terms of the order on the constituent predomains.

Proposition 4.7.

When A𝐴Aitalic_A and B𝐵Bitalic_B are predomains, the synthetic orders on A×B𝐴𝐵A\times Bitalic_A × italic_B and AB𝐴𝐵A\to Bitalic_A → italic_B are pointwise.

We may also give a similar characterization of the order relation on lifted predomains:

Proposition 4.8.

Given a predomain A𝐴Aitalic_A, we have that x𝖫Aysubscriptsquare-image-of-or-equals𝖫𝐴𝑥𝑦x\sqsubseteq_{\mathsf{L}A}yitalic_x ⊑ start_POSTSUBSCRIPT sansserif_L italic_A end_POSTSUBSCRIPT italic_y if and only if x𝑥absentx{\downarrow}italic_x ↓ implies y𝑦absenty{\downarrow}italic_y ↓ and whenever x𝑥absentx{\downarrow}italic_x ↓, we have xAysubscriptsquare-image-of-or-equals𝐴𝑥𝑦x\sqsubseteq_{A}yitalic_x ⊑ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_y.

4.3 The synthetic ω𝜔\omegaitalic_ω-complete partial order structure

Every predomain A𝐴Aitalic_A contains the least upper bound of a synthetic ω𝜔\omegaitalic_ω-chain; we will use this fact to interpret fixed points of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in Section 6.

Proposition 4.9.

For every map f:ωA:𝑓𝜔𝐴f:\omega\to Aitalic_f : italic_ω → italic_A into a complete type A𝐴Aitalic_A, there exists an element a:A:subscript𝑎𝐴a_{\infty}:Aitalic_a start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT : italic_A such that asubscript𝑎a_{\infty}italic_a start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT is a least upper bound of f𝑓fitalic_f with respect to the intrinsic preorder.

Because the intrinsic preorder on a predomain is a partial order by Proposition 4.1, we write f𝑓\bigvee f⋁ italic_f for the (necessarily unique) element defined in Proposition 4.9. We note that suprema of synthetic ω𝜔\omegaitalic_ω-chains in function spaces are computed pointwise.

4.4 Domains and admissibility

Semantically, recursive functions may be interpreted as the fixed points of endomaps of domains:

Definition 4.10.

A domain is a predomain equipped with a 𝖫𝖫\mathsf{L}sansserif_L-algebra structure. Every domain D𝐷Ditalic_D contains a least element given by postcomposing the algebra map with the unique undefined element (,!):1𝖫D(\bot,!):1\to\mathsf{L}D( ⊥ , ! ) : 1 → sansserif_L italic_D. We write D:D\bot_{D}:D⊥ start_POSTSUBSCRIPT italic_D end_POSTSUBSCRIPT : italic_D for the least element of D𝐷Ditalic_D.

Proposition 4.11.

Given a map of domains f:DD:𝑓𝐷𝐷f:D\to Ditalic_f : italic_D → italic_D, there is an element 𝖿𝗂𝗑(f):D:𝖿𝗂𝗑𝑓𝐷\mathsf{fix}(f):Dsansserif_fix ( italic_f ) : italic_D such that 𝖿𝗂𝗑(f)𝖿𝗂𝗑𝑓\mathsf{fix}(f)sansserif_fix ( italic_f ) is the least fixed-point of f𝑓fitalic_f.

Similar to classical domains, we may introduce a notion of “good subsets” of domains for which fixed-point induction is valid.

Definition 4.12.

A subset of a domain D𝐷Ditalic_D is admissible when it contains Dsubscriptbottom𝐷\bot_{D}⊥ start_POSTSUBSCRIPT italic_D end_POSTSUBSCRIPT and is closed under suprema of synthetic ω𝜔\omegaitalic_ω-chains.

Proposition 4.13 (Fixed-point induction).

Given an admissible subset AD𝐴𝐷A\subseteq Ditalic_A ⊆ italic_D of a domain D𝐷Ditalic_D and f:DD:𝑓𝐷𝐷f:D\to Ditalic_f : italic_D → italic_D, to show that 𝖿𝗂𝗑(f)A𝖿𝗂𝗑𝑓𝐴\mathsf{fix}(f)\in Asansserif_fix ( italic_f ) ∈ italic_A it suffices to show that xA𝑥𝐴x\in Aitalic_x ∈ italic_A implies fxA𝑓𝑥𝐴f~{}x\in Aitalic_f italic_x ∈ italic_A.

4.5 Monotonicity and continuity

As we discussed in Section 1.2.2, one of the main benefits of working in a synthetic domain theory is that maps are automatically compatible with the derived order structure:

Proposition 4.14.

Every map f:AB:𝑓𝐴𝐵f:A\to Bitalic_f : italic_A → italic_B between predomains is monotone in the synthetic order.

Proposition 4.15.

Every map f:AB:𝑓𝐴𝐵f:A\to Bitalic_f : italic_A → italic_B between predomains is continuous in the sense that f(d)=(fd)𝑓𝑑𝑓𝑑f(\bigvee d)=\bigvee(f\circ d)italic_f ( ⋁ italic_d ) = ⋁ ( italic_f ∘ italic_d ) for every synthetic ω𝜔\omegaitalic_ω-chain d:ωA:𝑑𝜔𝐴d:\omega\to Aitalic_d : italic_ω → italic_A.

5 PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT: a language for cost-aware higher-order recursion

Our main technical result is the computational adequacy property for PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT, a version of Plotkin’s PCF [22] equipped with an abstract cost effect. The treatment of both cost structure and recursion as a call-by-push-value effect in PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT is inspired by [13]. The syntax of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT is parameterized in a monoid \mathbb{C}blackboard_C representing the cost structure; in Section 6 we will impose further properties on \mathbb{C}blackboard_C when we define the denotational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT. As mentioned in Section 2.1, the type structure of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT is generated by a pair of operators 𝖥,𝖴𝖥𝖴\mathsf{F},\mathsf{U}sansserif_F , sansserif_U that corresponds semantically to the free-forgetful adjunction between plain sets and the category of partial cost algebras, which are sets equipped with an action for the partial cost monad 𝖫(×)\mathsf{L}(\mathbb{C}\times-)sansserif_L ( blackboard_C × - ). The types and terms of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT are summarized in Fig. 1, defined as inductive definitions in the SDT topos \mathscr{E}script_E.

  • inductive𝖳𝗒+:𝖲𝖾𝗍where:inductivesuperscript𝖳𝗒𝖲𝖾𝗍where\textbf{inductive}~{}\mathsf{Ty}^{+}:\mathsf{Set}~{}\textbf{where}inductive sansserif_Ty start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT : sansserif_Set where

    • 𝖺𝗇𝗌:𝖳𝗒+:𝖺𝗇𝗌superscript𝖳𝗒\mathsf{ans}:\mathsf{Ty}^{+}sansserif_ans : sansserif_Ty start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT

    • 𝗇𝖺𝗍:𝖳𝗒+:𝗇𝖺𝗍superscript𝖳𝗒\mathsf{nat}:\mathsf{Ty}^{+}sansserif_nat : sansserif_Ty start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT

    • 𝖴:𝖳𝗒𝖳𝗒+:𝖴superscript𝖳𝗒symmetric-differencesuperscript𝖳𝗒\mathsf{U}:\mathsf{Ty}^{\ominus}\to\mathsf{Ty}^{+}sansserif_U : sansserif_Ty start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT → sansserif_Ty start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT

  • inductive𝖳𝗒:𝗍𝗉+where:inductivesuperscript𝖳𝗒symmetric-differencesuperscript𝗍𝗉where\textbf{inductive}~{}\mathsf{Ty}^{\ominus}:\mathsf{tp}^{+}~{}\textbf{where}inductive sansserif_Ty start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT : sansserif_tp start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT where

    • 𝖥:𝖳𝗒+𝖳𝗒:𝖥superscript𝖳𝗒superscript𝖳𝗒symmetric-difference\mathsf{F}:\mathsf{Ty}^{+}\to\mathsf{Ty}^{\ominus}sansserif_F : sansserif_Ty start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT → sansserif_Ty start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT

    • :𝖳𝗒+𝖳𝗒𝖳𝗒{\rightharpoonup}:\mathsf{Ty}^{+}\to\mathsf{Ty}^{\ominus}\to\mathsf{Ty}^{\ominus}⇀ : sansserif_Ty start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT → sansserif_Ty start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT → sansserif_Ty start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT

  • 𝖳𝗆:𝖢𝗈𝗇𝖳𝗒𝗍𝗉+:superscript𝖳𝗆symmetric-difference𝖢𝗈𝗇superscript𝖳𝗒symmetric-differencesuperscript𝗍𝗉\mathsf{Tm}^{\ominus}:\mathsf{Con}\to\mathsf{Ty}^{\ominus}\to\mathsf{tp}^{+}sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT : sansserif_Con → sansserif_Ty start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT → sansserif_tp start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT

  • 𝖳𝗆(Γ,X)=𝖳𝗆+(Γ,𝖴(X))superscript𝖳𝗆symmetric-differenceΓ𝑋superscript𝖳𝗆Γ𝖴𝑋\mathsf{Tm}^{\ominus}(\Gamma,X)=\mathsf{Tm}^{+}(\Gamma,\mathsf{U}(X))sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_X ) = sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , sansserif_U ( italic_X ) )

  • inductive𝖳𝗆+:𝖢𝗈𝗇𝖳𝗒+𝖲𝖾𝗍where:inductivesuperscript𝖳𝗆𝖢𝗈𝗇superscript𝖳𝗒𝖲𝖾𝗍where\textbf{inductive}~{}\mathsf{Tm}^{+}:\mathsf{Con}\to\mathsf{Ty}^{+}\to\mathsf{% Set}~{}\textbf{where}inductive sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT : sansserif_Con → sansserif_Ty start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT → sansserif_Set where

    • 𝗏𝖺𝗋:𝖵𝖺𝗋(Γ,A)𝖳𝗆(Γ,A):𝗏𝖺𝗋𝖵𝖺𝗋Γ𝐴𝖳𝗆Γ𝐴\mathsf{var}:\mathsf{Var}(\Gamma,A)\to\mathsf{Tm}(\Gamma,A)sansserif_var : sansserif_Var ( roman_Γ , italic_A ) → sansserif_Tm ( roman_Γ , italic_A )

    • 𝗒𝖾𝗌:𝖳𝗆+(Γ,𝖺𝗇𝗌):𝗒𝖾𝗌superscript𝖳𝗆Γ𝖺𝗇𝗌\mathsf{yes}:\mathsf{Tm}^{+}(\Gamma,\mathsf{ans})sansserif_yes : sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , sansserif_ans )

    • 𝗇𝗈:𝖳𝗆+(Γ,𝖺𝗇𝗌):𝗇𝗈superscript𝖳𝗆Γ𝖺𝗇𝗌\mathsf{no}:\mathsf{Tm}^{+}(\Gamma,\mathsf{ans})sansserif_no : sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , sansserif_ans )

    • 𝗓𝖾𝗋𝗈:𝖳𝗆+(Γ,𝗇𝖺𝗍):𝗓𝖾𝗋𝗈superscript𝖳𝗆Γ𝗇𝖺𝗍\mathsf{zero}:\mathsf{Tm}^{+}(\Gamma,\mathsf{nat})sansserif_zero : sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , sansserif_nat )

    • 𝗌𝗎𝖼𝖼:𝖳𝗆+(Γ,𝗇𝖺𝗍)𝖳𝗆+(Γ,𝗇𝖺𝗍):𝗌𝗎𝖼𝖼superscript𝖳𝗆Γ𝗇𝖺𝗍superscript𝖳𝗆Γ𝗇𝖺𝗍\mathsf{succ}:\mathsf{Tm}^{+}(\Gamma,\mathsf{nat})\to\mathsf{Tm}^{+}(\Gamma,% \mathsf{nat})sansserif_succ : sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , sansserif_nat ) → sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , sansserif_nat )

    • 𝖺𝗉:𝖳𝗆(Γ,AX)𝖳𝗆+(Γ,A)𝖳𝗆(X):𝖺𝗉superscript𝖳𝗆symmetric-differenceΓ𝐴𝑋superscript𝖳𝗆Γ𝐴superscript𝖳𝗆symmetric-difference𝑋\mathsf{ap}:\mathsf{Tm}^{\ominus}(\Gamma,A\rightharpoonup X)\to\mathsf{Tm}^{+}% (\Gamma,A)\to\mathsf{Tm}^{\ominus}(X)sansserif_ap : sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_A ⇀ italic_X ) → sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , italic_A ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( italic_X )

    • 𝗋𝖾𝗍:𝖳𝗆+(Γ,A)𝖳𝗆(Γ,𝖥(A)):𝗋𝖾𝗍superscript𝖳𝗆Γ𝐴superscript𝖳𝗆symmetric-differenceΓ𝖥𝐴\mathsf{ret}:\mathsf{Tm}^{+}(\Gamma,A)\to\mathsf{Tm}^{\ominus}(\Gamma,\mathsf{% F}(A))sansserif_ret : sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , italic_A ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , sansserif_F ( italic_A ) )

    • 𝗌𝗍𝖾𝗉:𝖳𝗆(Γ,X)𝖳𝗆(Γ,X):𝗌𝗍𝖾𝗉superscript𝖳𝗆symmetric-differenceΓ𝑋superscript𝖳𝗆symmetric-differenceΓ𝑋\mathsf{step}:\mathbb{C}\to\mathsf{Tm}^{\ominus}(\Gamma,X)\to\mathsf{Tm}^{% \ominus}(\Gamma,X)sansserif_step : blackboard_C → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_X ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_X )

    • 𝖻𝗂𝗇𝖽:𝖳𝗆(Γ,𝖥(A))𝖳𝗆(A::Γ,X)𝖳𝗆(Γ,X)\mathsf{bind}:\mathsf{Tm}^{\ominus}(\Gamma,\mathsf{F}(A))\to\mathsf{Tm}^{% \ominus}(A::\Gamma,X)\to\mathsf{Tm}^{\ominus}(\Gamma,X)sansserif_bind : sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , sansserif_F ( italic_A ) ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( italic_A : : roman_Γ , italic_X ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_X )

    • 𝗂𝖿𝗓:𝖳𝗆+(Γ,𝗇𝖺𝗍)𝖳𝗆(Γ,X)𝖳𝗆(𝗇𝖺𝗍::Γ,X)𝖳𝗆(Γ,X)\mathsf{ifz}:\mathsf{Tm}^{+}(\Gamma,\mathsf{nat})\to\mathsf{Tm}^{\ominus}(% \Gamma,X)\to\mathsf{Tm}^{\ominus}(\mathsf{nat}::\Gamma,X)\to\mathsf{Tm}^{% \ominus}(\Gamma,X)sansserif_ifz : sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( roman_Γ , sansserif_nat ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_X ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( sansserif_nat : : roman_Γ , italic_X ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_X )

    • 𝖿𝗂𝗑:𝖳𝗆(𝖴(X)::Γ,X)𝖳𝗆(Γ,X)\mathsf{fix}:\mathsf{Tm}^{\ominus}(\mathsf{U}(X)::\Gamma,X)\to\mathsf{Tm}^{% \ominus}(\Gamma,X)sansserif_fix : sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( sansserif_U ( italic_X ) : : roman_Γ , italic_X ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_X )

    • 𝗅𝖺𝗆:𝖳𝗆(A::Γ,X)𝖳𝗆(Γ,AX)\mathsf{lam}:\mathsf{Tm}^{\ominus}(A::\Gamma,X)\to\mathsf{Tm}^{\ominus}(\Gamma% ,A\rightharpoonup X)sansserif_lam : sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( italic_A : : roman_Γ , italic_X ) → sansserif_Tm start_POSTSUPERSCRIPT ⊖ end_POSTSUPERSCRIPT ( roman_Γ , italic_A ⇀ italic_X )

Figure 1: The grammar of types and terms in PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT. We will often omit 𝖳𝗆{+,}superscript𝖳𝗆symmetric-difference\mathsf{Tm}^{\{+,\ominus\}}sansserif_Tm start_POSTSUPERSCRIPT { + , ⊖ } end_POSTSUPERSCRIPT in the case of closed terms and write Γ{A,X}provesΓ𝐴𝑋\Gamma\vdash\{A,X\}roman_Γ ⊢ { italic_A , italic_X } for the type 𝖳𝗆{+,}(Γ,{A,X})superscript𝖳𝗆symmetric-differenceΓ𝐴𝑋\mathsf{Tm}^{\{+,\ominus\}}(\Gamma,\{A,X\})sansserif_Tm start_POSTSUPERSCRIPT { + , ⊖ } end_POSTSUPERSCRIPT ( roman_Γ , { italic_A , italic_X } ). Given e:𝖴𝖥A:𝑒𝖴𝖥𝐴e:\mathsf{U}\mathsf{F}Aitalic_e : sansserif_UF italic_A and f:𝖴(AX):𝑓𝖴𝐴𝑋f:\mathsf{U}(A\to X)italic_f : sansserif_U ( italic_A → italic_X ), we also write e;f𝑒𝑓e;fitalic_e ; italic_f for 𝖻𝗂𝗇𝖽(e,f):𝖴X:𝖻𝗂𝗇𝖽𝑒𝑓𝖴𝑋\mathsf{bind}(e,f):\mathsf{U}Xsansserif_bind ( italic_e , italic_f ) : sansserif_U italic_X.

6 Cost-aware denotational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT

Both the syntax of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT and our model construction is parameterized in a monoid object (,+,0)0(\mathbb{C},+,0)( blackboard_C , + , 0 ) representing the cost structure. We require the following conditions to hold:

  1. \normalshape(1)

    Computational: \mathbb{C}blackboard_C is a predomain with ΣΣ\Sigmaroman_Σ-equality.

  2. \normalshape(2)

    Phase separation: \mathbb{C}blackboard_C is purely intensional, i.e. ()11(\P\to\mathbb{C})\cong 1( ¶ → blackboard_C ) ≅ 1.

That \mathbb{C}blackboard_C is computational are used in two places in the computational adequacy proof: when reasoning about the computational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT (see Section 7), we need \mathbb{C}blackboard_C to be discrete (which follows from Proposition 4.4) in order to prove the property that sequential composition of computations may be decomposed (Proposition 7.4), and we need \mathbb{C}blackboard_C to have ΣΣ\Sigmaroman_Σ-equality when showing that the formal approximation predicates (see Fig. 5) associated to semantic domains are admissible. We require \mathbb{C}blackboard_C to be purely intensional to ensure that the denotational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT exhibits an intrinsic noninterference property of cost and behavior as sketched in Section 2.1. As discussed in Section 3.4, there is a canonical way of turning any monoid \mathcal{M}caligraphic_M into a purely intensional type by means of the sealing monad \P\vee-¶ ∨ -.

6.1 The partial cost monad

To model partiality and cost as a single effect, the computation types of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT are interpreted as algebras for the monad (𝕋,η𝕋,μ𝕋)𝕋subscript𝜂𝕋subscript𝜇𝕋(\mathbb{T},\eta_{\mathbb{T}},\mu_{\mathbb{T}})( blackboard_T , italic_η start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT , italic_μ start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT ) whose action on points is defined by composing the lift and the writer monad 𝖳A=𝖫(×A)𝖳𝐴𝖫𝐴\mathsf{T}A=\mathsf{L}(\mathbb{C}\times A)sansserif_T italic_A = sansserif_L ( blackboard_C × italic_A ). The distributive law for 𝖳𝖳\mathsf{T}sansserif_T and the resulting monad structure is displayed in Fig. 2, where we write x𝕄e;f(x)subscript𝕄𝑥𝑒𝑓𝑥x\leftarrow_{\mathbb{M}}e;f(x)italic_x ← start_POSTSUBSCRIPT blackboard_M end_POSTSUBSCRIPT italic_e ; italic_f ( italic_x ) for the induced bind operation of a monad 𝕄𝕄\mathbb{M}blackboard_M where f:A𝖬(B):𝑓𝐴𝖬𝐵f:A\to\mathsf{M}(B)italic_f : italic_A → sansserif_M ( italic_B ) is a map into a free 𝕄𝕄\mathbb{M}blackboard_M-algebra. We will also write f(e)superscript𝑓𝑒f^{\sharp}(e)italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_e ) for sequencing e:𝖬(A):𝑒𝖬𝐴e:\mathsf{M}(A)italic_e : sansserif_M ( italic_A ) and f:AX:𝑓𝐴𝑋f:A\to Xitalic_f : italic_A → italic_X for an 𝕄𝕄\mathbb{M}blackboard_M-algebra X𝑋Xitalic_X.

  • τ:×𝖫A𝖫(×A):𝜏𝖫𝐴𝖫𝐴\tau:\mathbb{C}\times\mathsf{L}A\to\mathsf{L}(\mathbb{C}\times A)italic_τ : blackboard_C × sansserif_L italic_A → sansserif_L ( blackboard_C × italic_A )

  • τ(c,(ϕ,f))=(ϕ,λu:ϕ.(c,fu))\tau(c,(\phi,f))=(\phi,\lambda u:\phi.~{}(c,fu))italic_τ ( italic_c , ( italic_ϕ , italic_f ) ) = ( italic_ϕ , italic_λ italic_u : italic_ϕ . ( italic_c , italic_f italic_u ) )

  • η𝕋(a)=η𝖫(0,a)subscript𝜂𝕋𝑎subscript𝜂𝖫0𝑎\eta_{\mathbb{T}}(a)=\eta_{\mathsf{L}}(0,a)italic_η start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT ( italic_a ) = italic_η start_POSTSUBSCRIPT sansserif_L end_POSTSUBSCRIPT ( 0 , italic_a )

  • μ𝕋(e)=(c,x)𝕃e;(c,a)𝕃x;(c+c,a)formulae-sequencesubscript𝜇𝕋𝑒𝑐𝑥subscript𝕃𝑒subscript𝕃superscript𝑐𝑎𝑥𝑐superscript𝑐𝑎\mu_{\mathbb{T}}(e)=(c,x)\leftarrow_{\mathbb{L}}e;(c^{\prime},a)\leftarrow_{% \mathbb{L}}x;(c+c^{\prime},a)italic_μ start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT ( italic_e ) = ( italic_c , italic_x ) ← start_POSTSUBSCRIPT blackboard_L end_POSTSUBSCRIPT italic_e ; ( italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_a ) ← start_POSTSUBSCRIPT blackboard_L end_POSTSUBSCRIPT italic_x ; ( italic_c + italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_a )

Figure 2: Left: distributive law; right: monad structure of 𝕋𝕋\mathbb{T}blackboard_T.

6.2 The derived cost algebra

To model the cost effect 𝗌𝗍𝖾𝗉:×XX:𝗌𝗍𝖾𝗉𝑋𝑋\mathsf{step}:\mathbb{C}\times X\to Xsansserif_step : blackboard_C × italic_X → italic_X, we use the fact that every algebra for 𝕋𝕋\mathbb{T}blackboard_T is canonically an algebra for the writer monad ×\mathbb{C}\times-blackboard_C × -, which is a general property of composite monads defined from a distributive law [1, Section 2]. In our case this means that every 𝕋𝕋\mathbb{T}blackboard_T-algebra has an underlying cost algebra as well; we write :×XX\boxplus:\mathbb{C}\times X\to X⊞ : blackboard_C × italic_X → italic_X for the cost algebra map.

Proposition 6.1.

The action of the derived cost algebra satisfies the following equations for e:𝖳(A):𝑒𝖳𝐴e:\mathsf{T}(A)italic_e : sansserif_T ( italic_A ) and f:AX:𝑓𝐴𝑋f:A\to Xitalic_f : italic_A → italic_X for some 𝕋𝕋\mathbb{T}blackboard_T-algebra X𝑋Xitalic_X:

c𝖳(A)e=(e,λu.μ×(c,e))\displaystyle c\boxplus_{\mathsf{T}(A)}e=(e{\downarrow},\lambda u.~{}\mu_{% \mathbb{C}\times-}(c,e))italic_c ⊞ start_POSTSUBSCRIPT sansserif_T ( italic_A ) end_POSTSUBSCRIPT italic_e = ( italic_e ↓ , italic_λ italic_u . italic_μ start_POSTSUBSCRIPT blackboard_C × - end_POSTSUBSCRIPT ( italic_c , italic_e ) )
f(c𝖳(A)e)=cX(fe)superscript𝑓subscript𝖳𝐴𝑐𝑒subscript𝑋𝑐superscript𝑓𝑒\displaystyle f^{\sharp}(c\boxplus_{\mathsf{T}(A)}e)=c\boxplus_{X}(f^{\sharp}~% {}e)italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_c ⊞ start_POSTSUBSCRIPT sansserif_T ( italic_A ) end_POSTSUBSCRIPT italic_e ) = italic_c ⊞ start_POSTSUBSCRIPT italic_X end_POSTSUBSCRIPT ( italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT italic_e )
(cAXf)a=cX(fa)subscript𝐴𝑋𝑐𝑓𝑎subscript𝑋𝑐𝑓𝑎\displaystyle(c\boxplus_{A\to X}f)~{}a=c\boxplus_{X}(f~{}a)( italic_c ⊞ start_POSTSUBSCRIPT italic_A → italic_X end_POSTSUBSCRIPT italic_f ) italic_a = italic_c ⊞ start_POSTSUBSCRIPT italic_X end_POSTSUBSCRIPT ( italic_f italic_a )

6.3 Denotational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT

The semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT is based around the free-forgetful adjunction associated with the partial cost monad in which value types are predomains and computation types are 𝕋𝕋\mathbb{T}blackboard_T-algebra valued in predomains. The essential parts of the model is displayed in Fig. 3. Most of the type structure of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT is interpreted using the cartesian closed structure of predomains; note that the numerals type is interpreted as the natural numbers type of predomains 𝖯subscript𝖯{\mathbb{N}}_{\mathsf{P}}blackboard_N start_POSTSUBSCRIPT sansserif_P end_POSTSUBSCRIPT, which is not the same as the ambient natural numbers {\mathbb{N}}blackboard_N.

  • :𝗍𝗉+𝒰𝗉𝗋𝖾𝖽𝗈𝗆\llbracket-\rrbracket:\mathsf{tp}^{+}\to\mathcal{U}_{\mathsf{predom}}⟦ - ⟧ : sansserif_tp start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT → caligraphic_U start_POSTSUBSCRIPT sansserif_predom end_POSTSUBSCRIPT

  • :𝗍𝗉𝖠𝗅𝗀𝕋(𝒰𝗉𝗋𝖾𝖽𝗈𝗆)\llbracket-\rrbracket:\mathsf{tp}^{-}\to\mathsf{Alg}_{\mathsf{\mathbb{T}}}(% \mathcal{U}_{\mathsf{predom}})⟦ - ⟧ : sansserif_tp start_POSTSUPERSCRIPT - end_POSTSUPERSCRIPT → sansserif_Alg start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT ( caligraphic_U start_POSTSUBSCRIPT sansserif_predom end_POSTSUBSCRIPT )

  • 𝖥A=𝖳(A)\llbracket\mathsf{F}A\rrbracket=\mathsf{T}(\llbracket A\rrbracket)⟦ sansserif_F italic_A ⟧ = sansserif_T ( ⟦ italic_A ⟧ )

  • 𝖴X=U(X)\llbracket\mathsf{U}X\rrbracket=U(\llbracket X\rrbracket)⟦ sansserif_U italic_X ⟧ = italic_U ( ⟦ italic_X ⟧ )

  • 1=1\llbracket 1\rrbracket=1⟦ 1 ⟧ = 1

  • 𝖺𝗇𝗌=2\llbracket\mathsf{ans}\rrbracket=2⟦ sansserif_ans ⟧ = 2

  • 𝗇𝖺𝗍=𝖯\llbracket\mathsf{nat}\rrbracket={\mathbb{N}}_{\mathsf{P}}⟦ sansserif_nat ⟧ = blackboard_N start_POSTSUBSCRIPT sansserif_P end_POSTSUBSCRIPT

  • AX=AX\llbracket A\rightharpoonup X\rrbracket=\llbracket A\rrbracket\to\llbracket X\rrbracket⟦ italic_A ⇀ italic_X ⟧ = ⟦ italic_A ⟧ → ⟦ italic_X ⟧

  • :{Γ,A}(ΓA)ΓA\llbracket-\rrbracket:\{\Gamma,A\}(\Gamma\vdash A)\to\llbracket\Gamma% \rrbracket\to\llbracket A\rrbracket⟦ - ⟧ : { roman_Γ , italic_A } ( roman_Γ ⊢ italic_A ) → ⟦ roman_Γ ⟧ → ⟦ italic_A ⟧

  • :{Γ,A}(ΓX)ΓU(X)\llbracket-\rrbracket:\{\Gamma,A\}(\Gamma\vdash X)\to\llbracket\Gamma% \rrbracket\to U(\llbracket X\rrbracket)⟦ - ⟧ : { roman_Γ , italic_A } ( roman_Γ ⊢ italic_X ) → ⟦ roman_Γ ⟧ → italic_U ( ⟦ italic_X ⟧ )

  • 𝗋𝖾𝗍(a)(γ)=η𝕋(a(γ))\llbracket\mathsf{ret}(a)\rrbracket(\gamma)=\eta_{\mathbb{T}}(\llbracket a% \rrbracket(\gamma))⟦ sansserif_ret ( italic_a ) ⟧ ( italic_γ ) = italic_η start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT ( ⟦ italic_a ⟧ ( italic_γ ) )

  • 𝗌𝗍𝖾𝗉(c,e)(γ)=ce(γ)\llbracket\mathsf{step}(c,e)\rrbracket(\gamma)=c\boxplus\llbracket e\rrbracket% (\gamma)⟦ sansserif_step ( italic_c , italic_e ) ⟧ ( italic_γ ) = italic_c ⊞ ⟦ italic_e ⟧ ( italic_γ )

  • 𝖻𝗂𝗇𝖽(e,f)(γ)=𝖻𝗂𝗇𝖽(e(γ),λa.f(a,γ))\llbracket\mathsf{bind}(e,f)\rrbracket(\gamma)=\mathsf{bind}(\llbracket e% \rrbracket(\gamma),\lambda a.~{}\llbracket f\rrbracket(a,\gamma))⟦ sansserif_bind ( italic_e , italic_f ) ⟧ ( italic_γ ) = sansserif_bind ( ⟦ italic_e ⟧ ( italic_γ ) , italic_λ italic_a . ⟦ italic_f ⟧ ( italic_a , italic_γ ) )

  • 𝖿𝗂𝗑(f)(γ)=𝖿𝗂𝗑(λx.f(x,γ))\llbracket\mathsf{fix}(f)\rrbracket(\gamma)=\mathsf{fix}(\lambda x.~{}% \llbracket f\rrbracket(x,\gamma))⟦ sansserif_fix ( italic_f ) ⟧ ( italic_γ ) = sansserif_fix ( italic_λ italic_x . ⟦ italic_f ⟧ ( italic_x , italic_γ ) )

Figure 3: Selected clauses of the model; in the above we write U(X)𝑈𝑋U(X)italic_U ( italic_X ) for the carrier of a 𝕋𝕋\mathbb{T}blackboard_T-algebra X𝑋Xitalic_X.

7 Computational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT

Computational adequacy is a property relating the denotational semantics of a language with its execution behavior as given by an operational semantics. Commonly one employs a structural operational semantics [21] in which the operational semantics of a language is defined as an inductive family of relations AA×A{\mapsto_{A}}\subseteq A\times A↦ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT ⊆ italic_A × italic_A. Both termination and evaluation can be defined by means of the reflexive transitive closure of the family of relations Asubscriptmaps-to𝐴\mapsto_{A}↦ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT, which is the smallest reflexive, transitive family of relations containing Asubscriptmaps-to𝐴\mapsto_{A}↦ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT.

Computational semantics. We consider an alternative formulation of the dynamic semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in which execution is modeled not as an inductive family but directly as a (partial) computation. This departure from traditional operational semantics is necessitated by our proof of computational adequacy. As we explain in Section 8.2, termination must be a predicate valued in ΣΣ\Sigmaroman_Σ-propositions; however, the reflexive-transitive closure of a decidable relation (such as Asubscriptmaps-to𝐴\mapsto_{A}↦ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT) can only be seen to be a ΣΣ\Sigmaroman_Σ-predicate assuming that ΣΣ\Sigmaroman_Σ is closed under countable joins of decidable propositions that are preserved by the inclusion into the ambient type theory, i.e. [n:]ϕ(n)Σ\exists[n:{\mathbb{N}}]~{}\phi(n)\in\Sigma∃ [ italic_n : blackboard_N ] italic_ϕ ( italic_n ) ∈ roman_Σ for every countable family of ΣΣ\Sigmaroman_Σ-propositions ϕitalic-ϕ\phiitalic_ϕ. Our approach bypasses this question by de-emphasizing {\mathbb{N}}blackboard_N in favor of the initial lifting algebra ω𝜔\omegaitalic_ω, a lesson of Simpson [28]. We discuss the relationship between this computational semantics and ordinary operational semantics in Section 11.

7.1 Computational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT

{mathpar}\inferrule

𝖻𝗂𝗇𝖽𝖻𝗂𝗇𝖽\mathsf{bind}sansserif_bind(𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(a), f) ↦0, f(a)

\inferrule

𝖺𝗉𝖺𝗉\mathsf{ap}sansserif_ap(𝗅𝖺𝗆𝗅𝖺𝗆\mathsf{lam}sansserif_lam(e), e_1) ↦0, e(e_1)

\inferrule

𝖿𝗂𝗑𝖿𝗂𝗑\mathsf{fix}sansserif_fix(e) ↦0, e(𝖿𝗂𝗑𝖿𝗂𝗑\mathsf{fix}sansserif_fix(e))

\inferrule

𝗂𝖿𝗓𝗂𝖿𝗓\mathsf{ifz}sansserif_ifz(𝗓𝖾𝗋𝗈𝗓𝖾𝗋𝗈\mathsf{zero}sansserif_zero, e_0, e_1) ↦0, e_0

\inferrule

𝗂𝖿𝗓𝗂𝖿𝗓\mathsf{ifz}sansserif_ifz(𝗌𝗎𝖼𝖼𝗌𝗎𝖼𝖼\mathsf{succ}sansserif_succ(v), e_0, e_1) ↦0, e_1(v)

\inferrule

𝗌𝗍𝖾𝗉𝗌𝗍𝖾𝗉\mathsf{step}sansserif_step^c(e) ↦c, e

Figure 4: Rules for the small-step transition relation.

We begin with a family of small-step transition relations A𝖳𝗆+(A)××𝖳𝗆+(A){\mapsto_{A}}\subseteq\mathsf{Tm}^{+}(A)\times\mathbb{C}\times\mathsf{Tm}^{+}(A)↦ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT ⊆ sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( italic_A ) × blackboard_C × sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( italic_A ) that implements the cost effect model in the sense of Hoffmann [10]. The intuitive meaning of ec,emaps-to𝑒𝑐superscript𝑒e\mapsto c,e^{\prime}italic_e ↦ italic_c , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT is that e𝑒eitalic_e transitions in one step to esuperscript𝑒e^{\prime}italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and incurs cost c𝑐citalic_c; the only place where cost is effected is at 𝗌𝗍𝖾𝗉𝗌𝗍𝖾𝗉\mathsf{step}sansserif_step: 𝗌𝗍𝖾𝗉c(e)c,emaps-tosuperscript𝗌𝗍𝖾𝗉𝑐𝑒𝑐𝑒\mathsf{step}^{c}(e)\mapsto c,esansserif_step start_POSTSUPERSCRIPT italic_c end_POSTSUPERSCRIPT ( italic_e ) ↦ italic_c , italic_e. The family of relations Asubscriptmaps-to𝐴\mapsto_{A}↦ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT is defined as an inductive family whose generators are displayed in Fig. 4 (the expected congruence rules have been omitted). We iterate the “one step” relation to obtain the partial map implementing the computational semantics. Because Asubscriptmaps-to𝐴\mapsto_{A}↦ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT is decidable, we have a characteristic map 𝗈𝗎𝗍:{A:𝗍𝗉+}.𝖳𝗆+(A)1+(×𝖳𝗆+(A))\mathsf{out}:\{A:\mathsf{tp}^{+}\}.~{}\mathsf{Tm}^{+}(A)\to 1+(\mathbb{C}% \times\mathsf{Tm}^{+}(A))sansserif_out : { italic_A : sansserif_tp start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT } . sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( italic_A ) → 1 + ( blackboard_C × sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( italic_A ) ). Consider the following functional:

Φ𝖾𝗏𝖺𝗅f(e,v)={cf(e,v)𝗈𝗎𝗍(e)=𝗂𝗇𝗋(c,e)(e=v,λ.0)𝗈𝗎𝗍(e)=𝗂𝗇𝗅\displaystyle\Phi_{\mathsf{eval}}~{}f~{}(e,v)=\begin{cases}c\boxplus f(e^{% \prime},v)&\mathsf{out}(e)=\mathsf{inr}\cdot(c,e^{\prime})\\ (e=v,\lambda-.~{}0)&\mathsf{out}(e)=\mathsf{inl}\cdot\star\end{cases}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT italic_f ( italic_e , italic_v ) = { start_ROW start_CELL italic_c ⊞ italic_f ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_v ) end_CELL start_CELL sansserif_out ( italic_e ) = sansserif_inr ⋅ ( italic_c , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) end_CELL end_ROW start_ROW start_CELL ( italic_e = italic_v , italic_λ - . 0 ) end_CELL start_CELL sansserif_out ( italic_e ) = sansserif_inl ⋅ ⋆ end_CELL end_ROW

Define 𝖾𝗏𝖺𝗅:{A:𝗍𝗉+}.𝖳𝗆+(A)×𝖳𝗆+(A)𝖳(1)\mathsf{eval}:\{A:\mathsf{tp}^{+}\}.~{}\mathsf{Tm}^{+}(A)\times\mathsf{Tm}^{+}% (A)\to\mathsf{T}(1)sansserif_eval : { italic_A : sansserif_tp start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT } . sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( italic_A ) × sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( italic_A ) → sansserif_T ( 1 ) to be the fixed-point of Φ𝖾𝗏𝖺𝗅subscriptΦ𝖾𝗏𝖺𝗅\Phi_{\mathsf{eval}}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾:𝗍𝗆+(𝖴𝖥1)𝖳(1):𝗉𝗋𝗈𝖿𝗂𝗅𝖾superscript𝗍𝗆𝖴𝖥1𝖳1\mathsf{profile}:\mathsf{tm}^{+}(\mathsf{U}\mathsf{F}1)\to\mathsf{T}(1)sansserif_profile : sansserif_tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( sansserif_UF 1 ) → sansserif_T ( 1 ) as 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e)=𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍())𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍\mathsf{profile}(e)=\mathsf{eval}(e,\mathsf{ret}(\star))sansserif_profile ( italic_e ) = sansserif_eval ( italic_e , sansserif_ret ( ⋆ ) ). The meaning of 𝖾𝗏𝖺𝗅A(e,v):𝖳(1):subscript𝖾𝗏𝖺𝗅𝐴𝑒𝑣𝖳1\mathsf{eval}_{A}(e,v):\mathsf{T}(1)sansserif_eval start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT ( italic_e , italic_v ) : sansserif_T ( 1 ) is that when it is defined, e𝑒eitalic_e computes to a value v𝑣vitalic_v incurring the defined cost. Similarly, 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒\mathsf{profile}(e)sansserif_profile ( italic_e ) is the cost of computing e𝑒eitalic_e when the former is defined. In the following, we will establish some expected properties of the computational semantics such as the uniqueness of evaluation and a “big-step” law for sequencing evaluations.

Proposition 7.1.

The relation π1𝖾𝗏𝖺𝗅subscript𝜋1𝖾𝗏𝖺𝗅\pi_{1}\circ\mathsf{eval}italic_π start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT ∘ sansserif_eval is functional, i.e. 𝖾𝗏𝖺𝗅(e,v)absent𝖾𝗏𝖺𝗅𝑒𝑣{\downarrow}{\mathsf{eval}(e,v)}↓ sansserif_eval ( italic_e , italic_v ) and 𝖾𝗏𝖺𝗅(e,v)absent𝖾𝗏𝖺𝗅𝑒superscript𝑣{\downarrow}{\mathsf{eval}(e,v^{\prime})}↓ sansserif_eval ( italic_e , italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) implies v=v𝑣superscript𝑣v=v^{\prime}italic_v = italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

Proposition 7.2.

If 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))=c1𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍𝑣subscript𝑐1\mathsf{eval}(e,\mathsf{ret}(v))=c_{1}sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) = italic_c start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and 𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))=c2𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤subscript𝑐2\mathsf{eval}(g~{}v,\mathsf{ret}(w))=c_{2}sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) = italic_c start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT, then 𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))=c1+c2𝖾𝗏𝖺𝗅𝑒𝑔𝗋𝖾𝗍𝑤subscript𝑐1subscript𝑐2\mathsf{eval}(e;g,\mathsf{ret}(w))=c_{1}+c_{2}sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) = italic_c start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT + italic_c start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT.

Corollary 7.3.

If 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))=c1𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍𝑣subscript𝑐1\mathsf{eval}(e,\mathsf{ret}(v))=c_{1}sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) = italic_c start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(gv)=c2𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑔𝑣subscript𝑐2\mathsf{profile}(g~{}v)=c_{2}sansserif_profile ( italic_g italic_v ) = italic_c start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT, then 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;g)=c1+c2𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝑔subscript𝑐1subscript𝑐2\mathsf{profile}(e;g)=c_{1}+c_{2}sansserif_profile ( italic_e ; italic_g ) = italic_c start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT + italic_c start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT.

In ordinary operational semantics, one has the property that e;gv𝑒𝑔𝑣e;g\Downarrow vitalic_e ; italic_g ⇓ italic_v implies there exists a value w𝑤witalic_w such that ew𝑒𝑤e\Downarrow witalic_e ⇓ italic_w and g(w)v𝑔𝑤𝑣g(w)\Downarrow vitalic_g ( italic_w ) ⇓ italic_v. An analogous rule also holds for the computational semantics, except the value w𝑤witalic_w is not existentially quantified:

Proposition 7.4.

The following inference rule is valid for any ΣΣ\Sigmaroman_Σ-predicate φ𝜑\varphiitalic_φ: {mathpar} \inferrule [v:A]\forall[v:A]~{}∀ [ italic_v : italic_A ] 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(e, v){\downarrow} 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(g v, 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w)){\downarrow} φ(𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(e, v) + 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(g v, 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w))) 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(e; g, 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w)){\downarrow} φ(𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(e; g, 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w)))

Using this rule we may derive the following law for profiling compound sequences:

Proposition 7.5.

We have 𝗉𝗋𝗈𝖿𝗂𝗅𝖾((e;g);i)=𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;i))\mathsf{profile}((e;g);i)=\mathsf{profile}(e;(\lambda v.~{}g~{}v;i))sansserif_profile ( ( italic_e ; italic_g ) ; italic_i ) = sansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_i ) ).

8 Computational adequacy and noninterference

In this section we show that the computational and denotational semantics satisfy a tight correspondence at the type of observations: for every e:𝖴𝖥1:𝑒𝖴𝖥1e:\mathsf{U}\mathsf{F}1italic_e : sansserif_UF 1, we have that edelimited-⟦⟧𝑒\llbracket e\rrbracket⟦ italic_e ⟧ is Kleene equivalent to 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒\mathsf{profile}(e)sansserif_profile ( italic_e ) in the sense that the cost specified computationally and denotationally are equal whenever one of them is defined.

8.1 Soundness

In one direction, it is not too difficult to show soundness, which means that the computational steps are respected by the denotational semantics:

Proposition 8.1.

If ec,emaps-to𝑒𝑐superscript𝑒e\mapsto c,e^{\prime}italic_e ↦ italic_c , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, then e=ce\llbracket e\rrbracket=c\boxplus\llbracket e^{\prime}\rrbracket⟦ italic_e ⟧ = italic_c ⊞ ⟦ italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟧.

Theorem 8.2.

If 𝖾𝗏𝖺𝗅(e,v)𝖾𝗏𝖺𝗅𝑒𝑣absent\mathsf{eval}(e,v){\downarrow}sansserif_eval ( italic_e , italic_v ) ↓, then e=𝖾𝗏𝖺𝗅(e,v)v\llbracket e\rrbracket=\mathsf{eval}(e,v)\boxplus\llbracket v\rrbracket⟦ italic_e ⟧ = sansserif_eval ( italic_e , italic_v ) ⊞ ⟦ italic_v ⟧.

Corollary 8.3.

Given e:𝖴𝖥1:𝑒𝖴𝖥1e:\mathsf{U}\mathsf{F}1italic_e : sansserif_UF 1, we have 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e)e\mathsf{profile}(e)\sqsubseteq\llbracket e\rrbracketsansserif_profile ( italic_e ) ⊑ ⟦ italic_e ⟧.

8.2 Adequacy

Adequacy proper usually refers to the converse direction of the property stated in Corollary 8.3: definedness of the denotational semantics implies termination under the computational semantics. Our proof is based on a standard binary logical relations construction between the syntax and semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT (cf. Plotkin [22]). The logical relation consists of a family of relations AA×𝖳𝗆+(A){\lhd_{A}}\subseteq\llbracket A\rrbracket\times\mathsf{Tm}^{+}(A)⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT ⊆ ⟦ italic_A ⟧ × sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( italic_A ) indexed in the syntactic types A𝐴Aitalic_A of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT such that e𝖴𝖥1e\llbracket e\rrbracket\lhd_{\mathsf{U}\mathsf{F}1}e⟦ italic_e ⟧ ⊲ start_POSTSUBSCRIPT sansserif_UF 1 end_POSTSUBSCRIPT italic_e implies the computational adequacy property. The purpose of considering a family of relations is to provide a sufficient strengthening of the desired property to all types so that one may proceed by an inductive proof on the derivation of terms to show that eAe\llbracket e\rrbracket\lhd_{A}e⟦ italic_e ⟧ ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_e holds for every term e:A:𝑒𝐴e:Aitalic_e : italic_A. Due to the presence of fixed-point computations, we must show that 𝖴Xe-\lhd_{\mathsf{U}X}e- ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT italic_e is always an admissible subset of the domain Xdelimited-⟦⟧𝑋\llbracket X\rrbracket⟦ italic_X ⟧ in the sense of Definition 4.12. We define a family of relations called the formal approximation relations in Fig. 5 by induction on the structure of syntactic types and show that they satisfy the properties in the preceding discussion.

  • e𝟣e=subscriptsubgroup-of1𝑒superscript𝑒tope\lhd_{\mathsf{1}}e^{\prime}=\topitalic_e ⊲ start_POSTSUBSCRIPT sansserif_1 end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = ⊤

  • e𝖺𝗇𝗌e=(e¯=e)subscriptsubgroup-of𝖺𝗇𝗌𝑒superscript𝑒¯𝑒superscript𝑒e\lhd_{\mathsf{ans}}e^{\prime}=(\overline{e}=e^{\prime})italic_e ⊲ start_POSTSUBSCRIPT sansserif_ans end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = ( over¯ start_ARG italic_e end_ARG = italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT )

  • e𝗇𝖺𝗍e=(e=e)e\lhd_{\mathsf{nat}}e^{\prime}=(e=\llbracket e^{\prime}\rrbracket)italic_e ⊲ start_POSTSUBSCRIPT sansserif_nat end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = ( italic_e = ⟦ italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟧ )

  • e𝖴𝖥Ae=[f(A𝖺𝖽𝗊)f]𝖺𝖽𝗊(f(e),e;f)e\lhd_{\mathsf{U}\mathsf{F}A}e^{\prime}=\forall{\left[f\mathrel{(\lhd_{A}% \Rightarrow\mathsf{adq})}f^{\prime}\right]}~{}\mathsf{adq}(f^{\sharp}(e),e^{% \prime};f^{\prime})italic_e ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = ∀ [ italic_f start_RELOP ( ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT ⇒ sansserif_adq ) end_RELOP italic_f start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] sansserif_adq ( italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_e ) , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_f start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT )

  • e𝖴(AX)e=e(A𝖴X)ee\lhd_{\mathsf{U}(A\to X)}e^{\prime}=e\mathrel{(\lhd_{A}\Rightarrow\lhd_{% \mathsf{U}X})}e^{\prime}italic_e ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → italic_X ) end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = italic_e start_RELOP ( ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT ⇒ ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT ) end_RELOP italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT

  • 𝖺𝖽𝗊(e,e)=(ee)𝖺𝖽𝗊𝑒superscript𝑒square-image-of-or-equals𝑒superscript𝑒\mathsf{adq}(e,e^{\prime})=(e\sqsubseteq e^{\prime})sansserif_adq ( italic_e , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = ( italic_e ⊑ italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT )

  • e(RS)e=[a𝑅a](ea)𝑆(ea)𝑅𝑆𝑒superscript𝑒for-alldelimited-[]𝑅𝑎superscript𝑎𝑒𝑎𝑆superscript𝑒superscript𝑎e\mathrel{(R\Rightarrow S)}e^{\prime}=\forall{\left[a\mathrel{R}a^{\prime}% \right]}~{}(e~{}a)\mathrel{S}(e^{\prime}~{}a^{\prime})italic_e start_RELOP ( italic_R ⇒ italic_S ) end_RELOP italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = ∀ [ italic_a italic_R italic_a start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] ( italic_e italic_a ) italic_S ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT italic_a start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT )

Figure 5: Formal approximation relations. We write ¯:2𝖺𝗇𝗌:¯2𝖺𝗇𝗌\overline{-}:2\to\mathsf{ans}over¯ start_ARG - end_ARG : 2 → sansserif_ans for the function sending 00 to 𝗇𝗈𝗇𝗈\mathsf{no}sansserif_no and 1111 to 𝗒𝖾𝗌𝗒𝖾𝗌\mathsf{yes}sansserif_yes. The relation 𝖺𝖽𝗊𝖳(1)×𝖳𝗆+(𝖴𝖥1)𝖺𝖽𝗊𝖳1superscript𝖳𝗆𝖴𝖥1\mathsf{adq}\subseteq\mathsf{T}(1)\times\mathsf{Tm}^{+}(\mathsf{U}\mathsf{F}1)sansserif_adq ⊆ sansserif_T ( 1 ) × sansserif_Tm start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( sansserif_UF 1 ) is the “ground relation” that generates the formal approximation relations at higher types.

Formal approximation relations may be extended to open terms as usual. We write ΓeAeprovesΓsubscriptsubgroup-of𝐴𝑒superscript𝑒\Gamma\vdash e\lhd_{A}e^{\prime}roman_Γ ⊢ italic_e ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT when for all closing substitutions σ:Γ:𝜎Γ\sigma:\Gammaitalic_σ : roman_Γ, we have that e(σ)Ae[σ]e(\llbracket\sigma\rrbracket)\lhd_{A}e^{\prime}[\sigma]italic_e ( ⟦ italic_σ ⟧ ) ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT [ italic_σ ] holds. The computational adequacy result may be deduced from the fundamental lemma:

Theorem 8.4.

For every closed term e:ΓA:𝑒Γproves𝐴e:\Gamma\vdash Aitalic_e : roman_Γ ⊢ italic_A, the approximation ΓeAe\Gamma\vdash\llbracket e\rrbracket\lhd_{A}eroman_Γ ⊢ ⟦ italic_e ⟧ ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_e holds.

The proof of the fundamental lemma proceeds by induction on the derivation of terms. Details and the proof that formal approximation predicates 𝖴Xe-\lhd_{\mathsf{U}X}e- ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT italic_e are admissible can be found in Appendix F; crucially we rely on the fact that 𝖾𝗏𝖺𝗅(e,v)𝖾𝗏𝖺𝗅𝑒𝑣\mathsf{eval}(e,v)sansserif_eval ( italic_e , italic_v ) is a ΣΣ\Sigmaroman_Σ-proposition.

Corollary 8.5.

Given e:𝖴𝖥1:𝑒𝖴𝖥1e:\mathsf{U}\mathsf{F}1italic_e : sansserif_UF 1, we have that e=𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e)\llbracket e\rrbracket=\mathsf{profile}(e)⟦ italic_e ⟧ = sansserif_profile ( italic_e ).

Extensionally, both the denotational and computational semantics of e𝑒eitalic_e are simply partial computations of type 𝖫1𝖫1\mathsf{L}1sansserif_L 1, so one may view Corollary 8.5 as a cost-sensitive (and internal) version of Ploktin’s original adequacy theorem for PCF. Lastly, we see that our semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT provides a rigorous proof of the intuitive fact that computations may not observe the cost effect:

Theorem 8.6.

Any e:𝖴𝖥1𝖥2:𝑒𝖴𝖥1𝖥2e:\mathsf{U}\mathsf{F}1\rightharpoonup\mathsf{F}2italic_e : sansserif_UF 1 ⇀ sansserif_F 2 is weakly, extensionally constant in the sense that for all x,y:𝖴𝖥1:𝑥𝑦𝖴𝖥1x,y:\mathsf{U}\mathsf{F}1italic_x , italic_y : sansserif_UF 1, if 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(x)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑥absent\mathsf{profile}(x){\downarrow}sansserif_profile ( italic_x ) ↓ and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(y)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑦absent\mathsf{profile}(y){\downarrow}sansserif_profile ( italic_y ) ↓, then 𝖾𝗏𝖺𝗅(ex,𝗋𝖾𝗍(v))𝖾𝗏𝖺𝗅𝑒𝑥𝗋𝖾𝗍𝑣absent\mathsf{eval}(e~{}x,\mathsf{ret}(v)){\downarrow}sansserif_eval ( italic_e italic_x , sansserif_ret ( italic_v ) ) ↓ and 𝖾𝗏𝖺𝗅(ey,𝗋𝖾𝗍(u))𝖾𝗏𝖺𝗅𝑒𝑦𝗋𝖾𝗍𝑢absent\mathsf{eval}(e~{}y,\mathsf{ret}(u)){\downarrow}sansserif_eval ( italic_e italic_y , sansserif_ret ( italic_u ) ) ↓ imply v=u𝑣𝑢v=uitalic_v = italic_u.

9 An SDT model of the intension-extension phase distinction

To obtain a model for the constructions of the preceding sections, we instantiate the sheaf model of Sterling and Harper [32] at the poset 𝕀={𝖾𝗑𝗍𝗂𝗇𝗍}𝕀square-image-of-or-equals𝖾𝗑𝗍𝗂𝗇𝗍\mathbb{I}={\left\{\mathsf{ext}\sqsubseteq\mathsf{int}\right\}}blackboard_I = { sansserif_ext ⊑ sansserif_int } representing the intension-extension security order. The basic idea is to first develop domain theory internal to the presheaf topos 𝕀^^𝕀\widehat{\mathbb{I}}over^ start_ARG blackboard_I end_ARG, from which we may obtain an appropriate internal domain-theoretic site that embeds into a sheaf topos model of SDT in the sense of Definition 3.16. The reason to consider internal sites is that we may build into the base category the intension-extension phase distinction that is preserved through the embedding.

In op. cit. the internal domain theory of 𝕀^^𝕀\widehat{\mathbb{I}}over^ start_ARG blackboard_I end_ARG is developed in terms of constructive dcpos following the work de Jong [2]. These internal dcpos are similar to ordinary dcpos; for example, one may use them to give the denotational semantics of PCF [2]. The difference lies in the dominance ΣΣ\Sigmaroman_Σ of the category of internal dcpos given by the subobject classifier Ω𝕀^subscriptΩ^𝕀\Omega_{\widehat{\mathbb{I}}}roman_Ω start_POSTSUBSCRIPT over^ start_ARG blackboard_I end_ARG end_POSTSUBSCRIPT: while a partial element of ordinary domains in Set is either defined or not, a partial element of a domain internal to 𝕀^^𝕀\widehat{\mathbb{I}}over^ start_ARG blackboard_I end_ARG may have the phase proposition \P as its support, where \P is the intermediate proposition in Ω𝕀^subscriptΩ^𝕀\Omega_{\widehat{\mathbb{I}}}roman_Ω start_POSTSUBSCRIPT over^ start_ARG blackboard_I end_ARG end_POSTSUBSCRIPT. Recalling the interpretation of a map AΣ𝐴ΣA\to\Sigmaitalic_A → roman_Σ as a computational predicate, this also means that predicates can be phase-dependent in the sense of holding only at the extensional phase.

We recall some definitions from Sterling and Harper [32] (SH22).

Definition 9.1.

A Scott-open immersion of a dcpo is any mono UA𝑈𝐴U\rightarrowtail Aitalic_U ↣ italic_A arising from a predicate AΣ𝐴ΣA\to\Sigmaitalic_A → roman_Σ.

Definition 9.2.

In a category, a sink on an object A𝐴Aitalic_A is a set of morphisms into A𝐴Aitalic_A.

Definition 9.3.

In a category with pullbacks, a Cartesian coverage is an assignment of objects A𝐴Aitalic_A to set of sinks on A𝐴Aitalic_A that is stable under pullback.

Definition 9.4.

The finite open cover topology is generated by the Cartesian coverage assigning to each dcpo A𝐴Aitalic_A the set of sinks {UiA}isubscriptsubscript𝑈𝑖𝐴𝑖\{U_{i}\rightarrowtail A\}_{i}{ italic_U start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ↣ italic_A } start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT on A𝐴Aitalic_A with every UiAsubscript𝑈𝑖𝐴U_{i}\rightarrowtail Aitalic_U start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ↣ italic_A a Scott-open immersion and iUiAsubscript𝑖subscript𝑈𝑖𝐴\bigvee_{i}U_{i}\cong A⋁ start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT italic_U start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ≅ italic_A.

Our domain-theoretic site is given by an internal category 𝒞𝒞\mathscr{C}script_C of small dcpos in 𝕀^^𝕀\widehat{\mathbb{I}}over^ start_ARG blackboard_I end_ARG. We embed 𝒞𝒞\mathscr{C}script_C into a Grothendieck topos Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ), obtained by localizing 𝒞^^𝒞\widehat{\mathscr{C}}over^ start_ARG script_C end_ARG at the finite open cover topology. The purpose of this localization is to ensure that the finite joins of the dominance in 𝒞𝒞\mathscr{C}script_C are preserved by the embedding into Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ). This property was notably used by op. cit. to implement the semantics of termination declassification; here we use the finite join structure of ΣΣ\Sigmaroman_Σ to show that 2222 is an extensional predomain. The phase distinction in Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ) is inherited from the ambient presheaf topos, where it is represented by 𝖾𝗑𝗍𝖾𝗑𝗍\mathsf{ext}sansserif_ext.

Theorem 9.5 (SH22, Corollary 90).

Every representable presheaf is well-complete.

Thus we obtain a functor y:𝒞Sh(𝒞):𝑦𝒞Sh𝒞y:\mathscr{C}\hookrightarrow\mathrm{Sh}(\mathscr{C})italic_y : script_C ↪ roman_Sh ( script_C ) restricting the Yoneda embedding 𝗒𝒞:𝒞𝒞^:subscript𝗒𝒞𝒞^𝒞\mathsf{y}_{\mathscr{C}}:\mathscr{C}\hookrightarrow\widehat{\mathscr{C}}sansserif_y start_POSTSUBSCRIPT script_C end_POSTSUBSCRIPT : script_C ↪ over^ start_ARG script_C end_ARG onto sheaves.

Theorem 9.6 (SH22, B.1.4.3).

The representable Σ=y(Σ)Σ𝑦Σ\Sigma=y(\Sigma)roman_Σ = italic_y ( roman_Σ ) is a dominance in Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ).

Theorem 9.7 (SH22, Corollary 79).

Coproducts in 𝒞𝒞\mathscr{C}script_C are given by unions of families of Scott-opens.

Corollary 9.8.

Finite coproducts of 𝒞𝒞\mathscr{C}script_C are preserved by the embedding into sheaves.

Theorem 9.9 (SH22, Axiom-SDT-1).

The dominance ΣΣ\Sigmaroman_Σ has finite joins that are preserved by the inclusion ΣΩΣΩ\Sigma\hookrightarrow\Omegaroman_Σ ↪ roman_Ω.

Theorem 9.10.

Setting Σ=y(Ω𝕀^)Σ𝑦subscriptΩ^𝕀\Sigma=y(\Omega_{\widehat{\mathbb{I}}})roman_Σ = italic_y ( roman_Ω start_POSTSUBSCRIPT over^ start_ARG blackboard_I end_ARG end_POSTSUBSCRIPT ) and =y(𝗒𝕀(𝖾𝗑𝗍))𝑦subscript𝗒𝕀𝖾𝗑𝗍\P=y(\mathsf{y}_{\mathbb{I}}(\mathsf{ext}))¶ = italic_y ( sansserif_y start_POSTSUBSCRIPT blackboard_I end_POSTSUBSCRIPT ( sansserif_ext ) ), we have that (Sh(𝒞),Σ,)Sh𝒞Σ(\mathrm{Sh}(\mathscr{C}),\Sigma,\P)( roman_Sh ( script_C ) , roman_Σ , ¶ ) is an SDT model of the intension-extension phase distinction in the sense of Definition 3.16.

Proof 9.11.

By Theorem 9.5 we know that ΣΣ\Sigmaroman_Σ is a well-complete dominance in Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ). To show that Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ) also models the intension-extension phase distinction, we observe that the presheaf model of the intension-extension phase distinction of Niu et al. [18] restricts to a smaller model in 𝒞𝒞\mathscr{C}script_C: every subterminal object in 𝕀^^𝕀\widehat{\mathbb{I}}over^ start_ARG blackboard_I end_ARG is an internal dcpo, and so we may take the subterminal =𝗒𝕀(𝖾𝗑𝗍)subscript𝗒𝕀𝖾𝗑𝗍\P=\mathsf{y}_{\mathbb{I}}(\mathsf{ext})¶ = sansserif_y start_POSTSUBSCRIPT blackboard_I end_POSTSUBSCRIPT ( sansserif_ext ) to be the phase proposition in 𝒞𝒞\mathscr{C}script_C. The phase proposition =y()𝑦\P=y(\P)¶ = italic_y ( ¶ ) in Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ) is classified by ΣΣ\Sigmaroman_Σ: since y𝑦yitalic_y is fully faithful, every ϕ:Σ:italic-ϕΣ\phi:\Sigmaitalic_ϕ : roman_Σ arise from a unique map 1𝕀^Ω𝕀^subscript1^𝕀subscriptΩ^𝕀1_{\widehat{\mathbb{I}}}\to\Omega_{\widehat{\mathbb{I}}}1 start_POSTSUBSCRIPT over^ start_ARG blackboard_I end_ARG end_POSTSUBSCRIPT → roman_Ω start_POSTSUBSCRIPT over^ start_ARG blackboard_I end_ARG end_POSTSUBSCRIPT.

Moreover, we can directly verify that 2𝒞=2𝕀^=1𝕀^+11^subscript2𝒞subscript2^𝕀subscript1^𝕀subscript1^12_{\mathscr{C}}=2_{\widehat{\mathbb{I}}}=1_{\widehat{\mathbb{I}}}+1_{\widehat{% 1}}2 start_POSTSUBSCRIPT script_C end_POSTSUBSCRIPT = 2 start_POSTSUBSCRIPT over^ start_ARG blackboard_I end_ARG end_POSTSUBSCRIPT = 1 start_POSTSUBSCRIPT over^ start_ARG blackboard_I end_ARG end_POSTSUBSCRIPT + 1 start_POSTSUBSCRIPT over^ start_ARG 1 end_ARG end_POSTSUBSCRIPT is internally orthogonal to \P in 𝒞𝒞\mathscr{C}script_C. By Corollary 9.8, y𝑦yitalic_y preserves finite coproducts, so we have that 2Sh(𝒞)=y(2𝒞)subscript2Sh𝒞𝑦subscript2𝒞2_{\mathrm{Sh}(\mathscr{C})}=y(2_{\mathscr{C}})2 start_POSTSUBSCRIPT roman_Sh ( script_C ) end_POSTSUBSCRIPT = italic_y ( 2 start_POSTSUBSCRIPT script_C end_POSTSUBSCRIPT ). We observe that 2 is extensional because the restricted embedding y:𝒞Sh(𝒞):𝑦𝒞Sh𝒞y:\mathscr{C}\to\mathrm{Sh}(\mathscr{C})italic_y : script_C → roman_Sh ( script_C ) is both full and faithful and preserves products. To see that 2222 is replete, we observe that 2 is isomorphic to its type of singletons:

2{ϕ:Σ2([a,b:2]ϕaϕba=b)(ϕ(𝗂𝗇𝗅)ϕ(𝗂𝗇𝗋))}\displaystyle 2\cong{\left\{\phi:\Sigma^{2}\mid{\left(\forall[a,b:2]~{}\phi~{}% a\land\phi~{}b\to a=b\right)}\land{\left(\phi(\mathsf{inl}\cdot\star)\lor\phi(% \mathsf{inr}\cdot\star)\right)}\right\}}2 ≅ { italic_ϕ : roman_Σ start_POSTSUPERSCRIPT 2 end_POSTSUPERSCRIPT ∣ ( ∀ [ italic_a , italic_b : 2 ] italic_ϕ italic_a ∧ italic_ϕ italic_b → italic_a = italic_b ) ∧ ( italic_ϕ ( sansserif_inl ⋅ ⋆ ) ∨ italic_ϕ ( sansserif_inr ⋅ ⋆ ) ) }

Because ΣΣ\Sigmaroman_Σ is closed under finite joins (by Theorem 9.9), the type of singletons of 2 can be defined as the limit of a diagram of replete types, and so it is replete as well.

Lastly, to see that Phoa’s principle is satisfied, we note that it holds in 𝒞𝒞\mathscr{C}script_C. Since the subobject {(ϕ,ψ):Σ×Σϕψ}conditional-setitalic-ϕ𝜓conditionalΣΣitalic-ϕ𝜓{\left\{(\phi,\psi):\Sigma\times\Sigma\mid\phi\to\psi\right\}}{ ( italic_ϕ , italic_ψ ) : roman_Σ × roman_Σ ∣ italic_ϕ → italic_ψ } can be defined as the equalizer of π1:Σ×ΣΣ:subscript𝜋1ΣΣΣ\pi_{1}:\Sigma\times\Sigma\to\Sigmaitalic_π start_POSTSUBSCRIPT 1 end_POSTSUBSCRIPT : roman_Σ × roman_Σ → roman_Σ and :Σ×ΣΣ\land:\Sigma\times\Sigma\to\Sigma∧ : roman_Σ × roman_Σ → roman_Σ, every object in the diagram is defined using the cartesian closed structure of 𝒞𝒞\mathscr{C}script_C, it is preserved by any cartesian closed embedding, and so Phoa’s principle also holds in Sh(𝒞)Sh𝒞\mathrm{Sh}(\mathscr{C})roman_Sh ( script_C ).

10 Discussion of related work

Cost analysis in type theory. The original motivation for proving internal, cost-sensitive computational adequacy results grew out of the work of Niu et al. [18] on formalizing cost analysis of functional programs in dependent type theory. Niu and Harper [17] prove such an adequacy theorem for a variant of the Algol language featuring a notion of first-order recursion in the form of while loops. The purpose of the present paper is to generalize that result to account for higher-order recursion. In contrast to both prior works, we have de-emphasized the role of the call-by-push-value language and instead work directly with the internal language of the SDT topos. Because the model we construct in Section 9 can also be seen as a model for the type theories in both prior works, we expect that it would be routine to formalize our results in a call-by-push-value version of type theory as well.

Cost-sensitive computational adequacy. The kind of cost-sensitive adequacy theorem we prove in this paper has been proved in a classic domain-theoretic setting by Kavvos et al. [13], and the general theory of computational adequacy for languages with algebraic effects has been developed by Plotkin and Power [23]. The main difference between our work and those mentioned is that we aim to prove adequacy results internally to a type theory equipped with a phase distinction (such as the one in Niu et al. [18]). As argued in Niu and Harper [17], such internal adequacy theorems can be used as a basis for the validity of axiomatic cost analysis in these type theories.

Relative sheaf models of SDT. As we have explained in Section 1.2.2, the main sheaf models of synthetic domain theory take the form of Grothendieck topoi over the category of sets. Meanwhile, the logic of phase distinctions finds its home in presheaf topoi in which one finds many distinct subterminal objects that are neither globally true nor globally false; because the category of sets is boolean and two-valued, it can have no non-trivial phase distinctions. For this reason, Sterling and Harper [32] have proposed to combine synthetic domain theory with phase distinctions by developing models in relative Grothendieck topoi [12] over a presheaf topos that exhibits a phase distinction. In other words, rather than building a site out of predomains in the category of sets, op. cit. built an internal site based on internal predomains in a category of presheaves. Our model of cost-sensitive synthetic domain theory is similar to that of Sterling and Harper [32]. On the other hand, our proof of computational adequacy is different from that of op. cit., as the latter contains a subtle error [30] involving a mismatch between the existential quantifier and the join of a family of ΣΣ\Sigmaroman_Σ-propositions in the lifting of free algebras to formal approximation relations.

Computational adequacy in SDT. Our approach to internal denotational semantics and computational adequacy of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT builds on the pioneering work of Simpson [29] on proving the computational adequacy property of PCF in elementary topoi models of SDT. One difference between our work and that of op. cit. is the addition of the phase distinction, which we use to give an intrinsic denotational account of the interaction between cost and behavior in PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT. Another difference is in the SDT axioms used and the ensuing definition of the dynamic semantics of the object programming language. Simpson [29] assumes a property called Axiom N that closes the dominance ΣΣ\Sigmaroman_Σ under countable joins of decidable families in the ambient logic, a fact that we do not rely on in our constructions. The benefit of this axiom is that it enables op. cit. to give an internal definition of PCF whose dynamic semantics can be characterized by means of existentially quantified statements of the form [n:]ϕ(n)\exists[n:{\mathbb{N}}]~{}\phi(n)∃ [ italic_n : blackboard_N ] italic_ϕ ( italic_n ) where ϕitalic-ϕ\phiitalic_ϕ is a primitive recursive predicate. This is used to show that a general property of the internal logic of topoi called 1-consistency333A topos \mathcal{E}caligraphic_E is 1-consistent when a closed formula [n:]ϕ(n)\exists[n:{\mathbb{N}}]~{}\phi(n)∃ [ italic_n : blackboard_N ] italic_ϕ ( italic_n ) of the form described above holding in the internal logic of \mathscr{E}script_E implies that it holds externally. is both necessary and sufficient to externalize the internal adequacy proof into a corresponding proof in ordinary mathematics. In a follow-up paper, Simpson [28] gave a different logical criterion for the equivalence of internal and external adequacy called computational 1-consistency that does not rely on Axiom N. Roughly the idea is to define the programming language and its operational semantics in terms of the computational natural numbers (analogous to the predomain 𝖯subscript𝖯{\mathbb{N}}_{\mathsf{P}}blackboard_N start_POSTSUBSCRIPT sansserif_P end_POSTSUBSCRIPT in this paper); computational 1-consistency is just the property needed to ensure that internal computational observations hold externally as well.

By contrast, the dynamic semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in this paper is defined computationally and is not known to be equivalent to the operational semantics of Simpson [29] in the absence of Axiom N. However, we expect that a version of our computational semantics using the computational natural numbers will be equivalent to the semantics given in Simpson [28]. On the other hand, we find the computational semantics developed in Section 7 both philosophically and mathematically compelling and deserving of further investigation in its own right. Moreover, although the computational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT does not appear to be definable in terms of countable joins, it can be defined using synthetic ω𝜔\omegaitalic_ω-joins of decidable families. Therefore, we conjecture that one may externalize the internal adequacy proof of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in the manner of Simpson [29] by developing a Kripke-Joyal semantics for the sheaf model defined in Section 9 that unfolds an internal statement involving synthetic ω𝜔\omegaitalic_ω-joins to an external statement in the metatheory.

11 Conclusion & future work

In this paper we study a language for higher-order recursion PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT in the setting of synthetic domain theory. Our main contribution is an internal, cost-sensitive version of Plotkin’s computational adequacy theorem for PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT. In particular, we define and relate a denotational model of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT to a new dynamic semantics for PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT defined directly in terms of computation that is both natural and mathematically appealing. Here we suggest some ideas for future investigations.

Internal vs. external adequacy. In the same vein as the work of Simpson [29, 28], we are also interested in giving a logical characterization of when internal computational adequacy (with respect to the computational semantics of PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT) implies external adequacy. However it is not clear to us what would be an analogous condition to 1-consistency: internal notions such as the initial lift algebra ω𝜔\omegaitalic_ω and synthetic ω𝜔\omegaitalic_ω-chains do not have natural external counterparts. As mentioned in Section 10, a first step would be to develop a systematic understanding of the logical aspects of the initial lift algebra from an external point of view.

As mentioned in Section 10, one way to obtain external adequacy would be to follow the approach of [28] and define PCF𝖼𝗈𝗌𝗍subscriptPCF𝖼𝗈𝗌𝗍\textbf{PCF}_{\mathsf{cost}}PCF start_POSTSUBSCRIPT sansserif_cost end_POSTSUBSCRIPT and its computational semantics purely in terms of computational natural numbers. Alternatively, we may decide to assume Axiom N (see Section 10), which would imply that the computational semantics coincides with ordinary operational semantics in the internal logic of the SDT topos. We do not expect Axiom N to hold in the model we construct in this paper (cf. van Oosten and Simpson [34]), but it does not appear to be a limitation of the general approach to the model construction; indeed we believe it should be possible to start with a different domain-theoretic site such that the embedding into the resulting sheaf topos preserves countable coproducts, which would be enough to validate Axiom N.

Cost and information order. As discussed in Section 1.2.3, we would like to combine and develop a practical theory for the interaction of the domain-theoretic information order with a cost preorder in the sense of Grodin et al., who developed a “preorder” version of SDT in which “predomains” are types equipped with a preorder. Following the approach of relative sheaf models of SDT, we conjecture that one may build a model of SDT that further incorporates an intrinsic preorder structure by starting with a domain-theoretic site internal to the category of simplicial sets.

Recursive types. We have emphasized recursion at the term level, but synthetic domain theory is also compatible with having recursive types. Simpson [28] has developed in a very general setting the theory and existence of algebraically compact categories of predomains in SDT, and we hope to instantiate the ideas of op. cit. at a relative sheaf model of SDT similar to the one presented in this paper.

References

  • [1] Beck, J., Distributive laws, in: B. Eckmann, editor, Seminar on Triples and Categorical Homology Theory, pages 119–140, Springer Berlin Heidelberg, Berlin, Heidelberg (1969), ISBN 978-3-540-36091-9.
  • [2] de Jong, T., Domain theory in constructive and predicative univalent foundations (2023).
    https://doi.org/10.48550/ARXIV.2301.12405
  • [3] Fiore, M. P., Lifting as a KZ-doctrine, in: D. Pitt, D. E. Rydeheard and P. Johnstone, editors, Category Theory and Computer Science, pages 146–158, Springer Berlin Heidelberg, Berlin, Heidelberg (1995), ISBN 978-3-540-44661-3.
  • [4] Fiore, M. P., A. M. Pitts and S. C. Steenkamp, Quotients, inductive types, and quotient inductive types, Logical Methods in Computer Science Volume 18, Issue 2 (2022).
    https://doi.org/10.46298/lmcs-18(2:15)2022
  • [5] Fiore, M. P. and G. D. Plotkin, An extension of models of axiomatic domain theory to models of synthetic domain theory, in: D. van Dalen and M. Bezem, editors, Computer Science Logic, 10th International Workshop, CSL ’96, Annual Conference of the EACSL, Utrecht, The Netherlands, September 21-27, 1996, Selected Papers, volume 1258 of Lecture Notes in Computer Science, pages 129–149, Springer (1996).
    https://doi.org/10.1007/3-540-63172-0_36
  • [6] Fiore, M. P. and G. Rosolini, The category of cpos from a synthetic viewpoint, in: S. D. Brookes and M. W. Mislove, editors, Thirteenth Annual Conference on Mathematical Foundations of Progamming Semantics, MFPS 1997, Carnegie Mellon University, Pittsburgh, PA, USA, March 23-26, 1997, volume 6 of Electronic Notes in Theoretical Computer Science, pages 133–150, Elsevier (1997).
    https://doi.org/10.1016/S1571-0661(05)80165-3
  • [7] Fiore, M. P. and G. Rosolini, Two models of synthetic domain theory, Journal of Pure and Applied Algebra 116, pages 151–162 (1997), ISSN 0022-4049.
    https://doi.org/10.1016/S0022-4049(96)00164-8
  • [8] Grodin, H., Y. Niu, J. Sterling and R. Harper, Decalf: A directed, effectful cost-aware logical framework, Proceedings of the ACM on Programming Languages 8 (2024).
    https://doi.org/10.1145/3632852
  • [9] Harper, R., J. C. Mitchell and E. Moggi, Higher-order modules and the phase distinction, in: Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 341–354, Association for Computing Machinery, San Francisco, California, USA (1990), ISBN 0-89791-343-4.
    https://doi.org/10.1145/96709.96744
  • [10] Hoffmann, J., Types with Potential: Polynomial Resource Bounds via Automatic Amortized Analysis, Ph.D. thesis, Ludwig-Maximilians-Universität München (2011).
    https://www.cs.cmu.edu/~janh/assets/pdf/Hoffmann11.pdf
  • [11] Hyland, J. M. E., First steps in synthetic domain theory, in: A. Carboni, M. C. Pedicchio and G. Rosolini, editors, Category Theory, pages 131–156, Springer Berlin Heidelberg, Berlin, Heidelberg (1991), ISBN 978-3-540-46435-8.
  • [12] Johnstone, P. T., Sketches of an Elephant: A Topos Theory Compendium: Volumes 1 and 2, number 43 in Oxford Logical Guides, Oxford Science Publications (2002).
  • [13] Kavvos, G. A., E. Morehouse, D. R. Licata and N. Danner, Recurrence extraction for functional programs through call-by-push-value, Proceedings of the ACM on Programming Languages 4 (2019).
    https://doi.org/10.1145/3371083
  • [14] Levy, P. B., Call-by-Push-Value: A Functional/Imperative Synthesis, Kluwer, Semantic Structures in Computation, 2 (2003), ISBN 1-4020-1730-8.
  • [15] LONGLEY, J. R. and A. K. SIMPSON, A uniform approach to domain theory in realizability models, Mathematical Structures in Computer Science 7, page 469–505 (1997).
    https://doi.org/10.1017/S0960129597002387
  • [16] Matache, C., S. Moss and S. Staton, Recursion and Sequentiality in Categories of Sheaves, in: N. Kobayashi, editor, 6th International Conference on Formal Structures for Computation and Deduction (FSCD 2021), volume 195 of Leibniz International Proceedings in Informatics (LIPIcs), pages 25:1–25:22, Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany (2021), ISBN 978-3-95977-191-7, ISSN 1868-8969.
    https://doi.org/10.4230/LIPIcs.FSCD.2021.25
  • [17] Niu, Y. and R. Harper, A metalanguage for cost-aware denotational semantics, in: 2023 38th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), pages 1–14 (2023).
    https://doi.org/10.1109/LICS56636.2023.10175777
  • [18] Niu, Y., J. Sterling, H. Grodin and R. Harper, A cost-aware logical framework, Proceedings of the ACM on Programming Languages 6 (2022). 2107.04663.
    https://doi.org/10.1145/3498670
  • [19] Paviotti, M., R. E. Møgelberg and L. Birkedal, A model of PCF in Guarded Type Theory, Electronic Notes in Theoretical Computer Science 319, pages 333–349 (2015), ISSN 1571-0661. The 31st Conference on the Mathematical Foundations of Programming Semantics (MFPS XXXI).
    https://doi.org/10.1016/j.entcs.2015.12.020
  • [20] Phoa, W., Domain Theory in Realizability Toposes, Ph.D. thesis, University of Edinburgh (1991).
  • [21] Plotkin, G., A structural approach to operational semantics, J. Log. Algebr. Program. 60-61, pages 17–139 (2004).
    https://doi.org/10.1016/j.jlap.2004.05.001
  • [22] Plotkin, G. D., LCF considered as a programming language, Theoretical Computer Science 5, pages 223–255 (1977), ISSN 0304-3975.
    https://doi.org/10.1016/0304-3975(77)90044-5
  • [23] Plotkin, G. D. and J. Power, Notions of computation determine monads, in: Proceedings of the 5th International Conference on Foundations of Software Science and Computation Structures, pages 342–356, Springer-Verlag, Berlin, Heidelberg (2002), ISBN 3-540-43366-X.
  • [24] Reus, B., Program Verification in Synthetic Domain Theory, Ph.D. thesis, Ludwig-Maximilians-Universität München, München (1995).
  • [25] Reus, B. and T. Streicher, General synthetic domain theory — a logical approach, Mathematical Structures in Computer Science 9, pages 177–223 (1999).
    https://doi.org/10.1017/S096012959900273X
  • [26] Rijke, E., M. Shulman and B. Spitters, Modalities in homotopy type theory, Logical Methods in Computer Science 16 (2020).
    https://doi.org/10.23638/LMCS-16(1:2)2020
  • [27] Rosolini, G., Continuity and effectiveness in topoi, Ph.D. thesis, University of Oxford (1986).
  • [28] Simpson, A., Computational adequacy for recursive types in models of intuitionistic set theory, Annals of Pure and Applied Logic 130, pages 207–275 (2004), ISSN 0168-0072. Papers presented at the 2002 IEEE Symposium on Logic in Computer Science (LICS).
    https://doi.org/10.1016/j.apal.2003.12.005
  • [29] Simpson, A. K., Computational Adequacy in an Elementary Topos, in: G. Gottlob, E. Grandjean and K. Seyr, editors, Computer Science Logic, Lecture Notes in Computer Science, pages 323–342, Springer, Berlin, Heidelberg (1999), ISBN 978-3-540-48855-2.
    https://doi.org/10.1007/10703163_22
  • [30] Sterling, J., Erratum: adequacy of Sheaf semantics of noninterference (2023).
    http://www.jonmsterling.com/jms-005Z.xml
  • [31] Sterling, J. and R. Harper, Logical relations as types: Proof-relevant parametricity for program modules, Journal of the ACM 68 (2021), ISSN 0004-5411. 2010.08599.
    https://doi.org/10.1145/3474834
  • [32] Sterling, J. and R. Harper, Sheaf semantics of termination-insensitive noninterference, in: A. P. Felty, editor, 7th International Conference on Formal Structures for Computation and Deduction (FSCD 2022), volume 228 of Leibniz International Proceedings in Informatics (LIPIcs), pages 5:1–5:19, Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany (2022), ISBN 978-3-95977-233-4, ISSN 1868-8969. 2204.09421.
    https://doi.org/10.4230/LIPIcs.FSCD.2022.5
  • [33] Taylor, P., The fixed point property in synthetic domain theory, in: [1991] Proceedings Sixth Annual IEEE Symposium on Logic in Computer Science, pages 152–160 (1991).
    https://doi.org/10.1109/LICS.1991.151640
  • [34] van Oosten, J. and A. K. Simpson, Axioms and (counter)examples in synthetic domain theory, Annals of Pure and Applied Logic 104, pages 233–278 (2000), ISSN 0168-0072.
    https://doi.org/10.1016/S0168-0072(00)00014-2

Appendix A Properties of the dominance

See 3.12

Proof A.1.

We need to show that the intrinsic order on ΣΣ\Sigmaroman_Σ coincides with the path relation. First, we observe that bottomsuperscriptsquare-image-of-or-equalstop\bot\sqsubseteq^{\circ}\top⊥ ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT ⊤; indeed, fixing a map f:ΣΣ:𝑓ΣΣf:\Sigma\to\Sigmaitalic_f : roman_Σ → roman_Σ, by Phoa’s principle, evaluation at boundary obtains a pair (f,f)limit-from𝑓bottomlimit-from𝑓top(f~{}\bot,f~{}\top)( italic_f ⊥ , italic_f ⊤ ) such that flimit-from𝑓bottomf~{}\botitalic_f ⊥ implies flimit-from𝑓topf~{}\topitalic_f ⊤. In one direction, suppose x𝗉ysuperscriptsquare-image-of-or-equals𝗉𝑥𝑦x\sqsubseteq^{\mathsf{p}}yitalic_x ⊑ start_POSTSUPERSCRIPT sansserif_p end_POSTSUPERSCRIPT italic_y, which means we have a path l:ΣΣ:𝑙ΣΣl:\Sigma\to\Sigmaitalic_l : roman_Σ → roman_Σ whose boundary is determined by x,y𝑥𝑦x,yitalic_x , italic_y. Fixing f:ΣΣ:𝑓ΣΣf:\Sigma\to\Sigmaitalic_f : roman_Σ → roman_Σ, we want to show that fxfy𝑓𝑥𝑓𝑦f~{}x\to f~{}yitalic_f italic_x → italic_f italic_y. But this follows by evaluating bottomsuperscriptsquare-image-of-or-equalstop\bot\sqsubseteq^{\circ}\top⊥ ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT ⊤ at the ΣΣ\Sigmaroman_Σ-predicate fl:ΣΣ:𝑓𝑙ΣΣf\circ l:\Sigma\to\Sigmaitalic_f ∘ italic_l : roman_Σ → roman_Σ. Conversely, if xysuperscriptsquare-image-of-or-equals𝑥𝑦x\sqsubseteq^{\circ}yitalic_x ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT italic_y, then we have in particular xy𝑥𝑦x\to yitalic_x → italic_y, which by Phoa’s principle uniquely determines a path l:ΣΣ:𝑙ΣΣl:\Sigma\to\Sigmaitalic_l : roman_Σ → roman_Σ.

Appendix B Properties of predomains

See 4.1

Proof B.1.

Replete types are both complete and boundary separated because the latter can be defined by orthogonality conditions and is satisfied by ΣΣ\Sigmaroman_Σ: it is complete by the axioms of SDT (Definition 3.16) and it is boundary separated by Proposition 3.15. Assuming Phoa’s principle, the proof that replete types are linked can be found in Taylor [33, Corollary 2.10] and Reus [24, Corollary 6.1.16]. Lastly, one can show that the objects whose link relation is antisymmetric can be defined as an orthogonality condition, thus we know that the link relation on every replete type is antisymmetric, hence it follows the intrinsic order on replete types are also partial orders since they are linked.

See 4.6

Proof B.2.

We observe that A𝐴\P\vee A¶ ∨ italic_A is defined as the pushout of the projections of A×𝐴A\times\Pitalic_A × ¶ as indicated below:

A×𝐴A\times\Pitalic_A × ¶\PA𝐴Aitalic_AA𝐴\P\vee A¶ ∨ italic_Aηsubscript𝜂limit-from\eta_{\P\vee-}italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT\star

Using the fact that A𝐴Aitalic_A has ΣΣ\Sigmaroman_Σ-equality, we obtain a map f:(A)×(A)Σ:𝑓𝐴𝐴Σf:(\P\vee A)\times(\P\vee A)\to\P\vee\Sigmaitalic_f : ( ¶ ∨ italic_A ) × ( ¶ ∨ italic_A ) → ¶ ∨ roman_Σ such that f(η(x),η(y))=η(x=y)𝑓subscript𝜂limit-from𝑥subscript𝜂limit-from𝑦subscript𝜂limit-from𝑥𝑦f(\eta_{\P\vee-}(x),\eta_{\P\vee-}(y))=\eta_{\P\vee-}(x=y)italic_f ( italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_x ) , italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_y ) ) = italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_x = italic_y ) and f(,)=f(,)=𝑓𝑓f(\star,-)=f(-,\star)=\staritalic_f ( ⋆ , - ) = italic_f ( - , ⋆ ) = ⋆. The desired characteristic map can then be defined as σf𝜎𝑓\sigma\circ fitalic_σ ∘ italic_f, where σ:ΣΣ:𝜎ΣΣ\sigma:\P\vee\Sigma\to\Sigmaitalic_σ : ¶ ∨ roman_Σ → roman_Σ is defined as follows:

σ:ΣΣ:𝜎ΣΣ\displaystyle\sigma:\P\vee\Sigma\to\Sigmaitalic_σ : ¶ ∨ roman_Σ → roman_Σ
σ(η(ϕ))=ϕ𝜎subscript𝜂limit-fromitalic-ϕitalic-ϕ\displaystyle\sigma(\eta_{\P\vee-}(\phi))=\P\vee\phiitalic_σ ( italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_ϕ ) ) = ¶ ∨ italic_ϕ
σ()=𝜎top\displaystyle\sigma(\star)=\topitalic_σ ( ⋆ ) = ⊤

For any u,v:A:𝑢𝑣𝐴u,v:\P\vee Aitalic_u , italic_v : ¶ ∨ italic_A, if u=v=η(x)𝑢𝑣subscript𝜂limit-from𝑥u=v=\eta_{\P\vee-}(x)italic_u = italic_v = italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_x ) for some x:A:𝑥𝐴x:Aitalic_x : italic_A, then we have σ(f(u,v))=σ(η(x=x))=(x=x)=𝜎𝑓𝑢𝑣𝜎subscript𝜂limit-from𝑥𝑥𝑥𝑥top\sigma(f(u,v))=\sigma(\eta_{\P\vee-}(x=x))=\P\vee(x=x)=\topitalic_σ ( italic_f ( italic_u , italic_v ) ) = italic_σ ( italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_x = italic_x ) ) = ¶ ∨ ( italic_x = italic_x ) = ⊤. Otherwise, we have that u𝑢uitalic_u or v𝑣vitalic_v is \star, which means \P holds and so σ(f(u,v))=σ()=𝜎𝑓𝑢𝑣𝜎top\sigma(f(u,v))=\sigma(\star)=\topitalic_σ ( italic_f ( italic_u , italic_v ) ) = italic_σ ( ⋆ ) = ⊤ as well. Conversely, suppose σ(f(u,v))=𝜎𝑓𝑢𝑣top\sigma(f(u,v))=\topitalic_σ ( italic_f ( italic_u , italic_v ) ) = ⊤, and that u=η(x)𝑢subscript𝜂limit-from𝑥u=\eta_{\P\vee-}(x)italic_u = italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_x ) and v=η(y)𝑣subscript𝜂limit-from𝑦v=\eta_{\P\vee-}(y)italic_v = italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_y ), which means that σ(η(x=y))=(x=y)𝜎subscript𝜂limit-from𝑥𝑦𝑥𝑦\sigma(\eta_{\P\vee-}(x=y))=\P\vee(x=y)italic_σ ( italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_x = italic_y ) ) = ¶ ∨ ( italic_x = italic_y ) holds. If \P holds, we are done as (A)1𝐴1(\P\vee A)\cong 1( ¶ ∨ italic_A ) ≅ 1 in this case. Otherwise, we have x=y𝑥𝑦x=yitalic_x = italic_y, and so u=η(x)=η(y)=v𝑢subscript𝜂limit-from𝑥subscript𝜂limit-from𝑦𝑣u=\eta_{\P\vee-}(x)=\eta_{\P\vee-}(y)=vitalic_u = italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_x ) = italic_η start_POSTSUBSCRIPT ¶ ∨ - end_POSTSUBSCRIPT ( italic_y ) = italic_v. Lastly, if either u𝑢uitalic_u or v𝑣vitalic_v is the unique element \star then we may discharge the case as above.

See 4.7

Proof B.3.

This is Proposition 5.4.4 of Phoa [20]. We just show the case for the function types. Given a path fXBgsubscriptsquare-image-of-or-equals𝑋𝐵𝑓𝑔f\sqsubseteq_{X\to B}gitalic_f ⊑ start_POSTSUBSCRIPT italic_X → italic_B end_POSTSUBSCRIPT italic_g, it is clear that we may construct a path fxBgxsquare-image-of-or-equals𝑓𝑥𝐵𝑔𝑥f~{}x\sqsubseteq Bg~{}xitalic_f italic_x ⊑ italic_B italic_g italic_x for all x:X:𝑥𝑋x:Xitalic_x : italic_X. Conversely, suppose we are given a path fxBgxsquare-image-of-or-equals𝑓𝑥𝐵𝑔𝑥f~{}x\sqsubseteq Bg~{}xitalic_f italic_x ⊑ italic_B italic_g italic_x for all x:X:𝑥𝑋x:Xitalic_x : italic_X. By Proposition 4.1, B𝐵Bitalic_B is boundary separated, and so such paths are necessarily unique, and so we have a function α:XΣB:𝛼𝑋Σ𝐵\alpha:X\to\Sigma\to Bitalic_α : italic_X → roman_Σ → italic_B such that α(x)𝛼𝑥\alpha(x)italic_α ( italic_x ) is a path fxBgxsquare-image-of-or-equals𝑓𝑥𝐵𝑔𝑥f~{}x\sqsubseteq Bg~{}xitalic_f italic_x ⊑ italic_B italic_g italic_x. We then obtain a path fXBgsubscriptsquare-image-of-or-equals𝑋𝐵𝑓𝑔f\sqsubseteq_{X\to B}gitalic_f ⊑ start_POSTSUBSCRIPT italic_X → italic_B end_POSTSUBSCRIPT italic_g by taking the exponential transpose of α𝛼\alphaitalic_α.

See 4.8

Proof B.4.

In the forward direction, we have a path x𝑥absentx{\downarrow}italic_x ↓ square-image-of-or-equals\sqsubseteq y𝑦absenty{\downarrow}italic_y ↓, which means x𝑥absentx{\downarrow}italic_x ↓ implies y𝑦absenty{\downarrow}italic_y ↓ as the ΣΣ\Sigmaroman_Σ is linked by Proposition 3.12. Suppose x𝑥absentx{\downarrow}italic_x ↓, and let f:AΣ:𝑓𝐴Σf:A\to\Sigmaitalic_f : italic_A → roman_Σ be arbitrary. By assumption, we have that f(x)f(y)superscript𝑓𝑥superscript𝑓𝑦f^{\prime}(x)\to f^{\prime}(y)italic_f start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ( italic_x ) → italic_f start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ( italic_y ), where f((ϕ,u))=ϕfusuperscript𝑓italic-ϕ𝑢italic-ϕ𝑓𝑢f^{\prime}((\phi,u))=\phi\mathbin{\angle}f\circ uitalic_f start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ( ( italic_ϕ , italic_u ) ) = italic_ϕ ∠ italic_f ∘ italic_u. In other words, we have xf(x)𝑥𝑓𝑥x{\downarrow}\mathbin{\angle}f(x)italic_x ↓ ∠ italic_f ( italic_x ) implies yf(y)𝑦𝑓𝑦y{\downarrow}\mathbin{\angle}f(y)italic_y ↓ ∠ italic_f ( italic_y ). Since x𝑥absentx{\downarrow}italic_x ↓ holds, we have that f(x)f(y)𝑓𝑥𝑓𝑦f(x)\to f(y)italic_f ( italic_x ) → italic_f ( italic_y ), which by definition means xAysubscriptsquare-image-of-or-equals𝐴𝑥𝑦x\sqsubseteq_{A}yitalic_x ⊑ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_y.

In the backward direction, let α:xxAy\alpha:x{\downarrow}\to x\sqsubseteq_{A}yitalic_α : italic_x ↓ → italic_x ⊑ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_y be the given partial path. We may define a total path β:Σ𝖫A:𝛽Σ𝖫𝐴\beta:\Sigma\to\mathsf{L}Aitalic_β : roman_Σ → sansserif_L italic_A between x𝑥xitalic_x and y𝑦yitalic_y by setting β(ϕ)=(x,λp.αpϕ)\beta(\phi)=(x{\downarrow},\lambda p.~{}\alpha~{}p~{}\phi)italic_β ( italic_ϕ ) = ( italic_x ↓ , italic_λ italic_p . italic_α italic_p italic_ϕ ). Thus we have x𝖫Aysubscriptsquare-image-of-or-equals𝖫𝐴𝑥𝑦x\sqsubseteq_{\mathsf{L}A}yitalic_x ⊑ start_POSTSUBSCRIPT sansserif_L italic_A end_POSTSUBSCRIPT italic_y as required.

See 4.9

Proof B.5.

The final 𝖫𝖫\mathsf{L}sansserif_L-coalgebra is equipped with a global element :ω¯:¯𝜔\infty:\overline{\omega}∞ : over¯ start_ARG italic_ω end_ARG that can be thought of as the “point at infinity”. Define fsubscript𝑓f_{\infty}italic_f start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT be the element determined by the unique extension f¯:ω¯A:¯𝑓¯𝜔𝐴\overline{f}:\overline{\omega}\to Aover¯ start_ARG italic_f end_ARG : over¯ start_ARG italic_ω end_ARG → italic_A evaluated at the invariant point \infty.

  1. \normalshape(1)

    First we show that fsubscript𝑓f_{\infty}italic_f start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT is an upper bound for f𝑓fitalic_f. Fixing i:ω:𝑖𝜔i:\omegaitalic_i : italic_ω, we need to show that fiAfsubscriptsuperscriptsquare-image-of-or-equals𝐴𝑓𝑖subscript𝑓f~{}i\sqsubseteq^{\circ}_{A}f_{\infty}italic_f italic_i ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_f start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT. Because f¯¯𝑓\overline{f}over¯ start_ARG italic_f end_ARG extends f𝑓fitalic_f, it suffices to show f¯iAfsubscriptsuperscriptsquare-image-of-or-equals𝐴¯𝑓𝑖subscript𝑓\overline{f}~{}i\sqsubseteq^{\circ}_{A}f_{\infty}over¯ start_ARG italic_f end_ARG italic_i ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_f start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT. Using the fact that every map is monotone with respect to the specialization order, the result holds because iω¯subscriptsuperscriptsquare-image-of-or-equals¯𝜔𝑖i\sqsubseteq^{\circ}_{\overline{\omega}}\inftyitalic_i ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT start_POSTSUBSCRIPT over¯ start_ARG italic_ω end_ARG end_POSTSUBSCRIPT ∞.

  2. \normalshape(2)

    Let α𝛼\alphaitalic_α be an upper bound for f𝑓fitalic_f. We need to show that fαsuperscriptsquare-image-of-or-equalssubscript𝑓𝛼f_{\infty}\sqsubseteq^{\circ}\alphaitalic_f start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT italic_α. If the principal lower set (α)absent𝛼{\downarrow}(\alpha)↓ ( italic_α ) is complete, we have the following lifting situation:

    ω𝜔\omegaitalic_ωω¯¯𝜔\overline{\omega}over¯ start_ARG italic_ω end_ARG(α)={aaα}absent𝛼conditional-set𝑎superscriptsquare-image-of-or-equals𝑎𝛼{\downarrow}(\alpha)=\{a\mid a\sqsubseteq^{\circ}\alpha\}↓ ( italic_α ) = { italic_a ∣ italic_a ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT italic_α }f𝑓fitalic_ff~~𝑓\tilde{f}over~ start_ARG italic_f end_ARG

    In the above f~~𝑓\tilde{f}over~ start_ARG italic_f end_ARG is the unique extension of f𝑓fitalic_f considered as a map ω(α)\omega\to{\downarrow}(\alpha)italic_ω → ↓ ( italic_α ). By uniqueness of f¯¯𝑓\overline{f}over¯ start_ARG italic_f end_ARG as the extension of f:ωA:𝑓𝜔𝐴f:\omega\to Aitalic_f : italic_ω → italic_A, f~~𝑓\tilde{f}over~ start_ARG italic_f end_ARG is equal to f¯¯𝑓\overline{f}over¯ start_ARG italic_f end_ARG considered as maps ω¯A¯𝜔𝐴\overline{\omega}\to Aover¯ start_ARG italic_ω end_ARG → italic_A. Consequently we have that f=f¯()=f~()subscript𝑓¯𝑓~𝑓f_{\infty}=\overline{f}(\infty)=\tilde{f}(\infty)italic_f start_POSTSUBSCRIPT ∞ end_POSTSUBSCRIPT = over¯ start_ARG italic_f end_ARG ( ∞ ) = over~ start_ARG italic_f end_ARG ( ∞ ), so the result follows by observing that f~()(α)\tilde{f}(\infty)\in{\downarrow}(\alpha)over~ start_ARG italic_f end_ARG ( ∞ ) ∈ ↓ ( italic_α ).

    It remains to show that (α)absent𝛼{\downarrow}(\alpha)↓ ( italic_α ) is complete. We can express the principal lower set as follows:

    (α)absent𝛼\displaystyle{\downarrow}(\alpha)↓ ( italic_α ) ={aaα}absentconditional-set𝑎superscriptsquare-image-of-or-equals𝑎𝛼\displaystyle={\left\{a\mid a\sqsubseteq^{\circ}\alpha\right\}}= { italic_a ∣ italic_a ⊑ start_POSTSUPERSCRIPT ∘ end_POSTSUPERSCRIPT italic_α }
    ={af:AΣf(a)f(α)}absentconditional-set𝑎:for-all𝑓𝐴Σ𝑓𝑎𝑓𝛼\displaystyle={\left\{a\mid\forall f:A\to\Sigma~{}f(a)\to f(\alpha)\right\}}= { italic_a ∣ ∀ italic_f : italic_A → roman_Σ italic_f ( italic_a ) → italic_f ( italic_α ) }
    =f:AΣ{af(a)f(α)}absentsubscript:𝑓𝐴Σconditional-set𝑎𝑓𝑎𝑓𝛼\displaystyle=\bigcap_{f:A\to\Sigma}{\left\{a\mid f(a)\to f(\alpha)\right\}}= ⋂ start_POSTSUBSCRIPT italic_f : italic_A → roman_Σ end_POSTSUBSCRIPT { italic_a ∣ italic_f ( italic_a ) → italic_f ( italic_α ) }

    Because complete types are internally complete, the result would follow if we can show that S={af(a)f(α)}𝑆conditional-set𝑎𝑓𝑎𝑓𝛼S={\left\{a\mid f(a)\to f(\alpha)\right\}}italic_S = { italic_a ∣ italic_f ( italic_a ) → italic_f ( italic_α ) } is complete. We may show that S𝑆Sitalic_S can be computed as follows:

    S𝑆Sitalic_SΣΣsuperscriptΣΣ\Sigma^{\Sigma}roman_Σ start_POSTSUPERSCRIPT roman_Σ end_POSTSUPERSCRIPTA𝐴Aitalic_AΣ×ΣΣΣ\Sigma\times\Sigmaroman_Σ × roman_Σf,f(α)𝑓𝑓𝛼\langle f,f(\alpha)\rangle⟨ italic_f , italic_f ( italic_α ) ⟩\partial

    Since S𝑆Sitalic_S can be defined as the limit of a diagram of complete types, it is complete as well.

See 4.14

Proof B.6.

Given absquare-image-of-or-equals𝑎𝑏a\sqsubseteq bitalic_a ⊑ italic_b, we derive a path ΣBΣ𝐵\Sigma\to Broman_Σ → italic_B whose boundary is (fa,fb)𝑓𝑎𝑓𝑏(f~{}a,f~{}b)( italic_f italic_a , italic_f italic_b ) by postcomposing with f𝑓fitalic_f, and so fafbsquare-image-of-or-equals𝑓𝑎𝑓𝑏f~{}a\sqsubseteq f~{}bitalic_f italic_a ⊑ italic_f italic_b as well.

See 4.15

Proof B.7.

Predomains are complete, so we have the following extensions of d𝑑ditalic_d and fd𝑓𝑑f\circ ditalic_f ∘ italic_d:

ω𝜔\omegaitalic_ωω¯¯𝜔\overline{\omega}over¯ start_ARG italic_ω end_ARGA𝐴Aitalic_AB𝐵Bitalic_Bf𝑓fitalic_ffd¯¯𝑓𝑑\overline{f\circ d}over¯ start_ARG italic_f ∘ italic_d end_ARGd¯¯𝑑\overline{d}over¯ start_ARG italic_d end_ARG

Because extensions along ωω¯𝜔¯𝜔\omega\hookrightarrow\overline{\omega}italic_ω ↪ over¯ start_ARG italic_ω end_ARG are unique for complete types, we have fd¯=fd¯𝑓¯𝑑¯𝑓𝑑f\circ\overline{d}=\overline{f\circ d}italic_f ∘ over¯ start_ARG italic_d end_ARG = over¯ start_ARG italic_f ∘ italic_d end_ARG. But by definition of the synthetic ω𝜔\omegaitalic_ω-join, this means that f(d)=f(d¯())=fd¯()=(fd)𝑓𝑑𝑓¯𝑑¯𝑓𝑑𝑓𝑑f(\bigvee d)=f(\overline{d}(\infty))=\overline{f\circ d}(\infty)=\bigvee(f% \circ d)italic_f ( ⋁ italic_d ) = italic_f ( over¯ start_ARG italic_d end_ARG ( ∞ ) ) = over¯ start_ARG italic_f ∘ italic_d end_ARG ( ∞ ) = ⋁ ( italic_f ∘ italic_d ).

Proposition B.8.

The intersection of a family of admissible subsets of a domain is admissible.

Proof B.9.

The least element is contained in the intersection as it is contained in every fiber. Suppose that f:ωA:𝑓𝜔𝐴f:\omega\to Aitalic_f : italic_ω → italic_A is a synthetic ω𝜔\omegaitalic_ω-chain such that fiFsubscript𝑓𝑖𝐹f_{i}\in\bigcap Fitalic_f start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∈ ⋂ italic_F. But since fiFjsubscript𝑓𝑖subscript𝐹𝑗f_{i}\in F_{j}italic_f start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∈ italic_F start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT for every j:J:𝑗𝐽j:Jitalic_j : italic_J, we have fFj𝑓subscript𝐹𝑗\bigvee f\in F_{j}⋁ italic_f ∈ italic_F start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT as every Fjsubscript𝐹𝑗F_{j}italic_F start_POSTSUBSCRIPT italic_j end_POSTSUBSCRIPT is admissible, which means fF𝑓𝐹\bigvee f\in\bigcap F⋁ italic_f ∈ ⋂ italic_F as well.

Proposition B.10.

If P,Q𝑃𝑄P,Qitalic_P , italic_Q are ΣΣ\Sigmaroman_Σ-subsets of a domain A𝐴Aitalic_A, then the exponential subobject QPsuperscript𝑄𝑃Q^{P}italic_Q start_POSTSUPERSCRIPT italic_P end_POSTSUPERSCRIPT is an admissible subset of A𝐴Aitalic_A.

Proof B.11.

Let fiQPsubscript𝑓𝑖superscript𝑄𝑃f_{i}\in Q^{P}italic_f start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∈ italic_Q start_POSTSUPERSCRIPT italic_P end_POSTSUPERSCRIPT for some synthetic ω𝜔\omegaitalic_ω-chain f𝑓fitalic_f. Suppose that fP𝑓𝑃\bigvee f\in P⋁ italic_f ∈ italic_P. We need to show that fQ𝑓𝑄\bigvee f\in Q⋁ italic_f ∈ italic_Q. By the universal property of \bigvee, we may assume that fiPsubscript𝑓𝑖𝑃f_{i}\in Pitalic_f start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∈ italic_P for some i:ω:𝑖𝜔i:\omegaitalic_i : italic_ω. By assumption, this means that fiQsubscript𝑓𝑖𝑄f_{i}\in Qitalic_f start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ∈ italic_Q and thence fQ𝑓𝑄\bigvee f\in Q⋁ italic_f ∈ italic_Q as every ΣΣ\Sigmaroman_Σ-subset is monotone in the synthetic order.

Appendix C Properties of the denotational semantics

See 6.1

Proof C.1.

Routine computation using the distributive law τ𝜏\tauitalic_τ of ×\mathbb{C}\times-blackboard_C × - over the lifting monad.

Appendix D Properties of the computational semantics

See 7.1

Proof D.1.

Consider the following subset:

P={α[e,v,v]α(e,v)α(e,v)v=v}\displaystyle P={\left\{\alpha\mid\forall{\left[e,v,v^{\prime}\right]}~{}% \alpha(e,v){\downarrow}\land\alpha(e,v^{\prime}){\downarrow}\to v=v^{\prime}% \right\}}italic_P = { italic_α ∣ ∀ [ italic_e , italic_v , italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ] italic_α ( italic_e , italic_v ) ↓ ∧ italic_α ( italic_e , italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ↓ → italic_v = italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT }

We may check that P𝑃Pitalic_P is admissible and proceed by fixed-point induction. Suppose that αP𝛼𝑃\alpha\in Pitalic_α ∈ italic_P and that Φ𝖾𝗏𝖺𝗅(α)(e,v)subscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒𝑣absent\Phi_{\mathsf{eval}}(\alpha)(e,v){\downarrow}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , italic_v ) ↓ and Φ𝖾𝗏𝖺𝗅(α)(e,v)subscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒superscript𝑣absent\Phi_{\mathsf{eval}}(\alpha)(e,v^{\prime}){\downarrow}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ↓. We need to show that v=v𝑣superscript𝑣v=v^{\prime}italic_v = italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT. We proceed by cases on 𝗈𝗎𝗍(e)𝗈𝗎𝗍𝑒\mathsf{out}(e)sansserif_out ( italic_e ).

  1. \normalshape(1)

    If ec,emaps-to𝑒superscript𝑐superscript𝑒e\mapsto c^{\prime},e^{\prime}italic_e ↦ italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, we may deduce that α(e,v)𝛼superscript𝑒𝑣absent\alpha(e^{\prime},v){\downarrow}italic_α ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_v ) ↓ and α(e,v)𝛼superscript𝑒superscript𝑣absent\alpha(e^{\prime},v^{\prime}){\downarrow}italic_α ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ↓, so the result follows from the assumption that αP𝛼𝑃\alpha\in Pitalic_α ∈ italic_P.

  2. \normalshape(2)

    Otherwise, we have that e=v𝑒𝑣e=vitalic_e = italic_v and e=v𝑒superscript𝑣e=v^{\prime}italic_e = italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT by definition of Φ𝖾𝗏𝖺𝗅subscriptΦ𝖾𝗏𝖺𝗅\Phi_{\mathsf{eval}}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT, and so v=v𝑣superscript𝑣v=v^{\prime}italic_v = italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

See 7.2

Proof D.2.

Consider the following subset of ΠA:𝗍𝗉.𝖴𝖥A𝖴𝖥A𝖳(1)formulae-sequencesubscriptΠ:𝐴𝗍𝗉𝖴𝖥𝐴𝖴𝖥𝐴𝖳1\Pi_{A:\mathsf{tp}}.~{}\mathsf{U}\mathsf{F}A\to\mathsf{U}\mathsf{F}A\to\mathsf% {T}(1)roman_Π start_POSTSUBSCRIPT italic_A : sansserif_tp end_POSTSUBSCRIPT . sansserif_UF italic_A → sansserif_UF italic_A → sansserif_T ( 1 ):

P={α[e]α(e,v)𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))=α(e,v)+𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))}\displaystyle P={\left\{\alpha\mid\forall{\left[e\right]}~{}\alpha(e,v){% \downarrow}\land\mathsf{eval}(g~{}v,\mathsf{ret}(w)){\downarrow}\to\mathsf{% eval}(e;g,\mathsf{ret}(w))=\alpha(e,v)+\mathsf{eval}(g~{}v,\mathsf{ret}(w))% \right\}}italic_P = { italic_α ∣ ∀ [ italic_e ] italic_α ( italic_e , italic_v ) ↓ ∧ sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) ↓ → sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) = italic_α ( italic_e , italic_v ) + sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) }

It suffices to show that 𝖾𝗏𝖺𝗅P𝖾𝗏𝖺𝗅𝑃\mathsf{eval}\in Psansserif_eval ∈ italic_P. Observing that P𝑃Pitalic_P is admissible, we proceed by fixed-point induction. Suppose that αP𝛼𝑃\alpha\in Pitalic_α ∈ italic_P, Φ𝖾𝗏𝖺𝗅(α)(e,v)subscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒𝑣absent\Phi_{\mathsf{eval}}(\alpha)(e,v){\downarrow}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , italic_v ) ↓, and that 𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤absent\mathsf{eval}(g~{}v,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) ↓. We need to show that 𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))=Φ𝖾𝗏𝖺𝗅(α)(e,v)+𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑒𝑔𝗋𝖾𝗍𝑤subscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒𝑣𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤\mathsf{eval}(e;g,\mathsf{ret}(w))=\Phi_{\mathsf{eval}}(\alpha)(e,v)+\mathsf{% eval}(g~{}v,\mathsf{ret}(w))sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) = roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , italic_v ) + sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ). We proceed by cases on 𝗈𝗎𝗍(e)𝗈𝗎𝗍𝑒\mathsf{out}(e)sansserif_out ( italic_e ).

  1. \normalshape(1)

    If ec,emaps-to𝑒superscript𝑐superscript𝑒e\mapsto c^{\prime},e^{\prime}italic_e ↦ italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, then we compute:

    𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑒𝑔𝗋𝖾𝗍𝑤\displaystyle\mathsf{eval}(e;g,\mathsf{ret}(w))sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) =c𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))absentsuperscript𝑐𝖾𝗏𝖺𝗅superscript𝑒𝑔𝗋𝖾𝗍𝑤\displaystyle=c^{\prime}\boxplus\mathsf{eval}(e^{\prime};g,\mathsf{ret}(w))= italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊞ sansserif_eval ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) )
    =c+α(e,v)+𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))absentsuperscript𝑐𝛼superscript𝑒𝑣𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤\displaystyle=c^{\prime}+\alpha(e^{\prime},v)+\mathsf{eval}(g~{}v,\mathsf{ret}% (w))= italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + italic_α ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_v ) + sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) )
    =Φ𝖾𝗏𝖺𝗅(α)(e,v)+𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))absentsubscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒𝑣𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤\displaystyle=\Phi_{\mathsf{eval}}(\alpha)(e,v)+\mathsf{eval}(g~{}v,\mathsf{% ret}(w))= roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , italic_v ) + sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) )

    Where the first equality follows from the assumption that αP𝛼𝑃\alpha\in Pitalic_α ∈ italic_P and the second by the definition of Φ𝖾𝗏𝖺𝗅subscriptΦ𝖾𝗏𝖺𝗅\Phi_{\mathsf{eval}}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT.

  2. \normalshape(2)

    Otherwise, we have that e𝗏𝖺𝗅𝑒𝗏𝖺𝗅e~{}\mathsf{val}italic_e sansserif_val. Since Φ𝖾𝗏𝖺𝗅(α)(e,𝗋𝖾𝗍(v))=(e=𝗋𝖾𝗍(v),0)=(e=𝗋𝖾𝗍(v))\Phi_{\mathsf{eval}}(\alpha)(e,\mathsf{ret}(v)){\downarrow}=(e=\mathsf{ret}(v)% ,0){\downarrow}=(e=\mathsf{ret}(v))roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , sansserif_ret ( italic_v ) ) ↓ = ( italic_e = sansserif_ret ( italic_v ) , 0 ) ↓ = ( italic_e = sansserif_ret ( italic_v ) ) holds, we can compute:

    𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑒𝑔𝗋𝖾𝗍𝑤\displaystyle\mathsf{eval}(e;g,\mathsf{ret}(w))sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) =𝖾𝗏𝖺𝗅(𝗋𝖾𝗍(v);g,𝗋𝖾𝗍(w))absent𝖾𝗏𝖺𝗅𝗋𝖾𝗍𝑣𝑔𝗋𝖾𝗍𝑤\displaystyle=\mathsf{eval}(\mathsf{ret}(v);g,\mathsf{ret}(w))= sansserif_eval ( sansserif_ret ( italic_v ) ; italic_g , sansserif_ret ( italic_w ) )
    =Φ𝖾𝗏𝖺𝗅(𝖾𝗏𝖺𝗅)(𝗋𝖾𝗍(v);g,𝗋𝖾𝗍(w))absentsubscriptΦ𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅𝗋𝖾𝗍𝑣𝑔𝗋𝖾𝗍𝑤\displaystyle=\Phi_{\mathsf{eval}}(\mathsf{eval})(\mathsf{ret}(v);g,\mathsf{% ret}(w))= roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( sansserif_eval ) ( sansserif_ret ( italic_v ) ; italic_g , sansserif_ret ( italic_w ) )
    =𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))absent𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤\displaystyle=\mathsf{eval}(g~{}v,\mathsf{ret}(w))= sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) )

    But this is what we needed to show since Φ𝖾𝗏𝖺𝗅(α)(e,𝗋𝖾𝗍(v))=0subscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒𝗋𝖾𝗍𝑣0\Phi_{\mathsf{eval}}(\alpha)(e,\mathsf{ret}(v))=0roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , sansserif_ret ( italic_v ) ) = 0.

See 7.4

Proof D.3.

Consider the subset P𝖴𝖥A𝖴𝖥A𝖳(1)𝑃𝖴𝖥𝐴𝖴𝖥𝐴𝖳1P\subseteq\mathsf{U}\mathsf{F}A\to\mathsf{U}\mathsf{F}A\to\mathsf{T}(1)italic_P ⊆ sansserif_UF italic_A → sansserif_UF italic_A → sansserif_T ( 1 ) defined as the intersection of the following subsets:

Q={αα𝖾𝗏𝖺𝗅}𝑄conditional-set𝛼square-image-of-or-equals𝛼𝖾𝗏𝖺𝗅\displaystyle Q={\left\{\alpha\mid\alpha\sqsubseteq\mathsf{eval}\right\}}italic_Q = { italic_α ∣ italic_α ⊑ sansserif_eval }
R={α[c,e,n](enc,e)(α(e;g,𝗋𝖾𝗍(w)))φ(c+α(e;g,𝗋𝖾𝗍(w)))}\displaystyle R={\left\{\alpha\mid\forall{\left[c^{\prime},e^{\prime},n\right]% }~{}(e\mapsto^{n}c^{\prime},e^{\prime})\land{\left(\alpha(e^{\prime};g,\mathsf% {ret}(w)){\downarrow}\right)}\to\varphi(c^{\prime}+\alpha(e^{\prime};g,\mathsf% {ret}(w)))\right\}}italic_R = { italic_α ∣ ∀ [ italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_n ] ( italic_e ↦ start_POSTSUPERSCRIPT italic_n end_POSTSUPERSCRIPT italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ∧ ( italic_α ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) ↓ ) → italic_φ ( italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + italic_α ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) ) }

It suffices to show that 𝖾𝗏𝖺𝗅P𝖾𝗏𝖺𝗅𝑃\mathsf{eval}\in Psansserif_eval ∈ italic_P. We have that P𝑃Pitalic_P is admissible, and we proceed by fixed-point induction. Suppose that αP𝛼𝑃\alpha\in Pitalic_α ∈ italic_P. We need to show that Φ𝖾𝗏𝖺𝗅(α)PsubscriptΦ𝖾𝗏𝖺𝗅𝛼𝑃\Phi_{\mathsf{eval}}(\alpha)\in Proman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ∈ italic_P, where Φ𝖾𝗏𝖺𝗅subscriptΦ𝖾𝗏𝖺𝗅\Phi_{\mathsf{eval}}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT is the characteristic functional of 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval (Section 7.1). It’s immediate that Φ𝖾𝗏𝖺𝗅(α)QsubscriptΦ𝖾𝗏𝖺𝗅𝛼𝑄\Phi_{\mathsf{eval}}(\alpha)\in Qroman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ∈ italic_Q. It remains to show that it is also contained in R𝑅Ritalic_R. So suppose that enc,esuperscriptmaps-to𝑛𝑒superscript𝑐superscript𝑒e\mapsto^{n}c^{\prime},e^{\prime}italic_e ↦ start_POSTSUPERSCRIPT italic_n end_POSTSUPERSCRIPT italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT and Φ𝖾𝗏𝖺𝗅(α)(e;g,𝗋𝖾𝗍(w))subscriptΦ𝖾𝗏𝖺𝗅𝛼superscript𝑒𝑔𝗋𝖾𝗍𝑤absent\Phi_{\mathsf{eval}}(\alpha)(e^{\prime};g,\mathsf{ret}(w)){\downarrow}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) ↓. We want to show that φ(c+Φ𝖾𝗏𝖺𝗅(α)(e;g,𝗋𝖾𝗍(w)))𝜑superscript𝑐subscriptΦ𝖾𝗏𝖺𝗅𝛼superscript𝑒𝑔𝗋𝖾𝗍𝑤\varphi(c^{\prime}+\Phi_{\mathsf{eval}}(\alpha)(e^{\prime};g,\mathsf{ret}(w)))italic_φ ( italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) ). We proceed by cases on 𝗈𝗎𝗍(e)𝗈𝗎𝗍superscript𝑒\mathsf{out}(e^{\prime})sansserif_out ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ).

  1. \normalshape(1)

    If 𝗈𝗎𝗍(e)=𝗂𝗇𝗅\mathsf{out}(e^{\prime})=\mathsf{inl}\cdot\starsansserif_out ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = sansserif_inl ⋅ ⋆, then we know that e=𝗋𝖾𝗍(v)superscript𝑒𝗋𝖾𝗍𝑣e^{\prime}=\mathsf{ret}(v)italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT = sansserif_ret ( italic_v ) for some v:𝖴𝖥1:𝑣𝖴𝖥1v:\mathsf{U}\mathsf{F}1italic_v : sansserif_UF 1. Stepping the operational semantics, we have that 𝗋𝖾𝗍(v);g0,gvformulae-sequencemaps-to𝗋𝖾𝗍𝑣𝑔0𝑔𝑣\mathsf{ret}(v);g\mapsto 0,g~{}vsansserif_ret ( italic_v ) ; italic_g ↦ 0 , italic_g italic_v, and by definition of the computational semantics Φ𝖾𝗏𝖺𝗅(α)(e;g,𝗋𝖾𝗍(w))=0α(gv,𝗋𝖾𝗍(w))=α(gv,𝗋𝖾𝗍(w))subscriptΦ𝖾𝗏𝖺𝗅𝛼superscript𝑒𝑔𝗋𝖾𝗍𝑤0𝛼𝑔𝑣𝗋𝖾𝗍𝑤𝛼𝑔𝑣𝗋𝖾𝗍𝑤\Phi_{\mathsf{eval}}(\alpha)(e^{\prime};g,\mathsf{ret}(w))=0\boxplus\alpha(g~{% }v,\mathsf{ret}(w))=\alpha(g~{}v,\mathsf{ret}(w))roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) = 0 ⊞ italic_α ( italic_g italic_v , sansserif_ret ( italic_w ) ) = italic_α ( italic_g italic_v , sansserif_ret ( italic_w ) ). Since we assumed αQα𝖾𝗏𝖺𝗅iff𝛼𝑄square-image-of-or-equals𝛼𝖾𝗏𝖺𝗅\alpha\in Q\iff\alpha\sqsubseteq\mathsf{eval}italic_α ∈ italic_Q ⇔ italic_α ⊑ sansserif_eval, we also have 𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤absent\mathsf{eval}(g~{}v,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) ↓, and since \mathbb{C}blackboard_C is discrete we have α(gv,𝗋𝖾𝗍(w))=𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝛼𝑔𝑣𝗋𝖾𝗍𝑤𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤\alpha(g~{}v,\mathsf{ret}(w))=\mathsf{eval}(g~{}v,\mathsf{ret}(w))italic_α ( italic_g italic_v , sansserif_ret ( italic_w ) ) = sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ). Recalling the premise and the fact that 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))=c𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍𝑣superscript𝑐\mathsf{eval}(e,\mathsf{ret}(v))=c^{\prime}sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) = italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, we may conclude that φ(c+𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w)))𝜑superscript𝑐𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤\varphi(c^{\prime}+\mathsf{eval}(g~{}v,\mathsf{ret}(w)))italic_φ ( italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) ), which is what we needed to show.

  2. \normalshape(2)

    Otherwise, 𝗈𝗎𝗍(e)=𝗂𝗇𝗋(c′′,e′′)𝗈𝗎𝗍superscript𝑒𝗂𝗇𝗋superscript𝑐′′superscript𝑒′′\mathsf{out}(e^{\prime})=\mathsf{inr}\cdot(c^{\prime\prime},e^{\prime\prime})sansserif_out ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) = sansserif_inr ⋅ ( italic_c start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ) for some e′′:𝖴𝖥1:superscript𝑒′′𝖴𝖥1e^{\prime\prime}:\mathsf{U}\mathsf{F}1italic_e start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT : sansserif_UF 1, and we have that e;gc′′,e′′;gformulae-sequencemaps-tosuperscript𝑒𝑔superscript𝑐′′superscript𝑒′′𝑔e^{\prime};g\mapsto c^{\prime\prime},e^{\prime\prime};gitalic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g ↦ italic_c start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ; italic_g. By definition of the computational semantics, this means that Φ𝖾𝗏𝖺𝗅(α)(e;g,𝗋𝖾𝗍(w))=c′′α(e′′;g,𝗋𝖾𝗍(w))subscriptΦ𝖾𝗏𝖺𝗅𝛼superscript𝑒𝑔𝗋𝖾𝗍𝑤superscript𝑐′′𝛼superscript𝑒′′𝑔𝗋𝖾𝗍𝑤\Phi_{\mathsf{eval}}(\alpha)(e^{\prime};g,\mathsf{ret}(w))=c^{\prime\prime}% \boxplus\alpha(e^{\prime\prime};g,\mathsf{ret}(w))roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) = italic_c start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⊞ italic_α ( italic_e start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ). Since we assumed that c′′α(e′′;g,𝗋𝖾𝗍(w))superscript𝑐′′𝛼superscript𝑒′′𝑔𝗋𝖾𝗍𝑤absentc^{\prime\prime}\boxplus\alpha(e^{\prime\prime};g,\mathsf{ret}(w)){\downarrow}italic_c start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ⊞ italic_α ( italic_e start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) ↓, we can use the laws of the derived algebra (Proposition 6.1) to deduce that α(e′′;g,𝗋𝖾𝗍(w))𝛼superscript𝑒′′𝑔𝗋𝖾𝗍𝑤absent\alpha(e^{\prime\prime};g,\mathsf{ret}(w)){\downarrow}italic_α ( italic_e start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) ↓ as well, and so by the assumption that αRP𝛼𝑅𝑃\alpha\in R\subseteq Pitalic_α ∈ italic_R ⊆ italic_P, we have that φ(c+c′′+α(e′′;g,𝗋𝖾𝗍(w)))𝜑superscript𝑐superscript𝑐′′𝛼superscript𝑒′′𝑔𝗋𝖾𝗍𝑤\varphi(c^{\prime}+c^{\prime\prime}+\alpha(e^{\prime\prime};g,\mathsf{ret}(w)))italic_φ ( italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT + italic_c start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT + italic_α ( italic_e start_POSTSUPERSCRIPT ′ ′ end_POSTSUPERSCRIPT ; italic_g , sansserif_ret ( italic_w ) ) ) holds, which is what we needed to show.

See 7.5

Proof D.4.

In one direction, we show that 𝗉𝗋𝗈𝖿𝗂𝗅𝖾((e;g);i)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝑔𝑖absent\mathsf{profile}((e;g);i){\downarrow}sansserif_profile ( ( italic_e ; italic_g ) ; italic_i ) ↓ implies 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;i))\mathsf{profile}(e;(\lambda v.~{}g~{}v;i)){\downarrow}sansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_i ) ) ↓ and both denote identical costs. Consider the ΣΣ\Sigmaroman_Σ-predicate φ𝜑\varphiitalic_φ such that φ(c)𝜑𝑐\varphi(c)italic_φ ( italic_c ) if and only if 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;h))=c\mathsf{profile}(e;(\lambda v.~{}g~{}v;h))=csansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_h ) ) = italic_c. Suppose that 𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑒𝑔𝗋𝖾𝗍𝑤absent\mathsf{eval}(e;g,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) ↓ and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(iw)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑖𝑤absent\mathsf{profile}(i~{}w){\downarrow}sansserif_profile ( italic_i italic_w ) ↓. By computational induction on sequencing Proposition 7.4, it suffices to show that 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;h))=𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))+𝗉𝗋𝗈𝖿𝗂𝗅𝖾(iw)\mathsf{profile}(e;(\lambda v.~{}g~{}v;h))=\mathsf{eval}(e;g,\mathsf{ret}(w))+% \mathsf{profile}(i~{}w)sansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_h ) ) = sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) + sansserif_profile ( italic_i italic_w ). Applying computational induction on 𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑒𝑔𝗋𝖾𝗍𝑤absent\mathsf{eval}(e;g,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) ↓, we further suppose that 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍𝑣absent\mathsf{eval}(e,\mathsf{ret}(v)){\downarrow}sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) ↓ and 𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤absent\mathsf{eval}(g~{}v,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) ↓ and aim to show that 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;h))=𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))+𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))+𝗉𝗋𝗈𝖿𝗂𝗅𝖾(iw)\mathsf{profile}(e;(\lambda v.~{}g~{}v;h))=\mathsf{eval}(e,\mathsf{ret}(v))+% \mathsf{eval}(g~{}v,\mathsf{ret}(w))+\mathsf{profile}(i~{}w)sansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_h ) ) = sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) + sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) + sansserif_profile ( italic_i italic_w ).

  1. \normalshape(1)

    We claim that 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;i))\mathsf{profile}(e;(\lambda v.~{}g~{}v;i)){\downarrow}sansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_i ) ) ↓. By the big-step semantics of profiling Corollary 7.3, it suffices to show that 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍𝑣absent\mathsf{eval}(e,\mathsf{ret}(v)){\downarrow}sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) ↓ for some v𝑣vitalic_v and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(gv;i)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑔𝑣𝑖absent\mathsf{profile}(g~{}v;i){\downarrow}sansserif_profile ( italic_g italic_v ; italic_i ) ↓. The former follows from our assumption; for the latter, it suffices to show that 𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤absent\mathsf{eval}(g~{}v,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) ↓ and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(iw)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑖𝑤absent\mathsf{profile}(i~{}w){\downarrow}sansserif_profile ( italic_i italic_w ) ↓, both of which follow from assumptions.

  2. \normalshape(2)

    Given that 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;i))\mathsf{profile}(e;(\lambda v.~{}g~{}v;i)){\downarrow}sansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_i ) ) ↓, we may apply computational induction again: supposing that 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍superscript𝑣absent\mathsf{eval}(e,\mathsf{ret}(v^{\prime})){\downarrow}sansserif_eval ( italic_e , sansserif_ret ( italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ) ↓ and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(gv;i)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑔𝑣𝑖absent\mathsf{profile}(g~{}v;i){\downarrow}sansserif_profile ( italic_g italic_v ; italic_i ) ↓, we have to show that 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))+𝗉𝗋𝗈𝖿𝗂𝗅𝖾(gv;i)=𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))+𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))+𝗉𝗋𝗈𝖿𝗂𝗅𝖾(iw)𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍superscript𝑣𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑔𝑣𝑖𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍𝑣𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑖𝑤\mathsf{eval}(e,\mathsf{ret}(v^{\prime}))+\mathsf{profile}(g~{}v;i)=\mathsf{% eval}(e,\mathsf{ret}(v))+\mathsf{eval}(g~{}v,\mathsf{ret}(w))+\mathsf{profile}% (i~{}w)sansserif_eval ( italic_e , sansserif_ret ( italic_v start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ) ) + sansserif_profile ( italic_g italic_v ; italic_i ) = sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) + sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) + sansserif_profile ( italic_i italic_w ), which follows from the uniqueness of evaluation Proposition 7.1 and big-step semantics of profiling Corollary 7.3.

In the other direction, suppose that 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;(λv.gv;i))\mathsf{profile}(e;(\lambda v.~{}g~{}v;i)){\downarrow}sansserif_profile ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_i ) ) ↓. It suffices to show that 𝗉𝗋𝗈𝖿𝗂𝗅𝖾((e;g);i)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝑔𝑖absent\mathsf{profile}((e;g);i){\downarrow}sansserif_profile ( ( italic_e ; italic_g ) ; italic_i ) ↓. By computational induction, we may assume that 𝖾𝗏𝖺𝗅(e,𝗋𝖾𝗍(v))𝖾𝗏𝖺𝗅𝑒𝗋𝖾𝗍𝑣absent\mathsf{eval}(e,\mathsf{ret}(v)){\downarrow}sansserif_eval ( italic_e , sansserif_ret ( italic_v ) ) ↓ and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(gv;i)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑔𝑣𝑖absent\mathsf{profile}(g~{}v;i){\downarrow}sansserif_profile ( italic_g italic_v ; italic_i ) ↓. Applying computational induction again, we can also assume that 𝖾𝗏𝖺𝗅(gv,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑔𝑣𝗋𝖾𝗍𝑤absent\mathsf{eval}(g~{}v,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_g italic_v , sansserif_ret ( italic_w ) ) ↓ and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(iw)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑖𝑤absent\mathsf{profile}(i~{}w){\downarrow}sansserif_profile ( italic_i italic_w ) ↓ for some w𝑤witalic_w. By the big-step semantics of profiling Corollary 7.3, it suffices to show that 𝖾𝗏𝖺𝗅(e;g,𝗋𝖾𝗍(w))𝖾𝗏𝖺𝗅𝑒𝑔𝗋𝖾𝗍𝑤absent\mathsf{eval}(e;g,\mathsf{ret}(w)){\downarrow}sansserif_eval ( italic_e ; italic_g , sansserif_ret ( italic_w ) ) ↓ and 𝗉𝗋𝗈𝖿𝗂𝗅𝖾(iw)𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑖𝑤absent\mathsf{profile}(i~{}w){\downarrow}sansserif_profile ( italic_i italic_w ) ↓. The latter is our assumption, and the former follows from the big-step semantics of evaluation Proposition 7.2.

Proposition D.5.

The following is valid: {mathpar} \inferrule [e]for-alldelimited-[]𝑒\forall[e]~{}∀ [ italic_e ] 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(f, λe){\downarrow} 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(e[v], 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w)){\downarrow} φ(𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(f, λe) + 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(e[v], 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w))) 𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(f v, 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w)){\downarrow} φ(𝖾𝗏𝖺𝗅𝖾𝗏𝖺𝗅\mathsf{eval}sansserif_eval(f v, 𝗋𝖾𝗍𝗋𝖾𝗍\mathsf{ret}sansserif_ret(w)))

Proposition D.6.

We have that 𝖾𝗏𝖺𝗅((e;g)w,z)=𝖾𝗏𝖺𝗅(e;λv.gvw,z)\mathsf{eval}((e;g)~{}w,z)=\mathsf{eval}(e;\lambda v.~{}g~{}v~{}w,z)sansserif_eval ( ( italic_e ; italic_g ) italic_w , italic_z ) = sansserif_eval ( italic_e ; italic_λ italic_v . italic_g italic_v italic_w , italic_z ).

Appendix E Soundness of the denotational semantics

See 8.1

Proof E.1.

By induction on the derivation of ec,emaps-to𝑒𝑐superscript𝑒e\mapsto c,e^{\prime}italic_e ↦ italic_c , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

See 8.2

Proof E.2.

Consider the following subset:

P={α[e]α(e,v)e=𝖾𝗏𝖺𝗅(e,v)v}\displaystyle P={\left\{\alpha\mid\forall{\left[e\right]}~{}\alpha(e,v){% \downarrow}\to\llbracket e\rrbracket=\mathsf{eval}(e,v)\boxplus\llbracket v% \rrbracket\right\}}italic_P = { italic_α ∣ ∀ [ italic_e ] italic_α ( italic_e , italic_v ) ↓ → ⟦ italic_e ⟧ = sansserif_eval ( italic_e , italic_v ) ⊞ ⟦ italic_v ⟧ }

Because e=𝖾𝗏𝖺𝗅(e,v)v\llbracket e\rrbracket=\mathsf{eval}(e,v)\boxplus\llbracket v\rrbracket⟦ italic_e ⟧ = sansserif_eval ( italic_e , italic_v ) ⊞ ⟦ italic_v ⟧ is a ΣΣ\Sigmaroman_Σ-proposition, we see that P𝑃Pitalic_P is an admissible subset. Suppose that αP𝛼𝑃\alpha\in Pitalic_α ∈ italic_P and Φ𝖾𝗏𝖺𝗅(α)(e,v)subscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒𝑣absent\Phi_{\mathsf{eval}}(\alpha)(e,v){\downarrow}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , italic_v ) ↓. We need to show that e=𝖾𝗏𝖺𝗅(e,v)v\llbracket e\rrbracket=\mathsf{eval}(e,v)\boxplus\llbracket v\rrbracket⟦ italic_e ⟧ = sansserif_eval ( italic_e , italic_v ) ⊞ ⟦ italic_v ⟧. We proceed by cases on 𝗈𝗎𝗍(e)𝗈𝗎𝗍𝑒\mathsf{out}(e)sansserif_out ( italic_e ).

  1. \normalshape(1)

    If ec,emaps-to𝑒superscript𝑐superscript𝑒e\mapsto c^{\prime},e^{\prime}italic_e ↦ italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT, then by the soundness of the one step relation Proposition 8.1, it suffices to show that ce=c𝖾𝗏𝖺𝗅(e,v)vc^{\prime}\boxplus\llbracket e^{\prime}\rrbracket=c^{\prime}\boxplus\mathsf{% eval}(e^{\prime},v)\boxplus\llbracket v\rrbracketitalic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊞ ⟦ italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⟧ = italic_c start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ⊞ sansserif_eval ( italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT , italic_v ) ⊞ ⟦ italic_v ⟧, which follows from the assumption, noting that Φ𝖾𝗏𝖺𝗅(α)(e,v)subscriptΦ𝖾𝗏𝖺𝗅𝛼𝑒𝑣absent\Phi_{\mathsf{eval}}(\alpha)(e,v){\downarrow}roman_Φ start_POSTSUBSCRIPT sansserif_eval end_POSTSUBSCRIPT ( italic_α ) ( italic_e , italic_v ) ↓ implies α(e,v)𝛼𝑒𝑣absent\alpha(e,v){\downarrow}italic_α ( italic_e , italic_v ) ↓.

  2. \normalshape(2)

    Otherwise, we have that e=v𝑒𝑣e=vitalic_e = italic_v, and so the result holds since 𝖾𝗏𝖺𝗅(e,e)=0𝖾𝗏𝖺𝗅𝑒𝑒0\mathsf{eval}(e,e)=0sansserif_eval ( italic_e , italic_e ) = 0.

Appendix F Proofs for the computational adequacy property

Proposition F.1.

If dXesubscriptsubgroup-of𝑋𝑑𝑒d\lhd_{X}eitalic_d ⊲ start_POSTSUBSCRIPT italic_X end_POSTSUBSCRIPT italic_e and ec,emaps-tosuperscript𝑒𝑐𝑒e^{\prime}\mapsto c,eitalic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT ↦ italic_c , italic_e, then cdXesubscriptsubgroup-of𝑋𝑐𝑑superscript𝑒c\boxplus d\lhd_{X}e^{\prime}italic_c ⊞ italic_d ⊲ start_POSTSUBSCRIPT italic_X end_POSTSUBSCRIPT italic_e start_POSTSUPERSCRIPT ′ end_POSTSUPERSCRIPT.

Proof F.2.

By induction on X𝑋Xitalic_X, using the laws of the cost algebraProposition 6.1.

F.1 Admissibility

Proposition F.3.

We have that 𝖴𝖥Ae-\lhd_{\mathsf{U}\mathsf{F}A}e- ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT italic_e is an admissible subset of 𝖳(A)𝖳𝐴\mathsf{T}(A)sansserif_T ( italic_A ).

Proof F.4.

First, we have to show that 𝖴𝖥Ae\bot\lhd_{\mathsf{U}\mathsf{F}A}e⊥ ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT italic_e. By definition, this means to show f()𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;g)square-image-of-or-equalssuperscript𝑓bottom𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝑔f^{\sharp}(\bot)\sqsubseteq\mathsf{profile}(e;g)italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( ⊥ ) ⊑ sansserif_profile ( italic_e ; italic_g ) for all f(A𝖺𝖽𝗊)g𝐴𝖺𝖽𝗊𝑓𝑔f\mathrel{(A\Rightarrow\mathsf{adq})}gitalic_f start_RELOP ( italic_A ⇒ sansserif_adq ) end_RELOP italic_g. But this holds since f()=superscript𝑓bottombottomf^{\sharp}(\bot)=\botitalic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( ⊥ ) = ⊥ and bottom\bot is the least element of 𝖳(A)𝖳𝐴\mathsf{T}(A)sansserif_T ( italic_A ). Otherwise, let d𝑑ditalic_d be a synthetic ω𝜔\omegaitalic_ω-chain such that di𝖴𝖥Aesubscriptsubgroup-of𝖴𝖥𝐴subscript𝑑𝑖𝑒d_{i}\lhd_{\mathsf{U}\mathsf{F}A}eitalic_d start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT italic_e for all i:ω:𝑖𝜔i:\omegaitalic_i : italic_ω. We want to show that d𝖴𝖥Aesubscriptsubgroup-of𝖴𝖥𝐴𝑑𝑒\bigvee d\lhd_{\mathsf{U}\mathsf{F}A}e⋁ italic_d ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT italic_e, which is to show that f(d)𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;g)square-image-of-or-equalssuperscript𝑓𝑑𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝑔f^{\sharp}(\bigvee d)\sqsubseteq\mathsf{profile}(e;g)italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( ⋁ italic_d ) ⊑ sansserif_profile ( italic_e ; italic_g ) for all f(A𝖺𝖽𝗊)g𝐴𝖺𝖽𝗊𝑓𝑔f\mathrel{(A\Rightarrow\mathsf{adq})}gitalic_f start_RELOP ( italic_A ⇒ sansserif_adq ) end_RELOP italic_g. Since f(d)=(fd)superscript𝑓𝑑superscript𝑓𝑑f^{\sharp}(\bigvee d)=\bigvee(f^{\sharp}\circ d)italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( ⋁ italic_d ) = ⋁ ( italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ∘ italic_d ), this means to show (fd)𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;g)square-image-of-or-equalssuperscript𝑓𝑑𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝑔\bigvee(f^{\sharp}\circ d)\sqsubseteq\mathsf{profile}(e;g)⋁ ( italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ∘ italic_d ) ⊑ sansserif_profile ( italic_e ; italic_g ). By the universal property of the synthetic ω𝜔\omegaitalic_ω-supremum, it suffices to show f(di)𝗉𝗋𝗈𝖿𝗂𝗅𝖾(e;g)square-image-of-or-equalssuperscript𝑓subscript𝑑𝑖𝗉𝗋𝗈𝖿𝗂𝗅𝖾𝑒𝑔f^{\sharp}(d_{i})\sqsubseteq\mathsf{profile}(e;g)italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_d start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ) ⊑ sansserif_profile ( italic_e ; italic_g ) for all i:ω:𝑖𝜔i:\omegaitalic_i : italic_ω, but this is the assumption.

Proposition F.5.

Suprema of synthetic ω𝜔\omegaitalic_ω-chains in function spaces are computed pointwise.

Proposition F.6.

Given that 𝖴Xe-\lhd_{\mathsf{U}X}e- ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT italic_e is admissible for all e:𝖴X:𝑒𝖴𝑋e:\mathsf{U}Xitalic_e : sansserif_U italic_X, we have that 𝖴(AX)e-\lhd_{\mathsf{U}(A\to X)}e- ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → italic_X ) end_POSTSUBSCRIPT italic_e is as well.

Proof F.7.

Because (a)=bottom𝑎bottom\bot(a)=\bot⊥ ( italic_a ) = ⊥, we have that 𝖴(AX)e\bot\lhd_{\mathsf{U}(A\to X)}e⊥ ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → italic_X ) end_POSTSUBSCRIPT italic_e. Suppose that fi𝖴(AX)esubscriptsubgroup-of𝖴𝐴𝑋subscript𝑓𝑖𝑒f_{i}\lhd_{\mathsf{U}(A\to X)}eitalic_f start_POSTSUBSCRIPT italic_i end_POSTSUBSCRIPT ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → italic_X ) end_POSTSUBSCRIPT italic_e. We need to show that f𝖴(AX)esubscriptsubgroup-of𝖴𝐴𝑋𝑓𝑒\bigvee f\lhd_{\mathsf{U}(A\to X)}e⋁ italic_f ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → italic_X ) end_POSTSUBSCRIPT italic_e. Suppose that aAbsubscriptsubgroup-of𝐴𝑎𝑏a\lhd_{A}bitalic_a ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_b. We need to show that (f)a𝖴Xebsubscriptsubgroup-of𝖴𝑋𝑓𝑎𝑒𝑏(\bigvee f)~{}a\lhd_{\mathsf{U}X}e~{}b( ⋁ italic_f ) italic_a ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT italic_e italic_b. This follows from the characterization of synthetic ω𝜔\omegaitalic_ω-suprema in function spaces (Proposition F.5) and the assumption that 𝖴Xe-\lhd_{\mathsf{U}X}e- ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT italic_e.

Proposition F.8.

Given e:𝖴X:𝑒𝖴𝑋e:\mathsf{U}Xitalic_e : sansserif_U italic_X, we have that 𝖴Xe-\lhd_{\mathsf{U}X}e- ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT italic_e is an admissible subset of 𝖴Xdelimited-⟦⟧𝖴𝑋\llbracket\mathsf{U}X\rrbracket⟦ sansserif_U italic_X ⟧.

Proof F.9.

F.2 Fundamental lemma

We give the representative cases of the proof by induction on the derivation of terms.

Lemma F.10.

If aAvsubscriptsubgroup-of𝐴𝑎𝑣a\lhd_{A}vitalic_a ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_v, then η𝖳(a)𝖴𝖥A𝗋𝖾𝗍(v)subscriptsubgroup-of𝖴𝖥𝐴subscript𝜂𝖳𝑎𝗋𝖾𝗍𝑣\eta_{\mathsf{T}}(a)\lhd_{\mathsf{U}\mathsf{F}A}\mathsf{ret}(v)italic_η start_POSTSUBSCRIPT sansserif_T end_POSTSUBSCRIPT ( italic_a ) ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT sansserif_ret ( italic_v ).

Proof F.11.

Let f(A𝖺𝖽𝗊)gf\mathrel{(\lhd_{A}\Rightarrow{\mathsf{adq}})}gitalic_f start_RELOP ( ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT ⇒ sansserif_adq ) end_RELOP italic_g. We need to show that (f(η𝖳(a)))𝖺𝖽𝗊(𝗋𝖾𝗍(v);g)𝖺𝖽𝗊superscript𝑓subscript𝜂𝖳𝑎𝗋𝖾𝗍𝑣𝑔(f^{\sharp}(\eta_{\mathsf{T}}(a)))\mathrel{\mathsf{adq}}(\mathsf{ret}(v);g)( italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_η start_POSTSUBSCRIPT sansserif_T end_POSTSUBSCRIPT ( italic_a ) ) ) sansserif_adq ( sansserif_ret ( italic_v ) ; italic_g ). Computing the denotational semantics and applying Proposition F.1, it suffices to show that (fa)𝖺𝖽𝗊(gv)𝖺𝖽𝗊𝑓𝑎𝑔𝑣(f~{}a)\mathrel{\mathsf{adq}}(g~{}v)( italic_f italic_a ) sansserif_adq ( italic_g italic_v ), which follows from our assumption.

Lemma F.12.

If d𝖴𝖥Aesubscriptsubgroup-of𝖴𝖥𝐴𝑑𝑒d\lhd_{\mathsf{U}\mathsf{F}A}eitalic_d ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT italic_e and f𝖴(AX)gsubscriptsubgroup-of𝖴𝐴𝑋𝑓𝑔f\lhd_{\mathsf{U}(A\to X)}gitalic_f ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → italic_X ) end_POSTSUBSCRIPT italic_g, then f(d)𝖴Xe;gsubscriptsubgroup-of𝖴𝑋superscript𝑓𝑑𝑒𝑔f^{\sharp}(d)\lhd_{\mathsf{U}X}e;gitalic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_d ) ⊲ start_POSTSUBSCRIPT sansserif_U italic_X end_POSTSUBSCRIPT italic_e ; italic_g.

Proof F.13.

By induction on X𝑋Xitalic_X.

  1. \normalshape(1)

    If X=𝖥B𝑋𝖥𝐵X=\mathsf{F}Bitalic_X = sansserif_F italic_B, let h(B𝖺𝖽𝗊)ih\mathrel{(\lhd_{B}\Rightarrow\mathsf{adq})}iitalic_h start_RELOP ( ⊲ start_POSTSUBSCRIPT italic_B end_POSTSUBSCRIPT ⇒ sansserif_adq ) end_RELOP italic_i. We need to show that h(f(d))𝖺𝖽𝗊(e;g);i𝖺𝖽𝗊superscriptsuperscript𝑓𝑑𝑒𝑔𝑖h^{\sharp}(f^{\sharp}(d))\mathrel{\mathsf{adq}}(e;g);iitalic_h start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_d ) ) sansserif_adq ( italic_e ; italic_g ) ; italic_i. Computing the denotational semantics and using the fact that we may reassociate sequences (Proposition 7.5), it suffices to show ((hf)(d))𝖺𝖽𝗊(e;(λv.gv;i))((h^{\sharp}\circ f)^{\sharp}(d))\mathrel{\mathsf{adq}}(e;(\lambda v.~{}g~{}v;% i))( ( italic_h start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ∘ italic_f ) start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_d ) ) sansserif_adq ( italic_e ; ( italic_λ italic_v . italic_g italic_v ; italic_i ) ). By the assumption that d𝖴𝖥Aesubscriptsubgroup-of𝖴𝖥𝐴𝑑𝑒d\lhd_{\mathsf{U}\mathsf{F}A}eitalic_d ⊲ start_POSTSUBSCRIPT sansserif_UF italic_A end_POSTSUBSCRIPT italic_e, it suffices to show that for all aAvsubscriptsubgroup-of𝐴𝑎𝑣a\lhd_{A}vitalic_a ⊲ start_POSTSUBSCRIPT italic_A end_POSTSUBSCRIPT italic_v, we have that (h(fa))𝖺𝖽𝗊(gv;i)𝖺𝖽𝗊superscript𝑓𝑎𝑔𝑣𝑖(h^{\sharp}(f~{}a))\mathrel{\mathsf{adq}}(g~{}v;i)( italic_h start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_f italic_a ) ) sansserif_adq ( italic_g italic_v ; italic_i ), which follows directly from the assumptions that f𝖴(AX)gsubscriptsubgroup-of𝖴𝐴𝑋𝑓𝑔f\lhd_{\mathsf{U}(A\to X)}gitalic_f ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → italic_X ) end_POSTSUBSCRIPT italic_g and h(B𝖺𝖽𝗊)ih\mathrel{(\lhd_{B}\Rightarrow\mathsf{adq})}iitalic_h start_RELOP ( ⊲ start_POSTSUBSCRIPT italic_B end_POSTSUBSCRIPT ⇒ sansserif_adq ) end_RELOP italic_i.

  2. \normalshape(2)

    If X=BY𝑋𝐵𝑌X=B\to Yitalic_X = italic_B → italic_Y, suppose that bBvsubscriptsubgroup-of𝐵𝑏𝑣b\lhd_{B}vitalic_b ⊲ start_POSTSUBSCRIPT italic_B end_POSTSUBSCRIPT italic_v. We need to show that (f(d))b𝖴Y(e;g)vsubscriptsubgroup-of𝖴𝑌superscript𝑓𝑑𝑏𝑒𝑔𝑣(f^{\sharp}(d))~{}b\lhd_{\mathsf{U}Y}(e;g)~{}v( italic_f start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT ( italic_d ) ) italic_b ⊲ start_POSTSUBSCRIPT sansserif_U italic_Y end_POSTSUBSCRIPT ( italic_e ; italic_g ) italic_v. Unraveling the denotational semantics and the computational semantics (using Proposition D.6), it suffices to show (λd.fdb)d𝖴Y(e;λd.gdv)(\lambda d.~{}f~{}d~{}b)^{\sharp}~{}d\lhd_{\mathsf{U}Y}(e;\lambda d.~{}g~{}d~{% }v)( italic_λ italic_d . italic_f italic_d italic_b ) start_POSTSUPERSCRIPT ♯ end_POSTSUPERSCRIPT italic_d ⊲ start_POSTSUBSCRIPT sansserif_U italic_Y end_POSTSUBSCRIPT ( italic_e ; italic_λ italic_d . italic_g italic_d italic_v ), which follows from the inductive hypothesis and the assumption that f𝖴(A(BY))gsubscriptsubgroup-of𝖴𝐴𝐵𝑌𝑓𝑔f\lhd_{\mathsf{U}(A\to(B\to Y))}gitalic_f ⊲ start_POSTSUBSCRIPT sansserif_U ( italic_A → ( italic_B → italic_Y ) ) end_POSTSUBSCRIPT italic_g.

Lemma F.14.

If dXesubscriptsubgroup-of𝑋𝑑𝑒d\lhd_{X}eitalic_d ⊲ start_POSTSUBSCRIPT italic_X end_POSTSUBSCRIPT italic_e, then cdX𝗌𝗍𝖾𝗉c(e)subscriptsubgroup-of𝑋𝑐𝑑superscript𝗌𝗍𝖾𝗉𝑐𝑒c\boxplus d\lhd_{X}\mathsf{step}^{c}(e)italic_c ⊞ italic_d ⊲ start_POSTSUBSCRIPT italic_X end_POSTSUBSCRIPT sansserif_step start_POSTSUPERSCRIPT italic_c end_POSTSUPERSCRIPT ( italic_e ).

Proof F.15.

Since 𝗌𝗍𝖾𝗉c(e)c,emaps-tosuperscript𝗌𝗍𝖾𝗉𝑐𝑒𝑐𝑒\mathsf{step}^{c}(e)\mapsto c,esansserif_step start_POSTSUPERSCRIPT italic_c end_POSTSUPERSCRIPT ( italic_e ) ↦ italic_c , italic_e, the result holds by Proposition F.1.

See 8.4

Proof F.16.

By Lemmas F.10, F.12, F.14 and F.8.

See 8.6

Proof F.17.

Let c::𝑐c:\mathbb{C}italic_c : blackboard_C and d::𝑑d:\mathbb{C}italic_d : blackboard_C be the costs denoted by 𝖾𝗏𝖺𝗅(ex,𝗋𝖾𝗍(v))𝖾𝗏𝖺𝗅𝑒𝑥𝗋𝖾𝗍𝑣\mathsf{eval}(e~{}x,\mathsf{ret}(v))sansserif_eval ( italic_e italic_x , sansserif_ret ( italic_v ) ) and 𝖾𝗏𝖺𝗅(ey,𝗋𝖾𝗍(u))𝖾𝗏𝖺𝗅𝑒𝑦𝗋𝖾𝗍𝑢\mathsf{eval}(e~{}y,\mathsf{ret}(u))sansserif_eval ( italic_e italic_y , sansserif_ret ( italic_u ) ). By soundness Theorem 8.2 and laws of the derived algebra Proposition 6.1, we have that ex=cη𝕋(v)=η𝕃(c,v)\llbracket e~{}x\rrbracket=c\boxplus\eta_{\mathbb{T}}(\llbracket v\rrbracket)=% \eta_{\mathbb{L}}(c,\llbracket v\rrbracket)⟦ italic_e italic_x ⟧ = italic_c ⊞ italic_η start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT ( ⟦ italic_v ⟧ ) = italic_η start_POSTSUBSCRIPT blackboard_L end_POSTSUBSCRIPT ( italic_c , ⟦ italic_v ⟧ ) and similarly ey=η𝕋(u)=η𝕃(d,u)\llbracket e~{}y\rrbracket=\boxplus\eta_{\mathbb{T}}(\llbracket u\rrbracket)=% \eta_{\mathbb{L}}(d,\llbracket u\rrbracket)⟦ italic_e italic_y ⟧ = ⊞ italic_η start_POSTSUBSCRIPT blackboard_T end_POSTSUBSCRIPT ( ⟦ italic_u ⟧ ) = italic_η start_POSTSUBSCRIPT blackboard_L end_POSTSUBSCRIPT ( italic_d , ⟦ italic_u ⟧ ). It suffices to show that v=2u\llbracket v\rrbracket=_{2}\llbracket u\rrbracket⟦ italic_v ⟧ = start_POSTSUBSCRIPT 2 end_POSTSUBSCRIPT ⟦ italic_u ⟧. Because 2 is a purely extensional type (as required by Definition 3.16), we may assume that \P holds. By assumption and soundness, we have x=y\llbracket x\rrbracket=\llbracket y\rrbracket⟦ italic_x ⟧ = ⟦ italic_y ⟧, and so ex=η𝕃(c,v)=η𝕃(d,u)=ey\llbracket e~{}x\rrbracket=\eta_{\mathbb{L}}(c,\llbracket v\rrbracket)=\eta_{% \mathbb{L}}(d,\llbracket u\rrbracket)=\llbracket e~{}y\rrbracket⟦ italic_e italic_x ⟧ = italic_η start_POSTSUBSCRIPT blackboard_L end_POSTSUBSCRIPT ( italic_c , ⟦ italic_v ⟧ ) = italic_η start_POSTSUBSCRIPT blackboard_L end_POSTSUBSCRIPT ( italic_d , ⟦ italic_u ⟧ ) = ⟦ italic_e italic_y ⟧, which means that v=u\llbracket v\rrbracket=\llbracket u\rrbracket⟦ italic_v ⟧ = ⟦ italic_u ⟧ since c=d𝑐𝑑c=ditalic_c = italic_d as elements of a purely intensional type \mathbb{C}blackboard_C.