Beruflich Dokumente
Kultur Dokumente
Robert Harper
Spring 2022
1 Introduction
The computability method, aka the theory of logical relations, gives meaning to proofs and pro-
grams by associating behavioral properties with types that ensures that well-typed terms enjoy the
associated properties. The “logical” part of the theory refers to the canonical choice of interpre-
tation of a compound type in terms of the interpretation of its constituent types. For example,
the interpretation of a product type is, in a sense dependent on the setting, the product of their
interpretations.1
The method works well for “pure” type theories, but is less effective in the presence of compu-
tational effects. Control effects expressible by continuations are managable by making the context
explicit (see Harper (2022a)). Partiality (the possibility of non-terminating expressions that have
no value) poses more significant challenges. For example, the language PCF introduces partiality
through a fixed point operation that allows for recursive definitions that might, when executed, loop
forever. The language FPC adds general recursive types (without any positivity restriction), with
which fixed points are definable, also demands partiality. Extending further to store effects raises
even further complications.
This note is concerned with partiality arising in its own right via a fixed point operation, and
with unrestricted recursive types, which give rise to such fixed points en passant. The method
of step-indexing is, at a high level, based on a “compactness” property of evaluation of complete
programs stating that the computation of an answer can only rely on some finite number of unrollings
of any recursive computation within it. That is, the same outcome can be achieved by bounding
recursive computations within it to some finite depth determined by the computation itself. Thus,
for example, the computation of a factorial of n requires only n recursive calls to itself, so that if
recursion is cut off at n or more steps, the same answer is returned as if it were not artificially
constrained.
Putting this idea into practice in the definition of logical relations requires indexing the relations
by the “steps remaining” to determine the outcome of a condition. With no steps remaining, the
computability conditions are trivially true, because it is not possible to refute it, because to do so
would require a computation step that cannot be taken. Otherwise the conditions are formulated
as usual, albeit up to the limitation of the remaining number of steps. The fundamental theorem
states that well-typed terms are well-behaved with respect to all finite numbers of steps, and that
is all that is required in any terminating computation.
∗
Copyright © Robert Harper. All Rights Reserved
1
See Harper (2022b) for a fuller development of this idea.
1
(n)
⟨⟩ ∈val 1 ⇐⇒ (true)
(n) (n) (n)
⟨V1 , V2 ⟩ ∈val A1 × A2 ⇐⇒ V1 ∈val A1 and V2 ∈val A2
(n) (k)
λ(x . M ) ∈val A1 ⇀ A2 ⇐⇒ ∀k < n if V1 ∈val A1 then [V1 /x]M ∈(k)
exp A2
(n−k)
M ∈(n) −→(k) V val then V ∈val
exp A ⇐⇒ ∀k < n if M 7− A
(n) (n)
γ ∈ctx Γ ⇐⇒ γ(x) ∈val Ax (for each Γ ⊢ x : Ax )
(n)
Γ ≫(n) M ∈ A ⇐⇒ if γ ∈ctx Γ then γ̂(M ) ∈(n)
exp A
Γ ≫ M ∈ A ⇐⇒ ∀n ≥ 0 Γ ≫(n) M ∈ A
Theorem 2. If Γ ⊢ M : A, then Γ ≫ M ∈ A.
Proof. By induction on typing, with each case being proved by induction on the stage n ≥ 0,
assuming the premises for all n ≥ 0 in each case. The base case is always trivial, and is omitted,
with the understanding that n > 0 unless specified otherwise. To lighten notation the substitution
instance γ̂(M ) of M by γ is written Mc whenever γ is clear from context.
For variables the result is immediate, by assumption. The product types are left as exericses.
(a) Γ ≫ M1 ∈ A2 ⇀ A, and
(b) Γ ≫ M2 ∈ A2 .
(n)
Suppose that n > 0, the case for n = 0 being trivial, and that γ ∈ctx Γ, with the intent to
show that ap(M c2 ) ∈(n)
c1 , M c c −→(k) V ,
exp A. To this end fix k < n and suppose that ap(M1 , M2 ) 7−
for some value V . By the definition of transition this sequence is structured as follows:
7−−→(k2 ) ap(V1 , V2 )
7−−→ [V1 , V2 /f, x]M
7−−→(k3 ) V
where
7 −→(k2 ) V2 , and
c2 −
(c) M
c1 ∈(n)
(a) M exp A2 ⇀ A, and
c2 ∈(n)
(b) M exp A2 ,
∀m ≥ 0 Γ, f : A1 ⇀ A2 , x : A1 ≫(m) M2 : A2 .
∀n ≥ 0 Γ ≫(n) F : A1 ⇀ A2 .
Proceed by induction on n. The base case is trivially true, by definition. Assume the statement
(n+1)
for n, and, towards proving it for n + 1, suppose that γ ∈ctx Γ; it suffices to show that
(n+1) (n+1)
Fb ∈exp A1 ⇀ A2 . Because Fb is a value, it suffices to show Fb ∈val A1 ⇀ A2 . Suppose
(k) (k)
that k < n + 1, and V1 ∈val A1 . To prove [F , V1 /f, x]M2 ∈exp A2 , proceed by cases according
b c
to whether k < n or k = n:
(n)
(a) Assume k < n. By downwards closure γ ∈ctx Γ, and hence by the inner inductive
(n) (n)
hypothesis Fb ∈exp A1 ⇀ A2 , which is to say Fb ∈val A1 ⇀ A2 . But then by the definition
c2 ∈(k)
of computability at partial function type, [Fb, V1 /f, x]M exp A2 .
(n)
c2 ∈exp A2 . By downwards
(b) Otherwise k = n, and the goal is to show that [Fb, V1 /f, x]M
(n) (n)
closure γ ∈ctx Γ and by the inner inductive hypothesis Fb ∈val A1 ⇀ A2 , and so by the
(n)
c2 ∈exp
outer inductive hypothesis, taking m = n, [Fb, V1 /f, x]M A2 , as desired.
Exercise 2. Prove the remaining cases of the fundamental theorem for nullary and binary product
types.
Exercise 3. Extend the fundamental theorem to nullary and binary sum types.
The intended inductive structure breaks down; step-indexing provides a solution (Dreyer et al.,
2011). Specifically, to account for recursive types add the following clause to the definition of the
logical relation given in Figure 1:
(n+1) (n)
foldX.A (V ) ∈val rec(X.A) ⇐⇒ V ∈val [rec(X.A)/X]A
With recursive types in hand there is of course no need to treat recursive functions as a special
construct, for one may define funA1 ,A2 (f, x.M ) in terms of recursive types as follows:
A1 ⇀rec A2 ≜ rec(X.X → A1 ⇀ A2 )
funA1 ,A2 (f, x.M ) ≜ foldX.X⇀A1 ⇀A2 (λA1 ⇀A2 (F . [λA1 (x . funap(F, x))/f ]M ))
funap(V, V1 ) ≜ ap(ap(unfold(V ), V ), V1 )
The type A1 ⇀rec A2 is used here to isolate recursively defined functions from the underlying partial
function type to make it easier to define in isolation. Equivalently, one could define A1 ⇀rec A2 to
be self(A1 ⇀ A2 ), the type of self-referential partial functions with the given domain and range. The
type self(A) is the recursive type rec(X.X ⇀ A), with introductory form self A (x.M ) and eliminatory
form unself(M ), as in PFPL.
(n) (k)
K ∈stk A ⇐⇒ ∀k ≤ n V ∈val A implies K ⊥ V
(k)
M ∈(n)
exp A ⇐⇒ ∀k ≤ n K ∈stk A implies K ⊥ M
Figure 2: Biorthogonal Step-Indexed Logical Predicate for Simple and Recursive Types
Exercise 5. Replay the verification that recursive functions inhabit the relation when defined as
above in terms of recursive types.
4 Bi-Orthogonal Step-Indexing
The concept of biorthogonality in logical relations, a re-formulation that makes use of a control stack
much as described in Harper (2016). Informally, a stack K may be considered to be “orthogonal” to
a term M in the sense that, when juxtaposed to form a machine state, they successfully compute
an answer: K ⊥ M iff K ▷ M 7−−→∗ α, where α is either yes or no. The terminology is suggested
by an analogy with linear algebra in which the formation of the machine state corresponds to an
“inner product” that evaluates to a “scalar”, the final outcome of a complete computation.3
The definitions given in Figure 1 may be re-formulated using stacks as in Figure 2. Computability
for values has much the same form as that given earlier, but the computability of expressions is
re-formulated using stacks, and the computability of stacks is as given in the figure. Put simply,
a computable expression is on that “behaves properly” on all stacks, and a computable stack is on
that “behaves properly” on all values, in both cases taking account of step-indexing.
Exercise 6. Formulate and prove the fundamental theorem for the logical predicates as defined in
Figure 2. Hint: Refer to the statics of control stacks as given in Harper (2016), extended with
recursive types for the typing of (closed) stacks.
References
Amal Ahmed. Step-indexed syntactic logical relations for recursive and quantified types. In Peter
Sestoft, editor, ESOP 2006, 2006.
Derek Dreyer, Amal Ahmed, and Lars Birkedal. Logical step-indexed logical relations *. Logical
Methods in Computer Science, 7:1–37, 2011. doi: 10.2168/LMCS-7. URL www.lmcs-online.org.
3
From this point of view the machine state might well be written in “bra-ket” notation as ⟨K | M ⟩.
Robert Harper. Continuations, aka contradictions, aka contexts, aka stacks. Unpublished lecture
note., February 2022a. URL https://www.cs.cmu.edu/~rwh/courses/atpl/pdfs/tlc-cont.
pdf.
Robert Harper. Tait computability. Unpublished lecture note., Spring 2022b. URL https://www.
cs.cmu.edu/~rwh/courses/atpl/pdfs/tait-comp.pdf.