Logic Programming - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Logic Programming

Description:

( car set1) set2) (overlap? ( cdr set1) set2) overlap(X,Y) :- member(M,X), member(M,Y) ... Correspondence between Horn clauses and predicates ... Horn Clauses ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 22
Provided by: sam73
Category:

less

Transcript and Presenter's Notes

Title: Logic Programming


1
Logic Programming
2
Announcements
  • Test No. 5 This Friday
  • Since Last Exam 50
  • Event-driven programming
  • Logic programming
  • Previous lessons 50
  • Emphasis on concepts that should carry over
    beyond the course
  • Hint Review missed questions in previous tests
  • Multiple Choice
  • Closed book closed notes
  • Homework 8 is also due

3
Logic Programming
  • Algorithm logic control
  • Lot of effort in programming is to manage control
  • Logic programming separates them
  • Use facts and rules to represent information
  • Use deduction to answer queries

4
Logic Programming
  • (define overlap?
  • (lambda (set1 set2)
  • (cond
  • ((null? set1) f)
  • (else (or
  • (member? (car set1) set2)
  • (overlap? (cdr set1) set2)))))))

overlap(X,Y) - member(M,X), member(M,Y).
5
Declarative Programming
  • Programmer declares the goals of the computation
  • Not the detailed algorithm by which the goals can
    be reached
  • Two major domains
  • Databases, e.g. SQL
  • Artificial intelligence (Prolog)
  • Logic Programming
  • Express the computation using mathematical logic
  • Motivated by natural language processing and
    automatic theorem proving

6
Logic Programming
  • Prolog is the principal language
  • Based on two powerful principles
  • Resolution
  • Unification
  • Two interesting features
  • Nondeterminism find multiple solutions
  • Backtracking part of the language

7
Propositional Logic
  • Provides the formal foundation for Boolean
    expressions in languages
  • Basic Rules

8
Propositional Logic
  • Precedence of operators
  • Negation, conjunction, disjunction, implication,
    equivalence
  • Propositions provide symbolic representation for
    logic expressions
  • Can be interpreted as true or false.

9
Propositional LogicExample
  • p Mary speaks Russian
  • q Bob speaks Russian
  • p?q Either Mary or Bob speak Russian
  • p?q Both Mary and Bob speak Russian
  • r Bob and Mary can communicate with each other
  • p?q?r true

10
Predicate Logic
  • Includes all of Propositional logic
  • Includes additional entities
  • Variables in various domains
  • Boolean valued functions
  • Quantifiers

11
Predicate LogicExamples
True if x is between 0 and 1 false otherwise
True if both speak Russian means x talks with y
True if everybody speaks Russian
True if for every person can speak a language
12
Properties of Predicate Logic
13
Predicate Logic
  • Tautology Propositions that are true for all
    possible values of variables
  • p?p
  • Satisfiability Predicates that are true for some
    particular assignment of variables
  • speaks(x,Russian) (not valid)
  • Validity Predicates that are true for all
    possible assignments of values to the variables
  • even(x)?odd(x)

14
Horn Clauses
  • Consists of two parts
  • Head (predicate)
  • Body (a set of predicates)
  • h is true if the predicates in the body are all
    true simultaneously
  • i.e. logical conjunction

15
Horn Clauses
  • Example
  • snowing(city)?precipitation(city),freezing(city)
  • Correspondence between Horn clauses and
    predicates
  • precipitation(city),freezing(city)? snowing(city)
  • Equivalent to
  • ?(precipitation(city)?freezing(city))?
    snowing(city)
  • ?precipitation(city) ?? freezing(city) ?
    snowing(city)

16
Horn Clauses
  • Underlying representation for Prolog
  • Any Horn clause can be written as a predicate
  • Not all predicates can be written as Horn clauses
  • Systematic procedure exists to convert a
    predicate into a Horn clause
  • Can be automated

17
Horn Clauses
  • Eliminate implication using the following rule
  • p?q is equivalent to ?p?q
  • Move negation inward in p using deMorgan and
    quantification properties so that only individual
    terms are negated
  • ?(p?q) is equivalent to ?p??q

18
Horn Clauses
  • Eliminate existential quantifiers
  • Replace the existentially quantified variable by
    a unique constant
  • ?x p(x) is replaced by p(c), c is a constant
  • Called skolemization
  • Move all universal quantifiers to the beginning
    of p and then drop them
  • Avoid naming conflicts
  • Does not change the meaning of p

19
Horn Clauses
  • Use Distributive, Associative and Commutative
    properties to convert p to a conjunctive normal
    form
  • Conjunction of disjunctions
  • Convert embedded disjunctions to implications in
    the Horn clause format

20
Horn ClausesExample
literate(x)?writes(x) literate(x)
?reads(x,y),book(y)
21
Horn ClausesExample
  • Conversion of a predicate to CNF does not
    guarantee a set of Horn clauses
  • Example
  • ?x(literate(x)?reads(x)?writes(x))
  • ?literate(x)?reads(x)?writes(x)
  • literate(x)?reads(x)?writes(x)
  • Not a single term (head) in the right
Write a Comment
User Comments (0)
About PowerShow.com