Rules in Prolog: Student Name Student Roll # Program Section
Rules in Prolog: Student Name Student Roll # Program Section
Student Roll #
Program
Section
RULES IN PROLOG
Lab-03
___________________________________________________________________________
7
Artificial Intelligence-Lab [COSC-3212]
OBJECTIVES:
Predicate names, function names, and the names for objects must begin with a lowercase
letter.
mother_of
male
female
greater_than
socrates
4. RULES IN PROLOG
A rule can be viewed as an extension of a fact with added conditions that also have to be
satisfied for it to be true. Or more precisely “a rule is a predicate expression that uses
logical implication (:-) to describe a relationship among facts.” It consists of two parts:
___________________________________________________________________________
8
Artificial Intelligence-Lab [COSC-3212]
1. The first part is similar to a fact (a predicate with atoms).
2. The second part consists of other clauses (facts or rules which are separated by
commas) which must all be true for the rule itself to be true.
These two parts are separated by ":-". You may interpret this operator as "if" in English.
left_hand_side :- 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.
EXAMPLE-I:
___________________________________________________________________________
9
Artificial Intelligence-Lab [COSC-3212]
Program 1. A Program with Facts only
sunny.
father(john, peter).
father(john, mary).
mother(susan, peter).
Goals/Queries and their results:
?- sunny. /* The response is yes because the fact "sunny." is present. */
True
?- rainy. /* There is an error because there is no predicate "rainy". */
Erroneous result.
?- father(john, mary).
True
?- mother(susan, mary). /* This cannot be deduced. */
False
?- father(john, susan). /* This cannot be deduced. */
False
EXAMPLE-2:
Program 2. A program describes the relationships of the members in a family.
As you can see from Rules 3 to 5, predicates that only appear in rules but not
facts (in this case, parent) can also form conditions of other rules.
5. LAB TASKS
Indicate whether the following are syntactically correct Rules by answering in Yes or No.
happy(X):- a , b.
?- parent(susan, mary).
?- parent(ray, peter).
___________________________________________________________________________
11
Artificial Intelligence-Lab [COSC-3212]
?- yeye(X, susan).
?- mama(amy, X).
?- gunggung(X, Y).
___________________________________________________________________________
12
Artificial Intelligence-Lab [COSC-3212]