Skip to main content

Constraint Handling Rules

A Tutorial for (Prolog) Programmers

  • Conference paper
Logic Programming (ICLP 2008)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 5366))

Included in the following conference series:

Abstract

Constraint Handling Rules (CHR) [2,5] is a high-level programming language based on multi-headed, committed-choice, guarded multiset rewrite rules. Originally designed in 1991 by Frühwirth for the particular purpose of adding user-defined constraint solvers to a host-language, CHR has matured over the last decade to a powerful and elegant general-purpose language with a wide spectrum of application domains.

Different semantics have been proposed for the language, based on various logics (first-order logic, linear logic, ...). These logics, in combination with rewriting techniques, have been used to study program properties such as soundness and completeness, confluence, termination, ...While that line of work treats CHR as a calculus, this tutorial teaches CHR as a proper programming language.

As a programming language, CHR seems simple enough: The programmer specifies a number of rewrite rules, and the CHR engine applies these rules exhaustively to an initial (multi-)set of constraints. Yet, this simplicity hides great power: e.g., the power to quickly prototype new constraint solvers, the power to implement Prolog’s co-routining predicates freeze/2 and when/2 in a single CHR rule each, and the power to subsume Guarded Horn Clauses while still not exploiting CHR’s full potential. Moreover, CHR is the only declarative language known in which every algorithm can be implemented with optimal space and time complexity [4].

Unfortunately, few Prolog programmers are aware of the CHR language or that it is available in their Prolog system. These programmers are unable to tap into CHR’s power, so they have to go to great length to accomplish even simple tasks. Or they simply give up. This tutorial shows how to use CHR for solving their problems quickly and elegantly. Simple examples teach interactively how to write and reason about CHR programs, and what problems one can solve effectively with CHR.

This tutorial starts with ground CHR, the three types of rules, and the refined semantics [1] which is based on the notion of the active constraint and its occurrences. Other topics covered are triggering of rules, the propagation history, the use of data structures and the host language, declarations and impure features, and the common pitfalls of CHR.

This tutorial intends to make the attendants aware of CHR’s strengths as a programming language, and teaches them when and how to apply CHR for small to medium sized problems. The full set of tutorial slides is available at http://www.cs.kuleuven.be/~dtai/projects/CHR/ .

About the Speaker. Tom Schrijvers is a post-doctoral researcher at the K.U.Leuven in Belgium, who has defended his Ph.D. thesis on Analyses, Optimizations and Extensions of Constraint Handling Rules in 2005 [3]. His CHR implementation, the K.U.Leuven CHR system, is the most advanced in its kind and is in wide-spread use in many Prolog systems. Tom uses CHR on a daily basis, for implementing his compiler, for supporting his type checking and test generation research, or simply for gaining an edge in the Prolog Programming Contest.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Institutional subscriptions

Similar content being viewed by others

References

  1. Duck, G.J., Stuckey, P.J., García de la Banda, M., Holzbaur, C.: The refined operational semantics of Constraint Handling Rules. In: Demoen, B., Lifschitz, V. (eds.) ICLP 2004. LNCS, vol. 3132, pp. 90–104. Springer, Heidelberg (2004)

    Chapter  Google Scholar 

  2. Frühwirth, T.: Theory and practice of Constraint Handling Rules. J. Logic Programming, Special Issue on Constraint Logic Programming 37(1-3), 95–138 (1998)

    MathSciNet  MATH  Google Scholar 

  3. Schrijvers, T.: Analyses, optimizations and extensions of Constraint Handling Rules. PhD thesis, K.U. Leuven, Belgium (June 2005)

    Google Scholar 

  4. Sneyers, J., Schrijvers, T., Demoen, B.: The computational power and complexity of Constraint Handling Rules. In: ACM TOPLAS (accepted, 2008)

    Google Scholar 

  5. Sneyers, J., Van Weert, P., Schrijvers, T., De Koninck, L.: As time goes by: Constraint Handling Rules – A survey of CHR research between 1998 and 2007. Journal of Theory and Practice of Logic Programming (submitted, 2008)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2008 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Schrijvers, T. (2008). Constraint Handling Rules. In: Garcia de la Banda, M., Pontelli, E. (eds) Logic Programming. ICLP 2008. Lecture Notes in Computer Science, vol 5366. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-89982-2_3

Download citation

  • DOI: https://doi.org/10.1007/978-3-540-89982-2_3

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-89981-5

  • Online ISBN: 978-3-540-89982-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics