This document provides an introduction to the Prolog programming language. It discusses how Prolog differs from other languages by manipulating data according to defined relationships rather than using algorithms or procedures. It also describes some key aspects of Prolog including variables, goals/queries, rules, and examples of its applications in areas like expert systems and natural language processing. PDC Prolog is mentioned as an integrated development environment for writing and testing Prolog programs.
2. 11/18/2023
2
Introduction
Early 1970 in Marseilles, formed by Alain
Colmerauer.
In 1981 Japanese choose Prolog for the fifth
generation computers.
PROLOG (PROgraming in LOGic) is widely used
in Europe. Programing
LISP (LISt Processing).
Various Prolog compilers/programing environment
are available.
PDC prolog (previously turbo prolog) is typed.
3. 11/18/2023
3
Prolog Against Other Programing Languages
Languages such as C, Fortran and Basic are
procedural languages and use algorithms.
Prolog manipulates the data according to defined
procedures. It uses heuristics solve problems.
Prolog program is a collection of facts and
relationship. It uses no procedures to solve a
problem, it uses data about objects and relationship
to solve the problems.
The user defines the goal and the program find the
procedures and solution.
Prolog is not efficient at numerical processing but it
is most efficient at reasoning.
Prolog is good at inferring facts from given facts.
4. 11/18/2023
4
Applications of Prolog
It is most useful at AI programing. Application
includes:
Expert Systems.
Natural Language Processing.
Robotics.
Gamming.
5. 11/18/2023
5
PDC Prolog
Stand alone programs.
Some standard predicates.
Interface with other programing languages.
Arithmetic operations can be programed.
It has good working environment. Main windows
includes:
– Editor.
– Dialog.
– Message.
– Trace.
6. 11/18/2023
6
PDC Objects
Most important PDDC Prolog objects include:
char:
Single character written between quartinos. Example
‘a’, ‘y’ and ‘n’.
integer: integers of range (-37,368 to 32,767).
real: floating point number range (e-307
to e308
)
string: character sequences double written between
quartinos. Example “abc”, “SDF” and “aBc”.
symbol: character sequences of letters, numbers and
under scores. The first character must be small
character. Examples ali_hassan, page_1, cARS and
city_Sanaa
7. 11/18/2023
7
PDC Basic Sections (1/2)
PDC prolog program are divided into number of
sections. Basic ones will be discussed now, and others
will be introduced in the lap. and/or in the coming
lectures. Below are most basic ones:
Domains:
All objects type are defined in this section. In this
Domains Examples
person, item = symbol
price = real
replay = char
8. 11/18/2023
8
PDC Basic Sections (2/2)
Predicates:
In this section all facts and relevant objects are defined
except few built-in predicates.
Predicates Examples
own(person ,item) like(person, food, type)
Built-in Predicates Examples
save(string) write(arg_1, arg_2, arg_3)
Clauses:
Main PDC prolog program is written in this section. It
can include one or more fact/rule. All the facts that are
in the clauses section must be defined first in domains
and/or predicates sections in terms of relation name,
arguments number and type.
9. 11/18/2023
9
Variables
Objects in prolog can be given a variable name.
Variable names is a sequence of , numbers and under
scores. The first letter must be Capital letter.
Examples
Name
Price
City_1,
Variables is usually used in clauses section and may be
used in goal.
They get their type from the predicates.
10. 11/18/2023
10
How Variables Gets their Values
Variables gets their values by being matched to
constants in facts and/or rules.
When a variable gets a value it said to be bound.
When it is not bound it is said to be free.
It is important to not that, in prolog, variables for only
the time needed to obtain one solution. For this reason
we can not store information by giving a value to a
variable as we normally do in other programming
languages.
Anonymous Variables
Anonymous variable is a variable that is used in place
of any other variable with unknown value.
It is represented by underscore “_”
11. 11/18/2023
11
Prolog Goals (Queries)
To asking prolog a question we use goal section as
follows:
goal
predicate.
When asking prolog a question it tries to find answer.
In other words when prolog is given a query it means
that it is given a goal to accomplish.
Goals can be single or compound.
Single goal is when asking one question using one
predicates only.
Lets start with making single goal clear through an
example.
13. 11/18/2023
13
Compound Goals
Compound goal it means that prolog is asked to answer more
than one query.
Tow types of compound goals are used in prolog conjunction
an disjunction.
Conjunction goal:
When is set of facts separated by comma (,) which means and.
Example
owns(Person, pen), owns(Person, car).
This means is their a Person who owns pen and car.
Disjunction goals
When set of facts separated by semicolon (;) which means or.
Example
owns(Person, pen) ; owns(Person, car).
This means is their a Person who owns pen or a Person who
owns car
14. 11/18/2023
14
Prolog Rules
Prolog rules consists of two parts, head and body.
It takes the form of (if then), but differ totally than what is
used in other conventional programming languages.
The head is a conclusion that can be drawn provided that all
the facts in the body are proven to be true.
As an example look at the following expression:
This is a square if:
- It is a closed shape.
- It has four sides.
- All sides are equal.
- every side is perpendicular on the other
tow sides.
15. 11/18/2023
15
Prolog Rules
In Prolog, the previous example can be written as follows:
this_is(square):-
shape(closed),
- no_of_sides(4),
- all_sides(equal),
- relation_with other_sides(perpendicular)