Professional Documents
Culture Documents
Reference: Bratko(2001)
Website: http://www.lpa.co.uk/
Download free trial version
There are manuals available
Prolog Logic
Clause form (conjunctive normal First-order predicate logic
form, quantifiers are not explicitly (predicates and quantification)
written)
Horn clauses (clauses that have at -
most one positive literal)
Procedural meaning Resolution principle for
mechanical theorem proving
Matching using “=“ Unification: substitution instance
?- parent(bob, pat).
bob liz yes Prolog
query
Prolog ?- parent(X, liz).
answer X = tom
ann pat
?- parent(Y, jim), parent(X, Y).
Answer will be the same Y = pat
although we change the X = bob
jim order of the 2
requirements as the
logical meaning are ?- parent(X, Y), parent(Y, jim).
same. Will the answer be the same?
CPT114/CPT104 Shahida S. (2008) 14
Exercise
Who are Pam’s grandchildren?
pam tom ?- parent(pam, X), parent(X, Y).
X = bob
Y = ann; Type semicolon
for more
X = bob solutions, type
bob liz
Y = pat enter to stop.
X X is an indirect
X is a direct predecessor of Z predecessor of Z
parent
X Y1
parent predecessor parent predecessor
Z Y2
predecessor(X, Z) :-
predecessor(X, Z) :- parent
parent(X, Z). Z parent(X, Y1),
parent(Y1, Y2),
CPT114/CPT104 Shahida S. (2008) parent(Y2, Z). 21
How Prolog Answers Questions
Prolog tries to satisfy all goals when answering a
question.
Demonstrate that the goal is true, assuming that the relations
in the program are true or
Demonstrate that the goal logically follows from the facts and
rules in the program.
If the questions contain variables, Prolog has to find
the particular objects (in place of variables) for which
the goals are satisfied.
The particular instantiation of variables to these
objects is displayed to the user.
If not found, Prolog’s answer to the question will be
‘no’.
Data objects
Matching
Declarative meaning of Prolog programs
Procedural meaning
Order of clauses and goals
constants variables
atoms numbers
Arguments: can be
functor constants, variables, variable
or other structures
D = 2, E = 2
program
success/failure indicator
goal list execute
instantiation of variables
person •
tom fox date works ann fox date unemp.
[]
7 may 1960 bbc 15200 9 may 1961 pat fox date unemp. person
5 may 1983
CPT114/CPT104 Shahida S. (2008) 55
Example: Retrieving Database
Specify objects not by content but by their
structure, leave the arguments as anonymous
variables.
Refer to all Fox family as:
family(person( _, fox, _, _), _ )
Refer all families with 3 children:
family( _, [_, _, _] )
Find all married women with at least 3 children:
?- family( person(Name, Surname,_,_ ), [_, _, _ | _] ).
member( X, [X | L] ).
member( X, [Y | L] ) :-
member( X, L).
conc([], L, L).
conc([X|L1],L2, [X|L3]) :-
conc(L1,L2,L3).
permutation( L, [X | P]) :-
del( X, L, L1),
permutation( L1, P).