Logic Programming Part 2: Semantics - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Logic Programming Part 2: Semantics

Description:

An B and B,C1,...,Cm D. Then A1 ... An,C1,...,Cm D. Proof search: To prove B, try to prove B False ... In Prolog, logic variables X,Y,Z can be substituted by ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 20
Provided by: jche6
Category:

less

Transcript and Presenter's Notes

Title: Logic Programming Part 2: Semantics


1
Logic Programming Part 2 Semantics
  • James Cheney
  • CS 411

2
Resolution
  • Resolution principle
  • If A1 ... An ? B and B,C1,...,Cm ? D
  • Then A1 ... An,C1,...,Cm ? D
  • Proof search
  • To prove B, try to prove B ? False
  • Apply resolution until LHS is empty.

3
Unification
  • In Prolog, logic variables X,Y,Z can be
    substituted by any other term
  • Unification Algorithm for finding substitution
    making two terms equal

4
Examples
  • f(X,Y,Z) f(g(Z),W)
  • unifies with X g(Z), W Y,Z
  • f(X,g(X)) f(2,g(Y))
  • Doesnt iunify X 2 and X g(Y) impossible

5
More Examples
  • f(X) X
  • Doesnt unify!
  • X f(X) f(f(X)) ...
  • f(X,Y) f(Y,g(X))
  • Doesnt unify! (Why?)

6
Example
f
f
X
Y
Y
g
X
7
Example
f
f
X
Y
Y
g
X
8
Example
X
Y
Y
g
X
9
Example
Answer X Y
Y
g
X
10
Example
Answer X Y
Y
g
Y
11
Example
Answer X Y Y g(Y)
12
Example
Answer X Y Y g(Y)
Problem In equation Y f(Y), Y
occurs circularly. There is no finite term
satisfying this equation. Checking that this is
not the case is called the occurs check. For
efficiency reasons, PROLOG skips this check.
13
Robinsons Algorithm
  • Consider a general unification problem
  • P t1 u1, t2 u2, ...
  • Reduce the problem by replacing one equation with
    a set of equations
  • Succeed if all equations reducible, else fail.

14
Robinsons Algorithm
  • Two constants unify if they are equal.
  • c c, P ? P
  • Else fail.

15
Robinsons Algorithm
  • Two function applications unify if the symbols
    are equal, and the corresponding arguments unify.
  • f(t1,...tn) f(u1,...,un), P ?
  • t1 u1,... tn un, P
  • Must have equal number of arguments

16
Robinsons Algorithm
  • Two variables unify if they are the same.
  • X X, P ? P

17
Robinsons Algorithm
  • Otherwise, a variable X unifies with a term t
    provided X does not occur in t.
  • X t, P ? Pt/X (if X not in FV(t))
  • Proceed by substituting t for X in P.

18
Operational Semantics
  • In general, we have
  • a program P clauses,
  • a goal G atomic goals,
  • and a substitution q Var ? Term
  • Base case If there are no goals then succeed
  • (P,,q) ? Yes q

19
Operational Semantics
  • Inductive case Suppose state is
  • (P,G,q) with G nonempty.
  • Pick a p(t1,...,tn) in G.
  • Assume clause p(u1,...,un) - G in P.
  • Assume q unifies p(t1,...,tn) and p(u1,...,un)
  • Then
  • (P,G,q) ? (P,qG, qq).
Write a Comment
User Comments (0)
About PowerShow.com