Lectures onType Theory
ch:semi-unification: ch:semi-unification
appendix sectionsolutions

ch:semi-unification: ch:semi-unification

Exercise 5.1.

Put M=αβ and N=γγ. The encoding is ((αβ),(αβ))su((αβ),(γγ)). The substitution S=[γ/α,γ/β] is a most general unifier, up to renaming of γ. After applying S, both sides of the encoded inequality are the pair ((γγ),(γγ)), so the identity matcher replays it. Conversely, decomposition of any replay equates the two images, hence gives a unifier of the original equation.

Exercise 5.2.

Suppose S,R replayed the inequality and put A=S(α), B=S(β). Its left side after both substitutions is (R(A)R(B))R(A), whereas the right side is A. Therefore |A|=2+2|R(A)|+|R(B)|>|R(A)||A|, a contradiction. The last inequality holds because a substitution on finite first-order trees retains every constructor node and replaces every variable leaf by a nonempty finite tree. Infinite regular trees do not support this natural-number node count, which is where finiteness is used.

Exercise 5.3.

Under monomorphic recursion, let the one type of f be δ. The whole body requires δ=αγ, while the recursive occurrence f(λy.x) requires δ=(βα)γ. Decomposition yields α=βα; its right side contains α, so the occurs check rejects it.

Exercise 5.4.

Take S=[γ/β] and R=[γ/α]. The equation becomes γ=γ, and the inequality replays as R(αα)=γγ. For any semi-unifier, the equation clause is checked before any local matcher and states S(β)=S(γ). A matcher belongs only to its inequality and cannot repair an equation, so this equality is necessarily a restriction on the shared outer substitution.

Exercise 5.5.

Encode every equation MN as (M,M)su(M,N). Any unifier S semi-unifies all encodings with identity matchers. Conversely, decomposition of each encoded replay gives S(M)=S(N), so the outer substitution is a unifier. The first two FO-Fix inequalities mutually match τx and τb while protecting ρ¯; by lemma 5.9 they express equality of the two generalized schemes. The third premise (τb,ρ¯)su(τ,ρ¯) is the genuine one-way inequality that instantiates the whole fix expression. It remains when let is deleted, because it is generated by the recursive binder itself.

Exercise 5.6.

Write the annotation as σ=α¯.τ. Replace α¯ in the body target by fresh rigid constants κ¯ and check the body against τ[κ¯/α¯]. The free type variables of the ambient environment are rigid as well. Keep the recursive assumption as the written scheme σ; at each recursive occurrence replace its prefix by fresh flexible variables and generate the ordinary application and abstraction equations. Unification may solve only flexible variables. It rejects an equation that binds a κi or an ambient rigid variable, and its final substitution may not place a κi in any type whose scope extends outside the checked body.

If the checker succeeds, replace each κi by αi in the body derivation. Every recursive leaf is an instance of the written scheme, the rigid target is exactly its body monotype, and generalizing the αi reconstructs the annotated MM-Fix premise. This proves soundness by rule induction. Conversely, alpha-rename the prefix of an annotated derivation, replace its bound variables by fresh rigid constants, and read the flexible instantiations from the recursive leaves. They solve the generated equations without binding or escaping a rigid constant; unification completeness therefore makes the checker accept.

Rigidity is necessary. Checking λf.λx.fx against a.aa with a flexible would solve a as an arrow and accept, although the term’s principal type is (bc)(bc) and it has no such universal type. The rigid checker rejects the attempted arrow equation for κa. The algorithm is finite for a supplied annotation. Searching for an annotation quantifies over all finite schemes and is the inference problem excluded by corollary 5.27.

Search the book

Type to search the local edition.