Lectures onType Theory
ch:inference-rules: ch:inference-rules
appendix sectionsolutions

ch:inference-rules: ch:inference-rules

exercise 1.1.

Take three judgments P,Q,R and the one-rule system

PQ
R

The sets S={P} and T={Q} are each closed: in either set at least one premise of the rule is absent. Their union contains both premises but not the conclusion, and therefore is not closed. This also explains why intersections, rather than unions, occur in proposition 1.5.

exercise 1.2.

The grammar is presented by the three rules

s comb
k comb
a1 comba2 comb
ap(a1;a2) comb

Writing 1¯=suc(0) and using the metalevel operation defined in the exercise, the required relation is generated by

len(s;1¯)
len(k;1¯)
len(a1;m)len(a2;n)
len(ap(a1;a2);mn)

Rule induction shows simultaneously that a derivable length judgment has a combinator as its first subject and that its second subject is precisely the number of leaves labeled s or k.

Exercise 1.3.

Every node in the numeral-equality derivation is forced: X0is0IsZsuc(0)issuc(0)IsSsuc(suc(0))issuc(suc(0))IsS. The tree derivation uses one axiom for each empty subtree and one Tree-Node for each node: Xemp treeTreeEmpXemp treeTreeEmpnode(emp;emp) treeTreeNodeXemp treeTreeEmpnode(node(emp;emp);emp) treeTreeNode.

Exercise 1.4.

The only conclusions of the equality rules are 0is0 and suc(a)issuc(b). Hence no rule instance has conclusion suc(0)is0, so a finite derivation of that judgment has no possible final rule.

Likewise, the outer successor on both sides of suc(a)issuc(b) excludes Is-Z. Its final rule must therefore be aisbsuc(a)issuc(b)IsS. Thus the derivation contains a derivation of aisb as its immediate subtree.

Exercise 1.5.

For reflexivity, induct on a nat. The Nat-Z case is Is-Z. If the premise derivation gives, by induction, aisa, then Is-S gives suc(a)issuc(a).

For transitivity, induct on the derivation of aisb. If it ends in Is-Z, then a=b=0. Final-rule inspection of 0isc forces Is-Z, hence c=0, and Is-Z proves the result. In the successor case the two derivations have the shapes a0isb0suc(a0)issuc(b0)IsS,b0isc0suc(b0)issuc(c0)IsS. The induction hypothesis derives a0isc0, and Is-S derives the required successor judgment.

Finally, the outer form of suc(a)issuc(b) excludes Is-Z; the final rule is Is-S, and its premise is exactly aisb. This proves successor injectivity.

Exercise 1.6.

Only Ev-S concludes a judgment whose subject is a successor and whose tag is even. Thus a derivation of suc(a) even has immediate premise a odd. Similarly, only Od-S can conclude suc(a) odd, and its premise is a even.

Assume for contradiction that both a even and a odd are derivable. Either derivation gives a nat by lemma 1.24. Induct on that numeral derivation. If a=0, no rule concludes 0 odd. If a=suc(b), the two inversion facts extract both b odd and b even. The induction hypothesis for the predecessor derivation rules this out. Hence no expression has both parity tags.

Exercise 1.7.

The complete tree is X0 natNatZsuc(0) natNatSsum(0;suc(0);suc(0))SumZsum(suc(0);suc(0);suc(suc(0)))SumSsum(suc(suc(0));suc(0);suc(suc(suc(0))))SumS. Deleting the final Sum-S leaves sum(suc(0);suc(0);suc(suc(0))) at the root. This premise is forced: Sum-Z can conclude only a sum whose first argument is 0, so the displayed successor-headed conclusion can only arise from Sum-S. Matching that rule against the conclusion uniquely determines the premise above.

Exercise 1.8.

Let Ei derive Ki from Γ. For the iterated proof, weaken E1 to the ambient hypotheses Γ,K2,,Kn and apply transitivity to discharge K1. The result derives J from Γ,K2,,Kn. Repeat with E2, and so on. After n applications, the result derives J from Γ.

For the single proof, induct on the given derivation D of J from Γ,K1,,Kn. A hypothesis leaf from Γ is retained. A leaf Ki is replaced by the fixed tree Ei. At a primitive-rule node, transform every immediate subderivation by the induction hypotheses and reapply the same rule. Every new leaf is now justified by Γ, and every internal node has the same conclusion as before, so the transformed root is a derivation of J from Γ.

Exercise 1.9.

One direction is immediate: every R-derivation is also an R{r}-derivation. Conversely, induct on a derivation over R{r}. If its final rule lies in R, transform its premises by the induction hypotheses and reapply that rule. For a two-premise instance of r, the induction hypotheses transform D1,D2 into closed R-derivations, and admissibility supplies E. The complete final-rule transformation is D1::R{r}J1D2::R{r}J2R{r}Jrinduction; admissibilityE::RJ. Thus every judgment derivable after adjoining r was already derivable before adjoining it.

For the reverse direction, assume that adjoining r preserves and reflects derivability. Fix a two-premise instance J1,J2/J whose premises have closed R-derivations D1,D2. The one use of the added rule and the right-to-left implication are D1::RJ1D2::RJ2R{r}Jrright-to-left implicationE::RJ. Since the instance was arbitrary, r is admissible.

Exercise 1.10.

Fix an instance of Ev-Inv and suppose its premise suc(a) even is derivable in the original parity system. The axiom Ev-Z concludes only 0 even, and Od-S concludes an odd judgment. The final rule can only be a oddsuc(a) evenEvS. Its immediate subtree derives the desired conclusion, so every instance is admissible.

After adjoining the new axiom, there is a one-node derivation Xsuc(0) evenNew. For the concrete instance a=0, admissibility would require a derivation of 0 odd. No parity rule has that conclusion, so it remains underivable. The new premise is derivable while the required conclusion is not; admissibility is destroyed.

Exercise 1.11.

Put e0=add(add(0;suc(0));suc(0)). The complete one-step trees are X0 numNumZsuc(0) numNumSadd(0;suc(0))Asuc(0)AAddZe0Aadd(suc(0);suc(0))AAddL, X0 numNumZsuc(0) numNumSX0 numNumZsuc(0) numNumSadd(suc(0);suc(0))Asuc(add(0;suc(0)))AAddS. The final one-step tree is X0 numNumZsuc(0) numNumSadd(0;suc(0))Asuc(0)AAddZsuc(add(0;suc(0)))Asuc(suc(0))ASuc.

Let V0 and V1 denote the complete AB-Z and AB-S(AB-Z) derivations of 0A0 and suc(0)Asuc(0). The big-step tree is V0V1X0 natNatZsuc(0) natNatSsum(0;suc(0);suc(0))SumZadd(0;suc(0))Asuc(0)ABAddV1X0 natNatZsuc(0) natNatSsum(0;suc(0);suc(0))SumZsum(suc(0);suc(0);suc(suc(0)))SumSe0Asuc(suc(0))ABAdd.

Exercise 1.12.

Because yx, the first renaming passes under the binder: (λy.x(yz))w/x=λy.w(yz). Its free variables are {w,z}, which equals ({x,z}{x}){w}. In the second term the binder is the source name, so renaming stops: (λx.xy)w/x=λx.xy. Its free-variable set remains {y}; the source x was not free in the complete abstraction, so the absent-source branch of the free-variable equation adds no w.

Exercise 1.13.

Choose w{x,y,u,v}. Opening the outer abstractions gives λy.wandλv.w. Choose r{w,y,v}. Opening their binders gives w on both sides, and the variable clause gives w=αw. The abstraction clause with witness r, followed by the abstraction clause with witness w, therefore derives λx.λy.x=αλu.λv.u. The choice w=y is invalid because yNames(e); opening to an existing binder name would not satisfy the common freshness premise.

Exercise 1.14.

The displayed binder y would capture a free y in the inserted term, so first rename it to a fresh u: (λy.x(yz))[(yx)/x]=α(λu.x(uz))[(yx)/x]=λu.(yx)(uz). Its free-variable set is {x,y,z}; the displayed u is bound.

For the composition equation, the binder z is already clean for the displayed data. The left side is (λz.xy)[y/x][tt/y]=(λz.yy)[tt/y]=λz.tttt. The right side is (λz.xy)[tt/y][y[tt/y]/x]=(λz.xtt)[tt/x]=λz.tttt. Thus both sides agree, and the hypotheses xy and xFV(tt) hold.

Exercise 1.15.

Put v=λx.add(x;suc(0)). At the first term, E=v[] and r=add(0;suc(0)), which contracts to suc(0). At vsuc(0), the context is empty and the whole term is the beta-redex; it contracts to add(suc(0);suc(0)). This whole addition is again the redex in the empty context and contracts to suc(add(0;suc(0))). Finally E=suc([]) and the redex in its hole is add(0;suc(0)), contracting to suc(0). The final term is suc(suc(0)), a value.

With argument λy.y, beta contraction first produces add(λy.y;suc(0)). Both arguments are values, but the first is not numeric. It cannot step, no addition contraction matches it, and the whole term is not a value. Hence it is in clause 3 of unique decomposition.

Exercise 1.16.

The original step is Xtt valVTrue(λy.xy)ttxttEBeta. Because y is fresh for λz.z, substitution throughout the derivation gives Xtt valVTrue(λy.(λz.z)y)tt(λz.z)ttEBetaXtt valVTrue(λz.z)ttttEBeta.

If the original display uses binder z, clean it first: (λz.xz)tt=α(λu.xu)tt. Now substitution produces Xtt valVTrue(λu.(λz.z)u)tt(λz.z)ttEBeta. The second complete tree is the preceding E-Beta/V-True tree for (λz.z)tttt. The fresh representative is what prevents the inserted binder name from being confused with the binder discharged by the outer beta step.

Exercise 1.17.

Since ω is a value, E-Beta applies: Xω valVLam(λx.xx)ω(xx)[ω/x]EBeta. The contractum satisfies (xx)[ω/x]=ωω. The same step repeats forever. Thus ωω diverges, but it is not stuck because it always has a next step.

In (λx.tt)(ttff), the function is already a value, so call by value must next reduce the argument. But ttff is neither a value nor a redex: both subterms are final and the function is not an abstraction. Consequently the argument has no step, the outer application has no step, and the outer term is not a value; it is stuck. Unevaluated beta substitution would instead give tt[(ttff)/x]=tt, but call by value forbids that contraction until the argument is a value.

Exercise 1.18.

Induct on the displayed value derivation. A final V-Lam, V-True, or V-False conclusion has a source shape matched by no reduction rule. A final V-Num reduces the claim to the premise n num; rule induction on that premise excludes a step from 0, and excludes a step from suc(n) because E-Suc would require a step from the smaller numeral. Structural induction on the raw syntax would expose arbitrary successors as well as numeral successors and would therefore have to recover the missing numeric premise by inversion.

Exercise 1.19.

After deleting E-Suc, the premise add(0;0)0 remains derivable by E-Add-Z, but no remaining rule has source suc(add(0;0)); hence the proposed rule is not admissible. Restoring E-Suc makes the transformation immediate: append one E-Suc inference below any derivation of ee to obtain suc(e)suc(e). Thus admissibility depends on the complete ambient rule set.

Exercise 1.20.

First prove the backward-step lemma eAeandeAneAn by induction on the one-step derivation. In A-Suc, inversion of the target evaluation selects AB-S; apply the induction hypothesis to its premise and rebuild AB-S. In A-Add-L, inversion selects AB-Add; apply the induction hypothesis to the changed left evaluation, retain the right evaluation and sum derivation, and rebuild AB-Add. The A-Add-R case applies its induction hypothesis to the changed right evaluation; its left evaluation and sum derivation are unchanged.

In A-Add-Z, the target is a numeral n2. From n2Aq, lemma 1.44, lemma 1.37 gives q nat. Rule Sum-Z gives sum(0;q;q), so AB-Add, with AB-Z and the assumed target evaluation, derives add(0;n2)Aq.

In A-Add-S, inversion of the target evaluation gives a numeral q and derivations n1Ap1,n2Ap2,sum(p1;p2;q), with final result suc(q). Rule AB-S changes the first evaluation to suc(n1)Asuc(p1), and Sum-S changes the sum premise to sum(suc(p1);p2;suc(q)). Reapplying AB-Add derives the required source evaluation.

Finally fix n num and induct on eAn. In M-Refl, lemma 1.45 gives nAn. In M-Step, the induction hypothesis gives e1An for the many-step tail, and the backward-step lemma applied to eAe1 gives eAn.

Practical route.

The evaluator requested by exercise 1.20 is built in appendix F; its frozen Kappa run and evidence boundary are recorded in appendix E.

Search the book

Type to search the local edition.