PROgramming LOGic

 The Logical Model  Introduction Unification  Backtracking Programming

What will be covered ?


Example: From Ghezzi p 385
The transitive closure of rel.

  1. relation(a,b).
  2. relation(a,c).
  3. relation(b,f).
  4. relation(f,g).
  5. closure(A,B) :- relation(A,B).
  6. closure(A,B) :- relation(A,Z), closure(Z,B).
Try  -> trace.  in prolog to view the execution steps.
See Brassard&Bratley problem 8.18
The  code below will abreviate relation to rel and closure to clos.
This is very similar to code presented page 631, Scott.


Queries


Consider the following prolog "code"
rel(a,b).
rel(a,c).
rel(b,f).
rel(f,g).
 
Implementation Consideration
  • Logical processors like Prolog are implemented in a procedure way.
  • Finding the variables which make the logic program true is an NP problem.
  • There are a number of different techniques to search/discover the variables
  • Prolog uses Backtracking
  • Depth first search of the solution space
  • Searching only feasible nodes
  • sound proof procedure
  • not complete
  • i.e. completeness = if there is a finite proof of the goal it will be found.

  • Control in Prolog

  • A prolog program contains
  • A sequence of clauses (forming the data base), and
  • a query of the form  A:- B1,B2, ... Bn
  • Program evaluation strategy: characterized by two decisions:
  • Goal order: Subgoals are processed left --> right
  • Rule order: Rules are applied top --> bottom

  •  The Search Space for clos(a,f)

    Figure 8.7 from Ghezzi & Jazayeri