Professional Documents
Culture Documents
/* Facts--- */
ako(chair, furniture). ako(chair, seat). isa(your_chair, chair). isa(you, person). made_of(your_chair, wood). colour(wood, brown). belongs_to(your_chair, you).
/* Queries--
Solutions---
output--
X = wood Y = brown
yes
2. Determine whether your chair is a seat. 3. Determine whether your chair is a furniture.
output--
X = chair Y = furniture ? ;
X = chair Y = seat
yes
Ans-- belongs_to(X,you),isa(you,Y).
output--
X = your_chair Y = person
yes
*/
start:- write('input a= '),read(A), write('input b= '),read(B), write('input c= '),read(C), A >= 0,B>= 0,C >= 0, /* must be positive */ A < B+C,B< C+A,C < A+B, write('These numbers are the sides of a triangle.').
Queries :-
1. | ?- start. input a= 3. input b= 4. input c= 5. These numbers are the edges of a triangle.
input b= 34. input c= 23. These numbers are the edges of a triangle.
yes
3. | ?- start. input a= 12. input b= 13. input c= 14. These numbers are the edges of a triangle.
yes
Facts:-
likes(john, susie). likes(X, susie). likes(john, Y). likes(john, Y), likes(Y, john).
not(likes(john,pizza)).
Rules :likes(john,susie) :- likes(john,mary). /* John likes Susie if John likes Mary*/ friends(X,Y) :- likes(X,Y),likes(Y,X). hates(X,Y) :- not(likes(X,Y)). /* X and Y are friends if they like each other */ /* X hates Y if X does not like Y*/
enemies(X,Y) :- not(likes(X,Y)),not(likes(Y,X)). /* X and Y are enemies if they don't like each other */
Queries(with output):-
1. | ?- hates(john,Y).
Y = pizza
yes
2.?- friends(john,susie).
no
3. | ?- enemies(john,marry).
no
4. | ?- friends(john,marry).
no
5. | ?- likes(X,Y).
X = john Y = susie ?
Ques4.
/* Facts---- */
animal(mammal, tiger, carnivore, stripes). animal(mammal, lion, carnivore, mane). animal(mammal, hyena, carnivore, ugly). animal(mammal, zebra, herbivore, stripes).
/*
Queries---
Solutions---
Ans.-- animal_name(X).
output--
X = tiger ? ;
X = lion ? ;
X = hyena ? ;
X = zebra ? ;
X = eagle ? ;
X = sparrow ? ;
X = snake ? ;
X = lizard
Ans.-- animal_name(X,small).
output--
X = sparrow ? ;
X = lizard ? ;
no
Ans.-- animal_name(X,mammal).
output--
X = tiger ? ;
X = lion ? ;
X = hyena ? ;
X = zebra ? ;
(16 ms) no
Ans.-- animal_name(X,bird).
output--
X = eagle ? ;
X = sparrow ? ;
no
Ans.-- animal_name(X,carnivore).
X = tiger ? ;
output--
X = lion ? ;
X = hyena ? ;
X = eagle ? ;
X = snake ? ;
(16 ms) no
Ans.-- animal(X,Y,carnivore,ugly).
output--
X = mammal Y = hyena ? ;
no
*/
start:-sum,n1. sum:- write('Enter value of X= '),read(X), write('Enter value of Y= '),read(Y), S is X+Y, write('Sum is '),write(S).
/*queries*/
/*| ?- start.
| ?- start.
| ?- start.
Sum is 5.7 */
Query :1.
| ?- power(2,3,R).
R=8
yes 2.
| ?- power(3,3,R).
R = 27
yes
3. | ?- power(4,3,R).
R = 64
Yes
Query:1. | ?- fact(4,R).
R = 24 ?
yes
2. | ?- fact(5,R).
R = 120 ?
yes
3. | ?- fact(3,R).
R=6?
yes | ?-
Ques8.-Family problem.
Facts:-
Rules:-
Queries :-
1. father_of(X,paul).
X = joe ?
yes
2. | ?sibling_of(X,paul).
X = mary ?
yes
3. | ?- daughter_of(X,Y).
X = mary Y = joe ?
Yes
Facts :-
star(sun). orbit(earth, sun). orbit(moon, earth). orbit(saturn, sun). orbit(jupiter, sun). orbit(ioa, jupiter). orbit(casini, saturn). orbit(titan, saturn).
Rules :-
Queries:-
1.
yes
3. | ?- satellite(casini). Yes
Facts &Rules :-
Queries :-
1.
| ?- size([1,2,3,4],N).
N=4
yes 2.
| ?- size([bill,ted,ming,pascal,nat,ron],N).
N=6
yes
3.
N=5
yes