unification algrithm

Upload: mahima-rojith

Post on 04-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Unification Algrithm

    1/5

    Unification Algrithm.

    UNIFICATION ALGORITHMIn propsoitional logic it is easy to determine that two literals can not both be true at the same time. Simply look for L and ~L . In predicatelogic, this matching process is more complicated, since bindings of variables must be considered.

    For example man (john) and man(john) is a contradiction while man (john) and man(Himalayas) is not. Thus in order to determinecontradictions we need a matching procedure that compares two literals and discovers whether there exist a set of substitutions thatmakes them identical . There is a recursive procedure that does this matching . It is called Unification algorithm.In Unification algorithm each literal is represented as a list, where first element is the name of a predicate and the remaining elements arearguments. The argument may be a single element (atom) or may be another list. For example we can have literals as

    ( tryassassinate Marcus Caesar)

    ( tryassassinate Marcus (ruler of Rome))

    To unify two literals , first check if their first elements re same. If so proceed. Otherwise they can not be unified. For example the literals

    ( try assassinate Marcus Caesar)

    ( hate Marcus Caesar)

    Can not be Unfied. The unification algorithm recursively matches pairs of elements, one pair at a time. The matching rules are :

    i) Different constants , functions or predicates can not match, whereas identical ones can.

    ii) A variable can match another variable , any constant or a function or predicate expression, subject to the condition that the function or[predicate expression must not contain any instance of the variable being matched (otherwise it will lead to infinite recursion).

    iii) The substitution must be consistent. Substituting y for x now and then z for x later is inconsistent. (a substitution y for x written as y/x)

    The Unification algorithm is listed below as a procedure UNIFY (L1, L2). It returns a list representing the composition of the substitutionsthat were performed during the match. An empty list NIL indicates that a match was found without any substitutions. If the list contains asingle value F, it indicates that the unification procedure failed.

    UNIFY (L1, L2)

    1. if L1 or L2 is an atom part of same thing do

    (a) if L1 or L2 are identical then return NIL

    (b) else if L1 is a variable then do

    (i) if L1 occurs in L2 then return F else return (L2/L1)

    else if L2 is a variable then do

    (i) if L2 occurs in L1 then return F else return (L1/L2)

    else return F.

    2. If length (L!) is not equal to length (L2) then return F.

    3. Set SUBST to NIL

    ( at the end of this procedure , SUBST will contain all the substitutions used to unify L1 and L2).

    4. For I = 1 to number of elements in L1 do

    i) call UNIFY with the i th element of L1 and Ith element of L2, putting the result in S

    ii) if S = F then return F

    iii) if S is not equal to NIL then do

    (A) apply S to the remainder of both L1 and L2

    (B) SUBST := APPEND (S, SUBST) return SUBST.

    Unification Algorithm

  • 7/30/2019 Unification Algrithm

    2/5

    The basic unification algorithm is simple. However, it must be implemented

    with care to ensure that the results are correct.

    We begin by making sure that the two expressions have no variables in

    common. If there are common variables, substitute a new variable in one of the

    expressions. (Since variables are universally quantified, another variable can besubstituted without changing the meaning.)

    Imagine moving a pointer left-to-right across both expressions until parts are

    encountered that are not the same in both expressions. If one is a variable, and

    the other is a term not containing that variable,

    1. substitute the term for the variable in both expressions,

    2. substitute the term for the variable in the existing substitution set [This is

    necessary so that the substitution set will be simultaneous.]

    3. add the substitution to the substitution set.

    Unification Implementation

    1. Initialize the substitution set to be empty. We do this with the set ((t . t)). A nil set indicates failure.2. Recursively unify expressions:

    1. Identical items match.

    2. If one item is a variable viand the other is a term tinot containing that variable, then:1. Substitute ti / viin the existing substitutions.

    2. Add ti / vito the substitution set.3. If both items are functions, the function names must be identical and all arguments must unify.

    Substitutions are made in the rest of the expression as unification proceeds.

    Simple Unification Algorithm

    (defun unify (u v) (unifyb u v '((t . t))))

    ; unify terms: subs list or NIL if failure

    (defun unifyb (u v subs) ; works if:

    (or (and (eq u v) subs) ; identical vars

    (varunify v u subs) ; u is a var

    (varunify u v subs) ; v is a var

    (and (consp u) (consp v) ; both are fns

    (eq (car u) (car v)) ; with same name

    (unifyc (cdr u) (cdr v) subs))) ) ;args

    (defun unifyc (args1 args2 subs) ; unify arg lists

    (if (null args1) ; if args1 empty

    (if (null args2) subs) ; args2 must be

    (and args2 subs ; unify first args

    (let ((newsubs (unifyb (car args1)

    (car args2) subs)))

    (unifyc (sublis newsubs (cdr args1))

  • 7/30/2019 Unification Algrithm

    3/5

    (sublis newsubs (cdr args2))

    newsubs))) ))

    (defun varunify (term var subs) ; unify with var

    (and var (symbolp var) (not (occurs var term))

    (cons (cons var term)

    (subst term var subs))))

  • 7/30/2019 Unification Algrithm

    4/5

    Well-Formed Formula for First Order Predicate Logic

    --- Syntax Rules

    Subjects to be Learned

    wff (well formed formula)

    atomic formula

    syntax of wff

    Contents

    Not all strings can represent propositions of the predicate logic. Those which produce a proposition when their symbolsare interpreted must follow the rules given below, and they are called wffs(well-formed formulas) of the first order

    predicate logic.

    Rules for constructing Wffs

    A predicate name followed by a list of variables such asP(x, y), wherePis a predicate name, andx andy are variables,is called an atomic formula.

    Wffs are constructed using the following rules:

    1. True andFalse are wffs.2. Each propositional constant (i.e. specific proposition), and each propositional variable (i.e. a variable

    representing propositions) are wffs.

    3. Each atomic formula (i.e. a specific predicate with variables) is a wff.

    4. IfA, B, and Care wffs, then so are A, (A B), (A B), (A B), and (A B).

    5. Ifx is a variable (representing objects of the universe of discourse), andA is a wff, then so are x A and x

    A .

    (Note : More generally, arguments of predicates are something called a term. Also variables representing predicatenames (called predicate variables) with a list of variables can form atomic formulas. But we do not get into that here.Those who are interestedclick here.)

    For example, "The capital of Virginia is Richmond." is a specific proposition. Hence it is a wff by Rule 2.

    LetB be a predicate name representing "being blue" and letxbe a variable. ThenB(x) is an atomic formula meaning

    "xis blue". Thus it is a wff by Rule 3. above. By applying Rule 5. toB(x), xB(x) is a wff and so is xB(x). Then by

    applying Rule 4. to them xB(x) xB(x) is seen to be a wff. Similarly ifR is a predicate name representing "being

    round". ThenR(x) is an atomic formula. Hence it is a wff. By applying Rule 4 toB(x) andR(x), a wffB(x) R(x) is

    obtained.In this manner, larger and more complex wffs can be constructed following the rules given above.

    Note, however, that strings that can not be constructed by using those rules are not wffs. For example, xB(x)R(x),andB( x) are NOT wffs, NORareB(R(x) ), andB( xR(x) ) .

    One way to check whether or not an expression is a wff is to try to state it in English. If you can translate it into acorrect English sentence, then it is a wff.

    More examples: To express the fact that Tom is taller than John, we can use the atomic formula taller(Tom, John),

    which is a wff. This wff can also be part of some compound statement such as taller(Tom, John) taller(John,Tom), which is also a wff.

    http://www.cs.odu.edu/~toida/nerzic/content/logic/pred_logic/construction/wff_intro.html????http://www.cs.odu.edu/~toida/nerzic/content/logic/pred_logic/construction/wff_intro.html????http://www.cs.odu.edu/~toida/nerzic/content/logic/pred_logic/construction/wff_intro.html????
  • 7/30/2019 Unification Algrithm

    5/5

    Ifx is a variable representing people in the world, then taller(x,Tom), x taller(x,Tom), x taller(x,Tom), x ytaller(x,y) are all wffs among others.

    However, taller( x,John) and taller(Tom Mary, Jim), for example, are NOT wffs.

    Test Your Understanding of Wff Construction

    Indicate which of the following statements are correct and which are not.

    Click Yes or No , then Submit. There are two sets of questions.

    Below \A represents the universal and \E the existential quantifiers, respectively.