You are on page 1of 15

CSE-4103

Artificial Intelligence
PROLOG BASICS

MD. NAZMUS SALEHIN

LECTURER

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE)

BANGLADESH ARMY UNIVERSITY OF ENGINEERING AND TECHNOLOGY (BAUET)

CONTACT:

salehinfall2020@gmail.com
Reference Book 2

 Introduction to Turbo Prolog by Carl Townsend

"All healing is first a healing of the heart." - Carl Townsend


What is prolog 3

 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

It is useful for almost any application that requires “formal reasoning”


Example:
Premise 1 : I wash my car when the weather is good on weekends.
Premise 2: Hot weather is good.
Premise 3: Today is Sunday and the weather is hot
Conclusion: Therefore, I will wash my car today.
Applications for Prolog Cont. 5

 Expert systems
 Natural Language Processing
 Robotics
 Gaming
 Simulations
FACTS, OBJECTS, PREDICATES 6

Clauses

Facts Rules

Periods (.) Predicates

Relations Arguments

Objects Variables
FACTS, OBJECTS, PREDICATES CONT. 7

Clauses

Facts Rules

Periods (.) Predicates

Facts: Facts are symbolic relationships. Properties Relations Arguments


of objects, or relationships between objects;

Example of Facts: Objects Variables


“The right speaker is dead", is written in Prolog as:

Facts: is(right_speaker, dead).


FACTS, OBJECTS, PREDICATES CONT. 8

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: The factual expression in Prolog is called


Periods (.) Predicates
a clause. It contains facts and rules.
Relations Arguments
Example of Clauses :

symptom (charlie, fever). Objects Variables


symptom (charlie, cough).
hypothesis (corona) :-
symptom (fever),
symptom (cough).
FACTS, OBJECTS, PREDICATES CONT. 10

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 :

Facts: is(right_speaker, dead).

Predicates: is(right_speaker, dead)


Periods: .
FACTS, OBJECTS, PREDICATES CONT. 11

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 :

Fact: is (right_speaker, dead).


Relation : is
FACTS, OBJECTS, PREDICATES CONT. 12

Clauses

Facts Rules

Periods (.) Predicates


Arguments: The elements (objects or variables)
within the parentheses are the arguments of the Relations Arguments
predicate.
Objects Variables
Example of Arguments :

Fact: is (right_speaker, dead).


Arguments : (right_speaker, dead)
FACTS, OBJECTS, PREDICATES CONT. 13

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 :

Fact: is (right_speaker, dead). Objects Variables


Objects : right_speaker and dead

Names of Objects begin with lower case letters.


They also can begin with digits (like 9020), and can
be strings of characters enclosed in quotes (as in
reads (fred, "War and Peace")).
FACTS, OBJECTS, PREDICATES CONT. 14

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").

Symbol type String type


Objects Objects
FACTS, OBJECTS, PREDICATES CONT. 15

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

You might also like