arXiv reader

The Scott model of PCF in univalent type theory

Tom de Jong

arXiv
1904.09810v4 · PDF · 23 June 2021
Categories
math.LO, cs.LO
Licence
CC BY 4.0 The site shows the text.

Abstract

We develop the Scott model of the programming language PCF in univalent type theory. Moreover, we work constructively and predicatively. To account for the non-termination in PCF, we use the lifting monad (also known as the partial map classifier monad) from topos theory, which has been extended to univalent type theory by Escardó and Knapp. 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 quotient inductive-inductive types. We show that one can do without these extensions.

Items 119

Example

Example 1

VUZF

In set theory, the mathematical structure is provided by a set X and a binary relation \leq on X. Moreover, this relation is required to be reflexive, transitive and antisymmetric. Reflexivity, \forall_{x \in X} x \leq x is a logical statement that is bivalent.

In type theory, if we define {\leq} : {X \to X \to \mathsf{Type}}, with \mathsf{Type} some type universe, then the type encoding reflexivity, \prod_{x : X} x \leq x, may have more than one element. This is a fundamental difference with set theory.

In Coq, we could instead define {\leq} : {X \to X \to \texttt{Prop}}, where \texttt{Prop} is Coq’s special sort of propositions. This sort is defined such that (for instance) reflexivity, \forall_{x : X}\,x \leq x, is again in \texttt{Prop}.

The crucial difference between these approaches and the univalent approach, is that in univalent type theory, we prove that something is a proposition (truth value). Following Voevodsky, we define a type to be a proposition (truth value, subsingleton) if it has at most one element with respect to its identity type, i.e. up to propositional equality. To define posets, we then ask for a witness that the type x \leq y is a proposition for every x,y : X. This allows us, in the presence of function extensionality (which is a consequence of the univalence axiom), to prove that reflexivity and transitivity are propositions. For example, for reflexivity, we wish to show that the type \prod_{x : X} x \leq x is a proposition. So let f,g be two elements of this type. By function extensionality, it suffices to show that f(x) = g(x) for every x : X. But the type of f(x) and g(x) is x \leq x, which is a proposition by requirement, so f(x) and g(x) must be (propositionally) equal, as desired. Finally, we require X to be a set: any two elements of X are equal in at most one way. This ensures, using function extensionality again, that antisymmetry is a proposition.

Remark

Remark 3

GJMC

Notice that we require \leq to take values in \Omega, the type of propositions in \mathcal{U}_0, cf. Example 1. This allows us to prove (using function extensionality [HoTTbook, Example 3.6.2]) that reflexivity and transitivity are propositions, i.e. there is at most one witness of reflexivity and transitivity. We also express this by saying that reflexivity and transitivity are properties, rather than structures. Moreover, we restrict to X being a set to ensure that antisymmetry is a property, rather than a structure.

Definition

Definition 4 (FoundationsSetsposetmorphism)

VCU1

Let X and Y be posets. A poset morphism from X to Y is a function between the underlying sets that preserves the order. We also say that the function is monotone.

Remark

Remark 6

4YTO

We use the propositional truncation in the definition above to ensure that being directed is a property, rather than a structure (\nolinkurl{isaprop_isdirected}).

Firstly, we express that the type I is inhabited by requiring an element of \squash{I}. This is different from requiring an element of I. It is akin to the difference (in set theory) between a set X such that \exists {x \in X} holds and a pair (X,x) of a set with a chosen element x \in X.

Secondly, if we had used an untruncated \Sigma in the second clause of the definition, then we would have asked our poset to be equipped with an operation mapping pairs (x,y) of elements to some specified element greater than both x and y.

Definition

Definition 7 (AlgebraDCPOisupperbound, AlgebraDCPOislub, AlgebraDCPOisdirectedcomplete)

K74H

An element x of a poset X is an upper bound of a family u : I \to X if u_i \sqsubseteq x for every i : I.

It is a least upper bound of u if it is an upper bound and x \sqsubseteq y holds whenever y is an upper bound of u.

A poset X is called \mathcal U-directed complete for a type universe \mathcal U if every directed family in X indexed by a type in \mathcal U has a least upper bound in X, which we denote by \bigsqcup_{i : I} u_i. Symbolically, \prod_{I : \mathcal U}\prod_{u : I \to X} \pa*{u\text{ is directed} \to \sum_{x : X} x \text{ is a least upper bound of u}}.

We call such a poset a \mathcal U-dcpo.

We shall often simply write dcpo, omitting reference to the type universe.

Remark

Remark 8

ADAJ

Contrary to Definition 5, directed completeness is not phrased with a truncated \Sigma. This justifies having the least upper bound operator \bigsqcup. The reason for this definition of directed completeness is that least upper bounds are unique when they exist (\nolinkurl{lubsareunique}). Moreover, the type expressing that an element is a least upper bound for a family can be shown to be a proposition using function extensionality (\nolinkurl{isaprop_islub}). Hence, for any family u, the type of least upper bounds of u and its propositional truncation are equivalent. This observation also tells us, using function extensionality again, that the type expressing that a poset is directed complete is also a proposition (\nolinkurl{isaprop_isdirectedcomplete}), i.e. it is a property of the poset.

Remark

Remark 9

1S53

In classical mathematics, a dcpo is usually defined as a poset such that every directed subset has a least upper bound. We have formulated our version using families, because in our type-theoretic framework functions are primitive, unlike in set theory where sets are primitive and functions are encoded as particular sets. Another reason for preferring families is that we work in the absence of propositional resizing, so that we must pay attention to size and therefore only ask for least upper bounds of small directed subsets. This point is explained and worked out in detail in [deJongEscardo2021b, Section 5] to which we refer the interested reader. Here we limit ourselves to saying that working with families is more direct, and that for the Scott model we will only need to consider simple \mathsf{N}-indexed directed families anyway.

Lemma

Lemma 11

0365

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

Proof (AlgebraDCPOpreservesdirectedlub_isdcpomorphism) of Lemma 11

Let f : D \to E be a morphism of dcpos and suppose x,y : D with x \leq y. Consider the family \mathsf{1} + \mathsf{1} \to D defined as \operatorname{\mathsf{inl}}(\star) \mapsto x and \operatorname{\mathsf{inr}}(\star) \mapsto y. This family is easily seen to be directed and its least upper bound is y. Now f preserves this least upper bound, so f(x) \leq f(y).

Lemma

Lemma 12

ZVYH

Every morphism of dcpos preserves directed families. That is, if f : D \to E is a morphism of dcpos and u is a directed family in D, then f \circ u is a directed family in E.

Proof (AlgebraDCPOdcpomorphism_preservesdirected) of Lemma 12

Using monotonicity of f.

Theorem

Theorem 13

ISQZ

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

Proof (AlgebraDCPOdcpoofdcpomorphisms) of Theorem 13

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

Definition

Definition 14 (AlgebraDCPOdcpowithbottom)

RN0K

A dcpo with \bot is a dcpo D together with a least element in D.

Theorem

Theorem 15

QL5K

Let D be a dcpo and let E be a dcpo with \bot. Ordered pointwise, the morphisms from D to E form a dcpo with \bot, which we denote by E^D.

Proof (AlgebraDCPOdcpowithbottom_ofdcpomorphisms) of Theorem 15

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

Theorem

Theorem 16

8563

Let D be a dcpo with \bot. There is a continuous function \mu : D^D \to D that sends each continuous function to its least fixed point. In fact, \mu satisfies:

  1. f(\mu(f)) = \mu(f) for every continuous f : D \to D;

  2. for every continuous f : D \to D and each d : D, if f(d) \leq d, then \mu(f) \leq d.

Proof (Proof. (AlgebraDCPOleastfixedpoint_isfixedpoint, AlgebraDCPOleastfixedpoint_isleast)) of Theorem 16

We have formalised the proof of [AbramskyJung1994, Theorem 2.1.19]. We sketch the main construction here. For each natural number n, define \mathsf{iter}(n) : D^D \to D as

\mathsf{iter}(n)(f) \vcentcolon\mspace{-1.2mu}\equiv f^n(\bot) \vcentcolon\mspace{-1.2mu}\equiv \underbrace{f(f(\dots(f}_{n\text{ times}}(\bot))\dots)).

By induction on n, one may show that every \mathsf{iter}(n) is continuous. Then, the assignment n~\mapsto~{\mathsf{iter}(n)} is a directed family in D^{\pa*{D^D}}. Finally, one defines \mu as the least upper bound of this directed family. Recall that least upper bounds in the exponential are given pointwise, so that \mu(f) = \bigsqcup_{n : \mathsf{N}} f^n(\bot).

Lemma

Lemma 17

6J21

Directed completeness of \mathsf{N}_{\bot} implies LPO.

Proof of Lemma 17

Suppose that \mathsf{N}_{\bot} is (\mathcal{U}_0-)directed complete. Let \alpha : \mathsf{N} \to \mathsf{2} be an arbitrary binary sequence. Define the family \beta : \mathsf{N} \to \mathsf{N}_{\bot} as

\beta(n) \vcentcolon\mspace{-1.2mu}\equiv \begin{cases} \operatorname{\mathsf{inl}}(k) &\text{if $k$ is the least integer $\leq n$ such that $\alpha(k) = 1$;} \\ \operatorname{\mathsf{inr}}(\star) &\text{else}. \end{cases}

Then \beta is directed, so by assumption, it has a supremum s in \mathsf{N}_{\bot}. By the induction principle of sum-types, we can decide whether s = \operatorname{\mathsf{inl}}(k) for some k : \mathsf{N} or s = \operatorname{\mathsf{inr}}(\star). The former implies \sum_{k : \mathsf{N}} \alpha(k) = 1 and we claim that the latter implies \prod_{n : \mathsf{N}} \alpha(n) = 0. For suppose that s = \operatorname{\mathsf{inr}}(\star) and let n : \mathsf{N}. Since \mathsf{2} has decidable equality, it suffices to show that \alpha(n) \neq 1. Assume for a contradiction that \alpha(n) = 1. Then \beta(n) = \operatorname{\mathsf{inl}}(k) for some natural number k \leq n. Using that s is the supremum of \beta yields: \operatorname{\mathsf{inl}}(k) = \beta(n) \leq_\bot s = \operatorname{\mathsf{inr}}(\star). By definition of the order we also have the reverse inequality \operatorname{\mathsf{inr}}(\star) \leq_\bot \operatorname{\mathsf{inl}}(k). Hence, \operatorname{\mathsf{inr}}(\star) = \operatorname{\mathsf{inl}}(k) by antisymmetry, which is a contradiction, so \alpha(n) \neq 1 as desired.

Definition

Definition 18 (PartialityPartialElementslift)

1YR0

Let X be any type. Define the lifting of X as

\operatorname{\mathcal L}(X) \vcentcolon\mspace{-1.2mu}\equiv \sum_{P : \Omega} (P \to X).

Strictly speaking, we should have written \operatorname{\mathsf{pr_1}}(P) \to X, because elements of \Omega are pairs of types and witnesses that these types are subsingletons. We will almost always suppress reference to these witnesses in this paper.

Definition

Definition 19 (PartialityPartialElementsliftorder_least)

CLS2

For any type X, the type \operatorname{\mathcal L}(X) has a distinguished element

\bot_X \vcentcolon\mspace{-1.2mu}\equiv \pa*{\mathsf{0},\textup{\textsf{from-}}\mathsf{0}_X} : \operatorname{\mathcal L}(X),

where \textup{\textsf{from-}}\mathsf{0}_X is the unique function from \mathsf{0} to X.

Used by Proof
Definition

Definition 20 (PartialityPartialElementslift_embedding)

QLDD

There is a canonical map \eta_X \colon X \to \operatorname{\mathcal L}(X) defined by

\eta_X(x) \vcentcolon\mspace{-1.2mu}\equiv (\mathsf{1},\lambda t.x).
Definition

Definition 21 (PartialityPartialElementsisdefined, PartialityPartialElementsvalue)

6LLA

We take \operatorname{\mathsf{isdefined}} : \operatorname{\mathcal L}(X) \to \Omega to be the first projection. The function \operatorname{\mathsf{value}} : \prod_{l : \operatorname{\mathcal L} (X)} \operatorname{\mathsf{isdefined}} (l) \to X is given by: \operatorname{\mathsf{value}} (P,\varphi) (p) \vcentcolon\mspace{-1.2mu}\equiv \varphi (p).

Lemma

Lemma 22

9F59

Let X be any type and let l, m : \operatorname{\mathcal L}(X). The following are logically equivalent(In fact, there is a type equivalence. One can prove this using univalence and a generalised structure identity principle, cf. [TypeTopology, LiftingIdentityViaSIP].)

  1. l = m;

  2. \sum_{e : \operatorname{\mathsf{isdefined}}(l) \leftrightarrow \operatorname{\mathsf{isdefined}}(m)} \operatorname{\mathsf{value}}(l) \circ \operatorname{\mathsf{pr_2}}(e) \sim \operatorname{\mathsf{value}}(m).

Used by Proof, Proof
Proof (Proof. (PartialityPartialElementslifteq_necc, PartialityPartialElementslifteq_suff)) of Lemma 22

First of all, the characterisation of the identity type of \Sigma-types [HoTTbook, Theorem 2.7.2] yields:

\pa*{l = m} \simeq \sum_{e' : \operatorname{\mathsf{isdefined}}(l) = \operatorname{\mathsf{isdefined}}(m)} \operatorname{\mathsf{transport}}(e',\operatorname{\mathsf{value}}(l))=\operatorname{\mathsf{value}}(m).

Thus we only have to show that the right-hand side of (Proof) is logically equivalent to (?) in the lemma. Suppose first that we have e' : \operatorname{\mathsf{isdefined}}(l) = \operatorname{\mathsf{isdefined}}(m) and an equality {p : \operatorname{\mathsf{transport}}(e',\operatorname{\mathsf{value}}(l)) = \operatorname{\mathsf{value}}(m)}. Then

e \vcentcolon\mspace{-1.2mu}\equiv \mathsf{eqtoiff}(e') : {\operatorname{\mathsf{isdefined}}(l) \leftrightarrow \operatorname{\mathsf{isdefined}}(m)}.

Using path induction on e', we can prove that \operatorname{\mathsf{value}}(l) \circ \operatorname{\mathsf{pr_2}}(e) = \operatorname{\mathsf{transport}}(e',\operatorname{\mathsf{value}}(l)). Together with p, this equality implies \operatorname{\mathsf{value}}(l) \circ \operatorname{\mathsf{pr_2}}(e) \sim \operatorname{\mathsf{value}}(m), as desired.

Conversely, suppose e : \operatorname{\mathsf{isdefined}} (l) \leftrightarrow \operatorname{\mathsf{isdefined}} (m) and v : \operatorname{\mathsf{value}} (l) \circ \operatorname{\mathsf{pr_2}}(e) \sim \operatorname{\mathsf{value}}(m). By propositional extensionality, we obtain e' : \operatorname{\mathsf{isdefined}}(l) = \operatorname{\mathsf{isdefined}}(m) from e. From e' we can get an equivalence \mathsf{idtoeqv}(e') : \operatorname{\mathsf{isdefined}} (l) \simeq \operatorname{\mathsf{isdefined}}(m). Furthermore, using path induction on e', one can prove that

\operatorname{\mathsf{transport}}(e',\operatorname{\mathsf{value}}(l)) = \operatorname{\mathsf{value}}(l) \circ (\mathsf{idtoeqv}(e'))^{-1}.

Hence, it suffices to show that the right-hand side of (?) is equal to \operatorname{\mathsf{value}}(m). The homotopy v yields \operatorname{\mathsf{value}}(l) \circ \operatorname{\mathsf{pr_2}}(e) = \operatorname{\mathsf{value}}(m) by function extensionality, so it suffices to prove that (\mathsf{idtoeqv}(e'))^{-1} = \operatorname{\mathsf{pr_2}}(e). But these are both functions with codomain \operatorname{\mathsf{isdefined}}(l), which is a proposition, so they are equal by function extensionality.

Definition

Definition 23 (PartialityLiftMonadKleisli_extension)

AHTZ

Given f : X \to \operatorname{\mathcal L} (Y), the Kleisli extension f^\# : \operatorname{\mathcal L}(X) \to \operatorname{\mathcal L}(Y) is defined by:

f^\#(P,\varphi) \vcentcolon\mspace{-1.2mu}\equiv \Bigg(\sum_{p : P} \operatorname{\mathsf{isdefined}} (f(\varphi(p))), \psi\Bigg),

where \psi(p,d) \vcentcolon\mspace{-1.2mu}\equiv \operatorname{\mathsf{value}} (f(\varphi(p)))(d).

Theorem

Theorem 24 (Theorem 5.8 in , Section 2.2 in)

HDSF

The above constructions yield a monad structure on \operatorname{\mathcal L}(X), i.e. the Kleisli laws hold (pointwise):

  1. \pa*{\eta_X}^\# \sim \operatorname{id}_{\operatorname{\mathcal L}(X)};

  2. f^\# \circ \eta_X \sim f for any f : X \to \operatorname{\mathcal L} (Y);

  3. g^\# \circ f^\# \sim (g^\# \circ f)^\# for any f : X \to \operatorname{\mathcal L}(Y) and g : Y \to \operatorname{\mathcal L}(Z).

Used by Proof
Proof (Proof. (PartialityLiftMonadeta_extension, PartialityLiftMonadfun_extension_after_eta, PartialityLiftMonadextension_comp)) of Theorem 24

The proofs are straightforward thanks to Lemma 22. Item (?) is essentially the associativity of \Sigma, i.e. equivalence between \sum_{a : A} \sum_{b : B(a)} C(a,b) and \sum_{(a,b) : \sum_{a : A} B(a)} C(a,b).

Theorem

Theorem 25

4TKO

If X is a set, then so is its lifting \operatorname{\mathcal L}(X).

Proof (PartialityPartialElementsliftofhset_isaset) of Theorem 25

As in the proof of Lemma 22, we have:

l = m \simeq \sum_{e : \operatorname{\mathsf{isdefined}}(l) = \operatorname{\mathsf{isdefined}}(m)} \operatorname{\mathsf{transport}}(e,\operatorname{\mathsf{value}} (l)) = \operatorname{\mathsf{value}} (m).

Since X is a set, the type \operatorname{\mathsf{transport}}(e,\operatorname{\mathsf{value}}(l)) = \operatorname{\mathsf{value}}(m) is a proposition. So, if we can prove that \operatorname{\mathsf{isdefined}}(l) = \operatorname{\mathsf{isdefined}}(m) 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 P and Q are propositions, then so is P = Q. At first glance, it might seem like one needs univalence (for propositions) to prove this, but in fact propositional extensionality suffices. By [Krausetal2017, Lemma 3.11] (applied to the type of propositions), it suffices to give for every proposition R, a (weakly) constant (i.e. any two of its values are equal) endomap on P = R. But the composition

(P = R) \to (P \leftrightarrow R) \xrightarrow{\text{PropExt}} (P = R)

is weakly constant, because P \leftrightarrow R is a proposition, so this finishes the proof.

Theorem

Theorem 26 (cf. Theorem 5.14 in and Theorem 1 in)

IDEM

If X is a set, then \operatorname{\mathcal L}(X) is a dcpo with \bot with the following order:

l \sqsubseteq m \vcentcolon\mspace{-1.2mu}\equiv \operatorname{\mathsf{isdefined}}(l) \to l = m.
Proof (PartialityPartialElementsliftdcpowithbottom) of Theorem 26

First of all, we should prove that \operatorname{\mathcal L}(X) is a poset with the specified order. In particular, \sqsubseteq should be proposition-valued. If X is a set, then \operatorname{\mathsf{isdefined}}(l) \to l = m is a function type into a proposition and therefore a proposition itself.

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

The \bot element of \operatorname{\mathcal L}(X) is given by \bot_X from Definition 19.

The construction of the least upper bound of a directed family is the most challenging part of the proof. Let u : I \to \operatorname{\mathcal L}(X) be a directed family in \operatorname{\mathcal L}(X). Consider the diagram (of solid arrows):

The paper has a diagram here, which this page does not show.

We are going to construct the dashed map \psi that makes the diagram commute and define the least upper bound of u as: \pa*{\squash*{\sum_{i : I}\operatorname{\mathsf{isdefined}}(u_i)},\psi}. Truncating the type is necessary, as \sum_{i : I}\operatorname{\mathsf{isdefined}}(u_i) may have more than one element if I is not a proposition. The difficulty lies in the fact that the universal property of the truncation only tells us how to define maps into propositions. But X is a set. We solve this problem using [Krausetal2017, Theorem 5.4], which says that every weakly constant function f : A \to B to a set B factors through \squash*{A}. That f is weakly constant means that f(a) = f(a') for every a,a' : A. So, to construct \psi, we only need to prove that the top map \varphi in the diagram is weakly constant. Let (i,d_i) , (j,d_j) be two elements of the domain of \varphi. We are to prove that \operatorname{\mathsf{value}}(u_i)(d_i) = \operatorname{\mathsf{value}}(u_j)(d_j). As X is a set, this is a proposition. Therefore, using that u is directed, we obtain k : I with u_i,u_j \sqsubseteq u_k. But d_i : \operatorname{\mathsf{isdefined}}(u_i) and d_j : \operatorname{\mathsf{isdefined}}(u_j), so u_i = u_k = u_j by definition of the order. Hence, \varphi(i,d_i) = \operatorname{\mathsf{value}}(u_i)(d_i) = \operatorname{\mathsf{value}}(u_j)(d_j) = \varphi(j,d_j), as we wished to show.

Theorem

Theorem 27

O9MX

Let X and Y be sets and f : X \to \operatorname{\mathcal L}(Y) any function. The Kleisli extension f^\# : \operatorname{\mathcal L}(X) \to \operatorname{\mathcal L}(Y) is a morphism of dcpos.

Proof (PartialityLiftMonadKleisli_extension_dcpo) of Theorem 27

Let v be the least upper bound of a directed family u : I \to \operatorname{\mathcal L}(X) in \operatorname{\mathcal L}(X). Proving that f^\# is monotone is quite easy. By monotonicity, f^\#(v) is an upper bound for the family f^\# \circ u. We are left to prove that it is the least. Suppose that l : \operatorname{\mathcal L}(Y) is another upper bound for the family f^\#\circ u, i.e. l \sqsupseteq f^\#(u_i) for every i : I. We must show that f^\#(v) \sqsubseteq l. To this end, assume we have q : \operatorname{\mathsf{isdefined}}(f^\#(v)). We must prove that f^\#(v) = l.

From q, we obtain p : \operatorname{\mathsf{isdefined}}(v) by definition of f^\#. By our construction of suprema in \operatorname{\mathcal L}(X) and the fact that f^\#(v) = l is a proposition, we may in fact assume that we have an element i : I and d_i : \operatorname{\mathsf{isdefined}}(u_i). But l \sqsupseteq f^\#(u_i), so using d_i, we get the equality l = f^\#(u_i). Since v is an upper bound for u, the term d_i also yields u_i = v. In particular, l = f^\#(u_i) = f^\#(v), as desired.

Remark

Remark 28 (PartialityLiftMonadliftfunctor_eq)

C3JP

Finally, one could define the functor \operatorname{\mathcal L} from the Kleisli extension and unit by putting \operatorname{\mathcal L}(f) \vcentcolon\mspace{-1.2mu}\equiv (\eta_Y \circ f)^\# for any f : X \to Y. However, it is equivalent and easier to directly define \operatorname{\mathcal L}(f) by postcomposition: \operatorname{\mathcal L}(f)(P,\varphi) \vcentcolon\mspace{-1.2mu}\equiv (P,f \circ \varphi).

Remark

Remark 29

NTWP

We remark that lifting may be regarded as a free construction, in more than one way in fact. This result should be compared to [AltenkirchDanielssonKraus2017, Theorem 5], where Altenkirch et al. exhibit their QIIT as the free \omega-cpo with a least element (cf. Section ?).

By [deJongEscardo2021a, Theorems 21 and 23], the lifting of a set X can be regarded both as the free pointed dcpo on X and as the free subsingleton complete poset on X. In our predicative setting, some care should be taken in formulating these statements. We do not go into the details here and instead refer the interested reader to [deJongEscardo2021a].

Definition

Definition 30 (PartialityPCFtype)

Z4N2

The PCF types are inductively defined as:

  1. \iota is a type, the base type;

  2. for every two types \sigma and \tau, there is a function type \sigma \Rightarrow \tau.

As usual, \Rightarrow will be right associative, so we write \sigma \Rightarrow \tau \Rightarrow \rho for \sigma \Rightarrow (\tau \Rightarrow \rho).

Definition

Definition 31 (PartialityPCFterm)

WT6O

The PCF terms of PCF type \sigma are inductively generated by:

t : \iota {\mathsf{zero}} \text{ of type } \iota t : \iota {\operatorname{\mathsf{succ}}} \text{ of type } \iota \Rightarrow \iota
t : \iota \operatorname{\mathsf{pred}} \text{ of type } \iota \Rightarrow \iota t : \iota {\operatorname{\mathsf{ifz}}} \text{ of type } {\iota \Rightarrow \iota \Rightarrow \iota \Rightarrow \iota}
t : \iota {\operatorname{\mathsf{k}}_{\sigma,\tau}} \text{ of type } \sigma \Rightarrow \tau \Rightarrow \sigma t : \iota {\operatorname{\mathsf{s}}_{\sigma,\tau,\rho}} \text{ of type } (\sigma \Rightarrow \tau \Rightarrow \rho) \Rightarrow \break (\sigma \Rightarrow \tau) \Rightarrow \sigma \Rightarrow \rho
t : \iota {\operatorname{\mathsf{fix}}_\sigma} \text{ of type } (\sigma \Rightarrow \sigma) \Rightarrow \sigma s \text{ of type } \sigma \Rightarrow \tau t \text{ of type } \tau (st) \text{ of type } \tau

We will often drop the parentheses in the final clause, as well as the PCF type subscripts in {\operatorname{\mathsf{k}}_{\sigma,\tau}}, {\operatorname{\mathsf{s}}_{\sigma,\tau,\rho}} and {\operatorname{\mathsf{fix}}_\sigma}. Finally, we employ the convention that the parentheses associate to the left, i.e. we write rst for (rs)t.

Definition

Definition 32 (PartialityPCFnumeral)

YGS9

For any n : \mathsf{N}, let us write \underline n for the nth PCF numeral, defined inductively as:

\underline 0 \vcentcolon\mspace{-1.2mu}\equiv {\mathsf{zero}};\quad \underline {n+1} \vcentcolon\mspace{-1.2mu}\equiv \operatorname{\mathsf{succ}}\,\underline n.
Definition

Definition 33 (PartialityPCFsmallstep’, PartialityPCFsmallstep)

VFO4

Define the small-step pre-relation \mathbin{\widetilde{\triangleright}} of type

\prod_{\sigma : \text{PCF types}} \text{PCF terms of type $\sigma$} \to \text{PCF terms of type $\sigma$} \to \mathcal{U}_0

as the inductive family generated by:

f \mathbin{\widetilde{\triangleright}} g \operatorname{\mathsf{pred}}\underline 0\mathbin{\widetilde{\triangleright}}\underline 0 f \mathbin{\widetilde{\triangleright}} g \operatorname{\mathsf{pred}}\underline {n+1}\mathbin{\widetilde{\triangleright}}\underline n f \mathbin{\widetilde{\triangleright}} g \operatorname{\mathsf{ifz}} s\,t\,\underline 0\mathbin{\widetilde{\triangleright}} s f \mathbin{\widetilde{\triangleright}} g \operatorname{\mathsf{ifz}} s\,t\,\underline {n+1}\mathbin{\widetilde{\triangleright}} t
f \mathbin{\widetilde{\triangleright}} g {\operatorname{\mathsf{k}}} st\mathbin{\widetilde{\triangleright}} s f \mathbin{\widetilde{\triangleright}} g {\operatorname{\mathsf{s}}}fgt\mathbin{\widetilde{\triangleright}} ft(gt) f\mathbin{\widetilde{\triangleright}} g \operatorname{\mathsf{fix}} f\mathbin{\widetilde{\triangleright}} f(\operatorname{\mathsf{fix}} f) f\mathbin{\widetilde{\triangleright}} g ft\mathbin{\widetilde{\triangleright}} gt
s \mathbin{\widetilde{\triangleright}} t \operatorname{\mathsf{succ}} s \mathbin{\widetilde{\triangleright}} \operatorname{\mathsf{succ}} t s \mathbin{\widetilde{\triangleright}} t \operatorname{\mathsf{pred}} s \mathbin{\widetilde{\triangleright}} \operatorname{\mathsf{pred}} t r \mathbin{\widetilde{\triangleright}} r' \operatorname{\mathsf{ifz}} s\,t\,r \mathbin{\widetilde{\triangleright}} \operatorname{\mathsf{ifz}} s\,t\,r'

We have been unable to prove that s \mathbin{\widetilde{\triangleright}} t is a proposition for every suitable PCF terms s and t. The difficulty is that one cannot perform induction on both s and t. However, conceptually, s \mathbin{\widetilde{\triangleright}} t should be a proposition, as (by inspection of the definition), there is at most one way by which we obtained s \mathbin{\widetilde{\triangleright}} t. Moreover, for technical reasons that will become apparent later, we really want \mathbin{\widetilde{\triangleright}} to be propostion-valued.

We solve the problem by defining the small-step relation \mathbin{\triangleright} as the propositional truncation of \mathbin{\widetilde{\triangleright}}, i.e. s \mathbin{\triangleright} t \vcentcolon\mspace{-1.2mu}\equiv \squash{s \mathbin{\widetilde{\triangleright}} t}.

Used by Proof, Proof
Remark

Remark 34

5D46

Benedikt Ahrens pointed out that in an impredicative framework, one could use propositional resizing and an impredicative encoding, i.e. by defining \mathbin{\triangleright} as a \Pi-type of all suitable proposition-valued relations. This is similar to the situation in set theory, where one would define \mathbin{\triangleright} as an intersection. Specifically, say that a relation

R : \prod_{\sigma : \text{PCF types}} \pa*{\text{PCF terms of type \(\sigma\)} \to \text{PCF terms of type \(\sigma\)} \to \Omega_{\mathcal U_0}}

is suitable if it closed under all the clauses of Definition 33, i.e. R\pa*{\iota,\operatorname{\mathsf{pred}} \underline 0,\underline 0}, R\pa*{\iota,\operatorname{\mathsf{pred}} \underline{n+1},\underline n}, etc. are all inhabited. We could define s \mathbin{\triangleright}_{\text{impred}} t \vcentcolon\mspace{-1.2mu}\equiv \prod_{R \text{ suitable}} R(\sigma,s,t). But notice the increase in universe level:

\mathbin{\triangleright}_{\text{impred}} : \prod_{\sigma : \text{PCF types}} \pa*{\text{PCF terms of type \(\sigma\)} \to \text{PCF terms of type \(\sigma\)} \to \Omega_{\mathcal U_1}}.

So because of this increase, \mathbin{\triangleright}_{\text{impred}} itself is not one of the suitable relations. Therefore \mathbin{\triangleright}_{\text{impred}} does not satisfy the appropriate universal property in being the least relation closed under the clauses in Definition 33. With propositional resizing we could resize \mathbin{\triangleright}_{\text{impred}} to a \mathcal U_0-valued relation satisfying the appropriate universal property.

The advantage of using the propositional truncation above is that it does satisfy the right universal property even without propositional resizing.

Definition

Definition 35 (MoreFoundationsClosureOfHrelrefl_trans_clos, MoreFoundationsClosureOfHrelrefl_trans_clos_hrel)

JWXL

Let R : X \to X \to \Omega be a relation on a type X. We define the reflexive transitive closure R^\ast of R by x R^\ast y \vcentcolon\mspace{-1.2mu}\equiv \squash*{x R_\ast y}, where R_\ast is as above.

Lemma

Lemma 36

5159

Let r', r, s and t be PCF terms of type \iota. If r' \mathbin{\triangleright}^\ast r, then

  1. \operatorname{\mathsf{succ}} r' \mathbin{\triangleright}^\ast \operatorname{\mathsf{succ}} r;

  2. \operatorname{\mathsf{pred}} r' \mathbin{\triangleright}^\ast \operatorname{\mathsf{pred}} r;

  3. \operatorname{\mathsf{ifz}} s\,t\,r' \mathbin{\triangleright}^\ast \operatorname{\mathsf{ifz}} s\,t\,r.

Moreover, if f and g are PCF terms of type \sigma\Rightarrow\tau and f \mathbin{\triangleright}^\ast g, then f t \mathbin{\triangleright}^\ast g t for any PCF term t of type \sigma.

Used by Proof, Proof
Proof (Proof (PartialityPCFsucc_refltrans_smallstep, PartialityPCFpred_refltrans_smallstep, PartialityPCFifz_refltrans_smallstep, PartialityPCFapp_refltrans_smallstep)) of Lemma 36

We only prove (?) the rest is similar. Suppose r' \mathbin{\triangleright}^\ast r'. Since \operatorname{\mathsf{succ}} r' \mathbin{\triangleright}^\ast \operatorname{\mathsf{succ}} r is a proposition, we may assume that we actually have a term p of type r' \mathbin{\triangleright}_\ast r'. Now we can perform induction on p. The cases were p is formed using \mathsf{refl} or \mathsf{trans} are easy. If p is formed by \mathsf{extend}, then we get a term of type r \mathbin{\triangleright} r' \equiv \squash{r \widetilde{\mathbin{\triangleright}} r'}. Again, as we are proving a proposition, we may suppose the existence of a term of type r \widetilde{\mathbin{\triangleright}} r'. By Definition 33, we then get \operatorname{\mathsf{succ}} r'\widetilde{\mathbin{\triangleright}}\operatorname{\mathsf{succ}} r. This in turn yields, \operatorname{\mathsf{succ}} r'\mathbin{\triangleright}\operatorname{\mathsf{succ}} r and finally we use \mathsf{extend} to get the desired \operatorname{\mathsf{succ}} r'\mathbin{\triangleright}^\ast\operatorname{\mathsf{succ}} r.

Definition

Definition 37 (PartialityPCFdenotational_semantics_type)

8DWT

Inductively assign to each PCF type \sigma a dcpo with \bot as follows:

  1. \densem{\iota} \vcentcolon\mspace{-1.2mu}\equiv \operatorname{\mathcal L}(\mathsf{N});

  2. \densem{\sigma \Rightarrow \tau} \vcentcolon\mspace{-1.2mu}\equiv \densem{\tau}^{\densem{\sigma}}.

Recall that if D and E are dcpos with \bot, then E^D is the dcpo with \bot of dcpo morphisms from D to E, with pointwise ordering and pointwise least upper bounds.

Definition

Definition 38 (PartialityPCFdenotational_semantics_terms)

PYAP

Define for each PCF term t of PCF type \sigma a term \densem{t} of type \densem{\sigma}, by the following inductive clauses:

  1. \densem{\mathsf{zero}} \vcentcolon\mspace{-1.2mu}\equiv \eta(0);

  2. \densem{\operatorname{\mathsf{succ}}} \vcentcolon\mspace{-1.2mu}\equiv \operatorname{\mathcal L}(s), where s : \mathsf{N} \to \mathsf{N} is the successor function;

  3. \densem{\operatorname{\mathsf{pred}}} \vcentcolon\mspace{-1.2mu}\equiv \operatorname{\mathcal L}(p), where p : \mathsf{N} \to \mathsf{N} is the predecessor function;

  4. \densem{\operatorname{\mathsf{ifz}}} : \densem{\iota\Rightarrow\iota\Rightarrow\iota\Rightarrow\iota} is defined using the Kleisli extension as: \lambda x,y.\pa*{\chi_{x,y}}^{\#}, where

    \chi_{x,y}(n) \vcentcolon\mspace{-1.2mu}\equiv \begin{cases} x &\text{if } n = 0; \\ y &\text{else}; \end{cases}
  5. \densem{\operatorname{\mathsf{k}}} \vcentcolon\mspace{-1.2mu}\equiv \lambda x, y . x;

  6. \densem{\operatorname{\mathsf{s}}} \vcentcolon\mspace{-1.2mu}\equiv \lambda f, g, x . (f (x)) (g (x));

  7. \densem{\operatorname{\mathsf{fix}}} \vcentcolon\mspace{-1.2mu}\equiv \mu, where \mu is the least fixed point operator from Theorem 16.

Remark

Remark 39

GLL2

Of course, there are some things to be proved here. Namely, \densem{\operatorname{\mathsf{succ}}}, \densem{\operatorname{\mathsf{pred}}}, \dots, \densem{\operatorname{\mathsf{fix}}} all need to be dcpo morphisms. In the case of \densem{\operatorname{\mathsf{succ}}} and \densem{\operatorname{\mathsf{pred}}}, we simply appeal to Theorem 27 and Remark 28. For \densem{\operatorname{\mathsf{fix}}}, this is Theorem 16. The continuity of \densem{\operatorname{\mathsf{k}}}, \densem{\operatorname{\mathsf{s}}} and \densem{\operatorname{\mathsf{ifz}}} can be verified directly, as done in the formalisation (\nolinkurl{k_dcpo}, \nolinkurl{s_dcpo}, \nolinkurl{lifted_ifz}). It is however, unenlightning and tedious, so we omit the details here.

Proposition

Proposition 40

8LSO

For every natural number n, we have \densem{\underline n} = \eta (n).

Used by Proof, Proof
Proof (PartialityPCFdenotational_semantics_numerals) of Proposition 40

We proceed by induction on n. The n\equiv 0 case is by definition of \densem{\underline 0}. Suppose \densem{\underline m} = \eta (m) for a natural number m. Then,

\begin{alignedat}{2} \densem{\underline {m+1}} &= \densem{\operatorname{\mathsf{succ}}}(\densem{\underline m}) \\ &= \operatorname{\mathcal L}(s)(\eta (m))\quad&&\text{(by induction hypothesis)} \\ &= \eta(m + 1) \quad&&\text{(by definition of the lift functor)}, \end{alignedat}

as desired.

Theorem

Theorem 41 (Soundness)

S7S1

Let s and t be any PCF terms of PCF type \sigma. If s \mathbin{\triangleright}^\ast t, then \densem{s} = \densem{t}.

Proof (PartialityPCFsoundness) of Theorem 41

Since the carriers of dcpos are defined to be sets, the type \densem{s} = \densem{t} is a proposition. Therefore, we can use induction on the derivation of s \mathbin{\triangleright}^\ast t. We use the Kleisli monad laws in proving some of the cases. For example, one step is to prove that

\densem{\operatorname{\mathsf{ifz}} s\,t\,\underline{n+1}} = \densem{t}.

This may be proved by the following chain of equalities:

\begin{alignedat}{2} \densem{\operatorname{\mathsf{ifz}} s\,t\,\underline{n+1}} &= \densem{\operatorname{\mathsf{ifz}} s\,t}(\densem{\underline{n+1}}) \\ &= \densem{\operatorname{\mathsf{ifz}} s\,t}(\eta(n+1))\quad&&\text{(by Proposition~\ref{densemnumeral})} \\ &= (\chi_{\densem{s},\densem{t}})^\#(\eta(n+1)) \quad&&\text{(by definition of $\densem{\operatorname{\mathsf{ifz}}}$)} \\ &= \chi_{\densem{s},\densem{t}}(n+1) \quad&&\text{(by Theorem~\ref{lifting-is-monad})} \\ &= \densem{t}. \end{alignedat}
Theorem

Theorem 42 (Computational adequacy)

IMXG

Let t be a PCF term of PCF type \iota. Then,

\prod_{p : \operatorname{\mathsf{isdefined}} (\densem{t})} t \mathbin{\triangleright}^\ast \underline{\operatorname{\mathsf{value}} (\densem{t}) (p)}.

Equivalently, for every n : \mathsf{N}, it holds that \densem{t} = \densem{\underline{n}} implies t \mathbin{\triangleright^{\ast}} {\underline n}.

Definition

Definition 43 (PartialityPCFadequacy_relation)

ABHB

For every PCF type \sigma, define a relation

R_\sigma : \textup{PCF terms of type $\sigma$} \to \densem{\sigma} \to \Omega

by induction on \sigma:

  1. t R_\iota d \vcentcolon\mspace{-1.2mu}\equiv \prod_{p : \operatorname{\mathsf{isdefined}} (d)} t \mathbin{\triangleright}^\ast \underline {\operatorname{\mathsf{value}}(d)(p)};

  2. s R_{\tau \Rightarrow \rho} f \vcentcolon\mspace{-1.2mu}\equiv \prod_{t : \text{PCF terms of type}} \prod_{d : \densem{\tau}} \pa*{t R_\tau d \to st R_\rho f(d)}.

We sometimes omit the type subscript \sigma in R_\sigma.

Lemma

Lemma 44

KJLM

Let s and t be PCF terms of type \sigma and let d be an element of \densem{\sigma}. If s \mathbin{\triangleright}^\ast t and t R_\sigma d, then s R_\sigma d.

Used by Proof
Proof (PartialityPCFadequacy_step) of Lemma 44

By induction on \sigma, making use of the last part of Lemma 36.

Lemma

Lemma 45

NAUM

For t equal to \mathsf{zero}, {\operatorname{\mathsf{succ}}}, {\operatorname{\mathsf{pred}}}, {\operatorname{\mathsf{ifz}}}, {\operatorname{\mathsf{k}}} or {\operatorname{\mathsf{s}}}, we have: t R \densem{t}.

Used by Proof
Proof (Proof (PartialityPCFadequacy_zero, PartialityPCFadequacy_succ, PartialityPCFadequacy_pred, PartialityPCFadequacy_ifz, PartialityPCFadequacy_k,
PartialityPCFadequacy_s).)
of Lemma 45

By the previous lemma and Lemma 36.

Lemma

Lemma 46

EOEW

Let \sigma be a PCF type and let \bot be the least element of \densem{\sigma}. Then, t R_\sigma \bot for any PCF term t of type \sigma.

Used by Proof
Proof (PartialityPCFadequacy_bottom) of Lemma 46

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

Lemma

Lemma 47

36DY

The logical relation is closed under directed suprema. That is, for every PCF term t of type \sigma and every directed family d : I \to \densem{\sigma}, if t R_\sigma d_i for every i : I, then t R_\sigma \bigsqcup_{i : I}d_i.

Proof (PartialityPCFadequacy_lubs) of Lemma 47

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

The case when \sigma 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 \sigma \equiv \iota instead.

Recall that \bigsqcup_{i : I} d_i is given by \pa*{\squash*{\sum_{i : I} \operatorname{\mathsf{isdefined}}(d_i)}, \varphi}, where \varphi is the factorisation of

\sum_{i : I} \operatorname{\mathsf{isdefined}}(d_i) \to \operatorname{\mathcal L}(\mathsf{N}), \quad (i, p_i) \mapsto \operatorname{\mathsf{value}}(d_i)(p_i)

through \squash*{\sum_{i : I} \operatorname{\mathsf{isdefined}}(d_i)}.

We are tasked with proving that t \mathbin{\triangleright}^\ast \underline{\varphi (p)} for every p : \operatorname{\mathsf{isdefined}}\pa*{\bigsqcup_{i : I}d_i}. So assume that p : \squash*{\sum_{i : I}\operatorname{\mathsf{isdefined}}(d_i)}. Since we are trying to prove a proposition (as \mathbin{\triangleright}^\ast is proposition-valued), we may actually assume that we have (j,p_{j}) : \sum_{i : I}\operatorname{\mathsf{isdefined}}(d_i). By definition of \varphi we have: \varphi (p) = \operatorname{\mathsf{value}}(d_{j})(p_{j}) and by assumption we know that t \mathbin{\triangleright}^\ast \underline{\operatorname{\mathsf{value}} (d_{j}) (p_{j})}, so we are done.

Lemma

Lemma 48

VX72

For every PCF type \sigma, we have \operatorname{\mathsf{fix}}_\sigma R_{(\sigma \Rightarrow \sigma)\Rightarrow \sigma} \densem{\operatorname{\mathsf{fix}}_\sigma}.

Proof (PartialityPCFadequacy_fixp) of Lemma 48

Let t be a PCF term of type \sigma\Rightarrow\sigma and let f : \densem{\sigma\Rightarrow\sigma} such that t R_{\sigma\Rightarrow\sigma} f. We are to prove that \operatorname{\mathsf{fix}} t R_\sigma \mu(f).

By definition of \mu and the previous lemma, it suffices to prove that \operatorname{\mathsf{fix}} t R_\sigma f^n(\bot) where \bot is the least element of \densem{\sigma} for every natural number n. We do so by induction on n.

The base case is an application of Lemma 46.

Now suppose that \operatorname{\mathsf{fix}} t R_\sigma f^m(\bot). Then, using t R_{\sigma\Rightarrow\sigma} f, we find: t(\operatorname{\mathsf{fix}} t) R_\sigma f(f^m(\bot)). Hence, by Lemma 44, we obtain the desired \operatorname{\mathsf{fix}} t R_\sigma f^{m+1}(\bot), completing our proof by induction.

Lemma

Lemma 49 (Fundamental Theorem)

835R

For every PCF term t of type \sigma, we have t R_\sigma \densem{t}.

Used by Proof
Proof (PartialityPCFadequacy_allterms) of Lemma 49

The proof is by induction on t. The base cases are taken care of by Lemma 45 and the previous lemma. For the inductive step, suppose t is a PCF term of type \sigma\Rightarrow\tau. By induction hypothesis, ts R_\tau \densem{ts} for every PCF term s of type \sigma, but \densem{ts} \equiv \densem{t}\densem{s}, so we are done.

Proof

Proof (Proof of computational adequacy (PartialityPCFadequacy, PartialityPCFadequacy_alt, PartialityPCFalt_adequacy))

E09E

Take \sigma to be the base type \iota in Lemma 49.

Definition

Definition 50

O96Y

A proposition Q is semidecidable if it is equivalent to \exists_{n_1 : \mathsf{N}}\cdots\exists_{n_k : \mathsf{N}}P(n_1,\dots,n_k) where k is some natural number and P : \mathsf{N}^k \to \Omega is a proposition-valued family such that P(m_1,\dots,m_k) is decidable for every (m_1,\dots,m_k) : \mathsf{N}^k.

Used by Theorem 53
Lemma

Lemma 51

ZSX4

Let t be a PCF term of type \iota. We have the following logical equivalences

\operatorname{\mathsf{isdefined}}(\densem{t}) \enspace\longleftrightarrow\enspace \sum_{n : \mathsf{N}} t \mathbin{\triangleright}^\ast {\underline{n}} \enspace\longleftrightarrow\enspace \squash*{\sum_{n : \mathsf{N}} t \mathbin{\triangleright}^\ast \underline {n}}.
Used by Proof
Proof (PartialityPCFchar_pcf_propositions) of Lemma 51

We start by proving the first logical equivalence. The second then follows from the fact that \operatorname{\mathsf{isdefined}}(\densem{t}) is a proposition. Suppose p is of type \operatorname{\mathsf{isdefined}}(\densem{t}). By computational adequacy, we find that t \mathbin{\triangleright}^\ast {\underline {\operatorname{\mathsf{value}} (\densem{t}) (p)}}, so we are done.

Conversely, suppose that we are given a natural number n such that t \mathbin{\triangleright}^\ast \underline n. Soundness and Proposition 40 then yield \densem{t} = \eta(n). Now \star : \operatorname{\mathsf{isdefined}}(\eta(n)), so we may transport along the equality to get an element of \operatorname{\mathsf{isdefined}}(\densem{t}).

Lemma

Lemma 52

L34S

For every PCF term t of type \iota, we have:

\operatorname{\mathsf{isdefined}}\pa*{\densem{t}} \longleftrightarrow \exists_{n : \mathsf{N}}\exists_{k : \mathsf{N}} t \mathbin{\triangleright}^k {\underline n}.
Proof (PartialityPCFchar_pcf_propositions’) of Lemma 52

This follows from Lemma 51 and Lemma 57.

Theorem

Theorem (Theorem 61)

IXF5

Let R be relation on a type X. If

  1. X has decidable equality;

  2. R is single-valued;

  3. \sum_{y : X} x R y is decidable for every x : X;

then, the k-step reflexive transitive closure R^k of R is decidable for every natural number k.

Theorem

Theorem 53

ASNO

The propositions that arise from PCF terms t of type \iota are all semidecidable, as witnessed by the following logical equivalence:

\operatorname{\mathsf{isdefined}}(\densem{t}) \longleftrightarrow \exists_{n : \mathsf{N}} \exists_{k : \mathsf{N}}\, t \mathbin{\triangleright}^k \underline n

and the decidability of t \mathbin{\triangleright}^k \underline n.

Definition

Definition 54 (FoundationsSetshrel)

J7GE

A relation on X is a term of type X \to X \to \Omega.

Definition

Definition 55 (MoreFoundationsClosureOfHrelrefltransclos_step, MoreFoundationsClosureOfHrelrefltransclos_step_hrel)

MMBW

Let R be a relation on a type X. We wish to define the k-step reflexive transitive closure of R. As in Definition 35, we want this to be proposition-valued again. Therefore, we proceed as follows. For any natural number k, define x R_{k} y by induction on k:

  1. x R_{0}y \vcentcolon\mspace{-1.2mu}\equiv x = y;

  2. x R_{k+1}z \vcentcolon\mspace{-1.2mu}\equiv \sum_{y : X} x R y \times y R_{k} z.

The k-step reflexive transitive closure R^k of R is now defined as the relation on X given by {x R^k y \vcentcolon\mspace{-1.2mu}\equiv \squash{ x R_k y}}.

Lemma

Lemma 56

VBTK

Let R be a relation on X. Recall the untruncated reflexive transitive closure R_\ast from Definition 35. We have a logical equivalence for every x,y in X:

x R_\ast y \longleftrightarrow \sum_{k : \mathsf{N}} x R_{k} y.
Proof (Proof (MoreFoundationsClosureOfHrelstepleftequiv, MoreFoundationsClosureOfHrelleft_regular_equiv)) of Lemma 56

Define x R' y inductively by:

\begin{alignedat}{2} &\mathsf{refl'} &&: \prod_{x : X} x R' x; \\ &\mathsf{left} &&: \prod_{x y z : X} x R y \to y R' z \to x R' z. \end{alignedat}

It is not hard to verify that R' is reflexive, transitive and that it extends R. Using this, one shows that x R' y and x R_\ast y are logically equivalent for every x,y : X. Now one easily proves \prod_{k : \mathsf{N}} (x R_k y \to x R' y) by induction on k. This yields \pa*{\sum_{k : \mathsf{N}} x R_k y} \to x R' y. The converse is also easily established. Thus, x R' y and \sum_{k : \mathsf{N}} x R_k y are logically equivalent, finishing the proof.

Lemma

Lemma 57

GKTA

Let R be a relation on X. For every x,y : X, we have a logical equivalence:

x R^\ast y \longleftrightarrow \squash*{\sum_{k : \mathsf{N}} x R^k y}.
Used by Proof
Proof (Proof (MoreFoundationsClosureOfHrelstepleftequiv_hrel, MoreFoundationsClosureOfHrelleft_regular_equiv).) of Lemma 57

Let x and y be in X. By the previous lemma and functoriality of propositional truncation, we have

x R^\ast y \equiv \squash{x R_\ast y} \longleftrightarrow \squash*{\sum_{k : \mathsf{N}} x R_k y}.

But the latter is equivalent to \squash*{\sum_{k : \mathsf{N}} \squash*{x R_k y}} \equiv \squash*{\sum_{k : \mathsf{N}} x R^k y} by [HoTTbook, Theorem 7.3.9]. This may also be proved directly, as done in the formalisation.

Definition

Definition 58 (MoreFoundationsClosureOfHrelis_singlevalued)

6Y2V

A relation R on X is said to be single-valued if for every x,y,z : X with x R y and x R z we have y = z.

Used by Theorem 61, Proof
Lemma

Lemma 60

1AS2

Let X be a type. If X is decidable, then so is \squash{X}.

Uses Definition 59 · Used by Proof
Proof (FoundationsPropositionsdecidable_ishinh) of Lemma 60

Suppose that X is decidable. Then there are two cases to consider. Either we have x : X or \lnot X. If we have x : X, then obviously we have |x| : \squash{X}.

So suppose that \lnot X. We claim that \lnot\squash{X}. Assuming \squash{X}, we must find a term of type \mathsf{0}. But \mathsf{0} is a proposition, so we may actually assume that we have x : X. Using \lnot X, we then obtain \mathsf{0}, as desired.

Theorem

Theorem 61

ZP95

Let R be relation on a type X. If

  1. X has decidable equality;

  2. R is single-valued;

  3. \sum_{y : X} x R y is decidable for every x : X;

then, the k-step reflexive transitive closure R^k of R is decidable for every natural number k.

Proof (MoreFoundationsClosureOfHreldecidable_step) of Theorem 61

Suppose X and R satisfy conditions (?)–(?). By Lemma 60, it suffices to prove that the untruncated version of R^k, that is R_k, is decidable by induction on k.

For the base case, let x and y be elements of X. We need to decide x R_0 y. By definition this means deciding x = y, which we can, since X is assumed to have decidable equality.

Now suppose x and z are elements of X and that a R_k b is decidable for every a,b : X. We need to show that xR_{k+1}z is decidable. By definition this means that we must prove

\sum_{y : X} x R y \times y R_k z

to be decidable. By (?), we can decide \sum_{y : X}x R y. Obviously, if we have \lnot\sum_{y : X}x R y, then \lnot\eqref{toprovedec}. So assume that we have y : X such that x R y. By induction hypothesis, y R_k z is decidable. If we have y R_k z, then we get \eqref{toprovedec}. So suppose that \lnot y R_k z. We claim that \lnot\eqref{toprovedec}. For suppose \eqref{toprovedec}, then we obtain y' : X with x R y' and y' R_k z. But R is single-valued, so y = y' and hence, y R_k z, contradicting our assumption.

Definition

Definition 62 (MoreFoundationsWtypesindexedWtype)

WIEZ

Let A and I be types and let B be a type family over A. Suppose we have t : A \to I and s : \pa*{\sum_{a : A} B(a)} \to I. The indexed \mathsf W-type \mathsf{W}_{s,t} specified by s and t is the inductive type family over I generated by the following constructor:

\mathsf{indexedsup} : \prod_{a : A}\big(B(a) \to \mathsf{W}_{s,t}(s(a,b))\big) \to \mathsf{W}_{s,t}(t(a)).

We have the following induction principle for indexed \mathsf{W}-types. If E : \prod_{i : I}\pa*{\mathsf{W}_{s,t}(i) \to \mathcal U}, then to prove \prod_{i : I}\prod_{w : \mathsf{W}_{s,t}(i)} E(i,w), it suffices to show that for any a : A and f : \prod_{b:B(a)}\mathsf{W}_{s,t}(s(a,b)) satisfying E(s(a,b),f(b)) for every b : B(a) (the induction hypothesis), we have a term of type E(t(a),\mathsf{indexedsup}(a,f)).

Used by Proof
Example

Example 63

I0I8

In this example, we show that a fragment of the PCF terms can be encoded as an indexed \mathsf{W}-type. One could extend the encoding to capture all PCF terms, but we do not spell out the tedious details here, as a fragment suffices to get the idea across.

The type family \mathsf{T} is inductively defined as:

  1. \mathsf{zero} is a term of type \iota;

  2. \mathsf{succ} is a term of type \iota \Rightarrow \iota;

  3. for every PCF type \sigma and \tau, we have a term \mathsf{app}_{\sigma,\tau} of type (\sigma \Rightarrow \tau) \Rightarrow \sigma \Rightarrow \tau.

We can encode \mathsf{T} as an indexed \mathsf{W}-type. Let us write \mathsf{2} for \mathsf{1} + \mathsf{1} and 0_{\mathsf{2}} and 1_{\mathsf{2}} for its elements. Take I to be the type of PCF types and put A \vcentcolon\mspace{-1.2mu}\equiv \mathsf{2} + (I \times I). Define B : A \to \mathcal U by

B(\operatorname{\mathsf{inl}}(0_{\mathsf{2}})) \vcentcolon\mspace{-1.2mu}\equiv B(\operatorname{\mathsf{inl}}(1_{\mathsf{2}})) \vcentcolon\mspace{-1.2mu}\equiv \mathsf{0}\quad\text{and}\quad B(\operatorname{\mathsf{inr}}(\sigma,\tau)) \vcentcolon\mspace{-1.2mu}\equiv \mathsf{2}.

Finally, define t by

t(\operatorname{\mathsf{inl}}(0_{\mathsf{2}})) \vcentcolon\mspace{-1.2mu}\equiv \iota;\quad t(\operatorname{\mathsf{inl}}(1_{\mathsf{2}})) \vcentcolon\mspace{-1.2mu}\equiv \iota \Rightarrow \iota;\quad \text{and}\quad t(\operatorname{\mathsf{inr}}(\sigma,\tau)) \vcentcolon\mspace{-1.2mu}\equiv \tau;

and s by

s(\operatorname{\mathsf{inr}}(\sigma,\tau),0_{\mathsf{2}}) \vcentcolon\mspace{-1.2mu}\equiv \sigma \Rightarrow \tau;\quad\text{and}\quad s(\operatorname{\mathsf{inr}}(\sigma,\tau),1_{\mathsf{2}}) \vcentcolon\mspace{-1.2mu}\equiv \sigma;

on the other elements s is defined as the unique function from \mathsf{0}.

One can check that given a PCF type \sigma : I, there is a type equivalence T(\sigma) \simeq W_{s,t}(\sigma).

Uses Definition 30 · Used by Proof
Definition

Definition 64 (WeaklyCompactTypes in , MoreFoundationsWtypespicompact)

PNSP

A type X is called \Pi-compact when every type family Y over X satisfies: if Y(x) is decidable for every x : X, then so is the dependent product \prod_{x : X} Y(x).

Example

Example 65 (MoreFoundationsWtypespicompact_empty, MoreFoundationsWtypespicompact_unit)

FB87

The empty type \mathsf{0} is vacuously \Pi-compact. The unit type \mathsf{1} is also easily seen to be \Pi-compact. There are also interesting examples of infinite types that are \Pi-compact, such as \mathsf{N}_{\infty}, the one-point compactification of the natural numbers [TypeTopology, WeaklyCompactTypes].

Used by Proof
Theorem

Theorem 66

FT0K

Let A and I be types and B a type family over A. Suppose t : A \to I and s : \pa*{\sum_{a : A}B(a)} \to I. If A has decidable equality, B(a) is \Pi-compact for every a : A and I is a set, then \mathsf{W}_{s,t}(i) has decidable equality for every i : I.

Uses Definition 59 · Used by Proof
Proof (Proof of Theorem 66 (using Theorem 73) (MoreFoundationsWtypesindexedWtype_deceq’)) of Theorem 66

Suppose that A has decidable equality and I is a set. We are to show that the fiber of t over i has decidable equality for every i : I. Let i : I be arbitrary. Suppose we have (a,p) and (a',p') in the fiber of t over i. Since A has decidable equality, we can decide whether a and a' are equal or not. If they are not, then certainly (a,p) \neq (a',p'). If they are, then we claim that the dependent pairs (a,p) and (a',p') are also equal. If e : a = a' is the supposed equality, then it suffices to show that \operatorname{\mathsf{transport}}^{\lambda x : A.t(x) = i}(e,p) = p', but both these terms are paths in I and I is a set, so they must be equal.

Lemma

Lemma 67

JR4Q

Let X and Y be logically equivalent types. The type X is decidable if and only if Y is decidable.

Uses Definition 59 · Used by Proof
Proof (MoreFoundationsWtypesdecidable_iff) of Lemma 67

Straightforward.

Definition

Definition 68

2LP5

A type X is called a retract of a type Y if there are maps s : X \to Y (the section) and r : Y \to X (the retraction) such that \prod_{x : X} r(s(x)) = x.

Used by Lemma 69, Proof, Proof
Lemma

Lemma 69

AUFC

Let X be a retract of Y. If Y has decidable equality, then so does X.

Proof (MoreFoundationsWtypesisdeceq_retract) of Lemma 69

Let r : Y \to X and s : X \to Y be respectively the retraction and section establishing X as a retract of Y. Let a,b : X. Since Y has decidable equality, we can consider two cases: r(a) = r(b) and r(a) \neq r(b). In the first case, we find a = s(r(a)) = s(r(b)) = b. In the second case, we immediately see that a \neq b. This finishes the proof.

Lemma

Lemma 70

OD1W

The \Pi-compact types are closed under binary coproducts.

Used by Proof
Proof (MoreFoundationsWtypespicompact_coprod) of Lemma 70

Let X and Y be \Pi-compact types. Suppose F is a type family over X + Y such that F(z) is decidable for every z : X + Y. We must show that \prod_{z : X + Y}F(z) is decidable.

Define F_X : X \to \mathcal U by F_X(x) \vcentcolon\mspace{-1.2mu}\equiv F(\operatorname{\mathsf{inl}}(x)) and F_Y : Y \to\mathcal U as F_Y(y) \vcentcolon\mspace{-1.2mu}\equiv F(\operatorname{\mathsf{inr}}(y)). By our assumption on F, the types F_X(x) and F_Y(y) are decidable for every x : X and y : Y. Hence, since X and Y are assumed to be \Pi-compact, the dependent products \prod_{x : X}F_X(x) and \prod_{y : Y}F_Y(y) are decidable.

Finally, \prod_{z : X + Y}F(z) is logically equivalent to \prod_{x : X}F_X(x) \times \prod_{y : Y}F_Y(y). Since the product of two decidable types is again decidable, an application of Lemma 67 now finishes the proof.

Theorem

Theorem 71

WF4H

The PCF terms have decidable equality.

Proof of Theorem 71

As with Example 63, we only spell out the details for the fragment \mathsf{T}. Recall that \mathsf{T} may be encoded as a \mathsf{W}-type, indexed by the PCF types. Using Example 65 and Lemma 70, we see that B(a) is \Pi-compact for every a : A. Note that A has decidable equality if I does. So it remains to prove that I, the type of PCF types, has decidable equality.

This will be another application of Theorem 66. Define A' \vcentcolon\mspace{-1.2mu}\equiv \mathsf{2} and define B' : A' \to \mathcal U by B'(\operatorname{\mathsf{inl}}(\star)) \vcentcolon\mspace{-1.2mu}\equiv \mathsf{0} and B'(\operatorname{\mathsf{inr}}(\star)) \vcentcolon\mspace{-1.2mu}\equiv \mathsf{2}. Let t' and s' be the unique functions to \mathsf{1} from A' and \sum_{x : A'}B'(x), respectively. One quickly verifies that the type of PCF types is a retract of \mathsf{W}_{s',t'}(\star). Observe that B'(x) is \Pi-compact for every x : A' because of Example 65 and Lemma 70. Finally, \mathsf{1} and A' \equiv 2 clearly have decidable equality, so by Theorem 66 the type \mathsf{W}_{s',t'}(\star) has decidable equality. Thus, by Lemma 69, so do the PCF types.

Definition

Definition 72 (Definition 2.4.2 in , FoundationsPartAhfiber)

AWBN

Let f : X \to Y be a map. The fiber of f over a point y : Y is

\mathsf{fib}_f(y) \vcentcolon\mspace{-1.2mu}\equiv \sum_{x : X}(f(x) = y).
Theorem

Theorem 73 (Jasper Hugunin)

203R

Let A and I be types and B a type family over A. Suppose t : A \to I and s : \pa*{\sum_{a : A}B(a)} \to I. If B(a) is \Pi-compact for every a : A and the fiber of t over i has decidable equality for every i : I, then \mathsf{W}_{s,t}(i) also has decidable equality for every i : I.

Uses Definition 59 · Used by Proof
Proof (Proof of Theorem 73 (MoreFoundationsWtypesindexedWtype_deceq)) of Theorem 73

Let i : I and u,v : \mathsf{W}_{s,t}(i). Taking j \vcentcolon\mspace{-1.2mu}\equiv i and p \vcentcolon\mspace{-1.2mu}\equiv \mathsf{refl}_i in Lemma 79, we see that u = v is decidable, as desired.

Lemma

Lemma 74

K807

Let X be a type and let Y be a type family over it. If X is a set, then the right pair function is injective, in the following sense: if (x,y) = (x,y') as terms of \sum_{a : X}Y(a), then y = y'.

Used by Proof
Proof (MoreFoundationsWtypesdec_depeq) of Lemma 74

Suppose X is a set, x : X and y,y' : Y(x) with e : (x,y) = (x,y'). From e, we obtain e_1 : x = x and e_2 : \operatorname{\mathsf{transport}}^{Y}(e_1,y) = y'. Since X is a set, we must have that e_1 = \mathsf{refl}_{x}, so that from e_2 we obtain a term of type y \equiv \operatorname{\mathsf{transport}}^Y(\mathsf{refl}_{x},y) = y', as desired.

Definition

Definition 75 (MoreFoundationsWtypessubtrees)

VZGA

For each i : I, define

\mathsf{sub}_i : \mathsf{W}_{s,t} (i) \to \sum_{p:\mathsf{fib}_t(i)} \prod_{b : B(\operatorname{\mathsf{pr_1}}(p))}\mathsf{W}_{s,t}( s(\operatorname{\mathsf{pr_1}}(p),b))

by induction:

\mathsf{sub}_{t(a)}(\mathsf{indexedsup}(a,f)) \vcentcolon\mspace{-1.2mu}\equiv \pa*{\pa*{a,\mathsf{refl}_{t(a)}},f}.

For notational convenience, we will omit the subscript of \mathsf{sub}.

Lemma

Lemma 76

Z1HU

Let a : A and f,g : \prod_{b : B(a)} \mathsf{W}_{s,t}(s(a,b)). If the fiber of t over i has decidable equality for every i : I, then \mathsf{indexedsup}(a,f) = \mathsf{indexedsup}(a,g) implies f = g.

Uses Definition 59 · Used by Proof
Proof (MoreFoundationsWtypessubtrees_eq) of Lemma 76

Suppose \mathsf{indexesup}(a,f) = \mathsf{indexedsup}(a,g). Then

\pa*{\pa*{a,\mathsf{refl}_{t(a)}},f} \equiv \mathsf{sub}(\mathsf{indexedsup}(a,f)) = \mathsf{sub}(\mathsf{indexedsup}(a,g)) \equiv \pa*{\pa*{a,\mathsf{refl}_{t(a)}},g}.

As \mathsf{fib}_t(i) is decidable, it is a set by Hedberg’s Theorem [HoTTbook, Theorem 7.2.5]. Therefore f = g by Lemma 74.

Definition

Definition 77 (MoreFoundationsWtypesgetfib)

JJ6V

For every i : I, define a function \mathsf{getfib}_i : \mathsf{W}_{s,t}(i) \to \mathsf{fib}_t(i) inductively by

\mathsf{getfib}_{t(a)}(\mathsf{indexedsup}(a,f)) \vcentcolon\mspace{-1.2mu}\equiv (a,\mathsf{refl}_{t(a)}).

In future use, we omit the subscript of \mathsf{getfib}.

Lemma

Lemma 78

081L

Let i,j : I with a path p : i = j and w : \mathsf{W}_{s,t}(i). We have the following equality:

\mathsf{getfib}(\operatorname{\mathsf{transport}}^{\mathsf{W}_{s,t}}(p,w)) = (\operatorname{\mathsf{pr_1}}(\mathsf{getfib}(w)),\operatorname{\mathsf{pr_2}}(\mathsf{getfib}(w)) \mathbin{\bullet} p).
Used by Proof
Proof (MoreFoundationsWtypesgetfib_transport) of Lemma 78

By path induction on p.

Lemma

Lemma 79

658Z

Suppose that B(a) is \Pi-compact for every a :A and that the fiber of t over each i : I has decidable equality. For any i : I, u : \mathsf{W}_{s,t}(i), j : I, path p : i = j and v : \mathsf{W}_{s,t}(j), the type

\operatorname{\mathsf{transport}}^{\mathsf{W}_{s,t}}(p,u) = v

is decidable.

Uses Definition 59 · Used by Proof
Proof (MoreFoundationsWtypesindexedWtype_deceq_transport) of Lemma 79

Suppose i : I and u : \mathsf{W}_{s,t}(i). We proceed by induction on u and so we assume that u \equiv \mathsf{indexedsup}(a,f). The induction hypothesis reads:

\prod_{b : B(a)}\prod_{j' : I}\prod_{p' : s(a,b) = j'}\prod_{v' : \mathsf{W}_{s,t}(j')} (\operatorname{\mathsf{transport}}^{\mathsf{W}_{s,t}}(p',f(b))=v') \text{ is decidable }.

Suppose we have j : I with path p : t(a) = j and v : \mathsf{W}_{s,t}(j). By induction, we may assume that v \equiv \mathsf{indexedsup}(a',f'). We are tasked to show that

\operatorname{\mathsf{transport}}^{\mathsf{W}_{s,t}}(p, \mathsf{indexedsup}(a,f)) = \mathsf{indexedsup}(a',f')

is decidable, where p : t(a) = t(a').

By assumption the fiber of t over t(a') has decidable equality. Hence, we can decide if \pa*{a',\mathsf{refl}_{t(a')}} and (a,p) are equal or not. Suppose first that the pairs are not equal. We claim that in this case \lnot \eqref{indexedsupdec}. For suppose we had e : \eqref{indexedsupdec}, then

\mathsf{ap}_{\mathsf{getfib}}(e) : \mathsf{getfib}(\operatorname{\mathsf{transport}}^{\mathsf{W}_{s,t}}(p, \mathsf{indexedsup}(a,f))) = \mathsf{getfib}(\mathsf{indexedsup}(a',f')).

By definition, the right hand side is (a',\mathsf{refl}_{t(a')}). By Lemma 78, the left hand side is equal to (a, \mathsf{refl}_{t(a)} \mathbin{\bullet} p) which is in turn equal to (a,p), contradicting our assumption that \pa*{a',\mathsf{refl}_{t(a')}} and (a,p) were not equal.

Now suppose that \pa*{a',\mathsf{refl}_{t(a')}} = (a,p). From this, we obtain paths e_1 : a' = a and e_2~:~\operatorname{\mathsf{transport}}^{\lambda x : A.t(x) = t(a')}\pa*{e_1,\mathsf{refl}_{t(a')}} = p. By path induction, we may assume e_1 \equiv \mathsf{refl}_{a'}, so that from e_2 we obtain a path

\rho : \mathsf{refl}_{t(a')} = p.

Using this path, we see that the left hand side of (Proof) is equal to \mathsf{indexedsup}(a',f), so we are left to show that

\mathsf{indexedsup}(a',f) = \mathsf{indexedsup}(a',f')

is decidable.

By induction hypothesis (Proof) and the fact that a \equiv a', the type f(b) = f'(b) is decidable for every b : B(a'). Since B(a') is \Pi-compact, this implies that \prod_{b : B(a')}f(b) = f'(b) is decidable.

Suppose first that \prod_{b : B(a')}f(b) = f'(b). Function extensionality then yields f = f', so that \mathsf{indexedsup}(a',f) = \mathsf{indexedsup}(a',f').

On the other hand, suppose \lnot\prod_{b : B(a')}f(b) = f'(b). We claim that then, \mathsf{indexedsup}(a',f) cannot be equal to \mathsf{indexedsup}(a',f'). For suppose that \mathsf{indexedsup}(a',f) = \mathsf{indexedsup}(a',f'). Then Lemma 76 yields f = f', contradicting our assumption that \lnot\prod_{b : B(a)}f(b) = f'(b), and finishing the proof.

Theorem

Theorem 80

UJ48

The interpretation function \densem{-} from PCF types to dcpos with \bot can be typed as:

\densem{-} : \textup{PCF types} \to \mathcal U_0\text{-}\pa*{\mathsf{DCPO}_\bot}_{\mathcal U_1,\mathcal U_1}.
Proof of Theorem 80

If, in (?), we take \mathcal W to be \mathcal U_0 and \mathcal U,\mathcal U',\mathcal V,\mathcal V' all to be \mathcal U_1, then (?) reads:

(-)^{(-)} : \mathcal U_0\text{-}\pa*{\mathsf{DCPO}_\bot}_{\mathcal U_1,\mathcal U_1} \to \mathcal U_0\text{-}\pa*{\mathsf{DCPO}_\bot}_{\mathcal U_1,\mathcal U_1} \to \mathcal U_0\text{-}\pa*{\mathsf{DCPO}_\bot}_{\mathcal U_1,\mathcal U_1},

as desired.

Source and licence

The text on this page is from arXiv:1904.09810v4 by Tom de Jong, under the licence CC BY 4.0. The corpus made these changes: it read the items out of the LaTeX source, it expanded the macros of the paper, it put each proof after its statement, and it converted the text to HTML. The formulas are the TeX of the paper, and KaTeX renders them. A formula or a reference can look different from the PDF. The page is published under CC BY 4.0.

The record of each item is in analysis/objects/1904/1904.09810.jsonl.