Prolog programming language
History
• Kowalski: late 60’s Logician who showed logical proof can support
computation.
• Colmerauer: early 70’s Developed early version of Prolog for
natural language processing, mainly multiple parses.
• Warren: mid 70’s First version of Prolog that was efficient.
• The official ISO standard for Prolog was published in 1996.
• 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.“
• Emphasis on what rather than how
• It is widely used in the field of AI
Introduction
Introduction
Characteristics
• Prolog approximates first-order logic.
• Every program is a set of Horn clauses.
• Inference is by resolution.
• Search is by backtracking with unification.
• Basic data structure is term or tree.
• Variables are unknowns not locations.
• Prolog does not distinguish between inputs and outputs. It solves
relations/predicates.
Features
Features
Backtracking-
• prolog stores data in tree.
• It uses depth first search to find answers.
• In its attempt to prove a goal, Prolog sometimes goes
down a dead-end, at which point it needs to backtrack.
Features
• Prolog is major example of fourth generation programming
language supporting the declarative programming paradigm.
• In a declarative language the programmer specifies a goal to
be achieved the prolog system works out hoe to achieve it.
• Relational databases owe something to prolog
Current implementations
• There are several popular Prolog interpreters available. They
include:
• GNU Prolog (http://pauillac.inria.fr/vdiaz/gnuprolog/)
• SWI-Prolog (http://www.swi-prolog.org/)
• Visual Prolog
(http://www.visualprolog.com/vip6/Download/Default.htm)
• BProlog
(http://www.cad.mse.kyutech.ac.jp/people/zhou/bpr
• olog.html)
Weaknesses of prolog
• Lack of structure
• Issues with readability of Prolog code
• serious implications for the readability and
• declarativeness of code due to cut predicate (!).
• Inefficiency of Prolog code
• Logical imperfectness
Fundamentals
• Facts
• Rules
• Query
• Unification
• Resolution
• Backtracking
• Cuts and negations
Facts
• Facts are statements about what is true about a problem,
instead of instructions how to accomplish the solution.
• 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.
Syntax for facts declaration
• Names of relationship and objects must begin with a lowercase
letter.
• Relationship is written first (typically the predicate of the
sentence).
• Objects are written separated by commas and are enclosed by a
pair of round brackets.
• The full stop character ‘.’ must come at the end of a fact.
Rules
• Specifies under what conditions a tuple of values
satisfies a predicate.
• The basic building block of a rule is called an atom
• Atom :- Atom1, ..., Atomn
If each of Atom1,...,Atomn is true, then Atom is also
true.
Rules
• Rules specify:
• If-then conditions
• I use an umbrella if there is a rain
• use(i, umbrella) :- occur(rain).
• Generalizations
• All men are mortal
• mortal(X) :- man(X).
• Definitions
• An animal is a bird if it has feathers
• bird(X) :- animal(X), has_feather(X).
Prolog

Prolog

  • 1.
  • 2.
    History • Kowalski: late60’s Logician who showed logical proof can support computation. • Colmerauer: early 70’s Developed early version of Prolog for natural language processing, mainly multiple parses. • Warren: mid 70’s First version of Prolog that was efficient. • The official ISO standard for Prolog was published in 1996.
  • 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.“ • Emphasis on what rather than how • It is widely used in the field of AI Introduction
  • 4.
  • 5.
    Characteristics • Prolog approximatesfirst-order logic. • Every program is a set of Horn clauses. • Inference is by resolution. • Search is by backtracking with unification. • Basic data structure is term or tree. • Variables are unknowns not locations. • Prolog does not distinguish between inputs and outputs. It solves relations/predicates.
  • 6.
  • 7.
    Features Backtracking- • prolog storesdata in tree. • It uses depth first search to find answers. • In its attempt to prove a goal, Prolog sometimes goes down a dead-end, at which point it needs to backtrack.
  • 8.
    Features • Prolog ismajor example of fourth generation programming language supporting the declarative programming paradigm. • In a declarative language the programmer specifies a goal to be achieved the prolog system works out hoe to achieve it. • Relational databases owe something to prolog
  • 9.
    Current implementations • Thereare several popular Prolog interpreters available. They include: • GNU Prolog (http://pauillac.inria.fr/vdiaz/gnuprolog/) • SWI-Prolog (http://www.swi-prolog.org/) • Visual Prolog (http://www.visualprolog.com/vip6/Download/Default.htm) • BProlog (http://www.cad.mse.kyutech.ac.jp/people/zhou/bpr • olog.html)
  • 10.
    Weaknesses of prolog •Lack of structure • Issues with readability of Prolog code • serious implications for the readability and • declarativeness of code due to cut predicate (!). • Inefficiency of Prolog code • Logical imperfectness
  • 11.
    Fundamentals • Facts • Rules •Query • Unification • Resolution • Backtracking • Cuts and negations
  • 12.
    Facts • Facts arestatements about what is true about a problem, instead of instructions how to accomplish the solution. • 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.
  • 13.
    Syntax for factsdeclaration • Names of relationship and objects must begin with a lowercase letter. • Relationship is written first (typically the predicate of the sentence). • Objects are written separated by commas and are enclosed by a pair of round brackets. • The full stop character ‘.’ must come at the end of a fact.
  • 14.
    Rules • Specifies underwhat conditions a tuple of values satisfies a predicate. • The basic building block of a rule is called an atom • Atom :- Atom1, ..., Atomn If each of Atom1,...,Atomn is true, then Atom is also true.
  • 15.
    Rules • Rules specify: •If-then conditions • I use an umbrella if there is a rain • use(i, umbrella) :- occur(rain). • Generalizations • All men are mortal • mortal(X) :- man(X). • Definitions • An animal is a bird if it has feathers • bird(X) :- animal(X), has_feather(X).