Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4: Prolog (Substitution, Unification and Resolution)

Similar presentations


Presentation on theme: "Chapter 4: Prolog (Substitution, Unification and Resolution)"— Presentation transcript:

1 Chapter 4: Prolog (Substitution, Unification and Resolution)
DM552: Part 2 Programing Logic Chapter 4: Prolog (Substitution, Unification and Resolution) Dr Youcef Djenouri

2 Substitution: Definition (1/2)
Substitution θ is an operation allowing to replace some variables occurring in a formula with terms. The goal of applying a substitution is to make a certain formula more specific so that it matches another formula. Substitutions allow for unification of formulae (or terms).

3 Substitution: Definition (2/2)
A substitution is any finite mapping of variables into terms of the form: θ: V ⇒ TER Any (finite) substitution θ can be presented as θ={t1/X1, t2/X2… tn/Xn} ti is the term to be substituted for a variable Xi, i= 1…n. No two elements in the set have the same variable after the / symbol,

4 Substitution: Example
{ y/X, f(y)/Z } is a substitution. { a/Y, b/X} is a substitution. {a/X, b/X} is not a substitution. {X/f(Y)} is not a substitution.

5 Instance (1/2) Let θ ={t1/X1, t2/X2… tn/Xn} be a substitution and let E be an expression. Then Eθ is an expression obtained by replacing all occurrences of every vi in E with the corresponding term ti, Eθ is an instance of E.

6 Instance (2/2) θ ={ a/X, f(b)/Y, c/Z} , E=P(X, Y, Z)
Eθ= P(a, f(b), c) is an instance of E. θ ={f(f(a))/X, X/Y} , E=(P(X ) ∨ Q(Y)) Eθ= (P(f(f(a))) ∨ Q(X)) is an instance of E. θ ={ Y/X, a/Y} , E=(P(X ) ∨ Q(Y)) Eθ= (P(Y) ∨ Q(a)) is an instance of E.

7 Composition of substitutions
Let θ= {t1/X1, t2/X2… tn/Xn} and Γ={u1/Y1, u2/Y2… um/Ym} be two substitutions. The composition of θ and Γ is denoted by θ o Γ, and it is obtained by building the set {t1 Γ /X1, t2 Γ /X2… tn Γ /Xn, u1/Y1, u2/Y2… um/Ym} Remove the following elements: tj Γ/ Xj such that tj Γ = Xj ui/ Yj such that Yj is in {X1, X2… Xn}

8 Example θ= {t1/X1, t2/X2}= {f(Y)/X, Z/Y}
Γ={u1/Y1, u2/Y2,u3/Y3}= {a/X, b/Y, Y/Z} {t1 Γ /X1, t2 Γ /X2, u1/Y1, u2/Y2,u3/Y3}={f(b)/X, Y/Y, a/X, b/Y, Y/Z} θ o Γ ={f(b)/X, Y/Z}

9 Classwork Consider θ = {f(Y)/X} and µ = {f(Z)/Y} Compute θ o µ and µ o θ ?

10 Unification A substitution θ is called a unifier for a set {E1…Ek} if and only if: E1θ =E2θ = E3θ =…= Ekθ The set {E1…Ek} is unifiable if and only if there exists a unifier for it. A unifier θ is a most general unifier for a set {E1…Ek} if and only if for each unifier Γ there exisits a substitution μ such that Γ= θ o μ.

11 θ o μ= {f(f(Z))/X, f(Z)/Y}= Γ
Example E1=P(X), E2= P(f(Y)) are unifiable by Γ={f(f(Z))/X, f(Z)/Y} E1 Γ = E2 Γ = P(f(f(Z))). θ= {f(Y)/X} is a most general unifier, we can find μ ={f(Z)/Y} such that θ o μ= {f(f(Z))/X, f(Z)/Y}= Γ

12 Classwork Prove that the following expressions are all unifiers by θ = {f(b)/X, b/Y, u/Z} E = f(X, b, g(Z)). F = f(f(Y), Y, g(u)).

13 Resolution: Used to prove a consequence from a set of logical formulae
States: Sets of clauses L1 …  Lm Initially: The consequence we want to prove is negated and added to the set of clauses representing the initial state Goal: Derive the empty clause ()

14 Example (1/6) ¬P(X)  P(f(X)) ¬Q(a, Y)  ¬R(Y, X)  P(X) R(b, g(a, Z))
Q(a, b) Goal: P(f(g(a, c)))

15 Example (2/6) Negate goal, add to formulas 1. ¬P(X)  P(f(X))
2. ¬Q(a, Y)  ¬R(Y, X)  P(X) 3. R(b, g(a, Z)) 4. Q(a, b) 5. ¬P(f(g(a, c)))

16 Example (3/6) Resolve (4) and (2) by applying {b/Y} 1. ¬P(X)  P(f(X))
2. ¬Q(a, Y)  ¬R(Y, X)  P(X) 3. R(b, g(a, Z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) ¬R(b, X)  P(X)

17 Example (4/6) Resolve (6) and (3) by applying {g(a,Z)/X} 1. ¬P(X)  P(f(X)) 2. ¬Q(a, Y)  ¬R(Y, X)  P(X) 3. R(b, g(a, Z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, X)  P(X) P(X)

18 Example (5/6) Resolve (7) and (1) by applying {g(a,Z)/X}
1. ¬P(X)  P(f(X)) 2. ¬Q(a, Y)  ¬R(Y, X)  P(X) 3. R(b, g(a, Z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, X)  P(X) 7. P(g(a, Z)) P(f(X))

19 □ Example (6/6) Resolve (8) and (5) by applying {g(a,c)/ X}
1. ¬P(X)  P(f(X)) 2. ¬Q(a, Y)  ¬R(Y, X)  P(X) 3. R(b, g(a, Z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, X)  P(X) 7. P(g(a, Z)) 8. P(f(X))

20 SLDTree Facts: grand_father(jacob, X)
father(john, merry). father(jacob, jones). father(jones, sylia) father(jacob, Z), father(Z, X ) father(jacob, Z), mother(Z, X) mother(sylia, anes). mother(merry, relly). Rules: father(jacob, jones), father(jones, X) Exit grand_father (X, Y) :-father(X, Z), father(Z, Y). grand_father(X, Y) :-father(X, Z), mother(Z, Y). Question: grand_father(jacob, X) father(jacob, jones), father(jones, sylia)


Download ppt "Chapter 4: Prolog (Substitution, Unification and Resolution)"

Similar presentations


Ads by Google