Professional Documents
Culture Documents
Unit-12: Introduction To: Prolog
Unit-12: Introduction To: Prolog
3170716
Unit-12: Introduction to
Prolog
Fact
Likes(samyra, john).
Relation Objects
Domains
Predicates
clauses
// defining Facts,Rules
// likes(aditya, naina).
//likes(bob, hezal).
Load
Run
| ?- Predicate(arguments).
Output
Output Goal:boy(bob).
Goal:likes(bob, hezal). True
True Goal:girl(bob).
Goal:likes(bob, mery). False
False
Output
Goal:max(3,4,MAX).
MAX = 4
Goal:max(5,4,MAX).
MAX = 5
fact(N,Result) :-
N > 0,
N1 is N-1,
fact(N1,Result1),
Result is Result1*N.
Output
Goal:fact(2,F).
F = 2
Goal:fact(3,F).
F = 6
Output
Goal:sum(4,SUM).
SUM = 10
Output
Goal:fibonacci(2).
0 1
Goal:fibonacci(3).
0 1 2
b(1).
b(4).
c(1).
c(3).
d(4).
Output
Goal:a(x).
X = 4
cut.pl Output
a(X) :- b(X),!,c(X). Goal:a(x).
a(X) :- d(X). X = 1
b(1).
b(4).
c(1).
c(3).
d(4).
B
Cut condition
C River F
D E G N
H K
Shop Fail condition
I J L M
Goal
o P
Output
List.pl
Goal:length([a,b,c],N).
length([],0). N = 3
length([_|TAIL],N) :- Goal:length([],0).
length(TAIL,N1),N is N1 +1. N = 0
Output
List.pl
Goal:con([a,b,c],[1,2],N).
con([],L1,L1). N = [a,b,c,1,2]
con([X|Tail],L2,[X|Tail1]):-
con(Tail,L2,Tail1).