logic programming and prolog
Download
Skip this Video
Download Presentation
Logic Programming and Prolog

Loading in 2 Seconds...

play fullscreen
1 / 51

Logic Programming and Prolog - PowerPoint PPT Presentation


  • 650 Views
  • Uploaded on

Cat(Spot) Mammal(Spot) . Cat(Rebecca) Mammal(Rebecca) . Cat(Felix) ... (Felix, Spot) Cat(Felix)) (Sister(Richard, Spot) Cat(Richard)) ...

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Logic Programming and Prolog' - Kelvin_Ajay


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
logic programming and prolog

Logic Programming and Prolog

Stuart Howard

CS 550

Montana State University

December 5, 2003

presentation outline
Presentation Outline
  • Definition
  • History and background
  • Logical calculus
  • Resolution theorem proving
  • Prolog syntax and example program
  • Strengths and weaknesses
  • Summary and conclusions
slide3
Logic programming
  • based on symbolic logic
  • write declarations and infer the results
  • logic programming languages are declarative languages
what does declarative mean
What does declarative mean?
  • Logic programmers write declarations describing relationships between entities
  • the ‘what’ vs. the ‘how’
  • what does the answer look like? (specification)

vs.

  • how do I exactly compute the answer?(implementation)
let s sort a list nonprocedurally
Let’s sort a list nonprocedurally

permute(oldList, newList) Ù sorted(newList) => sort(oldList, newList)

  • j such that 1 ≤ j < n, list(j) ≤ list(j + 1) => sorted(list)

example from [Sebesta]

prolog
Prolog

Prolog = Programmation en Logique

  • Early 70’s
  • Alain Colmerauer and Phillipe Roussel
  • Robert Kowalski
origins of prolog
Origins of Prolog

Q-systems – designed for machine natural language translation (Colmerauer)

  • used to construct automatic English-French translations
  • used in Canada to translate weather forecasts from English to French
first large prolog program
First large Prolog program

man-machine communication system –1972

TOUT PSYCHIATRE EST UNE PERSONNE.

CHAQUE PERSONNE QU'IL ANALYSE, EST MALADE.

*JACQUES EST UN PSYCHIATRE A *MARSEILLE.

EST-CE QUE *JACQUES EST UNE PERSONNE?

OU EST *JACQUES?

EST-CE QUE *JACQUES EST MALADE?

OUI.

A MARSEILLE.

JE NE SAIS PAS.

prolog example
Prolog example

Shaun, the bull, and the tractor.

logical calculus
Logical calculus
  • language
  • inference rules
  • semantics
propositional calculus
Propositional calculus

the language…

  • atoms: T, F, {w | w is a string and begins

with a capital letter}…H, On_A_B

  • connectives: Ù, Ú, Ø, →
  • rules for forming sentences(aka. well-formed formulas, wff’s)
rules for wff s
Rules for wff’s
  • any atom is a wff
  • If w1 and w2 are wff’s, so are:w1 Ù w2conjunctionw1 Ú w2disjunctionw1 →w2implication

Ø w1negation

  • there are no other wff’s
more terms
more terms…
  • literal: atom or negated atom (P, ØP)
  • w1 →w2(antecedent) (consequent)
propositional calculus15
Propositional calculus

the inference rules…(6 of them anyway)

  • w2 from w1 and w1 →w2 (modus ponens)
  • w1 Ù w2 from w1 and w2 (Ù introduction)
  • w2 Ù w1 from w1 Ù w2 (commutativity of Ù)
  • w1 from w1 Ù w2 (Ù elimination)
  • w1 Ú w2 from w1 or w2 (Ú introduction)
  • w1 from Ø(Øw1) (Ø elimination)
propositional calculus16
Propositional calculus

the semantics…

  • associate atoms with propositions about the world

Shaun_strong with “Shaun is strong”|_________________| denotation |__________________________________________|

interpretation

propositional calculus17
Propositional calculus

remember…?

  • literal: an atom or its negation

a new term!

  • clause: a set of literals with disjunction implied {P, Q, ØR} ≡ (P ÚQ ÚØR)
propositional calculus18
Propositional calculus

a new inference rule…resolution

S1 S2from{a} S1 and{Øa} S2

P ÚR from P ÚQ and R ÚØQ

{ } from{a} and {Øa}

why not
Why not?
  • Soundness - OK
  • Completeness – not OK
limitations
limitations…
  • Propositional calculus limits us to referring to ‘hard-coded’ propositions about the world.
  • What if we also want to refer to objects and propositions by name?
predicate calculus
Predicate Calculus

Objects: constants (names) or variables

Functions/relations: constants (names)

weird(MichaelJackson)

cute(Russell)

smart(x)

hate(Michael, Microsoft)

predicate calculus25
Predicate Calculus
  • Quantifiers
    • Universal
    • Existential
  • Express properties of entire collections of objects
predicate calculus26
Predicate Calculus
  • Universal quantifiers make statements about every object, "x

A cat is a mammal

"x Cat(x) ÞMammal(x)

Cat(Spot) Þ Mammal(Spot) Ù

Cat(Rebecca) Þ Mammal(Rebecca) Ù

Cat(Felix) Þ Mammal(Felix) Ù

Cat(Richard) Þ Mammal(Richard) Ù

Cat(John) Þ Mammal(John) Ù

… [Comp313A]

predicate calculus27
Predicate Calculus
  • Existential Quantifiers make statements about some objects, $x

Spot has a sister who is a cat

$x Sister(x, Spot) Ù Cat(x)

(Sister(Spot, Spot) Ù Cat(Spot)) Ú

(Sister(Rebecca, Spot) Ù Cat(Rebecca)) Ú

(Sister(Felix, Spot) Ù Cat(Felix)) Ú

(Sister(Richard, Spot) Ù Cat(Richard)) Ú

(Sister(John, Spot) Ù Cat(John)) Ú

… [Comp313A]

predicate calculus28
Predicate Calculus

"is a conjunction over the universe of objects

$is a disjunction over the universe of objects

predicate calculus example
Predicate Calculus Example

The George W. Bush Family

mother(Barbara, George Jr.)

father(George Jr., Jenna)

father(George Jr., Barbara II)

predicate calculus example30
Predicate Calculus Example

Q: Barbara is the grandmother of whom?

" x" y"z[mother(x, y) Ù parent(y, z) => grandmother(x, z)]

" x"y [father(x,y) => parent(x, y)]

" x"y [mother(x,y) => parent(x, y)]

predicate calculus example31
Predicate Calculus Example
  • mother(Barbara, George Jr.)
  • father(George Jr., Jenna)
  • father(George Jr., Barbara II)
  • " x" y"z[mother(x, y) Ù parent(y, z) => grandmother(x, z)]
  • " x"y [father(x,y) => parent(x, y)]
  • " x"y [mother(x,y) => parent(x, y)]
resolution in predicate calculus
Resolution in Predicate Calculus

" x" y"z[mother(x, y) Ùparent(y, z) => grandmother(x, z)]

mother(x, y) Ùparent(y, z) => grandmother(x, z)

Ø [mother(x, y) Ùparent(y, z)] Ú grandmother(x, z)

Ø mother(x, y) ÚØ parent(y, z) Ú grandmother(x, z)

resolution in predicate calculus33
Resolution in Predicate Calculus

" x"y [father(x,y) => parent(x, y)]

father(a, b) => parent(a, b)

Ø father(a, b) Úparent(a, b)

resolution in predicate calculus34
Resolution in Predicate Calculus

" x"y [mother(x,y) => parent(x, y)]

mother(c, d) => parent(c, d)

Ø mother(c, d) Úparent(c, d)

slide35
mother(Barbara, George Jr.)
  • father(George Jr., Jenna)
  • father(George Jr., Barbara II)
  • Ø mother(x, y) ÚØ parent(y, z) Ú grandmother(x, z)
  • Ø father(a, b) Úparent(a, b)
  • Ø mother(c, d) Úparent(c, d)
  • Ø grandmother(Barbara, Jenna)
  • Ø mother(Barbara, e) ÚØ parent(e, Jenna) [7, 4]
  • Ø mother(Barbara, f) ÚØ father(f, Jenna) [8, 5]
  • Ø father(George Jr., Jenna) [9, 1]
  • { }
prolog syntax
Prolog Syntax
  • Rules
  • Facts
  • Goals

They are all variants of an implication!

slide37
Rule

General

a => b

a Ù bÙ c => d

Prolog b :- a.

d :- a, b, c.

slide38
Fact

General

{ } => b

Prolog

b.

slide39
Goal

General

b => { }

Prolog

b.

horn what
Horn what?

Ø a Ú Ø b Ú Ø c Ú d

(Ø a Ú Ø b Ú Ø c) Ú d

Ø (a Ù bÙ c) Ú d

a Ù bÙ c => d

horn what41
Horn what?

b

Ø { } Ú b

{ } => b

horn what42
Horn what?

Ø a Ú Ø b Ú Ø c

Ø (a Ù bÙ c) Ú { }

a Ù bÙ c => { }

slide44
1

2

4

5

3

6

slide45
1

2

4

3

5

6

7

uses of logic programming
Uses of logic programming
  • relational database management systems
  • expert systems
  • natural language processing
weaknesses of prolog
Weaknesses of Prolog
  • Resolution order control
  • Closed world assumption
summary and conclusions
Summary and Conclusions

Proponets say…

  • Logical language => logically organized=> fewer errors, less maintenance
  • Programs concise => less development time => good prototyping language

Opponents say…

  • BUNK!

http://www.mozart-oz.org/features.html

presentation review
Presentation Review
  • Definition
  • History and background
  • Logical calculus
  • Resolution theorem proving
  • Prolog syntax and example program
  • Strengths and weaknesses
  • Summary and conclusions
references
References

Concepts of Programming Languages (Fourth Edition) by Robert Sebesta (An excellent overview of Prolog... very helpful!) Notes from CS 436 (Artificial Intelligence) Dr. John Paxton (My first introduction to predicate calculus and Prolog) Artificial Intelligence: A New Synthesis by Nils Nilsson (Excellent presentation of propositional and predicate calculus) Computer Science: An Overview by Glenn Brookshear (Nice short overview of logic programming and Prolog) Compiler Design by Reinhard Wilhelm and Dieter Maurer (Obtuse, highly mathemetized, and hard to read.... i.e. it's Greek to me) http://www.cs.waikato.ac.nz/Teaching/COMP313A/lecture_notes.html (6 excellent PowerPoint lectures on logic programming) Alain Colmerauer's web site (a cofounder of Prolog) History of PrologProlog compiler that ESUS uses

ad