Ch1_2 CS3032
Ch1_2 CS3032
CS 3032
2
An Overview of SWI- PROLOG
3
Overview of Prolog
▪ It is a logic programming language, associated with artificial intelligence &
computational linguistics.
▪ Although there are other Logic Programming languages, by far the most widely
used is Prolog.
▪ The name stands for Programming in Logic.
▪ It benefits for rule based logical quarries.
▪ Features:
o Think differently not procedurally, in declaratively manner. **
o Good for rapid prototyping
o Useful in many AI apps
o Not efficient as, C
4
History of Prolog
1972
• First Prolog interpreter introduced by Alain
Colmerauer and Philippe Roussel
1977
• David H. D Warren implemented DEC 10 compiler
1980
• Definite clause grammars implemented by Pereire
and Warren
5
History of Prolog
1980/1990
• Prolog specifically grown in Japan and Europe
2005
• NASA used Prolog to program natural language
interface.
2011
• Parts of IBM’s Watson QA supercomputer were
coded in Prolog.
6
Applications of Prolog
▪ Processing a natural language text, to answer questions about its meaning,
translate it to another language.
▪ Advisory systems for legal applications
▪ Maintaining databases for the Human Genome project
▪ Automatic story generation
▪ Analyzing and measuring social networks
▪ Supporting the development of complex software systems
▪ Automatically generating legally correct licenses and other documents in multiple
languages
7
Prolog is much different from other programming
languages
- Declarative
- Recursion
- Relations
- Unification
8
Fundamental idea behind a Prolog program:
- Describe the situation of interest
- Ask a question
- Logically deduce new facts about the situation you described
- produce deductions back as answers
9
Basic Operators in Prolog
?- This is the system prompt. The prompt indicates that the Prolog
system is ready for the user to enter a sequence of one or
more goals, which must be terminated by a full stop.
write(…..). Display the content in side the brackets on the user’s screen.
10
Logic Operators in Prolog
Logic Prolog
Implication B→ A A :- B
Conjunction A˄B A ,B
Disjunction A˅B A ;B
11
Data objects in Prolog
1. Numbers
▪ Prolog allows the use of integers. They are written as any sequence of
numeral from 0 to 9, optionally by a + or – sign.
Example: 212
-55
+100
017
▪ Prolog allows the use of numbers with decimal points. They are written in
the same way as integers, but contain a single decimal point, anywhere except
an optional + or – sign.
Example: -12.36
40.1
+448.
12
Data objects in Prolog (contd.)
2. Atoms
▪ Atoms are constants that do not have numerical values. There are three
ways in which atoms can be written.
i. Any sequence of one or more letters (upper or lower case), numerals
and underscores, beginning with lowercase letter.
Example mary / temperatue_value / d3_ABCD
(but not Year / temperature-value / 456abcd )
iii. Any sequence of one or more special characters from a list that
includes the following
Example >= > +++
13
Data objects in Prolog (contd.)
3. Variables
▪ A variable is a name used to stand for a term that is to be determined. It
can be denoted by any sequence of one or more letters (upper or lower
case), numerals and underscores, beginning with an upper case letter or
underscore.
14
Data objects in Prolog (contd.)
4. Compound Terms
▪ These are fundamental elements of Prolog programs. A compound term is a
structured data type which begins with an atom, known as functor as well. It
is followed by a sequence of one or more arguments that are enclosed in
brackets and separated by commas.
15
Data objects in Prolog (contd.)
5. Lists
▪ Lists are written as an unlimited number of elements enclosed in square
brackets and separated by commas
16
Facts, Rules and Queries
17
Facts
A fact is a predicate expression that makes a declarative statement about the
problem domain. Whenever a variable occurs in a Prolog expression, it is assumed
to be universally quantified.
18
Rules
Rules are the conditional statements about objects and their relationships.
19
Facts & Rules in Prolog
?-likes(X,Y).
X=mary ,
Y=riya ; To get next solution
X=Jasun ,
Y=Dino . 21
Example 01: Change the following sentences into facts / rules
▪ Scooby is a dog.
▪ Millie is a cat.
22