Sunday 18 January 2009

Matching

Matching is operation on terms (structures).
Given two terms, they match if:
They are identical, or
They can be made identical by properly instantiating the variables in both terms.
Matching two dates:
date( D1, M1, 2006) = date( D2, june, Y2).
This causes the variables to be instantianted as:
D1 = D2
M1 = june
Y2 = 2006

The terms below don’t match:
date( D, M, 2008) = date( D1,M1, 2000).
In order to check whether the given dates are matching or not in Prolog we use ‘=‘ operator.
?-date( D, M, 2008) = date( D1,May, Y1).

Example:
?- date(D, M, 2001) = date(D1, may, Y1),
date(D, M, 2001) = date(15, M, Y).
D=15, D1= 15, M= may, Y1 = 2001, Y= 2001
Example:
?- date( D1, M1, 2006) = date( D2, june, Y2),
date( D1, M1, 2006) = date( 17, M3, Y3).
D1 = 17, D2 = 17, M1 = june, M3 = june,Y2 = 2006, Y3 = 2006



Matching succeeds or fails; if succeeds then it results in the most general instantiation

To decide whether terms S and T match:
If S and T are constants then they match only if they are identical
If S is a variable and T is anything then matching succeeds, S is instantiated to T and vice versa.
If S and T are structures then they match only if:
S and T have the same principal functor ,and
All their corresponding components match.


Matching succeeds or fails; if succeeds then it results in the most general instantiation

To decide whether terms S and T match:
If S and T are constants then they match only if they are identical
If S is a variable and T is anything then matching succeeds, S is instantiated to T and vice versa.
If S and T are structures then they match only if:
S and T have the same principal functor ,and
All their corresponding components match.

No comments:

Post a Comment