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:
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.
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 }.
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).
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:
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).
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.
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, zUsing this representation, write atomic clauses as follows:
|