Title: Logic Programming
1Logic Programming
2Roteiro
- 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
3Logic Programming a Versatile Metaphor
4Logic 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
5Logic 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
6Prolog
- 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
7Pure 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)
8Full 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
9Pure 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
10CFOL 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
11Clarks 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)
12Clarks 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
13SLD 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)
14Refutation 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
15SLD 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)
16SLD 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)
17SLD 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)
18SLD 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)
19SLD 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)
20SLD 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)
21SLD 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)
22SLD 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)
23SLD 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)
24SLD 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)
25SLD 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)
26SLD 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)
27SLD 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)
28SLD 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)
29SLD 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)
30SLD 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)
31SLD 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)
32SLD 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)
33SLD 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)
34SLD 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)
35SLD 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)
36SLD 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)
37SLD 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)
38SLD 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)
39SLD 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)
40SLD 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)
41SLD 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)
42SLD 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)
43SLD 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)
44SLD 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)
45SLD 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)
46SLD 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)
47SLD 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)
48SLD 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)
49SLD 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)
50SLD 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)
51SLD 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)
52SLD 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)
53SLD 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)
54SLD 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)
55Dual 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
56Logic 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!
57Limitations 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
58Limitation 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
59Prologs 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
60Prologs redundant sub-goal proofs
61Extensions 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
62Table 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
63SLG 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
64SLG 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
65SLG 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
66SLG 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
67SLG 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
68SLG 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
69SLG 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
70SLG 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
71SLG 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
72SLG 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
73SLG 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
74SLG 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
75SLG 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
76SLG 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
77SLG 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
78SLG 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
79SLG 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
80SLG 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
81SLG 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
82SLG 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
83SLG 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
84SLG 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
85SLG 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
86SLG 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
87SLG 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
88SLG 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
89SLG 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
90SLG 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
91SLG 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
92SLG 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
93SLG 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
94SLG 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
95SLG 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
96SLG 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
97SLG 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
98SLG 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
99HiLog 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
100HiLog 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
101HiLog
- 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
102HiLog 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
103Constraint 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
104CLP
- Integrate Prolog with constraint satisfaction and