Lectures onType Theory
ch:relational-parametricity: ch:relational-parametricity
appendix sectionsolutions

ch:relational-parametricity: ch:relational-parametricity

exercise 6.1.

Suppose f=βf, g=βg, a=βa, and b=βb. Compatible beta conversion gives fa=βfa,gb=βgb. Since R and S are relations on beta-classes, replacing either endpoint by these equal terms changes no membership assertion. Thus the implication defining RS is independent of the four representatives. For a graph, also let k=βk. Compatible conversion in both the function and argument positions gives ka=βbka=βb, so the represented graph is unchanged by replacing (k,a,b) with beta-equivalent representatives (k,a,b). Thus Gr(k) is well defined on the quotient in all three arguments.

Now let f:AB be closed and suppose [a]EqA[b]. By definition, a=βb; compatible conversion then gives fa=βfb. Hence [f](EqAEqB)[f]. This proves membership, not equality of the lifted relation with EqAB. An arrow relation may be vacuous when its domain has no closed terms.

Exercise 6.2.

Write ϱ(Y)=(E0,E1,T). The two endpoint types are X.(E0X)E0X,X.(E1X)E1X. For terms p and q at these endpoints, [p][[X.(YX)YX]]ϱ[q] means the following. For every pair of closed formed types C,D, every relation S:CD, every pair [f](TS)[g], and every pair [a]T[b], one has [p[C]fa]S[q[D]gb]. Thus the two function arguments are related by TS, while the two Y-arguments are related directly by T; applying the related functions turns the latter pair into an S-related result pair.

Exercise 6.3.

Let the universal subexpression originally be displayed as Y.C. Choose one name W fresh for X, B, C, the finite ranges of both ϱ0 and ϱ1, and the domain of the ambient split context. Replace the binder by the alpha-equal display W.C,C:=C[W/Y]. This single replacement handles at once an occurrence of the old name Y in B or in either endpoint substitution: none of those occurrences is captured, because the new binder is W.

For an arbitrary relational object Q=(D0,D1,S) at W, the extension is formed without overwriting an ambient entry and satisfies ϱW:(ϱW)0(ϱW)1 over Δ0,Δ1,W,ϱW:=ϱ[WQ]. The body relation on the left of the substitution equation is [[C[B/X]]]ϱW. The induction hypothesis changes it to (1)[[C]]ϱW[X(B[(ϱW)0],B[(ϱW)1],[[B]]ϱW)]. Freshness gives Wftv(B). Exactly here we use that fact: (2)B[(ϱW)i]=B[ϱi](i=0,1),[[B]]ϱW=[[B]]ϱ. The second equality is irrelevance applied to the same freshness fact. Substituting (2) into (1) makes its environment ϱ[WQ][X(B[ϱ0],B[ϱ1],[[B]]ϱ)]. Since WX and the X-entry is independent of W, the extensions commute. It is therefore ϱ[X(B[ϱ0],B[ϱ1],[[B]]ϱ)][WQ], which is precisely the environment used by the body of the right-hand universal clause. The endpoint substitutions commute by the same capture-avoiding freshening. Quantifying over all Q completes the universal case.

exercise 6.4.

Write ϱ(Y)=(Y0,Y1,RY),ϱ(Z)=(Z0,Z1,RZ). The premise induction hypothesis for q says [q[ϱ0]][[X.(XY)XY]]ϱ[q[ϱ1]]. In its universal clause choose endpoint types Z0,Z1 and the relation RZ=[[Z]]ϱ. It gives [q[ϱ0][Z0]][[(XY)XY]]ϱ[X(Z0,Z1,RZ)][q[ϱ1][Z1]]. For i=0,1, this is the endpoint term printed by the type-application conclusion because (q[Z])[ϱi]=α(q[ϱi])[Z[ϱi]]=α(q[ϱi])[Zi]. The first equality is the type-substitution clause for type application; the second is the definition of the endpoint substitution. The endpoint types are (Z0Y0)Z0Y0,(Z1Y1)Z1Y1. Finally, lemma 6.8 identifies the displayed middle relation with [[((XY)XY)[Z/X]]]ϱ, which is exactly the relation at the result type assigned to q[Z] by F-All-E.

exercise 6.5.

Formation gives VoidF type and BoolF type. Weakening the two closed boolean typings under z:VoidF and applying F-Arr-I yields λz:VoidF.trueF,λz:VoidF.falseF:VoidFBoolF. The domain relation has no pairs because Tm(VoidF)=. Consequently the universal condition in the lifted arrow relation has no instance to check. This is the single premise that is never tested. The codomain values need not be related at all.

Replacing the codomain gives, for example, λz:VoidF.zeroF,λz:VoidF.ΛX.λx:X.λs:XX.sx. They are again related vacuously at [[VoidFNatF]]ϵ. Both displayed functions are beta-normal: the first returns the zero Church numeral, while the second returns the one Church numeral written out in normal form. Their bodies are distinct beta-normal terms, so Church–Rosser separates their beta classes.

Exercise 6.6.

Let G=Gr(k) with G:AB. Self-parametricity of b, instantiated at G, gives [b[A]](GGG)[b[B]]. By definition of a graph, [a0]G[ka0],[a1]G[ka1]. The first use of arrow lifting applies the related Boolean eliminators to the first related branch pair and gives [b[A]a0](GG)[b[B](ka0)]. The second use applies these related functions to the second branch pair: [b[A]a0a1]G[b[B](ka0)(ka1)]. Unfolding G in the last line is exactly k(b[A]a0a1)=βb[B](ka0)(ka1). No classification of b as true or false was used.

Exercise 6.7.

Put G=Gr(f) with G:AB, and put idA=λx:A.x. Self-parametricity of r, instantiated at G, gives (1)[r[A]](([[A]]ϵG)G)[r[B]]. We claim (2)[idA]([[A]]ϵG)[f]. Indeed, suppose [a][[A]]ϵ[a]. Identity extension at A is used at this exact point to conclude a=βa. Compatible beta conversion then gives f(idAa)=βfa=βfa, which says [idAa]G[fa]. This proves (2).

Applying the arrow relation in (1) to (2) yields [r[A]idA]G[r[B]f]. The graph definition now reads f(r[A](λx:A.x))=βr[B]f, and symmetry gives the equation in the question. For A=NatF, the required identity extension is proposition 6.14.

Without identity extension, an input pair in [[A]]ϵ need not consist of beta-equal terms, so the implication needed for (2) need not hold. Replacing that missing step by an assertion of beta equality would repeat exactly the false unrestricted identity-extension claim refuted by proposition 6.15.

exercise 6.8.

Put B:=NatF×FNatF and define i:=zeroF,zeroFF,s:=λp:B.succF(fstF(p)),succF(sndF(p))F,r:=λp:B.fstF(p). Let [n]R[p] mean p=βn,nF. The initial states are related directly. If [n]R[p], the two projection beta laws give sp=βsuccFn,succFnF, so [succFn]R[sp]. The first projection also gives n=βrp, hence [succF](RR)[s],[λn:NatF.n](REqNatF)[r].

For c2, the first implementation reduces to 2. In the paired implementation, two steps reduce the state to 2,2F, and the observer projects the first component. Thus its result also reduces to 2, as predicted by theorem 6.18.

Exercise 6.9.

For the empty relation R= with R:AA, the implication defining RR has no input pair to test. Hence [idA](RR)[idA]. The abstraction-theorem case for a proposed fixA:(AA)A would have to conclude [fixAidA]R[fixAidA], which is impossible because R has no pairs.

Requiring relations to be nonempty removes this particular choice but not the problem. Fix a closed a:A and take R={([a],[a])}. If the sole input pair [a]R[a] is supplied to the two identity functions, their outputs are again [a]R[a]. Therefore [idA](RR)[idA]. Parametricity of fixA would force the pair of fixed-point results to lie in the singleton R, hence fixAidA=βa. But the least fixed point of the identity in a partial language is the designated divergent, or least, computation, not an arbitrary closed a. Thus nonemptiness alone admits relations that omit the least computations. One must at least require strictness, relating the two least computations; admissibility can then address closure under limits of finite approximations.

Practical route.

The finite relation calculator of exercise 10.10 is built in appendix F; its concrete witnesses and failed fixed-point mutation are recorded in appendix E.

Search the book

Type to search the local edition.