Content deleted Content added
→Language overview: ''Simpagation'' |
→Example program: Adding wikilinks Tag: Disambiguation links added |
||
(48 intermediate revisions by 26 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]]
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 \
* Propagation rules have the form <math>h_1, \dots, h_n \
* ''Simpagation'' rules combine simplification and propagation. They are written <math>h_1, \dots, h_\ell \,\backslash\, h_{\ell+1}, \dots, h_n \
Since simpagation rules subsume simplification and propagation, all CHR rules follow the format
:<math>H_k \,\backslash\, H_r \
where each of <math>H_k, H_r, G, B</math> is a conjunction of constraints: <math>H_k, H_r</math> and <math>B</math> contain CHR constraints, while the guards <math>G</math> are built-in. Only one of <math>H_k, H_r</math> needs to be non-empty.
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
* A CHR program is ''locally confluent'' if all its [[Critical pair (logic)|critical pairs]] are [[Rewriting#Normal forms, joinability and the word problem|joinable]].
* A CHR program is called ''terminating'' if there are no infinite computations.
* A terminating CHR program is confluent if ''all its critical pairs are joinable''.
Line 95 ⟶ 110:
*[[Constraint logic programming]]
*[[Logic programming]]
*[[Production system (computer science)
*[[Business rules engine]]s
*[[Rewriting]]
Line 103 ⟶ 118:
==Further reading==
* Christiansen, Henning. "[https://arxiv.org/abs/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]]
|