# The Scott model of PCF in univalent type theory

We develop the Scott model of the programming language PCF in constructive predicative univalent type theory. To account for the non-termination in PCF, we work with the partial map classifier monad (also known as the lifting monad) from topos theory, which has been extended to constructive type theory by Knapp and Escardó. Our results show that lifting is a viable approach to partiality in univalent type theory. Moreover, we show that the Scott model can be constructed in a predicative and constructive setting. Other approaches to partiality either require some form of choice or higher inductive-inductive types. We show that one can do without these extensions.

## Authors

• 5 publications
• ### On Higher Inductive Types in Cubical Type Theory

Cubical type theory provides a constructive justification to certain asp...
02/04/2018 ∙ by Thierry Coquand, et al. ∙ 0

• ### Introduction to Univalent Foundations of Mathematics with Agda

We introduce Voevodsky's univalent foundations and univalent mathematics...
11/01/2019 ∙ by Martín Hötzel Escardó, et al. ∙ 0

• ### Homotopy canonicity for cubical type theory

Cubical type theory provides a constructive justification of homotopy ty...
02/18/2019 ∙ by Thierry Coquand, et al. ∙ 0

• ### A Constructive, Type-Theoretic Approach to Regression via Global Optimisation

We examine the connections between deterministic, complete, and general ...
06/23/2020 ∙ by Dan R. Ghica, et al. ∙ 0

• ### Computing with Continuous Objects: A Uniform Co-inductive Approach

A uniform approach to computing with infinite objects like real numbers,...
04/11/2020 ∙ by Dieter Spreen, et al. ∙ 0

• ### Partial Univalence in n-truncated Type Theory

It is well known that univalence is incompatible with uniqueness of iden...
05/01/2020 ∙ by Christian Sattler, et al. ∙ 0

• ### Free Commutative Monoids in Homotopy Type Theory

We develop a constructive theory of finite multisets, defining them as f...
10/11/2021 ∙ by Vikraman Choudhury, et al. ∙ 0

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 0.1 Introduction

We develop the Scott model of the programming language PCF [Str06] in constructive predicative univalent mathematics. Our development differs from the classical approach in three key ways. First of all, our work is constructive. Secondly, we work predicatively and do not assume propositional resizing. This has led us to consider directed families, rather than subsets. Thirdly, we situate our development in the framework of univalent mathematics.

The programming language PCF has general recursion and hence non-termination, and this is what makes a constructive type theoretic treatment challenging. In classical mathematics, the construction of adding a (least) element to a set is used to deal with partiality. Moreover, this construction yields a domain. Constructively, this is no longer true, so to account for partiality, we instead work with the partial map classifier monad (also known as the lifting monad) from topos theory [Koc91], which has been extended to univalent type theory by Cory Knapp and Martín Escardó [Kna18, EK17].

The lifting of a type is defined as , where is a type universe of propositions (subsingletons). Note that we can embed into by . If is a set, then is a dcpo with a least element [Kna18]. This least element is given by .

PCF has a type for natural numbers and a function type for every two PCF types and . Every natural number is represented as the numeral of type . Moreover, PCF has a fixed point operator. To model this, we work with directed complete posets (dcpos) with a least element. We write for the interpretation of a type , and for the interpretation of a term . In our model, . The function type is interpreted as the dcpo of continuous maps from to . For a term and a term , the application is a term, and is interpreted as function application .

The operational semantics of PCF induce a binary reduction relation on terms, where intuitively means that “t computes to s”. We show our Scott model to work well with the operational semantics through soundness and computational adequacy. Soundness means that if , then . Computational adequacy states that for any PCF term of type and natural number , if , then . An interesting use of computational adequacy is that it allows one to argue semantically to obtain results about termination (i.e. reduction to a numeral) in PCF, see Section 0.7.1.

Recall that PCF terms of type are interpreted as elements of the lifting of the natural numbers. Hence, the first projection yields a proposition for every such term. Soundness and computational adequacy allow us to characterise these propositions as those of the form , where is a PCF term of type . Intuitively, these propositions are semidecidable, i.e. of the form where is a decidable predicate on . In proving this, we are led to study indexed -types, a particular class of inductive types, and when they have decidable equality. Moreover, we provide some conditions on a relation for its -step reflexive transitive closure to be decidable.

### 0.1.1 Related work

Partiality in type theory has been the subject of recent study. We briefly discuss the different approaches. First, there are Capretta’s delay monad and its quotient by weak bisimilarity, which have been studied by Uustula, Chapman and Veltri [CUV17]. A drawback of the quotient is that some form of choice is needed (countable choice suffices) to show that it is again a monad. Another approach is laid out in [ADK17] by Altenkirch, Danielsson and Kraus. They construct (essentially by definition) the free -cpo with a least element using a higher inductive-inductive type. Moreover, Altenkirch et al. show that, assuming countable choice, their free -cpo coincides with the quotiented delay monad. In [Kna18], Knapp showed that, assuming countable choice, a restricted version (using a dominance) of the lifting is isomorphic to the quotiented delay monad.

One way in which the lifting distinguishes itself from the other approaches is that the lifting of a set can be seen as the free subsingleton complete poset with a least element, rather than the free -cpo with a least element. We stress that our approach does not need countable choice or higher inductive-inductive types.

Capretta’s delay monad has been used to give a constructive approach to domain theory [BKV09]. However, the objects have the “wrong equality”, so that every object comes with an equivalence relation that maps must preserve. The framework of univalent mathematics in which we have placed our development provides a more natural approach. Moreover, we do not make use of Coq’s impredicative Prop universe and our treatment incorporates directed complete posets (dcpos) and not just -cpos.

### 0.1.2 Overview

The first section introduces basic domain theory in the framework of univalent type theory. We develop the material right up to the least fixed point operator, as this will suffice for our purposes.

We proceed by discussing the constructive issues with the classical approach to partiality and flat dcpos. In Section 4 we introduce the lifting monad as a solution to partiality in constructive type theory. We show that it is a monad and prove that the lifting may be seen as a free construction.

Section 5 lays out PCF and its operational semantics, while Section 6 discusses the constructive Scott model of PCF. In Section 7 we prove that the operational and denotational semantics work well together in the form of soundness and computational adequacy.

Section 8 aims to characterise propositions that arise from PCF terms of the base type as semidecidable propositions. To do so, we study the reflexive transitive closure of a relation and indexed -types in general.

Finally, the appendix will discuss universe level issues surrounding the lifting and directed completeness.

### 0.1.3 Framework, notation and formalisation

We work in intensional Martin-Löf Type Theory with inductive types (including the empty , unit , natural numbers and identity types), - and -types, functional and propositional extensionality and propositional truncation. We work predicatively, so we do not assume propositional resizing. Although we do not need full univalence at any point, we emphasise the importance of the idea of hlevels, which is fundamental to univalent type theory.

We write for the type of propositions (or subsingletons) and for the propositional truncation of a type . Given two functions , we write for the type .

All our results up to Section 0.7.1 (and except for Section 0.3) have been formalised in the proof assistant Coq using the UniMath library [VAG] and Coq’s Inductive types. The general results from Section 8 have also been formalised, but their direct applications to PCF, e.g. single-valuedness of the operational semantics and PCF as an indexed -type, have not. The code may be found at https://github.com/tomdjong/UniMath/tree/paper.

At present, it is not possible to verify universe levels in UniMath. Therefore, to verify the correctness of our development and our claims in the Appendix about universe levels in particular, we reformalised our model in Agda using Martín Escardó’s TypeTopology library [E]. Our code is now part of the library. An HTML rendering may be found at: https://www.cs.bham.ac.uk/~mhe/agda-new/ScottModelOfPCF.html.

### 0.1.4 Acknowledgements

I would like to thank Martín Escardó for suggesting and supervising this project. I have also benefited from Benedikt Ahrens’s support and his help with UniMath.

## 0.2 Basic domain theory

We introduce basic domain theory in the setting of constructive univalent mathematics. All definitions and theorems are straightforward adaptions of the usual ones in [AJ94, Section 2.1] and [Str06, Chapter 4].

### 0.2.1 Directed complete posets

###### Definition 0.2.1.

A poset is a set together with a proposition valued binary relation satisfying:

1. reflexivity: ;

2. antisymmetry: ;

3. transitivity: .

###### Definition 0.2.2.

Let and be posets. A poset morphism from to is a function between the underlying sets that preserves the order. One also says that the function is monotone.

###### Definition 0.2.3.

Let be a poset and any type. Given a family , we write for . Such a family is called directed if it is inhabited (i.e. ) and .

Observe that being directed is property, rather than structure.

###### Definition 0.2.4.

Let be a type universe. A poset is called -directed complete if every directed family in indexed by a type in has a least upper bound in . We call such a poset a -dcpo.

We shall often simply write dcpo, omitting reference to the type universe. A discussion on size/universe issues can be found in the appendix.

Finally, we denote the least upper bound of a directed family by .

### 0.2.2 Morphisms of dcpos

###### Definition 0.2.5.

Let and be dcpos. A poset morphism from to is a dcpo morphism or continuous if it preserves least upper bounds of directed families.

In fact, requiring that the function is monotone is redundant.

###### Lemma 0.2.6.

Let and be dcpos. If is a function (on the underlying sets) from to preserving least upper bounds of directed families, then is order preserving.

###### Proof.

Let be a morphism of dcpos and suppose with . Consider the family defined as and . This family is easily seen to be directed and its least upper bound is . Now preserves this least upper bound, so . ∎

###### Corollary 0.2.7.

Every morphism of dcpos preserves directed families. That is, if is a morphism of dcpos and is a directed family in , then is a directed family in .

###### Theorem 0.2.8.

Let and be dcpos. The morphisms from to form a dcpo with the pointwise order.

###### Proof.

The least upper bound of a directed family of dcpo morphisms is also given pointwise. The proof only differs from the standard proof of [Str06, Theorem 4.2] in that it uses directed families, rather than subsets. One may consult the formalisation for the technical details. ∎

### 0.2.3 Dcpos with bottom

###### Definition 0.2.9.

A dcpo with bottom is a dcpo together with a least element in .

###### Theorem 0.2.10.

Let be a dcpo and let be a dcpo with bottom. Ordered pointwise, the morphisms from to form a dcpo with bottom.

###### Proof.

Since the order is pointwise, the least morphism from to is simply given by mapping every element in to the least element in . The rest is as in Theorem 0.2.8. ∎

###### Definition 0.2.11.

Let and be dcpos with bottom. We will write for the dcpo with bottom that has the dcpo morphisms from to as its underlying set.

Dcpos with bottoms are interesting because of fixed points.

###### Theorem 0.2.12.

Let be a dcpo with bottom. There is a continuous function that sends each continuous function to its least fixed point. In fact, satisfies:

1. for every continuous ;

2. for every continuous and each , if , then .

###### Proof.

We have formalised the proof of [AJ94, Theorem 2.1.19]. We sketch the main construction here. For each natural number , define as

 iter(n)(f)≡fn(⊥)≡f(f(…(fn % times(⊥))…)).

By induction on , one may show that every is continuous. Then, the assignment is a directed family in . Finally, one defines as the least upper bound of this directed family. Recall that least upper bounds in the exponential are given pointwise, so that . ∎

## 0.3 Constructive issues with partiality

In classical mathematics, a partial map from to can simply be seen as total map from to , where is some fresh element not in . The flat dcpo is ordered as in the following Hasse diagram:

Classically, it is easy to show that is a directed complete poset (viz. every finite subset of has a least upper bound in ).

One could hope that the above translates directly into constructive univalent mathematics, that is, that is directed complete (in the sense of Definition 0.2.4). However, we can prove that this implies the Weak Limited Principle of Omniscience (WLPO), a constructive taboo, as follows.

In type theory, WLPO can be formulated as the following type:

 ∏α:N→2(∏n:Nα(n)=0)+(¬∏n:Nα(n)=0). (WLPO)

Define the type of increasing sequences binary sequences by:

###### Lemma 0.3.1.

WLPO is equivalent to a restricted version of WLPO where just runs over increasing sequences, viz. the type:

 ∏α:N∞(∏n:Nα(n)=0)+(¬∏n:Nα(n)=0).
###### Proof.

Since both types are propositions, proving the bi-implication suffices. Of course, one implication is trivial, because there is an obvious embedding of into .

For the converse, suppose we have a term of . Let be any binary sequence. Define by:

 ~α(n)≡{0if ∏k≤nα(k)=0;1else.

Observe that is decidable for every , so this definition is constructively sound. Finally, it is easily seen that is equivalent to , so is a proof of WLPO. ∎

###### Lemma 0.3.2.

Directed completeness of implies WLPO.

###### Proof.

Suppose that is directed complete. We employ the previous lemma. Given , define a sequence by:

 un≡{inl(n)if α(n)=1;inr(⋆)else.

Since is increasing, the family is directed. Thus, has a least upper bound in . By definition of , it follows that if and only if . But is decidable, so we get . ∎

## 0.4 Dealing with partiality constructively

In his PhD thesis [Kna18], Cory Knapp studied partial functions and recursion in univalent type theory. Most of the results in this section can be found in [Kna18] or in the paper [EK17] by Knapp and his supervisor Martín Escardó. Exceptions are Lemma 0.4.3, Theorem 0.4.5 and Theorem 0.4.7. The former, however, is implicit in the antisymmetry of the order on the lifting. The order on the lifting in this paper (see Theorem 0.4.6) is different from the order presented in [EK17] and [Kna18]. The two orders are equivalent however and this was first observed by Martín Escardó.

###### Definition 0.4.1.

Let be any type. Define the lifting of X as

 LX≡∑P:Ω(P→X).

We now define meaningful projections.

###### Definition 0.4.2.

The function is defined as the first projection. The function is defined as: .

Since equality of -types often requires , it will be convenient to characterise the equality of .

###### Lemma 0.4.3.

Let be any type and let . Then and

 ∑e:isdefined(l)↔isdefined(m)value(l)∘pr2(e)∼value(m)

are logically equivalent.111In fact, there is a type equivalence. One can prove this using univalence and a generalised structure identity principle, c.f. http://www.cs.bham.ac.uk/~mhe/agda-new/LiftingIdentityViaSIP.html

###### Proof.

Suppose we have a path . By the characterisation of the identity type of -types, we obtain and . Obviously, yields a term . Using path induction on , we can prove that . Together with , this equality implies , as desired.

Conversely, suppose and . By the characterisation of the identity type of -types:

 l=m≃∑e′:isdefined(l)=isdefined(m)transport(e′,value(l))=value(m).

By propositional extensionality, we obtain from . From we get an equivalence , as both types are propositions. Furthermore, using path induction on , one can prove that

 transport(e′,value(l))=value(l)∘(idtoeqv(e′))−1.

Using function extensionality and our homotopy we have

 value(m)=value(l)∘pr2(e)

and we are to prove that

 value(m)=transport(e′,value(l)).

Thus, by is suffices to establish that

 (idtoeqv(e′))−1=pr2(e).

But the domain and codomain of these maps are propositions, so this follows immediately from function extensionality. ∎

The lifting carries a monad structure that is most easily described as a Kleisli triple. The unit is given by , where denotes the function . Given , the Kleisli extension is defined by:

 f#(P,φ) ≡(∑p:Pisdefined(f(φ(p))),ψ), where ψ(p,d) ≡value(f(φ(p)))(d).
###### Theorem 0.4.4.

The above constructions yield a monad structure on , i.e. the Kleisli laws hold (pointwise):

1. ;

2. for any ;

3. for any and .

###### Proof.

Using Lemma 0.4.3 the proofs become easy. Item (iii) is essentially the equivalence between and . ∎

### 0.4.2 The lifting as a dcpo with bottom

###### Theorem 0.4.5.

If is a set, then so is its lifting .

###### Proof.

As in the proof of Lemma 0.4.3, we have:

 l=m≃∑e:isdefined(l)=isdefined(m)transport(e,value(l))=value(m).

Since is a set, the type is a proposition. So, if we can prove that is a proposition, then the right hand side is a proposition indexed sum of propositions, which is again a proposition.

So let us prove that if and are propositions, then so is . At first glance, it might seem like one needs univalence (for propositions) to prove this, but in fact propositional extensionality suffices. By [KECA17, Lemma 3.11], it suffices to give a weakly constant (i.e. any two of its values are equal) endomap on (one may safely replace the type in [KECA17, Lemma 3.11] with , c.f. our formalisation). But the composition

 (P=Q)→(P↔Q)PropExt−−−−→(P=Q)

is weakly constant, because is a proposition, so this finishes the proof. ∎

###### Theorem 0.4.6.

If is a set, then is a dcpo with bottom with the following order:

 l⊑m≡isdefined(l)→l=m.
###### Proof.

First of all, we should prove that is a poset with the specified order. In particular, should be proposition valued. If is a set, then is a function type into a proposition and therefore a proposition itself.

Reflexivity and transitivity of are easily verified. Moreover, is seen to be antisymmetric using Lemma 0.4.3.

The bottom element of is given by , where is the unique function from .

The construction of the least upper bound of a directed family is the most challenging part of the proof. If is a directed family in , then its least upper bound is

 (∥∥ ∥∥∑i:Iisdefined(ui)∥∥ ∥∥,φ):LX,

where is the factorisation of the function

 ψ:∑i:Iisdefined(ui)→X,(i,d)↦value(ui)d

through . This factorisation exists by [KECA17, Theorem 5.4], as is a set and is weakly constant (viz. any two of its values are equal), which we prove now.

Suppose and are terms of type . We want to prove that . Since is a set, this is a proposition, so we may use directedness of to obtain with . From and , we now get satisfying:

 ψ(i0,d0)=ψ(k,d)andψ(i1,d1)=ψ(k,d′)

but since is a proposition, so , as desired. ∎

###### Theorem 0.4.7.

Let and be sets and any function. The Kleisli extension is a morphism of dcpos.

###### Proof.

Let be the upper bound of a directed family in . Proving that is monotone is quite easy. By monotonicity, is an upper bound for the family . We are left to prove that it is the least. Suppose that is another upper bound for the family , i.e.  for every . We must show that . To this end, assume we have . We must prove that .

From , we obtain by definition of . By our construction of suprema in and the fact that is a proposition, we may in fact assume that we have an element and . But , so using we get the equality . Since is an upper bound for , the term also yields . In particular, , as desired. ∎

###### Remark 0.4.8.

Finally, one could define the functor from the Kleisli extension and unit by putting for any . However, it is equivalent and easier to directly define by postcomposition: .

### 0.4.3 The lifting as a free construction

###### Definition 0.4.9.

Let us call a poset subsingleton complete if it has least upper bounds of proposition (subsingleton) indexed families.

###### Definition 0.4.10.

Let - be the category with as objects subsingleton complete posets with a least element and maps that preserve proposition indexed suprema as morphisms.

###### Theorem 0.4.11.

If is a set, then is a subsingleton complete poset with a least element.

###### Proof.

We have already seen that is a poset with a least element. Let be a proposition indexed family. It is straightforward to verify that the least upper bound of is given by

 (∑p:Pisdefined(up),(p,d)↦value(up)(d)):L(X).\qed
###### Theorem 0.4.12.

The lifting functor is left adjoint to the forgetful functor .

###### Proof.

Let be a set and a subsingleton complete poset with a least element. Suppose is a map of sets. We must construct a unique morphism in such that .

We do so by defining as

 (P,φ)↦⨆p:Pf(φ(p)).

Note that this is well-defined, because is assumed to be subsingleton complete. It is not hard to show that preserves proposition indexed suprema. Hence, it remains to prove that is the unique such morphism. To this end, suppose is a morphism in with . We must show that for every . Suppose that we have . Note that

 (P,φ)=⨆p:PηX(φ(p)),

so that we have the following chain of equalities

 g(P,φ) =g(⨆p:PηX(φ(p))) =⨆p:Pg(ηX(φ(p))) (as g preserves proposition indexed suprema) =⨆p:Pf(φ(p)) (by assumption on g) ≡˜f(P,φ),

as desired. ∎

## 0.5 PCF and its operational semantics

To avoid dealing with (free and bound) variables, we opt to work in the combinatory version of PCF. It is inductively defined as follows.

###### Definition 0.5.1.

The PCF types are inductively defined as:

1. is a type, the base type;

2. for every two types and , there is a function type .

As usual, will be right associative, so we write for .

###### Definition 0.5.2.

The PCF terms of PCF type are inductively defined as:

1. there is a PCF term of PCF type ;

2. there is a PCF term of PCF type ;

3. there is a PCF term of PCF type ;

4. there is a PCF term of PCF type ;

5. for any types and , there is a PCF term of PCF type ;

6. for any types and , there is a PCF term of PCF type ;

7. for any type , there is a PCF term of PCF type ;

8. if is a PCF term of PCF type and is a PCF term of PCF type , then is a PCF term of PCF type .

We will often drop the parenthesis in (viii) as well as the PCF type subscripts in (v) – (vii). Finally, we employ the convention that the parenthesis associate to the left, i.e. we write for .

###### Definition 0.5.3.

For any , let us write for the th PCF numeral, defined inductively as:

 0–=zero;n+1––––––=succn––.

To define the smallstep operational semantics of PCF, we first define the following inductive type.

###### Definition 0.5.4.

Define the smallstep pre-relation of type

 ∏σ:PCF typesPCF terms of type σ→PCF % terms of type σ→U

as the inductive type generated by:

It seems rather hard to prove that is a proposition for every suitable PCF terms and . However, conceptually, should be a proposition, as (by inspection of the definition), there is at most one way by which we obtained . Moreover, for technical reasons that will become apparent later, we really want to be propostion-valued.

We solve the problem by defining the smallstep relation as the propositional truncation of , i.e. .222Alternatively, one could use propositional resizing and an impredicative encoding, i.e. by defining as a -type of all suitable relations. This is similar to the situation in set theory, where one would define as an intersection. Thanks to Benedikt Ahrens for pointing this out.

###### Definition 0.5.5.

Let be a relation on a type . We could define the reflexive transitive closure of as an inductive type, generated by three constructors:

 extend :∏x,y:XxRy→xR∗y; refl :∏x:XxR∗x; trans :∏x,y,z:XxR∗y→yR∗z→xR∗z.

But is not necessarily proposition valued. However, one can show that the relation defined as is. Moreover, it is the least reflexive, transitive, proposition valued relation that extends . Therefore, we define to be the reflexive transitive closure of .

Some properties of reflect onto as the following lemma shows.

###### Lemma 0.5.6.

Let and be PCF terms of type . If , then

1. ;

2. ;

3. .

Moreover, if and are PCF terms of type and , then for any PCF term of type .

###### Proof.

We only prove (i), the rest is similar. Suppose . Since is a proposition, we may assume that we actually have a term of type . Now we can perform induction on . The cases were is formed using or are easy. If is formed by , then we get a term of type . Again, as we are proving a proposition, we may suppose the existence of a term of type . By (ix) of Definition 0.5.4, we then get . This in turn yields, and finally we use to get the desired . ∎

## 0.6 The Scott model of PCF using the lifting monad

We have already introduced the operational semantics of PCF. Next, we wish to give another sort of semantics for PCF, the Scott model [Str06]. The idea is to assign some mathematical structure to each PCF type. The PCF terms will then be interpreted as elements of the structure.

Moreover, we want the denotational semantics to be in sync with the operational semantics, as expressed by soundness and computational adequacy in the next section.

###### Definition 0.6.1.

Inductively assign to each PCF type a dcpo with bottom as follows:

1. ;

2. .

Recall that if and are dcpos with bottom, then is the dcpo with bottom of dcpo morphisms from to , with pointwise ordering and pointwise least upper bounds.

Next, we interpret PCF terms as elements of these dcpos with bottom.

###### Definition 0.6.2.

Define for each PCF term of PCF type a term of type , by the following inductive clauses:

1. ;

2. , where is the successor function;

3. , where is the predecessor function;

4. is defined using the Kleisli extension as: , where

 χx,y(n)≡{xif n=0;yelse.
5. ;

6. ;

7. , where is the least fixed point operator from Theorem 0.2.12.

###### Remark 0.6.3.

Of course, there are some things to be proved here. Namely, all need to be dcpo morphisms. In the case of and , we simply appeal to Theorem 0.4.7 and Remark 0.4.8. For , this is Theorem 0.2.12. The continuity of and can be verified directly, as done in the formalisation. It is however, unenlightning and tedious, so we omit the details here.

As a first result about our denotational semantics, we show that the PCF numerals have a canonical interpretation in the denotational semantics.

###### Lemma 0.6.4.

For every natural number , we have .

###### Proof.

We proceed by induction on . The case is by definition of . Suppose for a natural number . Then,

 ⟦m+1–––––––⟧ =⟦succ⟧(⟦m––⟧) =L(s)(η(m)) (by induction hypothesis) =η(m+1) (by definition of the lift functor),

as desired. ∎

## 0.7 Soundness and computational adequacy

###### Theorem 0.7.1 (Soundness).

Let and be any PCF terms of PCF type . If , then .

###### Proof.

By induction on the derivation of , using the Kleisli monad laws. For example, one step is to prove that

 ⟦ifzstn+1––––––⟧=⟦t⟧.

This may be proved by the following chain of equalities:

 ⟦ifzstn+1––––––⟧ =⟦ifzst⟧(⟦n+1––––––⟧) =⟦ifzst⟧(η(n+1)) (by Lemma 0.6.4) =(χ⟦s⟧,⟦t⟧)#(η(n+1)) (by definition of ⟦ifz⟧) =χ⟦s⟧,⟦t⟧(n+1) (by Theorem 0.4.4(ii)) =⟦t⟧.

Ideally, we would like a converse to soundness. However, this is not possible, as for example, , but neither nor holds. We do, however, have the following.

Let be a PCF term of PCF type . Then,

 ∏p:isdefined(⟦t⟧)t▹∗value(⟦t⟧)(p)––––––––––––––.

We will not prove computational adequacy directly, as, unlike soundness, it does not allow for a straightforward proof by induction. Instead, we obtain the result as a direct corollary of Lemma 0.7.9. The rest of the section will be devoted to a particular logical relation that is the key to proving computational adequacy.

###### Definition 0.7.3.

For every PCF type , define a relation

 Rσ:PCFtermsoftype$σ$→⟦σ⟧→Ω

by induction on :

1. ;

2. .

We will sometimes omit the type subscript in .

###### Lemma 0.7.4.

Let and be PCF terms of type and let be an element of . If and , then .

###### Proof.

By induction on , making use of the last part of Lemma 0.5.6. ∎

###### Lemma 0.7.5.

For equal to or , we have: .

###### Proof.

By the previous lemma and Lemma 0.5.6(i)–(iii). ∎

Next, we wish to extend the previous lemma the case where for any PCF type . This is slightly more complicated and we will need two intermediate lemmas. Only the second has a non-trivial proof.

###### Lemma 0.7.6.

Let be a PCF type and let be the least element of . Then, for any PCF term of type .

###### Proof.

By induction on . For the base type, this holds vacuously. For function types, it follows by induction hypothesis and the pointwise ordering. ∎

###### Lemma 0.7.7.

The logical relation is closed under directed suprema. That is, for every PCF term of type and every directed family , if for every , then .

###### Proof.

This proof is somewhat different from the classical proof, so we spell out the details. We prove the lemma by induction on .

The case when is a function type is easy, because least upper bounds are calculated pointwise and so it reduces to an application of the induction hypothesis. We concentrate on the case when instead.

Recall that is given by , where is the factorisation of

 ∑i:Iisdefined(di)→LN,(i,pi)↦value(di)(pi)

through . Let us write for the .

We are tasked with proving that for every . So assume that