Constraint handling rules chr rule based constraint solving and deduction
Download
1 / 161

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


  • 105 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Constraint Handling Rules (CHR): Rule-Based Constraint Solving and Deduction' - tyrone-munoz


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.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 - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Constraint handling rules chr rule based constraint solving and deduction

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

Jacques Robin


Outline

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

Outline


Constraint handling rules chr key ideas
Constraint Handling Rules (CHR):Key Ideas

  • Originally a logical rule-based language to declaratively program specialized constraint solvers on top of a host programming language (Prolog, Haskell, Java)

  • Since evolved in a general purpose first-order knowledge representation language and Turing-complete programming language

  • Fact base contains both extensional and intentional knowledge in the form of a conjunction of constraints

  • Rule base integrates and generalizes:

    • Event-Condition-Action rules (themselves generalizing production rules) for constraint propagation

    • Conditional rewrite rules for constraint simplification

  • Relies on forward chaining and rule Left-Hand-Side (LHS) matching

  • Extended variant CHRV adds backtracking search and thus generalizes Prolog rules as well


Chr by example rule base defining in terms of
CHR by Example:Rule Base Defining  in Terms of =

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y.

% Constraint simplification (or rewriting) rules

% Syntax: <ruleName>@ <simplifiedHead> <=> <guard> | <body>

% Logically:Xvars(head  guard)

% <guard>  (<head>  Yvars(body - (head  guard)) <body>)

% Operationally: substitute in constraint store (knowledge base) constraints that match

% the rule simplified head by those in rule body with their variables instantiated from

% the match

[email protected] X  Y , Y  Z ==> X  Z.

% Constraint propagation (or production) rule (in this case, unguarded)

% Syntax: <ruleName>@ <propagatedHead> ==> guard | <body>

% Logically:Xvars(head  guard)

% <guard>  (<head>  Yvars(body - (head  guard)) <body>)

% Operationally: if constraint store (knowledge base) contains constraints that match

% the rule propagated head then add those in rule body to the store with their variables

% instantiated from the match


Chr by example rule base defining in terms of1
CHR by Example: Rule Base Defining  in Terms of =

[email protected] X  Y \ X Y <=> true.

% Constraint simpagation rule (in this case, unguarded)

% Syntax: <ruleName>@ <propagatedHead> \ <simplifiedHead> <=> guard | <body>

% Logically:Xvars((head  guard) <guard>  (<propagatedhead>  <simplifiedHead>%  Yvars(body - (head  guard)) <body>  <propagatedhead>)

% Operationally: if constraint store (knowledge base) contains constraints that match

% the rule simplified head and the rule propagated head, then substitute in the store% those matching the simplified head by the rule body with their variables instantiated% from the match

query1: A  B, C  A, B  C, A = 2% Initial constraint store: a constraint conjunction

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

query2:A  B, B  C, C  A

answer2:A = B, B = C


Chr by example rule base defining in terms of2

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Rule-Defined Constraint Store

Built-In Constraint Store

Matching Equations  Guard


Chr by example rule base defining in terms of3

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active Constraint


Chr by example rule base defining in terms of4
CHR by Example: Rule Base Defining  in Terms of =

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Normalizing Simplification

Active Constraint


Chr by example rule base defining in terms of5

[email protected] X  Y <=> X = Y | true.(A,B A = 2  X',Y' X' = A = Y' = B), eg, B = 3  2 = A

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active Constraint


Chr by example rule base defining in terms of6

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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;

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of7

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = A Y' = B = C), eg, B = 3  4 = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of8

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of9

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = B = C Y' = A),eg, B = 3  4 = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of10

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of11

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = A = C  Y' = B),eg, C = 3  2 = A

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of12

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of13

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = B  Y' = A = C),eg, C = 3  2 = A

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of14

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of15

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of16

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of17

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of18

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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


Chr by example rule base defining in terms of19

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of20

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of21

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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


Chr by example rule base defining in terms of22

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of23

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of24

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of25

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of26

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of27

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of28

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of29

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of30

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of31

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] 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

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of32

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of33

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true. (A,B,C A = 2  X',Y', Z' X' = Y' =Z' = A = B = C ), eg, A = 2  4 = C

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of34

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of35

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of36

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of37

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \X  Y <=> true. (A,B,C A = 2  X',Y‘ X' = Y' =A = B = C ), eg, A = 2  4 = C

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of38

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of39

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of40

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of41

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \X  Y <=> true. (A,B,C A = 2  X',Y‘ X' =A = C, Y’ = B), eg, A = 2  4 =C

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of42

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of43

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of44

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \X  Y <=> true.

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of45

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \X  Y <=> true. (A,B,C A = 2  X',Y‘ X' =A, Y’ = B = C), eg, B = 3  4 =C

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of46

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of47

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active

Constraint

Partner

Constraint


Chr by example rule base defining in terms of48

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] 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

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

Active

Constraint


Chr by example rule base defining in terms of49

[email protected] X  Y <=> X = Y | true.(A,B,C A = 2  X',Y' X' = Y' = B = C ), eg, B = 3  4 = C

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint


Chr by example rule base defining in terms of50

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of51

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = Y' =A = B = C), eg, B = 3  4 = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of52

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of53

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = A = C  Y' = B), eg, A = 2  4 = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of54

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of55

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = Y' = A = B = C), eg, A = 2  4 = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of56

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of57

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y (A,B,C A = 2  X',Y’ X' = Y' = A = B = C), eg, A = 2  4 = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of58

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of59

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y A,B,C A = 2  X',Y' X' = C’  Y’ = B), eg, A = 2, X’ = C, Y’ = B

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of60

[email protected] X  Y <=> X = Y | true.

[email protected]  Y,Y  X <=> X=Y A,B,C A = 2  X',Y' X' = C’  Y’ = B), eg, A = 2, X’ = C, Y’ = B

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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


Chr by example rule base defining in terms of61

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint


Chr by example rule base defining in terms of62

[email protected] X  Y <=> X = Y | true. (A,B,C A = 2, B = C  X',Y’ X' = Y' = A = B = C), eg, A = 2  4 = C

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint


Chr by example rule base defining in terms of63

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of64

[email protected] X  Y <=> X = Y | true.

[email protected] 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

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of65

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

Alternate matching combination:

Active constraint matched against rightmost head

Partner constraint matched against leftmost head

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of66

[email protected] X  Y <=> X = Y | true.

[email protected] 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

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of67

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of68

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y A,B,C A = 2, B = C  X',Y’ X' = A  Y’ = C), eg, X’ = 2, Y’ = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Partner

Constraint

Active

Constraint


Chr by example rule base defining in terms of69

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y A,B,C A = 2, B = C  X',Y’ X' = A  Y’ = C), eg, X’ = 2, Y’ = C

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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


Chr by example rule base defining in terms of70

[email protected] X  Y <=> X = Y | true.

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint


Chr by example rule base defining in terms of71

[email protected] X  Y <=> X = Y | true. A,B,C A = B = C = 2  X',Y’ X' = Y’ = A = B), eg, X’ = 2, Y’ = 2

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Active

Constraint


Chr by example rule base defining in terms of72

[email protected] X  Y <=> X = Y | true. A,B,C A = B = C = 2  X',Y’ X' = Y’ = A = B), eg, X’ = 2, Y’ = 2

[email protected] X  Y, Y  X <=> X=Y

[email protected] X  Y, Y  Z ==> X  Z.

[email protected] X  Y \ X  Y <=> true.

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

Constraints Simplified

Final Normalized Solved Form


Chr syntax overview

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: Syntax Overview

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


Chr complete abstract syntax

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

*

*

CHR: Complete Abstract Syntax

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


Chr derivation data structures

Used

Rule

*

Built-In

Constraint Store

Rule Defined

Constraint Store

*

*

Derivation

State

*

{ordered}

CHR

Derivation

CHR: Derivation Data Structures

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


Chr declarative semantics in classical first order logic cfol
CHR: Declarative Semantics inClassical First-Order Logic (CFOL)

  • Simplificationrule: sh1, ... , shi<=>g1, ..., gj|b1, ..., bk.

    where: {X1, ..., Xn} = vars(sh1 ...  shig1 ...  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 ...  phig1 ...  gj)and {Y1, ... , Ym} = vars(b1 ...  bk) \ {X1, ..., Xn}X1, ..., Xng1 ...  gj (ph1 ...  phi Y1, ... , Ymb1 ... bk)


Chr constraint and rule priority heuristics
CHR: Constraint and RulePriority 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


Chr base example defining min in terms of and

[email protected] min(X,Y,Z) <=> X  Y | Z = X

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | X = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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


Chr base example defining min in terms of and1

[email protected] min(X,Y,Z) <=> X  Y | Z = XM true |= X'=1,Y'=2,Z'=M X' = 1, Y' = 2, Z' = M, 1  2

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | Y = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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


Chr base example defining min in terms of and2

[email protected] 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'

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | Y = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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


Chr base example defining min in terms of and3

[email protected] 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'

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | Y = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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

Projection(CS,vars(Query))


Chr base example defining min in terms of and4

[email protected] min(X,Y,Z) <=> X  Y | Z = X

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | Y = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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


Chr base example defining min in terms of and5

[email protected] 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'

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | Y = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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


Chr base example defining min in terms of and6

[email protected] 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'

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | Y = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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


Chr base example defining min in terms of and7

[email protected] 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'

[email protected] min(X,Y,Z) <=> Y  X | Z = Y.

[email protected] min(X,Y,Z) <=> Z < X | Y = Z.

[email protected] min(X,Y,Z) <=> Z < Y | Y = Z.

[email protected] min(X,Y,Z) ==> Z  X, Z  Y.

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

Projection(CS,vars(Query))


Chr bases as component
CHR 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


Example chr base component assembly

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

Example CHR Base Component Assembly


Chr base example restricted form of real linear equations solver

[email protected] ?P == C <=> P = C.

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?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

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver1

[email protected] ?P == C <=> P = C ?Y, true|= ?P=?Y,C=2 ?P = ?Y, C = 2

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver2

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver3

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver

Why r1 does not apply?


Chr base example restricted form of real linear equations solver4

[email protected] ?P == C<=> P = C

[email protected] ?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

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver5

[email protected] ?P == C<=> P = C

[email protected] ?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

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver6

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver7

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver8

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=>?Q.number, R := C - ?Q | ?P = R

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver9

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=>?Q.number, R := C - ?Q | ?P = R

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver10

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=>?Q.number, R := C - ?Q | ?P = R

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?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

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver11

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=>?Q.number, R := C - ?Q | ?P = R

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?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

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver12

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver13

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R

[email protected] ?P + ?Q == C <=> ?P.number, R := C - ?P | ?Q = R.

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver14

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

[email protected] ?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

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr base example restricted form of real linear equations solver15

[email protected] ?P == C <=> P = C

[email protected] ?P + ?Q == C <=> ?Q.number, R := C - ?Q | ?P = R.

[email protected] ?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

[email protected] ?P + ?Q == C \ ?P - ?Q == D <=> R := (C + D) / 2 | ?P = R.

CHR Base Example: Restricted Formof Real Linear Equations Solver


Chr abstract syntax

OrAnd Formula

connective: enum{or,and}

CHR : Abstract Syntax

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


Chr declarative semantics in classical first order logic cfol1
CHR : Declarative Semantics inClassical First-Order Logic (CFOL)

  • Simplificationrule: sh1, ... , shi<=>g1, ..., gj|b11, ..., bkp ; ... ; b11, ..., blq.

    where: {X1, ..., Xn} = vars(sh1 ...  shig1 ...  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 ...  phig1 ...  gj)and {Y1, ... , Ym} = vars(b1 ...  bk) \ {X1, ..., Xn}X1, ..., Xng1 ...  gj (ph1  ... phi Y1, ... , Ym ((b11 ... bkp)  ...  (b11  ... bkq))


Chr operational semantics
CHR : 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


Chr base example map coloring problem

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

[email protected] d(r4,C) ==> (C = r ; C = b).

[email protected] d(r3,C) ==> (C = r ; C = b).

[email protected] d(r2,C) ==> (C = b ; C = g).

[email protected] d(r5,C) ==> (C = r ; C = g).

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem1

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem2

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem3

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem4

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem5

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem6

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem7

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem8

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem9

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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

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


Chr base example map coloring problem10

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem11

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem12

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] 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

[email protected] l([ ],[ ]) <=> true. eg., C1 = b  r = C7

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


Chr base example map coloring problem13

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem14

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem15

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem16

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem17

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem18

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem19

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem20

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] 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

[email protected] l([ ],[ ]) <=> true. eg., Cj = b  r = Ci

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


Chr base example map coloring problem21

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem22

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem23

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

...

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem24

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

[email protected] d(r7,C) ==> (C = r ; C = b).

[email protected] d(r4,C) ==> (C = r ; C = b).

[email protected] d(r3,C) ==> (C = r ; C = b).

[email protected] d(r2,C) ==> (C = b ; C = g).

[email protected] d(r5,C) ==> (C = r ; C = g).

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Chr base example map coloring problem25

r 1

r7

r2

r6

r

b

g

r3

r4

r5

r

g

t

b

b

g

g

r

r

r

b

b

b

CHR Base Example:Map Coloring Problem

% More efficient version with forward checking

[email protected] c(r1,r), c(r1,b), c(r1,g) ==> false.

[email protected] d(r1,C), c(r1,r), c(r1,b) ==> C = g.

[email protected] d(r1,C), c(r1,r), c(r1,g) ==> C = b.

[email protected] d(r1,C), c(r1,b), c(r1,g) ==> C = r.

[email protected] d(r1,C), c(r1,b) ==> (C = r ; C = g).

[email protected] d(r1,C), c(r1,g) ==> (C = r ; C = b).

[email protected] d(r1,C), c(r1,r) ==> (C = b ; C = g).

[email protected] d(r1,C) ==> (C = r ; C = b ; C = g).

...

[email protected] d(r6,C) ==> (C = r ; C = g; C = t).

[email protected] 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).

[email protected] n(Ri,Rj), d(Rj,Cj) ==> c(Ri,Cj).

[email protected] n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false.

[email protected] l([ ],[ ]) <=> true.

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


Implementing a rewriting system in chr
Implementing a Rewriting System in 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).


Example term rewriting as chr solving fibonacci

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

[email protected] plus(X,U,V) <=> U = 0 | V = X.

[email protected] plus(X,U,V) <=> U = suc(Y) |

V = suc(W), plus(X,Y,W).

[email protected] fib(U,V) <=> U = 0 | V = suc(0).

[email protected] fib(U,V) <=> U = suc(0) | V = suc(0).

[email protected] fib(U,V) <=> U = suc(W), W = suc(N) |

fib(N,Y), fib(W,X), plus(X,Y,V).

Example Term Rewritingas CHRSolving:fibonacci


Example term rewriting as chr solving solving fibonacci 2

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] f(U,V) <=> U = s(W), W = s(N) |

f(N,Y), f(W,X), p(X,Y,V).

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 21

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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)

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 22

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 23

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 24

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 25

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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)

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 26

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 27

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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)

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 28

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 29

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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)

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 210

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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)

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 211

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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))

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 212

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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))

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?


Example term rewriting as chr solving solving fibonacci 213

[email protected] p(X,U,V) <=> U = 0 | V = X.

[email protected] p(X,U,V) <=> U = s(Y) | V = s(W), p(X,Y,W).

[email protected] f(U,V) <=> U = 0 | V = s(0).

[email protected] f(U,V) <=> U = s(0) | V = s(0).

[email protected] 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))

Example Term Rewritingas CHR Solving Solving: fibonacci(2) = ?

Projection(BICS, vars(Query))


Chr v vs rewriting systems

CHR V:

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

CHRV vs. Rewriting Systems

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)


Implementing a production system in chr
Implementing a Production System in CHR

  • 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


Chr v vs production systems

CHR V:

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

CHRV vs. Production Systems

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


Implementing a prolog program in chr
Implementing a Prolog Program in CHR

  • 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(t11,...,tn1) :- b1. ... p(t1k,...,tnk) :- bk.}that provide the intentional part of the definition for predicate p

    • onto a CHRsimplification 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 CHRworld 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


Example prolog program implemented in chr

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

Example Prolog ProgramImplemented in CHR


Chr v vs prolog
CHR V 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)

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

  • 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 with chr
CLP with CHR

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 with chr1
CLP with CHR

CLP Application Rule Base

CHR Base for Domain D1 Solver

CHR Engine

...

CHR

Host

Programming

Language L

CHR Base for Domain Dk Solver


Chr v practical applications
CHR V: 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


ad