Logic Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Logic Programming

Description:

Basis for aborted attempt to Japanese to fully revolutionize all computing from ... of last proven theorem clause in left to right program writing order (goal) ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 107
Provided by: jacque4
Category:

less

Transcript and Presenter's Notes

Title: Logic Programming


1
Logic Programming
  • Jacques Robin

2
Roteiro
  • A unifying metaphor for computer science
  • Syntax
  • Pure Prolog abstract syntax
  • Full Prolog abstract syntax
  • Concrete syntax
  • Declarative semantics
  • Open x closed world hypothesis
  • Unique name hypothesis
  • Clarks completion
  • Least Herbrand model
  • Operational semantics
  • Lifted SLD resolution and backward chaining
  • Limitations
  • Of ISO Prolog
  • Of SLD resolution and pure backward chaining
  • Tabled logic programming
  • SLG resolution for pure Prolog
  • High order logic programming
  • HiLog abstract syntax
  • HiLog first-order semantics
  • Constraint logic programming
  • Limitations of CSP
  • CLP engine architeture
  • CLP abstract syntax
  • Operational semantics
  • Other extensions

3
Logic Programming a Versatile Metaphor
4
Logic Programming Key Ideas
Logical Theory Software Specification Declarative Programming Automated Reasoning Intelligent Databases
Logical Formula Abstract Specification Declarative Program / Data Structure Knowledge Base Database
Theorem Prover Specification Verifier Interpreter / Compiler Inference Engine Query Processor
Theorem Proof Specification Verification Program Execution Inference Query Execution
Theorem Proving Strategy Verification Algorithm Single, Fixed, Problem-Independent Control Structure Inference Search Algorithm Query Processing Algorithm
5
Logic programming vision
  • Single language with logic-based declarative
    semantics that is
  • A Turing-complete, general purpose programming
    language
  • A versatile, expressive knowledge representation
    language to support deduction and other reasoning
    services useful for intelligent agents
    (abduction, induction, constraint solving, belief
    revision)
  • Data definition, query and update language for
    databases with built-in inference capabilities
  • One tool solves all philosophy
  • Any computation resolution unification
    search
  • Programming declaring logical axioms (Horn
    clauses)
  • Running the program query about theorems
    provable from declared axioms
  • Algorithmic design entirely avoided (single,
    built-in control structure)
  • Same language for formal specification
    (modeling) and implementation
  • Same language for model checking and code
    testing

6
Prolog
  • First and still most widely used logic
    programming language
  • Falls short to fulfill the vision in many
    respect
  • Many imperative constructs with no logical
    declarative semantics
  • No commercial deductive database available
  • Most other logic programming languages both
  • Extend Prolog
  • Fulfills better one aspect of the logic
    programming vision
  • Basis for aborted attempt to Japanese to fully
    revolutionize all computing from ground up in the
    80s

7
Pure Prolog abstract syntax
arg


0..1
Pure Prolog Term

Pure Prolog Atom
arg

predicate
head
body
Function-Free Term
Functional Term
functor
Symbol
clauses
Numerical Symbol
Variable
c11 (...,Xk1,...) - p11(...,Xi1,...), ... ,
pm1(...,Xj1,...). ... c1n (...,Xkn,...) -
p1n(...,Xin,...), ... , pmn(...,Xjn,...).
  • parent(al,jim)
  • ? parent(jim,joe
  • ? anc(A,D) ? parent(A,D)
  • ? anc(A,D) ? parent(A,P) ? anc(P,D)

8
Full Prolog
arg
0..1

arg
Prolog Literal
Full Prolog Term

body
head
Functional Term
predicate
Function-Free Term
functor

Symbol
User-Defined Symbol
Variable
Built-in Symbol
Built-in Logical Symbol
Built-in Imperative Symbol
  • Semantics of full Prolog
  • Cannot be purely logic-based
  • Must integrate algorithmic ones

Meta-Programming Predicate Symbol
Numerical Symbol
I/O Predicate Symbol
Search Customization Predicate Symbol
Program Update Predicate Symbol
9
Pure Prolog program declarative formal semantics
  • Declarative, denotational, intentional
  • Clarks transformation to CFOL formula
  • First-order formula semantically equivalent to
    program
  • Declarative, denotational, extentional,
    model-theoretic
  • Least Herbrand Model
  • Intersection of all Herbrand Models
  • Conjunction of all ground formulas that are
    deductive consequences of program

10
CFOL x Prolog Semantic Assumptions
  • Classical First-Order Predicate Logic
  • No Unique Name Assumption (UNA) two distinct
    symbols can potentially be paraphrases to denote
    the same domain entity
  • Open-World Assumption (OWA) If KB ? Q but KB
    ? ?Q , the truth value of Q is considered
    unknown
  • Ex KB true ? core(ai) ? true ? core(se)
    ? core(C) ? offered(C,T) ?
    true ? offered(mda,fall)
  • Q true ? offered(mda,spring)
  • OWA necessary for monotonic, deductively sound
    reasoning If KB T then ?A, KB ? A T
  • Logic Programming
  • UNA two distinct symbols necessarily denote two
    distinct domain entities
  • Closed-World Assumption (CWA) If KB ? Q but KB
    ? ?Q , the truth value of Q is considered false
  • Ex ?- offered(mda,spring) fail
  • CWA is a logically unsound form of negatively
    abductive reasoning
  • CWA makes reasoning inherently non-monotonic as
    one can haveKB T but KB ? A ? Tif the
    proof KB T included steps assuming A false by
    CWA
  • Motivation intuitive, representational economy,
    consistent w/ databases

11
Clarks completion semantics
  • Transform Pure Prolog Program P into semantically
    equivalent CFOL formula comp(P)
  • Same answer query set derived from P
    (abductively) than from FP (deductively)
  • Example Pcore(se). core(ai).
    offered(mda,fall). offered(C,T) - core(C).
  • ?- offered(mda,spring)
  • no
  • ?-
  • Naive semantics naive(P)?C,T true ? core(ai)
    ? true ? core(se) ? true ?
    offered(mda,fall) ? core(C) ?
    offered(C,T) naive(P) ? ?offered(mda,spring)
  • Clarks completion semantics comp(P)
  • ?C,T,C1,T1
  • (core(C1) ? (C1ai ? C1se)) ?(offered(C1,T1) ?
    (C1mda ? T1fall) ? (?C,T (C1C
    ? T1T ? core(C)))) ??(aise) ? ?(aimda) ?
    ?(aifall) ? ?(sefall) ? ?(semda) ?
    ?(mdafall)
  • Fp ?offered(mda,spring)

12
Clarks transformation
  • Axiomatizes closed-world and unique name
    assumptions in CFOL
  • Start from naive Horn formula semantics of pure
    Prolog program
  • Partition program in clause sets, each one
    defining one predicate (i.e., group together
    clauses with same predicate c(t1, ..., tn) as
    conclusion)
  • Replace each such set by a logical equivalence
  • One side of this equivalence contains c(X1, ...,
    Xn) where X1, ..., Xn are fresh universally
    quantified variables
  • The other side contains a disjunction of
    conjunctions, one for each original clause
  • Each conjunction is either of the form
  • Xi ci ? ... ? Xj ci, if the original clause
    is a ground fact
  • ?Yi ... Yj Xi Yi ? ... ? Xj Yj ? p1( ...) ?
    ... ? pn( ... ) if the original clause is a rule
    with body p1( ...) ? ... ? pn( ... ) containing
    variables Yi ... Yj
  • Join all resulting equivalences in a conjunction
  • Add conjunction of the form ?(ci cj) for all
    possible pairs (ci,cj) of constant symbols in
    pure Prolog program

13
SLD Resolution
  • SLD resolution (Linear resolution with Selection
    function for Definite logic programs)
  • Joint use of input and goal-driven set of support
    heuristics
  • Always pick last proven theorem clause with next
    untried axiom clause
  • Always questions last pick even if unrelated to
    failure that triggered backtracking
  • A form of goal-driven backward chaining of Horn
    clauses seen as deductive rules
  • Prolog uses special case of SLD resolution where
  • Axiom clauses tried in top to bottom program
    writing order
  • Atoms to unify in the two picked clauses
  • Conclusion of selected axiom clause
  • Next untried premise of last proven theorem
    clause in left to right program writing order
    (goal)
  • Unification without occur-check
  • Generates proof tree in top-down, depth-first
    manner
  • Failure triggers systematic, chronological
    backtracking
  • Try next alternative for last selection even if
    clearly unrelated to failure
  • Reprocess from scratch new occurrences of
    sub-goals previously proven true or false
  • Simple, intuitive, space-efficient,
    time-inefficient, potentially non-terminating
    (incomplete)

14
Refutation Resolution Proof Example
  • Refutation proof principle
  • To prove KB F
  • Prove logically equivalent (KB ? F) True
  • In turn logically equivalent to (KB ? ? F)
    False
  • (american(P) ? weapon(W) ?
  • nation(N) ? hostile(N) ?
  • sells(P,N,W) ? criminal(P)) //1
  • ? (T ? owns(nono,m1)) //2a
  • ? (T ? missile(m1)) //2b
  • ? (owns(nono,W) ? missile(W) ?
    sells(west,nono,W)) //3
  • ? (T ? american(west)) //4
  • ? (T ? nation(nono)) //5
  • ? (T ? enemy(nono,america)) //6
  • ? (missile(W) ? weapon(W)) //7
  • ? (enemy(N,america) ? hostile(N))
    //8
  • ? (T ? nation(america)) //9
  • ? (criminal(west) ? F) //0

1. Solve 0 w/ 1 unifying P/westamerican(west) ?
weapon(W) ? nation(N) ?hostile(N) ?
sells(west,N,W) ? F //10 2. Solve
10 w/ 4weapon(W) ? nation(N) ? hostile(N)
?sells(west,N,W) ? F
//11 3. Solve 11 w/ 7 missile(W) ? nation(N)
? hostile(N) ?sells(west,N,W) ? F
//12 4. Solve 12 w/ 2b unifying
W/m1nation(N) ? hostile(N) ? sells(west,N,m1) ?
F //13 5. Solve 13 w/ 5 unifying
N/nonohostile(nono) ? sells(west,nono,m1) ? F
//14 6. Solve 14 w/ 8 unifying
N/nonoenemy(nono,america) ? sells(west,nono,m1)
? F //15 7. Solve 15 w/ 6 sells(west,nono,m1) ?
F //16 8. Solve 16 w/ 3 unifying W/m1
owns(nono,m1) ? missile(m1) ? F
//17 9. Solve 17 with 2a missile(m1) ? F
//18 10. Solve 18 with 2b F
15
SLD resolution example
criminal(west)?
criminal(P)
american(P)
weapon(W)
nation(N)
hostile(N)
sells(P,N,W)
sells(west,nono,W)
missile(W)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
16
SLD resolution example
criminal(west)?
criminal(west)
american(P)
weapon(W)
nation(N)
hostile(N)
sells(P,N,W)
sells(west,nono,W)
missile(W)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
17
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(W)
nation(N)
hostile(N)
sells(west,N,W)
sells(west,nono,W)
missile(W)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
18
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(W)
nation(N)
hostile(N)
sells(west,N,W)
sells(west,nono,W)
missile(W)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
19
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(W)
nation(N)
hostile(N)
sells(west,N,W)
sells(west,nono,W)
missile(W)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
20
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(W)
nation(N)
hostile(N)
sells(west,N,W)
sells(west,nono,W)
missile(W)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
21
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(W)
nation(N)
hostile(N)
sells(west,N,W)
sells(west,nono,W)
missile(W)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
22
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(W)
nation(N)
hostile(N)
sells(west,N,W)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
23
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,W)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
24
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
25
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
26
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
27
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
28
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
29
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
30
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,W)
missile(m1)
enemy(nono,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
31
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,W)
missile(m1)
enemy(nono,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
32
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,W)
missile(m1)
enemy(nono,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
33
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,W)
missile(m1)
enemy(nono,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
34
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,W)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
35
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
36
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
37
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
38
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
39
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
40
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
41
SLD resolution example
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
42
SLD resolution example
criminal(west)? yes
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,m1)
missile(m1)
enemy(nono,america)
owns(nono,m1)
missile(m1)
american(west)
nation(nono)
enermy(nono,america)
owns(nono,m1)
nation(america)
43
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
44
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
45
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(america)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
46
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(america)
hostile(america)
sells(west,america,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
47
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(america)
hostile(america)
sells(west,america,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
48
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(america)
hostile(america)
sells(west,america,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
49
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(america)
hostile(america)
sells(west,america,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
fail
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
50
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(america)
hostile(america)
sells(west,america,m1)
sells(west,nono,W)
backtrack
missile(m1)
enemy(N,america)
owns(nono,W)
fail
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
51
SLD resolution example with backtracking
criminal(west)?
criminal(west)
backtrack
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
52
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(N)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
53
SLD resolution example with backtracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(N)
sells(west,N,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
54
SLD resolution example with bactracking
criminal(west)?
criminal(west)
american(west)
weapon(m1)
nation(nono)
hostile(nono)
sells(west,nono,m1)
sells(west,nono,W)
missile(m1)
enemy(N,america)
owns(nono,W)
missile(m1)
american(west)
nation(america)
enermy(nono,america)
owns(nono,m1)
nation(nono)
55
Dual use of Prolog for AI
  • As knowledge representation language
  • As Turing-complete programming language

Inference Engine Implementing in
Prolog Reasoning R in formalism F
Knowledge Base Prolog Facts and Rules
Inference Engine Prolog Compiler/ Interpreter
Knowledge Base Sentences in formalism F
Ask
Ask
Tell
Tell
Retract
Retract
Inference Engine Prolog Compiler/ Interpreter
56
Logic vs. imperative and functional programming
  • Single relational definition
  • append(,L,L).
  • append(HT1,L,HT2) - append(T1,L,T2).
  • Usable as verification function
  • ?- append(a,b,c,a,b,c). -gt yes.
  • ?- append(a,b,c,a). -gt no.
  • Usable as function and its various input/output
    converse functions
  • ?- append(a,b,c,R). -gt R a,b,c.
  • ?- append(H,c,a,b,c). -gt H a,b.
  • Usable as constraint solver
  • ?- append(X,Y,a,b,c). -gt X , Y a,b,c
    -gt X a, Y b,c ...
  • Usable for enumeration
  • ?- append(X,Y,Z). -gt X , Y , Z -gt X
    _, Y , Z _ ...
  • Implements alone 8 different functions or methods!

57
Limitations of Pure Prolog and ISO Prolog
  • For programming
  • no fine-grained encapsulation
  • no code factoring (inheritance)
  • poor data structures (function symbols as only
    construct)
  • mismatch with dominant object-oriented paradigm
  • not integrated to comprehensive software
    engineering methodology
  • IDE not friendly enough
  • scarce middleware
  • very scarce reusable libraries or components (ex,
    web, graphics)
  • mono-thread
  • For declarative logic programming
  • imperative numerical computation, I/O and
    meta-programming without logical semantics
  • For knowledge representation
  • search customization
  • No declarative constructs
  • Limited support procedimental constructs (cuts)
  • no support for uncertain reasoning
  • forces unintuitive rule-based encoding of
    inherently taxonomic and procedural knowledge
  • knowledge base updates non-backtrackable and
    without logical semantics
  • ab - assert(a), b.if b fails, a remains as true

58
Limitation of SLD resolution engines
  • Unsound unification without occur-check
  • Incomplete left-recursion
  • Correct ancestor Prolog program
  • anc(A,D) - parent(A,D).
  • anc(A,D) - parent(P,D), anc(A,P).
  • Logically equivalent program (since conjunction
    is a commutative connective) that infinitely
    loops anc(A,D) - anc(A,P), parent(P,D).
    anc(A,D) - parent(A,D).
  • Inefficient
  • repeated proofs of same sub-goals
  • irrelevant chronological backtracking

59
Prologs imperative arithmetics
  • fac(0,1) - !.
  • fac(I,O) - I1 is I - 1,
  • fac(I1,O1), O is I O1.
  • ?- fac(1,X).
  • X 1
  • ?- fac(3,X).
  • X 6
  • ?- I1 is I -1
  • error
  • ?- I1 I -1
  • I1 I -1
  • ?- I 2, I1 I -1
  • I1 2 -1
  • ?- I 2, I1 is I -1
  • I1 1
  • Arithmetic functions and predicates generate
    exception if queried with non-ground terms as
    arguments
  • is requires a uninstantiated variable on the
    left and an arithmetic expression on the right
  • Relational programming property lost
  • Syntax more like assembly than functional !
  • is Prologs sole explicit variable assignment
    predicate (only for arithmetics)
  • is a bi-directional, general-purpose
    unification query predicate

60
Prologs redundant sub-goal proofs
61
Extensions of pure Prolog
Aleph
Inductive LP
Abductive LP
Preference LP
Functional LP
Pure Prolog
Constraint LP
ISO Prolog
XSB
High-Order LP
Tabled LP
Transaction LP
Flora
Frame (OO) LP
62
Table logic programming SLG resolution
  • Substitute goal stack by goal and answer table
    caching containing for each goal
  • Calling goal (parent in top-down proof tree)
  • Pointer to variant goal modulo
  • variable renaming, ex, p(f(X),Y) ? p(f(A),B)
  • or term subsumption, ex, p(X,g(d)) ? p(A,B)
  • Instantiated program clause which conclusion it
    unified with
  • Position of that clause in the program
  • All its answers
  • To prove goal G
  • Look for goal G variant of G in the table
  • If there is one, then use answers of G to
    answer G
  • Else backchain on G to get first answer to G
  • After finding such answer (or failing)
  • cache it in the table
  • backtrack to find all the other answers and cache
    them as well
  • Resume proof to next premise of calling goal

63
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1
64
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
65
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
66
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
67
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
68
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
69
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
70
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1
71
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1
5a parent(A,fay) 4a fail
72
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1 5a
5a parent(A,fay) 4a fail
73
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1 5a
4b 1b anc(A,fay) - parent(P,fay), anc(A,P) C2
5a parent(A,fay) 4a fail
74
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1 5a
4b 1b anc(A,fay) - parent(P,fay), anc(A,P) C2
5a parent(A,fay) 4a fail
6a parent(P,fay) 5 4b
75
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1 5a
4b 1b anc(A,fay) - parent(P,fay), anc(A,P) C2 6a
5a parent(A,fay) 4a fail
6a parent(P,fay) 5 4b
76
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1 5a
4b 1b anc(A,fay) - parent(P,fay), anc(A,P) C2 6a
5a parent(A,fay) 4a fail
6a parent(P,fay) 5 4b
7a anc(A,jim) 1b anc(A,jim) - parent(A,jim) C1
77
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A dan
  • A fay
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1 5a
4b 1b anc(A,fay) - parent(P,fay), anc(A,P) C2 6a
5a parent(A,fay) 4a fail
6a parent(P,fay) 5 4b
7a anc(A,jim) 1b anc(A,jim) - parent(A,jim) C1 8a
7b 1b anc(A,jim) - parent(P,jim), anc(A,P) C2 9a
8a parent(A,jim) 4a fail
9a parent(P,jim) 5 4b
78
SLG resolution for definite programs
  • anc(A,D) - parent(A,D). C1
  • anc(A,D) - parent(P,D), anc(A,P). C2
  • parent(fay,dan). C3
  • parent(jim,dan). C4
  • ?- anc(A,dan).
  • A fay
  • A jim
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - parent(A,dan) C1 2a, 2b
1b anc(A,dan) - parent(P,dan), anc(A,P) C2 fail
2a parent(A,dan) 1a parent(fay,dan) C3 A fay
2b 1a parent(jim,dan) C4 A jim
3a parent(P,dan) 2 1b
4a anc(A,fay) 1b anc(A,fay) - parent(A,fay) C1 5a
4b 1b anc(A,fay) - parent(P,fay), anc(A,P) C2 6a
5a parent(A,fay) 4a fail
6a parent(P,fay) 5 4b
7a anc(A,jim) 1b anc(A,jim) - parent(A,jim) C1 8a
7b 1b anc(A,jim) - parent(P,jim), anc(A,P) C2 9a
8a parent(A,jim) 4a fail
9a parent(P,jim) 5 4b
79
SLG resolution for definite programs
  • Avoids redundant repeated proofs of same subgoals
  • ex, calculates each fibonacci number exactly
    once
  • Also avoids left-recursive loops
  • The table allows detection of goal G that is a
    variant of the goal G that called it
  • Looping is avoided by suspending G and moving to
    the following goals of the clause body and then
    backpropagating to G the variable bindings
    necessary to prove these following goals
  • When G becomes sufficiently instantiated to no
    longer be a variant of G, its proof resumes

80
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
81
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
82
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
83
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
4a parent(P,P) 1a parent(fay,dan) C3 P fay
84
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
4a parent(P,P) 1a parent(fay,dan) C3 P fay, P dan
4b 1a parent(jim,dan) C4 P jim, P dan
85
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), anc(P,fay) C1
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
86
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
87
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
88
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
89
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
90
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
91
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
92
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
2b 1a anc(A,P) - parent(A,P) C2
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
93
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
2b 1a anc(A,P) - parent(A,P) C2
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay
4b 1a parent(jim,dan) C4 P jim
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
8a parent(A,P) 4a 4a,4b
94
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
2b 1a anc(A,P) - parent(A,P) C2 4a, 4b
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay, P dan
4b 1a parent(jim,dan) C4 P jim, P dan
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
8a parent(A,P) 4a 4a,4b
95
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
2b 1a anc(A,P) - parent(A,P) C2 4a, 4b
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay, P dan
4b 1a parent(jim,dan) C4 P jim, P dan
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
8a parent(A,P) 4a 4a,4b
9a parent(fay,dan) parent(fay,dan) yes
96
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1 4a
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
2b 1a anc(A,P) - parent(A,P) C2 4a, 4b
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay, P dan
4b 1a parent(jim,dan) C4 P jim, P dan
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
8a parent(A,P) 4a 4a,4b
9a parent(fay,dan) 1a parent(fay,dan) yes
97
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1 4a
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
2b 1a anc(A,P) - parent(A,P) C2 4a, 4b
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay, P dan
4b 1a parent(jim,dan) C4 P jim, P dan
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
8a parent(A,P) 4a 4a,4b
9a parent(fay,dan) 1a parent(fay,dan) yes
10a parent(jim,dan) 1a parent(jim,dan) yes
98
SLG resolution for definite programs
  • anc(A,D) - anc(A,P), parent(P,D). C1
  • anc(A,D) - parent(A,D). C2
  • parent(fay,dan).
    C3
  • parent(jim,dan).
    C4
  • ?- anc(A,dan).
  • A fay
  • A dan
  • no
  • ?-

gid goal vg cg instantiated rule rn answers
1a anc(A,dan) anc(A,dan) - anc(A.P), parent(P,dan) C1 4a, 4b
2a anc(A,P) 1a anc(A.P) - anc(A,P), parent(P,P) C1
2b 1a anc(A,P) - parent(A,P) C2 4a, 4b
3a anc(A,P) 2a 2a suspend fail
3b anc(A,fay) 3a anc(A,fay) - anc(A,P), parent(P,fay) C1 fail
3b 3a anc(A,fay) - parent(A,fay) C2 fail
4a parent(P,P) 1a parent(fay,dan) C3 P fay, P dan
4b 1a parent(jim,dan) C4 P jim, P dan
5a anc(A,P) 2a 3a suspend
6a parent(P,fay) 3a fail
7a parent(A,fay) 6a
8a parent(A,P) 4a 4a,4b
9a parent(fay,dan) 1a parent(fay,dan) yes
10a parent(jim,dan) 1a parent(jim,dan) yes
99
HiLog extending Prolog with high-order syntax
  • Meta-programming facilities of functional
    languages
  • Single language for reasoning and meta-reasoning
  • Schema browsing in databases
  • Examples of HiLog atomsthat are not Prolog
    atoms
  • P(a)
  • p(F(a)
  • f(a)(X,Y)
  • p(f(a)(X,Y))
  • P(F(X))(G(Y))

Prolog atoms
HiLog atoms
arg
arg


Prolog Atom
Prolog Term
predicate
HiLog Atom
HiLog Term

predicate
arg
arg

Function-Free Term
Function-Free Term
Functional Term
Functional Term
functor
functor
Variable
Variable
Symbol
Symbol
100
HiLog example
  • Prolog program
  • parent(bob, bill).parent(bill,
    mary).supervisor(john, mary).supervisor(mary,
    kathy).
  • anc(A,D) - parent(A,D).anc(A,D) - parent(A,C),
    anc(C,D).
  • boss(B,E) - supervisor(B,E).
  • boss(B,E) - supervisor(B,D), boss(D,E).
  • obeys(P,A) - anc(A,P).
  • obeys(P,A) - boss(A,P).
  • ?- obeys(mary,X).
  • Xbill Xbob X mary Xjohn no
  • More concise and extensible HiLog program
  • parent(bob, bill).parent(bill,
    mary).supervisor(john, mary).supervisor(mary,
    kathy).
  • relation(parent).relation(supervisor).
  • trans(R)(X, Y) - R(X, Y)trans(R)(X, Y) - R(X,
    Z), trans(R)(Z,Y).obeys(P)(A) - relation(R),
    trans(R)(A,P).
  • ?- obeys(mary)(X).Xbill Xbob X mary
    Xjohn no

101
HiLog
  • High-order syntax ...
  • ... but first-order semantics (and thus
    semi-decidable)
  • Why?
  • HiLog is merely a very convenient syntactic sugar
    since
  • All HiLog program can be translated into a barely
    legible, verbose but semantically equivalent
    Prolog program
  • How?
  • Axiomatize predicates and functions with single
    additional functor apply
  • Complex terms or variables as functors become
    first argument of apply
  • Arguments of these functors become second to last
    arguments of apply

102
HiLog to Prolog translation example
  • parent(bob, bill).
  • parent(bill, kathy).
  • supervisor(john, mary).
  • supervisor(mary, kathy).
  • relation(parent).
  • relation(supervisor).
  • trans(R)(X, Y) - R(X, Y)
  • trans(R)(X, Y) - R(X, Z), trans(R)(Z,Y).
  • obeys(P)(A) - relation(R), trans(R)(A,P)
  • ?- obeys(kathy)(X).Xbill Xbob X mary
    Xjohn no
  • parent(bob, bill).
  • parent(bill, kathy).
  • supervisor(john, mary).
  • supervisor(mary, kathy).
  • relation(parent).
  • relation(supervisor).
  • apply(trans(R),X,Y) - apply(R,X,Y).
  • apply(trans(R),X,Y) - apply(R,X,Y),
    apply(trans(R),Z,Y).
  • apply(obeys(P,A)) - relation(R),
    apply(trans(R),A,P)).
  • ?- apply(obeys(john),X).Xbill Xbob X mary
    Xjohn no

103
Constraint Logic Programming (CLP)
  • CSP libraries strengths
  • Specification level, declarative programming for
    predefined sets of constraints over given domains
  • Efficient
  • Extensive libraries cover both finite domain
    combinatorial problems and infinite numerical
    domain optimization problems
  • CSP libraries weaknesses
  • Constraint set extension can only be done
    externally through API using general-purpose
    programming language
  • Same problem for mixed constraint problems (ex,
    mixing symbolic finite domain with real
    variables)
  • Prologs strengths
  • Allows specification level, declarative
    programming of arbitrary general purpose problems
  • A constraint is just a predicate
  • New constraints easily declaratively specified
    through user predicate definitions
  • Mixed-domain constraints straightforwardly
    defined as predicate with arguments from
    different domains
  • Prologs weakness
  • Numerical programming is imperative, not
    declarative
  • Very inefficient at solving finite domain
    combinatorial problem

104
CLP
  • Integrate Prolog with constraint satisfaction and
Write a Comment
User Comments (0)
About PowerShow.com