Professional Documents
Culture Documents
INSTITUTE OF ENGINEERING
PULCHOWK CAMPUS
Artificial Intelligence
Lab Report
Introduction to Prolog
Logic
Logic is the systematic study of reasoning and argumentation. It is concerned with the
principles of valid reasoning and inference, and is used to evaluate the correctness of
arguments and draw conclusions based on evidence and facts.
In logic, we use a set of rules and principles to determine whether an argument is valid or
not. This involves examining the structure of the argument and the relationships between
its premises and its conclusion.
Propositional Logic
Propositional logic, also known as sentential logic, is a branch of mathematical logic that
studies propositions, which are statements that are either true or false. In propositional
logic, these statements are represented by propositional variables or atomic propositions,
which can be combined using logical connectives to form compound propositions.
In FOL, a domain of discourse is defined, which is the collection of all objects that can be
referred to in the logical statements. This domain can be finite or infinite and can include
objects of any type, including numbers, people, or abstract concepts.
Using these symbols, we can write complex statements in FOL, such as "For all x, there
exists a y such that x is greater than y." This statement is represented in FOL as ∀x ∃y
(x > y), which means "For all x, there exists a y such that x is greater than y."
Conversion of Prolog into FOPL
Prolog (PROgramming in LOGic) is a declarative programming language that is based on
first-order predicate logic (FOPL). As such, it is possible to convert Prolog programs into
FOPL statements.
To convert a Prolog program into FOPL, we need to translate each clause in the program
into an equivalent FOPL statement. Here are the steps to follow:
● Identify the predicates in the Prolog program: Predicates are represented by their
names followed by their arguments in parentheses. For example, in the clause
likes(john, mary)., likes is the predicate and john and mary are its arguments.
● Translate Prolog operators into FOPL notation: Prolog uses some operators such
as = and is that do not have direct equivalents in FOPL. These operators can be
translated into FOPL notation using standard logical symbols. For example, the
Prolog clause X is Y + 1 can be translated into FOPL as S(Y) = X, where S
represents the successor function.
Assignments
1. Premises 1
1. Horses, cows, and pigs are mammals.
2. An offspring of a horse is a horse.
3. Bluebeard is a horse.
4. Bluebeard is Charlie’s parent.
5. Offspring and parent are inverse relations.
6. Every mammal has a parent.
Query
1. Is Charlie a horse?
Code
PREDICATES
horse(STRING)
mammal(STRING)
cow(STRING)
pig(STRING)
isOffspring(STRING,STRING)
isParent(STRING, STRING)
CLAUSES
horse("Bluebeard").
horse(X):- mammal(X).
horse(X):- isOffspring(Y,X),horses(Y).
isOffspring(X,Y):-parent(Y,X).
isParent("Bluebeard","Charlie").
isParent(X,Y):- isOffspring(Y,X).
cow(X):- mammal(X).
pig(X):- mammal(X).
Mammal(X):- parent(Y,X).
GOAL
horse("Charlie").
Output
2. Premises 2
1. All people who are not poor and are smart are happy.
2. Those people who read are not stupid.
3. John can read and is wealthy.
4. Happy people have exciting lives.
Question:
1. Can anyone be found with an exciting life?”?
Code
PREDICATES
notPoor(STRING)
smart(STRING)
happy(STRING)
notStupid(STRING)
read(STRING)
wealthy(STRING)
excitingLife(STRING)
CLAUSES
excitingLife(X):-happy(X).
happy(X):- notPoor(X),smart(X).
smart(X):- notStupid(X).
notStupid(X):- read(X).
notPoor(X):- wealthy(X).
read("John").
wealthy("John").
GOAL
excitingLife(X).
Output
3. Premises 3
1. All Pompeians are Romans.
2. All Romans were either loyal to Caesar or hated him.
3. Everyone is loyal to someone.
4. People only try to assassinate rulers they are not loyal to.
5. Marcus tried to assassinate Caesar.
6. Marcus was Pompeian.
Question
1. Did Marcus hate Caesar?
Code
PREDICATES
pompeian(STRING)
roman(STRING)
loyal(STRING,STRING)
hate(STRING,STRING)
assassinate(STRING,STRING)
CLAUSES
pompeian(X):- roman(X).
pompeian(X):- loyal(X,Y).
roman(X):- loyal(X,Y).
roman(X):- loyal(X,"Caesar");hate(X,"Caesar").
assassinate(X,Y):- not(loyal(X,Y)).
assassinate("Marcus","Caesar").
hate(X,Y).
loyal(X,Y).
GOAL
hate("Marcus","Caesar").
Output
4. Premises 4
Bhogendra likes all kinds of food. Oranges are food. Chicken is food. Anything anyone eats and
isn’t killed by its food. If a person likes a food means that person has eaten it. Jogendra eats
peanuts and is still alive. Shailendra eats everything Bhogendra eats.
Question
Does Shailendra like chicken?
Code
PREDICATES
food(STRING)
eat(STRING,STRING)
notKilledby(STRING,STRING)
like(STRING,STRING)
CLAUSES
food("Oranges").
food("Chicken").
food(X):- like("Bhogendra",X).
food(X):- eat(Y,X),notKilledby(Y,X).
like(X,Y):- eat(X,Y).
eat("Jogendra","Peanuts").
eat("Bhogendra",X):- eat("Shailendra",X).
notKilledby("Jogendra","Peanuts").
GOAL
like("Shailendra","Chicken").
Output
5. Premises 5
Dave and Fred are members of a dancing club in which no member can both waltz and jive.
Fred’s dad can’t waltz and Dave can do whatever Fred can’t do. If a child can do something, then
their parents can do it also.
Question
Prove that there is a member of the dancing club who can’t jive.
Code
PREDICATES
member(STRING,STRING)
parent(STRING,STRING)
can(STRING,STRING)
cant(STRING,STRING)
CLAUSES
member("Dave","Dancing Club").
member("Fred","Dancing Club").
cant("Freds Dad","Waltz").
cant(X,Y):- parent(Z,X), cant(Z ,Y).
cant(X,"Waltz"):- member(X,"Dancing Club"), can(X,"Jive").
cant(X,"Jive"):- member(X,"Dancing Club"), can(X,"Waltz").
can("Dave",X):- cant("Fred",X).
can(X,Y):- parent(Z,X), can(Z,Y).
parent("Freds Dad","Fred").
GOAL
cant(X,"Jive"),member(X,"Dancing Club").
Output
Conclusion
During the lab session, we were taught First Order Predicate Logic and applied it to
problem solving in Visual Prolog. The session began with a focus on Propositional Logic
before moving on to Predicate Logic, where we learned about quantifiers and observed
how universal and existential quantifiers work. We solved five predicate logic questions
in Visual Prolog and constructed first order predicate logic to represent general natural
language statements.