Lab Report of AI2
Lab Report of AI2
PROLOG Code:
% Facts
delicious(cakes).
delicious(pickles).
delicious(biryani).
spicy(pickles).
relishes(priya,coffee).
% Rules
likes(priya,Food) :- delicious(Food).
likes(pranab,Food) :- spicy(Food), delicious(Food).
%?- delicious(Food).
Observation.
Experiment No. 2: Student-Teacher-Subject Relationship
PROLOG Code:
% Facts
student(john).
student(sara).
teacher(mr_smith).
teacher(ms_clark).
studies(john,math).
studies(sara,science).
teaches(mr_smith,math).
teaches(ms_clark,science).
% Rules
teaches_subject_to(Teacher, Student, Subject) :-
teacher(Teacher),
student(Student),
teaches(Teacher, Subject),
studies(Student, Subject).
Observation.
parent(john, mary).
parent(jane, mary).
parent(john, mike).
parent(jane, mike).
parent(mary, alice).
parent(tom, alice).
male(john).
male(mike).
male(tom).
female(jane).
female(mary).
female(alice).
% Rules
father(X, Y) :- parent(X, Y), male(X).
mother(X, Y) :- parent(X, Y), female(X).
sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y.
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
Observation.
PROLOG Code:
car(maruti, white).
car(fiat, black).
car(tesla, red).
Observation.
Agin:
Code;
% ----------- Knowledge Base (Facts) -----------
% car(Brand, Color, Type).
eco_friendly(Car) :-
car(Car, _, electric).
%Query:
%?- car(_, Color, _).
%?- car(Brand, black, _).
%?- car(Brand, white, sedan).
%?- car(Brand, _, Type).
%?- eco_friendly(Brand).
%?- car(_, _, Type).
%?- car(Brand, red, _).
Observation.
% ----- Facts -----
a.
b.
c.
d.
e.
f.
%query
%?-p.
Observation.
● .
Lab 2:
Code:
% Facts
man(marcus).
pompeian(marcus).
roman(X) :- pompeian(X). % All Pompeians are Romans
ruler(caesar).
tried_to_assassinate(marcus, caesar).
% Rules
% Clauses for hates/2
hates(X, Y) :- tried_to_assassinate(X, Y), ruler(Y). % People hate rulers they try to assassinate
hates(X, caesar) :- roman(X), \+ loyal_to(X, caesar). % Romans hate Caesar if they are not loyal
%query
%?-hates(marcus, caesar).
%?-loyal_to(marcus, caesar).
Result:
Lab-3:
Code:
% Facts
greek(aristotle).
greek(plato).
student(plato, aristotle).
born(aristotle, -348). % -348 represents 348 BC
lifespan(human, 120).
% Rules
is_greek(X) :- greek(X).
is_alive(X, Year) :-
born(X, BirthYear),
lifespan(human, Lifespan),
DeathYear is BirthYear + Lifespan,
Year =< DeathYear.
% Queries
% ?- is_greek(plato). % To check if Plato was a Greek
% ?- is_alive(plato, 2024). % To check if Plato is alive in 2024