Logic Programming and Prolog - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

Logic Programming and Prolog

Description:

weird(MichaelJackson) cute(Russell) smart(x) hate(Michael, Microsoft) Predicate Calculus ... Computer Science: An Overview by Glenn Brookshear ... – PowerPoint PPT presentation

Number of Views:115
Avg rating:3.0/5.0
Slides: 52
Provided by: Joh7
Category:

less

Transcript and Presenter's Notes

Title: Logic Programming and Prolog


1
Logic Programming and Prolog
  • Stuart Howard
  • CS 550
  • Montana State University
  • December 5, 2003

2
Presentation Outline
  • Definition
  • History and background
  • Logical calculus
  • Resolution theorem proving
  • Prolog syntax and example program
  • Strengths and weaknesses
  • Summary and conclusions

3
Logic programming
  • based on symbolic logic
  • write declarations and infer the results
  • logic programming languages are declarative
    languages

4
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? (implementa
    tion)

5
The evolution of programming paradigms
figure from Brookshear
6
Lets sort a list nonprocedurally
  • permute(oldList, newList) Ù sorted(newList) gt
    sort(oldList, newList)
  • j such that 1 j lt n, list(j) list(j 1) gt
    sorted(list)
  • example from Sebesta

7
Prolog
  • Prolog Programmation en Logique
  • Early 70s
  • Alain Colmerauer and Phillipe Roussel
  • Robert Kowalski

8
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

9
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.

10
Prolog example
  • Shaun, the bull, and the tractor.

11
Logical calculus
  • language
  • inference rules
  • semantics

12
Propositional calculus
  • the language
  • atoms T, F, w w is a string and begins
  • with a capital letterH, On_A_B
  • connectives Ù, Ú, Ø, ?
  • rules for forming sentences (aka. well-formed
    formulas, wffs)

13
Rules for wffs
  • any atom is a wff
  • If w1 and w2 are wffs, so are w1 Ù w2
    conjunction w1 Ú w2 disjunction w1 ? w2
    implication
  • Ø w1 negation
  • there are no other wffs

14
more terms
  • literal atom or negated atom (P, Ø P)
  • w1 ? w2(antecedent) (consequent)

15
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)

16
Propositional calculus
  • the semantics
  • associate atoms with propositions about the
    world
  • Shaun_strong with Shaun is strong _____
    ____________ denotation
    __________________________________________
  • interpretation

17
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)

18
Propositional calculus
  • a new inference rule resolution
  • S1 ? S2 from a? S1 and Øa? S2
  • P Ú R from P Ú Q and R Ú ØQ
  • from a and Øa

19
Resolving (P OR Q) (R OR ? Q)
Brookshear
20
Resolving (P OR Q), (R OR ?Q), ?R
21
Why not?
  • Soundness - OK
  • Completeness not OK

22
Resolving (P OR Q), (R OR ?Q), ?R, ?P
Brookshear
23
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?

24
Predicate Calculus
  • Objects constants (names) or variables
  • Functions/relations constants (names)
  • weird(MichaelJackson)
  • cute(Russell)
  • smart(x)
  • hate(Michael, Microsoft)



25
Predicate Calculus
  • Quantifiers
  • Universal
  • Existential
  • Express properties of entire collections of
    objects

26
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

27
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

28
Predicate Calculus
  • " is a conjunction over the universe of objects
  • is a disjunction over the universe of objects

29
Predicate Calculus Example
  • The George W. Bush Family
  • mother(Barbara, George Jr.)
  • father(George Jr., Jenna)
  • father(George Jr., Barbara II)

30
Predicate Calculus Example
  • Q Barbara is the grandmother of whom?
  • " x " y "z mother(x, y) Ù parent(y, z) gt
    grandmother(x, z)
  • " x "y father(x,y) gt parent(x, y)
  • " x "y mother(x,y) gt parent(x, y)

31
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) gt
    grandmother(x, z)
  • " x "y father(x,y) gt parent(x, y)
  • " x "y mother(x,y) gt parent(x, y)

32
Resolution in Predicate Calculus
  • " x " y "z mother(x, y) Ù parent(y, z) gt
    grandmother(x, z)
  • mother(x, y) Ù parent(y, z) gt grandmother(x, z)
  • Ø mother(x, y) Ù parent(y, z) Ú grandmother(x,
    z)
  • Ø mother(x, y) Ú Ø parent(y, z) Ú grandmother(x,
    z)

33
Resolution in Predicate Calculus
  • " x "y father(x,y) gt parent(x, y)
  • father(a, b) gt parent(a, b)
  • Ø father(a, b) Ú parent(a, b)

34
Resolution in Predicate Calculus
  • " x "y mother(x,y) gt parent(x, y)
  • mother(c, d) gt parent(c, d)
  • Ø mother(c, d) Ú parent(c, d)

35
  • 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

36
Prolog Syntax
  • Rules
  • Facts
  • Goals
  • They are all variants of an implication!

37
Rule
  • General
  • a gt b
  • a Ù b Ù c gt d

Prolog b - a. d - a, b, c.
38
Fact
  • General
  • gt b

Prolog b.
39
Goal
  • General
  • b gt

Prolog b.
40
Horn what?
  • Ø a Ú Ø b Ú Ø c Ú d
  • (Ø a Ú Ø b Ú Ø c) Ú d
  • Ø (a Ù b Ù c) Ú d
  • a Ù b Ù c gt d

41
Horn what?
  • b
  • Ø Ú b
  • gt b

42
Horn what?
  • Ø a Ú Ø b Ú Ø c
  • Ø (a Ù b Ù c) Ú
  • a Ù b Ù c gt

43
More Prolog
44
1
2
4
5
3
6
45
1
2
4
3
5
6
7
46
Uses of logic programming
  • relational database management systems
  • expert systems
  • natural language processing

47
Weaknesses of Prolog
  • Resolution order control
  • Closed world assumption

48
Summary and Conclusions
  • Proponets say
  • Logical language gt logically organizedgt fewer
    errors, less maintenance
  • Programs concise gt less development time gt good
    prototyping language
  • Opponents say
  • BUNK!
  • http//www.mozart-oz.org/features.html

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

50
Thanks for staying awake!
51
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/Te
    aching/COMP313A/lecture_notes.html (6 excellent
    PowerPoint lectures on logic programming) Alain
    Colmerauer's web site (a cofounder of Prolog)
    History of Prolog Prolog compiler that ESUS
    uses
Write a Comment
User Comments (0)
About PowerShow.com