0% found this document useful (0 votes)
33 views

Prolog Tutorial

This document introduces the logic programming language Prolog. It discusses the basic elements of a Prolog program, including facts, rules, goals, and predicates. Facts are assertions that define relationships, like "Ali owns a book". Rules define relationships that depend on other facts, like "Two people are sisters if they are both female and have the same parents". Goals are queries to the program, like "What does Abdu like?". Prolog uses predicate logic to represent these elements and attempt to match goals with the facts and rules in the knowledge base.

Uploaded by

Berliani
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Prolog Tutorial

This document introduces the logic programming language Prolog. It discusses the basic elements of a Prolog program, including facts, rules, goals, and predicates. Facts are assertions that define relationships, like "Ali owns a book". Rules define relationships that depend on other facts, like "Two people are sisters if they are both female and have the same parents". Goals are queries to the program, like "What does Abdu like?". Prolog uses predicate logic to represent these elements and attempt to match goals with the facts and rules in the knowledge base.

Uploaded by

Berliani
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Logic Programming

(PROLOG)
Text Book
Prolog Programming, A First Course,
by Paul Brna, 2001

References:
PROLOG A Relational Language and its Applications,
by John Malpas, Prentice Hall
Using Turbo Prolog, QUE Corporation (For PROLOG),
by Yin K. and Solomon D
Course Description
This course will introduce
The theory of functional and logic based
approaches.
Declarative programming will be
introduced using the Prolog programming
language.
Course Objectives
Students should:
Become familiar with the basic syntax of
Prolog language.
Be able to give a declarative and procedural
reading of a Prolog program.
Be able to pursue any course that makes use of
predicate calculus or Prolog.
Introduction
Types of programming languages
Imperative languages: Describe the steps that are
required to solve a given problem. The programmer
must know an algorithm that tells the computer what
to do. That is how to get the output from a given
input. (Examples: C++, C#, Pascal, Algol, … etc.)
Declarative languages: Declare the logic by which the
program solves a problem (the logic of problem
solving is declared in the program). The programmer
must know what relations hold between various
entities. (Examples: LISP, PROLOG, … etc.)
PROLOG
PROLOG: PROgramming in LOGic.
It was developed from a foundation of logical
theorem proving and originally used for research
in natural language processing
Its popularity has been mainly in the artificial
intelligence (AI), where it has been used in expert
systems, natural language, and intelligent
databases.
It is based on First Order Predicate Logic
Elements of a PROLOG program
Facts: A fact is an assertion that a particular
relation holds.
Examples on facts
Ali owns the book.
The relationship between Ali and the book is own.
Abdu likes apples.
The relationship between Abdu and apples is like.
Fatima is female.
The relationship between Fatimaand gender is female.
Every mother loves her children.
The relationship between mother and children is love.
Amina is the mother of Ali.
The relationship between Amina and Ali is mother.
Fact as a Relation
Relationship Object 1 Object 2

Own Ali Book

Like Abdu Apples

Female Fatima Gender

Love Mother Child

Mother Amina Ali


Elements of a PROLOG program

Rules: A rule is a fact whose truth value


depends on the truth value of other facts..
Examples of rules
Ahmed likes something if Omer likes it.
(i.e. Ahmed likes anything that Omer
likes)
Two persons are sisters if both are female
and they have the same parents.
Suhaib will pass if he gets more than
60%.
Elements of a PROLOG program

Goals: A goal is what is to be determined.


PROLOG attempts to match the goal with the facts
and rules within the program. If the goal is a fact,
PROLOG responds by its truth value. If goal
contains variables, PROLOG responds with values
that constitute a solution.
Examples on goals
What does Abdu like?
What does Ahmed own?
Is Fatima a female?
Are Suha and Ruba sisters?
FACT and RULES = Knowledge Base

Facts: don’t need to be proved,


accepted as is.
Rules: Truth value depends on the
truth value of the facts on which it
depends.
Predicate logic in PROLOG
(i) " Every mother loves her children"
(ii) Amina is the mother of Ali.

From the above we can conclude:


(iii ) Amina loves Ali
We need to define a syntax to express the
facts and formalize the rules:
Predicates
Facts Syntax
Zahra is Female female(Zahra).

Ali likes apples likes(Ali, apples).

Ahmed owns the book owns(ahmed, book).

Predicate name

Predicate arguments (objects)

Predicate End Indicator


Example Rules
Ahmed like anything Omer likes:
likes(Ahmed, X):- likes(Omer, X).
(:- Stands for if)
X and Y are sisters if: X and Y are female and have same parents:
sister_of(X, Y):-
female(X),
female(Y),
parents(X, F, M),
parents(Y, F, M).

The (,) stands for and


Example Goals
likes(Ali, X).

owns(ahmed, Y).

female(Fatima).

sister_of(suha, ruba).

sunny. This one can be a fact, a goal (a query!)

You might also like