Lectures onType Theory
ch:trusted-kernels: ch:trusted-kernels
appendix sectionsolutions

ch:trusted-kernels: ch:trusted-kernels

Exercise 48.1.

The four rules are the direct Σ-counterparts of the annotated Π-rules:

Γτ0typeAΓ,x:Aτ1typeB
ΓSg(τ0;x.τ1)typex:AB
Pre-Sg
Γτ0typeAΓ,x:Aτ1typeBΓe0:AaΓe1:B[a/x]bΓCx:AB type
Γpair(τ0;x.τ1;e0;e1):C(a,b)
Pre-Pair
Γτ0typeAΓ,x:Aτ1typeBΓe:x:ABpΓCA type
Γfst(τ0;x.τ1;e):Cpr1(p)
Pre-Fst
Γτ0typeAΓ,x:Aτ1typeBΓe:x:ABpΓCB[pr1(p)/x] type
Γsnd(τ0;x.τ1;e):Cpr2(p)
Pre-Snd

The final equality premise in each term rule compares the supplied expected type C with the type computed from the annotations and elaborated subterms. No such premise belongs in Pre-Sg, whose output is itself a type.

Determinism is syntactic at the outermost constructor. The heads Sg, pair, fst, and snd are pairwise distinct and each appears in the conclusion of exactly one rule. Once that rule is selected, all recursive inputs and the result-equality query are fixed; therefore no second rule can elaborate the same constructor in the same mode.

Exercise 48.2.

Choose de Bruijn indices for bound variables and a Gödel coding of finite lists and finite rooted ordered trees. Because the signature is recursive, we can effectively code every operator and rule name and decide whether a number is such a code. Decode a natural number n as a candidate tree whose nodes carry:

  1. a rule name and one of the five judgment forms;

  2. codes for its context and constituent raw expressions; and

  3. an ordered list of immediate subtrees.

Let Der(n) hold precisely when a bottom-up check accepts this tree. At a node the checker verifies the rule’s arity, matches the conclusion and premises against the corresponding recursive rule schema, and checks all side conditions. Raw substitution, lifting of de Bruijn indices, equality of alpha-classes, list membership, and freshness are recursive operations, so Der is a decidable predicate. The accepted numbers, in numerical order, are an effective enumeration of all derivations, possibly with harmless duplicate derivations.

Suppose total decision procedures decTyEq and decTmEq are given. On a derivation d of ΓA type, define the decidable predicate PΓ,A(n){Der(n),root(n)=ΓAn type,decTyEq(A,An)=yes. The equality decider receives the input formation derivation d and the formation derivation decoded from n. Put nfTy(d):=μn.PΓ,A(n). Unbounded minimization of a recursive predicate is partial recursive. It is total on the stated domain because the code of d itself satisfies the predicate, by reflexivity.

For terms, let d derive Γa:A. Define QΓ,a,A(n) to say that n is a derivation of some Γbn:Bn, that the type decider accepts ABn, and that, after converting the decoded derivation of bn:Bn to bn:A, the term decider accepts abn:A. A positive answer from the type decider can be turned effectively into an equality derivation: dovetail the recursive enumeration until a derivation of ABn appears. This secondary search terminates exactly in the positive branch, after which the conversion tree is computably assembled. Thus Q is decidable, and nfTm(d):=μn.QΓ,a,A(n) is partial recursive and total on typing derivations, since the code of d itself is a witness.

It remains to verify the classifying properties. If AA, then by symmetry and transitivity a candidate An is equal to A exactly when it is equal to A. Hence PΓ,A and PΓ,A have the same accepted indices and their least indices coincide. Conversely, a common accepted least index provides AAnA, so AA. The term argument is identical after the classifier conversions: candidates for two judgmentally equal terms form the same set, and a common candidate gives the desired equality by symmetry and transitivity.

Finally suppose the same raw term has converted typings Γa:A,Γa:A,ΓAA type. If bn:Bn is admissible for the first search, then AABn, and conversion of the term equality abn:A gives abn:A. Thus it is admissible for the second search; the converse is symmetric. The candidate sets, and hence the least term index, are independent of which converted classifier was supplied. This completes every computability and totality obligation suppressed in the proposition.

Exercise 48.3.

Despite the exercise label, the requested extension is by coproducts. Add the type and universe-code rules

Γτ0typeAΓτ1typeB
Γτ0+τ1typeA+B
Ty-Sum

The universe-code rule is separate:

unUniv(Γ,C)=iΓτ0UiAΓτ1UiB
Γτ0+τ1CA+B
Chk-Code-Sum

The two introduction forms check against an expected coproduct:

unSum(Γ,C)=(A,B)ΓeAa
Γinl(e)Cinl(a)
Chk-Inl
unSum(Γ,C)=(A,B)ΓeBb
Γinr(e)Cinr(b)
Chk-Inr

Soundness of unSum includes a derivation CA+B; it is the implicit conversion that validates the returned constructor at the original expected type. Universal coherence says that these A,B agree with the components of every other coproduct presentation of C.

Retain an explicit motive in the surface eliminator and write it as ind+(z.τ;e,er;e). Its synthesis rule is

ΓeDsunSum(Γ,D)=(A,B)Γ,z:A+BτtypeCΓex:AC[inl(x)/z]fΓery:BC[inr(y)/z]g
Γind+(z.τ;e,er;e)C[s/z]ind+(f,g,s)
Syn-SumInd

For termination, the head constructor chooses one rule. Every recursive query is on a proper subexpression: the summands, injected term, scrutinee, motive, or one of the two branches. Calls to unSum and unUniv are total by hypothesis, and all substitutions only construct expected types. Hence the same lexicographic (mode, expression-size) argument as for the original rules terminates.

For soundness of Syn-SumInd, the induction hypotheses give Γs:D,Γ,z:A+BC type,Γf:x:AC[inl(x)/z],Γg:y:BC[inr(y)/z]. Soundness of unSum gives DA+B, so conversion yields s:A+B. The primitive coproduct eliminator then derives Γind+(f,g,s):C[s/z], which is exactly the synthesized output judgment. No unstated inversion of D is used; all such information is supplied by the coherent unSum call.

Exercise 48.4.

Put Γ:=, A:=N, a:=0, τ:=N, and e:=0. Then ΓτtypeA and ΓeAa are the two base rules. Use the annotated eliminand q:=(refl(e):Idτ(e,e)). Rule Syn-Ann first checks Idτ(e,e) as a type. Its three queries are ΓτtypeA,ΓeAa,ΓeAa, followed by Ty-Id. It then checks refl(e) at the resulting core type. Here unId returns (A,a,a); the single recursive query checks e against A and returns a, and the two conversion tests aa:A are reflexive. Thus ΓqIdA(a,a)refla.

Put Δ:=Γ,x:A,y:A,p:IdA(x,y). Rule Ty-N elaborates τ to A in every displayed context, so Ty-Id checks the surface motive Idτ(x,y) by ΔτtypeA,ΔxAx,ΔyAy. It returns C(x,y,p):=IdA(x,y). After substituting x=z, y=z, and p=reflz, the required branch type is IdA(z,z). A second use of Chk-Refl gives Γ,z:Arefl(z)IdA(z,z)reflz. Its queries are unId(Γ,z:A,IdA(z,z))=(A,z,z),Γ,z:AzAz, followed by the two reflexive conversion tests zz:A. Thus the branch call has no suppressed algorithmic premise. All premises of Syn-J are now present. With τC(x,y,p):=Idτ(x,y) and c(z):=reflz, its output is ΓJ(x.y.p.τC;z.refl(z);q)IdA(a,a)JA;a;a(x.y.p.C;z.c;refla). The annotation is essential: reflexivity is an introduction and therefore does not synthesize by itself.

Exercise 48.5.

Fix a:A and define SingA(a):=x:AEqA(x,a). Its canonical introduction and underlying-value projection are singa:=(a,refla):SingA(a),out(u):=pr1(u):A. For arbitrary u:SingA(a), the second projection has type pr2(u):EqA(out(u),a). One use of Eq-Reflect therefore gives the defining judgmental equality out(u)a:A.

For eta, Σ-eta first gives u(pr1(u),pr2(u)). The defining equality compares the first components pr1(u)a. Rule Eq-Uniq gives pr2(u)refl:EqA(pr1(u),a), where the reflexivity classifier is converted along the equality of first components. Dependent pair congruence now yields (pr1(u),pr2(u))(a,refla). Composing with Σ-eta proves usinga:SingA(a). Thus the encoding has the expected point, projection equation, and judgmental singleton eta law.

Exercise 48.6.

After the first two declarations, let a:=suc(suc(0)). The defined context contains D(c)=(N,a),D(p)=(IdN(a,a),refla). In the third declared type, both occurrences of c elaborate by Syn-Var-Def to a, so the type elaborates to IdN(a,a). Its body refl(c) checks at this type: the endpoint elaborates to a, and Chk-Refl returns refla. Hence the updated map stores D(q)=(IdN(a,a),refla). If a recursive query is made under a fresh local declaration y:B, the entry for c does not become a variable. It returns the weakening ay:N in the enlarged context; similarly the entries for p and q return the weakened term reflay.

Exercise 48.12.

The hypotheses eK and eS are needed only for the two generating steps. Applying them to encoded arguments produces terms of the appropriate extensional equality types, and Eq-Reflect turns those terms into the judgmental equations encoding SK-K and SK-S.

Everything used to close those equations is already built into judgmental equality. If the induction derivation of tu ends in reflexivity, use term-equality reflexivity on t:X. If it ends in symmetry or transitivity, apply the corresponding structural rule to the induction hypothesis or hypotheses. In the application case, the two induction hypotheses are combined by congruence of the context variable app:XXX, yielding tv=apptvappuw=uw:X. Thus reflexive, symmetric, transitive, and congruence closure are rules of the ambient judgmental equality, not additional assumptions in ΓSK. The context need hypothesize only the two nonstructural generating equations.

Exercise 48.13.

Write rt:=eqreflt. If tu:X, then Eq congruence gives EqX(t,t)EqX(t,u) type. The conversion direction is the tree ΓSKt:XΓSKrt:EqX(t,t)EqIΓSKEqX(t,t)EqX(t,u) typeΓSKrt:EqX(t,u)Conv. The second premise is the Eq-congruence judgment displayed just above; its nonreflexive endpoint premise is the assumed tu:X. Conversely, reflection is the one-step tree ΓSKrt:EqX(t,u)ΓSKtu:XEqReflect. Thus the term-typing query and the SK equality query are equivalent, with no appeal to an unannotated surface refl.

Exercise 110.9.

Application synthesizes app(f,a;A,B) after normalizing the type of f and inverting its Π head; the independent check rechecks f, checks a:A, and substitutes a into B. Natural elimination records the motive k.C, zero branch, and step branch n:N,y:C[n/k]s:C[suc(n)/k]; rechecking repeats these three premises and returns C[m/k]. Identity elimination records x,y,p.C and the reflexive branch after y,x,p are replaced by x,x,reflx. Normalization occurs only before head inversion; constructor inversion chooses the rule; context conversion transports a checked branch when its reconstructed type is judgmentally, but not syntactically, the stored annotation.

Search the book

Type to search the local edition.