DCS 440: Artificial Intelligence
Homework 2, Fall 1999
Due Oct 13

Contents
Overview
Problem 1
Problem 2
Problem 3
Overview

This homework consists of mathematical exercises designed to connect Prolog and logic with other branches of computer science.


Problem 1: Complexity of Unification

The moral of this story is that Prolog can allow you to build structures very quickly that are very expensive to actually use.

In class, I described informally the process of unification, which computes a most general substitution under which an equation is true. We've seen many informal examples of this process.

A. Write most general unifiers for the following terms:

  • t(a,X) = t(Y,f(Y,Y))
  • t(a,X,f(X,X)) = t(Y,f(Y,Y),Z)
  • t(a,X,f(X,X),W) = t(Y,f(Y,Y),Z,f(Z,Z))

Use substitutions of the form { ...Xi / ti... } where each ti is a ground term. How large must a unifier of this form be as a function of the number of symbols in the equation it solves?

B. Recall that one of our logical proofs required us to describe compositions of substitutions. If s is a substitution and t is a substitution, then we can define (s.t) such that

e(s.t) = ((es)t)
We use the ability to combine substitutions in this way in this part of problem 1.

  • Write the unifier for t(a,X) = t(Y,f(Y,Y)) in the form (s.t) where s and t have two properties. First, each should take the form { Vi/ti } for a single variable and a single term. Second, except possibly for renaming variables, the term ti should occur in the original problem.
  • Write the unifier for t(a,X,f(X,X)) = t(Y,f(Y,Y),Z) as a composition of three such substitutions.
  • Write the unifier for t(a,X,f(X,X),W) = t(Y,f(Y,Y),Z,f(Z,Z)) as a composition of four such substitutions.

Each of these small substitutions is called a variable elimination.

C. You can always construct a unifier, if one exists, by performing a sequence of variable eliminations this way. In this part of problem 1, you will develop the argument why.

You can ``simplify'' a single equation into a set of little equations of the form X=t where X is a variable with an occurrence in one of the terms being equated and t is the corresponding subterm from the other term. Any unifier for the set of little equations also unifies the overall equation. On the other hand, you cannot unify the overall equation without solving each of the little equations. Each little equation suggests a corresponding candidate for variable elimination: { X/t }.

Consider two such candidates: { X1/t1 } and { X2/t2 }.

  • Under what conditions would applying the composed substitution

    ({X1/t1} . {X2/t2})
    not achieve the effect of eliminating all occurrences of X1 and X2 in an expression?
  • Which of these conditions could give a composed substitution

    ({X1/t1} . {X2/t2})
    which is more general than some ground substitution? Which of them could not?
  • Under which conditions can you rewrite the equations X1=t1, X2=t2 so that you can have a term t3 that X2 must equal to solve the equations, where t3 is a renaming of t2 and such that applying

    ({X1/t1} . {X2/t3})
    does eliminate all occurrences of X1 and X2 in an expression?

Given a set of little equations E, define a relation X1 < X2 if there is an equation X2 = t2 and X1 occurs as a proper subterm of t2 (in other words, X1 occurs in t2 and t2 is not simply X1).

  • Suppose s is a ground substitution that solves the equations E. If X1 < X2, what can you conclude about X1s and X2s?
  • Consider the transitive closure of <, written <*. X1 <* X2 if X1 < X2 or if there is an X3 with X1 <* X3 and X3 <* X2. If X1 <* X2, what can you conclude about X1s and X2s?

Put your answers to the earlier parts of problem 1C together to argue that you must be able to select and order the candidate variable eliminations for a set of solvable equations to obtain a unifier for them. In particular:

  • Argue that in a set of equations E which are solved by some ground substitution, there must be an equation X=t that you can select next---in that you can describe the unifier for E in the form:

    ( {X/t} . s )

By induction, you can repeat this selection until you have described a unifier for all the equations!

D. If you represent a unifier as a sequence of variable eliminations, how large of a data structure will you need, as a function of the size of the terms you are unifying? Compare this to the size required to represent a unifier explicitly (which you can also think of as the size of the data structures computed by a unification problem).


Problem 2: More About Lists

These are some problems modeled after exercise 3.5 and 3.6 from the text. Note: for this question, in reporting results, it suffices to describe the substitution computed for each proof.

  • Given the definition of append from class:

    append(nil,Y,Y).
    append([A|X],Y,[A|Z]) :- append(X,Y,Z).
    what is the result of the following queries

    ?append(A,[a|B],[b,a,d,a,c,a]).
    ?append(A,[A,B|Y],[a,b,c,d,e]).
  • Write a relation remove(E,L,R) that is true precisely in case R is a list like L with one occurrence of E omitted. The relation is false if E isn't a member of L.

  • What are all of the answers to the following queries:

    ?remove(a,[b,a,d,a],R).
    ?remove(E,[b,a,d,a],R).
    ?remove(E,L,[b,a,d]).


Problem 3: Gaps in data structures

Read the description of difference lists on pages 85 and 86 of CI. You can use the idea behind difference lists to fill a hole quickly in any data structure. You use a term swg(S,X) to record a data structure S that contains an occurrence of X as a hole. When X is a variable, you can unify X with another value, to fill the hole in S once and for all. By building larger terms, you can record multiple holes with more complex patterns.

Describe a representation for lists with ellipses in the middle -- lists you would write informally to yourself in the form

a, b, c, .... x, y, z
Using this representation, write atomic clauses as follows:
  • stitched(LWE,L) for a relation true when the ellipses in LWE are empty so that the ordinary list L is the same list as LWE. (If you prefer, you may instead treat L as a difference list.)

  • narrow_rightward(LWE1,ELT,LWE2) for a relation true when LWE1 and LWE1 are identical lists, except that where ellipses start at position k in LWE1, ellipses start at position k+1 in LWE2 and position k actually contains ELT.

  • narrow_leftward(LWE1,ELT,LWE2) for a relation true when LWE1 and LWE1 are identical lists, except that where ellipses end at position k in LWE1, ellipses end at position k-1 in LWE2 and position k actually contains ELT.