Introduction
To
PROLOG
PREPARED BY-
SHOWKOT USMAN
ID: 15-02-01-008
DEPT. OF CSE
GUB
1
2
 Introduction
 CURRENT IMPLEMENTATIONS
 SWI_PROLOG
 Fundamentals of PROLOG
 Applications
 References
Objective
 Prolog is the most popular language of the logic
programing languages.
 It is goal based language, it has automatic
backtracking and uses recursion.
 Prolog stands for programmation en logique", or
programming in logic.“
3
Introduction
CURRENT
IMPLEMENTATIONS
There are several popular Prolog interpreters
available. They include:
1.GNU Prolog (http://pauillac.inria.fr/vdiaz/gnuprolog/)
2. Visual Prolog (http://www.visualprolog.com/vip6/Download/Default.htm)
3. Bprolog
(http://www.cad.mse.kyutech.ac.jp/people/zhou/bpr
olog.html)
4. SWI_PROLOG
4
 SWI-Prolog offers a comprehensive FREE
Software Prolog environment.
 Link for downloading:
http://www.swi-prolog.org/download/stable
 A Self-installing executable for Windows: swipl-win.exe
 Works on Windows XP
 LINUX versions are also available.
5
SWI_PROLOG
o Prolog is a logical and a declarative
programming language.
o The name itself, Prolog, is short for
Programming in Logics.
o Prolog is the major example of a fourth
generation
programming language supporting the
declarative programming paradigm.
6
What is Prolog ?
Applications of Prolog
Some applications of Prolog are:
 Intelligent data base retrieval
 Natural language understanding
 Expert systems
 Specification language
 Machine learning
 Robot planning
 Problem solving
7
1. Facts
2. Rules
3. Query
4. Variables
5. Unification
6. Resolution
8
Fundamentals
 The Prolog system uses the facts to work out how
to accomplish the solution by searching through
the space of possible solutions.
 It is defined by an identifier followed by an n-
tuple of constants.
 A relation identifier is referred to as a predicate
 When a tuple of values is in a relation we say the
tuple satisfies the predicate.
 Names of relationship and objects must begin
with a lowercase letter.
9
Facts
1. Specifies under what conditions a tuple of
values satisfies a predicate.
2. The basic building block of a rule is called an
atom
3. Atom :- Atom1, ..., Atomn
If each of Atom1,...,Atomn is true, then Atom is
also true.
10
Rules
There are two types of queries:
1.Ground Query
 edge(a,b)
 This query is called a ground query because it consists only of
value identifiers as parameters to the predicate.
 a ground query is posed we expect a yes/no answer.
2. Non Ground Query
 They have variables as parameters
 tedge(a,X)
11
Query
 Always begin with a capital letter
 ?- likes (john,X).
 ?- likes (john, Something).
 But not
 ?- likes (john,something)
12
Variables
Example
 Facts: ()
◦ likes(john,mary).
◦ likes(john,X). % Variables begin with capital
 Queries
◦ ?- likes(X,Y).
◦ X=john, Y=Mary. % hit “;” for more
◦ ?- likes(X,X).
◦ X=john.
13
 Prolog associates variables and values using a
process
known as unification
 Variables that receive a value are said to be
instantiated
14
Unification
Arithmetic in prolog
 Prolog provides a number of basic arithmetic tools.
 Arithmetic examples Prolog Notation
 6 + 2 = 8 8 is 6+2.
 6 *2 = 12 12 is 6*2.
 Answers to arithmetic questions by using ariables.
 For example:
?- X is 6+2.
X=8
15
References
 Artificial Intellegence & Expert System
DAN .W PATERSON
 www.swi-prolog.org/
 http://www.learnprolognow.org
16
Thank You
17

Artificial Intelligence and Expert System

  • 1.
  • 2.
    2  Introduction  CURRENTIMPLEMENTATIONS  SWI_PROLOG  Fundamentals of PROLOG  Applications  References Objective
  • 3.
     Prolog isthe most popular language of the logic programing languages.  It is goal based language, it has automatic backtracking and uses recursion.  Prolog stands for programmation en logique", or programming in logic.“ 3 Introduction
  • 4.
    CURRENT IMPLEMENTATIONS There are severalpopular Prolog interpreters available. They include: 1.GNU Prolog (http://pauillac.inria.fr/vdiaz/gnuprolog/) 2. Visual Prolog (http://www.visualprolog.com/vip6/Download/Default.htm) 3. Bprolog (http://www.cad.mse.kyutech.ac.jp/people/zhou/bpr olog.html) 4. SWI_PROLOG 4
  • 5.
     SWI-Prolog offersa comprehensive FREE Software Prolog environment.  Link for downloading: http://www.swi-prolog.org/download/stable  A Self-installing executable for Windows: swipl-win.exe  Works on Windows XP  LINUX versions are also available. 5 SWI_PROLOG
  • 6.
    o Prolog isa logical and a declarative programming language. o The name itself, Prolog, is short for Programming in Logics. o Prolog is the major example of a fourth generation programming language supporting the declarative programming paradigm. 6 What is Prolog ?
  • 7.
    Applications of Prolog Someapplications of Prolog are:  Intelligent data base retrieval  Natural language understanding  Expert systems  Specification language  Machine learning  Robot planning  Problem solving 7
  • 8.
    1. Facts 2. Rules 3.Query 4. Variables 5. Unification 6. Resolution 8 Fundamentals
  • 9.
     The Prologsystem uses the facts to work out how to accomplish the solution by searching through the space of possible solutions.  It is defined by an identifier followed by an n- tuple of constants.  A relation identifier is referred to as a predicate  When a tuple of values is in a relation we say the tuple satisfies the predicate.  Names of relationship and objects must begin with a lowercase letter. 9 Facts
  • 10.
    1. Specifies underwhat conditions a tuple of values satisfies a predicate. 2. The basic building block of a rule is called an atom 3. Atom :- Atom1, ..., Atomn If each of Atom1,...,Atomn is true, then Atom is also true. 10 Rules
  • 11.
    There are twotypes of queries: 1.Ground Query  edge(a,b)  This query is called a ground query because it consists only of value identifiers as parameters to the predicate.  a ground query is posed we expect a yes/no answer. 2. Non Ground Query  They have variables as parameters  tedge(a,X) 11 Query
  • 12.
     Always beginwith a capital letter  ?- likes (john,X).  ?- likes (john, Something).  But not  ?- likes (john,something) 12 Variables
  • 13.
    Example  Facts: () ◦likes(john,mary). ◦ likes(john,X). % Variables begin with capital  Queries ◦ ?- likes(X,Y). ◦ X=john, Y=Mary. % hit “;” for more ◦ ?- likes(X,X). ◦ X=john. 13
  • 14.
     Prolog associatesvariables and values using a process known as unification  Variables that receive a value are said to be instantiated 14 Unification
  • 15.
    Arithmetic in prolog Prolog provides a number of basic arithmetic tools.  Arithmetic examples Prolog Notation  6 + 2 = 8 8 is 6+2.  6 *2 = 12 12 is 6*2.  Answers to arithmetic questions by using ariables.  For example: ?- X is 6+2. X=8 15
  • 16.
    References  Artificial Intellegence& Expert System DAN .W PATERSON  www.swi-prolog.org/  http://www.learnprolognow.org 16
  • 17.