Article thumbnail

Termination Analysis of Constraint Handling Rules: Theory and Practice

By Paolo Pilozzi

Abstract

Constraint Handling Rules (CHR), closely related to Logic Programming (LP), is a declarative programming language. Over the years, the language proved successful for implementing many kinds of problems efficiently. Mainly this, but also its simple syntax and semantics, accounts for its success and impact on the research community. To further encourage the use of CHR, we need to further improve its efficiency of execution. To this end, termination analysis of CHR can be seen as one of the main sources of input. Furthermore, in the context of program debugging, termination analysis of CHR is an important asset. Due to the many language specifics, it is often hard for programmers to point out unwanted loops in their CHR programs. It is therefore essential to have a good understanding of the termination problem in CHR. Until recently, however, there was only an informal discussion on termination of the subset of CHR that only considers simplification rules. The contributions of this thesis are therefore twofold. First, we provide for a theoretical framework for termination analysis of the full CHR language. Secondly, based on this theoretical framework, we derive an approach for automated termination analysis of CHR. This approach extends the approaches in LP to integer polynomial interpretations and can be modularised. Furthermore, the approach is practical, as we demonstrate with T*CoP, a Termination analyser for CHR on top of Prolog.Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . v Contents . . . . . . . . . . . . . . . . . . . . . . . . . . ix List of Figures . . . . . . . . . . . . . . . . . . . . . . xv List of Tables . . . . . . . . . . . . . . . . . . . . . . xvii 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Motivating termination analysis . . . . . . . . . . . . . 1 1.2 Motivating termination analysis for CHR . . . . . . . . . 2 1.3 Defining the termination problem for CHR . . . . . . . . 3 1.3.1 Transformational vs. direct approaches . . . . . . . . 5 1.3.2 Host language . . . . . . . . . . . . . . . . . . . . . 5 1.3.3 Termination of simplification . . . . . . . . . . . . . 6 1.3.4 The effect of matching . . . . . . . . . . . . . . . . 7 1.3.5 The effect of guarded rules . . . . . . . . . . . . . . 8 1.3.6 Termination of propagation . . . . . . . . . . . . . . 9 1.3.7 Availability of different control structures . . . . 10 1.4 Overview . . . . . . . . . . . . . . . . . . . . . . . 11 I Theory . . . . . . . . . . . . . . . . . . . . . . . . . 13 2 Termination of abstract CHR . . . . . . . . . . . . . . . 14 2.1 CHR syntax . . . . . . . . . . . . . . . . . . . . . . 15 2.2 The abstract CHR semantics . . . . . . . . . . . . . . 18 2.3 Termination of abstract CHR . . . . . . . . . . . . . . 22 2.3.1 Termination of abstract CHR . . . . . . . . . . . . . 22 2.3.2 A termination proof by a well-founded order . . . . . 23 2.3.3 The intended use . . . . . . . . . . . . . . . . . . 27 2.3.4 Termination of non-ground CHR programs . . . . . . . 29 2.3.5 The success set of a CHR program . . . . . . . . . . 30 2.3.6 The Ranking Condition for abstract CHR . . . . . . . 34 2.3.7 Correctness of the RC for abstract CHR . . . . . . . 37 2.4 Termination of typical abstract CHR programs . . . . . 40 2.4.1 Greatest common divisor . . . . . . . . . . . . . . . 40 2.4.2 Merge-sort . . . . . . . . . . . . . . . . . . . . . 41 3 Termination of CHR with propagation . . . . . . . . . . . 44 3.1 The theoretical CHR semantics . . . . . . . . . . . . . 45 3.2 Termination of CHR with propagation . . . . . . . . . . 50 3.2.1 The intended use and success set of a CHR program . . 51 3.2.2 Termination of CHR with propagation . . . . . . . . . 52 3.2.3 The RC for CHR with propagation . . . . . . . . . . . 52 3.2.4 Correctness of the RC for CHR with propagation . . . 56 3.3 Termination of typical CHR programs . . . . . . . . . . 58 3.3.1 Merge-sort . . . . . . . . . . . . . . . . . . . . . 59 3.3.2 Primes . . . . . . . . . . . . . . . . . . . . . . . 59 3.3.3 Fibonacci . . . . . . . . . . . . . . . . . . . . . . 60 3.3.4 Problem classes . . . . . . . . . . . . . . . . . . . 61 4 Termination of CHR . . . . . . . . . . . . . . . . . . . 62 4.1 Problem description . . . . . . . . . . . . . . . . . . 62 4.1.1 A new CHR state representation . . . . . . . . . . . 65 4.2 Termination of propagation . . . . . . . . . . . . . . 67 4.2.1 The RC for CHR on propagation rules . . . . . . . . . 68 4.2.2 Correctness of the RC for CHR on propagation rules . 68 4.3 Termination of CHR . . . . . . . . . . . . . . . . . . 74 4.3.1 A new CHR state representation . . . . . . . . . . . 74 4.3.2 The RC for CHR . . . . . . . . . . . . . . . . . . . 77 4.3.3 Correctness of the RC for CHR . . . . . . . . . . . . 82 4.4 Termination of typical CHR programs . . . . . . . . . . 87 4.4.1 Merge-sort . . . . . . . . . . . . . . . . . . . . . 87 4.4.2 Primes . . . . . . . . . . . . . . . . . . . . . . . 88 4.4.3 Fibonacci . . . . . . . . . . . . . . . . . . . . . . 88 4.4.4 Second problem from Section 3.3.4 . . . . . . . . . . 89 5 Theory: Conclusions . . . . . . . . . . . . . . . . . . . 90 5.1 A comparison of RCs . . . . . . . . . . . . . . . . . . 91 5.1.1 RC for abstract CHR vs. RC for CHR with propagation . 92 5.1.2 RC for abstract CHR vs. RC for CHR . . . . . . . . . 92 5.1.3 RC for CHR with propagation vs. RC for CHR . . . . . 93 5.2 Limitations of the RC for CHR . . . . . . . . . . . . . 94 5.2.1 The success set of CHR predicates . . . . . . . . . . 94 5.2.2 Extensions different from multiset extensions . . . . 95 5.2.3 Single-headed propagation rules . . . . . . . . . . . 97 5.2.4 Refined control . . . . . . . . . . . . . . . . . . . 98 II Practice . . . . . . . . . . . . . . . . . . . . . . . . 100 6 Automating termination analysis for CHR . . . . . . . . . 102 6.1 A verifiable RC for CHR . . . . . . . . . . . . . . . . 104 6.1.1 Polynomial interpretations . . . . . . . . . . . . . 106 6.1.2 The RC for CHR with polynomial interpretations . . . 110 6.2 Automating the termination proof . . . . . . . . . . . 125 6.2.1 Conditions for inferring the success set relations . 128 6.2.2 Conditions for inferring the call set relations . . . 129 6.2.3 Conditions for verifying rigidity . . . . . . . . . . 134 6.2.4 Conditions for verifying N-closedness . . . . . . . . 134 6.2.5 Conditions for verifying the decrease conditions . . 135 6.3 Towards constraints on symbolic coefficients . . . . . 141 6.4 Solving Diophantine constraints . . . . . . . . . . . . 143 6.5 Termination of CHR for specific queries . . . . . . . . 144 7 Modularised termination proofs for CHR . . . . . . . . . 146 7.1 Problem description . . . . . . . . . . . . . . . . . . 147 7.2 The CHR dependency graph and CHR net . . . . . . . . . 148 7.3 Self-sustainable SCCs of a CHR program . . . . . . . . 151 7.3.1 Self-sustainable SCCs . . . . . . . . . . . . . . . . 152 7.3.2 Non-self-sustainable SCCs . . . . . . . . . . . . . . 157 8 T*CoP: Termination of CHR on top of Prolog . . . . . . . 160 8.1 Implementation . . . . . . . . . . . . . . . . . . . . 161 8.1.1 The non-self-sustainability test . . . . . . . . . . 162 8.1.2 Verifying the RC for CHR . . . . . . . . . . . . . . 162 8.1.3 The Diophantine constraint solver . . . . . . . . . . 163 8.2 Evaluation . . . . . . . . . . . . . . . . . . . . . . 163 8.2.1 Interpreting the results . . . . . . . . . . . . . . 164 8.2.2 Evaluating the results . . . . . . . . . . . . . . . 166 9 Practice: Conclusions . . . . . . . . . . . . . . . . . . 170 9.1 Limitations of the RC for CHR with P . . . . . . . . . 171 9.1.1 Limitations inherited from the RC for CHR . . . . . . 171 9.1.2 Interpreting functor symbols in Z . . . . . . . . . 171 9.1.3 Interargument relations with multiple conjuncts . . . 172 9.1.4 Limitations not specific to CHR . . . . . . . . . . . 173 9.2 Self-sustainability of propagation . . . . . . . . . . 174 10 Conclusions . . . . . . . . . . . . . . . . . . . . . . 175 10.1 A formal framework for CHR-termination . . . . . . . . 175 10.2 Verifiable conditions for CHR-termination . . . . . . 176 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . 179 Biography . . . . . . . . . . . . . . . . . . . . . . . . . 191 List of Publications . . . . . . . . . . . . . . . . . . . . 193nrpages: 228status: publishe

Topics: Termination Analysis, Constraint Handling Rules, Declarative Programming Languages
Year: 2011
OAI identifier: oai:lirias.kuleuven.be:123456789/319173
Provided by: Lirias

Suggested articles


To submit an update or takedown request for this paper, please submit an Update/Correction/Removal Request.