Content deleted Content added
No edit summary |
→Example program: Adding wikilinks Tag: Disambiguation links added |
||
(30 intermediate revisions by 19 users not shown) | |||
Line 1:
{{Short description|Concurrent constraint logic programming language}}
{{Infobox programming language
|
| paradigms = [[Constraint logic programming|Constraint logic]], [[Declarative programming|declarative]]
| year = {{Start date and age|1991}}
| designer
| implementations =
| dialects
| influenced by
| influenced
|
| wikibooks
}}
'''Constraint Handling Rules''' ('''CHR''') is a [[declarative programming|declarative]], rule-based [[programming
A CHR program, sometimes called a ''constraint handler'', is a set of rules that maintain a ''constraint store'', a [[multi-set]] of logical formulas. Execution of rules may add or remove formulas from the store, thus changing the state of the program. The order in which rules "fire" on a given constraint store is [[non-deterministic programming|non-deterministic]],<ref name="timegoesby">{{Cite journal |
Although CHR is [[Turing complete]],<ref name="complexity">{{cite journal |first1=Jon |last1=Sneyers |first2=Tom |last2=Schrijvers |first3=Bart |last3=Demoen |title=The computational power and complexity of constraint handling rules |journal=[[ACM
==Language overview==
Line 21 ⟶ 23:
A CHR program, then, consists of rules that manipulate a multi-set of these terms, called the ''constraint store''. Rules come in three types:<ref name="timegoesby"/>
* Simplification rules have the form <math>h_1, \dots, h_n \Longleftrightarrow g_1, \dots, g_m \,|\, b_1, \dots, b_o</math>. When they match the ''heads'' <math>h_1, \dots, h_n</math> and the ''[[Guard (computer science)|guards]]'' <math>g_1, \dots, g_m</math> hold, simplification rules may rewrite the heads into the ''body'' <math>b_1, \dots, b_o</math>.
* Propagation rules have the form <math>h_1, \dots, h_n \Longrightarrow g_1, \dots, g_m \,|\, b_1, \dots, b_o</math>. These rules add the constraints in the body to the store, without removing the heads.
* ''Simpagation'' rules combine simplification and propagation. They are written <math>h_1, \dots, h_\ell \,\backslash\, h_{\ell+1}, \dots, h_n \Longleftrightarrow g_1, \dots, g_m \,|\, b_1, \dots, b_o</math>. For a simpagation rule to fire, the constraint store must match all the rules in the head and the guards must hold true. The <math>\ell</math> constraints before the <math>\backslash</math> are kept, as a in a propagation rule; the remaining <math>n - \ell</math> constraints are removed.
Line 37 ⟶ 39:
===Example program===
The following CHR program, in Prolog syntax, contains four rules that implement a solver for a ''less-or-equal'' constraint. The rules are labeled for convenience (labels are optional in CHR).
<
% X leq Y means variable X is less-or-equal to variable Y
reflexivity @ X leq X <=> true.
Line 43 ⟶ 45:
transitivity @ X leq Y, Y leq Z ==> X leq Z.
idempotence @ X leq Y \ X leq Y <=> true.
</syntaxhighlight>
The rules can be read in two ways. In the declarative reading, three of the rules specify the [[Partially ordered set#Formal definition|axioms of a partial ordering]]:
* [[Reflexivity]]: ''X'' ≤ ''X''
* [[Antisymmetry]]: if ''X'' ≤ ''Y'' and ''Y'' ≤ ''X'', then ''X'' = ''Y''
* [[Transitivity]]: if ''X'' ≤ ''Y'' and ''Y'' ≤ ''Z'', then ''X'' ≤ ''Z''
All three rules are implicitly universally quantified (upper-cased identifiers are variables in Prolog syntax). The idempotence rule is a [[tautology (logic)|tautology]] from the logical viewpoint, but has a purpose in the second reading of the program.
Line 81 ⟶ 83:
== Execution of CHR programs ==
To decide which rule should "fire" on a given constraint store, a CHR implementation must use some [[pattern matching]] algorithm. Candidate algorithms include [[Rete algorithm|RETE]] and [[
{{cite conference
| url = https://www.aaai.org/Papers/AAAI/1987/AAAI87-008.pdf
| title = TREAT: A Better Match Algorithm for AI Production Systems
| last1 = Miranker
| first1 = Daniel P.
| author-link1 = Daniel P. Miranker
| date = July 13–17, 1987
| publisher = Association for the Advancement of Artificial Intelligence, AAAI
| book-title = AAAI'87: Proceedings of the sixth National conference on Artificial intelligence
| pages = 42–47
| ___location = Seattle, Washington
| isbn = 978-0-262-51055-4
}}</ref> but most implementation use a [[Lazy evaluation|lazy]] algorithm called [[LEAPS (algorithm)|LEAPS]].<ref>{{cite thesis |url=http://www.cs.kuleuven.be/publicaties/doctoraten/cw/CW2008_14.pdf |title=Execution Control for Constraint Handling Rules |author=Leslie De Koninck |year=2008 |publisher=[[Katholieke Universiteit Leuven]] |type=Ph.D. thesis |pages=12–14}}</ref>
The original specification of CHR's semantics was entirely non-deterministic, but the so-called "refined operation semantics" of Duck ''et al.'' removed much of the non-determinism so that application writers can rely on the order of execution for performance and correctness of their programs.<ref name="timegoesby"/><ref>{{cite
Most applications of CHRs require that the rewriting process be [[confluence (abstract rewriting)|confluent]]; otherwise the results of searching for a satisfying assignment will be nondeterministic and unpredictable. Establishing confluence is usually done by way of the following three properties:<ref name="chrtheorypractice" />
Line 95 ⟶ 110:
*[[Constraint logic programming]]
*[[Logic programming]]
*[[Production system (computer science)
*[[Business rules engine]]s
*[[Rewriting]]
==References==
{{Reflist}}
==Further reading==
* Christiansen, Henning. "[https://arxiv.org/
▲* Christiansen, Henning. "[https://arxiv.org/pdf/cs/0408027 CHR grammars]." Theory and Practice of Logic Programming 5.4-5 (2005): 467-501.
==External links==
* {{Official website|constraint-handling-rules.org}}
* [http://dtai.cs.kuleuven.be/CHR/biblio/ CHR Bibliography]
* [http://listserv.cc.kuleuven.ac.be/archives/chr.html The CHR mailing list]
* [http://dtai.cs.kuleuven.be/CHR/ The K.U.Leuven CHR System]
* [http://chr.informatik.uni-ulm.de/~webchr/ WebCHR
[[Category:Constraint logic programming]]
[[Category:Declarative programming languages]]
[[Category:Constraint programming languages]]
[[Category:Concurrent programming languages]]
|