Module 3
Module 3
or v ;
if --> :-
not ~ not
• Variables and Names
• Variables begin with an uppercase letter. Predicate names, function
names, and the names for objects must begin with a lowercase letter.
Rules for forming names are the same as for predicate calculus.
• mother_of
• male
• female
• greater_than
• socrates
A fact is a predicate expression that makes a declarative statement about the problem domain.
Whenever a variable occurs in a Prolog expression, it is assumed to be universally quantified. Note
that all Prolog sentences must end with a period.
• likes(john, susie). /* John likes Susie */
• likes(X, susie). /* Everyone likes Susie */
• likes(john, Y). /* John likes everybody */
• likes(john, Y), likes(Y, john). /* John likes everybody and everybody
likes John */
• likes(john, susie); likes(john,mary). /* John likes Susie or John likes Mary
*/
• not(likes(john,pizza)). /* John does not like pizza */
• likes(john,susie) :- likes(john,mary). /* John likes Susie if John likes Mary.
• Rules
• A rule is a predicate expression that uses logical implication (:-) to
describe a relationship among facts. Thus a Prolog rule takes the form
• left_hand_side :- right_hand_side
• This sentence is interpreted as: left_hand_side if right_hand_side
• This notation is known as a Horn clause
• In Horn clause logic, the left hand side of the clause is the conclusion,
and must be a single positive literal. The right hand side contains the
premises. The Horn clause calculus is equivalent to the first-order
predicate calculus.
• The left_hand_side is restricted to a single, positive, literal, which
means it must consist of a positive atomic expression. It cannot be
negated and it cannot contain logical connectives.
valid rules:
Slots Filters
Slots Filter
Title Artificial
Name Peter Intelligence
Profession Doctor Genre Computer
Age 25 Science
cat(tom).
loves_to_eat(kunal,pasta).
of_color(hair,black).
loves_to_play_games(nawaz).
lazy(pratyusha).
• Rules:
• Lili is happy if she dances.
• Tom is hungry if he is searching for food.
• Jack and Bili are friends if both of them love to play cricket.
• will go to play if school is closed, and he is free.
• symbol ( :- ) will be pronounced as “If”, or “is implied by”
• rule_name(object1, object2, ...) :- fact/rule(object1, object2, ...)
• happy(lili) :- dances(lili).
• hungry(tom) :- search_for_food(tom).
• friends(jack, bili) :- lovesCricket(jack), lovesCricket(bili).
• goToPlay(ryan) :- isClosed(school), free(ryan).
• Queries: Queries are some questions on the relationships between
objects and object properties
• Is tom a cat?
• Does Kunal love to eat pasta?
• Is Lili happy?
• Will Ryan go to play?
• So according to these queries, Logic programming language can find
the answer and return them.
Knowledge Base in Logic Programming
• three main components in logic programming − Facts,
Rules and Queries.
• Among these three if we collect the facts and rules as a
whole then that forms a Knowledge Base. So we can
say that the knowledge base is a collection of facts
and rules.
• KB1:girl(priya).
• girl(tiyasha).
• girl(jaya).
• can_cook(priya).
ACTIVITY
• Perform 5 experiments each one.