Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

106
Ontologi es Reasonin g Component s Agents Simulatio ns Logic Programming Logic Programming Jacques Robin

Transcript of Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Page 1: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

OntologiesReasoningComponentsAgentsSimulations

Logic ProgrammingLogic Programming

Jacques Robin

Page 2: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

RoteiroRoteiro

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 Clark’s 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

Page 3: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

FormalLogic

Theory

IntelligentDatabases

FormalSoftware

Specification

AutomatedReasoning

DeclarativeProgramming

Logic Programming: Logic Programming: a Versatile Metaphora Versatile Metaphor

Logic Programming

Page 4: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Logic Programming: Key IdeasLogic 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

Page 5: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Logic programming visionLogic programming vision

Single language with logic-based declarative semanticslogic-based declarative semantics that is: A Turing-complete, general purpose programmingprogramming language A versatile, expressive knowledge representationknowledge representation language to

support deduction and other reasoning services useful for intelligent agents (abduction, induction, constraint solving, belief revision)

Data definition, query and update 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

Page 6: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

PrologProlog

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

Page 7: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Pure Prolog: abstract syntaxPure Prolog: abstract syntax

Pure Prolog Atom

arg

Definite Query+connective =

Definite Clause+connective =

headbody

0..1

Numerical Symbol

Pure Prolog Term

Function-Free TermFunctional Term

Variable

Symbol

functor

argpredicate *

*

**

Definite Logic Program+connective =

c11 (...,Xk

1,...) :- p11(...,Xi

1,...), ... , pm1(...,Xj

1,...)....c1

n (...,Xkn,...) :- p1

n(...,Xin,...), ... , pm

n(...,Xjn,...).

clauses

parent(al,jim) parent(jim,joe anc(A,D) parent(A,D) anc(A,D) parent(A,P) anc(P,D)

Page 8: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Full PrologFull Prolog

Full Prolog Atom

Prolog LiteralargFull Prolog Query

+connective =

Full Prologl Clause+connective =

head

body

0..1

User-Defined Symbol

Full Prolog Term

Function-Free TermFunctional Term

Variable

Symbol

functor

arg

predicate

**Prolog Literal

+connective = naf

Full Prolog Program+connective =

*

Built-in Symbol

Built-inLogical Symbol

Built-in Imperative Symbol

Meta-ProgrammingPredicate Symbol

NumericalSymbol

I/O Predicate Symbol

Program UpdatePredicate Symbol

Search CustomizationPredicate Symbol

Semantics of full Prolog:• Cannot be purely logic-based• Must integrate algorithmic ones

Page 9: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Pure Prolog program Pure Prolog program declarative formal semantics declarative formal semantics

Declarative, denotational, intentional: Clark’s 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

Page 10: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

CFOL x Prolog Semantic AssumptionsCFOL 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 have:KB |= T but KB A |≠ Tif the proof KB |= T included steps assuming A false by CWA

Motivation: intuitive, representational economy, consistent w/ databases

Page 11: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Clark’s completion semanticsClark’s 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 P:core(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)

Clark’s completion semantics comp(P):C,T,C1,T1

(core(C1) (C1=ai C1=se)) (offered(C1,T1) (C1=mda T1=fall) (C,T (C1=C T1=T core(C)))) (ai=se) (ai=mda) (ai=fall) (se=fall) (se=mda) (mda=fall)

Fp |= offered(mda,spring)

Page 12: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Clark’s transformationClark’s 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

Page 13: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD ResolutionSLD 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)

Page 14: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Refutation Resolution Proof ExampleRefutation 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/west:american(west) weapon(W) nation(N) hostile(N) sells(west,N,W) F //10

2. Solve 10 w/ 4:weapon(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/m1:nation(N) hostile(N) sells(west,N,m1) F //13

5. Solve 13 w/ 5 unifying N/nono:hostile(nono) sells(west,nono,m1) F //14

6. Solve 14 w/ 8 unifying N/nono:enemy(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

Page 15: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(P)

american(P) weapon(W) nation(N) hostile(N) sells(P,N,W)

criminal(west)?

missile(W) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 16: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(P) weapon(W) nation(N) hostile(N) sells(P,N,W)

criminal(west)?

missile(W) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 17: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(W) nation(N) hostile(N) sells(west,N,W)

criminal(west)?

missile(W) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 18: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(W) nation(N) hostile(N) sells(west,N,W)

criminal(west)?

missile(W) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 19: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(W) nation(N) hostile(N) sells(west,N,W)

criminal(west)?

missile(W) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 20: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(W) nation(N) hostile(N) sells(west,N,W)

criminal(west)?

missile(W) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 21: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(W) nation(N) hostile(N) sells(west,N,W)

criminal(west)?

missile(W) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 22: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(W) nation(N) hostile(N) sells(west,N,W)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 23: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,W)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 24: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 25: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 26: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 27: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 28: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 29: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 30: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 31: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 32: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 33: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 34: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,W)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,m1)

Page 35: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,m1)

Page 36: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america)owns(nono,m1)

sells(west,nono,m1)

Page 37: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america) owns(nono,m1)

sells(west,nono,m1)

Page 38: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america) owns(nono,m1)

sells(west,nono,m1)

Page 39: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america) owns(nono,m1)

sells(west,nono,m1)

Page 40: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america) owns(nono,m1)

sells(west,nono,m1)

Page 41: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america) owns(nono,m1)

sells(west,nono,m1)

Page 42: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example SLD resolution example

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)? yes

missile(m1) enemy(nono,america) owns(nono,m1)

missile(m1)american(west) nation(nono)

nation(america)

enermy(nono,america) owns(nono,m1)

sells(west,nono,m1)

Page 43: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 44: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 45: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(america) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 46: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 47: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 48: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 49: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

fail

Page 50: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

fail

backtrack

Page 51: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

backtrack

Page 52: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 53: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with backtrackingbacktracking

criminal(west)

american(west) weapon(m1) nation(nono) hostile(N) sells(west,N,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 54: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLD resolution example with SLD resolution example with bactrackingbactracking

criminal(west)

american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1)

criminal(west)?

missile(m1) enemy(N,america) owns(nono,W)

missile(m1)american(west)

nation(nono)

nation(america) enermy(nono,america)owns(nono,m1)

sells(west,nono,W)

Page 55: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Dual use of Prolog for AIDual use of Prolog for AI

As knowledge representationknowledge representation language

As Turing-complete programmingprogramming language

KnowledgeBase:

Prolog Facts and Rules

Inference Engine:Prolog

Compiler/Interpreter

Ask

Tell

Retract

KnowledgeBase:

Sentences in formalism F

Inference Engine

Implementing in Prologin Prolog

Reasoning R in formalism F

Ask

Tell

Retract

Inference Engine:Prolog

Compiler/Interpreter

Page 56: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Logic Logic vs.vs. imperative and functional imperative and functional programmingprogramming

Single relational definition:append([],L,L).append([H|T1],L,[H|T2]) :- append(T1,L,T2).

Usable as verification function: ?- append([a,b],[c],[a,b,c]). -> yes.?- append([a,b],[c],[a]). -> no.

Usable as function and its various input/output converse functions:?- append([a,b],[c],R). -> R = [a,b,c].?- append(H,[c],[a,b,c]). -> H = [a,b].

Usable as constraint solver:?- append(X,Y,[a,b,c]). -> X = [], Y = [a,b,c] ; -> X = [a], Y = [b,c] ...

Usable for enumeration: ?- append(X,Y,Z). -> X = [], Y =[], Z = [] ; -> X = [_], Y = [], Z = [_] ...

Implements alone 8 different functions or methods!

Page 57: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Limitations of Pure Prolog Limitations of Pure Prolog and ISO Prologand ISO Prolog

For knowledge representationknowledge 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

For programmingprogramming: 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 logicdeclarative logic programming:

imperative numerical computation, I/O and meta-programming without logical semantics

Page 58: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Limitation of SLD resolution enginesLimitation 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

Page 59: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Prolog’s imperative arithmeticsProlog’s 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 -1error?- I1 = I -1I1 = I -1?- I = 2, I1 = I -1I1 = 2 -1?- I = 2, I1 is I -1I1 = 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 Prolog’s sole explicit variable variable assignmentassignment predicate (only for arithmetics) = is a bi-directional, general-purpose unification queryquery predicate

Page 60: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Prolog’s redundant sub-goal proofsProlog’s redundant sub-goal proofs

Page 61: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Extensions of pure PrologExtensions of pure Prolog

Pure Prolog

ISO Prolog

High-Order LP

Functional LP

Constraint LP

Abductive LP

Transaction LP

Frame (OO) LP

Preference LP

Tabled LP

Inductive LP

XSB

Aleph

Flora

Page 62: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Table logic programming: SLG Table logic programming: SLG resolutionresolution

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

Page 63: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 64: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 65: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 66: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 67: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 68: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 69: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 70: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 71: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 72: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 73: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 74: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 75: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 76: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 77: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 78: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(A,D) :- parent(A,D). %C1anc(A,D) :- parent(P,D), anc(A,P). %C2parent(fay,dan). %C3parent(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

Page 79: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG 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

Page 80: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 81: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 82: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 83: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 84: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 85: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 86: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 87: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 88: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 89: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 90: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 91: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 92: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 93: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 94: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 95: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 96: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 97: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 98: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

SLG resolution for definite programsSLG resolution for definite programsanc(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

Page 99: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

HiLog: extending Prolog HiLog: extending Prolog with high-order syntaxwith high-order syntax

Meta-programming facilities of functional languages Single language for reasoning and meta-reasoning Schema browsing in databases

Prolog atoms HiLog atoms

PrologAtom

Prolog Term

Function-FreeTerm

Functional Term

VariableSymbol

functor

arg

predicate

*

*arg

HiLogAtom

HiLog Term

Function-FreeTerm

Functional Term

VariableSymbol

functor

arg

predicate

*

*arg

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))

Page 100: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

HiLog: exampleHiLog: 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).

X=bill; X=bob; X= mary; X=john; 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).X=bill; X=bob; X= mary; X=john; no

Page 101: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

HiLogHiLog

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

Page 102: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

HiLog to Prolog translation: exampleHiLog 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).X=bill; X=bob; X= mary; X=john; 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).X=bill; X=bob; X= mary; X=john; no

Page 103: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

Constraint Logic Programming (CLP)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)

Prolog’s strengths:Allows specification level,

declarative programming of arbitrary general purpose problems

A constraint is just a predicateNew constraints easily

declaratively specified through user predicate definitions

Mixed-domain constraints straightforwardly defined as predicate with arguments from different domains

Prolog’s weakness:Numerical programming is

imperative, not declarativeVery inefficient at solving finite

domain combinatorial problem

Page 104: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

CLPCLP

Integrate Prolog with constraint satisfaction and solving libraries in a single inference engine

Get the best of both worlds: Declarative user definition of arbitrary constraints Declarative definition of arbitrarily mixed constraints Declarative numerical and symbolic reasoning, seamlessly

integrated Efficient combinatorial and optimization problem solving Single language to program constraint satisfaction or solving

problems and the rest of the application

Page 105: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

CLP engine architectureCLP engine architecture

Page 106: Ontologies Reasoning Components Agents Simulations Logic Programming Jacques Robin.

CLP engine reasoning servicesCLP engine reasoning services