# 20 - Click to edit Master subtitle style Chapter Twenty...

This preview shows pages 1–9. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style Chapter Twenty Modern Programming Languages, 2nd ed. A Second Look At Prolog Chapter Twenty Modern Programming Languages, 2nd ed. 11 Chapter Twenty Modern Programming Languages, 2nd ed. Outline Unification Three views of Prologs execution model Procedural Implementational Abstract The lighter side of Prolog Chapter Twenty Modern Programming Languages, 2nd ed. 22 Chapter Twenty Modern Programming Languages, 2nd ed. Substitutions A substitution is a function that maps variables to terms: = { Xa a , Yaf(a,b) } This & maps X to a and Y to f(a,b) The result of applying a substitution to a term is an instance of the term ( g(X,Y) ) = g(a,f(a,b)) so g(a,f(a,b)) is an instance of g(X,Y) Chapter Twenty Modern Programming Languages, 2nd ed. 33 Chapter Twenty Modern Programming Languages, 2nd ed. Unification Two Prolog terms t1 and t2 unify if there is some substitution } (their unifier ) that makes them identical: ( t1 ) = ( t2 ) a and b do not unify f(X,b) and f(a,Y) unify: a unifier is { Xa a , Ya b } f(X,b) and g(X,b) do not unify a(X,X,b) and a(b,X,X) unify: a unifier is { Xa b } a(X,X,b) and a(c,X,X) do not unify a(X,f) and a(X,f) do unify: a unifier is {} Chapter Twenty Modern Programming Languages, 2nd ed. 44 Chapter Twenty Modern Programming Languages, 2nd ed. Multiple Unifiers parent(X,Y) and parent(fred,Y) : one unifier is 1 = { Xafred } another is 2 = { Xafred , Ya mary } Prolog chooses unifiers like 1 that do just enough substitution to unify, and no more That is, it chooses the MGUthe Most General Unifier Chapter Twenty Modern Programming Languages, 2nd ed. 55 Chapter Twenty Modern Programming Languages, 2nd ed. MGU Term x1 is more general than x2 if x2 is an instance of x1 but x1 is not an instance of x2 Example: parent(fred,Y) is more general than parent(fred,mary) A unifier 1 of two terms t1 and t2 is an MGU if there is no other unifier 2 such that { 2( t1 ) is more general than 1( t1 ) MGU is unique up to variable renaming Chapter Twenty Modern Programming Languages, 2nd ed. 66 Chapter Twenty Modern Programming Languages, 2nd ed. Unification For Everything Parameter passing reverse([1,2,3],X) Binding X=0 Data construction X=.(1,[2,3]) Data selection [1,2,3]=.(X,Y) Chapter Twenty Modern Programming Languages, 2nd ed. 77 Chapter Twenty Modern Programming Languages, 2nd ed. The Occurs Check Any variable X and term t unify with { Xa t }: X and b unify: an MGU is { Xab } X and f(a,g(b,c)) unify: an MGU is { Xaf(a,g(b,c)) } X and f(a,Y) unify: an MGU is { Xaf(a,Y) } Unless X occurs in t: X and f(a,X) do not unify, in particular not by { Xaf(a,X) } Chapter Twenty Modern Programming Languages, 2nd ed....
View Full Document

## This note was uploaded on 09/30/2011 for the course CS 6371 taught by Professor Hamlen during the Spring '11 term at University of Texas at Dallas, Richardson.

### Page1 / 64

20 - Click to edit Master subtitle style Chapter Twenty...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online