Академический Документы
Профессиональный Документы
Культура Документы
Andrian Rakhmatsyah
Institut Teknologi Telkom
Conventional Programming
The programmer instruct the machine HOW to solve a problem
by performing a given sequence of actions
The machine carries out the instructions in a specified order
Logic Programming
PROLOG PROGRAMS
In a PROLOG program:
A FACT represents a unit of information that is
assumed to be true;
A RULE represents a conditional assertion
A VARIABLE represents an unspesified element of a
world
A CONSTANT represents a spesific elements of that
world
A PREDICATE represents a relatioship between
element or a property of a class of elements.
A PROCEDURE is a group of clauses having the
same head predicate.
likes(sue,husband(ann)),
Queries
DEBUGGER
The Amzi! debugger is used to find and identify
errors.
It works on interpreted source code.
The debugger can only be invoked from, and
used within, the listener. In order to step
through code, you need to consult the source
code form of the module
?- 3 = 1 + 2
no
Comment : 3 is not the same terms as 1 + 2
?- 3 is 1 + 2
yes
Comment : 3 is the value of 1 + 2.
The Predicate symbols = does not represent the
normal equality but it represent a special
relation in PROLOG called unifiability
?- 4-1
no
?- 4-1
yes
?- X+2
X = 1
?- X +
1+2
no
is 1+2
=:= 1+2
= 1+2
2 =:=
Problem VS Solution
smart(X) :teaches(X,Y),computing(Y).
teaches(john,ma1).
teaches(wife(john),sa1).
mathematics(ma1).
computing(sa1).
FACTS
teaches(john,ma1).
teaches(wife(john),sa1).
mathematics(ma1).
computing(sa1).
RULE
smart(X) :- teaches(X,Y),computing(Y).
ATOMIC FORMULAs
smart(X), teaches(X,Y), computing(Y).
TERM
Variabels : X, Y
Constants : john, ma1, sa1
Function : wife(john)
function symbol :
wife
PREDICATEs: smart, teaches, computing
?- smart(X)
X = wife(john).
no
Program 1
likes(mother(X),X) :- good(X).
woman(mother(X)).
woman(ann).
good(husband(ann)).
Program 2
likes(X,Y) :- mother(X,Y), good(Y).
woman(Y) :- mother(X,Y).
woman(ann).
good(X) :- husband(X,ann)
loves(X,husband(Y));
loves(X,husband(X));
mother(john);
min(log(X),Y);
X + 1;
loves(mother(Z),Z);
loves(mother(Z),Z);
mother(sue);
min(U,exp(V)).
Y + 2;