ontologies reasoning components agents simulations rule-based reasoning: constraint solving and...

254
Ontologi es Reasonin g Component s Agents Simulatio ns Rule-Based Reasoning: Rule-Based Reasoning: Constraint Solving and Constraint Solving and Deduction Deduction Jacques Robin

Post on 21-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

OntologiesReasoningComponentsAgentsSimulations

Rule-Based Reasoning:Rule-Based Reasoning:Constraint Solving and DeductionConstraint Solving and Deduction

Jacques Robin

Page 2: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

OutlineOutline

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

Page 3: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rules as a Rules as a Knowledge Representation Knowledge Representation

FormalismFormalism 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.

Page 4: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rule-Based AgentRule-Based Agent

Enviro

nm

ent

Sensors

Effectors

Rule Base:Rule Base:• Persistant intentional knowledge• Dependent on problem class, not instance• Declarative code

Ask

Fact Base:Fact Base:• Volatile knowledge• Dependent on problem instance• Data

Rule Engine:Rule Engine:• Problem class independent• Only dependent on rule language• Declarative code interpreter or compiler

Tell Retract

Ask

Page 5: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rule Languages: Common Rule Languages: Common CharacteristicsCharacteristics

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.

Page 6: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rule Languages: General AdvantagesRule 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

Page 7: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rule Languages: General LimitationsRule 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

Page 8: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Business Rules Business Rules

Example of modern commercial application of rule-based knowledge representation

GUI Layer

Data Layer

Business LogicLayer

Classic 3-TierInformation System

Architecture

Imperative OOProgram

Imperative OOLanguageSQL API

Imperative OOLanguageGUI API

ClassicImperative OOImplementation

Rule-Based Implementation

Imperative OOHost Language

EmbeddedProduction

RuleEngine

Imperative OOLanguageSQL API

Imperative OOLanguageGUI API

ProductionRule Base

Generic ComponentReusable in Any

Application Domain

Easier to reflect frequent policy changes

than imperative code

Page 9: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Semi-Natural Language SyntaxSemi-Natural Language Syntaxfor Business Rulesfor 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 W to nono

IF W is a missile THEN W is a weapon

IF N is an enemy of America THEN N is hostile

Page 10: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

OO RuleLanguages

NeOPS

JEOPS

CLIPS

JESS

XML

Web MarkupLanguages

CLP(X)

Rule-BasedConstraintLanguages

Roadmap of Rule-Based LanguagesRoadmap of Rule-Based Languages

XSLT

OPS5

ProductionRules

ISO Prolog

Logic Programming

TransactionLogic

HiLogConcurrentProlog

CourteousRules

CCLP(X)

FrameLogic

Flora

OCLMOF

UML

CHORD

RuleML

ELAN

Maude

Otter

EProver

RewriteRules

SWSL

CHRV

CHR

QVT

Java

Smalltalk

C++

Pure OOLanguages

Page 11: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Constraint Handling Rules (CHR):Constraint Handling Rules (CHR):Key IdeasKey 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

Page 12: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example:Rule Base Defining Rule Base Defining in Terms of = 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: Xvars(head guard) % <guard> (<head> Yvars(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: Xvars(head guard) % <guard> (<head> Yvars(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

Page 13: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

idempotence@ X Y \ X Y <=> true.% Constraint simpagation rule (in this case, unguarded)% Syntax: <ruleName>@ <propagatedHead> \ <simplifiedHead> <=> guard | <body>% Logically: Xvars((head guard) <guard> (<propagatedhead> <simplifiedHead>% Yvars(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 conjunctionanswer1: 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 Aanswer2: A = B, B = C

Page 14: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

A B, C A, B C A = 2

Matching Equations GuardBuilt-In Constraint StoreRule-Defined Constraint Store

Page 15: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Condition for firing a rule:1. Rule head matches active constraint in RDCS

Generates set of equations between variables and constants from the head and the constraint (inserted to MEG)

2. Every other head from the rule matches against some other (partner) constraint in the RDCS Generates another set of equations (inserted to MEG)

3. Rule r fires iff:X1,...,Xi vars(MEG BICS - r) BICS Y1,...,Yj vars(r) MEG

Rule RDCS BICS MEG

r? A B, C A, B C A = 2 X' = A, Y' = B, X' = Y'

Active Constraint

Page 16: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

r? A B, C A, B C A = 2 X' = A = Y' = B

Normalizing SimplificationActive Constraint

Page 17: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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.

Rule RDCS BICS MEG

r? A B, C A, B C A = 2 X' = A = Y' = B

Active Constraint

Page 18: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true. a@ X Y, Y X <=> X=Yt@ X Y, Y Z ==> X Z.i@ X Y \ X Y <=> true.

Rule firing order depends on 3 heuristics, with the following priority:1. Rule-defined constraint ordering to become active2. Rule ordering to try matching and entailment check with active constraint3. Rule-defined constraint ordering to become partner constraints

Engine first tries matching and entailment check: All rules with current active constraint, before trying any rule with the next constraint

in the RDCS; For all elements of the RDCS as partner for the first multi-headed rule that matches

the active constraint, before trying the next rule that matches the active constraint;

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = A, Y' = B, Y' = C, X' = AActive

Constraint

PartnerConstrain

t

Page 19: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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.

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = A, Y' = B = CActive

Constraint

PartnerConstrain

t

Page 20: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = C, Y' = A, Y' = A, X' = BActive

Constraint

PartnerConstrain

t

Page 21: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y (A,B,C A = 2 X',Y' X' = B = C Y' = A), eg, 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

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = B = C, Y' = AActive

Constraint

PartnerConstrain

t

Page 22: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = A, Y' = B, Y' = B, X' = CActive

Constraint

PartnerConstrain

t

Page 23: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y (A,B,C A = 2 X',Y' X' = A = C Y' = B), eg, C = 3 2 = A

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = A = C, Y' = BActive

Constraint

PartnerConstrain

t

Page 24: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = B, Y' = C, Y' = A, X' = BActive

Constraint

PartnerConstrain

t

Page 25: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y (A,B,C A = 2 X',Y' X' = B Y' = A = C), eg, C = 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

Rule RDCS BICS MEG

a? A B, C A, B C A = 2 X' = B, Y' = A = CActive

Constraint

PartnerConstrain

t

Page 26: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t? A B, C A, B C A = 2 X' = A, Y' = B, Y' = C, Z' = AActive

Constraint

PartnerConstrain

t

Page 27: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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.

Rule RDCS BICS MEG

t? A B, C A, B C A = 2 X' = Z' = A, Y' = B = CActive

Constraint

PartnerConstrain

t

Page 28: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t? A B, C A, B C A = 2 X' = C, Y' = A, Y' = A, Z' = BActive

Constraint

PartnerConstrain

t

Page 29: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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 Z' = B, e.g., X'=C,Y'=2,Z'=B

i@ X Y \ X Y <=> true.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t? A B, C A, B C A = 2 X' = C, Y' = A, Z' = BActive

Constraint

PartnerConstrain

t

Page 30: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

A B, C A, B C, C B

A = 2

Page 31: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

For a given active constraint: a matching multi-headed propagation rule is reapplied with all matching

partner constraints, before any other rule is tried; in contrast, a matching multi-headed simplification or simpagation rule is

applied only once with the first matching partner constraint, and then engine moves on to the next rule

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t? A B, C A, B C, C B

A = 2 X' = A, Y' = B, Y' = B, Z' = C

ActiveConstrain

t

PartnerConstrain

t

Page 32: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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 Z' = B, e.g., X'=A,Y'=B, Z'=C

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t? A B, C A, B C, C B

A = 2 X' = A, Y' = B, Z' = C

ActiveConstrain

t

PartnerConstrain

t

Page 33: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

A B, C A, B C, C B, A C

A = 2

Page 34: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Attempt to reapply same propagation rule matching same pair of active and partner constraints with same head pair but swapped assignments: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = B, Y' = C, Y' = A, Z' = B

ActiveConstrain

t

PartnerConstrain

t

Page 35: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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' = B Y' = A = C), eg, A = 2 4 = C

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = Z' = B, Y' = A = C

ActiveConstrain

t

PartnerConstrain

t

Page 36: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = A, Y' = B, Y' = C, Z' = B

ActiveConstrain

t

PartnerConstrain

t

Page 37: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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' = Z' = B = C), eg, B = 3 4 = C

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = A, Y' = Z' = B = C

ActiveConstrain

t

PartnerConstrain

t

Page 38: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B, Y' = A, Z' = B

ActiveConstrain

t

PartnerConstrain

t

Page 39: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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' = Z' = A = B), eg, A = 2 3 = B

i@ X Y \ X Y <=> true.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = Z' = A = B

ActiveConstrain

t

PartnerConstrain

t

Page 40: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = A, Y' = B, Y' = A, Z' = C

ActiveConstrain

t

PartnerConstrain

t

Page 41: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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 = B Z' = C ), eg, A = 2 3 = B

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = Y' = A = B, Z' = C

ActiveConstrain

t

PartnerConstrain

t

Page 42: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = A, Y' = C, Y' = A, Z' = B

ActiveConstrain

t

PartnerConstrain

t

Page 43: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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' = B ), eg, A = 2 4 = C

i@ X Y \ X Y <=> true.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

t? A B, C A, B C, C B, A C

A = 2 X' = Y' = A = C, Z' = B

ActiveConstrain

t

PartnerConstrain

t

Page 44: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A, Y' = B, X' = C, Y' = A

ActiveConstrain

t

PartnerConstrain

t

Page 45: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y', Z' X' = Y' = Z' = A = B = C ), eg, A = 2 4 = C

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = Y' = A = B = C

ActiveConstrain

t

PartnerConstrain

t

Page 46: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = A, X' = A, Y' = B

ActiveConstrain

t

PartnerConstrain

t

Page 47: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y', Z' X' = Y' = Z' = A = B = C ), eg, A = 2 4 = C

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = Y' = A = B = C

ActiveConstrain

t

PartnerConstrain

t

Page 48: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A, Y’ = B, X’ = B, Y’ = C

ActiveConstrain

t

PartnerConstrain

t

Page 49: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y‘ X' = Y' = A = B = C ), eg, A = 2 4 = C

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A = B = Y’ = C

ActiveConstrain

t

PartnerConstrain

t

Page 50: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = B, Y' = C, X’ = A, Y’ = B

ActiveConstrain

t

PartnerConstrain

t

Page 51: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y' X' = Y' = A = B = C ), eg, A = 2 4 = C

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = Y' = A = B = C

ActiveConstrain

t

PartnerConstrain

t

Page 52: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A, Y’ = B, X’ =C, Y’ = B

ActiveConstrain

t

PartnerConstrain

t

Page 53: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y‘ X' = A = C, Y’ = B), eg, A = 2 4 = C

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A = C, Y’ = B

ActiveConstrain

t

PartnerConstrain

t

Page 54: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B, X’ = A, Y’ = B

ActiveConstrain

t

PartnerConstrain

t

Page 55: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y' X' = A = C,Y’ = B ), eg, A = 2 4 = C

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A = C, Y' = B

ActiveConstrain

t

PartnerConstrain

t

Page 56: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A, Y’ = B, X’ =A, Y’ = C

ActiveConstrain

t

PartnerConstrain

t

Page 57: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y‘ X' = A, Y’ = B = C), eg, B = 3 4 = C

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A, Y’ = B = C

ActiveConstrain

t

PartnerConstrain

t

Page 58: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A, Y' = C, X’ = A, Y’ = B

ActiveConstrain

t

PartnerConstrain

t

Page 59: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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. (A,B,C A = 2 X',Y' X' = A, Y’ = B = C), eg, B = 3 4 = C

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

i? A B, C A, B C, C B, A C

A = 2 X' = A, Y' = B = C

ActiveConstrain

t

PartnerConstrain

t

Page 60: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Heuristic to choose next active constraint after processing of active constraint A added to the store constraints N1, ... Nn

N1, ... , Nn in order

Constraints O1, ... , Om present in the store before processing A

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B, X' = Y'

ActiveConstrain

t

Page 61: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true. (A,B,C A = 2 X',Y' X' = Y' = B = C ), eg, B = 3 4 = C

a@ X Y, Y X <=> X=Y

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r? A B, C A, B C, C B, A C

A = 2 X' = Y' = B = C

ActiveConstrain

t

Page 62: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B, Y' = A, X' = B,

PartnerConstrain

t

ActiveConstrain

t

Page 63: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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 4 = C

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X' = Y' = A = C = B

PartnerConstrain

t

ActiveConstrain

t

Page 64: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 Y' = C, X' = B, X' = A, Y' = B

PartnerConstrain

t

ActiveConstrain

t

Page 65: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y (A,B,C A = 2 X',Y' X' = A = C Y' = B), eg, A = 2 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

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X' = A = C, Y' = B

PartnerConstrain

t

ActiveConstrain

t

Page 66: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B, Y’ = C, X’ = A

PartnerConstrain

t

ActiveConstrain

t

Page 67: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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, A = 2 4 = C

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X' = Y’ = A, = B = C

PartnerConstrain

t

ActiveConstrain

t

Page 68: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 Y’ = C, X’ = B, X’ = C, Y’ = A

PartnerConstrain

t

ActiveConstrain

t

Page 69: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

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, A = 2 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

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X’ = Y’ = A = B = C

PartnerConstrain

t

ActiveConstrain

t

Page 70: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B, Y’ = B, X’ = C

PartnerConstrain

t

ActiveConstrain

t

Page 71: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y A,B,C A = 2 X',Y' X' = C’ Y’ = B), eg, A = 2, X’ = C, Y’ = B

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a? A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

PartnerConstrain

t

ActiveConstrain

t

Page 72: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y A,B,C A = 2 X',Y' X' = C’ Y’ = B), eg, A = 2, X’ = C, Y’ = B

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

a! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

A B, C A, A C A = 2, B = C

Page 73: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

r? A B, C A, A C A = 2, B = C X’ = A, Y’ = C, X’ = Y’Active

Constraint

Page 74: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true. (A,B,C A = 2, B = C X',Y’ X' = Y' = A = B = C), eg, A = 2 4 = C a@ X Y, Y X <=> X=Y t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

r? A B, C A, A C A = 2, B = C X’ = Y’ = A = CActive

Constraint

Page 75: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a? A B, C A, A C A = 2, B = C X’ = A, Y’ = C, Y’ = A, X’ = BActive

Constraint

PartnerConstrain

t

Page 76: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y (A,B,C A = 2, B = C X',Y’ X' = Y' = A = B = C), eg, A = 2 4 = C

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a? A B, C A, A C A = 2, B = C X’ = Y’ = A = B = CActive

Constraint

PartnerConstrain

t

Page 77: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a? A B, C A, A C A = 2, B = C Y’ = A, X’ = C, X’ = A, Y’ = BActive

Constraint

PartnerConstrain

t

Page 78: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y (A,B,C A = 2, B = C X',Y’ X' = Y' = A = B = C), eg, A = 2 4 = C

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a? A B, C A, A C A = 2, B = C X’ = Y’ = A = B = CActive

Constraint

PartnerConstrain

t

Page 79: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a? A B, C A, A C A = 2, B = C X’ = A, Y’ = C, Y’ = C, X’ = AActive

Constraint

PartnerConstrain

t

Page 80: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y A,B,C A = 2, B = C X',Y’ X' = A Y’ = C), eg, X’ = 2, Y’ = C

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a? A B, C A, A C A = 2, B = C X’ = Y’ = A = CActive

Constraint

PartnerConstrain

t

Page 81: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true.

a@ X Y, Y X <=> X=Y A,B,C A = 2, B = C X',Y’ X' = A Y’ = C), eg, X’ = 2, Y’ = C

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a! A B, C A, A C A = 2, B = C X’ = Y’ = A = C

A B A = 2, B = C, A = C

Page 82: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = 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.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a! A B, C A, A C A = 2, B = C X’ = Y’ = A = C

r? A B A = B = C = 2 X’ = A, Y’ = B, X’ = Y’Active

Constraint

Page 83: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true. A,B,C A = B = C = 2 X',Y’ X' = Y’ = A = B), eg, X’ = 2, Y’ = 2

a@ X Y, Y X <=> X=Y

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a! A B, C A, A C A = 2, B = C X’ = Y’ = A = C

r? A B A = B = C = 2 X’ = Y’ = A = BActive

Constraint

Page 84: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR by Example:CHR by Example: Rule Base Defining Rule Base Defining in Terms of = in Terms of =

r@ X Y <=> X = Y | true. A,B,C A = B = C = 2 X',Y’ X' = Y’ = A = B), eg, X’ = 2, Y’ = 2

a@ X Y, Y X <=> X=Y

t@ X Y, Y Z ==> X Z.

i@ X Y \ X Y <=> true.

Rule RDCS BICS MEG

t! A B, C A, B C A = 2 X' = C, Y' = A, Z' = B

t! A B, C A, B C, C B A = 2 X' = A, Y' = B, Z' = C

r! A B, C A, B C, C B, A C

A = 2 X' = C, Y' = B

a! A B, C A, A C A = 2, B = C X’ = Y’ = A = C

r! A B A = B = C = 2 X’ = Y’ = A = B

A = B = C = 2

Constraints Simplified Final Normalized Solved Form

Page 85: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Body:Rule-Defined and

Built-In Constraints

Guard:Built-In Constraints (from host language)

Head: Rule-Defined Constraints

• Simplification rule: sh1(X,a), sh2(b,Y) <=> g1(X,Y), g2(a,b,c) | b1(X,c), b2(Y,c).• Propagation rule: ph1(X,Y), ph2(d) ==> g3(X), g4(d,Y) | b3(X,d), b4(X,Y).• Simpagation rule: ph3(X), ph4(Y,Z) \ sh3(X,U), sh4(Y,V) <=> g5(X,Z), g6(Z,Y) | b5(X), b6(Y,Z).

• Simplification rules are conditional rewrite rules (condition is the guard)• Propagation rules are event-condition-action rules (condition is the guard)• Simpagation rules heads are hybrid syntactic sugar, each can be replaced by a semantically equivalent simplification rule, ex, p, r \ s, t <=> g, h | b, c. is equivalent to p, r, s, t <=> g, h | p, r, b, c.

2..*And Formula

CHR: Syntax OverviewCHR: Syntax Overview

CHR Base

* CHR Rule

guard

simplified head

propagated head

body

LogicalFormula

0..1

0..1

0..1

Atomic Formula

SimpagationRule

SimplificationRule

PropagationRule

{non-overlapping, complete}

Built-InConstraint

Rule DefinedConstraint

Page 86: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR: Complete Abstract SyntaxCHR: Complete Abstract Syntax

SimpagationRule

SimplificationRule

PropagationRule

CHR Base

* CHR Rule

guard

simplified head

propagated head

body

LogicalFormula

0..1

0..1

0..12..*

{non-overlapping, complete}

Non-GroundTerm

GroundTerm

{non-overlapping, complete}

And Formula

Atomic Formulaarg

*

Term

ConstraintSymbol

FunctionalTerm

Non-FunctionalTerm

{non-overlapping, complete}

arg

*

FunctionSymbol

ConstraintDomain*

*

*

Built-InConstraint

Rule DefinedConstraint

true false

VariableConstantSymbol

Rule DefinedConstraint

Symbol

Built-InConstraint

Symbol

Page 87: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR: Derivation Data StructuresCHR: Derivation Data Structures

SimpagationRule

SimplificationRule

PropagationRule

CHR Base

* CHR Rule

guard

simplified head

propagated head

body

CHRLogicalFormula

Atomic Formula

Built-InConstraint

Rule DefinedConstraint

0..1

0..1

0..12..*

Term

And Formula

arg

*

*

**

{ordered}

Rule DefinedConstraint Store

Built-InConstraint Store

UsedRule

DerivationState

*

CHRDerivation

Page 88: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR: Declarative Semantics inCHR: Declarative Semantics inClassical First-Order Logic (CFOL)Classical First-Order Logic (CFOL)

Simplification rule: sh1, ... , shi <=> g1, ..., gj | b1, ..., bk.

where: {X1, ..., Xn} = vars(sh1 ... shi g1 ... gj) and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}

X1, ..., Xn g1 ... gj (sh1 ... shi Y1, ... , Ym b1 ... bk)

Propagation rule: ph1, ... , phi ==> g1, ..., gj | b1, ..., bk.

where: {X1, ..., Xn} = vars(ph1 ... phi g1 ... gj) and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}

X1, ..., Xn g1 ... gj (ph1 ... phi Y1, ... , Ym b1 ... bk)

Page 89: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR: Constraint and RuleCHR: Constraint and RulePriority HeuristicsPriority Heuristics

No standard, implementation dependent Active constraint priority heuristics:

Preferring constraints most recently inserted in store Left-to-right writing order in query

Rule priority heuristics: Preferring simplification rules over simpagation rules and

simpagation over propagation rules Preferring simplification and simpagation rules with highest

number of heads Preferring propagation rules with lowest number of heads Preferring rules whose head constraint have never be matched yet Top to bottom writing order

Partner constraint priority heuristics: Preferring constraints most recently inserted in store Left-to-right writing order in query

Page 90: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | X = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

min(1,2,M)

Page 91: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X M true |= X'=1,Y'=2,Z'=M X' = 1, Y' = 2, Z' = M, 1 2

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | Y = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

r? min(1,2,M) true X' = 1, Y' = 2, Z' = M, X' Y'

Page 92: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X M true |= X'=1,Y'=2,Z'=M X' = 1, Y' = 2, Z' = M, X' = 1 2 = Y'

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | Y = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

r! min(1,2,M) true X' = 1, Y' = 2, Z' = M, X' Y'

true M = Z' = X' = 1

Page 93: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X M true |= X'=1,Y'=2,Z'=M X' = 1, Y' = 2, Z' = M, X' = 1 2 = Y'

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | Y = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

r! min(1,2,M) true X' = 1, Y' = 2, Z' = M, X' Y'

true M = 1

Projection(CS,vars(Query))

Page 94: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | Y = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

min(A,B,M) A B

Page 95: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X A,B,M A B |= X'=A,Y'=B,Z'=M X' = A, Y' = B, Z' = M, X' = A B = Y'

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | Y = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

r1? min(A,B,M) A B X' = A, Y' = B, Z' = M, X' Y'

Page 96: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X A,B,M A B |= X'=A,Y'=B,Z'=M X' = A, Y' = B, Z' = M, X' = A B = Y'

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | Y = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

r1! min(A,B,M) A B X' = A, Y' = B, Z' = M, X' Y'

true M = Z' = X' = A, A B

Page 97: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: CHR Base Example: Defining min in Terms of Defining min in Terms of , , and = and =

r1@ min(X,Y,Z) <=> X Y | Z = X A,B,M A B |= X'=A,Y'=B,Z'=M X' = A, Y' = B, Z' = M, X' = A B = Y'

r2@ min(X,Y,Z) <=> Y X | Z = Y.

r3@ min(X,Y,Z) <=> Z < X | Y = Z.

r4@ min(X,Y,Z) <=> Z < Y | Y = Z.

r5@ min(X,Y,Z) ==> Z X, Z Y.

Rule RDCS BICS MEG

r1! min(A,B,M) A B X' = A, Y' = B, Z' = M, X' Y'

true M = A, A B

Projection(CS,vars(Query))

Page 98: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Bases as ComponentCHR Bases as Component

Several solvers, each one implemented by a pair(CHR base, CHR engine)

can be assembled in a component-based architecture, with server solvers' CHR bases defining in their rule heads the constraints used as built-ins by client solvers' CHR bases

Page 99: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

<<Component>>HostPlatform

<<Interface>>Min

min(X:Real, Y:Real, out Z:Real)

<<Component>>CHRDEngine

X Y X = Y | trueX Y Y X X = YX Y Y Z X ZX Y \ X Y true X X falseX Y Y Z X Y Y Z | X ZY Z X Y X Y Y Z | X Z X Y Y Z X Y Y Z | X Z

<<Component>>LoeSltCHRDBase

<<Interface>>LoeStl

(X:Real, Y:Real): Boolean(X:Real, Y:Real): Boolean

«uses»

min(X,Y,Z) X Y | Z = Xmin(X,Y,Z) Z Y | Z = Xmin(X,Y,Z) Y Z | Z = Ymin(X,Y,Z) Z X | Z = Ymin(X,Y,Z) Z X Z Y

<<Component>>MinCHRDBase

<<Interface>>CHRDEngine

derive()

«uses»

Example CHR Base Component Example CHR Base Component AssemblyAssembly

«uses» <<Interface>>EqNeq

= (X:Real, Y:Real): Boolean (X:Real, Y:Real): Boolean

Page 100: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C.

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Notation: ?P Constraint Domain Variable and CHR Variable C Constraint Domain Constant and CHR Variable == Constraint Domain Equality Predicate = CHR Equality Predicate 0,1,2, ... CHR and Host Programming Language Constants := Host Programming Language Variable Assignment Predicate,

always returns true, performs arithmetic computation as side-effect +, -, / Host Programming Language Arithmetic Function number Host Programming Language Type Checking Function

Rule RDCS BICS MEG

?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true

Page 101: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C ?Y, true |= ?P=?Y,C=2 ?P = ?Y, C = 2

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1? ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

Page 102: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2

Page 103: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r1? ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2

Page 104: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

?X,?Y,?U,?V ?Y = 2 |= <?P,?Q,C,R> = <?X,2,3,1> ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2? ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

Page 105: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

?X,?Y,?U,?V ?Y = 2 |= <?P,?Q,C,R> = <?X,2,3,1> ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

?Y = 2, ?X = 1

Page 106: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r1? ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1

Page 107: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r2? ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 2, ?Q.number

Page 108: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r3? ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 2, ?P.number

Page 109: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r4? ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 0, ?P = ?U, ?Q = ?V, D = 2, R = 1

Page 110: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R

?X,?Y,?U,?V ?X = 1, ?Y = 2 |= <?P,?Q,C,D,R> = <?U,?V,0,2,1> ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r4? ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

Page 111: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

?X,?Y,?U,?V ?X = 1, ?Y = 2 |= <?P,?Q,C,D,R> = <?U,?V,0,2,1> ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r4! ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

?U + ?V == 0 ?Y = 2, ?X = 1, ?U = 1

Page 112: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r4! ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

r1? ?U + ?V == 0 ?Y = 2, ?X = 1, ?U = 1

Page 113: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r4! ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

r2? ?U + ?V == 0 ?Y = 2, ?X = 1, ?U = 1 ?P = ?U, ?Q = ?V, C = 0, ?Q.number

Page 114: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

?X,?Y,?U,?V ?X = 1, ?Y = 2, ?U = 1 |= <?P,?Q,C,R> = <1,?V,0,-1> ?P = ?U, ?Q = ?V, C = 0, ?P.number, R = -1

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r4! ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

r3? ?U + ?V == 0 ?Y = 2, ?X = 1, ?U = 1 ?P = ?U, ?Q = ?V, C = 0, ?P.number, R = -1

Page 115: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHR Base Example: Restricted FormCHR Base Example: Restricted Formof Real Linear Equations Solverof Real Linear Equations Solver

r1@ ?P == C <=> P = C

r2@ ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

r3@ ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

?X,?Y,?U,?V ?X = 1, ?Y = 2, ?U = 1 |= <?P,?Q,C,R> = <1,?V,0,-1> ?P = ?U, ?Q = ?V, C = 0, ?P.number, R = -1

r4@ ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

Rule RDCS BICS MEG

r1! ?Y == 2,?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

true ?P = ?Y, C = 2

r2! ?X + ?Y == 3, ?U - ?V == 2, ?U + ?V == 0

?Y = 2 ?P = ?X, ?Q = ?Y, C = 3, ?Q.number, R = 1

r4! ?U - ?V == 2, ?U + ?V == 0

?Y = 2, ?X = 1 ?P = ?U, ?Q = ?V, C = 0, D = 2, R = 1

r3! ?U + ?V == 2 ?Y = 2, ?X = 1, ?U = 1 ?P = ?U, ?Q = ?V, C = 0, ?P.number, R = -1

true ?Y = 2, ?X = 1, ?U = 1, ?V = -1

Page 116: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR : Abstract Syntax : Abstract Syntax

OrAnd Formula

connective: enum{or,and}

SimpagationRule

SimplificationRule

PropagationRule

CHR Base

* CHR Rule

guard

simplified head

propagated head

body

And Formula

Atomic Formula

Constraint

Built-InConstraint

Rule DefinedConstraint

2..*

true false

0..1

0..1

0..1

Built-InConstraint Store

Rule DefinedConstraint Store

*

FiredRule

DerivationState

*

CHRDerivation

*

{ordered} * *

TriedAlternative

Body

*

*

Page 117: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR: Declarative Semantics in: Declarative Semantics inClassical First-Order Logic (CFOL)Classical First-Order Logic (CFOL)

Simplification rule: sh1, ... , shi <=> g1, ..., gj | b11, ..., bk

p ; ... ; b11, ..., bl

q.

where: {X1, ..., Xn} = vars(sh1 ... shi g1 ... gj) and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}

X1, ..., Xn g1 ... gj (sh1 ... shi Y1, ... , Ym ((b1

1 ... bk

p) ... (b11 ... bk

q))

Propagation rule: ph1, ... , phi ==> g1, ..., gj | b11, ..., bk

p ; ... ; b11, ..., bl

q.

where: {X1, ..., Xn} = vars(ph1 ... phi g1 ... gj) and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}

X1, ..., Xn g1 ... gj (ph1 ... phi Y1, ... , Ym ((b1

1 ... bk

p) ... (b11 ... bk

q))

Page 118: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR: Operational Semantics: Operational Semantics

When rule R with disjunctive body B1 ; ... ; Bk is fired Update both constraint stores using B1

Start next matching-updating cycle

When BICS = false or when no rule matches the RDCS Backtrack to last alternative body Bi

Restore both constraint stores to their states prior to their update with Bi

Update both constraint stores using Bi+1

Start next matching-updating cycle

Exhaustively try all alternative bodies of all fired rules through backtracking

Page 119: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

d4@ d(r4,C) ==> (C = r ; C = b).

d3@ d(r3,C) ==> (C = r ; C = b).

d2@ d(r2,C) ==> (C = b ; C = g).

d5@ d(r5,C) ==> (C = r ; C = g).

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]). true

Page 120: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m? m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]). true

Page 121: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true

Page 122: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2? l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

Page 123: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true

Page 124: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

n? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true

Page 125: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

Page 126: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r

Page 127: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

n? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r

Page 128: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

d1a? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r1, C = C1

Already fired w/ same constraint. Not repeated to avoid trivial non-termination

Page 129: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

Page 130: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r

Page 131: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false. C1,C7 Ri',Rj',Ci',Cj' C1=r | Ri=r1, Rj=r7, Ci=C1, Cj=C7, Ci=Cj

l1@ l([ ],[ ]) <=> true. eg., Cj = b r = Ci

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

n? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r1, Rj = r7, Ci = C1, Cj = C7, Ci = Cj

Page 132: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7a? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

Page 133: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = r

Page 134: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

n? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = r

Ri = r1, Rj = r7, Ci = r, Cj = r

Page 135: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

n! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = r

Ri = r1, Rj = r7, Ci = r, Cj = r

n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

false

Page 136: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

n! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = r

Ri = r1, Rj = r7, Ci = r, Cj = r

bt n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

false

Page 137: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7b? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

Page 138: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7b! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = b

Page 139: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false. C1,C7 Ri',Rj',Ci',Cj' C1=r | Ri=r1, Rj=r7, Ci=C1, Cj=C7, Ci=Cj

l1@ l([ ],[ ]) <=> true. eg., Cj = b r = Ci

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7b! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

n? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = b

Ri = r1, Rj = r7, Ci = C1, Cj = C7, Ci = Cj

Page 140: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7b! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

l2? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = b

R = r4, Rs = [r3,r2,r5,r6],C = C4, Cs = [C3,C2,C5,C6]

Page 141: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7b! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), d(r4,C4), l([r3,r2,r5,r6],[C3,C2,C5,C6])

C1 = r,C7 = b

R = r4, Rs = [r3,r2,r5,r6],C = C4, Cs = [C3,C2,C5,C6]

Page 142: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

...

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m! m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), true

l2! l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]), n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7)

true R = r1, Rs = [r7,r4,r3,r2,r5,r6],C = C1, Cs = [C7,C4,C3,C2,C5,C6]

d1a! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

true C = C1

l2! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), l([r7,r4,r3,r2,r5,r6],[C7,C4,C3,C2,C5,C6])

C1 = r R = r7, Rs = [r4,r3,r2,r5,r6],C = C7, Cs = [C4,C3,C2,C5,C6]

d7b! n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r Ri = r7, C = C7

l2? n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r7,C7), l([r4,r3,r2,r5,r6],[C4,C3,C2,C5,C6])

C1 = r,C7 = b

Page 143: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

d7@ d(r7,C) ==> (C = r ; C = b).

d4@ d(r4,C) ==> (C = r ; C = b).

d3@ d(r3,C) ==> (C = r ; C = b).

d2@ d(r2,C) ==> (C = b ; C = g).

d5@ d(r5,C) ==> (C = r ; C = g).

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Rule RDCS BICS MEG

m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]). true

n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7), d(r1,C1), d(r2,C2), d(r2,C2), d(r1,C3), d(r4,C4), d(r5,C5), d(r6,C6), d(r7,C7)

C1 = g,C2 = b,C3 = r,C4 = r,C5 = g,C6 = r,C7 = b

Page 144: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHR Base Example: Base Example:Map Coloring ProblemMap Coloring Problem

% More efficient version with forward checkingd1@ c(r1,r), c(r1,b), c(r1,g) ==> false.

d1@ d(r1,C), c(r1,r), c(r1,b) ==> C = g.

d1@ d(r1,C), c(r1,r), c(r1,g) ==> C = b.

d1@ d(r1,C), c(r1,b), c(r1,g) ==> C = r.

d1@ d(r1,C), c(r1,b) ==> (C = r ; C = g).

d1@ d(r1,C), c(r1,g) ==> (C = r ; C = b).

d1@ d(r1,C), c(r1,r) ==> (C = b ; C = g).

d1@ d(r1,C) ==> (C = r ; C = b ; C = g).

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

m@ m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7).

fcr@ n(Ri,Rj), d(Rj,Cj) ==> c(Ri,Cj).

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

l1@ l([ ],[ ]) <=> true.

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r2b g r6 r g t

r3

r b

r4

r b

r5

b g

r1

r b g

r7

r b

Page 145: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHRVV: Practical Applications: Practical Applications

Declarative, easy to extend and compose constraint solvers and all their applications Scheduling, allocation, planning, optimization, recommendation,

configuration Deductive theorem proving (propositional and first-order) and all its

applications: CASE tools, declarative programs analysis, formal methods in hardware and

software design, Hypothetical abductive reasoning and all its applications:

Diagnosis and repair, observation explanation, sensor data integration Multi-agent reasoning Spatio-temporal reasoning and robotics Hybrid reasoning integrating:

Deduction, belief revision, abduction, constraint solving and optimization with open and closed world assumption

Heterogeneous knowledge integration Semantic web services Natural language processing

Page 146: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rewrite Rules: Abstract SyntaxRewrite Rules: Abstract Syntax

RewriteRule Base

RewriteRule

* RHS plus(X,0) X

fib(suc(suc(N))) plus(fib(suc(N)),fib(N))

FunctionalTerm

Non-FunctionalTerm

GroundTerm

Non-GroundTerm

FunctionSymbol

ConstantSymbol

Variable

*args

{disjoint, complete} {disjoint, complete}

LHS

Term

Page 147: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rewrite Rules: Operational Rewrite Rules: Operational SemanticsSemantics

: RewriteRuleBase

T : Term

Unify LHS of Rewrite Rule Baseagainst sub-terms of Term

: Unifying Set of Pairs:- Instantiated Rule- Instantiated Sub-term

[ Matching Pair Set Empty ]

[ Matching Pair Set Singleton ] : Pair

- Instantiated Rule R- Instantiated Sub-Term S

Pick onePair Set[ Else ]

Substitute Sub-Term S in Term T

by RHS of Rule R

Page 148: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rewrite Rule Base Computation Rewrite Rule Base Computation ExampleExample

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(suc(N))

plus(fib(suc(N)),fib(N))

1. fib(suc(suc(suc(0)))) w/ rule e2. plus(fib(suc(suc(0))),fib(suc(0))) w/ rule d3. plus(fib(suc(suc(0))),suc(0)) w/ rule

b4. suc(plus(fib(suc(suc(0))),0)) w/ rule

a5. suc(fib(suc(suc(0)))) w/ rule e6. suc(plus(fib(suc(0)),fib(0))) w/ rule c7. suc(plus(fib(suc(0)),suc(0))) w/ rule

b8. suc(suc(plus(fib(suc(0)),0))) w/ rule

a9. suc(suc(fib(suc(0)))) w/ rule d10.suc(suc(suc(0)))

Page 149: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Conditional Rewrite Rules:Conditional Rewrite Rules:Abstract SyntaxAbstract Syntax

RewriteRule Base

RewriteRule

*

LHS

Term

RHS

Condition

Equation

*

2

X = 0 Y = 0 | X + Y 0

• Rule with matching LHS can only be fired if condition is also verified• Proving condition can be recursively done by rewriting it to true

Page 150: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rewrite Rule Base Deduction Rewrite Rule Base Deduction Example:Example:

Is West Criminal?Is West Criminal?Rewrite Rule Base:a) criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P,N,W)b) sells(west,nono,W) owns(nono,W) missile(W)c) hostile(N) enemy(N,america)d) weapon(W) missile(W)e) owns(nono,m1) missile(m1) american(west) nation(nono) enemy(nono,america) truef) A B B Ag) A A A

Term:criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P,N,W) w/ rule aamerican(P) weapon(W) nation(N) hostile(N) owns(nono,W) missile(W) w/ rule bamerican(P) weapon(W) nation(N) enemy(N,america) owns(nono,W) missile(W) w/ rule camerican(P) missile(W) nation(N) enemy(N,america) owns(nono,W) missile(W) w/ rule damerican(P) missile(W) nation(N) enemy(N,america) owns(nono,W) w/ rule g ... w/ rule fowns(nono,W) missile(W) american(P) nation(N) enemy(N,america) w/ rule ftrue w/ rule e

Page 151: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Rewriting Systems: Practical Rewriting Systems: Practical ApplicationApplication

Theorem proving CASE:

Programming language formal semantics Program verification Compiler design and implementation Model transformation and automatic programming

Data integration Using XSLT an XML-based language to rewrite XML-based data and

documents Web server pages and web services (also using XSLT)

Page 152: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Implementing a Rewriting SystemImplementing a Rewriting Systemin CHRin CHR

Map each conditional rewrite system rule of the formCondition | LHS RHSonto a CHR simplification rule of the formLHS Condition | RHSi.e., map the rewrite rule condition onto the CHR guard the rewrite rule LHS onto the CHR head the rewrite rule RHS onto the CHR body

Replace each functional terms ti appearing in a Condition, LHS or RHS of the rewrite rule by: a new variable Vi, and

a new equational atom Vi = ti in the guard, head or body (respectively) of the CHR

For example: fib(suc(suc(N)) plus(fib(suc(N)),fib(N)), becomes fib(U,V) <=> U = suc(W), W = suc(N) |fib(N,Y), fib(W,X),

plus(X,Y,V).

Page 153: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving:Solving:fibonaccifibonacci

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(suc(N))

plus(fib(suc(N)),fib(N))

a@ plus(X,U,V) <=> U = 0 | V = X.b@ plus(X,U,V) <=> U = suc(Y) | V = suc(W), plus(X,Y,W).c@ fib(U,V) <=> U = 0 | V = suc(0).d@ fib(U,V) <=> U = suc(0) | V = suc(0).e@ fib(U,V) <=> U = suc(W), W = suc(N) | fib(N,Y), fib(W,X), plus(X,Y,V).

Page 154: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Rule RDCS BICS MEG

f(s(s(0)),R) true

Page 155: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Guard Entailment Condition:R true N1,U1,V1,W1 U1=s(s(0)) V1=R U1=s(W1) W1=s(N1),

e.g., N1=0, U1=s(s(0)), V1=R, W1=s(0)

Rule RDCS BICS MEG

e? f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

Page 156: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification): U1=s(s(0)) U1=s(W1) W1=s(0)

W1=s(0) W1=s(N1) N1=0

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

Page 157: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification): U1=s(s(0)) U1=s(W1) W1=s(0)

W1=s(0) W1=s(N1) N1=0

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0)

Page 158: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Guard Entailment Condition:R,N1,U1,V1,Y1,W1 R=V1 N1=0 U1=s(s(0)) W1=s(0) U2,V2 U2=N1 V2=Y1 U2=0,e.g., U2=0, V2=Y1

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c? f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

Page 159: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification):V2=Y1 V2=s(0) Y1=s(0)

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0), U2=N1, V2=Y1, U2=0, V2=s(0)

Page 160: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Guard Entailment Condition: R,N1,U1,V1,Y1,W1,U2,V2 R=V1 N1=U2=0 U1=s(s(0)) W1=Y1=V2=s(0) U3,V3 U3=W1 V3=X1 U3=s(0) e.g., U3=s(0), V3=X1

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d? f(W1,X1), p(X1,Y1,V1)

R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=W1, V3=X1, U3=s(0)

Page 161: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification):V3=X1 V3=s(0) X1=s(0)

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d! f(W1,X1), p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=W1, V3=X1, U3=s(0)

p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=s(0)

Page 162: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Guard Entailment Condition: R,N1,U1,V1,X1,Y1,W1,U2,V2,U3,V3R=V1 N1=U2=0 U1=s(s(0)) W1=X1=Y1=V2=U3=V3=s(0) U4,V4,X4,Y4,W4 X4=X1 U4=Y1 V4=V1 U4=s(Y4)e.g., U4=s(0), V4=R, X4=s(0), Y4=0

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d! f(W1,X1), p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=Z1, V3=X1, U3=s(0)

b? p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=s(0)

X4=X1, U4=Y1, V4=V1, U4=s(Y4)

Page 163: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification):U4=Y1 Y1=s(0) U4=s(0)U4=s(0) U4=s(Y4) Y4=0X4=X1 X1=s(0) X4=s(0)

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d! f(W1,X1), p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=Z1, V3=X1, U3=s(0)

b! p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=s(0) X4=X1, U4=Y1, V4=V1, U4=s(Y4)

p(X4,Y4,W4) R=V1=V4=s(W4), N1=U2=Y4=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=U4=X4=s(0)

Page 164: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Guard Entailment Condition: R,N1,U1,V1,X1,Y1,W1,U2,V2,U3,V3,U4,V4,W4,X4,Y4,R=V1=V4=s(W4) N1=U2=Y4=0 ) U1=s(s(0)) ) W1=X1=Y1=V2=U3=V3=U4=X4=s(0) U5,V5,X5 X5=X4 U5=Y4 V5=W4 U5 = 0e.g., U5=0, V5=W4, X5=s(0)

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d! f(W1,X1), p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=Z1, V3=X1, U3=s(0)

b! p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=s(0) X4=X1, U4=Y1, V4=V1, U4=Y4

a? p(X4,Y4,W4) R=V1=V4=s(W4), N1=U2=Y4=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=U4=X4=s(0)

X5=X4, U5=Y4, V5=W4, U5 = 0

Page 165: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification):X5=X4 X4=s(0) X5=s(0)X5=s(0) V5=X5 V5=s(0)V5=s(0) V5=W4 W4=s(0)W4=s(0) R=s(W4) R=s(s(0))

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d! f(W1,X1), p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=Z1, V3=X1, U3=s(0)

b! p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=s(0) X4=X1, U4=Y1, V4=V1, U4=Y4

a! p(X4,Y4,W4) R=V1=V4=s(W4), N1=U2=Y4=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=U4=X4=s(0)

X5=X4, U5=Y4, V5=W4, U5 = 0

R=V1=V4=s(W4), N1=U2=Y4=U5=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=U4=X4=X5=s(0), V5=W4, V5=X5

Page 166: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification):X5=X4 X4=s(0) X5=s(0)X5=s(0) V5=X5 V5=s(0)V5=s(0) V5=W4 W4=s(0)W4=s(0) R=s(W4) R=s(s(0))

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d! f(W1,X1), p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=Z1, V3=X1, U3=s(0)

b! p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=s(0) X4=X1, U4=Y1, V4=V1, U4=Y4

a! p(X4,Y4,W4) R=V1=V4=s(W4), N1=U2=Y4=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=U4=X4=s(0)

X5=X4, U5=Y4, V5=W4, U5 = 0

R=V1=V4=s(s(0)), N1=U2=Y4=U5=0, U1=s(s(0))W1=X1=Y1=V2=U3=V3=U4=X4=W4=V5=X5=s(0)

Page 167: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Term RewritingExample Term Rewritingas as CHRCHR Solving Solving Solving: Solving: fibonacci(2) = fibonacci(2) =

??a@ p(X,U,V) <=> U = 0 | V = X.b@ p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).c@ f(U,V) <=> U = 0 | V = s(0).d@ f(U,V) <=> U = s(0) | V = s(0).e@ f(U,V) <=> U = s(W), W = s(N) | f(N,Y), f(W,X), p(X,Y,V).

Built-in First-Order Atom Syntactic Equality Solver (Unification):X5=X4 X4=s(0) X5=s(0)X5=s(0) V5=X5 V5=s(0)V5=s(0) V5=W4 W4=s(0)W4=s(0) R=s(W4) R=s(s(0))

Rule RDCS BICS MEG

e! f(s(s(0)),R) true U1=s(s(0)), V1=R, U1=s(W1), W1=s(N1)

c! f(N1,Y1), f(W1,X1), p(X1,Y1,V1)

R=V1, N1=0, U1=s(s(0)), W1=s(0) U2=N1, V2=Y1, U2=0

d! f(W1,X1), p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=Y1=V2=s(0) U3=Z1, V3=X1, U3=s(0)

b! p(X1,Y1,V1) R=V1, N1=U2=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=s(0) X4=X1, U4=Y1, V4=V1, U4=Y4

a! p(X4,Y4,W4) R=V1=V4=s(W4), N1=U2=Y4=0, U1=s(s(0)), W1=X1=Y1=V2=U3=V3=U4=X4=s(0)

X5=X4, U5=Y4, V5=W4, U5 = 0

R=s(s(0))

Projection(BICS, vars(Query))

Page 168: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHRVV vs. Rewriting Systems vs. Rewriting Systems

CHRV: Matching applied to atomic formula

conjunctions Rule head is matched with constraint

store sub-set, which requires the head to be more general than the sub-set

Propagation rules provide further simplification opportunities

Rewriting Systems: Unification of LHS is applied

recursively down to sub-terms Rule LHS is unified with sub-term

which allows the sub-term to be more general than the LHS

All reasoning done through rewriting (no propagation rules)

Common characteristics: Forward chains rules Requires conflict resolution strategy to choose:

Which of several matching rules to fire Non-monotonic reasoning due to:

Constraint retraction in Rule-Defined Constraint Store Retraction of substituted sub-term

Tricky confluence and termination issues

Page 169: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rules: Abstract SyntaxProduction Rules: Abstract Syntax

ProductionRule Base

ProductionRule

*

Arithmetic Predicate Symbol

Right-Hand Side(RHS)

Action*

Arithmetic Constant Symbol

IF (p(X,a) OR p(X,b)) AND p(Y,Z) AND q(c) AND X <> Y AND X > 3.5THEN Z = X + 12 AND add{r(a,c,Z} AND delete{p(Y,Z)}

FactFactBase

*

Atom

And-Or Formula

Connective: enum{and,or}

Left-Hand Side(LHS)

2..*

ArithmeticCalculation

Fact Base Update

Operator: enum{add,delete}

PredicateSymbol

Non-GroundAtom

ConstantSymbol

VariableGroundAtom

Non-FunctionalTerm

argsFunctor

Page 170: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production System ArchitectureProduction System Architecture

Fact Base ManagementComponent

Rule FiringPolicy

Component

Host LanguageAPI

Action ExecutionComponent

FactBase

RuleBase

Pattern MatchingComponent

CandidateRules

Page 171: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rules: Operational Production Rules: Operational SemanticsSemantics

[Matching Instantiated Rule Set Empty]

Pick one Instantiated Rule to Fire [Else]

[Matching InstantiatedRule Set Singleton]

SelectedInstantiated

Rule

Execute in SequenceActions in RHS

of SelectedInstantiated Rule

Match LHSof Rule BaseagainstFact Base

RuleBase

FactBase

MatchingInstantiated

Rule Set

Page 172: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Conflict Resolution StrategiesConflict Resolution Strategies

Conflict resolution strategy: Heuristic to choose at each cycle which of the matching rule set to

fire Common strategies:

Follow writing order of rules in rule base Follow absolute priority level annotations associated with each rule

or rule class Follow relative priority level annotations associated with pairs of

rules or rule classes Prefer rules whose LHS match the most recently derived facts in

the fact base Prefer rules that have remained for the longest time unfired while

matching a fact Apply control meta-rules that declaratively specify arbitrarily

sophisticated strategies

Page 173: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Base Example:Production Rule Base Example:Is West Criminal?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,m1)missile(m1)american(west)nation(nono)enemy(nono,america)nation(america)

Page 174: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

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 175: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(P)

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

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

Page 176: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(P)

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

criminal(west)?

missile(W) 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 177: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(P)

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

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

Page 178: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(P)

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

criminal(west)?

missile(W) owns(nono,W)

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

nation(america)

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

sells(west,nono,W)

Page 179: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(P)

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

criminal(west)?

missile(m1) owns(nono,m1)

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

nation(america)

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

sells(west,nono,W)

Page 180: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(P)

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

criminal(west)?

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

nation(america)

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

sells(west,nono,m1)

Page 181: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(P)

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

criminal(west)?

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

nation(america)

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

sells(west,nono,m1)

Page 182: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(west)

weapon(m1) hostile(nono)

criminal(west)?

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

nation(america)

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

sells(west,nono,m1)

Page 183: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rule Inference Example:Production Rule Inference Example:Is West Criminal?Is West Criminal?

criminal(west)

weapon(m1) hostile(nono)

criminal(west)? yes

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

nation(america)

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

sells(west,nono,m1)

Page 184: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Properties of Production SystemsProperties of Production Systems

Confluence: From confluent rule base, same final fact base is derived

independently of rule firing order Makes values of queries made to the system independent of the

conflict resolution strategy

Termination: Terminating system does not enter in an infinite loop; Example of non-termination production rule base:

Initial fact base: p(0) Production rule base: IF p(X) THEN Y = X + 1 AND add{p(Y)}

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.

Page 185: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production System Inference vs.Production System Inference vs.Lifted Forward ChainingLifted Forward Chaining

Production System Inference Sequential conjunction of actions in

rule RHS Non-monotonic reasoning due to

delete actions Matching only Datalog atoms (i.e.,

atoms which arguments are all non-functional terms)

Matching ground fact atoms against non-ground atoms in rule LHS And-Or atom

Neither sound nor complete inference engine

Lifted Forward Chaining Unique conclusion in Horn Clause

Monotonic reasoning

Unifying arbitrary first-order atoms, possibly functional

Unifying two arbitrary atoms, possibly both non-grounds

Sound and refutation-complete

Common characteristics: Data driven reasoning Requires conflict resolution strategy to choose:

Which of several matching rules to fire Which of several unifying clauses for next Modus Ponens inference step

Page 186: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Embedded Production System: Embedded Production System: Abstract SyntaxAbstract Syntax

HPL Operation

HPL GroundData Structure

HPL Data Structureargs

*HPL BooleanOperation

Right-Hand Side(RHS)

Action*Fact Base Update

Operator: enum{add,delete}

FactFactBase

*

ProductionRule Base

ProductionRule

*

Left-Hand Side(LHS)

And-Or Formula

Connective: enum{and,or}2..*

HPL BooleanOperator

HPLOperator

Page 187: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Generalized Production Rules: ECA Generalized Production Rules: ECA RulesRules

Event-Condition-Action rule: extension of production rule with triggering event external to addition of facts in fact base

Only the rule subset which event just occurred is matched against the fact base

Events thus partition the rule base into subsets, each one specifying a behavior in response to a given events

EventCondtion

ActionRule

EventLHS RHS

Agent’sPercept

HPL BooleanOperation

Page 188: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Production Rules vs. Rewriting RulesProduction Rules vs. Rewriting Rules

Production System Inference Fact base implicitly conjunctive Matching only Datalog atoms (i.e.,

atoms which arguments are all non-functional terms)

Matching ground fact atoms against non-ground atoms in rule LHS And-Or atom

Term Rewriting Reified logical connectives in term

provide full first-order expressivity Unifying arbitrary first-order atoms,

possibly functional

Unifying two arbitrary atoms, possibly both non-grounds

Common characteristics: Data driven reasoning Requires conflict resolution strategy to choose:

Which of several matching rules to fire Which of several rules with an LHS unifying with a sub-term

Non-monotonic reasoning due to: Fact deletion actions in RHS Retraction of substituted sub-term

Tricky confluence and termination issues

Page 189: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Implementing a Production SystemImplementing a Production Systemin CHRin CHR

Map each production rule of the form:IF m1 AND ... AND ml THEN a1 AND ... AND an

where: {a1 ,..., an} = {add(n1) ,..., add(ni)} {delete(o1) ,..., delete(oj)} {hplOp1(p11,..., p1n) ,..., hplOpk(pk1,..., pkm)}

onto a CHR simpagation rule of the form:p1,..., pr \ o1 ,..., oj hplOp1(p11, ..., p1n) ,..., hplOpk(pk1,..., pkm) | n1 ,..., ni.where {p1,..., pr} = {m1,..., ml} \ {o1 ,..., oj}

Valid only when: {o1 , ... , oj} \ {m1, ... , ml} = , and

C{hplOp1(p11,..., p1n),...,hplOpk(pk1,..., pkm)}, O{o1,...,oj}, N{n1,...,ni} C occurs before O and N in a1 and ... and an

i.e., there no direct way in CHR to: delete facts (ground constraints) not matched in the rule head call host programming language operations after some matched facts have

been deleted or add to the fact base (constraint store) two possibilities allowed in production systems that make the resulting rule

base operational behavior hard to comprehend, verify and maintain

Page 190: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHRVV vs. Production Systems vs. Production Systems

CHRV: Constraint store contains arbitrary atoms

including functional, non-ground atoms Simplification rules allow straightforward

modeling for goal-driven reasoning, with rewriting simulating Prolog-like backward chaining

Disjunctive bodies Built-in backtracking search

Production Systems: Fact base only contains

ground Datalog atoms Cumbersome modeling to

implement goal-driven reasoning

No disjunctions in RHS No built-in search

Common characteristics: Forward chains rules Requires conflict resolution strategy to choose:

Which of several matching rules to fire Non-monotonic reasoning due to:

Constraint retraction in Rule-Defined Constraint Store Fact retraction in the RHS

Tricky confluence and termination issues

Page 191: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

FormalLogic

Theory

IntelligentDatabases

FormalSoftware

Specification

AutomatedReasoning

DeclarativeProgramming

Logic Programming: Logic Programming: a Versatile Metaphora Versatile Metaphor

Logic Programming

Page 192: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 193: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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, belief update, inheritance, planning)

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 194: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 Fulfill better one aspect of the logic programming vision

In the 80s, huge Japanese project tried to entirely rebuild all of computing from ground up using logic programming as hardware basis

Page 195: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Definite Logic Program+connective =

Definite Query+connective =

Definite Clause+connective =

clauses

Pure Prolog: abstract syntaxPure Prolog: abstract syntax

Pure Prolog Atom

arg

headbody

0..1 *

*arg Pure Prolog Term*

c11 (...,Xk

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

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

1,...)....c1

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

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

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

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

Numerical Symbol

Function-Free TermFunctional Term

Variable

functor

*

Symbol

predicate

Page 196: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Full PrologFull Prolog

Full Prolog Atom

Full Prolog Query+connective =

Full Prologl Clause+connective =

head

body

0..1

Full Prolog Program+connective =

*

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

User-Defined Symbol

Built-in Symbol

Built-inLogical Symbol

Built-in Imperative Symbol

Meta-ProgrammingPredicate Symbol

NumericalSymbol

I/O Predicate Symbol

Program UpdatePredicate Symbol

Search CustomizationPredicate Symbol

Full Prolog Term

Function-Free TermFunctional Term

Variable

Symbol

functor

arg

predicate

* Prolog LiteralProlog Literal

+connective = naf

arg

*

Page 197: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 198: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 199: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 200: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Clark’s transformationClark’s transformation

Axiomatizes closed-world and unique name assumptions in CFOL Starts from naive Horn formula semantics of pure Prolog program Partitions program in clause sets, each one defining one predicate (i.e.,

group together clauses with same predicate c(t1, ..., tn) as conclusion) Replaces 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

Joins all resulting equivalences in a conjunction Adds conjunction of the form (ci = cj) for all possible pairs (ci,cj) of

constant symbols in pure Prolog program

Page 201: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

SLD ResolutionSLD Resolution SLD resolution (Linear resolution with Selection function for Definite

logic programs): Joint use of goal-driven set of support and input resolution 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 202: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 203: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 204: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 205: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 206: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 207: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 208: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 209: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 210: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 211: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 212: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 213: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 214: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 215: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 216: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 217: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 218: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 219: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 220: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 221: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 222: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 223: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 224: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 225: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 226: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 227: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 228: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 229: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 230: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 231: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 232: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 233: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 234: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 235: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 236: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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(america,america)

owns(nono,W)

missile(m1)american(west)

nation(nono)

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

sells(west,nono,W)

Page 237: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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(america,america)

owns(nono,W)

missile(m1)american(west)

nation(nono)

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

sells(west,nono,W)

fail

Page 238: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 239: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 240: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 241: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 242: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 243: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 244: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 245: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 246: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

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

Page 247: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 248: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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 249: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction 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

CLP Engine CLP Application Rule Base

Prolog EngineProcedural Solver

for Domain D1

Procedural Solverfor Domain Dk

Solver Programming Language L

...Prolog/L Bridge

Page 250: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CLP with CHRCLP with CHR

CLP Engine CLP Application Rule Base

Prolog Engine

CHRHost

ProgrammingLanguage L

CHR EngineCHR Base for Domain D1 Solver

CHR Base for Domain Dk Solver

...

Prolog/L Bridge

Page 251: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Implementing a Prolog Program in Implementing a Prolog Program in CHRCHR

Map Prolog fact base of the form {f1. ... fn.} onto a fact introduction CHR propagation rule: facts f1 ,..., fn.

Map each set of Prolog deductive rules of the form{p(t1

1,...,tn1) :- b1. ... p(t1

k,...,tnk) :- bk.}

that provide the intentional part of the definition for predicate p onto a CHR simplification rule of the form

p(X1,...,Xn) (X1=t11,..., Xn=tn

1, b1) ;...; (X1=t1k ,..., Xn=tn

k, bk).where {X1,...,Xn} is a set of fresh variablesnot occurring in {t1

1,...,tn1,b1, ... p(t1

k,...,tnk), bk}

Map each set of Prolog facts of the form{p(t'11,...,t'n1). ,..., p(t'1k,...,t'nk).}that provide the extensional part of the definition for predicate p onto a CHR world closure propagation rule of the form

p(X1,...,Xn) (X1=t'11,..., Xn=t'n1) ;...; (X1=t'1k ,..., Xn=t'nk).

Valid only for pure Prolog programs

Page 252: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

Example Prolog ProgramExample Prolog ProgramImplemented in CHRImplemented in CHR

Prolog Programfather(john,mary). father(john,peter).mother(jane,mary).

person(john,male). person(peter,male). person(jane,female). person(mary,female). person(paul, male).

parent(P,C) :- father(P,C).parent(P,C) :- mother(P,C).

sibling(C1,C2) :- not C1 = C2, parent(P,C1),

parent(P,C2).

CHR Translationfacts father(john,mary), father(john,peter), mother(jane,mary), person(john,male), person(peter,male), person(jane,female),

person(mary,female), person(paul, male).

parent(P,C) father(P,C) ; mother(P,C).

sibling(C1,C2) C1 C2 | parent(P,C1), parent(P,C2).

father(F,C) (F=john,C=mary) ; (F=john,C=peter).

mother(M,C) (M=jane,C=mary) .

person(P,G) (P=john, G=male) ; (P=peter, G=male) ;

(P=jane, G=male) ; (P=mary, G=male) ;

(P=paul, G=male).

Page 253: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CHRCHRVV vs. Prolog vs. Prolog

CFOL semantics of CHRV guardless, single head simplification rule, equivalent to CFOL semantics of pure Prolog clause set sharing same conclusion (Clark's completion) Simplification rule: sh <=> true | b1

1, ..., bkp ; ... ; b1

1, ..., blq.

where: {X1, ..., Xn} = vars(shi), and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn} X1, ..., Xn true (sh Y1, ... , Ym ((b1

1 ... bk

p) ... (b11 ... bk

q))

Equivalent Prolog clauses: {sh :- b1

1, ..., bkp. , ... , sh :- b1

1, ..., blq.}

Thus, using Clark's completion, any Prolog program can be reformulated into a semantically equivalent CHRV program

CHRV extends Prolog with: Conjunctions in the heads Guards Non-ground numerical constraints heads, guards and bodies Propagation rules

Page 254: Ontologies Reasoning Components Agents Simulations Rule-Based Reasoning: Constraint Solving and Deduction Jacques Robin

CLP with CHRCLP with CHR

CLP Application Rule Base

CHR

HostProgrammingLanguage L

CHR EngineCHR Base for Domain D1 Solver

CHR Base for Domain Dk Solver

...