Lectures onType Theory
ch:supercompilation: ch:supercompilation
appendix sectionsolutions

ch:supercompilation: ch:supercompilation

Exercise 128.1.

Unfolding append exposes a case on x. Rule D-Case-Open first creates two refinement edges, to the same case with scrutinee Nil and with scrutinee Cons(a,z), respectively. The edge substitutions are [Nil/x] and [Cons(a,z)/x]. At the second node on each path, D-Case-Known contracts the case and gives the residual leaves Cnil=Cons(b,Nil),Ccons=Cons(a,append(z,Cons(b,Nil))). The second leaf contains the one residual recursive call; its first argument is the constructor tail z.

Exercise 128.2.

At the roots, Emb-Couple reduces the forward judgment to its two children. Rule Emb-Var gives xa. For the tail, Emb-Dive selects the tail of the outer right-hand Cons, after which Emb-Couple gives NilNil. Hence the required embedding holds. Reversing it would couple the outer Cons heads and then require Cons(x,Nil)Nil. The heads do not match for Emb-Couple, and Nil has no child for Emb-Dive; the derivation stops there.

Exercise 128.3.

The first five call configurations are Qi=loop(Si(x))(0i4). The first whistle is Q0Q1: couple the common loop head and use Emb-Dive with Emb-Var for xS(x). Their most-specific generalization is g=loop(z),σ=[x/z],τ=[S(x)/z]. Direct substitution gives gσ=Q0 and gτ=Q1. Root agreement forces any common generalization to retain the loop head, while the child disagreement forces a variable, so the factorization clause of lemma 128.5 proves most-specificity.

Exercise 128.4.

Let the faulty test erase constructor names before comparing states. It then identifies the same-arity closed states S(Z) and P(Z), where S and P are distinct unary constructors, and folds the former to the latter’s residual node. The unfolded state returns S(Z), whereas the folded state returns P(Z), so returned constructors differ. Variant equivalence repairs the test by demanding identical constructor heads and only a bijective renaming of free variables. For an accepted pair Q=Qπ, the residual equation for Q abstracts exactly fv(Q); applying it to π alpha-renames that equation to Q. Thus the repaired back edge satisfies the folding equation and preserves evaluation.

Search the book

Type to search the local edition.