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

ch:efficient-unification: ch:efficient-unification

Exercise 113.1.

Decomposition of the root pair first equates the two F-nodes and then adds xG(y),G(a)y. The quotient therefore has one F-class, one class containing x and G(y), one class containing y and G(a), and the class of a. Both mixed classes have one rigid representative, so the quotient is homogeneous. Its nonconstant arcs run from the x/G(y)-class to the y/G(a)-class and then to the a-class; hence it is acyclic. Reading the rigid recipes gives xG(y),yG(a).

After replacing the second root by F(G(y),x), propagation gives xG(y) and G(a)x. The two G-nodes in this class force ya. The quotient remains homogeneous and acyclic, and one triangular MGU is ya,xG(a).

Exercise 113.2.

The first root class contains the two H-nodes. Deleting it creates xF(a),F(y)F(a). The maximally shared input has one node for the two printed occurrences of F(a). Consequently the two new links form the single live root class {x,F(y),F(a)}. Its transition records xF(a) and, from the two rigid F-nodes, creates the child link ya. The second and final root-class transition records ya. The output xF(a),ya is triangular. Unfolding sends both roots to H(F(a),F(a)), which verifies the input equation.

Exercise 113.3.

Choose one of the k rigid q-ary nodes as representative. Each of the other k1 nodes contributes one equality at each of its q child positions, so the transition creates q(k1) links. Charge the link from position j of nonrepresentative node s to the unique outgoing arc (s,s[j]). The pair (s,j) recovers the charged arc, so the charge is injective.

A node is deleted once. Consequently an outgoing arc is charged only in the transition that deletes its source. Summing over classes bounds all generated links by the input child arcs. Node visits, parent-cursor advances, incident-link advances, stack operations, and bindings likewise admit one constant charge per stored node, arc, link, or variable. Restarting an incident-link cursor after each merge destroys the last claim: a list prefix can then be rescanned after every newly discovered class member, producing quadratic work on a linear-size star of links.

Exercise 113.4.

For xf(x), the linked class contains the flexible node x and the rigid node f(x). With the completion mark inside the sr branch, the rigid representative r remains owner=r,Complete=ff while its parent dependency is followed. The traversal reaches x, whose parent is the unfinished representative, and reports the quotient self-cycle. With the mark after the branch, the state instead becomes owner(r)=r,Complete(r)=tt before that revisit. The revisit is skipped and the cyclic recipe xf(x) escapes to post-processing.

For xf(y) and yg(x), the first link class records x with f(y), and the second records y with g(x). Following the parent of y enters the first unfinished class; following the parent of x returns to the second unfinished class. Thus the corrected procedure first revisits whichever of these two classes was entered first under the implementation’s fixed parent order. The certificate is the two-class quotient cycle [x=f(y)][y=g(x)][x=f(y)].

Exercise 113.5.

Maximal sharing uses one node for each of x,y,z,a,G(a), one node for each occurring H-recipe, and the two root F-nodes. Deleting the root class creates xH(z,a),H(y,a)H(G(a),a),yG(a). The first mixed class records xH(z,a). Decomposing the two H-nodes adds yG(a) and the reflexive link aa. The remaining mixed class records yG(a); z remains a variable-only quotient parameter. Hence S=(xH(z,a), yG(a)). Every unifier θ must give y the tree G(a), by rigid injectivity, and must give x the tree H(θ(z),a). Define δ(z)=θ(z). Then θ(y)=δ(S(y)) and θ(x)=δ(S(x)); the equation for z is immediate. Thus θ=δS on all input variables.

Exercise 113.6.

Use F(x)G(x),xF(x),xF(y), yG(z), zH(x). The first problem fails in its initial root class because it contains unequal rigid heads F and G. A common tree would have both heads, contradicting constructor disjointness. The second problem’s quotient has a self-loop from the class [x,F(x)] to itself. If its tree had height h, equality with the proper F-subtree would require h>h.

The third problem produces three quotient classes with strict child edges [x][y][z][x]. If their unfolded finite-tree heights are hx,hy,hz, the three equations imply hx>hy>hz>hx, an impossible strict cycle. The failure becomes detectable when the last link closes that quotient cycle; no finite-tree substitution can remove it.

Exercise 113.7.

Store the recipes x0a,xif(xi1,xi1)(1in) once each. This representation has n+1 bindings and 2n child pointers. To read the root of xn, inspect its recipe. To follow a chosen leaf, read one of the two equal child pointers at each f-recipe; after n pointer steps the traversal reaches a, so the cost is O(n).

The expanded tree has 2n distinct leaf positions. Any enumeration that emits each position performs at least one output action per position and therefore takes Ω(2n) time. The linear theorem constructs the recipe graph and triangular bindings. It does not claim to enumerate the expanded tree, so the two bounds concern different outputs.

Search the book

Type to search the local edition.