on completion of constraint handling rules
play

On Completion of Constraint Handling Rules Slim Abdennadher and Thom - PDF document

On Completion of Constraint Handling Rules Slim Abdennadher and Thom Fr uhwirth Computer Science Department University of Munich Oettingenstr. 67, 80538 Munich, Germany 1 6 Architecture of Constraint Programs application (e.g. in a CLP


  1. On Completion of Constraint Handling Rules Slim Abdennadher and Thom Fr¨ uhwirth Computer Science Department University of Munich Oettingenstr. 67, 80538 Munich, Germany 1

  2. 6 Architecture of Constraint Programs application (e.g. in a CLP language) constraints black-box constraint solver (e.g. arithmetic constraints) 2 6 6

  3. 6 with CHR 6 user-defined constraints CHR program (e.g. interval arithmetics) predefined 2-a 6

  4. � In general constraint application are written in a CLP language Remarks � CHR is a proposal to extend CLP languages to allow the user to using black box solvers. Nevertheless these solvers are efficient, this approach makes it hard to modify a solver or build a solver over a new domain, let alone reason about and analyze it. � CHR: declarative � Black-box solver: non-declarative define new constraints, together with rules specifying how the new constraints react with the constraint store. 2-1

  5. � defined by CHR: � � defined by the blackbox solver: true , = CHR: Introductory Example X � X , [ X � Y , X = Y j true (reflexivity) ] X � Y ^ Y � X , X = Y X � Y ^ Y � Z ) X � Z true (reflexivity) A � B ^ B � C ^ C � A (antisymmetry) (transitivity) A � B ^ B � C ^ C � A ^ A � C A � B ^ B � C ^ A = C (transitivity) A � B ^ B � A ^ A = C (antisymmetry) A = B ^ A = C (black-box solver) (antisymmetry) 3

  6. � CHR consists of guarded rules. We distinguish two kinds of rules. Remarks � We define a user-defined constraint for less-than-or-equal. The Simplification rule replaces constraints by simpler constraints while preserving logical equivalence. Propagation rule adds new con- straints, which are logically redundant but may cause further sim- plification. � The reflexivity rule states that X � X is logically true. Whenever we see a constraint of the form A � A we can simplify it with true. The syntactical equality and true are predefined constraints. The CHR program implements reflexivity, antisymmetry, and transitivity in a straightforward way. � The antisymmetry rule means that if we find X � Y as well as Y � X reflexivity rule can be written using a guard (a precondition on the � The transitivity rule propagates constraints. It states that the con- aplicability of the rule). junction of X � Y and Y � Z implies X � Z . Operationally, we add the logical consequence X � Z as a redundant constraint. in the current constraint, we can replace them by the logically equivalent X=Y . � Redundancy from propagation rules is useful, as the following computation shows: 3-1

  7. H , C j B 8 x � ( C ! ( H $ 9 y � B )) H ) C j B 8 x � ( C ! ( H ! 9 y � B )) CHR: Syntax and Declarative Semantics x : variables occurring in � H or C ; y : variables occurring only in � B ;) Simplification rule: Propagation rule: ( � the above logical formulas + � a constraint theory C T for the predefined constraints. Declarative semantics of a CHR program: 4

  8. � 0 C T j = 8 ( G $ G ) 0 is “simpler” than CHR: Calculus G G G Solve 0 G If and ( H , C j B ) is a fresh variant of a rule with variables x � then G G pr e are the predefined constraints in 0 C T j = G ! 9 x � ( H = H ^ C ) pr e Simplify 0 H ^ G If 0 H = H ^ B ^ G and and ( H ) C j B ) is a fresh variant of a rule with variables x � then G G pr e are the predefined constraints in 0 C T j = G ! 9 x � ( H = H ^ C ) pr e Propagate 0 H ^ G If 0 0 H = H ^ B ^ H ^ G and and then 5

  9. � “ ^ ” is AC (or AC1 with unit > ) 0 ”: syntactic equality per component of the conjunctions � “ H = H 0 ; H and H � simplified states and rules; � Actual states contain information to avoid trivial nontermination of propagation rules. 5-1

  10. ❖ � ❖ ❖ ❖ ❖ ❖ ❖ ❖ ❖ ❖ ❖ P � P P P P P P P P P P P ❖ Confluence Given a goal, every computation leads to the same result no matter what rules are applied. A decidable, sufficient and necessary condition for confluence of terminating CHR programs through joinability of critical pairs X � X , (Abdennadher, CP97). X � Y ^ Y � X , X = Y Example A � A ^ A � A true (reflexivity) (antisymmetry) A � A A = A Solv e � ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ reflexivity antisymmetry � ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ reflexivity true 6

  11. � In previous work we introduced a notion of confluence for CHR Remarks � We gave a decidable, sufficient and necessary syntactic condi- programs. Confluence is an essential syntactical property of any constraint solver. It ensures that the solver will always compute the same result for a given set of constraints independent of which rules are applied. � These critical pairs can be derived from rules with overlapping tion for confluence of terminating CHR programs. This condition � Consider the program for less-than-or-equal. adopts the notion of critical pairs as known from term rewriting systems. heads. The critical state stems from unifying the first atom of the head of the reflexivity rule with the first atom of the head of the antisymmetry rule. The crit- ical pair stems from applying the reflexivity and the antisymmetry rule. 6-1

  12. ◆ � � ◆ ◆ ◆ ◆ ◆ ◆ ◆ ◆ ◆ ◆ Completion X � Y ^ Y � X , X = Y Derive rules from a non-joinable critical pair that would allow a X � Y ^ Y < X , f al se transition from one of the critical states into the other one. A � B ^ B � A ^ B < A (antisymmetry) (inconsistency) B � A ^ f al se A = B ^ B < A Solv e Solv e � � ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ ♦ f al se A = B ^ A < A inconsistency antisymmetry X < X , X = Y j f al se (irreflexivity) 7

  13. � The idea of completion is to derive a rule from a non-joinable criti- Remarks � This example shows that the completion method can be used - to cal pair that would allow a transition from one of the critical states � We extend the CHR program for less-than-or-equal by a simplifi- into the other one, thus re-introducing confluence. � The completion procedure inserts the following rule ... expressing some extent – to specialize constraints. < . cation rule expressing the interaction between less-than-or-equal and less. Then the resulting program loses confluence. the irreflexivity of 7-1

  14. P P � P P P P P P P P P p ( X ; Y ) , X � Y ^ q ( X ; Y ) p ( X ; Y ) , X > Y ^ r ( X ; Y ) Orientation of the Rules p ( A; B ) (r1) (r2) q ( A; B ) ^ A � B r ( A; B ) ^ A > B � ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥ r ( X ; Y ) , X > Y j q ( X ; Y ) ^ X � Y r1 r2 q ( X ; Y ) ) X � Y j X > Y (r3) (r4) 1¡ 8

  15. � In contrast to completion methods for TRS, we need more than Remarks � We write the following CHR program, where p, q and r are one rule to make a critical pair joinable and in general it is not suf- � ; > are built-in constraints. The ficient to insert only simplification rules as in completion for TRS, in order to join a non-joinable critical pair. as the following example shows. user-defined constraints and CHR program is not confluent, since the c.p. stemming from r1 and r2 is non-joinable. 8-1

  16. � C : set of critical pairs � P : set of rules Inference Rules of Completion ( C ; P ) ( S ; S ) is a critical pair of P 1 2 ( C [ f ( S ; S ) g ; P ) 1 2 CP-Deduction: ( C [ f ( S ; S ) g ; P ) 1 2 0 S 7! S 1 1 0 S 7! S 2 2 0 ( C [ f ( S ; S ) g ; P ) 2 CP-Simplification: 1 ( C [ f ( S ; S ) g ; P ) 1 2 S S 1 and 2 are joinable ( C ; P ) CP-Deletion: ( C [ f ( S ; S ) g ; P ) 1 2 R = orient ( S ; S ) � 1 2 ( C ; P [ R ) CP-Orientation: 9

  17. � Our completion algorithm maintains a set C of critical pairs and a P of rules. � The rule CP-Deduction permits to add critical pairs to C . Remarks � The rule CP-Simplification replaces state in a critical pair by its set � The rule CP-Deletion removes a joinable critical pair. � CP-Orientation removes a critical pair from C and adds new rules P , provided the critical pair can be oriented with respect to the successor state. � . to termination ordering 9-1

  18. Properties of Completion (I) 1. The algorithm stops successfully 2. The algorithm aborts unsuccessfully 3. The algorithm does not terminate Range-restricted Rule: P is a range-restricted terminating CHR program and Every variable in the body or the guard appears also in the head. 0 P Correctness Theorem � confluent If the completion procedure is successful � terminating Then: Output � logically equivalent to P 10

Recommend


More recommend