Constraint Handling Rules (CHR): Rule-Based Constraint Solving and Deduction

Download Presentation

Constraint Handling Rules (CHR): Rule-Based Constraint Solving and Deduction

Loading in 2 Seconds...

- 73 Views
- Uploaded on
- Presentation posted in: General

Constraint Handling Rules (CHR): Rule-Based Constraint Solving and Deduction

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Constraint Handling Rules (CHR):Rule-Based Constraint Solving and Deduction

Jacques Robin

Constraint Handling Rules (CHR)

Key ideas

Introductory example

CHR constraint solver over real variables

CHR with disjunction (CHR)

CHR constraint solver over finite domain variables

General purpose rule-based reasoning with CHR

A taxonomy of rule-based languages

Production rules and ECA rules in CHR

Conditional term rewrite rules in CHR

Prolog and CLP rules in CHR

Deduction with CHR

Propositional deduction as Boolean constraint solving in CHR

First-order Horn Logic forward chaining with CHR

First-order Horn Logic backward chaining with CHR

First-order logic refutation and resolution based entailment with CHR

Description logic reasoning with CHR

- 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

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

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 conjunction

answer1:A = 2, B = 2, C = 2, % Final constraint store = initial constraint store% simplified through repeated rule application until no rule neither simplifies nor% propagates any new constraint

query2:A B, B C, C A

answer2:A = B, B = C

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-Defined Constraint Store

Built-In Constraint Store

Matching Equations Guard

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

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

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

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

Condition for firing a rule:

Rule head matches active constraint in RDCS

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

Every other head from the rule matches against some other (partner) constraint in the RDCS

Generates another set of equations (inserted to MEG)

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

Active Constraint

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

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

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

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

Normalizing Simplification

Active Constraint

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.

Active Constraint

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

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

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

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

Rule firing order depends on 3 heuristics, with the following priority:

Rule-defined constraint ordering to become active

Rule ordering to try matching and entailment check with active constraint

Rule-defined constraint ordering to become partner constraints

Engine first tries matching and entailment check:

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;

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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.

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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.

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

Partner

Constraint

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

Active

Constraint

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.

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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

Partner

Constraint

Active

Constraint

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

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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

Partner

Constraint

Active

Constraint

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

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

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.

Active

Constraint

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.

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

Partner

Constraint

Active

Constraint

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.

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.

Active

Constraint

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.

Active

Constraint

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.

Constraints Simplified

Final Normalized Solved Form

body

guard

0..1

Logical

Formula

CHR

Rule

2..*

simplified head

*

0..1

And Formula

propagated head

0..1

{non-overlapping, complete}

Atomic Formula

Simpagation

Rule

Simplification

Rule

Propagation

Rule

Built-In

Constraint

Rule Defined

Constraint

CHR

Base

- 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 (event 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.

Head: Rule-Defined Constraints

Guard:

Built-In Constraints

(from host language)

Body:

Rule-Defined and

Built-In Constraints

arg

*

Constraint

Symbol

*

Term

*

{non-overlapping,

complete}

{non-overlapping,

complete}

Rule Defined

Constraint

Symbol

Rule Defined

Constraint

arg

Built-In

Constraint

Symbol

Non-Ground

Term

Ground

Term

Non-Functional

Term

Functional

Term

Built-In

Constraint

true

false

Constant

Symbol

Function

Symbol

Constraint

Domain

Variable

*

*

body

guard

0..1

Logical

Formula

CHR

Rule

2..*

simplified head

*

CHR

Base

0..1

And Formula

propagated head

0..1

{non-overlapping, complete}

Atomic Formula

Simpagation

Rule

Simplification

Rule

Propagation

Rule

Used

Rule

*

Built-In

Constraint Store

Rule Defined

Constraint Store

*

*

Derivation

State

*

{ordered}

CHR

Derivation

body

guard

0..1

CHR

Logical

Formula

CHR

Rule

2..*

simplified head

*

CHR

Base

0..1

And Formula

propagated head

0..1

arg

Atomic Formula

*

Simpagation

Rule

Simplification

Rule

Propagation

Rule

Term

Built-In

Constraint

Rule Defined

Constraint

- Simplificationrule: sh1, ... , shi<=>g1, ..., gj|b1, ..., bk.
where: {X1, ..., Xn} = vars(sh1 ... shig1 ... gj) and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}X1, ..., Xng1 ... gj (sh1 ... shi Y1, ... , Ymb1 ... bk)

- Propagation rule: ph1, ... , phi==>g1, ..., gj|b1, ..., bk.
where: {X1, ..., Xn} = vars(ph1 ... phig1 ... gj)and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}X1, ..., Xng1 ... gj (ph1 ... phi Y1, ... , Ymb1 ... bk)

- 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

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.

r1@ min(X,Y,Z) <=> X Y | Z = XM 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.

r1@ min(X,Y,Z) <=> X Y | Z = XM 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.

r1@ min(X,Y,Z) <=> X Y | Z = XM 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.

Projection(CS,vars(Query))

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.

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.

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.

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.

Projection(CS,vars(Query))

- 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

<<Component>>

CHRDEngine

<<Component>>

MinCHRDBase

<<Interface>>

Min

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

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

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

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

min(X,Y,Z) Z X Z Y

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

<<Interface>>

CHRDEngine

«uses»

«uses»

derive()

<<Component>>

LoeStlCHRDBase

<<Component>>

HostPlatform

X Y X = Y | true

X Y Y X X = Y

X Y Y Z X ZX Y \ X Y true

X X false

X 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

<<Interface>>

LoeStl

<<Interface>>

EqNeq

«uses»

(X:Real, Y:Real): Boolean

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

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

(X:Real, Y:Real): Boolean

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

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.

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.

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.

Why r1 does not apply?

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.

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

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

?X,?Y ?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.

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.

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.

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.

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.

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

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

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.

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.

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.

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.

OrAnd Formula

connective: enum{or,and}

2..*

body

guard

0..1

CHR

Rule

And

Formula

Tried

Alternative

Body

simplified head

*

CHR

Base

0..1

*

propagated head

0..1

Atomic Formula

Fired

Rule

Simpagation

Rule

Simplification

Rule

Propagation

Rule

Constraint

*

{ordered}

*

*

*

Derivation

State

CHR

Derivation

Rule Defined

Constraint Store

Rule Defined

Constraint

Built-In

Constraint

Built-In

Constraint Store

*

*

true

false

- Simplificationrule: sh1, ... , shi<=>g1, ..., gj|b11, ..., bkp ; ... ; b11, ..., blq.
where: {X1, ..., Xn} = vars(sh1 ... shig1 ... gj) and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}X1, ..., Xng1 ... gj (sh1 ... shi Y1, ... , Ym((b11 ... bkp) ... (b11 ... bkq))

- Propagation rule: ph1, ... , phi==>g1, ..., gj|b11, ..., bkp ; ... ; b11, ..., blq.
where: {X1, ..., Xn} = vars(ph1 ... phig1 ... gj)and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}X1, ..., Xng1 ... gj (ph1 ... phi Y1, ... , Ym ((b11 ... bkp) ... (b11 ... bkq))

- 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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

Already fired w/ same constraint. Not repeated to avoid trivial non-termination

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

...

d6@ d(r6,C) ==> (C = r ; C = g; C = t).

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false. C1,C7Ri',Rj',Ci',Cj' C1=r | Ri=r1, Rj=r7, Ci=C1, Cj=C7, Ci=Cj

l1@ l([ ],[ ]) <=> true. eg., C1 = b r = C7

l2@ l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs).

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

n@ n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false. C1,C7Ri',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).

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

...

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

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

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

r1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

% More efficient version with forward checking

d1@ 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).

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

- 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 CHRguard the rewrite rule LHS onto the CHRhead the rewrite rule RHS onto the CHRbody
- 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).

plus(X,0) X

plus(X,suc(Y)) suc(plus(X,Y))

fib(0) suc(0)

fib(suc(0)) suc(0)

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

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

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)

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

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

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

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)

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

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)

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

R=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

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=0

X4=X1 X1=s(0) X4=s(0)

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 = 0

e.g., U5=0, V5=W4, X5=s(0)

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

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

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

Projection(BICS, vars(Query))

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

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

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)

- Map each production rule of the form:IF m1 AND ... AND ml THEN a1 AND ... AND anwhere: {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

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

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

Production Systems:

- Fact base only contains ground Datalog atoms
- Cumbersome modeling to implement goal-driven reasoning
- No disjunctions in RHS
- No built-in search

- Map Prolog fact base of the form {f1. ... fn.}
- onto a fact introduction CHRpropagation rule: facts f1 ,..., fn.

- Map each set of Prolog deductive rules of the form{p(t11,...,tn1) :- b1. ... p(t1k,...,tnk) :- bk.}that provide the intentional part of the definition for predicate p
- onto a CHRsimplification rule of the formp(X1,...,Xn) (X1=t11,..., Xn=tn1, b1) ;...; (X1=t1k ,..., Xn=tnk, bk).where {X1,...,Xn} is a set of fresh variablesnot occurring in {t11,...,tn1,b1, ... p(t1k,...,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 CHRworld closure propagation rule of the formp(X1,...,Xn) (X1=t'11,..., Xn=t'n1) ;...; (X1=t'1k ,..., Xn=t'nk).

- Valid only for pure Prolog programs

Prolog Program

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).parent(P,C) :- mother(P,C).

sibling(C1,C2) :- not C1 = C2, parent(P,C1),

parent(P,C2).

CHR Translation

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

- CFOL semantics of CHRV guardless, single head simplification rule, equivalent to CFOL semantics of pure Prolog clause set sharing same conclusion (Clark's completion)
- Simplificationrule: sh<=>true|b11, ..., bkp ; ... ; b11, ..., blq.
where: {X1, ..., Xn} = vars(shi), and {Y1, ... , Ym} = vars(b1 ... bk) \ {X1, ..., Xn}X1, ..., Xntrue (sh Y1, ... , Ym((b11 ... bkp) ... (b11 ... bkq))

- Simplificationrule: sh<=>true|b11, ..., bkp ; ... ; b11, ..., blq.
- Equivalent Prolog clauses:{sh :- b11, ..., bkp. , ... , sh :- b11, ..., 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

CLP Application Rule Base

CLP Engine

CHR Base for Domain D1 Solver

Prolog Engine

CHR Engine

...

CHR

Host

Programming

Language L

Prolog/L Bridge

CHR Base for Domain Dk Solver

CLP Application Rule Base

CHR Base for Domain D1 Solver

CHR Engine

...

CHR

Host

Programming

Language L

CHR Base for Domain Dk Solver

- 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