1 / 247

Rule-Based Reasoning: Constraint Solving and Deduction

Rule-Based Reasoning: Constraint Solving and Deduction. Jacques Robin. Outline. Rules as a knowledge representation formalism Common characteristics of rule-based systems Roadmap of rule-based languages Common advantages and limitations

clovis
Télécharger la présentation

Rule-Based Reasoning: Constraint Solving and Deduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rule-Based Reasoning:Constraint Solving and Deduction Jacques Robin

  2. Outline • Rules as a knowledge representation formalism • 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 • Constraint Handling Rules (CHR) • Production Systems • Term Rewriting Systems • Logic Programming and Prolog

  3. Rules as a Knowledge Representation Formalism • What is a rule? • 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, • then a logico-temporal combination of actions can or must be executed by the agent, • directly on its environment (through actuators) or on the facts in its KB. • A KB agent such that the persistent part of its KB consists entirely of such rules is called a rule-base agent; • In such case, the inference engine used by the KB agent is an interpreter or a compiler for a specific rule language.

  4. Fact Base: • Volatile knowledge • Dependent on problem instance • Data Rule-Based Agent Environment Sensors Ask Tell Retract • Rule Engine: • Problem class independent • Only dependent on rule language • Declarative code interpreter or compiler Ask • Rule Base: • Persistant intentional knowledge • Dependent on problem class, not instance • Declarative code Effectors

  5. Rule Languages: Common Characteristics • Syntax generally: • Extends a host programming language and/or • Restricts a formal logic and/or • Uses a semi-natural language with • closed keyword set expressing logical connectives and actions classes, • and an open keyword set to refer to the entities and relations appearing in the agent’s fact base; • Some systems provide 3 distinct syntax layers for different users with automated tools to translate a rule across the various layers; • Declarative semantics: generally based on some formal logic; • Operational semantics: • Generally based on transition systems, automata or similar procedural formalisms; • Formalizes the essence of the rule interpreter algorithm.

  6. Rule Languages: General Advantages • 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 • Facilitates knowledge acquisition • Rules can be easily paraphrased in semi-natural language syntax, friendlier to experts averse to computational languages • Facilitates knowledge acquisition • Rule bases easy to formalize as logical formulas (conjunctions of equivalences and/or implications) • Facilitates building rule engine that perform sound, logic-based inference • Each rule largely independent of others in the base (but to precisely what degree depends highly of the rule engine algorithm) • Can thus be viewed as an encapsulated, declarative piece of knowledge; • Facilitates life cycle evolution and composition of knowledge bases • Very sophisticated, mature rule base compilation techniques available • Allows scalable inference in practice • Some engines for simple rule languages can efficiently handle millions of rules

  7. Rule Languages: General Limitations • Subtle interactions between rules hard to debug without: • sophisticated rule explanation GUI • detailed knowledge of the rule engine’s algorithm • Especially serious with: • Object-oriented rule languages for combining rule-based deduction or abduction with class-based inheritance; • Probabilistic rule languages for combining logical and Bayesian inference; • But purely logical relational rule language do not naturally: • Embed within mainstream object-oriented modeling and programming languages • Represent inherently procedural, taxonomic and uncertain knowledge • Current research challenge: • User-friendly reasoning engine for probabilistic object-oriented rules

  8. Classic Imperative OO Implementation Classic 3-Tier Information System Architecture Rule-Based Implementation Imperative OO Language GUI API Imperative OO Language GUI API GUI Layer Easier to reflect frequent policy changes than imperative code Embedded Production Rule Engine Production Rule Base Imperative OO Program Business Logic Layer Imperative OO Host Language Imperative OO Language SQL API Imperative OO Language SQL API Data Layer Generic Component Reusable in Any Application Domain Business Rules • Example of modern commercial application of rule-based knowledge representation

  9. Semi-Natural Language Syntaxfor Business Rules • Associate key word or key phrase to: • Each domain model entity or relation name • Each rule language syntactic construct • Each host programming language construct used in rules • Substitute in place of these constructs and symbols the associated words or phrase • 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 nono to W IF W is a missile THEN W is a weapon IF N is an enemy of America THEN N is hostile

  10. Rewrite Rules Logic Programming ISO Prolog Otter Concurrent Prolog Transaction Logic HiLog Production Rules EProver Courteous Rules Maude CLP(X) CCLP(X) CHR OPS5 ELAN Pure OO Languages Rule-Based Constraint Languages CHRV Frame Logic CHORD NeOPS Smalltalk UML QVT CLIPS C++ Flora MOF OCL Web Markup Languages JEOPS JESS Java SWSL OO Rule Languages RuleML XML XSLT Roadmap of Rule-Based Languages

  11. Constraint Handling Rules (CHR):Key Ideas • Originally a logical rule-based language to declaratively program specialized constraint solvers on top of a host programming language (Prolog, Haskell, Java) • Since evolved in a general purpose first-order knowledge representation language and Turing-complete programming language • Fact base contains both extensional and intentional knowledge in the form of a conjunction of constraints • Rule base integrates and generalizes: • Event-Condition-Action rules (themselves generalizing production rules) for constraint propagation • Conditional rewrite rules for constraint simplification • Relies on forward chaining and rule Left-Hand-Side (LHS) matching • Extended variant CHRV adds backtracking search and thus generalizes Prolog rules as well

  12. CHR by Example:Rule Base Defining  in Terms of = reflexivity@ X  Y <=> X = Y | true. asymmetry@ X  Y, Y  X <=> X=Y. % Constraint simplification (or rewriting) rules % Syntax: <ruleName>@ <simplifiedHead> <=> <guard> | <body> % Logically:Xvars(head  guard) % <guard>  (<head>  Yvars(body - (head  guard)) <body>) % Operationally: substitute in constraint store (knowledge base) constraints that match % the rule simplified head by those in rule body with their variables instantiated from % the match transitivity@ X  Y , Y  Z ==> X  Z. % Constraint propagation (or production) rule (in this case, unguarded) % Syntax: <ruleName>@ <propagatedHead> ==> guard | <body> % Logically:Xvars(head  guard) % <guard>  (<head>  Yvars(body - (head  guard)) <body>) % Operationally: if constraint store (knowledge base) contains constraints that match % the rule propagated head then add those in rule body to the store with their variables % instantiated from the match

  13. CHR by Example: Rule Base Defining  in Terms of = idempotence@ X  Y \ X Y <=> true. % Constraint simpagation rule (in this case, unguarded) % Syntax: <ruleName>@ <propagatedHead> \ <simplifiedHead> <=> guard | <body> % Logically:Xvars((head  guard) <propagatedhead>  <simplifiedHead>%  Yvars(body - (head  guard)) <body>  <propagatedhead> % Operationally: if constraint store (knowledge base) contains constraints that match % the rule simplified head and the rule propagated head, then substitute in the store% those matching the simplified head by the rule body with their variables instantiated% from the match query1: A  B, C  A, B  C, A = 2% Initial constraint store: a constraint conjunction answer1:A = 2, B = 2, C = 2, % Final constraint store = initial constraint store% simplified through repeated rule application until no rule neither simplifies nor% propagates any new constraint query2:A  B, B  C, C  A answer2:A = B, B = C

  14. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Rule-Defined Constraint Store Built-In Constraint Store Matching Equations  Guard

  15. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Condition for firing a rule: Rule head matches active constraint in RDCS Generates set of equations between variables and constants from the head and the constraint (inserted to MEG) Every other head from the rule matches against some other (partner) constraint in the RDCS Generates another set of equations (inserted to MEG) Rule r fires iff:X1,...,Xi  vars(MEGS  BICS - r) BICS  Y1,...,Yj  vars(r) MEG CHR by Example: Rule Base Defining  in Terms of = Active Constraint

  16. CHR by Example: Rule Base Defining  in Terms of = r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Normalizing Simplification Active Constraint

  17. r@ X  Y <=> X = Y | true.A,B A = 2 | X',Y' X' = A = Y' = B, eg, B = 3  2 = A a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint

  18. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Rule firing order depends on 3 heuristics, with the following priority: Rule-defined constraint ordering to become active Rule ordering to try matching and entailment check with active constraint Rule-defined constraint ordering to become partner constraints Engine first tries matching and entailment check for all rules with current active constraint, before trying any rule with the next constraint in the RDCS CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  19. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y A,B,C A = 2 | X',Y' X' = A, Y' = B = C, eg, B = 3  4 = C t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  20. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  21. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y A,B,C A = 2 | X',Y' X' = B = C, Y' = Aeg, B = 3  4 = C t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  22. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  23. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2 | X',Y', Z' X' = Z' = A, Y' = B = C, eg, B = 3  4 = C i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  24. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  25. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2 |= X'=C,Y'=2,Z'=B, X' = C, Y' = A, Z' = B i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  26. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of =

  27. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint

  28. r@ X  Y <=> X = Y | true.B,C A = 2 | X',Y' X' = Y' = B = C, eg, B = 3  2 = C a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint

  29. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  30. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=YA,B,C A = 2 | X',Y' X' = Y' = A = B = C, eg, B = 3  2 = C t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  31. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  32. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=YA,B,C A = 2 | X',Y' X' = Y' = A = B = C, eg, B = 3  2 = C t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  33. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  34. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2 | X',Y',Z' X' = C, Y' = A = B = Ceg, B = 3  2 = C i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  35. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  36. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2 | X',Y',Z' X' = A, Y' = B = C, Z' = Beg, B = 3  2 = C i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  37. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  38. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. A,B,C A = 2 | X',Y' X' = A = C, Y' = B, eg, C = 3  2 = A CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  39. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  40. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. A,B,C A = 2 | X',Y' X' = A = C, Y' = B, eg, C = 3  2 = A Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  41. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  42. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=YA,B,C A = 2 | X',Y' X' = Y' = A = B = Ceg, C = 3  2 = A t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  43. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  44. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y A,B,C A = 2 | X',Y' X' = C, Y' = A = Beg, B = 3  2 = A t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  45. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  46. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2 | X',Y',Z' X' = Y' = B = C, Z' = Aeg, B = 3  2 = C i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  47. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  48. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2 | X',Y',Z' X' = Y' = A = C, Z' = Beg, B = 3  2 = A i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  49. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

  50. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. A,B,C A = 2 | X',Y' X' = C, Y' = A = Beg, B = 3  2 = A CHR by Example: Rule Base Defining  in Terms of = Partner Constraint Active Constraint

More Related