Constraint Handling Rules

Constraint Handling Rules (CHR)
ParadigmsConstraint logic, declarative
Designed byThom Frühwirth
First appeared1991; 34 years ago (1991)
Influenced by
Prolog

Constraint Handling Rules (CHR) is a declarative, rule-based programming language, introduced in 1991 by Thom Frühwirth at the time with European Computer-Industry Research Centre (ECRC) in Munich, Germany.[1][2] Originally intended for constraint programming, CHR finds applications in grammar induction,[3] type systems,[4] abductive reasoning, multi-agent systems, natural language processing, compilation, scheduling, spatial-temporal reasoning, testing, and verification.

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,[5] according to its abstract semantics and deterministic (top-down rule application), according to its refined semantics.[6]

Although CHR is Turing complete,[7] it is not commonly used as a programming language in its own right. Rather, it is used to extend a host language with constraints. Prolog is by far the most popular host language and CHR is included in several Prolog implementations, including SICStus and SWI-Prolog, although CHR implementations also exist for Haskell,[8] Java, C,[9] SQL,[10] and JavaScript.[11] In contrast to Prolog, CHR rules are multi-headed and are executed in a committed-choice manner using a forward chaining algorithm.

Language overview

The concrete syntax of CHR programs depends on the host language, and in fact programs embed statements in the host language that are executed to handle some rules. The host language supplies a data structure for representing terms, including logical variables. Terms represent constraints, which can be thought of as "facts" about the program's problem domain. Traditionally, Prolog is used as the host language, so its data structures and variables are used. The rest of this section uses a neutral, mathematical notation that is common in the CHR literature.

A CHR program, then, consists of rules that manipulate a multi-set of these terms, called the constraint store. Rules come in three types:[5]

  • Simplification rules have the form . When they match the heads and the guards hold, simplification rules may rewrite the heads into the body .
  • Propagation rules have the form . These rules add the constraints in the body to the store, without removing the heads.
  • Simpagation rules combine simplification and propagation. They are written . For a simpagation rule to fire, the constraint store must match all the rules in the head and the guards must hold true. The constraints before the are kept, as a in a propagation rule; the remaining constraints are removed.

Since simpagation rules subsume simplification and propagation, all CHR rules follow the format

where each of is a conjunction of constraints: and contain CHR constraints, while the guards are built-in. Only one of needs to be non-empty.

The host language must also define built-in constraints over terms. The guards in rules are built-in constraints, so they effectively execute host language code. The built-in constraint theory must include at least true (the constraint that always holds), fail (the constraint that never holds, and is used to signal failure) and equality of terms, i.e., unification.[7] When the host language does not support these features, they must be implemented along with CHR.[9]

Execution of a CHR program starts with an initial constraint store. The program then proceeds by matching rules against the store and applying them, until either no more rules match (success) or the fail constraint is derived. In the former case, the constraint store can be read off by a host language program to look for facts of interest. Matching is defined as "one-way unification": it binds variables only on one side of the equation. Pattern matching can be easily implemented when as unification when the host language supports it.[9]

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.
 antisymmetry @ X leq Y, Y leq X <=> X = Y.
 transitivity @ X leq Y, Y leq Z ==> X leq Z.
 idempotence  @ X leq Y \ X leq Y <=> true.

The rules can be read in two ways. In the declarative reading, three of the rules specify the axioms of a partial ordering:

  • Reflexivity: XX
  • Antisymmetry: if XY and YX, then X = Y
  • Transitivity: if XY and YZ, then XZ

All three rules are implicitly universally quantified (upper-cased identifiers are variables in Prolog syntax). The idempotence rule is a tautology from the logical viewpoint, but has a purpose in the second reading of the program.

The second way to read the above is as a computer program for maintaining a constraint store, a collection of facts (constraints) about objects. The constraint store is not part of this program, but must be supplied separately. The rules express the following rules of computation:

  • Reflexivity is a simplification rule: it expresses that, if a fact of the form XX is found in the store, it may be removed.
  • Antisymmetry is also a simplification rule, but with two heads. If two facts of the form XY and YX can be found in the store (with matching X and Y), then they can be replaced with the single fact X = Y. Such an equality constraint is considered built in, and implemented as a unification that is typically handled by the underlying Prolog system.
  • Transitivity is a propagation rule. Unlike simplification, it does not remove anything from the constraint store; instead, when facts of the form XY and YZ (with the same value for Y) are in the store, a third fact XZ may be added.
  • Idempotence, finally, is a simpagation rule, a combined simplification and propagation. When it finds duplicate facts, it removes them from the store. Duplicates may occur because constraint stores are multi-sets of facts.

Given the query

A leq B, B leq C, C leq A

the following transformations may occur:

Current constraints Rule applicable to constraints Conclusion from rule application
A leq B, B leq C, C leq A transitivity A leq C
A leq B, B leq C, C leq A, A leq C antisymmetry A = C
A leq B, B leq A, A = C antisymmetry A = B
A = B, A = C none

The transitivity rule adds A leq C. Then, by applying the antisymmetry rule, A leq C and C leq A are removed and replaced by A = C. Now the antisymmetry rule becomes applicable on the first two constraints of the original query. Now all CHR constraints are eliminated, so no further rules can be applied, and the answer A = B, A = C is returned: CHR has correctly inferred that all three variables must refer to the same object.

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 and TREAT,[12] but most implementation use a lazy algorithm called LEAPS.[13]

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.[5][14]

Most applications of CHRs require that the rewriting process be 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:[2]

  • A CHR program is locally confluent if all its critical pairs are 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.

See also

References

  1. ^ Thom Frühwirth. Introducing Simplification Rules. Internal Report ECRC-LP-63, ECRC Munich, Germany, October 1991, Presented at the Workshop Logisches Programmieren, Goosen/Berlin, Germany, October 1991 and the Workshop on Rewriting and Constraints, Dagstuhl, Germany, October 1991.
  2. ^ a b Thom Frühwirth. Theory and Practice of Constraint Handling Rules. Special Issue on Constraint Logic Programming (P. Stuckey and K. Marriott, Eds.), Journal of Logic Programming, Vol 37(1-3), October 1998. doi:10.1016/S0743-1066(98)10005-5
  3. ^ Dahl, Veronica, and J. Emilio Miralles. "Womb grammars: Constraint solving for grammar induction." Proceedings of the 9th Workshop on Constraint Handling Rules. vol. Technical report CW. Vol. 624. 2012.
  4. ^ Alves, Sandra, and Mário Florido. "Type inference using constraint handling rules." Electronic Notes in Theoretical Computer Science 64 (2002): 56-72.
  5. ^ a b c Sneyers, Jon; Van Weert, Peter; Schrijvers, Tom; De Koninck, Leslie (2009). "As time goes by: Constraint Handling Rules – A Survey of CHR Research between 1998 and 2007" (PDF). Theory and Practice of Logic Programming. 10: 1. arXiv:0906.4474. doi:10.1017/S1471068409990123. S2CID 11044594.
  6. ^ Frühwirth, Thom (2009). Constraint handling rules. Cambridge University Press. ISBN 978-0521877763.
  7. ^ a b Sneyers, Jon; Schrijvers, Tom; Demoen, Bart (2009). "The computational power and complexity of constraint handling rules" (PDF). ACM Transactions on Programming Languages and Systems. 31 (2): 1–42. doi:10.1145/1462166.1462169. S2CID 2691882.
  8. ^ "CHR: Constraint Handling Rules library". GitHub. 5 September 2021.
  9. ^ a b c Peter Van Weert; Pieter Wuille; Tom Schrijvers; Bart Demoen. "CHR for imperative host languages". Constraint Handling Rules: Current Research Topics. Springer.
  10. ^ "CHR2 to SQL converter". GitHub. 15 March 2021.
  11. ^ CHR.js - A CHR Transpiler for JavaScript
  12. ^ Miranker, Daniel P. (July 13–17, 1987). "TREAT: A Better Match Algorithm for AI Production Systems" (PDF). AAAI'87: Proceedings of the sixth National conference on Artificial intelligence. Seattle, Washington: Association for the Advancement of Artificial Intelligence, AAAI. pp. 42–47. ISBN 978-0-262-51055-4.
  13. ^ Leslie De Koninck (2008). Execution Control for Constraint Handling Rules (PDF) (Ph.D. thesis). Katholieke Universiteit Leuven. pp. 12–14.
  14. ^ Duck, Gregory J.; Stuckey, Peter J.; García de la Banda, María; Holzbaur, Christian (2004). "The Refined Operational Semantics of Constraint Handling Rules" (PDF). Logic Programming. Lecture Notes in Computer Science. Vol. 3132. pp. 90–104. doi:10.1007/978-3-540-27775-0_7. ISBN 978-3-540-22671-0. Archived from the original (PDF) on 2011-03-04. Retrieved 2014-12-23.

Further reading

  • Christiansen, Henning. "CHR grammars." Theory and Practice of Logic Programming 5.4-5 (2005): 467-501.

Read other articles:

Daftar Tokoh Sumatera Selatan ini berisi daftar tokoh tokoh keturunan Sumatera Selatan ataupun tokoh tokoh dari etnik lain yang lahir di Sumatera Selatan. Daftar ini belumlah lengkap, para pembaca dipersilakan untuk ikut menambahnya dengan baik untuk pengetahuan kita bersama. Ahli dan akademisi Alikabul Mahi, MS, ahli Bidang Evaluasi lahan, dosen Universitas Lampung Aminurrahman Fikri, ahli audit Aulia Pohan, ekonom, deputi gubernur BI Bayu Indrawan, ahli Waste-to-Energy, pengelolaan sampah d...

 

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (ديسمبر 2020) أكيرا شيمادا (باليابانية: 島田叡)‏    معلومات شخصية الميلاد 25 ديسمبر 1901  كوبه  تاريخ الوفاة 27 يونيو 1945 (43 سنة)   مواطنة اليابان  الحياة العملية ا�...

 

Malagasy prelate of the Catholic Church (born 1954) His EminenceDésiré TsarahazanaArchbishop of ToamasinaCardinal Tsarahazana in June 2018.ChurchCatholicArchdioceseToamasinaSeeToamasinaAppointed24 November 2008PredecessorRené Joseph RakotondrabéOther post(s)President of the Episcopal Conference of Madagascar (2012–)Cardinal-Priest of San Gregorio Barbarigo alle Tre Fontane (2018–)OrdersOrdination28 September 1986Consecration18 February 2001by Michel Malo [fr]Created ...

Novel by Dan Simmons Song of Kali Hardcover first editionAuthorDan SimmonsCountryUnited StatesLanguageEnglishGenreHorrorPublisherBluejay BooksPublication dateNovember 1, 1985Media typePrint (hardcover & paperback)Pages311AwardsWorld Fantasy Award, 1986ISBN978-0747200338 Song of Kali is a horror novel by American writer Dan Simmons, published in 1985. It was the winner of the 1986 World Fantasy Award.[1] The story deals with an American intellectual who travels to Calcutta, In...

 

Questa voce o sezione tratta di una competizione calcistica in corso. Le informazioni possono pertanto cambiare rapidamente con il progredire degli eventi. Se vuoi scrivere un articolo giornalistico sull'argomento, puoi farlo su Wikinotizie. Non aggiungere speculazioni alla voce. UEFA Europa Conference League 2023-2024 Competizione UEFA Europa Conference League Sport Calcio Edizione 3ª Organizzatore UEFA Date dal 12 luglio 2023al 29 maggio 2024 Partecipanti 32 (181 alle qualificazio...

 

United States Secret ServiceLogo U.S. Secret ServiceLencana Agen Khusus U.S. Secret ServiceBendera U.S. Secret ServiceNamaU.S. Secret ServiceSingkatanUSSSIkhtisarDibentuk5 Juli 1865; 158 tahun lalu (1865-07-05)Personel6,750 + (2014)Anggaran$2.8 miliar (2014)Struktur yurisdiksiLembaga federalASWilayah hukumASKategoriPenegakan hukum federalMarkas besarWashington, D.C.Personel aktif4,400Pejabat eksekutifRandolph Alles, Direktur[1]William Callahan, Deputi DirekturLembaga induk Depart...

Railway station in Derbyshire, England This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Bamford railway station – news · newspapers · books · scholar · JSTOR (March 2011) (Learn how and when to remove this template message) BamfordGeneral informationLocationBamford, High PeakEnglandCoordinates53°20′20″N ...

 

1997 studio album by AerosmithNine LivesStudio album by AerosmithReleasedMarch 18, 1997 (1997-03-18)[1]RecordedSeptember–November 1996Studio Avatar, New York City The Boneyard Genre Hard rock blues rock Length62:54LabelColumbiaProducer Kevin Shirley Aerosmith Aerosmith chronology Get a Grip(1993) Nine Lives(1997) Just Push Play(2001) Alternative coverOriginal album cover, replaced due to controversy Singles from Nine Lives Falling in Love (Is Hard on the Knee...

 

Region in Pennsylvania Autumn on a small road in Somerset County The Laurel Highlands is a region in southwestern Pennsylvania made up of Fayette County, Somerset County, and Westmoreland County.[1] It has a population of about 600,000 people. The region is approximately fifty-five miles southeast of Pittsburgh; the Laurel Highlands center on Laurel Hill and Chestnut Ridge of the Allegheny Mountains. The mountains making up the Laurel Highlands are the highest in Pennsylvania, with Mo...

У этого термина существуют и другие значения, см. Чайки (значения). Чайки Доминиканская чайкаЗападная чайкаКалифорнийская чайкаМорская чайка Научная классификация Домен:ЭукариотыЦарство:ЖивотныеПодцарство:ЭуметазоиБез ранга:Двусторонне-симметричныеБез ранга:Вторич...

 

Contea di IrionconteaLocalizzazioneStato Stati Uniti Stato federato Texas AmministrazioneCapoluogoMertzon Data di istituzione1889 TerritorioCoordinatedel capoluogo31°18′00″N 100°58′48″W / 31.3°N 100.98°W31.3; -100.98 (Contea di Irion)Coordinate: 31°18′00″N 100°58′48″W / 31.3°N 100.98°W31.3; -100.98 (Contea di Irion) Superficie2 724 km² Abitanti1 771 (2000) Densità0,65 ab./km² Altre informazioniFuso orarioU...

 

В Википедии есть статьи о других людях с фамилией Трейси. Шон Трейсиирл. Seán Ó Treasaigh Дата рождения 14 февраля 1895(1895-02-14)[1] Место рождения графство Типперэри, Ирландия. Дата смерти 14 октября 1920(1920-10-14) (25 лет) Место смерти Талбот-стрит, Дублин Страна Ирландия Род деят...

10th round of the 2008 Formula One season 2008 German Grand Prix Race 10 of 18 in the 2008 Formula One World Championship← Previous raceNext race → Race detailsDate 20 July 2008Official name Formula 1 Grosser Preis Santander von Deutschland 2008Location Hockenheimring, Hockenheim, GermanyCourse Permanent racing facilityCourse length 4.574 km (2.842 miles)Distance 67 laps, 306.458 km (190.424 miles)Weather Cloudy, later sunny[1]Pole positionDriver Lewis Hamilton...

 

豪栄道 豪太郎 場所入りする豪栄道基礎情報四股名 澤井 豪太郎→豪栄道 豪太郎本名 澤井 豪太郎愛称 ゴウタロウ、豪ちゃん、GAD[1][2]生年月日 (1986-04-06) 1986年4月6日(38歳)出身 大阪府寝屋川市身長 183cm体重 160kgBMI 47.26所属部屋 境川部屋得意技 右四つ・出し投げ・切り返し・外掛け・首投げ・右下手投げ成績現在の番付 引退最高位 東大関生涯戦歴 696勝493敗...

 

British politician (born 1968) The subject of this article is standing for re-election to the House of Commons of the United Kingdom on 4 July, and has not been an incumbent MP since Parliament was dissolved on 30 May. Some parts of this article may be out of date during this period. Please feel free to improve this article (but note that updates without valid and reliable references will be removed) or discuss changes on the talk page. The Right HonourableGrant ShappsOfficial portr...

У этого термина существуют и другие значения, см. Новый Путь. ПосёлокНовый Путь 52°10′14″ с. ш. 82°26′54″ в. д.HGЯO Страна  Россия Субъект Федерации Алтайский край Муниципальный район Шипуновский Сельское поселение Краснояровский сельсовет История и география Ча�...

 

Waiting for the EndSingel oleh Linkin Parkdari album A Thousand SunsSisi-BWaiting for the End (The Glitch Mob Remix)The Catalyst (Guitarmagedon DIOYY? Remix)Dirilis1 Oktober 2010 (2010-10-01)FormatCD single, digital downloadDirekam2008–2010GenreRock alternatifDurasi3:51LabelWarner Bros.PenciptaLinkin ParkProduserRick Rubin, Mike ShinodaVideo musikWaiting For the End di YouTube Video musikWaiting For the End (live) di YouTube Waiting for the End adalah lagu dari band rock Amerika Linkin...

 

Neurotoxic protein produced by Clostridium botulinum Botulinum toxin ARibbon diagram of tertiary structure of BotA (P0DPI1). PDB entry 3BTA.Clinical dataTrade namesBotox, Myobloc, Jeuveau, othersOther namesBoNT, botoxBiosimilarsabobotulinumtoxinA, daxibotulinumtoxinA, daxibotulinumtoxinA-lanm, evabotulinumtoxinA, incobotulinumtoxinA, letibotulinumtoxinA, letibotulinumtoxinA-wlbg,[1] onabotulinumtoxinA, prabotulinumtoxinA, relabotulinumtoxinA, rimabotulinumtoxinBAHFS/Drugs.comabobotuli...

Disambiguazione – Se stai cercando altri significati, vedi Chef (disambigua). William Orpen, Chef de l'Hôtel Chatham, Paris Lo chef o capocuoco è un cuoco altamente qualificato, competente in tutti gli aspetti della preparazione del cibo ed è il responsabile dell'intera brigata di cucina. È incaricato dell'impostazione del menù, delle ricette e dell'intera sorveglianza della loro realizzazione. Indice 1 Etimologia 2 Responsabilità e rischi del lavoro 3 La formazione professionale 4 T...

 

  提示:此条目页的主题不是阿拉伯聯合共和國。 阿拉伯联合酋长國الإمارات العربية المتحدة(阿拉伯語) 国旗 国徽 国歌:عيشي بلادي《祖国万岁》地位聯邦首都阿布達比最大城市杜拜 25°15′N 55°18′E / 25.250°N 55.300°E / 25.250; 55.300官方语言阿拉伯语族群(2015[1])11.32% 阿联酋公民88.68% 外国人— 27.15% 印度裔— 12.53% 巴基斯坦裔— ...