Lectures onType Theory
Chapter 10
Chapter 10Core route

Relational Parametricity and Abstraction Theorems

Consider a closed term h:X.XX. At a closed type A, the specialization h[A] is an endomap of A. Nothing in its arrow type alone prevents a constant endomap. The universal quantifier is the obstruction: h must be the same program when A is replaced by any other type. Relational preservation makes “the same program” a calculation.

A unary property of terms at one type cannot compare a numeral with a state represented by a pair. Such a comparison needs a relation whose endpoints may be different types. It must be a relation rather than only the graph of a function: empty, singleton, and partial correspondences will all be used.

Here “type”, “term”, and “beta” refer to the Church-style System F of chapter 5; the language has no additional term former or reduction rule.

Relations between programs

The set-theoretic obstruction of theorem 5.40 concerned a denotational model in which types range over arbitrary sets and arrows denote all set-theoretic functions. The relational model instead relates typed syntax to typed syntax.

Assign to each type a binary relation between terms of its two endpoint instances. At AB, relate functions that send A-related arguments to B-related results; at X.A, quantify over every relation used for X. These clauses define the logical relation, a family of binary relations indexed by types, whose preservation is the central induction of the chapter.

Definition 6.1 — Closed terms modulo beta

For every closed formed System F type A, taken modulo alpha-equivalence, put Tm(A):={t;t:A}/=β. We write [t]A, or simply [t], for the beta-class of t. A relation from A to B is a subset R:ABmeaningRTm(A)×Tm(B). Write [a]R[b] for ([a],[b])R and EqA:={([a],[a])[a]Tm(A)}.

Here =β is restricted to pairs of terms already typed at A; it is therefore an equivalence relation on the displayed set. Subject reduction, proposition 5.14, additionally says that every forward reduct of such a term remains in that set. Syntax is a set—indeed it is countable—so the family, indexed by closed type pairs (A,B), of all subsets of Tm(A)×Tm(B) is one fixed set in the classical ZF metatheory fixed in chapter 5. This is the meta-level, as opposed to a construction expressed inside System F. Every relation used here is a subset of this fixed syntactic set, so Reynolds’ obstruction to full set-theoretic impredicativity does not apply.

Definition 6.2 — Arrow lifting and graphs

Given R:AB and S:CD, define [f](RS)[g]for every [a]R[b], one has [fa]S[gb]. Thus RS relates terms of types AC and BD. For a closed k:AB, its graph relation is [a]Gr(k)[b]ka=βb.

Relations need not have equal endpoint types. For example, {([trueF],[0]),([falseF],[1])}:BoolFNatF is a heterogeneous relation. It pairs observations across two encodings; it is neither an equality relation nor the graph of an endofunction.

Arrow lifting is the binary analogue of chapter 5’s candidate-arrow construction: both require an operation to send admissible inputs to admissible outputs. Here both inputs and outputs come in related pairs. Like the underlying type arrow, associates to the right.

These definitions use beta-classes, not chosen representatives. For example, if f=βf, a=βa, and [fa]S[gb], compatible reduction gives fa=βfa; changing g,b gives gb=βgb in the same way. Thus the same relation statement holds after changing any representative. Graph relations satisfy the following calculation.

Lemma 6.3 — Graph calculation

Let k:AB, f:AA, and g:BB be closed. Then [f](Gr(k)Gr(k))[g] if and only if, for every closed a:A, k(fa)=βg(ka).

Proof of Lemma 6.3 — Graph calculation

Proof. Suppose first that the lifted relation holds. Since [a]Gr(k)[ka], its defining implication gives [fa]Gr(k)[g(ka)], which is the displayed equation.

Conversely, let [a]Gr(k)[b], so ka=βb. The assumed equation and compatible beta conversion give k(fa)=βg(ka)=βgb. This says precisely that [fa]Gr(k)[gb]. ◻

Exercise 6.1

★★☆ Prove directly that arrow lifting and graph relations are independent of all chosen beta-class representatives. Then show that EqAEqB contains the beta-class of every closed f:AB paired with itself. Do not claim that this lifted relation is equal to EqAB: membership is all that the assertion asks you to prove.

Reading a type as a relation

A free type variable must now carry three pieces of data: a left type, a right type, and a relation between them.

Definition 6.4 — Relation environments

Let Δ=X1,,Xn be a formed type-variable context. A relation environment ϱ over Δ assigns to every XΔ a triple ϱ(X)=(AX,BX,RX),RX:AXBX, where AX and BX are closed formed types. Its two endpoint substitutions are ϱ0(X)=AX,ϱ1(X)=BX. We write “ϱ relates ϱ0 and ϱ1 over Δ”, abbreviated ϱ:ϱ0ϱ1 over Δ. The symbol ϱ is reserved here for relation environments; the row metavariable ρ of chapter 4 retains its earlier role.

Write ϵ for the unique relation environment over the empty type context. This symbol will not be used for the empty relation.

The endpoint substitutions are simultaneous, capture-avoiding type substitutions in the sense of convention 5.2. Bound type variables are first synchronized away from their finite ranges.

Definition 6.5 — Relational interpretation of types

If ΔA type and ϱ:ϱ0ϱ1 over Δ, choose a raw representative of A whose binders avoid dom(Δ) and the finite ranges of ϱ0,ϱ1. On that representative define a relation [[A]]ϱ:A[ϱ0]A[ϱ1] by structural recursion on A: [[X]]ϱ:=RXwhen ϱ(X)=(AX,BX,RX),[[AB]]ϱ:=[[A]]ϱ[[B]]ϱ. [p][[X.A]]ϱ[q]for all closed formed C,D and all S:CD,[p[C]][[A]]ϱ[X(C,D,S)][q[D]]. In the last clause, first alpha-rename X away from dom(Δ) and the finite ranges of the displayed endpoint substitutions. The double brackets carry a binary relation here, where in chapter 5 the same brackets carried a unary candidate set.

Lemma 10.6 — Relational alpha-equivariance

Suppose Δ,XA type and ϱ:ϱ0ϱ1 over Δ. Let Ydom(Δ) and suppose Y does not occur in the chosen raw representative of A. Let C,D be closed formed types with S:CD. Then [[A[Y/X]]]ϱ[Y(C,D,S)]=[[A]]ϱ[X(C,D,S)]. Consequently definition 6.5 is independent of the chosen alpha-equivalent representative of A.

Proof of Lemma 10.6 — Relational alpha-equivariance

Proof. Induct on the displayed representative of A. If A=X, both sides are S. The variable case A=ZX uses the unchanged Z-entry of ϱ; the freshness hypothesis excludes Z=Y. The arrow case applies the two induction hypotheses and then the arrow-lifting clause.

For A=Z.B, first alpha-rename Z away from {X,Y}dom(Δ) and the finite ranges of ϱ0,ϱ1. Take arbitrary closed formed E,F and a relation T:EF. The two universal clauses compare the body relations under, respectively, ϱ[Y(C,D,S)][Z(E,F,T)],ϱ[X(C,D,S)][Z(E,F,T)]. The Z-extension commutes with the X- and Y-extensions. Apply the induction hypothesis to B under ϱ[Z(E,F,T)]; it equates these body relations. Since E,F,T were arbitrary, the universal clauses are equal.

One alpha-conversion X.A=αY.A[Y/X] is therefore interpreted equally. The variable and arrow congruence cases preserve equality of interpretations, and the universal congruence case is the calculation just proved. Reflexivity, symmetry, and transitivity are inherited from equality of relations. Induction on the generation of alpha-equivalence gives independence from every representative. ◻

Definition 10.7 — Logical relation

The family A[[A]]ϱ just constructed from the variable, arrow, and universal clauses is the chapter’s logical relation. The phrase names the entire type-indexed family, not one chosen endpoint relation.

The tempting clause [p][[X.A]]ϱ[q]C,D,S.[p[C]][[A[C/X]]]ϱ[q[D]] is not structurally recursive: A[C/X] need not be a subexpression of X.A. The actual universal clause recurses at the proper syntactic subexpression A, under a larger environment. Its quantifiers range over the fixed meta-set described after definition 6.1. The result of the universal clause is itself one of the relations over which such clauses quantify. This impredicative use is Separation over that fixed set of term pairs; it does not construct a new universe of relations.

Lemma 6.6 — Compatibility with beta-classes

The arrow and universal clauses in definition 6.5 are independent of every chosen term representative. In particular, p=βpp[C]=βp[C] for every closed formed C.

Proof of Lemma 6.6 — Compatibility with beta-classes

Proof. Compatible beta reduction is closed under both term application and type application. Hence f=βf, a=βafa=βfa,p=βpp[C]=βp[C]. For the arrow clause, changing representatives therefore changes neither the premise class nor the conclusion class of its defining implication. For the universal clause, the second equation shows that, for every C,D,S, the two type applications determine the same beta-classes in the recursively defined body relation. Thus both clauses define relations on the quotient sets Tm(). ◻

Here is a complete expansion. Suppose ϱ(Y)=(E0,E1,T) and put P:=X.(XY)XY. Then [p][[P]]ϱ[q] means that for every S:CD, every [f](ST)[g],[a]S[b], one has [p[C]fa]T[q[D]gb]. The left endpoint of P is X.(XE0)XE0; the right endpoint replaces E0 by E1. Every symbol in the expanded assertion is therefore typed.

Exercise 6.2

★☆☆ Expand [[X.(YX)YX]]ϱ in the same fashion. Display the left and right endpoint types, then state the relation on the two function arguments and on the two Y-arguments.

The endpoint calculation and irrelevant-variable property are:

Lemma 6.7 — Endpoints and irrelevant variables

Let ΔA type.

  1. For every ϱ:ϱ0ϱ1 over Δ, [[A]]ϱ is a relation from Tm(A[ϱ0]) to Tm(A[ϱ1]).

  2. If ϱ:ϱ0ϱ1 over Δ and ϱ:ϱ0ϱ1 over Δ, and ϱ(X)=ϱ(X) as endpoint-and-relation triples for every Xftv(A), then [[A]]ϱ=[[A]]ϱ.

Proof of Lemma 6.7 — Endpoints and irrelevant variables

Proof. For item 1, induct on A. Variables use the corresponding environment entry, and arrows use the induction hypotheses at domain and codomain. For X.B, choose X fresh for both environments. Its endpoint is (X.B)[ϱi]=X.B[ϱi]. If C is closed, type application has endpoint ((X.B)[ϱi])[C]:B[ϱi][C/X]=B[ϱi,XC], where the equality is the simultaneous/single type-substitution composition equation of equation 5.2. The induction hypothesis types the body relation at these two endpoints.

For item 2, run a second structural induction on A. The variable case uses agreement on that variable; the arrow case applies the two induction hypotheses. At X.B, freshen X for both environments and extend each by the same arbitrary triple (C0,C1,S). The extended environments agree on ftv(B), so the induction hypothesis equates the body relations for every such triple. The universal clauses are therefore equal. ◻

Lemma 6.8 — Relational type substitution

Suppose Δ0,X,Δ1A type, Δ0B type, and ϱ:ϱ0ϱ1 over Δ0,Δ1. Put ϱ+:=ϱ[X(B[ϱ0],B[ϱ1],[[B]]ϱ)]. Then [[A[B/X]]]ϱ=[[A]]ϱ+. The two relations have endpoints A[B/X][ϱi]=A[ϱi,XB[ϱi]].

Proof of Lemma 6.8 — Relational type substitution

Proof. Induct on A. For A=X, both sides are [[B]]ϱ. For a variable YX, both sides are RY. For an arrow CD, the induction hypotheses give [[C[B/X]]]ϱ=[[C]]ϱ+ and [[D[B/X]]]ϱ=[[D]]ϱ+; substituting these equalities into the arrow clause equates the two arrow liftings.

The induction assertion is the displayed split-context statement, with an arbitrary suffix Δ1. Thus it remains available when a binder is added to that suffix. If we had proved only the case Δ1=, the universal case would require the unavailable instance Δ1=Y. For that case, write A=Y.C after choosing Y distinct from X and fresh for B, both endpoint substitutions, and the domains of the split context Δ0,Δ1. For arbitrary closed D0,D1 and S:D0D1, the extended judgment ϱ[Y(D0,D1,S)]:ϱ0[YD0]ϱ1[YD1] over Δ0,Δ1,Y is formed without overwriting an existing entry. The left-hand universal clause invokes [[C[B/X]]]ϱ[Y(D0,D1,S)]. The induction hypothesis turns this into [[C]]ϱ[Y(D0,D1,S)][X(B[ϱ0],B[ϱ1],[[B]]ϱ)]. Because Yftv(B), extending at Y does not change B[ϱi] or [[B]]ϱ. The two extensions commute, so this is exactly the body relation under ϱ+[Y(D0,D1,S)]:ϱ0+[YD0]ϱ1+[YD1] over Δ0,Δ1,Y, which is the right-hand universal clause. The endpoint equation is the type-substitution composition equation of equation 5.2. ◻

Exercise 6.3 — *

★★☆ Repeat the universal case when the original displayed binder occurs in the range of ϱ0, ϱ1, or in B. Choose a single fresh replacement, write both environment extensions after freshening, and identify the exact line at which Yftv(B) is used.

The abstraction theorem

An open term must be closed twice, once at each endpoint. The two closing substitutions are not assumed equal; their corresponding entries are assumed related.

Thus γ0[[Γ]]ϱγ1 is not an application of the type-relation notation to a context: it denotes the pointwise lifting of the already defined type relations to a pair of closing substitutions.

The theorem’s notation is now all defined: ϱ(X)=(AX,BX,RX)relation environment entryϱ0,ϱ1left and right endpoint substitutions[[A]]ϱrelation interpreting type Aγ0[[Γ]]ϱγ1related closing substitutionsγ0,γ1closing term substitutions at the endpoints[t], Tm(A)beta class of t and classes at AEqA, Gr(k), RSbeta identity, graph, and arrow lifting The suffix “over Δ” distinguishes a relation environment from a single relation R:AB.

For example, if Γ=x:X,f:XY, then related closing substitutions provide [γ0(x)]RX[γ1(x)],[γ0(f)](RXRY)[γ1(f)]. The second hypothesis can be applied to the first, yielding related interpretations of fx. The abstraction theorem says that every typing derivation is built from this same operation.

Theorem 6.10 — Abstraction theorem

Suppose Δ;Γt:A,ϱ:ϱ0ϱ1 over Δ,γ0[[Γ]]ϱγ1. Put ti:=t[ϱi][γi] for i=0,1. Then [t0][[A]]ϱ[t1]. Here the bracketed substitutions are simultaneous, capture-avoiding substitutions of the two sorts defined in convention 5.2.

Proof of Theorem 6.10 — Abstraction theorem

Proof. Induct on the Church-style typing derivation. There are five final-rule cases. The two rules for the universal type use lemma 6.8; the other three unfold the variable or arrow clause directly.

Variable. If the last rule reads x:BΓ, the conclusion is exactly the x:B component of γ0[[Γ]]ϱγ1.

Arrow introduction. Suppose the last premise is Δ;Γ,x:Bu:C. Choose the binder x fresh for the finite ranges of γ0 and γ1. To prove the arrow relation, take arbitrary closed a,b with [a][[B]]ϱ[b]. The extended substitutions γ0[xa],γ1[xb] are related at Γ,x:B. The induction hypothesis gives related bodies at [[C]]ϱ. Term beta gives, at each endpoint, (λx:B[ϱi].u[ϱi][γi])ai=βu[ϱi][γi[xai]], where a0=a and a1=b. This is the required arrow clause. The equality on the right uses the term/term substitution-composition equation of equation 5.2, after the displayed binder has been freshened.

Arrow elimination. The operator induction hypothesis gives a pair in [[B]]ϱ[[C]]ϱ; the argument induction hypothesis gives a pair in [[B]]ϱ. Applying the definition of arrow lifting gives the conclusion at [[C]]ϱ.

Universal introduction. Suppose the premise is Δ,X;Γu:B, with X fresh for Δ. Let closed C0,C1 and a relation S:C0C1 be arbitrary. Extend ϱ to ϱ:=ϱ[X(C0,C1,S)]. Every declaration type in Γ was formed under Δ, so it contains no free X. By lemma 6.7, the original γ0,γ1 remain related at Γ under ϱ. Apply the induction hypothesis to the premise. On endpoint i, the resulting body is beta-convertible to the type application of the substituted abstraction: ((ΛX.u)[ϱi][γi])[Ci]=βu[ϱi,XCi][γi]. Type and term substitution commute because every γi(x) is closed; this is the last equation of equation 5.2. Since C0,C1,S were arbitrary, the universal relation holds.

Universal elimination. Suppose the premise has type X.B and the supplied type is C. The operator induction hypothesis is a pair in [[X.B]]ϱ. Instantiate its defining universal quantifier with C[ϱ0],C[ϱ1],[[C]]ϱ. The resulting relation is [[B]]ϱ[X(C[ϱ0],C[ϱ1],[[C]]ϱ)]. By lemma 6.8, it is exactly [[B[C/X]]]ϱ, the relation required by the conclusion. For i=0,1, the endpoint term printed by the conclusion is the same alpha-class as the endpoint term just obtained: (u[C])[ϱi][γi]=α(u[ϱi])[C[ϱi]][γi](type-application substitution),=α(u[ϱi][γi])[C[ϱi]](closed-image composition). The two annotations invoke, respectively, the type-application substitution clause and the term/type substitution-composition equation of equation 5.2; the latter applies because every γi(x) is closed. The variable, arrow-introduction, arrow-elimination, universal-introduction, and universal-elimination cases exhaust the Church typing derivation. ◻

The universal-elimination case is short only because its substitution equation was proved first. Without that lemma one obtains related terms at a relation with the right ingredients but no established connection to the result type printed by F-All-E.

Exercise 6.4

★★☆ Let YZ and suppose Y,Z;q:X.(XY)XY. Reconstruct the universal-elimination case for q[Z], showing the two endpoint types of Z, the relation chosen for Z, and the final use of lemma 6.8.

Corollary 6.11 — Self-parametricity

If ;t:A, then [t][[A]]ϵ[t]. More generally, beta-equal closed terms may replace either occurrence.

Proof of Corollary 6.11 — Self-parametricity

Proof. Use theorem 6.10 with empty type and term environments. Replacement is legitimate because every relation was defined on beta-classes. ◻

Self-parametricity gives the relation needed to prove the opening equation without normalizing h.

Proposition 6.12 — The polymorphic endomap is pointwise the identity

If ;h:X.XX, then for every closed ;a:A, h[A]a=βa.

Proof of Proposition 6.12 — The polymorphic endomap is pointwise the identity

Proof. Apply self-parametricity and instantiate the universal clause with the singleton relation S:={([a],[a])},S:AA. The arrow clause sends the unique input pair to an output pair in S. Membership in this singleton says h[A]a=βa. ◻

Corollary 10.15 — Unary preservation

If ;h:X.XX, let P be any collection of beta-equivalence classes of closed terms of a closed type A. If [a]P, then [h[A]a]P.

Proof of Corollary 10.15 — Unary preservation

Proof. By proposition 6.12, h[A]a=βa, so the two terms determine the same beta class. Equivalently, instantiate self-parametricity with the diagonal relation on the classes in P. ◻

Thus unary preservation is obtained as a corollary of the binary theorem. A unary logical relation could prove it directly, but would not compare two different representations.

The empty relation is equally useful.

Corollary 6.13 — Parametric emptiness

The Church type VoidF:=X.X has no closed inhabitant.

Proof of Corollary 6.13 — Parametric emptiness

Proof. If v:X.X were closed, self-parametricity would allow the universal clause to be instantiated with the empty relation :BoolFBoolF. It would then assert [v[BoolF]][v[BoolF]], which is impossible. ◻

This is a second relative-consistency proof for pure Church-style System F in the classical ZF metatheory fixed in chapter 5. Unlike corollary 5.36, it does not use strong normalization: the contradiction follows from the syntactic abstraction theorem and the empty external relation alone.

The failure of unrestricted identity extension

It is tempting to expect [[A]]ϵ=EqA for every closed A. Equation (6.3) is called identity extension at A. Self-parametricity proves the inclusion from right to left. The reverse inclusion is false for beta equality. Before constructing the counterexample, proposition 6.14 proves the two observation instances used in proposition 6.15.

Proposition 6.14 — Identity extension at Church observations

For the closed encodings of definition 5.15, definition 5.18, [[BoolF]]ϵ=EqBoolF,[[NatF]]ϵ=EqNatF.

Proof of Proposition 6.14 — Identity extension at Church observations

Proof. The inclusions from right to left are corollary 6.11. For the converse, first suppose [u][[BoolF]]ϵ[v]. Normalize u and v. By proposition 5.39, each normal form is trueF or falseF. Unfolding the encoded Boolean gives [u][[BoolF]]ϵ[v]for every S:CD,[u[C]](S(SS))[v[D]]. Take C=D=BoolF and in the universal clause choose EqBoolF:BoolFBoolF and then choose the related branch pairs (trueF,trueF) and (falseF,falseF). The two resulting eliminations must be beta-equal. They reduce to the chosen normal forms of u and v, so those normal forms are the same boolean. Concretely, for either Boolean normal form b, b[BoolF]trueFfalseF=βb; the two eliminations therefore expose the normal forms being compared.

For naturals, normalize and use the same proposition to write the normal forms as m and n. In the universal clause choose EqNatF, the related zero pair, and the pair (succF,succF). The latter lies in EqNatFEqNatF by compatible beta conversion. The two iterator results are therefore beta-equal, but they reduce to m and n. For an endomap f, write f0a=a and fk+1a=f(fka). The required iterator computation follows by induction on the numeral spine: k[NatF]0succFβsuccFk0βk. The base case contracts the three encoding binders to 0; the successor case exposes one additional application of succF and uses the induction hypothesis on the remaining spine. Uniqueness of normal forms gives m=n. ◻

Proposition 6.15 — Failure of unrestricted beta identity extension

Equation (6.3) fails. In particular, λz:VoidF.trueFandλz:VoidF.falseF are related by [[VoidFBoolF]]ϵ but are not beta-equal.

Proof of Proposition 6.15 — Failure of unrestricted beta identity extension

Proof. By corollary 6.13, Tm(VoidF) is empty. Hence the domain relation [[VoidF]]ϵ has no pairs. The implication in the arrow lifting is therefore vacuous, so it relates the two displayed functions. They are distinct beta-normal forms, and theorem 5.38 shows that they are not beta-convertible. ◻

The missing principle is extensionality. For simple types alone, a first-order set interpretation may take arrows to be full function sets and prove EqSEqT=EqST using function extensionality: two set-theoretic functions are equal when they agree at every argument. Reynolds’ obstruction says that this simple model cannot be extended with System F’s impredicative universal type. A parametric semantic model may validate its own identity-extension lemma. The syntactic beta-quotient used here does not validate the general equation.

Exercise 6.5

★★☆ Verify every typing judgment in proposition 6.15. Then replace BoolF by NatF and construct two further distinct related beta-normal functions. Which single premise of the arrow relation is never tested?

Free theorems by choosing a relation

Consequences obtained by choosing a relation are called free theorems because the type alone yields them through the abstraction theorem; the polymorphic program’s text is never inspected.

The abstraction theorem is fixed; its applications differ mainly in the relation one chooses. We give two calculations in full.

Proposition 6.16 — Polymorphic application

If ;q:X.Y.(XY)XY, then for every closed f:AB and a:A, q[A][B]fa=βfa.

Proof of Proposition 6.16 — Polymorphic application

Proof. Self-parametricity permits two relation choices. At X, choose R:={([a],[a])},R:AA; at Y, choose S:={([fa],[fa])},S:BB. Thus the two universal clauses use equal endpoint types (A,A) and then (B,B); heterogeneous endpoints are available but not needed here. The sole premise in the definition of RS shows [f](RS)[f]. Applying the resulting arrow relation first to f and then to the unique R-pair puts ([q[A][B]fa],[q[A][B]fa]) in S. Membership in S is the claimed beta equation. ◻

The abstraction theorem also implies iterator naturality (theorem 6.17) without classifying the normal form of h.

Theorem 6.17 — Iterator naturality

Let h:X.(XX)XX,k:AB,f:AA,g:BB be closed. If k(fa)=βg(ka)for every closed a:A, then every closed a:A satisfies k(h[A]fa)=βh[B]g(ka).

Proof of Theorem 6.17 — Iterator naturality

Proof. By lemma 6.3, the hypothesis is exactly [f](Gr(k)Gr(k))[g]. Also [a]Gr(k)[ka]. Self-parametricity of h, instantiated at the heterogeneous relation Gr(k):AB, may therefore be read explicitly as [h[A]]((Gr(k)Gr(k))(Gr(k)Gr(k)))[h[B]]. Apply this relation first to f,g and then to a,ka. It yields [h[A]fa]Gr(k)[h[B]g(ka)], which unfolds to the desired equation. ◻

The normal-form argument proves this iterator equation by classifying every beta-normal inhabitant of the particular type, separating an eta-short case, and then inducting on an exponent. The abstraction theorem instead follows by one induction on the typing of an arbitrary System F term. Instantiating its relation variable with the graph relation records, in the relation itself, the invariant used by the normal-form proof.

When the chosen relation is Gr(k), the last calculation says that the operations commute with change of representation along k: it is the commuting-square property called naturality. No categorical definition is needed for the proof here; the two uses of arrow lifting are the square written elementwise.

Exercise 6.6

★★☆ Let b:BoolF and k:AB be closed. Use Gr(k) to derive k(b[A]a0a1)=βb[B](ka0)(ka1) for closed a0,a1:A. Write the two uses of arrow lifting rather than appealing to a slogan about naturality.

Exercise 6.7 — *

★★★ Fix a closed type A and let r:X.(AX)X be closed. Assuming identity extension at A, prove for every closed f:AB that r[B]f=βf(r[A](λx:A.x)). Use the graph of f and state exactly where the identity-extension hypothesis at A is needed. Explain why omitting that hypothesis would repeat the error exposed in proposition 6.15. You may first take A=NatF, for which proposition 6.14 proves the assumption, and then repeat the proof under the stated general hypothesis.

Representation independence

An abstract counter supplies an initial state, a step operation, and an observer. A client that works for every representation type has the Church type Client:=O.X.X(XX)(XO)O. The result type O is also quantified. This lets an application choose the exact observation relation it needs, without invoking general identity extension.

Theorem 6.18 — Counter representation independence

Let A,B,O0,O1 be closed types and let R:AB,S:O0O1. Suppose the following closed operations are related: [iA]R[iB],[sA](RR)[sB],[rA](RS)[rB]. Then every closed c:Client satisfies [c[O0][A]iAsArA]S[c[O1][B]iBsBrB]. If O0=O1=O and S=EqO, the two client results are beta-equal.

Proof of Theorem 6.18 — Counter representation independence

Proof. Apply self-parametricity of c. Instantiate its outer universal clause at O0,O1 with the relation S, and its inner universal clause at A,B with R. The remaining type is a chain of three arrows. Apply its relation successively as follows: [c[O0][A]](R(RR)(RS)S)[c[O1][B]],[c[O0][A]iA]((RR)(RS)S)[c[O1][B]iB],[c[O0][A]iAsA]((RS)S)[c[O1][B]iBsB],[c[O0][A]iAsArA]S[c[O1][B]iBsBrB]. The result is the asserted S-pair. When S is beta identity, membership is beta equality by definition. ◻

Now compare two concrete implementations. Put A:=NatF,B:=NatF×FBoolF. These are the hidden state types. Define their operations by iA:=zeroF,iB:=zeroF,falseFF,sA:=succF,sB:=λp:B.succF(fstF(p)),falseFF,rA:=λn:NatF.n,rB:=λp:B.fstF(p). The second representation stores a redundant boolean. Relate the states by [n]R[p]p=βn,falseFF. Then [iA]R[iB] by definition. If [n]R[p], the product beta laws give sBp=βsuccFn,falseFF, so [sAn]R[sBp]. The same hypothesis and the first projection beta law give rAn=definitionofrAn=(6.5)and×FβfstF(p)=definitionofrBrBp. Thus [sA](RR)[sB],[rA](REqNatF)[rB]. The theorem applies with O=NatF and S=EqNatF.

For a visible client, take c2:=ΛO.ΛX.λi:X.λs:XX.λr:XO.r(s(si)). With the first implementation, c2[NatF][A]iAsArAβ2. With the second, two applications of sB produce 2,falseFF, and the observer projects its first component: c2[NatF][B]iBsBrBβfstF(2,falseFF)β2. Representation independence says the same for every closed, well-typed client of (6.4), not merely for this example.

Where the proof stops

The interpretation is structural because types are finite syntax trees, and the relation-preservation induction is uncluttered because the language is pure and has no exceptional constants. Strong normalization entered in proposition 6.14, where canonical forms turned related Church observations into beta equality. Four nearby extensions break four different lines of this account.

  1. A hypothetical primitive typecase, with syntax such as typecase X of {CtrueF,_falseF, where _ is a wildcard matching every type other than the preceding case, could define d:X.BoolF whose operational observations at two distinct closed types C,D choose different branches. Keep, however, the beta quotient used by definition 6.5; do not silently enlarge beta equality with a typecase computation equation. Then d[C] and d[D] are distinct typecase-headed beta-normal forms. If one nevertheless tried to validate the same relational clauses, the universal clause could be instantiated with any R:CD—the empty relation always exists. Because the result type BoolF ignores X, it would require [d[C]][[BoolF]]ϵ[d[D]]. Unfold the encoded-Boolean relation, choose EqBoolF, and supply the related branch pairs (trueF,trueF) and (falseF,falseF). The resulting eliminations remain distinct typecase-headed beta-normal forms, so they are not related by beta identity. This is a direct beta-class counterexample; it neither infers a beta equation from the proposed operational observations nor invokes proposition 6.14. Thus a primitive typecase rule fails the universal case required by the abstraction theorem.

  2. Suppose a polymorphic constant fix:X.(XX)X is added, with specializations fix[A] and the unfolding root fix[A]ff(fix[A]f). For the empty relation R:AA, the two identity functions are vacuously related by RR, but their fixed points cannot be related by R. Relations for partial languages therefore require additional order-theoretic conditions; the present relations on terminating beta-classes contain no information about divergence or finite approximation.

  3. Mutable state makes the meaning of “related arguments” depend on related heaps before and after evaluation. A world records the heap locations and invariants currently assumed, and the relation must be indexed by that world; the present arrow clause contains no such index.

  4. For a recursive type μX.A, defining its relation by immediately recursing to A[μX.A/X] is not structural recursion on a smaller type. This is the same failure of a decreasing structural call that impredicativity caused in section 5.7. Recursive-type semantics replace the simple induction with a construction that controls each recursive unfolding.

These are not four counterexamples to parametricity. They identify the data a stronger logical relation must remember.

The fixed-point obstruction determines the missing closure conditions.

Definition 10.22 — Strict admissible relation

A pointed ω-cpo is a partial order A with a least element A and a least upper bound nan for every sequence with anAan+1. A function f:AA is continuous when it is monotone and f(nan)=nf(an) for every increasing ω-chain. For pointed ω-cpos A,B, a relation RA×B is strict when ARB. It is admissible when, for all increasing chains (an)n in A and (bn)n in B, (n. anRbn)(nan)R(nbn).

Proposition 10.23 — Least fixed points preserve strict admissible relations

Let A,B be pointed ω-cpos, let f:AA and g:BB be continuous, and let RA×B be strict and admissible. If aA. bB.aRbf(a)Rg(b), then, with μf:=n0fn(A),μg:=n0gn(B), one has (μf)R(μg). Each displayed supremum is the least fixed point of its function.

Proof of Proposition 10.23 — Least fixed points preserve strict admissible relations

Proof. Monotonicity and leastness of the bottoms make both approximation sequences increasing. Strictness supplies the base pair ARB. The preservation hypothesis supplies the induction step, so fn(A)Rgn(B) for every n. Admissibility now gives (μf)R(μg).

Continuity calculates f(μf)=f(nfn(A))=nfn+1(A)=μf; the last equality holds because deleting the least first approximation does not change the supremum. If f(a)Aa, induction gives fn(A)Aa for every n, hence μfAa. Thus μf is the least fixed point. The same argument with B,g proves the claim for μg. ◻

The orders, least elements, and chain limits in definition 10.22 belong to a domain semantics for partial computation; none is a hidden premise of the strongly normalizing calculus studied here.

Two established parametricity developments use richer formal interfaces. The following definitions delimit the comparison; no theorem from either interface is used in the abstraction proof above.

Definition 10.24 — Logic-of-parametricity comparison interface

The comparison logic extends typed System F terms with formulas generated by typed equality t=Au, relation atoms R(t,u), implication, and universal quantification over terms x:A, types X, and relations RA×B. A formula ϕ with distinguished variables x:A,y:B presents the definable relation (x:A,y:B).ϕ.

For a parameter-free type expression F(X) and a closed u:X.F(X), its parametricity schema is the internal formula Y.Z.RY×Z.u[Y]F[R]u[Z], where F[R] is the structural relation lifting. Its identity-extension principle is the internal equivalence pF[EqY]qp=F(Y)q. The schema is an axiom of that logic, and its equality includes the logic’s beta–eta equality. Neither assertion is a theorem about the external beta-quotient of definition 6.5.

Definition 10.25 — Effectful PE comparison interface

The PE calculus separates value types B,C from computation types A,B. With X a value-type variable and X a computation-type variable, its two mutually defined grammars are B::=XBCX.BXX.BAB,A::=BAX.AXX.A. Thus computation types form a subcollection of value types, while classifies computation homomorphisms. Terms are typed by ΓΔt:B, where Δ is empty or consists of one computation variable; a nonempty Δ requires B to be a computation type.

Its categorical models are constructed in IZF. The value category C is a full subcategory of sets closed under set-indexed products and equalizers; it has a set of objects representing every object up to isomorphism and is replete under set isomorphism. A functor U:AC weakly creates limits and reflects isomorphisms; every hom-set A(A,B) is an object of C, and a set of objects of A represents every object up to isomorphism. Admissible relation classes RC and RA contain diagonals and are closed under reindexing and set-indexed intersections, with RA(A,B)RC(UA,UB). For any monad T on C, its Eilenberg–Moore category with the forgetful functor and all categorical subobjects as the two relation classes supplies the standard example. Only under this syntax and model signature is its effectful relational interpretation claimed; it supplies no additional case of the pure theorem proved in theorem 6.10.

Finally distinguish three results that are often given the same name.

  • The syntactic abstraction theorem proved here says that every derivable Church-style System F term preserves every external relation on closed typed beta-classes.

  • A semantic parametric model equips every semantic element with a relational action. It may validate a genuine identity-extension lemma, but that requires the model’s extensional and coherence structure.

  • An internal parametric theory places relations inside a richer type theory rather than keeping them solely in the metatheory. It validates internal terms and equations unavailable in bare System F.

The first result is enough for the free theorems and representation theorem above; the latter two describe strictly richer settings.

Bibliographic notes

Reynolds introduced the relational abstraction method and used it to prove independence of representations in [Rey83]; those pages also expose the identity-extension difficulty. The theorem above is the syntactic version for definition 5.4.

Wadler derives program equations from polymorphic types in [Wad89], states the relational theorem in [Wad89], and discusses fixpoints in [Wad89].

The formula grammar, relation quantifiers, definable relations, parametricity schema, and identity-extension principle isolated in definition 10.24 are the bounded interface of Plotkin and Abadi’s logic [PA93]. Their equality and axioms belong to that internal logic; the chapter does not import their identity-extension result into its beta-quotient.

The value/computation syntax, categorical hypotheses, admissible-relation closures, and Eilenberg–Moore example in definition 10.25 are recorded from Møgelberg and Simpson [MS09]. Their theorem concerns the PE model signature stated there, not bare Church-style System F.

Suggested first pass.

None of these problems is a prerequisite for later chapters. Begin with exercise 6.8, exercise 6.9; the calculator in exercise 10.10 is an optional experimental check.

Exercise 6.8 — *

★★★ Replace B by NatF×FNatF and relate n to p when p=βn,nF. Construct the initial state, step, and observer for the paired representation. Verify all three hypotheses of theorem 6.18, then calculate c2 under both implementations.

Exercise 6.9

★★★ Write the failed abstraction-theorem case for fix[A] using the empty relation. Explain why requiring a nonempty relation blocks only that instance. Then take a closed a:A and the singleton R={([a],[a])}: show that the two identity functions are related by RR, whereas parametricity of fix would force fix[A](λx:A.x)=βa. Conclude that strictness, not mere nonemptiness, is the additional condition needed before admissibility can handle limits.

Exercise 10.10

★★★ Practical project.parametricity-calculator Implement finite beta-class relations together with identity, graph, and arrow lifting. Check the three obligations in the concrete counter calculation of theorem 6.18, and print the related output pair after each client application. The acceptance test must validate both counter representations through c2, validate the graph-lemma calculation for a supplied closed function, and reject the attempted fixed-point relation from exercise 6.9. Record explicitly which finite relation witnesses every successful check.

Search the book

Type to search the local edition.