Structures and Matching: CS-521 (WEEK 4) D.C.SC
Structures and Matching: CS-521 (WEEK 4) D.C.SC
Structures and
Matching
CS-521(WEEK 4)
D.C.SC
2
Outline
Data Objects
Matching
Declarative meaning of Prolog programs
Procedural meaning
Example : monkey and banana
Order of clauses and goals
The relation between Prolog and logic
3
2.1 Data objects
4
Structures
Example date(1,may,2003)
More Structures
terms
Example
All data objects in Prolog are terms
an atom is a term. Eg – may, 2003
date(Day,may,2003)
a variable is a term. Eg- Day
a compound term is a term. Eg- date(Day,may,2003)
7
P1=point(1,1)
P2=point(2,3)
S=seg(P1,P2)=seg(point(1,1),point(2,3))
T=triangle(point(4,2),point(6,4),point(7,1))
8
2.2 Matching
Example
In Prolog,
?- date(D,M,2001) = date(15,may,Y1).
If S and T are constants then S and T match only if they are the same objects
Facts
vertical(seg(point(X,Y),point(X,Y1))). % same X value
horizontal(seg(point(X,Y),point(X1,Y))). % same Y value
Questions
?- vertical(seg(point(1,1),point(1,2))).
true
?- vertical(seg(point(1,1),point(2,Y))).
false
?- horizontal(seg(point(1,1),point(2,Y))).
Y=1 true
14
Declarative meaning
To determine whether a given goal is true and if so, for what values it
is true
Variant
Variant of a clause C is such an instance of the clause C where each
variable is substituted by another variable
Instance
An instance of a clause C is the clause C with each of its variables
substituted by some term
15
Example
For a clause
hasachild(X) :- parent(X,Y).
Thank You.