Professional Documents
Culture Documents
Artificial Intelligence
PROLOG BASICS
LECTURER
CONTACT:
salehinfall2020@gmail.com
Reference Book 2
The name Prolog was taken from the phrase “Programming in Logic” i.e.
“PRO” means Programming and “LOG” means Logic.
The language was originally developed in 1972 by Alain Colmerauer and P.
Roussel at the University of Marseilles in France.
Applications for Prolog 4
Expert systems
Natural Language Processing
Robotics
Gaming
Simulations
FACTS, OBJECTS, PREDICATES 6
Clauses
Facts Rules
Relations Arguments
Objects Variables
FACTS, OBJECTS, PREDICATES CONT. 7
Clauses
Facts Rules
Clauses
Facts Rules
Rules: A rule is an expression that indicates that
the truth of a particular fact depends upon one Periods (.) Predicates
or more other facts. A rule allows us to find out
about a relationship even if the relationship isn't Relations Arguments
explicitly stated as a fact.
Objects Variables
Example of Rules:
hypothesis (corona) :-
symptom (fever),
symptom (cough).
FACTS, OBJECTS, PREDICATES CONT. 9
Clauses
Facts Rules
Clauses
Facts Rules
Periods and Predicates: The full stop(.) is called
Periods and the entire expression before the period Periods (.) Predicates
in each case is called a Predicate. A predicate is a
function with a value of true or false. Predicates Relations Arguments
express a relationship or property.
Objects Variables
Example of Periods and Predicates :
Clauses
Facts Rules
Relations: A relation is a name that defines the way Periods (.) Predicates
in which a collection of objects (or objects and
variables referring to objects) belong together. The Relations Arguments
word before the parentheses is the relation. Names
of Relations begin with lower case letters.
Objects Variables
Example of Relations :
Clauses
Facts Rules
Clauses
Facts Rules
Objects: An object is the name of an element of a
certain type. It represents an entity or a property of Periods (.) Predicates
an entity in the real world.
Relations Arguments
Example of Objects :
Clauses
Objects: There are six different types of objects used Facts Rules
in Prolog:
• Char: Single character(enclosed between single Periods (.) Predicates
quotation marks)
• Integer: Integer from -32,768 to +32,767 Relations Arguments
• String: Character sequence (enclosed between
double quotation marks).
• Real: Floating-point numbers. Objects Variables
• Symbol: Character sequence of letters, numbers
and underscore with the first character as a
lowercase letter.
• File: Symbolic file name.
Examples:
reads (fred, "War and Peace").
Clauses
Facts Rules
Variables: It is used to specify an unknown quantity.
A variable name must begin with a capital letter Periods (.) Predicates
and may be from 1 to 250 characters long. Except
for the first character in the variable name, you Relations Arguments
may use uppercase, lowercase, underscore or
digits. Variable name should be meaningful.
Objects Variables
Examples of Variables:
Age
Disease
Patient
John_Smith