Introduction to RuleBased Reasoning Jacques Robin Ontologies Reasoning
Introduction to Rule-Based Reasoning Jacques Robin Ontologies Reasoning Components Agents Simulations
Outline E Rules as a knowledge representation formalism E E E E Common characteristics of rule-based systems Roadmap of rule-based languages Common advantages and limitations Example practical application of rules: declarative business rules History of rule-based systems Production Systems Term Rewriting Systems Logic Programming and Prolog
Rules as a Knowledge Representation Formalism E What is a rule? E A statement that specifies that: If a determined logical combination of conditions is satisfied, over the set of an agent’s percepts and/or facts in its Knowledge Base (KB) that represent the current, past and/or hypothetical future of its environment model, its goals and/or its preferences, E then a logico-temporal combination of actions can or must be executed by the agent, E directly on its environment (through actuators) or on the facts in its KB. E E E A KB agent such that the persistent part of its KB consists entirely of such rules is called a rule-base agent; E In such case, the inference engine used by the KB agent is an interpreter or a compiler for a specific rule language.
Rule-Based Agent Fact Base: Ask Sensors • Volatile knowledge • Dependent on problem instance • Data Tell Environment Rule Engine: • Problem class independent • Only dependent on rule language • Declarative code interpreter or compiler Ask Rule Base: Effectors • Persistant intentional knowledge • Dependent on problem class, not instance • Declarative code Retract
Rule Languages: Common Characteristics E Syntax generally: E Extends a host programming language and/or E Restricts a formal logic and/or E Uses a semi-natural language with E closed keyword set expressing logical connectives and actions classes, E and an open keyword set to refer to the entities and relations appearing in the agent’s fact base; E Some systems provide 3 distinct syntax layers for different users with automated tools to translate a rule across the various layers; E Declarative semantics: generally based on some formal logic; E Operational semantics: E Generally based on transition systems, automata or similar procedural formalisms; E Formalizes the essence of the rule interpreter algorithm.
Rule Languages: General Advantages E Human experts in many domains (medicine, law, finance, marketing, administration, design, engineering, equipment maintenance, games, sports, etc. ) find it intuitive and easy to formalize their knowledge as a rule base E Facilitates knowledge acquisition E Rules can be easily paraphrased in semi-natural language syntax, friendlier to experts averse to computational languages E Facilitates knowledge acquisition E Rule bases easy to formalize as logical formulas (conjunctions of equivalences and/or implications) E Facilitates building rule engine that perform sound, logic-based inference E Each rule largely independent of others in the base (but to precisely what degree depends highly of the rule engine algorithm) E Can thus be viewed as an encapsulated, declarative piece of knowledge; E Facilitates life cycle evolution and composition of knowledge bases E Very sophisticated, mature rule base compilation techniques available E Allows scalable inference in practice E Some engines for simple rule languages can efficiently handle millions of rules
Rule Languages: General Limitations E Subtle interactions between rules hard to debug without: E sophisticated rule explanation GUI E detailed knowledge of the rule engine’s algorithm E Especially serious with: E Object-oriented rule languages for combining rule-based deduction or abduction with class-based inheritance; E Probabilistic rule languages for combining logical and Bayesian inference; E But purely logical relational rule language do not naturally: E Embed within mainstream object-oriented modeling and programming languages E Represent inherently procedural, taxonomic and uncertain knowledge E Current research challenge: E User-friendly reasoning engine for probabilistic object-oriented rules
Business Rules E Example of modern commercial application of rule-based knowledge representation Classic Imperative OO Implementation Classic 3 -Tier Information System Architecture Rule-Based Implementation Imperative OO Language GUI API GUI Layer Imperative OO Program Business Logic Layer Production Rule Base Imperative OO Language SQL API Data Layer Imperative OO Language SQL API Easier to reflect frequent policy changes than imperative code Embedded Production Rule Engine Generic Component Reusable in Any Application Domain Imperative OO Host Language
Semi-Natural Language Syntax for Business Rules E Associate key word or key phrase to: E Each domain model entity or relation name E Each rule language syntactic construct E Each host programming language construct used in rules E Substitute in place of these constructs and symbols the associated words or phrase E Example: “Is West Criminal? ” in semi-natural language syntax: IF P is American AND P sells a W to N AND W is a weapon AND N is a nation AND N is hostile THEN P is a criminal IF nono owns a W AND W is a missile THEN west sells W to nono IF W is a missile THEN W is a weapon IF N is an enemy of America THEN N is hostile
Roadmap of Rule-Based Languages Rewrite Rules Logic Programming ISO Prolog Otter Concurrent Prolog EProver Transaction Logic Courteous Rules Maude ELAN CLP(X) CCLP(X) Rule-Based Constraint Languages CHR Production Rules OPS 5 Pure OO Languages CHRV CHORD QVT Frame Logic Ne. OPS Flora Web Markup Languages SWSL Rule. ML XSLT Hi. Log XML JEOPS Smalltalk CLIPS C++ UML JESS Java MOF OO Rule Languages OCL
Rewrite Rules: Abstract Syntax Rewrite Rule Base * Rewrite Rule plus(X, 0) X RHS fib(suc(N))) plus(fib(suc(N)), fib(N)) LHS Term * args {disjoint, complete} Functional Term Function Symbol {disjoint, complete} Non-Functional Term Ground Term Constant Symbol Non-Ground Term Variable
Rewrite Rules: Operational Semantics : Rewrite Rule Base : Unifying Set of Pairs: - Instantiated Rule - Instantiated Sub-term [ Matching Pair Set Empty ] Unify LHS of Rewrite Rule Base against sub-terms of Term T : Term Pick one Pair Set [ Else ] [ Matching Pair Set Singleton ] : Pair - Instantiated Rule R - Instantiated Sub-Term S Substitute Sub-Term S in Term T by RHS of Rule R
Rewrite Rule Base Computation Example a) plus(X, 0) X b) plus(X, suc(Y)) suc(plus(X, Y)) c) fib(0) suc(0) d) fib(suc(0)) suc(0) e) fib(suc(N)) plus(fib(suc(N)), fib(N)) 1. fib(suc(suc(0)))) w/ rule e 2. plus(fib(suc(0))), fib(suc(0))) w/ rule d 3. plus(fib(suc(0))), suc(0)) w/ rule b 4. suc(plus(fib(suc(0))), 0)) w/ rule a 5. suc(fib(suc(0)))) w/ rule e 6. suc(plus(fib(suc(0)), fib(0))) w/ rule c 7. suc(plus(fib(suc(0)), suc(0))) w/ rule b 8. suc(plus(fib(suc(0)), 0))) w/ rule a 9. suc(fib(suc(0)))) w/ rule d 10. suc(suc(0)))
Conditional Rewrite Rules: Abstract Syntax Rewrite Rule Base Condition * Rewrite Rule RHS X=0 Y=0|X+Y 0 LHS * Equation 2 Term • Rule with matching LHS can only be fired if condition is also verified • Proving condition can be recursively done by rewriting it to true
Rewrite Rule Base Deduction Example: Is West Criminal? Rewrite Rule Base: a) b) c) d) e) criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P, N, W) sells(west, nono, W) owns(nono, W) missile(W) hostile(N) enemy(N, america) weapon(W) missile(W) owns(nono, m 1) missile(m 1) american(west) nation(nono) enemy(nono, america) true f) A B B A g) A A A Term: criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P, N, W) w/ rule a american(P) weapon(W) nation(N) hostile(N) owns(nono, W) missile(W) w/ rule b american(P) weapon(W) nation(N) enemy(N, america) owns(nono, W) missile(W) w/ rule c american(P) missile(W) nation(N) enemy(N, america) owns(nono, W) missile(W) w/ rule d american(P) missile(W) nation(N) enemy(N, america) owns(nono, W) w/ rule g
Rewriting Systems: Practical Application E Theorem proving E CASE: E Programming language formal semantics E Program verification ECompiler design and implementation E Model transformation and automatic programming E Data integration E Using XSLT an XML-based language to rewrite XML-based data and documents E Web server pages and web services (also using XSLT)
Production Rules: Abstract Syntax Production Rule Base * Production Rule 2. . * Action Operator: enum{add, delete} Fact Base And-Or Formula IF Fact Base Update Arithmetic Calculation Left-Hand Side (LHS) * Right-Hand Side (RHS) * Connective: enum{and, or} Atom Functor Predicate Symbol args Ground Atom Non-Functional Term Arithmetic Predicate Symbol Variable Constant Symbol Arithmetic Constant Symbol Fact (p(X, a) OR p(X, b)) AND p(Y, Z) AND q(c) AND X <> Y AND X > 3. 5 THEN Z = X + 12 AND add{r(a, c, Z} AND delete{p(Y, Z)}
Production System Architecture Fact Base Rule Base Candidate Rules Fact Base Management Component Pattern Matching Component Action Execution Component Host Language API Rule Firing Policy Component
Production Rules: Operational Semantics [Matching Instantiated Rule Set Empty] Match LHS of Rule Base against Fact Base Rule Base Matching Instantiated Rule Set [Else] Pick one Instantiated Rule to Fire Fact Base [Matching Instantiated Rule Set Singleton] Selected Instantiated Rule Execute in Sequence Actions in RHS of Selected Instantiated Rule
Conflict Resolution Strategies E Conflict resolution strategy: E Heuristic to choose at each cycle which of the matching rule set to fire E Common strategies: E Follow writing order of rules in rule base E Follow absolute priority level annotations associated with each rule or rule class E Follow relative priority level annotations associated with pairs of rules or rule classes E Prefer rules whose LHS match the most recently derived facts in the fact base E Prefer rules that have remained for the longest time unfired while matching a fact E Apply control meta-rules that declaratively specify arbitrarily sophisticated strategies
Production Rule Base Example: Is West Criminal? Production Rule Base: IF american(P) AND weapon(W) AND nation(N) AND hostile(N) AND sell(P, N, W) THEN add{criminal(P)} IF owns(nono, W) AND missile(W) THEN add{sells(west, nono, W) IF missile(W) THEN add{weapon(W)} IF enemy(N, america) THEN add{hostile(N)} Initial Fact Base: owns(nono, m 1) missile(m 1) american(west) nation(nono) enemy(nono, america) nation(america)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P, N, W) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(P) weapon(m 1) nation(N) hostile(N) sells(P, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(P) weapon(m 1) nation(N) hostile(N) sells(P, N, W) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(P) weapon(m 1) nation(N) hostile(nono) sells(P, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) owns(nono, W) enemy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(P) weapon(m 1) nation(N) hostile(nono) sells(P, N, W) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) owns(nono, m 1) enemy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(P) weapon(m 1) nation(N) hostile(nono) sells(P, N, W) sells(west, nono, m 1) american(west) missile(m 1) nation(nono) nation(america) enermy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(P) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) american(west) missile(m 1) nation(nono) nation(america) enermy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? criminal(west) weapon(m 1) hostile(nono) sells(west, nono, m 1) american(west) missile(m 1) nation(nono) nation(america) enermy(nono, america) owns(nono, m 1)
Production Rule Inference Example: Is West Criminal? criminal(west)? yes criminal(west) weapon(m 1) hostile(nono) sells(west, nono, m 1) american(west) missile(m 1) nation(nono) nation(america) enermy(nono, america) owns(nono, m 1)
Properties of Production Systems E Confluence: E From confluent rule base, same final fact base is derived independently of rule firing order E Makes values of queries made to the system independent of the conflict resolution strategy E Termination: E Terminating system does not enter in an infinite loop; E Example of non-termination production rule base: E Initial fact base: p(0) E Production rule base: IF p(X) THEN Y = X + 1 AND add{p(Y)} E Any production system which conflict resolution strategy does not prevent the same rule instance to be fired in two consecutive cycles is trivially non-terminating.
Production System Inference vs. Lifted Forward Chaining Common characteristics: E Data driven reasoning E Requires conflict resolution strategy to choose: E Which of several matching rules to fire E Which of several unifying clauses for next Modus Ponens inference step Production System Inference E Sequential conjunction of actions in rule RHS E Non-monotonic reasoning due to delete actions E Matching only Datalog atoms (i. e. , atoms which arguments are all nonfunctional terms) E Matching ground fact atoms against non-ground atoms in rule LHS And-Or atom E Neither sound nor complete inference engine Lifted Forward Chaining E Unique conclusion in Horn Clause E Monotonic reasoning E Unifying arbitrary first-order atoms, possibly functional E Unifying two arbitrary atoms, possibly both non-grounds E Sound and refutation-complete
Embedded Production System: Abstract Syntax Production Rule Base * Production Rule Right-Hand Side (RHS) Fact Base Update * Action Operator: enum{add, delete} Fact Left-Hand Side (LHS) And-Or Formula 2. . * Connective: enum{and, or} HPL Boolean Operation HPL Operator HPL Boolean Operator * args HPL Data Structure * Fact Base HPL Ground Data Structure
Generalized Production Rules: ECA Rules E Event-Condition-Action rule: extension of production rule with triggering event external to addition of facts in fact base E Only the rule subset which event just occurred is matched against the fact base E Events thus partition the rule base into subsets, each one specifying a behavior in response to a given events Event Condtion Action Rule LHS Event Agent’s Percept RHS HPL Boolean Operation
Production Rules vs. Rewriting Rules Common characteristics: E Data driven reasoning E Requires conflict resolution strategy to choose: E Which of several matching rules to fire E Which of several rules with an LHS unifying with a sub-term E Non-monotonic reasoning due to: E Fact deletion actions in RHS E Retraction of substituted sub-term E Tricky confluence and termination issues Production System Inference E Fact base implicitly conjunctive E Matching only Datalog atoms (i. e. , atoms which arguments are all nonfunctional terms) E Matching ground fact atoms against non-ground atoms in rule LHS And-Or atom Term Rewriting E Reified logical connectives in term provide full first-order expressivity E Unifying arbitrary first-order atoms, possibly functional E Unifying two arbitrary atoms, possibly both non-grounds
Logic Programming: a Versatile Metaphor Formal Software Specification Declarative Programming Automated Reasoning Logic Programming Formal Logic Theory Intelligent Databases
Logic Programming: Key Ideas Logical Theory Software Specification Declarative Programming Logical Formula Abstract Specification Declarative Program / Knowledge Data Structure Base Database Theorem Prover Specification Verifier Interpreter / Compiler Inference Engine Query Processor Theorem Proof Specification Verification Program Execution Inference Query Execution Single, Fixed, Problem-Independent Control Structure Inference Search Algorithm Query Processing Algorithm Theorem Verification Proving Algorithm Strategy Automated Reasoning Intelligent Databases
Logic programming vision E Single language with logic-based declarative semantics that is: E A Turing-complete, general purpose programming language E A versatile, expressive knowledge representation language to support deduction and other reasoning services useful for intelligent agents (abduction, induction, constraint solving, belief revision, belief update, inheritance, planning) E Data definition, query and update language for databases with built-in inference capabilities E "One tool solves all" philosophy: E Any computation = resolution + unification + search E Programming = declaring logical axioms (Horn clauses) E Running the program = query about theorems provable from declared axioms E Algorithmic design entirely avoided (single, built-in control structure) E Same language formal specification (modeling) and implementation E Same language for model checking and code testing
Prolog E First and still most widely used logic programming language E Falls short to fulfill the vision in many respect: E Many imperative constructs with no logical declarative semantics E No commercial deductive database available E Most other logic programming languages both: E Extend Prolog E Fulfill better one aspect of the logic programming vision E In the 80 s, huge Japanese project tried to entirely rebuild all of computing from ground up using logic programming as hardware basis
Pure Prolog: abstract syntax arg 0. . 1 body Definite Query +connective = head * Pure Prolog Atom predicate Definite Clause +connective = arg * * Pure * Prolog Term Functional Term functor Function-Free Term Symbol clauses Numerical Symbol Definite Logic Program +connective = c 11 (. . . , Xk 1, . . . ) : - p 11(. . . , Xi 1, . . . ), . . . , pm 1(. . . , Xj 1, . . . ). . c 1 n (. . . , Xkn, . . . ) : - p 1 n(. . . , Xin, . . . ), . . . , pmn(. . . , Xjn, . . . ). parent(al, jim) parent(jim, joe) anc(A, D) parent(A, D) anc(A, D) parent(A, P) anc(P, D) Variable
Full Prolog 0. . 1 Full Prolog Query arg Prolog Literal +connective = * body Full Prologl Clause +connective = Prolog Literal +connective = naf * Full Prolog Term Full Prolog Atom head predicate * Full Prolog Program +connective = arg Functional Term Function-Free Term functor Symbol Built-in Symbol User-Defined Symbol Variable Built-in Imperative Symbol Logical Symbol Numerical Meta-Programming I/O Predicate Search Customization Symbol Predicate Symbol Program Update Predicate Symbol Semantics of full Prolog: • Cannot be purely logic-base • Must integrate algorithmic
Pure Prolog program declarative formal semantics E Declarative, denotational, intentional: E Clark’s transformation to CFOL formula E First-order formula semantically equivalent to program E Declarative, denotational, extentional, model-theoretic: E Least Herbrand Model E Intersection of all Herbrand Models E Conjunction of all ground formulas that are deductive consequences of program
CFOL x Prolog Semantic Assumptions Classical First-Order Predicate Logic: E No Unique Name Assumption (UNA): two distinct symbols can potentially be paraphrases to denote the same domain entity E Open-World Assumption (OWA): If KB |≠ Q but KB |≠ Q , the truth value of Q is considered unknown E Ex: KB: true core(ai) true core(se) core(C) offered(C, T) true offered(mda, fall) Q: true offered(mda, spring) E OWA necessary for monotonic, deductively sound reasoning: If KB |= T then A, KB A |= T Logic Programming: E UNA: two distinct symbols necessarily denote two distinct domain entities E Closed-World Assumption (CWA): If KB |≠ Q but KB |≠ Q , the truth value of Q is considered false E Ex: ? - offered(mda, spring) fail E CWA is a logically unsound form of negatively abductive reasoning E CWA makes reasoning inherently non-monotonic as one can have: KB |= T but KB A |≠ T if the proof KB |= T included steps assuming A false by CWA E Motivation: intuitive, representational economy, consistent w/ databases
Clark’s completion semantics E Transform Pure Prolog Program P into semantically equivalent CFOL formula comp(P) E Same answer query set derived from P (abductively) than from FP (deductively) E Example P: core(se). core(ai). offered(mda, fall). offered(C, T) : - core(C). ? - offered(mda, spring) no ? - E 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) E Clark’s completion semantics comp(P): C, T, C 1, T 1 (core(C 1) (C 1=ai C 1=se)) (offered(C 1, T 1) (C 1=mda T 1=fall) ( C, T (C 1=C T 1=T core(C)))) (ai=se) (ai=mda) (ai=fall) (se=mda) (mda=fall)
Clark’s transformation E Axiomatizes closed-world and unique name assumptions in CFOL E Starts from naive Horn formula semantics of pure Prolog program E Partitions program in clause sets, each one defining one predicate (i. e. , group together clauses with same predicate c(t 1, . . . , tn) as conclusion) E Replaces each such set by a logical equivalence E One side of this equivalence contains c(X 1, . . . , Xn) where X 1, . . . , Xn are fresh universally quantified variables E The other side contains a disjunction of conjunctions, one for each original clause E Each conjunction is either of the form: E Xi = ci . . . Xj = ci, if the original clause is a ground fact E Yi. . . Yj Xi = Yi . . . Xj = Yj p 1(. . . ) . . . pn(. . . ) if the original clause is a rule with body p 1(. . . ) . . . pn(. . . ) containing variables Yi. . . Yj E Joins all resulting equivalences in a conjunction E Adds conjunction of the form (ci = cj) for all possible pairs (ci, cj) of constant symbols in pure Prolog program
SLD Resolution E SLD resolution (Linear resolution with Selection function for Definite logic programs): E Joint use of goal-driven set of support and input resolution heuristics E Always pick last proven theorem clause with next untried axiom clause E Always questions last pick even if unrelated to failure that triggered backtracking E A form of goal-driven backward chaining of Horn clauses seen as deductive rules E Prolog uses special case of SLD resolution where: E Axiom clauses tried in top to bottom program writing order E Atoms to unify in the two picked clauses: E Conclusion of selected axiom clause E Next untried premise of last proven theorem clause in left to right program writing order (goal) E Unification without occur-check E Generates proof tree in top-down, depth-first manner E Failure triggers systematic, chronological backtracking: E Try next alternative for last selection even if clearly unrelated to failure E Reprocess from scratch new occurrences of sub-goals previously proven true or false E Simple, intuitive, space-efficient, time-inefficient, potentially nonterminating (incomplete)
Refutation Resolution Proof Example Refutation proof principle: E To prove KB |= F E Prove logically equivalent: (KB F) |= True E 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, m 1)) //2 a (T missile(m 1)) //2 b (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/ 2 b unifying W/m 1: nation(N) hostile(N) sells(west, N, m 1) F //13 5. Solve 13 w/ 5 unifying N/nono: hostile(nono) sells(west, nono, m 1) F //14 6. Solve 14 w/ 8 unifying N/nono: enemy(nono, america) sells(west, nono, m 1) F //15 7. Solve 15 w/ 6: sells(west, nono, m 1) F //16 8. Solve 16 w/ 3 unifying W/m 1: owns(nono, m 1) missile(m 1) F //17 9. Solve 17 with 2 a: missile(m 1) F //18 10. Solve 18 with 2 b: F
SLD resolution example criminal(west)? criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(P) weapon(W) nation(N) hostile(N) sells(P, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west, N, W) sells(west, nono, W) missile(W) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west, N, W) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) hostile(N) sells(west, N, W) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) nation(america) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) nation(america) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example criminal(west)? yes criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) missile(m 1) american(west) missile(m 1) nation(nono) nation(america) enemy(nono, america) owns(nono, m 1) enermy(nono, america) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(america) nation(nono) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(america) nation(nono) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(america) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) nation(america) nation(nono) enemy(N, america) owns(nono, W) enermy(nono, america) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(america) hostile(america) sells(west, america, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(america) hostile(america) sells(west, america, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(america) hostile(america) sells(west, america, m 1) sells(west, nono, W) missile(m 1) owns(nono, W) enemy(america, america) american(west) missile(m 1) nation(america) nation(nono) enermy(nono, america) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(america) hostile(america) sells(west, america, m 1) sells(west, nono, W) enemy(america, america) missile(m 1) american(west) missile(m 1) fail nation(america) nation(nono) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(america) hostile(america) sells(west, america, m 1) sells(west, nono, W) backtrack missile(m 1) enemy(N, america) owns(nono, W) fail american(west) missile(m 1) nation(america) nation(nono) enermy(nono, america) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) backtrack hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(N) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(N) sells(west, N, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) enermy(nono, america) owns(nono, W) owns(nono, m 1)
SLD resolution example with bactracking criminal(west)? criminal(west) american(west) weapon(m 1) nation(nono) hostile(nono) sells(west, nono, m 1) sells(west, nono, W) missile(m 1) american(west) missile(m 1) enemy(N, america) nation(nono) enermy(nono, america) owns(nono, W) owns(nono, m 1)
Limitations of Pure Prolog and ISO Prolog For knowledge representation: representation E search customization: E No declarative constructs E Limited support procedimental constructs (cuts) E no support for uncertain reasoning E forces unintuitive rule-based encoding of inherently taxonomic and procedural knowledge E knowledge base updates nonbacktrackable and without logical semantics Eab : - assert(a), b. if b fails, a remains as true For programming: programming E no fine-grained encapsulation E no code factoring (inheritance) E poor data structures (function symbols as only construct) E mismatch with dominant objectoriented paradigm E not integrated to comprehensive software engineering methodology E IDE not friendly enough E scarce middleware E very scarce reusable libraries or components (ex, web, graphics) E mono-thread For declarative logic programming: E imperative numerical computation, I/O and meta-programming without logical semantics
Limitation of SLD resolution engines E Unsound: unification without occur-check E Incomplete: left-recursion E Correct ancestor Prolog program: anc(A, D) : - parent(A, D). anc(A, D) : - parent(P, D), anc(A, P). E 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). E Inefficient: E repeated proofs of same sub-goals E irrelevant chronological backtracking
Prolog’s imperative arithmetics fac(0, 1) : - !. fac(I, O) : - I 1 is I - 1, fac(I 1, O 1), O is I * O 1. ? - fac(1, X). X=1 ? - fac(3, X). X=6 ? - I 1 is I -1 error ? - I 1 = I -1 ? - I = 2, I 1 = I -1 I 1 = 2 -1 ? - I = 2, I 1 is I -1 I 1 = 1 E Arithmetic functions and predicates generate exception if queried with non-ground terms as arguments E is: requires a uninstantiated variable on the left and an arithmetic expression on the right E Relational programming property lost E Syntax more like assembly than functional ! E is: Prolog’s sole explicit variable assignment predicate (only for arithmetics) E =: is a bi-directional, generalpurpose unification query predicate
Prolog’s redundant sub-goal proofs
Extensions of pure Prolog Inductive LP Aleph Abductive LP Preference LP Functional LP Pure Prolog Constraint LP ISO Prolog High-Order LP XSB Tabled LP Transaction LP Frame (OO) LP Flora
Constraint Logic Programming (CLP) E CSP libraries’ strengths: E Specification level, declarative programming for predefined sets of constraints over given domains E Efficient E Extensive libraries cover both finite domain combinatorial problems and infinite numerical domain optimization problems ECSP libraries’ weaknesses: E Constraint set extension can only be done externally through API using general-purpose programming language E Same problem for mixed constraint problems (ex, mixing symbolic finite domain with real variables) Prolog’s strengths: EAllows specification level, declarative programming of arbitrary general purpose problems EA constraint is just a predicate ENew constraints easily declaratively specified through user predicate definitions E Mixed-domain constraints straightforwardly defined as predicate with arguments from different domains E Prolog’s weakness: ENumerical programming is imperative, not declarative EVery inefficient at solving finite domain combinatorial problem
CLP E Integrate Prolog with constraint satisfaction and solving libraries in a single inference engine E Get the best of both worlds: E E E 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 CLP Engine Prolog/L Bridge CLP Application Rule Base . . . Procedural Solver for Domain D 1 Procedural Solver for Domain Dk Solver Programming Language L
- Slides: 95