Lectures onType Theory
ch:computational-type-theory: ch:computational-type-theory
appendix sectionsolutions

ch:computational-type-theory: ch:computational-type-theory

Exercise 91.1.

The pair p is canonical as soon as its outer pair constructor is visible. Neither (λx.0)Ω nor 1+2 is evaluated to establish that fact. The first spread performs spread(p;x,y.x)(λx.0)Ω0. The first contraction inspects only the outer constructor of p; the second substitutes Ω into a body in which the bound variable does not occur. Thus no step evaluates Ω. The second spread performs spread(p;x,y.y)1+23. Here the left component, including its occurrence of Ω, is discarded. Only the selected right component is evaluated.

Exercise 91.2.

If S(m,n), then |nm|=|mn|=1, so S is symmetric. It is not transitive: S(0,1) and S(1,2) hold, whereas S(0,2) does not. Its PER domain would be {mZS(m,m)}={mZ0=1}=. The empty domain does not repair the failure of transitivity on arguments outside that domain; S is therefore not a PER.

Write T(m,n) when 2 divides mn. Reflexivity follows from 20, symmetry from 2d2d, and transitivity from closure of divisibility under addition: 2(mn),2(nk)2(mk). Hence T is an equivalence relation, in particular a PER, and T(m,m) holds for every integer. Its domain is all of Z.

Exercise 91.3.

Integer addition gives 2+13, while the canonical integer 3 evaluates to itself. Thus RZ(2+1,3) holds by (91.1). The witness axiom also evaluates to itself, so all three conjuncts of (91.4) hold. Therefore Memi(axiom;EqInt(2+1,3)). Evaluation is used first to compute the two endpoints and then to expose the canonical equality witness; integer equality is used to see that both endpoints compute to the same integer.

For EqInt(2,3), the endpoints are distinct canonical integers. Determinism rules out an integer z to which both evaluate, so RZ(2,3) is false. Equation (91.4) therefore assigns the empty member relation to this equality type, independently of the proposed witness. It has no member.

Exercise 91.4.

Apply (91.11) in each case: 11,1<0,so 1 is not a member;00,00,so 0 is a member;(λx.x)44,40,so (λx.x)4 is a member. Root contraction of Ω reproduces Ω, so it does not evaluate to any integer. The existential in (91.11) has no witness, and Ω is not a member. Divergence and convergence to a negative integer are distinct reasons for rejection.

Exercise 91.5.

Take the two raw representatives r:=0,s:=(λz.z)0. Both evaluate to 0 and are therefore equal in N. On the abstract two-element set {r,s}, this is the total PER. Write traws for literal equality of raw syntax. Define a total, representation-sensitive assignment on every closed representative t by B(t):={N,if traws,Int,otherwise. Thus B(r)=Int and B(s)=N. Every closed instance is a type, so a test that substitutes one representative at a time accepts it. Pointwise functionality also compares the equal substitutions [r/x] and [s/x] and would require TyEqi(Int,N). This is false: 1 belongs to the integer PER but not to the natural-number PER. The pair [r/x]x:N[s/x] therefore exposes the failure. Such source-spelling inspection is not a valid functional Nuprl family; the example isolates exactly what the two-substitution condition excludes.

Exercise 91.6.

At input n, successor has raw output n+1 in the set type Inc(n)={m:NEqN(m,n+1)}. The predicate is inhabited by axiom, but (91.5) relates the ambient members themselves and does not pair them with predicate evidence. At n=2, the result is therefore the program 2+13.

For the dependent pair m:NEqN(m,n+1), the dependent-pair specification uses (n+1,axiom). At n=2, beta contraction gives s20(2+1,axiom). This pair is canonical before either component is evaluated. Projecting its first component and demanding a natural numeral gives 2+13; the second projection gives axiom. Thus its observed components are 3 and axiom, although lazy evaluation does not reduce under the pair constructor merely to expose the outer value. Equation (91.3) retains both components, whereas (91.5) uses only inhabitance of the predicate relation. This accounts for the visible axiom in exactly one result.

Exercise 91.7.

Define the relation program E3(m,n):=EqInt((mn)mod3,0), where mod is signed integer remainder. At every old-system level i, equality formation derives Tyi(E3(m,n)). If equal integer representatives replace m,n, their computed values are unchanged, so both instances normalize to the same canonical equality type EqInt(r,0), where r is their common signed remainder. Thus TyEqi relates the two instances, proving the functionality clause. The condition Inhi(E3(m,n)) holds exactly when r=0, so it is equivalent to 3(mn), and the other admissibility clauses are 3(mm)=0,3(mn)3(nm)=(mn),3(mn), 3(nk)3(mk)=(mn)+(nk). Thus E3 is admissible at every old-system level.

As candidate endomaps Int/E3Int/E3, successor respects the quotient because (m+1)(n+1)=mn. Absolute value does not. The representatives 1 and 2 are equal modulo 3, since 1(2)=3, but their absolute values are 1 and 2, whose difference is not divisible by 3.

Exercise 91.8.

For function transitivity, assume RΠ(f,g) and RΠ(g,h) and take RA(a,c). The PER laws give RA(c,c). Instantiating the first function relation at (a,c) and the second at (c,c) gives RBa,c(fa,gc),RBc,c(gc,hc). The middle application is gc. Functionality identifies RBa,c with RBc,c, and transitivity in that common fiber relates fa to hc. Symmetry reverses the domain relation and then uses symmetry in the identified fiber.

For pairs, write the two premises as p(a,u),q(b,v),RA(a,b),RBa,b(u,v),q(b,v),r(c,w),RA(b,c),RBb,c(v,w). Determinism of evaluation gives (b,v)=(b,v), hence b=b and v=v. Base transitivity gives RA(a,c); functionality puts the two component relations in the fiber RBa,c; fiber transitivity then gives RBa,c(u,w).

The need for functionality is witnessed by a finite countermodel. Give {0,1} the total base PER and take four distinct results u,v,w,z. Let the nontrivial equivalence classes of the four fiber PERs be (0,0){u,w}(0,1){u,v},{w,z}(1,0){u,v,w}(1,1){u,v,z}. With f(0)=f(1)=u, g(0)=w, g(1)=v, h(0)=w, and h(1)=z, the four fiber checks show RΠ(f,g) and RΠ(g,h). But the (0,1) check for RΠ(f,h) asks that u and z lie in one class of the (0,1) fiber, which they do not. Likewise, (0,u) RΣ (1,v),(1,v) RΣ (1,z), but the first and last pairs are not related. Every displayed fiber is a PER; the failure is precisely that equal base inputs do not identify the fiber PERs.

Exercise 91.9.

Write σ=(a,u,g),τ=(a,u,g) for substitutions into the three hypotheses. They are equal exactly when the left-to-right construction yields MemEqi(a,a;N),MemEqi(u,u;EqN(a,a)),MemEqi(g,g;x:NN), together with the type equalities that make the second components legitimate. The first hypothesis is functional because N is closed. For the second, equality of a,a makes EqN(a,a) and EqN(a,a) equal types. The third type is closed, so it is functional independently of the prefix.

For the extract fn, (91.14) becomes TyEqi(N,N)andMemEqi(ga,ga;N). The last conjunct in the definition of equal substitutions is a function-PER relation; its instance at the related arguments a,a gives the member equality.

After replacing the last hypothesis by f:x:NEqN(x,n), functionality requires the additional cross-fiber obligation TyEqi(EqN(x,a),EqN(x,a)),whenever MemEqi(x,x;N) and MemEqi(a,a;N). An equal pair of substituted functions must in addition return equal axiom witnesses in those fibers. In fact the modified function type has no closed member: a member would have to inhabit EqN(x,a) for every natural x, including one whose numeral is different from the numeral denoted by a. The context may still be proved functional, but it admits no closed substitution for its final hypothesis.

Exercise 91.10.

Put A:=x:IntInt,sum(p):=spread(p;x,y.x+y),E(p,q):=EqInt(sum(p),sum(q)). These are old-system programs; in particular, the quotient is not used in the definition of E. Let p,qdom(RA). Sigma inversion gives evaluations of p and q to canonical pairs whose two components belong to the integer PER. Spread followed by addition therefore evaluates each sum to a canonical integer. The old equality-type generator then proves Tyi(E(p,q)) for every old-system level i.

It remains to check functionality for arbitrary program representatives, not only written pairs. Suppose RA(p,p) and RA(q,q). Sigma inversion and the integer PER identify the two component values of p,p and those of q,q. Hence sum(p) and sum(p) evaluate to the same integer, as do the two sums from q,q. The equality generator consequently gives TyEqi(E(p,q),E(p,q)). Moreover, Inhi(E(p,q))sum(p) and sum(q) evaluate to the same integer. Reflexivity, symmetry, and transitivity of integer equality establish admissibility clauses (2)–(4). Thus all four clauses hold on the entire Sigma-PER domain.

Three nontrivial equalities in A/E are (0,3)E(1,2),(1,5)E(4,0),(7,2)E(0,5).

Use the lazy programs at the signatures printed in the exercise: first:=λp.spread(p;x,y.x),total:=λp.spread(p;x,y.x+y),swap:=λp.spread(p;x,y.(y,x)). First projection does not respect E: the E-equal programs (0,3) and (1,2) produce the unequal integers 0 and 1. Sigma inversion shows that totalp evaluates to an integer whenever p is a member of A. It also shows that swapp evaluates to a pair of integer components, hence is a member of A and therefore of A/E by quotient reflexivity. Total respects E by its defining condition. Swapping respects E because a+b=c+db+a=d+c. If swapping instead had the unquotiented pair type as codomain, the same representatives would be a counterexample: (3,0) and (2,1) are not componentwise equal. The codomain equality is therefore part of the congruence claim.

Search the book

Type to search the local edition.