



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Unification is a third major topic that will appear many times in this course. It is used in languages such as Haskell and Prolog, and also in theoretical discussions.
The problem of unification is to find a single solution that satisfies multiple sets of constraints. A constraint is a way of specifying a solution to a problem, where some of the elements of the solution are specified precisely, but other elements may be less precise. For example, suppose you have two advisors. Your first advisor wants you to take a theory course and also CS 440. There are several theory courses you could take. Register for one of those, and register for CS 440, and you have satisfied the problem, and your advisor. Now suppose your second advisor wants you to take CS 430 and a language course. There are several language courses that you could take. Take one of those, and take CS 430, and your second advisor is happy. The problem of unification comes in when we ask, āIs there a way to register for classes that make both advisors happy?ā. We want one solution that simultaneously solves both constraints. In this case, we do have a solution: take CS 430 and CS 440.
Of course, we need to do this more formally. We will use a notation that will look something like function applications. In actuality, they are patterns, much like the ones you use when you write a function in Haskell. There are two kinds of patterns: terms and variables. Terms have names, to be written using the Roman alphabet, and arity, a fancy way of saying ānumber of argumentsā. That number may turn out to be zero. Such terms will look like variables in algebra, but itās important to remember that they are patterns. Examples of terms include x, z, f(x,y), and x(y,f,z). We write variables using the Greek alphabet, and we may subscript them if necessary. Examples include α, β 12 , and γ 7. Using terms and variables, we can specify constraints. For example, we could say that s is the schedule function. The first argument is a theory course, and the second argument is a language course. The first advisorās constraint might look like s(α, c 440 ). The second advisorās constraint would look like s(c 430 , β). If we want to specify a solution to the constraint, we need to provide a mapping from variables to terms. The solution to the first advisorās constraint would be Ļ 1 = {α 7 ā c 430 }. This solution Ļ 1 is also called a substitution. A substitution could involve multiple variables, such as Ļ = {α 7 ā f(x, β), β 7 ā y}. Notationally, these substitutions are applied like functions. So, Ļ 1 (s(α, c 440 )) = s(c 430 , c 440 ).
The problem is, given constraints S and T , is to find a substitution Ļ such that Ļ(S) = Ļ(T ). If such a substitution exists, it is said that S and T unify. A unification problem is a set of equations S = {s 1 =?^ t 1 , s 2 =?^ t 2 ,.. .}. A unification problem S = {x 1 =?^ t 1 , x 2 =?^ t 2 ,.. .} is in solved form if
Our approach: given a unification problem S, we want to find the most general unifier Ļ that solves it. We will do this by transforming the equations.
Start with a unification problem S = {s 1 =?^ t 1 , s 2 =?^ t 2 ,.. .} and apply the following transforma- tions as necessary:
Delete A trivial equation t =?^ t can be deleted.
Decompose An equation f (tn) =?^ f (un) can be replaced by the set {t 1 =?^ u 1 ,... , tn =?^ un}
Orient An equation t =?^ x can be replaced by x =?^ t if x is a variable and t is not.
Eliminate an equation x =?^ t can be used to substitute all occurrences of x in the remainder of S.
(Stolen from āTerm Rewriting and All Thatā) {α =?^ f (x), g(α, α) =?^ g(α, β)}
Try to unify the following:
To build a unifier, you need:
How should we represent things?
You need three lists:
You need functions to perform the transformations we need.
You may need a flag to indicate completion. Time to start coding...!